PluginProbe
Gutenberg / 13.0.0
Gutenberg v13.0.0
24.1.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 All 404 releases
gutenberg / build / block-directory / index.js

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

1,796 lines 56.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (function() { // webpackBootstrap
2 /******/ "use strict";
3 /******/ // The require scope
4 /******/ var __webpack_require__ = {};
5 /******/
6 /************************************************************************/
7 /******/ /* webpack/runtime/compat get default export */
8 /******/ !function() {
9 /******/ // getDefaultExport function for compatibility with non-harmony modules
10 /******/ __webpack_require__.n = function(module) {
11 /******/ var getter = module && module.__esModule ?
12 /******/ function() { return module['default']; } :
13 /******/ function() { return module; };
14 /******/ __webpack_require__.d(getter, { a: getter });
15 /******/ return getter;
16 /******/ };
17 /******/ }();
18 /******/
19 /******/ /* webpack/runtime/define property getters */
20 /******/ !function() {
21 /******/ // define getter functions for harmony exports
22 /******/ __webpack_require__.d = function(exports, definition) {
23 /******/ for(var key in definition) {
24 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
25 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
26 /******/ }
27 /******/ }
28 /******/ };
29 /******/ }();
30 /******/
31 /******/ /* webpack/runtime/hasOwnProperty shorthand */
32 /******/ !function() {
33 /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
34 /******/ }();
35 /******/
36 /******/ /* webpack/runtime/make namespace object */
37 /******/ !function() {
38 /******/ // define __esModule on exports
39 /******/ __webpack_require__.r = function(exports) {
40 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
41 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
42 /******/ }
43 /******/ Object.defineProperty(exports, '__esModule', { value: true });
44 /******/ };
45 /******/ }();
46 /******/
47 /************************************************************************/
48 var __webpack_exports__ = {};
49 // ESM COMPAT FLAG
50 __webpack_require__.r(__webpack_exports__);
51
52 // EXPORTS
53 __webpack_require__.d(__webpack_exports__, {
54 "store": function() { return /* 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": function() { return getDownloadableBlocks; },
62 "getErrorNoticeForBlock": function() { return getErrorNoticeForBlock; },
63 "getErrorNotices": function() { return getErrorNotices; },
64 "getInstalledBlockTypes": function() { return getInstalledBlockTypes; },
65 "getNewBlockTypes": function() { return getNewBlockTypes; },
66 "getUnusedBlockTypes": function() { return getUnusedBlockTypes; },
67 "isInstalling": function() { return isInstalling; },
68 "isRequestingDownloadableBlocks": function() { return 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": function() { return addInstalledBlockType; },
76 "clearErrorNotice": function() { return clearErrorNotice; },
77 "fetchDownloadableBlocks": function() { return fetchDownloadableBlocks; },
78 "installBlockType": function() { return installBlockType; },
79 "receiveDownloadableBlocks": function() { return receiveDownloadableBlocks; },
80 "removeInstalledBlockType": function() { return removeInstalledBlockType; },
81 "setErrorNotice": function() { return setErrorNotice; },
82 "setIsInstalling": function() { return setIsInstalling; },
83 "uninstallBlockType": function() { return 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": function() { return resolvers_getDownloadableBlocks; }
91 });
92
93 ;// CONCATENATED MODULE: external ["wp","element"]
94 var external_wp_element_namespaceObject = window["wp"]["element"];
95 ;// CONCATENATED MODULE: external ["wp","plugins"]
96 var external_wp_plugins_namespaceObject = window["wp"]["plugins"];
97 ;// CONCATENATED MODULE: external ["wp","hooks"]
98 var external_wp_hooks_namespaceObject = window["wp"]["hooks"];
99 ;// CONCATENATED MODULE: external ["wp","blocks"]
100 var external_wp_blocks_namespaceObject = window["wp"]["blocks"];
101 ;// CONCATENATED MODULE: external ["wp","data"]
102 var external_wp_data_namespaceObject = window["wp"]["data"];
103 ;// CONCATENATED MODULE: external ["wp","editor"]
104 var external_wp_editor_namespaceObject = window["wp"]["editor"];
105 ;// CONCATENATED MODULE: external "lodash"
106 var 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 */ var reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
215 downloadableBlocks,
216 blockManagement,
217 errorNotices
218 }));
219
220 ;// CONCATENATED MODULE: external ["wp","blockEditor"]
221 var 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 var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
374 ;// CONCATENATED MODULE: external ["wp","apiFetch"]
375 var 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 var external_wp_notices_namespaceObject = window["wp"]["notices"];
379 ;// CONCATENATED MODULE: external ["wp","url"]
380 var 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 var external_wp_components_namespaceObject = window["wp"]["components"];
860 ;// CONCATENATED MODULE: external ["wp","compose"]
861 var external_wp_compose_namespaceObject = window["wp"]["compose"];
862 ;// CONCATENATED MODULE: external ["wp","coreData"]
863 var 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 var 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 */ var icon = (Icon);
915
916 ;// CONCATENATED MODULE: external ["wp","primitives"]
917 var 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 */ var 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 */ var 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 */ var 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 */ var 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 */ var 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 */ var 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 */ var 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 role: "option",
1190 as: external_wp_components_namespaceObject.Button
1191 }, composite, {
1192 className: "block-directory-downloadable-block-list-item",
1193 onClick: event => {
1194 event.preventDefault();
1195 onClick();
1196 },
1197 isBusy: isInstalling,
1198 disabled: isInstalling || !isInstallable,
1199 label: getDownloadableBlockLabel(item, {
1200 hasNotice,
1201 isInstalled,
1202 isInstalling
1203 }),
1204 showTooltip: true,
1205 tooltipPosition: "top center"
1206 }), (0,external_wp_element_namespaceObject.createElement)("div", {
1207 className: "block-directory-downloadable-block-list-item__icon"
1208 }, (0,external_wp_element_namespaceObject.createElement)(downloadable_block_icon, {
1209 icon: icon,
1210 title: title
1211 }), isInstalling ? (0,external_wp_element_namespaceObject.createElement)("span", {
1212 className: "block-directory-downloadable-block-list-item__spinner"
1213 }, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Spinner, null)) : (0,external_wp_element_namespaceObject.createElement)(block_ratings, {
1214 rating: rating
1215 })), (0,external_wp_element_namespaceObject.createElement)("span", {
1216 className: "block-directory-downloadable-block-list-item__details"
1217 }, (0,external_wp_element_namespaceObject.createElement)("span", {
1218 className: "block-directory-downloadable-block-list-item__title"
1219 }, (0,external_wp_element_namespaceObject.createInterpolateElement)((0,external_wp_i18n_namespaceObject.sprintf)(
1220 /* translators: %1$s: block title, %2$s: author name. */
1221 (0,external_wp_i18n_namespaceObject.__)('%1$s <span>by %2$s</span>'), (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(title), author), {
1222 span: (0,external_wp_element_namespaceObject.createElement)("span", {
1223 className: "block-directory-downloadable-block-list-item__author"
1224 })
1225 })), hasNotice ? (0,external_wp_element_namespaceObject.createElement)(downloadable_block_notice, {
1226 block: item
1227 }) : (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)("span", {
1228 className: "block-directory-downloadable-block-list-item__desc"
1229 }, !!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')))));
1230 }
1231
1232 /* harmony default export */ var downloadable_block_list_item = (DownloadableBlockListItem);
1233
1234 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/downloadable-blocks-list/index.js
1235
1236
1237
1238 /**
1239 * External dependencies
1240 */
1241
1242 /**
1243 * WordPress dependencies
1244 */
1245
1246
1247
1248
1249
1250 /**
1251 * Internal dependencies
1252 */
1253
1254
1255
1256
1257 function DownloadableBlocksList(_ref) {
1258 let {
1259 items,
1260 onHover = external_lodash_namespaceObject.noop,
1261 onSelect
1262 } = _ref;
1263 const composite = (0,external_wp_components_namespaceObject.__unstableUseCompositeState)();
1264 const {
1265 installBlockType
1266 } = (0,external_wp_data_namespaceObject.useDispatch)(store);
1267
1268 if (!items.length) {
1269 return null;
1270 }
1271
1272 return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.__unstableComposite, _extends({}, composite, {
1273 role: "listbox",
1274 className: "block-directory-downloadable-blocks-list",
1275 "aria-label": (0,external_wp_i18n_namespaceObject.__)('Blocks available for install')
1276 }), items.map(item => {
1277 return (0,external_wp_element_namespaceObject.createElement)(downloadable_block_list_item, {
1278 key: item.id,
1279 composite: composite,
1280 onClick: () => {
1281 // Check if the block is registered (`getBlockType`
1282 // will return an object). If so, insert the block.
1283 // This prevents installing existing plugins.
1284 if ((0,external_wp_blocks_namespaceObject.getBlockType)(item.name)) {
1285 onSelect(item);
1286 } else {
1287 installBlockType(item).then(success => {
1288 if (success) {
1289 onSelect(item);
1290 }
1291 });
1292 }
1293
1294 onHover(null);
1295 },
1296 onHover: onHover,
1297 item: item
1298 });
1299 }));
1300 }
1301
1302 /* harmony default export */ var downloadable_blocks_list = (DownloadableBlocksList);
1303
1304 ;// CONCATENATED MODULE: external ["wp","a11y"]
1305 var external_wp_a11y_namespaceObject = window["wp"]["a11y"];
1306 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/downloadable-blocks-panel/inserter-panel.js
1307
1308
1309 /**
1310 * WordPress dependencies
1311 */
1312
1313
1314
1315
1316 function DownloadableBlocksInserterPanel(_ref) {
1317 let {
1318 children,
1319 downloadableItems,
1320 hasLocalBlocks
1321 } = _ref;
1322 const count = downloadableItems.length;
1323 (0,external_wp_element_namespaceObject.useEffect)(() => {
1324 (0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.sprintf)(
1325 /* translators: %d: number of available blocks. */
1326 (0,external_wp_i18n_namespaceObject._n)('%d additional block is available to install.', '%d additional blocks are available to install.', count), count));
1327 }, [count]);
1328 return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, !hasLocalBlocks && (0,external_wp_element_namespaceObject.createElement)("p", {
1329 className: "block-directory-downloadable-blocks-panel__no-local"
1330 }, (0,external_wp_i18n_namespaceObject.__)('No results available from your installed blocks.')), (0,external_wp_element_namespaceObject.createElement)("div", {
1331 className: "block-editor-inserter__quick-inserter-separator"
1332 }), (0,external_wp_element_namespaceObject.createElement)("div", {
1333 className: "block-directory-downloadable-blocks-panel"
1334 }, (0,external_wp_element_namespaceObject.createElement)("div", {
1335 className: "block-directory-downloadable-blocks-panel__header"
1336 }, (0,external_wp_element_namespaceObject.createElement)("h2", {
1337 className: "block-directory-downloadable-blocks-panel__title"
1338 }, (0,external_wp_i18n_namespaceObject.__)('Available to install')), (0,external_wp_element_namespaceObject.createElement)("p", {
1339 className: "block-directory-downloadable-blocks-panel__description"
1340 }, (0,external_wp_i18n_namespaceObject.__)('Select a block to install and add it to your post.'))), children));
1341 }
1342
1343 /* harmony default export */ var inserter_panel = (DownloadableBlocksInserterPanel);
1344
1345 ;// CONCATENATED MODULE: ./packages/icons/build-module/library/block-default.js
1346
1347
1348 /**
1349 * WordPress dependencies
1350 */
1351
1352 const blockDefault = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, {
1353 xmlns: "http://www.w3.org/2000/svg",
1354 viewBox: "0 0 24 24"
1355 }, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, {
1356 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"
1357 }));
1358 /* harmony default export */ var block_default = (blockDefault);
1359
1360 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/downloadable-blocks-panel/no-results.js
1361
1362
1363 /**
1364 * WordPress dependencies
1365 */
1366
1367
1368
1369 function DownloadableBlocksNoResults() {
1370 return (0,external_wp_element_namespaceObject.createElement)("div", {
1371 className: "block-editor-inserter__no-results"
1372 }, (0,external_wp_element_namespaceObject.createElement)(icon, {
1373 className: "block-editor-inserter__no-results-icon",
1374 icon: block_default
1375 }), (0,external_wp_element_namespaceObject.createElement)("p", null, (0,external_wp_i18n_namespaceObject.__)('No results found.')));
1376 }
1377
1378 /* harmony default export */ var no_results = (DownloadableBlocksNoResults);
1379
1380 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/downloadable-blocks-panel/index.js
1381
1382
1383 /**
1384 * WordPress dependencies
1385 */
1386
1387
1388
1389
1390
1391
1392 /**
1393 * Internal dependencies
1394 */
1395
1396
1397
1398
1399
1400
1401 function DownloadableBlocksPanel(_ref) {
1402 let {
1403 downloadableItems,
1404 onSelect,
1405 onHover,
1406 hasLocalBlocks,
1407 hasPermission,
1408 isLoading,
1409 isTyping
1410 } = _ref;
1411
1412 if (typeof hasPermission === 'undefined' || isLoading || isTyping) {
1413 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", {
1414 className: "block-directory-downloadable-blocks-panel__no-local"
1415 }, (0,external_wp_i18n_namespaceObject.__)('No results available from your installed blocks.')), (0,external_wp_element_namespaceObject.createElement)("div", {
1416 className: "block-editor-inserter__quick-inserter-separator"
1417 })), (0,external_wp_element_namespaceObject.createElement)("div", {
1418 className: "block-directory-downloadable-blocks-panel has-blocks-loading"
1419 }, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Spinner, null)));
1420 }
1421
1422 if (false === hasPermission) {
1423 if (!hasLocalBlocks) {
1424 return (0,external_wp_element_namespaceObject.createElement)(no_results, null);
1425 }
1426
1427 return null;
1428 }
1429
1430 return !!downloadableItems.length ? (0,external_wp_element_namespaceObject.createElement)(inserter_panel, {
1431 downloadableItems: downloadableItems,
1432 hasLocalBlocks: hasLocalBlocks
1433 }, (0,external_wp_element_namespaceObject.createElement)(downloadable_blocks_list, {
1434 items: downloadableItems,
1435 onSelect: onSelect,
1436 onHover: onHover
1437 })) : !hasLocalBlocks && (0,external_wp_element_namespaceObject.createElement)(no_results, null);
1438 }
1439
1440 /* harmony default export */ var downloadable_blocks_panel = ((0,external_wp_compose_namespaceObject.compose)([(0,external_wp_data_namespaceObject.withSelect)((select, _ref2) => {
1441 let {
1442 filterValue,
1443 rootClientId = null
1444 } = _ref2;
1445 const {
1446 getDownloadableBlocks,
1447 isRequestingDownloadableBlocks
1448 } = select(store);
1449 const {
1450 canInsertBlockType
1451 } = select(external_wp_blockEditor_namespaceObject.store);
1452 const hasPermission = select(external_wp_coreData_namespaceObject.store).canUser('read', 'block-directory/search');
1453
1454 function getInstallableBlocks(term) {
1455 return getDownloadableBlocks(term).filter(block => canInsertBlockType(block, rootClientId, true));
1456 }
1457
1458 const downloadableItems = hasPermission ? getInstallableBlocks(filterValue) : [];
1459 const isLoading = isRequestingDownloadableBlocks(filterValue);
1460 return {
1461 downloadableItems,
1462 hasPermission,
1463 isLoading
1464 };
1465 })])(DownloadableBlocksPanel));
1466
1467 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.js
1468
1469
1470 /**
1471 * External dependencies
1472 */
1473
1474 /**
1475 * WordPress dependencies
1476 */
1477
1478
1479
1480 /**
1481 * Internal dependencies
1482 */
1483
1484
1485
1486 function InserterMenuDownloadableBlocksPanel() {
1487 const [debouncedFilterValue, setFilterValue] = (0,external_wp_element_namespaceObject.useState)('');
1488 const debouncedSetFilterValue = (0,external_lodash_namespaceObject.debounce)(setFilterValue, 400);
1489 return (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.__unstableInserterMenuExtension, null, _ref => {
1490 let {
1491 onSelect,
1492 onHover,
1493 filterValue,
1494 hasItems,
1495 rootClientId
1496 } = _ref;
1497
1498 if (debouncedFilterValue !== filterValue) {
1499 debouncedSetFilterValue(filterValue);
1500 }
1501
1502 if (!debouncedFilterValue) {
1503 return null;
1504 }
1505
1506 return (0,external_wp_element_namespaceObject.createElement)(downloadable_blocks_panel, {
1507 onSelect: onSelect,
1508 onHover: onHover,
1509 rootClientId: rootClientId,
1510 filterValue: debouncedFilterValue,
1511 hasLocalBlocks: hasItems,
1512 isTyping: filterValue !== debouncedFilterValue
1513 });
1514 });
1515 }
1516
1517 /* harmony default export */ var inserter_menu_downloadable_blocks_panel = (InserterMenuDownloadableBlocksPanel);
1518
1519 ;// CONCATENATED MODULE: external ["wp","editPost"]
1520 var external_wp_editPost_namespaceObject = window["wp"]["editPost"];
1521 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/components/compact-list/index.js
1522
1523
1524 /**
1525 * WordPress dependencies
1526 */
1527
1528 /**
1529 * Internal dependencies
1530 */
1531
1532
1533 function CompactList(_ref) {
1534 let {
1535 items
1536 } = _ref;
1537
1538 if (!items.length) {
1539 return null;
1540 }
1541
1542 return (0,external_wp_element_namespaceObject.createElement)("ul", {
1543 className: "block-directory-compact-list"
1544 }, items.map(_ref2 => {
1545 let {
1546 icon,
1547 id,
1548 title,
1549 author
1550 } = _ref2;
1551 return (0,external_wp_element_namespaceObject.createElement)("li", {
1552 key: id,
1553 className: "block-directory-compact-list__item"
1554 }, (0,external_wp_element_namespaceObject.createElement)(downloadable_block_icon, {
1555 icon: icon,
1556 title: title
1557 }), (0,external_wp_element_namespaceObject.createElement)("div", {
1558 className: "block-directory-compact-list__item-details"
1559 }, (0,external_wp_element_namespaceObject.createElement)("div", {
1560 className: "block-directory-compact-list__item-title"
1561 }, title), (0,external_wp_element_namespaceObject.createElement)("div", {
1562 className: "block-directory-compact-list__item-author"
1563 }, (0,external_wp_i18n_namespaceObject.sprintf)(
1564 /* translators: %s: Name of the block author. */
1565 (0,external_wp_i18n_namespaceObject.__)('By %s'), author))));
1566 }));
1567 }
1568
1569 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/plugins/installed-blocks-pre-publish-panel/index.js
1570
1571
1572 /**
1573 * WordPress dependencies
1574 */
1575
1576
1577
1578
1579 /**
1580 * Internal dependencies
1581 */
1582
1583
1584
1585 function InstalledBlocksPrePublishPanel() {
1586 const newBlockTypes = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).getNewBlockTypes(), []);
1587
1588 if (!newBlockTypes.length) {
1589 return null;
1590 }
1591
1592 return (0,external_wp_element_namespaceObject.createElement)(external_wp_editPost_namespaceObject.PluginPrePublishPanel, {
1593 icon: block_default,
1594 title: (0,external_wp_i18n_namespaceObject.sprintf)( // translators: %d: number of blocks (number).
1595 (0,external_wp_i18n_namespaceObject._n)('Added: %d block', 'Added: %d blocks', newBlockTypes.length), newBlockTypes.length),
1596 initialOpen: true
1597 }, (0,external_wp_element_namespaceObject.createElement)("p", {
1598 className: "installed-blocks-pre-publish-panel__copy"
1599 }, (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, {
1600 items: newBlockTypes
1601 }));
1602 }
1603
1604 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/plugins/get-install-missing/install-button.js
1605
1606
1607 /**
1608 * WordPress dependencies
1609 */
1610
1611
1612
1613
1614
1615 /**
1616 * Internal dependencies
1617 */
1618
1619
1620 function InstallButton(_ref) {
1621 let {
1622 attributes,
1623 block,
1624 clientId
1625 } = _ref;
1626 const isInstallingBlock = (0,external_wp_data_namespaceObject.useSelect)(select => select(store).isInstalling(block.id), [block.id]);
1627 const {
1628 installBlockType
1629 } = (0,external_wp_data_namespaceObject.useDispatch)(store);
1630 const {
1631 replaceBlock
1632 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
1633 return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, {
1634 onClick: () => installBlockType(block).then(success => {
1635 if (success) {
1636 const blockType = (0,external_wp_blocks_namespaceObject.getBlockType)(block.name);
1637 const [originalBlock] = (0,external_wp_blocks_namespaceObject.parse)(attributes.originalContent);
1638
1639 if (originalBlock && blockType) {
1640 replaceBlock(clientId, (0,external_wp_blocks_namespaceObject.createBlock)(blockType.name, originalBlock.attributes, originalBlock.innerBlocks));
1641 }
1642 }
1643 }),
1644 disabled: isInstallingBlock,
1645 isBusy: isInstallingBlock,
1646 variant: "primary"
1647 }, (0,external_wp_i18n_namespaceObject.sprintf)(
1648 /* translators: %s: block name */
1649 (0,external_wp_i18n_namespaceObject.__)('Install %s'), block.title));
1650 }
1651
1652 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/plugins/get-install-missing/index.js
1653
1654
1655
1656 /**
1657 * WordPress dependencies
1658 */
1659
1660
1661
1662
1663
1664
1665
1666 /**
1667 * Internal dependencies
1668 */
1669
1670
1671
1672
1673 const getInstallMissing = OriginalComponent => props => {
1674 const {
1675 originalName
1676 } = props.attributes; // Disable reason: This is a valid component, but it's mistaken for a callback.
1677 // eslint-disable-next-line react-hooks/rules-of-hooks
1678
1679 const {
1680 block,
1681 hasPermission
1682 } = (0,external_wp_data_namespaceObject.useSelect)(select => {
1683 const {
1684 getDownloadableBlocks
1685 } = select(store);
1686 const blocks = getDownloadableBlocks('block:' + originalName).filter(_ref => {
1687 let {
1688 name
1689 } = _ref;
1690 return originalName === name;
1691 });
1692 return {
1693 hasPermission: select(external_wp_coreData_namespaceObject.store).canUser('read', 'block-directory/search'),
1694 block: blocks.length && blocks[0]
1695 };
1696 }, [originalName]); // The user can't install blocks, or the block isn't available for download.
1697
1698 if (!hasPermission || !block) {
1699 return (0,external_wp_element_namespaceObject.createElement)(OriginalComponent, props);
1700 }
1701
1702 return (0,external_wp_element_namespaceObject.createElement)(ModifiedWarning, _extends({}, props, {
1703 originalBlock: block
1704 }));
1705 };
1706
1707 const ModifiedWarning = _ref2 => {
1708 let {
1709 originalBlock,
1710 ...props
1711 } = _ref2;
1712 const {
1713 originalName,
1714 originalUndelimitedContent
1715 } = props.attributes;
1716 const {
1717 replaceBlock
1718 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
1719
1720 const convertToHTML = () => {
1721 replaceBlock(props.clientId, (0,external_wp_blocks_namespaceObject.createBlock)('core/html', {
1722 content: originalUndelimitedContent
1723 }));
1724 };
1725
1726 const hasContent = !!originalUndelimitedContent;
1727 const hasHTMLBlock = (0,external_wp_blocks_namespaceObject.getBlockType)('core/html');
1728 let messageHTML = (0,external_wp_i18n_namespaceObject.sprintf)(
1729 /* translators: %s: block name */
1730 (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);
1731 const actions = [(0,external_wp_element_namespaceObject.createElement)(InstallButton, {
1732 key: "install",
1733 block: originalBlock,
1734 attributes: props.attributes,
1735 clientId: props.clientId
1736 })];
1737
1738 if (hasContent && hasHTMLBlock) {
1739 messageHTML = (0,external_wp_i18n_namespaceObject.sprintf)(
1740 /* translators: %s: block name */
1741 (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);
1742 actions.push((0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, {
1743 key: "convert",
1744 onClick: convertToHTML,
1745 variant: "link"
1746 }, (0,external_wp_i18n_namespaceObject.__)('Keep as HTML')));
1747 }
1748
1749 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, {
1750 actions: actions
1751 }, messageHTML), (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.RawHTML, null, originalUndelimitedContent));
1752 };
1753
1754 /* harmony default export */ var get_install_missing = (getInstallMissing);
1755
1756 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/plugins/index.js
1757
1758
1759 /**
1760 * WordPress dependencies
1761 */
1762
1763
1764 /**
1765 * Internal dependencies
1766 */
1767
1768
1769
1770
1771
1772 (0,external_wp_plugins_namespaceObject.registerPlugin)('block-directory', {
1773 render() {
1774 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));
1775 }
1776
1777 });
1778 (0,external_wp_hooks_namespaceObject.addFilter)('blocks.registerBlockType', 'block-directory/fallback', (settings, name) => {
1779 if (name !== 'core/missing') {
1780 return settings;
1781 }
1782
1783 settings.edit = get_install_missing(settings.edit);
1784 return settings;
1785 });
1786
1787 ;// CONCATENATED MODULE: ./packages/block-directory/build-module/index.js
1788 /**
1789 * Internal dependencies
1790 */
1791
1792
1793
1794 (window.wp = window.wp || {}).blockDirectory = __webpack_exports__;
1795 /******/ })()
1796 ;