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

  • 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 - 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

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', editDefault: true, 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', editDefault: true, editorLabel:'Hi I am a test menu > item'}
  }
)