@codemirror/state 0.19.1 → 0.19.5

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,27 @@
1
+ ## 0.19.5 (2021-11-10)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a bug that would cause dynamic facet values influenced by a state reconfiguration to not properly recompute.
6
+
7
+ ## 0.19.4 (2021-11-05)
8
+
9
+ ### Bug fixes
10
+
11
+ When reconfiguring a state, effects from the reconfiguring transaction can now be seen by newly added state fields.
12
+
13
+ ## 0.19.3 (2021-11-03)
14
+
15
+ ### New features
16
+
17
+ The precedence levels (under `Prec`) now have more generic names, because their 'meaningful' names were entirely inappropriate in many situations.
18
+
19
+ ## 0.19.2 (2021-09-13)
20
+
21
+ ### New features
22
+
23
+ The editor state now has a `readOnly` property with a matching facet to control its value.
24
+
1
25
  ## 0.19.1 (2021-08-15)
2
26
 
3
27
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -967,21 +967,23 @@ class FacetProvider {
967
967
  depAddrs.push(addresses[dep.id]);
968
968
  }
969
969
  return (state, tr) => {
970
- if (!tr || tr.reconfigured) {
970
+ let oldVal = state.values[idx];
971
+ if (oldVal === Uninitialized) {
971
972
  state.values[idx] = getter(state);
972
973
  return 1 /* Changed */;
973
974
  }
974
- else {
975
+ if (tr) {
975
976
  let depChanged = (depDoc && tr.docChanged) || (depSel && (tr.docChanged || tr.selection)) ||
976
977
  depAddrs.some(addr => (ensureAddr(state, addr) & 1 /* Changed */) > 0);
977
- if (!depChanged)
978
- return 0;
979
- let newVal = getter(state), oldVal = tr.startState.values[idx];
980
- if (multi ? compareArray(newVal, oldVal, compare) : compare(newVal, oldVal))
981
- return 0;
982
- state.values[idx] = newVal;
983
- return 1 /* Changed */;
978
+ if (depChanged) {
979
+ let newVal = getter(state);
980
+ if (multi ? !compareArray(newVal, oldVal, compare) : !compare(newVal, oldVal)) {
981
+ state.values[idx] = newVal;
982
+ return 1 /* Changed */;
983
+ }
984
+ }
984
985
  }
986
+ return 0;
985
987
  };
986
988
  }
987
989
  }
@@ -999,8 +1001,7 @@ function dynamicFacetSlot(addresses, facet, providers) {
999
1001
  let dynamic = providerAddrs.filter(p => !(p & 1));
1000
1002
  let idx = addresses[facet.id] >> 1;
1001
1003
  return (state, tr) => {
1002
- let oldAddr = !tr ? null : tr.reconfigured ? tr.startState.config.address[facet.id] : idx << 1;
1003
- let changed = oldAddr == null;
1004
+ let oldVal = state.values[idx], changed = oldVal === Uninitialized || !tr;
1004
1005
  for (let dynAddr of dynamic) {
1005
1006
  if (ensureAddr(state, dynAddr) & 1 /* Changed */)
1006
1007
  changed = true;
@@ -1016,17 +1017,13 @@ function dynamicFacetSlot(addresses, facet, providers) {
1016
1017
  else
1017
1018
  values.push(value);
1018
1019
  }
1019
- let newVal = facet.combine(values);
1020
- if (oldAddr != null && facet.compare(newVal, getAddr(tr.startState, oldAddr)))
1020
+ let value = facet.combine(values);
1021
+ if (facet.compare(value, oldVal))
1021
1022
  return 0;
1022
- state.values[idx] = newVal;
1023
+ state.values[idx] = value;
1023
1024
  return 1 /* Changed */;
1024
1025
  };
1025
1026
  }
1026
- function maybeIndex(state, id) {
1027
- let found = state.config.address[id];
1028
- return found == null ? null : found >> 1;
1029
- }
1030
1027
  const initField = Facet.define({ static: true });
1031
1028
  /**
1032
1029
  Fields can store additional information in an editor state, and
@@ -1071,24 +1068,19 @@ class StateField {
1071
1068
  slot(addresses) {
1072
1069
  let idx = addresses[this.id] >> 1;
1073
1070
  return (state, tr) => {
1074
- if (!tr || (tr.reconfigured && maybeIndex(tr.startState, this.id) == null)) {
1071
+ let oldVal = state.values[idx];
1072
+ if (oldVal === Uninitialized) {
1075
1073
  state.values[idx] = this.create(state);
1076
1074
  return 1 /* Changed */;
1077
1075
  }
