UNPKG

@selenite/commons

Version:

This typescript package provides a set of frequently used utilities, types and svelte actions for building projects with Typescript and Svelte.

64 lines (63 loc) 1.97 kB
import type { Position } from '../../utils'; import type { MenuItem } from './types'; /** * This class is a singleton that represents the state of the context menu. * * It autohides based on the hovered state and filters items based on a query. */ export declare class ContextMenuState { #private; triggerFirstItem(): void; triggerItem(i: number): void; /** Returns the singleton instance. */ static get instance(): ContextMenuState; target: HTMLElement | undefined; /** Position of the menu, in client coordinates. */ pos: Position; minHeight: number | undefined; minWidth: number | undefined; get visible(): boolean; set visible(v: boolean); /** Delay before hiding menu in miliseconds. */ hidingDelay: number; /** Visibility of the searchbar. */ searchbar: boolean; onHide: (() => void) | undefined; /** Items of the menu. */ items: MenuItem[]; /** Is menu fully expanded */ expanded: boolean; get query(): string; set query(q: string); sort: boolean; /** Filtered items. */ filteredItems: MenuItem[]; get focused(): boolean; set focused(f: boolean); get autohide(): boolean; set autohide(v: boolean); private updateAutohide; /** Sets hovered state and manages autohide. */ set hovered(v: boolean); /** Returns hovered state. */ get hovered(): boolean; private constructor(); } export declare const contextMenu: ContextMenuState; export type ShowContextMenu = (params: { expand?: boolean; pos: Position; /** Whether to sort the items. Default to false. */ sort?: boolean; items: Partial<MenuItem>[]; searchbar?: boolean; onHide?: () => void; autoHide?: boolean; target?: HTMLElement; }) => void; /** * Shows the context menu with the given items at the given position. * * Helper function to use the context menu singleton. */ export declare const showContextMenu: ShowContextMenu;