@wordpress/commands 1.41.1-next.v.202603161435.0 → 1.43.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 +8 -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
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/components/use-recent-commands.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseSelect,\n\tuseDispatch,\n\tselect as globalSelect,\n\tdispatch,\n} from '@wordpress/data';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport { useCallback, useEffect, useMemo, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\nconst MAX_RECENTLY_SAVED = 30;\nconst MAX_RECENTLY_DISPLAYED = 5;\nconst EMPTY_ARRAY = [];\nconst EMPTY_SET = new Set();\n\nexport function recordUsage( name ) {\n\tconst current =\n\t\tglobalSelect( preferencesStore ).get(\n\t\t\t'core/commands',\n\t\t\t'recentlyUsed'\n\t\t) ?? [];\n\tconst next = [ name, ...current.filter( ( n ) => n !== name ) ].slice(\n\t\t0,\n\t\tMAX_RECENTLY_SAVED\n\t);\n\tdispatch( preferencesStore ).set( 'core/commands', 'recentlyUsed', next );\n}\n\nexport function useLoaderCollector( hook, name, filterNames, onResolved ) {\n\tconst { setLoaderLoading } = unlock( useDispatch( commandsStore ) );\n\tconst { isLoading: loading, commands = [] } = hook( { search: '' } ) ?? {};\n\n\tuseEffect( () => {\n\t\tsetLoaderLoading( name, loading );\n\t}, [ setLoaderLoading, name, loading ] );\n\n\tconst filtered = filterNames\n\t\t? commands.filter( ( c ) => filterNames.has( c.name ) )\n\t\t: commands;\n\n\tuseEffect( () => {\n\t\tonResolved( name, filtered );\n\t}, [ onResolved, name, filtered ] );\n\n\t// Clear this loader's entries when it unmounts.\n\tuseEffect( () => {\n\t\treturn () => onResolved( name, [] );\n\t}, [ onResolved, name ] );\n}\n\nexport function useRecentCommands() {\n\tconst {\n\t\tcontextualCommands,\n\t\tstaticCommands,\n\t\tcontextualLoaders,\n\t\tstaticLoaders,\n\t\trecentlyUsedNames = EMPTY_ARRAY,\n\t} = useSelect( ( select ) => {\n\t\tconst { getCommands, getCommandLoaders } = select( commandsStore );\n\t\treturn {\n\t\t\tcontextualCommands: getCommands( true ),\n\t\t\tstaticCommands: getCommands( false ),\n\t\t\tcontextualLoaders: getCommandLoaders( true ),\n\t\t\tstaticLoaders: getCommandLoaders( false ),\n\t\t\trecentlyUsedNames: select( preferencesStore ).get(\n\t\t\t\t'core/commands',\n\t\t\t\t'recentlyUsed'\n\t\t\t),\n\t\t};\n\t}, [] );\n\n\tconst [ resolvedMap, setResolvedMap ] = useState( () => new Map() );\n\n\tconst onResolved = useCallback( ( loaderName, cmds ) => {\n\t\tsetResolvedMap( ( prev ) => {\n\t\t\tconst prevCmds = prev.get( loaderName );\n\t\t\tif (\n\t\t\t\tprevCmds &&\n\t\t\t\tprevCmds.length === cmds.length &&\n\t\t\t\tprevCmds.every( ( c, i ) => c.name === cmds[ i ].name )\n\t\t\t) {\n\t\t\t\treturn prev;\n\t\t\t}\n\t\t\tconst next = new Map( prev );\n\t\t\tnext.set( loaderName, cmds );\n\t\t\treturn next;\n\t\t} );\n\t}, [] );\n\n\tconst { recentNames, recentSet } = useMemo( () => {\n\t\tconst names = recentlyUsedNames.slice( 0, MAX_RECENTLY_DISPLAYED );\n\t\treturn { recentNames: names, recentSet: new Set( names ) };\n\t}, [ recentlyUsedNames ] );\n\n\tif ( ! recentlyUsedNames.length ) {\n\t\treturn {\n\t\t\tcommands: [],\n\t\t\tloaders: [],\n\t\t\trecentSet: EMPTY_SET,\n\t\t\tonResolved,\n\t\t};\n\t}\n\n\tconst allStaticCommands = [ ...contextualCommands, ...staticCommands ];\n\tconst loaders = [ ...contextualLoaders, ...staticLoaders ];\n\n\t// Merge static commands with loader-resolved commands.\n\tconst allByName = new Map();\n\tallStaticCommands.forEach( ( c ) => allByName.set( c.name, c ) );\n\tfor ( const cmds of resolvedMap.values() ) {\n\t\tcmds.forEach( ( c ) => {\n\t\t\tif ( ! allByName.has( c.name ) ) {\n\t\t\t\tallByName.set( c.name, c );\n\t\t\t}\n\t\t} );\n\t}\n\t// Return in recency order.\n\tconst commands = recentNames\n\t\t.map( ( n ) => allByName.get( n ) )\n\t\t.filter( Boolean );\n\n\treturn { commands, loaders, recentSet, onResolved };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;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,GAAG,aAAc;AAGzD,QAAM,YAAY,oBAAI,IAAI;AAC1B,oBAAkB,QAAS,CAAE,MAAO,UAAU,IAAK,EAAE,MAAM,CAAE,CAAE;AAC/D,aAAY,QAAQ,YAAY,OAAO,GAAI;AAC1C,SAAK,QAAS,CAAE,MAAO;AACtB,UAAK,CAAE,UAAU,IAAK,EAAE,IAAK,GAAI;AAChC,kBAAU,IAAK,EAAE,MAAM,CAAE;AAAA,MAC1B;AAAA,IACD,CAAE;AAAA,EACH;AAEA,QAAM,WAAW,YACf,IAAK,CAAE,MAAO,UAAU,IAAK,CAAE,CAAE,EACjC,OAAQ,OAAQ;AAElB,SAAO,EAAE,UAAU,SAAS,WAAW,WAAW;AACnD;",
|
|
6
|
+
"names": ["globalSelect", "preferencesStore", "commandsStore"]
|
|
7
|
+
}
|
package/build/store/index.cjs
CHANGED
|
@@ -37,6 +37,7 @@ var import_reducer = __toESM(require("./reducer.cjs"));
|
|
|
37
37
|
var actions = __toESM(require("./actions.cjs"));
|
|
38
38
|
var selectors = __toESM(require("./selectors.cjs"));
|
|
39
39
|
var privateActions = __toESM(require("./private-actions.cjs"));
|
|
40
|
+
var privateSelectors = __toESM(require("./private-selectors.cjs"));
|
|
40
41
|
var import_lock_unlock = require("../lock-unlock.cjs");
|
|
41
42
|
var STORE_NAME = "core/commands";
|
|
42
43
|
var store = (0, import_data.createReduxStore)(STORE_NAME, {
|
|
@@ -46,6 +47,7 @@ var store = (0, import_data.createReduxStore)(STORE_NAME, {
|
|
|
46
47
|
});
|
|
47
48
|
(0, import_data.register)(store);
|
|
48
49
|
(0, import_lock_unlock.unlock)(store).registerPrivateActions(privateActions);
|
|
50
|
+
(0, import_lock_unlock.unlock)(store).registerPrivateSelectors(privateSelectors);
|
|
49
51
|
// Annotate the CommonJS export names for ESM import in node:
|
|
50
52
|
0 && (module.exports = {
|
|
51
53
|
store
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport * as privateActions from './private-actions';\nimport { unlock } from '../lock-unlock';\n\nconst STORE_NAME = 'core/commands';\n\n/**\n * Store definition for the commands namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n *\n * @example\n * ```js\n * import { store as commandsStore } from '@wordpress/commands';\n * import { useDispatch } from '@wordpress/data';\n * ...\n * const { open: openCommandCenter } = useDispatch( commandsStore );\n * ```\n */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\nunlock( store ).registerPrivateActions( privateActions );\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA2C;AAK3C,qBAAoB;AACpB,cAAyB;AACzB,gBAA2B;AAC3B,qBAAgC;AAChC,yBAAuB;AAEvB,IAAM,aAAa;AAiBZ,IAAM,YAAQ,8BAAkB,YAAY;AAAA,EAClD,wBAAAA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAAA,IAEF,sBAAU,KAAM;AAAA,IAChB,2BAAQ,KAAM,EAAE,uBAAwB,cAAe;",
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport * as privateActions from './private-actions';\nimport * as privateSelectors from './private-selectors';\nimport { unlock } from '../lock-unlock';\n\nconst STORE_NAME = 'core/commands';\n\n/**\n * Store definition for the commands namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n *\n * @example\n * ```js\n * import { store as commandsStore } from '@wordpress/commands';\n * import { useDispatch } from '@wordpress/data';\n * ...\n * const { open: openCommandCenter } = useDispatch( commandsStore );\n * ```\n */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\nunlock( store ).registerPrivateActions( privateActions );\nunlock( store ).registerPrivateSelectors( privateSelectors );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA2C;AAK3C,qBAAoB;AACpB,cAAyB;AACzB,gBAA2B;AAC3B,qBAAgC;AAChC,uBAAkC;AAClC,yBAAuB;AAEvB,IAAM,aAAa;AAiBZ,IAAM,YAAQ,8BAAkB,YAAY;AAAA,EAClD,wBAAAA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAAA,IAEF,sBAAU,KAAM;AAAA,IAChB,2BAAQ,KAAM,EAAE,uBAAwB,cAAe;AAAA,IACvD,2BAAQ,KAAM,EAAE,yBAA0B,gBAAiB;",
|
|
6
6
|
"names": ["reducer"]
|
|
7
7
|
}
|
|
@@ -19,7 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// packages/commands/src/store/private-actions.js
|
|
20
20
|
var private_actions_exports = {};
|
|
21
21
|
__export(private_actions_exports, {
|
|
22
|
-
setContext: () => setContext
|
|
22
|
+
setContext: () => setContext,
|
|
23
|
+
setLoaderLoading: () => setLoaderLoading
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(private_actions_exports);
|
|
25
26
|
function setContext(context) {
|
|
@@ -28,8 +29,16 @@ function setContext(context) {
|
|
|
28
29
|
context
|
|
29
30
|
};
|
|
30
31
|
}
|
|
32
|
+
function setLoaderLoading(name, isLoading) {
|
|
33
|
+
return {
|
|
34
|
+
type: "SET_LOADER_LOADING",
|
|
35
|
+
name,
|
|
36
|
+
isLoading
|
|
37
|
+
};
|
|
38
|
+
}
|
|
31
39
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
40
|
0 && (module.exports = {
|
|
33
|
-
setContext
|
|
41
|
+
setContext,
|
|
42
|
+
setLoaderLoading
|
|
34
43
|
});
|
|
35
44
|
//# sourceMappingURL=private-actions.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/private-actions.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * Sets the active context.\n *\n * @param {string} context Context.\n *\n * @return {Object} action.\n */\nexport function setContext( context ) {\n\treturn {\n\t\ttype: 'SET_CONTEXT',\n\t\tcontext,\n\t};\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,WAAY,SAAU;AACrC,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;",
|
|
4
|
+
"sourcesContent": ["/**\n * Sets the active context.\n *\n * @param {string} context Context.\n *\n * @return {Object} action.\n */\nexport function setContext( context ) {\n\treturn {\n\t\ttype: 'SET_CONTEXT',\n\t\tcontext,\n\t};\n}\n\n/**\n * Sets whether a command loader is currently loading.\n *\n * @param {string} name Command loader name.\n * @param {boolean} isLoading Whether the loader is loading.\n *\n * @return {Object} action.\n */\nexport function setLoaderLoading( name, isLoading ) {\n\treturn {\n\t\ttype: 'SET_LOADER_LOADING',\n\t\tname,\n\t\tisLoading,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,WAAY,SAAU;AACrC,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;AAUO,SAAS,iBAAkB,MAAM,WAAY;AACnD,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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/store/private-selectors.js
|
|
20
|
+
var private_selectors_exports = {};
|
|
21
|
+
__export(private_selectors_exports, {
|
|
22
|
+
isLoading: () => isLoading
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(private_selectors_exports);
|
|
25
|
+
function isLoading(state) {
|
|
26
|
+
return Object.values(state.loaderStates).some(Boolean);
|
|
27
|
+
}
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
isLoading
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=private-selectors.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/store/private-selectors.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Returns whether any command loader is currently loading.\n *\n * @param {Object} state State tree.\n *\n * @return {boolean} Whether any loader is loading.\n */\nexport function isLoading( state ) {\n\treturn Object.values( state.loaderStates ).some( Boolean );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,UAAW,OAAQ;AAClC,SAAO,OAAO,OAAQ,MAAM,YAAa,EAAE,KAAM,OAAQ;AAC1D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/store/reducer.cjs
CHANGED
|
@@ -81,11 +81,22 @@ function context(state = "root", action) {
|
|
|
81
81
|
}
|
|
82
82
|
return state;
|
|
83
83
|
}
|
|
84
|
+
function loaderStates(state = {}, action) {
|
|
85
|
+
switch (action.type) {
|
|
86
|
+
case "SET_LOADER_LOADING":
|
|
87
|
+
return {
|
|
88
|
+
...state,
|
|
89
|
+
[action.name]: action.isLoading
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return state;
|
|
93
|
+
}
|
|
84
94
|
var reducer = (0, import_data.combineReducers)({
|
|
85
95
|
commands,
|
|
86
96
|
commandLoaders,
|
|
87
97
|
isOpen,
|
|
88
|
-
context
|
|
98
|
+
context,
|
|
99
|
+
loaderStates
|
|
89
100
|
});
|
|
90
101
|
var reducer_default = reducer;
|
|
91
102
|
//# sourceMappingURL=reducer.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/store/reducer.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Reducer returning the registered commands\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nfunction commands( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'REGISTER_COMMAND':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.name ]: {\n\t\t\t\t\tname: action.name,\n\t\t\t\t\tlabel: action.label,\n\t\t\t\t\tsearchLabel: action.searchLabel,\n\t\t\t\t\tcontext: action.context,\n\t\t\t\t\tcategory: action.category,\n\t\t\t\t\tcallback: action.callback,\n\t\t\t\t\ticon: action.icon,\n\t\t\t\t\tkeywords: action.keywords,\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'UNREGISTER_COMMAND': {\n\t\t\tconst { [ action.name ]: _, ...remainingState } = state;\n\t\t\treturn remainingState;\n\t\t}\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning the command loaders\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nfunction commandLoaders( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'REGISTER_COMMAND_LOADER':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.name ]: {\n\t\t\t\t\tname: action.name,\n\t\t\t\t\tcontext: action.context,\n\t\t\t\t\tcategory: action.category,\n\t\t\t\t\thook: action.hook,\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'UNREGISTER_COMMAND_LOADER': {\n\t\t\tconst { [ action.name ]: _, ...remainingState } = state;\n\t\t\treturn remainingState;\n\t\t}\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning the command palette open state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {boolean} Updated state.\n */\nfunction isOpen( state = false, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'OPEN':\n\t\t\treturn true;\n\t\tcase 'CLOSE':\n\t\t\treturn false;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning the command palette's active context.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {boolean} Updated state.\n */\nfunction context( state = 'root', action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_CONTEXT':\n\t\t\treturn action.context;\n\t}\n\n\treturn state;\n}\n\nconst reducer = combineReducers( {\n\tcommands,\n\tcommandLoaders,\n\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AC1C,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AACJ,aAAO,OAAO;AAAA,EAChB;AAEA,SAAO;AACR;AAEA,IAAM,cAAU,6BAAiB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAEF,IAAO,kBAAQ;",
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Reducer returning the registered commands\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nfunction commands( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'REGISTER_COMMAND':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.name ]: {\n\t\t\t\t\tname: action.name,\n\t\t\t\t\tlabel: action.label,\n\t\t\t\t\tsearchLabel: action.searchLabel,\n\t\t\t\t\tcontext: action.context,\n\t\t\t\t\tcategory: action.category,\n\t\t\t\t\tcallback: action.callback,\n\t\t\t\t\ticon: action.icon,\n\t\t\t\t\tkeywords: action.keywords,\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'UNREGISTER_COMMAND': {\n\t\t\tconst { [ action.name ]: _, ...remainingState } = state;\n\t\t\treturn remainingState;\n\t\t}\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning the command loaders\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nfunction commandLoaders( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'REGISTER_COMMAND_LOADER':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.name ]: {\n\t\t\t\t\tname: action.name,\n\t\t\t\t\tcontext: action.context,\n\t\t\t\t\tcategory: action.category,\n\t\t\t\t\thook: action.hook,\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'UNREGISTER_COMMAND_LOADER': {\n\t\t\tconst { [ action.name ]: _, ...remainingState } = state;\n\t\t\treturn remainingState;\n\t\t}\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning the command palette open state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {boolean} Updated state.\n */\nfunction isOpen( state = false, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'OPEN':\n\t\t\treturn true;\n\t\tcase 'CLOSE':\n\t\t\treturn false;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning the command palette's active context.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {boolean} Updated state.\n */\nfunction context( state = 'root', action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_CONTEXT':\n\t\t\treturn action.context;\n\t}\n\n\treturn state;\n}\n\nfunction loaderStates( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_LOADER_LOADING':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.name ]: action.isLoading,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\nconst reducer = combineReducers( {\n\tcommands,\n\tcommandLoaders,\n\tisOpen,\n\tcontext,\n\tloaderStates,\n} );\n\nexport default reducer;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAgC;AAUhC,SAAS,SAAU,QAAQ,CAAC,GAAG,QAAS;AACvC,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AACJ,aAAO;AAAA,QACN,GAAG;AAAA,QACH,CAAE,OAAO,IAAK,GAAG;AAAA,UAChB,MAAM,OAAO;AAAA,UACb,OAAO,OAAO;AAAA,UACd,aAAa,OAAO;AAAA,UACpB,SAAS,OAAO;AAAA,UAChB,UAAU,OAAO;AAAA,UACjB,UAAU,OAAO;AAAA,UACjB,MAAM,OAAO;AAAA,UACb,UAAU,OAAO;AAAA,QAClB;AAAA,MACD;AAAA,IACD,KAAK,sBAAsB;AAC1B,YAAM,EAAE,CAAE,OAAO,IAAK,GAAG,G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
11
9
|
isValidElement,
|
|
12
10
|
Component
|
|
13
11
|
} from "@wordpress/element";
|
|
@@ -25,8 +23,14 @@ import {
|
|
|
25
23
|
import { Icon, search as inputIcon, arrowRight } from "@wordpress/icons";
|
|
26
24
|
import { store as commandsStore } from "../store/index.mjs";
|
|
27
25
|
import { unlock } from "../lock-unlock.mjs";
|
|
26
|
+
import {
|
|
27
|
+
recordUsage,
|
|
28
|
+
useLoaderCollector,
|
|
29
|
+
useRecentCommands
|
|
30
|
+
} from "./use-recent-commands.mjs";
|
|
28
31
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
29
32
|
var { withIgnoreIMEEvents } = unlock(componentsPrivateApis);
|
|
33
|
+
var ITEM_ID_PREFIX = "command-palette-item-";
|
|
30
34
|
var inputLabel = __("Search commands and settings");
|
|
31
35
|
var CATEGORY_ICONS = {
|
|
32
36
|
view: arrowRight
|
|
@@ -41,68 +45,66 @@ var CATEGORY_LABELS = {
|
|
|
41
45
|
function isValidIcon(icon) {
|
|
42
46
|
return !!icon && (typeof icon === "string" || isValidElement(icon) || typeof icon === "function" || icon instanceof Component);
|
|
43
47
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
function CommandItem({ command, search, category, valuePrefix }) {
|
|
49
|
+
const { close } = useDispatch(commandsStore);
|
|
50
|
+
const commandCategory = category ?? command.category;
|
|
51
|
+
const label = command.searchLabel ?? command.label;
|
|
52
|
+
const value = valuePrefix ? `${valuePrefix}${command.name}` : label;
|
|
53
|
+
return /* @__PURE__ */ jsx(
|
|
54
|
+
Command.Item,
|
|
55
|
+
{
|
|
56
|
+
id: `${ITEM_ID_PREFIX}${value.toLowerCase()}`,
|
|
57
|
+
value,
|
|
58
|
+
keywords: valuePrefix ? [...command.keywords ?? [], label] : command.keywords,
|
|
59
|
+
onSelect: () => {
|
|
60
|
+
recordUsage(command.name);
|
|
61
|
+
command.callback({ close });
|
|
62
|
+
},
|
|
63
|
+
children: /* @__PURE__ */ jsxs(
|
|
64
|
+
HStack,
|
|
65
|
+
{
|
|
66
|
+
alignment: "left",
|
|
67
|
+
className: clsx("commands-command-menu__item", {
|
|
68
|
+
"has-icon": CATEGORY_ICONS[commandCategory] || command.icon
|
|
69
|
+
}),
|
|
70
|
+
children: [
|
|
71
|
+
CATEGORY_ICONS[commandCategory] ? /* @__PURE__ */ jsx(Icon, { icon: CATEGORY_ICONS[commandCategory] }) : isValidIcon(command.icon) && /* @__PURE__ */ jsx(Icon, { icon: command.icon }),
|
|
72
|
+
/* @__PURE__ */ jsx("span", { className: "commands-command-menu__item-label", children: /* @__PURE__ */ jsx(
|
|
73
|
+
TextHighlight,
|
|
74
|
+
{
|
|
75
|
+
text: command.label,
|
|
76
|
+
highlight: search
|
|
77
|
+
}
|
|
78
|
+
) }),
|
|
79
|
+
CATEGORY_LABELS[commandCategory] && /* @__PURE__ */ jsx("span", { className: "commands-command-menu__item-category", children: CATEGORY_LABELS[commandCategory] })
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
},
|
|
84
|
+
command.name
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
function CommandMenuLoader({ name, search, hook, category, valuePrefix }) {
|
|
88
|
+
const { setLoaderLoading } = unlock(useDispatch(commandsStore));
|
|
89
|
+
const { isLoading: loading, commands = [] } = hook({ search }) ?? {};
|
|
53
90
|
useEffect(() => {
|
|
54
|
-
|
|
55
|
-
}, [
|
|
91
|
+
setLoaderLoading(name, loading);
|
|
92
|
+
}, [setLoaderLoading, name, loading]);
|
|
56
93
|
if (!commands.length) {
|
|
57
94
|
return null;
|
|
58
95
|
}
|
|
59
|
-
return /* @__PURE__ */ jsx(Fragment, { children: commands.map((command) =>
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
HStack,
|
|
70
|
-
{
|
|
71
|
-
alignment: "left",
|
|
72
|
-
className: clsx("commands-command-menu__item", {
|
|
73
|
-
"has-icon": CATEGORY_ICONS[commandCategory] || command.icon
|
|
74
|
-
}),
|
|
75
|
-
children: [
|
|
76
|
-
CATEGORY_ICONS[commandCategory] && /* @__PURE__ */ jsx(
|
|
77
|
-
Icon,
|
|
78
|
-
{
|
|
79
|
-
icon: CATEGORY_ICONS[commandCategory]
|
|
80
|
-
}
|
|
81
|
-
),
|
|
82
|
-
!CATEGORY_ICONS[commandCategory] && isValidIcon(command.icon) && /* @__PURE__ */ jsx(Icon, { icon: command.icon }),
|
|
83
|
-
/* @__PURE__ */ jsx("span", { className: "commands-command-menu__item-label", children: /* @__PURE__ */ jsx(
|
|
84
|
-
TextHighlight,
|
|
85
|
-
{
|
|
86
|
-
text: command.label,
|
|
87
|
-
highlight: search
|
|
88
|
-
}
|
|
89
|
-
) }),
|
|
90
|
-
CATEGORY_LABELS[commandCategory] && /* @__PURE__ */ jsx("span", { className: "commands-command-menu__item-category", children: CATEGORY_LABELS[commandCategory] })
|
|
91
|
-
]
|
|
92
|
-
}
|
|
93
|
-
)
|
|
94
|
-
},
|
|
95
|
-
command.name
|
|
96
|
-
);
|
|
97
|
-
}) });
|
|
96
|
+
return /* @__PURE__ */ jsx(Fragment, { children: commands.map((command) => /* @__PURE__ */ jsx(
|
|
97
|
+
CommandItem,
|
|
98
|
+
{
|
|
99
|
+
command,
|
|
100
|
+
search,
|
|
101
|
+
category: command.category ?? category,
|
|
102
|
+
valuePrefix
|
|
103
|
+
},
|
|
104
|
+
command.name
|
|
105
|
+
)) });
|
|
98
106
|
}
|
|
99
|
-
function CommandMenuLoaderWrapper({
|
|
100
|
-
hook,
|
|
101
|
-
search,
|
|
102
|
-
setLoader,
|
|
103
|
-
close,
|
|
104
|
-
category
|
|
105
|
-
}) {
|
|
107
|
+
function CommandMenuLoaderWrapper({ hook, ...props }) {
|
|
106
108
|
const currentLoaderRef = useRef(hook);
|
|
107
109
|
const [key, setKey] = useState(0);
|
|
108
110
|
useEffect(() => {
|
|
@@ -115,86 +117,112 @@ function CommandMenuLoaderWrapper({
|
|
|
115
117
|
CommandMenuLoader,
|
|
116
118
|
{
|
|
117
119
|
hook: currentLoaderRef.current,
|
|
118
|
-
|
|
119
|
-
setLoader,
|
|
120
|
-
close,
|
|
121
|
-
category
|
|
120
|
+
...props
|
|
122
121
|
},
|
|
123
122
|
key
|
|
124
123
|
);
|
|
125
124
|
}
|
|
126
|
-
function
|
|
127
|
-
|
|
128
|
-
(select) => {
|
|
129
|
-
const { getCommands, getCommandLoaders } = select(commandsStore);
|
|
130
|
-
return {
|
|
131
|
-
commands: getCommands(isContextual),
|
|
132
|
-
loaders: getCommandLoaders(isContextual)
|
|
133
|
-
};
|
|
134
|
-
},
|
|
135
|
-
[isContextual]
|
|
136
|
-
);
|
|
137
|
-
if (!commands.length && !loaders.length) {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
return /* @__PURE__ */ jsxs(Command.Group, { children: [
|
|
125
|
+
function CommandList({ search, commands, loaders, valuePrefix }) {
|
|
126
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
141
127
|
commands.map((command) => /* @__PURE__ */ jsx(
|
|
142
|
-
|
|
128
|
+
CommandItem,
|
|
143
129
|
{
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
id: command.name,
|
|
148
|
-
children: /* @__PURE__ */ jsxs(
|
|
149
|
-
HStack,
|
|
150
|
-
{
|
|
151
|
-
alignment: "left",
|
|
152
|
-
className: clsx("commands-command-menu__item", {
|
|
153
|
-
"has-icon": CATEGORY_ICONS[command.category] || command.icon
|
|
154
|
-
}),
|
|
155
|
-
children: [
|
|
156
|
-
CATEGORY_ICONS[command.category] ? /* @__PURE__ */ jsx(Icon, { icon: CATEGORY_ICONS[command.category] }) : command.icon && /* @__PURE__ */ jsx(Icon, { icon: command.icon }),
|
|
157
|
-
/* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(
|
|
158
|
-
TextHighlight,
|
|
159
|
-
{
|
|
160
|
-
text: command.label,
|
|
161
|
-
highlight: search
|
|
162
|
-
}
|
|
163
|
-
) }),
|
|
164
|
-
CATEGORY_LABELS[command.category] && /* @__PURE__ */ jsx("span", { className: "commands-command-menu__item-category", children: CATEGORY_LABELS[command.category] })
|
|
165
|
-
]
|
|
166
|
-
}
|
|
167
|
-
)
|
|
130
|
+
command,
|
|
131
|
+
search,
|
|
132
|
+
valuePrefix
|
|
168
133
|
},
|
|
169
134
|
command.name
|
|
170
135
|
)),
|
|
171
136
|
loaders.map((loader) => /* @__PURE__ */ jsx(
|
|
172
137
|
CommandMenuLoaderWrapper,
|
|
173
138
|
{
|
|
174
|
-
|
|
139
|
+
name: loader.name,
|
|
175
140
|
search,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
141
|
+
hook: loader.hook,
|
|
142
|
+
category: loader.category,
|
|
143
|
+
valuePrefix
|
|
179
144
|
},
|
|
180
145
|
loader.name
|
|
181
146
|
))
|
|
182
147
|
] });
|
|
183
148
|
}
|
|
184
|
-
function
|
|
149
|
+
function RecentLoaderRunner({ hook, name, filterNames, onResolved }) {
|
|
150
|
+
useLoaderCollector(hook, name, filterNames, onResolved);
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
function RecentGroup() {
|
|
154
|
+
const { commands, loaders, recentSet, onResolved } = useRecentCommands();
|
|
155
|
+
if (!commands.length && !loaders.length) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
return /* @__PURE__ */ jsxs(Command.Group, { heading: __("Recent"), children: [
|
|
159
|
+
loaders.map((loader) => /* @__PURE__ */ jsx(
|
|
160
|
+
RecentLoaderRunner,
|
|
161
|
+
{
|
|
162
|
+
name: loader.name,
|
|
163
|
+
hook: loader.hook,
|
|
164
|
+
filterNames: recentSet,
|
|
165
|
+
onResolved
|
|
166
|
+
},
|
|
167
|
+
loader.name
|
|
168
|
+
)),
|
|
169
|
+
commands.map((command) => /* @__PURE__ */ jsx(
|
|
170
|
+
CommandItem,
|
|
171
|
+
{
|
|
172
|
+
command,
|
|
173
|
+
search: "",
|
|
174
|
+
valuePrefix: "recent-"
|
|
175
|
+
},
|
|
176
|
+
command.name
|
|
177
|
+
))
|
|
178
|
+
] });
|
|
179
|
+
}
|
|
180
|
+
function SuggestionsGroup() {
|
|
181
|
+
const { commands, loaders } = useSelect((select) => {
|
|
182
|
+
const { getCommands, getCommandLoaders } = select(commandsStore);
|
|
183
|
+
return {
|
|
184
|
+
commands: getCommands(true),
|
|
185
|
+
loaders: getCommandLoaders(true)
|
|
186
|
+
};
|
|
187
|
+
}, []);
|
|
188
|
+
return /* @__PURE__ */ jsx(Command.Group, { heading: __("Suggestions"), children: /* @__PURE__ */ jsx(CommandList, { search: "", commands, loaders }) });
|
|
189
|
+
}
|
|
190
|
+
function ResultsGroup({ search }) {
|
|
191
|
+
const { commands, contextualCommands, loaders, contextualLoaders } = useSelect((select) => {
|
|
192
|
+
const { getCommands, getCommandLoaders } = select(commandsStore);
|
|
193
|
+
return {
|
|
194
|
+
commands: getCommands(false),
|
|
195
|
+
contextualCommands: getCommands(true),
|
|
196
|
+
loaders: getCommandLoaders(false),
|
|
197
|
+
contextualLoaders: getCommandLoaders(true)
|
|
198
|
+
};
|
|
199
|
+
}, []);
|
|
200
|
+
return /* @__PURE__ */ jsxs(Command.Group, { heading: __("Results"), children: [
|
|
201
|
+
/* @__PURE__ */ jsx(
|
|
202
|
+
CommandList,
|
|
203
|
+
{
|
|
204
|
+
search,
|
|
205
|
+
commands,
|
|
206
|
+
loaders
|
|
207
|
+
}
|
|
208
|
+
),
|
|
209
|
+
/* @__PURE__ */ jsx(
|
|
210
|
+
CommandList,
|
|
211
|
+
{
|
|
212
|
+
search,
|
|
213
|
+
commands: contextualCommands,
|
|
214
|
+
loaders: contextualLoaders
|
|
215
|
+
}
|
|
216
|
+
)
|
|
217
|
+
] });
|
|
218
|
+
}
|
|
219
|
+
function CommandInput({ search, setSearch }) {
|
|
185
220
|
const commandMenuInput = useRef();
|
|
186
221
|
const _value = useCommandState((state) => state.value);
|
|
187
|
-
const selectedItemId =
|
|
188
|
-
const item = document.querySelector(
|
|
189
|
-
`[cmdk-item=""][data-value="${_value}"]`
|
|
190
|
-
);
|
|
191
|
-
return item?.getAttribute("id");
|
|
192
|
-
}, [_value]);
|
|
222
|
+
const selectedItemId = _value ? `${ITEM_ID_PREFIX}${_value}` : null;
|
|
193
223
|
useEffect(() => {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
}, [isOpen]);
|
|
224
|
+
commandMenuInput.current.focus();
|
|
225
|
+
}, []);
|
|
198
226
|
return /* @__PURE__ */ jsx(
|
|
199
227
|
Command.Input,
|
|
200
228
|
{
|
|
@@ -209,12 +237,14 @@ function CommandInput({ isOpen, search, setSearch }) {
|
|
|
209
237
|
function CommandMenu() {
|
|
210
238
|
const { registerShortcut } = useDispatch(keyboardShortcutsStore);
|
|
211
239
|
const [search, setSearch] = useState("");
|
|
212
|
-
const isOpen = useSelect(
|
|
213
|
-
(select) =>
|
|
240
|
+
const { isOpen: paletteIsOpen, loadersLoading } = useSelect(
|
|
241
|
+
(select) => ({
|
|
242
|
+
isOpen: select(commandsStore).isOpen(),
|
|
243
|
+
loadersLoading: unlock(select(commandsStore)).isLoading()
|
|
244
|
+
}),
|
|
214
245
|
[]
|
|
215
246
|
);
|
|
216
247
|
const { open, close } = useDispatch(commandsStore);
|
|
217
|
-
const [loaders, setLoaders] = useState({});
|
|
218
248
|
useEffect(() => {
|
|
219
249
|
registerShortcut({
|
|
220
250
|
name: "core/commands",
|
|
@@ -234,7 +264,7 @@ function CommandMenu() {
|
|
|
234
264
|
return;
|
|
235
265
|
}
|
|
236
266
|
event.preventDefault();
|
|
237
|
-
if (
|
|
267
|
+
if (paletteIsOpen) {
|
|
238
268
|
close();
|
|
239
269
|
} else {
|
|
240
270
|
open();
|
|
@@ -244,21 +274,13 @@ function CommandMenu() {
|
|
|
244
274
|
bindGlobal: true
|
|
245
275
|
}
|
|
246
276
|
);
|
|
247
|
-
const setLoader = useCallback(
|
|
248
|
-
(name, value) => setLoaders((current) => ({
|
|
249
|
-
...current,
|
|
250
|
-
[name]: value
|
|
251
|
-
})),
|
|
252
|
-
[]
|
|
253
|
-
);
|
|
254
277
|
const closeAndReset = () => {
|
|
255
278
|
setSearch("");
|
|
256
279
|
close();
|
|
257
280
|
};
|
|
258
|
-
if (!
|
|
281
|
+
if (!paletteIsOpen) {
|
|
259
282
|
return false;
|
|
260
283
|
}
|
|
261
|
-
const isLoading = Object.values(loaders).some(Boolean);
|
|
262
284
|
return /* @__PURE__ */ jsx(
|
|
263
285
|
Modal,
|
|
264
286
|
{
|
|
@@ -266,8 +288,9 @@ function CommandMenu() {
|
|
|
266
288
|
overlayClassName: "commands-command-menu__overlay",
|
|
267
289
|
onRequestClose: closeAndReset,
|
|
268
290
|
__experimentalHideHeader: true,
|
|
291
|
+
size: "medium",
|
|
269
292
|
contentLabel: __("Command palette"),
|
|
270
|
-
children: /* @__PURE__ */ jsx("div", { className: "commands-command-menu__container", children: /* @__PURE__ */ jsxs(Command, { label: inputLabel, children: [
|
|
293
|
+
children: /* @__PURE__ */ jsx("div", { className: "commands-command-menu__container", children: /* @__PURE__ */ jsxs(Command, { label: inputLabel, loop: true, children: [
|
|
271
294
|
/* @__PURE__ */ jsxs("div", { className: "commands-command-menu__header", children: [
|
|
272
295
|
/* @__PURE__ */ jsx(
|
|
273
296
|
Icon,
|
|
@@ -280,30 +303,15 @@ function CommandMenu() {
|
|
|
280
303
|
CommandInput,
|
|
281
304
|
{
|
|
282
305
|
search,
|
|
283
|
-
setSearch
|
|
284
|
-
isOpen
|
|
306
|
+
setSearch
|
|
285
307
|
}
|
|
286
308
|
)
|
|
287
309
|
] }),
|
|
288
310
|
/* @__PURE__ */ jsxs(Command.List, { label: __("Command suggestions"), children: [
|
|
289
|
-
search && !
|
|
290
|
-
/* @__PURE__ */ jsx(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
search,
|
|
294
|
-
setLoader,
|
|
295
|
-
close: closeAndReset,
|
|
296
|
-
isContextual: true
|
|
297
|
-
}
|
|
298
|
-
),
|
|
299
|
-
search && /* @__PURE__ */ jsx(
|
|
300
|
-
CommandMenuGroup,
|
|
301
|
-
{
|
|
302
|
-
search,
|
|
303
|
-
setLoader,
|
|
304
|
-
close: closeAndReset
|
|
305
|
-
}
|
|
306
|
-
)
|
|
311
|
+
search && !loadersLoading && /* @__PURE__ */ jsx(Command.Empty, { children: __("No results found.") }),
|
|
312
|
+
!search && /* @__PURE__ */ jsx(RecentGroup, {}),
|
|
313
|
+
!search && /* @__PURE__ */ jsx(SuggestionsGroup, {}),
|
|
314
|
+
search && /* @__PURE__ */ jsx(ResultsGroup, { search })
|
|
307
315
|
] })
|
|
308
316
|
] }) })
|
|
309
317
|
}
|
|
@@ -311,8 +319,6 @@ function CommandMenu() {
|
|
|
311
319
|
}
|
|
312
320
|
export {
|
|
313
321
|
CommandMenu,
|
|
314
|
-
CommandMenuGroup,
|
|
315
|
-
CommandMenuLoaderWrapper,
|
|
316
322
|
isValidIcon
|
|
317
323
|
};
|
|
318
324
|
//# sourceMappingURL=command-menu.mjs.map
|