1078
- let oldVal, changed = 0;
1079
- if (tr.reconfigured) {
1080
- oldVal = tr.startState.values[maybeIndex(tr.startState, this.id)];
1081
- changed = 1 /* Changed */;
1082
- }
1083
- else {
1084
- oldVal = tr.startState.values[idx];
1076
+ if (tr) {
1077
+ let value = this.updateF(oldVal, tr);
1078
+ if (!this.compareF(oldVal, value)) {
1079
+ state.values[idx] = value;
1080
+ return 1 /* Changed */;
1081
+ }
1085
1082
  }
1086
- let value = this.updateF(oldVal, tr);
1087
- if (!changed && !this.compareF(oldVal, value))
1088
- changed = 1 /* Changed */;
1089
- if (changed)
1090
- state.values[idx] = value;
1091
- return changed;
1083
+ return 0;
1092
1084
  };
1093
1085
  }
1094
1086
  /**
@@ -1106,7 +1098,7 @@ class StateField {
1106
1098
  */
1107
1099
  get extension() { return this; }
1108
1100
  }
1109
- const Prec_ = { fallback: 3, default: 2, extend: 1, override: 0 };
1101
+ const Prec_ = { lowest: 4, low: 3, default: 2, high: 1, highest: 0 };
1110
1102
  function prec(value) {
1111
1103
  return (ext) => new PrecExtension(ext, value);
1112
1104
  }
@@ -1122,23 +1114,42 @@ precedence and then by order within each precedence.
1122
1114
  */
1123
1115
  const Prec = {
1124
1116
  /**
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.
1117
+ The lowest precedence level. Meant for things that should end up
1118
+ near the end of the extension order.
1119
+ */
1120
+ lowest: prec(Prec_.lowest),
1121
+ /**
1122
+ A lower-than-default precedence, for extensions.
1128
1123
  */
1129
- fallback: prec(Prec_.fallback),
1124
+ low: prec(Prec_.low),
1130
1125
  /**
1131
- The regular default precedence.
1126
+ The default precedence, which is also used for extensions
1127
+ without an explicit precedence.
1132
1128
  */
1133
1129
  default: prec(Prec_.default),
1134
1130
  /**
1135
- A higher-than-default precedence.
1131
+ A higher-than-default precedence, for extensions that should
1132
+ come before those with default precedence.
1133
+ */
1134
+ high: prec(Prec_.high),
1135
+ /**
1136
+ The highest precedence level, for extensions that should end up
1137
+ near the start of the precedence ordering.
1138
+ */
1139
+ highest: prec(Prec_.highest),
1140
+ // FIXME Drop these in some future breaking version
1141
+ /**
1142
+ Backwards-compatible synonym for `Prec.lowest`.
1143
+ */
1144
+ fallback: prec(Prec_.lowest),
1145
+ /**
1146
+ Backwards-compatible synonym for `Prec.high`.
1136
1147
  */
1137
- extend: prec(Prec_.extend),
1148
+ extend: prec(Prec_.high),
1138
1149
  /**
1139
- Precedence above the `default` and `extend` precedences.
1150
+ Backwards-compatible synonym for `Prec.highest`.
1140
1151
  */
1141
- override: prec(Prec_.override)
1152
+ override: prec(Prec_.highest)
1142
1153
  };
