@codemirror/state 0.19.9 → 0.20.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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,136 @@
1
- import { Text } from '@codemirror/text';
2
- export { Text } from '@codemirror/text';
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
+ Convert the document to an array of lines (which can be
89
+ deserialized again via [`Text.of`](https://codemirror.net/6/docs/ref/#state.Text^of)).
90
+ */
91
+ toJSON(): string[];
92
+ /**
93
+ If this is a branch node, `children` will hold the `Text`
94
+ objects that it is made up of. For leaf nodes, this holds null.
95
+ */
96
+ abstract readonly children: readonly Text[] | null;
97
+ [Symbol.iterator]: () => Iterator<string>;
98
+ /**
99
+ Create a `Text` instance for the given array of lines.
100
+ */
101
+ static of(text: readonly string[]): Text;
102
+ /**
103
+ The empty document.
104
+ */
105
+ static empty: Text;
106
+ }
107
+ /**
108
+ This type describes a line in the document. It is created
109
+ on-demand when lines are [queried](https://codemirror.net/6/docs/ref/#state.Text.lineAt).
110
+ */
111
+ declare class Line {
112
+ /**
113
+ The position of the start of the line.
114
+ */
115
+ readonly from: number;
116
+ /**
117
+ The position at the end of the line (_before_ the line break,
118
+ or at the end of document for the last line).
119
+ */
120
+ readonly to: number;
121
+ /**
122
+ This line's line number (1-based).
123
+ */
124
+ readonly number: number;
125
+ /**
126
+ The line's content.
127
+ */
128
+ readonly text: string;
129
+ /**
130
+ The length of the line (not including any line break after it).
131
+ */
132
+ get length(): number;
133
+ }
3
134
 
4
135
  /**
5
136
  Distinguishes different ways in which positions can be mapped.
@@ -42,13 +173,18 @@ declare class ChangeDesc {
42
173
  */
43
174
  get empty(): boolean;
44
175
  /**
45
- Iterate over the unchanged parts left by these changes.
176
+ Iterate over the unchanged parts left by these changes. `posA`
177
+ provides the position of the range in the old document, `posB`
178
+ the new position in the changed document.
46
179
  */
47
180
  iterGaps(f: (posA: number, posB: number, length: number) => void): void;
48
181
  /**
49
182
  Iterate over the ranges changed by these changes. (See
50
183
  [`ChangeSet.iterChanges`](https://codemirror.net/6/docs/ref/#state.ChangeSet.iterChanges) for a
51
184
  variant that also provides you with the inserted text.)
185
+ `fromA`/`toA` provides the extent of the change in the starting
186
+ document, `fromB`/`toB` the extent of the replacement in the
187
+ changed document.
52
188
 
53
189
  When `individual` is true, adjacent changes (which are kept
54
190
  separate for [position mapping](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) are
@@ -344,9 +480,9 @@ declare type FacetConfig<Input, Output> = {
344
480
  /**
345
481
  How to combine the input values into a single output value. When
346
482
  not given, the array of input values becomes the output. This
347
- will immediately be called on creating the facet, with an empty
348
- array, to compute the facet's default value when no inputs are
349
- present.
483
+ function will immediately be called on creating the facet, with
484
+ an empty array, to compute the facet's default value when no
485
+ inputs are present.
350
486
  */
351
487
  combine?: (value: readonly Input[]) => Output;
352
488
  /**
@@ -362,7 +498,7 @@ declare type FacetConfig<Input, Output> = {
362
498
  */
363
499
  compareInput?: (a: Input, b: Input) => boolean;
364
500
  /**
365
- Static facets can not contain dynamic inputs.
501
+ Forbids dynamic inputs to this facet.
366
502
  */
367
503
  static?: boolean;
368
504
  /**
@@ -379,10 +515,10 @@ A facet is a labeled value that is associated with an editor
379
515
  state. It takes inputs from any number of extensions, and combines
380
516
  those into a single output value.
381
517
 
382
- Examples of facets are the [theme](https://codemirror.net/6/docs/ref/#view.EditorView^theme) styles
383
- associated with an editor or the [tab
384
- size](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) (which is reduced to a single
385
- value, using the input with the hightest precedence).
518
+ Examples of uses of facets are the [tab
519
+ size](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize), [editor
520
+ attributes](https://codemirror.net/6/docs/ref/#view.EditorView^editorAttributes), and [update
521
+ listeners](https://codemirror.net/6/docs/ref/#view.EditorView^updateListener).
386
522
  */
387
523
  declare class Facet<Input, Output = readonly Input[]> {
388
524
  private isStatic;
@@ -392,7 +528,7 @@ declare class Facet<Input, Output = readonly Input[]> {
392
528
  */
393
529
  static define<Input, Output = readonly Input[]>(config?: FacetConfig<Input, Output>): Facet<Input, Output>;
394
530
  /**
395
- Returns an extension that adds the given value for this facet.
531
+ Returns an extension that adds the given value to this facet.
396
532
  */
397
533
  of(value: Input): Extension;
398
534
  /**
@@ -401,9 +537,8 @@ declare class Facet<Input, Output = readonly Input[]> {
401
537
  this value depends on, since your function is only called again
402
538
  for a new state when one of those parts changed.
403
539
 
404
- In most cases, you'll want to use the
405
- [`provide`](https://codemirror.net/6/docs/ref/#state.StateField^define^config.provide) option when
406
- defining a field instead.
540
+ In cases where your value depends only on a single field, you'll
541
+ want to use the [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method instead.
407
542
  */
408
543
  compute(deps: readonly Slot<any>[], get: (state: EditorState) => Input): Extension;
409
544
  /**
@@ -417,7 +552,7 @@ declare class Facet<Input, Output = readonly Input[]> {
417
552
  input type, the getter function can be omitted. If given, it
418
553
  will be used to retrieve the input from the field value.
419
554
  */
420
- from(field: StateField<Input>): Extension;
555
+ from<T extends Input>(field: StateField<T>): Extension;
421
556
  from<T>(field: StateField<T>, get: (value: T) => Input): Extension;
422
557
  }
423
558
  declare type Slot<T> = Facet<any, T> | StateField<T> | "doc" | "selection";
@@ -439,12 +574,12 @@ declare type StateFieldSpec<Value> = {
439
574
  */
440
575
  compare?: (a: Value, b: Value) => boolean;
441
576
  /**
442
- Provide values for facets based on the value of this field. The
443
- given function will be called once with the initialized field. It
444
- will usually want to call some facet's
445
- [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method to create facet inputs from
446
- this field, but can also return other extensions that should be
447
- enabled by this field.
577
+ Provide extensions based on this field. The given function will
578
+ be called once with the initialized field. It will usually want
579
+ to call some facet's [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method to
580
+ create facet inputs from this field, but can also return other
581
+ extensions that should be enabled when the field is present in a
582
+ configuration.
448
583
  */
449
584
  provide?: (field: StateField<Value>) => Extension;
450
585
  /**
@@ -511,41 +646,29 @@ precedence and then by order within each precedence.
511
646
  */
512
647
  declare const Prec: {
513
648
  /**
514
- The lowest precedence level. Meant for things that should end up
515
- near the end of the extension order.
516
- */
517
- lowest: (ext: Extension) => Extension;
518
- /**
519
- A lower-than-default precedence, for extensions.
520
- */
521
- low: (ext: Extension) => Extension;
522
- /**
523
- The default precedence, which is also used for extensions
524
- without an explicit precedence.
649
+ The highest precedence level, for extensions that should end up
650
+ near the start of the precedence ordering.
525
651
  */
526
- default: (ext: Extension) => Extension;
652
+ highest: (ext: Extension) => Extension;
527
653
  /**
528
654
  A higher-than-default precedence, for extensions that should
529
655
  come before those with default precedence.
530
656
  */
531
657
  high: (ext: Extension) => Extension;
532
658
  /**
533
- The highest precedence level, for extensions that should end up
534
- near the start of the precedence ordering.
535
- */
536
- highest: (ext: Extension) => Extension;
537
- /**
538
- Backwards-compatible synonym for `Prec.lowest`.
659
+ The default precedence, which is also used for extensions
660
+ without an explicit precedence.
539
661
  */
540
- fallback: (ext: Extension) => Extension;
662
+ default: (ext: Extension) => Extension;
541
663
  /**
542
- Backwards-compatible synonym for `Prec.high`.
664
+ A lower-than-default precedence.
543
665
  */
544
- extend: (ext: Extension) => Extension;
666
+ low: (ext: Extension) => Extension;
545
667
  /**
546
- Backwards-compatible synonym for `Prec.highest`.
668
+ The lowest precedence level. Meant for things that should end up
669
+ near the end of the extension order.
547
670
  */
548
- override: (ext: Extension) => Extension;
671
+ lowest: (ext: Extension) => Extension;
549
672
  };
550
673
  /**
551
674
  Extension compartments can be used to make a configuration
@@ -703,7 +826,7 @@ interface TransactionSpec {
703
826
  */
704
827
  annotations?: Annotation<any> | readonly Annotation<any>[];
705
828
  /**
706
- Shorthand for `annotations: `[`Transaction.userEvent`](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent)[`.of(...)`.
829
+ Shorthand for `annotations:` [`Transaction.userEvent`](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent)`.of(...)`.
707
830
  */
708
831
  userEvent?: string;
709
832
  /**
@@ -715,7 +838,9 @@ interface TransactionSpec {
715
838
  By default, transactions can be modified by [change
716
839
  filters](https://codemirror.net/6/docs/ref/#state.EditorState^changeFilter) and [transaction
717
840
  filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter). You can set this
718
- to `false` to disable that.
841
+ to `false` to disable that. This can be necessary for
842
+ transactions that, for example, include annotations that must be
843
+ kept consistent with their changes.
719
844
  */
720
845
  filter?: boolean;
721
846
  /**
@@ -733,7 +858,9 @@ Changes to the editor state are grouped into transactions.
733
858
  Typically, a user action creates a single transaction, which may
734
859
  contain any number of document changes, may change the selection,
735
860
  or have other effects. Create a transaction by calling
736
- [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update).
861
+ [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update), or immediately
862
+ dispatch one by calling
863
+ [`EditorView.dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch).
737
864
  */
738
865
  declare class Transaction {
739
866
  /**
@@ -776,7 +903,7 @@ declare class Transaction {
776
903
  get newSelection(): EditorSelection;
777
904
  /**
778
905
  The new state created by the transaction. Computed on demand
779
- (but retained for subsequent access), so itis recommended not to
906
+ (but retained for subsequent access), so it is recommended not to
780
907
  access it in [transaction
781
908
  filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) when possible.
782
909
  */
@@ -805,7 +932,8 @@ declare class Transaction {
805
932
  */
806
933
  isUserEvent(event: string): boolean;
807
934
  /**
808
- Annotation used to store transaction timestamps.
935
+ Annotation used to store transaction timestamps. Automatically
936
+ added to every transaction, holding `Date.now()`.
809
937
  */
810
938
  static time: AnnotationType<number>;
811
939
  /**
@@ -879,7 +1007,7 @@ interface EditorStateConfig {
879
1007
  provided either as a plain string (which will be split into
880
1008
  lines according to the value of the [`lineSeparator`
881
1009
  facet](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator)), or an instance of
882
- the [`Text`](https://codemirror.net/6/docs/ref/#text.Text) class (which is what the state will use
1010
+ the [`Text`](https://codemirror.net/6/docs/ref/#state.Text) class (which is what the state will use
883
1011
  to represent the document).
884
1012
  */
885
1013
  doc?: string | Text;
@@ -941,11 +1069,7 @@ declare class EditorState {
941
1069
  Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
942
1070
  replaces every selection range with the given content.
943
1071
  */
944
- replaceSelection(text: string | Text): {
945
- changes: ChangeSet;
946
- selection: EditorSelection;
947
- effects: readonly StateEffect<any>[];
948
- };
1072
+ replaceSelection(text: string | Text): TransactionSpec;
949
1073
  /**
950
1074
  Create a set of changes and a new selection by running the given
951
1075
  function for each range in the active selection. The function
@@ -975,7 +1099,7 @@ declare class EditorState {
975
1099
  /**
976
1100
  Using the state's [line
977
1101
  separator](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator), create a
978
- [`Text`](https://codemirror.net/6/docs/ref/#text.Text) instance from the given string.
1102
+ [`Text`](https://codemirror.net/6/docs/ref/#state.Text) instance from the given string.
979
1103
  */
980
1104
  toText(string: string): Text;
981
1105
  /**
@@ -1097,7 +1221,7 @@ declare class EditorState {
1097
1221
  languageDataAt<T>(name: string, pos: number, side?: -1 | 0 | 1): readonly T[];
1098
1222
  /**
1099
1223
  Return a function that can categorize strings (expected to
1100
- represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#text.findClusterBreak))
1224
+ represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak))
1101
1225
  into one of:
1102
1226
 
1103
1227
  - Word (contains an alphanumeric character or a character
@@ -1124,7 +1248,7 @@ declare class EditorState {
1124
1248
  want to do anything, `false` to completely stop the changes in
1125
1249
  the transaction, or a set of ranges in which changes should be
1126
1250
  suppressed. Such ranges are represented as an array of numbers,
1127
- with each pair of two number indicating the start and end of a
1251
+ with each pair of two numbers indicating the start and end of a
1128
1252
  range. So for example `[10, 20, 100, 110]` suppresses changes
1129
1253
  between 10 and 20, and between 100 and 110.
1130
1254
  */
@@ -1155,12 +1279,12 @@ declare class EditorState {
1155
1279
  which can only add
1156
1280
  [annotations](https://codemirror.net/6/docs/ref/#state.TransactionSpec.annotations) and
1157
1281
  [effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects). _But_, this type
1158
- of filter runs even the transaction has disabled regular
1282
+ of filter runs even if the transaction has disabled regular
1159
1283
  [filtering](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter), making it suitable
1160
1284
  for effects that don't need to touch the changes or selection,
1161
1285
  but do want to process every transaction.
1162
1286
 
1163
- Extenders run _after_ filters, when both are applied.
1287
+ Extenders run _after_ filters, when both are present.
1164
1288
  */
1165
1289
  static transactionExtender: Facet<(tr: Transaction) => Pick<TransactionSpec, "effects" | "annotations"> | null, readonly ((tr: Transaction) => Pick<TransactionSpec, "effects" | "annotations"> | null)[]>;
1166
1290
  }
@@ -1177,13 +1301,334 @@ declare type StateCommand = (target: {
1177
1301
 
1178
1302
  /**
1179
1303
  Utility function for combining behaviors to fill in a config
1180
- object from an array of provided configs. Will, by default, error
1304
+ object from an array of provided configs. `defaults` should hold
1305
+ default values for all optional fields in `Config`.
1306
+
1307
+ The function will, by default, error
1181
1308
  when a field gets two values that aren't `===`-equal, but you can
1182
1309
  provide combine functions per field to do something else.
1183
1310
  */
1184
- declare function combineConfig<Config>(configs: readonly Partial<Config>[], defaults: Partial<Config>, // Should hold only the optional properties of Config, but I haven't managed to express that
1311
+ 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
1185
1312
  combine?: {
1186
1313
  [P in keyof Config]?: (first: Config[P], second: Config[P]) => Config[P];
1187
1314
  }): Config;
1188
1315
 
1189
- export { Annotation, AnnotationType, ChangeDesc, ChangeSet, ChangeSpec, CharCategory, Compartment, EditorSelection, EditorState, EditorStateConfig, Extension, Facet, MapMode, Prec, SelectionRange, StateCommand, StateEffect, StateEffectType, StateField, Transaction, TransactionSpec, combineConfig };
1316
+ /**
1317
+ Each range is associated with a value, which must inherit from
1318
+ this class.
1319
+ */
1320
+ declare abstract class RangeValue {
1321
+ /**
1322
+ Compare this value with another value. Used when comparing
1323
+ rangesets. The default implementation compares by identity.
1324
+ Unless you are only creating a fixed number of unique instances
1325
+ of your value type, it is a good idea to implement this
1326
+ properly.
1327
+ */
1328
+ eq(other: RangeValue): boolean;
1329
+ /**
1330
+ The bias value at the start of the range. Determines how the
1331
+ range is positioned relative to other ranges starting at this
1332
+ position. Defaults to 0.
1333
+ */
1334
+ startSide: number;
1335
+ /**
1336
+ The bias value at the end of the range. Defaults to 0.
1337
+ */
1338
+ endSide: number;
1339
+ /**
1340
+ The mode with which the location of the range should be mapped
1341
+ when its `from` and `to` are the same, to decide whether a
1342
+ change deletes the range. Defaults to `MapMode.TrackDel`.
1343
+ */
1344
+ mapMode: MapMode;
1345
+ /**
1346
+ Determines whether this value marks a point range. Regular
1347
+ ranges affect the part of the document they cover, and are
1348
+ meaningless when empty. Point ranges have a meaning on their
1349
+ own. When non-empty, a point range is treated as atomic and
1350
+ shadows any ranges contained in it.
1351
+ */
1352
+ point: boolean;
1353
+ /**
1354
+ Create a [range](https://codemirror.net/6/docs/ref/#state.Range) with this value.
1355
+ */
1356
+ range(from: number, to?: number): Range<this>;
1357
+ }
1358
+ /**
1359
+ A range associates a value with a range of positions.
1360
+ */
1361
+ declare class Range<T extends RangeValue> {
1362
+ /**
1363
+ The range's start position.
1364
+ */
1365
+ readonly from: number;
1366
+ /**
1367
+ Its end position.
1368
+ */
1369
+ readonly to: number;
1370
+ /**
1371
+ The value associated with this range.
1372
+ */
1373
+ readonly value: T;
1374
+ }
1375
+ /**
1376
+ Collection of methods used when comparing range sets.
1377
+ */
1378
+ interface RangeComparator<T extends RangeValue> {
1379
+ /**
1380
+ Notifies the comparator that a range (in positions in the new
1381
+ document) has the given sets of values associated with it, which
1382
+ are different in the old (A) and new (B) sets.
1383
+ */
1384
+ compareRange(from: number, to: number, activeA: T[], activeB: T[]): void;
1385
+ /**
1386
+ Notification for a changed (or inserted, or deleted) point range.
1387
+ */
1388
+ comparePoint(from: number, to: number, pointA: T | null, pointB: T | null): void;
1389
+ }
1390
+ /**
1391
+ Methods used when iterating over the spans created by a set of
1392
+ ranges. The entire iterated range will be covered with either
1393
+ `span` or `point` calls.
1394
+ */
1395
+ interface SpanIterator<T extends RangeValue> {
1396
+ /**
1397
+ Called for any ranges not covered by point decorations. `active`
1398
+ holds the values that the range is marked with (and may be
1399
+ empty). `openStart` indicates how many of those ranges are open
1400
+ (continued) at the start of the span.
1401
+ */
1402
+ span(from: number, to: number, active: readonly T[], openStart: number): void;
1403
+ /**
1404
+ Called when going over a point decoration. The active range
1405
+ decorations that cover the point and have a higher precedence
1406
+ are provided in `active`. The open count in `openStart` counts
1407
+ the number of those ranges that started before the point and. If
1408
+ the point started before the iterated range, `openStart` will be
1409
+ `active.length + 1` to signal this.
1410
+ */
1411
+ point(from: number, to: number, value: T, active: readonly T[], openStart: number, index: number): void;
1412
+ }
1413
+ /**
1414
+ A range cursor is an object that moves to the next range every
1415
+ time you call `next` on it. Note that, unlike ES6 iterators, these
1416
+ start out pointing at the first element, so you should call `next`
1417
+ only after reading the first range (if any).
1418
+ */
1419
+ interface RangeCursor<T> {
1420
+ /**
1421
+ Move the iterator forward.
1422
+ */
1423
+ next: () => void;
1424
+ /**
1425
+ The next range's value. Holds `null` when the cursor has reached
1426
+ its end.
1427
+ */
1428
+ value: T | null;
1429
+ /**
1430
+ The next range's start position.
1431
+ */
1432
+ from: number;
1433
+ /**
1434
+ The next end position.
1435
+ */
1436
+ to: number;
1437
+ }
1438
+ declare type RangeSetUpdate<T extends RangeValue> = {
1439
+ /**
1440
+ An array of ranges to add. If given, this should be sorted by
1441
+ `from` position and `startSide` unless
1442
+ [`sort`](https://codemirror.net/6/docs/ref/#state.RangeSet.update^updateSpec.sort) is given as
1443
+ `true`.
1444
+ */
1445
+ add?: readonly Range<T>[];
1446
+ /**
1447
+ Indicates whether the library should sort the ranges in `add`.
1448
+ Defaults to `false`.
1449
+ */
1450
+ sort?: boolean;
1451
+ /**
1452
+ Filter the ranges already in the set. Only those for which this
1453
+ function returns `true` are kept.
1454
+ */
1455
+ filter?: (from: number, to: number, value: T) => boolean;
1456
+ /**
1457
+ Can be used to limit the range on which the filter is
1458
+ applied. Filtering only a small range, as opposed to the entire
1459
+ set, can make updates cheaper.
1460
+ */
1461
+ filterFrom?: number;
1462
+ /**
1463
+ The end position to apply the filter to.
1464
+ */
1465
+ filterTo?: number;
1466
+ };
1467
+ /**
1468
+ A range set stores a collection of [ranges](https://codemirror.net/6/docs/ref/#state.Range) in a
1469
+ way that makes them efficient to [map](https://codemirror.net/6/docs/ref/#state.RangeSet.map) and
1470
+ [update](https://codemirror.net/6/docs/ref/#state.RangeSet.update). This is an immutable data
1471
+ structure.
1472
+ */
1473
+ declare class RangeSet<T extends RangeValue> {
1474
+ /**
1475
+ The number of ranges in the set.
1476
+ */
1477
+ get size(): number;
1478
+ /**
1479
+ Update the range set, optionally adding new ranges or filtering
1480
+ out existing ones.
1481
+
1482
+ (Note: The type parameter is just there as a kludge to work
1483
+ around TypeScript variance issues that prevented `RangeSet<X>`
1484
+ from being a subtype of `RangeSet<Y>` when `X` is a subtype of
1485
+ `Y`.)
1486
+ */
1487
+ update<U extends T>(updateSpec: RangeSetUpdate<U>): RangeSet<T>;
1488
+ /**
1489
+ Map this range set through a set of changes, return the new set.
1490
+ */
1491
+ map(changes: ChangeDesc): RangeSet<T>;
1492
+ /**
1493
+ Iterate over the ranges that touch the region `from` to `to`,
1494
+ calling `f` for each. There is no guarantee that the ranges will
1495
+ be reported in any specific order. When the callback returns
1496
+ `false`, iteration stops.
1497
+ */
1498
+ between(from: number, to: number, f: (from: number, to: number, value: T) => void | false): void;
1499
+ /**
1500
+ Iterate over the ranges in this set, in order, including all
1501
+ ranges that end at or after `from`.
1502
+ */
1503
+ iter(from?: number): RangeCursor<T>;
1504
+ /**
1505
+ Iterate over the ranges in a collection of sets, in order,
1506
+ starting from `from`.
1507
+ */
1508
+ static iter<T extends RangeValue>(sets: readonly RangeSet<T>[], from?: number): RangeCursor<T>;
1509
+ /**
1510
+ Iterate over two groups of sets, calling methods on `comparator`
1511
+ to notify it of possible differences.
1512
+ */
1513
+ static compare<T extends RangeValue>(oldSets: readonly RangeSet<T>[], newSets: readonly RangeSet<T>[],
1514
+ /**
1515
+ This indicates how the underlying data changed between these
1516
+ ranges, and is needed to synchronize the iteration. `from` and
1517
+ `to` are coordinates in the _new_ space, after these changes.
1518
+ */
1519
+ textDiff: ChangeDesc, comparator: RangeComparator<T>,
1520
+ /**
1521
+ Can be used to ignore all non-point ranges, and points below
1522
+ the given size. When -1, all ranges are compared.
1523
+ */
1524
+ minPointSize?: number): void;
1525
+ /**
1526
+ Compare the contents of two groups of range sets, returning true
1527
+ if they are equivalent in the given range.
1528
+ */
1529
+ static eq<T extends RangeValue>(oldSets: readonly RangeSet<T>[], newSets: readonly RangeSet<T>[], from?: number, to?: number): boolean;
1530
+ /**
1531
+ Iterate over a group of range sets at the same time, notifying
1532
+ the iterator about the ranges covering every given piece of
1533
+ content. Returns the open count (see
1534
+ [`SpanIterator.span`](https://codemirror.net/6/docs/ref/#state.SpanIterator.span)) at the end
1535
+ of the iteration.
1536
+ */
1537
+ static spans<T extends RangeValue>(sets: readonly RangeSet<T>[], from: number, to: number, iterator: SpanIterator<T>,
1538
+ /**
1539
+ When given and greater than -1, only points of at least this
1540
+ size are taken into account.
1541
+ */
1542
+ minPointSize?: number): number;
1543
+ /**
1544
+ Create a range set for the given range or array of ranges. By
1545
+ default, this expects the ranges to be _sorted_ (by start
1546
+ position and, if two start at the same position,
1547
+ `value.startSide`). You can pass `true` as second argument to
1548
+ cause the method to sort them.
1549
+ */
1550
+ static of<T extends RangeValue>(ranges: readonly Range<T>[] | Range<T>, sort?: boolean): RangeSet<T>;
1551
+ /**
1552
+ The empty set of ranges.
1553
+ */
1554
+ static empty: RangeSet<any>;
1555
+ }
1556
+ /**
1557
+ A range set builder is a data structure that helps build up a
1558
+ [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) directly, without first allocating
1559
+ an array of [`Range`](https://codemirror.net/6/docs/ref/#state.Range) objects.
1560
+ */
1561
+ declare class RangeSetBuilder<T extends RangeValue> {
1562
+ private chunks;
1563
+ private chunkPos;
1564
+ private chunkStart;
1565
+ private last;
1566
+ private lastFrom;
1567
+ private lastTo;
1568
+ private from;
1569
+ private to;
1570
+ private value;
1571
+ private maxPoint;
1572
+ private setMaxPoint;
1573
+ private nextLayer;
1574
+ private finishChunk;
1575
+ /**
1576
+ Create an empty builder.
1577
+ */
1578
+ constructor();
1579
+ /**
1580
+ Add a range. Ranges should be added in sorted (by `from` and
1581
+ `value.startSide`) order.
1582
+ */
1583
+ add(from: number, to: number, value: T): void;
1584
+ /**
1585
+ Finish the range set. Returns the new set. The builder can't be
1586
+ used anymore after this has been called.
1587
+ */
1588
+ finish(): RangeSet<T>;
1589
+ }
1590
+
1591
+ /**
1592
+ Returns a next grapheme cluster break _after_ (not equal to)
1593
+ `pos`, if `forward` is true, or before otherwise. Returns `pos`
1594
+ itself if no further cluster break is available in the string.
1595
+ Moves across surrogate pairs, extending characters (when
1596
+ `includeExtending` is true), characters joined with zero-width
1597
+ joiners, and flag emoji.
1598
+ */
1599
+ declare function findClusterBreak(str: string, pos: number, forward?: boolean, includeExtending?: boolean): number;
1600
+ /**
1601
+ Find the code point at the given position in a string (like the
1602
+ [`codePointAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
1603
+ string method).
1604
+ */
1605
+ declare function codePointAt(str: string, pos: number): number;
1606
+ /**
1607
+ Given a Unicode codepoint, return the JavaScript string that
1608
+ respresents it (like
1609
+ [`String.fromCodePoint`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)).
1610
+ */
1611
+ declare function fromCodePoint(code: number): string;
1612
+ /**
1613
+ The first character that takes up two positions in a JavaScript
1614
+ string. It is often useful to compare with this after calling
1615
+ `codePointAt`, to figure out whether your character takes up 1 or
1616
+ 2 index positions.
1617
+ */
1618
+ declare function codePointSize(code: number): 1 | 2;
1619
+
1620
+ /**
1621
+ Count the column position at the given offset into the string,
1622
+ taking extending characters and tab size into account.
1623
+ */
1624
+ declare function countColumn(string: string, tabSize: number, to?: number): number;
1625
+ /**
1626
+ Find the offset that corresponds to the given column position in a
1627
+ string, taking extending characters and tab size into account. By
1628
+ default, the string length is returned when it is too short to
1629
+ reach the column. Pass `strict` true to make it return -1 in that
1630
+ situation.
1631
+ */
1632
+ declare function findColumn(string: string, col: number, tabSize: number, strict?: boolean): number;
1633
+
1634
+ export { Annotation, AnnotationType, ChangeDesc, ChangeSet, ChangeSpec, CharCategory, Compartment, EditorSelection, EditorState, EditorStateConfig, Extension, Facet, 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 };