40 lines
1 KiB
TypeScript
40 lines
1 KiB
TypeScript
export interface ContextMenuType {
|
|
visible: boolean;
|
|
position: {
|
|
top: number;
|
|
left: number;
|
|
};
|
|
menu: ContextMenu
|
|
}
|
|
|
|
export interface ContextMenu {
|
|
entries: ContextMenuEntry[];
|
|
}
|
|
|
|
interface ContextMenuEntryWithAction {
|
|
menuText: string;
|
|
actionTrigger: string;
|
|
}
|
|
|
|
interface ContextMenuEntryWithChildren {
|
|
expanded: boolean;
|
|
menuText: string;
|
|
children: ContextMenuEntry[];
|
|
}
|
|
|
|
type ContextMenuEntry = ContextMenuEntryWithAction | ContextMenuEntryWithChildren;
|
|
|
|
export type ExtractActionTriggers<T> =
|
|
T extends { actionTrigger: infer U } ? U :
|
|
T extends { children: infer C } ? ExtractActionTriggers<C> :
|
|
T extends (infer R)[] ? ExtractActionTriggers<R> :
|
|
never;
|
|
|
|
export function menuEntryWithAction(entry: ContextMenuEntry): entry is ContextMenuEntryWithAction {
|
|
return 'actionTrigger' in entry;
|
|
}
|
|
|
|
export function menuEntryWithChildren(entry: ContextMenuEntry): entry is ContextMenuEntryWithChildren {
|
|
return 'children' in entry;
|
|
}
|
|
|