UNPKG

@launchmenu/core

Version:

An environment for visual keyboard controlled applets

110 lines 4.1 kB
/// <reference types="node" /> import { IDataHook } from "model-react"; import { IIOContext } from "../../context/_types/IIOContext"; import { SortedList } from "../../utils/SortedList"; import { IUUID } from "../../_types/IUUID"; import { TRequired } from "../../_types/TRequired"; import { IMenuItem } from "../items/_types/IMenuItem"; import { AbstractMenu } from "./AbstractMenu"; import { MenuItemCategorizer } from "./MenuItemCategorizer"; import { IMenuCategoryData } from "./_types/IMenuCategoryData"; import { IPrioritizedMenuConfig } from "./_types/IPrioritizedMenuConfig"; import { IPrioritizedMenuItem } from "./_types/IPrioritizedMenuItem"; declare type IBatchData = { add: Set<IPrioritizedMenuItem>; addIDs: Map<IUUID, IPrioritizedMenuItem>; remove: Set<IPrioritizedMenuItem>; removeIDs: Map<IUUID, IPrioritizedMenuItem>; }; /** * A prioritized menu */ export declare class PrioritizedMenu extends AbstractMenu { protected config: TRequired<IPrioritizedMenuConfig>; protected items: SortedList<IPrioritizedMenuItem>; protected categorizer: MenuItemCategorizer<IPrioritizedMenuItem>; protected batchTimeout: NodeJS.Timeout | null; protected batch: IBatchData; protected maxCountHookDestroyer?: () => void; protected menuChangeEvents: { added: IMenuItem[]; removed: IMenuItem[]; }; /** * Creates a new menu * @param context The context to be used by menu items * @param config The configuration for category options */ constructor(context: IIOContext, config?: IPrioritizedMenuConfig); /** * Creates a new menu * @param context The context to be used by menu items * @param items The initial items to store * @param config The configuration for category options */ constructor(context: IIOContext, items: IPrioritizedMenuItem[], config?: IPrioritizedMenuConfig); /** * Destroys the menu */ destroy(): boolean; /** * Adds the given items to the menu * @param items The items to be added */ addItems(items: IPrioritizedMenuItem[]): void; /** * Adds an item to the menu * @param item The item to be added */ addItem(item: IPrioritizedMenuItem): void; /** * Removes the given items from the menu if present * @param items The items to be removed */ removeItems(items: IPrioritizedMenuItem[]): void; /** * Removes the given item from the menu if present * @param item The item to remove * @param oldCategory The category that item was in (null to use the items' latest category) */ removeItem(item: IPrioritizedMenuItem): void; /** * Schedules an items data update */ protected scheduleUpdate(): void; /** * Flushes the batch to make sure that any items that are queued to be added or removed are added/removed. * * Note that this also automatically happens with some delay after calling add or remove item. */ flushBatch(): void; /** * Checks whether the selected items are still present, and deselects them if not */ protected deselectRemovedItems(): void; /** * Selects or deselects the given item * @param item The item to select or deselect * @param selected Whether to select or deselect */ setSelected(item: IMenuItem, selected?: boolean): void; /** * Selects an item to be the cursor * @param item The new cursor */ setCursor(item: IMenuItem | null): void; /** * Retrieves the items of the menu * @param hook The hook to subscribe to changes * @returns The menu items */ getItems(hook?: IDataHook): IMenuItem[]; /** * Retrieves the item categories of the menu * @param hook The hook to subscribe to changes * @returns The categories and their items */ getCategories(hook?: IDataHook): IMenuCategoryData[]; } export {}; //# sourceMappingURL=PrioritizedMenu.d.ts.map