Skip to main content Link Search Menu Expand Document (external link)

The Menu Registry Interface

With the Menu Registry you can create menu items for the various menus.

There is only one menu registry interface and it can always be found at jancy.menuRegistry.

Methods

Registers a menu item. With the option.targetTemplate you can specify where to put the menu item and it will show up by default at the bottom of the menu. Without that option, it will be added to the plugin menu and can be moved in the editor.

  • id (string)
  • canShow (function) return a boolean for circumstances that allow the menu item to show. Return true to always show it.
  • getItem (function) return an object with id, label, and click properties.
  • options (object)
    • targetTemplate - can be ‘tab’, ‘tab-button’, ‘tab-button-multi’, and ‘app’
      • tab - right clicking the webpage
      • tab-button - right clicking a tab button
      • tab-button-multi - when multiple tabs are selected and the user right clicks them
      • app - the menu at the top of the app
    • editDefault - (removed) a boolean to determine if you want it automatically added to the default menus
    • editorLabel - a string that will show in the editor proceeded by Menu Item: e.g. Menu Item: Hi I am a test menu item
    • jancyMade - used internally to hide it from the plugin menu
    • insertBefore - specify the id of the menu item you would like to insert this menu item before. Makes it so that users can have their menu item show up without having to edit the menu manually after the menu item is created
    • canMove - allows the menu item to be moved in the editor
    • canDelete - allows the menu item to be deleted in the editor
    • hasIcons - allows the showing of icons on the menu editor (no add button, delete button, drag, or collapse icons)

This is an example of registering a single menu item.

jancy.menuRegistry.registerMenuItem(
      'tab-test-me',
      (jancy) => {
        return true
      },
      (jancy, {tab}) => {
        return {
          id: 'test',
          label: 'Test ME!',
          click: () => console.log('test clicked'),
        }
      },
      {targetTemplate:'tab', editorLabel:'Hi I am a test menu > item'}
)

Registering a menu item that returns a sub-menu.

const isShowing = true
jancy.menuRegistry.registerMenuItem(
  'tab-submenu-of-mine',
  (jancy) => isShowing,
  (jancy, {tab}) => {
    return {
      id: 'mine-submenu',
      label: 'Mine Sub',
      submenu: [
        {
          id: 'pie',
          label: 'pie',
          click: () => console.log('chicken, you great lummox')
        },
        {
          id: 'apples',
          label: 'apples',
          click: () => console.log('how bout them?')
        }
      ]
    },
    {targetTemplate:'tab', editorLabel:'Hi I am a test menu > item'}
  }
)