@wordpress/commands 1.30.0 → 1.30.1-next.6f42e1382.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -188,6 +188,42 @@ _Parameters_
188
188
 
189
189
  - _loader_ `import('../store/actions').WPCommandLoaderConfig`: command loader config.
190
190
 
191
+ ### useCommands
192
+
193
+ Attach multiple commands to the command palette. Used for static commands.
194
+
195
+ _Usage_
196
+
197
+ ```js
198
+ import { useCommands } from '@wordpress/commands';
199
+ import { plus, edit } from '@wordpress/icons';
200
+
201
+ useCommands( [
202
+ {
203
+ name: 'myplugin/add-post',
204
+ label: __( 'Add new post' ),
205
+ icon: plus,
206
+ callback: ( { close } ) => {
207
+ document.location.href = 'post-new.php';
208
+ close();
209
+ },
210
+ },
211
+ {
212
+ name: 'myplugin/edit-posts',
213
+ label: __( 'Edit posts' ),
214
+ icon: edit,
215
+ callback: ( { close } ) => {
216
+ document.location.href = 'edit.php';
217
+ close();
218
+ },
219
+ },
220
+ ] );
221
+ ```
222
+
223
+ _Parameters_
224
+
225
+ - _commands_ `import('../store/actions').WPCommandConfig[]`: Array of command configs.
226
+
191
227
  <!-- END TOKEN(Autogenerated API docs) -->
192
228
 
193
229
  ## Contributing to this package
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = useCommand;
6
+ exports.useCommand = useCommand;
7
+ exports.useCommands = useCommands;
7
8
  var _element = require("@wordpress/element");
8
9
  var _data = require("@wordpress/data");
9
10
  var _store = require("../store");
@@ -63,4 +64,83 @@ function useCommand(command) {
63
64
  };
64
65
  }, [command.name, command.label, command.searchLabel, command.icon, command.context, command.keywords, command.disabled, registerCommand, unregisterCommand]);
65
66
  }
