UNPKG

chrome-devtools-frontend

Version:
1,388 lines (1,366 loc) 228 kB
interface ChangedRange { fromA: number; toA: number; fromB: number; toB: number; } declare class TreeFragment { readonly from: number; readonly to: number; readonly tree: Tree; readonly offset: number; constructor(from: number, to: number, tree: Tree, offset: number, openStart?: boolean, openEnd?: boolean); get openStart(): boolean; get openEnd(): boolean; static addTree(tree: Tree, fragments?: readonly TreeFragment[], partial?: boolean): TreeFragment[]; static applyChanges(fragments: readonly TreeFragment[], changes: readonly ChangedRange[], minGap?: number): readonly TreeFragment[]; } interface PartialParse { advance(): Tree | null; readonly parsedPos: number; stopAt(pos: number): void; readonly stoppedAt: number | null; } declare abstract class Parser { abstract createParse(input: Input, fragments: readonly TreeFragment[], ranges: readonly { from: number; to: number; }[]): PartialParse; startParse(input: Input | string, fragments?: readonly TreeFragment[], ranges?: readonly { from: number; to: number; }[]): PartialParse; parse(input: Input | string, fragments?: readonly TreeFragment[], ranges?: readonly { from: number; to: number; }[]): Tree; } interface Input { readonly length: number; chunk(from: number): string; readonly lineChunks: boolean; read(from: number, to: number): string; } type ParseWrapper = (inner: PartialParse, input: Input, fragments: readonly TreeFragment[], ranges: readonly { from: number; to: number; }[]) => PartialParse; declare class NodeProp<T> { perNode: boolean; deserialize: (str: string) => T; constructor(config?: { deserialize?: (str: string) => T; perNode?: boolean; }); add(match: { [selector: string]: T; } | ((type: NodeType) => T | undefined)): NodePropSource; static closedBy: NodeProp<readonly string[]>; static openedBy: NodeProp<readonly string[]>; static group: NodeProp<readonly string[]>; static contextHash: NodeProp<number>; static lookAhead: NodeProp<number>; static mounted: NodeProp<MountedTree>; } declare class MountedTree { readonly tree: Tree; readonly overlay: readonly { from: number; to: number; }[] | null; readonly parser: Parser; constructor(tree: Tree, overlay: readonly { from: number; to: number; }[] | null, parser: Parser); } type NodePropSource = (type: NodeType) => null | [NodeProp<any>, any]; declare class NodeType { readonly name: string; readonly id: number; static define(spec: { id: number; name?: string; props?: readonly ([NodeProp<any>, any] | NodePropSource)[]; top?: boolean; error?: boolean; skipped?: boolean; }): NodeType; prop<T>(prop: NodeProp<T>): T | undefined; get isTop(): boolean; get isSkipped(): boolean; get isError(): boolean; get isAnonymous(): boolean; is(name: string | number): boolean; static none: NodeType; static match<T>(map: { [selector: string]: T; }): (node: NodeType) => T | undefined; } declare class NodeSet { readonly types: readonly NodeType[]; constructor(types: readonly NodeType[]); extend(...props: NodePropSource[]): NodeSet; } declare enum IterMode { ExcludeBuffers = 1, IncludeAnonymous = 2, IgnoreMounts = 4, IgnoreOverlays = 8 } declare class Tree { readonly type: NodeType; readonly children: readonly (Tree | TreeBuffer)[]; readonly positions: readonly number[]; readonly length: number; constructor(type: NodeType, children: readonly (Tree | TreeBuffer)[], positions: readonly number[], length: number, props?: readonly [NodeProp<any> | number, any][]); static empty: Tree; cursor(mode?: IterMode): TreeCursor; cursorAt(pos: number, side?: -1 | 0 | 1, mode?: IterMode): TreeCursor; get topNode(): SyntaxNode; resolve(pos: number, side?: -1 | 0 | 1): SyntaxNode; resolveInner(pos: number, side?: -1 | 0 | 1): SyntaxNode; iterate(spec: { enter(node: SyntaxNodeRef): boolean | void; leave?(node: SyntaxNodeRef): void; from?: number; to?: number; mode?: IterMode; }): void; prop<T>(prop: NodeProp<T>): T | undefined; get propValues(): readonly [NodeProp<any> | number, any][]; balance(config?: { makeTree?: (children: readonly (Tree | TreeBuffer)[], positions: readonly number[], length: number) => Tree; }): Tree; static build(data: BuildData): Tree; } type BuildData = { buffer: BufferCursor | readonly number[]; nodeSet: NodeSet; topID: number; start?: number; bufferStart?: number; length?: number; maxBufferLength?: number; reused?: readonly Tree[]; minRepeatType?: number; }; interface BufferCursor { pos: number; id: number; start: number; end: number; size: number; next(): void; fork(): BufferCursor; } declare class TreeBuffer { readonly buffer: Uint16Array; readonly length: number; readonly set: NodeSet; constructor(buffer: Uint16Array, length: number, set: NodeSet); } interface SyntaxNodeRef { readonly from: number; readonly to: number; readonly type: NodeType; readonly name: string; readonly tree: Tree | null; readonly node: SyntaxNode; matchContext(context: readonly string[]): boolean; } interface SyntaxNode extends SyntaxNodeRef { parent: SyntaxNode | null; firstChild: SyntaxNode | null; lastChild: SyntaxNode | null; childAfter(pos: number): SyntaxNode | null; childBefore(pos: number): SyntaxNode | null; enter(pos: number, side: -1 | 0 | 1, mode?: IterMode): SyntaxNode | null; nextSibling: SyntaxNode | null; prevSibling: SyntaxNode | null; cursor(mode?: IterMode): TreeCursor; resolve(pos: number, side?: -1 | 0 | 1): SyntaxNode; resolveInner(pos: number, side?: -1 | 0 | 1): SyntaxNode; enterUnfinishedNodesBefore(pos: number): SyntaxNode; toTree(): Tree; getChild(type: string | number, before?: string | number | null, after?: string | number | null): SyntaxNode | null; getChildren(type: string | number, before?: string | number | null, after?: string | number | null): SyntaxNode[]; matchContext(context: readonly string[]): boolean; } declare class TreeCursor implements SyntaxNodeRef { type: NodeType; get name(): string; from: number; to: number; private stack; private bufferNode; private yieldNode; private yieldBuf; private yield; firstChild(): boolean; lastChild(): boolean; childAfter(pos: number): boolean; childBefore(pos: number): boolean; enter(pos: number, side: -1 | 0 | 1, mode?: IterMode): boolean; parent(): boolean; nextSibling(): boolean; prevSibling(): boolean; private atLastNode; private move; next(enter?: boolean): boolean; prev(enter?: boolean): boolean; moveTo(pos: number, side?: -1 | 0 | 1): this; get node(): SyntaxNode; get tree(): Tree | null; iterate(enter: (node: SyntaxNodeRef) => boolean | void, leave?: (node: SyntaxNodeRef) => void): void; matchContext(context: readonly string[]): boolean; } declare class Stack { pos: number; get context(): any; canShift(term: number): boolean; get parser(): LRParser; dialectEnabled(dialectID: number): boolean; private shiftContext; private reduceContext; private updateContext; } declare class InputStream { private chunk2; private chunk2Pos; next: number; pos: number; private rangeIndex; private range; peek(offset: number): any; acceptToken(token: number, endOffset?: number): void; private getChunk; private readNext; advance(n?: number): number; private setDone; } interface ExternalOptions { contextual?: boolean; fallback?: boolean; extend?: boolean; } declare class ExternalTokenizer { constructor(token: (input: InputStream, stack: Stack) => void, options?: ExternalOptions); } declare class ContextTracker<T> { constructor(spec: { start: T; shift?(context: T, term: number, stack: Stack, input: InputStream): T; reduce?(context: T, term: number, stack: Stack, input: InputStream): T; reuse?(context: T, node: Tree, stack: Stack, input: InputStream): T; hash?(context: T): number; strict?: boolean; }); } interface ParserConfig { props?: readonly NodePropSource[]; top?: string; dialect?: string; tokenizers?: { from: ExternalTokenizer; to: ExternalTokenizer; }[]; specializers?: { from: (value: string, stack: Stack) => number; to: (value: string, stack: Stack) => number; }[]; contextTracker?: ContextTracker<any>; strict?: boolean; wrap?: ParseWrapper; bufferLength?: number; } declare class LRParser extends Parser { readonly nodeSet: NodeSet; createParse(input: Input, fragments: readonly TreeFragment[], ranges: readonly { from: number; to: number; }[]): PartialParse; configure(config: ParserConfig): LRParser; hasWrappers(): boolean; getName(term: number): string; get topNode(): NodeType; static deserialize(spec: any): LRParser; } /** A text iterator iterates over a sequence of strings. When iterating over a [`Text`](https://codemirror.net/6/docs/ref/#state.Text) document, result values will either be lines or line breaks. */ interface TextIterator extends Iterator<string>, Iterable<string> { /** Retrieve the next string. Optionally skip a given number of positions after the current position. Always returns the object itself. */ next(skip?: number): this; /** The current string. Will be the empty string when the cursor is at its end or `next` hasn't been called on it yet. */ value: string; /** Whether the end of the iteration has been reached. You should probably check this right after calling `next`. */ done: boolean; /** Whether the current string represents a line break. */ lineBreak: boolean; } /** The data structure for documents. @nonabstract */ declare abstract class Text implements Iterable<string> { /** The length of the string. */ abstract readonly length: number; /** The number of lines in the string (always >= 1). */ abstract readonly lines: number; /** Get the line description around the given position. */ lineAt(pos: number): Line$1; /** Get the description for the given (1-based) line number. */ line(n: number): Line$1; /** Replace a range of the text with the given content. */ replace(from: number, to: number, text: Text): Text; /** Append another document to this one. */ append(other: Text): Text; /** Retrieve the text between the given points. */ slice(from: number, to?: number): Text; /** Retrieve a part of the document as a string */ abstract sliceString(from: number, to?: number, lineSep?: string): string; /** Test whether this text is equal to another instance. */ eq(other: Text): boolean; /** Iterate over the text. When `dir` is `-1`, iteration happens from end to start. This will return lines and the breaks between them as separate strings. */ iter(dir?: 1 | -1): TextIterator; /** Iterate over a range of the text. When `from` > `to`, the iterator will run in reverse. */ iterRange(from: number, to?: number): TextIterator; /** Return a cursor that iterates over the given range of lines, _without_ returning the line breaks between, and yielding empty strings for empty lines. When `from` and `to` are given, they should be 1-based line numbers. */ iterLines(from?: number, to?: number): TextIterator; /** Return the document as a string, using newline characters to separate lines. */ toString(): string; /** Convert the document to an array of lines (which can be deserialized again via [`Text.of`](https://codemirror.net/6/docs/ref/#state.Text^of)). */ toJSON(): string[]; /** If this is a branch node, `children` will hold the `Text` objects that it is made up of. For leaf nodes, this holds null. */ abstract readonly children: readonly Text[] | null; [Symbol.iterator]: () => Iterator<string>; /** Create a `Text` instance for the given array of lines. */ static of(text: readonly string[]): Text; /** The empty document. */ static empty: Text; } /** This type describes a line in the document. It is created on-demand when lines are [queried](https://codemirror.net/6/docs/ref/#state.Text.lineAt). */ declare class Line$1 { /** The position of the start of the line. */ readonly from: number; /** The position at the end of the line (_before_ the line break, or at the end of document for the last line). */ readonly to: number; /** This line's line number (1-based). */ readonly number: number; /** The line's content. */ readonly text: string; /** The length of the line (not including any line break after it). */ get length(): number; } /** Distinguishes different ways in which positions can be mapped. */ declare enum MapMode { /** Map a position to a valid new position, even when its context was deleted. */ Simple = 0, /** Return null if deletion happens across the position. */ TrackDel = 1, /** Return null if the character _before_ the position is deleted. */ TrackBefore = 2, /** Return null if the character _after_ the position is deleted. */ TrackAfter = 3 } /** A change description is a variant of [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet) that doesn't store the inserted text. As such, it can't be applied, but is cheaper to store and manipulate. */ declare class ChangeDesc { /** The length of the document before the change. */ get length(): number; /** The length of the document after the change. */ get newLength(): number; /** False when there are actual changes in this set. */ get empty(): boolean; /** Iterate over the unchanged parts left by these changes. `posA` provides the position of the range in the old document, `posB` the new position in the changed document. */ iterGaps(f: (posA: number, posB: number, length: number) => void): void; /** Iterate over the ranges changed by these changes. (See [`ChangeSet.iterChanges`](https://codemirror.net/6/docs/ref/#state.ChangeSet.iterChanges) for a variant that also provides you with the inserted text.) `fromA`/`toA` provides the extent of the change in the starting document, `fromB`/`toB` the extent of the replacement in the changed document. When `individual` is true, adjacent changes (which are kept separate for [position mapping](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) are reported separately. */ iterChangedRanges(f: (fromA: number, toA: number, fromB: number, toB: number) => void, individual?: boolean): void; /** Get a description of the inverted form of these changes. */ get invertedDesc(): ChangeDesc; /** Compute the combined effect of applying another set of changes after this one. The length of the document after this set should match the length before `other`. */ composeDesc(other: ChangeDesc): ChangeDesc; /** Map this description, which should start with the same document as `other`, over another set of changes, so that it can be applied after it. When `before` is true, map as if the changes in `other` happened before the ones in `this`. */ mapDesc(other: ChangeDesc, before?: boolean): ChangeDesc; /** Map a given position through these changes, to produce a position pointing into the new document. `assoc` indicates which side the position should be associated with. When it is negative or zero, the mapping will try to keep the position close to the character before it (if any), and will move it before insertions at that point or replacements across that point. When it is positive, the position is associated with the character after it, and will be moved forward for insertions at or replacements across the position. Defaults to -1. `mode` determines whether deletions should be [reported](https://codemirror.net/6/docs/ref/#state.MapMode). It defaults to [`MapMode.Simple`](https://codemirror.net/6/docs/ref/#state.MapMode.Simple) (don't report deletions). */ mapPos(pos: number, assoc?: number): number; mapPos(pos: number, assoc: number, mode: MapMode): number | null; /** Check whether these changes touch a given range. When one of the changes entirely covers the range, the string `"cover"` is returned. */ touchesRange(from: number, to?: number): boolean | "cover"; /** Serialize this change desc to a JSON-representable value. */ toJSON(): readonly number[]; /** Create a change desc from its JSON representation (as produced by [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeDesc.toJSON). */ static fromJSON(json: any): ChangeDesc; } /** This type is used as argument to [`EditorState.changes`](https://codemirror.net/6/docs/ref/#state.EditorState.changes) and in the [`changes` field](https://codemirror.net/6/docs/ref/#state.TransactionSpec.changes) of transaction specs to succinctly describe document changes. It may either be a plain object describing a change (a deletion, insertion, or replacement, depending on which fields are present), a [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet), or an array of change specs. */ type ChangeSpec = { from: number; to?: number; insert?: string | Text; } | ChangeSet | readonly ChangeSpec[]; /** A change set represents a group of modifications to a document. It stores the document length, and can only be applied to documents with exactly that length. */ declare class ChangeSet extends ChangeDesc { private constructor(); /** Apply the changes to a document, returning the modified document. */ apply(doc: Text): Text; mapDesc(other: ChangeDesc, before?: boolean): ChangeDesc; /** Given the document as it existed _before_ the changes, return a change set that represents the inverse of this set, which could be used to go from the document created by the changes back to the document as it existed before the changes. */ invert(doc: Text): ChangeSet; /** Combine two subsequent change sets into a single set. `other` must start in the document produced by `this`. If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the returned value will represent the change `docA` → `docC`. */ compose(other: ChangeSet): ChangeSet; /** Given another change set starting in the same document, maps this change set over the other, producing a new change set that can be applied to the document produced by applying `other`. When `before` is `true`, order changes as if `this` comes before `other`, otherwise (the default) treat `other` as coming first. Given two changes `A` and `B`, `A.compose(B.map(A))` and `B.compose(A.map(B, true))` will produce the same document. This provides a basic form of [operational transformation](https://en.wikipedia.org/wiki/Operational_transformation), and can be used for collaborative editing. */ map(other: ChangeDesc, before?: boolean): ChangeSet; /** Iterate over the changed ranges in the document, calling `f` for each, with the range in the original document (`fromA`-`toA`) and the range that replaces it in the new document (`fromB`-`toB`). When `individual` is true, adjacent changes are reported separately. */ iterChanges(f: (fromA: number, toA: number, fromB: number, toB: number, inserted: Text) => void, individual?: boolean): void; /** Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change set. */ get desc(): ChangeDesc; /** Serialize this change set to a JSON-representable value. */ toJSON(): any; /** Create a change set for the given changes, for a document of the given length, using `lineSep` as line separator. */ static of(changes: ChangeSpec, length: number, lineSep?: string): ChangeSet; /** Create an empty changeset of the given length. */ static empty(length: number): ChangeSet; /** Create a changeset from its JSON representation (as produced by [`toJSON`](https://codemirror.net/6/docs/ref/#state.ChangeSet.toJSON). */ static fromJSON(json: any): ChangeSet; } /** A single selection range. When [`allowMultipleSelections`](https://codemirror.net/6/docs/ref/#state.EditorState^allowMultipleSelections) is enabled, a [selection](https://codemirror.net/6/docs/ref/#state.EditorSelection) may hold multiple ranges. By default, selections hold exactly one range. */ declare class SelectionRange { /** The lower boundary of the range. */ readonly from: number; /** The upper boundary of the range. */ readonly to: number; private flags; private constructor(); /** The anchor of the range—the side that doesn't move when you extend it. */ get anchor(): number; /** The head of the range, which is moved when the range is [extended](https://codemirror.net/6/docs/ref/#state.SelectionRange.extend). */ get head(): number; /** True when `anchor` and `head` are at the same position. */ get empty(): boolean; /** If this is a cursor that is explicitly associated with the character on one of its sides, this returns the side. -1 means the character before its position, 1 the character after, and 0 means no association. */ get assoc(): -1 | 0 | 1; /** The bidirectional text level associated with this cursor, if any. */ get bidiLevel(): number | null; /** The goal column (stored vertical offset) associated with a cursor. This is used to preserve the vertical position when [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across lines of different length. */ get goalColumn(): number | undefined; /** Map this range through a change, producing a valid range in the updated document. */ map(change: ChangeDesc, assoc?: number): SelectionRange; /** Extend this range to cover at least `from` to `to`. */ extend(from: number, to?: number): SelectionRange; /** Compare this range to another range. */ eq(other: SelectionRange): boolean; /** Return a JSON-serializable object representing the range. */ toJSON(): any; /** Convert a JSON representation of a range to a `SelectionRange` instance. */ static fromJSON(json: any): SelectionRange; } /** An editor selection holds one or more selection ranges. */ declare class EditorSelection { /** The ranges in the selection, sorted by position. Ranges cannot overlap (but they may touch, if they aren't empty). */ readonly ranges: readonly SelectionRange[]; /** The index of the _main_ range in the selection (which is usually the range that was added last). */ readonly mainIndex: number; private constructor(); /** Map a selection through a change. Used to adjust the selection position for changes. */ map(change: ChangeDesc, assoc?: number): EditorSelection; /** Compare this selection to another selection. */ eq(other: EditorSelection): boolean; /** Get the primary selection range. Usually, you should make sure your code applies to _all_ ranges, by using methods like [`changeByRange`](https://codemirror.net/6/docs/ref/#state.EditorState.changeByRange). */ get main(): SelectionRange; /** Make sure the selection only has one range. Returns a selection holding only the main range from this selection. */ asSingle(): EditorSelection; /** Extend this selection with an extra range. */ addRange(range: SelectionRange, main?: boolean): EditorSelection; /** Replace a given range with another range, and then normalize the selection to merge and sort ranges if necessary. */ replaceRange(range: SelectionRange, which?: number): EditorSelection; /** Convert this selection to an object that can be serialized to JSON. */ toJSON(): any; /** Create a selection from a JSON representation. */ static fromJSON(json: any): EditorSelection; /** Create a selection holding a single range. */ static single(anchor: number, head?: number): EditorSelection; /** Sort and merge the given set of ranges, creating a valid selection. */ static create(ranges: readonly SelectionRange[], mainIndex?: number): EditorSelection; /** Create a cursor selection range at the given position. You can safely ignore the optional arguments in most situations. */ static cursor(pos: number, assoc?: number, bidiLevel?: number, goalColumn?: number): SelectionRange; /** Create a selection range. */ static range(anchor: number, head: number, goalColumn?: number, bidiLevel?: number): SelectionRange; } type FacetConfig<Input, Output> = { /** How to combine the input values into a single output value. When not given, the array of input values becomes the output. This function will immediately be called on creating the facet, with an empty array, to compute the facet's default value when no inputs are present. */ combine?: (value: readonly Input[]) => Output; /** How to compare output values to determine whether the value of the facet changed. Defaults to comparing by `===` or, if no `combine` function was given, comparing each element of the array with `===`. */ compare?: (a: Output, b: Output) => boolean; /** How to compare input values to avoid recomputing the output value when no inputs changed. Defaults to comparing with `===`. */ compareInput?: (a: Input, b: Input) => boolean; /** Forbids dynamic inputs to this facet. */ static?: boolean; /** If given, these extension(s) (or the result of calling the given function with the facet) will be added to any state where this facet is provided. (Note that, while a facet's default value can be read from a state even if the facet wasn't present in the state at all, these extensions won't be added in that situation.) */ enables?: Extension | ((self: Facet<Input, Output>) => Extension); }; /** A facet is a labeled value that is associated with an editor state. It takes inputs from any number of extensions, and combines those into a single output value. Examples of uses of facets are the [tab size](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize), [editor attributes](https://codemirror.net/6/docs/ref/#view.EditorView^editorAttributes), and [update listeners](https://codemirror.net/6/docs/ref/#view.EditorView^updateListener). */ declare class Facet<Input, Output = readonly Input[]> { private isStatic; private constructor(); /** Define a new facet. */ static define<Input, Output = readonly Input[]>(config?: FacetConfig<Input, Output>): Facet<Input, Output>; /** Returns an extension that adds the given value to this facet. */ of(value: Input): Extension; /** Create an extension that computes a value for the facet from a state. You must take care to declare the parts of the state that this value depends on, since your function is only called again for a new state when one of those parts changed. In cases where your value depends only on a single field, you'll want to use the [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method instead. */ compute(deps: readonly Slot<any>[], get: (state: EditorState) => Input): Extension; /** Create an extension that computes zero or more values for this facet from a state. */ computeN(deps: readonly Slot<any>[], get: (state: EditorState) => readonly Input[]): Extension; /** Shorthand method for registering a facet source with a state field as input. If the field's type corresponds to this facet's input type, the getter function can be omitted. If given, it will be used to retrieve the input from the field value. */ from<T extends Input>(field: StateField<T>): Extension; from<T>(field: StateField<T>, get: (value: T) => Input): Extension; } type Slot<T> = Facet<any, T> | StateField<T> | "doc" | "selection"; type StateFieldSpec<Value> = { /** Creates the initial value for the field when a state is created. */ create: (state: EditorState) => Value; /** Compute a new value from the field's previous value and a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction). */ update: (value: Value, transaction: Transaction) => Value; /** Compare two values of the field, returning `true` when they are the same. This is used to avoid recomputing facets that depend on the field when its value did not change. Defaults to using `===`. */ compare?: (a: Value, b: Value) => boolean; /** Provide extensions based on this field. The given function will be called once with the initialized field. It will usually want to call some facet's [`from`](https://codemirror.net/6/docs/ref/#state.Facet.from) method to create facet inputs from this field, but can also return other extensions that should be enabled when the field is present in a configuration. */ provide?: (field: StateField<Value>) => Extension; /** A function used to serialize this field's content to JSON. Only necessary when this field is included in the argument to [`EditorState.toJSON`](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON). */ toJSON?: (value: Value, state: EditorState) => any; /** A function that deserializes the JSON representation of this field's content. */ fromJSON?: (json: any, state: EditorState) => Value; }; /** Fields can store additional information in an editor state, and keep it in sync with the rest of the state. */ declare class StateField<Value> { private createF; private updateF; private compareF; private constructor(); /** Define a state field. */ static define<Value>(config: StateFieldSpec<Value>): StateField<Value>; private create; /** Returns an extension that enables this field and overrides the way it is initialized. Can be useful when you need to provide a non-default starting value for the field. */ init(create: (state: EditorState) => Value): Extension; /** State field instances can be used as [`Extension`](https://codemirror.net/6/docs/ref/#state.Extension) values to enable the field in a given state. */ get extension(): Extension; } /** Extension values can be [provided](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions) when creating a state to attach various kinds of configuration and behavior information. They can either be built-in extension-providing objects, such as [state fields](https://codemirror.net/6/docs/ref/#state.StateField) or [facet providers](https://codemirror.net/6/docs/ref/#state.Facet.of), or objects with an extension in its `extension` property. Extensions can be nested in arrays arbitrarily deep—they will be flattened when processed. */ type Extension = { extension: Extension; } | readonly Extension[]; /** By default extensions are registered in the order they are found in the flattened form of nested array that was provided. Individual extension values can be assigned a precedence to override this. Extensions that do not have a precedence set get the precedence of the nearest parent with a precedence, or [`default`](https://codemirror.net/6/docs/ref/#state.Prec.default) if there is no such parent. The final ordering of extensions is determined by first sorting by precedence and then by order within each precedence. */ declare const Prec: { /** The highest precedence level, for extensions that should end up near the start of the precedence ordering. */ highest: (ext: Extension) => Extension; /** A higher-than-default precedence, for extensions that should come before those with default precedence. */ high: (ext: Extension) => Extension; /** The default precedence, which is also used for extensions without an explicit precedence. */ default: (ext: Extension) => Extension; /** A lower-than-default precedence. */ low: (ext: Extension) => Extension; /** The lowest precedence level. Meant for things that should end up near the end of the extension order. */ lowest: (ext: Extension) => Extension; }; /** Extension compartments can be used to make a configuration dynamic. By [wrapping](https://codemirror.net/6/docs/ref/#state.Compartment.of) part of your configuration in a compartment, you can later [replace](https://codemirror.net/6/docs/ref/#state.Compartment.reconfigure) that part through a transaction. */ declare class Compartment { /** Create an instance of this compartment to add to your [state configuration](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions). */ of(ext: Extension): Extension; /** Create an [effect](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) that reconfigures this compartment. */ reconfigure(content: Extension): StateEffect<unknown>; /** Get the current content of the compartment in the state, or `undefined` if it isn't present. */ get(state: EditorState): Extension | undefined; } /** Annotations are tagged values that are used to add metadata to transactions in an extensible way. They should be used to model things that effect the entire transaction (such as its [time stamp](https://codemirror.net/6/docs/ref/#state.Transaction^time) or information about its [origin](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent)). For effects that happen _alongside_ the other changes made by the transaction, [state effects](https://codemirror.net/6/docs/ref/#state.StateEffect) are more appropriate. */ declare class Annotation<T> { /** The annotation type. */ readonly type: AnnotationType<T>; /** The value of this annotation. */ readonly value: T; /** Define a new type of annotation. */ static define<T>(): AnnotationType<T>; private _isAnnotation; } /** Marker that identifies a type of [annotation](https://codemirror.net/6/docs/ref/#state.Annotation). */ declare class AnnotationType<T> { /** Create an instance of this annotation. */ of(value: T): Annotation<T>; } interface StateEffectSpec<Value> { /** Provides a way to map an effect like this through a position mapping. When not given, the effects will simply not be mapped. When the function returns `undefined`, that means the mapping deletes the effect. */ map?: (value: Value, mapping: ChangeDesc) => Value | undefined; } /** Representation of a type of state effect. Defined with [`StateEffect.define`](https://codemirror.net/6/docs/ref/#state.StateEffect^define). */ declare class StateEffectType<Value> { /** @internal */ readonly map: (value: any, mapping: ChangeDesc) => any | undefined; /** Create a [state effect](https://codemirror.net/6/docs/ref/#state.StateEffect) instance of this type. */ of(value: Value): StateEffect<Value>; } /** State effects can be used to represent additional effects associated with a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction.effects). They are often useful to model changes to custom [state fields](https://codemirror.net/6/docs/ref/#state.StateField), when those changes aren't implicit in document or selection changes. */ declare class StateEffect<Value> { /** The value of this effect. */ readonly value: Value; /** Map this effect through a position mapping. Will return `undefined` when that ends up deleting the effect. */ map(mapping: ChangeDesc): StateEffect<Value> | undefined; /** Tells you whether this effect object is of a given [type](https://codemirror.net/6/docs/ref/#state.StateEffectType). */ is<T>(type: StateEffectType<T>): this is StateEffect<T>; /** Define a new effect type. The type parameter indicates the type of values that his effect holds. It should be a type that doesn't include `undefined`, since that is used in [mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is removed. */ static define<Value = null>(spec?: StateEffectSpec<Value>): StateEffectType<Value>; /** Map an array of effects through a change set. */ static mapEffects(effects: readonly StateEffect<any>[], mapping: ChangeDesc): readonly StateEffect<any>[]; /** This effect can be used to reconfigure the root extensions of the editor. Doing this will discard any extensions [appended](https://codemirror.net/6/docs/ref/#state.StateEffect^appendConfig), but does not reset the content of [reconfigured](https://codemirror.net/6/docs/ref/#state.Compartment.reconfigure) compartments. */ static reconfigure: StateEffectType<Extension>; /** Append extensions to the top-level configuration of the editor. */ static appendConfig: StateEffectType<Extension>; } /** Describes a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction) when calling the [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update) method. */ interface TransactionSpec { /** The changes to the document made by this transaction. */ changes?: ChangeSpec; /** When set, this transaction explicitly updates the selection. Offsets in this selection should refer to the document as it is _after_ the transaction. */ selection?: EditorSelection | { anchor: number; head?: number; }; /** Attach [state effects](https://codemirror.net/6/docs/ref/#state.StateEffect) to this transaction. Again, when they contain positions and this same spec makes changes, those positions should refer to positions in the updated document. */ effects?: StateEffect<any> | readonly StateEffect<any>[]; /** Set [annotations](https://codemirror.net/6/docs/ref/#state.Annotation) for this transaction. */ annotations?: Annotation<any> | readonly Annotation<any>[]; /** Shorthand for `annotations:` [`Transaction.userEvent`](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent)`.of(...)`. */ userEvent?: string; /** When set to `true`, the transaction is marked as needing to scroll the current selection into view. */ scrollIntoView?: boolean; /** By default, transactions can be modified by [change filters](https://codemirror.net/6/docs/ref/#state.EditorState^changeFilter) and [transaction filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter). You can set this to `false` to disable that. This can be necessary for transactions that, for example, include annotations that must be kept consistent with their changes. */ filter?: boolean; /** Normally, when multiple specs are combined (for example by [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update)), the positions in `changes` are taken to refer to the document positions in the initial document. When a spec has `sequental` set to true, its positions will be taken to refer to the document created by the specs before it instead. */ sequential?: boolean; } /** Changes to the editor state are grouped into transactions. Typically, a user action creates a single transaction, which may contain any number of document changes, may change the selection, or have other effects. Create a transaction by calling [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update), or immediately dispatch one by calling [`EditorView.dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch). */ declare class Transaction { /** The state from which the transaction starts. */ readonly startState: EditorState; /** The document changes made by this transaction. */ readonly changes: ChangeSet; /** The selection set by this transaction, or undefined if it doesn't explicitly set a selection. */ readonly selection: EditorSelection | undefined; /** The effects added to the transaction. */ readonly effects: readonly StateEffect<any>[]; /** Whether the selection should be scrolled into view after this transaction is dispatched. */ readonly scrollIntoView: boolean; private constructor(); /** The new document produced by the transaction. Contrary to [`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't force the entire new state to be computed right away, so it is recommended that [transaction filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) use this getter when they need to look at the new document. */ get newDoc(): Text; /** The new selection produced by the transaction. If [`this.selection`](https://codemirror.net/6/docs/ref/#state.Transaction.selection) is undefined, this will [map](https://codemirror.net/6/docs/ref/#state.EditorSelection.map) the start state's current selection through the changes made by the transaction. */ get newSelection(): EditorSelection; /** The new state created by the transaction. Computed on demand (but retained for subsequent access), so it is recommended not to access it in [transaction filters](https://codemirror.net/6/docs/ref/#state.EditorState^transactionFilter) when possible. */ get state(): EditorState; /** Get the value of the given annotation type, if any. */ annotation<T>(type: AnnotationType<T>): T | undefined; /** Indicates whether the transaction changed the document. */ get docChanged(): boolean; /** Indicates whether this transaction reconfigures the state (through a [configuration compartment](https://codemirror.net/6/docs/ref/#state.Compartment) or with a top-level configuration [effect](https://codemirror.net/6/docs/ref/#state.StateEffect^reconfigure). */ get reconfigured(): boolean; /** Returns true if the transaction has a [user event](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent) annotation that is equal to or more specific than `event`. For example, if the transaction has `"select.pointer"` as user event, `"select"` and `"select.pointer"` will match it. */ isUserEvent(event: string): boolean; /** Annotation used to store transaction timestamps. Automatically added to every transaction, holding `Date.now()`. */ static time: AnnotationType<number>; /** Annotation used to associate a transaction with a user interface event. Holds a string identifying the event, using a dot-separated format to support attaching more specific information. The events used by the core libraries are: - `"input"` when content is entered - `"input.type"` for typed input - `"input.type.compose"` for composition - `"input.paste"` for pasted input - `"input.drop"` when adding content with drag-and-drop - `"input.complete"` when autocompleting - `"delete"` when the user deletes content - `"delete.selection"` when deleting the selection - `"delete.forward"` when deleting forward from the selection - `"delete.backward"` when deleting backward from the selection - `"delete.cut"` when cutting to the clipboard - `"move"` when content is moved - `"move.drop"` when content is moved within the editor through drag-and-drop - `"select"` when explicitly changing the selection - `"select.pointer"` when selecting with a mouse or other pointing device - `"undo"` and `"redo"` for history actions Use [`isUserEvent`](https://codemirror.net/6/docs/ref/#state.Transaction.isUserEvent) to check whether the annotation matches a given event. */ static userEvent: AnnotationType<string>; /** Annotation indicating whether a transaction should be added to the undo history or not. */ static addToHistory: AnnotationType<boolean>; /** Annotation indicating (when present and true) that a transaction represents a change made by some other actor, not the user. This is used, for example, to tag other people's changes in collaborative editing. */ static remote: AnnotationType<boolean>; } /** The categories produced by a [character categorizer](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer). These are used do things like selecting by word. */ declare enum CharCategory { /** Word characters. */ Word = 0, /** Whitespace. */ Space = 1, /** Anything else. */ Other = 2 } /** Options passed when [creating](https://codemirror.net/6/docs/ref/#state.EditorState^create) an editor state. */ interface EditorStateConfig { /** The initial document. Defaults to an empty document. Can be provided either as a plain string (which will be split into lines according to the value of the [`lineSeparator` facet](https://codemirror.net/6/docs/ref/#state.EditorState^lineSeparator)), or an instance of the [`Text`](https://codemirror.net/6/docs/ref/#state.Text) class (which is what the state will use to represent the document). */ doc?: string | Text; /** The starting selection. Defaults to a cursor at the very start of the document. */ selection?: EditorSelection | { anchor: number; head?: number; }; /** [Extension(s)](https://codemirror.net/6/docs/ref/#state.Extension) to associate with this state. */ extensions?: Extension; } /** The editor state class is a persistent (immutable) data structure. To update a state, you [create](https://codemirror.net/6/docs/ref/#state.EditorState.update) a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction), which produces a _new_ state instance, without modifying the original object. As such, _never_ mutate properties of a state directly. That'll just break things. */ declare class EditorState { /** The current document. */ readonly doc: Text; /** The current selection. */ readonly selection: EditorSelection; private constructor(); /** Retrieve the value of a [state field](https://codemirror.net/6/docs/ref/#state.StateField). Throws an error when the state doesn't have that field, unless you pass `false` as second parameter. */ field<T>(field: StateField<T>): T; field<T>(field: StateField<T>, require: false): T | undefined; /** Create a [transaction](https://codemirror.net/6/docs/ref/#state.Transaction) that updates this state. Any number of [transaction specs](https://codemirror.net/6/docs/ref/#state.TransactionSpec) can be passed. Unless [`sequential`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.sequential) is set, the [changes](https://codemirror.net/6/docs/ref/#state.TransactionSpec.changes) (if any) of each spec are assumed to start in the _current_ document (not the document produced by previous specs), and its [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) and [effects](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) are assumed to refer to the document created by its _own_ changes. The resulting transaction contains the combined effect of all the different specs. For [selection](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection), later specs take precedence over earlier ones. */ update(...specs: readonly TransactionSpec[]): Transaction; /** Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that replaces every selection range with the given content. */ replaceSelection(text: string | Text): TransactionSpec; /** Create a set of changes and a new selection by running the given function for each range in the active selection. The function can return an optional set of changes (in the coordinate space of the start document), plus an updated range (in the coordinate space of the document produced by the call's own changes). This method will merge all the changes and ranges into a single changeset and selection, and return it as a [transaction spec](https://codemi