import {caretRectFrom, getCaretCoordinates} from '../../utilities/caret-position'; import {filterSlashItems} from './slash-menu-items'; import {SLASH_ITEM_SELECT} from './slash-menu.component'; import type {CaretCoordinates, TextField} from '../../utilities/caret-position'; import type {ReactiveController, ReactiveControllerHost} from 'lit'; import type {SlashMenuItem} from './slash-menu-items'; import type {VirtualElement} from '../popup'; import type ZnSlashMenu from './slash-menu.component'; export interface SlashMenuControllerOptions { /** * Resolves the menu to render results into. Called the first time the menu is needed, so the host * can render it lazily; may return a promise (e.g. after awaiting `updateComplete`). */ menu: () => ZnSlashMenu | null | Promise; /** The available items, unfiltered. Receives the current query so lists can be resolved remotely. */ items: (query: string) => SlashMenuItem[] | Promise; /** The characters that open the menu. Defaults to `/`. */ trigger?: () => string; /** Called before an item is inserted. Return `false` to handle the item yourself. */ onSelect?: (item: SlashMenuItem, query: string) => boolean; /** Called after an item's value has been written into the field. */ onInsert?: (item: SlashMenuItem, value: string) => void; } /** Queries longer than this are treated as prose the user never meant as a menu search. */ const MAX_QUERY_LENGTH = 40; /** * Drives a slash menu for a plain `