@wordpress/commands
Version:
Handles the commands menu.
61 lines (56 loc) • 1.91 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getCommands = exports.getCommandLoaders = void 0;
exports.getContext = getContext;
exports.isOpen = isOpen;
var _data = require("@wordpress/data");
/**
* WordPress dependencies
*/
/**
* 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.
*/
const getCommands = exports.getCommands = (0, _data.createSelector)((state, contextual = false) => Object.values(state.commands).filter(command => {
const isContextual = command.context && command.context === state.context;
return contextual ? isContextual : !isContextual;
}), 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.
*/
const getCommandLoaders = exports.getCommandLoaders = (0, _data.createSelector)((state, contextual = false) => Object.values(state.commandLoaders).filter(loader => {
const isContextual = loader.context && loader.context === state.context;
return contextual ? isContextual : !isContextual;
}), 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.
*/
function isOpen(state) {
return state.isOpen;
}
/**
* Returns whether the active context.
*
* @param {Object} state State tree.
*
* @return {string} Context.
*/
function getContext(state) {
return state.context;
}
//# sourceMappingURL=selectors.js.map
;