@wordpress/commands 1.42.0 → 1.43.1-next.v.202604091042.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 +6 -1
- package/build/components/command-menu.cjs +156 -154
- package/build/components/command-menu.cjs.map +3 -3
- package/build/components/use-recent-commands.cjs +125 -0
- package/build/components/use-recent-commands.cjs.map +7 -0
- package/build/store/index.cjs +2 -0
- package/build/store/index.cjs.map +2 -2
- package/build/store/private-actions.cjs +11 -2
- package/build/store/private-actions.cjs.map +2 -2
- package/build/store/private-selectors.cjs +32 -0
- package/build/store/private-selectors.cjs.map +7 -0
- package/build/store/reducer.cjs +12 -1
- package/build/store/reducer.cjs.map +2 -2
- package/build-module/components/command-menu.mjs +160 -154
- package/build-module/components/command-menu.mjs.map +2 -2
- package/build-module/components/use-recent-commands.mjs +104 -0
- package/build-module/components/use-recent-commands.mjs.map +7 -0
- package/build-module/store/index.mjs +2 -0
- package/build-module/store/index.mjs.map +2 -2
- package/build-module/store/private-actions.mjs +9 -1
- package/build-module/store/private-actions.mjs.map +2 -2
- package/build-module/store/private-selectors.mjs +8 -0
- package/build-module/store/private-selectors.mjs.map +7 -0
- package/build-module/store/reducer.mjs +12 -1
- package/build-module/store/reducer.mjs.map +2 -2
- package/build-style/style-rtl.css +25 -21
- package/build-style/style.css +25 -21
- package/package.json +12 -11
- package/src/components/command-menu.js +179 -161
- package/src/components/style.scss +32 -29
- package/src/components/use-recent-commands.js +131 -0
- package/src/store/index.js +2 -0
- package/src/store/private-actions.js +16 -0
- package/src/store/private-selectors.js +10 -0
- package/src/store/reducer.js +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 1.43.0 (2026-04-01)
|
|
6
|
+
|
|
7
|
+
### Enhancements
|
|
8
|
+
|
|
9
|
+
- Add a new section of recently used commands to the Command Palette.
|
|
10
|
+
|
|
5
11
|
## 1.42.0 (2026-03-18)
|
|
6
12
|
|
|
7
13
|
## 1.41.0 (2026-03-04)
|
|
8
14
|
|
|
9
15
|
## 1.40.0 (2026-02-18)
|
|
10
|
-
|
|
11
16
|
- Add `category` property to command config, used to visually differentiate commands in the Command Palette.
|
|
12
17
|
|
|
13
18
|
## 1.39.0 (2026-01-29)
|
|
@@ -30,8 +30,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
var command_menu_exports = {};
|
|
31
31
|
__export(command_menu_exports, {
|
|
32
32
|
CommandMenu: () => CommandMenu,
|
|
33
|
-
CommandMenuGroup: () => CommandMenuGroup,
|
|
34
|
-
CommandMenuLoaderWrapper: () => CommandMenuLoaderWrapper,
|
|
35
33
|
isValidIcon: () => isValidIcon
|
|
36
34
|
});
|
|
37
35
|
module.exports = __toCommonJS(command_menu_exports);
|
|
@@ -45,8 +43,10 @@ var import_keyboard_shortcuts = require("@wordpress/keyboard-shortcuts");
|
|
|
45
43
|
var import_icons = require("@wordpress/icons");
|
|
46
44
|
var import_store = require("../store/index.cjs");
|
|
47
45
|
var import_lock_unlock = require("../lock-unlock.cjs");
|
|
46
|
+
var import_use_recent_commands = require("./use-recent-commands.cjs");
|
|
48
47
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
49
48
|
var { withIgnoreIMEEvents } = (0, import_lock_unlock.unlock)(import_components.privateApis);
|
|
49
|
+
var ITEM_ID_PREFIX = "command-palette-item-";
|
|
50
50
|
var inputLabel = (0, import_i18n.__)("Search commands and settings");
|
|
51
51
|
var CATEGORY_ICONS = {
|
|
52
52
|
view: import_icons.arrowRight
|
|
@@ -61,68 +61,66 @@ var CATEGORY_LABELS = {
|
|
|
61
61
|
function isValidIcon(icon) {
|
|
62
62
|
return !!icon && (typeof icon === "string" || (0, import_element.isValidElement)(icon) || typeof icon === "function" || icon instanceof import_element.Component);
|
|
63
63
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
function CommandItem({ command, search, category, valuePrefix }) {
|
|
65
|
+
const { close } = (0, import_data.useDispatch)(import_store.store);
|
|
66
|
+
const commandCategory = category ?? command.category;
|
|
67
|
+
const label = command.searchLabel ?? command.label;
|
|
68
|
+
const value = valuePrefix ? `${valuePrefix}${command.name}` : label;
|
|
69
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
70
|
+
import_cmdk.Command.Item,
|
|
71
|
+
{
|
|
72
|
+
id: `${ITEM_ID_PREFIX}${value.toLowerCase()}`,
|
|
73
|
+
value,
|
|
74
|
+
keywords: valuePrefix ? [...command.keywords ?? [], label] : command.keywords,
|
|
75
|
+
onSelect: () => {
|
|
76
|
+
(0, import_use_recent_commands.recordUsage)(command.name);
|
|
77
|
+
command.callback({ close });
|
|
78
|
+
},
|
|
79
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
80
|
+
import_components.__experimentalHStack,
|
|
81
|
+
{
|
|
82
|
+
alignment: "left",
|
|
83
|
+
className: (0, import_clsx.default)("commands-command-menu__item", {
|
|
84
|
+
"has-icon": CATEGORY_ICONS[commandCategory] || command.icon
|
|
85
|
+
}),
|
|
86
|
+
children: [
|
|
87
|
+
CATEGORY_ICONS[commandCategory] ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.Icon, { icon: CATEGORY_ICONS[commandCategory] }) : isValidIcon(command.icon) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.Icon, { icon: command.icon }),
|
|
88
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "commands-command-menu__item-label", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
89
|
+
import_components.TextHighlight,
|
|
90
|
+
{
|
|
91
|
+
text: command.label,
|
|
92
|
+
highlight: search
|
|
93
|
+
}
|
|
94
|
+
) }),
|
|
95
|
+
CATEGORY_LABELS[commandCategory] && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "commands-command-menu__item-category", children: CATEGORY_LABELS[commandCategory] })
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
},
|
|
100
|
+
command.name
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
function CommandMenuLoader({ name, search, hook, category, valuePrefix }) {
|
|
104
|
+
const { setLoaderLoading } = (0, import_lock_unlock.unlock)((0, import_data.useDispatch)(import_store.store));
|
|
105
|
+
const { isLoading: loading, commands = [] } = hook({ search }) ?? {};
|
|
73
106
|
(0, import_element.useEffect)(() => {
|
|
74
|
-
|
|
75
|
-
}, [
|
|
107
|
+
setLoaderLoading(name, loading);
|
|
108
|
+
}, [setLoaderLoading, name, loading]);
|
|
76
109
|
if (!commands.length) {
|
|
77
110
|
return null;
|
|
78
111
|
}
|
|
79
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: commands.map((command) =>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
import_components.__experimentalHStack,
|
|
90
|
-
{
|
|
91
|
-
alignment: "left",
|
|
92
|
-
className: (0, import_clsx.default)("commands-command-menu__item", {
|
|
93
|
-
"has-icon": CATEGORY_ICONS[commandCategory] || command.icon
|
|
94
|
-
}),
|
|
95
|
-
children: [
|
|
96
|
-
CATEGORY_ICONS[commandCategory] && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
97
|
-
import_icons.Icon,
|
|
98
|
-
{
|
|
99
|
-
icon: CATEGORY_ICONS[commandCategory]
|
|
100
|
-
}
|
|
101
|
-
),
|
|
102
|
-
!CATEGORY_ICONS[commandCategory] && isValidIcon(command.icon) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.Icon, { icon: command.icon }),
|
|
103
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "commands-command-menu__item-label", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
104
|
-
import_components.TextHighlight,
|
|
105
|
-
{
|
|
106
|
-
text: command.label,
|
|
107
|
-
highlight: search
|
|
108
|
-
}
|
|
109
|
-
) }),
|
|
110
|
-
CATEGORY_LABELS[commandCategory] && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "commands-command-menu__item-category", children: CATEGORY_LABELS[commandCategory] })
|
|
111
|
-
]
|
|
112
|
-
}
|
|
113
|
-
)
|
|
114
|
-
},
|
|
115
|
-
command.name
|
|
116
|
-
);
|
|
117
|
-
}) });
|
|
112
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: commands.map((command) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
113
|
+
CommandItem,
|
|
114
|
+
{
|
|
115
|
+
command,
|
|
116
|
+
search,
|
|
117
|
+
category: command.category ?? category,
|
|
118
|
+
valuePrefix
|
|
119
|
+
},
|
|
120
|
+
command.name
|
|
121
|
+
)) });
|
|
118
122
|
}
|
|
119
|
-
function CommandMenuLoaderWrapper({
|
|
120
|
-
hook,
|
|
121
|
-
search,
|
|
122
|
-
setLoader,
|
|
123
|
-
close,
|
|
124
|
-
category
|
|
125
|
-
}) {
|
|
123
|
+
function CommandMenuLoaderWrapper({ hook, ...props }) {
|
|
126
124
|
const currentLoaderRef = (0, import_element.useRef)(hook);
|
|
127
125
|
const [key, setKey] = (0, import_element.useState)(0);
|
|
128
126
|
(0, import_element.useEffect)(() => {
|
|
@@ -135,86 +133,112 @@ function CommandMenuLoaderWrapper({
|
|
|
135
133
|
CommandMenuLoader,
|
|
136
134
|
{
|
|
137
135
|
hook: currentLoaderRef.current,
|
|
138
|
-
|
|
139
|
-
setLoader,
|
|
140
|
-
close,
|
|
141
|
-
category
|
|
136
|
+
...props
|
|
142
137
|
},
|
|
143
138
|
key
|
|
144
139
|
);
|
|
145
140
|
}
|
|
146
|
-
function
|
|
147
|
-
|
|
148
|
-
(select) => {
|
|
149
|
-
const { getCommands, getCommandLoaders } = select(import_store.store);
|
|
150
|
-
return {
|
|
151
|
-
commands: getCommands(isContextual),
|
|
152
|
-
loaders: getCommandLoaders(isContextual)
|
|
153
|
-
};
|
|
154
|
-
},
|
|
155
|
-
[isContextual]
|
|
156
|
-
);
|
|
157
|
-
if (!commands.length && !loaders.length) {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_cmdk.Command.Group, { children: [
|
|
141
|
+
function CommandList({ search, commands, loaders, valuePrefix }) {
|
|
142
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
161
143
|
commands.map((command) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
162
|
-
|
|
144
|
+
CommandItem,
|
|
163
145
|
{
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
id: command.name,
|
|
168
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
169
|
-
import_components.__experimentalHStack,
|
|
170
|
-
{
|
|
171
|
-
alignment: "left",
|
|
172
|
-
className: (0, import_clsx.default)("commands-command-menu__item", {
|
|
173
|
-
"has-icon": CATEGORY_ICONS[command.category] || command.icon
|
|
174
|
-
}),
|
|
175
|
-
children: [
|
|
176
|
-
CATEGORY_ICONS[command.category] ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.Icon, { icon: CATEGORY_ICONS[command.category] }) : command.icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.Icon, { icon: command.icon }),
|
|
177
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
178
|
-
import_components.TextHighlight,
|
|
179
|
-
{
|
|
180
|
-
text: command.label,
|
|
181
|
-
highlight: search
|
|
182
|
-
}
|
|
183
|
-
) }),
|
|
184
|
-
CATEGORY_LABELS[command.category] && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "commands-command-menu__item-category", children: CATEGORY_LABELS[command.category] })
|
|
185
|
-
]
|
|
186
|
-
}
|
|
187
|
-
)
|
|
146
|
+
command,
|
|
147
|
+
search,
|
|
148
|
+
valuePrefix
|
|
188
149
|
},
|
|
189
150
|
command.name
|
|
190
151
|
)),
|
|
191
152
|
loaders.map((loader) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
192
153
|
CommandMenuLoaderWrapper,
|
|
193
154
|
{
|
|
194
|
-
|
|
155
|
+
name: loader.name,
|
|
195
156
|
search,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
157
|
+
hook: loader.hook,
|
|
158
|
+
category: loader.category,
|
|
159
|
+
valuePrefix
|
|
160
|
+
},
|
|
161
|
+
loader.name
|
|
162
|
+
))
|
|
163
|
+
] });
|
|
164
|
+
}
|
|
165
|
+
function RecentLoaderRunner({ hook, name, filterNames, onResolved }) {
|
|
166
|
+
(0, import_use_recent_commands.useLoaderCollector)(hook, name, filterNames, onResolved);
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
function RecentGroup() {
|
|
170
|
+
const { commands, loaders, recentSet, onResolved } = (0, import_use_recent_commands.useRecentCommands)();
|
|
171
|
+
if (!commands.length && !loaders.length) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_cmdk.Command.Group, { heading: (0, import_i18n.__)("Recent"), children: [
|
|
175
|
+
loaders.map((loader) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
176
|
+
RecentLoaderRunner,
|
|
177
|
+
{
|
|
178
|
+
name: loader.name,
|
|
179
|
+
hook: loader.hook,
|
|
180
|
+
filterNames: recentSet,
|
|
181
|
+
onResolved
|
|
199
182
|
},
|
|
200
183
|
loader.name
|
|
184
|
+
)),
|
|
185
|
+
commands.map((command) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
186
|
+
CommandItem,
|
|
187
|
+
{
|
|
188
|
+
command,
|
|
189
|
+
search: "",
|
|
190
|
+
valuePrefix: "recent-"
|
|
191
|
+
},
|
|
192
|
+
command.name
|
|
201
193
|
))
|
|
202
194
|
] });
|
|
203
195
|
}
|
|
204
|
-
function
|
|
196
|
+
function SuggestionsGroup() {
|
|
197
|
+
const { commands, loaders } = (0, import_data.useSelect)((select) => {
|
|
198
|
+
const { getCommands, getCommandLoaders } = select(import_store.store);
|
|
199
|
+
return {
|
|
200
|
+
commands: getCommands(true),
|
|
201
|
+
loaders: getCommandLoaders(true)
|
|
202
|
+
};
|
|
203
|
+
}, []);
|
|
204
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_cmdk.Command.Group, { heading: (0, import_i18n.__)("Suggestions"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CommandList, { search: "", commands, loaders }) });
|
|
205
|
+
}
|
|
206
|
+
function ResultsGroup({ search }) {
|
|
207
|
+
const { commands, contextualCommands, loaders, contextualLoaders } = (0, import_data.useSelect)((select) => {
|
|
208
|
+
const { getCommands, getCommandLoaders } = select(import_store.store);
|
|
209
|
+
return {
|
|
210
|
+
commands: getCommands(false),
|
|
211
|
+
contextualCommands: getCommands(true),
|
|
212
|
+
loaders: getCommandLoaders(false),
|
|
213
|
+
contextualLoaders: getCommandLoaders(true)
|
|
214
|
+
};
|
|
215
|
+
}, []);
|
|
216
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_cmdk.Command.Group, { heading: (0, import_i18n.__)("Results"), children: [
|
|
217
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
218
|
+
CommandList,
|
|
219
|
+
{
|
|
220
|
+
search,
|
|
221
|
+
commands,
|
|
222
|
+
loaders
|
|
223
|
+
}
|
|
224
|
+
),
|
|
225
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
226
|
+
CommandList,
|
|
227
|
+
{
|
|
228
|
+
search,
|
|
229
|
+
commands: contextualCommands,
|
|
230
|
+
loaders: contextualLoaders
|
|
231
|
+
}
|
|
232
|
+
)
|
|
233
|
+
] });
|
|
234
|
+
}
|
|
235
|
+
function CommandInput({ search, setSearch }) {
|
|
205
236
|
const commandMenuInput = (0, import_element.useRef)();
|
|
206
237
|
const _value = (0, import_cmdk.useCommandState)((state) => state.value);
|
|
207
|
-
const selectedItemId =
|
|
208
|
-
const item = document.querySelector(
|
|
209
|
-
`[cmdk-item=""][data-value="${_value}"]`
|
|
210
|
-
);
|
|
211
|
-
return item?.getAttribute("id");
|
|
212
|
-
}, [_value]);
|
|
238
|
+
const selectedItemId = _value ? `${ITEM_ID_PREFIX}${_value}` : null;
|
|
213
239
|
(0, import_element.useEffect)(() => {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
}, [isOpen]);
|
|
240
|
+
commandMenuInput.current.focus();
|
|
241
|
+
}, []);
|
|
218
242
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
219
243
|
import_cmdk.Command.Input,
|
|
220
244
|
{
|
|
@@ -229,12 +253,14 @@ function CommandInput({ isOpen, search, setSearch }) {
|
|
|
229
253
|
function CommandMenu() {
|
|
230
254
|
const { registerShortcut } = (0, import_data.useDispatch)(import_keyboard_shortcuts.store);
|
|
231
255
|
const [search, setSearch] = (0, import_element.useState)("");
|
|
232
|
-
const isOpen = (0, import_data.useSelect)(
|
|
233
|
-
(select) =>
|
|
256
|
+
const { isOpen: paletteIsOpen, loadersLoading } = (0, import_data.useSelect)(
|
|
257
|
+
(select) => ({
|
|
258
|
+
isOpen: select(import_store.store).isOpen(),
|
|
259
|
+
loadersLoading: (0, import_lock_unlock.unlock)(select(import_store.store)).isLoading()
|
|
260
|
+
}),
|
|
234
261
|
[]
|
|
235
262
|
);
|
|
236
263
|
const { open, close } = (0, import_data.useDispatch)(import_store.store);
|
|
237
|
-
const [loaders, setLoaders] = (0, import_element.useState)({});
|
|
238
264
|
(0, import_element.useEffect)(() => {
|
|
239
265
|
registerShortcut({
|
|
240
266
|
name: "core/commands",
|
|
@@ -254,7 +280,7 @@ function CommandMenu() {
|
|
|
254
280
|
return;
|
|
255
281
|
}
|
|
256
282
|
event.preventDefault();
|
|
257
|
-
if (
|
|
283
|
+
if (paletteIsOpen) {
|
|
258
284
|
close();
|
|
259
285
|
} else {
|
|
260
286
|
open();
|
|
@@ -264,21 +290,13 @@ function CommandMenu() {
|
|
|
264
290
|
bindGlobal: true
|
|
265
291
|
}
|
|
266
292
|
);
|
|
267
|
-
const setLoader = (0, import_element.useCallback)(
|
|
268
|
-
(name, value) => setLoaders((current) => ({
|
|
269
|
-
...current,
|
|
270
|
-
[name]: value
|
|
271
|
-
})),
|
|
272
|
-
[]
|
|
273
|
-
);
|
|
274
293
|
const closeAndReset = () => {
|
|
275
294
|
setSearch("");
|
|
276
295
|
close();
|
|
277
296
|
};
|
|
278
|
-
if (!
|
|
297
|
+
if (!paletteIsOpen) {
|
|
279
298
|
return false;
|
|
280
299
|
}
|
|
281
|
-
const isLoading = Object.values(loaders).some(Boolean);
|
|
282
300
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
283
301
|
import_components.Modal,
|
|
284
302
|
{
|
|
@@ -286,8 +304,9 @@ function CommandMenu() {
|
|
|
286
304
|
overlayClassName: "commands-command-menu__overlay",
|
|
287
305
|
onRequestClose: closeAndReset,
|
|
288
306
|
__experimentalHideHeader: true,
|
|
307
|
+
size: "medium",
|
|
289
308
|
contentLabel: (0, import_i18n.__)("Command palette"),
|
|
290
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "commands-command-menu__container", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_cmdk.Command, { label: inputLabel, children: [
|
|
309
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "commands-command-menu__container", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_cmdk.Command, { label: inputLabel, loop: true, children: [
|
|
291
310
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "commands-command-menu__header", children: [
|
|
292
311
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
293
312
|
import_icons.Icon,
|
|
@@ -300,30 +319,15 @@ function CommandMenu() {
|
|
|
300
319
|
CommandInput,
|
|
301
320
|
{
|
|
302
321
|
search,
|
|
303
|
-
setSearch
|
|
304
|
-
isOpen
|
|
322
|
+
setSearch
|
|
305
323
|
}
|
|
306
324
|
)
|
|
307
325
|
] }),
|
|
308
326
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_cmdk.Command.List, { label: (0, import_i18n.__)("Command suggestions"), children: [
|
|
309
|
-
search && !
|
|
310
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
search,
|
|
314
|
-
setLoader,
|
|
315
|
-
close: closeAndReset,
|
|
316
|
-
isContextual: true
|
|
317
|
-
}
|
|
318
|
-
),
|
|
319
|
-
search && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
320
|
-
CommandMenuGroup,
|
|
321
|
-
{
|
|
322
|
-
search,
|
|
323
|
-
setLoader,
|
|
324
|
-
close: closeAndReset
|
|
325
|
-
}
|
|
326
|
-
)
|
|
327
|
+
search && !loadersLoading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_cmdk.Command.Empty, { children: (0, import_i18n.__)("No results found.") }),
|
|
328
|
+
!search && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecentGroup, {}),
|
|
329
|
+
!search && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SuggestionsGroup, {}),
|
|
330
|
+
search && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ResultsGroup, { search })
|
|
327
331
|
] })
|
|
328
332
|
] }) })
|
|
329
333
|
}
|
|
@@ -332,8 +336,6 @@ function CommandMenu() {
|
|
|
332
336
|
// Annotate the CommonJS export names for ESM import in node:
|
|
333
337
|
0 && (module.exports = {
|
|
334
338
|
CommandMenu,
|
|
335
|
-
CommandMenuGroup,
|
|
336
|
-
CommandMenuLoaderWrapper,
|
|
337
339
|
isValidIcon
|
|
338
340
|
});
|
|
339
341
|
//# sourceMappingURL=command-menu.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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\tisValidElement,\n\tComponent,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tModal,\n\tTextHighlight,\n\t__experimentalHStack as HStack,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { Icon, search as inputIcon, arrowRight } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nconst { withIgnoreIMEEvents } = unlock( componentsPrivateApis );\n\nconst inputLabel = __( 'Search commands and settings' );\n\n/**\n * Icons enforced per command category.\n * Categories listed here will always use the specified icon,\n * ignoring whatever icon the command itself provides.\n */\nconst CATEGORY_ICONS = {\n\tview: arrowRight,\n};\n\n/**\n * Translatable labels for command categories.\n */\nconst CATEGORY_LABELS = {\n\tcommand: __( 'Command' ),\n\tview: __( 'View' ),\n\tedit: __( 'Edit' ),\n\taction: __( 'Action' ),\n\tworkflow: __( 'Workflow' ),\n};\n\n/**\n * Function that checks if the parameter is a valid icon.\n * Taken from @wordpress/blocks/src/api/utils.js and copied\n * in case requirements diverge and to avoid a dependency on @wordpress/blocks.\n *\n * @param {*} icon Parameter to be checked.\n *\n * @return {boolean} True if the parameter is a valid icon and false otherwise.\n */\n\nexport function isValidIcon( icon ) {\n\treturn (\n\t\t!! icon &&\n\t\t( typeof icon === 'string' ||\n\t\t\tisValidElement( icon ) ||\n\t\t\ttypeof icon === 'function' ||\n\t\t\ticon instanceof Component )\n\t);\n}\n\nfunction CommandMenuLoader( {\n\tname,\n\tsearch,\n\thook,\n\tsetLoader,\n\tclose,\n\tcategory,\n} ) {\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\tconst commandCategory = command.category ?? category;\n\t\t\t\treturn (\n\t\t\t\t\t<Command.Item\n\t\t\t\t\t\tkey={ command.name }\n\t\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\t\tkeywords={ command.keywords }\n\t\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\t\tid={ command.name }\n\t\t\t\t\t>\n\t\t\t\t\t\t<HStack\n\t\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\t\tclassName={ clsx( 'commands-command-menu__item', {\n\t\t\t\t\t\t\t\t'has-icon':\n\t\t\t\t\t\t\t\t\tCATEGORY_ICONS[ commandCategory ] ||\n\t\t\t\t\t\t\t\t\tcommand.icon,\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ CATEGORY_ICONS[ commandCategory ] && (\n\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\ticon={ CATEGORY_ICONS[ commandCategory ] }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ ! CATEGORY_ICONS[ commandCategory ] &&\n\t\t\t\t\t\t\t\tisValidIcon( command.icon ) && (\n\t\t\t\t\t\t\t\t\t<Icon icon={ command.icon } />\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t<span className=\"commands-command-menu__item-label\">\n\t\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t{ CATEGORY_LABELS[ commandCategory ] && (\n\t\t\t\t\t\t\t\t<span className=\"commands-command-menu__item-category\">\n\t\t\t\t\t\t\t\t\t{ CATEGORY_LABELS[ commandCategory ] }\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</HStack>\n\t\t\t\t\t</Command.Item>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</>\n\t);\n}\n\nexport function CommandMenuLoaderWrapper( {\n\thook,\n\tsearch,\n\tsetLoader,\n\tclose,\n\tcategory,\n} ) {\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\tcategory={ category }\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':\n\t\t\t\t\t\t\t\tCATEGORY_ICONS[ command.category ] ||\n\t\t\t\t\t\t\t\tcommand.icon,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ CATEGORY_ICONS[ command.category ] ? (\n\t\t\t\t\t\t\t<Icon icon={ CATEGORY_ICONS[ command.category ] } />\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\tcommand.icon && <Icon icon={ command.icon } />\n\t\t\t\t\t\t) }\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\t{ CATEGORY_LABELS[ command.category ] && (\n\t\t\t\t\t\t\t<span className=\"commands-command-menu__item-category\">\n\t\t\t\t\t\t\t\t{ CATEGORY_LABELS[ command.category ] }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) }\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\tcategory={ loader.category }\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/>\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 {React.KeyboardEventHandler} */\n\t\twithIgnoreIMEEvents( ( 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 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 }>\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
6
|
-
"names": ["componentsPrivateApis", "
|
|
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\tisValidElement,\n\tComponent,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tModal,\n\tTextHighlight,\n\t__experimentalHStack as HStack,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { Icon, search as inputIcon, arrowRight } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\nimport { unlock } from '../lock-unlock';\nimport {\n\trecordUsage,\n\tuseLoaderCollector,\n\tuseRecentCommands,\n} from './use-recent-commands';\n\nconst { withIgnoreIMEEvents } = unlock( componentsPrivateApis );\n\n// Namespaces item ids to avoid collisions with other elements on the page.\nconst ITEM_ID_PREFIX = 'command-palette-item-';\nconst inputLabel = __( 'Search commands and settings' );\n\n/**\n * Icons enforced per command category.\n * Categories listed here will always use the specified icon,\n * ignoring whatever icon the command itself provides.\n */\nconst CATEGORY_ICONS = {\n\tview: arrowRight,\n};\n\n/**\n * Translatable labels for command categories.\n */\nconst CATEGORY_LABELS = {\n\tcommand: __( 'Command' ),\n\tview: __( 'View' ),\n\tedit: __( 'Edit' ),\n\taction: __( 'Action' ),\n\tworkflow: __( 'Workflow' ),\n};\n\n/**\n * Function that checks if the parameter is a valid icon.\n * Taken from @wordpress/blocks/src/api/utils.js and copied\n * in case requirements diverge and to avoid a dependency on @wordpress/blocks.\n *\n * @param {*} icon Parameter to be checked.\n *\n * @return {boolean} True if the parameter is a valid icon and false otherwise.\n */\n\nexport function isValidIcon( icon ) {\n\treturn (\n\t\t!! icon &&\n\t\t( typeof icon === 'string' ||\n\t\t\tisValidElement( icon ) ||\n\t\t\ttypeof icon === 'function' ||\n\t\t\ticon instanceof Component )\n\t);\n}\n\nfunction CommandItem( { command, search, category, valuePrefix } ) {\n\tconst { close } = useDispatch( commandsStore );\n\tconst commandCategory = category ?? command.category;\n\tconst label = command.searchLabel ?? command.label;\n\tconst value = valuePrefix ? `${ valuePrefix }${ command.name }` : label;\n\treturn (\n\t\t<Command.Item\n\t\t\tkey={ command.name }\n\t\t\tid={ `${ ITEM_ID_PREFIX }${ value.toLowerCase() }` }\n\t\t\tvalue={ value }\n\t\t\tkeywords={\n\t\t\t\tvaluePrefix\n\t\t\t\t\t? [ ...( command.keywords ?? [] ), label ]\n\t\t\t\t\t: command.keywords\n\t\t\t}\n\t\t\tonSelect={ () => {\n\t\t\t\trecordUsage( command.name );\n\t\t\t\tcommand.callback( { close } );\n\t\t\t} }\n\t\t>\n\t\t\t<HStack\n\t\t\t\talignment=\"left\"\n\t\t\t\tclassName={ clsx( 'commands-command-menu__item', {\n\t\t\t\t\t'has-icon':\n\t\t\t\t\t\tCATEGORY_ICONS[ commandCategory ] || command.icon,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ CATEGORY_ICONS[ commandCategory ] ? (\n\t\t\t\t\t<Icon icon={ CATEGORY_ICONS[ commandCategory ] } />\n\t\t\t\t) : (\n\t\t\t\t\tisValidIcon( command.icon ) && (\n\t\t\t\t\t\t<Icon icon={ command.icon } />\n\t\t\t\t\t)\n\t\t\t\t) }\n\t\t\t\t<span className=\"commands-command-menu__item-label\">\n\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t/>\n\t\t\t\t</span>\n\t\t\t\t{ CATEGORY_LABELS[ commandCategory ] && (\n\t\t\t\t\t<span className=\"commands-command-menu__item-category\">\n\t\t\t\t\t\t{ CATEGORY_LABELS[ commandCategory ] }\n\t\t\t\t\t</span>\n\t\t\t\t) }\n\t\t\t</HStack>\n\t\t</Command.Item>\n\t);\n}\n\nfunction CommandMenuLoader( { name, search, hook, category, valuePrefix } ) {\n\tconst { setLoaderLoading } = unlock( useDispatch( commandsStore ) );\n\tconst { isLoading: loading, commands = [] } = hook( { search } ) ?? {};\n\tuseEffect( () => {\n\t\tsetLoaderLoading( name, loading );\n\t}, [ setLoaderLoading, name, loading ] );\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<CommandItem\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tcommand={ command }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\tcategory={ command.category ?? category }\n\t\t\t\t\tvaluePrefix={ valuePrefix }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</>\n\t);\n}\n\nfunction CommandMenuLoaderWrapper( { hook, ...props } ) {\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\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\t{ ...props }\n\t\t/>\n\t);\n}\n\nfunction CommandList( { search, commands, loaders, valuePrefix } ) {\n\treturn (\n\t\t<>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<CommandItem\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tcommand={ command }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\tvaluePrefix={ valuePrefix }\n\t\t\t\t/>\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\tname={ loader.name }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\thook={ loader.hook }\n\t\t\t\t\tcategory={ loader.category }\n\t\t\t\t\tvaluePrefix={ valuePrefix }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</>\n\t);\n}\n\nfunction RecentLoaderRunner( { hook, name, filterNames, onResolved } ) {\n\tuseLoaderCollector( hook, name, filterNames, onResolved );\n\treturn null;\n}\n\nfunction RecentGroup() {\n\tconst { commands, loaders, recentSet, onResolved } = useRecentCommands();\n\n\tif ( ! commands.length && ! loaders.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Command.Group heading={ __( 'Recent' ) }>\n\t\t\t{ loaders.map( ( loader ) => (\n\t\t\t\t<RecentLoaderRunner\n\t\t\t\t\tkey={ loader.name }\n\t\t\t\t\tname={ loader.name }\n\t\t\t\t\thook={ loader.hook }\n\t\t\t\t\tfilterNames={ recentSet }\n\t\t\t\t\tonResolved={ onResolved }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<CommandItem\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tcommand={ command }\n\t\t\t\t\tsearch=\"\"\n\t\t\t\t\tvaluePrefix=\"recent-\"\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Command.Group>\n\t);\n}\n\nfunction SuggestionsGroup() {\n\tconst { commands, loaders } = useSelect( ( select ) => {\n\t\tconst { getCommands, getCommandLoaders } = select( commandsStore );\n\t\treturn {\n\t\t\tcommands: getCommands( true ),\n\t\t\tloaders: getCommandLoaders( true ),\n\t\t};\n\t}, [] );\n\n\treturn (\n\t\t<Command.Group heading={ __( 'Suggestions' ) }>\n\t\t\t<CommandList search=\"\" commands={ commands } loaders={ loaders } />\n\t\t</Command.Group>\n\t);\n}\n\nfunction ResultsGroup( { search } ) {\n\tconst { commands, contextualCommands, loaders, contextualLoaders } =\n\t\tuseSelect( ( select ) => {\n\t\t\tconst { getCommands, getCommandLoaders } = select( commandsStore );\n\t\t\treturn {\n\t\t\t\tcommands: getCommands( false ),\n\t\t\t\tcontextualCommands: getCommands( true ),\n\t\t\t\tloaders: getCommandLoaders( false ),\n\t\t\t\tcontextualLoaders: getCommandLoaders( true ),\n\t\t\t};\n\t\t}, [] );\n\n\treturn (\n\t\t<Command.Group heading={ __( 'Results' ) }>\n\t\t\t<CommandList\n\t\t\t\tsearch={ search }\n\t\t\t\tcommands={ commands }\n\t\t\t\tloaders={ loaders }\n\t\t\t/>\n\t\t\t<CommandList\n\t\t\t\tsearch={ search }\n\t\t\t\tcommands={ contextualCommands }\n\t\t\t\tloaders={ contextualLoaders }\n\t\t\t/>\n\t\t</Command.Group>\n\t);\n}\n\nfunction CommandInput( { search, setSearch } ) {\n\tconst commandMenuInput = useRef();\n\tconst _value = useCommandState( ( state ) => state.value );\n\tconst selectedItemId = _value ? `${ ITEM_ID_PREFIX }${ _value }` : null;\n\tuseEffect( () => {\n\t\t// Focus the command palette input when mounting the modal.\n\t\tcommandMenuInput.current.focus();\n\t}, [] );\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/>\n\t);\n}\n\n/**\n * @ignore\n */\nexport function CommandMenu() {\n\tconst { registerShortcut } = useDispatch( keyboardShortcutsStore );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst { isOpen: paletteIsOpen, loadersLoading } = useSelect(\n\t\t( select ) => ( {\n\t\t\tisOpen: select( commandsStore ).isOpen(),\n\t\t\tloadersLoading: unlock( select( commandsStore ) ).isLoading(),\n\t\t} ),\n\t\t[]\n\t);\n\tconst { open, close } = useDispatch( commandsStore );\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 {React.KeyboardEventHandler} */\n\t\twithIgnoreIMEEvents( ( 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 ( paletteIsOpen ) {\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 closeAndReset = () => {\n\t\tsetSearch( '' );\n\t\tclose();\n\t};\n\n\tif ( ! paletteIsOpen ) {\n\t\treturn false;\n\t}\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\tsize=\"medium\"\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 } loop>\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/>\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 && ! loadersLoading && (\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{ ! search && <RecentGroup /> }\n\t\t\t\t\t\t{ ! search && <SuggestionsGroup /> }\n\t\t\t\t\t\t{ search && <ResultsGroup search={ search } /> }\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAyC;AACzC,kBAAiB;AAKjB,kBAAuC;AACvC,qBAMO;AACP,kBAAmB;AACnB,wBAKO;AACP,gCAGO;AACP,mBAAsD;AAKtD,mBAAuC;AACvC,y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;AAAA,MAErC,sDAAC,SAAI,WAAU,oCACd,uDAAC,uBAAQ,OAAQ,YAAa,MAAI,MACjC;AAAA,qDAAC,SAAI,WAAU,iCACd;AAAA;AAAA,YAAC;AAAA;AAAA,cACA,WAAU;AAAA,cACV,MAAO,aAAAI;AAAA;AAAA,UACR;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA;AAAA,cACA;AAAA;AAAA,UACD;AAAA,WACD;AAAA,QACA,6CAAC,oBAAQ,MAAR,EAAa,WAAQ,gBAAI,qBAAsB,GAC7C;AAAA,oBAAU,CAAE,kBACb,4CAAC,oBAAQ,OAAR,EACE,8BAAI,mBAAoB,GAC3B;AAAA,UAEC,CAAE,UAAU,4CAAC,eAAY;AAAA,UACzB,CAAE,UAAU,4CAAC,oBAAiB;AAAA,UAC9B,UAAU,4CAAC,gBAAa,QAAkB;AAAA,WAC7C;AAAA,SACD,GACD;AAAA;AAAA,EACD;AAEF;",
|
|
6
|
+
"names": ["componentsPrivateApis", "commandsStore", "HStack", "clsx", "keyboardShortcutsStore", "inputIcon"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/commands/src/components/use-recent-commands.js
|
|
20
|
+
var use_recent_commands_exports = {};
|
|
21
|
+
__export(use_recent_commands_exports, {
|
|
22
|
+
recordUsage: () => recordUsage,
|
|
23
|
+
useLoaderCollector: () => useLoaderCollector,
|
|
24
|
+
useRecentCommands: () => useRecentCommands
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(use_recent_commands_exports);
|
|
27
|
+
var import_data = require("@wordpress/data");
|
|
28
|
+
var import_preferences = require("@wordpress/preferences");
|
|
29
|
+
var import_element = require("@wordpress/element");
|
|
30
|
+
var import_store = require("../store/index.cjs");
|
|
31
|
+
var import_lock_unlock = require("../lock-unlock.cjs");
|
|
32
|
+
var MAX_RECENTLY_SAVED = 30;
|
|
33
|
+
var MAX_RECENTLY_DISPLAYED = 5;
|
|
34
|
+
var EMPTY_ARRAY = [];
|
|
35
|
+
var EMPTY_SET = /* @__PURE__ */ new Set();
|
|
36
|
+
function recordUsage(name) {
|
|
37
|
+
const current = (0, import_data.select)(import_preferences.store).get(
|
|
38
|
+
"core/commands",
|
|
39
|
+
"recentlyUsed"
|
|
40
|
+
) ?? [];
|
|
41
|
+
const next = [name, ...current.filter((n) => n !== name)].slice(
|
|
42
|
+
0,
|
|
43
|
+
MAX_RECENTLY_SAVED
|
|
44
|
+
);
|
|
45
|
+
(0, import_data.dispatch)(import_preferences.store).set("core/commands", "recentlyUsed", next);
|
|
46
|
+
}
|
|
47
|
+
function useLoaderCollector(hook, name, filterNames, onResolved) {
|
|
48
|
+
const { setLoaderLoading } = (0, import_lock_unlock.unlock)((0, import_data.useDispatch)(import_store.store));
|
|
49
|
+
const { isLoading: loading, commands = [] } = hook({ search: "" }) ?? {};
|
|
50
|
+
(0, import_element.useEffect)(() => {
|
|
51
|
+
setLoaderLoading(name, loading);
|
|
52
|
+
}, [setLoaderLoading, name, loading]);
|
|
53
|
+
const filtered = filterNames ? commands.filter((c) => filterNames.has(c.name)) : commands;
|
|
54
|
+
(0, import_element.useEffect)(() => {
|
|
55
|
+
onResolved(name, filtered);
|
|
56
|
+
}, [onResolved, name, filtered]);
|
|
57
|
+
(0, import_element.useEffect)(() => {
|
|
58
|
+
return () => onResolved(name, []);
|
|
59
|
+
}, [onResolved, name]);
|
|
60
|
+
}
|
|
61
|
+
function useRecentCommands() {
|
|
62
|
+
const {
|
|
63
|
+
contextualCommands,
|
|
64
|
+
staticCommands,
|
|
65
|
+
contextualLoaders,
|
|
66
|
+
staticLoaders,
|
|
67
|
+
recentlyUsedNames = EMPTY_ARRAY
|
|
68
|
+
} = (0, import_data.useSelect)((select) => {
|
|
69
|
+
const { getCommands, getCommandLoaders } = select(import_store.store);
|
|
70
|
+
return {
|
|
71
|
+
contextualCommands: getCommands(true),
|
|
72
|
+
staticCommands: getCommands(false),
|
|
73
|
+
contextualLoaders: getCommandLoaders(true),
|
|
74
|
+
staticLoaders: getCommandLoaders(false),
|
|
75
|
+
recentlyUsedNames: select(import_preferences.store).get(
|
|
76
|
+
"core/commands",
|
|
77
|
+
"recentlyUsed"
|
|
78
|
+
)
|
|
79
|
+
};
|
|
80
|
+
}, []);
|
|
81
|
+
const [resolvedMap, setResolvedMap] = (0, import_element.useState)(() => /* @__PURE__ */ new Map());
|
|
82
|
+
const onResolved = (0, import_element.useCallback)((loaderName, cmds) => {
|
|
83
|
+
setResolvedMap((prev) => {
|
|
84
|
+
const prevCmds = prev.get(loaderName);
|
|
85
|
+
if (prevCmds && prevCmds.length === cmds.length && prevCmds.every((c, i) => c.name === cmds[i].name)) {
|
|
86
|
+
return prev;
|
|
87
|
+
}
|
|
88
|
+
const next = new Map(prev);
|
|
89
|
+
next.set(loaderName, cmds);
|
|
90
|
+
return next;
|
|
91
|
+
});
|
|
92
|
+
}, []);
|
|
93
|
+
const { recentNames, recentSet } = (0, import_element.useMemo)(() => {
|
|
94
|
+
const names = recentlyUsedNames.slice(0, MAX_RECENTLY_DISPLAYED);
|
|
95
|
+
return { recentNames: names, recentSet: new Set(names) };
|
|
96
|
+
}, [recentlyUsedNames]);
|
|
97
|
+
if (!recentlyUsedNames.length) {
|
|
98
|
+
return {
|
|
99
|
+
commands: [],
|
|
100
|
+
loaders: [],
|
|
101
|
+
recentSet: EMPTY_SET,
|
|
102
|
+
onResolved
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const allStaticCommands = [...contextualCommands, ...staticCommands];
|
|
106
|
+
const loaders = [...contextualLoaders, ...staticLoaders];
|
|
107
|
+
const allByName = /* @__PURE__ */ new Map();
|
|
108
|
+
allStaticCommands.forEach((c) => allByName.set(c.name, c));
|
|
109
|
+
for (const cmds of resolvedMap.values()) {
|
|
110
|
+
cmds.forEach((c) => {
|
|
111
|
+
if (!allByName.has(c.name)) {
|
|
112
|
+
allByName.set(c.name, c);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const commands = recentNames.map((n) => allByName.get(n)).filter(Boolean);
|
|
117
|
+
return { commands, loaders, recentSet, onResolved };
|
|
118
|
+
}
|
|
119
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
120
|
+
0 && (module.exports = {
|
|
121
|
+
recordUsage,
|
|
122
|
+
useLoaderCollector,
|
|
123
|
+
useRecentCommands
|
|
124
|
+
});
|
|
125
|
+
//# sourceMappingURL=use-recent-commands.cjs.map
|