[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 /******/ (() => { // webpackBootstrap 2 /******/ "use strict"; 3 /******/ // The require scope 4 /******/ var __webpack_require__ = {}; 5 /******/ 6 /************************************************************************/ 7 /******/ /* webpack/runtime/define property getters */ 8 /******/ (() => { 9 /******/ // define getter functions for harmony exports 10 /******/ __webpack_require__.d = (exports, definition) => { 11 /******/ for(var key in definition) { 12 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 13 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 14 /******/ } 15 /******/ } 16 /******/ }; 17 /******/ })(); 18 /******/ 19 /******/ /* webpack/runtime/hasOwnProperty shorthand */ 20 /******/ (() => { 21 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 22 /******/ })(); 23 /******/ 24 /******/ /* webpack/runtime/make namespace object */ 25 /******/ (() => { 26 /******/ // define __esModule on exports 27 /******/ __webpack_require__.r = (exports) => { 28 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 29 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 30 /******/ } 31 /******/ Object.defineProperty(exports, '__esModule', { value: true }); 32 /******/ }; 33 /******/ })(); 34 /******/ 35 /************************************************************************/ 36 var __webpack_exports__ = {}; 37 // ESM COMPAT FLAG 38 __webpack_require__.r(__webpack_exports__); 39 40 // EXPORTS 41 __webpack_require__.d(__webpack_exports__, { 42 privateApis: () => (/* reexport */ privateApis), 43 store: () => (/* reexport */ store) 44 }); 45 46 // NAMESPACE OBJECT: ./node_modules/@wordpress/patterns/build-module/store/actions.js 47 var actions_namespaceObject = {}; 48 __webpack_require__.r(actions_namespaceObject); 49 __webpack_require__.d(actions_namespaceObject, { 50 convertSyncedPatternToStatic: () => (convertSyncedPatternToStatic), 51 createPattern: () => (createPattern), 52 createPatternFromFile: () => (createPatternFromFile), 53 setEditingPattern: () => (setEditingPattern) 54 }); 55 56 // NAMESPACE OBJECT: ./node_modules/@wordpress/patterns/build-module/store/selectors.js 57 var selectors_namespaceObject = {}; 58 __webpack_require__.r(selectors_namespaceObject); 59 __webpack_require__.d(selectors_namespaceObject, { 60 isEditingPattern: () => (selectors_isEditingPattern) 61 }); 62 63 ;// CONCATENATED MODULE: external ["wp","data"] 64 const external_wp_data_namespaceObject = window["wp"]["data"]; 65 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/store/reducer.js 66 /** 67 * WordPress dependencies 68 */ 69 70 function isEditingPattern(state = {}, action) { 71 if (action?.type === 'SET_EDITING_PATTERN') { 72 return { 73 ...state, 74 [action.clientId]: action.isEditing 75 }; 76 } 77 return state; 78 } 79 /* harmony default export */ const reducer = ((0,external_wp_data_namespaceObject.combineReducers)({ 80 isEditingPattern 81 })); 82 83 ;// CONCATENATED MODULE: external ["wp","blocks"] 84 const external_wp_blocks_namespaceObject = window["wp"]["blocks"]; 85 ;// CONCATENATED MODULE: external ["wp","coreData"] 86 const external_wp_coreData_namespaceObject = window["wp"]["coreData"]; 87 ;// CONCATENATED MODULE: external ["wp","blockEditor"] 88 const external_wp_blockEditor_namespaceObject = window["wp"]["blockEditor"]; 89 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/constants.js 90 const PATTERN_TYPES = { 91 theme: 'pattern', 92 user: 'wp_block' 93 }; 94 const PATTERN_DEFAULT_CATEGORY = 'all-patterns'; 95 const PATTERN_USER_CATEGORY = 'my-patterns'; 96 const EXCLUDED_PATTERN_SOURCES = ['core', 'pattern-directory/core', 'pattern-directory/featured']; 97 const PATTERN_SYNC_TYPES = { 98 full: 'fully', 99 unsynced: 'unsynced' 100 }; 101 102 // TODO: This should not be hardcoded. Maybe there should be a config and/or an UI. 103 const PARTIAL_SYNCING_SUPPORTED_BLOCKS = { 104 'core/paragraph': ['content'], 105 'core/heading': ['content'], 106 'core/button': ['text', 'url', 'linkTarget', 'rel'], 107 'core/image': ['id', 'url', 'title', 'alt'] 108 }; 109 110 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/store/actions.js 111 /** 112 * WordPress dependencies 113 */ 114 115 116 117 118 119 /** 120 * Internal dependencies 121 */ 122 123 124 /** 125 * Returns a generator converting one or more static blocks into a pattern, or creating a new empty pattern. 126 * 127 * @param {string} title Pattern title. 128 * @param {'full'|'unsynced'} syncType They way block is synced, 'full' or 'unsynced'. 129 * @param {string|undefined} [content] Optional serialized content of blocks to convert to pattern. 130 * @param {number[]|undefined} [categories] Ids of any selected categories. 131 */ 132 const createPattern = (title, syncType, content, categories) => async ({ 133 registry 134 }) => { 135 const meta = syncType === PATTERN_SYNC_TYPES.unsynced ? { 136 wp_pattern_sync_status: syncType 137 } : undefined; 138 const reusableBlock = { 139 title, 140 content, 141 status: 'publish', 142 meta, 143 wp_pattern_category: categories 144 }; 145 const updatedRecord = await registry.dispatch(external_wp_coreData_namespaceObject.store).saveEntityRecord('postType', 'wp_block', reusableBlock); 146 return updatedRecord; 147 }; 148 149 /** 150 * Create a pattern from a JSON file. 151 * @param {File} file The JSON file instance of the pattern. 152 * @param {number[]|undefined} [categories] Ids of any selected categories. 153 */ 154 const createPatternFromFile = (file, categories) => async ({ 155 dispatch 156 }) => { 157 const fileContent = await file.text(); 158 /** @type {import('./types').PatternJSON} */ 159 let parsedContent; 160 try { 161 parsedContent = JSON.parse(fileContent); 162 } catch (e) { 163 throw new Error('Invalid JSON file'); 164 } 165 if (parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== 'string' || typeof parsedContent.content !== 'string' || parsedContent.syncStatus && typeof parsedContent.syncStatus !== 'string') { 166 throw new Error('Invalid pattern JSON file'); 167 } 168 const pattern = await dispatch.createPattern(parsedContent.title, parsedContent.syncStatus, parsedContent.content, categories); 169 return pattern; 170 }; 171 172 /** 173 * Returns a generator converting a synced pattern block into a static block. 174 * 175 * @param {string} clientId The client ID of the block to attach. 176 */ 177 const convertSyncedPatternToStatic = clientId => ({ 178 registry 179 }) => { 180 const patternBlock = registry.select(external_wp_blockEditor_namespaceObject.store).getBlock(clientId); 181 function cloneBlocksAndRemoveBindings(blocks) { 182 return blocks.map(block => { 183 let metadata = block.attributes.metadata; 184 if (metadata) { 185 metadata = { 186 ...metadata 187 }; 188 delete metadata.id; 189 delete metadata.bindings; 190 } 191 return (0,external_wp_blocks_namespaceObject.cloneBlock)(block, { 192 metadata: metadata && Object.keys(metadata).length > 0 ? metadata : undefined 193 }, cloneBlocksAndRemoveBindings(block.innerBlocks)); 194 }); 195 } 196 registry.dispatch(external_wp_blockEditor_namespaceObject.store).replaceBlocks(patternBlock.clientId, cloneBlocksAndRemoveBindings(patternBlock.innerBlocks)); 197 }; 198 199 /** 200 * Returns an action descriptor for SET_EDITING_PATTERN action. 201 * 202 * @param {string} clientId The clientID of the pattern to target. 203 * @param {boolean} isEditing Whether the block should be in editing state. 204 * @return {Object} Action descriptor. 205 */ 206 function setEditingPattern(clientId, isEditing) { 207 return { 208 type: 'SET_EDITING_PATTERN', 209 clientId, 210 isEditing 211 }; 212 } 213 214 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/store/constants.js 215 /** 216 * Module Constants 217 */ 218 const STORE_NAME = 'core/patterns'; 219 220 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/store/selectors.js 221 /** 222 * Returns true if pattern is in the editing state. 223 * 224 * @param {Object} state Global application state. 225 * @param {number} clientId the clientID of the block. 226 * @return {boolean} Whether the pattern is in the editing state. 227 */ 228 function selectors_isEditingPattern(state, clientId) { 229 return state.isEditingPattern[clientId]; 230 } 231 232 ;// CONCATENATED MODULE: external ["wp","privateApis"] 233 const external_wp_privateApis_namespaceObject = window["wp"]["privateApis"]; 234 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/lock-unlock.js 235 /** 236 * WordPress dependencies 237 */ 238 239 const { 240 lock, 241 unlock 242 } = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', '@wordpress/patterns'); 243 244 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/store/index.js 245 /** 246 * WordPress dependencies 247 */ 248 249 250 /** 251 * Internal dependencies 252 */ 253 254 255 256 257 258 259 /** 260 * Post editor data store configuration. 261 * 262 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registerStore 263 * 264 * @type {Object} 265 */ 266 const storeConfig = { 267 reducer: reducer 268 }; 269 270 /** 271 * Store definition for the editor namespace. 272 * 273 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore 274 * 275 * @type {Object} 276 */ 277 const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, { 278 ...storeConfig 279 }); 280 (0,external_wp_data_namespaceObject.register)(store); 281 unlock(store).registerPrivateActions(actions_namespaceObject); 282 unlock(store).registerPrivateSelectors(selectors_namespaceObject); 283 284 ;// CONCATENATED MODULE: external "React" 285 const external_React_namespaceObject = window["React"]; 286 ;// CONCATENATED MODULE: external ["wp","components"] 287 const external_wp_components_namespaceObject = window["wp"]["components"]; 288 ;// CONCATENATED MODULE: external ["wp","i18n"] 289 const external_wp_i18n_namespaceObject = window["wp"]["i18n"]; 290 ;// CONCATENATED MODULE: external ["wp","element"] 291 const external_wp_element_namespaceObject = window["wp"]["element"]; 292 ;// CONCATENATED MODULE: external ["wp","notices"] 293 const external_wp_notices_namespaceObject = window["wp"]["notices"]; 294 ;// CONCATENATED MODULE: external ["wp","compose"] 295 const external_wp_compose_namespaceObject = window["wp"]["compose"]; 296 ;// CONCATENATED MODULE: external ["wp","htmlEntities"] 297 const external_wp_htmlEntities_namespaceObject = window["wp"]["htmlEntities"]; 298 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/components/category-selector.js 299 300 /** 301 * WordPress dependencies 302 */ 303 304 305 306 307 308 const unescapeString = arg => { 309 return (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(arg); 310 }; 311 const CATEGORY_SLUG = 'wp_pattern_category'; 312 function CategorySelector({ 313 categoryTerms, 314 onChange, 315 categoryMap 316 }) { 317 const [search, setSearch] = (0,external_wp_element_namespaceObject.useState)(''); 318 const debouncedSearch = (0,external_wp_compose_namespaceObject.useDebounce)(setSearch, 500); 319 const suggestions = (0,external_wp_element_namespaceObject.useMemo)(() => { 320 return Array.from(categoryMap.values()).map(category => unescapeString(category.label)).filter(category => { 321 if (search !== '') { 322 return category.toLowerCase().includes(search.toLowerCase()); 323 } 324 return true; 325 }).sort((a, b) => a.localeCompare(b)); 326 }, [search, categoryMap]); 327 function handleChange(termNames) { 328 const uniqueTerms = termNames.reduce((terms, newTerm) => { 329 if (!terms.some(term => term.toLowerCase() === newTerm.toLowerCase())) { 330 terms.push(newTerm); 331 } 332 return terms; 333 }, []); 334 onChange(uniqueTerms); 335 } 336 return (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.FormTokenField, { 337 className: "patterns-menu-items__convert-modal-categories", 338 value: categoryTerms, 339 suggestions: suggestions, 340 onChange: handleChange, 341 onInputChange: debouncedSearch, 342 label: (0,external_wp_i18n_namespaceObject.__)('Categories'), 343 tokenizeOnBlur: true, 344 __experimentalExpandOnFocus: true, 345 __next40pxDefaultSize: true, 346 __nextHasNoMarginBottom: true 347 }); 348 } 349 350 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/private-hooks.js 351 /** 352 * WordPress dependencies 353 */ 354 355 356 357 358 /** 359 * Internal dependencies 360 */ 361 362 363 /** 364 * Helper hook that creates a Map with the core and user patterns categories 365 * and removes any duplicates. It's used when we need to create new user 366 * categories when creating or importing patterns. 367 * This hook also provides a function to find or create a pattern category. 368 * 369 * @return {Object} The merged categories map and the callback function to find or create a category. 370 */ 371 function useAddPatternCategory() { 372 const { 373 saveEntityRecord, 374 invalidateResolution 375 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_coreData_namespaceObject.store); 376 const { 377 corePatternCategories, 378 userPatternCategories 379 } = (0,external_wp_data_namespaceObject.useSelect)(select => { 380 const { 381 getUserPatternCategories, 382 getBlockPatternCategories 383 } = select(external_wp_coreData_namespaceObject.store); 384 return { 385 corePatternCategories: getBlockPatternCategories(), 386 userPatternCategories: getUserPatternCategories() 387 }; 388 }, []); 389 const categoryMap = (0,external_wp_element_namespaceObject.useMemo)(() => { 390 // Merge the user and core pattern categories and remove any duplicates. 391 const uniqueCategories = new Map(); 392 userPatternCategories.forEach(category => { 393 uniqueCategories.set(category.label.toLowerCase(), { 394 label: category.label, 395 name: category.name, 396 id: category.id 397 }); 398 }); 399 corePatternCategories.forEach(category => { 400 if (!uniqueCategories.has(category.label.toLowerCase()) && 401 // There are two core categories with `Post` label so explicitly remove the one with 402 // the `query` slug to avoid any confusion. 403 category.name !== 'query') { 404 uniqueCategories.set(category.label.toLowerCase(), { 405 label: category.label, 406 name: category.name 407 }); 408 } 409 }); 410 return uniqueCategories; 411 }, [userPatternCategories, corePatternCategories]); 412 async function findOrCreateTerm(term) { 413 try { 414 const existingTerm = categoryMap.get(term.toLowerCase()); 415 if (existingTerm?.id) { 416 return existingTerm.id; 417 } 418 // If we have an existing core category we need to match the new user category to the 419 // correct slug rather than autogenerating it to prevent duplicates, eg. the core `Headers` 420 // category uses the singular `header` as the slug. 421 const termData = existingTerm ? { 422 name: existingTerm.label, 423 slug: existingTerm.name 424 } : { 425 name: term 426 }; 427 const newTerm = await saveEntityRecord('taxonomy', CATEGORY_SLUG, termData, { 428 throwOnError: true 429 }); 430 invalidateResolution('getUserPatternCategories'); 431 return newTerm.id; 432 } catch (error) { 433 if (error.code !== 'term_exists') { 434 throw error; 435 } 436 return error.data.term_id; 437 } 438 } 439 return { 440 categoryMap, 441 findOrCreateTerm 442 }; 443 } 444 445 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/components/create-pattern-modal.js 446 447 /** 448 * WordPress dependencies 449 */ 450 451 452 453 454 455 456 /** 457 * Internal dependencies 458 */ 459 460 461 462 463 464 function CreatePatternModal({ 465 className = 'patterns-menu-items__convert-modal', 466 modalTitle = (0,external_wp_i18n_namespaceObject.__)('Create pattern'), 467 ...restProps 468 }) { 469 return (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.Modal, { 470 title: modalTitle, 471 onRequestClose: restProps.onClose, 472 overlayClassName: className 473 }, (0,external_React_namespaceObject.createElement)(CreatePatternModalContents, { 474 ...restProps 475 })); 476 } 477 function CreatePatternModalContents({ 478 confirmLabel = (0,external_wp_i18n_namespaceObject.__)('Create'), 479 defaultCategories = [], 480 content, 481 onClose, 482 onError, 483 onSuccess, 484 defaultSyncType = PATTERN_SYNC_TYPES.full, 485 defaultTitle = '' 486 }) { 487 const [syncType, setSyncType] = (0,external_wp_element_namespaceObject.useState)(defaultSyncType); 488 const [categoryTerms, setCategoryTerms] = (0,external_wp_element_namespaceObject.useState)(defaultCategories); 489 const [title, setTitle] = (0,external_wp_element_namespaceObject.useState)(defaultTitle); 490 const [isSaving, setIsSaving] = (0,external_wp_element_namespaceObject.useState)(false); 491 const { 492 createPattern 493 } = unlock((0,external_wp_data_namespaceObject.useDispatch)(store)); 494 const { 495 createErrorNotice 496 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store); 497 const { 498 categoryMap, 499 findOrCreateTerm 500 } = useAddPatternCategory(); 501 async function onCreate(patternTitle, sync) { 502 if (!title || isSaving) { 503 return; 504 } 505 try { 506 setIsSaving(true); 507 const categories = await Promise.all(categoryTerms.map(termName => findOrCreateTerm(termName))); 508 const newPattern = await createPattern(patternTitle, sync, typeof content === 'function' ? content() : content, categories); 509 onSuccess({ 510 pattern: newPattern, 511 categoryId: PATTERN_DEFAULT_CATEGORY 512 }); 513 } catch (error) { 514 createErrorNotice(error.message, { 515 type: 'snackbar', 516 id: 'pattern-create' 517 }); 518 onError?.(); 519 } finally { 520 setIsSaving(false); 521 setCategoryTerms([]); 522 setTitle(''); 523 } 524 } 525 return (0,external_React_namespaceObject.createElement)("form", { 526 onSubmit: event => { 527 event.preventDefault(); 528 onCreate(title, syncType); 529 } 530 }, (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.__experimentalVStack, { 531 spacing: "5" 532 }, (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.TextControl, { 533 label: (0,external_wp_i18n_namespaceObject.__)('Name'), 534 value: title, 535 onChange: setTitle, 536 placeholder: (0,external_wp_i18n_namespaceObject.__)('My pattern'), 537 className: "patterns-create-modal__name-input", 538 __nextHasNoMarginBottom: true, 539 __next40pxDefaultSize: true 540 }), (0,external_React_namespaceObject.createElement)(CategorySelector, { 541 categoryTerms: categoryTerms, 542 onChange: setCategoryTerms, 543 categoryMap: categoryMap 544 }), (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.ToggleControl, { 545 label: (0,external_wp_i18n_namespaceObject._x)('Synced', 'Option that makes an individual pattern synchronized'), 546 help: (0,external_wp_i18n_namespaceObject.__)('Sync this pattern across multiple locations.'), 547 checked: syncType === PATTERN_SYNC_TYPES.full, 548 onChange: () => { 549 setSyncType(syncType === PATTERN_SYNC_TYPES.full ? PATTERN_SYNC_TYPES.unsynced : PATTERN_SYNC_TYPES.full); 550 } 551 }), (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.__experimentalHStack, { 552 justify: "right" 553 }, (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, { 554 __next40pxDefaultSize: true, 555 variant: "tertiary", 556 onClick: () => { 557 onClose(); 558 setTitle(''); 559 } 560 }, (0,external_wp_i18n_namespaceObject.__)('Cancel')), (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, { 561 __next40pxDefaultSize: true, 562 variant: "primary", 563 type: "submit", 564 "aria-disabled": !title || isSaving, 565 isBusy: isSaving 566 }, confirmLabel)))); 567 } 568 569 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/components/duplicate-pattern-modal.js 570 571 /** 572 * WordPress dependencies 573 */ 574 575 576 577 578 579 /** 580 * Internal dependencies 581 */ 582 583 584 function getTermLabels(pattern, categories) { 585 // Theme patterns rely on core pattern categories. 586 if (pattern.type !== PATTERN_TYPES.user) { 587 return categories.core?.filter(category => pattern.categories.includes(category.name)).map(category => category.label); 588 } 589 return categories.user?.filter(category => pattern.wp_pattern_category.includes(category.id)).map(category => category.label); 590 } 591 function useDuplicatePatternProps({ 592 pattern, 593 onSuccess 594 }) { 595 const { 596 createSuccessNotice 597 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store); 598 const categories = (0,external_wp_data_namespaceObject.useSelect)(select => { 599 const { 600 getUserPatternCategories, 601 getBlockPatternCategories 602 } = select(external_wp_coreData_namespaceObject.store); 603 return { 604 core: getBlockPatternCategories(), 605 user: getUserPatternCategories() 606 }; 607 }); 608 if (!pattern) { 609 return null; 610 } 611 return { 612 content: pattern.content, 613 defaultCategories: getTermLabels(pattern, categories), 614 defaultSyncType: pattern.type !== PATTERN_TYPES.user // Theme patterns are unsynced by default. 615 ? PATTERN_SYNC_TYPES.unsynced : pattern.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full, 616 defaultTitle: (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: Existing pattern title */ 617 (0,external_wp_i18n_namespaceObject.__)('%s (Copy)'), typeof pattern.title === 'string' ? pattern.title : pattern.title.raw), 618 onSuccess: ({ 619 pattern: newPattern 620 }) => { 621 createSuccessNotice((0,external_wp_i18n_namespaceObject.sprintf)( 622 // translators: %s: The new pattern's title e.g. 'Call to action (copy)'. 623 (0,external_wp_i18n_namespaceObject.__)('"%s" duplicated.'), newPattern.title.raw), { 624 type: 'snackbar', 625 id: 'patterns-create' 626 }); 627 onSuccess?.({ 628 pattern: newPattern 629 }); 630 } 631 }; 632 } 633 function DuplicatePatternModal({ 634 pattern, 635 onClose, 636 onSuccess 637 }) { 638 const duplicatedProps = useDuplicatePatternProps({ 639 pattern, 640 onSuccess 641 }); 642 if (!pattern) { 643 return null; 644 } 645 return (0,external_React_namespaceObject.createElement)(CreatePatternModal, { 646 modalTitle: (0,external_wp_i18n_namespaceObject.__)('Duplicate pattern'), 647 confirmLabel: (0,external_wp_i18n_namespaceObject.__)('Duplicate'), 648 onClose: onClose, 649 onError: onClose, 650 ...duplicatedProps 651 }); 652 } 653 654 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/components/rename-pattern-modal.js 655 656 /** 657 * WordPress dependencies 658 */ 659 660 661 662 663 664 665 666 function RenamePatternModal({ 667 onClose, 668 onError, 669 onSuccess, 670 pattern, 671 ...props 672 }) { 673 const originalName = (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(pattern.title); 674 const [name, setName] = (0,external_wp_element_namespaceObject.useState)(originalName); 675 const [isSaving, setIsSaving] = (0,external_wp_element_namespaceObject.useState)(false); 676 const { 677 editEntityRecord, 678 __experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits 679 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_coreData_namespaceObject.store); 680 const { 681 createSuccessNotice, 682 createErrorNotice 683 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store); 684 const onRename = async event => { 685 event.preventDefault(); 686 if (!name || name === pattern.title || isSaving) { 687 return; 688 } 689 try { 690 await editEntityRecord('postType', pattern.type, pattern.id, { 691 title: name 692 }); 693 setIsSaving(true); 694 setName(''); 695 onClose?.(); 696 const savedRecord = await saveSpecifiedEntityEdits('postType', pattern.type, pattern.id, ['title'], { 697 throwOnError: true 698 }); 699 onSuccess?.(savedRecord); 700 createSuccessNotice((0,external_wp_i18n_namespaceObject.__)('Pattern renamed'), { 701 type: 'snackbar', 702 id: 'pattern-update' 703 }); 704 } catch (error) { 705 onError?.(); 706 const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : (0,external_wp_i18n_namespaceObject.__)('An error occurred while renaming the pattern.'); 707 createErrorNotice(errorMessage, { 708 type: 'snackbar', 709 id: 'pattern-update' 710 }); 711 } finally { 712 setIsSaving(false); 713 setName(''); 714 } 715 }; 716 const onRequestClose = () => { 717 onClose?.(); 718 setName(''); 719 }; 720 return (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.Modal, { 721 title: (0,external_wp_i18n_namespaceObject.__)('Rename'), 722 ...props, 723 onRequestClose: onClose 724 }, (0,external_React_namespaceObject.createElement)("form", { 725 onSubmit: onRename 726 }, (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.__experimentalVStack, { 727 spacing: "5" 728 }, (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.TextControl, { 729 __nextHasNoMarginBottom: true, 730 __next40pxDefaultSize: true, 731 label: (0,external_wp_i18n_namespaceObject.__)('Name'), 732 value: name, 733 onChange: setName, 734 required: true 735 }), (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.__experimentalHStack, { 736 justify: "right" 737 }, (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, { 738 __next40pxDefaultSize: true, 739 variant: "tertiary", 740 onClick: onRequestClose 741 }, (0,external_wp_i18n_namespaceObject.__)('Cancel')), (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, { 742 __next40pxDefaultSize: true, 743 variant: "primary", 744 type: "submit" 745 }, (0,external_wp_i18n_namespaceObject.__)('Save')))))); 746 } 747 748 ;// CONCATENATED MODULE: external ["wp","primitives"] 749 const external_wp_primitives_namespaceObject = window["wp"]["primitives"]; 750 ;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/symbol.js 751 752 /** 753 * WordPress dependencies 754 */ 755 756 const symbol = (0,external_React_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, { 757 xmlns: "http://www.w3.org/2000/svg", 758 viewBox: "0 0 24 24" 759 }, (0,external_React_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, { 760 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" 761 })); 762 /* harmony default export */ const library_symbol = (symbol); 763 764 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/components/pattern-convert-button.js 765 766 /** 767 * WordPress dependencies 768 */ 769 770 771 772 773 774 775 776 777 778 /** 779 * Internal dependencies 780 */ 781 782 783 784 785 786 /** 787 * Menu control to convert block(s) to a pattern block. 788 * 789 * @param {Object} props Component props. 790 * @param {string[]} props.clientIds Client ids of selected blocks. 791 * @param {string} props.rootClientId ID of the currently selected top-level block. 792 * @param {()=>void} props.closeBlockSettingsMenu Callback to close the block settings menu dropdown. 793 * @return {import('react').ComponentType} The menu control or null. 794 */ 795 function PatternConvertButton({ 796 clientIds, 797 rootClientId, 798 closeBlockSettingsMenu 799 }) { 800 const { 801 createSuccessNotice 802 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store); 803 const { 804 replaceBlocks 805 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store); 806 // Ignore reason: false positive of the lint rule. 807 // eslint-disable-next-line @wordpress/no-unused-vars-before-return 808 const { 809 setEditingPattern 810 } = unlock((0,external_wp_data_namespaceObject.useDispatch)(store)); 811 const [isModalOpen, setIsModalOpen] = (0,external_wp_element_namespaceObject.useState)(false); 812 const canConvert = (0,external_wp_data_namespaceObject.useSelect)(select => { 813 var _getBlocksByClientId; 814 const { 815 canUser 816 } = select(external_wp_coreData_namespaceObject.store); 817 const { 818 getBlocksByClientId, 819 canInsertBlockType, 820 getBlockRootClientId 821 } = select(external_wp_blockEditor_namespaceObject.store); 822 const rootId = rootClientId || (clientIds.length > 0 ? getBlockRootClientId(clientIds[0]) : undefined); 823 const blocks = (_getBlocksByClientId = getBlocksByClientId(clientIds)) !== null && _getBlocksByClientId !== void 0 ? _getBlocksByClientId : []; 824 const isReusable = blocks.length === 1 && blocks[0] && (0,external_wp_blocks_namespaceObject.isReusableBlock)(blocks[0]) && !!select(external_wp_coreData_namespaceObject.store).getEntityRecord('postType', 'wp_block', blocks[0].attributes.ref); 825 const _canConvert = 826 // Hide when this is already a synced pattern. 827 !isReusable && 828 // Hide when patterns are disabled. 829 canInsertBlockType('core/block', rootId) && blocks.every(block => 830 // Guard against the case where a regular block has *just* been converted. 831 !!block && 832 // Hide on invalid blocks. 833 block.isValid && 834 // Hide when block doesn't support being made into a pattern. 835 (0,external_wp_blocks_namespaceObject.hasBlockSupport)(block.name, 'reusable', true)) && 836 // Hide when current doesn't have permission to do that. 837 !!canUser('create', 'blocks'); 838 return _canConvert; 839 }, [clientIds, rootClientId]); 840 const { 841 getBlocksByClientId 842 } = (0,external_wp_data_namespaceObject.useSelect)(external_wp_blockEditor_namespaceObject.store); 843 const getContent = (0,external_wp_element_namespaceObject.useCallback)(() => (0,external_wp_blocks_namespaceObject.serialize)(getBlocksByClientId(clientIds)), [getBlocksByClientId, clientIds]); 844 if (!canConvert) { 845 return null; 846 } 847 const handleSuccess = ({ 848 pattern 849 }) => { 850 if (pattern.wp_pattern_sync_status !== PATTERN_SYNC_TYPES.unsynced) { 851 const newBlock = (0,external_wp_blocks_namespaceObject.createBlock)('core/block', { 852 ref: pattern.id 853 }); 854 replaceBlocks(clientIds, newBlock); 855 setEditingPattern(newBlock.clientId, true); 856 closeBlockSettingsMenu(); 857 } 858 createSuccessNotice(pattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced ? (0,external_wp_i18n_namespaceObject.sprintf)( 859 // translators: %s: the name the user has given to the pattern. 860 (0,external_wp_i18n_namespaceObject.__)('Unsynced pattern created: %s'), pattern.title.raw) : (0,external_wp_i18n_namespaceObject.sprintf)( 861 // translators: %s: the name the user has given to the pattern. 862 (0,external_wp_i18n_namespaceObject.__)('Synced pattern created: %s'), pattern.title.raw), { 863 type: 'snackbar', 864 id: 'convert-to-pattern-success' 865 }); 866 setIsModalOpen(false); 867 }; 868 return (0,external_React_namespaceObject.createElement)(external_React_namespaceObject.Fragment, null, (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, { 869 icon: library_symbol, 870 onClick: () => setIsModalOpen(true), 871 "aria-expanded": isModalOpen, 872 "aria-haspopup": "dialog" 873 }, (0,external_wp_i18n_namespaceObject.__)('Create pattern')), isModalOpen && (0,external_React_namespaceObject.createElement)(CreatePatternModal, { 874 content: getContent, 875 onSuccess: pattern => { 876 handleSuccess(pattern); 877 }, 878 onError: () => { 879 setIsModalOpen(false); 880 }, 881 onClose: () => { 882 setIsModalOpen(false); 883 } 884 })); 885 } 886 887 ;// CONCATENATED MODULE: external ["wp","url"] 888 const external_wp_url_namespaceObject = window["wp"]["url"]; 889 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/components/patterns-manage-button.js 890 891 /** 892 * WordPress dependencies 893 */ 894 895 896 897 898 899 900 901 902 /** 903 * Internal dependencies 904 */ 905 906 907 function PatternsManageButton({ 908 clientId 909 }) { 910 const { 911 canRemove, 912 isVisible, 913 managePatternsUrl 914 } = (0,external_wp_data_namespaceObject.useSelect)(select => { 915 const { 916 getBlock, 917 canRemoveBlock, 918 getBlockCount, 919 getSettings 920 } = select(external_wp_blockEditor_namespaceObject.store); 921 const { 922 canUser 923 } = select(external_wp_coreData_namespaceObject.store); 924 const reusableBlock = getBlock(clientId); 925 const isBlockTheme = getSettings().__unstableIsBlockBasedTheme; 926 return { 927 canRemove: canRemoveBlock(clientId), 928 isVisible: !!reusableBlock && (0,external_wp_blocks_namespaceObject.isReusableBlock)(reusableBlock) && !!canUser('update', 'blocks', reusableBlock.attributes.ref), 929 innerBlockCount: getBlockCount(clientId), 930 // The site editor and templates both check whether the user 931 // has edit_theme_options capabilities. We can leverage that here 932 // and omit the manage patterns link if the user can't access it. 933 managePatternsUrl: isBlockTheme && canUser('read', 'templates') ? (0,external_wp_url_namespaceObject.addQueryArgs)('site-editor.php', { 934 path: '/patterns' 935 }) : (0,external_wp_url_namespaceObject.addQueryArgs)('edit.php', { 936 post_type: 'wp_block' 937 }) 938 }; 939 }, [clientId]); 940 941 // Ignore reason: false positive of the lint rule. 942 // eslint-disable-next-line @wordpress/no-unused-vars-before-return 943 const { 944 convertSyncedPatternToStatic 945 } = unlock((0,external_wp_data_namespaceObject.useDispatch)(store)); 946 if (!isVisible) { 947 return null; 948 } 949 return (0,external_React_namespaceObject.createElement)(external_React_namespaceObject.Fragment, null, canRemove && (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, { 950 onClick: () => convertSyncedPatternToStatic(clientId) 951 }, (0,external_wp_i18n_namespaceObject.__)('Detach')), (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, { 952 href: managePatternsUrl 953 }, (0,external_wp_i18n_namespaceObject.__)('Manage patterns'))); 954 } 955 /* harmony default export */ const patterns_manage_button = (PatternsManageButton); 956 957 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/components/index.js 958 959 /** 960 * WordPress dependencies 961 */ 962 963 964 /** 965 * Internal dependencies 966 */ 967 968 969 function PatternsMenuItems({ 970 rootClientId 971 }) { 972 return (0,external_React_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.BlockSettingsMenuControls, null, ({ 973 selectedClientIds, 974 onClose 975 }) => (0,external_React_namespaceObject.createElement)(external_React_namespaceObject.Fragment, null, (0,external_React_namespaceObject.createElement)(PatternConvertButton, { 976 clientIds: selectedClientIds, 977 rootClientId: rootClientId, 978 closeBlockSettingsMenu: onClose 979 }), selectedClientIds.length === 1 && (0,external_React_namespaceObject.createElement)(patterns_manage_button, { 980 clientId: selectedClientIds[0] 981 }))); 982 } 983 984 ;// CONCATENATED MODULE: external ["wp","a11y"] 985 const external_wp_a11y_namespaceObject = window["wp"]["a11y"]; 986 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/components/rename-pattern-category-modal.js 987 988 /** 989 * WordPress dependencies 990 */ 991 992 993 994 995 996 997 998 999 1000 /** 1001 * Internal dependencies 1002 */ 1003 1004 function RenamePatternCategoryModal({ 1005 category, 1006 existingCategories, 1007 onClose, 1008 onError, 1009 onSuccess, 1010 ...props 1011 }) { 1012 const id = (0,external_wp_element_namespaceObject.useId)(); 1013 const textControlRef = (0,external_wp_element_namespaceObject.useRef)(); 1014 const [name, setName] = (0,external_wp_element_namespaceObject.useState)((0,external_wp_htmlEntities_namespaceObject.decodeEntities)(category.name)); 1015 const [isSaving, setIsSaving] = (0,external_wp_element_namespaceObject.useState)(false); 1016 const [validationMessage, setValidationMessage] = (0,external_wp_element_namespaceObject.useState)(false); 1017 const validationMessageId = validationMessage ? `patterns-rename-pattern-category-modal__validation-message-$id}` : undefined; 1018 const { 1019 saveEntityRecord, 1020 invalidateResolution 1021 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_coreData_namespaceObject.store); 1022 const { 1023 createErrorNotice, 1024 createSuccessNotice 1025 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store); 1026 const onChange = newName => { 1027 if (validationMessage) { 1028 setValidationMessage(undefined); 1029 } 1030 setName(newName); 1031 }; 1032 const onSave = async event => { 1033 event.preventDefault(); 1034 if (isSaving) { 1035 return; 1036 } 1037 if (!name || name === category.name) { 1038 const message = (0,external_wp_i18n_namespaceObject.__)('Please enter a new name for this category.'); 1039 (0,external_wp_a11y_namespaceObject.speak)(message, 'assertive'); 1040 setValidationMessage(message); 1041 textControlRef.current?.focus(); 1042 return; 1043 } 1044 1045 // Check existing categories to avoid creating duplicates. 1046 if (existingCategories.patternCategories.find(existingCategory => { 1047 // Compare the id so that the we don't disallow the user changing the case of their current category 1048 // (i.e. renaming 'test' to 'Test'). 1049 return existingCategory.id !== category.id && existingCategory.label.toLowerCase() === name.toLowerCase(); 1050 })) { 1051 const message = (0,external_wp_i18n_namespaceObject.__)('This category already exists. Please use a different name.'); 1052 (0,external_wp_a11y_namespaceObject.speak)(message, 'assertive'); 1053 setValidationMessage(message); 1054 textControlRef.current?.focus(); 1055 return; 1056 } 1057 try { 1058 setIsSaving(true); 1059 1060 // User pattern category properties may differ as they can be 1061 // normalized for use alongside template part areas, core pattern 1062 // categories etc. As a result we won't just destructure the passed 1063 // category object. 1064 const savedRecord = await saveEntityRecord('taxonomy', CATEGORY_SLUG, { 1065 id: category.id, 1066 slug: category.slug, 1067 name 1068 }); 1069 invalidateResolution('getUserPatternCategories'); 1070 onSuccess?.(savedRecord); 1071 onClose(); 1072 createSuccessNotice((0,external_wp_i18n_namespaceObject.__)('Pattern category renamed.'), { 1073 type: 'snackbar', 1074 id: 'pattern-category-update' 1075 }); 1076 } catch (error) { 1077 onError?.(); 1078 createErrorNotice(error.message, { 1079 type: 'snackbar', 1080 id: 'pattern-category-update' 1081 }); 1082 } finally { 1083 setIsSaving(false); 1084 setName(''); 1085 } 1086 }; 1087 const onRequestClose = () => { 1088 onClose(); 1089 setName(''); 1090 }; 1091 return (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.Modal, { 1092 title: (0,external_wp_i18n_namespaceObject.__)('Rename'), 1093 onRequestClose: onRequestClose, 1094 ...props 1095 }, (0,external_React_namespaceObject.createElement)("form", { 1096 onSubmit: onSave 1097 }, (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.__experimentalVStack, { 1098 spacing: "5" 1099 }, (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.__experimentalVStack, { 1100 spacing: "2" 1101 }, (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.TextControl, { 1102 ref: textControlRef, 1103 __nextHasNoMarginBottom: true, 1104 __next40pxDefaultSize: true, 1105 label: (0,external_wp_i18n_namespaceObject.__)('Name'), 1106 value: name, 1107 onChange: onChange, 1108 "aria-describedby": validationMessageId, 1109 required: true 1110 }), validationMessage && (0,external_React_namespaceObject.createElement)("span", { 1111 className: "patterns-rename-pattern-category-modal__validation-message", 1112 id: validationMessageId 1113 }, validationMessage)), (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.__experimentalHStack, { 1114 justify: "right" 1115 }, (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, { 1116 __next40pxDefaultSize: true, 1117 variant: "tertiary", 1118 onClick: onRequestClose 1119 }, (0,external_wp_i18n_namespaceObject.__)('Cancel')), (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, { 1120 __next40pxDefaultSize: true, 1121 variant: "primary", 1122 type: "submit", 1123 "aria-disabled": !name || name === category.name || isSaving, 1124 isBusy: isSaving 1125 }, (0,external_wp_i18n_namespaceObject.__)('Save')))))); 1126 } 1127 1128 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/components/use-set-pattern-bindings.js 1129 /** 1130 * WordPress dependencies 1131 */ 1132 1133 1134 1135 1136 1137 /** 1138 * Internal dependencies 1139 */ 1140 1141 1142 function removeBindings(bindings, syncedAttributes) { 1143 let updatedBindings = {}; 1144 for (const attributeName of syncedAttributes) { 1145 // Omit any pattern override bindings from the `updatedBindings` object. 1146 if (bindings?.[attributeName]?.source !== 'core/pattern-overrides' && bindings?.[attributeName]?.source !== undefined) { 1147 updatedBindings[attributeName] = bindings[attributeName]; 1148 } 1149 } 1150 if (!Object.keys(updatedBindings).length) { 1151 updatedBindings = undefined; 1152 } 1153 return updatedBindings; 1154 } 1155 function addBindings(bindings, syncedAttributes) { 1156 const updatedBindings = { 1157 ...bindings 1158 }; 1159 for (const attributeName of syncedAttributes) { 1160 if (!bindings?.[attributeName]) { 1161 updatedBindings[attributeName] = { 1162 source: 'core/pattern-overrides' 1163 }; 1164 } 1165 } 1166 return updatedBindings; 1167 } 1168 function useSetPatternBindings({ 1169 name, 1170 attributes, 1171 setAttributes 1172 }, currentPostType) { 1173 var _attributes$metadata$, _usePrevious; 1174 const hasPatternOverridesSource = (0,external_wp_data_namespaceObject.useSelect)(select => { 1175 const { 1176 getBlockBindingsSource 1177 } = unlock(select(external_wp_blocks_namespaceObject.store)); 1178 1179 // For editing link to the site editor if the theme and user permissions support it. 1180 return !!getBlockBindingsSource('core/pattern-overrides'); 1181 }, []); 1182 const metadataName = (_attributes$metadata$ = attributes?.metadata?.name) !== null && _attributes$metadata$ !== void 0 ? _attributes$metadata$ : ''; 1183 const prevMetadataName = (_usePrevious = (0,external_wp_compose_namespaceObject.usePrevious)(metadataName)) !== null && _usePrevious !== void 0 ? _usePrevious : ''; 1184 const bindings = attributes?.metadata?.bindings; 1185 (0,external_wp_element_namespaceObject.useEffect)(() => { 1186 // Bindings should only be created when editing a wp_block post type, 1187 // and also when there's a change to the user-given name for the block. 1188 // Also check that the pattern overrides source is registered. 1189 if (!hasPatternOverridesSource || currentPostType !== 'wp_block' || metadataName === prevMetadataName) { 1190 return; 1191 } 1192 const syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[name]; 1193 const attributeSources = syncedAttributes.map(attributeName => attributes.metadata?.bindings?.[attributeName]?.source); 1194 const isConnectedToOtherSources = attributeSources.every(source => source && source !== 'core/pattern-overrides'); 1195 1196 // Avoid overwriting other (e.g. meta) bindings. 1197 if (isConnectedToOtherSources) { 1198 return; 1199 } 1200 1201 // The user-given name for the block was deleted, remove the bindings. 1202 if (!metadataName?.length && prevMetadataName?.length) { 1203 const updatedBindings = removeBindings(bindings, syncedAttributes); 1204 setAttributes({ 1205 metadata: { 1206 ...attributes.metadata, 1207 bindings: updatedBindings 1208 } 1209 }); 1210 } 1211 1212 // The user-given name for the block was set, set the bindings. 1213 if (!prevMetadataName?.length && metadataName.length) { 1214 const updatedBindings = addBindings(bindings, syncedAttributes); 1215 setAttributes({ 1216 metadata: { 1217 ...attributes.metadata, 1218 bindings: updatedBindings 1219 } 1220 }); 1221 } 1222 }, [hasPatternOverridesSource, bindings, prevMetadataName, metadataName, currentPostType, name, attributes.metadata, setAttributes]); 1223 } 1224 1225 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/components/reset-overrides-control.js 1226 1227 /** 1228 * WordPress dependencies 1229 */ 1230 1231 1232 1233 1234 1235 1236 function recursivelyFindBlockWithName(blocks, name) { 1237 for (const block of blocks) { 1238 if (block.attributes.metadata?.name === name) { 1239 return block; 1240 } 1241 const found = recursivelyFindBlockWithName(block.innerBlocks, name); 1242 if (found) { 1243 return found; 1244 } 1245 } 1246 } 1247 function ResetOverridesControl(props) { 1248 const registry = (0,external_wp_data_namespaceObject.useRegistry)(); 1249 const name = props.attributes.metadata?.name; 1250 const patternWithOverrides = (0,external_wp_data_namespaceObject.useSelect)(select => { 1251 if (!name) { 1252 return undefined; 1253 } 1254 const { 1255 getBlockParentsByBlockName, 1256 getBlocksByClientId 1257 } = select(external_wp_blockEditor_namespaceObject.store); 1258 const patternBlock = getBlocksByClientId(getBlockParentsByBlockName(props.clientId, 'core/block'))[0]; 1259 if (!patternBlock?.attributes.content?.[name]) { 1260 return undefined; 1261 } 1262 return patternBlock; 1263 }, [props.clientId, name]); 1264 const resetOverrides = async () => { 1265 var _editedRecord$blocks; 1266 const editedRecord = await registry.resolveSelect(external_wp_coreData_namespaceObject.store).getEditedEntityRecord('postType', 'wp_block', patternWithOverrides.attributes.ref); 1267 const blocks = (_editedRecord$blocks = editedRecord.blocks) !== null && _editedRecord$blocks !== void 0 ? _editedRecord$blocks : (0,external_wp_blocks_namespaceObject.parse)(editedRecord.content); 1268 const block = recursivelyFindBlockWithName(blocks, name); 1269 const newAttributes = Object.assign( 1270 // Reset every existing attribute to undefined. 1271 Object.fromEntries(Object.keys(props.attributes).map(key => [key, undefined])), 1272 // Then assign the original attributes. 1273 block.attributes); 1274 props.setAttributes(newAttributes); 1275 }; 1276 return (0,external_React_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.BlockControls, { 1277 group: "other" 1278 }, (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.ToolbarGroup, null, (0,external_React_namespaceObject.createElement)(external_wp_components_namespaceObject.ToolbarButton, { 1279 onClick: resetOverrides, 1280 disabled: !patternWithOverrides, 1281 __experimentalIsFocusable: true 1282 }, (0,external_wp_i18n_namespaceObject.__)('Reset')))); 1283 } 1284 1285 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/private-apis.js 1286 /** 1287 * Internal dependencies 1288 */ 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 const privateApis = {}; 1300 lock(privateApis, { 1301 CreatePatternModal: CreatePatternModal, 1302 CreatePatternModalContents: CreatePatternModalContents, 1303 DuplicatePatternModal: DuplicatePatternModal, 1304 useDuplicatePatternProps: useDuplicatePatternProps, 1305 RenamePatternModal: RenamePatternModal, 1306 PatternsMenuItems: PatternsMenuItems, 1307 RenamePatternCategoryModal: RenamePatternCategoryModal, 1308 useSetPatternBindings: useSetPatternBindings, 1309 ResetOverridesControl: ResetOverridesControl, 1310 useAddPatternCategory: useAddPatternCategory, 1311 PATTERN_TYPES: PATTERN_TYPES, 1312 PATTERN_DEFAULT_CATEGORY: PATTERN_DEFAULT_CATEGORY, 1313 PATTERN_USER_CATEGORY: PATTERN_USER_CATEGORY, 1314 EXCLUDED_PATTERN_SOURCES: EXCLUDED_PATTERN_SOURCES, 1315 PATTERN_SYNC_TYPES: PATTERN_SYNC_TYPES, 1316 PARTIAL_SYNCING_SUPPORTED_BLOCKS: PARTIAL_SYNCING_SUPPORTED_BLOCKS 1317 }); 1318 1319 ;// CONCATENATED MODULE: ./node_modules/@wordpress/patterns/build-module/index.js 1320 /** 1321 * Internal dependencies 1322 */ 1323 1324 1325 1326 (window.wp = window.wp || {}).patterns = __webpack_exports__; 1327 /******/ })() 1328 ;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sat May 11 08:20:01 2024 | Cross-referenced by PHPXref |