@codemirror/state 0.19.3 → 0.19.4
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 +6 -0
- package/dist/index.cjs +51 -50
- package/dist/index.js +51 -50
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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
|
-
|
|
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
|
-
|
|
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 (
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
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
|
}
|
|
@@ -998,9 +1000,8 @@ function dynamicFacetSlot(addresses, facet, providers) {
|
|
|
998
1000
|
let providerTypes = providers.map(p => p.type);
|
|
999
1001
|
let dynamic = providerAddrs.filter(p => !(p & 1));
|
|
1000
1002
|
let idx = addresses[facet.id] >> 1;
|
|
1001
|
-
return (state
|
|
1002
|
-
let
|
|
1003
|
-
let changed = oldAddr == null;
|
|
1003
|
+
return (state) => {
|
|
1004
|
+
let oldVal = state.values[idx], changed = oldVal === Uninitialized;
|
|
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
|
|
1020
|
-
if (
|
|
1020
|
+
let value = facet.combine(values);
|
|
1021
|
+
if (facet.compare(value, oldVal))
|
|
1021
1022
|
return 0;
|
|
1022
|
-
state.values[idx] =
|
|
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
|
-
|
|
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
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -1208,7 +1200,7 @@ class Configuration {
|
|
|
1208
1200
|
this.staticValues = staticValues;
|
|
1209
1201
|
this.statusTemplate = [];
|
|
1210
1202
|
while (this.statusTemplate.length < dynamicSlots.length)
|
|
1211
|
-
this.statusTemplate.push(0 /*
|
|
1203
|
+
this.statusTemplate.push(0 /* Unresolved */);
|
|
1212
1204
|
}
|
|
1213
1205
|
staticFacet(facet) {
|
|
1214
1206
|
let addr = this.address[facet.id];
|
|
@@ -1311,6 +1303,7 @@ function flatten(extension, compartments, newCompartments) {
|
|
|
1311
1303
|
inner(extension, Prec_.default);
|
|
1312
1304
|
return result.reduce((a, b) => a.concat(b));
|
|
1313
1305
|
}
|
|
1306
|
+
const Uninitialized = {};
|
|
1314
1307
|
function ensureAddr(state, addr) {
|
|
1315
1308
|
if (addr & 1)
|
|
1316
1309
|
return 2 /* Computed */;
|
|
@@ -1836,28 +1829,20 @@ class EditorState {
|
|
|
1836
1829
|
/**
|
|
1837
1830
|
The current selection.
|
|
1838
1831
|
*/
|
|
1839
|
-
selection,
|
|
1832
|
+
selection,
|
|
1833
|
+
/**
|
|
1834
|
+
@internal
|
|
1835
|
+
*/
|
|
1836
|
+
values, tr = null) {
|
|
1840
1837
|
this.config = config;
|
|
1841
1838
|
this.doc = doc;
|
|
1842
1839
|
this.selection = selection;
|
|
1840
|
+
this.values = values;
|
|
1843
1841
|
/**
|
|
1844
1842
|
@internal
|
|
1845
1843
|
*/
|
|
1846
1844
|
this.applying = null;
|
|
1847
1845
|
this.status = config.statusTemplate.slice();
|
|
1848
|
-
if (tr && tr.startState.config == config) {
|
|
1849
|
-
this.values = tr.startState.values.slice();
|
|
1850
|
-
}
|
|
1851
|
-
else {
|
|
1852
|
-
this.values = config.dynamicSlots.map(_ => null);
|
|
1853
|
-
// Copy over old values for shared facets/fields if this is a reconfigure
|
|
1854
|
-
if (tr)
|
|
1855
|
-
for (let id in config.address) {
|
|
1856
|
-
let cur = config.address[id], prev = tr.startState.config.address[id];
|
|
1857
|
-
if (prev != null && (cur & 1) == 0)
|
|
1858
|
-
this.values[cur >> 1] = getAddr(tr.startState, prev);
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
1846
|
this.applying = tr;
|
|
1862
1847
|
// Fill in the computed state immediately, so that further queries
|
|
1863
1848
|
// for it made during the update return this state
|
|
@@ -1918,7 +1903,23 @@ class EditorState {
|
|
|
1918
1903
|
base = asArray(base).concat(effect.value);
|
|
1919
1904
|
}
|
|
1920
1905
|
}
|
|
1921
|
-
|
|
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);
|
|
1922
1923
|
}
|
|
1923
1924
|
/**
|
|
1924
1925
|
Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
|
|
@@ -2051,7 +2052,7 @@ class EditorState {
|
|
|
2051
2052
|
checkSelection(selection, doc.length);
|
|
2052
2053
|
if (!configuration.staticFacet(allowMultipleSelections))
|
|
2053
2054
|
selection = selection.asSingle();
|
|
2054
|
-
return new EditorState(configuration, doc, selection);
|
|
2055
|
+
return new EditorState(configuration, doc, selection, configuration.dynamicSlots.map(_ => Uninitialized));
|
|
2055
2056
|
}
|
|
2056
2057
|
/**
|
|
2057
2058
|
The size (in columns) of a tab in the document, determined by
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
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
|
}
|
|
@@ -994,9 +996,8 @@ function dynamicFacetSlot(addresses, facet, providers) {
|
|
|
994
996
|
let providerTypes = providers.map(p => p.type);
|
|
995
997
|
let dynamic = providerAddrs.filter(p => !(p & 1));
|
|
996
998
|
let idx = addresses[facet.id] >> 1;
|
|
997
|
-
return (state
|
|
998
|
-
let
|
|
999
|
-
let changed = oldAddr == null;
|
|
999
|
+
return (state) => {
|
|
1000
|
+
let oldVal = state.values[idx], changed = oldVal === Uninitialized;
|
|
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
|
|
1016
|
-
if (
|
|
1016
|
+
let value = facet.combine(values);
|
|
1017
|
+
if (facet.compare(value, oldVal))
|
|
1017
1018
|
return 0;
|
|
1018
|
-
state.values[idx] =
|
|
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
|
-
|
|
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
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -1204,7 +1196,7 @@ class Configuration {
|
|
|
1204
1196
|
this.staticValues = staticValues;
|
|
1205
1197
|
this.statusTemplate = [];
|
|
1206
1198
|
while (this.statusTemplate.length < dynamicSlots.length)
|
|
1207
|
-
this.statusTemplate.push(0 /*
|
|
1199
|
+
this.statusTemplate.push(0 /* Unresolved */);
|
|
1208
1200
|
}
|
|
1209
1201
|
staticFacet(facet) {
|
|
1210
1202
|
let addr = this.address[facet.id];
|
|
@@ -1307,6 +1299,7 @@ function flatten(extension, compartments, newCompartments) {
|
|
|
1307
1299
|
inner(extension, Prec_.default);
|
|
1308
1300
|
return result.reduce((a, b) => a.concat(b));
|
|
1309
1301
|
}
|
|
1302
|
+
const Uninitialized = {};
|
|
1310
1303
|
function ensureAddr(state, addr) {
|
|
1311
1304
|
if (addr & 1)
|
|
1312
1305
|
return 2 /* Computed */;
|
|
@@ -1831,28 +1824,20 @@ class EditorState {
|
|
|
1831
1824
|
/**
|
|
1832
1825
|
The current selection.
|
|
1833
1826
|
*/
|
|
1834
|
-
selection,
|
|
1827
|
+
selection,
|
|
1828
|
+
/**
|
|
1829
|
+
@internal
|
|
1830
|
+
*/
|
|
1831
|
+
values, tr = null) {
|
|
1835
1832
|
this.config = config;
|
|
1836
1833
|
this.doc = doc;
|
|
1837
1834
|
this.selection = selection;
|
|
1835
|
+
this.values = values;
|
|
1838
1836
|
/**
|
|
1839
1837
|
@internal
|
|
1840
1838
|
*/
|
|
1841
1839
|
this.applying = null;
|
|
1842
1840
|
this.status = config.statusTemplate.slice();
|
|
1843
|
-
if (tr && tr.startState.config == config) {
|
|
1844
|
-
this.values = tr.startState.values.slice();
|
|
1845
|
-
}
|
|
1846
|
-
else {
|
|
1847
|
-
this.values = config.dynamicSlots.map(_ => null);
|
|
1848
|
-
// Copy over old values for shared facets/fields if this is a reconfigure
|
|
1849
|
-
if (tr)
|
|
1850
|
-
for (let id in config.address) {
|
|
1851
|
-
let cur = config.address[id], prev = tr.startState.config.address[id];
|
|
1852
|
-
if (prev != null && (cur & 1) == 0)
|
|
1853
|
-
this.values[cur >> 1] = getAddr(tr.startState, prev);
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
1841
|
this.applying = tr;
|
|
1857
1842
|
// Fill in the computed state immediately, so that further queries
|
|
1858
1843
|
// for it made during the update return this state
|
|
@@ -1913,7 +1898,23 @@ class EditorState {
|
|
|
1913
1898
|
base = asArray(base).concat(effect.value);
|
|
1914
1899
|
}
|
|
1915
1900
|
}
|
|
1916
|
-
|
|
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);
|
|
1917
1918
|
}
|
|
1918
1919
|
/**
|
|
1919
1920
|
Create a [transaction spec](https://codemirror.net/6/docs/ref/#state.TransactionSpec) that
|
|
@@ -2046,7 +2047,7 @@ class EditorState {
|
|
|
2046
2047
|
checkSelection(selection, doc.length);
|
|
2047
2048
|
if (!configuration.staticFacet(allowMultipleSelections))
|
|
2048
2049
|
selection = selection.asSingle();
|
|
2049
|
-
return new EditorState(configuration, doc, selection);
|
|
2050
|
+
return new EditorState(configuration, doc, selection, configuration.dynamicSlots.map(_ => Uninitialized));
|
|
2050
2051
|
}
|
|
2051
2052
|
/**
|
|
2052
2053
|
The size (in columns) of a tab in the document, determined by
|