PluginProbe
Gutenberg / 18.9.0
Gutenberg v18.9.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / build / block-directory / index.js

index.js in Gutenberg 18.9.0, at build/block-directory/index.js

2,255 lines 78.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (() => { // webpackBootstrap
2 /******/ "use strict";
3 /******/ // The require scope
4 /******/ var __webpack_require__ = {};
5 /******/
6 /************************************************************************/
7 /******/ /* webpack/runtime/compat get default export */
8 /******/ (() => {
9 /******/ // getDefaultExport function for compatibility with non-harmony modules
10 /******/ __webpack_require__.n = (module) => {
11 /******/ var getter = module && module.__esModule ?
12 /******/ () => (module['default']) :
13 /******/ () => (module);
14 /******/ __webpack_require__.d(getter, { a: getter });
15 /******/ return getter;
16 /******/ };
17 /******/ })();
18 /******/
19 /******/ /* webpack/runtime/define property getters */
20 /******/ (() => {
21 /******/ // define getter functions for harmony exports
22 /******/ __webpack_require__.d = (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 /******/ (() => {
33 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
34 /******/ })();
35 /******/
36 /******/ /* webpack/runtime/make namespace object */
37 /******/ (() => {
38 /******/ // define __esModule on exports
39 /******/ __webpack_require__.r = (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
52 // EXPORTS
53 __webpack_require__.d(__webpack_exports__, {
54 store: () => (/* reexport */ store)
55 });
56
57 // NAMESPACE OBJECT: ./packages/block-directory/build-module/store/selectors.js
58 var selectors_namespaceObject = {};
59 __webpack_require__.r(selectors_namespaceObject);
60 __webpack_require__.d(selectors_namespaceObject, {
61 getDownloadableBlocks: () => (getDownloadableBlocks),
62 getErrorNoticeForBlock: () => (getErrorNoticeForBlock),
63 getErrorNotices: () => (getErrorNotices),
64 getInstalledBlockTypes: () => (getInstalledBlockTypes),
65 getNewBlockTypes: () => (getNewBlockTypes),
66 getUnusedBlockTypes: () => (getUnusedBlockTypes),
67 isInstalling: () => (isInstalling),
68 isRequestingDownloadableBlocks: () => (isRequestingDownloadableBlocks)
69 });
70
71 // NAMESPACE OBJECT: ./packages/block-directory/build-module/store/actions.js
72 var actions_namespaceObject = {};
73 __webpack_require__.r(actions_namespaceObject);
74 __webpack_require__.d(actions_namespaceObject, {
75 addInstalledBlockType: () => (addInstalledBlockType),
76 clearErrorNotice: () => (clearErrorNotice),
77 fetchDownloadableBlocks: () => (fetchDownloadableBlocks),
78 installBlockType: () => (installBlockType),
79 receiveDownloadableBlocks: () => (receiveDownloadableBlocks),
80 removeInstalledBlockType: () => (removeInstalledBlockType),
81 setErrorNotice: () => (setErrorNotice),
82 setIsInstalling: () => (setIsInstalling),
83 uninstallBlockType: () => (uninstallBlockType)
84 });
85
86 // NAMESPACE OBJECT: ./packages/block-directory/build-module/store/resolvers.js
87 var resolvers_namespaceObject = {};
88 __webpack_require__.r(resolvers_namespaceObject);
89 __webpack_require__.d(resolvers_namespaceObject, {
90 getDownloadableBlocks: () => (resolvers_getDownloadableBlocks)
91 });
92
93 ;// CONCATENATED MODULE: external ["wp","plugins"]
94 const external_wp_plugins_namespaceObject = window["wp"]["plugins"];
95 ;// CONCATENATED MODULE: external ["wp","hooks"]
96 const external_wp_hooks_namespaceObject = window["wp"]["hooks"];
97 ;// CONCATENATED MODULE: external ["wp","blocks"]
98 const external_wp_blocks_namespaceObject = window["wp"]["blocks"];
99 ;// CONCATENATED MODULE: external ["wp","data"]
100 const external_wp_data_namespaceObject = window["wp"]["data"];
101 ;// CONCATENATED MODULE: external ["wp","element"]
102 const external_wp_element_namespaceObject = window["wp"]["element"];
103 ;// CONCATENATED MODULE: external ["wp","editor"]
104 const external_wp_editor_namespaceObject = window["wp"]["editor"];
105 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/store/reducer.js
106 /**
107 * WordPress dependencies
108 */
109
110
111 /**
112 * Reducer returning an array of downloadable blocks.
113 *
114 * @param {Object} state Current state.
115 * @param {Object} action Dispatched action.
116 *
117 * @return {Object} Updated state.
118 */
119 const downloadableBlocks = (state = {}, action) => {
120 switch (action.type) {
121 case 'FETCH_DOWNLOADABLE_BLOCKS':
122 return {
123 ...state,
124 [action.filterValue]: {
125 isRequesting: true
126 }
127 };
128 case 'RECEIVE_DOWNLOADABLE_BLOCKS':
129 return {
130 ...state,
131 [action.filterValue]: {
132 results: action.downloadableBlocks,
133 isRequesting: false
134 }
135 };
136 }
137 return state;
138 };
139
140 /**
141 * Reducer managing the installation and deletion of blocks.
142 *
143 * @param {Object} state Current state.
144 * @param {Object} action Dispatched action.
145 *
146 * @return {Object} Updated state.
147 */
148 const blockManagement = (state = {
149 installedBlockTypes: [],
150 isInstalling: {}
151 }, action) => {
152 switch (action.type) {
153 case 'ADD_INSTALLED_BLOCK_TYPE':
154 return {
155 ...state,
156 installedBlockTypes: [...state.installedBlockTypes, action.item]
157 };
158 case 'REMOVE_INSTALLED_BLOCK_TYPE':
159 return {
160 ...state,
161 installedBlockTypes: state.installedBlockTypes.filter(blockType => blockType.name !== action.item.name)
162 };
163 case 'SET_INSTALLING_BLOCK':
164 return {
165 ...state,
166 isInstalling: {
167 ...state.isInstalling,
168 [action.blockId]: action.isInstalling
169 }
170 };
171 }
172 return state;
173 };
174
175 /**
176 * Reducer returning an object of error notices.
177 *
178 * @param {Object} state Current state.
179 * @param {Object} action Dispatched action.
180 *
181 * @return {Object} Updated state.
182 */
183 const errorNotices = (state = {}, action) => {
184 switch (action.type) {
185 case 'SET_ERROR_NOTICE':
186 return {
187 ...state,
188 [action.blockId]: {
189 message: action.message,
190 isFatal: action.isFatal
191 }
192 };
193 case 'CLEAR_ERROR_NOTICE':
194 const {
195 [action.blockId]: blockId,
196 ...restState
197 } = state;
198 return restState;
199 }
200 return state;
201 };
202 /* harmony default export */ const reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
203 downloadableBlocks,
204 blockManagement,
205 errorNotices
206 }));
207
208 ;// CONCATENATED MODULE: external ["wp","blockEditor"]
209 const external_wp_blockEditor_namespaceObject = window["wp"]["blockEditor"];
210 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/store/utils/has-block-type.js
211 /**
212 * Check if a block list contains a specific block type. Recursively searches
213 * through `innerBlocks` if they exist.
214 *
215 * @param {Object} blockType A block object to search for.
216 * @param {Object[]} blocks The list of blocks to look through.
217 *
218 * @return {boolean} Whether the blockType is found.
219 */
220 function hasBlockType(blockType, blocks = []) {
221 if (!blocks.length) {
222 return false;
223 }
224 if (blocks.some(({
225 name
226 }) => name === blockType.name)) {
227 return true;
228 }
229 for (let i = 0; i < blocks.length; i++) {
230 if (hasBlockType(blockType, blocks[i].innerBlocks)) {
231 return true;
232 }
233 }
234 return false;
235 }
236
237 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/store/selectors.js
238 /**
239 * WordPress dependencies
240 */
241
242
243
244 /**
245 * Internal dependencies
246 */
247
248
249 /**
250 * Returns true if application is requesting for downloadable blocks.
251 *
252 * @param {Object} state Global application state.
253 * @param {string} filterValue Search string.
254 *
255 * @return {boolean} Whether a request is in progress for the blocks list.
256 */
257 function isRequestingDownloadableBlocks(state, filterValue) {
258 var _state$downloadableBl;
259 return (_state$downloadableBl = state.downloadableBlocks[filterValue]?.isRequesting) !== null && _state$downloadableBl !== void 0 ? _state$downloadableBl : false;
260 }
261
262 /**
263 * Returns the available uninstalled blocks.
264 *
265 * @param {Object} state Global application state.
266 * @param {string} filterValue Search string.
267 *
268 * @return {Array} Downloadable blocks.
269 */
270 function getDownloadableBlocks(state, filterValue) {
271 var _state$downloadableBl2;
272 return (_state$downloadableBl2 = state.downloadableBlocks[filterValue]?.results) !== null && _state$downloadableBl2 !== void 0 ? _state$downloadableBl2 : [];
273 }
274
275 /**
276 * Returns the block types that have been installed on the server in this
277 * session.
278 *
279 * @param {Object} state Global application state.
280 *
281 * @return {Array} Block type items
282 */
283 function getInstalledBlockTypes(state) {
284 return state.blockManagement.installedBlockTypes;
285 }
286
287 /**
288 * Returns block types that have been installed on the server and used in the
289 * current post.
290 *
291 * @param {Object} state Global application state.
292 *
293 * @return {Array} Block type items.
294 */
295 const getNewBlockTypes = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => (0,external_wp_data_namespaceObject.createSelector)(state => {
296 const usedBlockTree = select(external_wp_blockEditor_namespaceObject.store).getBlocks();
297 const installedBlockTypes = getInstalledBlockTypes(state);
298 return installedBlockTypes.filter(blockType => hasBlockType(blockType, usedBlockTree));
299 }, state => [getInstalledBlockTypes(state), select(external_wp_blockEditor_namespaceObject.store).getBlocks()]));
300
301 /**
302 * Returns the block types that have been installed on the server but are not
303 * used in the current post.
304 *
305 * @param {Object} state Global application state.
306 *
307 * @return {Array} Block type items.
308 */
309 const getUnusedBlockTypes = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => (0,external_wp_data_namespaceObject.createSelector)(state => {
310 const usedBlockTree = select(external_wp_blockEditor_namespaceObject.store).getBlocks();
311 const installedBlockTypes = getInstalledBlockTypes(state);
312 return installedBlockTypes.filter(blockType => !hasBlockType(blockType, usedBlockTree));
313 }, state => [getInstalledBlockTypes(state), select(external_wp_blockEditor_namespaceObject.store).getBlocks()]));
314
315 /**
316 * Returns true if a block plugin install is in progress.
317 *
318 * @param {Object} state Global application state.
319 * @param {string} blockId Id of the block.
320 *
321 * @return {boolean} Whether this block is currently being installed.
322 */
323 function isInstalling(state, blockId) {
324 return state.blockManagement.isInstalling[blockId] || false;
325 }
326
327 /**
328 * Returns all block error notices.
329 *
330 * @param {Object} state Global application state.
331 *
332 * @return {Object} Object with error notices.
333 */
334 function getErrorNotices(state) {
335 return state.errorNotices;
336 }
337
338 /**
339 * Returns the error notice for a given block.
340 *
341 * @param {Object} state Global application state.
342 * @param {string} blockId The ID of the block plugin. eg: my-block
343 *
344 * @return {string|boolean} The error text, or false if no error.
345 */
346 function getErrorNoticeForBlock(state, blockId) {
347 return state.errorNotices[blockId];
348 }
349
350 ;// CONCATENATED MODULE: external ["wp","i18n"]
351 const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
352 ;// CONCATENATED MODULE: external ["wp","apiFetch"]
353 const external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"];
354 var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject);
355 ;// CONCATENATED MODULE: external ["wp","notices"]
356 const external_wp_notices_namespaceObject = window["wp"]["notices"];
357 ;// CONCATENATED MODULE: external ["wp","url"]
358 const external_wp_url_namespaceObject = window["wp"]["url"];
359 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/store/load-assets.js
360 /**
361 * WordPress dependencies
362 */
363
364
365 /**
366 * Load an asset for a block.
367 *
368 * This function returns a Promise that will resolve once the asset is loaded,
369 * or in the case of Stylesheets and Inline JavaScript, will resolve immediately.
370 *
371 * @param {HTMLElement} el A HTML Element asset to inject.
372 *
373 * @return {Promise} Promise which will resolve when the asset is loaded.
374 */
375 const loadAsset = el => {
376 return new Promise((resolve, reject) => {
377 /*
378 * Reconstruct the passed element, this is required as inserting the Node directly
379 * won't always fire the required onload events, even if the asset wasn't already loaded.
380 */
381 const newNode = document.createElement(el.nodeName);
382 ['id', 'rel', 'src', 'href', 'type'].forEach(attr => {
383 if (el[attr]) {
384 newNode[attr] = el[attr];
385 }
386 });
387
388 // Append inline <script> contents.
389 if (el.innerHTML) {
390 newNode.appendChild(document.createTextNode(el.innerHTML));
391 }
392 newNode.onload = () => resolve(true);
393 newNode.onerror = () => reject(new Error('Error loading asset.'));
394 document.body.appendChild(newNode);
395
396 // Resolve Stylesheets and Inline JavaScript immediately.
397 if ('link' === newNode.nodeName.toLowerCase() || 'script' === newNode.nodeName.toLowerCase() && !newNode.src) {
398 resolve();
399 }
400 });
401 };
402
403 /**
404 * Load the asset files for a block
405 */
406 async function loadAssets() {
407 /*
408 * Fetch the current URL (post-new.php, or post.php?post=1&action=edit) and compare the
409 * JavaScript and CSS assets loaded between the pages. This imports the required assets
410 * for the block into the current page while not requiring that we know them up-front.
411 * In the future this can be improved by reliance upon block.json and/or a script-loader
412 * dependency API.
413 */
414 const response = await external_wp_apiFetch_default()({
415 url: document.location.href,
416 parse: false
417 });
418 const data = await response.text();
419 const doc = new window.DOMParser().parseFromString(data, 'text/html');
420 const newAssets = Array.from(doc.querySelectorAll('link[rel="stylesheet"],script')).filter(asset => asset.id && !document.getElementById(asset.id));
421
422 /*
423 * Load each asset in order, as they may depend upon an earlier loaded script.
424 * Stylesheets and Inline Scripts will resolve immediately upon insertion.
425 */
426 for (const newAsset of newAssets) {
427 await loadAsset(newAsset);
428 }
429 }
430
431 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/store/utils/get-plugin-url.js
432 /**
433 * Get the plugin's direct API link out of a block-directory response.
434 *
435 * @param {Object} block The block object
436 *
437 * @return {string} The plugin URL, if exists.
438 */
439 function getPluginUrl(block) {
440 if (!block) {
441 return false;
442 }
443 const link = block.links['wp:plugin'] || block.links.self;
444 if (link && link.length) {
445 return link[0].href;
446 }
447 return false;
448 }
449
450 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/store/actions.js
451 /**
452 * WordPress dependencies
453 */
454
455
456
457
458
459
460 /**
461 * Internal dependencies
462 */
463
464
465
466 /**
467 * Returns an action object used in signalling that the downloadable blocks
468 * have been requested and are loading.
469 *
470 * @param {string} filterValue Search string.
471 *
472 * @return {Object} Action object.
473 */
474 function fetchDownloadableBlocks(filterValue) {
475 return {
476 type: 'FETCH_DOWNLOADABLE_BLOCKS',
477 filterValue
478 };
479 }
480
481 /**
482 * Returns an action object used in signalling that the downloadable blocks
483 * have been updated.
484 *
485 * @param {Array} downloadableBlocks Downloadable blocks.
486 * @param {string} filterValue Search string.
487 *
488 * @return {Object} Action object.
489 */
490 function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
491 return {
492 type: 'RECEIVE_DOWNLOADABLE_BLOCKS',
493 downloadableBlocks,
494 filterValue
495 };
496 }
497
498 /**
499 * Action triggered to install a block plugin.
500 *
501 * @param {Object} block The block item returned by search.
502 *
503 * @return {boolean} Whether the block was successfully installed & loaded.
504 */
505 const installBlockType = block => async ({
506 registry,
507 dispatch
508 }) => {
509 const {
510 id,
511 name
512 } = block;
513 let success = false;
514 dispatch.clearErrorNotice(id);
515 try {
516 dispatch.setIsInstalling(id, true);
517
518 // If we have a wp:plugin link, the plugin is installed but inactive.
519 const url = getPluginUrl(block);
520 let links = {};
521 if (url) {
522 await external_wp_apiFetch_default()({
523 method: 'PUT',
524 url,
525 data: {
526 status: 'active'
527 }
528 });
529 } else {
530 const response = await external_wp_apiFetch_default()({
531 method: 'POST',
532 path: 'wp/v2/plugins',
533 data: {
534 slug: id,
535 status: 'active'
536 }
537 });
538 // Add the `self` link for newly-installed blocks.
539 links = response._links;
540 }
541 dispatch.addInstalledBlockType({
542 ...block,
543 links: {
544 ...block.links,
545 ...links
546 }
547 });
548
549 // Ensures that the block metadata is propagated to the editor when registered on the server.
550 const metadataFields = ['api_version', 'title', 'category', 'parent', 'icon', 'description', 'keywords', 'attributes', 'provides_context', 'uses_context', 'supports', 'styles', 'example', 'variations'];
551 await external_wp_apiFetch_default()({
552 path: (0,external_wp_url_namespaceObject.addQueryArgs)(`/wp/v2/block-types/${name}`, {
553 _fields: metadataFields
554 })
555 })
556 // Ignore when the block is not registered on the server.
557 .catch(() => {}).then(response => {
558 if (!response) {
559 return;
560 }
561 (0,external_wp_blocks_namespaceObject.unstable__bootstrapServerSideBlockDefinitions)({
562 [name]: Object.fromEntries(Object.entries(response).filter(([key]) => metadataFields.includes(key)))
563 });
564 });
565 await loadAssets();
566 const registeredBlocks = registry.select(external_wp_blocks_namespaceObject.store).getBlockTypes();
567 if (!registeredBlocks.some(i => i.name === name)) {
568 throw new Error((0,external_wp_i18n_namespaceObject.__)('Error registering block. Try reloading the page.'));
569 }
570 registry.dispatch(external_wp_notices_namespaceObject.store).createInfoNotice((0,external_wp_i18n_namespaceObject.sprintf)(
571 // translators: %s is the block title.
572 (0,external_wp_i18n_namespaceObject.__)('Block %s installed and added.'), block.title), {
573 speak: true,
574 type: 'snackbar'
575 });
576 success = true;
577 } catch (error) {
578 let message = error.message || (0,external_wp_i18n_namespaceObject.__)('An error occurred.');
579
580 // Errors we throw are fatal.
581 let isFatal = error instanceof Error;
582
583 // Specific API errors that are fatal.
584 const fatalAPIErrors = {
585 folder_exists: (0,external_wp_i18n_namespaceObject.__)('This block is already installed. Try reloading the page.'),
586 unable_to_connect_to_filesystem: (0,external_wp_i18n_namespaceObject.__)('Error installing block. You can reload the page and try again.')
587 };
588 if (fatalAPIErrors[error.code]) {
589 isFatal = true;
590 message = fatalAPIErrors[error.code];
591 }
592 dispatch.setErrorNotice(id, message, isFatal);
593 registry.dispatch(external_wp_notices_namespaceObject.store).createErrorNotice(message, {
594 speak: true,
595 isDismissible: true
596 });
597 }
598 dispatch.setIsInstalling(id, false);
599 return success;
600 };
601
602 /**
603 * Action triggered to uninstall a block plugin.
604 *
605 * @param {Object} block The blockType object.
606 */
607 const uninstallBlockType = block => async ({
608 registry,
609 dispatch
610 }) => {
611 try {
612 const url = getPluginUrl(block);
613 await external_wp_apiFetch_default()({
614 method: 'PUT',
615 url,
616 data: {
617 status: 'inactive'
618 }
619 });
620 await external_wp_apiFetch_default()({
621 method: 'DELETE',
622 url
623 });
624 dispatch.removeInstalledBlockType(block);
625 } catch (error) {
626 registry.dispatch(external_wp_notices_namespaceObject.store).createErrorNotice(error.message || (0,external_wp_i18n_namespaceObject.__)('An error occurred.'));
627 }
628 };
629
630 /**
631 * Returns an action object used to add a block type to the "newly installed"
632 * tracking list.
633 *
634 * @param {Object} item The block item with the block id and name.
635 *
636 * @return {Object} Action object.
637 */
638 function addInstalledBlockType(item) {
639 return {
640 type: 'ADD_INSTALLED_BLOCK_TYPE',
641 item
642 };
643 }
644
645 /**
646 * Returns an action object used to remove a block type from the "newly installed"
647 * tracking list.
648 *
649 * @param {string} item The block item with the block id and name.
650 *
651 * @return {Object} Action object.
652 */
653 function removeInstalledBlockType(item) {
654 return {
655 type: 'REMOVE_INSTALLED_BLOCK_TYPE',
656 item
657 };
658 }
659
660 /**
661 * Returns an action object used to indicate install in progress.
662 *
663 * @param {string} blockId
664 * @param {boolean} isInstalling
665 *
666 * @return {Object} Action object.
667 */
668 function setIsInstalling(blockId, isInstalling) {
669 return {
670 type: 'SET_INSTALLING_BLOCK',
671 blockId,
672 isInstalling
673 };
674 }
675
676 /**
677 * Sets an error notice to be displayed to the user for a given block.
678 *
679 * @param {string} blockId The ID of the block plugin. eg: my-block
680 * @param {string} message The message shown in the notice.
681 * @param {boolean} isFatal Whether the user can recover from the error.
682 *
683 * @return {Object} Action object.
684 */
685 function setErrorNotice(blockId, message, isFatal = false) {
686 return {
687 type: 'SET_ERROR_NOTICE',
688 blockId,
689 message,
690 isFatal
691 };
692 }
693
694 /**
695 * Sets the error notice to empty for specific block.
696 *
697 * @param {string} blockId The ID of the block plugin. eg: my-block
698 *
699 * @return {Object} Action object.
700 */
701 function clearErrorNotice(blockId) {
702 return {
703 type: 'CLEAR_ERROR_NOTICE',
704 blockId
705 };
706 }
707
708 ;// CONCATENATED MODULE: ./node_modules/tslib/tslib.es6.mjs
709 /******************************************************************************
710 Copyright (c) Microsoft Corporation.
711
712 Permission to use, copy, modify, and/or distribute this software for any
713 purpose with or without fee is hereby granted.
714
715 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
716 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
717 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
718 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
719 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
720 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
721 PERFORMANCE OF THIS SOFTWARE.
722 ***************************************************************************** */
723 /* global Reflect, Promise, SuppressedError, Symbol */
724
725 var extendStatics = function(d, b) {
726 extendStatics = Object.setPrototypeOf ||
727 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
728 function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
729 return extendStatics(d, b);
730 };
731
732 function __extends(d, b) {
733 if (typeof b !== "function" && b !== null)
734 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
735 extendStatics(d, b);
736 function __() { this.constructor = d; }
737 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
738 }
739
740 var __assign = function() {
741 __assign = Object.assign || function __assign(t) {
742 for (var s, i = 1, n = arguments.length; i < n; i++) {
743 s = arguments[i];
744 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
745 }
746 return t;
747 }
748 return __assign.apply(this, arguments);
749 }
750
751 function __rest(s, e) {
752 var t = {};
753 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
754 t[p] = s[p];
755 if (s != null && typeof Object.getOwnPropertySymbols === "function")
756 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
757 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
758 t[p[i]] = s[p[i]];
759 }
760 return t;
761 }
762
763 function __decorate(decorators, target, key, desc) {
764 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
765 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
766 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;
767 return c > 3 && r && Object.defineProperty(target, key, r), r;
768 }
769
770 function __param(paramIndex, decorator) {
771 return function (target, key) { decorator(target, key, paramIndex); }
772 }
773
774 function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
775 function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
776 var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
777 var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
778 var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
779 var _, done = false;
780 for (var i = decorators.length - 1; i >= 0; i--) {
781 var context = {};
782 for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
783 for (var p in contextIn.access) context.access[p] = contextIn.access[p];
784 context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
785 var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
786 if (kind === "accessor") {
787 if (result === void 0) continue;
788 if (result === null || typeof result !== "object") throw new TypeError("Object expected");
789 if (_ = accept(result.get)) descriptor.get = _;
790 if (_ = accept(result.set)) descriptor.set = _;
791 if (_ = accept(result.init)) initializers.unshift(_);
792 }
793 else if (_ = accept(result)) {
794 if (kind === "field") initializers.unshift(_);
795 else descriptor[key] = _;
796 }
797 }
798 if (target) Object.defineProperty(target, contextIn.name, descriptor);
799 done = true;
800 };
801
802 function __runInitializers(thisArg, initializers, value) {
803 var useValue = arguments.length > 2;
804 for (var i = 0; i < initializers.length; i++) {
805 value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
806 }
807 return useValue ? value : void 0;
808 };
809
810 function __propKey(x) {
811 return typeof x === "symbol" ? x : "".concat(x);
812 };
813
814 function __setFunctionName(f, name, prefix) {
815 if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
816 return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
817 };
818
819 function __metadata(metadataKey, metadataValue) {
820 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
821 }
822
823 function __awaiter(thisArg, _arguments, P, generator) {
824 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
825 return new (P || (P = Promise))(function (resolve, reject) {
826 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
827 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
828 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
829 step((generator = generator.apply(thisArg, _arguments || [])).next());
830 });
831 }
832
833 function __generator(thisArg, body) {
834 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
835 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
836 function verb(n) { return function (v) { return step([n, v]); }; }
837 function step(op) {
838 if (f) throw new TypeError("Generator is already executing.");
839 while (g && (g = 0, op[0] && (_ = 0)), _) try {
840 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;
841 if (y = 0, t) op = [op[0] & 2, t.value];
842 switch (op[0]) {
843 case 0: case 1: t = op; break;
844 case 4: _.label++; return { value: op[1], done: false };
845 case 5: _.label++; y = op[1]; op = [0]; continue;
846 case 7: op = _.ops.pop(); _.trys.pop(); continue;
847 default:
848 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
849 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
850 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
851 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
852 if (t[2]) _.ops.pop();
853 _.trys.pop(); continue;
854 }
855 op = body.call(thisArg, _);
856 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
857 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
858 }
859 }
860
861 var __createBinding = Object.create ? (function(o, m, k, k2) {
862 if (k2 === undefined) k2 = k;
863 var desc = Object.getOwnPropertyDescriptor(m, k);
864 if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
865 desc = { enumerable: true, get: function() { return m[k]; } };
866 }
867 Object.defineProperty(o, k2, desc);
868 }) : (function(o, m, k, k2) {
869 if (k2 === undefined) k2 = k;
870 o[k2] = m[k];
871 });
872
873 function __exportStar(m, o) {
874 for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
875 }
876
877 function __values(o) {
878 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
879 if (m) return m.call(o);
880 if (o && typeof o.length === "number") return {
881 next: function () {
882 if (o && i >= o.length) o = void 0;
883 return { value: o && o[i++], done: !o };
884 }
885 };
886 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
887 }
888
889 function __read(o, n) {
890 var m = typeof Symbol === "function" && o[Symbol.iterator];
891 if (!m) return o;
892 var i = m.call(o), r, ar = [], e;
893 try {
894 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
895 }
896 catch (error) { e = { error: error }; }
897 finally {
898 try {
899 if (r && !r.done && (m = i["return"])) m.call(i);
900 }
901 finally { if (e) throw e.error; }
902 }
903 return ar;
904 }
905
906 /** @deprecated */
907 function __spread() {
908 for (var ar = [], i = 0; i < arguments.length; i++)
909 ar = ar.concat(__read(arguments[i]));
910 return ar;
911 }
912
913 /** @deprecated */
914 function __spreadArrays() {
915 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
916 for (var r = Array(s), k = 0, i = 0; i < il; i++)
917 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
918 r[k] = a[j];
919 return r;
920 }
921
922 function __spreadArray(to, from, pack) {
923 if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
924 if (ar || !(i in from)) {
925 if (!ar) ar = Array.prototype.slice.call(from, 0, i);
926 ar[i] = from[i];
927 }
928 }
929 return to.concat(ar || Array.prototype.slice.call(from));
930 }
931
932 function __await(v) {
933 return this instanceof __await ? (this.v = v, this) : new __await(v);
934 }
935
936 function __asyncGenerator(thisArg, _arguments, generator) {
937 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
938 var g = generator.apply(thisArg, _arguments || []), i, q = [];
939 return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
940 function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
941 function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
942 function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
943 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
944 function fulfill(value) { resume("next", value); }
945 function reject(value) { resume("throw", value); }
946 function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
947 }
948
949 function __asyncDelegator(o) {
950 var i, p;
951 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
952 function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
953 }
954
955 function __asyncValues(o) {
956 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
957 var m = o[Symbol.asyncIterator], i;
958 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);
959 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); }); }; }
960 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
961 }
962
963 function __makeTemplateObject(cooked, raw) {
964 if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
965 return cooked;
966 };
967
968 var __setModuleDefault = Object.create ? (function(o, v) {
969 Object.defineProperty(o, "default", { enumerable: true, value: v });
970 }) : function(o, v) {
971 o["default"] = v;
972 };
973
974 function __importStar(mod) {
975 if (mod && mod.__esModule) return mod;
976 var result = {};
977 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
978 __setModuleDefault(result, mod);
979 return result;
980 }
981
982 function __importDefault(mod) {
983 return (mod && mod.__esModule) ? mod : { default: mod };
984 }
985
986 function __classPrivateFieldGet(receiver, state, kind, f) {
987 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
988 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");
989 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
990 }
991
992 function __classPrivateFieldSet(receiver, state, value, kind, f) {
993 if (kind === "m") throw new TypeError("Private method is not writable");
994 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
995 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");
996 return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
997 }
998
999 function __classPrivateFieldIn(state, receiver) {
1000 if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function")) throw new TypeError("Cannot use 'in' operator on non-object");
1001 return typeof state === "function" ? receiver === state : state.has(receiver);
1002 }
1003
1004 function __addDisposableResource(env, value, async) {
1005 if (value !== null && value !== void 0) {
1006 if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
1007 var dispose, inner;
1008 if (async) {
1009 if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
1010 dispose = value[Symbol.asyncDispose];
1011 }
1012 if (dispose === void 0) {
1013 if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
1014 dispose = value[Symbol.dispose];
1015 if (async) inner = dispose;
1016 }
1017 if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
1018 if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
1019 env.stack.push({ value: value, dispose: dispose, async: async });
1020 }
1021 else if (async) {
1022 env.stack.push({ async: true });
1023 }
1024 return value;
1025 }
1026
1027 var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1028 var e = new Error(message);
1029 return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1030 };
1031
1032 function __disposeResources(env) {
1033 function fail(e) {
1034 env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
1035 env.hasError = true;
1036 }
1037 function next() {
1038 while (env.stack.length) {
1039 var rec = env.stack.pop();
1040 try {
1041 var result = rec.dispose && rec.dispose.call(rec.value);
1042 if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
1043 }
1044 catch (e) {
1045 fail(e);
1046 }
1047 }
1048 if (env.hasError) throw env.error;
1049 }
1050 return next();
1051 }
1052
1053 /* harmony default export */ const tslib_es6 = ({
1054 __extends,
1055 __assign,
1056 __rest,
1057 __decorate,
1058 __param,
1059 __metadata,
1060 __awaiter,
1061 __generator,
1062 __createBinding,
1063 __exportStar,
1064 __values,
1065 __read,
1066 __spread,
1067 __spreadArrays,
1068 __spreadArray,
1069 __await,
1070 __asyncGenerator,
1071 __asyncDelegator,
1072 __asyncValues,
1073 __makeTemplateObject,
1074 __importStar,
1075 __importDefault,
1076 __classPrivateFieldGet,
1077 __classPrivateFieldSet,
1078 __classPrivateFieldIn,
1079 __addDisposableResource,
1080 __disposeResources,
1081 });
1082
1083 ;// CONCATENATED MODULE: ./node_modules/lower-case/dist.es2015/index.js
1084 /**
1085 * Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
1086 */
1087 var SUPPORTED_LOCALE = {
1088 tr: {
1089 regexp: /\u0130|\u0049|\u0049\u0307/g,
1090 map: {
1091 İ: "\u0069",
1092 I: "\u0131",
1093 : "\u0069",
1094 },
1095 },
1096 az: {
1097 regexp: /\u0130/g,
1098 map: {
1099 İ: "\u0069",
1100 I: "\u0131",
1101 : "\u0069",
1102 },
1103 },
1104 lt: {
1105 regexp: /\u0049|\u004A|\u012E|\u00CC|\u00CD|\u0128/g,
1106 map: {
1107 I: "\u0069\u0307",
1108 J: "\u006A\u0307",
1109 Į: "\u012F\u0307",
1110 Ì: "\u0069\u0307\u0300",
1111 Í: "\u0069\u0307\u0301",
1112 Ĩ: "\u0069\u0307\u0303",
1113 },
1114 },
1115 };
1116 /**
1117 * Localized lower case.
1118 */
1119 function localeLowerCase(str, locale) {
1120 var lang = SUPPORTED_LOCALE[locale.toLowerCase()];
1121 if (lang)
1122 return lowerCase(str.replace(lang.regexp, function (m) { return lang.map[m]; }));
1123 return lowerCase(str);
1124 }
1125 /**
1126 * Lower case as a function.
1127 */
1128 function lowerCase(str) {
1129 return str.toLowerCase();
1130 }
1131
1132 ;// CONCATENATED MODULE: ./node_modules/no-case/dist.es2015/index.js
1133
1134 // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
1135 var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
1136 // Remove all non-word characters.
1137 var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
1138 /**
1139 * Normalize the string into something other libraries can manipulate easier.
1140 */
1141 function noCase(input, options) {
1142 if (options === void 0) { options = {}; }
1143 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;
1144 var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
1145 var start = 0;
1146 var end = result.length;
1147 // Trim the delimiter from around the output string.
1148 while (result.charAt(start) === "\0")
1149 start++;
1150 while (result.charAt(end - 1) === "\0")
1151 end--;
1152 // Transform each token independently.
1153 return result.slice(start, end).split("\0").map(transform).join(delimiter);
1154 }
1155 /**
1156 * Replace `re` in the input string with the replacement value.
1157 */
1158 function replace(input, re, value) {
1159 if (re instanceof RegExp)
1160 return input.replace(re, value);
1161 return re.reduce(function (input, re) { return input.replace(re, value); }, input);
1162 }
1163
1164 ;// CONCATENATED MODULE: ./node_modules/pascal-case/dist.es2015/index.js
1165
1166
1167 function pascalCaseTransform(input, index) {
1168 var firstChar = input.charAt(0);
1169 var lowerChars = input.substr(1).toLowerCase();
1170 if (index > 0 && firstChar >= "0" && firstChar <= "9") {
1171 return "_" + firstChar + lowerChars;
1172 }
1173 return "" + firstChar.toUpperCase() + lowerChars;
1174 }
1175 function dist_es2015_pascalCaseTransformMerge(input) {
1176 return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
1177 }
1178 function pascalCase(input, options) {
1179 if (options === void 0) { options = {}; }
1180 return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options));
1181 }
1182
1183 ;// CONCATENATED MODULE: ./node_modules/camel-case/dist.es2015/index.js
1184
1185
1186 function camelCaseTransform(input, index) {
1187 if (index === 0)
1188 return input.toLowerCase();
1189 return pascalCaseTransform(input, index);
1190 }
1191 function camelCaseTransformMerge(input, index) {
1192 if (index === 0)
1193 return input.toLowerCase();
1194 return pascalCaseTransformMerge(input);
1195 }
1196 function camelCase(input, options) {
1197 if (options === void 0) { options = {}; }
1198 return pascalCase(input, __assign({ transform: camelCaseTransform }, options));
1199 }
1200
1201 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/store/resolvers.js
1202 /**
1203 * External dependencies
1204 */
1205
1206
1207 /**
1208 * WordPress dependencies
1209 */
1210
1211
1212 /**
1213 * Internal dependencies
1214 */
1215
1216 const resolvers_getDownloadableBlocks = filterValue => async ({
1217 dispatch
1218 }) => {
1219 if (!filterValue) {
1220 return;
1221 }
1222 try {
1223 dispatch(fetchDownloadableBlocks(filterValue));
1224 const results = await external_wp_apiFetch_default()({
1225 path: `wp/v2/block-directory/search?term=${filterValue}`
1226 });
1227 const blocks = results.map(result => Object.fromEntries(Object.entries(result).map(([key, value]) => [camelCase(key), value])));
1228 dispatch(receiveDownloadableBlocks(blocks, filterValue));
1229 } catch {}
1230 };
1231
1232 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/store/index.js
1233 /**
1234 * WordPress dependencies
1235 */
1236
1237
1238 /**
1239 * Internal dependencies
1240 */
1241
1242
1243
1244
1245
1246 /**
1247 * Module Constants
1248 */
1249 const STORE_NAME = 'core/block-directory';
1250
1251 /**
1252 * Block editor data store configuration.
1253 *
1254 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registerStore
1255 *
1256 * @type {Object}
1257 */
1258 const storeConfig = {
1259 reducer: reducer,
1260 selectors: selectors_namespaceObject,
1261 actions: actions_namespaceObject,
1262 resolvers: resolvers_namespaceObject
1263 };
1264
1265 /**
1266 * Store definition for the block directory namespace.
1267 *
1268 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
1269 *
1270 * @type {Object}
1271 */
1272 const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, storeConfig);
1273 (0,external_wp_data_namespaceObject.register)(store);
1274
1275 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/auto-block-uninstaller/index.js
1276 /**
1277 * WordPress dependencies
1278 */
1279
1280
1281
1282
1283
1284 /**
1285 * Internal dependencies
1286 */
1287
1288 function AutoBlockUninstaller() {
1289 const {
1290 uninstallBlockType
1291 } = (0,external_wp_data_namespaceObject.useDispatch)(store);
1292 const shouldRemoveBlockTypes = (0,external_wp_data_namespaceObject.useSelect)(select => {
1293 const {
1294 isAutosavingPost,
1295 isSavingPost
1296 } = select(external_wp_editor_namespaceObject.store);
1297 return isSavingPost() && !isAutosavingPost();
1298 }, []);
1299 const unusedBlockTypes = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).getUnusedBlockTypes(), []);
1300 (0,external_wp_element_namespaceObject.useEffect)(() => {
1301 if (shouldRemoveBlockTypes && unusedBlockTypes.length) {
1302 unusedBlockTypes.forEach(blockType => {
1303 uninstallBlockType(blockType);
1304 (0,external_wp_blocks_namespaceObject.unregisterBlockType)(blockType.name);
1305 });
1306 }
1307 }, [shouldRemoveBlockTypes]);
1308 return null;
1309 }
1310
1311 ;// CONCATENATED MODULE: external ["wp","compose"]
1312 const external_wp_compose_namespaceObject = window["wp"]["compose"];
1313 ;// CONCATENATED MODULE: external ["wp","components"]
1314 const external_wp_components_namespaceObject = window["wp"]["components"];
1315 ;// CONCATENATED MODULE: external ["wp","coreData"]
1316 const external_wp_coreData_namespaceObject = window["wp"]["coreData"];
1317 ;// CONCATENATED MODULE: external ["wp","htmlEntities"]
1318 const external_wp_htmlEntities_namespaceObject = window["wp"]["htmlEntities"];
1319 ;// CONCATENATED MODULE: ./packages/icons/build-module/icon/index.js
1320 /**
1321 * WordPress dependencies
1322 */
1323
1324
1325 /** @typedef {{icon: JSX.Element, size?: number} & import('@wordpress/primitives').SVGProps} IconProps */
1326
1327 /**
1328 * Return an SVG icon.
1329 *
1330 * @param {IconProps} props icon is the SVG component to render
1331 * size is a number specifiying the icon size in pixels
1332 * Other props will be passed to wrapped SVG component
1333 * @param {import('react').ForwardedRef<HTMLElement>} ref The forwarded ref to the SVG element.
1334 *
1335 * @return {JSX.Element} Icon component
1336 */
1337 function Icon({
1338 icon,
1339 size = 24,
1340 ...props
1341 }, ref) {
1342 return (0,external_wp_element_namespaceObject.cloneElement)(icon, {
1343 width: size,
1344 height: size,
1345 ...props,
1346 ref
1347 });
1348 }
1349 /* harmony default export */ const icon = ((0,external_wp_element_namespaceObject.forwardRef)(Icon));
1350
1351 ;// CONCATENATED MODULE: external ["wp","primitives"]
1352 const external_wp_primitives_namespaceObject = window["wp"]["primitives"];
1353 ;// CONCATENATED MODULE: external "ReactJSXRuntime"
1354 const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
1355 ;// CONCATENATED MODULE: ./packages/icons/build-module/library/star-filled.js
1356 /**
1357 * WordPress dependencies
1358 */
1359
1360
1361 const starFilled = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1362 xmlns: "http://www.w3.org/2000/svg",
1363 viewBox: "0 0 24 24",
1364 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1365 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"
1366 })
1367 });
1368 /* harmony default export */ const star_filled = (starFilled);
1369
1370 ;// CONCATENATED MODULE: ./packages/icons/build-module/library/star-half.js
1371 /**
1372 * WordPress dependencies
1373 */
1374
1375
1376 const starHalf = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1377 xmlns: "http://www.w3.org/2000/svg",
1378 viewBox: "0 0 24 24",
1379 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1380 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"
1381 })
1382 });
1383 /* harmony default export */ const star_half = (starHalf);
1384
1385 ;// CONCATENATED MODULE: ./packages/icons/build-module/library/star-empty.js
1386 /**
1387 * WordPress dependencies
1388 */
1389
1390
1391 const starEmpty = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1392 xmlns: "http://www.w3.org/2000/svg",
1393 viewBox: "0 0 24 24",
1394 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1395 fillRule: "evenodd",
1396 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",
1397 clipRule: "evenodd"
1398 })
1399 });
1400 /* harmony default export */ const star_empty = (starEmpty);
1401
1402 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/block-ratings/stars.js
1403 /**
1404 * WordPress dependencies
1405 */
1406
1407
1408
1409
1410 function Stars({
1411 rating
1412 }) {
1413 const stars = Math.round(rating / 0.5) * 0.5;
1414 const fullStarCount = Math.floor(rating);
1415 const halfStarCount = Math.ceil(rating - fullStarCount);
1416 const emptyStarCount = 5 - (fullStarCount + halfStarCount);
1417 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("span", {
1418 "aria-label": (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: number of stars. */
1419 (0,external_wp_i18n_namespaceObject.__)('%s out of 5 stars'), stars),
1420 children: [Array.from({
1421 length: fullStarCount
1422 }).map((_, i) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(icon, {
1423 className: "block-directory-block-ratings__star-full",
1424 icon: star_filled,
1425 size: 16
1426 }, `full_stars_${i}`)), Array.from({
1427 length: halfStarCount
1428 }).map((_, i) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(icon, {
1429 className: "block-directory-block-ratings__star-half-full",
1430 icon: star_half,
1431 size: 16
1432 }, `half_stars_${i}`)), Array.from({
1433 length: emptyStarCount
1434 }).map((_, i) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(icon, {
1435 className: "block-directory-block-ratings__star-empty",
1436 icon: star_empty,
1437 size: 16
1438 }, `empty_stars_${i}`))]
1439 });
1440 }
1441 /* harmony default export */ const stars = (Stars);
1442
1443 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/block-ratings/index.js
1444 /**
1445 * Internal dependencies
1446 */
1447
1448
1449 const BlockRatings = ({
1450 rating
1451 }) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("span", {
1452 className: "block-directory-block-ratings",
1453 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(stars, {
1454 rating: rating
1455 })
1456 });
1457 /* harmony default export */ const block_ratings = (BlockRatings);
1458
1459 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/downloadable-block-icon/index.js
1460 /**
1461 * WordPress dependencies
1462 */
1463
1464
1465 function DownloadableBlockIcon({
1466 icon
1467 }) {
1468 const className = 'block-directory-downloadable-block-icon';
1469 return icon.match(/\.(jpeg|jpg|gif|png|svg)(?:\?.*)?$/) !== null ? /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("img", {
1470 className: className,
1471 src: icon,
1472 alt: ""
1473 }) : /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.BlockIcon, {
1474 className: className,
1475 icon: icon,
1476 showColors: true
1477 });
1478 }
1479 /* harmony default export */ const downloadable_block_icon = (DownloadableBlockIcon);
1480
1481 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/downloadable-block-notice/index.js
1482 /**
1483 * WordPress dependencies
1484 */
1485
1486
1487
1488 /**
1489 * Internal dependencies
1490 */
1491
1492
1493
1494 const DownloadableBlockNotice = ({
1495 block
1496 }) => {
1497 const errorNotice = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).getErrorNoticeForBlock(block.id), [block]);
1498 if (!errorNotice) {
1499 return null;
1500 }
1501 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
1502 className: "block-directory-downloadable-block-notice",
1503 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
1504 className: "block-directory-downloadable-block-notice__content",
1505 children: [errorNotice.message, errorNotice.isFatal ? ' ' + (0,external_wp_i18n_namespaceObject.__)('Try reloading the page.') : null]
1506 })
1507 });
1508 };
1509 /* harmony default export */ const downloadable_block_notice = (DownloadableBlockNotice);
1510
1511 ;// CONCATENATED MODULE: external ["wp","privateApis"]
1512 const external_wp_privateApis_namespaceObject = window["wp"]["privateApis"];
1513 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/lock-unlock.js
1514 /**
1515 * WordPress dependencies
1516 */
1517
1518 const {
1519 lock,
1520 unlock
1521 } = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/block-directory');
1522
1523 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/downloadable-block-list-item/index.js
1524 /**
1525 * WordPress dependencies
1526 */
1527
1528
1529
1530
1531
1532
1533
1534 /**
1535 * Internal dependencies
1536 */
1537
1538
1539
1540
1541
1542
1543
1544
1545 const {
1546 CompositeItemV2: CompositeItem
1547 } = unlock(external_wp_components_namespaceObject.privateApis);
1548
1549 // Return the appropriate block item label, given the block data and status.
1550 function getDownloadableBlockLabel({
1551 title,
1552 rating,
1553 ratingCount
1554 }, {
1555 hasNotice,
1556 isInstalled,
1557 isInstalling
1558 }) {
1559 const stars = Math.round(rating / 0.5) * 0.5;
1560 if (!isInstalled && hasNotice) {
1561 /* translators: %1$s: block title */
1562 return (0,external_wp_i18n_namespaceObject.sprintf)('Retry installing %s.', (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title));
1563 }
1564 if (isInstalled) {
1565 /* translators: %1$s: block title */
1566 return (0,external_wp_i18n_namespaceObject.sprintf)('Add %s.', (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title));
1567 }
1568 if (isInstalling) {
1569 /* translators: %1$s: block title */
1570 return (0,external_wp_i18n_namespaceObject.sprintf)('Installing %s.', (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title));
1571 }
1572
1573 // No ratings yet, just use the title.
1574 if (ratingCount < 1) {
1575 /* translators: %1$s: block title */
1576 return (0,external_wp_i18n_namespaceObject.sprintf)('Install %s.', (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title));
1577 }
1578 return (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %1$s: block title, %2$s: average rating, %3$s: total ratings count. */
1579 (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);
1580 }
1581 function DownloadableBlockListItem({
1582 composite,
1583 item,
1584 onClick
1585 }) {
1586 const {
1587 author,
1588 description,
1589 icon,
1590 rating,
1591 title
1592 } = item;
1593 // getBlockType returns a block object if this block exists, or null if not.
1594 const isInstalled = !!(0,external_wp_blocks_namespaceObject.getBlockType)(item.name);
1595 const {
1596 hasNotice,
1597 isInstalling,
1598 isInstallable
1599 } = (0,external_wp_data_namespaceObject.useSelect)(select => {
1600 const {
1601 getErrorNoticeForBlock,
1602 isInstalling: isBlockInstalling
1603 } = select(store);
1604 const notice = getErrorNoticeForBlock(item.id);
1605 const hasFatal = notice && notice.isFatal;
1606 return {
1607 hasNotice: !!notice,
1608 isInstalling: isBlockInstalling(item.id),
1609 isInstallable: !hasFatal
1610 };
1611 }, [item]);
1612 let statusText = '';
1613 if (isInstalled) {
1614 statusText = (0,external_wp_i18n_namespaceObject.__)('Installed!');
1615 } else if (isInstalling) {
1616 statusText = (0,external_wp_i18n_namespaceObject.__)('Installing…');
1617 }
1618 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(CompositeItem, {
1619 render: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
1620 accessibleWhenDisabled: true,
1621 type: "button",
1622 role: "option",
1623 className: "block-directory-downloadable-block-list-item",
1624 isBusy: isInstalling,
1625 onClick: event => {
1626 event.preventDefault();
1627 onClick();
1628 },
1629 label: getDownloadableBlockLabel(item, {
1630 hasNotice,
1631 isInstalled,
1632 isInstalling
1633 }),
1634 showTooltip: true,
1635 tooltipPosition: "top center"
1636 }),
1637 store: composite,
1638 disabled: isInstalling || !isInstallable,
1639 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
1640 className: "block-directory-downloadable-block-list-item__icon",
1641 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(downloadable_block_icon, {
1642 icon: icon,
1643 title: title
1644 }), isInstalling ? /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("span", {
1645 className: "block-directory-downloadable-block-list-item__spinner",
1646 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Spinner, {})
1647 }) : /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(block_ratings, {
1648 rating: rating
1649 })]
1650 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("span", {
1651 className: "block-directory-downloadable-block-list-item__details",
1652 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("span", {
1653 className: "block-directory-downloadable-block-list-item__title",
1654 children: (0,external_wp_element_namespaceObject.createInterpolateElement)((0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %1$s: block title, %2$s: author name. */
1655 (0,external_wp_i18n_namespaceObject.__)('%1$s <span>by %2$s</span>'), (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title), author), {
1656 span: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("span", {
1657 className: "block-directory-downloadable-block-list-item__author"
1658 })
1659 })
1660 }), hasNotice ? /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(downloadable_block_notice, {
1661 block: item
1662 }) : /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1663 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("span", {
1664 className: "block-directory-downloadable-block-list-item__desc",
1665 children: !!statusText ? statusText : (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(description)
1666 }), isInstallable && !(isInstalled || isInstalling) && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.VisuallyHidden, {
1667 children: (0,external_wp_i18n_namespaceObject.__)('Install block')
1668 })]
1669 })]
1670 })]
1671 });
1672 }
1673 /* harmony default export */ const downloadable_block_list_item = (DownloadableBlockListItem);
1674
1675 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/downloadable-blocks-list/index.js
1676 /**
1677 * WordPress dependencies
1678 */
1679
1680
1681
1682
1683
1684 /**
1685 * Internal dependencies
1686 */
1687
1688
1689
1690
1691 const {
1692 CompositeV2: Composite,
1693 useCompositeStoreV2: useCompositeStore
1694 } = unlock(external_wp_components_namespaceObject.privateApis);
1695 const noop = () => {};
1696 function DownloadableBlocksList({
1697 items,
1698 onHover = noop,
1699 onSelect
1700 }) {
1701 const composite = useCompositeStore();
1702 const {
1703 installBlockType
1704 } = (0,external_wp_data_namespaceObject.useDispatch)(store);
1705 if (!items.length) {
1706 return null;
1707 }
1708 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Composite, {
1709 store: composite,
1710 role: "listbox",
1711 className: "block-directory-downloadable-blocks-list",
1712 "aria-label": (0,external_wp_i18n_namespaceObject.__)('Blocks available for install'),
1713 children: items.map(item => {
1714 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(downloadable_block_list_item, {
1715 composite: composite,
1716 onClick: () => {
1717 // Check if the block is registered (`getBlockType`
1718 // will return an object). If so, insert the block.
1719 // This prevents installing existing plugins.
1720 if ((0,external_wp_blocks_namespaceObject.getBlockType)(item.name)) {
1721 onSelect(item);
1722 } else {
1723 installBlockType(item).then(success => {
1724 if (success) {
1725 onSelect(item);
1726 }
1727 });
1728 }
1729 onHover(null);
1730 },
1731 onHover: onHover,
1732 item: item
1733 }, item.id);
1734 })
1735 });
1736 }
1737 /* harmony default export */ const downloadable_blocks_list = (DownloadableBlocksList);
1738
1739 ;// CONCATENATED MODULE: external ["wp","a11y"]
1740 const external_wp_a11y_namespaceObject = window["wp"]["a11y"];
1741 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/downloadable-blocks-panel/inserter-panel.js
1742 /**
1743 * WordPress dependencies
1744 */
1745
1746
1747
1748
1749
1750
1751 function DownloadableBlocksInserterPanel({
1752 children,
1753 downloadableItems,
1754 hasLocalBlocks
1755 }) {
1756 const count = downloadableItems.length;
1757 (0,external_wp_element_namespaceObject.useEffect)(() => {
1758 (0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %d: number of available blocks. */
1759 (0,external_wp_i18n_namespaceObject._n)('%d additional block is available to install.', '%d additional blocks are available to install.', count), count));
1760 }, [count]);
1761 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1762 children: [!hasLocalBlocks && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("p", {
1763 className: "block-directory-downloadable-blocks-panel__no-local",
1764 children: (0,external_wp_i18n_namespaceObject.__)('No results available from your installed blocks.')
1765 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
1766 className: "block-editor-inserter__quick-inserter-separator"
1767 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
1768 className: "block-directory-downloadable-blocks-panel",
1769 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
1770 className: "block-directory-downloadable-blocks-panel__header",
1771 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("h2", {
1772 className: "block-directory-downloadable-blocks-panel__title",
1773 children: (0,external_wp_i18n_namespaceObject.__)('Available to install')
1774 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("p", {
1775 className: "block-directory-downloadable-blocks-panel__description",
1776 children: (0,external_wp_i18n_namespaceObject.__)('Select a block to install and add it to your post.')
1777 })]
1778 }), children]
1779 })]
1780 });
1781 }
1782 /* harmony default export */ const inserter_panel = (DownloadableBlocksInserterPanel);
1783
1784 ;// CONCATENATED MODULE: ./packages/icons/build-module/library/block-default.js
1785 /**
1786 * WordPress dependencies
1787 */
1788
1789
1790 const blockDefault = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1791 xmlns: "http://www.w3.org/2000/svg",
1792 viewBox: "0 0 24 24",
1793 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1794 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"
1795 })
1796 });
1797 /* harmony default export */ const block_default = (blockDefault);
1798
1799 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/downloadable-blocks-panel/no-results.js
1800 /**
1801 * WordPress dependencies
1802 */
1803
1804
1805
1806
1807
1808
1809 function DownloadableBlocksNoResults() {
1810 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1811 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
1812 className: "block-editor-inserter__no-results",
1813 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(icon, {
1814 className: "block-editor-inserter__no-results-icon",
1815 icon: block_default
1816 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("p", {
1817 children: (0,external_wp_i18n_namespaceObject.__)('No results found.')
1818 })]
1819 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
1820 className: "block-editor-inserter__tips",
1821 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_components_namespaceObject.Tip, {
1822 children: [(0,external_wp_i18n_namespaceObject.__)('Interested in creating your own block?'), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("br", {}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_components_namespaceObject.ExternalLink, {
1823 href: "https://developer.wordpress.org/block-editor/",
1824 children: [(0,external_wp_i18n_namespaceObject.__)('Get started here'), "."]
1825 })]
1826 })
1827 })]
1828 });
1829 }
1830 /* harmony default export */ const no_results = (DownloadableBlocksNoResults);
1831
1832 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/downloadable-blocks-panel/index.js
1833 /**
1834 * WordPress dependencies
1835 */
1836
1837
1838
1839
1840
1841
1842 /**
1843 * Internal dependencies
1844 */
1845
1846
1847
1848
1849
1850
1851
1852 const EMPTY_ARRAY = [];
1853 const useDownloadableBlocks = filterValue => (0,external_wp_data_namespaceObject.useSelect)(select => {
1854 const {
1855 getDownloadableBlocks,
1856 isRequestingDownloadableBlocks,
1857 getInstalledBlockTypes
1858 } = select(store);
1859 const hasPermission = select(external_wp_coreData_namespaceObject.store).canUser('read', 'block-directory/search');
1860 let downloadableBlocks = EMPTY_ARRAY;
1861 if (hasPermission) {
1862 downloadableBlocks = getDownloadableBlocks(filterValue);
1863
1864 // Filter out blocks that are already installed.
1865 const installedBlockTypes = getInstalledBlockTypes();
1866 const installableBlocks = downloadableBlocks.filter(({
1867 name
1868 }) => {
1869 // Check if the block has just been installed, in which case it
1870 // should still show in the list to avoid suddenly disappearing.
1871 // `installedBlockTypes` only returns blocks stored in state
1872 // immediately after installation, not all installed blocks.
1873 const isJustInstalled = installedBlockTypes.some(blockType => blockType.name === name);
1874 const isPreviouslyInstalled = (0,external_wp_blocks_namespaceObject.getBlockType)(name);
1875 return isJustInstalled || !isPreviouslyInstalled;
1876 });
1877
1878 // Keep identity of the `downloadableBlocks` array if nothing was filtered out
1879 if (installableBlocks.length !== downloadableBlocks.length) {
1880 downloadableBlocks = installableBlocks;
1881 }
1882
1883 // Return identical empty array when there are no blocks
1884 if (downloadableBlocks.length === 0) {
1885 downloadableBlocks = EMPTY_ARRAY;
1886 }
1887 }
1888 return {
1889 hasPermission,
1890 downloadableBlocks,
1891 isLoading: isRequestingDownloadableBlocks(filterValue)
1892 };
1893 }, [filterValue]);
1894 function DownloadableBlocksPanel({
1895 onSelect,
1896 onHover,
1897 hasLocalBlocks,
1898 isTyping,
1899 filterValue
1900 }) {
1901 const {
1902 hasPermission,
1903 downloadableBlocks,
1904 isLoading
1905 } = useDownloadableBlocks(filterValue);
1906 if (hasPermission === undefined || isLoading || isTyping) {
1907 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1908 children: [hasPermission && !hasLocalBlocks && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1909 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("p", {
1910 className: "block-directory-downloadable-blocks-panel__no-local",
1911 children: (0,external_wp_i18n_namespaceObject.__)('No results available from your installed blocks.')
1912 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
1913 className: "block-editor-inserter__quick-inserter-separator"
1914 })]
1915 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
1916 className: "block-directory-downloadable-blocks-panel has-blocks-loading",
1917 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Spinner, {})
1918 })]
1919 });
1920 }
1921 if (false === hasPermission) {
1922 if (!hasLocalBlocks) {
1923 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(no_results, {});
1924 }
1925 return null;
1926 }
1927 if (downloadableBlocks.length === 0) {
1928 return hasLocalBlocks ? null : /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(no_results, {});
1929 }
1930 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(inserter_panel, {
1931 downloadableItems: downloadableBlocks,
1932 hasLocalBlocks: hasLocalBlocks,
1933 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(downloadable_blocks_list, {
1934 items: downloadableBlocks,
1935 onSelect: onSelect,
1936 onHover: onHover
1937 })
1938 });
1939 }
1940
1941 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.js
1942 /**
1943 * WordPress dependencies
1944 */
1945
1946
1947
1948
1949 /**
1950 * Internal dependencies
1951 */
1952
1953
1954 function InserterMenuDownloadableBlocksPanel() {
1955 const [debouncedFilterValue, setFilterValue] = (0,external_wp_element_namespaceObject.useState)('');
1956 const debouncedSetFilterValue = (0,external_wp_compose_namespaceObject.debounce)(setFilterValue, 400);
1957 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.__unstableInserterMenuExtension, {
1958 children: ({
1959 onSelect,
1960 onHover,
1961 filterValue,
1962 hasItems
1963 }) => {
1964 if (debouncedFilterValue !== filterValue) {
1965 debouncedSetFilterValue(filterValue);
1966 }
1967 if (!debouncedFilterValue) {
1968 return null;
1969 }
1970 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(DownloadableBlocksPanel, {
1971 onSelect: onSelect,
1972 onHover: onHover,
1973 filterValue: debouncedFilterValue,
1974 hasLocalBlocks: hasItems,
1975 isTyping: filterValue !== debouncedFilterValue
1976 });
1977 }
1978 });
1979 }
1980 /* harmony default export */ const inserter_menu_downloadable_blocks_panel = (InserterMenuDownloadableBlocksPanel);
1981
1982 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/compact-list/index.js
1983 /**
1984 * WordPress dependencies
1985 */
1986
1987
1988 /**
1989 * Internal dependencies
1990 */
1991
1992
1993
1994 function CompactList({
1995 items
1996 }) {
1997 if (!items.length) {
1998 return null;
1999 }
2000 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("ul", {
2001 className: "block-directory-compact-list",
2002 children: items.map(({
2003 icon,
2004 id,
2005 title,
2006 author
2007 }) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("li", {
2008 className: "block-directory-compact-list__item",
2009 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(downloadable_block_icon, {
2010 icon: icon,
2011 title: title
2012 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
2013 className: "block-directory-compact-list__item-details",
2014 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
2015 className: "block-directory-compact-list__item-title",
2016 children: title
2017 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
2018 className: "block-directory-compact-list__item-author",
2019 children: (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: Name of the block author. */
2020 (0,external_wp_i18n_namespaceObject.__)('By %s'), author)
2021 })]
2022 })]
2023 }, id))
2024 });
2025 }
2026
2027 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/plugins/installed-blocks-pre-publish-panel/index.js
2028 /**
2029 * WordPress dependencies
2030 */
2031
2032
2033
2034
2035
2036 /**
2037 * Internal dependencies
2038 */
2039
2040
2041
2042
2043 function InstalledBlocksPrePublishPanel() {
2044 const newBlockTypes = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).getNewBlockTypes(), []);
2045 if (!newBlockTypes.length) {
2046 return null;
2047 }
2048 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_editor_namespaceObject.PluginPrePublishPanel, {
2049 icon: block_default,
2050 title: (0,external_wp_i18n_namespaceObject.sprintf)(
2051 // translators: %d: number of blocks (number).
2052 (0,external_wp_i18n_namespaceObject._n)('Added: %d block', 'Added: %d blocks', newBlockTypes.length), newBlockTypes.length),
2053 initialOpen: true,
2054 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("p", {
2055 className: "installed-blocks-pre-publish-panel__copy",
2056 children: (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)
2057 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(CompactList, {
2058 items: newBlockTypes
2059 })]
2060 });
2061 }
2062
2063 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/plugins/get-install-missing/install-button.js
2064 /**
2065 * WordPress dependencies
2066 */
2067
2068
2069
2070
2071
2072
2073 /**
2074 * Internal dependencies
2075 */
2076
2077
2078 function InstallButton({
2079 attributes,
2080 block,
2081 clientId
2082 }) {
2083 const isInstallingBlock = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).isInstalling(block.id), [block.id]);
2084 const {
2085 installBlockType
2086 } = (0,external_wp_data_namespaceObject.useDispatch)(store);
2087 const {
2088 replaceBlock
2089 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
2090 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
2091 onClick: () => installBlockType(block).then(success => {
2092 if (success) {
2093 const blockType = (0,external_wp_blocks_namespaceObject.getBlockType)(block.name);
2094 const [originalBlock] = (0,external_wp_blocks_namespaceObject.parse)(attributes.originalContent);
2095 if (originalBlock && blockType) {
2096 replaceBlock(clientId, (0,external_wp_blocks_namespaceObject.createBlock)(blockType.name, originalBlock.attributes, originalBlock.innerBlocks));
2097 }
2098 }
2099 }),
2100 accessibleWhenDisabled: true,
2101 disabled: isInstallingBlock,
2102 isBusy: isInstallingBlock,
2103 variant: "primary",
2104 children: (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: block name */
2105 (0,external_wp_i18n_namespaceObject.__)('Install %s'), block.title)
2106 });
2107 }
2108
2109 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/plugins/get-install-missing/index.js
2110 /**
2111 * WordPress dependencies
2112 */
2113
2114
2115
2116
2117
2118
2119
2120
2121 /**
2122 * Internal dependencies
2123 */
2124
2125
2126
2127
2128 const getInstallMissing = OriginalComponent => props => {
2129 const {
2130 originalName
2131 } = props.attributes;
2132 // Disable reason: This is a valid component, but it's mistaken for a callback.
2133 // eslint-disable-next-line react-hooks/rules-of-hooks
2134 const {
2135 block,
2136 hasPermission
2137 } = (0,external_wp_data_namespaceObject.useSelect)(select => {
2138 const {
2139 getDownloadableBlocks
2140 } = select(store);
2141 const blocks = getDownloadableBlocks('block:' + originalName).filter(({
2142 name
2143 }) => originalName === name);
2144 return {
2145 hasPermission: select(external_wp_coreData_namespaceObject.store).canUser('read', 'block-directory/search'),
2146 block: blocks.length && blocks[0]
2147 };
2148 }, [originalName]);
2149
2150 // The user can't install blocks, or the block isn't available for download.
2151 if (!hasPermission || !block) {
2152 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(OriginalComponent, {
2153 ...props
2154 });
2155 }
2156 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ModifiedWarning, {
2157 ...props,
2158 originalBlock: block
2159 });
2160 };
2161 const ModifiedWarning = ({
2162 originalBlock,
2163 ...props
2164 }) => {
2165 const {
2166 originalName,
2167 originalUndelimitedContent,
2168 clientId
2169 } = props.attributes;
2170 const {
2171 replaceBlock
2172 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
2173 const convertToHTML = () => {
2174 replaceBlock(props.clientId, (0,external_wp_blocks_namespaceObject.createBlock)('core/html', {
2175 content: originalUndelimitedContent
2176 }));
2177 };
2178 const hasContent = !!originalUndelimitedContent;
2179 const hasHTMLBlock = (0,external_wp_data_namespaceObject.useSelect)(select => {
2180 const {
2181 canInsertBlockType,
2182 getBlockRootClientId
2183 } = select(external_wp_blockEditor_namespaceObject.store);
2184 return canInsertBlockType('core/html', getBlockRootClientId(clientId));
2185 }, [clientId]);
2186 let messageHTML = (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: block name */
2187 (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);
2188 const actions = [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(InstallButton, {
2189 block: originalBlock,
2190 attributes: props.attributes,
2191 clientId: props.clientId
2192 }, "install")];
2193 if (hasContent && hasHTMLBlock) {
2194 messageHTML = (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: block name */
2195 (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);
2196 actions.push( /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
2197 onClick: convertToHTML,
2198 variant: "tertiary",
2199 children: (0,external_wp_i18n_namespaceObject.__)('Keep as HTML')
2200 }, "convert"));
2201 }
2202 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
2203 ...(0,external_wp_blockEditor_namespaceObject.useBlockProps)(),
2204 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.Warning, {
2205 actions: actions,
2206 children: messageHTML
2207 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_element_namespaceObject.RawHTML, {
2208 children: originalUndelimitedContent
2209 })]
2210 });
2211 };
2212 /* harmony default export */ const get_install_missing = (getInstallMissing);
2213
2214 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/plugins/index.js
2215 /**
2216 * WordPress dependencies
2217 */
2218
2219
2220
2221 /**
2222 * Internal dependencies
2223 */
2224
2225
2226
2227
2228
2229
2230
2231 (0,external_wp_plugins_namespaceObject.registerPlugin)('block-directory', {
2232 render() {
2233 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
2234 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(AutoBlockUninstaller, {}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(inserter_menu_downloadable_blocks_panel, {}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(InstalledBlocksPrePublishPanel, {})]
2235 });
2236 }
2237 });
2238 (0,external_wp_hooks_namespaceObject.addFilter)('blocks.registerBlockType', 'block-directory/fallback', (settings, name) => {
2239 if (name !== 'core/missing') {
2240 return settings;
2241 }
2242 settings.edit = get_install_missing(settings.edit);
2243 return settings;
2244 });
2245
2246 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/index.js
2247 /**
2248 * Internal dependencies
2249 */
2250
2251
2252
2253 (window.wp = window.wp || {}).blockDirectory = __webpack_exports__;
2254 /******/ })()
2255 ;