Açıklama Yok

block-directory.js 57KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797
  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: external "lodash"
  101. var external_lodash_namespaceObject = window["lodash"];
  102. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/reducer.js
  103. /**
  104. * External dependencies
  105. */
  106. /**
  107. * WordPress dependencies
  108. */
  109. /**
  110. * Reducer returning an array of downloadable blocks.
  111. *
  112. * @param {Object} state Current state.
  113. * @param {Object} action Dispatched action.
  114. *
  115. * @return {Object} Updated state.
  116. */
  117. const downloadableBlocks = function () {
  118. let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  119. let action = arguments.length > 1 ? arguments[1] : undefined;
  120. switch (action.type) {
  121. case 'FETCH_DOWNLOADABLE_BLOCKS':
  122. return { ...state,
  123. [action.filterValue]: {
  124. isRequesting: true
  125. }
  126. };
  127. case 'RECEIVE_DOWNLOADABLE_BLOCKS':
  128. return { ...state,
  129. [action.filterValue]: {
  130. results: action.downloadableBlocks,
  131. isRequesting: false
  132. }
  133. };
  134. }
  135. return state;
  136. };
  137. /**
  138. * Reducer managing the installation and deletion of blocks.
  139. *
  140. * @param {Object} state Current state.
  141. * @param {Object} action Dispatched action.
  142. *
  143. * @return {Object} Updated state.
  144. */
  145. const blockManagement = function () {
  146. let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
  147. installedBlockTypes: [],
  148. isInstalling: {}
  149. };
  150. let action = arguments.length > 1 ? arguments[1] : undefined;
  151. switch (action.type) {
  152. case 'ADD_INSTALLED_BLOCK_TYPE':
  153. return { ...state,
  154. installedBlockTypes: [...state.installedBlockTypes, action.item]
  155. };
  156. case 'REMOVE_INSTALLED_BLOCK_TYPE':
  157. return { ...state,
  158. installedBlockTypes: state.installedBlockTypes.filter(blockType => blockType.name !== action.item.name)
  159. };
  160. case 'SET_INSTALLING_BLOCK':
  161. return { ...state,
  162. isInstalling: { ...state.isInstalling,
  163. [action.blockId]: action.isInstalling
  164. }
  165. };
  166. }
  167. return state;
  168. };
  169. /**
  170. * Reducer returning an object of error notices.
  171. *
  172. * @param {Object} state Current state.
  173. * @param {Object} action Dispatched action.
  174. *
  175. * @return {Object} Updated state.
  176. */
  177. const errorNotices = function () {
  178. let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  179. let action = arguments.length > 1 ? arguments[1] : undefined;
  180. switch (action.type) {
  181. case 'SET_ERROR_NOTICE':
  182. return { ...state,
  183. [action.blockId]: {
  184. message: action.message,
  185. isFatal: action.isFatal
  186. }
  187. };
  188. case 'CLEAR_ERROR_NOTICE':
  189. return (0,external_lodash_namespaceObject.omit)(state, action.blockId);
  190. }
  191. return state;
  192. };
  193. /* harmony default export */ var reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
  194. downloadableBlocks,
  195. blockManagement,
  196. errorNotices
  197. }));
  198. ;// CONCATENATED MODULE: external ["wp","blockEditor"]
  199. var external_wp_blockEditor_namespaceObject = window["wp"]["blockEditor"];
  200. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/utils/has-block-type.js
  201. /**
  202. * Check if a block list contains a specific block type. Recursively searches
  203. * through `innerBlocks` if they exist.
  204. *
  205. * @param {Object} blockType A block object to search for.
  206. * @param {Object[]} blocks The list of blocks to look through.
  207. *
  208. * @return {boolean} Whether the blockType is found.
  209. */
  210. function hasBlockType(blockType) {
  211. let blocks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  212. if (!blocks.length) {
  213. return false;
  214. }
  215. if (blocks.some(_ref => {
  216. let {
  217. name
  218. } = _ref;
  219. return name === blockType.name;
  220. })) {
  221. return true;
  222. }
  223. for (let i = 0; i < blocks.length; i++) {
  224. if (hasBlockType(blockType, blocks[i].innerBlocks)) {
  225. return true;
  226. }
  227. }
  228. return false;
  229. }
  230. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/selectors.js
  231. /**
  232. * WordPress dependencies
  233. */
  234. /**
  235. * Internal dependencies
  236. */
  237. /**
  238. * Returns true if application is requesting for downloadable blocks.
  239. *
  240. * @param {Object} state Global application state.
  241. * @param {string} filterValue Search string.
  242. *
  243. * @return {boolean} Whether a request is in progress for the blocks list.
  244. */
  245. function isRequestingDownloadableBlocks(state, filterValue) {
  246. var _state$downloadableBl, _state$downloadableBl2;
  247. 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;
  248. }
  249. /**
  250. * Returns the available uninstalled blocks.
  251. *
  252. * @param {Object} state Global application state.
  253. * @param {string} filterValue Search string.
  254. *
  255. * @return {Array} Downloadable blocks.
  256. */
  257. function getDownloadableBlocks(state, filterValue) {
  258. var _state$downloadableBl3, _state$downloadableBl4;
  259. 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 : [];
  260. }
  261. /**
  262. * Returns the block types that have been installed on the server in this
  263. * session.
  264. *
  265. * @param {Object} state Global application state.
  266. *
  267. * @return {Array} Block type items
  268. */
  269. function getInstalledBlockTypes(state) {
  270. return state.blockManagement.installedBlockTypes;
  271. }
  272. /**
  273. * Returns block types that have been installed on the server and used in the
  274. * current post.
  275. *
  276. * @param {Object} state Global application state.
  277. *
  278. * @return {Array} Block type items.
  279. */
  280. const getNewBlockTypes = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => state => {
  281. const usedBlockTree = select(external_wp_blockEditor_namespaceObject.store).getBlocks();
  282. const installedBlockTypes = getInstalledBlockTypes(state);
  283. return installedBlockTypes.filter(blockType => hasBlockType(blockType, usedBlockTree));
  284. });
  285. /**
  286. * Returns the block types that have been installed on the server but are not
  287. * used in the current post.
  288. *
  289. * @param {Object} state Global application state.
  290. *
  291. * @return {Array} Block type items.
  292. */
  293. const getUnusedBlockTypes = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => state => {
  294. const usedBlockTree = select(external_wp_blockEditor_namespaceObject.store).getBlocks();
  295. const installedBlockTypes = getInstalledBlockTypes(state);
  296. return installedBlockTypes.filter(blockType => !hasBlockType(blockType, usedBlockTree));
  297. });
  298. /**
  299. * Returns true if a block plugin install is in progress.
  300. *
  301. * @param {Object} state Global application state.
  302. * @param {string} blockId Id of the block.
  303. *
  304. * @return {boolean} Whether this block is currently being installed.
  305. */
  306. function isInstalling(state, blockId) {
  307. return state.blockManagement.isInstalling[blockId] || false;
  308. }
  309. /**
  310. * Returns all block error notices.
  311. *
  312. * @param {Object} state Global application state.
  313. *
  314. * @return {Object} Object with error notices.
  315. */
  316. function getErrorNotices(state) {
  317. return state.errorNotices;
  318. }
  319. /**
  320. * Returns the error notice for a given block.
  321. *
  322. * @param {Object} state Global application state.
  323. * @param {string} blockId The ID of the block plugin. eg: my-block
  324. *
  325. * @return {string|boolean} The error text, or false if no error.
  326. */
  327. function getErrorNoticeForBlock(state, blockId) {
  328. return state.errorNotices[blockId];
  329. }
  330. ;// CONCATENATED MODULE: external ["wp","i18n"]
  331. var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
  332. ;// CONCATENATED MODULE: external ["wp","apiFetch"]
  333. var external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"];
  334. var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject);
  335. ;// CONCATENATED MODULE: external ["wp","notices"]
  336. var external_wp_notices_namespaceObject = window["wp"]["notices"];
  337. ;// CONCATENATED MODULE: external ["wp","url"]
  338. var external_wp_url_namespaceObject = window["wp"]["url"];
  339. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/load-assets.js
  340. /**
  341. * WordPress dependencies
  342. */
  343. /**
  344. * Load an asset for a block.
  345. *
  346. * This function returns a Promise that will resolve once the asset is loaded,
  347. * or in the case of Stylesheets and Inline JavaScript, will resolve immediately.
  348. *
  349. * @param {HTMLElement} el A HTML Element asset to inject.
  350. *
  351. * @return {Promise} Promise which will resolve when the asset is loaded.
  352. */
  353. const loadAsset = el => {
  354. return new Promise((resolve, reject) => {
  355. /*
  356. * Reconstruct the passed element, this is required as inserting the Node directly
  357. * won't always fire the required onload events, even if the asset wasn't already loaded.
  358. */
  359. const newNode = document.createElement(el.nodeName);
  360. ['id', 'rel', 'src', 'href', 'type'].forEach(attr => {
  361. if (el[attr]) {
  362. newNode[attr] = el[attr];
  363. }
  364. }); // Append inline <script> contents.
  365. if (el.innerHTML) {
  366. newNode.appendChild(document.createTextNode(el.innerHTML));
  367. }
  368. newNode.onload = () => resolve(true);
  369. newNode.onerror = () => reject(new Error('Error loading asset.'));
  370. document.body.appendChild(newNode); // Resolve Stylesheets and Inline JavaScript immediately.
  371. if ('link' === newNode.nodeName.toLowerCase() || 'script' === newNode.nodeName.toLowerCase() && !newNode.src) {
  372. resolve();
  373. }
  374. });
  375. };
  376. /**
  377. * Load the asset files for a block
  378. */
  379. async function loadAssets() {
  380. /*
  381. * Fetch the current URL (post-new.php, or post.php?post=1&action=edit) and compare the
  382. * JavaScript and CSS assets loaded between the pages. This imports the required assets
  383. * for the block into the current page while not requiring that we know them up-front.
  384. * In the future this can be improved by reliance upon block.json and/or a script-loader
  385. * dependency API.
  386. */
  387. const response = await external_wp_apiFetch_default()({
  388. url: document.location.href,
  389. parse: false
  390. });
  391. const data = await response.text();
  392. const doc = new window.DOMParser().parseFromString(data, 'text/html');
  393. const newAssets = Array.from(doc.querySelectorAll('link[rel="stylesheet"],script')).filter(asset => asset.id && !document.getElementById(asset.id));
  394. /*
  395. * Load each asset in order, as they may depend upon an earlier loaded script.
  396. * Stylesheets and Inline Scripts will resolve immediately upon insertion.
  397. */
  398. for (const newAsset of newAssets) {
  399. await loadAsset(newAsset);
  400. }
  401. }
  402. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/utils/get-plugin-url.js
  403. /**
  404. * Get the plugin's direct API link out of a block-directory response.
  405. *
  406. * @param {Object} block The block object
  407. *
  408. * @return {string} The plugin URL, if exists.
  409. */
  410. function getPluginUrl(block) {
  411. if (!block) {
  412. return false;
  413. }
  414. const link = block.links['wp:plugin'] || block.links.self;
  415. if (link && link.length) {
  416. return link[0].href;
  417. }
  418. return false;
  419. }
  420. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/actions.js
  421. /**
  422. * External dependencies
  423. */
  424. /**
  425. * WordPress dependencies
  426. */
  427. /**
  428. * Internal dependencies
  429. */
  430. /**
  431. * Returns an action object used in signalling that the downloadable blocks
  432. * have been requested and are loading.
  433. *
  434. * @param {string} filterValue Search string.
  435. *
  436. * @return {Object} Action object.
  437. */
  438. function fetchDownloadableBlocks(filterValue) {
  439. return {
  440. type: 'FETCH_DOWNLOADABLE_BLOCKS',
  441. filterValue
  442. };
  443. }
  444. /**
  445. * Returns an action object used in signalling that the downloadable blocks
  446. * have been updated.
  447. *
  448. * @param {Array} downloadableBlocks Downloadable blocks.
  449. * @param {string} filterValue Search string.
  450. *
  451. * @return {Object} Action object.
  452. */
  453. function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
  454. return {
  455. type: 'RECEIVE_DOWNLOADABLE_BLOCKS',
  456. downloadableBlocks,
  457. filterValue
  458. };
  459. }
  460. /**
  461. * Action triggered to install a block plugin.
  462. *
  463. * @param {Object} block The block item returned by search.
  464. *
  465. * @return {boolean} Whether the block was successfully installed & loaded.
  466. */
  467. const installBlockType = block => async _ref => {
  468. let {
  469. registry,
  470. dispatch
  471. } = _ref;
  472. const {
  473. id,
  474. name
  475. } = block;
  476. let success = false;
  477. dispatch.clearErrorNotice(id);
  478. try {
  479. dispatch.setIsInstalling(id, true); // If we have a wp:plugin link, the plugin is installed but inactive.
  480. const url = getPluginUrl(block);
  481. let links = {};
  482. if (url) {
  483. await external_wp_apiFetch_default()({
  484. method: 'PUT',
  485. url,
  486. data: {
  487. status: 'active'
  488. }
  489. });
  490. } else {
  491. const response = await external_wp_apiFetch_default()({
  492. method: 'POST',
  493. path: 'wp/v2/plugins',
  494. data: {
  495. slug: id,
  496. status: 'active'
  497. }
  498. }); // Add the `self` link for newly-installed blocks.
  499. links = response._links;
  500. }
  501. dispatch.addInstalledBlockType({ ...block,
  502. links: { ...block.links,
  503. ...links
  504. }
  505. }); // Ensures that the block metadata is propagated to the editor when registered on the server.
  506. const metadataFields = ['api_version', 'title', 'category', 'parent', 'icon', 'description', 'keywords', 'attributes', 'provides_context', 'uses_context', 'supports', 'styles', 'example', 'variations'];
  507. await external_wp_apiFetch_default()({
  508. path: (0,external_wp_url_namespaceObject.addQueryArgs)(`/wp/v2/block-types/${name}`, {
  509. _fields: metadataFields
  510. })
  511. }) // Ignore when the block is not registered on the server.
  512. .catch(() => {}).then(response => {
  513. if (!response) {
  514. return;
  515. }
  516. (0,external_wp_blocks_namespaceObject.unstable__bootstrapServerSideBlockDefinitions)({
  517. [name]: (0,external_lodash_namespaceObject.pick)(response, metadataFields)
  518. });
  519. });
  520. await loadAssets();
  521. const registeredBlocks = registry.select(external_wp_blocks_namespaceObject.store).getBlockTypes();
  522. if (!registeredBlocks.some(i => i.name === name)) {
  523. throw new Error((0,external_wp_i18n_namespaceObject.__)('Error registering block. Try reloading the page.'));
  524. }
  525. registry.dispatch(external_wp_notices_namespaceObject.store).createInfoNotice((0,external_wp_i18n_namespaceObject.sprintf)( // translators: %s is the block title.
  526. (0,external_wp_i18n_namespaceObject.__)('Block %s installed and added.'), block.title), {
  527. speak: true,
  528. type: 'snackbar'
  529. });
  530. success = true;
  531. } catch (error) {
  532. let message = error.message || (0,external_wp_i18n_namespaceObject.__)('An error occurred.'); // Errors we throw are fatal.
  533. let isFatal = error instanceof Error; // Specific API errors that are fatal.
  534. const fatalAPIErrors = {
  535. folder_exists: (0,external_wp_i18n_namespaceObject.__)('This block is already installed. Try reloading the page.'),
  536. unable_to_connect_to_filesystem: (0,external_wp_i18n_namespaceObject.__)('Error installing block. You can reload the page and try again.')
  537. };
  538. if (fatalAPIErrors[error.code]) {
  539. isFatal = true;
  540. message = fatalAPIErrors[error.code];
  541. }
  542. dispatch.setErrorNotice(id, message, isFatal);
  543. registry.dispatch(external_wp_notices_namespaceObject.store).createErrorNotice(message, {
  544. speak: true,
  545. isDismissible: true
  546. });
  547. }
  548. dispatch.setIsInstalling(id, false);
  549. return success;
  550. };
  551. /**
  552. * Action triggered to uninstall a block plugin.
  553. *
  554. * @param {Object} block The blockType object.
  555. */
  556. const uninstallBlockType = block => async _ref2 => {
  557. let {
  558. registry,
  559. dispatch
  560. } = _ref2;
  561. try {
  562. const url = getPluginUrl(block);
  563. await external_wp_apiFetch_default()({
  564. method: 'PUT',
  565. url,
  566. data: {
  567. status: 'inactive'
  568. }
  569. });
  570. await external_wp_apiFetch_default()({
  571. method: 'DELETE',
  572. url
  573. });
  574. dispatch.removeInstalledBlockType(block);
  575. } catch (error) {
  576. registry.dispatch(external_wp_notices_namespaceObject.store).createErrorNotice(error.message || (0,external_wp_i18n_namespaceObject.__)('An error occurred.'));
  577. }
  578. };
  579. /**
  580. * Returns an action object used to add a block type to the "newly installed"
  581. * tracking list.
  582. *
  583. * @param {Object} item The block item with the block id and name.
  584. *
  585. * @return {Object} Action object.
  586. */
  587. function addInstalledBlockType(item) {
  588. return {
  589. type: 'ADD_INSTALLED_BLOCK_TYPE',
  590. item
  591. };
  592. }
  593. /**
  594. * Returns an action object used to remove a block type from the "newly installed"
  595. * tracking list.
  596. *
  597. * @param {string} item The block item with the block id and name.
  598. *
  599. * @return {Object} Action object.
  600. */
  601. function removeInstalledBlockType(item) {
  602. return {
  603. type: 'REMOVE_INSTALLED_BLOCK_TYPE',
  604. item
  605. };
  606. }
  607. /**
  608. * Returns an action object used to indicate install in progress.
  609. *
  610. * @param {string} blockId
  611. * @param {boolean} isInstalling
  612. *
  613. * @return {Object} Action object.
  614. */
  615. function setIsInstalling(blockId, isInstalling) {
  616. return {
  617. type: 'SET_INSTALLING_BLOCK',
  618. blockId,
  619. isInstalling
  620. };
  621. }
  622. /**
  623. * Sets an error notice to be displayed to the user for a given block.
  624. *
  625. * @param {string} blockId The ID of the block plugin. eg: my-block
  626. * @param {string} message The message shown in the notice.
  627. * @param {boolean} isFatal Whether the user can recover from the error.
  628. *
  629. * @return {Object} Action object.
  630. */
  631. function setErrorNotice(blockId, message) {
  632. let isFatal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  633. return {
  634. type: 'SET_ERROR_NOTICE',
  635. blockId,
  636. message,
  637. isFatal
  638. };
  639. }
  640. /**
  641. * Sets the error notice to empty for specific block.
  642. *
  643. * @param {string} blockId The ID of the block plugin. eg: my-block
  644. *
  645. * @return {Object} Action object.
  646. */
  647. function clearErrorNotice(blockId) {
  648. return {
  649. type: 'CLEAR_ERROR_NOTICE',
  650. blockId
  651. };
  652. }
  653. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/resolvers.js
  654. /**
  655. * External dependencies
  656. */
  657. /**
  658. * WordPress dependencies
  659. */
  660. /**
  661. * Internal dependencies
  662. */
  663. const resolvers_getDownloadableBlocks = filterValue => async _ref => {
  664. let {
  665. dispatch
  666. } = _ref;
  667. if (!filterValue) {
  668. return;
  669. }
  670. try {
  671. dispatch(fetchDownloadableBlocks(filterValue));
  672. const results = await external_wp_apiFetch_default()({
  673. path: `wp/v2/block-directory/search?term=${filterValue}`
  674. });
  675. const blocks = results.map(result => (0,external_lodash_namespaceObject.mapKeys)(result, (value, key) => (0,external_lodash_namespaceObject.camelCase)(key)));
  676. dispatch(receiveDownloadableBlocks(blocks, filterValue));
  677. } catch {}
  678. };
  679. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/store/index.js
  680. /**
  681. * WordPress dependencies
  682. */
  683. /**
  684. * Internal dependencies
  685. */
  686. /**
  687. * Module Constants
  688. */
  689. const STORE_NAME = 'core/block-directory';
  690. /**
  691. * Block editor data store configuration.
  692. *
  693. * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registerStore
  694. *
  695. * @type {Object}
  696. */
  697. const storeConfig = {
  698. reducer: reducer,
  699. selectors: selectors_namespaceObject,
  700. actions: actions_namespaceObject,
  701. resolvers: resolvers_namespaceObject
  702. };
  703. /**
  704. * Store definition for the block directory namespace.
  705. *
  706. * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
  707. *
  708. * @type {Object}
  709. */
  710. const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, storeConfig);
  711. (0,external_wp_data_namespaceObject.register)(store);
  712. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/auto-block-uninstaller/index.js
  713. /**
  714. * WordPress dependencies
  715. */
  716. /**
  717. * Internal dependencies
  718. */
  719. function AutoBlockUninstaller() {
  720. const {
  721. uninstallBlockType
  722. } = (0,external_wp_data_namespaceObject.useDispatch)(store);
  723. const shouldRemoveBlockTypes = (0,external_wp_data_namespaceObject.useSelect)(select => {
  724. const {
  725. isAutosavingPost,
  726. isSavingPost
  727. } = select(external_wp_editor_namespaceObject.store);
  728. return isSavingPost() && !isAutosavingPost();
  729. }, []);
  730. const unusedBlockTypes = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).getUnusedBlockTypes(), []);
  731. (0,external_wp_element_namespaceObject.useEffect)(() => {
  732. if (shouldRemoveBlockTypes && unusedBlockTypes.length) {
  733. unusedBlockTypes.forEach(blockType => {
  734. uninstallBlockType(blockType);
  735. (0,external_wp_blocks_namespaceObject.unregisterBlockType)(blockType.name);
  736. });
  737. }
  738. }, [shouldRemoveBlockTypes]);
  739. return null;
  740. }
  741. ;// CONCATENATED MODULE: external ["wp","components"]
  742. var external_wp_components_namespaceObject = window["wp"]["components"];
  743. ;// CONCATENATED MODULE: external ["wp","compose"]
  744. var external_wp_compose_namespaceObject = window["wp"]["compose"];
  745. ;// CONCATENATED MODULE: external ["wp","coreData"]
  746. var external_wp_coreData_namespaceObject = window["wp"]["coreData"];
  747. ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js
  748. function _extends() {
  749. _extends = Object.assign || function (target) {
  750. for (var i = 1; i < arguments.length; i++) {
  751. var source = arguments[i];
  752. for (var key in source) {
  753. if (Object.prototype.hasOwnProperty.call(source, key)) {
  754. target[key] = source[key];
  755. }
  756. }
  757. }
  758. return target;
  759. };
  760. return _extends.apply(this, arguments);
  761. }
  762. ;// CONCATENATED MODULE: external ["wp","htmlEntities"]
  763. var external_wp_htmlEntities_namespaceObject = window["wp"]["htmlEntities"];
  764. ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/icon/index.js
  765. /**
  766. * WordPress dependencies
  767. */
  768. /** @typedef {{icon: JSX.Element, size?: number} & import('@wordpress/primitives').SVGProps} IconProps */
  769. /**
  770. * Return an SVG icon.
  771. *
  772. * @param {IconProps} props icon is the SVG component to render
  773. * size is a number specifiying the icon size in pixels
  774. * Other props will be passed to wrapped SVG component
  775. *
  776. * @return {JSX.Element} Icon component
  777. */
  778. function Icon(_ref) {
  779. let {
  780. icon,
  781. size = 24,
  782. ...props
  783. } = _ref;
  784. return (0,external_wp_element_namespaceObject.cloneElement)(icon, {
  785. width: size,
  786. height: size,
  787. ...props
  788. });
  789. }
  790. /* harmony default export */ var icon = (Icon);
  791. ;// CONCATENATED MODULE: external ["wp","primitives"]
  792. var external_wp_primitives_namespaceObject = window["wp"]["primitives"];
  793. ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/star-filled.js
  794. /**
  795. * WordPress dependencies
  796. */
  797. const starFilled = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, {
  798. xmlns: "http://www.w3.org/2000/svg",
  799. viewBox: "0 0 24 24"
  800. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, {
  801. 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"
  802. }));
  803. /* harmony default export */ var star_filled = (starFilled);
  804. ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/star-half.js
  805. /**
  806. * WordPress dependencies
  807. */
  808. const starHalf = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, {
  809. xmlns: "http://www.w3.org/2000/svg",
  810. viewBox: "0 0 24 24"
  811. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, {
  812. 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"
  813. }));
  814. /* harmony default export */ var star_half = (starHalf);
  815. ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/star-empty.js
  816. /**
  817. * WordPress dependencies
  818. */
  819. const starEmpty = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, {
  820. xmlns: "http://www.w3.org/2000/svg",
  821. viewBox: "0 0 24 24"
  822. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, {
  823. fillRule: "evenodd",
  824. 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",
  825. clipRule: "evenodd"
  826. }));
  827. /* harmony default export */ var star_empty = (starEmpty);
  828. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/block-ratings/stars.js
  829. /**
  830. * External dependencies
  831. */
  832. /**
  833. * WordPress dependencies
  834. */
  835. function Stars(_ref) {
  836. let {
  837. rating
  838. } = _ref;
  839. const stars = Math.round(rating / 0.5) * 0.5;
  840. const fullStarCount = Math.floor(rating);
  841. const halfStarCount = Math.ceil(rating - fullStarCount);
  842. const emptyStarCount = 5 - (fullStarCount + halfStarCount);
  843. return (0,external_wp_element_namespaceObject.createElement)("span", {
  844. "aria-label": (0,external_wp_i18n_namespaceObject.sprintf)(
  845. /* translators: %s: number of stars. */
  846. (0,external_wp_i18n_namespaceObject.__)('%s out of 5 stars'), stars)
  847. }, (0,external_lodash_namespaceObject.times)(fullStarCount, i => (0,external_wp_element_namespaceObject.createElement)(icon, {
  848. key: `full_stars_${i}`,
  849. className: "block-directory-block-ratings__star-full",
  850. icon: star_filled,
  851. size: 16
  852. })), (0,external_lodash_namespaceObject.times)(halfStarCount, i => (0,external_wp_element_namespaceObject.createElement)(icon, {
  853. key: `half_stars_${i}`,
  854. className: "block-directory-block-ratings__star-half-full",
  855. icon: star_half,
  856. size: 16
  857. })), (0,external_lodash_namespaceObject.times)(emptyStarCount, i => (0,external_wp_element_namespaceObject.createElement)(icon, {
  858. key: `empty_stars_${i}`,
  859. className: "block-directory-block-ratings__star-empty",
  860. icon: star_empty,
  861. size: 16
  862. })));
  863. }
  864. /* harmony default export */ var stars = (Stars);
  865. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/block-ratings/index.js
  866. /**
  867. * Internal dependencies
  868. */
  869. const BlockRatings = _ref => {
  870. let {
  871. rating
  872. } = _ref;
  873. return (0,external_wp_element_namespaceObject.createElement)("span", {
  874. className: "block-directory-block-ratings"
  875. }, (0,external_wp_element_namespaceObject.createElement)(stars, {
  876. rating: rating
  877. }));
  878. };
  879. /* harmony default export */ var block_ratings = (BlockRatings);
  880. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/downloadable-block-icon/index.js
  881. /**
  882. * WordPress dependencies
  883. */
  884. function DownloadableBlockIcon(_ref) {
  885. let {
  886. icon
  887. } = _ref;
  888. const className = 'block-directory-downloadable-block-icon';
  889. return icon.match(/\.(jpeg|jpg|gif|png|svg)(?:\?.*)?$/) !== null ? (0,external_wp_element_namespaceObject.createElement)("img", {
  890. className: className,
  891. src: icon,
  892. alt: ""
  893. }) : (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.BlockIcon, {
  894. className: className,
  895. icon: icon,
  896. showColors: true
  897. });
  898. }
  899. /* harmony default export */ var downloadable_block_icon = (DownloadableBlockIcon);
  900. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/downloadable-block-notice/index.js
  901. /**
  902. * WordPress dependencies
  903. */
  904. /**
  905. * Internal dependencies
  906. */
  907. const DownloadableBlockNotice = _ref => {
  908. let {
  909. block
  910. } = _ref;
  911. const errorNotice = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).getErrorNoticeForBlock(block.id), [block]);
  912. if (!errorNotice) {
  913. return null;
  914. }
  915. return (0,external_wp_element_namespaceObject.createElement)("div", {
  916. className: "block-directory-downloadable-block-notice"
  917. }, (0,external_wp_element_namespaceObject.createElement)("div", {
  918. className: "block-directory-downloadable-block-notice__content"
  919. }, errorNotice.message, errorNotice.isFatal ? ' ' + (0,external_wp_i18n_namespaceObject.__)('Try reloading the page.') : null));
  920. };
  921. /* harmony default export */ var downloadable_block_notice = (DownloadableBlockNotice);
  922. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/downloadable-block-list-item/index.js
  923. /**
  924. * WordPress dependencies
  925. */
  926. /**
  927. * Internal dependencies
  928. */
  929. // Return the appropriate block item label, given the block data and status.
  930. function getDownloadableBlockLabel(_ref, _ref2) {
  931. let {
  932. title,
  933. rating,
  934. ratingCount
  935. } = _ref;
  936. let {
  937. hasNotice,
  938. isInstalled,
  939. isInstalling
  940. } = _ref2;
  941. const stars = Math.round(rating / 0.5) * 0.5;
  942. if (!isInstalled && hasNotice) {
  943. /* translators: %1$s: block title */
  944. return (0,external_wp_i18n_namespaceObject.sprintf)('Retry installing %s.', (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title));
  945. }
  946. if (isInstalled) {
  947. /* translators: %1$s: block title */
  948. return (0,external_wp_i18n_namespaceObject.sprintf)('Add %s.', (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title));
  949. }
  950. if (isInstalling) {
  951. /* translators: %1$s: block title */
  952. return (0,external_wp_i18n_namespaceObject.sprintf)('Installing %s.', (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title));
  953. } // No ratings yet, just use the title.
  954. if (ratingCount < 1) {
  955. /* translators: %1$s: block title */
  956. return (0,external_wp_i18n_namespaceObject.sprintf)('Install %s.', (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title));
  957. }
  958. return (0,external_wp_i18n_namespaceObject.sprintf)(
  959. /* translators: %1$s: block title, %2$s: average rating, %3$s: total ratings count. */
  960. (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);
  961. }
  962. function DownloadableBlockListItem(_ref3) {
  963. let {
  964. composite,
  965. item,
  966. onClick
  967. } = _ref3;
  968. const {
  969. author,
  970. description,
  971. icon,
  972. rating,
  973. title
  974. } = item; // getBlockType returns a block object if this block exists, or null if not.
  975. const isInstalled = !!(0,external_wp_blocks_namespaceObject.getBlockType)(item.name);
  976. const {
  977. hasNotice,
  978. isInstalling,
  979. isInstallable
  980. } = (0,external_wp_data_namespaceObject.useSelect)(select => {
  981. const {
  982. getErrorNoticeForBlock,
  983. isInstalling: isBlockInstalling
  984. } = select(store);
  985. const notice = getErrorNoticeForBlock(item.id);
  986. const hasFatal = notice && notice.isFatal;
  987. return {
  988. hasNotice: !!notice,
  989. isInstalling: isBlockInstalling(item.id),
  990. isInstallable: !hasFatal
  991. };
  992. }, [item]);
  993. let statusText = '';
  994. if (isInstalled) {
  995. statusText = (0,external_wp_i18n_namespaceObject.__)('Installed!');
  996. } else if (isInstalling) {
  997. statusText = (0,external_wp_i18n_namespaceObject.__)('Installing…');
  998. }
  999. return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.__unstableCompositeItem, _extends({
  1000. __experimentalIsFocusable: true,
  1001. role: "option",
  1002. as: external_wp_components_namespaceObject.Button
  1003. }, composite, {
  1004. className: "block-directory-downloadable-block-list-item",
  1005. onClick: event => {
  1006. event.preventDefault();
  1007. onClick();
  1008. },
  1009. isBusy: isInstalling,
  1010. disabled: isInstalling || !isInstallable,
  1011. label: getDownloadableBlockLabel(item, {
  1012. hasNotice,
  1013. isInstalled,
  1014. isInstalling
  1015. }),
  1016. showTooltip: true,
  1017. tooltipPosition: "top center"
  1018. }), (0,external_wp_element_namespaceObject.createElement)("div", {
  1019. className: "block-directory-downloadable-block-list-item__icon"
  1020. }, (0,external_wp_element_namespaceObject.createElement)(downloadable_block_icon, {
  1021. icon: icon,
  1022. title: title
  1023. }), isInstalling ? (0,external_wp_element_namespaceObject.createElement)("span", {
  1024. className: "block-directory-downloadable-block-list-item__spinner"
  1025. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Spinner, null)) : (0,external_wp_element_namespaceObject.createElement)(block_ratings, {
  1026. rating: rating
  1027. })), (0,external_wp_element_namespaceObject.createElement)("span", {
  1028. className: "block-directory-downloadable-block-list-item__details"
  1029. }, (0,external_wp_element_namespaceObject.createElement)("span", {
  1030. className: "block-directory-downloadable-block-list-item__title"
  1031. }, (0,external_wp_element_namespaceObject.createInterpolateElement)((0,external_wp_i18n_namespaceObject.sprintf)(
  1032. /* translators: %1$s: block title, %2$s: author name. */
  1033. (0,external_wp_i18n_namespaceObject.__)('%1$s <span>by %2$s</span>'), (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title), author), {
  1034. span: (0,external_wp_element_namespaceObject.createElement)("span", {
  1035. className: "block-directory-downloadable-block-list-item__author"
  1036. })
  1037. })), hasNotice ? (0,external_wp_element_namespaceObject.createElement)(downloadable_block_notice, {
  1038. block: item
  1039. }) : (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)("span", {
  1040. className: "block-directory-downloadable-block-list-item__desc"
  1041. }, !!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')))));
  1042. }
  1043. /* harmony default export */ var downloadable_block_list_item = (DownloadableBlockListItem);
  1044. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/downloadable-blocks-list/index.js
  1045. /**
  1046. * External dependencies
  1047. */
  1048. /**
  1049. * WordPress dependencies
  1050. */
  1051. /**
  1052. * Internal dependencies
  1053. */
  1054. function DownloadableBlocksList(_ref) {
  1055. let {
  1056. items,
  1057. onHover = external_lodash_namespaceObject.noop,
  1058. onSelect
  1059. } = _ref;
  1060. const composite = (0,external_wp_components_namespaceObject.__unstableUseCompositeState)();
  1061. const {
  1062. installBlockType
  1063. } = (0,external_wp_data_namespaceObject.useDispatch)(store);
  1064. if (!items.length) {
  1065. return null;
  1066. }
  1067. return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.__unstableComposite, _extends({}, composite, {
  1068. role: "listbox",
  1069. className: "block-directory-downloadable-blocks-list",
  1070. "aria-label": (0,external_wp_i18n_namespaceObject.__)('Blocks available for install')
  1071. }), items.map(item => {
  1072. return (0,external_wp_element_namespaceObject.createElement)(downloadable_block_list_item, {
  1073. key: item.id,
  1074. composite: composite,
  1075. onClick: () => {
  1076. // Check if the block is registered (`getBlockType`
  1077. // will return an object). If so, insert the block.
  1078. // This prevents installing existing plugins.
  1079. if ((0,external_wp_blocks_namespaceObject.getBlockType)(item.name)) {
  1080. onSelect(item);
  1081. } else {
  1082. installBlockType(item).then(success => {
  1083. if (success) {
  1084. onSelect(item);
  1085. }
  1086. });
  1087. }
  1088. onHover(null);
  1089. },
  1090. onHover: onHover,
  1091. item: item
  1092. });
  1093. }));
  1094. }
  1095. /* harmony default export */ var downloadable_blocks_list = (DownloadableBlocksList);
  1096. ;// CONCATENATED MODULE: external ["wp","a11y"]
  1097. var external_wp_a11y_namespaceObject = window["wp"]["a11y"];
  1098. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/downloadable-blocks-panel/inserter-panel.js
  1099. /**
  1100. * WordPress dependencies
  1101. */
  1102. function DownloadableBlocksInserterPanel(_ref) {
  1103. let {
  1104. children,
  1105. downloadableItems,
  1106. hasLocalBlocks
  1107. } = _ref;
  1108. const count = downloadableItems.length;
  1109. (0,external_wp_element_namespaceObject.useEffect)(() => {
  1110. (0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.sprintf)(
  1111. /* translators: %d: number of available blocks. */
  1112. (0,external_wp_i18n_namespaceObject._n)('%d additional block is available to install.', '%d additional blocks are available to install.', count), count));
  1113. }, [count]);
  1114. return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, !hasLocalBlocks && (0,external_wp_element_namespaceObject.createElement)("p", {
  1115. className: "block-directory-downloadable-blocks-panel__no-local"
  1116. }, (0,external_wp_i18n_namespaceObject.__)('No results available from your installed blocks.')), (0,external_wp_element_namespaceObject.createElement)("div", {
  1117. className: "block-editor-inserter__quick-inserter-separator"
  1118. }), (0,external_wp_element_namespaceObject.createElement)("div", {
  1119. className: "block-directory-downloadable-blocks-panel"
  1120. }, (0,external_wp_element_namespaceObject.createElement)("div", {
  1121. className: "block-directory-downloadable-blocks-panel__header"
  1122. }, (0,external_wp_element_namespaceObject.createElement)("h2", {
  1123. className: "block-directory-downloadable-blocks-panel__title"
  1124. }, (0,external_wp_i18n_namespaceObject.__)('Available to install')), (0,external_wp_element_namespaceObject.createElement)("p", {
  1125. className: "block-directory-downloadable-blocks-panel__description"
  1126. }, (0,external_wp_i18n_namespaceObject.__)('Select a block to install and add it to your post.'))), children));
  1127. }
  1128. /* harmony default export */ var inserter_panel = (DownloadableBlocksInserterPanel);
  1129. ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/block-default.js
  1130. /**
  1131. * WordPress dependencies
  1132. */
  1133. const blockDefault = (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: "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"
  1138. }));
  1139. /* harmony default export */ var block_default = (blockDefault);
  1140. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/downloadable-blocks-panel/no-results.js
  1141. /**
  1142. * WordPress dependencies
  1143. */
  1144. function DownloadableBlocksNoResults() {
  1145. return (0,external_wp_element_namespaceObject.createElement)("div", {
  1146. className: "block-editor-inserter__no-results"
  1147. }, (0,external_wp_element_namespaceObject.createElement)(icon, {
  1148. className: "block-editor-inserter__no-results-icon",
  1149. icon: block_default
  1150. }), (0,external_wp_element_namespaceObject.createElement)("p", null, (0,external_wp_i18n_namespaceObject.__)('No results found.')));
  1151. }
  1152. /* harmony default export */ var no_results = (DownloadableBlocksNoResults);
  1153. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/downloadable-blocks-panel/index.js
  1154. /**
  1155. * WordPress dependencies
  1156. */
  1157. /**
  1158. * Internal dependencies
  1159. */
  1160. function DownloadableBlocksPanel(_ref) {
  1161. let {
  1162. downloadableItems,
  1163. onSelect,
  1164. onHover,
  1165. hasLocalBlocks,
  1166. hasPermission,
  1167. isLoading,
  1168. isTyping
  1169. } = _ref;
  1170. if (typeof hasPermission === 'undefined' || isLoading || isTyping) {
  1171. 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", {
  1172. className: "block-directory-downloadable-blocks-panel__no-local"
  1173. }, (0,external_wp_i18n_namespaceObject.__)('No results available from your installed blocks.')), (0,external_wp_element_namespaceObject.createElement)("div", {
  1174. className: "block-editor-inserter__quick-inserter-separator"
  1175. })), (0,external_wp_element_namespaceObject.createElement)("div", {
  1176. className: "block-directory-downloadable-blocks-panel has-blocks-loading"
  1177. }, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Spinner, null)));
  1178. }
  1179. if (false === hasPermission) {
  1180. if (!hasLocalBlocks) {
  1181. return (0,external_wp_element_namespaceObject.createElement)(no_results, null);
  1182. }
  1183. return null;
  1184. }
  1185. return !!downloadableItems.length ? (0,external_wp_element_namespaceObject.createElement)(inserter_panel, {
  1186. downloadableItems: downloadableItems,
  1187. hasLocalBlocks: hasLocalBlocks
  1188. }, (0,external_wp_element_namespaceObject.createElement)(downloadable_blocks_list, {
  1189. items: downloadableItems,
  1190. onSelect: onSelect,
  1191. onHover: onHover
  1192. })) : !hasLocalBlocks && (0,external_wp_element_namespaceObject.createElement)(no_results, null);
  1193. }
  1194. /* harmony default export */ var downloadable_blocks_panel = ((0,external_wp_compose_namespaceObject.compose)([(0,external_wp_data_namespaceObject.withSelect)((select, _ref2) => {
  1195. let {
  1196. filterValue,
  1197. rootClientId = null
  1198. } = _ref2;
  1199. const {
  1200. getDownloadableBlocks,
  1201. isRequestingDownloadableBlocks
  1202. } = select(store);
  1203. const {
  1204. canInsertBlockType
  1205. } = select(external_wp_blockEditor_namespaceObject.store);
  1206. const hasPermission = select(external_wp_coreData_namespaceObject.store).canUser('read', 'block-directory/search');
  1207. function getInstallableBlocks(term) {
  1208. return getDownloadableBlocks(term).filter(block => canInsertBlockType(block, rootClientId, true));
  1209. }
  1210. const downloadableItems = hasPermission ? getInstallableBlocks(filterValue) : [];
  1211. const isLoading = isRequestingDownloadableBlocks(filterValue);
  1212. return {
  1213. downloadableItems,
  1214. hasPermission,
  1215. isLoading
  1216. };
  1217. })])(DownloadableBlocksPanel));
  1218. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.js
  1219. /**
  1220. * External dependencies
  1221. */
  1222. /**
  1223. * WordPress dependencies
  1224. */
  1225. /**
  1226. * Internal dependencies
  1227. */
  1228. function InserterMenuDownloadableBlocksPanel() {
  1229. const [debouncedFilterValue, setFilterValue] = (0,external_wp_element_namespaceObject.useState)('');
  1230. const debouncedSetFilterValue = (0,external_lodash_namespaceObject.debounce)(setFilterValue, 400);
  1231. return (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.__unstableInserterMenuExtension, null, _ref => {
  1232. let {
  1233. onSelect,
  1234. onHover,
  1235. filterValue,
  1236. hasItems,
  1237. rootClientId
  1238. } = _ref;
  1239. if (debouncedFilterValue !== filterValue) {
  1240. debouncedSetFilterValue(filterValue);
  1241. }
  1242. if (!debouncedFilterValue) {
  1243. return null;
  1244. }
  1245. return (0,external_wp_element_namespaceObject.createElement)(downloadable_blocks_panel, {
  1246. onSelect: onSelect,
  1247. onHover: onHover,
  1248. rootClientId: rootClientId,
  1249. filterValue: debouncedFilterValue,
  1250. hasLocalBlocks: hasItems,
  1251. isTyping: filterValue !== debouncedFilterValue
  1252. });
  1253. });
  1254. }
  1255. /* harmony default export */ var inserter_menu_downloadable_blocks_panel = (InserterMenuDownloadableBlocksPanel);
  1256. ;// CONCATENATED MODULE: external ["wp","editPost"]
  1257. var external_wp_editPost_namespaceObject = window["wp"]["editPost"];
  1258. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/components/compact-list/index.js
  1259. /**
  1260. * WordPress dependencies
  1261. */
  1262. /**
  1263. * Internal dependencies
  1264. */
  1265. function CompactList(_ref) {
  1266. let {
  1267. items
  1268. } = _ref;
  1269. if (!items.length) {
  1270. return null;
  1271. }
  1272. return (0,external_wp_element_namespaceObject.createElement)("ul", {
  1273. className: "block-directory-compact-list"
  1274. }, items.map(_ref2 => {
  1275. let {
  1276. icon,
  1277. id,
  1278. title,
  1279. author
  1280. } = _ref2;
  1281. return (0,external_wp_element_namespaceObject.createElement)("li", {
  1282. key: id,
  1283. className: "block-directory-compact-list__item"
  1284. }, (0,external_wp_element_namespaceObject.createElement)(downloadable_block_icon, {
  1285. icon: icon,
  1286. title: title
  1287. }), (0,external_wp_element_namespaceObject.createElement)("div", {
  1288. className: "block-directory-compact-list__item-details"
  1289. }, (0,external_wp_element_namespaceObject.createElement)("div", {
  1290. className: "block-directory-compact-list__item-title"
  1291. }, title), (0,external_wp_element_namespaceObject.createElement)("div", {
  1292. className: "block-directory-compact-list__item-author"
  1293. }, (0,external_wp_i18n_namespaceObject.sprintf)(
  1294. /* translators: %s: Name of the block author. */
  1295. (0,external_wp_i18n_namespaceObject.__)('By %s'), author))));
  1296. }));
  1297. }
  1298. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/plugins/installed-blocks-pre-publish-panel/index.js
  1299. /**
  1300. * WordPress dependencies
  1301. */
  1302. /**
  1303. * Internal dependencies
  1304. */
  1305. function InstalledBlocksPrePublishPanel() {
  1306. const newBlockTypes = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).getNewBlockTypes(), []);
  1307. if (!newBlockTypes.length) {
  1308. return null;
  1309. }
  1310. return (0,external_wp_element_namespaceObject.createElement)(external_wp_editPost_namespaceObject.PluginPrePublishPanel, {
  1311. icon: block_default,
  1312. title: (0,external_wp_i18n_namespaceObject.sprintf)( // translators: %d: number of blocks (number).
  1313. (0,external_wp_i18n_namespaceObject._n)('Added: %d block', 'Added: %d blocks', newBlockTypes.length), newBlockTypes.length),
  1314. initialOpen: true
  1315. }, (0,external_wp_element_namespaceObject.createElement)("p", {
  1316. className: "installed-blocks-pre-publish-panel__copy"
  1317. }, (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, {
  1318. items: newBlockTypes
  1319. }));
  1320. }
  1321. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/plugins/get-install-missing/install-button.js
  1322. /**
  1323. * WordPress dependencies
  1324. */
  1325. /**
  1326. * Internal dependencies
  1327. */
  1328. function InstallButton(_ref) {
  1329. let {
  1330. attributes,
  1331. block,
  1332. clientId
  1333. } = _ref;
  1334. const isInstallingBlock = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).isInstalling(block.id), [block.id]);
  1335. const {
  1336. installBlockType
  1337. } = (0,external_wp_data_namespaceObject.useDispatch)(store);
  1338. const {
  1339. replaceBlock
  1340. } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
  1341. return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, {
  1342. onClick: () => installBlockType(block).then(success => {
  1343. if (success) {
  1344. const blockType = (0,external_wp_blocks_namespaceObject.getBlockType)(block.name);
  1345. const [originalBlock] = (0,external_wp_blocks_namespaceObject.parse)(attributes.originalContent);
  1346. if (originalBlock && blockType) {
  1347. replaceBlock(clientId, (0,external_wp_blocks_namespaceObject.createBlock)(blockType.name, originalBlock.attributes, originalBlock.innerBlocks));
  1348. }
  1349. }
  1350. }),
  1351. disabled: isInstallingBlock,
  1352. isBusy: isInstallingBlock,
  1353. variant: "primary"
  1354. }, (0,external_wp_i18n_namespaceObject.sprintf)(
  1355. /* translators: %s: block name */
  1356. (0,external_wp_i18n_namespaceObject.__)('Install %s'), block.title));
  1357. }
  1358. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/plugins/get-install-missing/index.js
  1359. /**
  1360. * WordPress dependencies
  1361. */
  1362. /**
  1363. * Internal dependencies
  1364. */
  1365. const getInstallMissing = OriginalComponent => props => {
  1366. const {
  1367. originalName
  1368. } = props.attributes; // Disable reason: This is a valid component, but it's mistaken for a callback.
  1369. // eslint-disable-next-line react-hooks/rules-of-hooks
  1370. const {
  1371. block,
  1372. hasPermission
  1373. } = (0,external_wp_data_namespaceObject.useSelect)(select => {
  1374. const {
  1375. getDownloadableBlocks
  1376. } = select(store);
  1377. const blocks = getDownloadableBlocks('block:' + originalName).filter(_ref => {
  1378. let {
  1379. name
  1380. } = _ref;
  1381. return originalName === name;
  1382. });
  1383. return {
  1384. hasPermission: select(external_wp_coreData_namespaceObject.store).canUser('read', 'block-directory/search'),
  1385. block: blocks.length && blocks[0]
  1386. };
  1387. }, [originalName]); // The user can't install blocks, or the block isn't available for download.
  1388. if (!hasPermission || !block) {
  1389. return (0,external_wp_element_namespaceObject.createElement)(OriginalComponent, props);
  1390. }
  1391. return (0,external_wp_element_namespaceObject.createElement)(ModifiedWarning, _extends({}, props, {
  1392. originalBlock: block
  1393. }));
  1394. };
  1395. const ModifiedWarning = _ref2 => {
  1396. let {
  1397. originalBlock,
  1398. ...props
  1399. } = _ref2;
  1400. const {
  1401. originalName,
  1402. originalUndelimitedContent
  1403. } = props.attributes;
  1404. const {
  1405. replaceBlock
  1406. } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
  1407. const convertToHTML = () => {
  1408. replaceBlock(props.clientId, (0,external_wp_blocks_namespaceObject.createBlock)('core/html', {
  1409. content: originalUndelimitedContent
  1410. }));
  1411. };
  1412. const hasContent = !!originalUndelimitedContent;
  1413. const hasHTMLBlock = (0,external_wp_blocks_namespaceObject.getBlockType)('core/html');
  1414. let messageHTML = (0,external_wp_i18n_namespaceObject.sprintf)(
  1415. /* translators: %s: block name */
  1416. (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);
  1417. const actions = [(0,external_wp_element_namespaceObject.createElement)(InstallButton, {
  1418. key: "install",
  1419. block: originalBlock,
  1420. attributes: props.attributes,
  1421. clientId: props.clientId
  1422. })];
  1423. if (hasContent && hasHTMLBlock) {
  1424. messageHTML = (0,external_wp_i18n_namespaceObject.sprintf)(
  1425. /* translators: %s: block name */
  1426. (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);
  1427. actions.push((0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, {
  1428. key: "convert",
  1429. onClick: convertToHTML,
  1430. variant: "link"
  1431. }, (0,external_wp_i18n_namespaceObject.__)('Keep as HTML')));
  1432. }
  1433. 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, {
  1434. actions: actions
  1435. }, messageHTML), (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.RawHTML, null, originalUndelimitedContent));
  1436. };
  1437. /* harmony default export */ var get_install_missing = (getInstallMissing);
  1438. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/plugins/index.js
  1439. /**
  1440. * WordPress dependencies
  1441. */
  1442. /**
  1443. * Internal dependencies
  1444. */
  1445. (0,external_wp_plugins_namespaceObject.registerPlugin)('block-directory', {
  1446. render() {
  1447. 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));
  1448. }
  1449. });
  1450. (0,external_wp_hooks_namespaceObject.addFilter)('blocks.registerBlockType', 'block-directory/fallback', (settings, name) => {
  1451. if (name !== 'core/missing') {
  1452. return settings;
  1453. }
  1454. settings.edit = get_install_missing(settings.edit);
  1455. return settings;
  1456. });
  1457. ;// CONCATENATED MODULE: ./node_modules/@wordpress/block-directory/build-module/index.js
  1458. /**
  1459. * Internal dependencies
  1460. */
  1461. (window.wp = window.wp || {}).blockDirectory = __webpack_exports__;
  1462. /******/ })()
  1463. ;