1143
1154
  class PrecExtension {
1144
1155
  constructor(inner, prec) {
@@ -1189,7 +1200,7 @@ class Configuration {
1189
1200
  this.staticValues = staticValues;
1190
1201
  this.statusTemplate = [];
1191
1202
  while (this.statusTemplate.length < dynamicSlots.length)
1192
- this.statusTemplate.push(0 /* Uninitialized */);
1203
+ this.statusTemplate.push(0 /* Unresolved */);
1193
1204
  }
1194
1205
  staticFacet(facet) {
1195
1206
  let addr = this.address[facet.id];
@@ -1244,7 +1255,7 @@ class Configuration {
1244
1255
  }
1245
1256
  }
1246
1257
  function flatten(extension, compartments, newCompartments) {
1247
- let result = [[], [], [], []];
1258
+ let result = [[], [], [], [], []];
1248
1259
  let seen = new Map();
1249
1260
  function inner(ext, prec) {
1250
1261
  let known = seen.get(ext);
@@ -1292,6 +1303,7 @@ function flatten(extension, compartments, newCompartments) {
1292
1303
  inner(extension, Prec_.default);
1293
1304
  return result.reduce((a, b) => a.concat(b));
1294
1305
  }
1306
+ const Uninitialized = {};
1295
1307
  function ensureAddr(state, addr) {
1296
1308
  if (addr & 1)
1297
1309
  return 2 /* Computed */;
@@ -1321,6 +1333,9 @@ const lineSeparator = Facet.define({
1321
1333
  const changeFilter = Facet.define();
1322
1334
  const transactionFilter = Facet.define();
1323
1335
  const transactionExtender = Facet.define();
1336
+ const readOnly = Facet.define({
1337
+ combine: values => values.length ? values[0] : false
1338
+ });
1324
1339
 
1325
1340
  /**
1326
1341
  Annotations are tagged values that are used to add metadata to
@@ -1573,7 +1588,7 @@ class Transaction {
1573
1588
  */
1574
1589
  isUserEvent(event) {
1575
1590
  let e = this.annotation(Transaction.userEvent);
1576
- return e && (e == event || e.length > event.length && e.slice(0, event.length) == event && e[event.length] == ".");
1591
+ return !!(e && (e == event || e.length > event.length && e.slice(0, event.length) == event && e[event.length] == "."));
1577
1592
  }
1578
1593
  }
1579
1594
  /**
@@ -1814,28 +1829,20 @@ class EditorState {
1814
1829
  /**
1815
1830
  The current selection.
1816
1831
  */
1817
- selection, tr = null) {
1832
+ selection,
1833
+ /**
1834
+ @internal
1835
+ */
1836
+ values, tr = null) {
1818
1837
  this.config = config;
1819
1838
  this.doc = doc;
1820
1839
  this.selection = selection;
1840
+ this.values = values;
1821
1841
  /**
1822
1842
  @internal
1823
1843
  */
1824
1844
  this.applying = null;
1825
1845
  this.status = config.statusTemplate.slice();
1826
- if (tr && tr.startState.config == config) {
1827
- this.values = tr.startState.values.slice();
1828
- }
1829
- else {
1830
- this.values = config.dynamicSlots.map(_ => null);
1831
- // Copy over old values for shared facets/fields if this is a reconfigure
1832
- if (tr)
1833
- for (let id in config.address) {
1834
- let cur = config.address[id], prev = tr.startState.config.address[id];
1835
- if (prev != null && (cur & 1) == 0)
1836
- this.values[cur >> 1] = getAddr(tr.startState, prev);
1837
- }
1838
- }
1839
1846
  this.applying = tr;
1840
1847
  // Fill in the computed state immediately, so that further queries
1841
1848
  // for it made during the update return this state
@@ -1896,7 +1903,23 @@ class EditorState {
1896
1903
  base = asArray(base).concat(effect.value);
1897
1904
  }
1898
1905
  }
1899
- new EditorState(conf || Configuration.resolve(base, compartments, this), tr.newDoc, tr.newSelection, tr);
1906
+ let startValues;
1907
+ if (!conf) {
1908
+ conf = Configuration.resolve(base, compartments, this);
1909
+ let updatedValues = conf.dynamicSlots.map(_ => Uninitialized);
1910
+ // Copy over old values for shared facets/fields
1911
+ for (let id in conf.address) {
1912
+ let cur = conf.address[id], prev = this.config.address[id];
1913
+ if (prev != null && (cur & 1) == 0)
1914
+ updatedValues[cur >> 1] = getAddr(this, prev);
1915
+ }
1916
+ let intermediateState = new EditorState(conf, this.doc, this.selection, updatedValues, null);
1917
+ startValues = intermediateState.values;
1918
+ }
1919
+ else {
1920
+ startValues = tr.startState.values.slice();
1921
+ }
1922
+ new EditorState(conf, tr.newDoc, tr.newSelection, startValues, tr);
1900
1923
  }
1901
1924
  /**
1902
1925
  Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
@@ -2029,7 +2052,7 @@ class EditorState {
2029
2052
  checkSelection(selection, doc.length);
2030
2053
  if (!configuration.staticFacet(allowMultipleSelections))
2031
2054
  selection = selection.asSingle();
2032
- return new EditorState(configuration, doc, selection);
2055
+ return new EditorState(configuration, doc, selection, configuration.dynamicSlots.map(_ => Uninitialized));
2033
2056
  }
2034
2057
  /**
2035
2058
  The size (in columns) of a tab in the document, determined by
@@ -2042,6 +2065,11 @@ class EditorState {
2042
2065
  */
2043
2066
  get lineBreak() { return this.facet(EditorState.lineSeparator) || "\n"; }
2044
2067
  /**
2068
+ Returns true when the editor is
2069
+ [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only.
2070
+ */
2071
+ get readOnly() { return this.facet(readOnly); }
2072
+ /**
2045
2073
  Look up a translation for the given phrase (via the
2046
2074
  [`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
2047
2075
  original string if no translation is found.
@@ -2133,6 +2161,20 @@ editor without normalizing line separators.
2133
2161
  */
2134
2162
  EditorState.lineSeparator = lineSeparator;
2135
2163
  /**
2164
+ This facet controls the value of the
2165
+ [`readOnly`](https://codemirror.net/6/docs/ref/#state.EditorState.readOnly) getter, which is
2166
+ consulted by commands and extensions that implement editing
2167
+ functionality to determine whether they should apply. It
2168
+ defaults to false, but when its highest-precedence value is
2169
+ `true`, such functionality disables itself.
2170
+
2171
+ Not to be confused with
2172
+ [`EditorView.editable`](https://codemirror.net/6/docs/ref/#view.EditorView^editable), which
2173
+ controls whether the editor's DOM is set to be editable (and
2174
+ thus focusable).
2175
+ */
2176
+ EditorState.readOnly = readOnly;
2177
+ /**
2136
2178
  Registers translation phrases. The
2137
2179
  [`phrase`](https://codemirror.net/6/docs/ref/#state.EditorState.phrase) method will look through
2138
2180
  all objects registered with this facet to find translations for
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
  };
@@ -783,7 +801,7 @@ declare class Transaction {
783
801
  has `"select.pointer"` as user event, `"select"` and
784
802
  `"select.pointer"` will match it.
785
803
  */
786
- isUserEvent(event: string): boolean | "" | undefined;
804
+ isUserEvent(event: string): boolean;
787
805
  /**
788
806
  Annotation used to store transaction timestamps.
789
807
  */
@@ -1026,6 +1044,25 @@ declare class EditorState {
1026
1044
  */
1027
1045
  get lineBreak(): string;
1028
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
+ /**
1029
1066
  Registers translation phrases. The
1030
1067
  [`phrase`](https://codemirror.net/6/docs/ref/#state.EditorState.phrase) method will look through
1031
1068
  all objects registered with this facet to find translations for
package/dist/index.js CHANGED
@@ -963,21 +963,23 @@ class FacetProvider {
963
963
  depAddrs.push(addresses[dep.id]);
964
964
  }
965
965
  return (state, tr) => {
966
- if (!tr || tr.reconfigured) {
966
+ let oldVal = state.values[idx];
967
+ if (oldVal === Uninitialized) {
967
968
  state.values[idx] = getter(state);
968
969
  return 1 /* Changed */;
969
970
  }
970
- else {
971
+ if (tr) {
971
972
  let depChanged = (depDoc && tr.docChanged) || (depSel && (tr.docChanged || tr.selection)) ||
972
973
  depAddrs.some(addr => (ensureAddr(state, addr) & 1 /* Changed */) > 0);
973
- if (!depChanged)
974
- return 0;
975
- let newVal = getter(state), oldVal = tr.startState.values[idx];
976
- if (multi ? compareArray(newVal, oldVal, compare) : compare(newVal, oldVal))
977
- return 0;
978
- state.values[idx] = newVal;
979
- return 1 /* Changed */;
974
+ if (depChanged) {
975
+ let newVal = getter(state);
976
+ if (multi ? !compareArray(newVal, oldVal, compare) : !compare(newVal, oldVal)) {
977
+ state.values[idx] = newVal;
978
+ return 1 /* Changed */;
979
+ }
980
+ }
980
981
  }
982
+ return 0;
981
983
  };
982
984
  }
983
985
  }
@@ -995,8 +997,7 @@ function dynamicFacetSlot(addresses, facet, providers) {
995
997
  let dynamic = providerAddrs.filter(p => !(p & 1));
996
998
  let idx = addresses[facet.id] >> 1;
997
999
  return (state, tr) => {
998
- let oldAddr = !tr ? null : tr.reconfigured ? tr.startState.config.address[facet.id] : idx << 1;
999
- let changed = oldAddr == null;
1000
+ let oldVal = state.values[idx], changed = oldVal === Uninitialized || !tr;
1000
1001
  for (let dynAddr of dynamic) {
1001
1002
  if (ensureAddr(state, dynAddr) & 1 /* Changed */)
1002
1003
  changed = true;
@@ -1012,17 +1013,13 @@ function dynamicFacetSlot(addresses, facet, providers) {
1012
1013
  else
1013
1014
  values.push(value);
1014
1015
  }
1015
- let newVal = facet.combine(values);
1016
- if (oldAddr != null && facet.compare(newVal, getAddr(tr.startState, oldAddr)))
1016
+ let value = facet.combine(values);
1017
+ if (facet.compare(value, oldVal))
1017
1018
  return 0;
1018
- state.values[idx] = newVal;
1019
+ state.values[idx] = value;
1019
1020
  return 1 /* Changed */;
1020
1021
  };
1021
1022
  }
1022
- function maybeIndex(state, id) {
1023
- let found = state.config.address[id];
1024
- return found == null ? null : found >> 1;
1025
- }
1026
1023
  const initField = /*@__PURE__*/Facet.define({ static: true });
1027
1024
  /**
1028
1025
  Fields can store additional information in an editor state, and
@@ -1067,24 +1064,19 @@ class StateField {
1067
1064
  slot(addresses) {
1068
1065
  let idx = addresses[this.id] >> 1;
1069
1066
  return (state, tr) => {
1070
- if (!tr || (tr.reconfigured && maybeIndex(tr.startState, this.id) == null)) {
1067
+ let oldVal = state.values[idx];
1068
+ if (oldVal === Uninitialized) {
1071
1069
  state.values[idx] = this.create(state);
1072
1070
  return 1 /* Changed */;
1073
1071
  }
1074
- let oldVal, changed = 0;
1075
- if (tr.reconfigured) {
1076
- oldVal = tr.startState.values[maybeIndex(tr.startState, this.id)];
1077
- changed = 1 /* Changed */;
1078
- }
1079
- else {
1080
- oldVal = tr.startState.values[idx];
1072
+ if (tr) {
1073
+ let value = this.updateF(oldVal, tr);
1074
+ if (!this.compareF(oldVal, value)) {
1075
+ state.values[idx] = value;
1076
+ return 1 /* Changed */;
1077
+ }
1081
1078
  }
1082
- let value = this.updateF(oldVal, tr);
1083
- if (!changed && !this.compareF(oldVal, value))
1084
- changed = 1 /* Changed */;
1085
- if (changed)
1086
- state.values[idx] = value;
1087
- return changed;
1079
+ return 0;
1088
1080
  };
1089
1081
  }
1090
1082
  /**
@@ -1102,7 +1094,7 @@ class StateField {
1102
1094
  */
1103
1095
  get extension() { return this; }
1104
1096
  }
