| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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.mjs 161 var index_exports = {}; 162 __export(index_exports, { 163 store: () => store 164 }); 165 166 // packages/block-directory/build-module/plugins/index.mjs 167 var import_plugins = __toESM(require_plugins(), 1); 168 var import_hooks = __toESM(require_hooks(), 1); 169 170 // packages/block-directory/build-module/components/auto-block-uninstaller/index.mjs 171 var import_blocks2 = __toESM(require_blocks(), 1); 172 var import_data4 = __toESM(require_data(), 1); 173 var import_element = __toESM(require_element(), 1); 174 var import_editor = __toESM(require_editor(), 1); 175 176 // packages/block-directory/build-module/store/index.mjs 177 var import_data3 = __toESM(require_data(), 1); 178 179 // packages/block-directory/build-module/store/reducer.mjs 180 var import_data = __toESM(require_data(), 1); 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.mjs 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(), 1); 267 var import_block_editor = __toESM(require_block_editor(), 1); 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.mjs 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(), 1); 358 var import_i18n = __toESM(require_i18n(), 1); 359 var import_api_fetch2 = __toESM(require_api_fetch(), 1); 360 var import_notices = __toESM(require_notices(), 1); 361 var import_url = __toESM(require_url(), 1); 362 363 // packages/block-directory/build-module/store/load-assets.mjs 364 var import_api_fetch = __toESM(require_api_fetch(), 1); 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.mjs 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.mjs 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.mjs 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.mjs 659 var import_api_fetch3 = __toESM(require_api_fetch(), 1); 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.mjs 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.mjs 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.mjs 717 var import_block_editor3 = __toESM(require_block_editor(), 1); 718 var import_compose = __toESM(require_compose(), 1); 719 var import_element5 = __toESM(require_element(), 1); 720 721 // packages/block-directory/build-module/components/downloadable-blocks-panel/index.mjs 722 var import_i18n8 = __toESM(require_i18n(), 1); 723 var import_components4 = __toESM(require_components(), 1); 724 var import_core_data = __toESM(require_core_data(), 1); 725 var import_data8 = __toESM(require_data(), 1); 726 var import_blocks5 = __toESM(require_blocks(), 1); 727 728 // packages/block-directory/build-module/components/downloadable-blocks-list/index.mjs 729 var import_i18n5 = __toESM(require_i18n(), 1); 730 var import_components2 = __toESM(require_components(), 1); 731 var import_blocks4 = __toESM(require_blocks(), 1); 732 var import_data7 = __toESM(require_data(), 1); 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.mjs 751 var import_i18n4 = __toESM(require_i18n(), 1); 752 var import_components = __toESM(require_components(), 1); 753 var import_element3 = __toESM(require_element(), 1); 754 var import_html_entities = __toESM(require_html_entities(), 1); 755 var import_blocks3 = __toESM(require_blocks(), 1); 756 var import_data6 = __toESM(require_data(), 1); 757 758 // packages/block-directory/build-module/components/block-ratings/stars.mjs 759 var import_i18n2 = __toESM(require_i18n(), 1); 760 761 // packages/icons/build-module/icon/index.mjs 762 var import_element2 = __toESM(require_element(), 1); 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.mjs 775 var import_primitives = __toESM(require_primitives(), 1); 776 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1); 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)(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" }) }); 778 779 // packages/icons/build-module/library/star-filled.mjs 780 var import_primitives2 = __toESM(require_primitives(), 1); 781 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1); 782 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" }) }); 783 784 // packages/icons/build-module/library/star-half.mjs 785 var import_primitives3 = __toESM(require_primitives(), 1); 786 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1); 787 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" }) }); 788 789 // packages/block-directory/build-module/components/block-ratings/stars.mjs 790 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1); 791 function Stars({ rating }) { 792 const stars = Math.round(rating / 0.5) * 0.5; 793 const fullStarCount = Math.floor(rating); 794 const halfStarCount = Math.ceil(rating - fullStarCount); 795 const emptyStarCount = 5 - (fullStarCount + halfStarCount); 796 return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)( 797 "span", 798 { 799 "aria-label": (0, import_i18n2.sprintf)( 800 /* translators: %s: number of stars. */ 801 (0, import_i18n2.__)("%s out of 5 stars"), 802 stars 803 ), 804 children: [ 805 Array.from({ length: fullStarCount }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( 806 icon_default, 807 { 808 className: "block-directory-block-ratings__star-full", 809 icon: star_filled_default, 810 size: 16 811 }, 812 `full_stars_$i}` 813 )), 814 Array.from({ length: halfStarCount }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( 815 icon_default, 816 { 817 className: "block-directory-block-ratings__star-half-full", 818 icon: star_half_default, 819 size: 16 820 }, 821 `half_stars_$i}` 822 )), 823 Array.from({ length: emptyStarCount }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( 824 icon_default, 825 { 826 className: "block-directory-block-ratings__star-empty", 827 icon: star_empty_default, 828 size: 16 829 }, 830 `empty_stars_$i}` 831 )) 832 ] 833 } 834 ); 835 } 836 var stars_default = Stars; 837 838 // packages/block-directory/build-module/components/block-ratings/index.mjs 839 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1); 840 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 }) }); 841 var block_ratings_default = BlockRatings; 842 843 // packages/block-directory/build-module/components/downloadable-block-icon/index.mjs 844 var import_block_editor2 = __toESM(require_block_editor(), 1); 845 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1); 846 function DownloadableBlockIcon({ icon }) { 847 const className = "block-directory-downloadable-block-icon"; 848 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 }); 849 } 850 var downloadable_block_icon_default = DownloadableBlockIcon; 851 852 // packages/block-directory/build-module/components/downloadable-block-notice/index.mjs 853 var import_i18n3 = __toESM(require_i18n(), 1); 854 var import_data5 = __toESM(require_data(), 1); 855 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1); 856 var DownloadableBlockNotice = ({ block }) => { 857 const errorNotice = (0, import_data5.useSelect)( 858 (select) => select(store).getErrorNoticeForBlock(block.id), 859 [block] 860 ); 861 if (!errorNotice) { 862 return null; 863 } 864 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: [ 865 errorNotice.message, 866 errorNotice.isFatal ? " " + (0, import_i18n3.__)("Try reloading the page.") : null 867 ] }) }); 868 }; 869 var downloadable_block_notice_default = DownloadableBlockNotice; 870 871 // packages/block-directory/build-module/components/downloadable-block-list-item/index.mjs 872 var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1); 873 function getDownloadableBlockLabel({ title, rating, ratingCount }, { hasNotice, isInstalled, isInstalling: isInstalling2 }) { 874 const stars = Math.round(rating / 0.5) * 0.5; 875 if (!isInstalled && hasNotice) { 876 return (0, import_i18n4.sprintf)("Retry installing %s.", (0, import_html_entities.decodeEntities)(title)); 877 } 878 if (isInstalled) { 879 return (0, import_i18n4.sprintf)("Add %s.", (0, import_html_entities.decodeEntities)(title)); 880 } 881 if (isInstalling2) { 882 return (0, import_i18n4.sprintf)("Installing %s.", (0, import_html_entities.decodeEntities)(title)); 883 } 884 if (ratingCount < 1) { 885 return (0, import_i18n4.sprintf)("Install %s.", (0, import_html_entities.decodeEntities)(title)); 886 } 887 return (0, import_i18n4.sprintf)( 888 /* translators: 1: block title, 2: average rating, 3: total ratings count. */ 889 (0, import_i18n4._n)( 890 "Install %1$s. %2$s stars with %3$s review.", 891 "Install %1$s. %2$s stars with %3$s reviews.", 892 ratingCount 893 ), 894 (0, import_html_entities.decodeEntities)(title), 895 stars, 896 ratingCount 897 ); 898 } 899 function DownloadableBlockListItem({ item, onClick }) { 900 const { author, description, icon, rating, title } = item; 901 const isInstalled = !!(0, import_blocks3.getBlockType)(item.name); 902 const { hasNotice, isInstalling: isInstalling2, isInstallable } = (0, import_data6.useSelect)( 903 (select) => { 904 const { getErrorNoticeForBlock: getErrorNoticeForBlock2, isInstalling: isBlockInstalling } = select(store); 905 const notice = getErrorNoticeForBlock2(item.id); 906 const hasFatal = notice && notice.isFatal; 907 return { 908 hasNotice: !!notice, 909 isInstalling: isBlockInstalling(item.id), 910 isInstallable: !hasFatal 911 }; 912 }, 913 [item] 914 ); 915 let statusText = ""; 916 if (isInstalled) { 917 statusText = (0, import_i18n4.__)("Installed!"); 918 } else if (isInstalling2) { 919 statusText = (0, import_i18n4.__)("Installing\u2026"); 920 } 921 const itemLabel = getDownloadableBlockLabel(item, { 922 hasNotice, 923 isInstalled, 924 isInstalling: isInstalling2 925 }); 926 return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components.Tooltip, { placement: "top", text: itemLabel, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)( 927 import_components.Composite.Item, 928 { 929 className: clsx_default( 930 "block-directory-downloadable-block-list-item", 931 isInstalling2 && "is-installing" 932 ), 933 accessibleWhenDisabled: true, 934 disabled: isInstalling2 || !isInstallable, 935 onClick: (event) => { 936 event.preventDefault(); 937 onClick(); 938 }, 939 "aria-label": itemLabel, 940 type: "button", 941 role: "option", 942 children: [ 943 /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "block-directory-downloadable-block-list-item__icon", children: [ 944 /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(downloadable_block_icon_default, { icon, title }), 945 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 }) 946 ] }), 947 /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "block-directory-downloadable-block-list-item__details", children: [ 948 /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "block-directory-downloadable-block-list-item__title", children: (0, import_element3.createInterpolateElement)( 949 (0, import_i18n4.sprintf)( 950 /* translators: 1: block title. 2: author name. */ 951 (0, import_i18n4.__)("%1$s <span>by %2$s</span>"), 952 (0, import_html_entities.decodeEntities)(title), 953 author 954 ), 955 { 956 span: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "block-directory-downloadable-block-list-item__author" }) 957 } 958 ) }), 959 hasNotice ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(downloadable_block_notice_default, { block: item }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [ 960 /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "block-directory-downloadable-block-list-item__desc", children: !!statusText ? statusText : (0, import_html_entities.decodeEntities)(description) }), 961 isInstallable && !(isInstalled || isInstalling2) && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components.VisuallyHidden, { children: (0, import_i18n4.__)("Install block") }) 962 ] }) 963 ] }) 964 ] 965 } 966 ) }); 967 } 968 var downloadable_block_list_item_default = DownloadableBlockListItem; 969 970 // packages/block-directory/build-module/components/downloadable-blocks-list/index.mjs 971 var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1); 972 var noop = () => { 973 }; 974 function DownloadableBlocksList({ items, onHover = noop, onSelect }) { 975 const { installBlockType: installBlockType2 } = (0, import_data7.useDispatch)(store); 976 if (!items.length) { 977 return null; 978 } 979 return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)( 980 import_components2.Composite, 981 { 982 role: "listbox", 983 className: "block-directory-downloadable-blocks-list", 984 "aria-label": (0, import_i18n5.__)("Blocks available for install"), 985 children: items.map((item) => { 986 return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)( 987 downloadable_block_list_item_default, 988 { 989 onClick: () => { 990 if ((0, import_blocks4.getBlockType)(item.name)) { 991 onSelect(item); 992 } else { 993 installBlockType2(item).then((success) => { 994 if (success) { 995 onSelect(item); 996 } 997 }); 998 } 999 onHover(null); 1000 }, 1001 onHover, 1002 item 1003 }, 1004 item.id 1005 ); 1006 }) 1007 } 1008 ); 1009 } 1010 var downloadable_blocks_list_default = DownloadableBlocksList; 1011 1012 // packages/block-directory/build-module/components/downloadable-blocks-panel/inserter-panel.mjs 1013 var import_i18n6 = __toESM(require_i18n(), 1); 1014 var import_element4 = __toESM(require_element(), 1); 1015 var import_a11y = __toESM(require_a11y(), 1); 1016 var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1); 1017 function DownloadableBlocksInserterPanel({ 1018 children, 1019 downloadableItems, 1020 hasLocalBlocks 1021 }) { 1022 const count = downloadableItems.length; 1023 (0, import_element4.useEffect)(() => { 1024 (0, import_a11y.speak)( 1025 (0, import_i18n6.sprintf)( 1026 /* translators: %d: number of available blocks. */ 1027 (0, import_i18n6._n)( 1028 "%d additional block is available to install.", 1029 "%d additional blocks are available to install.", 1030 count 1031 ), 1032 count 1033 ) 1034 ); 1035 }, [count]); 1036 return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [ 1037 !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.") }), 1038 /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "block-editor-inserter__quick-inserter-separator" }), 1039 /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "block-directory-downloadable-blocks-panel", children: [ 1040 /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "block-directory-downloadable-blocks-panel__header", children: [ 1041 /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("h2", { className: "block-directory-downloadable-blocks-panel__title", children: (0, import_i18n6.__)("Available to install") }), 1042 /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "block-directory-downloadable-blocks-panel__description", children: (0, import_i18n6.__)( 1043 "Select a block to install and add it to your post." 1044 ) }) 1045 ] }), 1046 children 1047 ] }) 1048 ] }); 1049 } 1050 var inserter_panel_default = DownloadableBlocksInserterPanel; 1051 1052 // packages/block-directory/build-module/components/downloadable-blocks-panel/no-results.mjs 1053 var import_i18n7 = __toESM(require_i18n(), 1); 1054 var import_components3 = __toESM(require_components(), 1); 1055 var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1); 1056 function DownloadableBlocksNoResults() { 1057 return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [ 1058 /* @__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.") }) }), 1059 /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "block-editor-inserter__tips", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_components3.Tip, { children: [ 1060 (0, import_i18n7.__)("Interested in creating your own block?"), 1061 /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("br", {}), 1062 /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_components3.ExternalLink, { href: "https://developer.wordpress.org/block-editor/", children: [ 1063 (0, import_i18n7.__)("Get started here"), 1064 "." 1065 ] }) 1066 ] }) }) 1067 ] }); 1068 } 1069 var no_results_default = DownloadableBlocksNoResults; 1070 1071 // packages/block-directory/build-module/components/downloadable-blocks-panel/index.mjs 1072 var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1); 1073 var EMPTY_ARRAY2 = []; 1074 var useDownloadableBlocks = (filterValue) => (0, import_data8.useSelect)( 1075 (select) => { 1076 const { 1077 getDownloadableBlocks: getDownloadableBlocks3, 1078 isRequestingDownloadableBlocks: isRequestingDownloadableBlocks2, 1079 getInstalledBlockTypes: getInstalledBlockTypes2 1080 } = select(store); 1081 const hasPermission = select(import_core_data.store).canUser( 1082 "read", 1083 "block-directory/search" 1084 ); 1085 let downloadableBlocks2 = EMPTY_ARRAY2; 1086 if (hasPermission) { 1087 downloadableBlocks2 = getDownloadableBlocks3(filterValue); 1088 const installedBlockTypes = getInstalledBlockTypes2(); 1089 const installableBlocks = downloadableBlocks2.filter( 1090 ({ name }) => { 1091 const isJustInstalled = installedBlockTypes.some( 1092 (blockType) => blockType.name === name 1093 ); 1094 const isPreviouslyInstalled = (0, import_blocks5.getBlockType)(name); 1095 return isJustInstalled || !isPreviouslyInstalled; 1096 } 1097 ); 1098 if (installableBlocks.length !== downloadableBlocks2.length) { 1099 downloadableBlocks2 = installableBlocks; 1100 } 1101 if (downloadableBlocks2.length === 0) { 1102 downloadableBlocks2 = EMPTY_ARRAY2; 1103 } 1104 } 1105 return { 1106 hasPermission, 1107 downloadableBlocks: downloadableBlocks2, 1108 isLoading: isRequestingDownloadableBlocks2(filterValue) 1109 }; 1110 }, 1111 [filterValue] 1112 ); 1113 function DownloadableBlocksPanel({ 1114 onSelect, 1115 onHover, 1116 hasLocalBlocks, 1117 isTyping, 1118 filterValue 1119 }) { 1120 const { hasPermission, downloadableBlocks: downloadableBlocks2, isLoading } = useDownloadableBlocks(filterValue); 1121 if (hasPermission === void 0 || isLoading || isTyping) { 1122 return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [ 1123 hasPermission && !hasLocalBlocks && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [ 1124 /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "block-directory-downloadable-blocks-panel__no-local", children: (0, import_i18n8.__)( 1125 "No results available from your installed blocks." 1126 ) }), 1127 /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "block-editor-inserter__quick-inserter-separator" }) 1128 ] }), 1129 /* @__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, {}) }) 1130 ] }); 1131 } 1132 if (false === hasPermission) { 1133 if (!hasLocalBlocks) { 1134 return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(no_results_default, {}); 1135 } 1136 return null; 1137 } 1138 if (downloadableBlocks2.length === 0) { 1139 return hasLocalBlocks ? null : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(no_results_default, {}); 1140 } 1141 return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)( 1142 inserter_panel_default, 1143 { 1144 downloadableItems: downloadableBlocks2, 1145 hasLocalBlocks, 1146 children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)( 1147 downloadable_blocks_list_default, 1148 { 1149 items: downloadableBlocks2, 1150 onSelect, 1151 onHover 1152 } 1153 ) 1154 } 1155 ); 1156 } 1157 1158 // packages/block-directory/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.mjs 1159 var import_jsx_runtime13 = __toESM(require_jsx_runtime(), 1); 1160 function InserterMenuDownloadableBlocksPanel() { 1161 const [debouncedFilterValue, setFilterValue] = (0, import_element5.useState)(""); 1162 const debouncedSetFilterValue = (0, import_compose.debounce)(setFilterValue, 400); 1163 return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_block_editor3.__unstableInserterMenuExtension, { children: ({ onSelect, onHover, filterValue, hasItems }) => { 1164 if (debouncedFilterValue !== filterValue) { 1165 debouncedSetFilterValue(filterValue); 1166 } 1167 if (!debouncedFilterValue) { 1168 return null; 1169 } 1170 return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)( 1171 DownloadableBlocksPanel, 1172 { 1173 onSelect, 1174 onHover, 1175 filterValue: debouncedFilterValue, 1176 hasLocalBlocks: hasItems, 1177 isTyping: filterValue !== debouncedFilterValue 1178 } 1179 ); 1180 } }); 1181 } 1182 var inserter_menu_downloadable_blocks_panel_default = InserterMenuDownloadableBlocksPanel; 1183 1184 // packages/block-directory/build-module/plugins/installed-blocks-pre-publish-panel/index.mjs 1185 var import_i18n10 = __toESM(require_i18n(), 1); 1186 var import_data9 = __toESM(require_data(), 1); 1187 var import_editor2 = __toESM(require_editor(), 1); 1188 1189 // packages/block-directory/build-module/components/compact-list/index.mjs 1190 var import_i18n9 = __toESM(require_i18n(), 1); 1191 var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1); 1192 function CompactList({ items }) { 1193 if (!items.length) { 1194 return null; 1195 } 1196 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: [ 1197 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(downloadable_block_icon_default, { icon, title }), 1198 /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "block-directory-compact-list__item-details", children: [ 1199 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "block-directory-compact-list__item-title", children: title }), 1200 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "block-directory-compact-list__item-author", children: (0, import_i18n9.sprintf)( 1201 /* translators: %s: Name of the block author. */ 1202 (0, import_i18n9.__)("By %s"), 1203 author 1204 ) }) 1205 ] }) 1206 ] }, id)) }); 1207 } 1208 1209 // packages/block-directory/build-module/plugins/installed-blocks-pre-publish-panel/index.mjs 1210 var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1); 1211 function InstalledBlocksPrePublishPanel() { 1212 const newBlockTypes = (0, import_data9.useSelect)( 1213 (select) => select(store).getNewBlockTypes(), 1214 [] 1215 ); 1216 if (!newBlockTypes.length) { 1217 return null; 1218 } 1219 return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)( 1220 import_editor2.PluginPrePublishPanel, 1221 { 1222 title: (0, import_i18n10.sprintf)( 1223 // translators: %d: number of blocks (number). 1224 (0, import_i18n10._n)( 1225 "Added: %d block", 1226 "Added: %d blocks", 1227 newBlockTypes.length 1228 ), 1229 newBlockTypes.length 1230 ), 1231 initialOpen: true, 1232 children: [ 1233 /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "installed-blocks-pre-publish-panel__copy", children: (0, import_i18n10._n)( 1234 "The following block has been added to your site.", 1235 "The following blocks have been added to your site.", 1236 newBlockTypes.length 1237 ) }), 1238 /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(CompactList, { items: newBlockTypes }) 1239 ] 1240 } 1241 ); 1242 } 1243 1244 // packages/block-directory/build-module/plugins/get-install-missing/index.mjs 1245 var import_i18n12 = __toESM(require_i18n(), 1); 1246 var import_components6 = __toESM(require_components(), 1); 1247 var import_blocks7 = __toESM(require_blocks(), 1); 1248 var import_element6 = __toESM(require_element(), 1); 1249 var import_data11 = __toESM(require_data(), 1); 1250 var import_core_data2 = __toESM(require_core_data(), 1); 1251 var import_block_editor5 = __toESM(require_block_editor(), 1); 1252 1253 // packages/block-directory/build-module/plugins/get-install-missing/install-button.mjs 1254 var import_i18n11 = __toESM(require_i18n(), 1); 1255 var import_components5 = __toESM(require_components(), 1); 1256 var import_blocks6 = __toESM(require_blocks(), 1); 1257 var import_data10 = __toESM(require_data(), 1); 1258 var import_block_editor4 = __toESM(require_block_editor(), 1); 1259 var import_jsx_runtime16 = __toESM(require_jsx_runtime(), 1); 1260 function InstallButton({ attributes, block, clientId }) { 1261 const isInstallingBlock = (0, import_data10.useSelect)( 1262 (select) => select(store).isInstalling(block.id), 1263 [block.id] 1264 ); 1265 const { installBlockType: installBlockType2 } = (0, import_data10.useDispatch)(store); 1266 const { replaceBlock } = (0, import_data10.useDispatch)(import_block_editor4.store); 1267 return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( 1268 import_components5.Button, 1269 { 1270 __next40pxDefaultSize: true, 1271 onClick: () => installBlockType2(block).then((success) => { 1272 if (success) { 1273 const blockType = (0, import_blocks6.getBlockType)(block.name); 1274 const [originalBlock] = (0, import_blocks6.parse)( 1275 attributes.originalContent 1276 ); 1277 if (originalBlock && blockType) { 1278 replaceBlock( 1279 clientId, 1280 (0, import_blocks6.createBlock)( 1281 blockType.name, 1282 originalBlock.attributes, 1283 originalBlock.innerBlocks 1284 ) 1285 ); 1286 } 1287 } 1288 }), 1289 accessibleWhenDisabled: true, 1290 disabled: isInstallingBlock, 1291 isBusy: isInstallingBlock, 1292 variant: "primary", 1293 children: (0, import_i18n11.sprintf)( 1294 /* translators: %s: block name */ 1295 (0, import_i18n11.__)("Install %s"), 1296 block.title 1297 ) 1298 } 1299 ); 1300 } 1301 1302 // packages/block-directory/build-module/plugins/get-install-missing/index.mjs 1303 var import_jsx_runtime17 = __toESM(require_jsx_runtime(), 1); 1304 var getInstallMissing = (OriginalComponent) => (props) => { 1305 const { originalName } = props.attributes; 1306 const { block, hasPermission } = (0, import_data11.useSelect)( 1307 (select) => { 1308 const { getDownloadableBlocks: getDownloadableBlocks3 } = select(store); 1309 const blocks = getDownloadableBlocks3( 1310 "block:" + originalName 1311 ).filter(({ name }) => originalName === name); 1312 return { 1313 hasPermission: select(import_core_data2.store).canUser( 1314 "read", 1315 "block-directory/search" 1316 ), 1317 block: blocks.length && blocks[0] 1318 }; 1319 }, 1320 [originalName] 1321 ); 1322 if (!hasPermission || !block) { 1323 return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(OriginalComponent, { ...props }); 1324 } 1325 return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ModifiedWarning, { ...props, originalBlock: block }); 1326 }; 1327 var ModifiedWarning = ({ originalBlock, ...props }) => { 1328 const { originalName, originalUndelimitedContent, clientId } = props.attributes; 1329 const { replaceBlock } = (0, import_data11.useDispatch)(import_block_editor5.store); 1330 const convertToHTML = () => { 1331 replaceBlock( 1332 props.clientId, 1333 (0, import_blocks7.createBlock)("core/html", { 1334 content: originalUndelimitedContent 1335 }) 1336 ); 1337 }; 1338 const hasContent = !!originalUndelimitedContent; 1339 const hasHTMLBlock = (0, import_data11.useSelect)( 1340 (select) => { 1341 const { canInsertBlockType, getBlockRootClientId } = select(import_block_editor5.store); 1342 return canInsertBlockType( 1343 "core/html", 1344 getBlockRootClientId(clientId) 1345 ); 1346 }, 1347 [clientId] 1348 ); 1349 let messageHTML = (0, import_i18n12.sprintf)( 1350 /* translators: %s: block name */ 1351 (0, import_i18n12.__)( 1352 "Your site doesn\u2019t include support for the %s block. You can try installing the block or remove it entirely." 1353 ), 1354 originalBlock.title || originalName 1355 ); 1356 const actions = [ 1357 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)( 1358 InstallButton, 1359 { 1360 block: originalBlock, 1361 attributes: props.attributes, 1362 clientId: props.clientId 1363 }, 1364 "install" 1365 ) 1366 ]; 1367 if (hasContent && hasHTMLBlock) { 1368 messageHTML = (0, import_i18n12.sprintf)( 1369 /* translators: %s: block name */ 1370 (0, import_i18n12.__)( 1371 "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." 1372 ), 1373 originalBlock.title || originalName 1374 ); 1375 actions.push( 1376 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)( 1377 import_components6.Button, 1378 { 1379 __next40pxDefaultSize: true, 1380 onClick: convertToHTML, 1381 variant: "tertiary", 1382 children: (0, import_i18n12.__)("Keep as HTML") 1383 }, 1384 "convert" 1385 ) 1386 ); 1387 } 1388 return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { ...(0, import_block_editor5.useBlockProps)(), children: [ 1389 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_block_editor5.Warning, { actions, children: messageHTML }), 1390 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_element6.RawHTML, { children: originalUndelimitedContent }) 1391 ] }); 1392 }; 1393 var get_install_missing_default = getInstallMissing; 1394 1395 // packages/block-directory/build-module/plugins/index.mjs 1396 var import_jsx_runtime18 = __toESM(require_jsx_runtime(), 1); 1397 (0, import_plugins.registerPlugin)("block-directory", { 1398 // The icon is explicitly set to undefined to prevent PluginPrePublishPanel 1399 // from rendering the fallback icon pluginIcon. 1400 icon: void 0, 1401 render() { 1402 return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [ 1403 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(AutoBlockUninstaller, {}), 1404 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(inserter_menu_downloadable_blocks_panel_default, {}), 1405 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(InstalledBlocksPrePublishPanel, {}) 1406 ] }); 1407 } 1408 }); 1409 (0, import_hooks.addFilter)( 1410 "blocks.registerBlockType", 1411 "block-directory/fallback", 1412 (settings, name) => { 1413 if (name !== "core/missing") { 1414 return settings; 1415 } 1416 settings.edit = get_install_missing_default(settings.edit); 1417 return settings; 1418 } 1419 ); 1420 return __toCommonJS(index_exports); 1421 })();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Mon Jun 29 08:20:12 2026 | Cross-referenced by PHPXref |