/** * @file * * Mock of Obsidian's `MenuItem`, one entry of a context menu. */ import type { IconName as IconNameOriginal, MenuItem as MenuItemOriginal } from 'obsidian'; import { Menu } from './Menu.cjs'; /** * Mock of Obsidian's `MenuItem`. * * Every setter records its argument on a public field, so a test can read an item's title, icon, section and * state, and invoke {@link MenuItem.onClick__} to simulate a click. */ export declare class MenuItem { /** * The item's checked state: `true` or `false` for a checkbox item, `null` when it has no check mark. */ checked: boolean | null; /** * Whether the item is disabled. */ disabled: boolean; /** * Mock-only: the icon id set by {@link MenuItem.setIcon}, or `null` for none. */ icon__: IconNameOriginal | null; /** * Mock-only: whether {@link MenuItem.setIsLabel} marked the item as a non-clickable label. */ isLabel__: boolean; /** * The menu the item belongs to. */ menu: Menu; /** * Mock-only: the click handler set by {@link MenuItem.onClick}, or `null` when none was set. */ onClick__: (($event: KeyboardEvent | MouseEvent) => unknown) | null; /** * The id of the menu section the item belongs to; empty when none was set. */ section: string; /** * The item's submenu, created by {@link MenuItem.setSubmenu}, or `null` when it has none. */ submenu: Menu | null; /** * Mock-only: the title set by {@link MenuItem.setTitle}. */ title__: DocumentFragment | string; /** * Mock-only: whether {@link MenuItem.setWarning} put the item in the warning (red) style. */ warning__: boolean; private constructor(); /** * Mock-only factory: creates a menu item, spyable via `vi.spyOn(MenuItem, 'create__')`. Obsidian's constructor * is private; items come from `Menu.addItem`. * * @param menu - The menu the item belongs to, kept in {@link MenuItem.menu}. * @returns The new menu item. */ static create__(menu: Menu): MenuItem; /** * Mock-only: views a value typed as Obsidian's `MenuItem` as this mock. * * @param value - The value typed as the original `MenuItem`. * @returns The same object, typed as the mock. */ static fromOriginalType__(value: MenuItemOriginal): MenuItem; /** * Mock-only: views this mock as Obsidian's `MenuItem` type. * * @returns The same object, typed as the original `MenuItem`. */ asOriginalType__(): MenuItemOriginal; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(MenuItem.prototype, 'constructor__')`. * * @param _menu - The menu the item belongs to. */ constructor__(_menu: Menu): void; /** * Sets the handler run when the item is clicked or chosen with the keyboard. The mock stores it in * {@link MenuItem.onClick__} and never calls it. * * @param callback - The click handler. * @returns This item, for chaining. */ onClick(callback: ($event: KeyboardEvent | MouseEvent) => unknown): this; /** * Sets whether the item shows a check mark. * * @param checked - `true` or `false` for a checkbox item, `null` to show no check mark. * @returns This item, for chaining. */ setChecked(checked: boolean | null): this; /** * Enables or disables the item. * * @param disabled - Whether the item is disabled. * @returns This item, for chaining. */ setDisabled(disabled: boolean): this; /** * Sets the item's icon. * * @param icon - The id of an icon added with `addIcon` or from the built-in Lucide set, or `null` for none. * @returns This item, for chaining. */ setIcon(icon: IconNameOriginal | null): this; /** * Sets whether the item is a label rather than a clickable entry. * * @param isLabel - Whether the item is a label. * @returns This item, for chaining. */ setIsLabel(isLabel: boolean): this; /** * Sets the menu section the item belongs in. Existing section ids can be found in the `data-section` attribute * of a real menu's elements. * * @param section - The section id. * @returns This item, for chaining. */ setSection(section: string): this; /** * Turns the item into a submenu entry. * * @returns The item's submenu, created on the first call and reused afterwards. */ setSubmenu(): Menu; /** * Sets the item's title. * * @param title - The title, as text or as a fragment. * @returns This item, for chaining. */ setTitle(title: DocumentFragment | string): this; /** * Sets whether the item is shown in the warning style, which colors its title and icon red. * * @param isWarning - Whether the warning style is on. * @returns This item, for chaining. */ setWarning(isWarning: boolean): this; }