1105
- const Prec_ = { fallback: 3, default: 2, extend: 1, override: 0 };
1097
+ const Prec_ = { lowest: 4, low: 3, default: 2, high: 1, highest: 0 };
1106
1098
  function prec(value) {
1107
1099
  return (ext) => new PrecExtension(ext, value);
1108
1100
  }
@@ -1118,23 +1110,42 @@ precedence and then by order within each precedence.
1118
1110
  */
1119
1111
  const Prec = {
1120
1112
  /**
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.
1113
+ The lowest precedence level. Meant for things that should end up
1114
+ near the end of the extension order.
1115
+ */
1116
+ lowest: /*@__PURE__*/prec(Prec_.lowest),
1117
+ /**
1118
+ A lower-than-default precedence, for extensions.
1124
1119
  */
1125
- fallback: /*@__PURE__*/prec(Prec_.fallback),
1120
+ low: /*@__PURE__*/prec(Prec_.low),
1126
1121
  /**
1127
- The regular default precedence.
1122
+ The default precedence, which is also used for extensions
1123
+ without an explicit precedence.
1128
1124
  */
1129
1125
  default: /*@__PURE__*/prec(Prec_.default),
1130
1126
  /**
1131
- A higher-than-default precedence.
1127
+ A higher-than-default precedence, for extensions that should
1128
+ come before those with default precedence.
1129
+ */
1130
+ high: /*@__PURE__*/prec(Prec_.high),
1131
+ /**
1132
+ The highest precedence level, for extensions that should end up
1133
+ near the start of the precedence ordering.
1134
+ */
1135
+ highest: /*@__PURE__*/prec(Prec_.highest),
1136
+ // FIXME Drop these in some future breaking version
1137
+ /**
1138
+ Backwards-compatible synonym for `Prec.lowest`.
1139
+ */
1140
+ fallback: /*@__PURE__*/prec(Prec_.lowest),
1141
+ /**
1142
+ Backwards-compatible synonym for `Prec.high`.
1132
1143
  */
1133
- extend: /*@__PURE__*/prec(Prec_.extend),
1144
+ extend: /*@__PURE__*/prec(Prec_.high),
1134
1145
  /**
1135
- Precedence above the `default` and `extend` precedences.
1146
+ Backwards-compatible synonym for `Prec.highest`.
1136
1147
  */
1137
- override: /*@__PURE__*/prec(Prec_.override)
1148
+ override: /*@__PURE__*/prec(Prec_.highest)
1138
1149
  };
