@wordpress/patterns 1.14.0 → 1.15.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,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.15.0 (2024-03-21)
6
+
5
7
  ## 1.14.0 (2024-03-06)
6
8
 
7
9
  ## 1.13.0 (2024-02-21)
@@ -5,8 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = useSetPatternBindings;
7
7
  var _compose = require("@wordpress/compose");
8
+ var _blocks = require("@wordpress/blocks");
8
9
  var _element = require("@wordpress/element");
10
+ var _data = require("@wordpress/data");
9
11
  var _constants = require("../constants");
12
+ var _lockUnlock = require("../lock-unlock");
10
13
  /**
11
14
  * WordPress dependencies
12
15
  */
@@ -47,13 +50,22 @@ function useSetPatternBindings({
47
50
  setAttributes
48
51
  }, currentPostType) {
49
52
  var _attributes$metadata$, _usePrevious;
53
+ const hasPatternOverridesSource = (0, _data.useSelect)(select => {
54
+ const {
55
+ getBlockBindingsSource
56
+ } = (0, _lockUnlock.unlock)(select(_blocks.store));
57
+
58
+ // For editing link to the site editor if the theme and user permissions support it.
59
+ return !!getBlockBindingsSource('core/pattern-overrides');
60
+ }, []);
50
61
  const metadataName = (_attributes$metadata$ = attributes?.metadata?.name) !== null && _attributes$metadata$ !== void 0 ? _attributes$metadata$ : '';
51
62
  const prevMetadataName = (_usePrevious = (0, _compose.usePrevious)(metadataName)) !== null && _usePrevious !== void 0 ? _usePrevious : '';
52
63
  const bindings = attributes?.metadata?.bindings;
53
64
  (0, _element.useEffect)(() => {
54
65
  // Bindings should only be created when editing a wp_block post type,
55
66
  // and also when there's a change to the user-given name for the block.
56
- if (currentPostType !== 'wp_block' || metadataName === prevMetadataName) {
67
+ // Also check that the pattern overrides source is registered.
68
+ if (!hasPatternOverridesSource || currentPostType !== 'wp_block' || metadataName === prevMetadataName) {
57
69
  return;
58
70
  }
59
71
  const syncedAttributes = _constants.PARTIAL_SYNCING_SUPPORTED_BLOCKS[name];
@@ -86,6 +98,6 @@ function useSetPatternBindings({
86
98
  }
87
99
  });
88
100
  }
89
- }, [bindings, prevMetadataName, metadataName, currentPostType, name, attributes.metadata, setAttributes]);
101
+ }, [hasPatternOverridesSource, bindings, prevMetadataName, metadataName, currentPostType, name, attributes.metadata, setAttributes]);
90
102
  }
