block-directory.js 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158
  1. /******/ (function() { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ // The require scope
  4. /******/ var __webpack_require__ = {};
  5. /******/
  6. /************************************************************************/
  7. /******/ /* webpack/runtime/compat get default export */
  8. /******/ !function() {
  9. /******/ // getDefaultExport function for compatibility with non-harmony modules
  10. /******/ __webpack_require__.n = function(module) {
  11. /******/ var getter = module && module.__esModule ?
  12. /******/ function() { return module['default']; } :
  13. /******/ function() { return module; };
  14. /******/ __webpack_require__.d(getter, { a: getter });
  15. /******/ return getter;
  16. /******/ };
  17. /******/ }();
  18. /******/
  19. /******/ /* webpack/runtime/define property getters */
  20. /******/ !function() {
  21. /******/ // define getter functions for harmony exports
  22. /******/ __webpack_require__.d = function(exports, definition) {
  23. /******/ for(var key in definition) {
  24. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  25. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  26. /******/ }
  27. /******/ }
  28. /******/ };
  29. /******/ }();
  30. /******/
  31. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  32. /******/ !function() {
  33. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  34. /******/ }();
  35. /******/
  36. /******/ /* webpack/runtime/make namespace object */
  37. /******/ !function() {
  38. /******/ // define __esModule on exports
  39. /******/ __webpack_require__.r = function(exports) {
  40. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  41. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  42. /******/ }
  43. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  44. /******/ };
  45. /******/ }();
  46. /******/
  47. /************************************************************************/
  48. var __webpack_exports__ = {};
  49. // ESM COMPAT FLAG
  50. __webpack_require__.r(__webpack_exports__);
  51. // EXPORTS
  52. __webpack_require__.d(__webpack_exports__, {
  53. "store": function() { return /* reexport */ store; }
  54. });
  55. // NAMESPACE OBJECT: ./node_modules/@wordpress/block-directory/build-module/store/selectors.js
  56. var selectors_namespaceObject = {};
  57. __webpack_require__.r(selectors_namespaceObject);
  58. __webpack_require__.d(selectors_namespaceObject, {
  59. "getDownloadableBlocks": function() { return getDownloadableBlocks; },
  60. "getErrorNoticeForBlock": function() { return getErrorNoticeForBlock; },
  61. "getErrorNotices": function() { return getErrorNotices; },
  62. "getInstalledBlockTypes": function() { return getInstalledBlockTypes; },
  63. "getNewBlockTypes": function() { return getNewBlockTypes; },
  64. "getUnusedBlockTypes": function() { return getUnusedBlockTypes; },
  65. "isInstalling": function() { return isInstalling; },
  66. "isRequestingDownloadableBlocks": function() { return isRequestingDownloadableBlocks; }
  67. });
  68. // NAMESPACE OBJECT: ./node_modules/@wordpress/block-directory/build-module/store/actions.js
  69. var actions_namespaceObject = {};
  70. __webpack_require__.r(actions_namespaceObject);
  71. __webpack_require__.d(actions_namespaceObject, {
  72. "addInstalledBlockType": function() { return addInstalledBlockType; },
  73. "clearErrorNotice": function() { return clearErrorNotice; },
  74. "fetchDownloadableBlocks": function() { return fetchDownloadableBlocks; },
  75. "installBlockType": function() { return installBlockType; },
  76. "receiveDownloadableBlocks": function() { return receiveDownloadableBlocks; },
  77. "removeInstalledBlockType": function() { return removeInstalledBlockType; },
  78. "setErrorNotice": function() { return setErrorNotice; },
  79. "setIsInstalling": function() { return setIsInstalling; },
  80. "uninstallBlockType": function() { return uninstallBlockType; }
  81. });
  82. // NAMESPACE OBJECT: ./node_modules/@wordpress/block-directory/build-module/store/resolvers.js
  83. var resolvers_namespaceObject = {};
  84. __webpack_require__.r(resolvers_namespaceObject);
  85. __webpack_require__.d(resolvers_namespaceObject, {
  86. "getDownloadableBlocks": function() { return resolvers_getDownloadableBlocks; }
  87. });
  88. ;// CONCATENATED MODULE: external ["wp","element"]
  89. var external_wp_element_namespaceObject = window["wp"]["element"];
  90. ;// CONCATENATED MODULE: external ["wp","plugins"]
  91. var external_wp_plugins_namespaceObject = window["wp"]["plugins"];
  92. ;// CONCATENATED MODULE: external ["wp","hooks"]
  93. var external_wp_hooks_namespaceObject = window["wp"]["hooks"];
  94. ;// CONCATENATED MODULE: external ["wp","blocks"]
  95. var external_wp_blocks_namespaceObject = window["wp"]["blocks"];
  96. ;// CONCATENATED MODULE: external ["wp","data"]
  97. var external_wp_data_namespaceObject = window["wp"]["data"];
  98. ;// CONCATENATED MODULE: external ["wp","editor"]
  99. var external_wp_editor_namespaceObject = window["wp"]["editor"];
  100. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/reducer.js
  101. /**
  102. * WordPress dependencies
  103. */
  104. /**
  105. * Reducer returning an array of downloadable blocks.
  106. *
  107. * @param {Object} state Current state.
  108. * @param {Object} action Dispatched action.
  109. *
  110. * @return {Object} Updated state.
  111. */
  112. const downloadableBlocks = function () {
  113. let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  114. let action = arguments.length > 1 ? arguments[1] : undefined;
  115. switch (action.type) {
  116. case 'FETCH_DOWNLOADABLE_BLOCKS':
  117. return { ...state,
  118. [action.filterValue]: {
  119. isRequesting: true
  120. }
  121. };
  122. case 'RECEIVE_DOWNLOADABLE_BLOCKS':
  123. return { ...state,
  124. [action.filterValue]: {
  125. results: action.downloadableBlocks,
  126. isRequesting: false
  127. }
  128. };
  129. }
  130. return state;
  131. };
  132. /**
  133. * Reducer managing the installation and deletion of blocks.
  134. *
  135. * @param {Object} state Current state.
  136. * @param {Object} action Dispatched action.
  137. *
  138. * @return {Object} Updated state.
  139. */
  140. const blockManagement = function () {
  141. let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
  142. installedBlockTypes: [],
  143. isInstalling: {}
  144. };
  145. let action = arguments.length > 1 ? arguments[1] : undefined;
  146. switch (action.type) {
  147. case 'ADD_INSTALLED_BLOCK_TYPE':
  148. return { ...state,
  149. installedBlockTypes: [...state.installedBlockTypes, action.item]
  150. };
  151. case 'REMOVE_INSTALLED_BLOCK_TYPE':
  152. return { ...state,
  153. installedBlockTypes: state.installedBlockTypes.filter(blockType => blockType.name !== action.item.name)
  154. };
  155. case 'SET_INSTALLING_BLOCK':
  156. return { ...state,
  157. isInstalling: { ...state.isInstalling,
  158. [action.blockId]: action.isInstalling
  159. }
  160. };
  161. }
  162. return state;
  163. };
  164. /**
  165. * Reducer returning an object of error notices.
  166. *
  167. * @param {Object} state Current state.
  168. * @param {Object} action Dispatched action.
  169. *
  170. * @return {Object} Updated state.
  171. */
  172. const errorNotices = function () {
  173. let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  174. let action = arguments.length > 1 ? arguments[1] : undefined;
  175. switch (action.type) {
  176. case 'SET_ERROR_NOTICE':
  177. return { ...state,
  178. [action.blockId]: {
  179. message: action.message,
  180. isFatal: action.isFatal
  181. }
  182. };
  183. case 'CLEAR_ERROR_NOTICE':
  184. const {
  185. [action.blockId]: blockId,
  186. ...restState
  187. } = state;
  188. return restState;
  189. }
  190. return state;
  191. };
  192. /* harmony default export */ var reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
  193. downloadableBlocks,
  194. blockManagement,
  195. errorNotices
  196. }));
  197. ;// CONCATENATED MODULE: external ["wp","blockEditor"]
  198. var external_wp_blockEditor_namespaceObject = window["wp"]["blockEditor"];
  199. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/utils/has-block-type.js
  200. /**
  201. * Check if a block list contains a specific block type. Recursively searches
  202. * through `innerBlocks` if they exist.
  203. *
  204. * @param {Object} blockType A block object to search for.
  205. * @param {Object[]} blocks The list of blocks to look through.
  206. *
  207. * @return {boolean} Whether the blockType is found.
  208. */
  209. function hasBlockType(blockType) {
  210. let blocks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  211. if (!blocks.length) {
  212. return false;
  213. }
  214. if (blocks.some(_ref => {
  215. let {
  216. name
  217. } = _ref;
  218. return name === blockType.name;
  219. })) {
  220. return true;
  221. }
  222. for (let i = 0; i < blocks.length; i++) {
  223. if (hasBlockType(blockType, blocks[i].innerBlocks)) {
  224. return true;
  225. }
  226. }
  227. return false;
  228. }
  229. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/selectors.js
  230. /**
  231. * WordPress dependencies
  232. */
  233. /**
  234. * Internal dependencies
  235. */
  236. /**
  237. * Returns true if application is requesting for downloadable blocks.
  238. *
  239. * @param {Object} state Global application state.
  240. * @param {string} filterValue Search string.
  241. *
  242. * @return {boolean} Whether a request is in progress for the blocks list.
  243. */
  244. function isRequestingDownloadableBlocks(state, filterValue) {
  245. var _state$downloadableBl, _state$downloadableBl2;
  246. return (_state$downloadableBl = (_state$downloadableBl2 = state.downloadableBlocks[filterValue]) === null || _state$downloadableBl2 === void 0 ? void 0 : _state$downloadableBl2.isRequesting) !== null && _state$downloadableBl !== void 0 ? _state$downloadableBl : false;
  247. }
  248. /**
  249. * Returns the available uninstalled blocks.
  250. *
  251. * @param {Object} state Global application state.
  252. * @param {string} filterValue Search string.
  253. *
  254. * @return {Array} Downloadable blocks.
  255. */
  256. function getDownloadableBlocks(state, filterValue) {
  257. var _state$downloadableBl3, _state$downloadableBl4;
  258. return (_state$downloadableBl3 = (_state$downloadableBl4 = state.downloadableBlocks[filterValue]) === null || _state$downloadableBl4 === void 0 ? void 0 : _state$downloadableBl4.results) !== null && _state$downloadableBl3 !== void 0 ? _state$downloadableBl3 : [];
  259. }
  260. /**
  261. * Returns the block types that have been installed on the server in this
  262. * session.
  263. *
  264. * @param {Object} state Global application state.
  265. *
  266. * @return {Array} Block type items
  267. */
  268. function getInstalledBlockTypes(state) {
  269. return state.blockManagement.installedBlockTypes;
  270. }
  271. /**
  272. * Returns block types that have been installed on the server and used in the
  273. * current post.
  274. *
  275. * @param {Object} state Global application state.
  276. *
  277. * @return {Array} Block type items.
  278. */
  279. const getNewBlockTypes = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => state => {
  280. const usedBlockTree = select(external_wp_blockEditor_namespaceObject.store).getBlocks();
  281. const installedBlockTypes = getInstalledBlockTypes(state);
  282. return installedBlockTypes.filter(blockType => hasBlockType(blockType, usedBlockTree));
  283. });
  284. /**
  285. * Returns the block types that have been installed on the server but are not
  286. * used in the current post.
  287. *
  288. * @param {Object} state Global application state.
  289. *
  290. * @return {Array} Block type items.
  291. */
  292. const getUnusedBlockTypes = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => state => {
  293. const usedBlockTree = select(external_wp_blockEditor_namespaceObject.store).getBlocks();
  294. const installedBlockTypes = getInstalledBlockTypes(state);
  295. return installedBlockTypes.filter(blockType => !hasBlockType(blockType, usedBlockTree));
  296. });
  297. /**
  298. * Returns true if a block plugin install is in progress.
  299. *
  300. * @param {Object} state Global application state.
  301. * @param {string} blockId Id of the block.
  302. *
  303. * @return {boolean} Whether this block is currently being installed.
  304. */
  305. function isInstalling(state, blockId) {
  306. return state.blockManagement.isInstalling[blockId] || false;
  307. }
  308. /**
  309. * Returns all block error notices.
  310. *
  311. * @param {Object} state Global application state.
  312. *
  313. * @return {Object} Object with error notices.
  314. */
  315. function getErrorNotices(state) {
  316. return state.errorNotices;
  317. }
  318. /**
  319. * Returns the error notice for a given block.
  320. *
  321. * @param {Object} state Global application state.
  322. * @param {string} blockId The ID of the block plugin. eg: my-block
  323. *
  324. * @return {string|boolean} The error text, or false if no error.
  325. */
  326. function getErrorNoticeForBlock(state, blockId) {
  327. return state.errorNotices[blockId];
  328. }
  329. ;// CONCATENATED MODULE: external "lodash"
  330. var external_lodash_namespaceObject = window["lodash"];
  331. ;// CONCATENATED MODULE: external ["wp","i18n"]
  332. var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
  333. ;// CONCATENATED MODULE: external ["wp","apiFetch"]
  334. var external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"];
  335. var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject);
  336. ;// CONCATENATED MODULE: external ["wp","notices"]
  337. var external_wp_notices_namespaceObject = window["wp"]["notices"];
  338. ;// CONCATENATED MODULE: external ["wp","url"]
  339. var external_wp_url_namespaceObject = window["wp"]["url"];
  340. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/load-assets.js
  341. /**
  342. * WordPress dependencies
  343. */
  344. /**
  345. * Load an asset for a block.
  346. *
  347. * This function returns a Promise that will resolve once the asset is loaded,
  348. * or in the case of Stylesheets and Inline JavaScript, will resolve immediately.
  349. *
  350. * @param {HTMLElement} el A HTML Element asset to inject.
  351. *
  352. * @return {Promise} Promise which will resolve when the asset is loaded.
  353. */
  354. const loadAsset = el => {
  355. return new Promise((resolve, reject) => {
  356. /*
  357. * Reconstruct the passed element, this is required as inserting the Node directly
  358. * won't always fire the required onload events, even if the asset wasn't already loaded.
  359. */
  360. const newNode = document.createElement(el.nodeName);
  361. ['id', 'rel', 'src', 'href', 'type'].forEach(attr => {
  362. if (el[attr]) {
  363. newNode[attr] = el[attr];
  364. }
  365. }); // Append inline <script> contents.
  366. if (el.innerHTML) {
  367. newNode.appendChild(document.createTextNode(el.innerHTML));
  368. }
  369. newNode.onload = () => resolve(true);
  370. newNode.onerror = () => reject(new Error('Error loading asset.'));
  371. document.body.appendChild(newNode); // Resolve Stylesheets and Inline JavaScript immediately.
  372. if ('link' === newNode.nodeName.toLowerCase() || 'script' === newNode.nodeName.toLowerCase() && !newNode.src) {
  373. resolve();
  374. }
  375. });
  376. };
  377. /**
  378. * Load the asset files for a block
  379. */
  380. async function loadAssets() {
  381. /*
  382. * Fetch the current URL (post-new.php, or post.php?post=1&action=edit) and compare the
  383. * JavaScript and CSS assets loaded between the pages. This imports the required assets
  384. * for the block into the current page while not requiring that we know them up-front.
  385. * In the future this can be improved by reliance upon block.json and/or a script-loader
  386. * dependency API.
  387. */
  388. const response = await external_wp_apiFetch_default()({
  389. url: document.location.href,
  390. parse: false
  391. });
  392. const data = await response.text();
  393. const doc = new window.DOMParser().parseFromString(data, 'text/html');
  394. const newAssets = Array.from(doc.querySelectorAll('link[rel="stylesheet"],script')).filter(asset => asset.id && !document.getElementById(asset.id));
  395. /*
  396. * Load each asset in order, as they may depend upon an earlier loaded script.
  397. * Stylesheets and Inline Scripts will resolve immediately upon insertion.
  398. */
  399. for (const newAsset of newAssets) {
  400. await loadAsset(newAsset);
  401. }
  402. }
  403. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/utils/get-plugin-url.js
  404. /**
  405. * Get the plugin's direct API link out of a block-directory response.
  406. *
  407. * @param {Object} block The block object
  408. *
  409. * @return {string} The plugin URL, if exists.
  410. */
  411. function getPluginUrl(block) {
  412. if (!block) {
  413. return false;
  414. }
  415. const link = block.links['wp:plugin'] || block.links.self;
  416. if (link && link.length) {
  417. return link[0].href;
  418. }
  419. return false;
  420. }
  421. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/actions.js
  422. /**
  423. * External dependencies
  424. */
  425. /**
  426. * WordPress dependencies
  427. */
  428. /**
  429. * Internal dependencies
  430. */
  431. /**
  432. * Returns an action object used in signalling that the downloadable blocks
  433. * have been requested and are loading.
  434. *
  435. * @param {string} filterValue Search string.
  436. *
  437. * @return {Object} Action object.
  438. */
  439. function fetchDownloadableBlocks(filterValue) {
  440. return {
  441. type: 'FETCH_DOWNLOADABLE_BLOCKS',
  442. filterValue
  443. };
  444. }
  445. /**
  446. * Returns an action object used in signalling that the downloadable blocks
  447. * have been updated.
  448. *
  449. * @param {Array} downloadableBlocks Downloadable blocks.
  450. * @param {string} filterValue Search string.
  451. *
  452. * @return {Object} Action object.
  453. */
  454. function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
  455. return {
  456. type: 'RECEIVE_DOWNLOADABLE_BLOCKS',
  457. downloadableBlocks,
  458. filterValue
  459. };
  460. }
  461. /**
  462. * Action triggered to install a block plugin.
  463. *
  464. * @param {Object} block The block item returned by search.
  465. *
  466. * @return {boolean} Whether the block was successfully installed & loaded.
  467. */
  468. const installBlockType = block => async _ref => {
  469. let {
  470. registry,
  471. dispatch
  472. } = _ref;
  473. const {
  474. id,
  475. name
  476. } = block;
  477. let success = false;
  478. dispatch.clearErrorNotice(id);
  479. try {
  480. dispatch.setIsInstalling(id, true); // If we have a wp:plugin link, the plugin is installed but inactive.
  481. const url = getPluginUrl(block);
  482. let links = {};
  483. if (url) {
  484. await external_wp_apiFetch_default()({
  485. method: 'PUT',
  486. url,
  487. data: {
  488. status: 'active'
  489. }
  490. });
  491. } else {
  492. const response = await external_wp_apiFetch_default()({
  493. method: 'POST',
  494. path: 'wp/v2/plugins',
  495. data: {
  496. slug: id,
  497. status: 'active'
  498. }
  499. }); // Add the `self` link for newly-installed blocks.
  500. links = response._links;
  501. }
  502. dispatch.addInstalledBlockType({ ...block,
  503. links: { ...block.links,
  504. ...links
  505. }
  506. }); // Ensures that the block metadata is propagated to the editor when registered on the server.
  507. const metadataFields = ['api_version', 'title', 'category', 'parent', 'icon', 'description', 'keywords', 'attributes', 'provides_context', 'uses_context', 'supports', 'styles', 'example', 'variations'];
  508. await external_wp_apiFetch_default()({
  509. path: (0,external_wp_url_namespaceObject.addQueryArgs)(`/wp/v2/block-types/${name}`, {
  510. _fields: metadataFields
  511. })
  512. }) // Ignore when the block is not registered on the server.
  513. .catch(() => {}).then(response => {
  514. if (!response) {
  515. return;
  516. }
  517. (0,external_wp_blocks_namespaceObject.unstable__bootstrapServerSideBlockDefinitions)({
  518. [name]: (0,external_lodash_namespaceObject.pick)(response, metadataFields)
  519. });
  520. });
  521. await loadAssets();
  522. const registeredBlocks = registry.select(external_wp_blocks_namespaceObject.store).getBlockTypes();
  523. if (!registeredBlocks.some(i => i.name === name)) {
  524. throw new Error((0,external_wp_i18n_namespaceObject.__)('Error registering block. Try reloading the page.'));
  525. }
  526. registry.dispatch(external_wp_notices_namespaceObject.store).createInfoNotice((0,external_wp_i18n_namespaceObject.sprintf)( // translators: %s is the block title.
  527. (0,external_wp_i18n_namespaceObject.__)('Block %s installed and added.'), block.title), {
  528. speak: true,
  529. type: 'snackbar'
  530. });
  531. success = true;
  532. } catch (error) {
  533. let message = error.message || (0,external_wp_i18n_namespaceObject.__)('An error occurred.'); // Errors we throw are fatal.
  534. let isFatal = error instanceof Error; // Specific API errors that are fatal.
  535. const fatalAPIErrors = {
  536. folder_exists: (0,external_wp_i18n_namespaceObject.__)('This block is already installed. Try reloading the page.'),
  537. unable_to_connect_to_filesystem: (0,external_wp_i18n_namespaceObject.__)('Error installing block. You can reload the page and try again.')
  538. };
  539. if (fatalAPIErrors[error.code]) {
  540. isFatal = true;
  541. message = fatalAPIErrors[error.code];
  542. }
  543. dispatch.setErrorNotice(id, message, isFatal);
  544. registry.dispatch(external_wp_notices_namespaceObject.store).createErrorNotice(message, {
  545. speak: true,
  546. isDismissible: true
  547. });
  548. }
  549. dispatch.setIsInstalling(id, false);
  550. return success;
  551. };
  552. /**
  553. * Action triggered to uninstall a block plugin.
  554. *
  555. * @param {Object} block The blockType object.
  556. */
  557. const uninstallBlockType = block => async _ref2 => {
  558. let {
  559. registry,
  560. dispatch
  561. } = _ref2;
  562. try {
  563. const url = getPluginUrl(block);
  564. await external_wp_apiFetch_default()({
  565. method: 'PUT',
  566. url,
  567. data: {
  568. status: 'inactive'
  569. }
  570. });
  571. await external_wp_apiFetch_default()({
  572. method: 'DELETE',
  573. url
  574. });
  575. dispatch.removeInstalledBlockType(block);
  576. } catch (error) {
  577. registry.dispatch(external_wp_notices_namespaceObject.store).createErrorNotice(error.message || (0,external_wp_i18n_namespaceObject.__)('An error occurred.'));
  578. }
  579. };
  580. /**
  581. * Returns an action object used to add a block type to the "newly installed"
  582. * tracking list.
  583. *
  584. * @param {Object} item The block item with the block id and name.
  585. *
  586. * @return {Object} Action object.
  587. */
  588. function addInstalledBlockType(item) {
  589. return {
  590. type: 'ADD_INSTALLED_BLOCK_TYPE',
  591. item
  592. };
  593. }
  594. /**
  595. * Returns an action object used to remove a block type from the "newly installed"
  596. * tracking list.
  597. *
  598. * @param {string} item The block item with the block id and name.
  599. *
  600. * @return {Object} Action object.
  601. */
  602. function removeInstalledBlockType(item) {
  603. return {
  604. type: 'REMOVE_INSTALLED_BLOCK_TYPE',
  605. item
  606. };
  607. }
  608. /**
  609. * Returns an action object used to indicate install in progress.
  610. *
  611. * @param {string} blockId
  612. * @param {boolean} isInstalling
  613. *
  614. * @return {Object} Action object.
  615. */
  616. function setIsInstalling(blockId, isInstalling) {
  617. return {
  618. type: 'SET_INSTALLING_BLOCK',
  619. blockId,
  620. isInstalling
  621. };
  622. }
  623. /**
  624. * Sets an error notice to be displayed to the user for a given block.
  625. *
  626. * @param {string} blockId The ID of the block plugin. eg: my-block
  627. * @param {string} message The message shown in the notice.
  628. * @param {boolean} isFatal Whether the user can recover from the error.
  629. *
  630. * @return {Object} Action object.
  631. */
  632. function setErrorNotice(blockId, message) {
  633. let isFatal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  634. return {
  635. type: 'SET_ERROR_NOTICE',
  636. blockId,
  637. message,
  638. isFatal
  639. };
  640. }
  641. /**
  642. * Sets the error notice to empty for specific block.
  643. *
  644. * @param {string} blockId The ID of the block plugin. eg: my-block
  645. *
  646. * @return {Object} Action object.
  647. */
  648. function clearErrorNotice(blockId) {
  649. return {
  650. type: 'CLEAR_ERROR_NOTICE',
  651. blockId
  652. };
  653. }
  654. ;// CONCATENATED MODULE: ./node_modules/tslib/tslib.es6.js
  655. /*! *****************************************************************************
  656. Copyright (c) Microsoft Corporation.
  657. Permission to use, copy, modify, and/or distribute this software for any
  658. purpose with or without fee is hereby granted.
  659. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  660. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  661. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  662. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  663. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  664. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  665. PERFORMANCE OF THIS SOFTWARE.
  666. ***************************************************************************** */
  667. /* global Reflect, Promise */
  668. var extendStatics = function(d, b) {
  669. extendStatics = Object.setPrototypeOf ||
  670. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  671. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  672. return extendStatics(d, b);
  673. };
  674. function __extends(d, b) {
  675. if (typeof b !== "function" && b !== null)
  676. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  677. extendStatics(d, b);
  678. function __() { this.constructor = d; }
  679. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  680. }
  681. var __assign = function() {
  682. __assign = Object.assign || function __assign(t) {
  683. for (var s, i = 1, n = arguments.length; i < n; i++) {
  684. s = arguments[i];
  685. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  686. }
  687. return t;
  688. }
  689. return __assign.apply(this, arguments);
  690. }
  691. function __rest(s, e) {
  692. var t = {};
  693. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  694. t[p] = s[p];
  695. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  696. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  697. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  698. t[p[i]] = s[p[i]];
  699. }
  700. return t;
  701. }
  702. function __decorate(decorators, target, key, desc) {
  703. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  704. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  705. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  706. return c > 3 && r && Object.defineProperty(target, key, r), r;
  707. }
  708. function __param(paramIndex, decorator) {
  709. return function (target, key) { decorator(target, key, paramIndex); }
  710. }
  711. function __metadata(metadataKey, metadataValue) {
  712. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  713. }
  714. function __awaiter(thisArg, _arguments, P, generator) {
  715. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  716. return new (P || (P = Promise))(function (resolve, reject) {
  717. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  718. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  719. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  720. step((generator = generator.apply(thisArg, _arguments || [])).next());
  721. });
  722. }
  723. function __generator(thisArg, body) {
  724. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  725. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  726. function verb(n) { return function (v) { return step([n, v]); }; }
  727. function step(op) {
  728. if (f) throw new TypeError("Generator is already executing.");
  729. while (_) try {
  730. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  731. if (y = 0, t) op = [op[0] & 2, t.value];
  732. switch (op[0]) {
  733. case 0: case 1: t = op; break;
  734. case 4: _.label++; return { value: op[1], done: false };
  735. case 5: _.label++; y = op[1]; op = [0]; continue;
  736. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  737. default:
  738. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  739. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  740. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  741. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  742. if (t[2]) _.ops.pop();
  743. _.trys.pop(); continue;
  744. }
  745. op = body.call(thisArg, _);
  746. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  747. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  748. }
  749. }
  750. var __createBinding = Object.create ? (function(o, m, k, k2) {
  751. if (k2 === undefined) k2 = k;
  752. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  753. }) : (function(o, m, k, k2) {
  754. if (k2 === undefined) k2 = k;
  755. o[k2] = m[k];
  756. });
  757. function __exportStar(m, o) {
  758. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
  759. }
  760. function __values(o) {
  761. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  762. if (m) return m.call(o);
  763. if (o && typeof o.length === "number") return {
  764. next: function () {
  765. if (o && i >= o.length) o = void 0;
  766. return { value: o && o[i++], done: !o };
  767. }
  768. };
  769. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  770. }
  771. function __read(o, n) {
  772. var m = typeof Symbol === "function" && o[Symbol.iterator];
  773. if (!m) return o;
  774. var i = m.call(o), r, ar = [], e;
  775. try {
  776. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  777. }
  778. catch (error) { e = { error: error }; }
  779. finally {
  780. try {
  781. if (r && !r.done && (m = i["return"])) m.call(i);
  782. }
  783. finally { if (e) throw e.error; }
  784. }
  785. return ar;
  786. }
  787. /** @deprecated */
  788. function __spread() {
  789. for (var ar = [], i = 0; i < arguments.length; i++)
  790. ar = ar.concat(__read(arguments[i]));
  791. return ar;
  792. }
  793. /** @deprecated */
  794. function __spreadArrays() {
  795. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  796. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  797. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  798. r[k] = a[j];
  799. return r;
  800. }
  801. function __spreadArray(to, from, pack) {
  802. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  803. if (ar || !(i in from)) {
  804. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  805. ar[i] = from[i];
  806. }
  807. }
  808. return to.concat(ar || Array.prototype.slice.call(from));
  809. }
  810. function __await(v) {
  811. return this instanceof __await ? (this.v = v, this) : new __await(v);
  812. }
  813. function __asyncGenerator(thisArg, _arguments, generator) {
  814. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  815. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  816. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  817. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  818. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  819. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  820. function fulfill(value) { resume("next", value); }
  821. function reject(value) { resume("throw", value); }
  822. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  823. }
  824. function __asyncDelegator(o) {
  825. var i, p;
  826. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  827. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  828. }
  829. function __asyncValues(o) {
  830. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  831. var m = o[Symbol.asyncIterator], i;
  832. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  833. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  834. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  835. }
  836. function __makeTemplateObject(cooked, raw) {
  837. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  838. return cooked;
  839. };
  840. var __setModuleDefault = Object.create ? (function(o, v) {
  841. Object.defineProperty(o, "default", { enumerable: true, value: v });
  842. }) : function(o, v) {
  843. o["default"] = v;
  844. };
  845. function __importStar(mod) {
  846. if (mod && mod.__esModule) return mod;
  847. var result = {};
  848. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  849. __setModuleDefault(result, mod);
  850. return result;
  851. }
  852. function __importDefault(mod) {
  853. return (mod && mod.__esModule) ? mod : { default: mod };
  854. }
  855. function __classPrivateFieldGet(receiver, state, kind, f) {
  856. if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
  857. if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
  858. return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
  859. }
  860. function __classPrivateFieldSet(receiver, state, value, kind, f) {
  861. if (kind === "m") throw new TypeError("Private method is not writable");
  862. if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
  863. if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
  864. return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
  865. }
  866. ;// CONCATENATED MODULE: ./node_modules/lower-case/dist.es2015/index.js
  867. /**
  868. * Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
  869. */
  870. var SUPPORTED_LOCALE = {
  871. tr: {
  872. regexp: /\u0130|\u0049|\u0049\u0307/g,
  873. map: {
  874. İ: "\u0069",
  875. I: "\u0131",
  876. İ: "\u0069",
  877. },
  878. },
  879. az: {
  880. regexp: /\u0130/g,
  881. map: {
  882. İ: "\u0069",
  883. I: "\u0131",
  884. İ: "\u0069",
  885. },
  886. },
  887. lt: {
  888. regexp: /\u0049|\u004A|\u012E|\u00CC|\u00CD|\u0128/g,
  889. map: {
  890. I: "\u0069\u0307",
  891. J: "\u006A\u0307",
  892. Į: "\u012F\u0307",
  893. Ì: "\u0069\u0307\u0300",
  894. Í: "\u0069\u0307\u0301",
  895. Ĩ: "\u0069\u0307\u0303",
  896. },
  897. },
  898. };
  899. /**
  900. * Localized lower case.
  901. */
  902. function localeLowerCase(str, locale) {
  903. var lang = SUPPORTED_LOCALE[locale.toLowerCase()];
  904. if (lang)
  905. return lowerCase(str.replace(lang.regexp, function (m) { return lang.map[m]; }));
  906. return lowerCase(str);
  907. }
  908. /**
  909. * Lower case as a function.
  910. */
  911. function lowerCase(str) {
  912. return str.toLowerCase();
  913. }
  914. ;// CONCATENATED MODULE: ./node_modules/no-case/dist.es2015/index.js
  915. // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
  916. var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
  917. // Remove all non-word characters.
  918. var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
  919. /**
  920. * Normalize the string into something other libraries can manipulate easier.
  921. */
  922. function noCase(input, options) {
  923. if (options === void 0) { options = {}; }
  924. var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
  925. var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
  926. var start = 0;
  927. var end = result.length;
  928. // Trim the delimiter from around the output string.
  929. while (result.charAt(start) === "\0")
  930. start++;
  931. while (result.charAt(end - 1) === "\0")
  932. end--;
  933. // Transform each token independently.
  934. return result.slice(start, end).split("\0").map(transform).join(delimiter);
  935. }
  936. /**
  937. * Replace `re` in the input string with the replacement value.
  938. */
  939. function replace(input, re, value) {
  940. if (re instanceof RegExp)
  941. return input.replace(re, value);
  942. return re.reduce(function (input, re) { return input.replace(re, value); }, input);
  943. }
  944. ;// CONCATENATED MODULE: ./node_modules/pascal-case/dist.es2015/index.js
  945. function pascalCaseTransform(input, index) {
  946. var firstChar = input.charAt(0);
  947. var lowerChars = input.substr(1).toLowerCase();
  948. if (index > 0 && firstChar >= "0" && firstChar <= "9") {
  949. return "_" + firstChar + lowerChars;
  950. }
  951. return "" + firstChar.toUpperCase() + lowerChars;
  952. }
  953. function dist_es2015_pascalCaseTransformMerge(input) {
  954. return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
  955. }
  956. function pascalCase(input, options) {
  957. if (options === void 0) { options = {}; }
  958. return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options));
  959. }
  960. ;// CONCATENATED MODULE: ./node_modules/camel-case/dist.es2015/index.js
  961. function camelCaseTransform(input, index) {
  962. if (index === 0)
  963. return input.toLowerCase();
  964. return pascalCaseTransform(input, index);
  965. }
  966. function camelCaseTransformMerge(input, index) {
  967. if (index === 0)
  968. return input.toLowerCase();
  969. return pascalCaseTransformMerge(input);
  970. }
  971. function camelCase(input, options) {
  972. if (options === void 0) { options = {}; }
  973. return pascalCase(input, __assign({ transform: camelCaseTransform }, options));
  974. }
  975. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/resolvers.js
  976. /**
  977. * External dependencies
  978. */
  979. /**
  980. * WordPress dependencies
  981. */
  982. /**
  983. * Internal dependencies
  984. */
  985. const resolvers_getDownloadableBlocks = filterValue => async _ref => {
  986. let {
  987. dispatch
  988. } = _ref;
  989. if (!filterValue) {
  990. return;
  991. }
  992. try {
  993. dispatch(fetchDownloadableBlocks(filterValue));
  994. const results = await external_wp_apiFetch_default()({
  995. path: `wp/v2/block-directory/search?term=${filterValue}`
  996. });
  997. const blocks = results.map(result => Object.fromEntries(Object.entries(result).map(_ref2 => {
  998. let [key, value] = _ref2;
  999. return [camelCase(key), value];
  1000. })));
  1001. dispatch(receiveDownloadableBlocks(blocks, filterValue));
  1002. } catch {}
  1003. };
  1004. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/index.js
  1005. /**
  1006. * WordPress dependencies
  1007. */
  1008. /**
  1009. * Internal dependencies
  1010. */
  1011. /**
  1012. * Module Constants
  1013. */
  1014. const STORE_NAME = 'core/block-directory';
  1015. /**
  1016. * Block editor data store configuration.
  1017. *
  1018. * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registerStore
  1019. *
  1020. * @type {Object}
  1021. */
  1022. const storeConfig = {
  1023. reducer: reducer,
  1024. selectors: selectors_namespaceObject,
  1025. actions: actions_namespaceObject,
  1026. resolvers: resolvers_namespaceObject
  1027. };
  1028. /**
  1029. * Store definition for the block directory namespace.
  1030. *
  1031. * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
  1032. *
  1033. * @type {Object}
  1034. */
  1035. const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, storeConfig);
  1036. (0,external_wp_data_namespaceObject.register)(store);
  1037. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/auto-block-uninstaller/index.js
  1038. /**
  1039. * WordPress dependencies
  1040. */
  1041. /**
  1042. * Internal dependencies
  1043. */
  1044. function AutoBlockUninstaller() {
  1045. const {
  1046. uninstallBlockType
  1047. } = (0,external_wp_data_namespaceObject.useDispatch)(store);
  1048. const shouldRemoveBlockTypes = (0,external_wp_data_namespaceObject.useSelect)(select => {
  1049. const {
  1050. isAutosavingPost,
  1051. isSavingPost
  1052. } = select(external_wp_editor_namespaceObject.store);
  1053. return isSavingPost() && !isAutosavingPost();
  1054. }, []);
  1055. const unusedBlockTypes = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).getUnusedBlockTypes(), []);
  1056. (0,external_wp_element_namespaceObject.useEffect)(() => {
  1057. if (shouldRemoveBlockTypes && unusedBlockTypes.length) {
  1058. unusedBlockTypes.forEach(blockType => {
  1059. uninstallBlockType(blockType);
  1060. (0,external_wp_blocks_namespaceObject.unregisterBlockType)(blockType.name);
  1061. });
  1062. }
  1063. }, [shouldRemoveBlockTypes]);
  1064. return null;
  1065. }
  1066. ;// CONCATENATED MODULE: external ["wp","components"]
  1067. var external_wp_components_namespaceObject = window["wp"]["components"];
  1068. ;// CONCATENATED MODULE: external ["wp","compose"]
  1069. var external_wp_compose_namespaceObject = window["wp"]["compose"];
  1070. ;// CONCATENATED MODULE: external ["wp","coreData"]
  1071. var external_wp_coreData_namespaceObject = window["wp"]["coreData"];
  1072. ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js
  1073. function _extends() {
  1074. _extends = Object.assign ? Object.assign.bind() : function (target) {
  1075. for (var i = 1; i < arguments.length; i++) {
  1076. var source = arguments[i];
  1077. for (var key in source) {
  1078. if (Object.prototype.hasOwnProperty.call(source, key)) {
  1079. target[key] = source[key];
  1080. }
  1081. }
  1082. }
  1083. return target;
  1084. };
  1085. return _extends.apply(this, arguments);
  1086. }
  1087. ;// CONCATENATED MODULE: external ["wp","htmlEntities"]
  1088. var external_wp_htmlEntities_namespaceObject = window["wp"]["htmlEntities"];
  1089. ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/icon/index.js
  1090. /**
  1091. * WordPress dependencies
  1092. */
  1093. /** @typedef {{icon: JSX.Element, size?: number} & import('@wordpress/primitives').SVGProps} IconProps */
  1094. /**
  1095. * Return an SVG icon.
  1096. *
  1097. * @param {IconProps} props icon is the SVG component to render
  1098. * size is a number specifiying the icon size in pixels
  1099. * Other props will be passed to wrapped SVG component
  1100. *
  1101. * @return {JSX.Element} Icon component
  1102. */
  1103. function Icon(_ref) {
  1104. let {
  1105. icon,
  1106. size = 24,
  1107. ...props
  1108. } = _ref;
  1109. return (0,external_wp_element_namespaceObject.cloneElement)(icon, {
  1110. width: size,
  1111. height: size,
  1112. ...props
  1113. });
  1114. }
  1115. /* harmony default export */ var icon = (Icon);
  1116. ;// CONCATENATED MODULE: external ["wp","primitives"]
  1117. var external_wp_primitives_namespaceObject = window["wp"]["primitives"];
  1118. ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/star-filled.js
  1119. /**
  1120. * WordPress dependencies
  1121. */
  1122. const starFilled = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, {
  1123. xmlns: "http://www.w3.org/2000/svg",
  1124. viewBox: "0 0 24 24"
  1125. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, {
  1126. d: "M11.776 4.454a.25.25 0 01.448 0l2.069 4.192a.25.25 0 00.188.137l4.626.672a.25.25 0 01.139.426l-3.348 3.263a.25.25 0 00-.072.222l.79 4.607a.25.25 0 01-.362.263l-4.138-2.175a.25.25 0 00-.232 0l-4.138 2.175a.25.25 0 01-.363-.263l.79-4.607a.25.25 0 00-.071-.222L4.754 9.881a.25.25 0 01.139-.426l4.626-.672a.25.25 0 00.188-.137l2.069-4.192z"
  1127. }));
  1128. /* harmony default export */ var star_filled = (starFilled);
  1129. ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/star-half.js
  1130. /**
  1131. * WordPress dependencies
  1132. */
  1133. const starHalf = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, {
  1134. xmlns: "http://www.w3.org/2000/svg",
  1135. viewBox: "0 0 24 24"
  1136. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, {
  1137. d: "M9.518 8.783a.25.25 0 00.188-.137l2.069-4.192a.25.25 0 01.448 0l2.07 4.192a.25.25 0 00.187.137l4.626.672a.25.25 0 01.139.427l-3.347 3.262a.25.25 0 00-.072.222l.79 4.607a.25.25 0 01-.363.264l-4.137-2.176a.25.25 0 00-.233 0l-4.138 2.175a.25.25 0 01-.362-.263l.79-4.607a.25.25 0 00-.072-.222L4.753 9.882a.25.25 0 01.14-.427l4.625-.672zM12 14.533c.28 0 .559.067.814.2l1.895.997-.362-2.11a1.75 1.75 0 01.504-1.55l1.533-1.495-2.12-.308a1.75 1.75 0 01-1.317-.957L12 7.39v7.143z"
  1138. }));
  1139. /* harmony default export */ var star_half = (starHalf);
  1140. ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/star-empty.js
  1141. /**
  1142. * WordPress dependencies
  1143. */
  1144. const starEmpty = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, {
  1145. xmlns: "http://www.w3.org/2000/svg",
  1146. viewBox: "0 0 24 24"
  1147. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, {
  1148. fillRule: "evenodd",
  1149. d: "M9.706 8.646a.25.25 0 01-.188.137l-4.626.672a.25.25 0 00-.139.427l3.348 3.262a.25.25 0 01.072.222l-.79 4.607a.25.25 0 00.362.264l4.138-2.176a.25.25 0 01.233 0l4.137 2.175a.25.25 0 00.363-.263l-.79-4.607a.25.25 0 01.072-.222l3.347-3.262a.25.25 0 00-.139-.427l-4.626-.672a.25.25 0 01-.188-.137l-2.069-4.192a.25.25 0 00-.448 0L9.706 8.646zM12 7.39l-.948 1.921a1.75 1.75 0 01-1.317.957l-2.12.308 1.534 1.495c.412.402.6.982.503 1.55l-.362 2.11 1.896-.997a1.75 1.75 0 011.629 0l1.895.997-.362-2.11a1.75 1.75 0 01.504-1.55l1.533-1.495-2.12-.308a1.75 1.75 0 01-1.317-.957L12 7.39z",
  1150. clipRule: "evenodd"
  1151. }));
  1152. /* harmony default export */ var star_empty = (starEmpty);
  1153. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/block-ratings/stars.js
  1154. /**
  1155. * WordPress dependencies
  1156. */
  1157. function Stars(_ref) {
  1158. let {
  1159. rating
  1160. } = _ref;
  1161. const stars = Math.round(rating / 0.5) * 0.5;
  1162. const fullStarCount = Math.floor(rating);
  1163. const halfStarCount = Math.ceil(rating - fullStarCount);
  1164. const emptyStarCount = 5 - (fullStarCount + halfStarCount);
  1165. return (0,external_wp_element_namespaceObject.createElement)("span", {
  1166. "aria-label": (0,external_wp_i18n_namespaceObject.sprintf)(
  1167. /* translators: %s: number of stars. */
  1168. (0,external_wp_i18n_namespaceObject.__)('%s out of 5 stars'), stars)
  1169. }, Array.from({
  1170. length: fullStarCount
  1171. }).map((_, i) => (0,external_wp_element_namespaceObject.createElement)(icon, {
  1172. key: `full_stars_${i}`,
  1173. className: "block-directory-block-ratings__star-full",
  1174. icon: star_filled,
  1175. size: 16
  1176. })), Array.from({
  1177. length: halfStarCount
  1178. }).map((_, i) => (0,external_wp_element_namespaceObject.createElement)(icon, {
  1179. key: `half_stars_${i}`,
  1180. className: "block-directory-block-ratings__star-half-full",
  1181. icon: star_half,
  1182. size: 16
  1183. })), Array.from({
  1184. length: emptyStarCount
  1185. }).map((_, i) => (0,external_wp_element_namespaceObject.createElement)(icon, {
  1186. key: `empty_stars_${i}`,
  1187. className: "block-directory-block-ratings__star-empty",
  1188. icon: star_empty,
  1189. size: 16
  1190. })));
  1191. }
  1192. /* harmony default export */ var stars = (Stars);
  1193. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/block-ratings/index.js
  1194. /**
  1195. * Internal dependencies
  1196. */
  1197. const BlockRatings = _ref => {
  1198. let {
  1199. rating
  1200. } = _ref;
  1201. return (0,external_wp_element_namespaceObject.createElement)("span", {
  1202. className: "block-directory-block-ratings"
  1203. }, (0,external_wp_element_namespaceObject.createElement)(stars, {
  1204. rating: rating
  1205. }));
  1206. };
  1207. /* harmony default export */ var block_ratings = (BlockRatings);
  1208. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/downloadable-block-icon/index.js
  1209. /**
  1210. * WordPress dependencies
  1211. */
  1212. function DownloadableBlockIcon(_ref) {
  1213. let {
  1214. icon
  1215. } = _ref;
  1216. const className = 'block-directory-downloadable-block-icon';
  1217. return icon.match(/\.(jpeg|jpg|gif|png|svg)(?:\?.*)?$/) !== null ? (0,external_wp_element_namespaceObject.createElement)("img", {
  1218. className: className,
  1219. src: icon,
  1220. alt: ""
  1221. }) : (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.BlockIcon, {
  1222. className: className,
  1223. icon: icon,
  1224. showColors: true
  1225. });
  1226. }
  1227. /* harmony default export */ var downloadable_block_icon = (DownloadableBlockIcon);
  1228. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/downloadable-block-notice/index.js
  1229. /**
  1230. * WordPress dependencies
  1231. */
  1232. /**
  1233. * Internal dependencies
  1234. */
  1235. const DownloadableBlockNotice = _ref => {
  1236. let {
  1237. block
  1238. } = _ref;
  1239. const errorNotice = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).getErrorNoticeForBlock(block.id), [block]);
  1240. if (!errorNotice) {
  1241. return null;
  1242. }
  1243. return (0,external_wp_element_namespaceObject.createElement)("div", {
  1244. className: "block-directory-downloadable-block-notice"
  1245. }, (0,external_wp_element_namespaceObject.createElement)("div", {
  1246. className: "block-directory-downloadable-block-notice__content"
  1247. }, errorNotice.message, errorNotice.isFatal ? ' ' + (0,external_wp_i18n_namespaceObject.__)('Try reloading the page.') : null));
  1248. };
  1249. /* harmony default export */ var downloadable_block_notice = (DownloadableBlockNotice);
  1250. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/downloadable-block-list-item/index.js
  1251. /**
  1252. * WordPress dependencies
  1253. */
  1254. /**
  1255. * Internal dependencies
  1256. */
  1257. // Return the appropriate block item label, given the block data and status.
  1258. function getDownloadableBlockLabel(_ref, _ref2) {
  1259. let {
  1260. title,
  1261. rating,
  1262. ratingCount
  1263. } = _ref;
  1264. let {
  1265. hasNotice,
  1266. isInstalled,
  1267. isInstalling
  1268. } = _ref2;
  1269. const stars = Math.round(rating / 0.5) * 0.5;
  1270. if (!isInstalled && hasNotice) {
  1271. /* translators: %1$s: block title */
  1272. return (0,external_wp_i18n_namespaceObject.sprintf)('Retry installing %s.', (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title));
  1273. }
  1274. if (isInstalled) {
  1275. /* translators: %1$s: block title */
  1276. return (0,external_wp_i18n_namespaceObject.sprintf)('Add %s.', (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title));
  1277. }
  1278. if (isInstalling) {
  1279. /* translators: %1$s: block title */
  1280. return (0,external_wp_i18n_namespaceObject.sprintf)('Installing %s.', (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title));
  1281. } // No ratings yet, just use the title.
  1282. if (ratingCount < 1) {
  1283. /* translators: %1$s: block title */
  1284. return (0,external_wp_i18n_namespaceObject.sprintf)('Install %s.', (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title));
  1285. }
  1286. return (0,external_wp_i18n_namespaceObject.sprintf)(
  1287. /* translators: %1$s: block title, %2$s: average rating, %3$s: total ratings count. */
  1288. (0,external_wp_i18n_namespaceObject._n)('Install %1$s. %2$s stars with %3$s review.', 'Install %1$s. %2$s stars with %3$s reviews.', ratingCount), (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title), stars, ratingCount);
  1289. }
  1290. function DownloadableBlockListItem(_ref3) {
  1291. let {
  1292. composite,
  1293. item,
  1294. onClick
  1295. } = _ref3;
  1296. const {
  1297. author,
  1298. description,
  1299. icon,
  1300. rating,
  1301. title
  1302. } = item; // getBlockType returns a block object if this block exists, or null if not.
  1303. const isInstalled = !!(0,external_wp_blocks_namespaceObject.getBlockType)(item.name);
  1304. const {
  1305. hasNotice,
  1306. isInstalling,
  1307. isInstallable
  1308. } = (0,external_wp_data_namespaceObject.useSelect)(select => {
  1309. const {
  1310. getErrorNoticeForBlock,
  1311. isInstalling: isBlockInstalling
  1312. } = select(store);
  1313. const notice = getErrorNoticeForBlock(item.id);
  1314. const hasFatal = notice && notice.isFatal;
  1315. return {
  1316. hasNotice: !!notice,
  1317. isInstalling: isBlockInstalling(item.id),
  1318. isInstallable: !hasFatal
  1319. };
  1320. }, [item]);
  1321. let statusText = '';
  1322. if (isInstalled) {
  1323. statusText = (0,external_wp_i18n_namespaceObject.__)('Installed!');
  1324. } else if (isInstalling) {
  1325. statusText = (0,external_wp_i18n_namespaceObject.__)('Installing…');
  1326. }
  1327. return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.__unstableCompositeItem, _extends({
  1328. __experimentalIsFocusable: true,
  1329. role: "option",
  1330. as: external_wp_components_namespaceObject.Button
  1331. }, composite, {
  1332. className: "block-directory-downloadable-block-list-item",
  1333. onClick: event => {
  1334. event.preventDefault();
  1335. onClick();
  1336. },
  1337. isBusy: isInstalling,
  1338. disabled: isInstalling || !isInstallable,
  1339. label: getDownloadableBlockLabel(item, {
  1340. hasNotice,
  1341. isInstalled,
  1342. isInstalling
  1343. }),
  1344. showTooltip: true,
  1345. tooltipPosition: "top center"
  1346. }), (0,external_wp_element_namespaceObject.createElement)("div", {
  1347. className: "block-directory-downloadable-block-list-item__icon"
  1348. }, (0,external_wp_element_namespaceObject.createElement)(downloadable_block_icon, {
  1349. icon: icon,
  1350. title: title
  1351. }), isInstalling ? (0,external_wp_element_namespaceObject.createElement)("span", {
  1352. className: "block-directory-downloadable-block-list-item__spinner"
  1353. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Spinner, null)) : (0,external_wp_element_namespaceObject.createElement)(block_ratings, {
  1354. rating: rating
  1355. })), (0,external_wp_element_namespaceObject.createElement)("span", {
  1356. className: "block-directory-downloadable-block-list-item__details"
  1357. }, (0,external_wp_element_namespaceObject.createElement)("span", {
  1358. className: "block-directory-downloadable-block-list-item__title"
  1359. }, (0,external_wp_element_namespaceObject.createInterpolateElement)((0,external_wp_i18n_namespaceObject.sprintf)(
  1360. /* translators: %1$s: block title, %2$s: author name. */
  1361. (0,external_wp_i18n_namespaceObject.__)('%1$s <span>by %2$s</span>'), (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title), author), {
  1362. span: (0,external_wp_element_namespaceObject.createElement)("span", {
  1363. className: "block-directory-downloadable-block-list-item__author"
  1364. })
  1365. })), hasNotice ? (0,external_wp_element_namespaceObject.createElement)(downloadable_block_notice, {
  1366. block: item
  1367. }) : (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)("span", {
  1368. className: "block-directory-downloadable-block-list-item__desc"
  1369. }, !!statusText ? statusText : (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(description)), isInstallable && !(isInstalled || isInstalling) && (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.VisuallyHidden, null, (0,external_wp_i18n_namespaceObject.__)('Install block')))));
  1370. }
  1371. /* harmony default export */ var downloadable_block_list_item = (DownloadableBlockListItem);
  1372. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/downloadable-blocks-list/index.js
  1373. /**
  1374. * WordPress dependencies
  1375. */
  1376. /**
  1377. * Internal dependencies
  1378. */
  1379. const noop = () => {};
  1380. function DownloadableBlocksList(_ref) {
  1381. let {
  1382. items,
  1383. onHover = noop,
  1384. onSelect
  1385. } = _ref;
  1386. const composite = (0,external_wp_components_namespaceObject.__unstableUseCompositeState)();
  1387. const {
  1388. installBlockType
  1389. } = (0,external_wp_data_namespaceObject.useDispatch)(store);
  1390. if (!items.length) {
  1391. return null;
  1392. }
  1393. return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.__unstableComposite, _extends({}, composite, {
  1394. role: "listbox",
  1395. className: "block-directory-downloadable-blocks-list",
  1396. "aria-label": (0,external_wp_i18n_namespaceObject.__)('Blocks available for install')
  1397. }), items.map(item => {
  1398. return (0,external_wp_element_namespaceObject.createElement)(downloadable_block_list_item, {
  1399. key: item.id,
  1400. composite: composite,
  1401. onClick: () => {
  1402. // Check if the block is registered (`getBlockType`
  1403. // will return an object). If so, insert the block.
  1404. // This prevents installing existing plugins.
  1405. if ((0,external_wp_blocks_namespaceObject.getBlockType)(item.name)) {
  1406. onSelect(item);
  1407. } else {
  1408. installBlockType(item).then(success => {
  1409. if (success) {
  1410. onSelect(item);
  1411. }
  1412. });
  1413. }
  1414. onHover(null);
  1415. },
  1416. onHover: onHover,
  1417. item: item
  1418. });
  1419. }));
  1420. }
  1421. /* harmony default export */ var downloadable_blocks_list = (DownloadableBlocksList);
  1422. ;// CONCATENATED MODULE: external ["wp","a11y"]
  1423. var external_wp_a11y_namespaceObject = window["wp"]["a11y"];
  1424. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/downloadable-blocks-panel/inserter-panel.js
  1425. /**
  1426. * WordPress dependencies
  1427. */
  1428. function DownloadableBlocksInserterPanel(_ref) {
  1429. let {
  1430. children,
  1431. downloadableItems,
  1432. hasLocalBlocks
  1433. } = _ref;
  1434. const count = downloadableItems.length;
  1435. (0,external_wp_element_namespaceObject.useEffect)(() => {
  1436. (0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.sprintf)(
  1437. /* translators: %d: number of available blocks. */
  1438. (0,external_wp_i18n_namespaceObject._n)('%d additional block is available to install.', '%d additional blocks are available to install.', count), count));
  1439. }, [count]);
  1440. return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, !hasLocalBlocks && (0,external_wp_element_namespaceObject.createElement)("p", {
  1441. className: "block-directory-downloadable-blocks-panel__no-local"
  1442. }, (0,external_wp_i18n_namespaceObject.__)('No results available from your installed blocks.')), (0,external_wp_element_namespaceObject.createElement)("div", {
  1443. className: "block-editor-inserter__quick-inserter-separator"
  1444. }), (0,external_wp_element_namespaceObject.createElement)("div", {
  1445. className: "block-directory-downloadable-blocks-panel"
  1446. }, (0,external_wp_element_namespaceObject.createElement)("div", {
  1447. className: "block-directory-downloadable-blocks-panel__header"
  1448. }, (0,external_wp_element_namespaceObject.createElement)("h2", {
  1449. className: "block-directory-downloadable-blocks-panel__title"
  1450. }, (0,external_wp_i18n_namespaceObject.__)('Available to install')), (0,external_wp_element_namespaceObject.createElement)("p", {
  1451. className: "block-directory-downloadable-blocks-panel__description"
  1452. }, (0,external_wp_i18n_namespaceObject.__)('Select a block to install and add it to your post.'))), children));
  1453. }
  1454. /* harmony default export */ var inserter_panel = (DownloadableBlocksInserterPanel);
  1455. ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/block-default.js
  1456. /**
  1457. * WordPress dependencies
  1458. */
  1459. const blockDefault = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, {
  1460. xmlns: "http://www.w3.org/2000/svg",
  1461. viewBox: "0 0 24 24"
  1462. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, {
  1463. d: "M19 8h-1V6h-5v2h-2V6H6v2H5c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2v-8c0-1.1-.9-2-2-2zm.5 10c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5v-8c0-.3.2-.5.5-.5h14c.3 0 .5.2.5.5v8z"
  1464. }));
  1465. /* harmony default export */ var block_default = (blockDefault);
  1466. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/downloadable-blocks-panel/no-results.js
  1467. /**
  1468. * WordPress dependencies
  1469. */
  1470. function DownloadableBlocksNoResults() {
  1471. return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)("div", {
  1472. className: "block-editor-inserter__no-results"
  1473. }, (0,external_wp_element_namespaceObject.createElement)(icon, {
  1474. className: "block-editor-inserter__no-results-icon",
  1475. icon: block_default
  1476. }), (0,external_wp_element_namespaceObject.createElement)("p", null, (0,external_wp_i18n_namespaceObject.__)('No results found.'))), (0,external_wp_element_namespaceObject.createElement)("div", {
  1477. className: "block-editor-inserter__tips"
  1478. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Tip, null, (0,external_wp_i18n_namespaceObject.__)('Interested in creating your own block?'), (0,external_wp_element_namespaceObject.createElement)("br", null), (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.ExternalLink, {
  1479. href: "https://developer.wordpress.org/block-editor/"
  1480. }, (0,external_wp_i18n_namespaceObject.__)('Get started here'), "."))));
  1481. }
  1482. /* harmony default export */ var no_results = (DownloadableBlocksNoResults);
  1483. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/downloadable-blocks-panel/index.js
  1484. /**
  1485. * WordPress dependencies
  1486. */
  1487. /**
  1488. * Internal dependencies
  1489. */
  1490. function DownloadableBlocksPanel(_ref) {
  1491. let {
  1492. downloadableItems,
  1493. onSelect,
  1494. onHover,
  1495. hasLocalBlocks,
  1496. hasPermission,
  1497. isLoading,
  1498. isTyping
  1499. } = _ref;
  1500. if (typeof hasPermission === 'undefined' || isLoading || isTyping) {
  1501. return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, hasPermission && !hasLocalBlocks && (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)("p", {
  1502. className: "block-directory-downloadable-blocks-panel__no-local"
  1503. }, (0,external_wp_i18n_namespaceObject.__)('No results available from your installed blocks.')), (0,external_wp_element_namespaceObject.createElement)("div", {
  1504. className: "block-editor-inserter__quick-inserter-separator"
  1505. })), (0,external_wp_element_namespaceObject.createElement)("div", {
  1506. className: "block-directory-downloadable-blocks-panel has-blocks-loading"
  1507. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Spinner, null)));
  1508. }
  1509. if (false === hasPermission) {
  1510. if (!hasLocalBlocks) {
  1511. return (0,external_wp_element_namespaceObject.createElement)(no_results, null);
  1512. }
  1513. return null;
  1514. }
  1515. return !!downloadableItems.length ? (0,external_wp_element_namespaceObject.createElement)(inserter_panel, {
  1516. downloadableItems: downloadableItems,
  1517. hasLocalBlocks: hasLocalBlocks
  1518. }, (0,external_wp_element_namespaceObject.createElement)(downloadable_blocks_list, {
  1519. items: downloadableItems,
  1520. onSelect: onSelect,
  1521. onHover: onHover
  1522. })) : !hasLocalBlocks && (0,external_wp_element_namespaceObject.createElement)(no_results, null);
  1523. }
  1524. /* harmony default export */ var downloadable_blocks_panel = ((0,external_wp_compose_namespaceObject.compose)([(0,external_wp_data_namespaceObject.withSelect)((select, _ref2) => {
  1525. let {
  1526. filterValue,
  1527. rootClientId = null
  1528. } = _ref2;
  1529. const {
  1530. getDownloadableBlocks,
  1531. isRequestingDownloadableBlocks
  1532. } = select(store);
  1533. const {
  1534. canInsertBlockType
  1535. } = select(external_wp_blockEditor_namespaceObject.store);
  1536. const hasPermission = select(external_wp_coreData_namespaceObject.store).canUser('read', 'block-directory/search');
  1537. function getInstallableBlocks(term) {
  1538. return getDownloadableBlocks(term).filter(block => canInsertBlockType(block, rootClientId, true));
  1539. }
  1540. const downloadableItems = hasPermission ? getInstallableBlocks(filterValue) : [];
  1541. const isLoading = isRequestingDownloadableBlocks(filterValue);
  1542. return {
  1543. downloadableItems,
  1544. hasPermission,
  1545. isLoading
  1546. };
  1547. })])(DownloadableBlocksPanel));
  1548. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.js
  1549. /**
  1550. * External dependencies
  1551. */
  1552. /**
  1553. * WordPress dependencies
  1554. */
  1555. /**
  1556. * Internal dependencies
  1557. */
  1558. function InserterMenuDownloadableBlocksPanel() {
  1559. const [debouncedFilterValue, setFilterValue] = (0,external_wp_element_namespaceObject.useState)('');
  1560. const debouncedSetFilterValue = (0,external_lodash_namespaceObject.debounce)(setFilterValue, 400);
  1561. return (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.__unstableInserterMenuExtension, null, _ref => {
  1562. let {
  1563. onSelect,
  1564. onHover,
  1565. filterValue,
  1566. hasItems,
  1567. rootClientId
  1568. } = _ref;
  1569. if (debouncedFilterValue !== filterValue) {
  1570. debouncedSetFilterValue(filterValue);
  1571. }
  1572. if (!debouncedFilterValue) {
  1573. return null;
  1574. }
  1575. return (0,external_wp_element_namespaceObject.createElement)(downloadable_blocks_panel, {
  1576. onSelect: onSelect,
  1577. onHover: onHover,
  1578. rootClientId: rootClientId,
  1579. filterValue: debouncedFilterValue,
  1580. hasLocalBlocks: hasItems,
  1581. isTyping: filterValue !== debouncedFilterValue
  1582. });
  1583. });
  1584. }
  1585. /* harmony default export */ var inserter_menu_downloadable_blocks_panel = (InserterMenuDownloadableBlocksPanel);
  1586. ;// CONCATENATED MODULE: external ["wp","editPost"]
  1587. var external_wp_editPost_namespaceObject = window["wp"]["editPost"];
  1588. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/compact-list/index.js
  1589. /**
  1590. * WordPress dependencies
  1591. */
  1592. /**
  1593. * Internal dependencies
  1594. */
  1595. function CompactList(_ref) {
  1596. let {
  1597. items
  1598. } = _ref;
  1599. if (!items.length) {
  1600. return null;
  1601. }
  1602. return (0,external_wp_element_namespaceObject.createElement)("ul", {
  1603. className: "block-directory-compact-list"
  1604. }, items.map(_ref2 => {
  1605. let {
  1606. icon,
  1607. id,
  1608. title,
  1609. author
  1610. } = _ref2;
  1611. return (0,external_wp_element_namespaceObject.createElement)("li", {
  1612. key: id,
  1613. className: "block-directory-compact-list__item"
  1614. }, (0,external_wp_element_namespaceObject.createElement)(downloadable_block_icon, {
  1615. icon: icon,
  1616. title: title
  1617. }), (0,external_wp_element_namespaceObject.createElement)("div", {
  1618. className: "block-directory-compact-list__item-details"
  1619. }, (0,external_wp_element_namespaceObject.createElement)("div", {
  1620. className: "block-directory-compact-list__item-title"
  1621. }, title), (0,external_wp_element_namespaceObject.createElement)("div", {
  1622. className: "block-directory-compact-list__item-author"
  1623. }, (0,external_wp_i18n_namespaceObject.sprintf)(
  1624. /* translators: %s: Name of the block author. */
  1625. (0,external_wp_i18n_namespaceObject.__)('By %s'), author))));
  1626. }));
  1627. }
  1628. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/plugins/installed-blocks-pre-publish-panel/index.js
  1629. /**
  1630. * WordPress dependencies
  1631. */
  1632. /**
  1633. * Internal dependencies
  1634. */
  1635. function InstalledBlocksPrePublishPanel() {
  1636. const newBlockTypes = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).getNewBlockTypes(), []);
  1637. if (!newBlockTypes.length) {
  1638. return null;
  1639. }
  1640. return (0,external_wp_element_namespaceObject.createElement)(external_wp_editPost_namespaceObject.PluginPrePublishPanel, {
  1641. icon: block_default,
  1642. title: (0,external_wp_i18n_namespaceObject.sprintf)( // translators: %d: number of blocks (number).
  1643. (0,external_wp_i18n_namespaceObject._n)('Added: %d block', 'Added: %d blocks', newBlockTypes.length), newBlockTypes.length),
  1644. initialOpen: true
  1645. }, (0,external_wp_element_namespaceObject.createElement)("p", {
  1646. className: "installed-blocks-pre-publish-panel__copy"
  1647. }, (0,external_wp_i18n_namespaceObject._n)('The following block has been added to your site.', 'The following blocks have been added to your site.', newBlockTypes.length)), (0,external_wp_element_namespaceObject.createElement)(CompactList, {
  1648. items: newBlockTypes
  1649. }));
  1650. }
  1651. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/plugins/get-install-missing/install-button.js
  1652. /**
  1653. * WordPress dependencies
  1654. */
  1655. /**
  1656. * Internal dependencies
  1657. */
  1658. function InstallButton(_ref) {
  1659. let {
  1660. attributes,
  1661. block,
  1662. clientId
  1663. } = _ref;
  1664. const isInstallingBlock = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).isInstalling(block.id), [block.id]);
  1665. const {
  1666. installBlockType
  1667. } = (0,external_wp_data_namespaceObject.useDispatch)(store);
  1668. const {
  1669. replaceBlock
  1670. } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
  1671. return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, {
  1672. onClick: () => installBlockType(block).then(success => {
  1673. if (success) {
  1674. const blockType = (0,external_wp_blocks_namespaceObject.getBlockType)(block.name);
  1675. const [originalBlock] = (0,external_wp_blocks_namespaceObject.parse)(attributes.originalContent);
  1676. if (originalBlock && blockType) {
  1677. replaceBlock(clientId, (0,external_wp_blocks_namespaceObject.createBlock)(blockType.name, originalBlock.attributes, originalBlock.innerBlocks));
  1678. }
  1679. }
  1680. }),
  1681. disabled: isInstallingBlock,
  1682. isBusy: isInstallingBlock,
  1683. variant: "primary"
  1684. }, (0,external_wp_i18n_namespaceObject.sprintf)(
  1685. /* translators: %s: block name */
  1686. (0,external_wp_i18n_namespaceObject.__)('Install %s'), block.title));
  1687. }
  1688. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/plugins/get-install-missing/index.js
  1689. /**
  1690. * WordPress dependencies
  1691. */
  1692. /**
  1693. * Internal dependencies
  1694. */
  1695. const getInstallMissing = OriginalComponent => props => {
  1696. const {
  1697. originalName
  1698. } = props.attributes; // Disable reason: This is a valid component, but it's mistaken for a callback.
  1699. // eslint-disable-next-line react-hooks/rules-of-hooks
  1700. const {
  1701. block,
  1702. hasPermission
  1703. } = (0,external_wp_data_namespaceObject.useSelect)(select => {
  1704. const {
  1705. getDownloadableBlocks
  1706. } = select(store);
  1707. const blocks = getDownloadableBlocks('block:' + originalName).filter(_ref => {
  1708. let {
  1709. name
  1710. } = _ref;
  1711. return originalName === name;
  1712. });
  1713. return {
  1714. hasPermission: select(external_wp_coreData_namespaceObject.store).canUser('read', 'block-directory/search'),
  1715. block: blocks.length && blocks[0]
  1716. };
  1717. }, [originalName]); // The user can't install blocks, or the block isn't available for download.
  1718. if (!hasPermission || !block) {
  1719. return (0,external_wp_element_namespaceObject.createElement)(OriginalComponent, props);
  1720. }
  1721. return (0,external_wp_element_namespaceObject.createElement)(ModifiedWarning, _extends({}, props, {
  1722. originalBlock: block
  1723. }));
  1724. };
  1725. const ModifiedWarning = _ref2 => {
  1726. let {
  1727. originalBlock,
  1728. ...props
  1729. } = _ref2;
  1730. const {
  1731. originalName,
  1732. originalUndelimitedContent
  1733. } = props.attributes;
  1734. const {
  1735. replaceBlock
  1736. } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
  1737. const convertToHTML = () => {
  1738. replaceBlock(props.clientId, (0,external_wp_blocks_namespaceObject.createBlock)('core/html', {
  1739. content: originalUndelimitedContent
  1740. }));
  1741. };
  1742. const hasContent = !!originalUndelimitedContent;
  1743. const hasHTMLBlock = (0,external_wp_blocks_namespaceObject.getBlockType)('core/html');
  1744. let messageHTML = (0,external_wp_i18n_namespaceObject.sprintf)(
  1745. /* translators: %s: block name */
  1746. (0,external_wp_i18n_namespaceObject.__)('Your site doesn’t include support for the %s block. You can try installing the block or remove it entirely.'), originalBlock.title || originalName);
  1747. const actions = [(0,external_wp_element_namespaceObject.createElement)(InstallButton, {
  1748. key: "install",
  1749. block: originalBlock,
  1750. attributes: props.attributes,
  1751. clientId: props.clientId
  1752. })];
  1753. if (hasContent && hasHTMLBlock) {
  1754. messageHTML = (0,external_wp_i18n_namespaceObject.sprintf)(
  1755. /* translators: %s: block name */
  1756. (0,external_wp_i18n_namespaceObject.__)('Your site doesn’t include support for the %s block. You can try installing the block, convert it to a Custom HTML block, or remove it entirely.'), originalBlock.title || originalName);
  1757. actions.push((0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, {
  1758. key: "convert",
  1759. onClick: convertToHTML,
  1760. variant: "link"
  1761. }, (0,external_wp_i18n_namespaceObject.__)('Keep as HTML')));
  1762. }
  1763. return (0,external_wp_element_namespaceObject.createElement)("div", (0,external_wp_blockEditor_namespaceObject.useBlockProps)(), (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.Warning, {
  1764. actions: actions
  1765. }, messageHTML), (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.RawHTML, null, originalUndelimitedContent));
  1766. };
  1767. /* harmony default export */ var get_install_missing = (getInstallMissing);
  1768. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/plugins/index.js
  1769. /**
  1770. * WordPress dependencies
  1771. */
  1772. /**
  1773. * Internal dependencies
  1774. */
  1775. (0,external_wp_plugins_namespaceObject.registerPlugin)('block-directory', {
  1776. render() {
  1777. return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)(AutoBlockUninstaller, null), (0,external_wp_element_namespaceObject.createElement)(inserter_menu_downloadable_blocks_panel, null), (0,external_wp_element_namespaceObject.createElement)(InstalledBlocksPrePublishPanel, null));
  1778. }
  1779. });
  1780. (0,external_wp_hooks_namespaceObject.addFilter)('blocks.registerBlockType', 'block-directory/fallback', (settings, name) => {
  1781. if (name !== 'core/missing') {
  1782. return settings;
  1783. }
  1784. settings.edit = get_install_missing(settings.edit);
  1785. return settings;
  1786. });
  1787. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/index.js
  1788. /**
  1789. * Internal dependencies
  1790. */
  1791. (window.wp = window.wp || {}).blockDirectory = __webpack_exports__;
  1792. /******/ })()
  1793. ;