| 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 |
var STYLE_HASH_ATTRIBUTE = "data-wp-hash"; |
| 1264 |
function getRuntime() { |
| 1265 |
const globalScope = globalThis; |
| 1266 |
if (globalScope.__wpStyleRuntime) { |
| 1267 |
return globalScope.__wpStyleRuntime; |
| 1268 |
} |
| 1269 |
globalScope.__wpStyleRuntime = { |
| 1270 |
documents: /* @__PURE__ */ new Map(), |
| 1271 |
styles: /* @__PURE__ */ new Map(), |
| 1272 |
injectedStyles: /* @__PURE__ */ new WeakMap() |
| 1273 |
}; |
| 1274 |
if (typeof document !== "undefined") { |
| 1275 |
registerDocument(document); |
| 1276 |
} |
| 1277 |
return globalScope.__wpStyleRuntime; |
| 1278 |
} |
| 1279 |
function documentContainsStyleHash(targetDocument, hash) { |
| 1280 |
if (!targetDocument.head) { |
| 1281 |
return false; |
| 1282 |
} |
| 1283 |
for (const style of targetDocument.head.querySelectorAll( |
| 1284 |
`style[${STYLE_HASH_ATTRIBUTE}]` |
| 1285 |
)) { |
| 1286 |
if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) { |
| 1287 |
return true; |
| 1288 |
} |
| 1289 |
} |
| 1290 |
return false; |
| 1291 |
} |
| 1292 |
function injectStyle(targetDocument, hash, css) { |
| 1293 |
if (!targetDocument.head) { |
| 1294 |
return; |
| 1295 |
} |
| 1296 |
const runtime = getRuntime(); |
| 1297 |
let injectedStyles = runtime.injectedStyles.get(targetDocument); |
| 1298 |
if (!injectedStyles) { |
| 1299 |
injectedStyles = /* @__PURE__ */ new Set(); |
| 1300 |
runtime.injectedStyles.set(targetDocument, injectedStyles); |
| 1301 |
} |
| 1302 |
if (injectedStyles.has(hash)) { |
| 1303 |
return; |
| 1304 |
} |
| 1305 |
if (documentContainsStyleHash(targetDocument, hash)) { |
| 1306 |
injectedStyles.add(hash); |
| 1307 |
return; |
| 1308 |
} |
| 1309 |
const style = targetDocument.createElement("style"); |
| 1310 |
style.setAttribute(STYLE_HASH_ATTRIBUTE, hash); |
| 1311 |
style.appendChild(targetDocument.createTextNode(css)); |
| 1312 |
targetDocument.head.appendChild(style); |
| 1313 |
injectedStyles.add(hash); |
| 1314 |
} |
| 1315 |
function registerDocument(targetDocument) { |
| 1316 |
const runtime = getRuntime(); |
| 1317 |
runtime.documents.set( |
| 1318 |
targetDocument, |
| 1319 |
(runtime.documents.get(targetDocument) ?? 0) + 1 |
| 1320 |
); |
| 1321 |
for (const [hash, css] of runtime.styles) { |
| 1322 |
injectStyle(targetDocument, hash, css); |
| 1323 |
} |
| 1324 |
return () => { |
| 1325 |
const count = runtime.documents.get(targetDocument); |
| 1326 |
if (count === void 0) { |
| 1327 |
return; |
| 1328 |
} |
| 1329 |
if (count <= 1) { |
| 1330 |
runtime.documents.delete(targetDocument); |
| 1331 |
return; |
| 1332 |
} |
| 1333 |
runtime.documents.set(targetDocument, count - 1); |
| 1334 |
}; |
| 1335 |
} |
| 1336 |
function registerStyle(hash, css) { |
| 1337 |
const runtime = getRuntime(); |
| 1338 |
runtime.styles.set(hash, css); |
| 1339 |
for (const targetDocument of runtime.documents.keys()) { |
| 1340 |
injectStyle(targetDocument, hash, css); |
| 1341 |
} |
| 1342 |
} |
| 1343 |
if (typeof process === "undefined" || true) { |
| 1344 |
registerStyle("c46e8cb841", "@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}}"); |
| 1345 |
} |
| 1346 |
var style_default = { "visually-hidden": "f37b9e2e191ebd66__visually-hidden" }; |
| 1347 |
var VisuallyHidden = (0, import_element3.forwardRef)( |
| 1348 |
function VisuallyHidden2({ render, ...restProps }, ref) { |
| 1349 |
const element = useRender({ |
| 1350 |
render, |
| 1351 |
ref, |
| 1352 |
props: mergeProps( |
| 1353 |
{ className: style_default["visually-hidden"] }, |
| 1354 |
restProps, |
| 1355 |
{ |
| 1356 |
// @ts-expect-error Arbitrary data-* attributes aren't indexable on the typed div props. Kept hardcoded so consumers can't change or remove it. |
| 1357 |
"data-visually-hidden": "" |
| 1358 |
} |
| 1359 |
) |
| 1360 |
}); |
| 1361 |
return element; |
| 1362 |
} |
| 1363 |
); |
| 1364 |
|
| 1365 |
// packages/block-directory/build-module/components/block-ratings/stars.mjs |
| 1366 |
var import_i18n2 = __toESM(require_i18n(), 1); |
| 1367 |
var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1); |
| 1368 |
function Stars({ rating }) { |
| 1369 |
const stars = Math.round(rating / 0.5) * 0.5; |
| 1370 |
const fullStarCount = Math.floor(rating); |
| 1371 |
const halfStarCount = Math.ceil(rating - fullStarCount); |
| 1372 |
const emptyStarCount = 5 - (fullStarCount + halfStarCount); |
| 1373 |
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)( |
| 1374 |
"span", |
| 1375 |
{ |
| 1376 |
"aria-label": (0, import_i18n2.sprintf)( |
| 1377 |
/* translators: %s: number of stars. */ |
| 1378 |
(0, import_i18n2.__)("%s out of 5 stars"), |
| 1379 |
stars |
| 1380 |
), |
| 1381 |
children: [ |
| 1382 |
Array.from({ length: fullStarCount }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( |
| 1383 |
icon_default, |
| 1384 |
{ |
| 1385 |
className: "block-directory-block-ratings__star-full", |
| 1386 |
icon: star_filled_default, |
| 1387 |
size: 16 |
| 1388 |
}, |
| 1389 |
`full_stars_${i}` |
| 1390 |
)), |
| 1391 |
Array.from({ length: halfStarCount }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( |
| 1392 |
icon_default, |
| 1393 |
{ |
| 1394 |
className: "block-directory-block-ratings__star-half-full", |
| 1395 |
icon: star_half_default, |
| 1396 |
size: 16 |
| 1397 |
}, |
| 1398 |
`half_stars_${i}` |
| 1399 |
)), |
| 1400 |
Array.from({ length: emptyStarCount }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( |
| 1401 |
icon_default, |
| 1402 |
{ |
| 1403 |
className: "block-directory-block-ratings__star-empty", |
| 1404 |
icon: star_empty_default, |
| 1405 |
size: 16 |
| 1406 |
}, |
| 1407 |
`empty_stars_${i}` |
| 1408 |
)) |
| 1409 |
] |
| 1410 |
} |
| 1411 |
); |
| 1412 |
} |
| 1413 |
var stars_default = Stars; |
| 1414 |
|
| 1415 |
// packages/block-directory/build-module/components/block-ratings/index.mjs |
| 1416 |
var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1); |
| 1417 |
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 }) }); |
| 1418 |
var block_ratings_default = BlockRatings; |
| 1419 |
|
| 1420 |
// packages/block-directory/build-module/components/downloadable-block-icon/index.mjs |
| 1421 |
var import_block_editor2 = __toESM(require_block_editor(), 1); |
| 1422 |
var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1); |
| 1423 |
function DownloadableBlockIcon({ icon }) { |
| 1424 |
const className = "block-directory-downloadable-block-icon"; |
| 1425 |
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 }); |
| 1426 |
} |
| 1427 |
var downloadable_block_icon_default = DownloadableBlockIcon; |
| 1428 |
|
| 1429 |
// packages/block-directory/build-module/components/downloadable-block-notice/index.mjs |
| 1430 |
var import_i18n3 = __toESM(require_i18n(), 1); |
| 1431 |
var import_data5 = __toESM(require_data(), 1); |
| 1432 |
var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1); |
| 1433 |
var DownloadableBlockNotice = ({ block }) => { |
| 1434 |
const errorNotice = (0, import_data5.useSelect)( |
| 1435 |
(select) => select(store).getErrorNoticeForBlock(block.id), |
| 1436 |
[block] |
| 1437 |
); |
| 1438 |
if (!errorNotice) { |
| 1439 |
return null; |
| 1440 |
} |
| 1441 |
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: [ |
| 1442 |
errorNotice.message, |
| 1443 |
errorNotice.isFatal ? " " + (0, import_i18n3.__)("Try reloading the page.") : null |
| 1444 |
] }) }); |
| 1445 |
}; |
| 1446 |
var downloadable_block_notice_default = DownloadableBlockNotice; |
| 1447 |
|
| 1448 |
// packages/block-directory/build-module/components/downloadable-block-list-item/index.mjs |
| 1449 |
var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1); |
| 1450 |
function getDownloadableBlockLabel({ title, rating, ratingCount }, { hasNotice, isInstalled, isInstalling: isInstalling2 }) { |
| 1451 |
const stars = Math.round(rating / 0.5) * 0.5; |
| 1452 |
if (!isInstalled && hasNotice) { |
| 1453 |
return (0, import_i18n4.sprintf)("Retry installing %s.", (0, import_html_entities.decodeEntities)(title)); |
| 1454 |
} |
| 1455 |
if (isInstalled) { |
| 1456 |
return (0, import_i18n4.sprintf)("Add %s.", (0, import_html_entities.decodeEntities)(title)); |
| 1457 |
} |
| 1458 |
if (isInstalling2) { |
| 1459 |
return (0, import_i18n4.sprintf)("Installing %s.", (0, import_html_entities.decodeEntities)(title)); |
| 1460 |
} |
| 1461 |
if (ratingCount < 1) { |
| 1462 |
return (0, import_i18n4.sprintf)("Install %s.", (0, import_html_entities.decodeEntities)(title)); |
| 1463 |
} |
| 1464 |
return (0, import_i18n4.sprintf)( |
| 1465 |
/* translators: 1: block title, 2: average rating, 3: total ratings count. */ |
| 1466 |
(0, import_i18n4._n)( |
| 1467 |
"Install %1$s. %2$s stars with %3$s review.", |
| 1468 |
"Install %1$s. %2$s stars with %3$s reviews.", |
| 1469 |
ratingCount |
| 1470 |
), |
| 1471 |
(0, import_html_entities.decodeEntities)(title), |
| 1472 |
stars, |
| 1473 |
ratingCount |
| 1474 |
); |
| 1475 |
} |
| 1476 |
function DownloadableBlockListItem({ item, onClick }) { |
| 1477 |
const { author, description, icon, rating, title } = item; |
| 1478 |
const isInstalled = !!(0, import_blocks3.getBlockType)(item.name); |
| 1479 |
const { hasNotice, isInstalling: isInstalling2, isInstallable } = (0, import_data6.useSelect)( |
| 1480 |
(select) => { |
| 1481 |
const { getErrorNoticeForBlock: getErrorNoticeForBlock2, isInstalling: isBlockInstalling } = select(store); |
| 1482 |
const notice = getErrorNoticeForBlock2(item.id); |
| 1483 |
const hasFatal = notice && notice.isFatal; |
| 1484 |
return { |
| 1485 |
hasNotice: !!notice, |
| 1486 |
isInstalling: isBlockInstalling(item.id), |
| 1487 |
isInstallable: !hasFatal |
| 1488 |
}; |
| 1489 |
}, |
| 1490 |
[item] |
| 1491 |
); |
| 1492 |
let statusText = ""; |
| 1493 |
if (isInstalled) { |
| 1494 |
statusText = (0, import_i18n4.__)("Installed!"); |
| 1495 |
} else if (isInstalling2) { |
| 1496 |
statusText = (0, import_i18n4.__)("Installing\u2026"); |
| 1497 |
} |
| 1498 |
const itemLabel = getDownloadableBlockLabel(item, { |
| 1499 |
hasNotice, |
| 1500 |
isInstalled, |
| 1501 |
isInstalling: isInstalling2 |
| 1502 |
}); |
| 1503 |
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_components.Tooltip, { placement: "top", text: itemLabel, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)( |
| 1504 |
import_components.Composite.Item, |
| 1505 |
{ |
| 1506 |
className: clsx_default( |
| 1507 |
"block-directory-downloadable-block-list-item", |
| 1508 |
isInstalling2 && "is-installing" |
| 1509 |
), |
| 1510 |
accessibleWhenDisabled: true, |
| 1511 |
disabled: isInstalling2 || !isInstallable, |
| 1512 |
onClick: (event) => { |
| 1513 |
event.preventDefault(); |
| 1514 |
onClick(); |
| 1515 |
}, |
| 1516 |
"aria-label": itemLabel, |
| 1517 |
type: "button", |
| 1518 |
role: "option", |
| 1519 |
children: [ |
| 1520 |
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "block-directory-downloadable-block-list-item__icon", children: [ |
| 1521 |
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(downloadable_block_icon_default, { icon, title }), |
| 1522 |
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 }) |
| 1523 |
] }), |
| 1524 |
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "block-directory-downloadable-block-list-item__details", children: [ |
| 1525 |
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "block-directory-downloadable-block-list-item__title", children: (0, import_element4.createInterpolateElement)( |
| 1526 |
(0, import_i18n4.sprintf)( |
| 1527 |
/* translators: 1: block title. 2: author name. */ |
| 1528 |
(0, import_i18n4.__)("%1$s <span>by %2$s</span>"), |
| 1529 |
(0, import_html_entities.decodeEntities)(title), |
| 1530 |
author |
| 1531 |
), |
| 1532 |
{ |
| 1533 |
span: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "block-directory-downloadable-block-list-item__author" }) |
| 1534 |
} |
| 1535 |
) }), |
| 1536 |
hasNotice ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(downloadable_block_notice_default, { block: item }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [ |
| 1537 |
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "block-directory-downloadable-block-list-item__desc", children: !!statusText ? statusText : (0, import_html_entities.decodeEntities)(description) }), |
| 1538 |
isInstallable && !(isInstalled || isInstalling2) && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(VisuallyHidden, { children: (0, import_i18n4.__)("Install block") }) |
| 1539 |
] }) |
| 1540 |
] }) |
| 1541 |
] |
| 1542 |
} |
| 1543 |
) }); |
| 1544 |
} |
| 1545 |
var downloadable_block_list_item_default = DownloadableBlockListItem; |
| 1546 |
|
| 1547 |
// packages/block-directory/build-module/components/downloadable-blocks-list/index.mjs |
| 1548 |
var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1); |
| 1549 |
var noop = () => { |
| 1550 |
}; |
| 1551 |
function DownloadableBlocksList({ items, onHover = noop, onSelect }) { |
| 1552 |
const { installBlockType: installBlockType2 } = (0, import_data7.useDispatch)(store); |
| 1553 |
if (!items.length) { |
| 1554 |
return null; |
| 1555 |
} |
| 1556 |
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)( |
| 1557 |
import_components2.Composite, |
| 1558 |
{ |
| 1559 |
role: "listbox", |
| 1560 |
className: "block-directory-downloadable-blocks-list", |
| 1561 |
"aria-label": (0, import_i18n5.__)("Blocks available for install"), |
| 1562 |
children: items.map((item) => { |
| 1563 |
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)( |
| 1564 |
downloadable_block_list_item_default, |
| 1565 |
{ |
| 1566 |
onClick: () => { |
| 1567 |
if ((0, import_blocks4.getBlockType)(item.name)) { |
| 1568 |
onSelect(item); |
| 1569 |
} else { |
| 1570 |
installBlockType2(item).then((success) => { |
| 1571 |
if (success) { |
| 1572 |
onSelect(item); |
| 1573 |
} |
| 1574 |
}); |
| 1575 |
} |
| 1576 |
onHover(null); |
| 1577 |
}, |
| 1578 |
onHover, |
| 1579 |
item |
| 1580 |
}, |
| 1581 |
item.id |
| 1582 |
); |
| 1583 |
}) |
| 1584 |
} |
| 1585 |
); |
| 1586 |
} |
| 1587 |
var downloadable_blocks_list_default = DownloadableBlocksList; |
| 1588 |
|
| 1589 |
// packages/block-directory/build-module/components/downloadable-blocks-panel/inserter-panel.mjs |
| 1590 |
var import_i18n6 = __toESM(require_i18n(), 1); |
| 1591 |
var import_element5 = __toESM(require_element(), 1); |
| 1592 |
var import_a11y = __toESM(require_a11y(), 1); |
| 1593 |
var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1); |
| 1594 |
function DownloadableBlocksInserterPanel({ |
| 1595 |
children, |
| 1596 |
downloadableItems, |
| 1597 |
hasLocalBlocks |
| 1598 |
}) { |
| 1599 |
const count = downloadableItems.length; |
| 1600 |
(0, import_element5.useEffect)(() => { |
| 1601 |
(0, import_a11y.speak)( |
| 1602 |
(0, import_i18n6.sprintf)( |
| 1603 |
/* translators: %d: number of available blocks. */ |
| 1604 |
(0, import_i18n6._n)( |
| 1605 |
"%d additional block is available to install.", |
| 1606 |
"%d additional blocks are available to install.", |
| 1607 |
count |
| 1608 |
), |
| 1609 |
count |
| 1610 |
) |
| 1611 |
); |
| 1612 |
}, [count]); |
| 1613 |
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [ |
| 1614 |
!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.") }), |
| 1615 |
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "block-editor-inserter__quick-inserter-separator" }), |
| 1616 |
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "block-directory-downloadable-blocks-panel", children: [ |
| 1617 |
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "block-directory-downloadable-blocks-panel__header", children: [ |
| 1618 |
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("h2", { className: "block-directory-downloadable-blocks-panel__title", children: (0, import_i18n6.__)("Available to install") }), |
| 1619 |
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "block-directory-downloadable-blocks-panel__description", children: (0, import_i18n6.__)( |
| 1620 |
"Select a block to install and add it to your post." |
| 1621 |
) }) |
| 1622 |
] }), |
| 1623 |
children |
| 1624 |
] }) |
| 1625 |
] }); |
| 1626 |
} |
| 1627 |
var inserter_panel_default = DownloadableBlocksInserterPanel; |
| 1628 |
|
| 1629 |
// packages/block-directory/build-module/components/downloadable-blocks-panel/no-results.mjs |
| 1630 |
var import_i18n7 = __toESM(require_i18n(), 1); |
| 1631 |
var import_components3 = __toESM(require_components(), 1); |
| 1632 |
var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1); |
| 1633 |
function DownloadableBlocksNoResults() { |
| 1634 |
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [ |
| 1635 |
/* @__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.") }) }), |
| 1636 |
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "block-editor-inserter__tips", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_components3.Tip, { children: [ |
| 1637 |
(0, import_i18n7.__)("Interested in creating your own block?"), |
| 1638 |
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("br", {}), |
| 1639 |
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_components3.ExternalLink, { href: "https://developer.wordpress.org/block-editor/", children: [ |
| 1640 |
(0, import_i18n7.__)("Get started here"), |
| 1641 |
"." |
| 1642 |
] }) |
| 1643 |
] }) }) |
| 1644 |
] }); |
| 1645 |
} |
| 1646 |
var no_results_default = DownloadableBlocksNoResults; |
| 1647 |
|
| 1648 |
// packages/block-directory/build-module/components/downloadable-blocks-panel/index.mjs |
| 1649 |
var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1); |
| 1650 |
var EMPTY_ARRAY3 = []; |
| 1651 |
var useDownloadableBlocks = (filterValue) => (0, import_data8.useSelect)( |
| 1652 |
(select) => { |
| 1653 |
const { |
| 1654 |
getDownloadableBlocks: getDownloadableBlocks3, |
| 1655 |
isRequestingDownloadableBlocks: isRequestingDownloadableBlocks2, |
| 1656 |
getInstalledBlockTypes: getInstalledBlockTypes2 |
| 1657 |
} = select(store); |
| 1658 |
const hasPermission = select(import_core_data.store).canUser( |
| 1659 |
"read", |
| 1660 |
"block-directory/search" |
| 1661 |
); |
| 1662 |
let downloadableBlocks2 = EMPTY_ARRAY3; |
| 1663 |
if (hasPermission) { |
| 1664 |
downloadableBlocks2 = getDownloadableBlocks3(filterValue); |
| 1665 |
const installedBlockTypes = getInstalledBlockTypes2(); |
| 1666 |
const installableBlocks = downloadableBlocks2.filter( |
| 1667 |
({ name }) => { |
| 1668 |
const isJustInstalled = installedBlockTypes.some( |
| 1669 |
(blockType) => blockType.name === name |
| 1670 |
); |
| 1671 |
const isPreviouslyInstalled = (0, import_blocks5.getBlockType)(name); |
| 1672 |
return isJustInstalled || !isPreviouslyInstalled; |
| 1673 |
} |
| 1674 |
); |
| 1675 |
if (installableBlocks.length !== downloadableBlocks2.length) { |
| 1676 |
downloadableBlocks2 = installableBlocks; |
| 1677 |
} |
| 1678 |
if (downloadableBlocks2.length === 0) { |
| 1679 |
downloadableBlocks2 = EMPTY_ARRAY3; |
| 1680 |
} |
| 1681 |
} |
| 1682 |
return { |
| 1683 |
hasPermission, |
| 1684 |
downloadableBlocks: downloadableBlocks2, |
| 1685 |
isLoading: isRequestingDownloadableBlocks2(filterValue) |
| 1686 |
}; |
| 1687 |
}, |
| 1688 |
[filterValue] |
| 1689 |
); |
| 1690 |
function DownloadableBlocksPanel({ |
| 1691 |
onSelect, |
| 1692 |
onHover, |
| 1693 |
hasLocalBlocks, |
| 1694 |
isTyping, |
| 1695 |
filterValue |
| 1696 |
}) { |
| 1697 |
const { hasPermission, downloadableBlocks: downloadableBlocks2, isLoading } = useDownloadableBlocks(filterValue); |
| 1698 |
if (hasPermission === void 0 || isLoading || isTyping) { |
| 1699 |
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [ |
| 1700 |
hasPermission && !hasLocalBlocks && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [ |
| 1701 |
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "block-directory-downloadable-blocks-panel__no-local", children: (0, import_i18n8.__)( |
| 1702 |
"No results available from your installed blocks." |
| 1703 |
) }), |
| 1704 |
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "block-editor-inserter__quick-inserter-separator" }) |
| 1705 |
] }), |
| 1706 |
/* @__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, {}) }) |
| 1707 |
] }); |
| 1708 |
} |
| 1709 |
if (false === hasPermission) { |
| 1710 |
if (!hasLocalBlocks) { |
| 1711 |
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(no_results_default, {}); |
| 1712 |
} |
| 1713 |
return null; |
| 1714 |
} |
| 1715 |
if (downloadableBlocks2.length === 0) { |
| 1716 |
return hasLocalBlocks ? null : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(no_results_default, {}); |
| 1717 |
} |
| 1718 |
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)( |
| 1719 |
inserter_panel_default, |
| 1720 |
{ |
| 1721 |
downloadableItems: downloadableBlocks2, |
| 1722 |
hasLocalBlocks, |
| 1723 |
children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)( |
| 1724 |
downloadable_blocks_list_default, |
| 1725 |
{ |
| 1726 |
items: downloadableBlocks2, |
| 1727 |
onSelect, |
| 1728 |
onHover |
| 1729 |
} |
| 1730 |
) |
| 1731 |
} |
| 1732 |
); |
| 1733 |
} |
| 1734 |
|
| 1735 |
// packages/block-directory/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.mjs |
| 1736 |
var import_jsx_runtime13 = __toESM(require_jsx_runtime(), 1); |
| 1737 |
function InserterMenuDownloadableBlocksPanel() { |
| 1738 |
const [debouncedFilterValue, setFilterValue] = (0, import_element6.useState)(""); |
| 1739 |
const debouncedSetFilterValue = (0, import_compose.debounce)(setFilterValue, 400); |
| 1740 |
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_block_editor3.__unstableInserterMenuExtension, { children: ({ onSelect, onHover, filterValue, hasItems }) => { |
| 1741 |
if (debouncedFilterValue !== filterValue) { |
| 1742 |
debouncedSetFilterValue(filterValue); |
| 1743 |
} |
| 1744 |
if (!debouncedFilterValue) { |
| 1745 |
return null; |
| 1746 |
} |
| 1747 |
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)( |
| 1748 |
DownloadableBlocksPanel, |
| 1749 |
{ |
| 1750 |
onSelect, |
| 1751 |
onHover, |
| 1752 |
filterValue: debouncedFilterValue, |
| 1753 |
hasLocalBlocks: hasItems, |
| 1754 |
isTyping: filterValue !== debouncedFilterValue |
| 1755 |
} |
| 1756 |
); |
| 1757 |
} }); |
| 1758 |
} |
| 1759 |
var inserter_menu_downloadable_blocks_panel_default = InserterMenuDownloadableBlocksPanel; |
| 1760 |
|
| 1761 |
// packages/block-directory/build-module/plugins/installed-blocks-pre-publish-panel/index.mjs |
| 1762 |
var import_i18n10 = __toESM(require_i18n(), 1); |
| 1763 |
var import_data9 = __toESM(require_data(), 1); |
| 1764 |
var import_editor2 = __toESM(require_editor(), 1); |
| 1765 |
|
| 1766 |
// packages/block-directory/build-module/components/compact-list/index.mjs |
| 1767 |
var import_i18n9 = __toESM(require_i18n(), 1); |
| 1768 |
var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1); |
| 1769 |
function CompactList({ items }) { |
| 1770 |
if (!items.length) { |
| 1771 |
return null; |
| 1772 |
} |
| 1773 |
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: [ |
| 1774 |
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(downloadable_block_icon_default, { icon, title }), |
| 1775 |
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "block-directory-compact-list__item-details", children: [ |
| 1776 |
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "block-directory-compact-list__item-title", children: title }), |
| 1777 |
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "block-directory-compact-list__item-author", children: (0, import_i18n9.sprintf)( |
| 1778 |
/* translators: %s: Name of the block author. */ |
| 1779 |
(0, import_i18n9.__)("By %s"), |
| 1780 |
author |
| 1781 |
) }) |
| 1782 |
] }) |
| 1783 |
] }, id)) }); |
| 1784 |
} |
| 1785 |
|
| 1786 |
// packages/block-directory/build-module/plugins/installed-blocks-pre-publish-panel/index.mjs |
| 1787 |
var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1); |
| 1788 |
function InstalledBlocksPrePublishPanel() { |
| 1789 |
const newBlockTypes = (0, import_data9.useSelect)( |
| 1790 |
(select) => select(store).getNewBlockTypes(), |
| 1791 |
[] |
| 1792 |
); |
| 1793 |
if (!newBlockTypes.length) { |
| 1794 |
return null; |
| 1795 |
} |
| 1796 |
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)( |
| 1797 |
import_editor2.PluginPrePublishPanel, |
| 1798 |
{ |
| 1799 |
title: (0, import_i18n10.sprintf)( |
| 1800 |
// translators: %d: number of blocks (number). |
| 1801 |
(0, import_i18n10._n)( |
| 1802 |
"Added: %d block", |
| 1803 |
"Added: %d blocks", |
| 1804 |
newBlockTypes.length |
| 1805 |
), |
| 1806 |
newBlockTypes.length |
| 1807 |
), |
| 1808 |
initialOpen: true, |
| 1809 |
children: [ |
| 1810 |
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "installed-blocks-pre-publish-panel__copy", children: (0, import_i18n10._n)( |
| 1811 |
"The following block has been added to your site.", |
| 1812 |
"The following blocks have been added to your site.", |
| 1813 |
newBlockTypes.length |
| 1814 |
) }), |
| 1815 |
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(CompactList, { items: newBlockTypes }) |
| 1816 |
] |
| 1817 |
} |
| 1818 |
); |
| 1819 |
} |
| 1820 |
|
| 1821 |
// packages/block-directory/build-module/plugins/get-install-missing/index.mjs |
| 1822 |
var import_i18n12 = __toESM(require_i18n(), 1); |
| 1823 |
var import_components6 = __toESM(require_components(), 1); |
| 1824 |
var import_blocks7 = __toESM(require_blocks(), 1); |
| 1825 |
var import_element7 = __toESM(require_element(), 1); |
| 1826 |
var import_data11 = __toESM(require_data(), 1); |
| 1827 |
var import_core_data2 = __toESM(require_core_data(), 1); |
| 1828 |
var import_block_editor5 = __toESM(require_block_editor(), 1); |
| 1829 |
|
| 1830 |
// packages/block-directory/build-module/plugins/get-install-missing/install-button.mjs |
| 1831 |
var import_i18n11 = __toESM(require_i18n(), 1); |
| 1832 |
var import_components5 = __toESM(require_components(), 1); |
| 1833 |
var import_blocks6 = __toESM(require_blocks(), 1); |
| 1834 |
var import_data10 = __toESM(require_data(), 1); |
| 1835 |
var import_block_editor4 = __toESM(require_block_editor(), 1); |
| 1836 |
var import_jsx_runtime16 = __toESM(require_jsx_runtime(), 1); |
| 1837 |
function InstallButton({ attributes, block, clientId }) { |
| 1838 |
const isInstallingBlock = (0, import_data10.useSelect)( |
| 1839 |
(select) => select(store).isInstalling(block.id), |
| 1840 |
[block.id] |
| 1841 |
); |
| 1842 |
const { installBlockType: installBlockType2 } = (0, import_data10.useDispatch)(store); |
| 1843 |
const { replaceBlock } = (0, import_data10.useDispatch)(import_block_editor4.store); |
| 1844 |
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( |
| 1845 |
import_components5.Button, |
| 1846 |
{ |
| 1847 |
__next40pxDefaultSize: true, |
| 1848 |
onClick: () => installBlockType2(block).then((success) => { |
| 1849 |
if (success) { |
| 1850 |
const blockType = (0, import_blocks6.getBlockType)(block.name); |
| 1851 |
const [originalBlock] = (0, import_blocks6.parse)( |
| 1852 |
attributes.originalContent |
| 1853 |
); |
| 1854 |
if (originalBlock && blockType) { |
| 1855 |
replaceBlock( |
| 1856 |
clientId, |
| 1857 |
(0, import_blocks6.createBlock)( |
| 1858 |
blockType.name, |
| 1859 |
originalBlock.attributes, |
| 1860 |
originalBlock.innerBlocks |
| 1861 |
) |
| 1862 |
); |
| 1863 |
} |
| 1864 |
} |
| 1865 |
}), |
| 1866 |
accessibleWhenDisabled: true, |
| 1867 |
disabled: isInstallingBlock, |
| 1868 |
isBusy: isInstallingBlock, |
| 1869 |
variant: "primary", |
| 1870 |
children: (0, import_i18n11.sprintf)( |
| 1871 |
/* translators: %s: block name */ |
| 1872 |
(0, import_i18n11.__)("Install %s"), |
| 1873 |
block.title |
| 1874 |
) |
| 1875 |
} |
| 1876 |
); |
| 1877 |
} |
| 1878 |
|
| 1879 |
// packages/block-directory/build-module/plugins/get-install-missing/index.mjs |
| 1880 |
var import_jsx_runtime17 = __toESM(require_jsx_runtime(), 1); |
| 1881 |
var getInstallMissing = (OriginalComponent) => (props) => { |
| 1882 |
const { originalName } = props.attributes; |
| 1883 |
const { block, hasPermission } = (0, import_data11.useSelect)( |
| 1884 |
(select) => { |
| 1885 |
const { getDownloadableBlocks: getDownloadableBlocks3 } = select(store); |
| 1886 |
const blocks = getDownloadableBlocks3( |
| 1887 |
"block:" + originalName |
| 1888 |
).filter(({ name }) => originalName === name); |
| 1889 |
return { |
| 1890 |
hasPermission: select(import_core_data2.store).canUser( |
| 1891 |
"read", |
| 1892 |
"block-directory/search" |
| 1893 |
), |
| 1894 |
block: blocks.length && blocks[0] |
| 1895 |
}; |
| 1896 |
}, |
| 1897 |
[originalName] |
| 1898 |
); |
| 1899 |
if (!hasPermission || !block) { |
| 1900 |
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(OriginalComponent, { ...props }); |
| 1901 |
} |
| 1902 |
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ModifiedWarning, { ...props, originalBlock: block }); |
| 1903 |
}; |
| 1904 |
var ModifiedWarning = ({ originalBlock, ...props }) => { |
| 1905 |
const { originalName, originalUndelimitedContent, clientId } = props.attributes; |
| 1906 |
const { replaceBlock } = (0, import_data11.useDispatch)(import_block_editor5.store); |
| 1907 |
const convertToHTML = () => { |
| 1908 |
replaceBlock( |
| 1909 |
props.clientId, |
| 1910 |
(0, import_blocks7.createBlock)("core/html", { |
| 1911 |
content: originalUndelimitedContent |
| 1912 |
}) |
| 1913 |
); |
| 1914 |
}; |
| 1915 |
const hasContent = !!originalUndelimitedContent; |
| 1916 |
const hasHTMLBlock = (0, import_data11.useSelect)( |
| 1917 |
(select) => { |
| 1918 |
const { canInsertBlockType, getBlockRootClientId } = select(import_block_editor5.store); |
| 1919 |
return canInsertBlockType( |
| 1920 |
"core/html", |
| 1921 |
getBlockRootClientId(clientId) |
| 1922 |
); |
| 1923 |
}, |
| 1924 |
[clientId] |
| 1925 |
); |
| 1926 |
let messageHTML = (0, import_i18n12.sprintf)( |
| 1927 |
/* translators: %s: block name */ |
| 1928 |
(0, import_i18n12.__)( |
| 1929 |
"Your site doesn\u2019t include support for the %s block. You can try installing the block or remove it entirely." |
| 1930 |
), |
| 1931 |
originalBlock.title || originalName |
| 1932 |
); |
| 1933 |
const actions = [ |
| 1934 |
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)( |
| 1935 |
InstallButton, |
| 1936 |
{ |
| 1937 |
block: originalBlock, |
| 1938 |
attributes: props.attributes, |
| 1939 |
clientId: props.clientId |
| 1940 |
}, |
| 1941 |
"install" |
| 1942 |
) |
| 1943 |
]; |
| 1944 |
if (hasContent && hasHTMLBlock) { |
| 1945 |
messageHTML = (0, import_i18n12.sprintf)( |
| 1946 |
/* translators: %s: block name */ |
| 1947 |
(0, import_i18n12.__)( |
| 1948 |
"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." |
| 1949 |
), |
| 1950 |
originalBlock.title || originalName |
| 1951 |
); |
| 1952 |
actions.push( |
| 1953 |
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)( |
| 1954 |
import_components6.Button, |
| 1955 |
{ |
| 1956 |
__next40pxDefaultSize: true, |
| 1957 |
onClick: convertToHTML, |
| 1958 |
variant: "tertiary", |
| 1959 |
children: (0, import_i18n12.__)("Keep as HTML") |
| 1960 |
}, |
| 1961 |
"convert" |
| 1962 |
) |
| 1963 |
); |
| 1964 |
} |
| 1965 |
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { ...(0, import_block_editor5.useBlockProps)(), children: [ |
| 1966 |
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_block_editor5.Warning, { actions, children: messageHTML }), |
| 1967 |
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_element7.RawHTML, { children: originalUndelimitedContent }) |
| 1968 |
] }); |
| 1969 |
}; |
| 1970 |
var get_install_missing_default = getInstallMissing; |
| 1971 |
|
| 1972 |
// packages/block-directory/build-module/plugins/index.mjs |
| 1973 |
var import_jsx_runtime18 = __toESM(require_jsx_runtime(), 1); |
| 1974 |
(0, import_plugins.registerPlugin)("block-directory", { |
| 1975 |
// The icon is explicitly set to undefined to prevent PluginPrePublishPanel |
| 1976 |
// from rendering the fallback icon pluginIcon. |
| 1977 |
icon: void 0, |
| 1978 |
render() { |
| 1979 |
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [ |
| 1980 |
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(AutoBlockUninstaller, {}), |
| 1981 |
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(inserter_menu_downloadable_blocks_panel_default, {}), |
| 1982 |
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(InstalledBlocksPrePublishPanel, {}) |
| 1983 |
] }); |
| 1984 |
} |
| 1985 |
}); |
| 1986 |
(0, import_hooks.addFilter)( |
| 1987 |
"blocks.registerBlockType", |
| 1988 |
"block-directory/fallback", |
| 1989 |
(settings, name) => { |
| 1990 |
if (name !== "core/missing") { |
| 1991 |
return settings; |
| 1992 |
} |
| 1993 |
settings.edit = get_install_missing_default(settings.edit); |
| 1994 |
return settings; |
| 1995 |
} |
| 1996 |
); |
| 1997 |
return __toCommonJS(index_exports); |
| 1998 |
})(); |
| 1999 |
//# sourceMappingURL=index.js.map |
| 2000 |
|