1139
1150
  class PrecExtension {
1140
1151
  constructor(inner, prec) {
@@ -1185,7 +1196,7 @@ class Configuration {
1185
1196
  this.staticValues = staticValues;
1186
1197
  this.statusTemplate = [];
1187
1198
  while (this.statusTemplate.length < dynamicSlots.length)
1188
- this.statusTemplate.push(0 /* Uninitialized */);
1199
+ this.statusTemplate.push(0 /* Unresolved */);
1189
1200
  }
1190
1201
  staticFacet(facet) {
1191
1202
  let addr = this.address[facet.id];
@@ -1240,7 +1251,7 @@ class Configuration {
1240
1251
  }
1241
1252
  }
1242
1253
  function flatten(extension, compartments, newCompartments) {
1243
- let result = [[], [], [], []];
1254
+ let result = [[], [], [], [], []];
1244
1255
  let seen = new Map();
1245
1256
  function inner(ext, prec) {
1246
1257
  let known = seen.get(ext);
@@ -1288,6 +1299,7 @@ function flatten(extension, compartments, newCompartments) {
1288
1299
  inner(extension, Prec_.default);
1289
1300
  return result.reduce((a, b) => a.concat(b));
1290
1301
  }
1302
+ const Uninitialized = {};
1291
1303
  function ensureAddr(state, addr) {
1292
1304
  if (addr & 1)
1293
1305
  return 2 /* Computed */;
@@ -1317,6 +1329,9 @@ const lineSeparator = /*@__PURE__*/Facet.define({
1317
1329
  const changeFilter = /*@__PURE__*/Facet.define();
1318
1330
  const transactionFilter = /*@__PURE__*/Facet.define();
1319
1331
  const transactionExtender = /*@__PURE__*/Facet.define();
1332
+ const readOnly = /*@__PURE__*/Facet.define({
1333
+ combine: values => values.length ? values[0] : false
1334
+ });
1320
1335
 
1321
1336
  /**
1322
1337
  Annotations are tagged values that are used to add metadata to
@@ -1569,7 +1584,7 @@ class Transaction {
1569
1584
  */
1570
1585
  isUserEvent(event) {
1571
1586
  let e = this.annotation(Transaction.userEvent);
1572
- return e && (e == event || e.length > event.length && e.slice(0, event.length) == event && e[event.length] == ".");
1587
+ return !!(e && (e == event || e.length > event.length && e.slice(0, event.length) == event && e[event.length] == "."));
1573
1588
  }
1574
1589
  }
1575
1590
  /**
@@ -1809,28 +1824,20 @@ class EditorState {
1809
1824
  /**
1810
1825
  The current selection.
1811
1826
  */
1812
- selection, tr = null) {
1827
+ selection,
1828
+ /**
1829
+ @internal
1830
+ */
1831
+ values, tr = null) {
1813
1832
  this.config = config;
1814
1833
  this.doc = doc;
1815
1834
  this.selection = selection;
1835
+ this.values = values;
1816
1836
  /**
1817
1837
  @internal
1818
1838
  */
1819
1839
  this.applying = null;
1820
1840
  this.status = config.statusTemplate.slice();
1821
- if (tr && tr.startState.config == config) {
1822
- this.values = tr.startState.values.slice();
1823
- }
1824
- else {
1825
- this.values = config.dynamicSlots.map(_ => null);
1826
- // Copy over old values for shared facets/fields if this is a reconfigure
1827
- if (tr)
1828
- for (let id in config.address) {
1829
- let cur = config.address[id], prev = tr.startState.config.address[id];
1830
- if (prev != null && (cur & 1) == 0)
1831
- this.values[cur >> 1] = getAddr(tr.startState, prev);
1832
- }
1833
- }
1834
1841
  this.applying = tr;
1835
1842
  // Fill in the computed state immediately, so that further queries
1836
1843
  // for it made during the update return this state
@@ -1891,7 +1898,23 @@ class EditorState {
1891
1898
  base = asArray(base).concat(effect.value);
1892
1899
  }
1893
1900
  }
1894
- new EditorState(conf || Configuration.resolve(base, compartments, this), tr.newDoc, tr.newSelection, tr);
1901
+ let startValues;
1902
+ if (!conf) {
1903
+ conf = Configuration.resolve(base, compartments, this);
1904
+ let updatedValues = conf.dynamicSlots.map(_ => Uninitialized);
1905
+ // Copy over old values for shared facets/fields
1906
+ for (let id in conf.address) {
1907
+ let cur = conf.address[id], prev = this.config.address[id];
1908
+ if (prev != null && (cur & 1) == 0)
1909
+ updatedValues[cur >> 1] = getAddr(this, prev);
1910
+ }
1911
+ let intermediateState = new EditorState(conf, this.doc, this.selection, updatedValues, null);
1912
+ startValues = intermediateState.values;
1913
+ }
1914
+ else {
1915
+ startValues = tr.startState.values.slice();
1916
+ }
1917
+ new EditorState(conf, tr.newDoc, tr.newSelection, startValues, tr);
1895
1918
  }
1896
1919
  /**
1897
1920
  Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
@@ -2024,7 +2047,7 @@ class EditorState {
2024
2047
  checkSelection(selection, doc.length);
2025
2048
  if (!configuration.staticFacet(allowMultipleSelections))
2026
2049
  selection = selection.asSingle();
2027
- return new EditorState(configuration, doc, selection);
2050
+ return new EditorState(configuration, doc, selection, configuration.dynamicSlots.map(_ => Uninitialized));
2028
2051
  }
2029
2052
  /**
2030
2053
  The size (in columns) of a tab in the document, determined by
@@ -2037,6 +2060,11 @@ class EditorState {
2037
2060
  */
2038
2061
  get lineBreak() { return this.facet(EditorState.lineSeparator) || "\n"; }
2039
2062
  /**
2063
+ Returns true when the editor is
2064
+ [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only.
2065
+ */
2066
+ get readOnly() { return this.facet(readOnly); }
2067
+ /**
2040
2068
  Look up a translation for the given phrase (via the
2041
2069
  [`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
2042
2070
  original string if no translation is found.
@@ -2128,6 +2156,20 @@ editor without normalizing line separators.
2128
2156
  */
2129
2157
  EditorState.lineSeparator = lineSeparator;
2130
2158
  /**
2159
+ This facet controls the value of the
2160
+ [`readOnly`](https://codemirror.net/6/docs/ref/#state.EditorState.readOnly) getter, which is
2161
+ consulted by commands and extensions that implement editing
2162
+ functionality to determine whether they should apply. It
2163
+ defaults to false, but when its highest-precedence value is
2164
+ `true`, such functionality disables itself.
2165
+
2166
+ Not to be confused with
2167
+ [`EditorView.editable`](https://codemirror.net/6/docs/ref/#view.EditorView^editable), which
2168
+ controls whether the editor's DOM is set to be editable (and
2169
+ thus focusable).
2170
+ */
2171
+ EditorState.readOnly = readOnly;
2172
+ /**
2131
2173
  Registers translation phrases. The
2132
2174
  [`phrase`](https://codemirror.net/6/docs/ref/#state.EditorState.phrase) method will look through
2133
2175
  all objects registered with this facet to find translations for
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/state",
3
- "version": "0.19.1",
3
+ "version": "0.19.5",
4
4
  "description": "Editor state data structures for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",