Type Editor / @type-editor/menu / MenuBarBuilder / MenuBarBuilder
Class: MenuBarBuilder
Defined in: packages/menu/src/MenuBarBuilder.ts:34
Builder for constructing a ProseMirror menu bar plugin.
Use addMenuGroup to add flat groups of items to the toolbar, and addDropDown to add dropdown menus. Finish with build() to produce the configured Plugin instance.
Example
const plugin = new MenuBarBuilder()
.addMenuGroup(boldItem, italicItem)
.addDropDown({ label: "Insert" }, tableItem, imageItem)
.build();Constructors
Constructor
new MenuBarBuilder(isLegacy?, floating?): MenuBarBuilder;Defined in: packages/menu/src/MenuBarBuilder.ts:48
Creates a new MenuBarBuilder.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
isLegacy | boolean | false | When true, dropdowns are rendered using the legacy DropdownLegacy component for backward compatibility. Defaults to false. |
floating | boolean | false | When true, the menu bar sticks to the top of the viewport while the editor is partially scrolled out of view. Defaults to false. |
Returns
MenuBarBuilder
Methods
addDropDown()
addDropDown(options?, ...menuElements): MenuBarBuilder;Defined in: packages/menu/src/MenuBarBuilder.ts:137
Adds a dropdown menu group to the menu bar.
If a single pre-built Dropdown instance is passed as the only element, it is added directly. Otherwise, all elements are collected and wrapped in a new Dropdown (or DropdownLegacy when the builder is in legacy mode).
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | { label?: string; showLabel?: boolean; title?: string; } | Optional display options for the dropdown trigger (e.g. label or title). |
options.label? | string | - |
options.showLabel? | boolean | - |
options.title? | string | - |
...menuElements? | MenuElementInput[] | One or more menu elements (or arrays thereof) to include in the dropdown. null / undefined entries are silently ignored. |
Returns
MenuBarBuilder
This builder instance for method chaining.
addMenuGroup()
addMenuGroup(...menuElements): MenuBarBuilder;Defined in: packages/menu/src/MenuBarBuilder.ts:181
Adds a flat group of menu elements to the menu bar.
Each group is rendered as a visually separated section of the toolbar. Arrays within menuElements are flattened; null / undefined entries are silently ignored.
Parameters
| Parameter | Type | Description |
|---|---|---|
...menuElements | ( | Dropdown | DropdownLegacy | MenuItem | MenuElement[])[] | One or more menu elements (or arrays thereof) to include in this group. |
Returns
MenuBarBuilder
This builder instance for method chaining.
addStaticDropDown()
addStaticDropDown(options?, ...menuElements): MenuBarBuilder;Defined in: packages/menu/src/MenuBarBuilder.ts:143
Parameters
| Parameter | Type |
|---|---|
options? | { label?: string; showLabel?: boolean; title?: string; } |
options.label? | string |
options.showLabel? | boolean |
options.title? | string |
...menuElements? | MenuElementInput[] |
Returns
MenuBarBuilder
build()
build(): Plugin_2;Defined in: packages/menu/src/MenuBarBuilder.ts:114
Builds and returns the configured menu bar Plugin.
Returns
Plugin_2
A ProseMirror Plugin that renders the menu bar.
createMenuItem()
static createMenuItem(spec, useSelect?): MenuItem;Defined in: packages/menu/src/MenuBarBuilder.ts:71
Creates a MenuItem from the given spec.
Convenience factory that handles two common omissions automatically:
- If only
labelis provided,titleis set to the same value. - If only
title(as a plain string) is provided,labelis set to the same value.
When useSelect is true and the spec defines a run function but no explicit select guard, a select function is derived from run so that the item is hidden whenever run would return false.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
spec | MenuItemSpec | undefined | The MenuItemSpec describing the item's appearance and behaviour. |
useSelect | boolean | false | When true, derives a select guard from run if none is specified. Defaults to false. |
Returns
A new MenuItem, or null if spec is falsy.