@wordpress/patterns 2.32.0 → 2.32.1-next.47f435fc9.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/build/api/index.js +35 -29
- package/build/api/index.js.map +7 -1
- package/build/components/allow-overrides-modal.js +149 -112
- package/build/components/allow-overrides-modal.js.map +7 -1
- package/build/components/category-selector.js +59 -38
- package/build/components/category-selector.js.map +7 -1
- package/build/components/create-pattern-modal.js +162 -111
- package/build/components/create-pattern-modal.js.map +7 -1
- package/build/components/duplicate-pattern-modal.js +85 -66
- package/build/components/duplicate-pattern-modal.js.map +7 -1
- package/build/components/index.js +50 -33
- package/build/components/index.js.map +7 -1
- package/build/components/overrides-panel.js +44 -39
- package/build/components/overrides-panel.js.map +7 -1
- package/build/components/pattern-convert-button.js +144 -133
- package/build/components/pattern-convert-button.js.map +7 -1
- package/build/components/pattern-overrides-block-controls.js +109 -109
- package/build/components/pattern-overrides-block-controls.js.map +7 -1
- package/build/components/pattern-overrides-controls.js +86 -69
- package/build/components/pattern-overrides-controls.js.map +7 -1
- package/build/components/patterns-manage-button.js +96 -97
- package/build/components/patterns-manage-button.js.map +7 -1
- package/build/components/rename-pattern-category-modal.js +122 -111
- package/build/components/rename-pattern-category-modal.js.map +7 -1
- package/build/components/rename-pattern-modal.js +95 -73
- package/build/components/rename-pattern-modal.js.map +7 -1
- package/build/components/reset-overrides-control.js +61 -57
- package/build/components/reset-overrides-control.js.map +7 -1
- package/build/constants.js +57 -23
- package/build/constants.js.map +7 -1
- package/build/index.js +27 -24
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -15
- package/build/lock-unlock.js.map +7 -1
- package/build/private-apis.js +71 -48
- package/build/private-apis.js.map +7 -1
- package/build/private-hooks.js +57 -69
- package/build/private-hooks.js.map +7 -1
- package/build/store/actions.js +72 -85
- package/build/store/actions.js.map +7 -1
- package/build/store/constants.js +27 -10
- package/build/store/constants.js.map +7 -1
- package/build/store/index.js +50 -44
- package/build/store/index.js.map +7 -1
- package/build/store/reducer.js +30 -14
- package/build/store/reducer.js.map +7 -1
- package/build/store/selectors.js +26 -13
- package/build/store/selectors.js.map +7 -1
- package/build-module/api/index.js +14 -25
- package/build-module/api/index.js.map +7 -1
- package/build-module/components/allow-overrides-modal.js +131 -103
- package/build-module/components/allow-overrides-modal.js.map +7 -1
- package/build-module/components/category-selector.js +35 -29
- package/build-module/components/category-selector.js.map +7 -1
- package/build-module/components/create-pattern-modal.js +137 -99
- package/build-module/components/create-pattern-modal.js.map +7 -1
- package/build-module/components/duplicate-pattern-modal.js +53 -58
- package/build-module/components/duplicate-pattern-modal.js.map +7 -1
- package/build-module/components/index.js +22 -26
- package/build-module/components/index.js.map +7 -1
- package/build-module/components/overrides-panel.js +30 -34
- package/build-module/components/overrides-panel.js.map +7 -1
- package/build-module/components/pattern-convert-button.js +120 -125
- package/build-module/components/pattern-convert-button.js.map +7 -1
- package/build-module/components/pattern-overrides-block-controls.js +100 -103
- package/build-module/components/pattern-overrides-block-controls.js.map +7 -1
- package/build-module/components/pattern-overrides-controls.js +69 -58
- package/build-module/components/pattern-overrides-controls.js.map +7 -1
- package/build-module/components/patterns-manage-button.js +78 -91
- package/build-module/components/patterns-manage-button.js.map +7 -1
- package/build-module/components/rename-pattern-category-modal.js +106 -101
- package/build-module/components/rename-pattern-category-modal.js.map +7 -1
- package/build-module/components/rename-pattern-modal.js +80 -64
- package/build-module/components/rename-pattern-modal.js.map +7 -1
- package/build-module/components/reset-overrides-control.js +46 -51
- package/build-module/components/reset-overrides-control.js.map +7 -1
- package/build-module/constants.js +29 -18
- package/build-module/constants.js.map +7 -1
- package/build-module/index.js +6 -6
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/private-apis.js +31 -18
- package/build-module/private-apis.js.map +7 -1
- package/build-module/private-hooks.js +35 -64
- package/build-module/private-hooks.js.map +7 -1
- package/build-module/store/actions.js +44 -74
- package/build-module/store/actions.js.map +7 -1
- package/build-module/store/constants.js +5 -5
- package/build-module/store/constants.js.map +7 -1
- package/build-module/store/index.js +13 -32
- package/build-module/store/index.js.map +7 -1
- package/build-module/store/reducer.js +9 -8
- package/build-module/store/reducer.js.map +7 -1
- package/build-module/store/selectors.js +5 -9
- package/build-module/store/selectors.js.map +7 -1
- package/build-style/style-rtl.css +3 -138
- package/build-style/style.css +3 -138
- package/package.json +24 -17
- package/src/components/style.scss +5 -0
- package/src/style.scss +2 -1
- package/build/index.native.js +0 -18
- package/build/index.native.js.map +0 -1
- package/build-module/index.native.js +0 -11
- package/build-module/index.native.js.map +0 -1
|
@@ -1,123 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} = unlock(blockEditorPrivateApis);
|
|
21
|
-
function PatternOverridesToolbarIndicator({
|
|
22
|
-
clientIds
|
|
23
|
-
}) {
|
|
1
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "@wordpress/element";
|
|
3
|
+
import { __, sprintf } from "@wordpress/i18n";
|
|
4
|
+
import {
|
|
5
|
+
DropdownMenu,
|
|
6
|
+
ToolbarItem,
|
|
7
|
+
__experimentalText as Text
|
|
8
|
+
} from "@wordpress/components";
|
|
9
|
+
import { store as blocksStore } from "@wordpress/blocks";
|
|
10
|
+
import { useSelect } from "@wordpress/data";
|
|
11
|
+
import { copy } from "@wordpress/icons";
|
|
12
|
+
import {
|
|
13
|
+
store as blockEditorStore,
|
|
14
|
+
BlockIcon,
|
|
15
|
+
privateApis as blockEditorPrivateApis,
|
|
16
|
+
BlockControls
|
|
17
|
+
} from "@wordpress/block-editor";
|
|
18
|
+
import { unlock } from "../lock-unlock";
|
|
19
|
+
import { PATTERN_OVERRIDES_BINDING_SOURCE } from "../constants";
|
|
20
|
+
const { useBlockDisplayTitle } = unlock(blockEditorPrivateApis);
|
|
21
|
+
function PatternOverridesToolbarIndicator({ clientIds }) {
|
|
24
22
|
const isSingleBlockSelected = clientIds.length === 1;
|
|
25
|
-
const {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
icon: _icon,
|
|
53
|
-
firstBlockName: getBlockAttributes(clientIds[0]).metadata.name
|
|
54
|
-
};
|
|
55
|
-
}, [clientIds, isSingleBlockSelected]);
|
|
23
|
+
const { icon, firstBlockName } = useSelect(
|
|
24
|
+
(select) => {
|
|
25
|
+
const { getBlockAttributes, getBlockNamesByClientId } = select(blockEditorStore);
|
|
26
|
+
const { getBlockType, getActiveBlockVariation } = select(blocksStore);
|
|
27
|
+
const blockTypeNames = getBlockNamesByClientId(clientIds);
|
|
28
|
+
const _firstBlockTypeName = blockTypeNames[0];
|
|
29
|
+
const firstBlockType = getBlockType(_firstBlockTypeName);
|
|
30
|
+
let _icon;
|
|
31
|
+
if (isSingleBlockSelected) {
|
|
32
|
+
const match = getActiveBlockVariation(
|
|
33
|
+
_firstBlockTypeName,
|
|
34
|
+
getBlockAttributes(clientIds[0])
|
|
35
|
+
);
|
|
36
|
+
_icon = match?.icon || firstBlockType.icon;
|
|
37
|
+
} else {
|
|
38
|
+
const isSelectionOfSameType = new Set(blockTypeNames).size === 1;
|
|
39
|
+
_icon = isSelectionOfSameType ? firstBlockType.icon : copy;
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
icon: _icon,
|
|
43
|
+
firstBlockName: getBlockAttributes(clientIds[0]).metadata.name
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
[clientIds, isSingleBlockSelected]
|
|
47
|
+
);
|
|
56
48
|
const firstBlockTitle = useBlockDisplayTitle({
|
|
57
49
|
clientId: clientIds[0],
|
|
58
50
|
maximumLength: 35
|
|
59
51
|
});
|
|
60
|
-
const blockDescription = isSingleBlockSelected ? sprintf(
|
|
61
|
-
|
|
52
|
+
const blockDescription = isSingleBlockSelected ? sprintf(
|
|
53
|
+
/* translators: 1: The block type's name. 2: The block's user-provided name (the same as the override name). */
|
|
54
|
+
__('This %1$s is editable using the "%2$s" override.'),
|
|
55
|
+
firstBlockTitle.toLowerCase(),
|
|
56
|
+
firstBlockName
|
|
57
|
+
) : __("These blocks are editable using overrides.");
|
|
62
58
|
const descriptionId = useId();
|
|
63
|
-
return
|
|
64
|
-
|
|
59
|
+
return /* @__PURE__ */ jsx(ToolbarItem, { children: (toggleProps) => /* @__PURE__ */ jsx(
|
|
60
|
+
DropdownMenu,
|
|
61
|
+
{
|
|
65
62
|
className: "patterns-pattern-overrides-toolbar-indicator",
|
|
66
63
|
label: firstBlockTitle,
|
|
67
64
|
popoverProps: {
|
|
68
|
-
placement:
|
|
69
|
-
className:
|
|
65
|
+
placement: "bottom-start",
|
|
66
|
+
className: "patterns-pattern-overrides-toolbar-indicator__popover"
|
|
70
67
|
},
|
|
71
|
-
icon:
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
icon: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
69
|
+
BlockIcon,
|
|
70
|
+
{
|
|
71
|
+
icon,
|
|
74
72
|
className: "patterns-pattern-overrides-toolbar-indicator-icon",
|
|
75
73
|
showColors: true
|
|
76
|
-
}
|
|
77
|
-
}),
|
|
74
|
+
}
|
|
75
|
+
) }),
|
|
78
76
|
toggleProps: {
|
|
79
77
|
description: blockDescription,
|
|
80
78
|
...toggleProps
|
|
81
79
|
},
|
|
82
80
|
menuProps: {
|
|
83
|
-
orientation:
|
|
84
|
-
|
|
81
|
+
orientation: "both",
|
|
82
|
+
"aria-describedby": descriptionId
|
|
85
83
|
},
|
|
86
|
-
children: () =>
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
})
|
|
90
|
-
})
|
|
91
|
-
});
|
|
84
|
+
children: () => /* @__PURE__ */ jsx(Text, { id: descriptionId, children: blockDescription })
|
|
85
|
+
}
|
|
86
|
+
) });
|
|
92
87
|
}
|
|
93
|
-
|
|
94
|
-
const {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
getSelectedBlockClientIds
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}) : null;
|
|
88
|
+
function PatternOverridesBlockControls() {
|
|
89
|
+
const { clientIds, hasPatternOverrides, hasParentPattern } = useSelect(
|
|
90
|
+
(select) => {
|
|
91
|
+
const {
|
|
92
|
+
getBlockAttributes,
|
|
93
|
+
getSelectedBlockClientIds,
|
|
94
|
+
getBlockParentsByBlockName
|
|
95
|
+
} = select(blockEditorStore);
|
|
96
|
+
const selectedClientIds = getSelectedBlockClientIds();
|
|
97
|
+
const _hasPatternOverrides = selectedClientIds.every(
|
|
98
|
+
(clientId) => Object.values(
|
|
99
|
+
getBlockAttributes(clientId)?.metadata?.bindings ?? {}
|
|
100
|
+
).some(
|
|
101
|
+
(binding) => binding?.source === PATTERN_OVERRIDES_BINDING_SOURCE
|
|
102
|
+
)
|
|
103
|
+
);
|
|
104
|
+
const _hasParentPattern = selectedClientIds.every(
|
|
105
|
+
(clientId) => getBlockParentsByBlockName(clientId, "core/block", true).length > 0
|
|
106
|
+
);
|
|
107
|
+
return {
|
|
108
|
+
clientIds: selectedClientIds,
|
|
109
|
+
hasPatternOverrides: _hasPatternOverrides,
|
|
110
|
+
hasParentPattern: _hasParentPattern
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
[]
|
|
114
|
+
);
|
|
115
|
+
return hasPatternOverrides && hasParentPattern ? /* @__PURE__ */ jsx(BlockControls, { group: "parent", children: /* @__PURE__ */ jsx(PatternOverridesToolbarIndicator, { clientIds }) }) : null;
|
|
122
116
|
}
|
|
123
|
-
|
|
117
|
+
export {
|
|
118
|
+
PatternOverridesBlockControls as default
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=pattern-overrides-block-controls.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/components/pattern-overrides-block-controls.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useId } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tDropdownMenu,\n\tToolbarItem,\n\t__experimentalText as Text,\n} from '@wordpress/components';\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport { copy } from '@wordpress/icons';\nimport {\n\tstore as blockEditorStore,\n\tBlockIcon,\n\tprivateApis as blockEditorPrivateApis,\n\tBlockControls,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\nimport { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';\n\nconst { useBlockDisplayTitle } = unlock( blockEditorPrivateApis );\n\nfunction PatternOverridesToolbarIndicator( { clientIds } ) {\n\tconst isSingleBlockSelected = clientIds.length === 1;\n\tconst { icon, firstBlockName } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockAttributes, getBlockNamesByClientId } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst { getBlockType, getActiveBlockVariation } =\n\t\t\t\tselect( blocksStore );\n\t\t\tconst blockTypeNames = getBlockNamesByClientId( clientIds );\n\t\t\tconst _firstBlockTypeName = blockTypeNames[ 0 ];\n\t\t\tconst firstBlockType = getBlockType( _firstBlockTypeName );\n\t\t\tlet _icon;\n\t\t\tif ( isSingleBlockSelected ) {\n\t\t\t\tconst match = getActiveBlockVariation(\n\t\t\t\t\t_firstBlockTypeName,\n\t\t\t\t\tgetBlockAttributes( clientIds[ 0 ] )\n\t\t\t\t);\n\t\t\t\t// Take into account active block variations.\n\t\t\t\t_icon = match?.icon || firstBlockType.icon;\n\t\t\t} else {\n\t\t\t\tconst isSelectionOfSameType =\n\t\t\t\t\tnew Set( blockTypeNames ).size === 1;\n\t\t\t\t// When selection consists of blocks of multiple types, display an\n\t\t\t\t// appropriate icon to communicate the non-uniformity.\n\t\t\t\t_icon = isSelectionOfSameType ? firstBlockType.icon : copy;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\ticon: _icon,\n\t\t\t\tfirstBlockName: getBlockAttributes( clientIds[ 0 ] ).metadata\n\t\t\t\t\t.name,\n\t\t\t};\n\t\t},\n\t\t[ clientIds, isSingleBlockSelected ]\n\t);\n\tconst firstBlockTitle = useBlockDisplayTitle( {\n\t\tclientId: clientIds[ 0 ],\n\t\tmaximumLength: 35,\n\t} );\n\n\tconst blockDescription = isSingleBlockSelected\n\t\t? sprintf(\n\t\t\t\t/* translators: 1: The block type's name. 2: The block's user-provided name (the same as the override name). */\n\t\t\t\t__( 'This %1$s is editable using the \"%2$s\" override.' ),\n\t\t\t\tfirstBlockTitle.toLowerCase(),\n\t\t\t\tfirstBlockName\n\t\t )\n\t\t: __( 'These blocks are editable using overrides.' );\n\n\tconst descriptionId = useId();\n\n\treturn (\n\t\t<ToolbarItem>\n\t\t\t{ ( toggleProps ) => (\n\t\t\t\t<DropdownMenu\n\t\t\t\t\tclassName=\"patterns-pattern-overrides-toolbar-indicator\"\n\t\t\t\t\tlabel={ firstBlockTitle }\n\t\t\t\t\tpopoverProps={ {\n\t\t\t\t\t\tplacement: 'bottom-start',\n\t\t\t\t\t\tclassName:\n\t\t\t\t\t\t\t'patterns-pattern-overrides-toolbar-indicator__popover',\n\t\t\t\t\t} }\n\t\t\t\t\ticon={\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\t\tclassName=\"patterns-pattern-overrides-toolbar-indicator-icon\"\n\t\t\t\t\t\t\t\tshowColors\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</>\n\t\t\t\t\t}\n\t\t\t\t\ttoggleProps={ {\n\t\t\t\t\t\tdescription: blockDescription,\n\t\t\t\t\t\t...toggleProps,\n\t\t\t\t\t} }\n\t\t\t\t\tmenuProps={ {\n\t\t\t\t\t\torientation: 'both',\n\t\t\t\t\t\t'aria-describedby': descriptionId,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ () => (\n\t\t\t\t\t\t<Text id={ descriptionId }>{ blockDescription }</Text>\n\t\t\t\t\t) }\n\t\t\t\t</DropdownMenu>\n\t\t\t) }\n\t\t</ToolbarItem>\n\t);\n}\n\nexport default function PatternOverridesBlockControls() {\n\tconst { clientIds, hasPatternOverrides, hasParentPattern } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockAttributes,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst selectedClientIds = getSelectedBlockClientIds();\n\t\t\tconst _hasPatternOverrides = selectedClientIds.every(\n\t\t\t\t( clientId ) =>\n\t\t\t\t\tObject.values(\n\t\t\t\t\t\tgetBlockAttributes( clientId )?.metadata?.bindings ?? {}\n\t\t\t\t\t).some(\n\t\t\t\t\t\t( binding ) =>\n\t\t\t\t\t\t\tbinding?.source === PATTERN_OVERRIDES_BINDING_SOURCE\n\t\t\t\t\t)\n\t\t\t);\n\t\t\tconst _hasParentPattern = selectedClientIds.every(\n\t\t\t\t( clientId ) =>\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, 'core/block', true )\n\t\t\t\t\t\t.length > 0\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tclientIds: selectedClientIds,\n\t\t\t\thasPatternOverrides: _hasPatternOverrides,\n\t\t\t\thasParentPattern: _hasParentPattern,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\treturn hasPatternOverrides && hasParentPattern ? (\n\t\t<BlockControls group=\"parent\">\n\t\t\t<PatternOverridesToolbarIndicator clientIds={ clientIds } />\n\t\t</BlockControls>\n\t) : null;\n}\n"],
|
|
5
|
+
"mappings": "AA2FM,mBACC,WADD;AAxFN,SAAS,aAAa;AACtB,SAAS,IAAI,eAAe;AAC5B;AAAA,EACC;AAAA,EACA;AAAA,EACA,sBAAsB;AAAA,OAChB;AACP,SAAS,SAAS,mBAAmB;AACrC,SAAS,iBAAiB;AAC1B,SAAS,YAAY;AACrB;AAAA,EACC,SAAS;AAAA,EACT;AAAA,EACA,eAAe;AAAA,EACf;AAAA,OACM;AAKP,SAAS,cAAc;AACvB,SAAS,wCAAwC;AAEjD,MAAM,EAAE,qBAAqB,IAAI,OAAQ,sBAAuB;AAEhE,SAAS,iCAAkC,EAAE,UAAU,GAAI;AAC1D,QAAM,wBAAwB,UAAU,WAAW;AACnD,QAAM,EAAE,MAAM,eAAe,IAAI;AAAA,IAChC,CAAE,WAAY;AACb,YAAM,EAAE,oBAAoB,wBAAwB,IACnD,OAAQ,gBAAiB;AAC1B,YAAM,EAAE,cAAc,wBAAwB,IAC7C,OAAQ,WAAY;AACrB,YAAM,iBAAiB,wBAAyB,SAAU;AAC1D,YAAM,sBAAsB,eAAgB,CAAE;AA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AAAA,IAC5D,CAAE,WAAY;AACb,YAAM;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,MACD,IAAI,OAAQ,gBAAiB;AAC7B,YAAM,oBAAoB,0BAA0B;AACpD,YAAM,uBAAuB,kBAAkB;AAAA,QAC9C,CAAE,aACD,OAAO;AAAA,UACN,mBAAoB,QAAS,GAAG,UAAU,YAAY,CAAC;AAAA,QACxD,EAAE;AAAA,UACD,CAAE,YACD,SAAS,WAAW;AAAA,QACtB;AAAA,MACF;AACA,YAAM,oBAAoB,kBAAkB;AAAA,QAC3C,CAAE,aACD,2BAA4B,UAAU,cAAc,IAAK,EACvD,SAAS;AAAA,MACb;AACA,aAAO;AAAA,QACN,WAAW;AAAA,QACX,qBAAqB;AAAA,QACrB,kBAAkB;AAAA,MACnB;AAAA,IACD;AAAA,IACA,CAAC;AAAA,EACF;AAEA,SAAO,uBAAuB,mBAC7B,oBAAC,iBAAc,OAAM,UACpB,8BAAC,oCAAiC,WAAwB,GAC3D,IACG;AACL;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useId } from "@wordpress/element";
|
|
3
|
+
import {
|
|
4
|
+
InspectorControls,
|
|
5
|
+
useBlockBindingsUtils
|
|
6
|
+
} from "@wordpress/block-editor";
|
|
7
|
+
import { BaseControl, Button } from "@wordpress/components";
|
|
8
|
+
import { __ } from "@wordpress/i18n";
|
|
9
|
+
import { PATTERN_OVERRIDES_BINDING_SOURCE } from "../constants";
|
|
10
|
+
import {
|
|
11
|
+
AllowOverridesModal,
|
|
12
|
+
DisallowOverridesModal
|
|
13
|
+
} from "./allow-overrides-modal";
|
|
15
14
|
function PatternOverridesControls({
|
|
16
15
|
attributes,
|
|
17
16
|
setAttributes,
|
|
@@ -24,9 +23,7 @@ function PatternOverridesControls({
|
|
|
24
23
|
const defaultBindings = attributes.metadata?.bindings?.__default;
|
|
25
24
|
const hasOverrides = hasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;
|
|
26
25
|
const isConnectedToOtherSources = defaultBindings?.source && defaultBindings.source !== PATTERN_OVERRIDES_BINDING_SOURCE;
|
|
27
|
-
const {
|
|
28
|
-
updateBlockBindings
|
|
29
|
-
} = useBlockBindingsUtils();
|
|
26
|
+
const { updateBlockBindings } = useBlockBindingsUtils();
|
|
30
27
|
function updateBindings(isChecked, customName) {
|
|
31
28
|
if (customName) {
|
|
32
29
|
setAttributes({
|
|
@@ -37,54 +34,68 @@ function PatternOverridesControls({
|
|
|
37
34
|
});
|
|
38
35
|
}
|
|
39
36
|
updateBlockBindings({
|
|
40
|
-
__default: isChecked ? {
|
|
41
|
-
source: PATTERN_OVERRIDES_BINDING_SOURCE
|
|
42
|
-
} : undefined
|
|
37
|
+
__default: isChecked ? { source: PATTERN_OVERRIDES_BINDING_SOURCE } : void 0
|
|
43
38
|
});
|
|
44
39
|
}
|
|
45
|
-
|
|
46
|
-
// Avoid overwriting other (e.g. meta) bindings.
|
|
47
40
|
if (isConnectedToOtherSources) {
|
|
48
41
|
return null;
|
|
49
42
|
}
|
|
50
|
-
const hasUnsupportedImageAttributes = blockName ===
|
|
51
|
-
const helpText = !hasOverrides && hasUnsupportedImageAttributes ? __(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
const hasUnsupportedImageAttributes = blockName === "core/image" && (!!attributes.caption?.length || !!attributes.href?.length);
|
|
44
|
+
const helpText = !hasOverrides && hasUnsupportedImageAttributes ? __(
|
|
45
|
+
`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`
|
|
46
|
+
) : __(
|
|
47
|
+
"Allow changes to this block throughout instances of this pattern."
|
|
48
|
+
);
|
|
49
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
50
|
+
/* @__PURE__ */ jsx(InspectorControls, { group: "advanced", children: /* @__PURE__ */ jsx(
|
|
51
|
+
BaseControl,
|
|
52
|
+
{
|
|
56
53
|
__nextHasNoMarginBottom: true,
|
|
57
54
|
id: controlId,
|
|
58
|
-
label: __(
|
|
55
|
+
label: __("Overrides"),
|
|
59
56
|
help: helpText,
|
|
60
|
-
children:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
onClose: () => setShowAllowOverridesModal(false),
|
|
80
|
-
onSave: newName => {
|
|
81
|
-
updateBindings(true, newName);
|
|
57
|
+
children: /* @__PURE__ */ jsx(
|
|
58
|
+
Button,
|
|
59
|
+
{
|
|
60
|
+
__next40pxDefaultSize: true,
|
|
61
|
+
className: "pattern-overrides-control__allow-overrides-button",
|
|
62
|
+
variant: "secondary",
|
|
63
|
+
"aria-haspopup": "dialog",
|
|
64
|
+
onClick: () => {
|
|
65
|
+
if (hasOverrides) {
|
|
66
|
+
setShowDisallowOverridesModal(true);
|
|
67
|
+
} else {
|
|
68
|
+
setShowAllowOverridesModal(true);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
disabled: !hasOverrides && hasUnsupportedImageAttributes,
|
|
72
|
+
accessibleWhenDisabled: true,
|
|
73
|
+
children: hasOverrides ? __("Disable overrides") : __("Enable overrides")
|
|
74
|
+
}
|
|
75
|
+
)
|
|
82
76
|
}
|
|
83
|
-
}),
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
77
|
+
) }),
|
|
78
|
+
showAllowOverridesModal && /* @__PURE__ */ jsx(
|
|
79
|
+
AllowOverridesModal,
|
|
80
|
+
{
|
|
81
|
+
initialName: attributes.metadata?.name,
|
|
82
|
+
onClose: () => setShowAllowOverridesModal(false),
|
|
83
|
+
onSave: (newName) => {
|
|
84
|
+
updateBindings(true, newName);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
),
|
|
88
|
+
showDisallowOverridesModal && /* @__PURE__ */ jsx(
|
|
89
|
+
DisallowOverridesModal,
|
|
90
|
+
{
|
|
91
|
+
onClose: () => setShowDisallowOverridesModal(false),
|
|
92
|
+
onSave: () => updateBindings(false)
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
] });
|
|
88
96
|
}
|
|
89
|
-
|
|
90
|
-
|
|
97
|
+
var pattern_overrides_controls_default = PatternOverridesControls;
|
|
98
|
+
export {
|
|
99
|
+
pattern_overrides_controls_default as default
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=pattern-overrides-controls.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/components/pattern-overrides-controls.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useState, useId } from '@wordpress/element';\nimport {\n\tInspectorControls,\n\tuseBlockBindingsUtils,\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';\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"],
|
|
5
|
+
"mappings": "AA4EE,mBAQG,KARH;AAzEF,SAAS,UAAU,aAAa;AAChC;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,aAAa,cAAc;AACpC,SAAS,UAAU;AAKnB,SAAS,wCAAwC;AACjD;AAAA,EACC;AAAA,EACA;AAAA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