@wordpress/commands 1.53.0 → 1.54.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 +7 -0
- package/README.md +2 -0
- package/build/components/command-menu.cjs +4 -3
- package/build/components/command-menu.cjs.map +2 -2
- package/build-module/components/command-menu.mjs +4 -3
- package/build-module/components/command-menu.mjs.map +2 -2
- package/package.json +13 -13
- package/src/components/command-menu.js +7 -13
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 1.54.0 (2026-08-26)
|
|
6
|
+
|
|
7
|
+
### Enhancements
|
|
8
|
+
|
|
9
|
+
- Command Palette: Treat the per-category icon as a fallback used only when a command passes no `icon`, instead of an override that discards the command's own icon ([#81787](https://github.com/WordPress/gutenberg/pull/81787)).
|
|
10
|
+
|
|
5
11
|
## 1.53.0 (2026-08-12)
|
|
6
12
|
|
|
7
13
|
### Internal
|
|
@@ -52,6 +58,7 @@
|
|
|
52
58
|
## 1.41.0 (2026-03-04)
|
|
53
59
|
|
|
54
60
|
## 1.40.0 (2026-02-18)
|
|
61
|
+
|
|
55
62
|
- Add `category` property to command config, used to visually differentiate commands in the Command Palette.
|
|
56
63
|
|
|
57
64
|
## 1.39.0 (2026-01-29)
|
package/README.md
CHANGED
|
@@ -49,6 +49,8 @@ Each command can be assigned a `category` that describes what kind of action it
|
|
|
49
49
|
|
|
50
50
|
If no `category` is specified, the command will have `action` set. If an invalid value is provided, a warning is emitted in development mode and the category defaults to `action`.
|
|
51
51
|
|
|
52
|
+
A category can also supply a fallback icon, used when the command passes no `icon` of its own: `view` falls back to an arrow, so that navigating somewhere reads the same way throughout the palette. Commands in that category are expected to rely on the fallback rather than pass an icon, unless their own icon says something the arrow cannot, such as opening a new tab.
|
|
53
|
+
|
|
52
54
|
## WordPress Data API
|
|
53
55
|
|
|
54
56
|
The Command Palette also offers a number of [selectors and actions](https://developer.wordpress.org/block-editor/reference-guides/data/data-core-commands/) to manipulate its state, which include:
|
|
@@ -48,7 +48,7 @@ var import_use_recent_commands = require("./use-recent-commands.cjs");
|
|
|
48
48
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
49
49
|
var ITEM_ID_PREFIX = "command-palette-item-";
|
|
50
50
|
var inputLabel = (0, import_i18n.__)("Search commands and settings");
|
|
51
|
-
var
|
|
51
|
+
var CATEGORY_FALLBACK_ICONS = {
|
|
52
52
|
view: import_icons.arrowRight
|
|
53
53
|
};
|
|
54
54
|
var CATEGORY_LABELS = {
|
|
@@ -64,6 +64,7 @@ function isValidIcon(icon) {
|
|
|
64
64
|
function CommandItem({ command, search, category, valuePrefix }) {
|
|
65
65
|
const { close } = (0, import_data.useDispatch)(import_store.store);
|
|
66
66
|
const commandCategory = category ?? command.category;
|
|
67
|
+
const icon = command.icon ?? CATEGORY_FALLBACK_ICONS[commandCategory];
|
|
67
68
|
const label = command.searchLabel ?? command.label;
|
|
68
69
|
const value = valuePrefix ? `${valuePrefix}${command.name}` : label;
|
|
69
70
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -81,10 +82,10 @@ function CommandItem({ command, search, category, valuePrefix }) {
|
|
|
81
82
|
{
|
|
82
83
|
alignment: "left",
|
|
83
84
|
className: (0, import_clsx.default)("commands-command-menu__item", {
|
|
84
|
-
"has-icon":
|
|
85
|
+
"has-icon": !!icon
|
|
85
86
|
}),
|
|
86
87
|
children: [
|
|
87
|
-
|
|
88
|
+
isValidIcon(icon) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.Icon, { icon }),
|
|
88
89
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "commands-command-menu__item-label", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
89
90
|
import_components.TextHighlight,
|
|
90
91
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/components/command-menu.js"],
|
|
4
|
-
"sourcesContent": ["import { Command, useCommandState } from 'cmdk';\nimport clsx from 'clsx';\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} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { withIgnoreIMEEvents } from '@wordpress/keycodes';\nimport { Icon, search as inputIcon, arrowRight } from '@wordpress/icons';\nimport { store as commandsStore } from '../store';\nimport { unlock } from '../lock-unlock';\nimport {\n\trecordUsage,\n\tuseLoaderCollector,\n\tuseRecentCommands,\n} from './use-recent-commands';\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;AAAA,kBAAyC;AACzC,kBAAiB;AACjB,kBAAuC;AACvC,qBAMO;AACP,kBAAmB;AACnB,wBAIO;AACP,gCAGO;AACP,sBAAoC;AACpC,mBAAsD;AACtD,mBAAuC;AACvC,yBAAuB;AACvB,iCAIO;
|
|
4
|
+
"sourcesContent": ["import { Command, useCommandState } from 'cmdk';\nimport clsx from 'clsx';\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} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { withIgnoreIMEEvents } from '@wordpress/keycodes';\nimport { Icon, search as inputIcon, arrowRight } from '@wordpress/icons';\nimport { store as commandsStore } from '../store';\nimport { unlock } from '../lock-unlock';\nimport {\n\trecordUsage,\n\tuseLoaderCollector,\n\tuseRecentCommands,\n} from './use-recent-commands';\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 * Fallback icons per command category, used when a command provides no icon of\n * its own. Navigating somewhere reads the same way across the palette, so `view`\n * commands are expected to rely on this rather than pass an icon.\n */\nconst CATEGORY_FALLBACK_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 icon = command.icon ?? CATEGORY_FALLBACK_ICONS[ commandCategory ];\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': !! icon,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ isValidIcon( icon ) && <Icon icon={ icon } /> }\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;AAAA,kBAAyC;AACzC,kBAAiB;AACjB,kBAAuC;AACvC,qBAMO;AACP,kBAAmB;AACnB,wBAIO;AACP,gCAGO;AACP,sBAAoC;AACpC,mBAAsD;AACtD,mBAAuC;AACvC,yBAAuB;AACvB,iCAIO;AAmEJ;AAhEH,IAAM,iBAAiB;AACvB,IAAM,iBAAa,gBAAI,8BAA+B;AAOtD,IAAM,0BAA0B;AAAA,EAC/B,MAAM;AACP;AAKA,IAAM,kBAAkB;AAAA,EACvB,aAAS,gBAAI,SAAU;AAAA,EACvB,UAAM,gBAAI,MAAO;AAAA,EACjB,UAAM,gBAAI,MAAO;AAAA,EACjB,YAAQ,gBAAI,QAAS;AAAA,EACrB,cAAU,gBAAI,UAAW;AAC1B;AAYO,SAAS,YAAa,MAAO;AACnC,SACC,CAAC,CAAE,SACD,OAAO,SAAS,gBACjB,+BAAgB,IAAK,KACrB,OAAO,SAAS,cAChB,gBAAgB;AAEnB;AAEA,SAAS,YAAa,EAAE,SAAS,QAAQ,UAAU,YAAY,GAAI;A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"HStack", "clsx", "keyboardShortcutsStore", "inputIcon"]
|
|
7
7
|
}
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
32
32
|
var ITEM_ID_PREFIX = "command-palette-item-";
|
|
33
33
|
var inputLabel = __("Search commands and settings");
|
|
34
|
-
var
|
|
34
|
+
var CATEGORY_FALLBACK_ICONS = {
|
|
35
35
|
view: arrowRight
|
|
36
36
|
};
|
|
37
37
|
var CATEGORY_LABELS = {
|
|
@@ -47,6 +47,7 @@ function isValidIcon(icon) {
|
|
|
47
47
|
function CommandItem({ command, search, category, valuePrefix }) {
|
|
48
48
|
const { close } = useDispatch(commandsStore);
|
|
49
49
|
const commandCategory = category ?? command.category;
|
|
50
|
+
const icon = command.icon ?? CATEGORY_FALLBACK_ICONS[commandCategory];
|
|
50
51
|
const label = command.searchLabel ?? command.label;
|
|
51
52
|
const value = valuePrefix ? `${valuePrefix}${command.name}` : label;
|
|
52
53
|
return /* @__PURE__ */ jsx(
|
|
@@ -64,10 +65,10 @@ function CommandItem({ command, search, category, valuePrefix }) {
|
|
|
64
65
|
{
|
|
65
66
|
alignment: "left",
|
|
66
67
|
className: clsx("commands-command-menu__item", {
|
|
67
|
-
"has-icon":
|
|
68
|
+
"has-icon": !!icon
|
|
68
69
|
}),
|
|
69
70
|
children: [
|
|
70
|
-
|
|
71
|
+
isValidIcon(icon) && /* @__PURE__ */ jsx(Icon, { icon }),
|
|
71
72
|
/* @__PURE__ */ jsx("span", { className: "commands-command-menu__item-label", children: /* @__PURE__ */ jsx(
|
|
72
73
|
TextHighlight,
|
|
73
74
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/components/command-menu.js"],
|
|
4
|
-
"sourcesContent": ["import { Command, useCommandState } from 'cmdk';\nimport clsx from 'clsx';\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} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { withIgnoreIMEEvents } from '@wordpress/keycodes';\nimport { Icon, search as inputIcon, arrowRight } from '@wordpress/icons';\nimport { store as commandsStore } from '../store';\nimport { unlock } from '../lock-unlock';\nimport {\n\trecordUsage,\n\tuseLoaderCollector,\n\tuseRecentCommands,\n} from './use-recent-commands';\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,SAAS,SAAS,uBAAuB;AACzC,OAAO,UAAU;AACjB,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,2BAA2B;AACpC,SAAS,MAAM,UAAU,WAAW,kBAAkB;AACtD,SAAS,SAAS,qBAAqB;AACvC,SAAS,cAAc;AACvB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;
|
|
4
|
+
"sourcesContent": ["import { Command, useCommandState } from 'cmdk';\nimport clsx from 'clsx';\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} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { withIgnoreIMEEvents } from '@wordpress/keycodes';\nimport { Icon, search as inputIcon, arrowRight } from '@wordpress/icons';\nimport { store as commandsStore } from '../store';\nimport { unlock } from '../lock-unlock';\nimport {\n\trecordUsage,\n\tuseLoaderCollector,\n\tuseRecentCommands,\n} from './use-recent-commands';\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 * Fallback icons per command category, used when a command provides no icon of\n * its own. Navigating somewhere reads the same way across the palette, so `view`\n * commands are expected to rely on this rather than pass an icon.\n */\nconst CATEGORY_FALLBACK_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 icon = command.icon ?? CATEGORY_FALLBACK_ICONS[ commandCategory ];\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': !! icon,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ isValidIcon( icon ) && <Icon icon={ icon } /> }\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,SAAS,SAAS,uBAAuB;AACzC,OAAO,UAAU;AACjB,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,2BAA2B;AACpC,SAAS,MAAM,UAAU,WAAW,kBAAkB;AACtD,SAAS,SAAS,qBAAqB;AACvC,SAAS,cAAc;AACvB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAmEJ,SAmCD,UA7B2B,KAN1B;AAhEH,IAAM,iBAAiB;AACvB,IAAM,aAAa,GAAI,8BAA+B;AAOtD,IAAM,0BAA0B;AAAA,EAC/B,MAAM;AACP;AAKA,IAAM,kBAAkB;AAAA,EACvB,SAAS,GAAI,SAAU;AAAA,EACvB,MAAM,GAAI,MAAO;AAAA,EACjB,MAAM,GAAI,MAAO;AAAA,EACjB,QAAQ,GAAI,QAAS;AAA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AAkB;AAAA,WAC7C;AAAA,SACD,GACD;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/commands",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.54.0",
|
|
4
4
|
"description": "Handles the commands menu.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -43,17 +43,17 @@
|
|
|
43
43
|
},
|
|
44
44
|
"wpScript": true,
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@wordpress/base-styles": "^
|
|
47
|
-
"@wordpress/components": "^
|
|
48
|
-
"@wordpress/data": "^10.
|
|
49
|
-
"@wordpress/element": "^8.
|
|
50
|
-
"@wordpress/i18n": "^6.
|
|
51
|
-
"@wordpress/icons": "^15.
|
|
52
|
-
"@wordpress/keyboard-shortcuts": "^5.
|
|
53
|
-
"@wordpress/keycodes": "^4.
|
|
54
|
-
"@wordpress/preferences": "^4.
|
|
55
|
-
"@wordpress/private-apis": "^1.
|
|
56
|
-
"@wordpress/warning": "^3.
|
|
46
|
+
"@wordpress/base-styles": "^13.0.0",
|
|
47
|
+
"@wordpress/components": "^40.0.0",
|
|
48
|
+
"@wordpress/data": "^10.54.0",
|
|
49
|
+
"@wordpress/element": "^8.6.0",
|
|
50
|
+
"@wordpress/i18n": "^6.27.0",
|
|
51
|
+
"@wordpress/icons": "^15.5.0",
|
|
52
|
+
"@wordpress/keyboard-shortcuts": "^5.54.0",
|
|
53
|
+
"@wordpress/keycodes": "^4.54.0",
|
|
54
|
+
"@wordpress/preferences": "^4.54.0",
|
|
55
|
+
"@wordpress/private-apis": "^1.54.0",
|
|
56
|
+
"@wordpress/warning": "^3.54.0",
|
|
57
57
|
"clsx": "^2.1.1",
|
|
58
58
|
"cmdk": "^1.0.0"
|
|
59
59
|
},
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "5ef24f60261976bb198ad035db24bf81c1fb92b4"
|
|
68
68
|
}
|
|
@@ -33,11 +33,11 @@ const ITEM_ID_PREFIX = 'command-palette-item-';
|
|
|
33
33
|
const inputLabel = __( 'Search commands and settings' );
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
36
|
+
* Fallback icons per command category, used when a command provides no icon of
|
|
37
|
+
* its own. Navigating somewhere reads the same way across the palette, so `view`
|
|
38
|
+
* commands are expected to rely on this rather than pass an icon.
|
|
39
39
|
*/
|
|
40
|
-
const
|
|
40
|
+
const CATEGORY_FALLBACK_ICONS = {
|
|
41
41
|
view: arrowRight,
|
|
42
42
|
};
|
|
43
43
|
|
|
@@ -75,6 +75,7 @@ export function isValidIcon( icon ) {
|
|
|
75
75
|
function CommandItem( { command, search, category, valuePrefix } ) {
|
|
76
76
|
const { close } = useDispatch( commandsStore );
|
|
77
77
|
const commandCategory = category ?? command.category;
|
|
78
|
+
const icon = command.icon ?? CATEGORY_FALLBACK_ICONS[ commandCategory ];
|
|
78
79
|
const label = command.searchLabel ?? command.label;
|
|
79
80
|
const value = valuePrefix ? `${ valuePrefix }${ command.name }` : label;
|
|
80
81
|
return (
|
|
@@ -95,17 +96,10 @@ function CommandItem( { command, search, category, valuePrefix } ) {
|
|
|
95
96
|
<HStack
|
|
96
97
|
alignment="left"
|
|
97
98
|
className={ clsx( 'commands-command-menu__item', {
|
|
98
|
-
'has-icon':
|
|
99
|
-
CATEGORY_ICONS[ commandCategory ] || command.icon,
|
|
99
|
+
'has-icon': !! icon,
|
|
100
100
|
} ) }
|
|
101
101
|
>
|
|
102
|
-
{
|
|
103
|
-
<Icon icon={ CATEGORY_ICONS[ commandCategory ] } />
|
|
104
|
-
) : (
|
|
105
|
-
isValidIcon( command.icon ) && (
|
|
106
|
-
<Icon icon={ command.icon } />
|
|
107
|
-
)
|
|
108
|
-
) }
|
|
102
|
+
{ isValidIcon( icon ) && <Icon icon={ icon } /> }
|
|
109
103
|
<span className="commands-command-menu__item-label">
|
|
110
104
|
<TextHighlight
|
|
111
105
|
text={ command.label }
|