@codemirror/state 0.19.9 → 6.0.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
@@ -127,6 +263,7 @@ stores the document length, and can only be applied to documents
127
263
  with exactly that length.
128
264
  */
129
265
  declare class ChangeSet extends ChangeDesc {
266
+ private constructor();
130
267
  /**
131
268
  Apply the changes to a document, returning the modified
132
269
  document.
@@ -212,6 +349,7 @@ declare class SelectionRange {
212
349
  */
213
350
  readonly to: number;
214
351
  private flags;
352
+ private constructor();
215
353
  /**
216
354
  The anchor of the range—the side that doesn't move when you
217
355
  extend it.
@@ -282,6 +420,7 @@ declare class EditorSelection {
282
420
  usually the range that was added last).
283
421
  */
284
422
  readonly mainIndex: number;
423
+ private constructor();
285
424
  /**
286
425
  Map a selection through a change. Used to adjust the selection
287
426
  position for changes.
@@ -344,9 +483,9 @@ declare type FacetConfig<Input, Output> = {
344
483
  /**
345
484
  How to combine the input values into a single output value. When
346
485
  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.
486
+ function will immediately be called on creating the facet, with
487
+ an empty array, to compute the facet's default value when no
488
+ inputs are present.
350
489
  */
351
490
  combine?: (value: readonly Input[]) => Output;
352
491
  /**
@@ -362,7 +501,7 @@ declare type FacetConfig<Input, Output> = {
362
501
  */
363
502
  compareInput?: (a: Input, b: Input) => boolean;
364
503
  /**
365
- Static facets can not contain dynamic inputs.
504
+ Forbids dynamic inputs to this facet.
366
505
  */
367
506
  static?: boolean;
368
507
  /**
@@ -379,10 +518,10 @@ A facet is a labeled value that is associated with an editor
379
518
  state. It takes inputs from any number of extensions, and combines
380
519
  those into a single output value.
381
520
 
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).
521
+ Examples of uses of facets are the [tab
522
+ size](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize), [editor
523
+ attributes](https://codemirror.net/6/docs/ref/#view.EditorView^editorAttributes), and [update
524
+ listeners](https://codemirror.net/6/docs/ref/#view.EditorView^updateListener).
386
525
  */
387
526
  declare class Facet<Input, Output = readonly Input[]> {
388
527
  private isStatic;
@@ -392,7 +531,7 @@ declare class Facet<Input, Output = readonly Input[]> {
392
531
  */
393
532
  static define<Input, Output = readonly Input[]>(config?: FacetConfig<Input, Output>): Facet<Input, Output>;
394
533
  /**
395
- Returns an extension that adds the given value for this facet.
534
+ Returns an extension that adds the given value to this facet.
396
535
  */
397
536
  of(value: Input): Extension;
398
537
  /**
@@ -401,9 +540,8 @@ declare class Facet<Input, Output = readonly Input[]> {
401
540
  this value depends on, since your function is only called again
402
541
  for a new state when one of those parts changed.
403
542
 
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.
543
+ In cases where your value depends only on a single field, you'll
544
+ want to use the [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method instead.
407
545
  */
408
546
  compute(deps: readonly Slot<any>[], get: (state: EditorState) => Input): Extension;
409
547
  /**
@@ -417,7 +555,7 @@ declare class Facet<Input, Output = readonly Input[]> {
417
555
  input type, the getter function can be omitted. If given, it
418
556
  will be used to retrieve the input from the field value.
419
557
  */
420
- from(field: StateField<Input>): Extension;
558
+ from<T extends Input>(field: StateField<T>): Extension;
421
559
  from<T>(field: StateField<T>, get: (value: T) => Input): Extension;
422
560
  }
423
561
  declare type Slot<T> = Facet<any, T> | StateField<T> | "doc" | "selection";
@@ -439,12 +577,12 @@ declare type StateFieldSpec<Value> = {
439
577
  */
440
578
  compare?: (a: Value, b: Value) => boolean;
441
579
  /**
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.
580
+ Provide extensions based on this field. The given function will
581
+ be called once with the initialized field. It will usually want
582
+ to call some facet's [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method to
583
+ create facet inputs from this field, but can also return other
584
+ extensions that should be enabled when the field is present in a
585
+ configuration.
448
586
  */
449
587
  provide?: (field: StateField<Value>) => Extension;
450
588
  /**
@@ -511,41 +649,29 @@ precedence and then by order within each precedence.
511
649
  */
512
650
  declare const Prec: {
513
651
  /**
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.
652
+ The highest precedence level, for extensions that should end up
653
+ near the start of the precedence ordering.
525
654
  */
526
- default: (ext: Extension) => Extension;
655
+ highest: (ext: Extension) => Extension;
527
656
  /**
528
657
  A higher-than-default precedence, for extensions that should
529
658
  come before those with default precedence.
530
659
  */
531
660
  high: (ext: Extension) => Extension;
532
661
  /**
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`.
662
+ The default precedence, which is also used for extensions
663
+ without an explicit precedence.
539
664
  */
540
- fallback: (ext: Extension) => Extension;
665
+ default: (ext: Extension) => Extension;
541
666
  /**
542
- Backwards-compatible synonym for `Prec.high`.
667
+ A lower-than-default precedence.
543
668
  */
544
- extend: (ext: Extension) => Extension;
669
+ low: (ext: Extension) => Extension;
545
670
  /**
546
- Backwards-compatible synonym for `Prec.highest`.
671
+ The lowest precedence level. Meant for things that should end up
672
+ near the end of the extension order.
547
673
  */
548
- override: (ext: Extension) => Extension;
674
+ lowest: (ext: Extension) => Extension;
549
675
  };
550
676
  /**
551
677
  Extension compartments can be used to make a configuration
@@ -703,7 +829,7 @@ interface TransactionSpec {
703
829
  */
704
830
  annotations?: Annotation<any> | readonly Annotation<any>[];
705
831
  /**
706
- Shorthand for `annotations: `[`Transaction.userEvent`](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent)[`.of(...)`.
832
+ Shorthand for `annotations:` [`Transaction.userEvent`](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent)`.of(...)`.
707
833
  */
708
834
  userEvent?: string;
709
835
  /**
@@ -715,7 +841,9 @@ interface TransactionSpec {
715
841
  By default, transactions can be modified by [change
716
842
  filters](https://codemirror.net/6/docs/ref/#state.EditorState^changeFilter) and [transaction
717
843
  filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter). You can set this
718
- to `false` to disable that.
844
+ to `false` to disable that. This can be necessary for
845
+ transactions that, for example, include annotations that must be
846
+ kept consistent with their changes.
719
847
  */
720
848
  filter?: boolean;
721
849
  /**
@@ -733,7 +861,9 @@ Changes to the editor state are grouped into transactions.
733
861
  Typically, a user action creates a single transaction, which may
734
862
  contain any number of document changes, may change the selection,
735
863
  or have other effects. Create a transaction by calling
736
- [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update).
864
+ [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update), or immediately
865
+ dispatch one by calling
866
+ [`EditorView.dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch).
737
867
  */
738
868
  declare class Transaction {
739
869
  /**
@@ -758,6 +888,7 @@ declare class Transaction {
758
888
  transaction is dispatched.
759
889
  */
760
890
  readonly scrollIntoView: boolean;
891
+ private constructor();
761
892
  /**
762
893
  The new document produced by the transaction. Contrary to
763
894
  [`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't
@@ -776,7 +907,7 @@ declare class Transaction {
776
907
  get newSelection(): EditorSelection;
777
908
  /**
778
909
  The new state created by the transaction. Computed on demand
779
- (but retained for subsequent access), so itis recommended not to
910
+ (but retained for subsequent access), so it is recommended not to
780
911
  access it in [transaction
781
912
  filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) when possible.
782
913
  */
@@ -805,7 +936,8 @@ declare class Transaction {
805
936
  */
806
937
  isUserEvent(event: string): boolean;
807
938
  /**
808
- Annotation used to store transaction timestamps.
939
+ Annotation used to store transaction timestamps. Automatically
940
+ added to every transaction, holding `Date.now()`.
809
941
  */
810
942
  static time: AnnotationType<number>;
811
943
  /**
@@ -879,7 +1011,7 @@ interface EditorStateConfig {
879
1011
  provided either as a plain string (which will be split into
880
1012
  lines according to the value of the [`lineSeparator`
881
1013
  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
1014
+ the [`Text`](https://codemirror.net/6/docs/ref/#state.Text) class (which is what the state will use
883
1015
  to represent the document).
884
1016
  */
885
1017
  doc?: string | Text;
@@ -914,6 +1046,7 @@ declare class EditorState {
914
1046
  The current selection.
915
1047
  */
916
1048
  readonly selection: EditorSelection;
1049
+ private constructor();
917
1050
  /**
918
1051
  Retrieve the value of a [state field](https://codemirror.net/6/docs/ref/#state.StateField). Throws
919
1052
  an error when the state doesn't have that field, unless you pass
@@ -941,11 +1074,7 @@ declare class EditorState {
941
1074
  Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
942
1075
  replaces every selection range with the given content.
943
1076
  */
944
- replaceSelection(text: string | Text): {
945
- changes: ChangeSet;
946
- selection: EditorSelection;
947
- effects: readonly StateEffect<any>[];
948
- };
1077
+ replaceSelection(text: string | Text): TransactionSpec;
949
1078
  /**
950
1079
  Create a set of changes and a new selection by running the given
951
1080
  function for each range in the active selection. The function
@@ -975,7 +1104,7 @@ declare class EditorState {
975
1104
  /**
976
1105
  Using the state's [line
977
1106
  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.
1107
+ [`Text`](https://codemirror.net/6/docs/ref/#state.Text) instance from the given string.
979
1108
  */
980
1109
  toText(string: string): Text;
981
1110
  /**
@@ -1079,8 +1208,13 @@ declare class EditorState {
1079
1208
  Look up a translation for the given phrase (via the
1080
1209
  [`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
1081
1210
  original string if no translation is found.
1211
+
1212
+ If additional arguments are passed, they will be inserted in
1213
+ place of markers like `$1` (for the first value) and `$2`, etc.
1214
+ A single `$` is equivalent to `$1`, and `$$` will produce a
1215
+ literal dollar sign.
1082
1216
  */
1083
- phrase(phrase: string): string;
1217
+ phrase(phrase: string, ...insert: any[]): string;
1084
1218
  /**
1085
1219
  A facet used to register [language
1086
1220
  data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) providers.
@@ -1097,7 +1231,7 @@ declare class EditorState {
1097
1231
  languageDataAt<T>(name: string, pos: number, side?: -1 | 0 | 1): readonly T[];
1098
1232
  /**
1099
1233
  Return a function that can categorize strings (expected to
1100
- represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#text.findClusterBreak))
1234
+ represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak))
1101
1235
  into one of:
1102
1236
 
1103
1237
  - Word (contains an alphanumeric character or a character
@@ -1124,7 +1258,7 @@ declare class EditorState {
1124
1258
  want to do anything, `false` to completely stop the changes in
1125
1259
  the transaction, or a set of ranges in which changes should be
1126
1260
  suppressed. Such ranges are represented as an array of numbers,
1127
- with each pair of two number indicating the start and end of a
1261
+ with each pair of two numbers indicating the start and end of a
1128
1262
  range. So for example `[10, 20, 100, 110]` suppresses changes
1129
1263
  between 10 and 20, and between 100 and 110.
1130
1264
  */
@@ -1155,12 +1289,12 @@ declare class EditorState {
1155
1289
  which can only add
1156
1290
  [annotations](https://codemirror.net/6/docs/ref/#state.TransactionSpec.annotations) and
1157
1291
  [effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects). _But_, this type
1158
- of filter runs even the transaction has disabled regular
1292
+ of filter runs even if the transaction has disabled regular
1159
1293
  [filtering](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter), making it suitable
1160
1294
  for effects that don't need to touch the changes or selection,
1161
1295
  but do want to process every transaction.
1162
1296
 
1163
- Extenders run _after_ filters, when both are applied.
1297
+ Extenders run _after_ filters, when both are present.
1164
1298
  */
1165
1299
  static transactionExtender: Facet<(tr: Transaction) => Pick<TransactionSpec, "effects" | "annotations"> | null, readonly ((tr: Transaction) => Pick<TransactionSpec, "effects" | "annotations"> | null)[]>;
1166
1300
  }
@@ -1177,13 +1311,333 @@ declare type StateCommand = (target: {
1177
1311
 
1178
1312
  /**
1179
1313
  Utility function for combining behaviors to fill in a config
1180
- object from an array of provided configs. Will, by default, error
1314
+ object from an array of provided configs. `defaults` should hold
1315
+ default values for all optional fields in `Config`.
1316
+
1317
+ The function will, by default, error
1181
1318
  when a field gets two values that aren't `===`-equal, but you can
1182
1319
  provide combine functions per field to do something else.
1183
1320
  */
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
1321
+ 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
1322
  combine?: {
1186
1323
  [P in keyof Config]?: (first: Config[P], second: Config[P]) => Config[P];
1187
1324
  }): Config;
1188
1325
 
1189
- export { Annotation, AnnotationType, ChangeDesc, ChangeSet, ChangeSpec, CharCategory, Compartment, EditorSelection, EditorState, EditorStateConfig, Extension, Facet, MapMode, Prec, SelectionRange, StateCommand, StateEffect, StateEffectType, StateField, Transaction, TransactionSpec, combineConfig };
1326
+ /**
1327
+ Each range is associated with a value, which must inherit from
1328
+ this class.
1329
+ */
1330
+ declare abstract class RangeValue {
1331
+ /**
1332
+ Compare this value with another value. Used when comparing
1333
+ rangesets. The default implementation compares by identity.
1334
+ Unless you are only creating a fixed number of unique instances
1335
+ of your value type, it is a good idea to implement this
1336
+ properly.
1337
+ */
1338
+ eq(other: RangeValue): boolean;
1339
+ /**
1340
+ The bias value at the start of the range. Determines how the
1341
+ range is positioned relative to other ranges starting at this
1342
+ position. Defaults to 0.
1343
+ */
1344
+ startSide: number;
1345
+ /**
1346
+ The bias value at the end of the range. Defaults to 0.
1347
+ */
1348
+ endSide: number;
1349
+ /**
1350
+ The mode with which the location of the range should be mapped
1351
+ when its `from` and `to` are the same, to decide whether a
1352
+ change deletes the range. Defaults to `MapMode.TrackDel`.
1353
+ */
1354
+ mapMode: MapMode;
1355
+ /**
1356
+ Determines whether this value marks a point range. Regular
1357
+ ranges affect the part of the document they cover, and are
1358
+ meaningless when empty. Point ranges have a meaning on their
1359
+ own. When non-empty, a point range is treated as atomic and
1360
+ shadows any ranges contained in it.
1361
+ */
1362
+ point: boolean;
1363
+ /**
1364
+ Create a [range](https://codemirror.net/6/docs/ref/#state.Range) with this value.
1365
+ */
1366
+ range(from: number, to?: number): Range<this>;
1367
+ }
1368
+ /**
1369
+ A range associates a value with a range of positions.
1370
+ */
1371
+ declare class Range<T extends RangeValue> {
1372
+ /**
1373
+ The range's start position.
1374
+ */
1375
+ readonly from: number;
1376
+ /**
1377
+ Its end position.
1378
+ */
1379
+ readonly to: number;
1380
+ /**
1381
+ The value associated with this range.
1382
+ */
1383
+ readonly value: T;
1384
+ private constructor();
1385
+ }
1386
+ /**
1387
+ Collection of methods used when comparing range sets.
1388
+ */
1389
+ interface RangeComparator<T extends RangeValue> {
1390
+ /**
1391
+ Notifies the comparator that a range (in positions in the new
1392
+ document) has the given sets of values associated with it, which
1393
+ are different in the old (A) and new (B) sets.
1394
+ */
1395
+ compareRange(from: number, to: number, activeA: T[], activeB: T[]): void;
1396
+ /**
1397
+ Notification for a changed (or inserted, or deleted) point range.
1398
+ */
1399
+ comparePoint(from: number, to: number, pointA: T | null, pointB: T | null): void;
1400
+ }
1401
+ /**
1402
+ Methods used when iterating over the spans created by a set of
1403
+ ranges. The entire iterated range will be covered with either
1404
+ `span` or `point` calls.
1405
+ */
1406
+ interface SpanIterator<T extends RangeValue> {
1407
+ /**
1408
+ Called for any ranges not covered by point decorations. `active`
1409
+ holds the values that the range is marked with (and may be
1410
+ empty). `openStart` indicates how many of those ranges are open
1411
+ (continued) at the start of the span.
1412
+ */
1413
+ span(from: number, to: number, active: readonly T[], openStart: number): void;
1414
+ /**
1415
+ Called when going over a point decoration. The active range
1416
+ decorations that cover the point and have a higher precedence
1417
+ are provided in `active`. The open count in `openStart` counts
1418
+ the number of those ranges that started before the point and. If
1419
+ the point started before the iterated range, `openStart` will be
1420
+ `active.length + 1` to signal this.
1421
+ */
1422
+ point(from: number, to: number, value: T, active: readonly T[], openStart: number, index: number): void;
1423
+ }
1424
+ /**
1425
+ A range cursor is an object that moves to the next range every
1426
+ time you call `next` on it. Note that, unlike ES6 iterators, these
1427
+ start out pointing at the first element, so you should call `next`
1428
+ only after reading the first range (if any).
1429
+ */
1430
+ interface RangeCursor<T> {
1431
+ /**
1432
+ Move the iterator forward.
1433
+ */
1434
+ next: () => void;
1435
+ /**
1436
+ The next range's value. Holds `null` when the cursor has reached
1437
+ its end.
1438
+ */
1439
+ value: T | null;
1440
+ /**
1441
+ The next range's start position.
1442
+ */
1443
+ from: number;
1444
+ /**
1445
+ The next end position.
1446
+ */
1447
+ to: number;
1448
+ }
1449
+ declare type RangeSetUpdate<T extends RangeValue> = {
1450
+ /**
1451
+ An array of ranges to add. If given, this should be sorted by
1452
+ `from` position and `startSide` unless
1453
+ [`sort`](https://codemirror.net/6/docs/ref/#state.RangeSet.update^updateSpec.sort) is given as
1454
+ `true`.
1455
+ */
1456
+ add?: readonly Range<T>[];
1457
+ /**
1458
+ Indicates whether the library should sort the ranges in `add`.
1459
+ Defaults to `false`.
1460
+ */
1461
+ sort?: boolean;
1462
+ /**
1463
+ Filter the ranges already in the set. Only those for which this
1464
+ function returns `true` are kept.
1465
+ */
1466
+ filter?: (from: number, to: number, value: T) => boolean;
1467
+ /**
1468
+ Can be used to limit the range on which the filter is
1469
+ applied. Filtering only a small range, as opposed to the entire
1470
+ set, can make updates cheaper.
1471
+ */
1472
+ filterFrom?: number;
1473
+ /**
1474
+ The end position to apply the filter to.
1475
+ */
1476
+ filterTo?: number;
1477
+ };
1478
+ /**
1479
+ A range set stores a collection of [ranges](https://codemirror.net/6/docs/ref/#state.Range) in a
1480
+ way that makes them efficient to [map](https://codemirror.net/6/docs/ref/#state.RangeSet.map) and
1481
+ [update](https://codemirror.net/6/docs/ref/#state.RangeSet.update). This is an immutable data
1482
+ structure.
1483
+ */
1484
+ declare class RangeSet<T extends RangeValue> {
1485
+ private constructor();
1486
+ /**
1487
+ The number of ranges in the set.
1488
+ */
1489
+ get size(): number;
1490
+ /**
1491
+ Update the range set, optionally adding new ranges or filtering
1492
+ out existing ones.
1493
+
1494
+ (Note: The type parameter is just there as a kludge to work
1495
+ around TypeScript variance issues that prevented `RangeSet<X>`
1496
+ from being a subtype of `RangeSet<Y>` when `X` is a subtype of
1497
+ `Y`.)
1498
+ */
1499
+ update<U extends T>(updateSpec: RangeSetUpdate<U>): RangeSet<T>;
1500
+ /**
1501
+ Map this range set through a set of changes, return the new set.
1502
+ */
1503
+ map(changes: ChangeDesc): RangeSet<T>;
1504
+ /**
1505
+ Iterate over the ranges that touch the region `from` to `to`,
1506
+ calling `f` for each. There is no guarantee that the ranges will
1507
+ be reported in any specific order. When the callback returns
1508
+ `false`, iteration stops.
1509
+ */
1510
+ between(from: number, to: number, f: (from: number, to: number, value: T) => void | false): void;
1511
+ /**
1512
+ Iterate over the ranges in this set, in order, including all
1513
+ ranges that end at or after `from`.
1514
+ */
1515
+ iter(from?: number): RangeCursor<T>;
1516
+ /**
1517
+ Iterate over the ranges in a collection of sets, in order,
1518
+ starting from `from`.
1519
+ */
1520
+ static iter<T extends RangeValue>(sets: readonly RangeSet<T>[], from?: number): RangeCursor<T>;
1521
+ /**
1522
+ Iterate over two groups of sets, calling methods on `comparator`
1523
+ to notify it of possible differences.
1524
+ */
1525
+ static compare<T extends RangeValue>(oldSets: readonly RangeSet<T>[], newSets: readonly RangeSet<T>[],
1526
+ /**
1527
+ This indicates how the underlying data changed between these
1528
+ ranges, and is needed to synchronize the iteration. `from` and
1529
+ `to` are coordinates in the _new_ space, after these changes.
1530
+ */
1531
+ textDiff: ChangeDesc, comparator: RangeComparator<T>,
1532
+ /**
1533
+ Can be used to ignore all non-point ranges, and points below
1534
+ the given size. When -1, all ranges are compared.
1535
+ */
1536
+ minPointSize?: number): void;
1537
+ /**
1538
+ Compare the contents of two groups of range sets, returning true
1539
+ if they are equivalent in the given range.
1540
+ */
1541
+ static eq<T extends RangeValue>(oldSets: readonly RangeSet<T>[], newSets: readonly RangeSet<T>[], from?: number, to?: number): boolean;
1542
+ /**
1543
+ Iterate over a group of range sets at the same time, notifying
1544
+ the iterator about the ranges covering every given piece of
1545
+ content. Returns the open count (see
1546
+ [`SpanIterator.span`](https://codemirror.net/6/docs/ref/#state.SpanIterator.span)) at the end
1547
+ of the iteration.
1548
+ */
1549
+ static spans<T extends RangeValue>(sets: readonly RangeSet<T>[], from: number, to: number, iterator: SpanIterator<T>,
1550
+ /**
1551
+ When given and greater than -1, only points of at least this
1552
+ size are taken into account.
1553
+ */
1554
+ minPointSize?: number): number;
1555
+ /**
1556
+ Create a range set for the given range or array of ranges. By
1557
+ default, this expects the ranges to be _sorted_ (by start
1558
+ position and, if two start at the same position,
1559
+ `value.startSide`). You can pass `true` as second argument to
1560
+ cause the method to sort them.
1561
+ */
1562
+ static of<T extends RangeValue>(ranges: readonly Range<T>[] | Range<T>, sort?: boolean): RangeSet<T>;
1563
+ /**
1564
+ The empty set of ranges.
1565
+ */
1566
+ static empty: RangeSet<any>;
1567
+ }
1568
+ /**
1569
+ A range set builder is a data structure that helps build up a
1570
+ [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) directly, without first allocating
1571
+ an array of [`Range`](https://codemirror.net/6/docs/ref/#state.Range) objects.
1572
+ */
1573
+ declare class RangeSetBuilder<T extends RangeValue> {
1574
+ private chunks;
1575
+ private chunkPos;
1576
+ private chunkStart;
1577
+ private last;
1578
+ private lastFrom;
1579
+ private lastTo;
1580
+ private from;
1581
+ private to;
1582
+ private value;
1583
+ private maxPoint;
1584
+ private setMaxPoint;
1585
+ private nextLayer;
1586
+ private finishChunk;
1587
+ /**
1588
+ Create an empty builder.
1589
+ */
1590
+ constructor();
1591
+ /**
1592
+ Add a range. Ranges should be added in sorted (by `from` and
1593
+ `value.startSide`) order.
1594
+ */
1595
+ add(from: number, to: number, value: T): void;
1596
+ /**
1597
+ Finish the range set. Returns the new set. The builder can't be
1598
+ used anymore after this has been called.
1599
+ */
1600
+ finish(): RangeSet<T>;
1601
+ }
1602
+
1603
+ /**
1604
+ Returns a next grapheme cluster break _after_ (not equal to)
1605
+ `pos`, if `forward` is true, or before otherwise. Returns `pos`
1606
+ itself if no further cluster break is available in the string.
1607
+ Moves across surrogate pairs, extending characters (when
1608
+ `includeExtending` is true), characters joined with zero-width
1609
+ joiners, and flag emoji.
1610
+ */
1611
+ declare function findClusterBreak(str: string, pos: number, forward?: boolean, includeExtending?: boolean): number;
1612
+ /**
1613
+ Find the code point at the given position in a string (like the
1614
+ [`codePointAt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
1615
+ string method).
1616
+ */
1617
+ declare function codePointAt(str: string, pos: number): number;
1618
+ /**
1619
+ Given a Unicode codepoint, return the JavaScript string that
1620
+ respresents it (like
1621
+ [`String.fromCodePoint`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)).
1622
+ */
1623
+ declare function fromCodePoint(code: number): string;
1624
+ /**
1625
+ The amount of positions a character takes up a JavaScript string.
1626
+ */
1627
+ declare function codePointSize(code: number): 1 | 2;
1628
+
1629
+ /**
1630
+ Count the column position at the given offset into the string,
1631
+ taking extending characters and tab size into account.
1632
+ */
1633
+ declare function countColumn(string: string, tabSize: number, to?: number): number;
1634
+ /**
1635
+ Find the offset that corresponds to the given column position in a
1636
+ string, taking extending characters and tab size into account. By
1637
+ default, the string length is returned when it is too short to
1638
+ reach the column. Pass `strict` true to make it return -1 in that
1639
+ situation.
1640
+ */
1641
+ declare function findColumn(string: string, col: number, tabSize: number, strict?: boolean): number;
1642
+
1643
+ 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 };