PluginProbe
Gutenberg / 22.3.0
Gutenberg v22.3.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 7.4.0 All 402 releases
gutenberg / build / scripts / widgets / index.js

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

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