PluginProbe
Gutenberg / 23.1.0
Gutenberg v23.1.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 23.1.0, at build/scripts/block-directory/index.js

1,923 lines 71.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 // vendor-external:react
140 var require_react = __commonJS({
141 "vendor-external:react"(exports, module) {
142 module.exports = window.React;
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 // package-external:@wordpress/primitives
161 var require_primitives = __commonJS({
162 "package-external:@wordpress/primitives"(exports, module) {
163 module.exports = window.wp.primitives;
164 }
165 });
166
167 // packages/block-directory/build-module/index.mjs
168 var index_exports = {};
169 __export(index_exports, {
170 store: () => store
171 });
172
173 // packages/block-directory/build-module/plugins/index.mjs
174 var import_plugins = __toESM(require_plugins(), 1);
175 var import_hooks = __toESM(require_hooks(), 1);
176
177 // packages/block-directory/build-module/components/auto-block-uninstaller/index.mjs
178 var import_blocks2 = __toESM(require_blocks(), 1);
179 var import_data4 = __toESM(require_data(), 1);
180 var import_element = __toESM(require_element(), 1);
181 var import_editor = __toESM(require_editor(), 1);
182
183 // packages/block-directory/build-module/store/index.mjs
184 var import_data3 = __toESM(require_data(), 1);
185
186 // packages/block-directory/build-module/store/reducer.mjs
187 var import_data = __toESM(require_data(), 1);
188 var downloadableBlocks = (state = {}, action) => {
189 switch (action.type) {
190 case "FETCH_DOWNLOADABLE_BLOCKS":
191 return {
192 ...state,
193 [action.filterValue]: {
194 isRequesting: true
195 }
196 };
197 case "RECEIVE_DOWNLOADABLE_BLOCKS":
198 return {
199 ...state,
200 [action.filterValue]: {
201 results: action.downloadableBlocks,
202 isRequesting: false
203 }
204 };
205 }
206 return state;
207 };
208 var blockManagement = (state = {
209 installedBlockTypes: [],
210 isInstalling: {}
211 }, action) => {
212 switch (action.type) {
213 case "ADD_INSTALLED_BLOCK_TYPE":
214 return {
215 ...state,
216 installedBlockTypes: [
217 ...state.installedBlockTypes,
218 action.item
219 ]
220 };
221 case "REMOVE_INSTALLED_BLOCK_TYPE":
222 return {
223 ...state,
224 installedBlockTypes: state.installedBlockTypes.filter(
225 (blockType) => blockType.name !== action.item.name
226 )
227 };
228 case "SET_INSTALLING_BLOCK":
229 return {
230 ...state,
231 isInstalling: {
232 ...state.isInstalling,
233 [action.blockId]: action.isInstalling
234 }
235 };
236 }
237 return state;
238 };
239 var errorNotices = (state = {}, action) => {
240 switch (action.type) {
241 case "SET_ERROR_NOTICE":
242 return {
243 ...state,
244 [action.blockId]: {
245 message: action.message,
246 isFatal: action.isFatal
247 }
248 };
249 case "CLEAR_ERROR_NOTICE":
250 const { [action.blockId]: blockId, ...restState } = state;
251 return restState;
252 }
253 return state;
254 };
255 var reducer_default = (0, import_data.combineReducers)({
256 downloadableBlocks,
257 blockManagement,
258 errorNotices
259 });
260
261 // packages/block-directory/build-module/store/selectors.mjs
262 var selectors_exports = {};
263 __export(selectors_exports, {
264 getDownloadableBlocks: () => getDownloadableBlocks,
265 getErrorNoticeForBlock: () => getErrorNoticeForBlock,
266 getErrorNotices: () => getErrorNotices,
267 getInstalledBlockTypes: () => getInstalledBlockTypes,
268 getNewBlockTypes: () => getNewBlockTypes,
269 getUnusedBlockTypes: () => getUnusedBlockTypes,
270 isInstalling: () => isInstalling,
271 isRequestingDownloadableBlocks: () => isRequestingDownloadableBlocks
272 });
273 var import_data2 = __toESM(require_data(), 1);
274 var import_block_editor = __toESM(require_block_editor(), 1);
275 var EMPTY_ARRAY = [];
276 function isRequestingDownloadableBlocks(state, filterValue) {
277 return state.downloadableBlocks[filterValue]?.isRequesting ?? false;
278 }
279 function getDownloadableBlocks(state, filterValue) {
280 return state.downloadableBlocks[filterValue]?.results ?? EMPTY_ARRAY;
281 }
282 function getInstalledBlockTypes(state) {
283 return state.blockManagement.installedBlockTypes;
284 }
285 var getNewBlockTypes = (0, import_data2.createRegistrySelector)(
286 (select) => (0, import_data2.createSelector)(
287 (state) => {
288 const installedBlockTypes = getInstalledBlockTypes(state);
289 if (!installedBlockTypes.length) {
290 return EMPTY_ARRAY;
291 }
292 const { getBlockName, getClientIdsWithDescendants } = select(import_block_editor.store);
293 const installedBlockNames = installedBlockTypes.map(
294 (blockType) => blockType.name
295 );
296 const foundBlockNames = getClientIdsWithDescendants().flatMap(
297 (clientId) => {
298 const blockName = getBlockName(clientId);
299 return installedBlockNames.includes(blockName) ? blockName : [];
300 }
301 );
302 const newBlockTypes = installedBlockTypes.filter(
303 (blockType) => foundBlockNames.includes(blockType.name)
304 );
305 return newBlockTypes.length > 0 ? newBlockTypes : EMPTY_ARRAY;
306 },
307 (state) => [
308 getInstalledBlockTypes(state),
309 select(import_block_editor.store).getClientIdsWithDescendants()
310 ]
311 )
312 );
313 var getUnusedBlockTypes = (0, import_data2.createRegistrySelector)(
314 (select) => (0, import_data2.createSelector)(
315 (state) => {
316 const installedBlockTypes = getInstalledBlockTypes(state);
317 if (!installedBlockTypes.length) {
318 return EMPTY_ARRAY;
319 }
320 const { getBlockName, getClientIdsWithDescendants } = select(import_block_editor.store);
321 const installedBlockNames = installedBlockTypes.map(
322 (blockType) => blockType.name
323 );
324 const foundBlockNames = getClientIdsWithDescendants().flatMap(
325 (clientId) => {
326 const blockName = getBlockName(clientId);
327 return installedBlockNames.includes(blockName) ? blockName : [];
328 }
329 );
330 const unusedBlockTypes = installedBlockTypes.filter(
331 (blockType) => !foundBlockNames.includes(blockType.name)
332 );
333 return unusedBlockTypes.length > 0 ? unusedBlockTypes : EMPTY_ARRAY;
334 },
335 (state) => [
336 getInstalledBlockTypes(state),
337 select(import_block_editor.store).getClientIdsWithDescendants()
338 ]
339 )
340 );
341 function isInstalling(state, blockId) {
342 return state.blockManagement.isInstalling[blockId] || false;
343 }
344 function getErrorNotices(state) {
345 return state.errorNotices;
346 }
347 function getErrorNoticeForBlock(state, blockId) {
348 return state.errorNotices[blockId];
349 }
350
351 // packages/block-directory/build-module/store/actions.mjs
352 var actions_exports = {};
353 __export(actions_exports, {
354 addInstalledBlockType: () => addInstalledBlockType,
355 clearErrorNotice: () => clearErrorNotice,
356 fetchDownloadableBlocks: () => fetchDownloadableBlocks,
357 installBlockType: () => installBlockType,
358 receiveDownloadableBlocks: () => receiveDownloadableBlocks,
359 removeInstalledBlockType: () => removeInstalledBlockType,
360 setErrorNotice: () => setErrorNotice,
361 setIsInstalling: () => setIsInstalling,
362 uninstallBlockType: () => uninstallBlockType
363 });
364 var import_blocks = __toESM(require_blocks(), 1);
365 var import_i18n = __toESM(require_i18n(), 1);
366 var import_api_fetch2 = __toESM(require_api_fetch(), 1);
367 var import_notices = __toESM(require_notices(), 1);
368 var import_url = __toESM(require_url(), 1);
369
370 // packages/block-directory/build-module/store/load-assets.mjs
371 var import_api_fetch = __toESM(require_api_fetch(), 1);
372 var loadAsset = (el) => {
373 return new Promise((resolve, reject) => {
374 const newNode = document.createElement(el.nodeName);
375 ["id", "rel", "src", "href", "type"].forEach((attr) => {
376 if (el[attr]) {
377 newNode[attr] = el[attr];
378 }
379 });
380 if (el.innerHTML) {
381 newNode.appendChild(document.createTextNode(el.innerHTML));
382 }
383 newNode.onload = () => resolve(true);
384 newNode.onerror = () => reject(new Error("Error loading asset."));
385 document.body.appendChild(newNode);
386 if ("link" === newNode.nodeName.toLowerCase() || "script" === newNode.nodeName.toLowerCase() && !newNode.src) {
387 resolve();
388 }
389 });
390 };
391 async function loadAssets() {
392 const response = await (0, import_api_fetch.default)({
393 url: document.location.href,
394 parse: false
395 });
396 const data = await response.text();
397 const doc = new window.DOMParser().parseFromString(data, "text/html");
398 const newAssets = Array.from(
399 doc.querySelectorAll('link[rel="stylesheet"],script')
400 ).filter((asset) => asset.id && !document.getElementById(asset.id));
401 for (const newAsset of newAssets) {
402 await loadAsset(newAsset);
403 }
404 }
405
406 // packages/block-directory/build-module/store/utils/get-plugin-url.mjs
407 function getPluginUrl(block) {
408 if (!block) {
409 return false;
410 }
411 const link = block.links["wp:plugin"] || block.links.self;
412 if (link && link.length) {
413 return link[0].href;
414 }
415 return false;
416 }
417
418 // packages/block-directory/build-module/store/actions.mjs
419 function fetchDownloadableBlocks(filterValue) {
420 return { type: "FETCH_DOWNLOADABLE_BLOCKS", filterValue };
421 }
422 function receiveDownloadableBlocks(downloadableBlocks2, filterValue) {
423 return {
424 type: "RECEIVE_DOWNLOADABLE_BLOCKS",
425 downloadableBlocks: downloadableBlocks2,
426 filterValue
427 };
428 }
429 var installBlockType = (block) => async ({ registry, dispatch }) => {
430 const { id, name } = block;
431 let success = false;
432 dispatch.clearErrorNotice(id);
433 try {
434 dispatch.setIsInstalling(id, true);
435 const url = getPluginUrl(block);
436 let links = {};
437 if (url) {
438 await (0, import_api_fetch2.default)({
439 method: "PUT",
440 url,
441 data: { status: "active" }
442 });
443 } else {
444 const response = await (0, import_api_fetch2.default)({
445 method: "POST",
446 path: "wp/v2/plugins",
447 data: { slug: id, status: "active" }
448 });
449 links = response._links;
450 }
451 dispatch.addInstalledBlockType({
452 ...block,
453 links: { ...block.links, ...links }
454 });
455 const metadataFields = [
456 "api_version",
457 "title",
458 "category",
459 "parent",
460 "ancestor",
461 "icon",
462 "description",
463 "keywords",
464 "attributes",
465 "provides_context",
466 "uses_context",
467 "selectors",
468 "supports",
469 "styles",
470 "example",
471 "variations",
472 "allowed_blocks",
473 "block_hooks"
474 ];
475 await (0, import_api_fetch2.default)({
476 path: (0, import_url.addQueryArgs)(`/wp/v2/block-types/${name}`, {
477 _fields: metadataFields
478 })
479 }).catch(() => {
480 }).then((response) => {
481 if (!response) {
482 return;
483 }
484 (0, import_blocks.unstable__bootstrapServerSideBlockDefinitions)({
485 [name]: Object.fromEntries(
486 Object.entries(response).filter(
487 ([key]) => metadataFields.includes(key)
488 )
489 )
490 });
491 });
492 await loadAssets();
493 const registeredBlocks = registry.select(import_blocks.store).getBlockTypes();
494 if (!registeredBlocks.some((i) => i.name === name)) {
495 throw new Error(
496 (0, import_i18n.__)("Error registering block. Try reloading the page.")
497 );
498 }
499 registry.dispatch(import_notices.store).createInfoNotice(
500 (0, import_i18n.sprintf)(
501 // translators: %s is the block title.
502 (0, import_i18n.__)("Block %s installed and added."),
503 block.title
504 ),
505 {
506 speak: true,
507 type: "snackbar"
508 }
509 );
510 success = true;
511 } catch (error) {
512 let message = error.message || (0, import_i18n.__)("An error occurred.");
513 let isFatal = error instanceof Error;
514 const fatalAPIErrors = {
515 folder_exists: (0, import_i18n.__)(
516 "This block is already installed. Try reloading the page."
517 ),
518 unable_to_connect_to_filesystem: (0, import_i18n.__)(
519 "Error installing block. You can reload the page and try again."
520 )
521 };
522 if (fatalAPIErrors[error.code]) {
523 isFatal = true;
524 message = fatalAPIErrors[error.code];
525 }
526 dispatch.setErrorNotice(id, message, isFatal);
527 registry.dispatch(import_notices.store).createErrorNotice(message, {
528 speak: true,
529 isDismissible: true
530 });
531 }
532 dispatch.setIsInstalling(id, false);
533 return success;
534 };
535 var uninstallBlockType = (block) => async ({ registry, dispatch }) => {
536 try {
537 const url = getPluginUrl(block);
538 await (0, import_api_fetch2.default)({
539 method: "PUT",
540 url,
541 data: { status: "inactive" }
542 });
543 await (0, import_api_fetch2.default)({
544 method: "DELETE",
545 url
546 });
547 dispatch.removeInstalledBlockType(block);
548 } catch (error) {
549 registry.dispatch(import_notices.store).createErrorNotice(
550 error.message || (0, import_i18n.__)("An error occurred.")
551 );
552 }
553 };
554 function addInstalledBlockType(item) {
555 return {
556 type: "ADD_INSTALLED_BLOCK_TYPE",
557 item
558 };
559 }
560 function removeInstalledBlockType(item) {
561 return {
562 type: "REMOVE_INSTALLED_BLOCK_TYPE",
563 item
564 };
565 }
566 function setIsInstalling(blockId, isInstalling2) {
567 return {
568 type: "SET_INSTALLING_BLOCK",
569 blockId,
570 isInstalling: isInstalling2
571 };
572 }
573 function setErrorNotice(blockId, message, isFatal = false) {
574 return {
575 type: "SET_ERROR_NOTICE",
576 blockId,
577 message,
578 isFatal
579 };
580 }
581 function clearErrorNotice(blockId) {
582 return {
583 type: "CLEAR_ERROR_NOTICE",
584 blockId
585 };
586 }
587
588 // packages/block-directory/build-module/store/resolvers.mjs
589 var resolvers_exports = {};
590 __export(resolvers_exports, {
591 getDownloadableBlocks: () => getDownloadableBlocks2
592 });
593
594 // node_modules/tslib/tslib.es6.mjs
595 var __assign = function() {
596 __assign = Object.assign || function __assign2(t) {
597 for (var s, i = 1, n = arguments.length; i < n; i++) {
598 s = arguments[i];
599 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
600 }
601 return t;
602 };
603 return __assign.apply(this, arguments);
604 };
605
606 // node_modules/lower-case/dist.es2015/index.js
607 function lowerCase(str) {
608 return str.toLowerCase();
609 }
610
611 // node_modules/no-case/dist.es2015/index.js
612 var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
613 var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
614 function noCase(input, options) {
615 if (options === void 0) {
616 options = {};
617 }
618 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;
619 var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
620 var start = 0;
621 var end = result.length;
622 while (result.charAt(start) === "\0")
623 start++;
624 while (result.charAt(end - 1) === "\0")
625 end--;
626 return result.slice(start, end).split("\0").map(transform).join(delimiter);
627 }
628 function replace(input, re, value) {
629 if (re instanceof RegExp)
630 return input.replace(re, value);
631 return re.reduce(function(input2, re2) {
632 return input2.replace(re2, value);
633 }, input);
634 }
635
636 // node_modules/pascal-case/dist.es2015/index.js
637 function pascalCaseTransform(input, index) {
638 var firstChar = input.charAt(0);
639 var lowerChars = input.substr(1).toLowerCase();
640 if (index > 0 && firstChar >= "0" && firstChar <= "9") {
641 return "_" + firstChar + lowerChars;
642 }
643 return "" + firstChar.toUpperCase() + lowerChars;
644 }
645 function pascalCase(input, options) {
646 if (options === void 0) {
647 options = {};
648 }
649 return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options));
650 }
651
652 // node_modules/camel-case/dist.es2015/index.js
653 function camelCaseTransform(input, index) {
654 if (index === 0)
655 return input.toLowerCase();
656 return pascalCaseTransform(input, index);
657 }
658 function camelCase(input, options) {
659 if (options === void 0) {
660 options = {};
661 }
662 return pascalCase(input, __assign({ transform: camelCaseTransform }, options));
663 }
664
665 // packages/block-directory/build-module/store/resolvers.mjs
666 var import_api_fetch3 = __toESM(require_api_fetch(), 1);
667 var getDownloadableBlocks2 = (filterValue) => async ({ dispatch }) => {
668 if (!filterValue) {
669 return;
670 }
671 try {
672 dispatch(fetchDownloadableBlocks(filterValue));
673 const results = await (0, import_api_fetch3.default)({
674 path: `wp/v2/block-directory/search?term=${filterValue}`
675 });
676 const blocks = results.map(
677 (result) => Object.fromEntries(
678 Object.entries(result).map(([key, value]) => [
679 camelCase(key),
680 value
681 ])
682 )
683 );
684 dispatch(receiveDownloadableBlocks(blocks, filterValue));
685 } catch {
686 dispatch(receiveDownloadableBlocks([], filterValue));
687 }
688 };
689
690 // packages/block-directory/build-module/store/index.mjs
691 var STORE_NAME = "core/block-directory";
692 var storeConfig = {
693 reducer: reducer_default,
694 selectors: selectors_exports,
695 actions: actions_exports,
696 resolvers: resolvers_exports
697 };
698 var store = (0, import_data3.createReduxStore)(STORE_NAME, storeConfig);
699 (0, import_data3.register)(store);
700
701 // packages/block-directory/build-module/components/auto-block-uninstaller/index.mjs
702 function AutoBlockUninstaller() {
703 const { uninstallBlockType: uninstallBlockType2 } = (0, import_data4.useDispatch)(store);
704 const shouldRemoveBlockTypes = (0, import_data4.useSelect)((select) => {
705 const { isAutosavingPost, isSavingPost } = select(import_editor.store);
706 return isSavingPost() && !isAutosavingPost();
707 }, []);
708 const unusedBlockTypes = (0, import_data4.useSelect)(
709 (select) => select(store).getUnusedBlockTypes(),
710 []
711 );
712 (0, import_element.useEffect)(() => {
713 if (shouldRemoveBlockTypes && unusedBlockTypes.length) {
714 unusedBlockTypes.forEach((blockType) => {
715 uninstallBlockType2(blockType);
716 (0, import_blocks2.unregisterBlockType)(blockType.name);
717 });
718 }
719 }, [shouldRemoveBlockTypes]);
720 return null;
721 }
722
723 // packages/block-directory/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.mjs
724 var import_block_editor3 = __toESM(require_block_editor(), 1);
725 var import_compose = __toESM(require_compose(), 1);
726 var import_element6 = __toESM(require_element(), 1);
727
728 // packages/block-directory/build-module/components/downloadable-blocks-panel/index.mjs
729 var import_i18n8 = __toESM(require_i18n(), 1);
730 var import_components4 = __toESM(require_components(), 1);
731 var import_core_data = __toESM(require_core_data(), 1);
732 var import_data8 = __toESM(require_data(), 1);
733 var import_blocks5 = __toESM(require_blocks(), 1);
734
735 // packages/block-directory/build-module/components/downloadable-blocks-list/index.mjs
736 var import_i18n5 = __toESM(require_i18n(), 1);
737 var import_components2 = __toESM(require_components(), 1);
738 var import_blocks4 = __toESM(require_blocks(), 1);
739 var import_data7 = __toESM(require_data(), 1);
740
741 // node_modules/clsx/dist/clsx.mjs
742 function r(e) {
743 var t, f, n = "";
744 if ("string" == typeof e || "number" == typeof e) n += e;
745 else if ("object" == typeof e) if (Array.isArray(e)) {
746 var o = e.length;
747 for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
748 } else for (f in e) e[f] && (n && (n += " "), n += f);
749 return n;
750 }
751 function clsx() {
752 for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
753 return n;
754 }
755 var clsx_default = clsx;
756
757 // packages/block-directory/build-module/components/downloadable-block-list-item/index.mjs
758 var import_i18n4 = __toESM(require_i18n(), 1);
759 var import_components = __toESM(require_components(), 1);
760 var import_element4 = __toESM(require_element(), 1);
761 var import_html_entities = __toESM(require_html_entities(), 1);
762 var import_blocks3 = __toESM(require_blocks(), 1);
763 var import_data6 = __toESM(require_data(), 1);
764
765 // node_modules/@base-ui/utils/esm/useRefWithInit.js
766 var React = __toESM(require_react(), 1);
767 var UNINITIALIZED = {};
768 function useRefWithInit(init, initArg) {
769 const ref = React.useRef(UNINITIALIZED);
770 if (ref.current === UNINITIALIZED) {
771 ref.current = init(initArg);
772 }
773 return ref;
774 }
775
776 // node_modules/@base-ui/utils/esm/warn.js
777 var set;
778 if (true) {
779 set = /* @__PURE__ */ new Set();
780 }
781 function warn(...messages) {
782 if (true) {
783 const messageKey = messages.join(" ");
784 if (!set.has(messageKey)) {
785 set.add(messageKey);
786 console.warn(`Base UI: ${messageKey}`);
787 }
788 }
789 }
790
791 // node_modules/@base-ui/react/esm/internals/useRenderElement.js
792 var React4 = __toESM(require_react(), 1);
793
794 // node_modules/@base-ui/utils/esm/useMergedRefs.js
795 function useMergedRefs(a, b, c, d) {
796 const forkRef = useRefWithInit(createForkRef).current;
797 if (didChange(forkRef, a, b, c, d)) {
798 update(forkRef, [a, b, c, d]);
799 }
800 return forkRef.callback;
801 }
802 function useMergedRefsN(refs) {
803 const forkRef = useRefWithInit(createForkRef).current;
804 if (didChangeN(forkRef, refs)) {
805 update(forkRef, refs);
806 }
807 return forkRef.callback;
808 }
809 function createForkRef() {
810 return {
811 callback: null,
812 cleanup: null,
813 refs: []
814 };
815 }
816 function didChange(forkRef, a, b, c, d) {
817 return forkRef.refs[0] !== a || forkRef.refs[1] !== b || forkRef.refs[2] !== c || forkRef.refs[3] !== d;
818 }
819 function didChangeN(forkRef, newRefs) {
820 return forkRef.refs.length !== newRefs.length || forkRef.refs.some((ref, index) => ref !== newRefs[index]);
821 }
822 function update(forkRef, refs) {
823 forkRef.refs = refs;
824 if (refs.every((ref) => ref == null)) {
825 forkRef.callback = null;
826 return;
827 }
828 forkRef.callback = (instance) => {
829 if (forkRef.cleanup) {
830 forkRef.cleanup();
831 forkRef.cleanup = null;
832 }
833 if (instance != null) {
834 const cleanupCallbacks = Array(refs.length).fill(null);
835 for (let i = 0; i < refs.length; i += 1) {
836 const ref = refs[i];
837 if (ref == null) {
838 continue;
839 }
840 switch (typeof ref) {
841 case "function": {
842 const refCleanup = ref(instance);
843 if (typeof refCleanup === "function") {
844 cleanupCallbacks[i] = refCleanup;
845 }
846 break;
847 }
848 case "object": {
849 ref.current = instance;
850 break;
851 }
852 default:
853 }
854 }
855 forkRef.cleanup = () => {
856 for (let i = 0; i < refs.length; i += 1) {
857 const ref = refs[i];
858 if (ref == null) {
859 continue;
860 }
861 switch (typeof ref) {
862 case "function": {
863 const cleanupCallback = cleanupCallbacks[i];
864 if (typeof cleanupCallback === "function") {
865 cleanupCallback();
866 } else {
867 ref(null);
868 }
869 break;
870 }
871 case "object": {
872 ref.current = null;
873 break;
874 }
875 default:
876 }
877 }
878 };
879 }
880 };
881 }
882
883 // node_modules/@base-ui/utils/esm/getReactElementRef.js
884 var React3 = __toESM(require_react(), 1);
885
886 // node_modules/@base-ui/utils/esm/reactVersion.js
887 var React2 = __toESM(require_react(), 1);
888 var majorVersion = parseInt(React2.version, 10);
889 function isReactVersionAtLeast(reactVersionToCheck) {
890 return majorVersion >= reactVersionToCheck;
891 }
892
893 // node_modules/@base-ui/utils/esm/getReactElementRef.js
894 function getReactElementRef(element) {
895 if (!/* @__PURE__ */ React3.isValidElement(element)) {
896 return null;
897 }
898 const reactElement = element;
899 const propsWithRef = reactElement.props;
900 return (isReactVersionAtLeast(19) ? propsWithRef?.ref : reactElement.ref) ?? null;
901 }
902
903 // node_modules/@base-ui/utils/esm/mergeObjects.js
904 function mergeObjects(a, b) {
905 if (a && !b) {
906 return a;
907 }
908 if (!a && b) {
909 return b;
910 }
911 if (a || b) {
912 return {
913 ...a,
914 ...b
915 };
916 }
917 return void 0;
918 }
919
920 // node_modules/@base-ui/utils/esm/empty.js
921 var EMPTY_ARRAY2 = Object.freeze([]);
922 var EMPTY_OBJECT = Object.freeze({});
923
924 // node_modules/@base-ui/react/esm/internals/getStateAttributesProps.js
925 function getStateAttributesProps(state, customMapping) {
926 const props = {};
927 for (const key in state) {
928 const value = state[key];
929 if (customMapping?.hasOwnProperty(key)) {
930 const customProps = customMapping[key](value);
931 if (customProps != null) {
932 Object.assign(props, customProps);
933 }
934 continue;
935 }
936 if (value === true) {
937 props[`data-${key.toLowerCase()}`] = "";
938 } else if (value) {
939 props[`data-${key.toLowerCase()}`] = value.toString();
940 }
941 }
942 return props;
943 }
944
945 // node_modules/@base-ui/react/esm/utils/resolveClassName.js
946 function resolveClassName(className, state) {
947 return typeof className === "function" ? className(state) : className;
948 }
949
950 // node_modules/@base-ui/react/esm/utils/resolveStyle.js
951 function resolveStyle(style, state) {
952 return typeof style === "function" ? style(state) : style;
953 }
954
955 // node_modules/@base-ui/react/esm/merge-props/mergeProps.js
956 var EMPTY_PROPS = {};
957 function mergeProps(a, b, c, d, e) {
958 if (!c && !d && !e && !a) {
959 return createInitialMergedProps(b);
960 }
961 let merged = createInitialMergedProps(a);
962 if (b) {
963 merged = mergeInto(merged, b);
964 }
965 if (c) {
966 merged = mergeInto(merged, c);
967 }
968 if (d) {
969 merged = mergeInto(merged, d);
970 }
971 if (e) {
972 merged = mergeInto(merged, e);
973 }
974 return merged;
975 }
976 function mergePropsN(props) {
977 if (props.length === 0) {
978 return EMPTY_PROPS;
979 }
980 if (props.length === 1) {
981 return createInitialMergedProps(props[0]);
982 }
983 let merged = createInitialMergedProps(props[0]);
984 for (let i = 1; i < props.length; i += 1) {
985 merged = mergeInto(merged, props[i]);
986 }
987 return merged;
988 }
989 function createInitialMergedProps(inputProps) {
990 if (isPropsGetter(inputProps)) {
991 return {
992 ...resolvePropsGetter(inputProps, EMPTY_PROPS)
993 };
994 }
995 return copyInitialProps(inputProps);
996 }
997 function mergeInto(merged, inputProps) {
998 if (isPropsGetter(inputProps)) {
999 return resolvePropsGetter(inputProps, merged);
1000 }
1001 return mutablyMergeInto(merged, inputProps);
1002 }
1003 function copyInitialProps(inputProps) {
1004 const copiedProps = {
1005 ...inputProps
1006 };
1007 for (const propName in copiedProps) {
1008 const propValue = copiedProps[propName];
1009 if (isEventHandler(propName, propValue)) {
1010 copiedProps[propName] = wrapEventHandler(propValue);
1011 }
1012 }
1013 return copiedProps;
1014 }
1015 function mutablyMergeInto(mergedProps, externalProps) {
1016 if (!externalProps) {
1017 return mergedProps;
1018 }
1019 for (const propName in externalProps) {
1020 const externalPropValue = externalProps[propName];
1021 switch (propName) {
1022 case "style": {
1023 mergedProps[propName] = mergeObjects(mergedProps.style, externalPropValue);
1024 break;
1025 }
1026 case "className": {
1027 mergedProps[propName] = mergeClassNames(mergedProps.className, externalPropValue);
1028 break;
1029 }
1030 default: {
1031 if (isEventHandler(propName, externalPropValue)) {
1032 mergedProps[propName] = mergeEventHandlers(mergedProps[propName], externalPropValue);
1033 } else {
1034 mergedProps[propName] = externalPropValue;
1035 }
1036 }
1037 }
1038 }
1039 return mergedProps;
1040 }
1041 function isEventHandler(key, value) {
1042 const code0 = key.charCodeAt(0);
1043 const code1 = key.charCodeAt(1);
1044 const code2 = key.charCodeAt(2);
1045 return code0 === 111 && code1 === 110 && code2 >= 65 && code2 <= 90 && (typeof value === "function" || typeof value === "undefined");
1046 }
1047 function isPropsGetter(inputProps) {
1048 return typeof inputProps === "function";
1049 }
1050 function resolvePropsGetter(inputProps, previousProps) {
1051 if (isPropsGetter(inputProps)) {
1052 return inputProps(previousProps);
1053 }
1054 return inputProps ?? EMPTY_PROPS;
1055 }
1056 function mergeEventHandlers(ourHandler, theirHandler) {
1057 if (!theirHandler) {
1058 return ourHandler;
1059 }
1060 if (!ourHandler) {
1061 return wrapEventHandler(theirHandler);
1062 }
1063 return (...args) => {
1064 const event = args[0];
1065 if (isSyntheticEvent(event)) {
1066 const baseUIEvent = event;
1067 makeEventPreventable(baseUIEvent);
1068 const result2 = theirHandler(...args);
1069 if (!baseUIEvent.baseUIHandlerPrevented) {
1070 ourHandler?.(...args);
1071 }
1072 return result2;
1073 }
1074 const result = theirHandler(...args);
1075 ourHandler?.(...args);
1076 return result;
1077 };
1078 }
1079 function wrapEventHandler(handler) {
1080 if (!handler) {
1081 return handler;
1082 }
1083 return (...args) => {
1084 const event = args[0];
1085 if (isSyntheticEvent(event)) {
1086 makeEventPreventable(event);
1087 }
1088 return handler(...args);
1089 };
1090 }
1091 function makeEventPreventable(event) {
1092 event.preventBaseUIHandler = () => {
1093 event.baseUIHandlerPrevented = true;
1094 };
1095 return event;
1096 }
1097 function mergeClassNames(ourClassName, theirClassName) {
1098 if (theirClassName) {
1099 if (ourClassName) {
1100 return theirClassName + " " + ourClassName;
1101 }
1102 return theirClassName;
1103 }
1104 return ourClassName;
1105 }
1106 function isSyntheticEvent(event) {
1107 return event != null && typeof event === "object" && "nativeEvent" in event;
1108 }
1109
1110 // node_modules/@base-ui/react/esm/internals/useRenderElement.js
1111 var import_react = __toESM(require_react(), 1);
1112 function useRenderElement(element, componentProps, params = {}) {
1113 const renderProp = componentProps.render;
1114 const outProps = useRenderElementProps(componentProps, params);
1115 if (params.enabled === false) {
1116 return null;
1117 }
1118 const state = params.state ?? EMPTY_OBJECT;
1119 return evaluateRenderProp(element, renderProp, outProps, state);
1120 }
1121 function useRenderElementProps(componentProps, params = {}) {
1122 const {
1123 className: classNameProp,
1124 style: styleProp,
1125 render: renderProp
1126 } = componentProps;
1127 const {
1128 state = EMPTY_OBJECT,
1129 ref,
1130 props,
1131 stateAttributesMapping,
1132 enabled = true
1133 } = params;
1134 const className = enabled ? resolveClassName(classNameProp, state) : void 0;
1135 const style = enabled ? resolveStyle(styleProp, state) : void 0;
1136 const stateProps = enabled ? getStateAttributesProps(state, stateAttributesMapping) : EMPTY_OBJECT;
1137 const resolvedProps = enabled && props ? resolveRenderFunctionProps(props) : void 0;
1138 const outProps = enabled ? mergeObjects(stateProps, resolvedProps) ?? {} : EMPTY_OBJECT;
1139 if (typeof document !== "undefined") {
1140 if (!enabled) {
1141 useMergedRefs(null, null);
1142 } else if (Array.isArray(ref)) {
1143 outProps.ref = useMergedRefsN([outProps.ref, getReactElementRef(renderProp), ...ref]);
1144 } else {
1145 outProps.ref = useMergedRefs(outProps.ref, getReactElementRef(renderProp), ref);
1146 }
1147 }
1148 if (!enabled) {
1149 return EMPTY_OBJECT;
1150 }
1151 if (className !== void 0) {
1152 outProps.className = mergeClassNames(outProps.className, className);
1153 }
1154 if (style !== void 0) {
1155 outProps.style = mergeObjects(outProps.style, style);
1156 }
1157 return outProps;
1158 }
1159 function resolveRenderFunctionProps(props) {
1160 if (Array.isArray(props)) {
1161 return mergePropsN(props);
1162 }
1163 return mergeProps(void 0, props);
1164 }
1165 var REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for("react.lazy");
1166 var COMPONENT_IDENTIFIER_PATTERN = /^[A-Z][A-Za-z0-9$]*$/;
1167 var LOWERCASE_CHARACTER_PATTERN = /[a-z]/;
1168 function evaluateRenderProp(element, render, props, state) {
1169 if (render) {
1170 if (typeof render === "function") {
1171 if (true) {
1172 warnIfRenderPropLooksLikeComponent(render);
1173 }
1174 return render(props, state);
1175 }
1176 const mergedProps = mergeProps(props, render.props);
1177 mergedProps.ref = props.ref;
1178 let newElement = render;
1179 if (newElement?.$$typeof === REACT_LAZY_TYPE) {
1180 const children = React4.Children.toArray(render);
1181 newElement = children[0];
1182 }
1183 if (true) {
1184 if (!/* @__PURE__ */ React4.isValidElement(newElement)) {
1185 throw new Error(["Base UI: The `render` prop was provided an invalid React element as `React.isValidElement(render)` is `false`.", "A valid React element must be provided to the `render` prop because it is cloned with props to replace the default element.", "https://base-ui.com/r/invalid-render-prop"].join("\n"));
1186 }
1187 }
1188 return /* @__PURE__ */ React4.cloneElement(newElement, mergedProps);
1189 }
1190 if (element) {
1191 if (typeof element === "string") {
1192 return renderTag(element, props);
1193 }
1194 }
1195 throw new Error(true ? "Base UI: Render element or function are not defined." : formatErrorMessage_default(8));
1196 }
1197 function warnIfRenderPropLooksLikeComponent(renderFn) {
1198 const functionName = renderFn.name;
1199 if (functionName.length === 0) {
1200 return;
1201 }
1202 if (!COMPONENT_IDENTIFIER_PATTERN.test(functionName)) {
1203 return;
1204 }
1205 if (!LOWERCASE_CHARACTER_PATTERN.test(functionName)) {
1206 return;
1207 }
1208 warn(`The \`render\` prop received a function named \`${functionName}\` that starts with an uppercase letter.`, "This usually means a React component was passed directly as `render={Component}`.", "Base UI calls `render` as a plain function, which can break the Rules of Hooks during reconciliation.", "If this is an intentional render callback, rename it to start with a lowercase letter.", "Use `render={<Component />}` or `render={(props) => <Component {...props} />}` instead.", "https://base-ui.com/r/invalid-render-prop");
1209 }
1210 function renderTag(Tag, props) {
1211 if (Tag === "button") {
1212 return /* @__PURE__ */ (0, import_react.createElement)("button", {
1213 type: "button",
1214 ...props,
1215 key: props.key
1216 });
1217 }
1218 if (Tag === "img") {
1219 return /* @__PURE__ */ (0, import_react.createElement)("img", {
1220 alt: "",
1221 ...props,
1222 key: props.key
1223 });
1224 }
1225 return /* @__PURE__ */ React4.createElement(Tag, props);
1226 }
1227
1228 // node_modules/@base-ui/react/esm/use-render/useRender.js
1229 function useRender(params) {
1230 return useRenderElement(params.defaultTagName ?? "div", params, params);
1231 }
1232
1233 // packages/icons/build-module/icon/index.mjs
1234 var import_element2 = __toESM(require_element(), 1);
1235 var icon_default = (0, import_element2.forwardRef)(
1236 ({ icon, size = 24, ...props }, ref) => {
1237 return (0, import_element2.cloneElement)(icon, {
1238 width: size,
1239 height: size,
1240 ...props,
1241 ref
1242 });
1243 }
1244 );
1245
1246 // packages/icons/build-module/library/star-empty.mjs
1247 var import_primitives = __toESM(require_primitives(), 1);
1248 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
1249 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)(import_primitives.Path, { fillRule: "evenodd", clipRule: "evenodd", 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" }) });
1250
1251 // packages/icons/build-module/library/star-filled.mjs
1252 var import_primitives2 = __toESM(require_primitives(), 1);
1253 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
1254 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" }) });
1255
1256 // packages/icons/build-module/library/star-half.mjs
1257 var import_primitives3 = __toESM(require_primitives(), 1);
1258 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
1259 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" }) });
1260
1261 // packages/ui/build-module/visually-hidden/visually-hidden.mjs
1262 var import_element3 = __toESM(require_element(), 1);
1263 if (typeof document !== "undefined" && true && !document.head.querySelector("style[data-wp-hash='c46e8cb841']")) {
1264 const style = document.createElement("style");
1265 style.setAttribute("data-wp-hash", "c46e8cb841");
1266 style.appendChild(document.createTextNode("@layer wp-ui-utilities, wp-ui-components, wp-ui-compositions, wp-ui-overrides;@layer wp-ui-components{.f37b9e2e191ebd66__visually-hidden{word-wrap:normal;border:0;clip-path:inset(50%);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;word-break:normal}}"));
1267 document.head.appendChild(style);
1268 }
1269 var style_default = { "visually-hidden": "f37b9e2e191ebd66__visually-hidden" };
1270 var VisuallyHidden = (0, import_element3.forwardRef)(
1271 function VisuallyHidden2({ render, ...restProps }, ref) {
1272 const element = useRender({
1273 render,
1274 ref,
1275 props: mergeProps(
1276 { className: style_default["visually-hidden"] },
1277 restProps,
1278 {
1279 // @ts-expect-error Arbitrary data-* attributes aren't indexable on the typed div props. Kept hardcoded so consumers can't change or remove it.
1280 "data-visually-hidden": ""
1281 }
1282 )
1283 });
1284 return element;
1285 }
1286 );
1287
1288 // packages/block-directory/build-module/components/block-ratings/stars.mjs
1289 var import_i18n2 = __toESM(require_i18n(), 1);
1290 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
1291 function Stars({ rating }) {
1292 const stars = Math.round(rating / 0.5) * 0.5;
1293 const fullStarCount = Math.floor(rating);
1294 const halfStarCount = Math.ceil(rating - fullStarCount);
1295 const emptyStarCount = 5 - (fullStarCount + halfStarCount);
1296 return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1297 "span",
1298 {
1299 "aria-label": (0, import_i18n2.sprintf)(
1300 /* translators: %s: number of stars. */
1301 (0, import_i18n2.__)("%s out of 5 stars"),
1302 stars
1303 ),
1304 children: [
1305 Array.from({ length: fullStarCount }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1306 icon_default,
1307 {
1308 className: "block-directory-block-ratings__star-full",
1309 icon: star_filled_default,
1310 size: 16
1311 },
1312 `full_stars_${i}`
1313 )),
1314 Array.from({ length: halfStarCount }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1315 icon_default,
1316 {
1317 className: "block-directory-block-ratings__star-half-full",
1318 icon: star_half_default,
1319 size: 16
1320 },
1321 `half_stars_${i}`
1322 )),
1323 Array.from({ length: emptyStarCount }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1324 icon_default,
1325 {
1326 className: "block-directory-block-ratings__star-empty",
1327 icon: star_empty_default,
1328 size: 16
1329 },
1330 `empty_stars_${i}`
1331 ))
1332 ]
1333 }
1334 );
1335 }
1336 var stars_default = Stars;
1337
1338 // packages/block-directory/build-module/components/block-ratings/index.mjs
1339 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
1340 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 }) });
1341 var block_ratings_default = BlockRatings;
1342
1343 // packages/block-directory/build-module/components/downloadable-block-icon/index.mjs
1344 var import_block_editor2 = __toESM(require_block_editor(), 1);
1345 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
1346 function DownloadableBlockIcon({ icon }) {
1347 const className = "block-directory-downloadable-block-icon";
1348 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 });
1349 }
1350 var downloadable_block_icon_default = DownloadableBlockIcon;
1351
1352 // packages/block-directory/build-module/components/downloadable-block-notice/index.mjs
1353 var import_i18n3 = __toESM(require_i18n(), 1);
1354 var import_data5 = __toESM(require_data(), 1);
1355 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
1356 var DownloadableBlockNotice = ({ block }) => {
1357 const errorNotice = (0, import_data5.useSelect)(
1358 (select) => select(store).getErrorNoticeForBlock(block.id),
1359 [block]
1360 );
1361 if (!errorNotice) {
1362 return null;
1363 }
1364 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: [
1365 errorNotice.message,
1366 errorNotice.isFatal ? " " + (0, import_i18n3.__)("Try reloading the page.") : null
1367 ] }) });
1368 };
1369 var downloadable_block_notice_default = DownloadableBlockNotice;
1370
1371 // packages/block-directory/build-module/components/downloadable-block-list-item/index.mjs
1372 var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
1373 function getDownloadableBlockLabel({ title, rating, ratingCount }, { hasNotice, isInstalled, isInstalling: isInstalling2 }) {
1374 const stars = Math.round(rating / 0.5) * 0.5;
1375 if (!isInstalled && hasNotice) {
1376 return (0, import_i18n4.sprintf)("Retry installing %s.", (0, import_html_entities.decodeEntities)(title));
1377 }
1378 if (isInstalled) {
1379 return (0, import_i18n4.sprintf)("Add %s.", (0, import_html_entities.decodeEntities)(title));
1380 }
1381 if (isInstalling2) {
1382 return (0, import_i18n4.sprintf)("Installing %s.", (0, import_html_entities.decodeEntities)(title));
1383 }
1384 if (ratingCount < 1) {
1385 return (0, import_i18n4.sprintf)("Install %s.", (0, import_html_entities.decodeEntities)(title));
1386 }
1387 return (0, import_i18n4.sprintf)(
1388 /* translators: 1: block title, 2: average rating, 3: total ratings count. */
1389 (0, import_i18n4._n)(
1390 "Install %1$s. %2$s stars with %3$s review.",
1391 "Install %1$s. %2$s stars with %3$s reviews.",
1392 ratingCount
1393 ),
1394 (0, import_html_entities.decodeEntities)(title),
1395 stars,
1396 ratingCount
1397 );
1398 }
1399 function DownloadableBlockListItem({ item, onClick }) {
1400 const { author, description, icon, rating, title } = item;
1401 const isInstalled = !!(0, import_blocks3.getBlockType)(item.name);
1402 const { hasNotice, isInstalling: isInstalling2, isInstallable } = (0, import_data6.useSelect)(
1403 (select) => {
1404 const { getErrorNoticeForBlock: getErrorNoticeForBlock2, isInstalling: isBlockInstalling } = select(store);
1405 const notice = getErrorNoticeForBlock2(item.id);
1406 const hasFatal = notice && notice.isFatal;
1407 return {
1408 hasNotice: !!notice,
1409 isInstalling: isBlockInstalling(item.id),
1410 isInstallable: !hasFatal
1411 };
1412 },
1413 [item]
1414 );
1415 let statusText = "";
1416 if (isInstalled) {
1417 statusText = (0, import_i18n4.__)("Installed!");
1418 } else if (isInstalling2) {
1419 statusText = (0, import_i18n4.__)("Installing\u2026");
1420 }
1421 const itemLabel = getDownloadableBlockLabel(item, {
1422 hasNotice,
1423 isInstalled,
1424 isInstalling: isInstalling2
1425 });
1426 return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components.Tooltip, { placement: "top", text: itemLabel, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1427 import_components.Composite.Item,
1428 {
1429 className: clsx_default(
1430 "block-directory-downloadable-block-list-item",
1431 isInstalling2 && "is-installing"
1432 ),
1433 accessibleWhenDisabled: true,
1434 disabled: isInstalling2 || !isInstallable,
1435 onClick: (event) => {
1436 event.preventDefault();
1437 onClick();
1438 },
1439 "aria-label": itemLabel,
1440 type: "button",
1441 role: "option",
1442 children: [
1443 /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "block-directory-downloadable-block-list-item__icon", children: [
1444 /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(downloadable_block_icon_default, { icon, title }),
1445 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 })
1446 ] }),
1447 /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "block-directory-downloadable-block-list-item__details", children: [
1448 /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "block-directory-downloadable-block-list-item__title", children: (0, import_element4.createInterpolateElement)(
1449 (0, import_i18n4.sprintf)(
1450 /* translators: 1: block title. 2: author name. */
1451 (0, import_i18n4.__)("%1$s <span>by %2$s</span>"),
1452 (0, import_html_entities.decodeEntities)(title),
1453 author
1454 ),
1455 {
1456 span: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "block-directory-downloadable-block-list-item__author" })
1457 }
1458 ) }),
1459 hasNotice ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(downloadable_block_notice_default, { block: item }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1460 /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "block-directory-downloadable-block-list-item__desc", children: !!statusText ? statusText : (0, import_html_entities.decodeEntities)(description) }),
1461 isInstallable && !(isInstalled || isInstalling2) && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(VisuallyHidden, { children: (0, import_i18n4.__)("Install block") })
1462 ] })
1463 ] })
1464 ]
1465 }
1466 ) });
1467 }
1468 var downloadable_block_list_item_default = DownloadableBlockListItem;
1469
1470 // packages/block-directory/build-module/components/downloadable-blocks-list/index.mjs
1471 var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
1472 var noop = () => {
1473 };
1474 function DownloadableBlocksList({ items, onHover = noop, onSelect }) {
1475 const { installBlockType: installBlockType2 } = (0, import_data7.useDispatch)(store);
1476 if (!items.length) {
1477 return null;
1478 }
1479 return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1480 import_components2.Composite,
1481 {
1482 role: "listbox",
1483 className: "block-directory-downloadable-blocks-list",
1484 "aria-label": (0, import_i18n5.__)("Blocks available for install"),
1485 children: items.map((item) => {
1486 return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1487 downloadable_block_list_item_default,
1488 {
1489 onClick: () => {
1490 if ((0, import_blocks4.getBlockType)(item.name)) {
1491 onSelect(item);
1492 } else {
1493 installBlockType2(item).then((success) => {
1494 if (success) {
1495 onSelect(item);
1496 }
1497 });
1498 }
1499 onHover(null);
1500 },
1501 onHover,
1502 item
1503 },
1504 item.id
1505 );
1506 })
1507 }
1508 );
1509 }
1510 var downloadable_blocks_list_default = DownloadableBlocksList;
1511
1512 // packages/block-directory/build-module/components/downloadable-blocks-panel/inserter-panel.mjs
1513 var import_i18n6 = __toESM(require_i18n(), 1);
1514 var import_element5 = __toESM(require_element(), 1);
1515 var import_a11y = __toESM(require_a11y(), 1);
1516 var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
1517 function DownloadableBlocksInserterPanel({
1518 children,
1519 downloadableItems,
1520 hasLocalBlocks
1521 }) {
1522 const count = downloadableItems.length;
1523 (0, import_element5.useEffect)(() => {
1524 (0, import_a11y.speak)(
1525 (0, import_i18n6.sprintf)(
1526 /* translators: %d: number of available blocks. */
1527 (0, import_i18n6._n)(
1528 "%d additional block is available to install.",
1529 "%d additional blocks are available to install.",
1530 count
1531 ),
1532 count
1533 )
1534 );
1535 }, [count]);
1536 return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
1537 !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.") }),
1538 /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "block-editor-inserter__quick-inserter-separator" }),
1539 /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "block-directory-downloadable-blocks-panel", children: [
1540 /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "block-directory-downloadable-blocks-panel__header", children: [
1541 /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("h2", { className: "block-directory-downloadable-blocks-panel__title", children: (0, import_i18n6.__)("Available to install") }),
1542 /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "block-directory-downloadable-blocks-panel__description", children: (0, import_i18n6.__)(
1543 "Select a block to install and add it to your post."
1544 ) })
1545 ] }),
1546 children
1547 ] })
1548 ] });
1549 }
1550 var inserter_panel_default = DownloadableBlocksInserterPanel;
1551
1552 // packages/block-directory/build-module/components/downloadable-blocks-panel/no-results.mjs
1553 var import_i18n7 = __toESM(require_i18n(), 1);
1554 var import_components3 = __toESM(require_components(), 1);
1555 var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
1556 function DownloadableBlocksNoResults() {
1557 return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
1558 /* @__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.") }) }),
1559 /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "block-editor-inserter__tips", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_components3.Tip, { children: [
1560 (0, import_i18n7.__)("Interested in creating your own block?"),
1561 /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("br", {}),
1562 /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_components3.ExternalLink, { href: "https://developer.wordpress.org/block-editor/", children: [
1563 (0, import_i18n7.__)("Get started here"),
1564 "."
1565 ] })
1566 ] }) })
1567 ] });
1568 }
1569 var no_results_default = DownloadableBlocksNoResults;
1570
1571 // packages/block-directory/build-module/components/downloadable-blocks-panel/index.mjs
1572 var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1);
1573 var EMPTY_ARRAY3 = [];
1574 var useDownloadableBlocks = (filterValue) => (0, import_data8.useSelect)(
1575 (select) => {
1576 const {
1577 getDownloadableBlocks: getDownloadableBlocks3,
1578 isRequestingDownloadableBlocks: isRequestingDownloadableBlocks2,
1579 getInstalledBlockTypes: getInstalledBlockTypes2
1580 } = select(store);
1581 const hasPermission = select(import_core_data.store).canUser(
1582 "read",
1583 "block-directory/search"
1584 );
1585 let downloadableBlocks2 = EMPTY_ARRAY3;
1586 if (hasPermission) {
1587 downloadableBlocks2 = getDownloadableBlocks3(filterValue);
1588 const installedBlockTypes = getInstalledBlockTypes2();
1589 const installableBlocks = downloadableBlocks2.filter(
1590 ({ name }) => {
1591 const isJustInstalled = installedBlockTypes.some(
1592 (blockType) => blockType.name === name
1593 );
1594 const isPreviouslyInstalled = (0, import_blocks5.getBlockType)(name);
1595 return isJustInstalled || !isPreviouslyInstalled;
1596 }
1597 );
1598 if (installableBlocks.length !== downloadableBlocks2.length) {
1599 downloadableBlocks2 = installableBlocks;
1600 }
1601 if (downloadableBlocks2.length === 0) {
1602 downloadableBlocks2 = EMPTY_ARRAY3;
1603 }
1604 }
1605 return {
1606 hasPermission,
1607 downloadableBlocks: downloadableBlocks2,
1608 isLoading: isRequestingDownloadableBlocks2(filterValue)
1609 };
1610 },
1611 [filterValue]
1612 );
1613 function DownloadableBlocksPanel({
1614 onSelect,
1615 onHover,
1616 hasLocalBlocks,
1617 isTyping,
1618 filterValue
1619 }) {
1620 const { hasPermission, downloadableBlocks: downloadableBlocks2, isLoading } = useDownloadableBlocks(filterValue);
1621 if (hasPermission === void 0 || isLoading || isTyping) {
1622 return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
1623 hasPermission && !hasLocalBlocks && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
1624 /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "block-directory-downloadable-blocks-panel__no-local", children: (0, import_i18n8.__)(
1625 "No results available from your installed blocks."
1626 ) }),
1627 /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "block-editor-inserter__quick-inserter-separator" })
1628 ] }),
1629 /* @__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, {}) })
1630 ] });
1631 }
1632 if (false === hasPermission) {
1633 if (!hasLocalBlocks) {
1634 return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(no_results_default, {});
1635 }
1636 return null;
1637 }
1638 if (downloadableBlocks2.length === 0) {
1639 return hasLocalBlocks ? null : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(no_results_default, {});
1640 }
1641 return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1642 inserter_panel_default,
1643 {
1644 downloadableItems: downloadableBlocks2,
1645 hasLocalBlocks,
1646 children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1647 downloadable_blocks_list_default,
1648 {
1649 items: downloadableBlocks2,
1650 onSelect,
1651 onHover
1652 }
1653 )
1654 }
1655 );
1656 }
1657
1658 // packages/block-directory/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.mjs
1659 var import_jsx_runtime13 = __toESM(require_jsx_runtime(), 1);
1660 function InserterMenuDownloadableBlocksPanel() {
1661 const [debouncedFilterValue, setFilterValue] = (0, import_element6.useState)("");
1662 const debouncedSetFilterValue = (0, import_compose.debounce)(setFilterValue, 400);
1663 return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_block_editor3.__unstableInserterMenuExtension, { children: ({ onSelect, onHover, filterValue, hasItems }) => {
1664 if (debouncedFilterValue !== filterValue) {
1665 debouncedSetFilterValue(filterValue);
1666 }
1667 if (!debouncedFilterValue) {
1668 return null;
1669 }
1670 return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1671 DownloadableBlocksPanel,
1672 {
1673 onSelect,
1674 onHover,
1675 filterValue: debouncedFilterValue,
1676 hasLocalBlocks: hasItems,
1677 isTyping: filterValue !== debouncedFilterValue
1678 }
1679 );
1680 } });
1681 }
1682 var inserter_menu_downloadable_blocks_panel_default = InserterMenuDownloadableBlocksPanel;
1683
1684 // packages/block-directory/build-module/plugins/installed-blocks-pre-publish-panel/index.mjs
1685 var import_i18n10 = __toESM(require_i18n(), 1);
1686 var import_data9 = __toESM(require_data(), 1);
1687 var import_editor2 = __toESM(require_editor(), 1);
1688
1689 // packages/block-directory/build-module/components/compact-list/index.mjs
1690 var import_i18n9 = __toESM(require_i18n(), 1);
1691 var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1);
1692 function CompactList({ items }) {
1693 if (!items.length) {
1694 return null;
1695 }
1696 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: [
1697 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(downloadable_block_icon_default, { icon, title }),
1698 /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "block-directory-compact-list__item-details", children: [
1699 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "block-directory-compact-list__item-title", children: title }),
1700 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "block-directory-compact-list__item-author", children: (0, import_i18n9.sprintf)(
1701 /* translators: %s: Name of the block author. */
1702 (0, import_i18n9.__)("By %s"),
1703 author
1704 ) })
1705 ] })
1706 ] }, id)) });
1707 }
1708
1709 // packages/block-directory/build-module/plugins/installed-blocks-pre-publish-panel/index.mjs
1710 var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1);
1711 function InstalledBlocksPrePublishPanel() {
1712 const newBlockTypes = (0, import_data9.useSelect)(
1713 (select) => select(store).getNewBlockTypes(),
1714 []
1715 );
1716 if (!newBlockTypes.length) {
1717 return null;
1718 }
1719 return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
1720 import_editor2.PluginPrePublishPanel,
1721 {
1722 title: (0, import_i18n10.sprintf)(
1723 // translators: %d: number of blocks (number).
1724 (0, import_i18n10._n)(
1725 "Added: %d block",
1726 "Added: %d blocks",
1727 newBlockTypes.length
1728 ),
1729 newBlockTypes.length
1730 ),
1731 initialOpen: true,
1732 children: [
1733 /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "installed-blocks-pre-publish-panel__copy", children: (0, import_i18n10._n)(
1734 "The following block has been added to your site.",
1735 "The following blocks have been added to your site.",
1736 newBlockTypes.length
1737 ) }),
1738 /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(CompactList, { items: newBlockTypes })
1739 ]
1740 }
1741 );
1742 }
1743
1744 // packages/block-directory/build-module/plugins/get-install-missing/index.mjs
1745 var import_i18n12 = __toESM(require_i18n(), 1);
1746 var import_components6 = __toESM(require_components(), 1);
1747 var import_blocks7 = __toESM(require_blocks(), 1);
1748 var import_element7 = __toESM(require_element(), 1);
1749 var import_data11 = __toESM(require_data(), 1);
1750 var import_core_data2 = __toESM(require_core_data(), 1);
1751 var import_block_editor5 = __toESM(require_block_editor(), 1);
1752
1753 // packages/block-directory/build-module/plugins/get-install-missing/install-button.mjs
1754 var import_i18n11 = __toESM(require_i18n(), 1);
1755 var import_components5 = __toESM(require_components(), 1);
1756 var import_blocks6 = __toESM(require_blocks(), 1);
1757 var import_data10 = __toESM(require_data(), 1);
1758 var import_block_editor4 = __toESM(require_block_editor(), 1);
1759 var import_jsx_runtime16 = __toESM(require_jsx_runtime(), 1);
1760 function InstallButton({ attributes, block, clientId }) {
1761 const isInstallingBlock = (0, import_data10.useSelect)(
1762 (select) => select(store).isInstalling(block.id),
1763 [block.id]
1764 );
1765 const { installBlockType: installBlockType2 } = (0, import_data10.useDispatch)(store);
1766 const { replaceBlock } = (0, import_data10.useDispatch)(import_block_editor4.store);
1767 return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1768 import_components5.Button,
1769 {
1770 __next40pxDefaultSize: true,
1771 onClick: () => installBlockType2(block).then((success) => {
1772 if (success) {
1773 const blockType = (0, import_blocks6.getBlockType)(block.name);
1774 const [originalBlock] = (0, import_blocks6.parse)(
1775 attributes.originalContent
1776 );
1777 if (originalBlock && blockType) {
1778 replaceBlock(
1779 clientId,
1780 (0, import_blocks6.createBlock)(
1781 blockType.name,
1782 originalBlock.attributes,
1783 originalBlock.innerBlocks
1784 )
1785 );
1786 }
1787 }
1788 }),
1789 accessibleWhenDisabled: true,
1790 disabled: isInstallingBlock,
1791 isBusy: isInstallingBlock,
1792 variant: "primary",
1793 children: (0, import_i18n11.sprintf)(
1794 /* translators: %s: block name */
1795 (0, import_i18n11.__)("Install %s"),
1796 block.title
1797 )
1798 }
1799 );
1800 }
1801
1802 // packages/block-directory/build-module/plugins/get-install-missing/index.mjs
1803 var import_jsx_runtime17 = __toESM(require_jsx_runtime(), 1);
1804 var getInstallMissing = (OriginalComponent) => (props) => {
1805 const { originalName } = props.attributes;
1806 const { block, hasPermission } = (0, import_data11.useSelect)(
1807 (select) => {
1808 const { getDownloadableBlocks: getDownloadableBlocks3 } = select(store);
1809 const blocks = getDownloadableBlocks3(
1810 "block:" + originalName
1811 ).filter(({ name }) => originalName === name);
1812 return {
1813 hasPermission: select(import_core_data2.store).canUser(
1814 "read",
1815 "block-directory/search"
1816 ),
1817 block: blocks.length && blocks[0]
1818 };
1819 },
1820 [originalName]
1821 );
1822 if (!hasPermission || !block) {
1823 return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(OriginalComponent, { ...props });
1824 }
1825 return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ModifiedWarning, { ...props, originalBlock: block });
1826 };
1827 var ModifiedWarning = ({ originalBlock, ...props }) => {
1828 const { originalName, originalUndelimitedContent, clientId } = props.attributes;
1829 const { replaceBlock } = (0, import_data11.useDispatch)(import_block_editor5.store);
1830 const convertToHTML = () => {
1831 replaceBlock(
1832 props.clientId,
1833 (0, import_blocks7.createBlock)("core/html", {
1834 content: originalUndelimitedContent
1835 })
1836 );
1837 };
1838 const hasContent = !!originalUndelimitedContent;
1839 const hasHTMLBlock = (0, import_data11.useSelect)(
1840 (select) => {
1841 const { canInsertBlockType, getBlockRootClientId } = select(import_block_editor5.store);
1842 return canInsertBlockType(
1843 "core/html",
1844 getBlockRootClientId(clientId)
1845 );
1846 },
1847 [clientId]
1848 );
1849 let messageHTML = (0, import_i18n12.sprintf)(
1850 /* translators: %s: block name */
1851 (0, import_i18n12.__)(
1852 "Your site doesn\u2019t include support for the %s block. You can try installing the block or remove it entirely."
1853 ),
1854 originalBlock.title || originalName
1855 );
1856 const actions = [
1857 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1858 InstallButton,
1859 {
1860 block: originalBlock,
1861 attributes: props.attributes,
1862 clientId: props.clientId
1863 },
1864 "install"
1865 )
1866 ];
1867 if (hasContent && hasHTMLBlock) {
1868 messageHTML = (0, import_i18n12.sprintf)(
1869 /* translators: %s: block name */
1870 (0, import_i18n12.__)(
1871 "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."
1872 ),
1873 originalBlock.title || originalName
1874 );
1875 actions.push(
1876 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1877 import_components6.Button,
1878 {
1879 __next40pxDefaultSize: true,
1880 onClick: convertToHTML,
1881 variant: "tertiary",
1882 children: (0, import_i18n12.__)("Keep as HTML")
1883 },
1884 "convert"
1885 )
1886 );
1887 }
1888 return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { ...(0, import_block_editor5.useBlockProps)(), children: [
1889 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_block_editor5.Warning, { actions, children: messageHTML }),
1890 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_element7.RawHTML, { children: originalUndelimitedContent })
1891 ] });
1892 };
1893 var get_install_missing_default = getInstallMissing;
1894
1895 // packages/block-directory/build-module/plugins/index.mjs
1896 var import_jsx_runtime18 = __toESM(require_jsx_runtime(), 1);
1897 (0, import_plugins.registerPlugin)("block-directory", {
1898 // The icon is explicitly set to undefined to prevent PluginPrePublishPanel
1899 // from rendering the fallback icon pluginIcon.
1900 icon: void 0,
1901 render() {
1902 return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
1903 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(AutoBlockUninstaller, {}),
1904 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(inserter_menu_downloadable_blocks_panel_default, {}),
1905 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(InstalledBlocksPrePublishPanel, {})
1906 ] });
1907 }
1908 });
1909 (0, import_hooks.addFilter)(
1910 "blocks.registerBlockType",
1911 "block-directory/fallback",
1912 (settings, name) => {
1913 if (name !== "core/missing") {
1914 return settings;
1915 }
1916 settings.edit = get_install_missing_default(settings.edit);
1917 return settings;
1918 }
1919 );
1920 return __toCommonJS(index_exports);
1921 })();
1922 //# sourceMappingURL=index.js.map
1923