| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 var wp; 2 (wp ||= {}).reusableBlocks = (() => { 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/data 35 var require_data = __commonJS({ 36 "package-external:@wordpress/data"(exports, module) { 37 module.exports = window.wp.data; 38 } 39 }); 40 41 // package-external:@wordpress/block-editor 42 var require_block_editor = __commonJS({ 43 "package-external:@wordpress/block-editor"(exports, module) { 44 module.exports = window.wp.blockEditor; 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/i18n 56 var require_i18n = __commonJS({ 57 "package-external:@wordpress/i18n"(exports, module) { 58 module.exports = window.wp.i18n; 59 } 60 }); 61 62 // package-external:@wordpress/deprecated 63 var require_deprecated = __commonJS({ 64 "package-external:@wordpress/deprecated"(exports, module) { 65 module.exports = window.wp.deprecated; 66 } 67 }); 68 69 // package-external:@wordpress/element 70 var require_element = __commonJS({ 71 "package-external:@wordpress/element"(exports, module) { 72 module.exports = window.wp.element; 73 } 74 }); 75 76 // package-external:@wordpress/components 77 var require_components = __commonJS({ 78 "package-external:@wordpress/components"(exports, module) { 79 module.exports = window.wp.components; 80 } 81 }); 82 83 // package-external:@wordpress/primitives 84 var require_primitives = __commonJS({ 85 "package-external:@wordpress/primitives"(exports, module) { 86 module.exports = window.wp.primitives; 87 } 88 }); 89 90 // vendor-external:react/jsx-runtime 91 var require_jsx_runtime = __commonJS({ 92 "vendor-external:react/jsx-runtime"(exports, module) { 93 module.exports = window.ReactJSXRuntime; 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/core-data 105 var require_core_data = __commonJS({ 106 "package-external:@wordpress/core-data"(exports, module) { 107 module.exports = window.wp.coreData; 108 } 109 }); 110 111 // package-external:@wordpress/url 112 var require_url = __commonJS({ 113 "package-external:@wordpress/url"(exports, module) { 114 module.exports = window.wp.url; 115 } 116 }); 117 118 // packages/reusable-blocks/build-module/index.mjs 119 var index_exports = {}; 120 __export(index_exports, { 121 ReusableBlocksMenuItems: () => ReusableBlocksMenuItems, 122 store: () => store 123 }); 124 125 // packages/reusable-blocks/build-module/store/index.mjs 126 var import_data2 = __toESM(require_data(), 1); 127 128 // packages/reusable-blocks/build-module/store/actions.mjs 129 var actions_exports = {}; 130 __export(actions_exports, { 131 __experimentalConvertBlockToStatic: () => __experimentalConvertBlockToStatic, 132 __experimentalConvertBlocksToReusable: () => __experimentalConvertBlocksToReusable, 133 __experimentalDeleteReusableBlock: () => __experimentalDeleteReusableBlock, 134 __experimentalSetEditingReusableBlock: () => __experimentalSetEditingReusableBlock 135 }); 136 var import_block_editor = __toESM(require_block_editor(), 1); 137 var import_blocks = __toESM(require_blocks(), 1); 138 var import_i18n = __toESM(require_i18n(), 1); 139 var import_deprecated = __toESM(require_deprecated(), 1); 140 var __experimentalConvertBlockToStatic = (clientId) => ({ registry }) => { 141 (0, import_deprecated.default)( 142 "wp.data.dispatch( 'core/reusable-blocks' ).__experimentalConvertBlockToStatic", 143 { 144 since: "7.1" 145 } 146 ); 147 const oldBlock = registry.select(import_block_editor.store).getBlock(clientId); 148 const reusableBlock = registry.select("core").getEditedEntityRecord( 149 "postType", 150 "wp_block", 151 oldBlock.attributes.ref 152 ); 153 const newBlocks = (0, import_blocks.parse)( 154 typeof reusableBlock.content === "function" ? reusableBlock.content(reusableBlock) : reusableBlock.content 155 ); 156 registry.dispatch(import_block_editor.store).replaceBlocks(oldBlock.clientId, newBlocks); 157 }; 158 var __experimentalConvertBlocksToReusable = (clientIds, title, syncType) => async ({ registry, dispatch }) => { 159 (0, import_deprecated.default)( 160 "wp.data.dispatch( 'core/reusable-blocks' ).__experimentalConvertBlocksToReusable", 161 { 162 since: "7.1" 163 } 164 ); 165 const meta = syncType === "unsynced" ? { 166 wp_pattern_sync_status: syncType 167 } : void 0; 168 const reusableBlock = { 169 title: title || (0, import_i18n.__)("Untitled pattern block"), 170 content: (0, import_blocks.serialize)( 171 registry.select(import_block_editor.store).getBlocksByClientId(clientIds) 172 ), 173 status: "publish", 174 meta 175 }; 176 const updatedRecord = await registry.dispatch("core").saveEntityRecord("postType", "wp_block", reusableBlock); 177 if (syncType === "unsynced") { 178 return; 179 } 180 const newBlock = (0, import_blocks.createBlock)("core/block", { 181 ref: updatedRecord.id 182 }); 183 registry.dispatch(import_block_editor.store).replaceBlocks(clientIds, newBlock); 184 dispatch.__experimentalSetEditingReusableBlock( 185 newBlock.clientId, 186 true 187 ); 188 }; 189 var __experimentalDeleteReusableBlock = (id) => async ({ registry }) => { 190 (0, import_deprecated.default)( 191 "wp.data.dispatch( 'core/reusable-blocks' ).__experimentalDeleteReusableBlock", 192 { 193 since: "7.1" 194 } 195 ); 196 const reusableBlock = registry.select("core").getEditedEntityRecord("postType", "wp_block", id); 197 if (!reusableBlock) { 198 return; 199 } 200 const allBlocks = registry.select(import_block_editor.store).getBlocks(); 201 const associatedBlocks = allBlocks.filter( 202 (block) => (0, import_blocks.isReusableBlock)(block) && block.attributes.ref === id 203 ); 204 const associatedBlockClientIds = associatedBlocks.map( 205 (block) => block.clientId 206 ); 207 if (associatedBlockClientIds.length) { 208 registry.dispatch(import_block_editor.store).removeBlocks(associatedBlockClientIds); 209 } 210 await registry.dispatch("core").deleteEntityRecord("postType", "wp_block", id); 211 }; 212 function __experimentalSetEditingReusableBlock(clientId, isEditing) { 213 (0, import_deprecated.default)( 214 "wp.data.dispatch( 'core/reusable-blocks' ).__experimentalSetEditingReusableBlock", 215 { 216 since: "7.1" 217 } 218 ); 219 return { 220 type: "SET_EDITING_REUSABLE_BLOCK", 221 clientId, 222 isEditing 223 }; 224 } 225 226 // packages/reusable-blocks/build-module/store/reducer.mjs 227 var import_data = __toESM(require_data(), 1); 228 function isEditingReusableBlock(state = {}, action) { 229 if (action?.type === "SET_EDITING_REUSABLE_BLOCK") { 230 return { 231 ...state, 232 [action.clientId]: action.isEditing 233 }; 234 } 235 return state; 236 } 237 var reducer_default = (0, import_data.combineReducers)({ 238 isEditingReusableBlock 239 }); 240 241 // packages/reusable-blocks/build-module/store/selectors.mjs 242 var selectors_exports = {}; 243 __export(selectors_exports, { 244 __experimentalIsEditingReusableBlock: () => __experimentalIsEditingReusableBlock 245 }); 246 var import_deprecated2 = __toESM(require_deprecated(), 1); 247 function __experimentalIsEditingReusableBlock(state, clientId) { 248 (0, import_deprecated2.default)( 249 "wp.data.select( 'core/reusable-blocks' ).__experimentalIsEditingReusableBlock", 250 { 251 since: "7.1" 252 } 253 ); 254 return state.isEditingReusableBlock[clientId]; 255 } 256 257 // packages/reusable-blocks/build-module/store/index.mjs 258 var STORE_NAME = "core/reusable-blocks"; 259 var store = (0, import_data2.createReduxStore)(STORE_NAME, { 260 actions: actions_exports, 261 reducer: reducer_default, 262 selectors: selectors_exports 263 }); 264 (0, import_data2.register)(store); 265 266 // packages/reusable-blocks/build-module/components/reusable-blocks-menu-items/index.mjs 267 var import_block_editor4 = __toESM(require_block_editor(), 1); 268 var import_deprecated3 = __toESM(require_deprecated(), 1); 269 270 // packages/reusable-blocks/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.mjs 271 var import_blocks2 = __toESM(require_blocks(), 1); 272 var import_block_editor2 = __toESM(require_block_editor(), 1); 273 var import_element = __toESM(require_element(), 1); 274 var import_components = __toESM(require_components(), 1); 275 276 // packages/icons/build-module/library/symbol.mjs 277 var import_primitives = __toESM(require_primitives(), 1); 278 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1); 279 var symbol_default = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.Path, { d: "M21.3 10.8l-5.6-5.6c-.7-.7-1.8-.7-2.5 0l-5.6 5.6c-.7.7-.7 1.8 0 2.5l5.6 5.6c.3.3.8.5 1.2.5s.9-.2 1.2-.5l5.6-5.6c.8-.7.8-1.9.1-2.5zm-1 1.4l-5.6 5.6c-.1.1-.3.1-.4 0l-5.6-5.6c-.1-.1-.1-.3 0-.4l5.6-5.6s.1-.1.2-.1.1 0 .2.1l5.6 5.6c.1.1.1.3 0 .4zm-16.6-.4L10 5.5l-1-1-6.3 6.3c-.7.7-.7 1.8 0 2.5L9 19.5l1.1-1.1-6.3-6.3c-.2 0-.2-.2-.1-.3z" }) }); 280 281 // packages/reusable-blocks/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.mjs 282 var import_data3 = __toESM(require_data(), 1); 283 var import_i18n2 = __toESM(require_i18n(), 1); 284 var import_notices = __toESM(require_notices(), 1); 285 var import_core_data = __toESM(require_core_data(), 1); 286 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1); 287 function ReusableBlockConvertButton({ 288 clientIds, 289 rootClientId, 290 onClose 291 }) { 292 const [syncType, setSyncType] = (0, import_element.useState)(void 0); 293 const [isModalOpen, setIsModalOpen] = (0, import_element.useState)(false); 294 const [title, setTitle] = (0, import_element.useState)(""); 295 const canConvert = (0, import_data3.useSelect)( 296 (select) => { 297 const { canUser } = select(import_core_data.store); 298 const { 299 getBlocksByClientId, 300 canInsertBlockType, 301 getBlockRootClientId 302 } = select(import_block_editor2.store); 303 const rootId = rootClientId || (clientIds.length > 0 ? getBlockRootClientId(clientIds[0]) : void 0); 304 const blocks = getBlocksByClientId(clientIds) ?? []; 305 const isReusable = blocks.length === 1 && blocks[0] && (0, import_blocks2.isReusableBlock)(blocks[0]) && !!select(import_core_data.store).getEntityRecord( 306 "postType", 307 "wp_block", 308 blocks[0].attributes.ref 309 ); 310 const _canConvert = ( 311 // Hide when this is already a reusable block. 312 !isReusable && // Hide when reusable blocks are disabled. 313 canInsertBlockType("core/block", rootId) && blocks.every( 314 (block) => ( 315 // Guard against the case where a regular block has *just* been converted. 316 !!block && // Hide on invalid blocks. 317 block.isValid && // Hide when block doesn't support being made reusable. 318 (0, import_blocks2.hasBlockSupport)(block.name, "reusable", true) 319 ) 320 ) && // Hide when current doesn't have permission to do that. 321 // Blocks refers to the wp_block post type, this checks the ability to create a post of that type. 322 !!canUser("create", { 323 kind: "postType", 324 name: "wp_block" 325 }) 326 ); 327 return _canConvert; 328 }, 329 [clientIds, rootClientId] 330 ); 331 const { __experimentalConvertBlocksToReusable: convertBlocksToReusable } = (0, import_data3.useDispatch)(store); 332 const { createSuccessNotice, createErrorNotice } = (0, import_data3.useDispatch)(import_notices.store); 333 const onConvert = (0, import_element.useCallback)( 334 async function(reusableBlockTitle) { 335 try { 336 await convertBlocksToReusable( 337 clientIds, 338 reusableBlockTitle, 339 syncType 340 ); 341 createSuccessNotice( 342 !syncType ? (0, import_i18n2.sprintf)( 343 // translators: %s: the name the user has given to the pattern. 344 (0, import_i18n2.__)("Synced pattern created: %s"), 345 reusableBlockTitle 346 ) : (0, import_i18n2.sprintf)( 347 // translators: %s: the name the user has given to the pattern. 348 (0, import_i18n2.__)("Unsynced pattern created: %s"), 349 reusableBlockTitle 350 ), 351 { 352 type: "snackbar", 353 id: "convert-to-reusable-block-success" 354 } 355 ); 356 } catch (error) { 357 createErrorNotice(error.message, { 358 type: "snackbar", 359 id: "convert-to-reusable-block-error" 360 }); 361 } 362 }, 363 [ 364 convertBlocksToReusable, 365 clientIds, 366 syncType, 367 createSuccessNotice, 368 createErrorNotice 369 ] 370 ); 371 if (!canConvert) { 372 return null; 373 } 374 return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [ 375 /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_components.MenuItem, { icon: symbol_default, onClick: () => setIsModalOpen(true), children: (0, import_i18n2.__)("Create pattern") }), 376 isModalOpen && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( 377 import_components.Modal, 378 { 379 title: (0, import_i18n2.__)("Create pattern"), 380 onRequestClose: () => { 381 setIsModalOpen(false); 382 setTitle(""); 383 }, 384 overlayClassName: "reusable-blocks-menu-items__convert-modal", 385 children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( 386 "form", 387 { 388 onSubmit: (event) => { 389 event.preventDefault(); 390 onConvert(title); 391 setIsModalOpen(false); 392 setTitle(""); 393 onClose(); 394 }, 395 children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_components.__experimentalVStack, { spacing: "5", children: [ 396 /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( 397 import_components.TextControl, 398 { 399 label: (0, import_i18n2.__)("Name"), 400 value: title, 401 onChange: setTitle, 402 placeholder: (0, import_i18n2.__)("My pattern") 403 } 404 ), 405 /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( 406 import_components.ToggleControl, 407 { 408 label: (0, import_i18n2._x)("Synced", "pattern (singular)"), 409 help: (0, import_i18n2.__)( 410 "Sync this pattern across multiple locations." 411 ), 412 checked: !syncType, 413 onChange: () => { 414 setSyncType( 415 !syncType ? "unsynced" : void 0 416 ); 417 } 418 } 419 ), 420 /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_components.__experimentalHStack, { justify: "right", children: [ 421 /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( 422 import_components.Button, 423 { 424 __next40pxDefaultSize: true, 425 variant: "tertiary", 426 onClick: () => { 427 setIsModalOpen(false); 428 setTitle(""); 429 }, 430 children: (0, import_i18n2.__)("Cancel") 431 } 432 ), 433 /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( 434 import_components.Button, 435 { 436 __next40pxDefaultSize: true, 437 variant: "primary", 438 type: "submit", 439 children: (0, import_i18n2.__)("Create") 440 } 441 ) 442 ] }) 443 ] }) 444 } 445 ) 446 } 447 ) 448 ] }); 449 } 450 451 // packages/reusable-blocks/build-module/components/reusable-blocks-menu-items/reusable-blocks-manage-button.mjs 452 var import_components2 = __toESM(require_components(), 1); 453 var import_i18n3 = __toESM(require_i18n(), 1); 454 var import_blocks3 = __toESM(require_blocks(), 1); 455 var import_data4 = __toESM(require_data(), 1); 456 var import_element2 = __toESM(require_element(), 1); 457 var import_block_editor3 = __toESM(require_block_editor(), 1); 458 var import_url = __toESM(require_url(), 1); 459 var import_core_data2 = __toESM(require_core_data(), 1); 460 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1); 461 function ReusableBlocksManageButton({ clientId }) { 462 const [showConfirmDialog, setShowConfirmDialog] = (0, import_element2.useState)(false); 463 const { canRemove, isVisible, managePatternsUrl } = (0, import_data4.useSelect)( 464 (select) => { 465 const { getBlock, canRemoveBlock } = select(import_block_editor3.store); 466 const { canUser } = select(import_core_data2.store); 467 const reusableBlock = getBlock(clientId); 468 return { 469 canRemove: canRemoveBlock(clientId), 470 isVisible: !!reusableBlock && (0, import_blocks3.isReusableBlock)(reusableBlock) && !!canUser("update", { 471 kind: "postType", 472 name: "wp_block", 473 id: reusableBlock.attributes.ref 474 }), 475 // The site editor and templates both check whether the user 476 // has edit_theme_options capabilities. We can leverage that here 477 // and omit the manage patterns link if the user can't access it. 478 managePatternsUrl: canUser("create", { 479 kind: "postType", 480 name: "wp_template" 481 }) ? (0, import_url.addQueryArgs)("site-editor.php", { 482 p: "/pattern" 483 }) : (0, import_url.addQueryArgs)("edit.php", { 484 post_type: "wp_block" 485 }) 486 }; 487 }, 488 [clientId] 489 ); 490 const { __experimentalConvertBlockToStatic: convertBlockToStatic } = (0, import_data4.useDispatch)(store); 491 if (!isVisible) { 492 return null; 493 } 494 const handleDetach = () => { 495 convertBlockToStatic(clientId); 496 setShowConfirmDialog(false); 497 }; 498 return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [ 499 /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_components2.MenuItem, { href: managePatternsUrl, children: (0, import_i18n3.__)("Manage patterns") }), 500 canRemove && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [ 501 /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_components2.MenuItem, { onClick: () => setShowConfirmDialog(true), children: (0, import_i18n3.__)("Disconnect pattern") }), 502 /* @__PURE__ */ (0, import_jsx_runtime3.jsx)( 503 import_components2.__experimentalConfirmDialog, 504 { 505 isOpen: showConfirmDialog, 506 onConfirm: handleDetach, 507 onCancel: () => setShowConfirmDialog(false), 508 confirmButtonText: (0, import_i18n3.__)("Disconnect"), 509 size: "medium", 510 title: (0, import_i18n3.__)("Disconnect pattern?"), 511 __experimentalHideHeader: false, 512 children: (0, import_i18n3.__)( 513 "Blocks will be separated from the original pattern and will be fully editable. Future changes to the pattern will not apply here." 514 ) 515 } 516 ) 517 ] }) 518 ] }); 519 } 520 var reusable_blocks_manage_button_default = ReusableBlocksManageButton; 521 522 // packages/reusable-blocks/build-module/components/reusable-blocks-menu-items/index.mjs 523 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1); 524 function ReusableBlocksMenuItems({ rootClientId }) { 525 (0, import_deprecated3.default)("wp.reusableBlocks.ReusableBlocksMenuItems", { 526 since: "7.1" 527 }); 528 return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_block_editor4.BlockSettingsMenuControls, { children: ({ onClose, selectedClientIds }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [ 529 /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( 530 ReusableBlockConvertButton, 531 { 532 clientIds: selectedClientIds, 533 rootClientId, 534 onClose 535 } 536 ), 537 selectedClientIds.length === 1 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( 538 reusable_blocks_manage_button_default, 539 { 540 clientId: selectedClientIds[0] 541 } 542 ) 543 ] }) }); 544 } 545 return __toCommonJS(index_exports); 546 })();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Fri Jul 24 08:20:19 2026 | Cross-referenced by PHPXref |