@codemirror/state 6.2.1 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1686 @@
1
+ /**
2
+ A text iterator iterates over a sequence of strings. When
3
+ iterating over a [`Text`](https://codemirror.net/6/docs/ref/#state.Text) document, result values will
4
+ either be lines or line breaks.
5
+ */
6
+ interface TextIterator extends Iterator<string>, Iterable<string> {
7
+ /**
8
+ Retrieve the next string. Optionally skip a given number of
9
+ positions after the current position. Always returns the object
10
+ itself.
11
+ */
12
+ next(skip?: number): this;
13
+ /**
14
+ The current string. Will be the empty string when the cursor is
15
+ at its end or `next` hasn't been called on it yet.
16
+ */
17
+ value: string;
18
+ /**
19
+ Whether the end of the iteration has been reached. You should
20
+ probably check this right after calling `next`.
21
+ */
22
+ done: boolean;
23
+ /**
24
+ Whether the current string represents a line break.
25
+ */
26
+ lineBreak: boolean;
27
+ }
28
+ /**
29
+ The data structure for documents. @nonabstract
30
+ */
31
+ declare abstract class Text implements Iterable<string> {
32
+ /**
33
+ The length of the string.
34
+ */
35
+ abstract readonly length: number;
36
+ /**
37
+ The number of lines in the string (always >= 1).
38
+ */
39
+ abstract readonly lines: number;
40
+ /**
41
+ Get the line description around the given position.
42
+ */
43
+ lineAt(pos: number): Line;
44
+ /**
45
+ Get the description for the given (1-based) line number.
46
+ */
47
+ line(n: number): Line;
48
+ /**
49
+ Replace a range of the text with the given content.
50
+ */
51
+ replace(from: number, to: number, text: Text): Text;
52
+ /**
53
+ Append another document to this one.
54
+ */
55
+ append(other: Text): Text;
56
+ /**
57
+ Retrieve the text between the given points.
58
+ */
59
+ slice(from: number, to?: number): Text;
60
+ /**
61
+ Retrieve a part of the document as a string
62
+ */
63
+ abstract sliceString(from: number, to?: number, lineSep?: string): string;
64
+ /**
65
+ Test whether this text is equal to another instance.
66
+ */
67
+ eq(other: Text): boolean;
68
+ /**
69
+ Iterate over the text. When `dir` is `-1`, iteration happens
70
+ from end to start. This will return lines and the breaks between
71
+ them as separate strings.
72
+ */
73
+ iter(dir?: 1 | -1): TextIterator;
74
+ /**
75
+ Iterate over a range of the text. When `from` > `to`, the
76
+ iterator will run in reverse.
77
+ */
78
+ iterRange(from: number, to?: number): TextIterator;
79
+ /**
80
+ Return a cursor that iterates over the given range of lines,
81
+ _without_ returning the line breaks between, and yielding empty
82
+ strings for empty lines.
83
+
84
+ When `from` and `to` are given, they should be 1-based line numbers.
85
+ */
86
+ iterLines(from?: number, to?: number): TextIterator;
87
+ /**
88
+ Return the document as a string, using newline characters to
89
+ separate lines.
90
+ */
91
+ toString(): string;
92
+ /**
93
+ Convert the document to an array of lines (which can be
94
+ deserialized again via [`Text.of`](https://codemirror.net/6/docs/ref/#state.Text^of)).
95
+ */
96
+ toJSON(): string[];
97
+ /**
98
+ If this is a branch node, `children` will hold the `Text`
99
+ objects that it is made up of. For leaf nodes, this holds null.
100
+ */
101
+ abstract readonly children: readonly Text[] | null;
102
+ [Symbol.iterator]: () => Iterator<string>;
103
+ /**
104
+ Create a `Text` instance for the given array of lines.
105
+ */
106
+ static of(text: readonly string[]): Text;
107
+ /**
108
+ The empty document.
109
+ */
110
+ static empty: Text;
111
+ }
112
+ /**
113
+ This type describes a line in the document. It is created
114
+ on-demand when lines are [queried](https://codemirror.net/6/docs/ref/#state.Text.lineAt).
115
+ */
116
+ declare class Line {
117
+ /**
118
+ The position of the start of the line.
119
+ */
120
+ readonly from: number;
121
+ /**
122
+ The position at the end of the line (_before_ the line break,
123
+ or at the end of document for the last line).
124
+ */
125
+ readonly to: number;
126
+ /**
127
+ This line's line number (1-based).
128
+ */
129
+ readonly number: number;
130
+ /**
131
+ The line's content.
132
+ */
133
+ readonly text: string;
134
+ /**
135
+ The length of the line (not including any line break after it).
136
+ */
137
+ get length(): number;
138
+ }
139
+
140
+ /**
141
+ Distinguishes different ways in which positions can be mapped.
142
+ */
143
+ declare enum MapMode {
144
+ /**
145
+ Map a position to a valid new position, even when its context
146
+ was deleted.
147
+ */
148
+ Simple = 0,
149
+ /**
150
+ Return null if deletion happens across the position.
151
+ */
152
+ TrackDel = 1,
153
+ /**
154
+ Return null if the character _before_ the position is deleted.
155
+ */
156
+ TrackBefore = 2,
157
+ /**
158
+ Return null if the character _after_ the position is deleted.
159
+ */
160
+ TrackAfter = 3
161
+ }
162
+ /**
163
+ A change description is a variant of [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet)
164
+ that doesn't store the inserted text. As such, it can't be
165
+ applied, but is cheaper to store and manipulate.
166
+ */
167
+ declare class ChangeDesc {
168
+ /**
169
+ The length of the document before the change.
170
+ */
171
+ get length(): number;
172
+ /**
173
+ The length of the document after the change.
174
+ */
175
+ get newLength(): number;
176
+ /**
177
+ False when there are actual changes in this set.
178
+ */
179
+ get empty(): boolean;
180
+ /**
181
+ Iterate over the unchanged parts left by these changes. `posA`
182
+ provides the position of the range in the old document, `posB`
183
+ the new position in the changed document.
184
+ */
185
+ iterGaps(f: (posA: number, posB: number, length: number) => void): void;
186
+ /**
187
+ Iterate over the ranges changed by these changes. (See
188
+ [`ChangeSet.iterChanges`](https://codemirror.net/6/docs/ref/#state.ChangeSet.iterChanges) for a
189
+ variant that also provides you with the inserted text.)
190
+ `fromA`/`toA` provides the extent of the change in the starting
191
+ document, `fromB`/`toB` the extent of the replacement in the
192
+ changed document.
193
+
194
+ When `individual` is true, adjacent changes (which are kept
195
+ separate for [position mapping](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) are
196
+ reported separately.
197
+ */
198
+ iterChangedRanges(f: (fromA: number, toA: number, fromB: number, toB: number) => void, individual?: boolean): void;
199
+ /**
200
+ Get a description of the inverted form of these changes.
201
+ */
202
+ get invertedDesc(): ChangeDesc;
203
+ /**
204
+ Compute the combined effect of applying another set of changes
205
+ after this one. The length of the document after this set should
206
+ match the length before `other`.
207
+ */
208
+ composeDesc(other: ChangeDesc): ChangeDesc;
209
+ /**
210
+ Map this description, which should start with the same document
211
+ as `other`, over another set of changes, so that it can be
212
+ applied after it. When `before` is true, map as if the changes
213
+ in `other` happened before the ones in `this`.
214
+ */
215
+ mapDesc(other: ChangeDesc, before?: boolean): ChangeDesc;
216
+ /**
217
+ Map a given position through these changes, to produce a
218
+ position pointing into the new document.
219
+
220
+ `assoc` indicates which side the position should be associated
221
+ with. When it is negative or zero, the mapping will try to keep
222
+ the position close to the character before it (if any), and will
223
+ move it before insertions at that point or replacements across
224
+ that point. When it is positive, the position is associated with
225
+ the character after it, and will be moved forward for insertions
226
+ at or replacements across the position. Defaults to -1.
227
+
228
+ `mode` determines whether deletions should be
229
+ [reported](https://codemirror.net/6/docs/ref/#state.MapMode). It defaults to
230
+ [`MapMode.Simple`](https://codemirror.net/6/docs/ref/#state.MapMode.Simple) (don't report
231
+ deletions).
232
+ */
233
+ mapPos(pos: number, assoc?: number): number;
234
+ mapPos(pos: number, assoc: number, mode: MapMode): number | null;
235
+ /**
236
+ Check whether these changes touch a given range. When one of the
237
+ changes entirely covers the range, the string `"cover"` is
238
+ returned.
239
+ */
240
+ touchesRange(from: number, to?: number): boolean | "cover";
241
+ /**
242
+ Serialize this change desc to a JSON-representable value.
243
+ */
244
+ toJSON(): readonly number[];
245
+ /**
246
+ Create a change desc from its JSON representation (as produced
247
+ by [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeDesc.toJSON).
248
+ */
249
+ static fromJSON(json: any): ChangeDesc;
250
+ }
251
+ /**
252
+ This type is used as argument to
253
+ [`EditorState.changes`](https://codemirror.net/6/docs/ref/#state.EditorState.changes) and in the
254
+ [`changes` field](https://codemirror.net/6/docs/ref/#state.TransactionSpec.changes) of transaction
255
+ specs to succinctly describe document changes. It may either be a
256
+ plain object describing a change (a deletion, insertion, or
257
+ replacement, depending on which fields are present), a [change
258
+ set](https://codemirror.net/6/docs/ref/#state.ChangeSet), or an array of change specs.
259
+ */
260
+ type ChangeSpec = {
261
+ from: number;
262
+ to?: number;
263
+ insert?: string | Text;
264
+ } | ChangeSet | readonly ChangeSpec[];
265
+ /**
266
+ A change set represents a group of modifications to a document. It
267
+ stores the document length, and can only be applied to documents
268
+ with exactly that length.
269
+ */
270
+ declare class ChangeSet extends ChangeDesc {
271
+ private constructor();
272
+ /**
273
+ Apply the changes to a document, returning the modified
274
+ document.
275
+ */
276
+ apply(doc: Text): Text;
277
+ mapDesc(other: ChangeDesc, before?: boolean): ChangeDesc;
278
+ /**
279
+ Given the document as it existed _before_ the changes, return a
280
+ change set that represents the inverse of this set, which could
281
+ be used to go from the document created by the changes back to
282
+ the document as it existed before the changes.
283
+ */
284
+ invert(doc: Text): ChangeSet;
285
+ /**
286
+ Combine two subsequent change sets into a single set. `other`
287
+ must start in the document produced by `this`. If `this` goes
288
+ `docA` → `docB` and `other` represents `docB` → `docC`, the
289
+ returned value will represent the change `docA` → `docC`.
290
+ */
291
+ compose(other: ChangeSet): ChangeSet;
292
+ /**
293
+ Given another change set starting in the same document, maps this
294
+ change set over the other, producing a new change set that can be
295
+ applied to the document produced by applying `other`. When
296
+ `before` is `true`, order changes as if `this` comes before
297
+ `other`, otherwise (the default) treat `other` as coming first.
298
+
299
+ Given two changes `A` and `B`, `A.compose(B.map(A))` and
300
+ `B.compose(A.map(B, true))` will produce the same document. This
301
+ provides a basic form of [operational
302
+ transformation](https://en.wikipedia.org/wiki/Operational_transformation),
303
+ and can be used for collaborative editing.
304
+ */
305
+ map(other: ChangeDesc, before?: boolean): ChangeSet;
306
+ /**
307
+ Iterate over the changed ranges in the document, calling `f` for
308
+ each, with the range in the original document (`fromA`-`toA`)
309
+ and the range that replaces it in the new document
310
+ (`fromB`-`toB`).
311
+
312
+ When `individual` is true, adjacent changes are reported
313
+ separately.
314
+ */
315
+ iterChanges(f: (fromA: number, toA: number, fromB: number, toB: number, inserted: Text) => void, individual?: boolean): void;
316
+ /**
317
+ Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change
318
+ set.
319
+ */
320
+ get desc(): ChangeDesc;
321
+ /**
322
+ Serialize this change set to a JSON-representable value.
323
+ */
324
+ toJSON(): any;
325
+ /**
326
+ Create a change set for the given changes, for a document of the
327
+ given length, using `lineSep` as line separator.
328
+ */
329
+ static of(changes: ChangeSpec, length: number, lineSep?: string): ChangeSet;
330
+ /**
331
+ Create an empty changeset of the given length.
332
+ */
333
+ static empty(length: number): ChangeSet;
334
+ /**
335
+ Create a changeset from its JSON representation (as produced by
336
+ [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeSet.toJSON).
337
+ */
338
+ static fromJSON(json: any): ChangeSet;
339
+ }
340
+
341
+ /**
342
+ A single selection range. When
343
+ [`allowMultipleSelections`](https://codemirror.net/6/docs/ref/#state.EditorState^allowMultipleSelections)
344
+ is enabled, a [selection](https://codemirror.net/6/docs/ref/#state.EditorSelection) may hold
345
+ multiple ranges. By default, selections hold exactly one range.
346
+ */
347
+ declare class SelectionRange {
348
+ /**
349
+ The lower boundary of the range.
350
+ */
351
+ readonly from: number;
352
+ /**
353
+ The upper boundary of the range.
354
+ */
355
+ readonly to: number;
356
+ private flags;
357
+ private constructor();
358
+ /**
359
+ The anchor of the range—the side that doesn't move when you
360
+ extend it.
361
+ */
362
+ get anchor(): number;
363
+ /**
364
+ The head of the range, which is moved when the range is
365
+ [extended](https://codemirror.net/6/docs/ref/#state.SelectionRange.extend).
366
+ */
367
+ get head(): number;
368
+ /**
369
+ True when `anchor` and `head` are at the same position.
370
+ */
371
+ get empty(): boolean;
372
+ /**
373
+ If this is a cursor that is explicitly associated with the
374
+ character on one of its sides, this returns the side. -1 means
375
+ the character before its position, 1 the character after, and 0
376
+ means no association.
377
+ */
378
+ get assoc(): -1 | 0 | 1;
379
+ /**
380
+ The bidirectional text level associated with this cursor, if
381
+ any.
382
+ */
383
+ get bidiLevel(): number | null;
384
+ /**
385
+ The goal column (stored vertical offset) associated with a
386
+ cursor. This is used to preserve the vertical position when
387
+ [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
388
+ lines of different length.
389
+ */
390
+ get goalColumn(): number | undefined;
391
+ /**
392
+ Map this range through a change, producing a valid range in the
393
+ updated document.
394
+ */
395
+ map(change: ChangeDesc, assoc?: number): SelectionRange;
396
+ /**
397
+ Extend this range to cover at least `from` to `to`.
398
+ */
399
+ extend(from: number, to?: number): SelectionRange;
400
+ /**
401
+ Compare this range to another range.
402
+ */
403
+ eq(other: SelectionRange): boolean;
404
+ /**
405
+ Return a JSON-serializable object representing the range.
406
+ */
407
+ toJSON(): any;
408
+ /**
409
+ Convert a JSON representation of a range to a `SelectionRange`
410
+ instance.
411
+ */
412
+ static fromJSON(json: any): SelectionRange;
413
+ }
414
+ /**
415
+ An editor selection holds one or more selection ranges.
416
+ */
417
+ declare class EditorSelection {
418
+ /**
419
+ The ranges in the selection, sorted by position. Ranges cannot
420
+ overlap (but they may touch, if they aren't empty).
421
+ */
422
+ readonly ranges: readonly SelectionRange[];
423
+ /**
424
+ The index of the _main_ range in the selection (which is
425
+ usually the range that was added last).
426
+ */
427
+ readonly mainIndex: number;
428
+ private constructor();
429
+ /**
430
+ Map a selection through a change. Used to adjust the selection
431
+ position for changes.
432
+ */
433
+ map(change: ChangeDesc, assoc?: number): EditorSelection;
434
+ /**
435
+ Compare this selection to another selection.
436
+ */
437
+ eq(other: EditorSelection): boolean;
438
+ /**
439
+ Get the primary selection range. Usually, you should make sure
440
+ your code applies to _all_ ranges, by using methods like
441
+ [`changeByRange`](https://codemirror.net/6/docs/ref/#state.EditorState.changeByRange).
442
+ */
443
+ get main(): SelectionRange;
444
+ /**
445
+ Make sure the selection only has one range. Returns a selection
446
+ holding only the main range from this selection.
447
+ */
448
+ asSingle(): EditorSelection;
449
+ /**
450
+ Extend this selection with an extra range.
451
+ */
452
+ addRange(range: SelectionRange, main?: boolean): EditorSelection;
453
+ /**
454
+ Replace a given range with another range, and then normalize the
455
+ selection to merge and sort ranges if necessary.
456
+ */
457
+ replaceRange(range: SelectionRange, which?: number): EditorSelection;
458
+ /**
459
+ Convert this selection to an object that can be serialized to
460
+ JSON.
461
+ */
462
+ toJSON(): any;
463
+ /**
464
+ Create a selection from a JSON representation.
465
+ */
466
+ static fromJSON(json: any): EditorSelection;
467
+ /**
468
+ Create a selection holding a single range.
469
+ */
470
+ static single(anchor: number, head?: number): EditorSelection;
471
+ /**
472
+ Sort and merge the given set of ranges, creating a valid
473
+ selection.
474
+ */
475
+ static create(ranges: readonly SelectionRange[], mainIndex?: number): EditorSelection;
476
+ /**
477
+ Create a cursor selection range at the given position. You can
478
+ safely ignore the optional arguments in most situations.
479
+ */
480
+ static cursor(pos: number, assoc?: number, bidiLevel?: number, goalColumn?: number): SelectionRange;
481
+ /**
482
+ Create a selection range.
483
+ */
484
+ static range(anchor: number, head: number, goalColumn?: number, bidiLevel?: number): SelectionRange;
485
+ }
486
+
487
+ type FacetConfig<Input, Output> = {
488
+ /**
489
+ How to combine the input values into a single output value. When
490
+ not given, the array of input values becomes the output. This
491
+ function will immediately be called on creating the facet, with
492
+ an empty array, to compute the facet's default value when no
493
+ inputs are present.
494
+ */
495
+ combine?: (value: readonly Input[]) => Output;
496
+ /**
497
+ How to compare output values to determine whether the value of
498
+ the facet changed. Defaults to comparing by `===` or, if no
499
+ `combine` function was given, comparing each element of the
500
+ array with `===`.
501
+ */
502
+ compare?: (a: Output, b: Output) => boolean;
503
+ /**
504
+ How to compare input values to avoid recomputing the output
505
+ value when no inputs changed. Defaults to comparing with `===`.
506
+ */
507
+ compareInput?: (a: Input, b: Input) => boolean;
508
+ /**
509
+ Forbids dynamic inputs to this facet.
510
+ */
511
+ static?: boolean;
512
+ /**
513
+ If given, these extension(s) (or the result of calling the given
514
+ function with the facet) will be added to any state where this
515
+ facet is provided. (Note that, while a facet's default value can
516
+ be read from a state even if the facet wasn't present in the
517
+ state at all, these extensions won't be added in that
518
+ situation.)
519
+ */
520
+ enables?: Extension | ((self: Facet<Input, Output>) => Extension);
521
+ };
522
+ /**
523
+ A facet is a labeled value that is associated with an editor
524
+ state. It takes inputs from any number of extensions, and combines
525
+ those into a single output value.
526
+
527
+ Examples of uses of facets are the [tab
528
+ size](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize), [editor
529
+ attributes](https://codemirror.net/6/docs/ref/#view.EditorView^editorAttributes), and [update
530
+ listeners](https://codemirror.net/6/docs/ref/#view.EditorView^updateListener).
531
+
532
+ Note that `Facet` instances can be used anywhere where
533
+ [`FacetReader`](https://codemirror.net/6/docs/ref/#state.FacetReader) is expected.
534
+ */
535
+ declare class Facet<Input, Output = readonly Input[]> implements FacetReader<Output> {
536
+ private isStatic;
537
+ private constructor();
538
+ /**
539
+ Returns a facet reader for this facet, which can be used to
540
+ [read](https://codemirror.net/6/docs/ref/#state.EditorState.facet) it but not to define values for it.
541
+ */
542
+ get reader(): FacetReader<Output>;
543
+ /**
544
+ Define a new facet.
545
+ */
546
+ static define<Input, Output = readonly Input[]>(config?: FacetConfig<Input, Output>): Facet<Input, Output>;
547
+ /**
548
+ Returns an extension that adds the given value to this facet.
549
+ */
550
+ of(value: Input): Extension;
551
+ /**
552
+ Create an extension that computes a value for the facet from a
553
+ state. You must take care to declare the parts of the state that
554
+ this value depends on, since your function is only called again
555
+ for a new state when one of those parts changed.
556
+
557
+ In cases where your value depends only on a single field, you'll
558
+ want to use the [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method instead.
559
+ */
560
+ compute(deps: readonly Slot<any>[], get: (state: EditorState) => Input): Extension;
561
+ /**
562
+ Create an extension that computes zero or more values for this
563
+ facet from a state.
564
+ */
565
+ computeN(deps: readonly Slot<any>[], get: (state: EditorState) => readonly Input[]): Extension;
566
+ /**
567
+ Shorthand method for registering a facet source with a state
568
+ field as input. If the field's type corresponds to this facet's
569
+ input type, the getter function can be omitted. If given, it
570
+ will be used to retrieve the input from the field value.
571
+ */
572
+ from<T extends Input>(field: StateField<T>): Extension;
573
+ from<T>(field: StateField<T>, get: (value: T) => Input): Extension;
574
+ tag: typeof FacetTag;
575
+ }
576
+ declare const FacetTag: unique symbol;
577
+ /**
578
+ A facet reader can be used to fetch the value of a facet, though
579
+ [`EditorState.facet`](https://codemirror.net/6/docs/ref/#state.EditorState.facet) or as a dependency
580
+ in [`Facet.compute`](https://codemirror.net/6/docs/ref/#state.Facet.compute), but not to define new
581
+ values for the facet.
582
+ */
583
+ type FacetReader<Output> = {
584
+ /**
585
+ Dummy tag that makes sure TypeScript doesn't consider all object
586
+ types as conforming to this type.
587
+ */
588
+ tag: typeof FacetTag;
589
+ };
590
+ type Slot<T> = FacetReader<T> | StateField<T> | "doc" | "selection";
591
+ type StateFieldSpec<Value> = {
592
+ /**
593
+ Creates the initial value for the field when a state is created.
594
+ */
595
+ create: (state: EditorState) => Value;
596
+ /**
597
+ Compute a new value from the field's previous value and a
598
+ [transaction](https://codemirror.net/6/docs/ref/#state.Transaction).
599
+ */
600
+ update: (value: Value, transaction: Transaction) => Value;
601
+ /**
602
+ Compare two values of the field, returning `true` when they are
603
+ the same. This is used to avoid recomputing facets that depend
604
+ on the field when its value did not change. Defaults to using
605
+ `===`.
606
+ */
607
+ compare?: (a: Value, b: Value) => boolean;
608
+ /**
609
+ Provide extensions based on this field. The given function will
610
+ be called once with the initialized field. It will usually want
611
+ to call some facet's [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method to
612
+ create facet inputs from this field, but can also return other
613
+ extensions that should be enabled when the field is present in a
614
+ configuration.
615
+ */
616
+ provide?: (field: StateField<Value>) => Extension;
617
+ /**
618
+ A function used to serialize this field's content to JSON. Only
619
+ necessary when this field is included in the argument to
620
+ [`EditorState.toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON).
621
+ */
622
+ toJSON?: (value: Value, state: EditorState) => any;
623
+ /**
624
+ A function that deserializes the JSON representation of this
625
+ field's content.
626
+ */
627
+ fromJSON?: (json: any, state: EditorState) => Value;
628
+ };
629
+ /**
630
+ Fields can store additional information in an editor state, and
631
+ keep it in sync with the rest of the state.
632
+ */
633
+ declare class StateField<Value> {
634
+ private createF;
635
+ private updateF;
636
+ private compareF;
637
+ private constructor();
638
+ /**
639
+ Define a state field.
640
+ */
641
+ static define<Value>(config: StateFieldSpec<Value>): StateField<Value>;
642
+ private create;
643
+ /**
644
+ Returns an extension that enables this field and overrides the
645
+ way it is initialized. Can be useful when you need to provide a
646
+ non-default starting value for the field.
647
+ */
648
+ init(create: (state: EditorState) => Value): Extension;
649
+ /**
650
+ State field instances can be used as
651
+ [`Extension`](https://codemirror.net/6/docs/ref/#state.Extension) values to enable the field in a
652
+ given state.
653
+ */
654
+ get extension(): Extension;
655
+ }
656
+ /**
657
+ Extension values can be
658
+ [provided](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions) when creating a
659
+ state to attach various kinds of configuration and behavior
660
+ information. They can either be built-in extension-providing
661
+ objects, such as [state fields](https://codemirror.net/6/docs/ref/#state.StateField) or [facet
662
+ providers](https://codemirror.net/6/docs/ref/#state.Facet.of), or objects with an extension in its
663
+ `extension` property. Extensions can be nested in arrays
664
+ arbitrarily deep—they will be flattened when processed.
665
+ */
666
+ type Extension = {
667
+ extension: Extension;
668
+ } | readonly Extension[];
669
+ /**
670
+ By default extensions are registered in the order they are found
671
+ in the flattened form of nested array that was provided.
672
+ Individual extension values can be assigned a precedence to
673
+ override this. Extensions that do not have a precedence set get
674
+ the precedence of the nearest parent with a precedence, or
675
+ [`default`](https://codemirror.net/6/docs/ref/#state.Prec.default) if there is no such parent. The
676
+ final ordering of extensions is determined by first sorting by
677
+ precedence and then by order within each precedence.
678
+ */
679
+ declare const Prec: {
680
+ /**
681
+ The highest precedence level, for extensions that should end up
682
+ near the start of the precedence ordering.
683
+ */
684
+ highest: (ext: Extension) => Extension;
685
+ /**
686
+ A higher-than-default precedence, for extensions that should
687
+ come before those with default precedence.
688
+ */
689
+ high: (ext: Extension) => Extension;
690
+ /**
691
+ The default precedence, which is also used for extensions
692
+ without an explicit precedence.
693
+ */
694
+ default: (ext: Extension) => Extension;
695
+ /**
696
+ A lower-than-default precedence.
697
+ */
698
+ low: (ext: Extension) => Extension;
699
+ /**
700
+ The lowest precedence level. Meant for things that should end up
701
+ near the end of the extension order.
702
+ */
703
+ lowest: (ext: Extension) => Extension;
704
+ };
705
+ /**
706
+ Extension compartments can be used to make a configuration
707
+ dynamic. By [wrapping](https://codemirror.net/6/docs/ref/#state.Compartment.of) part of your
708
+ configuration in a compartment, you can later
709
+ [replace](https://codemirror.net/6/docs/ref/#state.Compartment.reconfigure) that part through a
710
+ transaction.
711
+ */
712
+ declare class Compartment {
713
+ /**
714
+ Create an instance of this compartment to add to your [state
715
+ configuration](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions).
716
+ */
717
+ of(ext: Extension): Extension;
718
+ /**
719
+ Create an [effect](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) that
720
+ reconfigures this compartment.
721
+ */
722
+ reconfigure(content: Extension): StateEffect<unknown>;
723
+ /**
724
+ Get the current content of the compartment in the state, or
725
+ `undefined` if it isn't present.
726
+ */
727
+ get(state: EditorState): Extension | undefined;
728
+ }
729
+
730
+ /**
731
+ Annotations are tagged values that are used to add metadata to
732
+ transactions in an extensible way. They should be used to model
733
+ things that effect the entire transaction (such as its [time
734
+ stamp](https://codemirror.net/6/docs/ref/#state.Transaction^time) or information about its
735
+ [origin](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent)). For effects that happen
736
+ _alongside_ the other changes made by the transaction, [state
737
+ effects](https://codemirror.net/6/docs/ref/#state.StateEffect) are more appropriate.
738
+ */
739
+ declare class Annotation<T> {
740
+ /**
741
+ The annotation type.
742
+ */
743
+ readonly type: AnnotationType<T>;
744
+ /**
745
+ The value of this annotation.
746
+ */
747
+ readonly value: T;
748
+ /**
749
+ Define a new type of annotation.
750
+ */
751
+ static define<T>(): AnnotationType<T>;
752
+ private _isAnnotation;
753
+ }
754
+ /**
755
+ Marker that identifies a type of [annotation](https://codemirror.net/6/docs/ref/#state.Annotation).
756
+ */
757
+ declare class AnnotationType<T> {
758
+ /**
759
+ Create an instance of this annotation.
760
+ */
761
+ of(value: T): Annotation<T>;
762
+ }
763
+ interface StateEffectSpec<Value> {
764
+ /**
765
+ Provides a way to map an effect like this through a position
766
+ mapping. When not given, the effects will simply not be mapped.
767
+ When the function returns `undefined`, that means the mapping
768
+ deletes the effect.
769
+ */
770
+ map?: (value: Value, mapping: ChangeDesc) => Value | undefined;
771
+ }
772
+ /**
773
+ Representation of a type of state effect. Defined with
774
+ [`StateEffect.define`](https://codemirror.net/6/docs/ref/#state.StateEffect^define).
775
+ */
776
+ declare class StateEffectType<Value> {
777
+ /**
778
+ @internal
779
+ */
780
+ readonly map: (value: any, mapping: ChangeDesc) => any | undefined;
781
+ /**
782
+ Create a [state effect](https://codemirror.net/6/docs/ref/#state.StateEffect) instance of this
783
+ type.
784
+ */
785
+ of(value: Value): StateEffect<Value>;
786
+ }
787
+ /**
788
+ State effects can be used to represent additional effects
789
+ associated with a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction.effects). They
790
+ are often useful to model changes to custom [state
791
+ fields](https://codemirror.net/6/docs/ref/#state.StateField), when those changes aren't implicit in
792
+ document or selection changes.
793
+ */
794
+ declare class StateEffect<Value> {
795
+ /**
796
+ The value of this effect.
797
+ */
798
+ readonly value: Value;
799
+ /**
800
+ Map this effect through a position mapping. Will return
801
+ `undefined` when that ends up deleting the effect.
802
+ */
803
+ map(mapping: ChangeDesc): StateEffect<Value> | undefined;
804
+ /**
805
+ Tells you whether this effect object is of a given
806
+ [type](https://codemirror.net/6/docs/ref/#state.StateEffectType).
807
+ */
808
+ is<T>(type: StateEffectType<T>): this is StateEffect<T>;
809
+ /**
810
+ Define a new effect type. The type parameter indicates the type
811
+ of values that his effect holds. It should be a type that
812
+ doesn't include `undefined`, since that is used in
813
+ [mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is
814
+ removed.
815
+ */
816
+ static define<Value = null>(spec?: StateEffectSpec<Value>): StateEffectType<Value>;
817
+ /**
818
+ Map an array of effects through a change set.
819
+ */
820
+ static mapEffects(effects: readonly StateEffect<any>[], mapping: ChangeDesc): readonly StateEffect<any>[];
821
+ /**
822
+ This effect can be used to reconfigure the root extensions of
823
+ the editor. Doing this will discard any extensions
824
+ [appended](https://codemirror.net/6/docs/ref/#state.StateEffect^appendConfig), but does not reset
825
+ the content of [reconfigured](https://codemirror.net/6/docs/ref/#state.Compartment.reconfigure)
826
+ compartments.
827
+ */
828
+ static reconfigure: StateEffectType<Extension>;
829
+ /**
830
+ Append extensions to the top-level configuration of the editor.
831
+ */
832
+ static appendConfig: StateEffectType<Extension>;
833
+ }
834
+ /**
835
+ Describes a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction) when calling the
836
+ [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update) method.
837
+ */
838
+ interface TransactionSpec {
839
+ /**
840
+ The changes to the document made by this transaction.
841
+ */
842
+ changes?: ChangeSpec;
843
+ /**
844
+ When set, this transaction explicitly updates the selection.
845
+ Offsets in this selection should refer to the document as it is
846
+ _after_ the transaction.
847
+ */
848
+ selection?: EditorSelection | {
849
+ anchor: number;
850
+ head?: number;
851
+ };
852
+ /**
853
+ Attach [state effects](https://codemirror.net/6/docs/ref/#state.StateEffect) to this transaction.
854
+ Again, when they contain positions and this same spec makes
855
+ changes, those positions should refer to positions in the
856
+ updated document.
857
+ */
858
+ effects?: StateEffect<any> | readonly StateEffect<any>[];
859
+ /**
860
+ Set [annotations](https://codemirror.net/6/docs/ref/#state.Annotation) for this transaction.
861
+ */
862
+ annotations?: Annotation<any> | readonly Annotation<any>[];
863
+ /**
864
+ Shorthand for `annotations:` [`Transaction.userEvent`](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent)`.of(...)`.
865
+ */
866
+ userEvent?: string;
867
+ /**
868
+ When set to `true`, the transaction is marked as needing to
869
+ scroll the current selection into view.
870
+ */
871
+ scrollIntoView?: boolean;
872
+ /**
873
+ By default, transactions can be modified by [change
874
+ filters](https://codemirror.net/6/docs/ref/#state.EditorState^changeFilter) and [transaction
875
+ filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter). You can set this
876
+ to `false` to disable that. This can be necessary for
877
+ transactions that, for example, include annotations that must be
878
+ kept consistent with their changes.
879
+ */
880
+ filter?: boolean;
881
+ /**
882
+ Normally, when multiple specs are combined (for example by
883
+ [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update)), the
884
+ positions in `changes` are taken to refer to the document
885
+ positions in the initial document. When a spec has `sequental`
886
+ set to true, its positions will be taken to refer to the
887
+ document created by the specs before it instead.
888
+ */
889
+ sequential?: boolean;
890
+ }
891
+ /**
892
+ Changes to the editor state are grouped into transactions.
893
+ Typically, a user action creates a single transaction, which may
894
+ contain any number of document changes, may change the selection,
895
+ or have other effects. Create a transaction by calling
896
+ [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update), or immediately
897
+ dispatch one by calling
898
+ [`EditorView.dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch).
899
+ */
900
+ declare class Transaction {
901
+ /**
902
+ The state from which the transaction starts.
903
+ */
904
+ readonly startState: EditorState;
905
+ /**
906
+ The document changes made by this transaction.
907
+ */
908
+ readonly changes: ChangeSet;
909
+ /**
910
+ The selection set by this transaction, or undefined if it
911
+ doesn't explicitly set a selection.
912
+ */
913
+ readonly selection: EditorSelection | undefined;
914
+ /**
915
+ The effects added to the transaction.
916
+ */
917
+ readonly effects: readonly StateEffect<any>[];
918
+ /**
919
+ Whether the selection should be scrolled into view after this
920
+ transaction is dispatched.
921
+ */
922
+ readonly scrollIntoView: boolean;
923
+ private constructor();
924
+ /**
925
+ The new document produced by the transaction. Contrary to
926
+ [`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't
927
+ force the entire new state to be computed right away, so it is
928
+ recommended that [transaction
929
+ filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) use this getter
930
+ when they need to look at the new document.
931
+ */
932
+ get newDoc(): Text;
933
+ /**
934
+ The new selection produced by the transaction. If
935
+ [`this.selection`](https://codemirror.net/6/docs/ref/#state.Transaction.selection) is undefined,
936
+ this will [map](https://codemirror.net/6/docs/ref/#state.EditorSelection.map) the start state's
937
+ current selection through the changes made by the transaction.
938
+ */
939
+ get newSelection(): EditorSelection;
940
+ /**
941
+ The new state created by the transaction. Computed on demand
942
+ (but retained for subsequent access), so it is recommended not to
943
+ access it in [transaction
944
+ filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) when possible.
945
+ */
946
+ get state(): EditorState;
947
+ /**
948
+ Get the value of the given annotation type, if any.
949
+ */
950
+ annotation<T>(type: AnnotationType<T>): T | undefined;
951
+ /**
952
+ Indicates whether the transaction changed the document.
953
+ */
954
+ get docChanged(): boolean;
955
+ /**
956
+ Indicates whether this transaction reconfigures the state
957
+ (through a [configuration compartment](https://codemirror.net/6/docs/ref/#state.Compartment) or
958
+ with a top-level configuration
959
+ [effect](https://codemirror.net/6/docs/ref/#state.StateEffect^reconfigure).
960
+ */
961
+ get reconfigured(): boolean;
962
+ /**
963
+ Returns true if the transaction has a [user
964
+ event](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent) annotation that is equal to
965
+ or more specific than `event`. For example, if the transaction
966
+ has `"select.pointer"` as user event, `"select"` and
967
+ `"select.pointer"` will match it.
968
+ */
969
+ isUserEvent(event: string): boolean;
970
+ /**
971
+ Annotation used to store transaction timestamps. Automatically
972
+ added to every transaction, holding `Date.now()`.
973
+ */
974
+ static time: AnnotationType<number>;
975
+ /**
976
+ Annotation used to associate a transaction with a user interface
977
+ event. Holds a string identifying the event, using a
978
+ dot-separated format to support attaching more specific
979
+ information. The events used by the core libraries are:
980
+
981
+ - `"input"` when content is entered
982
+ - `"input.type"` for typed input
983
+ - `"input.type.compose"` for composition
984
+ - `"input.paste"` for pasted input
985
+ - `"input.drop"` when adding content with drag-and-drop
986
+ - `"input.complete"` when autocompleting
987
+ - `"delete"` when the user deletes content
988
+ - `"delete.selection"` when deleting the selection
989
+ - `"delete.forward"` when deleting forward from the selection
990
+ - `"delete.backward"` when deleting backward from the selection
991
+ - `"delete.cut"` when cutting to the clipboard
992
+ - `"move"` when content is moved
993
+ - `"move.drop"` when content is moved within the editor through drag-and-drop
994
+ - `"select"` when explicitly changing the selection
995
+ - `"select.pointer"` when selecting with a mouse or other pointing device
996
+ - `"undo"` and `"redo"` for history actions
997
+
998
+ Use [`isUserEvent`](https://codemirror.net/6/docs/ref/#state.Transaction.isUserEvent) to check
999
+ whether the annotation matches a given event.
1000
+ */
1001
+ static userEvent: AnnotationType<string>;
1002
+ /**
1003
+ Annotation indicating whether a transaction should be added to
1004
+ the undo history or not.
1005
+ */
1006
+ static addToHistory: AnnotationType<boolean>;
1007
+ /**
1008
+ Annotation indicating (when present and true) that a transaction
1009
+ represents a change made by some other actor, not the user. This
1010
+ is used, for example, to tag other people's changes in
1011
+ collaborative editing.
1012
+ */
1013
+ static remote: AnnotationType<boolean>;
1014
+ }
1015
+
1016
+ /**
1017
+ The categories produced by a [character
1018
+ categorizer](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer). These are used
1019
+ do things like selecting by word.
1020
+ */
1021
+ declare enum CharCategory {
1022
+ /**
1023
+ Word characters.
1024
+ */
1025
+ Word = 0,
1026
+ /**
1027
+ Whitespace.
1028
+ */
1029
+ Space = 1,
1030
+ /**
1031
+ Anything else.
1032
+ */
1033
+ Other = 2
1034
+ }
1035
+
1036
+ /**
1037
+ Options passed when [creating](https://codemirror.net/6/docs/ref/#state.EditorState^create) an
1038
+ editor state.
1039
+ */
1040
+ interface EditorStateConfig {
1041
+ /**
1042
+ The initial document. Defaults to an empty document. Can be
1043
+ provided either as a plain string (which will be split into
1044
+ lines according to the value of the [`lineSeparator`
1045
+ facet](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator)), or an instance of
1046
+ the [`Text`](https://codemirror.net/6/docs/ref/#state.Text) class (which is what the state will use
1047
+ to represent the document).
1048
+ */
1049
+ doc?: string | Text;
1050
+ /**
1051
+ The starting selection. Defaults to a cursor at the very start
1052
+ of the document.
1053
+ */
1054
+ selection?: EditorSelection | {
1055
+ anchor: number;
1056
+ head?: number;
1057
+ };
1058
+ /**
1059
+ [Extension(s)](https://codemirror.net/6/docs/ref/#state.Extension) to associate with this state.
1060
+ */
1061
+ extensions?: Extension;
1062
+ }
1063
+ /**
1064
+ The editor state class is a persistent (immutable) data structure.
1065
+ To update a state, you [create](https://codemirror.net/6/docs/ref/#state.EditorState.update) a
1066
+ [transaction](https://codemirror.net/6/docs/ref/#state.Transaction), which produces a _new_ state
1067
+ instance, without modifying the original object.
1068
+
1069
+ As such, _never_ mutate properties of a state directly. That'll
1070
+ just break things.
1071
+ */
1072
+ declare class EditorState {
1073
+ /**
1074
+ The current document.
1075
+ */
1076
+ readonly doc: Text;
1077
+ /**
1078
+ The current selection.
1079
+ */
1080
+ readonly selection: EditorSelection;
1081
+ private constructor();
1082
+ /**
1083
+ Retrieve the value of a [state field](https://codemirror.net/6/docs/ref/#state.StateField). Throws
1084
+ an error when the state doesn't have that field, unless you pass
1085
+ `false` as second parameter.
1086
+ */
1087
+ field<T>(field: StateField<T>): T;
1088
+ field<T>(field: StateField<T>, require: false): T | undefined;
1089
+ /**
1090
+ Create a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction) that updates this
1091
+ state. Any number of [transaction specs](https://codemirror.net/6/docs/ref/#state.TransactionSpec)
1092
+ can be passed. Unless
1093
+ [`sequential`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.sequential) is set, the
1094
+ [changes](https://codemirror.net/6/docs/ref/#state.TransactionSpec.changes) (if any) of each spec
1095
+ are assumed to start in the _current_ document (not the document
1096
+ produced by previous specs), and its
1097
+ [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) and
1098
+ [effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) are assumed to refer
1099
+ to the document created by its _own_ changes. The resulting
1100
+ transaction contains the combined effect of all the different
1101
+ specs. For [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection), later
1102
+ specs take precedence over earlier ones.
1103
+ */
1104
+ update(...specs: readonly TransactionSpec[]): Transaction;
1105
+ /**
1106
+ Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
1107
+ replaces every selection range with the given content.
1108
+ */
1109
+ replaceSelection(text: string | Text): TransactionSpec;
1110
+ /**
1111
+ Create a set of changes and a new selection by running the given
1112
+ function for each range in the active selection. The function
1113
+ can return an optional set of changes (in the coordinate space
1114
+ of the start document), plus an updated range (in the coordinate
1115
+ space of the document produced by the call's own changes). This
1116
+ method will merge all the changes and ranges into a single
1117
+ changeset and selection, and return it as a [transaction
1118
+ spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec), which can be passed to
1119
+ [`update`](https://codemirror.net/6/docs/ref/#state.EditorState.update).
1120
+ */
1121
+ changeByRange(f: (range: SelectionRange) => {
1122
+ range: SelectionRange;
1123
+ changes?: ChangeSpec;
1124
+ effects?: StateEffect<any> | readonly StateEffect<any>[];
1125
+ }): {
1126
+ changes: ChangeSet;
1127
+ selection: EditorSelection;
1128
+ effects: readonly StateEffect<any>[];
1129
+ };
1130
+ /**
1131
+ Create a [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet) from the given change
1132
+ description, taking the state's document length and line
1133
+ separator into account.
1134
+ */
1135
+ changes(spec?: ChangeSpec): ChangeSet;
1136
+ /**
1137
+ Using the state's [line
1138
+ separator](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator), create a
1139
+ [`Text`](https://codemirror.net/6/docs/ref/#state.Text) instance from the given string.
1140
+ */
1141
+ toText(string: string): Text;
1142
+ /**
1143
+ Return the given range of the document as a string.
1144
+ */
1145
+ sliceDoc(from?: number, to?: number): string;
1146
+ /**
1147
+ Get the value of a state [facet](https://codemirror.net/6/docs/ref/#state.Facet).
1148
+ */
1149
+ facet<Output>(facet: FacetReader<Output>): Output;
1150
+ /**
1151
+ Convert this state to a JSON-serializable object. When custom
1152
+ fields should be serialized, you can pass them in as an object
1153
+ mapping property names (in the resulting object, which should
1154
+ not use `doc` or `selection`) to fields.
1155
+ */
1156
+ toJSON(fields?: {
1157
+ [prop: string]: StateField<any>;
1158
+ }): any;
1159
+ /**
1160
+ Deserialize a state from its JSON representation. When custom
1161
+ fields should be deserialized, pass the same object you passed
1162
+ to [`toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) when serializing as
1163
+ third argument.
1164
+ */
1165
+ static fromJSON(json: any, config?: EditorStateConfig, fields?: {
1166
+ [prop: string]: StateField<any>;
1167
+ }): EditorState;
1168
+ /**
1169
+ Create a new state. You'll usually only need this when
1170
+ initializing an editor—updated states are created by applying
1171
+ transactions.
1172
+ */
1173
+ static create(config?: EditorStateConfig): EditorState;
1174
+ /**
1175
+ A facet that, when enabled, causes the editor to allow multiple
1176
+ ranges to be selected. Be careful though, because by default the
1177
+ editor relies on the native DOM selection, which cannot handle
1178
+ multiple selections. An extension like
1179
+ [`drawSelection`](https://codemirror.net/6/docs/ref/#view.drawSelection) can be used to make
1180
+ secondary selections visible to the user.
1181
+ */
1182
+ static allowMultipleSelections: Facet<boolean, boolean>;
1183
+ /**
1184
+ Configures the tab size to use in this state. The first
1185
+ (highest-precedence) value of the facet is used. If no value is
1186
+ given, this defaults to 4.
1187
+ */
1188
+ static tabSize: Facet<number, number>;
1189
+ /**
1190
+ The size (in columns) of a tab in the document, determined by
1191
+ the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet.
1192
+ */
1193
+ get tabSize(): number;
1194
+ /**
1195
+ The line separator to use. By default, any of `"\n"`, `"\r\n"`
1196
+ and `"\r"` is treated as a separator when splitting lines, and
1197
+ lines are joined with `"\n"`.
1198
+
1199
+ When you configure a value here, only that precise separator
1200
+ will be used, allowing you to round-trip documents through the
1201
+ editor without normalizing line separators.
1202
+ */
1203
+ static lineSeparator: Facet<string, string | undefined>;
1204
+ /**
1205
+ Get the proper [line-break](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator)
1206
+ string for this state.
1207
+ */
1208
+ get lineBreak(): string;
1209
+ /**
1210
+ This facet controls the value of the
1211
+ [`readOnly`](https://codemirror.net/6/docs/ref/#state.EditorState.readOnly) getter, which is
1212
+ consulted by commands and extensions that implement editing
1213
+ functionality to determine whether they should apply. It
1214
+ defaults to false, but when its highest-precedence value is
1215
+ `true`, such functionality disables itself.
1216
+
1217
+ Not to be confused with
1218
+ [`EditorView.editable`](https://codemirror.net/6/docs/ref/#view.EditorView^editable), which
1219
+ controls whether the editor's DOM is set to be editable (and
1220
+ thus focusable).
1221
+ */
1222
+ static readOnly: Facet<boolean, boolean>;
1223
+ /**
1224
+ Returns true when the editor is
1225
+ [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only.
1226
+ */
1227
+ get readOnly(): boolean;
1228
+ /**
1229
+ Registers translation phrases. The
1230
+ [`phrase`](https://codemirror.net/6/docs/ref/#state.EditorState.phrase) method will look through
1231
+ all objects registered with this facet to find translations for
1232
+ its argument.
1233
+ */
1234
+ static phrases: Facet<{
1235
+ [key: string]: string;
1236
+ }, readonly {
1237
+ [key: string]: string;
1238
+ }[]>;
1239
+ /**
1240
+ Look up a translation for the given phrase (via the
1241
+ [`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
1242
+ original string if no translation is found.
1243
+
1244
+ If additional arguments are passed, they will be inserted in
1245
+ place of markers like `$1` (for the first value) and `$2`, etc.
1246
+ A single `$` is equivalent to `$1`, and `$$` will produce a
1247
+ literal dollar sign.
1248
+ */
1249
+ phrase(phrase: string, ...insert: any[]): string;
1250
+ /**
1251
+ A facet used to register [language
1252
+ data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) providers.
1253
+ */
1254
+ static languageData: Facet<(state: EditorState, pos: number, side: 0 | 1 | -1) => readonly {
1255
+ [name: string]: any;
1256
+ }[], readonly ((state: EditorState, pos: number, side: 0 | 1 | -1) => readonly {
1257
+ [name: string]: any;
1258
+ }[])[]>;
1259
+ /**
1260
+ Find the values for a given language data field, provided by the
1261
+ the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
1262
+
1263
+ Examples of language data fields are...
1264
+
1265
+ - [`"commentTokens"`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) for specifying
1266
+ comment syntax.
1267
+ - [`"autocomplete"`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.override)
1268
+ for providing language-specific completion sources.
1269
+ - [`"wordChars"`](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) for adding
1270
+ characters that should be considered part of words in this
1271
+ language.
1272
+ - [`"closeBrackets"`](https://codemirror.net/6/docs/ref/#autocomplete.CloseBracketConfig) controls
1273
+ bracket closing behavior.
1274
+ */
1275
+ languageDataAt<T>(name: string, pos: number, side?: -1 | 0 | 1): readonly T[];
1276
+ /**
1277
+ Return a function that can categorize strings (expected to
1278
+ represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak))
1279
+ into one of:
1280
+
1281
+ - Word (contains an alphanumeric character or a character
1282
+ explicitly listed in the local language's `"wordChars"`
1283
+ language data, which should be a string)
1284
+ - Space (contains only whitespace)
1285
+ - Other (anything else)
1286
+ */
1287
+ charCategorizer(at: number): (char: string) => CharCategory;
1288
+ /**
1289
+ Find the word at the given position, meaning the range
1290
+ containing all [word](https://codemirror.net/6/docs/ref/#state.CharCategory.Word) characters
1291
+ around it. If no word characters are adjacent to the position,
1292
+ this returns null.
1293
+ */
1294
+ wordAt(pos: number): SelectionRange | null;
1295
+ /**
1296
+ Facet used to register change filters, which are called for each
1297
+ transaction (unless explicitly
1298
+ [disabled](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter)), and can suppress
1299
+ part of the transaction's changes.
1300
+
1301
+ Such a function can return `true` to indicate that it doesn't
1302
+ want to do anything, `false` to completely stop the changes in
1303
+ the transaction, or a set of ranges in which changes should be
1304
+ suppressed. Such ranges are represented as an array of numbers,
1305
+ with each pair of two numbers indicating the start and end of a
1306
+ range. So for example `[10, 20, 100, 110]` suppresses changes
1307
+ between 10 and 20, and between 100 and 110.
1308
+ */
1309
+ static changeFilter: Facet<(tr: Transaction) => boolean | readonly number[], readonly ((tr: Transaction) => boolean | readonly number[])[]>;
1310
+ /**
1311
+ Facet used to register a hook that gets a chance to update or
1312
+ replace transaction specs before they are applied. This will
1313
+ only be applied for transactions that don't have
1314
+ [`filter`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter) set to `false`. You
1315
+ can either return a single transaction spec (possibly the input
1316
+ transaction), or an array of specs (which will be combined in
1317
+ the same way as the arguments to
1318
+ [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update)).
1319
+
1320
+ When possible, it is recommended to avoid accessing
1321
+ [`Transaction.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state) in a filter,
1322
+ since it will force creation of a state that will then be
1323
+ discarded again, if the transaction is actually filtered.
1324
+
1325
+ (This functionality should be used with care. Indiscriminately
1326
+ modifying transaction is likely to break something or degrade
1327
+ the user experience.)
1328
+ */
1329
+ static transactionFilter: Facet<(tr: Transaction) => TransactionSpec | readonly TransactionSpec[], readonly ((tr: Transaction) => TransactionSpec | readonly TransactionSpec[])[]>;
1330
+ /**
1331
+ This is a more limited form of
1332
+ [`transactionFilter`](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter),
1333
+ which can only add
1334
+ [annotations](https://codemirror.net/6/docs/ref/#state.TransactionSpec.annotations) and
1335
+ [effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects). _But_, this type
1336
+ of filter runs even if the transaction has disabled regular
1337
+ [filtering](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter), making it suitable
1338
+ for effects that don't need to touch the changes or selection,
1339
+ but do want to process every transaction.
1340
+
1341
+ Extenders run _after_ filters, when both are present.
1342
+ */
1343
+ static transactionExtender: Facet<(tr: Transaction) => Pick<TransactionSpec, "effects" | "annotations"> | null, readonly ((tr: Transaction) => Pick<TransactionSpec, "effects" | "annotations"> | null)[]>;
1344
+ }
1345
+
1346
+ /**
1347
+ Subtype of [`Command`](https://codemirror.net/6/docs/ref/#view.Command) that doesn't require access
1348
+ to the actual editor view. Mostly useful to define commands that
1349
+ can be run and tested outside of a browser environment.
1350
+ */
1351
+ type StateCommand = (target: {
1352
+ state: EditorState;
1353
+ dispatch: (transaction: Transaction) => void;
1354
+ }) => boolean;
1355
+
1356
+ /**
1357
+ Utility function for combining behaviors to fill in a config
1358
+ object from an array of provided configs. `defaults` should hold
1359
+ default values for all optional fields in `Config`.
1360
+
1361
+ The function will, by default, error
1362
+ when a field gets two values that aren't `===`-equal, but you can
1363
+ provide combine functions per field to do something else.
1364
+ */
1365
+ declare 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
1366
+ combine?: {
1367
+ [P in keyof Config]?: (first: Config[P], second: Config[P]) => Config[P];
1368
+ }): Config;
1369
+
1370
+ /**
1371
+ Each range is associated with a value, which must inherit from
1372
+ this class.
1373
+ */
1374
+ declare abstract class RangeValue {
1375
+ /**
1376
+ Compare this value with another value. Used when comparing
1377
+ rangesets. The default implementation compares by identity.
1378
+ Unless you are only creating a fixed number of unique instances
1379
+ of your value type, it is a good idea to implement this
1380
+ properly.
1381
+ */
1382
+ eq(other: RangeValue): boolean;
1383
+ /**
1384
+ The bias value at the start of the range. Determines how the
1385
+ range is positioned relative to other ranges starting at this
1386
+ position. Defaults to 0.
1387
+ */
1388
+ startSide: number;
1389
+ /**
1390
+ The bias value at the end of the range. Defaults to 0.
1391
+ */
1392
+ endSide: number;
1393
+ /**
1394
+ The mode with which the location of the range should be mapped
1395
+ when its `from` and `to` are the same, to decide whether a
1396
+ change deletes the range. Defaults to `MapMode.TrackDel`.
1397
+ */
1398
+ mapMode: MapMode;
1399
+ /**
1400
+ Determines whether this value marks a point range. Regular
1401
+ ranges affect the part of the document they cover, and are
1402
+ meaningless when empty. Point ranges have a meaning on their
1403
+ own. When non-empty, a point range is treated as atomic and
1404
+ shadows any ranges contained in it.
1405
+ */
1406
+ point: boolean;
1407
+ /**
1408
+ Create a [range](https://codemirror.net/6/docs/ref/#state.Range) with this value.
1409
+ */
1410
+ range(from: number, to?: number): Range<this>;
1411
+ }
1412
+ /**
1413
+ A range associates a value with a range of positions.
1414
+ */
1415
+ declare class Range<T extends RangeValue> {
1416
+ /**
1417
+ The range's start position.
1418
+ */
1419
+ readonly from: number;
1420
+ /**
1421
+ Its end position.
1422
+ */
1423
+ readonly to: number;
1424
+ /**
1425
+ The value associated with this range.
1426
+ */
1427
+ readonly value: T;
1428
+ private constructor();
1429
+ }
1430
+ /**
1431
+ Collection of methods used when comparing range sets.
1432
+ */
1433
+ interface RangeComparator<T extends RangeValue> {
1434
+ /**
1435
+ Notifies the comparator that a range (in positions in the new
1436
+ document) has the given sets of values associated with it, which
1437
+ are different in the old (A) and new (B) sets.
1438
+ */
1439
+ compareRange(from: number, to: number, activeA: T[], activeB: T[]): void;
1440
+ /**
1441
+ Notification for a changed (or inserted, or deleted) point range.
1442
+ */
1443
+ comparePoint(from: number, to: number, pointA: T | null, pointB: T | null): void;
1444
+ }
1445
+ /**
1446
+ Methods used when iterating over the spans created by a set of
1447
+ ranges. The entire iterated range will be covered with either
1448
+ `span` or `point` calls.
1449
+ */
1450
+ interface SpanIterator<T extends RangeValue> {
1451
+ /**
1452
+ Called for any ranges not covered by point decorations. `active`
1453
+ holds the values that the range is marked with (and may be
1454
+ empty). `openStart` indicates how many of those ranges are open
1455
+ (continued) at the start of the span.
1456
+ */
1457
+ span(from: number, to: number, active: readonly T[], openStart: number): void;
1458
+ /**
1459
+ Called when going over a point decoration. The active range
1460
+ decorations that cover the point and have a higher precedence
1461
+ are provided in `active`. The open count in `openStart` counts
1462
+ the number of those ranges that started before the point and. If
1463
+ the point started before the iterated range, `openStart` will be
1464
+ `active.length + 1` to signal this.
1465
+ */
1466
+ point(from: number, to: number, value: T, active: readonly T[], openStart: number, index: number): void;
1467
+ }
1468
+ /**
1469
+ A range cursor is an object that moves to the next range every
1470
+ time you call `next` on it. Note that, unlike ES6 iterators, these
1471
+ start out pointing at the first element, so you should call `next`
1472
+ only after reading the first range (if any).
1473
+ */
1474
+ interface RangeCursor<T> {
1475
+ /**
1476
+ Move the iterator forward.
1477
+ */
1478
+ next: () => void;
1479
+ /**
1480
+ The next range's value. Holds `null` when the cursor has reached
1481
+ its end.
1482
+ */
1483
+ value: T | null;
1484
+ /**
1485
+ The next range's start position.
1486
+ */
1487
+ from: number;
1488
+ /**
1489
+ The next end position.
1490
+ */
1491
+ to: number;
1492
+ }
1493
+ type RangeSetUpdate<T extends RangeValue> = {
1494
+ /**
1495
+ An array of ranges to add. If given, this should be sorted by
1496
+ `from` position and `startSide` unless
1497
+ [`sort`](https://codemirror.net/6/docs/ref/#state.RangeSet.update^updateSpec.sort) is given as
1498
+ `true`.
1499
+ */
1500
+ add?: readonly Range<T>[];
1501
+ /**
1502
+ Indicates whether the library should sort the ranges in `add`.
1503
+ Defaults to `false`.
1504
+ */
1505
+ sort?: boolean;
1506
+ /**
1507
+ Filter the ranges already in the set. Only those for which this
1508
+ function returns `true` are kept.
1509
+ */
1510
+ filter?: (from: number, to: number, value: T) => boolean;
1511
+ /**
1512
+ Can be used to limit the range on which the filter is
1513
+ applied. Filtering only a small range, as opposed to the entire
1514
+ set, can make updates cheaper.
1515
+ */
1516
+ filterFrom?: number;
1517
+ /**
1518
+ The end position to apply the filter to.
1519
+ */
1520
+ filterTo?: number;
1521
+ };
1522
+ /**
1523
+ A range set stores a collection of [ranges](https://codemirror.net/6/docs/ref/#state.Range) in a
1524
+ way that makes them efficient to [map](https://codemirror.net/6/docs/ref/#state.RangeSet.map) and
1525
+ [update](https://codemirror.net/6/docs/ref/#state.RangeSet.update). This is an immutable data
1526
+ structure.
1527
+ */
1528
+ declare class RangeSet<T extends RangeValue> {
1529
+ private constructor();
1530
+ /**
1531
+ The number of ranges in the set.
1532
+ */
1533
+ get size(): number;
1534
+ /**
1535
+ Update the range set, optionally adding new ranges or filtering
1536
+ out existing ones.
1537
+
1538
+ (Note: The type parameter is just there as a kludge to work
1539
+ around TypeScript variance issues that prevented `RangeSet<X>`
1540
+ from being a subtype of `RangeSet<Y>` when `X` is a subtype of
1541
+ `Y`.)
1542
+ */
1543
+ update<U extends T>(updateSpec: RangeSetUpdate<U>): RangeSet<T>;
1544
+ /**
1545
+ Map this range set through a set of changes, return the new set.
1546
+ */
1547
+ map(changes: ChangeDesc): RangeSet<T>;
1548
+ /**
1549
+ Iterate over the ranges that touch the region `from` to `to`,
1550
+ calling `f` for each. There is no guarantee that the ranges will
1551
+ be reported in any specific order. When the callback returns
1552
+ `false`, iteration stops.
1553
+ */
1554
+ between(from: number, to: number, f: (from: number, to: number, value: T) => void | false): void;
1555
+ /**
1556
+ Iterate over the ranges in this set, in order, including all
1557
+ ranges that end at or after `from`.
1558
+ */
1559
+ iter(from?: number): RangeCursor<T>;
1560
+ /**
1561
+ Iterate over the ranges in a collection of sets, in order,
1562
+ starting from `from`.
1563
+ */
1564
+ static iter<T extends RangeValue>(sets: readonly RangeSet<T>[], from?: number): RangeCursor<T>;
1565
+ /**
1566
+ Iterate over two groups of sets, calling methods on `comparator`
1567
+ to notify it of possible differences.
1568
+ */
1569
+ static compare<T extends RangeValue>(oldSets: readonly RangeSet<T>[], newSets: readonly RangeSet<T>[],
1570
+ /**
1571
+ This indicates how the underlying data changed between these
1572
+ ranges, and is needed to synchronize the iteration.
1573
+ */
1574
+ textDiff: ChangeDesc, comparator: RangeComparator<T>,
1575
+ /**
1576
+ Can be used to ignore all non-point ranges, and points below
1577
+ the given size. When -1, all ranges are compared.
1578
+ */
1579
+ minPointSize?: number): void;
1580
+ /**
1581
+ Compare the contents of two groups of range sets, returning true
1582
+ if they are equivalent in the given range.
1583
+ */
1584
+ static eq<T extends RangeValue>(oldSets: readonly RangeSet<T>[], newSets: readonly RangeSet<T>[], from?: number, to?: number): boolean;
1585
+ /**
1586
+ Iterate over a group of range sets at the same time, notifying
1587
+ the iterator about the ranges covering every given piece of
1588
+ content. Returns the open count (see
1589
+ [`SpanIterator.span`](https://codemirror.net/6/docs/ref/#state.SpanIterator.span)) at the end
1590
+ of the iteration.
1591
+ */
1592
+ static spans<T extends RangeValue>(sets: readonly RangeSet<T>[], from: number, to: number, iterator: SpanIterator<T>,
1593
+ /**
1594
+ When given and greater than -1, only points of at least this
1595
+ size are taken into account.
1596
+ */
1597
+ minPointSize?: number): number;
1598
+ /**
1599
+ Create a range set for the given range or array of ranges. By
1600
+ default, this expects the ranges to be _sorted_ (by start
1601
+ position and, if two start at the same position,
1602
+ `value.startSide`). You can pass `true` as second argument to
1603
+ cause the method to sort them.
1604
+ */
1605
+ static of<T extends RangeValue>(ranges: readonly Range<T>[] | Range<T>, sort?: boolean): RangeSet<T>;
1606
+ /**
1607
+ The empty set of ranges.
1608
+ */
1609
+ static empty: RangeSet<any>;
1610
+ }
1611
+ /**
1612
+ A range set builder is a data structure that helps build up a
1613
+ [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) directly, without first allocating
1614
+ an array of [`Range`](https://codemirror.net/6/docs/ref/#state.Range) objects.
1615
+ */
1616
+ declare class RangeSetBuilder<T extends RangeValue> {
1617
+ private chunks;
1618
+ private chunkPos;
1619
+ private chunkStart;
1620
+ private last;
1621
+ private lastFrom;
1622
+ private lastTo;
1623
+ private from;
1624
+ private to;
1625
+ private value;
1626
+ private maxPoint;
1627
+ private setMaxPoint;
1628
+ private nextLayer;
1629
+ private finishChunk;
1630
+ /**
1631
+ Create an empty builder.
1632
+ */
1633
+ constructor();
1634
+ /**
1635
+ Add a range. Ranges should be added in sorted (by `from` and
1636
+ `value.startSide`) order.
1637
+ */
1638
+ add(from: number, to: number, value: T): void;
1639
+ /**
1640
+ Finish the range set. Returns the new set. The builder can't be
1641
+ used anymore after this has been called.
1642
+ */
1643
+ finish(): RangeSet<T>;
1644
+ }
1645
+
1646
+ /**
1647
+ Returns a next grapheme cluster break _after_ (not equal to)
1648
+ `pos`, if `forward` is true, or before otherwise. Returns `pos`
1649
+ itself if no further cluster break is available in the string.
1650
+ Moves across surrogate pairs, extending characters (when
1651
+ `includeExtending` is true), characters joined with zero-width
1652
+ joiners, and flag emoji.
1653
+ */
1654
+ declare function findClusterBreak(str: string, pos: number, forward?: boolean, includeExtending?: boolean): number;
1655
+ /**
1656
+ Find the code point at the given position in a string (like the
1657
+ [`codePointAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
1658
+ string method).
1659
+ */
1660
+ declare function codePointAt(str: string, pos: number): number;
1661
+ /**
1662
+ Given a Unicode codepoint, return the JavaScript string that
1663
+ respresents it (like
1664
+ [`String.fromCodePoint`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)).
1665
+ */
1666
+ declare function fromCodePoint(code: number): string;
1667
+ /**
1668
+ The amount of positions a character takes up a JavaScript string.
1669
+ */
1670
+ declare function codePointSize(code: number): 1 | 2;
1671
+
1672
+ /**
1673
+ Count the column position at the given offset into the string,
1674
+ taking extending characters and tab size into account.
1675
+ */
1676
+ declare function countColumn(string: string, tabSize: number, to?: number): number;
1677
+ /**
1678
+ Find the offset that corresponds to the given column position in a
1679
+ string, taking extending characters and tab size into account. By
1680
+ default, the string length is returned when it is too short to
1681
+ reach the column. Pass `strict` true to make it return -1 in that
1682
+ situation.
1683
+ */
1684
+ declare function findColumn(string: string, col: number, tabSize: number, strict?: boolean): number;
1685
+
1686
+ export { Annotation, AnnotationType, ChangeDesc, ChangeSet, ChangeSpec, CharCategory, Compartment, EditorSelection, EditorState, EditorStateConfig, Extension, Facet, FacetReader, Line, MapMode, Prec, Range, RangeComparator, RangeCursor, RangeSet, RangeSetBuilder, RangeValue, SelectionRange, SpanIterator, StateCommand, StateEffect, StateEffectType, StateField, Text, TextIterator, Transaction, TransactionSpec, codePointAt, codePointSize, combineConfig, countColumn, findClusterBreak, findColumn, fromCodePoint };