@nerd-bible/wordgard 0.3.3

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/dist/doc.d.ts ADDED
@@ -0,0 +1,2210 @@
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 | Text;
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
+ Convert this node to its JSON-serializeable representation.
1140
+ */
1141
+ toJSON(): Node.JSON;
1142
+ }
1143
+ /**
1144
+ A node type can be either a leaf type or a plot type.
1145
+ */
1146
+ type Type<T = unknown> = Leaf.Type<T> | Plot.Type<T>;
1147
+ namespace Type {
1148
+ /**
1149
+ Used as input type by some functions acting on node types, so
1150
+ that you can pass either a bare type or a singleton leaf or
1151
+ plot tag.
1152
+ */
1153
+ type Ref<T> = Plot.Type<T> | Leaf.Type<T> | Plot.Tag<T> | Leaf<T>;
1154
+ /**
1155
+ Get the type referred to by a {@link Node.Type.Ref reference}.
1156
+ */
1157
+ function get<T>(ref: Ref<T>): Node.Type<T>;
1158
+ }
1159
+ /**
1160
+ A tag is a node type with a parameter and a set of marks. For
1161
+ leaves, the entire node is the tag. For plots, it is a separate
1162
+ object in the {@link Plot.tag `tag` property}.
1163
+ */
1164
+ type Tag = Leaf | Plot.Tag;
1165
+ namespace Tag {
1166
+ /**
1167
+ The interface shared by {@link Leaf leaves} and {@link
1168
+ Plot.Tag plot tags}.
1169
+ */
1170
+ interface Shared<Param> {
1171
+ /**
1172
+ The type of the tag.
1173
+ */
1174
+ type: Node.Type<Param>;
1175
+ /**
1176
+ The tag parameter. Will be `null` for parameter-less types.
1177
+ */
1178
+ param: Param;
1179
+ /**
1180
+ The set of marks for this tag.
1181
+ */
1182
+ marks: Mark.Set;
1183
+ /**
1184
+ The name of the tag's type.
1185
+ */
1186
+ name: string;
1187
+ /**
1188
+ Find the value of the given given make type in this tag's
1189
+ set of marks, or return `undefined` if it isn't present.
1190
+ */
1191
+ mark<Value>(mark: Mark.Type<Value>): Value | undefined;
1192
+ /**
1193
+ Compare this tag to another tag.
1194
+ */
1195
+ eq(other: Node.Tag): boolean;
1196
+ /**
1197
+ Test whether this is a leaf.
1198
+ */
1199
+ isLeaf: boolean;
1200
+ /**
1201
+ Test whether this is a plot tag.
1202
+ */
1203
+ isPlot: boolean;
1204
+ /**
1205
+ Test whether this tag is of the given type.
1206
+ */
1207
+ is<T>(type: Leaf.Type<T>): this is Leaf<T>;
1208
+ is<T>(type: Plot.Type<T>): this is Plot.Tag<T>;
1209
+ /**
1210
+ Holds `true` when this is a text leaf.
1211
+ */
1212
+ isText: boolean;
1213
+ /**
1214
+ Convert this tag to a JSON-serializeable object.
1215
+ */
1216
+ toJSON(): Node.JSON;
1217
+ }
1218
+ /**
1219
+ Deduce a tag type for a given node type or tag.
1220
+ */
1221
+ 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;
1222
+ }
1223
+ /**
1224
+ Shared fields between {@link Leaf.Spec} and {@link Plot.Spec}.
1225
+ */
1226
+ interface Spec<Param> {
1227
+ /**
1228
+ Whether this node is an inline or a block node. Defaults to
1229
+ block.
1230
+ */
1231
+ inline?: boolean;
1232
+ /**
1233
+ The default parameter value for the node type. Only meaningful
1234
+ when the type is being defined directly, rather than as a
1235
+ singleton tag.
1236
+ */
1237
+ defaultParam?: Param;
1238
+ /**
1239
+ A function or type name used to validate this tag's parameter
1240
+ value. This will be used when deserializing the attribute from
1241
+ JSON. When a string, it should be a `|`-separated string of
1242
+ primitive types (`"number"`, `"string"`, `"boolean"`, `"null"`,
1243
+ and `"undefined"`). The library will raise an error when the
1244
+ value is not one of those types. When a function, it should
1245
+ raise an error if the value doesn't have the expected type or
1246
+ shape.
1247
+ */
1248
+ validate?: string | ((param: Param) => void);
1249
+ /**
1250
+ Assign one or more groups to this node type. Groups are used
1251
+ when specifying allowed content for a plot. Schema overrides
1252
+ can {@link Schema.Override.nodeGroup change} a node's set of
1253
+ groups.
1254
+ */
1255
+ group?: Group | readonly Group[];
1256
+ /**
1257
+ Roles to add to this node type, which mark it as having a
1258
+ certain semantic role, such as being a list.
1259
+ */
1260
+ role?: Node.Role | readonly Node.Role[];
1261
+ /**
1262
+ The default DOM/HTML shape of this node. This will determine
1263
+ what the node looks like, both in an editor an in serialized
1264
+ HTML form. In most cases, this also specifies the way the node
1265
+ is parsed when reading HTML content.
1266
+ */
1267
+ shape: Shape.Element<Param> | Shape.Structure<Param>;
1268
+ /**
1269
+ Extra parse rules to associate with this node type.
1270
+ */
1271
+ parseRules?: readonly parse.Rule.Element<Param>[];
1272
+ /**
1273
+ When set to `true`, nodes of this type, if they are a leaf or
1274
+ atom, can be selected by clicking them or moving the selection
1275
+ into them with the keyboard.
1276
+ */
1277
+ selectable?: boolean;
1278
+ }
1279
+ /**
1280
+ The JSON representation for a node or tag.
1281
+ */
1282
+ interface JSON {
1283
+ type: string;
1284
+ param?: any;
1285
+ marks?: {
1286
+ [name: string]: any;
1287
+ };
1288
+ content?: readonly Node.JSON[];
1289
+ }
1290
+ /**
1291
+ Groups are used to specify parent-child relationships between
1292
+ nodes, and valid targets for marks. You can use predefined
1293
+ groups provided as static properties on the class, or define
1294
+ your own for custom categories.
1295
+ */
1296
+ class Group {
1297
+ /**
1298
+ Groups may have a parent group. Membership of a group
1299
+ implies membership of its parent groups.
1300
+ */
1301
+ readonly parent: Group | undefined;
1302
+ private tag;
1303
+ private constructor();
1304
+ /**
1305
+ Define a custom node group.
1306
+ */
1307
+ static define(parent?: Group): Group;
1308
+ /**
1309
+ A group that contains every node type.
1310
+ */
1311
+ static All: Group;
1312
+ /**
1313
+ All inline nodes are automatically assigned to this group.
1314
+ */
1315
+ static Inline: Group;
1316
+ /**
1317
+ Block elements automatically get assigned to this group.
1318
+ */
1319
+ static Block: Group;
1320
+ /**
1321
+ The group of all leaf nodes.
1322
+ */
1323
+ static Leaf: Group;
1324
+ /**
1325
+ The group of all non-leaf nodes.
1326
+ */
1327
+ static Plot: Group;
1328
+ /**
1329
+ Block plots with inline content are tagged as textblocks.
1330
+ */
1331
+ static Textblock: Group;
1332
+ /**
1333
+ A group used for generic block content, such as paragraphs and
1334
+ lists. The basic schema uses this as the content type for the
1335
+ top level document, blockquotes, and list items.
1336
+ */
1337
+ static Content: Group;
1338
+ /**
1339
+ Group for the cell nodes in tables.
1340
+ */
1341
+ static TableCell: Group;
1342
+ /**
1343
+ Generic list item group.
1344
+ */
1345
+ static ListItem: Group;
1346
+ }
1347
+ /**
1348
+ Describes a set of node types. Can be either a single tag or
1349
+ type, which matches exactly that type (tags are assumed to be
1350
+ singleton tags—only their type is used), a reference to a {@link
1351
+ Node.Group node group}, or a combination of multiple of those.
1352
+ An array indicates the union of all the groups in the array
1353
+ (matches types that match any of the queries). An object with an
1354
+ `and` property indicates an intersection (must match all the
1355
+ queries).
1356
+ */
1357
+ type Query = Node.Tag | Node.Type | Group | readonly Node.Query[] | {
1358
+ and: readonly Node.Query[];
1359
+ };
1360
+ /**
1361
+ Roles are used to add some semantic information to node types.
1362
+ You can define your own, and use the `hasRole` method to check
1363
+ whether a given node has the role attached.
1364
+ */
1365
+ class Role {
1366
+ private constructor();
1367
+ /**
1368
+ Define a new role.
1369
+ */
1370
+ static define(): Role;
1371
+ /**
1372
+ This role indicates that a plot contains code, and makes some
1373
+ commands behave differently inside such a plot.
1374
+ */
1375
+ static Code: Role;
1376
+ /**
1377
+ Identifies a plot as a list container. This makes some
1378
+ commands treat the plot specially.
1379
+ */
1380
+ static List: Role;
1381
+ /**
1382
+ A single leaf type in a schema may have the `LineBreak` role,
1383
+ which identifies it as the canonical node that represents a
1384
+ line break. Nodes marked as line breaks will be parsed from
1385
+ and serialized to newline characters inside {@link
1386
+ Plot.Spec.preserveWhitespace whitespace-preserving} nodes.
1387
+ */
1388
+ static LineBreak: Role;
1389
+ }
1390
+ }
1391
+ /**
1392
+ A leaf node, which is a node with no content nodes. Used for
1393
+ things like text, images, line breaks, and so on. Counts as a
1394
+ {@link Node.Tag}.
1395
+ */
1396
+ declare class Leaf<Param = unknown> extends BaseTag<Param> implements Node.Shared, Node.Tag.Shared<Param> {
1397
+ /**
1398
+ This leaf's type.
1399
+ */
1400
+ readonly type: Leaf.Type<Param>;
1401
+ private constructor();
1402
+ get tag(): this;
1403
+ eq(other: Node | Node.Tag): boolean;
1404
+ /**
1405
+ Define a singleton leaf type, without parameter. If you need to
1406
+ store a parameter value in each leaf of the type, use {@link
1407
+ Leaf.Type.define} instead.
1408
+ */
1409
+ static define(name: string, spec: Leaf.Spec<null>): Leaf<null>;
1410
+ withMarks(marks: Mark.Set): Leaf<Param>;
1411
+ /**
1412
+ In {@link Slice slices}, leaf nodes count as node {@link Token
1413
+ tokens}.
1414
+ */
1415
+ get tokenType(): Token.Type.Node;
1416
+ get isLeaf(): true;
1417
+ get isPlot(): false;
1418
+ get length(): number;
1419
+ /**
1420
+ Create a text node with the given text and mark set.
1421
+ */
1422
+ static text(text: string, marks?: Mark.Set): Leaf<string>;
1423
+ }
1424
+ declare namespace Leaf {
1425
+ /**
1426
+ Node type for leaves.
1427
+ */
1428
+ class Type<Param = unknown> extends BaseType<Param> {
1429
+ /**
1430
+ A default leaf for this type. Available if the leaf was
1431
+ defined with {@link Leaf.define}, or a {@link
1432
+ Node.Spec.defaultParam} was given.
1433
+ */
1434
+ default: Leaf<Param> | null;
1435
+ /**
1436
+ The spec used to define this type. Its type parameter is
1437
+ cleared to avoid this field making the class invariant (in the
1438
+ type system sense), which would prevent `Leaf.Type<unknown>`
1439
+ from being a supertype of specific leaf types.
1440
+ */
1441
+ readonly spec: Leaf.Spec<any>;
1442
+ private constructor();
1443
+ /**
1444
+ Define a new leaf type.
1445
+ */
1446
+ static define<T>(name: string, spec: Leaf.Spec<T>): Type<T>;
1447
+ /**
1448
+ Create a leaf with this type.
1449
+ */
1450
+ of(param: Param, marks?: Mark.Set): Leaf<Param>;
1451
+ /**
1452
+ Used to narrow {@link Node.Type} values to {@link Leaf}.
1453
+ */
1454
+ get isLeaf(): true;
1455
+ /**
1456
+ Leaves are not plots.
1457
+ */
1458
+ get isPlot(): false;
1459
+ }
1460
+ interface Spec<Param> extends Node.Spec<Param> {
1461
+ /**
1462
+ Can be used to make leaves of this type show up in the output
1463
+ of {@link Plot.textContent}.
1464
+ */
1465
+ toText?: (node: Leaf) => string;
1466
+ }
1467
+ /**
1468
+ The type of text leaves. Represents a series of characters with
1469
+ a given set of marks. The only leaf with a length that isn't
1470
+ always 1. Adjacent text leaves with the same marks are merged
1471
+ automatically.
1472
+ */
1473
+ const Text: Leaf.Type<string>;
1474
+ }
1475
+ /**
1476
+ Plots delimit parts of the document, giving a special meaning to
1477
+ the nodes inside them. They are defined by a {@link Plot.Tag tag}
1478
+ and an array of {@link Plot.content content}.
1479
+ */
1480
+ declare class Plot implements Node.Shared {
1481
+ /**
1482
+ The tag that identifies this plot.
1483
+ */
1484
+ readonly tag: Plot.Tag;
1485
+ /**
1486
+ The nodes in this plot.
1487
+ */
1488
+ readonly content: readonly Node[];
1489
+ /**
1490
+ The sum of the length of this plot's content nodes.
1491
+ */
1492
+ contentLength: number;
1493
+ get name(): string;
1494
+ /**
1495
+ The type of this plot's tag.
1496
+ */
1497
+ get type(): Plot.Type<unknown>;
1498
+ get marks(): Mark.Set;
1499
+ get length(): number;
1500
+ eq(other: Node): boolean;
1501
+ /**
1502
+ Compare the content of this plot to the content of the given
1503
+ plot.
1504
+ */
1505
+ contentEq(other: Plot): boolean;
1506
+ /**
1507
+ @hidden
1508
+ */
1509
+ is<T>(type: Leaf.Type<T>): false;
1510
+ get isText(): false;
1511
+ /**
1512
+ Tells you whether the content of this plot is inline.
1513
+ */
1514
+ get inlineContent(): boolean;
1515
+ /**
1516
+ True if this is a block node with inline content.
1517
+ */
1518
+ get isTextblock(): boolean;
1519
+ get isLeaf(): false;
1520
+ get isPlot(): true;
1521
+ /**
1522
+ True if this is a document node.
1523
+ */
1524
+ get isDoc(): boolean;
1525
+ /**
1526
+ Get the plot's first child, if any.
1527
+ */
1528
+ get firstChild(): Node | null;
1529
+ /**
1530
+ Get the plot's first child.
1531
+ */
1532
+ get lastChild(): Node | null;
1533
+ /**
1534
+ Iterate though the given range (or the entire document, when
1535
+ given only one argument), and call the given function on every
1536
+ node that overlaps the given range, outer nodes before inner
1537
+ nodes. When the function returns `false` for a node, descendents
1538
+ of that node are not iterated.
1539
+ */
1540
+ iterate(from: number, to: number, f: (node: Node, pos: number, parent: Plot | null, index: number) => boolean | void): void;
1541
+ iterate(f: (node: Node, pos: number, parent: Plot | null, index: number) => boolean | void): void;
1542
+ /**
1543
+ Return the node that starts at the given offset from this node's
1544
+ content start, if any. Will not return text nodes.
1545
+ */
1546
+ nodeAt(pos: number): Node | null;
1547
+ /**
1548
+ Return the plot at the given offset, if any.
1549
+ */
1550
+ plotAt(pos: number): Plot | null;
1551
+ /**
1552
+ Return the text content of this plot.
1553
+ */
1554
+ textContent(options?: {
1555
+ /**
1556
+ An optional start position, as an offset from the plot's
1557
+ content start.
1558
+ */
1559
+ from?: number;
1560
+ /**
1561
+ An optional end position.
1562
+ */
1563
+ to?: number;
1564
+ /**
1565
+ Text to separate blocks with. Defaults to a single newline
1566
+ character.
1567
+ */
1568
+ blockSeparator?: string;
1569
+ /**
1570
+ Override the way non-text leaves are converted to string.
1571
+ */
1572
+ leafText?: string | ((node: Leaf) => string);
1573
+ }): string;
1574
+ toJSON(): Node.JSON;
1575
+ mark<Value>(mark: Mark.Type<Value>): Value | undefined;
1576
+ withMarks(marks: Mark.Set): Plot;
1577
+ /**
1578
+ Plot nodes count as node {@link Token tokens} in a {@link
1579
+ Slice}.
1580
+ */
1581
+ get tokenType(): Token.Type.Node;
1582
+ /**
1583
+ Define a singleton plot type. If the plot needs a parameter
1584
+ value, use {@link Plot.Type.define} instead.
1585
+ */
1586
+ static define(name: string, spec: Plot.Spec<null>): Plot.Tag<null>;
1587
+ /**
1588
+ Define a document plot type. Exactly one of these must occur in a schema.
1589
+ */
1590
+ static defineDoc(spec: {
1591
+ inlineContent?: Node.Query | true;
1592
+ blockContent?: Node.Query;
1593
+ canBeEmpty?: boolean;
1594
+ }): Plot.Type<null>;
1595
+ }
1596
+ declare namespace Plot {
1597
+ /**
1598
+ The end token for a plot. Used in {@link Slice slices}.
1599
+ */
1600
+ const End: {
1601
+ tokenType: Token.Type.Close;
1602
+ };
1603
+ /**
1604
+ A plot tag holds the type of the plot, its parameter (if any),
1605
+ and a set of marks.
1606
+ */
1607
+ class Tag<Param = unknown> extends BaseTag<Param> implements Node.Tag.Shared<Param> {
1608
+ readonly type: Plot.Type<Param>;
1609
+ private constructor();
1610
+ eq(other: Node | Node.Tag): boolean;
1611
+ /**
1612
+ Create a plot with this tag and the given content.
1613
+ */
1614
+ create(content?: readonly Node[]): Plot;
1615
+ /**
1616
+ Create a copy of this tag with the given marks.
1617
+ */
1618
+ withMarks(marks: Mark.Set): Tag<Param>;
1619
+ /**
1620
+ Return a tag that represents content split off from the plot
1621
+ with this tag. Will respect the {@link Mark.Spec.keepOnSplit}
1622
+ mark property. `atEnd` should be set to true if the split
1623
+ happens at the end of the plot's content.
1624
+ */
1625
+ split(atEnd: boolean): Tag<Param>;
1626
+ /**
1627
+ A plot tag counts as an open {@link Token token} in a {@link
1628
+ Slice slice}.
1629
+ */
1630
+ get tokenType(): Token.Type.Open;
1631
+ /**
1632
+ True when this plot type contains inline content.
1633
+ */
1634
+ get inlineContent(): boolean;
1635
+ /**
1636
+ True when this is a block plot with inline content.
1637
+ */
1638
+ get isTextblock(): boolean;
1639
+ get isLeaf(): false;
1640
+ get isPlot(): true;
1641
+ /**
1642
+ Test whether this is a document plot.
1643
+ */
1644
+ get isDoc(): boolean;
1645
+ }
1646
+ /**
1647
+ A type of {@link Plot plot}.
1648
+ */
1649
+ class Type<Param = unknown> extends BaseType<Param> {
1650
+ /**
1651
+ A default tag for this plot type.
1652
+ */
1653
+ readonly default: Plot.Tag<Param> | null;
1654
+ /**
1655
+ Whether the {@link Plot.Spec.isolating} flag is set on this
1656
+ plot type.
1657
+ */
1658
+ readonly isolating: boolean;
1659
+ /**
1660
+ The plot's {@link Plot.Spec.defining} flag.
1661
+ */
1662
+ readonly defining: boolean;
1663
+ /**
1664
+ The plot's {@link Plot.Spec.neutral} flag.
1665
+ */
1666
+ readonly neutral: boolean;
1667
+ /**
1668
+ Whether whitespace should be preserved inside this plot.
1669
+ */
1670
+ readonly preserveWhitespace: boolean;
1671
+ /**
1672
+ The orientation of the content of the plot. Will be `"row"`
1673
+ for plots with inline content, and defaults to `"column"` for
1674
+ plots with block content unless explicitly {@link
1675
+ Plot.Spec.orientation set}.
1676
+ */
1677
+ readonly orientation: "row" | "column";
1678
+ /**
1679
+ The spec used to define this plot type.
1680
+ */
1681
+ readonly spec: Plot.Spec<any>;
1682
+ private constructor();
1683
+ /**
1684
+ Define a plot type.
1685
+ */
1686
+ static define<T>(name: string, spec: Plot.Spec<T>): Type<T>;
1687
+ /**
1688
+ Create a plot tag of this type with the given parameter and
1689
+ mark set.
1690
+ */
1691
+ of(param: Param, marks?: Mark.Set): Tag<Param>;
1692
+ /**
1693
+ Tells you whether this plot type has inline content.
1694
+ */
1695
+ get inlineContent(): boolean;
1696
+ /**
1697
+ True if this is a block plot with inline content.
1698
+ */
1699
+ get isTextblock(): boolean;
1700
+ /**
1701
+ True if this is a document plot type.
1702
+ */
1703
+ get isDoc(): boolean;
1704
+ /**
1705
+ Tells you that this is not a leaf type.
1706
+ */
1707
+ get isLeaf(): false;
1708
+ /**
1709
+ This is a plot type. Can be used to narrow `Node.Type` to
1710
+ `Plot.Type`.
1711
+ */
1712
+ get isPlot(): true;
1713
+ /**
1714
+ Tells you whether this plot type is allowed {@link
1715
+ Plot.Spec.canBeEmpty to be empty}.
1716
+ */
1717
+ get canBeEmpty(): boolean;
1718
+ }
1719
+ /**
1720
+ Object used to define a plot type.
1721
+ */
1722
+ interface Spec<Param> extends Node.Spec<Param> {
1723
+ /**
1724
+ When this node has block-level content, provide a query
1725
+ matching the nodes it may contain here. You generally don't
1726
+ want to use `Node.Group.Block` here, since specialized block
1727
+ types (like table cells or list items) should probably only be
1728
+ allowed in their designated parent plots.
1729
+ */
1730
+ blockContent?: Node.Query;
1731
+ /**
1732
+ When this node has inline content, provide a query specifying
1733
+ valid content. If set to `true`, any inline node may appear in
1734
+ this node.
1735
+ */
1736
+ inlineContent?: Node.Query | true;
1737
+ /**
1738
+ Plots with block content, by default, require at least one
1739
+ child. You can set this to true to allow them to be empty.
1740
+ Plots with inlne content can always be empty.
1741
+ */
1742
+ canBeEmpty?: boolean;
1743
+ /**
1744
+ Whether the sides of this plot act as a 'barrier' when {@link
1745
+ state.GardSelection.nextNormalCursor normalizing} a cursor
1746
+ position, which means that a separate cursor position exists
1747
+ at its boundary. By default, nodes that are {@link
1748
+ Plot.Spec.isolating isolating}, {@link
1749
+ Plot.Spec.preserveWhitespace whitespace-preserving}, or both
1750
+ a {@link Leaf leaf} and a block count as barriers.
1751
+ */
1752
+ cursorBarrier?: boolean;
1753
+ /**
1754
+ Indicates that this type of block is the default generic block
1755
+ type in parent nodes where it may occur (which is appropriate
1756
+ for, for example, paragraphs tags). Default blocks should not
1757
+ have a required param. When not specified, the configuration
1758
+ precedence order determines which child type is the default.
1759
+ */
1760
+ defaultBlock?: boolean;
1761
+ /**
1762
+ Controls whether whitespace inside this type of node should be
1763
+ preserved. Disables whitespace collapsing and the replacement
1764
+ of newlines with line break nodes in the parser and
1765
+ serializer. Defaults to false, unless the node has the {@link
1766
+ Node.Role.Code} role.
1767
+ */
1768
+ preserveWhitespace?: boolean;
1769
+ /**
1770
+ Isolating plots disallow some kinds of editing across their
1771
+ borders (such as backspacing or unwrapping). A table cell is
1772
+ an example of a node that you'd use this for.
1773
+ */
1774
+ isolating?: boolean;
1775
+ /**
1776
+ Block containers are, by default, assumed to arrange their
1777
+ children vertically below each other (`"column"`). You can set this
1778
+ to `"row"` to tell the editor that this container's children
1779
+ are horizontally next to each other.
1780
+ */
1781
+ orientation?: "row" | "column";
1782
+ /**
1783
+ Defining nodes are preserved (when possible) when their content
1784
+ is duplicated (dragged, pasted, etc) into a new position.
1785
+ Defaults to false.
1786
+ */
1787
+ defining?: boolean;
1788
+ /**
1789
+ Neutral nodes may be completely replaced when their entire
1790
+ content gets replaced. Defaults to `!`{@link
1791
+ Plot.Spec.defining}.
1792
+ */
1793
+ neutral?: boolean;
1794
+ /**
1795
+ Whether block nodes of this type should be automatically
1796
+ joined when they become adjacent through an edit. Defaults to
1797
+ false. Note that editing commands need to explicitly call
1798
+ {@link command.autoJoinBlocks} for joining to happen.
1799
+ */
1800
+ autoJoin?: boolean | ((before: Plot.Tag, after: Plot.Tag) => boolean);
1801
+ /**
1802
+ By default, splitting a textblock at the end will revert the new
1803
+ block to the default type of textblock at that position. Setting
1804
+ this to true on a textblock type will prevent that behavior.
1805
+ */
1806
+ preserveOnSplitAtEnd?: boolean;
1807
+ /**
1808
+ For inline nodes with inline content, this determines whether
1809
+ there are normalized cursor positions directly inside the node.
1810
+ The default is to only have cursor positions right outside the
1811
+ node.
1812
+ */
1813
+ cursorInsideBounds?: boolean;
1814
+ }
1815
+ /**
1816
+ Document plots are used as the top level plot in a document.
1817
+ They offer some additional methods and, unlike normal plots,
1818
+ their {@link Plot.Doc.length `length` property} reports only the
1819
+ length of their content, without counting open/close tokens
1820
+ (because those are not part of the document).
1821
+ */
1822
+ class Doc extends Plot {
1823
+ /**
1824
+ The document's schema.
1825
+ */
1826
+ readonly schema: Schema;
1827
+ private constructor();
1828
+ /**
1829
+ The length of the document's content.
1830
+ */
1831
+ get length(): number;
1832
+ /**
1833
+ Resolve the given position in the document, returning an
1834
+ object describing its context.
1835
+ */
1836
+ resolve(pos: number): Pos;
1837
+ /**
1838
+ Resolve the node at the given position, providing information
1839
+ about its context.
1840
+ */
1841
+ resolveNode(pos: number): Pos.Node | null;
1842
+ /**
1843
+ Like {@link Plot.Doc.resolveNode}, but only resolves plot
1844
+ nodes.
1845
+ */
1846
+ resolvePlot(pos: number): Pos.Plot | null;
1847
+ /**
1848
+ Get the context stack (the array of wrapping plot tags,
1849
+ inner-to-outer) at the given position.
1850
+ */
1851
+ contextAt(pos: number, maxDepth?: number): readonly Plot.Tag[];
1852
+ /**
1853
+ Create a slice of the content between `from` and `to`.
1854
+ */
1855
+ slice(from: number, to?: number): Slice;
1856
+ }
1857
+ }
1858
+
1859
+ /**
1860
+ Exception type used for errors related to schema definition.
1861
+ */
1862
+ declare class SchemaError extends Error {
1863
+ }
1864
+ /**
1865
+ Exception type used when validating content against a schema, when
1866
+ checking JSON input, or when validating change sets.
1867
+ */
1868
+ declare class ValidationError extends Error {
1869
+ }
1870
+
1871
+ type Modification = {
1872
+ add: Mark;
1873
+ } | {
1874
+ remove: Mark;
1875
+ };
1876
+ /**
1877
+ A change set contains a series of changes to a given document that
1878
+ produce a new document. They divide the document in a number of
1879
+ sections that are either kept as-is, have marks added or removed,
1880
+ or are replaced entirely by a {@link Slice} of new tokens.
1881
+
1882
+ Change sets store the length of their start document and will
1883
+ raise an error if you try to apply them to a document with a
1884
+ different length.
1885
+ */
1886
+ declare class ChangeSet {
1887
+ /**
1888
+ Pairs of integers, with the first one representing the length
1889
+ of the section in the start document, the second either -1 for
1890
+ a preserved, -2 for a marked range, or a non-negative
1891
+ insertion length for a replacement.
1892
+ */
1893
+ readonly sections: ChangeSet.Sections;
1894
+ private _length;
1895
+ private _newLength;
1896
+ private constructor();
1897
+ /**
1898
+ The length of the start document.
1899
+ */
1900
+ get length(): number;
1901
+ /**
1902
+ The length of the updated document.
1903
+ */
1904
+ get newLength(): number;
1905
+ /**
1906
+ Returns true if this set makes no changes.
1907
+ */
1908
+ get empty(): boolean;
1909
+ /**
1910
+ Compare this change set to another one.
1911
+ */
1912
+ eq(other: ChangeSet): boolean;
1913
+ /**
1914
+ Apply the changes to the given document, producing a new
1915
+ document. Will raise an error if the document length doesn't
1916
+ match or the change is not well-formed for this document.
1917
+
1918
+ The result of this method is cached, so applying the same change
1919
+ set to the same document multiple times is cheap.
1920
+ */
1921
+ apply(doc: Plot.Doc): Plot.Doc;
1922
+ /**
1923
+ Convert this change set to a JSON-serializeable representation.
1924
+ */
1925
+ toJSON(): ChangeSet.JSON;
1926
+ /**
1927
+ Parse a JSON representation into a change set.
1928
+ */
1929
+ static fromJSON(schema: Schema, json: ChangeSet.JSON): ChangeSet;
1930
+ /**
1931
+ Perform an [operational
1932
+ transformation](https://en.wikipedia.org/wiki/Operational_transformation)
1933
+ on this change and the given other change. Both changes should
1934
+ start with the given document `doc`. Returns a modified version
1935
+ of the change that can be applied _after_ the other change has
1936
+ been applied to `doc`.
1937
+
1938
+ By default, the semantics of conflicting changes are resolved as
1939
+ if `this` came after `other`. That means content inserted in the
1940
+ same position by both will put the content inserted by `this`
1941
+ last. You can set `before` to true to invert this, making `this`
1942
+ come before `other`. Setting this correctly is necessary to make
1943
+ the result of independently applied transformed changes converge.
1944
+ */
1945
+ transform(doc: Plot.Doc, other: ChangeSet, before?: boolean): ChangeSet;
1946
+ /**
1947
+ Compose two change sets, where `other` starts from the document
1948
+ produced by `this`, into a single change set.
1949
+ */
1950
+ compose(other: ChangeSet): ChangeSet;
1951
+ /**
1952
+ Compute the inverse of this change set. `doc` is the document
1953
+ that the change starts from. For a given change `A`,
1954
+ `doc.apply(A).apply(A.invert(doc))` equals `doc`.
1955
+ */
1956
+ invert(doc: Plot.Doc): ChangeSet;
1957
+ /**
1958
+ Returns the change itself if it can be applied to this document
1959
+ and produce a valid new document, or a modified version of the
1960
+ change that _is_ correct.
1961
+ */
1962
+ correct(doc: Plot.Doc, local?: boolean): ChangeSet;
1963
+ /**
1964
+ Map a document position through this change, returning either
1965
+ the adjusted position, or `null` if a the tracked position is
1966
+ deleted.
1967
+
1968
+ The `assoc` parameter, which defaults to `-1`, decides to which
1969
+ side the position sticks. When content is inserted precisely at
1970
+ the mapped position, it will stay before it when `assoc == -1`,
1971
+ and move after it when `assoc == 1`.
1972
+
1973
+ By default, mapping will always return a new position, even if
1974
+ all the content around the position was deleted. You can pass a
1975
+ {@link ChangeSet.TrackMode tracking mode} to make it return null
1976
+ when either the token before, the token after, or both tokens
1977
+ around the position were deleted.
1978
+ */
1979
+ mapPos(pos: number, assoc?: -1 | 1): number;
1980
+ mapPos(pos: number, assoc: -1 | 1, track?: ChangeSet.TrackMode): number | null;
1981
+ /**
1982
+ Scan through the content inserted by this change until a tag
1983
+ that matches the predicate is found. If successful, return the
1984
+ position (in the new document) of the tag. This can be useful
1985
+ for when creating a new selection after a fitted change.
1986
+ */
1987
+ findInserted(pred: (tag: Node.Tag) => boolean): number | null;
1988
+ /**
1989
+ Returns true if any of the replaced ranges in this change set
1990
+ overlaps or is adjacent to the given range.
1991
+ */
1992
+ touchesRange(from: number, to: number): boolean | "cover";
1993
+ /**
1994
+ Iterate over the ranges in this changeset, calling `replaced`
1995
+ for ranges that have been replaced, and `preserved` for ranges
1996
+ that are either preserved as-is (when `modifications` is null)
1997
+ or only have marks modified.
1998
+ */
1999
+ 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;
2000
+ /**
2001
+ Iterate over the sections of the document this change leaves
2002
+ unchanged or which have only mark changes. `posA` provides the
2003
+ position of the range in the original document, `posB` the
2004
+ position in the changed document.
2005
+ */
2006
+ iterGaps(gap: (fromA: number, toA: number, fromB: number, toB: number) => void, change?: (fromA: number, toA: number, fromB: number, toB: number) => void): void;
2007
+ /**
2008
+ Iterate over the ranges changed (either replaced or modified) by
2009
+ this change desc. Joins adjacent changed ranges together.
2010
+ */
2011
+ iterChangedRanges(range: (fromA: number, toA: number, fromB: number, toB: number) => void): void;
2012
+ /**
2013
+ Add skipped sections before and after this change set, so that
2014
+ it can apply to a larger document. Mostly useful when
2015
+ propagating changes from an editor displaying a smaller part of
2016
+ a document into the full document.
2017
+ */
2018
+ pad(before: number, after: number): ChangeSet;
2019
+ /**
2020
+ Clip the set to only a sub-region. This can fail, if there are
2021
+ replacements across the region's sides, in which case the
2022
+ method returns null
2023
+ */
2024
+ clip(from: number, to: number): ChangeSet | null;
2025
+ /**
2026
+ Create a change set. All positions in the given change
2027
+ description refer to positions in the starting document.
2028
+ */
2029
+ static create(doc: Plot.Doc, spec: ChangeSet.Spec): ChangeSet;
2030
+ /**
2031
+ Returns an empty change set for a document of the given length.
2032
+ */
2033
+ static empty(length: number): ChangeSet;
2034
+ /**
2035
+ Transform two change set starting from the same document over
2036
+ each other, returning two transformed change sets. The returned
2037
+ `a` can be applied after the `b` passed in, and the returned `b`
2038
+ can be applied after the `a` passed in, resulting the same final
2039
+ document on both sides. `a` is taken to happen before `b` when insertions
2040
+ at the same position need to be merged.
2041
+
2042
+ This method is slightly more efficient than transforming both steps
2043
+ separately.
2044
+ */
2045
+ static transform(doc: Plot.Doc, a: ChangeSet, b: ChangeSet): {
2046
+ a: ChangeSet;
2047
+ b: ChangeSet;
2048
+ };
2049
+ }
2050
+ declare namespace ChangeSet {
2051
+ /**
2052
+ Representation of a single document change, as used in {@link
2053
+ ChangeSet.Spec}. Changes can either affect marks (when `add` or
2054
+ `remove` is present), or replace a part of the document
2055
+ (otherwise).
2056
+ */
2057
+ type Change = {
2058
+ /**
2059
+ The start position of the change.
2060
+ */
2061
+ from: number;
2062
+ /**
2063
+ The end position. When not given, this defaults to `from` for
2064
+ replacement changes, and `from + 1` for changes that add or
2065
+ remove marks.
2066
+ */
2067
+ to?: number;
2068
+ /**
2069
+ Replace the given range with this slice.
2070
+ */
2071
+ insert?: Slice | readonly Token[];
2072
+ /**
2073
+ For deletions or insertions where it isn't obvious that the
2074
+ replacement will produce a valid document, set this to `true`
2075
+ or a stack of context tags to make the library process the
2076
+ replacement to make sure it fits. Context tags (passed with
2077
+ the innermost tag first, as in {@link Plot.Doc.contextAt} may
2078
+ be used as wrappers when fitting the slice.
2079
+ */
2080
+ fit?: boolean | readonly Plot.Tag[];
2081
+ /**
2082
+ Add the given mark to this change's range. Cannot be combined
2083
+ with `insert`.
2084
+ */
2085
+ add?: Mark;
2086
+ /**
2087
+ Remove the given mark from this range.
2088
+ */
2089
+ remove?: Mark;
2090
+ };
2091
+ /**
2092
+ This type is used to describe a {@link ChangeSet.create change
2093
+ set}. A spec can be a single change, an existing change set, a
2094
+ set of changes wrapped in a correction scope, or an array of the
2095
+ same.
2096
+
2097
+ The {@link ChangeSet.Change.from `from`} and {@link
2098
+ ChangeSet.Change.to `to`} positions in the changes in a set spec
2099
+ all refer to the origin document. It is not necessary to
2100
+ 'compensate' for earlier changes in those specified later. If,
2101
+ for some reason, you have changes that should be applied after
2102
+ each other, create multiple change sets and {@link
2103
+ ChangeSet.compose compose} them.
2104
+
2105
+ By default, the provider of changes vouches for their
2106
+ correctness. It is possible to create change sets that will
2107
+ error when you try to apply them, because applying them does not
2108
+ create a well formed document.
2109
+
2110
+ When making changes where you cannot guarantee that they fit,
2111
+ you should either use {@link ChangeSet.Change.fit}, which will
2112
+ try to change the range of a change to make it fit, or the
2113
+ `{correct}` form, which will combine the changes it is given,
2114
+ and then process them as a whole to make sure they produce a
2115
+ valid document. The `local` flag indicates that the effect of
2116
+ changes should be kept as narrow as possible—for example, that
2117
+ nodes opened but not closed by them should not extend to cover
2118
+ content after the change.
2119
+ */
2120
+ type Spec = ChangeSet.Change | {
2121
+ correct: ChangeSet.Spec;
2122
+ local?: boolean;
2123
+ } | ChangeSet | readonly ChangeSet.Spec[];
2124
+ /**
2125
+ The sections in a change set are represented as an array, with
2126
+ each pair of two numbers describing a changed section. The first
2127
+ number is the length of the section in the old document. The
2128
+ second number is `-1` for unchanged sections, `-2` for updated
2129
+ sections, and a non-negative number (the length of the inserted
2130
+ content) for replacements.
2131
+ */
2132
+ type Sections = readonly number[];
2133
+ /**
2134
+ The JSON representation of a change set.
2135
+ */
2136
+ type JSON = readonly (number | [number, Slice.JSON | readonly ModificationJSON[]])[];
2137
+ /**
2138
+ Modes available in {@link ChangeSet.mapPos} to control whether
2139
+ `null` is returned on nearby deletions.
2140
+ */
2141
+ type TrackMode = "before" | "after" | "around";
2142
+ }
2143
+ type ModificationJSON = {
2144
+ add: string;
2145
+ value: any;
2146
+ } | {
2147
+ remove: string;
2148
+ value: any;
2149
+ };
2150
+
2151
+ /**
2152
+ Serialize a document to an array of {@link Elt elements} and
2153
+ strings. These can be converted to a DOM structure with {@link
2154
+ Elt.Fragment.toDOM} or an HTML string with {@link
2155
+ Elt.Fragment.toHTML}. Will use the shapes specified in the {@link
2156
+ Node.Spec.shape node specs}, unless {@link
2157
+ serialize.Options.override overridden}.
2158
+ */
2159
+ declare function serialize(doc: Plot.Doc, options?: serialize.Options): Elt.Fragment;
2160
+ declare namespace serialize {
2161
+ /**
2162
+ The options passed to serializer functions.
2163
+ */
2164
+ interface Options {
2165
+ /**
2166
+ Set this to true to replace nodes with the {@link
2167
+ Node.Role.LineBreak `LineBreak`} role with newline characters.
2168
+ */
2169
+ emitNewlines?: boolean;
2170
+ /**
2171
+ Override the shape used for some tags. Return null to fall
2172
+ back to the node's default shape.
2173
+ */
2174
+ override?: (tag: Node.Tag) => Elt | null;
2175
+ }
2176
+ /**
2177
+ Serialize a single node.
2178
+ */
2179
+ function node(node: Node, options: serialize.Options): Elt | string;
2180
+ /**
2181
+ Serialize a slice.
2182
+ */
2183
+ function slice(slice: Slice, options: slice.Options): Elt.Fragment;
2184
+ namespace slice {
2185
+ /**
2186
+ Options passed to {@link serialize.slice}.
2187
+ */
2188
+ interface Options extends serialize.Options {
2189
+ /**
2190
+ If given, the serializer will set this attribute to
2191
+ `"start"`, `"end"`, or `"start end"` for nodes that are open
2192
+ at the start and/or end of the slice.
2193
+ */
2194
+ openAttr?: string;
2195
+ /**
2196
+ The slice's context. Will be used to determine the type of
2197
+ open nodes at the start of the slice.
2198
+ */
2199
+ context?: readonly Plot.Tag[];
2200
+ /**
2201
+ The amount of context nodes to include in the output.
2202
+ Defaults to 0, meaning only use those that are open at the
2203
+ start of the slice.
2204
+ */
2205
+ includeContext?: number;
2206
+ }
2207
+ }
2208
+ }
2209
+
2210
+ export { Attributes, ChangeSet, Elt, Leaf, Mark, Node, Plot, Pos, Schema, SchemaError, Shape, Slice, Token, ValidationError, parse, serialize };