@codemirror/state 0.18.7 → 0.19.3

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 CHANGED
@@ -1,3 +1,35 @@
1
+ ## 0.19.3 (2021-11-03)
2
+
3
+ ### New features
4
+
5
+ The precedence levels (under `Prec`) now have more generic names, because their 'meaningful' names were entirely inappropriate in many situations.
6
+
7
+ ## 0.19.2 (2021-09-13)
8
+
9
+ ### New features
10
+
11
+ The editor state now has a `readOnly` property with a matching facet to control its value.
12
+
13
+ ## 0.19.1 (2021-08-15)
14
+
15
+ ### Bug fixes
16
+
17
+ Fix a bug where `wordAt` never returned a useful result.
18
+
19
+ ## 0.19.0 (2021-08-11)
20
+
21
+ ### Breaking changes
22
+
23
+ User event strings now work differently—the events emitted by the core packages follow a different system, and hierarchical event tags can be created by separating the words with dots.
24
+
25
+ ### New features
26
+
27
+ `languageDataAt` now takes an optional `side` argument to specificy which side of the position you're interested in.
28
+
29
+ It is now possible to add a user event annotation with a direct `userEvent` property on a transaction spec.
30
+
31
+ Transactions now have an `isUserEvent` method that can be used to check if it is (a subtype of) some user event type.
32
+
1
33
  ## 0.18.7 (2021-05-04)
2
34
 
3
35
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -1106,7 +1106,7 @@ class StateField {
1106
1106
  */
1107
1107
  get extension() { return this; }
1108
1108
  }
1109
- const Prec_ = { fallback: 3, default: 2, extend: 1, override: 0 };
1109
+ const Prec_ = { lowest: 4, low: 3, default: 2, high: 1, highest: 0 };
1110
1110
  function prec(value) {
1111
1111
  return (ext) => new PrecExtension(ext, value);
1112
1112
  }
@@ -1122,23 +1122,42 @@ precedence and then by order within each precedence.
1122
1122
  */
1123
1123
  const Prec = {
1124
1124
  /**
1125
- A precedence below the default precedence, which will cause
1126
- default-precedence extensions to override it even if they are
1127
- specified later in the extension ordering.
1125
+ The lowest precedence level. Meant for things that should end up
1126
+ near the end of the extension order.
1128
1127
  */
1129
- fallback: prec(Prec_.fallback),
1128
+ lowest: prec(Prec_.lowest),
1130
1129
  /**
1131
- The regular default precedence.
1130
+ A lower-than-default precedence, for extensions.
1131
+ */
1132
+ low: prec(Prec_.low),
1133
+ /**
1134
+ The default precedence, which is also used for extensions
1135
+ without an explicit precedence.
1132
1136
  */
1133
1137
  default: prec(Prec_.default),
1134
1138
  /**
1135
- A higher-than-default precedence.
1139
+ A higher-than-default precedence, for extensions that should
1140
+ come before those with default precedence.
1136
1141
  */
1137
- extend: prec(Prec_.extend),
1142
+ high: prec(Prec_.high),
1138
1143
  /**
1139
- Precedence above the `default` and `extend` precedences.
1144
+ The highest precedence level, for extensions that should end up
1145
+ near the start of the precedence ordering.
1140
1146
  */
1141
- override: prec(Prec_.override)
1147
+ highest: prec(Prec_.highest),
1148
+ // FIXME Drop these in some future breaking version
1149
+ /**
1150
+ Backwards-compatible synonym for `Prec.lowest`.
1151
+ */
1152
+ fallback: prec(Prec_.lowest),
1153
+ /**
1154
+ Backwards-compatible synonym for `Prec.high`.
1155
+ */
1156
+ extend: prec(Prec_.high),
1157
+ /**
1158
+ Backwards-compatible synonym for `Prec.highest`.
1159
+ */
1160
+ override: prec(Prec_.highest)
1142
1161
  };
