@nerd-bible/wordgard 0.0.0-beta3
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 +22 -0
- package/README.md +24 -0
- package/dist/collab.d.ts +105 -0
- package/dist/collab.js +218 -0
- package/dist/command.d.ts +808 -0
- package/dist/command.js +1479 -0
- package/dist/doc.d.ts +2227 -0
- package/dist/doc.js +3833 -0
- package/dist/editor.d.ts +1940 -0
- package/dist/editor.js +7616 -0
- package/dist/history.d.ts +90 -0
- package/dist/history.js +285 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/phrases.d.ts +90 -0
- package/dist/phrases.js +141 -0
- package/dist/schema.d.ts +579 -0
- package/dist/schema.js +1432 -0
- package/dist/state.d.ts +1382 -0
- package/dist/state.js +2047 -0
- package/dist/table.d.ts +215 -0
- package/dist/table.js +1303 -0
- package/dist/types.d.ts +196 -0
- package/dist/types.js +288 -0
- package/package.json +60 -0
package/dist/doc.d.ts
ADDED
|
@@ -0,0 +1,2227 @@
|
|
|
1
|
+
type DOMElement$1 = Element;
|
|
2
|
+
|
|
3
|
+
type DOMElement = Element;
|
|
4
|
+
/**
|
|
5
|
+
Parse the given DOM structure as a document, using the given
|
|
6
|
+
schema. By default the set of parse rules will be derived from the
|
|
7
|
+
schema, but it is possible to pass in a custom set.
|
|
8
|
+
*/
|
|
9
|
+
declare function parse(schema: Schema, doc: Element | DocumentFragment, options?: parse.Options): Plot.Doc;
|
|
10
|
+
declare namespace parse {
|
|
11
|
+
/**
|
|
12
|
+
Options that can be passed to parsing functions.
|
|
13
|
+
*/
|
|
14
|
+
type Options = {
|
|
15
|
+
/**
|
|
16
|
+
Controls whether HTML-style whitespace collapsing is used
|
|
17
|
+
(outside nodes that don't enable `preserveWhitespace`). Defaults
|
|
18
|
+
to true.
|
|
19
|
+
*/
|
|
20
|
+
collapseWhiteSpace?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
Function used in in {@link parse.slice} to determine
|
|
23
|
+
whether a given element is open (on either side).
|
|
24
|
+
*/
|
|
25
|
+
isOpen?: (elt: Element) => null | "start" | "end" | "start end";
|
|
26
|
+
/**
|
|
27
|
+
The rule set to use. Defaults to the rule set derived from the
|
|
28
|
+
schema.
|
|
29
|
+
*/
|
|
30
|
+
ruleSet?: parse.Rule.Set;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
Parse the given DOM structure as a slice.
|
|
34
|
+
*/
|
|
35
|
+
function slice(schema: Schema, doc: Element | DocumentFragment, options?: parse.Options): {
|
|
36
|
+
slice: Slice;
|
|
37
|
+
context: Plot.Tag<unknown>[];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
Parse rules describe how DOM constructs should map to Wordgard
|
|
41
|
+
document nodes. Many can be automatically derived from node and
|
|
42
|
+
mark {@link Node.Spec.shape shapes}, but it is also often
|
|
43
|
+
useful to provide them directly.
|
|
44
|
+
*/
|
|
45
|
+
type Rule<Param = any> = Rule.Element<Param> | Rule.Attribute<Param>;
|
|
46
|
+
namespace Rule {
|
|
47
|
+
/**
|
|
48
|
+
Describes a rule that matches elements by selector.
|
|
49
|
+
*/
|
|
50
|
+
interface Element<Param> {
|
|
51
|
+
/**
|
|
52
|
+
The CSS selector that should match the element.
|
|
53
|
+
*/
|
|
54
|
+
selector: string;
|
|
55
|
+
/**
|
|
56
|
+
If this is a node-creating rule, this holds the type of node
|
|
57
|
+
to create when this rule matches. If this is a node type
|
|
58
|
+
without default parameter, you _must_ also define {@link
|
|
59
|
+
parse.Rule.Element.param} or {@link
|
|
60
|
+
parse.Rule.Element.readElement}.
|
|
61
|
+
*/
|
|
62
|
+
tag?: Leaf<Param> | Plot.Tag<Param> | Node.Type<Param>;
|
|
63
|
+
/**
|
|
64
|
+
Mark-creating rules should provide a mark or mark type here.
|
|
65
|
+
The mark will be applied to the content of the element.
|
|
66
|
+
Again, if the type lacks a parameter, {@link
|
|
67
|
+
parse.Rule.Element.param} or {@link
|
|
68
|
+
parse.Rule.Element.readElement} will be used to find it.
|
|
69
|
+
*/
|
|
70
|
+
mark?: Mark.Type<Param> | Mark<Param>;
|
|
71
|
+
/**
|
|
72
|
+
Instead of creating a node or mark, rules may tell the
|
|
73
|
+
parser to ignore a given element. `true` means discard it
|
|
74
|
+
entirely, `"skip"` means ignore the element itself, but do
|
|
75
|
+
parse its child nodes.
|
|
76
|
+
*/
|
|
77
|
+
ignore?: boolean | "skip";
|
|
78
|
+
/**
|
|
79
|
+
A parameter for the tag or mark type.
|
|
80
|
+
*/
|
|
81
|
+
param?: Param;
|
|
82
|
+
/**
|
|
83
|
+
A function that reads the parameter from the matched
|
|
84
|
+
element. May return {@link parse.Reject} to indicate
|
|
85
|
+
that the rule should not be applied to this element.
|
|
86
|
+
*/
|
|
87
|
+
readElement?: (element: DOMElement) => Param | typeof Reject;
|
|
88
|
+
/**
|
|
89
|
+
An optional CSS selector for finding an additional inner
|
|
90
|
+
element to read marks from.
|
|
91
|
+
*/
|
|
92
|
+
marksFrom?: string;
|
|
93
|
+
/**
|
|
94
|
+
By default, when applying a rule for a plot or mark type,
|
|
95
|
+
parsing continues with the element's direct children. You
|
|
96
|
+
can pass a selector or function here to select another content element.
|
|
97
|
+
*/
|
|
98
|
+
contentElement?: string | ((elt: DOMElement) => DOMElement);
|
|
99
|
+
/**
|
|
100
|
+
Ignore DOM nodes matching this selector or predicate, when
|
|
101
|
+
they appear in this plot's content element.
|
|
102
|
+
*/
|
|
103
|
+
ignoreContent?: string | ((elt: DOMElement) => boolean);
|
|
104
|
+
/**
|
|
105
|
+
A number between -10 and 10 (inclusive) that specifies the
|
|
106
|
+
relative precedence of this rule. Defaults to 0.
|
|
107
|
+
*/
|
|
108
|
+
precedence?: number;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
An attribute parse rule matches an attribute, instead of an
|
|
112
|
+
entire element. Such a rule can only create marks, not tags.
|
|
113
|
+
*/
|
|
114
|
+
interface Attribute<Param> {
|
|
115
|
+
/**
|
|
116
|
+
The attribute to look for. May have the form `style/color`
|
|
117
|
+
to look at a style property instead.
|
|
118
|
+
*/
|
|
119
|
+
attribute: string;
|
|
120
|
+
/**
|
|
121
|
+
When given, this rule only matches when the attribute has
|
|
122
|
+
this value.
|
|
123
|
+
*/
|
|
124
|
+
value?: string;
|
|
125
|
+
/**
|
|
126
|
+
The mark to create for this attribute, if any.
|
|
127
|
+
*/
|
|
128
|
+
mark?: Mark.Type<Param> | Mark<Param>;
|
|
129
|
+
/**
|
|
130
|
+
Remove a mark from the surrounding set of marks when this
|
|
131
|
+
rule matches.
|
|
132
|
+
*/
|
|
133
|
+
clearMark?: (mark: Mark<unknown>) => boolean;
|
|
134
|
+
/**
|
|
135
|
+
Can be set to true to cause the parser to ignore this
|
|
136
|
+
attribute.
|
|
137
|
+
*/
|
|
138
|
+
ignore?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
A parameter to give to the mark type in {@link
|
|
141
|
+
parse.Rule.Attribute.mark}.
|
|
142
|
+
*/
|
|
143
|
+
param?: Param;
|
|
144
|
+
/**
|
|
145
|
+
Read a parameter value from the attribute value. May return
|
|
146
|
+
{@link parse.Reject} to prevent the rule from matching.
|
|
147
|
+
*/
|
|
148
|
+
readAttribute?: (value: string) => Param | typeof Reject;
|
|
149
|
+
/**
|
|
150
|
+
Controls whether other rules may match this attribute after
|
|
151
|
+
this rule matches. Defaults to true.
|
|
152
|
+
*/
|
|
153
|
+
consuming?: boolean;
|
|
154
|
+
/**
|
|
155
|
+
A number between -10 and 10 (inclusive) that specifies the
|
|
156
|
+
relative precedence of this rule. Defaults to 0.
|
|
157
|
+
*/
|
|
158
|
+
precedence?: number;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
A collection of parse rules. Usually derived from a schema.
|
|
162
|
+
*/
|
|
163
|
+
class Set {
|
|
164
|
+
/**
|
|
165
|
+
The rules in this set.
|
|
166
|
+
*/
|
|
167
|
+
readonly rules: readonly Rule[];
|
|
168
|
+
private constructor();
|
|
169
|
+
/**
|
|
170
|
+
Create a rule set with the given parse rules.
|
|
171
|
+
*/
|
|
172
|
+
static of(rules: readonly Rule[]): Set;
|
|
173
|
+
/**
|
|
174
|
+
Create a rule set containing all the parse rules attached to
|
|
175
|
+
nodes and marks in the given schema, as well as the rules that
|
|
176
|
+
can be derived from the node and mark shape declarations.
|
|
177
|
+
*/
|
|
178
|
+
static fromSchema(schema: Schema): Set;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
A special value that parse rule functions can return to block
|
|
183
|
+
the rule from matching.
|
|
184
|
+
*/
|
|
185
|
+
const Reject: unique symbol;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
This class describes a DOM element, its attributes, and its
|
|
190
|
+
children. It is used in describing the structure of {@link
|
|
191
|
+
Node.Spec.shape nodes} and {@link editor.Decoration decorations}.
|
|
192
|
+
|
|
193
|
+
Elements can provide a wrapping structure by having a content hole
|
|
194
|
+
somewhere in their children, which indicates where the structure
|
|
195
|
+
they wrap (typically a node's content) goes.
|
|
196
|
+
|
|
197
|
+
The type parameter indicates the set of additional leaf types. By
|
|
198
|
+
default, it holds only `string` (as a shorthand for text nodes),
|
|
199
|
+
but elements used in decorations also support {@link editor.Widget
|
|
200
|
+
custom widgets}.
|
|
201
|
+
*/
|
|
202
|
+
declare class Elt<T = string> {
|
|
203
|
+
/**
|
|
204
|
+
The element's tag name. May be prefixed with `"svg:"` or
|
|
205
|
+
`"math:"` to indicate an SVG or MathML element.
|
|
206
|
+
*/
|
|
207
|
+
readonly tagName: string;
|
|
208
|
+
/**
|
|
209
|
+
The set of attributes, as an {@link Attributes array of
|
|
210
|
+
strings}.
|
|
211
|
+
*/
|
|
212
|
+
readonly attrs: Attributes;
|
|
213
|
+
/**
|
|
214
|
+
The element's children.
|
|
215
|
+
*/
|
|
216
|
+
readonly children: readonly (T | Elt<T> | 0)[];
|
|
217
|
+
private constructor();
|
|
218
|
+
/**
|
|
219
|
+
Create an element. See also {@link Elt.mk} for a more ergonomic
|
|
220
|
+
creation function.
|
|
221
|
+
*/
|
|
222
|
+
static create<T = string>(tagName: string, attrs: Attributes, children: readonly (T | Elt<T> | 0)[]): Elt<Exclude<T, Elt<any> | 0>>;
|
|
223
|
+
/**
|
|
224
|
+
Create an element, specifying the attributes as an object. Both
|
|
225
|
+
the set of attributesand the array of children are optional. The
|
|
226
|
+
literal number 0 is used to indicate a content hole in the
|
|
227
|
+
array of children.
|
|
228
|
+
*/
|
|
229
|
+
static mk<T = string>(name: string, children?: (T | 0 | Elt<T>)[]): Elt<Exclude<T, Elt<any> | 0>>;
|
|
230
|
+
static mk<T = string>(name: string, attrs: Record<string, string>, children?: readonly (T | 0 | Elt<T>)[]): Elt<Exclude<T, Elt<any> | 0>>;
|
|
231
|
+
/**
|
|
232
|
+
True if this element or one of its children has a content hole.
|
|
233
|
+
*/
|
|
234
|
+
get hasContent(): boolean;
|
|
235
|
+
/**
|
|
236
|
+
Compare this element's tag name and attributes (not its
|
|
237
|
+
children) to another element.
|
|
238
|
+
*/
|
|
239
|
+
eqTag(elt: Elt<any>): boolean;
|
|
240
|
+
/**
|
|
241
|
+
Compare this element (including its children) to another
|
|
242
|
+
element.
|
|
243
|
+
*/
|
|
244
|
+
eq(other: any): boolean;
|
|
245
|
+
private modifyBySelector;
|
|
246
|
+
/**
|
|
247
|
+
Convert an element with string content to an HTML string.
|
|
248
|
+
*/
|
|
249
|
+
toHTML(this: Elt<string>): string;
|
|
250
|
+
/**
|
|
251
|
+
Convert an element (with only string content) to a DOM tree.
|
|
252
|
+
*/
|
|
253
|
+
toDOM(this: Elt<string>, doc?: Document): Element;
|
|
254
|
+
}
|
|
255
|
+
declare namespace Elt {
|
|
256
|
+
/**
|
|
257
|
+
A collection of elements or other content values.
|
|
258
|
+
*/
|
|
259
|
+
class Fragment<T = string> {
|
|
260
|
+
readonly content: readonly (T | Elt<T>)[];
|
|
261
|
+
private constructor();
|
|
262
|
+
/**
|
|
263
|
+
Create a fragment.
|
|
264
|
+
*/
|
|
265
|
+
static create<T = string>(content: readonly (T | Elt<T>)[]): Fragment<T>;
|
|
266
|
+
/**
|
|
267
|
+
Convert this fragment to an HTML string.
|
|
268
|
+
*/
|
|
269
|
+
toHTML(this: Fragment<string>): string;
|
|
270
|
+
/**
|
|
271
|
+
Convert this fragment to a DOM fragment.
|
|
272
|
+
*/
|
|
273
|
+
toDOM(this: Fragment<string>, doc?: Document): DocumentFragment;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
Sets of attributes are stored in arrays of strings, with the even
|
|
278
|
+
indices holding attribute names, the odd ones attribute values. The
|
|
279
|
+
attributes are sorted by name.
|
|
280
|
+
*/
|
|
281
|
+
type Attributes = readonly string[];
|
|
282
|
+
declare namespace Attributes {
|
|
283
|
+
/**
|
|
284
|
+
The empty set of attributes.
|
|
285
|
+
*/
|
|
286
|
+
const none: Attributes;
|
|
287
|
+
/**
|
|
288
|
+
Compare two attribute sets.
|
|
289
|
+
*/
|
|
290
|
+
function eq(a: Attributes, b: Attributes): boolean;
|
|
291
|
+
/**
|
|
292
|
+
Combine two attribute sets, with b having higher precedence when
|
|
293
|
+
they set the same attribute.
|
|
294
|
+
*/
|
|
295
|
+
function merge(a: Attributes, b: Attributes): Attributes;
|
|
296
|
+
/**
|
|
297
|
+
Convert an attribute object into a set.
|
|
298
|
+
*/
|
|
299
|
+
function read(obj: Record<string, string | null>): Attributes;
|
|
300
|
+
/**
|
|
301
|
+
Get the value of the given attribute.
|
|
302
|
+
*/
|
|
303
|
+
function get(attrs: Attributes, name: string): string | null;
|
|
304
|
+
}
|
|
305
|
+
declare namespace Shape {
|
|
306
|
+
/**
|
|
307
|
+
Declares the shape of a node or mark to be a simple element. A
|
|
308
|
+
parse rule can automatically be derived for it if the node or mark
|
|
309
|
+
has a default parameter or a `read` function is defined to
|
|
310
|
+
determine the parameter.
|
|
311
|
+
*/
|
|
312
|
+
type Element<Param> = {
|
|
313
|
+
/**
|
|
314
|
+
The element name to use.
|
|
315
|
+
*/
|
|
316
|
+
element: string;
|
|
317
|
+
/**
|
|
318
|
+
A selector to use in the parse rule. Defaults to the element
|
|
319
|
+
name.
|
|
320
|
+
*/
|
|
321
|
+
selector?: string;
|
|
322
|
+
/**
|
|
323
|
+
Attributes to add to the element.
|
|
324
|
+
*/
|
|
325
|
+
attributes?: Record<string, string> | ((param: Param) => Record<string, string>);
|
|
326
|
+
/**
|
|
327
|
+
A helper to read a parameter value from the element. If this
|
|
328
|
+
returns {@link parse.Reject}, the parse rule will not apply.
|
|
329
|
+
*/
|
|
330
|
+
readElement?: (element: DOMElement$1) => Param | typeof parse.Reject;
|
|
331
|
+
/**
|
|
332
|
+
When specifying the shape of a plot, this indicates whether this
|
|
333
|
+
node is an atom, meaning its content isn't editable through the
|
|
334
|
+
editor.
|
|
335
|
+
*/
|
|
336
|
+
atom?: boolean;
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
Declares the shape of a node in a way that allows a more
|
|
340
|
+
complicated shape than {@link Shape.Element}. This will not
|
|
341
|
+
automatically create a parse rule, so you'll want to define
|
|
342
|
+
those yourself.
|
|
343
|
+
*/
|
|
344
|
+
type Structure<Param> = {
|
|
345
|
+
/**
|
|
346
|
+
The structure as a tree of {@link Elt}s. If this is for a plot
|
|
347
|
+
that is not to be rendered as an atom, the structure should
|
|
348
|
+
contain a hole for the content.
|
|
349
|
+
*/
|
|
350
|
+
structure: Elt<string> | ((param: Param) => Elt<string>);
|
|
351
|
+
/**
|
|
352
|
+
If `structure` is a function, and the target node is a plot, use
|
|
353
|
+
this to specify whether the plot should be rendered as an atom
|
|
354
|
+
or with content.
|
|
355
|
+
*/
|
|
356
|
+
atom?: boolean;
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
359
|
+
Declares that a mark is represented with a specific DOM attribute.
|
|
360
|
+
This allows a matching parse rule to be derived automatically in
|
|
361
|
+
most situations.
|
|
362
|
+
*/
|
|
363
|
+
type Attribute<Param> = {
|
|
364
|
+
/**
|
|
365
|
+
The name of the attribute.
|
|
366
|
+
*/
|
|
367
|
+
attribute: string;
|
|
368
|
+
/**
|
|
369
|
+
Its value. When given as 0, which is ony valid when the
|
|
370
|
+
`Param` type is `string`, the value of the mark's parameter is
|
|
371
|
+
used directly.
|
|
372
|
+
*/
|
|
373
|
+
value: (Param extends string ? 0 : never) | string | ((param: Param) => string | null);
|
|
374
|
+
/**
|
|
375
|
+
An optional function that converts the value of the attribute
|
|
376
|
+
back into a parameter value. Used in the parse rule.
|
|
377
|
+
*/
|
|
378
|
+
readAttribute?: (value: string) => Param | typeof parse.Reject;
|
|
379
|
+
/**
|
|
380
|
+
If the target node may be a composite shape (rather than a
|
|
381
|
+
single DOM element), you can provide a limited form of selector
|
|
382
|
+
here to target a specific element in that shape. Node names and
|
|
383
|
+
class names are supported, as in `"img"`, `"img.my-class"`, or
|
|
384
|
+
`".class1.class2"`. If no matching element is found, the
|
|
385
|
+
attributes will be added to the node's outer element, as normal.
|
|
386
|
+
*/
|
|
387
|
+
preferTarget?: string;
|
|
388
|
+
};
|
|
389
|
+
/**
|
|
390
|
+
Declares that a dynamic attribute or set of attributes should be
|
|
391
|
+
added to nodes with this mark. Will not produce an implicit parse
|
|
392
|
+
rule.
|
|
393
|
+
*/
|
|
394
|
+
type Attributes<Param> = {
|
|
395
|
+
/**
|
|
396
|
+
The attributes to add, either directly or as a function of the
|
|
397
|
+
mark's parameter.
|
|
398
|
+
*/
|
|
399
|
+
attributes: Record<string, string> | ((param: Param) => Record<string, string>);
|
|
400
|
+
/**
|
|
401
|
+
A selector for the {@link Shape.Attribute.preferTarget
|
|
402
|
+
preferred target} element.
|
|
403
|
+
*/
|
|
404
|
+
preferTarget?: string;
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
A mark has a type and a value. Some mark types without a
|
|
410
|
+
meaningful parameter value (such as {@link types.Emphasis}),
|
|
411
|
+
will only use a single mark object.
|
|
412
|
+
*/
|
|
413
|
+
declare class Mark<Value = unknown> {
|
|
414
|
+
/**
|
|
415
|
+
The type of the mark.
|
|
416
|
+
*/
|
|
417
|
+
readonly type: Mark.Type<Value>;
|
|
418
|
+
/**
|
|
419
|
+
The parameter value. This may be something like the link
|
|
420
|
+
target for a link mark, or the alignment side for a text
|
|
421
|
+
alignment mark.
|
|
422
|
+
*/
|
|
423
|
+
readonly value: Value;
|
|
424
|
+
private constructor();
|
|
425
|
+
/**
|
|
426
|
+
Compare this mark to another one. Parameter values are compared
|
|
427
|
+
by structure.
|
|
428
|
+
*/
|
|
429
|
+
eq(other: Mark): boolean;
|
|
430
|
+
/**
|
|
431
|
+
The name of this mark's type.
|
|
432
|
+
*/
|
|
433
|
+
get name(): string;
|
|
434
|
+
/**
|
|
435
|
+
Define a singleton mark, without parameter.
|
|
436
|
+
*/
|
|
437
|
+
static define(name: string, spec: Mark.Spec<null>): Mark<null>;
|
|
438
|
+
/**
|
|
439
|
+
Add this mark to the given set. Will overwrite existing
|
|
440
|
+
instances of the mark in the set, unless this is a {@link
|
|
441
|
+
Mark.Spec.set set-valued} mark.
|
|
442
|
+
*/
|
|
443
|
+
addToSet(set: Mark.Set): Mark.Set;
|
|
444
|
+
/**
|
|
445
|
+
Remove this mark from the given set.
|
|
446
|
+
*/
|
|
447
|
+
removeFromSet(set: Mark.Set): Mark.Set;
|
|
448
|
+
/**
|
|
449
|
+
Test whether this mark is in the given set.
|
|
450
|
+
*/
|
|
451
|
+
isInSet(set: Mark.Set): Mark<Value> | null;
|
|
452
|
+
/**
|
|
453
|
+
Compare two sets of marks.
|
|
454
|
+
*/
|
|
455
|
+
static sameSet(a: Mark.Set, b: Mark.Set): boolean;
|
|
456
|
+
/**
|
|
457
|
+
The empty mark set.
|
|
458
|
+
*/
|
|
459
|
+
static none: Mark.Set;
|
|
460
|
+
}
|
|
461
|
+
declare namespace Mark {
|
|
462
|
+
class Type<Param = unknown> {
|
|
463
|
+
/**
|
|
464
|
+
The name of the mark's type.
|
|
465
|
+
*/
|
|
466
|
+
readonly name: string;
|
|
467
|
+
/**
|
|
468
|
+
The {@link Mark.Spec.defaultParam default} mark for this type,
|
|
469
|
+
if any.
|
|
470
|
+
*/
|
|
471
|
+
readonly default: Mark<Param> | null;
|
|
472
|
+
/**
|
|
473
|
+
Whether this is an {@link Mark.Spec.inclusive inclusive} mark.
|
|
474
|
+
*/
|
|
475
|
+
readonly inclusive: boolean;
|
|
476
|
+
/**
|
|
477
|
+
Whether this is a {@link Mark.Spec.spanning spanning} mark.
|
|
478
|
+
*/
|
|
479
|
+
readonly spanning: boolean;
|
|
480
|
+
/**
|
|
481
|
+
The spec used to define this mark. (Its type parameter is set
|
|
482
|
+
to `any` to circumvent a typing issue where `Mark<T>` isn't a
|
|
483
|
+
subtype of `Mark<unknown>`.)
|
|
484
|
+
*/
|
|
485
|
+
readonly spec: Mark.Spec<any>;
|
|
486
|
+
private constructor();
|
|
487
|
+
/**
|
|
488
|
+
Create a mark of this type.
|
|
489
|
+
*/
|
|
490
|
+
of(value: Param): Mark<Param>;
|
|
491
|
+
/**
|
|
492
|
+
Remove the mark of this type from the given set, if present.
|
|
493
|
+
*/
|
|
494
|
+
removeFromSet(set: Mark.Set): Mark.Set;
|
|
495
|
+
/**
|
|
496
|
+
Test whether there is a mark of this type in the given set. If
|
|
497
|
+
so, return it.
|
|
498
|
+
*/
|
|
499
|
+
isInSet(set: Mark.Set): Mark<Param> | null;
|
|
500
|
+
/**
|
|
501
|
+
Whether this mark is rendered with an element.
|
|
502
|
+
*/
|
|
503
|
+
get isElement(): boolean;
|
|
504
|
+
/**
|
|
505
|
+
Define a mark type with the given parameter type.
|
|
506
|
+
*/
|
|
507
|
+
static define<Param>(name: string, spec: Mark.Spec<Param>,
|
|
508
|
+
/**
|
|
509
|
+
@internal
|
|
510
|
+
*/
|
|
511
|
+
isFlag?: boolean): Type<Param>;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
Configuration for marks.
|
|
515
|
+
*/
|
|
516
|
+
interface Spec<Param> {
|
|
517
|
+
/**
|
|
518
|
+
Which node tags this mark may apply to, as node {@link Node.Query query}.
|
|
519
|
+
The default is `{and: [Node.Group.Inline, Node.Group.Leaf]}`.
|
|
520
|
+
*/
|
|
521
|
+
target?: Node.Query;
|
|
522
|
+
/**
|
|
523
|
+
Determines the position of this mark relative to other marks.
|
|
524
|
+
Should be a number between 0 and 100. Marks with lower rank
|
|
525
|
+
appear first in mark set arrays, and are rendered around
|
|
526
|
+
higher rank marks when rendered as an element. Ties are broken
|
|
527
|
+
by name. Defaults to 100.
|
|
528
|
+
*/
|
|
529
|
+
rank?: number;
|
|
530
|
+
/**
|
|
531
|
+
Whether this mark should be active when the cursor is positioned
|
|
532
|
+
at its end (or at its start when that is also the start of the
|
|
533
|
+
parent node). Defaults to true.
|
|
534
|
+
*/
|
|
535
|
+
inclusive?: boolean;
|
|
536
|
+
/**
|
|
537
|
+
Whether this mark can span across multiple nodes, or refers to
|
|
538
|
+
an individual node. Only spanning marks can be added to text.
|
|
539
|
+
Spanning marks with an element representation can be drawn as
|
|
540
|
+
elements containing multiple nodes, unless another, lower-ranked
|
|
541
|
+
mark requires the nodes to be wrapped separately. Defaults to
|
|
542
|
+
true for specs with an element representation, false
|
|
543
|
+
for specs with an attribute representation.
|
|
544
|
+
*/
|
|
545
|
+
spanning?: boolean;
|
|
546
|
+
/**
|
|
547
|
+
Used by {@link Plot.Tag.split `Plot.Tag.split`} to determine
|
|
548
|
+
whether to keep this mark in the split-off tag. `atEnd` will
|
|
549
|
+
be true if the split happens at the end of the node's content.
|
|
550
|
+
*/
|
|
551
|
+
keepOnSplit?: boolean | ((tag: Plot.Tag, atEnd: boolean) => boolean);
|
|
552
|
+
/**
|
|
553
|
+
Used by {@link Schema.withMarksFrom} to decide whether marks
|
|
554
|
+
of this type are preserved after the type change.
|
|
555
|
+
*/
|
|
556
|
+
keepOnTypeChange?: boolean | ((from: Node.Tag, to: Node.Tag) => boolean);
|
|
557
|
+
/**
|
|
558
|
+
A default value for the parameter. If given, a mark with this
|
|
559
|
+
parameter will be stored in {@link Mark.Type.default
|
|
560
|
+
`Mark.Type.default`}.
|
|
561
|
+
*/
|
|
562
|
+
defaultParam?: Param;
|
|
563
|
+
/**
|
|
564
|
+
A function or type name used to validate parameters of this
|
|
565
|
+
mark. See {@link Node.Spec.validate `Node.Spec.validate`}.
|
|
566
|
+
*/
|
|
567
|
+
validate?: string | ((value: Param) => void);
|
|
568
|
+
/**
|
|
569
|
+
A mark parameter can be set-valued, which changes how adding
|
|
570
|
+
and removing marks of that type works. This requires the mark
|
|
571
|
+
parameter to be an array type. When adding a set-valued mark
|
|
572
|
+
to a mark set, the value of the mark in the new set is the
|
|
573
|
+
union of the values of its original value and the added mark.
|
|
574
|
+
Similarly, when removing such a mark, only the values in the
|
|
575
|
+
parameter of the removed mark are removed from the mark in the
|
|
576
|
+
set (except when there are none left, in which case the mark
|
|
577
|
+
is removed entirely).
|
|
578
|
+
|
|
579
|
+
`compare` should be a function that compares two values and
|
|
580
|
+
returns 0 if they are the same, or an ordering number
|
|
581
|
+
otherwise. This is used to sort and compare the values.
|
|
582
|
+
*/
|
|
583
|
+
set?: Param extends ReadonlyArray<infer Content> ? {
|
|
584
|
+
compare: (a: Content, b: Content) => number;
|
|
585
|
+
} : never;
|
|
586
|
+
/**
|
|
587
|
+
A mark can be either represented with a wrapping element, or
|
|
588
|
+
with one or more attributes added to the affected nodes.
|
|
589
|
+
*/
|
|
590
|
+
shape: Shape.Element<Param> | Shape.Attribute<Param> | Shape.Attributes<Param>;
|
|
591
|
+
/**
|
|
592
|
+
A set of parse rules for this mark. The `mark` field for these
|
|
593
|
+
will automatically be defaulted to the mark type itself.
|
|
594
|
+
*/
|
|
595
|
+
parseRules?: readonly parse.Rule<Param>[];
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
A set of marks is a sorted array in which a given mark type can
|
|
599
|
+
occur at most once.
|
|
600
|
+
*/
|
|
601
|
+
type Set = readonly Mark[];
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
A schema is a collection of node and mark types, including exactly
|
|
606
|
+
one document type, plus an optional set of {@link Schema.Override
|
|
607
|
+
overrides} that modify the relations between those elements. It
|
|
608
|
+
determines what kind of elements may occur in documents that
|
|
609
|
+
follow this schema, and where they can show up.
|
|
610
|
+
*/
|
|
611
|
+
declare class Schema {
|
|
612
|
+
/**
|
|
613
|
+
All the schema elements that make up this schema. Useful if you
|
|
614
|
+
want to base another schema on this one.
|
|
615
|
+
*/
|
|
616
|
+
readonly elements: readonly Schema.Element[];
|
|
617
|
+
/**
|
|
618
|
+
The node types that are part of this schema.
|
|
619
|
+
*/
|
|
620
|
+
readonly nodes: readonly Node.Type[];
|
|
621
|
+
/**
|
|
622
|
+
Mark types used in this schema.
|
|
623
|
+
*/
|
|
624
|
+
readonly marks: readonly Mark.Type[];
|
|
625
|
+
private plotContent;
|
|
626
|
+
private markTarget;
|
|
627
|
+
private nodeGroup;
|
|
628
|
+
/**
|
|
629
|
+
The plot tag used by documents in this schema.
|
|
630
|
+
*/
|
|
631
|
+
readonly docTag: Plot.Tag<null>;
|
|
632
|
+
/**
|
|
633
|
+
The {@link Node.Role.LineBreak line break} node defined in
|
|
634
|
+
this schema, if any.
|
|
635
|
+
*/
|
|
636
|
+
readonly lineBreak: Leaf | null;
|
|
637
|
+
private nodesByName;
|
|
638
|
+
private marksByName;
|
|
639
|
+
private wrappingCache;
|
|
640
|
+
private validated;
|
|
641
|
+
private constructor();
|
|
642
|
+
/**
|
|
643
|
+
Create a document in this schema.
|
|
644
|
+
*/
|
|
645
|
+
doc(children: readonly Node[]): Plot.Doc;
|
|
646
|
+
/**
|
|
647
|
+
Validate that a node and its content conform to this schema.
|
|
648
|
+
Will run automatically when creating a document.
|
|
649
|
+
*/
|
|
650
|
+
validate(node: Node): void;
|
|
651
|
+
/**
|
|
652
|
+
Test whether the given mark or tag type is included in this
|
|
653
|
+
schema.
|
|
654
|
+
*/
|
|
655
|
+
has(elt: Mark<any> | Mark.Type | Node.Type.Ref<any>): boolean;
|
|
656
|
+
/**
|
|
657
|
+
Test whether a node type matches the given {@link Node.Query
|
|
658
|
+
node query}.
|
|
659
|
+
*/
|
|
660
|
+
matchNode(node: Node.Type, q: Node.Query): boolean;
|
|
661
|
+
/**
|
|
662
|
+
Test whether the given mark is allowed on the given node type.
|
|
663
|
+
*/
|
|
664
|
+
markAllowed(mark: Mark.Type, node: Node.Type): boolean;
|
|
665
|
+
/**
|
|
666
|
+
Returns true if there's at least one node type in the schema
|
|
667
|
+
that may occur in both `a` and `b`.
|
|
668
|
+
*/
|
|
669
|
+
sharesContent(a: Plot.Type, b: Plot.Type): boolean;
|
|
670
|
+
/**
|
|
671
|
+
Returns a copy of `to` with all the marks from `from` that it
|
|
672
|
+
doesn't already have, and that aren't dropped by the mark's
|
|
673
|
+
{@link Mark.Spec.keepOnTypeChange} configuration.
|
|
674
|
+
*/
|
|
675
|
+
withMarksFrom<T extends Node.Tag>(from: Node.Tag, to: T): T;
|
|
676
|
+
/**
|
|
677
|
+
Check whether a given plot type can contain a given node type.
|
|
678
|
+
*/
|
|
679
|
+
canContain(parent: Plot.Type, child: Node.Type): boolean;
|
|
680
|
+
/**
|
|
681
|
+
Return the first {@link Leaf.Type.default defaultable} node tag that
|
|
682
|
+
can occur as a child of `parent`.
|
|
683
|
+
*/
|
|
684
|
+
defaultContentTag(parent: Plot.Type): Node.Tag | null;
|
|
685
|
+
/**
|
|
686
|
+
Return the first {@link Plot.Type.default defaultable} plot tag
|
|
687
|
+
that can be a child of `parent`.
|
|
688
|
+
*/
|
|
689
|
+
defaultContentPlot(parent: Plot.Type): Plot.Tag | null;
|
|
690
|
+
/**
|
|
691
|
+
Create a node from a tag, optionally adding a default child if
|
|
692
|
+
this is a plot that cannot be empty.
|
|
693
|
+
*/
|
|
694
|
+
createAndFill(parent: Node.Tag): Node;
|
|
695
|
+
/**
|
|
696
|
+
Find a set of tags that `child` must be wrapped in to be able to
|
|
697
|
+
occur in `parent`. Will return the empty array if it fits
|
|
698
|
+
directly, and `null` if it cannot occur at all.
|
|
699
|
+
*/
|
|
700
|
+
findWrapping(parent: Plot.Type, child: Node.Type): readonly Plot.Tag[] | null;
|
|
701
|
+
private findWrappingInner;
|
|
702
|
+
/**
|
|
703
|
+
Get the mark type with the given name in this schema.
|
|
704
|
+
*/
|
|
705
|
+
getMark(name: string): Mark.Type | undefined;
|
|
706
|
+
/**
|
|
707
|
+
Get the node type with the given name.
|
|
708
|
+
*/
|
|
709
|
+
getNode(name: string): Node.Type | undefined;
|
|
710
|
+
/**
|
|
711
|
+
Define a schema from a set of schema elements. The set must
|
|
712
|
+
contain precisely one document type, and no conflicting node or
|
|
713
|
+
mark names.
|
|
714
|
+
*/
|
|
715
|
+
static define(spec: readonly Schema.Element[]): Schema;
|
|
716
|
+
/**
|
|
717
|
+
Deserialize a node from its JSON representation.
|
|
718
|
+
*/
|
|
719
|
+
nodeFromJSON(json: Node.JSON): Node;
|
|
720
|
+
/**
|
|
721
|
+
Deserialize a tag from its JSON representation.
|
|
722
|
+
*/
|
|
723
|
+
tagFromJSON(json: Node.JSON): Leaf<unknown> | Plot.Tag<unknown>;
|
|
724
|
+
/**
|
|
725
|
+
Read a set of marks from their JSON representation.
|
|
726
|
+
*/
|
|
727
|
+
marksFromJSON(json: Record<string, any>): Mark.Set;
|
|
728
|
+
/**
|
|
729
|
+
Read a document from JSON.
|
|
730
|
+
*/
|
|
731
|
+
docFromJSON(json: Node.JSON): Plot.Doc;
|
|
732
|
+
}
|
|
733
|
+
declare namespace Schema {
|
|
734
|
+
/**
|
|
735
|
+
A schema element is any node tag or type, mark or mark type, or
|
|
736
|
+
override.
|
|
737
|
+
*/
|
|
738
|
+
type Element = Node.Tag | Node.Type | Mark | Mark.Type | Schema.Override;
|
|
739
|
+
/**
|
|
740
|
+
Though nodes and marks are mostly self-contained, a few of their
|
|
741
|
+
aspects can be overridden per schema.
|
|
742
|
+
*/
|
|
743
|
+
class Override {
|
|
744
|
+
private constructor();
|
|
745
|
+
/**
|
|
746
|
+
@hidden
|
|
747
|
+
*/
|
|
748
|
+
tag: "schema.override";
|
|
749
|
+
/**
|
|
750
|
+
Create a schema override that changes the target nodes for a
|
|
751
|
+
mark.
|
|
752
|
+
*/
|
|
753
|
+
static markTarget(mark: Mark.Type | Mark, target: Node.Query | ((target: Node.Query) => Node.Query)): Override;
|
|
754
|
+
/**
|
|
755
|
+
Create a schema override that changes the content specification
|
|
756
|
+
for a given node. Note that this can not change a node with
|
|
757
|
+
inline content to block content or vice versa.
|
|
758
|
+
*/
|
|
759
|
+
static plotContent(plot: Plot.Type | Plot.Tag, content: Node.Query | ((content: Node.Query) => Node.Query)): Override;
|
|
760
|
+
/**
|
|
761
|
+
Override the set of groups that a node may be part of.
|
|
762
|
+
*/
|
|
763
|
+
static nodeGroup(node: Node.Type | Node.Tag, group: Node.Group | readonly Node.Group[]): Override;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
The type of tokens in a slice. A plot tag represents the point
|
|
769
|
+
where a plot is opened, {@link Plot.End} the point where a plot is
|
|
770
|
+
closed, and nodes just represent the insertion of that node.
|
|
771
|
+
*/
|
|
772
|
+
type Token = Node | Plot.Tag | typeof Plot.End;
|
|
773
|
+
declare namespace Token {
|
|
774
|
+
/**
|
|
775
|
+
Tokens have a `tokenType` property holding oneof these values.
|
|
776
|
+
*/
|
|
777
|
+
enum Type {
|
|
778
|
+
Open = 0,
|
|
779
|
+
Close = 1,
|
|
780
|
+
Node = 2
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
A slice represents a part of a document. It is used to represent
|
|
785
|
+
inserted content in {@link ChangeSet change sets}, or things like
|
|
786
|
+
clipboard content.
|
|
787
|
+
*/
|
|
788
|
+
declare class Slice {
|
|
789
|
+
readonly content: readonly Token[];
|
|
790
|
+
/**
|
|
791
|
+
The length of the slice's content.
|
|
792
|
+
*/
|
|
793
|
+
readonly length: number;
|
|
794
|
+
private constructor();
|
|
795
|
+
/**
|
|
796
|
+
Create a slice.
|
|
797
|
+
*/
|
|
798
|
+
static of(content: readonly Token[]): Slice;
|
|
799
|
+
/**
|
|
800
|
+
Compare a slice to another one.
|
|
801
|
+
*/
|
|
802
|
+
eq(other: Slice): boolean;
|
|
803
|
+
/**
|
|
804
|
+
Create a sub-slice of this slice.
|
|
805
|
+
*/
|
|
806
|
+
slice(from: number, to?: number): Slice;
|
|
807
|
+
/**
|
|
808
|
+
Concatenate this slice to another slice.
|
|
809
|
+
*/
|
|
810
|
+
concat(other: Slice): Slice;
|
|
811
|
+
/**
|
|
812
|
+
Get the text content of the slice's tokens.
|
|
813
|
+
*/
|
|
814
|
+
textContent(options?: {
|
|
815
|
+
blockSeparator?: string;
|
|
816
|
+
leafText?: string | ((node: Leaf) => string);
|
|
817
|
+
}): string;
|
|
818
|
+
/**
|
|
819
|
+
The empty slice.
|
|
820
|
+
*/
|
|
821
|
+
static empty: Slice;
|
|
822
|
+
/**
|
|
823
|
+
Convert this slice to a JSON-serializeable representation.
|
|
824
|
+
*/
|
|
825
|
+
toJSON(): Slice.JSON;
|
|
826
|
+
/**
|
|
827
|
+
Build a slice from its JSON representation.
|
|
828
|
+
*/
|
|
829
|
+
static fromJSON(schema: Schema, json: Slice.JSON): Slice;
|
|
830
|
+
}
|
|
831
|
+
declare namespace Slice {
|
|
832
|
+
/**
|
|
833
|
+
A slice's JSON representation.
|
|
834
|
+
*/
|
|
835
|
+
type JSON = readonly (Node.JSON | ".")[];
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
type _Node = Node;
|
|
839
|
+
type _Plot = Plot;
|
|
840
|
+
type _Doc = Plot.Doc;
|
|
841
|
+
type _Tag = Plot.Tag;
|
|
842
|
+
/**
|
|
843
|
+
This class represents a {@link Plot.Doc.resolve resolved}
|
|
844
|
+
position.
|
|
845
|
+
*/
|
|
846
|
+
declare class Pos {
|
|
847
|
+
/**
|
|
848
|
+
The plot that the position points into.
|
|
849
|
+
*/
|
|
850
|
+
readonly parent: Pos.Plot;
|
|
851
|
+
/**
|
|
852
|
+
The position itself.
|
|
853
|
+
*/
|
|
854
|
+
readonly pos: number;
|
|
855
|
+
/**
|
|
856
|
+
The index into its parent's content array. Note that if
|
|
857
|
+
`inText` is non-zero, this is the index of the text node.
|
|
858
|
+
*/
|
|
859
|
+
readonly index: number;
|
|
860
|
+
/**
|
|
861
|
+
Text nodes don't count as parent plots. Rather, positions that
|
|
862
|
+
fall inside a text node have a non-zero value here that
|
|
863
|
+
provides the offset into the text node.
|
|
864
|
+
*/
|
|
865
|
+
readonly inText: number;
|
|
866
|
+
private constructor();
|
|
867
|
+
/**
|
|
868
|
+
Find the innermost parent plot for which the given predicate
|
|
869
|
+
returns true.
|
|
870
|
+
*/
|
|
871
|
+
matchingParent(pred: (plot: _Plot) => boolean): Pos.Plot | null;
|
|
872
|
+
/**
|
|
873
|
+
Move ahead through the document the given number of positions.
|
|
874
|
+
Don't descend into nodes that fall entirely within the skipped
|
|
875
|
+
range. If `walk` is given, call methods on it for each node
|
|
876
|
+
entered, skipped, or left. Return a new position at the end of
|
|
877
|
+
the range.
|
|
878
|
+
*/
|
|
879
|
+
advance(distance: number, walk?: Pos.Walker): Pos;
|
|
880
|
+
/**
|
|
881
|
+
Move ahead through the document, always entering every plot. If
|
|
882
|
+
`walk` is given, call methods on it for each node or node
|
|
883
|
+
boundary passed. Return a new position.
|
|
884
|
+
*/
|
|
885
|
+
walk(distance: number, walk: Pos.Walker): Pos;
|
|
886
|
+
/**
|
|
887
|
+
Get the node directly after this position. If `inText` is
|
|
888
|
+
non-zero, return only the part of the text node that's after the
|
|
889
|
+
position.
|
|
890
|
+
*/
|
|
891
|
+
get nodeAfter(): Node | null;
|
|
892
|
+
/**
|
|
893
|
+
Get the node directly before this position. If `inText` is
|
|
894
|
+
non-zero, return only the part of the text node before the
|
|
895
|
+
position.
|
|
896
|
+
*/
|
|
897
|
+
get nodeBefore(): Node | null;
|
|
898
|
+
/**
|
|
899
|
+
Get the nearest parent that is a {@link Plot.isTextblock
|
|
900
|
+
textblock}.
|
|
901
|
+
*/
|
|
902
|
+
get textblockParent(): Pos.Plot | null;
|
|
903
|
+
/**
|
|
904
|
+
Get the depth of this position (the amount of plots that wrap
|
|
905
|
+
it, not counting the document).
|
|
906
|
+
*/
|
|
907
|
+
get depth(): number;
|
|
908
|
+
/**
|
|
909
|
+
Get the parent plot at the given depth.
|
|
910
|
+
*/
|
|
911
|
+
parentAt(depth: number): Pos.Plot;
|
|
912
|
+
/**
|
|
913
|
+
Returns true if this position is right at the start of the given
|
|
914
|
+
parent plot, or transitively at the start of its first child.
|
|
915
|
+
*/
|
|
916
|
+
isAtStart(parent: Pos.Plot): boolean;
|
|
917
|
+
/**
|
|
918
|
+
Returns true if this position is right at the end of the given
|
|
919
|
+
parent plot, or transitively at the end of its last child.
|
|
920
|
+
*/
|
|
921
|
+
isAtEnd(parent: Pos.Plot): boolean;
|
|
922
|
+
/**
|
|
923
|
+
Get the document that this position points into.
|
|
924
|
+
*/
|
|
925
|
+
get doc(): Plot.Doc;
|
|
926
|
+
/**
|
|
927
|
+
Get the set of active inline marks at this position or, if
|
|
928
|
+
`across` is given, the marks that would apply to content
|
|
929
|
+
replacing the range between that `this` and `across`.
|
|
930
|
+
*/
|
|
931
|
+
marks(across?: Pos): Mark.Set;
|
|
932
|
+
}
|
|
933
|
+
declare namespace Pos {
|
|
934
|
+
/**
|
|
935
|
+
Interface for the walker object that can be passed to {@link
|
|
936
|
+
Pos.advance `Pos.advance`} and {@link Pos.walk}.
|
|
937
|
+
*/
|
|
938
|
+
interface Walker {
|
|
939
|
+
/**
|
|
940
|
+
Called when a node is skipped over. Will only be called for
|
|
941
|
+
leaves when using {@link Pos.walk}.
|
|
942
|
+
*/
|
|
943
|
+
skip(node: _Node, pos: number, parent: Pos.Plot, index: number): void;
|
|
944
|
+
/**
|
|
945
|
+
Called when a plot is entered.
|
|
946
|
+
*/
|
|
947
|
+
enterPlot(node: _Plot, pos: number, parent: Pos.Plot, index: number): void | boolean;
|
|
948
|
+
/**
|
|
949
|
+
Called when leaving a plot.
|
|
950
|
+
*/
|
|
951
|
+
leavePlot(tag: _Tag, pos: number, parent: Pos.Plot, index: number): void;
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
Represents the position of a node, with information about its
|
|
955
|
+
parent plots.
|
|
956
|
+
*/
|
|
957
|
+
class Node {
|
|
958
|
+
/**
|
|
959
|
+
The node's direct parent.
|
|
960
|
+
*/
|
|
961
|
+
readonly parent: Pos.Plot | null;
|
|
962
|
+
/**
|
|
963
|
+
The node object.
|
|
964
|
+
*/
|
|
965
|
+
readonly node: _Node;
|
|
966
|
+
/**
|
|
967
|
+
The node's index in its parent plot.
|
|
968
|
+
*/
|
|
969
|
+
readonly index: number;
|
|
970
|
+
/**
|
|
971
|
+
@hidden
|
|
972
|
+
*/
|
|
973
|
+
protected constructor(
|
|
974
|
+
/**
|
|
975
|
+
The node's direct parent.
|
|
976
|
+
*/
|
|
977
|
+
parent: Pos.Plot | null,
|
|
978
|
+
/**
|
|
979
|
+
The node object.
|
|
980
|
+
*/
|
|
981
|
+
node: _Node,
|
|
982
|
+
/**
|
|
983
|
+
@internal
|
|
984
|
+
*/
|
|
985
|
+
pos: number,
|
|
986
|
+
/**
|
|
987
|
+
The node's index in its parent plot.
|
|
988
|
+
*/
|
|
989
|
+
index: number);
|
|
990
|
+
/**
|
|
991
|
+
The position before the node. Will raise an error if this is
|
|
992
|
+
the document top node.
|
|
993
|
+
*/
|
|
994
|
+
get before(): number;
|
|
995
|
+
/**
|
|
996
|
+
The position after the node. Throws if this is a document.
|
|
997
|
+
*/
|
|
998
|
+
get after(): number;
|
|
999
|
+
/**
|
|
1000
|
+
The depth of this node (the number of parent nodes, not
|
|
1001
|
+
counting the document).
|
|
1002
|
+
*/
|
|
1003
|
+
get depth(): number;
|
|
1004
|
+
/**
|
|
1005
|
+
The document that this position points into.
|
|
1006
|
+
*/
|
|
1007
|
+
get doc(): _Doc;
|
|
1008
|
+
/**
|
|
1009
|
+
Returns true if this is either a document node or the first
|
|
1010
|
+
node in its parent.
|
|
1011
|
+
*/
|
|
1012
|
+
get isFirst(): boolean;
|
|
1013
|
+
/**
|
|
1014
|
+
Returns true if this is a document node or the last node in its parent.
|
|
1015
|
+
*/
|
|
1016
|
+
get isLast(): boolean;
|
|
1017
|
+
/**
|
|
1018
|
+
The node before this one, if any.
|
|
1019
|
+
*/
|
|
1020
|
+
get nextSibling(): Node | null;
|
|
1021
|
+
/**
|
|
1022
|
+
The node after this node, if any.
|
|
1023
|
+
*/
|
|
1024
|
+
get previousSibling(): Node | null;
|
|
1025
|
+
}
|
|
1026
|
+
/**
|
|
1027
|
+
Subclass of {@link Pos.Node} that points at a plot node.
|
|
1028
|
+
*/
|
|
1029
|
+
class Plot extends Pos.Node {
|
|
1030
|
+
node: _Plot;
|
|
1031
|
+
private constructor();
|
|
1032
|
+
/**
|
|
1033
|
+
The position at the start of this plot's content.
|
|
1034
|
+
*/
|
|
1035
|
+
get start(): number;
|
|
1036
|
+
/**
|
|
1037
|
+
The position at end of this plot's content.
|
|
1038
|
+
*/
|
|
1039
|
+
get end(): number;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
declare abstract class BaseType<Param> {
|
|
1044
|
+
/**
|
|
1045
|
+
The name of this node type.
|
|
1046
|
+
*/
|
|
1047
|
+
readonly name: string;
|
|
1048
|
+
/**
|
|
1049
|
+
Test whether this node has the given role.
|
|
1050
|
+
*/
|
|
1051
|
+
hasRole(role: Node.Role): boolean;
|
|
1052
|
+
/**
|
|
1053
|
+
True when this is an inline node type.
|
|
1054
|
+
*/
|
|
1055
|
+
get isInline(): boolean;
|
|
1056
|
+
/**
|
|
1057
|
+
True when this is a block node type.
|
|
1058
|
+
*/
|
|
1059
|
+
get isBlock(): boolean;
|
|
1060
|
+
abstract isLeaf: boolean;
|
|
1061
|
+
abstract isPlot: boolean;
|
|
1062
|
+
/**
|
|
1063
|
+
Whether this node is {@link Node.Spec.selectable selectable}.
|
|
1064
|
+
*/
|
|
1065
|
+
get isSelectable(): boolean;
|
|
1066
|
+
}
|
|
1067
|
+
declare abstract class BaseTag<Param> {
|
|
1068
|
+
readonly param: Param;
|
|
1069
|
+
readonly marks: Mark.Set;
|
|
1070
|
+
abstract type: Node.Type<Param>;
|
|
1071
|
+
constructor(param: Param, marks: Mark.Set);
|
|
1072
|
+
mark<Value>(mark: Mark.Type<Value>): Value | undefined;
|
|
1073
|
+
get name(): string;
|
|
1074
|
+
abstract eq(other: Node | Node.Tag): boolean;
|
|
1075
|
+
abstract isLeaf: boolean;
|
|
1076
|
+
abstract isPlot: boolean;
|
|
1077
|
+
get isText(): boolean;
|
|
1078
|
+
is<T>(type: Leaf.Type<T>): this is Leaf<T>;
|
|
1079
|
+
is<T>(type: Plot.Type<T>): this is Plot.Tag<T>;
|
|
1080
|
+
toJSON(): Node.JSON;
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
A node in the document is either a plot (which may have content)
|
|
1084
|
+
or a leaf node.
|
|
1085
|
+
*/
|
|
1086
|
+
type Node = Plot | Leaf;
|
|
1087
|
+
declare namespace Node {
|
|
1088
|
+
/**
|
|
1089
|
+
The interface shared by both {@link Leaf} and {@link Plot}.
|
|
1090
|
+
*/
|
|
1091
|
+
interface Shared {
|
|
1092
|
+
/**
|
|
1093
|
+
The name of this node's type.
|
|
1094
|
+
*/
|
|
1095
|
+
name: string;
|
|
1096
|
+
/**
|
|
1097
|
+
The node's {@link Node.Tag tag}. For leaves, this is the leaf
|
|
1098
|
+
itself, for plots, the {@link Plot.Tag plot tag}.
|
|
1099
|
+
*/
|
|
1100
|
+
tag: Node.Tag;
|
|
1101
|
+
/**
|
|
1102
|
+
The length of this node. For a plot, this is its {@link
|
|
1103
|
+
Plot.contentLength} plus 2 (for the open and close tokens),
|
|
1104
|
+
for leaves this is 1, except for text leaves, where it is the
|
|
1105
|
+
length of the text.
|
|
1106
|
+
*/
|
|
1107
|
+
length: number;
|
|
1108
|
+
/**
|
|
1109
|
+
The set of marks for this node.
|
|
1110
|
+
*/
|
|
1111
|
+
marks: Mark.Set;
|
|
1112
|
+
/**
|
|
1113
|
+
Get the value of the given mark for this node, if any.
|
|
1114
|
+
*/
|
|
1115
|
+
mark<Value>(mark: Mark.Type<Value>): Value | undefined;
|
|
1116
|
+
/**
|
|
1117
|
+
Compare this node to another node.
|
|
1118
|
+
*/
|
|
1119
|
+
eq(other: Node): boolean;
|
|
1120
|
+
/**
|
|
1121
|
+
Create a copy of this node with the given set of marks instead
|
|
1122
|
+
of its current mark set.
|
|
1123
|
+
*/
|
|
1124
|
+
withMarks(marks: Mark.Set): Node;
|
|
1125
|
+
/**
|
|
1126
|
+
True when this is a leaf node. TypeScript will automatically
|
|
1127
|
+
narrow from {@link Node} to {@link Leaf} after you check this.
|
|
1128
|
+
*/
|
|
1129
|
+
isLeaf: boolean;
|
|
1130
|
+
/**
|
|
1131
|
+
Tests whether this is a {@link Leaf.Text text leaf}.
|
|
1132
|
+
*/
|
|
1133
|
+
isText: boolean;
|
|
1134
|
+
/**
|
|
1135
|
+
True when this is a {@link Plot}.
|
|
1136
|
+
*/
|
|
1137
|
+
isPlot: boolean;
|
|
1138
|
+
/**
|
|
1139
|
+
True when this node is a block node.
|
|
1140
|
+
*/
|
|
1141
|
+
isBlock: boolean;
|
|
1142
|
+
/**
|
|
1143
|
+
Indicate whether this is an inline node.
|
|
1144
|
+
*/
|
|
1145
|
+
isInline: boolean;
|
|
1146
|
+
/**
|
|
1147
|
+
Convert this node to its JSON-serializeable representation.
|
|
1148
|
+
*/
|
|
1149
|
+
toJSON(): Node.JSON;
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
A node type can be either a leaf type or a plot type.
|
|
1153
|
+
*/
|
|
1154
|
+
type Type<T = unknown> = Leaf.Type<T> | Plot.Type<T>;
|
|
1155
|
+
namespace Type {
|
|
1156
|
+
/**
|
|
1157
|
+
Used as input type by some functions acting on node types, so
|
|
1158
|
+
that you can pass either a bare type or a singleton leaf or
|
|
1159
|
+
plot tag.
|
|
1160
|
+
*/
|
|
1161
|
+
type Ref<T> = Plot.Type<T> | Leaf.Type<T> | Plot.Tag<T> | Leaf<T>;
|
|
1162
|
+
/**
|
|
1163
|
+
Get the type referred to by a {@link Node.Type.Ref reference}.
|
|
1164
|
+
*/
|
|
1165
|
+
function get<T>(ref: Ref<T>): Node.Type<T>;
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
A tag is a node type with a parameter and a set of marks. For
|
|
1169
|
+
leaves, the entire node is the tag. For plots, it is a separate
|
|
1170
|
+
object in the {@link Plot.tag `tag` property}.
|
|
1171
|
+
*/
|
|
1172
|
+
type Tag = Leaf | Plot.Tag;
|
|
1173
|
+
namespace Tag {
|
|
1174
|
+
/**
|
|
1175
|
+
The interface shared by {@link Leaf leaves} and {@link
|
|
1176
|
+
Plot.Tag plot tags}.
|
|
1177
|
+
*/
|
|
1178
|
+
interface Shared<Param> {
|
|
1179
|
+
/**
|
|
1180
|
+
The type of the tag.
|
|
1181
|
+
*/
|
|
1182
|
+
type: Node.Type<Param>;
|
|
1183
|
+
/**
|
|
1184
|
+
The tag parameter. Will be `null` for parameter-less types.
|
|
1185
|
+
*/
|
|
1186
|
+
param: Param;
|
|
1187
|
+
/**
|
|
1188
|
+
The set of marks for this tag.
|
|
1189
|
+
*/
|
|
1190
|
+
marks: Mark.Set;
|
|
1191
|
+
/**
|
|
1192
|
+
The name of the tag's type.
|
|
1193
|
+
*/
|
|
1194
|
+
name: string;
|
|
1195
|
+
/**
|
|
1196
|
+
Find the value of the given given make type in this tag's
|
|
1197
|
+
set of marks, or return `undefined` if it isn't present.
|
|
1198
|
+
*/
|
|
1199
|
+
mark<Value>(mark: Mark.Type<Value>): Value | undefined;
|
|
1200
|
+
/**
|
|
1201
|
+
Compare this tag to another tag.
|
|
1202
|
+
*/
|
|
1203
|
+
eq(other: Node.Tag): boolean;
|
|
1204
|
+
/**
|
|
1205
|
+
Test whether this is a leaf.
|
|
1206
|
+
*/
|
|
1207
|
+
isLeaf: boolean;
|
|
1208
|
+
/**
|
|
1209
|
+
Test whether this is a plot tag.
|
|
1210
|
+
*/
|
|
1211
|
+
isPlot: boolean;
|
|
1212
|
+
/**
|
|
1213
|
+
Test whether this tag is of the given type.
|
|
1214
|
+
*/
|
|
1215
|
+
is<T>(type: Leaf.Type<T>): this is Leaf<T>;
|
|
1216
|
+
is<T>(type: Plot.Type<T>): this is Plot.Tag<T>;
|
|
1217
|
+
/**
|
|
1218
|
+
Holds `true` when this is a text leaf.
|
|
1219
|
+
*/
|
|
1220
|
+
isText: boolean;
|
|
1221
|
+
/**
|
|
1222
|
+
Convert this tag to a JSON-serializeable object.
|
|
1223
|
+
*/
|
|
1224
|
+
toJSON(): Node.JSON;
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
Deduce a tag type for a given node type or tag.
|
|
1228
|
+
*/
|
|
1229
|
+
type For<Type extends Node.Type.Ref<any>> = Type extends Leaf.Type<infer T> ? Leaf<T> : Type extends Plot.Type<infer T> ? Plot.Tag<T> : Type;
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
Shared fields between {@link Leaf.Spec} and {@link Plot.Spec}.
|
|
1233
|
+
*/
|
|
1234
|
+
interface Spec<Param> {
|
|
1235
|
+
/**
|
|
1236
|
+
Whether this node is an inline or a block node. Defaults to
|
|
1237
|
+
block.
|
|
1238
|
+
*/
|
|
1239
|
+
inline?: boolean;
|
|
1240
|
+
/**
|
|
1241
|
+
The default parameter value for the node type. Only meaningful
|
|
1242
|
+
when the type is being defined directly, rather than as a
|
|
1243
|
+
singleton tag.
|
|
1244
|
+
*/
|
|
1245
|
+
defaultParam?: Param;
|
|
1246
|
+
/**
|
|
1247
|
+
A function or type name used to validate this tag's parameter
|
|
1248
|
+
value. This will be used when deserializing the attribute from
|
|
1249
|
+
JSON. When a string, it should be a `|`-separated string of
|
|
1250
|
+
primitive types (`"number"`, `"string"`, `"boolean"`, `"null"`,
|
|
1251
|
+
and `"undefined"`). The library will raise an error when the
|
|
1252
|
+
value is not one of those types. When a function, it should
|
|
1253
|
+
raise an error if the value doesn't have the expected type or
|
|
1254
|
+
shape.
|
|
1255
|
+
*/
|
|
1256
|
+
validate?: string | ((param: Param) => void);
|
|
1257
|
+
/**
|
|
1258
|
+
Assign one or more groups to this node type. Groups are used
|
|
1259
|
+
when specifying allowed content for a plot. Schema overrides
|
|
1260
|
+
can {@link Schema.Override.nodeGroup change} a node's set of
|
|
1261
|
+
groups.
|
|
1262
|
+
*/
|
|
1263
|
+
group?: Group | readonly Group[];
|
|
1264
|
+
/**
|
|
1265
|
+
Roles to add to this node type, which mark it as having a
|
|
1266
|
+
certain semantic role, such as being a list.
|
|
1267
|
+
*/
|
|
1268
|
+
role?: Node.Role | readonly Node.Role[];
|
|
1269
|
+
/**
|
|
1270
|
+
The default DOM/HTML shape of this node. This will determine
|
|
1271
|
+
what the node looks like, both in an editor an in serialized
|
|
1272
|
+
HTML form. In most cases, this also specifies the way the node
|
|
1273
|
+
is parsed when reading HTML content.
|
|
1274
|
+
*/
|
|
1275
|
+
shape: Shape.Element<Param> | Shape.Structure<Param>;
|
|
1276
|
+
/**
|
|
1277
|
+
Extra parse rules to associate with this node type.
|
|
1278
|
+
*/
|
|
1279
|
+
parseRules?: readonly parse.Rule.Element<Param>[];
|
|
1280
|
+
/**
|
|
1281
|
+
When set to `true`, nodes of this type, if they are a leaf or
|
|
1282
|
+
atom, can be selected by clicking them or moving the selection
|
|
1283
|
+
into them with the keyboard.
|
|
1284
|
+
*/
|
|
1285
|
+
selectable?: boolean;
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
The JSON representation for a node or tag.
|
|
1289
|
+
*/
|
|
1290
|
+
interface JSON {
|
|
1291
|
+
type: string;
|
|
1292
|
+
param?: any;
|
|
1293
|
+
marks?: {
|
|
1294
|
+
[name: string]: any;
|
|
1295
|
+
};
|
|
1296
|
+
content?: readonly Node.JSON[];
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
Groups are used to specify parent-child relationships between
|
|
1300
|
+
nodes, and valid targets for marks. You can use predefined
|
|
1301
|
+
groups provided as static properties on the class, or define
|
|
1302
|
+
your own for custom categories.
|
|
1303
|
+
*/
|
|
1304
|
+
class Group {
|
|
1305
|
+
/**
|
|
1306
|
+
Groups may have a parent group. Membership of a group
|
|
1307
|
+
implies membership of its parent groups.
|
|
1308
|
+
*/
|
|
1309
|
+
readonly parent: Group | undefined;
|
|
1310
|
+
private tag;
|
|
1311
|
+
private constructor();
|
|
1312
|
+
/**
|
|
1313
|
+
Define a custom node group.
|
|
1314
|
+
*/
|
|
1315
|
+
static define(parent?: Group): Group;
|
|
1316
|
+
/**
|
|
1317
|
+
A group that contains every node type.
|
|
1318
|
+
*/
|
|
1319
|
+
static All: Group;
|
|
1320
|
+
/**
|
|
1321
|
+
All inline nodes are automatically assigned to this group.
|
|
1322
|
+
*/
|
|
1323
|
+
static Inline: Group;
|
|
1324
|
+
/**
|
|
1325
|
+
Block elements automatically get assigned to this group.
|
|
1326
|
+
*/
|
|
1327
|
+
static Block: Group;
|
|
1328
|
+
/**
|
|
1329
|
+
The group of all leaf nodes.
|
|
1330
|
+
*/
|
|
1331
|
+
static Leaf: Group;
|
|
1332
|
+
/**
|
|
1333
|
+
The group of all non-leaf nodes.
|
|
1334
|
+
*/
|
|
1335
|
+
static Plot: Group;
|
|
1336
|
+
/**
|
|
1337
|
+
Block plots with inline content are tagged as textblocks.
|
|
1338
|
+
*/
|
|
1339
|
+
static Textblock: Group;
|
|
1340
|
+
/**
|
|
1341
|
+
A group used for generic block content, such as paragraphs and
|
|
1342
|
+
lists. The basic schema uses this as the content type for the
|
|
1343
|
+
top level document, blockquotes, and list items.
|
|
1344
|
+
*/
|
|
1345
|
+
static Content: Group;
|
|
1346
|
+
/**
|
|
1347
|
+
Group for the cell nodes in tables.
|
|
1348
|
+
*/
|
|
1349
|
+
static TableCell: Group;
|
|
1350
|
+
/**
|
|
1351
|
+
Generic list item group.
|
|
1352
|
+
*/
|
|
1353
|
+
static ListItem: Group;
|
|
1354
|
+
}
|
|
1355
|
+
/**
|
|
1356
|
+
Describes a set of node types. Can be either a single tag or
|
|
1357
|
+
type, which matches exactly that type (tags are assumed to be
|
|
1358
|
+
singleton tags—only their type is used), a reference to a {@link
|
|
1359
|
+
Node.Group node group}, or a combination of multiple of those.
|
|
1360
|
+
An array indicates the union of all the groups in the array
|
|
1361
|
+
(matches types that match any of the queries). An object with an
|
|
1362
|
+
`and` property indicates an intersection (must match all the
|
|
1363
|
+
queries).
|
|
1364
|
+
*/
|
|
1365
|
+
type Query = Node.Tag | Node.Type | Group | readonly Node.Query[] | {
|
|
1366
|
+
and: readonly Node.Query[];
|
|
1367
|
+
};
|
|
1368
|
+
/**
|
|
1369
|
+
Roles are used to add some semantic information to node types.
|
|
1370
|
+
You can define your own, and use the `hasRole` method to check
|
|
1371
|
+
whether a given node has the role attached.
|
|
1372
|
+
*/
|
|
1373
|
+
class Role {
|
|
1374
|
+
private constructor();
|
|
1375
|
+
/**
|
|
1376
|
+
Define a new role.
|
|
1377
|
+
*/
|
|
1378
|
+
static define(): Role;
|
|
1379
|
+
/**
|
|
1380
|
+
This role indicates that a plot contains code, and makes some
|
|
1381
|
+
commands behave differently inside such a plot.
|
|
1382
|
+
*/
|
|
1383
|
+
static Code: Role;
|
|
1384
|
+
/**
|
|
1385
|
+
Identifies a plot as a list container. This makes some
|
|
1386
|
+
commands treat the plot specially.
|
|
1387
|
+
*/
|
|
1388
|
+
static List: Role;
|
|
1389
|
+
/**
|
|
1390
|
+
A single leaf type in a schema may have the `LineBreak` role,
|
|
1391
|
+
which identifies it as the canonical node that represents a
|
|
1392
|
+
line break. Nodes marked as line breaks will be parsed from
|
|
1393
|
+
and serialized to newline characters inside {@link
|
|
1394
|
+
Plot.Spec.preserveWhitespace whitespace-preserving} nodes.
|
|
1395
|
+
*/
|
|
1396
|
+
static LineBreak: Role;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
/**
|
|
1400
|
+
A leaf node, which is a node with no content nodes. Used for
|
|
1401
|
+
things like text, images, line breaks, and so on. Counts as a
|
|
1402
|
+
{@link Node.Tag}.
|
|
1403
|
+
*/
|
|
1404
|
+
declare class Leaf<Param = unknown> extends BaseTag<Param> implements Node.Shared, Node.Tag.Shared<Param> {
|
|
1405
|
+
/**
|
|
1406
|
+
This leaf's type.
|
|
1407
|
+
*/
|
|
1408
|
+
readonly type: Leaf.Type<Param>;
|
|
1409
|
+
private constructor();
|
|
1410
|
+
get tag(): this;
|
|
1411
|
+
eq(other: Node | Node.Tag): boolean;
|
|
1412
|
+
/**
|
|
1413
|
+
Define a singleton leaf type, without parameter. If you need to
|
|
1414
|
+
store a parameter value in each leaf of the type, use {@link
|
|
1415
|
+
Leaf.Type.define} instead.
|
|
1416
|
+
*/
|
|
1417
|
+
static define(name: string, spec: Leaf.Spec<null>): Leaf<null>;
|
|
1418
|
+
withMarks(marks: Mark.Set): Leaf<Param>;
|
|
1419
|
+
/**
|
|
1420
|
+
In {@link Slice slices}, leaf nodes count as node {@link Token
|
|
1421
|
+
tokens}.
|
|
1422
|
+
*/
|
|
1423
|
+
get tokenType(): Token.Type.Node;
|
|
1424
|
+
get isLeaf(): true;
|
|
1425
|
+
get isPlot(): false;
|
|
1426
|
+
get isInline(): boolean;
|
|
1427
|
+
get isBlock(): boolean;
|
|
1428
|
+
get length(): number;
|
|
1429
|
+
/**
|
|
1430
|
+
Create a text node with the given text and mark set.
|
|
1431
|
+
*/
|
|
1432
|
+
static text(text: string, marks?: Mark.Set): Leaf<string>;
|
|
1433
|
+
}
|
|
1434
|
+
declare namespace Leaf {
|
|
1435
|
+
/**
|
|
1436
|
+
Node type for leaves.
|
|
1437
|
+
*/
|
|
1438
|
+
class Type<Param = unknown> extends BaseType<Param> {
|
|
1439
|
+
/**
|
|
1440
|
+
A default leaf for this type. Available if the leaf was
|
|
1441
|
+
defined with {@link Leaf.define}, or a {@link
|
|
1442
|
+
Node.Spec.defaultParam} was given.
|
|
1443
|
+
*/
|
|
1444
|
+
default: Leaf<Param> | null;
|
|
1445
|
+
/**
|
|
1446
|
+
The spec used to define this type. Its type parameter is
|
|
1447
|
+
cleared to avoid this field making the class invariant (in the
|
|
1448
|
+
type system sense), which would prevent `Leaf.Type<unknown>`
|
|
1449
|
+
from being a supertype of specific leaf types.
|
|
1450
|
+
*/
|
|
1451
|
+
readonly spec: Leaf.Spec<any>;
|
|
1452
|
+
private constructor();
|
|
1453
|
+
/**
|
|
1454
|
+
Define a new leaf type.
|
|
1455
|
+
*/
|
|
1456
|
+
static define<T>(name: string, spec: Leaf.Spec<T>): Type<T>;
|
|
1457
|
+
/**
|
|
1458
|
+
Create a leaf with this type.
|
|
1459
|
+
*/
|
|
1460
|
+
of(param: Param, marks?: Mark.Set): Leaf<Param>;
|
|
1461
|
+
/**
|
|
1462
|
+
Used to narrow {@link Node.Type} values to {@link Leaf}.
|
|
1463
|
+
*/
|
|
1464
|
+
get isLeaf(): true;
|
|
1465
|
+
/**
|
|
1466
|
+
Leaves are not plots.
|
|
1467
|
+
*/
|
|
1468
|
+
get isPlot(): false;
|
|
1469
|
+
}
|
|
1470
|
+
interface Spec<Param> extends Node.Spec<Param> {
|
|
1471
|
+
/**
|
|
1472
|
+
Can be used to make leaves of this type show up in the output
|
|
1473
|
+
of {@link Plot.textContent}.
|
|
1474
|
+
*/
|
|
1475
|
+
toText?: (node: Leaf) => string;
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
The type of text leaves. Represents a series of characters with
|
|
1479
|
+
a given set of marks. The only leaf with a length that isn't
|
|
1480
|
+
always 1. Adjacent text leaves with the same marks are merged
|
|
1481
|
+
automatically.
|
|
1482
|
+
|
|
1483
|
+
Text leaves must not include newline or return characters. Line
|
|
1484
|
+
breaks in the document are modeled with {@link LineBreak} nodes.
|
|
1485
|
+
*/
|
|
1486
|
+
const Text: Leaf.Type<string>;
|
|
1487
|
+
}
|
|
1488
|
+
/**
|
|
1489
|
+
Plots delimit parts of the document, giving a special meaning to
|
|
1490
|
+
the nodes inside them. They are defined by a {@link Plot.Tag tag}
|
|
1491
|
+
and an array of {@link Plot.content content}.
|
|
1492
|
+
*/
|
|
1493
|
+
declare class Plot implements Node.Shared {
|
|
1494
|
+
/**
|
|
1495
|
+
The tag that identifies this plot.
|
|
1496
|
+
*/
|
|
1497
|
+
readonly tag: Plot.Tag;
|
|
1498
|
+
/**
|
|
1499
|
+
The nodes in this plot.
|
|
1500
|
+
*/
|
|
1501
|
+
readonly content: readonly Node[];
|
|
1502
|
+
/**
|
|
1503
|
+
The sum of the length of this plot's content nodes.
|
|
1504
|
+
*/
|
|
1505
|
+
contentLength: number;
|
|
1506
|
+
get name(): string;
|
|
1507
|
+
/**
|
|
1508
|
+
The type of this plot's tag.
|
|
1509
|
+
*/
|
|
1510
|
+
get type(): Plot.Type<unknown>;
|
|
1511
|
+
get marks(): Mark.Set;
|
|
1512
|
+
get length(): number;
|
|
1513
|
+
eq(other: Node): boolean;
|
|
1514
|
+
/**
|
|
1515
|
+
Compare the content of this plot to the content of the given
|
|
1516
|
+
plot.
|
|
1517
|
+
*/
|
|
1518
|
+
contentEq(other: Plot): boolean;
|
|
1519
|
+
/**
|
|
1520
|
+
@hidden
|
|
1521
|
+
*/
|
|
1522
|
+
is<T>(type: Leaf.Type<T>): false;
|
|
1523
|
+
get isText(): false;
|
|
1524
|
+
/**
|
|
1525
|
+
Tells you whether the content of this plot is inline.
|
|
1526
|
+
*/
|
|
1527
|
+
get inlineContent(): boolean;
|
|
1528
|
+
/**
|
|
1529
|
+
True if this is a block node with inline content.
|
|
1530
|
+
*/
|
|
1531
|
+
get isTextblock(): boolean;
|
|
1532
|
+
get isLeaf(): false;
|
|
1533
|
+
get isPlot(): true;
|
|
1534
|
+
get isInline(): boolean;
|
|
1535
|
+
get isBlock(): boolean;
|
|
1536
|
+
/**
|
|
1537
|
+
True if this is a document node.
|
|
1538
|
+
*/
|
|
1539
|
+
get isDoc(): boolean;
|
|
1540
|
+
/**
|
|
1541
|
+
Get the plot's first child, if any.
|
|
1542
|
+
*/
|
|
1543
|
+
get firstChild(): Node | null;
|
|
1544
|
+
/**
|
|
1545
|
+
Get the plot's first child.
|
|
1546
|
+
*/
|
|
1547
|
+
get lastChild(): Node | null;
|
|
1548
|
+
/**
|
|
1549
|
+
Iterate though the given range (or the entire document, when
|
|
1550
|
+
given only one argument), and call the given function on every
|
|
1551
|
+
node that overlaps the given range, outer nodes before inner
|
|
1552
|
+
nodes. When the function returns `false` for a node, descendents
|
|
1553
|
+
of that node are not iterated.
|
|
1554
|
+
|
|
1555
|
+
When `from` is greater than `to`, iteration happens in inverted
|
|
1556
|
+
order, yielding later siblings before earlier ones.
|
|
1557
|
+
|
|
1558
|
+
Note that positions passed to the callback are relative to the
|
|
1559
|
+
start of the node this method is called on. That will usually be
|
|
1560
|
+
the document, in which case they are normal document positions,
|
|
1561
|
+
but you can also call it on an arbitrary plot, in which case
|
|
1562
|
+
they are local positions.
|
|
1563
|
+
*/
|
|
1564
|
+
iterate(from: number, to: number, f: (node: Node, pos: number, parent: Plot | null, index: number) => boolean | void): void;
|
|
1565
|
+
iterate(f: (node: Node, pos: number, parent: Plot | null, index: number) => boolean | void): void;
|
|
1566
|
+
/**
|
|
1567
|
+
Return the node that starts at the given offset from this node's
|
|
1568
|
+
content start, if any. Will not return text nodes.
|
|
1569
|
+
*/
|
|
1570
|
+
nodeAt(pos: number): Node | null;
|
|
1571
|
+
/**
|
|
1572
|
+
Return the plot at the given offset, if any.
|
|
1573
|
+
*/
|
|
1574
|
+
plotAt(pos: number): Plot | null;
|
|
1575
|
+
/**
|
|
1576
|
+
Return the text content of this plot.
|
|
1577
|
+
*/
|
|
1578
|
+
textContent(options?: {
|
|
1579
|
+
/**
|
|
1580
|
+
An optional start position, as an offset from the plot's
|
|
1581
|
+
content start.
|
|
1582
|
+
*/
|
|
1583
|
+
from?: number;
|
|
1584
|
+
/**
|
|
1585
|
+
An optional end position.
|
|
1586
|
+
*/
|
|
1587
|
+
to?: number;
|
|
1588
|
+
/**
|
|
1589
|
+
Text to separate blocks with. Defaults to a single newline
|
|
1590
|
+
character.
|
|
1591
|
+
*/
|
|
1592
|
+
blockSeparator?: string;
|
|
1593
|
+
/**
|
|
1594
|
+
Override the way non-text leaves are converted to string.
|
|
1595
|
+
*/
|
|
1596
|
+
leafText?: string | ((node: Leaf) => string);
|
|
1597
|
+
}): string;
|
|
1598
|
+
toJSON(): Node.JSON;
|
|
1599
|
+
mark<Value>(mark: Mark.Type<Value>): Value | undefined;
|
|
1600
|
+
withMarks(marks: Mark.Set): Plot;
|
|
1601
|
+
/**
|
|
1602
|
+
Plot nodes count as node {@link Token tokens} in a {@link
|
|
1603
|
+
Slice}.
|
|
1604
|
+
*/
|
|
1605
|
+
get tokenType(): Token.Type.Node;
|
|
1606
|
+
/**
|
|
1607
|
+
Define a singleton plot type. If the plot needs a parameter
|
|
1608
|
+
value, use {@link Plot.Type.define} instead.
|
|
1609
|
+
*/
|
|
1610
|
+
static define(name: string, spec: Plot.Spec<null>): Plot.Tag<null>;
|
|
1611
|
+
/**
|
|
1612
|
+
Define a document plot type. Exactly one of these must occur in a schema.
|
|
1613
|
+
*/
|
|
1614
|
+
static defineDoc(spec: {
|
|
1615
|
+
inlineContent?: Node.Query | true;
|
|
1616
|
+
blockContent?: Node.Query;
|
|
1617
|
+
canBeEmpty?: boolean;
|
|
1618
|
+
}): Plot.Type<null>;
|
|
1619
|
+
}
|
|
1620
|
+
declare namespace Plot {
|
|
1621
|
+
/**
|
|
1622
|
+
The end token for a plot. Used in {@link Slice slices}.
|
|
1623
|
+
*/
|
|
1624
|
+
const End: {
|
|
1625
|
+
tokenType: Token.Type.Close;
|
|
1626
|
+
};
|
|
1627
|
+
/**
|
|
1628
|
+
A plot tag holds the type of the plot, its parameter (if any),
|
|
1629
|
+
and a set of marks.
|
|
1630
|
+
*/
|
|
1631
|
+
class Tag<Param = unknown> extends BaseTag<Param> implements Node.Tag.Shared<Param> {
|
|
1632
|
+
readonly type: Plot.Type<Param>;
|
|
1633
|
+
private constructor();
|
|
1634
|
+
eq(other: Node | Node.Tag): boolean;
|
|
1635
|
+
/**
|
|
1636
|
+
Create a plot with this tag and the given content.
|
|
1637
|
+
*/
|
|
1638
|
+
create(content?: readonly Node[]): Plot;
|
|
1639
|
+
/**
|
|
1640
|
+
Create a copy of this tag with the given marks.
|
|
1641
|
+
*/
|
|
1642
|
+
withMarks(marks: Mark.Set): Tag<Param>;
|
|
1643
|
+
/**
|
|
1644
|
+
Return a tag that represents content split off from the plot
|
|
1645
|
+
with this tag. Will respect the {@link Mark.Spec.keepOnSplit}
|
|
1646
|
+
mark property. `atEnd` should be set to true if the split
|
|
1647
|
+
happens at the end of the plot's content.
|
|
1648
|
+
*/
|
|
1649
|
+
split(atEnd: boolean): Tag<Param>;
|
|
1650
|
+
/**
|
|
1651
|
+
A plot tag counts as an open {@link Token token} in a {@link
|
|
1652
|
+
Slice slice}.
|
|
1653
|
+
*/
|
|
1654
|
+
get tokenType(): Token.Type.Open;
|
|
1655
|
+
/**
|
|
1656
|
+
True when this plot type contains inline content.
|
|
1657
|
+
*/
|
|
1658
|
+
get inlineContent(): boolean;
|
|
1659
|
+
/**
|
|
1660
|
+
True when this is a block plot with inline content.
|
|
1661
|
+
*/
|
|
1662
|
+
get isTextblock(): boolean;
|
|
1663
|
+
get isLeaf(): false;
|
|
1664
|
+
get isPlot(): true;
|
|
1665
|
+
/**
|
|
1666
|
+
Test whether this is a document plot.
|
|
1667
|
+
*/
|
|
1668
|
+
get isDoc(): boolean;
|
|
1669
|
+
}
|
|
1670
|
+
/**
|
|
1671
|
+
A type of {@link Plot plot}.
|
|
1672
|
+
*/
|
|
1673
|
+
class Type<Param = unknown> extends BaseType<Param> {
|
|
1674
|
+
/**
|
|
1675
|
+
A default tag for this plot type.
|
|
1676
|
+
*/
|
|
1677
|
+
readonly default: Plot.Tag<Param> | null;
|
|
1678
|
+
/**
|
|
1679
|
+
Whether the {@link Plot.Spec.isolating} flag is set on this
|
|
1680
|
+
plot type.
|
|
1681
|
+
*/
|
|
1682
|
+
readonly isolating: boolean;
|
|
1683
|
+
/**
|
|
1684
|
+
The plot's {@link Plot.Spec.defining} flag.
|
|
1685
|
+
*/
|
|
1686
|
+
readonly defining: boolean;
|
|
1687
|
+
/**
|
|
1688
|
+
The plot's {@link Plot.Spec.neutral} flag.
|
|
1689
|
+
*/
|
|
1690
|
+
readonly neutral: boolean;
|
|
1691
|
+
/**
|
|
1692
|
+
Whether whitespace should be preserved inside this plot.
|
|
1693
|
+
*/
|
|
1694
|
+
readonly preserveWhitespace: boolean;
|
|
1695
|
+
/**
|
|
1696
|
+
The orientation of the content of the plot. Will be `"row"`
|
|
1697
|
+
for plots with inline content, and defaults to `"column"` for
|
|
1698
|
+
plots with block content unless explicitly {@link
|
|
1699
|
+
Plot.Spec.orientation set}.
|
|
1700
|
+
*/
|
|
1701
|
+
readonly orientation: "row" | "column";
|
|
1702
|
+
/**
|
|
1703
|
+
The spec used to define this plot type.
|
|
1704
|
+
*/
|
|
1705
|
+
readonly spec: Plot.Spec<any>;
|
|
1706
|
+
private constructor();
|
|
1707
|
+
/**
|
|
1708
|
+
Define a plot type.
|
|
1709
|
+
*/
|
|
1710
|
+
static define<T>(name: string, spec: Plot.Spec<T>): Type<T>;
|
|
1711
|
+
/**
|
|
1712
|
+
Create a plot tag of this type with the given parameter and
|
|
1713
|
+
mark set.
|
|
1714
|
+
*/
|
|
1715
|
+
of(param: Param, marks?: Mark.Set): Tag<Param>;
|
|
1716
|
+
/**
|
|
1717
|
+
Tells you whether this plot type has inline content.
|
|
1718
|
+
*/
|
|
1719
|
+
get inlineContent(): boolean;
|
|
1720
|
+
/**
|
|
1721
|
+
True if this is a block plot with inline content.
|
|
1722
|
+
*/
|
|
1723
|
+
get isTextblock(): boolean;
|
|
1724
|
+
/**
|
|
1725
|
+
True if this is a document plot type.
|
|
1726
|
+
*/
|
|
1727
|
+
get isDoc(): boolean;
|
|
1728
|
+
/**
|
|
1729
|
+
Tells you that this is not a leaf type.
|
|
1730
|
+
*/
|
|
1731
|
+
get isLeaf(): false;
|
|
1732
|
+
/**
|
|
1733
|
+
This is a plot type. Can be used to narrow `Node.Type` to
|
|
1734
|
+
`Plot.Type`.
|
|
1735
|
+
*/
|
|
1736
|
+
get isPlot(): true;
|
|
1737
|
+
/**
|
|
1738
|
+
Tells you whether this plot type is allowed {@link
|
|
1739
|
+
Plot.Spec.canBeEmpty to be empty}.
|
|
1740
|
+
*/
|
|
1741
|
+
get canBeEmpty(): boolean;
|
|
1742
|
+
}
|
|
1743
|
+
/**
|
|
1744
|
+
Object used to define a plot type.
|
|
1745
|
+
*/
|
|
1746
|
+
interface Spec<Param> extends Node.Spec<Param> {
|
|
1747
|
+
/**
|
|
1748
|
+
When this node has block-level content, provide a query
|
|
1749
|
+
matching the nodes it may contain here. You generally don't
|
|
1750
|
+
want to use `Node.Group.Block` here, since specialized block
|
|
1751
|
+
types (like table cells or list items) should probably only be
|
|
1752
|
+
allowed in their designated parent plots.
|
|
1753
|
+
*/
|
|
1754
|
+
blockContent?: Node.Query;
|
|
1755
|
+
/**
|
|
1756
|
+
When this node has inline content, provide a query specifying
|
|
1757
|
+
valid content. If set to `true`, any inline node may appear in
|
|
1758
|
+
this node.
|
|
1759
|
+
*/
|
|
1760
|
+
inlineContent?: Node.Query | true;
|
|
1761
|
+
/**
|
|
1762
|
+
Plots with block content, by default, require at least one
|
|
1763
|
+
child. You can set this to true to allow them to be empty.
|
|
1764
|
+
Plots with inlne content can always be empty.
|
|
1765
|
+
*/
|
|
1766
|
+
canBeEmpty?: boolean;
|
|
1767
|
+
/**
|
|
1768
|
+
Whether the sides of this plot act as a 'barrier' when {@link
|
|
1769
|
+
state.GardSelection.nextNormalCursor normalizing} a cursor
|
|
1770
|
+
position, which means that a separate cursor position exists
|
|
1771
|
+
at its boundary. By default, nodes that are {@link
|
|
1772
|
+
Plot.Spec.isolating isolating}, {@link
|
|
1773
|
+
Plot.Spec.preserveWhitespace whitespace-preserving}, or both
|
|
1774
|
+
a {@link Leaf leaf} and a block count as barriers.
|
|
1775
|
+
*/
|
|
1776
|
+
cursorBarrier?: boolean;
|
|
1777
|
+
/**
|
|
1778
|
+
Indicates that this type of block is the default generic block
|
|
1779
|
+
type in parent nodes where it may occur (which is appropriate
|
|
1780
|
+
for, for example, paragraphs tags). Default blocks should not
|
|
1781
|
+
have a required param. When not specified, the configuration
|
|
1782
|
+
precedence order determines which child type is the default.
|
|
1783
|
+
*/
|
|
1784
|
+
defaultBlock?: boolean;
|
|
1785
|
+
/**
|
|
1786
|
+
Controls whether whitespace inside this type of node should be
|
|
1787
|
+
preserved. Disables whitespace collapsing and the replacement
|
|
1788
|
+
of newlines with line break nodes in the parser and
|
|
1789
|
+
serializer. Defaults to false, unless the node has the {@link
|
|
1790
|
+
Node.Role.Code} role.
|
|
1791
|
+
*/
|
|
1792
|
+
preserveWhitespace?: boolean;
|
|
1793
|
+
/**
|
|
1794
|
+
Isolating plots disallow some kinds of editing across their
|
|
1795
|
+
borders (such as backspacing or unwrapping). A table cell is
|
|
1796
|
+
an example of a node that you'd use this for.
|
|
1797
|
+
*/
|
|
1798
|
+
isolating?: boolean;
|
|
1799
|
+
/**
|
|
1800
|
+
Block containers are, by default, assumed to arrange their
|
|
1801
|
+
children vertically below each other (`"column"`). You can set this
|
|
1802
|
+
to `"row"` to tell the editor that this container's children
|
|
1803
|
+
are horizontally next to each other.
|
|
1804
|
+
*/
|
|
1805
|
+
orientation?: "row" | "column";
|
|
1806
|
+
/**
|
|
1807
|
+
Defining nodes are preserved (when possible) when their content
|
|
1808
|
+
is duplicated (dragged, pasted, etc) into a new position.
|
|
1809
|
+
Defaults to false.
|
|
1810
|
+
*/
|
|
1811
|
+
defining?: boolean;
|
|
1812
|
+
/**
|
|
1813
|
+
Neutral nodes may be completely replaced when their entire
|
|
1814
|
+
content gets replaced. Defaults to `!`{@link
|
|
1815
|
+
Plot.Spec.defining}.
|
|
1816
|
+
*/
|
|
1817
|
+
neutral?: boolean;
|
|
1818
|
+
/**
|
|
1819
|
+
Whether block nodes of this type should be automatically
|
|
1820
|
+
joined when they become adjacent through an edit. Defaults to
|
|
1821
|
+
false. Note that editing commands need to explicitly call
|
|
1822
|
+
{@link command.autoJoinBlocks} for joining to happen.
|
|
1823
|
+
*/
|
|
1824
|
+
autoJoin?: boolean | ((before: Plot.Tag, after: Plot.Tag) => boolean);
|
|
1825
|
+
/**
|
|
1826
|
+
By default, splitting a textblock at the end will revert the new
|
|
1827
|
+
block to the default type of textblock at that position. Setting
|
|
1828
|
+
this to true on a textblock type will prevent that behavior.
|
|
1829
|
+
*/
|
|
1830
|
+
preserveOnSplitAtEnd?: boolean;
|
|
1831
|
+
}
|
|
1832
|
+
/**
|
|
1833
|
+
Document plots are used as the top level plot in a document.
|
|
1834
|
+
They offer some additional methods and, unlike normal plots,
|
|
1835
|
+
their {@link Plot.Doc.length `length` property} reports only the
|
|
1836
|
+
length of their content, without counting open/close tokens
|
|
1837
|
+
(because those are not part of the document).
|
|
1838
|
+
*/
|
|
1839
|
+
class Doc extends Plot {
|
|
1840
|
+
/**
|
|
1841
|
+
The document's schema.
|
|
1842
|
+
*/
|
|
1843
|
+
readonly schema: Schema;
|
|
1844
|
+
private constructor();
|
|
1845
|
+
/**
|
|
1846
|
+
The length of the document's content.
|
|
1847
|
+
*/
|
|
1848
|
+
get length(): number;
|
|
1849
|
+
/**
|
|
1850
|
+
Resolve the given position in the document, returning an
|
|
1851
|
+
object describing its context.
|
|
1852
|
+
*/
|
|
1853
|
+
resolve(pos: number): Pos;
|
|
1854
|
+
/**
|
|
1855
|
+
Resolve the node at the given position, providing information
|
|
1856
|
+
about its context.
|
|
1857
|
+
*/
|
|
1858
|
+
resolveNode(pos: number): Pos.Node | null;
|
|
1859
|
+
/**
|
|
1860
|
+
Like {@link Plot.Doc.resolveNode}, but only resolves plot
|
|
1861
|
+
nodes.
|
|
1862
|
+
*/
|
|
1863
|
+
resolvePlot(pos: number): Pos.Plot | null;
|
|
1864
|
+
/**
|
|
1865
|
+
Get the context stack (the array of wrapping plot tags,
|
|
1866
|
+
inner-to-outer) at the given position.
|
|
1867
|
+
*/
|
|
1868
|
+
contextAt(pos: number, maxDepth?: number): readonly Plot.Tag[];
|
|
1869
|
+
/**
|
|
1870
|
+
Create a slice of the content between `from` and `to`.
|
|
1871
|
+
*/
|
|
1872
|
+
slice(from: number, to?: number): Slice;
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
/**
|
|
1877
|
+
Exception type used for errors related to schema definition.
|
|
1878
|
+
*/
|
|
1879
|
+
declare class SchemaError extends Error {
|
|
1880
|
+
}
|
|
1881
|
+
/**
|
|
1882
|
+
Exception type used when validating content against a schema, when
|
|
1883
|
+
checking JSON input, or when validating change sets.
|
|
1884
|
+
*/
|
|
1885
|
+
declare class ValidationError extends Error {
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
type Modification = {
|
|
1889
|
+
add: Mark;
|
|
1890
|
+
} | {
|
|
1891
|
+
remove: Mark;
|
|
1892
|
+
};
|
|
1893
|
+
/**
|
|
1894
|
+
A change set contains a series of changes to a given document that
|
|
1895
|
+
produce a new document. They divide the document in a number of
|
|
1896
|
+
sections that are either kept as-is, have marks added or removed,
|
|
1897
|
+
or are replaced entirely by a {@link Slice} of new tokens.
|
|
1898
|
+
|
|
1899
|
+
Change sets store the length of their start document and will
|
|
1900
|
+
raise an error if you try to apply them to a document with a
|
|
1901
|
+
different length.
|
|
1902
|
+
*/
|
|
1903
|
+
declare class ChangeSet {
|
|
1904
|
+
/**
|
|
1905
|
+
Pairs of integers, with the first one representing the length
|
|
1906
|
+
of the section in the start document, the second either -1 for
|
|
1907
|
+
a preserved, -2 for a marked range, or a non-negative
|
|
1908
|
+
insertion length for a replacement.
|
|
1909
|
+
*/
|
|
1910
|
+
readonly sections: ChangeSet.Sections;
|
|
1911
|
+
private _length;
|
|
1912
|
+
private _newLength;
|
|
1913
|
+
private constructor();
|
|
1914
|
+
/**
|
|
1915
|
+
The length of the start document.
|
|
1916
|
+
*/
|
|
1917
|
+
get length(): number;
|
|
1918
|
+
/**
|
|
1919
|
+
The length of the updated document.
|
|
1920
|
+
*/
|
|
1921
|
+
get newLength(): number;
|
|
1922
|
+
/**
|
|
1923
|
+
Returns true if this set makes no changes.
|
|
1924
|
+
*/
|
|
1925
|
+
get empty(): boolean;
|
|
1926
|
+
/**
|
|
1927
|
+
Compare this change set to another one.
|
|
1928
|
+
*/
|
|
1929
|
+
eq(other: ChangeSet): boolean;
|
|
1930
|
+
/**
|
|
1931
|
+
Apply the changes to the given document, producing a new
|
|
1932
|
+
document. Will raise an error if the document length doesn't
|
|
1933
|
+
match or the change is not well-formed for this document.
|
|
1934
|
+
|
|
1935
|
+
The result of this method is cached, so applying the same change
|
|
1936
|
+
set to the same document multiple times is cheap.
|
|
1937
|
+
*/
|
|
1938
|
+
apply(doc: Plot.Doc): Plot.Doc;
|
|
1939
|
+
/**
|
|
1940
|
+
Convert this change set to a JSON-serializeable representation.
|
|
1941
|
+
*/
|
|
1942
|
+
toJSON(): ChangeSet.JSON;
|
|
1943
|
+
/**
|
|
1944
|
+
Parse a JSON representation into a change set.
|
|
1945
|
+
*/
|
|
1946
|
+
static fromJSON(schema: Schema, json: ChangeSet.JSON): ChangeSet;
|
|
1947
|
+
/**
|
|
1948
|
+
Perform an [operational
|
|
1949
|
+
transformation](https://en.wikipedia.org/wiki/Operational_transformation)
|
|
1950
|
+
on this change and the given other change. Both changes should
|
|
1951
|
+
start with the given document `doc`. Returns a modified version
|
|
1952
|
+
of the change that can be applied _after_ the other change has
|
|
1953
|
+
been applied to `doc`.
|
|
1954
|
+
|
|
1955
|
+
By default, the semantics of conflicting changes are resolved as
|
|
1956
|
+
if `this` came after `other`. That means content inserted in the
|
|
1957
|
+
same position by both will put the content inserted by `this`
|
|
1958
|
+
last. You can set `before` to true to invert this, making `this`
|
|
1959
|
+
come before `other`. Setting this correctly is necessary to make
|
|
1960
|
+
the result of independently applied transformed changes converge.
|
|
1961
|
+
*/
|
|
1962
|
+
transform(doc: Plot.Doc, other: ChangeSet, before?: boolean): ChangeSet;
|
|
1963
|
+
/**
|
|
1964
|
+
Compose two change sets, where `other` starts from the document
|
|
1965
|
+
produced by `this`, into a single change set.
|
|
1966
|
+
*/
|
|
1967
|
+
compose(other: ChangeSet): ChangeSet;
|
|
1968
|
+
/**
|
|
1969
|
+
Compute the inverse of this change set. `doc` is the document
|
|
1970
|
+
that the change starts from. For a given change `A`,
|
|
1971
|
+
`doc.apply(A).apply(A.invert(doc))` equals `doc`.
|
|
1972
|
+
*/
|
|
1973
|
+
invert(doc: Plot.Doc): ChangeSet;
|
|
1974
|
+
/**
|
|
1975
|
+
Returns the change itself if it can be applied to this document
|
|
1976
|
+
and produce a valid new document, or a modified version of the
|
|
1977
|
+
change that _is_ correct.
|
|
1978
|
+
*/
|
|
1979
|
+
correct(doc: Plot.Doc, local?: boolean): ChangeSet;
|
|
1980
|
+
/**
|
|
1981
|
+
Map a document position through this change, returning either
|
|
1982
|
+
the adjusted position, or `null` if a the tracked position is
|
|
1983
|
+
deleted.
|
|
1984
|
+
|
|
1985
|
+
The `assoc` parameter, which defaults to `-1`, decides to which
|
|
1986
|
+
side the position sticks. When content is inserted precisely at
|
|
1987
|
+
the mapped position, it will stay before it when `assoc == -1`,
|
|
1988
|
+
and move after it when `assoc == 1`.
|
|
1989
|
+
|
|
1990
|
+
By default, mapping will always return a new position, even if
|
|
1991
|
+
all the content around the position was deleted. You can pass a
|
|
1992
|
+
{@link ChangeSet.TrackMode tracking mode} to make it return null
|
|
1993
|
+
when either the token before, the token after, or both tokens
|
|
1994
|
+
around the position were deleted.
|
|
1995
|
+
*/
|
|
1996
|
+
mapPos(pos: number, assoc?: -1 | 1): number;
|
|
1997
|
+
mapPos(pos: number, assoc: -1 | 1, track?: ChangeSet.TrackMode): number | null;
|
|
1998
|
+
/**
|
|
1999
|
+
Scan through the content inserted by this change until a tag
|
|
2000
|
+
that matches the predicate is found. If successful, return the
|
|
2001
|
+
position (in the new document) of the tag. This can be useful
|
|
2002
|
+
for when creating a new selection after a fitted change.
|
|
2003
|
+
*/
|
|
2004
|
+
findInserted(pred: (tag: Node.Tag) => boolean): number | null;
|
|
2005
|
+
/**
|
|
2006
|
+
Returns true if any of the replaced ranges in this change set
|
|
2007
|
+
overlaps or is adjacent to the given range.
|
|
2008
|
+
*/
|
|
2009
|
+
touchesRange(from: number, to: number): boolean | "cover";
|
|
2010
|
+
/**
|
|
2011
|
+
Iterate over the ranges in this changeset, calling `replaced`
|
|
2012
|
+
for ranges that have been replaced, and `preserved` for ranges
|
|
2013
|
+
that are either preserved as-is (when `modifications` is null)
|
|
2014
|
+
or only have marks modified.
|
|
2015
|
+
*/
|
|
2016
|
+
iterChanges(replaced: (fromA: number, toA: number, fromB: number, toB: number, inserted: Slice) => void, preserved?: (fromA: number, toA: number, fromB: number, toB: number, modifications: readonly Modification[] | null) => void): void;
|
|
2017
|
+
/**
|
|
2018
|
+
Iterate over the sections of the document this change leaves
|
|
2019
|
+
unchanged or which have only mark changes. `posA` provides the
|
|
2020
|
+
position of the range in the original document, `posB` the
|
|
2021
|
+
position in the changed document.
|
|
2022
|
+
*/
|
|
2023
|
+
iterGaps(gap: (fromA: number, toA: number, fromB: number, toB: number, last: boolean) => void, change?: (fromA: number, toA: number, fromB: number, toB: number) => void): void;
|
|
2024
|
+
/**
|
|
2025
|
+
Iterate over the ranges changed (either replaced or modified) by
|
|
2026
|
+
this change desc. Joins adjacent changed ranges together.
|
|
2027
|
+
*/
|
|
2028
|
+
iterChangedRanges(range: (fromA: number, toA: number, fromB: number, toB: number) => void): void;
|
|
2029
|
+
/**
|
|
2030
|
+
Add skipped sections before and after this change set, so that
|
|
2031
|
+
it can apply to a larger document. Mostly useful when
|
|
2032
|
+
propagating changes from an editor displaying a smaller part of
|
|
2033
|
+
a document into the full document.
|
|
2034
|
+
*/
|
|
2035
|
+
pad(before: number, after: number): ChangeSet;
|
|
2036
|
+
/**
|
|
2037
|
+
Clip the set to only a sub-region. This can fail, if there are
|
|
2038
|
+
replacements across the region's sides, in which case the
|
|
2039
|
+
method returns null
|
|
2040
|
+
*/
|
|
2041
|
+
clip(from: number, to: number): ChangeSet | null;
|
|
2042
|
+
/**
|
|
2043
|
+
Create a change set. All positions in the given change
|
|
2044
|
+
description refer to positions in the starting document.
|
|
2045
|
+
*/
|
|
2046
|
+
static create(doc: Plot.Doc, spec: ChangeSet.Spec): ChangeSet;
|
|
2047
|
+
/**
|
|
2048
|
+
Returns an empty change set for a document of the given length.
|
|
2049
|
+
*/
|
|
2050
|
+
static empty(length: number): ChangeSet;
|
|
2051
|
+
/**
|
|
2052
|
+
Transform two change set starting from the same document over
|
|
2053
|
+
each other, returning two transformed change sets. The returned
|
|
2054
|
+
`a` can be applied after the `b` passed in, and the returned `b`
|
|
2055
|
+
can be applied after the `a` passed in, resulting the same final
|
|
2056
|
+
document on both sides. `a` is taken to happen before `b` when insertions
|
|
2057
|
+
at the same position need to be merged.
|
|
2058
|
+
|
|
2059
|
+
This method is slightly more efficient than transforming both steps
|
|
2060
|
+
separately.
|
|
2061
|
+
*/
|
|
2062
|
+
static transform(doc: Plot.Doc, a: ChangeSet, b: ChangeSet): {
|
|
2063
|
+
a: ChangeSet;
|
|
2064
|
+
b: ChangeSet;
|
|
2065
|
+
};
|
|
2066
|
+
}
|
|
2067
|
+
declare namespace ChangeSet {
|
|
2068
|
+
/**
|
|
2069
|
+
Representation of a single document change, as used in {@link
|
|
2070
|
+
ChangeSet.Spec}. Changes can either affect marks (when `add` or
|
|
2071
|
+
`remove` is present), or replace a part of the document
|
|
2072
|
+
(otherwise).
|
|
2073
|
+
*/
|
|
2074
|
+
type Change = {
|
|
2075
|
+
/**
|
|
2076
|
+
The start position of the change.
|
|
2077
|
+
*/
|
|
2078
|
+
from: number;
|
|
2079
|
+
/**
|
|
2080
|
+
The end position. When not given, this defaults to `from` for
|
|
2081
|
+
replacement changes, and `from + 1` for changes that add or
|
|
2082
|
+
remove marks.
|
|
2083
|
+
*/
|
|
2084
|
+
to?: number;
|
|
2085
|
+
/**
|
|
2086
|
+
Replace the given range with this slice.
|
|
2087
|
+
*/
|
|
2088
|
+
insert?: Slice | readonly Token[];
|
|
2089
|
+
/**
|
|
2090
|
+
For deletions or insertions where it isn't obvious that the
|
|
2091
|
+
replacement will produce a valid document, set this to `true`
|
|
2092
|
+
or a stack of context tags to make the library process the
|
|
2093
|
+
replacement to make sure it fits. Context tags (passed with
|
|
2094
|
+
the innermost tag first, as in {@link Plot.Doc.contextAt} may
|
|
2095
|
+
be used as wrappers when fitting the slice.
|
|
2096
|
+
*/
|
|
2097
|
+
fit?: boolean | readonly Plot.Tag[];
|
|
2098
|
+
/**
|
|
2099
|
+
Add the given mark to this change's range. Cannot be combined
|
|
2100
|
+
with `insert`.
|
|
2101
|
+
*/
|
|
2102
|
+
add?: Mark;
|
|
2103
|
+
/**
|
|
2104
|
+
Remove the given mark from this range.
|
|
2105
|
+
*/
|
|
2106
|
+
remove?: Mark;
|
|
2107
|
+
};
|
|
2108
|
+
/**
|
|
2109
|
+
This type is used to describe a {@link ChangeSet.create change
|
|
2110
|
+
set}. A spec can be a single change, an existing change set, a
|
|
2111
|
+
set of changes wrapped in a correction scope, or an array of the
|
|
2112
|
+
same.
|
|
2113
|
+
|
|
2114
|
+
The {@link ChangeSet.Change.from `from`} and {@link
|
|
2115
|
+
ChangeSet.Change.to `to`} positions in the changes in a set spec
|
|
2116
|
+
all refer to the origin document. It is not necessary to
|
|
2117
|
+
'compensate' for earlier changes in those specified later. If,
|
|
2118
|
+
for some reason, you have changes that should be applied after
|
|
2119
|
+
each other, create multiple change sets and {@link
|
|
2120
|
+
ChangeSet.compose compose} them.
|
|
2121
|
+
|
|
2122
|
+
By default, the provider of changes vouches for their
|
|
2123
|
+
correctness. It is possible to create change sets that will
|
|
2124
|
+
error when you try to apply them, because applying them does not
|
|
2125
|
+
create a well formed document.
|
|
2126
|
+
|
|
2127
|
+
When making changes where you cannot guarantee that they fit,
|
|
2128
|
+
you should either use {@link ChangeSet.Change.fit}, which will
|
|
2129
|
+
try to change the range of a change to make it fit, or the
|
|
2130
|
+
`{correct}` form, which will combine the changes it is given,
|
|
2131
|
+
and then process them as a whole to make sure they produce a
|
|
2132
|
+
valid document. The `local` flag indicates that the effect of
|
|
2133
|
+
changes should be kept as narrow as possible—for example, that
|
|
2134
|
+
nodes opened but not closed by them should not extend to cover
|
|
2135
|
+
content after the change.
|
|
2136
|
+
*/
|
|
2137
|
+
type Spec = ChangeSet.Change | {
|
|
2138
|
+
correct: ChangeSet.Spec;
|
|
2139
|
+
local?: boolean;
|
|
2140
|
+
} | ChangeSet | readonly ChangeSet.Spec[];
|
|
2141
|
+
/**
|
|
2142
|
+
The sections in a change set are represented as an array, with
|
|
2143
|
+
each pair of two numbers describing a changed section. The first
|
|
2144
|
+
number is the length of the section in the old document. The
|
|
2145
|
+
second number is `-1` for unchanged sections, `-2` for updated
|
|
2146
|
+
sections, and a non-negative number (the length of the inserted
|
|
2147
|
+
content) for replacements.
|
|
2148
|
+
*/
|
|
2149
|
+
type Sections = readonly number[];
|
|
2150
|
+
/**
|
|
2151
|
+
The JSON representation of a change set.
|
|
2152
|
+
*/
|
|
2153
|
+
type JSON = readonly (number | [number, Slice.JSON | readonly ModificationJSON[]])[];
|
|
2154
|
+
/**
|
|
2155
|
+
Modes available in {@link ChangeSet.mapPos} to control whether
|
|
2156
|
+
`null` is returned on nearby deletions.
|
|
2157
|
+
*/
|
|
2158
|
+
type TrackMode = "before" | "after" | "around";
|
|
2159
|
+
}
|
|
2160
|
+
type ModificationJSON = {
|
|
2161
|
+
add: string;
|
|
2162
|
+
value: any;
|
|
2163
|
+
} | {
|
|
2164
|
+
remove: string;
|
|
2165
|
+
value: any;
|
|
2166
|
+
};
|
|
2167
|
+
|
|
2168
|
+
/**
|
|
2169
|
+
Serialize a document to an array of {@link Elt elements} and
|
|
2170
|
+
strings. These can be converted to a DOM structure with {@link
|
|
2171
|
+
Elt.Fragment.toDOM} or an HTML string with {@link
|
|
2172
|
+
Elt.Fragment.toHTML}. Will use the shapes specified in the {@link
|
|
2173
|
+
Node.Spec.shape node specs}, unless {@link
|
|
2174
|
+
serialize.Options.override overridden}.
|
|
2175
|
+
*/
|
|
2176
|
+
declare function serialize(doc: Plot.Doc, options?: serialize.Options): Elt.Fragment;
|
|
2177
|
+
declare namespace serialize {
|
|
2178
|
+
/**
|
|
2179
|
+
The options passed to serializer functions.
|
|
2180
|
+
*/
|
|
2181
|
+
interface Options {
|
|
2182
|
+
/**
|
|
2183
|
+
Set this to true to replace nodes with the {@link
|
|
2184
|
+
Node.Role.LineBreak `LineBreak`} role with newline characters.
|
|
2185
|
+
*/
|
|
2186
|
+
emitNewlines?: boolean;
|
|
2187
|
+
/**
|
|
2188
|
+
Override the shape used for some tags. Return null to fall
|
|
2189
|
+
back to the node's default shape.
|
|
2190
|
+
*/
|
|
2191
|
+
override?: (tag: Node.Tag) => Elt | null;
|
|
2192
|
+
}
|
|
2193
|
+
/**
|
|
2194
|
+
Serialize a single node.
|
|
2195
|
+
*/
|
|
2196
|
+
function node(node: Node, options: serialize.Options): Elt | string;
|
|
2197
|
+
/**
|
|
2198
|
+
Serialize a slice.
|
|
2199
|
+
*/
|
|
2200
|
+
function slice(slice: Slice, options: slice.Options): Elt.Fragment;
|
|
2201
|
+
namespace slice {
|
|
2202
|
+
/**
|
|
2203
|
+
Options passed to {@link serialize.slice}.
|
|
2204
|
+
*/
|
|
2205
|
+
interface Options extends serialize.Options {
|
|
2206
|
+
/**
|
|
2207
|
+
If given, the serializer will set this attribute to
|
|
2208
|
+
`"start"`, `"end"`, or `"start end"` for nodes that are open
|
|
2209
|
+
at the start and/or end of the slice.
|
|
2210
|
+
*/
|
|
2211
|
+
openAttr?: string;
|
|
2212
|
+
/**
|
|
2213
|
+
The slice's context. Will be used to determine the type of
|
|
2214
|
+
open nodes at the start of the slice.
|
|
2215
|
+
*/
|
|
2216
|
+
context?: readonly Plot.Tag[];
|
|
2217
|
+
/**
|
|
2218
|
+
The amount of context nodes to include in the output.
|
|
2219
|
+
Defaults to 0, meaning only use those that are open at the
|
|
2220
|
+
start of the slice.
|
|
2221
|
+
*/
|
|
2222
|
+
includeContext?: number;
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
export { Attributes, ChangeSet, Elt, Leaf, Mark, Node, Plot, Pos, Schema, SchemaError, Shape, Slice, Token, ValidationError, parse, serialize };
|