@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,740 @@
|
|
|
1
|
+
import { ContentInput, ContentMatch, SpecRefs } from "./content.js";
|
|
2
|
+
import { ParseRule, TagParseRule } from "./from_dom.js";
|
|
3
|
+
import { DOMOutputSpec } from "./to_dom.js";
|
|
4
|
+
import "./dom.js";
|
|
5
|
+
import { AttributeError, ContentError, JSONError, ModelError, SchemaDefinitionError } from "./errors.js";
|
|
6
|
+
import { Fragment } from "./fragment.js";
|
|
7
|
+
import { Mark } from "./mark.js";
|
|
8
|
+
import { Node, TextNode } from "./node.js";
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
import * as Option from "effect/Option";
|
|
11
|
+
import * as S from "effect/Schema";
|
|
12
|
+
/**
|
|
13
|
+
* Describes a single attribute of a node or mark type.
|
|
14
|
+
*
|
|
15
|
+
* - `schema` is an Effect `Schema` used to validate the value and to
|
|
16
|
+
* decode/encode it from/to JSON. It also gives the attribute its
|
|
17
|
+
* static type.
|
|
18
|
+
* - `default` is used when no value is provided. Attributes without a
|
|
19
|
+
* default are required.
|
|
20
|
+
* - `validate` is accepted for ProseMirror compatibility: either a
|
|
21
|
+
* `|`-separated list of primitive type names or a function that
|
|
22
|
+
* throws on invalid values.
|
|
23
|
+
*
|
|
24
|
+
* Supplied values are validated whenever a node or mark is created (as
|
|
25
|
+
* prosemirror-model does since 1.25.12), and again by `Node.check`;
|
|
26
|
+
* defaults are trusted. A `schema` or a type-name `validate` rejects a
|
|
27
|
+
* value with an `AttributeError`; a `validate` function's own exception
|
|
28
|
+
* propagates as thrown (a defect in the Effect API).
|
|
29
|
+
*
|
|
30
|
+
* @since 0.1.0
|
|
31
|
+
* @category models
|
|
32
|
+
*/
|
|
33
|
+
export interface AttributeSpec<A = any, I = any> {
|
|
34
|
+
readonly schema?: S.Codec<A, I> | undefined;
|
|
35
|
+
readonly default?: A;
|
|
36
|
+
readonly validate?: string | ((value: unknown) => void) | undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* An attribute is either described by an `AttributeSpec` or, as a
|
|
40
|
+
* shorthand for a required attribute, directly by an Effect `Schema`.
|
|
41
|
+
*
|
|
42
|
+
* @since 0.1.0
|
|
43
|
+
* @category models
|
|
44
|
+
*/
|
|
45
|
+
export type AttributeDefinition = S.Top | AttributeSpec;
|
|
46
|
+
/**
|
|
47
|
+
* @since 0.1.0
|
|
48
|
+
* @category models
|
|
49
|
+
*/
|
|
50
|
+
export interface AttributeDefinitions {
|
|
51
|
+
readonly [name: string]: AttributeDefinition;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A description of a node type, used when defining a schema.
|
|
55
|
+
*
|
|
56
|
+
* @since 0.1.0
|
|
57
|
+
* @category models
|
|
58
|
+
*/
|
|
59
|
+
export interface NodeSpec {
|
|
60
|
+
/**
|
|
61
|
+
* The content expression for this node. When not given, the node
|
|
62
|
+
* does not allow any content. Prefer `Content` combinators, which
|
|
63
|
+
* keep the allowed child types at the type level; a plain string is
|
|
64
|
+
* read as ProseMirror content syntax (`"paragraph block*"`), and is
|
|
65
|
+
* only precisely typed when it is a single bare name.
|
|
66
|
+
*/
|
|
67
|
+
readonly content?: ContentInput<string> | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* The marks that are allowed inside of this node. May be a
|
|
70
|
+
* space-separated string referring to mark names or groups, `"_"` to
|
|
71
|
+
* explicitly allow all marks, or `""` to disallow marks. When not
|
|
72
|
+
* given, nodes with inline content default to allowing all marks,
|
|
73
|
+
* other nodes default to not allowing marks.
|
|
74
|
+
*/
|
|
75
|
+
readonly marks?: string | undefined;
|
|
76
|
+
/** The group or space-separated groups to which this node belongs. */
|
|
77
|
+
readonly group?: string | undefined;
|
|
78
|
+
/** Should be set to true for inline nodes. (Implied for text nodes.) */
|
|
79
|
+
readonly inline?: boolean | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Can be set to true to indicate that, though this isn't a leaf node,
|
|
82
|
+
* it doesn't have directly editable content and should be treated as
|
|
83
|
+
* a single unit in the view.
|
|
84
|
+
*/
|
|
85
|
+
readonly atom?: boolean | undefined;
|
|
86
|
+
/** The attributes that nodes of this type get. */
|
|
87
|
+
readonly attrs?: AttributeDefinitions | undefined;
|
|
88
|
+
/** Whether nodes of this type can be selected as a node selection. */
|
|
89
|
+
readonly selectable?: boolean | undefined;
|
|
90
|
+
/** Whether nodes of this type can be dragged without being selected. */
|
|
91
|
+
readonly draggable?: boolean | undefined;
|
|
92
|
+
/** Indicates that this node contains code. */
|
|
93
|
+
readonly code?: boolean | undefined;
|
|
94
|
+
/** Controls the way whitespace in this node is parsed. */
|
|
95
|
+
readonly whitespace?: "pre" | "normal" | undefined;
|
|
96
|
+
/** Whether this node is considered an important parent during replace operations. */
|
|
97
|
+
readonly definingAsContext?: boolean | undefined;
|
|
98
|
+
/** Whether defining parents of inserted content are preserved. */
|
|
99
|
+
readonly definingForContent?: boolean | undefined;
|
|
100
|
+
/** Enables both `definingAsContext` and `definingForContent`. */
|
|
101
|
+
readonly defining?: boolean | undefined;
|
|
102
|
+
/** Whether the sides of nodes of this type count as editing boundaries. */
|
|
103
|
+
readonly isolating?: boolean | undefined;
|
|
104
|
+
/** Defines the default way a node of this type should be serialized to DOM/HTML. */
|
|
105
|
+
readonly toDOM?: ((node: Node<any, any>) => DOMOutputSpec) | undefined;
|
|
106
|
+
/** DOM parser rules for this node type. */
|
|
107
|
+
readonly parseDOM?: ReadonlyArray<TagParseRule> | undefined;
|
|
108
|
+
/** Defines the way a node of this type is rendered for debugging. */
|
|
109
|
+
readonly toDebugString?: ((node: Node<any, any>) => string) | undefined;
|
|
110
|
+
/** Defines the way a leaf node of this type is serialized to a string. */
|
|
111
|
+
readonly leafText?: ((node: Node<any, any>) => string) | undefined;
|
|
112
|
+
/** Marks this (inline leaf) node as the schema's linebreak equivalent. */
|
|
113
|
+
readonly linebreakReplacement?: boolean | undefined;
|
|
114
|
+
/** Node specs may include arbitrary extra properties. */
|
|
115
|
+
readonly [key: string]: unknown;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Used to define marks when creating a schema.
|
|
119
|
+
*
|
|
120
|
+
* @since 0.1.0
|
|
121
|
+
* @category models
|
|
122
|
+
*/
|
|
123
|
+
export interface MarkSpec {
|
|
124
|
+
/** The attributes that marks of this type get. */
|
|
125
|
+
readonly attrs?: AttributeDefinitions | undefined;
|
|
126
|
+
/** Whether this mark should be active when the cursor is positioned at its end. Defaults to true. */
|
|
127
|
+
readonly inclusive?: boolean | undefined;
|
|
128
|
+
/** Space-separated mark names or groups this mark excludes. */
|
|
129
|
+
readonly excludes?: string | undefined;
|
|
130
|
+
/** The group or space-separated groups to which this mark belongs. */
|
|
131
|
+
readonly group?: string | undefined;
|
|
132
|
+
/** Whether marks of this type can span multiple adjacent nodes when serialized. Defaults to true. */
|
|
133
|
+
readonly spanning?: boolean | undefined;
|
|
134
|
+
/** Marks the content of this span as being code. */
|
|
135
|
+
readonly code?: boolean | undefined;
|
|
136
|
+
/** Defines the default way marks of this type should be serialized to DOM/HTML. */
|
|
137
|
+
readonly toDOM?: ((mark: Mark<any, any>, inline: boolean) => DOMOutputSpec) | undefined;
|
|
138
|
+
/** DOM parser rules for this mark type. */
|
|
139
|
+
readonly parseDOM?: ReadonlyArray<ParseRule> | undefined;
|
|
140
|
+
/** Mark specs may include arbitrary extra properties. */
|
|
141
|
+
readonly [key: string]: unknown;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* @since 0.1.0
|
|
145
|
+
* @category models
|
|
146
|
+
*/
|
|
147
|
+
export interface NodeSpecs {
|
|
148
|
+
readonly [name: string]: NodeSpec;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* @since 0.1.0
|
|
152
|
+
* @category models
|
|
153
|
+
*/
|
|
154
|
+
export interface MarkSpecs {
|
|
155
|
+
readonly [name: string]: MarkSpec;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* An object describing a schema, as passed to `DocSchema.make`.
|
|
159
|
+
*
|
|
160
|
+
* The order of `nodes` and `marks` is significant: it determines which
|
|
161
|
+
* parse rules take precedence by default, which nodes come first in a
|
|
162
|
+
* given group, and the order of marks in mark sets.
|
|
163
|
+
*
|
|
164
|
+
* @since 0.1.0
|
|
165
|
+
* @category models
|
|
166
|
+
*/
|
|
167
|
+
export interface SchemaSpec<N extends NodeSpecs = NodeSpecs, M extends MarkSpecs = MarkSpecs, Top extends string = string> {
|
|
168
|
+
readonly nodes: N;
|
|
169
|
+
readonly marks?: M | undefined;
|
|
170
|
+
/** The name of the default top-level node. Defaults to `"doc"`. */
|
|
171
|
+
readonly topNode?: Top | undefined;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* A schema of unknown shape.
|
|
175
|
+
*
|
|
176
|
+
* @since 0.1.0
|
|
177
|
+
* @category type-level
|
|
178
|
+
*/
|
|
179
|
+
export type AnySchema = DocSchema<any, any>;
|
|
180
|
+
/**
|
|
181
|
+
* The node specs of a schema.
|
|
182
|
+
*
|
|
183
|
+
* @since 0.1.0
|
|
184
|
+
* @category type-level
|
|
185
|
+
*/
|
|
186
|
+
export type NodeSpecsOf<Sc> = Sc extends DocSchema<infer N, any> ? N : never;
|
|
187
|
+
/**
|
|
188
|
+
* The mark specs of a schema.
|
|
189
|
+
*
|
|
190
|
+
* @since 0.1.0
|
|
191
|
+
* @category type-level
|
|
192
|
+
*/
|
|
193
|
+
export type MarkSpecsOf<Sc> = Sc extends DocSchema<any, infer M> ? M : never;
|
|
194
|
+
/**
|
|
195
|
+
* The names of a schema's node types.
|
|
196
|
+
*
|
|
197
|
+
* @since 0.1.0
|
|
198
|
+
* @category type-level
|
|
199
|
+
*/
|
|
200
|
+
export type NodeNames<Sc> = keyof NodeSpecsOf<Sc> & string;
|
|
201
|
+
/**
|
|
202
|
+
* The names of a schema's mark types.
|
|
203
|
+
*
|
|
204
|
+
* @since 0.1.0
|
|
205
|
+
* @category type-level
|
|
206
|
+
*/
|
|
207
|
+
export type MarkNames<Sc> = keyof MarkSpecsOf<Sc> & string;
|
|
208
|
+
/**
|
|
209
|
+
* The spec of node type `N` in schema `Sc`.
|
|
210
|
+
*
|
|
211
|
+
* @since 0.1.0
|
|
212
|
+
* @category type-level
|
|
213
|
+
*/
|
|
214
|
+
export type NodeSpecOf<Sc, N extends string> = NodeSpecsOf<Sc> extends (infer Specs) ? (N extends keyof Specs ? Specs[N] : NodeSpec) : NodeSpec;
|
|
215
|
+
/**
|
|
216
|
+
* The spec of mark type `M` in schema `Sc`.
|
|
217
|
+
*
|
|
218
|
+
* @since 0.1.0
|
|
219
|
+
* @category type-level
|
|
220
|
+
*/
|
|
221
|
+
export type MarkSpecOf<Sc, M extends string> = MarkSpecsOf<Sc> extends (infer Specs) ? (M extends keyof Specs ? Specs[M] : MarkSpec) : MarkSpec;
|
|
222
|
+
type Split<Str extends string> = string extends Str ? string : Str extends `${infer H} ${infer T}` ? (H extends "" ? never : H) | Split<T> : Str extends "" ? never : Str;
|
|
223
|
+
/**
|
|
224
|
+
* The groups a spec belongs to.
|
|
225
|
+
*
|
|
226
|
+
* @since 0.1.0
|
|
227
|
+
* @category type-level
|
|
228
|
+
*/
|
|
229
|
+
export type GroupsOf<Spec> = Spec extends {
|
|
230
|
+
readonly group: infer G extends string;
|
|
231
|
+
} ? Split<G> : never;
|
|
232
|
+
/**
|
|
233
|
+
* The names (of nodes or groups) referenced in a spec's content
|
|
234
|
+
* expression.
|
|
235
|
+
*
|
|
236
|
+
* @since 0.1.0
|
|
237
|
+
* @category type-level
|
|
238
|
+
*/
|
|
239
|
+
export type ContentRefsOf<Spec> = Spec extends {
|
|
240
|
+
readonly content: infer C;
|
|
241
|
+
} ? SpecRefs<C> : never;
|
|
242
|
+
/**
|
|
243
|
+
* The names of the node types that can appear as children of node type
|
|
244
|
+
* `N` in schema `Sc`.
|
|
245
|
+
*
|
|
246
|
+
* @since 0.1.0
|
|
247
|
+
* @category type-level
|
|
248
|
+
*/
|
|
249
|
+
export type ChildNames<Sc, N extends string> = string extends NodeNames<Sc> ? string : string extends N ? NodeNames<Sc> : ResolveRefs<Sc, ContentRefsOf<NodeSpecOf<Sc, N>>>;
|
|
250
|
+
/**
|
|
251
|
+
* Resolve a set of node/group names to the node names they denote.
|
|
252
|
+
*
|
|
253
|
+
* @since 0.1.0
|
|
254
|
+
* @category type-level
|
|
255
|
+
*/
|
|
256
|
+
export type ResolveRefs<Sc, R extends string> = string extends R ? NodeNames<Sc> : { [C in NodeNames<Sc>]: C extends R ? C : [GroupsOf<NodeSpecOf<Sc, C>> & R] extends [never] ? never : C; }[NodeNames<Sc>];
|
|
257
|
+
/**
|
|
258
|
+
* The names of node types in schema `Sc` that belong to group `G`.
|
|
259
|
+
*
|
|
260
|
+
* @since 0.1.0
|
|
261
|
+
* @category type-level
|
|
262
|
+
*/
|
|
263
|
+
export type NodesInGroup<Sc, G extends string> = ResolveRefs<Sc, G>;
|
|
264
|
+
/**
|
|
265
|
+
* The names of all mark types in group `G` of schema `Sc`.
|
|
266
|
+
*
|
|
267
|
+
* @since 0.1.0
|
|
268
|
+
* @category type-level
|
|
269
|
+
*/
|
|
270
|
+
export type MarksInGroup<Sc, G extends string> = string extends MarkNames<Sc> ? string : { [C in MarkNames<Sc>]: C extends G ? C : [GroupsOf<MarkSpecOf<Sc, C>> & G] extends [never] ? never : C; }[MarkNames<Sc>];
|
|
271
|
+
type Widen<A> = A extends string ? string : A extends number ? number : A extends boolean ? boolean : A extends null | undefined ? unknown : A;
|
|
272
|
+
interface ValidateTypeNames {
|
|
273
|
+
readonly string: string;
|
|
274
|
+
readonly number: number;
|
|
275
|
+
readonly boolean: boolean;
|
|
276
|
+
readonly bigint: bigint;
|
|
277
|
+
readonly symbol: symbol;
|
|
278
|
+
readonly undefined: undefined;
|
|
279
|
+
readonly object: object;
|
|
280
|
+
readonly function: (...args: ReadonlyArray<never>) => void;
|
|
281
|
+
readonly null: null;
|
|
282
|
+
}
|
|
283
|
+
type SplitBar<V extends string> = V extends `${infer H}|${infer T}` ? H | SplitBar<T> : V;
|
|
284
|
+
type ValidateType<V extends string> = string extends V ? unknown : SplitBar<V> extends (infer K) ? K extends keyof ValidateTypeNames ? ValidateTypeNames[K] : never : never;
|
|
285
|
+
/**
|
|
286
|
+
* The value type of an attribute definition: its `schema`'s type; else
|
|
287
|
+
* the types its `validate` type names admit (`"string|null"` is
|
|
288
|
+
* `string | null`); else the widened type of its `default`. An attribute
|
|
289
|
+
* with none of these (a ProseMirror-style `{ default: null }`, or a
|
|
290
|
+
* `validate` function) is `unknown`: nothing says what it holds.
|
|
291
|
+
*
|
|
292
|
+
* @since 0.1.0
|
|
293
|
+
* @category type-level
|
|
294
|
+
*/
|
|
295
|
+
export type AttributeType<D> = D extends S.Top ? D["Type"] : D extends {
|
|
296
|
+
readonly schema: infer Sc extends S.Top;
|
|
297
|
+
} ? Sc["Type"] : D extends {
|
|
298
|
+
readonly validate: infer V extends string;
|
|
299
|
+
} ? ValidateType<V> : D extends {
|
|
300
|
+
readonly default: infer A;
|
|
301
|
+
} ? Widen<A> : unknown;
|
|
302
|
+
type AttrDefsOf<Spec> = Spec extends {
|
|
303
|
+
readonly attrs: infer A extends AttributeDefinitions;
|
|
304
|
+
} ? A : {};
|
|
305
|
+
/**
|
|
306
|
+
* The (complete) attributes object for a node or mark spec.
|
|
307
|
+
*
|
|
308
|
+
* @since 0.1.0
|
|
309
|
+
* @category type-level
|
|
310
|
+
*/
|
|
311
|
+
export type AttrsOfSpec<Spec> = [Spec] extends [never] ? Attrs : string extends keyof AttrDefsOf<Spec> ? Attrs : { readonly [K in keyof AttrDefsOf<Spec>]: AttributeType<AttrDefsOf<Spec>[K]>; };
|
|
312
|
+
type OptionalAttrKeys<D> = { [K in keyof D]: D[K] extends {
|
|
313
|
+
readonly default?: any;
|
|
314
|
+
} ? K : never; }[keyof D];
|
|
315
|
+
/**
|
|
316
|
+
* The attributes accepted when creating a node or mark from a spec:
|
|
317
|
+
* attributes with defaults may be omitted.
|
|
318
|
+
*
|
|
319
|
+
* @since 0.1.0
|
|
320
|
+
* @category type-level
|
|
321
|
+
*/
|
|
322
|
+
export type AttrsInputOfSpec<Spec> = [Spec] extends [never] ? Attrs : string extends keyof AttrDefsOf<Spec> ? Attrs : Simplify<{ readonly [K in Exclude<keyof AttrDefsOf<Spec>, OptionalAttrKeys<AttrDefsOf<Spec>>>]: AttributeType<AttrDefsOf<Spec>[K]>; } & { readonly [K in OptionalAttrKeys<AttrDefsOf<Spec>>]?: AttributeType<AttrDefsOf<Spec>[K]>; }>;
|
|
323
|
+
type Simplify<A> = { [K in keyof A]: A[K]; } & {};
|
|
324
|
+
/**
|
|
325
|
+
* The attributes of node type `N` in schema `Sc`.
|
|
326
|
+
*
|
|
327
|
+
* @since 0.1.0
|
|
328
|
+
* @category type-level
|
|
329
|
+
*/
|
|
330
|
+
export type NodeAttrs<Sc, N extends string> = string extends NodeNames<Sc> ? Attrs : N extends any ? AttrsOfSpec<NodeSpecOf<Sc, N>> : never;
|
|
331
|
+
/**
|
|
332
|
+
* The attributes accepted when creating a node of type `N`.
|
|
333
|
+
*
|
|
334
|
+
* @since 0.1.0
|
|
335
|
+
* @category type-level
|
|
336
|
+
*/
|
|
337
|
+
export type NodeAttrsInput<Sc, N extends string> = string extends NodeNames<Sc> ? Attrs : AttrsInputOfSpec<NodeSpecOf<Sc, N>>;
|
|
338
|
+
/**
|
|
339
|
+
* The attributes of mark type `M` in schema `Sc`.
|
|
340
|
+
*
|
|
341
|
+
* @since 0.1.0
|
|
342
|
+
* @category type-level
|
|
343
|
+
*/
|
|
344
|
+
export type MarkAttrs<Sc, M extends string> = string extends MarkNames<Sc> ? Attrs : M extends any ? AttrsOfSpec<MarkSpecOf<Sc, M>> : never;
|
|
345
|
+
/**
|
|
346
|
+
* The attributes accepted when creating a mark of type `M`.
|
|
347
|
+
*
|
|
348
|
+
* @since 0.1.0
|
|
349
|
+
* @category type-level
|
|
350
|
+
*/
|
|
351
|
+
export type MarkAttrsInput<Sc, M extends string> = string extends MarkNames<Sc> ? Attrs : AttrsInputOfSpec<MarkSpecOf<Sc, M>>;
|
|
352
|
+
/**
|
|
353
|
+
* True when all attributes of the spec have defaults (or there are
|
|
354
|
+
* none), meaning the attrs argument can be omitted.
|
|
355
|
+
*
|
|
356
|
+
* @since 0.1.0
|
|
357
|
+
* @category type-level
|
|
358
|
+
*/
|
|
359
|
+
export type AttrsOptional<Spec> = {} extends AttrsInputOfSpec<Spec> ? true : false;
|
|
360
|
+
type GroupNames<Specs> = { [K in keyof Specs]: GroupsOf<Specs[K]>; }[keyof Specs];
|
|
361
|
+
type UnknownRefs<Refs, Known> = string extends Refs ? never : Exclude<Refs, Known>;
|
|
362
|
+
type MarkExprRefs<Spec, Key extends string> = Spec extends { readonly [P in Key]: infer E extends string; } ? Split<E> : never;
|
|
363
|
+
type Fail<Bad, Message extends string> = [Bad] extends [never] ? unknown : { readonly [P in Message]: true; };
|
|
364
|
+
type BadDefaults<Defs> = { [K in keyof Defs]: Defs[K] extends {
|
|
365
|
+
readonly schema: infer Sch extends S.Top;
|
|
366
|
+
readonly default: infer D;
|
|
367
|
+
} ? [D] extends [Sch["Type"]] ? never : K : never; }[keyof Defs] & string;
|
|
368
|
+
type BadDefaultsOf<Spec> = BadDefaults<AttrDefsOf<Spec>>;
|
|
369
|
+
type BadValidateNames<Defs> = { [K in keyof Defs]: Defs[K] extends {
|
|
370
|
+
readonly validate: infer V extends string;
|
|
371
|
+
} ? string extends V ? never : Exclude<SplitBar<V>, keyof ValidateTypeNames> : never; }[keyof Defs] & string;
|
|
372
|
+
type BadValidateNamesOf<Spec> = BadValidateNames<AttrDefsOf<Spec>>;
|
|
373
|
+
type MarkRefNames<M> = (keyof M & string) | GroupNames<M> | "_";
|
|
374
|
+
type UnknownContent<N, K extends keyof N> = UnknownRefs<ContentRefsOf<N[K]>, (keyof N & string) | GroupNames<N>> & string;
|
|
375
|
+
type UnknownMarks<M, Spec, Key extends string> = UnknownRefs<MarkExprRefs<Spec, Key>, MarkRefNames<M>> & string;
|
|
376
|
+
type NodeSpecCheck<N, M, K extends keyof N> = Fail<UnknownContent<N, K>, `Unknown node type or group in content: ${UnknownContent<N, K>}`> & Fail<UnknownMarks<M, N[K], "marks">, `Unknown mark type or group in marks: ${UnknownMarks<M, N[K], "marks">}`> & Fail<BadDefaultsOf<N[K]>, `Attribute default is not a value of its schema: ${BadDefaultsOf<N[K]>}`> & Fail<BadValidateNamesOf<N[K]>, `Unknown type name in validate: ${BadValidateNamesOf<N[K]>}`>;
|
|
377
|
+
type MarkSpecCheck<M, K extends keyof M> = Fail<UnknownMarks<M, M[K], "excludes">, `Unknown mark type or group in excludes: ${UnknownMarks<M, M[K], "excludes">}`> & Fail<BadDefaultsOf<M[K]>, `Attribute default is not a value of its schema: ${BadDefaultsOf<M[K]>}`> & Fail<BadValidateNamesOf<M[K]>, `Unknown type name in validate: ${BadValidateNamesOf<M[K]>}`>;
|
|
378
|
+
/**
|
|
379
|
+
* The static checks `DocSchema.make` applies to a spec, on top of its
|
|
380
|
+
* type: every name a content expression, a `marks` expression or an
|
|
381
|
+
* `excludes` refers to exists; the top node and a `text` node exist; no
|
|
382
|
+
* name is both a node and a mark; every attribute `default` is a value
|
|
383
|
+
* of the attribute's `schema`; and every `validate` type name is one the
|
|
384
|
+
* runtime knows. These are the runtime
|
|
385
|
+
* `SchemaDefinitionError`s, reported where the spec is written. Each check
|
|
386
|
+
* applies only where the names are known statically: a ProseMirror
|
|
387
|
+
* content string with operators, or an untyped spec, is left to the
|
|
388
|
+
* runtime check.
|
|
389
|
+
*
|
|
390
|
+
* @since 0.1.0
|
|
391
|
+
* @category type-level
|
|
392
|
+
*/
|
|
393
|
+
export type SchemaSpecCheck<N, M, Top extends string> = string extends keyof N ? unknown : {
|
|
394
|
+
readonly nodes: { readonly [K in keyof N]: NodeSpecCheck<N, M, K>; } & { readonly [K in (string extends Top ? never : Top) | "text"]: NodeSpec; };
|
|
395
|
+
} & (string extends keyof M ? unknown : {
|
|
396
|
+
readonly marks?: { readonly [K in keyof M]: MarkSpecCheck<M, K>; } & { readonly [K in keyof M & keyof N]: Fail<K, `Name used by both a node and a mark: ${K & string}`>; };
|
|
397
|
+
});
|
|
398
|
+
/**
|
|
399
|
+
* The node types of schema `Sc` whose attributes all have defaults (or
|
|
400
|
+
* that have none), so their constructors may be called without an
|
|
401
|
+
* attributes object. For other types, the attributes are a required
|
|
402
|
+
* argument, so a required attribute cannot be left out by omitting the
|
|
403
|
+
* whole object.
|
|
404
|
+
*
|
|
405
|
+
* @since 0.1.0
|
|
406
|
+
* @category type-level
|
|
407
|
+
*/
|
|
408
|
+
export type NodesWithOptionalAttrs<Sc> = { [K in NodeNames<Sc>]: Partial<NodeAttrsInput<Sc, K>> extends NodeAttrsInput<Sc, K> ? K : never; }[NodeNames<Sc>];
|
|
409
|
+
/**
|
|
410
|
+
* The mark types of schema `Sc` whose attributes all have defaults (see
|
|
411
|
+
* `NodesWithOptionalAttrs`).
|
|
412
|
+
*
|
|
413
|
+
* @since 0.1.0
|
|
414
|
+
* @category type-level
|
|
415
|
+
*/
|
|
416
|
+
export type MarksWithOptionalAttrs<Sc> = { [K in MarkNames<Sc>]: Partial<MarkAttrsInput<Sc, K>> extends MarkAttrsInput<Sc, K> ? K : never; }[MarkNames<Sc>];
|
|
417
|
+
/**
|
|
418
|
+
* An untyped attributes object.
|
|
419
|
+
*
|
|
420
|
+
* @since 0.1.0
|
|
421
|
+
* @category models
|
|
422
|
+
*/
|
|
423
|
+
export type Attrs = {
|
|
424
|
+
readonly [attr: string]: any;
|
|
425
|
+
};
|
|
426
|
+
/**
|
|
427
|
+
* The marks given to a node constructor: a mark set, or nothing (`null`
|
|
428
|
+
* or `undefined`) for none.
|
|
429
|
+
*
|
|
430
|
+
* @since 0.1.0
|
|
431
|
+
* @category models
|
|
432
|
+
*/
|
|
433
|
+
export type MarksInput<Sc extends AnySchema = AnySchema> = ReadonlyArray<Mark<Sc>> | null | undefined;
|
|
434
|
+
/**
|
|
435
|
+
* Anything that can be converted to a fragment of `N` nodes.
|
|
436
|
+
*
|
|
437
|
+
* @since 0.1.0
|
|
438
|
+
* @category models
|
|
439
|
+
*/
|
|
440
|
+
export type FragmentInput<Sc extends AnySchema = AnySchema, N extends string = string> = Fragment<Sc, N> | Node<Sc, N> | ReadonlyArray<Node<Sc, N>> | null | undefined;
|
|
441
|
+
/** @internal */
|
|
442
|
+
export declare class Attribute {
|
|
443
|
+
readonly hasDefault: boolean;
|
|
444
|
+
readonly default: unknown;
|
|
445
|
+
readonly schema: S.Codec<any, any> | undefined;
|
|
446
|
+
readonly validate: ((value: unknown) => void) | undefined;
|
|
447
|
+
readonly is: ((value: unknown) => boolean) | undefined;
|
|
448
|
+
readonly identityCodec: boolean;
|
|
449
|
+
constructor(typeName: string, attrName: string, definition: AttributeDefinition);
|
|
450
|
+
get isRequired(): boolean;
|
|
451
|
+
}
|
|
452
|
+
/** @internal */
|
|
453
|
+
export declare function computeAttrs(attrs: Record<string, Attribute>, value: Attrs | null | undefined, type: string, typeName: string, decoded?: boolean): Attrs;
|
|
454
|
+
/** @internal */
|
|
455
|
+
export declare function checkAttrs(attrs: Record<string, Attribute>, values: Attrs, type: string, typeName: string): void;
|
|
456
|
+
/**
|
|
457
|
+
* Node types are objects allocated once per schema and used to tag
|
|
458
|
+
* `Node` instances. They contain information about the node type, such
|
|
459
|
+
* as its name and what kind of node it represents.
|
|
460
|
+
*
|
|
461
|
+
* @since 0.1.0
|
|
462
|
+
* @category models
|
|
463
|
+
*/
|
|
464
|
+
export declare class NodeType<Sc extends AnySchema = AnySchema, out N extends NodeNames<Sc> = NodeNames<Sc>> {
|
|
465
|
+
/** The name the node type has in this schema. */
|
|
466
|
+
readonly name: N;
|
|
467
|
+
/** A link back to the schema the node type belongs to. */
|
|
468
|
+
readonly schema: Sc;
|
|
469
|
+
/** The spec that this type is based on. */
|
|
470
|
+
readonly spec: NodeSpecOf<Sc, N> & NodeSpec;
|
|
471
|
+
/** @internal */
|
|
472
|
+
readonly groups: ReadonlyArray<string>;
|
|
473
|
+
/** @internal */
|
|
474
|
+
readonly attrs: Record<string, Attribute>;
|
|
475
|
+
/** @internal */
|
|
476
|
+
readonly defaultAttrs: Attrs | null;
|
|
477
|
+
/** @internal Every attribute's codec is the identity: JSON attrs are the attrs. */
|
|
478
|
+
readonly identityAttrs: boolean;
|
|
479
|
+
/** True if this is a block type. */
|
|
480
|
+
readonly isBlock: boolean;
|
|
481
|
+
/** True if this is the text node type. */
|
|
482
|
+
readonly isText: boolean;
|
|
483
|
+
/** True if this node type has inline content. */
|
|
484
|
+
inlineContent: boolean;
|
|
485
|
+
/** The starting match of the node type's content expression. */
|
|
486
|
+
contentMatch: ContentMatch;
|
|
487
|
+
/** The set of marks allowed in this node. `null` means all marks are allowed. */
|
|
488
|
+
markSet: ReadonlyArray<MarkType<Sc>> | null;
|
|
489
|
+
/** @internal */
|
|
490
|
+
constructor(
|
|
491
|
+
/** The name the node type has in this schema. */
|
|
492
|
+
name: N,
|
|
493
|
+
/** A link back to the schema the node type belongs to. */
|
|
494
|
+
schema: Sc,
|
|
495
|
+
/** The spec that this type is based on. */
|
|
496
|
+
spec: NodeSpecOf<Sc, N> & NodeSpec);
|
|
497
|
+
/** True if this is an inline type. */
|
|
498
|
+
get isInline(): boolean;
|
|
499
|
+
/** True if this is a textblock type, a block that contains inline content. */
|
|
500
|
+
get isTextblock(): boolean;
|
|
501
|
+
/** True for node types that allow no content. */
|
|
502
|
+
get isLeaf(): boolean;
|
|
503
|
+
/** True when this node is an atom, i.e. when it does not have directly editable content. */
|
|
504
|
+
get isAtom(): boolean;
|
|
505
|
+
/** Return true when this node type is part of the given group. */
|
|
506
|
+
isInGroup(group: string): boolean;
|
|
507
|
+
/** The node type's whitespace option. */
|
|
508
|
+
get whitespace(): "pre" | "normal";
|
|
509
|
+
/** Tells you whether this node type has any required attributes. */
|
|
510
|
+
hasRequiredAttrs(): boolean;
|
|
511
|
+
/** Indicates whether this node allows some of the same content as the given node type. */
|
|
512
|
+
compatibleContent(other: NodeType<any, any>): boolean;
|
|
513
|
+
/** @internal */
|
|
514
|
+
computeAttrs(attrs: Attrs | null | undefined): Attrs;
|
|
515
|
+
/**
|
|
516
|
+
* Create a node of this type. Attributes are extended with defaults,
|
|
517
|
+
* and supplied attribute values are validated (see `AttributeSpec`);
|
|
518
|
+
* content is not checked against the content expression (see
|
|
519
|
+
* `createChecked`).
|
|
520
|
+
*/
|
|
521
|
+
create(this: NodeType<Sc, NodesWithOptionalAttrs<Sc>>, attrs?: NodeAttrsInput<Sc, N> | null, content?: FragmentInput<Sc, ChildNames<Sc, N>>, marks?: MarksInput<Sc>): Effect.Effect<Node<Sc, N>, AttributeError | ContentError>;
|
|
522
|
+
create(attrs: NodeAttrsInput<Sc, N>, content?: FragmentInput<Sc, ChildNames<Sc, N>>, marks?: MarksInput<Sc>): Effect.Effect<Node<Sc, N>, AttributeError | ContentError>;
|
|
523
|
+
/** Like `create`, but throws an `AttributeError` on failure. */
|
|
524
|
+
createUnsafe(this: NodeType<Sc, NodesWithOptionalAttrs<Sc>>, attrs?: NodeAttrsInput<Sc, N> | null, content?: FragmentInput<Sc, ChildNames<Sc, N>>, marks?: MarksInput<Sc>): Node<Sc, N>;
|
|
525
|
+
createUnsafe(attrs: NodeAttrsInput<Sc, N>, content?: FragmentInput<Sc, ChildNames<Sc, N>>, marks?: MarksInput<Sc>): Node<Sc, N>;
|
|
526
|
+
/**
|
|
527
|
+
* Like `createUnsafe`, for attributes already decoded by their Schemas.
|
|
528
|
+
*
|
|
529
|
+
* @internal
|
|
530
|
+
*/
|
|
531
|
+
createDecodedUnsafe(attrs: Option.Option<Attrs>, content: Fragment<Sc>, marks: ReadonlyArray<Mark<Sc>>): Node<Sc, N>;
|
|
532
|
+
private computeDecodedAttrs;
|
|
533
|
+
/**
|
|
534
|
+
* Like `create`, but check the given content against the node type's
|
|
535
|
+
* content restrictions.
|
|
536
|
+
*/
|
|
537
|
+
createChecked(this: NodeType<Sc, NodesWithOptionalAttrs<Sc>>, attrs?: NodeAttrsInput<Sc, N> | null, content?: FragmentInput<Sc, ChildNames<Sc, N>>, marks?: MarksInput<Sc>): Effect.Effect<Node<Sc, N>, AttributeError | ContentError>;
|
|
538
|
+
createChecked(attrs: NodeAttrsInput<Sc, N>, content?: FragmentInput<Sc, ChildNames<Sc, N>>, marks?: MarksInput<Sc>): Effect.Effect<Node<Sc, N>, AttributeError | ContentError>;
|
|
539
|
+
/** Like `createChecked`, but throws on failure. */
|
|
540
|
+
createCheckedUnsafe(this: NodeType<Sc, NodesWithOptionalAttrs<Sc>>, attrs?: NodeAttrsInput<Sc, N> | null, content?: FragmentInput<Sc, ChildNames<Sc, N>>, marks?: MarksInput<Sc>): Node<Sc, N>;
|
|
541
|
+
createCheckedUnsafe(attrs: NodeAttrsInput<Sc, N>, content?: FragmentInput<Sc, ChildNames<Sc, N>>, marks?: MarksInput<Sc>): Node<Sc, N>;
|
|
542
|
+
/**
|
|
543
|
+
* Like `create`, but see if it is necessary to add nodes to the start
|
|
544
|
+
* or end of the given fragment to make it fit the node. Fails with a
|
|
545
|
+
* `ContentError` if no fitting wrapping can be found. Note that, due
|
|
546
|
+
* to the fact that required nodes can always be created, this will
|
|
547
|
+
* always succeed if you pass no content.
|
|
548
|
+
*/
|
|
549
|
+
createAndFill(this: NodeType<Sc, NodesWithOptionalAttrs<Sc>>, attrs?: NodeAttrsInput<Sc, N> | null, content?: FragmentInput<Sc, ChildNames<Sc, N>>, marks?: MarksInput<Sc>): Effect.Effect<Node<Sc, N>, AttributeError | ContentError>;
|
|
550
|
+
createAndFill(attrs: NodeAttrsInput<Sc, N>, content?: FragmentInput<Sc, ChildNames<Sc, N>>, marks?: MarksInput<Sc>): Effect.Effect<Node<Sc, N>, AttributeError | ContentError>;
|
|
551
|
+
/** @internal */
|
|
552
|
+
createAndFillOrNull(attrs?: Attrs | null, content?: FragmentInput<any, any>, marks?: ReadonlyArray<Mark<any>> | null): Node<Sc, N> | null;
|
|
553
|
+
/** Returns true if the given fragment is valid content for this node type. */
|
|
554
|
+
validContent(content: Fragment<any, any>): boolean;
|
|
555
|
+
/** @internal */
|
|
556
|
+
checkContent(content: Fragment<any, any>): void;
|
|
557
|
+
/** @internal */
|
|
558
|
+
checkAttrs(attrs: Attrs): void;
|
|
559
|
+
/** Check whether the given mark type is allowed in this node. */
|
|
560
|
+
allowsMarkType(markType: MarkType<any, any>): boolean;
|
|
561
|
+
/** Test whether the given set of marks are allowed in this node. */
|
|
562
|
+
allowsMarks(marks: ReadonlyArray<Mark<any>>): boolean;
|
|
563
|
+
/** Removes the marks that are not allowed in this node from the given set. */
|
|
564
|
+
allowedMarks<M extends Mark<any>>(marks: ReadonlyArray<M>): ReadonlyArray<M>;
|
|
565
|
+
/** @internal */
|
|
566
|
+
toString(): string;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Like nodes, marks are tagged with type objects, which are
|
|
570
|
+
* instantiated once per schema.
|
|
571
|
+
*
|
|
572
|
+
* @since 0.1.0
|
|
573
|
+
* @category models
|
|
574
|
+
*/
|
|
575
|
+
export declare class MarkType<Sc extends AnySchema = AnySchema, out M extends MarkNames<Sc> = MarkNames<Sc>> {
|
|
576
|
+
/** The name of the mark type. */
|
|
577
|
+
readonly name: M;
|
|
578
|
+
/** @internal */
|
|
579
|
+
readonly rank: number;
|
|
580
|
+
/** The schema that this mark type instance is part of. */
|
|
581
|
+
readonly schema: Sc;
|
|
582
|
+
/** The spec on which the type is based. */
|
|
583
|
+
readonly spec: MarkSpecOf<Sc, M> & MarkSpec;
|
|
584
|
+
/** @internal */
|
|
585
|
+
readonly attrs: Record<string, Attribute>;
|
|
586
|
+
/** @internal Every attribute's codec is the identity: JSON attrs are the attrs. */
|
|
587
|
+
readonly identityAttrs: boolean;
|
|
588
|
+
/** @internal */
|
|
589
|
+
excluded: ReadonlyArray<MarkType<Sc>>;
|
|
590
|
+
/** @internal */
|
|
591
|
+
readonly instance: Option.Option<Mark<Sc, M>>;
|
|
592
|
+
/** @internal */
|
|
593
|
+
constructor(
|
|
594
|
+
/** The name of the mark type. */
|
|
595
|
+
name: M,
|
|
596
|
+
/** @internal */
|
|
597
|
+
rank: number,
|
|
598
|
+
/** The schema that this mark type instance is part of. */
|
|
599
|
+
schema: Sc,
|
|
600
|
+
/** The spec on which the type is based. */
|
|
601
|
+
spec: MarkSpecOf<Sc, M> & MarkSpec);
|
|
602
|
+
/**
|
|
603
|
+
* Create a mark of this type. Attributes that are not given are
|
|
604
|
+
* filled in from their defaults; supplied values are validated (see
|
|
605
|
+
* `AttributeSpec`).
|
|
606
|
+
*/
|
|
607
|
+
create(this: MarkType<Sc, MarksWithOptionalAttrs<Sc>>, attrs?: MarkAttrsInput<Sc, M>): Effect.Effect<Mark<Sc, M>, AttributeError>;
|
|
608
|
+
create(attrs: MarkAttrsInput<Sc, M>): Effect.Effect<Mark<Sc, M>, AttributeError>;
|
|
609
|
+
/** Like `create`, but throws an `AttributeError` on failure. */
|
|
610
|
+
createUnsafe(this: MarkType<Sc, MarksWithOptionalAttrs<Sc>>, attrs?: MarkAttrsInput<Sc, M>): Mark<Sc, M>;
|
|
611
|
+
createUnsafe(attrs: MarkAttrsInput<Sc, M>): Mark<Sc, M>;
|
|
612
|
+
/**
|
|
613
|
+
* Like `createUnsafe`, for attributes already decoded by their Schemas.
|
|
614
|
+
*
|
|
615
|
+
* @internal
|
|
616
|
+
*/
|
|
617
|
+
createDecodedUnsafe(attrs: Option.Option<Attrs>): Mark<Sc, M>;
|
|
618
|
+
/**
|
|
619
|
+
* When there is a mark of this type in the given set, a new set
|
|
620
|
+
* without it is returned. Otherwise, the input set is returned.
|
|
621
|
+
*/
|
|
622
|
+
removeFromSet<Mk extends Mark<any>>(set: ReadonlyArray<Mk>): ReadonlyArray<Mk>;
|
|
623
|
+
/** Find a mark of this type in the given set. */
|
|
624
|
+
isInSet(set: ReadonlyArray<Mark<any>>): Option.Option<Mark<Sc, M>>;
|
|
625
|
+
/** @internal */
|
|
626
|
+
findInSet(set: ReadonlyArray<Mark<any>>): Mark<Sc, M> | undefined;
|
|
627
|
+
/** @internal */
|
|
628
|
+
checkAttrs(attrs: Attrs): void;
|
|
629
|
+
/** Queries whether a given mark type is excluded by this one. */
|
|
630
|
+
excludes(other: MarkType<any, any>): boolean;
|
|
631
|
+
/** @internal */
|
|
632
|
+
toString(): string;
|
|
633
|
+
}
|
|
634
|
+
type NodeTypes<Sc extends AnySchema, N extends NodeSpecs> = { readonly [K in keyof N & string]: NodeType<Sc, K>; };
|
|
635
|
+
type MarkTypes<Sc extends AnySchema, M extends MarkSpecs> = { readonly [K in keyof M & string]: MarkType<Sc, K>; };
|
|
636
|
+
/**
|
|
637
|
+
* A document schema. Holds node and mark type objects for the nodes and
|
|
638
|
+
* marks that may occur in conforming documents, and provides
|
|
639
|
+
* functionality for creating and deserializing such documents.
|
|
640
|
+
*
|
|
641
|
+
* @since 0.1.0
|
|
642
|
+
* @category models
|
|
643
|
+
*/
|
|
644
|
+
export declare class DocSchema<N extends NodeSpecs = NodeSpecs, M extends MarkSpecs = MarkSpecs> {
|
|
645
|
+
/** The spec on which the schema is based. */
|
|
646
|
+
readonly spec: {
|
|
647
|
+
readonly nodes: N;
|
|
648
|
+
readonly marks: M;
|
|
649
|
+
readonly topNode?: string | undefined;
|
|
650
|
+
};
|
|
651
|
+
/** An object mapping the schema's node names to node type objects. */
|
|
652
|
+
readonly nodes: NodeTypes<DocSchema<N, M>, N> & Readonly<Partial<Record<string, NodeType<DocSchema<N, M>>>>>;
|
|
653
|
+
/** A map from mark names to mark type objects. */
|
|
654
|
+
readonly marks: MarkTypes<DocSchema<N, M>, M> & Readonly<Partial<Record<string, MarkType<DocSchema<N, M>>>>>;
|
|
655
|
+
/** The linebreak replacement node defined in this schema, if any. */
|
|
656
|
+
readonly linebreakReplacement: Option.Option<NodeType<DocSchema<N, M>>>;
|
|
657
|
+
/** The type of the default top node for this schema. */
|
|
658
|
+
readonly topNodeType: NodeType<DocSchema<N, M>>;
|
|
659
|
+
/**
|
|
660
|
+
* An object for storing whatever values modules may want to compute
|
|
661
|
+
* and cache per schema.
|
|
662
|
+
*/
|
|
663
|
+
readonly cached: Record<string, unknown>;
|
|
664
|
+
/** @internal */
|
|
665
|
+
constructor(spec: SchemaSpec<N, M>);
|
|
666
|
+
/**
|
|
667
|
+
* Construct a schema from a schema specification. A spec with literal
|
|
668
|
+
* names is also checked statically (`SchemaSpecCheck`): an unknown
|
|
669
|
+
* content, `marks` or `excludes` reference, a missing top or `text`
|
|
670
|
+
* node, a name used by both a node and a mark, a `default` outside its
|
|
671
|
+
* `schema` or an unknown `validate` type name fails to compile, where the
|
|
672
|
+
* runtime would fail with a `SchemaDefinitionError`.
|
|
673
|
+
*/
|
|
674
|
+
static make<const N extends NodeSpecs, const M extends MarkSpecs = {}, const Top extends string = "doc">(spec: SchemaSpec<N, M, Top> & NoInfer<SchemaSpecCheck<N, M, Top>>): Effect.Effect<DocSchema<N, M>, SchemaDefinitionError>;
|
|
675
|
+
/** Like `make`, but throws a `SchemaDefinitionError` for invalid specs. */
|
|
676
|
+
static makeUnsafe<const N extends NodeSpecs, const M extends MarkSpecs = {}, const Top extends string = "doc">(spec: SchemaSpec<N, M, Top> & NoInfer<SchemaSpecCheck<N, M, Top>>): DocSchema<N, M>;
|
|
677
|
+
/**
|
|
678
|
+
* Create a node in this schema. Attributes are extended with
|
|
679
|
+
* defaults and the content is checked against the node type's
|
|
680
|
+
* content expression.
|
|
681
|
+
*/
|
|
682
|
+
node<K extends NodesWithOptionalAttrs<DocSchema<N, M>>>(type: K | NodeType<DocSchema<N, M>, K>, attrs?: NodeAttrsInput<DocSchema<N, M>, K> | null, content?: FragmentInput<DocSchema<N, M>, ChildNames<DocSchema<N, M>, K>>, marks?: MarksInput<DocSchema<N, M>>): Effect.Effect<Node<DocSchema<N, M>, K>, AttributeError | ContentError>;
|
|
683
|
+
node<K extends keyof N & string>(type: K | NodeType<DocSchema<N, M>, K>, attrs: NodeAttrsInput<DocSchema<N, M>, K>, content?: FragmentInput<DocSchema<N, M>, ChildNames<DocSchema<N, M>, K>>, marks?: MarksInput<DocSchema<N, M>>): Effect.Effect<Node<DocSchema<N, M>, K>, AttributeError | ContentError>;
|
|
684
|
+
/** Like `node`, but throws on failure. */
|
|
685
|
+
nodeUnsafe<K extends NodesWithOptionalAttrs<DocSchema<N, M>>>(type: K | NodeType<DocSchema<N, M>, K>, attrs?: NodeAttrsInput<DocSchema<N, M>, K> | null, content?: FragmentInput<DocSchema<N, M>, ChildNames<DocSchema<N, M>, K>>, marks?: MarksInput<DocSchema<N, M>>): Node<DocSchema<N, M>, K>;
|
|
686
|
+
nodeUnsafe<K extends keyof N & string>(type: K | NodeType<DocSchema<N, M>, K>, attrs: NodeAttrsInput<DocSchema<N, M>, K>, content?: FragmentInput<DocSchema<N, M>, ChildNames<DocSchema<N, M>, K>>, marks?: MarksInput<DocSchema<N, M>>): Node<DocSchema<N, M>, K>;
|
|
687
|
+
/**
|
|
688
|
+
* Create a text node in the schema. Fails for empty strings, since
|
|
689
|
+
* empty text nodes are not allowed.
|
|
690
|
+
*/
|
|
691
|
+
text(text: string, marks?: MarksInput<DocSchema<N, M>>): Effect.Effect<TextNode<DocSchema<N, M>>, ContentError>;
|
|
692
|
+
/** Like `text`, but throws a `ContentError` for empty strings. */
|
|
693
|
+
textUnsafe(text: string, marks?: ReadonlyArray<Mark<DocSchema<N, M>>> | null): TextNode<DocSchema<N, M>>;
|
|
694
|
+
/** Create a mark with the given type and attributes. */
|
|
695
|
+
mark<K extends MarksWithOptionalAttrs<DocSchema<N, M>>>(type: K | MarkType<DocSchema<N, M>, K>, attrs?: MarkAttrsInput<DocSchema<N, M>, K>): Effect.Effect<Mark<DocSchema<N, M>, K>, AttributeError>;
|
|
696
|
+
mark<K extends keyof M & string>(type: K | MarkType<DocSchema<N, M>, K>, attrs: MarkAttrsInput<DocSchema<N, M>, K>): Effect.Effect<Mark<DocSchema<N, M>, K>, AttributeError>;
|
|
697
|
+
/** Like `mark`, but throws on failure. */
|
|
698
|
+
markUnsafe<K extends MarksWithOptionalAttrs<DocSchema<N, M>>>(type: K | MarkType<DocSchema<N, M>, K>, attrs?: MarkAttrsInput<DocSchema<N, M>, K>): Mark<DocSchema<N, M>, K>;
|
|
699
|
+
markUnsafe<K extends keyof M & string>(type: K | MarkType<DocSchema<N, M>, K>, attrs: MarkAttrsInput<DocSchema<N, M>, K>): Mark<DocSchema<N, M>, K>;
|
|
700
|
+
/** Deserialize a node from its JSON representation. */
|
|
701
|
+
nodeFromJSON(value: unknown): Effect.Effect<Node<DocSchema<N, M>>, JSONError | ModelError>;
|
|
702
|
+
/** Like `nodeFromJSON`, but throws on failure. */
|
|
703
|
+
nodeFromJSONUnsafe(value: unknown): Node<DocSchema<N, M>>;
|
|
704
|
+
/** Deserialize a mark from its JSON representation. */
|
|
705
|
+
markFromJSON(value: unknown): Effect.Effect<Mark<DocSchema<N, M>>, JSONError | ModelError>;
|
|
706
|
+
/** Like `markFromJSON`, but throws on failure. */
|
|
707
|
+
markFromJSONUnsafe(value: unknown): Mark<DocSchema<N, M>>;
|
|
708
|
+
/** @internal */
|
|
709
|
+
nodeType(name: string): NodeType<DocSchema<N, M>>;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Construct a schema from a specification.
|
|
713
|
+
*
|
|
714
|
+
* @since 0.1.0
|
|
715
|
+
* @category constructors
|
|
716
|
+
*/
|
|
717
|
+
export declare const make: typeof DocSchema.make;
|
|
718
|
+
/**
|
|
719
|
+
* Construct a schema from a specification, throwing on invalid specs.
|
|
720
|
+
*
|
|
721
|
+
* @since 0.1.0
|
|
722
|
+
* @category constructors
|
|
723
|
+
*/
|
|
724
|
+
export declare const makeUnsafe: typeof DocSchema.makeUnsafe;
|
|
725
|
+
/**
|
|
726
|
+
* Identity helper that gives a node spec's callbacks access to
|
|
727
|
+
* precisely typed attributes.
|
|
728
|
+
*
|
|
729
|
+
* @since 0.1.0
|
|
730
|
+
* @category constructors
|
|
731
|
+
*/
|
|
732
|
+
export declare const nodeSpec: <const Spec extends NodeSpec>(spec: Spec) => Spec;
|
|
733
|
+
/**
|
|
734
|
+
* Identity helper for mark specs.
|
|
735
|
+
*
|
|
736
|
+
* @since 0.1.0
|
|
737
|
+
* @category constructors
|
|
738
|
+
*/
|
|
739
|
+
export declare const markSpec: <const Spec extends MarkSpec>(spec: Spec) => Spec;
|
|
740
|
+
export {};
|