PluginProbe
Gutenberg / 22.3.0
Gutenberg v22.3.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 7.4.0 All 402 releases
gutenberg / build / scripts / block-directory / index.js

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

1,430 lines 55.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var wp;
2 (wp ||= {}).blockDirectory = (() => {
3 var __create = Object.create;
4 var __defProp = Object.defineProperty;
5 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6 var __getOwnPropNames = Object.getOwnPropertyNames;
7 var __getProtoOf = Object.getPrototypeOf;
8 var __hasOwnProp = Object.prototype.hasOwnProperty;
9 var __commonJS = (cb, mod) => function __require() {
10 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11 };
12 var __export = (target, all) => {
13 for (var name in all)
14 __defProp(target, name, { get: all[name], enumerable: true });
15 };
16 var __copyProps = (to, from, except, desc) => {
17 if (from && typeof from === "object" || typeof from === "function") {
18 for (let key of __getOwnPropNames(from))
19 if (!__hasOwnProp.call(to, key) && key !== except)
20 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21 }
22 return to;
23 };
24 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25 // If the importer is in node compatibility mode or this is not an ESM
26 // file that has been converted to a CommonJS file using a Babel-
27 // compatible transform (i.e. "__esModule" has not been set), then set
28 // "default" to the CommonJS "module.exports" for node compatibility.
29 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30 mod
31 ));
32 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
34 // package-external:@wordpress/plugins
35 var require_plugins = __commonJS({
36 "package-external:@wordpress/plugins"(exports, module) {
37 module.exports = window.wp.plugins;
38 }
39 });
40
41 // package-external:@wordpress/hooks
42 var require_hooks = __commonJS({
43 "package-external:@wordpress/hooks"(exports, module) {
44 module.exports = window.wp.hooks;
45 }
46 });
47
48 // package-external:@wordpress/blocks
49 var require_blocks = __commonJS({
50 "package-external:@wordpress/blocks"(exports, module) {
51 module.exports = window.wp.blocks;
52 }
53 });
54
55 // package-external:@wordpress/data
56 var require_data = __commonJS({
57 "package-external:@wordpress/data"(exports, module) {
58 module.exports = window.wp.data;
59 }
60 });
61
62 // package-external:@wordpress/element
63 var require_element = __commonJS({
64 "package-external:@wordpress/element"(exports, module) {
65 module.exports = window.wp.element;
66 }
67 });
68
69 // package-external:@wordpress/editor
70 var require_editor = __commonJS({
71 "package-external:@wordpress/editor"(exports, module) {
72 module.exports = window.wp.editor;
73 }
74 });
75
76 // package-external:@wordpress/block-editor
77 var require_block_editor = __commonJS({
78 "package-external:@wordpress/block-editor"(exports, module) {
79 module.exports = window.wp.blockEditor;
80 }
81 });
82
83 // package-external:@wordpress/i18n
84 var require_i18n = __commonJS({
85 "package-external:@wordpress/i18n"(exports, module) {
86 module.exports = window.wp.i18n;
87 }
88 });
89
90 // package-external:@wordpress/api-fetch
91 var require_api_fetch = __commonJS({
92 "package-external:@wordpress/api-fetch"(exports, module) {
93 module.exports = window.wp.apiFetch;
94 }
95 });
96
97 // package-external:@wordpress/notices
98 var require_notices = __commonJS({
99 "package-external:@wordpress/notices"(exports, module) {
100 module.exports = window.wp.notices;
101 }
102 });
103
104 // package-external:@wordpress/url
105 var require_url = __commonJS({
106 "package-external:@wordpress/url"(exports, module) {
107 module.exports = window.wp.url;
108 }
109 });
110
111 // package-external:@wordpress/compose
112 var require_compose = __commonJS({
113 "package-external:@wordpress/compose"(exports, module) {
114 module.exports = window.wp.compose;
115 }
116 });
117
118 // package-external:@wordpress/components
119 var require_components = __commonJS({
120 "package-external:@wordpress/components"(exports, module) {
121 module.exports = window.wp.components;
122 }
123 });
124
125 // package-external:@wordpress/core-data
126 var require_core_data = __commonJS({
127 "package-external:@wordpress/core-data"(exports, module) {
128 module.exports = window.wp.coreData;
129 }
130 });
131
132 // package-external:@wordpress/html-entities
133 var require_html_entities = __commonJS({
134 "package-external:@wordpress/html-entities"(exports, module) {
135 module.exports = window.wp.htmlEntities;
136 }
137 });
138
139 // package-external:@wordpress/primitives
140 var require_primitives = __commonJS({
141 "package-external:@wordpress/primitives"(exports, module) {
142 module.exports = window.wp.primitives;
143 }
144 });
145
146 // vendor-external:react/jsx-runtime
147 var require_jsx_runtime = __commonJS({
148 "vendor-external:react/jsx-runtime"(exports, module) {
149 module.exports = window.ReactJSXRuntime;
150 }
151 });
152
153 // package-external:@wordpress/a11y
154 var require_a11y = __commonJS({
155 "package-external:@wordpress/a11y"(exports, module) {
156 module.exports = window.wp.a11y;
157 }
158 });
159
160 // packages/block-directory/build-module/index.js
161 var index_exports = {};
162 __export(index_exports, {
163 store: () => store
164 });
165
166 // packages/block-directory/build-module/plugins/index.js
167 var import_plugins = __toESM(require_plugins());
168 var import_hooks = __toESM(require_hooks());
169
170 // packages/block-directory/build-module/components/auto-block-uninstaller/index.js
171 var import_blocks2 = __toESM(require_blocks());
172 var import_data4 = __toESM(require_data());
173 var import_element = __toESM(require_element());
174 var import_editor = __toESM(require_editor());
175
176 // packages/block-directory/build-module/store/index.js
177 var import_data3 = __toESM(require_data());
178
179 // packages/block-directory/build-module/store/reducer.js
180 var import_data = __toESM(require_data());
181 var downloadableBlocks = (state = {}, action) => {
182 switch (action.type) {
183 case "FETCH_DOWNLOADABLE_BLOCKS":
184 return {
185 ...state,
186 [action.filterValue]: {
187 isRequesting: true
188 }
189 };
190 case "RECEIVE_DOWNLOADABLE_BLOCKS":
191 return {
192 ...state,
193 [action.filterValue]: {
194 results: action.downloadableBlocks,
195 isRequesting: false
196 }
197 };
198 }
199 return state;
200 };
201 var blockManagement = (state = {
202 installedBlockTypes: [],
203 isInstalling: {}
204 }, action) => {
205 switch (action.type) {
206 case "ADD_INSTALLED_BLOCK_TYPE":
207 return {
208 ...state,
209 installedBlockTypes: [
210 ...state.installedBlockTypes,
211 action.item
212 ]
213 };
214 case "REMOVE_INSTALLED_BLOCK_TYPE":
215 return {
216 ...state,
217 installedBlockTypes: state.installedBlockTypes.filter(
218 (blockType) => blockType.name !== action.item.name
219 )
220 };
221 case "SET_INSTALLING_BLOCK":
222 return {
223 ...state,
224 isInstalling: {
225 ...state.isInstalling,
226 [action.blockId]: action.isInstalling
227 }
228 };
229 }
230 return state;
231 };
232 var errorNotices = (state = {}, action) => {
233 switch (action.type) {
234 case "SET_ERROR_NOTICE":
235 return {
236 ...state,
237 [action.blockId]: {
238 message: action.message,
239 isFatal: action.isFatal
240 }
241 };
242 case "CLEAR_ERROR_NOTICE":
243 const { [action.blockId]: blockId, ...restState } = state;
244 return restState;
245 }
246 return state;
247 };
248 var reducer_default = (0, import_data.combineReducers)({
249 downloadableBlocks,
250 blockManagement,
251 errorNotices
252 });
253
254 // packages/block-directory/build-module/store/selectors.js
255 var selectors_exports = {};
256 __export(selectors_exports, {
257 getDownloadableBlocks: () => getDownloadableBlocks,
258 getErrorNoticeForBlock: () => getErrorNoticeForBlock,
259 getErrorNotices: () => getErrorNotices,
260 getInstalledBlockTypes: () => getInstalledBlockTypes,
261 getNewBlockTypes: () => getNewBlockTypes,
262 getUnusedBlockTypes: () => getUnusedBlockTypes,
263 isInstalling: () => isInstalling,
264 isRequestingDownloadableBlocks: () => isRequestingDownloadableBlocks
265 });
266 var import_data2 = __toESM(require_data());
267 var import_block_editor = __toESM(require_block_editor());
268 var EMPTY_ARRAY = [];
269 function isRequestingDownloadableBlocks(state, filterValue) {
270 return state.downloadableBlocks[filterValue]?.isRequesting ?? false;
271 }
272 function getDownloadableBlocks(state, filterValue) {
273 return state.downloadableBlocks[filterValue]?.results ?? EMPTY_ARRAY;
274 }
275 function getInstalledBlockTypes(state) {
276 return state.blockManagement.installedBlockTypes;
277 }
278 var getNewBlockTypes = (0, import_data2.createRegistrySelector)(
279 (select) => (0, import_data2.createSelector)(
280 (state) => {
281 const installedBlockTypes = getInstalledBlockTypes(state);
282 if (!installedBlockTypes.length) {
283 return EMPTY_ARRAY;
284 }
285 const { getBlockName, getClientIdsWithDescendants } = select(import_block_editor.store);
286 const installedBlockNames = installedBlockTypes.map(
287 (blockType) => blockType.name
288 );
289 const foundBlockNames = getClientIdsWithDescendants().flatMap(
290 (clientId) => {
291 const blockName = getBlockName(clientId);
292 return installedBlockNames.includes(blockName) ? blockName : [];
293 }
294 );
295 const newBlockTypes = installedBlockTypes.filter(
296 (blockType) => foundBlockNames.includes(blockType.name)
297 );
298 return newBlockTypes.length > 0 ? newBlockTypes : EMPTY_ARRAY;
299 },
300 (state) => [
301 getInstalledBlockTypes(state),
302 select(import_block_editor.store).getClientIdsWithDescendants()
303 ]
304 )
305 );
306 var getUnusedBlockTypes = (0, import_data2.createRegistrySelector)(
307 (select) => (0, import_data2.createSelector)(
308 (state) => {
309 const installedBlockTypes = getInstalledBlockTypes(state);
310 if (!installedBlockTypes.length) {
311 return EMPTY_ARRAY;
312 }
313 const { getBlockName, getClientIdsWithDescendants } = select(import_block_editor.store);
314 const installedBlockNames = installedBlockTypes.map(
315 (blockType) => blockType.name
316 );
317 const foundBlockNames = getClientIdsWithDescendants().flatMap(
318 (clientId) => {
319 const blockName = getBlockName(clientId);
320 return installedBlockNames.includes(blockName) ? blockName : [];
321 }
322 );
323 const unusedBlockTypes = installedBlockTypes.filter(
324 (blockType) => !foundBlockNames.includes(blockType.name)
325 );
326 return unusedBlockTypes.length > 0 ? unusedBlockTypes : EMPTY_ARRAY;
327 },
328 (state) => [
329 getInstalledBlockTypes(state),
330 select(import_block_editor.store).getClientIdsWithDescendants()
331 ]
332 )
333 );
334 function isInstalling(state, blockId) {
335 return state.blockManagement.isInstalling[blockId] || false;
336 }
337 function getErrorNotices(state) {
338 return state.errorNotices;
339 }
340 function getErrorNoticeForBlock(state, blockId) {
341 return state.errorNotices[blockId];
342 }
343
344 // packages/block-directory/build-module/store/actions.js
345 var actions_exports = {};
346 __export(actions_exports, {
347 addInstalledBlockType: () => addInstalledBlockType,
348 clearErrorNotice: () => clearErrorNotice,
349 fetchDownloadableBlocks: () => fetchDownloadableBlocks,
350 installBlockType: () => installBlockType,
351 receiveDownloadableBlocks: () => receiveDownloadableBlocks,
352 removeInstalledBlockType: () => removeInstalledBlockType,
353 setErrorNotice: () => setErrorNotice,
354 setIsInstalling: () => setIsInstalling,
355 uninstallBlockType: () => uninstallBlockType
356 });
357 var import_blocks = __toESM(require_blocks());
358 var import_i18n = __toESM(require_i18n());
359 var import_api_fetch2 = __toESM(require_api_fetch());
360 var import_notices = __toESM(require_notices());
361 var import_url = __toESM(require_url());
362
363 // packages/block-directory/build-module/store/load-assets.js
364 var import_api_fetch = __toESM(require_api_fetch());
365 var loadAsset = (el) => {
366 return new Promise((resolve, reject) => {
367 const newNode = document.createElement(el.nodeName);
368 ["id", "rel", "src", "href", "type"].forEach((attr) => {
369 if (el[attr]) {
370 newNode[attr] = el[attr];
371 }
372 });
373 if (el.innerHTML) {
374 newNode.appendChild(document.createTextNode(el.innerHTML));
375 }
376 newNode.onload = () => resolve(true);
377 newNode.onerror = () => reject(new Error("Error loading asset."));
378 document.body.appendChild(newNode);
379 if ("link" === newNode.nodeName.toLowerCase() || "script" === newNode.nodeName.toLowerCase() && !newNode.src) {
380 resolve();
381 }
382 });
383 };
384 async function loadAssets() {
385 const response = await (0, import_api_fetch.default)({
386 url: document.location.href,
387 parse: false
388 });
389 const data = await response.text();
390 const doc = new window.DOMParser().parseFromString(data, "text/html");
391 const newAssets = Array.from(
392 doc.querySelectorAll('link[rel="stylesheet"],script')
393 ).filter((asset) => asset.id && !document.getElementById(asset.id));
394 for (const newAsset of newAssets) {
395 await loadAsset(newAsset);
396 }
397 }
398
399 // packages/block-directory/build-module/store/utils/get-plugin-url.js
400 function getPluginUrl(block) {
401 if (!block) {
402 return false;
403 }
404 const link = block.links["wp:plugin"] || block.links.self;
405 if (link && link.length) {
406 return link[0].href;
407 }
408 return false;
409 }
410
411 // packages/block-directory/build-module/store/actions.js
412 function fetchDownloadableBlocks(filterValue) {
413 return { type: "FETCH_DOWNLOADABLE_BLOCKS", filterValue };
414 }
415 function receiveDownloadableBlocks(downloadableBlocks2, filterValue) {
416 return {
417 type: "RECEIVE_DOWNLOADABLE_BLOCKS",
418 downloadableBlocks: downloadableBlocks2,
419 filterValue
420 };
421 }
422 var installBlockType = (block) => async ({ registry, dispatch }) => {
423 const { id, name } = block;
424 let success = false;
425 dispatch.clearErrorNotice(id);
426 try {
427 dispatch.setIsInstalling(id, true);
428 const url = getPluginUrl(block);
429 let links = {};
430 if (url) {
431 await (0, import_api_fetch2.default)({
432 method: "PUT",
433 url,
434 data: { status: "active" }
435 });
436 } else {
437 const response = await (0, import_api_fetch2.default)({
438 method: "POST",
439 path: "wp/v2/plugins",
440 data: { slug: id, status: "active" }
441 });
442 links = response._links;
443 }
444 dispatch.addInstalledBlockType({
445 ...block,
446 links: { ...block.links, ...links }
447 });
448 const metadataFields = [
449 "api_version",
450 "title",
451 "category",
452 "parent",
453 "ancestor",
454 "icon",
455 "description",
456 "keywords",
457 "attributes",
458 "provides_context",
459 "uses_context",
460 "selectors",
461 "supports",
462 "styles",
463 "example",
464 "variations",
465 "allowed_blocks",
466 "block_hooks"
467 ];
468 await (0, import_api_fetch2.default)({
469 path: (0, import_url.addQueryArgs)(`/wp/v2/block-types/${name}`, {
470 _fields: metadataFields
471 })
472 }).catch(() => {
473 }).then((response) => {
474 if (!response) {
475 return;
476 }
477 (0, import_blocks.unstable__bootstrapServerSideBlockDefinitions)({
478 [name]: Object.fromEntries(
479 Object.entries(response).filter(
480 ([key]) => metadataFields.includes(key)
481 )
482 )
483 });
484 });
485 await loadAssets();
486 const registeredBlocks = registry.select(import_blocks.store).getBlockTypes();
487 if (!registeredBlocks.some((i) => i.name === name)) {
488 throw new Error(
489 (0, import_i18n.__)("Error registering block. Try reloading the page.")
490 );
491 }
492 registry.dispatch(import_notices.store).createInfoNotice(
493 (0, import_i18n.sprintf)(
494 // translators: %s is the block title.
495 (0, import_i18n.__)("Block %s installed and added."),
496 block.title
497 ),
498 {
499 speak: true,
500 type: "snackbar"
501 }
502 );
503 success = true;
504 } catch (error) {
505 let message = error.message || (0, import_i18n.__)("An error occurred.");
506 let isFatal = error instanceof Error;
507 const fatalAPIErrors = {
508 folder_exists: (0, import_i18n.__)(
509 "This block is already installed. Try reloading the page."
510 ),
511 unable_to_connect_to_filesystem: (0, import_i18n.__)(
512 "Error installing block. You can reload the page and try again."
513 )
514 };
515 if (fatalAPIErrors[error.code]) {
516 isFatal = true;
517 message = fatalAPIErrors[error.code];
518 }
519 dispatch.setErrorNotice(id, message, isFatal);
520 registry.dispatch(import_notices.store).createErrorNotice(message, {
521 speak: true,
522 isDismissible: true
523 });
524 }
525 dispatch.setIsInstalling(id, false);
526 return success;
527 };
528 var uninstallBlockType = (block) => async ({ registry, dispatch }) => {
529 try {
530 const url = getPluginUrl(block);
531 await (0, import_api_fetch2.default)({
532 method: "PUT",
533 url,
534 data: { status: "inactive" }
535 });
536 await (0, import_api_fetch2.default)({
537 method: "DELETE",
538 url
539 });
540 dispatch.removeInstalledBlockType(block);
541 } catch (error) {
542 registry.dispatch(import_notices.store).createErrorNotice(
543 error.message || (0, import_i18n.__)("An error occurred.")
544 );
545 }
546 };
547 function addInstalledBlockType(item) {
548 return {
549 type: "ADD_INSTALLED_BLOCK_TYPE",
550 item
551 };
552 }
553 function removeInstalledBlockType(item) {
554 return {
555 type: "REMOVE_INSTALLED_BLOCK_TYPE",
556 item
557 };
558 }
559 function setIsInstalling(blockId, isInstalling2) {
560 return {
561 type: "SET_INSTALLING_BLOCK",
562 blockId,
563 isInstalling: isInstalling2
564 };
565 }
566 function setErrorNotice(blockId, message, isFatal = false) {
567 return {
568 type: "SET_ERROR_NOTICE",
569 blockId,
570 message,
571 isFatal
572 };
573 }
574 function clearErrorNotice(blockId) {
575 return {
576 type: "CLEAR_ERROR_NOTICE",
577 blockId
578 };
579 }
580
581 // packages/block-directory/build-module/store/resolvers.js
582 var resolvers_exports = {};
583 __export(resolvers_exports, {
584 getDownloadableBlocks: () => getDownloadableBlocks2
585 });
586
587 // node_modules/tslib/tslib.es6.mjs
588 var __assign = function() {
589 __assign = Object.assign || function __assign2(t) {
590 for (var s, i = 1, n = arguments.length; i < n; i++) {
591 s = arguments[i];
592 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
593 }
594 return t;
595 };
596 return __assign.apply(this, arguments);
597 };
598
599 // node_modules/lower-case/dist.es2015/index.js
600 function lowerCase(str) {
601 return str.toLowerCase();
602 }
603
604 // node_modules/no-case/dist.es2015/index.js
605 var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
606 var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
607 function noCase(input, options) {
608 if (options === void 0) {
609 options = {};
610 }
611 var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
612 var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
613 var start = 0;
614 var end = result.length;
615 while (result.charAt(start) === "\0")
616 start++;
617 while (result.charAt(end - 1) === "\0")
618 end--;
619 return result.slice(start, end).split("\0").map(transform).join(delimiter);
620 }
621 function replace(input, re, value) {
622 if (re instanceof RegExp)
623 return input.replace(re, value);
624 return re.reduce(function(input2, re2) {
625 return input2.replace(re2, value);
626 }, input);
627 }
628
629 // node_modules/pascal-case/dist.es2015/index.js
630 function pascalCaseTransform(input, index) {
631 var firstChar = input.charAt(0);
632 var lowerChars = input.substr(1).toLowerCase();
633 if (index > 0 && firstChar >= "0" && firstChar <= "9") {
634 return "_" + firstChar + lowerChars;
635 }
636 return "" + firstChar.toUpperCase() + lowerChars;
637 }
638 function pascalCase(input, options) {
639 if (options === void 0) {
640 options = {};
641 }
642 return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options));
643 }
644
645 // node_modules/camel-case/dist.es2015/index.js
646 function camelCaseTransform(input, index) {
647 if (index === 0)
648 return input.toLowerCase();
649 return pascalCaseTransform(input, index);
650 }
651 function camelCase(input, options) {
652 if (options === void 0) {
653 options = {};
654 }
655 return pascalCase(input, __assign({ transform: camelCaseTransform }, options));
656 }
657
658 // packages/block-directory/build-module/store/resolvers.js
659 var import_api_fetch3 = __toESM(require_api_fetch());
660 var getDownloadableBlocks2 = (filterValue) => async ({ dispatch }) => {
661 if (!filterValue) {
662 return;
663 }
664 try {
665 dispatch(fetchDownloadableBlocks(filterValue));
666 const results = await (0, import_api_fetch3.default)({
667 path: `wp/v2/block-directory/search?term=${filterValue}`
668 });
669 const blocks = results.map(
670 (result) => Object.fromEntries(
671 Object.entries(result).map(([key, value]) => [
672 camelCase(key),
673 value
674 ])
675 )
676 );
677 dispatch(receiveDownloadableBlocks(blocks, filterValue));
678 } catch {
679 dispatch(receiveDownloadableBlocks([], filterValue));
680 }
681 };
682
683 // packages/block-directory/build-module/store/index.js
684 var STORE_NAME = "core/block-directory";
685 var storeConfig = {
686 reducer: reducer_default,
687 selectors: selectors_exports,
688 actions: actions_exports,
689 resolvers: resolvers_exports
690 };
691 var store = (0, import_data3.createReduxStore)(STORE_NAME, storeConfig);
692 (0, import_data3.register)(store);
693
694 // packages/block-directory/build-module/components/auto-block-uninstaller/index.js
695 function AutoBlockUninstaller() {
696 const { uninstallBlockType: uninstallBlockType2 } = (0, import_data4.useDispatch)(store);
697 const shouldRemoveBlockTypes = (0, import_data4.useSelect)((select) => {
698 const { isAutosavingPost, isSavingPost } = select(import_editor.store);
699 return isSavingPost() && !isAutosavingPost();
700 }, []);
701 const unusedBlockTypes = (0, import_data4.useSelect)(
702 (select) => select(store).getUnusedBlockTypes(),
703 []
704 );
705 (0, import_element.useEffect)(() => {
706 if (shouldRemoveBlockTypes && unusedBlockTypes.length) {
707 unusedBlockTypes.forEach((blockType) => {
708 uninstallBlockType2(blockType);
709 (0, import_blocks2.unregisterBlockType)(blockType.name);
710 });
711 }
712 }, [shouldRemoveBlockTypes]);
713 return null;
714 }
715
716 // packages/block-directory/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.js
717 var import_block_editor3 = __toESM(require_block_editor());
718 var import_compose = __toESM(require_compose());
719 var import_element5 = __toESM(require_element());
720
721 // packages/block-directory/build-module/components/downloadable-blocks-panel/index.js
722 var import_i18n8 = __toESM(require_i18n());
723 var import_components4 = __toESM(require_components());
724 var import_core_data = __toESM(require_core_data());
725 var import_data8 = __toESM(require_data());
726 var import_blocks5 = __toESM(require_blocks());
727
728 // packages/block-directory/build-module/components/downloadable-blocks-list/index.js
729 var import_i18n5 = __toESM(require_i18n());
730 var import_components2 = __toESM(require_components());
731 var import_blocks4 = __toESM(require_blocks());
732 var import_data7 = __toESM(require_data());
733
734 // node_modules/clsx/dist/clsx.mjs
735 function r(e) {
736 var t, f, n = "";
737 if ("string" == typeof e || "number" == typeof e) n += e;
738 else if ("object" == typeof e) if (Array.isArray(e)) {
739 var o = e.length;
740 for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
741 } else for (f in e) e[f] && (n && (n += " "), n += f);
742 return n;
743 }
744 function clsx() {
745 for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
746 return n;
747 }
748 var clsx_default = clsx;
749
750 // packages/block-directory/build-module/components/downloadable-block-list-item/index.js
751 var import_i18n4 = __toESM(require_i18n());
752 var import_components = __toESM(require_components());
753 var import_element3 = __toESM(require_element());
754 var import_html_entities = __toESM(require_html_entities());
755 var import_blocks3 = __toESM(require_blocks());
756 var import_data6 = __toESM(require_data());
757
758 // packages/block-directory/build-module/components/block-ratings/stars.js
759 var import_i18n2 = __toESM(require_i18n());
760
761 // packages/icons/build-module/icon/index.js
762 var import_element2 = __toESM(require_element());
763 var icon_default = (0, import_element2.forwardRef)(
764 ({ icon, size = 24, ...props }, ref) => {
765 return (0, import_element2.cloneElement)(icon, {
766 width: size,
767 height: size,
768 ...props,
769 ref
770 });
771 }
772 );
773
774 // packages/icons/build-module/library/star-empty.js
775 var import_primitives = __toESM(require_primitives());
776 var import_jsx_runtime = __toESM(require_jsx_runtime());
777 var star_empty_default = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
778 import_primitives.Path,
779 {
780 fillRule: "evenodd",
781 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",
782 clipRule: "evenodd"
783 }
784 ) });
785
786 // packages/icons/build-module/library/star-filled.js
787 var import_primitives2 = __toESM(require_primitives());
788 var import_jsx_runtime2 = __toESM(require_jsx_runtime());
789 var star_filled_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.Path, { 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" }) });
790
791 // packages/icons/build-module/library/star-half.js
792 var import_primitives3 = __toESM(require_primitives());
793 var import_jsx_runtime3 = __toESM(require_jsx_runtime());
794 var star_half_default = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.Path, { 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" }) });
795
796 // packages/block-directory/build-module/components/block-ratings/stars.js
797 var import_jsx_runtime4 = __toESM(require_jsx_runtime());
798 function Stars({ rating }) {
799 const stars = Math.round(rating / 0.5) * 0.5;
800 const fullStarCount = Math.floor(rating);
801 const halfStarCount = Math.ceil(rating - fullStarCount);
802 const emptyStarCount = 5 - (fullStarCount + halfStarCount);
803 return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
804 "span",
805 {
806 "aria-label": (0, import_i18n2.sprintf)(
807 /* translators: %s: number of stars. */
808 (0, import_i18n2.__)("%s out of 5 stars"),
809 stars
810 ),
811 children: [
812 Array.from({ length: fullStarCount }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
813 icon_default,
814 {
815 className: "block-directory-block-ratings__star-full",
816 icon: star_filled_default,
817 size: 16
818 },
819 `full_stars_${i}`
820 )),
821 Array.from({ length: halfStarCount }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
822 icon_default,
823 {
824 className: "block-directory-block-ratings__star-half-full",
825 icon: star_half_default,
826 size: 16
827 },
828 `half_stars_${i}`
829 )),
830 Array.from({ length: emptyStarCount }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
831 icon_default,
832 {
833 className: "block-directory-block-ratings__star-empty",
834 icon: star_empty_default,
835 size: 16
836 },
837 `empty_stars_${i}`
838 ))
839 ]
840 }
841 );
842 }
843 var stars_default = Stars;
844
845 // packages/block-directory/build-module/components/block-ratings/index.js
846 var import_jsx_runtime5 = __toESM(require_jsx_runtime());
847 var BlockRatings = ({ rating }) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "block-directory-block-ratings", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(stars_default, { rating }) });
848 var block_ratings_default = BlockRatings;
849
850 // packages/block-directory/build-module/components/downloadable-block-icon/index.js
851 var import_block_editor2 = __toESM(require_block_editor());
852 var import_jsx_runtime6 = __toESM(require_jsx_runtime());
853 function DownloadableBlockIcon({ icon }) {
854 const className = "block-directory-downloadable-block-icon";
855 return icon.match(/\.(jpeg|jpg|gif|png|svg)(?:\?.*)?$/) !== null ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("img", { className, src: icon, alt: "" }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_block_editor2.BlockIcon, { className, icon, showColors: true });
856 }
857 var downloadable_block_icon_default = DownloadableBlockIcon;
858
859 // packages/block-directory/build-module/components/downloadable-block-notice/index.js
860 var import_i18n3 = __toESM(require_i18n());
861 var import_data5 = __toESM(require_data());
862 var import_jsx_runtime7 = __toESM(require_jsx_runtime());
863 var DownloadableBlockNotice = ({ block }) => {
864 const errorNotice = (0, import_data5.useSelect)(
865 (select) => select(store).getErrorNoticeForBlock(block.id),
866 [block]
867 );
868 if (!errorNotice) {
869 return null;
870 }
871 return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "block-directory-downloadable-block-notice", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "block-directory-downloadable-block-notice__content", children: [
872 errorNotice.message,
873 errorNotice.isFatal ? " " + (0, import_i18n3.__)("Try reloading the page.") : null
874 ] }) });
875 };
876 var downloadable_block_notice_default = DownloadableBlockNotice;
877
878 // packages/block-directory/build-module/components/downloadable-block-list-item/index.js
879 var import_jsx_runtime8 = __toESM(require_jsx_runtime());
880 function getDownloadableBlockLabel({ title, rating, ratingCount }, { hasNotice, isInstalled, isInstalling: isInstalling2 }) {
881 const stars = Math.round(rating / 0.5) * 0.5;
882 if (!isInstalled && hasNotice) {
883 return (0, import_i18n4.sprintf)("Retry installing %s.", (0, import_html_entities.decodeEntities)(title));
884 }
885 if (isInstalled) {
886 return (0, import_i18n4.sprintf)("Add %s.", (0, import_html_entities.decodeEntities)(title));
887 }
888 if (isInstalling2) {
889 return (0, import_i18n4.sprintf)("Installing %s.", (0, import_html_entities.decodeEntities)(title));
890 }
891 if (ratingCount < 1) {
892 return (0, import_i18n4.sprintf)("Install %s.", (0, import_html_entities.decodeEntities)(title));
893 }
894 return (0, import_i18n4.sprintf)(
895 /* translators: 1: block title, 2: average rating, 3: total ratings count. */
896 (0, import_i18n4._n)(
897 "Install %1$s. %2$s stars with %3$s review.",
898 "Install %1$s. %2$s stars with %3$s reviews.",
899 ratingCount
900 ),
901 (0, import_html_entities.decodeEntities)(title),
902 stars,
903 ratingCount
904 );
905 }
906 function DownloadableBlockListItem({ item, onClick }) {
907 const { author, description, icon, rating, title } = item;
908 const isInstalled = !!(0, import_blocks3.getBlockType)(item.name);
909 const { hasNotice, isInstalling: isInstalling2, isInstallable } = (0, import_data6.useSelect)(
910 (select) => {
911 const { getErrorNoticeForBlock: getErrorNoticeForBlock2, isInstalling: isBlockInstalling } = select(store);
912 const notice = getErrorNoticeForBlock2(item.id);
913 const hasFatal = notice && notice.isFatal;
914 return {
915 hasNotice: !!notice,
916 isInstalling: isBlockInstalling(item.id),
917 isInstallable: !hasFatal
918 };
919 },
920 [item]
921 );
922 let statusText = "";
923 if (isInstalled) {
924 statusText = (0, import_i18n4.__)("Installed!");
925 } else if (isInstalling2) {
926 statusText = (0, import_i18n4.__)("Installing\u2026");
927 }
928 const itemLabel = getDownloadableBlockLabel(item, {
929 hasNotice,
930 isInstalled,
931 isInstalling: isInstalling2
932 });
933 return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components.Tooltip, { placement: "top", text: itemLabel, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
934 import_components.Composite.Item,
935 {
936 className: clsx_default(
937 "block-directory-downloadable-block-list-item",
938 isInstalling2 && "is-installing"
939 ),
940 accessibleWhenDisabled: true,
941 disabled: isInstalling2 || !isInstallable,
942 onClick: (event) => {
943 event.preventDefault();
944 onClick();
945 },
946 "aria-label": itemLabel,
947 type: "button",
948 role: "option",
949 children: [
950 /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "block-directory-downloadable-block-list-item__icon", children: [
951 /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(downloadable_block_icon_default, { icon, title }),
952 isInstalling2 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "block-directory-downloadable-block-list-item__spinner", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components.Spinner, {}) }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(block_ratings_default, { rating })
953 ] }),
954 /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "block-directory-downloadable-block-list-item__details", children: [
955 /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "block-directory-downloadable-block-list-item__title", children: (0, import_element3.createInterpolateElement)(
956 (0, import_i18n4.sprintf)(
957 /* translators: 1: block title. 2: author name. */
958 (0, import_i18n4.__)("%1$s <span>by %2$s</span>"),
959 (0, import_html_entities.decodeEntities)(title),
960 author
961 ),
962 {
963 span: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "block-directory-downloadable-block-list-item__author" })
964 }
965 ) }),
966 hasNotice ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(downloadable_block_notice_default, { block: item }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
967 /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "block-directory-downloadable-block-list-item__desc", children: !!statusText ? statusText : (0, import_html_entities.decodeEntities)(description) }),
968 isInstallable && !(isInstalled || isInstalling2) && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components.VisuallyHidden, { children: (0, import_i18n4.__)("Install block") })
969 ] })
970 ] })
971 ]
972 }
973 ) });
974 }
975 var downloadable_block_list_item_default = DownloadableBlockListItem;
976
977 // packages/block-directory/build-module/components/downloadable-blocks-list/index.js
978 var import_jsx_runtime9 = __toESM(require_jsx_runtime());
979 var noop = () => {
980 };
981 function DownloadableBlocksList({ items, onHover = noop, onSelect }) {
982 const { installBlockType: installBlockType2 } = (0, import_data7.useDispatch)(store);
983 if (!items.length) {
984 return null;
985 }
986 return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
987 import_components2.Composite,
988 {
989 role: "listbox",
990 className: "block-directory-downloadable-blocks-list",
991 "aria-label": (0, import_i18n5.__)("Blocks available for install"),
992 children: items.map((item) => {
993 return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
994 downloadable_block_list_item_default,
995 {
996 onClick: () => {
997 if ((0, import_blocks4.getBlockType)(item.name)) {
998 onSelect(item);
999 } else {
1000 installBlockType2(item).then((success) => {
1001 if (success) {
1002 onSelect(item);
1003 }
1004 });
1005 }
1006 onHover(null);
1007 },
1008 onHover,
1009 item
1010 },
1011 item.id
1012 );
1013 })
1014 }
1015 );
1016 }
1017 var downloadable_blocks_list_default = DownloadableBlocksList;
1018
1019 // packages/block-directory/build-module/components/downloadable-blocks-panel/inserter-panel.js
1020 var import_i18n6 = __toESM(require_i18n());
1021 var import_element4 = __toESM(require_element());
1022 var import_a11y = __toESM(require_a11y());
1023 var import_jsx_runtime10 = __toESM(require_jsx_runtime());
1024 function DownloadableBlocksInserterPanel({
1025 children,
1026 downloadableItems,
1027 hasLocalBlocks
1028 }) {
1029 const count = downloadableItems.length;
1030 (0, import_element4.useEffect)(() => {
1031 (0, import_a11y.speak)(
1032 (0, import_i18n6.sprintf)(
1033 /* translators: %d: number of available blocks. */
1034 (0, import_i18n6._n)(
1035 "%d additional block is available to install.",
1036 "%d additional blocks are available to install.",
1037 count
1038 ),
1039 count
1040 )
1041 );
1042 }, [count]);
1043 return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
1044 !hasLocalBlocks && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "block-directory-downloadable-blocks-panel__no-local", children: (0, import_i18n6.__)("No results available from your installed blocks.") }),
1045 /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "block-editor-inserter__quick-inserter-separator" }),
1046 /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "block-directory-downloadable-blocks-panel", children: [
1047 /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "block-directory-downloadable-blocks-panel__header", children: [
1048 /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("h2", { className: "block-directory-downloadable-blocks-panel__title", children: (0, import_i18n6.__)("Available to install") }),
1049 /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "block-directory-downloadable-blocks-panel__description", children: (0, import_i18n6.__)(
1050 "Select a block to install and add it to your post."
1051 ) })
1052 ] }),
1053 children
1054 ] })
1055 ] });
1056 }
1057 var inserter_panel_default = DownloadableBlocksInserterPanel;
1058
1059 // packages/block-directory/build-module/components/downloadable-blocks-panel/no-results.js
1060 var import_i18n7 = __toESM(require_i18n());
1061 var import_components3 = __toESM(require_components());
1062 var import_jsx_runtime11 = __toESM(require_jsx_runtime());
1063 function DownloadableBlocksNoResults() {
1064 return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
1065 /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "block-editor-inserter__no-results", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { children: (0, import_i18n7.__)("No results found.") }) }),
1066 /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "block-editor-inserter__tips", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_components3.Tip, { children: [
1067 (0, import_i18n7.__)("Interested in creating your own block?"),
1068 /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("br", {}),
1069 /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_components3.ExternalLink, { href: "https://developer.wordpress.org/block-editor/", children: [
1070 (0, import_i18n7.__)("Get started here"),
1071 "."
1072 ] })
1073 ] }) })
1074 ] });
1075 }
1076 var no_results_default = DownloadableBlocksNoResults;
1077
1078 // packages/block-directory/build-module/components/downloadable-blocks-panel/index.js
1079 var import_jsx_runtime12 = __toESM(require_jsx_runtime());
1080 var EMPTY_ARRAY2 = [];
1081 var useDownloadableBlocks = (filterValue) => (0, import_data8.useSelect)(
1082 (select) => {
1083 const {
1084 getDownloadableBlocks: getDownloadableBlocks3,
1085 isRequestingDownloadableBlocks: isRequestingDownloadableBlocks2,
1086 getInstalledBlockTypes: getInstalledBlockTypes2
1087 } = select(store);
1088 const hasPermission = select(import_core_data.store).canUser(
1089 "read",
1090 "block-directory/search"
1091 );
1092 let downloadableBlocks2 = EMPTY_ARRAY2;
1093 if (hasPermission) {
1094 downloadableBlocks2 = getDownloadableBlocks3(filterValue);
1095 const installedBlockTypes = getInstalledBlockTypes2();
1096 const installableBlocks = downloadableBlocks2.filter(
1097 ({ name }) => {
1098 const isJustInstalled = installedBlockTypes.some(
1099 (blockType) => blockType.name === name
1100 );
1101 const isPreviouslyInstalled = (0, import_blocks5.getBlockType)(name);
1102 return isJustInstalled || !isPreviouslyInstalled;
1103 }
1104 );
1105 if (installableBlocks.length !== downloadableBlocks2.length) {
1106 downloadableBlocks2 = installableBlocks;
1107 }
1108 if (downloadableBlocks2.length === 0) {
1109 downloadableBlocks2 = EMPTY_ARRAY2;
1110 }
1111 }
1112 return {
1113 hasPermission,
1114 downloadableBlocks: downloadableBlocks2,
1115 isLoading: isRequestingDownloadableBlocks2(filterValue)
1116 };
1117 },
1118 [filterValue]
1119 );
1120 function DownloadableBlocksPanel({
1121 onSelect,
1122 onHover,
1123 hasLocalBlocks,
1124 isTyping,
1125 filterValue
1126 }) {
1127 const { hasPermission, downloadableBlocks: downloadableBlocks2, isLoading } = useDownloadableBlocks(filterValue);
1128 if (hasPermission === void 0 || isLoading || isTyping) {
1129 return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
1130 hasPermission && !hasLocalBlocks && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
1131 /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "block-directory-downloadable-blocks-panel__no-local", children: (0, import_i18n8.__)(
1132 "No results available from your installed blocks."
1133 ) }),
1134 /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "block-editor-inserter__quick-inserter-separator" })
1135 ] }),
1136 /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "block-directory-downloadable-blocks-panel has-blocks-loading", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_components4.Spinner, {}) })
1137 ] });
1138 }
1139 if (false === hasPermission) {
1140 if (!hasLocalBlocks) {
1141 return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(no_results_default, {});
1142 }
1143 return null;
1144 }
1145 if (downloadableBlocks2.length === 0) {
1146 return hasLocalBlocks ? null : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(no_results_default, {});
1147 }
1148 return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1149 inserter_panel_default,
1150 {
1151 downloadableItems: downloadableBlocks2,
1152 hasLocalBlocks,
1153 children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1154 downloadable_blocks_list_default,
1155 {
1156 items: downloadableBlocks2,
1157 onSelect,
1158 onHover
1159 }
1160 )
1161 }
1162 );
1163 }
1164
1165 // packages/block-directory/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.js
1166 var import_jsx_runtime13 = __toESM(require_jsx_runtime());
1167 function InserterMenuDownloadableBlocksPanel() {
1168 const [debouncedFilterValue, setFilterValue] = (0, import_element5.useState)("");
1169 const debouncedSetFilterValue = (0, import_compose.debounce)(setFilterValue, 400);
1170 return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_block_editor3.__unstableInserterMenuExtension, { children: ({ onSelect, onHover, filterValue, hasItems }) => {
1171 if (debouncedFilterValue !== filterValue) {
1172 debouncedSetFilterValue(filterValue);
1173 }
1174 if (!debouncedFilterValue) {
1175 return null;
1176 }
1177 return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1178 DownloadableBlocksPanel,
1179 {
1180 onSelect,
1181 onHover,
1182 filterValue: debouncedFilterValue,
1183 hasLocalBlocks: hasItems,
1184 isTyping: filterValue !== debouncedFilterValue
1185 }
1186 );
1187 } });
1188 }
1189 var inserter_menu_downloadable_blocks_panel_default = InserterMenuDownloadableBlocksPanel;
1190
1191 // packages/block-directory/build-module/plugins/installed-blocks-pre-publish-panel/index.js
1192 var import_i18n10 = __toESM(require_i18n());
1193 var import_data9 = __toESM(require_data());
1194 var import_editor2 = __toESM(require_editor());
1195
1196 // packages/block-directory/build-module/components/compact-list/index.js
1197 var import_i18n9 = __toESM(require_i18n());
1198 var import_jsx_runtime14 = __toESM(require_jsx_runtime());
1199 function CompactList({ items }) {
1200 if (!items.length) {
1201 return null;
1202 }
1203 return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("ul", { className: "block-directory-compact-list", children: items.map(({ icon, id, title, author }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("li", { className: "block-directory-compact-list__item", children: [
1204 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(downloadable_block_icon_default, { icon, title }),
1205 /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "block-directory-compact-list__item-details", children: [
1206 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "block-directory-compact-list__item-title", children: title }),
1207 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "block-directory-compact-list__item-author", children: (0, import_i18n9.sprintf)(
1208 /* translators: %s: Name of the block author. */
1209 (0, import_i18n9.__)("By %s"),
1210 author
1211 ) })
1212 ] })
1213 ] }, id)) });
1214 }
1215
1216 // packages/block-directory/build-module/plugins/installed-blocks-pre-publish-panel/index.js
1217 var import_jsx_runtime15 = __toESM(require_jsx_runtime());
1218 function InstalledBlocksPrePublishPanel() {
1219 const newBlockTypes = (0, import_data9.useSelect)(
1220 (select) => select(store).getNewBlockTypes(),
1221 []
1222 );
1223 if (!newBlockTypes.length) {
1224 return null;
1225 }
1226 return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
1227 import_editor2.PluginPrePublishPanel,
1228 {
1229 title: (0, import_i18n10.sprintf)(
1230 // translators: %d: number of blocks (number).
1231 (0, import_i18n10._n)(
1232 "Added: %d block",
1233 "Added: %d blocks",
1234 newBlockTypes.length
1235 ),
1236 newBlockTypes.length
1237 ),
1238 initialOpen: true,
1239 children: [
1240 /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "installed-blocks-pre-publish-panel__copy", children: (0, import_i18n10._n)(
1241 "The following block has been added to your site.",
1242 "The following blocks have been added to your site.",
1243 newBlockTypes.length
1244 ) }),
1245 /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(CompactList, { items: newBlockTypes })
1246 ]
1247 }
1248 );
1249 }
1250
1251 // packages/block-directory/build-module/plugins/get-install-missing/index.js
1252 var import_i18n12 = __toESM(require_i18n());
1253 var import_components6 = __toESM(require_components());
1254 var import_blocks7 = __toESM(require_blocks());
1255 var import_element6 = __toESM(require_element());
1256 var import_data11 = __toESM(require_data());
1257 var import_core_data2 = __toESM(require_core_data());
1258 var import_block_editor5 = __toESM(require_block_editor());
1259
1260 // packages/block-directory/build-module/plugins/get-install-missing/install-button.js
1261 var import_i18n11 = __toESM(require_i18n());
1262 var import_components5 = __toESM(require_components());
1263 var import_blocks6 = __toESM(require_blocks());
1264 var import_data10 = __toESM(require_data());
1265 var import_block_editor4 = __toESM(require_block_editor());
1266 var import_jsx_runtime16 = __toESM(require_jsx_runtime());
1267 function InstallButton({ attributes, block, clientId }) {
1268 const isInstallingBlock = (0, import_data10.useSelect)(
1269 (select) => select(store).isInstalling(block.id),
1270 [block.id]
1271 );
1272 const { installBlockType: installBlockType2 } = (0, import_data10.useDispatch)(store);
1273 const { replaceBlock } = (0, import_data10.useDispatch)(import_block_editor4.store);
1274 return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1275 import_components5.Button,
1276 {
1277 __next40pxDefaultSize: true,
1278 onClick: () => installBlockType2(block).then((success) => {
1279 if (success) {
1280 const blockType = (0, import_blocks6.getBlockType)(block.name);
1281 const [originalBlock] = (0, import_blocks6.parse)(
1282 attributes.originalContent
1283 );
1284 if (originalBlock && blockType) {
1285 replaceBlock(
1286 clientId,
1287 (0, import_blocks6.createBlock)(
1288 blockType.name,
1289 originalBlock.attributes,
1290 originalBlock.innerBlocks
1291 )
1292 );
1293 }
1294 }
1295 }),
1296 accessibleWhenDisabled: true,
1297 disabled: isInstallingBlock,
1298 isBusy: isInstallingBlock,
1299 variant: "primary",
1300 children: (0, import_i18n11.sprintf)(
1301 /* translators: %s: block name */
1302 (0, import_i18n11.__)("Install %s"),
1303 block.title
1304 )
1305 }
1306 );
1307 }
1308
1309 // packages/block-directory/build-module/plugins/get-install-missing/index.js
1310 var import_jsx_runtime17 = __toESM(require_jsx_runtime());
1311 var getInstallMissing = (OriginalComponent) => (props) => {
1312 const { originalName } = props.attributes;
1313 const { block, hasPermission } = (0, import_data11.useSelect)(
1314 (select) => {
1315 const { getDownloadableBlocks: getDownloadableBlocks3 } = select(store);
1316 const blocks = getDownloadableBlocks3(
1317 "block:" + originalName
1318 ).filter(({ name }) => originalName === name);
1319 return {
1320 hasPermission: select(import_core_data2.store).canUser(
1321 "read",
1322 "block-directory/search"
1323 ),
1324 block: blocks.length && blocks[0]
1325 };
1326 },
1327 [originalName]
1328 );
1329 if (!hasPermission || !block) {
1330 return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(OriginalComponent, { ...props });
1331 }
1332 return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ModifiedWarning, { ...props, originalBlock: block });
1333 };
1334 var ModifiedWarning = ({ originalBlock, ...props }) => {
1335 const { originalName, originalUndelimitedContent, clientId } = props.attributes;
1336 const { replaceBlock } = (0, import_data11.useDispatch)(import_block_editor5.store);
1337 const convertToHTML = () => {
1338 replaceBlock(
1339 props.clientId,
1340 (0, import_blocks7.createBlock)("core/html", {
1341 content: originalUndelimitedContent
1342 })
1343 );
1344 };
1345 const hasContent = !!originalUndelimitedContent;
1346 const hasHTMLBlock = (0, import_data11.useSelect)(
1347 (select) => {
1348 const { canInsertBlockType, getBlockRootClientId } = select(import_block_editor5.store);
1349 return canInsertBlockType(
1350 "core/html",
1351 getBlockRootClientId(clientId)
1352 );
1353 },
1354 [clientId]
1355 );
1356 let messageHTML = (0, import_i18n12.sprintf)(
1357 /* translators: %s: block name */
1358 (0, import_i18n12.__)(
1359 "Your site doesn\u2019t include support for the %s block. You can try installing the block or remove it entirely."
1360 ),
1361 originalBlock.title || originalName
1362 );
1363 const actions = [
1364 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1365 InstallButton,
1366 {
1367 block: originalBlock,
1368 attributes: props.attributes,
1369 clientId: props.clientId
1370 },
1371 "install"
1372 )
1373 ];
1374 if (hasContent && hasHTMLBlock) {
1375 messageHTML = (0, import_i18n12.sprintf)(
1376 /* translators: %s: block name */
1377 (0, import_i18n12.__)(
1378 "Your site doesn\u2019t include support for the %s block. You can try installing the block, convert it to a Custom HTML block, or remove it entirely."
1379 ),
1380 originalBlock.title || originalName
1381 );
1382 actions.push(
1383 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1384 import_components6.Button,
1385 {
1386 __next40pxDefaultSize: true,
1387 onClick: convertToHTML,
1388 variant: "tertiary",
1389 children: (0, import_i18n12.__)("Keep as HTML")
1390 },
1391 "convert"
1392 )
1393 );
1394 }
1395 return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { ...(0, import_block_editor5.useBlockProps)(), children: [
1396 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_block_editor5.Warning, { actions, children: messageHTML }),
1397 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_element6.RawHTML, { children: originalUndelimitedContent })
1398 ] });
1399 };
1400 var get_install_missing_default = getInstallMissing;
1401
1402 // packages/block-directory/build-module/plugins/index.js
1403 var import_jsx_runtime18 = __toESM(require_jsx_runtime());
1404 (0, import_plugins.registerPlugin)("block-directory", {
1405 // The icon is explicitly set to undefined to prevent PluginPrePublishPanel
1406 // from rendering the fallback icon pluginIcon.
1407 icon: void 0,
1408 render() {
1409 return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
1410 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(AutoBlockUninstaller, {}),
1411 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(inserter_menu_downloadable_blocks_panel_default, {}),
1412 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(InstalledBlocksPrePublishPanel, {})
1413 ] });
1414 }
1415 });
1416 (0, import_hooks.addFilter)(
1417 "blocks.registerBlockType",
1418 "block-directory/fallback",
1419 (settings, name) => {
1420 if (name !== "core/missing") {
1421 return settings;
1422 }
1423 settings.edit = get_install_missing_default(settings.edit);
1424 return settings;
1425 }
1426 );
1427 return __toCommonJS(index_exports);
1428 })();
1429 //# sourceMappingURL=index.js.map
1430