@usememos/editor 26.10.1 → 26.10.2
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.
- package/README.md +95 -25
- package/dist/base.css +18 -4
- package/dist/index.js +1525 -253
- package/dist/index.js.map +4 -4
- package/dist/react.js +22 -4
- package/dist/react.js.map +3 -3
- package/dist/style.css +48 -7
- package/dist/theme.css +4 -3
- package/dist/types/commands.d.ts +21 -0
- package/dist/types/editor.d.ts +111 -30
- package/dist/types/extensions/suggestion.d.ts +122 -30
- package/dist/types/extensions/tags.d.ts +5 -8
- package/dist/types/icons.d.ts +123 -0
- package/dist/types/index.d.ts +5 -2
- package/dist/types/labels.d.ts +8 -0
- package/dist/types/react/index.d.ts +17 -7
- package/dist/types/suggest/anchor.d.ts +21 -0
- package/dist/types/suggest/controller.d.ts +115 -0
- package/dist/types/suggest/match.d.ts +35 -0
- package/dist/types/suggest/source.d.ts +23 -0
- package/dist/types/ui/popup.d.ts +54 -6
- package/dist/types/view/scroll.d.ts +6 -0
- package/package.json +6 -2
|
@@ -1,51 +1,143 @@
|
|
|
1
1
|
import type { Editor } from '../editor.js';
|
|
2
2
|
import type { Extension } from '../extension.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Icon } from '../icons.js';
|
|
4
|
+
import type { Block, Cell, Inline, Position } from '../model.js';
|
|
4
5
|
export interface SuggestionItem {
|
|
5
6
|
/** Stable ID, for tests and keys. Defaults to the label. */
|
|
6
7
|
readonly id?: string;
|
|
7
8
|
readonly label: string;
|
|
8
|
-
/**
|
|
9
|
-
readonly
|
|
9
|
+
/** Secondary text after the label, such as a user name or a path. */
|
|
10
|
+
readonly detail?: string;
|
|
11
|
+
/** Shown before the label: text, or an element (such as an `<svg>` or an avatar `<img>`) that is cloned. */
|
|
12
|
+
readonly icon?: Icon;
|
|
13
|
+
/** A group heading. Items with the same section should be next to each other; a heading starts where it changes. */
|
|
14
|
+
readonly section?: string;
|
|
15
|
+
/** Written after the trigger by the default command. Default `id`, then `label`. */
|
|
16
|
+
readonly value?: string;
|
|
10
17
|
}
|
|
11
18
|
export interface SuggestionRange {
|
|
12
|
-
/** The trigger
|
|
19
|
+
/** The start of the trigger. */
|
|
13
20
|
readonly from: Position;
|
|
14
|
-
/** The
|
|
21
|
+
/** The end of the token, which may be after the caret. */
|
|
15
22
|
readonly to: Position;
|
|
16
23
|
}
|
|
24
|
+
/** A token at the caret, as offsets into the block's or cell's text. */
|
|
25
|
+
export interface SuggestionMatch {
|
|
26
|
+
/** The start of the trigger. */
|
|
27
|
+
readonly from: number;
|
|
28
|
+
/** The end of the token. At or after the caret. */
|
|
29
|
+
readonly to: number;
|
|
30
|
+
/** What `items` receives. The built-in matchers return the text between the trigger and the caret. */
|
|
31
|
+
readonly query: string;
|
|
32
|
+
}
|
|
33
|
+
export interface SuggestionMatchContext {
|
|
34
|
+
/** The plain text of the block or table cell with the caret. */
|
|
35
|
+
readonly text: string;
|
|
36
|
+
/** The caret's offset in `text`. */
|
|
37
|
+
readonly caret: number;
|
|
38
|
+
/** The formatted content, to check marks and links. */
|
|
39
|
+
readonly content: Inline;
|
|
40
|
+
/** The suggestion's triggers. */
|
|
41
|
+
readonly triggers: readonly string[];
|
|
42
|
+
}
|
|
43
|
+
/** Finds the token at the caret, or returns null. See `matchToken` for building one from a scanner. */
|
|
44
|
+
export type SuggestionMatcher = (ctx: SuggestionMatchContext) => SuggestionMatch | null;
|
|
45
|
+
export interface SuggestionAllowContext {
|
|
46
|
+
readonly editor: Editor;
|
|
47
|
+
/** The block with the caret. For a table cell, the table. */
|
|
48
|
+
readonly block: Block;
|
|
49
|
+
readonly cell?: Cell;
|
|
50
|
+
/** The start of the trigger, as an offset into the block's or cell's text. */
|
|
51
|
+
readonly from: number;
|
|
52
|
+
readonly query: string;
|
|
53
|
+
/** The text before the trigger in the same block or cell. */
|
|
54
|
+
readonly textBefore: string;
|
|
55
|
+
/** True when the trigger is in inline code, a link, an image, raw HTML or an extension token. */
|
|
56
|
+
readonly excluded: boolean;
|
|
57
|
+
/** True when the user asked for the popup (Ctrl+Space), rather than typing. */
|
|
58
|
+
readonly explicit: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface SuggestionItemsContext {
|
|
61
|
+
/** What the matcher returned; for the built-in matchers, the text between the trigger and the caret, unchanged. */
|
|
62
|
+
readonly query: string;
|
|
63
|
+
readonly editor: Editor;
|
|
64
|
+
/** True when the user asked for the popup (Ctrl+Space), rather than typing. */
|
|
65
|
+
readonly explicit: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* True while an input method is composing the query. The text may be a
|
|
68
|
+
* reading that matches nothing yet; an empty result then keeps the list shown.
|
|
69
|
+
*/
|
|
70
|
+
readonly composing: boolean;
|
|
71
|
+
/** Aborted when the query changes or the popup closes. Pass it to `fetch`. */
|
|
72
|
+
readonly signal: AbortSignal;
|
|
73
|
+
}
|
|
74
|
+
export interface SuggestionCommandContext<T> {
|
|
75
|
+
readonly editor: Editor;
|
|
76
|
+
/** The whole token: from the trigger to the end the matcher reported. */
|
|
77
|
+
readonly range: SuggestionRange;
|
|
78
|
+
readonly item: T;
|
|
79
|
+
readonly query: string;
|
|
80
|
+
}
|
|
17
81
|
export interface SuggestionConfig<T extends SuggestionItem = SuggestionItem> {
|
|
18
|
-
/**
|
|
19
|
-
readonly
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
82
|
+
/** Unique among the editor's extensions. Also the name of the suggestion in `editor.suggestion.open(name)`. */
|
|
83
|
+
readonly name: string;
|
|
84
|
+
/**
|
|
85
|
+
* Strings that start a token, such as "#", "@" or "[[". The first one is
|
|
86
|
+
* what the default command writes, so `['#', '#']` turns a full-width `#`
|
|
87
|
+
* into `#` on pick.
|
|
88
|
+
*/
|
|
89
|
+
readonly trigger: string | readonly string[];
|
|
90
|
+
/**
|
|
91
|
+
* Items for the query, shown in the order given. May be async: while a
|
|
92
|
+
* newer result is pending, the items shown stay usable; a result that
|
|
93
|
+
* arrives after the query changed is dropped; a rejection counts as no
|
|
94
|
+
* items.
|
|
95
|
+
*/
|
|
96
|
+
readonly items: (ctx: SuggestionItemsContext) => readonly T[] | Promise<readonly T[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Applies the picked item, usually by replacing `range`. Default: writes
|
|
99
|
+
* the first trigger, the item's `value` and a space, which is left out
|
|
100
|
+
* when the next character is whitespace or closing punctuation.
|
|
101
|
+
*/
|
|
102
|
+
readonly command?: (ctx: SuggestionCommandContext<T>) => void;
|
|
103
|
+
/**
|
|
104
|
+
* Finds the token at the caret. Default: a trigger at the start of a line
|
|
105
|
+
* or after whitespace, followed by text up to the caret with no whitespace
|
|
106
|
+
* (see `allowSpaces` and `allowAnywhere`). The token must start with one of
|
|
107
|
+
* the triggers.
|
|
108
|
+
*/
|
|
109
|
+
readonly match?: SuggestionMatcher;
|
|
110
|
+
/**
|
|
111
|
+
* Whether the popup may open for a match. Default: not when the trigger is
|
|
112
|
+
* in inline code, a link, an image, raw HTML or a token. Code blocks and
|
|
113
|
+
* raw blocks never open a popup.
|
|
114
|
+
*/
|
|
115
|
+
readonly allow?: (ctx: SuggestionAllowContext) => boolean;
|
|
116
|
+
/** Default matcher only: the query may contain single spaces, and the token ends at the caret. Default false. */
|
|
36
117
|
readonly allowSpaces?: boolean;
|
|
37
|
-
/**
|
|
118
|
+
/** Default matcher only: the trigger may follow any character. Default false: only the start of a line or whitespace. */
|
|
38
119
|
readonly allowAnywhere?: boolean;
|
|
39
|
-
/**
|
|
120
|
+
/** Waits until the query has not changed for this many ms before calling `items`. Default 0. */
|
|
121
|
+
readonly debounce?: number;
|
|
122
|
+
/** Most items shown. Default 50. */
|
|
123
|
+
readonly limit?: number;
|
|
124
|
+
/** Longest query that keeps the popup open. Default 30. */
|
|
40
125
|
readonly maxLength?: number;
|
|
41
126
|
/**
|
|
42
127
|
* Shown when there are no items, for queries up to three characters.
|
|
43
|
-
* Without it the
|
|
128
|
+
* Without it the popup hides while there are no items.
|
|
44
129
|
*/
|
|
45
130
|
readonly emptyLabel?: string;
|
|
46
|
-
/**
|
|
131
|
+
/** Accessible name of the listbox. Default `labels.suggestions`. */
|
|
132
|
+
readonly label?: string;
|
|
133
|
+
/**
|
|
134
|
+
* `false` draws no popup: matching, keys, async items and ARIA on the root
|
|
135
|
+
* still work, and the app draws its own popup from `editor.suggestion.state`
|
|
136
|
+
* and the `suggestionChange` event.
|
|
137
|
+
*/
|
|
138
|
+
readonly render?: false;
|
|
139
|
+
/** Extra class names for the popup element. */
|
|
47
140
|
readonly className?: string;
|
|
48
141
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}): Extension;
|
|
142
|
+
/** An autocomplete popup. Add one per trigger syntax, such as tags, mentions or links. */
|
|
143
|
+
export declare function suggestion<T extends SuggestionItem>(config: SuggestionConfig<T>): Extension;
|
|
@@ -1,16 +1,13 @@
|
|
|
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
|
|
5
|
+
export interface TagsOptions {
|
|
7
6
|
/** Class on each match. Default `mbe-tag` for tags and `mbe-mention` for mentions. */
|
|
8
7
|
readonly class?: string;
|
|
9
8
|
readonly attributes?: Readonly<Record<string, string>>;
|
|
10
9
|
/** Finds matches in a run of text. Default `scanTags` or `scanMentions`. */
|
|
11
10
|
readonly scan?: TagScanner;
|
|
12
|
-
/** A suggestion menu opened by the trigger character. See `suggestion()`. */
|
|
13
|
-
readonly suggestion?: Omit<SuggestionConfig<T>, 'char'>;
|
|
14
11
|
}
|
|
15
12
|
/**
|
|
16
13
|
* The default tag grammar. A tag is `#` and one or more segments separated
|
|
@@ -28,7 +25,7 @@ export declare function scanTags(text: string, from?: number, to?: number): Gene
|
|
|
28
25
|
* `_`, `.`, `+`, `-` or `@`, so the middle of an e-mail address is no mention.
|
|
29
26
|
*/
|
|
30
27
|
export declare function scanMentions(text: string, from?: number, to?: number): Generator<TextRange>;
|
|
31
|
-
/** `#tag` highlighting
|
|
32
|
-
export declare function tags
|
|
33
|
-
/** `@name` highlighting
|
|
34
|
-
export declare function mentions
|
|
28
|
+
/** `#tag` highlighting and `\#` escapes. */
|
|
29
|
+
export declare function tags(options?: TagsOptions): Extension;
|
|
30
|
+
/** `@name` highlighting and `\@` escapes. */
|
|
31
|
+
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 {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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';
|
|
@@ -18,6 +19,8 @@ export type { BlockSyntax, BlockSyntaxMatcher, InlineSyntax, MarkdownSyntax } fr
|
|
|
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';
|
package/dist/types/labels.d.ts
CHANGED
|
@@ -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;
|
|
@@ -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' | 'resolveImageSrc' | '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`, `resolveImageSrc` and `theme` update live.
|
|
24
24
|
* A change to the names in `extensions` recreates the editor, keeping its
|
|
25
|
-
* Markdown
|
|
26
|
-
*
|
|
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>;
|