@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
package/dist/theme.css
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Default theme: quiet, compact styles that match a rendered Markdown view,
|
|
3
|
+
* so a document looks the same while editing and when read-only.
|
|
4
|
+
* Needs base.css, which holds the layout and all spacing between blocks.
|
|
5
|
+
* Every color, font and size is a custom property; the theme option's
|
|
6
|
+
* tokens set them (see theme.ts), or set them on the root in CSS.
|
|
7
|
+
* Light and dark follow prefers-color-scheme; set data-theme="light" or
|
|
8
|
+
* data-theme="dark" on the root or an ancestor, or the theme option's
|
|
9
|
+
* colorScheme, to force one.
|
|
10
|
+
*/
|
|
11
|
+
.mbe-root,
|
|
12
|
+
.mbe-ui {
|
|
13
|
+
color-scheme: light dark;
|
|
14
|
+
--mbe-font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans',
|
|
15
|
+
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
|
|
16
|
+
--mbe-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
|
|
17
|
+
--mbe-font-size: 16px;
|
|
18
|
+
--mbe-line-height: 24px;
|
|
19
|
+
--mbe-radius: 8px;
|
|
20
|
+
/* Colors: light-dark() picks by the element's color-scheme. The theme
|
|
21
|
+
option's tokens set --mbe-<name>-light and --mbe-<name>-dark. */
|
|
22
|
+
--mbe-text: light-dark(var(--mbe-text-light, oklch(0.2438 0.0269 95.7226)), var(--mbe-text-dark, oklch(0.9 0.006 255)));
|
|
23
|
+
--mbe-muted: light-dark(var(--mbe-muted-light, oklch(0.5559 0.0075 97.4233)), var(--mbe-muted-dark, oklch(0.72 0.007 255)));
|
|
24
|
+
--mbe-bg: light-dark(var(--mbe-bg-light, transparent), var(--mbe-bg-dark, transparent));
|
|
25
|
+
--mbe-accent: light-dark(var(--mbe-accent-light, oklch(0.45 0.08 250)), var(--mbe-accent-dark, oklch(0.66 0.11 250)));
|
|
26
|
+
--mbe-link: light-dark(
|
|
27
|
+
var(--mbe-link-light, var(--mbe-accent-light, oklch(0.45 0.08 250))),
|
|
28
|
+
var(--mbe-link-dark, var(--mbe-accent-dark, oklch(0.66 0.11 250)))
|
|
29
|
+
);
|
|
30
|
+
--mbe-code-bg: light-dark(var(--mbe-code-bg-light, oklch(0.9341 0.0153 90.239)), var(--mbe-code-bg-dark, oklch(0.35 0.011 255)));
|
|
31
|
+
--mbe-border: light-dark(var(--mbe-border-light, oklch(0.8847 0.0069 97.3627)), var(--mbe-border-dark, oklch(0.38 0.01 255)));
|
|
32
|
+
--mbe-popup-bg: light-dark(var(--mbe-popup-bg-light, oklch(1 0 0)), var(--mbe-popup-bg-dark, oklch(0.32 0.01 255)));
|
|
33
|
+
--mbe-popup-border: light-dark(
|
|
34
|
+
var(--mbe-popup-border-light, var(--mbe-border-light, oklch(0.8847 0.0069 97.3627))),
|
|
35
|
+
var(--mbe-popup-border-dark, var(--mbe-border-dark, oklch(0.38 0.01 255)))
|
|
36
|
+
);
|
|
37
|
+
--mbe-hover: light-dark(var(--mbe-hover-light, oklch(0.9245 0.0138 92.9892)), var(--mbe-hover-dark, oklch(0.39 0.018 250)));
|
|
38
|
+
--mbe-danger: light-dark(var(--mbe-danger-light, oklch(0.5 0.12 25)), var(--mbe-danger-dark, oklch(0.64 0.18 24)));
|
|
39
|
+
/* Two soft shadows in light, one darker and wider in dark. */
|
|
40
|
+
--mbe-popup-shadow: 0 4px 12px light-dark(transparent, rgb(0 0 0 / 0.35)), 0 4px 6px -1px light-dark(rgb(0 0 0 / 0.1), transparent),
|
|
41
|
+
0 2px 4px -2px light-dark(rgb(0 0 0 / 0.1), transparent);
|
|
42
|
+
--mbe-block-code-bg: color-mix(in oklab, var(--mbe-code-bg) 45%, transparent);
|
|
43
|
+
--mbe-quote-border: color-mix(in oklab, var(--mbe-muted) 25%, transparent);
|
|
44
|
+
}
|
|
45
|
+
:where([data-theme='light']) :is(.mbe-root, .mbe-ui),
|
|
46
|
+
.mbe-root[data-theme='light'],
|
|
47
|
+
.mbe-ui[data-theme='light'] {
|
|
48
|
+
color-scheme: light;
|
|
49
|
+
}
|
|
50
|
+
:where([data-theme='dark']) :is(.mbe-root, .mbe-ui),
|
|
51
|
+
.mbe-root[data-theme='dark'],
|
|
52
|
+
.mbe-ui[data-theme='dark'] {
|
|
53
|
+
color-scheme: dark;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* Document ----------------------------------------------------------------
|
|
57
|
+
Editing and read-only use the same rules. */
|
|
58
|
+
|
|
59
|
+
.mbe-root {
|
|
60
|
+
font-family: var(--mbe-font);
|
|
61
|
+
font-size: var(--mbe-font-size);
|
|
62
|
+
line-height: var(--mbe-line-height);
|
|
63
|
+
color: var(--mbe-text);
|
|
64
|
+
background: var(--mbe-bg);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* Headings: close to the body size. */
|
|
68
|
+
.mbe-root > :is(h1, h2, h3, h4, h5, h6) { font-weight: 600; }
|
|
69
|
+
.mbe-root > h1 { font-size: 24px; line-height: 32px; }
|
|
70
|
+
.mbe-root > h2 { font-size: 20px; line-height: 28px; }
|
|
71
|
+
.mbe-root > h3 { font-size: 18px; line-height: 26px; }
|
|
72
|
+
.mbe-root > :is(h4, h5, h6) { font-size: 16px; line-height: 24px; }
|
|
73
|
+
.mbe-root > h6 { color: var(--mbe-muted); }
|
|
74
|
+
|
|
75
|
+
/* Block selection */
|
|
76
|
+
.mbe-root > .mbe-block.mbe-block-selected {
|
|
77
|
+
background: color-mix(in oklab, var(--mbe-accent) 14%, transparent);
|
|
78
|
+
box-shadow: 0 0 0 3px color-mix(in oklab, var(--mbe-accent) 14%, transparent);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* Inline */
|
|
82
|
+
.mbe-root a.mbe-link {
|
|
83
|
+
color: var(--mbe-link);
|
|
84
|
+
text-decoration: underline;
|
|
85
|
+
text-decoration-color: color-mix(in oklab, var(--mbe-link) 50%, transparent);
|
|
86
|
+
text-underline-offset: 2px;
|
|
87
|
+
}
|
|
88
|
+
.mbe-root a.mbe-link:hover { text-decoration-color: var(--mbe-link); }
|
|
89
|
+
/* Inline source text: code, raw HTML and extension tokens (math, footnote
|
|
90
|
+
references) shown as source. line-height: 1, because smaller text in
|
|
91
|
+
another font would otherwise make its line taller than the rest. */
|
|
92
|
+
.mbe-root :is(code, .mbe-raw-html, .mbe-token) { font-family: var(--mbe-mono); font-size: 0.875em; line-height: 1; }
|
|
93
|
+
.mbe-root :is(.mbe-raw-html, .mbe-token) { color: var(--mbe-muted); }
|
|
94
|
+
.mbe-root code { background: var(--mbe-code-bg); border-radius: 4px; padding: 2px 4px; }
|
|
95
|
+
.mbe-root .mbe-image { border-radius: 8px; }
|
|
96
|
+
|
|
97
|
+
/* Quote */
|
|
98
|
+
.mbe-root > blockquote {
|
|
99
|
+
border-inline-start: 3px solid var(--mbe-quote-border);
|
|
100
|
+
padding-inline-start: 12px;
|
|
101
|
+
color: var(--mbe-muted);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Lists */
|
|
105
|
+
.mbe-root .mbe-marker { color: var(--mbe-muted); }
|
|
106
|
+
/* appearance: none, so a disabled checkbox in read-only is not greyed out. */
|
|
107
|
+
.mbe-root .mbe-checkbox {
|
|
108
|
+
appearance: none;
|
|
109
|
+
-webkit-appearance: none;
|
|
110
|
+
border: 1px solid var(--mbe-border);
|
|
111
|
+
border-radius: 4px;
|
|
112
|
+
background: transparent center / 14px no-repeat;
|
|
113
|
+
}
|
|
114
|
+
.mbe-root .mbe-checkbox:checked {
|
|
115
|
+
background-color: var(--mbe-accent);
|
|
116
|
+
border-color: var(--mbe-accent);
|
|
117
|
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* Code: a quiet panel, with the language as a small label above the code. */
|
|
121
|
+
.mbe-root > .mbe-code {
|
|
122
|
+
background: var(--mbe-block-code-bg);
|
|
123
|
+
border-radius: var(--mbe-radius);
|
|
124
|
+
overflow: hidden;
|
|
125
|
+
}
|
|
126
|
+
.mbe-root .mbe-code-bar { padding: 6px 12px 0; }
|
|
127
|
+
.mbe-root .mbe-code-lang { font: 12px/16px var(--mbe-font); color: var(--mbe-muted); }
|
|
128
|
+
.mbe-root .mbe-code-lang::placeholder { color: var(--mbe-muted); opacity: 1; }
|
|
129
|
+
/* Block source text: code blocks and raw blocks. */
|
|
130
|
+
.mbe-root > .mbe-code pre,
|
|
131
|
+
.mbe-root > pre.mbe-raw { font: 14px/22px var(--mbe-mono); }
|
|
132
|
+
.mbe-root > .mbe-code pre { padding: 2px 12px 10px; }
|
|
133
|
+
.mbe-root > .mbe-code pre code { background: none; padding: 0; border-radius: 0; font: inherit; }
|
|
134
|
+
|
|
135
|
+
/* Raw blocks: Markdown kept as source (HTML, structure the editor cannot hold, extension syntax) */
|
|
136
|
+
.mbe-root > pre.mbe-raw { color: var(--mbe-muted); }
|
|
137
|
+
|
|
138
|
+
/* Divider */
|
|
139
|
+
.mbe-root > .mbe-divider hr { border: none; border-top: 1px solid var(--mbe-border); }
|
|
140
|
+
|
|
141
|
+
/* Table: a light grid around every cell and a shaded header row, as in
|
|
142
|
+
Notion and Outline. Separate borders, so the outer corners can be round. */
|
|
143
|
+
.mbe-root > .mbe-table table {
|
|
144
|
+
font-size: 14px;
|
|
145
|
+
line-height: 20px;
|
|
146
|
+
border: 1px solid var(--mbe-border);
|
|
147
|
+
border-radius: var(--mbe-radius);
|
|
148
|
+
}
|
|
149
|
+
.mbe-root > .mbe-table :is(th, td) { padding: 6px 10px; min-width: 8em; }
|
|
150
|
+
.mbe-root > .mbe-table :is(th, td):not(:first-child) { border-inline-start: 1px solid var(--mbe-border); }
|
|
151
|
+
.mbe-root > .mbe-table tr:not(:first-child) > * { border-top: 1px solid var(--mbe-border); }
|
|
152
|
+
.mbe-root > .mbe-table th { font-weight: 500; background: var(--mbe-block-code-bg); }
|
|
153
|
+
/* The header's fill stays inside the round corners. */
|
|
154
|
+
.mbe-root > .mbe-table tr:first-child > :first-child { border-start-start-radius: calc(var(--mbe-radius) - 1px); }
|
|
155
|
+
.mbe-root > .mbe-table tr:first-child > :last-child { border-start-end-radius: calc(var(--mbe-radius) - 1px); }
|
|
156
|
+
|
|
157
|
+
/* Placeholders and hints */
|
|
158
|
+
.mbe-root > .mbe-paragraph.mbe-empty:only-child::before,
|
|
159
|
+
.mbe-root > .mbe-paragraph.mbe-empty.mbe-show-hint::before,
|
|
160
|
+
.mbe-root > .mbe-empty[data-hint]:is(h1, h2, h3, h4, h5, h6, blockquote)::before,
|
|
161
|
+
.mbe-root > .mbe-list-item.mbe-empty[data-hint] > .mbe-content::before {
|
|
162
|
+
color: var(--mbe-muted);
|
|
163
|
+
opacity: 0.7;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* Floating UI ------------------------------------------------------------- */
|
|
167
|
+
|
|
168
|
+
.mbe-ui {
|
|
169
|
+
font-family: var(--mbe-font);
|
|
170
|
+
font-size: 13px;
|
|
171
|
+
line-height: 1.4;
|
|
172
|
+
color: var(--mbe-text);
|
|
173
|
+
}
|
|
174
|
+
.mbe-menu,
|
|
175
|
+
.mbe-toolbar,
|
|
176
|
+
.mbe-link-popover {
|
|
177
|
+
color: var(--mbe-text);
|
|
178
|
+
background: var(--mbe-popup-bg);
|
|
179
|
+
border: 1px solid var(--mbe-popup-border);
|
|
180
|
+
border-radius: var(--mbe-radius);
|
|
181
|
+
box-shadow: var(--mbe-popup-shadow);
|
|
182
|
+
}
|
|
183
|
+
.mbe-menu-title { font-size: 11px; font-weight: 600; color: var(--mbe-muted); text-transform: uppercase; letter-spacing: 0.04em; }
|
|
184
|
+
.mbe-menu-item { border-radius: 6px; }
|
|
185
|
+
.mbe-menu-item.mbe-highlighted { background: var(--mbe-hover); color: inherit; }
|
|
186
|
+
.mbe-menu-item.mbe-danger { color: var(--mbe-danger); }
|
|
187
|
+
.mbe-menu-icon { border-radius: 4px; font-size: 11px; font-weight: 600; color: var(--mbe-muted); }
|
|
188
|
+
.mbe-menu-empty { color: var(--mbe-muted); }
|
|
189
|
+
|
|
190
|
+
.mbe-tool { border-radius: 6px; }
|
|
191
|
+
.mbe-tool:hover { background: var(--mbe-hover); }
|
|
192
|
+
.mbe-tool.mbe-active { color: var(--mbe-accent); background: var(--mbe-hover); }
|
|
193
|
+
.mbe-tool-bold { font-weight: 700; }
|
|
194
|
+
.mbe-tool-italic { font-style: italic; font-family: Georgia, serif; }
|
|
195
|
+
.mbe-tool-strike { text-decoration: line-through; }
|
|
196
|
+
.mbe-tool-code { font-family: var(--mbe-mono); font-size: 12px; }
|
|
197
|
+
.mbe-tool-sep { background: var(--mbe-popup-border); }
|
|
198
|
+
|
|
199
|
+
.mbe-link-input {
|
|
200
|
+
border: 1px solid var(--mbe-popup-border);
|
|
201
|
+
border-radius: 6px;
|
|
202
|
+
background: transparent;
|
|
203
|
+
outline: none;
|
|
204
|
+
}
|
|
205
|
+
.mbe-link-input:focus { border-color: var(--mbe-accent); }
|
|
206
|
+
|
|
207
|
+
.mbe-handle {
|
|
208
|
+
border-radius: 4px;
|
|
209
|
+
color: var(--mbe-muted);
|
|
210
|
+
font-size: 12px;
|
|
211
|
+
letter-spacing: -2px;
|
|
212
|
+
opacity: 0.7;
|
|
213
|
+
}
|
|
214
|
+
.mbe-handle:hover { background: var(--mbe-hover); opacity: 1; }
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { type Block, type EditorState, type HeadingLevel, type ListType, type Mark, type Position, type Selection, type TableBlock, type Align } from './model.js';
|
|
2
|
+
import type { InlineSyntax } from './markdown/options.js';
|
|
3
|
+
export type Command = (state: EditorState) => EditorState;
|
|
4
|
+
/** A copy of a block with a new ID. */
|
|
5
|
+
export declare function cloneBlock(block: Block): Block;
|
|
6
|
+
/** Deletes everything between two positions (in document order) and joins the boundary blocks. */
|
|
7
|
+
export declare function deleteRange(state: EditorState, from: Position, to: Position): EditorState;
|
|
8
|
+
export declare function deleteSelection(state: EditorState): EditorState;
|
|
9
|
+
/** Offset of the grapheme boundary before `offset`, so Backspace removes a whole emoji. */
|
|
10
|
+
export declare function previousGrapheme(text: string, offset: number): number;
|
|
11
|
+
export declare function nextGrapheme(text: string, offset: number): number;
|
|
12
|
+
/** Backspace. */
|
|
13
|
+
export declare function deleteBackward(state: EditorState): EditorState;
|
|
14
|
+
/** Delete (forward). */
|
|
15
|
+
export declare function deleteForward(state: EditorState): EditorState;
|
|
16
|
+
/** Inserts text at the selection with the current format. "\n" is a hard line break. */
|
|
17
|
+
export declare function insertText(state: EditorState, text: string): EditorState;
|
|
18
|
+
/**
|
|
19
|
+
* ArrowDown on the last line of the last block, or ArrowUp on the first line
|
|
20
|
+
* of the first block, when that block is a code block, table or divider: adds
|
|
21
|
+
* an empty paragraph past it, so the caret is never stuck. In a table that is
|
|
22
|
+
* the last (or first) row. Lines are lines of text; a wrapped line counts as
|
|
23
|
+
* one.
|
|
24
|
+
*/
|
|
25
|
+
export declare function exitBlock(state: EditorState, dir: 1 | -1): EditorState;
|
|
26
|
+
/** Shift+Enter: a hard line break. A newline in code; nothing in a table cell. */
|
|
27
|
+
export declare function insertLineBreak(state: EditorState): EditorState;
|
|
28
|
+
/** Enter. */
|
|
29
|
+
export declare function splitBlock(state: EditorState): EditorState;
|
|
30
|
+
/** True if every character of the selection carries the mark (or, collapsed, the next typed text will). */
|
|
31
|
+
export declare function isMarkActive(state: EditorState, mark: Mark): boolean;
|
|
32
|
+
export declare function toggleMark(state: EditorState, mark: Mark): EditorState;
|
|
33
|
+
/** The link under the caret or at the start of the selection. */
|
|
34
|
+
export declare function activeLink(state: EditorState): {
|
|
35
|
+
href: string;
|
|
36
|
+
from: number;
|
|
37
|
+
to: number;
|
|
38
|
+
pos: Position;
|
|
39
|
+
} | null;
|
|
40
|
+
/**
|
|
41
|
+
* Sets a link on the selection, or removes it when `href` is null. With a
|
|
42
|
+
* collapsed selection inside a link, changes the whole link.
|
|
43
|
+
*/
|
|
44
|
+
export declare function setLink(state: EditorState, href: string | null): EditorState;
|
|
45
|
+
export type BlockTypeSpec = {
|
|
46
|
+
type: 'paragraph';
|
|
47
|
+
} | {
|
|
48
|
+
type: 'heading';
|
|
49
|
+
level: HeadingLevel;
|
|
50
|
+
} | {
|
|
51
|
+
type: 'listItem';
|
|
52
|
+
listType: ListType;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'quote';
|
|
55
|
+
} | {
|
|
56
|
+
type: 'code';
|
|
57
|
+
language?: string;
|
|
58
|
+
} | {
|
|
59
|
+
type: 'table';
|
|
60
|
+
rows?: number;
|
|
61
|
+
cols?: number;
|
|
62
|
+
} | {
|
|
63
|
+
type: 'divider';
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Changes the type of every text block touched by the selection. Text and IDs
|
|
67
|
+
* are kept. Tables and dividers are inserted instead (see insertBlock).
|
|
68
|
+
*/
|
|
69
|
+
export declare function setBlockType(state: EditorState, spec: BlockTypeSpec): EditorState;
|
|
70
|
+
/**
|
|
71
|
+
* Sets the type of the selected text blocks, or turns them back into
|
|
72
|
+
* paragraphs when they all have that type already.
|
|
73
|
+
*/
|
|
74
|
+
export declare function toggleBlockType(state: EditorState, spec: BlockTypeSpec): EditorState;
|
|
75
|
+
/**
|
|
76
|
+
* Applies a slash menu pick. Text types convert the current block in place.
|
|
77
|
+
* A table or divider replaces the current block if it is empty and otherwise
|
|
78
|
+
* goes below it. A divider is followed by a paragraph for the caret.
|
|
79
|
+
*/
|
|
80
|
+
export declare function insertBlock(state: EditorState, spec: BlockTypeSpec): EditorState;
|
|
81
|
+
/** Tab / Shift+Tab on list items: changes nesting by one level. */
|
|
82
|
+
export declare function indentListItems(state: EditorState, delta: 1 | -1): EditorState;
|
|
83
|
+
export declare function toggleTask(state: EditorState, blockId: string): EditorState;
|
|
84
|
+
/** Sets a code block's language, from the input in its header. */
|
|
85
|
+
export declare function setCodeLanguage(state: EditorState, blockId: string, language: string): EditorState;
|
|
86
|
+
export declare function duplicateBlock(state: EditorState, blockId: string): EditorState;
|
|
87
|
+
export declare function deleteBlock(state: EditorState, blockId: string): EditorState;
|
|
88
|
+
export interface BlockRange {
|
|
89
|
+
readonly from: number;
|
|
90
|
+
readonly to: number;
|
|
91
|
+
}
|
|
92
|
+
/** A selection from the start of the first block in a range to the end of the last. */
|
|
93
|
+
export declare function spanBlocks(blocks: readonly Block[], range: BlockRange): Selection;
|
|
94
|
+
/** Removes whole blocks. The caret goes to the end of the block before them, or the start of the block after. */
|
|
95
|
+
export declare function deleteBlocks(state: EditorState, range: BlockRange): EditorState;
|
|
96
|
+
/** Inserts copies of the blocks right after them, and selects the copies. */
|
|
97
|
+
export declare function duplicateBlocks(state: EditorState, range: BlockRange): EditorState;
|
|
98
|
+
/** Replaces whole blocks with `fragment` and puts the caret at its end. An empty fragment deletes them. */
|
|
99
|
+
export declare function replaceBlocks(state: EditorState, range: BlockRange, fragment: readonly Block[]): EditorState;
|
|
100
|
+
export declare function addRow(block: TableBlock, at: number): TableBlock;
|
|
101
|
+
export declare function addColumn(block: TableBlock, at: number): TableBlock;
|
|
102
|
+
export type TableAction = {
|
|
103
|
+
kind: 'addRowAbove';
|
|
104
|
+
} | {
|
|
105
|
+
kind: 'addRowBelow';
|
|
106
|
+
} | {
|
|
107
|
+
kind: 'addColumnLeft';
|
|
108
|
+
} | {
|
|
109
|
+
kind: 'addColumnRight';
|
|
110
|
+
} | {
|
|
111
|
+
kind: 'deleteRow';
|
|
112
|
+
} | {
|
|
113
|
+
kind: 'deleteColumn';
|
|
114
|
+
} | {
|
|
115
|
+
kind: 'align';
|
|
116
|
+
align: Align;
|
|
117
|
+
};
|
|
118
|
+
/** Table edits relative to the cell with the caret. */
|
|
119
|
+
export declare function tableAction(state: EditorState, action: TableAction): EditorState;
|
|
120
|
+
/** Tab / Shift+Tab in a table: next or previous cell. Tab in the last cell adds a row. */
|
|
121
|
+
export declare function moveCell(state: EditorState, delta: 1 | -1): EditorState;
|
|
122
|
+
export declare function applyBlockInputRules(state: EditorState): EditorState | null;
|
|
123
|
+
/**
|
|
124
|
+
* Inline shortcuts: typing the closing delimiter of `**x**`, `*x*`, `_x_`,
|
|
125
|
+
* `` `x` `` or `~~x~~` applies the mark and removes the delimiters.
|
|
126
|
+
*/
|
|
127
|
+
export declare function applyInlineInputRules(state: EditorState): EditorState | null;
|
|
128
|
+
/**
|
|
129
|
+
* Text just typed that completes a token of an inline syntax extension (for
|
|
130
|
+
* example the closing `$` of `$x^2$`) becomes that token, so it is saved
|
|
131
|
+
* verbatim instead of escaped. Only plain text on the caret's line counts.
|
|
132
|
+
*/
|
|
133
|
+
export declare function applyTokenInputRules(state: EditorState, syntax: readonly InlineSyntax[]): EditorState | null;
|
|
134
|
+
/**
|
|
135
|
+
* A GFM autolink literal (a `www.`, `http(s)://` or `ftp://` URL, or an
|
|
136
|
+
* e-mail address) just followed by a typed space becomes a link, the same
|
|
137
|
+
* link it reads back as after saving. Only text that is not code, a link, a
|
|
138
|
+
* token, raw HTML or an image counts.
|
|
139
|
+
*/
|
|
140
|
+
export declare function applyAutolinkInputRule(state: EditorState): EditorState | null;
|
|
141
|
+
/** The selected content as standalone blocks with fresh IDs. A partly selected table is copied whole. */
|
|
142
|
+
export declare function selectedBlocks(state: EditorState): Block[];
|
|
143
|
+
/**
|
|
144
|
+
* Pastes blocks at the selection. A single pasted text block merges into the
|
|
145
|
+
* current block as inline content. With several blocks, the first joins the
|
|
146
|
+
* text before the caret, the last joins the text after it, and the rest are
|
|
147
|
+
* inserted in between.
|
|
148
|
+
*/
|
|
149
|
+
export declare function insertBlocks(state: EditorState, fragment: readonly Block[]): EditorState;
|
|
150
|
+
export declare function selectAll(state: EditorState): EditorState;
|
|
151
|
+
export interface InsertOptions {
|
|
152
|
+
/**
|
|
153
|
+
* Where to insert. `'selection'` (default) replaces the selection, like a
|
|
154
|
+
* paste. `'end'` appends after the last block. A position inserts there
|
|
155
|
+
* and replaces nothing.
|
|
156
|
+
*/
|
|
157
|
+
readonly at?: 'selection' | 'end' | Position;
|
|
158
|
+
/**
|
|
159
|
+
* Insert as separate blocks even when the content is a single paragraph.
|
|
160
|
+
* A text block at the target is split. Default false: a single text block
|
|
161
|
+
* is inserted inline.
|
|
162
|
+
*/
|
|
163
|
+
readonly block?: boolean;
|
|
164
|
+
/** `'end'` (default) puts the caret after the inserted content; `'keep'` keeps the current selection. */
|
|
165
|
+
readonly select?: 'end' | 'keep';
|
|
166
|
+
}
|
|
167
|
+
/** Inserts blocks, for example parsed Markdown. See InsertOptions. */
|
|
168
|
+
export declare function insertFragment(state: EditorState, fragment: readonly Block[], options?: InsertOptions): EditorState;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Block, type Cell, type Inline, type Span } from './model.js';
|
|
2
|
+
export interface Decoration {
|
|
3
|
+
/** Start offset in the container's text. */
|
|
4
|
+
readonly from: number;
|
|
5
|
+
/** End offset (exclusive). */
|
|
6
|
+
readonly to: number;
|
|
7
|
+
readonly class: string;
|
|
8
|
+
readonly attributes?: Readonly<Record<string, string>>;
|
|
9
|
+
}
|
|
10
|
+
export interface TextRange {
|
|
11
|
+
readonly from: number;
|
|
12
|
+
readonly to: number;
|
|
13
|
+
}
|
|
14
|
+
/** One text container: a block's content, or one table cell. */
|
|
15
|
+
export interface DecorationContext {
|
|
16
|
+
readonly block: Block;
|
|
17
|
+
/** Set for a table cell. */
|
|
18
|
+
readonly cell?: Cell;
|
|
19
|
+
/** The container's plain text. An image counts as one character. */
|
|
20
|
+
readonly text: string;
|
|
21
|
+
readonly content: Inline;
|
|
22
|
+
/** Ranges of inline code, links, images, raw HTML and extension tokens, which decorators usually skip. */
|
|
23
|
+
readonly excluded: readonly TextRange[];
|
|
24
|
+
}
|
|
25
|
+
export type Decorator = (ctx: DecorationContext) => readonly Decoration[];
|
|
26
|
+
/** Whether a span is code, a link, an image, raw HTML or a token: text that is not plain prose. */
|
|
27
|
+
export declare function isExcluded(span: Span): boolean;
|
|
28
|
+
export declare function decorationContext(block: Block, content: Inline, cell?: Cell): DecorationContext;
|
|
29
|
+
export declare function overlapsAny(from: number, to: number, ranges: readonly TextRange[]): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Splits content at decoration edges. Each piece is a span with the
|
|
32
|
+
* decorations that cover it, in the order given. Spans for which `atomic`
|
|
33
|
+
* returns true (given their start offset) are never split, and their pieces
|
|
34
|
+
* are marked `atomic`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function splitByDecorations(content: Inline, decorations: readonly Decoration[], atomic?: (span: Span, from: number) => boolean): {
|
|
37
|
+
span: Span;
|
|
38
|
+
decorations: Decoration[];
|
|
39
|
+
atomic: boolean;
|
|
40
|
+
}[];
|