@wordpress/components 28.8.1 → 28.8.3
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 +9 -0
- package/build/guide/index.js +1 -0
- package/build/guide/index.js.map +1 -1
- package/build/navigator/navigator-provider/component.js +3 -4
- package/build/navigator/navigator-provider/component.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control-option-base/styles.js +9 -9
- package/build/toggle-group-control/toggle-group-control-option-base/styles.js.map +1 -1
- package/build/tools-panel/tools-panel/hook.js +183 -109
- package/build/tools-panel/tools-panel/hook.js.map +1 -1
- package/build/utils/config-values.js +1 -12
- package/build/utils/config-values.js.map +1 -1
- package/build-module/guide/index.js +1 -0
- package/build-module/guide/index.js.map +1 -1
- package/build-module/navigator/navigator-provider/component.js +3 -4
- package/build-module/navigator/navigator-provider/component.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control-option-base/styles.js +9 -9
- package/build-module/toggle-group-control/toggle-group-control-option-base/styles.js.map +1 -1
- package/build-module/tools-panel/tools-panel/hook.js +184 -110
- package/build-module/tools-panel/tools-panel/hook.js.map +1 -1
- package/build-module/utils/config-values.js +1 -12
- package/build-module/utils/config-values.js.map +1 -1
- package/build-types/guide/index.d.ts.map +1 -1
- package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel/hook.d.ts +2 -2
- package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
- package/build-types/utils/config-values.d.ts +0 -10
- package/package.json +12 -12
- package/src/guide/index.tsx +1 -0
- package/src/navigator/navigator-provider/component.tsx +3 -2
- package/src/toggle-group-control/toggle-group-control-option-base/styles.ts +1 -1
- package/src/tools-panel/tools-panel/hook.ts +221 -163
- package/src/utils/config-values.js +1 -15
- package/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/components",
|
|
3
|
-
"version": "28.8.
|
|
3
|
+
"version": "28.8.3",
|
|
4
4
|
"description": "UI components for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -43,22 +43,22 @@
|
|
|
43
43
|
"@types/gradient-parser": "0.1.3",
|
|
44
44
|
"@types/highlight-words-core": "1.2.1",
|
|
45
45
|
"@use-gesture/react": "^10.3.1",
|
|
46
|
-
"@wordpress/a11y": "^4.8.
|
|
47
|
-
"@wordpress/compose": "^7.8.
|
|
48
|
-
"@wordpress/date": "^5.8.
|
|
49
|
-
"@wordpress/deprecated": "^4.8.
|
|
50
|
-
"@wordpress/dom": "^4.8.
|
|
46
|
+
"@wordpress/a11y": "^4.8.2",
|
|
47
|
+
"@wordpress/compose": "^7.8.3",
|
|
48
|
+
"@wordpress/date": "^5.8.2",
|
|
49
|
+
"@wordpress/deprecated": "^4.8.2",
|
|
50
|
+
"@wordpress/dom": "^4.8.2",
|
|
51
51
|
"@wordpress/element": "^6.8.1",
|
|
52
52
|
"@wordpress/escape-html": "^3.8.1",
|
|
53
|
-
"@wordpress/hooks": "^4.8.
|
|
53
|
+
"@wordpress/hooks": "^4.8.2",
|
|
54
54
|
"@wordpress/html-entities": "^4.8.1",
|
|
55
|
-
"@wordpress/i18n": "^5.8.
|
|
56
|
-
"@wordpress/icons": "^10.8.
|
|
55
|
+
"@wordpress/i18n": "^5.8.2",
|
|
56
|
+
"@wordpress/icons": "^10.8.2",
|
|
57
57
|
"@wordpress/is-shallow-equal": "^5.8.1",
|
|
58
|
-
"@wordpress/keycodes": "^4.8.
|
|
58
|
+
"@wordpress/keycodes": "^4.8.2",
|
|
59
59
|
"@wordpress/primitives": "^4.8.1",
|
|
60
60
|
"@wordpress/private-apis": "^1.8.1",
|
|
61
|
-
"@wordpress/rich-text": "^7.8.
|
|
61
|
+
"@wordpress/rich-text": "^7.8.3",
|
|
62
62
|
"@wordpress/warning": "^3.8.1",
|
|
63
63
|
"change-case": "^4.1.2",
|
|
64
64
|
"clsx": "^2.1.1",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"publishConfig": {
|
|
85
85
|
"access": "public"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "6187079697e13c3292eb098d6338523a6676c6e8"
|
|
88
88
|
}
|
package/src/guide/index.tsx
CHANGED
|
@@ -66,7 +66,7 @@ function goTo(
|
|
|
66
66
|
options: NavigateOptions = {}
|
|
67
67
|
) {
|
|
68
68
|
const { focusSelectors } = state;
|
|
69
|
-
const currentLocation = { ...state.currentLocation
|
|
69
|
+
const currentLocation = { ...state.currentLocation };
|
|
70
70
|
|
|
71
71
|
const {
|
|
72
72
|
// Default assignments
|
|
@@ -114,6 +114,7 @@ function goTo(
|
|
|
114
114
|
return {
|
|
115
115
|
currentLocation: {
|
|
116
116
|
...restOptions,
|
|
117
|
+
isInitial: false,
|
|
117
118
|
path,
|
|
118
119
|
isBack,
|
|
119
120
|
hasRestoredFocus: false,
|
|
@@ -129,7 +130,7 @@ function goToParent(
|
|
|
129
130
|
options: NavigateToParentOptions = {}
|
|
130
131
|
) {
|
|
131
132
|
const { screens, focusSelectors } = state;
|
|
132
|
-
const currentLocation = { ...state.currentLocation
|
|
133
|
+
const currentLocation = { ...state.currentLocation };
|
|
133
134
|
const currentPath = currentLocation.path;
|
|
134
135
|
if ( currentPath === undefined ) {
|
|
135
136
|
return { currentLocation, focusSelectors };
|
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
useCallback,
|
|
6
6
|
useEffect,
|
|
7
7
|
useMemo,
|
|
8
|
+
useReducer,
|
|
8
9
|
useRef,
|
|
9
|
-
useState,
|
|
10
10
|
} from '@wordpress/element';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -27,14 +27,40 @@ import type {
|
|
|
27
27
|
|
|
28
28
|
const DEFAULT_COLUMNS = 2;
|
|
29
29
|
|
|
30
|
+
type PanelItemsState = {
|
|
31
|
+
panelItems: ToolsPanelItem[];
|
|
32
|
+
menuItemOrder: string[];
|
|
33
|
+
menuItems: ToolsPanelMenuItems;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type PanelItemsAction =
|
|
37
|
+
| { type: 'REGISTER_PANEL'; item: ToolsPanelItem }
|
|
38
|
+
| { type: 'UNREGISTER_PANEL'; label: string }
|
|
39
|
+
| {
|
|
40
|
+
type: 'UPDATE_VALUE';
|
|
41
|
+
group: ToolsPanelMenuItemKey;
|
|
42
|
+
label: string;
|
|
43
|
+
value: boolean;
|
|
44
|
+
}
|
|
45
|
+
| { type: 'TOGGLE_VALUE'; label: string }
|
|
46
|
+
| { type: 'RESET_ALL' };
|
|
47
|
+
|
|
48
|
+
function emptyMenuItems(): ToolsPanelMenuItems {
|
|
49
|
+
return { default: {}, optional: {} };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function emptyState(): PanelItemsState {
|
|
53
|
+
return { panelItems: [], menuItemOrder: [], menuItems: emptyMenuItems() };
|
|
54
|
+
}
|
|
55
|
+
|
|
30
56
|
const generateMenuItems = ( {
|
|
31
57
|
panelItems,
|
|
32
58
|
shouldReset,
|
|
33
59
|
currentMenuItems,
|
|
34
60
|
menuItemOrder,
|
|
35
61
|
}: ToolsPanelMenuItemsConfig ) => {
|
|
36
|
-
const newMenuItems: ToolsPanelMenuItems =
|
|
37
|
-
const menuItems: ToolsPanelMenuItems =
|
|
62
|
+
const newMenuItems: ToolsPanelMenuItems = emptyMenuItems();
|
|
63
|
+
const menuItems: ToolsPanelMenuItems = emptyMenuItems();
|
|
38
64
|
|
|
39
65
|
panelItems.forEach( ( { hasValue, isShownByDefault, label } ) => {
|
|
40
66
|
const group = isShownByDefault ? 'default' : 'optional';
|
|
@@ -75,9 +101,149 @@ const generateMenuItems = ( {
|
|
|
75
101
|
return menuItems;
|
|
76
102
|
};
|
|
77
103
|
|
|
104
|
+
function panelItemsReducer(
|
|
105
|
+
panelItems: ToolsPanelItem[],
|
|
106
|
+
action: PanelItemsAction
|
|
107
|
+
) {
|
|
108
|
+
switch ( action.type ) {
|
|
109
|
+
case 'REGISTER_PANEL': {
|
|
110
|
+
const newItems = [ ...panelItems ];
|
|
111
|
+
// If an item with this label has already been registered, remove it
|
|
112
|
+
// first. This can happen when an item is moved between the default
|
|
113
|
+
// and optional groups.
|
|
114
|
+
const existingIndex = newItems.findIndex(
|
|
115
|
+
( oldItem ) => oldItem.label === action.item.label
|
|
116
|
+
);
|
|
117
|
+
if ( existingIndex !== -1 ) {
|
|
118
|
+
newItems.splice( existingIndex, 1 );
|
|
119
|
+
}
|
|
120
|
+
newItems.push( action.item );
|
|
121
|
+
return newItems;
|
|
122
|
+
}
|
|
123
|
+
case 'UNREGISTER_PANEL': {
|
|
124
|
+
const index = panelItems.findIndex(
|
|
125
|
+
( item ) => item.label === action.label
|
|
126
|
+
);
|
|
127
|
+
if ( index !== -1 ) {
|
|
128
|
+
const newItems = [ ...panelItems ];
|
|
129
|
+
newItems.splice( index, 1 );
|
|
130
|
+
return newItems;
|
|
131
|
+
}
|
|
132
|
+
return panelItems;
|
|
133
|
+
}
|
|
134
|
+
default:
|
|
135
|
+
return panelItems;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function menuItemOrderReducer(
|
|
140
|
+
menuItemOrder: string[],
|
|
141
|
+
action: PanelItemsAction
|
|
142
|
+
) {
|
|
143
|
+
switch ( action.type ) {
|
|
144
|
+
case 'REGISTER_PANEL': {
|
|
145
|
+
// Track the initial order of item registration. This is used for
|
|
146
|
+
// maintaining menu item order later.
|
|
147
|
+
if ( menuItemOrder.includes( action.item.label ) ) {
|
|
148
|
+
return menuItemOrder;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return [ ...menuItemOrder, action.item.label ];
|
|
152
|
+
}
|
|
153
|
+
default:
|
|
154
|
+
return menuItemOrder;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function menuItemsReducer( state: PanelItemsState, action: PanelItemsAction ) {
|
|
159
|
+
switch ( action.type ) {
|
|
160
|
+
case 'REGISTER_PANEL':
|
|
161
|
+
case 'UNREGISTER_PANEL':
|
|
162
|
+
// generate new menu items from original `menuItems` and updated `panelItems` and `menuItemOrder`
|
|
163
|
+
return generateMenuItems( {
|
|
164
|
+
currentMenuItems: state.menuItems,
|
|
165
|
+
panelItems: state.panelItems,
|
|
166
|
+
menuItemOrder: state.menuItemOrder,
|
|
167
|
+
shouldReset: false,
|
|
168
|
+
} );
|
|
169
|
+
case 'RESET_ALL':
|
|
170
|
+
return generateMenuItems( {
|
|
171
|
+
panelItems: state.panelItems,
|
|
172
|
+
menuItemOrder: state.menuItemOrder,
|
|
173
|
+
shouldReset: true,
|
|
174
|
+
} );
|
|
175
|
+
case 'UPDATE_VALUE': {
|
|
176
|
+
const oldValue = state.menuItems[ action.group ][ action.label ];
|
|
177
|
+
if ( action.value === oldValue ) {
|
|
178
|
+
return state.menuItems;
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
...state.menuItems,
|
|
182
|
+
[ action.group ]: {
|
|
183
|
+
...state.menuItems[ action.group ],
|
|
184
|
+
[ action.label ]: action.value,
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
case 'TOGGLE_VALUE': {
|
|
189
|
+
const currentItem = state.panelItems.find(
|
|
190
|
+
( item ) => item.label === action.label
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
if ( ! currentItem ) {
|
|
194
|
+
return state.menuItems;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const menuGroup = currentItem.isShownByDefault
|
|
198
|
+
? 'default'
|
|
199
|
+
: 'optional';
|
|
200
|
+
|
|
201
|
+
const newMenuItems = {
|
|
202
|
+
...state.menuItems,
|
|
203
|
+
[ menuGroup ]: {
|
|
204
|
+
...state.menuItems[ menuGroup ],
|
|
205
|
+
[ action.label ]:
|
|
206
|
+
! state.menuItems[ menuGroup ][ action.label ],
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
return newMenuItems;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
default:
|
|
213
|
+
return state.menuItems;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function panelReducer( state: PanelItemsState, action: PanelItemsAction ) {
|
|
218
|
+
const panelItems = panelItemsReducer( state.panelItems, action );
|
|
219
|
+
const menuItemOrder = menuItemOrderReducer( state.menuItemOrder, action );
|
|
220
|
+
// `menuItemsReducer` is a bit unusual because it generates new state from original `menuItems`
|
|
221
|
+
// and the updated `panelItems` and `menuItemOrder`.
|
|
222
|
+
const menuItems = menuItemsReducer(
|
|
223
|
+
{ panelItems, menuItemOrder, menuItems: state.menuItems },
|
|
224
|
+
action
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
return { panelItems, menuItemOrder, menuItems };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function resetAllFiltersReducer(
|
|
231
|
+
filters: ResetAllFilter[],
|
|
232
|
+
action: { type: 'REGISTER' | 'UNREGISTER'; filter: ResetAllFilter }
|
|
233
|
+
) {
|
|
234
|
+
switch ( action.type ) {
|
|
235
|
+
case 'REGISTER':
|
|
236
|
+
return [ ...filters, action.filter ];
|
|
237
|
+
case 'UNREGISTER':
|
|
238
|
+
return filters.filter( ( f ) => f !== action.filter );
|
|
239
|
+
default:
|
|
240
|
+
return filters;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
78
244
|
const isMenuItemTypeEmpty = (
|
|
79
|
-
obj
|
|
80
|
-
) =>
|
|
245
|
+
obj: ToolsPanelMenuItems[ ToolsPanelMenuItemKey ]
|
|
246
|
+
) => Object.keys( obj ).length === 0;
|
|
81
247
|
|
|
82
248
|
export function useToolsPanel(
|
|
83
249
|
props: WordPressComponentProps< ToolsPanelProps, 'div' >
|
|
@@ -108,103 +274,43 @@ export function useToolsPanel(
|
|
|
108
274
|
}, [ wasResetting ] );
|
|
109
275
|
|
|
110
276
|
// Allow panel items to register themselves.
|
|
111
|
-
const [ panelItems,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const registerPanelItem = useCallback(
|
|
118
|
-
( item: ToolsPanelItem ) => {
|
|
119
|
-
// Add item to panel items.
|
|
120
|
-
setPanelItems( ( items ) => {
|
|
121
|
-
const newItems = [ ...items ];
|
|
122
|
-
// If an item with this label has already been registered, remove it
|
|
123
|
-
// first. This can happen when an item is moved between the default
|
|
124
|
-
// and optional groups.
|
|
125
|
-
const existingIndex = newItems.findIndex(
|
|
126
|
-
( oldItem ) => oldItem.label === item.label
|
|
127
|
-
);
|
|
128
|
-
if ( existingIndex !== -1 ) {
|
|
129
|
-
newItems.splice( existingIndex, 1 );
|
|
130
|
-
}
|
|
131
|
-
return [ ...newItems, item ];
|
|
132
|
-
} );
|
|
133
|
-
|
|
134
|
-
// Track the initial order of item registration. This is used for
|
|
135
|
-
// maintaining menu item order later.
|
|
136
|
-
setMenuItemOrder( ( items ) => {
|
|
137
|
-
if ( items.includes( item.label ) ) {
|
|
138
|
-
return items;
|
|
139
|
-
}
|
|
277
|
+
const [ { panelItems, menuItems }, panelDispatch ] = useReducer(
|
|
278
|
+
panelReducer,
|
|
279
|
+
undefined,
|
|
280
|
+
emptyState
|
|
281
|
+
);
|
|
140
282
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
[ setPanelItems, setMenuItemOrder ]
|
|
283
|
+
const [ resetAllFilters, dispatchResetAllFilters ] = useReducer(
|
|
284
|
+
resetAllFiltersReducer,
|
|
285
|
+
[]
|
|
145
286
|
);
|
|
146
287
|
|
|
288
|
+
const registerPanelItem = useCallback( ( item: ToolsPanelItem ) => {
|
|
289
|
+
// Add item to panel items.
|
|
290
|
+
panelDispatch( { type: 'REGISTER_PANEL', item } );
|
|
291
|
+
}, [] );
|
|
292
|
+
|
|
147
293
|
// Panels need to deregister on unmount to avoid orphans in menu state.
|
|
148
294
|
// This is an issue when panel items are being injected via SlotFills.
|
|
149
|
-
const deregisterPanelItem = useCallback(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if ( index !== -1 ) {
|
|
161
|
-
newItems.splice( index, 1 );
|
|
162
|
-
}
|
|
163
|
-
return newItems;
|
|
164
|
-
} );
|
|
165
|
-
},
|
|
166
|
-
[ setPanelItems ]
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
const registerResetAllFilter = useCallback(
|
|
170
|
-
( newFilter: ResetAllFilter ) => {
|
|
171
|
-
setResetAllFilters( ( filters ) => {
|
|
172
|
-
return [ ...filters, newFilter ];
|
|
173
|
-
} );
|
|
174
|
-
},
|
|
175
|
-
[ setResetAllFilters ]
|
|
176
|
-
);
|
|
295
|
+
const deregisterPanelItem = useCallback( ( label: string ) => {
|
|
296
|
+
// When switching selections between components injecting matching
|
|
297
|
+
// controls, e.g. both panels have a "padding" control, the
|
|
298
|
+
// deregistration of the first panel doesn't occur until after the
|
|
299
|
+
// registration of the next.
|
|
300
|
+
panelDispatch( { type: 'UNREGISTER_PANEL', label } );
|
|
301
|
+
}, [] );
|
|
302
|
+
|
|
303
|
+
const registerResetAllFilter = useCallback( ( filter: ResetAllFilter ) => {
|
|
304
|
+
dispatchResetAllFilters( { type: 'REGISTER', filter } );
|
|
305
|
+
}, [] );
|
|
177
306
|
|
|
178
307
|
const deregisterResetAllFilter = useCallback(
|
|
179
|
-
(
|
|
180
|
-
|
|
181
|
-
return filters.filter(
|
|
182
|
-
( filter ) => filter !== filterToRemove
|
|
183
|
-
);
|
|
184
|
-
} );
|
|
308
|
+
( filter: ResetAllFilter ) => {
|
|
309
|
+
dispatchResetAllFilters( { type: 'UNREGISTER', filter } );
|
|
185
310
|
},
|
|
186
|
-
[
|
|
311
|
+
[]
|
|
187
312
|
);
|
|
188
313
|
|
|
189
|
-
// Manage and share display state of menu items representing child controls.
|
|
190
|
-
const [ menuItems, setMenuItems ] = useState< ToolsPanelMenuItems >( {
|
|
191
|
-
default: {},
|
|
192
|
-
optional: {},
|
|
193
|
-
} );
|
|
194
|
-
|
|
195
|
-
// Setup menuItems state as panel items register themselves.
|
|
196
|
-
useEffect( () => {
|
|
197
|
-
setMenuItems( ( prevState ) => {
|
|
198
|
-
const items = generateMenuItems( {
|
|
199
|
-
panelItems,
|
|
200
|
-
shouldReset: false,
|
|
201
|
-
currentMenuItems: prevState,
|
|
202
|
-
menuItemOrder,
|
|
203
|
-
} );
|
|
204
|
-
return items;
|
|
205
|
-
} );
|
|
206
|
-
}, [ panelItems, setMenuItems, menuItemOrder ] );
|
|
207
|
-
|
|
208
314
|
// Updates the status of the panel’s menu items. For default items the
|
|
209
315
|
// value represents whether it differs from the default and for optional
|
|
210
316
|
// items whether the item is shown.
|
|
@@ -214,38 +320,24 @@ export function useToolsPanel(
|
|
|
214
320
|
label: string,
|
|
215
321
|
group: ToolsPanelMenuItemKey = 'default'
|
|
216
322
|
) => {
|
|
217
|
-
|
|
218
|
-
const newState = {
|
|
219
|
-
...items,
|
|
220
|
-
[ group ]: {
|
|
221
|
-
...items[ group ],
|
|
222
|
-
[ label ]: value,
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
return newState;
|
|
226
|
-
} );
|
|
323
|
+
panelDispatch( { type: 'UPDATE_VALUE', group, label, value } );
|
|
227
324
|
},
|
|
228
|
-
[
|
|
325
|
+
[]
|
|
229
326
|
);
|
|
230
327
|
|
|
231
328
|
// Whether all optional menu items are hidden or not must be tracked
|
|
232
329
|
// in order to later determine if the panel display is empty and handle
|
|
233
330
|
// conditional display of a plus icon to indicate the presence of further
|
|
234
331
|
// menu items.
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
)
|
|
243
|
-
|
|
244
|
-
menuItems.optional
|
|
245
|
-
).some( ( [ , isSelected ] ) => isSelected );
|
|
246
|
-
setAreAllOptionalControlsHidden( allControlsHidden );
|
|
247
|
-
}
|
|
248
|
-
}, [ menuItems, setAreAllOptionalControlsHidden ] );
|
|
332
|
+
const areAllOptionalControlsHidden = useMemo( () => {
|
|
333
|
+
return (
|
|
334
|
+
isMenuItemTypeEmpty( menuItems.default ) &&
|
|
335
|
+
! isMenuItemTypeEmpty( menuItems.optional ) &&
|
|
336
|
+
Object.values( menuItems.optional ).every(
|
|
337
|
+
( isSelected ) => ! isSelected
|
|
338
|
+
)
|
|
339
|
+
);
|
|
340
|
+
}, [ menuItems ] );
|
|
249
341
|
|
|
250
342
|
const cx = useCx();
|
|
251
343
|
const classes = useMemo( () => {
|
|
@@ -253,9 +345,7 @@ export function useToolsPanel(
|
|
|
253
345
|
hasInnerWrapper &&
|
|
254
346
|
styles.ToolsPanelWithInnerWrapper( DEFAULT_COLUMNS );
|
|
255
347
|
const emptyStyle =
|
|
256
|
-
|
|
257
|
-
areAllOptionalControlsHidden &&
|
|
258
|
-
styles.ToolsPanelHiddenInnerWrapper;
|
|
348
|
+
areAllOptionalControlsHidden && styles.ToolsPanelHiddenInnerWrapper;
|
|
259
349
|
|
|
260
350
|
return cx(
|
|
261
351
|
styles.ToolsPanel( DEFAULT_COLUMNS ),
|
|
@@ -263,42 +353,13 @@ export function useToolsPanel(
|
|
|
263
353
|
emptyStyle,
|
|
264
354
|
className
|
|
265
355
|
);
|
|
266
|
-
}, [
|
|
267
|
-
areAllOptionalControlsHidden,
|
|
268
|
-
className,
|
|
269
|
-
cx,
|
|
270
|
-
hasInnerWrapper,
|
|
271
|
-
menuItems,
|
|
272
|
-
] );
|
|
356
|
+
}, [ areAllOptionalControlsHidden, className, cx, hasInnerWrapper ] );
|
|
273
357
|
|
|
274
358
|
// Toggle the checked state of a menu item which is then used to determine
|
|
275
359
|
// display of the item within the panel.
|
|
276
|
-
const toggleItem = useCallback(
|
|
277
|
-
(
|
|
278
|
-
|
|
279
|
-
( item ) => item.label === label
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
if ( ! currentItem ) {
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const menuGroup = currentItem.isShownByDefault
|
|
287
|
-
? 'default'
|
|
288
|
-
: 'optional';
|
|
289
|
-
|
|
290
|
-
const newMenuItems = {
|
|
291
|
-
...menuItems,
|
|
292
|
-
[ menuGroup ]: {
|
|
293
|
-
...menuItems[ menuGroup ],
|
|
294
|
-
[ label ]: ! menuItems[ menuGroup ][ label ],
|
|
295
|
-
},
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
setMenuItems( newMenuItems );
|
|
299
|
-
},
|
|
300
|
-
[ menuItems, panelItems, setMenuItems ]
|
|
301
|
-
);
|
|
360
|
+
const toggleItem = useCallback( ( label: string ) => {
|
|
361
|
+
panelDispatch( { type: 'TOGGLE_VALUE', label } );
|
|
362
|
+
}, [] );
|
|
302
363
|
|
|
303
364
|
// Resets display of children and executes resetAll callback if available.
|
|
304
365
|
const resetAllItems = useCallback( () => {
|
|
@@ -308,20 +369,15 @@ export function useToolsPanel(
|
|
|
308
369
|
}
|
|
309
370
|
|
|
310
371
|
// Turn off display of all non-default items.
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
menuItemOrder,
|
|
314
|
-
shouldReset: true,
|
|
315
|
-
} );
|
|
316
|
-
setMenuItems( resetMenuItems );
|
|
317
|
-
}, [ panelItems, resetAllFilters, resetAll, setMenuItems, menuItemOrder ] );
|
|
372
|
+
panelDispatch( { type: 'RESET_ALL' } );
|
|
373
|
+
}, [ resetAllFilters, resetAll ] );
|
|
318
374
|
|
|
319
375
|
// Assist ItemGroup styling when there are potentially hidden placeholder
|
|
320
376
|
// items by identifying first & last items that are toggled on for display.
|
|
321
377
|
const getFirstVisibleItemLabel = ( items: ToolsPanelItem[] ) => {
|
|
322
378
|
const optionalItems = menuItems.optional || {};
|
|
323
379
|
const firstItem = items.find(
|
|
324
|
-
( item ) => item.isShownByDefault ||
|
|
380
|
+
( item ) => item.isShownByDefault || optionalItems[ item.label ]
|
|
325
381
|
);
|
|
326
382
|
|
|
327
383
|
return firstItem?.label;
|
|
@@ -332,6 +388,8 @@ export function useToolsPanel(
|
|
|
332
388
|
[ ...panelItems ].reverse()
|
|
333
389
|
);
|
|
334
390
|
|
|
391
|
+
const hasMenuItems = panelItems.length > 0;
|
|
392
|
+
|
|
335
393
|
const panelContext = useMemo(
|
|
336
394
|
() => ( {
|
|
337
395
|
areAllOptionalControlsHidden,
|
|
@@ -339,7 +397,7 @@ export function useToolsPanel(
|
|
|
339
397
|
deregisterResetAllFilter,
|
|
340
398
|
firstDisplayedItem,
|
|
341
399
|
flagItemCustomization,
|
|
342
|
-
hasMenuItems
|
|
400
|
+
hasMenuItems,
|
|
343
401
|
isResetting: isResettingRef.current,
|
|
344
402
|
lastDisplayedItem,
|
|
345
403
|
menuItems,
|
|
@@ -359,7 +417,7 @@ export function useToolsPanel(
|
|
|
359
417
|
lastDisplayedItem,
|
|
360
418
|
menuItems,
|
|
361
419
|
panelId,
|
|
362
|
-
|
|
420
|
+
hasMenuItems,
|
|
363
421
|
registerResetAllFilter,
|
|
364
422
|
registerPanelItem,
|
|
365
423
|
shouldRenderPlaceholderItems,
|
|
@@ -7,18 +7,13 @@ import { COLORS } from './colors-values';
|
|
|
7
7
|
const CONTROL_HEIGHT = '36px';
|
|
8
8
|
|
|
9
9
|
const CONTROL_PROPS = {
|
|
10
|
-
controlSurfaceColor: COLORS.white,
|
|
11
|
-
controlTextActiveColor: COLORS.theme.accent,
|
|
12
|
-
|
|
13
10
|
// These values should be shared with TextControl.
|
|
14
11
|
controlPaddingX: 12,
|
|
15
12
|
controlPaddingXSmall: 8,
|
|
16
13
|
controlPaddingXLarge: 12 * 1.3334, // TODO: Deprecate
|
|
17
14
|
|
|
18
15
|
controlBackgroundColor: COLORS.white,
|
|
19
|
-
controlBoxShadow: 'transparent',
|
|
20
16
|
controlBoxShadowFocus: `0 0 0 0.5px ${ COLORS.theme.accent }`,
|
|
21
|
-
controlDestructiveBorderColor: COLORS.alert.red,
|
|
22
17
|
controlHeight: CONTROL_HEIGHT,
|
|
23
18
|
controlHeightXSmall: `calc( ${ CONTROL_HEIGHT } * 0.6 )`,
|
|
24
19
|
controlHeightSmall: `calc( ${ CONTROL_HEIGHT } * 0.8 )`,
|
|
@@ -26,18 +21,9 @@ const CONTROL_PROPS = {
|
|
|
26
21
|
controlHeightXLarge: `calc( ${ CONTROL_HEIGHT } * 1.4 )`,
|
|
27
22
|
};
|
|
28
23
|
|
|
29
|
-
const TOGGLE_GROUP_CONTROL_PROPS = {
|
|
30
|
-
toggleGroupControlBackgroundColor: CONTROL_PROPS.controlBackgroundColor,
|
|
31
|
-
toggleGroupControlBorderColor: COLORS.ui.border,
|
|
32
|
-
toggleGroupControlBackdropBackgroundColor:
|
|
33
|
-
CONTROL_PROPS.controlSurfaceColor,
|
|
34
|
-
toggleGroupControlBackdropBorderColor: COLORS.ui.border,
|
|
35
|
-
toggleGroupControlButtonColorActive: CONTROL_PROPS.controlBackgroundColor,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
24
|
// Using Object.assign to avoid creating circular references when emitting
|
|
39
25
|
// TypeScript type declarations.
|
|
40
|
-
export default Object.assign( {}, CONTROL_PROPS,
|
|
26
|
+
export default Object.assign( {}, CONTROL_PROPS, {
|
|
41
27
|
colorDivider: 'rgba(0, 0, 0, 0.1)',
|
|
42
28
|
colorScrollbarThumb: 'rgba(0, 0, 0, 0.2)',
|
|
43
29
|
colorScrollbarThumbHover: 'rgba(0, 0, 0, 0.5)',
|