diff --git a/packages/commands/README.md b/packages/commands/README.md index 3113c540e4dd05..0e0afdce394c99 100644 --- a/packages/commands/README.md +++ b/packages/commands/README.md @@ -24,6 +24,22 @@ Undocumented declaration. Undocumented declaration. +### useCommand + +Attach a command to the Global command menu. + +_Parameters_ + +- _command_ `import('../store/actions').WPCommandConfig`: command config. + +### useCommandLoader + +Attach a command loader to the Global command menu. + +_Parameters_ + +- _loader_ `import('../store/actions').WPCommandLoaderConfig`: command loader config. + ## Contributing to this package diff --git a/packages/commands/src/index.js b/packages/commands/src/index.js index fbac76197f0b24..afc7ac27b7d5f4 100644 --- a/packages/commands/src/index.js +++ b/packages/commands/src/index.js @@ -1,2 +1,4 @@ export { CommandMenu } from './components/command-menu'; export { privateApis } from './private-apis'; +export { default as useCommand } from './hooks/use-command'; +export { default as useCommandLoader } from './hooks/use-command-loader'; diff --git a/packages/commands/src/private-apis.js b/packages/commands/src/private-apis.js index 3e8bfab2343c18..7348711efd3517 100644 --- a/packages/commands/src/private-apis.js +++ b/packages/commands/src/private-apis.js @@ -6,8 +6,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri /** * Internal dependencies */ -import { default as useCommand } from './hooks/use-command'; -import { default as useCommandLoader } from './hooks/use-command-loader'; import { default as useCommandContext } from './hooks/use-command-context'; import { store } from './store'; @@ -19,8 +17,6 @@ export const { lock, unlock } = export const privateApis = {}; lock( privateApis, { - useCommand, - useCommandLoader, useCommandContext, store, } ); diff --git a/packages/core-commands/src/add-post-type-commands.js b/packages/core-commands/src/add-post-type-commands.js index 3c2a7ea8c52cdd..47e6014f569444 100644 --- a/packages/core-commands/src/add-post-type-commands.js +++ b/packages/core-commands/src/add-post-type-commands.js @@ -1,17 +1,10 @@ /** * WordPress dependencies */ -import { privateApis } from '@wordpress/commands'; +import { useCommand } from '@wordpress/commands'; import { __ } from '@wordpress/i18n'; import { plus } from '@wordpress/icons'; -/** - * Internal dependencies - */ -import { unlock } from './lock-unlock'; - -const { useCommand } = unlock( privateApis ); - export function useAddPostTypeCommands() { useCommand( { name: 'core/add-new-post', diff --git a/packages/core-commands/src/site-editor-navigation-commands.js b/packages/core-commands/src/site-editor-navigation-commands.js index 1bf29fa08f9cea..31f65bb98579e2 100644 --- a/packages/core-commands/src/site-editor-navigation-commands.js +++ b/packages/core-commands/src/site-editor-navigation-commands.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { privateApis } from '@wordpress/commands'; +import { useCommandLoader } from '@wordpress/commands'; import { __ } from '@wordpress/i18n'; import { useMemo } from '@wordpress/element'; import { useSelect } from '@wordpress/data'; @@ -15,7 +15,6 @@ import { getQueryArg, addQueryArgs, getPath } from '@wordpress/url'; */ import { unlock } from './lock-unlock'; -const { useCommandLoader } = unlock( privateApis ); const { useHistory } = unlock( routerPrivateApis ); const icons = { diff --git a/packages/edit-site/src/hooks/commands/use-edit-mode-commands.js b/packages/edit-site/src/hooks/commands/use-edit-mode-commands.js index 67b7164edcdab5..4aef33ac2b1cfc 100644 --- a/packages/edit-site/src/hooks/commands/use-edit-mode-commands.js +++ b/packages/edit-site/src/hooks/commands/use-edit-mode-commands.js @@ -4,7 +4,7 @@ import { useDispatch } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; import { trash, backup } from '@wordpress/icons'; -import { privateApis as commandsPrivateApis } from '@wordpress/commands'; +import { useCommandLoader } from '@wordpress/commands'; import { privateApis as routerPrivateApis } from '@wordpress/router'; /** @@ -16,7 +16,6 @@ import isTemplateRemovable from '../../utils/is-template-removable'; import isTemplateRevertable from '../../utils/is-template-revertable'; import { unlock } from '../../private-apis'; -const { useCommandLoader } = unlock( commandsPrivateApis ); const { useHistory } = unlock( routerPrivateApis ); function useEditModeCommandLoader() {