1import * as _codemirror_state from '@codemirror/state';
2import { RangeSet, RangeValue, Range, EditorState, Extension, Transaction, ChangeSet, SelectionRange, ChangeDesc, EditorSelection, EditorStateConfig, StateEffect, TransactionSpec, Line, Facet, StateField } from '@codemirror/state';
3import { StyleModule, StyleSpec } from 'style-mod';
4
5/**
6Used to indicate [text direction](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection).
7*/
8declare enum Direction {
9 /**
10 Left-to-right.
11 */
12 LTR = 0,
13 /**
14 Right-to-left.
15 */
16 RTL = 1
17}
18/**
19Represents a contiguous range of text that has a single direction
20(as in left-to-right or right-to-left).
21*/
22declare class BidiSpan {
23 /**
24 The start of the span (relative to the start of the line).
25 */
26 readonly from: number;
27 /**
28 The end of the span.
29 */
30 readonly to: number;
31 /**
32 The ["bidi
33 level"](https://unicode.org/reports/tr9/#Basic_Display_Algorithm)
34 of the span (in this context, 0 means
35 left-to-right, 1 means right-to-left, 2 means left-to-right
36 number inside right-to-left text).
37 */
38 readonly level: number;
39 /**
40 The direction of this span.
41 */
42 get dir(): Direction;
43}
44
45type Attrs = {
46 [name: string]: string;
47};
48
49/**
50Basic rectangle type.
51*/
52interface Rect {
53 readonly left: number;
54 readonly right: number;
55 readonly top: number;
56 readonly bottom: number;
57}
58type ScrollStrategy = "nearest" | "start" | "end" | "center";
59
60interface MarkDecorationSpec {
61 /**
62 Whether the mark covers its start and end position or not. This
63 influences whether content inserted at those positions becomes
64 part of the mark. Defaults to false.
65 */
66 inclusive?: boolean;
67 /**
68 Specify whether the start position of the marked range should be
69 inclusive. Overrides `inclusive`, when both are present.
70 */
71 inclusiveStart?: boolean;
72 /**
73 Whether the end should be inclusive.
74 */
75 inclusiveEnd?: boolean;
76 /**
77 Add attributes to the DOM elements that hold the text in the
78 marked range.
79 */
80 attributes?: {
81 [key: string]: string;
82 };
83 /**
84 Shorthand for `{attributes: {class: value}}`.
85 */
86 class?: string;
87 /**
88 Add a wrapping element around the text in the marked range. Note
89 that there will not necessarily be a single element covering the
90 entire range—other decorations with lower precedence might split
91 this one if they partially overlap it, and line breaks always
92 end decoration elements.
93 */
94 tagName?: string;
95 /**
96 When using sets of decorations in
97 [`bidiIsolatedRanges`](https://codemirror.net/6/docs/ref/##view.EditorView^bidiIsolatedRanges),
98 this property provides the direction of the isolates. When null
99 or not given, it indicates the range has `dir=auto`, and its
100 direction should be derived from the first strong directional
101 character in it.
102 */
103 bidiIsolate?: Direction | null;
104 /**
105 Decoration specs allow extra properties, which can be retrieved
106 through the decoration's [`spec`](https://codemirror.net/6/docs/ref/#view.Decoration.spec)
107 property.
108 */
109 [other: string]: any;
110}
111interface WidgetDecorationSpec {
112 /**
113 The type of widget to draw here.
114 */
115 widget: WidgetType;
116 /**
117 Which side of the given position the widget is on. When this is
118 positive, the widget will be drawn after the cursor if the
119 cursor is on the same position. Otherwise, it'll be drawn before
120 it. When multiple widgets sit at the same position, their `side`
121 values will determine their ordering—those with a lower value
122 come first. Defaults to 0. May not be more than 10000 or less
123 than -10000.
124 */
125 side?: number;
126 /**
127 By default, to avoid unintended mixing of block and inline
128 widgets, block widgets with a positive `side` are always drawn
129 after all inline widgets at that position, and those with a
130 non-positive side before inline widgets. Setting this option to
131 `true` for a block widget will turn this off and cause it to be
132 rendered between the inline widgets, ordered by `side`.
133 */
134 inlineOrder?: boolean;
135 /**
136 Determines whether this is a block widgets, which will be drawn
137 between lines, or an inline widget (the default) which is drawn
138 between the surrounding text.
139
140 Note that block-level decorations should not have vertical
141 margins, and if you dynamically change their height, you should
142 make sure to call
143 [`requestMeasure`](https://codemirror.net/6/docs/ref/#view.EditorView.requestMeasure), so that the
144 editor can update its information about its vertical layout.
145 */
146 block?: boolean;
147 /**
148 Other properties are allowed.
149 */
150 [other: string]: any;
151}
152interface ReplaceDecorationSpec {
153 /**
154 An optional widget to drawn in the place of the replaced
155 content.
156 */
157 widget?: WidgetType;
158 /**
159 Whether this range covers the positions on its sides. This
160 influences whether new content becomes part of the range and
161 whether the cursor can be drawn on its sides. Defaults to false
162 for inline replacements, and true for block replacements.
163 */
164 inclusive?: boolean;
165 /**
166 Set inclusivity at the start.
167 */
168 inclusiveStart?: boolean;
169 /**
170 Set inclusivity at the end.
171 */
172 inclusiveEnd?: boolean;
173 /**
174 Whether this is a block-level decoration. Defaults to false.
175 */
176 block?: boolean;
177 /**
178 Other properties are allowed.
179 */
180 [other: string]: any;
181}
182interface LineDecorationSpec {
183 /**
184 DOM attributes to add to the element wrapping the line.
185 */
186 attributes?: {
187 [key: string]: string;
188 };
189 /**
190 Shorthand for `{attributes: {class: value}}`.
191 */
192 class?: string;
193 /**
194 Other properties are allowed.
195 */
196 [other: string]: any;
197}
198/**
199Widgets added to the content are described by subclasses of this
200class. Using a description object like that makes it possible to
201delay creating of the DOM structure for a widget until it is
202needed, and to avoid redrawing widgets even if the decorations
203that define them are recreated.
204*/
205declare abstract class WidgetType {
206 /**
207 Build the DOM structure for this widget instance.
208 */
209 abstract toDOM(view: EditorView): HTMLElement;
210 /**
211 Compare this instance to another instance of the same type.
212 (TypeScript can't express this, but only instances of the same
213 specific class will be passed to this method.) This is used to
214 avoid redrawing widgets when they are replaced by a new
215 decoration of the same type. The default implementation just
216 returns `false`, which will cause new instances of the widget to
217 always be redrawn.
218 */
219 eq(widget: WidgetType): boolean;
220 /**
221 Update a DOM element created by a widget of the same type (but
222 different, non-`eq` content) to reflect this widget. May return
223 true to indicate that it could update, false to indicate it
224 couldn't (in which case the widget will be redrawn). The default
225 implementation just returns false.
226 */
227 updateDOM(dom: HTMLElement, view: EditorView): boolean;
228 /**
229 The estimated height this widget will have, to be used when
230 estimating the height of content that hasn't been drawn. May
231 return -1 to indicate you don't know. The default implementation
232 returns -1.
233 */
234 get estimatedHeight(): number;
235 /**
236 For inline widgets that are displayed inline (as opposed to
237 `inline-block`) and introduce line breaks (through `<br>` tags
238 or textual newlines), this must indicate the amount of line
239 breaks they introduce. Defaults to 0.
240 */
241 get lineBreaks(): number;
242 /**
243 Can be used to configure which kinds of events inside the widget
244 should be ignored by the editor. The default is to ignore all
245 events.
246 */
247 ignoreEvent(event: Event): boolean;
248 /**
249 Override the way screen coordinates for positions at/in the
250 widget are found. `pos` will be the offset into the widget, and
251 `side` the side of the position that is being queried—less than
252 zero for before, greater than zero for after, and zero for
253 directly at that position.
254 */
255 coordsAt(dom: HTMLElement, pos: number, side: number): Rect | null;
256 /**
257 This is called when the an instance of the widget is removed
258 from the editor view.
259 */
260 destroy(dom: HTMLElement): void;
261}
262/**
263A decoration set represents a collection of decorated ranges,
264organized for efficient access and mapping. See
265[`RangeSet`](https://codemirror.net/6/docs/ref/#state.RangeSet) for its methods.
266*/
267type DecorationSet = RangeSet<Decoration>;
268/**
269The different types of blocks that can occur in an editor view.
270*/
271declare enum BlockType {
272 /**
273 A line of text.
274 */
275 Text = 0,
276 /**
277 A block widget associated with the position after it.
278 */
279 WidgetBefore = 1,
280 /**
281 A block widget associated with the position before it.
282 */
283 WidgetAfter = 2,
284 /**
285 A block widget [replacing](https://codemirror.net/6/docs/ref/#view.Decoration^replace) a range of content.
286 */
287 WidgetRange = 3
288}
289/**
290A decoration provides information on how to draw or style a piece
291of content. You'll usually use it wrapped in a
292[`Range`](https://codemirror.net/6/docs/ref/#state.Range), which adds a start and end position.
293@nonabstract
294*/
295declare abstract class Decoration extends RangeValue {
296 /**
297 The config object used to create this decoration. You can
298 include additional properties in there to store metadata about
299 your decoration.
300 */
301 readonly spec: any;
302 protected constructor(
303 /**
304 @internal
305 */
306 startSide: number,
307 /**
308 @internal
309 */
310 endSide: number,
311 /**
312 @internal
313 */
314 widget: WidgetType | null,
315 /**
316 The config object used to create this decoration. You can
317 include additional properties in there to store metadata about
318 your decoration.
319 */
320 spec: any);
321 abstract eq(other: Decoration): boolean;
322 /**
323 Create a mark decoration, which influences the styling of the
324 content in its range. Nested mark decorations will cause nested
325 DOM elements to be created. Nesting order is determined by
326 precedence of the [facet](https://codemirror.net/6/docs/ref/#view.EditorView^decorations), with
327 the higher-precedence decorations creating the inner DOM nodes.
328 Such elements are split on line boundaries and on the boundaries
329 of lower-precedence decorations.
330 */
331 static mark(spec: MarkDecorationSpec): Decoration;
332 /**
333 Create a widget decoration, which displays a DOM element at the
334 given position.
335 */
336 static widget(spec: WidgetDecorationSpec): Decoration;
337 /**
338 Create a replace decoration which replaces the given range with
339 a widget, or simply hides it.
340 */
341 static replace(spec: ReplaceDecorationSpec): Decoration;
342 /**
343 Create a line decoration, which can add DOM attributes to the
344 line starting at the given position.
345 */
346 static line(spec: LineDecorationSpec): Decoration;
347 /**
348 Build a [`DecorationSet`](https://codemirror.net/6/docs/ref/#view.DecorationSet) from the given
349 decorated range or ranges. If the ranges aren't already sorted,
350 pass `true` for `sort` to make the library sort them for you.
351 */
352 static set(of: Range<Decoration> | readonly Range<Decoration>[], sort?: boolean): DecorationSet;
353 /**
354 The empty set of decorations.
355 */
356 static none: DecorationSet;
357}
358
359/**
360Command functions are used in key bindings and other types of user
361actions. Given an editor view, they check whether their effect can
362apply to the editor, and if it can, perform it as a side effect
363(which usually means [dispatching](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch) a
364transaction) and return `true`.
365*/
366type Command = (target: EditorView) => boolean;
367declare class ScrollTarget {
368 readonly range: SelectionRange;
369 readonly y: ScrollStrategy;
370 readonly x: ScrollStrategy;
371 readonly yMargin: number;
372 readonly xMargin: number;
373 readonly isSnapshot: boolean;
374 constructor(range: SelectionRange, y?: ScrollStrategy, x?: ScrollStrategy, yMargin?: number, xMargin?: number, isSnapshot?: boolean);
375 map(changes: ChangeDesc): ScrollTarget;
376 clip(state: EditorState): ScrollTarget;
377}
378/**
379Log or report an unhandled exception in client code. Should
380probably only be used by extension code that allows client code to
381provide functions, and calls those functions in a context where an
382exception can't be propagated to calling code in a reasonable way
383(for example when in an event handler).
384
385Either calls a handler registered with
386[`EditorView.exceptionSink`](https://codemirror.net/6/docs/ref/#view.EditorView^exceptionSink),
387`window.onerror`, if defined, or `console.error` (in which case
388it'll pass `context`, when given, as first argument).
389*/
390declare function logException(state: EditorState, exception: any, context?: string): void;
391/**
392This is the interface plugin objects conform to.
393*/
394interface PluginValue extends Object {
395 /**
396 Notifies the plugin of an update that happened in the view. This
397 is called _before_ the view updates its own DOM. It is
398 responsible for updating the plugin's internal state (including
399 any state that may be read by plugin fields) and _writing_ to
400 the DOM for the changes in the update. To avoid unnecessary
401 layout recomputations, it should _not_ read the DOM layout—use
402 [`requestMeasure`](https://codemirror.net/6/docs/ref/#view.EditorView.requestMeasure) to schedule
403 your code in a DOM reading phase if you need to.
404 */
405 update?(update: ViewUpdate): void;
406 /**
407 Called when the document view is updated (due to content,
408 decoration, or viewport changes). Should not try to immediately
409 start another view update. Often useful for calling
410 [`requestMeasure`](https://codemirror.net/6/docs/ref/#view.EditorView.requestMeasure).
411 */
412 docViewUpdate?(view: EditorView): void;
413 /**
414 Called when the plugin is no longer going to be used. Should
415 revert any changes the plugin made to the DOM.
416 */
417 destroy?(): void;
418}
419/**
420Provides additional information when defining a [view
421plugin](https://codemirror.net/6/docs/ref/#view.ViewPlugin).
422*/
423interface PluginSpec<V extends PluginValue> {
424 /**
425 Register the given [event
426 handlers](https://codemirror.net/6/docs/ref/#view.EditorView^domEventHandlers) for the plugin.
427 When called, these will have their `this` bound to the plugin
428 value.
429 */
430 eventHandlers?: DOMEventHandlers<V>;
431 /**
432 Registers [event observers](https://codemirror.net/6/docs/ref/#view.EditorView^domEventObservers)
433 for the plugin. Will, when called, have their `this` bound to
434 the plugin value.
435 */
436 eventObservers?: DOMEventHandlers<V>;
437 /**
438 Specify that the plugin provides additional extensions when
439 added to an editor configuration.
440 */
441 provide?: (plugin: ViewPlugin<V, any>) => Extension;
442 /**
443 Allow the plugin to provide decorations. When given, this should
444 be a function that take the plugin value and return a
445 [decoration set](https://codemirror.net/6/docs/ref/#view.DecorationSet). See also the caveat about
446 [layout-changing decorations](https://codemirror.net/6/docs/ref/#view.EditorView^decorations) that
447 depend on the view.
448 */
449 decorations?: (value: V) => DecorationSet;
450}
451/**
452View plugins associate stateful values with a view. They can
453influence the way the content is drawn, and are notified of things
454that happen in the view. They optionally take an argument, in
455which case you need to call [`of`](https://codemirror.net/6/docs/ref/#view.ViewPlugin.of) to create
456an extension for the plugin. When the argument type is undefined,
457you can use the plugin instance as an extension directly.
458*/
459declare class ViewPlugin<V extends PluginValue, Arg = undefined> {
460 /**
461 When `Arg` is undefined, instances of this class act as
462 extensions. Otherwise, you have to call `of` to create an
463 extension value.
464 */
465 extension: Arg extends undefined ? Extension : null;
466 private baseExtensions;
467 private constructor();
468 /**
469 Create an extension for this plugin with the given argument.
470 */
471 of(arg: Arg): Extension;
472 /**
473 Define a plugin from a constructor function that creates the
474 plugin's value, given an editor view.
475 */
476 static define<V extends PluginValue, Arg = undefined>(create: (view: EditorView, arg: Arg) => V, spec?: PluginSpec<V>): ViewPlugin<V, Arg>;
477 /**
478 Create a plugin for a class whose constructor takes a single
479 editor view as argument.
480 */
481 static fromClass<V extends PluginValue, Arg = undefined>(cls: {
482 new (view: EditorView, arg: Arg): V;
483 }, spec?: PluginSpec<V>): ViewPlugin<V, Arg>;
484}
485interface MeasureRequest<T> {
486 /**
487 Called in a DOM read phase to gather information that requires
488 DOM layout. Should _not_ mutate the document.
489 */
490 read(view: EditorView): T;
491 /**
492 Called in a DOM write phase to update the document. Should _not_
493 do anything that triggers DOM layout.
494 */
495 write?(measure: T, view: EditorView): void;
496 /**
497 When multiple requests with the same key are scheduled, only the
498 last one will actually be run.
499 */
500 key?: any;
501}
502type AttrSource = Attrs | ((view: EditorView) => Attrs | null);
503/**
504View [plugins](https://codemirror.net/6/docs/ref/#view.ViewPlugin) are given instances of this
505class, which describe what happened, whenever the view is updated.
506*/
507declare class ViewUpdate {
508 /**
509 The editor view that the update is associated with.
510 */
511 readonly view: EditorView;
512 /**
513 The new editor state.
514 */
515 readonly state: EditorState;
516 /**
517 The transactions involved in the update. May be empty.
518 */
519 readonly transactions: readonly Transaction[];
520 /**
521 The changes made to the document by this update.
522 */
523 readonly changes: ChangeSet;
524 /**
525 The previous editor state.
526 */
527 readonly startState: EditorState;
528 private constructor();
529 /**
530 Tells you whether the [viewport](https://codemirror.net/6/docs/ref/#view.EditorView.viewport) or
531 [visible ranges](https://codemirror.net/6/docs/ref/#view.EditorView.visibleRanges) changed in this
532 update.
533 */
534 get viewportChanged(): boolean;
535 /**
536 Returns true when
537 [`viewportChanged`](https://codemirror.net/6/docs/ref/#view.ViewUpdate.viewportChanged) is true
538 and the viewport change is not just the result of mapping it in
539 response to document changes.
540 */
541 get viewportMoved(): boolean;
542 /**
543 Indicates whether the height of a block element in the editor
544 changed in this update.
545 */
546 get heightChanged(): boolean;
547 /**
548 Returns true when the document was modified or the size of the
549 editor, or elements within the editor, changed.
550 */
551 get geometryChanged(): boolean;
552 /**
553 True when this update indicates a focus change.
554 */
555 get focusChanged(): boolean;
556 /**
557 Whether the document changed in this update.
558 */
559 get docChanged(): boolean;
560 /**
561 Whether the selection was explicitly set in this update.
562 */
563 get selectionSet(): boolean;
564}
565
566/**
567Interface that objects registered with
568[`EditorView.mouseSelectionStyle`](https://codemirror.net/6/docs/ref/#view.EditorView^mouseSelectionStyle)
569must conform to.
570*/
571interface MouseSelectionStyle {
572 /**
573 Return a new selection for the mouse gesture that starts with
574 the event that was originally given to the constructor, and ends
575 with the event passed here. In case of a plain click, those may
576 both be the `mousedown` event, in case of a drag gesture, the
577 latest `mousemove` event will be passed.
578
579 When `extend` is true, that means the new selection should, if
580 possible, extend the start selection. If `multiple` is true, the
581 new selection should be added to the original selection.
582 */
583 get: (curEvent: MouseEvent, extend: boolean, multiple: boolean) => EditorSelection;
584 /**
585 Called when the view is updated while the gesture is in
586 progress. When the document changes, it may be necessary to map
587 some data (like the original selection or start position)
588 through the changes.
589
590 This may return `true` to indicate that the `get` method should
591 get queried again after the update, because something in the
592 update could change its result. Be wary of infinite loops when
593 using this (where `get` returns a new selection, which will
594 trigger `update`, which schedules another `get` in response).
595 */
596 update: (update: ViewUpdate) => boolean | void;
597}
598type MakeSelectionStyle = (view: EditorView, event: MouseEvent) => MouseSelectionStyle | null;
599
600/**
601Record used to represent information about a block-level element
602in the editor view.
603*/
604declare class BlockInfo {
605 /**
606 The start of the element in the document.
607 */
608 readonly from: number;
609 /**
610 The length of the element.
611 */
612 readonly length: number;
613 /**
614 The top position of the element (relative to the top of the
615 document).
616 */
617 readonly top: number;
618 /**
619 Its height.
620 */
621 readonly height: number;
622 /**
623 The type of element this is. When querying lines, this may be
624 an array of all the blocks that make up the line.
625 */
626 get type(): BlockType | readonly BlockInfo[];
627 /**
628 The end of the element as a document position.
629 */
630 get to(): number;
631 /**
632 The bottom position of the element.
633 */
634 get bottom(): number;
635 /**
636 If this is a widget block, this will return the widget
637 associated with it.
638 */
639 get widget(): WidgetType | null;
640 /**
641 If this is a textblock, this holds the number of line breaks
642 that appear in widgets inside the block.
643 */
644 get widgetLineBreaks(): number;
645}
646
647/**
648The type of object given to the [`EditorView`](https://codemirror.net/6/docs/ref/#view.EditorView)
649constructor.
650*/
651interface EditorViewConfig extends EditorStateConfig {
652 /**
653 The view's initial state. If not given, a new state is created
654 by passing this configuration object to
655 [`EditorState.create`](https://codemirror.net/6/docs/ref/#state.EditorState^create), using its
656 `doc`, `selection`, and `extensions` field (if provided).
657 */
658 state?: EditorState;
659 /**
660 When given, the editor is immediately appended to the given
661 element on creation. (Otherwise, you'll have to place the view's
662 [`dom`](https://codemirror.net/6/docs/ref/#view.EditorView.dom) element in the document yourself.)
663 */
664 parent?: Element | DocumentFragment;
665 /**
666 If the view is going to be mounted in a shadow root or document
667 other than the one held by the global variable `document` (the
668 default), you should pass it here. If you provide `parent`, but
669 not this option, the editor will automatically look up a root
670 from the parent.
671 */
672 root?: Document | ShadowRoot;
673 /**
674 Pass an effect created with
675 [`EditorView.scrollIntoView`](https://codemirror.net/6/docs/ref/#view.EditorView^scrollIntoView) or
676 [`EditorView.scrollSnapshot`](https://codemirror.net/6/docs/ref/#view.EditorView.scrollSnapshot)
677 here to set an initial scroll position.
678 */
679 scrollTo?: StateEffect<any>;
680 /**
681 Override the way transactions are
682 [dispatched](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch) for this editor view.
683 Your implementation, if provided, should probably call the
684 view's [`update` method](https://codemirror.net/6/docs/ref/#view.EditorView.update).
685 */
686 dispatchTransactions?: (trs: readonly Transaction[], view: EditorView) => void;
687 /**
688 **Deprecated** single-transaction version of
689 `dispatchTransactions`. Will force transactions to be dispatched
690 one at a time when used.
691 */
692 dispatch?: (tr: Transaction, view: EditorView) => void;
693}
694/**
695An editor view represents the editor's user interface. It holds
696the editable DOM surface, and possibly other elements such as the
697line number gutter. It handles events and dispatches state
698transactions for editing actions.
699*/
700declare class EditorView {
701 /**
702 The current editor state.
703 */
704 get state(): EditorState;
705 /**
706 To be able to display large documents without consuming too much
707 memory or overloading the browser, CodeMirror only draws the
708 code that is visible (plus a margin around it) to the DOM. This
709 property tells you the extent of the current drawn viewport, in
710 document positions.
711 */
712 get viewport(): {
713 from: number;
714 to: number;
715 };
716 /**
717 When there are, for example, large collapsed ranges in the
718 viewport, its size can be a lot bigger than the actual visible
719 content. Thus, if you are doing something like styling the
720 content in the viewport, it is preferable to only do so for
721 these ranges, which are the subset of the viewport that is
722 actually drawn.
723 */
724 get visibleRanges(): readonly {
725 from: number;
726 to: number;
727 }[];
728 /**
729 Returns false when the editor is entirely scrolled out of view
730 or otherwise hidden.
731 */
732 get inView(): boolean;
733 /**
734 Indicates whether the user is currently composing text via
735 [IME](https://en.wikipedia.org/wiki/Input_method), and at least
736 one change has been made in the current composition.
737 */
738 get composing(): boolean;
739 /**
740 Indicates whether the user is currently in composing state. Note
741 that on some platforms, like Android, this will be the case a
742 lot, since just putting the cursor on a word starts a
743 composition there.
744 */
745 get compositionStarted(): boolean;
746 private dispatchTransactions;
747 private _root;
748 /**
749 The document or shadow root that the view lives in.
750 */
751 get root(): DocumentOrShadowRoot;
752 /**
753 The DOM element that wraps the entire editor view.
754 */
755 readonly dom: HTMLElement;
756 /**
757 The DOM element that can be styled to scroll. (Note that it may
758 not have been, so you can't assume this is scrollable.)
759 */
760 readonly scrollDOM: HTMLElement;
761 /**
762 The editable DOM element holding the editor content. You should
763 not, usually, interact with this content directly though the
764 DOM, since the editor will immediately undo most of the changes
765 you make. Instead, [dispatch](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch)
766 [transactions](https://codemirror.net/6/docs/ref/#state.Transaction) to modify content, and
767 [decorations](https://codemirror.net/6/docs/ref/#view.Decoration) to style it.
768 */
769 readonly contentDOM: HTMLElement;
770 private announceDOM;
771 private plugins;
772 private pluginMap;
773 private editorAttrs;
774 private contentAttrs;
775 private styleModules;
776 private bidiCache;
777 private destroyed;
778 /**
779 Construct a new view. You'll want to either provide a `parent`
780 option, or put `view.dom` into your document after creating a
781 view, so that the user can see the editor.
782 */
783 constructor(config?: EditorViewConfig);
784 /**
785 All regular editor state updates should go through this. It
786 takes a transaction, array of transactions, or transaction spec
787 and updates the view to show the new state produced by that
788 transaction. Its implementation can be overridden with an
789 [option](https://codemirror.net/6/docs/ref/#view.EditorView.constructor^config.dispatchTransactions).
790 This function is bound to the view instance, so it does not have
791 to be called as a method.
792
793 Note that when multiple `TransactionSpec` arguments are
794 provided, these define a single transaction (the specs will be
795 merged), not a sequence of transactions.
796 */
797 dispatch(tr: Transaction): void;
798 dispatch(trs: readonly Transaction[]): void;
799 dispatch(...specs: TransactionSpec[]): void;
800 /**
801 Update the view for the given array of transactions. This will
802 update the visible document and selection to match the state
803 produced by the transactions, and notify view plugins of the
804 change. You should usually call
805 [`dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch) instead, which uses this
806 as a primitive.
807 */
808 update(transactions: readonly Transaction[]): void;
809 /**
810 Reset the view to the given state. (This will cause the entire
811 document to be redrawn and all view plugins to be reinitialized,
812 so you should probably only use it when the new state isn't
813 derived from the old state. Otherwise, use
814 [`dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch) instead.)
815 */
816 setState(newState: EditorState): void;
817 private updatePlugins;
818 private docViewUpdate;
819 /**
820 Get the CSS classes for the currently active editor themes.
821 */
822 get themeClasses(): string;
823 private updateAttrs;
824 private showAnnouncements;
825 private mountStyles;
826 private readMeasured;
827 /**
828 Schedule a layout measurement, optionally providing callbacks to
829 do custom DOM measuring followed by a DOM write phase. Using
830 this is preferable reading DOM layout directly from, for
831 example, an event handler, because it'll make sure measuring and
832 drawing done by other components is synchronized, avoiding
833 unnecessary DOM layout computations.
834 */
835 requestMeasure<T>(request?: MeasureRequest<T>): void;
836 /**
837 Get the value of a specific plugin, if present. Note that
838 plugins that crash can be dropped from a view, so even when you
839 know you registered a given plugin, it is recommended to check
840 the return value of this method.
841 */
842 plugin<T extends PluginValue>(plugin: ViewPlugin<T, any>): T | null;
843 /**
844 The top position of the document, in screen coordinates. This
845 may be negative when the editor is scrolled down. Points
846 directly to the top of the first line, not above the padding.
847 */
848 get documentTop(): number;
849 /**
850 Reports the padding above and below the document.
851 */
852 get documentPadding(): {
853 top: number;
854 bottom: number;
855 };
856 /**
857 If the editor is transformed with CSS, this provides the scale
858 along the X axis. Otherwise, it will just be 1. Note that
859 transforms other than translation and scaling are not supported.
860 */
861 get scaleX(): number;
862 /**
863 Provide the CSS transformed scale along the Y axis.
864 */
865 get scaleY(): number;
866 /**
867 Find the text line or block widget at the given vertical
868 position (which is interpreted as relative to the [top of the
869 document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop)).
870 */
871 elementAtHeight(height: number): BlockInfo;
872 /**
873 Find the line block (see
874 [`lineBlockAt`](https://codemirror.net/6/docs/ref/#view.EditorView.lineBlockAt)) at the given
875 height, again interpreted relative to the [top of the
876 document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop).
877 */
878 lineBlockAtHeight(height: number): BlockInfo;
879 /**
880 Get the extent and vertical position of all [line
881 blocks](https://codemirror.net/6/docs/ref/#view.EditorView.lineBlockAt) in the viewport. Positions
882 are relative to the [top of the
883 document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop);
884 */
885 get viewportLineBlocks(): BlockInfo[];
886 /**
887 Find the line block around the given document position. A line
888 block is a range delimited on both sides by either a
889 non-[hidden](https://codemirror.net/6/docs/ref/#view.Decoration^replace) line break, or the
890 start/end of the document. It will usually just hold a line of
891 text, but may be broken into multiple textblocks by block
892 widgets.
893 */
894 lineBlockAt(pos: number): BlockInfo;
895 /**
896 The editor's total content height.
897 */
898 get contentHeight(): number;
899 /**
900 Move a cursor position by [grapheme
901 cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak). `forward` determines whether
902 the motion is away from the line start, or towards it. In
903 bidirectional text, the line is traversed in visual order, using
904 the editor's [text direction](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection).
905 When the start position was the last one on the line, the
906 returned position will be across the line break. If there is no
907 further line, the original position is returned.
908
909 By default, this method moves over a single cluster. The
910 optional `by` argument can be used to move across more. It will
911 be called with the first cluster as argument, and should return
912 a predicate that determines, for each subsequent cluster,
913 whether it should also be moved over.
914 */
915 moveByChar(start: SelectionRange, forward: boolean, by?: (initial: string) => (next: string) => boolean): SelectionRange;
916 /**
917 Move a cursor position across the next group of either
918 [letters](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) or non-letter
919 non-whitespace characters.
920 */
921 moveByGroup(start: SelectionRange, forward: boolean): SelectionRange;
922 /**
923 Get the cursor position visually at the start or end of a line.
924 Note that this may differ from the _logical_ position at its
925 start or end (which is simply at `line.from`/`line.to`) if text
926 at the start or end goes against the line's base text direction.
927 */
928 visualLineSide(line: Line, end: boolean): SelectionRange;
929 /**
930 Move to the next line boundary in the given direction. If
931 `includeWrap` is true, line wrapping is on, and there is a
932 further wrap point on the current line, the wrap point will be
933 returned. Otherwise this function will return the start or end
934 of the line.
935 */
936 moveToLineBoundary(start: SelectionRange, forward: boolean, includeWrap?: boolean): SelectionRange;
937 /**
938 Move a cursor position vertically. When `distance` isn't given,
939 it defaults to moving to the next line (including wrapped
940 lines). Otherwise, `distance` should provide a positive distance
941 in pixels.
942
943 When `start` has a
944 [`goalColumn`](https://codemirror.net/6/docs/ref/#state.SelectionRange.goalColumn), the vertical
945 motion will use that as a target horizontal position. Otherwise,
946 the cursor's own horizontal position is used. The returned
947 cursor will have its goal column set to whichever column was
948 used.
949 */
950 moveVertically(start: SelectionRange, forward: boolean, distance?: number): SelectionRange;
951 /**
952 Find the DOM parent node and offset (child offset if `node` is
953 an element, character offset when it is a text node) at the
954 given document position.
955
956 Note that for positions that aren't currently in
957 `visibleRanges`, the resulting DOM position isn't necessarily
958 meaningful (it may just point before or after a placeholder
959 element).
960 */
961 domAtPos(pos: number): {
962 node: Node;
963 offset: number;
964 };
965 /**
966 Find the document position at the given DOM node. Can be useful
967 for associating positions with DOM events. Will raise an error
968 when `node` isn't part of the editor content.
969 */
970 posAtDOM(node: Node, offset?: number): number;
971 /**
972 Get the document position at the given screen coordinates. For
973 positions not covered by the visible viewport's DOM structure,
974 this will return null, unless `false` is passed as second
975 argument, in which case it'll return an estimated position that
976 would be near the coordinates if it were rendered.
977 */
978 posAtCoords(coords: {
979 x: number;
980 y: number;
981 }, precise: false): number;
982 posAtCoords(coords: {
983 x: number;
984 y: number;
985 }): number | null;
986 /**
987 Get the screen coordinates at the given document position.
988 `side` determines whether the coordinates are based on the
989 element before (-1) or after (1) the position (if no element is
990 available on the given side, the method will transparently use
991 another strategy to get reasonable coordinates).
992 */
993 coordsAtPos(pos: number, side?: -1 | 1): Rect | null;
994 /**
995 Return the rectangle around a given character. If `pos` does not
996 point in front of a character that is in the viewport and
997 rendered (i.e. not replaced, not a line break), this will return
998 null. For space characters that are a line wrap point, this will
999 return the position before the line break.
1000 */
1001 coordsForChar(pos: number): Rect | null;
1002 /**
1003 The default width of a character in the editor. May not
1004 accurately reflect the width of all characters (given variable
1005 width fonts or styling of invididual ranges).
1006 */
1007 get defaultCharacterWidth(): number;
1008 /**
1009 The default height of a line in the editor. May not be accurate
1010 for all lines.
1011 */
1012 get defaultLineHeight(): number;
1013 /**
1014 The text direction
1015 ([`direction`](https://developer.mozilla.org/en-US/docs/Web/CSS/direction)
1016 CSS property) of the editor's content element.
1017 */
1018 get textDirection(): Direction;
1019 /**
1020 Find the text direction of the block at the given position, as
1021 assigned by CSS. If
1022 [`perLineTextDirection`](https://codemirror.net/6/docs/ref/#view.EditorView^perLineTextDirection)
1023 isn't enabled, or the given position is outside of the viewport,
1024 this will always return the same as
1025 [`textDirection`](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection). Note that
1026 this may trigger a DOM layout.
1027 */
1028 textDirectionAt(pos: number): Direction;
1029 /**
1030 Whether this editor [wraps lines](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping)
1031 (as determined by the
1032 [`white-space`](https://developer.mozilla.org/en-US/docs/Web/CSS/white-space)
1033 CSS property of its content element).
1034 */
1035 get lineWrapping(): boolean;
1036 /**
1037 Returns the bidirectional text structure of the given line
1038 (which should be in the current document) as an array of span
1039 objects. The order of these spans matches the [text
1040 direction](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection)—if that is
1041 left-to-right, the leftmost spans come first, otherwise the
1042 rightmost spans come first.
1043 */
1044 bidiSpans(line: Line): readonly BidiSpan[];
1045 /**
1046 Check whether the editor has focus.
1047 */
1048 get hasFocus(): boolean;
1049 /**
1050 Put focus on the editor.
1051 */
1052 focus(): void;
1053 /**
1054 Update the [root](https://codemirror.net/6/docs/ref/##view.EditorViewConfig.root) in which the editor lives. This is only
1055 necessary when moving the editor's existing DOM to a new window or shadow root.
1056 */
1057 setRoot(root: Document | ShadowRoot): void;
1058 /**
1059 Clean up this editor view, removing its element from the
1060 document, unregistering event handlers, and notifying
1061 plugins. The view instance can no longer be used after
1062 calling this.
1063 */
1064 destroy(): void;
1065 /**
1066 Returns an effect that can be
1067 [added](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) to a transaction to
1068 cause it to scroll the given position or range into view.
1069 */
1070 static scrollIntoView(pos: number | SelectionRange, options?: {
1071 /**
1072 By default (`"nearest"`) the position will be vertically
1073 scrolled only the minimal amount required to move the given
1074 position into view. You can set this to `"start"` to move it
1075 to the top of the view, `"end"` to move it to the bottom, or
1076 `"center"` to move it to the center.
1077 */
1078 y?: ScrollStrategy;
1079 /**
1080 Effect similar to
1081 [`y`](https://codemirror.net/6/docs/ref/#view.EditorView^scrollIntoView^options.y), but for the
1082 horizontal scroll position.
1083 */
1084 x?: ScrollStrategy;
1085 /**
1086 Extra vertical distance to add when moving something into
1087 view. Not used with the `"center"` strategy. Defaults to 5.
1088 Must be less than the height of the editor.
1089 */
1090 yMargin?: number;
1091 /**
1092 Extra horizontal distance to add. Not used with the `"center"`
1093 strategy. Defaults to 5. Must be less than the width of the
1094 editor.
1095 */
1096 xMargin?: number;
1097 }): StateEffect<unknown>;
1098 /**
1099 Return an effect that resets the editor to its current (at the
1100 time this method was called) scroll position. Note that this
1101 only affects the editor's own scrollable element, not parents.
1102 See also
1103 [`EditorViewConfig.scrollTo`](https://codemirror.net/6/docs/ref/#view.EditorViewConfig.scrollTo).
1104
1105 The effect should be used with a document identical to the one
1106 it was created for. Failing to do so is not an error, but may
1107 not scroll to the expected position. You can
1108 [map](https://codemirror.net/6/docs/ref/#state.StateEffect.map) the effect to account for changes.
1109 */
1110 scrollSnapshot(): StateEffect<ScrollTarget>;
1111 /**
1112 Enable or disable tab-focus mode, which disables key bindings
1113 for Tab and Shift-Tab, letting the browser's default
1114 focus-changing behavior go through instead. This is useful to
1115 prevent trapping keyboard users in your editor.
1116
1117 Without argument, this toggles the mode. With a boolean, it
1118 enables (true) or disables it (false). Given a number, it
1119 temporarily enables the mode until that number of milliseconds
1120 have passed or another non-Tab key is pressed.
1121 */
1122 setTabFocusMode(to?: boolean | number): void;
1123 /**
1124 Facet to add a [style
1125 module](https://github.com/marijnh/style-mod#documentation) to
1126 an editor view. The view will ensure that the module is
1127 mounted in its [document
1128 root](https://codemirror.net/6/docs/ref/#view.EditorView.constructor^config.root).
1129 */
1130 static styleModule: Facet<StyleModule, readonly StyleModule[]>;
1131 /**
1132 Returns an extension that can be used to add DOM event handlers.
1133 The value should be an object mapping event names to handler
1134 functions. For any given event, such functions are ordered by
1135 extension precedence, and the first handler to return true will
1136 be assumed to have handled that event, and no other handlers or
1137 built-in behavior will be activated for it. These are registered
1138 on the [content element](https://codemirror.net/6/docs/ref/#view.EditorView.contentDOM), except
1139 for `scroll` handlers, which will be called any time the
1140 editor's [scroll element](https://codemirror.net/6/docs/ref/#view.EditorView.scrollDOM) or one of
1141 its parent nodes is scrolled.
1142 */
1143 static domEventHandlers(handlers: DOMEventHandlers<any>): Extension;
1144 /**
1145 Create an extension that registers DOM event observers. Contrary
1146 to event [handlers](https://codemirror.net/6/docs/ref/#view.EditorView^domEventHandlers),
1147 observers can't be prevented from running by a higher-precedence
1148 handler returning true. They also don't prevent other handlers
1149 and observers from running when they return true, and should not
1150 call `preventDefault`.
1151 */
1152 static domEventObservers(observers: DOMEventHandlers<any>): Extension;
1153 /**
1154 An input handler can override the way changes to the editable
1155 DOM content are handled. Handlers are passed the document
1156 positions between which the change was found, and the new
1157 content. When one returns true, no further input handlers are
1158 called and the default behavior is prevented.
1159
1160 The `insert` argument can be used to get the default transaction
1161 that would be applied for this input. This can be useful when
1162 dispatching the custom behavior as a separate transaction.
1163 */
1164 static inputHandler: Facet<(view: EditorView, from: number, to: number, text: string, insert: () => Transaction) => boolean, readonly ((view: EditorView, from: number, to: number, text: string, insert: () => Transaction) => boolean)[]>;
1165 /**
1166 Functions provided in this facet will be used to transform text
1167 pasted or dropped into the editor.
1168 */
1169 static clipboardInputFilter: Facet<(text: string, state: EditorState) => string, readonly ((text: string, state: EditorState) => string)[]>;
1170 /**
1171 Transform text copied or dragged from the editor.
1172 */
1173 static clipboardOutputFilter: Facet<(text: string, state: EditorState) => string, readonly ((text: string, state: EditorState) => string)[]>;
1174 /**
1175 Scroll handlers can override how things are scrolled into view.
1176 If they return `true`, no further handling happens for the
1177 scrolling. If they return false, the default scroll behavior is
1178 applied. Scroll handlers should never initiate editor updates.
1179 */
1180 static scrollHandler: Facet<(view: EditorView, range: SelectionRange, options: {
1181 x: ScrollStrategy;
1182 y: ScrollStrategy;
1183 xMargin: number;
1184 yMargin: number;
1185 }) => boolean, readonly ((view: EditorView, range: SelectionRange, options: {
1186 x: ScrollStrategy;
1187 y: ScrollStrategy;
1188 xMargin: number;
1189 yMargin: number;
1190 }) => boolean)[]>;
1191 /**
1192 This facet can be used to provide functions that create effects
1193 to be dispatched when the editor's focus state changes.
1194 */
1195 static focusChangeEffect: Facet<(state: EditorState, focusing: boolean) => StateEffect<any> | null, readonly ((state: EditorState, focusing: boolean) => StateEffect<any> | null)[]>;
1196 /**
1197 By default, the editor assumes all its content has the same
1198 [text direction](https://codemirror.net/6/docs/ref/#view.Direction). Configure this with a `true`
1199 value to make it read the text direction of every (rendered)
1200 line separately.
1201 */
1202 static perLineTextDirection: Facet<boolean, boolean>;
1203 /**
1204 Allows you to provide a function that should be called when the
1205 library catches an exception from an extension (mostly from view
1206 plugins, but may be used by other extensions to route exceptions
1207 from user-code-provided callbacks). This is mostly useful for
1208 debugging and logging. See [`logException`](https://codemirror.net/6/docs/ref/#view.logException).
1209 */
1210 static exceptionSink: Facet<(exception: any) => void, readonly ((exception: any) => void)[]>;
1211 /**
1212 A facet that can be used to register a function to be called
1213 every time the view updates.
1214 */
1215 static updateListener: Facet<(update: ViewUpdate) => void, readonly ((update: ViewUpdate) => void)[]>;
1216 /**
1217 Facet that controls whether the editor content DOM is editable.
1218 When its highest-precedence value is `false`, the element will
1219 not have its `contenteditable` attribute set. (Note that this
1220 doesn't affect API calls that change the editor content, even
1221 when those are bound to keys or buttons. See the
1222 [`readOnly`](https://codemirror.net/6/docs/ref/#state.EditorState.readOnly) facet for that.)
1223 */
1224 static editable: Facet<boolean, boolean>;
1225 /**
1226 Allows you to influence the way mouse selection happens. The
1227 functions in this facet will be called for a `mousedown` event
1228 on the editor, and can return an object that overrides the way a
1229 selection is computed from that mouse click or drag.
1230 */
1231 static mouseSelectionStyle: Facet<MakeSelectionStyle, readonly MakeSelectionStyle[]>;
1232 /**
1233 Facet used to configure whether a given selection drag event
1234 should move or copy the selection. The given predicate will be
1235 called with the `mousedown` event, and can return `true` when
1236 the drag should move the content.
1237 */
1238 static dragMovesSelection: Facet<(event: MouseEvent) => boolean, readonly ((event: MouseEvent) => boolean)[]>;
1239 /**
1240 Facet used to configure whether a given selecting click adds a
1241 new range to the existing selection or replaces it entirely. The
1242 default behavior is to check `event.metaKey` on macOS, and
1243 `event.ctrlKey` elsewhere.
1244 */
1245 static clickAddsSelectionRange: Facet<(event: MouseEvent) => boolean, readonly ((event: MouseEvent) => boolean)[]>;
1246 /**
1247 A facet that determines which [decorations](https://codemirror.net/6/docs/ref/#view.Decoration)
1248 are shown in the view. Decorations can be provided in two
1249 ways—directly, or via a function that takes an editor view.
1250
1251 Only decoration sets provided directly are allowed to influence
1252 the editor's vertical layout structure. The ones provided as
1253 functions are called _after_ the new viewport has been computed,
1254 and thus **must not** introduce block widgets or replacing
1255 decorations that cover line breaks.
1256
1257 If you want decorated ranges to behave like atomic units for
1258 cursor motion and deletion purposes, also provide the range set
1259 containing the decorations to
1260 [`EditorView.atomicRanges`](https://codemirror.net/6/docs/ref/#view.EditorView^atomicRanges).
1261 */
1262 static decorations: Facet<DecorationSet | ((view: EditorView) => DecorationSet), readonly (DecorationSet | ((view: EditorView) => DecorationSet))[]>;
1263 /**
1264 Facet that works much like
1265 [`decorations`](https://codemirror.net/6/docs/ref/#view.EditorView^decorations), but puts its
1266 inputs at the very bottom of the precedence stack, meaning mark
1267 decorations provided here will only be split by other, partially
1268 overlapping \`outerDecorations\` ranges, and wrap around all
1269 regular decorations. Use this for mark elements that should, as
1270 much as possible, remain in one piece.
1271 */
1272 static outerDecorations: Facet<DecorationSet | ((view: EditorView) => DecorationSet), readonly (DecorationSet | ((view: EditorView) => DecorationSet))[]>;
1273 /**
1274 Used to provide ranges that should be treated as atoms as far as
1275 cursor motion is concerned. This causes methods like
1276 [`moveByChar`](https://codemirror.net/6/docs/ref/#view.EditorView.moveByChar) and
1277 [`moveVertically`](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) (and the
1278 commands built on top of them) to skip across such regions when
1279 a selection endpoint would enter them. This does _not_ prevent
1280 direct programmatic [selection
1281 updates](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) from moving into such
1282 regions.
1283 */
1284 static atomicRanges: Facet<(view: EditorView) => _codemirror_state.RangeSet<any>, readonly ((view: EditorView) => _codemirror_state.RangeSet<any>)[]>;
1285 /**
1286 When range decorations add a `unicode-bidi: isolate` style, they
1287 should also include a
1288 [`bidiIsolate`](https://codemirror.net/6/docs/ref/#view.MarkDecorationSpec.bidiIsolate) property
1289 in their decoration spec, and be exposed through this facet, so
1290 that the editor can compute the proper text order. (Other values
1291 for `unicode-bidi`, except of course `normal`, are not
1292 supported.)
1293 */
1294 static bidiIsolatedRanges: Facet<DecorationSet | ((view: EditorView) => DecorationSet), readonly (DecorationSet | ((view: EditorView) => DecorationSet))[]>;
1295 /**
1296 Facet that allows extensions to provide additional scroll
1297 margins (space around the sides of the scrolling element that
1298 should be considered invisible). This can be useful when the
1299 plugin introduces elements that cover part of that element (for
1300 example a horizontally fixed gutter).
1301 */
1302 static scrollMargins: Facet<(view: EditorView) => Partial<Rect> | null, readonly ((view: EditorView) => Partial<Rect> | null)[]>;
1303 /**
1304 Create a theme extension. The first argument can be a
1305 [`style-mod`](https://github.com/marijnh/style-mod#documentation)
1306 style spec providing the styles for the theme. These will be
1307 prefixed with a generated class for the style.
1308
1309 Because the selectors will be prefixed with a scope class, rule
1310 that directly match the editor's [wrapper
1311 element](https://codemirror.net/6/docs/ref/#view.EditorView.dom)—to which the scope class will be
1312 added—need to be explicitly differentiated by adding an `&` to
1313 the selector for that element—for example
1314 `&.cm-focused`.
1315
1316 When `dark` is set to true, the theme will be marked as dark,
1317 which will cause the `&dark` rules from [base
1318 themes](https://codemirror.net/6/docs/ref/#view.EditorView^baseTheme) to be used (as opposed to
1319 `&light` when a light theme is active).
1320 */
1321 static theme(spec: {
1322 [selector: string]: StyleSpec;
1323 }, options?: {
1324 dark?: boolean;
1325 }): Extension;
1326 /**
1327 This facet records whether a dark theme is active. The extension
1328 returned by [`theme`](https://codemirror.net/6/docs/ref/#view.EditorView^theme) automatically
1329 includes an instance of this when the `dark` option is set to
1330 true.
1331 */
1332 static darkTheme: Facet<boolean, boolean>;
1333 /**
1334 Create an extension that adds styles to the base theme. Like
1335 with [`theme`](https://codemirror.net/6/docs/ref/#view.EditorView^theme), use `&` to indicate the
1336 place of the editor wrapper element when directly targeting
1337 that. You can also use `&dark` or `&light` instead to only
1338 target editors with a dark or light theme.
1339 */
1340 static baseTheme(spec: {
1341 [selector: string]: StyleSpec;
1342 }): Extension;
1343 /**
1344 Provides a Content Security Policy nonce to use when creating
1345 the style sheets for the editor. Holds the empty string when no
1346 nonce has been provided.
1347 */
1348 static cspNonce: Facet<string, string>;
1349 /**
1350 Facet that provides additional DOM attributes for the editor's
1351 editable DOM element.
1352 */
1353 static contentAttributes: Facet<AttrSource, readonly AttrSource[]>;
1354 /**
1355 Facet that provides DOM attributes for the editor's outer
1356 element.
1357 */
1358 static editorAttributes: Facet<AttrSource, readonly AttrSource[]>;
1359 /**
1360 An extension that enables line wrapping in the editor (by
1361 setting CSS `white-space` to `pre-wrap` in the content).
1362 */
1363 static lineWrapping: Extension;
1364 /**
1365 State effect used to include screen reader announcements in a
1366 transaction. These will be added to the DOM in a visually hidden
1367 element with `aria-live="polite"` set, and should be used to
1368 describe effects that are visually obvious but may not be
1369 noticed by screen reader users (such as moving to the next
1370 search match).
1371 */
1372 static announce: _codemirror_state.StateEffectType<string>;
1373 /**
1374 Retrieve an editor view instance from the view's DOM
1375 representation.
1376 */
1377 static findFromDOM(dom: HTMLElement): EditorView | null;
1378}
1379/**
1380Helper type that maps event names to event object types, or the
1381`any` type for unknown events.
1382*/
1383interface DOMEventMap extends HTMLElementEventMap {
1384 [other: string]: any;
1385}
1386/**
1387Event handlers are specified with objects like this. For event
1388types known by TypeScript, this will infer the event argument type
1389to hold the appropriate event object type. For unknown events, it
1390is inferred to `any`, and should be explicitly set if you want type
1391checking.
1392*/
1393type DOMEventHandlers<This> = {
1394 [event in keyof DOMEventMap]?: (this: This, event: DOMEventMap[event], view: EditorView) => boolean | void;
1395};
1396
1397/**
1398Key bindings associate key names with
1399[command](https://codemirror.net/6/docs/ref/#view.Command)-style functions.
1400
1401Key names may be strings like `"Shift-Ctrl-Enter"`—a key identifier
1402prefixed with zero or more modifiers. Key identifiers are based on
1403the strings that can appear in
1404[`KeyEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key).
1405Use lowercase letters to refer to letter keys (or uppercase letters
1406if you want shift to be held). You may use `"Space"` as an alias
1407for the `" "` name.
1408
1409Modifiers can be given in any order. `Shift-` (or `s-`), `Alt-` (or
1410`a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or
1411`Meta-`) are recognized.
1412
1413When a key binding contains multiple key names separated by
1414spaces, it represents a multi-stroke binding, which will fire when
1415the user presses the given keys after each other.
1416
1417You can use `Mod-` as a shorthand for `Cmd-` on Mac and `Ctrl-` on
1418other platforms. So `Mod-b` is `Ctrl-b` on Linux but `Cmd-b` on
1419macOS.
1420*/
1421interface KeyBinding {
1422 /**
1423 The key name to use for this binding. If the platform-specific
1424 property (`mac`, `win`, or `linux`) for the current platform is
1425 used as well in the binding, that one takes precedence. If `key`
1426 isn't defined and the platform-specific binding isn't either,
1427 a binding is ignored.
1428 */
1429 key?: string;
1430 /**
1431 Key to use specifically on macOS.
1432 */
1433 mac?: string;
1434 /**
1435 Key to use specifically on Windows.
1436 */
1437 win?: string;
1438 /**
1439 Key to use specifically on Linux.
1440 */
1441 linux?: string;
1442 /**
1443 The command to execute when this binding is triggered. When the
1444 command function returns `false`, further bindings will be tried
1445 for the key.
1446 */
1447 run?: Command;
1448 /**
1449 When given, this defines a second binding, using the (possibly
1450 platform-specific) key name prefixed with `Shift-` to activate
1451 this command.
1452 */
1453 shift?: Command;
1454 /**
1455 When this property is present, the function is called for every
1456 key that is not a multi-stroke prefix.
1457 */
1458 any?: (view: EditorView, event: KeyboardEvent) => boolean;
1459 /**
1460 By default, key bindings apply when focus is on the editor
1461 content (the `"editor"` scope). Some extensions, mostly those
1462 that define their own panels, might want to allow you to
1463 register bindings local to that panel. Such bindings should use
1464 a custom scope name. You may also assign multiple scope names to
1465 a binding, separating them by spaces.
1466 */
1467 scope?: string;
1468 /**
1469 When set to true (the default is false), this will always
1470 prevent the further handling for the bound key, even if the
1471 command(s) return false. This can be useful for cases where the
1472 native behavior of the key is annoying or irrelevant but the
1473 command doesn't always apply (such as, Mod-u for undo selection,
1474 which would cause the browser to view source instead when no
1475 selection can be undone).
1476 */
1477 preventDefault?: boolean;
1478 /**
1479 When set to true, `stopPropagation` will be called on keyboard
1480 events that have their `preventDefault` called in response to
1481 this key binding (see also
1482 [`preventDefault`](https://codemirror.net/6/docs/ref/#view.KeyBinding.preventDefault)).
1483 */
1484 stopPropagation?: boolean;
1485}
1486/**
1487Facet used for registering keymaps.
1488
1489You can add multiple keymaps to an editor. Their priorities
1490determine their precedence (the ones specified early or with high
1491priority get checked first). When a handler has returned `true`
1492for a given key, no further handlers are called.
1493*/
1494declare const keymap: Facet<readonly KeyBinding[], readonly (readonly KeyBinding[])[]>;
1495/**
1496Run the key handlers registered for a given scope. The event
1497object should be a `"keydown"` event. Returns true if any of the
1498handlers handled it.
1499*/
1500declare function runScopeHandlers(view: EditorView, event: KeyboardEvent, scope: string): boolean;
1501
1502type SelectionConfig = {
1503 /**
1504 The length of a full cursor blink cycle, in milliseconds.
1505 Defaults to 1200. Can be set to 0 to disable blinking.
1506 */
1507 cursorBlinkRate?: number;
1508 /**
1509 Whether to show a cursor for non-empty ranges. Defaults to
1510 true.
1511 */
1512 drawRangeCursor?: boolean;
1513};
1514/**
1515Returns an extension that hides the browser's native selection and
1516cursor, replacing the selection with a background behind the text
1517(with the `cm-selectionBackground` class), and the
1518cursors with elements overlaid over the code (using
1519`cm-cursor-primary` and `cm-cursor-secondary`).
1520
1521This allows the editor to display secondary selection ranges, and
1522tends to produce a type of selection more in line with that users
1523expect in a text editor (the native selection styling will often
1524leave gaps between lines and won't fill the horizontal space after
1525a line when the selection continues past it).
1526
1527It does have a performance cost, in that it requires an extra DOM
1528layout cycle for many updates (the selection is drawn based on DOM
1529layout information that's only available after laying out the
1530content).
1531*/
1532declare function drawSelection(config?: SelectionConfig): Extension;
1533/**
1534Retrieve the [`drawSelection`](https://codemirror.net/6/docs/ref/#view.drawSelection) configuration
1535for this state. (Note that this will return a set of defaults even
1536if `drawSelection` isn't enabled.)
1537*/
1538declare function getDrawSelectionConfig(state: EditorState): SelectionConfig;
1539
1540/**
1541Draws a cursor at the current drop position when something is
1542dragged over the editor.
1543*/
1544declare function dropCursor(): Extension;
1545
1546interface SpecialCharConfig {
1547 /**
1548 An optional function that renders the placeholder elements.
1549
1550 The `description` argument will be text that clarifies what the
1551 character is, which should be provided to screen readers (for
1552 example with the
1553 [`aria-label`](https://www.w3.org/TR/wai-aria/#aria-label)
1554 attribute) and optionally shown to the user in other ways (such
1555 as the
1556 [`title`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title)
1557 attribute).
1558
1559 The given placeholder string is a suggestion for how to display
1560 the character visually.
1561 */
1562 render?: ((code: number, description: string | null, placeholder: string) => HTMLElement) | null;
1563 /**
1564 Regular expression that matches the special characters to
1565 highlight. Must have its 'g'/global flag set.
1566 */
1567 specialChars?: RegExp;
1568 /**
1569 Regular expression that can be used to add characters to the
1570 default set of characters to highlight.
1571 */
1572 addSpecialChars?: RegExp | null;
1573}
1574/**
1575Returns an extension that installs highlighting of special
1576characters.
1577*/
1578declare function highlightSpecialChars(
1579/**
1580Configuration options.
1581*/
1582config?: SpecialCharConfig): Extension;
1583
1584/**
1585Returns an extension that makes sure the content has a bottom
1586margin equivalent to the height of the editor, minus one line
1587height, so that every line in the document can be scrolled to the
1588top of the editor.
1589
1590This is only meaningful when the editor is scrollable, and should
1591not be enabled in editors that take the size of their content.
1592*/
1593declare function scrollPastEnd(): Extension;
1594
1595/**
1596Mark lines that have a cursor on them with the `"cm-activeLine"`
1597DOM class.
1598*/
1599declare function highlightActiveLine(): Extension;
1600
1601/**
1602Extension that enables a placeholder—a piece of example content
1603to show when the editor is empty.
1604*/
1605declare function placeholder(content: string | HTMLElement | ((view: EditorView) => HTMLElement)): Extension;
1606
1607/**
1608Markers shown in a [layer](https://codemirror.net/6/docs/ref/#view.layer) must conform to this
1609interface. They are created in a measuring phase, and have to
1610contain all their positioning information, so that they can be
1611drawn without further DOM layout reading.
1612
1613Markers are automatically absolutely positioned. Their parent
1614element has the same top-left corner as the document, so they
1615should be positioned relative to the document.
1616*/
1617interface LayerMarker {
1618 /**
1619 Compare this marker to a marker of the same type. Used to avoid
1620 unnecessary redraws.
1621 */
1622 eq(other: LayerMarker): boolean;
1623 /**
1624 Draw the marker to the DOM.
1625 */
1626 draw(): HTMLElement;
1627 /**
1628 Update an existing marker of this type to this marker.
1629 */
1630 update?(dom: HTMLElement, oldMarker: LayerMarker): boolean;
1631}
1632/**
1633Implementation of [`LayerMarker`](https://codemirror.net/6/docs/ref/#view.LayerMarker) that creates
1634a rectangle at a given set of coordinates.
1635*/
1636declare class RectangleMarker implements LayerMarker {
1637 private className;
1638 /**
1639 The left position of the marker (in pixels, document-relative).
1640 */
1641 readonly left: number;
1642 /**
1643 The top position of the marker.
1644 */
1645 readonly top: number;
1646 /**
1647 The width of the marker, or null if it shouldn't get a width assigned.
1648 */
1649 readonly width: number | null;
1650 /**
1651 The height of the marker.
1652 */
1653 readonly height: number;
1654 /**
1655 Create a marker with the given class and dimensions. If `width`
1656 is null, the DOM element will get no width style.
1657 */
1658 constructor(className: string,
1659 /**
1660 The left position of the marker (in pixels, document-relative).
1661 */
1662 left: number,
1663 /**
1664 The top position of the marker.
1665 */
1666 top: number,
1667 /**
1668 The width of the marker, or null if it shouldn't get a width assigned.
1669 */
1670 width: number | null,
1671 /**
1672 The height of the marker.
1673 */
1674 height: number);
1675 draw(): HTMLDivElement;
1676 update(elt: HTMLElement, prev: RectangleMarker): boolean;
1677 private adjust;
1678 eq(p: RectangleMarker): boolean;
1679 /**
1680 Create a set of rectangles for the given selection range,
1681 assigning them theclass`className`. Will create a single
1682 rectangle for empty ranges, and a set of selection-style
1683 rectangles covering the range's content (in a bidi-aware
1684 way) for non-empty ones.
1685 */
1686 static forRange(view: EditorView, className: string, range: SelectionRange): readonly RectangleMarker[];
1687}
1688interface LayerConfig {
1689 /**
1690 Determines whether this layer is shown above or below the text.
1691 */
1692 above: boolean;
1693 /**
1694 When given, this class is added to the DOM element that will
1695 wrap the markers.
1696 */
1697 class?: string;
1698 /**
1699 Called on every view update. Returning true triggers a marker
1700 update (a call to `markers` and drawing of those markers).
1701 */
1702 update(update: ViewUpdate, layer: HTMLElement): boolean;
1703 /**
1704 Whether to update this layer every time the document view
1705 changes. Defaults to true.
1706 */
1707 updateOnDocViewUpdate?: boolean;
1708 /**
1709 Build a set of markers for this layer, and measure their
1710 dimensions.
1711 */
1712 markers(view: EditorView): readonly LayerMarker[];
1713 /**
1714 If given, this is called when the layer is created.
1715 */
1716 mount?(layer: HTMLElement, view: EditorView): void;
1717 /**
1718 If given, called when the layer is removed from the editor or
1719 the entire editor is destroyed.
1720 */
1721 destroy?(layer: HTMLElement, view: EditorView): void;
1722}
1723/**
1724Define a layer.
1725*/
1726declare function layer(config: LayerConfig): Extension;
1727
1728/**
1729Helper class used to make it easier to maintain decorations on
1730visible code that matches a given regular expression. To be used
1731in a [view plugin](https://codemirror.net/6/docs/ref/#view.ViewPlugin). Instances of this object
1732represent a matching configuration.
1733*/
1734declare class MatchDecorator {
1735 private regexp;
1736 private addMatch;
1737 private boundary;
1738 private maxLength;
1739 /**
1740 Create a decorator.
1741 */
1742 constructor(config: {
1743 /**
1744 The regular expression to match against the content. Will only
1745 be matched inside lines (not across them). Should have its 'g'
1746 flag set.
1747 */
1748 regexp: RegExp;
1749 /**
1750 The decoration to apply to matches, either directly or as a
1751 function of the match.
1752 */
1753 decoration?: Decoration | ((match: RegExpExecArray, view: EditorView, pos: number) => Decoration | null);
1754 /**
1755 Customize the way decorations are added for matches. This
1756 function, when given, will be called for matches and should
1757 call `add` to create decorations for them. Note that the
1758 decorations should appear *in* the given range, and the
1759 function should have no side effects beyond calling `add`.
1760
1761 The `decoration` option is ignored when `decorate` is
1762 provided.
1763 */
1764 decorate?: (add: (from: number, to: number, decoration: Decoration) => void, from: number, to: number, match: RegExpExecArray, view: EditorView) => void;
1765 /**
1766 By default, changed lines are re-matched entirely. You can
1767 provide a boundary expression, which should match single
1768 character strings that can never occur in `regexp`, to reduce
1769 the amount of re-matching.
1770 */
1771 boundary?: RegExp;
1772 /**
1773 Matching happens by line, by default, but when lines are
1774 folded or very long lines are only partially drawn, the
1775 decorator may avoid matching part of them for speed. This
1776 controls how much additional invisible content it should
1777 include in its matches. Defaults to 1000.
1778 */
1779 maxLength?: number;
1780 });
1781 /**
1782 Compute the full set of decorations for matches in the given
1783 view's viewport. You'll want to call this when initializing your
1784 plugin.
1785 */
1786 createDeco(view: EditorView): _codemirror_state.RangeSet<Decoration>;
1787 /**
1788 Update a set of decorations for a view update. `deco` _must_ be
1789 the set of decorations produced by _this_ `MatchDecorator` for
1790 the view state before the update.
1791 */
1792 updateDeco(update: ViewUpdate, deco: DecorationSet): DecorationSet;
1793 private updateRange;
1794}
1795
1796/**
1797Create an extension that enables rectangular selections. By
1798default, it will react to left mouse drag with the Alt key held
1799down. When such a selection occurs, the text within the rectangle
1800that was dragged over will be selected, as one selection
1801[range](https://codemirror.net/6/docs/ref/#state.SelectionRange) per line.
1802*/
1803declare function rectangularSelection(options?: {
1804 /**
1805 A custom predicate function, which takes a `mousedown` event and
1806 returns true if it should be used for rectangular selection.
1807 */
1808 eventFilter?: (event: MouseEvent) => boolean;
1809}): Extension;
1810/**
1811Returns an extension that turns the pointer cursor into a
1812crosshair when a given modifier key, defaulting to Alt, is held
1813down. Can serve as a visual hint that rectangular selection is
1814going to happen when paired with
1815[`rectangularSelection`](https://codemirror.net/6/docs/ref/#view.rectangularSelection).
1816*/
1817declare function crosshairCursor(options?: {
1818 key?: "Alt" | "Control" | "Shift" | "Meta";
1819}): Extension;
1820
1821/**
1822Creates an extension that configures tooltip behavior.
1823*/
1824declare function tooltips(config?: {
1825 /**
1826 By default, tooltips use `"fixed"`
1827 [positioning](https://developer.mozilla.org/en-US/docs/Web/CSS/position),
1828 which has the advantage that tooltips don't get cut off by
1829 scrollable parent elements. However, CSS rules like `contain:
1830 layout` can break fixed positioning in child nodes, which can be
1831 worked about by using `"absolute"` here.
1832
1833 On iOS, which at the time of writing still doesn't properly
1834 support fixed positioning, the library always uses absolute
1835 positioning.
1836
1837 If the tooltip parent element sits in a transformed element, the
1838 library also falls back to absolute positioning.
1839 */
1840 position?: "fixed" | "absolute";
1841 /**
1842 The element to put the tooltips into. By default, they are put
1843 in the editor (`cm-editor`) element, and that is usually what
1844 you want. But in some layouts that can lead to positioning
1845 issues, and you need to use a different parent to work around
1846 those.
1847 */
1848 parent?: HTMLElement;
1849 /**
1850 By default, when figuring out whether there is room for a
1851 tooltip at a given position, the extension considers the entire
1852 space between 0,0 and
1853 `documentElement.clientWidth`/`clientHeight` to be available for
1854 showing tooltips. You can provide a function here that returns
1855 an alternative rectangle.
1856 */
1857 tooltipSpace?: (view: EditorView) => Rect;
1858}): Extension;
1859/**
1860Describes a tooltip. Values of this type, when provided through
1861the [`showTooltip`](https://codemirror.net/6/docs/ref/#view.showTooltip) facet, control the
1862individual tooltips on the editor.
1863*/
1864interface Tooltip {
1865 /**
1866 The document position at which to show the tooltip.
1867 */
1868 pos: number;
1869 /**
1870 The end of the range annotated by this tooltip, if different
1871 from `pos`.
1872 */
1873 end?: number;
1874 /**
1875 A constructor function that creates the tooltip's [DOM
1876 representation](https://codemirror.net/6/docs/ref/#view.TooltipView).
1877 */
1878 create(view: EditorView): TooltipView;
1879 /**
1880 Whether the tooltip should be shown above or below the target
1881 position. Not guaranteed to be respected for hover tooltips
1882 since all hover tooltips for the same range are always
1883 positioned together. Defaults to false.
1884 */
1885 above?: boolean;
1886 /**
1887 Whether the `above` option should be honored when there isn't
1888 enough space on that side to show the tooltip inside the
1889 viewport. Defaults to false.
1890 */
1891 strictSide?: boolean;
1892 /**
1893 When set to true, show a triangle connecting the tooltip element
1894 to position `pos`.
1895 */
1896 arrow?: boolean;
1897 /**
1898 By default, tooltips are hidden when their position is outside
1899 of the visible editor content. Set this to false to turn that
1900 off.
1901 */
1902 clip?: boolean;
1903}
1904/**
1905Describes the way a tooltip is displayed.
1906*/
1907interface TooltipView {
1908 /**
1909 The DOM element to position over the editor.
1910 */
1911 dom: HTMLElement;
1912 /**
1913 Adjust the position of the tooltip relative to its anchor
1914 position. A positive `x` value will move the tooltip
1915 horizontally along with the text direction (so right in
1916 left-to-right context, left in right-to-left). A positive `y`
1917 will move the tooltip up when it is above its anchor, and down
1918 otherwise.
1919 */
1920 offset?: {
1921 x: number;
1922 y: number;
1923 };
1924 /**
1925 By default, a tooltip's screen position will be based on the
1926 text position of its `pos` property. This method can be provided
1927 to make the tooltip view itself responsible for finding its
1928 screen position.
1929 */
1930 getCoords?: (pos: number) => Rect;
1931 /**
1932 By default, tooltips are moved when they overlap with other
1933 tooltips. Set this to `true` to disable that behavior for this
1934 tooltip.
1935 */
1936 overlap?: boolean;
1937 /**
1938 Called after the tooltip is added to the DOM for the first time.
1939 */
1940 mount?(view: EditorView): void;
1941 /**
1942 Update the DOM element for a change in the view's state.
1943 */
1944 update?(update: ViewUpdate): void;
1945 /**
1946 Called when the tooltip is removed from the editor or the editor
1947 is destroyed.
1948 */
1949 destroy?(): void;
1950 /**
1951 Called when the tooltip has been (re)positioned. The argument is
1952 the [space](https://codemirror.net/6/docs/ref/#view.tooltips^config.tooltipSpace) available to the
1953 tooltip.
1954 */
1955 positioned?(space: Rect): void;
1956 /**
1957 By default, the library will restrict the size of tooltips so
1958 that they don't stick out of the available space. Set this to
1959 false to disable that.
1960 */
1961 resize?: boolean;
1962}
1963/**
1964Facet to which an extension can add a value to show a tooltip.
1965*/
1966declare const showTooltip: Facet<Tooltip | null, readonly (Tooltip | null)[]>;
1967/**
1968The type of function that can be used as a [hover tooltip
1969source](https://codemirror.net/6/docs/ref/#view.hoverTooltip^source).
1970*/
1971type HoverTooltipSource = (view: EditorView, pos: number, side: -1 | 1) => Tooltip | readonly Tooltip[] | null | Promise<Tooltip | readonly Tooltip[] | null>;
1972/**
1973Set up a hover tooltip, which shows up when the pointer hovers
1974over ranges of text. The callback is called when the mouse hovers
1975over the document text. It should, if there is a tooltip
1976associated with position `pos`, return the tooltip description
1977(either directly or in a promise). The `side` argument indicates
1978on which side of the position the pointer is—it will be -1 if the
1979pointer is before the position, 1 if after the position.
1980
1981Note that all hover tooltips are hosted within a single tooltip
1982container element. This allows multiple tooltips over the same
1983range to be "merged" together without overlapping.
1984
1985The return value is a valid [editor extension](https://codemirror.net/6/docs/ref/#state.Extension)
1986but also provides an `active` property holding a state field that
1987can be used to read the currently active tooltips produced by this
1988extension.
1989*/
1990declare function hoverTooltip(source: HoverTooltipSource, options?: {
1991 /**
1992 Controls whether a transaction hides the tooltip. The default
1993 is to not hide.
1994 */
1995 hideOn?: (tr: Transaction, tooltip: Tooltip) => boolean;
1996 /**
1997 When enabled (this defaults to false), close the tooltip
1998 whenever the document changes or the selection is set.
1999 */
2000 hideOnChange?: boolean | "touch";
2001 /**
2002 Hover time after which the tooltip should appear, in
2003 milliseconds. Defaults to 300ms.
2004 */
2005 hoverTime?: number;
2006}): Extension & {
2007 active: StateField<readonly Tooltip[]>;
2008};
2009/**
2010Get the active tooltip view for a given tooltip, if available.
2011*/
2012declare function getTooltip(view: EditorView, tooltip: Tooltip): TooltipView | null;
2013/**
2014Returns true if any hover tooltips are currently active.
2015*/
2016declare function hasHoverTooltips(state: EditorState): boolean;
2017/**
2018Transaction effect that closes all hover tooltips.
2019*/
2020declare const closeHoverTooltips: StateEffect<null>;
2021/**
2022Tell the tooltip extension to recompute the position of the active
2023tooltips. This can be useful when something happens (such as a
2024re-positioning or CSS change affecting the editor) that could
2025invalidate the existing tooltip positions.
2026*/
2027declare function repositionTooltips(view: EditorView): void;
2028
2029type PanelConfig = {
2030 /**
2031 By default, panels will be placed inside the editor's DOM
2032 structure. You can use this option to override where panels with
2033 `top: true` are placed.
2034 */
2035 topContainer?: HTMLElement;
2036 /**
2037 Override where panels with `top: false` are placed.
2038 */
2039 bottomContainer?: HTMLElement;
2040};
2041/**
2042Configures the panel-managing extension.
2043*/
2044declare function panels(config?: PanelConfig): Extension;
2045/**
2046Object that describes an active panel.
2047*/
2048interface Panel {
2049 /**
2050 The element representing this panel. The library will add the
2051 `"cm-panel"` DOM class to this.
2052 */
2053 dom: HTMLElement;
2054 /**
2055 Optionally called after the panel has been added to the editor.
2056 */
2057 mount?(): void;
2058 /**
2059 Update the DOM for a given view update.
2060 */
2061 update?(update: ViewUpdate): void;
2062 /**
2063 Called when the panel is removed from the editor or the editor
2064 is destroyed.
2065 */
2066 destroy?(): void;
2067 /**
2068 Whether the panel should be at the top or bottom of the editor.
2069 Defaults to false.
2070 */
2071 top?: boolean;
2072}
2073/**
2074Get the active panel created by the given constructor, if any.
2075This can be useful when you need access to your panels' DOM
2076structure.
2077*/
2078declare function getPanel(view: EditorView, panel: PanelConstructor): Panel | null;
2079/**
2080A function that initializes a panel. Used in
2081[`showPanel`](https://codemirror.net/6/docs/ref/#view.showPanel).
2082*/
2083type PanelConstructor = (view: EditorView) => Panel;
2084/**
2085Opening a panel is done by providing a constructor function for
2086the panel through this facet. (The panel is closed again when its
2087constructor is no longer provided.) Values of `null` are ignored.
2088*/
2089declare const showPanel: Facet<PanelConstructor | null, readonly (PanelConstructor | null)[]>;
2090
2091type DialogConfig = {
2092 /**
2093 A function to render the content of the dialog. The result
2094 should contain at least one `<form>` element. Submit handlers a
2095 handler for the Escape key will be added to the form.
2096
2097 If this is not given, the `label`, `input`, and `submitLabel`
2098 fields will be used to create a simple form for you.
2099 */
2100 content?: (view: EditorView, close: () => void) => HTMLElement;
2101 /**
2102 When `content` isn't given, this provides the text shown in the
2103 dialog.
2104 */
2105 label?: string;
2106 /**
2107 The attributes for an input element shown next to the label. If
2108 not given, no input element is added.
2109 */
2110 input?: {
2111 [attr: string]: string;
2112 };
2113 /**
2114 The label for the button that submits the form. Defaults to
2115 `"OK"`.
2116 */
2117 submitLabel?: string;
2118 /**
2119 Extra classes to add to the panel.
2120 */
2121 class?: string;
2122 /**
2123 A query selector to find the field that should be focused when
2124 the dialog is opened. When set to true, this picks the first
2125 `<input>` or `<button>` element in the form.
2126 */
2127 focus?: string | boolean;
2128 /**
2129 By default, dialogs are shown below the editor. Set this to
2130 `true` to have it show up at the top.
2131 */
2132 top?: boolean;
2133};
2134/**
2135Show a panel above or below the editor to show the user a message
2136or prompt them for input. Returns an effect that can be dispatched
2137to close the dialog, and a promise that resolves when the dialog
2138is closed or a form inside of it is submitted.
2139
2140You are encouraged, if your handling of the result of the promise
2141dispatches a transaction, to include the `close` effect in it. If
2142you don't, this function will automatically dispatch a separate
2143transaction right after.
2144*/
2145declare function showDialog(view: EditorView, config: DialogConfig): {
2146 close: StateEffect<unknown>;
2147 result: Promise<HTMLFormElement | null>;
2148};
2149/**
2150Find the [`Panel`](https://codemirror.net/6/docs/ref/#view.Panel) for an open dialog, using a class
2151name as identifier.
2152*/
2153declare function getDialog(view: EditorView, className: string): Panel | null;
2154
2155/**
2156A gutter marker represents a bit of information attached to a line
2157in a specific gutter. Your own custom markers have to extend this
2158class.
2159*/
2160declare abstract class GutterMarker extends RangeValue {
2161 /**
2162 Compare this marker to another marker of the same type.
2163 */
2164 eq(other: GutterMarker): boolean;
2165 /**
2166 Render the DOM node for this marker, if any.
2167 */
2168 toDOM?(view: EditorView): Node;
2169 /**
2170 This property can be used to add CSS classes to the gutter
2171 element that contains this marker.
2172 */
2173 elementClass: string;
2174 /**
2175 Called if the marker has a `toDOM` method and its representation
2176 was removed from a gutter.
2177 */
2178 destroy(dom: Node): void;
2179}
2180/**
2181Facet used to add a class to all gutter elements for a given line.
2182Markers given to this facet should _only_ define an
2183[`elementclass`](https://codemirror.net/6/docs/ref/#view.GutterMarker.elementClass), not a
2184[`toDOM`](https://codemirror.net/6/docs/ref/#view.GutterMarker.toDOM) (or the marker will appear
2185in all gutters for the line).
2186*/
2187declare const gutterLineClass: Facet<RangeSet<GutterMarker>, readonly RangeSet<GutterMarker>[]>;
2188/**
2189Facet used to add a class to all gutter elements next to a widget.
2190Should not provide widgets with a `toDOM` method.
2191*/
2192declare const gutterWidgetClass: Facet<(view: EditorView, widget: WidgetType, block: BlockInfo) => GutterMarker | null, readonly ((view: EditorView, widget: WidgetType, block: BlockInfo) => GutterMarker | null)[]>;
2193type Handlers = {
2194 [event: string]: (view: EditorView, line: BlockInfo, event: Event) => boolean;
2195};
2196interface GutterConfig {
2197 /**
2198 An extra CSS class to be added to the wrapper (`cm-gutter`)
2199 element.
2200 */
2201 class?: string;
2202 /**
2203 Controls whether empty gutter elements should be rendered.
2204 Defaults to false.
2205 */
2206 renderEmptyElements?: boolean;
2207 /**
2208 Retrieve a set of markers to use in this gutter.
2209 */
2210 markers?: (view: EditorView) => (RangeSet<GutterMarker> | readonly RangeSet<GutterMarker>[]);
2211 /**
2212 Can be used to optionally add a single marker to every line.
2213 */
2214 lineMarker?: (view: EditorView, line: BlockInfo, otherMarkers: readonly GutterMarker[]) => GutterMarker | null;
2215 /**
2216 Associate markers with block widgets in the document.
2217 */
2218 widgetMarker?: (view: EditorView, widget: WidgetType, block: BlockInfo) => GutterMarker | null;
2219 /**
2220 If line or widget markers depend on additional state, and should
2221 be updated when that changes, pass a predicate here that checks
2222 whether a given view update might change the line markers.
2223 */
2224 lineMarkerChange?: null | ((update: ViewUpdate) => boolean);
2225 /**
2226 Add a hidden spacer element that gives the gutter its base
2227 width.
2228 */
2229 initialSpacer?: null | ((view: EditorView) => GutterMarker);
2230 /**
2231 Update the spacer element when the view is updated.
2232 */
2233 updateSpacer?: null | ((spacer: GutterMarker, update: ViewUpdate) => GutterMarker);
2234 /**
2235 Supply event handlers for DOM events on this gutter.
2236 */
2237 domEventHandlers?: Handlers;
2238 /**
2239 By default, gutters are shown horizontally before the editor
2240 content (to the left in a left-to-right layout). Set this to
2241 `"after"` to show a gutter on the other side of the content.
2242 */
2243 side?: "before" | "after";
2244}
2245/**
2246Define an editor gutter. The order in which the gutters appear is
2247determined by their extension priority.
2248*/
2249declare function gutter(config: GutterConfig): Extension;
2250/**
2251The gutter-drawing plugin is automatically enabled when you add a
2252gutter, but you can use this function to explicitly configure it.
2253
2254Unless `fixed` is explicitly set to `false`, the gutters are
2255fixed, meaning they don't scroll along with the content
2256horizontally (except on Internet Explorer, which doesn't support
2257CSS [`position:
2258sticky`](https://developer.mozilla.org/en-US/docs/Web/CSS/position#sticky)).
2259*/
2260declare function gutters(config?: {
2261 fixed?: boolean;
2262}): Extension;
2263interface LineNumberConfig {
2264 /**
2265 How to display line numbers. Defaults to simply converting them
2266 to string.
2267 */
2268 formatNumber?: (lineNo: number, state: EditorState) => string;
2269 /**
2270 Supply event handlers for DOM events on this gutter.
2271 */
2272 domEventHandlers?: Handlers;
2273}
2274/**
2275Facet used to provide markers to the line number gutter.
2276*/
2277declare const lineNumberMarkers: Facet<RangeSet<GutterMarker>, readonly RangeSet<GutterMarker>[]>;
2278/**
2279Facet used to create markers in the line number gutter next to widgets.
2280*/
2281declare const lineNumberWidgetMarker: Facet<(view: EditorView, widget: WidgetType, block: BlockInfo) => GutterMarker | null, readonly ((view: EditorView, widget: WidgetType, block: BlockInfo) => GutterMarker | null)[]>;
2282/**
2283Create a line number gutter extension.
2284*/
2285declare function lineNumbers(config?: LineNumberConfig): Extension;
2286/**
2287Returns an extension that adds a `cm-activeLineGutter` class to
2288all gutter elements on the [active
2289line](https://codemirror.net/6/docs/ref/#view.highlightActiveLine).
2290*/
2291declare function highlightActiveLineGutter(): Extension;
2292
2293/**
2294Returns an extension that highlights whitespace, adding a
2295`cm-highlightSpace` class to stretches of spaces, and a
2296`cm-highlightTab` class to individual tab characters. By default,
2297the former are shown as faint dots, and the latter as arrows.
2298*/
2299declare function highlightWhitespace(): Extension;
2300/**
2301Returns an extension that adds a `cm-trailingSpace` class to all
2302trailing whitespace.
2303*/
2304declare function highlightTrailingWhitespace(): Extension;
2305
2306export { BidiSpan, BlockInfo, BlockType, type Command, type DOMEventHandlers, type DOMEventMap, Decoration, type DecorationSet, Direction, EditorView, type EditorViewConfig, GutterMarker, type HoverTooltipSource, type KeyBinding, type LayerMarker, MatchDecorator, type MouseSelectionStyle, type Panel, type PanelConstructor, type PluginSpec, type PluginValue, type Rect, RectangleMarker, type Tooltip, type TooltipView, ViewPlugin, ViewUpdate, WidgetType, closeHoverTooltips, crosshairCursor, drawSelection, dropCursor, getDialog, getDrawSelectionConfig, getPanel, getTooltip, gutter, gutterLineClass, gutterWidgetClass, gutters, hasHoverTooltips, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, highlightTrailingWhitespace, highlightWhitespace, hoverTooltip, keymap, layer, lineNumberMarkers, lineNumberWidgetMarker, lineNumbers, logException, panels, placeholder, rectangularSelection, repositionTooltips, runScopeHandlers, scrollPastEnd, showDialog, showPanel, showTooltip, tooltips };