91
103
  //# sourceMappingURL=use-set-pattern-bindings.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_compose","require","_element","_constants","removeBindings","bindings","syncedAttributes","updatedBindings","attributeName","source","undefined","Object","keys","length","addBindings","useSetPatternBindings","name","attributes","setAttributes","currentPostType","_attributes$metadata$","_usePrevious","metadataName","metadata","prevMetadataName","usePrevious","useEffect","PARTIAL_SYNCING_SUPPORTED_BLOCKS","attributeSources","map","isConnectedToOtherSources","every"],"sources":["@wordpress/patterns/src/components/use-set-pattern-bindings.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { usePrevious } from '@wordpress/compose';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';\n\nfunction removeBindings( bindings, syncedAttributes ) {\n\tlet updatedBindings = {};\n\tfor ( const attributeName of syncedAttributes ) {\n\t\t// Omit any pattern override bindings from the `updatedBindings` object.\n\t\tif (\n\t\t\tbindings?.[ attributeName ]?.source !== 'core/pattern-overrides' &&\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: 'core/pattern-overrides',\n\t\t\t};\n\t\t}\n\t}\n\treturn updatedBindings;\n}\n\nexport default function useSetPatternBindings(\n\t{ name, attributes, setAttributes },\n\tcurrentPostType\n) {\n\tconst metadataName = attributes?.metadata?.name ?? '';\n\tconst prevMetadataName = usePrevious( metadataName ) ?? '';\n\tconst bindings = attributes?.metadata?.bindings;\n\n\tuseEffect( () => {\n\t\t// Bindings should only be created when editing a wp_block post type,\n\t\t// and also when there's a change to the user-given name for the block.\n\t\tif (\n\t\t\tcurrentPostType !== 'wp_block' ||\n\t\t\tmetadataName === prevMetadataName\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];\n\t\tconst attributeSources = syncedAttributes.map(\n\t\t\t( attributeName ) =>\n\t\t\t\tattributes.metadata?.bindings?.[ attributeName ]?.source\n\t\t);\n\t\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t\t( source ) => source && source !== 'core/pattern-overrides'\n\t\t);\n\n\t\t// Avoid overwriting other (e.g. meta) bindings.\n\t\tif ( isConnectedToOtherSources ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The user-given name for the block was deleted, remove the bindings.\n\t\tif ( ! metadataName?.length && prevMetadataName?.length ) {\n\t\t\tconst updatedBindings = removeBindings(\n\t\t\t\tbindings,\n\t\t\t\tsyncedAttributes\n\t\t\t);\n\t\t\tsetAttributes( {\n\t\t\t\tmetadata: {\n\t\t\t\t\t...attributes.metadata,\n\t\t\t\t\tbindings: updatedBindings,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\t// The user-given name for the block was set, set the bindings.\n\t\tif ( ! prevMetadataName?.length && metadataName.length ) {\n\t\t\tconst updatedBindings = addBindings( bindings, syncedAttributes );\n\t\t\tsetAttributes( {\n\t\t\t\tmetadata: {\n\t\t\t\t\t...attributes.metadata,\n\t\t\t\t\tbindings: updated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,CAACM,QAAQ;UACtBlB,QAAQ,EAAEE;QACX;MACD,CAAE,CAAC;IACJ;EACD,CAAC,EAAE,CACFF,QAAQ,EACRmB,gBAAgB,EAChBF,YAAY,EACZH,eAAe,EACfH,IAAI,EACJC,UAAU,CAACM,QAAQ,EACnBL,aAAa,CACZ,CAAC;AACJ"}
