@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.
@@ -0,0 +1,1382 @@
1
+ import { ChangeSet, Node, Pos, Plot, Mark, Schema } from 'wordgard/doc';
2
+
3
+ type wgNode = Node;
4
+ /**
5
+ The base class for editor selections. Actual selections will be a
6
+ subclass of this—usually {@link GardSelection.Text} or {@link
7
+ GardSelection.Node}.
8
+ */
9
+ declare abstract class GardSelection {
10
+ /**
11
+ The anchor of the selection—the side that doesn't move when
12
+ you extend it.
13
+ */
14
+ readonly anchor: number;
15
+ /**
16
+ The head of the selection, which is moved when it is extended
17
+ (for example by moving the cursor while holding Shift).
18
+ */
19
+ readonly head: number;
20
+ /**
21
+ The goal column (stored vertical offset) associated with a
22
+ selection. This is used to preserve the vertical position when
23
+ moving across lines of different length.
24
+ */
25
+ readonly goalColumn?: number | undefined;
26
+ protected constructor(
27
+ /**
28
+ The anchor of the selection—the side that doesn't move when
29
+ you extend it.
30
+ */
31
+ anchor: number,
32
+ /**
33
+ The head of the selection, which is moved when it is extended
34
+ (for example by moving the cursor while holding Shift).
35
+ */
36
+ head: number,
37
+ /**
38
+ The goal column (stored vertical offset) associated with a
39
+ selection. This is used to preserve the vertical position when
40
+ moving across lines of different length.
41
+ */
42
+ goalColumn?: number | undefined);
43
+ /**
44
+ The lower boundary of the selected range.
45
+ */
46
+ get from(): number;
47
+ /**
48
+ The upper boundary of the range.
49
+ */
50
+ get to(): number;
51
+ /**
52
+ True when `anchor` and `head` are at the same position.
53
+ */
54
+ get empty(): boolean;
55
+ /**
56
+ Returns true when this is an empty text selection.
57
+ */
58
+ get isCursor(): boolean;
59
+ /**
60
+ The set of ranges covered by this selection, sorted. By default,
61
+ this is just the selection's main `from` to `to`, but custom
62
+ selection implementations can override it.
63
+ */
64
+ get ranges(): readonly {
65
+ from: number;
66
+ to: number;
67
+ }[];
68
+ /**
69
+ The range that should be used when replacing this selection with
70
+ other content (for example when typing or pasting over it) or
71
+ deleting it. The default implementation returns `this.from` to
72
+ `this.to`.
73
+ */
74
+ get replacementRange(): {
75
+ from: number;
76
+ to: number;
77
+ };
78
+ /**
79
+ This can be overridden to control the DOM selection created for
80
+ a selection. The default is to just return the selection's own
81
+ head and anchor.
82
+ */
83
+ get domSelection(): {
84
+ head: number;
85
+ headSide: -1 | 1;
86
+ anchor: number;
87
+ anchorSide: -1 | 1;
88
+ };
89
+ /**
90
+ The side that the selection head is associated with. -1 means it
91
+ is after the element before its position, 1 means it is before
92
+ the element after its position. This influences where the
93
+ cursor is drawn (for example when on a line wrapping boundary
94
+ or in bidirectional text) and where further motion takes it. It
95
+ is valid for it to point in a direction where the is no element
96
+ (say, -1 when at the start of its parent node).
97
+
98
+ By default, this points in the direction of the anchor or
99
+ forward if that is equal to the head, but selection types like
100
+ {@link GardSelection.Text} can override it.
101
+ */
102
+ get headSide(): -1 | 1;
103
+ /**
104
+ The {@link GardSelection.headSide side} associated with the
105
+ selection anchor. Also by default points towards the head, or if
106
+ that is the same position, forward.
107
+ */
108
+ get anchorSide(): -1 | 1;
109
+ /**
110
+ Compare this selection to another selection.
111
+ */
112
+ abstract eq(other: GardSelection): boolean;
113
+ /**
114
+ Returns true if this selection has the same head and anchor as
115
+ the given selection.
116
+ */
117
+ eqPos(other: GardSelection): boolean;
118
+ /**
119
+ Map a selection through a change. Used to adjust the selection
120
+ position for changes.
121
+ */
122
+ abstract map(change: ChangeSet, cx: GardSelection.Context, assoc?: -1 | 1): GardSelection;
123
+ /**
124
+ Convert this selection to an object that can be serialized to
125
+ JSON. Each selection type may define its own JSON representation
126
+ format.
127
+ */
128
+ toJSON(state: GardState): unknown;
129
+ /**
130
+ Deserialize a selection. The configuration is used to associate
131
+ custom selection types with their implementation.
132
+ */
133
+ static fromJSON(cx: GardSelection.Context, json: unknown): GardSelection;
134
+ /**
135
+ Create a cursor text selection at the given position.
136
+ */
137
+ static cursor(pos: number, side?: -1 | 1, goalColumn?: number): GardSelection.Text;
138
+ /**
139
+ Find a normal cursor near the given position.
140
+ */
141
+ static near(cx: GardSelection.Context, pos: number, side?: -1 | 1, goalColumn?: number): GardSelection.Text;
142
+ /**
143
+ Create a text selection.
144
+ */
145
+ static range(anchor: number, head?: number, headSide?: -1 | 1, goalColumn?: number): GardSelection.Text;
146
+ /**
147
+ Create a node selection.
148
+ */
149
+ static node(pos: number, node: wgNode, goalColumn?: number): GardSelection.Node;
150
+ /**
151
+ Find the next normal cursor position after or before this selection's
152
+ head. Normal cursor positions are:
153
+
154
+ - Any inline position.
155
+
156
+ - Positions between two cursor barriers, if not already an
157
+ inline position. Cursor barriers are the sides of the
158
+ document, any block leaves, or plots that are {@link
159
+ Plot.Spec.isolating isolating}, {@link
160
+ Plot.Spec.preserveWhitespace whitespace-preserving}, or
161
+ explicitly defined as a {@link Plot.Spec.cursorBarrier
162
+ cursor barrier}.
163
+ */
164
+ nextNormalCursor(cx: GardSelection.Context, forward?: boolean): GardSelection.Text | null;
165
+ /**
166
+ Move across one word starting from this selection's head.
167
+ */
168
+ skipWord(cx: GardSelection.Context, forward?: boolean): GardSelection.Text | null;
169
+ /**
170
+ Find a normal selection at the start of the document or the
171
+ given textblock.
172
+ */
173
+ static atStart(cx: GardSelection.Context, block?: Pos.Plot): GardSelection.Text;
174
+ /**
175
+ Find a normal selection at the end of the document or the given
176
+ textblock.
177
+ */
178
+ static atEnd(cx: GardSelection.Context, block?: Pos.Plot): GardSelection.Text;
179
+ }
180
+ declare namespace GardSelection {
181
+ /**
182
+ Create an extension that registers a custom selection type using
183
+ the given class. Such a selection is only valid in a state that
184
+ has the extension active. The JSON representation of a selection
185
+ will be tagged with the `tag` string, and created and read via
186
+ the functions passed here.
187
+ */
188
+ function define<T extends GardSelection, JSON extends object>(tag: string, cls: {
189
+ new (...args: any[]): T;
190
+ }, toJSON: (sel: T) => JSON, fromJSON: (doc: Plot.Doc, json: JSON) => T): any;
191
+ /**
192
+ Text selections hold a single arbitrary range in the document.
193
+ They represent a cursor when their anchor and head are the same
194
+ position.
195
+ */
196
+ class Text extends GardSelection {
197
+ private _headSide;
198
+ /**
199
+ A set of active marks that should be applied to content
200
+ inserted at this selection (replacing the contextual marks).
201
+ Used mostly for making the effect of toggling inline styles
202
+ stick until something is inserted. Marks that aren't valid for
203
+ the inserted content will be ignored.
204
+ */
205
+ readonly marks: Mark.Set | undefined;
206
+ private constructor();
207
+ get headSide(): 1 | -1;
208
+ get anchorSide(): 1 | -1;
209
+ /**
210
+ Create a text selection.
211
+ */
212
+ static create(spec: GardSelection.Text.Spec): Text;
213
+ map(change: ChangeSet, cx: GardSelection.Context, assoc?: -1 | 1): GardSelection;
214
+ eq(other: GardSelection): boolean;
215
+ }
216
+ namespace Text {
217
+ /**
218
+ Description of a text selection.
219
+ */
220
+ type Spec = {
221
+ /**
222
+ The anchor point of the selection. This is the side that doesn't
223
+ move when extending the selection (for example by moving the
224
+ cursor while holding shift).
225
+ */
226
+ anchor: number;
227
+ /**
228
+ The moving side of the selection. This will default to `anchor`
229
+ when not given.
230
+ */
231
+ head?: number;
232
+ /**
233
+ The side of the head position that the selection is associated
234
+ with, if any. `-1` points at the element before the position,
235
+ `1` at the element after. This is only meaningful for
236
+ empty/cursor selections. It will influence where the cursor is
237
+ drawn.
238
+ */
239
+ headSide?: -1 | 1;
240
+ /**
241
+ Associates a horizontal position with this selection for use
242
+ during vertical cursor motion.
243
+ */
244
+ goalColumn?: number;
245
+ /**
246
+ Marks associated with a cursor selection, which will determine
247
+ the marks of inline content inserted at that selection. This is
248
+ used for things like toggling emphasis on a cursor selection.
249
+ */
250
+ marks?: Mark.Set;
251
+ };
252
+ /**
253
+ The representation of a text selection when serialized to JSON.
254
+ */
255
+ type JSON = {
256
+ anchor: number;
257
+ head?: number;
258
+ side?: -1 | 1;
259
+ marks?: Record<string, any>;
260
+ };
261
+ }
262
+ /**
263
+ Node selections select a single node. They are created, for
264
+ example, when clicking on or moving into a {@link
265
+ Node.Spec.selectable selectable} leaf node. Use {@link
266
+ GardSelection.node} to create one.
267
+ */
268
+ class Node extends GardSelection {
269
+ /**
270
+ The selected node.
271
+ */
272
+ readonly node: wgNode;
273
+ private constructor();
274
+ map(change: ChangeSet, cx: GardSelection.Context, assoc?: -1 | 1): Text | Node;
275
+ eq(other: GardSelection): boolean;
276
+ }
277
+ namespace Node {
278
+ /**
279
+ The representation of a node selection when serialized to JSON.
280
+ */
281
+ type JSON = {
282
+ pos: number;
283
+ };
284
+ }
285
+ /**
286
+ A selection object where the selection positions have been
287
+ {@link Plot.Doc.resolve resolved}. For convenience, an editor
288
+ state's {@link GardState.sel `sel` property} provides an
289
+ instance of this, derived from the state's regular selection.
290
+ */
291
+ class Resolved {
292
+ /**
293
+ The original selection.
294
+ */
295
+ readonly selection: GardSelection;
296
+ /**
297
+ The selection anchor.
298
+ */
299
+ anchor: Pos;
300
+ /**
301
+ The head of the selection.
302
+ */
303
+ head: Pos;
304
+ private _ranges;
305
+ private constructor();
306
+ /**
307
+ The lower bound of the selection.
308
+ */
309
+ get from(): Pos;
310
+ /**
311
+ The upper bound of the selection.
312
+ */
313
+ get to(): Pos;
314
+ /**
315
+ The selection ranges.
316
+ */
317
+ get ranges(): readonly {
318
+ from: Pos;
319
+ to: Pos;
320
+ }[];
321
+ private resolveRanges;
322
+ /**
323
+ The resolved replacement range.
324
+ */
325
+ get replacementRange(): {
326
+ from: Pos;
327
+ to: Pos;
328
+ };
329
+ /**
330
+ The active marks for this selection. If this is a cursor
331
+ selection with explicitly stored {@link
332
+ GardSelection.Text.Spec.marks marks}, those are returned.
333
+ Otherwise, this computes the marks that should be applied to
334
+ content inserted in the selection's position, based on
335
+ spanning marks on the surrounding nodes.
336
+ */
337
+ get activeMarks(): Mark.Set;
338
+ }
339
+ /**
340
+ Many selection related functions need access to a configuration
341
+ (to determine text direction and visual motion behavior) and a
342
+ document. Note that {@link GardState} is a subtype of this.
343
+ */
344
+ type Context = {
345
+ doc: Plot.Doc;
346
+ config: GardState.Configuration;
347
+ };
348
+ }
349
+
350
+ /**
351
+ Changes to the editor state are grouped into transactions.
352
+ Typically, a user action creates a single transaction, which may
353
+ contain any number of document changes, may change the selection,
354
+ or have other {@link Transaction.Effect effects}. Create a
355
+ transaction by calling {@link GardState.update}, or immediately
356
+ dispatch one by calling {@link editor.Wordgard.dispatch
357
+ `Wordgard.dispatch`}.
358
+ */
359
+ declare class Transaction {
360
+ /**
361
+ The state from which this transaction starts.
362
+ */
363
+ readonly startState: GardState;
364
+ /**
365
+ The document changes made by this transaction.
366
+ */
367
+ readonly changes: ChangeSet;
368
+ /**
369
+ The selection set by this transaction, or undefined if it
370
+ doesn't explicitly set a selection.
371
+ */
372
+ readonly selection: GardSelection | undefined;
373
+ /**
374
+ The effects contained in this transaction.
375
+ */
376
+ readonly effects: readonly Transaction.Effect<any>[];
377
+ /**
378
+ Whether the selection should be scrolled into view after this
379
+ transaction is dispatched.
380
+ */
381
+ readonly scrollIntoView: boolean;
382
+ private constructor();
383
+ /**
384
+ The new selection produced by the transaction. If {@link
385
+ Transaction.selection `this.selection`} is undefined, this will
386
+ {@link GardSelection.map map} the start state's current
387
+ selection through the changes made by the transaction.
388
+ */
389
+ newSelection: GardSelection;
390
+ /**
391
+ The new document produced by the transaction. Contrary to
392
+ {@link Transaction.state `.state`}`.doc`, accessing this won't
393
+ force the entire new state to be computed right away, so it is
394
+ recommended that {@link Transaction.extender transaction
395
+ extenders} use this property when they need to look at the new
396
+ document.
397
+ */
398
+ newDoc: Plot.Doc;
399
+ /**
400
+ The new state created by the transaction. Lazily computed so
401
+ that the state is resolved the first time this property is
402
+ accessed.
403
+ */
404
+ get state(): GardState;
405
+ /**
406
+ Get the value of the given transaction {@link
407
+ Transaction.Annotation annotation} type, if any.
408
+ */
409
+ annotation<T>(type: Transaction.Annotation.Type<T>): T | undefined;
410
+ /**
411
+ Indicates whether the transaction changed the document.
412
+ */
413
+ get docChanged(): boolean;
414
+ /**
415
+ Indicates whether this transaction reconfigures the state
416
+ (through a {@link GardState.Compartment configuration
417
+ compartment}, {@link GardState.reconfigure reconfiguration}, or
418
+ {@link GardState.appendConfig appended configuration}).
419
+ */
420
+ get reconfigured(): boolean;
421
+ /**
422
+ Returns true if the transaction has a {@link
423
+ Transaction.userEvent user event} annotation that is equal to or
424
+ more specific than `event`. For example, if the transaction has
425
+ `"select.pointer"` as user event, `"select"` and
426
+ `"select.pointer"` will match it.
427
+ */
428
+ isUserEvent(event: string): boolean;
429
+ }
430
+ declare namespace Transaction {
431
+ /**
432
+ Describes a {@link Transaction transaction} when calling {@link
433
+ GardState.update `GardState.update`} or {@link Wordgard.dispatch
434
+ `Wordgard.dispatch`}.
435
+ */
436
+ interface Spec {
437
+ /**
438
+ The changes to the document made by this transaction.
439
+ */
440
+ changes?: ChangeSet.Spec;
441
+ /**
442
+ When set, this transaction explicitly updates the selection.
443
+ Offsets in this selection should refer to the document as it
444
+ is _after_ the transaction. If a selection can only be
445
+ computed after the new document is available, you can pass a
446
+ function here.
447
+ */
448
+ selection?: GardSelection | GardSelection.Text.Spec | ((cx: GardSelection.Context, changes: ChangeSet) => GardSelection | null);
449
+ /**
450
+ Attach {@link Transaction.Effect effects} to this transaction.
451
+ Again, when they contain positions and this same spec makes
452
+ changes, those positions should refer to positions in the
453
+ updated document.
454
+ */
455
+ effects?: Transaction.Effect<any> | readonly Transaction.Effect<any>[];
456
+ /**
457
+ Set {@link Transaction.Annotation annotations} for this
458
+ transaction.
459
+ */
460
+ annotations?: Transaction.Annotation<any> | readonly Transaction.Annotation<any>[];
461
+ /**
462
+ Shorthand for `annotations: `{@link Transaction.userEvent `Transaction.userEvent`}`.of(...)`.
463
+ */
464
+ userEvent?: string;
465
+ /**
466
+ When set to `true`, the transaction is marked as needing to
467
+ scroll the current selection into view.
468
+ */
469
+ scrollIntoView?: boolean;
470
+ /**
471
+ Only meaningful for specs that are combined with another
472
+ transaction spec (via {@link Transaction.merge or by being
473
+ returned from an {@link Transaction.extender extender}.
474
+ Normally, when specs are combined, the positions in `changes`
475
+ are taken to refer to the document positions in the initial
476
+ document. When a spec has `sequental` set to true, its
477
+ positions will be taken to refer to the document created by
478
+ the changes in the spec before it.
479
+ */
480
+ sequential?: boolean;
481
+ }
482
+ /**
483
+ Merge two transaction specs into a single one, combining the
484
+ effect of both.
485
+ */
486
+ function merge(state: GardState, a: Transaction.Spec, b: Transaction.Spec): Transaction.Spec;
487
+ /**
488
+ Facet used to register a hook that gets a chance to add to
489
+ transactions before they are applied. If such a function returns
490
+ a transaction spec, it will be combined with the original
491
+ transaction (in the same way as the arguments to
492
+ {@link GardState.update}).
493
+
494
+ When possible, it is recommended to avoid accessing {@link
495
+ Transaction.state} in an extender, since it will force creation
496
+ of a state that will then be discarded again, if the transaction
497
+ is actually extended.
498
+
499
+ This functionality should be used with care. Indiscriminately
500
+ modifying transaction is likely to break something or degrade
501
+ the user experience.
502
+
503
+ Extenders that may add document changes should generally not do
504
+ anything for {@link Transaction.remote remote} transactions,
505
+ because doing so risks causing endlessly cascading changes or
506
+ other confusion. It is possible to define extenders that are
507
+ safe when activated on multiple peer (for example, duplicate
508
+ deletions of the same content tend to converge), but it requires
509
+ a lot of care.
510
+ */
511
+ let extender: GardState.Facet<(tr: Transaction) => Transaction.Spec | null>;
512
+ /**
513
+ A transaction appender can create more transactions in response
514
+ to a transaction. {@link Transaction.append}, which is
515
+ called by the {@link Wordgard editor} when dispatching a
516
+ transaction, will call appenders on sets of transactions,
517
+ allowing them to add another transaction. When another appender
518
+ adds a transaction, extenders that already ran will be called
519
+ again, but only with the transactions that were added after they
520
+ ran.
521
+ */
522
+ let appender: GardState.Facet<(trs: readonly Transaction[], state: GardState) => Transaction.Spec | null>;
523
+ /**
524
+ Apply {@link Transaction.appender transaction appenders}, return
525
+ an array of the original transaction plus any that were appended.
526
+ */
527
+ function append(tr: Transaction): readonly Transaction[];
528
+ /**
529
+ Annotations are tagged values that are used to add metadata to
530
+ transactions in an extensible way. They should be used to model
531
+ things that effect the entire transaction (such as its {@link
532
+ Transaction.time time stamp} or information about its {@link
533
+ Transaction.userEvent origin}). For effects that happen
534
+ _alongside_ the other changes made by the transaction, {@link
535
+ Transaction.Effect effects} are more appropriate.
536
+ */
537
+ class Annotation<T> {
538
+ /**
539
+ The annotation type.
540
+ */
541
+ readonly type: Transaction.Annotation.Type<T>;
542
+ /**
543
+ The value of this annotation.
544
+ */
545
+ readonly value: T;
546
+ /**
547
+ Define a new type of annotation.
548
+ */
549
+ static define<T>(): Annotation.Type<T>;
550
+ private _isAnnotation;
551
+ }
552
+ namespace Annotation {
553
+ /**
554
+ Marker that identifies a type of {@link Transaction.Annotation
555
+ annotation}.
556
+ */
557
+ class Type<T> {
558
+ /**
559
+ Create an instance of this annotation.
560
+ */
561
+ of(value: T): Transaction.Annotation<T>;
562
+ }
563
+ }
564
+ const foo: number;
565
+ /**
566
+ Annotation used to store transaction timestamps. Automatically
567
+ added to every transaction, holding `Date.now()`.
568
+ */
569
+ const time: Annotation.Type<number>;
570
+ /**
571
+ Annotation used to associate a transaction with a user interface
572
+ event. Holds a string identifying the event, using a
573
+ dot-separated format to support attaching more specific
574
+ information. The events used by the core libraries are:
575
+
576
+ - `"input"` when content is entered
577
+ - `"input.type"` for typed input
578
+ - `"input.type.compose"` for composition
579
+ - `"input.paste"` for pasted input
580
+ - `"input.drop"` when adding content with drag-and-drop
581
+ - `"delete"` when the user deletes content
582
+ - `"delete.selection"` when deleting the selection
583
+ - `"delete.forward"` when deleting forward from the selection
584
+ - `"delete.backward"` when deleting backward from the selection
585
+ - `"delete.cut"` when cutting to the clipboard
586
+ - `"move"` when content is moved
587
+ - `"move.drop"` when content is moved within the editor
588
+ through drag-and-drop
589
+ - `"select"` when explicitly changing the selection
590
+ - `"select.pointer"` when selecting with a mouse or other pointing
591
+ device
592
+ - `"select.all"` when selecting the entire document
593
+ - `"undo"` and `"redo"` for history actions
594
+ - `"insert"` for actions that insert nodes
595
+ - `"mark"` for actions that manipulate marks
596
+ - `"mark.add"` when a command adds a mark
597
+ - `"mark.remove"` when a command removes one
598
+ - `"split"`, `"wrap"`, `"settype"`, `"wrap"`, `"unwrap"` for
599
+ block manipulation actions
600
+
601
+ Use {@link Transaction.isUserEvent `isUserEvent`} to check
602
+ whether the annotation matches a given event.
603
+ */
604
+ const userEvent: Annotation.Type<string>;
605
+ /**
606
+ Annotation indicating whether a transaction should be added to
607
+ the undo history or not.
608
+ */
609
+ const addToHistory: Annotation.Type<boolean>;
610
+ /**
611
+ Annotation indicating (when present and true) that a transaction
612
+ represents a change made by some other actor, not the user. This
613
+ is used, for example, to tag other people's changes in
614
+ collaborative editing.
615
+ */
616
+ const remote: Annotation.Type<boolean>;
617
+ /**
618
+ A flag set on transactions created by a {@link
619
+ Transaction.appender transaction appender}.
620
+ */
621
+ const appended: Annotation.Type<boolean>;
622
+ /**
623
+ Transaction effects can be used to represent additional effects
624
+ associated with a {@link Transaction.effects transaction}. They
625
+ are often useful to model changes to custom {@link
626
+ GardState.Field state fields}, when those changes aren't
627
+ implicit in document or selection changes.
628
+ */
629
+ class Effect<Value> {
630
+ /**
631
+ The value of this effect.
632
+ */
633
+ readonly value: Value;
634
+ /**
635
+ Map this effect through a position mapping. Will return
636
+ `undefined` when the changes deleted the effect.
637
+ */
638
+ map(mapping: ChangeSet): Transaction.Effect<Value> | undefined;
639
+ /**
640
+ Tells you whether this effect object is of a given
641
+ {@link Transaction.Effect.Type type}.
642
+ */
643
+ is<T>(type: Transaction.Effect.Type<T>): this is Transaction.Effect<T>;
644
+ /**
645
+ Define a new effect type. The type parameter indicates the
646
+ type of values that his effect holds. It should be a type that
647
+ doesn't include `undefined`, since that is used in {@link
648
+ Transaction.Effect.map mapping} to indicate that an effect is
649
+ removed.
650
+ */
651
+ static define<Value = null>(spec?: Transaction.Effect.Spec<Value>): Transaction.Effect.Type<Value>;
652
+ }
653
+ namespace Effect {
654
+ /**
655
+ Map an array of effects through a change set.
656
+ */
657
+ function mapEffects(effects: readonly Transaction.Effect<any>[], mapping: ChangeSet): readonly Effect<any>[];
658
+ /**
659
+ A type of state effect. Defined with {@link
660
+ Transaction.Effect.define}.
661
+ */
662
+ class Type<Value> {
663
+ /**
664
+ @internal
665
+ */
666
+ readonly map: (value: any, mapping: ChangeSet) => any | undefined;
667
+ /**
668
+ Create an {@link Transaction.Effect effect} instance of this
669
+ type.
670
+ */
671
+ of(value: Value): Transaction.Effect<Value>;
672
+ }
673
+ /**
674
+ Options passed when defining an effect.
675
+ */
676
+ interface Spec<Value> {
677
+ /**
678
+ Provides a way to map an effect like this through a position
679
+ mapping. When not given, the effects will simply not be mapped.
680
+ When the function returns `undefined`, that means the mapping
681
+ deletes the effect.
682
+ */
683
+ map?: (value: Value, mapping: ChangeSet) => Value | undefined;
684
+ }
685
+ }
686
+ }
687
+
688
+ /**
689
+ Represents a contiguous range of text that has a single direction
690
+ (as in left-to-right or right-to-left).
691
+ */
692
+ declare class BidiSpan {
693
+ /**
694
+ The start of the span (relative to the start of the line).
695
+ */
696
+ readonly from: number;
697
+ /**
698
+ The end of the span.
699
+ */
700
+ readonly to: number;
701
+ /**
702
+ The ["bidi
703
+ level"](https://unicode.org/reports/tr9/#Basic_Display_Algorithm)
704
+ of the span. 0 means left-to-right, 1 means right-to-left, 2
705
+ means left-to-right embedded inside right-to-left, and so on,
706
+ with even numbers being left-to-right, odd numbers
707
+ right-to-left..
708
+ */
709
+ readonly level: number;
710
+ /**
711
+ The direction of this span.
712
+ */
713
+ get ltr(): boolean;
714
+ /**
715
+ Query whether the given character has a strong direction.
716
+ Returns null when not, true when left-to-right, and false when
717
+ right-to-left.
718
+ */
719
+ static strongDir(ch: number): boolean | null;
720
+ }
721
+
722
+ /**
723
+ A textblock map contains the text in a textblock as a string, and
724
+ can help convert between string offsets and document positions.
725
+
726
+ Note that this is not the way to convert a piece of document to a
727
+ string. Use {@link doc.Plot.textContent} for that.
728
+ */
729
+ declare class TextblockMap {
730
+ /**
731
+ The start position of the textblock content.
732
+ */
733
+ readonly start: number;
734
+ /**
735
+ The textblock's document node.
736
+ */
737
+ readonly node: Plot;
738
+ /**
739
+ Whether the base direction of this block is left-to-right.
740
+ */
741
+ readonly ltr: boolean;
742
+ /**
743
+ The text in the block. Non-text leaf nodes and nodes with
744
+ block content will be replaced by a single `0xfffc` character
745
+ in this string.
746
+ */
747
+ readonly text: string;
748
+ private _order;
749
+ private config;
750
+ private sections;
751
+ private constructor();
752
+ /**
753
+ The text order of the text in this block. Will generally be a
754
+ single span, but if the block mixes left-to-right and
755
+ right-to-left text, this describes the individual sections,
756
+ ordered from the block's start to its end.
757
+ */
758
+ get order(): readonly BidiSpan[];
759
+ /**
760
+ Get the map for the given textblock. Will use a cache to reuse
761
+ results for unchanged blocks.
762
+ */
763
+ static get(cx: GardSelection.Context, start: number, node: Plot): TextblockMap;
764
+ private static create;
765
+ /**
766
+ Get the string index for a document position. Positions outside
767
+ of the textblock will be clipped to its start or end.
768
+ */
769
+ toIndex(pos: number): number;
770
+ /**
771
+ Get the document position for a given string index.
772
+ */
773
+ fromIndex(index: number): number;
774
+ /**
775
+ Get the position at the start or end of the textblock. Note that
776
+ in bidirectional text this may not be the actual start or end
777
+ position of the node.
778
+ */
779
+ visualSide(start: boolean): {
780
+ pos: number;
781
+ side: -1 | 1;
782
+ };
783
+ }
784
+
785
+ type DocSource = Plot.Doc | HTMLElement | DocumentFragment | string | Node.JSON | ((schema: Schema) => Plot.Doc);
786
+ /**
787
+ The editor state tracks things like the current document, the
788
+ selection, the configuration of the editor, and any extra state
789
+ defined by extensions.
790
+
791
+ The state is a persistent (immutable) data structure. To update a
792
+ state, you {@link GardState.update create} a {@link Transaction
793
+ transaction}, which produces a _new_ state instance, without
794
+ modifying the original object.
795
+ */
796
+ declare class GardState {
797
+ /**
798
+ The configuration for this state.
799
+ */
800
+ readonly config: GardState.Configuration;
801
+ private _doc;
802
+ private _selection;
803
+ private resolvedSel;
804
+ private trackAccess;
805
+ /**
806
+ Create a new state. You'll usually only need this when
807
+ initializing an editor or loading a new document—updated states
808
+ are created by applying transactions.
809
+
810
+ The schema of the state can be provided either via the {@link
811
+ GardState.schemaElement configuration} or by passing in an
812
+ initialized document (which will have its own schema). If the
813
+ configuration contains a document plot type, the schema from the
814
+ configuration will be used, even if a document was provided.
815
+ */
816
+ static create(spec: GardState.Spec): GardState;
817
+ private constructor();
818
+ /**
819
+ The current document.
820
+ */
821
+ get doc(): Plot.Doc;
822
+ /**
823
+ The document's schema.
824
+ */
825
+ get schema(): Schema;
826
+ /**
827
+ The current selection.
828
+ */
829
+ get selection(): GardSelection;
830
+ /**
831
+ A resolved form of the state's selection. Instead of raw
832
+ positions, this object holds {@link Pos document position}
833
+ objects for `head`, `anchor`, `from`, and `to`.
834
+ */
835
+ get sel(): GardSelection.Resolved;
836
+ /**
837
+ Retrieve the value of a {@link GardState.Field state field}.
838
+ Throws an error when the state doesn't have that field, unless
839
+ you pass `false` as second parameter.
840
+ */
841
+ field<T>(field: GardState.Field<T>): T;
842
+ field<T>(field: GardState.Field<T>, require: false): T | undefined;
843
+ /**
844
+ Get the value of a state {@link GardState.Facet facet}.
845
+ */
846
+ facet<Output>(facet: GardState.Facet.Reader<Output>): Output;
847
+ /**
848
+ Create a {@link Transaction transaction} that updates this
849
+ state.
850
+ */
851
+ update(spec: Transaction.Spec): Transaction;
852
+ /**
853
+ Compute the textblock map for the given plot (which should be a
854
+ textblock).
855
+ */
856
+ textblockMap(node: Pos.Plot): TextblockMap;
857
+ /**
858
+ Convert this state to a JSON-serializable object. When custom
859
+ fields should be serialized, you can pass them in as an object
860
+ mapping property names (in the resulting object, which should
861
+ not use `doc` or `selection`) to fields.
862
+ */
863
+ toJSON(fields?: {
864
+ [prop: string]: GardState.Field<any>;
865
+ }): any;
866
+ /**
867
+ Deserialize a state from its JSON representation. When custom
868
+ fields should be deserialized, pass the same object you passed
869
+ to {@link GardState.toJSON `toJSON`} when serializing as third
870
+ argument.
871
+ */
872
+ static fromJSON(json: any, extensions: GardState.Extension, fields?: {
873
+ [prop: string]: GardState.Field<any>;
874
+ }): GardState;
875
+ /**
876
+ Returns true when the editor is {@link GardState.readOnly} to be
877
+ read-only.
878
+ */
879
+ get readOnly(): boolean;
880
+ /**
881
+ Get the global text direction (true when left-to-right, false
882
+ when right-to-left) for the document. Note that the direction of
883
+ individual blocks can be overridden with {@link
884
+ GardState.textblockLTR}.
885
+ */
886
+ get textLTR(): boolean;
887
+ /**
888
+ Return the text direction in a given textblock (by tag).
889
+ */
890
+ textblockLTR(plot: Plot): boolean;
891
+ /**
892
+ Tells you whether a node type is an atom (a leaf or a plot with
893
+ an atomic shape).
894
+ */
895
+ isAtom(type: Node.Type): boolean;
896
+ /**
897
+ Return the extent of the word around the given position, as a
898
+ text selection.
899
+ */
900
+ wordAt(pos: number, bias?: -1 | 1): GardSelection.Text;
901
+ /**
902
+ This effect can be used to reconfigure the root extensions of
903
+ the editor. Doing this will discard any extensions {@link
904
+ GardState.appendConfig appended}, but does not reset the
905
+ content of {@link GardState.Compartment.reconfigure
906
+ reconfigured} compartments.
907
+ */
908
+ static reconfigure: Transaction.Effect.Type<GardState.Extension>;
909
+ /**
910
+ Append extensions to the top-level configuration of the editor.
911
+ */
912
+ static appendConfig: Transaction.Effect.Type<GardState.Extension>;
913
+ }
914
+ declare namespace GardState {
915
+ /**
916
+ Options passed when {@link GardState.create creating} an editor
917
+ state.
918
+ */
919
+ interface Spec {
920
+ /**
921
+ The initial document. When passing in a {@link Plot.Doc
922
+ document node} here, it is not necessary to include a schema
923
+ in your configuration (though it is allowed, and the document
924
+ content will be moved into that schema if it differs from the
925
+ one on the given document).
926
+
927
+ All other forms require a schema from the configuration. A
928
+ string or DOM structure will be parsed as HTML. Passing a
929
+ string only works in the browser, where the library can use
930
+ the browser's HTML parser. In other environments, you'll need
931
+ to do the parsing yourself (for example with
932
+ [jsdom](https://jsdom.org/)). A JSON node deserialized, and a
933
+ function called to produce the document.
934
+ */
935
+ doc?: DocSource;
936
+ /**
937
+ The starting selection. Defaults to a cursor at the start of the
938
+ document.
939
+ */
940
+ selection?: GardSelection | GardSelection.Text.Spec | ((cx: GardSelection.Context) => GardSelection);
941
+ /**
942
+ The configuration for this state, either as a resolved {@link
943
+ GardState.Configuration} or as a set of extensions.
944
+ */
945
+ config?: GardState.Extension | GardState.Configuration;
946
+ }
947
+ /**
948
+ Fields can store additional information in an editor state, and
949
+ keep it in sync with the rest of the state. The type parameter
950
+ indicates the type of value stored in the field.
951
+ */
952
+ class Field<Value> {
953
+ private createF;
954
+ private updateF;
955
+ private compareF;
956
+ private constructor();
957
+ /**
958
+ Define a state field.
959
+ */
960
+ static define<Value>(config: GardState.Field.Spec<Value>): GardState.Field<Value>;
961
+ private create;
962
+ /**
963
+ State field instances can be used as {@link
964
+ GardState.Extension `Extension`} values to enable the field in
965
+ a given state.
966
+ */
967
+ get extension(): GardState.Extension;
968
+ /**
969
+ Returns an extension that enables this field and overrides the
970
+ way it is initialized. Can be useful when you need to provide a
971
+ non-default starting value for the field.
972
+ */
973
+ init(create: (state: GardState) => Value): GardState.Extension;
974
+ }
975
+ namespace Field {
976
+ /**
977
+ The options passed when defining a state field.
978
+ */
979
+ type Spec<Value> = {
980
+ /**
981
+ Creates the initial value for the field when a state is created.
982
+ */
983
+ create: (state: GardState) => Value;
984
+ /**
985
+ Compute a new value from the field's previous value and a
986
+ {@link Transaction transaction}. Should not mutate the old
987
+ value (since that will change the existing state), but
988
+ create a fresh one or return the old value unchanged.
989
+ */
990
+ update: (value: Value, transaction: Transaction) => Value;
991
+ /**
992
+ Compare two values of the field, returning `true` when they are
993
+ the same. This is used to avoid recomputing facets that depend
994
+ on the field when its value did not change. Defaults to using
995
+ `===`.
996
+ */
997
+ compare?: (a: Value, b: Value) => boolean;
998
+ /**
999
+ Provide extensions based on this field. The given function
1000
+ will be called once with the initialized field. It is
1001
+ typically used with a facet's {@link GardState.Facet.from}
1002
+ method to create facet inputs from this field, but can also
1003
+ return other extensions that should be enabled when the
1004
+ field is present in a configuration.
1005
+ */
1006
+ provide?: (field: GardState.Field<Value>) => GardState.Extension;
1007
+ /**
1008
+ A function used to serialize this field's content to JSON. Only
1009
+ necessary when this field is included in the argument to
1010
+ {@link GardState.toJSON}.
1011
+ */
1012
+ toJSON?: (value: Value, state: GardState) => any;
1013
+ /**
1014
+ A function that deserializes the JSON representation of this
1015
+ field's content.
1016
+ */
1017
+ fromJSON?: (json: any, state: GardState) => Value;
1018
+ };
1019
+ }
1020
+ /**
1021
+ A facet is a labeled value that is associated with an editor
1022
+ state. It takes inputs from any number of extensions, and combines
1023
+ those into a single output value.
1024
+
1025
+ Examples of uses of facets are the {@link GardState.readOnly
1026
+ read-only configuration}, {@link
1027
+ editor.Wordgard.editorAttributes editor attributes}, and {@link
1028
+ editor.Wordgard.updateListener update listeners}.
1029
+
1030
+ Note that `Facet` instances can be used anywhere where {@link
1031
+ GardState.Facet.Reader} is expected.
1032
+
1033
+ Facets have an input type (the type of values provided for it),
1034
+ and an output type (the type you get when you read the facet)
1035
+ that defaults to an array of input values, but can be anything
1036
+ if a {@link GardState.Facet.Spec.combine}
1037
+ option is provided.
1038
+ */
1039
+ class Facet<Input, Output = readonly Input[]> implements GardState.Facet.Reader<Output> {
1040
+ /**
1041
+ True when this is a static facet.
1042
+ */
1043
+ readonly isStatic: boolean;
1044
+ /**
1045
+ The output of the facet when it has no inputs.
1046
+ */
1047
+ readonly default: Output;
1048
+ private constructor();
1049
+ /**
1050
+ A facet reader for this facet, which can be used to {@link
1051
+ GardState.facet read} it but not to define values for it.
1052
+ */
1053
+ get reader(): GardState.Facet.Reader<Output>;
1054
+ /**
1055
+ Defines a facet with the given input an output types.
1056
+ */
1057
+ static define<Input, Output = readonly Input[]>(config?: GardState.Facet.Spec<Input, Output>): Facet<Input, Output>;
1058
+ /**
1059
+ Returns an extension that provides the given value to this
1060
+ facet.
1061
+ */
1062
+ of(value: Input): GardState.Extension;
1063
+ /**
1064
+ Create an extension that computes a value for the facet from a
1065
+ state. The given function should only depend on the state, not
1066
+ any external non-constant inputs. Its return value will be kept
1067
+ on state update, unless any of the fields or facets (including
1068
+ document and selection) that it read are changed by the update,
1069
+ in which case it is called again.
1070
+
1071
+ In cases where your value depends only on a single field, you
1072
+ can use the {@link GardState.Facet.from `from`} method
1073
+ instead.
1074
+ */
1075
+ compute(get: (state: GardState) => Input): GardState.Extension;
1076
+ /**
1077
+ Create an extension that computes zero or more values for this
1078
+ facet from a state.
1079
+ */
1080
+ computeN(get: (state: GardState) => readonly Input[]): GardState.Extension;
1081
+ /**
1082
+ Shorthand method for registering a facet source with a state
1083
+ field as input. If the field's type corresponds to this facet's
1084
+ input type, the getter function can be omitted. If given, it
1085
+ will be used to produce the input from the field value.
1086
+ */
1087
+ from<T extends Input>(field: GardState.Field<T>): GardState.Extension;
1088
+ from<T>(field: GardState.Field<T>, get: (value: T) => Input): GardState.Extension;
1089
+ tag: Output;
1090
+ }
1091
+ namespace Facet {
1092
+ /**
1093
+ Options passed when {@link GardState.Facet.define defining} a
1094
+ facet.
1095
+ */
1096
+ type Spec<Input, Output> = {
1097
+ /**
1098
+ How to combine the input values into a single output value. When
1099
+ not given, the array of input values becomes the output. This
1100
+ function will immediately be called on creating the facet, with
1101
+ an empty array, to compute the facet's default value when no
1102
+ inputs are present.
1103
+ */
1104
+ combine?: (value: readonly Input[]) => Output;
1105
+ /**
1106
+ How to compare output values to determine whether the value
1107
+ of the facet changed. When a new value for the facet is
1108
+ computed that that compares as equal to the old value, the
1109
+ old value is kept. So in most circumstances, facet values
1110
+ can be cheaply compared by identity to check for changes.
1111
+ Defaults to comparing by `===` or, if no `combine` function
1112
+ was given, comparing each element of the array with `===`.
1113
+ */
1114
+ compare?: (a: Output, b: Output) => boolean;
1115
+ /**
1116
+ How to compare input values to avoid recomputing the output
1117
+ value when no inputs changed. Defaults to comparing with `===`.
1118
+ */
1119
+ compareInput?: (a: Input, b: Input) => boolean;
1120
+ /**
1121
+ Forbids dynamic inputs to this facet. Allows the facet to be
1122
+ {@link GardState.Configuration.staticFacet read} from a
1123
+ configuration.
1124
+ */
1125
+ static?: boolean;
1126
+ /**
1127
+ If given, these extensions (or the result of calling the
1128
+ given function with the facet) will be added to any state
1129
+ where this facet is provided. (Note that, while a facet's
1130
+ {@link GardState.Facet.default default} value can be read
1131
+ from a state even if the facet wasn't present in the state
1132
+ at all, the extensions won't be added in that situation.)
1133
+ */
1134
+ enables?: GardState.Extension | ((self: GardState.Facet<Input, Output>) => GardState.Extension);
1135
+ };
1136
+ /**
1137
+ A facet reader can be used to fetch the value of a facet,
1138
+ through {@link GardState.facet} or as a dependency in {@link
1139
+ GardState.Facet.compute `Facet.compute`}, but not to define
1140
+ new values for the facet.
1141
+ */
1142
+ type Reader<Output> = {
1143
+ /**
1144
+ @hidden
1145
+ */
1146
+ tag: Output;
1147
+ };
1148
+ /**
1149
+ Utility function for combining multiple configuration objects.
1150
+ `defaults` should hold default values for all optional fields
1151
+ in `Config`.
1152
+
1153
+ The function will, by default, raise an error when a field
1154
+ gets two values that aren't `===`-equal, but you can provide
1155
+ combine functions per field to do something else.
1156
+ */
1157
+ function combineConfig<Config extends object>(configs: readonly Partial<Config>[], defaults: Partial<Config>, // Should hold only the optional properties of Config, but I haven't managed to express that
1158
+ combine?: {
1159
+ [P in keyof Config]?: (first: Config[P], second: Config[P]) => Config[P];
1160
+ }): Config;
1161
+ }
1162
+ /**
1163
+ A state configuration stores a set of extensions, structured so
1164
+ that state updates can be performed efficiently.
1165
+ */
1166
+ class Configuration {
1167
+ /**
1168
+ The set of extensions that this configuration is based on.
1169
+ */
1170
+ readonly base: GardState.Extension;
1171
+ private constructor();
1172
+ /**
1173
+ Read the value of a static facet.
1174
+ */
1175
+ staticFacet<Output>(facet: GardState.Facet<any, Output>): Output;
1176
+ /**
1177
+ Create a configuration from the given set of extensions.
1178
+ */
1179
+ static create(extensions: GardState.Extension): Configuration;
1180
+ /**
1181
+ Get the schema defined by this configuration. Will be null if
1182
+ the schema does not contain a document plot type.
1183
+ */
1184
+ get schema(): Schema | null;
1185
+ }
1186
+ /**
1187
+ Extension values can be {@link GardState.Spec.config provided}
1188
+ when creating a state to attach various kinds of configuration
1189
+ and behavior information. They can either be built-in
1190
+ extension-providing objects, such as {@link GardState.Field
1191
+ state fields} or {@link GardState.Facet.of facet providers}, or
1192
+ objects with an extension in its `extension` property.
1193
+ Extensions can be nested in arrays arbitrarily deep—they will be
1194
+ flattened when resolved into a configuration.
1195
+ */
1196
+ type Extension = {
1197
+ extension: GardState.Extension;
1198
+ } | readonly GardState.Extension[];
1199
+ /**
1200
+ By default extensions are registered in the order they are found
1201
+ in the flattened form of the configuration's extension tree.
1202
+ Individual extension values can be assigned a precedence to
1203
+ override this. Extensions that do not have a precedence set get
1204
+ the precedence of the nearest parent with a precedence, or
1205
+ {@link GardState.prec.default `default`} if there is no such
1206
+ parent. The final ordering of extensions is determined by first
1207
+ sorting by precedence and then by order within each precedence.
1208
+ */
1209
+ const prec: {
1210
+ /**
1211
+ The highest precedence level, for extensions that should end up
1212
+ near the start of the precedence ordering.
1213
+ */
1214
+ highest: (ext: GardState.Extension) => GardState.Extension;
1215
+ /**
1216
+ A higher-than-default precedence, for extensions that should
1217
+ come before those with default precedence.
1218
+ */
1219
+ high: (ext: GardState.Extension) => GardState.Extension;
1220
+ /**
1221
+ The default precedence, which is also used for extensions
1222
+ without an explicit precedence.
1223
+ */
1224
+ default: (ext: GardState.Extension) => GardState.Extension;
1225
+ /**
1226
+ A lower-than-default precedence.
1227
+ */
1228
+ low: (ext: GardState.Extension) => GardState.Extension;
1229
+ /**
1230
+ The lowest precedence level. Meant for things that should end up
1231
+ near the end of the extension order.
1232
+ */
1233
+ lowest: (ext: GardState.Extension) => GardState.Extension;
1234
+ };
1235
+ /**
1236
+ Extension compartments can be used to make a configuration
1237
+ dynamic. By {@link GardState.Compartment.of wrapping} part of your
1238
+ configuration in a compartment, you can later {@link
1239
+ GardState.Compartment.reconfigure replace} that part through a
1240
+ transaction.
1241
+ */
1242
+ class Compartment {
1243
+ private constructor();
1244
+ /**
1245
+ Define a new compartment.
1246
+ */
1247
+ static define(): Compartment;
1248
+ /**
1249
+ Create an instance of this compartment to add to your {@link
1250
+ GardState.Spec.config state configuration}.
1251
+ */
1252
+ of(ext: GardState.Extension): GardState.Extension;
1253
+ /**
1254
+ Create an {@link Transaction.Spec.effects effect} that
1255
+ reconfigures this compartment.
1256
+ */
1257
+ reconfigure(content: GardState.Extension): Transaction.Effect<unknown>;
1258
+ /**
1259
+ Get the current content of the compartment in the state, or
1260
+ `undefined` if it isn't present.
1261
+ */
1262
+ get(state: GardState): GardState.Extension | undefined;
1263
+ }
1264
+ /**
1265
+ Facet used to register {@link Schema schema} elements. *If*
1266
+ a configuration contains a {@link Plot.defineDoc document}
1267
+ type, the editor's document schema will be derived from the
1268
+ content of this facet. (Otherwise, the state will try to use the
1269
+ schema provided via the {@link GardState.Spec.doc} option, or
1270
+ raise an error is none is provided.)
1271
+ */
1272
+ const schemaElement: Facet<Schema.Element | readonly Schema.Element[], readonly Schema.Element[]>;
1273
+ /**
1274
+ This facet controls the value of the {@link GardState.readOnly
1275
+ `readOnly` getter}, which is consulted by commands and
1276
+ extensions that implement editing functionality to determine
1277
+ whether they should apply. It defaults to false, but when its
1278
+ highest-precedence value is `true`, the state is considered
1279
+ read-only, and such functions won't change the document.
1280
+
1281
+ Not to be confused with {@link editor.Wordgard.editable}, which
1282
+ controls whether the editor's DOM is set to be editable (and
1283
+ thus focusable).
1284
+ */
1285
+ const readOnly: Facet<boolean, boolean>;
1286
+ /**
1287
+ Facet that indicates the document's default text direction. Note
1288
+ that this will not affect the editor CSS, and when the state's
1289
+ value disagrees with the direction set in the editor, the editor
1290
+ component will automatically inject an instance of this with a
1291
+ high precedence to align the state to the DOM. Still, if you
1292
+ know the direction in advance, it can be useful to set this, so
1293
+ that the direction is already accurate during initialization.
1294
+ Defaults to true.
1295
+ */
1296
+ const textLTR: Facet<boolean, boolean>;
1297
+ /**
1298
+ Configure the text direction per textblock. All values given for
1299
+ this will be consulted in order of precedence, until one returns
1300
+ a non-null value. If none set a direction, the editor's {@link
1301
+ GardState.textLTR base direction} is used.
1302
+
1303
+ Schema elements like {@link schema.direction} register an
1304
+ instance of this to make the editor aware of the meaning of the
1305
+ {@link types.Direction} mark.
1306
+ */
1307
+ const textblockLTR: Facet<(plot: Plot) => boolean | null, readonly ((plot: Plot) => boolean | null)[]>;
1308
+ /**
1309
+ Configure whether to use visual or logical cursor motion in
1310
+ bidirectional text. The default is visual, where pressing
1311
+ left/right arrow keys moves the cursor in the direction that
1312
+ corresponds to the arrow on key. When disabled, the motion uses
1313
+ the string index order instead.
1314
+ */
1315
+ const visualCursorMotion: Facet<boolean, boolean>;
1316
+ /**
1317
+ @hidden FIXME expose this?
1318
+ */
1319
+ const isAtom: Facet<[Plot.Type<unknown>, boolean], Map<Plot.Type<unknown>, boolean>>;
1320
+ }
1321
+
1322
+ /**
1323
+ The class representing a correction. Counts as an editor
1324
+ extension.
1325
+
1326
+ Corrections install themselves as {@link Transaction.extender
1327
+ transaction extenders} that check modified nodes and, if
1328
+ necessary, apply fixes to enforce constraints. In normal
1329
+ operation, this means that they guarantee the constraints
1330
+ implemented in the transaction are enforced.
1331
+
1332
+ They do not activate for {@link Transaction.remote remote}
1333
+ transactions, because acting on those can cause collaborative
1334
+ editing setups to malfunction (for example, causing all peers to
1335
+ repeatedly try to correct the same issue, causing an endless loop
1336
+ of updates or other chaos). The collab module has special
1337
+ provisions for integrating corrections in the step transformation
1338
+ in a safe way, but that requires you to explicitly tell it to use
1339
+ them, both on the {@link collab.Config.corrections client} and
1340
+ the {@link collab.transformUpdate server}.
1341
+ */
1342
+ declare class Correction {
1343
+ /**
1344
+ To take effect, corrections must be included in an editor
1345
+ configuration.
1346
+ */
1347
+ extension: GardState.Extension;
1348
+ private constructor();
1349
+ /**
1350
+ This method can be used to run a correction agains all matching
1351
+ nodes in an existing document. If the correction makes any
1352
+ changes, the method returns a transaction with those changes.
1353
+ */
1354
+ scan(state: GardState): Transaction | null;
1355
+ /**
1356
+ Create a correction that runs whenever the child list of a node
1357
+ that matches the given query changes, or such a node is inserted
1358
+ into the document.
1359
+ */
1360
+ static onChildList(query: Node.Query, correct: (node: Pos.Plot) => ChangeSet.Spec | null): Correction;
1361
+ /**
1362
+ Create a correction that runs whenever any content inside a node
1363
+ that matches the given query changes, or such a node is inserted
1364
+ into the document.
1365
+ */
1366
+ static onContent(query: Node.Query, correct: (node: Pos.Plot) => ChangeSet.Spec | null): Correction;
1367
+ /**
1368
+ Define a correction that runs whenever the set of marks on a
1369
+ matching tag changes.
1370
+ */
1371
+ static onMarks(query: Node.Query, correct: (node: Pos.Node) => ChangeSet.Spec | null): Correction;
1372
+ /**
1373
+ Check the ranges touched by the given change set against the
1374
+ given list of corrections. Return a change set if any changes
1375
+ need to be made. (This isn't how you normally use corrections,
1376
+ but can be useful in a situation where you aren't working with
1377
+ an editor state transaction.)
1378
+ */
1379
+ static check(changes: ChangeSet, doc: Plot.Doc, corrections: readonly Correction[]): ChangeSet | null;
1380
+ }
1381
+
1382
+ export { BidiSpan, Correction, GardSelection, GardState, TextblockMap, Transaction };