@usememos/editor 26.10.1 → 26.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,18 @@
1
1
  import { type TextRange } from '../decorations.js';
2
2
  import type { Extension } from '../extension.js';
3
- import type { SuggestionConfig, SuggestionItem } from './suggestion.js';
4
3
  /** Finds tags or mentions in `text[from, to)`. `text` is the whole container, so a scanner can look before `from`. */
5
4
  export type TagScanner = (text: string, from: number, to: number) => Iterable<TextRange>;
6
- export interface TagsOptions<T extends SuggestionItem = SuggestionItem> {
7
- /** Class on each match. Default `mbe-tag` for tags and `mbe-mention` for mentions. */
8
- readonly class?: string;
9
- readonly attributes?: Readonly<Record<string, string>>;
5
+ export interface TagsOptions {
6
+ /**
7
+ * Class on each match. Default `mbe-tag` for tags and `mbe-mention` for
8
+ * mentions. A function gets the match as written (`#work/planning`), for a
9
+ * class per tag or per person.
10
+ */
11
+ readonly class?: string | ((match: string) => string);
12
+ /** Attributes on each match, or a function of the match, such as `data-tag` or a custom color. */
13
+ readonly attributes?: Readonly<Record<string, string>> | ((match: string) => Readonly<Record<string, string>> | undefined);
10
14
  /** Finds matches in a run of text. Default `scanTags` or `scanMentions`. */
11
15
  readonly scan?: TagScanner;
12
- /** A suggestion menu opened by the trigger character. See `suggestion()`. */
13
- readonly suggestion?: Omit<SuggestionConfig<T>, 'char'>;
14
16
  }
15
17
  /**
16
18
  * The default tag grammar. A tag is `#` and one or more segments separated
@@ -28,7 +30,7 @@ export declare function scanTags(text: string, from?: number, to?: number): Gene
28
30
  * `_`, `.`, `+`, `-` or `@`, so the middle of an e-mail address is no mention.
29
31
  */
30
32
  export declare function scanMentions(text: string, from?: number, to?: number): Generator<TextRange>;
31
- /** `#tag` highlighting, `\#` escapes and an optional `#` suggestion menu. */
32
- export declare function tags<T extends SuggestionItem>(options?: TagsOptions<T>): Extension;
33
- /** `@name` highlighting, `\@` escapes and an optional `@` suggestion menu. */
34
- export declare function mentions<T extends SuggestionItem>(options?: TagsOptions<T>): Extension;
33
+ /** `#tag` highlighting and `\#` escapes. */
34
+ export declare function tags(options?: TagsOptions): Extension;
35
+ /** `@name` highlighting and `\@` escapes. */
36
+ export declare function mentions(options?: TagsOptions): Extension;
@@ -0,0 +1,123 @@
1
+ /*! Icons from Lucide (lucide-static 1.55.0), https://lucide.dev
2
+ * ISC License. Copyright (c) 2026 Lucide Icons and Contributors.
3
+ * Permission to use, copy, modify, and/or distribute this software for any
4
+ * purpose with or without fee is hereby granted, provided that the above
5
+ * copyright notice and this permission notice appear in all copies.
6
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
7
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
8
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
9
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
10
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
11
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
12
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
13
+ */
14
+ /** An icon: a string is shown as text, an element (such as an `<svg>`) is cloned for every place it appears. */
15
+ export type Icon = string | Element;
16
+ /** One SVG child: a path's `d`, or a tag and its attributes. */
17
+ type IconChild = string | readonly [tag: string, attrs: Readonly<Record<string, string>>];
18
+ /** The built-in icons, by the `labels` key of the control that shows them. The comment names the Lucide icon. */
19
+ declare const ICONS: {
20
+ /** `type` */
21
+ text: string[];
22
+ /** `heading-1` */
23
+ heading1: string[];
24
+ /** `heading-2` */
25
+ heading2: string[];
26
+ /** `heading-3` */
27
+ heading3: string[];
28
+ /** `list` */
29
+ bulletList: string[];
30
+ /** `list-ordered` */
31
+ numberedList: string[];
32
+ /** `list-todo` */
33
+ todoList: (string | [string, {
34
+ x: string;
35
+ y: string;
36
+ width: string;
37
+ height: string;
38
+ rx: string;
39
+ }])[];
40
+ /** `text-quote` */
41
+ quote: string[];
42
+ /** `square-code` */
43
+ code: (string | [string, {
44
+ x: string;
45
+ y: string;
46
+ width: string;
47
+ height: string;
48
+ rx: string;
49
+ }])[];
50
+ /** `table` */
51
+ table: (string | [string, {
52
+ width: string;
53
+ height: string;
54
+ x: string;
55
+ y: string;
56
+ rx: string;
57
+ }])[];
58
+ /** `minus` */
59
+ divider: string[];
60
+ /** `copy` */
61
+ duplicate: (string | [string, {
62
+ width: string;
63
+ height: string;
64
+ x: string;
65
+ y: string;
66
+ rx: string;
67
+ ry: string;
68
+ }])[];
69
+ /** `trash` */
70
+ delete: readonly IconChild[];
71
+ /** `arrow-up` */
72
+ addRowAbove: string[];
73
+ /** `arrow-down` */
74
+ addRowBelow: string[];
75
+ /** `arrow-left` */
76
+ addColumnLeft: string[];
77
+ /** `arrow-right` */
78
+ addColumnRight: string[];
79
+ /** `text-align-start` */
80
+ alignLeft: string[];
81
+ /** `text-align-center` */
82
+ alignCenter: string[];
83
+ /** `text-align-end` */
84
+ alignRight: string[];
85
+ /** `trash` */
86
+ deleteRow: readonly IconChild[];
87
+ /** `trash` */
88
+ deleteColumn: readonly IconChild[];
89
+ /** `bold` */
90
+ bold: string[];
91
+ /** `italic` */
92
+ italic: [string, {
93
+ x1: string;
94
+ x2: string;
95
+ y1: string;
96
+ y2: string;
97
+ }][];
98
+ /** `strikethrough` */
99
+ strike: (string | [string, {
100
+ x1: string;
101
+ x2: string;
102
+ y1: string;
103
+ y2: string;
104
+ }])[];
105
+ /** `code` */
106
+ inlineCode: string[];
107
+ /** `link` */
108
+ link: string[];
109
+ /** `grip-vertical` */
110
+ blockHandle: [string, {
111
+ cx: string;
112
+ cy: string;
113
+ r: string;
114
+ }][];
115
+ };
116
+ /** Names of the built-in icons. Each is the `labels` key of the control that shows it. */
117
+ export type IconName = keyof typeof ICONS;
118
+ export type Icons = Partial<Record<IconName, Icon>>;
119
+ /** Builds the built-in icon `name` as a new `<svg class="mbe-icon">`. */
120
+ export declare function builtinIcon(doc: Document, name: IconName): SVGSVGElement;
121
+ /** The content of an icon slot: text, a clone of an element, or nothing. */
122
+ export declare function iconNode(doc: Document, icon: Icon | undefined): Node | null;
123
+ export {};
@@ -1,5 +1,6 @@
1
- export { Editor, type ActiveName, type EditorCommands, type EditorEvents, type EditorOptions, type InsertMarkdownOptions, type InsertTarget, type PositionJSON, type RuntimeOptions, type SelectionJSON, SLASH_ITEM_IDS, type SlashItemId, } from './editor.js';
1
+ export { Editor, type ActiveName, type EditorCommands, type EditorEvents, type EditorOptions, type InsertMarkdownOptions, type InsertTarget, type PositionJSON, type RuntimeOptions, type SelectionJSON, type SuggestionApi, SLASH_ITEM_IDS, type SlashItemId, } from './editor.js';
2
2
  export { DEFAULT_LABELS, type Labels } from './labels.js';
3
+ export type { Icon, IconName, Icons } from './icons.js';
3
4
  export * from './model.js';
4
5
  export * as commands from './commands.js';
5
6
  export { parseMarkdown } from './markdown/parse.js';
@@ -9,15 +10,18 @@ export { loadMarkdown, type MarkdownSource } from './markdown/source.js';
9
10
  export type { MarkdownOptions } from './markdown/options.js';
10
11
  export { docToHtml } from './clipboard/toHtml.js';
11
12
  export { htmlToDoc } from './clipboard/fromHtml.js';
12
- export type { Extension, ExtensionContext, KeyHandler, SyntaxView } from './extension.js';
13
+ export type { CodeDecorationContext, Extension, ExtensionContext, KeyHandler, SyntaxView } from './extension.js';
13
14
  export type { ColorScheme, Theme, ThemeClasses, ThemeColors, ThemeTokens } from './theme.js';
14
15
  export { defaultKeymap } from './extensions/keymap.js';
15
16
  export { math, type MathOptions } from './extensions/math.js';
16
- export { footnotes } from './extensions/footnotes.js';
17
+ export { footnotes, type FootnotesOptions } from './extensions/footnotes.js';
17
18
  export type { BlockSyntax, BlockSyntaxMatcher, InlineSyntax, MarkdownSyntax } from './markdown/options.js';
18
19
  export { textDecorator, type TextDecoratorOptions } from './extensions/textDecorator.js';
19
20
  export { mentions, scanMentions, scanTags, tags, type TagScanner, type TagsOptions } from './extensions/tags.js';
20
21
  export type { Decoration, DecorationContext, Decorator, TextRange } from './decorations.js';
21
- export { suggestion, type SuggestionConfig, type SuggestionItem, type SuggestionRange } from './extensions/suggestion.js';
22
+ export { suggestion, type SuggestionAllowContext, type SuggestionCommandContext, type SuggestionConfig, type SuggestionItem, type SuggestionItemsContext, type SuggestionMatch, type SuggestionMatchContext, type SuggestionMatcher, type SuggestionRange, } from './extensions/suggestion.js';
23
+ export { matchToken, type MatchTokenOptions } from './suggest/match.js';
24
+ export type { SuggestionState } from './suggest/controller.js';
22
25
  export type { Widget, WidgetRender } from './widgets.js';
23
26
  export { fileHandler, type FileHandlerOptions } from './extensions/fileHandler.js';
27
+ export { defaultResolveUrl, type ResolveUrl, type UrlKind } from './view/dom.js';
@@ -6,11 +6,19 @@ export declare const DEFAULT_LABELS: {
6
6
  bulletList: string;
7
7
  numberedList: string;
8
8
  todoList: string;
9
+ /** Accessible name of a task checkbox whose item has no text. */
10
+ task: string;
9
11
  quote: string;
10
12
  code: string;
11
13
  table: string;
12
14
  divider: string;
13
15
  noResults: string;
16
+ /** Accessible name of an autocomplete popup without its own `label`. */
17
+ suggestions: string;
18
+ /** Accessible name of the slash menu. */
19
+ commands: string;
20
+ /** Shown in an autocomplete popup while its items are loading. */
21
+ loading: string;
14
22
  duplicate: string;
15
23
  delete: string;
16
24
  bold: string;
@@ -20,5 +20,9 @@ export declare function serializeInline(inline: Inline, options?: MarkdownOption
20
20
  * - Whitespace at the edges of a bold, italic or strike run moves outside it,
21
21
  * because `**foo **` is not valid emphasis.
22
22
  * - A "\n" in a code span is a hard break outside the code span.
23
+ * - Spaces and tabs that end a line of text are dropped, because Markdown
24
+ * strips them. Writing them as character references instead would leave
25
+ * "&#32;" behind wherever someone typed a space last. A line of only
26
+ * whitespace keeps it, so the line is not lost.
23
27
  */
24
28
  export declare function representableInline(inline: Inline): Span[];
@@ -1,8 +1,8 @@
1
- import { Editor, type EditorOptions } from '@usememos/editor';
1
+ import { Editor, type EditorOptions, type SuggestionState } from '@usememos/editor';
2
2
  import { type CSSProperties } from 'react';
3
- export type { Editor } from '@usememos/editor';
3
+ export type { Editor, SuggestionState } from '@usememos/editor';
4
4
  /** Constructor options that the React components take as props. */
5
- type EditorProps = Pick<EditorOptions, 'markdown' | 'extensions' | 'placeholder' | 'editable' | 'autofocus' | 'attributes' | 'resolveImageSrc' | 'theme' | 'toolbar' | 'slashMenu' | 'labels'>;
5
+ type EditorProps = Pick<EditorOptions, 'markdown' | 'extensions' | 'placeholder' | 'editable' | 'taskToggle' | 'autofocus' | 'attributes' | 'resolveUrl' | 'referrerPolicy' | 'headingIds' | 'onLinkClick' | 'theme' | 'toolbar' | 'slashMenu' | 'labels' | 'icons'>;
6
6
  export interface MarkdownEditorProps extends EditorProps {
7
7
  /** Markdown. The editor updates only when this is not a value it emitted itself. */
8
8
  value?: string;
@@ -20,10 +20,11 @@ export interface MarkdownEditorProps extends EditorProps {
20
20
  /**
21
21
  * The editor as a controlled React component. A `ref` gives the core `Editor`.
22
22
  *
23
- * `placeholder`, `editable`, `attributes`, `resolveImageSrc` and `theme` update live.
23
+ * `placeholder`, `editable`, `taskToggle`, `attributes`, `resolveUrl`, `onLinkClick` and `theme` update live.
24
24
  * A change to the names in `extensions` recreates the editor, keeping its
25
- * Markdown. Other props are read when the editor is created; change the
26
- * component's `key` to apply new values.
25
+ * Markdown; with the same names, the callbacks of `suggestion()` extensions
26
+ * (`items`, `command`, `match`, `allow`) update live. Other props are read
27
+ * when the editor is created; change the component's `key` to apply new values.
27
28
  *
28
29
  * A `value` that arrives while an input method is composing text is applied
29
30
  * when the composition ends, so it does not break the composition.
@@ -35,9 +36,18 @@ export declare const MarkdownEditor: import("react").ForwardRefExoticComponent<M
35
36
  * `<EditorContent editor={editor} />`, which shows it.
36
37
  *
37
38
  * Callbacks in `options` are read when called, so they may change between
38
- * renders without recreating the editor.
39
+ * renders without recreating the editor. So do the callbacks of
40
+ * `suggestion()` extensions, matched by name.
39
41
  */
40
42
  export declare function useEditor(options: Omit<EditorOptions, 'element'>, deps?: readonly unknown[]): Editor | null;
43
+ /**
44
+ * The open autocomplete popup of `editor`, or of its suggestion `name`, and
45
+ * a re-render on each change. With `render: false` on a suggestion, draw your
46
+ * own popup from it: put it at `state.anchorRect()`, give the listbox
47
+ * `id={state.listboxId}` and each option `id={state.optionId(i)}`, highlight
48
+ * `state.active`, and call `editor.suggestion.accept(i)` on click.
49
+ */
50
+ export declare function useSuggestion(editor: Editor | null, name?: string): SuggestionState | null;
41
51
  export interface EditorContentProps {
42
52
  editor: Editor | null;
43
53
  className?: string;
@@ -0,0 +1,21 @@
1
+ export interface Box {
2
+ readonly left: number;
3
+ readonly right: number;
4
+ readonly top: number;
5
+ readonly bottom: number;
6
+ }
7
+ export interface Anchor {
8
+ /** The rect to place the popup next to: the caret's line, at the trigger's x. */
9
+ readonly rect: Box;
10
+ /** `end` lines up the popup's right edge (right-to-left text). */
11
+ readonly align: 'start' | 'end';
12
+ }
13
+ /**
14
+ * The popup's anchor from the trigger character's rect and the caret's.
15
+ * Null when the trigger is outside `visible`. When the token wraps, so the
16
+ * trigger is on an earlier line than the caret, the popup lines up with the
17
+ * caret instead.
18
+ */
19
+ export declare function suggestionAnchor(trigger: Box | null, caret: Box | null, rtl: boolean, visible: Box | null): Anchor | null;
20
+ /** The part of the viewport where `el` can show content: inside every ancestor that clips or scrolls. */
21
+ export declare function visibleArea(el: HTMLElement): Box;
@@ -0,0 +1,115 @@
1
+ import type { Editor } from '../editor.js';
2
+ import type { SuggestionConfig, SuggestionItem, SuggestionRange } from '../extensions/suggestion.js';
3
+ /** The open suggestion, for apps that draw their own popup (`render: false`) or show state elsewhere. */
4
+ export interface SuggestionState {
5
+ /** The suggestion's name. */
6
+ readonly name: string;
7
+ readonly query: string;
8
+ /** The whole token, from the trigger to its end. */
9
+ readonly range: SuggestionRange;
10
+ /** The items to show, at most `limit`. Empty while there are none yet, or none match. */
11
+ readonly items: readonly SuggestionItem[];
12
+ /** The highlighted item's index, or -1 when there are no items. */
13
+ readonly active: number;
14
+ /** True while newer items are being loaded. */
15
+ readonly loading: boolean;
16
+ /** The ID the root's `aria-controls` names: give it to your `role="listbox"` element. */
17
+ readonly listboxId: string;
18
+ /** The ID of each `role="option"`; the root's `aria-activedescendant` names the active one. */
19
+ optionId(index: number): string;
20
+ /** Where to put the popup: the caret's line, at the trigger's start edge. Null while the trigger is out of view. */
21
+ anchorRect(): DOMRect | null;
22
+ }
23
+ /** What the controller needs from the editor. */
24
+ export interface SuggestionHost {
25
+ readonly editor: Editor;
26
+ readonly root: HTMLElement;
27
+ /** Sets `aria-activedescendant` on the root for the open popup or menu. */
28
+ syncActiveDescendant(): void;
29
+ /** Runs the UI update, which calls `update`. */
30
+ refresh(): void;
31
+ /** Reads a running composition into the model and ends it. */
32
+ endComposition(): void;
33
+ /** Emits `suggestionChange`. */
34
+ changed(state: SuggestionState | null): void;
35
+ }
36
+ export declare class SuggestionController {
37
+ private readonly host;
38
+ private readonly entries;
39
+ private session;
40
+ /** The token Escape closed the popup for. It stays closed until the caret leaves it. */
41
+ private dismissed;
42
+ /** The items shown, and the highlighted one. */
43
+ private items;
44
+ private active;
45
+ /** A line shown instead of items: the loading row or the empty label. */
46
+ private message;
47
+ /** The side the popup is on. It stays there while open, unless it no longer fits. */
48
+ private side;
49
+ private frame;
50
+ /** The last request was made while composing. */
51
+ private requestedComposing;
52
+ /** Until this time (ms), the popup takes no keys but Escape. */
53
+ private keysFrom;
54
+ /** What `suggestionChange` last reported, to emit only changes. */
55
+ private reported;
56
+ private readonly cleanup;
57
+ constructor(host: SuggestionHost, configs: readonly SuggestionConfig[]);
58
+ /** True while a suggestion tracks the token at the caret, shown or not. */
59
+ get isActive(): boolean;
60
+ /** True while the popup shows items, a loading row or the empty label. Its keys work then. */
61
+ get isOpen(): boolean;
62
+ /** The ID of the highlighted option while the popup is open. */
63
+ get activeDescendant(): string | null;
64
+ /** The open suggestion, or null. */
65
+ get state(): SuggestionState | null;
66
+ private get shown();
67
+ private get editor();
68
+ /**
69
+ * Takes new configs for the same suggestions, by name, so callbacks
70
+ * (`items`, `command`, `match`, `allow`) can change while the editor runs.
71
+ */
72
+ setConfigs(configs: readonly SuggestionConfig[]): void;
73
+ /** After typing: opens the suggestion whose token is at the caret, if any. Returns true when one opened. */
74
+ typed(): boolean;
75
+ /** Opens the popup for the token at the caret, as Ctrl+Space does. Returns false when there is none. */
76
+ open(name?: string): boolean;
77
+ /** Follows the document and the caret: updates the query, or closes. */
78
+ update(focused: boolean): void;
79
+ close(): void;
80
+ /** Moves the highlight by `delta` items, wrapping around. */
81
+ move(delta: number): void;
82
+ /** Picks the item at `index`, or the highlighted one. Returns false when there is none. */
83
+ accept(index?: number): boolean;
84
+ /**
85
+ * Handles a key while the popup is open. Returns true when the key was
86
+ * taken; the caller then prevents its default. Only the popup's keys are
87
+ * taken: arrows, Page Up and Down, Enter, Tab, Escape, and Ctrl+N and
88
+ * Ctrl+P on macOS.
89
+ */
90
+ keydown(e: KeyboardEvent): boolean;
91
+ /** Closes the popup and keeps it closed for this token (Escape). */
92
+ dismiss(): void;
93
+ /** Closes the popup and forgets dismissed tokens, as when the document is replaced. */
94
+ reset(): void;
95
+ /** Follows scrolling, resizing and the on-screen keyboard. */
96
+ reposition(): void;
97
+ destroy(): void;
98
+ private schedule;
99
+ private highlight;
100
+ /** Emits `suggestionChange` when the state differs from the last one reported. */
101
+ private report;
102
+ private itemsChanged;
103
+ /**
104
+ * The token at the caret that a suggestion accepts. When several do, the
105
+ * one that starts closest to the caret wins; on a tie, the earlier one.
106
+ */
107
+ private find;
108
+ /** Asks for items when the query changed, and shows them when they arrive. */
109
+ private refresh;
110
+ /** The popup's anchor, or null while the trigger is out of view. */
111
+ private anchor;
112
+ /** Shows the popup under the caret's line, lined up with the trigger, or hides it while the trigger is out of view. */
113
+ private place;
114
+ private pick;
115
+ }
@@ -0,0 +1,35 @@
1
+ import type { SuggestionMatcher } from '../extensions/suggestion.js';
2
+ import type { TagScanner } from '../extensions/tags.js';
3
+ import type { Inline } from '../model.js';
4
+ export interface DefaultMatcherOptions {
5
+ readonly allowSpaces?: boolean;
6
+ readonly allowAnywhere?: boolean;
7
+ readonly maxLength?: number;
8
+ }
9
+ /**
10
+ * The matcher of a suggestion without `match`: the nearest trigger before
11
+ * the caret, at the start of a line or after whitespace (any character with
12
+ * `allowAnywhere`), followed by a query with no whitespace (single spaces
13
+ * with `allowSpaces`). The token ends at the next whitespace after the
14
+ * caret, or at the caret with `allowSpaces`.
15
+ */
16
+ export declare function defaultMatcher({ allowSpaces, allowAnywhere, maxLength }?: DefaultMatcherOptions): SuggestionMatcher;
17
+ export interface MatchTokenOptions {
18
+ /** A character the scanner accepts inside a token, inserted at the caret while scanning. Default "a". */
19
+ readonly probe?: string;
20
+ /** Longest query. Default 30. */
21
+ readonly maxLength?: number;
22
+ }
23
+ /**
24
+ * Builds a matcher from a scanner, the same kind of function `tags({ scan })`
25
+ * takes, so the popup opens exactly where the text is highlighted. A probe
26
+ * character is inserted at the caret before scanning, so the scanner sees a
27
+ * token the user is still typing (`#` alone, or `#work/`) as a whole one.
28
+ * The scanner sees other triggers of the same length written as the first
29
+ * one, so a scanner for `#` also finds tokens typed with `#`.
30
+ */
31
+ export declare function matchToken(scan: TagScanner, { probe, maxLength }?: MatchTokenOptions): SuggestionMatcher;
32
+ /** The longest trigger at `i` that ends at or before `limit`. */
33
+ export declare function longestAt(text: string, i: number, triggers: readonly string[], limit?: number): string | null;
34
+ /** True when the character at `offset` is in inline code, a link, an image, raw HTML or a token. */
35
+ export declare function excludedAt(content: Inline, offset: number): boolean;
@@ -0,0 +1,23 @@
1
+ /** How long a request may be pending before the popup shows its loading row. */
2
+ export declare const LOADING_DELAY = 300;
3
+ export interface SourceHandlers<T> {
4
+ /** The result, or null when the source threw or rejected. */
5
+ show(value: T | null): void;
6
+ /** The request has been pending for `LOADING_DELAY` ms. */
7
+ loading(): void;
8
+ }
9
+ export declare class SourceRunner<T> {
10
+ private request;
11
+ private controller;
12
+ private debounceTimer;
13
+ private loadingTimer;
14
+ private waiting;
15
+ /** True from `run` until its result arrives or it is cancelled. */
16
+ get pending(): boolean;
17
+ /** Calls `fetch` after `debounce` ms and passes its result to `show`, unless a newer request or `cancel` came first. */
18
+ run(fetch: (signal: AbortSignal) => T | Promise<T>, handlers: SourceHandlers<T>, debounce?: number): void;
19
+ /** Drops the pending request: aborts its signal and clears its timers. */
20
+ cancel(): void;
21
+ private settle;
22
+ }
23
+ export declare function isPromise<T>(value: T | Promise<T>): value is Promise<T>;
@@ -1,20 +1,51 @@
1
- type Placement = 'below' | 'above';
1
+ import { type Icon } from '../icons.js';
2
+ export type Placement = 'below' | 'above';
3
+ /** Sets the element an editor's popups are appended to (the `popupContainer` option). */
4
+ export declare function setPopupContainer(owner: HTMLElement, container: HTMLElement | undefined): void;
5
+ /** Where the popups of the editor `owner` go: `popupContainer`, else the nearest open dialog or `aria-modal` ancestor, else the body. */
6
+ export declare function popupContainer(owner: HTMLElement): HTMLElement;
7
+ /**
8
+ * Appends a shown `position: fixed` element to its container, and returns
9
+ * the offset of its containing block. The offset is not zero when an
10
+ * ancestor has a `transform`, `filter` or `contain` style, which makes
11
+ * `position: fixed` relative to that ancestor instead of the viewport.
12
+ */
13
+ export declare function attach(el: HTMLElement, owner: HTMLElement): {
14
+ x: number;
15
+ y: number;
16
+ };
17
+ /** The visible part of the layout viewport, which the on-screen keyboard can shrink. */
18
+ export declare function visibleViewport(view: Window): {
19
+ left: number;
20
+ top: number;
21
+ width: number;
22
+ height: number;
23
+ };
2
24
  export declare const isMac: boolean;
25
+ /** Safari, which sends the Enter that commits a composition after `compositionend`. */
26
+ export declare const isSafari: boolean;
3
27
  /** True on touch devices, which have no hover and show their own menu over a selection. */
4
28
  export declare const isTouch: () => boolean;
5
29
  export declare class Popup {
6
30
  private readonly owner;
7
31
  readonly el: HTMLElement;
8
32
  private open;
33
+ private placed;
9
34
  constructor(owner: HTMLElement, className: string);
10
35
  get isOpen(): boolean;
11
- /** Shows the popup next to `rect` (viewport coordinates), flipping to stay on screen. */
36
+ /** The side of the anchor the popup was last shown on. */
37
+ get side(): Placement;
38
+ /**
39
+ * Shows the popup next to `rect` (viewport coordinates), flipping to stay
40
+ * on screen. With `align: 'end'`, its right edge lines up with `rect.right`
41
+ * (for right-to-left text).
42
+ */
12
43
  show(rect: {
13
44
  left: number;
14
45
  top: number;
15
46
  bottom: number;
16
47
  right?: number;
17
- }, placement?: Placement, gap?: number): void;
48
+ }, placement?: Placement, gap?: number, align?: 'start' | 'end'): void;
18
49
  hide(): void;
19
50
  destroy(): void;
20
51
  private copyTheme;
@@ -22,8 +53,12 @@ export declare class Popup {
22
53
  export interface MenuItem {
23
54
  id: string;
24
55
  label: string;
25
- /** Short glyph shown before the label. */
26
- icon?: string;
56
+ /** Secondary text after the label. */
57
+ detail?: string;
58
+ /** Text in the label to mark (the query): its first case-insensitive occurrence. */
59
+ mark?: string;
60
+ /** Shown before the label: text, or an element that is cloned. */
61
+ icon?: Icon;
27
62
  /** Extra words that match when filtering. */
28
63
  aliases?: string[];
29
64
  danger?: boolean;
@@ -41,13 +76,27 @@ export declare class Menu {
41
76
  private readonly id;
42
77
  /** Called after an item runs. */
43
78
  onPicked: (() => void) | null;
79
+ /** Called when the highlight moves, by key, by mouse or because the items changed. */
80
+ onHighlight: ((index: number) => void) | null;
44
81
  constructor(owner: HTMLElement, className: string, role?: 'listbox' | 'menu');
45
82
  get el(): HTMLElement;
46
83
  get isOpen(): boolean;
47
84
  get activeDescendant(): string | null;
48
85
  setSections(sections: MenuSection[], emptyLabel?: string): void;
86
+ /** Replaces the items with a line of text that is not an option, such as "Loading…". */
87
+ setMessage(text: string, className: string): void;
88
+ /** Marks the list as waiting for newer items (`aria-busy`). */
89
+ set busy(busy: boolean);
49
90
  get count(): number;
91
+ /** The ID of the highlighted item. */
92
+ get activeId(): string | null;
93
+ /** Highlights the item with this ID. Returns false when there is none. */
94
+ highlightId(id: string): boolean;
95
+ /** Moves the highlight by a page: the number of items that fit in the list's height. Stops at the ends. */
96
+ page(direction: 1 | -1): void;
50
97
  highlight(i: number): void;
98
+ /** The index of the highlighted item. */
99
+ get activeIndex(): number;
51
100
  move(delta: number): void;
52
101
  pick(i?: number): void;
53
102
  hide(): void;
@@ -55,4 +104,3 @@ export declare class Menu {
55
104
  }
56
105
  /** Case-insensitive match of a query against an item's label and aliases (a substring, also with spaces ignored). */
57
106
  export declare function matches(item: Pick<MenuItem, 'label' | 'aliases'>, query: string): boolean;
58
- export {};