@wordpress/patterns 2.0.1 → 2.1.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 +2 -0
- package/build/components/pattern-overrides-block-controls.js +130 -0
- package/build/components/pattern-overrides-block-controls.js.map +1 -0
- package/build/private-apis.js +2 -0
- package/build/private-apis.js.map +1 -1
- package/build-module/components/pattern-overrides-block-controls.js +124 -0
- package/build-module/components/pattern-overrides-block-controls.js.map +1 -0
- package/build-module/private-apis.js +2 -0
- package/build-module/private-apis.js.map +1 -1
- package/build-style/style-rtl.css +13 -0
- package/build-style/style.css +13 -0
- package/package.json +16 -16
- package/src/components/pattern-overrides-block-controls.js +155 -0
- package/src/components/style.scss +13 -0
- package/src/private-apis.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = PatternOverridesBlockControls;
|
|
7
|
+
var _element = require("@wordpress/element");
|
|
8
|
+
var _i18n = require("@wordpress/i18n");
|
|
9
|
+
var _components = require("@wordpress/components");
|
|
10
|
+
var _blocks = require("@wordpress/blocks");
|
|
11
|
+
var _data = require("@wordpress/data");
|
|
12
|
+
var _icons = require("@wordpress/icons");
|
|
13
|
+
var _blockEditor = require("@wordpress/block-editor");
|
|
14
|
+
var _lockUnlock = require("../lock-unlock");
|
|
15
|
+
var _constants = require("../constants");
|
|
16
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
|
+
/**
|
|
18
|
+
* WordPress dependencies
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Internal dependencies
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const {
|
|
26
|
+
useBlockDisplayTitle
|
|
27
|
+
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
28
|
+
function PatternOverridesToolbarIndicator({
|
|
29
|
+
clientIds
|
|
30
|
+
}) {
|
|
31
|
+
const isSingleBlockSelected = clientIds.length === 1;
|
|
32
|
+
const {
|
|
33
|
+
icon,
|
|
34
|
+
firstBlockName
|
|
35
|
+
} = (0, _data.useSelect)(select => {
|
|
36
|
+
const {
|
|
37
|
+
getBlockAttributes,
|
|
38
|
+
getBlockNamesByClientId
|
|
39
|
+
} = select(_blockEditor.store);
|
|
40
|
+
const {
|
|
41
|
+
getBlockType,
|
|
42
|
+
getActiveBlockVariation
|
|
43
|
+
} = select(_blocks.store);
|
|
44
|
+
const blockTypeNames = getBlockNamesByClientId(clientIds);
|
|
45
|
+
const _firstBlockTypeName = blockTypeNames[0];
|
|
46
|
+
const firstBlockType = getBlockType(_firstBlockTypeName);
|
|
47
|
+
let _icon;
|
|
48
|
+
if (isSingleBlockSelected) {
|
|
49
|
+
const match = getActiveBlockVariation(_firstBlockTypeName, getBlockAttributes(clientIds[0]));
|
|
50
|
+
// Take into account active block variations.
|
|
51
|
+
_icon = match?.icon || firstBlockType.icon;
|
|
52
|
+
} else {
|
|
53
|
+
const isSelectionOfSameType = new Set(blockTypeNames).size === 1;
|
|
54
|
+
// When selection consists of blocks of multiple types, display an
|
|
55
|
+
// appropriate icon to communicate the non-uniformity.
|
|
56
|
+
_icon = isSelectionOfSameType ? firstBlockType.icon : _icons.copy;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
icon: _icon,
|
|
60
|
+
firstBlockName: getBlockAttributes(clientIds[0]).metadata.name
|
|
61
|
+
};
|
|
62
|
+
}, [clientIds, isSingleBlockSelected]);
|
|
63
|
+
const firstBlockTitle = useBlockDisplayTitle({
|
|
64
|
+
clientId: clientIds[0],
|
|
65
|
+
maximumLength: 35
|
|
66
|
+
});
|
|
67
|
+
const blockDescription = isSingleBlockSelected ? (0, _i18n.sprintf)( /* translators: %1s: The block type's name; %2s: The block's user-provided name (the same as the override name). */
|
|
68
|
+
(0, _i18n.__)('This %1$s is editable using the "%2$s" override.'), firstBlockTitle.toLowerCase(), firstBlockName) : (0, _i18n.__)('These blocks are editable using overrides.');
|
|
69
|
+
const descriptionId = (0, _element.useId)();
|
|
70
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarItem, {
|
|
71
|
+
children: toggleProps => /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.DropdownMenu, {
|
|
72
|
+
className: "patterns-pattern-overrides-toolbar-indicator",
|
|
73
|
+
label: firstBlockTitle,
|
|
74
|
+
popoverProps: {
|
|
75
|
+
placement: 'bottom-start',
|
|
76
|
+
className: 'patterns-pattern-overrides-toolbar-indicator__popover'
|
|
77
|
+
},
|
|
78
|
+
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
79
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.BlockIcon, {
|
|
80
|
+
icon: icon,
|
|
81
|
+
className: "patterns-pattern-overrides-toolbar-indicator-icon",
|
|
82
|
+
showColors: true
|
|
83
|
+
})
|
|
84
|
+
}),
|
|
85
|
+
toggleProps: {
|
|
86
|
+
describedBy: blockDescription,
|
|
87
|
+
...toggleProps
|
|
88
|
+
},
|
|
89
|
+
menuProps: {
|
|
90
|
+
orientation: 'both',
|
|
91
|
+
'aria-describedby': descriptionId
|
|
92
|
+
},
|
|
93
|
+
children: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalText, {
|
|
94
|
+
id: descriptionId,
|
|
95
|
+
children: blockDescription
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function PatternOverridesBlockControls() {
|
|
101
|
+
const {
|
|
102
|
+
clientIds,
|
|
103
|
+
hasPatternOverrides,
|
|
104
|
+
hasParentPattern
|
|
105
|
+
} = (0, _data.useSelect)(select => {
|
|
106
|
+
const {
|
|
107
|
+
getBlockAttributes,
|
|
108
|
+
getSelectedBlockClientIds,
|
|
109
|
+
getBlockParentsByBlockName
|
|
110
|
+
} = select(_blockEditor.store);
|
|
111
|
+
const selectedClientIds = getSelectedBlockClientIds();
|
|
112
|
+
const _hasPatternOverrides = selectedClientIds.every(clientId => {
|
|
113
|
+
var _getBlockAttributes$m;
|
|
114
|
+
return Object.values((_getBlockAttributes$m = getBlockAttributes(clientId)?.metadata?.bindings) !== null && _getBlockAttributes$m !== void 0 ? _getBlockAttributes$m : {}).some(binding => binding?.source === _constants.PATTERN_OVERRIDES_BINDING_SOURCE);
|
|
115
|
+
});
|
|
116
|
+
const _hasParentPattern = selectedClientIds.every(clientId => getBlockParentsByBlockName(clientId, 'core/block', true).length > 0);
|
|
117
|
+
return {
|
|
118
|
+
clientIds: selectedClientIds,
|
|
119
|
+
hasPatternOverrides: _hasPatternOverrides,
|
|
120
|
+
hasParentPattern: _hasParentPattern
|
|
121
|
+
};
|
|
122
|
+
}, []);
|
|
123
|
+
return hasPatternOverrides && hasParentPattern ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.BlockControls, {
|
|
124
|
+
group: "parent",
|
|
125
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(PatternOverridesToolbarIndicator, {
|
|
126
|
+
clientIds: clientIds
|
|
127
|
+
})
|
|
128
|
+
}) : null;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=pattern-overrides-block-controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_element","require","_i18n","_components","_blocks","_data","_icons","_blockEditor","_lockUnlock","_constants","_jsxRuntime","useBlockDisplayTitle","unlock","blockEditorPrivateApis","PatternOverridesToolbarIndicator","clientIds","isSingleBlockSelected","length","icon","firstBlockName","useSelect","select","getBlockAttributes","getBlockNamesByClientId","blockEditorStore","getBlockType","getActiveBlockVariation","blocksStore","blockTypeNames","_firstBlockTypeName","firstBlockType","_icon","match","isSelectionOfSameType","Set","size","copy","metadata","name","firstBlockTitle","clientId","maximumLength","blockDescription","sprintf","__","toLowerCase","descriptionId","useId","jsx","ToolbarItem","children","toggleProps","DropdownMenu","className","label","popoverProps","placement","Fragment","BlockIcon","showColors","describedBy","menuProps","orientation","__experimentalText","id","PatternOverridesBlockControls","hasPatternOverrides","hasParentPattern","getSelectedBlockClientIds","getBlockParentsByBlockName","selectedClientIds","_hasPatternOverrides","every","_getBlockAttributes$m","Object","values","bindings","some","binding","source","PATTERN_OVERRIDES_BINDING_SOURCE","_hasParentPattern","BlockControls","group"],"sources":["@wordpress/patterns/src/components/pattern-overrides-block-controls.js"],"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: %1s: The block type's name; %2s: 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\tdescribedBy: 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"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAKA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAUA,IAAAO,WAAA,GAAAP,OAAA;AACA,IAAAQ,UAAA,GAAAR,OAAA;AAAgE,IAAAS,WAAA,GAAAT,OAAA;AAxBhE;AACA;AACA;;AAkBA;AACA;AACA;;AAIA,MAAM;EAAEU;AAAqB,CAAC,GAAG,IAAAC,kBAAM,EAAEC,wBAAuB,CAAC;AAEjE,SAASC,gCAAgCA,CAAE;EAAEC;AAAU,CAAC,EAAG;EAC1D,MAAMC,qBAAqB,GAAGD,SAAS,CAACE,MAAM,KAAK,CAAC;EACpD,MAAM;IAAEC,IAAI;IAAEC;EAAe,CAAC,GAAG,IAAAC,eAAS,EACvCC,MAAM,IAAM;IACb,MAAM;MAAEC,kBAAkB;MAAEC;IAAwB,CAAC,GACpDF,MAAM,CAAEG,kBAAiB,CAAC;IAC3B,MAAM;MAAEC,YAAY;MAAEC;IAAwB,CAAC,GAC9CL,MAAM,CAAEM,aAAY,CAAC;IACtB,MAAMC,cAAc,GAAGL,uBAAuB,CAAER,SAAU,CAAC;IAC3D,MAAMc,mBAAmB,GAAGD,cAAc,CAAE,CAAC,CAAE;IAC/C,MAAME,cAAc,GAAGL,YAAY,CAAEI,mBAAoB,CAAC;IAC1D,IAAIE,KAAK;IACT,IAAKf,qBAAqB,EAAG;MAC5B,MAAMg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ACE,KAAK,CAC9ChC,QAAQ,IACT6B,0BAA0B,CAAE7B,QAAQ,EAAE,YAAY,EAAE,IAAK,CAAC,CACxDvB,MAAM,GAAG,CACb,CAAC;IACD,OAAO;MACNF,SAAS,EAAEuD,iBAAiB;MAC5BJ,mBAAmB,EAAEK,oBAAoB;MACzCJ,gBAAgB,EAAEc;IACnB,CAAC;EACF,CAAC,EACD,EACD,CAAC;EAED,OAAOf,mBAAmB,IAAIC,gBAAgB,gBAC7C,IAAAzD,WAAA,CAAAsC,GAAA,EAACzC,YAAA,CAAA2E,aAAa;IAACC,KAAK,EAAC,QAAQ;IAAAjC,QAAA,eAC5B,IAAAxC,WAAA,CAAAsC,GAAA,EAAClC,gCAAgC;MAACC,SAAS,EAAGA;IAAW,CAAE;EAAC,CAC9C,CAAC,GACb,IAAI;AACT","ignoreList":[]}
|
package/build/private-apis.js
CHANGED
|
@@ -15,6 +15,7 @@ var _components = _interopRequireDefault(require("./components"));
|
|
|
15
15
|
var _renamePatternCategoryModal = _interopRequireDefault(require("./components/rename-pattern-category-modal"));
|
|
16
16
|
var _patternOverridesControls = _interopRequireDefault(require("./components/pattern-overrides-controls"));
|
|
17
17
|
var _resetOverridesControl = _interopRequireDefault(require("./components/reset-overrides-control"));
|
|
18
|
+
var _patternOverridesBlockControls = _interopRequireDefault(require("./components/pattern-overrides-block-controls"));
|
|
18
19
|
var _privateHooks = require("./private-hooks");
|
|
19
20
|
var _constants = require("./constants");
|
|
20
21
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -37,6 +38,7 @@ const privateApis = exports.privateApis = {};
|
|
|
37
38
|
RenamePatternCategoryModal: _renamePatternCategoryModal.default,
|
|
38
39
|
PatternOverridesControls: _patternOverridesControls.default,
|
|
39
40
|
ResetOverridesControl: _resetOverridesControl.default,
|
|
41
|
+
PatternOverridesBlockControls: _patternOverridesBlockControls.default,
|
|
40
42
|
useAddPatternCategory: _privateHooks.useAddPatternCategory,
|
|
41
43
|
PATTERN_TYPES: _constants.PATTERN_TYPES,
|
|
42
44
|
PATTERN_DEFAULT_CATEGORY: _constants.PATTERN_DEFAULT_CATEGORY,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_lockUnlock","require","_overridesPanel","_interopRequireDefault","_createPatternModal","_interopRequireWildcard","_duplicatePatternModal","_api","_renamePatternModal","_components","_renamePatternCategoryModal","_patternOverridesControls","_resetOverridesControl","_privateHooks","_constants","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","privateApis","exports","lock","OverridesPanel","CreatePatternModal","CreatePatternModalContents","DuplicatePatternModal","isOverridableBlock","hasOverridableBlocks","useDuplicatePatternProps","RenamePatternModal","PatternsMenuItems","RenamePatternCategoryModal","PatternOverridesControls","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 OverridesPanel from './components/overrides-panel';\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 { isOverridableBlock, hasOverridableBlocks } from './api';\nimport RenamePatternModal from './components/rename-pattern-modal';\nimport PatternsMenuItems from './components';\nimport RenamePatternCategoryModal from './components/rename-pattern-category-modal';\nimport PatternOverridesControls from './components/pattern-overrides-controls';\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\tOverridesPanel,\n\tCreatePatternModal,\n\tCreatePatternModalContents,\n\tDuplicatePatternModal,\n\tisOverridableBlock,\n\thasOverridableBlocks,\n\tuseDuplicatePatternProps,\n\tRenamePatternModal,\n\tPatternsMenuItems,\n\tRenamePatternCategoryModal,\n\tPatternOverridesControls,\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,eAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAIA,IAAAK,sBAAA,GAAAD,uBAAA,CAAAJ,OAAA;AAIA,IAAAM,IAAA,GAAAN,OAAA;AACA,IAAAO,mBAAA,GAAAL,sBAAA,CAAAF,OAAA;AACA,IAAAQ,WAAA,GAAAN,sBAAA,CAAAF,OAAA;AACA,IAAAS,2BAAA,GAAAP,sBAAA,CAAAF,OAAA;AACA,IAAAU,yBAAA,GAAAR,sBAAA,CAAAF,OAAA;AACA,IAAAW,sBAAA,GAAAT,sBAAA,CAAAF,OAAA;AACA,IAAAY,
|
|
1
|
+
{"version":3,"names":["_lockUnlock","require","_overridesPanel","_interopRequireDefault","_createPatternModal","_interopRequireWildcard","_duplicatePatternModal","_api","_renamePatternModal","_components","_renamePatternCategoryModal","_patternOverridesControls","_resetOverridesControl","_patternOverridesBlockControls","_privateHooks","_constants","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","privateApis","exports","lock","OverridesPanel","CreatePatternModal","CreatePatternModalContents","DuplicatePatternModal","isOverridableBlock","hasOverridableBlocks","useDuplicatePatternProps","RenamePatternModal","PatternsMenuItems","RenamePatternCategoryModal","PatternOverridesControls","ResetOverridesControl","PatternOverridesBlockControls","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 OverridesPanel from './components/overrides-panel';\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 { isOverridableBlock, hasOverridableBlocks } from './api';\nimport RenamePatternModal from './components/rename-pattern-modal';\nimport PatternsMenuItems from './components';\nimport RenamePatternCategoryModal from './components/rename-pattern-category-modal';\nimport PatternOverridesControls from './components/pattern-overrides-controls';\nimport ResetOverridesControl from './components/reset-overrides-control';\nimport PatternOverridesBlockControls from './components/pattern-overrides-block-controls';\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\tOverridesPanel,\n\tCreatePatternModal,\n\tCreatePatternModalContents,\n\tDuplicatePatternModal,\n\tisOverridableBlock,\n\thasOverridableBlocks,\n\tuseDuplicatePatternProps,\n\tRenamePatternModal,\n\tPatternsMenuItems,\n\tRenamePatternCategoryModal,\n\tPatternOverridesControls,\n\tResetOverridesControl,\n\tPatternOverridesBlockControls,\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,eAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAIA,IAAAK,sBAAA,GAAAD,uBAAA,CAAAJ,OAAA;AAIA,IAAAM,IAAA,GAAAN,OAAA;AACA,IAAAO,mBAAA,GAAAL,sBAAA,CAAAF,OAAA;AACA,IAAAQ,WAAA,GAAAN,sBAAA,CAAAF,OAAA;AACA,IAAAS,2BAAA,GAAAP,sBAAA,CAAAF,OAAA;AACA,IAAAU,yBAAA,GAAAR,sBAAA,CAAAF,OAAA;AACA,IAAAW,sBAAA,GAAAT,sBAAA,CAAAF,OAAA;AACA,IAAAY,8BAAA,GAAAV,sBAAA,CAAAF,OAAA;AACA,IAAAa,aAAA,GAAAb,OAAA;AACA,IAAAc,UAAA,GAAAd,OAAA;AAOqB,SAAAe,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAZ,wBAAAY,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAA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BA,8BAAqB;EACrBC,6BAA6B,EAA7BA,sCAA6B;EAC7BC,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","ignoreList":[]}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useId } from '@wordpress/element';
|
|
5
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
6
|
+
import { DropdownMenu, ToolbarItem, __experimentalText as Text } from '@wordpress/components';
|
|
7
|
+
import { store as blocksStore } from '@wordpress/blocks';
|
|
8
|
+
import { useSelect } from '@wordpress/data';
|
|
9
|
+
import { copy } from '@wordpress/icons';
|
|
10
|
+
import { store as blockEditorStore, BlockIcon, privateApis as blockEditorPrivateApis, BlockControls } from '@wordpress/block-editor';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import { unlock } from '../lock-unlock';
|
|
16
|
+
import { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';
|
|
17
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
19
|
+
const {
|
|
20
|
+
useBlockDisplayTitle
|
|
21
|
+
} = unlock(blockEditorPrivateApis);
|
|
22
|
+
function PatternOverridesToolbarIndicator({
|
|
23
|
+
clientIds
|
|
24
|
+
}) {
|
|
25
|
+
const isSingleBlockSelected = clientIds.length === 1;
|
|
26
|
+
const {
|
|
27
|
+
icon,
|
|
28
|
+
firstBlockName
|
|
29
|
+
} = useSelect(select => {
|
|
30
|
+
const {
|
|
31
|
+
getBlockAttributes,
|
|
32
|
+
getBlockNamesByClientId
|
|
33
|
+
} = select(blockEditorStore);
|
|
34
|
+
const {
|
|
35
|
+
getBlockType,
|
|
36
|
+
getActiveBlockVariation
|
|
37
|
+
} = select(blocksStore);
|
|
38
|
+
const blockTypeNames = getBlockNamesByClientId(clientIds);
|
|
39
|
+
const _firstBlockTypeName = blockTypeNames[0];
|
|
40
|
+
const firstBlockType = getBlockType(_firstBlockTypeName);
|
|
41
|
+
let _icon;
|
|
42
|
+
if (isSingleBlockSelected) {
|
|
43
|
+
const match = getActiveBlockVariation(_firstBlockTypeName, getBlockAttributes(clientIds[0]));
|
|
44
|
+
// Take into account active block variations.
|
|
45
|
+
_icon = match?.icon || firstBlockType.icon;
|
|
46
|
+
} else {
|
|
47
|
+
const isSelectionOfSameType = new Set(blockTypeNames).size === 1;
|
|
48
|
+
// When selection consists of blocks of multiple types, display an
|
|
49
|
+
// appropriate icon to communicate the non-uniformity.
|
|
50
|
+
_icon = isSelectionOfSameType ? firstBlockType.icon : copy;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
icon: _icon,
|
|
54
|
+
firstBlockName: getBlockAttributes(clientIds[0]).metadata.name
|
|
55
|
+
};
|
|
56
|
+
}, [clientIds, isSingleBlockSelected]);
|
|
57
|
+
const firstBlockTitle = useBlockDisplayTitle({
|
|
58
|
+
clientId: clientIds[0],
|
|
59
|
+
maximumLength: 35
|
|
60
|
+
});
|
|
61
|
+
const blockDescription = isSingleBlockSelected ? sprintf( /* translators: %1s: The block type's name; %2s: The block's user-provided name (the same as the override name). */
|
|
62
|
+
__('This %1$s is editable using the "%2$s" override.'), firstBlockTitle.toLowerCase(), firstBlockName) : __('These blocks are editable using overrides.');
|
|
63
|
+
const descriptionId = useId();
|
|
64
|
+
return /*#__PURE__*/_jsx(ToolbarItem, {
|
|
65
|
+
children: toggleProps => /*#__PURE__*/_jsx(DropdownMenu, {
|
|
66
|
+
className: "patterns-pattern-overrides-toolbar-indicator",
|
|
67
|
+
label: firstBlockTitle,
|
|
68
|
+
popoverProps: {
|
|
69
|
+
placement: 'bottom-start',
|
|
70
|
+
className: 'patterns-pattern-overrides-toolbar-indicator__popover'
|
|
71
|
+
},
|
|
72
|
+
icon: /*#__PURE__*/_jsx(_Fragment, {
|
|
73
|
+
children: /*#__PURE__*/_jsx(BlockIcon, {
|
|
74
|
+
icon: icon,
|
|
75
|
+
className: "patterns-pattern-overrides-toolbar-indicator-icon",
|
|
76
|
+
showColors: true
|
|
77
|
+
})
|
|
78
|
+
}),
|
|
79
|
+
toggleProps: {
|
|
80
|
+
describedBy: blockDescription,
|
|
81
|
+
...toggleProps
|
|
82
|
+
},
|
|
83
|
+
menuProps: {
|
|
84
|
+
orientation: 'both',
|
|
85
|
+
'aria-describedby': descriptionId
|
|
86
|
+
},
|
|
87
|
+
children: () => /*#__PURE__*/_jsx(Text, {
|
|
88
|
+
id: descriptionId,
|
|
89
|
+
children: blockDescription
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
export default function PatternOverridesBlockControls() {
|
|
95
|
+
const {
|
|
96
|
+
clientIds,
|
|
97
|
+
hasPatternOverrides,
|
|
98
|
+
hasParentPattern
|
|
99
|
+
} = useSelect(select => {
|
|
100
|
+
const {
|
|
101
|
+
getBlockAttributes,
|
|
102
|
+
getSelectedBlockClientIds,
|
|
103
|
+
getBlockParentsByBlockName
|
|
104
|
+
} = select(blockEditorStore);
|
|
105
|
+
const selectedClientIds = getSelectedBlockClientIds();
|
|
106
|
+
const _hasPatternOverrides = selectedClientIds.every(clientId => {
|
|
107
|
+
var _getBlockAttributes$m;
|
|
108
|
+
return Object.values((_getBlockAttributes$m = getBlockAttributes(clientId)?.metadata?.bindings) !== null && _getBlockAttributes$m !== void 0 ? _getBlockAttributes$m : {}).some(binding => binding?.source === PATTERN_OVERRIDES_BINDING_SOURCE);
|
|
109
|
+
});
|
|
110
|
+
const _hasParentPattern = selectedClientIds.every(clientId => getBlockParentsByBlockName(clientId, 'core/block', true).length > 0);
|
|
111
|
+
return {
|
|
112
|
+
clientIds: selectedClientIds,
|
|
113
|
+
hasPatternOverrides: _hasPatternOverrides,
|
|
114
|
+
hasParentPattern: _hasParentPattern
|
|
115
|
+
};
|
|
116
|
+
}, []);
|
|
117
|
+
return hasPatternOverrides && hasParentPattern ? /*#__PURE__*/_jsx(BlockControls, {
|
|
118
|
+
group: "parent",
|
|
119
|
+
children: /*#__PURE__*/_jsx(PatternOverridesToolbarIndicator, {
|
|
120
|
+
clientIds: clientIds
|
|
121
|
+
})
|
|
122
|
+
}) : null;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=pattern-overrides-block-controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useId","__","sprintf","DropdownMenu","ToolbarItem","__experimentalText","Text","store","blocksStore","useSelect","copy","blockEditorStore","BlockIcon","privateApis","blockEditorPrivateApis","BlockControls","unlock","PATTERN_OVERRIDES_BINDING_SOURCE","jsx","_jsx","Fragment","_Fragment","useBlockDisplayTitle","PatternOverridesToolbarIndicator","clientIds","isSingleBlockSelected","length","icon","firstBlockName","select","getBlockAttributes","getBlockNamesByClientId","getBlockType","getActiveBlockVariation","blockTypeNames","_firstBlockTypeName","firstBlockType","_icon","match","isSelectionOfSameType","Set","size","metadata","name","firstBlockTitle","clientId","maximumLength","blockDescription","toLowerCase","descriptionId","children","toggleProps","className","label","popoverProps","placement","showColors","describedBy","menuProps","orientation","id","PatternOverridesBlockControls","hasPatternOverrides","hasParentPattern","getSelectedBlockClientIds","getBlockParentsByBlockName","selectedClientIds","_hasPatternOverrides","every","_getBlockAttributes$m","Object","values","bindings","some","binding","source","_hasParentPattern","group"],"sources":["@wordpress/patterns/src/components/pattern-overrides-block-controls.js"],"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: %1s: The block type's name; %2s: 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\tdescribedBy: 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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SACCC,YAAY,EACZC,WAAW,EACXC,kBAAkB,IAAIC,IAAI,QACpB,uBAAuB;AAC9B,SAASC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACxD,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,IAAI,QAAQ,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enamePatternCategoryModal from './components/rename-pattern-category-modal';
|
|
12
12
|
import PatternOverridesControls from './components/pattern-overrides-controls';
|
|
13
13
|
import ResetOverridesControl from './components/reset-overrides-control';
|
|
14
|
+
import PatternOverridesBlockControls from './components/pattern-overrides-block-controls';
|
|
14
15
|
import { useAddPatternCategory } from './private-hooks';
|
|
15
16
|
import { PATTERN_TYPES, PATTERN_DEFAULT_CATEGORY, PATTERN_USER_CATEGORY, EXCLUDED_PATTERN_SOURCES, PATTERN_SYNC_TYPES, PARTIAL_SYNCING_SUPPORTED_BLOCKS } from './constants';
|
|
16
17
|
export const privateApis = {};
|
|
@@ -27,6 +28,7 @@ lock(privateApis, {
|
|
|
27
28
|
RenamePatternCategoryModal,
|
|
28
29
|
PatternOverridesControls,
|
|
29
30
|
ResetOverridesControl,
|
|
31
|
+
PatternOverridesBlockControls,
|
|
30
32
|
useAddPatternCategory,
|
|
31
33
|
PATTERN_TYPES,
|
|
32
34
|
PATTERN_DEFAULT_CATEGORY,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["lock","OverridesPanel","default","CreatePatternModal","CreatePatternModalContents","DuplicatePatternModal","useDuplicatePatternProps","isOverridableBlock","hasOverridableBlocks","RenamePatternModal","PatternsMenuItems","RenamePatternCategoryModal","PatternOverridesControls","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 OverridesPanel from './components/overrides-panel';\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 { isOverridableBlock, hasOverridableBlocks } from './api';\nimport RenamePatternModal from './components/rename-pattern-modal';\nimport PatternsMenuItems from './components';\nimport RenamePatternCategoryModal from './components/rename-pattern-category-modal';\nimport PatternOverridesControls from './components/pattern-overrides-controls';\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\tOverridesPanel,\n\tCreatePatternModal,\n\tCreatePatternModalContents,\n\tDuplicatePatternModal,\n\tisOverridableBlock,\n\thasOverridableBlocks,\n\tuseDuplicatePatternProps,\n\tRenamePatternModal,\n\tPatternsMenuItems,\n\tRenamePatternCategoryModal,\n\tPatternOverridesControls,\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,OAAOC,cAAc,MAAM,8BAA8B;AACzD,SACCC,OAAO,IAAIC,kBAAkB,EAC7BC,0BAA0B,QACpB,mCAAmC;AAC1C,SACCF,OAAO,IAAIG,qBAAqB,EAChCC,wBAAwB,QAClB,sCAAsC;AAC7C,SAASC,kBAAkB,EAAEC,oBAAoB,QAAQ,OAAO;AAChE,OAAOC,kBAAkB,MAAM,mCAAmC;AAClE,OAAOC,iBAAiB,MAAM,cAAc;AAC5C,OAAOC,0BAA0B,MAAM,4CAA4C;AACnF,OAAOC,wBAAwB,MAAM,yCAAyC;AAC9E,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;
|
|
1
|
+
{"version":3,"names":["lock","OverridesPanel","default","CreatePatternModal","CreatePatternModalContents","DuplicatePatternModal","useDuplicatePatternProps","isOverridableBlock","hasOverridableBlocks","RenamePatternModal","PatternsMenuItems","RenamePatternCategoryModal","PatternOverridesControls","ResetOverridesControl","PatternOverridesBlockControls","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 OverridesPanel from './components/overrides-panel';\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 { isOverridableBlock, hasOverridableBlocks } from './api';\nimport RenamePatternModal from './components/rename-pattern-modal';\nimport PatternsMenuItems from './components';\nimport RenamePatternCategoryModal from './components/rename-pattern-category-modal';\nimport PatternOverridesControls from './components/pattern-overrides-controls';\nimport ResetOverridesControl from './components/reset-overrides-control';\nimport PatternOverridesBlockControls from './components/pattern-overrides-block-controls';\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\tOverridesPanel,\n\tCreatePatternModal,\n\tCreatePatternModalContents,\n\tDuplicatePatternModal,\n\tisOverridableBlock,\n\thasOverridableBlocks,\n\tuseDuplicatePatternProps,\n\tRenamePatternModal,\n\tPatternsMenuItems,\n\tRenamePatternCategoryModal,\n\tPatternOverridesControls,\n\tResetOverridesControl,\n\tPatternOverridesBlockControls,\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,OAAOC,cAAc,MAAM,8BAA8B;AACzD,SACCC,OAAO,IAAIC,kBAAkB,EAC7BC,0BAA0B,QACpB,mCAAmC;AAC1C,SACCF,OAAO,IAAIG,qBAAqB,EAChCC,wBAAwB,QAClB,sCAAsC;AAC7C,SAASC,kBAAkB,EAAEC,oBAAoB,QAAQ,OAAO;AAChE,OAAOC,kBAAkB,MAAM,mCAAmC;AAClE,OAAOC,iBAAiB,MAAM,cAAc;AAC5C,OAAOC,0BAA0B,MAAM,4CAA4C;AACnF,OAAOC,wBAAwB,MAAM,yCAAyC;AAC9E,OAAOC,qBAAqB,MAAM,sCAAsC;AACxE,OAAOC,6BAA6B,MAAM,+CAA+C;AACzF,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;AAC7BtB,IAAI,CAAEsB,WAAW,EAAE;EAClBrB,cAAc;EACdE,kBAAkB;EAClBC,0BAA0B;EAC1BC,qBAAqB;EACrBE,kBAAkB;EAClBC,oBAAoB;EACpBF,wBAAwB;EACxBG,kBAAkB;EAClBC,iBAAiB;EACjBC,0BAA0B;EAC1BC,wBAAwB;EACxBC,qBAAqB;EACrBC,6BAA6B;EAC7BC,qBAAqB;EACrBC,aAAa;EACbC,wBAAwB;EACxBC,qBAAqB;EACrBC,wBAAwB;EACxBC,kBAAkB;EAClBC;AACD,CAAE,CAAC","ignoreList":[]}
|
|
@@ -144,4 +144,17 @@
|
|
|
144
144
|
.pattern-overrides-control__allow-overrides-button {
|
|
145
145
|
width: 100%;
|
|
146
146
|
justify-content: center;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.patterns-pattern-overrides-toolbar-indicator__popover .components-popover__content {
|
|
150
|
+
min-width: 260px;
|
|
151
|
+
padding: 16px;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.patterns-pattern-overrides-toolbar-indicator .patterns-pattern-overrides-toolbar-indicator-icon.has-colors svg {
|
|
155
|
+
fill: var(--wp-block-synced-color);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.editor-collapsible-block-toolbar .patterns-pattern-overrides-toolbar-indicator {
|
|
159
|
+
height: 32px;
|
|
147
160
|
}
|
package/build-style/style.css
CHANGED
|
@@ -144,4 +144,17 @@
|
|
|
144
144
|
.pattern-overrides-control__allow-overrides-button {
|
|
145
145
|
width: 100%;
|
|
146
146
|
justify-content: center;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.patterns-pattern-overrides-toolbar-indicator__popover .components-popover__content {
|
|
150
|
+
min-width: 260px;
|
|
151
|
+
padding: 16px;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.patterns-pattern-overrides-toolbar-indicator .patterns-pattern-overrides-toolbar-indicator-icon.has-colors svg {
|
|
155
|
+
fill: var(--wp-block-synced-color);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.editor-collapsible-block-toolbar .patterns-pattern-overrides-toolbar-indicator {
|
|
159
|
+
height: 32px;
|
|
147
160
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/patterns",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.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.0
|
|
36
|
-
"@wordpress/block-editor": "^13.0
|
|
37
|
-
"@wordpress/blocks": "^13.0
|
|
38
|
-
"@wordpress/components": "^28.0
|
|
39
|
-
"@wordpress/compose": "^7.0
|
|
40
|
-
"@wordpress/core-data": "^7.0
|
|
41
|
-
"@wordpress/data": "^10.0
|
|
42
|
-
"@wordpress/element": "^6.0
|
|
43
|
-
"@wordpress/html-entities": "^4.0
|
|
44
|
-
"@wordpress/i18n": "^5.0
|
|
45
|
-
"@wordpress/icons": "^10.0
|
|
46
|
-
"@wordpress/notices": "^5.0
|
|
47
|
-
"@wordpress/private-apis": "^1.0
|
|
48
|
-
"@wordpress/url": "^4.0
|
|
35
|
+
"@wordpress/a11y": "^4.1.0",
|
|
36
|
+
"@wordpress/block-editor": "^13.1.0",
|
|
37
|
+
"@wordpress/blocks": "^13.1.0",
|
|
38
|
+
"@wordpress/components": "^28.1.0",
|
|
39
|
+
"@wordpress/compose": "^7.1.0",
|
|
40
|
+
"@wordpress/core-data": "^7.1.0",
|
|
41
|
+
"@wordpress/data": "^10.1.0",
|
|
42
|
+
"@wordpress/element": "^6.1.0",
|
|
43
|
+
"@wordpress/html-entities": "^4.1.0",
|
|
44
|
+
"@wordpress/i18n": "^5.1.0",
|
|
45
|
+
"@wordpress/icons": "^10.1.0",
|
|
46
|
+
"@wordpress/notices": "^5.1.0",
|
|
47
|
+
"@wordpress/private-apis": "^1.1.0",
|
|
48
|
+
"@wordpress/url": "^4.1.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": "66d3bf12e67d16deddc4b4a9ec42e1d0bed3479a"
|
|
58
58
|
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useId } from '@wordpress/element';
|
|
5
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
6
|
+
import {
|
|
7
|
+
DropdownMenu,
|
|
8
|
+
ToolbarItem,
|
|
9
|
+
__experimentalText as Text,
|
|
10
|
+
} from '@wordpress/components';
|
|
11
|
+
import { store as blocksStore } from '@wordpress/blocks';
|
|
12
|
+
import { useSelect } from '@wordpress/data';
|
|
13
|
+
import { copy } from '@wordpress/icons';
|
|
14
|
+
import {
|
|
15
|
+
store as blockEditorStore,
|
|
16
|
+
BlockIcon,
|
|
17
|
+
privateApis as blockEditorPrivateApis,
|
|
18
|
+
BlockControls,
|
|
19
|
+
} from '@wordpress/block-editor';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Internal dependencies
|
|
23
|
+
*/
|
|
24
|
+
import { unlock } from '../lock-unlock';
|
|
25
|
+
import { PATTERN_OVERRIDES_BINDING_SOURCE } from '../constants';
|
|
26
|
+
|
|
27
|
+
const { useBlockDisplayTitle } = unlock( blockEditorPrivateApis );
|
|
28
|
+
|
|
29
|
+
function PatternOverridesToolbarIndicator( { clientIds } ) {
|
|
30
|
+
const isSingleBlockSelected = clientIds.length === 1;
|
|
31
|
+
const { icon, firstBlockName } = useSelect(
|
|
32
|
+
( select ) => {
|
|
33
|
+
const { getBlockAttributes, getBlockNamesByClientId } =
|
|
34
|
+
select( blockEditorStore );
|
|
35
|
+
const { getBlockType, getActiveBlockVariation } =
|
|
36
|
+
select( blocksStore );
|
|
37
|
+
const blockTypeNames = getBlockNamesByClientId( clientIds );
|
|
38
|
+
const _firstBlockTypeName = blockTypeNames[ 0 ];
|
|
39
|
+
const firstBlockType = getBlockType( _firstBlockTypeName );
|
|
40
|
+
let _icon;
|
|
41
|
+
if ( isSingleBlockSelected ) {
|
|
42
|
+
const match = getActiveBlockVariation(
|
|
43
|
+
_firstBlockTypeName,
|
|
44
|
+
getBlockAttributes( clientIds[ 0 ] )
|
|
45
|
+
);
|
|
46
|
+
// Take into account active block variations.
|
|
47
|
+
_icon = match?.icon || firstBlockType.icon;
|
|
48
|
+
} else {
|
|
49
|
+
const isSelectionOfSameType =
|
|
50
|
+
new Set( blockTypeNames ).size === 1;
|
|
51
|
+
// When selection consists of blocks of multiple types, display an
|
|
52
|
+
// appropriate icon to communicate the non-uniformity.
|
|
53
|
+
_icon = isSelectionOfSameType ? firstBlockType.icon : copy;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
icon: _icon,
|
|
58
|
+
firstBlockName: getBlockAttributes( clientIds[ 0 ] ).metadata
|
|
59
|
+
.name,
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
[ clientIds, isSingleBlockSelected ]
|
|
63
|
+
);
|
|
64
|
+
const firstBlockTitle = useBlockDisplayTitle( {
|
|
65
|
+
clientId: clientIds[ 0 ],
|
|
66
|
+
maximumLength: 35,
|
|
67
|
+
} );
|
|
68
|
+
|
|
69
|
+
const blockDescription = isSingleBlockSelected
|
|
70
|
+
? sprintf(
|
|
71
|
+
/* translators: %1s: The block type's name; %2s: The block's user-provided name (the same as the override name). */
|
|
72
|
+
__( 'This %1$s is editable using the "%2$s" override.' ),
|
|
73
|
+
firstBlockTitle.toLowerCase(),
|
|
74
|
+
firstBlockName
|
|
75
|
+
)
|
|
76
|
+
: __( 'These blocks are editable using overrides.' );
|
|
77
|
+
|
|
78
|
+
const descriptionId = useId();
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<ToolbarItem>
|
|
82
|
+
{ ( toggleProps ) => (
|
|
83
|
+
<DropdownMenu
|
|
84
|
+
className="patterns-pattern-overrides-toolbar-indicator"
|
|
85
|
+
label={ firstBlockTitle }
|
|
86
|
+
popoverProps={ {
|
|
87
|
+
placement: 'bottom-start',
|
|
88
|
+
className:
|
|
89
|
+
'patterns-pattern-overrides-toolbar-indicator__popover',
|
|
90
|
+
} }
|
|
91
|
+
icon={
|
|
92
|
+
<>
|
|
93
|
+
<BlockIcon
|
|
94
|
+
icon={ icon }
|
|
95
|
+
className="patterns-pattern-overrides-toolbar-indicator-icon"
|
|
96
|
+
showColors
|
|
97
|
+
/>
|
|
98
|
+
</>
|
|
99
|
+
}
|
|
100
|
+
toggleProps={ {
|
|
101
|
+
describedBy: blockDescription,
|
|
102
|
+
...toggleProps,
|
|
103
|
+
} }
|
|
104
|
+
menuProps={ {
|
|
105
|
+
orientation: 'both',
|
|
106
|
+
'aria-describedby': descriptionId,
|
|
107
|
+
} }
|
|
108
|
+
>
|
|
109
|
+
{ () => (
|
|
110
|
+
<Text id={ descriptionId }>{ blockDescription }</Text>
|
|
111
|
+
) }
|
|
112
|
+
</DropdownMenu>
|
|
113
|
+
) }
|
|
114
|
+
</ToolbarItem>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export default function PatternOverridesBlockControls() {
|
|
119
|
+
const { clientIds, hasPatternOverrides, hasParentPattern } = useSelect(
|
|
120
|
+
( select ) => {
|
|
121
|
+
const {
|
|
122
|
+
getBlockAttributes,
|
|
123
|
+
getSelectedBlockClientIds,
|
|
124
|
+
getBlockParentsByBlockName,
|
|
125
|
+
} = select( blockEditorStore );
|
|
126
|
+
const selectedClientIds = getSelectedBlockClientIds();
|
|
127
|
+
const _hasPatternOverrides = selectedClientIds.every(
|
|
128
|
+
( clientId ) =>
|
|
129
|
+
Object.values(
|
|
130
|
+
getBlockAttributes( clientId )?.metadata?.bindings ?? {}
|
|
131
|
+
).some(
|
|
132
|
+
( binding ) =>
|
|
133
|
+
binding?.source === PATTERN_OVERRIDES_BINDING_SOURCE
|
|
134
|
+
)
|
|
135
|
+
);
|
|
136
|
+
const _hasParentPattern = selectedClientIds.every(
|
|
137
|
+
( clientId ) =>
|
|
138
|
+
getBlockParentsByBlockName( clientId, 'core/block', true )
|
|
139
|
+
.length > 0
|
|
140
|
+
);
|
|
141
|
+
return {
|
|
142
|
+
clientIds: selectedClientIds,
|
|
143
|
+
hasPatternOverrides: _hasPatternOverrides,
|
|
144
|
+
hasParentPattern: _hasParentPattern,
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
[]
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
return hasPatternOverrides && hasParentPattern ? (
|
|
151
|
+
<BlockControls group="parent">
|
|
152
|
+
<PatternOverridesToolbarIndicator clientIds={ clientIds } />
|
|
153
|
+
</BlockControls>
|
|
154
|
+
) : null;
|
|
155
|
+
}
|
|
@@ -44,3 +44,16 @@
|
|
|
44
44
|
justify-content: center;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
|
|
48
|
+
.patterns-pattern-overrides-toolbar-indicator__popover .components-popover__content {
|
|
49
|
+
min-width: 260px;
|
|
50
|
+
padding: $grid-unit-20;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.patterns-pattern-overrides-toolbar-indicator .patterns-pattern-overrides-toolbar-indicator-icon.has-colors svg {
|
|
54
|
+
fill: var(--wp-block-synced-color);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.editor-collapsible-block-toolbar .patterns-pattern-overrides-toolbar-indicator {
|
|
58
|
+
height: 32px;
|
|
59
|
+
}
|
package/src/private-apis.js
CHANGED
|
@@ -17,6 +17,7 @@ import PatternsMenuItems from './components';
|
|
|
17
17
|
import RenamePatternCategoryModal from './components/rename-pattern-category-modal';
|
|
18
18
|
import PatternOverridesControls from './components/pattern-overrides-controls';
|
|
19
19
|
import ResetOverridesControl from './components/reset-overrides-control';
|
|
20
|
+
import PatternOverridesBlockControls from './components/pattern-overrides-block-controls';
|
|
20
21
|
import { useAddPatternCategory } from './private-hooks';
|
|
21
22
|
import {
|
|
22
23
|
PATTERN_TYPES,
|
|
@@ -41,6 +42,7 @@ lock( privateApis, {
|
|
|
41
42
|
RenamePatternCategoryModal,
|
|
42
43
|
PatternOverridesControls,
|
|
43
44
|
ResetOverridesControl,
|
|
45
|
+
PatternOverridesBlockControls,
|
|
44
46
|
useAddPatternCategory,
|
|
45
47
|
PATTERN_TYPES,
|
|
46
48
|
PATTERN_DEFAULT_CATEGORY,
|