@wordpress/patterns 1.10.0 → 1.11.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.11.0 (2024-01-24)
6
+
5
7
  ## 1.10.0 (2024-01-10)
6
8
 
7
9
  ## 1.9.0 (2023-12-13)
@@ -28,56 +28,58 @@ function PartialSyncingControls({
28
28
  setAttributes
29
29
  }) {
30
30
  const syncedAttributes = _constants.PARTIAL_SYNCING_SUPPORTED_BLOCKS[name];
31
- const attributeSources = Object.keys(syncedAttributes).map(attributeName => attributes.connections?.attributes?.[attributeName]?.source);
31
+ const attributeSources = Object.keys(syncedAttributes).map(attributeName => attributes.metadata?.bindings?.[attributeName]?.source?.name);
32
32
  const isConnectedToOtherSources = attributeSources.every(source => source && source !== 'pattern_attributes');
33
33
 
34
34
  // Render nothing if all supported attributes are connected to other sources.
35
35
  if (isConnectedToOtherSources) {
36
36
  return null;
37
37
  }
38
- function updateConnections(isChecked) {
39
- let updatedConnections = {
40
- ...attributes.connections,
41
- attributes: {
42
- ...attributes.connections?.attributes
43
- }
38
+ function updateBindings(isChecked) {
39
+ let updatedBindings = {
40
+ ...attributes?.metadata?.bindings
44
41
  };
45
42
  if (!isChecked) {
46
43
  for (const attributeName of Object.keys(syncedAttributes)) {
47
- if (updatedConnections.attributes[attributeName]?.source === 'pattern_attributes') {
48
- delete updatedConnections.attributes[attributeName];
44
+ if (updatedBindings[attributeName]?.source?.name === 'pattern_attributes') {
45
+ delete updatedBindings[attributeName];
49
46
  }
50
47
  }
51
- if (!Object.keys(updatedConnections.attributes).length) {
52
- delete updatedConnections.attributes;
53
- }
54
- if (!Object.keys(updatedConnections).length) {
55
- updatedConnections = undefined;
48
+ if (!Object.keys(updatedBindings).length) {
49
+ updatedBindings = undefined;
56
50
  }
57
51
  setAttributes({
58
- connections: updatedConnections
52
+ metadata: {
53
+ ...attributes.metadata,
54
+ bindings: updatedBindings
55
+ }
59
56
  });
60
57
  return;
61
58
  }
62
59
  for (const attributeName of Object.keys(syncedAttributes)) {
63
- if (!updatedConnections.attributes[attributeName]) {
64
- updatedConnections.attributes[attributeName] = {
65
- source: 'pattern_attributes'
60
+ if (!updatedBindings[attributeName]) {
61
+ updatedBindings[attributeName] = {
62
+ source: {
63
+ name: 'pattern_attributes'
64
+ }
66
65
  };
67
66
  }
68
67
  }
69
68
  if (typeof attributes.metadata?.id === 'string') {
70
69
  setAttributes({
71
- connections: updatedConnections
70
+ metadata: {
71
+ ...attributes.metadata,
72
+ bindings: updatedBindings
73
+ }
72
74
  });
73
75
  return;
74
76
  }
75
77
  const id = (0, _nanoid.nanoid)(6);
76
78
  setAttributes({
77
- connections: updatedConnections,
78
79
  metadata: {
79
80
  ...attributes.metadata,
80
- id
81
+ id,
82
+ bindings: updatedBindings
81
83
  }
82
84
  });
83
85
  }
@@ -90,7 +92,7 @@ function PartialSyncingControls({
90
92
  label: (0, _i18n.__)('Allow instance overrides'),
91
93
  checked: attributeSources.some(source => source === 'pattern_attributes'),
92
94
  onChange: isChecked => {
93
- updateConnections(isChecked);
95
+ updateBindings(isChecked);
94
96
  }
95
97
  })));
96
98
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_nanoid","require","_blockEditor","_components","_i18n","_constants","PartialSyncingControls","name","attributes","setAttributes","syncedAttributes","PARTIAL_SYNCING_SUPPORTED_BLOCKS","attributeSources","Object","keys","map","attributeName","connections","source","isConnectedToOtherSources","every","updateConnections","isChecked","updatedConnections","length","undefined","metadata","id","nanoid","_react","createElement","InspectorControls","group","BaseControl","__nextHasNoMarginBottom","VisualLabel","__","CheckboxControl","label","checked","some","onChange","_default","exports","default"],"sources":["@wordpress/patterns/src/components/partial-syncing-controls.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { nanoid } from 'nanoid';\n\n/**\n * WordPress dependencies\n */\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { BaseControl, CheckboxControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';\n\nfunction PartialSyncingControls( { name, attributes, setAttributes } ) {\n\tconst syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];\n\tconst attributeSources = Object.keys( syncedAttributes ).map(\n\t\t( attributeName ) =>\n\t\t\tattributes.connections?.attributes?.[ attributeName ]?.source\n\t);\n\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t( source ) => source && source !== 'pattern_attributes'\n\t);\n\n\t// Render nothing if all supported attributes are connected to other sources.\n\tif ( isConnectedToOtherSources ) {\n\t\treturn null;\n\t}\n\n\tfunction updateConnections( isChecked ) {\n\t\tlet updatedConnections = {\n\t\t\t...attributes.connections,\n\t\t\tattributes: { ...attributes.connections?.attributes },\n\t\t};\n\n\t\tif ( ! isChecked ) {\n\t\t\tfor ( const attributeName of Object.keys( syncedAttributes ) ) {\n\t\t\t\tif (\n\t\t\t\t\tupdatedConnections.attributes[ attributeName ]?.source ===\n\t\t\t\t\t'pattern_attributes'\n\t\t\t\t) {\n\t\t\t\t\tdelete updatedConnections.attributes[ attributeName ];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( ! Object.keys( updatedConnections.attributes ).length ) {\n\t\t\t\tdelete updatedConnections.attributes;\n\t\t\t}\n\t\t\tif ( ! Object.keys( updatedConnections ).length ) {\n\t\t\t\tupdatedConnections = undefined;\n\t\t\t}\n\t\t\tsetAttributes( {\n\t\t\t\tconnections: updatedConnections,\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\n\t\tfor ( const attributeName of Object.keys( syncedAttributes ) ) {\n\t\t\tif ( ! updatedConnections.attributes[ attributeName ] ) {\n\t\t\t\tupdatedConnections.attributes[ attributeName ] = {\n\t\t\t\t\tsource: 'pattern_attributes',\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tif ( typeof attributes.metadata?.id === 'string' ) {\n\t\t\tsetAttributes( { connections: updatedConnections } );\n\t\t\treturn;\n\t\t}\n\n\t\tconst id = nanoid( 6 );\n\t\tsetAttributes( {\n\t\t\tconnections: updatedConnections,\n\t\t\tmetadata: {\n\t\t\t\t...attributes.metadata,\n\t\t\t\tid,\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"advanced\">\n\t\t\t<BaseControl __nextHasNoMarginBottom>\n\t\t\t\t<BaseControl.VisualLabel>\n\t\t\t\t\t{ __( 'Pattern overrides' ) }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t<CheckboxControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Allow instance overrides' ) }\n\t\t\t\t\tchecked={ attributeSources.some(\n\t\t\t\t\t\t( source ) => source === 'pattern_attributes'\n\t\t\t\t\t) }\n\t\t\t\t\tonChange={ ( isChecked ) => {\n\t\t\t\t\t\tupdateConnections( isChecked );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BaseControl>\n\t\t</InspectorControls>\n\t);\n}\n\nexport default PartialSyncingControls;\n"],"mappings":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAKA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,UAAA,GAAAJ,OAAA;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;;AAGA,SAASK,sBAAsBA,CAAE;EAAEC,IAAI;EAAEC,UAAU;EAAEC;AAAc,CAAC,EAAG;EACtE,MAAMC,gBAAgB,GAAGC,2CAAgC,CAAEJ,IAAI,CAAE;EACjE,MAAMK,gBAAgB,GAAGC,MAAM,CAACC,IAAI,CAAEJ,gBAAiB,CAAC,CAACK,GAAG,CACzDC,aAAa,IACdR,UAAU,CAACS,WAAW,EAAET,UAAU,GA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AAE,KAAK,QAAQ,EAAG;MAClDlB,aAAa,CAAE;QAAEQ,WAAW,EAAEM;MAAmB,CAAE,CAAC;MACpD;IACD;IAEA,MAAMI,EAAE,GAAG,IAAAC,cAAM,EAAE,CAAE,CAAC;IACtBnB,aAAa,CAAE;MACdQ,WAAW,EAAEM,kBAAkB;MAC/BG,QAAQ,EAAE;QACT,GAAGlB,UAAU,CAACkB,QAAQ;QACtBC;MACD;IACD,CAAE,CAAC;EACJ;EAEA,OACC,IAAAE,MAAA,CAAAC,aAAA,EAAC5B,YAAA,CAAA6B,iBAAiB;IAACC,KAAK,EAAC;EAAU,GAClC,IAAAH,MAAA,CAAAC,aAAA,EAAC3B,WAAA,CAAA8B,WAAW;IAACC,uBAAuB;EAAA,GACnC,IAAAL,MAAA,CAAAC,aAAA,EAAC3B,WAAA,CAAA8B,WAAW,CAACE,WAAW,QACrB,IAAAC,QAAE,EAAE,mBAAoB,CACF,CAAC,EAC1B,IAAAP,MAAA,CAAAC,aAAA,EAAC3B,WAAA,CAAAkC,eAAe;IACfH,uBAAuB;IACvBI,KAAK,EAAG,IAAAF,QAAE,EAAE,0BAA2B,CAAG;IAC1CG,OAAO,EAAG3B,gBAAgB,CAAC4B,IAAI,CAC5BtB,MAAM,IAAMA,MAAM,KAAK,oBAC1B,CAAG;IACHuB,QAAQ,EAAKnB,SAAS,IAAM;MAC3BD,iBAAiB,CAAEC,SAAU,CAAC;IAC/B;EAAG,CACH,CACW,CACK,CAAC;AAEtB;AAAC,IAAAoB,QAAA,GAEcpC,sBAAsB;AAAAqC,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
1
+ {"version":3,"names":["_nanoid","require","_blockEditor","_components","_i18n","_constants","PartialSyncingControls","name","attributes","setAttributes","syncedAttributes","PARTIAL_SYNCING_SUPPORTED_BLOCKS","attributeSources","Object","keys","map","attributeName","metadata","bindings","source","isConnectedToOtherSources","every","updateBindings","isChecked","updatedBindings","length","undefined","id","nanoid","_react","createElement","InspectorControls","group","BaseControl","__nextHasNoMarginBottom","VisualLabel","__","CheckboxControl","label","checked","some","onChange","_default","exports","default"],"sources":["@wordpress/patterns/src/components/partial-syncing-controls.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { nanoid } from 'nanoid';\n\n/**\n * WordPress dependencies\n */\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { BaseControl, CheckboxControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';\n\nfunction PartialSyncingControls( { name, attributes, setAttributes } ) {\n\tconst syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];\n\tconst attributeSources = Object.keys( syncedAttributes ).map(\n\t\t( attributeName ) =>\n\t\t\tattributes.metadata?.bindings?.[ attributeName ]?.source?.name\n\t);\n\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t( source ) => source && source !== 'pattern_attributes'\n\t);\n\n\t// Render nothing if all supported attributes are connected to other sources.\n\tif ( isConnectedToOtherSources ) {\n\t\treturn null;\n\t}\n\n\tfunction updateBindings( isChecked ) {\n\t\tlet updatedBindings = {\n\t\t\t...attributes?.metadata?.bindings,\n\t\t};\n\n\t\tif ( ! isChecked ) {\n\t\t\tfor ( const attributeName of Object.keys( syncedAttributes ) ) {\n\t\t\t\tif (\n\t\t\t\t\tupdatedBindings[ attributeName ]?.source?.name ===\n\t\t\t\t\t'pattern_attributes'\n\t\t\t\t) {\n\t\t\t\t\tdelete updatedBindings[ attributeName ];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( ! Object.keys( updatedBindings ).length ) {\n\t\t\t\tupdatedBindings = undefined;\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\treturn;\n\t\t}\n\n\t\tfor ( const attributeName of Object.keys( syncedAttributes ) ) {\n\t\t\tif ( ! updatedBindings[ attributeName ] ) {\n\t\t\t\tupdatedBindings[ attributeName ] = {\n\t\t\t\t\tsource: {\n\t\t\t\t\t\tname: 'pattern_attributes',\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tif ( typeof attributes.metadata?.id === 'string' ) {\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\treturn;\n\t\t}\n\n\t\tconst id = nanoid( 6 );\n\t\tsetAttributes( {\n\t\t\tmetadata: {\n\t\t\t\t...attributes.metadata,\n\t\t\t\tid,\n\t\t\t\tbindings: updatedBindings,\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"advanced\">\n\t\t\t<BaseControl __nextHasNoMarginBottom>\n\t\t\t\t<BaseControl.VisualLabel>\n\t\t\t\t\t{ __( 'Pattern overrides' ) }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t<CheckboxControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Allow instance overrides' ) }\n\t\t\t\t\tchecked={ attributeSources.some(\n\t\t\t\t\t\t( source ) => source === 'pattern_attributes'\n\t\t\t\t\t) }\n\t\t\t\t\tonChange={ ( isChecked ) => {\n\t\t\t\t\t\tupdateBindings( isChecked );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BaseControl>\n\t\t</InspectorControls>\n\t);\n}\n\nexport default PartialSyncingControls;\n"],"mappings":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAKA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,UAAA,GAAAJ,OAAA;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;;AAG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YPES;
30
30
  const PARTIAL_SYNCING_SUPPORTED_BLOCKS = {
31
31
  'core/paragraph': {
32
32
  content: (0, _i18n.__)('Content')
33
+ },
34
+ 'core/heading': {
35
+ content: (0, _i18n.__)('Content')
36
+ },
37
+ 'core/button': {
38
+ text: (0, _i18n.__)('Text'),
39
+ url: (0, _i18n.__)('URL'),
40
+ linkTarget: (0, _i18n.__)('Link Target')
41
+ },
42
+ 'core/image': {
43
+ url: (0, _i18n.__)('URL'),
44
+ title: (0, _i18n.__)('Title'),
45
+ alt: (0, _i18n.__)('Alt Text')
33
46
  }
34
47
  };
35
48
  exports.PARTIAL_SYNCING_SUPPORTED_BLOCKS = PARTIAL_SYNCING_SUPPORTED_BLOCKS;
@@ -1 +1 @@
1
- {"version":3,"names":["_i18n","require","PATTERN_TYPES","theme","user","exports","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","EXCLUDED_PATTERN_SOURCES","PATTERN_SYNC_TYPES","full","unsynced","PARTIAL_SYNCING_SUPPORTED_BLOCKS","content","__"],"sources":["@wordpress/patterns/src/constants.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\nexport const PATTERN_TYPES = {\n\ttheme: 'pattern',\n\tuser: 'wp_block',\n};\n\nexport const PATTERN_DEFAULT_CATEGORY = 'all-patterns';\nexport const PATTERN_USER_CATEGORY = 'my-patterns';\nexport const EXCLUDED_PATTERN_SOURCES = [\n\t'core',\n\t'pattern-directory/core',\n\t'pattern-directory/featured',\n];\nexport const PATTERN_SYNC_TYPES = {\n\tfull: 'fully',\n\tunsynced: 'unsynced',\n};\n\n// TODO: This should not be hardcoded. Maybe there should be a config and/or an UI.\nexport const PARTIAL_SYNCING_SUPPORTED_BLOCKS = {\n\t'core/paragraph': { content: __( 'Content' ) },\n};\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGO,MAAMC,aAAa,GAAG;EAC5BC,KAAK,EAAE,SAAS;EAChBC,IAAI,EAAE;AACP,CAAC;AAACC,OAAA,CAAAH,aAAA,GAAAA,aAAA;AAEK,MAAMI,wBAAwB,GAAG,cAAc;AAACD,OAAA,CAAAC,wBAAA,GAAAA,wBAAA;AAChD,MAAMC,qBAAqB,GAAG,aAAa;AAACF,OAAA,CAAAE,qBAAA,GAAAA,qBAAA;AAC5C,MAAMC,wBAAwB,GAAG,CACvC,MAAM,EACN,wBAAwB,EACxB,4BAA4B,CAC5B;AAACH,OAAA,CAAAG,wBAAA,GAAAA,wBAAA;AACK,MAAMC,kBAAkB,GAAG;EACjCC,IAAI,EAAE,OAAO;EACbC,QAAQ,EAAE;AACX,CAAC;;AAED;AAAAN,OAAA,CAAAI,kBAAA,GAAAA,kBAAA;AACO,MAAMG,gCAAgC,GAAG;EAC/C,gBAAgB,EAAE;IAAEC,OAAO,EAAE,IAAAC,QAAE,EAAE,SAAU;EAAE;AAC9C,CAAC;AAACT,OAAA,CAAAO,gCAAA,GAAAA,gCAAA"}
1
+ {"version":3,"names":["_i18n","require","PATTERN_TYPES","theme","user","exports","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","EXCLUDED_PATTERN_SOURCES","PATTERN_SYNC_TYPES","full","unsynced","PARTIAL_SYNCING_SUPPORTED_BLOCKS","content","__","text","url","linkTarget","title","alt"],"sources":["@wordpress/patterns/src/constants.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\nexport const PATTERN_TYPES = {\n\ttheme: 'pattern',\n\tuser: 'wp_block',\n};\n\nexport const PATTERN_DEFAULT_CATEGORY = 'all-patterns';\nexport const PATTERN_USER_CATEGORY = 'my-patterns';\nexport const EXCLUDED_PATTERN_SOURCES = [\n\t'core',\n\t'pattern-directory/core',\n\t'pattern-directory/featured',\n];\nexport const PATTERN_SYNC_TYPES = {\n\tfull: 'fully',\n\tunsynced: 'unsynced',\n};\n\n// TODO: This should not be hardcoded. Maybe there should be a config and/or an UI.\nexport const PARTIAL_SYNCING_SUPPORTED_BLOCKS = {\n\t'core/paragraph': { content: __( 'Content' ) },\n\t'core/heading': { content: __( 'Content' ) },\n\t'core/button': {\n\t\ttext: __( 'Text' ),\n\t\turl: __( 'URL' ),\n\t\tlinkTarget: __( 'Link Target' ),\n\t},\n\t'core/image': {\n\t\turl: __( 'URL' ),\n\t\ttitle: __( 'Title' ),\n\t\talt: __( 'Alt Text' ),\n\t},\n};\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGO,MAAMC,aAAa,GAAG;EAC5BC,KAAK,EAAE,SAAS;EAChBC,IAAI,EAAE;AACP,CAAC;AAACC,OAAA,CAAAH,aAAA,GAAAA,aAAA;AAEK,MAAMI,wBAAwB,GAAG,cAAc;AAACD,OAAA,CAAAC,wBAAA,GAAAA,wBAAA;AAChD,MAAMC,qBAAqB,GAAG,aAAa;AAACF,OAAA,CAAAE,qBAAA,GAAAA,qBAAA;AAC5C,MAAMC,wBAAwB,GAAG,CACvC,MAAM,EACN,wBAAwB,EACxB,4BAA4B,CAC5B;AAACH,OAAA,CAAAG,wBAAA,GAAAA,wBAAA;AACK,MAAMC,kBAAkB,GAAG;EACjCC,IAAI,EAAE,OAAO;EACbC,QAAQ,EAAE;AACX,CAAC;;AAED;AAAAN,OAAA,CAAAI,kBAAA,GAAAA,kBAAA;AACO,MAAMG,gCAAgC,GAAG;EAC/C,gBAAgB,EAAE;IAAEC,OAAO,EAAE,IAAAC,QAAE,EAAE,SAAU;EAAE,CAAC;EAC9C,cAAc,EAAE;IAAED,OAAO,EAAE,IAAAC,QAAE,EAAE,SAAU;EAAE,CAAC;EAC5C,aAAa,EAAE;IACdC,IAAI,EAAE,IAAAD,QAAE,EAAE,MAAO,CAAC;IAClBE,GAAG,EAAE,IAAAF,QAAE,EAAE,KAAM,CAAC;IAChBG,UAAU,EAAE,IAAAH,QAAE,EAAE,aAAc;EAC/B,CAAC;EACD,YAAY,EAAE;IACbE,GAAG,EAAE,IAAAF,QAAE,EAAE,KAAM,CAAC;IAChBI,KAAK,EAAE,IAAAJ,QAAE,EAAE,OAAQ,CAAC;IACpBK,GAAG,EAAE,IAAAL,QAAE,EAAE,UAAW;EACrB;AACD,CAAC;AAACT,OAAA,CAAAO,gCAAA,GAAAA,gCAAA"}
@@ -75,10 +75,23 @@ exports.createPatternFromFile = createPatternFromFile;
75
75
  const convertSyncedPatternToStatic = clientId => ({
76
76
  registry
77
77
  }) => {
78
- const oldBlock = registry.select(_blockEditor.store).getBlock(clientId);
79
- const pattern = registry.select('core').getEditedEntityRecord('postType', 'wp_block', oldBlock.attributes.ref);
80
- const newBlocks = (0, _blocks.parse)(typeof pattern.content === 'function' ? pattern.content(pattern) : pattern.content);
81
- registry.dispatch(_blockEditor.store).replaceBlocks(oldBlock.clientId, newBlocks);
78
+ const patternBlock = registry.select(_blockEditor.store).getBlock(clientId);
79
+ function cloneBlocksAndRemoveBindings(blocks) {
80
+ return blocks.map(block => {
81
+ let metadata = block.attributes.metadata;
82
+ if (metadata) {
83
+ metadata = {
84
+ ...metadata
85
+ };
86
+ delete metadata.id;
87
+ delete metadata.bindings;
88
+ }
89
+ return (0, _blocks.cloneBlock)(block, {
90
+ metadata: metadata && Object.keys(metadata).length > 0 ? metadata : undefined
91
+ }, cloneBlocksAndRemoveBindings(block.innerBlocks));
92
+ });
93
+ }
94
+ registry.dispatch(_blockEditor.store).replaceBlocks(patternBlock.clientId, cloneBlocksAndRemoveBindings(patternBlock.innerBlocks));
82
95
  };
83
96
 
84
97
  /**
@@ -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","oldBlock","select","blockEditorStore","getBlock","getEditedEntityRecord","attributes","ref","newBlocks","replaceBlocks","setEditingPattern","isEditing","type"],"sources":["@wordpress/patterns/src/store/actions.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\n\nimport { parse } 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 oldBlock = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlock( clientId );\n\t\tconst pattern = registry\n\t\t\t.select( 'core' )\n\t\t\t.getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_block',\n\t\t\t\toldBlock.attributes.ref\n\t\t\t);\n\n\t\tconst newBlocks = parse(\n\t\t\ttypeof pattern.content === 'function'\n\t\t\t\t? pattern.content( pattern )\n\t\t\t\t: pattern.content\n\t\t);\n\t\tregistry\n\t\t\t.dispatch( blockEditorStore )\n\t\t\t.replaceBlocks( oldBlock.clientId, newBlocks );\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,YAA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"}
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,EAAE,UAAU,EAAEN,aAAc,CAAC;EAE3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AAM,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"}
@@ -21,56 +21,58 @@ function PartialSyncingControls({
21
21
  setAttributes
22
22
  }) {
23
23
  const syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[name];
24
- const attributeSources = Object.keys(syncedAttributes).map(attributeName => attributes.connections?.attributes?.[attributeName]?.source);
24
+ const attributeSources = Object.keys(syncedAttributes).map(attributeName => attributes.metadata?.bindings?.[attributeName]?.source?.name);
25
25
  const isConnectedToOtherSources = attributeSources.every(source => source && source !== 'pattern_attributes');
26
26
 
27
27
  // Render nothing if all supported attributes are connected to other sources.
28
28
  if (isConnectedToOtherSources) {
29
29
  return null;
30
30
  }
31
- function updateConnections(isChecked) {
32
- let updatedConnections = {
33
- ...attributes.connections,
34
- attributes: {
35
- ...attributes.connections?.attributes
36
- }
31
+ function updateBindings(isChecked) {
32
+ let updatedBindings = {
33
+ ...attributes?.metadata?.bindings
37
34
  };
38
35
  if (!isChecked) {
39
36
  for (const attributeName of Object.keys(syncedAttributes)) {
40
- if (updatedConnections.attributes[attributeName]?.source === 'pattern_attributes') {
41
- delete updatedConnections.attributes[attributeName];
37
+ if (updatedBindings[attributeName]?.source?.name === 'pattern_attributes') {
38
+ delete updatedBindings[attributeName];
42
39
  }
43
40
  }
44
- if (!Object.keys(updatedConnections.attributes).length) {
45
- delete updatedConnections.attributes;
46
- }
47
- if (!Object.keys(updatedConnections).length) {
48
- updatedConnections = undefined;
41
+ if (!Object.keys(updatedBindings).length) {
42
+ updatedBindings = undefined;
49
43
  }
50
44
  setAttributes({
51
- connections: updatedConnections
45
+ metadata: {
46
+ ...attributes.metadata,
47
+ bindings: updatedBindings
48
+ }
52
49
  });
53
50
  return;
54
51
  }
55
52
  for (const attributeName of Object.keys(syncedAttributes)) {
56
- if (!updatedConnections.attributes[attributeName]) {
57
- updatedConnections.attributes[attributeName] = {
58
- source: 'pattern_attributes'
53
+ if (!updatedBindings[attributeName]) {
54
+ updatedBindings[attributeName] = {
55
+ source: {
56
+ name: 'pattern_attributes'
57
+ }
59
58
  };
60
59
  }
61
60
  }
62
61
  if (typeof attributes.metadata?.id === 'string') {
63
62
  setAttributes({
64
- connections: updatedConnections
63
+ metadata: {
64
+ ...attributes.metadata,
65
+ bindings: updatedBindings
66
+ }
65
67
  });
66
68
  return;
67
69
  }
68
70
  const id = nanoid(6);
69
71
  setAttributes({
70
- connections: updatedConnections,
71
72
  metadata: {
72
73
  ...attributes.metadata,
73
- id
74
+ id,
75
+ bindings: updatedBindings
74
76
  }
75
77
  });
76
78
  }
@@ -83,7 +85,7 @@ function PartialSyncingControls({
83
85
  label: __('Allow instance overrides'),
84
86
  checked: attributeSources.some(source => source === 'pattern_attributes'),
85
87
  onChange: isChecked => {
86
- updateConnections(isChecked);
88
+ updateBindings(isChecked);
87
89
  }
88
90
  })));
89
91
  }
@@ -1 +1 @@
1
- {"version":3,"names":["nanoid","InspectorControls","BaseControl","CheckboxControl","__","PARTIAL_SYNCING_SUPPORTED_BLOCKS","PartialSyncingControls","name","attributes","setAttributes","syncedAttributes","attributeSources","Object","keys","map","attributeName","connections","source","isConnectedToOtherSources","every","updateConnections","isChecked","updatedConnections","length","undefined","metadata","id","createElement","group","__nextHasNoMarginBottom","VisualLabel","label","checked","some","onChange"],"sources":["@wordpress/patterns/src/components/partial-syncing-controls.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { nanoid } from 'nanoid';\n\n/**\n * WordPress dependencies\n */\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { BaseControl, CheckboxControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';\n\nfunction PartialSyncingControls( { name, attributes, setAttributes } ) {\n\tconst syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];\n\tconst attributeSources = Object.keys( syncedAttributes ).map(\n\t\t( attributeName ) =>\n\t\t\tattributes.connections?.attributes?.[ attributeName ]?.source\n\t);\n\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t( source ) => source && source !== 'pattern_attributes'\n\t);\n\n\t// Render nothing if all supported attributes are connected to other sources.\n\tif ( isConnectedToOtherSources ) {\n\t\treturn null;\n\t}\n\n\tfunction updateConnections( isChecked ) {\n\t\tlet updatedConnections = {\n\t\t\t...attributes.connections,\n\t\t\tattributes: { ...attributes.connections?.attributes },\n\t\t};\n\n\t\tif ( ! isChecked ) {\n\t\t\tfor ( const attributeName of Object.keys( syncedAttributes ) ) {\n\t\t\t\tif (\n\t\t\t\t\tupdatedConnections.attributes[ attributeName ]?.source ===\n\t\t\t\t\t'pattern_attributes'\n\t\t\t\t) {\n\t\t\t\t\tdelete updatedConnections.attributes[ attributeName ];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( ! Object.keys( updatedConnections.attributes ).length ) {\n\t\t\t\tdelete updatedConnections.attributes;\n\t\t\t}\n\t\t\tif ( ! Object.keys( updatedConnections ).length ) {\n\t\t\t\tupdatedConnections = undefined;\n\t\t\t}\n\t\t\tsetAttributes( {\n\t\t\t\tconnections: updatedConnections,\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\n\t\tfor ( const attributeName of Object.keys( syncedAttributes ) ) {\n\t\t\tif ( ! updatedConnections.attributes[ attributeName ] ) {\n\t\t\t\tupdatedConnections.attributes[ attributeName ] = {\n\t\t\t\t\tsource: 'pattern_attributes',\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tif ( typeof attributes.metadata?.id === 'string' ) {\n\t\t\tsetAttributes( { connections: updatedConnections } );\n\t\t\treturn;\n\t\t}\n\n\t\tconst id = nanoid( 6 );\n\t\tsetAttributes( {\n\t\t\tconnections: updatedConnections,\n\t\t\tmetadata: {\n\t\t\t\t...attributes.metadata,\n\t\t\t\tid,\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"advanced\">\n\t\t\t<BaseControl __nextHasNoMarginBottom>\n\t\t\t\t<BaseControl.VisualLabel>\n\t\t\t\t\t{ __( 'Pattern overrides' ) }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t<CheckboxControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Allow instance overrides' ) }\n\t\t\t\t\tchecked={ attributeSources.some(\n\t\t\t\t\t\t( source ) => source === 'pattern_attributes'\n\t\t\t\t\t) }\n\t\t\t\t\tonChange={ ( isChecked ) => {\n\t\t\t\t\t\tupdateConnections( isChecked );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BaseControl>\n\t\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AAS,IAAM;MAC3BD,iBAAiB,CAAEC,SAAU,CAAC;IAC/B;EAAG,CACH,CACW,CACK,CAAC;AAEtB;AAEA,eAAef,sBAAsB"}
1
+ {"version":3,"names":["nanoid","InspectorControls","BaseControl","CheckboxControl","__","PARTIAL_SYNCING_SUPPORTED_BLOCKS","PartialSyncingControls","name","attributes","setAttributes","syncedAttributes","attributeSources","Object","keys","map","attributeName","metadata","bindings","source","isConnectedToOtherSources","every","updateBindings","isChecked","updatedBindings","length","undefined","id","createElement","group","__nextHasNoMarginBottom","VisualLabel","label","checked","some","onChange"],"sources":["@wordpress/patterns/src/components/partial-syncing-controls.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { nanoid } from 'nanoid';\n\n/**\n * WordPress dependencies\n */\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { BaseControl, CheckboxControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';\n\nfunction PartialSyncingControls( { name, attributes, setAttributes } ) {\n\tconst syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];\n\tconst attributeSources = Object.keys( syncedAttributes ).map(\n\t\t( attributeName ) =>\n\t\t\tattributes.metadata?.bindings?.[ attributeName ]?.source?.name\n\t);\n\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t( source ) => source && source !== 'pattern_attributes'\n\t);\n\n\t// Render nothing if all supported attributes are connected to other sources.\n\tif ( isConnectedToOtherSources ) {\n\t\treturn null;\n\t}\n\n\tfunction updateBindings( isChecked ) {\n\t\tlet updatedBindings = {\n\t\t\t...attributes?.metadata?.bindings,\n\t\t};\n\n\t\tif ( ! isChecked ) {\n\t\t\tfor ( const attributeName of Object.keys( syncedAttributes ) ) {\n\t\t\t\tif (\n\t\t\t\t\tupdatedBindings[ attributeName ]?.source?.name ===\n\t\t\t\t\t'pattern_attributes'\n\t\t\t\t) {\n\t\t\t\t\tdelete updatedBindings[ attributeName ];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( ! Object.keys( updatedBindings ).length ) {\n\t\t\t\tupdatedBindings = undefined;\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\treturn;\n\t\t}\n\n\t\tfor ( const attributeName of Object.keys( syncedAttributes ) ) {\n\t\t\tif ( ! updatedBindings[ attributeName ] ) {\n\t\t\t\tupdatedBindings[ attributeName ] = {\n\t\t\t\t\tsource: {\n\t\t\t\t\t\tname: 'pattern_attributes',\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tif ( typeof attributes.metadata?.id === 'string' ) {\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\treturn;\n\t\t}\n\n\t\tconst id = nanoid( 6 );\n\t\tsetAttributes( {\n\t\t\tmetadata: {\n\t\t\t\t...attributes.metadata,\n\t\t\t\tid,\n\t\t\t\tbindings: updatedBindings,\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"advanced\">\n\t\t\t<BaseControl __nextHasNoMarginBottom>\n\t\t\t\t<BaseControl.VisualLabel>\n\t\t\t\t\t{ __( 'Pattern overrides' ) }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t<CheckboxControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Allow instance overrides' ) }\n\t\t\t\t\tchecked={ attributeSources.some(\n\t\t\t\t\t\t( source ) => source === 'pattern_attributes'\n\t\t\t\t\t) }\n\t\t\t\t\tonChange={ ( isChecked ) => {\n\t\t\t\t\t\tupdateBindings( isChecked );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t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CACW,CACK,CAAC;AAEtB;AAEA,eAAehB,sBAAsB"}
@@ -18,6 +18,19 @@ export const PATTERN_SYNC_TYPES = {
18
18
  export const PARTIAL_SYNCING_SUPPORTED_BLOCKS = {
19
19
  'core/paragraph': {
20
20
  content: __('Content')
21
+ },
22
+ 'core/heading': {
23
+ content: __('Content')
24
+ },
25
+ 'core/button': {
26
+ text: __('Text'),
27
+ url: __('URL'),
28
+ linkTarget: __('Link Target')
29
+ },
30
+ 'core/image': {
31
+ url: __('URL'),
32
+ title: __('Title'),
33
+ alt: __('Alt Text')
21
34
  }
22
35
  };
23
36
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["__","PATTERN_TYPES","theme","user","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","EXCLUDED_PATTERN_SOURCES","PATTERN_SYNC_TYPES","full","unsynced","PARTIAL_SYNCING_SUPPORTED_BLOCKS","content"],"sources":["@wordpress/patterns/src/constants.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\nexport const PATTERN_TYPES = {\n\ttheme: 'pattern',\n\tuser: 'wp_block',\n};\n\nexport const PATTERN_DEFAULT_CATEGORY = 'all-patterns';\nexport const PATTERN_USER_CATEGORY = 'my-patterns';\nexport const EXCLUDED_PATTERN_SOURCES = [\n\t'core',\n\t'pattern-directory/core',\n\t'pattern-directory/featured',\n];\nexport const PATTERN_SYNC_TYPES = {\n\tfull: 'fully',\n\tunsynced: 'unsynced',\n};\n\n// TODO: This should not be hardcoded. Maybe there should be a config and/or an UI.\nexport const PARTIAL_SYNCING_SUPPORTED_BLOCKS = {\n\t'core/paragraph': { content: __( 'Content' ) },\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AAEpC,OAAO,MAAMC,aAAa,GAAG;EAC5BC,KAAK,EAAE,SAAS;EAChBC,IAAI,EAAE;AACP,CAAC;AAED,OAAO,MAAMC,wBAAwB,GAAG,cAAc;AACtD,OAAO,MAAMC,qBAAqB,GAAG,aAAa;AAClD,OAAO,MAAMC,wBAAwB,GAAG,CACvC,MAAM,EACN,wBAAwB,EACxB,4BAA4B,CAC5B;AACD,OAAO,MAAMC,kBAAkB,GAAG;EACjCC,IAAI,EAAE,OAAO;EACbC,QAAQ,EAAE;AACX,CAAC;;AAED;AACA,OAAO,MAAMC,gCAAgC,GAAG;EAC/C,gBAAgB,EAAE;IAAEC,OAAO,EAAEX,EAAE,CAAE,SAAU;EAAE;AAC9C,CAAC"}
1
+ {"version":3,"names":["__","PATTERN_TYPES","theme","user","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","EXCLUDED_PATTERN_SOURCES","PATTERN_SYNC_TYPES","full","unsynced","PARTIAL_SYNCING_SUPPORTED_BLOCKS","content","text","url","linkTarget","title","alt"],"sources":["@wordpress/patterns/src/constants.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\nexport const PATTERN_TYPES = {\n\ttheme: 'pattern',\n\tuser: 'wp_block',\n};\n\nexport const PATTERN_DEFAULT_CATEGORY = 'all-patterns';\nexport const PATTERN_USER_CATEGORY = 'my-patterns';\nexport const EXCLUDED_PATTERN_SOURCES = [\n\t'core',\n\t'pattern-directory/core',\n\t'pattern-directory/featured',\n];\nexport const PATTERN_SYNC_TYPES = {\n\tfull: 'fully',\n\tunsynced: 'unsynced',\n};\n\n// TODO: This should not be hardcoded. Maybe there should be a config and/or an UI.\nexport const PARTIAL_SYNCING_SUPPORTED_BLOCKS = {\n\t'core/paragraph': { content: __( 'Content' ) },\n\t'core/heading': { content: __( 'Content' ) },\n\t'core/button': {\n\t\ttext: __( 'Text' ),\n\t\turl: __( 'URL' ),\n\t\tlinkTarget: __( 'Link Target' ),\n\t},\n\t'core/image': {\n\t\turl: __( 'URL' ),\n\t\ttitle: __( 'Title' ),\n\t\talt: __( 'Alt Text' ),\n\t},\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AAEpC,OAAO,MAAMC,aAAa,GAAG;EAC5BC,KAAK,EAAE,SAAS;EAChBC,IAAI,EAAE;AACP,CAAC;AAED,OAAO,MAAMC,wBAAwB,GAAG,cAAc;AACtD,OAAO,MAAMC,qBAAqB,GAAG,aAAa;AAClD,OAAO,MAAMC,wBAAwB,GAAG,CACvC,MAAM,EACN,wBAAwB,EACxB,4BAA4B,CAC5B;AACD,OAAO,MAAMC,kBAAkB,GAAG;EACjCC,IAAI,EAAE,OAAO;EACbC,QAAQ,EAAE;AACX,CAAC;;AAED;AACA,OAAO,MAAMC,gCAAgC,GAAG;EAC/C,gBAAgB,EAAE;IAAEC,OAAO,EAAEX,EAAE,CAAE,SAAU;EAAE,CAAC;EAC9C,cAAc,EAAE;IAAEW,OAAO,EAAEX,EAAE,CAAE,SAAU;EAAE,CAAC;EAC5C,aAAa,EAAE;IACdY,IAAI,EAAEZ,EAAE,CAAE,MAAO,CAAC;IAClBa,GAAG,EAAEb,EAAE,CAAE,KAAM,CAAC;IAChBc,UAAU,EAAEd,EAAE,CAAE,aAAc;EAC/B,CAAC;EACD,YAAY,EAAE;IACba,GAAG,EAAEb,EAAE,CAAE,KAAM,CAAC;IAChBe,KAAK,EAAEf,EAAE,CAAE,OAAQ,CAAC;IACpBgB,GAAG,EAAEhB,EAAE,CAAE,UAAW;EACrB;AACD,CAAC"}
@@ -2,7 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
 
5
- import { parse } from '@wordpress/blocks';
5
+ import { 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
 
@@ -67,10 +67,23 @@ export const createPatternFromFile = (file, categories) => async ({
67
67
  export const convertSyncedPatternToStatic = clientId => ({
68
68
  registry
69
69
  }) => {
70
- const oldBlock = registry.select(blockEditorStore).getBlock(clientId);
71
- const pattern = registry.select('core').getEditedEntityRecord('postType', 'wp_block', oldBlock.attributes.ref);
72
- const newBlocks = parse(typeof pattern.content === 'function' ? pattern.content(pattern) : pattern.content);
73
- registry.dispatch(blockEditorStore).replaceBlocks(oldBlock.clientId, newBlocks);
70
+ const patternBlock = registry.select(blockEditorStore).getBlock(clientId);
71
+ function cloneBlocksAndRemoveBindings(blocks) {
72
+ return blocks.map(block => {
73
+ let metadata = block.attributes.metadata;
74
+ if (metadata) {
75
+ metadata = {
76
+ ...metadata
77
+ };
78
+ delete metadata.id;
79
+ delete metadata.bindings;
80
+ }
81
+ return cloneBlock(block, {
82
+ metadata: metadata && Object.keys(metadata).length > 0 ? metadata : undefined
83
+ }, cloneBlocksAndRemoveBindings(block.innerBlocks));
84
+ });
85
+ }
86
+ registry.dispatch(blockEditorStore).replaceBlocks(patternBlock.clientId, cloneBlocksAndRemoveBindings(patternBlock.innerBlocks));
74
87
  };
75
88
 
76
89
  /**
@@ -1 +1 @@
1
- {"version":3,"names":["parse","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","e","Error","__file","syncStatus","pattern","convertSyncedPatternToStatic","clientId","oldBlock","select","getBlock","getEditedEntityRecord","attributes","ref","newBlocks","replaceBlocks","setEditingPattern","isEditing","type"],"sources":["@wordpress/patterns/src/store/actions.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\n\nimport { parse } 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 oldBlock = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.getBlock( clientId );\n\t\tconst pattern = registry\n\t\t\t.select( 'core' )\n\t\t\t.getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_block',\n\t\t\t\toldBlock.attributes.ref\n\t\t\t);\n\n\t\tconst newBlocks = parse(\n\t\t\ttypeof pattern.content === 'function'\n\t\t\t\t? pattern.content( pattern )\n\t\t\t\t: pattern.content\n\t\t);\n\t\tregistry\n\t\t\t.dispatch( blockEditorStore )\n\t\t\t.replaceBlocks( oldBlock.clientId, newBlocks );\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,KAAK,QAAQ,mBAAmB;AACzC,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASD,KAAK,IAAIE,gBAAgB,QAAQ,yBAAyB;;AAEnE;AACA;AACA;AACA,SAASC,kBAAkB,QAAQ,cAAc;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GACzBA,CAAEC,KAAK,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,UAAU,KACtC,OAAQ;EAAEC;AAAS,CAAC,KAAM;EACzB,MAAMC,IAAI,GACTJ,QAAQ,KAAKH,kBAAkB,CAACQ,QAAQ,GACrC;IACAC,sBAAsB,EAAEN;EACxB,CAAC,GACDO,SAAS;EAEb,MAAMC,aAAa,GAAG;IACrBT,KAA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AAC,KAAM;EACnB,MAAMwB,QAAQ,GAAGxB,QAAQ,CACvByB,MAAM,CAAEhC,gBAAiB,CAAC,CAC1BiC,QAAQ,CAAEH,QAAS,CAAC;EACtB,MAAMF,OAAO,GAAGrB,QAAQ,CACtByB,MAAM,CAAE,MAAO,CAAC,CAChBE,qBAAqB,CACrB,UAAU,EACV,UAAU,EACVH,QAAQ,CAACI,UAAU,CAACC,GACrB,CAAC;EAEF,MAAMC,SAAS,GAAGxC,KAAK,CACtB,OAAO+B,OAAO,CAACvB,OAAO,KAAK,UAAU,GAClCuB,OAAO,CAACvB,OAAO,CAAEuB,OAAQ,CAAC,GAC1BA,OAAO,CAACvB,OACZ,CAAC;EACDE,QAAQ,CACNS,QAAQ,CAAEhB,gBAAiB,CAAC,CAC5BsC,aAAa,CAAEP,QAAQ,CAACD,QAAQ,EAAEO,SAAU,CAAC;AAChD,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,iBAAiBA,CAAET,QAAQ,EAAEU,SAAS,EAAG;EACxD,OAAO;IACNC,IAAI,EAAE,qBAAqB;IAC3BX,QAAQ;IACRU;EACD,CAAC;AACF"}
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":"AA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AAa,CACbf,YAAY,CAACD,QAAQ,EACrBI,4BAA4B,CAAEH,YAAY,CAACc,WAAY,CACxD,CAAC;AACH,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,iBAAiBA,CAAEjB,QAAQ,EAAEkB,SAAS,EAAG;EACxD,OAAO;IACNC,IAAI,EAAE,qBAAqB;IAC3BnB,QAAQ;IACRkB;EACD,CAAC;AACF"}
@@ -97,7 +97,7 @@
97
97
  --wp-block-synced-color: #7a00df;
98
98
  --wp-block-synced-color--rgb: 122, 0, 223;
99
99
  }
100
- @media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
100
+ @media (min-resolution: 192dpi) {
101
101
  :root {
102
102
  --wp-admin-border-width-focus: 1.5px;
103
103
  }
@@ -97,7 +97,7 @@
97
97
  --wp-block-synced-color: #7a00df;
98
98
  --wp-block-synced-color--rgb: 122, 0, 223;
99
99
  }
100
- @media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
100
+ @media (min-resolution: 192dpi) {
101
101
  :root {
102
102
  --wp-admin-border-width-focus: 1.5px;
103
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/patterns",
3
- "version": "1.10.0",
3
+ "version": "1.11.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.49.0",
35
- "@wordpress/block-editor": "^12.17.0",
36
- "@wordpress/blocks": "^12.26.0",
37
- "@wordpress/components": "^25.15.0",
38
- "@wordpress/compose": "^6.26.0",
39
- "@wordpress/core-data": "^6.26.0",
40
- "@wordpress/data": "^9.19.0",
41
- "@wordpress/element": "^5.26.0",
42
- "@wordpress/html-entities": "^3.49.0",
43
- "@wordpress/i18n": "^4.49.0",
44
- "@wordpress/icons": "^9.40.0",
45
- "@wordpress/notices": "^4.17.0",
46
- "@wordpress/private-apis": "^0.31.0",
47
- "@wordpress/url": "^3.50.0",
34
+ "@wordpress/a11y": "^3.50.0",
35
+ "@wordpress/block-editor": "^12.18.0",
36
+ "@wordpress/blocks": "^12.27.0",
37
+ "@wordpress/components": "^25.16.0",
38
+ "@wordpress/compose": "^6.27.0",
39
+ "@wordpress/core-data": "^6.27.0",
40
+ "@wordpress/data": "^9.20.0",
41
+ "@wordpress/element": "^5.27.0",
42
+ "@wordpress/html-entities": "^3.50.0",
43
+ "@wordpress/i18n": "^4.50.0",
44
+ "@wordpress/icons": "^9.41.0",
45
+ "@wordpress/notices": "^4.18.0",
46
+ "@wordpress/private-apis": "^0.32.0",
47
+ "@wordpress/url": "^3.51.0",
48
48
  "nanoid": "^3.3.4"
49
49
  },
50
50
  "peerDependencies": {
@@ -54,5 +54,5 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  },
57
- "gitHead": "5e6f9caa205d3bfdbac131952b7bf9c6ec60569b"
57
+ "gitHead": "45de2cb4212fed7f2763e95f10300d1ff9d0ec08"
58
58
  }
@@ -19,7 +19,7 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) {
19
19
  const syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];
20
20
  const attributeSources = Object.keys( syncedAttributes ).map(
21
21
  ( attributeName ) =>
22
- attributes.connections?.attributes?.[ attributeName ]?.source
22
+ attributes.metadata?.bindings?.[ attributeName ]?.source?.name
23
23
  );
24
24
  const isConnectedToOtherSources = attributeSources.every(
25
25
  ( source ) => source && source !== 'pattern_attributes'
@@ -30,52 +30,58 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) {
30
30
  return null;
31
31
  }
32
32
 
33
- function updateConnections( isChecked ) {
34
- let updatedConnections = {
35
- ...attributes.connections,
36
- attributes: { ...attributes.connections?.attributes },
33
+ function updateBindings( isChecked ) {
34
+ let updatedBindings = {
35
+ ...attributes?.metadata?.bindings,
37
36
  };
38
37
 
39
38
  if ( ! isChecked ) {
40
39
  for ( const attributeName of Object.keys( syncedAttributes ) ) {
41
40
  if (
42
- updatedConnections.attributes[ attributeName ]?.source ===
41
+ updatedBindings[ attributeName ]?.source?.name ===
43
42
  'pattern_attributes'
44
43
  ) {
45
- delete updatedConnections.attributes[ attributeName ];
44
+ delete updatedBindings[ attributeName ];
46
45
  }
47
46
  }
48
- if ( ! Object.keys( updatedConnections.attributes ).length ) {
49
- delete updatedConnections.attributes;
50
- }
51
- if ( ! Object.keys( updatedConnections ).length ) {
52
- updatedConnections = undefined;
47
+ if ( ! Object.keys( updatedBindings ).length ) {
48
+ updatedBindings = undefined;
53
49
  }
54
50
  setAttributes( {
55
- connections: updatedConnections,
51
+ metadata: {
52
+ ...attributes.metadata,
53
+ bindings: updatedBindings,
54
+ },
56
55
  } );
57
56
  return;
58
57
  }
59
58
 
60
59
  for ( const attributeName of Object.keys( syncedAttributes ) ) {
61
- if ( ! updatedConnections.attributes[ attributeName ] ) {
62
- updatedConnections.attributes[ attributeName ] = {
63
- source: 'pattern_attributes',
60
+ if ( ! updatedBindings[ attributeName ] ) {
61
+ updatedBindings[ attributeName ] = {
62
+ source: {
63
+ name: 'pattern_attributes',
64
+ },
64
65
  };
65
66
  }
66
67
  }
67
68
 
68
69
  if ( typeof attributes.metadata?.id === 'string' ) {
69
- setAttributes( { connections: updatedConnections } );
70
+ setAttributes( {
71
+ metadata: {
72
+ ...attributes.metadata,
73
+ bindings: updatedBindings,
74
+ },
75
+ } );
70
76
  return;
71
77
  }
72
78
 
73
79
  const id = nanoid( 6 );
74
80
  setAttributes( {
75
- connections: updatedConnections,
76
81
  metadata: {
77
82
  ...attributes.metadata,
78
83
  id,
84
+ bindings: updatedBindings,
79
85
  },
80
86
  } );
81
87
  }
@@ -93,7 +99,7 @@ function PartialSyncingControls( { name, attributes, setAttributes } ) {
93
99
  ( source ) => source === 'pattern_attributes'
94
100
  ) }
95
101
  onChange={ ( isChecked ) => {
96
- updateConnections( isChecked );
102
+ updateBindings( isChecked );
97
103
  } }
98
104
  />
99
105
  </BaseControl>
package/src/constants.js CHANGED
@@ -23,4 +23,15 @@ export const PATTERN_SYNC_TYPES = {
23
23
  // TODO: This should not be hardcoded. Maybe there should be a config and/or an UI.
24
24
  export const PARTIAL_SYNCING_SUPPORTED_BLOCKS = {
25
25
  'core/paragraph': { content: __( 'Content' ) },
26
+ 'core/heading': { content: __( 'Content' ) },
27
+ 'core/button': {
28
+ text: __( 'Text' ),
29
+ url: __( 'URL' ),
30
+ linkTarget: __( 'Link Target' ),
31
+ },
32
+ 'core/image': {
33
+ url: __( 'URL' ),
34
+ title: __( 'Title' ),
35
+ alt: __( 'Alt Text' ),
36
+ },
26
37
  };
@@ -2,7 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
 
5
- import { parse } from '@wordpress/blocks';
5
+ import { 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
 
@@ -90,25 +90,37 @@ export const createPatternFromFile =
90
90
  export const convertSyncedPatternToStatic =
91
91
  ( clientId ) =>
92
92
  ( { registry } ) => {
93
- const oldBlock = registry
93
+ const patternBlock = registry
94
94
  .select( blockEditorStore )
95
95
  .getBlock( clientId );
96
- const pattern = registry
97
- .select( 'core' )
98
- .getEditedEntityRecord(
99
- 'postType',
100
- 'wp_block',
101
- oldBlock.attributes.ref
102
- );
103
96
 
104
- const newBlocks = parse(
105
- typeof pattern.content === 'function'
106
- ? pattern.content( pattern )
107
- : pattern.content
108
- );
97
+ function cloneBlocksAndRemoveBindings( blocks ) {
98
+ return blocks.map( ( block ) => {
99
+ let metadata = block.attributes.metadata;
100
+ if ( metadata ) {
101
+ metadata = { ...metadata };
102
+ delete metadata.id;
103
+ delete metadata.bindings;
104
+ }
105
+ return cloneBlock(
106
+ block,
107
+ {
108
+ metadata:
109
+ metadata && Object.keys( metadata ).length > 0
110
+ ? metadata
111
+ : undefined,
112
+ },
113
+ cloneBlocksAndRemoveBindings( block.innerBlocks )
114
+ );
115
+ } );
116
+ }
117
+
109
118
  registry
110
119
  .dispatch( blockEditorStore )
111
- .replaceBlocks( oldBlock.clientId, newBlocks );
120
+ .replaceBlocks(
121
+ patternBlock.clientId,
122
+ cloneBlocksAndRemoveBindings( patternBlock.innerBlocks )
123
+ );
112
124
  };
113
125
 
114
126
  /**