@nerd-bible/wordgard 0.5.3-beta6 → 0.6.2-beta1
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/dist/command.js +11 -10
- package/dist/doc.d.ts +45 -48
- package/dist/doc.js +131 -128
- package/dist/editor.d.ts +190 -104
- package/dist/editor.js +2001 -1616
- package/dist/highlight-code.d.ts +249 -0
- package/dist/highlight-code.js +264 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/phrases.d.ts +3 -2
- package/dist/phrases.js +20 -1
- package/dist/schema.d.ts +37 -1
- package/dist/schema.js +154 -127
- package/dist/set.js +5 -4
- package/dist/state.d.ts +68 -22
- package/dist/state.js +137 -107
- package/dist/table.d.ts +3 -2
- package/dist/table.js +32 -14
- package/package.json +3 -2
package/dist/doc.js
CHANGED
|
@@ -42,40 +42,63 @@ const Token = /*@__PURE__*/(function (Token) {
|
|
|
42
42
|
})(Token.Type || (Token.Type = {}));
|
|
43
43
|
Token.End = {
|
|
44
44
|
tokenType: Token.Type.Close,
|
|
45
|
-
toString() { return "[end]"; }
|
|
45
|
+
toString() { return "[end]"; },
|
|
46
|
+
toJSON() { return "."; }
|
|
46
47
|
};
|
|
48
|
+
function fromJSON(schema, value) {
|
|
49
|
+
if (value === ".")
|
|
50
|
+
return Token.End;
|
|
51
|
+
if (!value || typeof value.type != "string")
|
|
52
|
+
throw new ValidationError("Invalid slice JSON");
|
|
53
|
+
let type = schema.getNode(value.type);
|
|
54
|
+
return type?.isLeaf || ("content" in value) ? schema.nodeFromJSON(value) : schema.tagFromJSON(value);
|
|
55
|
+
}
|
|
56
|
+
Token.fromJSON = fromJSON;
|
|
47
57
|
;return Token})({});
|
|
48
58
|
class Slice {
|
|
49
59
|
content;
|
|
60
|
+
context;
|
|
50
61
|
length;
|
|
51
|
-
constructor(
|
|
62
|
+
constructor(
|
|
63
|
+
content,
|
|
64
|
+
context) {
|
|
52
65
|
this.content = content;
|
|
66
|
+
this.context = context;
|
|
53
67
|
this.length = content.reduce((l, e) => l + (e.tokenType == Token.Type.Node ? e.length : 1), 0);
|
|
54
68
|
}
|
|
55
|
-
static of(content) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
|
|
69
|
+
static of(content, context) {
|
|
70
|
+
return content.length || context && context.length ? new Slice(content, context || Slice.empty.context) : Slice.empty;
|
|
71
|
+
}
|
|
72
|
+
concat(other) {
|
|
73
|
+
return new Slice(Slice.concat(this.content, other.content), this.context);
|
|
74
|
+
}
|
|
75
|
+
textContent(options = {}) {
|
|
76
|
+
let { blockSeparator = "\n", leafText } = options;
|
|
77
|
+
let out = new TextOutput(blockSeparator, leafText == null ? undefined : typeof leafText == "string" ? () => leafText : leafText);
|
|
78
|
+
for (let tok of this.content) {
|
|
79
|
+
if (tok.tokenType == Token.Type.Open) {
|
|
80
|
+
if (tok.isTextblock)
|
|
81
|
+
out.openBlock();
|
|
68
82
|
}
|
|
69
|
-
else if (
|
|
70
|
-
if (
|
|
71
|
-
|
|
83
|
+
else if (tok.tokenType == Token.Type.Node) {
|
|
84
|
+
if (tok.isLeaf)
|
|
85
|
+
out.serialize(tok);
|
|
86
|
+
else
|
|
87
|
+
tok.iterate(node => !out.serialize(node));
|
|
72
88
|
}
|
|
73
89
|
}
|
|
74
|
-
return
|
|
90
|
+
return out.text;
|
|
75
91
|
}
|
|
76
|
-
|
|
92
|
+
static empty = /*@__PURE__*/(() => new Slice([], []))();
|
|
93
|
+
toString() {
|
|
94
|
+
return `<${this.content.join()}>`;
|
|
95
|
+
}
|
|
96
|
+
static get(doc, from, to) {
|
|
97
|
+
return new Slice(doc.slice(from, to), doc.contextAt(from));
|
|
98
|
+
}
|
|
99
|
+
static run(tokens, track, startPos = 0) {
|
|
77
100
|
let pos = startPos;
|
|
78
|
-
for (let elt of
|
|
101
|
+
for (let elt of tokens) {
|
|
79
102
|
if (elt.tokenType == Token.Type.Open)
|
|
80
103
|
track.open(elt, pos++);
|
|
81
104
|
else if (elt.tokenType == Token.Type.Node) {
|
|
@@ -86,18 +109,30 @@ class Slice {
|
|
|
86
109
|
track.close(pos++);
|
|
87
110
|
}
|
|
88
111
|
}
|
|
89
|
-
|
|
112
|
+
static concat(a, b) {
|
|
113
|
+
let tokens = a.slice();
|
|
114
|
+
let i = 0;
|
|
115
|
+
if (a.length && b.length && b[0].tokenType == Token.Type.Node &&
|
|
116
|
+
a[a.length - 1].tokenType == Token.Type.Node) {
|
|
117
|
+
b[0].pushTo(tokens);
|
|
118
|
+
i = 1;
|
|
119
|
+
}
|
|
120
|
+
for (; i < b.length; i++)
|
|
121
|
+
tokens.push(b[i]);
|
|
122
|
+
return tokens;
|
|
123
|
+
}
|
|
124
|
+
static slice(tokens, from, to = 1e9) {
|
|
90
125
|
if (from == to)
|
|
91
|
-
return Slice.empty;
|
|
126
|
+
return Slice.empty.content;
|
|
92
127
|
let result = [], off = 0;
|
|
93
|
-
for (let elt of
|
|
128
|
+
for (let elt of tokens) {
|
|
94
129
|
let start = off;
|
|
95
130
|
off += elt.tokenType == Token.Type.Node ? elt.length : 1;
|
|
96
131
|
if (off <= from)
|
|
97
132
|
continue;
|
|
98
133
|
if (start < from || off > to) {
|
|
99
134
|
let inner = elt.sliceInner(Math.max(0, from - start), Math.min(elt.length, to - start));
|
|
100
|
-
for (let elt of inner
|
|
135
|
+
for (let elt of inner)
|
|
101
136
|
result.push(elt);
|
|
102
137
|
}
|
|
103
138
|
else {
|
|
@@ -106,55 +141,17 @@ class Slice {
|
|
|
106
141
|
if (off >= to)
|
|
107
142
|
break;
|
|
108
143
|
}
|
|
109
|
-
return
|
|
110
|
-
}
|
|
111
|
-
concat(other) {
|
|
112
|
-
let content = this.content.slice();
|
|
113
|
-
let i = 0;
|
|
114
|
-
if (content.length && other.content.length && other.content[0].tokenType == Token.Type.Node &&
|
|
115
|
-
content[content.length - 1].tokenType == Token.Type.Node) {
|
|
116
|
-
other.content[0].pushTo(content);
|
|
117
|
-
i = 1;
|
|
118
|
-
}
|
|
119
|
-
for (; i < other.content.length; i++)
|
|
120
|
-
content.push(other.content[i]);
|
|
121
|
-
return new Slice(content);
|
|
144
|
+
return result;
|
|
122
145
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
for (let
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
else if (tok.tokenType == Token.Type.Node) {
|
|
132
|
-
if (tok.isLeaf)
|
|
133
|
-
out.serialize(tok);
|
|
134
|
-
else
|
|
135
|
-
tok.iterate(node => !out.serialize(node));
|
|
136
|
-
}
|
|
146
|
+
static eq(a, b) {
|
|
147
|
+
if (a.length != b.length)
|
|
148
|
+
return false;
|
|
149
|
+
for (let i = 0; i < a.length; i++) {
|
|
150
|
+
let tA = a[i], tB = b[i];
|
|
151
|
+
if (tA.tokenType != tB.tokenType || (tA.tokenType != Token.Type.Close && !tA.eq(tB)))
|
|
152
|
+
return false;
|
|
137
153
|
}
|
|
138
|
-
return
|
|
139
|
-
}
|
|
140
|
-
static empty = /*@__PURE__*/(() => new Slice([]))();
|
|
141
|
-
toString() {
|
|
142
|
-
return `<${this.content.join()}>`;
|
|
143
|
-
}
|
|
144
|
-
toJSON() {
|
|
145
|
-
return this.content.map(e => e.tokenType == Token.Type.Close ? "." : e.toJSON());
|
|
146
|
-
}
|
|
147
|
-
static fromJSON(schema, json) {
|
|
148
|
-
if (!Array.isArray(json))
|
|
149
|
-
throw new ValidationError("Invalid slice JSON");
|
|
150
|
-
return new Slice(json.map(value => {
|
|
151
|
-
if (value === ".")
|
|
152
|
-
return Token.End;
|
|
153
|
-
if (!value || typeof value.type != "string")
|
|
154
|
-
throw new ValidationError("Invalid slice JSON");
|
|
155
|
-
let type = schema.getNode(value.type);
|
|
156
|
-
return type?.isLeaf || ("content" in value) ? schema.nodeFromJSON(value) : schema.tagFromJSON(value);
|
|
157
|
-
}));
|
|
154
|
+
return true;
|
|
158
155
|
}
|
|
159
156
|
}
|
|
160
157
|
|
|
@@ -1198,7 +1195,7 @@ class Leaf extends BaseTag {
|
|
|
1198
1195
|
nodes.push(this);
|
|
1199
1196
|
}
|
|
1200
1197
|
sliceInner(from, to) {
|
|
1201
|
-
return from == to ? Slice.empty :
|
|
1198
|
+
return from == to ? Slice.empty.content : [this.is(Leaf.Text) ? this.sliceText(from, to) : this];
|
|
1202
1199
|
}
|
|
1203
1200
|
sliceText(from, to) {
|
|
1204
1201
|
if (!this.is(Leaf.Text))
|
|
@@ -1270,10 +1267,10 @@ class Plot {
|
|
|
1270
1267
|
}
|
|
1271
1268
|
sliceInner(from, to) {
|
|
1272
1269
|
if (from == to)
|
|
1273
|
-
return Slice.empty;
|
|
1270
|
+
return Slice.empty.content;
|
|
1274
1271
|
let content = [];
|
|
1275
1272
|
this.slicePlot(content, from, to);
|
|
1276
|
-
return
|
|
1273
|
+
return content;
|
|
1277
1274
|
}
|
|
1278
1275
|
slicePlot(out, from, to) {
|
|
1279
1276
|
if (from <= 0) {
|
|
@@ -1953,6 +1950,7 @@ class BuildContext {
|
|
|
1953
1950
|
this.parent = parent;
|
|
1954
1951
|
}
|
|
1955
1952
|
}
|
|
1953
|
+
const noTokens = /*@__PURE__*/(() => Slice.empty.content)();
|
|
1956
1954
|
class Builder {
|
|
1957
1955
|
stack;
|
|
1958
1956
|
modifications = null;
|
|
@@ -2081,7 +2079,7 @@ class ChangeSet {
|
|
|
2081
2079
|
return false;
|
|
2082
2080
|
for (let i = 0; i < this.data.length; i++) {
|
|
2083
2081
|
let a = this.data[i], b = other.data[i];
|
|
2084
|
-
if (a && !(this.sections[(i << 1) + 1] < 0 ? compareModifications(a, b) :
|
|
2082
|
+
if (a && !(this.sections[(i << 1) + 1] < 0 ? compareModifications(a, b) : Slice.eq(a, b)))
|
|
2085
2083
|
return false;
|
|
2086
2084
|
}
|
|
2087
2085
|
return true;
|
|
@@ -2105,7 +2103,7 @@ class ChangeSet {
|
|
|
2105
2103
|
}
|
|
2106
2104
|
else {
|
|
2107
2105
|
cursor = cursor.advance(lenA);
|
|
2108
|
-
this.data[i]
|
|
2106
|
+
Slice.run(this.data[i], builder);
|
|
2109
2107
|
}
|
|
2110
2108
|
}
|
|
2111
2109
|
if (cursor.pos != doc.length)
|
|
@@ -2123,7 +2121,7 @@ class ChangeSet {
|
|
|
2123
2121
|
else if (ins == -2)
|
|
2124
2122
|
result.push([len, this.data[i].map(modificationToJSON)]);
|
|
2125
2123
|
else
|
|
2126
|
-
result.push([len, this.data[i].toJSON()]);
|
|
2124
|
+
result.push([len, this.data[i].map(t => t.toJSON())]);
|
|
2127
2125
|
}
|
|
2128
2126
|
return result;
|
|
2129
2127
|
}
|
|
@@ -2145,9 +2143,11 @@ class ChangeSet {
|
|
|
2145
2143
|
data.push(val.map(m => modificationFromJSON(schema, m)));
|
|
2146
2144
|
}
|
|
2147
2145
|
else {
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2146
|
+
if (!Array.isArray(val))
|
|
2147
|
+
throw new ValidationError("Invalid ChangeSet JSON");
|
|
2148
|
+
let tokens = val.map(v => Token.fromJSON(schema, v));
|
|
2149
|
+
sections.push(len, sliceLen(tokens));
|
|
2150
|
+
data.push(tokens);
|
|
2151
2151
|
}
|
|
2152
2152
|
}
|
|
2153
2153
|
}
|
|
@@ -2232,7 +2232,7 @@ class ChangeSet {
|
|
|
2232
2232
|
this.iterChanges((_f, _t, pos, _to, inserted) => {
|
|
2233
2233
|
if (found != null)
|
|
2234
2234
|
return;
|
|
2235
|
-
for (let tok of inserted
|
|
2235
|
+
for (let tok of inserted) {
|
|
2236
2236
|
if (tok.tokenType == Token.Type.Node) {
|
|
2237
2237
|
if (pred(tok.tag))
|
|
2238
2238
|
return found = pos;
|
|
@@ -2398,6 +2398,9 @@ class ChangeSetBuilder {
|
|
|
2398
2398
|
data = [];
|
|
2399
2399
|
pos = 0;
|
|
2400
2400
|
}
|
|
2401
|
+
function sliceLen(tokens) {
|
|
2402
|
+
return tokens.reduce((l, e) => l + (e.tokenType == Token.Type.Node ? e.length : 1), 0);
|
|
2403
|
+
}
|
|
2401
2404
|
function createChangeSet(doc, spec, mayCorrect = true) {
|
|
2402
2405
|
let cur = null;
|
|
2403
2406
|
let accum = null;
|
|
@@ -2489,16 +2492,17 @@ function createChangeSet(doc, spec, mayCorrect = true) {
|
|
|
2489
2492
|
else {
|
|
2490
2493
|
if (to == null)
|
|
2491
2494
|
to = from;
|
|
2492
|
-
|
|
2495
|
+
let context = insert instanceof Slice ? insert.context : Slice.empty.context;
|
|
2496
|
+
insert = !insert ? noTokens : insert instanceof Slice ? insert.content : insert;
|
|
2493
2497
|
if (to <= from)
|
|
2494
2498
|
to = from;
|
|
2495
2499
|
if (fit) {
|
|
2496
2500
|
doCorrect = true;
|
|
2497
|
-
({ from, to,
|
|
2498
|
-
fitReplacement(doc, doc.resolve(from), doc.resolve(to), insert,
|
|
2501
|
+
({ from, to, tokens: insert } =
|
|
2502
|
+
fitReplacement(doc, doc.resolve(from), doc.resolve(to), insert, context));
|
|
2499
2503
|
}
|
|
2500
2504
|
if (insert.length || to != from)
|
|
2501
|
-
section(from, to, insert
|
|
2505
|
+
section(from, to, sliceLen(insert), insert);
|
|
2502
2506
|
}
|
|
2503
2507
|
}
|
|
2504
2508
|
};
|
|
@@ -2527,15 +2531,15 @@ function transform(setA, setB, doc, before, fit) {
|
|
|
2527
2531
|
let end = pos + b.len;
|
|
2528
2532
|
addSection(sections, data, b.ins, -1, null);
|
|
2529
2533
|
if (fitter)
|
|
2530
|
-
fitter.replaced(b.
|
|
2534
|
+
fitter.replaced(b.tokens, pos, end, true);
|
|
2531
2535
|
while (pos < end) {
|
|
2532
2536
|
if (a.done)
|
|
2533
2537
|
throw new ValidationError("Mismatched change sets");
|
|
2534
2538
|
let piece = Math.min(a.len, end - pos);
|
|
2535
2539
|
if (a.ins >= 0 && inserted < a.i && a.len <= piece) {
|
|
2536
|
-
addSection(sections, data, 0, a.ins, a.
|
|
2540
|
+
addSection(sections, data, 0, a.ins, a.tokens);
|
|
2537
2541
|
if (fitter)
|
|
2538
|
-
fitter.replaced(a.
|
|
2542
|
+
fitter.replaced(a.tokens, pos - a.off, pos + a.len);
|
|
2539
2543
|
inserted = a.i;
|
|
2540
2544
|
}
|
|
2541
2545
|
a.forward(piece);
|
|
@@ -2554,7 +2558,7 @@ function transform(setA, setB, doc, before, fit) {
|
|
|
2554
2558
|
}
|
|
2555
2559
|
else if (b.ins == 0 && pos + b.len < end) {
|
|
2556
2560
|
if (fitter)
|
|
2557
|
-
fitter.replaced(b.
|
|
2561
|
+
fitter.replaced(b.tokens, pos, pos + b.len, true);
|
|
2558
2562
|
pos += b.len;
|
|
2559
2563
|
b.next();
|
|
2560
2564
|
}
|
|
@@ -2563,13 +2567,13 @@ function transform(setA, setB, doc, before, fit) {
|
|
|
2563
2567
|
}
|
|
2564
2568
|
}
|
|
2565
2569
|
if (inserted < a.i) {
|
|
2566
|
-
addSection(sections, data, len, a.ins, a.
|
|
2570
|
+
addSection(sections, data, len, a.ins, a.tokens);
|
|
2567
2571
|
if (fitter)
|
|
2568
|
-
fitter.replaced(a.
|
|
2572
|
+
fitter.replaced(a.tokens, start - a.off, start + a.len);
|
|
2569
2573
|
inserted = a.i;
|
|
2570
2574
|
}
|
|
2571
2575
|
else {
|
|
2572
|
-
addSection(sections, data, len, 0,
|
|
2576
|
+
addSection(sections, data, len, 0, noTokens);
|
|
2573
2577
|
}
|
|
2574
2578
|
a.forward(pos - start);
|
|
2575
2579
|
}
|
|
@@ -2588,10 +2592,10 @@ function compose(sectionsA, sectionsB, dataA, dataB) {
|
|
|
2588
2592
|
if (a.done && b.done) {
|
|
2589
2593
|
return { sections, data };
|
|
2590
2594
|
}
|
|
2591
|
-
else if (a.ins == 0) { addSection(sections, data, a.len, 0, a.
|
|
2595
|
+
else if (a.ins == 0) { addSection(sections, data, a.len, 0, a.tokens, open);
|
|
2592
2596
|
a.next();
|
|
2593
2597
|
}
|
|
2594
|
-
else if (b.len == 0 && !b.done) { addSection(sections, data, 0, b.ins, b.
|
|
2598
|
+
else if (b.len == 0 && !b.done) { addSection(sections, data, 0, b.ins, b.tokens, open);
|
|
2595
2599
|
b.next();
|
|
2596
2600
|
}
|
|
2597
2601
|
else if (a.done || b.done) {
|
|
@@ -2604,13 +2608,13 @@ function compose(sectionsA, sectionsB, dataA, dataB) {
|
|
|
2604
2608
|
addSection(sections, data, len, (data ? mods : a.ins == -2 || b.ins == -2) ? -2 : -1, mods, open);
|
|
2605
2609
|
}
|
|
2606
2610
|
else if (a.keep) {
|
|
2607
|
-
addSection(sections, data, len, b.off ? 0 : b.ins, b.off ?
|
|
2611
|
+
addSection(sections, data, len, b.off ? 0 : b.ins, b.off ? noTokens : b.tokens, open);
|
|
2608
2612
|
}
|
|
2609
2613
|
else if (b.keep) {
|
|
2610
2614
|
addSection(sections, data, a.off ? 0 : a.len, len, data ? applyModsToSlice(a.slicePart(len), b.mods) : null, open);
|
|
2611
2615
|
}
|
|
2612
2616
|
else {
|
|
2613
|
-
addSection(sections, data, a.off ? 0 : a.len, b.off ? 0 : b.ins, b.off ?
|
|
2617
|
+
addSection(sections, data, a.off ? 0 : a.len, b.off ? 0 : b.ins, b.off ? noTokens : b.tokens, open);
|
|
2614
2618
|
}
|
|
2615
2619
|
open = (a.ins > len || b.ins >= 0 && b.len > len) && (open || sections.length > sectionLen);
|
|
2616
2620
|
a.forward2(len);
|
|
@@ -2646,11 +2650,11 @@ function invertMods(mods, target) {
|
|
|
2646
2650
|
return { remove: mod.add };
|
|
2647
2651
|
});
|
|
2648
2652
|
}
|
|
2649
|
-
function applyModsToSlice(
|
|
2653
|
+
function applyModsToSlice(tokens, mods) {
|
|
2650
2654
|
if (!mods)
|
|
2651
|
-
return
|
|
2655
|
+
return tokens;
|
|
2652
2656
|
let content = [];
|
|
2653
|
-
for (let tok of
|
|
2657
|
+
for (let tok of tokens) {
|
|
2654
2658
|
if (tok.tokenType == Token.Type.Open) {
|
|
2655
2659
|
content.push(tok.withMarks(applyModifications(mods, tok.marks, tok.type)));
|
|
2656
2660
|
}
|
|
@@ -2665,7 +2669,7 @@ function applyModsToSlice(slice, mods) {
|
|
|
2665
2669
|
content.push(tok);
|
|
2666
2670
|
}
|
|
2667
2671
|
}
|
|
2668
|
-
return
|
|
2672
|
+
return content;
|
|
2669
2673
|
}
|
|
2670
2674
|
class FitLevel {
|
|
2671
2675
|
tag;
|
|
@@ -2740,13 +2744,13 @@ class ChangeFitter {
|
|
|
2740
2744
|
lastCoverFrom = -1;
|
|
2741
2745
|
lastCoverTo = -1;
|
|
2742
2746
|
doubleDeleteDelta = 0;
|
|
2743
|
-
replaced(
|
|
2747
|
+
replaced(tokens, from, to, covering = false) {
|
|
2744
2748
|
this.doubleDeleteDelta = 0;
|
|
2745
2749
|
if (covering) {
|
|
2746
2750
|
this.lastCoverFrom = from;
|
|
2747
2751
|
this.lastCoverTo = to;
|
|
2748
2752
|
}
|
|
2749
|
-
else if (
|
|
2753
|
+
else if (tokens.length) {
|
|
2750
2754
|
let overlapFrom = Math.max(from, this.lastCoverFrom);
|
|
2751
2755
|
let overlapTo = Math.min(to, this.lastCoverTo);
|
|
2752
2756
|
if (overlapFrom < overlapTo) {
|
|
@@ -2759,7 +2763,7 @@ class ChangeFitter {
|
|
|
2759
2763
|
this.inputDelta -= counter.count;
|
|
2760
2764
|
}
|
|
2761
2765
|
this.inserting = true;
|
|
2762
|
-
|
|
2766
|
+
Slice.run(tokens, this, this.pos);
|
|
2763
2767
|
this.inserting = false;
|
|
2764
2768
|
if (this.local)
|
|
2765
2769
|
this.nextSync = Math.max(this.nextSync, localSyncPosAfter(this.inputPos = this.getPos(to)));
|
|
@@ -2922,8 +2926,7 @@ class ChangeFitter {
|
|
|
2922
2926
|
let sections = [], data = [], pos = 0;
|
|
2923
2927
|
for (let { from, to, insert } of this.patches) {
|
|
2924
2928
|
addSection(sections, data, from - pos, -1, null);
|
|
2925
|
-
|
|
2926
|
-
addSection(sections, data, to - from, slice.length, slice);
|
|
2929
|
+
addSection(sections, data, to - from, sliceLen(insert), insert);
|
|
2927
2930
|
pos = to;
|
|
2928
2931
|
}
|
|
2929
2932
|
addSection(sections, data, this.pos - pos, -1, null);
|
|
@@ -2979,11 +2982,11 @@ class SectionIter {
|
|
|
2979
2982
|
get mods() {
|
|
2980
2983
|
return this.data ? this.data[(this.i - 2) >> 1] : null;
|
|
2981
2984
|
}
|
|
2982
|
-
get
|
|
2983
|
-
return this.data ? this.data[(this.i - 2) >> 1] :
|
|
2985
|
+
get tokens() {
|
|
2986
|
+
return this.data ? this.data[(this.i - 2) >> 1] : noTokens;
|
|
2984
2987
|
}
|
|
2985
2988
|
slicePart(len) {
|
|
2986
|
-
return
|
|
2989
|
+
return Slice.slice(this.tokens, this.off, len == null ? undefined : this.off + len);
|
|
2987
2990
|
}
|
|
2988
2991
|
forward(len) {
|
|
2989
2992
|
if (len == this.len)
|
|
@@ -3022,7 +3025,7 @@ function addSection(sections, data, len, ins, value, forceJoin = false) {
|
|
|
3022
3025
|
sections[last] += len;
|
|
3023
3026
|
sections[last + 1] += ins;
|
|
3024
3027
|
if (data)
|
|
3025
|
-
data[data.length - 1] = data[data.length - 1]
|
|
3028
|
+
data[data.length - 1] = Slice.concat(data[data.length - 1], value);
|
|
3026
3029
|
}
|
|
3027
3030
|
else {
|
|
3028
3031
|
sections.push(len, ins);
|
|
@@ -3034,11 +3037,11 @@ function finishCx(cx, schema) {
|
|
|
3034
3037
|
return cx.tag.create(cx.children.length || cx.tag.type.canBeEmpty ? cx.children
|
|
3035
3038
|
: [schema.createDefault(cx.tag.type)]);
|
|
3036
3039
|
}
|
|
3037
|
-
function closeSlice(schema,
|
|
3040
|
+
function closeSlice(schema, tokens, context, depth, closeEnd = false) {
|
|
3038
3041
|
let top = [], stack = null;
|
|
3039
3042
|
for (let i = depth - 1; i >= 0; i--)
|
|
3040
3043
|
stack = new BuildContext(context[i], stack);
|
|
3041
|
-
for (let token of
|
|
3044
|
+
for (let token of tokens) {
|
|
3042
3045
|
if (token.tokenType == Token.Type.Close) {
|
|
3043
3046
|
if (stack) {
|
|
3044
3047
|
let node = finishCx(stack, schema);
|
|
@@ -3064,7 +3067,7 @@ function closeSlice(schema, slice, context, depth, closeEnd = false) {
|
|
|
3064
3067
|
}
|
|
3065
3068
|
if (stack)
|
|
3066
3069
|
splatContext(top, stack);
|
|
3067
|
-
return
|
|
3070
|
+
return top;
|
|
3068
3071
|
}
|
|
3069
3072
|
function splatContext(top, cx) {
|
|
3070
3073
|
if (cx.parent)
|
|
@@ -3076,8 +3079,8 @@ function splatContext(top, cx) {
|
|
|
3076
3079
|
function isFitBarrier(plot) {
|
|
3077
3080
|
return plot.isolating || plot.isInline;
|
|
3078
3081
|
}
|
|
3079
|
-
function fitReplacement(doc, from, to,
|
|
3080
|
-
if (!
|
|
3082
|
+
function fitReplacement(doc, from, to, tokens, context) {
|
|
3083
|
+
if (!tokens.length)
|
|
3081
3084
|
return fitDeletion(doc, from, to);
|
|
3082
3085
|
let preferredContext = -1;
|
|
3083
3086
|
for (let i = 0; i < context.length; i++) {
|
|
@@ -3088,8 +3091,8 @@ function fitReplacement(doc, from, to, slice, context) {
|
|
|
3088
3091
|
break;
|
|
3089
3092
|
}
|
|
3090
3093
|
let firstType = null, closeCount = 0;
|
|
3091
|
-
for (let i = 0, opened = 0; i <
|
|
3092
|
-
let tok =
|
|
3094
|
+
for (let i = 0, opened = 0; i < tokens.length; i++) {
|
|
3095
|
+
let tok = tokens[i];
|
|
3093
3096
|
if (tok.tokenType == Token.Type.Close) {
|
|
3094
3097
|
if (opened)
|
|
3095
3098
|
opened--;
|
|
@@ -3134,7 +3137,7 @@ function fitReplacement(doc, from, to, slice, context) {
|
|
|
3134
3137
|
let cost = (neutral ? 0 : 2) + (i < preferredContext ? context.length - i : i - preferredContext) + (toEnd ? 0 : 1e7);
|
|
3135
3138
|
if (foundCost > cost) {
|
|
3136
3139
|
found = { from: cxFrom.before, to: toEnd ? cxTo.after : to.pos,
|
|
3137
|
-
|
|
3140
|
+
tokens: i >= 0 ? closeSlice(doc.schema, tokens, context, i + 1, toEnd) : tokens };
|
|
3138
3141
|
foundCost = cost;
|
|
3139
3142
|
}
|
|
3140
3143
|
}
|
|
@@ -3151,7 +3154,7 @@ function fitReplacement(doc, from, to, slice, context) {
|
|
|
3151
3154
|
continue;
|
|
3152
3155
|
if (doc.schema.canContain(cx.node.type, type)) {
|
|
3153
3156
|
let pos = before > -1 ? before : after;
|
|
3154
|
-
return { from: pos, to: pos,
|
|
3157
|
+
return { from: pos, to: pos, tokens: i >= 0 ? closeSlice(doc.schema, tokens, context, i + 1, true) : tokens };
|
|
3155
3158
|
}
|
|
3156
3159
|
}
|
|
3157
3160
|
if (isFitBarrier(cx.node.type) || !cx.parent)
|
|
@@ -3166,11 +3169,11 @@ function fitReplacement(doc, from, to, slice, context) {
|
|
|
3166
3169
|
continue;
|
|
3167
3170
|
let depth = i < 0 ? preferredContext : i;
|
|
3168
3171
|
if (doc.schema.canContain(from.parent.node.type, context[depth].type)) {
|
|
3169
|
-
|
|
3172
|
+
tokens = closeSlice(doc.schema, tokens, context, depth + 1, true);
|
|
3170
3173
|
break;
|
|
3171
3174
|
}
|
|
3172
3175
|
}
|
|
3173
|
-
return { from: from.pos, to: to.pos,
|
|
3176
|
+
return { from: from.pos, to: to.pos, tokens };
|
|
3174
3177
|
}
|
|
3175
3178
|
function fitDeletion(doc, from, to) {
|
|
3176
3179
|
let toDepth = to.depth;
|
|
@@ -3184,12 +3187,12 @@ function fitDeletion(doc, from, to) {
|
|
|
3184
3187
|
end++;
|
|
3185
3188
|
}
|
|
3186
3189
|
let toAtEnd = toDepth == depth && cxTo.end == end; if (cx.end < to.pos && cx.parent.end > to.pos && !toAtEnd)
|
|
3187
|
-
return { from: cx.before, to: to.pos,
|
|
3190
|
+
return { from: cx.before, to: to.pos, tokens: noTokens };
|
|
3188
3191
|
if (!cx.node.inlineContent && toAtEnd && cx.parent.start == cxTo.parent.start &&
|
|
3189
3192
|
!(from.parent.start == to.parent.start && from.parent.node.inlineContent))
|
|
3190
|
-
covered = { from: cx.before, to: cxTo.after,
|
|
3193
|
+
covered = { from: cx.before, to: cxTo.after, tokens: noTokens };
|
|
3191
3194
|
}
|
|
3192
|
-
return covered || { from: from.pos, to: to.pos,
|
|
3195
|
+
return covered || { from: from.pos, to: to.pos, tokens: noTokens };
|
|
3193
3196
|
}
|
|
3194
3197
|
|
|
3195
3198
|
function parse(schema, doc, options = {}) {
|
|
@@ -3229,7 +3232,7 @@ function parse(schema, doc, options = {}) {
|
|
|
3229
3232
|
}
|
|
3230
3233
|
};
|
|
3231
3234
|
emitTokens(top.children, true, true);
|
|
3232
|
-
return
|
|
3235
|
+
return Slice.of(tokens, context);
|
|
3233
3236
|
}
|
|
3234
3237
|
parse.slice = slice;
|
|
3235
3238
|
(function (Rule) {
|
|
@@ -3675,12 +3678,12 @@ function serialize(doc, options = {}) {
|
|
|
3675
3678
|
return Elt.Fragment.create(serializeChildren(doc.content, new SerializeContext(options)));
|
|
3676
3679
|
}
|
|
3677
3680
|
;serialize = /*@__PURE__*/(function (serialize) {
|
|
3678
|
-
function node(node, options) {
|
|
3681
|
+
function node(node, options = {}) {
|
|
3679
3682
|
return serializeChildren([node], new SerializeContext(options))[0];
|
|
3680
3683
|
}
|
|
3681
3684
|
serialize.node = node;
|
|
3682
|
-
function slice(slice, options) {
|
|
3683
|
-
return Elt.Fragment.create(serializeChildren(flattenSlice(slice.content,
|
|
3685
|
+
function slice(slice, options = {}) {
|
|
3686
|
+
return Elt.Fragment.create(serializeChildren(flattenSlice(slice.content, slice.context, options.includeContext || 0, !!options.openAttr), new SerializeContext(options, options.openAttr)));
|
|
3684
3687
|
}
|
|
3685
3688
|
serialize.slice = slice;
|
|
3686
3689
|
;return serialize})(serialize);
|