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