@odoo/o-spreadsheet
Version:
A spreadsheet component
105 lines (104 loc) • 3.96 kB
TypeScript
import { Color } from "../types";
import { SpreadsheetChildEnv } from "../types/spreadsheet_env";
export type MenuItemOrSeparator = Action | "separator";
export interface ActionSpec {
/**
* String or a function to compute the name
*/
name: string | ((env: SpreadsheetChildEnv) => string);
description?: string | ((env: SpreadsheetChildEnv) => string);
shortcut?: string;
/**
* which represents its position inside the
* menus (the lower sequence it has, the upper it is in the menu)
*/
sequence?: number;
/**
* used for example to add child
*/
id?: string;
/**
* Can be defined to compute the visibility of the item
*/
isVisible?: (env: SpreadsheetChildEnv) => boolean;
/**
* Can be defined to compute if the user can click on the action
*/
isEnabled?: (env: SpreadsheetChildEnv) => boolean;
/**
* Can be defined to compute if the action is active
*/
isActive?: (env: SpreadsheetChildEnv) => boolean;
/**
* Can be defined to display an icon
*/
icon?: string | ((env: SpreadsheetChildEnv) => string);
iconColor?: Color;
/**
* Can be defined to display another icon on the right of the item.
*/
secondaryIcon?: string | ((env: SpreadsheetChildEnv) => string);
/**
* is the action allowed when running spreadsheet in readonly mode
*/
isReadonlyAllowed?: boolean;
/**
* is the action allowed when the active sheet is locked
*/
isEnabledOnLockedSheet?: boolean;
/**
*
* Execute the action. The action can return a result.
* The result will be carried by a `menu-clicked` event to the menu parent component.
*/
execute?: (env: SpreadsheetChildEnv, isMiddleClick?: boolean) => unknown;
/**
* subitems associated to this item
* NB: an action without an execute function or children is not displayed !
*/
children?: ActionChildren;
/**
* whether it should add a separator below the item in menus
* NB: a separator defined on the last item is not displayed !
*/
separator?: boolean;
textColor?: Color;
onStartHover?: (env: SpreadsheetChildEnv) => void;
onStopHover?: (env: SpreadsheetChildEnv) => void;
}
export interface Action {
name: (env: SpreadsheetChildEnv) => string;
description: (env: SpreadsheetChildEnv) => string;
shortcut: string;
sequence: number;
id: string;
isVisible: (env: SpreadsheetChildEnv) => boolean;
isEnabled: (env: SpreadsheetChildEnv) => boolean;
isActive?: (env: SpreadsheetChildEnv) => boolean;
icon: (env: SpreadsheetChildEnv) => string;
iconColor?: Color;
secondaryIcon: (env: SpreadsheetChildEnv) => string;
isReadonlyAllowed: boolean;
isEnabledOnLockedSheet: boolean;
execute?: (env: SpreadsheetChildEnv, isMiddleClick?: boolean) => unknown;
children: (env: SpreadsheetChildEnv) => Action[];
separator: boolean;
textColor?: Color;
onStartHover?: (env: SpreadsheetChildEnv) => void;
onStopHover?: (env: SpreadsheetChildEnv) => void;
}
export interface ComputedAction extends Omit<Action, "name" | "description" | "icon" | "secondaryIcon" | "children"> {
name: string;
description: string;
icon: string;
secondaryIcon: string;
}
export type ActionBuilder = (env: SpreadsheetChildEnv) => ActionSpec[];
type ActionChildren = (ActionSpec | ActionBuilder)[];
export declare function createActions(menuItems: ActionSpec[]): Action[];
export declare function createAction(item: ActionSpec): Action;
export declare function getMenuItemsAndSeparators(env: SpreadsheetChildEnv, actions: Action[]): MenuItemOrSeparator[];
export declare function isRootMenu(menu: Action): boolean;
export declare function hasVisibleChildren(env: SpreadsheetChildEnv, menu: Action): boolean;
export declare function isMenuItemEnabled(env: SpreadsheetChildEnv, menu: Action): boolean;
export {};