import * as React from "react"; import { Action } from "../model/Actions"; import { BorderNode } from "../model/BorderNode"; import { TabGroupNode } from "../model/TabGroupNode"; import { Node } from "../model/Node"; import { TabNode } from "../model/TabNode"; import { TabSetNode } from "../model/TabSetNode"; import { IPopupMenuItem, PopupMenuEntry } from "./PopupMenu"; /** Standard context menu actions, each mapped to a prebuilt menu item. */ export type NodeContextAction = "pin" | "float" | "popout" | "rename" | "maximize" | "closeAll" | "closeRight" | "closeOthers" | "close" | "borderType" | "addToNewGroup" | "addToGroup" | "removeFromGroup" | "ungroup" | "toggleOpen"; /** The canonical list of all {@link NodeContextAction}s, in a sensible menu order. */ export declare const NODE_CONTEXT_ACTIONS: readonly NodeContextAction[]; /** * The bulk close actions: `closeAll` closes every closeable tab in the tab, `closeRight` the * closeable tabs to its right (tabset tabs only), and `closeOthers` every closeable tab but * itself. They are not part of the standard menu (see {@link ContextMenuBuilder.addStandard}), * which keeps a single `close` item; add them explicitly to build a menu with them. They are only * enabled when the tab has siblings (there is nothing else to close in a single-tab tabset). */ export declare const BULK_CLOSE_ACTIONS: readonly NodeContextAction[]; /** * Options for {@link getNodeContextMenuItems}. * @category Components * @group Context Menu */ export interface INodeContextMenuOptions { /** dispatch actions through this instead of the node's model; useful to intercept/undo actions */ onAction?: (action: Action) => void; /** close the open context menu (used by the group picker / pill rename / color controls) */ closeMenu?: () => void; /** resolve a default CSS class name through the layout's classNameMapper */ getClassName?: (defaultClassName: string) => string; /** include actions that are not allowed on the node as disabled items (default false). * Set true to show the full set with not-allowed actions greyed out instead of omitted. */ includeDisabled?: boolean; /** the actions to build, in the order to show them (defaults to all actions for the node * type). Actions that do not apply to the node type are skipped. */ actions?: NodeContextAction[]; /** override the default label of an item (takes precedence over the i18n labels) */ getLabel?: (action: NodeContextAction, node: TabNode | TabSetNode | BorderNode | TabGroupNode) => string; /** provide an icon for an item */ getIcon?: (action: NodeContextAction, node: TabNode | TabSetNode | BorderNode | TabGroupNode) => React.ReactNode; } /** Returns the standard menu actions currently allowed on the node (the `addStandard` set; the * bulk close actions are opt-in and built explicitly via {@link getNodeContextMenuItem} or the * {@link ContextMenuBuilder}). */ export declare function getNodeContextActions(node: Node): NodeContextAction[]; /** Builds a single menu item for one action, or undefined if not applicable. */ export declare function getNodeContextMenuItem(node: TabNode | TabSetNode | BorderNode | TabGroupNode, action: NodeContextAction, options?: INodeContextMenuOptions): IPopupMenuItem | undefined; /** * A fluent builder for prebuilt node context menu entries: choose which actions to show (in your * own order), interleave your own items, and place dividers between groups, then call * {@link ContextMenuBuilder.build} to get the {@link PopupMenuEntry}s for {@link showPopupMenu}. * * @example * const items = new ContextMenuBuilder(node) * .add("pin") * .add("float") * .add("popout") * .add("rename") * .addDivider() * .add("closeAll") * .add("closeRight") * .add("closeOthers") * .addDivider() * .add("close") * .build(); * @category Components * @group Context Menu */ export declare class ContextMenuBuilder { private readonly node; private readonly options; private readonly entries; private dividerId; constructor(node: TabNode | TabSetNode | BorderNode | TabGroupNode, options?: INodeContextMenuOptions); /** add the prebuilt item for the given action (omitted, or included disabled, per `includeDisabled`) */ add(action: NodeContextAction): this; /** add all the standard actions for this node type, in their default order and without dividers. * For {@link TabGroupNode} this includes the custom rename/color controls (with a divider) * before the `toggleOpen`/`ungroup` actions, matching {@link getTabGroupMenuItems}. * `actions`/`includeDisabled`/`getLabel`/`getIcon` in the options apply only to the * `toggleOpen`/`ungroup` actions; the custom controls have no disabled/label/icon state. */ addStandard(): this; /** add a divider between groups. Unnamed dividers get a unique key (e.g. "divider-1") so * several can be added to one menu without React key collisions. */ addDivider(key?: string): this; /** interleave your own item into the menu */ addCustom(entry: IPopupMenuItem): this; /** * Returns entries with consecutive dividers collapsed to one and any divider that ends up * leading or trailing removed (a divider is only kept when it separates two other entries). */ build(): PopupMenuEntry[]; } /** Builds menu entries for the standard node actions. Use includeDisabled to show not-allowed actions as greyed-out items. * For {@link TabGroupNode} this delegates to {@link getTabGroupMenuItems} so the menu includes * the custom rename/color controls. `actions` filters only `toggleOpen`/`ungroup`; the customs * are always present via the default path. `getLabel`/`getIcon`/`includeDisabled` apply only to * the `toggleOpen`/`ungroup` actions. */ export declare function getNodeContextMenuItems(node: TabNode | TabSetNode | BorderNode | TabGroupNode, options?: INodeContextMenuOptions): PopupMenuEntry[]; /** * Builds the context menu entries for a group pill: an inline rename control, a single-line color * chooser, then the standard group actions (collapse/expand and ungroup). Pass a `closeMenu` * callback in the options so the rename/color controls can dismiss the menu after committing. * This is the default menu for {@link TabGroupNode} — {@link ContextMenuBuilder.addStandard} and * {@link getNodeContextMenuItems} delegate here. `actions`/`getLabel`/`getIcon`/`includeDisabled` * apply only to `toggleOpen`/`ungroup`; the custom controls are always included via the default path. */ export declare function getTabGroupMenuItems(group: TabGroupNode, options?: INodeContextMenuOptions): PopupMenuEntry[]; /** * Shows the group pill context menu (rename, color, collapse/expand, ungroup) using the reusable * {@link showPopupMenu}. Returns an idempotent hide handle. Pass `onAction` in the options to * intercept/undo the dispatched actions, and `closeMenu` is wired automatically. * This is a thin wrapper around {@link getTabGroupMenuItems}; the same menu is available via * `new ContextMenuBuilder(group).addStandard().build()` / {@link getNodeContextMenuItems}. */ export declare function showGroupMenu(group: TabGroupNode, anchor: { x: number; y: number; } | DOMRect | HTMLElement, options?: INodeContextMenuOptions): () => void;