npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@finpress/commands

v1.29.0

Published

Handles the commands menu.

Downloads

2

Readme

Commands

Commands is a generic package that allows registering and modifying commands to be displayed using the commands menu, also called the Command Palette. The Command Palette can be accessed in the Editor using cmd+k.

Types of commands

There are two ways to register commands: static or dynamic. Both methods receive a command object as an argument, which provides:

  • name: A unique machine-readable name for the command
  • label: A human-readable label
  • icon: An SVG icon
  • callback: A callback function that is called when the command is selected
  • context: (Optional) The context of the command
  • keywords: (Optional) An array of keywords for search matching

Static commands

Static commands can be registered using the fp.data.dispatch( fp.commands.store ).registerCommand action or using the fp.commands.useCommand React hook. Static commands are commonly used to perform a specific action. These could include adding a new page or opening a section of the Editor interface, such as opening the Editor Preferences modal. See the useCommand code example below.

Dynamic commands

Dynamic commands, on the other hand, are registered using “command loaders", fp.commands.useCommandLoader. These loaders are needed when the command list depends on a search term entered by the user in the Command Palette input or when some commands are only available when some conditions are met.

For example, when a user types "contact", the Command Palette needs to filter the available pages using that input to try and find the Contact page. See the useCommandLoader code example below.

Contextual commands

Static and dynamic commands can be contextual. This means that in a given context (for example, when navigating the Site Editor or editing a template), some specific commands are given more priority and are visible as soon as you open the Command Palette. Also, when typing the Command Palette, these contextual commands are shown above the rest of the commands.

At the moment, three contexts have been implemented:

  • site-editor: This is the context that is set when you are navigating in the site editor (sidebar visible).
  • entity-edit: This is the context that is set when you are editing a document (template, template part or page).
  • block-selection-edit: This is the context that is set when a block is selected.

As the usage of the Command Palette expands, more contexts will be added.

Attaching a command or command loader to a given context is as simple as adding the context property (with the right context value from the available contexts above) to the useCommand or useCommandLoader calls.

FinPress Data API

The Command Palette also offers a number of selectors and actions to manipulate its state, which include:

  • Retrieving the registered commands and command loaders using the following selectors getCommands and getCommandLoader
  • Checking if the Command Palette is open using the isOpen selector.
  • Programmatically open or close the Command Palette using the open and close actions.

See the Commands Data documentation for more information.

Installation

Install the module

npm install @finpress/commands --save

This package assumes that your code will run in an ES2015+ environment. If you're using an environment that has limited or no support for such language features and APIs, you should include the polyfill shipped in @finpress/babel-preset-default in your code.

This package requires the following stylesheets to be included for proper styling:

/* From node_modules: */
@import '@finpress/components/build-style/style.css';
@import '@finpress/commands/build-style/style.css';

API

store

Store definition for the commands namespace.

Related

Usage

import { store as commandsStore } from '@finpress/commands';
import { useDispatch } from '@finpress/data';
...
const { open: openCommandCenter } = useDispatch( commandsStore );

Type

  • Object

useCommand

Attach a command to the command palette. Used for static commands.

Usage

import { useCommand } from '@finpress/commands';
import { plus } from '@finpress/icons';

useCommand( {
	name: 'myplugin/my-command-name',
	label: __( 'Add new post' ),
	icon: plus,
	callback: ( { close } ) => {
		document.location.href = 'post-new.php';
		close();
	},
} );

Parameters

  • command import('../store/actions').FPCommandConfig: command config.

useCommandLoader

Attach a command loader to the command palette. Used for dynamic commands.

Usage

import { useCommandLoader } from '@finpress/commands';
import { post, page, layout, symbolFilled } from '@finpress/icons';

const icons = {
    post,
    page,
    fp_template: layout,
    fp_template_part: symbolFilled,
};

function usePageSearchCommandLoader( { search } ) {
    // Retrieve the pages for the "search" term.
    const { records, isLoading } = useSelect( ( select ) => {
        const { getEntityRecords } = select( coreStore );
        const query = {
            search: !! search ? search : undefined,
            per_page: 10,
            orderby: search ? 'relevance' : 'date',
        };
        return {
            records: getEntityRecords( 'postType', 'page', query ),
            isLoading: ! select( coreStore ).hasFinishedResolution(
                'getEntityRecords',
                'postType', 'page', query ]
            ),
        };
    }, [ search ] );

    // Create the commands.
    const commands = useMemo( () => {
        return ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {
            return {
                name: record.title?.rendered + ' ' + record.id,
                label: record.title?.rendered
                    ? record.title?.rendered
                    : __( '(no title)' ),
                icon: icons[ postType ],
                callback: ( { close } ) => {
                    const args = {
                        postType,
                        postId: record.id,
                        ...extraArgs,
                    };
                    document.location = addQueryArgs( 'site-editor.php', args );
                    close();
                },
            };
        } );
    }, [ records, history ] );

    return {
        commands,
        isLoading,
    };
}

useCommandLoader( {
    name: 'myplugin/page-search',
    hook: usePageSearchCommandLoader,
} );

Parameters

  • loader import('../store/actions').FPCommandLoaderConfig: command loader config.

Contributing to this package

This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to npm and used by FinPress as well as other software projects.

To find out more about contributing to this package or Gutenberg as a whole, please read the project's main contributor guide.