PluginProbe
Gutenberg / 11.6.0
Gutenberg v11.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 11.6.0, at build/widgets/index.js

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