@usememos/editor 0.0.0-stage → 26.10.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.
- package/LICENSE +21 -0
- package/README.md +246 -2
- package/dist/base.css +218 -0
- package/dist/entities.dom.js +14 -0
- package/dist/entities.dom.js.map +7 -0
- package/dist/entities.js +17 -0
- package/dist/entities.js.map +7 -0
- package/dist/index.js +7304 -0
- package/dist/index.js.map +7 -0
- package/dist/react.js +143 -0
- package/dist/react.js.map +7 -0
- package/dist/style.css +592 -0
- package/dist/theme.css +214 -0
- package/dist/types/clipboard/fromHtml.d.ts +2 -0
- package/dist/types/clipboard/toHtml.d.ts +4 -0
- package/dist/types/commands.d.ts +168 -0
- package/dist/types/decorations.d.ts +40 -0
- package/dist/types/editor.d.ts +408 -0
- package/dist/types/extension.d.ts +70 -0
- package/dist/types/extensions/fileHandler.d.ts +28 -0
- package/dist/types/extensions/footnotes.d.ts +2 -0
- package/dist/types/extensions/keymap.d.ts +2 -0
- package/dist/types/extensions/math.d.ts +15 -0
- package/dist/types/extensions/suggestion.d.ts +51 -0
- package/dist/types/extensions/tags.d.ts +34 -0
- package/dist/types/extensions/textDecorator.d.ts +17 -0
- package/dist/types/history.d.ts +17 -0
- package/dist/types/index.d.ts +23 -0
- package/dist/types/keymap.d.ts +12 -0
- package/dist/types/labels.d.ts +41 -0
- package/dist/types/markdown/ast.d.ts +129 -0
- package/dist/types/markdown/autolink.d.ts +21 -0
- package/dist/types/markdown/blocks.d.ts +4 -0
- package/dist/types/markdown/entities.d.ts +2 -0
- package/dist/types/markdown/entities.dom.d.ts +2 -0
- package/dist/types/markdown/html.d.ts +2 -0
- package/dist/types/markdown/inline.d.ts +35 -0
- package/dist/types/markdown/lower.d.ts +9 -0
- package/dist/types/markdown/options.d.ts +75 -0
- package/dist/types/markdown/parse.d.ts +4 -0
- package/dist/types/markdown/serialize.d.ts +24 -0
- package/dist/types/markdown/source.d.ts +30 -0
- package/dist/types/model.d.ts +205 -0
- package/dist/types/react/index.d.ts +47 -0
- package/dist/types/theme.d.ts +87 -0
- package/dist/types/ui/handle.d.ts +16 -0
- package/dist/types/ui/popup.d.ts +58 -0
- package/dist/types/ui/toolbar.d.ts +28 -0
- package/dist/types/view/dom.d.ts +85 -0
- package/dist/types/view/reveal.d.ts +12 -0
- package/dist/types/widgets.d.ts +26 -0
- package/package.json +58 -4
|
@@ -0,0 +1,23 @@
|
|
|
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';
|
|
2
|
+
export { DEFAULT_LABELS, type Labels } from './labels.js';
|
|
3
|
+
export * from './model.js';
|
|
4
|
+
export * as commands from './commands.js';
|
|
5
|
+
export { parseMarkdown } from './markdown/parse.js';
|
|
6
|
+
export { parseInline } from './markdown/inline.js';
|
|
7
|
+
export { serializeMarkdown, serializeInline, type SerializeOptions } from './markdown/serialize.js';
|
|
8
|
+
export { loadMarkdown, type MarkdownSource } from './markdown/source.js';
|
|
9
|
+
export type { MarkdownOptions } from './markdown/options.js';
|
|
10
|
+
export { docToHtml } from './clipboard/toHtml.js';
|
|
11
|
+
export { htmlToDoc } from './clipboard/fromHtml.js';
|
|
12
|
+
export type { Extension, ExtensionContext, KeyHandler, SyntaxView } from './extension.js';
|
|
13
|
+
export type { ColorScheme, Theme, ThemeClasses, ThemeColors, ThemeTokens } from './theme.js';
|
|
14
|
+
export { defaultKeymap } from './extensions/keymap.js';
|
|
15
|
+
export { math, type MathOptions } from './extensions/math.js';
|
|
16
|
+
export { footnotes } from './extensions/footnotes.js';
|
|
17
|
+
export type { BlockSyntax, BlockSyntaxMatcher, InlineSyntax, MarkdownSyntax } from './markdown/options.js';
|
|
18
|
+
export { textDecorator, type TextDecoratorOptions } from './extensions/textDecorator.js';
|
|
19
|
+
export { mentions, scanMentions, scanTags, tags, type TagScanner, type TagsOptions } from './extensions/tags.js';
|
|
20
|
+
export type { Decoration, DecorationContext, Decorator, TextRange } from './decorations.js';
|
|
21
|
+
export { suggestion, type SuggestionConfig, type SuggestionItem, type SuggestionRange } from './extensions/suggestion.js';
|
|
22
|
+
export type { Widget, WidgetRender } from './widgets.js';
|
|
23
|
+
export { fileHandler, type FileHandlerOptions } from './extensions/fileHandler.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { KeyHandler } from './extension.js';
|
|
2
|
+
interface Binding {
|
|
3
|
+
readonly key: string;
|
|
4
|
+
readonly ctrl: boolean;
|
|
5
|
+
readonly alt: boolean;
|
|
6
|
+
readonly shift: boolean;
|
|
7
|
+
readonly meta: boolean;
|
|
8
|
+
readonly handler: KeyHandler;
|
|
9
|
+
}
|
|
10
|
+
export declare function parseKeyName(name: string, handler: KeyHandler, mac: boolean): Binding;
|
|
11
|
+
export declare function matchesKey(binding: Binding, e: KeyboardEvent): boolean;
|
|
12
|
+
export type { Binding };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare const DEFAULT_LABELS: {
|
|
2
|
+
text: string;
|
|
3
|
+
heading1: string;
|
|
4
|
+
heading2: string;
|
|
5
|
+
heading3: string;
|
|
6
|
+
bulletList: string;
|
|
7
|
+
numberedList: string;
|
|
8
|
+
todoList: string;
|
|
9
|
+
quote: string;
|
|
10
|
+
code: string;
|
|
11
|
+
table: string;
|
|
12
|
+
divider: string;
|
|
13
|
+
noResults: string;
|
|
14
|
+
duplicate: string;
|
|
15
|
+
delete: string;
|
|
16
|
+
bold: string;
|
|
17
|
+
italic: string;
|
|
18
|
+
strike: string;
|
|
19
|
+
inlineCode: string;
|
|
20
|
+
link: string;
|
|
21
|
+
linkPlaceholder: string;
|
|
22
|
+
removeLink: string;
|
|
23
|
+
slashHint: string;
|
|
24
|
+
blockHandle: string;
|
|
25
|
+
listHint: string;
|
|
26
|
+
quoteHint: string;
|
|
27
|
+
language: string;
|
|
28
|
+
/** Shown in a code block's language field when it has none. */
|
|
29
|
+
plainText: string;
|
|
30
|
+
addRowAbove: string;
|
|
31
|
+
addRowBelow: string;
|
|
32
|
+
addColumnLeft: string;
|
|
33
|
+
addColumnRight: string;
|
|
34
|
+
deleteRow: string;
|
|
35
|
+
deleteColumn: string;
|
|
36
|
+
alignLeft: string;
|
|
37
|
+
alignCenter: string;
|
|
38
|
+
alignRight: string;
|
|
39
|
+
tableSection: string;
|
|
40
|
+
};
|
|
41
|
+
export type Labels = typeof DEFAULT_LABELS;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { Align } from '../model.js';
|
|
2
|
+
export type InlineNode = TextNode | {
|
|
3
|
+
readonly type: 'softBreak';
|
|
4
|
+
} | {
|
|
5
|
+
readonly type: 'hardBreak';
|
|
6
|
+
} | {
|
|
7
|
+
readonly type: 'code';
|
|
8
|
+
readonly value: string;
|
|
9
|
+
}
|
|
10
|
+
/** Raw inline HTML, verbatim. */
|
|
11
|
+
| {
|
|
12
|
+
readonly type: 'html';
|
|
13
|
+
readonly value: string;
|
|
14
|
+
}
|
|
15
|
+
/** A token of an inline syntax extension (`name`), verbatim source. */
|
|
16
|
+
| {
|
|
17
|
+
readonly type: 'token';
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly value: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly type: 'emphasis';
|
|
22
|
+
readonly children: InlineNode[];
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: 'strong';
|
|
25
|
+
readonly children: InlineNode[];
|
|
26
|
+
}
|
|
27
|
+
/** GFM strikethrough (`~text~` or `~~text~~`). */
|
|
28
|
+
| {
|
|
29
|
+
readonly type: 'strike';
|
|
30
|
+
readonly children: InlineNode[];
|
|
31
|
+
} | LinkNode | ImageNode;
|
|
32
|
+
export interface TextNode {
|
|
33
|
+
readonly type: 'text';
|
|
34
|
+
readonly value: string;
|
|
35
|
+
}
|
|
36
|
+
export interface LinkNode {
|
|
37
|
+
readonly type: 'link';
|
|
38
|
+
/** Decoded destination, not yet percent-encoded. */
|
|
39
|
+
readonly destination: string;
|
|
40
|
+
readonly title: string;
|
|
41
|
+
readonly children: InlineNode[];
|
|
42
|
+
}
|
|
43
|
+
export interface ImageNode {
|
|
44
|
+
readonly type: 'image';
|
|
45
|
+
readonly destination: string;
|
|
46
|
+
readonly title: string;
|
|
47
|
+
/** The image description; its plain text is the alt text. */
|
|
48
|
+
readonly children: InlineNode[];
|
|
49
|
+
}
|
|
50
|
+
export type BlockNode = ParagraphNode | HeadingNode | {
|
|
51
|
+
readonly type: 'thematicBreak';
|
|
52
|
+
} | BlockQuoteNode | ListNode | CodeBlockNode | HtmlBlockNode | RawNode | TableNode;
|
|
53
|
+
export interface ParagraphNode {
|
|
54
|
+
readonly type: 'paragraph';
|
|
55
|
+
readonly children: InlineNode[];
|
|
56
|
+
}
|
|
57
|
+
export interface HeadingNode {
|
|
58
|
+
readonly type: 'heading';
|
|
59
|
+
readonly level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
60
|
+
/** True for a setext heading (underlined with `=` or `-`). */
|
|
61
|
+
readonly setext: boolean;
|
|
62
|
+
readonly children: InlineNode[];
|
|
63
|
+
}
|
|
64
|
+
export interface BlockQuoteNode {
|
|
65
|
+
readonly type: 'blockQuote';
|
|
66
|
+
readonly children: BlockNode[];
|
|
67
|
+
}
|
|
68
|
+
export interface ListNode {
|
|
69
|
+
readonly type: 'list';
|
|
70
|
+
readonly ordered: boolean;
|
|
71
|
+
/** Number of the first item (ordered lists only; 1 for bullet lists). */
|
|
72
|
+
readonly start: number;
|
|
73
|
+
/** The bullet (`-`, `+`, `*`) or the ordered delimiter (`.`, `)`). */
|
|
74
|
+
readonly marker: string;
|
|
75
|
+
/** A tight list renders its paragraphs without `<p>` tags. */
|
|
76
|
+
readonly tight: boolean;
|
|
77
|
+
readonly items: ListItemNode[];
|
|
78
|
+
}
|
|
79
|
+
export interface ListItemNode {
|
|
80
|
+
readonly type: 'listItem';
|
|
81
|
+
/** GFM task list item: the item began with `[ ]`, `[x]` or `[X]`. */
|
|
82
|
+
readonly task: boolean;
|
|
83
|
+
readonly checked: boolean;
|
|
84
|
+
readonly children: BlockNode[];
|
|
85
|
+
}
|
|
86
|
+
export interface CodeBlockNode {
|
|
87
|
+
readonly type: 'codeBlock';
|
|
88
|
+
readonly fenced: boolean;
|
|
89
|
+
/** Info string of a fenced block (decoded), or "". */
|
|
90
|
+
readonly info: string;
|
|
91
|
+
/** Code text. Ends with "\n" unless empty. */
|
|
92
|
+
readonly value: string;
|
|
93
|
+
}
|
|
94
|
+
export interface HtmlBlockNode {
|
|
95
|
+
readonly type: 'htmlBlock';
|
|
96
|
+
/** Raw HTML, verbatim, without the final line ending. */
|
|
97
|
+
readonly value: string;
|
|
98
|
+
}
|
|
99
|
+
/** A block of a block syntax extension (`name`): its source lines, verbatim, without the final line ending. */
|
|
100
|
+
export interface RawNode {
|
|
101
|
+
readonly type: 'raw';
|
|
102
|
+
readonly name: string;
|
|
103
|
+
readonly value: string;
|
|
104
|
+
}
|
|
105
|
+
export type TableAlign = Align;
|
|
106
|
+
export interface TableNode {
|
|
107
|
+
readonly type: 'table';
|
|
108
|
+
readonly align: TableAlign[];
|
|
109
|
+
/** `rows[0]` is the header row. Every row has `align.length` cells. */
|
|
110
|
+
readonly rows: InlineNode[][][];
|
|
111
|
+
}
|
|
112
|
+
/** Source lines of a top-level block, 1-based and inclusive. */
|
|
113
|
+
export interface SourceLines {
|
|
114
|
+
readonly start: number;
|
|
115
|
+
readonly end: number;
|
|
116
|
+
}
|
|
117
|
+
export interface Root {
|
|
118
|
+
readonly type: 'root';
|
|
119
|
+
readonly children: BlockNode[];
|
|
120
|
+
/** Source lines of each child, by index. */
|
|
121
|
+
readonly lines: readonly SourceLines[];
|
|
122
|
+
/** Source text of every link reference definition, in order. */
|
|
123
|
+
readonly definitions: readonly string[];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The text of inline nodes without their markup, as in image alt text. `soft`
|
|
127
|
+
* is the text of a soft line break; a hard line break is "\n".
|
|
128
|
+
*/
|
|
129
|
+
export declare function inlineNodesText(nodes: readonly InlineNode[], soft: string): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a URL literal may start after `prev`: at the
|
|
3
|
+
* start of a line, after whitespace, or after `*`, `_`, `~` or `(`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isLiteralBoundary(prev: string | undefined): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* A `www.`, `http(s)://` or `ftp://` literal starting at `pos`: its end
|
|
8
|
+
* (exclusive) and link destination, or null. The caller checks the boundary
|
|
9
|
+
* before `pos`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function urlLiteralAt(text: string, pos: number): {
|
|
12
|
+
end: number;
|
|
13
|
+
href: string;
|
|
14
|
+
} | null;
|
|
15
|
+
/** E-mail literals in plain text: `[from, to)` ranges. */
|
|
16
|
+
export declare function emailLiterals(text: string): {
|
|
17
|
+
from: number;
|
|
18
|
+
to: number;
|
|
19
|
+
}[];
|
|
20
|
+
/** The link a literal's text stands for, if the whole text is one literal; else null. */
|
|
21
|
+
export declare function literalHref(text: string): string | null;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Inline } from '../model.js';
|
|
2
|
+
import type { InlineNode } from './ast.js';
|
|
3
|
+
import { type InlineSyntax, type MarkdownOptions } from './options.js';
|
|
4
|
+
/** Link reference definitions, keyed by normalized label. */
|
|
5
|
+
export type RefMap = Map<string, {
|
|
6
|
+
readonly destination: string;
|
|
7
|
+
readonly title: string;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Parses a paragraph's inline content into the document model. Link
|
|
11
|
+
* reference definitions are not available here, so reference links stay text.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseInline(src: string, options?: MarkdownOptions): Inline;
|
|
14
|
+
/**
|
|
15
|
+
* Parses inline content to syntax tree nodes. `src` should already be
|
|
16
|
+
* trimmed. `autolinks` turns on GFM autolink literals.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseInlines(src: string, refs: RefMap, syntax?: readonly InlineSyntax[], autolinks?: boolean): InlineNode[];
|
|
19
|
+
/** An open tag, as defined in the spec's "Raw HTML" section. Shared with the HTML block rules. */
|
|
20
|
+
export declare const OPENTAG = "<[A-Za-z][A-Za-z0-9-]*(?:[ \\t\\n]+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:[ \\t\\n]*=[ \\t\\n]*(?:[^\"'=<>`\\x00-\\x20]+|'[^']*'|\"[^\"]*\"))?)*[ \\t\\n]*/?>";
|
|
21
|
+
export declare const CLOSETAG = "</[A-Za-z][A-Za-z0-9-]*[ \\t\\n]*>";
|
|
22
|
+
/** The URI and e-mail address of an autolink (`<…>`), as regular expression sources. The serializer uses them too. */
|
|
23
|
+
export declare const AUTOLINK_URI = "[A-Za-z][A-Za-z0-9.+-]{1,31}:[^<>\\x00-\\x20]*";
|
|
24
|
+
export declare const AUTOLINK_EMAIL = "[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*";
|
|
25
|
+
/** Unicode whitespace as the spec defines it (Zs plus tab, LF, FF, CR). */
|
|
26
|
+
export declare function isUnicodeWhitespace(ch: string): boolean;
|
|
27
|
+
/** Unicode punctuation as the spec defines it (categories P and S). */
|
|
28
|
+
export declare function isUnicodePunctuation(ch: string): boolean;
|
|
29
|
+
/** Applies backslash escapes and entities, for link destinations, titles and info strings. */
|
|
30
|
+
export declare function unescapeString(s: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Parses link reference definitions at the start of a paragraph's raw
|
|
33
|
+
* content into `refs`. Returns the rest of the content.
|
|
34
|
+
*/
|
|
35
|
+
export declare function extractReferences(content: string, refs: RefMap): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Block, type Span } from '../model.js';
|
|
2
|
+
import { type BlockNode, type InlineNode } from './ast.js';
|
|
3
|
+
import { type MarkdownOptions } from './options.js';
|
|
4
|
+
/**
|
|
5
|
+
* Lowers one top-level block node. Structure the model cannot hold becomes
|
|
6
|
+
* one raw Markdown block holding `source`, the node's Markdown.
|
|
7
|
+
*/
|
|
8
|
+
export declare function lowerTopLevel(node: BlockNode, options: MarkdownOptions, source: string): Block[];
|
|
9
|
+
export declare function lowerInlines(nodes: readonly InlineNode[], options?: MarkdownOptions): Span[];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export interface MarkdownOptions {
|
|
2
|
+
/**
|
|
3
|
+
* A single newline inside a paragraph is a line break (like GitHub
|
|
4
|
+
* comments and remark-breaks), and a line break is saved as a plain
|
|
5
|
+
* newline. Default false: CommonMark soft breaks, which render as spaces.
|
|
6
|
+
*/
|
|
7
|
+
readonly breaks?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Setext headings (`Title` underlined with `===` or `---`). Default true.
|
|
10
|
+
* With false, `Title`⏎`---` is a paragraph and a divider.
|
|
11
|
+
*/
|
|
12
|
+
readonly setext?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* GFM autolink literals: `www.example.com`, `https://example.com` and
|
|
15
|
+
* `name@example.com` written without angle brackets are links. Default true.
|
|
16
|
+
*/
|
|
17
|
+
readonly autolinks?: boolean;
|
|
18
|
+
/** Syntax outside CommonMark and GFM, such as math or footnotes. */
|
|
19
|
+
readonly syntax?: readonly MarkdownSyntax[];
|
|
20
|
+
}
|
|
21
|
+
/** Syntax added by an extension. Its content is kept as source and saved verbatim. */
|
|
22
|
+
export interface MarkdownSyntax {
|
|
23
|
+
readonly inline?: readonly InlineSyntax[];
|
|
24
|
+
readonly block?: readonly BlockSyntax[];
|
|
25
|
+
/** Characters to backslash-escape in plain text, so typed text cannot start this syntax. */
|
|
26
|
+
readonly escape?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* An inline token, such as `$x^2$` or `[^1]`. It becomes a span with
|
|
30
|
+
* `token: name`, shown with the class `mbe-token-<name>` and saved exactly
|
|
31
|
+
* as written.
|
|
32
|
+
*/
|
|
33
|
+
export interface InlineSyntax {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
/** Characters that can start the token. */
|
|
36
|
+
readonly triggers: string;
|
|
37
|
+
/**
|
|
38
|
+
* Where a token starting at `pos` ends (exclusive), or -1 if there is no
|
|
39
|
+
* token there. `text` is the inline source, with escapes still in it. It is
|
|
40
|
+
* tried before CommonMark syntax, except backslash escapes.
|
|
41
|
+
*/
|
|
42
|
+
match(text: string, pos: number): number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A block kept as source, such as a `$$` math block or a footnote
|
|
46
|
+
* definition. It becomes a raw block with `syntax: name`.
|
|
47
|
+
*/
|
|
48
|
+
export interface BlockSyntax {
|
|
49
|
+
readonly name: string;
|
|
50
|
+
/** Whether it can start in the middle of a paragraph, like a code fence. Default false. */
|
|
51
|
+
readonly interruptsParagraph?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Called with a line (from its first non-space character) that might start
|
|
54
|
+
* the block. Returns a matcher for the lines that follow, or null.
|
|
55
|
+
*/
|
|
56
|
+
open(line: string): BlockSyntaxMatcher | null;
|
|
57
|
+
}
|
|
58
|
+
export interface BlockSyntaxMatcher {
|
|
59
|
+
/**
|
|
60
|
+
* For each following line: `continue` adds it, `close` adds it and ends
|
|
61
|
+
* the block, `end` ends the block before it.
|
|
62
|
+
*/
|
|
63
|
+
next(line: string): 'continue' | 'close' | 'end';
|
|
64
|
+
}
|
|
65
|
+
export interface ResolvedMarkdown {
|
|
66
|
+
readonly breaks: boolean;
|
|
67
|
+
readonly setext: boolean;
|
|
68
|
+
readonly autolinks: boolean;
|
|
69
|
+
readonly syntax: readonly MarkdownSyntax[];
|
|
70
|
+
readonly inline: readonly InlineSyntax[];
|
|
71
|
+
readonly block: readonly BlockSyntax[];
|
|
72
|
+
readonly escape: string;
|
|
73
|
+
}
|
|
74
|
+
export declare const DEFAULT_MARKDOWN: ResolvedMarkdown;
|
|
75
|
+
export declare function resolveMarkdown(options: MarkdownOptions | undefined): ResolvedMarkdown;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Block, type Doc, type Inline, type Span } from '../model.js';
|
|
2
|
+
import { type MarkdownOptions } from './options.js';
|
|
3
|
+
import { type MarkdownSource } from './source.js';
|
|
4
|
+
export declare function serializeMarkdown(doc: Doc, options?: SerializeOptions): string;
|
|
5
|
+
export interface SerializeOptions extends MarkdownOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The source the document was loaded from (see `loadMarkdown`). Blocks
|
|
8
|
+
* that are unchanged since loading are written exactly as they were.
|
|
9
|
+
*/
|
|
10
|
+
readonly source?: MarkdownSource | null;
|
|
11
|
+
}
|
|
12
|
+
/** Blocks as Markdown, without a final line ending. */
|
|
13
|
+
export declare function serializeBlocks(blocks: readonly Block[], options?: MarkdownOptions): string;
|
|
14
|
+
export declare function isEmptyParagraph(block: Block): boolean;
|
|
15
|
+
/** Serializes inline content as it appears in a paragraph. */
|
|
16
|
+
export declare function serializeInline(inline: Inline, options?: MarkdownOptions): string;
|
|
17
|
+
/**
|
|
18
|
+
* The inline content as Markdown can represent it, which is what parsing the
|
|
19
|
+
* serialized output gives back:
|
|
20
|
+
* - Whitespace at the edges of a bold, italic or strike run moves outside it,
|
|
21
|
+
* because `**foo **` is not valid emphasis.
|
|
22
|
+
* - A "\n" in a code span is a hard break outside the code span.
|
|
23
|
+
*/
|
|
24
|
+
export declare function representableInline(inline: Inline): Span[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Block, type Doc } from '../model.js';
|
|
2
|
+
import { type MarkdownOptions } from './options.js';
|
|
3
|
+
export interface SourceGroup {
|
|
4
|
+
/** Position among the groups of the source. */
|
|
5
|
+
readonly index: number;
|
|
6
|
+
/** Source range: from the start of the first line to the end of the last line, without its line ending. */
|
|
7
|
+
readonly from: number;
|
|
8
|
+
readonly to: number;
|
|
9
|
+
/** The blocks the source lowered to, in order. */
|
|
10
|
+
readonly blocks: readonly Block[];
|
|
11
|
+
/**
|
|
12
|
+
* The source may continue into whatever follows it (a code fence or HTML
|
|
13
|
+
* block without its closing line). It is then kept only at the end.
|
|
14
|
+
*/
|
|
15
|
+
readonly open: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface MarkdownSource {
|
|
18
|
+
readonly text: string;
|
|
19
|
+
readonly groups: readonly SourceGroup[];
|
|
20
|
+
/** The group of each loaded block. An edited block is a new object and is not in the map. */
|
|
21
|
+
readonly groupOf: WeakMap<Block, SourceGroup>;
|
|
22
|
+
/** Source of every link reference definition, so a kept block's reference links keep working. */
|
|
23
|
+
readonly definitions: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
/** Parses Markdown and remembers its source, for `serializeMarkdown(doc, { source })`. */
|
|
26
|
+
export declare function loadMarkdown(text: string, options?: MarkdownOptions): {
|
|
27
|
+
doc: Doc;
|
|
28
|
+
source: MarkdownSource;
|
|
29
|
+
};
|
|
30
|
+
export declare function saveWithSource(blocks: readonly Block[], source: MarkdownSource, options?: MarkdownOptions): string;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/** `html` marks raw inline HTML, which is shown as source and saved verbatim. */
|
|
2
|
+
export type Mark = 'bold' | 'italic' | 'strike' | 'code' | 'html';
|
|
3
|
+
/** Canonical mark order. Used for sorting and for nesting when rendering. */
|
|
4
|
+
export declare const MARK_ORDER: readonly Mark[];
|
|
5
|
+
/** Character used as the text of an inline atom (an image). */
|
|
6
|
+
export declare const ATOM_CHAR = "\uFFFC";
|
|
7
|
+
export interface ImageAtom {
|
|
8
|
+
readonly src: string;
|
|
9
|
+
readonly alt: string;
|
|
10
|
+
readonly title?: string;
|
|
11
|
+
}
|
|
12
|
+
/** A run of text that shares one format. A hard line break is a "\n" in the text. */
|
|
13
|
+
export interface Span {
|
|
14
|
+
readonly text: string;
|
|
15
|
+
/** Sorted by MARK_ORDER, no duplicates. */
|
|
16
|
+
readonly marks: readonly Mark[];
|
|
17
|
+
readonly link?: string;
|
|
18
|
+
/** An image. Its `text` is a single ATOM_CHAR. */
|
|
19
|
+
readonly image?: ImageAtom;
|
|
20
|
+
/**
|
|
21
|
+
* A token of an inline syntax extension, by syntax name (for example
|
|
22
|
+
* `math`). Its `text` is the token's Markdown source, saved verbatim.
|
|
23
|
+
*/
|
|
24
|
+
readonly token?: string;
|
|
25
|
+
}
|
|
26
|
+
/** Inline content: normalized spans (no empty spans, no adjacent spans with equal format). */
|
|
27
|
+
export type Inline = readonly Span[];
|
|
28
|
+
export interface Format {
|
|
29
|
+
readonly marks: readonly Mark[];
|
|
30
|
+
readonly link?: string;
|
|
31
|
+
readonly token?: string;
|
|
32
|
+
}
|
|
33
|
+
export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
34
|
+
export type ListType = 'bullet' | 'ordered' | 'task';
|
|
35
|
+
export type Align = 'left' | 'center' | 'right' | null;
|
|
36
|
+
export declare const MAX_INDENT = 5;
|
|
37
|
+
export interface ParagraphBlock {
|
|
38
|
+
readonly id: string;
|
|
39
|
+
readonly type: 'paragraph';
|
|
40
|
+
readonly content: Inline;
|
|
41
|
+
}
|
|
42
|
+
export interface HeadingBlock {
|
|
43
|
+
readonly id: string;
|
|
44
|
+
readonly type: 'heading';
|
|
45
|
+
readonly level: HeadingLevel;
|
|
46
|
+
readonly content: Inline;
|
|
47
|
+
}
|
|
48
|
+
/** One list item. Adjacent items form a list; `indent` gives nesting (0 to MAX_INDENT). */
|
|
49
|
+
export interface ListItemBlock {
|
|
50
|
+
readonly id: string;
|
|
51
|
+
readonly type: 'listItem';
|
|
52
|
+
readonly listType: ListType;
|
|
53
|
+
readonly indent: number;
|
|
54
|
+
/** Task items only. */
|
|
55
|
+
readonly checked: boolean;
|
|
56
|
+
/** Ordered items only: the number of the first item of a list. Ignored on later items. */
|
|
57
|
+
readonly start?: number;
|
|
58
|
+
readonly content: Inline;
|
|
59
|
+
}
|
|
60
|
+
export interface QuoteBlock {
|
|
61
|
+
readonly id: string;
|
|
62
|
+
readonly type: 'quote';
|
|
63
|
+
readonly content: Inline;
|
|
64
|
+
}
|
|
65
|
+
/** Code block. Content is plain text (no marks); lines are separated by "\n". */
|
|
66
|
+
export interface CodeBlock {
|
|
67
|
+
readonly id: string;
|
|
68
|
+
readonly type: 'code';
|
|
69
|
+
readonly language: string;
|
|
70
|
+
readonly content: Inline;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Markdown kept as source, shown and edited as plain text and saved
|
|
74
|
+
* verbatim. `syntax` says what it is: `html` for an HTML block, `markdown`
|
|
75
|
+
* for structure the editor cannot edit as blocks (a list inside a quote, a
|
|
76
|
+
* code block inside a list item), or the name of a syntax extension.
|
|
77
|
+
*/
|
|
78
|
+
export interface RawBlock {
|
|
79
|
+
readonly id: string;
|
|
80
|
+
readonly type: 'raw';
|
|
81
|
+
readonly syntax: string;
|
|
82
|
+
readonly content: Inline;
|
|
83
|
+
}
|
|
84
|
+
/** GFM table. `rows[0]` is the header row. Every row has `align.length` cells. */
|
|
85
|
+
export interface TableBlock {
|
|
86
|
+
readonly id: string;
|
|
87
|
+
readonly type: 'table';
|
|
88
|
+
readonly align: readonly Align[];
|
|
89
|
+
readonly rows: readonly (readonly Inline[])[];
|
|
90
|
+
}
|
|
91
|
+
export interface DividerBlock {
|
|
92
|
+
readonly id: string;
|
|
93
|
+
readonly type: 'divider';
|
|
94
|
+
}
|
|
95
|
+
export type TextBlock = ParagraphBlock | HeadingBlock | ListItemBlock | QuoteBlock | CodeBlock | RawBlock;
|
|
96
|
+
export type Block = TextBlock | TableBlock | DividerBlock;
|
|
97
|
+
export type BlockType = Block['type'];
|
|
98
|
+
export interface Doc {
|
|
99
|
+
readonly blocks: readonly Block[];
|
|
100
|
+
}
|
|
101
|
+
export interface Cell {
|
|
102
|
+
readonly row: number;
|
|
103
|
+
readonly col: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A caret position: a character offset into a block's text. Inside a table
|
|
107
|
+
* the position also names the cell. A divider only has offset 0.
|
|
108
|
+
*/
|
|
109
|
+
export interface Position {
|
|
110
|
+
readonly blockId: string;
|
|
111
|
+
readonly offset: number;
|
|
112
|
+
readonly cell?: Cell;
|
|
113
|
+
}
|
|
114
|
+
export interface Selection {
|
|
115
|
+
readonly anchor: Position;
|
|
116
|
+
readonly focus: Position;
|
|
117
|
+
}
|
|
118
|
+
export interface EditorState {
|
|
119
|
+
readonly doc: Doc;
|
|
120
|
+
readonly selection: Selection;
|
|
121
|
+
/** Format for the next typed text, set by toggling a mark on a collapsed selection. */
|
|
122
|
+
readonly storedMarks: readonly Mark[] | null;
|
|
123
|
+
}
|
|
124
|
+
export declare function createId(): string;
|
|
125
|
+
export declare function paragraph(content?: Inline, id?: string): ParagraphBlock;
|
|
126
|
+
export declare function heading(level: HeadingLevel, content?: Inline, id?: string): HeadingBlock;
|
|
127
|
+
export declare function listItem(listType: ListType, content?: Inline, opts?: {
|
|
128
|
+
indent?: number;
|
|
129
|
+
checked?: boolean;
|
|
130
|
+
start?: number;
|
|
131
|
+
id?: string;
|
|
132
|
+
}): ListItemBlock;
|
|
133
|
+
export declare function quote(content?: Inline, id?: string): QuoteBlock;
|
|
134
|
+
export declare function codeBlock(language?: string, text?: string, id?: string): CodeBlock;
|
|
135
|
+
export declare function rawBlock(syntax: string, text?: string, id?: string): RawBlock;
|
|
136
|
+
/** A raw HTML block. */
|
|
137
|
+
export declare function htmlBlock(text?: string, id?: string): RawBlock;
|
|
138
|
+
export declare function table(align: readonly Align[], rows: readonly (readonly Inline[])[], id?: string): TableBlock;
|
|
139
|
+
export declare function emptyTable(rows?: number, cols?: number, id?: string): TableBlock;
|
|
140
|
+
export declare function divider(id?: string): DividerBlock;
|
|
141
|
+
export declare function plain(text: string): Span[];
|
|
142
|
+
export declare function isTextBlock(block: Block): block is TextBlock;
|
|
143
|
+
/** Blocks whose content is plain text: no marks, links or images, and Enter inserts a newline. */
|
|
144
|
+
export declare function isPlainTextBlock(block: Block): block is CodeBlock | RawBlock;
|
|
145
|
+
/** Inline content at a position's container: the block's content, or a table cell. Null for dividers. */
|
|
146
|
+
export declare function containerContent(block: Block, cell?: Cell): Inline | null;
|
|
147
|
+
/** Returns the block with new content at a container. */
|
|
148
|
+
export declare function withContainerContent(block: Block, cell: Cell | undefined, content: Inline): Block;
|
|
149
|
+
export declare function withContent<B extends TextBlock>(block: B, content: Inline): B;
|
|
150
|
+
/** Drops all formatting. Images become their alt text. */
|
|
151
|
+
export declare function toPlain(inline: Inline): Span[];
|
|
152
|
+
export declare function sortMarks(marks: Iterable<Mark>): Mark[];
|
|
153
|
+
export declare function sameMarks(a: readonly Mark[], b: readonly Mark[]): boolean;
|
|
154
|
+
export declare function inlineText(inline: Inline): string;
|
|
155
|
+
export declare function inlineLength(inline: Inline): number;
|
|
156
|
+
export declare function normalizeInline(inline: Inline): Span[];
|
|
157
|
+
export declare function sliceInline(inline: Inline, from: number, to?: number): Span[];
|
|
158
|
+
export declare function concatInline(...parts: Inline[]): Span[];
|
|
159
|
+
/** Marks of the character before `offset`, or after it at offset 0. */
|
|
160
|
+
export declare function marksAt(inline: Inline, offset: number): readonly Mark[];
|
|
161
|
+
/**
|
|
162
|
+
* Format for text typed at `offset`. Marks come from the character before.
|
|
163
|
+
* A link is continued only when the caret is inside it, not at its edge.
|
|
164
|
+
*/
|
|
165
|
+
export declare function formatAt(inline: Inline, offset: number): Format;
|
|
166
|
+
export declare function insertInline(inline: Inline, offset: number, text: string, format: Format): Span[];
|
|
167
|
+
export declare function deleteInline(inline: Inline, from: number, to: number): Span[];
|
|
168
|
+
/** True if every non-atom character in [from, to) carries `mark`. */
|
|
169
|
+
export declare function rangeHasMark(inline: Inline, from: number, to: number, mark: Mark): boolean;
|
|
170
|
+
export declare function setMarkInRange(inline: Inline, from: number, to: number, mark: Mark, on: boolean): Span[];
|
|
171
|
+
/** Makes [from, to) one token of an inline syntax extension. */
|
|
172
|
+
export declare function setTokenInRange(inline: Inline, from: number, to: number, token: string): Span[];
|
|
173
|
+
/** Sets (or with `href` null, removes) a link on [from, to). */
|
|
174
|
+
export declare function setLinkInRange(inline: Inline, from: number, to: number, href: string | null): Span[];
|
|
175
|
+
/** Extension tokens that touch an offset, edges included, with their start offsets. At most two. */
|
|
176
|
+
export declare function tokensAt(inline: Inline, offset: number): {
|
|
177
|
+
token: string;
|
|
178
|
+
from: number;
|
|
179
|
+
}[];
|
|
180
|
+
/** The link at an offset (the character after it, or before it at the end), if any. */
|
|
181
|
+
export declare function linkAt(inline: Inline, offset: number): {
|
|
182
|
+
href: string;
|
|
183
|
+
from: number;
|
|
184
|
+
to: number;
|
|
185
|
+
} | null;
|
|
186
|
+
export declare function blockIndex(doc: Doc, id: string): number;
|
|
187
|
+
export declare function getBlock(doc: Doc, id: string): Block;
|
|
188
|
+
export declare function sameCell(a?: Cell, b?: Cell): boolean;
|
|
189
|
+
export declare function samePosition(a: Position, b: Position): boolean;
|
|
190
|
+
/** Negative if a is before b in document order, 0 if equal, positive if after. */
|
|
191
|
+
export declare function comparePositions(doc: Doc, a: Position, b: Position): number;
|
|
192
|
+
export declare function isCollapsed(sel: Selection): boolean;
|
|
193
|
+
/** Selection endpoints in document order. */
|
|
194
|
+
export declare function orderedRange(doc: Doc, sel: Selection): {
|
|
195
|
+
from: Position;
|
|
196
|
+
to: Position;
|
|
197
|
+
};
|
|
198
|
+
export declare function caret(blockId: string, offset: number, cell?: Cell): Selection;
|
|
199
|
+
/** The first caret position inside a block. */
|
|
200
|
+
export declare function startOf(block: Block): Position;
|
|
201
|
+
/** The last caret position inside a block. */
|
|
202
|
+
export declare function endOf(block: Block): Position;
|
|
203
|
+
/** Moves positions that point past the end of their container back inside it, and positions in removed blocks to the start. */
|
|
204
|
+
export declare function clampSelection(doc: Doc, sel: Selection): Selection;
|
|
205
|
+
export declare function createState(doc: Doc): EditorState;
|