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

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,23 @@
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;
@@ -0,0 +1,5 @@
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;
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1,120 @@
1
+ import type { Ctx } from '@milkdown/kit/ctx';
2
+ import type { Fragment, Node as ProseNode, Slice } from '@milkdown/kit/prose/model';
3
+ import type { EditorState, Transaction } from '@milkdown/kit/prose/state';
4
+ import type { DiagramStore } from '../mermaid';
5
+ import type { ClipboardInput, ClipboardOutput, DocumentContext, DocumentFormat, DocumentVersion, EditorLabels, FileAdapter, FormatPromise, ImageAdapter, PrintableDocument } from '../types';
6
+ /** The current document as the editor holds it: its text, which for RTF is the canonical JSON of
7
+ * its `RichTextDocument`. */
8
+ export interface SavedText extends DocumentVersion {
9
+ readonly format: DocumentFormat;
10
+ readonly text: string;
11
+ readonly dirty: boolean;
12
+ }
13
+ /** What a format whose document is not source text adds to formatted editing. */
14
+ export interface RichTextBehaviour {
15
+ /** Whether the document that `tr` reaches from `before` holds only what the format can. */
16
+ allows(tr: Transaction, before: EditorState): boolean;
17
+ /** Runs in `from` to `to` that hold both a link and underline, which the format cannot keep. */
18
+ linkedUnderlines(doc: ProseNode, from: number, to: number): {
19
+ from: number;
20
+ to: number;
21
+ }[];
22
+ /** Whether the selection is all link text, where underline does nothing. */
23
+ inLink(state: EditorState): boolean;
24
+ /** The slice a formatted paste inserts. */
25
+ paste(input: ClipboardInput, state: EditorState, linkSchemes: ReadonlySet<string>): Slice;
26
+ /** What copying the selection writes. */
27
+ copy(state: EditorState, linkSchemes: ReadonlySet<string>): {
28
+ text: string;
29
+ html: string;
30
+ };
31
+ }
32
+ /** What a format keeps from reading a text, to save edits to the document it read. */
33
+ export interface FormatSource {
34
+ /** The document read from the text. */
35
+ readonly baseline: ProseNode;
36
+ /** The text to save for `doc`, which is `baseline` after edits. `carried` holds nodes that block
37
+ * moves carried. Absent for a format that saves its literal surface's text. */
38
+ serialize?(doc: ProseNode, carried?: WeakSet<ProseNode>): string;
39
+ }
40
+ /** What a format's output reads from the editor. Each call reads the current value, and
41
+ * `context()` names a new operation, so call it only when an adapter needs it. */
42
+ export interface FormatOutput {
43
+ ctx(): Ctx;
44
+ element(): HTMLTextAreaElement;
45
+ sourceMode(): boolean;
46
+ exportDocument(text: string): ProseNode;
47
+ images(): ImageAdapter | undefined;
48
+ files(): FileAdapter | undefined;
49
+ linkSchemes(): ReadonlySet<string>;
50
+ context(): DocumentContext;
51
+ diagrams(): DiagramStore;
52
+ root(): HTMLElement;
53
+ /** Markdown for rich content copied from a document that is not Markdown. A copy may lose what
54
+ * Markdown can't hold, such as alignment. */
55
+ richTextMarkdown(content: Slice): string;
56
+ remember<T extends {
57
+ text: string;
58
+ html: string;
59
+ }>(output: T, markdown: string, content: Fragment, privateSource?: boolean): T;
60
+ }
61
+ export type PrintableContent = Pick<PrintableDocument, 'html' | 'styles' | 'assets' | 'warnings'>;
62
+ export interface PrintRequest {
63
+ /** The current text. */
64
+ readonly text: string;
65
+ /** The document to print, which holds source typed but not yet settled. */
66
+ readonly doc: ProseNode;
67
+ readonly signal: AbortSignal;
68
+ readonly output: FormatOutput;
69
+ }
70
+ export interface ClipboardRequest {
71
+ readonly snapshot: SavedText;
72
+ /** The whole document, rather than the selection. */
73
+ readonly all: boolean;
74
+ readonly version: DocumentVersion;
75
+ readonly output: FormatOutput;
76
+ /** Runs asynchronous output work, and throws `stale-document` when the document, its revision or
77
+ * the editing mode changed meanwhile. */
78
+ run<T>(operation: (signal: AbortSignal) => Promise<T>): Promise<T>;
79
+ /** Throws unless the captured document is still current. */
80
+ assertCurrent(): void;
81
+ }
82
+ /**
83
+ * Everything that differs between document formats. The editor sets one handler on each load and
84
+ * reads its fields directly, so a keystroke does no lookup.
85
+ */
86
+ export interface FormatHandler {
87
+ readonly format: DocumentFormat;
88
+ readonly promise: FormatPromise;
89
+ /** The person edits only the literal surface: there is no formatted mode, and no format, table
90
+ * or block commands. */
91
+ readonly literalOnly: boolean;
92
+ /** A source mode exists beside formatted mode. */
93
+ readonly sourceMode: boolean;
94
+ /** The label that names the formatted surface. */
95
+ readonly formattedLabel: keyof Pick<EditorLabels, 'formattedEditor' | 'richTextEditor'>;
96
+ /** The label that names the literal surface. */
97
+ readonly literalLabel: keyof Pick<EditorLabels, 'plainTextEditor' | 'sourceEditor'>;
98
+ /** `headings` lists the document's headings. */
99
+ readonly headings: boolean;
100
+ /** Copying from the literal surface is left to the browser. */
101
+ readonly nativeCopy: boolean;
102
+ /** Text inserted on the literal surface keeps its own line endings, rather than taking the
103
+ * document's. */
104
+ readonly keepsInsertedLineEndings: boolean;
105
+ /** Markdown input rules and bare-address links apply while typing in formatted mode. */
106
+ readonly markdownInput: boolean;
107
+ /** Present for a format that is not Markdown source but edits in formatted mode. */
108
+ readonly richText?: RichTextBehaviour;
109
+ /** Reads loaded text into the formatted document. Throws when it cannot be shown. */
110
+ load(ctx: Ctx, text: string): FormatSource;
111
+ /** Reads text from the literal surface into the formatted document. */
112
+ parse(ctx: Ctx, text: string): FormatSource;
113
+ /** The document that output reads while text from the literal surface has not reached the
114
+ * formatted document, or `undefined` to read the formatted document. */
115
+ pendingExport(ctx: Ctx, text: string): ProseNode | undefined;
116
+ /** The text that a paste on the literal surface inserts. */
117
+ literalPaste(input: ClipboardInput): string;
118
+ print(request: PrintRequest): Promise<PrintableContent>;
119
+ clipboard(request: ClipboardRequest): Promise<ClipboardOutput>;
120
+ }
@@ -0,0 +1 @@
1
+ export * from './core.js';