@thomasfosterau/effect-richtext 0.0.0 → 0.1.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 +48 -0
- package/README.md +117 -1
- package/dist/_virtual/_rolldown/runtime.js +12 -0
- package/dist/commands/commands.d.ts +323 -0
- package/dist/commands/commands.js +722 -0
- package/dist/commands/internal.js +43 -0
- package/dist/commands/keymaps.d.ts +46 -0
- package/dist/commands/keymaps.js +64 -0
- package/dist/commands.d.ts +3 -0
- package/dist/commands.js +3 -0
- package/dist/compat/commands.d.ts +250 -0
- package/dist/compat/commands.js +275 -0
- package/dist/compat/internal/core.d.ts +20 -0
- package/dist/compat/internal/core.js +148 -0
- package/dist/compat/internal/props.js +82 -0
- package/dist/compat/keymap.d.ts +21 -0
- package/dist/compat/keymap.js +38 -0
- package/dist/compat/model.d.ts +893 -0
- package/dist/compat/model.js +1212 -0
- package/dist/compat/orderedmap.d.ts +74 -0
- package/dist/compat/orderedmap.js +124 -0
- package/dist/compat/schema-basic.d.ts +38 -0
- package/dist/compat/schema-basic.js +238 -0
- package/dist/compat/schema-list.d.ts +81 -0
- package/dist/compat/schema-list.js +156 -0
- package/dist/compat/state.d.ts +415 -0
- package/dist/compat/state.js +689 -0
- package/dist/compat/test-builder.d.ts +98 -0
- package/dist/compat/test-builder.js +197 -0
- package/dist/compat/transform.d.ts +458 -0
- package/dist/compat/transform.js +803 -0
- package/dist/compat/view.d.ts +411 -0
- package/dist/compat/view.js +409 -0
- package/dist/dropcursor.d.ts +46 -0
- package/dist/dropcursor.js +176 -0
- package/dist/extensions/defaults.d.ts +716 -0
- package/dist/extensions/defaults.js +209 -0
- package/dist/extensions/editor.d.ts +246 -0
- package/dist/extensions/editor.js +271 -0
- package/dist/extensions/extension.d.ts +375 -0
- package/dist/extensions/extension.js +233 -0
- package/dist/extensions.d.ts +4 -0
- package/dist/extensions.js +4 -0
- package/dist/gapcursor.d.ts +66 -0
- package/dist/gapcursor.js +273 -0
- package/dist/history.d.ts +178 -0
- package/dist/history.js +412 -0
- package/dist/html.d.ts +158 -0
- package/dist/html.js +164 -0
- package/dist/inputrules.d.ts +271 -0
- package/dist/inputrules.js +321 -0
- package/dist/internal/attempt.js +15 -0
- package/dist/internal/json.js +29 -0
- package/dist/keymap/keymap.d.ts +130 -0
- package/dist/keymap/keymap.js +159 -0
- package/dist/keymap.d.ts +2 -0
- package/dist/keymap.js +1 -0
- package/dist/markdown/errors.d.ts +23 -0
- package/dist/markdown/errors.js +26 -0
- package/dist/markdown/from_markdown.d.ts +185 -0
- package/dist/markdown/from_markdown.js +266 -0
- package/dist/markdown/schema.d.ts +522 -0
- package/dist/markdown/schema.js +292 -0
- package/dist/markdown/to_markdown.d.ts +251 -0
- package/dist/markdown/to_markdown.js +413 -0
- package/dist/markdown.d.ts +5 -0
- package/dist/markdown.js +5 -0
- package/dist/model/attrsCodec.js +48 -0
- package/dist/model/comparedeep.js +17 -0
- package/dist/model/content.d.ts +232 -0
- package/dist/model/content.js +630 -0
- package/dist/model/diff.js +66 -0
- package/dist/model/dom.d.ts +3 -0
- package/dist/model/errors.d.ts +90 -0
- package/dist/model/errors.js +76 -0
- package/dist/model/fragment.d.ts +131 -0
- package/dist/model/fragment.js +262 -0
- package/dist/model/from_dom.d.ts +299 -0
- package/dist/model/from_dom.js +618 -0
- package/dist/model/json.d.ts +37 -0
- package/dist/model/json.js +126 -0
- package/dist/model/mark.d.ts +73 -0
- package/dist/model/mark.js +121 -0
- package/dist/model/node.d.ts +267 -0
- package/dist/model/node.js +434 -0
- package/dist/model/replace.d.ts +78 -0
- package/dist/model/replace.js +207 -0
- package/dist/model/resolvedpos.d.ts +196 -0
- package/dist/model/resolvedpos.js +305 -0
- package/dist/model/schema.d.ts +740 -0
- package/dist/model/schema.js +451 -0
- package/dist/model/to_dom.d.ts +169 -0
- package/dist/model/to_dom.js +238 -0
- package/dist/model.d.ts +12 -0
- package/dist/model.js +12 -0
- package/dist/placeholder.d.ts +53 -0
- package/dist/placeholder.js +79 -0
- package/dist/reactive/observer.d.ts +54 -0
- package/dist/reactive/observer.js +61 -0
- package/dist/reactive/selectors.d.ts +22 -0
- package/dist/reactive/selectors.js +61 -0
- package/dist/reactive/stateref.d.ts +72 -0
- package/dist/reactive/stateref.js +71 -0
- package/dist/reactive/streams.d.ts +83 -0
- package/dist/reactive/streams.js +85 -0
- package/dist/reactive.d.ts +16 -0
- package/dist/reactive.js +26 -0
- package/dist/schema-basic.d.ts +448 -0
- package/dist/schema-basic.js +269 -0
- package/dist/schema-list/commands.d.ts +66 -0
- package/dist/schema-list/commands.js +203 -0
- package/dist/schema-list.d.ts +92 -0
- package/dist/schema-list.js +100 -0
- package/dist/state/errors.d.ts +39 -0
- package/dist/state/errors.js +32 -0
- package/dist/state/plugin.d.ts +232 -0
- package/dist/state/plugin.js +82 -0
- package/dist/state/selection.d.ts +297 -0
- package/dist/state/selection.js +486 -0
- package/dist/state/state.d.ts +212 -0
- package/dist/state/state.js +489 -0
- package/dist/state/transaction.d.ts +145 -0
- package/dist/state/transaction.js +195 -0
- package/dist/state.d.ts +6 -0
- package/dist/state.js +6 -0
- package/dist/test-builder.d.ts +3582 -0
- package/dist/test-builder.js +239 -0
- package/dist/transform/attr_step.d.ts +60 -0
- package/dist/transform/attr_step.js +105 -0
- package/dist/transform/errors.d.ts +50 -0
- package/dist/transform/errors.js +35 -0
- package/dist/transform/map.d.ts +182 -0
- package/dist/transform/map.js +280 -0
- package/dist/transform/mark.js +98 -0
- package/dist/transform/mark_set_step.js +69 -0
- package/dist/transform/mark_step.d.ts +113 -0
- package/dist/transform/mark_step.js +225 -0
- package/dist/transform/replace.d.ts +18 -0
- package/dist/transform/replace.js +381 -0
- package/dist/transform/replace_step.d.ts +109 -0
- package/dist/transform/replace_step.js +175 -0
- package/dist/transform/step.d.ts +157 -0
- package/dist/transform/step.js +168 -0
- package/dist/transform/structure.d.ts +89 -0
- package/dist/transform/structure.js +350 -0
- package/dist/transform/transform.d.ts +248 -0
- package/dist/transform/transform.js +373 -0
- package/dist/transform.d.ts +10 -0
- package/dist/transform.js +10 -0
- package/dist/view/browser.js +39 -0
- package/dist/view/capturekeys.js +282 -0
- package/dist/view/clipboard.d.ts +8 -0
- package/dist/view/clipboard.js +245 -0
- package/dist/view/decoration.d.ts +339 -0
- package/dist/view/decoration.js +566 -0
- package/dist/view/dom.d.ts +18 -0
- package/dist/view/dom.js +140 -0
- package/dist/view/domchange.js +295 -0
- package/dist/view/domcoords.d.ts +22 -0
- package/dist/view/domcoords.js +448 -0
- package/dist/view/domobserver.d.ts +47 -0
- package/dist/view/domobserver.js +328 -0
- package/dist/view/errors.d.ts +18 -0
- package/dist/view/errors.js +21 -0
- package/dist/view/input.d.ts +58 -0
- package/dist/view/input.js +704 -0
- package/dist/view/selection.js +198 -0
- package/dist/view/view.d.ts +699 -0
- package/dist/view/view.js +623 -0
- package/dist/view/viewdesc.d.ts +236 -0
- package/dist/view/viewdesc.js +1205 -0
- package/dist/view-css.d.ts +43 -0
- package/dist/view-css.js +124 -0
- package/dist/view.d.ts +6 -0
- package/dist/view.js +4 -0
- package/package.json +200 -4
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
import { DocSchema } from "./model/schema.js";
|
|
2
|
+
import { Mark } from "./model/mark.js";
|
|
3
|
+
import { Node } from "./model/node.js";
|
|
4
|
+
import { ContentExpr } from "./model/content.js";
|
|
5
|
+
import "./model.js";
|
|
6
|
+
import * as S from "effect/Schema";
|
|
7
|
+
/**
|
|
8
|
+
* The node specs of the basic schema.
|
|
9
|
+
*
|
|
10
|
+
* @since 0.1.0
|
|
11
|
+
* @category specs
|
|
12
|
+
*/
|
|
13
|
+
export declare const nodes: {
|
|
14
|
+
/** The top level document node. */
|
|
15
|
+
doc: {
|
|
16
|
+
readonly content: ContentExpr<"block">;
|
|
17
|
+
};
|
|
18
|
+
/** A plain paragraph textblock. Represented in the DOM as a `<p>` element. */
|
|
19
|
+
paragraph: {
|
|
20
|
+
readonly content: ContentExpr<"inline">;
|
|
21
|
+
readonly group: "block";
|
|
22
|
+
readonly parseDOM: readonly [{
|
|
23
|
+
readonly tag: "p";
|
|
24
|
+
}];
|
|
25
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
26
|
+
};
|
|
27
|
+
/** A blockquote (`<blockquote>`) wrapping one or more blocks. */
|
|
28
|
+
blockquote: {
|
|
29
|
+
readonly content: ContentExpr<"block">;
|
|
30
|
+
readonly group: "block";
|
|
31
|
+
readonly defining: true;
|
|
32
|
+
readonly parseDOM: readonly [{
|
|
33
|
+
readonly tag: "blockquote";
|
|
34
|
+
}];
|
|
35
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
36
|
+
};
|
|
37
|
+
/** A horizontal rule (`<hr>`). */
|
|
38
|
+
horizontal_rule: {
|
|
39
|
+
readonly group: "block";
|
|
40
|
+
readonly parseDOM: readonly [{
|
|
41
|
+
readonly tag: "hr";
|
|
42
|
+
}];
|
|
43
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* A heading textblock, with a `level` attribute that should hold the
|
|
47
|
+
* number 1 to 6. Parsed and serialized as `<h1>` to `<h6>` elements.
|
|
48
|
+
*/
|
|
49
|
+
heading: {
|
|
50
|
+
readonly attrs: {
|
|
51
|
+
readonly level: {
|
|
52
|
+
readonly schema: S.Number;
|
|
53
|
+
readonly default: 1;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
readonly content: ContentExpr<"inline">;
|
|
57
|
+
readonly group: "block";
|
|
58
|
+
readonly defining: true;
|
|
59
|
+
readonly parseDOM: readonly [{
|
|
60
|
+
readonly tag: "h1";
|
|
61
|
+
readonly attrs: {
|
|
62
|
+
readonly level: 1;
|
|
63
|
+
};
|
|
64
|
+
}, {
|
|
65
|
+
readonly tag: "h2";
|
|
66
|
+
readonly attrs: {
|
|
67
|
+
readonly level: 2;
|
|
68
|
+
};
|
|
69
|
+
}, {
|
|
70
|
+
readonly tag: "h3";
|
|
71
|
+
readonly attrs: {
|
|
72
|
+
readonly level: 3;
|
|
73
|
+
};
|
|
74
|
+
}, {
|
|
75
|
+
readonly tag: "h4";
|
|
76
|
+
readonly attrs: {
|
|
77
|
+
readonly level: 4;
|
|
78
|
+
};
|
|
79
|
+
}, {
|
|
80
|
+
readonly tag: "h5";
|
|
81
|
+
readonly attrs: {
|
|
82
|
+
readonly level: 5;
|
|
83
|
+
};
|
|
84
|
+
}, {
|
|
85
|
+
readonly tag: "h6";
|
|
86
|
+
readonly attrs: {
|
|
87
|
+
readonly level: 6;
|
|
88
|
+
};
|
|
89
|
+
}];
|
|
90
|
+
readonly toDOM: (node: Node<any, any>) => [string, number];
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* A code listing. Disallows marks or non-text inline nodes by default.
|
|
94
|
+
* Represented as a `<pre>` element with a `<code>` element inside of
|
|
95
|
+
* it.
|
|
96
|
+
*/
|
|
97
|
+
code_block: {
|
|
98
|
+
readonly content: ContentExpr<"text">;
|
|
99
|
+
readonly marks: "";
|
|
100
|
+
readonly group: "block";
|
|
101
|
+
readonly code: true;
|
|
102
|
+
readonly defining: true;
|
|
103
|
+
readonly parseDOM: readonly [{
|
|
104
|
+
readonly tag: "pre";
|
|
105
|
+
readonly preserveWhitespace: "full";
|
|
106
|
+
}];
|
|
107
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
108
|
+
};
|
|
109
|
+
/** The text node. */
|
|
110
|
+
text: {
|
|
111
|
+
readonly group: "inline";
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* An inline image (`<img>`) node. Supports `src`, `alt`, and `title`
|
|
115
|
+
* attributes. The latter two default to `null`.
|
|
116
|
+
*/
|
|
117
|
+
image: {
|
|
118
|
+
readonly inline: true;
|
|
119
|
+
readonly attrs: {
|
|
120
|
+
readonly src: S.String;
|
|
121
|
+
readonly alt: {
|
|
122
|
+
readonly schema: S.NullOr<S.String>;
|
|
123
|
+
readonly default: null;
|
|
124
|
+
};
|
|
125
|
+
readonly title: {
|
|
126
|
+
readonly schema: S.NullOr<S.String>;
|
|
127
|
+
readonly default: null;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
readonly group: "inline";
|
|
131
|
+
readonly draggable: true;
|
|
132
|
+
readonly parseDOM: readonly [{
|
|
133
|
+
readonly tag: "img[src]";
|
|
134
|
+
readonly getAttrs: (dom: HTMLElement) => {
|
|
135
|
+
src: string | null;
|
|
136
|
+
title: string | null;
|
|
137
|
+
alt: string | null;
|
|
138
|
+
};
|
|
139
|
+
}];
|
|
140
|
+
readonly toDOM: (node: Node<any, any>) => [string, {
|
|
141
|
+
src: any;
|
|
142
|
+
alt: any;
|
|
143
|
+
title: any;
|
|
144
|
+
}];
|
|
145
|
+
};
|
|
146
|
+
/** A hard line break, represented in the DOM as `<br>`. */
|
|
147
|
+
hard_break: {
|
|
148
|
+
readonly inline: true;
|
|
149
|
+
readonly group: "inline";
|
|
150
|
+
readonly selectable: false;
|
|
151
|
+
readonly parseDOM: readonly [{
|
|
152
|
+
readonly tag: "br";
|
|
153
|
+
}];
|
|
154
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* The mark specs of the basic schema.
|
|
159
|
+
*
|
|
160
|
+
* @since 0.1.0
|
|
161
|
+
* @category specs
|
|
162
|
+
*/
|
|
163
|
+
export declare const marks: {
|
|
164
|
+
/**
|
|
165
|
+
* A link. Has `href` and `title` attributes. `title` defaults to
|
|
166
|
+
* `null`. Rendered and parsed as an `<a>` element.
|
|
167
|
+
*/
|
|
168
|
+
link: {
|
|
169
|
+
readonly attrs: {
|
|
170
|
+
readonly href: S.String;
|
|
171
|
+
readonly title: {
|
|
172
|
+
readonly schema: S.NullOr<S.String>;
|
|
173
|
+
readonly default: null;
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
readonly inclusive: false;
|
|
177
|
+
readonly parseDOM: readonly [{
|
|
178
|
+
readonly tag: "a[href]";
|
|
179
|
+
readonly getAttrs: (dom: HTMLElement) => {
|
|
180
|
+
href: string | null;
|
|
181
|
+
title: string | null;
|
|
182
|
+
};
|
|
183
|
+
}];
|
|
184
|
+
readonly toDOM: (node: Mark<any, any>) => [string, {
|
|
185
|
+
href: any;
|
|
186
|
+
title: any;
|
|
187
|
+
}, number];
|
|
188
|
+
};
|
|
189
|
+
/** An emphasis mark. Rendered as an `<em>` element. */
|
|
190
|
+
em: {
|
|
191
|
+
readonly parseDOM: readonly [{
|
|
192
|
+
readonly tag: "i";
|
|
193
|
+
}, {
|
|
194
|
+
readonly tag: "em";
|
|
195
|
+
}, {
|
|
196
|
+
readonly style: "font-style=italic";
|
|
197
|
+
}, {
|
|
198
|
+
readonly style: "font-style=normal";
|
|
199
|
+
readonly clearMark: (m: Mark<any, any>) => boolean;
|
|
200
|
+
}];
|
|
201
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
202
|
+
};
|
|
203
|
+
/** A strong mark. Rendered as `<strong>`, parse rules also match `<b>` and `font-weight: bold`. */
|
|
204
|
+
strong: {
|
|
205
|
+
readonly parseDOM: readonly [{
|
|
206
|
+
readonly tag: "strong";
|
|
207
|
+
}, {
|
|
208
|
+
readonly tag: "b";
|
|
209
|
+
readonly getAttrs: (node: HTMLElement) => false | null;
|
|
210
|
+
}, {
|
|
211
|
+
readonly style: "font-weight=400";
|
|
212
|
+
readonly clearMark: (m: Mark<any, any>) => boolean;
|
|
213
|
+
}, {
|
|
214
|
+
readonly style: "font-weight";
|
|
215
|
+
readonly getAttrs: (value: string) => false | null;
|
|
216
|
+
}];
|
|
217
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
218
|
+
};
|
|
219
|
+
/** Code font mark. Represented as a `<code>` element. */
|
|
220
|
+
code: {
|
|
221
|
+
readonly code: true;
|
|
222
|
+
readonly parseDOM: readonly [{
|
|
223
|
+
readonly tag: "code";
|
|
224
|
+
}];
|
|
225
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* This schema roughly corresponds to the document schema used by
|
|
230
|
+
* CommonMark, minus the list elements, which are defined in the
|
|
231
|
+
* `schema-list` module.
|
|
232
|
+
*
|
|
233
|
+
* @since 0.1.0
|
|
234
|
+
* @category schemas
|
|
235
|
+
*/
|
|
236
|
+
export declare const schema: DocSchema<{
|
|
237
|
+
/** The top level document node. */
|
|
238
|
+
doc: {
|
|
239
|
+
readonly content: ContentExpr<"block">;
|
|
240
|
+
};
|
|
241
|
+
/** A plain paragraph textblock. Represented in the DOM as a `<p>` element. */
|
|
242
|
+
paragraph: {
|
|
243
|
+
readonly content: ContentExpr<"inline">;
|
|
244
|
+
readonly group: "block";
|
|
245
|
+
readonly parseDOM: readonly [{
|
|
246
|
+
readonly tag: "p";
|
|
247
|
+
}];
|
|
248
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
249
|
+
};
|
|
250
|
+
/** A blockquote (`<blockquote>`) wrapping one or more blocks. */
|
|
251
|
+
blockquote: {
|
|
252
|
+
readonly content: ContentExpr<"block">;
|
|
253
|
+
readonly group: "block";
|
|
254
|
+
readonly defining: true;
|
|
255
|
+
readonly parseDOM: readonly [{
|
|
256
|
+
readonly tag: "blockquote";
|
|
257
|
+
}];
|
|
258
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
259
|
+
};
|
|
260
|
+
/** A horizontal rule (`<hr>`). */
|
|
261
|
+
horizontal_rule: {
|
|
262
|
+
readonly group: "block";
|
|
263
|
+
readonly parseDOM: readonly [{
|
|
264
|
+
readonly tag: "hr";
|
|
265
|
+
}];
|
|
266
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* A heading textblock, with a `level` attribute that should hold the
|
|
270
|
+
* number 1 to 6. Parsed and serialized as `<h1>` to `<h6>` elements.
|
|
271
|
+
*/
|
|
272
|
+
heading: {
|
|
273
|
+
readonly attrs: {
|
|
274
|
+
readonly level: {
|
|
275
|
+
readonly schema: S.Number;
|
|
276
|
+
readonly default: 1;
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
readonly content: ContentExpr<"inline">;
|
|
280
|
+
readonly group: "block";
|
|
281
|
+
readonly defining: true;
|
|
282
|
+
readonly parseDOM: readonly [{
|
|
283
|
+
readonly tag: "h1";
|
|
284
|
+
readonly attrs: {
|
|
285
|
+
readonly level: 1;
|
|
286
|
+
};
|
|
287
|
+
}, {
|
|
288
|
+
readonly tag: "h2";
|
|
289
|
+
readonly attrs: {
|
|
290
|
+
readonly level: 2;
|
|
291
|
+
};
|
|
292
|
+
}, {
|
|
293
|
+
readonly tag: "h3";
|
|
294
|
+
readonly attrs: {
|
|
295
|
+
readonly level: 3;
|
|
296
|
+
};
|
|
297
|
+
}, {
|
|
298
|
+
readonly tag: "h4";
|
|
299
|
+
readonly attrs: {
|
|
300
|
+
readonly level: 4;
|
|
301
|
+
};
|
|
302
|
+
}, {
|
|
303
|
+
readonly tag: "h5";
|
|
304
|
+
readonly attrs: {
|
|
305
|
+
readonly level: 5;
|
|
306
|
+
};
|
|
307
|
+
}, {
|
|
308
|
+
readonly tag: "h6";
|
|
309
|
+
readonly attrs: {
|
|
310
|
+
readonly level: 6;
|
|
311
|
+
};
|
|
312
|
+
}];
|
|
313
|
+
readonly toDOM: (node: Node<any, any>) => [string, number];
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* A code listing. Disallows marks or non-text inline nodes by default.
|
|
317
|
+
* Represented as a `<pre>` element with a `<code>` element inside of
|
|
318
|
+
* it.
|
|
319
|
+
*/
|
|
320
|
+
code_block: {
|
|
321
|
+
readonly content: ContentExpr<"text">;
|
|
322
|
+
readonly marks: "";
|
|
323
|
+
readonly group: "block";
|
|
324
|
+
readonly code: true;
|
|
325
|
+
readonly defining: true;
|
|
326
|
+
readonly parseDOM: readonly [{
|
|
327
|
+
readonly tag: "pre";
|
|
328
|
+
readonly preserveWhitespace: "full";
|
|
329
|
+
}];
|
|
330
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
331
|
+
};
|
|
332
|
+
/** The text node. */
|
|
333
|
+
text: {
|
|
334
|
+
readonly group: "inline";
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* An inline image (`<img>`) node. Supports `src`, `alt`, and `title`
|
|
338
|
+
* attributes. The latter two default to `null`.
|
|
339
|
+
*/
|
|
340
|
+
image: {
|
|
341
|
+
readonly inline: true;
|
|
342
|
+
readonly attrs: {
|
|
343
|
+
readonly src: S.String;
|
|
344
|
+
readonly alt: {
|
|
345
|
+
readonly schema: S.NullOr<S.String>;
|
|
346
|
+
readonly default: null;
|
|
347
|
+
};
|
|
348
|
+
readonly title: {
|
|
349
|
+
readonly schema: S.NullOr<S.String>;
|
|
350
|
+
readonly default: null;
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
readonly group: "inline";
|
|
354
|
+
readonly draggable: true;
|
|
355
|
+
readonly parseDOM: readonly [{
|
|
356
|
+
readonly tag: "img[src]";
|
|
357
|
+
readonly getAttrs: (dom: HTMLElement) => {
|
|
358
|
+
src: string | null;
|
|
359
|
+
title: string | null;
|
|
360
|
+
alt: string | null;
|
|
361
|
+
};
|
|
362
|
+
}];
|
|
363
|
+
readonly toDOM: (node: Node<any, any>) => [string, {
|
|
364
|
+
src: any;
|
|
365
|
+
alt: any;
|
|
366
|
+
title: any;
|
|
367
|
+
}];
|
|
368
|
+
};
|
|
369
|
+
/** A hard line break, represented in the DOM as `<br>`. */
|
|
370
|
+
hard_break: {
|
|
371
|
+
readonly inline: true;
|
|
372
|
+
readonly group: "inline";
|
|
373
|
+
readonly selectable: false;
|
|
374
|
+
readonly parseDOM: readonly [{
|
|
375
|
+
readonly tag: "br";
|
|
376
|
+
}];
|
|
377
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
378
|
+
};
|
|
379
|
+
}, {
|
|
380
|
+
/**
|
|
381
|
+
* A link. Has `href` and `title` attributes. `title` defaults to
|
|
382
|
+
* `null`. Rendered and parsed as an `<a>` element.
|
|
383
|
+
*/
|
|
384
|
+
link: {
|
|
385
|
+
readonly attrs: {
|
|
386
|
+
readonly href: S.String;
|
|
387
|
+
readonly title: {
|
|
388
|
+
readonly schema: S.NullOr<S.String>;
|
|
389
|
+
readonly default: null;
|
|
390
|
+
};
|
|
391
|
+
};
|
|
392
|
+
readonly inclusive: false;
|
|
393
|
+
readonly parseDOM: readonly [{
|
|
394
|
+
readonly tag: "a[href]";
|
|
395
|
+
readonly getAttrs: (dom: HTMLElement) => {
|
|
396
|
+
href: string | null;
|
|
397
|
+
title: string | null;
|
|
398
|
+
};
|
|
399
|
+
}];
|
|
400
|
+
readonly toDOM: (node: Mark<any, any>) => [string, {
|
|
401
|
+
href: any;
|
|
402
|
+
title: any;
|
|
403
|
+
}, number];
|
|
404
|
+
};
|
|
405
|
+
/** An emphasis mark. Rendered as an `<em>` element. */
|
|
406
|
+
em: {
|
|
407
|
+
readonly parseDOM: readonly [{
|
|
408
|
+
readonly tag: "i";
|
|
409
|
+
}, {
|
|
410
|
+
readonly tag: "em";
|
|
411
|
+
}, {
|
|
412
|
+
readonly style: "font-style=italic";
|
|
413
|
+
}, {
|
|
414
|
+
readonly style: "font-style=normal";
|
|
415
|
+
readonly clearMark: (m: Mark<any, any>) => boolean;
|
|
416
|
+
}];
|
|
417
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
418
|
+
};
|
|
419
|
+
/** A strong mark. Rendered as `<strong>`, parse rules also match `<b>` and `font-weight: bold`. */
|
|
420
|
+
strong: {
|
|
421
|
+
readonly parseDOM: readonly [{
|
|
422
|
+
readonly tag: "strong";
|
|
423
|
+
}, {
|
|
424
|
+
readonly tag: "b";
|
|
425
|
+
readonly getAttrs: (node: HTMLElement) => false | null;
|
|
426
|
+
}, {
|
|
427
|
+
readonly style: "font-weight=400";
|
|
428
|
+
readonly clearMark: (m: Mark<any, any>) => boolean;
|
|
429
|
+
}, {
|
|
430
|
+
readonly style: "font-weight";
|
|
431
|
+
readonly getAttrs: (value: string) => false | null;
|
|
432
|
+
}];
|
|
433
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
434
|
+
};
|
|
435
|
+
/** Code font mark. Represented as a `<code>` element. */
|
|
436
|
+
code: {
|
|
437
|
+
readonly code: true;
|
|
438
|
+
readonly parseDOM: readonly [{
|
|
439
|
+
readonly tag: "code";
|
|
440
|
+
}];
|
|
441
|
+
readonly toDOM: () => readonly any[] | readonly [string, ...any[]];
|
|
442
|
+
};
|
|
443
|
+
}>;
|
|
444
|
+
/**
|
|
445
|
+
* @since 0.1.0
|
|
446
|
+
* @category schemas
|
|
447
|
+
*/
|
|
448
|
+
export type BasicSchema = typeof schema;
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { oneOrMore, zeroOrMore } from "./model/content.js";
|
|
2
|
+
import { DocSchema, markSpec, nodeSpec } from "./model/schema.js";
|
|
3
|
+
import * as S from "effect/Schema";
|
|
4
|
+
// src/schema-basic.ts
|
|
5
|
+
/**
|
|
6
|
+
* A basic document schema, ported from `prosemirror-schema-basic`.
|
|
7
|
+
*
|
|
8
|
+
* It supports paragraphs, blockquotes, horizontal rules, headings, code
|
|
9
|
+
* blocks, images, hard breaks, and the `link`, `em`, `strong` and
|
|
10
|
+
* `code` marks. It is mostly useful as an example and a starting point
|
|
11
|
+
* for your own schemas.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.1.0
|
|
14
|
+
*/
|
|
15
|
+
const pDOM = ["p", 0];
|
|
16
|
+
const blockquoteDOM = ["blockquote", 0];
|
|
17
|
+
const hrDOM = ["hr"];
|
|
18
|
+
const preDOM = ["pre", ["code", 0]];
|
|
19
|
+
const brDOM = ["br"];
|
|
20
|
+
/**
|
|
21
|
+
* The node specs of the basic schema.
|
|
22
|
+
*
|
|
23
|
+
* @since 0.1.0
|
|
24
|
+
* @category specs
|
|
25
|
+
*/
|
|
26
|
+
const nodes = {
|
|
27
|
+
/** The top level document node. */
|
|
28
|
+
doc: nodeSpec({ content: oneOrMore("block") }),
|
|
29
|
+
/** A plain paragraph textblock. Represented in the DOM as a `<p>` element. */
|
|
30
|
+
paragraph: nodeSpec({
|
|
31
|
+
content: zeroOrMore("inline"),
|
|
32
|
+
group: "block",
|
|
33
|
+
parseDOM: [{ tag: "p" }],
|
|
34
|
+
toDOM() {
|
|
35
|
+
return pDOM;
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
38
|
+
/** A blockquote (`<blockquote>`) wrapping one or more blocks. */
|
|
39
|
+
blockquote: nodeSpec({
|
|
40
|
+
content: oneOrMore("block"),
|
|
41
|
+
group: "block",
|
|
42
|
+
defining: true,
|
|
43
|
+
parseDOM: [{ tag: "blockquote" }],
|
|
44
|
+
toDOM() {
|
|
45
|
+
return blockquoteDOM;
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
/** A horizontal rule (`<hr>`). */
|
|
49
|
+
horizontal_rule: nodeSpec({
|
|
50
|
+
group: "block",
|
|
51
|
+
parseDOM: [{ tag: "hr" }],
|
|
52
|
+
toDOM() {
|
|
53
|
+
return hrDOM;
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
56
|
+
/**
|
|
57
|
+
* A heading textblock, with a `level` attribute that should hold the
|
|
58
|
+
* number 1 to 6. Parsed and serialized as `<h1>` to `<h6>` elements.
|
|
59
|
+
*/
|
|
60
|
+
heading: nodeSpec({
|
|
61
|
+
attrs: { level: {
|
|
62
|
+
schema: S.Number,
|
|
63
|
+
default: 1
|
|
64
|
+
} },
|
|
65
|
+
content: zeroOrMore("inline"),
|
|
66
|
+
group: "block",
|
|
67
|
+
defining: true,
|
|
68
|
+
parseDOM: [
|
|
69
|
+
{
|
|
70
|
+
tag: "h1",
|
|
71
|
+
attrs: { level: 1 }
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
tag: "h2",
|
|
75
|
+
attrs: { level: 2 }
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
tag: "h3",
|
|
79
|
+
attrs: { level: 3 }
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
tag: "h4",
|
|
83
|
+
attrs: { level: 4 }
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
tag: "h5",
|
|
87
|
+
attrs: { level: 5 }
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
tag: "h6",
|
|
91
|
+
attrs: { level: 6 }
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
toDOM(node) {
|
|
95
|
+
return ["h" + node.attrs.level, 0];
|
|
96
|
+
}
|
|
97
|
+
}),
|
|
98
|
+
/**
|
|
99
|
+
* A code listing. Disallows marks or non-text inline nodes by default.
|
|
100
|
+
* Represented as a `<pre>` element with a `<code>` element inside of
|
|
101
|
+
* it.
|
|
102
|
+
*/
|
|
103
|
+
code_block: nodeSpec({
|
|
104
|
+
content: zeroOrMore("text"),
|
|
105
|
+
marks: "",
|
|
106
|
+
group: "block",
|
|
107
|
+
code: true,
|
|
108
|
+
defining: true,
|
|
109
|
+
parseDOM: [{
|
|
110
|
+
tag: "pre",
|
|
111
|
+
preserveWhitespace: "full"
|
|
112
|
+
}],
|
|
113
|
+
toDOM() {
|
|
114
|
+
return preDOM;
|
|
115
|
+
}
|
|
116
|
+
}),
|
|
117
|
+
/** The text node. */
|
|
118
|
+
text: nodeSpec({ group: "inline" }),
|
|
119
|
+
/**
|
|
120
|
+
* An inline image (`<img>`) node. Supports `src`, `alt`, and `title`
|
|
121
|
+
* attributes. The latter two default to `null`.
|
|
122
|
+
*/
|
|
123
|
+
image: nodeSpec({
|
|
124
|
+
inline: true,
|
|
125
|
+
attrs: {
|
|
126
|
+
src: S.String,
|
|
127
|
+
alt: {
|
|
128
|
+
schema: S.NullOr(S.String),
|
|
129
|
+
default: null
|
|
130
|
+
},
|
|
131
|
+
title: {
|
|
132
|
+
schema: S.NullOr(S.String),
|
|
133
|
+
default: null
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
group: "inline",
|
|
137
|
+
draggable: true,
|
|
138
|
+
parseDOM: [{
|
|
139
|
+
tag: "img[src]",
|
|
140
|
+
getAttrs(dom) {
|
|
141
|
+
return {
|
|
142
|
+
src: dom.getAttribute("src"),
|
|
143
|
+
title: dom.getAttribute("title"),
|
|
144
|
+
alt: dom.getAttribute("alt")
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}],
|
|
148
|
+
toDOM(node) {
|
|
149
|
+
const { alt, src, title } = node.attrs;
|
|
150
|
+
return ["img", {
|
|
151
|
+
src,
|
|
152
|
+
alt,
|
|
153
|
+
title
|
|
154
|
+
}];
|
|
155
|
+
}
|
|
156
|
+
}),
|
|
157
|
+
/** A hard line break, represented in the DOM as `<br>`. */
|
|
158
|
+
hard_break: nodeSpec({
|
|
159
|
+
inline: true,
|
|
160
|
+
group: "inline",
|
|
161
|
+
selectable: false,
|
|
162
|
+
parseDOM: [{ tag: "br" }],
|
|
163
|
+
toDOM() {
|
|
164
|
+
return brDOM;
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
};
|
|
168
|
+
const emDOM = ["em", 0];
|
|
169
|
+
const strongDOM = ["strong", 0];
|
|
170
|
+
const codeDOM = ["code", 0];
|
|
171
|
+
/**
|
|
172
|
+
* The mark specs of the basic schema.
|
|
173
|
+
*
|
|
174
|
+
* @since 0.1.0
|
|
175
|
+
* @category specs
|
|
176
|
+
*/
|
|
177
|
+
const marks = {
|
|
178
|
+
/**
|
|
179
|
+
* A link. Has `href` and `title` attributes. `title` defaults to
|
|
180
|
+
* `null`. Rendered and parsed as an `<a>` element.
|
|
181
|
+
*/
|
|
182
|
+
link: markSpec({
|
|
183
|
+
attrs: {
|
|
184
|
+
href: S.String,
|
|
185
|
+
title: {
|
|
186
|
+
schema: S.NullOr(S.String),
|
|
187
|
+
default: null
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
inclusive: false,
|
|
191
|
+
parseDOM: [{
|
|
192
|
+
tag: "a[href]",
|
|
193
|
+
getAttrs(dom) {
|
|
194
|
+
return {
|
|
195
|
+
href: dom.getAttribute("href"),
|
|
196
|
+
title: dom.getAttribute("title")
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}],
|
|
200
|
+
toDOM(node) {
|
|
201
|
+
const { href, title } = node.attrs;
|
|
202
|
+
return [
|
|
203
|
+
"a",
|
|
204
|
+
{
|
|
205
|
+
href,
|
|
206
|
+
title
|
|
207
|
+
},
|
|
208
|
+
0
|
|
209
|
+
];
|
|
210
|
+
}
|
|
211
|
+
}),
|
|
212
|
+
/** An emphasis mark. Rendered as an `<em>` element. */
|
|
213
|
+
em: markSpec({
|
|
214
|
+
parseDOM: [
|
|
215
|
+
{ tag: "i" },
|
|
216
|
+
{ tag: "em" },
|
|
217
|
+
{ style: "font-style=italic" },
|
|
218
|
+
{
|
|
219
|
+
style: "font-style=normal",
|
|
220
|
+
clearMark: (m) => m.type.name === "em"
|
|
221
|
+
}
|
|
222
|
+
],
|
|
223
|
+
toDOM() {
|
|
224
|
+
return emDOM;
|
|
225
|
+
}
|
|
226
|
+
}),
|
|
227
|
+
/** A strong mark. Rendered as `<strong>`, parse rules also match `<b>` and `font-weight: bold`. */
|
|
228
|
+
strong: markSpec({
|
|
229
|
+
parseDOM: [
|
|
230
|
+
{ tag: "strong" },
|
|
231
|
+
{
|
|
232
|
+
tag: "b",
|
|
233
|
+
getAttrs: (node) => node.style.fontWeight !== "normal" && null
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
style: "font-weight=400",
|
|
237
|
+
clearMark: (m) => m.type.name === "strong"
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
style: "font-weight",
|
|
241
|
+
getAttrs: (value) => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null
|
|
242
|
+
}
|
|
243
|
+
],
|
|
244
|
+
toDOM() {
|
|
245
|
+
return strongDOM;
|
|
246
|
+
}
|
|
247
|
+
}),
|
|
248
|
+
/** Code font mark. Represented as a `<code>` element. */
|
|
249
|
+
code: markSpec({
|
|
250
|
+
code: true,
|
|
251
|
+
parseDOM: [{ tag: "code" }],
|
|
252
|
+
toDOM() {
|
|
253
|
+
return codeDOM;
|
|
254
|
+
}
|
|
255
|
+
})
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* This schema roughly corresponds to the document schema used by
|
|
259
|
+
* CommonMark, minus the list elements, which are defined in the
|
|
260
|
+
* `schema-list` module.
|
|
261
|
+
*
|
|
262
|
+
* @since 0.1.0
|
|
263
|
+
* @category schemas
|
|
264
|
+
*/
|
|
265
|
+
const schema = DocSchema.makeUnsafe({
|
|
266
|
+
nodes,
|
|
267
|
+
marks
|
|
268
|
+
});
|
|
269
|
+
export { marks, nodes, schema };
|