@wordpress/patterns 1.19.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/api/index.js +17 -0
  3. package/build/api/index.js.map +1 -1
  4. package/build/components/allow-overrides-modal.js +72 -58
  5. package/build/components/allow-overrides-modal.js.map +1 -1
  6. package/build/components/category-selector.js +2 -2
  7. package/build/components/category-selector.js.map +1 -1
  8. package/build/components/create-pattern-modal.js +56 -48
  9. package/build/components/create-pattern-modal.js.map +1 -1
  10. package/build/components/duplicate-pattern-modal.js +2 -2
  11. package/build/components/duplicate-pattern-modal.js.map +1 -1
  12. package/build/components/index.js +15 -11
  13. package/build/components/index.js.map +1 -1
  14. package/build/components/overrides-panel.js +7 -6
  15. package/build/components/overrides-panel.js.map +1 -1
  16. package/build/components/pattern-convert-button.js +22 -20
  17. package/build/components/pattern-convert-button.js.map +1 -1
  18. package/build/components/pattern-overrides-controls.js +49 -54
  19. package/build/components/pattern-overrides-controls.js.map +1 -1
  20. package/build/components/patterns-manage-button.js +10 -6
  21. package/build/components/patterns-manage-button.js.map +1 -1
  22. package/build/components/rename-pattern-category-modal.js +42 -34
  23. package/build/components/rename-pattern-category-modal.js.map +1 -1
  24. package/build/components/rename-pattern-modal.js +31 -25
  25. package/build/components/rename-pattern-modal.js.map +1 -1
  26. package/build/components/reset-overrides-control.js +12 -8
  27. package/build/components/reset-overrides-control.js.map +1 -1
  28. package/build/private-apis.js +1 -0
  29. package/build/private-apis.js.map +1 -1
  30. package/build/store/actions.js +2 -2
  31. package/build/store/actions.js.map +1 -1
  32. package/build-module/api/index.js +16 -0
  33. package/build-module/api/index.js.map +1 -1
  34. package/build-module/components/allow-overrides-modal.js +73 -58
  35. package/build-module/components/allow-overrides-modal.js.map +1 -1
  36. package/build-module/components/category-selector.js +2 -2
  37. package/build-module/components/category-selector.js.map +1 -1
  38. package/build-module/components/create-pattern-modal.js +59 -50
  39. package/build-module/components/create-pattern-modal.js.map +1 -1
  40. package/build-module/components/duplicate-pattern-modal.js +2 -2
  41. package/build-module/components/duplicate-pattern-modal.js.map +1 -1
  42. package/build-module/components/index.js +17 -11
  43. package/build-module/components/index.js.map +1 -1
  44. package/build-module/components/overrides-panel.js +7 -6
  45. package/build-module/components/overrides-panel.js.map +1 -1
  46. package/build-module/components/pattern-convert-button.js +23 -18
  47. package/build-module/components/pattern-convert-button.js.map +1 -1
  48. package/build-module/components/pattern-overrides-controls.js +52 -55
  49. package/build-module/components/pattern-overrides-controls.js.map +1 -1
  50. package/build-module/components/patterns-manage-button.js +12 -6
  51. package/build-module/components/patterns-manage-button.js.map +1 -1
  52. package/build-module/components/rename-pattern-category-modal.js +43 -34
  53. package/build-module/components/rename-pattern-category-modal.js.map +1 -1
  54. package/build-module/components/rename-pattern-modal.js +32 -25
  55. package/build-module/components/rename-pattern-modal.js.map +1 -1
  56. package/build-module/components/reset-overrides-control.js +12 -8
  57. package/build-module/components/reset-overrides-control.js.map +1 -1
  58. package/build-module/private-apis.js +2 -1
  59. package/build-module/private-apis.js.map +1 -1
  60. package/build-module/store/actions.js +2 -2
  61. package/build-module/store/actions.js.map +1 -1
  62. package/package.json +18 -17
  63. package/src/api/index.js +16 -0
  64. package/src/components/create-pattern-modal.js +17 -9
  65. package/src/components/pattern-overrides-controls.js +19 -44
  66. package/src/private-apis.js +2 -1
  67. package/src/store/actions.js +2 -2