67
+
68
+ /**
69
+ * Attach multiple commands to the command palette. Used for static commands.
70
+ *
71
+ * @param {import('../store/actions').WPCommandConfig[]} commands Array of command configs.
72
+ *
73
+ * @example
74
+ * ```js
75
+ * import { useCommands } from '@wordpress/commands';
76
+ * import { plus, edit } from '@wordpress/icons';
77
+ *
78
+ * useCommands( [
79
+ * {
80
+ * name: 'myplugin/add-post',
81
+ * label: __( 'Add new post' ),
82
+ * icon: plus,
83
+ * callback: ({ close }) => {
84
+ * document.location.href = 'post-new.php';
85
+ * close();
86
+ * },
87
+ * },
88
+ * {
89
+ * name: 'myplugin/edit-posts',
90
+ * label: __( 'Edit posts' ),
91
+ * icon: edit,
92
+ * callback: ({ close }) => {
93
+ * document.location.href = 'edit.php';
94
+ * close();
95
+ * },
96
+ * },
97
+ * ] );
98
+ * ```
99
+ */
100
+ function useCommands(commands) {
101
+ const {
102
+ registerCommand,
103
+ unregisterCommand
104
+ } = (0, _data.useDispatch)(_store.store);
105
+ const currentCallbacksRef = (0, _element.useRef)({});
106
+ (0, _element.useEffect)(() => {
107
+ if (!commands) {
108
+ return;
109
+ }
110
+ commands.forEach(command => {
111
+ if (command.callback) {
112
+ currentCallbacksRef.current[command.name] = command.callback;
113
+ }
114
+ });
115
+ }, [commands]);
116
+ (0, _element.useEffect)(() => {
117
+ if (!commands) {
118
+ return;
119
+ }
120
+ commands.forEach(command => {
121
+ if (command.disabled) {
122
+ return;
123
+ }
124
+ registerCommand({
125
+ name: command.name,
126
+ context: command.context,
127
+ label: command.label,
128
+ searchLabel: command.searchLabel,
129
+ icon: command.icon,
130
+ keywords: command.keywords,
131
+ callback: (...args) => {
132
+ const callback = currentCallbacksRef.current[command.name];
133
+ if (callback) {
134
+ callback(...args);
135
+ }
136
+ }
137
+ });
138
+ });
139
+ return () => {
140
+ commands.forEach(command => {
141
+ unregisterCommand(command.name);
142
+ });
143
+ };
144
+ }, [commands, registerCommand, unregisterCommand]);
145
+ }
66
146
  //# sourceMappingURL=use-command.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_data","_store","useCommand","command","registerCommand","unregisterCommand","useDispatch","commandsStore","currentCallbackRef","useRef","callback","useEffect","current","disabled","name","context","label","searchLabel","icon","keywords","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 currentCallbackRef = useRef( command.callback );\n\tuseEffect( () => {\n\t\tcurrentCallbackRef.current = command.callback;\n\t}, [ command.callback ] );\n\n\tuseEffect( () => {\n\t\tif ( command.disabled ) {\n\t\t\treturn;\n\t\t}\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\tkeywords: command.keywords,\n\t\t\tcallback: ( ...args ) => currentCallbackRef.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\tcommand.keywords,\n\t\tcommand.disabled,\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,kBAAkB,GAAG,IAAAC,eAAM,EAAEN,OAAO,CAACO,QAAS,CAAC;EACrD,IAAAC,kBAAS,EAAE,MAAM;IAChBH,kBAAkB,CAACI,OAAO,GAAGT,OAAO,CAACO,QAAQ;EAC9C,CAAC,EAAE,CAAEP,OAAO,CAACO,QAAQ,CAAG,CAAC;EAEzB,IAAAC,kBAAS,EAAE,MAAM;IAChB,IAAKR,OAAO,CAACU,QAAQ,EAAG;MACvB;IACD;IACAT,eAAe,CAAE;MAChBU,IAAI,EAAEX,OAAO,CAACW,IAAI;MAClBC,OAAO,EAAEZ,OAAO,CAACY,OAAO;MACxBC,KAAK,EAAEb,OAAO,CAACa,KAAK;MACpBC,WAAW,EAAEd,OAAO,CAACc,WAAW;MAChCC,IAAI,EAAEf,OAAO,CAACe,IAAI;MAClBC,QAAQ,EAAEhB,OAAO,CAACgB,QAAQ;MAC1BT,QAAQ,EAAEA,CAAE,GAAGU,IAAI,KAAMZ,kBAAkB,CAACI,OAAO,CAAE,GAAGQ,IAAK;IAC9D,CAAE,CAAC;IACH,OAAO,MAAM;MACZf,iBAAiB,CAAEF,OAAO,CAACW,IAAK,CAAC;IAClC,CAAC;EACF,CAAC,EAAE,CACFX,OAAO,CAACW,IAAI,EACZX,OAAO,CAACa,KAAK,EACbb,OAAO,CAACc,WAAW,EACnBd,OAAO,CAACe,IAAI,EACZf,OAAO,CAACY,OAAO,EACfZ,OAAO,CAACgB,QAAQ,EAChBhB,OAAO,CAACU,QAAQ,EAChBT,eAAe,EACfC,iBAAiB,CAChB,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["_element","require","_data","_store","useCommand","command","registerCommand","unregisterCommand","useDispatch","commandsStore","currentCallbackRef","useRef","callback","useEffect","current","disabled","name","context","label","searchLabel","icon","keywords","args","useCommands","commands","currentCallbacksRef","forEach"],"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 function useCommand( command ) {\n\tconst { registerCommand, unregisterCommand } = useDispatch( commandsStore );\n\tconst currentCallbackRef = useRef( command.callback );\n\tuseEffect( () => {\n\t\tcurrentCallbackRef.current = command.callback;\n\t}, [ command.callback ] );\n\n\tuseEffect( () => {\n\t\tif ( command.disabled ) {\n\t\t\treturn;\n\t\t}\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\tkeywords: command.keywords,\n\t\t\tcallback: ( ...args ) => currentCallbackRef.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\tcommand.keywords,\n\t\tcommand.disabled,\n\t\tregisterCommand,\n\t\tunregisterCommand,\n\t] );\n}\n\n/**\n * Attach multiple commands to the command palette. Used for static commands.\n *\n * @param {import('../store/actions').WPCommandConfig[]} commands Array of command configs.\n *\n * @example\n * ```js\n * import { useCommands } from '@wordpress/commands';\n * import { plus, edit } from '@wordpress/icons';\n *\n * useCommands( [\n * {\n * name: 'myplugin/add-post',\n * label: __( 'Add new post' ),\n * icon: plus,\n * callback: ({ close }) => {\n * document.location.href = 'post-new.php';\n * close();\n * },\n * },\n * {\n * name: 'myplugin/edit-posts',\n * label: __( 'Edit posts' ),\n * icon: edit,\n * callback: ({ close }) => {\n * document.location.href = 'edit.php';\n * close();\n * },\n * },\n * ] );\n * ```\n */\nexport function useCommands( commands ) {\n\tconst { registerCommand, unregisterCommand } = useDispatch( commandsStore );\n\tconst currentCallbacksRef = useRef( {} );\n\n\tuseEffect( () => {\n\t\tif ( ! commands ) {\n\t\t\treturn;\n\t\t}\n\t\tcommands.forEach( ( command ) => {\n\t\t\tif ( command.callback ) {\n\t\t\t\tcurrentCallbacksRef.current[ command.name ] = command.callback;\n\t\t\t}\n\t\t} );\n\t}, [ commands ] );\n\n\tuseEffect( () => {\n\t\tif ( ! commands ) {\n\t\t\treturn;\n\t\t}\n\t\tcommands.forEach( ( command ) => {\n\t\t\tif ( command.disabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tregisterCommand( {\n\t\t\t\tname: command.name,\n\t\t\t\tcontext: command.context,\n\t\t\t\tlabel: command.label,\n\t\t\t\tsearchLabel: command.searchLabel,\n\t\t\t\ticon: command.icon,\n\t\t\t\tkeywords: command.keywords,\n\t\t\t\tcallback: ( ...args ) => {\n\t\t\t\t\tconst callback =\n\t\t\t\t\t\tcurrentCallbacksRef.current[ command.name ];\n\t\t\t\t\tif ( callback ) {\n\t\t\t\t\t\tcallback( ...args );\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t} );\n\t\t} );\n\n\t\treturn () => {\n\t\t\tcommands.forEach( ( command ) => {\n\t\t\t\tunregisterCommand( command.name );\n\t\t\t} );\n\t\t};\n\t}, [ commands, registerCommand, unregisterCommand ] );\n}\n"],"mappings":";;;;;;;AAGA,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;UACxB,MAAMV,QAAQ,GACba,mBAAmB,CAACX,OAAO,CAAET,OAAO,CAACW,IAAI,CAAE;UAC5C,IAAKJ,QAAQ,EAAG;YACfA,QAAQ,CAAE,GAAGU,IAAK,CAAC;UACpB;QACD;MACD,CAAE,CAAC;IACJ,CAAE,CAAC;IAEH,OAAO,MAAM;MACZE,QAAQ,CAACE,OAAO,CAAIrB,OAAO,IAAM;QAChCE,iBAAiB,CAAEF,OAAO,CAACW,IAAK,CAAC;MAClC,CAAE,CAAC;IACJ,CAAC;EACF,CAAC,EAAE,CAAEQ,QAAQ,EAAElB,eAAe,EAAEC,iBAAiB,CAAG,CAAC;AACtD","ignoreList":[]}
