widgets.js 54 KB

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