PluginProbe
Gutenberg / 13.5.1
Gutenberg v13.5.1
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 13.5.1, at build/block-directory/index.js

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