You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1756 lines
54 KiB

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