@codemirror/state 0.19.8 → 0.20.1

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