widgets.js 55 KB

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