@codemirror/view 0.19.32 → 0.19.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as _codemirror_rangeset from '@codemirror/rangeset';
2
2
  import { RangeSet, RangeValue, Range } from '@codemirror/rangeset';
3
3
  export { Range } from '@codemirror/rangeset';
4
4
  import * as _codemirror_state from '@codemirror/state';
5
- import { EditorState, Extension, Transaction, ChangeSet, EditorSelection, TransactionSpec, SelectionRange, Facet } from '@codemirror/state';
5
+ import { EditorState, Extension, Transaction, ChangeSet, EditorSelection, TransactionSpec, SelectionRange, StateEffect, Facet } from '@codemirror/state';
6
6
  import { Line } from '@codemirror/text';
7
7
  import { StyleModule, StyleSpec } from 'style-mod';
8
8
 
@@ -264,6 +264,7 @@ interface Rect {
264
264
  readonly top: number;
265
265
  readonly bottom: number;
266
266
  }
267
+ declare type ScrollStrategy = "nearest" | "start" | "end" | "center";
267
268
 
268
269
  /**
269
270
  Command functions are used in key bindings and other types of user
@@ -339,11 +340,13 @@ declare class PluginField<T> {
339
340
  **Note**: For reasons of data flow (plugins are only updated
340
341
  after the viewport is computed), decorations produced by plugins
341
342
  are _not_ taken into account when predicting the vertical layout
342
- structure of the editor. Thus, things like large widgets or big
343
- replacements (i.e. code folding) should be provided through the
344
- state-level [`decorations` facet](https://codemirror.net/6/docs/ref/#view.EditorView^decorations),
345
- not this plugin field. Specifically, replacing decorations that
346
- cross line boundaries will break if provided through a plugin.
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.
347
350
  */
348
351
  static decorations: PluginField<DecorationSet>;
349
352
  /**
@@ -469,12 +472,13 @@ declare class ViewUpdate {
469
472
  */
470
473
  get viewportChanged(): boolean;
471
474
  /**
472
- Indicates whether the line height in the editor changed in this update.
475
+ Indicates whether the height of an element in the editor changed
476
+ in this update.
473
477
  */
474
478
  get heightChanged(): boolean;
475
479
  /**
476
- Returns true when the document changed or the size of the editor
477
- or the lines or characters within it has changed.
480
+ Returns true when the document was modified or the size of the
481
+ editor, or elements within the editor, changed.
478
482
  */
479
483
  get geometryChanged(): boolean;
480
484
  /**
@@ -936,8 +940,11 @@ declare class EditorView {
936
940
  */
937
941
  posAtDOM(node: Node, offset?: number): number;
938
942
  /**
939
- Get the document position at the given screen coordinates.
940
- Returns null if no valid position could be found.
943
+ Get the document position at the given screen coordinates. For
944
+ positions not covered by the visible viewport's DOM structure,
945
+ this will return null, unless `false` is passed as second
946
+ argument, in which case it'll return an estimated position that
947
+ would be near the coordinates if it were rendered.
941
948
  */
942
949
  posAtCoords(coords: {
943
950
  x: number;
@@ -1006,14 +1013,49 @@ declare class EditorView {
1006
1013
  /**
1007
1014
  Effect that can be [added](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) to a
1008
1015
  transaction to make it scroll the given range into view.
1016
+
1017
+ *Deprecated*. Use [`scrollIntoView`](https://codemirror.net/6/docs/ref/#view.EditorView^scrollIntoView) instead.
1009
1018
  */
1010
1019
  static scrollTo: _codemirror_state.StateEffectType<SelectionRange>;
1011
1020
  /**
1012
1021
  Effect that makes the editor scroll the given range to the
1013
1022
  center of the visible view.
1023
+
1024
+ *Deprecated*. Use [`scrollIntoView`](https://codemirror.net/6/docs/ref/#view.EditorView^scrollIntoView) instead.
1014
1025
  */
1015
1026
  static centerOn: _codemirror_state.StateEffectType<SelectionRange>;
1016
1027
  /**
1028
+ Returns an effect that can be
1029
+ [added](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) to a transaction to
1030
+ cause it to scroll the given position or range into view.
1031
+ */
1032
+ static scrollIntoView(pos: number | SelectionRange, options?: {
1033
+ /**
1034
+ By default (`"nearest"`) the position will be vertically
1035
+ scrolled only the minimal amount required to move the given
1036
+ position into view. You can set this to `"start"` to move it
1037
+ to the top of the view, `"end"` to move it to the bottom, or
1038
+ `"center"` to move it to the center.
1039
+ */
1040
+ y?: ScrollStrategy;
1041
+ /**
1042
+ Effect similar to
1043
+ [`y`](https://codemirror.net/6/docs/ref/#view.EditorView^scrollIntoView^options.y), but for the
1044
+ horizontal scroll position.
1045
+ */
1046
+ x?: ScrollStrategy;
1047
+ /**
1048
+ Extra vertical distance to add when moving something into
1049
+ view. Not used with the `"center"` strategy. Defaults to 5.
1050
+ */
1051
+ yMargin?: number;
1052
+ /**
1053
+ Extra horizontal distance to add. Not used with the `"center"`
1054
+ strategy. Defaults to 5.
1055
+ */
1056
+ xMargin?: number;
1057
+ }): StateEffect<unknown>;
1058
+ /**
1017
1059
  Facet to add a [style
1018
1060
  module](https://github.com/marijnh/style-mod#documentation) to
1019
1061
  an editor view. The view will ensure that the module is