@wordpress/commands 0.12.1-next.5a1d1283.0 → 0.13.1

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 CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.13.0 (2023-09-20)
6
+
5
7
  ## 0.12.0 (2023-08-31)
6
8
 
7
9
  ## 0.11.0 (2023-08-16)
package/README.md CHANGED
@@ -1,6 +1,48 @@
1
1
  # Commands
2
2
 
3
- Commands is a generic package that allows registering and modifying commands to be displayed using the commands menu (Also called cmd+k).
3
+ Commands is a generic package that allows registering and modifying commands to be displayed using the commands menu, also called the Command Palette. The Command Palette can be accessed in the Editor using `cmd+k`.
4
+
5
+ ## Types of commands
6
+
7
+ There are two ways to register commands: static or dynamic. Both methods receive a command object as an argument, which provides:
8
+
9
+ - `name`: A unique machine-readable name for the command
10
+ - `label`: A human-readable label
11
+ - `icon`: An SVG icon
12
+ - `callback`: A callback function that is called when the command is selected
13
+ - `context`: (Optional) The context of the command
14
+
15
+ ### Static commands
16
+
17
+ Static commands can be registered using the `wp.data.dispatch( wp.commands.store ).registerCommand` action or using the `wp.commands.useCommand` React hook. Static commands are commonly used to perform a specific action. These could include adding a new page or opening a section of the Editor interface, such as opening the Editor Preferences modal. See the `useCommand` [code example](#usecommand) below.
18
+
19
+ ### Dynamic commands
20
+
21
+ Dynamic commands, on the other hand, are registered using “command loaders", `wp.commands.useCommandLoader`. These loaders are needed when the command list depends on a search term entered by the user in the Command Palette input or when some commands are only available when some conditions are met.
22
+
23
+ For example, when a user types "contact", the Command Palette needs to filter the available pages using that input to try and find the Contact page. See the `useCommandLoader` [code example](#usecommandloader) below.
24
+
25
+ ## Contextual commands
26
+
27
+ Static and dynamic commands can be contextual. This means that in a given context (for example, when navigating the Site Editor or editing a template), some specific commands are given more priority and are visible as soon as you open the Command Palette. Also, when typing the Command Palette, these contextual commands are shown above the rest of the commands.
28
+
29
+ At the moment, two contexts have been implemented:
30
+
31
+ - `site-editor`: This is the context that is set when you are navigating in the site editor (sidebar visible).
32
+ - `site-editor-edit`: This is the context that is set when you are editing a document (template, template part or page) in the site editor.
33
+ As the usage of the Command Palette expands, more contexts will be added.
34
+
35
+ Attaching a command or command loader to a given context is as simple as adding the `context` property (with the right context value from the available contexts above) to the `useCommand` or `useCommandLoader` calls.
36
+
37
+ ## WordPress Data API
38
+
39
+ 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:
40
+
41
+ - Retrieving the registered commands and command loaders using the following selectors `getCommands` and `getCommandLoader`
42
+ - Checking if the Command Palette is open using the `isOpen` selector.
43
+ - Programmatically open or close the Command Palette using the `open` and `close` actions.
44
+
45
+ See the [Commands Data](https://developer.wordpress.org/block-editor/reference-guides/data/data-core-commands/) documentation for more information.
4
46
 
5
47
  ## Installation
6
48
 
@@ -16,29 +58,49 @@ _This package assumes that your code will run in an **ES2015+** environment. If
16
58
 
17
59
  <!-- START TOKEN(Autogenerated API docs) -->
18
60
 
19
- ### CommandMenu
20
-
21
- Undocumented declaration.
22
-
23
- ### privateApis
24
-
25
- Undocumented declaration.
26
-
27
61
  ### store
28
62
 
29
63
  Store definition for the commands namespace.
30
64
 
65
+ See how the Commands Store is being used in components like [site-hub](https://github.com/WordPress/gutenberg/blob/HEAD/packages/edit-site/src/components/site-hub/index.js#L23) and [document-actions](https://github.com/WordPress/gutenberg/blob/HEAD/packages/edit-post/src/components/header/document-actions/index.js#L14).
66
+
31
67
  _Related_
32
68
 
33
69
  - <https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore>
34
70
 
71
+ _Usage_
72
+
73
+ ```js
74
+ import { store as commandsStore } from '@wordpress/commands';
75
+ import { useDispatch } from '@wordpress/data';
76
+ ...
77
+ const { open: openCommandCenter } = useDispatch( commandsStore );
78
+ ```
79
+
35
80
  _Type_
36
81
 
37
82
  - `Object`
38
83
 
39
84
  ### useCommand
40
85
 
41
- Attach a command to the command palette.
86
+ Attach a command to the command palette. Used for static commands.
87
+
88
+ _Usage_
89
+
90
+ ```js
91
+ import { useCommand } from '@wordpress/commands';
92
+ import { plus } from '@wordpress/icons';
93
+
94
+ useCommand( {
95
+ name: 'myplugin/my-command-name',
96
+ label: __( 'Add new post' ),
97
+ icon: plus,
98
+ callback: ( { close } ) => {
99
+ document.location.href = 'post-new.php';
100
+ close();
101
+ },
102
+ } );
103
+ ```
42
104
 
43
105
  _Parameters_
44
106
 
@@ -46,7 +108,72 @@ _Parameters_
46
108
 
47
109
  ### useCommandLoader
48
110
 
49
- Attach a command loader to the command palette.
111
+ Attach a command loader to the command palette. Used for dynamic commands.
112
+
113
+ _Usage_
114
+
115
+ ```js
116
+ import { useCommandLoader } from '@wordpress/commands';
117
+ import { post, page, layout, symbolFilled } from '@wordpress/icons';
118
+
119
+ const icons = {
120
+ post,
121
+ page,
122
+ wp_template: layout,
123
+ wp_template_part: symbolFilled,
124
+ };
125
+
126
+ function usePageSearchCommandLoader( { search } ) {
127
+ // Retrieve the pages for the "search" term.
128
+ const { records, isLoading } = useSelect( ( select ) => {
129
+ const { getEntityRecords } = select( coreStore );
130
+ const query = {
131
+ search: !! search ? search : undefined,
132
+ per_page: 10,
133
+ orderby: search ? 'relevance' : 'date',
134
+ };
135
+ return {
136
+ records: getEntityRecords( 'postType', 'page', query ),
137
+ isLoading: ! select( coreStore ).hasFinishedResolution(
138
+ 'getEntityRecords',
139
+ 'postType', 'page', query ]
140
+ ),
141
+ };
142
+ }, [ search ] );
143
+
144
+ // Create the commands.
145
+ const commands = useMemo( () => {
146
+ return ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {
147
+ return {
148
+ name: record.title?.rendered + ' ' + record.id,
149
+ label: record.title?.rendered
150
+ ? record.title?.rendered
151
+ : __( '(no title)' ),
152
+ icon: icons[ postType ],
153
+ callback: ( { close } ) => {
154
+ const args = {
155
+ postType,
156
+ postId: record.id,
157
+ ...extraArgs,
158
+ };
159
+ document.location = addQueryArgs( 'site-editor.php', args );
160
+ close();
161
+ },
162
+ };
163
+ } );
164
+ }, [ records, history ] );
165
+
166
+ return {
167
+ commands,
168
+ isLoading,
169
+ };
170
+ }
171
+
172
+ useCommandLoader( {
173
+ name: 'myplugin/page-search',
174
+ hook: usePageSearchCommandLoader,
175
+ } );
176
+ ```
50
177
 
51
178
  _Parameters_
52
179
 
@@ -173,6 +173,10 @@ function CommandInput({
173
173
  icon: search
174
174
  });
175
175
  }
176
+
177
+ /**
178
+ * @ignore
179
+ */
176
180
  function CommandMenu() {
177
181
  const {
178
182
  registerShortcut
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_cmdk","_classnames","_interopRequireDefault","_data","_i18n","_components","_keyboardShortcuts","_icons","_store","CommandMenuLoader","name","search","hook","setLoader","close","_hook","isLoading","commands","useEffect","length","createElement","Fragment","Command","List","map","command","_command$searchLabel","Item","key","value","searchLabel","label","onSelect","callback","id","__experimentalHStack","alignment","className","classnames","icon","Icon","TextHighlight","text","highlight","CommandMenuLoaderWrapper","currentLoader","useRef","setKey","useState","current","prevKey","CommandMenuGroup","isContextual","loaders","useSelect","select","getCommands","getCommandLoaders","commandsStore","Group","_command$searchLabel2","loader","CommandInput","isOpen","setSearch","commandMenuInput","_value","useCommandState","state","selectedItemId","useMemo","item","document","querySelector","getAttribute","focus","Input","ref","onValueChange","placeholder","__","CommandMenu","registerShortcut","useDispatch","keyboardShortcutsStore","open","setLoaders","category","description","keyCombination","modifier","character","useShortcut","event","defaultPrevented","preventDefault","bindGlobal","useCallback","closeAndReset","onKeyDown","nativeEvent","isComposing","keyCode","Object","values","some","Boolean","Modal","overlayClassName","onRequestClose","__experimentalHideHeader","inputIcon","Empty"],"sources":["@wordpress/commands/src/components/command-menu.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { Command, useCommandState } from 'cmdk';\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseState,\n\tuseEffect,\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tModal,\n\tTextHighlight,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { Icon, search as inputIcon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\nfunction CommandMenuLoader( { name, search, hook, setLoader, close } ) {\n\tconst { isLoading, commands = [] } = hook( { search } ) ?? {};\n\tuseEffect( () => {\n\t\tsetLoader( name, isLoading );\n\t}, [ setLoader, name, isLoading ] );\n\n\tif ( ! commands.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Command.List>\n\t\t\t\t{ commands.map( ( command ) => (\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\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={ classnames(\n\t\t\t\t\t\t\t\t'commands-command-menu__item',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t\t<span>\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</HStack>\n\t\t\t\t\t</Command.Item>\n\t\t\t\t) ) }\n\t\t\t</Command.List>\n\t\t</>\n\t);\n}\n\nexport function CommandMenuLoaderWrapper( { hook, search, setLoader, close } ) {\n\t// The \"hook\" prop is actually a custom React hook\n\t// so to avoid breaking the rules of hooks\n\t// the CommandMenuLoaderWrapper component need to be\n\t// remounted on each hook prop change\n\t// We use the key state to make sure we do that properly.\n\tconst currentLoader = useRef( hook );\n\tconst [ key, setKey ] = useState( 0 );\n\tuseEffect( () => {\n\t\tif ( currentLoader.current !== hook ) {\n\t\t\tcurrentLoader.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={ currentLoader.current }\n\t\t\tsearch={ search }\n\t\t\tsetLoader={ setLoader }\n\t\t\tclose={ close }\n\t\t/>\n\t);\n}\n\nexport function CommandMenuGroup( { isContextual, search, setLoader, close } ) {\n\tconst { commands, loaders } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCommands, getCommandLoaders } = select( commandsStore );\n\t\t\treturn {\n\t\t\t\tcommands: getCommands( isContextual ),\n\t\t\t\tloaders: getCommandLoaders( isContextual ),\n\t\t\t};\n\t\t},\n\t\t[ isContextual ]\n\t);\n\n\tif ( ! commands.length && ! loaders.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Command.Group>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\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={ classnames( 'commands-command-menu__item', {\n\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t\t{ loaders.map( ( loader ) => (\n\t\t\t\t<CommandMenuLoaderWrapper\n\t\t\t\t\tkey={ loader.name }\n\t\t\t\t\thook={ loader.hook }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\tclose={ close }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Command.Group>\n\t);\n}\n\nfunction CommandInput( { isOpen, search, setSearch } ) {\n\tconst commandMenuInput = useRef();\n\tconst _value = useCommandState( ( state ) => state.value );\n\tconst selectedItemId = useMemo( () => {\n\t\tconst item = document.querySelector(\n\t\t\t`[cmdk-item=\"\"][data-value=\"${ _value }\"]`\n\t\t);\n\t\treturn item?.getAttribute( 'id' );\n\t}, [ _value ] );\n\tuseEffect( () => {\n\t\t// Focus the command palette input when mounting the modal.\n\t\tif ( isOpen ) {\n\t\t\tcommandMenuInput.current.focus();\n\t\t}\n\t}, [ isOpen ] );\n\treturn (\n\t\t<Command.Input\n\t\t\tref={ commandMenuInput }\n\t\t\tvalue={ search }\n\t\t\tonValueChange={ setSearch }\n\t\t\tplaceholder={ __( 'Search for commands' ) }\n\t\t\taria-activedescendant={ selectedItemId }\n\t\t\ticon={ search }\n\t\t/>\n\t);\n}\n\nexport function CommandMenu() {\n\tconst { registerShortcut } = useDispatch( keyboardShortcutsStore );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst isOpen = useSelect(\n\t\t( select ) => select( commandsStore ).isOpen(),\n\t\t[]\n\t);\n\tconst { open, close } = useDispatch( commandsStore );\n\tconst [ loaders, setLoaders ] = useState( {} );\n\n\tuseEffect( () => {\n\t\tregisterShortcut( {\n\t\t\tname: 'core/commands',\n\t\t\tcategory: 'global',\n\t\t\tdescription: __( 'Open the command palette.' ),\n\t\t\tkeyCombination: {\n\t\t\t\tmodifier: 'primary',\n\t\t\t\tcharacter: 'k',\n\t\t\t},\n\t\t} );\n\t}, [ registerShortcut ] );\n\n\tuseShortcut(\n\t\t'core/commands',\n\t\t/** @type {import('react').KeyboardEventHandler} */\n\t\t( event ) => {\n\t\t\t// Bails to avoid obscuring the effect of the preceding handler(s).\n\t\t\tif ( event.defaultPrevented ) return;\n\n\t\t\tevent.preventDefault();\n\t\t\tif ( isOpen ) {\n\t\t\t\tclose();\n\t\t\t} else {\n\t\t\t\topen();\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tbindGlobal: true,\n\t\t}\n\t);\n\n\tconst setLoader = useCallback(\n\t\t( name, value ) =>\n\t\t\tsetLoaders( ( current ) => ( {\n\t\t\t\t...current,\n\t\t\t\t[ name ]: value,\n\t\t\t} ) ),\n\t\t[]\n\t);\n\tconst closeAndReset = () => {\n\t\tsetSearch( '' );\n\t\tclose();\n\t};\n\n\tif ( ! isOpen ) {\n\t\treturn false;\n\t}\n\n\tconst onKeyDown = ( event ) => {\n\t\tif (\n\t\t\t// Ignore keydowns from IMEs\n\t\t\tevent.nativeEvent.isComposing ||\n\t\t\t// Workaround for Mac Safari where the final Enter/Backspace of an IME composition\n\t\t\t// is `isComposing=false`, even though it's technically still part of the composition.\n\t\t\t// These can only be detected by keyCode.\n\t\t\tevent.keyCode === 229\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\tconst isLoading = Object.values( loaders ).some( Boolean );\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"commands-command-menu\"\n\t\t\toverlayClassName=\"commands-command-menu__overlay\"\n\t\t\tonRequestClose={ closeAndReset }\n\t\t\t__experimentalHideHeader\n\t\t>\n\t\t\t<div className=\"commands-command-menu__container\">\n\t\t\t\t<Command\n\t\t\t\t\tlabel={ __( 'Command palette' ) }\n\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t>\n\t\t\t\t\t<div className=\"commands-command-menu__header\">\n\t\t\t\t\t\t<Icon icon={ inputIcon } />\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>\n\t\t\t\t\t\t{ search && ! isLoading && (\n\t\t\t\t\t\t\t<Command.Empty>\n\t\t\t\t\t\t\t\t{ __( 'No results found.' ) }\n\t\t\t\t\t\t\t</Command.Empty>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\tisContextual\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ search && (\n\t\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Command.List>\n\t\t\t\t</Command>\n\t\t\t</div>\n\t\t</Modal>\n\t);\n}\n"],"mappings":";;;;;;;;;AAUA,IAAAA,QAAA,GAAAC,OAAA;AAPA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAC,sBAAA,CAAAH,OAAA;AAKA,IAAAI,KAAA,GAAAJ,OAAA;AAQA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAKA,IAAAO,kBAAA,GAAAP,OAAA;AAIA,IAAAQ,MAAA,GAAAR,OAAA;AAKA,IAAAS,MAAA,GAAAT,OAAA;A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AGwE;EAAW,CAAE,CAAC,EAC3B,IAAAjH,QAAA,CAAAsB,aAAA,EAAC0C,YAAY;IACZnD,MAAM,EAAGA,MAAQ;IACjBqD,SAAS,EAAGA,SAAW;IACvBD,MAAM,EAAGA;EAAQ,CACjB,CACG,CAAC,EACN,IAAAjE,QAAA,CAAAsB,aAAA,EAACpB,KAAA,CAAAsB,OAAO,CAACC,IAAI,QACVZ,MAAM,IAAI,CAAEK,SAAS,IACtB,IAAAlB,QAAA,CAAAsB,aAAA,EAACpB,KAAA,CAAAsB,OAAO,CAAC0F,KAAK,QACX,IAAAhC,QAAE,EAAE,mBAAoB,CACZ,CACf,EACD,IAAAlF,QAAA,CAAAsB,aAAA,EAAC+B,gBAAgB;IAChBxC,MAAM,EAAGA,MAAQ;IACjBE,SAAS,EAAGA,SAAW;IACvBC,KAAK,EAAGoF,aAAe;IACvB9C,YAAY;EAAA,CACZ,CAAC,EACAzC,MAAM,IACP,IAAAb,QAAA,CAAAsB,aAAA,EAAC+B,gBAAgB;IAChBxC,MAAM,EAAGA,MAAQ;IACjBE,SAAS,EAAGA,SAAW;IACvBC,KAAK,EAAGoF;EAAe,CACvB,CAEW,CACN,CACL,CACC,CAAC;AAEV"}
1
+ {"version":3,"names":["_element","require","_cmdk","_classnames","_interopRequireDefault","_data","_i18n","_components","_keyboardShortcuts","_icons","_store","CommandMenuLoader","name","search","hook","setLoader","close","_hook","isLoading","commands","useEffect","length","createElement","Fragment","Command","List","map","command","_command$searchLabel","Item","key","value","searchLabel","label","onSelect","callback","id","__experimentalHStack","alignment","className","classnames","icon","Icon","TextHighlight","text","highlight","CommandMenuLoaderWrapper","currentLoader","useRef","setKey","useState","current","prevKey","CommandMenuGroup","isContextual","loaders","useSelect","select","getCommands","getCommandLoaders","commandsStore","Group","_command$searchLabel2","loader","CommandInput","isOpen","setSearch","commandMenuInput","_value","useCommandState","state","selectedItemId","useMemo","item","document","querySelector","getAttribute","focus","Input","ref","onValueChange","placeholder","__","CommandMenu","registerShortcut","useDispatch","keyboardShortcutsStore","open","setLoaders","category","description","keyCombination","modifier","character","useShortcut","event","defaultPrevented","preventDefault","bindGlobal","useCallback","closeAndReset","onKeyDown","nativeEvent","isComposing","keyCode","Object","values","some","Boolean","Modal","overlayClassName","onRequestClose","__experimentalHideHeader","inputIcon","Empty"],"sources":["@wordpress/commands/src/components/command-menu.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { Command, useCommandState } from 'cmdk';\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseState,\n\tuseEffect,\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tModal,\n\tTextHighlight,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { Icon, search as inputIcon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\nfunction CommandMenuLoader( { name, search, hook, setLoader, close } ) {\n\tconst { isLoading, commands = [] } = hook( { search } ) ?? {};\n\tuseEffect( () => {\n\t\tsetLoader( name, isLoading );\n\t}, [ setLoader, name, isLoading ] );\n\n\tif ( ! commands.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Command.List>\n\t\t\t\t{ commands.map( ( command ) => (\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\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={ classnames(\n\t\t\t\t\t\t\t\t'commands-command-menu__item',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t\t<span>\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</HStack>\n\t\t\t\t\t</Command.Item>\n\t\t\t\t) ) }\n\t\t\t</Command.List>\n\t\t</>\n\t);\n}\n\nexport function CommandMenuLoaderWrapper( { hook, search, setLoader, close } ) {\n\t// The \"hook\" prop is actually a custom React hook\n\t// so to avoid breaking the rules of hooks\n\t// the CommandMenuLoaderWrapper component need to be\n\t// remounted on each hook prop change\n\t// We use the key state to make sure we do that properly.\n\tconst currentLoader = useRef( hook );\n\tconst [ key, setKey ] = useState( 0 );\n\tuseEffect( () => {\n\t\tif ( currentLoader.current !== hook ) {\n\t\t\tcurrentLoader.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={ currentLoader.current }\n\t\t\tsearch={ search }\n\t\t\tsetLoader={ setLoader }\n\t\t\tclose={ close }\n\t\t/>\n\t);\n}\n\nexport function CommandMenuGroup( { isContextual, search, setLoader, close } ) {\n\tconst { commands, loaders } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCommands, getCommandLoaders } = select( commandsStore );\n\t\t\treturn {\n\t\t\t\tcommands: getCommands( isContextual ),\n\t\t\t\tloaders: getCommandLoaders( isContextual ),\n\t\t\t};\n\t\t},\n\t\t[ isContextual ]\n\t);\n\n\tif ( ! commands.length && ! loaders.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Command.Group>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\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={ classnames( 'commands-command-menu__item', {\n\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t\t{ loaders.map( ( loader ) => (\n\t\t\t\t<CommandMenuLoaderWrapper\n\t\t\t\t\tkey={ loader.name }\n\t\t\t\t\thook={ loader.hook }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\tclose={ close }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Command.Group>\n\t);\n}\n\nfunction CommandInput( { isOpen, search, setSearch } ) {\n\tconst commandMenuInput = useRef();\n\tconst _value = useCommandState( ( state ) => state.value );\n\tconst selectedItemId = useMemo( () => {\n\t\tconst item = document.querySelector(\n\t\t\t`[cmdk-item=\"\"][data-value=\"${ _value }\"]`\n\t\t);\n\t\treturn item?.getAttribute( 'id' );\n\t}, [ _value ] );\n\tuseEffect( () => {\n\t\t// Focus the command palette input when mounting the modal.\n\t\tif ( isOpen ) {\n\t\t\tcommandMenuInput.current.focus();\n\t\t}\n\t}, [ isOpen ] );\n\treturn (\n\t\t<Command.Input\n\t\t\tref={ commandMenuInput }\n\t\t\tvalue={ search }\n\t\t\tonValueChange={ setSearch }\n\t\t\tplaceholder={ __( 'Search for commands' ) }\n\t\t\taria-activedescendant={ selectedItemId }\n\t\t\ticon={ search }\n\t\t/>\n\t);\n}\n\n/**\n * @ignore\n */\nexport function CommandMenu() {\n\tconst { registerShortcut } = useDispatch( keyboardShortcutsStore );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst isOpen = useSelect(\n\t\t( select ) => select( commandsStore ).isOpen(),\n\t\t[]\n\t);\n\tconst { open, close } = useDispatch( commandsStore );\n\tconst [ loaders, setLoaders ] = useState( {} );\n\n\tuseEffect( () => {\n\t\tregisterShortcut( {\n\t\t\tname: 'core/commands',\n\t\t\tcategory: 'global',\n\t\t\tdescription: __( 'Open the command palette.' ),\n\t\t\tkeyCombination: {\n\t\t\t\tmodifier: 'primary',\n\t\t\t\tcharacter: 'k',\n\t\t\t},\n\t\t} );\n\t}, [ registerShortcut ] );\n\n\tuseShortcut(\n\t\t'core/commands',\n\t\t/** @type {import('react').KeyboardEventHandler} */\n\t\t( event ) => {\n\t\t\t// Bails to avoid obscuring the effect of the preceding handler(s).\n\t\t\tif ( event.defaultPrevented ) return;\n\n\t\t\tevent.preventDefault();\n\t\t\tif ( isOpen ) {\n\t\t\t\tclose();\n\t\t\t} else {\n\t\t\t\topen();\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tbindGlobal: true,\n\t\t}\n\t);\n\n\tconst setLoader = useCallback(\n\t\t( name, value ) =>\n\t\t\tsetLoaders( ( current ) => ( {\n\t\t\t\t...current,\n\t\t\t\t[ name ]: value,\n\t\t\t} ) ),\n\t\t[]\n\t);\n\tconst closeAndReset = () => {\n\t\tsetSearch( '' );\n\t\tclose();\n\t};\n\n\tif ( ! isOpen ) {\n\t\treturn false;\n\t}\n\n\tconst onKeyDown = ( event ) => {\n\t\tif (\n\t\t\t// Ignore keydowns from IMEs\n\t\t\tevent.nativeEvent.isComposing ||\n\t\t\t// Workaround for Mac Safari where the final Enter/Backspace of an IME composition\n\t\t\t// is `isComposing=false`, even though it's technically still part of the composition.\n\t\t\t// These can only be detected by keyCode.\n\t\t\tevent.keyCode === 229\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\tconst isLoading = Object.values( loaders ).some( Boolean );\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"commands-command-menu\"\n\t\t\toverlayClassName=\"commands-command-menu__overlay\"\n\t\t\tonRequestClose={ closeAndReset }\n\t\t\t__experimentalHideHeader\n\t\t>\n\t\t\t<div className=\"commands-command-menu__container\">\n\t\t\t\t<Command\n\t\t\t\t\tlabel={ __( 'Command palette' ) }\n\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t>\n\t\t\t\t\t<div className=\"commands-command-menu__header\">\n\t\t\t\t\t\t<Icon icon={ inputIcon } />\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>\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\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AChCY,wBAAwB;EAAA,GAExB,IAAAhH,QAAA,CAAAsB,aAAA;IAAKiB,SAAS,EAAC;EAAkC,GAChD,IAAAvC,QAAA,CAAAsB,aAAA,EAACpB,KAAA,CAAAsB,OAAO;IACPS,KAAK,EAAG,IAAAiD,QAAE,EAAE,iBAAkB,CAAG;IACjCmB,SAAS,EAAGA;EAAW,GAEvB,IAAArG,QAAA,CAAAsB,aAAA;IAAKiB,SAAS,EAAC;EAA+B,GAC7C,IAAAvC,QAAA,CAAAsB,aAAA,EAACb,MAAA,CAAAiC,IAAI;IAACD,IAAI,EAAGwE;EAAW,CAAE,CAAC,EAC3B,IAAAjH,QAAA,CAAAsB,aAAA,EAAC0C,YAAY;IACZnD,MAAM,EAAGA,MAAQ;IACjBqD,SAAS,EAAGA,SAAW;IACvBD,MAAM,EAAGA;EAAQ,CACjB,CACG,CAAC,EACN,IAAAjE,QAAA,CAAAsB,aAAA,EAACpB,KAAA,CAAAsB,OAAO,CAACC,IAAI,QACVZ,MAAM,IAAI,CAAEK,SAAS,IACtB,IAAAlB,QAAA,CAAAsB,aAAA,EAACpB,KAAA,CAAAsB,OAAO,CAAC0F,KAAK,QACX,IAAAhC,QAAE,EAAE,mBAAoB,CACZ,CACf,EACD,IAAAlF,QAAA,CAAAsB,aAAA,EAAC+B,gBAAgB;IAChBxC,MAAM,EAAGA,MAAQ;IACjBE,SAAS,EAAGA,SAAW;IACvBC,KAAK,EAAGoF,aAAe;IACvB9C,YAAY;EAAA,CACZ,CAAC,EACAzC,MAAM,IACP,IAAAb,QAAA,CAAAsB,aAAA,EAAC+B,gBAAgB;IAChBxC,MAAM,EAAGA,MAAQ;IACjBE,SAAS,EAAGA,SAAW;IACvBC,KAAK,EAAGoF;EAAe,CACvB,CAEW,CACN,CACL,CACC,CAAC;AAEV"}
@@ -16,9 +16,73 @@ var _store = require("../store");
16
16
  */
17
17
 
18
18
  /**
19
- * Attach a command loader to the command palette.
19
+ * Attach a command loader to the command palette. Used for dynamic commands.
20
20
  *
21
21
  * @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.
22
+ *
23
+ * @example
24
+ * ```js
25
+ * import { useCommandLoader } from '@wordpress/commands';
26
+ * import { post, page, layout, symbolFilled } from '@wordpress/icons';
27
+ *
28
+ * const icons = {
29
+ * post,
30
+ * page,
31
+ * wp_template: layout,
32
+ * wp_template_part: symbolFilled,
33
+ * };
34
+ *
35
+ * function usePageSearchCommandLoader( { search } ) {
36
+ * // Retrieve the pages for the "search" term.
37
+ * const { records, isLoading } = useSelect( ( select ) => {
38
+ * const { getEntityRecords } = select( coreStore );
39
+ * const query = {
40
+ * search: !! search ? search : undefined,
41
+ * per_page: 10,
42
+ * orderby: search ? 'relevance' : 'date',
43
+ * };
44
+ * return {
45
+ * records: getEntityRecords( 'postType', 'page', query ),
46
+ * isLoading: ! select( coreStore ).hasFinishedResolution(
47
+ * 'getEntityRecords',
48
+ * 'postType', 'page', query ]
49
+ * ),
50
+ * };
51
+ * }, [ search ] );
52
+ *
53
+ * // Create the commands.
54
+ * const commands = useMemo( () => {
55
+ * return ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {
56
+ * return {
57
+ * name: record.title?.rendered + ' ' + record.id,
58
+ * label: record.title?.rendered
59
+ * ? record.title?.rendered
60
+ * : __( '(no title)' ),
61
+ * icon: icons[ postType ],
62
+ * callback: ( { close } ) => {
63
+ * const args = {
64
+ * postType,
65
+ * postId: record.id,
66
+ * ...extraArgs,
67
+ * };
68
+ * document.location = addQueryArgs( 'site-editor.php', args );
69
+ * close();
70
+ * },
71
+ * };
72
+ * } );
73
+ * }, [ records, history ] );
74
+ *
75
+ * return {
76
+ * commands,
77
+ * isLoading,
78
+ * };
79
+ * }
80
+ *
81
+ * useCommandLoader( {
82
+ * name: 'myplugin/page-search',
83
+ * hook: usePageSearchCommandLoader,
84
+ * } );
85
+ * ```
22
86
  */
23
87
  function useCommandLoader(loader) {
24
88
  const {
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_data","_store","useCommandLoader","loader","registerCommandLoader","unregisterCommandLoader","useDispatch","commandsStore","useEffect","name","hook","context"],"sources":["@wordpress/commands/src/hooks/use-command-loader.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Attach a command loader to the command palette.\n *\n * @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.\n */\nexport default function useCommandLoader( loader ) {\n\tconst { registerCommandLoader, unregisterCommandLoader } =\n\t\tuseDispatch( commandsStore );\n\tuseEffect( () => {\n\t\tregisterCommandLoader( {\n\t\t\tname: loader.name,\n\t\t\thook: loader.hook,\n\t\t\tcontext: loader.context,\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommandLoader( loader.name );\n\t\t};\n\t}, [\n\t\tloader.name,\n\t\tloader.hook,\n\t\tloader.context,\n\t\tregisterCommandLoader,\n\t\tunregisterCommandLoader,\n\t] );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACe,SAASG,gBAAgBA,CAAEC,MAAM,EAAG;EAClD,MAAM;IAAEC,qBAAqB;IAAEC;EAAwB,CAAC,GACvD,IAAAC,iBAAW,EAAEC,YAAc,CAAC;EAC7B,IAAAC,kBAAS,EAAE,MAAM;IAChBJ,qBAAqB,CAAE;MACtBK,IAAI,EAAEN,MAAM,CAACM,IAAI;MACjBC,IAAI,EAAEP,MAAM,CAACO,IAAI;MACjBC,OAAO,EAAER,MAAM,CAACQ;IACjB,CAAE,CAAC;IACH,OAAO,MAAM;MACZN,uBAAuB,CAAEF,MAAM,CAACM,IAAK,CAAC;IACvC,CAAC;EACF,CAAC,EAAE,CACFN,MAAM,CAACM,IAAI,EACXN,MAAM,CAACO,IAAI,EACXP,MAAM,CAACQ,OAAO,EACdP,qBAAqB,EACrBC,uBAAuB,CACtB,CAAC;AACJ"}
1
+ {"version":3,"names":["_element","require","_data","_store","useCommandLoader","loader","registerCommandLoader","unregisterCommandLoader","useDispatch","commandsStore","useEffect","name","hook","context"],"sources":["@wordpress/commands/src/hooks/use-command-loader.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Attach a command loader to the command palette. Used for dynamic commands.\n *\n * @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.\n *\n * @example\n * ```js\n * import { useCommandLoader } from '@wordpress/commands';\n * import { post, page, layout, symbolFilled } from '@wordpress/icons';\n *\n * const icons = {\n * post,\n * page,\n * wp_template: layout,\n * wp_template_part: symbolFilled,\n * };\n *\n * function usePageSearchCommandLoader( { search } ) {\n * // Retrieve the pages for the \"search\" term.\n * const { records, isLoading } = useSelect( ( select ) => {\n * const { getEntityRecords } = select( coreStore );\n * const query = {\n * search: !! search ? search : undefined,\n * per_page: 10,\n * orderby: search ? 'relevance' : 'date',\n * };\n * return {\n * records: getEntityRecords( 'postType', 'page', query ),\n * isLoading: ! select( coreStore ).hasFinishedResolution(\n * 'getEntityRecords',\n * 'postType', 'page', query ]\n * ),\n * };\n * }, [ search ] );\n *\n * // Create the commands.\n * const commands = useMemo( () => {\n * return ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {\n * return {\n * name: record.title?.rendered + ' ' + record.id,\n * label: record.title?.rendered\n * ? record.title?.rendered\n * : __( '(no title)' ),\n * icon: icons[ postType ],\n * callback: ( { close } ) => {\n * const args = {\n * postType,\n * postId: record.id,\n * ...extraArgs,\n * };\n * document.location = addQueryArgs( 'site-editor.php', args );\n * close();\n * },\n * };\n * } );\n * }, [ records, history ] );\n *\n * return {\n * commands,\n * isLoading,\n * };\n * }\n *\n * useCommandLoader( {\n * name: 'myplugin/page-search',\n * hook: usePageSearchCommandLoader,\n * } );\n * ```\n */\nexport default function useCommandLoader( loader ) {\n\tconst { registerCommandLoader, unregisterCommandLoader } =\n\t\tuseDispatch( commandsStore );\n\tuseEffect( () => {\n\t\tregisterCommandLoader( {\n\t\t\tname: loader.name,\n\t\t\thook: loader.hook,\n\t\t\tcontext: loader.context,\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommandLoader( loader.name );\n\t\t};\n\t}, [\n\t\tloader.name,\n\t\tloader.hook,\n\t\tloader.context,\n\t\tregisterCommandLoader,\n\t\tunregisterCommandLoader,\n\t] );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,gBAAgBA,CAAEC,MAAM,EAAG;EAClD,MAAM;IAAEC,qBAAqB;IAAEC;EAAwB,CAAC,GACvD,IAAAC,iBAAW,EAAEC,YAAc,CAAC;EAC7B,IAAAC,kBAAS,EAAE,MAAM;IAChBJ,qBAAqB,CAAE;MACtBK,IAAI,EAAEN,MAAM,CAACM,IAAI;MACjBC,IAAI,EAAEP,MAAM,CAACO,IAAI;MACjBC,OAAO,EAAER,MAAM,CAACQ;IACjB,CAAE,CAAC;IACH,OAAO,MAAM;MACZN,uBAAuB,CAAEF,MAAM,CAACM,IAAK,CAAC;IACvC,CAAC;EACF,CAAC,EAAE,CACFN,MAAM,CAACM,IAAI,EACXN,MAAM,CAACO,IAAI,EACXP,MAAM,CAACQ,OAAO,EACdP,qBAAqB,EACrBC,uBAAuB,CACtB,CAAC;AACJ"}
@@ -16,9 +16,25 @@ var _store = require("../store");
16
16
  */
17
17
 
18
18
  /**
19
- * Attach a command to the command palette.
19
+ * Attach a command to the command palette. Used for static commands.
20
20
  *
21
21
  * @param {import('../store/actions').WPCommandConfig} command command config.
22
+ *
23
+ * @example
24
+ * ```js
25
+ * import { useCommand } from '@wordpress/commands';
26
+ * import { plus } from '@wordpress/icons';
27
+ *
28
+ * useCommand( {
29
+ * name: 'myplugin/my-command-name',
30
+ * label: __( 'Add new post' ),
31
+ * icon: plus,
32
+ * callback: ({ close }) => {
33
+ * document.location.href = 'post-new.php';
34
+ * close();
35
+ * },
36
+ * } );
37
+ * ```
22
38
  */
23
39
  function useCommand(command) {
24
40
  const {
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_data","_store","useCommand","command","registerCommand","unregisterCommand","useDispatch","commandsStore","currentCallback","useRef","callback","useEffect","current","name","context","label","searchLabel","icon","args"],"sources":["@wordpress/commands/src/hooks/use-command.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Attach a command to the command palette.\n *\n * @param {import('../store/actions').WPCommandConfig} command command config.\n */\nexport default function useCommand( command ) {\n\tconst { registerCommand, unregisterCommand } = useDispatch( commandsStore );\n\tconst currentCallback = useRef( command.callback );\n\tuseEffect( () => {\n\t\tcurrentCallback.current = command.callback;\n\t}, [ command.callback ] );\n\n\tuseEffect( () => {\n\t\tregisterCommand( {\n\t\t\tname: command.name,\n\t\t\tcontext: command.context,\n\t\t\tlabel: command.label,\n\t\t\tsearchLabel: command.searchLabel,\n\t\t\ticon: command.icon,\n\t\t\tcallback: ( ...args ) => currentCallback.current( ...args ),\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommand( command.name );\n\t\t};\n\t}, [\n\t\tcommand.name,\n\t\tcommand.label,\n\t\tcommand.searchLabel,\n\t\tcommand.icon,\n\t\tcommand.context,\n\t\tregisterCommand,\n\t\tunregisterCommand,\n\t] );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACe,SAASG,UAAUA,CAAEC,OAAO,EAAG;EAC7C,MAAM;IAAEC,eAAe;IAAEC;EAAkB,CAAC,GAAG,IAAAC,iBAAW,EAAEC,YAAc,CAAC;EAC3E,MAAMC,eAAe,GAAG,IAAAC,eAAM,EAAEN,OAAO,CAACO,QAAS,CAAC;EAClD,IAAAC,kBAAS,EAAE,MAAM;IAChBH,eAAe,CAACI,OAAO,GAAGT,OAAO,CAACO,QAAQ;EAC3C,CAAC,EAAE,CAAEP,OAAO,CAACO,QAAQ,CAAG,CAAC;EAEzB,IAAAC,kBAAS,EAAE,MAAM;IAChBP,eAAe,CAAE;MAChBS,IAAI,EAAEV,OAAO,CAACU,IAAI;MAClBC,OAAO,EAAEX,OAAO,CAACW,OAAO;MACxBC,KAAK,EAAEZ,OAAO,CAACY,KAAK;MACpBC,WAAW,EAAEb,OAAO,CAACa,WAAW;MAChCC,IAAI,EAAEd,OAAO,CAACc,IAAI;MAClBP,QAAQ,EAAEA,CAAE,GAAGQ,IAAI,KAAMV,eAAe,CAACI,OAAO,CAAE,GAAGM,IAAK;IAC3D,CAAE,CAAC;IACH,OAAO,MAAM;MACZb,iBAAiB,CAAEF,OAAO,CAACU,IAAK,CAAC;IAClC,CAAC;EACF,CAAC,EAAE,CACFV,OAAO,CAACU,IAAI,EACZV,OAAO,CAACY,KAAK,EACbZ,OAAO,CAACa,WAAW,EACnBb,OAAO,CAACc,IAAI,EACZd,OAAO,CAACW,OAAO,EACfV,eAAe,EACfC,iBAAiB,CAChB,CAAC;AACJ"}
1
+ {"version":3,"names":["_element","require","_data","_store","useCommand","command","registerCommand","unregisterCommand","useDispatch","commandsStore","currentCallback","useRef","callback","useEffect","current","name","context","label","searchLabel","icon","args"],"sources":["@wordpress/commands/src/hooks/use-command.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Attach a command to the command palette. Used for static commands.\n *\n * @param {import('../store/actions').WPCommandConfig} command command config.\n *\n * @example\n * ```js\n * import { useCommand } from '@wordpress/commands';\n * import { plus } from '@wordpress/icons';\n *\n * useCommand( {\n * name: 'myplugin/my-command-name',\n * label: __( 'Add new post' ),\n *\t icon: plus,\n * callback: ({ close }) => {\n * document.location.href = 'post-new.php';\n * close();\n * },\n * } );\n * ```\n */\nexport default function useCommand( command ) {\n\tconst { registerCommand, unregisterCommand } = useDispatch( commandsStore );\n\tconst currentCallback = useRef( command.callback );\n\tuseEffect( () => {\n\t\tcurrentCallback.current = command.callback;\n\t}, [ command.callback ] );\n\n\tuseEffect( () => {\n\t\tregisterCommand( {\n\t\t\tname: command.name,\n\t\t\tcontext: command.context,\n\t\t\tlabel: command.label,\n\t\t\tsearchLabel: command.searchLabel,\n\t\t\ticon: command.icon,\n\t\t\tcallback: ( ...args ) => currentCallback.current( ...args ),\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommand( command.name );\n\t\t};\n\t}, [\n\t\tcommand.name,\n\t\tcommand.label,\n\t\tcommand.searchLabel,\n\t\tcommand.icon,\n\t\tcommand.context,\n\t\tregisterCommand,\n\t\tunregisterCommand,\n\t] );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,UAAUA,CAAEC,OAAO,EAAG;EAC7C,MAAM;IAAEC,eAAe;IAAEC;EAAkB,CAAC,GAAG,IAAAC,iBAAW,EAAEC,YAAc,CAAC;EAC3E,MAAMC,eAAe,GAAG,IAAAC,eAAM,EAAEN,OAAO,CAACO,QAAS,CAAC;EAClD,IAAAC,kBAAS,EAAE,MAAM;IAChBH,eAAe,CAACI,OAAO,GAAGT,OAAO,CAACO,QAAQ;EAC3C,CAAC,EAAE,CAAEP,OAAO,CAACO,QAAQ,CAAG,CAAC;EAEzB,IAAAC,kBAAS,EAAE,MAAM;IAChBP,eAAe,CAAE;MAChBS,IAAI,EAAEV,OAAO,CAACU,IAAI;MAClBC,OAAO,EAAEX,OAAO,CAACW,OAAO;MACxBC,KAAK,EAAEZ,OAAO,CAACY,KAAK;MACpBC,WAAW,EAAEb,OAAO,CAACa,WAAW;MAChCC,IAAI,EAAEd,OAAO,CAACc,IAAI;MAClBP,QAAQ,EAAEA,CAAE,GAAGQ,IAAI,KAAMV,eAAe,CAACI,OAAO,CAAE,GAAGM,IAAK;IAC3D,CAAE,CAAC;IACH,OAAO,MAAM;MACZb,iBAAiB,CAAEF,OAAO,CAACU,IAAK,CAAC;IAClC,CAAC;EACF,CAAC,EAAE,CACFV,OAAO,CAACU,IAAI,EACZV,OAAO,CAACY,KAAK,EACbZ,OAAO,CAACa,WAAW,EACnBb,OAAO,CAACc,IAAI,EACZd,OAAO,CAACW,OAAO,EACfV,eAAe,EACfC,iBAAiB,CAChB,CAAC;AACJ"}
@@ -11,6 +11,9 @@ var _lockUnlock = require("./lock-unlock");
11
11
  * Internal dependencies
12
12
  */
13
13
 
14
+ /**
15
+ * @private
16
+ */
14
17
  const privateApis = {};
15
18
  exports.privateApis = privateApis;
16
19
  (0, _lockUnlock.lock)(privateApis, {
@@ -1 +1 @@
1
- {"version":3,"names":["_useCommandContext","_interopRequireDefault","require","_lockUnlock","privateApis","exports","lock","useCommandContext"],"sources":["@wordpress/commands/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { default as useCommandContext } from './hooks/use-command-context';\nimport { lock } from './lock-unlock';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tuseCommandContext,\n} );\n"],"mappings":";;;;;;;AAGA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAIO,MAAME,WAAW,GAAG,CAAC,CAAC;AAACC,OAAA,CAAAD,WAAA,GAAAA,WAAA;AAC9B,IAAAE,gBAAI,EAAEF,WAAW,EAAE;EAClBG,iBAAiB,EAAjBA;AACD,CAAE,CAAC"}
1
+ {"version":3,"names":["_useCommandContext","_interopRequireDefault","require","_lockUnlock","privateApis","exports","lock","useCommandContext"],"sources":["@wordpress/commands/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { default as useCommandContext } from './hooks/use-command-context';\nimport { lock } from './lock-unlock';\n\n/**\n * @private\n */\nexport const privateApis = {};\nlock( privateApis, {\n\tuseCommandContext,\n} );\n"],"mappings":";;;;;;;AAGA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACO,MAAME,WAAW,GAAG,CAAC,CAAC;AAACC,OAAA,CAAAD,WAAA,GAAAA,WAAA;AAC9B,IAAAE,gBAAI,EAAEF,WAAW,EAAE;EAClBG,iBAAiB,EAAjBA;AACD,CAAE,CAAC"}
@@ -26,9 +26,19 @@ const STORE_NAME = 'core/commands';
26
26
  /**
27
27
  * Store definition for the commands namespace.
28
28
  *
29
+ * See how the Commands Store is being used in components like [site-hub](https://github.com/WordPress/gutenberg/blob/HEAD/packages/edit-site/src/components/site-hub/index.js#L23) and [document-actions](https://github.com/WordPress/gutenberg/blob/HEAD/packages/edit-post/src/components/header/document-actions/index.js#L14).
30
+ *
29
31
  * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
30
32
  *
31
33
  * @type {Object}
34
+ *
35
+ * @example
36
+ * ```js
37
+ * import { store as commandsStore } from '@wordpress/commands';
38
+ * import { useDispatch } from '@wordpress/data';
39
+ * ...
40
+ * const { open: openCommandCenter } = useDispatch( commandsStore );
41
+ * ```
32
42
  */
33
43
  const store = (0, _data.createReduxStore)(STORE_NAME, {
34
44
  reducer: _reducer.default,
@@ -1 +1 @@
1
- {"version":3,"names":["_data","require","_reducer","_interopRequireDefault","actions","_interopRequireWildcard","selectors","privateActions","_lockUnlock","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","STORE_NAME","store","createReduxStore","reducer","exports","register","unlock","registerPrivateActions"],"sources":["@wordpress/commands/src/store/index.js"],"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 */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\nunlock( store ).registerPrivateActions( privateActions );\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,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GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA;AAZxC;AACA;AACA;;AAGA;AACA;AACA;;AAOA,MAAMW,UAAU,GAAG,eAAe;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,KAAK,GAAG,IAAAC,sBAAgB,EAAEF,UAAU,EAAE;EAClDG,OAAO,EAAPA,gBAAO;EACP9B,OAAO;EACPE;AACD,CAAE,CAAC;AAAC6B,OAAA,CAAAH,KAAA,GAAAA,KAAA;AAEJ,IAAAI,cAAQ,EAAEJ,KAAM,CAAC;AACjB,IAAAK,kBAAM,EAAEL,KAAM,CAAC,CAACM,sBAAsB,CAAE/B,cAAe,CAAC"}
1
+ {"version":3,"names":["_data","require","_reducer","_interopRequireDefault","actions","_interopRequireWildcard","selectors","privateActions","_lockUnlock","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","STORE_NAME","store","createReduxStore","reducer","exports","register","unlock","registerPrivateActions"],"sources":["@wordpress/commands/src/store/index.js"],"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 how the Commands Store is being used in components like [site-hub](https://github.com/WordPress/gutenberg/blob/HEAD/packages/edit-site/src/components/site-hub/index.js#L23) and [document-actions](https://github.com/WordPress/gutenberg/blob/HEAD/packages/edit-post/src/components/header/document-actions/index.js#L14).\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"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAC,uBAAA,CAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAD,uBAAA,CAAAJ,OAAA;AACA,IAAAM,cAAA,GAAAF,uBAAA,CAAAJ,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AAAwC,SAAAQ,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAL,wBAAAS,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA;AAZxC;AACA;AACA;;AAGA;AACA;AACA;;AAOA,MAAMW,UAAU,GAAG,eAAe;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,KAAK,GAAG,IAAAC,sBAAgB,EAAEF,UAAU,EAAE;EAClDG,OAAO,EAAPA,gBAAO;EACP9B,OAAO;EACPE;AACD,CAAE,CAAC;AAAC6B,OAAA,CAAAH,KAAA,GAAAA,KAAA;AAEJ,IAAAI,cAAQ,EAAEJ,KAAM,CAAC;AACjB,IAAAK,kBAAM,EAAEL,KAAM,CAAC,CAACM,sBAAsB,CAAE/B,cAAe,CAAC"}
@@ -164,6 +164,10 @@ function CommandInput({
164
164
  icon: search
165
165
  });
166
166
  }
167
+
168
+ /**
169
+ * @ignore
170
+ */
167
171
  export function CommandMenu() {
168
172
  const {
169
173
  registerShortcut
@@ -1 +1 @@
1
- {"version":3,"names":["Command","useCommandState","classnames","useSelect","useDispatch","useState","useEffect","useRef","useCallback","useMemo","__","Modal","TextHighlight","__experimentalHStack","HStack","store","keyboardShortcutsStore","useShortcut","Icon","search","inputIcon","commandsStore","CommandMenuLoader","name","hook","setLoader","close","_hook","isLoading","commands","length","createElement","Fragment","List","map","command","_command$searchLabel","Item","key","value","searchLabel","label","onSelect","callback","id","alignment","className","icon","text","highlight","CommandMenuLoaderWrapper","currentLoader","setKey","current","prevKey","CommandMenuGroup","isContextual","loaders","select","getCommands","getCommandLoaders","Group","_command$searchLabel2","loader","CommandInput","isOpen","setSearch","commandMenuInput","_value","state","selectedItemId","item","document","querySelector","getAttribute","focus","Input","ref","onValueChange","placeholder","CommandMenu","registerShortcut","open","setLoaders","category","description","keyCombination","modifier","character","event","defaultPrevented","preventDefault","bindGlobal","closeAndReset","onKeyDown","nativeEvent","isComposing","keyCode","Object","values","some","Boolean","overlayClassName","onRequestClose","__experimentalHideHeader","Empty"],"sources":["@wordpress/commands/src/components/command-menu.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { Command, useCommandState } from 'cmdk';\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseState,\n\tuseEffect,\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tModal,\n\tTextHighlight,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { Icon, search as inputIcon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\nfunction CommandMenuLoader( { name, search, hook, setLoader, close } ) {\n\tconst { isLoading, commands = [] } = hook( { search } ) ?? {};\n\tuseEffect( () => {\n\t\tsetLoader( name, isLoading );\n\t}, [ setLoader, name, isLoading ] );\n\n\tif ( ! commands.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Command.List>\n\t\t\t\t{ commands.map( ( command ) => (\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\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={ classnames(\n\t\t\t\t\t\t\t\t'commands-command-menu__item',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t\t<span>\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</HStack>\n\t\t\t\t\t</Command.Item>\n\t\t\t\t) ) }\n\t\t\t</Command.List>\n\t\t</>\n\t);\n}\n\nexport function CommandMenuLoaderWrapper( { hook, search, setLoader, close } ) {\n\t// The \"hook\" prop is actually a custom React hook\n\t// so to avoid breaking the rules of hooks\n\t// the CommandMenuLoaderWrapper component need to be\n\t// remounted on each hook prop change\n\t// We use the key state to make sure we do that properly.\n\tconst currentLoader = useRef( hook );\n\tconst [ key, setKey ] = useState( 0 );\n\tuseEffect( () => {\n\t\tif ( currentLoader.current !== hook ) {\n\t\t\tcurrentLoader.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={ currentLoader.current }\n\t\t\tsearch={ search }\n\t\t\tsetLoader={ setLoader }\n\t\t\tclose={ close }\n\t\t/>\n\t);\n}\n\nexport function CommandMenuGroup( { isContextual, search, setLoader, close } ) {\n\tconst { commands, loaders } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCommands, getCommandLoaders } = select( commandsStore );\n\t\t\treturn {\n\t\t\t\tcommands: getCommands( isContextual ),\n\t\t\t\tloaders: getCommandLoaders( isContextual ),\n\t\t\t};\n\t\t},\n\t\t[ isContextual ]\n\t);\n\n\tif ( ! commands.length && ! loaders.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Command.Group>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\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={ classnames( 'commands-command-menu__item', {\n\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t\t{ loaders.map( ( loader ) => (\n\t\t\t\t<CommandMenuLoaderWrapper\n\t\t\t\t\tkey={ loader.name }\n\t\t\t\t\thook={ loader.hook }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\tclose={ close }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Command.Group>\n\t);\n}\n\nfunction CommandInput( { isOpen, search, setSearch } ) {\n\tconst commandMenuInput = useRef();\n\tconst _value = useCommandState( ( state ) => state.value );\n\tconst selectedItemId = useMemo( () => {\n\t\tconst item = document.querySelector(\n\t\t\t`[cmdk-item=\"\"][data-value=\"${ _value }\"]`\n\t\t);\n\t\treturn item?.getAttribute( 'id' );\n\t}, [ _value ] );\n\tuseEffect( () => {\n\t\t// Focus the command palette input when mounting the modal.\n\t\tif ( isOpen ) {\n\t\t\tcommandMenuInput.current.focus();\n\t\t}\n\t}, [ isOpen ] );\n\treturn (\n\t\t<Command.Input\n\t\t\tref={ commandMenuInput }\n\t\t\tvalue={ search }\n\t\t\tonValueChange={ setSearch }\n\t\t\tplaceholder={ __( 'Search for commands' ) }\n\t\t\taria-activedescendant={ selectedItemId }\n\t\t\ticon={ search }\n\t\t/>\n\t);\n}\n\nexport function CommandMenu() {\n\tconst { registerShortcut } = useDispatch( keyboardShortcutsStore );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst isOpen = useSelect(\n\t\t( select ) => select( commandsStore ).isOpen(),\n\t\t[]\n\t);\n\tconst { open, close } = useDispatch( commandsStore );\n\tconst [ loaders, setLoaders ] = useState( {} );\n\n\tuseEffect( () => {\n\t\tregisterShortcut( {\n\t\t\tname: 'core/commands',\n\t\t\tcategory: 'global',\n\t\t\tdescription: __( 'Open the command palette.' ),\n\t\t\tkeyCombination: {\n\t\t\t\tmodifier: 'primary',\n\t\t\t\tcharacter: 'k',\n\t\t\t},\n\t\t} );\n\t}, [ registerShortcut ] );\n\n\tuseShortcut(\n\t\t'core/commands',\n\t\t/** @type {import('react').KeyboardEventHandler} */\n\t\t( event ) => {\n\t\t\t// Bails to avoid obscuring the effect of the preceding handler(s).\n\t\t\tif ( event.defaultPrevented ) return;\n\n\t\t\tevent.preventDefault();\n\t\t\tif ( isOpen ) {\n\t\t\t\tclose();\n\t\t\t} else {\n\t\t\t\topen();\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tbindGlobal: true,\n\t\t}\n\t);\n\n\tconst setLoader = useCallback(\n\t\t( name, value ) =>\n\t\t\tsetLoaders( ( current ) => ( {\n\t\t\t\t...current,\n\t\t\t\t[ name ]: value,\n\t\t\t} ) ),\n\t\t[]\n\t);\n\tconst closeAndReset = () => {\n\t\tsetSearch( '' );\n\t\tclose();\n\t};\n\n\tif ( ! isOpen ) {\n\t\treturn false;\n\t}\n\n\tconst onKeyDown = ( event ) => {\n\t\tif (\n\t\t\t// Ignore keydowns from IMEs\n\t\t\tevent.nativeEvent.isComposing ||\n\t\t\t// Workaround for Mac Safari where the final Enter/Backspace of an IME composition\n\t\t\t// is `isComposing=false`, even though it's technically still part of the composition.\n\t\t\t// These can only be detected by keyCode.\n\t\t\tevent.keyCode === 229\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\tconst isLoading = Object.values( loaders ).some( Boolean );\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"commands-command-menu\"\n\t\t\toverlayClassName=\"commands-command-menu__overlay\"\n\t\t\tonRequestClose={ closeAndReset }\n\t\t\t__experimentalHideHeader\n\t\t>\n\t\t\t<div className=\"commands-command-menu__container\">\n\t\t\t\t<Command\n\t\t\t\t\tlabel={ __( 'Command palette' ) }\n\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t>\n\t\t\t\t\t<div className=\"commands-command-menu__header\">\n\t\t\t\t\t\t<Icon icon={ inputIcon } />\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>\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={ closeAndRe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W;IACvBD,MAAM,EAAGA;EAAQ,CACjB,CACG,CAAC,EACNlC,aAAA,CAAC/B,OAAO,CAACiC,IAAI,QACVd,MAAM,IAAI,CAAES,SAAS,IACtBG,aAAA,CAAC/B,OAAO,CAACyG,KAAK,QACX/F,EAAE,CAAE,mBAAoB,CACZ,CACf,EACDqB,aAAA,CAACwB,gBAAgB;IAChBpC,MAAM,EAAGA,MAAQ;IACjBM,SAAS,EAAGA,SAAW;IACvBC,KAAK,EAAGmE,aAAe;IACvBrC,YAAY;EAAA,CACZ,CAAC,EACArC,MAAM,IACPY,aAAA,CAACwB,gBAAgB;IAChBpC,MAAM,EAAGA,MAAQ;IACjBM,SAAS,EAAGA,SAAW;IACvBC,KAAK,EAAGmE;EAAe,CACvB,CAEW,CACN,CACL,CACC,CAAC;AAEV"}
1
+ {"version":3,"names":["Command","useCommandState","classnames","useSelect","useDispatch","useState","useEffect","useRef","useCallback","useMemo","__","Modal","TextHighlight","__experimentalHStack","HStack","store","keyboardShortcutsStore","useShortcut","Icon","search","inputIcon","commandsStore","CommandMenuLoader","name","hook","setLoader","close","_hook","isLoading","commands","length","createElement","Fragment","List","map","command","_command$searchLabel","Item","key","value","searchLabel","label","onSelect","callback","id","alignment","className","icon","text","highlight","CommandMenuLoaderWrapper","currentLoader","setKey","current","prevKey","CommandMenuGroup","isContextual","loaders","select","getCommands","getCommandLoaders","Group","_command$searchLabel2","loader","CommandInput","isOpen","setSearch","commandMenuInput","_value","state","selectedItemId","item","document","querySelector","getAttribute","focus","Input","ref","onValueChange","placeholder","CommandMenu","registerShortcut","open","setLoaders","category","description","keyCombination","modifier","character","event","defaultPrevented","preventDefault","bindGlobal","closeAndReset","onKeyDown","nativeEvent","isComposing","keyCode","Object","values","some","Boolean","overlayClassName","onRequestClose","__experimentalHideHeader","Empty"],"sources":["@wordpress/commands/src/components/command-menu.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { Command, useCommandState } from 'cmdk';\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseState,\n\tuseEffect,\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tModal,\n\tTextHighlight,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { Icon, search as inputIcon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\nfunction CommandMenuLoader( { name, search, hook, setLoader, close } ) {\n\tconst { isLoading, commands = [] } = hook( { search } ) ?? {};\n\tuseEffect( () => {\n\t\tsetLoader( name, isLoading );\n\t}, [ setLoader, name, isLoading ] );\n\n\tif ( ! commands.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Command.List>\n\t\t\t\t{ commands.map( ( command ) => (\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\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={ classnames(\n\t\t\t\t\t\t\t\t'commands-command-menu__item',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t\t<span>\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</HStack>\n\t\t\t\t\t</Command.Item>\n\t\t\t\t) ) }\n\t\t\t</Command.List>\n\t\t</>\n\t);\n}\n\nexport function CommandMenuLoaderWrapper( { hook, search, setLoader, close } ) {\n\t// The \"hook\" prop is actually a custom React hook\n\t// so to avoid breaking the rules of hooks\n\t// the CommandMenuLoaderWrapper component need to be\n\t// remounted on each hook prop change\n\t// We use the key state to make sure we do that properly.\n\tconst currentLoader = useRef( hook );\n\tconst [ key, setKey ] = useState( 0 );\n\tuseEffect( () => {\n\t\tif ( currentLoader.current !== hook ) {\n\t\t\tcurrentLoader.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={ currentLoader.current }\n\t\t\tsearch={ search }\n\t\t\tsetLoader={ setLoader }\n\t\t\tclose={ close }\n\t\t/>\n\t);\n}\n\nexport function CommandMenuGroup( { isContextual, search, setLoader, close } ) {\n\tconst { commands, loaders } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCommands, getCommandLoaders } = select( commandsStore );\n\t\t\treturn {\n\t\t\t\tcommands: getCommands( isContextual ),\n\t\t\t\tloaders: getCommandLoaders( isContextual ),\n\t\t\t};\n\t\t},\n\t\t[ isContextual ]\n\t);\n\n\tif ( ! commands.length && ! loaders.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Command.Group>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\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={ classnames( 'commands-command-menu__item', {\n\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t\t{ loaders.map( ( loader ) => (\n\t\t\t\t<CommandMenuLoaderWrapper\n\t\t\t\t\tkey={ loader.name }\n\t\t\t\t\thook={ loader.hook }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\tclose={ close }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Command.Group>\n\t);\n}\n\nfunction CommandInput( { isOpen, search, setSearch } ) {\n\tconst commandMenuInput = useRef();\n\tconst _value = useCommandState( ( state ) => state.value );\n\tconst selectedItemId = useMemo( () => {\n\t\tconst item = document.querySelector(\n\t\t\t`[cmdk-item=\"\"][data-value=\"${ _value }\"]`\n\t\t);\n\t\treturn item?.getAttribute( 'id' );\n\t}, [ _value ] );\n\tuseEffect( () => {\n\t\t// Focus the command palette input when mounting the modal.\n\t\tif ( isOpen ) {\n\t\t\tcommandMenuInput.current.focus();\n\t\t}\n\t}, [ isOpen ] );\n\treturn (\n\t\t<Command.Input\n\t\t\tref={ commandMenuInput }\n\t\t\tvalue={ search }\n\t\t\tonValueChange={ setSearch }\n\t\t\tplaceholder={ __( 'Search for commands' ) }\n\t\t\taria-activedescendant={ selectedItemId }\n\t\t\ticon={ search }\n\t\t/>\n\t);\n}\n\n/**\n * @ignore\n */\nexport function CommandMenu() {\n\tconst { registerShortcut } = useDispatch( keyboardShortcutsStore );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst isOpen = useSelect(\n\t\t( select ) => select( commandsStore ).isOpen(),\n\t\t[]\n\t);\n\tconst { open, close } = useDispatch( commandsStore );\n\tconst [ loaders, setLoaders ] = useState( {} );\n\n\tuseEffect( () => {\n\t\tregisterShortcut( {\n\t\t\tname: 'core/commands',\n\t\t\tcategory: 'global',\n\t\t\tdescription: __( 'Open the command palette.' ),\n\t\t\tkeyCombination: {\n\t\t\t\tmodifier: 'primary',\n\t\t\t\tcharacter: 'k',\n\t\t\t},\n\t\t} );\n\t}, [ registerShortcut ] );\n\n\tuseShortcut(\n\t\t'core/commands',\n\t\t/** @type {import('react').KeyboardEventHandler} */\n\t\t( event ) => {\n\t\t\t// Bails to avoid obscuring the effect of the preceding handler(s).\n\t\t\tif ( event.defaultPrevented ) return;\n\n\t\t\tevent.preventDefault();\n\t\t\tif ( isOpen ) {\n\t\t\t\tclose();\n\t\t\t} else {\n\t\t\t\topen();\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tbindGlobal: true,\n\t\t}\n\t);\n\n\tconst setLoader = useCallback(\n\t\t( name, value ) =>\n\t\t\tsetLoaders( ( current ) => ( {\n\t\t\t\t...current,\n\t\t\t\t[ name ]: value,\n\t\t\t} ) ),\n\t\t[]\n\t);\n\tconst closeAndReset = () => {\n\t\tsetSearch( '' );\n\t\tclose();\n\t};\n\n\tif ( ! isOpen ) {\n\t\treturn false;\n\t}\n\n\tconst onKeyDown = ( event ) => {\n\t\tif (\n\t\t\t// Ignore keydowns from IMEs\n\t\t\tevent.nativeEvent.isComposing ||\n\t\t\t// Workaround for Mac Safari where the final Enter/Backspace of an IME composition\n\t\t\t// is `isComposing=false`, even though it's technically still part of the composition.\n\t\t\t// These can only be detected by keyCode.\n\t\t\tevent.keyCode === 229\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\tconst isLoading = Object.values( loaders ).some( Boolean );\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"commands-command-menu\"\n\t\t\toverlayClassName=\"commands-command-menu__overlay\"\n\t\t\tonRequestClose={ closeAndReset }\n\t\t\t__experimentalHideHeader\n\t\t>\n\t\t\t<div className=\"commands-command-menu__container\">\n\t\t\t\t<Command\n\t\t\t\t\tlabel={ __( 'Command palette' ) }\n\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t>\n\t\t\t\t\t<div className=\"commands-command-menu__header\">\n\t\t\t\t\t\t<Icon icon={ inputIcon } />\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>\n\t\t\t\t\t\t{ search && ! isLoading && (\n\t\t\t\t\t\t\t<Command.Empty>\n\t\t\t\t\t\t\t\t{ __( 'No results found.' ) }\n\t\t\t\t\t\t\t</Command.Empty>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\tisContextual\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ search && (\n\t\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Command.List>\n\t\t\t\t</Command>\n\t\t\t</div>\n\t\t</Modal>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,eAAe,QAAQ,MAAM;AAC/C,OAAOC,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SACCC,QAAQ,EACRC,SAAS,EACTC,MAAM,EACNC,WAAW,EACXC,OAAO,QACD,oBAAoB;AAC3B,SAASC,EAAE,QAAQ,iBAAiB;AACpC,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AAM,EAAGA,MAAQ;IACjBM,SAAS,EAAGA,SAAW;IACvBC,KAAK,EAAGmE;EAAe,CACvB,CAEW,CACN,CACL,CACC,CAAC;AAEV"}
@@ -10,9 +10,73 @@ import { useDispatch } from '@wordpress/data';
10
10
  import { store as commandsStore } from '../store';
11
11
 
12
12
  /**
13
- * Attach a command loader to the command palette.
13
+ * Attach a command loader to the command palette. Used for dynamic commands.
14
14
  *
15
15
  * @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.
16
+ *
17
+ * @example
18
+ * ```js
19
+ * import { useCommandLoader } from '@wordpress/commands';
20
+ * import { post, page, layout, symbolFilled } from '@wordpress/icons';
21
+ *
22
+ * const icons = {
23
+ * post,
24
+ * page,
25
+ * wp_template: layout,
26
+ * wp_template_part: symbolFilled,
27
+ * };
28
+ *
29
+ * function usePageSearchCommandLoader( { search } ) {
30
+ * // Retrieve the pages for the "search" term.
31
+ * const { records, isLoading } = useSelect( ( select ) => {
32
+ * const { getEntityRecords } = select( coreStore );
33
+ * const query = {
34
+ * search: !! search ? search : undefined,
35
+ * per_page: 10,
36
+ * orderby: search ? 'relevance' : 'date',
37
+ * };
38
+ * return {
39
+ * records: getEntityRecords( 'postType', 'page', query ),
40
+ * isLoading: ! select( coreStore ).hasFinishedResolution(
41
+ * 'getEntityRecords',
42
+ * 'postType', 'page', query ]
43
+ * ),
44
+ * };
45
+ * }, [ search ] );
46
+ *
47
+ * // Create the commands.
48
+ * const commands = useMemo( () => {
49
+ * return ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {
50
+ * return {
51
+ * name: record.title?.rendered + ' ' + record.id,
52
+ * label: record.title?.rendered
53
+ * ? record.title?.rendered
54
+ * : __( '(no title)' ),
55
+ * icon: icons[ postType ],
56
+ * callback: ( { close } ) => {
57
+ * const args = {
58
+ * postType,
59
+ * postId: record.id,
60
+ * ...extraArgs,
61
+ * };
62
+ * document.location = addQueryArgs( 'site-editor.php', args );
63
+ * close();
64
+ * },
65
+ * };
66
+ * } );
67
+ * }, [ records, history ] );
68
+ *
69
+ * return {
70
+ * commands,
71
+ * isLoading,
72
+ * };
73
+ * }
74
+ *
75
+ * useCommandLoader( {
76
+ * name: 'myplugin/page-search',
77
+ * hook: usePageSearchCommandLoader,
78
+ * } );
79
+ * ```
16
80
  */
17
81
  export default function useCommandLoader(loader) {
18
82
  const {
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useDispatch","store","commandsStore","useCommandLoader","loader","registerCommandLoader","unregisterCommandLoader","name","hook","context"],"sources":["@wordpress/commands/src/hooks/use-command-loader.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Attach a command loader to the command palette.\n *\n * @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.\n */\nexport default function useCommandLoader( loader ) {\n\tconst { registerCommandLoader, unregisterCommandLoader } =\n\t\tuseDispatch( commandsStore );\n\tuseEffect( () => {\n\t\tregisterCommandLoader( {\n\t\t\tname: loader.name,\n\t\t\thook: loader.hook,\n\t\t\tcontext: loader.context,\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommandLoader( loader.name );\n\t\t};\n\t}, [\n\t\tloader.name,\n\t\tloader.hook,\n\t\tloader.context,\n\t\tregisterCommandLoader,\n\t\tunregisterCommandLoader,\n\t] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,oBAAoB;AAC9C,SAASC,WAAW,QAAQ,iBAAiB;;AAE7C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,aAAa,QAAQ,UAAU;;AAEjD;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,gBAAgBA,CAAEC,MAAM,EAAG;EAClD,MAAM;IAAEC,qBAAqB;IAAEC;EAAwB,CAAC,GACvDN,WAAW,CAAEE,aAAc,CAAC;EAC7BH,SAAS,CAAE,MAAM;IAChBM,qBAAqB,CAAE;MACtBE,IAAI,EAAEH,MAAM,CAACG,IAAI;MACjBC,IAAI,EAAEJ,MAAM,CAACI,IAAI;MACjBC,OAAO,EAAEL,MAAM,CAACK;IACjB,CAAE,CAAC;IACH,OAAO,MAAM;MACZH,uBAAuB,CAAEF,MAAM,CAACG,IAAK,CAAC;IACvC,CAAC;EACF,CAAC,EAAE,CACFH,MAAM,CAACG,IAAI,EACXH,MAAM,CAACI,IAAI,EACXJ,MAAM,CAACK,OAAO,EACdJ,qBAAqB,EACrBC,uBAAuB,CACtB,CAAC;AACJ"}
1
+ {"version":3,"names":["useEffect","useDispatch","store","commandsStore","useCommandLoader","loader","registerCommandLoader","unregisterCommandLoader","name","hook","context"],"sources":["@wordpress/commands/src/hooks/use-command-loader.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Attach a command loader to the command palette. Used for dynamic commands.\n *\n * @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.\n *\n * @example\n * ```js\n * import { useCommandLoader } from '@wordpress/commands';\n * import { post, page, layout, symbolFilled } from '@wordpress/icons';\n *\n * const icons = {\n * post,\n * page,\n * wp_template: layout,\n * wp_template_part: symbolFilled,\n * };\n *\n * function usePageSearchCommandLoader( { search } ) {\n * // Retrieve the pages for the \"search\" term.\n * const { records, isLoading } = useSelect( ( select ) => {\n * const { getEntityRecords } = select( coreStore );\n * const query = {\n * search: !! search ? search : undefined,\n * per_page: 10,\n * orderby: search ? 'relevance' : 'date',\n * };\n * return {\n * records: getEntityRecords( 'postType', 'page', query ),\n * isLoading: ! select( coreStore ).hasFinishedResolution(\n * 'getEntityRecords',\n * 'postType', 'page', query ]\n * ),\n * };\n * }, [ search ] );\n *\n * // Create the commands.\n * const commands = useMemo( () => {\n * return ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {\n * return {\n * name: record.title?.rendered + ' ' + record.id,\n * label: record.title?.rendered\n * ? record.title?.rendered\n * : __( '(no title)' ),\n * icon: icons[ postType ],\n * callback: ( { close } ) => {\n * const args = {\n * postType,\n * postId: record.id,\n * ...extraArgs,\n * };\n * document.location = addQueryArgs( 'site-editor.php', args );\n * close();\n * },\n * };\n * } );\n * }, [ records, history ] );\n *\n * return {\n * commands,\n * isLoading,\n * };\n * }\n *\n * useCommandLoader( {\n * name: 'myplugin/page-search',\n * hook: usePageSearchCommandLoader,\n * } );\n * ```\n */\nexport default function useCommandLoader( loader ) {\n\tconst { registerCommandLoader, unregisterCommandLoader } =\n\t\tuseDispatch( commandsStore );\n\tuseEffect( () => {\n\t\tregisterCommandLoader( {\n\t\t\tname: loader.name,\n\t\t\thook: loader.hook,\n\t\t\tcontext: loader.context,\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommandLoader( loader.name );\n\t\t};\n\t}, [\n\t\tloader.name,\n\t\tloader.hook,\n\t\tloader.context,\n\t\tregisterCommandLoader,\n\t\tunregisterCommandLoader,\n\t] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,oBAAoB;AAC9C,SAASC,WAAW,QAAQ,iBAAiB;;AAE7C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,aAAa,QAAQ,UAAU;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,gBAAgBA,CAAEC,MAAM,EAAG;EAClD,MAAM;IAAEC,qBAAqB;IAAEC;EAAwB,CAAC,GACvDN,WAAW,CAAEE,aAAc,CAAC;EAC7BH,SAAS,CAAE,MAAM;IAChBM,qBAAqB,CAAE;MACtBE,IAAI,EAAEH,MAAM,CAACG,IAAI;MACjBC,IAAI,EAAEJ,MAAM,CAACI,IAAI;MACjBC,OAAO,EAAEL,MAAM,CAACK;IACjB,CAAE,CAAC;IACH,OAAO,MAAM;MACZH,uBAAuB,CAAEF,MAAM,CAACG,IAAK,CAAC;IACvC,CAAC;EACF,CAAC,EAAE,CACFH,MAAM,CAACG,IAAI,EACXH,MAAM,CAACI,IAAI,EACXJ,MAAM,CAACK,OAAO,EACdJ,qBAAqB,EACrBC,uBAAuB,CACtB,CAAC;AACJ"}
@@ -10,9 +10,25 @@ import { useDispatch } from '@wordpress/data';
10
10
  import { store as commandsStore } from '../store';
11
11
 
12
12
  /**
13
- * Attach a command to the command palette.
13
+ * Attach a command to the command palette. Used for static commands.
14
14
  *
15
15
  * @param {import('../store/actions').WPCommandConfig} command command config.
16
+ *
17
+ * @example
18
+ * ```js
19
+ * import { useCommand } from '@wordpress/commands';
20
+ * import { plus } from '@wordpress/icons';
21
+ *
22
+ * useCommand( {
23
+ * name: 'myplugin/my-command-name',
24
+ * label: __( 'Add new post' ),
25
+ * icon: plus,
26
+ * callback: ({ close }) => {
27
+ * document.location.href = 'post-new.php';
28
+ * close();
29
+ * },
30
+ * } );
31
+ * ```
16
32
  */
17
33
  export default function useCommand(command) {
18
34
  const {
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useRef","useDispatch","store","commandsStore","useCommand","command","registerCommand","unregisterCommand","currentCallback","callback","current","name","context","label","searchLabel","icon","args"],"sources":["@wordpress/commands/src/hooks/use-command.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Attach a command to the command palette.\n *\n * @param {import('../store/actions').WPCommandConfig} command command config.\n */\nexport default function useCommand( command ) {\n\tconst { registerCommand, unregisterCommand } = useDispatch( commandsStore );\n\tconst currentCallback = useRef( command.callback );\n\tuseEffect( () => {\n\t\tcurrentCallback.current = command.callback;\n\t}, [ command.callback ] );\n\n\tuseEffect( () => {\n\t\tregisterCommand( {\n\t\t\tname: command.name,\n\t\t\tcontext: command.context,\n\t\t\tlabel: command.label,\n\t\t\tsearchLabel: command.searchLabel,\n\t\t\ticon: command.icon,\n\t\t\tcallback: ( ...args ) => currentCallback.current( ...args ),\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommand( command.name );\n\t\t};\n\t}, [\n\t\tcommand.name,\n\t\tcommand.label,\n\t\tcommand.searchLabel,\n\t\tcommand.icon,\n\t\tcommand.context,\n\t\tregisterCommand,\n\t\tunregisterCommand,\n\t] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,MAAM,QAAQ,oBAAoB;AACtD,SAASC,WAAW,QAAQ,iBAAiB;;AAE7C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,aAAa,QAAQ,UAAU;;AAEjD;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,UAAUA,CAAEC,OAAO,EAAG;EAC7C,MAAM;IAAEC,eAAe;IAAEC;EAAkB,CAAC,GAAGN,WAAW,CAAEE,aAAc,CAAC;EAC3E,MAAMK,eAAe,GAAGR,MAAM,CAAEK,OAAO,CAACI,QAAS,CAAC;EAClDV,SAAS,CAAE,MAAM;IAChBS,eAAe,CAACE,OAAO,GAAGL,OAAO,CAACI,QAAQ;EAC3C,CAAC,EAAE,CAAEJ,OAAO,CAACI,QAAQ,CAAG,CAAC;EAEzBV,SAAS,CAAE,MAAM;IAChBO,eAAe,CAAE;MAChBK,IAAI,EAAEN,OAAO,CAACM,IAAI;MAClBC,OAAO,EAAEP,OAAO,CAACO,OAAO;MACxBC,KAAK,EAAER,OAAO,CAACQ,KAAK;MACpBC,WAAW,EAAET,OAAO,CAACS,WAAW;MAChCC,IAAI,EAAEV,OAAO,CAACU,IAAI;MAClBN,QAAQ,EAAEA,CAAE,GAAGO,IAAI,KAAMR,eAAe,CAACE,OAAO,CAAE,GAAGM,IAAK;IAC3D,CAAE,CAAC;IACH,OAAO,MAAM;MACZT,iBAAiB,CAAEF,OAAO,CAACM,IAAK,CAAC;IAClC,CAAC;EACF,CAAC,EAAE,CACFN,OAAO,CAACM,IAAI,EACZN,OAAO,CAACQ,KAAK,EACbR,OAAO,CAACS,WAAW,EACnBT,OAAO,CAACU,IAAI,EACZV,OAAO,CAACO,OAAO,EACfN,eAAe,EACfC,iBAAiB,CAChB,CAAC;AACJ"}
1
+ {"version":3,"names":["useEffect","useRef","useDispatch","store","commandsStore","useCommand","command","registerCommand","unregisterCommand","currentCallback","callback","current","name","context","label","searchLabel","icon","args"],"sources":["@wordpress/commands/src/hooks/use-command.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Attach a command to the command palette. Used for static commands.\n *\n * @param {import('../store/actions').WPCommandConfig} command command config.\n *\n * @example\n * ```js\n * import { useCommand } from '@wordpress/commands';\n * import { plus } from '@wordpress/icons';\n *\n * useCommand( {\n * name: 'myplugin/my-command-name',\n * label: __( 'Add new post' ),\n *\t icon: plus,\n * callback: ({ close }) => {\n * document.location.href = 'post-new.php';\n * close();\n * },\n * } );\n * ```\n */\nexport default function useCommand( command ) {\n\tconst { registerCommand, unregisterCommand } = useDispatch( commandsStore );\n\tconst currentCallback = useRef( command.callback );\n\tuseEffect( () => {\n\t\tcurrentCallback.current = command.callback;\n\t}, [ command.callback ] );\n\n\tuseEffect( () => {\n\t\tregisterCommand( {\n\t\t\tname: command.name,\n\t\t\tcontext: command.context,\n\t\t\tlabel: command.label,\n\t\t\tsearchLabel: command.searchLabel,\n\t\t\ticon: command.icon,\n\t\t\tcallback: ( ...args ) => currentCallback.current( ...args ),\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommand( command.name );\n\t\t};\n\t}, [\n\t\tcommand.name,\n\t\tcommand.label,\n\t\tcommand.searchLabel,\n\t\tcommand.icon,\n\t\tcommand.context,\n\t\tregisterCommand,\n\t\tunregisterCommand,\n\t] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,MAAM,QAAQ,oBAAoB;AACtD,SAASC,WAAW,QAAQ,iBAAiB;;AAE7C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,aAAa,QAAQ,UAAU;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,UAAUA,CAAEC,OAAO,EAAG;EAC7C,MAAM;IAAEC,eAAe;IAAEC;EAAkB,CAAC,GAAGN,WAAW,CAAEE,aAAc,CAAC;EAC3E,MAAMK,eAAe,GAAGR,MAAM,CAAEK,OAAO,CAACI,QAAS,CAAC;EAClDV,SAAS,CAAE,MAAM;IAChBS,eAAe,CAACE,OAAO,GAAGL,OAAO,CAACI,QAAQ;EAC3C,CAAC,EAAE,CAAEJ,OAAO,CAACI,QAAQ,CAAG,CAAC;EAEzBV,SAAS,CAAE,MAAM;IAChBO,eAAe,CAAE;MAChBK,IAAI,EAAEN,OAAO,CAACM,IAAI;MAClBC,OAAO,EAAEP,OAAO,CAACO,OAAO;MACxBC,KAAK,EAAER,OAAO,CAACQ,KAAK;MACpBC,WAAW,EAAET,OAAO,CAACS,WAAW;MAChCC,IAAI,EAAEV,OAAO,CAACU,IAAI;MAClBN,QAAQ,EAAEA,CAAE,GAAGO,IAAI,KAAMR,eAAe,CAACE,OAAO,CAAE,GAAGM,IAAK;IAC3D,CAAE,CAAC;IACH,OAAO,MAAM;MACZT,iBAAiB,CAAEF,OAAO,CAACM,IAAK,CAAC;IAClC,CAAC;EACF,CAAC,EAAE,CACFN,OAAO,CAACM,IAAI,EACZN,OAAO,CAACQ,KAAK,EACbR,OAAO,CAACS,WAAW,EACnBT,OAAO,CAACU,IAAI,EACZV,OAAO,CAACO,OAAO,EACfN,eAAe,EACfC,iBAAiB,CAChB,CAAC;AACJ"}
@@ -3,6 +3,10 @@
3
3
  */
4
4
  import { default as useCommandContext } from './hooks/use-command-context';
5
5
  import { lock } from './lock-unlock';
6
+
7
+ /**
8
+ * @private
9
+ */
6
10
  export const privateApis = {};
7
11
  lock(privateApis, {
8
12
  useCommandContext
@@ -1 +1 @@
1
- {"version":3,"names":["default","useCommandContext","lock","privateApis"],"sources":["@wordpress/commands/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { default as useCommandContext } from './hooks/use-command-context';\nimport { lock } from './lock-unlock';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tuseCommandContext,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,IAAIC,iBAAiB,QAAQ,6BAA6B;AAC1E,SAASC,IAAI,QAAQ,eAAe;AAEpC,OAAO,MAAMC,WAAW,GAAG,CAAC,CAAC;AAC7BD,IAAI,CAAEC,WAAW,EAAE;EAClBF;AACD,CAAE,CAAC"}
1
+ {"version":3,"names":["default","useCommandContext","lock","privateApis"],"sources":["@wordpress/commands/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { default as useCommandContext } from './hooks/use-command-context';\nimport { lock } from './lock-unlock';\n\n/**\n * @private\n */\nexport const privateApis = {};\nlock( privateApis, {\n\tuseCommandContext,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,IAAIC,iBAAiB,QAAQ,6BAA6B;AAC1E,SAASC,IAAI,QAAQ,eAAe;;AAEpC;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GAAG,CAAC,CAAC;AAC7BD,IAAI,CAAEC,WAAW,EAAE;EAClBF;AACD,CAAE,CAAC"}
@@ -16,9 +16,19 @@ const STORE_NAME = 'core/commands';
16
16
  /**
17
17
  * Store definition for the commands namespace.
18
18
  *
19
+ * See how the Commands Store is being used in components like [site-hub](https://github.com/WordPress/gutenberg/blob/HEAD/packages/edit-site/src/components/site-hub/index.js#L23) and [document-actions](https://github.com/WordPress/gutenberg/blob/HEAD/packages/edit-post/src/components/header/document-actions/index.js#L14).
20
+ *
19
21
  * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
20
22
  *
21
23
  * @type {Object}
24
+ *
25
+ * @example
26
+ * ```js
27
+ * import { store as commandsStore } from '@wordpress/commands';
28
+ * import { useDispatch } from '@wordpress/data';
29
+ * ...
30
+ * const { open: openCommandCenter } = useDispatch( commandsStore );
31
+ * ```
22
32
  */
23
33
  export const store = createReduxStore(STORE_NAME, {
24
34
  reducer,
@@ -1 +1 @@
1
- {"version":3,"names":["createReduxStore","register","reducer","actions","selectors","privateActions","unlock","STORE_NAME","store","registerPrivateActions"],"sources":["@wordpress/commands/src/store/index.js"],"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 */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\nunlock( store ).registerPrivateActions( privateActions );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAgB,EAAEC,QAAQ,QAAQ,iBAAiB;;AAE5D;AACA;AACA;AACA,OAAOC,OAAO,MAAM,WAAW;AAC/B,OAAO,KAAKC,OAAO,MAAM,WAAW;AACpC,OAAO,KAAKC,SAAS,MAAM,aAAa;AACxC,OAAO,KAAKC,cAAc,MAAM,mBAAmB;AACnD,SAASC,MAAM,QAAQ,gBAAgB;AAEvC,MAAMC,UAAU,GAAG,eAAe;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,KAAK,GAAGR,gBAAgB,CAAEO,UAAU,EAAE;EAClDL,OAAO;EACPC,OAAO;EACPC;AACD,CAAE,CAAC;AAEHH,QAAQ,CAAEO,KAAM,CAAC;AACjBF,MAAM,CAAEE,KAAM,CAAC,CAACC,sBAAsB,CAAEJ,cAAe,CAAC"}
1
+ {"version":3,"names":["createReduxStore","register","reducer","actions","selectors","privateActions","unlock","STORE_NAME","store","registerPrivateActions"],"sources":["@wordpress/commands/src/store/index.js"],"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 how the Commands Store is being used in components like [site-hub](https://github.com/WordPress/gutenberg/blob/HEAD/packages/edit-site/src/components/site-hub/index.js#L23) and [document-actions](https://github.com/WordPress/gutenberg/blob/HEAD/packages/edit-post/src/components/header/document-actions/index.js#L14).\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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAgB,EAAEC,QAAQ,QAAQ,iBAAiB;;AAE5D;AACA;AACA;AACA,OAAOC,OAAO,MAAM,WAAW;AAC/B,OAAO,KAAKC,OAAO,MAAM,WAAW;AACpC,OAAO,KAAKC,SAAS,MAAM,aAAa;AACxC,OAAO,KAAKC,cAAc,MAAM,mBAAmB;AACnD,SAASC,MAAM,QAAQ,gBAAgB;AAEvC,MAAMC,UAAU,GAAG,eAAe;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,KAAK,GAAGR,gBAAgB,CAAEO,UAAU,EAAE;EAClDL,OAAO;EACPC,OAAO;EACPC;AACD,CAAE,CAAC;AAEHH,QAAQ,CAAEO,KAAM,CAAC;AACjBF,MAAM,CAAEE,KAAM,CAAC,CAACC,sBAAsB,CAAEJ,cAAe,CAAC"}
@@ -175,11 +175,11 @@
175
175
  min-height: 40px;
176
176
  }
177
177
  .commands-command-menu__container [cmdk-item][aria-selected=true], .commands-command-menu__container [cmdk-item]:active {
178
- background: rgba(var(--wp-admin-theme-color--rgb), 0.04);
179
- color: var(--wp-admin-theme-color);
178
+ background: var(--wp-admin-theme-color);
179
+ color: #fff;
180
180
  }
181
181
  .commands-command-menu__container [cmdk-item][aria-selected=true] svg, .commands-command-menu__container [cmdk-item]:active svg {
182
- fill: var(--wp-admin-theme-color);
182
+ fill: #fff;
183
183
  }
184
184
  .commands-command-menu__container [cmdk-item][aria-disabled=true] {
185
185
  color: #949494;
@@ -175,11 +175,11 @@
175
175
  min-height: 40px;
176
176
  }
177
177
  .commands-command-menu__container [cmdk-item][aria-selected=true], .commands-command-menu__container [cmdk-item]:active {
178
- background: rgba(var(--wp-admin-theme-color--rgb), 0.04);
179
- color: var(--wp-admin-theme-color);
178
+ background: var(--wp-admin-theme-color);
179
+ color: #fff;
180
180
  }
181
181
  .commands-command-menu__container [cmdk-item][aria-selected=true] svg, .commands-command-menu__container [cmdk-item]:active svg {
182
- fill: var(--wp-admin-theme-color);
182
+ fill: #fff;
183
183
  }
184
184
  .commands-command-menu__container [cmdk-item][aria-disabled=true] {
185
185
  color: #949494;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/commands",
3
- "version": "0.12.1-next.5a1d1283.0",
3
+ "version": "0.13.1",
4
4
  "description": "Handles the commands menu.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -27,13 +27,13 @@
27
27
  "react-native": "src/index",
28
28
  "dependencies": {
29
29
  "@babel/runtime": "^7.16.0",
30
- "@wordpress/components": "^26.0.1-next.5a1d1283.0",
31
- "@wordpress/data": "^9.11.1-next.5a1d1283.0",
32
- "@wordpress/element": "^5.18.1-next.5a1d1283.0",
33
- "@wordpress/i18n": "^4.41.1-next.5a1d1283.0",
34
- "@wordpress/icons": "^9.32.1-next.5a1d1283.0",
35
- "@wordpress/keyboard-shortcuts": "^4.18.1-next.5a1d1283.0",
36
- "@wordpress/private-apis": "^0.23.1-next.5a1d1283.0",
30
+ "@wordpress/components": "^25.8.1",
31
+ "@wordpress/data": "^9.12.1",
32
+ "@wordpress/element": "^5.19.1",
33
+ "@wordpress/i18n": "^4.42.1",
34
+ "@wordpress/icons": "^9.33.1",
35
+ "@wordpress/keyboard-shortcuts": "^4.19.1",
36
+ "@wordpress/private-apis": "^0.24.1",
37
37
  "classnames": "^2.3.1",
38
38
  "cmdk": "^0.2.0",
39
39
  "rememo": "^4.0.2"
@@ -45,5 +45,5 @@
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "fa0b66987dab5a15f38663e06036d09bccffaa4b"
48
+ "gitHead": "4987d16acb5c41b62704dc4f88225acb97ddd698"
49
49
  }
@@ -183,6 +183,9 @@ function CommandInput( { isOpen, search, setSearch } ) {
183
183
  );
184
184
  }
185
185
 
186
+ /**
187
+ * @ignore
188
+ */
186
189
  export function CommandMenu() {
187
190
  const { registerShortcut } = useDispatch( keyboardShortcutsStore );
188
191
  const [ search, setSearch ] = useState( '' );
@@ -78,11 +78,11 @@
78
78
 
79
79
  &[aria-selected="true"],
80
80
  &:active {
81
- background: rgba(var(--wp-admin-theme-color--rgb), 0.04);
82
- color: var(--wp-admin-theme-color);
81
+ background: var(--wp-admin-theme-color);
82
+ color: $white;
83
83
 
84
84
  svg {
85
- fill: var(--wp-admin-theme-color);
85
+ fill: $white;
86
86
  }
87
87
  }
88
88
 
@@ -10,9 +10,73 @@ import { useDispatch } from '@wordpress/data';
10
10
  import { store as commandsStore } from '../store';
11
11
 
12
12
  /**
13
- * Attach a command loader to the command palette.
13
+ * Attach a command loader to the command palette. Used for dynamic commands.
14
14
  *
15
15
  * @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.
16
+ *
17
+ * @example
18
+ * ```js
19
+ * import { useCommandLoader } from '@wordpress/commands';
20
+ * import { post, page, layout, symbolFilled } from '@wordpress/icons';
21
+ *
22
+ * const icons = {
23
+ * post,
24
+ * page,
25
+ * wp_template: layout,
26
+ * wp_template_part: symbolFilled,
27
+ * };
28
+ *
29
+ * function usePageSearchCommandLoader( { search } ) {
30
+ * // Retrieve the pages for the "search" term.
31
+ * const { records, isLoading } = useSelect( ( select ) => {
32
+ * const { getEntityRecords } = select( coreStore );
33
+ * const query = {
34
+ * search: !! search ? search : undefined,
35
+ * per_page: 10,
36
+ * orderby: search ? 'relevance' : 'date',
37
+ * };
38
+ * return {
39
+ * records: getEntityRecords( 'postType', 'page', query ),
40
+ * isLoading: ! select( coreStore ).hasFinishedResolution(
41
+ * 'getEntityRecords',
42
+ * 'postType', 'page', query ]
43
+ * ),
44
+ * };
45
+ * }, [ search ] );
46
+ *
47
+ * // Create the commands.
48
+ * const commands = useMemo( () => {
49
+ * return ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {
50
+ * return {
51
+ * name: record.title?.rendered + ' ' + record.id,
52
+ * label: record.title?.rendered
53
+ * ? record.title?.rendered
54
+ * : __( '(no title)' ),
55
+ * icon: icons[ postType ],
56
+ * callback: ( { close } ) => {
57
+ * const args = {
58
+ * postType,
59
+ * postId: record.id,
60
+ * ...extraArgs,
61
+ * };
62
+ * document.location = addQueryArgs( 'site-editor.php', args );
63
+ * close();
64
+ * },
65
+ * };
66
+ * } );
67
+ * }, [ records, history ] );
68
+ *
69
+ * return {
70
+ * commands,
71
+ * isLoading,
72
+ * };
73
+ * }
74
+ *
75
+ * useCommandLoader( {
76
+ * name: 'myplugin/page-search',
77
+ * hook: usePageSearchCommandLoader,
78
+ * } );
79
+ * ```
16
80
  */
17
81
  export default function useCommandLoader( loader ) {
18
82
  const { registerCommandLoader, unregisterCommandLoader } =
@@ -10,9 +10,25 @@ import { useDispatch } from '@wordpress/data';
10
10
  import { store as commandsStore } from '../store';
11
11
 
12
12
  /**
13
- * Attach a command to the command palette.
13
+ * Attach a command to the command palette. Used for static commands.
14
14
  *
15
15
  * @param {import('../store/actions').WPCommandConfig} command command config.
16
+ *
17
+ * @example
18
+ * ```js
19
+ * import { useCommand } from '@wordpress/commands';
20
+ * import { plus } from '@wordpress/icons';
21
+ *
22
+ * useCommand( {
23
+ * name: 'myplugin/my-command-name',
24
+ * label: __( 'Add new post' ),
25
+ * icon: plus,
26
+ * callback: ({ close }) => {
27
+ * document.location.href = 'post-new.php';
28
+ * close();
29
+ * },
30
+ * } );
31
+ * ```
16
32
  */
17
33
  export default function useCommand( command ) {
18
34
  const { registerCommand, unregisterCommand } = useDispatch( commandsStore );
@@ -4,6 +4,9 @@
4
4
  import { default as useCommandContext } from './hooks/use-command-context';
5
5
  import { lock } from './lock-unlock';
6
6
 
7
+ /**
8
+ * @private
9
+ */
7
10
  export const privateApis = {};
8
11
  lock( privateApis, {
9
12
  useCommandContext,
@@ -17,9 +17,19 @@ const STORE_NAME = 'core/commands';
17
17
  /**
18
18
  * Store definition for the commands namespace.
19
19
  *
20
+ * See how the Commands Store is being used in components like [site-hub](https://github.com/WordPress/gutenberg/blob/HEAD/packages/edit-site/src/components/site-hub/index.js#L23) and [document-actions](https://github.com/WordPress/gutenberg/blob/HEAD/packages/edit-post/src/components/header/document-actions/index.js#L14).
21
+ *
20
22
  * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
21
23
  *
22
24
  * @type {Object}
25
+ *
26
+ * @example
27
+ * ```js
28
+ * import { store as commandsStore } from '@wordpress/commands';
29
+ * import { useDispatch } from '@wordpress/data';
30
+ * ...
31
+ * const { open: openCommandCenter } = useDispatch( commandsStore );
32
+ * ```
23
33
  */
24
34
  export const store = createReduxStore( STORE_NAME, {
25
35
  reducer,