@wordpress/commands 1.32.0 → 1.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/README.md +2 -2
- package/build/components/command-menu.js +261 -246
- package/build/components/command-menu.js.map +7 -1
- package/build/hooks/use-command-context.js +31 -35
- package/build/hooks/use-command-context.js.map +7 -1
- package/build/hooks/use-command-loader.js +35 -92
- package/build/hooks/use-command-loader.js.map +7 -1
- package/build/hooks/use-command.js +53 -90
- package/build/hooks/use-command.js.map +7 -1
- package/build/index.js +49 -45
- 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 +41 -19
- package/build/private-apis.js.map +7 -1
- package/build/store/actions.js +42 -92
- package/build/store/actions.js.map +7 -1
- package/build/store/index.js +47 -44
- package/build/store/index.js.map +7 -1
- package/build/store/private-actions.js +27 -14
- package/build/store/private-actions.js.map +7 -1
- package/build/store/reducer.js +39 -70
- package/build/store/reducer.js.map +7 -1
- package/build/store/selectors.js +47 -54
- package/build/store/selectors.js.map +7 -1
- package/build-module/components/command-menu.js +232 -229
- package/build-module/components/command-menu.js.map +7 -1
- package/build-module/hooks/use-command-context.js +11 -28
- package/build-module/hooks/use-command-context.js.map +7 -1
- package/build-module/hooks/use-command-loader.js +17 -87
- package/build-module/hooks/use-command-loader.js.map +7 -1
- package/build-module/hooks/use-command.js +25 -79
- package/build-module/hooks/use-command.js.map +7 -1
- package/build-module/index.js +14 -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 +7 -11
- package/build-module/private-apis.js.map +7 -1
- package/build-module/store/actions.js +21 -88
- package/build-module/store/actions.js.map +7 -1
- package/build-module/store/index.js +12 -32
- package/build-module/store/index.js.map +7 -1
- package/build-module/store/private-actions.js +6 -10
- package/build-module/store/private-actions.js.map +7 -1
- package/build-module/store/reducer.js +20 -64
- package/build-module/store/reducer.js.map +7 -1
- package/build-module/store/selectors.js +24 -49
- package/build-module/store/selectors.js.map +7 -1
- package/build-style/style-rtl.css +7 -138
- package/build-style/style.css +7 -138
- package/package.json +18 -10
- package/src/components/command-menu.js +4 -1
- package/src/components/style.scss +10 -0
- package/src/hooks/use-command.js +2 -2
- package/src/style.scss +2 -1
|
@@ -1,281 +1,284 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import { __ } from
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
hook
|
|
27
|
-
setLoader,
|
|
28
|
-
close
|
|
29
|
-
}) {
|
|
30
|
-
var _hook;
|
|
31
|
-
const {
|
|
32
|
-
isLoading,
|
|
33
|
-
commands = []
|
|
34
|
-
} = (_hook = hook({
|
|
35
|
-
search
|
|
36
|
-
})) !== null && _hook !== void 0 ? _hook : {};
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Command, useCommandState } from "cmdk";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { useSelect, useDispatch } from "@wordpress/data";
|
|
5
|
+
import {
|
|
6
|
+
useState,
|
|
7
|
+
useEffect,
|
|
8
|
+
useRef,
|
|
9
|
+
useCallback,
|
|
10
|
+
useMemo
|
|
11
|
+
} from "@wordpress/element";
|
|
12
|
+
import { __ } from "@wordpress/i18n";
|
|
13
|
+
import {
|
|
14
|
+
Modal,
|
|
15
|
+
TextHighlight,
|
|
16
|
+
__experimentalHStack as HStack
|
|
17
|
+
} from "@wordpress/components";
|
|
18
|
+
import {
|
|
19
|
+
store as keyboardShortcutsStore,
|
|
20
|
+
useShortcut
|
|
21
|
+
} from "@wordpress/keyboard-shortcuts";
|
|
22
|
+
import { Icon, search as inputIcon } from "@wordpress/icons";
|
|
23
|
+
import { store as commandsStore } from "../store";
|
|
24
|
+
const inputLabel = __("Search commands and settings");
|
|
25
|
+
function CommandMenuLoader({ name, search, hook, setLoader, close }) {
|
|
26
|
+
const { isLoading, commands = [] } = hook({ search }) ?? {};
|
|
37
27
|
useEffect(() => {
|
|
38
28
|
setLoader(name, isLoading);
|
|
39
29
|
}, [setLoader, name, isLoading]);
|
|
40
30
|
if (!commands.length) {
|
|
41
31
|
return null;
|
|
42
32
|
}
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
children: /*#__PURE__*/_jsxs(HStack, {
|
|
33
|
+
return /* @__PURE__ */ jsx(Fragment, { children: commands.map((command) => /* @__PURE__ */ jsx(
|
|
34
|
+
Command.Item,
|
|
35
|
+
{
|
|
36
|
+
value: command.searchLabel ?? command.label,
|
|
37
|
+
keywords: command.keywords,
|
|
38
|
+
onSelect: () => command.callback({ close }),
|
|
39
|
+
id: command.name,
|
|
40
|
+
children: /* @__PURE__ */ jsxs(
|
|
41
|
+
HStack,
|
|
42
|
+
{
|
|
54
43
|
alignment: "left",
|
|
55
|
-
className: clsx(
|
|
56
|
-
|
|
44
|
+
className: clsx("commands-command-menu__item", {
|
|
45
|
+
"has-icon": command.icon
|
|
57
46
|
}),
|
|
58
|
-
children: [
|
|
59
|
-
icon: command.icon
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
47
|
+
children: [
|
|
48
|
+
command.icon && /* @__PURE__ */ jsx(Icon, { icon: command.icon }),
|
|
49
|
+
/* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(
|
|
50
|
+
TextHighlight,
|
|
51
|
+
{
|
|
52
|
+
text: command.label,
|
|
53
|
+
highlight: search
|
|
54
|
+
}
|
|
55
|
+
) })
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
},
|
|
60
|
+
command.name
|
|
61
|
+
)) });
|
|
70
62
|
}
|
|
71
|
-
|
|
72
|
-
hook,
|
|
73
|
-
search,
|
|
74
|
-
setLoader,
|
|
75
|
-
close
|
|
76
|
-
}) {
|
|
77
|
-
// The "hook" prop is actually a custom React hook
|
|
78
|
-
// so to avoid breaking the rules of hooks
|
|
79
|
-
// the CommandMenuLoaderWrapper component need to be
|
|
80
|
-
// remounted on each hook prop change
|
|
81
|
-
// We use the key state to make sure we do that properly.
|
|
63
|
+
function CommandMenuLoaderWrapper({ hook, search, setLoader, close }) {
|
|
82
64
|
const currentLoaderRef = useRef(hook);
|
|
83
65
|
const [key, setKey] = useState(0);
|
|
84
66
|
useEffect(() => {
|
|
85
67
|
if (currentLoaderRef.current !== hook) {
|
|
86
68
|
currentLoaderRef.current = hook;
|
|
87
|
-
setKey(prevKey => prevKey + 1);
|
|
69
|
+
setKey((prevKey) => prevKey + 1);
|
|
88
70
|
}
|
|
89
71
|
}, [hook]);
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
72
|
+
return /* @__PURE__ */ jsx(
|
|
73
|
+
CommandMenuLoader,
|
|
74
|
+
{
|
|
75
|
+
hook: currentLoaderRef.current,
|
|
76
|
+
search,
|
|
77
|
+
setLoader,
|
|
78
|
+
close
|
|
79
|
+
},
|
|
80
|
+
key
|
|
81
|
+
);
|
|
96
82
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
getCommands,
|
|
109
|
-
getCommandLoaders
|
|
110
|
-
} = select(commandsStore);
|
|
111
|
-
return {
|
|
112
|
-
commands: getCommands(isContextual),
|
|
113
|
-
loaders: getCommandLoaders(isContextual)
|
|
114
|
-
};
|
|
115
|
-
}, [isContextual]);
|
|
83
|
+
function CommandMenuGroup({ isContextual, search, setLoader, close }) {
|
|
84
|
+
const { commands, loaders } = useSelect(
|
|
85
|
+
(select) => {
|
|
86
|
+
const { getCommands, getCommandLoaders } = select(commandsStore);
|
|
87
|
+
return {
|
|
88
|
+
commands: getCommands(isContextual),
|
|
89
|
+
loaders: getCommandLoaders(isContextual)
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
[isContextual]
|
|
93
|
+
);
|
|
116
94
|
if (!commands.length && !loaders.length) {
|
|
117
95
|
return null;
|
|
118
96
|
}
|
|
119
|
-
return
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
value:
|
|
97
|
+
return /* @__PURE__ */ jsxs(Command.Group, { children: [
|
|
98
|
+
commands.map((command) => /* @__PURE__ */ jsx(
|
|
99
|
+
Command.Item,
|
|
100
|
+
{
|
|
101
|
+
value: command.searchLabel ?? command.label,
|
|
124
102
|
keywords: command.keywords,
|
|
125
|
-
onSelect: () => command.callback({
|
|
126
|
-
close
|
|
127
|
-
}),
|
|
103
|
+
onSelect: () => command.callback({ close }),
|
|
128
104
|
id: command.name,
|
|
129
|
-
children:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
105
|
+
children: /* @__PURE__ */ jsxs(
|
|
106
|
+
HStack,
|
|
107
|
+
{
|
|
108
|
+
alignment: "left",
|
|
109
|
+
className: clsx("commands-command-menu__item", {
|
|
110
|
+
"has-icon": command.icon
|
|
111
|
+
}),
|
|
112
|
+
children: [
|
|
113
|
+
command.icon && /* @__PURE__ */ jsx(Icon, { icon: command.icon }),
|
|
114
|
+
/* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(
|
|
115
|
+
TextHighlight,
|
|
116
|
+
{
|
|
117
|
+
text: command.label,
|
|
118
|
+
highlight: search
|
|
119
|
+
}
|
|
120
|
+
) })
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
},
|
|
125
|
+
command.name
|
|
126
|
+
)),
|
|
127
|
+
loaders.map((loader) => /* @__PURE__ */ jsx(
|
|
128
|
+
CommandMenuLoaderWrapper,
|
|
129
|
+
{
|
|
130
|
+
hook: loader.hook,
|
|
131
|
+
search,
|
|
132
|
+
setLoader,
|
|
133
|
+
close
|
|
134
|
+
},
|
|
135
|
+
loader.name
|
|
136
|
+
))
|
|
137
|
+
] });
|
|
151
138
|
}
|
|
152
|
-
function CommandInput({
|
|
153
|
-
isOpen,
|
|
154
|
-
search,
|
|
155
|
-
setSearch
|
|
156
|
-
}) {
|
|
139
|
+
function CommandInput({ isOpen, search, setSearch }) {
|
|
157
140
|
const commandMenuInput = useRef();
|
|
158
|
-
const _value = useCommandState(state => state.value);
|
|
141
|
+
const _value = useCommandState((state) => state.value);
|
|
159
142
|
const selectedItemId = useMemo(() => {
|
|
160
|
-
const item = document.querySelector(
|
|
161
|
-
|
|
143
|
+
const item = document.querySelector(
|
|
144
|
+
`[cmdk-item=""][data-value="${_value}"]`
|
|
145
|
+
);
|
|
146
|
+
return item?.getAttribute("id");
|
|
162
147
|
}, [_value]);
|
|
163
148
|
useEffect(() => {
|
|
164
|
-
// Focus the command palette input when mounting the modal.
|
|
165
149
|
if (isOpen) {
|
|
166
150
|
commandMenuInput.current.focus();
|
|
167
151
|
}
|
|
168
152
|
}, [isOpen]);
|
|
169
|
-
return
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
153
|
+
return /* @__PURE__ */ jsx(
|
|
154
|
+
Command.Input,
|
|
155
|
+
{
|
|
156
|
+
ref: commandMenuInput,
|
|
157
|
+
value: search,
|
|
158
|
+
onValueChange: setSearch,
|
|
159
|
+
placeholder: inputLabel,
|
|
160
|
+
"aria-activedescendant": selectedItemId,
|
|
161
|
+
icon: search
|
|
162
|
+
}
|
|
163
|
+
);
|
|
177
164
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
} = useDispatch(
|
|
186
|
-
const [search, setSearch] = useState('');
|
|
187
|
-
const isOpen = useSelect(select => select(commandsStore).isOpen(), []);
|
|
188
|
-
const {
|
|
189
|
-
open,
|
|
190
|
-
close
|
|
191
|
-
} = useDispatch(commandsStore);
|
|
165
|
+
function CommandMenu() {
|
|
166
|
+
const { registerShortcut } = useDispatch(keyboardShortcutsStore);
|
|
167
|
+
const [search, setSearch] = useState("");
|
|
168
|
+
const isOpen = useSelect(
|
|
169
|
+
(select) => select(commandsStore).isOpen(),
|
|
170
|
+
[]
|
|
171
|
+
);
|
|
172
|
+
const { open, close } = useDispatch(commandsStore);
|
|
192
173
|
const [loaders, setLoaders] = useState({});
|
|
193
174
|
useEffect(() => {
|
|
194
175
|
registerShortcut({
|
|
195
|
-
name:
|
|
196
|
-
category:
|
|
197
|
-
description: __(
|
|
176
|
+
name: "core/commands",
|
|
177
|
+
category: "global",
|
|
178
|
+
description: __("Open the command palette."),
|
|
198
179
|
keyCombination: {
|
|
199
|
-
modifier:
|
|
200
|
-
character:
|
|
180
|
+
modifier: "primary",
|
|
181
|
+
character: "k"
|
|
201
182
|
}
|
|
202
183
|
});
|
|
203
184
|
}, [registerShortcut]);
|
|
204
|
-
useShortcut(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
185
|
+
useShortcut(
|
|
186
|
+
"core/commands",
|
|
187
|
+
/** @type {import('react').KeyboardEventHandler} */
|
|
188
|
+
(event) => {
|
|
189
|
+
if (event.defaultPrevented) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
event.preventDefault();
|
|
193
|
+
if (isOpen) {
|
|
194
|
+
close();
|
|
195
|
+
} else {
|
|
196
|
+
open();
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
bindGlobal: true
|
|
215
201
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
202
|
+
);
|
|
203
|
+
const setLoader = useCallback(
|
|
204
|
+
(name, value) => setLoaders((current) => ({
|
|
205
|
+
...current,
|
|
206
|
+
[name]: value
|
|
207
|
+
})),
|
|
208
|
+
[]
|
|
209
|
+
);
|
|
223
210
|
const closeAndReset = () => {
|
|
224
|
-
setSearch(
|
|
211
|
+
setSearch("");
|
|
225
212
|
close();
|
|
226
213
|
};
|
|
227
214
|
if (!isOpen) {
|
|
228
215
|
return false;
|
|
229
216
|
}
|
|
230
|
-
const onKeyDown = event => {
|
|
217
|
+
const onKeyDown = (event) => {
|
|
231
218
|
if (
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
219
|
+
// Ignore keydowns from IMEs
|
|
220
|
+
event.nativeEvent.isComposing || // Workaround for Mac Safari where the final Enter/Backspace of an IME composition
|
|
221
|
+
// is `isComposing=false`, even though it's technically still part of the composition.
|
|
222
|
+
// These can only be detected by keyCode.
|
|
223
|
+
event.keyCode === 229
|
|
224
|
+
) {
|
|
238
225
|
event.preventDefault();
|
|
239
226
|
}
|
|
240
227
|
};
|
|
241
228
|
const isLoading = Object.values(loaders).some(Boolean);
|
|
242
|
-
return
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
children:
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
229
|
+
return /* @__PURE__ */ jsx(
|
|
230
|
+
Modal,
|
|
231
|
+
{
|
|
232
|
+
className: "commands-command-menu",
|
|
233
|
+
overlayClassName: "commands-command-menu__overlay",
|
|
234
|
+
onRequestClose: closeAndReset,
|
|
235
|
+
__experimentalHideHeader: true,
|
|
236
|
+
contentLabel: __("Command palette"),
|
|
237
|
+
children: /* @__PURE__ */ jsx("div", { className: "commands-command-menu__container", children: /* @__PURE__ */ jsxs(Command, { label: inputLabel, onKeyDown, children: [
|
|
238
|
+
/* @__PURE__ */ jsxs("div", { className: "commands-command-menu__header", children: [
|
|
239
|
+
/* @__PURE__ */ jsx(
|
|
240
|
+
Icon,
|
|
241
|
+
{
|
|
242
|
+
className: "commands-command-menu__header-search-icon",
|
|
243
|
+
icon: inputIcon
|
|
244
|
+
}
|
|
245
|
+
),
|
|
246
|
+
/* @__PURE__ */ jsx(
|
|
247
|
+
CommandInput,
|
|
248
|
+
{
|
|
249
|
+
search,
|
|
250
|
+
setSearch,
|
|
251
|
+
isOpen
|
|
252
|
+
}
|
|
253
|
+
)
|
|
254
|
+
] }),
|
|
255
|
+
/* @__PURE__ */ jsxs(Command.List, { label: __("Command suggestions"), children: [
|
|
256
|
+
search && !isLoading && /* @__PURE__ */ jsx(Command.Empty, { children: __("No results found.") }),
|
|
257
|
+
/* @__PURE__ */ jsx(
|
|
258
|
+
CommandMenuGroup,
|
|
259
|
+
{
|
|
260
|
+
search,
|
|
261
|
+
setLoader,
|
|
262
|
+
close: closeAndReset,
|
|
263
|
+
isContextual: true
|
|
264
|
+
}
|
|
265
|
+
),
|
|
266
|
+
search && /* @__PURE__ */ jsx(
|
|
267
|
+
CommandMenuGroup,
|
|
268
|
+
{
|
|
269
|
+
search,
|
|
270
|
+
setLoader,
|
|
271
|
+
close: closeAndReset
|
|
272
|
+
}
|
|
273
|
+
)
|
|
274
|
+
] })
|
|
275
|
+
] }) })
|
|
276
|
+
}
|
|
277
|
+
);
|
|
280
278
|
}
|
|
281
|
-
|
|
279
|
+
export {
|
|
280
|
+
CommandMenu,
|
|
281
|
+
CommandMenuGroup,
|
|
282
|
+
CommandMenuLoaderWrapper
|
|
283
|
+
};
|
|
284
|
+
//# sourceMappingURL=command-menu.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["Command","useCommandState","clsx","useSelect","useDispatch","useState","useEffect","useRef","useCallback","useMemo","__","Modal","TextHighlight","__experimentalHStack","HStack","store","keyboardShortcutsStore","useShortcut","Icon","search","inputIcon","commandsStore","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","inputLabel","CommandMenuLoader","name","hook","setLoader","close","_hook","isLoading","commands","length","children","map","command","_command$searchLabel","Item","value","searchLabel","label","keywords","onSelect","callback","id","alignment","className","icon","text","highlight","CommandMenuLoaderWrapper","currentLoaderRef","key","setKey","current","prevKey","CommandMenuGroup","isContextual","loaders","select","getCommands","getCommandLoaders","Group","_command$searchLabel2","loader","CommandInput","isOpen","setSearch","commandMenuInput","_value","state","selectedItemId","item","document","querySelector","getAttribute","focus","Input","ref","onValueChange","placeholder","CommandMenu","registerShortcut","open","setLoaders","category","description","keyCombination","modifier","character","event","defaultPrevented","preventDefault","bindGlobal","closeAndReset","onKeyDown","nativeEvent","isComposing","keyCode","Object","values","some","Boolean","overlayClassName","onRequestClose","__experimentalHideHeader","contentLabel","List","Empty"],"sources":["@wordpress/commands/src/components/command-menu.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { Command, useCommandState } from 'cmdk';\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseState,\n\tuseEffect,\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tModal,\n\tTextHighlight,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { Icon, search as inputIcon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\nconst inputLabel = __( 'Search commands and settings' );\n\nfunction CommandMenuLoader( { name, search, hook, setLoader, close } ) {\n\tconst { isLoading, commands = [] } = hook( { search } ) ?? {};\n\tuseEffect( () => {\n\t\tsetLoader( name, isLoading );\n\t}, [ setLoader, name, isLoading ] );\n\n\tif ( ! commands.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\tkeywords={ command.keywords }\n\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\tid={ command.name }\n\t\t\t\t>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\tclassName={ clsx( 'commands-command-menu__item', {\n\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t</>\n\t);\n}\n\nexport function CommandMenuLoaderWrapper( { hook, search, setLoader, close } ) {\n\t// The \"hook\" prop is actually a custom React hook\n\t// so to avoid breaking the rules of hooks\n\t// the CommandMenuLoaderWrapper component need to be\n\t// remounted on each hook prop change\n\t// We use the key state to make sure we do that properly.\n\tconst currentLoaderRef = useRef( hook );\n\tconst [ key, setKey ] = useState( 0 );\n\tuseEffect( () => {\n\t\tif ( currentLoaderRef.current !== hook ) {\n\t\t\tcurrentLoaderRef.current = hook;\n\t\t\tsetKey( ( prevKey ) => prevKey + 1 );\n\t\t}\n\t}, [ hook ] );\n\n\treturn (\n\t\t<CommandMenuLoader\n\t\t\tkey={ key }\n\t\t\thook={ currentLoaderRef.current }\n\t\t\tsearch={ search }\n\t\t\tsetLoader={ setLoader }\n\t\t\tclose={ close }\n\t\t/>\n\t);\n}\n\nexport function CommandMenuGroup( { isContextual, search, setLoader, close } ) {\n\tconst { commands, loaders } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCommands, getCommandLoaders } = select( commandsStore );\n\t\t\treturn {\n\t\t\t\tcommands: getCommands( isContextual ),\n\t\t\t\tloaders: getCommandLoaders( isContextual ),\n\t\t\t};\n\t\t},\n\t\t[ isContextual ]\n\t);\n\n\tif ( ! commands.length && ! loaders.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Command.Group>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\tkeywords={ command.keywords }\n\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\tid={ command.name }\n\t\t\t\t>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\tclassName={ clsx( 'commands-command-menu__item', {\n\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t\t{ loaders.map( ( loader ) => (\n\t\t\t\t<CommandMenuLoaderWrapper\n\t\t\t\t\tkey={ loader.name }\n\t\t\t\t\thook={ loader.hook }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\tclose={ close }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Command.Group>\n\t);\n}\n\nfunction CommandInput( { isOpen, search, setSearch } ) {\n\tconst commandMenuInput = useRef();\n\tconst _value = useCommandState( ( state ) => state.value );\n\tconst selectedItemId = useMemo( () => {\n\t\tconst item = document.querySelector(\n\t\t\t`[cmdk-item=\"\"][data-value=\"${ _value }\"]`\n\t\t);\n\t\treturn item?.getAttribute( 'id' );\n\t}, [ _value ] );\n\tuseEffect( () => {\n\t\t// Focus the command palette input when mounting the modal.\n\t\tif ( isOpen ) {\n\t\t\tcommandMenuInput.current.focus();\n\t\t}\n\t}, [ isOpen ] );\n\treturn (\n\t\t<Command.Input\n\t\t\tref={ commandMenuInput }\n\t\t\tvalue={ search }\n\t\t\tonValueChange={ setSearch }\n\t\t\tplaceholder={ inputLabel }\n\t\t\taria-activedescendant={ selectedItemId }\n\t\t\ticon={ search }\n\t\t/>\n\t);\n}\n\n/**\n * @ignore\n */\nexport function CommandMenu() {\n\tconst { registerShortcut } = useDispatch( keyboardShortcutsStore );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst isOpen = useSelect(\n\t\t( select ) => select( commandsStore ).isOpen(),\n\t\t[]\n\t);\n\tconst { open, close } = useDispatch( commandsStore );\n\tconst [ loaders, setLoaders ] = useState( {} );\n\n\tuseEffect( () => {\n\t\tregisterShortcut( {\n\t\t\tname: 'core/commands',\n\t\t\tcategory: 'global',\n\t\t\tdescription: __( 'Open the command palette.' ),\n\t\t\tkeyCombination: {\n\t\t\t\tmodifier: 'primary',\n\t\t\t\tcharacter: 'k',\n\t\t\t},\n\t\t} );\n\t}, [ registerShortcut ] );\n\n\tuseShortcut(\n\t\t'core/commands',\n\t\t/** @type {import('react').KeyboardEventHandler} */\n\t\t( event ) => {\n\t\t\t// Bails to avoid obscuring the effect of the preceding handler(s).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\t\t\tif ( isOpen ) {\n\t\t\t\tclose();\n\t\t\t} else {\n\t\t\t\topen();\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tbindGlobal: true,\n\t\t}\n\t);\n\n\tconst setLoader = useCallback(\n\t\t( name, value ) =>\n\t\t\tsetLoaders( ( current ) => ( {\n\t\t\t\t...current,\n\t\t\t\t[ name ]: value,\n\t\t\t} ) ),\n\t\t[]\n\t);\n\tconst closeAndReset = () => {\n\t\tsetSearch( '' );\n\t\tclose();\n\t};\n\n\tif ( ! isOpen ) {\n\t\treturn false;\n\t}\n\n\tconst onKeyDown = ( event ) => {\n\t\tif (\n\t\t\t// Ignore keydowns from IMEs\n\t\t\tevent.nativeEvent.isComposing ||\n\t\t\t// Workaround for Mac Safari where the final Enter/Backspace of an IME composition\n\t\t\t// is `isComposing=false`, even though it's technically still part of the composition.\n\t\t\t// These can only be detected by keyCode.\n\t\t\tevent.keyCode === 229\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\tconst isLoading = Object.values( loaders ).some( Boolean );\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"commands-command-menu\"\n\t\t\toverlayClassName=\"commands-command-menu__overlay\"\n\t\t\tonRequestClose={ closeAndReset }\n\t\t\t__experimentalHideHeader\n\t\t\tcontentLabel={ __( 'Command palette' ) }\n\t\t>\n\t\t\t<div className=\"commands-command-menu__container\">\n\t\t\t\t<Command label={ inputLabel } onKeyDown={ onKeyDown }>\n\t\t\t\t\t<div className=\"commands-command-menu__header\">\n\t\t\t\t\t\t<CommandInput\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetSearch={ setSearch }\n\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Icon icon={ inputIcon } />\n\t\t\t\t\t</div>\n\t\t\t\t\t<Command.List label={ __( 'Command suggestions' ) }>\n\t\t\t\t\t\t{ search && ! isLoading && (\n\t\t\t\t\t\t\t<Command.Empty>\n\t\t\t\t\t\t\t\t{ __( 'No results found.' ) }\n\t\t\t\t\t\t\t</Command.Empty>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\tisContextual\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ search && (\n\t\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Command.List>\n\t\t\t\t</Command>\n\t\t\t</div>\n\t\t</Modal>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,eAAe,QAAQ,MAAM;AAC/C,OAA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B;UAAAb,QAAA,gBAC7Cf,IAAA,CAAC+C,YAAY;YACZnD,MAAM,EAAGA,MAAQ;YACjBqD,SAAS,EAAGA,SAAW;YACvBD,MAAM,EAAGA;UAAQ,CACjB,CAAC,eACFhD,IAAA,CAACL,IAAI;YAACkC,IAAI,EAAGhC;UAAW,CAAE,CAAC;QAAA,CACvB,CAAC,eACNK,KAAA,CAACzB,OAAO,CAACgH,IAAI;UAACnE,KAAK,EAAGnC,EAAE,CAAE,qBAAsB,CAAG;UAAA4B,QAAA,GAChDnB,MAAM,IAAI,CAAEgB,SAAS,iBACtBZ,IAAA,CAACvB,OAAO,CAACiH,KAAK;YAAA3E,QAAA,EACX5B,EAAE,CAAE,mBAAoB;UAAC,CACb,CACf,eACDa,IAAA,CAACsC,gBAAgB;YAChB1C,MAAM,EAAGA,MAAQ;YACjBa,SAAS,EAAGA,SAAW;YACvBC,KAAK,EAAGkE,aAAe;YACvBrC,YAAY;UAAA,CACZ,CAAC,EACA3C,MAAM,iBACPI,IAAA,CAACsC,gBAAgB;YAChB1C,MAAM,EAAGA,MAAQ;YACjBa,SAAS,EAAGA,SAAW;YACvBC,KAAK,EAAGkE;UAAe,CACvB,CACD;QAAA,CACY,CAAC;MAAA,CACP;IAAC,CACN;EAAC,CACA,CAAC;AAEV","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/components/command-menu.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { Command, useCommandState } from 'cmdk';\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseState,\n\tuseEffect,\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tModal,\n\tTextHighlight,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { Icon, search as inputIcon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\nconst inputLabel = __( 'Search commands and settings' );\n\nfunction CommandMenuLoader( { name, search, hook, setLoader, close } ) {\n\tconst { isLoading, commands = [] } = hook( { search } ) ?? {};\n\tuseEffect( () => {\n\t\tsetLoader( name, isLoading );\n\t}, [ setLoader, name, isLoading ] );\n\n\tif ( ! commands.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\tkeywords={ command.keywords }\n\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\tid={ command.name }\n\t\t\t\t>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\tclassName={ clsx( 'commands-command-menu__item', {\n\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t</>\n\t);\n}\n\nexport function CommandMenuLoaderWrapper( { hook, search, setLoader, close } ) {\n\t// The \"hook\" prop is actually a custom React hook\n\t// so to avoid breaking the rules of hooks\n\t// the CommandMenuLoaderWrapper component need to be\n\t// remounted on each hook prop change\n\t// We use the key state to make sure we do that properly.\n\tconst currentLoaderRef = useRef( hook );\n\tconst [ key, setKey ] = useState( 0 );\n\tuseEffect( () => {\n\t\tif ( currentLoaderRef.current !== hook ) {\n\t\t\tcurrentLoaderRef.current = hook;\n\t\t\tsetKey( ( prevKey ) => prevKey + 1 );\n\t\t}\n\t}, [ hook ] );\n\n\treturn (\n\t\t<CommandMenuLoader\n\t\t\tkey={ key }\n\t\t\thook={ currentLoaderRef.current }\n\t\t\tsearch={ search }\n\t\t\tsetLoader={ setLoader }\n\t\t\tclose={ close }\n\t\t/>\n\t);\n}\n\nexport function CommandMenuGroup( { isContextual, search, setLoader, close } ) {\n\tconst { commands, loaders } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCommands, getCommandLoaders } = select( commandsStore );\n\t\t\treturn {\n\t\t\t\tcommands: getCommands( isContextual ),\n\t\t\t\tloaders: getCommandLoaders( isContextual ),\n\t\t\t};\n\t\t},\n\t\t[ isContextual ]\n\t);\n\n\tif ( ! commands.length && ! loaders.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Command.Group>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\tkeywords={ command.keywords }\n\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\tid={ command.name }\n\t\t\t\t>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\tclassName={ clsx( 'commands-command-menu__item', {\n\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t\t{ loaders.map( ( loader ) => (\n\t\t\t\t<CommandMenuLoaderWrapper\n\t\t\t\t\tkey={ loader.name }\n\t\t\t\t\thook={ loader.hook }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\tclose={ close }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Command.Group>\n\t);\n}\n\nfunction CommandInput( { isOpen, search, setSearch } ) {\n\tconst commandMenuInput = useRef();\n\tconst _value = useCommandState( ( state ) => state.value );\n\tconst selectedItemId = useMemo( () => {\n\t\tconst item = document.querySelector(\n\t\t\t`[cmdk-item=\"\"][data-value=\"${ _value }\"]`\n\t\t);\n\t\treturn item?.getAttribute( 'id' );\n\t}, [ _value ] );\n\tuseEffect( () => {\n\t\t// Focus the command palette input when mounting the modal.\n\t\tif ( isOpen ) {\n\t\t\tcommandMenuInput.current.focus();\n\t\t}\n\t}, [ isOpen ] );\n\treturn (\n\t\t<Command.Input\n\t\t\tref={ commandMenuInput }\n\t\t\tvalue={ search }\n\t\t\tonValueChange={ setSearch }\n\t\t\tplaceholder={ inputLabel }\n\t\t\taria-activedescendant={ selectedItemId }\n\t\t\ticon={ search }\n\t\t/>\n\t);\n}\n\n/**\n * @ignore\n */\nexport function CommandMenu() {\n\tconst { registerShortcut } = useDispatch( keyboardShortcutsStore );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst isOpen = useSelect(\n\t\t( select ) => select( commandsStore ).isOpen(),\n\t\t[]\n\t);\n\tconst { open, close } = useDispatch( commandsStore );\n\tconst [ loaders, setLoaders ] = useState( {} );\n\n\tuseEffect( () => {\n\t\tregisterShortcut( {\n\t\t\tname: 'core/commands',\n\t\t\tcategory: 'global',\n\t\t\tdescription: __( 'Open the command palette.' ),\n\t\t\tkeyCombination: {\n\t\t\t\tmodifier: 'primary',\n\t\t\t\tcharacter: 'k',\n\t\t\t},\n\t\t} );\n\t}, [ registerShortcut ] );\n\n\tuseShortcut(\n\t\t'core/commands',\n\t\t/** @type {import('react').KeyboardEventHandler} */\n\t\t( event ) => {\n\t\t\t// Bails to avoid obscuring the effect of the preceding handler(s).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\t\t\tif ( isOpen ) {\n\t\t\t\tclose();\n\t\t\t} else {\n\t\t\t\topen();\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tbindGlobal: true,\n\t\t}\n\t);\n\n\tconst setLoader = useCallback(\n\t\t( name, value ) =>\n\t\t\tsetLoaders( ( current ) => ( {\n\t\t\t\t...current,\n\t\t\t\t[ name ]: value,\n\t\t\t} ) ),\n\t\t[]\n\t);\n\tconst closeAndReset = () => {\n\t\tsetSearch( '' );\n\t\tclose();\n\t};\n\n\tif ( ! isOpen ) {\n\t\treturn false;\n\t}\n\n\tconst onKeyDown = ( event ) => {\n\t\tif (\n\t\t\t// Ignore keydowns from IMEs\n\t\t\tevent.nativeEvent.isComposing ||\n\t\t\t// Workaround for Mac Safari where the final Enter/Backspace of an IME composition\n\t\t\t// is `isComposing=false`, even though it's technically still part of the composition.\n\t\t\t// These can only be detected by keyCode.\n\t\t\tevent.keyCode === 229\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\tconst isLoading = Object.values( loaders ).some( Boolean );\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"commands-command-menu\"\n\t\t\toverlayClassName=\"commands-command-menu__overlay\"\n\t\t\tonRequestClose={ closeAndReset }\n\t\t\t__experimentalHideHeader\n\t\t\tcontentLabel={ __( 'Command palette' ) }\n\t\t>\n\t\t\t<div className=\"commands-command-menu__container\">\n\t\t\t\t<Command label={ inputLabel } onKeyDown={ onKeyDown }>\n\t\t\t\t\t<div className=\"commands-command-menu__header\">\n\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\tclassName=\"commands-command-menu__header-search-icon\"\n\t\t\t\t\t\t\ticon={ inputIcon }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<CommandInput\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetSearch={ setSearch }\n\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t\t<Command.List label={ __( 'Command suggestions' ) }>\n\t\t\t\t\t\t{ search && ! isLoading && (\n\t\t\t\t\t\t\t<Command.Empty>\n\t\t\t\t\t\t\t\t{ __( 'No results found.' ) }\n\t\t\t\t\t\t\t</Command.Empty>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\tisContextual\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ search && (\n\t\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Command.List>\n\t\t\t\t</Command>\n\t\t\t</div>\n\t\t</Modal>\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AA+CE,mBAesB,KANnB,YATH;AA5CF,SAAS,SAAS,uBAAuB;AACzC,OAAO,UAAU;AAKjB,SAAS,WAAW,mBAAmB;AACvC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA;AAAA,EACA,wBAAwB;AAAA,OAClB;AACP;AAAA,EACC,SAAS;AAAA,EACT;AAAA,OACM;AACP,SAAS,MAAM,UAAU,iBAAiB;AAK1C,SAAS,SAAS,qBAAqB;AAEvC,MAAM,aAAa,GAAI,8BAA+B;AAEtD,SAAS,kBAAmB,EAAE,MAAM,QAAQ,MAAM,WAAW,MAAM,GAAI;AACtE,QAAM,EAAE,W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;AAAA;AAAA,UACT;AAAA,WAEF;AAAA,SACD,GACD;AAAA;AAAA,EACD;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,37 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { store as commandsStore } from '../store';
|
|
11
|
-
import { unlock } from '../lock-unlock';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Sets the active context of the command palette
|
|
15
|
-
*
|
|
16
|
-
* @param {string} context Context to set.
|
|
17
|
-
*/
|
|
18
|
-
export default function useCommandContext(context) {
|
|
19
|
-
const {
|
|
20
|
-
getContext
|
|
21
|
-
} = useSelect(commandsStore);
|
|
1
|
+
import { useEffect, useRef } from "@wordpress/element";
|
|
2
|
+
import { useDispatch, useSelect } from "@wordpress/data";
|
|
3
|
+
import { store as commandsStore } from "../store";
|
|
4
|
+
import { unlock } from "../lock-unlock";
|
|
5
|
+
function useCommandContext(context) {
|
|
6
|
+
const { getContext } = useSelect(commandsStore);
|
|
22
7
|
const initialContext = useRef(getContext());
|
|
23
|
-
const {
|
|
24
|
-
setContext
|
|
25
|
-
} = unlock(useDispatch(commandsStore));
|
|
8
|
+
const { setContext } = unlock(useDispatch(commandsStore));
|
|
26
9
|
useEffect(() => {
|
|
27
10
|
setContext(context);
|
|
28
11
|
}, [context, setContext]);
|
|
29
|
-
|
|
30
|
-
// This effects ensures that on unmount, we restore the context
|
|
31
|
-
// that was set before the component actually mounts.
|
|
32
12
|
useEffect(() => {
|
|
33
13
|
const initialContextRef = initialContext.current;
|
|
34
14
|
return () => setContext(initialContextRef);
|
|
35
15
|
}, [setContext]);
|
|
36
16
|
}
|
|
37
|
-
|
|
17
|
+
export {
|
|
18
|
+
useCommandContext as default
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=use-command-context.js.map
|