PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.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 All 404 releases
gutenberg / build / scripts / widgets / index.js

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

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