1143
1162
  class PrecExtension {
1144
1163
  constructor(inner, prec) {
@@ -1244,7 +1263,7 @@ class Configuration {
1244
1263
  }
1245
1264
  }
1246
1265
  function flatten(extension, compartments, newCompartments) {
1247
- let result = [[], [], [], []];
1266
+ let result = [[], [], [], [], []];
1248
1267
  let seen = new Map();
1249
1268
  function inner(ext, prec) {
1250
1269
  let known = seen.get(ext);
@@ -1321,6 +1340,9 @@ const lineSeparator = Facet.define({
1321
1340
  const changeFilter = Facet.define();
1322
1341
  const transactionFilter = Facet.define();
1323
1342
  const transactionExtender = Facet.define();
1343
+ const readOnly = Facet.define({
1344
+ combine: values => values.length ? values[0] : false
1345
+ });
1324
1346
 
1325
1347
  /**
1326
1348
  Annotations are tagged values that are used to add metadata to
@@ -1564,6 +1586,17 @@ class Transaction {
1564
1586
  [effect](https://codemirror.net/6/docs/ref/#state.StateEffect^reconfigure).
1565
1587
  */
1566
1588
  get reconfigured() { return this.startState.config != this.state.config; }
1589
+ /**
1590
+ Returns true if the transaction has a [user
1591
+ event](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent) annotation that is equal to
1592
+ or more specific than `event`. For example, if the transaction
1593
+ has `"select.pointer"` as user event, `"select"` and
1594
+ `"select.pointer"` will match it.
1595
+ */
1596
+ isUserEvent(event) {
1597
+ let e = this.annotation(Transaction.userEvent);
1598
+ return !!(e && (e == event || e.length > event.length && e.slice(0, event.length) == event && e[event.length] == "."));
1599
+ }
1567
1600
  }
1568
1601
  /**
1569
1602
  Annotation used to store transaction timestamps.
@@ -1571,15 +1604,29 @@ Annotation used to store transaction timestamps.
1571
1604
  Transaction.time = Annotation.define();
1572
1605
  /**
1573
1606
  Annotation used to associate a transaction with a user interface
1574
- event. The view will set this to...
1607
+ event. Holds a string identifying the event, using a
1608
+ dot-separated format to support attaching more specific
1609
+ information. The events used by the core libraries are:
1575
1610
 
1576
- - `"input"` when the user types text
1577
- - `"delete"` when the user deletes the selection or text near the selection
1578
- - `"keyboardselection"` when moving the selection via the keyboard
1579
- - `"pointerselection"` when moving the selection through the pointing device
1580
- - `"paste"` when pasting content
1581
- - `"cut"` when cutting
1582
- - `"drop"` when content is inserted via drag-and-drop
1611
+ - `"input"` when content is entered
1612
+ - `"input.type"` for typed input
1613
+ - `"input.type.compose"` for composition
1614
+ - `"input.paste"` for pasted input
1615
+ - `"input.drop"` when adding content with drag-and-drop
1616
+ - `"input.complete"` when autocompleting
1617
+ - `"delete"` when the user deletes content
1618
+ - `"delete.selection"` when deleting the selection
1619
+ - `"delete.forward"` when deleting forward from the selection
1620
+ - `"delete.backward"` when deleting backward from the selection
1621
+ - `"delete.cut"` when cutting to the clipboard
1622
+ - `"move"` when content is moved
1623
+ - `"move.drop"` when content is moved within the editor through drag-and-drop
1624
+ - `"select"` when explicitly changing the selection
1625
+ - `"select.pointer"` when selecting with a mouse or other pointing device
1626
+ - `"undo"` and `"redo"` for history actions
1627
+
1628
+ Use [`isUserEvent`](https://codemirror.net/6/docs/ref/#state.Transaction.isUserEvent) to check
1629
+ whether the annotation matches a given event.
1583
1630
  */
1584
1631
  Transaction.userEvent = Annotation.define();
1585
1632
  /**
@@ -1636,13 +1683,15 @@ function mergeTransaction(a, b, sequential) {
1636
1683
  };
1637
1684
  }
1638
1685
  function resolveTransactionInner(state, spec, docSize) {
1639
- let sel = spec.selection;
1686
+ let sel = spec.selection, annotations = asArray(spec.annotations);
1687
+ if (spec.userEvent)
1688
+ annotations = annotations.concat(Transaction.userEvent.of(spec.userEvent));
1640
1689
  return {
1641
1690
  changes: spec.changes instanceof ChangeSet ? spec.changes
1642
1691
  : ChangeSet.of(spec.changes || [], docSize, state.facet(lineSeparator)),
1643
1692
  selection: sel && (sel instanceof EditorSelection ? sel : EditorSelection.single(sel.anchor, sel.head)),
1644
1693
  effects: asArray(spec.effects),
1645
- annotations: asArray(spec.annotations),
1694
+ annotations,
1646
1695
  scrollIntoView: !!spec.scrollIntoView
1647
1696
  };
1648
1697
  }
@@ -2015,6 +2064,11 @@ class EditorState {
2015
2064
  */
2016
2065
  get lineBreak() { return this.facet(EditorState.lineSeparator) || "\n"; }
2017
2066
  /**
2067
+ Returns true when the editor is
2068
+ [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only.
2069
+ */
2070
+ get readOnly() { return this.facet(readOnly); }
2071
+ /**
2018
2072
  Look up a translation for the given phrase (via the
2019
2073
  [`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
2020
2074
  original string if no translation is found.
@@ -2029,10 +2083,10 @@ class EditorState {
2029
2083
  Find the values for a given language data field, provided by the
2030
2084
  the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
2031
2085
  */
2032
- languageDataAt(name, pos) {
2086
+ languageDataAt(name, pos, side = -1) {
2033
2087
  let values = [];
2034
2088
  for (let provider of this.facet(languageData)) {
2035
- for (let result of provider(this, pos)) {
2089
+ for (let result of provider(this, pos, side)) {
2036
2090
  if (Object.prototype.hasOwnProperty.call(result, name))
2037
2091
  values.push(result[name]);
2038
2092
  }
@@ -2075,7 +2129,7 @@ class EditorState {
2075
2129
  break;
2076
2130
  end = next;
2077
2131
  }
2078
- return start == end ? EditorSelection.range(start + from, end + from) : null;
2132
+ return start == end ? null : EditorSelection.range(start + from, end + from);
2079
2133
  }
2080
2134
  }
2081
2135
  /**
@@ -2106,6 +2160,20 @@ editor without normalizing line separators.
2106
2160
  */
2107
2161
  EditorState.lineSeparator = lineSeparator;
2108
2162
  /**
2163
+ This facet controls the value of the
2164
+ [`readOnly`](https://codemirror.net/6/docs/ref/#state.EditorState.readOnly) getter, which is
2165
+ consulted by commands and extensions that implement editing
2166
+ functionality to determine whether they should apply. It
2167
+ defaults to false, but when its highest-precedence value is
2168
+ `true`, such functionality disables itself.
2169
+
2170
+ Not to be confused with
2171
+ [`EditorView.editable`](https://codemirror.net/6/docs/ref/#view.EditorView^editable), which
2172
+ controls whether the editor's DOM is set to be editable (and
2173
+ thus focusable).
2174
+ */
2175
+ EditorState.readOnly = readOnly;
2176
+ /**
2109
2177
  Registers translation phrases. The
2110
2178
  [`phrase`](https://codemirror.net/6/docs/ref/#state.EditorState.phrase) method will look through
2111
2179
  all objects registered with this facet to find translations for
@@ -2137,9 +2205,10 @@ Facet used to register a hook that gets a chance to update or
2137
2205
  replace transaction specs before they are applied. This will
2138
2206
  only be applied for transactions that don't have
2139
2207
  [`filter`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter) set to `false`. You
2140
- can either return a single (possibly the input transaction), or
2141
- an array of specs (which will be combined in the same way as the
2142
- arguments to [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update)).
2208
+ can either return a single transaction spec (possibly the input
2209
+ transaction), or an array of specs (which will be combined in
2210
+ the same way as the arguments to
2211
+ [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update)).
2143
2212
 
2144
2213
  When possible, it is recommended to avoid accessing
2145
2214
  [`Transaction.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state) in a filter,
package/dist/index.d.ts CHANGED
@@ -509,21 +509,39 @@ precedence and then by order within each precedence.
509
509
  */
510
510
  declare const Prec: {
511
511
  /**
512
- A precedence below the default precedence, which will cause
513
- default-precedence extensions to override it even if they are
514
- specified later in the extension ordering.
512
+ The lowest precedence level. Meant for things that should end up
513
+ near the end of the extension order.
515
514
  */
516
- fallback: (ext: Extension) => Extension;
515
+ lowest: (ext: Extension) => Extension;
516
+ /**
517
+ A lower-than-default precedence, for extensions.
518
+ */
519
+ low: (ext: Extension) => Extension;
517
520
  /**
518
- The regular default precedence.
521
+ The default precedence, which is also used for extensions
522
+ without an explicit precedence.
519
523
  */
520
524
  default: (ext: Extension) => Extension;
521
525
  /**
522
- A higher-than-default precedence.
526
+ A higher-than-default precedence, for extensions that should
527
+ come before those with default precedence.
528
+ */
529
+ high: (ext: Extension) => Extension;
530
+ /**
531
+ The highest precedence level, for extensions that should end up
532
+ near the start of the precedence ordering.
533
+ */
534
+ highest: (ext: Extension) => Extension;
535
+ /**
536
+ Backwards-compatible synonym for `Prec.lowest`.
537
+ */
538
+ fallback: (ext: Extension) => Extension;
539
+ /**
540
+ Backwards-compatible synonym for `Prec.high`.
523
541
  */
524
542
  extend: (ext: Extension) => Extension;
525
543
  /**
526
- Precedence above the `default` and `extend` precedences.
544
+ Backwards-compatible synonym for `Prec.highest`.
527
545
  */
528
546
  override: (ext: Extension) => Extension;
529
547
  };
@@ -683,6 +701,10 @@ interface TransactionSpec {
683
701
  */
684
702
  annotations?: Annotation<any> | readonly Annotation<any>[];
685
703
  /**
704
+ Shorthand for `annotations: `[`Transaction.userEvent`](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent)[`.of(...)`.
705
+ */
706
+ userEvent?: string;
707
+ /**
686
708
  When set to `true`, the transaction is marked as needing to
687
709
  scroll the current selection into view.
688
710
  */
@@ -773,20 +795,42 @@ declare class Transaction {
773
795
  */
774
796
  get reconfigured(): boolean;
775
797
  /**
798
+ Returns true if the transaction has a [user
799
+ event](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent) annotation that is equal to
800
+ or more specific than `event`. For example, if the transaction
801
+ has `"select.pointer"` as user event, `"select"` and
802
+ `"select.pointer"` will match it.
803
+ */
804
+ isUserEvent(event: string): boolean;
805
+ /**
776
806
  Annotation used to store transaction timestamps.
777
807
  */
778
808
  static time: AnnotationType<number>;
779
809
  /**
780
810
  Annotation used to associate a transaction with a user interface
781
- event. The view will set this to...
811
+ event. Holds a string identifying the event, using a
812
+ dot-separated format to support attaching more specific
813
+ information. The events used by the core libraries are:
814
+
815
+ - `"input"` when content is entered
816
+ - `"input.type"` for typed input
817
+ - `"input.type.compose"` for composition
818
+ - `"input.paste"` for pasted input
819
+ - `"input.drop"` when adding content with drag-and-drop
820
+ - `"input.complete"` when autocompleting
821
+ - `"delete"` when the user deletes content
822
+ - `"delete.selection"` when deleting the selection
823
+ - `"delete.forward"` when deleting forward from the selection
824
+ - `"delete.backward"` when deleting backward from the selection
825
+ - `"delete.cut"` when cutting to the clipboard
826
+ - `"move"` when content is moved
827
+ - `"move.drop"` when content is moved within the editor through drag-and-drop
828
+ - `"select"` when explicitly changing the selection
829
+ - `"select.pointer"` when selecting with a mouse or other pointing device
830
+ - `"undo"` and `"redo"` for history actions
782
831
 
783
- - `"input"` when the user types text
784
- - `"delete"` when the user deletes the selection or text near the selection
785
- - `"keyboardselection"` when moving the selection via the keyboard
786
- - `"pointerselection"` when moving the selection through the pointing device
787
- - `"paste"` when pasting content
788
- - `"cut"` when cutting
789
- - `"drop"` when content is inserted via drag-and-drop
832
+ Use [`isUserEvent`](https://codemirror.net/6/docs/ref/#state.Transaction.isUserEvent) to check
833
+ whether the annotation matches a given event.
790
834
  */
791
835
  static userEvent: AnnotationType<string>;
792
836
  /**
@@ -1000,6 +1044,25 @@ declare class EditorState {
1000
1044
  */
1001
1045
  get lineBreak(): string;
1002
1046
  /**
1047
+ This facet controls the value of the
1048
+ [`readOnly`](https://codemirror.net/6/docs/ref/#state.EditorState.readOnly) getter, which is
1049
+ consulted by commands and extensions that implement editing
1050
+ functionality to determine whether they should apply. It
1051
+ defaults to false, but when its highest-precedence value is
1052
+ `true`, such functionality disables itself.
1053
+
1054
+ Not to be confused with
1055
+ [`EditorView.editable`](https://codemirror.net/6/docs/ref/#view.EditorView^editable), which
1056
+ controls whether the editor's DOM is set to be editable (and
1057
+ thus focusable).
1058
+ */
1059
+ static readOnly: Facet<boolean, boolean>;
1060
+ /**
1061
+ Returns true when the editor is
1062
+ [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only.
1063
+ */
1064
+ get readOnly(): boolean;
1065
+ /**
1003
1066
  Registers translation phrases. The
1004
1067
  [`phrase`](https://codemirror.net/6/docs/ref/#state.EditorState.phrase) method will look through
1005
1068
  all objects registered with this facet to find translations for
@@ -1020,16 +1083,16 @@ declare class EditorState {
1020
1083
  A facet used to register [language
1021
1084
  data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) providers.
1022
1085
  */
1023
- static languageData: Facet<(state: EditorState, pos: number) => readonly {
1086
+ static languageData: Facet<(state: EditorState, pos: number, side: 0 | 1 | -1) => readonly {
1024
1087
  [name: string]: any;
1025
- }[], readonly ((state: EditorState, pos: number) => readonly {
1088
+ }[], readonly ((state: EditorState, pos: number, side: 0 | 1 | -1) => readonly {
1026
1089
  [name: string]: any;
1027
1090
  }[])[]>;
1028
1091
  /**
1029
1092
  Find the values for a given language data field, provided by the
1030
1093
  the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
1031
1094
  */
1032
- languageDataAt<T>(name: string, pos: number): readonly T[];
1095
+ languageDataAt<T>(name: string, pos: number, side?: -1 | 0 | 1): readonly T[];
1033
1096
  /**
1034
1097
  Return a function that can categorize strings (expected to
1035
1098
  represent a single [grapheme cluster](https://codemirror.net/6/docs/ref/#text.findClusterBreak))
@@ -1069,9 +1132,10 @@ declare class EditorState {
1069
1132
  replace transaction specs before they are applied. This will
1070
1133
  only be applied for transactions that don't have
1071
1134
  [`filter`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter) set to `false`. You
1072
- can either return a single (possibly the input transaction), or
1073
- an array of specs (which will be combined in the same way as the
1074
- arguments to [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update)).
1135
+ can either return a single transaction spec (possibly the input
1136
+ transaction), or an array of specs (which will be combined in
1137
+ the same way as the arguments to
1138
+ [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update)).
1075
1139
 
1076
1140
  When possible, it is recommended to avoid accessing
1077
1141
  [`Transaction.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state) in a filter,
package/dist/index.js CHANGED
@@ -1102,7 +1102,7 @@ class StateField {
1102
1102
  */
1103
1103
  get extension() { return this; }
1104
1104
  }
1105
- const Prec_ = { fallback: 3, default: 2, extend: 1, override: 0 };
1105
+ const Prec_ = { lowest: 4, low: 3, default: 2, high: 1, highest: 0 };
1106
1106
  function prec(value) {
1107
1107
  return (ext) => new PrecExtension(ext, value);
1108
1108
  }
@@ -1118,23 +1118,42 @@ precedence and then by order within each precedence.
1118
1118
  */
1119
1119
  const Prec = {
1120
1120
  /**
1121
- A precedence below the default precedence, which will cause
1122
- default-precedence extensions to override it even if they are
1123
- specified later in the extension ordering.
1121
+ The lowest precedence level. Meant for things that should end up
1122
+ near the end of the extension order.
1124
1123
  */
1125
- fallback: /*@__PURE__*/prec(Prec_.fallback),
1124
+ lowest: /*@__PURE__*/prec(Prec_.lowest),
1126
1125
  /**
1127
- The regular default precedence.
1126
+ A lower-than-default precedence, for extensions.
1127
+ */
1128
+ low: /*@__PURE__*/prec(Prec_.low),
1129
+ /**
1130
+ The default precedence, which is also used for extensions
1131
+ without an explicit precedence.
1128
1132
  */
1129
1133
  default: /*@__PURE__*/prec(Prec_.default),
1130
1134
  /**
1131
- A higher-than-default precedence.
1135
+ A higher-than-default precedence, for extensions that should
1136
+ come before those with default precedence.
1132
1137
  */
1133
- extend: /*@__PURE__*/prec(Prec_.extend),
1138
+ high: /*@__PURE__*/prec(Prec_.high),
1134
1139
  /**
1135
- Precedence above the `default` and `extend` precedences.
1140
+ The highest precedence level, for extensions that should end up
1141
+ near the start of the precedence ordering.
1136
1142
  */
1137
- override: /*@__PURE__*/prec(Prec_.override)
1143
+ highest: /*@__PURE__*/prec(Prec_.highest),
1144
+ // FIXME Drop these in some future breaking version
1145
+ /**
1146
+ Backwards-compatible synonym for `Prec.lowest`.
1147
+ */
1148
+ fallback: /*@__PURE__*/prec(Prec_.lowest),
1149
+ /**
1150
+ Backwards-compatible synonym for `Prec.high`.
1151
+ */
1152
+ extend: /*@__PURE__*/prec(Prec_.high),
1153
+ /**
1154
+ Backwards-compatible synonym for `Prec.highest`.
1155
+ */
1156
+ override: /*@__PURE__*/prec(Prec_.highest)
1138
1157
  };
1139
1158
  class PrecExtension {
1140
1159
  constructor(inner, prec) {
@@ -1240,7 +1259,7 @@ class Configuration {
1240
1259
  }
1241
1260
  }
1242
1261
  function flatten(extension, compartments, newCompartments) {
1243
- let result = [[], [], [], []];
1262
+ let result = [[], [], [], [], []];
1244
1263
  let seen = new Map();
1245
1264
  function inner(ext, prec) {
1246
1265
  let known = seen.get(ext);
@@ -1317,6 +1336,9 @@ const lineSeparator = /*@__PURE__*/Facet.define({
1317
1336
  const changeFilter = /*@__PURE__*/Facet.define();
1318
1337
  const transactionFilter = /*@__PURE__*/Facet.define();
1319
1338
  const transactionExtender = /*@__PURE__*/Facet.define();
1339
+ const readOnly = /*@__PURE__*/Facet.define({
1340
+ combine: values => values.length ? values[0] : false
1341
+ });
1320
1342
 
1321
1343
  /**
1322
1344
  Annotations are tagged values that are used to add metadata to
@@ -1560,6 +1582,17 @@ class Transaction {
1560
1582
  [effect](https://codemirror.net/6/docs/ref/#state.StateEffect^reconfigure).
1561
1583
  */
1562
1584
  get reconfigured() { return this.startState.config != this.state.config; }
1585
+ /**
1586
+ Returns true if the transaction has a [user
1587
+ event](https://codemirror.net/6/docs/ref/#state.Transaction^userEvent) annotation that is equal to
1588
+ or more specific than `event`. For example, if the transaction
1589
+ has `"select.pointer"` as user event, `"select"` and
1590
+ `"select.pointer"` will match it.
1591
+ */
1592
+ isUserEvent(event) {
1593
+ let e = this.annotation(Transaction.userEvent);
1594
+ return !!(e && (e == event || e.length > event.length && e.slice(0, event.length) == event && e[event.length] == "."));
1595
+ }
1563
1596
  }
1564
1597
  /**
1565
1598
  Annotation used to store transaction timestamps.
@@ -1567,15 +1600,29 @@ Annotation used to store transaction timestamps.
1567
1600
  Transaction.time = /*@__PURE__*/Annotation.define();
1568
1601
  /**
1569
1602
  Annotation used to associate a transaction with a user interface
1570
- event. The view will set this to...
1603
+ event. Holds a string identifying the event, using a
1604
+ dot-separated format to support attaching more specific
1605
+ information. The events used by the core libraries are:
1571
1606
 
1572
- - `"input"` when the user types text
1573
- - `"delete"` when the user deletes the selection or text near the selection
1574
- - `"keyboardselection"` when moving the selection via the keyboard
1575
- - `"pointerselection"` when moving the selection through the pointing device
1576
- - `"paste"` when pasting content
1577
- - `"cut"` when cutting
1578
- - `"drop"` when content is inserted via drag-and-drop
1607
+ - `"input"` when content is entered
1608
+ - `"input.type"` for typed input
1609
+ - `"input.type.compose"` for composition
1610
+ - `"input.paste"` for pasted input
1611
+ - `"input.drop"` when adding content with drag-and-drop
1612
+ - `"input.complete"` when autocompleting
1613
+ - `"delete"` when the user deletes content
1614
+ - `"delete.selection"` when deleting the selection
1615
+ - `"delete.forward"` when deleting forward from the selection
1616
+ - `"delete.backward"` when deleting backward from the selection
1617
+ - `"delete.cut"` when cutting to the clipboard
1618
+ - `"move"` when content is moved
1619
+ - `"move.drop"` when content is moved within the editor through drag-and-drop
1620
+ - `"select"` when explicitly changing the selection
1621
+ - `"select.pointer"` when selecting with a mouse or other pointing device
1622
+ - `"undo"` and `"redo"` for history actions
1623
+
1624
+ Use [`isUserEvent`](https://codemirror.net/6/docs/ref/#state.Transaction.isUserEvent) to check
1625
+ whether the annotation matches a given event.
1579
1626
  */
1580
1627
  Transaction.userEvent = /*@__PURE__*/Annotation.define();
1581
1628
  /**
@@ -1632,13 +1679,15 @@ function mergeTransaction(a, b, sequential) {
1632
1679
  };
1633
1680
  }
1634
1681
  function resolveTransactionInner(state, spec, docSize) {
1635
- let sel = spec.selection;
1682
+ let sel = spec.selection, annotations = asArray(spec.annotations);
1683
+ if (spec.userEvent)
1684
+ annotations = annotations.concat(Transaction.userEvent.of(spec.userEvent));
1636
1685
  return {
1637
1686
  changes: spec.changes instanceof ChangeSet ? spec.changes
1638
1687
  : ChangeSet.of(spec.changes || [], docSize, state.facet(lineSeparator)),
1639
1688
  selection: sel && (sel instanceof EditorSelection ? sel : EditorSelection.single(sel.anchor, sel.head)),
1640
1689
  effects: asArray(spec.effects),
1641
- annotations: asArray(spec.annotations),
1690
+ annotations,
1642
1691
  scrollIntoView: !!spec.scrollIntoView
1643
1692
  };
1644
1693
  }
@@ -2010,6 +2059,11 @@ class EditorState {
2010
2059
  */
2011
2060
  get lineBreak() { return this.facet(EditorState.lineSeparator) || "\n"; }
2012
2061
  /**
2062
+ Returns true when the editor is
2063
+ [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only.
2064
+ */
2065
+ get readOnly() { return this.facet(readOnly); }
2066
+ /**
2013
2067
  Look up a translation for the given phrase (via the
2014
2068
  [`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
2015
2069
  original string if no translation is found.
@@ -2024,10 +2078,10 @@ class EditorState {
2024
2078
  Find the values for a given language data field, provided by the
2025
2079
  the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
2026
2080
  */
2027
- languageDataAt(name, pos) {
2081
+ languageDataAt(name, pos, side = -1) {
2028
2082
  let values = [];
2029
2083
  for (let provider of this.facet(languageData)) {
2030
- for (let result of provider(this, pos)) {
2084
+ for (let result of provider(this, pos, side)) {
2031
2085
  if (Object.prototype.hasOwnProperty.call(result, name))
2032
2086
  values.push(result[name]);
2033
2087
  }
@@ -2070,7 +2124,7 @@ class EditorState {
2070
2124
  break;
2071
2125
  end = next;
2072
2126
  }
2073
- return start == end ? EditorSelection.range(start + from, end + from) : null;
2127
+ return start == end ? null : EditorSelection.range(start + from, end + from);
2074
2128
  }
2075
2129
  }
2076
2130
  /**
@@ -2101,6 +2155,20 @@ editor without normalizing line separators.
2101
2155
  */
2102
2156
  EditorState.lineSeparator = lineSeparator;
2103
2157
  /**
2158
+ This facet controls the value of the
2159
+ [`readOnly`](https://codemirror.net/6/docs/ref/#state.EditorState.readOnly) getter, which is
2160
+ consulted by commands and extensions that implement editing
2161
+ functionality to determine whether they should apply. It
2162
+ defaults to false, but when its highest-precedence value is
2163
+ `true`, such functionality disables itself.
2164
+
2165
+ Not to be confused with
2166
+ [`EditorView.editable`](https://codemirror.net/6/docs/ref/#view.EditorView^editable), which
2167
+ controls whether the editor's DOM is set to be editable (and
2168
+ thus focusable).
2169
+ */
2170
+ EditorState.readOnly = readOnly;
2171
+ /**
2104
2172
  Registers translation phrases. The
2105
2173
  [`phrase`](https://codemirror.net/6/docs/ref/#state.EditorState.phrase) method will look through
2106
2174
  all objects registered with this facet to find translations for
@@ -2132,9 +2200,10 @@ Facet used to register a hook that gets a chance to update or
2132
2200
  replace transaction specs before they are applied. This will
2133
2201
  only be applied for transactions that don't have
2134
2202
  [`filter`](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter) set to `false`. You
2135
- can either return a single (possibly the input transaction), or
2136
- an array of specs (which will be combined in the same way as the
2137
- arguments to [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update)).
2203
+ can either return a single transaction spec (possibly the input
2204
+ transaction), or an array of specs (which will be combined in
2205
+ the same way as the arguments to
2206
+ [`EditorState.update`](https://codemirror.net/6/docs/ref/#state.EditorState.update)).
2138
2207
 
2139
2208
  When possible, it is recommended to avoid accessing
2140
2209
  [`Transaction.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state) in a filter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/state",
3
- "version": "0.18.7",
3
+ "version": "0.19.3",
4
4
  "description": "Editor state data structures for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",
@@ -26,7 +26,7 @@
26
26
  "sideEffects": false,
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "@codemirror/text": "^0.18.0"
29
+ "@codemirror/text": "^0.19.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@codemirror/buildhelper": "^0.1.5"