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

grapesjs-context-menu

v1.3.1

Published

GrapesJS plugin: right-click context menu for the canvas and the Layer Manager (add block inside, select parent/child, reorder, move, clone, delete) plus a clickable hierarchy badge on the selected element.

Readme

grapesjs-context-menu

Patreon

A GrapesJS plugin that adds a right-click context menu to the canvas and to the Layer Manager, plus a clickable hierarchy badge over the selected element.

Menu items:

| Item | What it does | | --- | --- | | Add element ▸ | Submenu with every Block Manager block, grouped by category. The block is appended inside the target component. Disabled for droppable: false. | | Select parent / Select child | Moves the selection one level up / to the first selectable child. | | Move up / Move down | Reorders the component among its siblings. | | Move (drag) | Starts the same tlb-move command as the toolbar's "arrows" button: move the pointer, click to drop. | | Duplicate | Runs tlb-clone. | | Font ▸ | Only with grapesjs-fonts 0.2+. Submenu with the fonts of the project (each in its own face, the current one checked). Applies to the text selected in the canvas (it is wrapped in a <span>), otherwise to the whole element (what the Style Manager edits for it). Default font removes the element's font-family, More fonts… opens the font browser. Works from the Layer Manager too. | | View styles | Runs viewStylesCommand. Shown only when that command is registered. | | Delete | Removes the component. Disabled for removable: false. |

Every item respects the component's draggable, copyable, removable and droppable flags; impossible actions are shown disabled.

Hierarchy badge — a Name ▾ pill sitting over the selected element. Clicking it lists the element and all its ancestors up to <body>; picking one selects it. A right-click inside the selected element keeps working with it, so "pick an ancestor in the badge → right-click" is how you act on a wrapper that is hard to click directly.

Keyboard: ↑/↓ move over enabled items, → opens "Add element" / "Font", ←/Esc close the submenu, Enter activates, Esc closes the menu.

Installation

npm install grapesjs-context-menu
import grapesjs from 'grapesjs';
import contextMenu from 'grapesjs-context-menu';

grapesjs.init({
  container: '#gjs',
  plugins: [contextMenu],
  pluginsOpts: {
    [contextMenu]: {
      /* options */
    },
  },
});

Or pass the options with a wrapper function:

plugins: [(editor) => contextMenu(editor, { blocks: ['text', 'image'] })];

Without a bundler

The UMD build registers the global grapesjsContextMenu (an object with the plugin as default, like the ES module):

<link rel="stylesheet" href="https://unpkg.com/grapesjs/dist/css/grapes.min.css" />
<script src="https://unpkg.com/grapesjs"></script>
<script src="https://unpkg.com/grapesjs-context-menu/dist/grapesjs-context-menu.umd.cjs"></script>
<script>
  grapesjs.init({
    container: '#gjs',
    plugins: [grapesjsContextMenu.default],
  });
</script>

The plugin can also be applied to an editor that is already running: grapesjsContextMenu.default(editor, { ... }).

Options

| Option | Type | Default | Description | | --- | --- | --- | --- | | blocks | string[] \| null | null | Block ids shown in "Add element". null = all blocks. | | canvasMenu | boolean | true | Right-click menu inside the canvas. | | layersMenu | boolean | true | Right-click menu on Layer Manager rows (wherever the Layer Manager is rendered). | | hierarchyBadge | boolean | true | The Name ▾ badge over the selected element. | | fontsMenu | boolean | true | The "Font" submenu when grapesjs-fonts is installed (found as editor.Fonts, no dependency). | | viewStylesCommand | string \| null | 'layers-sidebar:show-styles' | Command run by "View styles". The item is hidden while the command isn't registered; null hides it for good. | | labels | Partial<ContextMenuLabels> | {} | Text overrides, see below. | | injectCss | boolean | true | Inject the plugin CSS. Turn off to ship your own styles (classes are prefixed with gjs-cm-). | | extendMenu | (items, ctx) => items | — | Change the item list before rendering: reorder, remove, add your own items. |

