@wordpress/patterns 2.5.0 → 2.7.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/pattern-overrides-controls.js +18 -27
- package/build/components/pattern-overrides-controls.js.map +1 -1
- package/build-module/components/pattern-overrides-controls.js +19 -28
- package/build-module/components/pattern-overrides-controls.js.map +1 -1
- package/build-style/style-rtl.css +2 -2
- package/build-style/style.css +2 -2
- package/package.json +16 -16
- package/src/components/pattern-overrides-controls.js +18 -29
- package/src/components/style.scss +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,7 @@ var _components = require("@wordpress/components");
|
|
|
10
10
|
var _i18n = require("@wordpress/i18n");
|
|
11
11
|
var _constants = require("../constants");
|
|
12
12
|
var _allowOverridesModal = require("./allow-overrides-modal");
|
|
13
|
+
var _lockUnlock = require("../lock-unlock");
|
|
13
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
15
|
/**
|
|
15
16
|
* WordPress dependencies
|
|
@@ -19,24 +20,9 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
19
20
|
* Internal dependencies
|
|
20
21
|
*/
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
delete updatedBindings.__default;
|
|
27
|
-
if (!Object.keys(updatedBindings).length) {
|
|
28
|
-
updatedBindings = undefined;
|
|
29
|
-
}
|
|
30
|
-
return updatedBindings;
|
|
31
|
-
}
|
|
32
|
-
function addBindings(bindings) {
|
|
33
|
-
return {
|
|
34
|
-
...bindings,
|
|
35
|
-
__default: {
|
|
36
|
-
source: _constants.PATTERN_OVERRIDES_BINDING_SOURCE
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
}
|
|
23
|
+
const {
|
|
24
|
+
useBlockBindingsUtils
|
|
25
|
+
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
40
26
|
function PatternOverridesControls({
|
|
41
27
|
attributes,
|
|
42
28
|
setAttributes,
|
|
@@ -49,18 +35,22 @@ function PatternOverridesControls({
|
|
|
49
35
|
const defaultBindings = attributes.metadata?.bindings?.__default;
|
|
50
36
|
const hasOverrides = hasName && defaultBindings?.source === _constants.PATTERN_OVERRIDES_BINDING_SOURCE;
|
|
51
37
|
const isConnectedToOtherSources = defaultBindings?.source && defaultBindings.source !== _constants.PATTERN_OVERRIDES_BINDING_SOURCE;
|
|
38
|
+
const {
|
|
39
|
+
updateBlockBindings
|
|
40
|
+
} = useBlockBindingsUtils();
|
|
52
41
|
function updateBindings(isChecked, customName) {
|
|
53
|
-
const prevBindings = attributes?.metadata?.bindings;
|
|
54
|
-
const updatedBindings = isChecked ? addBindings(prevBindings) : removeBindings(prevBindings);
|
|
55
|
-
const updatedMetadata = {
|
|
56
|
-
...attributes.metadata,
|
|
57
|
-
bindings: updatedBindings
|
|
58
|
-
};
|
|
59
42
|
if (customName) {
|
|
60
|
-
|
|
43
|
+
setAttributes({
|
|
44
|
+
metadata: {
|
|
45
|
+
...attributes.metadata,
|
|
46
|
+
name: customName
|
|
47
|
+
}
|
|
48
|
+
});
|
|
61
49
|
}
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
updateBlockBindings({
|
|
51
|
+
__default: isChecked ? {
|
|
52
|
+
source: _constants.PATTERN_OVERRIDES_BINDING_SOURCE
|
|
53
|
+
} : undefined
|
|
64
54
|
});
|
|
65
55
|
}
|
|
66
56
|
|
|
@@ -74,6 +64,7 @@ function PatternOverridesControls({
|
|
|
74
64
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.InspectorControls, {
|
|
75
65
|
group: "advanced",
|
|
76
66
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.BaseControl, {
|
|
67
|
+
__nextHasNoMarginBottom: true,
|
|
77
68
|
id: controlId,
|
|
78
69
|
label: (0, _i18n.__)('Overrides'),
|
|
79
70
|
help: helpText,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_blockEditor","_components","_i18n","_constants","_allowOverridesModal","
|
|
1
|
+
{"version":3,"names":["_element","require","_blockEditor","_components","_i18n","_constants","_allowOverridesModal","_lockUnlock","_jsxRuntime","useBlockBindingsUtils","unlock","blockEditorPrivateApis","PatternOverridesControls","attributes","setAttributes","name","blockName","controlId","useId","showAllowOverridesModal","setShowAllowOverridesModal","useState","showDisallowOverridesModal","setShowDisallowOverridesModal","hasName","metadata","defaultBindings","bindings","__default","hasOverrides","source","PATTERN_OVERRIDES_BINDING_SOURCE","isConnectedToOtherSources","updateBlockBindings","updateBindings","isChecked","customName","undefined","hasUnsupportedImageAttributes","caption","length","href","helpText","__","jsxs","Fragment","children","jsx","InspectorControls","group","BaseControl","__nextHasNoMarginBottom","id","label","help","Button","__next40pxDefaultSize","className","variant","onClick","disabled","accessibleWhenDisabled","AllowOverridesModal","initialName","onClose","onSave","newName","DisallowOverridesModal","_default","exports","default"],"sources":["@wordpress/patterns/src/components/pattern-overrides-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useId } from '@wordpress/element';\nimport {\n\tInspectorControls,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { BaseControl, Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';\nimport {\n\tAllowOverridesModal,\n\tDisallowOverridesModal,\n} from './allow-overrides-modal';\nimport { unlock } from '../lock-unlock';\n\nconst { useBlockBindingsUtils } = unlock( blockEditorPrivateApis );\n\nfunction PatternOverridesControls( {\n\tattributes,\n\tsetAttributes,\n\tname: blockName,\n} ) {\n\tconst controlId = useId();\n\tconst [ showAllowOverridesModal, setShowAllowOverridesModal ] =\n\t\tuseState( false );\n\tconst [ showDisallowOverridesModal, setShowDisallowOverridesModal ] =\n\t\tuseState( false );\n\n\tconst hasName = !! attributes.metadata?.name;\n\tconst defaultBindings = attributes.metadata?.bindings?.__default;\n\tconst hasOverrides =\n\t\thasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;\n\tconst isConnectedToOtherSources =\n\t\tdefaultBindings?.source &&\n\t\tdefaultBindings.source !== PATTERN_OVERRIDES_BINDING_SOURCE;\n\tconst { updateBlockBindings } = useBlockBindingsUtils();\n\n\tfunction updateBindings( isChecked, customName ) {\n\t\tif ( customName ) {\n\t\t\tsetAttributes( {\n\t\t\t\tmetadata: {\n\t\t\t\t\t...attributes.metadata,\n\t\t\t\t\tname: customName,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\tupdateBlockBindings( {\n\t\t\t__default: isChecked\n\t\t\t\t? { source: PATTERN_OVERRIDES_BINDING_SOURCE }\n\t\t\t\t: undefined,\n\t\t} );\n\t}\n\n\t// Avoid overwriting other (e.g. meta) bindings.\n\tif ( isConnectedToOtherSources ) {\n\t\treturn null;\n\t}\n\n\tconst hasUnsupportedImageAttributes =\n\t\tblockName === 'core/image' &&\n\t\t( !! attributes.caption?.length || !! attributes.href?.length );\n\n\tconst helpText =\n\t\t! hasOverrides && hasUnsupportedImageAttributes\n\t\t\t? __(\n\t\t\t\t\t`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`\n\t\t\t )\n\t\t\t: __(\n\t\t\t\t\t'Allow changes to this block throughout instances of this pattern.'\n\t\t\t );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<BaseControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tid={ controlId }\n\t\t\t\t\tlabel={ __( 'Overrides' ) }\n\t\t\t\t\thelp={ helpText }\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"pattern-overrides-control__allow-overrides-button\"\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tif ( hasOverrides ) {\n\t\t\t\t\t\t\t\tsetShowDisallowOverridesModal( true );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetShowAllowOverridesModal( true );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tdisabled={\n\t\t\t\t\t\t\t! hasOverrides && hasUnsupportedImageAttributes\n\t\t\t\t\t\t}\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t>\n\t\t\t\t\t\t{ hasOverrides\n\t\t\t\t\t\t\t? __( 'Disable overrides' )\n\t\t\t\t\t\t\t: __( 'Enable overrides' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</BaseControl>\n\t\t\t</InspectorControls>\n\n\t\t\t{ showAllowOverridesModal && (\n\t\t\t\t<AllowOverridesModal\n\t\t\t\t\tinitialName={ attributes.metadata?.name }\n\t\t\t\t\tonClose={ () => setShowAllowOverridesModal( false ) }\n\t\t\t\t\tonSave={ ( newName ) => {\n\t\t\t\t\t\tupdateBindings( true, newName );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showDisallowOverridesModal && (\n\t\t\t\t<DisallowOverridesModal\n\t\t\t\t\tonClose={ () => setShowDisallowOverridesModal( false ) }\n\t\t\t\t\tonSave={ () => updateBindings( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PatternOverridesControls;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAIA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,oBAAA,GAAAL,OAAA;AAIA,IAAAM,WAAA,GAAAN,OAAA;AAAwC,IAAAO,WAAA,GAAAP,OAAA;AAnBxC;AACA;AACA;;AAS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,QAAQ,EAAEV,IAAM;MACzCiD,OAAO,EAAGA,CAAA,KAAM5C,0BAA0B,CAAE,KAAM,CAAG;MACrD6C,MAAM,EAAKC,OAAO,IAAM;QACvBhC,cAAc,CAAE,IAAI,EAAEgC,OAAQ,CAAC;MAChC;IAAG,CACH,CACD,EACC5C,0BAA0B,iBAC3B,IAAAd,WAAA,CAAAuC,GAAA,EAACzC,oBAAA,CAAA6D,sBAAsB;MACtBH,OAAO,EAAGA,CAAA,KAAMzC,6BAA6B,CAAE,KAAM,CAAG;MACxD0C,MAAM,EAAGA,CAAA,KAAM/B,cAAc,CAAE,KAAM;IAAG,CACxC,CACD;EAAA,CACA,CAAC;AAEL;AAAC,IAAAkC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc1D,wBAAwB","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useState, useId } from '@wordpress/element';
|
|
5
|
-
import { InspectorControls } from '@wordpress/block-editor';
|
|
5
|
+
import { InspectorControls, privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
6
6
|
import { BaseControl, Button } from '@wordpress/components';
|
|
7
7
|
import { __ } from '@wordpress/i18n';
|
|
8
8
|
|
|
@@ -11,27 +11,13 @@ import { __ } from '@wordpress/i18n';
|
|
|
11
11
|
*/
|
|
12
12
|
import { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';
|
|
13
13
|
import { AllowOverridesModal, DisallowOverridesModal } from './allow-overrides-modal';
|
|
14
|
+
import { unlock } from '../lock-unlock';
|
|
14
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
16
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
16
17
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
delete updatedBindings.__default;
|
|
22
|
-
if (!Object.keys(updatedBindings).length) {
|
|
23
|
-
updatedBindings = undefined;
|
|
24
|
-
}
|
|
25
|
-
return updatedBindings;
|
|
26
|
-
}
|
|
27
|
-
function addBindings(bindings) {
|
|
28
|
-
return {
|
|
29
|
-
...bindings,
|
|
30
|
-
__default: {
|
|
31
|
-
source: PATTERN_OVERRIDES_BINDING_SOURCE
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
18
|
+
const {
|
|
19
|
+
useBlockBindingsUtils
|
|
20
|
+
} = unlock(blockEditorPrivateApis);
|
|
35
21
|
function PatternOverridesControls({
|
|
36
22
|
attributes,
|
|
37
23
|
setAttributes,
|
|
@@ -44,18 +30,22 @@ function PatternOverridesControls({
|
|
|
44
30
|
const defaultBindings = attributes.metadata?.bindings?.__default;
|
|
45
31
|
const hasOverrides = hasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;
|
|
46
32
|
const isConnectedToOtherSources = defaultBindings?.source && defaultBindings.source !== PATTERN_OVERRIDES_BINDING_SOURCE;
|
|
33
|
+
const {
|
|
34
|
+
updateBlockBindings
|
|
35
|
+
} = useBlockBindingsUtils();
|
|
47
36
|
function updateBindings(isChecked, customName) {
|
|
48
|
-
const prevBindings = attributes?.metadata?.bindings;
|
|
49
|
-
const updatedBindings = isChecked ? addBindings(prevBindings) : removeBindings(prevBindings);
|
|
50
|
-
const updatedMetadata = {
|
|
51
|
-
...attributes.metadata,
|
|
52
|
-
bindings: updatedBindings
|
|
53
|
-
};
|
|
54
37
|
if (customName) {
|
|
55
|
-
|
|
38
|
+
setAttributes({
|
|
39
|
+
metadata: {
|
|
40
|
+
...attributes.metadata,
|
|
41
|
+
name: customName
|
|
42
|
+
}
|
|
43
|
+
});
|
|
56
44
|
}
|
|
57
|
-
|
|
58
|
-
|
|
45
|
+
updateBlockBindings({
|
|
46
|
+
__default: isChecked ? {
|
|
47
|
+
source: PATTERN_OVERRIDES_BINDING_SOURCE
|
|
48
|
+
} : undefined
|
|
59
49
|
});
|
|
60
50
|
}
|
|
61
51
|
|
|
@@ -69,6 +59,7 @@ function PatternOverridesControls({
|
|
|
69
59
|
children: [/*#__PURE__*/_jsx(InspectorControls, {
|
|
70
60
|
group: "advanced",
|
|
71
61
|
children: /*#__PURE__*/_jsx(BaseControl, {
|
|
62
|
+
__nextHasNoMarginBottom: true,
|
|
72
63
|
id: controlId,
|
|
73
64
|
label: __('Overrides'),
|
|
74
65
|
help: helpText,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useState","useId","InspectorControls","BaseControl","Button","__","PATTERN_OVERRIDES_BINDING_SOURCE","AllowOverridesModal","DisallowOverridesModal","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","
|
|
1
|
+
{"version":3,"names":["useState","useId","InspectorControls","privateApis","blockEditorPrivateApis","BaseControl","Button","__","PATTERN_OVERRIDES_BINDING_SOURCE","AllowOverridesModal","DisallowOverridesModal","unlock","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","useBlockBindingsUtils","PatternOverridesControls","attributes","setAttributes","name","blockName","controlId","showAllowOverridesModal","setShowAllowOverridesModal","showDisallowOverridesModal","setShowDisallowOverridesModal","hasName","metadata","defaultBindings","bindings","__default","hasOverrides","source","isConnectedToOtherSources","updateBlockBindings","updateBindings","isChecked","customName","undefined","hasUnsupportedImageAttributes","caption","length","href","helpText","children","group","__nextHasNoMarginBottom","id","label","help","__next40pxDefaultSize","className","variant","onClick","disabled","accessibleWhenDisabled","initialName","onClose","onSave","newName"],"sources":["@wordpress/patterns/src/components/pattern-overrides-controls.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useId } from '@wordpress/element';\nimport {\n\tInspectorControls,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { BaseControl, Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';\nimport {\n\tAllowOverridesModal,\n\tDisallowOverridesModal,\n} from './allow-overrides-modal';\nimport { unlock } from '../lock-unlock';\n\nconst { useBlockBindingsUtils } = unlock( blockEditorPrivateApis );\n\nfunction PatternOverridesControls( {\n\tattributes,\n\tsetAttributes,\n\tname: blockName,\n} ) {\n\tconst controlId = useId();\n\tconst [ showAllowOverridesModal, setShowAllowOverridesModal ] =\n\t\tuseState( false );\n\tconst [ showDisallowOverridesModal, setShowDisallowOverridesModal ] =\n\t\tuseState( false );\n\n\tconst hasName = !! attributes.metadata?.name;\n\tconst defaultBindings = attributes.metadata?.bindings?.__default;\n\tconst hasOverrides =\n\t\thasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;\n\tconst isConnectedToOtherSources =\n\t\tdefaultBindings?.source &&\n\t\tdefaultBindings.source !== PATTERN_OVERRIDES_BINDING_SOURCE;\n\tconst { updateBlockBindings } = useBlockBindingsUtils();\n\n\tfunction updateBindings( isChecked, customName ) {\n\t\tif ( customName ) {\n\t\t\tsetAttributes( {\n\t\t\t\tmetadata: {\n\t\t\t\t\t...attributes.metadata,\n\t\t\t\t\tname: customName,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\tupdateBlockBindings( {\n\t\t\t__default: isChecked\n\t\t\t\t? { source: PATTERN_OVERRIDES_BINDING_SOURCE }\n\t\t\t\t: undefined,\n\t\t} );\n\t}\n\n\t// Avoid overwriting other (e.g. meta) bindings.\n\tif ( isConnectedToOtherSources ) {\n\t\treturn null;\n\t}\n\n\tconst hasUnsupportedImageAttributes =\n\t\tblockName === 'core/image' &&\n\t\t( !! attributes.caption?.length || !! attributes.href?.length );\n\n\tconst helpText =\n\t\t! hasOverrides && hasUnsupportedImageAttributes\n\t\t\t? __(\n\t\t\t\t\t`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`\n\t\t\t )\n\t\t\t: __(\n\t\t\t\t\t'Allow changes to this block throughout instances of this pattern.'\n\t\t\t );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<BaseControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tid={ controlId }\n\t\t\t\t\tlabel={ __( 'Overrides' ) }\n\t\t\t\t\thelp={ helpText }\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"pattern-overrides-control__allow-overrides-button\"\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tif ( hasOverrides ) {\n\t\t\t\t\t\t\t\tsetShowDisallowOverridesModal( true );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetShowAllowOverridesModal( true );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tdisabled={\n\t\t\t\t\t\t\t! hasOverrides && hasUnsupportedImageAttributes\n\t\t\t\t\t\t}\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t>\n\t\t\t\t\t\t{ hasOverrides\n\t\t\t\t\t\t\t? __( 'Disable overrides' )\n\t\t\t\t\t\t\t: __( 'Enable overrides' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</BaseControl>\n\t\t\t</InspectorControls>\n\n\t\t\t{ showAllowOverridesModal && (\n\t\t\t\t<AllowOverridesModal\n\t\t\t\t\tinitialName={ attributes.metadata?.name }\n\t\t\t\t\tonClose={ () => setShowAllowOverridesModal( false ) }\n\t\t\t\t\tonSave={ ( newName ) => {\n\t\t\t\t\t\tupdateBindings( true, newName );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showDisallowOverridesModal && (\n\t\t\t\t<DisallowOverridesModal\n\t\t\t\t\tonClose={ () => setShowDisallowOverridesModal( false ) }\n\t\t\t\t\tonSave={ () => updateBindings( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default P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AClB;UACDgB,sBAAsB;UAAAX,QAAA,EAEpBb,YAAY,GACX3B,EAAE,CAAE,mBAAoB,CAAC,GACzBA,EAAE,CAAE,kBAAmB;QAAC,CACpB;MAAC,CACG;IAAC,CACI,CAAC,EAElBkB,uBAAuB,iBACxBZ,IAAA,CAACJ,mBAAmB;MACnBkD,WAAW,EAAGvC,UAAU,CAACU,QAAQ,EAAER,IAAM;MACzCsC,OAAO,EAAGA,CAAA,KAAMlC,0BAA0B,CAAE,KAAM,CAAG;MACrDmC,MAAM,EAAKC,OAAO,IAAM;QACvBxB,cAAc,CAAE,IAAI,EAAEwB,OAAQ,CAAC;MAChC;IAAG,CACH,CACD,EACCnC,0BAA0B,iBAC3Bd,IAAA,CAACH,sBAAsB;MACtBkD,OAAO,EAAGA,CAAA,KAAMhC,6BAA6B,CAAE,KAAM,CAAG;MACxDiC,MAAM,EAAGA,CAAA,KAAMvB,cAAc,CAAE,KAAM;IAAG,CACxC,CACD;EAAA,CACA,CAAC;AAEL;AAEA,eAAenB,wBAAwB","ignoreList":[]}
|
package/build-style/style.css
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/patterns",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Management of user pattern editing.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -32,20 +32,20 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/runtime": "^7.16.0",
|
|
35
|
-
"@wordpress/a11y": "^4.
|
|
36
|
-
"@wordpress/block-editor": "^14.
|
|
37
|
-
"@wordpress/blocks": "^13.
|
|
38
|
-
"@wordpress/components": "^28.
|
|
39
|
-
"@wordpress/compose": "^7.
|
|
40
|
-
"@wordpress/core-data": "^7.
|
|
41
|
-
"@wordpress/data": "^10.
|
|
42
|
-
"@wordpress/element": "^6.
|
|
43
|
-
"@wordpress/html-entities": "^4.
|
|
44
|
-
"@wordpress/i18n": "^5.
|
|
45
|
-
"@wordpress/icons": "^10.
|
|
46
|
-
"@wordpress/notices": "^5.
|
|
47
|
-
"@wordpress/private-apis": "^1.
|
|
48
|
-
"@wordpress/url": "^4.
|
|
35
|
+
"@wordpress/a11y": "^4.7.0",
|
|
36
|
+
"@wordpress/block-editor": "^14.2.0",
|
|
37
|
+
"@wordpress/blocks": "^13.7.0",
|
|
38
|
+
"@wordpress/components": "^28.7.0",
|
|
39
|
+
"@wordpress/compose": "^7.7.0",
|
|
40
|
+
"@wordpress/core-data": "^7.7.0",
|
|
41
|
+
"@wordpress/data": "^10.7.0",
|
|
42
|
+
"@wordpress/element": "^6.7.0",
|
|
43
|
+
"@wordpress/html-entities": "^4.7.0",
|
|
44
|
+
"@wordpress/i18n": "^5.7.0",
|
|
45
|
+
"@wordpress/icons": "^10.7.0",
|
|
46
|
+
"@wordpress/notices": "^5.7.0",
|
|
47
|
+
"@wordpress/private-apis": "^1.7.0",
|
|
48
|
+
"@wordpress/url": "^4.7.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"react": "^18.0.0",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "c90d920de07c53dff82c5914635b56fafa503b7f"
|
|
58
58
|
}
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useState, useId } from '@wordpress/element';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
InspectorControls,
|
|
7
|
+
privateApis as blockEditorPrivateApis,
|
|
8
|
+
} from '@wordpress/block-editor';
|
|
6
9
|
import { BaseControl, Button } from '@wordpress/components';
|
|
7
10
|
import { __ } from '@wordpress/i18n';
|
|
8
11
|
|
|
@@ -14,22 +17,9 @@ import {
|
|
|
14
17
|
AllowOverridesModal,
|
|
15
18
|
DisallowOverridesModal,
|
|
16
19
|
} from './allow-overrides-modal';
|
|
20
|
+
import { unlock } from '../lock-unlock';
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
let updatedBindings = { ...bindings };
|
|
20
|
-
delete updatedBindings.__default;
|
|
21
|
-
if ( ! Object.keys( updatedBindings ).length ) {
|
|
22
|
-
updatedBindings = undefined;
|
|
23
|
-
}
|
|
24
|
-
return updatedBindings;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function addBindings( bindings ) {
|
|
28
|
-
return {
|
|
29
|
-
...bindings,
|
|
30
|
-
__default: { source: PATTERN_OVERRIDES_BINDING_SOURCE },
|
|
31
|
-
};
|
|
32
|
-
}
|
|
22
|
+
const { useBlockBindingsUtils } = unlock( blockEditorPrivateApis );
|
|
33
23
|
|
|
34
24
|
function PatternOverridesControls( {
|
|
35
25
|
attributes,
|
|
@@ -49,24 +39,22 @@ function PatternOverridesControls( {
|
|
|
49
39
|
const isConnectedToOtherSources =
|
|
50
40
|
defaultBindings?.source &&
|
|
51
41
|
defaultBindings.source !== PATTERN_OVERRIDES_BINDING_SOURCE;
|
|
42
|
+
const { updateBlockBindings } = useBlockBindingsUtils();
|
|
52
43
|
|
|
53
44
|
function updateBindings( isChecked, customName ) {
|
|
54
|
-
const prevBindings = attributes?.metadata?.bindings;
|
|
55
|
-
const updatedBindings = isChecked
|
|
56
|
-
? addBindings( prevBindings )
|
|
57
|
-
: removeBindings( prevBindings );
|
|
58
|
-
|
|
59
|
-
const updatedMetadata = {
|
|
60
|
-
...attributes.metadata,
|
|
61
|
-
bindings: updatedBindings,
|
|
62
|
-
};
|
|
63
|
-
|
|
64
45
|
if ( customName ) {
|
|
65
|
-
|
|
46
|
+
setAttributes( {
|
|
47
|
+
metadata: {
|
|
48
|
+
...attributes.metadata,
|
|
49
|
+
name: customName,
|
|
50
|
+
},
|
|
51
|
+
} );
|
|
66
52
|
}
|
|
67
53
|
|
|
68
|
-
|
|
69
|
-
|
|
54
|
+
updateBlockBindings( {
|
|
55
|
+
__default: isChecked
|
|
56
|
+
? { source: PATTERN_OVERRIDES_BINDING_SOURCE }
|
|
57
|
+
: undefined,
|
|
70
58
|
} );
|
|
71
59
|
}
|
|
72
60
|
|
|
@@ -92,6 +80,7 @@ function PatternOverridesControls( {
|
|
|
92
80
|
<>
|
|
93
81
|
<InspectorControls group="advanced">
|
|
94
82
|
<BaseControl
|
|
83
|
+
__nextHasNoMarginBottom
|
|
95
84
|
id={ controlId }
|
|
96
85
|
label={ __( 'Overrides' ) }
|
|
97
86
|
help={ helpText }
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
.components-form-token-field__suggestions-list:not(:empty) {
|
|
14
14
|
position: absolute;
|
|
15
15
|
border: $border-width solid var(--wp-admin-theme-color);
|
|
16
|
-
border-bottom-left-radius: $radius-
|
|
17
|
-
border-bottom-right-radius: $radius-
|
|
16
|
+
border-bottom-left-radius: $radius-small;
|
|
17
|
+
border-bottom-right-radius: $radius-small;
|
|
18
18
|
box-shadow: 0 0 0.5px 0.5px var(--wp-admin-theme-color);
|
|
19
19
|
box-sizing: border-box;
|
|
20
20
|
z-index: 1;
|