@codemirror/state 0.18.3 → 0.18.7
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 +24 -0
- package/dist/index.cjs +33 -3
- package/dist/index.d.ts +14 -0
- package/dist/index.js +58 -30
- package/package.json +3 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## 0.18.7 (2021-05-04)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix an issue where state fields might be initialized with a state that they aren't actually part of during reconfiguration.
|
|
6
|
+
|
|
7
|
+
## 0.18.6 (2021-04-12)
|
|
8
|
+
|
|
9
|
+
### New features
|
|
10
|
+
|
|
11
|
+
The new `EditorState.wordAt` method finds the word at a given position.
|
|
12
|
+
|
|
13
|
+
## 0.18.5 (2021-04-08)
|
|
14
|
+
|
|
15
|
+
### Bug fixes
|
|
16
|
+
|
|
17
|
+
Fix an issue in the compiled output that would break the code when minified with terser.
|
|
18
|
+
|
|
19
|
+
## 0.18.4 (2021-04-06)
|
|
20
|
+
|
|
21
|
+
### New features
|
|
22
|
+
|
|
23
|
+
The new `Transaction.remote` annotation can be used to mark and recognize transactions created by other actors.
|
|
24
|
+
|
|
1
25
|
## 0.18.3 (2021-03-23)
|
|
2
26
|
|
|
3
27
|
### New features
|
package/dist/index.cjs
CHANGED
|
@@ -1071,14 +1071,13 @@ class StateField {
|
|
|
1071
1071
|
slot(addresses) {
|
|
1072
1072
|
let idx = addresses[this.id] >> 1;
|
|
1073
1073
|
return (state, tr) => {
|
|
1074
|
-
if (!tr) {
|
|
1074
|
+
if (!tr || (tr.reconfigured && maybeIndex(tr.startState, this.id) == null)) {
|
|
1075
1075
|
state.values[idx] = this.create(state);
|
|
1076
1076
|
return 1 /* Changed */;
|
|
1077
1077
|
}
|
|
1078
1078
|
let oldVal, changed = 0;
|
|
1079
1079
|
if (tr.reconfigured) {
|
|
1080
|
-
|
|
1081
|
-
oldVal = oldIdx == null ? this.create(tr.startState) : tr.startState.values[oldIdx];
|
|
1080
|
+
oldVal = tr.startState.values[maybeIndex(tr.startState, this.id)];
|
|
1082
1081
|
changed = 1 /* Changed */;
|
|
1083
1082
|
}
|
|
1084
1083
|
else {
|
|
@@ -1588,6 +1587,13 @@ Annotation indicating whether a transaction should be added to
|
|
|
1588
1587
|
the undo history or not.
|
|
1589
1588
|
*/
|
|
1590
1589
|
Transaction.addToHistory = Annotation.define();
|
|
1590
|
+
/**
|
|
1591
|
+
Annotation indicating (when present and true) that a transaction
|
|
1592
|
+
represents a change made by some other actor, not the user. This
|
|
1593
|
+
is used, for example, to tag other people's changes in
|
|
1594
|
+
collaborative editing.
|
|
1595
|
+
*/
|
|
1596
|
+
Transaction.remote = Annotation.define();
|
|
1591
1597
|
function joinRanges(a, b) {
|
|
1592
1598
|
let result = [];
|
|
1593
1599
|
for (let iA = 0, iB = 0;;) {
|
|
@@ -2047,6 +2053,30 @@ class EditorState {
|
|
|
2047
2053
|
charCategorizer(at) {
|
|
2048
2054
|
return makeCategorizer(this.languageDataAt("wordChars", at).join(""));
|
|
2049
2055
|
}
|
|
2056
|
+
/**
|
|
2057
|
+
Find the word at the given position, meaning the range
|
|
2058
|
+
containing all [word](https://codemirror.net/6/docs/ref/#state.CharCategory.Word) characters
|
|
2059
|
+
around it. If no word characters are adjacent to the position,
|
|
2060
|
+
this returns null.
|
|
2061
|
+
*/
|
|
2062
|
+
wordAt(pos) {
|
|
2063
|
+
let { text: text$1, from, length } = this.doc.lineAt(pos);
|
|
2064
|
+
let cat = this.charCategorizer(pos);
|
|
2065
|
+
let start = pos - from, end = pos - from;
|
|
2066
|
+
while (start > 0) {
|
|
2067
|
+
let prev = text.findClusterBreak(text$1, start, false);
|
|
2068
|
+
if (cat(text$1.slice(prev, start)) != exports.CharCategory.Word)
|
|
2069
|
+
break;
|
|
2070
|
+
start = prev;
|
|
2071
|
+
}
|
|
2072
|
+
while (end < length) {
|
|
2073
|
+
let next = text.findClusterBreak(text$1, end);
|
|
2074
|
+
if (cat(text$1.slice(end, next)) != exports.CharCategory.Word)
|
|
2075
|
+
break;
|
|
2076
|
+
end = next;
|
|
2077
|
+
}
|
|
2078
|
+
return start == end ? EditorSelection.range(start + from, end + from) : null;
|
|
2079
|
+
}
|
|
2050
2080
|
}
|
|
2051
2081
|
/**
|
|
2052
2082
|
A facet that, when enabled, causes the editor to allow multiple
|
package/dist/index.d.ts
CHANGED
|
@@ -794,6 +794,13 @@ declare class Transaction {
|
|
|
794
794
|
the undo history or not.
|
|
795
795
|
*/
|
|
796
796
|
static addToHistory: AnnotationType<boolean>;
|
|
797
|
+
/**
|
|
798
|
+
Annotation indicating (when present and true) that a transaction
|
|
799
|
+
represents a change made by some other actor, not the user. This
|
|
800
|
+
is used, for example, to tag other people's changes in
|
|
801
|
+
collaborative editing.
|
|
802
|
+
*/
|
|
803
|
+
static remote: AnnotationType<boolean>;
|
|
797
804
|
}
|
|
798
805
|
|
|
799
806
|
/**
|
|
@@ -1036,6 +1043,13 @@ declare class EditorState {
|
|
|
1036
1043
|
*/
|
|
1037
1044
|
charCategorizer(at: number): (char: string) => CharCategory;
|
|
1038
1045
|
/**
|
|
1046
|
+
Find the word at the given position, meaning the range
|
|
1047
|
+
containing all [word](https://codemirror.net/6/docs/ref/#state.CharCategory.Word) characters
|
|
1048
|
+
around it. If no word characters are adjacent to the position,
|
|
1049
|
+
this returns null.
|
|
1050
|
+
*/
|
|
1051
|
+
wordAt(pos: number): SelectionRange | null;
|
|
1052
|
+
/**
|
|
1039
1053
|
Facet used to register change filters, which are called for each
|
|
1040
1054
|
transaction (unless explicitly
|
|
1041
1055
|
[disabled](https://codemirror.net/6/docs/ref/#state.TransactionSpec.filter)), and can suppress
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Text } from '@codemirror/text';
|
|
1
|
+
import { Text, findClusterBreak } from '@codemirror/text';
|
|
2
2
|
export { Text } from '@codemirror/text';
|
|
3
3
|
|
|
4
4
|
const DefaultSplit = /\r\n?|\n/;
|
|
5
5
|
/**
|
|
6
6
|
Distinguishes different ways in which positions can be mapped.
|
|
7
7
|
*/
|
|
8
|
-
var MapMode
|
|
9
|
-
(function (MapMode) {
|
|
8
|
+
var MapMode = /*@__PURE__*/(function (MapMode) {
|
|
10
9
|
/**
|
|
11
10
|
Map a position to a valid new position, even when its context
|
|
12
11
|
was deleted.
|
|
@@ -24,7 +23,7 @@ var MapMode;
|
|
|
24
23
|
Return null if the character _after_ the position is deleted.
|
|
25
24
|
*/
|
|
26
25
|
MapMode[MapMode["TrackAfter"] = 3] = "TrackAfter";
|
|
27
|
-
})(MapMode || (MapMode = {}));
|
|
26
|
+
return MapMode})(MapMode || (MapMode = {}));
|
|
28
27
|
/**
|
|
29
28
|
A change description is a variant of [change set](https://codemirror.net/6/docs/ref/#state.ChangeSet)
|
|
30
29
|
that doesn't store the inserted text. As such, it can't be
|
|
@@ -1024,7 +1023,7 @@ function maybeIndex(state, id) {
|
|
|
1024
1023
|
let found = state.config.address[id];
|
|
1025
1024
|
return found == null ? null : found >> 1;
|
|
1026
1025
|
}
|
|
1027
|
-
const initField = Facet.define({ static: true });
|
|
1026
|
+
const initField = /*@__PURE__*/Facet.define({ static: true });
|
|
1028
1027
|
/**
|
|
1029
1028
|
Fields can store additional information in an editor state, and
|
|
1030
1029
|
keep it in sync with the rest of the state.
|
|
@@ -1068,14 +1067,13 @@ class StateField {
|
|
|
1068
1067
|
slot(addresses) {
|
|
1069
1068
|
let idx = addresses[this.id] >> 1;
|
|
1070
1069
|
return (state, tr) => {
|
|
1071
|
-
if (!tr) {
|
|
1070
|
+
if (!tr || (tr.reconfigured && maybeIndex(tr.startState, this.id) == null)) {
|
|
1072
1071
|
state.values[idx] = this.create(state);
|
|
1073
1072
|
return 1 /* Changed */;
|
|
1074
1073
|
}
|
|
1075
1074
|
let oldVal, changed = 0;
|
|
1076
1075
|
if (tr.reconfigured) {
|
|
1077
|
-
|
|
1078
|
-
oldVal = oldIdx == null ? this.create(tr.startState) : tr.startState.values[oldIdx];
|
|
1076
|
+
oldVal = tr.startState.values[maybeIndex(tr.startState, this.id)];
|
|
1079
1077
|
changed = 1 /* Changed */;
|
|
1080
1078
|
}
|
|
1081
1079
|
else {
|
|
@@ -1124,19 +1122,19 @@ const Prec = {
|
|
|
1124
1122
|
default-precedence extensions to override it even if they are
|
|
1125
1123
|
specified later in the extension ordering.
|
|
1126
1124
|
*/
|
|
1127
|
-
fallback: prec(Prec_.fallback),
|
|
1125
|
+
fallback: /*@__PURE__*/prec(Prec_.fallback),
|
|
1128
1126
|
/**
|
|
1129
1127
|
The regular default precedence.
|
|
1130
1128
|
*/
|
|
1131
|
-
default: prec(Prec_.default),
|
|
1129
|
+
default: /*@__PURE__*/prec(Prec_.default),
|
|
1132
1130
|
/**
|
|
1133
1131
|
A higher-than-default precedence.
|
|
1134
1132
|
*/
|
|
1135
|
-
extend: prec(Prec_.extend),
|
|
1133
|
+
extend: /*@__PURE__*/prec(Prec_.extend),
|
|
1136
1134
|
/**
|
|
1137
1135
|
Precedence above the `default` and `extend` precedences.
|
|
1138
1136
|
*/
|
|
1139
|
-
override: prec(Prec_.override)
|
|
1137
|
+
override: /*@__PURE__*/prec(Prec_.override)
|
|
1140
1138
|
};
|
|
1141
1139
|
class PrecExtension {
|
|
1142
1140
|
constructor(inner, prec) {
|
|
@@ -1307,18 +1305,18 @@ function getAddr(state, addr) {
|
|
|
1307
1305
|
return addr & 1 ? state.config.staticValues[addr >> 1] : state.values[addr >> 1];
|
|
1308
1306
|
}
|
|
1309
1307
|
|
|
1310
|
-
const languageData = Facet.define();
|
|
1311
|
-
const allowMultipleSelections = Facet.define({
|
|
1308
|
+
const languageData = /*@__PURE__*/Facet.define();
|
|
1309
|
+
const allowMultipleSelections = /*@__PURE__*/Facet.define({
|
|
1312
1310
|
combine: values => values.some(v => v),
|
|
1313
1311
|
static: true
|
|
1314
1312
|
});
|
|
1315
|
-
const lineSeparator = Facet.define({
|
|
1313
|
+
const lineSeparator = /*@__PURE__*/Facet.define({
|
|
1316
1314
|
combine: values => values.length ? values[0] : undefined,
|
|
1317
1315
|
static: true
|
|
1318
1316
|
});
|
|
1319
|
-
const changeFilter = Facet.define();
|
|
1320
|
-
const transactionFilter = Facet.define();
|
|
1321
|
-
const transactionExtender = Facet.define();
|
|
1317
|
+
const changeFilter = /*@__PURE__*/Facet.define();
|
|
1318
|
+
const transactionFilter = /*@__PURE__*/Facet.define();
|
|
1319
|
+
const transactionExtender = /*@__PURE__*/Facet.define();
|
|
1322
1320
|
|
|
1323
1321
|
/**
|
|
1324
1322
|
Annotations are tagged values that are used to add metadata to
|
|
@@ -1449,11 +1447,11 @@ the editor. Doing this will discard any extensions
|
|
|
1449
1447
|
the content of [reconfigured](https://codemirror.net/6/docs/ref/#state.Compartment.reconfigure)
|
|
1450
1448
|
compartments.
|
|
1451
1449
|
*/
|
|
1452
|
-
StateEffect.reconfigure = StateEffect.define();
|
|
1450
|
+
StateEffect.reconfigure = /*@__PURE__*/StateEffect.define();
|
|
1453
1451
|
/**
|
|
1454
1452
|
Append extensions to the top-level configuration of the editor.
|
|
1455
1453
|
*/
|
|
1456
|
-
StateEffect.appendConfig = StateEffect.define();
|
|
1454
|
+
StateEffect.appendConfig = /*@__PURE__*/StateEffect.define();
|
|
1457
1455
|
/**
|
|
1458
1456
|
Changes to the editor state are grouped into transactions.
|
|
1459
1457
|
Typically, a user action creates a single transaction, which may
|
|
@@ -1566,7 +1564,7 @@ class Transaction {
|
|
|
1566
1564
|
/**
|
|
1567
1565
|
Annotation used to store transaction timestamps.
|
|
1568
1566
|
*/
|
|
1569
|
-
Transaction.time = Annotation.define();
|
|
1567
|
+
Transaction.time = /*@__PURE__*/Annotation.define();
|
|
1570
1568
|
/**
|
|
1571
1569
|
Annotation used to associate a transaction with a user interface
|
|
1572
1570
|
event. The view will set this to...
|
|
@@ -1579,12 +1577,19 @@ event. The view will set this to...
|
|
|
1579
1577
|
- `"cut"` when cutting
|
|
1580
1578
|
- `"drop"` when content is inserted via drag-and-drop
|
|
1581
1579
|
*/
|
|
1582
|
-
Transaction.userEvent = Annotation.define();
|
|
1580
|
+
Transaction.userEvent = /*@__PURE__*/Annotation.define();
|
|
1583
1581
|
/**
|
|
1584
1582
|
Annotation indicating whether a transaction should be added to
|
|
1585
1583
|
the undo history or not.
|
|
1586
1584
|
*/
|
|
1587
|
-
Transaction.addToHistory = Annotation.define();
|
|
1585
|
+
Transaction.addToHistory = /*@__PURE__*/Annotation.define();
|
|
1586
|
+
/**
|
|
1587
|
+
Annotation indicating (when present and true) that a transaction
|
|
1588
|
+
represents a change made by some other actor, not the user. This
|
|
1589
|
+
is used, for example, to tag other people's changes in
|
|
1590
|
+
collaborative editing.
|
|
1591
|
+
*/
|
|
1592
|
+
Transaction.remote = /*@__PURE__*/Annotation.define();
|
|
1588
1593
|
function joinRanges(a, b) {
|
|
1589
1594
|
let result = [];
|
|
1590
1595
|
for (let iA = 0, iB = 0;;) {
|
|
@@ -1709,8 +1714,7 @@ The categories produced by a [character
|
|
|
1709
1714
|
categorizer](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer). These are used
|
|
1710
1715
|
do things like selecting by word.
|
|
1711
1716
|
*/
|
|
1712
|
-
var CharCategory
|
|
1713
|
-
(function (CharCategory) {
|
|
1717
|
+
var CharCategory = /*@__PURE__*/(function (CharCategory) {
|
|
1714
1718
|
/**
|
|
1715
1719
|
Word characters.
|
|
1716
1720
|
*/
|
|
@@ -1723,11 +1727,11 @@ var CharCategory;
|
|
|
1723
1727
|
Anything else.
|
|
1724
1728
|
*/
|
|
1725
1729
|
CharCategory[CharCategory["Other"] = 2] = "Other";
|
|
1726
|
-
})(CharCategory || (CharCategory = {}));
|
|
1730
|
+
return CharCategory})(CharCategory || (CharCategory = {}));
|
|
1727
1731
|
const nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
|
|
1728
1732
|
let wordChar;
|
|
1729
1733
|
try {
|
|
1730
|
-
wordChar = new RegExp("[\\p{Alphabetic}\\p{Number}_]", "u");
|
|
1734
|
+
wordChar = /*@__PURE__*/new RegExp("[\\p{Alphabetic}\\p{Number}_]", "u");
|
|
1731
1735
|
}
|
|
1732
1736
|
catch (_) { }
|
|
1733
1737
|
function hasWordChar(str) {
|
|
@@ -2044,6 +2048,30 @@ class EditorState {
|
|
|
2044
2048
|
charCategorizer(at) {
|
|
2045
2049
|
return makeCategorizer(this.languageDataAt("wordChars", at).join(""));
|
|
2046
2050
|
}
|
|
2051
|
+
/**
|
|
2052
|
+
Find the word at the given position, meaning the range
|
|
2053
|
+
containing all [word](https://codemirror.net/6/docs/ref/#state.CharCategory.Word) characters
|
|
2054
|
+
around it. If no word characters are adjacent to the position,
|
|
2055
|
+
this returns null.
|
|
2056
|
+
*/
|
|
2057
|
+
wordAt(pos) {
|
|
2058
|
+
let { text, from, length } = this.doc.lineAt(pos);
|
|
2059
|
+
let cat = this.charCategorizer(pos);
|
|
2060
|
+
let start = pos - from, end = pos - from;
|
|
2061
|
+
while (start > 0) {
|
|
2062
|
+
let prev = findClusterBreak(text, start, false);
|
|
2063
|
+
if (cat(text.slice(prev, start)) != CharCategory.Word)
|
|
2064
|
+
break;
|
|
2065
|
+
start = prev;
|
|
2066
|
+
}
|
|
2067
|
+
while (end < length) {
|
|
2068
|
+
let next = findClusterBreak(text, end);
|
|
2069
|
+
if (cat(text.slice(end, next)) != CharCategory.Word)
|
|
2070
|
+
break;
|
|
2071
|
+
end = next;
|
|
2072
|
+
}
|
|
2073
|
+
return start == end ? EditorSelection.range(start + from, end + from) : null;
|
|
2074
|
+
}
|
|
2047
2075
|
}
|
|
2048
2076
|
/**
|
|
2049
2077
|
A facet that, when enabled, causes the editor to allow multiple
|
|
@@ -2059,7 +2087,7 @@ Configures the tab size to use in this state. The first
|
|
|
2059
2087
|
(highest-precedence) value of the facet is used. If no value is
|
|
2060
2088
|
given, this defaults to 4.
|
|
2061
2089
|
*/
|
|
2062
|
-
EditorState.tabSize = Facet.define({
|
|
2090
|
+
EditorState.tabSize = /*@__PURE__*/Facet.define({
|
|
2063
2091
|
combine: values => values.length ? values[0] : 4
|
|
2064
2092
|
});
|
|
2065
2093
|
/**
|
|
@@ -2078,7 +2106,7 @@ Registers translation phrases. The
|
|
|
2078
2106
|
all objects registered with this facet to find translations for
|
|
2079
2107
|
its argument.
|
|
2080
2108
|
*/
|
|
2081
|
-
EditorState.phrases = Facet.define();
|
|
2109
|
+
EditorState.phrases = /*@__PURE__*/Facet.define();
|
|
2082
2110
|
/**
|
|
2083
2111
|
A facet used to register [language
|
|
2084
2112
|
data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) providers.
|
|
@@ -2132,7 +2160,7 @@ but do want to process every transaction.
|
|
|
2132
2160
|
Extenders run _after_ filters, when both are applied.
|
|
2133
2161
|
*/
|
|
2134
2162
|
EditorState.transactionExtender = transactionExtender;
|
|
2135
|
-
Compartment.reconfigure = StateEffect.define();
|
|
2163
|
+
Compartment.reconfigure = /*@__PURE__*/StateEffect.define();
|
|
2136
2164
|
|
|
2137
2165
|
/**
|
|
2138
2166
|
Utility function for combining behaviors to fill in a config
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemirror/state",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.7",
|
|
4
4
|
"description": "Editor state data structures for the CodeMirror code editor",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"test": "
|
|
6
|
+
"test": "cm-runtests",
|
|
7
7
|
"prepare": "cm-buildhelper src/index.ts"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
@@ -29,10 +29,7 @@
|
|
|
29
29
|
"@codemirror/text": "^0.18.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@codemirror/buildhelper": "^0.1.
|
|
33
|
-
"@types/mocha": "^5.2.0",
|
|
34
|
-
"ist": "^1.1.6",
|
|
35
|
-
"mocha": "^7.1.1"
|
|
32
|
+
"@codemirror/buildhelper": "^0.1.5"
|
|
36
33
|
},
|
|
37
34
|
"repository": {
|
|
38
35
|
"type": "git",
|