@codemirror/state 0.19.4 → 0.19.8
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 +28 -0
- package/dist/index.cjs +97 -66
- package/dist/index.d.ts +3 -1
- package/dist/index.js +96 -63
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## 0.19.8 (2022-02-15)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix a bug where facet values with computed inputs could incorrectly retain their old value on reconfiguration.
|
|
6
|
+
|
|
7
|
+
## 0.19.7 (2022-02-11)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
Avoid recomputing facets on state reconfiguration if that facet's inputs stayed precisely the same.
|
|
12
|
+
|
|
13
|
+
Selection ranges created with `EditorSelection.range` will now have an assoc pointing at their anchor, when non-empty.
|
|
14
|
+
|
|
15
|
+
## 0.19.6 (2021-11-19)
|
|
16
|
+
|
|
17
|
+
### Bug fixes
|
|
18
|
+
|
|
19
|
+
Fix a bug that caused facet compare functions to be called with an invalid value in some situations.
|
|
20
|
+
|
|
21
|
+
Fix a bug that caused dynamic facet values to be incorrectly kept unchanged when reconfiguration changed one of their dependencies.
|
|
22
|
+
|
|
23
|
+
## 0.19.5 (2021-11-10)
|
|
24
|
+
|
|
25
|
+
### Bug fixes
|
|
26
|
+
|
|
27
|
+
Fix a bug that would cause dynamic facet values influenced by a state reconfiguration to not properly recompute.
|
|
28
|
+
|
|
1
29
|
## 0.19.4 (2021-11-05)
|
|
2
30
|
|
|
3
31
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -265,7 +265,9 @@ class ChangeSet extends ChangeDesc {
|
|
|
265
265
|
map(other, before = false) { return other.empty ? this : mapSet(this, other, before, true); }
|
|
266
266
|
/**
|
|
267
267
|
Iterate over the changed ranges in the document, calling `f` for
|
|
268
|
-
each
|
|
268
|
+
each, with the range in the original document (`fromA`-`toA`)
|
|
269
|
+
and the range that replaces it in the new document
|
|
270
|
+
(`fromB`-`toB`).
|
|
269
271
|
|
|
270
272
|
When `individual` is true, adjacent changes are reported
|
|
271
273
|
separately.
|
|
@@ -835,7 +837,8 @@ class EditorSelection {
|
|
|
835
837
|
*/
|
|
836
838
|
static range(anchor, head, goalColumn) {
|
|
837
839
|
let goal = (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* NoGoalColumn */) << 5 /* GoalColumnOffset */;
|
|
838
|
-
return head < anchor ? new SelectionRange(head, anchor, 16 /* Inverted */ | goal
|
|
840
|
+
return head < anchor ? new SelectionRange(head, anchor, 16 /* Inverted */ | goal | 8 /* AssocAfter */)
|
|
841
|
+
: new SelectionRange(anchor, head, goal | (head > anchor ? 4 /* AssocBefore */ : 0));
|
|
839
842
|
}
|
|
840
843
|
}
|
|
841
844
|
function normalized(ranges, mainIndex = 0) {
|
|
@@ -956,7 +959,7 @@ class FacetProvider {
|
|
|
956
959
|
var _a;
|
|
957
960
|
let getter = this.value;
|
|
958
961
|
let compare = this.facet.compareInput;
|
|
959
|
-
let idx = addresses[
|
|
962
|
+
let id = this.id, idx = addresses[id] >> 1, multi = this.type == 2 /* Multi */;
|
|
960
963
|
let depDoc = false, depSel = false, depAddrs = [];
|
|
961
964
|
for (let dep of this.dependencies) {
|
|
962
965
|
if (dep == "doc")
|
|
@@ -966,24 +969,35 @@ class FacetProvider {
|
|
|
966
969
|
else if ((((_a = addresses[dep.id]) !== null && _a !== void 0 ? _a : 1) & 1) == 0)
|
|
967
970
|
depAddrs.push(addresses[dep.id]);
|
|
968
971
|
}
|
|
969
|
-
return
|
|
970
|
-
|
|
971
|
-
if (oldVal === Uninitialized) {
|
|
972
|
+
return {
|
|
973
|
+
create(state) {
|
|
972
974
|
state.values[idx] = getter(state);
|
|
973
975
|
return 1 /* Changed */;
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
depAddrs.some(addr => (ensureAddr(state, addr) & 1 /* Changed */) > 0)
|
|
978
|
-
if (depChanged) {
|
|
976
|
+
},
|
|
977
|
+
update(state, tr) {
|
|
978
|
+
if ((depDoc && tr.docChanged) || (depSel && (tr.docChanged || tr.selection)) ||
|
|
979
|
+
depAddrs.some(addr => (ensureAddr(state, addr) & 1 /* Changed */) > 0)) {
|
|
979
980
|
let newVal = getter(state);
|
|
980
|
-
if (multi ? !compareArray(newVal,
|
|
981
|
+
if (multi ? !compareArray(newVal, state.values[idx], compare) : !compare(newVal, state.values[idx])) {
|
|
981
982
|
state.values[idx] = newVal;
|
|
982
983
|
return 1 /* Changed */;
|
|
983
984
|
}
|
|
984
985
|
}
|
|
986
|
+
return 0;
|
|
987
|
+
},
|
|
988
|
+
reconfigure(state, oldState) {
|
|
989
|
+
let newVal = getter(state);
|
|
990
|
+
let oldAddr = oldState.config.address[id];
|
|
991
|
+
if (oldAddr != null) {
|
|
992
|
+
let oldVal = getAddr(oldState, oldAddr);
|
|
993
|
+
if (multi ? compareArray(newVal, oldVal, compare) : compare(newVal, oldVal)) {
|
|
994
|
+
state.values[idx] = oldVal;
|
|
995
|
+
return 0;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
state.values[idx] = newVal;
|
|
999
|
+
return 1 /* Changed */;
|
|
985
1000
|
}
|
|
986
|
-
return 0;
|
|
987
1001
|
};
|
|
988
1002
|
}
|
|
989
1003
|
}
|
|
@@ -1000,14 +1014,7 @@ function dynamicFacetSlot(addresses, facet, providers) {
|
|
|
1000
1014
|
let providerTypes = providers.map(p => p.type);
|
|
1001
1015
|
let dynamic = providerAddrs.filter(p => !(p & 1));
|
|
1002
1016
|
let idx = addresses[facet.id] >> 1;
|
|
1003
|
-
|
|
1004
|
-
let oldVal = state.values[idx], changed = oldVal === Uninitialized;
|
|
1005
|
-
for (let dynAddr of dynamic) {
|
|
1006
|
-
if (ensureAddr(state, dynAddr) & 1 /* Changed */)
|
|
1007
|
-
changed = true;
|
|
1008
|
-
}
|
|
1009
|
-
if (!changed)
|
|
1010
|
-
return 0;
|
|
1017
|
+
function get(state) {
|
|
1011
1018
|
let values = [];
|
|
1012
1019
|
for (let i = 0; i < providerAddrs.length; i++) {
|
|
1013
1020
|
let value = getAddr(state, providerAddrs[i]);
|
|
@@ -1017,11 +1024,39 @@ function dynamicFacetSlot(addresses, facet, providers) {
|
|
|
1017
1024
|
else
|
|
1018
1025
|
values.push(value);
|
|
1019
1026
|
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
state
|
|
1024
|
-
|
|
1027
|
+
return facet.combine(values);
|
|
1028
|
+
}
|
|
1029
|
+
return {
|
|
1030
|
+
create(state) {
|
|
1031
|
+
for (let addr of providerAddrs)
|
|
1032
|
+
ensureAddr(state, addr);
|
|
1033
|
+
state.values[idx] = get(state);
|
|
1034
|
+
return 1 /* Changed */;
|
|
1035
|
+
},
|
|
1036
|
+
update(state, tr) {
|
|
1037
|
+
if (!dynamic.some(dynAddr => ensureAddr(state, dynAddr) & 1 /* Changed */))
|
|
1038
|
+
return 0;
|
|
1039
|
+
let value = get(state);
|
|
1040
|
+
if (facet.compare(value, state.values[idx]))
|
|
1041
|
+
return 0;
|
|
1042
|
+
state.values[idx] = value;
|
|
1043
|
+
return 1 /* Changed */;
|
|
1044
|
+
},
|
|
1045
|
+
reconfigure(state, oldState) {
|
|
1046
|
+
let depChanged = providerAddrs.some(addr => ensureAddr(state, addr) & 1 /* Changed */);
|
|
1047
|
+
let oldProviders = oldState.config.facets[facet.id], oldValue = oldState.facet(facet);
|
|
1048
|
+
if (oldProviders && !depChanged && sameArray(providers, oldProviders)) {
|
|
1049
|
+
state.values[idx] = oldValue;
|
|
1050
|
+
return 0;
|
|
1051
|
+
}
|
|
1052
|
+
let value = get(state);
|
|
1053
|
+
if (facet.compare(value, oldValue)) {
|
|
1054
|
+
state.values[idx] = oldValue;
|
|
1055
|
+
return 0;
|
|
1056
|
+
}
|
|
1057
|
+
state.values[idx] = value;
|
|
1058
|
+
return 1 /* Changed */;
|
|
1059
|
+
}
|
|
1025
1060
|
};
|
|
1026
1061
|
}
|
|
1027
1062
|
const initField = Facet.define({ static: true });
|
|
@@ -1067,20 +1102,27 @@ class StateField {
|
|
|
1067
1102
|
*/
|
|
1068
1103
|
slot(addresses) {
|
|
1069
1104
|
let idx = addresses[this.id] >> 1;
|
|
1070
|
-
return
|
|
1071
|
-
|
|
1072
|
-
if (oldVal === Uninitialized) {
|
|
1105
|
+
return {
|
|
1106
|
+
create: (state) => {
|
|
1073
1107
|
state.values[idx] = this.create(state);
|
|
1074
1108
|
return 1 /* Changed */;
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1109
|
+
},
|
|
1110
|
+
update: (state, tr) => {
|
|
1111
|
+
let oldVal = state.values[idx];
|
|
1077
1112
|
let value = this.updateF(oldVal, tr);
|
|
1078
|
-
if (
|
|
1079
|
-
|
|
1080
|
-
|
|
1113
|
+
if (this.compareF(oldVal, value))
|
|
1114
|
+
return 0;
|
|
1115
|
+
state.values[idx] = value;
|
|
1116
|
+
return 1 /* Changed */;
|
|
1117
|
+
},
|
|
1118
|
+
reconfigure: (state, oldState) => {
|
|
1119
|
+
if (oldState.config.address[this.id] != null) {
|
|
1120
|
+
state.values[idx] = oldState.field(this);
|
|
1121
|
+
return 0;
|
|
1081
1122
|
}
|
|
1123
|
+
state.values[idx] = this.create(state);
|
|
1124
|
+
return 1 /* Changed */;
|
|
1082
1125
|
}
|
|
1083
|
-
return 0;
|
|
1084
1126
|
};
|
|
1085
1127
|
}
|
|
1086
1128
|
/**
|
|
@@ -1192,12 +1234,13 @@ class CompartmentInstance {
|
|
|
1192
1234
|
}
|
|
1193
1235
|
}
|
|
1194
1236
|
class Configuration {
|
|
1195
|
-
constructor(base, compartments, dynamicSlots, address, staticValues) {
|
|
1237
|
+
constructor(base, compartments, dynamicSlots, address, staticValues, facets) {
|
|
1196
1238
|
this.base = base;
|
|
1197
1239
|
this.compartments = compartments;
|
|
1198
1240
|
this.dynamicSlots = dynamicSlots;
|
|
1199
1241
|
this.address = address;
|
|
1200
1242
|
this.staticValues = staticValues;
|
|
1243
|
+
this.facets = facets;
|
|
1201
1244
|
this.statusTemplate = [];
|
|
1202
1245
|
while (this.statusTemplate.length < dynamicSlots.length)
|
|
1203
1246
|
this.statusTemplate.push(0 /* Unresolved */);
|
|
@@ -1223,18 +1266,19 @@ class Configuration {
|
|
|
1223
1266
|
address[field.id] = dynamicSlots.length << 1;
|
|
1224
1267
|
dynamicSlots.push(a => field.slot(a));
|
|
1225
1268
|
}
|
|
1269
|
+
let oldFacets = oldState === null || oldState === void 0 ? void 0 : oldState.config.facets;
|
|
1226
1270
|
for (let id in facets) {
|
|
1227
1271
|
let providers = facets[id], facet = providers[0].facet;
|
|
1272
|
+
let oldProviders = oldFacets && oldFacets[id] || [];
|
|
1228
1273
|
if (providers.every(p => p.type == 0 /* Static */)) {
|
|
1229
1274
|
address[facet.id] = (staticValues.length << 1) | 1;
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1275
|
+
if (sameArray(oldProviders, providers)) {
|
|
1276
|
+
staticValues.push(oldState.facet(facet));
|
|
1277
|
+
}
|
|
1278
|
+
else {
|
|
1279
|
+
let value = facet.combine(providers.map(p => p.value));
|
|
1280
|
+
staticValues.push(oldState && facet.compare(value, oldState.facet(facet)) ? oldState.facet(facet) : value);
|
|
1236
1281
|
}
|
|
1237
|
-
staticValues.push(value);
|
|
1238
1282
|
}
|
|
1239
1283
|
else {
|
|
1240
1284
|
for (let p of providers) {
|
|
@@ -1251,7 +1295,8 @@ class Configuration {
|
|
|
1251
1295
|
dynamicSlots.push(a => dynamicFacetSlot(a, facet, providers));
|
|
1252
1296
|
}
|
|
1253
1297
|
}
|
|
1254
|
-
|
|
1298
|
+
let dynamic = dynamicSlots.map(f => f(address));
|
|
1299
|
+
return new Configuration(base, newCompartments, dynamic, address, staticValues, facets);
|
|
1255
1300
|
}
|
|
1256
1301
|
}
|
|
1257
1302
|
function flatten(extension, compartments, newCompartments) {
|
|
@@ -1303,7 +1348,6 @@ function flatten(extension, compartments, newCompartments) {
|
|
|
1303
1348
|
inner(extension, Prec_.default);
|
|
1304
1349
|
return result.reduce((a, b) => a.concat(b));
|
|
1305
1350
|
}
|
|
1306
|
-
const Uninitialized = {};
|
|
1307
1351
|
function ensureAddr(state, addr) {
|
|
1308
1352
|
if (addr & 1)
|
|
1309
1353
|
return 2 /* Computed */;
|
|
@@ -1314,7 +1358,7 @@ function ensureAddr(state, addr) {
|
|
|
1314
1358
|
if (status & 2 /* Computed */)
|
|
1315
1359
|
return status;
|
|
1316
1360
|
state.status[idx] = 4 /* Computing */;
|
|
1317
|
-
let changed = state.config.dynamicSlots[idx]
|
|
1361
|
+
let changed = state.computeSlot(state, state.config.dynamicSlots[idx]);
|
|
1318
1362
|
return state.status[idx] = 2 /* Computed */ | changed;
|
|
1319
1363
|
}
|
|
1320
1364
|
function getAddr(state, addr) {
|
|
@@ -1833,24 +1877,20 @@ class EditorState {
|
|
|
1833
1877
|
/**
|
|
1834
1878
|
@internal
|
|
1835
1879
|
*/
|
|
1836
|
-
values, tr
|
|
1880
|
+
values, computeSlot, tr) {
|
|
1837
1881
|
this.config = config;
|
|
1838
1882
|
this.doc = doc;
|
|
1839
1883
|
this.selection = selection;
|
|
1840
1884
|
this.values = values;
|
|
1841
|
-
/**
|
|
1842
|
-
@internal
|
|
1843
|
-
*/
|
|
1844
|
-
this.applying = null;
|
|
1845
1885
|
this.status = config.statusTemplate.slice();
|
|
1846
|
-
this.
|
|
1886
|
+
this.computeSlot = computeSlot;
|
|
1847
1887
|
// Fill in the computed state immediately, so that further queries
|
|
1848
1888
|
// for it made during the update return this state
|
|
1849
1889
|
if (tr)
|
|
1850
1890
|
tr._state = this;
|
|
1851
1891
|
for (let i = 0; i < this.config.dynamicSlots.length; i++)
|
|
1852
1892
|
ensureAddr(this, i << 1);
|
|
1853
|
-
this.
|
|
1893
|
+
this.computeSlot = null;
|
|
1854
1894
|
}
|
|
1855
1895
|
field(field, require = true) {
|
|
1856
1896
|
let addr = this.config.address[field.id];
|
|
@@ -1906,20 +1946,13 @@ class EditorState {
|
|
|
1906
1946
|
let startValues;
|
|
1907
1947
|
if (!conf) {
|
|
1908
1948
|
conf = Configuration.resolve(base, compartments, this);
|
|
1909
|
-
let
|
|
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);
|
|
1949
|
+
let intermediateState = new EditorState(conf, this.doc, this.selection, conf.dynamicSlots.map(() => null), (state, slot) => slot.reconfigure(state, this), null);
|
|
1917
1950
|
startValues = intermediateState.values;
|
|
1918
1951
|
}
|
|
1919
1952
|
else {
|
|
1920
1953
|
startValues = tr.startState.values.slice();
|
|
1921
1954
|
}
|
|
1922
|
-
new EditorState(conf, tr.newDoc, tr.newSelection, startValues, tr);
|
|
1955
|
+
new EditorState(conf, tr.newDoc, tr.newSelection, startValues, (state, slot) => slot.update(state, tr), tr);
|
|
1923
1956
|
}
|
|
1924
1957
|
/**
|
|
1925
1958
|
Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
|
|
@@ -2052,7 +2085,7 @@ class EditorState {
|
|
|
2052
2085
|
checkSelection(selection, doc.length);
|
|
2053
2086
|
if (!configuration.staticFacet(allowMultipleSelections))
|
|
2054
2087
|
selection = selection.asSingle();
|
|
2055
|
-
return new EditorState(configuration, doc, selection, configuration.dynamicSlots.map(
|
|
2088
|
+
return new EditorState(configuration, doc, selection, configuration.dynamicSlots.map(() => null), (state, slot) => slot.create(state), null);
|
|
2056
2089
|
}
|
|
2057
2090
|
/**
|
|
2058
2091
|
The size (in columns) of a tab in the document, determined by
|
|
@@ -2265,9 +2298,7 @@ combine = {}) {
|
|
|
2265
2298
|
|
|
2266
2299
|
Object.defineProperty(exports, 'Text', {
|
|
2267
2300
|
enumerable: true,
|
|
2268
|
-
get: function () {
|
|
2269
|
-
return text.Text;
|
|
2270
|
-
}
|
|
2301
|
+
get: function () { return text.Text; }
|
|
2271
2302
|
});
|
|
2272
2303
|
exports.Annotation = Annotation;
|
|
2273
2304
|
exports.AnnotationType = AnnotationType;
|
package/dist/index.d.ts
CHANGED
|
@@ -163,7 +163,9 @@ declare class ChangeSet extends ChangeDesc {
|
|
|
163
163
|
map(other: ChangeDesc, before?: boolean): ChangeSet;
|
|
164
164
|
/**
|
|
165
165
|
Iterate over the changed ranges in the document, calling `f` for
|
|
166
|
-
each
|
|
166
|
+
each, with the range in the original document (`fromA`-`toA`)
|
|
167
|
+
and the range that replaces it in the new document
|
|
168
|
+
(`fromB`-`toB`).
|
|
167
169
|
|
|
168
170
|
When `individual` is true, adjacent changes are reported
|
|
169
171
|
separately.
|
package/dist/index.js
CHANGED
|
@@ -261,7 +261,9 @@ class ChangeSet extends ChangeDesc {
|
|
|
261
261
|
map(other, before = false) { return other.empty ? this : mapSet(this, other, before, true); }
|
|
262
262
|
/**
|
|
263
263
|
Iterate over the changed ranges in the document, calling `f` for
|
|
264
|
-
each
|
|
264
|
+
each, with the range in the original document (`fromA`-`toA`)
|
|
265
|
+
and the range that replaces it in the new document
|
|
266
|
+
(`fromB`-`toB`).
|
|
265
267
|
|
|
266
268
|
When `individual` is true, adjacent changes are reported
|
|
267
269
|
separately.
|
|
@@ -831,7 +833,8 @@ class EditorSelection {
|
|
|
831
833
|
*/
|
|
832
834
|
static range(anchor, head, goalColumn) {
|
|
833
835
|
let goal = (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* NoGoalColumn */) << 5 /* GoalColumnOffset */;
|
|
834
|
-
return head < anchor ? new SelectionRange(head, anchor, 16 /* Inverted */ | goal
|
|
836
|
+
return head < anchor ? new SelectionRange(head, anchor, 16 /* Inverted */ | goal | 8 /* AssocAfter */)
|
|
837
|
+
: new SelectionRange(anchor, head, goal | (head > anchor ? 4 /* AssocBefore */ : 0));
|
|
835
838
|
}
|
|
836
839
|
}
|
|
837
840
|
function normalized(ranges, mainIndex = 0) {
|
|
@@ -952,7 +955,7 @@ class FacetProvider {
|
|
|
952
955
|
var _a;
|
|
953
956
|
let getter = this.value;
|
|
954
957
|
let compare = this.facet.compareInput;
|
|
955
|
-
let idx = addresses[
|
|
958
|
+
let id = this.id, idx = addresses[id] >> 1, multi = this.type == 2 /* Multi */;
|
|
956
959
|
let depDoc = false, depSel = false, depAddrs = [];
|
|
957
960
|
for (let dep of this.dependencies) {
|
|
958
961
|
if (dep == "doc")
|
|
@@ -962,24 +965,35 @@ class FacetProvider {
|
|
|
962
965
|
else if ((((_a = addresses[dep.id]) !== null && _a !== void 0 ? _a : 1) & 1) == 0)
|
|
963
966
|
depAddrs.push(addresses[dep.id]);
|
|
964
967
|
}
|
|
965
|
-
return
|
|
966
|
-
|
|
967
|
-
if (oldVal === Uninitialized) {
|
|
968
|
+
return {
|
|
969
|
+
create(state) {
|
|
968
970
|
state.values[idx] = getter(state);
|
|
969
971
|
return 1 /* Changed */;
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
depAddrs.some(addr => (ensureAddr(state, addr) & 1 /* Changed */) > 0)
|
|
974
|
-
if (depChanged) {
|
|
972
|
+
},
|
|
973
|
+
update(state, tr) {
|
|
974
|
+
if ((depDoc && tr.docChanged) || (depSel && (tr.docChanged || tr.selection)) ||
|
|
975
|
+
depAddrs.some(addr => (ensureAddr(state, addr) & 1 /* Changed */) > 0)) {
|
|
975
976
|
let newVal = getter(state);
|
|
976
|
-
if (multi ? !compareArray(newVal,
|
|
977
|
+
if (multi ? !compareArray(newVal, state.values[idx], compare) : !compare(newVal, state.values[idx])) {
|
|
977
978
|
state.values[idx] = newVal;
|
|
978
979
|
return 1 /* Changed */;
|
|
979
980
|
}
|
|
980
981
|
}
|
|
982
|
+
return 0;
|
|
983
|
+
},
|
|
984
|
+
reconfigure(state, oldState) {
|
|
985
|
+
let newVal = getter(state);
|
|
986
|
+
let oldAddr = oldState.config.address[id];
|
|
987
|
+
if (oldAddr != null) {
|
|
988
|
+
let oldVal = getAddr(oldState, oldAddr);
|
|
989
|
+
if (multi ? compareArray(newVal, oldVal, compare) : compare(newVal, oldVal)) {
|
|
990
|
+
state.values[idx] = oldVal;
|
|
991
|
+
return 0;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
state.values[idx] = newVal;
|
|
995
|
+
return 1 /* Changed */;
|
|
981
996
|
}
|
|
982
|
-
return 0;
|
|
983
997
|
};
|
|
984
998
|
}
|
|
985
999
|
}
|
|
@@ -996,14 +1010,7 @@ function dynamicFacetSlot(addresses, facet, providers) {
|
|
|
996
1010
|
let providerTypes = providers.map(p => p.type);
|
|
997
1011
|
let dynamic = providerAddrs.filter(p => !(p & 1));
|
|
998
1012
|
let idx = addresses[facet.id] >> 1;
|
|
999
|
-
|
|
1000
|
-
let oldVal = state.values[idx], changed = oldVal === Uninitialized;
|
|
1001
|
-
for (let dynAddr of dynamic) {
|
|
1002
|
-
if (ensureAddr(state, dynAddr) & 1 /* Changed */)
|
|
1003
|
-
changed = true;
|
|
1004
|
-
}
|
|
1005
|
-
if (!changed)
|
|
1006
|
-
return 0;
|
|
1013
|
+
function get(state) {
|
|
1007
1014
|
let values = [];
|
|
1008
1015
|
for (let i = 0; i < providerAddrs.length; i++) {
|
|
1009
1016
|
let value = getAddr(state, providerAddrs[i]);
|
|
@@ -1013,11 +1020,39 @@ function dynamicFacetSlot(addresses, facet, providers) {
|
|
|
1013
1020
|
else
|
|
1014
1021
|
values.push(value);
|
|
1015
1022
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
state
|
|
1020
|
-
|
|
1023
|
+
return facet.combine(values);
|
|
1024
|
+
}
|
|
1025
|
+
return {
|
|
1026
|
+
create(state) {
|
|
1027
|
+
for (let addr of providerAddrs)
|
|
1028
|
+
ensureAddr(state, addr);
|
|
1029
|
+
state.values[idx] = get(state);
|
|
1030
|
+
return 1 /* Changed */;
|
|
1031
|
+
},
|
|
1032
|
+
update(state, tr) {
|
|
1033
|
+
if (!dynamic.some(dynAddr => ensureAddr(state, dynAddr) & 1 /* Changed */))
|
|
1034
|
+
return 0;
|
|
1035
|
+
let value = get(state);
|
|
1036
|
+
if (facet.compare(value, state.values[idx]))
|
|
1037
|
+
return 0;
|
|
1038
|
+
state.values[idx] = value;
|
|
1039
|
+
return 1 /* Changed */;
|
|
1040
|
+
},
|
|
1041
|
+
reconfigure(state, oldState) {
|
|
1042
|
+
let depChanged = providerAddrs.some(addr => ensureAddr(state, addr) & 1 /* Changed */);
|
|
1043
|
+
let oldProviders = oldState.config.facets[facet.id], oldValue = oldState.facet(facet);
|
|
1044
|
+
if (oldProviders && !depChanged && sameArray(providers, oldProviders)) {
|
|
1045
|
+
state.values[idx] = oldValue;
|
|
1046
|
+
return 0;
|
|
1047
|
+
}
|
|
1048
|
+
let value = get(state);
|
|
1049
|
+
if (facet.compare(value, oldValue)) {
|
|
1050
|
+
state.values[idx] = oldValue;
|
|
1051
|
+
return 0;
|
|
1052
|
+
}
|
|
1053
|
+
state.values[idx] = value;
|
|
1054
|
+
return 1 /* Changed */;
|
|
1055
|
+
}
|
|
1021
1056
|
};
|
|
1022
1057
|
}
|
|
1023
1058
|
const initField = /*@__PURE__*/Facet.define({ static: true });
|
|
@@ -1063,20 +1098,27 @@ class StateField {
|
|
|
1063
1098
|
*/
|
|
1064
1099
|
slot(addresses) {
|
|
1065
1100
|
let idx = addresses[this.id] >> 1;
|
|
1066
|
-
return
|
|
1067
|
-
|
|
1068
|
-
if (oldVal === Uninitialized) {
|
|
1101
|
+
return {
|
|
1102
|
+
create: (state) => {
|
|
1069
1103
|
state.values[idx] = this.create(state);
|
|
1070
1104
|
return 1 /* Changed */;
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1105
|
+
},
|
|
1106
|
+
update: (state, tr) => {
|
|
1107
|
+
let oldVal = state.values[idx];
|
|
1073
1108
|
let value = this.updateF(oldVal, tr);
|
|
1074
|
-
if (
|
|
1075
|
-
|
|
1076
|
-
|
|
1109
|
+
if (this.compareF(oldVal, value))
|
|
1110
|
+
return 0;
|
|
1111
|
+
state.values[idx] = value;
|
|
1112
|
+
return 1 /* Changed */;
|
|
1113
|
+
},
|
|
1114
|
+
reconfigure: (state, oldState) => {
|
|
1115
|
+
if (oldState.config.address[this.id] != null) {
|
|
1116
|
+
state.values[idx] = oldState.field(this);
|
|
1117
|
+
return 0;
|
|
1077
1118
|
}
|
|
1119
|
+
state.values[idx] = this.create(state);
|
|
1120
|
+
return 1 /* Changed */;
|
|
1078
1121
|
}
|
|
1079
|
-
return 0;
|
|
1080
1122
|
};
|
|
1081
1123
|
}
|
|
1082
1124
|
/**
|
|
@@ -1188,12 +1230,13 @@ class CompartmentInstance {
|
|
|
1188
1230
|
}
|
|
1189
1231
|
}
|
|
1190
1232
|
class Configuration {
|
|
1191
|
-
constructor(base, compartments, dynamicSlots, address, staticValues) {
|
|
1233
|
+
constructor(base, compartments, dynamicSlots, address, staticValues, facets) {
|
|
1192
1234
|
this.base = base;
|
|
1193
1235
|
this.compartments = compartments;
|
|
1194
1236
|
this.dynamicSlots = dynamicSlots;
|
|
1195
1237
|
this.address = address;
|
|
1196
1238
|
this.staticValues = staticValues;
|
|
1239
|
+
this.facets = facets;
|
|
1197
1240
|
this.statusTemplate = [];
|
|
1198
1241
|
while (this.statusTemplate.length < dynamicSlots.length)
|
|
1199
1242
|
this.statusTemplate.push(0 /* Unresolved */);
|
|
@@ -1219,18 +1262,19 @@ class Configuration {
|
|
|
1219
1262
|
address[field.id] = dynamicSlots.length << 1;
|
|
1220
1263
|
dynamicSlots.push(a => field.slot(a));
|
|
1221
1264
|
}
|
|
1265
|
+
let oldFacets = oldState === null || oldState === void 0 ? void 0 : oldState.config.facets;
|
|
1222
1266
|
for (let id in facets) {
|
|
1223
1267
|
let providers = facets[id], facet = providers[0].facet;
|
|
1268
|
+
let oldProviders = oldFacets && oldFacets[id] || [];
|
|
1224
1269
|
if (providers.every(p => p.type == 0 /* Static */)) {
|
|
1225
1270
|
address[facet.id] = (staticValues.length << 1) | 1;
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1271
|
+
if (sameArray(oldProviders, providers)) {
|
|
1272
|
+
staticValues.push(oldState.facet(facet));
|
|
1273
|
+
}
|
|
1274
|
+
else {
|
|
1275
|
+
let value = facet.combine(providers.map(p => p.value));
|
|
1276
|
+
staticValues.push(oldState && facet.compare(value, oldState.facet(facet)) ? oldState.facet(facet) : value);
|
|
1232
1277
|
}
|
|
1233
|
-
staticValues.push(value);
|
|
1234
1278
|
}
|
|
1235
1279
|
else {
|
|
1236
1280
|
for (let p of providers) {
|
|
@@ -1247,7 +1291,8 @@ class Configuration {
|
|
|
1247
1291
|
dynamicSlots.push(a => dynamicFacetSlot(a, facet, providers));
|
|
1248
1292
|
}
|
|
1249
1293
|
}
|
|
1250
|
-
|
|
1294
|
+
let dynamic = dynamicSlots.map(f => f(address));
|
|
1295
|
+
return new Configuration(base, newCompartments, dynamic, address, staticValues, facets);
|
|
1251
1296
|
}
|
|
1252
1297
|
}
|
|
1253
1298
|
function flatten(extension, compartments, newCompartments) {
|
|
@@ -1299,7 +1344,6 @@ function flatten(extension, compartments, newCompartments) {
|
|
|
1299
1344
|
inner(extension, Prec_.default);
|
|
1300
1345
|
return result.reduce((a, b) => a.concat(b));
|
|
1301
1346
|
}
|
|
1302
|
-
const Uninitialized = {};
|
|
1303
1347
|
function ensureAddr(state, addr) {
|
|
1304
1348
|
if (addr & 1)
|
|
1305
1349
|
return 2 /* Computed */;
|
|
@@ -1310,7 +1354,7 @@ function ensureAddr(state, addr) {
|
|
|
1310
1354
|
if (status & 2 /* Computed */)
|
|
1311
1355
|
return status;
|
|
1312
1356
|
state.status[idx] = 4 /* Computing */;
|
|
1313
|
-
let changed = state.config.dynamicSlots[idx]
|
|
1357
|
+
let changed = state.computeSlot(state, state.config.dynamicSlots[idx]);
|
|
1314
1358
|
return state.status[idx] = 2 /* Computed */ | changed;
|
|
1315
1359
|
}
|
|
1316
1360
|
function getAddr(state, addr) {
|
|
@@ -1828,24 +1872,20 @@ class EditorState {
|
|
|
1828
1872
|
/**
|
|
1829
1873
|
@internal
|
|
1830
1874
|
*/
|
|
1831
|
-
values, tr
|
|
1875
|
+
values, computeSlot, tr) {
|
|
1832
1876
|
this.config = config;
|
|
1833
1877
|
this.doc = doc;
|
|
1834
1878
|
this.selection = selection;
|
|
1835
1879
|
this.values = values;
|
|
1836
|
-
/**
|
|
1837
|
-
@internal
|
|
1838
|
-
*/
|
|
1839
|
-
this.applying = null;
|
|
1840
1880
|
this.status = config.statusTemplate.slice();
|
|
1841
|
-
this.
|
|
1881
|
+
this.computeSlot = computeSlot;
|
|
1842
1882
|
// Fill in the computed state immediately, so that further queries
|
|
1843
1883
|
// for it made during the update return this state
|
|
1844
1884
|
if (tr)
|
|
1845
1885
|
tr._state = this;
|
|
1846
1886
|
for (let i = 0; i < this.config.dynamicSlots.length; i++)
|
|
1847
1887
|
ensureAddr(this, i << 1);
|
|
1848
|
-
this.
|
|
1888
|
+
this.computeSlot = null;
|
|
1849
1889
|
}
|
|
1850
1890
|
field(field, require = true) {
|
|
1851
1891
|
let addr = this.config.address[field.id];
|
|
@@ -1901,20 +1941,13 @@ class EditorState {
|
|
|
1901
1941
|
let startValues;
|
|
1902
1942
|
if (!conf) {
|
|
1903
1943
|
conf = Configuration.resolve(base, compartments, this);
|
|
1904
|
-
let
|
|
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);
|
|
1944
|
+
let intermediateState = new EditorState(conf, this.doc, this.selection, conf.dynamicSlots.map(() => null), (state, slot) => slot.reconfigure(state, this), null);
|
|
1912
1945
|
startValues = intermediateState.values;
|
|
1913
1946
|
}
|
|
1914
1947
|
else {
|
|
1915
1948
|
startValues = tr.startState.values.slice();
|
|
1916
1949
|
}
|
|
1917
|
-
new EditorState(conf, tr.newDoc, tr.newSelection, startValues, tr);
|
|
1950
|
+
new EditorState(conf, tr.newDoc, tr.newSelection, startValues, (state, slot) => slot.update(state, tr), tr);
|
|
1918
1951
|
}
|
|
1919
1952
|
/**
|
|
1920
1953
|
Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
|
|
@@ -2047,7 +2080,7 @@ class EditorState {
|
|
|
2047
2080
|
checkSelection(selection, doc.length);
|
|
2048
2081
|
if (!configuration.staticFacet(allowMultipleSelections))
|
|
2049
2082
|
selection = selection.asSingle();
|
|
2050
|
-
return new EditorState(configuration, doc, selection, configuration.dynamicSlots.map(
|
|
2083
|
+
return new EditorState(configuration, doc, selection, configuration.dynamicSlots.map(() => null), (state, slot) => slot.create(state), null);
|
|
2051
2084
|
}
|
|
2052
2085
|
/**
|
|
2053
2086
|
The size (in columns) of a tab in the document, determined by
|