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

index.js in Gutenberg 21.7.0, at build/widgets/index.js

1,729 lines 52.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (() => { // webpackBootstrap
2 /******/ "use strict";
3 /******/ // The require scope
4 /******/ var __webpack_require__ = {};
5 /******/
6 /************************************************************************/
7 /******/ /* webpack/runtime/compat get default export */
8 /******/ (() => {
9 /******/ // getDefaultExport function for compatibility with non-harmony modules
10 /******/ __webpack_require__.n = (module) => {
11 /******/ var getter = module && module.__esModule ?
12 /******/ () => (module['default']) :
13 /******/ () => (module);
14 /******/ __webpack_require__.d(getter, { a: getter });
15 /******/ return getter;
16 /******/ };
17 /******/ })();
18 /******/
19 /******/ /* webpack/runtime/define property getters */
20 /******/ (() => {
21 /******/ // define getter functions for harmony exports
22 /******/ __webpack_require__.d = (exports, definition) => {
23 /******/ for(var key in definition) {
24 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
25 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
26 /******/ }
27 /******/ }
28 /******/ };
29 /******/ })();
30 /******/
31 /******/ /* webpack/runtime/hasOwnProperty shorthand */
32 /******/ (() => {
33 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
34 /******/ })();
35 /******/
36 /******/ /* webpack/runtime/make namespace object */
37 /******/ (() => {
38 /******/ // define __esModule on exports
39 /******/ __webpack_require__.r = (exports) => {
40 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
41 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
42 /******/ }
43 /******/ Object.defineProperty(exports, '__esModule', { value: true });
44 /******/ };
45 /******/ })();
46 /******/
47 /************************************************************************/
48 var __webpack_exports__ = {};
49 // ESM COMPAT FLAG
50 __webpack_require__.r(__webpack_exports__);
51
52 // EXPORTS
53 __webpack_require__.d(__webpack_exports__, {
54 MoveToWidgetArea: () => (/* reexport */ MoveToWidgetArea),
55 addWidgetIdToBlock: () => (/* reexport */ addWidgetIdToBlock),
56 getWidgetIdFromBlock: () => (/* reexport */ getWidgetIdFromBlock),
57 registerLegacyWidgetBlock: () => (/* binding */ registerLegacyWidgetBlock),
58 registerLegacyWidgetVariations: () => (/* reexport */ registerLegacyWidgetVariations),
59 registerWidgetGroupBlock: () => (/* binding */ registerWidgetGroupBlock)
60 });
61
62 // NAMESPACE OBJECT: ./packages/widgets/build-module/blocks/legacy-widget/index.js
63 var legacy_widget_namespaceObject = {};
64 __webpack_require__.r(legacy_widget_namespaceObject);
65 __webpack_require__.d(legacy_widget_namespaceObject, {
66 yu: () => (metadata),
67 UU: () => (legacy_widget_name),
68 W0: () => (settings)
69 });
70
71 // NAMESPACE OBJECT: ./packages/widgets/build-module/blocks/widget-group/index.js
72 var widget_group_namespaceObject = {};
73 __webpack_require__.r(widget_group_namespaceObject);
74 __webpack_require__.d(widget_group_namespaceObject, {
75 yu: () => (widget_group_metadata),
76 UU: () => (widget_group_name),
77 W0: () => (widget_group_settings)
78 });
79
80 ;// external ["wp","blocks"]
81 const external_wp_blocks_namespaceObject = window["wp"]["blocks"];
82 ;// external ["wp","primitives"]
83 const external_wp_primitives_namespaceObject = window["wp"]["primitives"];
84 ;// external "ReactJSXRuntime"
85 const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
86 ;// ./packages/icons/build-module/library/widget.js
87 /**
88 * WordPress dependencies
89 */
90
91
92 const widget = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
93 xmlns: "http://www.w3.org/2000/svg",
94 viewBox: "0 0 24 24",
95 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
96 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"
97 })
98 });
99 /* harmony default export */ const library_widget = (widget);
100
101 ;// ./node_modules/clsx/dist/clsx.mjs
102 function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f)}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}/* harmony default export */ const dist_clsx = (clsx);
103 ;// external ["wp","blockEditor"]
104 const external_wp_blockEditor_namespaceObject = window["wp"]["blockEditor"];
105 ;// external ["wp","components"]
106 const external_wp_components_namespaceObject = window["wp"]["components"];
107 ;// ./packages/icons/build-module/library/brush.js
108 /**
109 * WordPress dependencies
110 */
111
112
113 const brush = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
114 xmlns: "http://www.w3.org/2000/svg",
115 viewBox: "0 0 24 24",
116 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
117 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"
118 })
119 });
120 /* harmony default export */ const library_brush = (brush);
121
122 ;// external ["wp","i18n"]
123 const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
124 ;// external ["wp","element"]
125 const external_wp_element_namespaceObject = window["wp"]["element"];
126 ;// external ["wp","coreData"]
127 const external_wp_coreData_namespaceObject = window["wp"]["coreData"];
128 ;// external ["wp","data"]
129 const external_wp_data_namespaceObject = window["wp"]["data"];
130 ;// ./packages/widgets/build-module/blocks/legacy-widget/edit/widget-type-selector.js
131 /**
132 * WordPress dependencies
133 */
134
135
136
137
138
139
140 function WidgetTypeSelector({
141 selectedId,
142 onSelect
143 }) {
144 const widgetTypes = (0,external_wp_data_namespaceObject.useSelect)(select => {
145 var _select$getSettings$w;
146 const hiddenIds = (_select$getSettings$w = select(external_wp_blockEditor_namespaceObject.store).getSettings()?.widgetTypesToHideFromLegacyWidgetBlock) !== null && _select$getSettings$w !== void 0 ? _select$getSettings$w : [];
147 return select(external_wp_coreData_namespaceObject.store).getWidgetTypes({
148 per_page: -1
149 })?.filter(widgetType => !hiddenIds.includes(widgetType.id));
150 }, []);
151 if (!widgetTypes) {
152 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Spinner, {});
153 }
154 if (widgetTypes.length === 0) {
155 return (0,external_wp_i18n_namespaceObject.__)('There are no widgets available.');
156 }
157 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.SelectControl, {
158 __next40pxDefaultSize: true,
159 __nextHasNoMarginBottom: true,
160 label: (0,external_wp_i18n_namespaceObject.__)('Legacy widget'),
161 value: selectedId !== null && selectedId !== void 0 ? selectedId : '',
162 options: [{
163 value: '',
164 label: (0,external_wp_i18n_namespaceObject.__)('Select widget')
165 }, ...widgetTypes.map(widgetType => ({
166 value: widgetType.id,
167 label: widgetType.name
168 }))],
169 onChange: value => {
170 if (value) {
171 const selected = widgetTypes.find(widgetType => widgetType.id === value);
172 onSelect({
173 selectedId: selected.id,
174 isMulti: selected.is_multi
175 });
176 } else {
177 onSelect({
178 selectedId: null
179 });
180 }
181 }
182 });
183 }
184
185 ;// ./packages/widgets/build-module/blocks/legacy-widget/edit/inspector-card.js
186
187 function InspectorCard({
188 name,
189 description
190 }) {
191 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
192 className: "wp-block-legacy-widget-inspector-card",
193 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("h3", {
194 className: "wp-block-legacy-widget-inspector-card__name",
195 children: name
196 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("span", {
197 children: description
198 })]
199 });
200 }
201
202 ;// external ["wp","notices"]
203 const external_wp_notices_namespaceObject = window["wp"]["notices"];
204 ;// external ["wp","compose"]
205 const external_wp_compose_namespaceObject = window["wp"]["compose"];
206 ;// external ["wp","apiFetch"]
207 const external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"];
208 var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject);
209 ;// ./packages/widgets/build-module/blocks/legacy-widget/edit/control.js
210 /* wp:polyfill */
211 /**
212 * WordPress dependencies
213 */
214
215
216
217
218 /**
219 * An API for creating and loading a widget control (a <div class="widget">
220 * element) that is compatible with most third party widget scripts. By not
221 * using React for this, we ensure that we have complete control over the DOM
222 * and do not accidentally remove any elements that a third party widget script
223 * has attached an event listener to.
224 *
225 * @property {Element} element The control's DOM element.
226 */
227 class Control {
228 /**
229 * Creates and loads a new control.
230 *
231 * @access public
232 * @param {Object} params
233 * @param {string} params.id
234 * @param {string} params.idBase
235 * @param {Object} params.instance
236 * @param {Function} params.onChangeInstance
237 * @param {Function} params.onChangeHasPreview
238 * @param {Function} params.onError
239 */
240 constructor({
241 id,
242 idBase,
243 instance,
244 onChangeInstance,
245 onChangeHasPreview,
246 onError
247 }) {
248 this.id = id;
249 this.idBase = idBase;
250 this._instance = instance;
251 this._hasPreview = null;
252 this.onChangeInstance = onChangeInstance;
253 this.onChangeHasPreview = onChangeHasPreview;
254 this.onError = onError;
255
256 // We can't use the real widget number as this is calculated by the
257 // server and we may not ever *actually* save this widget. Instead, use
258 // a fake but unique number.
259 this.number = ++lastNumber;
260 this.handleFormChange = (0,external_wp_compose_namespaceObject.debounce)(this.handleFormChange.bind(this), 200);
261 this.handleFormSubmit = this.handleFormSubmit.bind(this);
262 this.initDOM();
263 this.bindEvents();
264 this.loadContent();
265 }
266
267 /**
268 * Clean up the control so that it can be garbage collected.
269 *
270 * @access public
271 */
272 destroy() {
273 this.unbindEvents();
274 this.element.remove();
275 // TODO: How do we make third party widget scripts remove their event
276 // listeners?
277 }
278
279 /**
280 * Creates the control's DOM structure.
281 *
282 * @access private
283 */
284 initDOM() {
285 var _this$id, _this$idBase;
286 this.element = el('div', {
287 class: 'widget open'
288 }, [el('div', {
289 class: 'widget-inside'
290 }, [this.form = el('form', {
291 class: 'form',
292 method: 'post'
293 }, [
294 // These hidden form inputs are what most widgets' scripts
295 // use to access data about the widget.
296 el('input', {
297 class: 'widget-id',
298 type: 'hidden',
299 name: 'widget-id',
300 value: (_this$id = this.id) !== null && _this$id !== void 0 ? _this$id : `${this.idBase}-${this.number}`
301 }), el('input', {
302 class: 'id_base',
303 type: 'hidden',
304 name: 'id_base',
305 value: (_this$idBase = this.idBase) !== null && _this$idBase !== void 0 ? _this$idBase : this.id
306 }), el('input', {
307 class: 'widget-width',
308 type: 'hidden',
309 name: 'widget-width',
310 value: '250'
311 }), el('input', {
312 class: 'widget-height',
313 type: 'hidden',
314 name: 'widget-height',
315 value: '200'
316 }), el('input', {
317 class: 'widget_number',
318 type: 'hidden',
319 name: 'widget_number',
320 value: this.idBase ? this.number.toString() : ''
321 }), this.content = el('div', {
322 class: 'widget-content'
323 }),
324 // Non-multi widgets can be saved via a Save button.
325 this.id && el('button', {
326 class: 'button is-primary',
327 type: 'submit'
328 }, (0,external_wp_i18n_namespaceObject.__)('Save'))])])]);
329 }
330
331 /**
332 * Adds the control's event listeners.
333 *
334 * @access private
335 */
336 bindEvents() {
337 // Prefer jQuery 'change' event instead of the native 'change' event
338 // because many widgets use jQuery's event bus to trigger an update.
339 if (window.jQuery) {
340 const {
341 jQuery: $
342 } = window;
343 $(this.form).on('change', null, this.handleFormChange);
344 $(this.form).on('input', null, this.handleFormChange);
345 $(this.form).on('submit', this.handleFormSubmit);
346 } else {
347 this.form.addEventListener('change', this.handleFormChange);
348 this.form.addEventListener('input', this.handleFormChange);
349 this.form.addEventListener('submit', this.handleFormSubmit);
350 }
351 }
352
353 /**
354 * Removes the control's event listeners.
355 *
356 * @access private
357 */
358 unbindEvents() {
359 if (window.jQuery) {
360 const {
361 jQuery: $
362 } = window;
363 $(this.form).off('change', null, this.handleFormChange);
364 $(this.form).off('input', null, this.handleFormChange);
365 $(this.form).off('submit', this.handleFormSubmit);
366 } else {
367 this.form.removeEventListener('change', this.handleFormChange);
368 this.form.removeEventListener('input', this.handleFormChange);
369 this.form.removeEventListener('submit', this.handleFormSubmit);
370 }
371 }
372
373 /**
374 * Fetches the widget's form HTML from the REST API and loads it into the
375 * control's form.
376 *
377 * @access private
378 */
379 async loadContent() {
380 try {
381 if (this.id) {
382 const {
383 form
384 } = await saveWidget(this.id);
385 this.content.innerHTML = form;
386 } else if (this.idBase) {
387 const {
388 form,
389 preview
390 } = await encodeWidget({
391 idBase: this.idBase,
392 instance: this.instance,
393 number: this.number
394 });
395 this.content.innerHTML = form;
396 this.hasPreview = !isEmptyHTML(preview);
397
398 // If we don't have an instance, perform a save right away. This
399 // happens when creating a new Legacy Widget block.
400 if (!this.instance.hash) {
401 const {
402 instance
403 } = await encodeWidget({
404 idBase: this.idBase,
405 instance: this.instance,
406 number: this.number,
407 formData: serializeForm(this.form)
408 });
409 this.instance = instance;
410 }
411 }
412
413 // Trigger 'widget-added' when widget is ready. This event is what
414 // widgets' scripts use to initialize, attach events, etc. The event
415 // must be fired using jQuery's event bus as this is what widget
416 // scripts expect. If jQuery is not loaded, do nothing - some
417 // widgets will still work regardless.
418 if (window.jQuery) {
419 const {
420 jQuery: $
421 } = window;
422 $(document).trigger('widget-added', [$(this.element)]);
423 }
424 } catch (error) {
425 this.onError(error);
426 }
427 }
428
429 /**
430 * Perform a save when a multi widget's form is changed. Non-multi widgets
431 * are saved manually.
432 *
433 * @access private
434 */
435 handleFormChange() {
436 if (this.idBase) {
437 this.saveForm();
438 }
439 }
440
441 /**
442 * Perform a save when the control's form is manually submitted.
443 *
444 * @access private
445 * @param {Event} event
446 */
447 handleFormSubmit(event) {
448 event.preventDefault();
449 this.saveForm();
450 }
451
452 /**
453 * Serialize the control's form, send it to the REST API, and update the
454 * instance with the encoded instance that the REST API returns.
455 *
456 * @access private
457 */
458 async saveForm() {
459 const formData = serializeForm(this.form);
460 try {
461 if (this.id) {
462 const {
463 form
464 } = await saveWidget(this.id, formData);
465 this.content.innerHTML = form;
466 if (window.jQuery) {
467 const {
468 jQuery: $
469 } = window;
470 $(document).trigger('widget-updated', [$(this.element)]);
471 }
472 } else if (this.idBase) {
473 const {
474 instance,
475 preview
476 } = await encodeWidget({
477 idBase: this.idBase,
478 instance: this.instance,
479 number: this.number,
480 formData
481 });
482 this.instance = instance;
483 this.hasPreview = !isEmptyHTML(preview);
484 }
485 } catch (error) {
486 this.onError(error);
487 }
488 }
489
490 /**
491 * The widget's instance object.
492 *
493 * @access private
494 */
495 get instance() {
496 return this._instance;
497 }
498
499 /**
500 * The widget's instance object.
501 *
502 * @access private
503 */
504 set instance(instance) {
505 if (this._instance !== instance) {
506 this._instance = instance;
507 this.onChangeInstance(instance);
508 }
509 }
510
511 /**
512 * Whether or not the widget can be previewed.
513 *
514 * @access public
515 */
516 get hasPreview() {
517 return this._hasPreview;
518 }
519
520 /**
521 * Whether or not the widget can be previewed.
522 *
523 * @access private
524 */
525 set hasPreview(hasPreview) {
526 if (this._hasPreview !== hasPreview) {
527 this._hasPreview = hasPreview;
528 this.onChangeHasPreview(hasPreview);
529 }
530 }
531 }
532 let lastNumber = 0;
533 function el(tagName, attributes = {}, content = null) {
534 const element = document.createElement(tagName);
535 for (const [attribute, value] of Object.entries(attributes)) {
536 element.setAttribute(attribute, value);
537 }
538 if (Array.isArray(content)) {
539 for (const child of content) {
540 if (child) {
541 element.appendChild(child);
542 }
543 }
544 } else if (typeof content === 'string') {
545 element.innerText = content;
546 }
547 return element;
548 }
549 async function saveWidget(id, formData = null) {
550 let widget;
551 if (formData) {
552 widget = await external_wp_apiFetch_default()({
553 path: `/wp/v2/widgets/${id}?context=edit`,
554 method: 'PUT',
555 data: {
556 form_data: formData
557 }
558 });
559 } else {
560 widget = await external_wp_apiFetch_default()({
561 path: `/wp/v2/widgets/${id}?context=edit`,
562 method: 'GET'
563 });
564 }
565 return {
566 form: widget.rendered_form
567 };
568 }
569 async function encodeWidget({
570 idBase,
571 instance,
572 number,
573 formData = null
574 }) {
575 const response = await external_wp_apiFetch_default()({
576 path: `/wp/v2/widget-types/${idBase}/encode`,
577 method: 'POST',
578 data: {
579 instance,
580 number,
581 form_data: formData
582 }
583 });
584 return {
585 instance: response.instance,
586 form: response.form,
587 preview: response.preview
588 };
589 }
590 function isEmptyHTML(html) {
591 const element = document.createElement('div');
592 element.innerHTML = html;
593 return isEmptyNode(element);
594 }
595 function isEmptyNode(node) {
596 switch (node.nodeType) {
597 case node.TEXT_NODE:
598 // Text nodes are empty if it's entirely whitespace.
599 return node.nodeValue.trim() === '';
600 case node.ELEMENT_NODE:
601 // Elements that are "embedded content" are not empty.
602 // https://dev.w3.org/html5/spec-LC/content-models.html#embedded-content-0
603 if (['AUDIO', 'CANVAS', 'EMBED', 'IFRAME', 'IMG', 'MATH', 'OBJECT', 'SVG', 'VIDEO'].includes(node.tagName)) {
604 return false;
605 }
606 // Elements with no children are empty.
607 if (!node.hasChildNodes()) {
608 return true;
609 }
610 // Elements with children are empty if all their children are empty.
611 return Array.from(node.childNodes).every(isEmptyNode);
612 default:
613 return true;
614 }
615 }
616 function serializeForm(form) {
617 return new window.URLSearchParams(Array.from(new window.FormData(form))).toString();
618 }
619
620 ;// ./packages/widgets/build-module/blocks/legacy-widget/edit/form.js
621 /**
622 * External dependencies
623 */
624
625 /**
626 * WordPress dependencies
627 */
628
629
630
631
632
633
634 /**
635 * Internal dependencies
636 */
637
638
639 function Form({
640 title,
641 isVisible,
642 id,
643 idBase,
644 instance,
645 isWide,
646 onChangeInstance,
647 onChangeHasPreview
648 }) {
649 const ref = (0,external_wp_element_namespaceObject.useRef)();
650 const isMediumLargeViewport = (0,external_wp_compose_namespaceObject.useViewportMatch)('small');
651
652 // We only want to remount the control when the instance changes
653 // *externally*. For example, if the user performs an undo. To do this, we
654 // keep track of changes made to instance by the control itself and then
655 // ignore those.
656 const outgoingInstances = (0,external_wp_element_namespaceObject.useRef)(new Set());
657 const incomingInstances = (0,external_wp_element_namespaceObject.useRef)(new Set());
658 const {
659 createNotice
660 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store);
661 (0,external_wp_element_namespaceObject.useEffect)(() => {
662 if (incomingInstances.current.has(instance)) {
663 incomingInstances.current.delete(instance);
664 return;
665 }
666 const control = new Control({
667 id,
668 idBase,
669 instance,
670 onChangeInstance(nextInstance) {
671 outgoingInstances.current.add(instance);
672 incomingInstances.current.add(nextInstance);
673 onChangeInstance(nextInstance);
674 },
675 onChangeHasPreview,
676 onError(error) {
677 window.console.error(error);
678 createNotice('error', (0,external_wp_i18n_namespaceObject.sprintf)(/* translators: %s: the name of the affected block. */
679 (0,external_wp_i18n_namespaceObject.__)('The "%s" block was affected by errors and may not function properly. Check the developer tools for more details.'), idBase || id));
680 }
681 });
682 ref.current.appendChild(control.element);
683 return () => {
684 if (outgoingInstances.current.has(instance)) {
685 outgoingInstances.current.delete(instance);
686 return;
687 }
688 control.destroy();
689 };
690 }, [id, idBase, instance, onChangeInstance, onChangeHasPreview, isMediumLargeViewport]);
691 if (isWide && isMediumLargeViewport) {
692 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
693 className: dist_clsx({
694 'wp-block-legacy-widget__container': isVisible
695 }),
696 children: [isVisible && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("h3", {
697 className: "wp-block-legacy-widget__edit-form-title",
698 children: title
699 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Popover, {
700 focusOnMount: false,
701 placement: "right",
702 offset: 32,
703 resize: false,
704 flip: false,
705 shift: true,
706 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
707 ref: ref,
708 className: "wp-block-legacy-widget__edit-form",
709 hidden: !isVisible
710 })
711 })]
712 });
713 }
714 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
715 ref: ref,
716 className: "wp-block-legacy-widget__edit-form",
717 hidden: !isVisible,
718 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("h3", {
719 className: "wp-block-legacy-widget__edit-form-title",
720 children: title
721 })
722 });
723 }
724
725 ;// ./packages/widgets/build-module/blocks/legacy-widget/edit/preview.js
726 /**
727 * External dependencies
728 */
729
730
731 /**
732 * WordPress dependencies
733 */
734
735
736
737
738
739
740 function Preview({
741 idBase,
742 instance,
743 isVisible
744 }) {
745 const [isLoaded, setIsLoaded] = (0,external_wp_element_namespaceObject.useState)(false);
746 const [srcDoc, setSrcDoc] = (0,external_wp_element_namespaceObject.useState)('');
747 (0,external_wp_element_namespaceObject.useEffect)(() => {
748 const abortController = typeof window.AbortController === 'undefined' ? undefined : new window.AbortController();
749 async function fetchPreviewHTML() {
750 const restRoute = `/wp/v2/widget-types/${idBase}/render`;
751 return await external_wp_apiFetch_default()({
752 path: restRoute,
753 method: 'POST',
754 signal: abortController?.signal,
755 data: instance ? {
756 instance
757 } : {}
758 });
759 }
760 fetchPreviewHTML().then(response => {
761 setSrcDoc(response.preview);
762 }).catch(error => {
763 if ('AbortError' === error.name) {
764 // We don't want to log aborted requests.
765 return;
766 }
767 throw error;
768 });
769 return () => abortController?.abort();
770 }, [idBase, instance]);
771
772 // Resize the iframe on either the load event, or when the iframe becomes visible.
773 const ref = (0,external_wp_compose_namespaceObject.useRefEffect)(iframe => {
774 // Only set height if the iframe is loaded,
775 // or it will grow to an unexpected large height in Safari if it's hidden initially.
776 if (!isLoaded) {
777 return;
778 }
779 // If the preview frame has another origin then this won't work.
780 // One possible solution is to add custom script to call `postMessage` in the preview frame.
781 // Or, better yet, we migrate away from iframe.
782 function setHeight() {
783 var _iframe$contentDocume, _iframe$contentDocume2;
784 // Pick the maximum of these two values to account for margin collapsing.
785 const height = Math.max((_iframe$contentDocume = iframe.contentDocument.documentElement?.offsetHeight) !== null && _iframe$contentDocume !== void 0 ? _iframe$contentDocume : 0, (_iframe$contentDocume2 = iframe.contentDocument.body?.offsetHeight) !== null && _iframe$contentDocume2 !== void 0 ? _iframe$contentDocume2 : 0);
786
787 // Fallback to a height of 100px if the height cannot be determined.
788 // This ensures the block is still selectable. 100px should hopefully
789 // be not so big that it's annoying, and not so small that nothing
790 // can be seen.
791 iframe.style.height = `${height !== 0 ? height : 100}px`;
792 }
793 const {
794 IntersectionObserver
795 } = iframe.ownerDocument.defaultView;
796
797 // Observe for intersections that might cause a change in the height of
798 // the iframe, e.g. a Widget Area becoming expanded.
799 const intersectionObserver = new IntersectionObserver(([entry]) => {
800 if (entry.isIntersecting) {
801 setHeight();
802 }
803 }, {
804 threshold: 1
805 });
806 intersectionObserver.observe(iframe);
807 iframe.addEventListener('load', setHeight);
808 return () => {
809 intersectionObserver.disconnect();
810 iframe.removeEventListener('load', setHeight);
811 };
812 }, [isLoaded]);
813 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
814 children: [isVisible && !isLoaded && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, {
815 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Spinner, {})
816 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
817 className: dist_clsx('wp-block-legacy-widget__edit-preview', {
818 'is-offscreen': !isVisible || !isLoaded
819 }),
820 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Disabled, {
821 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("iframe", {
822 ref: ref,
823 className: "wp-block-legacy-widget__edit-preview-iframe",
824 tabIndex: "-1",
825 title: (0,external_wp_i18n_namespaceObject.__)('Legacy Widget Preview'),
826 srcDoc: srcDoc,
827 onLoad: event => {
828 // To hide the scrollbars of the preview frame for some edge cases,
829 // such as negative margins in the Gallery Legacy Widget.
830 // It can't be scrolled anyway.
831 // TODO: Ideally, this should be fixed in core.
832 event.target.contentDocument.body.style.overflow = 'hidden';
833 setIsLoaded(true);
834 },
835 height: 100
836 })
837 })
838 })]
839 });
840 }
841
842 ;// ./packages/widgets/build-module/blocks/legacy-widget/edit/no-preview.js
843 /**
844 * WordPress dependencies
845 */
846
847
848 function NoPreview({
849 name
850 }) {
851 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
852 className: "wp-block-legacy-widget__edit-no-preview",
853 children: [name && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("h3", {
854 children: name
855 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("p", {
856 children: (0,external_wp_i18n_namespaceObject.__)('No preview available.')
857 })]
858 });
859 }
860
861 ;// ./packages/widgets/build-module/blocks/legacy-widget/edit/convert-to-blocks-button.js
862 /**
863 * WordPress dependencies
864 */
865
866
867
868
869
870
871 function ConvertToBlocksButton({
872 clientId,
873 rawInstance
874 }) {
875 const {
876 replaceBlocks
877 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
878 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.ToolbarButton, {
879 onClick: () => {
880 if (rawInstance.title) {
881 replaceBlocks(clientId, [(0,external_wp_blocks_namespaceObject.createBlock)('core/heading', {
882 content: rawInstance.title
883 }), ...(0,external_wp_blocks_namespaceObject.rawHandler)({
884 HTML: rawInstance.text
885 })]);
886 } else {
887 replaceBlocks(clientId, (0,external_wp_blocks_namespaceObject.rawHandler)({
888 HTML: rawInstance.text
889 }));
890 }
891 },
892 children: (0,external_wp_i18n_namespaceObject.__)('Convert to blocks')
893 });
894 }
895
896 ;// ./packages/widgets/build-module/blocks/legacy-widget/edit/index.js
897 /**
898 * External dependencies
899 */
900
901
902 /**
903 * WordPress dependencies
904 */
905
906
907
908
909
910
911
912 /**
913 * Internal dependencies
914 */
915
916
917
918
919
920
921
922 function Edit(props) {
923 const {
924 id,
925 idBase
926 } = props.attributes;
927 const {
928 isWide = false
929 } = props;
930 const blockProps = (0,external_wp_blockEditor_namespaceObject.useBlockProps)({
931 className: dist_clsx({
932 'is-wide-widget': isWide
933 })
934 });
935 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
936 ...blockProps,
937 children: !id && !idBase ? /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Empty, {
938 ...props
939 }) : /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(NotEmpty, {
940 ...props
941 })
942 });
943 }
944 function Empty({
945 attributes: {
946 id,
947 idBase
948 },
949 setAttributes
950 }) {
951 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, {
952 icon: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.BlockIcon, {
953 icon: library_brush
954 }),
955 label: (0,external_wp_i18n_namespaceObject.__)('Legacy Widget'),
956 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Flex, {
957 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.FlexBlock, {
958 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WidgetTypeSelector, {
959 selectedId: id !== null && id !== void 0 ? id : idBase,
960 onSelect: ({
961 selectedId,
962 isMulti
963 }) => {
964 if (!selectedId) {
965 setAttributes({
966 id: null,
967 idBase: null,
968 instance: null
969 });
970 } else if (isMulti) {
971 setAttributes({
972 id: null,
973 idBase: selectedId,
974 instance: {}
975 });
976 } else {
977 setAttributes({
978 id: selectedId,
979 idBase: null,
980 instance: null
981 });
982 }
983 }
984 })
985 })
986 })
987 });
988 }
989 function NotEmpty({
990 attributes: {
991 id,
992 idBase,
993 instance
994 },
995 setAttributes,
996 clientId,
997 isSelected,
998 isWide = false
999 }) {
1000 const [hasPreview, setHasPreview] = (0,external_wp_element_namespaceObject.useState)(null);
1001 const widgetTypeId = id !== null && id !== void 0 ? id : idBase;
1002 const {
1003 record: widgetType,
1004 hasResolved: hasResolvedWidgetType
1005 } = (0,external_wp_coreData_namespaceObject.useEntityRecord)('root', 'widgetType', widgetTypeId);
1006 const setInstance = (0,external_wp_element_namespaceObject.useCallback)(nextInstance => {
1007 setAttributes({
1008 instance: nextInstance
1009 });
1010 }, []);
1011 if (!widgetType && hasResolvedWidgetType) {
1012 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, {
1013 icon: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.BlockIcon, {
1014 icon: library_brush
1015 }),
1016 label: (0,external_wp_i18n_namespaceObject.__)('Legacy Widget'),
1017 children: (0,external_wp_i18n_namespaceObject.__)('Widget is missing.')
1018 });
1019 }
1020 if (!hasResolvedWidgetType) {
1021 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, {
1022 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Spinner, {})
1023 });
1024 }
1025 const mode = idBase && !isSelected ? 'preview' : 'edit';
1026 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1027 children: [idBase === 'text' && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.BlockControls, {
1028 group: "other",
1029 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ConvertToBlocksButton, {
1030 clientId: clientId,
1031 rawInstance: instance.raw
1032 })
1033 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.InspectorControls, {
1034 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(InspectorCard, {
1035 name: widgetType.name,
1036 description: widgetType.description
1037 })
1038 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Form, {
1039 title: widgetType.name,
1040 isVisible: mode === 'edit',
1041 id: id,
1042 idBase: idBase,
1043 instance: instance,
1044 isWide: isWide,
1045 onChangeInstance: setInstance,
1046 onChangeHasPreview: setHasPreview
1047 }), idBase && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1048 children: [hasPreview === null && mode === 'preview' && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, {
1049 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Spinner, {})
1050 }), hasPreview === true && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Preview, {
1051 idBase: idBase,
1052 instance: instance,
1053 isVisible: mode === 'preview'
1054 }), hasPreview === false && mode === 'preview' && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(NoPreview, {
1055 name: widgetType.name
1056 })]
1057 })]
1058 });
1059 }
1060
1061 ;// ./packages/widgets/build-module/blocks/legacy-widget/transforms.js
1062 /**
1063 * WordPress dependencies
1064 */
1065
1066 const legacyWidgetTransforms = [{
1067 block: 'core/calendar',
1068 widget: 'calendar'
1069 }, {
1070 block: 'core/search',
1071 widget: 'search'
1072 }, {
1073 block: 'core/html',
1074 widget: 'custom_html',
1075 transform: ({
1076 content
1077 }) => ({
1078 content
1079 })
1080 }, {
1081 block: 'core/archives',
1082 widget: 'archives',
1083 transform: ({
1084 count,
1085 dropdown
1086 }) => {
1087 return {
1088 displayAsDropdown: !!dropdown,
1089 showPostCounts: !!count
1090 };
1091 }
1092 }, {
1093 block: 'core/latest-posts',
1094 widget: 'recent-posts',
1095 transform: ({
1096 show_date: displayPostDate,
1097 number
1098 }) => {
1099 return {
1100 displayPostDate: !!displayPostDate,
1101 postsToShow: number
1102 };
1103 }
1104 }, {
1105 block: 'core/latest-comments',
1106 widget: 'recent-comments',
1107 transform: ({
1108 number
1109 }) => {
1110 return {
1111 commentsToShow: number
1112 };
1113 }
1114 }, {
1115 block: 'core/tag-cloud',
1116 widget: 'tag_cloud',
1117 transform: ({
1118 taxonomy,
1119 count
1120 }) => {
1121 return {
1122 showTagCounts: !!count,
1123 taxonomy
1124 };
1125 }
1126 }, {
1127 block: 'core/categories',
1128 widget: 'categories',
1129 transform: ({
1130 count,
1131 dropdown,
1132 hierarchical
1133 }) => {
1134 return {
1135 displayAsDropdown: !!dropdown,
1136 showPostCounts: !!count,
1137 showHierarchy: !!hierarchical
1138 };
1139 }
1140 }, {
1141 block: 'core/audio',
1142 widget: 'media_audio',
1143 transform: ({
1144 url,
1145 preload,
1146 loop,
1147 attachment_id: id
1148 }) => {
1149 return {
1150 src: url,
1151 id,
1152 preload,
1153 loop
1154 };
1155 }
1156 }, {
1157 block: 'core/video',
1158 widget: 'media_video',
1159 transform: ({
1160 url,
1161 preload,
1162 loop,
1163 attachment_id: id
1164 }) => {
1165 return {
1166 src: url,
1167 id,
1168 preload,
1169 loop
1170 };
1171 }
1172 }, {
1173 block: 'core/image',
1174 widget: 'media_image',
1175 transform: ({
1176 alt,
1177 attachment_id: id,
1178 caption,
1179 height,
1180 link_classes: linkClass,
1181 link_rel: rel,
1182 link_target_blank: targetBlack,
1183 link_type: linkDestination,
1184 link_url: link,
1185 size: sizeSlug,
1186 url,
1187 width
1188 }) => {
1189 return {
1190 alt,
1191 caption,
1192 height,
1193 id,
1194 link,
1195 linkClass,
1196 linkDestination,
1197 linkTarget: targetBlack ? '_blank' : undefined,
1198 rel,
1199 sizeSlug,
1200 url,
1201 width
1202 };
1203 }
1204 }, {
1205 block: 'core/gallery',
1206 widget: 'media_gallery',
1207 transform: ({
1208 ids,
1209 link_type: linkTo,
1210 size,
1211 number
1212 }) => {
1213 return {
1214 ids,
1215 columns: number,
1216 linkTo,
1217 sizeSlug: size,
1218 images: ids.map(id => ({
1219 id
1220 }))
1221 };
1222 }
1223 }, {
1224 block: 'core/rss',
1225 widget: 'rss',
1226 transform: ({
1227 url,
1228 show_author: displayAuthor,
1229 show_date: displayDate,
1230 show_summary: displayExcerpt,
1231 items
1232 }) => {
1233 return {
1234 feedURL: url,
1235 displayAuthor: !!displayAuthor,
1236 displayDate: !!displayDate,
1237 displayExcerpt: !!displayExcerpt,
1238 itemsToShow: items
1239 };
1240 }
1241 }].map(({
1242 block,
1243 widget,
1244 transform
1245 }) => {
1246 return {
1247 type: 'block',
1248 blocks: [block],
1249 isMatch: ({
1250 idBase,
1251 instance
1252 }) => {
1253 return idBase === widget && !!instance?.raw;
1254 },
1255 transform: ({
1256 instance
1257 }) => {
1258 const transformedBlock = (0,external_wp_blocks_namespaceObject.createBlock)(block, transform ? transform(instance.raw) : undefined);
1259 if (!instance.raw?.title) {
1260 return transformedBlock;
1261 }
1262 return [(0,external_wp_blocks_namespaceObject.createBlock)('core/heading', {
1263 content: instance.raw.title
1264 }), transformedBlock];
1265 }
1266 };
1267 });
1268 const transforms = {
1269 to: legacyWidgetTransforms
1270 };
1271 /* harmony default export */ const legacy_widget_transforms = (transforms);
1272
1273 ;// ./packages/widgets/build-module/blocks/legacy-widget/index.js
1274 /**
1275 * WordPress dependencies
1276 */
1277
1278
1279 /**
1280 * Internal dependencies
1281 */
1282 const metadata = {
1283 $schema: "https://schemas.wp.org/trunk/block.json",
1284 apiVersion: 3,
1285 name: "core/legacy-widget",
1286 title: "Legacy Widget",
1287 category: "widgets",
1288 description: "Display a legacy widget.",
1289 textdomain: "default",
1290 attributes: {
1291 id: {
1292 type: "string",
1293 "default": null
1294 },
1295 idBase: {
1296 type: "string",
1297 "default": null
1298 },
1299 instance: {
1300 type: "object",
1301 "default": null
1302 }
1303 },
1304 supports: {
1305 html: false,
1306 customClassName: false,
1307 reusable: false
1308 },
1309 editorStyle: "wp-block-legacy-widget-editor"
1310 };
1311
1312
1313 const {
1314 name: legacy_widget_name
1315 } = metadata;
1316
1317 const settings = {
1318 icon: library_widget,
1319 edit: Edit,
1320 transforms: legacy_widget_transforms
1321 };
1322
1323 ;// ./packages/icons/build-module/library/group.js
1324 /**
1325 * WordPress dependencies
1326 */
1327
1328
1329 const group = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1330 viewBox: "0 0 24 24",
1331 xmlns: "http://www.w3.org/2000/svg",
1332 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1333 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"
1334 })
1335 });
1336 /* harmony default export */ const library_group = (group);
1337
1338 ;// ./packages/widgets/build-module/blocks/widget-group/edit.js
1339 /**
1340 * WordPress dependencies
1341 */
1342
1343
1344
1345
1346
1347
1348 function edit_Edit(props) {
1349 const {
1350 clientId
1351 } = props;
1352 const {
1353 innerBlocks
1354 } = (0,external_wp_data_namespaceObject.useSelect)(select => select(external_wp_blockEditor_namespaceObject.store).getBlock(clientId), [clientId]);
1355 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
1356 ...(0,external_wp_blockEditor_namespaceObject.useBlockProps)({
1357 className: 'widget'
1358 }),
1359 children: innerBlocks.length === 0 ? /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(PlaceholderContent, {
1360 ...props
1361 }) : /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(PreviewContent, {
1362 ...props
1363 })
1364 });
1365 }
1366 function PlaceholderContent({
1367 clientId
1368 }) {
1369 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1370 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, {
1371 className: "wp-block-widget-group__placeholder",
1372 icon: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.BlockIcon, {
1373 icon: library_group
1374 }),
1375 label: (0,external_wp_i18n_namespaceObject.__)('Widget Group'),
1376 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.ButtonBlockAppender, {
1377 rootClientId: clientId
1378 })
1379 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.InnerBlocks, {
1380 renderAppender: false
1381 })]
1382 });
1383 }
1384 function PreviewContent({
1385 attributes,
1386 setAttributes
1387 }) {
1388 var _attributes$title;
1389 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1390 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichText, {
1391 tagName: "h2",
1392 identifier: "title",
1393 className: "widget-title",
1394 allowedFormats: [],
1395 placeholder: (0,external_wp_i18n_namespaceObject.__)('Title'),
1396 value: (_attributes$title = attributes.title) !== null && _attributes$title !== void 0 ? _attributes$title : '',
1397 onChange: title => setAttributes({
1398 title
1399 })
1400 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.InnerBlocks, {})]
1401 });
1402 }
1403
1404 ;// ./packages/widgets/build-module/blocks/widget-group/save.js
1405 /**
1406 * WordPress dependencies
1407 */
1408
1409
1410 function save({
1411 attributes
1412 }) {
1413 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1414 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichText.Content, {
1415 tagName: "h2",
1416 className: "widget-title",
1417 value: attributes.title
1418 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
1419 className: "wp-widget-group__inner-blocks",
1420 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.InnerBlocks.Content, {})
1421 })]
1422 });
1423 }
1424
1425 ;// ./packages/widgets/build-module/blocks/widget-group/deprecated.js
1426 /**
1427 * WordPress dependencies
1428 */
1429
1430
1431 const v1 = {
1432 attributes: {
1433 title: {
1434 type: 'string'
1435 }
1436 },
1437 supports: {
1438 html: false,
1439 inserter: true,
1440 customClassName: true,
1441 reusable: false
1442 },
1443 save({
1444 attributes
1445 }) {
1446 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1447 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichText.Content, {
1448 tagName: "h2",
1449 className: "widget-title",
1450 value: attributes.title
1451 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.InnerBlocks.Content, {})]
1452 });
1453 }
1454 };
1455 /* harmony default export */ const deprecated = ([v1]);
1456
1457 ;// ./packages/widgets/build-module/blocks/widget-group/index.js
1458 /**
1459 * WordPress dependencies
1460 */
1461
1462
1463
1464
1465 /**
1466 * Internal dependencies
1467 */
1468 const widget_group_metadata = {
1469 $schema: "https://schemas.wp.org/trunk/block.json",
1470 apiVersion: 3,
1471 name: "core/widget-group",
1472 title: "Widget Group",
1473 category: "widgets",
1474 attributes: {
1475 title: {
1476 type: "string"
1477 }
1478 },
1479 supports: {
1480 html: false,
1481 inserter: true,
1482 customClassName: true,
1483 reusable: false
1484 },
1485 editorStyle: "wp-block-widget-group-editor",
1486 style: "wp-block-widget-group"
1487 };
1488
1489
1490
1491 const {
1492 name: widget_group_name
1493 } = widget_group_metadata;
1494
1495 const widget_group_settings = {
1496 title: (0,external_wp_i18n_namespaceObject.__)('Widget Group'),
1497 description: (0,external_wp_i18n_namespaceObject.__)('Create a classic widget layout with a title that’s styled by your theme for your widget areas.'),
1498 icon: library_group,
1499 __experimentalLabel: ({
1500 name: label
1501 }) => label,
1502 edit: edit_Edit,
1503 save: save,
1504 transforms: {
1505 from: [{
1506 type: 'block',
1507 isMultiBlock: true,
1508 blocks: ['*'],
1509 isMatch(attributes, blocks) {
1510 // Avoid transforming existing `widget-group` blocks.
1511 return !blocks.some(block => block.name === 'core/widget-group');
1512 },
1513 __experimentalConvert(blocks) {
1514 // Put the selected blocks inside the new Widget Group's innerBlocks.
1515 let innerBlocks = [...blocks.map(block => {
1516 return (0,external_wp_blocks_namespaceObject.createBlock)(block.name, block.attributes, block.innerBlocks);
1517 })];
1518
1519 // If the first block is a heading then assume this is intended
1520 // to be the Widget's "title".
1521 const firstHeadingBlock = innerBlocks[0].name === 'core/heading' ? innerBlocks[0] : null;
1522
1523 // Remove the first heading block as we're copying
1524 // it's content into the Widget Group's title attribute.
1525 innerBlocks = innerBlocks.filter(block => block !== firstHeadingBlock);
1526 return (0,external_wp_blocks_namespaceObject.createBlock)('core/widget-group', {
1527 ...(firstHeadingBlock && {
1528 title: firstHeadingBlock.attributes.content
1529 })
1530 }, innerBlocks);
1531 }
1532 }]
1533 },
1534 deprecated: deprecated
1535 };
1536
1537 ;// ./packages/icons/build-module/library/move-to.js
1538 /**
1539 * WordPress dependencies
1540 */
1541
1542
1543 const moveTo = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1544 xmlns: "http://www.w3.org/2000/svg",
1545 viewBox: "0 0 24 24",
1546 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1547 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"
1548 })
1549 });
1550 /* harmony default export */ const move_to = (moveTo);
1551
1552 ;// ./packages/widgets/build-module/components/move-to-widget-area/index.js
1553 /**
1554 * WordPress dependencies
1555 */
1556
1557
1558
1559
1560 function MoveToWidgetArea({
1561 currentWidgetAreaId,
1562 widgetAreas,
1563 onSelect
1564 }) {
1565 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.ToolbarGroup, {
1566 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.ToolbarItem, {
1567 children: toggleProps => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.DropdownMenu, {
1568 icon: move_to,
1569 label: (0,external_wp_i18n_namespaceObject.__)('Move to widget area'),
1570 toggleProps: toggleProps,
1571 children: ({
1572 onClose
1573 }) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.MenuGroup, {
1574 label: (0,external_wp_i18n_namespaceObject.__)('Move to'),
1575 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.MenuItemsChoice, {
1576 choices: widgetAreas.map(widgetArea => ({
1577 value: widgetArea.id,
1578 label: widgetArea.name,
1579 info: widgetArea.description
1580 })),
1581 value: currentWidgetAreaId,
1582 onSelect: value => {
1583 onSelect(value);
1584 onClose();
1585 }
1586 })
1587 })
1588 })
1589 })
1590 });
1591 }
1592
1593 ;// ./packages/widgets/build-module/components/index.js
1594
1595
1596 ;// ./packages/widgets/build-module/utils.js
1597 // @ts-check
1598
1599 /**
1600 * Get the internal widget id from block.
1601 *
1602 * @typedef {Object} Attributes
1603 * @property {string} __internalWidgetId The internal widget id.
1604 * @typedef {Object} Block
1605 * @property {Attributes} attributes The attributes of the block.
1606 *
1607 * @param {Block} block The block.
1608 * @return {string} The internal widget id.
1609 */
1610 function getWidgetIdFromBlock(block) {
1611 return block.attributes.__internalWidgetId;
1612 }
1613
1614 /**
1615 * Add internal widget id to block's attributes.
1616 *
1617 * @param {Block} block The block.
1618 * @param {string} widgetId The widget id.
1619 * @return {Block} The updated block.
1620 */
1621 function addWidgetIdToBlock(block, widgetId) {
1622 return {
1623 ...block,
1624 attributes: {
1625 ...(block.attributes || {}),
1626 __internalWidgetId: widgetId
1627 }
1628 };
1629 }
1630
1631 ;// ./packages/widgets/build-module/register-legacy-widget-variations.js
1632 /**
1633 * WordPress dependencies
1634 */
1635
1636
1637
1638 function registerLegacyWidgetVariations(settings) {
1639 const unsubscribe = (0,external_wp_data_namespaceObject.subscribe)(() => {
1640 var _settings$widgetTypes;
1641 const hiddenIds = (_settings$widgetTypes = settings?.widgetTypesToHideFromLegacyWidgetBlock) !== null && _settings$widgetTypes !== void 0 ? _settings$widgetTypes : [];
1642 const widgetTypes = (0,external_wp_data_namespaceObject.select)(external_wp_coreData_namespaceObject.store).getWidgetTypes({
1643 per_page: -1
1644 })?.filter(widgetType => !hiddenIds.includes(widgetType.id));
1645 if (widgetTypes) {
1646 unsubscribe();
1647 (0,external_wp_data_namespaceObject.dispatch)(external_wp_blocks_namespaceObject.store).addBlockVariations('core/legacy-widget', widgetTypes.map(widgetType => ({
1648 name: widgetType.id,
1649 title: widgetType.name,
1650 description: widgetType.description,
1651 attributes: widgetType.is_multi ? {
1652 idBase: widgetType.id,
1653 instance: {}
1654 } : {
1655 id: widgetType.id
1656 }
1657 })));
1658 }
1659 });
1660 }
1661
1662 ;// ./packages/widgets/build-module/index.js
1663 /**
1664 * WordPress dependencies
1665 */
1666
1667
1668 /**
1669 * Internal dependencies
1670 */
1671
1672
1673
1674
1675
1676 /**
1677 * Registers the Legacy Widget block.
1678 *
1679 * Note that for the block to be useful, any scripts required by a widget must
1680 * be loaded into the page.
1681 *
1682 * @param {Object} supports Block support settings.
1683 * @see https://developer.wordpress.org/block-editor/how-to-guides/widgets/legacy-widget-block/
1684 */
1685 function registerLegacyWidgetBlock(supports = {}) {
1686 const {
1687 /* metadata */ "yu": metadata,
1688 /* settings */ "W0": settings,
1689 /* name */ "UU": name
1690 } = legacy_widget_namespaceObject;
1691 (0,external_wp_blocks_namespaceObject.registerBlockType)({
1692 name,
1693 ...metadata
1694 }, {
1695 ...settings,
1696 supports: {
1697 ...settings.supports,
1698 ...supports
1699 }
1700 });
1701 }
1702
1703 /**
1704 * Registers the Widget Group block.
1705 *
1706 * @param {Object} supports Block support settings.
1707 */
1708 function registerWidgetGroupBlock(supports = {}) {
1709 const {
1710 /* metadata */ "yu": metadata,
1711 /* settings */ "W0": settings,
1712 /* name */ "UU": name
1713 } = widget_group_namespaceObject;
1714 (0,external_wp_blocks_namespaceObject.registerBlockType)({
1715 name,
1716 ...metadata
1717 }, {
1718 ...settings,
1719 supports: {
1720 ...settings.supports,
1721 ...supports
1722 }
1723 });
1724 }
1725
1726
1727 (window.wp = window.wp || {}).widgets = __webpack_exports__;
1728 /******/ })()
1729 ;