@@ -1 +1 @@
1
- {"version":3,"names":["lock","OverridesPanel","default","CreatePatternModal","CreatePatternModalContents","DuplicatePatternModal","useDuplicatePatternProps","isOverridableBlock","RenamePatternModal","PatternsMenuItems","RenamePatternCategoryModal","PatternOverridesControls","ResetOverridesControl","useAddPatternCategory","PATTERN_TYPES","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","EXCLUDED_PATTERN_SOURCES","PATTERN_SYNC_TYPES","PARTIAL_SYNCING_SUPPORTED_BLOCKS","privateApis"],"sources":["@wordpress/patterns/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { lock } from './lock-unlock';\nimport OverridesPanel from './components/overrides-panel';\nimport {\n\tdefault as CreatePatternModal,\n\tCreatePatternModalContents,\n} from './components/create-pattern-modal';\nimport {\n\tdefault as DuplicatePatternModal,\n\tuseDuplicatePatternProps,\n} from './components/duplicate-pattern-modal';\nimport { isOverridableBlock } from './api';\nimport RenamePatternModal from './components/rename-pattern-modal';\nimport PatternsMenuItems from './components';\nimport RenamePatternCategoryModal from './components/rename-pattern-category-modal';\nimport PatternOverridesControls from './components/pattern-overrides-controls';\nimport ResetOverridesControl from './components/reset-overrides-control';\nimport { useAddPatternCategory } from './private-hooks';\nimport {\n\tPATTERN_TYPES,\n\tPATTERN_DEFAULT_CATEGORY,\n\tPATTERN_USER_CATEGORY,\n\tEXCLUDED_PATTERN_SOURCES,\n\tPATTERN_SYNC_TYPES,\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n} from './constants';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tOverridesPanel,\n\tCreatePatternModal,\n\tCreatePatternModalContents,\n\tDuplicatePatternModal,\n\tisOverridableBlock,\n\tuseDuplicatePatternProps,\n\tRenamePatternModal,\n\tPatternsMenuItems,\n\tRenamePatternCategoryModal,\n\tPatternOverridesControls,\n\tResetOverridesControl,\n\tuseAddPatternCategory,\n\tPATTERN_TYPES,\n\tPATTERN_DEFAULT_CATEGORY,\n\tPATTERN_USER_CATEGORY,\n\tEXCLUDED_PATTERN_SOURCES,\n\tPATTERN_SYNC_TYPES,\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAI,QAAQ,eAAe;AACpC,OAAOC,cAAc,MAAM,8BAA8B;AACzD,SACCC,OAAO,IAAIC,kBAAkB,EAC7BC,0BAA0B,QACpB,mCAAmC;AAC1C,SACCF,OAAO,IAAIG,qBAAqB,EAChCC,wBAAwB,QAClB,sCAAsC;AAC7C,SAASC,kBAAkB,QAAQ,OAAO;AAC1C,OAAOC,kBAAkB,MAAM,mCAAmC;AAClE,OAAOC,iBAAiB,MAAM,cAAc;AAC5C,OAAOC,0BAA0B,MAAM,4CAA4C;AACnF,OAAOC,wBAAwB,MAAM,yCAAyC;AAC9E,OAAOC,qBAAqB,MAAM,sCAAsC;AACxE,SAASC,qBAAqB,QAAQ,iBAAiB;AACvD,SACCC,aAAa,EACbC,wBAAwB,EACxBC,qBAAqB,EACrBC,wBAAwB,EACxBC,kBAAkB,EAClBC,gCAAgC,QAC1B,aAAa;AAEpB,OAAO,MAAMC,WAAW,GAAG,CAAC,CAAC;AAC7BpB,IAAI,CAAEoB,WAAW,EAAE;EAClBnB,cAAc;EACdE,kBAAkB;EAClBC,0BAA0B;EAC1BC,qBAAqB;EACrBE,kBAAkB;EAClBD,wBAAwB;EACxBE,kBAAkB;EAClBC,iBAAiB;EACjBC,0BAA0B;EAC1BC,wBAAwB;EACxBC,qBAAqB;EACrBC,qBAAqB;EACrBC,aAAa;EACbC,wBAAwB;EACxBC,qBAAqB;EACrBC,wBAAwB;EACxBC,kBAAkB;EAClBC;AACD,CAAE,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["lock","OverridesPanel","default","CreatePatternModal","CreatePatternModalContents","DuplicatePatternModal","useDuplicatePatternProps","isOverridableBlock","hasOverridableBlocks","RenamePatternModal","PatternsMenuItems","RenamePatternCategoryModal","PatternOverridesControls","ResetOverridesControl","useAddPatternCategory","PATTERN_TYPES","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","EXCLUDED_PATTERN_SOURCES","PATTERN_SYNC_TYPES","PARTIAL_SYNCING_SUPPORTED_BLOCKS","privateApis"],"sources":["@wordpress/patterns/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { lock } from './lock-unlock';\nimport OverridesPanel from './components/overrides-panel';\nimport {\n\tdefault as CreatePatternModal,\n\tCreatePatternModalContents,\n} from './components/create-pattern-modal';\nimport {\n\tdefault as DuplicatePatternModal,\n\tuseDuplicatePatternProps,\n} from './components/duplicate-pattern-modal';\nimport { isOverridableBlock, hasOverridableBlocks } from './api';\nimport RenamePatternModal from './components/rename-pattern-modal';\nimport PatternsMenuItems from './components';\nimport RenamePatternCategoryModal from './components/rename-pattern-category-modal';\nimport PatternOverridesControls from './components/pattern-overrides-controls';\nimport ResetOverridesControl from './components/reset-overrides-control';\nimport { useAddPatternCategory } from './private-hooks';\nimport {\n\tPATTERN_TYPES,\n\tPATTERN_DEFAULT_CATEGORY,\n\tPATTERN_USER_CATEGORY,\n\tEXCLUDED_PATTERN_SOURCES,\n\tPATTERN_SYNC_TYPES,\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n} from './constants';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tOverridesPanel,\n\tCreatePatternModal,\n\tCreatePatternModalContents,\n\tDuplicatePatternModal,\n\tisOverridableBlock,\n\thasOverridableBlocks,\n\tuseDuplicatePatternProps,\n\tRenamePatternModal,\n\tPatternsMenuItems,\n\tRenamePatternCategoryModal,\n\tPatternOverridesControls,\n\tResetOverridesControl,\n\tuseAddPatternCategory,\n\tPATTERN_TYPES,\n\tPATTERN_DEFAULT_CATEGORY,\n\tPATTERN_USER_CATEGORY,\n\tEXCLUDED_PATTERN_SOURCES,\n\tPATTERN_SYNC_TYPES,\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAI,QAAQ,eAAe;AACpC,OAAOC,cAAc,MAAM,8BAA8B;AACzD,SACCC,OAAO,IAAIC,kBAAkB,EAC7BC,0BAA0B,QACpB,mCAAmC;AAC1C,SACCF,OAAO,IAAIG,qBAAqB,EAChCC,wBAAwB,QAClB,sCAAsC;AAC7C,SAASC,kBAAkB,EAAEC,oBAAoB,QAAQ,OAAO;AAChE,OAAOC,kBAAkB,MAAM,mCAAmC;AAClE,OAAOC,iBAAiB,MAAM,cAAc;AAC5C,OAAOC,0BAA0B,MAAM,4CAA4C;AACnF,OAAOC,wBAAwB,MAAM,yCAAyC;AAC9E,OAAOC,qBAAqB,MAAM,sCAAsC;AACxE,SAASC,qBAAqB,QAAQ,iBAAiB;AACvD,SACCC,aAAa,EACbC,wBAAwB,EACxBC,qBAAqB,EACrBC,wBAAwB,EACxBC,kBAAkB,EAClBC,gCAAgC,QAC1B,aAAa;AAEpB,OAAO,MAAMC,WAAW,GAAG,CAAC,CAAC;AAC7BrB,IAAI,CAAEqB,WAAW,EAAE;EAClBpB,cAAc;EACdE,kBAAkB;EAClBC,0BAA0B;EAC1BC,qBAAqB;EACrBE,kBAAkB;EAClBC,oBAAoB;EACpBF,wBAAwB;EACxBG,kBAAkB;EAClBC,iBAAiB;EACjBC,0BAA0B;EAC1BC,wBAAwB;EACxBC,qBAAqB;EACrBC,qBAAqB;EACrBC,aAAa;EACbC,wBAAwB;EACxBC,qBAAqB;EACrBC,wBAAwB;EACxBC,kBAAkB;EAClBC;AACD,CAAE,CAAC","ignoreList":[]}
@@ -78,8 +78,8 @@ export const convertSyncedPatternToStatic = clientId => ({
78
78
  };
79
79
  delete metadata.id;
80
80
  delete metadata.bindings;
81
- // Use overriden values of the pattern block if they exist.
82
- if (existingOverrides[metadata.name]) {
81
+ // Use overridden values of the pattern block if they exist.
82
+ if (existingOverrides?.[metadata.name]) {
83
83
  // Iterate over each overriden attribute.
84
84
  for (const [attributeName, value] of Object.entries(existingOverrides[metadata.name])) {
85
85
  // Skip if the attribute does not exist in the block type.
@@ -1 +1 @@
1
- {"version":3,"names":["getBlockType","cloneBlock","store","coreStore","blockEditorStore","PATTERN_SYNC_TYPES","createPattern","title","syncType","content","categories","registry","meta","unsynced","wp_pattern_sync_status","undefined","reusableBlock","status","wp_pattern_category","updatedRecord","dispatch","saveEntityRecord","createPatternFromFile","file","fileContent","text","parsedContent","JSON","parse","e","Error","__file","syncStatus","pattern","convertSyncedPatternToStatic","clientId","patternBlock","select","getBlock","existingOverrides","attributes","cloneBlocksAndRemoveBindings","blocks","map","block","metadata","id","bindings","name","attributeName","value","Object","entries","keys","length","innerBlocks","patternInnerBlocks","getBlocks","replaceBlocks","setEditingPattern","isEditing","type"],"sources":["@wordpress/patterns/src/store/actions.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\n\nimport { getBlockType, cloneBlock } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Returns a generator converting one or more static blocks into a pattern, or creating a new empty pattern.\n *\n * @param {string} title Pattern title.\n * @param {'full'|'unsynced'} syncType They way block is synced, 'full' or 'unsynced'.\n * @param {string|undefined} [content] Optional serialized content of blocks to convert to pattern.\n * @param {number[]|undefined} [categories] Ids of any selected categories.\n */\nexport const createPattern =\n\t( title, syncType, content, categories ) =>\n\tasync ( { registry } ) => {\n\t\tconst meta =\n\t\t\tsyncType === PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t? {\n\t\t\t\t\t\twp_pattern_sync_status: syncType,\n\t\t\t\t }\n\t\t\t\t: undefined;\n\n\t\tconst reusableBlock = {\n\t\t\ttitle,\n\t\t\tcontent,\n\t\t\tstatus: 'publish',\n\t\t\tmeta,\n\t\t\twp_pattern_category: categories,\n\t\t};\n\n\t\tconst updatedRecord = await registry\n\t\t\t.dispatch( coreStore )\n\t\t\t.saveEntityRecord( 'postType', 'wp_block', reusableBlock );\n\n\t\treturn updatedRecord;\n\t};\n\n/**\n * Create a pattern from a JSON file.\n * @param {File} file The JSON file instance of the pattern.\n * @param {number[]|undefined} [categories] Ids of any selected categories.\n */\nexport const createPatternFromFile =\n\t( file, categories ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst fileContent = await file.text();\n\t\t/** @type {import('./types').PatternJSON} */\n\t\tlet parsedContent;\n\t\ttry {\n\t\t\tparsedContent = JSON.parse( fileContent );\n\t\t} catch ( e ) {\n\t\t\tthrow new Error( 'Invalid JSON file' );\n\t\t}\n\t\tif (\n\t\t\tparsedContent.__file !== 'wp_block' ||\n\t\t\t! parsedContent.title ||\n\t\t\t! parsedContent.content ||\n\t\t\ttypeof parsedContent.title !== 'string' ||\n\t\t\ttypeof parsedContent.content !== 'string' ||\n\t\t\t( parsedContent.syncStatus &&\n\t\t\t\ttypeof parsedContent.syncStatus !== 'string' )\n\t\t) {\n\t\t\tthrow new Error( 'Invalid pattern JSON file' );\n\t\t}\n\n\t\tconst pattern = await dispatch.createPattern(\n\t\t\tparsedContent.title,\n\t\t\tparsedContent.syncStatus,\n\t\t\tparsedContent.content,\n\t\t\tcategories\n\t\t);\n\n\t\treturn pattern;\n\t};\n\n/**\n * Returns a generator converting a synced pattern block into a static block.\n *\n * @param {string} clientId The client ID of the block to attach.\n */\nexport const convertSyncedPatternToStatic =\n\t( clientId ) =>\n\t( { registry } ) => {\n\t\tconst patternBlock = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlock( clientId );\n\t\tconst existingOverrides = patternBlock.attributes?.content;\n\n\t\tfunction cloneBlocksAndRemoveBindings( blocks ) {\n\t\t\treturn blocks.map( ( block ) => {\n\t\t\t\tlet metadata = block.attributes.metadata;\n\t\t\t\tif ( metadata ) {\n\t\t\t\t\tmetadata = { ...metadata };\n\t\t\t\t\tdelete metadata.id;\n\t\t\t\t\tdelete metadata.bindings;\n\t\t\t\t\t// Use overriden values of the pattern block if they exist.\n\t\t\t\t\tif ( existingOverrides[ metadata.name ] ) {\n\t\t\t\t\t\t// Iterate over each overriden attribute.\n\t\t\t\t\t\tfor ( const [ attributeName, value ] of Object.entries(\n\t\t\t\t\t\t\texistingOverrides[ metadata.name ]\n\t\t\t\t\t\t) ) {\n\t\t\t\t\t\t\t// Skip if the attribute does not exist in the block type.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t! getBlockType( block.name )?.attributes[\n\t\t\t\t\t\t\t\t\tattributeName\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Update the block attribute with the override value.\n\t\t\t\t\t\t\tblock.attributes[ attributeName ] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn cloneBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\t{\n\t\t\t\t\t\tmetadata:\n\t\t\t\t\t\t\tmetadata && Object.keys( metadata ).length > 0\n\t\t\t\t\t\t\t\t? metadata\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t},\n\t\t\t\t\tcloneBlocksAndRemoveBindings( block.innerBlocks )\n\t\t\t\t);\n\t\t\t} );\n\t\t}\n\n\t\tconst patternInnerBlocks = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlocks( patternBlock.clientId );\n\n\t\tregistry\n\t\t\t.dispatch( blockEditorStore )\n\t\t\t.replaceBlocks(\n\t\t\t\tpatternBlock.clientId,\n\t\t\t\tcloneBlocksAndRemoveBindings( patternInnerBlocks )\n\t\t\t);\n\t};\n\n/**\n * Returns an action descriptor for SET_EDITING_PATTERN action.\n *\n * @param {string} clientId The clientID of the pattern to target.\n * @param {boolean} isEditing Whether the block should be in editing state.\n * @return {Object} Action descriptor.\n */\nexport function setEditingPattern( clientId, isEditing ) {\n\treturn {\n\t\ttype: 'SET_EDITING_PATTERN',\n\t\tclientId,\n\t\tisEditing,\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;;AAEA,SAASA,YAAY,EAAEC,UAAU,QAAQ,mBAAmB;AAC5D,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASD,KAAK,IAAIE,gBAAgB,QAAQ,yBAAyB;;AAEnE;AACA;AACA;AACA,SAASC,kBAAkB,QAAQ,cAAc;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,a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MAAM,GAAG,CAAC,GAC3CT,QAAQ,GACR9B;MACL,CAAC,EACD0B,4BAA4B,CAAEG,KAAK,CAACW,WAAY,CACjD,CAAC;IACF,CAAE,CAAC;EACJ;EAEA,MAAMC,kBAAkB,GAAG7C,QAAQ,CACjC0B,MAAM,CAAEjC,gBAAiB,CAAC,CAC1BqD,SAAS,CAAErB,YAAY,CAACD,QAAS,CAAC;EAEpCxB,QAAQ,CACNS,QAAQ,CAAEhB,gBAAiB,CAAC,CAC5BsD,aAAa,CACbtB,YAAY,CAACD,QAAQ,EACrBM,4BAA4B,CAAEe,kBAAmB,CAClD,CAAC;AACH,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,iBAAiBA,CAAExB,QAAQ,EAAEyB,SAAS,EAAG;EACxD,OAAO;IACNC,IAAI,EAAE,qBAAqB;IAC3B1B,QAAQ;IACRyB;EACD,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["getBlockType","cloneBlock","store","coreStore","blockEditorStore","PATTERN_SYNC_TYPES","createPattern","title","syncType","content","categories","registry","meta","unsynced","wp_pattern_sync_status","undefined","reusableBlock","status","wp_pattern_category","updatedRecord","dispatch","saveEntityRecord","createPatternFromFile","file","fileContent","text","parsedContent","JSON","parse","e","Error","__file","syncStatus","pattern","convertSyncedPatternToStatic","clientId","patternBlock","select","getBlock","existingOverrides","attributes","cloneBlocksAndRemoveBindings","blocks","map","block","metadata","id","bindings","name","attributeName","value","Object","entries","keys","length","innerBlocks","patternInnerBlocks","getBlocks","replaceBlocks","setEditingPattern","isEditing","type"],"sources":["@wordpress/patterns/src/store/actions.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\n\nimport { getBlockType, cloneBlock } from '@wordpress/blocks';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_SYNC_TYPES } from '../constants';\n\n/**\n * Returns a generator converting one or more static blocks into a pattern, or creating a new empty pattern.\n *\n * @param {string} title Pattern title.\n * @param {'full'|'unsynced'} syncType They way block is synced, 'full' or 'unsynced'.\n * @param {string|undefined} [content] Optional serialized content of blocks to convert to pattern.\n * @param {number[]|undefined} [categories] Ids of any selected categories.\n */\nexport const createPattern =\n\t( title, syncType, content, categories ) =>\n\tasync ( { registry } ) => {\n\t\tconst meta =\n\t\t\tsyncType === PATTERN_SYNC_TYPES.unsynced\n\t\t\t\t? {\n\t\t\t\t\t\twp_pattern_sync_status: syncType,\n\t\t\t\t }\n\t\t\t\t: undefined;\n\n\t\tconst reusableBlock = {\n\t\t\ttitle,\n\t\t\tcontent,\n\t\t\tstatus: 'publish',\n\t\t\tmeta,\n\t\t\twp_pattern_category: categories,\n\t\t};\n\n\t\tconst updatedRecord = await registry\n\t\t\t.dispatch( coreStore )\n\t\t\t.saveEntityRecord( 'postType', 'wp_block', reusableBlock );\n\n\t\treturn updatedRecord;\n\t};\n\n/**\n * Create a pattern from a JSON file.\n * @param {File} file The JSON file instance of the pattern.\n * @param {number[]|undefined} [categories] Ids of any selected categories.\n */\nexport const createPatternFromFile =\n\t( file, categories ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst fileContent = await file.text();\n\t\t/** @type {import('./types').PatternJSON} */\n\t\tlet parsedContent;\n\t\ttry {\n\t\t\tparsedContent = JSON.parse( fileContent );\n\t\t} catch ( e ) {\n\t\t\tthrow new Error( 'Invalid JSON file' );\n\t\t}\n\t\tif (\n\t\t\tparsedContent.__file !== 'wp_block' ||\n\t\t\t! parsedContent.title ||\n\t\t\t! parsedContent.content ||\n\t\t\ttypeof parsedContent.title !== 'string' ||\n\t\t\ttypeof parsedContent.content !== 'string' ||\n\t\t\t( parsedContent.syncStatus &&\n\t\t\t\ttypeof parsedContent.syncStatus !== 'string' )\n\t\t) {\n\t\t\tthrow new Error( 'Invalid pattern JSON file' );\n\t\t}\n\n\t\tconst pattern = await dispatch.createPattern(\n\t\t\tparsedContent.title,\n\t\t\tparsedContent.syncStatus,\n\t\t\tparsedContent.content,\n\t\t\tcategories\n\t\t);\n\n\t\treturn pattern;\n\t};\n\n/**\n * Returns a generator converting a synced pattern block into a static block.\n *\n * @param {string} clientId The client ID of the block to attach.\n */\nexport const convertSyncedPatternToStatic =\n\t( clientId ) =>\n\t( { registry } ) => {\n\t\tconst patternBlock = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlock( clientId );\n\t\tconst existingOverrides = patternBlock.attributes?.content;\n\n\t\tfunction cloneBlocksAndRemoveBindings( blocks ) {\n\t\t\treturn blocks.map( ( block ) => {\n\t\t\t\tlet metadata = block.attributes.metadata;\n\t\t\t\tif ( metadata ) {\n\t\t\t\t\tmetadata = { ...metadata };\n\t\t\t\t\tdelete metadata.id;\n\t\t\t\t\tdelete metadata.bindings;\n\t\t\t\t\t// Use overridden values of the pattern block if they exist.\n\t\t\t\t\tif ( existingOverrides?.[ metadata.name ] ) {\n\t\t\t\t\t\t// Iterate over each overriden attribute.\n\t\t\t\t\t\tfor ( const [ attributeName, value ] of Object.entries(\n\t\t\t\t\t\t\texistingOverrides[ metadata.name ]\n\t\t\t\t\t\t) ) {\n\t\t\t\t\t\t\t// Skip if the attribute does not exist in the block type.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t! getBlockType( block.name )?.attributes[\n\t\t\t\t\t\t\t\t\tattributeName\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Update the block attribute with the override value.\n\t\t\t\t\t\t\tblock.attributes[ attributeName ] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn cloneBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\t{\n\t\t\t\t\t\tmetadata:\n\t\t\t\t\t\t\tmetadata && Object.keys( metadata ).length > 0\n\t\t\t\t\t\t\t\t? metadata\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t},\n\t\t\t\t\tcloneBlocksAndRemoveBindings( block.innerBlocks )\n\t\t\t\t);\n\t\t\t} );\n\t\t}\n\n\t\tconst patternInnerBlocks = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlocks( patternBlock.clientId );\n\n\t\tregistry\n\t\t\t.dispatch( blockEditorStore )\n\t\t\t.replaceBlocks(\n\t\t\t\tpatternBlock.clientId,\n\t\t\t\tcloneBlocksAndRemoveBindings( patternInnerBlocks )\n\t\t\t);\n\t};\n\n/**\n * Returns an action descriptor for SET_EDITING_PATTERN action.\n *\n * @param {string} clientId The clientID of the pattern to target.\n * @param {boolean} isEditing Whether the block should be in editing state.\n * @return {Object} Action descriptor.\n */\nexport function setEditingPattern( clientId, isEditing ) {\n\treturn {\n\t\ttype: 'SET_EDITING_PATTERN',\n\t\tclientId,\n\t\tisEditing,\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;;AAEA,SAASA,YAAY,EAAEC,UAAU,QAAQ,mBAAmB;AAC5D,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASD,KAAK,IAAIE,gBAAgB,QAAQ,yBAAyB;;AAEnE;AACA;AACA;AACA,SAASC,kBAAkB,QAAQ,cAAc;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GACzBA,CAAEC,KAAK,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,UAAU,KACtC,OAAQ;EAAEC;AAAS,CAAC,KAAM;EACzB,MAAMC,IAAI,GACTJ,QAAQ,KAAKH,kBAAkB,CAACQ,QAAQ,GACrC;IACAC,sBAAsB,EAAEN;EACxB,CAAC,GACDO,SAAS;EAEb,MAAMC,aAAa,GAAG;IACrBT,KAAK;IACLE,OAAO;IACPQ,MAAM,EAAE,SAAS;IACjBL,IAAI;IACJM,mBAAmB,EAAER;EACtB,CAAC;EAED,MAAMS,aAAa,GAAG,MAAMR,QAAQ,CAClCS,Q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AACH,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,iBAAiBA,CAAExB,QAAQ,EAAEyB,SAAS,EAAG;EACxD,OAAO;IACNC,IAAI,EAAE,qBAAqB;IAC3B1B,QAAQ;IACRyB;EACD,CAAC;AACF","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/patterns",
3
- "version": "1.19.0",
3
+ "version": "2.0.1",
4
4
  "description": "Management of user pattern editing.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -19,7 +19,8 @@
19
19
  "url": "https://github.com/WordPress/gutenberg/issues"
20
20
  },
21
21
  "engines": {
22
- "node": ">=16.0.0"
22
+ "node": ">=18.12.0",
23
+ "npm": ">=8.19.2"
23
24
  },
24
25
  "main": "build/index.js",
25
26
  "module": "build-module/index.js",
@@ -31,20 +32,20 @@
31
32
  ],
32
33
  "dependencies": {
33
34
  "@babel/runtime": "^7.16.0",
34
- "@wordpress/a11y": "^3.58.0",
35
- "@wordpress/block-editor": "^12.26.0",
36
- "@wordpress/blocks": "^12.35.0",
37
- "@wordpress/components": "^27.6.0",
38
- "@wordpress/compose": "^6.35.0",
39
- "@wordpress/core-data": "^6.35.0",
40
- "@wordpress/data": "^9.28.0",
41
- "@wordpress/element": "^5.35.0",
42
- "@wordpress/html-entities": "^3.58.0",
43
- "@wordpress/i18n": "^4.58.0",
44
- "@wordpress/icons": "^9.49.0",
45
- "@wordpress/notices": "^4.26.0",
46
- "@wordpress/private-apis": "^0.40.0",
47
- "@wordpress/url": "^3.59.0"
35
+ "@wordpress/a11y": "^4.0.1",
36
+ "@wordpress/block-editor": "^13.0.1",
37
+ "@wordpress/blocks": "^13.0.1",
38
+ "@wordpress/components": "^28.0.1",
39
+ "@wordpress/compose": "^7.0.1",
40
+ "@wordpress/core-data": "^7.0.1",
41
+ "@wordpress/data": "^10.0.1",
42
+ "@wordpress/element": "^6.0.1",
43
+ "@wordpress/html-entities": "^4.0.1",
44
+ "@wordpress/i18n": "^5.0.1",
45
+ "@wordpress/icons": "^10.0.1",
46
+ "@wordpress/notices": "^5.0.1",
47
+ "@wordpress/private-apis": "^1.0.1",
48
+ "@wordpress/url": "^4.0.1"
48
49
  },
49
50
  "peerDependencies": {
50
51
  "react": "^18.0.0",
@@ -53,5 +54,5 @@
53
54
  "publishConfig": {
54
55
  "access": "public"
55
56
  },
56
- "gitHead": "42f38f287506a6b3ed8ccba839b18ad066821044"
57
+ "gitHead": "0e973525f7787401b5a544e0727774d52a78639f"
57
58
  }
package/src/api/index.js CHANGED
@@ -22,3 +22,19 @@ export function isOverridableBlock( block ) {
22
22
  )
23
23
  );
24
24
  }
25
+
26
+ /**
27
+ * Determines whether the blocks list has overridable blocks.
28
+ *
29
+ * @param {WPBlock[]} blocks The blocks list.
30
+ *
31
+ * @return {boolean} `true` if the list has overridable blocks, `false` otherwise.
32
+ */
33
+ export function hasOverridableBlocks( blocks ) {
34
+ return blocks.some( ( block ) => {
35
+ if ( isOverridableBlock( block ) ) {
36
+ return true;
37
+ }
38
+ return hasOverridableBlocks( block.innerBlocks );
39
+ } );
40
+ }
@@ -11,13 +11,18 @@ import {
11
11
  } from '@wordpress/components';
12
12
  import { __, _x } from '@wordpress/i18n';
13
13
  import { useState } from '@wordpress/element';
14
- import { useDispatch } from '@wordpress/data';
14
+ import { useDispatch, useSelect } from '@wordpress/data';
15
15
  import { store as noticesStore } from '@wordpress/notices';
16
+ import { store as coreStore } from '@wordpress/core-data';
16
17
 
17
18
  /**
18
19
  * Internal dependencies
19
20
  */
20
- import { PATTERN_DEFAULT_CATEGORY, PATTERN_SYNC_TYPES } from '../constants';
21
+ import {
22
+ PATTERN_DEFAULT_CATEGORY,
23
+ PATTERN_SYNC_TYPES,
24
+ PATTERN_TYPES,
25
+ } from '../constants';
21
26
  import { store as patternsStore } from '../store';
22
27
  import CategorySelector from './category-selector';
23
28
  import { useAddPatternCategory } from '../private-hooks';
@@ -25,12 +30,18 @@ import { unlock } from '../lock-unlock';
25
30
 
26
31
  export default function CreatePatternModal( {
27
32
  className = 'patterns-menu-items__convert-modal',
28
- modalTitle = __( 'Create pattern' ),
33
+ modalTitle,
29
34
  ...restProps
30
35
  } ) {
36
+ const defaultModalTitle = useSelect(
37
+ ( select ) =>
38
+ select( coreStore ).getPostType( PATTERN_TYPES.user )?.labels
39
+ ?.add_new_item,
40
+ []
41
+ );
31
42
  return (
32
43
  <Modal
33
- title={ modalTitle }
44
+ title={ modalTitle || defaultModalTitle }
34
45
  onRequestClose={ restProps.onClose }
35
46
  overlayClassName={ className }
36
47
  >
@@ -40,7 +51,7 @@ export default function CreatePatternModal( {
40
51
  }
41
52
 
42
53
  export function CreatePatternModalContents( {
43
- confirmLabel = __( 'Create' ),
54
+ confirmLabel = __( 'Add' ),
44
55
  defaultCategories = [],
45
56
  content,
46
57
  onClose,
@@ -118,10 +129,7 @@ export function CreatePatternModalContents( {
118
129
  categoryMap={ categoryMap }
119
130
  />
120
131
  <ToggleControl
121
- label={ _x(
122
- 'Synced',
123
- 'Option that makes an individual pattern synchronized'
124
- ) }
132
+ label={ _x( 'Synced', 'pattern (singular)' ) }
125
133
  help={ __(
126
134
  'Sync this pattern across multiple locations.'
127
135
  ) }
@@ -9,66 +9,48 @@ import { __ } from '@wordpress/i18n';
9
9
  /**
10
10
  * Internal dependencies
11
11
  */
12
- import {
13
- PARTIAL_SYNCING_SUPPORTED_BLOCKS,
14
- PATTERN_OVERRIDES_BINDING_SOURCE,
15
- } from '../constants';
12
+ import { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';
16
13
  import {
17
14
  AllowOverridesModal,
18
15
  DisallowOverridesModal,
19
16
  } from './allow-overrides-modal';
20
17
 
21
- function removeBindings( bindings, syncedAttributes ) {
22
- let updatedBindings = {};
23
- for ( const attributeName of syncedAttributes ) {
24
- // Omit any bindings that's not the same source from the `updatedBindings` object.
25
- if (
26
- bindings?.[ attributeName ]?.source !==
27
- PATTERN_OVERRIDES_BINDING_SOURCE &&
28
- bindings?.[ attributeName ]?.source !== undefined
29
- ) {
30
- updatedBindings[ attributeName ] = bindings[ attributeName ];
31
- }
32
- }
18
+ function removeBindings( bindings ) {
19
+ let updatedBindings = { ...bindings };
20
+ delete updatedBindings.__default;
33
21
  if ( ! Object.keys( updatedBindings ).length ) {
34
22
  updatedBindings = undefined;
35
23
  }
36
24
  return updatedBindings;
37
25
  }
38
26
 
39
- function addBindings( bindings, syncedAttributes ) {
40
- const updatedBindings = { ...bindings };
41
- for ( const attributeName of syncedAttributes ) {
42
- if ( ! bindings?.[ attributeName ] ) {
43
- updatedBindings[ attributeName ] = {
44
- source: PATTERN_OVERRIDES_BINDING_SOURCE,
45
- };
46
- }
47
- }
48
- return updatedBindings;
27
+ function addBindings( bindings ) {
28
+ return {
29
+ ...bindings,
30
+ __default: { source: PATTERN_OVERRIDES_BINDING_SOURCE },
31
+ };
49
32
  }
50
33
 
51
- function PatternOverridesControls( { attributes, name, setAttributes } ) {
34
+ function PatternOverridesControls( { attributes, setAttributes } ) {
52
35
  const controlId = useId();
53
36
  const [ showAllowOverridesModal, setShowAllowOverridesModal ] =
54
37
  useState( false );
55
38
  const [ showDisallowOverridesModal, setShowDisallowOverridesModal ] =
56
39
  useState( false );
57
40
 
58
- const syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];
59
- const attributeSources = syncedAttributes.map(
60
- ( attributeName ) =>
61
- attributes.metadata?.bindings?.[ attributeName ]?.source
62
- );
63
- const isConnectedToOtherSources = attributeSources.every(
64
- ( source ) => source && source !== 'core/pattern-overrides'
65
- );
41
+ const hasName = !! attributes.metadata?.name;
42
+ const defaultBindings = attributes.metadata?.bindings?.__default;
43
+ const allowOverrides =
44
+ hasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;
45
+ const isConnectedToOtherSources =
46
+ defaultBindings?.source &&
47
+ defaultBindings.source !== PATTERN_OVERRIDES_BINDING_SOURCE;
66
48
 
67
49
  function updateBindings( isChecked, customName ) {
68
50
  const prevBindings = attributes?.metadata?.bindings;
69
51
  const updatedBindings = isChecked
70
- ? addBindings( prevBindings, syncedAttributes )
71
- : removeBindings( prevBindings, syncedAttributes );
52
+ ? addBindings( prevBindings )
53
+ : removeBindings( prevBindings );
72
54
 
73
55
  const updatedMetadata = {
74
56
  ...attributes.metadata,
@@ -89,13 +71,6 @@ function PatternOverridesControls( { attributes, name, setAttributes } ) {
89
71
  return null;
90
72
  }
91
73
 
92
- const hasName = !! attributes.metadata?.name;
93
- const allowOverrides =
94
- hasName &&
95
- attributeSources.some(
96
- ( source ) => source === PATTERN_OVERRIDES_BINDING_SOURCE
97
- );
98
-
99
74
  return (
100
75
  <>
101
76
  <InspectorControls group="advanced">
@@ -11,7 +11,7 @@ import {
11
11
  default as DuplicatePatternModal,
12
12
  useDuplicatePatternProps,
13
13
  } from './components/duplicate-pattern-modal';
14
- import { isOverridableBlock } from './api';
14
+ import { isOverridableBlock, hasOverridableBlocks } from './api';
15
15
  import RenamePatternModal from './components/rename-pattern-modal';
16
16
  import PatternsMenuItems from './components';
17
17
  import RenamePatternCategoryModal from './components/rename-pattern-category-modal';
@@ -34,6 +34,7 @@ lock( privateApis, {
34
34
  CreatePatternModalContents,
35
35
  DuplicatePatternModal,
36
36
  isOverridableBlock,
37
+ hasOverridableBlocks,
37
38
  useDuplicatePatternProps,
38
39
  RenamePatternModal,
39
40
  PatternsMenuItems,
@@ -102,8 +102,8 @@ export const convertSyncedPatternToStatic =
102
102
  metadata = { ...metadata };
103
103
  delete metadata.id;
104
104
  delete metadata.bindings;
105
- // Use overriden values of the pattern block if they exist.
106
- if ( existingOverrides[ metadata.name ] ) {
105
+ // Use overridden values of the pattern block if they exist.
106
+ if ( existingOverrides?.[ metadata.name ] ) {
107
107
  // Iterate over each overriden attribute.
108
108
  for ( const [ attributeName, value ] of Object.entries(
109
109
  existingOverrides[ metadata.name ]