package/build/index.js CHANGED
@@ -25,7 +25,7 @@ Object.defineProperty(exports, "store", {
25
25
  Object.defineProperty(exports, "useCommand", {
26
26
  enumerable: true,
27
27
  get: function () {
28
- return _useCommand.default;
28
+ return _useCommand.useCommand;
29
29
  }
30
30
  });
31
31
  Object.defineProperty(exports, "useCommandLoader", {
@@ -34,9 +34,15 @@ Object.defineProperty(exports, "useCommandLoader", {
34
34
  return _useCommandLoader.default;
35
35
  }
36
36
  });
37
+ Object.defineProperty(exports, "useCommands", {
38
+ enumerable: true,
39
+ get: function () {
40
+ return _useCommand.useCommands;
41
+ }
42
+ });
37
43
  var _commandMenu = require("./components/command-menu");
38
44
  var _privateApis = require("./private-apis");
39
- var _useCommand = _interopRequireDefault(require("./hooks/use-command"));
45
+ var _useCommand = require("./hooks/use-command");
40
46
  var _useCommandLoader = _interopRequireDefault(require("./hooks/use-command-loader"));
41
47
  var _store = require("./store");
42
48
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_commandMenu","require","_privateApis","_useCommand","_interopRequireDefault","_useCommandLoader","_store"],"sources":["@wordpress/commands/src/index.js"],"sourcesContent":["export { CommandMenu } from './components/command-menu';\nexport { privateApis } from './private-apis';\nexport { default as useCommand } from './hooks/use-command';\nexport { default as useCommandLoader } from './hooks/use-command-loader';\nexport { store } from './store';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_commandMenu","require","_privateApis","_useCommand","_useCommandLoader","_interopRequireDefault","_store"],"sources":["@wordpress/commands/src/index.js"],"sourcesContent":["export { CommandMenu } from './components/command-menu';\nexport { privateApis } from './private-apis';\nexport { useCommand, useCommands } from './hooks/use-command';\nexport { default as useCommandLoader } from './hooks/use-command-loader';\nexport { store } from './store';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA","ignoreList":[]}
@@ -30,7 +30,7 @@ import { store as commandsStore } from '../store';
30
30
  * } );
31
31
  * ```
32
32
  */
33
- export default function useCommand(command) {
33
+ export function useCommand(command) {
34
34
  const {
35
35
  registerCommand,
36
36
  unregisterCommand
@@ -57,4 +57,83 @@ export default function useCommand(command) {
57
57
  };
58
58
  }, [command.name, command.label, command.searchLabel, command.icon, command.context, command.keywords, command.disabled, registerCommand, unregisterCommand]);
59
59
  }
60
+
61
+ /**
62
+ * Attach multiple commands to the command palette. Used for static commands.
63
+ *
64
+ * @param {import('../store/actions').WPCommandConfig[]} commands Array of command configs.
65
+ *
66
+ * @example
67
+ * ```js
68
+ * import { useCommands } from '@wordpress/commands';
69
+ * import { plus, edit } from '@wordpress/icons';
70
+ *
71
+ * useCommands( [
72
+ * {
73
+ * name: 'myplugin/add-post',
74
+ * label: __( 'Add new post' ),
75
+ * icon: plus,
76
+ * callback: ({ close }) => {
77
+ * document.location.href = 'post-new.php';
78
+ * close();
79
+ * },
80
+ * },
81
+ * {
82
+ * name: 'myplugin/edit-posts',
83
+ * label: __( 'Edit posts' ),
84
+ * icon: edit,
85
+ * callback: ({ close }) => {
86
+ * document.location.href = 'edit.php';
87
+ * close();
88
+ * },
89
+ * },
90
+ * ] );
91
+ * ```
92
+ */
93
+ export function useCommands(commands) {
94
+ const {
95
+ registerCommand,
96
+ unregisterCommand
97
+ } = useDispatch(commandsStore);
98
+ const currentCallbacksRef = useRef({});
99
+ useEffect(() => {
100
+ if (!commands) {
101
+ return;
102
+ }
103
+ commands.forEach(command => {
104
+ if (command.callback) {
105
+ currentCallbacksRef.current[command.name] = command.callback;
106
+ }
107
+ });
108
+ }, [commands]);
109
+ useEffect(() => {
110
+ if (!commands) {
111
+ return;
112
+ }
113
+ commands.forEach(command => {
114
+ if (command.disabled) {
115
+ return;
116
+ }
117
+ registerCommand({
118
+ name: command.name,
119
+ context: command.context,
120
+ label: command.label,
121
+ searchLabel: command.searchLabel,
122
+ icon: command.icon,
123
+ keywords: command.keywords,
124
+ callback: (...args) => {
125
+ const callback = currentCallbacksRef.current[command.name];
126
+ if (callback) {
127
+ callback(...args);
128
+ }
129
+ }
130
+ });
131
+ });
132
+ return () => {
133
+ commands.forEach(command => {
134
+ unregisterCommand(command.name);
135
+ });
136
+ };
137
+ }, [commands, registerCommand, unregisterCommand]);
138
+ }
60
139
  //# sourceMappingURL=use-command.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useRef","useDispatch","store","commandsStore","useCommand","command","registerCommand","unregisterCommand","currentCallbackRef","callback","current","disabled","name","context","label","searchLabel","icon","keywords","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 currentCallbackRef = useRef( command.callback );\n\tuseEffect( () => {\n\t\tcurrentCallbackRef.current = command.callback;\n\t}, [ command.callback ] );\n\n\tuseEffect( () => {\n\t\tif ( command.disabled ) {\n\t\t\treturn;\n\t\t}\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\tkeywords: command.keywords,\n\t\t\tcallback: ( ...args ) => currentCallbackRef.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\tcommand.keywords,\n\t\tcommand.disabled,\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,kBAAkB,GAAGR,MAAM,CAAEK,OAAO,CAACI,QAAS,CAAC;EACrDV,SAAS,CAAE,MAAM;IAChBS,kBAAkB,CAACE,OAAO,GAAGL,OAAO,CAACI,QAAQ;EAC9C,CAAC,EAAE,CAAEJ,OAAO,CAACI,QAAQ,CAAG,CAAC;EAEzBV,SAAS,CAAE,MAAM;IAChB,IAAKM,OAAO,CAACM,QAAQ,EAAG;MACvB;IACD;IACAL,eAAe,CAAE;MAChBM,IAAI,EAAEP,OAAO,CAACO,IAAI;MAClBC,OAAO,EAAER,OAAO,CAACQ,OAAO;MACxBC,KAAK,EAAET,OAAO,CAACS,KAAK;MACpBC,WAAW,EAAEV,OAAO,CAACU,WAAW;MAChCC,IAAI,EAAEX,OAAO,CAACW,IAAI;MAClBC,QAAQ,EAAEZ,OAAO,CAACY,QAAQ;MAC1BR,QAAQ,EAAEA,CAAE,GAAGS,IAAI,KAAMV,kBAAkB,CAACE,OAAO,CAAE,GAAGQ,IAAK;IAC9D,CAAE,CAAC;IACH,OAAO,MAAM;MACZX,iBAAiB,CAAEF,OAAO,CAACO,IAAK,CAAC;IAClC,CAAC;EACF,CAAC,EAAE,CACFP,OAAO,CAACO,IAAI,EACZP,OAAO,CAACS,KAAK,EACbT,OAAO,CAACU,WAAW,EACnBV,OAAO,CAACW,IAAI,EACZX,OAAO,CAACQ,OAAO,EACfR,OAAO,CAACY,QAAQ,EAChBZ,OAAO,CAACM,QAAQ,EAChBL,eAAe,EACfC,iBAAiB,CAChB,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["useEffect","useRef","useDispatch","store","commandsStore","useCommand","command","registerCommand","unregisterCommand","currentCallbackRef","callback","current","disabled","name","context","label","searchLabel","icon","keywords","args","useCommands","commands","currentCallbacksRef","forEach"],"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 function useCommand( command ) {\n\tconst { registerCommand, unregisterCommand } = useDispatch( commandsStore );\n\tconst currentCallbackRef = useRef( command.callback );\n\tuseEffect( () => {\n\t\tcurrentCallbackRef.current = command.callback;\n\t}, [ command.callback ] );\n\n\tuseEffect( () => {\n\t\tif ( command.disabled ) {\n\t\t\treturn;\n\t\t}\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\tkeywords: command.keywords,\n\t\t\tcallback: ( ...args ) => currentCallbackRef.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\tcommand.keywords,\n\t\tcommand.disabled,\n\t\tregisterCommand,\n\t\tunregisterCommand,\n\t] );\n}\n\n/**\n * Attach multiple commands to the command palette. Used for static commands.\n *\n * @param {import('../store/actions').WPCommandConfig[]} commands Array of command configs.\n *\n * @example\n * ```js\n * import { useCommands } from '@wordpress/commands';\n * import { plus, edit } from '@wordpress/icons';\n *\n * useCommands( [\n * {\n * name: 'myplugin/add-post',\n * label: __( 'Add new post' ),\n * icon: plus,\n * callback: ({ close }) => {\n * document.location.href = 'post-new.php';\n * close();\n * },\n * },\n * {\n * name: 'myplugin/edit-posts',\n * label: __( 'Edit posts' ),\n * icon: edit,\n * callback: ({ close }) => {\n * document.location.href = 'edit.php';\n * close();\n * },\n * },\n * ] );\n * ```\n */\nexport function useCommands( commands ) {\n\tconst { registerCommand, unregisterCommand } = useDispatch( commandsStore );\n\tconst currentCallbacksRef = useRef( {} );\n\n\tuseEffect( () => {\n\t\tif ( ! commands ) {\n\t\t\treturn;\n\t\t}\n\t\tcommands.forEach( ( command ) => {\n\t\t\tif ( command.callback ) {\n\t\t\t\tcurrentCallbacksRef.current[ command.name ] = command.callback;\n\t\t\t}\n\t\t} );\n\t}, [ commands ] );\n\n\tuseEffect( () => {\n\t\tif ( ! commands ) {\n\t\t\treturn;\n\t\t}\n\t\tcommands.forEach( ( command ) => {\n\t\t\tif ( command.disabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tregisterCommand( {\n\t\t\t\tname: command.name,\n\t\t\t\tcontext: command.context,\n\t\t\t\tlabel: command.label,\n\t\t\t\tsearchLabel: command.searchLabel,\n\t\t\t\ticon: command.icon,\n\t\t\t\tkeywords: command.keywords,\n\t\t\t\tcallback: ( ...args ) => {\n\t\t\t\t\tconst callback =\n\t\t\t\t\t\tcurrentCallbacksRef.current[ command.name ];\n\t\t\t\t\tif ( callback ) {\n\t\t\t\t\t\tcallback( ...args );\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t} );\n\t\t} );\n\n\t\treturn () => {\n\t\t\tcommands.forEach( ( command ) => {\n\t\t\t\tunregisterCommand( command.name );\n\t\t\t} );\n\t\t};\n\t}, [ commands, registerCommand, unregisterCommand ] );\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;A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AE,CAAC;IAEH,OAAO,MAAM;MACZE,QAAQ,CAACE,OAAO,CAAIjB,OAAO,IAAM;QAChCE,iBAAiB,CAAEF,OAAO,CAACO,IAAK,CAAC;MAClC,CAAE,CAAC;IACJ,CAAC;EACF,CAAC,EAAE,CAAEQ,QAAQ,EAAEd,eAAe,EAAEC,iBAAiB,CAAG,CAAC;AACtD","ignoreList":[]}
@@ -1,6 +1,6 @@
1
1
  export { CommandMenu } from './components/command-menu';
2
2
  export { privateApis } from './private-apis';
3
- export { default as useCommand } from './hooks/use-command';
3
+ export { useCommand, useCommands } from './hooks/use-command';
4
4
  export { default as useCommandLoader } from './hooks/use-command-loader';
5
5
  export { store } from './store';
6
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["CommandMenu","privateApis","default","useCommand","useCommandLoader","store"],"sources":["@wordpress/commands/src/index.js"],"sourcesContent":["export { CommandMenu } from './components/command-menu';\nexport { privateApis } from './private-apis';\nexport { default as useCommand } from './hooks/use-command';\nexport { default as useCommandLoader } from './hooks/use-command-loader';\nexport { store } from './store';\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,2BAA2B;AACvD,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SAASC,OAAO,IAAIC,UAAU,QAAQ,qBAAqB;AAC3D,SAASD,OAAO,IAAIE,gBAAgB,QAAQ,4BAA4B;AACxE,SAASC,KAAK,QAAQ,SAAS","ignoreList":[]}
1
+ {"version":3,"names":["CommandMenu","privateApis","useCommand","useCommands","default","useCommandLoader","store"],"sources":["@wordpress/commands/src/index.js"],"sourcesContent":["export { CommandMenu } from './components/command-menu';\nexport { privateApis } from './private-apis';\nexport { useCommand, useCommands } from './hooks/use-command';\nexport { default as useCommandLoader } from './hooks/use-command-loader';\nexport { store } from './store';\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,2BAA2B;AACvD,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SAASC,UAAU,EAAEC,WAAW,QAAQ,qBAAqB;AAC7D,SAASC,OAAO,IAAIC,gBAAgB,QAAQ,4BAA4B;AACxE,SAASC,KAAK,QAAQ,SAAS","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/commands",
3
- "version": "1.30.0",
3
+ "version": "1.30.1-next.6f42e1382.0",
4
4
  "description": "Handles the commands menu.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -29,13 +29,13 @@
29
29
  "wpScript": true,
30
30
  "dependencies": {
31
31
  "@babel/runtime": "7.25.7",
32
- "@wordpress/components": "^30.3.0",
33
- "@wordpress/data": "^10.30.0",
34
- "@wordpress/element": "^6.30.0",
35
- "@wordpress/i18n": "^6.3.0",
36
- "@wordpress/icons": "^10.30.0",
37
- "@wordpress/keyboard-shortcuts": "^5.30.0",
38
- "@wordpress/private-apis": "^1.30.0",
32
+ "@wordpress/components": "^30.3.2-next.6f42e1382.0",
33
+ "@wordpress/data": "^10.30.1-next.6f42e1382.0",
34
+ "@wordpress/element": "^6.30.1-next.6f42e1382.0",
35
+ "@wordpress/i18n": "^6.3.1-next.6f42e1382.0",
36
+ "@wordpress/icons": "^10.30.1-next.6f42e1382.0",
37
+ "@wordpress/keyboard-shortcuts": "^5.30.1-next.6f42e1382.0",
38
+ "@wordpress/private-apis": "^1.30.1-next.6f42e1382.0",
39
39
  "clsx": "^2.1.1",
40
40
  "cmdk": "^1.0.0"
41
41
  },
@@ -46,5 +46,5 @@
46
46
  "publishConfig": {
47
47
  "access": "public"
48
48
  },
49
- "gitHead": "c66cb089eed19d4f4956962fa7b4c81abe6dd513"
49
+ "gitHead": "8806899f598577a3c90a55d9aa79fbc372fe1e75"
50
50
  }
@@ -30,7 +30,7 @@ import { store as commandsStore } from '../store';
30
30
  * } );
31
31
  * ```
32
32
  */
33
- export default function useCommand( command ) {
33
+ export function useCommand( command ) {
34
34
  const { registerCommand, unregisterCommand } = useDispatch( commandsStore );
35
35
  const currentCallbackRef = useRef( command.callback );
36
36
  useEffect( () => {
@@ -65,3 +65,83 @@ export default function useCommand( command ) {
65
65
  unregisterCommand,
66
66
  ] );
67
67
  }
68
+
69
+ /**
70
+ * Attach multiple commands to the command palette. Used for static commands.
71
+ *
72
+ * @param {import('../store/actions').WPCommandConfig[]} commands Array of command configs.
73
+ *
74
+ * @example
75
+ * ```js
76
+ * import { useCommands } from '@wordpress/commands';
77
+ * import { plus, edit } from '@wordpress/icons';
78
+ *
79
+ * useCommands( [
80
+ * {
81
+ * name: 'myplugin/add-post',
82
+ * label: __( 'Add new post' ),
83
+ * icon: plus,
84
+ * callback: ({ close }) => {
85
+ * document.location.href = 'post-new.php';
86
+ * close();
87
+ * },
88
+ * },
89
+ * {
90
+ * name: 'myplugin/edit-posts',
91
+ * label: __( 'Edit posts' ),
92
+ * icon: edit,
93
+ * callback: ({ close }) => {
94
+ * document.location.href = 'edit.php';
95
+ * close();
96
+ * },
97
+ * },
98
+ * ] );
99
+ * ```
100
+ */
101
+ export function useCommands( commands ) {
102
+ const { registerCommand, unregisterCommand } = useDispatch( commandsStore );
103
+ const currentCallbacksRef = useRef( {} );
104
+
105
+ useEffect( () => {
106
+ if ( ! commands ) {
107
+ return;
108
+ }
109
+ commands.forEach( ( command ) => {
110
+ if ( command.callback ) {
111
+ currentCallbacksRef.current[ command.name ] = command.callback;
112
+ }
113
+ } );
114
+ }, [ commands ] );
115
+
116
+ useEffect( () => {
117
+ if ( ! commands ) {
118
+ return;
119
+ }
120
+ commands.forEach( ( command ) => {
121
+ if ( command.disabled ) {
122
+ return;
123
+ }
124
+ registerCommand( {
125
+ name: command.name,
126
+ context: command.context,
127
+ label: command.label,
128
+ searchLabel: command.searchLabel,
129
+ icon: command.icon,
130
+ keywords: command.keywords,
131
+ callback: ( ...args ) => {
132
+ const callback =
133
+ currentCallbacksRef.current[ command.name ];
134
+ if ( callback ) {
135
+ callback( ...args );
136
+ }
137
+ },
138
+ } );
139
+ } );
140
+
141
+ return () => {
142
+ commands.forEach( ( command ) => {
143
+ unregisterCommand( command.name );
144
+ } );
145
+ };
146
+ }, [ commands, registerCommand, unregisterCommand ] );
147
+ }
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { CommandMenu } from './components/command-menu';
2
2
  export { privateApis } from './private-apis';
3
- export { default as useCommand } from './hooks/use-command';
3
+ export { useCommand, useCommands } from './hooks/use-command';
4
4
  export { default as useCommandLoader } from './hooks/use-command-loader';
5
5
  export { store } from './store';