Skip to content

Commit

Permalink
Documentation: Add the auto-generated commands store documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jul 12, 2023
1 parent e448fa7 commit ab113e3
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 0 deletions.
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;
}

0 comments on commit ab113e3

Please sign in to comment.