@codemirror/view 0.19.48 → 0.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/dist/index.cjs +1600 -370
- package/dist/index.d.ts +540 -249
- package/dist/index.js +1561 -345
- package/package.json +2 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import * as _codemirror_rangeset from '@codemirror/rangeset';
|
|
2
|
-
import { RangeSet, RangeValue, Range } from '@codemirror/rangeset';
|
|
3
|
-
export { Range } from '@codemirror/rangeset';
|
|
4
1
|
import * as _codemirror_state from '@codemirror/state';
|
|
5
|
-
import { EditorState, Extension, Transaction, ChangeSet, EditorSelection, TransactionSpec, SelectionRange, StateEffect, Facet } from '@codemirror/state';
|
|
6
|
-
import { Line } from '@codemirror/text';
|
|
2
|
+
import { RangeSet, RangeValue, Range, EditorState, Extension, Transaction, ChangeSet, EditorSelection, TransactionSpec, SelectionRange, Line, StateEffect, Facet } from '@codemirror/state';
|
|
7
3
|
import { StyleModule, StyleSpec } from 'style-mod';
|
|
8
4
|
|
|
9
5
|
declare type Attrs = {
|
|
@@ -39,9 +35,10 @@ interface MarkDecorationSpec {
|
|
|
39
35
|
class?: string;
|
|
40
36
|
/**
|
|
41
37
|
Add a wrapping element around the text in the marked range. Note
|
|
42
|
-
that there will not be a single element covering the
|
|
43
|
-
range—
|
|
44
|
-
|
|
38
|
+
that there will not necessarily be a single element covering the
|
|
39
|
+
entire range—other decorations with lower precedence might split
|
|
40
|
+
this one if they partially overlap it, and line breaks always
|
|
41
|
+
end decoration elements.
|
|
45
42
|
*/
|
|
46
43
|
tagName?: string;
|
|
47
44
|
/**
|
|
@@ -132,7 +129,7 @@ interface LineDecorationSpec {
|
|
|
132
129
|
Widgets added to the content are described by subclasses of this
|
|
133
130
|
class. Using a description object like that makes it possible to
|
|
134
131
|
delay creating of the DOM structure for a widget until it is
|
|
135
|
-
needed, and to avoid redrawing widgets even
|
|
132
|
+
needed, and to avoid redrawing widgets even if the decorations
|
|
136
133
|
that define them are recreated.
|
|
137
134
|
*/
|
|
138
135
|
declare abstract class WidgetType {
|
|
@@ -149,7 +146,7 @@ declare abstract class WidgetType {
|
|
|
149
146
|
returns `false`, which will cause new instances of the widget to
|
|
150
147
|
always be redrawn.
|
|
151
148
|
*/
|
|
152
|
-
eq(
|
|
149
|
+
eq(widget: WidgetType): boolean;
|
|
153
150
|
/**
|
|
154
151
|
Update a DOM element created by a widget of the same type (but
|
|
155
152
|
different, non-`eq` content) to reflect this widget. May return
|
|
@@ -157,7 +154,7 @@ declare abstract class WidgetType {
|
|
|
157
154
|
couldn't (in which case the widget will be redrawn). The default
|
|
158
155
|
implementation just returns false.
|
|
159
156
|
*/
|
|
160
|
-
updateDOM(
|
|
157
|
+
updateDOM(dom: HTMLElement): boolean;
|
|
161
158
|
/**
|
|
162
159
|
The estimated height this widget will have, to be used when
|
|
163
160
|
estimating the height of content that hasn't been drawn. May
|
|
@@ -170,17 +167,17 @@ declare abstract class WidgetType {
|
|
|
170
167
|
should be ignored by the editor. The default is to ignore all
|
|
171
168
|
events.
|
|
172
169
|
*/
|
|
173
|
-
ignoreEvent(
|
|
170
|
+
ignoreEvent(event: Event): boolean;
|
|
174
171
|
/**
|
|
175
172
|
This is called when the an instance of the widget is removed
|
|
176
173
|
from the editor view.
|
|
177
174
|
*/
|
|
178
|
-
destroy(
|
|
175
|
+
destroy(dom: HTMLElement): void;
|
|
179
176
|
}
|
|
180
177
|
/**
|
|
181
178
|
A decoration set represents a collection of decorated ranges,
|
|
182
179
|
organized for efficient access and mapping. See
|
|
183
|
-
[`RangeSet`](https://codemirror.net/6/docs/ref/#
|
|
180
|
+
[`RangeSet`](https://codemirror.net/6/docs/ref/#state.RangeSet) for its methods.
|
|
184
181
|
*/
|
|
185
182
|
declare type DecorationSet = RangeSet<Decoration>;
|
|
186
183
|
/**
|
|
@@ -207,7 +204,8 @@ declare enum BlockType {
|
|
|
207
204
|
/**
|
|
208
205
|
A decoration provides information on how to draw or style a piece
|
|
209
206
|
of content. You'll usually use it wrapped in a
|
|
210
|
-
[`Range`](https://codemirror.net/6/docs/ref/#
|
|
207
|
+
[`Range`](https://codemirror.net/6/docs/ref/#state.Range), which adds a start and end position.
|
|
208
|
+
@nonabstract
|
|
211
209
|
*/
|
|
212
210
|
declare abstract class Decoration extends RangeValue {
|
|
213
211
|
/**
|
|
@@ -221,16 +219,15 @@ declare abstract class Decoration extends RangeValue {
|
|
|
221
219
|
Create a mark decoration, which influences the styling of the
|
|
222
220
|
content in its range. Nested mark decorations will cause nested
|
|
223
221
|
DOM elements to be created. Nesting order is determined by
|
|
224
|
-
precedence of the [facet](https://codemirror.net/6/docs/ref/#view.EditorView^decorations)
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
decorations.
|
|
222
|
+
precedence of the [facet](https://codemirror.net/6/docs/ref/#view.EditorView^decorations), with
|
|
223
|
+
the higher-precedence decorations creating the inner DOM nodes.
|
|
224
|
+
Such elements are split on line boundaries and on the boundaries
|
|
225
|
+
of lower-precedence decorations.
|
|
229
226
|
*/
|
|
230
227
|
static mark(spec: MarkDecorationSpec): Decoration;
|
|
231
228
|
/**
|
|
232
|
-
Create a widget decoration, which
|
|
233
|
-
position.
|
|
229
|
+
Create a widget decoration, which displays a DOM element at the
|
|
230
|
+
given position.
|
|
234
231
|
*/
|
|
235
232
|
static widget(spec: WidgetDecorationSpec): Decoration;
|
|
236
233
|
/**
|
|
@@ -290,7 +287,7 @@ declare function logException(state: EditorState, exception: any, context?: stri
|
|
|
290
287
|
/**
|
|
291
288
|
This is the interface plugin objects conform to.
|
|
292
289
|
*/
|
|
293
|
-
interface PluginValue {
|
|
290
|
+
interface PluginValue extends Object {
|
|
294
291
|
/**
|
|
295
292
|
Notifies the plugin of an update that happened in the view. This
|
|
296
293
|
is called _before_ the view updates its own DOM. It is
|
|
@@ -301,75 +298,13 @@ interface PluginValue {
|
|
|
301
298
|
[`requestMeasure`](https://codemirror.net/6/docs/ref/#view.EditorView.requestMeasure) to schedule
|
|
302
299
|
your code in a DOM reading phase if you need to.
|
|
303
300
|
*/
|
|
304
|
-
update?(
|
|
301
|
+
update?(update: ViewUpdate): void;
|
|
305
302
|
/**
|
|
306
303
|
Called when the plugin is no longer going to be used. Should
|
|
307
304
|
revert any changes the plugin made to the DOM.
|
|
308
305
|
*/
|
|
309
306
|
destroy?(): void;
|
|
310
307
|
}
|
|
311
|
-
declare const isFieldProvider: unique symbol;
|
|
312
|
-
/**
|
|
313
|
-
Used to [declare](https://codemirror.net/6/docs/ref/#view.PluginSpec.provide) which
|
|
314
|
-
[fields](https://codemirror.net/6/docs/ref/#view.PluginValue) a [view plugin](https://codemirror.net/6/docs/ref/#view.ViewPlugin)
|
|
315
|
-
provides.
|
|
316
|
-
*/
|
|
317
|
-
declare class PluginFieldProvider<V> {
|
|
318
|
-
private [isFieldProvider];
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
Plugin fields are a mechanism for allowing plugins to provide
|
|
322
|
-
values that can be retrieved through the
|
|
323
|
-
[`pluginField`](https://codemirror.net/6/docs/ref/#view.EditorView.pluginField) view method.
|
|
324
|
-
*/
|
|
325
|
-
declare class PluginField<T> {
|
|
326
|
-
/**
|
|
327
|
-
Create a [provider](https://codemirror.net/6/docs/ref/#view.PluginFieldProvider) for this field,
|
|
328
|
-
to use with a plugin's [provide](https://codemirror.net/6/docs/ref/#view.PluginSpec.provide)
|
|
329
|
-
option.
|
|
330
|
-
*/
|
|
331
|
-
from<V extends PluginValue>(get: (value: V) => T): PluginFieldProvider<V>;
|
|
332
|
-
/**
|
|
333
|
-
Define a new plugin field.
|
|
334
|
-
*/
|
|
335
|
-
static define<T>(): PluginField<T>;
|
|
336
|
-
/**
|
|
337
|
-
This field can be used by plugins to provide
|
|
338
|
-
[decorations](https://codemirror.net/6/docs/ref/#view.Decoration).
|
|
339
|
-
|
|
340
|
-
**Note**: For reasons of data flow (plugins are only updated
|
|
341
|
-
after the viewport is computed), decorations produced by plugins
|
|
342
|
-
are _not_ taken into account when predicting the vertical layout
|
|
343
|
-
structure of the editor. They **must not** introduce block
|
|
344
|
-
widgets (that will raise an error) or replacing decorations that
|
|
345
|
-
cover line breaks (these will be ignored if they occur). Such
|
|
346
|
-
decorations, or others that cause a large amount of vertical
|
|
347
|
-
size shift compared to the undecorated content, should be
|
|
348
|
-
provided through the state-level [`decorations`
|
|
349
|
-
facet](https://codemirror.net/6/docs/ref/#view.EditorView^decorations) instead.
|
|
350
|
-
*/
|
|
351
|
-
static decorations: PluginField<DecorationSet>;
|
|
352
|
-
/**
|
|
353
|
-
Used to provide ranges that should be treated as atoms as far as
|
|
354
|
-
cursor motion is concerned. This causes methods like
|
|
355
|
-
[`moveByChar`](https://codemirror.net/6/docs/ref/#view.EditorView.moveByChar) and
|
|
356
|
-
[`moveVertically`](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) (and the
|
|
357
|
-
commands built on top of them) to skip across such regions when
|
|
358
|
-
a selection endpoint would enter them. This does _not_ prevent
|
|
359
|
-
direct programmatic [selection
|
|
360
|
-
updates](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) from moving into such
|
|
361
|
-
regions.
|
|
362
|
-
*/
|
|
363
|
-
static atomicRanges: PluginField<RangeSet<any>>;
|
|
364
|
-
/**
|
|
365
|
-
Plugins can provide additional scroll margins (space around the
|
|
366
|
-
sides of the scrolling element that should be considered
|
|
367
|
-
invisible) through this field. This can be useful when the
|
|
368
|
-
plugin introduces elements that cover part of that element (for
|
|
369
|
-
example a horizontally fixed gutter).
|
|
370
|
-
*/
|
|
371
|
-
static scrollMargins: PluginField<Partial<Rect> | null>;
|
|
372
|
-
}
|
|
373
308
|
/**
|
|
374
309
|
Provides additional information when defining a [view
|
|
375
310
|
plugin](https://codemirror.net/6/docs/ref/#view.ViewPlugin).
|
|
@@ -383,20 +318,18 @@ interface PluginSpec<V extends PluginValue> {
|
|
|
383
318
|
*/
|
|
384
319
|
eventHandlers?: DOMEventHandlers<V>;
|
|
385
320
|
/**
|
|
321
|
+
Specify that the plugin provides additional extensions when
|
|
322
|
+
added to an editor configuration.
|
|
323
|
+
*/
|
|
324
|
+
provide?: (plugin: ViewPlugin<V>) => Extension;
|
|
325
|
+
/**
|
|
386
326
|
Allow the plugin to provide decorations. When given, this should
|
|
387
327
|
a function that take the plugin value and return a [decoration
|
|
388
328
|
set](https://codemirror.net/6/docs/ref/#view.DecorationSet). See also the caveat about
|
|
389
|
-
[layout-changing decorations](https://codemirror.net/6/docs/ref/#view.
|
|
390
|
-
|
|
329
|
+
[layout-changing decorations](https://codemirror.net/6/docs/ref/#view.EditorView^decorations)
|
|
330
|
+
that depend on the view.
|
|
391
331
|
*/
|
|
392
332
|
decorations?: (value: V) => DecorationSet;
|
|
393
|
-
/**
|
|
394
|
-
Specify that the plugin provides [plugin
|
|
395
|
-
field](https://codemirror.net/6/docs/ref/#view.PluginField) values. Use a field's
|
|
396
|
-
[`from`](https://codemirror.net/6/docs/ref/#view.PluginField.from) method to create these
|
|
397
|
-
providers.
|
|
398
|
-
*/
|
|
399
|
-
provide?: PluginFieldProvider<V> | readonly PluginFieldProvider<V>[];
|
|
400
333
|
}
|
|
401
334
|
/**
|
|
402
335
|
View plugins associate stateful values with a view. They can
|
|
@@ -413,12 +346,12 @@ declare class ViewPlugin<V extends PluginValue> {
|
|
|
413
346
|
Define a plugin from a constructor function that creates the
|
|
414
347
|
plugin's value, given an editor view.
|
|
415
348
|
*/
|
|
416
|
-
static define<V extends PluginValue
|
|
349
|
+
static define<V extends PluginValue>(create: (view: EditorView) => V, spec?: PluginSpec<V>): ViewPlugin<V>;
|
|
417
350
|
/**
|
|
418
351
|
Create a plugin for a class whose constructor takes a single
|
|
419
352
|
editor view as argument.
|
|
420
353
|
*/
|
|
421
|
-
static fromClass<V extends PluginValue
|
|
354
|
+
static fromClass<V extends PluginValue>(cls: {
|
|
422
355
|
new (view: EditorView): V;
|
|
423
356
|
}, spec?: PluginSpec<V>): ViewPlugin<V>;
|
|
424
357
|
}
|
|
@@ -472,8 +405,8 @@ declare class ViewUpdate {
|
|
|
472
405
|
*/
|
|
473
406
|
get viewportChanged(): boolean;
|
|
474
407
|
/**
|
|
475
|
-
Indicates whether the height of
|
|
476
|
-
in this update.
|
|
408
|
+
Indicates whether the height of a block element in the editor
|
|
409
|
+
changed in this update.
|
|
477
410
|
*/
|
|
478
411
|
get heightChanged(): boolean;
|
|
479
412
|
/**
|
|
@@ -529,6 +462,43 @@ interface MouseSelectionStyle {
|
|
|
529
462
|
}
|
|
530
463
|
declare type MakeSelectionStyle = (view: EditorView, event: MouseEvent) => MouseSelectionStyle | null;
|
|
531
464
|
|
|
465
|
+
/**
|
|
466
|
+
Record used to represent information about a block-level element
|
|
467
|
+
in the editor view.
|
|
468
|
+
*/
|
|
469
|
+
declare class BlockInfo {
|
|
470
|
+
/**
|
|
471
|
+
The start of the element in the document.
|
|
472
|
+
*/
|
|
473
|
+
readonly from: number;
|
|
474
|
+
/**
|
|
475
|
+
The length of the element.
|
|
476
|
+
*/
|
|
477
|
+
readonly length: number;
|
|
478
|
+
/**
|
|
479
|
+
The top position of the element (relative to the top of the
|
|
480
|
+
document).
|
|
481
|
+
*/
|
|
482
|
+
readonly top: number;
|
|
483
|
+
/**
|
|
484
|
+
Its height.
|
|
485
|
+
*/
|
|
486
|
+
readonly height: number;
|
|
487
|
+
/**
|
|
488
|
+
The type of element this is. When querying lines, this may be
|
|
489
|
+
an array of all the blocks that make up the line.
|
|
490
|
+
*/
|
|
491
|
+
readonly type: BlockType | readonly BlockInfo[];
|
|
492
|
+
/**
|
|
493
|
+
The end of the element as a document position.
|
|
494
|
+
*/
|
|
495
|
+
get to(): number;
|
|
496
|
+
/**
|
|
497
|
+
The bottom position of the element.
|
|
498
|
+
*/
|
|
499
|
+
get bottom(): number;
|
|
500
|
+
}
|
|
501
|
+
|
|
532
502
|
/**
|
|
533
503
|
Used to indicate [text direction](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection).
|
|
534
504
|
*/
|
|
@@ -569,43 +539,6 @@ declare class BidiSpan {
|
|
|
569
539
|
get dir(): Direction;
|
|
570
540
|
}
|
|
571
541
|
|
|
572
|
-
/**
|
|
573
|
-
Record used to represent information about a block-level element
|
|
574
|
-
in the editor view.
|
|
575
|
-
*/
|
|
576
|
-
declare class BlockInfo {
|
|
577
|
-
/**
|
|
578
|
-
The start of the element in the document.
|
|
579
|
-
*/
|
|
580
|
-
readonly from: number;
|
|
581
|
-
/**
|
|
582
|
-
The length of the element.
|
|
583
|
-
*/
|
|
584
|
-
readonly length: number;
|
|
585
|
-
/**
|
|
586
|
-
The top position of the element (relative to the top of the
|
|
587
|
-
document).
|
|
588
|
-
*/
|
|
589
|
-
readonly top: number;
|
|
590
|
-
/**
|
|
591
|
-
Its height.
|
|
592
|
-
*/
|
|
593
|
-
readonly height: number;
|
|
594
|
-
/**
|
|
595
|
-
The type of element this is. When querying lines, this may be
|
|
596
|
-
an array of all the blocks that make up the line.
|
|
597
|
-
*/
|
|
598
|
-
readonly type: BlockType | readonly BlockInfo[];
|
|
599
|
-
/**
|
|
600
|
-
The end of the element as a document position.
|
|
601
|
-
*/
|
|
602
|
-
get to(): number;
|
|
603
|
-
/**
|
|
604
|
-
The bottom position of the element.
|
|
605
|
-
*/
|
|
606
|
-
get bottom(): number;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
542
|
interface EditorConfig {
|
|
610
543
|
/**
|
|
611
544
|
The view's initial state. Defaults to an extension-less state
|
|
@@ -613,6 +546,12 @@ interface EditorConfig {
|
|
|
613
546
|
*/
|
|
614
547
|
state?: EditorState;
|
|
615
548
|
/**
|
|
549
|
+
When given, the editor is immediately appended to the given
|
|
550
|
+
element on creation. (Otherwise, you'll have to place the view's
|
|
551
|
+
[`dom`](https://codemirror.net/6/docs/ref/#view.EditorView.dom) element in the document yourself.)
|
|
552
|
+
*/
|
|
553
|
+
parent?: Element | DocumentFragment;
|
|
554
|
+
/**
|
|
616
555
|
If the view is going to be mounted in a shadow root or document
|
|
617
556
|
other than the one held by the global variable `document` (the
|
|
618
557
|
default), you should pass it here. If you provide `parent`, but
|
|
@@ -628,12 +567,6 @@ interface EditorConfig {
|
|
|
628
567
|
method](https://codemirror.net/6/docs/ref/#view.EditorView.update).
|
|
629
568
|
*/
|
|
630
569
|
dispatch?: (tr: Transaction) => void;
|
|
631
|
-
/**
|
|
632
|
-
When given, the editor is immediately appended to the given
|
|
633
|
-
element on creation. (Otherwise, you'll have to place the view's
|
|
634
|
-
[`dom`](https://codemirror.net/6/docs/ref/#view.EditorView.dom) element in the document yourself.)
|
|
635
|
-
*/
|
|
636
|
-
parent?: Element | DocumentFragment;
|
|
637
570
|
}
|
|
638
571
|
/**
|
|
639
572
|
An editor view represents the editor's user interface. It holds
|
|
@@ -719,9 +652,9 @@ declare class EditorView {
|
|
|
719
652
|
private bidiCache;
|
|
720
653
|
private destroyed;
|
|
721
654
|
/**
|
|
722
|
-
Construct a new view. You'll
|
|
723
|
-
|
|
724
|
-
|
|
655
|
+
Construct a new view. You'll want to either provide a `parent`
|
|
656
|
+
option, or put `view.dom` into your document after creating a
|
|
657
|
+
view, so that the user can see the editor.
|
|
725
658
|
*/
|
|
726
659
|
constructor(
|
|
727
660
|
/**
|
|
@@ -775,11 +708,6 @@ declare class EditorView {
|
|
|
775
708
|
*/
|
|
776
709
|
requestMeasure<T>(request?: MeasureRequest<T>): void;
|
|
777
710
|
/**
|
|
778
|
-
Collect all values provided by the active plugins for a given
|
|
779
|
-
field.
|
|
780
|
-
*/
|
|
781
|
-
pluginField<T>(field: PluginField<T>): readonly T[];
|
|
782
|
-
/**
|
|
783
711
|
Get the value of a specific plugin, if present. Note that
|
|
784
712
|
plugins that crash can be dropped from a view, so even when you
|
|
785
713
|
know you registered a given plugin, it is recommended to check
|
|
@@ -800,55 +728,18 @@ declare class EditorView {
|
|
|
800
728
|
bottom: number;
|
|
801
729
|
};
|
|
802
730
|
/**
|
|
803
|
-
Find the line or block widget at the given vertical position.
|
|
804
|
-
|
|
805
|
-
By default, this position is interpreted as a screen position,
|
|
806
|
-
meaning `docTop` is set to the DOM top position of the editor
|
|
807
|
-
content (forcing a layout). You can pass a different `docTop`
|
|
808
|
-
value—for example 0 to interpret `height` as a document-relative
|
|
809
|
-
position, or a precomputed document top
|
|
810
|
-
(`view.contentDOM.getBoundingClientRect().top`) to limit layout
|
|
811
|
-
queries.
|
|
812
|
-
|
|
813
|
-
*Deprecated: use `elementAtHeight` instead.*
|
|
814
|
-
*/
|
|
815
|
-
blockAtHeight(height: number, docTop?: number): BlockInfo;
|
|
816
|
-
/**
|
|
817
731
|
Find the text line or block widget at the given vertical
|
|
818
732
|
position (which is interpreted as relative to the [top of the
|
|
819
733
|
document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop)
|
|
820
734
|
*/
|
|
821
735
|
elementAtHeight(height: number): BlockInfo;
|
|
822
736
|
/**
|
|
823
|
-
Find information for the visual line (see
|
|
824
|
-
[`visualLineAt`](https://codemirror.net/6/docs/ref/#view.EditorView.visualLineAt)) at the given
|
|
825
|
-
vertical position. The resulting block info might hold another
|
|
826
|
-
array of block info structs in its `type` field if this line
|
|
827
|
-
consists of more than one block.
|
|
828
|
-
|
|
829
|
-
Defaults to treating `height` as a screen position. See
|
|
830
|
-
[`blockAtHeight`](https://codemirror.net/6/docs/ref/#view.EditorView.blockAtHeight) for the
|
|
831
|
-
interpretation of the `docTop` parameter.
|
|
832
|
-
|
|
833
|
-
*Deprecated: use `lineBlockAtHeight` instead.*
|
|
834
|
-
*/
|
|
835
|
-
visualLineAtHeight(height: number, docTop?: number): BlockInfo;
|
|
836
|
-
/**
|
|
837
737
|
Find the line block (see
|
|
838
738
|
[`lineBlockAt`](https://codemirror.net/6/docs/ref/#view.EditorView.lineBlockAt) at the given
|
|
839
739
|
height.
|
|
840
740
|
*/
|
|
841
741
|
lineBlockAtHeight(height: number): BlockInfo;
|
|
842
742
|
/**
|
|
843
|
-
Iterate over the height information of the visual lines in the
|
|
844
|
-
viewport. The heights of lines are reported relative to the
|
|
845
|
-
given document top, which defaults to the screen position of the
|
|
846
|
-
document (forcing a layout).
|
|
847
|
-
|
|
848
|
-
*Deprecated: use `viewportLineBlocks` instead.*
|
|
849
|
-
*/
|
|
850
|
-
viewportLines(f: (line: BlockInfo) => void, docTop?: number): void;
|
|
851
|
-
/**
|
|
852
743
|
Get the extent and vertical position of all [line
|
|
853
744
|
blocks](https://codemirror.net/6/docs/ref/#view.EditorView.lineBlockAt) in the viewport. Positions
|
|
854
745
|
are relative to the [top of the
|
|
@@ -856,22 +747,9 @@ declare class EditorView {
|
|
|
856
747
|
*/
|
|
857
748
|
get viewportLineBlocks(): BlockInfo[];
|
|
858
749
|
/**
|
|
859
|
-
Find the extent and height of the visual line (a range delimited
|
|
860
|
-
on both sides by either non-[hidden](https://codemirror.net/6/docs/ref/#view.Decoration^range)
|
|
861
|
-
line breaks, or the start/end of the document) at the given position.
|
|
862
|
-
|
|
863
|
-
Vertical positions are computed relative to the `docTop`
|
|
864
|
-
argument, which defaults to 0 for this method. You can pass
|
|
865
|
-
`view.contentDOM.getBoundingClientRect().top` here to get screen
|
|
866
|
-
coordinates.
|
|
867
|
-
|
|
868
|
-
*Deprecated: use `lineBlockAt` instead.*
|
|
869
|
-
*/
|
|
870
|
-
visualLineAt(pos: number, docTop?: number): BlockInfo;
|
|
871
|
-
/**
|
|
872
750
|
Find the line block around the given document position. A line
|
|
873
751
|
block is a range delimited on both sides by either a
|
|
874
|
-
non-[hidden](https://codemirror.net/6/docs/ref/#view.Decoration^
|
|
752
|
+
non-[hidden](https://codemirror.net/6/docs/ref/#view.Decoration^replace) line breaks, or the
|
|
875
753
|
start/end of the document. It will usually just hold a line of
|
|
876
754
|
text, but may be broken into multiple textblocks by block
|
|
877
755
|
widgets.
|
|
@@ -883,13 +761,13 @@ declare class EditorView {
|
|
|
883
761
|
get contentHeight(): number;
|
|
884
762
|
/**
|
|
885
763
|
Move a cursor position by [grapheme
|
|
886
|
-
cluster](https://codemirror.net/6/docs/ref/#
|
|
887
|
-
the motion is away from the line start, or towards it.
|
|
888
|
-
bidirectional text is in visual order,
|
|
889
|
-
direction](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection).
|
|
890
|
-
position was the last one on the line, the
|
|
891
|
-
will be across the line break. If there is no
|
|
892
|
-
original position is returned.
|
|
764
|
+
cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak). `forward` determines whether
|
|
765
|
+
the motion is away from the line start, or towards it. In
|
|
766
|
+
bidirectional text, the line is traversed in visual order, using
|
|
767
|
+
the editor's [text direction](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection).
|
|
768
|
+
When the start position was the last one on the line, the
|
|
769
|
+
returned position will be across the line break. If there is no
|
|
770
|
+
further line, the original position is returned.
|
|
893
771
|
|
|
894
772
|
By default, this method moves over a single cluster. The
|
|
895
773
|
optional `by` argument can be used to move across more. It will
|
|
@@ -926,7 +804,6 @@ declare class EditorView {
|
|
|
926
804
|
used.
|
|
927
805
|
*/
|
|
928
806
|
moveVertically(start: SelectionRange, forward: boolean, distance?: number): SelectionRange;
|
|
929
|
-
scrollPosIntoView(pos: number): void;
|
|
930
807
|
/**
|
|
931
808
|
Find the DOM parent node and offset (child offset if `node` is
|
|
932
809
|
an element, character offset when it is a text node) at the
|
|
@@ -984,10 +861,20 @@ declare class EditorView {
|
|
|
984
861
|
/**
|
|
985
862
|
The text direction
|
|
986
863
|
([`direction`](https://developer.mozilla.org/en-US/docs/Web/CSS/direction)
|
|
987
|
-
CSS property) of the editor.
|
|
864
|
+
CSS property) of the editor's content element.
|
|
988
865
|
*/
|
|
989
866
|
get textDirection(): Direction;
|
|
990
867
|
/**
|
|
868
|
+
Find the text direction of the block at the given position, as
|
|
869
|
+
assigned by CSS. If
|
|
870
|
+
[`perLineTextDirection`](https://codemirror.net/6/docs/ref/#view.EditorView^perLineTextDirection)
|
|
871
|
+
isn't enabled, or the given position is outside of the viewport,
|
|
872
|
+
this will always return the same as
|
|
873
|
+
[`textDirection`](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection). Note that
|
|
874
|
+
this may trigger a DOM layout.
|
|
875
|
+
*/
|
|
876
|
+
textDirectionAt(pos: number): Direction;
|
|
877
|
+
/**
|
|
991
878
|
Whether this editor [wraps lines](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping)
|
|
992
879
|
(as determined by the
|
|
993
880
|
[`white-space`](https://developer.mozilla.org/en-US/docs/Web/CSS/white-space)
|
|
@@ -1019,20 +906,6 @@ declare class EditorView {
|
|
|
1019
906
|
*/
|
|
1020
907
|
destroy(): void;
|
|
1021
908
|
/**
|
|
1022
|
-
Effect that can be [added](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) to a
|
|
1023
|
-
transaction to make it scroll the given range into view.
|
|
1024
|
-
|
|
1025
|
-
*Deprecated*. Use [`scrollIntoView`](https://codemirror.net/6/docs/ref/#view.EditorView^scrollIntoView) instead.
|
|
1026
|
-
*/
|
|
1027
|
-
static scrollTo: _codemirror_state.StateEffectType<SelectionRange>;
|
|
1028
|
-
/**
|
|
1029
|
-
Effect that makes the editor scroll the given range to the
|
|
1030
|
-
center of the visible view.
|
|
1031
|
-
|
|
1032
|
-
*Deprecated*. Use [`scrollIntoView`](https://codemirror.net/6/docs/ref/#view.EditorView^scrollIntoView) instead.
|
|
1033
|
-
*/
|
|
1034
|
-
static centerOn: _codemirror_state.StateEffectType<SelectionRange>;
|
|
1035
|
-
/**
|
|
1036
909
|
Returns an effect that can be
|
|
1037
910
|
[added](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) to a transaction to
|
|
1038
911
|
cause it to scroll the given position or range into view.
|
|
@@ -1072,16 +945,16 @@ declare class EditorView {
|
|
|
1072
945
|
*/
|
|
1073
946
|
static styleModule: Facet<StyleModule, readonly StyleModule[]>;
|
|
1074
947
|
/**
|
|
1075
|
-
|
|
1076
|
-
should be an object mapping event names to handler
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
These are registered
|
|
1081
|
-
element](https://codemirror.net/6/docs/ref/#view.EditorView.contentDOM), except
|
|
1082
|
-
handlers, which will be called any time the
|
|
1083
|
-
element](https://codemirror.net/6/docs/ref/#view.EditorView.scrollDOM) or one of
|
|
1084
|
-
is scrolled.
|
|
948
|
+
Returns an extension that can be used to add DOM event handlers.
|
|
949
|
+
The value should be an object mapping event names to handler
|
|
950
|
+
functions. For any given event, such functions are ordered by
|
|
951
|
+
extension precedence, and the first handler to return true will
|
|
952
|
+
be assumed to have handled that event, and no other handlers or
|
|
953
|
+
built-in behavior will be activated for it. These are registered
|
|
954
|
+
on the [content element](https://codemirror.net/6/docs/ref/#view.EditorView.contentDOM), except
|
|
955
|
+
for `scroll` handlers, which will be called any time the
|
|
956
|
+
editor's [scroll element](https://codemirror.net/6/docs/ref/#view.EditorView.scrollDOM) or one of
|
|
957
|
+
its parent nodes is scrolled.
|
|
1085
958
|
*/
|
|
1086
959
|
static domEventHandlers(handlers: DOMEventHandlers<any>): Extension;
|
|
1087
960
|
/**
|
|
@@ -1093,6 +966,13 @@ declare class EditorView {
|
|
|
1093
966
|
*/
|
|
1094
967
|
static inputHandler: Facet<(view: EditorView, from: number, to: number, text: string) => boolean, readonly ((view: EditorView, from: number, to: number, text: string) => boolean)[]>;
|
|
1095
968
|
/**
|
|
969
|
+
By default, the editor assumes all its content has the same
|
|
970
|
+
[text direction](https://codemirror.net/6/docs/ref/#view.Direction). Configure this with a `true`
|
|
971
|
+
value to make it read and store the text direction of every
|
|
972
|
+
(rendered) line separately.
|
|
973
|
+
*/
|
|
974
|
+
static perLineTextDirection: Facet<boolean, boolean>;
|
|
975
|
+
/**
|
|
1096
976
|
Allows you to provide a function that should be called when the
|
|
1097
977
|
library catches an exception from an extension (mostly from view
|
|
1098
978
|
plugins, but may be used by other extensions to route exceptions
|
|
@@ -1108,9 +988,9 @@ declare class EditorView {
|
|
|
1108
988
|
/**
|
|
1109
989
|
Facet that controls whether the editor content DOM is editable.
|
|
1110
990
|
When its highest-precedence value is `false`, the element will
|
|
1111
|
-
not
|
|
1112
|
-
|
|
1113
|
-
|
|
991
|
+
not have its `contenteditable` attribute set. (Note that this
|
|
992
|
+
doesn't affect API calls that change the editor content, even
|
|
993
|
+
when those are bound to keys or buttons. See the
|
|
1114
994
|
[`readOnly`](https://codemirror.net/6/docs/ref/#state.EditorState.readOnly) facet for that.)
|
|
1115
995
|
*/
|
|
1116
996
|
static editable: Facet<boolean, boolean>;
|
|
@@ -1129,17 +1009,44 @@ declare class EditorView {
|
|
|
1129
1009
|
*/
|
|
1130
1010
|
static dragMovesSelection: Facet<(event: MouseEvent) => boolean, readonly ((event: MouseEvent) => boolean)[]>;
|
|
1131
1011
|
/**
|
|
1132
|
-
Facet used to configure whether a given selecting click adds
|
|
1133
|
-
|
|
1012
|
+
Facet used to configure whether a given selecting click adds a
|
|
1013
|
+
new range to the existing selection or replaces it entirely. The
|
|
1014
|
+
default behavior is to check `event.metaKey` on macOS, and
|
|
1015
|
+
`event.ctrlKey` elsewhere.
|
|
1134
1016
|
*/
|
|
1135
1017
|
static clickAddsSelectionRange: Facet<(event: MouseEvent) => boolean, readonly ((event: MouseEvent) => boolean)[]>;
|
|
1136
1018
|
/**
|
|
1137
1019
|
A facet that determines which [decorations](https://codemirror.net/6/docs/ref/#view.Decoration)
|
|
1138
|
-
are shown in the view.
|
|
1139
|
-
|
|
1140
|
-
|
|
1020
|
+
are shown in the view. Decorations can be provided in two
|
|
1021
|
+
ways—directly, or via a function that takes an editor view.
|
|
1022
|
+
|
|
1023
|
+
Only decoration sets provided directly are allowed to influence
|
|
1024
|
+
the editor's vertical layout structure. The ones provided as
|
|
1025
|
+
functions are called _after_ the new viewport has been computed,
|
|
1026
|
+
and thus **must not** introduce block widgets or replacing
|
|
1027
|
+
decorations that cover line breaks.
|
|
1028
|
+
*/
|
|
1029
|
+
static decorations: Facet<DecorationSet | ((view: EditorView) => DecorationSet), readonly (DecorationSet | ((view: EditorView) => DecorationSet))[]>;
|
|
1030
|
+
/**
|
|
1031
|
+
Used to provide ranges that should be treated as atoms as far as
|
|
1032
|
+
cursor motion is concerned. This causes methods like
|
|
1033
|
+
[`moveByChar`](https://codemirror.net/6/docs/ref/#view.EditorView.moveByChar) and
|
|
1034
|
+
[`moveVertically`](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) (and the
|
|
1035
|
+
commands built on top of them) to skip across such regions when
|
|
1036
|
+
a selection endpoint would enter them. This does _not_ prevent
|
|
1037
|
+
direct programmatic [selection
|
|
1038
|
+
updates](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) from moving into such
|
|
1039
|
+
regions.
|
|
1141
1040
|
*/
|
|
1142
|
-
static
|
|
1041
|
+
static atomicRanges: Facet<(view: EditorView) => _codemirror_state.RangeSet<any>, readonly ((view: EditorView) => _codemirror_state.RangeSet<any>)[]>;
|
|
1042
|
+
/**
|
|
1043
|
+
Facet that allows extensions to provide additional scroll
|
|
1044
|
+
margins (space around the sides of the scrolling element that
|
|
1045
|
+
should be considered invisible). This can be useful when the
|
|
1046
|
+
plugin introduces elements that cover part of that element (for
|
|
1047
|
+
example a horizontally fixed gutter).
|
|
1048
|
+
*/
|
|
1049
|
+
static scrollMargins: Facet<(view: EditorView) => Partial<Rect> | null, readonly ((view: EditorView) => Partial<Rect> | null)[]>;
|
|
1143
1050
|
/**
|
|
1144
1051
|
Create a theme extension. The first argument can be a
|
|
1145
1052
|
[`style-mod`](https://github.com/marijnh/style-mod#documentation)
|
|
@@ -1241,7 +1148,7 @@ Modifiers can be given in any order. `Shift-` (or `s-`), `Alt-` (or
|
|
|
1241
1148
|
|
|
1242
1149
|
When a key binding contains multiple key names separated by
|
|
1243
1150
|
spaces, it represents a multi-stroke binding, which will fire when
|
|
1244
|
-
the user presses the given keys after each other
|
|
1151
|
+
the user presses the given keys after each other.
|
|
1245
1152
|
|
|
1246
1153
|
You can use `Mod-` as a shorthand for `Cmd-` on Mac and `Ctrl-` on
|
|
1247
1154
|
other platforms. So `Mod-b` is `Ctrl-b` on Linux but `Cmd-b` on
|
|
@@ -1285,8 +1192,8 @@ interface KeyBinding {
|
|
|
1285
1192
|
content (the `"editor"` scope). Some extensions, mostly those
|
|
1286
1193
|
that define their own panels, might want to allow you to
|
|
1287
1194
|
register bindings local to that panel. Such bindings should use
|
|
1288
|
-
a custom scope name. You may also
|
|
1289
|
-
|
|
1195
|
+
a custom scope name. You may also assign multiple scope names to
|
|
1196
|
+
a binding, separating them by spaces.
|
|
1290
1197
|
*/
|
|
1291
1198
|
scope?: string;
|
|
1292
1199
|
/**
|
|
@@ -1311,7 +1218,7 @@ for a given key, no further handlers are called.
|
|
|
1311
1218
|
declare const keymap: Facet<readonly KeyBinding[], readonly (readonly KeyBinding[])[]>;
|
|
1312
1219
|
/**
|
|
1313
1220
|
Run the key handlers registered for a given scope. The event
|
|
1314
|
-
object should be `"keydown"` event. Returns true if any of the
|
|
1221
|
+
object should be a `"keydown"` event. Returns true if any of the
|
|
1315
1222
|
handlers handled it.
|
|
1316
1223
|
*/
|
|
1317
1224
|
declare function runScopeHandlers(view: EditorView, event: KeyboardEvent, scope: string): boolean;
|
|
@@ -1462,7 +1369,7 @@ declare class MatchDecorator {
|
|
|
1462
1369
|
view's viewport. You'll want to call this when initializing your
|
|
1463
1370
|
plugin.
|
|
1464
1371
|
*/
|
|
1465
|
-
createDeco(view: EditorView):
|
|
1372
|
+
createDeco(view: EditorView): _codemirror_state.RangeSet<Decoration>;
|
|
1466
1373
|
/**
|
|
1467
1374
|
Update a set of decorations for a view update. `deco` _must_ be
|
|
1468
1375
|
the set of decorations produced by _this_ `MatchDecorator` for
|
|
@@ -1472,4 +1379,388 @@ declare class MatchDecorator {
|
|
|
1472
1379
|
private updateRange;
|
|
1473
1380
|
}
|
|
1474
1381
|
|
|
1475
|
-
|
|
1382
|
+
/**
|
|
1383
|
+
Create an extension that enables rectangular selections. By
|
|
1384
|
+
default, it will react to left mouse drag with the Alt key held
|
|
1385
|
+
down. When such a selection occurs, the text within the rectangle
|
|
1386
|
+
that was dragged over will be selected, as one selection
|
|
1387
|
+
[range](https://codemirror.net/6/docs/ref/#state.SelectionRange) per line.
|
|
1388
|
+
*/
|
|
1389
|
+
declare function rectangularSelection(options?: {
|
|
1390
|
+
/**
|
|
1391
|
+
A custom predicate function, which takes a `mousedown` event and
|
|
1392
|
+
returns true if it should be used for rectangular selection.
|
|
1393
|
+
*/
|
|
1394
|
+
eventFilter?: (event: MouseEvent) => boolean;
|
|
1395
|
+
}): Extension;
|
|
1396
|
+
/**
|
|
1397
|
+
Returns an extension that turns the pointer cursor into a
|
|
1398
|
+
crosshair when a given modifier key, defaulting to Alt, is held
|
|
1399
|
+
down. Can serve as a visual hint that rectangular selection is
|
|
1400
|
+
going to happen when paired with
|
|
1401
|
+
[`rectangularSelection`](https://codemirror.net/6/docs/ref/#view.rectangularSelection).
|
|
1402
|
+
*/
|
|
1403
|
+
declare function crosshairCursor(options?: {
|
|
1404
|
+
key?: "Alt" | "Control" | "Shift" | "Meta";
|
|
1405
|
+
}): Extension;
|
|
1406
|
+
|
|
1407
|
+
/**
|
|
1408
|
+
Creates an extension that configures tooltip behavior.
|
|
1409
|
+
*/
|
|
1410
|
+
declare function tooltips(config?: {
|
|
1411
|
+
/**
|
|
1412
|
+
By default, tooltips use `"fixed"`
|
|
1413
|
+
[positioning](https://developer.mozilla.org/en-US/docs/Web/CSS/position),
|
|
1414
|
+
which has the advantage that tooltips don't get cut off by
|
|
1415
|
+
scrollable parent elements. However, CSS rules like `contain:
|
|
1416
|
+
layout` can break fixed positioning in child nodes, which can be
|
|
1417
|
+
worked about by using `"absolute"` here.
|
|
1418
|
+
|
|
1419
|
+
On iOS, which at the time of writing still doesn't properly
|
|
1420
|
+
support fixed positioning, the library always uses absolute
|
|
1421
|
+
positioning.
|
|
1422
|
+
*/
|
|
1423
|
+
position?: "fixed" | "absolute";
|
|
1424
|
+
/**
|
|
1425
|
+
The element to put the tooltips into. By default, they are put
|
|
1426
|
+
in the editor (`cm-editor`) element, and that is usually what
|
|
1427
|
+
you want. But in some layouts that can lead to positioning
|
|
1428
|
+
issues, and you need to use a different parent to work around
|
|
1429
|
+
those.
|
|
1430
|
+
*/
|
|
1431
|
+
parent?: HTMLElement;
|
|
1432
|
+
/**
|
|
1433
|
+
By default, when figuring out whether there is room for a
|
|
1434
|
+
tooltip at a given position, the extension considers the entire
|
|
1435
|
+
space between 0,0 and `innerWidth`,`innerHeight` to be available
|
|
1436
|
+
for showing tooltips. You can provide a function here that
|
|
1437
|
+
returns an alternative rectangle.
|
|
1438
|
+
*/
|
|
1439
|
+
tooltipSpace?: (view: EditorView) => {
|
|
1440
|
+
top: number;
|
|
1441
|
+
left: number;
|
|
1442
|
+
bottom: number;
|
|
1443
|
+
right: number;
|
|
1444
|
+
};
|
|
1445
|
+
}): Extension;
|
|
1446
|
+
/**
|
|
1447
|
+
Describes a tooltip. Values of this type, when provided through
|
|
1448
|
+
the [`showTooltip`](https://codemirror.net/6/docs/ref/#view.showTooltip) facet, control the
|
|
1449
|
+
individual tooltips on the editor.
|
|
1450
|
+
*/
|
|
1451
|
+
interface Tooltip {
|
|
1452
|
+
/**
|
|
1453
|
+
The document position at which to show the tooltip.
|
|
1454
|
+
*/
|
|
1455
|
+
pos: number;
|
|
1456
|
+
/**
|
|
1457
|
+
The end of the range annotated by this tooltip, if different
|
|
1458
|
+
from `pos`.
|
|
1459
|
+
*/
|
|
1460
|
+
end?: number;
|
|
1461
|
+
/**
|
|
1462
|
+
A constructor function that creates the tooltip's [DOM
|
|
1463
|
+
representation](https://codemirror.net/6/docs/ref/#view.TooltipView).
|
|
1464
|
+
*/
|
|
1465
|
+
create(view: EditorView): TooltipView;
|
|
1466
|
+
/**
|
|
1467
|
+
Whether the tooltip should be shown above or below the target
|
|
1468
|
+
position. Not guaranteed to be respected for hover tooltips
|
|
1469
|
+
since all hover tooltips for the same range are always
|
|
1470
|
+
positioned together. Defaults to false.
|
|
1471
|
+
*/
|
|
1472
|
+
above?: boolean;
|
|
1473
|
+
/**
|
|
1474
|
+
Whether the `above` option should be honored when there isn't
|
|
1475
|
+
enough space on that side to show the tooltip inside the
|
|
1476
|
+
viewport. Defaults to false.
|
|
1477
|
+
*/
|
|
1478
|
+
strictSide?: boolean;
|
|
1479
|
+
/**
|
|
1480
|
+
When set to true, show a triangle connecting the tooltip element
|
|
1481
|
+
to position `pos`.
|
|
1482
|
+
*/
|
|
1483
|
+
arrow?: boolean;
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
Describes the way a tooltip is displayed.
|
|
1487
|
+
*/
|
|
1488
|
+
interface TooltipView {
|
|
1489
|
+
/**
|
|
1490
|
+
The DOM element to position over the editor.
|
|
1491
|
+
*/
|
|
1492
|
+
dom: HTMLElement;
|
|
1493
|
+
/**
|
|
1494
|
+
Adjust the position of the tooltip relative to its anchor
|
|
1495
|
+
position. A positive `x` value will move the tooltip
|
|
1496
|
+
horizontally along with the text direction (so right in
|
|
1497
|
+
left-to-right context, left in right-to-left). A positive `y`
|
|
1498
|
+
will move the tooltip up when it is above its anchor, and down
|
|
1499
|
+
otherwise.
|
|
1500
|
+
*/
|
|
1501
|
+
offset?: {
|
|
1502
|
+
x: number;
|
|
1503
|
+
y: number;
|
|
1504
|
+
};
|
|
1505
|
+
/**
|
|
1506
|
+
By default, a tooltip's screen position will be based on the
|
|
1507
|
+
text position of its `pos` property. This method can be provided
|
|
1508
|
+
to make the tooltip view itself responsible for finding its
|
|
1509
|
+
screen position.
|
|
1510
|
+
*/
|
|
1511
|
+
getCoords?: (pos: number) => Rect;
|
|
1512
|
+
/**
|
|
1513
|
+
By default, tooltips are moved when they overlap with other
|
|
1514
|
+
tooltips. Set this to `true` to disable that behavior for this
|
|
1515
|
+
tooltip.
|
|
1516
|
+
*/
|
|
1517
|
+
overlap?: boolean;
|
|
1518
|
+
/**
|
|
1519
|
+
Called after the tooltip is added to the DOM for the first time.
|
|
1520
|
+
*/
|
|
1521
|
+
mount?(view: EditorView): void;
|
|
1522
|
+
/**
|
|
1523
|
+
Update the DOM element for a change in the view's state.
|
|
1524
|
+
*/
|
|
1525
|
+
update?(update: ViewUpdate): void;
|
|
1526
|
+
/**
|
|
1527
|
+
Called when the tooltip has been (re)positioned.
|
|
1528
|
+
*/
|
|
1529
|
+
positioned?(): void;
|
|
1530
|
+
}
|
|
1531
|
+
/**
|
|
1532
|
+
Facet to which an extension can add a value to show a tooltip.
|
|
1533
|
+
*/
|
|
1534
|
+
declare const showTooltip: Facet<Tooltip | null, readonly (Tooltip | null)[]>;
|
|
1535
|
+
/**
|
|
1536
|
+
Set up a hover tooltip, which shows up when the pointer hovers
|
|
1537
|
+
over ranges of text. The callback is called when the mouse hovers
|
|
1538
|
+
over the document text. It should, if there is a tooltip
|
|
1539
|
+
associated with position `pos`, return the tooltip description
|
|
1540
|
+
(either directly or in a promise). The `side` argument indicates
|
|
1541
|
+
on which side of the position the pointer is—it will be -1 if the
|
|
1542
|
+
pointer is before the position, 1 if after the position.
|
|
1543
|
+
|
|
1544
|
+
Note that all hover tooltips are hosted within a single tooltip
|
|
1545
|
+
container element. This allows multiple tooltips over the same
|
|
1546
|
+
range to be "merged" together without overlapping.
|
|
1547
|
+
*/
|
|
1548
|
+
declare function hoverTooltip(source: (view: EditorView, pos: number, side: -1 | 1) => Tooltip | null | Promise<Tooltip | null>, options?: {
|
|
1549
|
+
/**
|
|
1550
|
+
Controls whether a transaction hides the tooltip. The default
|
|
1551
|
+
is to not hide.
|
|
1552
|
+
*/
|
|
1553
|
+
hideOn?: (tr: Transaction, tooltip: Tooltip) => boolean;
|
|
1554
|
+
/**
|
|
1555
|
+
When enabled (this defaults to false), close the tooltip
|
|
1556
|
+
whenever the document changes or the selection is set.
|
|
1557
|
+
*/
|
|
1558
|
+
hideOnChange?: boolean | "touch";
|
|
1559
|
+
/**
|
|
1560
|
+
Hover time after which the tooltip should appear, in
|
|
1561
|
+
milliseconds. Defaults to 300ms.
|
|
1562
|
+
*/
|
|
1563
|
+
hoverTime?: number;
|
|
1564
|
+
}): Extension;
|
|
1565
|
+
/**
|
|
1566
|
+
Get the active tooltip view for a given tooltip, if available.
|
|
1567
|
+
*/
|
|
1568
|
+
declare function getTooltip(view: EditorView, tooltip: Tooltip): TooltipView | null;
|
|
1569
|
+
/**
|
|
1570
|
+
Returns true if any hover tooltips are currently active.
|
|
1571
|
+
*/
|
|
1572
|
+
declare function hasHoverTooltips(state: EditorState): boolean;
|
|
1573
|
+
/**
|
|
1574
|
+
Transaction effect that closes all hover tooltips.
|
|
1575
|
+
*/
|
|
1576
|
+
declare const closeHoverTooltips: StateEffect<null>;
|
|
1577
|
+
/**
|
|
1578
|
+
Tell the tooltip extension to recompute the position of the active
|
|
1579
|
+
tooltips. This can be useful when something happens (such as a
|
|
1580
|
+
re-positioning or CSS change affecting the editor) that could
|
|
1581
|
+
invalidate the existing tooltip positions.
|
|
1582
|
+
*/
|
|
1583
|
+
declare function repositionTooltips(view: EditorView): void;
|
|
1584
|
+
|
|
1585
|
+
declare type PanelConfig = {
|
|
1586
|
+
/**
|
|
1587
|
+
By default, panels will be placed inside the editor's DOM
|
|
1588
|
+
structure. You can use this option to override where panels with
|
|
1589
|
+
`top: true` are placed.
|
|
1590
|
+
*/
|
|
1591
|
+
topContainer?: HTMLElement;
|
|
1592
|
+
/**
|
|
1593
|
+
Override where panels with `top: false` are placed.
|
|
1594
|
+
*/
|
|
1595
|
+
bottomContainer?: HTMLElement;
|
|
1596
|
+
};
|
|
1597
|
+
/**
|
|
1598
|
+
Configures the panel-managing extension.
|
|
1599
|
+
*/
|
|
1600
|
+
declare function panels(config?: PanelConfig): Extension;
|
|
1601
|
+
/**
|
|
1602
|
+
Object that describes an active panel.
|
|
1603
|
+
*/
|
|
1604
|
+
interface Panel {
|
|
1605
|
+
/**
|
|
1606
|
+
The element representing this panel. The library will add the
|
|
1607
|
+
`"cm-panel"` DOM class to this.
|
|
1608
|
+
*/
|
|
1609
|
+
dom: HTMLElement;
|
|
1610
|
+
/**
|
|
1611
|
+
Optionally called after the panel has been added to the editor.
|
|
1612
|
+
*/
|
|
1613
|
+
mount?(): void;
|
|
1614
|
+
/**
|
|
1615
|
+
Update the DOM for a given view update.
|
|
1616
|
+
*/
|
|
1617
|
+
update?(update: ViewUpdate): void;
|
|
1618
|
+
/**
|
|
1619
|
+
Called when the panel is removed from the editor or the editor
|
|
1620
|
+
is destroyed.
|
|
1621
|
+
*/
|
|
1622
|
+
destroy?(): void;
|
|
1623
|
+
/**
|
|
1624
|
+
Whether the panel should be at the top or bottom of the editor.
|
|
1625
|
+
Defaults to false.
|
|
1626
|
+
*/
|
|
1627
|
+
top?: boolean;
|
|
1628
|
+
}
|
|
1629
|
+
/**
|
|
1630
|
+
Get the active panel created by the given constructor, if any.
|
|
1631
|
+
This can be useful when you need access to your panels' DOM
|
|
1632
|
+
structure.
|
|
1633
|
+
*/
|
|
1634
|
+
declare function getPanel(view: EditorView, panel: PanelConstructor): Panel | null;
|
|
1635
|
+
/**
|
|
1636
|
+
A function that initializes a panel. Used in
|
|
1637
|
+
[`showPanel`](https://codemirror.net/6/docs/ref/#view.showPanel).
|
|
1638
|
+
*/
|
|
1639
|
+
declare type PanelConstructor = (view: EditorView) => Panel;
|
|
1640
|
+
/**
|
|
1641
|
+
Opening a panel is done by providing a constructor function for
|
|
1642
|
+
the panel through this facet. (The panel is closed again when its
|
|
1643
|
+
constructor is no longer provided.) Values of `null` are ignored.
|
|
1644
|
+
*/
|
|
1645
|
+
declare const showPanel: Facet<PanelConstructor | null, readonly (PanelConstructor | null)[]>;
|
|
1646
|
+
|
|
1647
|
+
/**
|
|
1648
|
+
A gutter marker represents a bit of information attached to a line
|
|
1649
|
+
in a specific gutter. Your own custom markers have to extend this
|
|
1650
|
+
class.
|
|
1651
|
+
*/
|
|
1652
|
+
declare abstract class GutterMarker extends RangeValue {
|
|
1653
|
+
/**
|
|
1654
|
+
Compare this marker to another marker of the same type.
|
|
1655
|
+
*/
|
|
1656
|
+
eq(other: GutterMarker): boolean;
|
|
1657
|
+
/**
|
|
1658
|
+
Render the DOM node for this marker, if any.
|
|
1659
|
+
*/
|
|
1660
|
+
toDOM?(view: EditorView): Node;
|
|
1661
|
+
/**
|
|
1662
|
+
This property can be used to add CSS classes to the gutter
|
|
1663
|
+
element that contains this marker.
|
|
1664
|
+
*/
|
|
1665
|
+
elementClass: string;
|
|
1666
|
+
/**
|
|
1667
|
+
Called if the marker has a `toDOM` method and its representation
|
|
1668
|
+
was removed from a gutter.
|
|
1669
|
+
*/
|
|
1670
|
+
destroy(dom: Node): void;
|
|
1671
|
+
}
|
|
1672
|
+
/**
|
|
1673
|
+
Facet used to add a class to all gutter elements for a given line.
|
|
1674
|
+
Markers given to this facet should _only_ define an
|
|
1675
|
+
[`elementclass`](https://codemirror.net/6/docs/ref/#view.GutterMarker.elementClass), not a
|
|
1676
|
+
[`toDOM`](https://codemirror.net/6/docs/ref/#view.GutterMarker.toDOM) (or the marker will appear
|
|
1677
|
+
in all gutters for the line).
|
|
1678
|
+
*/
|
|
1679
|
+
declare const gutterLineClass: Facet<RangeSet<GutterMarker>, readonly RangeSet<GutterMarker>[]>;
|
|
1680
|
+
declare type Handlers = {
|
|
1681
|
+
[event: string]: (view: EditorView, line: BlockInfo, event: Event) => boolean;
|
|
1682
|
+
};
|
|
1683
|
+
interface GutterConfig {
|
|
1684
|
+
/**
|
|
1685
|
+
An extra CSS class to be added to the wrapper (`cm-gutter`)
|
|
1686
|
+
element.
|
|
1687
|
+
*/
|
|
1688
|
+
class?: string;
|
|
1689
|
+
/**
|
|
1690
|
+
Controls whether empty gutter elements should be rendered.
|
|
1691
|
+
Defaults to false.
|
|
1692
|
+
*/
|
|
1693
|
+
renderEmptyElements?: boolean;
|
|
1694
|
+
/**
|
|
1695
|
+
Retrieve a set of markers to use in this gutter.
|
|
1696
|
+
*/
|
|
1697
|
+
markers?: (view: EditorView) => (RangeSet<GutterMarker> | readonly RangeSet<GutterMarker>[]);
|
|
1698
|
+
/**
|
|
1699
|
+
Can be used to optionally add a single marker to every line.
|
|
1700
|
+
*/
|
|
1701
|
+
lineMarker?: (view: EditorView, line: BlockInfo, otherMarkers: readonly GutterMarker[]) => GutterMarker | null;
|
|
1702
|
+
/**
|
|
1703
|
+
If line markers depend on additional state, and should be
|
|
1704
|
+
updated when that changes, pass a predicate here that checks
|
|
1705
|
+
whether a given view update might change the line markers.
|
|
1706
|
+
*/
|
|
1707
|
+
lineMarkerChange?: null | ((update: ViewUpdate) => boolean);
|
|
1708
|
+
/**
|
|
1709
|
+
Add a hidden spacer element that gives the gutter its base
|
|
1710
|
+
width.
|
|
1711
|
+
*/
|
|
1712
|
+
initialSpacer?: null | ((view: EditorView) => GutterMarker);
|
|
1713
|
+
/**
|
|
1714
|
+
Update the spacer element when the view is updated.
|
|
1715
|
+
*/
|
|
1716
|
+
updateSpacer?: null | ((spacer: GutterMarker, update: ViewUpdate) => GutterMarker);
|
|
1717
|
+
/**
|
|
1718
|
+
Supply event handlers for DOM events on this gutter.
|
|
1719
|
+
*/
|
|
1720
|
+
domEventHandlers?: Handlers;
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
Define an editor gutter. The order in which the gutters appear is
|
|
1724
|
+
determined by their extension priority.
|
|
1725
|
+
*/
|
|
1726
|
+
declare function gutter(config: GutterConfig): Extension;
|
|
1727
|
+
/**
|
|
1728
|
+
The gutter-drawing plugin is automatically enabled when you add a
|
|
1729
|
+
gutter, but you can use this function to explicitly configure it.
|
|
1730
|
+
|
|
1731
|
+
Unless `fixed` is explicitly set to `false`, the gutters are
|
|
1732
|
+
fixed, meaning they don't scroll along with the content
|
|
1733
|
+
horizontally (except on Internet Explorer, which doesn't support
|
|
1734
|
+
CSS [`position:
|
|
1735
|
+
sticky`](https://developer.mozilla.org/en-US/docs/Web/CSS/position#sticky)).
|
|
1736
|
+
*/
|
|
1737
|
+
declare function gutters(config?: {
|
|
1738
|
+
fixed?: boolean;
|
|
1739
|
+
}): Extension;
|
|
1740
|
+
interface LineNumberConfig {
|
|
1741
|
+
/**
|
|
1742
|
+
How to display line numbers. Defaults to simply converting them
|
|
1743
|
+
to string.
|
|
1744
|
+
*/
|
|
1745
|
+
formatNumber?: (lineNo: number, state: EditorState) => string;
|
|
1746
|
+
/**
|
|
1747
|
+
Supply event handlers for DOM events on this gutter.
|
|
1748
|
+
*/
|
|
1749
|
+
domEventHandlers?: Handlers;
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
Facet used to provide markers to the line number gutter.
|
|
1753
|
+
*/
|
|
1754
|
+
declare const lineNumberMarkers: Facet<RangeSet<GutterMarker>, readonly RangeSet<GutterMarker>[]>;
|
|
1755
|
+
/**
|
|
1756
|
+
Create a line number gutter extension.
|
|
1757
|
+
*/
|
|
1758
|
+
declare function lineNumbers(config?: LineNumberConfig): Extension;
|
|
1759
|
+
/**
|
|
1760
|
+
Returns an extension that adds a `cm-activeLineGutter` class to
|
|
1761
|
+
all gutter elements on the [active
|
|
1762
|
+
line](https://codemirror.net/6/docs/ref/#view.highlightActiveLine).
|
|
1763
|
+
*/
|
|
1764
|
+
declare function highlightActiveLineGutter(): Extension;
|
|
1765
|
+
|
|
1766
|
+
export { BidiSpan, BlockInfo, BlockType, Command, DOMEventHandlers, DOMEventMap, Decoration, DecorationSet, Direction, EditorView, GutterMarker, KeyBinding, MatchDecorator, MouseSelectionStyle, Panel, PanelConstructor, PluginSpec, PluginValue, Rect, Tooltip, TooltipView, ViewPlugin, ViewUpdate, WidgetType, closeHoverTooltips, crosshairCursor, drawSelection, dropCursor, getPanel, getTooltip, gutter, gutterLineClass, gutters, hasHoverTooltips, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, hoverTooltip, keymap, lineNumberMarkers, lineNumbers, logException, panels, placeholder, rectangularSelection, repositionTooltips, runScopeHandlers, scrollPastEnd, showPanel, showTooltip, tooltips };
|