@withmarfa/inkkit 0.8.0-alpha.0 → 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.
package/dist/core.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as normalizeLinkAddress, r as InkKitEditor, s as InkKitError, t as canOpenLink } from "./chunks/core-CntI6pRW.js";
1
+ import { l as InkKitError, n as normalizeLinkAddress, r as InkKitEditor, t as canOpenLink } from "./chunks/core-DZmgpf9J.js";
2
2
  export { InkKitEditor, InkKitError, canOpenLink, normalizeLinkAddress };
package/dist/editor.d.ts CHANGED
@@ -18,7 +18,8 @@ export type Block = {
18
18
  } | {
19
19
  type: 'taskList';
20
20
  };
21
- /** `source` shows the Markdown or literal text in a textarea. A TXT document is always `source`. */
21
+ /** `source` shows the Markdown or literal text in a textarea. A TXT document is always `source`, and an
22
+ * RTF document always `formatted`. */
22
23
  export type EditingMode = 'source' | 'formatted';
23
24
  /** The formatting at the selection, for host toolbars. */
24
25
  export interface CaretState {
@@ -97,7 +98,17 @@ export interface DisplayPreferences {
97
98
  codeLineNumbers?: boolean;
98
99
  /** In formatted mode, how YAML front matter shows: `'source'`, its YAML as written, or
99
100
  * `'properties'`, a list of its properties that shows the YAML to edit when clicked or when the
100
- * caret moves into it. `'source'` unless set. */
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. */
101
112
  frontMatter?: 'source' | 'properties';
102
113
  }
103
114
  /** Mount options. Adapters, `formats`, `labels`, `linkSchemes` and `rendering` are fixed at mount;
@@ -115,6 +126,7 @@ export interface EditorOptions<F extends DocumentFormat = TextDocumentFormat> {
115
126
  wikiLinks?: WikiLinkAdapter;
116
127
  /** Defaults to true. See `setEditable`. */
117
128
  editable?: boolean;
129
+ /** See `setTextInputPreferences`. */
118
130
  textInput?: TextInputPreferences;
119
131
  /** See `setDisplayPreferences`. */
120
132
  display?: DisplayPreferences;
@@ -125,6 +137,7 @@ export interface EditorOptions<F extends DocumentFormat = TextDocumentFormat> {
125
137
  /** Schemes beyond `http`, `https`, `mailto` and `tel` that links may use, such as `things`.
126
138
  * Fixed at mount. */
127
139
  linkSchemes?: readonly string[];
140
+ /** What the editor draws besides text. Fixed at mount. */
128
141
  rendering?: {
129
142
  /** Defaults to true. */
130
143
  codeHighlighting?: boolean;
@@ -165,6 +178,7 @@ export interface CommandState extends DocumentVersion {
165
178
  insertFootnote: boolean;
166
179
  editReferenceDefinition: boolean;
167
180
  format: Record<FormatCommand, boolean>;
181
+ /** Whether `table(command)` applies at the selection now, for every command. */
168
182
  table: Record<TableCommand, boolean>;
169
183
  moveBlockUp: boolean;
170
184
  moveBlockDown: boolean;
@@ -179,13 +193,14 @@ export interface EditorEvents<F extends DocumentFormat = TextDocumentFormat> {
179
193
  /** A primary click with Mod on a link. Without it, links don't open. In an editor that can't be
180
194
  * edited, a plain click opens it too. */
181
195
  openLink?(href: string): void;
182
- /** The person asked for the context menu on a link, web or wiki. Inkkit selects the link, then
196
+ /** The person asked for the context menu on a link, web or wiki. InkKit selects the link, then
183
197
  * calls this with the link and the pointer position, so the host can show Open, Copy, Edit and
184
198
  * Remove. Without it, the web view's own menu shows. */
185
199
  linkMenu?(link: LinkMenuTarget, point: ClientPoint): void;
186
200
  /** The Copy button on a code block was clicked. Without this handler, no button is drawn. */
187
201
  copy?(text: string): void;
188
- /** A failure that no call is waiting for, such as one in an edit the person made. */
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. */
189
204
  error?(error: InkKitError): void;
190
205
  /** The person copied or cut a selection that holds an image or a diagram. Resolve after the
191
206
  * native clipboard write succeeds; a cut removes the selection only then. */
@@ -281,7 +296,8 @@ export declare class InkKitEditor<F extends DocumentFormat = TextDocumentFormat>
281
296
  * changes nothing and sends nothing. An edit that the preservation check refuses during the call
282
297
  * is thrown, not sent to `events.error`. When the call fails with a refusal or another coded
283
298
  * failure, every step it took is undone: the document, selection and history return to their
284
- * state before the call, and the state events it raised are dropped. An `internal` failure keeps
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
285
301
  * what happened and sends its events, since the editor's state can no longer be trusted to match.
286
302
  * Anything else thrown arrives as an `InkKitError`. A call made inside another runs as part of
287
303
  * it. Promises reject instead of throwing.
@@ -294,14 +310,27 @@ export declare class InkKitEditor<F extends DocumentFormat = TextDocumentFormat>
294
310
  /** What a failed call puts back. */
295
311
  private restorePoint;
296
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;
297
323
  /** Calls the editor makes to its own public methods, to publish command state, keep the selection
298
324
  * in view or finish another method's work. Diagnostics record what the host or person did, so
299
325
  * these run without operation events. */
300
326
  private unrecorded;
301
327
  /** Reports a refused edit to the facade call that made it, or else to `events.error`. */
302
328
  private refuse;
303
- /** Reports a failure no call is waiting for. */
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. */
304
331
  private report;
332
+ /** Delivers a failure to `events.error`, destroyed or not. */
333
+ private deliverError;
305
334
  /** Runs a host operation that names the text it changes, such as a replacement, which may
306
335
  * therefore change text a fold hides. */
307
336
  private naming;
@@ -320,7 +349,9 @@ export declare class InkKitEditor<F extends DocumentFormat = TextDocumentFormat>
320
349
  get editable(): boolean;
321
350
  /** Turns editing on or off for both surfaces. Throws `composition` during text composition. */
322
351
  setEditable(editable: boolean): void;
323
- /** Supplies native host activation for selection presentation. Null restores browser detection. */
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. */
324
355
  setHostActive(active: boolean | null): void;
325
356
  /** Turns the slash menu on or off. Commands chosen at mount are kept; enabling a menu mounted
326
357
  * without `slashMenu` offers every built-in command. Disabling closes an open slash menu. */
@@ -351,7 +382,7 @@ export declare class InkKitEditor<F extends DocumentFormat = TextDocumentFormat>
351
382
  /** `formatted` or `source`. A TXT document is always `source`. */
352
383
  get editingMode(): EditingMode;
353
384
  /** Switches between formatted and source editing. Returns false when the mode is already set, and
354
- * for TXT. */
385
+ * for TXT and RTF, which each have one mode. */
355
386
  setEditingMode(mode: EditingMode, expectedGeneration?: number): boolean;
356
387
  private updateSurface;
357
388
  /** Replaces the complete source as one undo step. Returns false for identical source. */
@@ -371,7 +402,9 @@ export declare class InkKitEditor<F extends DocumentFormat = TextDocumentFormat>
371
402
  /**
372
403
  * The loaded document converted to `format`, which must be offered, with what the conversion
373
404
  * lost. It changes nothing: load the result as a new generation. Markdown converts to RTF and
374
- * RTF to Markdown; the same format returns a copy. Throws `invalid-argument` for any other pair.
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.
375
408
  */
376
409
  convertDocument(format: DocumentFormat, expectedGeneration?: number): ConvertedDocument;
377
410
  /** The whole document as standalone HTML for printing. Rejects rather than return partial
@@ -395,14 +428,18 @@ export declare class InkKitEditor<F extends DocumentFormat = TextDocumentFormat>
395
428
  private refusedRichEdit;
396
429
  private insertPlainText;
397
430
  /** Runs a table command and returns whether it applied. False in source and TXT modes, outside a
398
- * table for commands that need one, and at a boundary a move can't cross. */
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. */
399
435
  table(command: TableCommand, options?: TableOptions, expectedGeneration?: number): boolean;
400
436
  /** Moves the blocks at the selection one place up or down in their list, quote, callout, footnote
401
437
  * or note, as one undo step. Returns whether they moved: false in source and TXT modes, in a
402
438
  * table, and when they are already first or last. */
403
439
  moveBlock(direction: BlockMoveDirection, expectedGeneration?: number): boolean;
404
- /** Cancels pending work and releases the editor. It never rejects. Afterwards every other member
405
- * throws `destroyed`. */
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`. */
406
443
  destroy(): Promise<void>;
407
444
  private keymapPlugin;
408
445
  private indentPlugin;
@@ -442,6 +479,9 @@ export declare class InkKitEditor<F extends DocumentFormat = TextDocumentFormat>
442
479
  * the mode changes. */
443
480
  textSnapshot(expectedGeneration?: number): ReadableTextSnapshot;
444
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. */
445
485
  selectTextRange(range: TextRange, options?: {
446
486
  focus?: boolean;
447
487
  reveal?: boolean;
@@ -486,6 +526,7 @@ export declare class InkKitEditor<F extends DocumentFormat = TextDocumentFormat>
486
526
  keyDown(input: KeyInput, expectedGeneration: number): boolean;
487
527
  /** Forgets the bracket pairs that pairing tracks, in every mode. */
488
528
  private forgetPairs;
529
+ /** Focuses the editor's current text surface. A load never focuses the editor. */
489
530
  focus(expectedGeneration?: number): void;
490
531
  /** Moves focus off InkKit's text surfaces. Focus anywhere else, such as in a host control or a
491
532
  * control InkKit draws, is left alone. */
@@ -511,7 +552,8 @@ export declare class InkKitEditor<F extends DocumentFormat = TextDocumentFormat>
511
552
  * keeps for itself. */
512
553
  setKeymap(keymap: Keymap): void;
513
554
  /** Dropped files land as one paragraph per path at the drop point: in place of an empty block, after
514
- * the top-level block otherwise, so a list or quote is not opened up by them. */
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. */
515
557
  insertPaths(paths: string[], at: ClientPoint, expectedGeneration?: number): boolean;
516
558
  /** Inserts images by reference, at the selection or the drop point `at`. Returns false when it
517
559
  * does nothing. */
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as normalizeLinkAddress, o as registerDiagram, r as InkKitEditor, s as InkKitError, t as canOpenLink } from "./chunks/core-CntI6pRW.js";
1
+ import { c as registerDiagram, l as InkKitError, n as normalizeLinkAddress, r as InkKitEditor, t as canOpenLink } from "./chunks/core-DZmgpf9J.js";
2
2
  //#region node_modules/.pnpm/dompurify@3.4.17/node_modules/dompurify/dist/purify.es.mjs
3
3
  /*! @license DOMPurify 3.4.17 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.17/LICENSE */
4
4
  function _OverloadYield(e, d) {
package/dist/style.css CHANGED
@@ -1052,24 +1052,6 @@
1052
1052
  color: var(--_inkkit-text);
1053
1053
  }
1054
1054
 
1055
- /* Copy waits out of sight until the pointer is over the block or focus, the caret included, is in
1056
- it. It stays focusable, so Tab reaches it and shows it. A device with no hover shows it always. */
1057
- .inkkit-root .ProseMirror pre .inkkit-copy {
1058
- opacity: 0;
1059
- }
1060
- .inkkit-root .ProseMirror pre:hover .inkkit-copy,
1061
- .inkkit-root .ProseMirror pre:focus-within .inkkit-copy,
1062
- .inkkit-root .ProseMirror pre[data-inkkit-code-active] .inkkit-copy,
1063
- .inkkit-root .ProseMirror pre .inkkit-copy:focus-visible,
1064
- .inkkit-root .ProseMirror pre .inkkit-copy[data-copied] {
1065
- opacity: 1;
1066
- }
1067
- @media (hover: none) {
1068
- .inkkit-root .ProseMirror pre .inkkit-copy {
1069
- opacity: 1;
1070
- }
1071
- }
1072
-
1073
1055
  .inkkit-root .ProseMirror pre > code {
1074
1056
  display: block;
1075
1057
  overflow-x: auto;
@@ -1396,6 +1378,13 @@
1396
1378
  border: 1px dashed var(--_inkkit-rule);
1397
1379
  }
1398
1380
 
1381
+ /* An HTML block is source that is not rendered, not Markdown InkKit could
1382
+ not format: no outline, and the muted colour of inline HTML. */
1383
+ .inkkit-root .ProseMirror .inkkit-literal-markdown.inkkit-html-source {
1384
+ border-color: transparent;
1385
+ color: var(--_inkkit-muted);
1386
+ }
1387
+
1399
1388
  /* Inline HTML shows its source, quietly, inside formatted text. */
1400
1389
  .inkkit-root .ProseMirror .inkkit-inline-source {
1401
1390
  font-family: var(--_inkkit-mono);
@@ -1618,6 +1607,8 @@
1618
1607
 
1619
1608
  .inkkit-root .ProseMirror .inkkit-callout-title {
1620
1609
  color: color-mix(in srgb, var(--_inkkit-callout-color) 80%, CanvasText);
1610
+ /* Lighter than bold text, so bold inside a title shows. */
1611
+ font-weight: 600;
1621
1612
  }
1622
1613
 
1623
1614
  .inkkit-root .ProseMirror [data-inkkit-callout='TIP'],
@@ -2027,7 +2018,7 @@
2027
2018
  position: absolute;
2028
2019
  top: 4px;
2029
2020
  z-index: 2;
2030
- right: 34px;
2021
+ right: 30px;
2031
2022
  font:
2032
2023
  calc(var(--_inkkit-font-size) * 0.8)/1.4 -apple-system,
2033
2024
  system-ui,
@@ -2044,13 +2035,13 @@
2044
2035
  .inkkit-root .inkkit-code-language {
2045
2036
  display: inline-flex;
2046
2037
  align-items: center;
2047
- gap: 5px;
2038
+ gap: 4px;
2048
2039
  height: 22px;
2049
- padding: 0 6px;
2040
+ padding: 0 0 0 6px;
2050
2041
  border: 0;
2051
2042
  border-radius: 5px;
2052
2043
  background: transparent;
2053
- color: color-mix(in srgb, var(--_inkkit-text) 50%, var(--_inkkit-muted));
2044
+ color: var(--_inkkit-muted);
2054
2045
  font: inherit;
2055
2046
  cursor: pointer;
2056
2047
  }
@@ -2065,8 +2056,14 @@
2065
2056
  stroke-linecap: round;
2066
2057
  stroke-linejoin: round;
2067
2058
  }
2059
+ .inkkit-root .inkkit-code-language svg {
2060
+ width: 10px;
2061
+ height: 10px;
2062
+ stroke-width: 1.4;
2063
+ }
2068
2064
  .inkkit-root .inkkit-code-language:hover {
2069
2065
  background: color-mix(in srgb, CanvasText 7%, transparent);
2066
+ color: var(--_inkkit-text);
2070
2067
  }
2071
2068
  .inkkit-root .inkkit-code-language:focus-visible,
2072
2069
  .inkkit-root .inkkit-copy:focus-visible,
@@ -2132,6 +2129,7 @@
2132
2129
  .inkkit-root .inkkit-code-wrap[aria-pressed='true'],
2133
2130
  .inkkit-root .inkkit-code-language[aria-expanded='true'] {
2134
2131
  background: color-mix(in srgb, CanvasText 10%, transparent);
2132
+ color: var(--_inkkit-text);
2135
2133
  }
2136
2134
  .inkkit-root .inkkit-code-language[aria-expanded='true'] svg {
2137
2135
  transform: rotate(180deg);
package/dist/types.d.ts CHANGED
@@ -5,7 +5,7 @@ export type DocumentFormat = 'md' | 'txt' | 'rtf';
5
5
  * `formats` has only these. */
6
6
  export type TextDocumentFormat = 'md' | 'txt';
7
7
  /** What saving promises for a format. `exact` saves the file exactly. `structure` keeps the
8
- * structure and marks and replaces fonts, colors and sizes with Inkkit's style. `lossy` is a
8
+ * structure and marks and replaces fonts, colors and sizes with InkKit's style. `lossy` is a
9
9
  * conversion that drops something and says what. */
10
10
  export type FormatPromise = 'exact' | 'structure' | 'lossy';
11
11
  /** A format the host offered at mount, with what saving it promises. */
@@ -58,12 +58,14 @@ export type RichTextBlock = {
58
58
  items: RichTextListItem[];
59
59
  } | {
60
60
  type: 'table';
61
- /** Every row has the same number of cells. */
61
+ /** Every row has the same number of cells: at most 1,000, and at most 100,000 in the table. */
62
62
  rows: RichTextTableCell[][];
63
63
  };
64
+ /** A list item: one paragraph, then only lists. */
64
65
  export interface RichTextListItem {
65
66
  blocks: RichTextBlock[];
66
67
  }
68
+ /** A table cell, which holds one paragraph's inline content. */
67
69
  export interface RichTextTableCell {
68
70
  content: RichTextInline[];
69
71
  }
@@ -90,6 +92,7 @@ export interface FormatLoss {
90
92
  }
91
93
  /** The closed list of what a conversion can lose. The API reference describes each one. */
92
94
  export declare const formatLossCodes: readonly ['heading', 'code-block', 'diagram', 'quote', 'callout', 'task', 'rule', 'footnote', 'comment', 'highlight', 'image', 'file', 'wiki-link', 'literal', 'link', 'table-alignment', 'list-start', 'list-item-blocks', 'list-depth', 'link-underline', 'invalid-character', 'alignment', 'mark-spaces', 'empty-line'];
95
+ /** A kind of content a conversion can lose. */
93
96
  export type FormatLossCode = (typeof formatLossCodes)[number];
94
97
  /** A document converted to another format, for the host to load as a new generation. */
95
98
  export type ConvertedDocument = {
@@ -121,6 +124,7 @@ export interface RichTextDocumentSnapshot extends RichTextDocumentInput, Documen
121
124
  }
122
125
  /** The closed list of failure codes. The API reference describes each one. */
123
126
  export declare const editorErrorCodes: readonly ['not-ready', 'destroyed', 'stale-document', 'composition', 'operation-pending', 'read-only', 'invalid-argument', 'invalid-range', 'hidden-text', 'preservation', 'image-unavailable', 'image-unsupported', 'diagram-unavailable', 'file-unavailable', 'clipboard-unavailable', 'slash-command-failed', 'internal'];
127
+ /** The kind of failure an `InkKitError` reports. */
124
128
  export type EditorErrorCode = (typeof editorErrorCodes)[number];
125
129
  /** Every failure InkKit reports. Hosts branch on `code`; `message` is for logs. When the failure
126
130
  * started elsewhere, such as in an adapter, the host clipboard or the renderer, `cause` holds the
@@ -161,7 +165,7 @@ export interface ImageAdapter {
161
165
  }>;
162
166
  /** The stored bytes and type of `reference`, for portable clipboard and print output. */
163
167
  exportImage(reference: string, context: DocumentContext): Promise<PortableImage>;
164
- /** Called for a context-menu request on an image. Inkkit selects the image first. */
168
+ /** Called for a context-menu request on an image. InkKit selects the image first. */
165
169
  contextMenu?(reference: string, point: ClientPoint, context: DocumentContext): void;
166
170
  }
167
171
  /** A wiki link as authored. */
@@ -198,7 +202,7 @@ export interface WikiLinkAdapter {
198
202
  /** Called by Mod-click, and by Enter or Space on the focused link. */
199
203
  open(reference: WikiLinkReference, context: DocumentContext): void;
200
204
  }
201
- /** A link a person asked a menu for, as `events.linkMenu` receives it. Inkkit selects the link
205
+ /** A link a person asked a menu for, as `events.linkMenu` receives it. InkKit selects the link
202
206
  * first, so `format('link', { destination })` changes a web link's address and `format('link')`
203
207
  * removes it, and `range` names the same text. */
204
208
  export type LinkMenuTarget = {
@@ -210,9 +214,9 @@ export type LinkMenuTarget = {
210
214
  } & ({
211
215
  kind: 'web';
212
216
  /** The destination as the document holds it. For a reference link, the address its definition
213
- * gives. It can be empty, or use a scheme that Inkkit does not open. */
217
+ * gives. It can be empty, or use a scheme that InkKit does not open. */
214
218
  href: string;
215
- /** Whether Mod-click would open it: not empty, relative, or on a scheme Inkkit opens. Only an
219
+ /** Whether Mod-click would open it: not empty, relative, or on a scheme InkKit opens. Only an
216
220
  * openable address goes to `events.openLink`. */
217
221
  openable: boolean;
218
222
  } | {
@@ -398,7 +402,8 @@ export interface FindSession {
398
402
  /** Sets the query, highlights its matches and selects one. A new query selects the first match
399
403
  * at or after the selection, or the last one before it with `direction: 'previous'`. With the
400
404
  * same query, the selection moves to the next or previous match and wraps at the ends; without
401
- * a direction, a selection on a match stays there. Returns whether there is a match. */
405
+ * a direction, a selection on a match stays there. Returns whether there is a match. Throws
406
+ * `invalid-argument` for any `direction` but `next`, `previous`, `null` or omitted. */
402
407
  find(query: string, options?: {
403
408
  direction?: 'next' | 'previous';
404
409
  }, expectedGeneration?: number): boolean;
@@ -413,7 +418,8 @@ export interface FindSession {
413
418
  replaceAll(query: string, replacement: string, expectedGeneration?: number): number;
414
419
  /** Clears the query and the highlights. */
415
420
  clear(expectedGeneration?: number): void;
416
- /** Stops the session: it clears the highlights and its handler is not called again. */
421
+ /** Stops the session: it clears the highlights and its handler is not called again. Closing
422
+ * twice, or after the editor is destroyed, does nothing. */
417
423
  close(): void;
418
424
  }
419
425
  /** A rectangle in CSS pixels in the web view's client coordinate space. */
@@ -432,11 +438,14 @@ export interface ViewportInsets {
432
438
  bottom: number;
433
439
  left: number;
434
440
  }
441
+ /** Where the editor scrolls, and the edges your own interface covers, for `setViewport`. */
435
442
  export interface ViewportOptions {
436
443
  /** The element that scrolls. It must be the root or an ancestor of it. Defaults to the root. */
437
444
  scrollContainer?: HTMLElement;
445
+ /** CSS pixels at each edge that floating host controls cover. */
438
446
  insets?: Partial<ViewportInsets>;
439
447
  }
448
+ /** The editor's viewport, as `viewport()` reports it. */
440
449
  export interface ViewportSnapshot {
441
450
  /** The visible area, less the insets. */
442
451
  rect: TextRect;
@@ -529,7 +538,7 @@ export interface Heading extends Readonly<DocumentVersion> {
529
538
  readonly level: number;
530
539
  readonly text: string;
531
540
  }
532
- /** A command for `table`. `insert` makes a table; the others work on the table at the selection. */
541
+ /** A command for `table`. `insert` makes a table where the selection is not in one; the others work on the table at the selection. */
533
542
  export type TableCommand = 'insert' | 'addRowBefore' | 'addRowAfter' | 'addColumnBefore' | 'addColumnAfter' | 'deleteRow' | 'deleteColumn' | 'deleteTable' | 'alignLeft' | 'alignCenter' | 'alignRight' | 'moveRowUp' | 'moveRowDown' | 'moveColumnLeft' | 'moveColumnRight' | 'sortRows' | 'exit';
534
543
  /** Where `moveBlock` moves the blocks at the selection. */
535
544
  export type BlockMoveDirection = 'up' | 'down';
@@ -546,15 +555,23 @@ export interface TableOptions {
546
555
  /** `sortRows`. Defaults to `text`. */
547
556
  comparison?: 'text' | 'number';
548
557
  }
558
+ /** A built-in slash menu command. */
549
559
  export type SlashCommandName = 'heading1' | 'heading2' | 'heading3' | 'bulletList' | 'orderedList' | 'taskList' | 'quote' | 'codeBlock' | 'table' | 'callout' | 'divider' | 'diagram';
560
+ /** A slash menu command the host adds. */
550
561
  export interface SlashCommand {
562
+ /** The name shown in the menu, which typing after `/` matches. */
551
563
  name: string;
564
+ /** More words that typing after `/` matches. */
552
565
  keywords?: readonly string[];
553
566
  /** Returns Markdown to insert in place of the trigger. Undefined cancels the action. */
554
567
  action(context: DocumentContext): string | undefined | Promise<string | undefined>;
555
568
  }
569
+ /** The menu of blocks offered when the person types `/` on an empty line. */
556
570
  export interface SlashMenuOptions {
571
+ /** Defaults to false. See `setSlashMenuEnabled`. */
557
572
  enabled?: boolean;
573
+ /** The built-in commands to offer, in their fixed order. Defaults to all. */
558
574
  commands?: readonly SlashCommandName[];
575
+ /** Commands of your own, offered after the built-in ones. */
559
576
  customCommands?: readonly SlashCommand[];
560
577
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withmarfa/inkkit",
3
- "version": "0.8.0-alpha.0",
3
+ "version": "0.8.0-alpha.1",
4
4
  "description": "A preserving Markdown editor for offline web views and the web",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -40,9 +40,6 @@
40
40
  "registry": "https://registry.npmjs.org/"
41
41
  },
42
42
  "packageManager": "pnpm@11.0.9",
43
- "engines": {
44
- "node": ">=26"
45
- },
46
43
  "scripts": {
47
44
  "build": "node scripts/clean-build.mjs && tsc -p tsconfig.build.json && vite build --config vite.package.config.ts && node scripts/build-host-notices.ts && node scripts/finish-build.mjs",
48
45
  "typecheck": "tsc --noEmit",
@@ -51,15 +48,13 @@
51
48
  "format:check": "prettier --check .",
52
49
  "dev": "vite playground",
53
50
  "build:playground": "vite build playground --config vite.config.ts",
54
- "test:docs": "node --test scripts/api-docs/*.test.mjs && node scripts/check-api-docs.mjs",
51
+ "test:docs": "node site/scripts/reference.mjs --check && node site/scripts/check-samples.mjs",
55
52
  "test:package": "node scripts/test-package.mjs",
56
53
  "check": "pnpm typecheck && pnpm test && pnpm build && pnpm test:docs && pnpm test:package",
57
54
  "test:browser": "playwright test --project=chromium",
58
55
  "test:playground": "playwright test --config playwright.playground.config.ts --project=chromium",
59
56
  "measure:browser": "playwright test --config playwright.measure.config.ts",
60
- "test:built-playground": "playwright test --config playwright.built.config.ts",
61
- "build:docs-demo": "pnpm build && node scripts/build-docs-demo.mjs",
62
- "test:docs-demo": "playwright test --config playwright.docs-demo.config.ts"
57
+ "test:built-playground": "playwright test --config playwright.built.config.ts"
63
58
  },
64
59
  "devDependencies": {
65
60
  "@milkdown/kit": "7.22.3",
@@ -1,17 +0,0 @@
1
- import type { Ctx } from '@milkdown/kit/ctx';
2
- import { type Slice, type Node as ProseNode } from '@milkdown/kit/prose/model';
3
- import { type FormatLoss, type RichTextDocument } from '../types';
4
- /** A formatted Markdown document as rich text, with what RTF could not hold. */
5
- export declare function markdownToRichText(doc: ProseNode): {
6
- document: RichTextDocument;
7
- lost: readonly FormatLoss[];
8
- };
9
- /** A rich text document as Markdown, with what Markdown could not hold: alignment. Underline,
10
- * superscript and subscript are written as `<u>`, `<sup>` and `<sub>`. */
11
- export declare function richTextToMarkdown(ctx: Ctx, document: RichTextDocument): {
12
- text: string;
13
- lost: readonly FormatLoss[];
14
- };
15
- /** Markdown for content copied from a rich text document. Unlike a conversion it reports no
16
- * losses and isn't read back: a copy may lose alignment. */
17
- export declare function richContentMarkdown(ctx: Ctx, content: Slice): string;
@@ -1,8 +0,0 @@
1
- import type { DocumentFormat } from '../types';
2
- import type { FormatHandler } from './types';
3
- export type { FormatHandler, FormatSource, FormatOutput, SavedText, } from './types';
4
- /** Every format Inkkit can open. */
5
- export declare const documentFormats: readonly ["md", "txt", "rtf"];
6
- /** The formats a host is offered when it chooses none. */
7
- export declare const defaultFormats: readonly ["md", "txt"];
8
- export declare const formatHandlers: Readonly<Record<DocumentFormat, FormatHandler>>;
@@ -1,4 +0,0 @@
1
- import type { FormatHandler } from './types';
2
- /** Markdown, read and saved through source preservation, so an unedited file saves exactly and an
3
- * edit changes only the bytes it touched. */
4
- export declare const markdownFormat: FormatHandler;
@@ -1,11 +0,0 @@
1
- import { Slice } from '@milkdown/kit/prose/model';
2
- import type { EditorState } from '@milkdown/kit/prose/state';
3
- import type { ClipboardInput, RichTextBlock } from '../types';
4
- /** Blocks for pasted HTML. */
5
- export declare function htmlBlocks(html: string, schemes: ReadonlySet<string>): RichTextBlock[];
6
- /**
7
- * The slice that `input` pastes into an RTF document at the selection. Explicit Markdown pastes as
8
- * its text, unparsed; HTML keeps what RTF can hold; plain text gives a paragraph for each line.
9
- * Plain text takes the marks of the text it replaces, as typing would.
10
- */
11
- export declare function richTextPaste(input: ClipboardInput, state: EditorState, schemes: ReadonlySet<string>): Slice;
@@ -1,56 +0,0 @@
1
- import type { RichTextBlock, RichTextDocument, RichTextInline, RichTextMark } from '../types';
2
- /** The deepest list nesting RTF can hold (`\ilvl` 0 to 8). */
3
- export declare const maximumListDepth = 9;
4
- /** The largest first number of an ordered list that RTF writes and reads back unchanged, as
5
- * measured with the host's converter. */
6
- export declare const maximumListStart = 2147483647;
7
- /** Why a run cannot hold `text`, or undefined. Loading and editing share the rule. */
8
- export declare function textProblem(text: string): string | undefined;
9
- /** Why `href` cannot be a link's address, or undefined. Any address that is not empty and holds
10
- * no control character is kept, as the host's converter keeps it; loading, editing, paste and the
11
- * converter share the rule. Edits and paste also apply Inkkit's link safety. */
12
- export declare function linkProblem(href: string): string | undefined;
13
- /** The canonical order of marks. */
14
- export declare const markRank: {
15
- readonly bold: 0;
16
- readonly italic: 1;
17
- readonly underline: 2;
18
- readonly strikethrough: 3;
19
- readonly superscript: 4;
20
- readonly subscript: 5;
21
- readonly code: 6;
22
- readonly link: 7;
23
- };
24
- type Path = string;
25
- /** Collects inline content in canonical form: adjacent runs with equal marks merge, and each run
26
- * is NFC after merging, because joining two NFC strings can leave a sequence that composes. */
27
- export declare class InlineBuilder {
28
- readonly content: RichTextInline[];
29
- private marksKey?;
30
- text(text: string, marks: readonly RichTextMark[]): void;
31
- break(): void;
32
- finish(): RichTextInline[];
33
- }
34
- /** Marks in canonical order. A link's run never also has underline: a link's underline is how it
35
- * is drawn, so RTF readers report it on every link. */
36
- export declare function canonicalMarks(marks: readonly RichTextMark[]): RichTextMark[];
37
- /**
38
- * Checks `value` as a version 1 document and returns its canonical form: marks sorted, a link's
39
- * underline removed, adjacent equal runs merged, runs in NFC, and `start` of 1 left out. Throws
40
- * `invalid-argument` naming the first problem, under `path`.
41
- */
42
- export declare function readRichTextDocument(value: unknown, path: Path): RichTextDocument;
43
- /** The text that stands for a canonical document inside the editor: its JSON. Two documents are
44
- * the same exactly when their texts are. */
45
- export declare function richTextText(document: RichTextDocument): string;
46
- /** The document a text from `richTextText` stands for, as a new object. */
47
- export declare function richTextFromText(text: string): RichTextDocument;
48
- /** Text from outside a document, such as a paste or another format, as canonical runs: a line or
49
- * paragraph separator inside a paragraph becomes a line break, and characters RTF cannot hold as
50
- * text become U+FFFD, so that no character disappears. */
51
- export declare function appendText(builder: InlineBuilder, text: string, marks: readonly RichTextMark[]): void;
52
- /** Typed or pasted text as paragraphs: each paragraph separator ends one, including a final one,
53
- * so inserting `'a\n'` leaves the caret in a new paragraph. A line separator is a line break.
54
- * Unlike the host's `RichTextDocument(plainText:)`, which reads a file, nothing is trimmed. */
55
- export declare function textBlocks(text: string): RichTextBlock[];
56
- export {};
@@ -1,23 +0,0 @@
1
- import type { Mark, Node as ProseNode, Schema } from '@milkdown/kit/prose/model';
2
- import type { EditorState, Transaction } from '@milkdown/kit/prose/state';
3
- import { type RichTextBlock, type RichTextDocument } from '../types';
4
- /** The editor block for a rich text block. Its text also takes `around`, the marks of text that a
5
- * paste replaces. */
6
- export declare function proseBlock(schema: Schema, block: RichTextBlock, around?: readonly Mark[]): ProseNode;
7
- /** The editor document for a canonical rich text document. */
8
- export declare function richTextToProse(schema: Schema, document: RichTextDocument): ProseNode;
9
- /** The canonical rich text document for an editor document. Throws `preservation` when the
10
- * document holds something RTF cannot. The editor always holds a block, so its one empty
11
- * paragraph is an empty document when `emptyAsNone`, as it is when the document loaded empty. */
12
- export declare function proseToRichText(doc: ProseNode, emptyAsNone?: boolean): RichTextDocument;
13
- /** Whether the document a transaction reaches holds only what RTF can, read in the part it
14
- * changed and that part's ancestors. */
15
- export declare function richTextAllows(tr: Transaction, before: EditorState): boolean;
16
- /** The ranges of runs that have both a link and underline, which canonical form removes the
17
- * underline from, in the part of `doc` from `from` to `to`. */
18
- export declare function linkedUnderlines(doc: ProseNode, from: number, to: number): {
19
- from: number;
20
- to: number;
21
- }[];
22
- /** Whether every character from `from` to `to`, or the caret's marks, is in a link. */
23
- export declare function inLink(state: EditorState): boolean;
@@ -1,5 +0,0 @@
1
- import type { FormatHandler } from './types';
2
- /** Rich text, which the host converts to and from RTF. The editor holds the canonical JSON as the
3
- * document's text. It reaches no Markdown parsing or preservation;
4
- * `test/formats/boundary.test.ts` checks its imports. */
5
- export declare const richTextFormat: FormatHandler;
@@ -1,4 +0,0 @@
1
- import type { FormatHandler } from './types';
2
- /** Literal text, edited only on the literal surface and saved as typed. It reaches no Markdown
3
- * parsing or preservation; `test/formats/boundary.test.ts` checks its imports. */
4
- export declare const textFormat: FormatHandler;