@codemirror/state 0.20.0 → 0.20.1
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 +85 -58
- package/dist/index.d.ts +18 -1
- package/dist/index.js +85 -58
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -690,9 +690,6 @@ class ChangeDesc {
|
|
|
690
690
|
// unaffected sections, and the length of the replacement content
|
|
691
691
|
// otherwise. So an insertion would be (0, n>0), a deletion (n>0,
|
|
692
692
|
// 0), and a replacement two positive numbers.
|
|
693
|
-
/**
|
|
694
|
-
@internal
|
|
695
|
-
*/
|
|
696
693
|
constructor(
|
|
697
694
|
/**
|
|
698
695
|
@internal
|
|
@@ -847,6 +844,10 @@ class ChangeDesc {
|
|
|
847
844
|
throw new RangeError("Invalid JSON representation of ChangeDesc");
|
|
848
845
|
return new ChangeDesc(json);
|
|
849
846
|
}
|
|
847
|
+
/**
|
|
848
|
+
@internal
|
|
849
|
+
*/
|
|
850
|
+
static create(sections) { return new ChangeDesc(sections); }
|
|
850
851
|
}
|
|
851
852
|
/**
|
|
852
853
|
A change set represents a group of modifications to a document. It
|
|
@@ -854,9 +855,6 @@ stores the document length, and can only be applied to documents
|
|
|
854
855
|
with exactly that length.
|
|
855
856
|
*/
|
|
856
857
|
class ChangeSet extends ChangeDesc {
|
|
857
|
-
/**
|
|
858
|
-
@internal
|
|
859
|
-
*/
|
|
860
858
|
constructor(sections,
|
|
861
859
|
/**
|
|
862
860
|
@internal
|
|
@@ -935,7 +933,7 @@ class ChangeSet extends ChangeDesc {
|
|
|
935
933
|
Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change
|
|
936
934
|
set.
|
|
937
935
|
*/
|
|
938
|
-
get desc() { return
|
|
936
|
+
get desc() { return ChangeDesc.create(this.sections); }
|
|
939
937
|
/**
|
|
940
938
|
@internal
|
|
941
939
|
*/
|
|
@@ -968,7 +966,7 @@ class ChangeSet extends ChangeDesc {
|
|
|
968
966
|
}
|
|
969
967
|
}
|
|
970
968
|
return { changes: new ChangeSet(resultSections, resultInserted),
|
|
971
|
-
filtered:
|
|
969
|
+
filtered: ChangeDesc.create(filteredSections) };
|
|
972
970
|
}
|
|
973
971
|
/**
|
|
974
972
|
Serialize this change set to a JSON-representable value.
|
|
@@ -1070,6 +1068,12 @@ class ChangeSet extends ChangeDesc {
|
|
|
1070
1068
|
}
|
|
1071
1069
|
return new ChangeSet(sections, inserted);
|
|
1072
1070
|
}
|
|
1071
|
+
/**
|
|
1072
|
+
@internal
|
|
1073
|
+
*/
|
|
1074
|
+
static createSet(sections, inserted) {
|
|
1075
|
+
return new ChangeSet(sections, inserted);
|
|
1076
|
+
}
|
|
1073
1077
|
}
|
|
1074
1078
|
function addSection(sections, len, ins, forceJoin = false) {
|
|
1075
1079
|
if (len == 0 && ins <= 0)
|
|
@@ -1173,7 +1177,7 @@ function mapSet(setA, setB, before, mkSet = false) {
|
|
|
1173
1177
|
a.next();
|
|
1174
1178
|
}
|
|
1175
1179
|
else if (a.done && b.done) {
|
|
1176
|
-
return insert ?
|
|
1180
|
+
return insert ? ChangeSet.createSet(sections, insert) : ChangeDesc.create(sections);
|
|
1177
1181
|
}
|
|
1178
1182
|
else {
|
|
1179
1183
|
throw new Error("Mismatched change set lengths");
|
|
@@ -1186,7 +1190,7 @@ function composeSets(setA, setB, mkSet = false) {
|
|
|
1186
1190
|
let a = new SectionIter(setA), b = new SectionIter(setB);
|
|
1187
1191
|
for (let open = false;;) {
|
|
1188
1192
|
if (a.done && b.done) {
|
|
1189
|
-
return insert ?
|
|
1193
|
+
return insert ? ChangeSet.createSet(sections, insert) : ChangeDesc.create(sections);
|
|
1190
1194
|
}
|
|
1191
1195
|
else if (a.ins == 0) { // Deletion in A
|
|
1192
1196
|
addSection(sections, a.len, 0, open);
|
|
@@ -1281,9 +1285,6 @@ is enabled, a [selection](https://codemirror.net/6/docs/ref/#state.EditorSelecti
|
|
|
1281
1285
|
multiple ranges. By default, selections hold exactly one range.
|
|
1282
1286
|
*/
|
|
1283
1287
|
class SelectionRange {
|
|
1284
|
-
/**
|
|
1285
|
-
@internal
|
|
1286
|
-
*/
|
|
1287
1288
|
constructor(
|
|
1288
1289
|
/**
|
|
1289
1290
|
The lower boundary of the range.
|
|
@@ -1379,14 +1380,17 @@ class SelectionRange {
|
|
|
1379
1380
|
throw new RangeError("Invalid JSON representation for SelectionRange");
|
|
1380
1381
|
return EditorSelection.range(json.anchor, json.head);
|
|
1381
1382
|
}
|
|
1383
|
+
/**
|
|
1384
|
+
@internal
|
|
1385
|
+
*/
|
|
1386
|
+
static create(from, to, flags) {
|
|
1387
|
+
return new SelectionRange(from, to, flags);
|
|
1388
|
+
}
|
|
1382
1389
|
}
|
|
1383
1390
|
/**
|
|
1384
1391
|
An editor selection holds one or more selection ranges.
|
|
1385
1392
|
*/
|
|
1386
1393
|
class EditorSelection {
|
|
1387
|
-
/**
|
|
1388
|
-
@internal
|
|
1389
|
-
*/
|
|
1390
1394
|
constructor(
|
|
1391
1395
|
/**
|
|
1392
1396
|
The ranges in the selection, sorted by position. Ranges cannot
|
|
@@ -1397,7 +1401,7 @@ class EditorSelection {
|
|
|
1397
1401
|
The index of the _main_ range in the selection (which is
|
|
1398
1402
|
usually the range that was added last).
|
|
1399
1403
|
*/
|
|
1400
|
-
mainIndex
|
|
1404
|
+
mainIndex) {
|
|
1401
1405
|
this.ranges = ranges;
|
|
1402
1406
|
this.mainIndex = mainIndex;
|
|
1403
1407
|
}
|
|
@@ -1433,7 +1437,7 @@ class EditorSelection {
|
|
|
1433
1437
|
holding only the main range from this selection.
|
|
1434
1438
|
*/
|
|
1435
1439
|
asSingle() {
|
|
1436
|
-
return this.ranges.length == 1 ? this : new EditorSelection([this.main]);
|
|
1440
|
+
return this.ranges.length == 1 ? this : new EditorSelection([this.main], 0);
|
|
1437
1441
|
}
|
|
1438
1442
|
/**
|
|
1439
1443
|
Extend this selection with an extra range.
|
|
@@ -1481,7 +1485,7 @@ class EditorSelection {
|
|
|
1481
1485
|
for (let pos = 0, i = 0; i < ranges.length; i++) {
|
|
1482
1486
|
let range = ranges[i];
|
|
1483
1487
|
if (range.empty ? range.from <= pos : range.from < pos)
|
|
1484
|
-
return normalized(ranges.slice(), mainIndex);
|
|
1488
|
+
return EditorSelection.normalized(ranges.slice(), mainIndex);
|
|
1485
1489
|
pos = range.to;
|
|
1486
1490
|
}
|
|
1487
1491
|
return new EditorSelection(ranges, mainIndex);
|
|
@@ -1491,7 +1495,7 @@ class EditorSelection {
|
|
|
1491
1495
|
safely ignore the optional arguments in most situations.
|
|
1492
1496
|
*/
|
|
1493
1497
|
static cursor(pos, assoc = 0, bidiLevel, goalColumn) {
|
|
1494
|
-
return
|
|
1498
|
+
return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 4 /* AssocBefore */ : 8 /* AssocAfter */) |
|
|
1495
1499
|
(bidiLevel == null ? 3 : Math.min(2, bidiLevel)) |
|
|
1496
1500
|
((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* NoGoalColumn */) << 5 /* GoalColumnOffset */));
|
|
1497
1501
|
}
|
|
@@ -1500,24 +1504,27 @@ class EditorSelection {
|
|
|
1500
1504
|
*/
|
|
1501
1505
|
static range(anchor, head, goalColumn) {
|
|
1502
1506
|
let goal = (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* NoGoalColumn */) << 5 /* GoalColumnOffset */;
|
|
1503
|
-
return head < anchor ?
|
|
1504
|
-
:
|
|
1507
|
+
return head < anchor ? SelectionRange.create(head, anchor, 16 /* Inverted */ | goal | 8 /* AssocAfter */)
|
|
1508
|
+
: SelectionRange.create(anchor, head, goal | (head > anchor ? 4 /* AssocBefore */ : 0));
|
|
1505
1509
|
}
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
ranges
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
let
|
|
1515
|
-
if (
|
|
1516
|
-
|
|
1517
|
-
|
|
1510
|
+
/**
|
|
1511
|
+
@internal
|
|
1512
|
+
*/
|
|
1513
|
+
static normalized(ranges, mainIndex = 0) {
|
|
1514
|
+
let main = ranges[mainIndex];
|
|
1515
|
+
ranges.sort((a, b) => a.from - b.from);
|
|
1516
|
+
mainIndex = ranges.indexOf(main);
|
|
1517
|
+
for (let i = 1; i < ranges.length; i++) {
|
|
1518
|
+
let range = ranges[i], prev = ranges[i - 1];
|
|
1519
|
+
if (range.empty ? range.from <= prev.to : range.from < prev.to) {
|
|
1520
|
+
let from = prev.from, to = Math.max(range.to, prev.to);
|
|
1521
|
+
if (i <= mainIndex)
|
|
1522
|
+
mainIndex--;
|
|
1523
|
+
ranges.splice(--i, 2, range.anchor > range.head ? EditorSelection.range(to, from) : EditorSelection.range(from, to));
|
|
1524
|
+
}
|
|
1518
1525
|
}
|
|
1526
|
+
return new EditorSelection(ranges, mainIndex);
|
|
1519
1527
|
}
|
|
1520
|
-
return new EditorSelection(ranges, mainIndex);
|
|
1521
1528
|
}
|
|
1522
1529
|
function checkSelection(selection, docLength) {
|
|
1523
1530
|
for (let range of selection.ranges)
|
|
@@ -2183,9 +2190,6 @@ dispatch one by calling
|
|
|
2183
2190
|
[`EditorView.dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch).
|
|
2184
2191
|
*/
|
|
2185
2192
|
class Transaction {
|
|
2186
|
-
/**
|
|
2187
|
-
@internal
|
|
2188
|
-
*/
|
|
2189
2193
|
constructor(
|
|
2190
2194
|
/**
|
|
2191
2195
|
The state from which the transaction starts.
|
|
@@ -2233,6 +2237,12 @@ class Transaction {
|
|
|
2233
2237
|
this.annotations = annotations.concat(Transaction.time.of(Date.now()));
|
|
2234
2238
|
}
|
|
2235
2239
|
/**
|
|
2240
|
+
@internal
|
|
2241
|
+
*/
|
|
2242
|
+
static create(startState, changes, selection, effects, annotations, scrollIntoView) {
|
|
2243
|
+
return new Transaction(startState, changes, selection, effects, annotations, scrollIntoView);
|
|
2244
|
+
}
|
|
2245
|
+
/**
|
|
2236
2246
|
The new document produced by the transaction. Contrary to
|
|
2237
2247
|
[`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't
|
|
2238
2248
|
force the entire new state to be computed right away, so it is
|
|
@@ -2403,7 +2413,7 @@ function resolveTransaction(state, specs, filter) {
|
|
|
2403
2413
|
let seq = !!specs[i].sequential;
|
|
2404
2414
|
s = mergeTransaction(s, resolveTransactionInner(state, specs[i], seq ? s.changes.newLength : state.doc.length), seq);
|
|
2405
2415
|
}
|
|
2406
|
-
let tr =
|
|
2416
|
+
let tr = Transaction.create(state, s.changes, s.selection, s.effects, s.annotations, s.scrollIntoView);
|
|
2407
2417
|
return extendTransaction(filter ? filterTransaction(tr) : tr);
|
|
2408
2418
|
}
|
|
2409
2419
|
// Finish a transaction by applying filters if necessary.
|
|
@@ -2431,7 +2441,7 @@ function filterTransaction(tr) {
|
|
|
2431
2441
|
changes = filtered.changes;
|
|
2432
2442
|
back = filtered.filtered.invertedDesc;
|
|
2433
2443
|
}
|
|
2434
|
-
tr =
|
|
2444
|
+
tr = Transaction.create(state, changes, tr.selection && tr.selection.map(back), StateEffect.mapEffects(tr.effects, back), tr.annotations, tr.scrollIntoView);
|
|
2435
2445
|
}
|
|
2436
2446
|
// Transaction filters
|
|
2437
2447
|
let filters = state.facet(transactionFilter);
|
|
@@ -2453,7 +2463,7 @@ function extendTransaction(tr) {
|
|
|
2453
2463
|
if (extension && Object.keys(extension).length)
|
|
2454
2464
|
spec = mergeTransaction(tr, resolveTransactionInner(state, extension, tr.changes.newLength), true);
|
|
2455
2465
|
}
|
|
2456
|
-
return spec == tr ? tr :
|
|
2466
|
+
return spec == tr ? tr : Transaction.create(state, tr.changes, tr.selection, spec.effects, spec.annotations, spec.scrollIntoView);
|
|
2457
2467
|
}
|
|
2458
2468
|
const none = [];
|
|
2459
2469
|
function asArray(value) {
|
|
@@ -2519,9 +2529,6 @@ As such, _never_ mutate properties of a state directly. That'll
|
|
|
2519
2529
|
just break things.
|
|
2520
2530
|
*/
|
|
2521
2531
|
class EditorState {
|
|
2522
|
-
/**
|
|
2523
|
-
@internal
|
|
2524
|
-
*/
|
|
2525
2532
|
constructor(
|
|
2526
2533
|
/**
|
|
2527
2534
|
@internal
|
|
@@ -2767,11 +2774,25 @@ class EditorState {
|
|
|
2767
2774
|
Look up a translation for the given phrase (via the
|
|
2768
2775
|
[`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
|
|
2769
2776
|
original string if no translation is found.
|
|
2777
|
+
|
|
2778
|
+
If additional arguments are passed, they will be inserted in
|
|
2779
|
+
place of markers like `$1` (for the first value) and `$2`, etc.
|
|
2780
|
+
A single `$` is equivalent to `$1`, and `$$` will produce a
|
|
2781
|
+
literal dollar sign.
|
|
2770
2782
|
*/
|
|
2771
|
-
phrase(phrase) {
|
|
2783
|
+
phrase(phrase, ...insert) {
|
|
2772
2784
|
for (let map of this.facet(EditorState.phrases))
|
|
2773
|
-
if (Object.prototype.hasOwnProperty.call(map, phrase))
|
|
2774
|
-
|
|
2785
|
+
if (Object.prototype.hasOwnProperty.call(map, phrase)) {
|
|
2786
|
+
phrase = map[phrase];
|
|
2787
|
+
break;
|
|
2788
|
+
}
|
|
2789
|
+
if (insert.length)
|
|
2790
|
+
phrase = phrase.replace(/\$(\$|\d*)/g, (m, i) => {
|
|
2791
|
+
if (i == "$")
|
|
2792
|
+
return "$";
|
|
2793
|
+
let n = +(i || 1);
|
|
2794
|
+
return n > insert.length ? m : insert[n - 1];
|
|
2795
|
+
});
|
|
2775
2796
|
return phrase;
|
|
2776
2797
|
}
|
|
2777
2798
|
/**
|
|
@@ -2981,7 +3002,7 @@ class RangeValue {
|
|
|
2981
3002
|
/**
|
|
2982
3003
|
Create a [range](https://codemirror.net/6/docs/ref/#state.Range) with this value.
|
|
2983
3004
|
*/
|
|
2984
|
-
range(from, to = from) { return
|
|
3005
|
+
range(from, to = from) { return Range.create(from, to, this); }
|
|
2985
3006
|
}
|
|
2986
3007
|
RangeValue.prototype.startSide = RangeValue.prototype.endSide = 0;
|
|
2987
3008
|
RangeValue.prototype.point = false;
|
|
@@ -2990,9 +3011,6 @@ RangeValue.prototype.mapMode = exports.MapMode.TrackDel;
|
|
|
2990
3011
|
A range associates a value with a range of positions.
|
|
2991
3012
|
*/
|
|
2992
3013
|
class Range {
|
|
2993
|
-
/**
|
|
2994
|
-
@internal
|
|
2995
|
-
*/
|
|
2996
3014
|
constructor(
|
|
2997
3015
|
/**
|
|
2998
3016
|
The range's start position.
|
|
@@ -3010,6 +3028,12 @@ class Range {
|
|
|
3010
3028
|
this.to = to;
|
|
3011
3029
|
this.value = value;
|
|
3012
3030
|
}
|
|
3031
|
+
/**
|
|
3032
|
+
@internal
|
|
3033
|
+
*/
|
|
3034
|
+
static create(from, to, value) {
|
|
3035
|
+
return new Range(from, to, value);
|
|
3036
|
+
}
|
|
3013
3037
|
}
|
|
3014
3038
|
function cmpRange(a, b) {
|
|
3015
3039
|
return a.from - b.from || a.value.startSide - b.value.startSide;
|
|
@@ -3090,9 +3114,6 @@ way that makes them efficient to [map](https://codemirror.net/6/docs/ref/#state.
|
|
|
3090
3114
|
structure.
|
|
3091
3115
|
*/
|
|
3092
3116
|
class RangeSet {
|
|
3093
|
-
/**
|
|
3094
|
-
@internal
|
|
3095
|
-
*/
|
|
3096
3117
|
constructor(
|
|
3097
3118
|
/**
|
|
3098
3119
|
@internal
|
|
@@ -3105,7 +3126,7 @@ class RangeSet {
|
|
|
3105
3126
|
/**
|
|
3106
3127
|
@internal
|
|
3107
3128
|
*/
|
|
3108
|
-
nextLayer
|
|
3129
|
+
nextLayer,
|
|
3109
3130
|
/**
|
|
3110
3131
|
@internal
|
|
3111
3132
|
*/
|
|
@@ -3118,6 +3139,12 @@ class RangeSet {
|
|
|
3118
3139
|
/**
|
|
3119
3140
|
@internal
|
|
3120
3141
|
*/
|
|
3142
|
+
static create(chunkPos, chunk, nextLayer, maxPoint) {
|
|
3143
|
+
return new RangeSet(chunkPos, chunk, nextLayer, maxPoint);
|
|
3144
|
+
}
|
|
3145
|
+
/**
|
|
3146
|
+
@internal
|
|
3147
|
+
*/
|
|
3121
3148
|
get length() {
|
|
3122
3149
|
let last = this.chunk.length - 1;
|
|
3123
3150
|
return last < 0 ? 0 : Math.max(this.chunkEnd(last), this.nextLayer.length);
|
|
@@ -3174,7 +3201,7 @@ class RangeSet {
|
|
|
3174
3201
|
else {
|
|
3175
3202
|
if (!filter || filterFrom > cur.to || filterTo < cur.from || filter(cur.from, cur.to, cur.value)) {
|
|
3176
3203
|
if (!builder.addInner(cur.from, cur.to, cur.value))
|
|
3177
|
-
spill.push(
|
|
3204
|
+
spill.push(Range.create(cur.from, cur.to, cur.value));
|
|
3178
3205
|
}
|
|
3179
3206
|
cur.next();
|
|
3180
3207
|
}
|
|
@@ -3207,7 +3234,7 @@ class RangeSet {
|
|
|
3207
3234
|
}
|
|
3208
3235
|
}
|
|
3209
3236
|
let next = this.nextLayer.map(changes);
|
|
3210
|
-
return chunks.length == 0 ? next : new RangeSet(chunkPos, chunks, next, maxPoint);
|
|
3237
|
+
return chunks.length == 0 ? next : new RangeSet(chunkPos, chunks, next || RangeSet.empty, maxPoint);
|
|
3211
3238
|
}
|
|
3212
3239
|
/**
|
|
3213
3240
|
Iterate over the ranges that touch the region `from` to `to`,
|
|
@@ -3452,7 +3479,7 @@ class RangeSetBuilder {
|
|
|
3452
3479
|
this.finishChunk(false);
|
|
3453
3480
|
if (this.chunks.length == 0)
|
|
3454
3481
|
return next;
|
|
3455
|
-
let result =
|
|
3482
|
+
let result = RangeSet.create(this.chunkPos, this.chunks, this.nextLayer ? this.nextLayer.finishInner(next) : next, this.setMaxPoint);
|
|
3456
3483
|
this.from = null; // Make sure further `add` calls produce errors
|
|
3457
3484
|
return result;
|
|
3458
3485
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -160,6 +160,11 @@ that doesn't store the inserted text. As such, it can't be
|
|
|
160
160
|
applied, but is cheaper to store and manipulate.
|
|
161
161
|
*/
|
|
162
162
|
declare class ChangeDesc {
|
|
163
|
+
protected constructor(
|
|
164
|
+
/**
|
|
165
|
+
@internal
|
|
166
|
+
*/
|
|
167
|
+
sections: readonly number[]);
|
|
163
168
|
/**
|
|
164
169
|
The length of the document before the change.
|
|
165
170
|
*/
|
|
@@ -263,6 +268,7 @@ stores the document length, and can only be applied to documents
|
|
|
263
268
|
with exactly that length.
|
|
264
269
|
*/
|
|
265
270
|
declare class ChangeSet extends ChangeDesc {
|
|
271
|
+
private constructor();
|
|
266
272
|
/**
|
|
267
273
|
Apply the changes to a document, returning the modified
|
|
268
274
|
document.
|
|
@@ -348,6 +354,7 @@ declare class SelectionRange {
|
|
|
348
354
|
*/
|
|
349
355
|
readonly to: number;
|
|
350
356
|
private flags;
|
|
357
|
+
private constructor();
|
|
351
358
|
/**
|
|
352
359
|
The anchor of the range—the side that doesn't move when you
|
|
353
360
|
extend it.
|
|
@@ -418,6 +425,7 @@ declare class EditorSelection {
|
|
|
418
425
|
usually the range that was added last).
|
|
419
426
|
*/
|
|
420
427
|
readonly mainIndex: number;
|
|
428
|
+
private constructor();
|
|
421
429
|
/**
|
|
422
430
|
Map a selection through a change. Used to adjust the selection
|
|
423
431
|
position for changes.
|
|
@@ -885,6 +893,7 @@ declare class Transaction {
|
|
|
885
893
|
transaction is dispatched.
|
|
886
894
|
*/
|
|
887
895
|
readonly scrollIntoView: boolean;
|
|
896
|
+
private constructor();
|
|
888
897
|
/**
|
|
889
898
|
The new document produced by the transaction. Contrary to
|
|
890
899
|
[`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't
|
|
@@ -1042,6 +1051,7 @@ declare class EditorState {
|
|
|
1042
1051
|
The current selection.
|
|
1043
1052
|
*/
|
|
1044
1053
|
readonly selection: EditorSelection;
|
|
1054
|
+
private constructor();
|
|
1045
1055
|
/**
|
|
1046
1056
|
Retrieve the value of a [state field](https://codemirror.net/6/docs/ref/#state.StateField). Throws
|
|
1047
1057
|
an error when the state doesn't have that field, unless you pass
|
|
@@ -1203,8 +1213,13 @@ declare class EditorState {
|
|
|
1203
1213
|
Look up a translation for the given phrase (via the
|
|
1204
1214
|
[`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
|
|
1205
1215
|
original string if no translation is found.
|
|
1216
|
+
|
|
1217
|
+
If additional arguments are passed, they will be inserted in
|
|
1218
|
+
place of markers like `$1` (for the first value) and `$2`, etc.
|
|
1219
|
+
A single `$` is equivalent to `$1`, and `$$` will produce a
|
|
1220
|
+
literal dollar sign.
|
|
1206
1221
|
*/
|
|
1207
|
-
phrase(phrase: string): string;
|
|
1222
|
+
phrase(phrase: string, ...insert: any[]): string;
|
|
1208
1223
|
/**
|
|
1209
1224
|
A facet used to register [language
|
|
1210
1225
|
data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) providers.
|
|
@@ -1371,6 +1386,7 @@ declare class Range<T extends RangeValue> {
|
|
|
1371
1386
|
The value associated with this range.
|
|
1372
1387
|
*/
|
|
1373
1388
|
readonly value: T;
|
|
1389
|
+
private constructor();
|
|
1374
1390
|
}
|
|
1375
1391
|
/**
|
|
1376
1392
|
Collection of methods used when comparing range sets.
|
|
@@ -1471,6 +1487,7 @@ way that makes them efficient to [map](https://codemirror.net/6/docs/ref/#state.
|
|
|
1471
1487
|
structure.
|
|
1472
1488
|
*/
|
|
1473
1489
|
declare class RangeSet<T extends RangeValue> {
|
|
1490
|
+
private constructor();
|
|
1474
1491
|
/**
|
|
1475
1492
|
The number of ranges in the set.
|
|
1476
1493
|
*/
|
package/dist/index.js
CHANGED
|
@@ -685,9 +685,6 @@ class ChangeDesc {
|
|
|
685
685
|
// unaffected sections, and the length of the replacement content
|
|
686
686
|
// otherwise. So an insertion would be (0, n>0), a deletion (n>0,
|
|
687
687
|
// 0), and a replacement two positive numbers.
|
|
688
|
-
/**
|
|
689
|
-
@internal
|
|
690
|
-
*/
|
|
691
688
|
constructor(
|
|
692
689
|
/**
|
|
693
690
|
@internal
|
|
@@ -842,6 +839,10 @@ class ChangeDesc {
|
|
|
842
839
|
throw new RangeError("Invalid JSON representation of ChangeDesc");
|
|
843
840
|
return new ChangeDesc(json);
|
|
844
841
|
}
|
|
842
|
+
/**
|
|
843
|
+
@internal
|
|
844
|
+
*/
|
|
845
|
+
static create(sections) { return new ChangeDesc(sections); }
|
|
845
846
|
}
|
|
846
847
|
/**
|
|
847
848
|
A change set represents a group of modifications to a document. It
|
|
@@ -849,9 +850,6 @@ stores the document length, and can only be applied to documents
|
|
|
849
850
|
with exactly that length.
|
|
850
851
|
*/
|
|
851
852
|
class ChangeSet extends ChangeDesc {
|
|
852
|
-
/**
|
|
853
|
-
@internal
|
|
854
|
-
*/
|
|
855
853
|
constructor(sections,
|
|
856
854
|
/**
|
|
857
855
|
@internal
|
|
@@ -930,7 +928,7 @@ class ChangeSet extends ChangeDesc {
|
|
|
930
928
|
Get a [change description](https://codemirror.net/6/docs/ref/#state.ChangeDesc) for this change
|
|
931
929
|
set.
|
|
932
930
|
*/
|
|
933
|
-
get desc() { return
|
|
931
|
+
get desc() { return ChangeDesc.create(this.sections); }
|
|
934
932
|
/**
|
|
935
933
|
@internal
|
|
936
934
|
*/
|
|
@@ -963,7 +961,7 @@ class ChangeSet extends ChangeDesc {
|
|
|
963
961
|
}
|
|
964
962
|
}
|
|
965
963
|
return { changes: new ChangeSet(resultSections, resultInserted),
|
|
966
|
-
filtered:
|
|
964
|
+
filtered: ChangeDesc.create(filteredSections) };
|
|
967
965
|
}
|
|
968
966
|
/**
|
|
969
967
|
Serialize this change set to a JSON-representable value.
|
|
@@ -1065,6 +1063,12 @@ class ChangeSet extends ChangeDesc {
|
|
|
1065
1063
|
}
|
|
1066
1064
|
return new ChangeSet(sections, inserted);
|
|
1067
1065
|
}
|
|
1066
|
+
/**
|
|
1067
|
+
@internal
|
|
1068
|
+
*/
|
|
1069
|
+
static createSet(sections, inserted) {
|
|
1070
|
+
return new ChangeSet(sections, inserted);
|
|
1071
|
+
}
|
|
1068
1072
|
}
|
|
1069
1073
|
function addSection(sections, len, ins, forceJoin = false) {
|
|
1070
1074
|
if (len == 0 && ins <= 0)
|
|
@@ -1168,7 +1172,7 @@ function mapSet(setA, setB, before, mkSet = false) {
|
|
|
1168
1172
|
a.next();
|
|
1169
1173
|
}
|
|
1170
1174
|
else if (a.done && b.done) {
|
|
1171
|
-
return insert ?
|
|
1175
|
+
return insert ? ChangeSet.createSet(sections, insert) : ChangeDesc.create(sections);
|
|
1172
1176
|
}
|
|
1173
1177
|
else {
|
|
1174
1178
|
throw new Error("Mismatched change set lengths");
|
|
@@ -1181,7 +1185,7 @@ function composeSets(setA, setB, mkSet = false) {
|
|
|
1181
1185
|
let a = new SectionIter(setA), b = new SectionIter(setB);
|
|
1182
1186
|
for (let open = false;;) {
|
|
1183
1187
|
if (a.done && b.done) {
|
|
1184
|
-
return insert ?
|
|
1188
|
+
return insert ? ChangeSet.createSet(sections, insert) : ChangeDesc.create(sections);
|
|
1185
1189
|
}
|
|
1186
1190
|
else if (a.ins == 0) { // Deletion in A
|
|
1187
1191
|
addSection(sections, a.len, 0, open);
|
|
@@ -1276,9 +1280,6 @@ is enabled, a [selection](https://codemirror.net/6/docs/ref/#state.EditorSelecti
|
|
|
1276
1280
|
multiple ranges. By default, selections hold exactly one range.
|
|
1277
1281
|
*/
|
|
1278
1282
|
class SelectionRange {
|
|
1279
|
-
/**
|
|
1280
|
-
@internal
|
|
1281
|
-
*/
|
|
1282
1283
|
constructor(
|
|
1283
1284
|
/**
|
|
1284
1285
|
The lower boundary of the range.
|
|
@@ -1374,14 +1375,17 @@ class SelectionRange {
|
|
|
1374
1375
|
throw new RangeError("Invalid JSON representation for SelectionRange");
|
|
1375
1376
|
return EditorSelection.range(json.anchor, json.head);
|
|
1376
1377
|
}
|
|
1378
|
+
/**
|
|
1379
|
+
@internal
|
|
1380
|
+
*/
|
|
1381
|
+
static create(from, to, flags) {
|
|
1382
|
+
return new SelectionRange(from, to, flags);
|
|
1383
|
+
}
|
|
1377
1384
|
}
|
|
1378
1385
|
/**
|
|
1379
1386
|
An editor selection holds one or more selection ranges.
|
|
1380
1387
|
*/
|
|
1381
1388
|
class EditorSelection {
|
|
1382
|
-
/**
|
|
1383
|
-
@internal
|
|
1384
|
-
*/
|
|
1385
1389
|
constructor(
|
|
1386
1390
|
/**
|
|
1387
1391
|
The ranges in the selection, sorted by position. Ranges cannot
|
|
@@ -1392,7 +1396,7 @@ class EditorSelection {
|
|
|
1392
1396
|
The index of the _main_ range in the selection (which is
|
|
1393
1397
|
usually the range that was added last).
|
|
1394
1398
|
*/
|
|
1395
|
-
mainIndex
|
|
1399
|
+
mainIndex) {
|
|
1396
1400
|
this.ranges = ranges;
|
|
1397
1401
|
this.mainIndex = mainIndex;
|
|
1398
1402
|
}
|
|
@@ -1428,7 +1432,7 @@ class EditorSelection {
|
|
|
1428
1432
|
holding only the main range from this selection.
|
|
1429
1433
|
*/
|
|
1430
1434
|
asSingle() {
|
|
1431
|
-
return this.ranges.length == 1 ? this : new EditorSelection([this.main]);
|
|
1435
|
+
return this.ranges.length == 1 ? this : new EditorSelection([this.main], 0);
|
|
1432
1436
|
}
|
|
1433
1437
|
/**
|
|
1434
1438
|
Extend this selection with an extra range.
|
|
@@ -1476,7 +1480,7 @@ class EditorSelection {
|
|
|
1476
1480
|
for (let pos = 0, i = 0; i < ranges.length; i++) {
|
|
1477
1481
|
let range = ranges[i];
|
|
1478
1482
|
if (range.empty ? range.from <= pos : range.from < pos)
|
|
1479
|
-
return normalized(ranges.slice(), mainIndex);
|
|
1483
|
+
return EditorSelection.normalized(ranges.slice(), mainIndex);
|
|
1480
1484
|
pos = range.to;
|
|
1481
1485
|
}
|
|
1482
1486
|
return new EditorSelection(ranges, mainIndex);
|
|
@@ -1486,7 +1490,7 @@ class EditorSelection {
|
|
|
1486
1490
|
safely ignore the optional arguments in most situations.
|
|
1487
1491
|
*/
|
|
1488
1492
|
static cursor(pos, assoc = 0, bidiLevel, goalColumn) {
|
|
1489
|
-
return
|
|
1493
|
+
return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 4 /* AssocBefore */ : 8 /* AssocAfter */) |
|
|
1490
1494
|
(bidiLevel == null ? 3 : Math.min(2, bidiLevel)) |
|
|
1491
1495
|
((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* NoGoalColumn */) << 5 /* GoalColumnOffset */));
|
|
1492
1496
|
}
|
|
@@ -1495,24 +1499,27 @@ class EditorSelection {
|
|
|
1495
1499
|
*/
|
|
1496
1500
|
static range(anchor, head, goalColumn) {
|
|
1497
1501
|
let goal = (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* NoGoalColumn */) << 5 /* GoalColumnOffset */;
|
|
1498
|
-
return head < anchor ?
|
|
1499
|
-
:
|
|
1502
|
+
return head < anchor ? SelectionRange.create(head, anchor, 16 /* Inverted */ | goal | 8 /* AssocAfter */)
|
|
1503
|
+
: SelectionRange.create(anchor, head, goal | (head > anchor ? 4 /* AssocBefore */ : 0));
|
|
1500
1504
|
}
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
ranges
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
let
|
|
1510
|
-
if (
|
|
1511
|
-
|
|
1512
|
-
|
|
1505
|
+
/**
|
|
1506
|
+
@internal
|
|
1507
|
+
*/
|
|
1508
|
+
static normalized(ranges, mainIndex = 0) {
|
|
1509
|
+
let main = ranges[mainIndex];
|
|
1510
|
+
ranges.sort((a, b) => a.from - b.from);
|
|
1511
|
+
mainIndex = ranges.indexOf(main);
|
|
1512
|
+
for (let i = 1; i < ranges.length; i++) {
|
|
1513
|
+
let range = ranges[i], prev = ranges[i - 1];
|
|
1514
|
+
if (range.empty ? range.from <= prev.to : range.from < prev.to) {
|
|
1515
|
+
let from = prev.from, to = Math.max(range.to, prev.to);
|
|
1516
|
+
if (i <= mainIndex)
|
|
1517
|
+
mainIndex--;
|
|
1518
|
+
ranges.splice(--i, 2, range.anchor > range.head ? EditorSelection.range(to, from) : EditorSelection.range(from, to));
|
|
1519
|
+
}
|
|
1513
1520
|
}
|
|
1521
|
+
return new EditorSelection(ranges, mainIndex);
|
|
1514
1522
|
}
|
|
1515
|
-
return new EditorSelection(ranges, mainIndex);
|
|
1516
1523
|
}
|
|
1517
1524
|
function checkSelection(selection, docLength) {
|
|
1518
1525
|
for (let range of selection.ranges)
|
|
@@ -2178,9 +2185,6 @@ dispatch one by calling
|
|
|
2178
2185
|
[`EditorView.dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch).
|
|
2179
2186
|
*/
|
|
2180
2187
|
class Transaction {
|
|
2181
|
-
/**
|
|
2182
|
-
@internal
|
|
2183
|
-
*/
|
|
2184
2188
|
constructor(
|
|
2185
2189
|
/**
|
|
2186
2190
|
The state from which the transaction starts.
|
|
@@ -2228,6 +2232,12 @@ class Transaction {
|
|
|
2228
2232
|
this.annotations = annotations.concat(Transaction.time.of(Date.now()));
|
|
2229
2233
|
}
|
|
2230
2234
|
/**
|
|
2235
|
+
@internal
|
|
2236
|
+
*/
|
|
2237
|
+
static create(startState, changes, selection, effects, annotations, scrollIntoView) {
|
|
2238
|
+
return new Transaction(startState, changes, selection, effects, annotations, scrollIntoView);
|
|
2239
|
+
}
|
|
2240
|
+
/**
|
|
2231
2241
|
The new document produced by the transaction. Contrary to
|
|
2232
2242
|
[`.state`](https://codemirror.net/6/docs/ref/#state.Transaction.state)`.doc`, accessing this won't
|
|
2233
2243
|
force the entire new state to be computed right away, so it is
|
|
@@ -2398,7 +2408,7 @@ function resolveTransaction(state, specs, filter) {
|
|
|
2398
2408
|
let seq = !!specs[i].sequential;
|
|
2399
2409
|
s = mergeTransaction(s, resolveTransactionInner(state, specs[i], seq ? s.changes.newLength : state.doc.length), seq);
|
|
2400
2410
|
}
|
|
2401
|
-
let tr =
|
|
2411
|
+
let tr = Transaction.create(state, s.changes, s.selection, s.effects, s.annotations, s.scrollIntoView);
|
|
2402
2412
|
return extendTransaction(filter ? filterTransaction(tr) : tr);
|
|
2403
2413
|
}
|
|
2404
2414
|
// Finish a transaction by applying filters if necessary.
|
|
@@ -2426,7 +2436,7 @@ function filterTransaction(tr) {
|
|
|
2426
2436
|
changes = filtered.changes;
|
|
2427
2437
|
back = filtered.filtered.invertedDesc;
|
|
2428
2438
|
}
|
|
2429
|
-
tr =
|
|
2439
|
+
tr = Transaction.create(state, changes, tr.selection && tr.selection.map(back), StateEffect.mapEffects(tr.effects, back), tr.annotations, tr.scrollIntoView);
|
|
2430
2440
|
}
|
|
2431
2441
|
// Transaction filters
|
|
2432
2442
|
let filters = state.facet(transactionFilter);
|
|
@@ -2448,7 +2458,7 @@ function extendTransaction(tr) {
|
|
|
2448
2458
|
if (extension && Object.keys(extension).length)
|
|
2449
2459
|
spec = mergeTransaction(tr, resolveTransactionInner(state, extension, tr.changes.newLength), true);
|
|
2450
2460
|
}
|
|
2451
|
-
return spec == tr ? tr :
|
|
2461
|
+
return spec == tr ? tr : Transaction.create(state, tr.changes, tr.selection, spec.effects, spec.annotations, spec.scrollIntoView);
|
|
2452
2462
|
}
|
|
2453
2463
|
const none = [];
|
|
2454
2464
|
function asArray(value) {
|
|
@@ -2513,9 +2523,6 @@ As such, _never_ mutate properties of a state directly. That'll
|
|
|
2513
2523
|
just break things.
|
|
2514
2524
|
*/
|
|
2515
2525
|
class EditorState {
|
|
2516
|
-
/**
|
|
2517
|
-
@internal
|
|
2518
|
-
*/
|
|
2519
2526
|
constructor(
|
|
2520
2527
|
/**
|
|
2521
2528
|
@internal
|
|
@@ -2761,11 +2768,25 @@ class EditorState {
|
|
|
2761
2768
|
Look up a translation for the given phrase (via the
|
|
2762
2769
|
[`phrases`](https://codemirror.net/6/docs/ref/#state.EditorState^phrases) facet), or return the
|
|
2763
2770
|
original string if no translation is found.
|
|
2771
|
+
|
|
2772
|
+
If additional arguments are passed, they will be inserted in
|
|
2773
|
+
place of markers like `$1` (for the first value) and `$2`, etc.
|
|
2774
|
+
A single `$` is equivalent to `$1`, and `$$` will produce a
|
|
2775
|
+
literal dollar sign.
|
|
2764
2776
|
*/
|
|
2765
|
-
phrase(phrase) {
|
|
2777
|
+
phrase(phrase, ...insert) {
|
|
2766
2778
|
for (let map of this.facet(EditorState.phrases))
|
|
2767
|
-
if (Object.prototype.hasOwnProperty.call(map, phrase))
|
|
2768
|
-
|
|
2779
|
+
if (Object.prototype.hasOwnProperty.call(map, phrase)) {
|
|
2780
|
+
phrase = map[phrase];
|
|
2781
|
+
break;
|
|
2782
|
+
}
|
|
2783
|
+
if (insert.length)
|
|
2784
|
+
phrase = phrase.replace(/\$(\$|\d*)/g, (m, i) => {
|
|
2785
|
+
if (i == "$")
|
|
2786
|
+
return "$";
|
|
2787
|
+
let n = +(i || 1);
|
|
2788
|
+
return n > insert.length ? m : insert[n - 1];
|
|
2789
|
+
});
|
|
2769
2790
|
return phrase;
|
|
2770
2791
|
}
|
|
2771
2792
|
/**
|
|
@@ -2975,7 +2996,7 @@ class RangeValue {
|
|
|
2975
2996
|
/**
|
|
2976
2997
|
Create a [range](https://codemirror.net/6/docs/ref/#state.Range) with this value.
|
|
2977
2998
|
*/
|
|
2978
|
-
range(from, to = from) { return
|
|
2999
|
+
range(from, to = from) { return Range.create(from, to, this); }
|
|
2979
3000
|
}
|
|
2980
3001
|
RangeValue.prototype.startSide = RangeValue.prototype.endSide = 0;
|
|
2981
3002
|
RangeValue.prototype.point = false;
|
|
@@ -2984,9 +3005,6 @@ RangeValue.prototype.mapMode = MapMode.TrackDel;
|
|
|
2984
3005
|
A range associates a value with a range of positions.
|
|
2985
3006
|
*/
|
|
2986
3007
|
class Range {
|
|
2987
|
-
/**
|
|
2988
|
-
@internal
|
|
2989
|
-
*/
|
|
2990
3008
|
constructor(
|
|
2991
3009
|
/**
|
|
2992
3010
|
The range's start position.
|
|
@@ -3004,6 +3022,12 @@ class Range {
|
|
|
3004
3022
|
this.to = to;
|
|
3005
3023
|
this.value = value;
|
|
3006
3024
|
}
|
|
3025
|
+
/**
|
|
3026
|
+
@internal
|
|
3027
|
+
*/
|
|
3028
|
+
static create(from, to, value) {
|
|
3029
|
+
return new Range(from, to, value);
|
|
3030
|
+
}
|
|
3007
3031
|
}
|
|
3008
3032
|
function cmpRange(a, b) {
|
|
3009
3033
|
return a.from - b.from || a.value.startSide - b.value.startSide;
|
|
@@ -3084,9 +3108,6 @@ way that makes them efficient to [map](https://codemirror.net/6/docs/ref/#state.
|
|
|
3084
3108
|
structure.
|
|
3085
3109
|
*/
|
|
3086
3110
|
class RangeSet {
|
|
3087
|
-
/**
|
|
3088
|
-
@internal
|
|
3089
|
-
*/
|
|
3090
3111
|
constructor(
|
|
3091
3112
|
/**
|
|
3092
3113
|
@internal
|
|
@@ -3099,7 +3120,7 @@ class RangeSet {
|
|
|
3099
3120
|
/**
|
|
3100
3121
|
@internal
|
|
3101
3122
|
*/
|
|
3102
|
-
nextLayer
|
|
3123
|
+
nextLayer,
|
|
3103
3124
|
/**
|
|
3104
3125
|
@internal
|
|
3105
3126
|
*/
|
|
@@ -3112,6 +3133,12 @@ class RangeSet {
|
|
|
3112
3133
|
/**
|
|
3113
3134
|
@internal
|
|
3114
3135
|
*/
|
|
3136
|
+
static create(chunkPos, chunk, nextLayer, maxPoint) {
|
|
3137
|
+
return new RangeSet(chunkPos, chunk, nextLayer, maxPoint);
|
|
3138
|
+
}
|
|
3139
|
+
/**
|
|
3140
|
+
@internal
|
|
3141
|
+
*/
|
|
3115
3142
|
get length() {
|
|
3116
3143
|
let last = this.chunk.length - 1;
|
|
3117
3144
|
return last < 0 ? 0 : Math.max(this.chunkEnd(last), this.nextLayer.length);
|
|
@@ -3168,7 +3195,7 @@ class RangeSet {
|
|
|
3168
3195
|
else {
|
|
3169
3196
|
if (!filter || filterFrom > cur.to || filterTo < cur.from || filter(cur.from, cur.to, cur.value)) {
|
|
3170
3197
|
if (!builder.addInner(cur.from, cur.to, cur.value))
|
|
3171
|
-
spill.push(
|
|
3198
|
+
spill.push(Range.create(cur.from, cur.to, cur.value));
|
|
3172
3199
|
}
|
|
3173
3200
|
cur.next();
|
|
3174
3201
|
}
|
|
@@ -3201,7 +3228,7 @@ class RangeSet {
|
|
|
3201
3228
|
}
|
|
3202
3229
|
}
|
|
3203
3230
|
let next = this.nextLayer.map(changes);
|
|
3204
|
-
return chunks.length == 0 ? next : new RangeSet(chunkPos, chunks, next, maxPoint);
|
|
3231
|
+
return chunks.length == 0 ? next : new RangeSet(chunkPos, chunks, next || RangeSet.empty, maxPoint);
|
|
3205
3232
|
}
|
|
3206
3233
|
/**
|
|
3207
3234
|
Iterate over the ranges that touch the region `from` to `to`,
|
|
@@ -3446,7 +3473,7 @@ class RangeSetBuilder {
|
|
|
3446
3473
|
this.finishChunk(false);
|
|
3447
3474
|
if (this.chunks.length == 0)
|
|
3448
3475
|
return next;
|
|
3449
|
-
let result =
|
|
3476
|
+
let result = RangeSet.create(this.chunkPos, this.chunks, this.nextLayer ? this.nextLayer.finishInner(next) : next, this.setMaxPoint);
|
|
3450
3477
|
this.from = null; // Make sure further `add` calls produce errors
|
|
3451
3478
|
return result;
|
|
3452
3479
|
}
|