PluginProbe
Gutenberg / 19.6.0
Gutenberg v19.6.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 19.6.0, at build/widgets/index.js

1,730 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 contorl 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 garabge 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 /* wp:polyfill */
622 /**
623 * External dependencies
624 */
625
626 /**
627 * WordPress dependencies
628 */
629
630
631
632
633
634
635 /**
636 * Internal dependencies
637 */
638
639
640 function Form({
641 title,
642 isVisible,
643 id,
644 idBase,
645 instance,
646 isWide,
647 onChangeInstance,
648 onChangeHasPreview
649 }) {
650 const ref = (0,external_wp_element_namespaceObject.useRef)();
651 const isMediumLargeViewport = (0,external_wp_compose_namespaceObject.useViewportMatch)('small');
652
653 // We only want to remount the control when the instance changes
654 // *externally*. For example, if the user performs an undo. To do this, we
655 // keep track of changes made to instance by the control itself and then
656 // ignore those.
657 const outgoingInstances = (0,external_wp_element_namespaceObject.useRef)(new Set());
658 const incomingInstances = (0,external_wp_element_namespaceObject.useRef)(new Set());
659 const {
660 createNotice
661 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store);
662 (0,external_wp_element_namespaceObject.useEffect)(() => {
663 if (incomingInstances.current.has(instance)) {
664 incomingInstances.current.delete(instance);
665 return;
666 }
667 const control = new Control({
668 id,
669 idBase,
670 instance,
671 onChangeInstance(nextInstance) {
672 outgoingInstances.current.add(instance);
673 incomingInstances.current.add(nextInstance);
674 onChangeInstance(nextInstance);
675 },
676 onChangeHasPreview,
677 onError(error) {
678 window.console.error(error);
679 createNotice('error', (0,external_wp_i18n_namespaceObject.sprintf)(/* translators: %s: the name of the affected block. */
680 (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));
681 }
682 });
683 ref.current.appendChild(control.element);
684 return () => {
685 if (outgoingInstances.current.has(instance)) {
686 outgoingInstances.current.delete(instance);
687 return;
688 }
689 control.destroy();
690 };
691 }, [id, idBase, instance, onChangeInstance, onChangeHasPreview, isMediumLargeViewport]);
692 if (isWide && isMediumLargeViewport) {
693 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
694 className: dist_clsx({
695 'wp-block-legacy-widget__container': isVisible
696 }),
697 children: [isVisible && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("h3", {
698 className: "wp-block-legacy-widget__edit-form-title",
699 children: title
700 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Popover, {
701 focusOnMount: false,
702 placement: "right",
703 offset: 32,
704 resize: false,
705 flip: false,
706 shift: true,
707 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
708 ref: ref,
709 className: "wp-block-legacy-widget__edit-form",
710 hidden: !isVisible
711 })
712 })]
713 });
714 }
715 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
716 ref: ref,
717 className: "wp-block-legacy-widget__edit-form",
718 hidden: !isVisible,
719 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("h3", {
720 className: "wp-block-legacy-widget__edit-form-title",
721 children: title
722 })
723 });
724 }
725
726 ;// ./packages/widgets/build-module/blocks/legacy-widget/edit/preview.js
727 /**
728 * External dependencies
729 */
730
731
732 /**
733 * WordPress dependencies
734 */
735
736
737
738
739
740
741 function Preview({
742 idBase,
743 instance,
744 isVisible
745 }) {
746 const [isLoaded, setIsLoaded] = (0,external_wp_element_namespaceObject.useState)(false);
747 const [srcDoc, setSrcDoc] = (0,external_wp_element_namespaceObject.useState)('');
748 (0,external_wp_element_namespaceObject.useEffect)(() => {
749 const abortController = typeof window.AbortController === 'undefined' ? undefined : new window.AbortController();
750 async function fetchPreviewHTML() {
751 const restRoute = `/wp/v2/widget-types/${idBase}/render`;
752 return await external_wp_apiFetch_default()({
753 path: restRoute,
754 method: 'POST',
755 signal: abortController?.signal,
756 data: instance ? {
757 instance
758 } : {}
759 });
760 }
761 fetchPreviewHTML().then(response => {
762 setSrcDoc(response.preview);
763 }).catch(error => {
764 if ('AbortError' === error.name) {
765 // We don't want to log aborted requests.
766 return;
767 }
768 throw error;
769 });
770 return () => abortController?.abort();
771 }, [idBase, instance]);
772
773 // Resize the iframe on either the load event, or when the iframe becomes visible.
774 const ref = (0,external_wp_compose_namespaceObject.useRefEffect)(iframe => {
775 // Only set height if the iframe is loaded,
776 // or it will grow to an unexpected large height in Safari if it's hidden initially.
777 if (!isLoaded) {
778 return;
779 }
780 // If the preview frame has another origin then this won't work.
781 // One possible solution is to add custom script to call `postMessage` in the preview frame.
782 // Or, better yet, we migrate away from iframe.
783 function setHeight() {
784 var _iframe$contentDocume, _iframe$contentDocume2;
785 // Pick the maximum of these two values to account for margin collapsing.
786 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);
787
788 // Fallback to a height of 100px if the height cannot be determined.
789 // This ensures the block is still selectable. 100px should hopefully
790 // be not so big that it's annoying, and not so small that nothing
791 // can be seen.
792 iframe.style.height = `${height !== 0 ? height : 100}px`;
793 }
794 const {
795 IntersectionObserver
796 } = iframe.ownerDocument.defaultView;
797
798 // Observe for intersections that might cause a change in the height of
799 // the iframe, e.g. a Widget Area becoming expanded.
800 const intersectionObserver = new IntersectionObserver(([entry]) => {
801 if (entry.isIntersecting) {
802 setHeight();
803 }
804 }, {
805 threshold: 1
806 });
807 intersectionObserver.observe(iframe);
808 iframe.addEventListener('load', setHeight);
809 return () => {
810 intersectionObserver.disconnect();
811 iframe.removeEventListener('load', setHeight);
812 };
813 }, [isLoaded]);
814 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
815 children: [isVisible && !isLoaded && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, {
816 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Spinner, {})
817 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
818 className: dist_clsx('wp-block-legacy-widget__edit-preview', {
819 'is-offscreen': !isVisible || !isLoaded
820 }),
821 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Disabled, {
822 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("iframe", {
823 ref: ref,
824 className: "wp-block-legacy-widget__edit-preview-iframe",
825 tabIndex: "-1",
826 title: (0,external_wp_i18n_namespaceObject.__)('Legacy Widget Preview'),
827 srcDoc: srcDoc,
828 onLoad: event => {
829 // To hide the scrollbars of the preview frame for some edge cases,
830 // such as negative margins in the Gallery Legacy Widget.
831 // It can't be scrolled anyway.
832 // TODO: Ideally, this should be fixed in core.
833 event.target.contentDocument.body.style.overflow = 'hidden';
834 setIsLoaded(true);
835 },
836 height: 100
837 })
838 })
839 })]
840 });
841 }
842
843 ;// ./packages/widgets/build-module/blocks/legacy-widget/edit/no-preview.js
844 /**
845 * WordPress dependencies
846 */
847
848
849 function NoPreview({
850 name
851 }) {
852 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
853 className: "wp-block-legacy-widget__edit-no-preview",
854 children: [name && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("h3", {
855 children: name
856 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("p", {
857 children: (0,external_wp_i18n_namespaceObject.__)('No preview available.')
858 })]
859 });
860 }
861
862 ;// ./packages/widgets/build-module/blocks/legacy-widget/edit/convert-to-blocks-button.js
863 /**
864 * WordPress dependencies
865 */
866
867
868
869
870
871
872 function ConvertToBlocksButton({
873 clientId,
874 rawInstance
875 }) {
876 const {
877 replaceBlocks
878 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
879 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.ToolbarButton, {
880 onClick: () => {
881 if (rawInstance.title) {
882 replaceBlocks(clientId, [(0,external_wp_blocks_namespaceObject.createBlock)('core/heading', {
883 content: rawInstance.title
884 }), ...(0,external_wp_blocks_namespaceObject.rawHandler)({
885 HTML: rawInstance.text
886 })]);
887 } else {
888 replaceBlocks(clientId, (0,external_wp_blocks_namespaceObject.rawHandler)({
889 HTML: rawInstance.text
890 }));
891 }
892 },
893 children: (0,external_wp_i18n_namespaceObject.__)('Convert to blocks')
894 });
895 }
896
897 ;// ./packages/widgets/build-module/blocks/legacy-widget/edit/index.js
898 /**
899 * External dependencies
900 */
901
902
903 /**
904 * WordPress dependencies
905 */
906
907
908
909
910
911
912
913 /**
914 * Internal dependencies
915 */
916
917
918
919
920
921
922
923 function Edit(props) {
924 const {
925 id,
926 idBase
927 } = props.attributes;
928 const {
929 isWide = false
930 } = props;
931 const blockProps = (0,external_wp_blockEditor_namespaceObject.useBlockProps)({
932 className: dist_clsx({
933 'is-wide-widget': isWide
934 })
935 });
936 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
937 ...blockProps,
938 children: !id && !idBase ? /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Empty, {
939 ...props
940 }) : /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(NotEmpty, {
941 ...props
942 })
943 });
944 }
945 function Empty({
946 attributes: {
947 id,
948 idBase
949 },
950 setAttributes
951 }) {
952 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, {
953 icon: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.BlockIcon, {
954 icon: library_brush
955 }),
956 label: (0,external_wp_i18n_namespaceObject.__)('Legacy Widget'),
957 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Flex, {
958 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.FlexBlock, {
959 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WidgetTypeSelector, {
960 selectedId: id !== null && id !== void 0 ? id : idBase,
961 onSelect: ({
962 selectedId,
963 isMulti
964 }) => {
965 if (!selectedId) {
966 setAttributes({
967 id: null,
968 idBase: null,
969 instance: null
970 });
971 } else if (isMulti) {
972 setAttributes({
973 id: null,
974 idBase: selectedId,
975 instance: {}
976 });
977 } else {
978 setAttributes({
979 id: selectedId,
980 idBase: null,
981 instance: null
982 });
983 }
984 }
985 })
986 })
987 })
988 });
989 }
990 function NotEmpty({
991 attributes: {
992 id,
993 idBase,
994 instance
995 },
996 setAttributes,
997 clientId,
998 isSelected,
999 isWide = false
1000 }) {
1001 const [hasPreview, setHasPreview] = (0,external_wp_element_namespaceObject.useState)(null);
1002 const widgetTypeId = id !== null && id !== void 0 ? id : idBase;
1003 const {
1004 record: widgetType,
1005 hasResolved: hasResolvedWidgetType
1006 } = (0,external_wp_coreData_namespaceObject.useEntityRecord)('root', 'widgetType', widgetTypeId);
1007 const setInstance = (0,external_wp_element_namespaceObject.useCallback)(nextInstance => {
1008 setAttributes({
1009 instance: nextInstance
1010 });
1011 }, []);
1012 if (!widgetType && hasResolvedWidgetType) {
1013 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, {
1014 icon: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.BlockIcon, {
1015 icon: library_brush
1016 }),
1017 label: (0,external_wp_i18n_namespaceObject.__)('Legacy Widget'),
1018 children: (0,external_wp_i18n_namespaceObject.__)('Widget is missing.')
1019 });
1020 }
1021 if (!hasResolvedWidgetType) {
1022 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, {
1023 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Spinner, {})
1024 });
1025 }
1026 const mode = idBase && !isSelected ? 'preview' : 'edit';
1027 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1028 children: [idBase === 'text' && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.BlockControls, {
1029 group: "other",
1030 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ConvertToBlocksButton, {
1031 clientId: clientId,
1032 rawInstance: instance.raw
1033 })
1034 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.InspectorControls, {
1035 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(InspectorCard, {
1036 name: widgetType.name,
1037 description: widgetType.description
1038 })
1039 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Form, {
1040 title: widgetType.name,
1041 isVisible: mode === 'edit',
1042 id: id,
1043 idBase: idBase,
1044 instance: instance,
1045 isWide: isWide,
1046 onChangeInstance: setInstance,
1047 onChangeHasPreview: setHasPreview
1048 }), idBase && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1049 children: [hasPreview === null && mode === 'preview' && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, {
1050 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Spinner, {})
1051 }), hasPreview === true && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Preview, {
1052 idBase: idBase,
1053 instance: instance,
1054 isVisible: mode === 'preview'
1055 }), hasPreview === false && mode === 'preview' && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(NoPreview, {
1056 name: widgetType.name
1057 })]
1058 })]
1059 });
1060 }
1061
1062 ;// ./packages/widgets/build-module/blocks/legacy-widget/transforms.js
1063 /**
1064 * WordPress dependencies
1065 */
1066
1067 const legacyWidgetTransforms = [{
1068 block: 'core/calendar',
1069 widget: 'calendar'
1070 }, {
1071 block: 'core/search',
1072 widget: 'search'
1073 }, {
1074 block: 'core/html',
1075 widget: 'custom_html',
1076 transform: ({
1077 content
1078 }) => ({
1079 content
1080 })
1081 }, {
1082 block: 'core/archives',
1083 widget: 'archives',
1084 transform: ({
1085 count,
1086 dropdown
1087 }) => {
1088 return {
1089 displayAsDropdown: !!dropdown,
1090 showPostCounts: !!count
1091 };
1092 }
1093 }, {
1094 block: 'core/latest-posts',
1095 widget: 'recent-posts',
1096 transform: ({
1097 show_date: displayPostDate,
1098 number
1099 }) => {
1100 return {
1101 displayPostDate: !!displayPostDate,
1102 postsToShow: number
1103 };
1104 }
1105 }, {
1106 block: 'core/latest-comments',
1107 widget: 'recent-comments',
1108 transform: ({
1109 number
1110 }) => {
1111 return {
1112 commentsToShow: number
1113 };
1114 }
1115 }, {
1116 block: 'core/tag-cloud',
1117 widget: 'tag_cloud',
1118 transform: ({
1119 taxonomy,
1120 count
1121 }) => {
1122 return {
1123 showTagCounts: !!count,
1124 taxonomy
1125 };
1126 }
1127 }, {
1128 block: 'core/categories',
1129 widget: 'categories',
1130 transform: ({
1131 count,
1132 dropdown,
1133 hierarchical
1134 }) => {
1135 return {
1136 displayAsDropdown: !!dropdown,
1137 showPostCounts: !!count,
1138 showHierarchy: !!hierarchical
1139 };
1140 }
1141 }, {
1142 block: 'core/audio',
1143 widget: 'media_audio',
1144 transform: ({
1145 url,
1146 preload,
1147 loop,
1148 attachment_id: id
1149 }) => {
1150 return {
1151 src: url,
1152 id,
1153 preload,
1154 loop
1155 };
1156 }
1157 }, {
1158 block: 'core/video',
1159 widget: 'media_video',
1160 transform: ({
1161 url,
1162 preload,
1163 loop,
1164 attachment_id: id
1165 }) => {
1166 return {
1167 src: url,
1168 id,
1169 preload,
1170 loop
1171 };
1172 }
1173 }, {
1174 block: 'core/image',
1175 widget: 'media_image',
1176 transform: ({
1177 alt,
1178 attachment_id: id,
1179 caption,
1180 height,
1181 link_classes: linkClass,
1182 link_rel: rel,
1183 link_target_blank: targetBlack,
1184 link_type: linkDestination,
1185 link_url: link,
1186 size: sizeSlug,
1187 url,
1188 width
1189 }) => {
1190 return {
1191 alt,
1192 caption,
1193 height,
1194 id,
1195 link,
1196 linkClass,
1197 linkDestination,
1198 linkTarget: targetBlack ? '_blank' : undefined,
1199 rel,
1200 sizeSlug,
1201 url,
1202 width
1203 };
1204 }
1205 }, {
1206 block: 'core/gallery',
1207 widget: 'media_gallery',
1208 transform: ({
1209 ids,
1210 link_type: linkTo,
1211 size,
1212 number
1213 }) => {
1214 return {
1215 ids,
1216 columns: number,
1217 linkTo,
1218 sizeSlug: size,
1219 images: ids.map(id => ({
1220 id
1221 }))
1222 };
1223 }
1224 }, {
1225 block: 'core/rss',
1226 widget: 'rss',
1227 transform: ({
1228 url,
1229 show_author: displayAuthor,
1230 show_date: displayDate,
1231 show_summary: displayExcerpt,
1232 items
1233 }) => {
1234 return {
1235 feedURL: url,
1236 displayAuthor: !!displayAuthor,
1237 displayDate: !!displayDate,
1238 displayExcerpt: !!displayExcerpt,
1239 itemsToShow: items
1240 };
1241 }
1242 }].map(({
1243 block,
1244 widget,
1245 transform
1246 }) => {
1247 return {
1248 type: 'block',
1249 blocks: [block],
1250 isMatch: ({
1251 idBase,
1252 instance
1253 }) => {
1254 return idBase === widget && !!instance?.raw;
1255 },
1256 transform: ({
1257 instance
1258 }) => {
1259 const transformedBlock = (0,external_wp_blocks_namespaceObject.createBlock)(block, transform ? transform(instance.raw) : undefined);
1260 if (!instance.raw?.title) {
1261 return transformedBlock;
1262 }
1263 return [(0,external_wp_blocks_namespaceObject.createBlock)('core/heading', {
1264 content: instance.raw.title
1265 }), transformedBlock];
1266 }
1267 };
1268 });
1269 const transforms = {
1270 to: legacyWidgetTransforms
1271 };
1272 /* harmony default export */ const legacy_widget_transforms = (transforms);
1273
1274 ;// ./packages/widgets/build-module/blocks/legacy-widget/index.js
1275 /**
1276 * WordPress dependencies
1277 */
1278
1279
1280 /**
1281 * Internal dependencies
1282 */
1283 const metadata = {
1284 $schema: "https://schemas.wp.org/trunk/block.json",
1285 apiVersion: 3,
1286 name: "core/legacy-widget",
1287 title: "Legacy Widget",
1288 category: "widgets",
1289 description: "Display a legacy widget.",
1290 textdomain: "default",
1291 attributes: {
1292 id: {
1293 type: "string",
1294 "default": null
1295 },
1296 idBase: {
1297 type: "string",
1298 "default": null
1299 },
1300 instance: {
1301 type: "object",
1302 "default": null
1303 }
1304 },
1305 supports: {
1306 html: false,
1307 customClassName: false,
1308 reusable: false
1309 },
1310 editorStyle: "wp-block-legacy-widget-editor"
1311 };
1312
1313
1314 const {
1315 name: legacy_widget_name
1316 } = metadata;
1317
1318 const settings = {
1319 icon: library_widget,
1320 edit: Edit,
1321 transforms: legacy_widget_transforms
1322 };
1323
1324 ;// ./packages/icons/build-module/library/group.js
1325 /**
1326 * WordPress dependencies
1327 */
1328
1329
1330 const group = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1331 viewBox: "0 0 24 24",
1332 xmlns: "http://www.w3.org/2000/svg",
1333 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1334 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"
1335 })
1336 });
1337 /* harmony default export */ const library_group = (group);
1338
1339 ;// ./packages/widgets/build-module/blocks/widget-group/edit.js
1340 /**
1341 * WordPress dependencies
1342 */
1343
1344
1345
1346
1347
1348
1349 function edit_Edit(props) {
1350 const {
1351 clientId
1352 } = props;
1353 const {
1354 innerBlocks
1355 } = (0,external_wp_data_namespaceObject.useSelect)(select => select(external_wp_blockEditor_namespaceObject.store).getBlock(clientId), [clientId]);
1356 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
1357 ...(0,external_wp_blockEditor_namespaceObject.useBlockProps)({
1358 className: 'widget'
1359 }),
1360 children: innerBlocks.length === 0 ? /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(PlaceholderContent, {
1361 ...props
1362 }) : /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(PreviewContent, {
1363 ...props
1364 })
1365 });
1366 }
1367 function PlaceholderContent({
1368 clientId
1369 }) {
1370 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1371 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, {
1372 className: "wp-block-widget-group__placeholder",
1373 icon: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.BlockIcon, {
1374 icon: library_group
1375 }),
1376 label: (0,external_wp_i18n_namespaceObject.__)('Widget Group'),
1377 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.ButtonBlockAppender, {
1378 rootClientId: clientId
1379 })
1380 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.InnerBlocks, {
1381 renderAppender: false
1382 })]
1383 });
1384 }
1385 function PreviewContent({
1386 attributes,
1387 setAttributes
1388 }) {
1389 var _attributes$title;
1390 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1391 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichText, {
1392 tagName: "h2",
1393 identifier: "title",
1394 className: "widget-title",
1395 allowedFormats: [],
1396 placeholder: (0,external_wp_i18n_namespaceObject.__)('Title'),
1397 value: (_attributes$title = attributes.title) !== null && _attributes$title !== void 0 ? _attributes$title : '',
1398 onChange: title => setAttributes({
1399 title
1400 })
1401 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.InnerBlocks, {})]
1402 });
1403 }
1404
1405 ;// ./packages/widgets/build-module/blocks/widget-group/save.js
1406 /**
1407 * WordPress dependencies
1408 */
1409
1410
1411 function save({
1412 attributes
1413 }) {
1414 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1415 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichText.Content, {
1416 tagName: "h2",
1417 className: "widget-title",
1418 value: attributes.title
1419 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
1420 className: "wp-widget-group__inner-blocks",
1421 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.InnerBlocks.Content, {})
1422 })]
1423 });
1424 }
1425
1426 ;// ./packages/widgets/build-module/blocks/widget-group/deprecated.js
1427 /**
1428 * WordPress dependencies
1429 */
1430
1431
1432 const v1 = {
1433 attributes: {
1434 title: {
1435 type: 'string'
1436 }
1437 },
1438 supports: {
1439 html: false,
1440 inserter: true,
1441 customClassName: true,
1442 reusable: false
1443 },
1444 save({
1445 attributes
1446 }) {
1447 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1448 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichText.Content, {
1449 tagName: "h2",
1450 className: "widget-title",
1451 value: attributes.title
1452 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.InnerBlocks.Content, {})]
1453 });
1454 }
1455 };
1456 /* harmony default export */ const deprecated = ([v1]);
1457
1458 ;// ./packages/widgets/build-module/blocks/widget-group/index.js
1459 /**
1460 * WordPress dependencies
1461 */
1462
1463
1464
1465
1466 /**
1467 * Internal dependencies
1468 */
1469 const widget_group_metadata = {
1470 $schema: "https://schemas.wp.org/trunk/block.json",
1471 apiVersion: 3,
1472 name: "core/widget-group",
1473 title: "Widget Group",
1474 category: "widgets",
1475 attributes: {
1476 title: {
1477 type: "string"
1478 }
1479 },
1480 supports: {
1481 html: false,
1482 inserter: true,
1483 customClassName: true,
1484 reusable: false
1485 },
1486 editorStyle: "wp-block-widget-group-editor",
1487 style: "wp-block-widget-group"
1488 };
1489
1490
1491
1492 const {
1493 name: widget_group_name
1494 } = widget_group_metadata;
1495
1496 const widget_group_settings = {
1497 title: (0,external_wp_i18n_namespaceObject.__)('Widget Group'),
1498 description: (0,external_wp_i18n_namespaceObject.__)('Create a classic widget layout with a title that’s styled by your theme for your widget areas.'),
1499 icon: library_group,
1500 __experimentalLabel: ({
1501 name: label
1502 }) => label,
1503 edit: edit_Edit,
1504 save: save,
1505 transforms: {
1506 from: [{
1507 type: 'block',
1508 isMultiBlock: true,
1509 blocks: ['*'],
1510 isMatch(attributes, blocks) {
1511 // Avoid transforming existing `widget-group` blocks.
1512 return !blocks.some(block => block.name === 'core/widget-group');
1513 },
1514 __experimentalConvert(blocks) {
1515 // Put the selected blocks inside the new Widget Group's innerBlocks.
1516 let innerBlocks = [...blocks.map(block => {
1517 return (0,external_wp_blocks_namespaceObject.createBlock)(block.name, block.attributes, block.innerBlocks);
1518 })];
1519
1520 // If the first block is a heading then assume this is intended
1521 // to be the Widget's "title".
1522 const firstHeadingBlock = innerBlocks[0].name === 'core/heading' ? innerBlocks[0] : null;
1523
1524 // Remove the first heading block as we're copying
1525 // it's content into the Widget Group's title attribute.
1526 innerBlocks = innerBlocks.filter(block => block !== firstHeadingBlock);
1527 return (0,external_wp_blocks_namespaceObject.createBlock)('core/widget-group', {
1528 ...(firstHeadingBlock && {
1529 title: firstHeadingBlock.attributes.content
1530 })
1531 }, innerBlocks);
1532 }
1533 }]
1534 },
1535 deprecated: deprecated
1536 };
1537
1538 ;// ./packages/icons/build-module/library/move-to.js
1539 /**
1540 * WordPress dependencies
1541 */
1542
1543
1544 const moveTo = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1545 xmlns: "http://www.w3.org/2000/svg",
1546 viewBox: "0 0 24 24",
1547 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1548 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"
1549 })
1550 });
1551 /* harmony default export */ const move_to = (moveTo);
1552
1553 ;// ./packages/widgets/build-module/components/move-to-widget-area/index.js
1554 /**
1555 * WordPress dependencies
1556 */
1557
1558
1559
1560
1561 function MoveToWidgetArea({
1562 currentWidgetAreaId,
1563 widgetAreas,
1564 onSelect
1565 }) {
1566 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.ToolbarGroup, {
1567 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.ToolbarItem, {
1568 children: toggleProps => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.DropdownMenu, {
1569 icon: move_to,
1570 label: (0,external_wp_i18n_namespaceObject.__)('Move to widget area'),
1571 toggleProps: toggleProps,
1572 children: ({
1573 onClose
1574 }) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.MenuGroup, {
1575 label: (0,external_wp_i18n_namespaceObject.__)('Move to'),
1576 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.MenuItemsChoice, {
1577 choices: widgetAreas.map(widgetArea => ({
1578 value: widgetArea.id,
1579 label: widgetArea.name,
1580 info: widgetArea.description
1581 })),
1582 value: currentWidgetAreaId,
1583 onSelect: value => {
1584 onSelect(value);
1585 onClose();
1586 }
1587 })
1588 })
1589 })
1590 })
1591 });
1592 }
1593
1594 ;// ./packages/widgets/build-module/components/index.js
1595
1596
1597 ;// ./packages/widgets/build-module/utils.js
1598 // @ts-check
1599
1600 /**
1601 * Get the internal widget id from block.
1602 *
1603 * @typedef {Object} Attributes
1604 * @property {string} __internalWidgetId The internal widget id.
1605 * @typedef {Object} Block
1606 * @property {Attributes} attributes The attributes of the block.
1607 *
1608 * @param {Block} block The block.
1609 * @return {string} The internal widget id.
1610 */
1611 function getWidgetIdFromBlock(block) {
1612 return block.attributes.__internalWidgetId;
1613 }
1614
1615 /**
1616 * Add internal widget id to block's attributes.
1617 *
1618 * @param {Block} block The block.
1619 * @param {string} widgetId The widget id.
1620 * @return {Block} The updated block.
1621 */
1622 function addWidgetIdToBlock(block, widgetId) {
1623 return {
1624 ...block,
1625 attributes: {
1626 ...(block.attributes || {}),
1627 __internalWidgetId: widgetId
1628 }
1629 };
1630 }
1631
1632 ;// ./packages/widgets/build-module/register-legacy-widget-variations.js
1633 /**
1634 * WordPress dependencies
1635 */
1636
1637
1638
1639 function registerLegacyWidgetVariations(settings) {
1640 const unsubscribe = (0,external_wp_data_namespaceObject.subscribe)(() => {
1641 var _settings$widgetTypes;
1642 const hiddenIds = (_settings$widgetTypes = settings?.widgetTypesToHideFromLegacyWidgetBlock) !== null && _settings$widgetTypes !== void 0 ? _settings$widgetTypes : [];
1643 const widgetTypes = (0,external_wp_data_namespaceObject.select)(external_wp_coreData_namespaceObject.store).getWidgetTypes({
1644 per_page: -1
1645 })?.filter(widgetType => !hiddenIds.includes(widgetType.id));
1646 if (widgetTypes) {
1647 unsubscribe();
1648 (0,external_wp_data_namespaceObject.dispatch)(external_wp_blocks_namespaceObject.store).addBlockVariations('core/legacy-widget', widgetTypes.map(widgetType => ({
1649 name: widgetType.id,
1650 title: widgetType.name,
1651 description: widgetType.description,
1652 attributes: widgetType.is_multi ? {
1653 idBase: widgetType.id,
1654 instance: {}
1655 } : {
1656 id: widgetType.id
1657 }
1658 })));
1659 }
1660 });
1661 }
1662
1663 ;// ./packages/widgets/build-module/index.js
1664 /**
1665 * WordPress dependencies
1666 */
1667
1668
1669 /**
1670 * Internal dependencies
1671 */
1672
1673
1674
1675
1676
1677 /**
1678 * Registers the Legacy Widget block.
1679 *
1680 * Note that for the block to be useful, any scripts required by a widget must
1681 * be loaded into the page.
1682 *
1683 * @param {Object} supports Block support settings.
1684 * @see https://developer.wordpress.org/block-editor/how-to-guides/widgets/legacy-widget-block/
1685 */
1686 function registerLegacyWidgetBlock(supports = {}) {
1687 const {
1688 /* metadata */ "yu": metadata,
1689 /* settings */ "W0": settings,
1690 /* name */ "UU": name
1691 } = legacy_widget_namespaceObject;
1692 (0,external_wp_blocks_namespaceObject.registerBlockType)({
1693 name,
1694 ...metadata
1695 }, {
1696 ...settings,
1697 supports: {
1698 ...settings.supports,
1699 ...supports
1700 }
1701 });
1702 }
1703
1704 /**
1705 * Registers the Widget Group block.
1706 *
1707 * @param {Object} supports Block support settings.
1708 */
1709 function registerWidgetGroupBlock(supports = {}) {
1710 const {
1711 /* metadata */ "yu": metadata,
1712 /* settings */ "W0": settings,
1713 /* name */ "UU": name
1714 } = widget_group_namespaceObject;
1715 (0,external_wp_blocks_namespaceObject.registerBlockType)({
1716 name,
1717 ...metadata
1718 }, {
1719 ...settings,
1720 supports: {
1721 ...settings.supports,
1722 ...supports
1723 }
1724 });
1725 }
1726
1727
1728 (window.wp = window.wp || {}).widgets = __webpack_exports__;
1729 /******/ })()
1730 ;