PluginProbe
Gutenberg / 17.1.1
Gutenberg v17.1.1
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 17.1.1, at build/widgets/index.js

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