Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: Add the auto-generated commands store documentation #52562

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/reference-guides/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [**core/block-directory**: Block directory](/docs/reference-guides/data/data-core-block-directory.md)
- [**core/block-editor**: The Block Editor’s Data](/docs/reference-guides/data/data-core-block-editor.md)
- [**core/blocks**: Block Types Data](/docs/reference-guides/data/data-core-blocks.md)
- [**core/commands**: Command Palette](/docs/reference-guides/data/data-core-commands.md)
- [**core/customize-widgets**: Customize Widgets](/docs/reference-guides/data/data-core-customize-widgets.md)
- [**core/edit-post**: The Editor’s UI Data](/docs/reference-guides/data/data-core-edit-post.md)
- [**core/edit-site**: Edit Site](/docs/reference-guides/data/data-core-edit-site.md)
Expand Down
129 changes: 129 additions & 0 deletions docs/reference-guides/data/data-core-commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# The Commands Data

Namespace: `core/commands`.

## Selectors

<!-- START TOKEN(Autogenerated selectors|../../../packages/commands/src/store/selectors.js) -->

### getCommandLoaders

Returns the registered command loaders.

_Parameters_

- _state_ `Object`: State tree.
- _contextual_ `boolean`: Whether to return only contextual command loaders.

_Returns_

- `import('./actions').WPCommandLoaderConfig[]`: The list of registered command loaders.

### getCommands

Returns the registered static commands.

_Parameters_

- _state_ `Object`: State tree.
- _contextual_ `boolean`: Whether to return only contextual commands.

_Returns_

- `import('./actions').WPCommandConfig[]`: The list of registered commands.

### getContext

Returns whether the active context.

_Parameters_

- _state_ `Object`: State tree.

_Returns_

- `string`: Context.

### isOpen

Returns whether the command palette is open.

_Parameters_

- _state_ `Object`: State tree.

_Returns_

- `boolean`: Returns whether the command palette is open.

<!-- END TOKEN(Autogenerated selectors|../../../packages/commands/src/store/selectors.js) -->

## Actions

<!-- START TOKEN(Autogenerated actions|../../../packages/commands/src/store/actions.js) -->

### close

Closes the command palette.

_Returns_

- `Object`: action.

### open

Opens the command palette.

_Returns_

- `Object`: action.

### registerCommand

Returns an action object used to register a new command.

_Parameters_

- _config_ `WPCommandConfig`: Command config.

_Returns_

- `Object`: action.

### registerCommandLoader

Register command loader.

_Parameters_

- _config_ `WPCommandLoaderConfig`: Command loader config.

_Returns_

- `Object`: action.

### unregisterCommand

Returns an action object used to unregister a command.

_Parameters_

- _name_ `string`: Command name.

_Returns_

- `Object`: action.

### unregisterCommandLoader

Unregister command loader hook.

_Parameters_

- _name_ `string`: Command loader name.

_Returns_

- `Object`: action.

<!-- END TOKEN(Autogenerated actions|../../../packages/commands/src/store/actions.js) -->
30 changes: 30 additions & 0 deletions packages/commands/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
*/
import createSelector from 'rememo';

/**
* Returns the registered static commands.
*
* @param {Object} state State tree.
* @param {boolean} contextual Whether to return only contextual commands.
*
* @return {import('./actions').WPCommandConfig[]} The list of registered commands.
*/
export const getCommands = createSelector(
( state, contextual = false ) =>
Object.values( state.commands ).filter( ( command ) => {
Expand All @@ -13,6 +21,14 @@ export const getCommands = createSelector(
( state ) => [ state.commands, state.context ]
);

/**
* Returns the registered command loaders.
*
* @param {Object} state State tree.
* @param {boolean} contextual Whether to return only contextual command loaders.
*
* @return {import('./actions').WPCommandLoaderConfig[]} The list of registered command loaders.
*/
export const getCommandLoaders = createSelector(
( state, contextual = false ) =>
Object.values( state.commandLoaders ).filter( ( loader ) => {
Expand All @@ -23,10 +39,24 @@ export const getCommandLoaders = createSelector(
( state ) => [ state.commandLoaders, state.context ]
);

/**
* Returns whether the command palette is open.
*
* @param {Object} state State tree.
*
* @return {boolean} Returns whether the command palette is open.
*/
export function isOpen( state ) {
return state.isOpen;
}

/**
* Returns whether the active context.
*
* @param {Object} state State tree.
*
* @return {string} Context.
*/
export function getContext( state ) {
return state.context;
}