@sheetwrite/coreinterface
Built-in, separator, or custom callback row in the right-click menu.
Examples
};See also
Members 7
id Stable host identifier, exposed as data-context-menu-item.
id?: string;action Built-in action to bind (or "separator").
Built-in action to bind (or "separator"). Omit when supplying `onClick`.
onClick Custom click handler; receives the grid and the right-clicked cell (null if none).
label Menu row text. Defaults per action.
label?: string;shortcut A bound action name or a custom key combination.
A bound action name or a custom key combination. An explicit combination
registers `onClick` as a keyboard command; action names only reference the
existing built-in binding. Both forms display platform-aware labels.
For example, `shortcut: "copy"` follows the configured Copy binding, while
`shortcut: "Mod+Shift+K"` binds this item's `onClick` callback.
See KeyboardOptions for built-in action overrides.
visible Static or request-aware visibility.
Static or request-aware visibility. Hidden separators are normalized.
disabled Static or context-aware disabled state.
Declaration
View full TypeScript declaration
export interface ContextMenuItem { id?: string; label?: string;}Referenced by
Workspace packages depending on @sheetwrite/core
@sheetwrite/benchdependency@sheetwrite/docs-startdependency@sheetwrite/reactdependency@sheetwrite/sveltedependency@sheetwrite/vuedependency@sheetwrite/xlsxdependency
Public exports naming ContextMenuItem
ContextMenuItems@sheetwrite/core
interface ContextMenuIteminterface ContextMenuIteminterface ContextMenuItemBuilt-in, separator, or custom callback row in the right-click menu.@example import type { ContextMenuItem, GridConfig } from "@sheetwrite/core"; const total: ContextMenuItem = { id: "total", label: "Show total", onClick(grid) { window.alert(String(grid.aggregate(0, "sum"))); }, }; const config: GridConfig = { contextMenu: [total, { action: "separator" }, { action: "copy" }] };@see ContextMenuItems *@see GridConfig.contextMenuAPI reference →interface GridConfiginterface GridConfiginterface GridConfigToolbar / feature configuration. When config is set the built-in toolbar is shown; control flags default to true except the opt-in export flag.@example import type { GridConfig } from "@sheetwrite/core"; const config: GridConfig = { toolbar: true, contextMenu: [{ action: "copy" }, { action: "paste" }], keyboard(event, grid) { if (event.altKey && event.key === "b") { grid.actions.toggleBold(); return true; } return false; }, };@see Grid.setConfig *@see ContextMenuItemAPI reference →ContextMenuItem.id?: string | undefinedinterface ContextMenuItem {
id?: string | undefined;
}interface ContextMenuItem {
id?: string | undefined;
}Stable host identifier, exposed as data-context-menu-item.API reference →ContextMenuItem.label?: string | undefinedinterface ContextMenuItem {
label?: string | undefined;
}interface ContextMenuItem {
label?: string | undefined;
}Menu row text. Defaults per action.API reference →ContextMenuItem.onClick?: ((grid: Grid, cell: CellAddress | null) => void) | undefinedinterface ContextMenuItem {
onClick?:
((grid: Grid, cell: CellAddress | null) => void) | undefined;
}interface ContextMenuItem {
onClick?:
| ((
grid: Grid,
cell: CellAddress | null,
) => void)
| undefined;
}Custom click handler; receives the grid and the right-clicked cell (null if none).API reference →grid: Gridlet grid: Gridlet grid: GridThe imperative core grid this controller owns.API reference →var window: Window & typeof globalThisvar window: Window & typeof globalThisvar window: Window &
typeof globalThisThe window property of a Window object points to the window object itself. MDN Referencefunction alert(message?: any): void (+1 overload)function alert(message?: any): void (+1 overload)function alert(message?: any): void (+1 overload)window.alert() instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog. MDN Referencevar String: StringConstructor
(value?: any) => stringvar String: StringConstructor;
(value?: any) => stringvar String: StringConstructor;
(value?: any) => stringAllows manipulation and formatting of text strings and determination and location of substrings within strings.Grid.aggregate(col: number, op: AggregateOp): numberGrid.aggregate(col: number, op: AggregateOp): numberGrid.aggregate(col: number, op: AggregateOp): numberColumn aggregate over the active sheet's data.@example import type { Grid } from "@sheetwrite/core"; function total(grid: Grid) { return grid.aggregate(1, "sum"); }@see SheetwriteStore.aggregateAPI reference →const config: GridConfigconst config: GridConfigconst config: GridConfigBuilt-in UI controls; providing an object enables the toolbar unless toolbar is false.API reference →GridConfig.contextMenu?: boolean | ContextMenuItems | undefinedinterface GridConfig {
contextMenu?: boolean | ContextMenuItems | undefined;
}interface GridConfig {
contextMenu?:
| boolean
| ContextMenuItems
| undefined;
}Built-in menu, disabled menu, static rows, or a request-aware row factory.API reference →const total: ContextMenuItemconst total: ContextMenuItemconst total: ContextMenuItemAPI reference →ContextMenuItem.action?: ContextMenuActionName | undefinedinterface ContextMenuItem {
action?: ContextMenuActionName | undefined;
}interface ContextMenuItem {
action?:
| ContextMenuActionName
| undefined;
}Built-in action to bind (or "separator"). Omit when supplying onClick.API reference →type ContextMenuActionName =
| "cut"
| "copy"
| "paste"
| "clearContents"
| "merge"
| "unmerge"
| "insertRowAbove"
| "insertRowBelow"
| "deleteRow"
| "insertColumnLeft"
| "insertColumnRight"
| "deleteColumn"
| "hideRow"
| "showAllRows"
// … 8 more lines — see the API reference
}type ContextMenuActionName =
| "cut"
| "copy"
| "paste"
| "clearContents"
| "merge"
| "unmerge"
| "insertRowAbove"
| "insertRowBelow"
| "deleteRow"
| "insertColumnLeft"
| "insertColumnRight"
| "deleteColumn"
| "hideRow"
| "showAllRows"
// … 8 more lines — see the API reference
}type ContextMenuActionName =
| "cut"
| "copy"
| "paste"
| "clearContents"
| "merge"
| "unmerge"
| "insertRowAbove"
| "insertRowBelow"
| "deleteRow"
| "insertColumnLeft"
| "insertColumnRight"
| "deleteColumn"
| "hideRow"
| "showAllRows"
| "autoFitRow"
| "hideColumn"
| "showAllColumns"
| "autoFitColumn"
// … 4 more lines — see the API reference
}Built-in action names accepted by custom context-menu rows.API reference →interface Grid {
readonly store: Store;
readonly actions: GridActions;
getRuntimeResourceSnapshot(
operation: RuntimeResourceOperation,
phase: RuntimeResourcePhase,
runtime?: RuntimeMemoryObservation,
): RuntimeResourceSnapshot;
getCommandState(command: GridCommandName): GridCommandState;
setActiveSheet(id: SheetId): void;
scrollToCell(addr: CellAddress): void;
getCellAtPoint(
clientX: number,
clientY: number,
): CellAddress | null;
// … 122 more lines — see the API reference
}interface Grid {
readonly store: Store;
readonly actions: GridActions;
getRuntimeResourceSnapshot(
operation: RuntimeResourceOperation,
phase: RuntimeResourcePhase,
runtime?: RuntimeMemoryObservation,
): RuntimeResourceSnapshot;
getCommandState(command: GridCommandName): GridCommandState;
setActiveSheet(id: SheetId): void;
scrollToCell(addr: CellAddress): void;
getCellAtPoint(
clientX: number,
clientY: number,
): CellAddress | null;
// … 122 more lines — see the API reference
}interface Grid {
readonly store: Store;
readonly actions: GridActions;
getRuntimeResourceSnapshot(
operation: RuntimeResourceOperation,
phase: RuntimeResourcePhase,
runtime?: RuntimeMemoryObservation,
): RuntimeResourceSnapshot;
getCommandState(
command: GridCommandName,
): GridCommandState;
setActiveSheet(
id: SheetId,
): void;
scrollToCell(
addr: CellAddress,
): void;
getCellAtPoint(
clientX: number,
// … 259 more lines — see the API reference
}Imperative grid handle for document commands, events, rendering, and teardown. @example import type { Grid } from "@sheetwrite/core"; function updateTotal(grid: Grid) { const sheet = grid.getActiveSheet(); const result = grid.applyTransaction({ patches: [{ op: "set", addr: { sheet, row: 0, col: 0 }, value: { kind: "literal", value: 42 } }], }); if (result.status === "applied") grid.scrollToCell({ sheet, row: 0, col: 0 }); return grid.aggregate(0, "sum"); } @see createGrid @see Grid.applyTransactionAPI reference →interface CellAddress {
sheet: SheetId;
row: number;
col: number;
}interface CellAddress {
sheet: SheetId;
row: number;
col: number;
}interface CellAddress {
sheet: SheetId;
row: number;
col: number;
}Zero-based address of one cell on a stable sheet ID.API reference →type KeyboardAction =
| "copy"
| "cut"
| "paste"
| "pasteValues"
| "undo"
| "redo"
| "find"
| "replace"
| "clearContents";type KeyboardAction =
| "copy"
| "cut"
| "paste"
| "pasteValues"
| "undo"
| "redo"
| "find"
| "replace"
| "clearContents";type KeyboardAction =
| "copy"
| "cut"
| "paste"
| "pasteValues"
| "undo"
| "redo"
| "find"
| "replace"
| "clearContents";Built-in actions that can be rebound without replacing navigation.API reference →type KeyShortcut =
| `${"Mod" | "Ctrl" | "Meta" | "Alt" | "Shift"}+${string}`
| {
key: string;
mod?: boolean;
ctrl?: boolean;
meta?: boolean;
shift?: boolean;
alt?: boolean;
};type KeyShortcut =
| `${"Mod" | "Ctrl" | "Meta" | "Alt" | "Shift"}+${string}`
| {
key: string;
mod?: boolean;
ctrl?: boolean;
meta?: boolean;
shift?: boolean;
alt?: boolean;
};type KeyShortcut =
| `${"Mod" | "Ctrl" | "Meta" | "Alt" | "Shift"}+${string}`
| {
key: string;
mod?: boolean;
ctrl?: boolean;
meta?: boolean;
shift?: boolean;
alt?: boolean;
};A compact modified key combination or a key object. Modifiers may appear in any order before the final key, for example "Mod+Shift+K" or "Ctrl+Alt+Delete". Mod/mod means Command on macOS and Control elsewhere; Ctrl and Meta are literal. The parser rejects unknown/repeated modifiers and missing keys.API reference →interface ContextMenuContext {
readonly cell: CellAddress | null;
readonly clientX: number;
readonly clientY: number;
}interface ContextMenuContext {
readonly cell: CellAddress | null;
readonly clientX: number;
readonly clientY: number;
}interface ContextMenuContext {
readonly cell: CellAddress | null;
readonly clientX: number;
readonly clientY: number;
}Cell and viewport coordinates resolved for one bundled context-menu opening.API reference →