Custom items

contextMenu(editor, {
  extendMenu: (items, { component }) => [
    ...items.filter((item) => item.id !== 'move'),
    {
      id: 'log',
      icon: '★',
      label: 'Log to console',
      separator: true, // line above the item
      disabled: !component.getId(),
      run: ({ component, editor, source }) => console.log(source, component.toHTML()),
    },
  ],
});

Built-in item ids: add, parent, child, up, down, move, clone, styles, delete.

Items from other plugins

A plugin can add its own items without touching the menu options: listen to context-menu:items and push items with a run function. They are shown before Delete; extendMenu still runs last, so the site keeps the final word. grapesjs-pages adds Edit component / Detach from component on its linked components and Save as component on everything else this way.

editor.on('context-menu:items', ({ items, ctx }) => {
  if (ctx.component.is('image')) {
    items.push({ id: 'crop', icon: '✂', label: 'Crop', separator: true, run: ({ component }) => crop(component) });
  }
});

Translations

Labels come from the editor's I18n module under the contextMenu.* keys. The plugin ships translations for every language GrapesJS core itself ships (grapesjs/locale): ar, bs, ca, de, el, en, es, fa, fr, he, id, it, ko, nb, nl, pl, pt, ru, se (Swedish — the core's historical code), tr, vi, zh — plus Ukrainian (uk).

Nothing has to be configured: GrapesJS picks the locale from the browser language (i18n.detectLocale, on by default) or from i18n: { locale: 'de' } in the config, and falls back to English for other languages. The list is exported as SUPPORTED_LOCALES, the messages as locales.

Add another language or change a phrase the GrapesJS way — after the plugin is loaded, since the later addMessages() call wins:

editor.onReady(() => {
  editor.I18n.addMessages({
    ja: {
      contextMenu: {
        add: '要素を追加',
        delete: '削除',
        // ...
      },
    },
  });
});

The labels option wins over I18n and is the quickest way to override a single text. Keys: add, noBlocks, selectParent, selectChild, moveUp, moveDown, move, clone, viewStyles, delete, hierarchyTitle, font, fontSelection, fontElement, noFonts, fontDefault, fontMore.

Events

| Event | Payload | | --- | --- | | context-menu:open | { component, source } — source is 'canvas' or 'layers' | | context-menu:action | { id, component, source }; for "Add element" also added (the new component) and block (block id); for "Font" also family (null = default) and selection (applied to selected text) | | context-menu:close | { component } | | context-menu:items | { items, ctx } — fired while the menu is built; push your items (with run) into items |

editor.on('context-menu:action', ({ id, component }) => { /* ... */ });

API

import { getContextMenu } from 'grapesjs-context-menu';

const menu = getContextMenu(editor);
menu.open(x, y, editor.getSelected()); // viewport coordinates of the host page
menu.open(x, y, component, 'canvas', range); // with a text Range: "Font" applies to it
menu.close();
menu.isOpen;
menu.destroy(); // remove every listener and element of the plugin

The plugin cleans up after editor.destroy() by itself.

Compatibility

GrapesJS >=0.21 <1.0. Tested against 0.21.13.

Development

npm install
npm run dev        # playground: index.html with the plugin from src/
npm test           # vitest + jsdom, a real GrapesJS editor per test
npm run typecheck  # src and tests
npm run build      # dist/: ES module, UMD, .d.ts

Using it by name and changing options in the editor

This plugin follows the plugin contract of grapesjs-plugins-manager (its docs/plugin-contract.md): with the UMD bundle on the page it registers itself as grapesjs-context-menu, so it can be listed like an official plugin —

grapesjs.init({
  plugins: ['grapesjs-context-menu'],
  pluginsOpts: { 'grapesjs-context-menu': { /* options */ } },
});

— and grapesjs-plugins-manager shows a form of its options (⚙ in the plugin list). The plugin function carries meta (id, version, option schema).

License

MIT

Patreon

If this project helps you, consider supporting its development on Patreon ❤️