1
+ {"version":3,"names":["_compose","require","_blocks","_element","_data","_constants","_lockUnlock","removeBindings","bindings","syncedAttributes","updatedBindings","attributeName","source","undefined","Object","keys","length","addBindings","useSetPatternBindings","name","attributes","setAttributes","currentPostType","_attributes$metadata$","_usePrevious","hasPatternOverridesSource","useSelect","select","getBlockBindingsSource","unlock","blocksStore","metadataName","metadata","prevMetadataName","usePrevious","useEffect","PARTIAL_SYNCING_SUPPORTED_BLOCKS","attributeSources","map","isConnectedToOtherSources","every"],"sources":["@wordpress/patterns/src/components/use-set-pattern-bindings.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { usePrevious } from '@wordpress/compose';\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { useEffect } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';\n\nimport { unlock } from '../lock-unlock';\n\nfunction removeBindings( bindings, syncedAttributes ) {\n\tlet updatedBindings = {};\n\tfor ( const attributeName of syncedAttributes ) {\n\t\t// Omit any pattern override bindings from the `updatedBindings` object.\n\t\tif (\n\t\t\tbindings?.[ attributeName ]?.source !== 'core/pattern-overrides' &&\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: 'core/pattern-overrides',\n\t\t\t};\n\t\t}\n\t}\n\treturn updatedBindings;\n}\n\nexport default function useSetPatternBindings(\n\t{ name, attributes, setAttributes },\n\tcurrentPostType\n) {\n\tconst hasPatternOverridesSource = useSelect( ( select ) => {\n\t\tconst { getBlockBindingsSource } = unlock( select( blocksStore ) );\n\n\t\t// For editing link to the site editor if the theme and user permissions support it.\n\t\treturn !! getBlockBindingsSource( 'core/pattern-overrides' );\n\t}, [] );\n\n\tconst metadataName = attributes?.metadata?.name ?? '';\n\tconst prevMetadataName = usePrevious( metadataName ) ?? '';\n\tconst bindings = attributes?.metadata?.bindings;\n\n\tuseEffect( () => {\n\t\t// Bindings should only be created when editing a wp_block post type,\n\t\t// and also when there's a change to the user-given name for the block.\n\t\t// Also check that the pattern overrides source is registered.\n\t\tif (\n\t\t\t! hasPatternOverridesSource ||\n\t\t\tcurrentPostType !== 'wp_block' ||\n\t\t\tmetadataName === prevMetadataName\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];\n\t\tconst attributeSources = syncedAttributes.map(\n\t\t\t( attributeName ) =>\n\t\t\t\tattributes.metadata?.bindings?.[ attributeName ]?.source\n\t\t);\n\t\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t\t( source ) => source && source !== 'core/pattern-overrides'\n\t\t);\n\n\t\t// Avoid overwriting other (e.g. meta) bindings.\n\t\tif ( isConnectedToOtherSources ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The user-given name for the block was deleted, remove the bindings.\n\t\tif ( ! metadataName?.length && prevMetadataName?.length ) {\n\t\t\tconst updatedBindings = removeBindings(\n\t\t\t\tbindings,\n\t\t\t\tsyncedAttributes\n\t\t\t);\n\t\t\tsetAttributes( {\n\t\t\t\tmetadata: {\n\t\t\t\t\t...attributes.metadata,\n\t\t\t\t\tbindings: updatedBindings,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\t// The user-given name for the block was set, set the bindings.\n\t\tif ( ! prevMetadataName?.length && metadataName.length ) {\n\t\t\tconst updatedBindings = addBindings( bindings, syncedAttributes );\n\t\t\tsetAttributes( {\n\t\t\t\tmetadata: {\n\t\t\t\t\t...attributes.metadata,\n\t\t\t\t\tbindings: updatedBindings,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\t}, [\n\t\thasPatternOverridesSource,\n\t\tbindings,\n\t\tprevMetadataName,\n\t\tmetadataName,\n\t\tcurrentPostType,\n\t\tname,\n\t\tattributes.metadata,\n\t\tsetAttributes,\n\t] );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,UAAA,GAAAJ,OAAA;AAEA,IAAAK,WAAA,GAAAL,OAAA;AAbA;AACA;AACA;;AAMA;AACA;AACA;;AAKA,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,KAAK,wBAAwB,IAChEJ,QAAQ,GAAIG,aAAa,CAAE,EAAEC,MAAM,KAAKC,SAAS,EAChD;MACDH,eAAe,CAAEC,aAAa,CAAE,GAAGH,QAAQ,CAAEG,aAAa,CAAE;IAC7D;EACD;EACA,IAAK,CAAEG,MAAM,CAACC,IAAI,CAAEL,eAAgB,CAAC,CAACM,MAAM,EAAG;IAC9CN,eAAe,GAAGG,SAAS;EAC5B;EACA,OAAOH,eAAe;AACvB;AAEA,SAASO,WAAWA,CAAET,QAAQ,EAAEC,gBAAgB,EAAG;EAClD,MAAMC,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,CAAE,EAAEC,MACpD,CAAC;IACD,MAAM2B,yBAAyB,GAAGF,gBAAgB,CAACG,KAAK,CACrD5B,MAAM,IAAMA,MAAM,IAAIA,MAAM,KAAK,wBACpC,CAAC;;IAED;IACA,IAAK2B,yBAAyB,EAAG;MAChC;IACD;;IAEA;IACA,IAAK,CAAER,YAAY,EAAEf,MAAM,IAAIiB,gBAAgB,EAAEjB,MAAM,EAAG;MACzD,MAAMN,eAAe,GAAGH,cAAc,CACrCC,QAAQ,EACRC,gBACD,CAAC;MACDY,aAAa,CAAE;QACdW,QAAQ,EAAE;UACT,GAAGZ,UAAU,CAACY,QAAQ;UACtBxB,QAAQ,EAAEE;QACX;MACD,CAAE,CAAC;IACJ;;IAEA;IACA,IAAK,CAAEuB,gBAAgB,EAAEjB,MAAM,IAAIe,YAAY,CAACf,MAAM,EAAG;MACxD,MAAMN,eAAe,GAAGO,WAAW,CAAET,QAAQ,EAAEC,gBAAiB,CAAC;MACjEY,aAAa,CAAE;QACdW,QAAQ,EAAE;UACT,GAAGZ,UAAU,CAACY,QAAQ;UACtBxB,QAAQ,EAAEE;QACX;MACD,CAAE,CAAC;IACJ;EACD,CAAC,EAAE,CACFe,yBAAyB,EACzBjB,QAAQ,EACRyB,gBAAgB,EAChBF,YAAY,EACZT,eAAe,EACfH,IAAI,EACJC,UAAU,CAACY,QAAQ,EACnBX,aAAa,CACZ,CAAC;AACJ"}
@@ -2,12 +2,15 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { usePrevious } from '@wordpress/compose';
5
+ import { store as blocksStore } from '@wordpress/blocks';
5
6
  import { useEffect } from '@wordpress/element';
7
+ import { useSelect } from '@wordpress/data';
6
8
 
7
9
  /**
8
10
  * Internal dependencies
9
11
  */
10
12
  import { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';
13
+ import { unlock } from '../lock-unlock';
11
14
  function removeBindings(bindings, syncedAttributes) {
12
15
  let updatedBindings = {};
13
16
  for (const attributeName of syncedAttributes) {
@@ -40,13 +43,22 @@ export default function useSetPatternBindings({
40
43
  setAttributes
41
44
  }, currentPostType) {
42
45
  var _attributes$metadata$, _usePrevious;
46
+ const hasPatternOverridesSource = useSelect(select => {
47
+ const {
48
+ getBlockBindingsSource
49
+ } = unlock(select(blocksStore));
50
+
51
+ // For editing link to the site editor if the theme and user permissions support it.
52
+ return !!getBlockBindingsSource('core/pattern-overrides');
53
+ }, []);
43
54
  const metadataName = (_attributes$metadata$ = attributes?.metadata?.name) !== null && _attributes$metadata$ !== void 0 ? _attributes$metadata$ : '';
44
55
  const prevMetadataName = (_usePrevious = usePrevious(metadataName)) !== null && _usePrevious !== void 0 ? _usePrevious : '';
45
56
  const bindings = attributes?.metadata?.bindings;
46
57
  useEffect(() => {
47
58
  // Bindings should only be created when editing a wp_block post type,
48
59
  // and also when there's a change to the user-given name for the block.
49
- if (currentPostType !== 'wp_block' || metadataName === prevMetadataName) {
60
+ // Also check that the pattern overrides source is registered.
61
+ if (!hasPatternOverridesSource || currentPostType !== 'wp_block' || metadataName === prevMetadataName) {
50
62
  return;
51
63
  }
52
64
  const syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[name];
@@ -79,6 +91,6 @@ export default function useSetPatternBindings({
79
91
  }
80
92
  });
81
93
  }
82
- }, [bindings, prevMetadataName, metadataName, currentPostType, name, attributes.metadata, setAttributes]);
94
+ }, [hasPatternOverridesSource, bindings, prevMetadataName, metadataName, currentPostType, name, attributes.metadata, setAttributes]);
83
95
  }
84
96
  //# sourceMappingURL=use-set-pattern-bindings.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["usePrevious","useEffect","PARTIAL_SYNCING_SUPPORTED_BLOCKS","removeBindings","bindings","syncedAttributes","updatedBindings","attributeName","source","undefined","Object","keys","length","addBindings","useSetPatternBindings","name","attributes","setAttributes","currentPostType","_attributes$metadata$","_usePrevious","metadataName","metadata","prevMetadataName","attributeSources","map","isConnectedToOtherSources","every"],"sources":["@wordpress/patterns/src/components/use-set-pattern-bindings.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { usePrevious } from '@wordpress/compose';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';\n\nfunction removeBindings( bindings, syncedAttributes ) {\n\tlet updatedBindings = {};\n\tfor ( const attributeName of syncedAttributes ) {\n\t\t// Omit any pattern override bindings from the `updatedBindings` object.\n\t\tif (\n\t\t\tbindings?.[ attributeName ]?.source !== 'core/pattern-overrides' &&\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: 'core/pattern-overrides',\n\t\t\t};\n\t\t}\n\t}\n\treturn updatedBindings;\n}\n\nexport default function useSetPatternBindings(\n\t{ name, attributes, setAttributes },\n\tcurrentPostType\n) {\n\tconst metadataName = attributes?.metadata?.name ?? '';\n\tconst prevMetadataName = usePrevious( metadataName ) ?? '';\n\tconst bindings = attributes?.metadata?.bindings;\n\n\tuseEffect( () => {\n\t\t// Bindings should only be created when editing a wp_block post type,\n\t\t// and also when there's a change to the user-given name for the block.\n\t\tif (\n\t\t\tcurrentPostType !== 'wp_block' ||\n\t\t\tmetadataName === prevMetadataName\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];\n\t\tconst attributeSources = syncedAttributes.map(\n\t\t\t( attributeName ) =>\n\t\t\t\tattributes.metadata?.bindings?.[ attributeName ]?.source\n\t\t);\n\t\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t\t( source ) => source && source !== 'core/pattern-overrides'\n\t\t);\n\n\t\t// Avoid overwriting other (e.g. meta) bindings.\n\t\tif ( isConnectedToOtherSources ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The user-given name for the block was deleted, remove the bindings.\n\t\tif ( ! metadataName?.length && prevMetadataName?.length ) {\n\t\t\tconst updatedBindings = removeBindings(\n\t\t\t\tbindings,\n\t\t\t\tsyncedAttributes\n\t\t\t);\n\t\t\tsetAttributes( {\n\t\t\t\tmetadata: {\n\t\t\t\t\t...attributes.metadata,\n\t\t\t\t\tbindings: updatedBindings,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\t// The user-given name for the block was set, set the bindings.\n\t\tif ( ! prevMetadataName?.length && metadataName.length ) {\n\t\t\tconst updatedBindings = addBindings( bindings, syncedAttributes );\n\t\t\tsetAttributes( {\n\t\t\t\tmetadata: {\n\t\t\t\t\t...attributes.metadata,\n\t\t\t\t\tbindings: updatedBindings,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\t}, [\n\t\tbindings,\n\t\tprevMetadataName,\n\t\tmetadataName,\n\t\tcurrentPostType,\n\t\tname,\n\t\tattributes.metadata,\n\t\tsetAttributes,\n\t] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,oBAAoB;AAChD,SAASC,SAAS,QAAQ,oBAAoB;;AAE9C;AACA;AACA;AACA,SAASC,gCAAgC,QAAQ,cAAc;AAE/D,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,KAAK,wBAAwB,IAChEJ,QAAQ,GAAIG,aAAa,CAAE,EAAEC,MAAM,KAAKC,SAAS,EAChD;MACDH,eAAe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ACpD,CAAC;IACD,MAAMkB,yBAAyB,GAAGF,gBAAgB,CAACG,KAAK,CACrDnB,MAAM,IAAMA,MAAM,IAAIA,MAAM,KAAK,wBACpC,CAAC;;IAED;IACA,IAAKkB,yBAAyB,EAAG;MAChC;IACD;;IAEA;IACA,IAAK,CAAEL,YAAY,EAAET,MAAM,IAAIW,gBAAgB,EAAEX,MAAM,EAAG;MACzD,MAAMN,eAAe,GAAGH,cAAc,CACrCC,QAAQ,EACRC,gBACD,CAAC;MACDY,aAAa,CAAE;QACdK,QAAQ,EAAE;UACT,GAAGN,UAAU,CAACM,QAAQ;UACtBlB,QAAQ,EAAEE;QACX;MACD,CAAE,CAAC;IACJ;;IAEA;IACA,IAAK,CAAEiB,gBAAgB,EAAEX,MAAM,IAAIS,YAAY,CAACT,MAAM,EAAG;MACxD,MAAMN,eAAe,GAAGO,WAAW,CAAET,QAAQ,EAAEC,gBAAiB,CAAC;MACjEY,aAAa,CAAE;QACdK,QAAQ,EAAE;UACT,GAAGN,UAAU,CAACM,QAAQ;UACtBlB,QAAQ,EAAEE;QACX;MACD,CAAE,CAAC;IACJ;EACD,CAAC,EAAE,CACFF,QAAQ,EACRmB,gBAAgB,EAChBF,YAAY,EACZH,eAAe,EACfH,IAAI,EACJC,UAAU,CAACM,QAAQ,EACnBL,aAAa,CACZ,CAAC;AACJ"}
1
+ {"version":3,"names":["usePrevious","store","blocksStore","useEffect","useSelect","PARTIAL_SYNCING_SUPPORTED_BLOCKS","unlock","removeBindings","bindings","syncedAttributes","updatedBindings","attributeName","source","undefined","Object","keys","length","addBindings","useSetPatternBindings","name","attributes","setAttributes","currentPostType","_attributes$metadata$","_usePrevious","hasPatternOverridesSource","select","getBlockBindingsSource","metadataName","metadata","prevMetadataName","attributeSources","map","isConnectedToOtherSources","every"],"sources":["@wordpress/patterns/src/components/use-set-pattern-bindings.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { usePrevious } from '@wordpress/compose';\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { useEffect } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';\n\nimport { unlock } from '../lock-unlock';\n\nfunction removeBindings( bindings, syncedAttributes ) {\n\tlet updatedBindings = {};\n\tfor ( const attributeName of syncedAttributes ) {\n\t\t// Omit any pattern override bindings from the `updatedBindings` object.\n\t\tif (\n\t\t\tbindings?.[ attributeName ]?.source !== 'core/pattern-overrides' &&\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: 'core/pattern-overrides',\n\t\t\t};\n\t\t}\n\t}\n\treturn updatedBindings;\n}\n\nexport default function useSetPatternBindings(\n\t{ name, attributes, setAttributes },\n\tcurrentPostType\n) {\n\tconst hasPatternOverridesSource = useSelect( ( select ) => {\n\t\tconst { getBlockBindingsSource } = unlock( select( blocksStore ) );\n\n\t\t// For editing link to the site editor if the theme and user permissions support it.\n\t\treturn !! getBlockBindingsSource( 'core/pattern-overrides' );\n\t}, [] );\n\n\tconst metadataName = attributes?.metadata?.name ?? '';\n\tconst prevMetadataName = usePrevious( metadataName ) ?? '';\n\tconst bindings = attributes?.metadata?.bindings;\n\n\tuseEffect( () => {\n\t\t// Bindings should only be created when editing a wp_block post type,\n\t\t// and also when there's a change to the user-given name for the block.\n\t\t// Also check that the pattern overrides source is registered.\n\t\tif (\n\t\t\t! hasPatternOverridesSource ||\n\t\t\tcurrentPostType !== 'wp_block' ||\n\t\t\tmetadataName === prevMetadataName\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];\n\t\tconst attributeSources = syncedAttributes.map(\n\t\t\t( attributeName ) =>\n\t\t\t\tattributes.metadata?.bindings?.[ attributeName ]?.source\n\t\t);\n\t\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t\t( source ) => source && source !== 'core/pattern-overrides'\n\t\t);\n\n\t\t// Avoid overwriting other (e.g. meta) bindings.\n\t\tif ( isConnectedToOtherSources ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The user-given name for the block was deleted, remove the bindings.\n\t\tif ( ! metadataName?.length && prevMetadataName?.length ) {\n\t\t\tconst updatedBindings = removeBindings(\n\t\t\t\tbindings,\n\t\t\t\tsyncedAttributes\n\t\t\t);\n\t\t\tsetAttributes( {\n\t\t\t\tmetadata: {\n\t\t\t\t\t...attributes.metadata,\n\t\t\t\t\tbindings: updatedBindings,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\t// The user-given name for the block was set, set the bindings.\n\t\tif ( ! prevMetadataName?.length && metadataName.length ) {\n\t\t\tconst updatedBindings = addBindings( bindings, syncedAttributes );\n\t\t\tsetAttributes( {\n\t\t\t\tmetadata: {\n\t\t\t\t\t...attributes.metadata,\n\t\t\t\t\tbindings: updatedBindings,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\t}, [\n\t\thasPatternOverridesSource,\n\t\tbindings,\n\t\tprevMetadataName,\n\t\tmetadataName,\n\t\tcurrentPostType,\n\t\tname,\n\t\tattributes.metadata,\n\t\tsetAttributes,\n\t] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,oBAAoB;AAChD,SAASC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACxD,SAASC,SAAS,QAAQ,oBAAoB;AAC9C,SAASC,SAAS,QAAQ,iBAAiB;;AAE3C;AACA;AACA;AACA,SAASC,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ACT,GAAGT,UAAU,CAACS,QAAQ;UACtBrB,QAAQ,EAAEE;QACX;MACD,CAAE,CAAC;IACJ;EACD,CAAC,EAAE,CACFe,yBAAyB,EACzBjB,QAAQ,EACRsB,gBAAgB,EAChBF,YAAY,EACZN,eAAe,EACfH,IAAI,EACJC,UAAU,CAACS,QAAQ,EACnBR,aAAa,CACZ,CAAC;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/patterns",
3
- "version": "1.14.0",
3
+ "version": "1.15.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.53.0",
35
- "@wordpress/block-editor": "^12.21.0",
36
- "@wordpress/blocks": "^12.30.0",
37
- "@wordpress/components": "^27.1.0",
38
- "@wordpress/compose": "^6.30.0",
39
- "@wordpress/core-data": "^6.30.0",
40
- "@wordpress/data": "^9.23.0",
41
- "@wordpress/element": "^5.30.0",
42
- "@wordpress/html-entities": "^3.53.0",
43
- "@wordpress/i18n": "^4.53.0",
44
- "@wordpress/icons": "^9.44.0",
45
- "@wordpress/notices": "^4.21.0",
46
- "@wordpress/private-apis": "^0.35.0",
47
- "@wordpress/url": "^3.54.0"
34
+ "@wordpress/a11y": "^3.54.0",
35
+ "@wordpress/block-editor": "^12.22.0",
36
+ "@wordpress/blocks": "^12.31.0",
37
+ "@wordpress/components": "^27.2.0",
38
+ "@wordpress/compose": "^6.31.0",
39
+ "@wordpress/core-data": "^6.31.0",
40
+ "@wordpress/data": "^9.24.0",
41
+ "@wordpress/element": "^5.31.0",
42
+ "@wordpress/html-entities": "^3.54.0",
43
+ "@wordpress/i18n": "^4.54.0",
44
+ "@wordpress/icons": "^9.45.0",
45
+ "@wordpress/notices": "^4.22.0",
46
+ "@wordpress/private-apis": "^0.36.0",
47
+ "@wordpress/url": "^3.55.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": "ac3c3e465a083081a86a4da6ee6fb817b41e5130"
56
+ "gitHead": "ffc07735d0abfb3f69e91d48f25b7fe8d1ef92d2"
57
57
  }
@@ -2,13 +2,17 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { usePrevious } from '@wordpress/compose';
5
+ import { store as blocksStore } from '@wordpress/blocks';
5
6
  import { useEffect } from '@wordpress/element';
7
+ import { useSelect } from '@wordpress/data';
6
8
 
7
9
  /**
8
10
  * Internal dependencies
9
11
  */
10
12
  import { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';
11
13
 
14
+ import { unlock } from '../lock-unlock';
15
+
12
16
  function removeBindings( bindings, syncedAttributes ) {
13
17
  let updatedBindings = {};
14
18
  for ( const attributeName of syncedAttributes ) {
@@ -42,6 +46,13 @@ export default function useSetPatternBindings(
42
46
  { name, attributes, setAttributes },
43
47
  currentPostType
44
48
  ) {
49
+ const hasPatternOverridesSource = useSelect( ( select ) => {
50
+ const { getBlockBindingsSource } = unlock( select( blocksStore ) );
51
+
52
+ // For editing link to the site editor if the theme and user permissions support it.
53
+ return !! getBlockBindingsSource( 'core/pattern-overrides' );
54
+ }, [] );
55
+
45
56
  const metadataName = attributes?.metadata?.name ?? '';
46
57
  const prevMetadataName = usePrevious( metadataName ) ?? '';
47
58
  const bindings = attributes?.metadata?.bindings;
@@ -49,7 +60,9 @@ export default function useSetPatternBindings(
49
60
  useEffect( () => {
50
61
  // Bindings should only be created when editing a wp_block post type,
51
62
  // and also when there's a change to the user-given name for the block.
63
+ // Also check that the pattern overrides source is registered.
52
64
  if (
65
+ ! hasPatternOverridesSource ||
53
66
  currentPostType !== 'wp_block' ||
54
67
  metadataName === prevMetadataName
55
68
  ) {
@@ -95,6 +108,7 @@ export default function useSetPatternBindings(
95
108
  } );
96
109
  }
97
110
  }, [
111
+ hasPatternOverridesSource,
98
112
  bindings,
99
113
  prevMetadataName,
100
114
  metadataName,