@wordpress/patterns 1.17.0 → 1.19.0

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.19.0 (2024-05-16)
6
+
7
+ ## 1.18.0 (2024-05-02)
8
+
5
9
  ## 1.17.0 (2024-04-19)
6
10
 
7
11
  ## 1.16.0 (2024-04-03)
@@ -72,7 +72,9 @@ function PatternOverridesControls({
72
72
  }
73
73
 
74
74
  // Avoid overwriting other (e.g. meta) bindings.
75
- if (isConnectedToOtherSources) return null;
75
+ if (isConnectedToOtherSources) {
76
+ return null;
77
+ }
76
78
  const hasName = !!attributes.metadata?.name;
77
79
  const allowOverrides = hasName && attributeSources.some(source => source === _constants.PATTERN_OVERRIDES_BINDING_SOURCE);
78
80
  return (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_blockEditor.InspectorControls, {
@@ -85,6 +87,7 @@ function PatternOverridesControls({
85
87
  __next40pxDefaultSize: true,
86
88
  className: "pattern-overrides-control__allow-overrides-button",
87
89
  variant: "secondary",
90
+ "aria-haspopup": "dialog",
88
91
  onClick: () => {
89
92
  if (allowOverrides) {
90
93
  setShowDisallowOverridesModal(true);
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_blockEditor","_components","_i18n","_constants","_allowOverridesModal","removeBindings","bindings","syncedAttributes","updatedBindings","attributeName","source","PATTERN_OVERRIDES_BINDING_SOURCE","undefined","Object","keys","length","addBindings","PatternOverridesControls","attributes","name","setAttributes","controlId","useId","showAllowOverridesModal","setShowAllowOverridesModal","useState","showDisallowOverridesModal","setShowDisallowOverridesModal","PARTIAL_SYNCING_SUPPORTED_BLOCKS","attributeSources","map","metadata","isConnectedToOtherSources","every","updateBindings","isChecked","customName","prevBindings","updatedMetadata","hasName","allowOverrides","some","_react","createElement","Fragment","InspectorControls","group","BaseControl","id","label","__","help","Button","__next40pxDefaultSize","className","variant","onClick","AllowOverridesModal","initialName","onClose","onSave","newName","DisallowOverridesModal","_default","exports","default"],"sources":["@wordpress/patterns/src/components/pattern-overrides-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useId } from '@wordpress/element';\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { BaseControl, Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n\tPATTERN_OVERRIDES_BINDING_SOURCE,\n} from '../constants';\nimport {\n\tAllowOverridesModal,\n\tDisallowOverridesModal,\n} from './allow-overrides-modal';\n\nfunction removeBindings( bindings, syncedAttributes ) {\n\tlet updatedBindings = {};\n\tfor ( const attributeName of syncedAttributes ) {\n\t\t// Omit any bindings that's not the same source from the `updatedBindings` object.\n\t\tif (\n\t\t\tbindings?.[ attributeName ]?.source !==\n\t\t\t\tPATTERN_OVERRIDES_BINDING_SOURCE &&\n\t\t\tbindings?.[ attributeName ]?.source !== undefined\n\t\t) {\n\t\t\tupdatedBindings[ attributeName ] = bindings[ attributeName ];\n\t\t}\n\t}\n\tif ( ! Object.keys( updatedBindings ).length ) {\n\t\tupdatedBindings = undefined;\n\t}\n\treturn updatedBindings;\n}\n\nfunction addBindings( bindings, syncedAttributes ) {\n\tconst updatedBindings = { ...bindings };\n\tfor ( const attributeName of syncedAttributes ) {\n\t\tif ( ! bindings?.[ attributeName ] ) {\n\t\t\tupdatedBindings[ attributeName ] = {\n\t\t\t\tsource: PATTERN_OVERRIDES_BINDING_SOURCE,\n\t\t\t};\n\t\t}\n\t}\n\treturn updatedBindings;\n}\n\nfunction PatternOverridesControls( { attributes, name, setAttributes } ) {\n\tconst controlId = useId();\n\tconst [ showAllowOverridesModal, setShowAllowOverridesModal ] =\n\t\tuseState( false );\n\tconst [ showDisallowOverridesModal, setShowDisallowOverridesModal ] =\n\t\tuseState( false );\n\n\tconst syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];\n\tconst attributeSources = syncedAttributes.map(\n\t\t( attributeName ) =>\n\t\t\tattributes.metadata?.bindings?.[ attributeName ]?.source\n\t);\n\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t( source ) => source && source !== 'core/pattern-overrides'\n\t);\n\n\tfunction updateBindings( isChecked, customName ) {\n\t\tconst prevBindings = attributes?.metadata?.bindings;\n\t\tconst updatedBindings = isChecked\n\t\t\t? addBindings( prevBindings, syncedAttributes )\n\t\t\t: removeBindings( prevBindings, syncedAttributes );\n\n\t\tconst updatedMetadata = {\n\t\t\t...attributes.metadata,\n\t\t\tbindings: updatedBindings,\n\t\t};\n\n\t\tif ( customName ) {\n\t\t\tupdatedMetadata.name = customName;\n\t\t}\n\n\t\tsetAttributes( {\n\t\t\tmetadata: updatedMetadata,\n\t\t} );\n\t}\n\n\t// Avoid overwriting other (e.g. meta) bindings.\n\tif ( isConnectedToOtherSources ) return null;\n\n\tconst hasName = !! attributes.metadata?.name;\n\tconst allowOverrides =\n\t\thasName &&\n\t\tattributeSources.some(\n\t\t\t( source ) => source === PATTERN_OVERRIDES_BINDING_SOURCE\n\t\t);\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<BaseControl\n\t\t\t\t\tid={ controlId }\n\t\t\t\t\tlabel={ __( 'Overrides' ) }\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'Allow changes to this block throughout instances of this pattern.'\n\t\t\t\t\t) }\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"pattern-overrides-control__allow-overrides-button\"\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tif ( allowOverrides ) {\n\t\t\t\t\t\t\t\tsetShowDisallowOverridesModal( true );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetShowAllowOverridesModal( true );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ allowOverrides\n\t\t\t\t\t\t\t? __( 'Disable overrides' )\n\t\t\t\t\t\t\t: __( 'Enable overrides' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</BaseControl>\n\t\t\t</InspectorControls>\n\n\t\t\t{ showAllowOverridesModal && (\n\t\t\t\t<AllowOverridesModal\n\t\t\t\t\tinitialName={ attributes.metadata?.name }\n\t\t\t\t\tonClose={ () => setShowAllowOverridesModal( false ) }\n\t\t\t\t\tonSave={ ( newName ) => {\n\t\t\t\t\t\tupdateBindings( true, newName );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showDisallowOverridesModal && (\n\t\t\t\t<DisallowOverridesModal\n\t\t\t\t\tonClose={ () => setShowDisallowOverridesModal( false ) }\n\t\t\t\t\tonSave={ () => updateBindings( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PatternOverridesControls;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,UAAA,GAAAJ,OAAA;AAIA,IAAAK,oBAAA,GAAAL,OAAA;AAfA;AACA;AACA;;AAMA;AACA;AACA;;AAUA,SAASM,cAAcA,CAAEC,QAAQ,EAAEC,gBAAgB,EAAG;EACrD,IAAIC,eAAe,GAAG,CAAC,CAAC;EACxB,KAAM,MAAMC,aAAa,IAAIF,gBAAgB,EAAG;IAC/C;IACA,IACCD,QAAQ,GAAIG,aAAa,CAAE,EAAEC,MAAM,KAClCC,2CAAgC,IACjCL,QAAQ,GAAIG,aAAa,CAAE,EAAEC,MAAM,KAAKE,SAAS,EAChD;MACDJ,eAAe,CAAEC,aAAa,CAAE,GAAGH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c,GACb,IAAAU,QAAE,EAAE,mBAAoB,CAAC,GACzB,IAAAA,QAAE,EAAE,kBAAmB,CACnB,CACI,CACK,CAAC,EAElB3B,uBAAuB,IACxB,IAAAmB,MAAA,CAAAC,aAAA,EAACvC,oBAAA,CAAAqD,mBAAmB;IACnBC,WAAW,EAAGxC,UAAU,CAACa,QAAQ,EAAEZ,IAAM;IACzCwC,OAAO,EAAGA,CAAA,KAAMnC,0BAA0B,CAAE,KAAM,CAAG;IACrDoC,MAAM,EAAKC,OAAO,IAAM;MACvB3B,cAAc,CAAE,IAAI,EAAE2B,OAAQ,CAAC;IAChC;EAAG,CACH,CACD,EACCnC,0BAA0B,IAC3B,IAAAgB,MAAA,CAAAC,aAAA,EAACvC,oBAAA,CAAA0D,sBAAsB;IACtBH,OAAO,EAAGA,CAAA,KAAMhC,6BAA6B,CAAE,KAAM,CAAG;IACxDiC,MAAM,EAAGA,CAAA,KAAM1B,cAAc,CAAE,KAAM;EAAG,CACxC,CAED,CAAC;AAEL;AAAC,IAAA6B,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEchD,wBAAwB","ignoreList":[]}
1
+ {"version":3,"names":["_element","require","_blockEditor","_components","_i18n","_constants","_allowOverridesModal","removeBindings","bindings","syncedAttributes","updatedBindings","attributeName","source","PATTERN_OVERRIDES_BINDING_SOURCE","undefined","Object","keys","length","addBindings","PatternOverridesControls","attributes","name","setAttributes","controlId","useId","showAllowOverridesModal","setShowAllowOverridesModal","useState","showDisallowOverridesModal","setShowDisallowOverridesModal","PARTIAL_SYNCING_SUPPORTED_BLOCKS","attributeSources","map","metadata","isConnectedToOtherSources","every","updateBindings","isChecked","customName","prevBindings","updatedMetadata","hasName","allowOverrides","some","_react","createElement","Fragment","InspectorControls","group","BaseControl","id","label","__","help","Button","__next40pxDefaultSize","className","variant","onClick","AllowOverridesModal","initialName","onClose","onSave","newName","DisallowOverridesModal","_default","exports","default"],"sources":["@wordpress/patterns/src/components/pattern-overrides-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useId } from '@wordpress/element';\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { BaseControl, Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n\tPATTERN_OVERRIDES_BINDING_SOURCE,\n} from '../constants';\nimport {\n\tAllowOverridesModal,\n\tDisallowOverridesModal,\n} from './allow-overrides-modal';\n\nfunction removeBindings( bindings, syncedAttributes ) {\n\tlet updatedBindings = {};\n\tfor ( const attributeName of syncedAttributes ) {\n\t\t// Omit any bindings that's not the same source from the `updatedBindings` object.\n\t\tif (\n\t\t\tbindings?.[ attributeName ]?.source !==\n\t\t\t\tPATTERN_OVERRIDES_BINDING_SOURCE &&\n\t\t\tbindings?.[ attributeName ]?.source !== undefined\n\t\t) {\n\t\t\tupdatedBindings[ attributeName ] = bindings[ attributeName ];\n\t\t}\n\t}\n\tif ( ! Object.keys( updatedBindings ).length ) {\n\t\tupdatedBindings = undefined;\n\t}\n\treturn updatedBindings;\n}\n\nfunction addBindings( bindings, syncedAttributes ) {\n\tconst updatedBindings = { ...bindings };\n\tfor ( const attributeName of syncedAttributes ) {\n\t\tif ( ! bindings?.[ attributeName ] ) {\n\t\t\tupdatedBindings[ attributeName ] = {\n\t\t\t\tsource: PATTERN_OVERRIDES_BINDING_SOURCE,\n\t\t\t};\n\t\t}\n\t}\n\treturn updatedBindings;\n}\n\nfunction PatternOverridesControls( { attributes, name, setAttributes } ) {\n\tconst controlId = useId();\n\tconst [ showAllowOverridesModal, setShowAllowOverridesModal ] =\n\t\tuseState( false );\n\tconst [ showDisallowOverridesModal, setShowDisallowOverridesModal ] =\n\t\tuseState( false );\n\n\tconst syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];\n\tconst attributeSources = syncedAttributes.map(\n\t\t( attributeName ) =>\n\t\t\tattributes.metadata?.bindings?.[ attributeName ]?.source\n\t);\n\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t( source ) => source && source !== 'core/pattern-overrides'\n\t);\n\n\tfunction updateBindings( isChecked, customName ) {\n\t\tconst prevBindings = attributes?.metadata?.bindings;\n\t\tconst updatedBindings = isChecked\n\t\t\t? addBindings( prevBindings, syncedAttributes )\n\t\t\t: removeBindings( prevBindings, syncedAttributes );\n\n\t\tconst updatedMetadata = {\n\t\t\t...attributes.metadata,\n\t\t\tbindings: updatedBindings,\n\t\t};\n\n\t\tif ( customName ) {\n\t\t\tupdatedMetadata.name = customName;\n\t\t}\n\n\t\tsetAttributes( {\n\t\t\tmetadata: updatedMetadata,\n\t\t} );\n\t}\n\n\t// Avoid overwriting other (e.g. meta) bindings.\n\tif ( isConnectedToOtherSources ) {\n\t\treturn null;\n\t}\n\n\tconst hasName = !! attributes.metadata?.name;\n\tconst allowOverrides =\n\t\thasName &&\n\t\tattributeSources.some(\n\t\t\t( source ) => source === PATTERN_OVERRIDES_BINDING_SOURCE\n\t\t);\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<BaseControl\n\t\t\t\t\tid={ controlId }\n\t\t\t\t\tlabel={ __( 'Overrides' ) }\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'Allow changes to this block throughout instances of this pattern.'\n\t\t\t\t\t) }\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"pattern-overrides-control__allow-overrides-button\"\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tif ( allowOverrides ) {\n\t\t\t\t\t\t\t\tsetShowDisallowOverridesModal( true );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetShowAllowOverridesModal( true );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ allowOverrides\n\t\t\t\t\t\t\t? __( 'Disable overrides' )\n\t\t\t\t\t\t\t: __( 'Enable overrides' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</BaseControl>\n\t\t\t</InspectorControls>\n\n\t\t\t{ showAllowOverridesModal && (\n\t\t\t\t<AllowOverridesModal\n\t\t\t\t\tinitialName={ attributes.metadata?.name }\n\t\t\t\t\tonClose={ () => setShowAllowOverridesModal( false ) }\n\t\t\t\t\tonSave={ ( newName ) => {\n\t\t\t\t\t\tupdateBindings( true, newName );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showDisallowOverridesModal && (\n\t\t\t\t<DisallowOverridesModal\n\t\t\t\t\tonClose={ () => setShowDisallowOverridesModal( false ) }\n\t\t\t\t\tonSave={ () => updateBindings( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PatternOverridesControls;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,UAAA,GAAAJ,OAAA;AAIA,IAAAK,oBAAA,GAAAL,OAAA;AAfA;AACA;AACA;;AAMA;AACA;AACA;;AAUA,SAASM,cAAcA,CAAEC,QAAQ,EAAEC,gBAAgB,EAAG;EACrD,IAAIC,eAAe,GAAG,CAAC,CAAC;EACxB,KAAM,MAAMC,aAAa,IAAIF,gBAAgB,EAAG;IAC/C;IACA,IACCD,QAAQ,GAAIG,aAAa,CAAE,EAAEC,MAAM,KAClCC,2CAAgC,IACjCL,QAAQ,GAAIG,aAAa,CAAE,EAAEC,MAAM,KAAKE,SAAS,EAChD;MACDJ,eAAe,CAAEC,aAAa,CAAE,GAAGH,QAAQ,CAAEG,aAAa,CAAE;IAC7D;EACD;EACA,IAAK,CAAEI,MAAM,CAACC,IAAI,C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,IAAAA,QAAE,EAAE,kBAAmB,CACnB,CACI,CACK,CAAC,EAElB3B,uBAAuB,IACxB,IAAAmB,MAAA,CAAAC,aAAA,EAACvC,oBAAA,CAAAqD,mBAAmB;IACnBC,WAAW,EAAGxC,UAAU,CAACa,QAAQ,EAAEZ,IAAM;IACzCwC,OAAO,EAAGA,CAAA,KAAMnC,0BAA0B,CAAE,KAAM,CAAG;IACrDoC,MAAM,EAAKC,OAAO,IAAM;MACvB3B,cAAc,CAAE,IAAI,EAAE2B,OAAQ,CAAC;IAChC;EAAG,CACH,CACD,EACCnC,0BAA0B,IAC3B,IAAAgB,MAAA,CAAAC,aAAA,EAACvC,oBAAA,CAAA0D,sBAAsB;IACtBH,OAAO,EAAGA,CAAA,KAAMhC,6BAA6B,CAAE,KAAM,CAAG;IACxDiC,MAAM,EAAGA,CAAA,KAAM1B,cAAc,CAAE,KAAM;EAAG,CACxC,CAED,CAAC;AAEL;AAAC,IAAA6B,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEchD,wBAAwB","ignoreList":[]}
@@ -33,14 +33,12 @@ function PatternsManageButton({
33
33
  const {
34
34
  getBlock,
35
35
  canRemoveBlock,
36
- getBlockCount,
37
- getSettings
36
+ getBlockCount
38
37
  } = select(_blockEditor.store);
39
38
  const {
40
39
  canUser
41
40
  } = select(_coreData.store);
42
41
  const reusableBlock = getBlock(clientId);
43
- const isBlockTheme = getSettings().__unstableIsBlockBasedTheme;
44
42
  return {
45
43
  canRemove: canRemoveBlock(clientId),
46
44
  isVisible: !!reusableBlock && (0, _blocks.isReusableBlock)(reusableBlock) && !!canUser('update', 'blocks', reusableBlock.attributes.ref),
@@ -48,7 +46,7 @@ function PatternsManageButton({
48
46
  // The site editor and templates both check whether the user
49
47
  // has edit_theme_options capabilities. We can leverage that here
50
48
  // and omit the manage patterns link if the user can't access it.
51
- managePatternsUrl: isBlockTheme && canUser('read', 'templates') ? (0, _url.addQueryArgs)('site-editor.php', {
49
+ managePatternsUrl: canUser('create', 'templates') ? (0, _url.addQueryArgs)('site-editor.php', {
52
50
  path: '/patterns'
53
51
  }) : (0, _url.addQueryArgs)('edit.php', {
54
52
  post_type: 'wp_block'
@@ -1 +1 @@
1
- {"version":3,"names":["_components","require","_i18n","_blocks","_data","_blockEditor","_url","_coreData","_store","_lockUnlock","PatternsManageButton","clientId","canRemove","isVisible","managePatternsUrl","useSelect","select","getBlock","canRemoveBlock","getBlockCount","getSettings","blockEditorStore","canUser","coreStore","reusableBlock","isBlockTheme","__unstableIsBlockBasedTheme","isReusableBlock","attributes","ref","innerBlockCount","addQueryArgs","path","post_type","convertSyncedPatternToStatic","unlock","useDispatch","patternsStore","_react","createElement","Fragment","MenuItem","onClick","__","href","_default","exports","default"],"sources":["@wordpress/patterns/src/components/patterns-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nfunction PatternsManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount, getSettings } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\t\t\tconst isBlockTheme = getSettings().__unstableIsBlockBasedTheme;\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser(\n\t\t\t\t\t\t'update',\n\t\t\t\t\t\t'blocks',\n\t\t\t\t\t\treusableBlock.attributes.ref\n\t\t\t\t\t),\n\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\tmanagePatternsUrl:\n\t\t\t\t\tisBlockTheme && canUser( 'read', 'templates' )\n\t\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\t\tpath: '/patterns',\n\t\t\t\t\t\t } )\n\t\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t\t } ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { convertSyncedPatternToStatic } = unlock(\n\t\tuseDispatch( patternsStore )\n\t);\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ canRemove && (\n\t\t\t\t<MenuItem\n\t\t\t\t\tonClick={ () => convertSyncedPatternToStatic( clientId ) }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Detach' ) }\n\t\t\t\t</MenuItem>\n\t\t\t) }\n\t\t\t<MenuItem href={ managePatternsUrl }>\n\t\t\t\t{ __( 'Manage patterns' ) }\n\t\t\t</MenuItem>\n\t\t</>\n\t);\n}\n\nexport default PatternsManageButton;\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,IAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA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AEA,OACC,IAAAyB,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAE,QAAA,QACG5B,SAAS,IACV,IAAA0B,MAAA,CAAAC,aAAA,EAACvC,WAAA,CAAAyC,QAAQ;IACRC,OAAO,EAAGA,CAAA,KAAMR,4BAA4B,CAAEvB,QAAS;EAAG,GAExD,IAAAgC,QAAE,EAAE,QAAS,CACN,CACV,EACD,IAAAL,MAAA,CAAAC,aAAA,EAACvC,WAAA,CAAAyC,QAAQ;IAACG,IAAI,EAAG9B;EAAmB,GACjC,IAAA6B,QAAE,EAAE,iBAAkB,CACf,CACT,CAAC;AAEL;AAAC,IAAAE,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcrC,oBAAoB","ignoreList":[]}
1
+ {"version":3,"names":["_components","require","_i18n","_blocks","_data","_blockEditor","_url","_coreData","_store","_lockUnlock","PatternsManageButton","clientId","canRemove","isVisible","managePatternsUrl","useSelect","select","getBlock","canRemoveBlock","getBlockCount","blockEditorStore","canUser","coreStore","reusableBlock","isReusableBlock","attributes","ref","innerBlockCount","addQueryArgs","path","post_type","convertSyncedPatternToStatic","unlock","useDispatch","patternsStore","_react","createElement","Fragment","MenuItem","onClick","__","href","_default","exports","default"],"sources":["@wordpress/patterns/src/components/patterns-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nfunction PatternsManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser(\n\t\t\t\t\t\t'update',\n\t\t\t\t\t\t'blocks',\n\t\t\t\t\t\treusableBlock.attributes.ref\n\t\t\t\t\t),\n\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\tmanagePatternsUrl: canUser( 'create', 'templates' )\n\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\tpath: '/patterns',\n\t\t\t\t\t } )\n\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t } ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { convertSyncedPatternToStatic } = unlock(\n\t\tuseDispatch( patternsStore )\n\t);\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ canRemove && (\n\t\t\t\t<MenuItem\n\t\t\t\t\tonClick={ () => convertSyncedPatternToStatic( clientId ) }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Detach' ) }\n\t\t\t\t</MenuItem>\n\t\t\t) }\n\t\t\t<MenuItem href={ managePatternsUrl }>\n\t\t\t\t{ __( 'Manage patterns' ) }\n\t\t\t</MenuItem>\n\t\t</>\n\t);\n}\n\nexport default PatternsManageButton;\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC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IAAAC,kBAAM,EAC9C,IAAAC,iBAAW,EAAEC,YAAc,CAC5B,CAAC;EAED,IAAK,CAAErB,SAAS,EAAG;IAClB,OAAO,IAAI;EACZ;EAEA,OACC,IAAAsB,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAE,QAAA,QACGzB,SAAS,IACV,IAAAuB,MAAA,CAAAC,aAAA,EAACpC,WAAA,CAAAsC,QAAQ;IACRC,OAAO,EAAGA,CAAA,KAAMR,4BAA4B,CAAEpB,QAAS;EAAG,GAExD,IAAA6B,QAAE,EAAE,QAAS,CACN,CACV,EACD,IAAAL,MAAA,CAAAC,aAAA,EAACpC,WAAA,CAAAsC,QAAQ;IAACG,IAAI,EAAG3B;EAAmB,GACjC,IAAA0B,QAAE,EAAE,iBAAkB,CACf,CACT,CAAC;AAEL;AAAC,IAAAE,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEclC,oBAAoB","ignoreList":[]}
@@ -8,58 +8,67 @@ var _react = require("react");
8
8
  var _blockEditor = require("@wordpress/block-editor");
9
9
  var _components = require("@wordpress/components");
10
10
  var _data = require("@wordpress/data");
11
- var _coreData = require("@wordpress/core-data");
12
- var _blocks = require("@wordpress/blocks");
13
11
  var _i18n = require("@wordpress/i18n");
14
12
  /**
15
13
  * WordPress dependencies
16
14
  */
17
15
 
18
- function recursivelyFindBlockWithName(blocks, name) {
19
- for (const block of blocks) {
20
- if (block.attributes.metadata?.name === name) {
21
- return block;
22
- }
23
- const found = recursivelyFindBlockWithName(block.innerBlocks, name);
24
- if (found) {
25
- return found;
26
- }
27
- }
28
- }
16
+ const CONTENT = 'content';
29
17
  function ResetOverridesControl(props) {
30
- const registry = (0, _data.useRegistry)();
31
18
  const name = props.attributes.metadata?.name;
32
- const patternWithOverrides = (0, _data.useSelect)(select => {
19
+ const registry = (0, _data.useRegistry)();
20
+ const isOverriden = (0, _data.useSelect)(select => {
33
21
  if (!name) {
34
- return undefined;
22
+ return;
35
23
  }
36
24
  const {
37
- getBlockParentsByBlockName,
38
- getBlocksByClientId
25
+ getBlockAttributes,
26
+ getBlockParentsByBlockName
39
27
  } = select(_blockEditor.store);
40
- const patternBlock = getBlocksByClientId(getBlockParentsByBlockName(props.clientId, 'core/block'))[0];
41
- if (!patternBlock?.attributes.content?.[name]) {
42
- return undefined;
28
+ const [patternClientId] = getBlockParentsByBlockName(props.clientId, 'core/block', true);
29
+ if (!patternClientId) {
30
+ return;
31
+ }
32
+ const overrides = getBlockAttributes(patternClientId)[CONTENT];
33
+ if (!overrides) {
34
+ return;
43
35
  }
44
- return patternBlock;
36
+ return overrides.hasOwnProperty(name);
45
37
  }, [props.clientId, name]);
46
- const resetOverrides = async () => {
47
- var _editedRecord$blocks;
48
- const editedRecord = await registry.resolveSelect(_coreData.store).getEditedEntityRecord('postType', 'wp_block', patternWithOverrides.attributes.ref);
49
- const blocks = (_editedRecord$blocks = editedRecord.blocks) !== null && _editedRecord$blocks !== void 0 ? _editedRecord$blocks : (0, _blocks.parse)(editedRecord.content);
50
- const block = recursivelyFindBlockWithName(blocks, name);
51
- const newAttributes = Object.assign(
52
- // Reset every existing attribute to undefined.
53
- Object.fromEntries(Object.keys(props.attributes).map(key => [key, undefined])),
54
- // Then assign the original attributes.
55
- block.attributes);
56
- props.setAttributes(newAttributes);
57
- };
38
+ function onClick() {
39
+ const {
40
+ getBlockAttributes,
41
+ getBlockParentsByBlockName
42
+ } = registry.select(_blockEditor.store);
43
+ const [patternClientId] = getBlockParentsByBlockName(props.clientId, 'core/block', true);
44
+ if (!patternClientId) {
45
+ return;
46
+ }
47
+ const overrides = getBlockAttributes(patternClientId)[CONTENT];
48
+ if (!overrides.hasOwnProperty(name)) {
49
+ return;
50
+ }
51
+ const {
52
+ updateBlockAttributes,
53
+ __unstableMarkLastChangeAsPersistent
54
+ } = registry.dispatch(_blockEditor.store);
55
+ __unstableMarkLastChangeAsPersistent();
56
+ let newOverrides = {
57
+ ...overrides
58
+ };
59
+ delete newOverrides[name];
60
+ if (!Object.keys(newOverrides).length) {
61
+ newOverrides = undefined;
62
+ }
63
+ updateBlockAttributes(patternClientId, {
64
+ [CONTENT]: newOverrides
65
+ });
66
+ }
58
67
  return (0, _react.createElement)(_blockEditor.BlockControls, {
59
68
  group: "other"
60
69
  }, (0, _react.createElement)(_components.ToolbarGroup, null, (0, _react.createElement)(_components.ToolbarButton, {
61
- onClick: resetOverrides,
62
- disabled: !patternWithOverrides,
70
+ onClick: onClick,
71
+ disabled: !isOverriden,
63
72
  __experimentalIsFocusable: true
64
73
  }, (0, _i18n.__)('Reset'))));
65
74
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_blockEditor","require","_components","_data","_coreData","_blocks","_i18n","recursivelyFindBlockWithName","blocks","name","block","attributes","metadata","found","innerBlocks","ResetOverridesControl","props","registry","useRegistry","patternWithOverrides","useSelect","select","undefined","getBlockParentsByBlockName","getBlocksByClientId","blockEditorStore","patternBlock","clientId","content","resetOverrides","_editedRecord$blocks","editedRecord","resolveSelect","coreStore","getEditedEntityRecord","ref","parse","newAttributes","Object","assign","fromEntries","keys","map","key","setAttributes","_react","createElement","BlockControls","group","ToolbarGroup","ToolbarButton","onClick","disabled","__experimentalIsFocusable","__"],"sources":["@wordpress/patterns/src/components/reset-overrides-control.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tstore as blockEditorStore,\n\tBlockControls,\n} from '@wordpress/block-editor';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { useSelect, useRegistry } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { parse } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\nfunction recursivelyFindBlockWithName( blocks, name ) {\n\tfor ( const block of blocks ) {\n\t\tif ( block.attributes.metadata?.name === name ) {\n\t\t\treturn block;\n\t\t}\n\n\t\tconst found = recursivelyFindBlockWithName( block.innerBlocks, name );\n\t\tif ( found ) {\n\t\t\treturn found;\n\t\t}\n\t}\n}\n\nexport default function ResetOverridesControl( props ) {\n\tconst registry = useRegistry();\n\tconst name = props.attributes.metadata?.name;\n\tconst patternWithOverrides = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! name ) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst { getBlockParentsByBlockName, getBlocksByClientId } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst patternBlock = getBlocksByClientId(\n\t\t\t\tgetBlockParentsByBlockName( props.clientId, 'core/block' )\n\t\t\t)[ 0 ];\n\n\t\t\tif ( ! patternBlock?.attributes.content?.[ name ] ) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\treturn patternBlock;\n\t\t},\n\t\t[ props.clientId, name ]\n\t);\n\n\tconst resetOverrides = async () => {\n\t\tconst editedRecord = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_block',\n\t\t\t\tpatternWithOverrides.attributes.ref\n\t\t\t);\n\t\tconst blocks = editedRecord.blocks ?? parse( editedRecord.content );\n\t\tconst block = recursivelyFindBlockWithName( blocks, name );\n\n\t\tconst newAttributes = Object.assign(\n\t\t\t// Reset every existing attribute to undefined.\n\t\t\tObject.fromEntries(\n\t\t\t\tObject.keys( props.attributes ).map( ( key ) => [\n\t\t\t\t\tkey,\n\t\t\t\t\tundefined,\n\t\t\t\t] )\n\t\t\t),\n\t\t\t// Then assign the original attributes.\n\t\t\tblock.attributes\n\t\t);\n\n\t\tprops.setAttributes( newAttributes );\n\t};\n\n\treturn (\n\t\t<BlockControls group=\"other\">\n\t\t\t<ToolbarGroup>\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tonClick={ resetOverrides }\n\t\t\t\t\tdisabled={ ! patternWithOverrides }\n\t\t\t\t\t__experimentalIsFocusable\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</ToolbarGroup>\n\t\t</BlockControls>\n\t);\n}\n"],"mappings":";;;;;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MAAMoB,cAAc,GAAG,MAAAA,CAAA,KAAY;IAAA,IAAAC,oBAAA;IAClC,MAAMC,YAAY,GAAG,MAAMd,QAAQ,CACjCe,aAAa,CAAEC,eAAU,CAAC,CAC1BC,qBAAqB,CACrB,UAAU,EACV,UAAU,EACVf,oBAAoB,CAACR,UAAU,CAACwB,GACjC,CAAC;IACF,MAAM3B,MAAM,IAAAsB,oBAAA,GAAGC,YAAY,CAACvB,MAAM,cAAAsB,oBAAA,cAAAA,oBAAA,GAAI,IAAAM,aAAK,EAAEL,YAAY,CAACH,OAAQ,CAAC;IACnE,MAAMlB,KAAK,GAAGH,4BAA4B,CAAEC,MAAM,EAAEC,IAAK,CAAC;IAE1D,MAAM4B,aAAa,GAAGC,MAAM,CAACC,MAAM;IAClC;IACAD,MAAM,CAACE,WAAW,CACjBF,MAAM,CAACG,IAAI,CAAEzB,KAAK,CAACL,UAAW,CAAC,CAAC+B,GAAG,CAAIC,GAAG,IAAM,CAC/CA,GAAG,EACHrB,SAAS,CACR,CACH,CAAC;IACD;IACAZ,KAAK,CAACC,UACP,CAAC;IAEDK,KAAK,CAAC4B,aAAa,CAAEP,aAAc,CAAC;EACrC,CAAC;EAED,OACC,IAAAQ,MAAA,CAAAC,aAAA,EAAC9C,YAAA,CAAA+C,aAAa;IAACC,KAAK,EAAC;EAAO,GAC3B,IAAAH,MAAA,CAAAC,aAAA,EAAC5C,WAAA,CAAA+C,YAAY,QACZ,IAAAJ,MAAA,CAAAC,aAAA,EAAC5C,WAAA,CAAAgD,aAAa;IACbC,OAAO,EAAGtB,cAAgB;IAC1BuB,QAAQ,EAAG,CAAEjC,oBAAsB;IACnCkC,yBAAyB;EAAA,GAEvB,IAAAC,QAAE,EAAE,OAAQ,CACA,CACF,CACA,CAAC;AAElB","ignoreList":[]}
1
+ {"version":3,"names":["_blockEditor","require","_components","_data","_i18n","CONTENT","ResetOverridesControl","props","name","attributes","metadata","registry","useRegistry","isOverriden","useSelect","select","getBlockAttributes","getBlockParentsByBlockName","blockEditorStore","patternClientId","clientId","overrides","hasOwnProperty","onClick","updateBlockAttributes","__unstableMarkLastChangeAsPersistent","dispatch","newOverrides","Object","keys","length","undefined","_react","createElement","BlockControls","group","ToolbarGroup","ToolbarButton","disabled","__experimentalIsFocusable","__"],"sources":["@wordpress/patterns/src/components/reset-overrides-control.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tstore as blockEditorStore,\n\tBlockControls,\n} from '@wordpress/block-editor';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\n\nconst CONTENT = 'content';\n\nexport default function ResetOverridesControl( props ) {\n\tconst name = props.attributes.metadata?.name;\n\tconst registry = useRegistry();\n\tconst isOverriden = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! name ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { getBlockAttributes, getBlockParentsByBlockName } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst [ patternClientId ] = getBlockParentsByBlockName(\n\t\t\t\tprops.clientId,\n\t\t\t\t'core/block',\n\t\t\t\ttrue\n\t\t\t);\n\n\t\t\tif ( ! patternClientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst overrides = getBlockAttributes( patternClientId )[ CONTENT ];\n\n\t\t\tif ( ! overrides ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\treturn overrides.hasOwnProperty( name );\n\t\t},\n\t\t[ props.clientId, name ]\n\t);\n\n\tfunction onClick() {\n\t\tconst { getBlockAttributes, getBlockParentsByBlockName } =\n\t\t\tregistry.select( blockEditorStore );\n\t\tconst [ patternClientId ] = getBlockParentsByBlockName(\n\t\t\tprops.clientId,\n\t\t\t'core/block',\n\t\t\ttrue\n\t\t);\n\n\t\tif ( ! patternClientId ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst overrides = getBlockAttributes( patternClientId )[ CONTENT ];\n\n\t\tif ( ! overrides.hasOwnProperty( name ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { updateBlockAttributes, __unstableMarkLastChangeAsPersistent } =\n\t\t\tregistry.dispatch( blockEditorStore );\n\t\t__unstableMarkLastChangeAsPersistent();\n\n\t\tlet newOverrides = { ...overrides };\n\t\tdelete newOverrides[ name ];\n\n\t\tif ( ! Object.keys( newOverrides ).length ) {\n\t\t\tnewOverrides = undefined;\n\t\t}\n\n\t\tupdateBlockAttributes( patternClientId, {\n\t\t\t[ CONTENT ]: newOverrides,\n\t\t} );\n\t}\n\n\treturn (\n\t\t<BlockControls group=\"other\">\n\t\t\t<ToolbarGroup>\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\tdisabled={ ! isOverriden }\n\t\t\t\t\t__experimentalIsFocusable\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</ToolbarGroup>\n\t\t</BlockControls>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAIA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AATA;AACA;AACA;;AASA,MAAMI,OAAO,GAAG,SAAS;AAEV,SAASC,qBAAqBA,CAAEC,KAAK,EAAG;EACtD,MAAMC,IAAI,GAAGD,KAAK,CAACE,UAAU,CAACC,QAAQ,EAAEF,IAAI;EAC5C,MAAMG,QAAQ,GAAG,IAAAC,iBAAW,EAAC,CAAC;EAC9B,MAAMC,WAAW,GAAG,IAAAC,eAAS,EAC1BC,MAAM,IAAM;IACb,IAAK,CAAEP,IAAI,EAAG;MACb;IACD;IAEA,MAAM;MAAEQ,kBAAkB;MAAEC;IAA2B,CAAC,GACvDF,MAAM,CAAEG,kBAAiB,CAAC;IAC3B,MAAM,CAAEC,eAAe,CAAE,GAAGF,0BAA0B,CACrDV,KAAK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O,GAC3B,IAAAH,MAAA,CAAAC,aAAA,EAAC/B,WAAA,CAAAkC,YAAY,QACZ,IAAAJ,MAAA,CAAAC,aAAA,EAAC/B,WAAA,CAAAmC,aAAa;IACbd,OAAO,EAAGA,OAAS;IACnBe,QAAQ,EAAG,CAAEzB,WAAa;IAC1B0B,yBAAyB;EAAA,GAEvB,IAAAC,QAAE,EAAE,OAAQ,CACA,CACF,CACA,CAAC;AAElB","ignoreList":[]}
@@ -76,6 +76,7 @@ const convertSyncedPatternToStatic = clientId => ({
76
76
  registry
77
77
  }) => {
78
78
  const patternBlock = registry.select(_blockEditor.store).getBlock(clientId);
79
+ const existingOverrides = patternBlock.attributes?.content;
79
80
  function cloneBlocksAndRemoveBindings(blocks) {
80
81
  return blocks.map(block => {
81
82
  let metadata = block.attributes.metadata;
@@ -85,13 +86,26 @@ const convertSyncedPatternToStatic = clientId => ({
85
86
  };
86
87
  delete metadata.id;
87
88
  delete metadata.bindings;
89
+ // Use overriden values of the pattern block if they exist.
90
+ if (existingOverrides[metadata.name]) {
91
+ // Iterate over each overriden attribute.
92
+ for (const [attributeName, value] of Object.entries(existingOverrides[metadata.name])) {
93
+ // Skip if the attribute does not exist in the block type.
94
+ if (!(0, _blocks.getBlockType)(block.name)?.attributes[attributeName]) {
95
+ continue;
96
+ }
97
+ // Update the block attribute with the override value.
98
+ block.attributes[attributeName] = value;
99
+ }
100
+ }
88
101
  }
89
102
  return (0, _blocks.cloneBlock)(block, {
90
103
  metadata: metadata && Object.keys(metadata).length > 0 ? metadata : undefined
91
104
  }, cloneBlocksAndRemoveBindings(block.innerBlocks));
92
105
  });
93
106
  }
94
- registry.dispatch(_blockEditor.store).replaceBlocks(patternBlock.clientId, cloneBlocksAndRemoveBindings(patternBlock.innerBlocks));
107
+ const patternInnerBlocks = registry.select(_blockEditor.store).getBlocks(patternBlock.clientId);
108
+ registry.dispatch(_blockEditor.store).replaceBlocks(patternBlock.clientId, cloneBlocksAndRemoveBindings(patternInnerBlocks));
95
109
  };
96
110
 
97
111
  /**
@@ -1 +1 @@
1
- {"version":3,"names":["_blocks","require","_coreData","_blockEditor","_constants","createPattern","title","syncType","content","categories","registry","meta","PATTERN_SYNC_TYPES","unsynced","wp_pattern_sync_status","undefined","reusableBlock","status","wp_pattern_category","updatedRecord","dispatch","coreStore","saveEntityRecord","exports","createPatternFromFile","file","fileContent","text","parsedContent","JSON","parse","e","Error","__file","syncStatus","pattern","convertSyncedPatternToStatic","clientId","patternBlock","select","blockEditorStore","getBlock","cloneBlocksAndRemoveBindings","blocks","map","block","metadata","attributes","id","bindings","cloneBlock","Object","keys","length","innerBlocks","replaceBlocks","setEditingPattern","isEditing","type"],"sources":["@wordpress/patterns/src/store/actions.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\n\nimport { 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\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}\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\tregistry\n\t\t\t.dispatch( blockEditorStore )\n\t\t\t.replaceBlocks(\n\t\t\t\tpatternBlock.clientId,\n\t\t\t\tcloneBlocksAndRemoveBindings( patternBlock.innerBlocks )\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":";;;;;;;AAIA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAKA,IAAAG,UAAA,GAAAH,OAAA;AAXA;AACA;AACA;;AAMA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMI,aAAa,GACzBA,CAAEC,KAAK,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,UAAU,KACtC,OAAQ;EAAEC;AAAS,CAAC,KAAM;EACzB,MAAMC,IAAI,GACTJ,QAAQ,KAAKK,6BAAkB,CAACC,QAAQ,GACrC;IACAC,sBAAsB,EAAEP;EACxB,CAAC,GACDQ,SAAS;EAEb,MAAMC,aAAa,GAAG;IACrBV,KAAK;IACLE,OAAO;IACPS,MAAM,EAAE,SAAS;IACjBN,IAAI;IACJO,mBAAmB,EAAET;EACtB,CAAC;EAED,MAAMU,aAAa,GAAG,MAAMT,QAAQ,CAClCU,QAAQ,CAAEC,eAAU,CAAC,CACrBC,gBAAgB,CAAE,UAAU,E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AC;EAEtB,SAASK,4BAA4BA,CAAEC,MAAM,EAAG;IAC/C,OAAOA,MAAM,CAACC,GAAG,CAAIC,KAAK,IAAM;MAC/B,IAAIC,QAAQ,GAAGD,KAAK,CAACE,UAAU,CAACD,QAAQ;MACxC,IAAKA,QAAQ,EAAG;QACfA,QAAQ,GAAG;UAAE,GAAGA;QAAS,CAAC;QAC1B,OAAOA,QAAQ,CAACE,EAAE;QAClB,OAAOF,QAAQ,CAACG,QAAQ;MACzB;MACA,OAAO,IAAAC,kBAAU,EAChBL,KAAK,EACL;QACCC,QAAQ,EACPA,QAAQ,IAAIK,MAAM,CAACC,IAAI,CAAEN,QAAS,CAAC,CAACO,MAAM,GAAG,CAAC,GAC3CP,QAAQ,GACR/B;MACL,CAAC,EACD2B,4BAA4B,CAAEG,KAAK,CAACS,WAAY,CACjD,CAAC;IACF,CAAE,CAAC;EACJ;EAEA5C,QAAQ,CACNU,QAAQ,CAAEoB,kBAAiB,CAAC,CAC5Be,aAAa,CACbjB,YAAY,CAACD,QAAQ,EACrBK,4BAA4B,CAAEJ,YAAY,CAACgB,WAAY,CACxD,CAAC;AACH,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AANA/B,OAAA,CAAAa,4BAAA,GAAAA,4BAAA;AAOO,SAASoB,iBAAiBA,CAAEnB,QAAQ,EAAEoB,SAAS,EAAG;EACxD,OAAO;IACNC,IAAI,EAAE,qBAAqB;IAC3BrB,QAAQ;IACRoB;EACD,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["_blocks","require","_coreData","_blockEditor","_constants","createPattern","title","syncType","content","categories","registry","meta","PATTERN_SYNC_TYPES","unsynced","wp_pattern_sync_status","undefined","reusableBlock","status","wp_pattern_category","updatedRecord","dispatch","coreStore","saveEntityRecord","exports","createPatternFromFile","file","fileContent","text","parsedContent","JSON","parse","e","Error","__file","syncStatus","pattern","convertSyncedPatternToStatic","clientId","patternBlock","select","blockEditorStore","getBlock","existingOverrides","attributes","cloneBlocksAndRemoveBindings","blocks","map","block","metadata","id","bindings","name","attributeName","value","Object","entries","getBlockType","cloneBlock","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":";;;;;;;AAIA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAKA,IAAAG,UAAA,GAAAH,OAAA;AAXA;AACA;AACA;;AAMA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMI,aAAa,GACzBA,CAAEC,KAAK,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,UAA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V,QAAS,CAAC,CAACW,MAAM,GAAG,CAAC,GAC3CX,QAAQ,GACRjC;MACL,CAAC,EACD6B,4BAA4B,CAAEG,KAAK,CAACa,WAAY,CACjD,CAAC;IACF,CAAE,CAAC;EACJ;EAEA,MAAMC,kBAAkB,GAAGnD,QAAQ,CACjC6B,MAAM,CAAEC,kBAAiB,CAAC,CAC1BsB,SAAS,CAAExB,YAAY,CAACD,QAAS,CAAC;EAEpC3B,QAAQ,CACNU,QAAQ,CAAEoB,kBAAiB,CAAC,CAC5BuB,aAAa,CACbzB,YAAY,CAACD,QAAQ,EACrBO,4BAA4B,CAAEiB,kBAAmB,CAClD,CAAC;AACH,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AANAtC,OAAA,CAAAa,4BAAA,GAAAA,4BAAA;AAOO,SAAS4B,iBAAiBA,CAAE3B,QAAQ,EAAE4B,SAAS,EAAG;EACxD,OAAO;IACNC,IAAI,EAAE,qBAAqB;IAC3B7B,QAAQ;IACR4B;EACD,CAAC;AACF","ignoreList":[]}
@@ -65,7 +65,9 @@ function PatternOverridesControls({
65
65
  }
66
66
 
67
67
  // Avoid overwriting other (e.g. meta) bindings.
68
- if (isConnectedToOtherSources) return null;
68
+ if (isConnectedToOtherSources) {
69
+ return null;
70
+ }
69
71
  const hasName = !!attributes.metadata?.name;
70
72
  const allowOverrides = hasName && attributeSources.some(source => source === PATTERN_OVERRIDES_BINDING_SOURCE);
71
73
  return createElement(Fragment, null, createElement(InspectorControls, {
@@ -78,6 +80,7 @@ function PatternOverridesControls({
78
80
  __next40pxDefaultSize: true,
79
81
  className: "pattern-overrides-control__allow-overrides-button",
80
82
  variant: "secondary",
83
+ "aria-haspopup": "dialog",
81
84
  onClick: () => {
82
85
  if (allowOverrides) {
83
86
  setShowDisallowOverridesModal(true);
@@ -1 +1 @@
1
- {"version":3,"names":["useState","useId","InspectorControls","BaseControl","Button","__","PARTIAL_SYNCING_SUPPORTED_BLOCKS","PATTERN_OVERRIDES_BINDING_SOURCE","AllowOverridesModal","DisallowOverridesModal","removeBindings","bindings","syncedAttributes","updatedBindings","attributeName","source","undefined","Object","keys","length","addBindings","PatternOverridesControls","attributes","name","setAttributes","controlId","showAllowOverridesModal","setShowAllowOverridesModal","showDisallowOverridesModal","setShowDisallowOverridesModal","attributeSources","map","metadata","isConnectedToOtherSources","every","updateBindings","isChecked","customName","prevBindings","updatedMetadata","hasName","allowOverrides","some","createElement","Fragment","group","id","label","help","__next40pxDefaultSize","className","variant","onClick","initialName","onClose","onSave","newName"],"sources":["@wordpress/patterns/src/components/pattern-overrides-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useId } from '@wordpress/element';\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { BaseControl, Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n\tPATTERN_OVERRIDES_BINDING_SOURCE,\n} from '../constants';\nimport {\n\tAllowOverridesModal,\n\tDisallowOverridesModal,\n} from './allow-overrides-modal';\n\nfunction removeBindings( bindings, syncedAttributes ) {\n\tlet updatedBindings = {};\n\tfor ( const attributeName of syncedAttributes ) {\n\t\t// Omit any bindings that's not the same source from the `updatedBindings` object.\n\t\tif (\n\t\t\tbindings?.[ attributeName ]?.source !==\n\t\t\t\tPATTERN_OVERRIDES_BINDING_SOURCE &&\n\t\t\tbindings?.[ attributeName ]?.source !== undefined\n\t\t) {\n\t\t\tupdatedBindings[ attributeName ] = bindings[ attributeName ];\n\t\t}\n\t}\n\tif ( ! Object.keys( updatedBindings ).length ) {\n\t\tupdatedBindings = undefined;\n\t}\n\treturn updatedBindings;\n}\n\nfunction addBindings( bindings, syncedAttributes ) {\n\tconst updatedBindings = { ...bindings };\n\tfor ( const attributeName of syncedAttributes ) {\n\t\tif ( ! bindings?.[ attributeName ] ) {\n\t\t\tupdatedBindings[ attributeName ] = {\n\t\t\t\tsource: PATTERN_OVERRIDES_BINDING_SOURCE,\n\t\t\t};\n\t\t}\n\t}\n\treturn updatedBindings;\n}\n\nfunction PatternOverridesControls( { attributes, name, setAttributes } ) {\n\tconst controlId = useId();\n\tconst [ showAllowOverridesModal, setShowAllowOverridesModal ] =\n\t\tuseState( false );\n\tconst [ showDisallowOverridesModal, setShowDisallowOverridesModal ] =\n\t\tuseState( false );\n\n\tconst syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];\n\tconst attributeSources = syncedAttributes.map(\n\t\t( attributeName ) =>\n\t\t\tattributes.metadata?.bindings?.[ attributeName ]?.source\n\t);\n\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t( source ) => source && source !== 'core/pattern-overrides'\n\t);\n\n\tfunction updateBindings( isChecked, customName ) {\n\t\tconst prevBindings = attributes?.metadata?.bindings;\n\t\tconst updatedBindings = isChecked\n\t\t\t? addBindings( prevBindings, syncedAttributes )\n\t\t\t: removeBindings( prevBindings, syncedAttributes );\n\n\t\tconst updatedMetadata = {\n\t\t\t...attributes.metadata,\n\t\t\tbindings: updatedBindings,\n\t\t};\n\n\t\tif ( customName ) {\n\t\t\tupdatedMetadata.name = customName;\n\t\t}\n\n\t\tsetAttributes( {\n\t\t\tmetadata: updatedMetadata,\n\t\t} );\n\t}\n\n\t// Avoid overwriting other (e.g. meta) bindings.\n\tif ( isConnectedToOtherSources ) return null;\n\n\tconst hasName = !! attributes.metadata?.name;\n\tconst allowOverrides =\n\t\thasName &&\n\t\tattributeSources.some(\n\t\t\t( source ) => source === PATTERN_OVERRIDES_BINDING_SOURCE\n\t\t);\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<BaseControl\n\t\t\t\t\tid={ controlId }\n\t\t\t\t\tlabel={ __( 'Overrides' ) }\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'Allow changes to this block throughout instances of this pattern.'\n\t\t\t\t\t) }\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"pattern-overrides-control__allow-overrides-button\"\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tif ( allowOverrides ) {\n\t\t\t\t\t\t\t\tsetShowDisallowOverridesModal( true );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetShowAllowOverridesModal( true );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ allowOverrides\n\t\t\t\t\t\t\t? __( 'Disable overrides' )\n\t\t\t\t\t\t\t: __( 'Enable overrides' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</BaseControl>\n\t\t\t</InspectorControls>\n\n\t\t\t{ showAllowOverridesModal && (\n\t\t\t\t<AllowOverridesModal\n\t\t\t\t\tinitialName={ attributes.metadata?.name }\n\t\t\t\t\tonClose={ () => setShowAllowOverridesModal( false ) }\n\t\t\t\t\tonSave={ ( newName ) => {\n\t\t\t\t\t\tupdateBindings( true, newName );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showDisallowOverridesModal && (\n\t\t\t\t<DisallowOverridesModal\n\t\t\t\t\tonClose={ () => setShowDisallowOverridesModal( false ) }\n\t\t\t\t\tonSave={ () => updateBindings( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PatternOverridesControls;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,KAAK,QAAQ,oBAAoB;AACpD,SAASC,iBAAiB,QAAQ,yBAAyB;AAC3D,SAASC,WAAW,EAAEC,MAAM,QAAQ,uBAAuB;AAC3D,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,SACCC,gCAAgC,EAChCC,gCAAgC,QAC1B,cAAc;AACrB,SACCC,mBAAmB,EACnBC,sBAAsB,QAChB,yBAAyB;A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A,CAAA,KAAM;MACf,IAAKX,cAAc,EAAG;QACrBZ,6BAA6B,CAAE,IAAK,CAAC;MACtC,CAAC,MAAM;QACNF,0BAA0B,CAAE,IAAK,CAAC;MACnC;IACD;EAAG,GAEDc,cAAc,GACbpC,EAAE,CAAE,mBAAoB,CAAC,GACzBA,EAAE,CAAE,kBAAmB,CACnB,CACI,CACK,CAAC,EAElBqB,uBAAuB,IACxBiB,aAAA,CAACnC,mBAAmB;IACnB6C,WAAW,EAAG/B,UAAU,CAACU,QAAQ,EAAET,IAAM;IACzC+B,OAAO,EAAGA,CAAA,KAAM3B,0BAA0B,CAAE,KAAM,CAAG;IACrD4B,MAAM,EAAKC,OAAO,IAAM;MACvBrB,cAAc,CAAE,IAAI,EAAEqB,OAAQ,CAAC;IAChC;EAAG,CACH,CACD,EACC5B,0BAA0B,IAC3Be,aAAA,CAAClC,sBAAsB;IACtB6C,OAAO,EAAGA,CAAA,KAAMzB,6BAA6B,CAAE,KAAM,CAAG;IACxD0B,MAAM,EAAGA,CAAA,KAAMpB,cAAc,CAAE,KAAM;EAAG,CACxC,CAED,CAAC;AAEL;AAEA,eAAed,wBAAwB","ignoreList":[]}
1
+ {"version":3,"names":["useState","useId","InspectorControls","BaseControl","Button","__","PARTIAL_SYNCING_SUPPORTED_BLOCKS","PATTERN_OVERRIDES_BINDING_SOURCE","AllowOverridesModal","DisallowOverridesModal","removeBindings","bindings","syncedAttributes","updatedBindings","attributeName","source","undefined","Object","keys","length","addBindings","PatternOverridesControls","attributes","name","setAttributes","controlId","showAllowOverridesModal","setShowAllowOverridesModal","showDisallowOverridesModal","setShowDisallowOverridesModal","attributeSources","map","metadata","isConnectedToOtherSources","every","updateBindings","isChecked","customName","prevBindings","updatedMetadata","hasName","allowOverrides","some","createElement","Fragment","group","id","label","help","__next40pxDefaultSize","className","variant","onClick","initialName","onClose","onSave","newName"],"sources":["@wordpress/patterns/src/components/pattern-overrides-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useId } from '@wordpress/element';\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { BaseControl, Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n\tPATTERN_OVERRIDES_BINDING_SOURCE,\n} from '../constants';\nimport {\n\tAllowOverridesModal,\n\tDisallowOverridesModal,\n} from './allow-overrides-modal';\n\nfunction removeBindings( bindings, syncedAttributes ) {\n\tlet updatedBindings = {};\n\tfor ( const attributeName of syncedAttributes ) {\n\t\t// Omit any bindings that's not the same source from the `updatedBindings` object.\n\t\tif (\n\t\t\tbindings?.[ attributeName ]?.source !==\n\t\t\t\tPATTERN_OVERRIDES_BINDING_SOURCE &&\n\t\t\tbindings?.[ attributeName ]?.source !== undefined\n\t\t) {\n\t\t\tupdatedBindings[ attributeName ] = bindings[ attributeName ];\n\t\t}\n\t}\n\tif ( ! Object.keys( updatedBindings ).length ) {\n\t\tupdatedBindings = undefined;\n\t}\n\treturn updatedBindings;\n}\n\nfunction addBindings( bindings, syncedAttributes ) {\n\tconst updatedBindings = { ...bindings };\n\tfor ( const attributeName of syncedAttributes ) {\n\t\tif ( ! bindings?.[ attributeName ] ) {\n\t\t\tupdatedBindings[ attributeName ] = {\n\t\t\t\tsource: PATTERN_OVERRIDES_BINDING_SOURCE,\n\t\t\t};\n\t\t}\n\t}\n\treturn updatedBindings;\n}\n\nfunction PatternOverridesControls( { attributes, name, setAttributes } ) {\n\tconst controlId = useId();\n\tconst [ showAllowOverridesModal, setShowAllowOverridesModal ] =\n\t\tuseState( false );\n\tconst [ showDisallowOverridesModal, setShowDisallowOverridesModal ] =\n\t\tuseState( false );\n\n\tconst syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];\n\tconst attributeSources = syncedAttributes.map(\n\t\t( attributeName ) =>\n\t\t\tattributes.metadata?.bindings?.[ attributeName ]?.source\n\t);\n\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t( source ) => source && source !== 'core/pattern-overrides'\n\t);\n\n\tfunction updateBindings( isChecked, customName ) {\n\t\tconst prevBindings = attributes?.metadata?.bindings;\n\t\tconst updatedBindings = isChecked\n\t\t\t? addBindings( prevBindings, syncedAttributes )\n\t\t\t: removeBindings( prevBindings, syncedAttributes );\n\n\t\tconst updatedMetadata = {\n\t\t\t...attributes.metadata,\n\t\t\tbindings: updatedBindings,\n\t\t};\n\n\t\tif ( customName ) {\n\t\t\tupdatedMetadata.name = customName;\n\t\t}\n\n\t\tsetAttributes( {\n\t\t\tmetadata: updatedMetadata,\n\t\t} );\n\t}\n\n\t// Avoid overwriting other (e.g. meta) bindings.\n\tif ( isConnectedToOtherSources ) {\n\t\treturn null;\n\t}\n\n\tconst hasName = !! attributes.metadata?.name;\n\tconst allowOverrides =\n\t\thasName &&\n\t\tattributeSources.some(\n\t\t\t( source ) => source === PATTERN_OVERRIDES_BINDING_SOURCE\n\t\t);\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<BaseControl\n\t\t\t\t\tid={ controlId }\n\t\t\t\t\tlabel={ __( 'Overrides' ) }\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'Allow changes to this block throughout instances of this pattern.'\n\t\t\t\t\t) }\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"pattern-overrides-control__allow-overrides-button\"\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tif ( allowOverrides ) {\n\t\t\t\t\t\t\t\tsetShowDisallowOverridesModal( true );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetShowAllowOverridesModal( true );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ allowOverrides\n\t\t\t\t\t\t\t? __( 'Disable overrides' )\n\t\t\t\t\t\t\t: __( 'Enable overrides' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</BaseControl>\n\t\t\t</InspectorControls>\n\n\t\t\t{ showAllowOverridesModal && (\n\t\t\t\t<AllowOverridesModal\n\t\t\t\t\tinitialName={ attributes.metadata?.name }\n\t\t\t\t\tonClose={ () => setShowAllowOverridesModal( false ) }\n\t\t\t\t\tonSave={ ( newName ) => {\n\t\t\t\t\t\tupdateBindings( true, newName );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showDisallowOverridesModal && (\n\t\t\t\t<DisallowOverridesModal\n\t\t\t\t\tonClose={ () => setShowDisallowOverridesModal( false ) }\n\t\t\t\t\tonSave={ () => updateBindings( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PatternOverridesControls;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,KAAK,QAAQ,oBAAoB;AACpD,SAASC,iBAAiB,QAAQ,yBAAyB;AAC3D,SAASC,WAAW,EAAEC,MAAM,QAAQ,uBAAuB;AAC3D,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,SACCC,gCAAgC,EAChCC,gCAAgC,QAC1B,cAAc;AACrB,SACCC,mBAAmB,EACnBC,sBAAsB,QAChB,yBAAyB;AAEhC,SAASC,cAAcA,CAAEC,QAAQ,EAAEC,gBAAgB,EAAG;EACrD,IAAIC,eAAe,GAAG,CAAC,CAAC;EACxB,KAAM,MAAMC,aAAa,IAAIF,gBAAgB,EAAG;IAC/C;IACA,IACCD,QAAQ,GAAIG,aAAa,CAAE,EAAEC,MAAM,KAClCR,gCAAgC,IACjCI,QAAQ,GAAIG,aAAa,CAAE,EAAEC,MAAM,KAAKC,SAAS,EAChD;MACDH,eAAe,CAAEC,aAAa,CAAE,GAAGH,QAAQ,CAAEG,aAAa,CAAE;IAC7D;EACD;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,EAAET,IAAM;IACzC+B,OAAO,EAAGA,CAAA,KAAM3B,0BAA0B,CAAE,KAAM,CAAG;IACrD4B,MAAM,EAAKC,OAAO,IAAM;MACvBrB,cAAc,CAAE,IAAI,EAAEqB,OAAQ,CAAC;IAChC;EAAG,CACH,CACD,EACC5B,0BAA0B,IAC3Be,aAAA,CAAClC,sBAAsB;IACtB6C,OAAO,EAAGA,CAAA,KAAMzB,6BAA6B,CAAE,KAAM,CAAG;IACxD0B,MAAM,EAAGA,CAAA,KAAMpB,cAAc,CAAE,KAAM;EAAG,CACxC,CAED,CAAC;AAEL;AAEA,eAAed,wBAAwB","ignoreList":[]}
@@ -26,14 +26,12 @@ function PatternsManageButton({
26
26
  const {
27
27
  getBlock,
28
28
  canRemoveBlock,
29
- getBlockCount,
30
- getSettings
29
+ getBlockCount
31
30
  } = select(blockEditorStore);
32
31
  const {
33
32
  canUser
34
33
  } = select(coreStore);
35
34
  const reusableBlock = getBlock(clientId);
36
- const isBlockTheme = getSettings().__unstableIsBlockBasedTheme;
37
35
  return {
38
36
  canRemove: canRemoveBlock(clientId),
39
37
  isVisible: !!reusableBlock && isReusableBlock(reusableBlock) && !!canUser('update', 'blocks', reusableBlock.attributes.ref),
@@ -41,7 +39,7 @@ function PatternsManageButton({
41
39
  // The site editor and templates both check whether the user
42
40
  // has edit_theme_options capabilities. We can leverage that here
43
41
  // and omit the manage patterns link if the user can't access it.
44
- managePatternsUrl: isBlockTheme && canUser('read', 'templates') ? addQueryArgs('site-editor.php', {
42
+ managePatternsUrl: canUser('create', 'templates') ? addQueryArgs('site-editor.php', {
45
43
  path: '/patterns'
46
44
  }) : addQueryArgs('edit.php', {
47
45
  post_type: 'wp_block'
@@ -1 +1 @@
1
- {"version":3,"names":["MenuItem","__","isReusableBlock","useSelect","useDispatch","store","blockEditorStore","addQueryArgs","coreStore","patternsStore","unlock","PatternsManageButton","clientId","canRemove","isVisible","managePatternsUrl","select","getBlock","canRemoveBlock","getBlockCount","getSettings","canUser","reusableBlock","isBlockTheme","__unstableIsBlockBasedTheme","attributes","ref","innerBlockCount","path","post_type","convertSyncedPatternToStatic","createElement","Fragment","onClick","href"],"sources":["@wordpress/patterns/src/components/patterns-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nfunction PatternsManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount, getSettings } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\t\t\tconst isBlockTheme = getSettings().__unstableIsBlockBasedTheme;\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser(\n\t\t\t\t\t\t'update',\n\t\t\t\t\t\t'blocks',\n\t\t\t\t\t\treusableBlock.attributes.ref\n\t\t\t\t\t),\n\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\tmanagePatternsUrl:\n\t\t\t\t\tisBlockTheme && canUser( 'read', 'templates' )\n\t\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\t\tpath: '/patterns',\n\t\t\t\t\t\t } )\n\t\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t\t } ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { convertSyncedPatternToStatic } = unlock(\n\t\tuseDispatch( patternsStore )\n\t);\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ canRemove && (\n\t\t\t\t<MenuItem\n\t\t\t\t\tonClick={ () => convertSyncedPatternToStatic( clientId ) }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Detach' ) }\n\t\t\t\t</MenuItem>\n\t\t\t) }\n\t\t\t<MenuItem href={ managePatternsUrl }>\n\t\t\t\t{ __( 'Manage patterns' ) }\n\t\t\t</MenuItem>\n\t\t</>\n\t);\n}\n\nexport default PatternsManageButton;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASF,KAAK,IAAIG,SAAS,QAAQ,sBAAsB;;AAEzD;AACA;AACA;AACA,SAASH,KAAK,IAAII,aAAa,QAAQ,UAAU;AACjD,SAASC,MAAM,QAAQ,gBAAgB;AAEvC,SAASC,oBAAoBA,CAAE;EAAEC;AAAS,CAAC,EAAG;EAC7C,MAAM;IAAEC,SAAS;IAAEC,SAAS;IAAEC;EAAkB,CAAC,GAAGZ,SAAS,CAC1Da,MAAM,IAAM;IACb,MAAM;MAAEC,QAAQ;MAAEC,cAAc;MAAEC,aAAa;MAAEC;IAAY,CAAC,GAC7D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names":["MenuItem","__","isReusableBlock","useSelect","useDispatch","store","blockEditorStore","addQueryArgs","coreStore","patternsStore","unlock","PatternsManageButton","clientId","canRemove","isVisible","managePatternsUrl","select","getBlock","canRemoveBlock","getBlockCount","canUser","reusableBlock","attributes","ref","innerBlockCount","path","post_type","convertSyncedPatternToStatic","createElement","Fragment","onClick","href"],"sources":["@wordpress/patterns/src/components/patterns-manage-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { isReusableBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as patternsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nfunction PatternsManageButton( { clientId } ) {\n\tconst { canRemove, isVisible, managePatternsUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, canRemoveBlock, getBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { canUser } = select( coreStore );\n\t\t\tconst reusableBlock = getBlock( clientId );\n\n\t\t\treturn {\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tisVisible:\n\t\t\t\t\t!! reusableBlock &&\n\t\t\t\t\tisReusableBlock( reusableBlock ) &&\n\t\t\t\t\t!! canUser(\n\t\t\t\t\t\t'update',\n\t\t\t\t\t\t'blocks',\n\t\t\t\t\t\treusableBlock.attributes.ref\n\t\t\t\t\t),\n\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t// The site editor and templates both check whether the user\n\t\t\t\t// has edit_theme_options capabilities. We can leverage that here\n\t\t\t\t// and omit the manage patterns link if the user can't access it.\n\t\t\t\tmanagePatternsUrl: canUser( 'create', 'templates' )\n\t\t\t\t\t? addQueryArgs( 'site-editor.php', {\n\t\t\t\t\t\t\tpath: '/patterns',\n\t\t\t\t\t } )\n\t\t\t\t\t: addQueryArgs( 'edit.php', {\n\t\t\t\t\t\t\tpost_type: 'wp_block',\n\t\t\t\t\t } ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\t// Ignore reason: false positive of the lint rule.\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { convertSyncedPatternToStatic } = unlock(\n\t\tuseDispatch( patternsStore )\n\t);\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ canRemove && (\n\t\t\t\t<MenuItem\n\t\t\t\t\tonClick={ () => convertSyncedPatternToStatic( clientId ) }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Detach' ) }\n\t\t\t\t</MenuItem>\n\t\t\t) }\n\t\t\t<MenuItem href={ managePatternsUrl }>\n\t\t\t\t{ __( 'Manage patterns' ) }\n\t\t\t</MenuItem>\n\t\t</>\n\t);\n}\n\nexport default PatternsManageButton;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASF,KAAK,IAAIG,SAAS,QAAQ,sBAAsB;;AAEzD;AACA;AACA;AACA,SAASH,KAAK,IAAII,aAAa,QAAQ,UAAU;AACjD,SAASC,MAAM,QAAQ,gBAAgB;AAEvC,SAASC,oBAAoBA,CAAE;EAAEC;AAAS,CAAC,EAAG;EAC7C,MAAM;IAAEC,SAAS;IAAEC,SAAS;IAAEC;EAAkB,CAAC,GAAGZ,SAAS,CAC1Da,MAAM,IAAM;IACb,MAAM;MAAEC,QAAQ;MAAEC,cAAc;MAAEC;IAAc,CAAC,GAChDH,MAAM,CAAEV,gBAAiB,CAAC;IAC3B,MAAM;MAAEc;IAAQ,CAAC,GAAGJ,MAAM,CAAER,SAAU,CAAC;IACvC,MAAMa,aAAa,GAAGJ,QAAQ,CAAEL,QAAS,CAAC;IAE1C,OAAO;MACNC,SAAS,EAAEK,cAAc,CAAEN,QAAS,CAAC;MACrCE,SAAS,EACR,CAAC,CAAEO,aAAa,IAChBnB,eAAe,CAAEmB,aAAc,CAAC,IAChC,CAAC,CAAED,OAAO,CACT,QAAQ,EACR,QAAQ,EACRC,aAAa,CAACC,UAAU,CAACC,GAC1B,CAAC;MACFC,eAAe,EAAEL,aAAa,CAAEP,QAAS,CAAC;MAC1C;MACA;MACA;MACAG,iBAAiB,EAAEK,OAAO,CAAE,QAAQ,EAAE,WAAY,CAAC,GAChDb,YAAY,CAAE,iBAAiB,EAAE;QACjCkB,IAAI,EAAE;MACN,CAAE,CAAC,GACHlB,YAAY,CAAE,UAAU,EAAE;QAC1BmB,SAAS,EAAE;MACX,CAAE;IACN,CAAC;EACF,CAAC,EACD,CAAEd,QAAQ,CACX,CAAC;;EAED;EACA;EACA,MAAM;IAAEe;EAA6B,CAAC,GAAGjB,MAAM,CAC9CN,WAAW,CAAEK,aAAc,CAC5B,CAAC;EAED,IAAK,CAAEK,SAAS,EAAG;IAClB,OAAO,IAAI;EACZ;EAEA,OACCc,aAAA,CAAAC,QAAA,QACGhB,SAAS,IACVe,aAAA,CAAC5B,QAAQ;IACR8B,OAAO,EAAGA,CAAA,KAAMH,4BAA4B,CAAEf,QAAS;EAAG,GAExDX,EAAE,CAAE,QAAS,CACN,CACV,EACD2B,aAAA,CAAC5B,QAAQ;IAAC+B,IAAI,EAAGhB;EAAmB,GACjCd,EAAE,CAAE,iBAAkB,CACf,CACT,CAAC;AAEL;AAEA,eAAeU,oBAAoB","ignoreList":[]}
@@ -4,55 +4,64 @@ import { createElement } from "react";
4
4
  */
5
5
  import { store as blockEditorStore, BlockControls } from '@wordpress/block-editor';
6
6
  import { ToolbarButton, ToolbarGroup } from '@wordpress/components';
7
- import { useSelect, useRegistry } from '@wordpress/data';
8
- import { store as coreStore } from '@wordpress/core-data';
9
- import { parse } from '@wordpress/blocks';
7
+ import { useRegistry, useSelect } from '@wordpress/data';
10
8
  import { __ } from '@wordpress/i18n';
11
- function recursivelyFindBlockWithName(blocks, name) {
12
- for (const block of blocks) {
13
- if (block.attributes.metadata?.name === name) {
14
- return block;
15
- }
16
- const found = recursivelyFindBlockWithName(block.innerBlocks, name);
17
- if (found) {
18
- return found;
19
- }
20
- }
21
- }
9
+ const CONTENT = 'content';
22
10
  export default function ResetOverridesControl(props) {
23
- const registry = useRegistry();
24
11
  const name = props.attributes.metadata?.name;
25
- const patternWithOverrides = useSelect(select => {
12
+ const registry = useRegistry();
13
+ const isOverriden = useSelect(select => {
26
14
  if (!name) {
27
- return undefined;
15
+ return;
28
16
  }
29
17
  const {
30
- getBlockParentsByBlockName,
31
- getBlocksByClientId
18
+ getBlockAttributes,
19
+ getBlockParentsByBlockName
32
20
  } = select(blockEditorStore);
33
- const patternBlock = getBlocksByClientId(getBlockParentsByBlockName(props.clientId, 'core/block'))[0];
34
- if (!patternBlock?.attributes.content?.[name]) {
35
- return undefined;
21
+ const [patternClientId] = getBlockParentsByBlockName(props.clientId, 'core/block', true);
22
+ if (!patternClientId) {
23
+ return;
24
+ }
25
+ const overrides = getBlockAttributes(patternClientId)[CONTENT];
26
+ if (!overrides) {
27
+ return;
36
28
  }
37
- return patternBlock;
29
+ return overrides.hasOwnProperty(name);
38
30
  }, [props.clientId, name]);
39
- const resetOverrides = async () => {
40
- var _editedRecord$blocks;
41
- const editedRecord = await registry.resolveSelect(coreStore).getEditedEntityRecord('postType', 'wp_block', patternWithOverrides.attributes.ref);
42
- const blocks = (_editedRecord$blocks = editedRecord.blocks) !== null && _editedRecord$blocks !== void 0 ? _editedRecord$blocks : parse(editedRecord.content);
43
- const block = recursivelyFindBlockWithName(blocks, name);
44
- const newAttributes = Object.assign(
45
- // Reset every existing attribute to undefined.
46
- Object.fromEntries(Object.keys(props.attributes).map(key => [key, undefined])),
47
- // Then assign the original attributes.
48
- block.attributes);
49
- props.setAttributes(newAttributes);
50
- };
31
+ function onClick() {
32
+ const {
33
+ getBlockAttributes,
34
+ getBlockParentsByBlockName
35
+ } = registry.select(blockEditorStore);
36
+ const [patternClientId] = getBlockParentsByBlockName(props.clientId, 'core/block', true);
37
+ if (!patternClientId) {
38
+ return;
39
+ }
40
+ const overrides = getBlockAttributes(patternClientId)[CONTENT];
41
+ if (!overrides.hasOwnProperty(name)) {
42
+ return;
43
+ }
44
+ const {
45
+ updateBlockAttributes,
46
+ __unstableMarkLastChangeAsPersistent
47
+ } = registry.dispatch(blockEditorStore);
48
+ __unstableMarkLastChangeAsPersistent();
49
+ let newOverrides = {
50
+ ...overrides
51
+ };
52
+ delete newOverrides[name];
53
+ if (!Object.keys(newOverrides).length) {
54
+ newOverrides = undefined;
55
+ }
56
+ updateBlockAttributes(patternClientId, {
57
+ [CONTENT]: newOverrides
58
+ });
59
+ }
51
60
  return createElement(BlockControls, {
52
61
  group: "other"
53
62
  }, createElement(ToolbarGroup, null, createElement(ToolbarButton, {
54
- onClick: resetOverrides,
55
- disabled: !patternWithOverrides,
63
+ onClick: onClick,
64
+ disabled: !isOverriden,
56
65
  __experimentalIsFocusable: true
57
66
  }, __('Reset'))));
58
67
  }
@@ -1 +1 @@
1
- {"version":3,"names":["store","blockEditorStore","BlockControls","ToolbarButton","ToolbarGroup","useSelect","useRegistry","coreStore","parse","__","recursivelyFindBlockWithName","blocks","name","block","attributes","metadata","found","innerBlocks","ResetOverridesControl","props","registry","patternWithOverrides","select","undefined","getBlockParentsByBlockName","getBlocksByClientId","patternBlock","clientId","content","resetOverrides","_editedRecord$blocks","editedRecord","resolveSelect","getEditedEntityRecord","ref","newAttributes","Object","assign","fromEntries","keys","map","key","setAttributes","createElement","group","onClick","disabled","__experimentalIsFocusable"],"sources":["@wordpress/patterns/src/components/reset-overrides-control.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tstore as blockEditorStore,\n\tBlockControls,\n} from '@wordpress/block-editor';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { useSelect, useRegistry } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { parse } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\nfunction recursivelyFindBlockWithName( blocks, name ) {\n\tfor ( const block of blocks ) {\n\t\tif ( block.attributes.metadata?.name === name ) {\n\t\t\treturn block;\n\t\t}\n\n\t\tconst found = recursivelyFindBlockWithName( block.innerBlocks, name );\n\t\tif ( found ) {\n\t\t\treturn found;\n\t\t}\n\t}\n}\n\nexport default function ResetOverridesControl( props ) {\n\tconst registry = useRegistry();\n\tconst name = props.attributes.metadata?.name;\n\tconst patternWithOverrides = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! name ) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst { getBlockParentsByBlockName, getBlocksByClientId } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst patternBlock = getBlocksByClientId(\n\t\t\t\tgetBlockParentsByBlockName( props.clientId, 'core/block' )\n\t\t\t)[ 0 ];\n\n\t\t\tif ( ! patternBlock?.attributes.content?.[ name ] ) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\treturn patternBlock;\n\t\t},\n\t\t[ props.clientId, name ]\n\t);\n\n\tconst resetOverrides = async () => {\n\t\tconst editedRecord = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_block',\n\t\t\t\tpatternWithOverrides.attributes.ref\n\t\t\t);\n\t\tconst blocks = editedRecord.blocks ?? parse( editedRecord.content );\n\t\tconst block = recursivelyFindBlockWithName( blocks, name );\n\n\t\tconst newAttributes = Object.assign(\n\t\t\t// Reset every existing attribute to undefined.\n\t\t\tObject.fromEntries(\n\t\t\t\tObject.keys( props.attributes ).map( ( key ) => [\n\t\t\t\t\tkey,\n\t\t\t\t\tundefined,\n\t\t\t\t] )\n\t\t\t),\n\t\t\t// Then assign the original attributes.\n\t\t\tblock.attributes\n\t\t);\n\n\t\tprops.setAttributes( newAttributes );\n\t};\n\n\treturn (\n\t\t<BlockControls group=\"other\">\n\t\t\t<ToolbarGroup>\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tonClick={ resetOverrides }\n\t\t\t\t\tdisabled={ ! patternWithOverrides }\n\t\t\t\t\t__experimentalIsFocusable\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</ToolbarGroup>\n\t\t</BlockControls>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,KAAK,IAAIC,gBAAgB,EACzBC,aAAa,QACP,yBAAyB;AAChC,SAASC,aAAa,EAAEC,YAAY,QAAQ,uBAAuB;AACnE,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASN,KAAK,IAAIO,SAAS,QAAQ,sBAAsB;AACzD,SAASC,KAAK,QAAQ,mBAAmB;AACzC,SAASC,EAAE,QAAQ,iBAAiB;AAEpC,SAASC,4BAA4BA,CAAEC,MAAM,EAAEC,IAAI,EAAG;EACrD,KAAM,MAAMC,KAAK,IAAIF,MAAM,EAAG;IAC7B,IAAKE,KAAK,CAACC,UAAU,CAACC,QAAQ,EAAEH,IAAI,KAAKA,IAAI,EAAG;MAC/C,OAAOC,KAAK;IACb;IAEA,MAAMG,KAAK,GAAGN,4BAA4B,CAAEG,KAAK,CAACI,WAAW,EAAEL,IAAK,CAAC;IACrE,IAAKI,KAAK,EAAG;MACZ,OAAOA,KAAK;IACb;EACD;AACD;AAEA,eAAe,SAASE,qBAAqBA,CAAEC,KAAK,EAAG;EACtD,MAAMC,QAAQ,GAAGd,WAAW,CAAC,CAAC;EAC9B,MAAMM,IAAI,GAAGO,KAAK,CAACL,U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CAACuB,aAAa,CAAEP,aAAc,CAAC;EACrC,CAAC;EAED,OACCQ,aAAA,CAACzC,aAAa;IAAC0C,KAAK,EAAC;EAAO,GAC3BD,aAAA,CAACvC,YAAY,QACZuC,aAAA,CAACxC,aAAa;IACb0C,OAAO,EAAGhB,cAAgB;IAC1BiB,QAAQ,EAAG,CAAEzB,oBAAsB;IACnC0B,yBAAyB;EAAA,GAEvBtC,EAAE,CAAE,OAAQ,CACA,CACF,CACA,CAAC;AAElB","ignoreList":[]}
1
+ {"version":3,"names":["store","blockEditorStore","BlockControls","ToolbarButton","ToolbarGroup","useRegistry","useSelect","__","CONTENT","ResetOverridesControl","props","name","attributes","metadata","registry","isOverriden","select","getBlockAttributes","getBlockParentsByBlockName","patternClientId","clientId","overrides","hasOwnProperty","onClick","updateBlockAttributes","__unstableMarkLastChangeAsPersistent","dispatch","newOverrides","Object","keys","length","undefined","createElement","group","disabled","__experimentalIsFocusable"],"sources":["@wordpress/patterns/src/components/reset-overrides-control.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tstore as blockEditorStore,\n\tBlockControls,\n} from '@wordpress/block-editor';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\n\nconst CONTENT = 'content';\n\nexport default function ResetOverridesControl( props ) {\n\tconst name = props.attributes.metadata?.name;\n\tconst registry = useRegistry();\n\tconst isOverriden = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! name ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { getBlockAttributes, getBlockParentsByBlockName } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst [ patternClientId ] = getBlockParentsByBlockName(\n\t\t\t\tprops.clientId,\n\t\t\t\t'core/block',\n\t\t\t\ttrue\n\t\t\t);\n\n\t\t\tif ( ! patternClientId ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst overrides = getBlockAttributes( patternClientId )[ CONTENT ];\n\n\t\t\tif ( ! overrides ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\treturn overrides.hasOwnProperty( name );\n\t\t},\n\t\t[ props.clientId, name ]\n\t);\n\n\tfunction onClick() {\n\t\tconst { getBlockAttributes, getBlockParentsByBlockName } =\n\t\t\tregistry.select( blockEditorStore );\n\t\tconst [ patternClientId ] = getBlockParentsByBlockName(\n\t\t\tprops.clientId,\n\t\t\t'core/block',\n\t\t\ttrue\n\t\t);\n\n\t\tif ( ! patternClientId ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst overrides = getBlockAttributes( patternClientId )[ CONTENT ];\n\n\t\tif ( ! overrides.hasOwnProperty( name ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { updateBlockAttributes, __unstableMarkLastChangeAsPersistent } =\n\t\t\tregistry.dispatch( blockEditorStore );\n\t\t__unstableMarkLastChangeAsPersistent();\n\n\t\tlet newOverrides = { ...overrides };\n\t\tdelete newOverrides[ name ];\n\n\t\tif ( ! Object.keys( newOverrides ).length ) {\n\t\t\tnewOverrides = undefined;\n\t\t}\n\n\t\tupdateBlockAttributes( patternClientId, {\n\t\t\t[ CONTENT ]: newOverrides,\n\t\t} );\n\t}\n\n\treturn (\n\t\t<BlockControls group=\"other\">\n\t\t\t<ToolbarGroup>\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\tdisabled={ ! isOverriden }\n\t\t\t\t\t__experimentalIsFocusable\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t</ToolbarButton>\n\t\t\t</ToolbarGroup>\n\t\t</BlockControls>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,KAAK,IAAIC,gBAAgB,EACzBC,aAAa,QACP,yBAAyB;AAChC,SAASC,aAAa,EAAEC,YAAY,QAAQ,uBAAuB;AACnE,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,E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CAAC,GACpEX,QAAQ,CAACY,QAAQ,CAAEzB,gBAAiB,CAAC;IACtCwB,oCAAoC,CAAC,CAAC;IAEtC,IAAIE,YAAY,GAAG;MAAE,GAAGN;IAAU,CAAC;IACnC,OAAOM,YAAY,CAAEhB,IAAI,CAAE;IAE3B,IAAK,CAAEiB,MAAM,CAACC,IAAI,CAAEF,YAAa,CAAC,CAACG,MAAM,EAAG;MAC3CH,YAAY,GAAGI,SAAS;IACzB;IAEAP,qBAAqB,CAAEL,eAAe,EAAE;MACvC,CAAEX,OAAO,GAAImB;IACd,CAAE,CAAC;EACJ;EAEA,OACCK,aAAA,CAAC9B,aAAa;IAAC+B,KAAK,EAAC;EAAO,GAC3BD,aAAA,CAAC5B,YAAY,QACZ4B,aAAA,CAAC7B,aAAa;IACboB,OAAO,EAAGA,OAAS;IACnBW,QAAQ,EAAG,CAAEnB,WAAa;IAC1BoB,yBAAyB;EAAA,GAEvB5B,EAAE,CAAE,OAAQ,CACA,CACF,CACA,CAAC;AAElB","ignoreList":[]}
@@ -2,7 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
 
5
- import { cloneBlock } from '@wordpress/blocks';
5
+ import { getBlockType, cloneBlock } from '@wordpress/blocks';
6
6
  import { store as coreStore } from '@wordpress/core-data';
7
7
  import { store as blockEditorStore } from '@wordpress/block-editor';
8
8
 
@@ -68,6 +68,7 @@ export const convertSyncedPatternToStatic = clientId => ({
68
68
  registry
69
69
  }) => {
70
70
  const patternBlock = registry.select(blockEditorStore).getBlock(clientId);
71
+ const existingOverrides = patternBlock.attributes?.content;
71
72
  function cloneBlocksAndRemoveBindings(blocks) {
72
73
  return blocks.map(block => {
73
74
  let metadata = block.attributes.metadata;
@@ -77,13 +78,26 @@ export const convertSyncedPatternToStatic = clientId => ({
77
78
  };
78
79
  delete metadata.id;
79
80
  delete metadata.bindings;
81
+ // Use overriden values of the pattern block if they exist.
82
+ if (existingOverrides[metadata.name]) {
83
+ // Iterate over each overriden attribute.
84
+ for (const [attributeName, value] of Object.entries(existingOverrides[metadata.name])) {
85
+ // Skip if the attribute does not exist in the block type.
86
+ if (!getBlockType(block.name)?.attributes[attributeName]) {
87
+ continue;
88
+ }
89
+ // Update the block attribute with the override value.
90
+ block.attributes[attributeName] = value;
91
+ }
92
+ }
80
93
  }
81
94
  return cloneBlock(block, {
82
95
  metadata: metadata && Object.keys(metadata).length > 0 ? metadata : undefined
83
96
  }, cloneBlocksAndRemoveBindings(block.innerBlocks));
84
97
  });
85
98
  }
86
- registry.dispatch(blockEditorStore).replaceBlocks(patternBlock.clientId, cloneBlocksAndRemoveBindings(patternBlock.innerBlocks));
99
+ const patternInnerBlocks = registry.select(blockEditorStore).getBlocks(patternBlock.clientId);
100
+ registry.dispatch(blockEditorStore).replaceBlocks(patternBlock.clientId, cloneBlocksAndRemoveBindings(patternInnerBlocks));
87
101
  };
88
102
 
89
103
  /**
@@ -1 +1 @@
1
- {"version":3,"names":["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","cloneBlocksAndRemoveBindings","blocks","map","block","metadata","attributes","id","bindings","Object","keys","length","innerBlocks","replaceBlocks","setEditingPattern","isEditing","type"],"sources":["@wordpress/patterns/src/store/actions.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\n\nimport { 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\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}\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\tregistry\n\t\t\t.dispatch( blockEditorStore )\n\t\t\t.replaceBlocks(\n\t\t\t\tpatternBlock.clientId,\n\t\t\t\tcloneBlocksAndRemoveBindings( patternBlock.innerBlocks )\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,UAAU,QAAQ,mBAAmB;AAC9C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASD,KAAK,IAAIE,gBAAgB,QAAQ,yBAAyB;;AAEnE;AACA;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AEjB,QAAQ,EAAEkB,SAAS,EAAG;EACxD,OAAO;IACNC,IAAI,EAAE,qBAAqB;IAC3BnB,QAAQ;IACRkB;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 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 setE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C,MAAM,CAACC,OAAO,CACrDb,iBAAiB,CAAEM,QAAQ,CAACG,IAAI,CACjC,CAAC,EAAG;YACH;YACA,IACC,CAAEhD,YAAY,CAAE4C,KAAK,CAACI,IAAK,CAAC,EAAER,UAAU,CACvCS,aAAa,CACb,EACA;cACD;YACD;YACA;YACAL,KAAK,CAACJ,UAAU,CAAES,aAAa,CAAE,GAAGC,KAAK;UAC1C;QACD;MACD;MACA,OAAOjD,UAAU,CAChB2C,KAAK,EACL;QACCC,QAAQ,EACPA,QAAQ,IAAIM,MAAM,CAACE,IAAI,CAAER,QAAS,CAAC,CAACS,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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/patterns",
3
- "version": "1.17.0",
3
+ "version": "1.19.0",
4
4
  "description": "Management of user pattern editing.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -31,20 +31,20 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "@babel/runtime": "^7.16.0",
34
- "@wordpress/a11y": "^3.56.0",
35
- "@wordpress/block-editor": "^12.24.0",
36
- "@wordpress/blocks": "^12.33.0",
37
- "@wordpress/components": "^27.4.0",
38
- "@wordpress/compose": "^6.33.0",
39
- "@wordpress/core-data": "^6.33.0",
40
- "@wordpress/data": "^9.26.0",
41
- "@wordpress/element": "^5.33.0",
42
- "@wordpress/html-entities": "^3.56.0",
43
- "@wordpress/i18n": "^4.56.0",
44
- "@wordpress/icons": "^9.47.0",
45
- "@wordpress/notices": "^4.24.0",
46
- "@wordpress/private-apis": "^0.38.0",
47
- "@wordpress/url": "^3.57.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"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "react": "^18.0.0",
@@ -53,5 +53,5 @@
53
53
  "publishConfig": {
54
54
  "access": "public"
55
55
  },
56
- "gitHead": "280403b4c1cf6cc2c55a6c4d56f9ef91145e4191"
56
+ "gitHead": "42f38f287506a6b3ed8ccba839b18ad066821044"
57
57
  }
@@ -85,7 +85,9 @@ function PatternOverridesControls( { attributes, name, setAttributes } ) {
85
85
  }
86
86
 
87
87
  // Avoid overwriting other (e.g. meta) bindings.
88
- if ( isConnectedToOtherSources ) return null;
88
+ if ( isConnectedToOtherSources ) {
89
+ return null;
90
+ }
89
91
 
90
92
  const hasName = !! attributes.metadata?.name;
91
93
  const allowOverrides =
@@ -108,6 +110,7 @@ function PatternOverridesControls( { attributes, name, setAttributes } ) {
108
110
  __next40pxDefaultSize
109
111
  className="pattern-overrides-control__allow-overrides-button"
110
112
  variant="secondary"
113
+ aria-haspopup="dialog"
111
114
  onClick={ () => {
112
115
  if ( allowOverrides ) {
113
116
  setShowDisallowOverridesModal( true );
@@ -18,11 +18,10 @@ import { unlock } from '../lock-unlock';
18
18
  function PatternsManageButton( { clientId } ) {
19
19
  const { canRemove, isVisible, managePatternsUrl } = useSelect(
20
20
  ( select ) => {
21
- const { getBlock, canRemoveBlock, getBlockCount, getSettings } =
21
+ const { getBlock, canRemoveBlock, getBlockCount } =
22
22
  select( blockEditorStore );
23
23
  const { canUser } = select( coreStore );
24
24
  const reusableBlock = getBlock( clientId );
25
- const isBlockTheme = getSettings().__unstableIsBlockBasedTheme;
26
25
 
27
26
  return {
28
27
  canRemove: canRemoveBlock( clientId ),
@@ -38,14 +37,13 @@ function PatternsManageButton( { clientId } ) {
38
37
  // The site editor and templates both check whether the user
39
38
  // has edit_theme_options capabilities. We can leverage that here
40
39
  // and omit the manage patterns link if the user can't access it.
41
- managePatternsUrl:
42
- isBlockTheme && canUser( 'read', 'templates' )
43
- ? addQueryArgs( 'site-editor.php', {
44
- path: '/patterns',
45
- } )
46
- : addQueryArgs( 'edit.php', {
47
- post_type: 'wp_block',
48
- } ),
40
+ managePatternsUrl: canUser( 'create', 'templates' )
41
+ ? addQueryArgs( 'site-editor.php', {
42
+ path: '/patterns',
43
+ } )
44
+ : addQueryArgs( 'edit.php', {
45
+ post_type: 'wp_block',
46
+ } ),
49
47
  };
50
48
  },
51
49
  [ clientId ]
@@ -6,80 +6,84 @@ import {
6
6
  BlockControls,
7
7
  } from '@wordpress/block-editor';
8
8
  import { ToolbarButton, ToolbarGroup } from '@wordpress/components';
9
- import { useSelect, useRegistry } from '@wordpress/data';
10
- import { store as coreStore } from '@wordpress/core-data';
11
- import { parse } from '@wordpress/blocks';
9
+ import { useRegistry, useSelect } from '@wordpress/data';
12
10
  import { __ } from '@wordpress/i18n';
13
11
 
14
- function recursivelyFindBlockWithName( blocks, name ) {
15
- for ( const block of blocks ) {
16
- if ( block.attributes.metadata?.name === name ) {
17
- return block;
18
- }
19
-
20
- const found = recursivelyFindBlockWithName( block.innerBlocks, name );
21
- if ( found ) {
22
- return found;
23
- }
24
- }
25
- }
12
+ const CONTENT = 'content';
26
13
 
27
14
  export default function ResetOverridesControl( props ) {
28
- const registry = useRegistry();
29
15
  const name = props.attributes.metadata?.name;
30
- const patternWithOverrides = useSelect(
16
+ const registry = useRegistry();
17
+ const isOverriden = useSelect(
31
18
  ( select ) => {
32
19
  if ( ! name ) {
33
- return undefined;
20
+ return;
34
21
  }
35
22
 
36
- const { getBlockParentsByBlockName, getBlocksByClientId } =
23
+ const { getBlockAttributes, getBlockParentsByBlockName } =
37
24
  select( blockEditorStore );
38
- const patternBlock = getBlocksByClientId(
39
- getBlockParentsByBlockName( props.clientId, 'core/block' )
40
- )[ 0 ];
25
+ const [ patternClientId ] = getBlockParentsByBlockName(
26
+ props.clientId,
27
+ 'core/block',
28
+ true
29
+ );
30
+
31
+ if ( ! patternClientId ) {
32
+ return;
33
+ }
34
+
35
+ const overrides = getBlockAttributes( patternClientId )[ CONTENT ];
41
36
 
42
- if ( ! patternBlock?.attributes.content?.[ name ] ) {
43
- return undefined;
37
+ if ( ! overrides ) {
38
+ return;
44
39
  }
45
40
 
46
- return patternBlock;
41
+ return overrides.hasOwnProperty( name );
47
42
  },
48
43
  [ props.clientId, name ]
49
44
  );
50
45
 
51
- const resetOverrides = async () => {
52
- const editedRecord = await registry
53
- .resolveSelect( coreStore )
54
- .getEditedEntityRecord(
55
- 'postType',
56
- 'wp_block',
57
- patternWithOverrides.attributes.ref
58
- );
59
- const blocks = editedRecord.blocks ?? parse( editedRecord.content );
60
- const block = recursivelyFindBlockWithName( blocks, name );
61
-
62
- const newAttributes = Object.assign(
63
- // Reset every existing attribute to undefined.
64
- Object.fromEntries(
65
- Object.keys( props.attributes ).map( ( key ) => [
66
- key,
67
- undefined,
68
- ] )
69
- ),
70
- // Then assign the original attributes.
71
- block.attributes
46
+ function onClick() {
47
+ const { getBlockAttributes, getBlockParentsByBlockName } =
48
+ registry.select( blockEditorStore );
49
+ const [ patternClientId ] = getBlockParentsByBlockName(
50
+ props.clientId,
51
+ 'core/block',
52
+ true
72
53
  );
73
54
 
74
- props.setAttributes( newAttributes );
75
- };
55
+ if ( ! patternClientId ) {
56
+ return;
57
+ }
58
+
59
+ const overrides = getBlockAttributes( patternClientId )[ CONTENT ];
60
+
61
+ if ( ! overrides.hasOwnProperty( name ) ) {
62
+ return;
63
+ }
64
+
65
+ const { updateBlockAttributes, __unstableMarkLastChangeAsPersistent } =
66
+ registry.dispatch( blockEditorStore );
67
+ __unstableMarkLastChangeAsPersistent();
68
+
69
+ let newOverrides = { ...overrides };
70
+ delete newOverrides[ name ];
71
+
72
+ if ( ! Object.keys( newOverrides ).length ) {
73
+ newOverrides = undefined;
74
+ }
75
+
76
+ updateBlockAttributes( patternClientId, {
77
+ [ CONTENT ]: newOverrides,
78
+ } );
79
+ }
76
80
 
77
81
  return (
78
82
  <BlockControls group="other">
79
83
  <ToolbarGroup>
80
84
  <ToolbarButton
81
- onClick={ resetOverrides }
82
- disabled={ ! patternWithOverrides }
85
+ onClick={ onClick }
86
+ disabled={ ! isOverriden }
83
87
  __experimentalIsFocusable
84
88
  >
85
89
  { __( 'Reset' ) }
@@ -2,7 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
 
5
- import { cloneBlock } from '@wordpress/blocks';
5
+ import { getBlockType, cloneBlock } from '@wordpress/blocks';
6
6
  import { store as coreStore } from '@wordpress/core-data';
7
7
  import { store as blockEditorStore } from '@wordpress/block-editor';
8
8
 
@@ -93,6 +93,7 @@ export const convertSyncedPatternToStatic =
93
93
  const patternBlock = registry
94
94
  .select( blockEditorStore )
95
95
  .getBlock( clientId );
96
+ const existingOverrides = patternBlock.attributes?.content;
96
97
 
97
98
  function cloneBlocksAndRemoveBindings( blocks ) {
98
99
  return blocks.map( ( block ) => {
@@ -101,6 +102,24 @@ export const convertSyncedPatternToStatic =
101
102
  metadata = { ...metadata };
102
103
  delete metadata.id;
103
104
  delete metadata.bindings;
105
+ // Use overriden values of the pattern block if they exist.
106
+ if ( existingOverrides[ metadata.name ] ) {
107
+ // Iterate over each overriden attribute.
108
+ for ( const [ attributeName, value ] of Object.entries(
109
+ existingOverrides[ metadata.name ]
110
+ ) ) {
111
+ // Skip if the attribute does not exist in the block type.
112
+ if (
113
+ ! getBlockType( block.name )?.attributes[
114
+ attributeName
115
+ ]
116
+ ) {
117
+ continue;
118
+ }
119
+ // Update the block attribute with the override value.
120
+ block.attributes[ attributeName ] = value;
121
+ }
122
+ }
104
123
  }
105
124
  return cloneBlock(
106
125
  block,
@@ -115,11 +134,15 @@ export const convertSyncedPatternToStatic =
115
134
  } );
116
135
  }
117
136
 
137
+ const patternInnerBlocks = registry
138
+ .select( blockEditorStore )
139
+ .getBlocks( patternBlock.clientId );
140
+
118
141
  registry
119
142
  .dispatch( blockEditorStore )
120
143
  .replaceBlocks(
121
144
  patternBlock.clientId,
122
- cloneBlocksAndRemoveBindings( patternBlock.innerBlocks )
145
+ cloneBlocksAndRemoveBindings( patternInnerBlocks )
123
146
  );
124
147
  };
125
148