@codemirror/state 0.19.5 → 0.19.9
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 +105 -67
- package/dist/index.d.ts +3 -1
- package/dist/index.js +104 -64
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## 0.19.9 (2022-02-16)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Mapping a non-empty selection range now always puts any newly inserted text on the sides of the range outside of the mapped version.
|
|
6
|
+
|
|
7
|
+
## 0.19.8 (2022-02-15)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
Fix a bug where facet values with computed inputs could incorrectly retain their old value on reconfiguration.
|
|
12
|
+
|
|
13
|
+
## 0.19.7 (2022-02-11)
|
|
14
|
+
|
|
15
|
+
### Bug fixes
|
|
16
|
+
|
|
17
|
+
Avoid recomputing facets on state reconfiguration if that facet's inputs stayed precisely the same.
|
|
18
|
+
|
|
19
|
+
Selection ranges created with `EditorSelection.range` will now have an assoc pointing at their anchor, when non-empty.
|
|
20
|
+
|
|
21
|
+
## 0.19.6 (2021-11-19)
|
|
22
|
+
|
|
23
|
+
### Bug fixes
|
|
24
|
+
|
|
25
|
+
Fix a bug that caused facet compare functions to be called with an invalid value in some situations.
|
|
26
|
+
|
|
27
|
+
Fix a bug that caused dynamic facet values to be incorrectly kept unchanged when reconfiguration changed one of their dependencies.
|
|
28
|
+
|
|
1
29
|
## 0.19.5 (2021-11-10)
|
|
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.
|
|
@@ -683,7 +685,14 @@ class SelectionRange {
|
|
|
683
685
|
updated document.
|
|
684
686
|
*/
|
|
685
687
|
map(change, assoc = -1) {
|
|
686
|
-
let from
|
|
688
|
+
let from, to;
|
|
689
|
+
if (this.empty) {
|
|
690
|
+
from = to = change.mapPos(this.from, assoc);
|
|
691
|
+
}
|
|
692
|
+
else {
|
|
693
|
+
from = change.mapPos(this.from, 1);
|
|
694
|
+
to = change.mapPos(this.to, -1);
|
|
695
|
+
}
|
|
687
696
|
return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags);
|
|
688
697
|
}
|
|
689
698
|
/**
|
|
@@ -835,7 +844,8 @@ class EditorSelection {
|
|
|
835
844
|
*/
|
|
836
845
|
static range(anchor, head, goalColumn) {
|
|
837
846
|
let goal = (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* NoGoalColumn */) << 5 /* GoalColumnOffset */;
|
|
838
|
-
return head < anchor ? new SelectionRange(head, anchor, 16 /* Inverted */ | goal
|
|
847
|
+
return head < anchor ? new SelectionRange(head, anchor, 16 /* Inverted */ | goal | 8 /* AssocAfter */)
|
|
848
|
+
: new SelectionRange(anchor, head, goal | (head > anchor ? 4 /* AssocBefore */ : 0));
|
|
839
849
|
}
|
|
840
850
|
}
|
|
841
851
|
function normalized(ranges, mainIndex = 0) {
|
|
@@ -956,7 +966,7 @@ class FacetProvider {
|
|
|
956
966
|
var _a;
|
|
957
967
|
let getter = this.value;
|
|
958
968
|
let compare = this.facet.compareInput;
|
|
959
|
-
let idx = addresses[
|
|
969
|
+
let id = this.id, idx = addresses[id] >> 1, multi = this.type == 2 /* Multi */;
|
|
960
970
|
let depDoc = false, depSel = false, depAddrs = [];
|
|
961
971
|
for (let dep of this.dependencies) {
|
|
962
972
|
if (dep == "doc")
|
|
@@ -966,24 +976,35 @@ class FacetProvider {
|
|
|
966
976
|
else if ((((_a = addresses[dep.id]) !== null && _a !== void 0 ? _a : 1) & 1) == 0)
|
|
967
977
|
depAddrs.push(addresses[dep.id]);
|
|
968
978
|
}
|
|
969
|
-
return
|
|
970
|
-
|
|
971
|
-
if (oldVal === Uninitialized) {
|
|
979
|
+
return {
|
|
980
|
+
create(state) {
|
|
972
981
|
state.values[idx] = getter(state);
|
|
973
982
|
return 1 /* Changed */;
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
depAddrs.some(addr => (ensureAddr(state, addr) & 1 /* Changed */) > 0)
|
|
978
|
-
if (depChanged) {
|
|
983
|
+
},
|
|
984
|
+
update(state, tr) {
|
|
985
|
+
if ((depDoc && tr.docChanged) || (depSel && (tr.docChanged || tr.selection)) ||
|
|
986
|
+
depAddrs.some(addr => (ensureAddr(state, addr) & 1 /* Changed */) > 0)) {
|
|
979
987
|
let newVal = getter(state);
|
|
980
|
-
if (multi ? !compareArray(newVal,
|
|
988
|
+
if (multi ? !compareArray(newVal, state.values[idx], compare) : !compare(newVal, state.values[idx])) {
|
|
981
989
|
state.values[idx] = newVal;
|
|
982
990
|
return 1 /* Changed */;
|
|
983
991
|
}
|
|
984
992
|
}
|
|
993
|
+
return 0;
|
|
994
|
+
},
|
|
995
|
+
reconfigure(state, oldState) {
|
|
996
|
+
let newVal = getter(state);
|
|
997
|
+
let oldAddr = oldState.config.address[id];
|
|
998
|
+
if (oldAddr != null) {
|
|
999
|
+
let oldVal = getAddr(oldState, oldAddr);
|
|
1000
|
+
if (multi ? compareArray(newVal, oldVal, compare) : compare(newVal, oldVal)) {
|
|
1001
|
+
state.values[idx] = oldVal;
|
|
1002
|
+
return 0;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
state.values[idx] = newVal;
|
|
1006
|
+
return 1 /* Changed */;
|
|
985
1007
|
}
|
|
986
|
-
return 0;
|
|
987
1008
|
};
|
|
988
1009
|
}
|
|
989
1010
|
}
|
|
@@ -1000,14 +1021,7 @@ function dynamicFacetSlot(addresses, facet, providers) {
|
|
|
1000
1021
|
let providerTypes = providers.map(p => p.type);
|
|
1001
1022
|
let dynamic = providerAddrs.filter(p => !(p & 1));
|
|
1002
1023
|
let idx = addresses[facet.id] >> 1;
|
|
1003
|
-
|
|
1004
|
-
let oldVal = state.values[idx], changed = oldVal === Uninitialized || !tr;
|
|
1005
|
-
for (let dynAddr of dynamic) {
|
|
1006
|
-
if (ensureAddr(state, dynAddr) & 1 /* Changed */)
|
|
1007
|
-
changed = true;
|
|
1008
|
-
}
|
|
1009
|
-
if (!changed)
|
|
1010
|
-
return 0;
|
|
1024
|
+
function get(state) {
|
|
1011
1025
|
let values = [];
|
|
1012
1026
|
for (let i = 0; i < providerAddrs.length; i++) {
|
|
1013
1027
|
let value = getAddr(state, providerAddrs[i]);
|
|
@@ -1017,11 +1031,39 @@ function dynamicFacetSlot(addresses, facet, providers) {
|
|
|
1017
1031
|
else
|
|
1018
1032
|
values.push(value);
|
|
1019
1033
|
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
state
|
|
1024
|
-
|
|
1034
|
+
return facet.combine(values);
|
|
1035
|
+
}
|
|
1036
|
+
return {
|
|
1037
|
+
create(state) {
|
|
1038
|
+
for (let addr of providerAddrs)
|
|
1039
|
+
ensureAddr(state, addr);
|
|
1040
|
+
state.values[idx] = get(state);
|
|
1041
|
+
return 1 /* Changed */;
|
|
1042
|
+
},
|
|
1043
|
+
update(state, tr) {
|
|
1044
|
+
if (!dynamic.some(dynAddr => ensureAddr(state, dynAddr) & 1 /* Changed */))
|
|
1045
|
+
return 0;
|
|
1046
|
+
let value = get(state);
|
|
1047
|
+
if (facet.compare(value, state.values[idx]))
|
|
1048
|
+
return 0;
|
|
1049
|
+
state.values[idx] = value;
|
|
1050
|
+
return 1 /* Changed */;
|
|
1051
|
+
},
|
|
1052
|
+
reconfigure(state, oldState) {
|
|
1053
|
+
let depChanged = providerAddrs.some(addr => ensureAddr(state, addr) & 1 /* Changed */);
|
|
1054
|
+
let oldProviders = oldState.config.facets[facet.id], oldValue = oldState.facet(facet);
|
|
1055
|
+
if (oldProviders && !depChanged && sameArray(providers, oldProviders)) {
|
|
1056
|
+
state.values[idx] = oldValue;
|
|
1057
|
+
return 0;
|
|
1058
|
+
}
|
|
1059
|
+
let value = get(state);
|
|
1060
|
+
if (facet.compare(value, oldValue)) {
|
|
1061
|
+
state.values[idx] = oldValue;
|
|
1062
|
+
return 0;
|
|
1063
|
+
}
|
|
1064
|
+
state.values[idx] = value;
|
|
1065
|
+
return 1 /* Changed */;
|
|
1066
|
+
}
|
|
1025
1067
|
};
|
|
1026
1068
|
}
|
|
1027
1069
|
const initField = Facet.define({ static: true });
|
|
@@ -1067,20 +1109,27 @@ class StateField {
|
|
|
1067
1109
|
*/
|
|
1068
1110
|
slot(addresses) {
|
|
1069
1111
|
let idx = addresses[this.id] >> 1;
|
|
1070
|
-
return
|
|
1071
|
-
|
|
1072
|
-
if (oldVal === Uninitialized) {
|
|
1112
|
+
return {
|
|
1113
|
+
create: (state) => {
|
|
1073
1114
|
state.values[idx] = this.create(state);
|
|
1074
1115
|
return 1 /* Changed */;
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1116
|
+
},
|
|
1117
|
+
update: (state, tr) => {
|
|
1118
|
+
let oldVal = state.values[idx];
|
|
1077
1119
|
let value = this.updateF(oldVal, tr);
|
|
1078
|
-
if (
|
|
1079
|
-
|
|
1080
|
-
|
|
1120
|
+
if (this.compareF(oldVal, value))
|
|
1121
|
+
return 0;
|
|
1122
|
+
state.values[idx] = value;
|
|
1123
|
+
return 1 /* Changed */;
|
|
1124
|
+
},
|
|
1125
|
+
reconfigure: (state, oldState) => {
|
|
1126
|
+
if (oldState.config.address[this.id] != null) {
|
|
1127
|
+
state.values[idx] = oldState.field(this);
|
|
1128
|
+
return 0;
|
|
1081
1129
|
}
|
|
1130
|
+
state.values[idx] = this.create(state);
|
|
1131
|
+
return 1 /* Changed */;
|
|
1082
1132
|
}
|
|
1083
|
-
return 0;
|
|
1084
1133
|
};
|
|
1085
1134
|
}
|
|
1086
1135
|
/**
|
|
@@ -1192,12 +1241,13 @@ class CompartmentInstance {
|
|
|
1192
1241
|
}
|
|
1193
1242
|
}
|
|
1194
1243
|
class Configuration {
|
|
1195
|
-
constructor(base, compartments, dynamicSlots, address, staticValues) {
|
|
1244
|
+
constructor(base, compartments, dynamicSlots, address, staticValues, facets) {
|
|
1196
1245
|
this.base = base;
|
|
1197
1246
|
this.compartments = compartments;
|
|
1198
1247
|
this.dynamicSlots = dynamicSlots;
|
|
1199
1248
|
this.address = address;
|
|
1200
1249
|
this.staticValues = staticValues;
|
|
1250
|
+
this.facets = facets;
|
|
1201
1251
|
this.statusTemplate = [];
|
|
1202
1252
|
while (this.statusTemplate.length < dynamicSlots.length)
|
|
1203
1253
|
this.statusTemplate.push(0 /* Unresolved */);
|
|
@@ -1223,18 +1273,19 @@ class Configuration {
|
|
|
1223
1273
|
address[field.id] = dynamicSlots.length << 1;
|
|
1224
1274
|
dynamicSlots.push(a => field.slot(a));
|
|
1225
1275
|
}
|
|
1276
|
+
let oldFacets = oldState === null || oldState === void 0 ? void 0 : oldState.config.facets;
|
|
1226
1277
|
for (let id in facets) {
|
|
1227
1278
|
let providers = facets[id], facet = providers[0].facet;
|
|
1279
|
+
let oldProviders = oldFacets && oldFacets[id] || [];
|
|
1228
1280
|
if (providers.every(p => p.type == 0 /* Static */)) {
|
|
1229
1281
|
address[facet.id] = (staticValues.length << 1) | 1;
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1282
|
+
if (sameArray(oldProviders, providers)) {
|
|
1283
|
+
staticValues.push(oldState.facet(facet));
|
|
1284
|
+
}
|
|
1285
|
+
else {
|
|
1286
|
+
let value = facet.combine(providers.map(p => p.value));
|
|
1287
|
+
staticValues.push(oldState && facet.compare(value, oldState.facet(facet)) ? oldState.facet(facet) : value);
|
|
1236
1288
|
}
|
|
1237
|
-
staticValues.push(value);
|
|
1238
1289
|
}
|
|
1239
1290
|
else {
|
|
1240
1291
|
for (let p of providers) {
|
|
@@ -1251,7 +1302,8 @@ class Configuration {
|
|
|
1251
1302
|
dynamicSlots.push(a => dynamicFacetSlot(a, facet, providers));
|
|
1252
1303
|
}
|
|
1253
1304
|
}
|
|
1254
|
-
|
|
1305
|
+
let dynamic = dynamicSlots.map(f => f(address));
|
|
1306
|
+
return new Configuration(base, newCompartments, dynamic, address, staticValues, facets);
|
|
1255
1307
|
}
|
|
1256
1308
|
}
|
|
1257
1309
|
function flatten(extension, compartments, newCompartments) {
|
|
@@ -1303,7 +1355,6 @@ function flatten(extension, compartments, newCompartments) {
|
|
|
1303
1355
|
inner(extension, Prec_.default);
|
|
1304
1356
|
return result.reduce((a, b) => a.concat(b));
|
|
1305
1357
|
}
|
|
1306
|
-
const Uninitialized = {};
|
|
1307
1358
|
function ensureAddr(state, addr) {
|
|
1308
1359
|
if (addr & 1)
|
|
1309
1360
|
return 2 /* Computed */;
|
|
@@ -1314,7 +1365,7 @@ function ensureAddr(state, addr) {
|
|
|
1314
1365
|
if (status & 2 /* Computed */)
|
|
1315
1366
|
return status;
|
|
1316
1367
|
state.status[idx] = 4 /* Computing */;
|
|
1317
|
-
let changed = state.config.dynamicSlots[idx]
|
|
1368
|
+
let changed = state.computeSlot(state, state.config.dynamicSlots[idx]);
|
|
1318
1369
|
return state.status[idx] = 2 /* Computed */ | changed;
|
|
1319
1370
|
}
|
|
1320
1371
|
function getAddr(state, addr) {
|
|
@@ -1833,24 +1884,20 @@ class EditorState {
|
|
|
1833
1884
|
/**
|
|
1834
1885
|
@internal
|
|
1835
1886
|
*/
|
|
1836
|
-
values, tr
|
|
1887
|
+
values, computeSlot, tr) {
|
|
1837
1888
|
this.config = config;
|
|
1838
1889
|
this.doc = doc;
|
|
1839
1890
|
this.selection = selection;
|
|
1840
1891
|
this.values = values;
|
|
1841
|
-
/**
|
|
1842
|
-
@internal
|
|
1843
|
-
*/
|
|
1844
|
-
this.applying = null;
|
|
1845
1892
|
this.status = config.statusTemplate.slice();
|
|
1846
|
-
this.
|
|
1893
|
+
this.computeSlot = computeSlot;
|
|
1847
1894
|
// Fill in the computed state immediately, so that further queries
|
|
1848
1895
|
// for it made during the update return this state
|
|
1849
1896
|
if (tr)
|
|
1850
1897
|
tr._state = this;
|
|
1851
1898
|
for (let i = 0; i < this.config.dynamicSlots.length; i++)
|
|
1852
1899
|
ensureAddr(this, i << 1);
|
|
1853
|
-
this.
|
|
1900
|
+
this.computeSlot = null;
|
|
1854
1901
|
}
|
|
1855
1902
|
field(field, require = true) {
|
|
1856
1903
|
let addr = this.config.address[field.id];
|
|
@@ -1906,20 +1953,13 @@ class EditorState {
|
|
|
1906
1953
|
let startValues;
|
|
1907
1954
|
if (!conf) {
|
|
1908
1955
|
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);
|
|
1956
|
+
let intermediateState = new EditorState(conf, this.doc, this.selection, conf.dynamicSlots.map(() => null), (state, slot) => slot.reconfigure(state, this), null);
|
|
1917
1957
|
startValues = intermediateState.values;
|
|
1918
1958
|
}
|
|
1919
1959
|
else {
|
|
1920
1960
|
startValues = tr.startState.values.slice();
|
|
1921
1961
|
}
|
|
1922
|
-
new EditorState(conf, tr.newDoc, tr.newSelection, startValues, tr);
|
|
1962
|
+
new EditorState(conf, tr.newDoc, tr.newSelection, startValues, (state, slot) => slot.update(state, tr), tr);
|
|
1923
1963
|
}
|
|
1924
1964
|
/**
|
|
1925
1965
|
Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
|
|
@@ -2052,7 +2092,7 @@ class EditorState {
|
|
|
2052
2092
|
checkSelection(selection, doc.length);
|
|
2053
2093
|
if (!configuration.staticFacet(allowMultipleSelections))
|
|
2054
2094
|
selection = selection.asSingle();
|
|
2055
|
-
return new EditorState(configuration, doc, selection, configuration.dynamicSlots.map(
|
|
2095
|
+
return new EditorState(configuration, doc, selection, configuration.dynamicSlots.map(() => null), (state, slot) => slot.create(state), null);
|
|
2056
2096
|
}
|
|
2057
2097
|
/**
|
|
2058
2098
|
The size (in columns) of a tab in the document, determined by
|
|
@@ -2265,9 +2305,7 @@ combine = {}) {
|
|
|
2265
2305
|
|
|
2266
2306
|
Object.defineProperty(exports, 'Text', {
|
|
2267
2307
|
enumerable: true,
|
|
2268
|
-
get: function () {
|
|
2269
|
-
return text.Text;
|
|
2270
|
-
}
|
|
2308
|
+
get: function () { return text.Text; }
|
|
2271
2309
|
});
|
|
2272
2310
|
exports.Annotation = Annotation;
|
|
2273
2311
|
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.
|
|
@@ -679,7 +681,14 @@ class SelectionRange {
|
|
|
679
681
|
updated document.
|
|
680
682
|
*/
|
|
681
683
|
map(change, assoc = -1) {
|
|
682
|
-
let from
|
|
684
|
+
let from, to;
|
|
685
|
+
if (this.empty) {
|
|
686
|
+
from = to = change.mapPos(this.from, assoc);
|
|
687
|
+
}
|
|
688
|
+
else {
|
|
689
|
+
from = change.mapPos(this.from, 1);
|
|
690
|
+
to = change.mapPos(this.to, -1);
|
|
691
|
+
}
|
|
683
692
|
return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags);
|
|
684
693
|
}
|
|
685
694
|
/**
|
|
@@ -831,7 +840,8 @@ class EditorSelection {
|
|
|
831
840
|
*/
|
|
832
841
|
static range(anchor, head, goalColumn) {
|
|
833
842
|
let goal = (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* NoGoalColumn */) << 5 /* GoalColumnOffset */;
|
|
834
|
-
return head < anchor ? new SelectionRange(head, anchor, 16 /* Inverted */ | goal
|
|
843
|
+
return head < anchor ? new SelectionRange(head, anchor, 16 /* Inverted */ | goal | 8 /* AssocAfter */)
|
|
844
|
+
: new SelectionRange(anchor, head, goal | (head > anchor ? 4 /* AssocBefore */ : 0));
|
|
835
845
|
}
|
|
836
846
|
}
|
|
837
847
|
function normalized(ranges, mainIndex = 0) {
|
|
@@ -952,7 +962,7 @@ class FacetProvider {
|
|
|
952
962
|
var _a;
|
|
953
963
|
let getter = this.value;
|
|
954
964
|
let compare = this.facet.compareInput;
|
|
955
|
-
let idx = addresses[
|
|
965
|
+
let id = this.id, idx = addresses[id] >> 1, multi = this.type == 2 /* Multi */;
|
|
956
966
|
let depDoc = false, depSel = false, depAddrs = [];
|
|
957
967
|
for (let dep of this.dependencies) {
|
|
958
968
|
if (dep == "doc")
|
|
@@ -962,24 +972,35 @@ class FacetProvider {
|
|
|
962
972
|
else if ((((_a = addresses[dep.id]) !== null && _a !== void 0 ? _a : 1) & 1) == 0)
|
|
963
973
|
depAddrs.push(addresses[dep.id]);
|
|
964
974
|
}
|
|
965
|
-
return
|
|
966
|
-
|
|
967
|
-
if (oldVal === Uninitialized) {
|
|
975
|
+
return {
|
|
976
|
+
create(state) {
|
|
968
977
|
state.values[idx] = getter(state);
|
|
969
978
|
return 1 /* Changed */;
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
depAddrs.some(addr => (ensureAddr(state, addr) & 1 /* Changed */) > 0)
|
|
974
|
-
if (depChanged) {
|
|
979
|
+
},
|
|
980
|
+
update(state, tr) {
|
|
981
|
+
if ((depDoc && tr.docChanged) || (depSel && (tr.docChanged || tr.selection)) ||
|
|
982
|
+
depAddrs.some(addr => (ensureAddr(state, addr) & 1 /* Changed */) > 0)) {
|
|
975
983
|
let newVal = getter(state);
|
|
976
|
-
if (multi ? !compareArray(newVal,
|
|
984
|
+
if (multi ? !compareArray(newVal, state.values[idx], compare) : !compare(newVal, state.values[idx])) {
|
|
977
985
|
state.values[idx] = newVal;
|
|
978
986
|
return 1 /* Changed */;
|
|
979
987
|
}
|
|
980
988
|
}
|
|
989
|
+
return 0;
|
|
990
|
+
},
|
|
991
|
+
reconfigure(state, oldState) {
|
|
992
|
+
let newVal = getter(state);
|
|
993
|
+
let oldAddr = oldState.config.address[id];
|
|
994
|
+
if (oldAddr != null) {
|
|
995
|
+
let oldVal = getAddr(oldState, oldAddr);
|
|
996
|
+
if (multi ? compareArray(newVal, oldVal, compare) : compare(newVal, oldVal)) {
|
|
997
|
+
state.values[idx] = oldVal;
|
|
998
|
+
return 0;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
state.values[idx] = newVal;
|
|
1002
|
+
return 1 /* Changed */;
|
|
981
1003
|
}
|
|
982
|
-
return 0;
|
|
983
1004
|
};
|
|
984
1005
|
}
|
|
985
1006
|
}
|
|
@@ -996,14 +1017,7 @@ function dynamicFacetSlot(addresses, facet, providers) {
|
|
|
996
1017
|
let providerTypes = providers.map(p => p.type);
|
|
997
1018
|
let dynamic = providerAddrs.filter(p => !(p & 1));
|
|
998
1019
|
let idx = addresses[facet.id] >> 1;
|
|
999
|
-
|
|
1000
|
-
let oldVal = state.values[idx], changed = oldVal === Uninitialized || !tr;
|
|
1001
|
-
for (let dynAddr of dynamic) {
|
|
1002
|
-
if (ensureAddr(state, dynAddr) & 1 /* Changed */)
|
|
1003
|
-
changed = true;
|
|
1004
|
-
}
|
|
1005
|
-
if (!changed)
|
|
1006
|
-
return 0;
|
|
1020
|
+
function get(state) {
|
|
1007
1021
|
let values = [];
|
|
1008
1022
|
for (let i = 0; i < providerAddrs.length; i++) {
|
|
1009
1023
|
let value = getAddr(state, providerAddrs[i]);
|
|
@@ -1013,11 +1027,39 @@ function dynamicFacetSlot(addresses, facet, providers) {
|
|
|
1013
1027
|
else
|
|
1014
1028
|
values.push(value);
|
|
1015
1029
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
state
|
|
1020
|
-
|
|
1030
|
+
return facet.combine(values);
|
|
1031
|
+
}
|
|
1032
|
+
return {
|
|
1033
|
+
create(state) {
|
|
1034
|
+
for (let addr of providerAddrs)
|
|
1035
|
+
ensureAddr(state, addr);
|
|
1036
|
+
state.values[idx] = get(state);
|
|
1037
|
+
return 1 /* Changed */;
|
|
1038
|
+
},
|
|
1039
|
+
update(state, tr) {
|
|
1040
|
+
if (!dynamic.some(dynAddr => ensureAddr(state, dynAddr) & 1 /* Changed */))
|
|
1041
|
+
return 0;
|
|
1042
|
+
let value = get(state);
|
|
1043
|
+
if (facet.compare(value, state.values[idx]))
|
|
1044
|
+
return 0;
|
|
1045
|
+
state.values[idx] = value;
|
|
1046
|
+
return 1 /* Changed */;
|
|
1047
|
+
},
|
|
1048
|
+
reconfigure(state, oldState) {
|
|
1049
|
+
let depChanged = providerAddrs.some(addr => ensureAddr(state, addr) & 1 /* Changed */);
|
|
1050
|
+
let oldProviders = oldState.config.facets[facet.id], oldValue = oldState.facet(facet);
|
|
1051
|
+
if (oldProviders && !depChanged && sameArray(providers, oldProviders)) {
|
|
1052
|
+
state.values[idx] = oldValue;
|
|
1053
|
+
return 0;
|
|
1054
|
+
}
|
|
1055
|
+
let value = get(state);
|
|
1056
|
+
if (facet.compare(value, oldValue)) {
|
|
1057
|
+
state.values[idx] = oldValue;
|
|
1058
|
+
return 0;
|
|
1059
|
+
}
|
|
1060
|
+
state.values[idx] = value;
|
|
1061
|
+
return 1 /* Changed */;
|
|
1062
|
+
}
|
|
1021
1063
|
};
|
|
1022
1064
|
}
|
|
1023
1065
|
const initField = /*@__PURE__*/Facet.define({ static: true });
|
|
@@ -1063,20 +1105,27 @@ class StateField {
|
|
|
1063
1105
|
*/
|
|
1064
1106
|
slot(addresses) {
|
|
1065
1107
|
let idx = addresses[this.id] >> 1;
|
|
1066
|
-
return
|
|
1067
|
-
|
|
1068
|
-
if (oldVal === Uninitialized) {
|
|
1108
|
+
return {
|
|
1109
|
+
create: (state) => {
|
|
1069
1110
|
state.values[idx] = this.create(state);
|
|
1070
1111
|
return 1 /* Changed */;
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1112
|
+
},
|
|
1113
|
+
update: (state, tr) => {
|
|
1114
|
+
let oldVal = state.values[idx];
|
|
1073
1115
|
let value = this.updateF(oldVal, tr);
|
|
1074
|
-
if (
|
|
1075
|
-
|
|
1076
|
-
|
|
1116
|
+
if (this.compareF(oldVal, value))
|
|
1117
|
+
return 0;
|
|
1118
|
+
state.values[idx] = value;
|
|
1119
|
+
return 1 /* Changed */;
|
|
1120
|
+
},
|
|
1121
|
+
reconfigure: (state, oldState) => {
|
|
1122
|
+
if (oldState.config.address[this.id] != null) {
|
|
1123
|
+
state.values[idx] = oldState.field(this);
|
|
1124
|
+
return 0;
|
|
1077
1125
|
}
|
|
1126
|
+
state.values[idx] = this.create(state);
|
|
1127
|
+
return 1 /* Changed */;
|
|
1078
1128
|
}
|
|
1079
|
-
return 0;
|
|
1080
1129
|
};
|
|
1081
1130
|
}
|
|
1082
1131
|
/**
|
|
@@ -1188,12 +1237,13 @@ class CompartmentInstance {
|
|
|
1188
1237
|
}
|
|
1189
1238
|
}
|
|
1190
1239
|
class Configuration {
|
|
1191
|
-
constructor(base, compartments, dynamicSlots, address, staticValues) {
|
|
1240
|
+
constructor(base, compartments, dynamicSlots, address, staticValues, facets) {
|
|
1192
1241
|
this.base = base;
|
|
1193
1242
|
this.compartments = compartments;
|
|
1194
1243
|
this.dynamicSlots = dynamicSlots;
|
|
1195
1244
|
this.address = address;
|
|
1196
1245
|
this.staticValues = staticValues;
|
|
1246
|
+
this.facets = facets;
|
|
1197
1247
|
this.statusTemplate = [];
|
|
1198
1248
|
while (this.statusTemplate.length < dynamicSlots.length)
|
|
1199
1249
|
this.statusTemplate.push(0 /* Unresolved */);
|
|
@@ -1219,18 +1269,19 @@ class Configuration {
|
|
|
1219
1269
|
address[field.id] = dynamicSlots.length << 1;
|
|
1220
1270
|
dynamicSlots.push(a => field.slot(a));
|
|
1221
1271
|
}
|
|
1272
|
+
let oldFacets = oldState === null || oldState === void 0 ? void 0 : oldState.config.facets;
|
|
1222
1273
|
for (let id in facets) {
|
|
1223
1274
|
let providers = facets[id], facet = providers[0].facet;
|
|
1275
|
+
let oldProviders = oldFacets && oldFacets[id] || [];
|
|
1224
1276
|
if (providers.every(p => p.type == 0 /* Static */)) {
|
|
1225
1277
|
address[facet.id] = (staticValues.length << 1) | 1;
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1278
|
+
if (sameArray(oldProviders, providers)) {
|
|
1279
|
+
staticValues.push(oldState.facet(facet));
|
|
1280
|
+
}
|
|
1281
|
+
else {
|
|
1282
|
+
let value = facet.combine(providers.map(p => p.value));
|
|
1283
|
+
staticValues.push(oldState && facet.compare(value, oldState.facet(facet)) ? oldState.facet(facet) : value);
|
|
1232
1284
|
}
|
|
1233
|
-
staticValues.push(value);
|
|
1234
1285
|
}
|
|
1235
1286
|
else {
|
|
1236
1287
|
for (let p of providers) {
|
|
@@ -1247,7 +1298,8 @@ class Configuration {
|
|
|
1247
1298
|
dynamicSlots.push(a => dynamicFacetSlot(a, facet, providers));
|
|
1248
1299
|
}
|
|
1249
1300
|
}
|
|
1250
|
-
|
|
1301
|
+
let dynamic = dynamicSlots.map(f => f(address));
|
|
1302
|
+
return new Configuration(base, newCompartments, dynamic, address, staticValues, facets);
|
|
1251
1303
|
}
|
|
1252
1304
|
}
|
|
1253
1305
|
function flatten(extension, compartments, newCompartments) {
|
|
@@ -1299,7 +1351,6 @@ function flatten(extension, compartments, newCompartments) {
|
|
|
1299
1351
|
inner(extension, Prec_.default);
|
|
1300
1352
|
return result.reduce((a, b) => a.concat(b));
|
|
1301
1353
|
}
|
|
1302
|
-
const Uninitialized = {};
|
|
1303
1354
|
function ensureAddr(state, addr) {
|
|
1304
1355
|
if (addr & 1)
|
|
1305
1356
|
return 2 /* Computed */;
|
|
@@ -1310,7 +1361,7 @@ function ensureAddr(state, addr) {
|
|
|
1310
1361
|
if (status & 2 /* Computed */)
|
|
1311
1362
|
return status;
|
|
1312
1363
|
state.status[idx] = 4 /* Computing */;
|
|
1313
|
-
let changed = state.config.dynamicSlots[idx]
|
|
1364
|
+
let changed = state.computeSlot(state, state.config.dynamicSlots[idx]);
|
|
1314
1365
|
return state.status[idx] = 2 /* Computed */ | changed;
|
|
1315
1366
|
}
|
|
1316
1367
|
function getAddr(state, addr) {
|
|
@@ -1828,24 +1879,20 @@ class EditorState {
|
|
|
1828
1879
|
/**
|
|
1829
1880
|
@internal
|
|
1830
1881
|
*/
|
|
1831
|
-
values, tr
|
|
1882
|
+
values, computeSlot, tr) {
|
|
1832
1883
|
this.config = config;
|
|
1833
1884
|
this.doc = doc;
|
|
1834
1885
|
this.selection = selection;
|
|
1835
1886
|
this.values = values;
|
|
1836
|
-
/**
|
|
1837
|
-
@internal
|
|
1838
|
-
*/
|
|
1839
|
-
this.applying = null;
|
|
1840
1887
|
this.status = config.statusTemplate.slice();
|
|
1841
|
-
this.
|
|
1888
|
+
this.computeSlot = computeSlot;
|
|
1842
1889
|
// Fill in the computed state immediately, so that further queries
|
|
1843
1890
|
// for it made during the update return this state
|
|
1844
1891
|
if (tr)
|
|
1845
1892
|
tr._state = this;
|
|
1846
1893
|
for (let i = 0; i < this.config.dynamicSlots.length; i++)
|
|
1847
1894
|
ensureAddr(this, i << 1);
|
|
1848
|
-
this.
|
|
1895
|
+
this.computeSlot = null;
|
|
1849
1896
|
}
|
|
1850
1897
|
field(field, require = true) {
|
|
1851
1898
|
let addr = this.config.address[field.id];
|
|
@@ -1901,20 +1948,13 @@ class EditorState {
|
|
|
1901
1948
|
let startValues;
|
|
1902
1949
|
if (!conf) {
|
|
1903
1950
|
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);
|
|
1951
|
+
let intermediateState = new EditorState(conf, this.doc, this.selection, conf.dynamicSlots.map(() => null), (state, slot) => slot.reconfigure(state, this), null);
|
|
1912
1952
|
startValues = intermediateState.values;
|
|
1913
1953
|
}
|
|
1914
1954
|
else {
|
|
1915
1955
|
startValues = tr.startState.values.slice();
|
|
1916
1956
|
}
|
|
1917
|
-
new EditorState(conf, tr.newDoc, tr.newSelection, startValues, tr);
|
|
1957
|
+
new EditorState(conf, tr.newDoc, tr.newSelection, startValues, (state, slot) => slot.update(state, tr), tr);
|
|
1918
1958
|
}
|
|
1919
1959
|
/**
|
|
1920
1960
|
Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
|
|
@@ -2047,7 +2087,7 @@ class EditorState {
|
|
|
2047
2087
|
checkSelection(selection, doc.length);
|
|
2048
2088
|
if (!configuration.staticFacet(allowMultipleSelections))
|
|
2049
2089
|
selection = selection.asSingle();
|
|
2050
|
-
return new EditorState(configuration, doc, selection, configuration.dynamicSlots.map(
|
|
2090
|
+
return new EditorState(configuration, doc, selection, configuration.dynamicSlots.map(() => null), (state, slot) => slot.create(state), null);
|
|
2051
2091
|
}
|
|
2052
2092
|
/**
|
|
2053
2093
|
The size (in columns) of a tab in the document, determined by
|