PluginProbe
Gutenberg / 24.0.0
Gutenberg v24.0.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / build / scripts / widgets / index.js

index.js in Gutenberg 24.0.0, at build/scripts/widgets/index.js

1,466 lines 50.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function() {
2 var wp;
3 (wp ||= {}).widgets = (() => {
4 var __create = Object.create;
5 var __defProp = Object.defineProperty;
6 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7 var __getOwnPropNames = Object.getOwnPropertyNames;
8 var __getProtoOf = Object.getPrototypeOf;
9 var __hasOwnProp = Object.prototype.hasOwnProperty;
10 var __commonJS = (cb, mod) => function __require() {
11 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12 };
13 var __export = (target, all) => {
14 for (var name3 in all)
15 __defProp(target, name3, { get: all[name3], enumerable: true });
16 };
17 var __copyProps = (to, from, except, desc) => {
18 if (from && typeof from === "object" || typeof from === "function") {
19 for (let key of __getOwnPropNames(from))
20 if (!__hasOwnProp.call(to, key) && key !== except)
21 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22 }
23 return to;
24 };
25 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26 // If the importer is in node compatibility mode or this is not an ESM
27 // file that has been converted to a CommonJS file using a Babel-
28 // compatible transform (i.e. "__esModule" has not been set), then set
29 // "default" to the CommonJS "module.exports" for node compatibility.
30 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31 mod
32 ));
33 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
35 // package-external:@wordpress/blocks
36 var require_blocks = __commonJS({
37 "package-external:@wordpress/blocks"(exports, module) {
38 module.exports = window.wp.blocks;
39 }
40 });
41
42 // package-external:@wordpress/element
43 var require_element = __commonJS({
44 "package-external:@wordpress/element"(exports, module) {
45 module.exports = window.wp.element;
46 }
47 });
48
49 // package-external:@wordpress/primitives
50 var require_primitives = __commonJS({
51 "package-external:@wordpress/primitives"(exports, module) {
52 module.exports = window.wp.primitives;
53 }
54 });
55
56 // vendor-external:react/jsx-runtime
57 var require_jsx_runtime = __commonJS({
58 "vendor-external:react/jsx-runtime"(exports, module) {
59 module.exports = window.ReactJSXRuntime;
60 }
61 });
62
63 // package-external:@wordpress/block-editor
64 var require_block_editor = __commonJS({
65 "package-external:@wordpress/block-editor"(exports, module) {
66 module.exports = window.wp.blockEditor;
67 }
68 });
69
70 // package-external:@wordpress/components
71 var require_components = __commonJS({
72 "package-external:@wordpress/components"(exports, module) {
73 module.exports = window.wp.components;
74 }
75 });
76
77 // package-external:@wordpress/i18n
78 var require_i18n = __commonJS({
79 "package-external:@wordpress/i18n"(exports, module) {
80 module.exports = window.wp.i18n;
81 }
82 });
83
84 // package-external:@wordpress/core-data
85 var require_core_data = __commonJS({
86 "package-external:@wordpress/core-data"(exports, module) {
87 module.exports = window.wp.coreData;
88 }
89 });
90
91 // package-external:@wordpress/data
92 var require_data = __commonJS({
93 "package-external:@wordpress/data"(exports, module) {
94 module.exports = window.wp.data;
95 }
96 });
97
98 // package-external:@wordpress/notices
99 var require_notices = __commonJS({
100 "package-external:@wordpress/notices"(exports, module) {
101 module.exports = window.wp.notices;
102 }
103 });
104
105 // package-external:@wordpress/compose
106 var require_compose = __commonJS({
107 "package-external:@wordpress/compose"(exports, module) {
108 module.exports = window.wp.compose;
109 }
110 });
111
112 // package-external:@wordpress/api-fetch
113 var require_api_fetch = __commonJS({
114 "package-external:@wordpress/api-fetch"(exports, module) {
115 module.exports = window.wp.apiFetch;
116 }
117 });
118
119 // packages/widgets/build-module/index.mjs
120 var index_exports = {};
121 __export(index_exports, {
122 MoveToWidgetArea: () => MoveToWidgetArea,
123 addWidgetIdToBlock: () => addWidgetIdToBlock,
124 getWidgetIdFromBlock: () => getWidgetIdFromBlock,
125 registerLegacyWidgetBlock: () => registerLegacyWidgetBlock,
126 registerLegacyWidgetVariations: () => registerLegacyWidgetVariations,
127 registerWidgetGroupBlock: () => registerWidgetGroupBlock
128 });
129 var import_blocks5 = __toESM(require_blocks(), 1);
130
131 // packages/widgets/build-module/blocks/legacy-widget/index.mjs
132 var legacy_widget_exports = {};
133 __export(legacy_widget_exports, {
134 metadata: () => block_default,
135 name: () => name,
136 settings: () => settings
137 });
138
139 // packages/icons/build-module/library/brush.mjs
140 var import_primitives = __toESM(require_primitives(), 1);
141 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
142 var brush_default = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.Path, { d: "M4 20h8v-1.5H4V20zM18.9 3.5c-.6-.6-1.5-.6-2.1 0l-7.2 7.2c-.4-.1-.7 0-1.1.1-.5.2-1.5.7-1.9 2.2-.4 1.7-.8 2.2-1.1 2.7-.1.1-.2.3-.3.4l-.6 1.1H6c2 0 3.4-.4 4.7-1.4.8-.6 1.2-1.4 1.3-2.3 0-.3 0-.5-.1-.7L19 5.7c.5-.6.5-1.6-.1-2.2zM9.7 14.7c-.7.5-1.5.8-2.4 1 .2-.5.5-1.2.8-2.3.2-.6.4-1 .8-1.1.5-.1 1 .1 1.3.3.2.2.3.5.2.8 0 .3-.1.9-.7 1.3z" }) });
143
144 // packages/icons/build-module/library/group.mjs
145 var import_primitives2 = __toESM(require_primitives(), 1);
146 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
147 var group_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.Path, { d: "M18 4h-7c-1.1 0-2 .9-2 2v3H6c-1.1 0-2 .9-2 2v7c0 1.1.9 2 2 2h7c1.1 0 2-.9 2-2v-3h3c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm-4.5 14c0 .3-.2.5-.5.5H6c-.3 0-.5-.2-.5-.5v-7c0-.3.2-.5.5-.5h3V13c0 1.1.9 2 2 2h2.5v3zm0-4.5H11c-.3 0-.5-.2-.5-.5v-2.5H13c.3 0 .5.2.5.5v2.5zm5-.5c0 .3-.2.5-.5.5h-3V11c0-1.1-.9-2-2-2h-2.5V6c0-.3.2-.5.5-.5h7c.3 0 .5.2.5.5v7z" }) });
148
149 // packages/icons/build-module/library/move-to.mjs
150 var import_primitives3 = __toESM(require_primitives(), 1);
151 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
152 var move_to_default = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.Path, { d: "M19.75 9c0-1.257-.565-2.197-1.39-2.858-.797-.64-1.827-1.017-2.815-1.247-1.802-.42-3.703-.403-4.383-.396L11 4.5V6l.177-.001c.696-.006 2.416-.02 4.028.356.887.207 1.67.518 2.216.957.52.416.829.945.829 1.688 0 .592-.167.966-.407 1.23-.255.281-.656.508-1.236.674-1.19.34-2.82.346-4.607.346h-.077c-1.692 0-3.527 0-4.942.404-.732.209-1.424.545-1.935 1.108-.526.579-.796 1.33-.796 2.238 0 1.257.565 2.197 1.39 2.858.797.64 1.827 1.017 2.815 1.247 1.802.42 3.703.403 4.383.396L13 19.5h.714V22L18 18.5 13.714 15v3H13l-.177.001c-.696.006-2.416.02-4.028-.356-.887-.207-1.67-.518-2.216-.957-.52-.416-.829-.945-.829-1.688 0-.592.167-.966.407-1.23.255-.281.656-.508 1.237-.674 1.189-.34 2.819-.346 4.606-.346h.077c1.692 0 3.527 0 4.941-.404.732-.209 1.425-.545 1.936-1.108.526-.579.796-1.33.796-2.238z" }) });
153
154 // packages/icons/build-module/library/widget.mjs
155 var import_primitives4 = __toESM(require_primitives(), 1);
156 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
157 var widget_default = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.Path, { d: "M6 3H8V5H16V3H18V5C19.1046 5 20 5.89543 20 7V19C20 20.1046 19.1046 21 18 21H6C4.89543 21 4 20.1046 4 19V7C4 5.89543 4.89543 5 6 5V3ZM18 6.5H6C5.72386 6.5 5.5 6.72386 5.5 7V8H18.5V7C18.5 6.72386 18.2761 6.5 18 6.5ZM18.5 9.5H5.5V19C5.5 19.2761 5.72386 19.5 6 19.5H18C18.2761 19.5 18.5 19.2761 18.5 19V9.5ZM11 11H13V13H11V11ZM7 11V13H9V11H7ZM15 13V11H17V13H15Z" }) });
158
159 // packages/widgets/build-module/blocks/legacy-widget/block.json
160 var block_default = {
161 $schema: "https://schemas.wp.org/trunk/block.json",
162 apiVersion: 3,
163 name: "core/legacy-widget",
164 title: "Legacy Widget",
165 category: "widgets",
166 description: "Display a legacy widget.",
167 textdomain: "default",
168 attributes: {
169 id: {
170 type: "string",
171 default: null
172 },
173 idBase: {
174 type: "string",
175 default: null
176 },
177 instance: {
178 type: "object",
179 default: null
180 }
181 },
182 supports: {
183 html: false,
184 customClassName: false,
185 reusable: false
186 },
187 editorStyle: "wp-block-legacy-widget-editor"
188 };
189
190 // node_modules/clsx/dist/clsx.mjs
191 function r(e) {
192 var t, f, n = "";
193 if ("string" == typeof e || "number" == typeof e) n += e;
194 else if ("object" == typeof e) if (Array.isArray(e)) {
195 var o = e.length;
196 for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
197 } else for (f in e) e[f] && (n && (n += " "), n += f);
198 return n;
199 }
200 function clsx() {
201 for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
202 return n;
203 }
204 var clsx_default = clsx;
205
206 // packages/widgets/build-module/blocks/legacy-widget/edit/index.mjs
207 var import_block_editor3 = __toESM(require_block_editor(), 1);
208 var import_components5 = __toESM(require_components(), 1);
209 var import_i18n7 = __toESM(require_i18n(), 1);
210 var import_element3 = __toESM(require_element(), 1);
211 var import_core_data2 = __toESM(require_core_data(), 1);
212
213 // packages/widgets/build-module/blocks/legacy-widget/edit/widget-type-selector.mjs
214 var import_components = __toESM(require_components(), 1);
215 var import_i18n = __toESM(require_i18n(), 1);
216 var import_data = __toESM(require_data(), 1);
217 var import_core_data = __toESM(require_core_data(), 1);
218 var import_block_editor = __toESM(require_block_editor(), 1);
219 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
220 function WidgetTypeSelector({ selectedId, onSelect }) {
221 const widgetTypes = (0, import_data.useSelect)((select2) => {
222 const hiddenIds = select2(import_block_editor.store).getSettings()?.widgetTypesToHideFromLegacyWidgetBlock ?? [];
223 return select2(import_core_data.store).getWidgetTypes({ per_page: -1 })?.filter((widgetType) => !hiddenIds.includes(widgetType.id));
224 }, []);
225 if (!widgetTypes) {
226 return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_components.Spinner, {});
227 }
228 if (widgetTypes.length === 0) {
229 return (0, import_i18n.__)("There are no widgets available.");
230 }
231 return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
232 import_components.SelectControl,
233 {
234 label: (0, import_i18n.__)("Legacy widget"),
235 value: selectedId ?? "",
236 options: [
237 { value: "", label: (0, import_i18n.__)("Select widget") },
238 ...widgetTypes.map((widgetType) => ({
239 value: widgetType.id,
240 label: widgetType.name
241 }))
242 ],
243 onChange: (value) => {
244 if (value) {
245 const selected = widgetTypes.find(
246 (widgetType) => widgetType.id === value
247 );
248 onSelect({
249 selectedId: selected.id,
250 isMulti: selected.is_multi
251 });
252 } else {
253 onSelect({ selectedId: null });
254 }
255 }
256 }
257 );
258 }
259
260 // packages/widgets/build-module/blocks/legacy-widget/edit/inspector-card.mjs
261 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
262 function InspectorCard({ name: name3, description }) {
263 return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "wp-block-legacy-widget-inspector-card", children: [
264 /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h3", { className: "wp-block-legacy-widget-inspector-card__name", children: name3 }),
265 /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: description })
266 ] });
267 }
268
269 // packages/widgets/build-module/blocks/legacy-widget/edit/form.mjs
270 var import_element = __toESM(require_element(), 1);
271 var import_data2 = __toESM(require_data(), 1);
272 var import_notices = __toESM(require_notices(), 1);
273 var import_i18n3 = __toESM(require_i18n(), 1);
274 var import_components2 = __toESM(require_components(), 1);
275 var import_compose2 = __toESM(require_compose(), 1);
276
277 // packages/widgets/build-module/blocks/legacy-widget/edit/control.mjs
278 var import_api_fetch = __toESM(require_api_fetch(), 1);
279 var import_compose = __toESM(require_compose(), 1);
280 var import_i18n2 = __toESM(require_i18n(), 1);
281 var Control = class {
282 /**
283 * Creates and loads a new control.
284 *
285 * @access public
286 * @param {Object} params
287 * @param {string} params.id
288 * @param {string} params.idBase
289 * @param {Object} params.instance
290 * @param {Function} params.onChangeInstance
291 * @param {Function} params.onChangeHasPreview
292 * @param {Function} params.onError
293 */
294 constructor({
295 id,
296 idBase,
297 instance,
298 onChangeInstance,
299 onChangeHasPreview,
300 onError
301 }) {
302 this.id = id;
303 this.idBase = idBase;
304 this._instance = instance;
305 this._hasPreview = null;
306 this.onChangeInstance = onChangeInstance;
307 this.onChangeHasPreview = onChangeHasPreview;
308 this.onError = onError;
309 this.number = ++lastNumber;
310 this.handleFormChange = (0, import_compose.debounce)(
311 this.handleFormChange.bind(this),
312 200
313 );
314 this.handleFormSubmit = this.handleFormSubmit.bind(this);
315 this.initDOM();
316 this.bindEvents();
317 this.loadContent();
318 }
319 /**
320 * Clean up the control so that it can be garbage collected.
321 *
322 * @access public
323 */
324 destroy() {
325 this.unbindEvents();
326 this.element.remove();
327 }
328 /**
329 * Creates the control's DOM structure.
330 *
331 * @access private
332 */
333 initDOM() {
334 this.element = el("div", { class: "widget open" }, [
335 el("div", { class: "widget-inside" }, [
336 this.form = el("form", { class: "form", method: "post" }, [
337 // These hidden form inputs are what most widgets' scripts
338 // use to access data about the widget.
339 el("input", {
340 class: "widget-id",
341 type: "hidden",
342 name: "widget-id",
343 value: this.id ?? `${this.idBase}-${this.number}`
344 }),
345 el("input", {
346 class: "id_base",
347 type: "hidden",
348 name: "id_base",
349 value: this.idBase ?? this.id
350 }),
351 el("input", {
352 class: "widget-width",
353 type: "hidden",
354 name: "widget-width",
355 value: "250"
356 }),
357 el("input", {
358 class: "widget-height",
359 type: "hidden",
360 name: "widget-height",
361 value: "200"
362 }),
363 el("input", {
364 class: "widget_number",
365 type: "hidden",
366 name: "widget_number",
367 value: this.idBase ? this.number.toString() : ""
368 }),
369 this.content = el("div", { class: "widget-content" }),
370 // Non-multi widgets can be saved via a Save button.
371 this.id && el(
372 "button",
373 {
374 class: "button is-primary",
375 type: "submit"
376 },
377 (0, import_i18n2.__)("Save")
378 )
379 ])
380 ])
381 ]);
382 }
383 /**
384 * Adds the control's event listeners.
385 *
386 * @access private
387 */
388 bindEvents() {
389 if (window.jQuery) {
390 const { jQuery: $ } = window;
391 $(this.form).on("change", null, this.handleFormChange);
392 $(this.form).on("input", null, this.handleFormChange);
393 $(this.form).on("submit", this.handleFormSubmit);
394 } else {
395 this.form.addEventListener("change", this.handleFormChange);
396 this.form.addEventListener("input", this.handleFormChange);
397 this.form.addEventListener("submit", this.handleFormSubmit);
398 }
399 }
400 /**
401 * Removes the control's event listeners.
402 *
403 * @access private
404 */
405 unbindEvents() {
406 if (window.jQuery) {
407 const { jQuery: $ } = window;
408 $(this.form).off("change", null, this.handleFormChange);
409 $(this.form).off("input", null, this.handleFormChange);
410 $(this.form).off("submit", this.handleFormSubmit);
411 } else {
412 this.form.removeEventListener("change", this.handleFormChange);
413 this.form.removeEventListener("input", this.handleFormChange);
414 this.form.removeEventListener("submit", this.handleFormSubmit);
415 }
416 }
417 /**
418 * Fetches the widget's form HTML from the REST API and loads it into the
419 * control's form.
420 *
421 * @access private
422 */
423 async loadContent() {
424 try {
425 if (this.id) {
426 const { form } = await saveWidget(this.id);
427 this.content.innerHTML = form;
428 } else if (this.idBase) {
429 const { form, preview } = await encodeWidget({
430 idBase: this.idBase,
431 instance: this.instance,
432 number: this.number
433 });
434 this.content.innerHTML = form;
435 this.hasPreview = !isEmptyHTML(preview);
436 if (!this.instance.hash) {
437 const { instance } = await encodeWidget({
438 idBase: this.idBase,
439 instance: this.instance,
440 number: this.number,
441 formData: serializeForm(this.form)
442 });
443 this.instance = instance;
444 }
445 }
446 if (window.jQuery) {
447 const { jQuery: $ } = window;
448 $(document).trigger("widget-added", [$(this.element)]);
449 }
450 } catch (error) {
451 this.onError(error);
452 }
453 }
454 /**
455 * Perform a save when a multi widget's form is changed. Non-multi widgets
456 * are saved manually.
457 *
458 * @access private
459 */
460 handleFormChange() {
461 if (this.idBase) {
462 this.saveForm();
463 }
464 }
465 /**
466 * Perform a save when the control's form is manually submitted.
467 *
468 * @access private
469 * @param {Event} event
470 */
471 handleFormSubmit(event) {
472 event.preventDefault();
473 this.saveForm();
474 }
475 /**
476 * Serialize the control's form, send it to the REST API, and update the
477 * instance with the encoded instance that the REST API returns.
478 *
479 * @access private
480 */
481 async saveForm() {
482 const formData = serializeForm(this.form);
483 try {
484 if (this.id) {
485 const { form } = await saveWidget(this.id, formData);
486 this.content.innerHTML = form;
487 if (window.jQuery) {
488 const { jQuery: $ } = window;
489 $(document).trigger("widget-updated", [
490 $(this.element)
491 ]);
492 }
493 } else if (this.idBase) {
494 const { instance, preview } = await encodeWidget({
495 idBase: this.idBase,
496 instance: this.instance,
497 number: this.number,
498 formData
499 });
500 this.instance = instance;
501 this.hasPreview = !isEmptyHTML(preview);
502 }
503 } catch (error) {
504 this.onError(error);
505 }
506 }
507 /**
508 * The widget's instance object.
509 *
510 * @access private
511 */
512 get instance() {
513 return this._instance;
514 }
515 /**
516 * The widget's instance object.
517 *
518 * @access private
519 */
520 set instance(instance) {
521 if (this._instance !== instance) {
522 this._instance = instance;
523 this.onChangeInstance(instance);
524 }
525 }
526 /**
527 * Whether or not the widget can be previewed.
528 *
529 * @access public
530 */
531 get hasPreview() {
532 return this._hasPreview;
533 }
534 /**
535 * Whether or not the widget can be previewed.
536 *
537 * @access private
538 */
539 set hasPreview(hasPreview) {
540 if (this._hasPreview !== hasPreview) {
541 this._hasPreview = hasPreview;
542 this.onChangeHasPreview(hasPreview);
543 }
544 }
545 };
546 var lastNumber = 0;
547 function el(tagName, attributes = {}, content = null) {
548 const element = document.createElement(tagName);
549 for (const [attribute, value] of Object.entries(attributes)) {
550 element.setAttribute(attribute, value);
551 }
552 if (Array.isArray(content)) {
553 for (const child of content) {
554 if (child) {
555 element.appendChild(child);
556 }
557 }
558 } else if (typeof content === "string") {
559 element.innerText = content;
560 }
561 return element;
562 }
563 async function saveWidget(id, formData = null) {
564 let widget;
565 if (formData) {
566 widget = await (0, import_api_fetch.default)({
567 path: `/wp/v2/widgets/${id}?context=edit`,
568 method: "PUT",
569 data: {
570 form_data: formData
571 }
572 });
573 } else {
574 widget = await (0, import_api_fetch.default)({
575 path: `/wp/v2/widgets/${id}?context=edit`,
576 method: "GET"
577 });
578 }
579 return { form: widget.rendered_form };
580 }
581 async function encodeWidget({ idBase, instance, number, formData = null }) {
582 const response = await (0, import_api_fetch.default)({
583 path: `/wp/v2/widget-types/${idBase}/encode`,
584 method: "POST",
585 data: {
586 instance,
587 number,
588 form_data: formData
589 }
590 });
591 return {
592 instance: response.instance,
593 form: response.form,
594 preview: response.preview
595 };
596 }
597 function isEmptyHTML(html) {
598 const element = document.createElement("div");
599 element.innerHTML = html;
600 return isEmptyNode(element);
601 }
602 function isEmptyNode(node) {
603 switch (node.nodeType) {
604 case node.TEXT_NODE:
605 return node.nodeValue.trim() === "";
606 case node.ELEMENT_NODE:
607 if ([
608 "AUDIO",
609 "CANVAS",
610 "EMBED",
611 "IFRAME",
612 "IMG",
613 "MATH",
614 "OBJECT",
615 "SVG",
616 "VIDEO"
617 ].includes(node.tagName)) {
618 return false;
619 }
620 if (!node.hasChildNodes()) {
621 return true;
622 }
623 return Array.from(node.childNodes).every(isEmptyNode);
624 default:
625 return true;
626 }
627 }
628 function serializeForm(form) {
629 return new window.URLSearchParams(
630 Array.from(new window.FormData(form))
631 ).toString();
632 }
633
634 // packages/widgets/build-module/blocks/legacy-widget/edit/form.mjs
635 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
636 function Form({
637 title,
638 isVisible,
639 id,
640 idBase,
641 instance,
642 isWide,
643 onChangeInstance,
644 onChangeHasPreview
645 }) {
646 const ref = (0, import_element.useRef)();
647 const isMediumLargeViewport = (0, import_compose2.useViewportMatch)("small");
648 const outgoingInstances = (0, import_element.useRef)(/* @__PURE__ */ new Set());
649 const incomingInstances = (0, import_element.useRef)(/* @__PURE__ */ new Set());
650 const { createNotice } = (0, import_data2.useDispatch)(import_notices.store);
651 (0, import_element.useEffect)(() => {
652 if (incomingInstances.current.has(instance)) {
653 incomingInstances.current.delete(instance);
654 return;
655 }
656 const control = new Control({
657 id,
658 idBase,
659 instance,
660 onChangeInstance(nextInstance) {
661 outgoingInstances.current.add(instance);
662 incomingInstances.current.add(nextInstance);
663 onChangeInstance(nextInstance);
664 },
665 onChangeHasPreview,
666 onError(error) {
667 window.console.error(error);
668 createNotice(
669 "error",
670 (0, import_i18n3.sprintf)(
671 /* translators: %s: the name of the affected block. */
672 (0, import_i18n3.__)(
673 'The "%s" block was affected by errors and may not function properly. Check the developer tools for more details.'
674 ),
675 idBase || id
676 )
677 );
678 }
679 });
680 ref.current.appendChild(control.element);
681 return () => {
682 if (outgoingInstances.current.has(instance)) {
683 outgoingInstances.current.delete(instance);
684 return;
685 }
686 control.destroy();
687 };
688 }, [
689 id,
690 idBase,
691 instance,
692 onChangeInstance,
693 onChangeHasPreview,
694 isMediumLargeViewport
695 ]);
696 if (isWide && isMediumLargeViewport) {
697 return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
698 "div",
699 {
700 className: clsx_default({
701 "wp-block-legacy-widget__container": isVisible
702 }),
703 children: [
704 isVisible && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h3", { className: "wp-block-legacy-widget__edit-form-title", children: title }),
705 /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
706 import_components2.Popover,
707 {
708 focusOnMount: false,
709 placement: "right",
710 offset: 32,
711 resize: false,
712 flip: false,
713 shift: true,
714 children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
715 "div",
716 {
717 ref,
718 className: "wp-block-legacy-widget__edit-form",
719 hidden: !isVisible
720 }
721 )
722 }
723 )
724 ]
725 }
726 );
727 }
728 return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
729 "div",
730 {
731 ref,
732 className: "wp-block-legacy-widget__edit-form",
733 hidden: !isVisible,
734 children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h3", { className: "wp-block-legacy-widget__edit-form-title", children: title })
735 }
736 );
737 }
738
739 // packages/widgets/build-module/blocks/legacy-widget/edit/preview.mjs
740 var import_compose3 = __toESM(require_compose(), 1);
741 var import_element2 = __toESM(require_element(), 1);
742 var import_components3 = __toESM(require_components(), 1);
743 var import_i18n4 = __toESM(require_i18n(), 1);
744 var import_api_fetch2 = __toESM(require_api_fetch(), 1);
745 var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
746 function Preview({ idBase, instance, isVisible }) {
747 const [isLoaded, setIsLoaded] = (0, import_element2.useState)(false);
748 const [srcDoc, setSrcDoc] = (0, import_element2.useState)("");
749 (0, import_element2.useEffect)(() => {
750 const abortController = typeof window.AbortController === "undefined" ? void 0 : new window.AbortController();
751 async function fetchPreviewHTML() {
752 const restRoute = `/wp/v2/widget-types/${idBase}/render`;
753 return await (0, import_api_fetch2.default)({
754 path: restRoute,
755 method: "POST",
756 signal: abortController?.signal,
757 data: instance ? { instance } : {}
758 });
759 }
760 fetchPreviewHTML().then((response) => {
761 setSrcDoc(response.preview);
762 }).catch((error) => {
763 if ("AbortError" === error.name) {
764 return;
765 }
766 throw error;
767 });
768 return () => abortController?.abort();
769 }, [idBase, instance]);
770 const ref = (0, import_compose3.useRefEffect)(
771 (iframe) => {
772 if (!isLoaded) {
773 return;
774 }
775 function setHeight() {
776 const height = Math.max(
777 iframe.contentDocument.documentElement?.offsetHeight ?? 0,
778 iframe.contentDocument.body?.offsetHeight ?? 0
779 );
780 iframe.style.height = `${height !== 0 ? height : 100}px`;
781 }
782 const { IntersectionObserver } = iframe.ownerDocument.defaultView;
783 const intersectionObserver = new IntersectionObserver(
784 ([entry]) => {
785 if (entry.isIntersecting) {
786 setHeight();
787 }
788 },
789 {
790 threshold: 1
791 }
792 );
793 intersectionObserver.observe(iframe);
794 iframe.addEventListener("load", setHeight);
795 return () => {
796 intersectionObserver.disconnect();
797 iframe.removeEventListener("load", setHeight);
798 };
799 },
800 [isLoaded]
801 );
802 return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
803 isVisible && !isLoaded && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components3.Placeholder, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components3.Spinner, {}) }),
804 /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
805 "div",
806 {
807 className: clsx_default("wp-block-legacy-widget__edit-preview", {
808 "is-offscreen": !isVisible || !isLoaded
809 }),
810 children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components3.Disabled, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
811 "iframe",
812 {
813 ref,
814 className: "wp-block-legacy-widget__edit-preview-iframe",
815 tabIndex: "-1",
816 title: (0, import_i18n4.__)("Legacy Widget Preview"),
817 srcDoc,
818 onLoad: (event) => {
819 event.target.contentDocument.body.style.overflow = "hidden";
820 setIsLoaded(true);
821 },
822 height: 100
823 }
824 ) })
825 }
826 )
827 ] });
828 }
829
830 // packages/widgets/build-module/blocks/legacy-widget/edit/no-preview.mjs
831 var import_i18n5 = __toESM(require_i18n(), 1);
832 var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
833 function NoPreview({ name: name3 }) {
834 return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "wp-block-legacy-widget__edit-no-preview", children: [
835 name3 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("h3", { children: name3 }),
836 /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { children: (0, import_i18n5.__)("No preview available.") })
837 ] });
838 }
839
840 // packages/widgets/build-module/blocks/legacy-widget/edit/convert-to-blocks-button.mjs
841 var import_data3 = __toESM(require_data(), 1);
842 var import_block_editor2 = __toESM(require_block_editor(), 1);
843 var import_components4 = __toESM(require_components(), 1);
844 var import_blocks = __toESM(require_blocks(), 1);
845 var import_i18n6 = __toESM(require_i18n(), 1);
846 var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
847 function ConvertToBlocksButton({ clientId, rawInstance }) {
848 const { replaceBlocks } = (0, import_data3.useDispatch)(import_block_editor2.store);
849 return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
850 import_components4.ToolbarButton,
851 {
852 onClick: () => {
853 if (rawInstance.title) {
854 replaceBlocks(clientId, [
855 (0, import_blocks.createBlock)("core/heading", {
856 content: rawInstance.title
857 }),
858 ...(0, import_blocks.rawHandler)({ HTML: rawInstance.text })
859 ]);
860 } else {
861 replaceBlocks(
862 clientId,
863 (0, import_blocks.rawHandler)({ HTML: rawInstance.text })
864 );
865 }
866 },
867 children: (0, import_i18n6.__)("Convert to blocks")
868 }
869 );
870 }
871
872 // packages/widgets/build-module/blocks/legacy-widget/edit/index.mjs
873 var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
874 function Edit(props) {
875 const { id, idBase } = props.attributes;
876 const { isWide = false } = props;
877 const blockProps = (0, import_block_editor3.useBlockProps)({
878 className: clsx_default({
879 "is-wide-widget": isWide
880 })
881 });
882 return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { ...blockProps, children: !id && !idBase ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Empty, { ...props }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(NotEmpty, { ...props }) });
883 }
884 function Empty({ attributes: { id, idBase }, setAttributes }) {
885 return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
886 import_components5.Placeholder,
887 {
888 icon: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_block_editor3.BlockIcon, { icon: brush_default }),
889 label: (0, import_i18n7.__)("Legacy Widget"),
890 children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_components5.Flex, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_components5.FlexBlock, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
891 WidgetTypeSelector,
892 {
893 selectedId: id ?? idBase,
894 onSelect: ({ selectedId, isMulti }) => {
895 if (!selectedId) {
896 setAttributes({
897 id: null,
898 idBase: null,
899 instance: null
900 });
901 } else if (isMulti) {
902 setAttributes({
903 id: null,
904 idBase: selectedId,
905 instance: {}
906 });
907 } else {
908 setAttributes({
909 id: selectedId,
910 idBase: null,
911 instance: null
912 });
913 }
914 }
915 }
916 ) }) })
917 }
918 );
919 }
920 function NotEmpty({
921 attributes: { id, idBase, instance },
922 setAttributes,
923 clientId,
924 isSelected,
925 isWide = false
926 }) {
927 const [hasPreview, setHasPreview] = (0, import_element3.useState)(null);
928 const widgetTypeId = id ?? idBase;
929 const { record: widgetType, hasResolved: hasResolvedWidgetType } = (0, import_core_data2.useEntityRecord)("root", "widgetType", widgetTypeId);
930 const setInstance = (0, import_element3.useCallback)((nextInstance) => {
931 setAttributes({ instance: nextInstance });
932 }, []);
933 if (!widgetType && hasResolvedWidgetType) {
934 return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
935 import_components5.Placeholder,
936 {
937 icon: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_block_editor3.BlockIcon, { icon: brush_default }),
938 label: (0, import_i18n7.__)("Legacy Widget"),
939 children: (0, import_i18n7.__)("Widget is missing.")
940 }
941 );
942 }
943 if (!hasResolvedWidgetType) {
944 return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_components5.Placeholder, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_components5.Spinner, {}) });
945 }
946 const mode = idBase && !isSelected ? "preview" : "edit";
947 return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
948 idBase === "text" && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_block_editor3.BlockControls, { group: "other", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
949 ConvertToBlocksButton,
950 {
951 clientId,
952 rawInstance: instance.raw
953 }
954 ) }),
955 /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_block_editor3.InspectorControls, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
956 InspectorCard,
957 {
958 name: widgetType.name,
959 description: widgetType.description
960 }
961 ) }),
962 /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
963 Form,
964 {
965 title: widgetType.name,
966 isVisible: mode === "edit",
967 id,
968 idBase,
969 instance,
970 isWide,
971 onChangeInstance: setInstance,
972 onChangeHasPreview: setHasPreview
973 }
974 ),
975 idBase && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
976 hasPreview === null && mode === "preview" && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_components5.Placeholder, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_components5.Spinner, {}) }),
977 hasPreview === true && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
978 Preview,
979 {
980 idBase,
981 instance,
982 isVisible: mode === "preview"
983 }
984 ),
985 hasPreview === false && mode === "preview" && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(NoPreview, { name: widgetType.name })
986 ] })
987 ] });
988 }
989
990 // packages/widgets/build-module/blocks/legacy-widget/transforms.mjs
991 var import_blocks2 = __toESM(require_blocks(), 1);
992 var legacyWidgetTransforms = [
993 {
994 block: "core/calendar",
995 widget: "calendar"
996 },
997 {
998 block: "core/search",
999 widget: "search"
1000 },
1001 {
1002 block: "core/html",
1003 widget: "custom_html",
1004 transformBlock: ({ content }) => (0, import_blocks2.createBlock)("core/html", {}, [], [content])
1005 },
1006 {
1007 block: "core/archives",
1008 widget: "archives",
1009 transform: ({ count, dropdown }) => {
1010 return {
1011 displayAsDropdown: !!dropdown,
1012 showPostCounts: !!count
1013 };
1014 }
1015 },
1016 {
1017 block: "core/latest-posts",
1018 widget: "recent-posts",
1019 transform: ({ show_date: displayPostDate, number }) => {
1020 return {
1021 displayPostDate: !!displayPostDate,
1022 postsToShow: number
1023 };
1024 }
1025 },
1026 {
1027 block: "core/latest-comments",
1028 widget: "recent-comments",
1029 transform: ({ number }) => {
1030 return {
1031 commentsToShow: number
1032 };
1033 }
1034 },
1035 {
1036 block: "core/tag-cloud",
1037 widget: "tag_cloud",
1038 transform: ({ taxonomy, count }) => {
1039 return {
1040 showTagCounts: !!count,
1041 taxonomy
1042 };
1043 }
1044 },
1045 {
1046 block: "core/categories",
1047 widget: "categories",
1048 transform: ({ count, dropdown, hierarchical }) => {
1049 return {
1050 displayAsDropdown: !!dropdown,
1051 showPostCounts: !!count,
1052 showHierarchy: !!hierarchical
1053 };
1054 }
1055 },
1056 {
1057 block: "core/audio",
1058 widget: "media_audio",
1059 transform: ({ url, preload, loop, attachment_id: id }) => {
1060 return {
1061 src: url,
1062 id,
1063 preload,
1064 loop
1065 };
1066 }
1067 },
1068 {
1069 block: "core/video",
1070 widget: "media_video",
1071 transform: ({ url, preload, loop, attachment_id: id }) => {
1072 return {
1073 src: url,
1074 id,
1075 preload,
1076 loop
1077 };
1078 }
1079 },
1080 {
1081 block: "core/image",
1082 widget: "media_image",
1083 transform: ({
1084 alt,
1085 attachment_id: id,
1086 caption,
1087 height,
1088 link_classes: linkClass,
1089 link_rel: rel,
1090 link_target_blank: targetBlack,
1091 link_type: linkDestination,
1092 link_url: link,
1093 size: sizeSlug,
1094 url,
1095 width
1096 }) => {
1097 return {
1098 alt,
1099 caption,
1100 height,
1101 id,
1102 link,
1103 linkClass,
1104 linkDestination,
1105 linkTarget: targetBlack ? "_blank" : void 0,
1106 rel,
1107 sizeSlug,
1108 url,
1109 width
1110 };
1111 }
1112 },
1113 {
1114 block: "core/gallery",
1115 widget: "media_gallery",
1116 transform: ({ ids, link_type: linkTo, size, number }) => {
1117 return {
1118 ids,
1119 columns: number,
1120 linkTo,
1121 sizeSlug: size,
1122 images: ids.map((id) => ({
1123 id
1124 }))
1125 };
1126 }
1127 },
1128 {
1129 block: "core/rss",
1130 widget: "rss",
1131 transform: ({
1132 url,
1133 show_author: displayAuthor,
1134 show_date: displayDate,
1135 show_summary: displayExcerpt,
1136 items
1137 }) => {
1138 return {
1139 feedURL: url,
1140 displayAuthor: !!displayAuthor,
1141 displayDate: !!displayDate,
1142 displayExcerpt: !!displayExcerpt,
1143 itemsToShow: items
1144 };
1145 }
1146 }
1147 ].map(({ block, widget, transform, transformBlock }) => {
1148 return {
1149 type: "block",
1150 blocks: [block],
1151 isMatch: ({ idBase, instance }) => {
1152 return idBase === widget && !!instance?.raw;
1153 },
1154 transform: ({ instance }) => {
1155 const transformedBlock = transformBlock ? transformBlock(instance.raw) : (0, import_blocks2.createBlock)(
1156 block,
1157 transform ? transform(instance.raw) : void 0
1158 );
1159 if (!instance.raw?.title) {
1160 return transformedBlock;
1161 }
1162 return [
1163 (0, import_blocks2.createBlock)("core/heading", {
1164 content: instance.raw.title
1165 }),
1166 transformedBlock
1167 ];
1168 }
1169 };
1170 });
1171 var transforms = {
1172 to: legacyWidgetTransforms
1173 };
1174 var transforms_default = transforms;
1175
1176 // packages/widgets/build-module/blocks/legacy-widget/index.mjs
1177 var { name } = block_default;
1178 var settings = {
1179 icon: widget_default,
1180 edit: Edit,
1181 transforms: transforms_default
1182 };
1183
1184 // packages/widgets/build-module/blocks/widget-group/index.mjs
1185 var widget_group_exports = {};
1186 __export(widget_group_exports, {
1187 metadata: () => block_default2,
1188 name: () => name2,
1189 settings: () => settings2
1190 });
1191 var import_i18n9 = __toESM(require_i18n(), 1);
1192 var import_blocks3 = __toESM(require_blocks(), 1);
1193
1194 // packages/widgets/build-module/blocks/widget-group/block.json
1195 var block_default2 = {
1196 $schema: "https://schemas.wp.org/trunk/block.json",
1197 apiVersion: 3,
1198 name: "core/widget-group",
1199 title: "Widget Group",
1200 category: "widgets",
1201 attributes: {
1202 title: {
1203 type: "string"
1204 }
1205 },
1206 supports: {
1207 html: false,
1208 inserter: true,
1209 customClassName: true,
1210 reusable: false
1211 },
1212 editorStyle: "wp-block-widget-group-editor",
1213 style: "wp-block-widget-group"
1214 };
1215
1216 // packages/widgets/build-module/blocks/widget-group/edit.mjs
1217 var import_block_editor4 = __toESM(require_block_editor(), 1);
1218 var import_components6 = __toESM(require_components(), 1);
1219 var import_i18n8 = __toESM(require_i18n(), 1);
1220 var import_data4 = __toESM(require_data(), 1);
1221 var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1);
1222 function Edit2(props) {
1223 const { clientId } = props;
1224 const hasInnerBlocks = (0, import_data4.useSelect)(
1225 (select2) => select2(import_block_editor4.store).getBlockCount(clientId) > 0,
1226 [clientId]
1227 );
1228 return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { ...(0, import_block_editor4.useBlockProps)({ className: "widget" }), children: !hasInnerBlocks ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(PlaceholderContent, { ...props }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(PreviewContent, { ...props }) });
1229 }
1230 function PlaceholderContent({ clientId }) {
1231 return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
1232 /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1233 import_components6.Placeholder,
1234 {
1235 className: "wp-block-widget-group__placeholder",
1236 icon: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_block_editor4.BlockIcon, { icon: group_default }),
1237 label: (0, import_i18n8.__)("Widget Group"),
1238 children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_block_editor4.ButtonBlockAppender, { rootClientId: clientId })
1239 }
1240 ),
1241 /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_block_editor4.InnerBlocks, { renderAppender: false })
1242 ] });
1243 }
1244 function PreviewContent({ attributes, setAttributes }) {
1245 return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
1246 /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1247 import_block_editor4.RichText,
1248 {
1249 tagName: "h2",
1250 identifier: "title",
1251 className: "widget-title",
1252 allowedFormats: [],
1253 placeholder: (0, import_i18n8.__)("Title"),
1254 value: attributes.title ?? "",
1255 onChange: (title) => setAttributes({ title })
1256 }
1257 ),
1258 /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_block_editor4.InnerBlocks, {})
1259 ] });
1260 }
1261
1262 // packages/widgets/build-module/blocks/widget-group/save.mjs
1263 var import_block_editor5 = __toESM(require_block_editor(), 1);
1264 var import_jsx_runtime13 = __toESM(require_jsx_runtime(), 1);
1265 function save({ attributes }) {
1266 return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
1267 /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1268 import_block_editor5.RichText.Content,
1269 {
1270 tagName: "h2",
1271 className: "widget-title",
1272 value: attributes.title
1273 }
1274 ),
1275 /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "wp-widget-group__inner-blocks", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_block_editor5.InnerBlocks.Content, {}) })
1276 ] });
1277 }
1278
1279 // packages/widgets/build-module/blocks/widget-group/deprecated.mjs
1280 var import_block_editor6 = __toESM(require_block_editor(), 1);
1281 var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1);
1282 var v1 = {
1283 attributes: {
1284 title: {
1285 type: "string"
1286 }
1287 },
1288 supports: {
1289 html: false,
1290 inserter: true,
1291 customClassName: true,
1292 reusable: false
1293 },
1294 save({ attributes }) {
1295 return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
1296 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1297 import_block_editor6.RichText.Content,
1298 {
1299 tagName: "h2",
1300 className: "widget-title",
1301 value: attributes.title
1302 }
1303 ),
1304 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_block_editor6.InnerBlocks.Content, {})
1305 ] });
1306 }
1307 };
1308 var deprecated_default = [v1];
1309
1310 // packages/widgets/build-module/blocks/widget-group/index.mjs
1311 var { name: name2 } = block_default2;
1312 var settings2 = {
1313 title: (0, import_i18n9.__)("Widget Group"),
1314 description: (0, import_i18n9.__)(
1315 "Create a classic widget layout with a title that\u2019s styled by your theme for your widget areas."
1316 ),
1317 icon: group_default,
1318 __experimentalLabel: ({ name: label }) => label,
1319 edit: Edit2,
1320 save,
1321 transforms: {
1322 from: [
1323 {
1324 type: "block",
1325 isMultiBlock: true,
1326 blocks: ["*"],
1327 isMatch(attributes, blocks) {
1328 return !blocks.some(
1329 (block) => block.name === "core/widget-group"
1330 );
1331 },
1332 __experimentalConvert(blocks) {
1333 let innerBlocks = blocks.map(
1334 (block) => (0, import_blocks3.cloneSanitizedBlock)(block)
1335 );
1336 const firstHeadingBlock = innerBlocks[0].name === "core/heading" ? innerBlocks[0] : null;
1337 innerBlocks = innerBlocks.filter(
1338 (block) => block !== firstHeadingBlock
1339 );
1340 return (0, import_blocks3.createBlock)(
1341 "core/widget-group",
1342 {
1343 ...firstHeadingBlock && {
1344 title: firstHeadingBlock.attributes.content
1345 }
1346 },
1347 innerBlocks
1348 );
1349 }
1350 }
1351 ]
1352 },
1353 deprecated: deprecated_default
1354 };
1355
1356 // packages/widgets/build-module/components/move-to-widget-area/index.mjs
1357 var import_components7 = __toESM(require_components(), 1);
1358 var import_i18n10 = __toESM(require_i18n(), 1);
1359 var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1);
1360 function MoveToWidgetArea({
1361 currentWidgetAreaId,
1362 widgetAreas,
1363 onSelect
1364 }) {
1365 return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_components7.ToolbarGroup, { children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_components7.ToolbarItem, { children: (toggleProps) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1366 import_components7.DropdownMenu,
1367 {
1368 icon: move_to_default,
1369 label: (0, import_i18n10.__)("Move to widget area"),
1370 toggleProps,
1371 children: ({ onClose }) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_components7.MenuGroup, { label: (0, import_i18n10.__)("Move to"), children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1372 import_components7.MenuItemsChoice,
1373 {
1374 choices: widgetAreas.map(
1375 (widgetArea) => ({
1376 value: widgetArea.id,
1377 label: widgetArea.name,
1378 info: widgetArea.description
1379 })
1380 ),
1381 value: currentWidgetAreaId,
1382 onSelect: (value) => {
1383 onSelect(value);
1384 onClose();
1385 }
1386 }
1387 ) })
1388 }
1389 ) }) });
1390 }
1391
1392 // packages/widgets/build-module/utils.mjs
1393 function getWidgetIdFromBlock(block) {
1394 return block.attributes.__internalWidgetId;
1395 }
1396 function addWidgetIdToBlock(block, widgetId) {
1397 return {
1398 ...block,
1399 attributes: {
1400 ...block.attributes || {},
1401 __internalWidgetId: widgetId
1402 }
1403 };
1404 }
1405
1406 // packages/widgets/build-module/register-legacy-widget-variations.mjs
1407 var import_data5 = __toESM(require_data(), 1);
1408 var import_core_data3 = __toESM(require_core_data(), 1);
1409 var import_blocks4 = __toESM(require_blocks(), 1);
1410 function registerLegacyWidgetVariations(settings3) {
1411 const unsubscribe = (0, import_data5.subscribe)(() => {
1412 const hiddenIds = settings3?.widgetTypesToHideFromLegacyWidgetBlock ?? [];
1413 const widgetTypes = (0, import_data5.select)(import_core_data3.store).getWidgetTypes({ per_page: -1 })?.filter((widgetType) => !hiddenIds.includes(widgetType.id));
1414 if (widgetTypes) {
1415 unsubscribe();
1416 (0, import_data5.dispatch)(import_blocks4.store).addBlockVariations(
1417 "core/legacy-widget",
1418 widgetTypes.map((widgetType) => ({
1419 name: widgetType.id,
1420 title: widgetType.name,
1421 description: widgetType.description,
1422 attributes: widgetType.is_multi ? {
1423 idBase: widgetType.id,
1424 instance: {}
1425 } : {
1426 id: widgetType.id
1427 }
1428 }))
1429 );
1430 }
1431 });
1432 }
1433
1434 // packages/widgets/build-module/index.mjs
1435 function registerLegacyWidgetBlock(supports = {}) {
1436 const { metadata, settings: settings3, name: name3 } = legacy_widget_exports;
1437 (0, import_blocks5.registerBlockType)(
1438 { name: name3, ...metadata },
1439 {
1440 ...settings3,
1441 supports: {
1442 ...settings3.supports,
1443 ...supports
1444 }
1445 }
1446 );
1447 }
1448 function registerWidgetGroupBlock(supports = {}) {
1449 const { metadata, settings: settings3, name: name3 } = widget_group_exports;
1450 (0, import_blocks5.registerBlockType)(
1451 { name: name3, ...metadata },
1452 {
1453 ...settings3,
1454 supports: {
1455 ...settings3.supports,
1456 ...supports
1457 }
1458 }
1459 );
1460 }
1461 return __toCommonJS(index_exports);
1462 })();
1463 (window.wp ||= {}).widgets = wp.widgets;
1464 })();
1465 //# sourceMappingURL=index.js.map
1466