@nerd-bible/wordgard 0.3.5 → 0.5.2-beta
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/README.md +1 -1
- package/dist/command.d.ts +19 -7
- package/dist/command.js +78 -50
- package/dist/doc.d.ts +17 -9
- package/dist/doc.js +67 -62
- package/dist/editor.d.ts +13 -4
- package/dist/editor.js +615 -275
- package/dist/schema.js +1 -1
- package/dist/state.d.ts +5 -11
- package/dist/state.js +52 -30
- package/dist/table.js +4 -3
- package/dist/types.d.ts +5 -5
- package/dist/types.js +8 -8
- package/package.json +1 -1
package/dist/doc.js
CHANGED
|
@@ -13,7 +13,7 @@ class TextOutput {
|
|
|
13
13
|
: node.type.spec.toText ? node.type.spec.toText(node)
|
|
14
14
|
: this.leafText ? this.leafText(node)
|
|
15
15
|
: "";
|
|
16
|
-
if (node.isLeaf ? node.
|
|
16
|
+
if (node.isLeaf ? node.isBlock && nodeText : node.isTextblock)
|
|
17
17
|
this.openBlock();
|
|
18
18
|
if (nodeText != null) {
|
|
19
19
|
this.text += nodeText;
|
|
@@ -1001,7 +1001,7 @@ class Pos {
|
|
|
1001
1001
|
}
|
|
1002
1002
|
Pos.Plot = Plot;
|
|
1003
1003
|
;return Pos})(Pos);
|
|
1004
|
-
const posCache = /*@__PURE__*/(() => new
|
|
1004
|
+
const posCache = /*@__PURE__*/(() => new WeakMap())(), cacheSize = 8;
|
|
1005
1005
|
let cachePos = 0;
|
|
1006
1006
|
function cacheFor(doc) {
|
|
1007
1007
|
let found = posCache.get(doc);
|
|
@@ -1184,6 +1184,8 @@ class Leaf extends BaseTag {
|
|
|
1184
1184
|
get tokenType() { return Token.Type.Node; }
|
|
1185
1185
|
get isLeaf() { return true; }
|
|
1186
1186
|
get isPlot() { return false; }
|
|
1187
|
+
get isInline() { return this.type.isInline; }
|
|
1188
|
+
get isBlock() { return this.type.isBlock; }
|
|
1187
1189
|
get length() { return this.is(Leaf.Text) ? this.param.length : 1; }
|
|
1188
1190
|
pushTo(nodes) {
|
|
1189
1191
|
if (this.is(Leaf.Text)) {
|
|
@@ -1291,6 +1293,8 @@ class Plot {
|
|
|
1291
1293
|
get isTextblock() { return this.type.isTextblock; }
|
|
1292
1294
|
get isLeaf() { return false; }
|
|
1293
1295
|
get isPlot() { return true; }
|
|
1296
|
+
get isInline() { return this.type.isInline; }
|
|
1297
|
+
get isBlock() { return this.type.isBlock; }
|
|
1294
1298
|
get isDoc() { return this.type.isDoc; }
|
|
1295
1299
|
get firstChild() {
|
|
1296
1300
|
return this.content.length ? this.content[0] : null;
|
|
@@ -1556,7 +1560,7 @@ function sliceContent(out, content, from, to) {
|
|
|
1556
1560
|
}
|
|
1557
1561
|
}
|
|
1558
1562
|
function joinText(nodes) {
|
|
1559
|
-
if (!nodes.length || nodes[0].
|
|
1563
|
+
if (!nodes.length || nodes[0].isBlock)
|
|
1560
1564
|
return nodes;
|
|
1561
1565
|
let joined;
|
|
1562
1566
|
for (let i = 0, last = null; i < nodes.length; i++) {
|
|
@@ -1627,7 +1631,7 @@ class Schema {
|
|
|
1627
1631
|
if (!node.type.canBeEmpty && node.content.length == 0)
|
|
1628
1632
|
throw new ValidationError(`Node ${node.name} with block content may not be empty`);
|
|
1629
1633
|
for (let ch of node.content) {
|
|
1630
|
-
if (!this.canContain(node.type, ch.type) || node.inlineContent != ch.
|
|
1634
|
+
if (!this.canContain(node.type, ch.type) || node.inlineContent != ch.isInline)
|
|
1631
1635
|
throw new ValidationError(`Node type ${node.name} cannot contain child ${ch.name}`);
|
|
1632
1636
|
this.validate(ch);
|
|
1633
1637
|
}
|
|
@@ -2154,8 +2158,43 @@ class ChangeSet {
|
|
|
2154
2158
|
return fix ? set.compose(fix) : set;
|
|
2155
2159
|
}
|
|
2156
2160
|
compose(other) {
|
|
2157
|
-
let
|
|
2158
|
-
|
|
2161
|
+
let sectionsA = this.sections, dataA = this.data;
|
|
2162
|
+
let sectionsB = other.sections, dataB = other.data;
|
|
2163
|
+
let sections = [], data = [];
|
|
2164
|
+
let a = new SectionIter(sectionsA, dataA), b = new SectionIter(sectionsB, dataB);
|
|
2165
|
+
for (let open = false;;) {
|
|
2166
|
+
if (a.done && b.done) {
|
|
2167
|
+
return new ChangeSet(sections, data);
|
|
2168
|
+
}
|
|
2169
|
+
else if (a.ins == 0) { addSection(sections, data, a.len, 0, a.slice, open);
|
|
2170
|
+
a.next();
|
|
2171
|
+
}
|
|
2172
|
+
else if (b.len == 0 && !b.done) { addSection(sections, data, 0, b.ins, b.slice, open);
|
|
2173
|
+
b.next();
|
|
2174
|
+
}
|
|
2175
|
+
else if (a.done || b.done) {
|
|
2176
|
+
throw new ValidationError("Mismatched change set lengths");
|
|
2177
|
+
}
|
|
2178
|
+
else {
|
|
2179
|
+
let len = Math.min(a.len2, b.len), sectionLen = sections.length;
|
|
2180
|
+
if (a.keep && b.keep) {
|
|
2181
|
+
let mods = combineMods(a.mods, b.mods);
|
|
2182
|
+
addSection(sections, data, len, mods ? -2 : -1, mods, open);
|
|
2183
|
+
}
|
|
2184
|
+
else if (a.keep) {
|
|
2185
|
+
addSection(sections, data, len, b.off ? 0 : b.ins, b.off ? Slice.empty : b.slice, open);
|
|
2186
|
+
}
|
|
2187
|
+
else if (b.keep) {
|
|
2188
|
+
addSection(sections, data, a.off ? 0 : a.len, len, applyModsToSlice(a.slicePart(len), b.mods), open);
|
|
2189
|
+
}
|
|
2190
|
+
else {
|
|
2191
|
+
addSection(sections, data, a.off ? 0 : a.len, b.off ? 0 : b.ins, b.off ? Slice.empty : b.slice, open);
|
|
2192
|
+
}
|
|
2193
|
+
open = (a.ins > len || b.ins >= 0 && b.len > len) && (open || sections.length > sectionLen);
|
|
2194
|
+
a.forward2(len);
|
|
2195
|
+
b.forward(len);
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2159
2198
|
}
|
|
2160
2199
|
invert(doc) {
|
|
2161
2200
|
let sections = [], data = [];
|
|
@@ -2274,7 +2313,7 @@ class ChangeSet {
|
|
|
2274
2313
|
len += this.sections[i];
|
|
2275
2314
|
i += 2;
|
|
2276
2315
|
}
|
|
2277
|
-
gap(posA, posA + len, posB, posB + len);
|
|
2316
|
+
gap(posA, posA + len, posB, posB + len, i == this.sections.length);
|
|
2278
2317
|
posB += len;
|
|
2279
2318
|
}
|
|
2280
2319
|
else {
|
|
@@ -2376,9 +2415,6 @@ class ChangeSet {
|
|
|
2376
2415
|
}
|
|
2377
2416
|
return result;
|
|
2378
2417
|
}
|
|
2379
|
-
static composeSections(a, b) {
|
|
2380
|
-
return compose(a, b).sections;
|
|
2381
|
-
}
|
|
2382
2418
|
static transform(doc, a, b) {
|
|
2383
2419
|
let { set: mA, fix } = transform(a, b, doc, true, true);
|
|
2384
2420
|
let mB = transform(b, a, doc, false, false).set;
|
|
@@ -2577,43 +2613,6 @@ function transform(setA, setB, doc, before, fit) {
|
|
|
2577
2613
|
}
|
|
2578
2614
|
}
|
|
2579
2615
|
}
|
|
2580
|
-
function compose(sectionsA, sectionsB, dataA, dataB) {
|
|
2581
|
-
let sections = [], data = dataA ? [] : null;
|
|
2582
|
-
let a = new SectionIter(sectionsA, dataA), b = new SectionIter(sectionsB, dataB);
|
|
2583
|
-
for (let open = false;;) {
|
|
2584
|
-
if (a.done && b.done) {
|
|
2585
|
-
return { sections, data };
|
|
2586
|
-
}
|
|
2587
|
-
else if (a.ins == 0) { addSection(sections, data, a.len, 0, a.slice, open);
|
|
2588
|
-
a.next();
|
|
2589
|
-
}
|
|
2590
|
-
else if (b.len == 0 && !b.done) { addSection(sections, data, 0, b.ins, b.slice, open);
|
|
2591
|
-
b.next();
|
|
2592
|
-
}
|
|
2593
|
-
else if (a.done || b.done) {
|
|
2594
|
-
throw new ValidationError("Mismatched change set lengths");
|
|
2595
|
-
}
|
|
2596
|
-
else {
|
|
2597
|
-
let len = Math.min(a.len2, b.len), sectionLen = sections.length;
|
|
2598
|
-
if (a.keep && b.keep) {
|
|
2599
|
-
let mods = combineMods(a.mods, b.mods);
|
|
2600
|
-
addSection(sections, data, len, (data ? mods : a.ins == -2 || b.ins == -2) ? -2 : -1, mods, open);
|
|
2601
|
-
}
|
|
2602
|
-
else if (a.keep) {
|
|
2603
|
-
addSection(sections, data, len, b.off ? 0 : b.ins, b.off ? Slice.empty : b.slice, open);
|
|
2604
|
-
}
|
|
2605
|
-
else if (b.keep) {
|
|
2606
|
-
addSection(sections, data, a.off ? 0 : a.len, len, data ? applyModsToSlice(a.slicePart(len), b.mods) : null, open);
|
|
2607
|
-
}
|
|
2608
|
-
else {
|
|
2609
|
-
addSection(sections, data, a.off ? 0 : a.len, b.off ? 0 : b.ins, b.off ? Slice.empty : b.slice, open);
|
|
2610
|
-
}
|
|
2611
|
-
open = (a.ins > len || b.ins >= 0 && b.len > len) && (open || sections.length > sectionLen);
|
|
2612
|
-
a.forward2(len);
|
|
2613
|
-
b.forward(len);
|
|
2614
|
-
}
|
|
2615
|
-
}
|
|
2616
|
-
}
|
|
2617
2616
|
function combineMods(a, b) {
|
|
2618
2617
|
return !a ? b : !b ? a : a.concat(b);
|
|
2619
2618
|
}
|
|
@@ -2973,10 +2972,10 @@ class SectionIter {
|
|
|
2973
2972
|
get done() { return this.ins == -3; }
|
|
2974
2973
|
get len2() { return this.ins < 0 ? this.len : this.ins; }
|
|
2975
2974
|
get mods() {
|
|
2976
|
-
return this.data
|
|
2975
|
+
return this.data[(this.i - 2) >> 1];
|
|
2977
2976
|
}
|
|
2978
2977
|
get slice() {
|
|
2979
|
-
return this.data
|
|
2978
|
+
return this.data[(this.i - 2) >> 1];
|
|
2980
2979
|
}
|
|
2981
2980
|
slicePart(len) {
|
|
2982
2981
|
return this.slice.slice(this.off, len == null ? undefined : this.off + len);
|
|
@@ -3005,7 +3004,7 @@ function addSection(sections, data, len, ins, value, forceJoin = false) {
|
|
|
3005
3004
|
return;
|
|
3006
3005
|
let last = sections.length - 2;
|
|
3007
3006
|
if (last >= 0 && ins <= 0 && ins == sections[last + 1]) {
|
|
3008
|
-
let lastValue = data
|
|
3007
|
+
let lastValue = data[data.length - 1];
|
|
3009
3008
|
let match = ins == 0 ? true
|
|
3010
3009
|
: value ? lastValue && compareModifications(lastValue, value)
|
|
3011
3010
|
: !lastValue;
|
|
@@ -3017,13 +3016,11 @@ function addSection(sections, data, len, ins, value, forceJoin = false) {
|
|
|
3017
3016
|
if (forceJoin || last >= 0 && len == 0 && sections[last] == 0) {
|
|
3018
3017
|
sections[last] += len;
|
|
3019
3018
|
sections[last + 1] += ins;
|
|
3020
|
-
|
|
3021
|
-
data[data.length - 1] = data[data.length - 1].concat(value);
|
|
3019
|
+
data[data.length - 1] = data[data.length - 1].concat(value);
|
|
3022
3020
|
}
|
|
3023
3021
|
else {
|
|
3024
3022
|
sections.push(len, ins);
|
|
3025
|
-
|
|
3026
|
-
data.push(value);
|
|
3023
|
+
data.push(value);
|
|
3027
3024
|
}
|
|
3028
3025
|
}
|
|
3029
3026
|
function finishCx(cx, schema) {
|
|
@@ -3069,6 +3066,9 @@ function splatContext(top, cx) {
|
|
|
3069
3066
|
for (let ch of cx.children)
|
|
3070
3067
|
top.push(ch);
|
|
3071
3068
|
}
|
|
3069
|
+
function isFitBarrier(plot) {
|
|
3070
|
+
return plot.isolating || plot.isInline;
|
|
3071
|
+
}
|
|
3072
3072
|
function fitReplacement(doc, from, to, slice, context) {
|
|
3073
3073
|
if (!slice.length)
|
|
3074
3074
|
return fitDeletion(doc, from, to);
|
|
@@ -3099,10 +3099,10 @@ function fitReplacement(doc, from, to, slice, context) {
|
|
|
3099
3099
|
let found, foundCost = 1e8;
|
|
3100
3100
|
let neutral = true, toEnd = true;
|
|
3101
3101
|
scan: for (let cxFrom = from.parent, cxTo = to.parent, fromDepth = from.depth, toDepth = to.depth, start = from.pos, end = to.pos; cxFrom.parent; cxFrom = cxFrom.parent, start--, fromDepth--) {
|
|
3102
|
-
if (cxFrom.start != start || cxFrom.node.type
|
|
3102
|
+
if (cxFrom.start != start || isFitBarrier(cxFrom.node.type))
|
|
3103
3103
|
break;
|
|
3104
3104
|
while (toDepth > fromDepth) {
|
|
3105
|
-
if (cxTo.node.type
|
|
3105
|
+
if (isFitBarrier(cxTo.node.type))
|
|
3106
3106
|
break scan;
|
|
3107
3107
|
cxTo = cxTo.parent;
|
|
3108
3108
|
toDepth--;
|
|
@@ -3136,17 +3136,22 @@ function fitReplacement(doc, from, to, slice, context) {
|
|
|
3136
3136
|
if (found)
|
|
3137
3137
|
return found;
|
|
3138
3138
|
if (from.pos == to.pos && !from.inText) {
|
|
3139
|
-
let cx = from.parent
|
|
3140
|
-
for (
|
|
3139
|
+
let cx = from.parent;
|
|
3140
|
+
for (let before = from.index ? -1 : from.pos, after = from.pos == from.parent.end ? from.pos : -1; before > -1 || after > -1;) {
|
|
3141
3141
|
for (let i = -1; i < context.length; i++) {
|
|
3142
3142
|
let type = i >= 0 ? context[i].type : firstType;
|
|
3143
3143
|
if (!type)
|
|
3144
3144
|
continue;
|
|
3145
|
-
if (doc.schema.canContain(cx.
|
|
3146
|
-
let pos = before
|
|
3145
|
+
if (doc.schema.canContain(cx.node.type, type)) {
|
|
3146
|
+
let pos = before > -1 ? before : after;
|
|
3147
3147
|
return { from: pos, to: pos, slice: i >= 0 ? closeSlice(doc.schema, slice, context, i + 1, true) : slice };
|
|
3148
3148
|
}
|
|
3149
3149
|
}
|
|
3150
|
+
if (isFitBarrier(cx.node.type) || !cx.parent)
|
|
3151
|
+
break;
|
|
3152
|
+
before = before == cx.start ? before - 1 : -1;
|
|
3153
|
+
after = after == cx.end ? after + 1 : -1;
|
|
3154
|
+
cx = cx.parent;
|
|
3150
3155
|
}
|
|
3151
3156
|
}
|
|
3152
3157
|
for (let i = 0; i < context.length; i++) {
|
|
@@ -3161,7 +3166,7 @@ function fitDeletion(doc, from, to) {
|
|
|
3161
3166
|
let toDepth = to.depth;
|
|
3162
3167
|
let covered;
|
|
3163
3168
|
for (let cx = from.parent, cxTo = to.parent, depth = from.depth, start = from.pos, end = to.pos; cx.parent; start--, cx = cx.parent, depth--) {
|
|
3164
|
-
if (cx.start != start || cx.node.type
|
|
3169
|
+
if (cx.start != start || isFitBarrier(cx.node.type))
|
|
3165
3170
|
break;
|
|
3166
3171
|
while (toDepth > depth) {
|
|
3167
3172
|
cxTo = cxTo.parent;
|
|
@@ -3350,7 +3355,7 @@ class ParseContext {
|
|
|
3350
3355
|
else if (!match || match.rule.ignore === "skip") {
|
|
3351
3356
|
let sync, top = this.top;
|
|
3352
3357
|
if (blockTags.has(name)) {
|
|
3353
|
-
if (top.children.length && top.children[0].
|
|
3358
|
+
if (top.children.length && top.children[0].isInline && top.parent)
|
|
3354
3359
|
this.close();
|
|
3355
3360
|
sync = true;
|
|
3356
3361
|
}
|
package/dist/editor.d.ts
CHANGED
|
@@ -351,11 +351,13 @@ declare class PointSet<T extends PointSet.Value = PointSet.Value> {
|
|
|
351
351
|
set with the adjusted points. May delete points when the content
|
|
352
352
|
around them was deleted.
|
|
353
353
|
*/
|
|
354
|
-
map(changes: ChangeSet): PointSet<T>;
|
|
354
|
+
map(changes: ChangeSet, start?: number): PointSet<T>;
|
|
355
355
|
/**
|
|
356
|
-
Returns the union of this set and the given set.
|
|
356
|
+
Returns the union of this set and the given set. If
|
|
357
|
+
`maskFrom`/`maskTo` are given, drop any points from `this`
|
|
358
|
+
between or at those positions.
|
|
357
359
|
*/
|
|
358
|
-
merge(other: PointSet<T
|
|
360
|
+
merge(other: PointSet<T>, maskFrom?: number, maskTo?: number | undefined): PointSet<T>;
|
|
359
361
|
/**
|
|
360
362
|
Get the value at the given position, if any. If there's multiple
|
|
361
363
|
values at that position, the one with the lowest side is
|
|
@@ -421,7 +423,13 @@ declare class RangeSet<T extends RangeSet.Value = RangeSet.Value> {
|
|
|
421
423
|
Adjust the positions of the ranges for the given change set.
|
|
422
424
|
Returns a set with the updated ranges.
|
|
423
425
|
*/
|
|
424
|
-
map(changes: ChangeSet): RangeSet<T>;
|
|
426
|
+
map(changes: ChangeSet, start?: number): RangeSet<T>;
|
|
427
|
+
/**
|
|
428
|
+
Merge this set with another set. If `maskFrom`/`maskTo` are
|
|
429
|
+
given, any ranges overlapping the masked range in `this` are
|
|
430
|
+
not included in the merged set.
|
|
431
|
+
*/
|
|
432
|
+
merge(other: RangeSet<T>, maskFrom?: number, maskTo?: number | undefined): RangeSet<T>;
|
|
425
433
|
/**
|
|
426
434
|
Create a range set from an iterable of `[from, to, value]`
|
|
427
435
|
tuples, or a function that calls its argument for every range to
|
|
@@ -512,6 +520,7 @@ declare abstract class Tile {
|
|
|
512
520
|
get boundary(): 0 | 1;
|
|
513
521
|
get firstChild(): Tile | null;
|
|
514
522
|
get lastChild(): Tile | null;
|
|
523
|
+
get nodeParent(): Tile;
|
|
515
524
|
ignoreEvent(event: Event): boolean;
|
|
516
525
|
get ignoreMutations(): boolean;
|
|
517
526
|
toString(): string;
|