@withmarfa/inkkit 0.0.0-stage → 0.8.0-alpha.1

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.
@@ -0,0 +1,592 @@
1
+ import { type DiagnosticReport } from './diagnostics.js';
2
+ import type { SlashMenuOptions } from './types.js';
3
+ import { InkKitError, type ClientPoint, type LinkMenuTarget, type DocumentFormat, type DocumentInput, type DocumentSnapshot, type ConvertedDocument, type TextDocumentFormat, type ImageAdapter, type FileAdapter, type WikiLinkAdapter, type ClipboardInput, type ClipboardOutput, type ClipboardScope, type DocumentVersion, type PrintableDocument, type TextRange, type ReadableTextSnapshot, type FindSession, type FindState, type TextRect, type ViewportOptions, type ViewportSnapshot, type EditorLabels, type Heading, type TableCommand, type TableOptions, type BlockMoveDirection, type OfferedFormat } from './types.js';
4
+ /** An inline format that `CaretState` can report. */
5
+ export type Mark = 'bold' | 'italic' | 'strikethrough' | 'highlight' | 'underline' | 'superscript' | 'subscript' | 'code' | 'link';
6
+ /** The kind of block that holds the start of the selection. Any other block reports `paragraph`. */
7
+ export type Block = {
8
+ type: 'paragraph';
9
+ } | {
10
+ type: 'heading';
11
+ level: number;
12
+ } | {
13
+ type: 'codeBlock';
14
+ } | {
15
+ type: 'bulletList';
16
+ } | {
17
+ type: 'orderedList';
18
+ } | {
19
+ type: 'taskList';
20
+ };
21
+ /** `source` shows the Markdown or literal text in a textarea. A TXT document is always `source`, and an
22
+ * RTF document always `formatted`. */
23
+ export type EditingMode = 'source' | 'formatted';
24
+ /** The formatting at the selection, for host toolbars. */
25
+ export interface CaretState {
26
+ /** At a caret, the marks the next typed text takes. For a range, every mark found in it. */
27
+ marks: Mark[];
28
+ block: Block;
29
+ /** One quote holds the whole selection; the block is what sits inside it. */
30
+ quoted: boolean;
31
+ /** The address of the link at the caret or, for a range, of the first link in it, as the
32
+ * document holds it. Present exactly when `marks` includes `'link'`. For a reference link, it
33
+ * is the address its definition gives. A host's Link sheet starts from it. */
34
+ href?: string;
35
+ /** In an RTF document, the alignment of the paragraph that holds the start of the selection. */
36
+ align?: 'left' | 'center' | 'right' | 'justify';
37
+ }
38
+ declare const formatCommands: readonly ['heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6', 'paragraph', 'bold', 'italic', 'strikethrough', 'highlight', 'underline', 'superscript', 'subscript', 'code', 'codeBlock', 'quote', 'bulletList', 'orderedList', 'taskList', 'toggleTask', 'alignLeft', 'alignCenter', 'alignRight', 'alignJustify', 'link'];
39
+ /** A command for `format`. */
40
+ export type FormatCommand = (typeof formatCommands)[number];
41
+ /** `destination` goes only with `link`, and `language` only with `codeBlock`. */
42
+ export interface FormatOptions {
43
+ destination?: string;
44
+ language?: string;
45
+ }
46
+ /** A key press for `keyDown`. An omitted modifier is not held. */
47
+ export interface KeyInput {
48
+ key: string;
49
+ code?: string;
50
+ metaKey?: boolean;
51
+ ctrlKey?: boolean;
52
+ altKey?: boolean;
53
+ shiftKey?: boolean;
54
+ }
55
+ /** An image to insert by the reference its adapter already stored it under. */
56
+ export interface ImageInsertion {
57
+ reference: string;
58
+ alt: string;
59
+ title?: string;
60
+ }
61
+ /** A name in `Keymap`: every format command except `link`, history, link opening, block moves, list indentation,
62
+ * and every table command. */
63
+ export type ShortcutName = Exclude<FormatCommand, 'link'> | 'undo' | 'redo' | 'moveBlockUp' | 'moveBlockDown' | 'indent' | 'outdent' | 'openLink' | `table${Capitalize<TableCommand>}`;
64
+ /** Host bindings in ProseMirror key notation, by shortcut name. */
65
+ export type Keymap = Partial<Record<ShortcutName, readonly string[]>>;
66
+ /** Every `ShortcutName`. */
67
+ export declare const shortcutNames: readonly ShortcutName[];
68
+ /** Hints for the browser's input features, smart punctuation and typing aids. A field left out
69
+ * takes its default. */
70
+ export interface TextInputPreferences {
71
+ spellcheck?: boolean;
72
+ autocorrect?: boolean;
73
+ autocapitalize?: 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters';
74
+ /** Typing a quote or `--` gives a curly quote or a dash, in formatted mode. Off unless true. */
75
+ smartPunctuation?: boolean;
76
+ /** Typing `(`, `[`, `{`, `"` or `'` also inserts its closer. Off unless true. */
77
+ pairBrackets?: boolean;
78
+ /** Return in a list item starts the next item. Defaults to true. */
79
+ continueLists?: boolean;
80
+ /** What Tab inserts in source and TXT modes. Defaults to `'tab'`. */
81
+ indent?: 'tab' | 'spaces';
82
+ /** The width of one indent made of spaces: an integer from 1 to 8. Defaults to 4. */
83
+ indentWidth?: number;
84
+ /** How a paste reads the clipboard. `'plainText'` inserts its plain text literally, as
85
+ * `pasteAsPlainText` does, in every mode and format. Defaults to `'formatted'`. */
86
+ paste?: PasteRoute;
87
+ }
88
+ /** How a paste reads the clipboard: as formatting, or as literal plain text. */
89
+ export type PasteRoute = 'formatted' | 'plainText';
90
+ /** Presentation settings that never touch the document, its revision, history, dirty state,
91
+ * snapshot, copy or print output. A field left out takes its default. */
92
+ export interface DisplayPreferences {
93
+ /** In formatted mode, a control beside each top-level heading hides what follows it, up to the
94
+ * next heading of the same or a higher level. Off unless true. */
95
+ foldHeadings?: boolean;
96
+ /** In formatted mode, each code block shows a number for each line of its text. Off unless
97
+ * true. */
98
+ codeLineNumbers?: boolean;
99
+ /** In formatted mode, how YAML front matter shows: `'source'`, its YAML as written, or
100
+ * `'properties'`, a list of its properties that shows the YAML to edit when clicked or when the
101
+ * caret moves into it. `'source'` unless set.
102
+ *
103
+ * `'properties'` needs a reader that loads the first time a document with YAML front matter
104
+ * shows that way, so front matter shows as source until the reader has loaded. The list then
105
+ * replaces it without a change to the document, its revision, history or snapshot. It waits
106
+ * while the caret is in the block and during a text composition, and appears when the caret
107
+ * leaves or the composition ends. YAML that is not a readable mapping, or that holds more than
108
+ * 5,000 values (each alias counts as the values it expands to), stays as source. A reader that fails to load leaves the
109
+ * front matter as source and reports one `InkKitError` with the code `internal` to
110
+ * `events.error`, with the failure as its `cause`. The editor stays fully usable, and the next
111
+ * document or display preference tries the reader again. */
112
+ frontMatter?: 'source' | 'properties';
113
+ }
114
+ /** Mount options. Adapters, `formats`, `labels`, `linkSchemes` and `rendering` are fixed at mount;
115
+ * the rest can change. `F` is the formats offered. */
116
+ export interface EditorOptions<F extends DocumentFormat = TextDocumentFormat> {
117
+ /** The formats the host offers, listed by `formats`. Defaults to `['md', 'txt']`. Fixed at mount. */
118
+ formats?: readonly F[];
119
+ /** Shows, imports and exports images. Without it and `files`, image Markdown stays literal. */
120
+ images?: ImageAdapter;
121
+ /** Opt-in block suggestions on an empty line. `setSlashMenuEnabled` turns it on or off later. */
122
+ slashMenu?: SlashMenuOptions;
123
+ /** Resolves path images and `![[name]]` embeds into images, audio, video, PDFs and file cards. */
124
+ files?: FileAdapter;
125
+ /** Resolves and opens `[[wiki links]]`. Without it they stay literal. */
126
+ wikiLinks?: WikiLinkAdapter;
127
+ /** Defaults to true. See `setEditable`. */
128
+ editable?: boolean;
129
+ /** See `setTextInputPreferences`. */
130
+ textInput?: TextInputPreferences;
131
+ /** See `setDisplayPreferences`. */
132
+ display?: DisplayPreferences;
133
+ /** Replaces built-in text and accessible names. */
134
+ labels?: Partial<EditorLabels>;
135
+ /** See `setKeymap`. */
136
+ keymap?: Keymap;
137
+ /** Schemes beyond `http`, `https`, `mailto` and `tel` that links may use, such as `things`.
138
+ * Fixed at mount. */
139
+ linkSchemes?: readonly string[];
140
+ /** What the editor draws besides text. Fixed at mount. */
141
+ rendering?: {
142
+ /** Defaults to true. */
143
+ codeHighlighting?: boolean;
144
+ /** Defaults to true. */
145
+ diagramPreview?: boolean;
146
+ /** Draws the caret at text height in formatted mode, where a fine pointer is the primary
147
+ * input. Defaults to true. */
148
+ drawnSelection?: boolean;
149
+ };
150
+ }
151
+ /** What the editor can do now. Availability is the state at the time of the call, not a promise. */
152
+ export interface CommandState extends DocumentVersion {
153
+ format: DocumentFormat;
154
+ mode: EditingMode;
155
+ editable: boolean;
156
+ /** Text composition (IME) is in progress. */
157
+ composing: boolean;
158
+ /** An image import is running. */
159
+ pending: boolean;
160
+ caret: CaretState;
161
+ /** Present when the selection is in a table. `rows` includes the header row. */
162
+ table?: {
163
+ row: number;
164
+ column: number;
165
+ rows: number;
166
+ columns: number;
167
+ };
168
+ commands: {
169
+ undo: boolean;
170
+ redo: boolean;
171
+ insertText: boolean;
172
+ paste: boolean;
173
+ replace: boolean;
174
+ replaceSource: boolean;
175
+ insertImages: boolean;
176
+ appendImages: boolean;
177
+ insertPaths: boolean;
178
+ insertFootnote: boolean;
179
+ editReferenceDefinition: boolean;
180
+ format: Record<FormatCommand, boolean>;
181
+ /** Whether `table(command)` applies at the selection now, for every command. */
182
+ table: Record<TableCommand, boolean>;
183
+ moveBlockUp: boolean;
184
+ moveBlockDown: boolean;
185
+ };
186
+ }
187
+ /** The host's handlers, passed to `mount`. Only `changed` is required. `F` is the formats offered. */
188
+ export interface EditorEvents<F extends DocumentFormat = TextDocumentFormat> {
189
+ /** The document changed. Not sent for a load, a reload or a refused edit. */
190
+ changed(snapshot: DocumentSnapshot<F>): void;
191
+ /** Availability or the caret changed, and once after each load. */
192
+ commandStateChanged?(state: CommandState): void;
193
+ /** A primary click with Mod on a link. Without it, links don't open. In an editor that can't be
194
+ * edited, a plain click opens it too. */
195
+ openLink?(href: string): void;
196
+ /** The person asked for the context menu on a link, web or wiki. InkKit selects the link, then
197
+ * calls this with the link and the pointer position, so the host can show Open, Copy, Edit and
198
+ * Remove. Without it, the web view's own menu shows. */
199
+ linkMenu?(link: LinkMenuTarget, point: ClientPoint): void;
200
+ /** The Copy button on a code block was clicked. Without this handler, no button is drawn. */
201
+ copy?(text: string): void;
202
+ /** A failure that no call is waiting for, such as one in an edit the person made, or a step of
203
+ * `destroy` that failed. */
204
+ error?(error: InkKitError): void;
205
+ /** The person copied or cut a selection that holds an image or a diagram. Resolve after the
206
+ * native clipboard write succeeds; a cut removes the selection only then. */
207
+ clipboard?(content: ClipboardOutput): void | Promise<void>;
208
+ }
209
+ /** Every member of `EditorEvents`. The type check below fails to compile when one is left out. */
210
+ export declare const editorEvents: readonly ["changed", "commandStateChanged", "openLink", "linkMenu", "copy", "error", "clipboard"];
211
+ /**
212
+ * The editor. Create it with `InkKitEditor.mount`, load a document, and read it back with
213
+ * `snapshot`. The reference is https://inkkit.withmarfa.com/reference/editor.
214
+ */
215
+ export declare class InkKitEditor<F extends DocumentFormat = TextDocumentFormat> {
216
+ private readonly options;
217
+ private editor;
218
+ private readonly diagnostics;
219
+ private unrecordedDepth;
220
+ private readonly document;
221
+ private readonly history;
222
+ private readonly text;
223
+ private readonly geometry;
224
+ private readonly search;
225
+ private readonly diagrams;
226
+ private readonly output;
227
+ private readonly clipboard;
228
+ private lastMarkdown;
229
+ private readonly session;
230
+ private mode;
231
+ private ready;
232
+ private destroyed;
233
+ private pasteController;
234
+ private source;
235
+ private root;
236
+ private ownsRootClass;
237
+ private activation;
238
+ private reportingSuppressed;
239
+ /** A reload keeps each find session's query; a load starts without one. */
240
+ private reloading;
241
+ private readonly findSessions;
242
+ private loading;
243
+ private call?;
244
+ /** Changes when tracked bracket pairs are to be forgotten, as on a mode switch. */
245
+ private pairEpoch;
246
+ /** Greater than zero while a host operation that names its own targets runs. */
247
+ private namingTargets;
248
+ private writable;
249
+ private inputPreferences;
250
+ private displayState;
251
+ private literalKeys;
252
+ private indentKeys;
253
+ private readOnlyKeys;
254
+ private suggestions?;
255
+ private slashMenu?;
256
+ private suggestionBase?;
257
+ private changePlugin;
258
+ private documentChanged;
259
+ private keys;
260
+ private readingKeys;
261
+ private readonly events;
262
+ /** The host's extra link schemes, in lower case. */
263
+ private readonly linkSchemes;
264
+ /** The formats the host offered, in its order. */
265
+ private readonly offered;
266
+ private readonly formatList;
267
+ /** How many of each state event the host has been sent. */
268
+ private readonly sentEvents;
269
+ private constructor();
270
+ private context;
271
+ /** The generation of the loaded document, for the composition check of native input. */
272
+ private get generation();
273
+ /** What `changed` reports for the document's new text. */
274
+ private changeSnapshot;
275
+ private saved;
276
+ /** The current text, as `snapshot` checks and reads it. */
277
+ private savedText;
278
+ /** Throws unless the document `captured` describes is still current, alive, not composing and
279
+ * has no import pending. */
280
+ private assertCaptured;
281
+ /** Throws unless a deferred cut can still remove what it copied: the document, its revision,
282
+ * the editing mode and editability are as they were when the cut started. */
283
+ private assertCut;
284
+ /** What file and wiki-link views capture: the adapter context, and whether the same load is
285
+ * still current. Edits do not make their work stale. */
286
+ private adapterCapture;
287
+ private mediaPolicy;
288
+ private assertAlive;
289
+ private assertReady;
290
+ /** Checks, in order, that the editor is alive, that `expectedGeneration` is a generation, and
291
+ * that the document is loaded, current, not composing and has no import pending. */
292
+ private assertCurrent;
293
+ private assertMutation;
294
+ /**
295
+ * Runs one facade call, so that its failure reaches the caller once and coded, and a failed call
296
+ * changes nothing and sends nothing. An edit that the preservation check refuses during the call
297
+ * is thrown, not sent to `events.error`. When the call fails with a refusal or another coded
298
+ * failure, every step it took is undone: the document, selection and history return to their
299
+ * state before the call, with the editing mode, editability, preferences, slash menu and the
300
+ * source surface's text, and the state events it raised are dropped. An `internal` failure keeps
301
+ * what happened and sends its events, since the editor's state can no longer be trusted to match.
302
+ * Anything else thrown arrives as an `InkKitError`. A call made inside another runs as part of
303
+ * it. Promises reject instead of throwing.
304
+ */
305
+ private facadeCall;
306
+ /** Sends a finished call's state events in order. Each event reports the whole of its state, so
307
+ * once a call made from one of the host's handlers has sent a newer event of a kind, the call's
308
+ * remaining events of that kind are out of date and are dropped. */
309
+ private deliver;
310
+ /** What a failed call puts back. */
311
+ private restorePoint;
312
+ private finish;
313
+ /** Shows the surface and input attributes of the restored mode and preferences, which a failed
314
+ * call may have half changed. Returns the failure to draw them, which the caller reports as
315
+ * `internal` once every step of the restore is done, since the surface may then differ from the
316
+ * editor's state; the call's own failure still reaches its caller. */
317
+ private restoreSurface;
318
+ /** Puts focus where it was before a failed call, which the call may have moved. Focus that the
319
+ * call left on the surface that is hidden again, or moved from where it was into the editor,
320
+ * goes back to `before` if that is still in the page, or else to the surface that shows. Focus
321
+ * that the call did not move, such as a control inside the editor's container, stays. */
322
+ private restoreFocus;
323
+ /** Calls the editor makes to its own public methods, to publish command state, keep the selection
324
+ * in view or finish another method's work. Diagnostics record what the host or person did, so
325
+ * these run without operation events. */
326
+ private unrecorded;
327
+ /** Reports a refused edit to the facade call that made it, or else to `events.error`. */
328
+ private refuse;
329
+ /** Reports a failure no call is waiting for. A destroyed editor reports nothing: the host has
330
+ * torn it down, so a deferred operation that finds it gone has no one to tell. */
331
+ private report;
332
+ /** Delivers a failure to `events.error`, destroyed or not. */
333
+ private deliverError;
334
+ /** Runs a host operation that names the text it changes, such as a replacement, which may
335
+ * therefore change text a fold hides. */
336
+ private naming;
337
+ /** Runs a facade method for something the person did, such as a shortcut. Its failure goes to
338
+ * `events.error`, unless a host call such as `keyDown` is waiting for it. */
339
+ private forPerson;
340
+ private get composing();
341
+ private diagnosticState;
342
+ /** Starts or clears content-free local tracing. Disabled by default. */
343
+ setDiagnosticsEnabled(enabled: boolean): void;
344
+ /** Reads diagnostics without serializing the document or requiring an editable surface. */
345
+ diagnosticReport(): DiagnosticReport;
346
+ /** The formats the host offered at mount, in its order, with what saving each promises. */
347
+ get formats(): readonly OfferedFormat[];
348
+ /** Whether the person can edit. A read-only editor still permits selection, copying and find. */
349
+ get editable(): boolean;
350
+ /** Turns editing on or off for both surfaces. Throws `composition` during text composition. */
351
+ setEditable(editable: boolean): void;
352
+ /** Supplies native host activation for selection presentation, which a web view cannot always read
353
+ * from `document.hasFocus()`. It may be called before the first load and holds across loads until
354
+ * changed. Null restores browser detection. */
355
+ setHostActive(active: boolean | null): void;
356
+ /** Turns the slash menu on or off. Commands chosen at mount are kept; enabling a menu mounted
357
+ * without `slashMenu` offers every built-in command. Disabling closes an open slash menu. */
358
+ setSlashMenuEnabled(enabled: boolean): void;
359
+ /** Replaces the input preferences. A field left out takes its default. Throws `composition`
360
+ * during text composition. */
361
+ setTextInputPreferences(preferences: TextInputPreferences): void;
362
+ /** What the source and TXT surfaces follow when text is typed. */
363
+ private sourceTyping;
364
+ /** Replaces the display preferences. A field left out takes its default. They change only what
365
+ * the formatted surface shows: the document, revision, history, dirty state, snapshot, copy
366
+ * and print output stay as they are. Preferences that equal the current ones change and
367
+ * announce nothing. Throws `composition` during text composition. */
368
+ setDisplayPreferences(preferences: DisplayPreferences): void;
369
+ private currentDisplay;
370
+ private applyInputPolicy;
371
+ private publishCommandState;
372
+ private refreshFindSessions;
373
+ /** What the editor can do now, for enabling host controls. Unlike `snapshot`, it works during
374
+ * composition. */
375
+ commandState(expectedGeneration?: number): CommandState;
376
+ /** An image adapter shows and exports an inserted reference, and so does a file adapter. An RTF
377
+ * document holds no images. */
378
+ private get canInsertImages();
379
+ private historyInputPlugin;
380
+ private policyPlugin;
381
+ private get literalSurface();
382
+ /** `formatted` or `source`. A TXT document is always `source`. */
383
+ get editingMode(): EditingMode;
384
+ /** Switches between formatted and source editing. Returns false when the mode is already set, and
385
+ * for TXT and RTF, which each have one mode. */
386
+ setEditingMode(mode: EditingMode, expectedGeneration?: number): boolean;
387
+ private updateSurface;
388
+ /** Replaces the complete source as one undo step. Returns false for identical source. */
389
+ replaceSource(text: string, expectedGeneration?: number): boolean;
390
+ /** Returns whether a history step applied. */
391
+ undo(expectedGeneration?: number): boolean;
392
+ /** Returns whether a history step applied. */
393
+ redo(expectedGeneration?: number): boolean;
394
+ /** Drops the steps that `undo` took off the history, so `redo` has nothing to bring back. For a
395
+ * host that adds content after an undo and must not let a redo resurrect what was undone.
396
+ * Returns whether a redo was available. The document, selection, revision and undo steps stay
397
+ * as they are, and no `changed` event is sent. */
398
+ discardUndone(expectedGeneration?: number): boolean;
399
+ /** The complete current document, which is what a host saves. It throws rather than return a
400
+ * partial document. */
401
+ snapshot(expectedGeneration?: number): DocumentSnapshot<F>;
402
+ /**
403
+ * The loaded document converted to `format`, which must be offered, with what the conversion
404
+ * lost. It changes nothing: load the result as a new generation. Markdown converts to RTF and
405
+ * RTF to Markdown; the same format returns a copy. Throws `invalid-argument` for any other pair,
406
+ * and `preservation` when the result could not be saved or loaded again, such as a table with
407
+ * more than 1,000 columns or 100,000 cells in a conversion to RTF.
408
+ */
409
+ convertDocument(format: DocumentFormat, expectedGeneration?: number): ConvertedDocument;
410
+ /** The whole document as standalone HTML for printing. Rejects rather than return partial
411
+ * output. */
412
+ printableSnapshot(expectedGeneration?: number): Promise<PrintableDocument>;
413
+ /** Prepares the document or the selection for the native clipboard. Rejects with `stale-document`
414
+ * if the document changes first. */
415
+ clipboardSnapshot(scope?: ClipboardScope, expectedGeneration?: number): Promise<ClipboardOutput>;
416
+ /** Cancels the pending image paste without changing the document or editability. */
417
+ cancelPendingImports(expectedGeneration?: number): void;
418
+ /** Pastes content the host read from the native clipboard. Capture it once; don't read the
419
+ * clipboard again while this runs. */
420
+ paste(input: ClipboardInput, expectedGeneration?: number): Promise<void>;
421
+ private get pastesPlainText();
422
+ /** Shows or hides author comments. Presentation only: the revision, history and dirty state don't
423
+ * change. */
424
+ setCommentsVisible(visible: boolean): void;
425
+ /** Inserts `text` literally at the selection and returns whether the document changed. */
426
+ pasteAsPlainText(text: string, expectedGeneration?: number): boolean;
427
+ /** Whether an RTF edit that should have changed `before` was refused. */
428
+ private refusedRichEdit;
429
+ private insertPlainText;
430
+ /** Runs a table command and returns whether it applied. False in source and TXT modes, outside a
431
+ * table for commands that need one, inside a table for `insert`, for `addRowBefore` and
432
+ * `deleteRow` when the selection reaches the header row, at a boundary a move can't cross, and
433
+ * in an RTF document when a new row or column would make the table larger than RTF allows
434
+ * (1,000 columns or 100,000 cells). `commandState` reports the same answer. */
435
+ table(command: TableCommand, options?: TableOptions, expectedGeneration?: number): boolean;
436
+ /** Moves the blocks at the selection one place up or down in their list, quote, callout, footnote
437
+ * or note, as one undo step. Returns whether they moved: false in source and TXT modes, in a
438
+ * table, and when they are already first or last. */
439
+ moveBlock(direction: BlockMoveDirection, expectedGeneration?: number): boolean;
440
+ /** Cancels pending work, closes the editor's find sessions and releases the editor. It never
441
+ * rejects: a teardown step that fails does not stop the rest, and each failure goes to
442
+ * `events.error` as `internal`. Afterwards every other member throws `destroyed`. */
443
+ destroy(): Promise<void>;
444
+ private keymapPlugin;
445
+ private indentPlugin;
446
+ /**
447
+ * Whether an input would change text the person has not been shown, because a fold hides it or
448
+ * because the section opened since the last paint. Then nothing changes, the section is open and
449
+ * `hidden-text` is reported: a facade call throws or rejects with it, and any other input,
450
+ * which the editor consumes, goes to `events.error`. Paste, typing, keys, cut, drop and
451
+ * composition get no exemption, inside a facade call or out of it. A host operation that names
452
+ * its own targets, a history step, a source replacement and a block move, which carries its
453
+ * nodes unchanged, do.
454
+ */
455
+ private refusesHiddenText;
456
+ private dispatchTransaction;
457
+ /** Builds the editor in `root`. It has no document until `loadDocument`. Rejects with
458
+ * `invalid-argument` for a bad root, handler or option. The editor's type follows `formats`:
459
+ * without `rtf` among them, its documents are text. */
460
+ static mount<F extends DocumentFormat>(root: HTMLElement, events: EditorEvents<F>, options: EditorOptions<F> & {
461
+ formats: readonly F[];
462
+ }): Promise<InkKitEditor<F>>;
463
+ static mount(root: HTMLElement, events: EditorEvents, options?: EditorOptions): Promise<InkKitEditor>;
464
+ /** Replaces the document. The generation must be greater than the loaded one. A failed load
465
+ * changes nothing. */
466
+ loadDocument(document: DocumentInput<F>): void;
467
+ /** Moves focus off whichever of InkKit's text surfaces holds it; other focus is left alone. */
468
+ private releaseFocus;
469
+ /** Replaces the document with a newer version of it, keeping the selection, focus, scroll
470
+ * position and Markdown editing mode. With `expectedGeneration`, the loaded document must be
471
+ * that generation. */
472
+ reloadDocument(document: DocumentInput<F>, expectedGeneration?: number): void;
473
+ /** Names the scroll container and the host chrome that overlaps the editor. It replaces earlier
474
+ * settings. */
475
+ setViewport(options: ViewportOptions): void;
476
+ /** The visible rectangle, the insets and the scroll offsets. */
477
+ viewport(): ViewportSnapshot;
478
+ /** The readable text and selection. Ranges from it go stale when the document, its revision or
479
+ * the mode changes. */
480
+ textSnapshot(expectedGeneration?: number): ReadableTextSnapshot;
481
+ private validateTextRange;
482
+ /** Selects `range`. `focus` also focuses the editor and `reveal` scrolls the range into view;
483
+ * both default to false. Throws `invalid-range` for part of an image label, footnote label or
484
+ * callout title. */
485
+ selectTextRange(range: TextRange, options?: {
486
+ focus?: boolean;
487
+ reveal?: boolean;
488
+ }): void;
489
+ /** Replaces `range` with literal text as one undo step. Returns whether the text changed. */
490
+ replaceTextRange(range: TextRange, text: string): boolean;
491
+ /** Measures ranges in client coordinates, with one array of rectangles for each. It measures only
492
+ * when called. */
493
+ textRangesRects(ranges: readonly TextRange[]): readonly (readonly TextRect[])[];
494
+ /** The ranges of the snapshot that are inside the viewport now. */
495
+ visibleTextRanges(snapshotId: string): readonly TextRange[];
496
+ /** Scrolls `range` into the viewport, unfolding a callout that holds it. */
497
+ revealTextRange(range: TextRange): void;
498
+ private revealCurrentSelection;
499
+ private revealLiteralSelection;
500
+ private load;
501
+ /** Returns every non-overlapping match without changing selection, focus or highlights. */
502
+ searchMatches(text: string, expectedGeneration?: number): readonly TextRange[];
503
+ /** Selects the next match and returns whether there was one. */
504
+ find(text: string, expectedGeneration?: number): boolean;
505
+ /** Replaces the selected match, or the next one, and returns whether text changed. */
506
+ replace(search: string, replacement: string, expectedGeneration?: number): boolean;
507
+ /** Replaces every non-overlapping match once and returns how many. */
508
+ replaceAll(search: string, replacement: string, expectedGeneration?: number): number;
509
+ /**
510
+ * Opens a find session, which keeps a query and reports its match count and position to
511
+ * `onChange` whenever they change. Open one session per editor: the editor has one set of
512
+ * highlights.
513
+ */
514
+ findSession(onChange: (state: FindState) => void): FindSession;
515
+ private outlineContext;
516
+ /** The outline in document order. Entries go stale when the document changes. */
517
+ headings(expectedGeneration?: number): readonly Heading[];
518
+ /** Moves to `heading`. Returns true, or throws `stale-document` for a stale entry. */
519
+ navigateHeading(heading: Heading): boolean;
520
+ /** Buffered native typing: input rules apply as if its last character were typed after the rest. */
521
+ insertText(text: string, generation: number): boolean;
522
+ /**
523
+ * A key the host's native input received, run through InkKit's key handling. Returns whether
524
+ * InkKit handled it; when it did, the host must not also handle it natively.
525
+ */
526
+ keyDown(input: KeyInput, expectedGeneration: number): boolean;
527
+ /** Forgets the bracket pairs that pairing tracks, in every mode. */
528
+ private forgetPairs;
529
+ /** Focuses the editor's current text surface. A load never focuses the editor. */
530
+ focus(expectedGeneration?: number): void;
531
+ /** Moves focus off InkKit's text surfaces. Focus anywhere else, such as in a host control or a
532
+ * control InkKit draws, is left alone. */
533
+ blur(expectedGeneration?: number): void;
534
+ /**
535
+ * Resolves wiki links and file embeds again, all of them or those whose `target` is named, after
536
+ * something they point to changed. A file keeps its card until the new answer differs. Changes no
537
+ * document state, so it works in a read-only editor and during composition. Source and TXT modes
538
+ * draw no references; named file answers are invalidated and resolved when formatted mode returns.
539
+ */
540
+ refreshReferences(targets?: readonly string[], expectedGeneration?: number): void;
541
+ /** The hint under a link: only where a Mod-click opens it and a plain click does not, and not
542
+ * under a link that already has a tooltip of its own. */
543
+ private linkHint;
544
+ /** Selects the link a context-menu request landed on, then gives the host the link and where the
545
+ * pointer was. False when there is nothing to hand over, so the web view shows its own menu. */
546
+ private linkMenu;
547
+ private openSelectedLink;
548
+ /** Replaces every binding. Keys are in ProseMirror's notation. A key given to two shortcuts goes
549
+ * to the later one, in the order history, link opening, formatting, block moves, tables, so it lands the same
550
+ * way every time. A table binding passes a key it shares with a block move to the move outside
551
+ * a table. List indentation keys apply after all of these, and after the table keys the editor
552
+ * keeps for itself. */
553
+ setKeymap(keymap: Keymap): void;
554
+ /** Dropped files land as one paragraph per path at the drop point: in place of an empty block, after
555
+ * the top-level block otherwise, so a list or quote is not opened up by them. Throws
556
+ * `invalid-argument`, and changes nothing, when a path is empty. */
557
+ insertPaths(paths: string[], at: ClientPoint, expectedGeneration?: number): boolean;
558
+ /** Inserts images by reference, at the selection or the drop point `at`. Returns false when it
559
+ * does nothing. */
560
+ insertImages(images: ImageInsertion[], at?: ClientPoint, expectedGeneration?: number): boolean;
561
+ /** Adds images as the last blocks of the document and leaves everything else as it is: no focus,
562
+ * no scrolling, and the selection stays on the text it covered. For a host that attaches images
563
+ * to a document the person is not editing at that moment. Returns false when it does nothing. */
564
+ appendImages(images: ImageInsertion[], expectedGeneration?: number): boolean;
565
+ private chooseWiki;
566
+ private chooseSlash;
567
+ /** Returns whether the document or the marks the next typed text takes changed. */
568
+ format(command: FormatCommand, options?: FormatOptions, expectedGeneration?: number): boolean;
569
+ /**
570
+ * Refuses a link destination that is empty, that opens anything but a web, mail or phone address
571
+ * or a scheme the host listed, or, in Markdown, that the writer cannot save so that it reads back
572
+ * the same. In RTF, it also refuses what the rich text link rule refuses.
573
+ */
574
+ private checkDestination;
575
+ /**
576
+ * With a destination, sets the link: on the whole link that holds the caret or the selection,
577
+ * keeping its title, or else on the selection. A reference link's shared definition is edited
578
+ * instead. Without one, removes that whole link, or every link in the selection. Marks waiting
579
+ * for the next typed text stay waiting.
580
+ */
581
+ private link;
582
+ /** Changes the destination, and optionally the title, of the shared definition for `label`.
583
+ * Returns false when no definition has that label. */
584
+ editReferenceDefinition(label: string, destination: string, title?: string, expectedGeneration?: number): boolean;
585
+ /** Inserts a footnote reference, and a definition when the label has none, and returns whether
586
+ * it did: formatted Markdown only. */
587
+ insertFootnote(label?: string, expectedGeneration?: number): boolean;
588
+ /** Moves to the definition, or the first reference, of the footnote at the caret. Returns whether
589
+ * there was one. */
590
+ navigateFootnote(target: 'definition' | 'reference', expectedGeneration?: number): boolean;
591
+ }
592
+ export {};
@@ -0,0 +1 @@
1
+ export * from './core.js';