@wordpress/patterns 1.13.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 +4 -0
- package/build/components/reset-overrides-control.js +8 -8
- package/build/components/reset-overrides-control.js.map +1 -1
- package/build/components/use-set-pattern-bindings.js +103 -0
- package/build/components/use-set-pattern-bindings.js.map +1 -0
- package/build/constants.js +4 -23
- package/build/constants.js.map +1 -1
- package/build/private-apis.js +2 -2
- package/build/private-apis.js.map +1 -1
- package/build-module/components/reset-overrides-control.js +8 -8
- package/build-module/components/reset-overrides-control.js.map +1 -1
- package/build-module/components/use-set-pattern-bindings.js +96 -0
- package/build-module/components/use-set-pattern-bindings.js.map +1 -0
- package/build-module/constants.js +4 -22
- package/build-module/constants.js.map +1 -1
- package/build-module/private-apis.js +2 -2
- package/build-module/private-apis.js.map +1 -1
- package/build-style/style-rtl.css +1 -0
- package/build-style/style.css +1 -0
- package/package.json +16 -17
- package/src/components/reset-overrides-control.js +8 -8
- package/src/components/use-set-pattern-bindings.js +120 -0
- package/src/constants.js +4 -19
- package/src/private-apis.js +2 -2
- package/build/components/partial-syncing-controls.js +0 -98
- package/build/components/partial-syncing-controls.js.map +0 -1
- package/build-module/components/partial-syncing-controls.js +0 -91
- package/build-module/components/partial-syncing-controls.js.map +0 -1
- package/src/components/partial-syncing-controls.js +0 -108
package/CHANGELOG.md
CHANGED
|
@@ -15,12 +15,12 @@ var _i18n = require("@wordpress/i18n");
|
|
|
15
15
|
* WordPress dependencies
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
function
|
|
18
|
+
function recursivelyFindBlockWithName(blocks, name) {
|
|
19
19
|
for (const block of blocks) {
|
|
20
|
-
if (block.attributes.metadata?.
|
|
20
|
+
if (block.attributes.metadata?.name === name) {
|
|
21
21
|
return block;
|
|
22
22
|
}
|
|
23
|
-
const found =
|
|
23
|
+
const found = recursivelyFindBlockWithName(block.innerBlocks, name);
|
|
24
24
|
if (found) {
|
|
25
25
|
return found;
|
|
26
26
|
}
|
|
@@ -28,9 +28,9 @@ function recursivelyFindBlockWithId(blocks, id) {
|
|
|
28
28
|
}
|
|
29
29
|
function ResetOverridesControl(props) {
|
|
30
30
|
const registry = (0, _data.useRegistry)();
|
|
31
|
-
const
|
|
31
|
+
const name = props.attributes.metadata?.name;
|
|
32
32
|
const patternWithOverrides = (0, _data.useSelect)(select => {
|
|
33
|
-
if (!
|
|
33
|
+
if (!name) {
|
|
34
34
|
return undefined;
|
|
35
35
|
}
|
|
36
36
|
const {
|
|
@@ -38,16 +38,16 @@ function ResetOverridesControl(props) {
|
|
|
38
38
|
getBlocksByClientId
|
|
39
39
|
} = select(_blockEditor.store);
|
|
40
40
|
const patternBlock = getBlocksByClientId(getBlockParentsByBlockName(props.clientId, 'core/block'))[0];
|
|
41
|
-
if (!patternBlock?.attributes.content?.[
|
|
41
|
+
if (!patternBlock?.attributes.content?.[name]) {
|
|
42
42
|
return undefined;
|
|
43
43
|
}
|
|
44
44
|
return patternBlock;
|
|
45
|
-
}, [props.clientId,
|
|
45
|
+
}, [props.clientId, name]);
|
|
46
46
|
const resetOverrides = async () => {
|
|
47
47
|
var _editedRecord$blocks;
|
|
48
48
|
const editedRecord = await registry.resolveSelect(_coreData.store).getEditedEntityRecord('postType', 'wp_block', patternWithOverrides.attributes.ref);
|
|
49
49
|
const blocks = (_editedRecord$blocks = editedRecord.blocks) !== null && _editedRecord$blocks !== void 0 ? _editedRecord$blocks : (0, _blocks.parse)(editedRecord.content);
|
|
50
|
-
const block =
|
|
50
|
+
const block = recursivelyFindBlockWithName(blocks, name);
|
|
51
51
|
const newAttributes = Object.assign(
|
|
52
52
|
// Reset every existing attribute to undefined.
|
|
53
53
|
Object.fromEntries(Object.keys(props.attributes).map(key => [key, undefined])),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_blockEditor","require","_components","_data","_coreData","_blocks","_i18n","
|
|
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":";;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAIA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AAXA;AACA;AACA;;AAWA,SAASM,4BAA4BA,CAAEC,MAAM,EAAEC,IAAI,EAAG;EACrD,KAAM,MAAMC,KAAK,IAAIF,MAAM,EAAG;IAC7B,IAAKE,KAAK,CAACC,UAAU,CAACC,QAAQ,EAAEH,IAAI,KAAKA,IA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AK,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"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useSetPatternBindings;
|
|
7
|
+
var _compose = require("@wordpress/compose");
|
|
8
|
+
var _blocks = require("@wordpress/blocks");
|
|
9
|
+
var _element = require("@wordpress/element");
|
|
10
|
+
var _data = require("@wordpress/data");
|
|
11
|
+
var _constants = require("../constants");
|
|
12
|
+
var _lockUnlock = require("../lock-unlock");
|
|
13
|
+
/**
|
|
14
|
+
* WordPress dependencies
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Internal dependencies
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
function removeBindings(bindings, syncedAttributes) {
|
|
22
|
+
let updatedBindings = {};
|
|
23
|
+
for (const attributeName of syncedAttributes) {
|
|
24
|
+
// Omit any pattern override bindings from the `updatedBindings` object.
|
|
25
|
+
if (bindings?.[attributeName]?.source !== 'core/pattern-overrides' && bindings?.[attributeName]?.source !== undefined) {
|
|
26
|
+
updatedBindings[attributeName] = bindings[attributeName];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (!Object.keys(updatedBindings).length) {
|
|
30
|
+
updatedBindings = undefined;
|
|
31
|
+
}
|
|
32
|
+
return updatedBindings;
|
|
33
|
+
}
|
|
34
|
+
function addBindings(bindings, syncedAttributes) {
|
|
35
|
+
const updatedBindings = {
|
|
36
|
+
...bindings
|
|
37
|
+
};
|
|
38
|
+
for (const attributeName of syncedAttributes) {
|
|
39
|
+
if (!bindings?.[attributeName]) {
|
|
40
|
+
updatedBindings[attributeName] = {
|
|
41
|
+
source: 'core/pattern-overrides'
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return updatedBindings;
|
|
46
|
+
}
|
|
47
|
+
function useSetPatternBindings({
|
|
48
|
+
name,
|
|
49
|
+
attributes,
|
|
50
|
+
setAttributes
|
|
51
|
+
}, currentPostType) {
|
|
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
|
+
}, []);
|
|
61
|
+
const metadataName = (_attributes$metadata$ = attributes?.metadata?.name) !== null && _attributes$metadata$ !== void 0 ? _attributes$metadata$ : '';
|
|
62
|
+
const prevMetadataName = (_usePrevious = (0, _compose.usePrevious)(metadataName)) !== null && _usePrevious !== void 0 ? _usePrevious : '';
|
|
63
|
+
const bindings = attributes?.metadata?.bindings;
|
|
64
|
+
(0, _element.useEffect)(() => {
|
|
65
|
+
// Bindings should only be created when editing a wp_block post type,
|
|
66
|
+
// and also when there's a change to the user-given name for the block.
|
|
67
|
+
// Also check that the pattern overrides source is registered.
|
|
68
|
+
if (!hasPatternOverridesSource || currentPostType !== 'wp_block' || metadataName === prevMetadataName) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const syncedAttributes = _constants.PARTIAL_SYNCING_SUPPORTED_BLOCKS[name];
|
|
72
|
+
const attributeSources = syncedAttributes.map(attributeName => attributes.metadata?.bindings?.[attributeName]?.source);
|
|
73
|
+
const isConnectedToOtherSources = attributeSources.every(source => source && source !== 'core/pattern-overrides');
|
|
74
|
+
|
|
75
|
+
// Avoid overwriting other (e.g. meta) bindings.
|
|
76
|
+
if (isConnectedToOtherSources) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// The user-given name for the block was deleted, remove the bindings.
|
|
81
|
+
if (!metadataName?.length && prevMetadataName?.length) {
|
|
82
|
+
const updatedBindings = removeBindings(bindings, syncedAttributes);
|
|
83
|
+
setAttributes({
|
|
84
|
+
metadata: {
|
|
85
|
+
...attributes.metadata,
|
|
86
|
+
bindings: updatedBindings
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// The user-given name for the block was set, set the bindings.
|
|
92
|
+
if (!prevMetadataName?.length && metadataName.length) {
|
|
93
|
+
const updatedBindings = addBindings(bindings, syncedAttributes);
|
|
94
|
+
setAttributes({
|
|
95
|
+
metadata: {
|
|
96
|
+
...attributes.metadata,
|
|
97
|
+
bindings: updatedBindings
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}, [hasPatternOverridesSource, bindings, prevMetadataName, metadataName, currentPostType, name, attributes.metadata, setAttributes]);
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=use-set-pattern-bindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,eAAe,GAAG;IAAE,GAAGF;EAAS,CAAC;EACvC,KAAM,MAAMG,aAAa,IAAIF,gBAAgB,EAAG;IAC/C,IAAK,CAAED,QAAQ,GAAIG,aAAa,CAAE,EAAG;MACpCD,eAAe,CAAEC,a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AAyB,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"}
|
package/build/constants.js
CHANGED
|
@@ -4,11 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.PATTERN_USER_CATEGORY = exports.PATTERN_TYPES = exports.PATTERN_SYNC_TYPES = exports.PATTERN_DEFAULT_CATEGORY = exports.PARTIAL_SYNCING_SUPPORTED_BLOCKS = exports.EXCLUDED_PATTERN_SOURCES = void 0;
|
|
7
|
-
var _i18n = require("@wordpress/i18n");
|
|
8
|
-
/**
|
|
9
|
-
* WordPress dependencies
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
7
|
const PATTERN_TYPES = exports.PATTERN_TYPES = {
|
|
13
8
|
theme: 'pattern',
|
|
14
9
|
user: 'wp_block'
|
|
@@ -23,23 +18,9 @@ const PATTERN_SYNC_TYPES = exports.PATTERN_SYNC_TYPES = {
|
|
|
23
18
|
|
|
24
19
|
// TODO: This should not be hardcoded. Maybe there should be a config and/or an UI.
|
|
25
20
|
const PARTIAL_SYNCING_SUPPORTED_BLOCKS = exports.PARTIAL_SYNCING_SUPPORTED_BLOCKS = {
|
|
26
|
-
'core/paragraph':
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
'core/
|
|
30
|
-
content: (0, _i18n.__)('Content')
|
|
31
|
-
},
|
|
32
|
-
'core/button': {
|
|
33
|
-
text: (0, _i18n.__)('Text'),
|
|
34
|
-
url: (0, _i18n.__)('URL'),
|
|
35
|
-
linkTarget: (0, _i18n.__)('Link Target'),
|
|
36
|
-
rel: (0, _i18n.__)('Link Relationship')
|
|
37
|
-
},
|
|
38
|
-
'core/image': {
|
|
39
|
-
id: (0, _i18n.__)('Image ID'),
|
|
40
|
-
url: (0, _i18n.__)('URL'),
|
|
41
|
-
title: (0, _i18n.__)('Title'),
|
|
42
|
-
alt: (0, _i18n.__)('Alt Text')
|
|
43
|
-
}
|
|
21
|
+
'core/paragraph': ['content'],
|
|
22
|
+
'core/heading': ['content'],
|
|
23
|
+
'core/button': ['text', 'url', 'linkTarget', 'rel'],
|
|
24
|
+
'core/image': ['id', 'url', 'title', 'alt']
|
|
44
25
|
};
|
|
45
26
|
//# sourceMappingURL=constants.js.map
|
package/build/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["PATTERN_TYPES","exports","theme","user","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","EXCLUDED_PATTERN_SOURCES","PATTERN_SYNC_TYPES","full","unsynced","PARTIAL_SYNCING_SUPPORTED_BLOCKS"],"sources":["@wordpress/patterns/src/constants.js"],"sourcesContent":["export 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' ],\n\t'core/heading': [ 'content' ],\n\t'core/button': [ 'text', 'url', 'linkTarget', 'rel' ],\n\t'core/image': [ 'id', 'url', 'title', 'alt' ],\n};\n"],"mappings":";;;;;;AAAO,MAAMA,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAG;EAC5BE,KAAK,EAAE,SAAS;EAChBC,IAAI,EAAE;AACP,CAAC;AAEM,MAAMC,wBAAwB,GAAAH,OAAA,CAAAG,wBAAA,GAAG,cAAc;AAC/C,MAAMC,qBAAqB,GAAAJ,OAAA,CAAAI,qBAAA,GAAG,aAAa;AAC3C,MAAMC,wBAAwB,GAAAL,OAAA,CAAAK,wBAAA,GAAG,CACvC,MAAM,EACN,wBAAwB,EACxB,4BAA4B,CAC5B;AACM,MAAMC,kBAAkB,GAAAN,OAAA,CAAAM,kBAAA,GAAG;EACjCC,IAAI,EAAE,OAAO;EACbC,QAAQ,EAAE;AACX,CAAC;;AAED;AACO,MAAMC,gCAAgC,GAAAT,OAAA,CAAAS,gCAAA,GAAG;EAC/C,gBAAgB,EAAE,CAAE,SAAS,CAAE;EAC/B,cAAc,EAAE,CAAE,SAAS,CAAE;EAC7B,aAAa,EAAE,CAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,CAAE;EACrD,YAAY,EAAE,CAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK;AAC5C,CAAC"}
|
package/build/private-apis.js
CHANGED
|
@@ -11,7 +11,7 @@ var _duplicatePatternModal = _interopRequireWildcard(require("./components/dupli
|
|
|
11
11
|
var _renamePatternModal = _interopRequireDefault(require("./components/rename-pattern-modal"));
|
|
12
12
|
var _components = _interopRequireDefault(require("./components"));
|
|
13
13
|
var _renamePatternCategoryModal = _interopRequireDefault(require("./components/rename-pattern-category-modal"));
|
|
14
|
-
var
|
|
14
|
+
var _useSetPatternBindings = _interopRequireDefault(require("./components/use-set-pattern-bindings"));
|
|
15
15
|
var _resetOverridesControl = _interopRequireDefault(require("./components/reset-overrides-control"));
|
|
16
16
|
var _privateHooks = require("./private-hooks");
|
|
17
17
|
var _constants = require("./constants");
|
|
@@ -30,7 +30,7 @@ const privateApis = exports.privateApis = {};
|
|
|
30
30
|
RenamePatternModal: _renamePatternModal.default,
|
|
31
31
|
PatternsMenuItems: _components.default,
|
|
32
32
|
RenamePatternCategoryModal: _renamePatternCategoryModal.default,
|
|
33
|
-
|
|
33
|
+
useSetPatternBindings: _useSetPatternBindings.default,
|
|
34
34
|
ResetOverridesControl: _resetOverridesControl.default,
|
|
35
35
|
useAddPatternCategory: _privateHooks.useAddPatternCategory,
|
|
36
36
|
PATTERN_TYPES: _constants.PATTERN_TYPES,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_lockUnlock","require","_createPatternModal","_interopRequireWildcard","_duplicatePatternModal","_renamePatternModal","_interopRequireDefault","_components","_renamePatternCategoryModal","
|
|
1
|
+
{"version":3,"names":["_lockUnlock","require","_createPatternModal","_interopRequireWildcard","_duplicatePatternModal","_renamePatternModal","_interopRequireDefault","_components","_renamePatternCategoryModal","_useSetPatternBindings","_resetOverridesControl","_privateHooks","_constants","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","privateApis","exports","lock","CreatePatternModal","CreatePatternModalContents","DuplicatePatternModal","useDuplicatePatternProps","RenamePatternModal","PatternsMenuItems","RenamePatternCategoryModal","useSetPatternBindings","ResetOverridesControl","useAddPatternCategory","PATTERN_TYPES","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","EXCLUDED_PATTERN_SOURCES","PATTERN_SYNC_TYPES","PARTIAL_SYNCING_SUPPORTED_BLOCKS"],"sources":["@wordpress/patterns/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { lock } from './lock-unlock';\nimport {\n\tdefault as CreatePatternModal,\n\tCreatePatternModalContents,\n} from './components/create-pattern-modal';\nimport {\n\tdefault as DuplicatePatternModal,\n\tuseDuplicatePatternProps,\n} from './components/duplicate-pattern-modal';\nimport RenamePatternModal from './components/rename-pattern-modal';\nimport PatternsMenuItems from './components';\nimport RenamePatternCategoryModal from './components/rename-pattern-category-modal';\nimport useSetPatternBindings from './components/use-set-pattern-bindings';\nimport ResetOverridesControl from './components/reset-overrides-control';\nimport { useAddPatternCategory } from './private-hooks';\nimport {\n\tPATTERN_TYPES,\n\tPATTERN_DEFAULT_CATEGORY,\n\tPATTERN_USER_CATEGORY,\n\tEXCLUDED_PATTERN_SOURCES,\n\tPATTERN_SYNC_TYPES,\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n} from './constants';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tCreatePatternModal,\n\tCreatePatternModalContents,\n\tDuplicatePatternModal,\n\tuseDuplicatePatternProps,\n\tRenamePatternModal,\n\tPatternsMenuItems,\n\tRenamePatternCategoryModal,\n\tuseSetPatternBindings,\n\tResetOverridesControl,\n\tuseAddPatternCategory,\n\tPATTERN_TYPES,\n\tPATTERN_DEFAULT_CATEGORY,\n\tPATTERN_USER_CATEGORY,\n\tEXCLUDED_PATTERN_SOURCES,\n\tPATTERN_SYNC_TYPES,\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n} );\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAC,uBAAA,CAAAF,OAAA;AAIA,IAAAG,sBAAA,GAAAD,uBAAA,CAAAF,OAAA;AAIA,IAAAI,mBAAA,GAA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AAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAgB,GAAA,CAAAnB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AAzBrB;AACA;AACA;;AAyBO,MAAMY,WAAW,GAAAC,OAAA,CAAAD,WAAA,GAAG,CAAC,CAAC;AAC7B,IAAAE,gBAAI,EAAEF,WAAW,EAAE;EAClBG,kBAAkB,EAAlBA,2BAAkB;EAClBC,0BAA0B,EAA1BA,8CAA0B;EAC1BC,qBAAqB,EAArBA,8BAAqB;EACrBC,wBAAwB,EAAxBA,+CAAwB;EACxBC,kBAAkB,EAAlBA,2BAAkB;EAClBC,iBAAiB,EAAjBA,mBAAiB;EACjBC,0BAA0B,EAA1BA,mCAA0B;EAC1BC,qBAAqB,EAArBA,8BAAqB;EACrBC,qBAAqB,EAArBA,8BAAqB;EACrBC,qBAAqB,EAArBA,mCAAqB;EACrBC,aAAa,EAAbA,wBAAa;EACbC,wBAAwB,EAAxBA,mCAAwB;EACxBC,qBAAqB,EAArBA,gCAAqB;EACrBC,wBAAwB,EAAxBA,mCAAwB;EACxBC,kBAAkB,EAAlBA,6BAAkB;EAClBC,gCAAgC,EAAhCA;AACD,CAAE,CAAC"}
|
|
@@ -8,12 +8,12 @@ import { useSelect, useRegistry } from '@wordpress/data';
|
|
|
8
8
|
import { store as coreStore } from '@wordpress/core-data';
|
|
9
9
|
import { parse } from '@wordpress/blocks';
|
|
10
10
|
import { __ } from '@wordpress/i18n';
|
|
11
|
-
function
|
|
11
|
+
function recursivelyFindBlockWithName(blocks, name) {
|
|
12
12
|
for (const block of blocks) {
|
|
13
|
-
if (block.attributes.metadata?.
|
|
13
|
+
if (block.attributes.metadata?.name === name) {
|
|
14
14
|
return block;
|
|
15
15
|
}
|
|
16
|
-
const found =
|
|
16
|
+
const found = recursivelyFindBlockWithName(block.innerBlocks, name);
|
|
17
17
|
if (found) {
|
|
18
18
|
return found;
|
|
19
19
|
}
|
|
@@ -21,9 +21,9 @@ function recursivelyFindBlockWithId(blocks, id) {
|
|
|
21
21
|
}
|
|
22
22
|
export default function ResetOverridesControl(props) {
|
|
23
23
|
const registry = useRegistry();
|
|
24
|
-
const
|
|
24
|
+
const name = props.attributes.metadata?.name;
|
|
25
25
|
const patternWithOverrides = useSelect(select => {
|
|
26
|
-
if (!
|
|
26
|
+
if (!name) {
|
|
27
27
|
return undefined;
|
|
28
28
|
}
|
|
29
29
|
const {
|
|
@@ -31,16 +31,16 @@ export default function ResetOverridesControl(props) {
|
|
|
31
31
|
getBlocksByClientId
|
|
32
32
|
} = select(blockEditorStore);
|
|
33
33
|
const patternBlock = getBlocksByClientId(getBlockParentsByBlockName(props.clientId, 'core/block'))[0];
|
|
34
|
-
if (!patternBlock?.attributes.content?.[
|
|
34
|
+
if (!patternBlock?.attributes.content?.[name]) {
|
|
35
35
|
return undefined;
|
|
36
36
|
}
|
|
37
37
|
return patternBlock;
|
|
38
|
-
}, [props.clientId,
|
|
38
|
+
}, [props.clientId, name]);
|
|
39
39
|
const resetOverrides = async () => {
|
|
40
40
|
var _editedRecord$blocks;
|
|
41
41
|
const editedRecord = await registry.resolveSelect(coreStore).getEditedEntityRecord('postType', 'wp_block', patternWithOverrides.attributes.ref);
|
|
42
42
|
const blocks = (_editedRecord$blocks = editedRecord.blocks) !== null && _editedRecord$blocks !== void 0 ? _editedRecord$blocks : parse(editedRecord.content);
|
|
43
|
-
const block =
|
|
43
|
+
const block = recursivelyFindBlockWithName(blocks, name);
|
|
44
44
|
const newAttributes = Object.assign(
|
|
45
45
|
// Reset every existing attribute to undefined.
|
|
46
46
|
Object.fromEntries(Object.keys(props.attributes).map(key => [key, undefined])),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["store","blockEditorStore","BlockControls","ToolbarButton","ToolbarGroup","useSelect","useRegistry","coreStore","parse","__","
|
|
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,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GH,4BAA4B,CAAEC,MAAM,EAAEC,IAAK,CAAC;IAE1D,MAAMuB,aAAa,GAAGC,MAAM,CAACC,MAAM;IAClC;IACAD,MAAM,CAACE,WAAW,CACjBF,MAAM,CAACG,IAAI,CAAEpB,KAAK,CAACL,UAAW,CAAC,CAAC0B,GAAG,CAAIC,GAAG,IAAM,CAC/CA,GAAG,EACHlB,SAAS,CACR,CACH,CAAC;IACD;IACAV,KAAK,CAACC,UACP,CAAC;IAEDK,KAAK,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"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { usePrevious } from '@wordpress/compose';
|
|
5
|
+
import { store as blocksStore } from '@wordpress/blocks';
|
|
6
|
+
import { useEffect } from '@wordpress/element';
|
|
7
|
+
import { useSelect } from '@wordpress/data';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';
|
|
13
|
+
import { unlock } from '../lock-unlock';
|
|
14
|
+
function removeBindings(bindings, syncedAttributes) {
|
|
15
|
+
let updatedBindings = {};
|
|
16
|
+
for (const attributeName of syncedAttributes) {
|
|
17
|
+
// Omit any pattern override bindings from the `updatedBindings` object.
|
|
18
|
+
if (bindings?.[attributeName]?.source !== 'core/pattern-overrides' && bindings?.[attributeName]?.source !== undefined) {
|
|
19
|
+
updatedBindings[attributeName] = bindings[attributeName];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (!Object.keys(updatedBindings).length) {
|
|
23
|
+
updatedBindings = undefined;
|
|
24
|
+
}
|
|
25
|
+
return updatedBindings;
|
|
26
|
+
}
|
|
27
|
+
function addBindings(bindings, syncedAttributes) {
|
|
28
|
+
const updatedBindings = {
|
|
29
|
+
...bindings
|
|
30
|
+
};
|
|
31
|
+
for (const attributeName of syncedAttributes) {
|
|
32
|
+
if (!bindings?.[attributeName]) {
|
|
33
|
+
updatedBindings[attributeName] = {
|
|
34
|
+
source: 'core/pattern-overrides'
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return updatedBindings;
|
|
39
|
+
}
|
|
40
|
+
export default function useSetPatternBindings({
|
|
41
|
+
name,
|
|
42
|
+
attributes,
|
|
43
|
+
setAttributes
|
|
44
|
+
}, currentPostType) {
|
|
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
|
+
}, []);
|
|
54
|
+
const metadataName = (_attributes$metadata$ = attributes?.metadata?.name) !== null && _attributes$metadata$ !== void 0 ? _attributes$metadata$ : '';
|
|
55
|
+
const prevMetadataName = (_usePrevious = usePrevious(metadataName)) !== null && _usePrevious !== void 0 ? _usePrevious : '';
|
|
56
|
+
const bindings = attributes?.metadata?.bindings;
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
// Bindings should only be created when editing a wp_block post type,
|
|
59
|
+
// and also when there's a change to the user-given name for the block.
|
|
60
|
+
// Also check that the pattern overrides source is registered.
|
|
61
|
+
if (!hasPatternOverridesSource || currentPostType !== 'wp_block' || metadataName === prevMetadataName) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[name];
|
|
65
|
+
const attributeSources = syncedAttributes.map(attributeName => attributes.metadata?.bindings?.[attributeName]?.source);
|
|
66
|
+
const isConnectedToOtherSources = attributeSources.every(source => source && source !== 'core/pattern-overrides');
|
|
67
|
+
|
|
68
|
+
// Avoid overwriting other (e.g. meta) bindings.
|
|
69
|
+
if (isConnectedToOtherSources) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// The user-given name for the block was deleted, remove the bindings.
|
|
74
|
+
if (!metadataName?.length && prevMetadataName?.length) {
|
|
75
|
+
const updatedBindings = removeBindings(bindings, syncedAttributes);
|
|
76
|
+
setAttributes({
|
|
77
|
+
metadata: {
|
|
78
|
+
...attributes.metadata,
|
|
79
|
+
bindings: updatedBindings
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// The user-given name for the block was set, set the bindings.
|
|
85
|
+
if (!prevMetadataName?.length && metadataName.length) {
|
|
86
|
+
const updatedBindings = addBindings(bindings, syncedAttributes);
|
|
87
|
+
setAttributes({
|
|
88
|
+
metadata: {
|
|
89
|
+
...attributes.metadata,
|
|
90
|
+
bindings: updatedBindings
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}, [hasPatternOverridesSource, bindings, prevMetadataName, metadataName, currentPostType, name, attributes.metadata, setAttributes]);
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=use-set-pattern-bindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAC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A;IACA,IAAK,CAAEoB,gBAAgB,EAAEd,MAAM,IAAIY,YAAY,CAACZ,MAAM,EAAG;MACxD,MAAMN,eAAe,GAAGO,WAAW,CAAET,QAAQ,EAAEC,gBAAiB,CAAC;MACjEY,aAAa,CAAE;QACdQ,QAAQ,EAAE;UACT,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"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { __ } from '@wordpress/i18n';
|
|
5
1
|
export const PATTERN_TYPES = {
|
|
6
2
|
theme: 'pattern',
|
|
7
3
|
user: 'wp_block'
|
|
@@ -16,23 +12,9 @@ export const PATTERN_SYNC_TYPES = {
|
|
|
16
12
|
|
|
17
13
|
// TODO: This should not be hardcoded. Maybe there should be a config and/or an UI.
|
|
18
14
|
export const PARTIAL_SYNCING_SUPPORTED_BLOCKS = {
|
|
19
|
-
'core/paragraph':
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
'core/
|
|
23
|
-
content: __('Content')
|
|
24
|
-
},
|
|
25
|
-
'core/button': {
|
|
26
|
-
text: __('Text'),
|
|
27
|
-
url: __('URL'),
|
|
28
|
-
linkTarget: __('Link Target'),
|
|
29
|
-
rel: __('Link Relationship')
|
|
30
|
-
},
|
|
31
|
-
'core/image': {
|
|
32
|
-
id: __('Image ID'),
|
|
33
|
-
url: __('URL'),
|
|
34
|
-
title: __('Title'),
|
|
35
|
-
alt: __('Alt Text')
|
|
36
|
-
}
|
|
15
|
+
'core/paragraph': ['content'],
|
|
16
|
+
'core/heading': ['content'],
|
|
17
|
+
'core/button': ['text', 'url', 'linkTarget', 'rel'],
|
|
18
|
+
'core/image': ['id', 'url', 'title', 'alt']
|
|
37
19
|
};
|
|
38
20
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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"],"sources":["@wordpress/patterns/src/constants.js"],"sourcesContent":["export 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' ],\n\t'core/heading': [ 'content' ],\n\t'core/button': [ 'text', 'url', 'linkTarget', 'rel' ],\n\t'core/image': [ 'id', 'url', 'title', 'alt' ],\n};\n"],"mappings":"AAAA,OAAO,MAAMA,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,CAAE,SAAS,CAAE;EAC/B,cAAc,EAAE,CAAE,SAAS,CAAE;EAC7B,aAAa,EAAE,CAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,CAAE;EACrD,YAAY,EAAE,CAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK;AAC5C,CAAC"}
|
|
@@ -7,7 +7,7 @@ import { default as DuplicatePatternModal, useDuplicatePatternProps } from './co
|
|
|
7
7
|
import RenamePatternModal from './components/rename-pattern-modal';
|
|
8
8
|
import PatternsMenuItems from './components';
|
|
9
9
|
import RenamePatternCategoryModal from './components/rename-pattern-category-modal';
|
|
10
|
-
import
|
|
10
|
+
import useSetPatternBindings from './components/use-set-pattern-bindings';
|
|
11
11
|
import ResetOverridesControl from './components/reset-overrides-control';
|
|
12
12
|
import { useAddPatternCategory } from './private-hooks';
|
|
13
13
|
import { PATTERN_TYPES, PATTERN_DEFAULT_CATEGORY, PATTERN_USER_CATEGORY, EXCLUDED_PATTERN_SOURCES, PATTERN_SYNC_TYPES, PARTIAL_SYNCING_SUPPORTED_BLOCKS } from './constants';
|
|
@@ -20,7 +20,7 @@ lock(privateApis, {
|
|
|
20
20
|
RenamePatternModal,
|
|
21
21
|
PatternsMenuItems,
|
|
22
22
|
RenamePatternCategoryModal,
|
|
23
|
-
|
|
23
|
+
useSetPatternBindings,
|
|
24
24
|
ResetOverridesControl,
|
|
25
25
|
useAddPatternCategory,
|
|
26
26
|
PATTERN_TYPES,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["lock","default","CreatePatternModal","CreatePatternModalContents","DuplicatePatternModal","useDuplicatePatternProps","RenamePatternModal","PatternsMenuItems","RenamePatternCategoryModal","
|
|
1
|
+
{"version":3,"names":["lock","default","CreatePatternModal","CreatePatternModalContents","DuplicatePatternModal","useDuplicatePatternProps","RenamePatternModal","PatternsMenuItems","RenamePatternCategoryModal","useSetPatternBindings","ResetOverridesControl","useAddPatternCategory","PATTERN_TYPES","PATTERN_DEFAULT_CATEGORY","PATTERN_USER_CATEGORY","EXCLUDED_PATTERN_SOURCES","PATTERN_SYNC_TYPES","PARTIAL_SYNCING_SUPPORTED_BLOCKS","privateApis"],"sources":["@wordpress/patterns/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { lock } from './lock-unlock';\nimport {\n\tdefault as CreatePatternModal,\n\tCreatePatternModalContents,\n} from './components/create-pattern-modal';\nimport {\n\tdefault as DuplicatePatternModal,\n\tuseDuplicatePatternProps,\n} from './components/duplicate-pattern-modal';\nimport RenamePatternModal from './components/rename-pattern-modal';\nimport PatternsMenuItems from './components';\nimport RenamePatternCategoryModal from './components/rename-pattern-category-modal';\nimport useSetPatternBindings from './components/use-set-pattern-bindings';\nimport ResetOverridesControl from './components/reset-overrides-control';\nimport { useAddPatternCategory } from './private-hooks';\nimport {\n\tPATTERN_TYPES,\n\tPATTERN_DEFAULT_CATEGORY,\n\tPATTERN_USER_CATEGORY,\n\tEXCLUDED_PATTERN_SOURCES,\n\tPATTERN_SYNC_TYPES,\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n} from './constants';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tCreatePatternModal,\n\tCreatePatternModalContents,\n\tDuplicatePatternModal,\n\tuseDuplicatePatternProps,\n\tRenamePatternModal,\n\tPatternsMenuItems,\n\tRenamePatternCategoryModal,\n\tuseSetPatternBindings,\n\tResetOverridesControl,\n\tuseAddPatternCategory,\n\tPATTERN_TYPES,\n\tPATTERN_DEFAULT_CATEGORY,\n\tPATTERN_USER_CATEGORY,\n\tEXCLUDED_PATTERN_SOURCES,\n\tPATTERN_SYNC_TYPES,\n\tPARTIAL_SYNCING_SUPPORTED_BLOCKS,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAI,QAAQ,eAAe;AACpC,SACCC,OAAO,IAAIC,kBAAkB,EAC7BC,0BAA0B,QACpB,mCAAmC;AAC1C,SACCF,OAAO,IAAIG,qBAAqB,EAChCC,wBAAwB,QAClB,sCAAsC;AAC7C,OAAOC,kBAAkB,MAAM,mCAAmC;AAClE,OAAOC,iBAAiB,MAAM,cAAc;AAC5C,OAAOC,0BAA0B,MAAM,4CAA4C;AACnF,OAAOC,qBAAqB,MAAM,uCAAuC;AACzE,OAAOC,qBAAqB,MAAM,sCAAsC;AACxE,SAASC,qBAAqB,QAAQ,iBAAiB;AACvD,SACCC,aAAa,EACbC,wBAAwB,EACxBC,qBAAqB,EACrBC,wBAAwB,EACxBC,kBAAkB,EAClBC,gCAAgC,QAC1B,aAAa;AAEpB,OAAO,MAAMC,WAAW,GAAG,CAAC,CAAC;AAC7BlB,IAAI,CAAEkB,WAAW,EAAE;EAClBhB,kBAAkB;EAClBC,0BAA0B;EAC1BC,qBAAqB;EACrBC,wBAAwB;EACxBC,kBAAkB;EAClBC,iBAAiB;EACjBC,0BAA0B;EAC1BC,qBAAqB;EACrBC,qBAAqB;EACrBC,qBAAqB;EACrBC,aAAa;EACbC,wBAAwB;EACxBC,qBAAqB;EACrBC,wBAAwB;EACxBC,kBAAkB;EAClBC;AACD,CAAE,CAAC"}
|
package/build-style/style.css
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/patterns",
|
|
3
|
-
"version": "1.
|
|
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,21 +31,20 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/runtime": "^7.16.0",
|
|
34
|
-
"@wordpress/a11y": "^3.
|
|
35
|
-
"@wordpress/block-editor": "^12.
|
|
36
|
-
"@wordpress/blocks": "^12.
|
|
37
|
-
"@wordpress/components": "^27.
|
|
38
|
-
"@wordpress/compose": "^6.
|
|
39
|
-
"@wordpress/core-data": "^6.
|
|
40
|
-
"@wordpress/data": "^9.
|
|
41
|
-
"@wordpress/element": "^5.
|
|
42
|
-
"@wordpress/html-entities": "^3.
|
|
43
|
-
"@wordpress/i18n": "^4.
|
|
44
|
-
"@wordpress/icons": "^9.
|
|
45
|
-
"@wordpress/notices": "^4.
|
|
46
|
-
"@wordpress/private-apis": "^0.
|
|
47
|
-
"@wordpress/url": "^3.
|
|
48
|
-
"nanoid": "^3.3.4"
|
|
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"
|
|
49
48
|
},
|
|
50
49
|
"peerDependencies": {
|
|
51
50
|
"react": "^18.0.0",
|
|
@@ -54,5 +53,5 @@
|
|
|
54
53
|
"publishConfig": {
|
|
55
54
|
"access": "public"
|
|
56
55
|
},
|
|
57
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "ffc07735d0abfb3f69e91d48f25b7fe8d1ef92d2"
|
|
58
57
|
}
|
|
@@ -11,13 +11,13 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
11
11
|
import { parse } from '@wordpress/blocks';
|
|
12
12
|
import { __ } from '@wordpress/i18n';
|
|
13
13
|
|
|
14
|
-
function
|
|
14
|
+
function recursivelyFindBlockWithName( blocks, name ) {
|
|
15
15
|
for ( const block of blocks ) {
|
|
16
|
-
if ( block.attributes.metadata?.
|
|
16
|
+
if ( block.attributes.metadata?.name === name ) {
|
|
17
17
|
return block;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const found =
|
|
20
|
+
const found = recursivelyFindBlockWithName( block.innerBlocks, name );
|
|
21
21
|
if ( found ) {
|
|
22
22
|
return found;
|
|
23
23
|
}
|
|
@@ -26,10 +26,10 @@ function recursivelyFindBlockWithId( blocks, id ) {
|
|
|
26
26
|
|
|
27
27
|
export default function ResetOverridesControl( props ) {
|
|
28
28
|
const registry = useRegistry();
|
|
29
|
-
const
|
|
29
|
+
const name = props.attributes.metadata?.name;
|
|
30
30
|
const patternWithOverrides = useSelect(
|
|
31
31
|
( select ) => {
|
|
32
|
-
if ( !
|
|
32
|
+
if ( ! name ) {
|
|
33
33
|
return undefined;
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -39,13 +39,13 @@ export default function ResetOverridesControl( props ) {
|
|
|
39
39
|
getBlockParentsByBlockName( props.clientId, 'core/block' )
|
|
40
40
|
)[ 0 ];
|
|
41
41
|
|
|
42
|
-
if ( ! patternBlock?.attributes.content?.[
|
|
42
|
+
if ( ! patternBlock?.attributes.content?.[ name ] ) {
|
|
43
43
|
return undefined;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
return patternBlock;
|
|
47
47
|
},
|
|
48
|
-
[ props.clientId,
|
|
48
|
+
[ props.clientId, name ]
|
|
49
49
|
);
|
|
50
50
|
|
|
51
51
|
const resetOverrides = async () => {
|
|
@@ -57,7 +57,7 @@ export default function ResetOverridesControl( props ) {
|
|
|
57
57
|
patternWithOverrides.attributes.ref
|
|
58
58
|
);
|
|
59
59
|
const blocks = editedRecord.blocks ?? parse( editedRecord.content );
|
|
60
|
-
const block =
|
|
60
|
+
const block = recursivelyFindBlockWithName( blocks, name );
|
|
61
61
|
|
|
62
62
|
const newAttributes = Object.assign(
|
|
63
63
|
// Reset every existing attribute to undefined.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { usePrevious } from '@wordpress/compose';
|
|
5
|
+
import { store as blocksStore } from '@wordpress/blocks';
|
|
6
|
+
import { useEffect } from '@wordpress/element';
|
|
7
|
+
import { useSelect } from '@wordpress/data';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';
|
|
13
|
+
|
|
14
|
+
import { unlock } from '../lock-unlock';
|
|
15
|
+
|
|
16
|
+
function removeBindings( bindings, syncedAttributes ) {
|
|
17
|
+
let updatedBindings = {};
|
|
18
|
+
for ( const attributeName of syncedAttributes ) {
|
|
19
|
+
// Omit any pattern override bindings from the `updatedBindings` object.
|
|
20
|
+
if (
|
|
21
|
+
bindings?.[ attributeName ]?.source !== 'core/pattern-overrides' &&
|
|
22
|
+
bindings?.[ attributeName ]?.source !== undefined
|
|
23
|
+
) {
|
|
24
|
+
updatedBindings[ attributeName ] = bindings[ attributeName ];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if ( ! Object.keys( updatedBindings ).length ) {
|
|
28
|
+
updatedBindings = undefined;
|
|
29
|
+
}
|
|
30
|
+
return updatedBindings;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function addBindings( bindings, syncedAttributes ) {
|
|
34
|
+
const updatedBindings = { ...bindings };
|
|
35
|
+
for ( const attributeName of syncedAttributes ) {
|
|
36
|
+
if ( ! bindings?.[ attributeName ] ) {
|
|
37
|
+
updatedBindings[ attributeName ] = {
|
|
38
|
+
source: 'core/pattern-overrides',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return updatedBindings;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default function useSetPatternBindings(
|
|
46
|
+
{ name, attributes, setAttributes },
|
|
47
|
+
currentPostType
|
|
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
|
+
|
|
56
|
+
const metadataName = attributes?.metadata?.name ?? '';
|
|
57
|
+
const prevMetadataName = usePrevious( metadataName ) ?? '';
|
|
58
|
+
const bindings = attributes?.metadata?.bindings;
|
|
59
|
+
|
|
60
|
+
useEffect( () => {
|
|
61
|
+
// Bindings should only be created when editing a wp_block post type,
|
|
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.
|
|
64
|
+
if (
|
|
65
|
+
! hasPatternOverridesSource ||
|
|
66
|
+
currentPostType !== 'wp_block' ||
|
|
67
|
+
metadataName === prevMetadataName
|
|
68
|
+
) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];
|
|
73
|
+
const attributeSources = syncedAttributes.map(
|
|
74
|
+
( attributeName ) =>
|
|
75
|
+
attributes.metadata?.bindings?.[ attributeName ]?.source
|
|
76
|
+
);
|
|
77
|
+
const isConnectedToOtherSources = attributeSources.every(
|
|
78
|
+
( source ) => source && source !== 'core/pattern-overrides'
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// Avoid overwriting other (e.g. meta) bindings.
|
|
82
|
+
if ( isConnectedToOtherSources ) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// The user-given name for the block was deleted, remove the bindings.
|
|
87
|
+
if ( ! metadataName?.length && prevMetadataName?.length ) {
|
|
88
|
+
const updatedBindings = removeBindings(
|
|
89
|
+
bindings,
|
|
90
|
+
syncedAttributes
|
|
91
|
+
);
|
|
92
|
+
setAttributes( {
|
|
93
|
+
metadata: {
|
|
94
|
+
...attributes.metadata,
|
|
95
|
+
bindings: updatedBindings,
|
|
96
|
+
},
|
|
97
|
+
} );
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// The user-given name for the block was set, set the bindings.
|
|
101
|
+
if ( ! prevMetadataName?.length && metadataName.length ) {
|
|
102
|
+
const updatedBindings = addBindings( bindings, syncedAttributes );
|
|
103
|
+
setAttributes( {
|
|
104
|
+
metadata: {
|
|
105
|
+
...attributes.metadata,
|
|
106
|
+
bindings: updatedBindings,
|
|
107
|
+
},
|
|
108
|
+
} );
|
|
109
|
+
}
|
|
110
|
+
}, [
|
|
111
|
+
hasPatternOverridesSource,
|
|
112
|
+
bindings,
|
|
113
|
+
prevMetadataName,
|
|
114
|
+
metadataName,
|
|
115
|
+
currentPostType,
|
|
116
|
+
name,
|
|
117
|
+
attributes.metadata,
|
|
118
|
+
setAttributes,
|
|
119
|
+
] );
|
|
120
|
+
}
|
package/src/constants.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { __ } from '@wordpress/i18n';
|
|
5
|
-
|
|
6
1
|
export const PATTERN_TYPES = {
|
|
7
2
|
theme: 'pattern',
|
|
8
3
|
user: 'wp_block',
|
|
@@ -22,18 +17,8 @@ export const PATTERN_SYNC_TYPES = {
|
|
|
22
17
|
|
|
23
18
|
// TODO: This should not be hardcoded. Maybe there should be a config and/or an UI.
|
|
24
19
|
export const PARTIAL_SYNCING_SUPPORTED_BLOCKS = {
|
|
25
|
-
'core/paragraph':
|
|
26
|
-
'core/heading':
|
|
27
|
-
'core/button':
|
|
28
|
-
|
|
29
|
-
url: __( 'URL' ),
|
|
30
|
-
linkTarget: __( 'Link Target' ),
|
|
31
|
-
rel: __( 'Link Relationship' ),
|
|
32
|
-
},
|
|
33
|
-
'core/image': {
|
|
34
|
-
id: __( 'Image ID' ),
|
|
35
|
-
url: __( 'URL' ),
|
|
36
|
-
title: __( 'Title' ),
|
|
37
|
-
alt: __( 'Alt Text' ),
|
|
38
|
-
},
|
|
20
|
+
'core/paragraph': [ 'content' ],
|
|
21
|
+
'core/heading': [ 'content' ],
|
|
22
|
+
'core/button': [ 'text', 'url', 'linkTarget', 'rel' ],
|
|
23
|
+
'core/image': [ 'id', 'url', 'title', 'alt' ],
|
|
39
24
|
};
|
package/src/private-apis.js
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
import RenamePatternModal from './components/rename-pattern-modal';
|
|
14
14
|
import PatternsMenuItems from './components';
|
|
15
15
|
import RenamePatternCategoryModal from './components/rename-pattern-category-modal';
|
|
16
|
-
import
|
|
16
|
+
import useSetPatternBindings from './components/use-set-pattern-bindings';
|
|
17
17
|
import ResetOverridesControl from './components/reset-overrides-control';
|
|
18
18
|
import { useAddPatternCategory } from './private-hooks';
|
|
19
19
|
import {
|
|
@@ -34,7 +34,7 @@ lock( privateApis, {
|
|
|
34
34
|
RenamePatternModal,
|
|
35
35
|
PatternsMenuItems,
|
|
36
36
|
RenamePatternCategoryModal,
|
|
37
|
-
|
|
37
|
+
useSetPatternBindings,
|
|
38
38
|
ResetOverridesControl,
|
|
39
39
|
useAddPatternCategory,
|
|
40
40
|
PATTERN_TYPES,
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _nanoid = require("nanoid");
|
|
9
|
-
var _blockEditor = require("@wordpress/block-editor");
|
|
10
|
-
var _components = require("@wordpress/components");
|
|
11
|
-
var _i18n = require("@wordpress/i18n");
|
|
12
|
-
var _constants = require("../constants");
|
|
13
|
-
/**
|
|
14
|
-
* External dependencies
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* WordPress dependencies
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Internal dependencies
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
function PartialSyncingControls({
|
|
26
|
-
name,
|
|
27
|
-
attributes,
|
|
28
|
-
setAttributes
|
|
29
|
-
}) {
|
|
30
|
-
const syncedAttributes = _constants.PARTIAL_SYNCING_SUPPORTED_BLOCKS[name];
|
|
31
|
-
const attributeSources = Object.keys(syncedAttributes).map(attributeName => attributes.metadata?.bindings?.[attributeName]?.source);
|
|
32
|
-
const isConnectedToOtherSources = attributeSources.every(source => source && source !== 'core/pattern-overrides');
|
|
33
|
-
|
|
34
|
-
// Render nothing if all supported attributes are connected to other sources.
|
|
35
|
-
if (isConnectedToOtherSources) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
function updateBindings(isChecked) {
|
|
39
|
-
let updatedBindings = {
|
|
40
|
-
...attributes?.metadata?.bindings
|
|
41
|
-
};
|
|
42
|
-
if (!isChecked) {
|
|
43
|
-
for (const attributeName of Object.keys(syncedAttributes)) {
|
|
44
|
-
if (updatedBindings[attributeName]?.source === 'core/pattern-overrides') {
|
|
45
|
-
delete updatedBindings[attributeName];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (!Object.keys(updatedBindings).length) {
|
|
49
|
-
updatedBindings = undefined;
|
|
50
|
-
}
|
|
51
|
-
setAttributes({
|
|
52
|
-
metadata: {
|
|
53
|
-
...attributes.metadata,
|
|
54
|
-
bindings: updatedBindings
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
for (const attributeName of Object.keys(syncedAttributes)) {
|
|
60
|
-
if (!updatedBindings[attributeName]) {
|
|
61
|
-
updatedBindings[attributeName] = {
|
|
62
|
-
source: 'core/pattern-overrides'
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (typeof attributes.metadata?.id === 'string') {
|
|
67
|
-
setAttributes({
|
|
68
|
-
metadata: {
|
|
69
|
-
...attributes.metadata,
|
|
70
|
-
bindings: updatedBindings
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const id = (0, _nanoid.nanoid)(6);
|
|
76
|
-
setAttributes({
|
|
77
|
-
metadata: {
|
|
78
|
-
...attributes.metadata,
|
|
79
|
-
id,
|
|
80
|
-
bindings: updatedBindings
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
return (0, _react.createElement)(_blockEditor.InspectorControls, {
|
|
85
|
-
group: "advanced"
|
|
86
|
-
}, (0, _react.createElement)(_components.BaseControl, {
|
|
87
|
-
__nextHasNoMarginBottom: true
|
|
88
|
-
}, (0, _react.createElement)(_components.BaseControl.VisualLabel, null, (0, _i18n.__)('Pattern overrides')), (0, _react.createElement)(_components.CheckboxControl, {
|
|
89
|
-
__nextHasNoMarginBottom: true,
|
|
90
|
-
label: (0, _i18n.__)('Allow instance overrides'),
|
|
91
|
-
checked: attributeSources.some(source => source === 'core/pattern-overrides'),
|
|
92
|
-
onChange: isChecked => {
|
|
93
|
-
updateBindings(isChecked);
|
|
94
|
-
}
|
|
95
|
-
})));
|
|
96
|
-
}
|
|
97
|
-
var _default = exports.default = PartialSyncingControls;
|
|
98
|
-
//# sourceMappingURL=partial-syncing-controls.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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\n\t);\n\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t( source ) => source && source !== 'core/pattern-overrides'\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 ===\n\t\t\t\t\t'core/pattern-overrides'\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: 'core/pattern-overrides',\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 === 'core/pattern-overrides'\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;;AAGA,SAASK,sBAAsBA,CAAE;EAAEC,IAAI;EAAEC,UAAU;EAAEC;AAAc,CAAC,EAAG;EACtE,MAAMC,gBAAgB,GAAGC,2CAAgC,C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E;QACdQ,QAAQ,EAAE;UACT,GAAGT,UAAU,CAACS,QAAQ;UACtBC,QAAQ,EAAEM;QACX;MACD,CAAE,CAAC;MACH;IACD;IAEA,MAAMG,EAAE,GAAG,IAAAC,cAAM,EAAE,CAAE,CAAC;IACtBnB,aAAa,CAAE;MACdQ,QAAQ,EAAE;QACT,GAAGT,UAAU,CAACS,QAAQ;QACtBU,EAAE;QACFT,QAAQ,EAAEM;MACX;IACD,CAAE,CAAC;EACJ;EAEA,OACC,IAAAK,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,CAC5BrB,MAAM,IAAMA,MAAM,KAAK,wBAC1B,CAAG;IACHsB,QAAQ,EAAKlB,SAAS,IAAM;MAC3BD,cAAc,CAAEC,SAAU,CAAC;IAC5B;EAAG,CACH,CACW,CACK,CAAC;AAEtB;AAAC,IAAAmB,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEctC,sBAAsB"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { createElement } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* External dependencies
|
|
4
|
-
*/
|
|
5
|
-
import { nanoid } from 'nanoid';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* WordPress dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { InspectorControls } from '@wordpress/block-editor';
|
|
11
|
-
import { BaseControl, CheckboxControl } from '@wordpress/components';
|
|
12
|
-
import { __ } from '@wordpress/i18n';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Internal dependencies
|
|
16
|
-
*/
|
|
17
|
-
import { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';
|
|
18
|
-
function PartialSyncingControls({
|
|
19
|
-
name,
|
|
20
|
-
attributes,
|
|
21
|
-
setAttributes
|
|
22
|
-
}) {
|
|
23
|
-
const syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[name];
|
|
24
|
-
const attributeSources = Object.keys(syncedAttributes).map(attributeName => attributes.metadata?.bindings?.[attributeName]?.source);
|
|
25
|
-
const isConnectedToOtherSources = attributeSources.every(source => source && source !== 'core/pattern-overrides');
|
|
26
|
-
|
|
27
|
-
// Render nothing if all supported attributes are connected to other sources.
|
|
28
|
-
if (isConnectedToOtherSources) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
function updateBindings(isChecked) {
|
|
32
|
-
let updatedBindings = {
|
|
33
|
-
...attributes?.metadata?.bindings
|
|
34
|
-
};
|
|
35
|
-
if (!isChecked) {
|
|
36
|
-
for (const attributeName of Object.keys(syncedAttributes)) {
|
|
37
|
-
if (updatedBindings[attributeName]?.source === 'core/pattern-overrides') {
|
|
38
|
-
delete updatedBindings[attributeName];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (!Object.keys(updatedBindings).length) {
|
|
42
|
-
updatedBindings = undefined;
|
|
43
|
-
}
|
|
44
|
-
setAttributes({
|
|
45
|
-
metadata: {
|
|
46
|
-
...attributes.metadata,
|
|
47
|
-
bindings: updatedBindings
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
for (const attributeName of Object.keys(syncedAttributes)) {
|
|
53
|
-
if (!updatedBindings[attributeName]) {
|
|
54
|
-
updatedBindings[attributeName] = {
|
|
55
|
-
source: 'core/pattern-overrides'
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (typeof attributes.metadata?.id === 'string') {
|
|
60
|
-
setAttributes({
|
|
61
|
-
metadata: {
|
|
62
|
-
...attributes.metadata,
|
|
63
|
-
bindings: updatedBindings
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const id = nanoid(6);
|
|
69
|
-
setAttributes({
|
|
70
|
-
metadata: {
|
|
71
|
-
...attributes.metadata,
|
|
72
|
-
id,
|
|
73
|
-
bindings: updatedBindings
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
return createElement(InspectorControls, {
|
|
78
|
-
group: "advanced"
|
|
79
|
-
}, createElement(BaseControl, {
|
|
80
|
-
__nextHasNoMarginBottom: true
|
|
81
|
-
}, createElement(BaseControl.VisualLabel, null, __('Pattern overrides')), createElement(CheckboxControl, {
|
|
82
|
-
__nextHasNoMarginBottom: true,
|
|
83
|
-
label: __('Allow instance overrides'),
|
|
84
|
-
checked: attributeSources.some(source => source === 'core/pattern-overrides'),
|
|
85
|
-
onChange: isChecked => {
|
|
86
|
-
updateBindings(isChecked);
|
|
87
|
-
}
|
|
88
|
-
})));
|
|
89
|
-
}
|
|
90
|
-
export default PartialSyncingControls;
|
|
91
|
-
//# sourceMappingURL=partial-syncing-controls.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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\n\t);\n\tconst isConnectedToOtherSources = attributeSources.every(\n\t\t( source ) => source && source !== 'core/pattern-overrides'\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 ===\n\t\t\t\t\t'core/pattern-overrides'\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: 'core/pattern-overrides',\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 === 'core/pattern-overrides'\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":";AAAA;AACA;AACA;AACA,SAASA,MAAM,QAAQ,QAAQ;;AAE/B;AACA;AACA;AACA,SAASC,iBAAiB,QAAQ,yBAAyB;AAC3D,SAASC,WAAW,EAAEC,eAAe,QAAQ,uBAAuB;AACpE,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,SAASC,gCAAgC,QAAQ,cAAc;AAE/D,SAASC,sBAAsBA,CAAE;EAAEC,IAAI;EAAEC,UAAU;EAAEC;AAAc,CAAC,EAAG;EACtE,MAAMC,gBAAgB,GAAGL,gCAAgC,CAAEE,IAAI,CAAE;EACjE,MAAMI,gBAAgB,GAAGC,MAAM,CAAC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BC,QAAQ,EAAEM;QACX;MACD,CAAE,CAAC;MACH;IACD;IAEA,MAAMG,EAAE,GAAG1B,MAAM,CAAE,CAAE,CAAC;IACtBS,aAAa,CAAE;MACdO,QAAQ,EAAE;QACT,GAAGR,UAAU,CAACQ,QAAQ;QACtBU,EAAE;QACFT,QAAQ,EAAEM;MACX;IACD,CAAE,CAAC;EACJ;EAEA,OACCI,aAAA,CAAC1B,iBAAiB;IAAC2B,KAAK,EAAC;EAAU,GAClCD,aAAA,CAACzB,WAAW;IAAC2B,uBAAuB;EAAA,GACnCF,aAAA,CAACzB,WAAW,CAAC4B,WAAW,QACrB1B,EAAE,CAAE,mBAAoB,CACF,CAAC,EAC1BuB,aAAA,CAACxB,eAAe;IACf0B,uBAAuB;IACvBE,KAAK,EAAG3B,EAAE,CAAE,0BAA2B,CAAG;IAC1C4B,OAAO,EAAGrB,gBAAgB,CAACsB,IAAI,CAC5Bf,MAAM,IAAMA,MAAM,KAAK,wBAC1B,CAAG;IACHgB,QAAQ,EAAKZ,SAAS,IAAM;MAC3BD,cAAc,CAAEC,SAAU,CAAC;IAC5B;EAAG,CACH,CACW,CACK,CAAC;AAEtB;AAEA,eAAehB,sBAAsB"}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { nanoid } from 'nanoid';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { InspectorControls } from '@wordpress/block-editor';
|
|
10
|
-
import { BaseControl, CheckboxControl } from '@wordpress/components';
|
|
11
|
-
import { __ } from '@wordpress/i18n';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Internal dependencies
|
|
15
|
-
*/
|
|
16
|
-
import { PARTIAL_SYNCING_SUPPORTED_BLOCKS } from '../constants';
|
|
17
|
-
|
|
18
|
-
function PartialSyncingControls( { name, attributes, setAttributes } ) {
|
|
19
|
-
const syncedAttributes = PARTIAL_SYNCING_SUPPORTED_BLOCKS[ name ];
|
|
20
|
-
const attributeSources = Object.keys( syncedAttributes ).map(
|
|
21
|
-
( attributeName ) =>
|
|
22
|
-
attributes.metadata?.bindings?.[ attributeName ]?.source
|
|
23
|
-
);
|
|
24
|
-
const isConnectedToOtherSources = attributeSources.every(
|
|
25
|
-
( source ) => source && source !== 'core/pattern-overrides'
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
// Render nothing if all supported attributes are connected to other sources.
|
|
29
|
-
if ( isConnectedToOtherSources ) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function updateBindings( isChecked ) {
|
|
34
|
-
let updatedBindings = {
|
|
35
|
-
...attributes?.metadata?.bindings,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
if ( ! isChecked ) {
|
|
39
|
-
for ( const attributeName of Object.keys( syncedAttributes ) ) {
|
|
40
|
-
if (
|
|
41
|
-
updatedBindings[ attributeName ]?.source ===
|
|
42
|
-
'core/pattern-overrides'
|
|
43
|
-
) {
|
|
44
|
-
delete updatedBindings[ attributeName ];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if ( ! Object.keys( updatedBindings ).length ) {
|
|
48
|
-
updatedBindings = undefined;
|
|
49
|
-
}
|
|
50
|
-
setAttributes( {
|
|
51
|
-
metadata: {
|
|
52
|
-
...attributes.metadata,
|
|
53
|
-
bindings: updatedBindings,
|
|
54
|
-
},
|
|
55
|
-
} );
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
for ( const attributeName of Object.keys( syncedAttributes ) ) {
|
|
60
|
-
if ( ! updatedBindings[ attributeName ] ) {
|
|
61
|
-
updatedBindings[ attributeName ] = {
|
|
62
|
-
source: 'core/pattern-overrides',
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if ( typeof attributes.metadata?.id === 'string' ) {
|
|
68
|
-
setAttributes( {
|
|
69
|
-
metadata: {
|
|
70
|
-
...attributes.metadata,
|
|
71
|
-
bindings: updatedBindings,
|
|
72
|
-
},
|
|
73
|
-
} );
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const id = nanoid( 6 );
|
|
78
|
-
setAttributes( {
|
|
79
|
-
metadata: {
|
|
80
|
-
...attributes.metadata,
|
|
81
|
-
id,
|
|
82
|
-
bindings: updatedBindings,
|
|
83
|
-
},
|
|
84
|
-
} );
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<InspectorControls group="advanced">
|
|
89
|
-
<BaseControl __nextHasNoMarginBottom>
|
|
90
|
-
<BaseControl.VisualLabel>
|
|
91
|
-
{ __( 'Pattern overrides' ) }
|
|
92
|
-
</BaseControl.VisualLabel>
|
|
93
|
-
<CheckboxControl
|
|
94
|
-
__nextHasNoMarginBottom
|
|
95
|
-
label={ __( 'Allow instance overrides' ) }
|
|
96
|
-
checked={ attributeSources.some(
|
|
97
|
-
( source ) => source === 'core/pattern-overrides'
|
|
98
|
-
) }
|
|
99
|
-
onChange={ ( isChecked ) => {
|
|
100
|
-
updateBindings( isChecked );
|
|
101
|
-
} }
|
|
102
|
-
/>
|
|
103
|
-
</BaseControl>
|
|
104
|
-
</InspectorControls>
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export default PartialSyncingControls;
|