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