@wordpress/commands 0.19.0 → 0.19.1-next.79a6196f.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/LICENSE.md +1 -1
- package/build/hooks/use-command-loader.js +4 -1
- package/build/hooks/use-command-loader.js.map +1 -1
- package/build/hooks/use-command.js +4 -1
- package/build/hooks/use-command.js.map +1 -1
- package/build/store/actions.js +5 -3
- package/build/store/actions.js.map +1 -1
- package/build-module/hooks/use-command-loader.js +4 -1
- package/build-module/hooks/use-command-loader.js.map +1 -1
- package/build-module/hooks/use-command.js +4 -1
- package/build-module/hooks/use-command.js.map +1 -1
- package/build-module/store/actions.js +5 -3
- package/build-module/store/actions.js.map +1 -1
- package/package.json +9 -9
- package/src/hooks/use-command-loader.js +4 -0
- package/src/hooks/use-command.js +4 -0
- package/src/store/actions.js +5 -3
package/CHANGELOG.md
CHANGED
package/LICENSE.md
CHANGED
|
@@ -90,6 +90,9 @@ function useCommandLoader(loader) {
|
|
|
90
90
|
unregisterCommandLoader
|
|
91
91
|
} = (0, _data.useDispatch)(_store.store);
|
|
92
92
|
(0, _element.useEffect)(() => {
|
|
93
|
+
if (loader.disabled) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
93
96
|
registerCommandLoader({
|
|
94
97
|
name: loader.name,
|
|
95
98
|
hook: loader.hook,
|
|
@@ -98,6 +101,6 @@ function useCommandLoader(loader) {
|
|
|
98
101
|
return () => {
|
|
99
102
|
unregisterCommandLoader(loader.name);
|
|
100
103
|
};
|
|
101
|
-
}, [loader.name, loader.hook, loader.context, registerCommandLoader, unregisterCommandLoader]);
|
|
104
|
+
}, [loader.name, loader.hook, loader.context, loader.disabled, registerCommandLoader, unregisterCommandLoader]);
|
|
102
105
|
}
|
|
103
106
|
//# sourceMappingURL=use-command-loader.js.map
|
|
@@ -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. 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;
|
|
1
|
+
{"version":3,"names":["_element","require","_data","_store","useCommandLoader","loader","registerCommandLoader","unregisterCommandLoader","useDispatch","commandsStore","useEffect","disabled","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\tif ( loader.disabled ) {\n\t\t\treturn;\n\t\t}\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\tloader.disabled,\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;IAChB,IAAKL,MAAM,CAACM,QAAQ,EAAG;MACtB;IACD;IACAL,qBAAqB,CAAE;MACtBM,IAAI,EAAEP,MAAM,CAACO,IAAI;MACjBC,IAAI,EAAER,MAAM,CAACQ,IAAI;MACjBC,OAAO,EAAET,MAAM,CAACS;IACjB,CAAE,CAAC;IACH,OAAO,MAAM;MACZP,uBAAuB,CAAEF,MAAM,CAACO,IAAK,CAAC;IACvC,CAAC;EACF,CAAC,EAAE,CACFP,MAAM,CAACO,IAAI,EACXP,MAAM,CAACQ,IAAI,EACXR,MAAM,CAACS,OAAO,EACdT,MAAM,CAACM,QAAQ,EACfL,qBAAqB,EACrBC,uBAAuB,CACtB,CAAC;AACJ"}
|
|
@@ -46,6 +46,9 @@ function useCommand(command) {
|
|
|
46
46
|
currentCallback.current = command.callback;
|
|
47
47
|
}, [command.callback]);
|
|
48
48
|
(0, _element.useEffect)(() => {
|
|
49
|
+
if (command.disabled) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
49
52
|
registerCommand({
|
|
50
53
|
name: command.name,
|
|
51
54
|
context: command.context,
|
|
@@ -57,6 +60,6 @@ function useCommand(command) {
|
|
|
57
60
|
return () => {
|
|
58
61
|
unregisterCommand(command.name);
|
|
59
62
|
};
|
|
60
|
-
}, [command.name, command.label, command.searchLabel, command.icon, command.context, registerCommand, unregisterCommand]);
|
|
63
|
+
}, [command.name, command.label, command.searchLabel, command.icon, command.context, command.disabled, registerCommand, unregisterCommand]);
|
|
61
64
|
}
|
|
62
65
|
//# sourceMappingURL=use-command.js.map
|
|
@@ -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. 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;
|
|
1
|
+
{"version":3,"names":["_element","require","_data","_store","useCommand","command","registerCommand","unregisterCommand","useDispatch","commandsStore","currentCallback","useRef","callback","useEffect","current","disabled","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\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\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\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,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;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;MAClBR,QAAQ,EAAEA,CAAE,GAAGS,IAAI,KAAMX,eAAe,CAACI,OAAO,CAAE,GAAGO,IAAK;IAC3D,CAAE,CAAC;IACH,OAAO,MAAM;MACZd,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,CAACU,QAAQ,EAChBT,eAAe,EACfC,iBAAiB,CAChB,CAAC;AACJ"}
|
package/build/store/actions.js
CHANGED
|
@@ -22,6 +22,7 @@ exports.unregisterCommandLoader = unregisterCommandLoader;
|
|
|
22
22
|
* @property {string=} context Command context.
|
|
23
23
|
* @property {JSX.Element} icon Command icon.
|
|
24
24
|
* @property {Function} callback Command callback.
|
|
25
|
+
* @property {boolean} disabled Whether to disable the command.
|
|
25
26
|
*/
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -33,9 +34,10 @@ exports.unregisterCommandLoader = unregisterCommandLoader;
|
|
|
33
34
|
*
|
|
34
35
|
* @typedef {Object} WPCommandLoaderConfig
|
|
35
36
|
*
|
|
36
|
-
* @property {string} name
|
|
37
|
-
* @property {string=} context
|
|
38
|
-
* @property {WPCommandLoaderHook} hook
|
|
37
|
+
* @property {string} name Command loader name.
|
|
38
|
+
* @property {string=} context Command loader context.
|
|
39
|
+
* @property {WPCommandLoaderHook} hook Command loader hook.
|
|
40
|
+
* @property {boolean} disabled Whether to disable the command loader.
|
|
39
41
|
*/
|
|
40
42
|
|
|
41
43
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["registerCommand","config","type","unregisterCommand","name","registerCommandLoader","unregisterCommandLoader","open","close"],"sources":["@wordpress/commands/src/store/actions.js"],"sourcesContent":["/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */\n\n/**\n * Configuration of a registered keyboard shortcut.\n *\n * @typedef {Object} WPCommandConfig\n *\n * @property {string} name Command name.\n * @property {string} label Command label.\n * @property {string=} searchLabel Command search label.\n * @property {string=} context Command context.\n * @property {JSX.Element} icon Command icon.\n * @property {Function} callback Command callback.\n */\n\n/**\n * @typedef {(search: string) => WPCommandConfig[]} WPCommandLoaderHook hoo\n */\n\n/**\n * Command loader config.\n *\n * @typedef {Object} WPCommandLoaderConfig\n *\n * @property {string} name
|
|
1
|
+
{"version":3,"names":["registerCommand","config","type","unregisterCommand","name","registerCommandLoader","unregisterCommandLoader","open","close"],"sources":["@wordpress/commands/src/store/actions.js"],"sourcesContent":["/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */\n\n/**\n * Configuration of a registered keyboard shortcut.\n *\n * @typedef {Object} WPCommandConfig\n *\n * @property {string} name Command name.\n * @property {string} label Command label.\n * @property {string=} searchLabel Command search label.\n * @property {string=} context Command context.\n * @property {JSX.Element} icon Command icon.\n * @property {Function} callback Command callback.\n * @property {boolean} disabled Whether to disable the command.\n */\n\n/**\n * @typedef {(search: string) => WPCommandConfig[]} WPCommandLoaderHook hoo\n */\n\n/**\n * Command loader config.\n *\n * @typedef {Object} WPCommandLoaderConfig\n *\n * @property {string} name Command loader name.\n * @property {string=} context Command loader context.\n * @property {WPCommandLoaderHook} hook Command loader hook.\n * @property {boolean} disabled Whether to disable the command loader.\n */\n\n/**\n * Returns an action object used to register a new command.\n *\n * @param {WPCommandConfig} config Command config.\n *\n * @return {Object} action.\n */\nexport function registerCommand( config ) {\n\treturn {\n\t\ttype: 'REGISTER_COMMAND',\n\t\t...config,\n\t};\n}\n\n/**\n * Returns an action object used to unregister a command.\n *\n * @param {string} name Command name.\n *\n * @return {Object} action.\n */\nexport function unregisterCommand( name ) {\n\treturn {\n\t\ttype: 'UNREGISTER_COMMAND',\n\t\tname,\n\t};\n}\n\n/**\n * Register command loader.\n *\n * @param {WPCommandLoaderConfig} config Command loader config.\n *\n * @return {Object} action.\n */\nexport function registerCommandLoader( config ) {\n\treturn {\n\t\ttype: 'REGISTER_COMMAND_LOADER',\n\t\t...config,\n\t};\n}\n\n/**\n * Unregister command loader hook.\n *\n * @param {string} name Command loader name.\n *\n * @return {Object} action.\n */\nexport function unregisterCommandLoader( name ) {\n\treturn {\n\t\ttype: 'UNREGISTER_COMMAND_LOADER',\n\t\tname,\n\t};\n}\n\n/**\n * Opens the command palette.\n *\n * @return {Object} action.\n */\nexport function open() {\n\treturn {\n\t\ttype: 'OPEN',\n\t};\n}\n\n/**\n * Closes the command palette.\n *\n * @return {Object} action.\n */\nexport function close() {\n\treturn {\n\t\ttype: 'CLOSE',\n\t};\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAeA,CAAEC,MAAM,EAAG;EACzC,OAAO;IACNC,IAAI,EAAE,kBAAkB;IACxB,GAAGD;EACJ,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,iBAAiBA,CAAEC,IAAI,EAAG;EACzC,OAAO;IACNF,IAAI,EAAE,oBAAoB;IAC1BE;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,qBAAqBA,CAAEJ,MAAM,EAAG;EAC/C,OAAO;IACNC,IAAI,EAAE,yBAAyB;IAC/B,GAAGD;EACJ,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASK,uBAAuBA,CAAEF,IAAI,EAAG;EAC/C,OAAO;IACNF,IAAI,EAAE,2BAA2B;IACjCE;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASG,IAAIA,CAAA,EAAG;EACtB,OAAO;IACNL,IAAI,EAAE;EACP,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASM,KAAKA,CAAA,EAAG;EACvB,OAAO;IACNN,IAAI,EAAE;EACP,CAAC;AACF"}
|
|
@@ -84,6 +84,9 @@ export default function useCommandLoader(loader) {
|
|
|
84
84
|
unregisterCommandLoader
|
|
85
85
|
} = useDispatch(commandsStore);
|
|
86
86
|
useEffect(() => {
|
|
87
|
+
if (loader.disabled) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
87
90
|
registerCommandLoader({
|
|
88
91
|
name: loader.name,
|
|
89
92
|
hook: loader.hook,
|
|
@@ -92,6 +95,6 @@ export default function useCommandLoader(loader) {
|
|
|
92
95
|
return () => {
|
|
93
96
|
unregisterCommandLoader(loader.name);
|
|
94
97
|
};
|
|
95
|
-
}, [loader.name, loader.hook, loader.context, registerCommandLoader, unregisterCommandLoader]);
|
|
98
|
+
}, [loader.name, loader.hook, loader.context, loader.disabled, registerCommandLoader, unregisterCommandLoader]);
|
|
96
99
|
}
|
|
97
100
|
//# sourceMappingURL=use-command-loader.js.map
|
|
@@ -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. 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;
|
|
1
|
+
{"version":3,"names":["useEffect","useDispatch","store","commandsStore","useCommandLoader","loader","registerCommandLoader","unregisterCommandLoader","disabled","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\tif ( loader.disabled ) {\n\t\t\treturn;\n\t\t}\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\tloader.disabled,\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;IAChB,IAAKK,MAAM,CAACG,QAAQ,EAAG;MACtB;IACD;IACAF,qBAAqB,CAAE;MACtBG,IAAI,EAAEJ,MAAM,CAACI,IAAI;MACjBC,IAAI,EAAEL,MAAM,CAACK,IAAI;MACjBC,OAAO,EAAEN,MAAM,CAACM;IACjB,CAAE,CAAC;IACH,OAAO,MAAM;MACZJ,uBAAuB,CAAEF,MAAM,CAACI,IAAK,CAAC;IACvC,CAAC;EACF,CAAC,EAAE,CACFJ,MAAM,CAACI,IAAI,EACXJ,MAAM,CAACK,IAAI,EACXL,MAAM,CAACM,OAAO,EACdN,MAAM,CAACG,QAAQ,EACfF,qBAAqB,EACrBC,uBAAuB,CACtB,CAAC;AACJ"}
|
|
@@ -40,6 +40,9 @@ export default function useCommand(command) {
|
|
|
40
40
|
currentCallback.current = command.callback;
|
|
41
41
|
}, [command.callback]);
|
|
42
42
|
useEffect(() => {
|
|
43
|
+
if (command.disabled) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
43
46
|
registerCommand({
|
|
44
47
|
name: command.name,
|
|
45
48
|
context: command.context,
|
|
@@ -51,6 +54,6 @@ export default function useCommand(command) {
|
|
|
51
54
|
return () => {
|
|
52
55
|
unregisterCommand(command.name);
|
|
53
56
|
};
|
|
54
|
-
}, [command.name, command.label, command.searchLabel, command.icon, command.context, registerCommand, unregisterCommand]);
|
|
57
|
+
}, [command.name, command.label, command.searchLabel, command.icon, command.context, command.disabled, registerCommand, unregisterCommand]);
|
|
55
58
|
}
|
|
56
59
|
//# sourceMappingURL=use-command.js.map
|
|
@@ -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. 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;
|
|
1
|
+
{"version":3,"names":["useEffect","useRef","useDispatch","store","commandsStore","useCommand","command","registerCommand","unregisterCommand","currentCallback","callback","current","disabled","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\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\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\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,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;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;MAClBP,QAAQ,EAAEA,CAAE,GAAGQ,IAAI,KAAMT,eAAe,CAACE,OAAO,CAAE,GAAGO,IAAK;IAC3D,CAAE,CAAC;IACH,OAAO,MAAM;MACZV,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,CAACM,QAAQ,EAChBL,eAAe,EACfC,iBAAiB,CAChB,CAAC;AACJ"}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* @property {string=} context Command context.
|
|
12
12
|
* @property {JSX.Element} icon Command icon.
|
|
13
13
|
* @property {Function} callback Command callback.
|
|
14
|
+
* @property {boolean} disabled Whether to disable the command.
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -22,9 +23,10 @@
|
|
|
22
23
|
*
|
|
23
24
|
* @typedef {Object} WPCommandLoaderConfig
|
|
24
25
|
*
|
|
25
|
-
* @property {string} name
|
|
26
|
-
* @property {string=} context
|
|
27
|
-
* @property {WPCommandLoaderHook} hook
|
|
26
|
+
* @property {string} name Command loader name.
|
|
27
|
+
* @property {string=} context Command loader context.
|
|
28
|
+
* @property {WPCommandLoaderHook} hook Command loader hook.
|
|
29
|
+
* @property {boolean} disabled Whether to disable the command loader.
|
|
28
30
|
*/
|
|
29
31
|
|
|
30
32
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["registerCommand","config","type","unregisterCommand","name","registerCommandLoader","unregisterCommandLoader","open","close"],"sources":["@wordpress/commands/src/store/actions.js"],"sourcesContent":["/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */\n\n/**\n * Configuration of a registered keyboard shortcut.\n *\n * @typedef {Object} WPCommandConfig\n *\n * @property {string} name Command name.\n * @property {string} label Command label.\n * @property {string=} searchLabel Command search label.\n * @property {string=} context Command context.\n * @property {JSX.Element} icon Command icon.\n * @property {Function} callback Command callback.\n */\n\n/**\n * @typedef {(search: string) => WPCommandConfig[]} WPCommandLoaderHook hoo\n */\n\n/**\n * Command loader config.\n *\n * @typedef {Object} WPCommandLoaderConfig\n *\n * @property {string} name
|
|
1
|
+
{"version":3,"names":["registerCommand","config","type","unregisterCommand","name","registerCommandLoader","unregisterCommandLoader","open","close"],"sources":["@wordpress/commands/src/store/actions.js"],"sourcesContent":["/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */\n\n/**\n * Configuration of a registered keyboard shortcut.\n *\n * @typedef {Object} WPCommandConfig\n *\n * @property {string} name Command name.\n * @property {string} label Command label.\n * @property {string=} searchLabel Command search label.\n * @property {string=} context Command context.\n * @property {JSX.Element} icon Command icon.\n * @property {Function} callback Command callback.\n * @property {boolean} disabled Whether to disable the command.\n */\n\n/**\n * @typedef {(search: string) => WPCommandConfig[]} WPCommandLoaderHook hoo\n */\n\n/**\n * Command loader config.\n *\n * @typedef {Object} WPCommandLoaderConfig\n *\n * @property {string} name Command loader name.\n * @property {string=} context Command loader context.\n * @property {WPCommandLoaderHook} hook Command loader hook.\n * @property {boolean} disabled Whether to disable the command loader.\n */\n\n/**\n * Returns an action object used to register a new command.\n *\n * @param {WPCommandConfig} config Command config.\n *\n * @return {Object} action.\n */\nexport function registerCommand( config ) {\n\treturn {\n\t\ttype: 'REGISTER_COMMAND',\n\t\t...config,\n\t};\n}\n\n/**\n * Returns an action object used to unregister a command.\n *\n * @param {string} name Command name.\n *\n * @return {Object} action.\n */\nexport function unregisterCommand( name ) {\n\treturn {\n\t\ttype: 'UNREGISTER_COMMAND',\n\t\tname,\n\t};\n}\n\n/**\n * Register command loader.\n *\n * @param {WPCommandLoaderConfig} config Command loader config.\n *\n * @return {Object} action.\n */\nexport function registerCommandLoader( config ) {\n\treturn {\n\t\ttype: 'REGISTER_COMMAND_LOADER',\n\t\t...config,\n\t};\n}\n\n/**\n * Unregister command loader hook.\n *\n * @param {string} name Command loader name.\n *\n * @return {Object} action.\n */\nexport function unregisterCommandLoader( name ) {\n\treturn {\n\t\ttype: 'UNREGISTER_COMMAND_LOADER',\n\t\tname,\n\t};\n}\n\n/**\n * Opens the command palette.\n *\n * @return {Object} action.\n */\nexport function open() {\n\treturn {\n\t\ttype: 'OPEN',\n\t};\n}\n\n/**\n * Closes the command palette.\n *\n * @return {Object} action.\n */\nexport function close() {\n\treturn {\n\t\ttype: 'CLOSE',\n\t};\n}\n"],"mappings":"AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,eAAeA,CAAEC,MAAM,EAAG;EACzC,OAAO;IACNC,IAAI,EAAE,kBAAkB;IACxB,GAAGD;EACJ,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,iBAAiBA,CAAEC,IAAI,EAAG;EACzC,OAAO;IACNF,IAAI,EAAE,oBAAoB;IAC1BE;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAAEJ,MAAM,EAAG;EAC/C,OAAO;IACNC,IAAI,EAAE,yBAAyB;IAC/B,GAAGD;EACJ,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,uBAAuBA,CAAEF,IAAI,EAAG;EAC/C,OAAO;IACNF,IAAI,EAAE,2BAA2B;IACjCE;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,IAAIA,CAAA,EAAG;EACtB,OAAO;IACNL,IAAI,EAAE;EACP,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM,KAAKA,CAAA,EAAG;EACvB,OAAO;IACNN,IAAI,EAAE;EACP,CAAC;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/commands",
|
|
3
|
-
"version": "0.19.0",
|
|
3
|
+
"version": "0.19.1-next.79a6196f.0",
|
|
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": "^25.
|
|
31
|
-
"@wordpress/data": "^9.18.0",
|
|
32
|
-
"@wordpress/element": "^5.25.0",
|
|
33
|
-
"@wordpress/i18n": "^4.48.0",
|
|
34
|
-
"@wordpress/icons": "^9.39.0",
|
|
35
|
-
"@wordpress/keyboard-shortcuts": "^4.25.0",
|
|
36
|
-
"@wordpress/private-apis": "^0.30.0",
|
|
30
|
+
"@wordpress/components": "^25.15.1-next.79a6196f.0",
|
|
31
|
+
"@wordpress/data": "^9.18.1-next.79a6196f.0",
|
|
32
|
+
"@wordpress/element": "^5.25.1-next.79a6196f.0",
|
|
33
|
+
"@wordpress/i18n": "^4.48.1-next.79a6196f.0",
|
|
34
|
+
"@wordpress/icons": "^9.39.1-next.79a6196f.0",
|
|
35
|
+
"@wordpress/keyboard-shortcuts": "^4.25.1-next.79a6196f.0",
|
|
36
|
+
"@wordpress/private-apis": "^0.30.1-next.79a6196f.0",
|
|
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": "
|
|
48
|
+
"gitHead": "1e74b942ac0119a22ceaaf5c9594263f3ec516ab"
|
|
49
49
|
}
|
|
@@ -82,6 +82,9 @@ export default function useCommandLoader( loader ) {
|
|
|
82
82
|
const { registerCommandLoader, unregisterCommandLoader } =
|
|
83
83
|
useDispatch( commandsStore );
|
|
84
84
|
useEffect( () => {
|
|
85
|
+
if ( loader.disabled ) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
85
88
|
registerCommandLoader( {
|
|
86
89
|
name: loader.name,
|
|
87
90
|
hook: loader.hook,
|
|
@@ -94,6 +97,7 @@ export default function useCommandLoader( loader ) {
|
|
|
94
97
|
loader.name,
|
|
95
98
|
loader.hook,
|
|
96
99
|
loader.context,
|
|
100
|
+
loader.disabled,
|
|
97
101
|
registerCommandLoader,
|
|
98
102
|
unregisterCommandLoader,
|
|
99
103
|
] );
|
package/src/hooks/use-command.js
CHANGED
|
@@ -38,6 +38,9 @@ export default function useCommand( command ) {
|
|
|
38
38
|
}, [ command.callback ] );
|
|
39
39
|
|
|
40
40
|
useEffect( () => {
|
|
41
|
+
if ( command.disabled ) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
41
44
|
registerCommand( {
|
|
42
45
|
name: command.name,
|
|
43
46
|
context: command.context,
|
|
@@ -55,6 +58,7 @@ export default function useCommand( command ) {
|
|
|
55
58
|
command.searchLabel,
|
|
56
59
|
command.icon,
|
|
57
60
|
command.context,
|
|
61
|
+
command.disabled,
|
|
58
62
|
registerCommand,
|
|
59
63
|
unregisterCommand,
|
|
60
64
|
] );
|
package/src/store/actions.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* @property {string=} context Command context.
|
|
12
12
|
* @property {JSX.Element} icon Command icon.
|
|
13
13
|
* @property {Function} callback Command callback.
|
|
14
|
+
* @property {boolean} disabled Whether to disable the command.
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -22,9 +23,10 @@
|
|
|
22
23
|
*
|
|
23
24
|
* @typedef {Object} WPCommandLoaderConfig
|
|
24
25
|
*
|
|
25
|
-
* @property {string} name
|
|
26
|
-
* @property {string=} context
|
|
27
|
-
* @property {WPCommandLoaderHook} hook
|
|
26
|
+
* @property {string} name Command loader name.
|
|
27
|
+
* @property {string=} context Command loader context.
|
|
28
|
+
* @property {WPCommandLoaderHook} hook Command loader hook.
|
|
29
|
+
* @property {boolean} disabled Whether to disable the command loader.
|
|
28
30
|
*/
|
|
29
31
|
|
|
30
32
|
/**
|