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