PluginProbe
Gutenberg / 14.8.0
Gutenberg v14.8.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 14.8.0, at build/widgets/index.js

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