@nerd-bible/wordgard 0.6.2-beta1 → 0.6.2-beta11
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/collab.js +3 -0
- package/dist/command.d.ts +15 -7
- package/dist/command.js +27 -8
- package/dist/doc.d.ts +14 -3
- package/dist/doc.js +98 -47
- package/dist/editor.d.ts +25 -10
- package/dist/editor.js +351 -205
- package/dist/history.js +7 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/phrases.js +1 -0
- package/dist/schema.js +13 -10
- package/dist/set.d.ts +3 -2
- package/dist/set.js +27 -13
- package/dist/state.d.ts +52 -7
- package/dist/state.js +92 -34
- package/dist/table.d.ts +111 -1
- package/dist/table.js +32 -22
- package/package.json +1 -1
package/dist/state.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Leaf, ValidationError, Slice, Pos, ChangeSet, Plot, SchemaError, parse, Schema } from 'wordgard/doc';
|
|
1
|
+
import { Leaf, ValidationError, Slice, Pos, ChangeSet, Plot, SchemaError, parse, Schema, Node } from 'wordgard/doc';
|
|
2
2
|
import { findClusterBreak } from '@marijn/find-cluster-break';
|
|
3
3
|
|
|
4
4
|
function dec(str) {
|
|
@@ -910,7 +910,7 @@ function skipWord(cx, start, side, forward) {
|
|
|
910
910
|
function wordAt(state, pos, bias) {
|
|
911
911
|
let res = state.doc.resolve(pos);
|
|
912
912
|
if (!res.parent.node.inlineContent)
|
|
913
|
-
return
|
|
913
|
+
return null;
|
|
914
914
|
let start = pos, end = pos, text = "";
|
|
915
915
|
scanBack: for (let i = res.index - (res.inText ? 0 : 1), cur = res.nodeBefore; cur;) {
|
|
916
916
|
if (!cur.is(Leaf.Text))
|
|
@@ -951,8 +951,18 @@ function wordAt(state, pos, bias) {
|
|
|
951
951
|
if (segment.isWordLike && segment.index <= local && segment.index + segment.segment.length >= local && (!best || bias > 0))
|
|
952
952
|
best = segment;
|
|
953
953
|
}
|
|
954
|
-
return best ? GardSelection.undirectionalRange(start + best.index, start + best.index + best.segment.length)
|
|
955
|
-
|
|
954
|
+
return best ? GardSelection.undirectionalRange(start + best.index, start + best.index + best.segment.length) : null;
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
function debugString(value) {
|
|
958
|
+
let tp = typeof value;
|
|
959
|
+
if (tp == "string")
|
|
960
|
+
return JSON.stringify(value);
|
|
961
|
+
if (tp == "function")
|
|
962
|
+
return /.*?\)/.exec(value.toString())?.[0] || value;
|
|
963
|
+
if (Array.isArray(value))
|
|
964
|
+
return `[${value.map(debugString)}]`;
|
|
965
|
+
return value;
|
|
956
966
|
}
|
|
957
967
|
|
|
958
968
|
class Transaction {
|
|
@@ -1045,20 +1055,28 @@ class Transaction {
|
|
|
1045
1055
|
this.type = type;
|
|
1046
1056
|
this.value = value;
|
|
1047
1057
|
}
|
|
1048
|
-
static define() { return
|
|
1058
|
+
static define(name) { return Transaction.Annotation.Type.new(name || null); }
|
|
1059
|
+
toString() { return `${this.type}(${debugString(this.value)})`; }
|
|
1049
1060
|
}
|
|
1050
1061
|
Transaction.Annotation = Annotation;
|
|
1051
1062
|
(function (Annotation) {
|
|
1052
1063
|
class Type {
|
|
1064
|
+
name;
|
|
1065
|
+
constructor(
|
|
1066
|
+
name) {
|
|
1067
|
+
this.name = name;
|
|
1068
|
+
}
|
|
1069
|
+
static new(name) { return new Type(name); }
|
|
1053
1070
|
of(value) { return new Transaction.Annotation(this, value); }
|
|
1071
|
+
toString() { return "Annotation" + (this.name ? ":" + this.name : ""); }
|
|
1054
1072
|
}
|
|
1055
1073
|
Annotation.Type = Type;
|
|
1056
1074
|
})(Annotation = Transaction.Annotation || (Transaction.Annotation = {}));
|
|
1057
|
-
Transaction.time = Transaction.Annotation.define();
|
|
1058
|
-
Transaction.userEvent = Annotation.define();
|
|
1059
|
-
Transaction.addToHistory = Annotation.define();
|
|
1060
|
-
Transaction.remote = Annotation.define();
|
|
1061
|
-
Transaction.appended = Annotation.define();
|
|
1075
|
+
Transaction.time = Transaction.Annotation.define("time");
|
|
1076
|
+
Transaction.userEvent = Annotation.define("userEvent");
|
|
1077
|
+
Transaction.addToHistory = Annotation.define("addToHistory");
|
|
1078
|
+
Transaction.remote = Annotation.define("remote");
|
|
1079
|
+
Transaction.appended = Annotation.define("appended");
|
|
1062
1080
|
class Effect {
|
|
1063
1081
|
type;
|
|
1064
1082
|
value;
|
|
@@ -1074,8 +1092,9 @@ class Transaction {
|
|
|
1074
1092
|
}
|
|
1075
1093
|
is(type) { return this.type == type; }
|
|
1076
1094
|
static define(spec = {}) {
|
|
1077
|
-
return
|
|
1095
|
+
return Effect.Type.new(spec.map || (v => v), spec.name || null);
|
|
1078
1096
|
}
|
|
1097
|
+
toString() { return `${this.type}(${debugString(this.value)})`; }
|
|
1079
1098
|
}
|
|
1080
1099
|
Transaction.Effect = Effect;
|
|
1081
1100
|
(function (Effect) {
|
|
@@ -1093,11 +1112,18 @@ class Transaction {
|
|
|
1093
1112
|
Effect.mapEffects = mapEffects;
|
|
1094
1113
|
class Type {
|
|
1095
1114
|
map;
|
|
1115
|
+
name;
|
|
1096
1116
|
constructor(
|
|
1097
|
-
map
|
|
1117
|
+
map,
|
|
1118
|
+
name) {
|
|
1098
1119
|
this.map = map;
|
|
1120
|
+
this.name = name;
|
|
1121
|
+
}
|
|
1122
|
+
static new(map, name) {
|
|
1123
|
+
return new Type(map, name);
|
|
1099
1124
|
}
|
|
1100
1125
|
of(value) { return new Transaction.Effect(this, value); }
|
|
1126
|
+
toString() { return "Effect" + (this.name ? ":" + this.name : ""); }
|
|
1101
1127
|
}
|
|
1102
1128
|
Effect.Type = Type;
|
|
1103
1129
|
})(Effect = Transaction.Effect || (Transaction.Effect = {}));
|
|
@@ -1366,8 +1392,8 @@ class GardState {
|
|
|
1366
1392
|
wordAt(pos, bias = 1) {
|
|
1367
1393
|
return wordAt(this, pos, bias);
|
|
1368
1394
|
}
|
|
1369
|
-
static reconfigure = /*@__PURE__*/Transaction.Effect.define();
|
|
1370
|
-
static appendConfig = /*@__PURE__*/Transaction.Effect.define();
|
|
1395
|
+
static reconfigure = /*@__PURE__*/Transaction.Effect.define({ name: "reconfigure" });
|
|
1396
|
+
static appendConfig = /*@__PURE__*/Transaction.Effect.define({ name: "appendConfig" });
|
|
1371
1397
|
}
|
|
1372
1398
|
;GardState = /*@__PURE__*/(function (GardState) {
|
|
1373
1399
|
class Field {
|
|
@@ -1385,13 +1411,15 @@ class GardState {
|
|
|
1385
1411
|
this.updateF = updateF;
|
|
1386
1412
|
this.compareF = compareF;
|
|
1387
1413
|
this.spec = spec;
|
|
1414
|
+
this.name = spec.name || null;
|
|
1388
1415
|
}
|
|
1389
1416
|
static define(config) {
|
|
1390
|
-
let field = new
|
|
1417
|
+
let field = new Field(nextID++, config.create, config.update, config.compare || ((a, b) => a === b), config);
|
|
1391
1418
|
if (config.provide)
|
|
1392
1419
|
field.provides = config.provide(field);
|
|
1393
1420
|
return field;
|
|
1394
1421
|
}
|
|
1422
|
+
name;
|
|
1395
1423
|
create(state) {
|
|
1396
1424
|
let init = state.facet(initField).find(i => i.field == this);
|
|
1397
1425
|
return (init?.create || this.createF)(state);
|
|
@@ -1425,21 +1453,25 @@ class GardState {
|
|
|
1425
1453
|
init(create) {
|
|
1426
1454
|
return [this, initField.of({ field: this, create })];
|
|
1427
1455
|
}
|
|
1456
|
+
toString() { return "Field" + (this.name ? ":" + this.name : ""); }
|
|
1428
1457
|
}
|
|
1429
1458
|
GardState.Field = Field;
|
|
1430
1459
|
(function (Field) {
|
|
1431
1460
|
class Derived {
|
|
1432
1461
|
value;
|
|
1433
1462
|
compareF;
|
|
1463
|
+
name;
|
|
1434
1464
|
id = nextID++;
|
|
1435
1465
|
dependencies = [];
|
|
1436
1466
|
constructor(
|
|
1437
|
-
value, compareF
|
|
1467
|
+
value, compareF,
|
|
1468
|
+
name) {
|
|
1438
1469
|
this.value = value;
|
|
1439
1470
|
this.compareF = compareF;
|
|
1471
|
+
this.name = name;
|
|
1440
1472
|
}
|
|
1441
1473
|
static define(compute, spec = {}) {
|
|
1442
|
-
return new Derived(compute, spec.compare || ((a, b) => a === b));
|
|
1474
|
+
return new Derived(compute, spec.compare || ((a, b) => a === b), spec.name || null);
|
|
1443
1475
|
}
|
|
1444
1476
|
get extension() { return this; }
|
|
1445
1477
|
slot(addresses) {
|
|
@@ -1483,6 +1515,7 @@ class GardState {
|
|
|
1483
1515
|
}
|
|
1484
1516
|
};
|
|
1485
1517
|
}
|
|
1518
|
+
toString() { return "Field.Derived" + (this.name ? ":" + this.name : ""); }
|
|
1486
1519
|
}
|
|
1487
1520
|
Field.Derived = Derived;
|
|
1488
1521
|
})(Field = GardState.Field || (GardState.Field = {}));
|
|
@@ -1491,6 +1524,7 @@ class GardState {
|
|
|
1491
1524
|
compareInput;
|
|
1492
1525
|
compare;
|
|
1493
1526
|
isStatic;
|
|
1527
|
+
name;
|
|
1494
1528
|
id = nextID++;
|
|
1495
1529
|
default;
|
|
1496
1530
|
extensions;
|
|
@@ -1498,17 +1532,19 @@ class GardState {
|
|
|
1498
1532
|
combine,
|
|
1499
1533
|
compareInput,
|
|
1500
1534
|
compare,
|
|
1501
|
-
isStatic, enables
|
|
1535
|
+
isStatic, enables,
|
|
1536
|
+
name) {
|
|
1502
1537
|
this.combine = combine;
|
|
1503
1538
|
this.compareInput = compareInput;
|
|
1504
1539
|
this.compare = compare;
|
|
1505
1540
|
this.isStatic = isStatic;
|
|
1541
|
+
this.name = name;
|
|
1506
1542
|
this.default = combine(none);
|
|
1507
1543
|
this.extensions = typeof enables == "function" ? enables(this) : enables;
|
|
1508
1544
|
}
|
|
1509
1545
|
get reader() { return this; }
|
|
1510
1546
|
static define(config = {}) {
|
|
1511
|
-
return new GardState.Facet(config.combine || ((a) => a), config.compareInput || ((a, b) => a === b), config.compare || (!config.combine ? sameArray : (a, b) => a === b), !!config.static, config.enables);
|
|
1547
|
+
return new GardState.Facet(config.combine || ((a) => a), config.compareInput || ((a, b) => a === b), config.compare || (!config.combine ? sameArray : (a, b) => a === b), !!config.static, config.enables, config.name || null);
|
|
1512
1548
|
}
|
|
1513
1549
|
of(value) {
|
|
1514
1550
|
return new FacetProvider(this, nextID++, 1, value);
|
|
@@ -1533,6 +1569,7 @@ class GardState {
|
|
|
1533
1569
|
return this.derive(s => get(s.field(field)));
|
|
1534
1570
|
}
|
|
1535
1571
|
tag;
|
|
1572
|
+
toString() { return "Facet" + (this.name ? ":" + this.name : ""); }
|
|
1536
1573
|
}
|
|
1537
1574
|
GardState.Facet = Facet;
|
|
1538
1575
|
(function (Facet) {
|
|
@@ -1707,15 +1744,19 @@ class GardState {
|
|
|
1707
1744
|
return result.reduce((a, b) => a.concat(b));
|
|
1708
1745
|
}
|
|
1709
1746
|
GardState.prec = {
|
|
1710
|
-
highest: mkPrec(0),
|
|
1711
|
-
high: mkPrec(1),
|
|
1712
|
-
default: mkPrec(2),
|
|
1713
|
-
low: mkPrec(3),
|
|
1714
|
-
lowest: mkPrec(4)
|
|
1747
|
+
highest: mkPrec(0, "Highest"),
|
|
1748
|
+
high: mkPrec(1, "High"),
|
|
1749
|
+
default: mkPrec(2, "Default"),
|
|
1750
|
+
low: mkPrec(3, "Low"),
|
|
1751
|
+
lowest: mkPrec(4, "Lowest")
|
|
1715
1752
|
};
|
|
1716
1753
|
class Compartment {
|
|
1717
|
-
|
|
1718
|
-
|
|
1754
|
+
name;
|
|
1755
|
+
constructor(
|
|
1756
|
+
name) {
|
|
1757
|
+
this.name = name;
|
|
1758
|
+
}
|
|
1759
|
+
static define(name) { return new Compartment(name || null); }
|
|
1719
1760
|
of(ext) { return new CompartmentInstance(this, ext); }
|
|
1720
1761
|
reconfigure(content) {
|
|
1721
1762
|
return GardState.Compartment.reconfigureCompartment.of({ compartment: this, extension: content });
|
|
@@ -1723,28 +1764,35 @@ class GardState {
|
|
|
1723
1764
|
get(state) {
|
|
1724
1765
|
return state.config.compartments.get(this);
|
|
1725
1766
|
}
|
|
1726
|
-
static reconfigureCompartment = Transaction.Effect.define();
|
|
1767
|
+
static reconfigureCompartment = Transaction.Effect.define({ name: "reconfigureCompartment" });
|
|
1768
|
+
toString() { return "Compartment" + (this.name ? ":" + this.name : ""); }
|
|
1727
1769
|
}
|
|
1728
1770
|
GardState.Compartment = Compartment;
|
|
1729
1771
|
GardState.schemaElement = GardState.Facet.define({
|
|
1772
|
+
name: "schemaElement",
|
|
1730
1773
|
combine: values => values.reduce((set, elt) => set.concat(elt), none),
|
|
1731
1774
|
static: true
|
|
1732
1775
|
});
|
|
1733
1776
|
GardState.readOnly = GardState.Facet.define({
|
|
1777
|
+
name: "readOnly",
|
|
1734
1778
|
combine: values => values.length ? values[0] : false
|
|
1735
1779
|
});
|
|
1736
1780
|
GardState.textLTR = GardState.Facet.define({
|
|
1781
|
+
name: "textLTR",
|
|
1737
1782
|
combine: values => values.length ? values[0] : true,
|
|
1738
1783
|
static: true
|
|
1739
1784
|
});
|
|
1740
1785
|
GardState.textblockLTR = GardState.Facet.define({
|
|
1786
|
+
name: "textblockLTR",
|
|
1741
1787
|
static: true
|
|
1742
1788
|
});
|
|
1743
1789
|
GardState.visualCursorMotion = GardState.Facet.define({
|
|
1790
|
+
name: "visualCursorMotion",
|
|
1744
1791
|
combine(values) { return !values.length ? true : values[0]; },
|
|
1745
1792
|
static: true
|
|
1746
1793
|
});
|
|
1747
1794
|
GardState.isAtom = GardState.Facet.define({
|
|
1795
|
+
name: "isAtom",
|
|
1748
1796
|
static: true,
|
|
1749
1797
|
combine(inputs) {
|
|
1750
1798
|
let map = new Map();
|
|
@@ -1754,22 +1802,28 @@ class GardState {
|
|
|
1754
1802
|
}
|
|
1755
1803
|
});
|
|
1756
1804
|
;return GardState})(GardState);
|
|
1757
|
-
const initField = /*@__PURE__*/GardState.Facet.define({
|
|
1805
|
+
const initField = /*@__PURE__*/GardState.Facet.define({
|
|
1806
|
+
name: "init",
|
|
1807
|
+
static: true
|
|
1808
|
+
});
|
|
1758
1809
|
function addValue(set, value) {
|
|
1759
1810
|
if (set.indexOf(value) < 0)
|
|
1760
1811
|
set.push(value);
|
|
1761
1812
|
}
|
|
1762
|
-
function mkPrec(value) {
|
|
1763
|
-
return (ext) => new PrecExtension(ext, value);
|
|
1813
|
+
function mkPrec(value, name) {
|
|
1814
|
+
return (ext) => new PrecExtension(ext, value, name);
|
|
1764
1815
|
}
|
|
1765
1816
|
class PrecExtension {
|
|
1766
1817
|
inner;
|
|
1767
1818
|
prec;
|
|
1768
|
-
|
|
1819
|
+
name;
|
|
1820
|
+
constructor(inner, prec, name) {
|
|
1769
1821
|
this.inner = inner;
|
|
1770
1822
|
this.prec = prec;
|
|
1823
|
+
this.name = name;
|
|
1771
1824
|
}
|
|
1772
1825
|
extension;
|
|
1826
|
+
toString() { return `Prec.${this.name}(${this.inner})`; }
|
|
1773
1827
|
}
|
|
1774
1828
|
function sameArray(a, b) {
|
|
1775
1829
|
return a == b || a.length == b.length && a.every((e, i) => e === b[i]);
|
|
@@ -1807,6 +1861,7 @@ class FacetProvider {
|
|
|
1807
1861
|
this.flags = flags;
|
|
1808
1862
|
this.value = value;
|
|
1809
1863
|
}
|
|
1864
|
+
toString() { return `${this.facet}(${this.flags & 1 ? debugString(this.value) : "dynamic"})`; }
|
|
1810
1865
|
}
|
|
1811
1866
|
function compareArray(a, b, compare) {
|
|
1812
1867
|
if (a.length != b.length)
|
|
@@ -1896,8 +1951,10 @@ class CompartmentInstance {
|
|
|
1896
1951
|
this.inner = inner;
|
|
1897
1952
|
}
|
|
1898
1953
|
extension;
|
|
1954
|
+
toString() { return `${this.compartment}(${this.inner})`; }
|
|
1899
1955
|
}
|
|
1900
1956
|
GardSelection = /*@__PURE__*/(GardSelection => {GardSelection.selectionType = GardState.Facet.define({
|
|
1957
|
+
name: "selectionType",
|
|
1901
1958
|
combine(values) {
|
|
1902
1959
|
let types = [GardSelection.Text.type, GardSelection.Node.type, ...values];
|
|
1903
1960
|
for (let i = 0; i < types.length; i++)
|
|
@@ -1909,8 +1966,8 @@ GardSelection = /*@__PURE__*/(GardSelection => {GardSelection.selectionType = Ga
|
|
|
1909
1966
|
},
|
|
1910
1967
|
static: true
|
|
1911
1968
|
}); return GardSelection})(GardSelection);
|
|
1912
|
-
Transaction = /*@__PURE__*/(Transaction => {Transaction.extender = GardState.Facet.define(); return Transaction})(Transaction);
|
|
1913
|
-
Transaction = /*@__PURE__*/(Transaction => {Transaction.appender = GardState.Facet.define(); return Transaction})(Transaction);
|
|
1969
|
+
Transaction = /*@__PURE__*/(Transaction => {Transaction.extender = GardState.Facet.define({ name: "extender" }); return Transaction})(Transaction);
|
|
1970
|
+
Transaction = /*@__PURE__*/(Transaction => {Transaction.appender = GardState.Facet.define({ name: "appender" }); return Transaction})(Transaction);
|
|
1914
1971
|
|
|
1915
1972
|
function scanChanges(changes, doc, corrections) {
|
|
1916
1973
|
let buckets = [[], [], []], [childList, content, marks] = buckets;
|
|
@@ -2003,7 +2060,7 @@ function scanChanges(changes, doc, corrections) {
|
|
|
2003
2060
|
}
|
|
2004
2061
|
return plan;
|
|
2005
2062
|
}
|
|
2006
|
-
const corrections = /*@__PURE__*/GardState.Facet.define();
|
|
2063
|
+
const corrections = /*@__PURE__*/GardState.Facet.define({ name: "corrections" });
|
|
2007
2064
|
const planCache = /*@__PURE__*/(() => new WeakMap())();
|
|
2008
2065
|
class Correction {
|
|
2009
2066
|
event;
|
|
@@ -2072,6 +2129,7 @@ class Correction {
|
|
|
2072
2129
|
}
|
|
2073
2130
|
return changed.length ? ChangeSet.create(doc, changed) : null;
|
|
2074
2131
|
}
|
|
2132
|
+
toString() { return `Correction(${Node.queryToString(this.query)})`; }
|
|
2075
2133
|
}
|
|
2076
2134
|
|
|
2077
2135
|
export { BidiSpan, Correction, GardSelection, GardState, TextblockMap, Transaction };
|
package/dist/table.d.ts
CHANGED
|
@@ -175,6 +175,116 @@ declare class CellSelection extends GardSelection {
|
|
|
175
175
|
static extension: GardState.Extension;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
/**
|
|
179
|
+
A table map describes the structore of a given table.
|
|
180
|
+
*/
|
|
181
|
+
declare class TableMap {
|
|
182
|
+
/**
|
|
183
|
+
The start position of the table's content.
|
|
184
|
+
*/
|
|
185
|
+
readonly start: number;
|
|
186
|
+
/**
|
|
187
|
+
Get a table map for the given table node. Will reuse known
|
|
188
|
+
structure of unchanged tables across document changes.
|
|
189
|
+
*/
|
|
190
|
+
static get(table: Plot, start: number): TableMap;
|
|
191
|
+
private constructor();
|
|
192
|
+
/**
|
|
193
|
+
The number of columns in this table.
|
|
194
|
+
*/
|
|
195
|
+
get width(): number;
|
|
196
|
+
/**
|
|
197
|
+
The number of rows in the table.
|
|
198
|
+
*/
|
|
199
|
+
get height(): number;
|
|
200
|
+
/**
|
|
201
|
+
The table plot.
|
|
202
|
+
*/
|
|
203
|
+
get table(): Plot;
|
|
204
|
+
/**
|
|
205
|
+
The document position before the table.
|
|
206
|
+
*/
|
|
207
|
+
get tablePos(): number;
|
|
208
|
+
/**
|
|
209
|
+
Find the dimensions of the cell at the given position.
|
|
210
|
+
*/
|
|
211
|
+
cellRect(pos: number): TableMap.Rect;
|
|
212
|
+
/**
|
|
213
|
+
Find the end position of the given cell.
|
|
214
|
+
*/
|
|
215
|
+
cellEnd(pos: number): number;
|
|
216
|
+
/**
|
|
217
|
+
Get the rectangle spanning the two given cells.
|
|
218
|
+
*/
|
|
219
|
+
rectBetween(a: number, b: number): TableMap.Rect;
|
|
220
|
+
/**
|
|
221
|
+
Return the position of all cells that have their top start
|
|
222
|
+
corner in the given rectangle.
|
|
223
|
+
*/
|
|
224
|
+
cellsInRect(rect: TableMap.Rect): number[];
|
|
225
|
+
/**
|
|
226
|
+
Return the position of the cell that occupies the position at the
|
|
227
|
+
given row and column (which must be in bounds for the table).
|
|
228
|
+
*/
|
|
229
|
+
cellAt(col: number, row: number): number | null;
|
|
230
|
+
/**
|
|
231
|
+
Get the position at the start of the given row (which may be
|
|
232
|
+
`width` to query the position after the last row).
|
|
233
|
+
*/
|
|
234
|
+
rowPos(row: number): number;
|
|
235
|
+
/**
|
|
236
|
+
Get the position where a cell would have to be inserted to
|
|
237
|
+
appear at the given column and row.
|
|
238
|
+
*/
|
|
239
|
+
cellInsertionPos(col: number, row: number): number;
|
|
240
|
+
/**
|
|
241
|
+
Get the node for the cell at the given position.
|
|
242
|
+
*/
|
|
243
|
+
getCell(pos: number): Plot;
|
|
244
|
+
}
|
|
245
|
+
declare namespace TableMap {
|
|
246
|
+
/**
|
|
247
|
+
Data type used for a rectangular area in a table.
|
|
248
|
+
*/
|
|
249
|
+
class Rect {
|
|
250
|
+
/**
|
|
251
|
+
Starting column of the rectangle.
|
|
252
|
+
*/
|
|
253
|
+
readonly startCol: number;
|
|
254
|
+
/**
|
|
255
|
+
Starting row.
|
|
256
|
+
*/
|
|
257
|
+
readonly startRow: number;
|
|
258
|
+
/**
|
|
259
|
+
The end column. Non-inclusive. Always higher than
|
|
260
|
+
`startCol`.
|
|
261
|
+
*/
|
|
262
|
+
readonly endCol: number;
|
|
263
|
+
/**
|
|
264
|
+
The end row. Non-inclusive. Always higher than `startRow`.
|
|
265
|
+
*/
|
|
266
|
+
readonly endRow: number;
|
|
267
|
+
constructor(
|
|
268
|
+
/**
|
|
269
|
+
Starting column of the rectangle.
|
|
270
|
+
*/
|
|
271
|
+
startCol: number,
|
|
272
|
+
/**
|
|
273
|
+
Starting row.
|
|
274
|
+
*/
|
|
275
|
+
startRow: number,
|
|
276
|
+
/**
|
|
277
|
+
The end column. Non-inclusive. Always higher than
|
|
278
|
+
`startCol`.
|
|
279
|
+
*/
|
|
280
|
+
endCol: number,
|
|
281
|
+
/**
|
|
282
|
+
The end row. Non-inclusive. Always higher than `startRow`.
|
|
283
|
+
*/
|
|
284
|
+
endRow: number);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
178
288
|
declare const toggleHeaderCell: Command.Pure;
|
|
179
289
|
/**
|
|
180
290
|
Add a column at the given side of the selection. The selection may
|
|
@@ -213,4 +323,4 @@ declare const splitCell: Command.Pure;
|
|
|
213
323
|
*/
|
|
214
324
|
declare function handleTablePaste(state: GardState, slice: Slice, drop?: number): false | Transaction.Spec;
|
|
215
325
|
|
|
216
|
-
export { CellSelection, addColumn, addRow, deleteColumn, deleteRow, handleTablePaste, mergeCells, splitCell, tableMenu, tables, toggleHeaderCell };
|
|
326
|
+
export { CellSelection, TableMap, addColumn, addRow, deleteColumn, deleteRow, handleTablePaste, mergeCells, splitCell, tableMenu, tables, toggleHeaderCell };
|
package/dist/table.js
CHANGED
|
@@ -5,18 +5,6 @@ import { Node, Slice, ValidationError, Token, ChangeSet } from 'wordgard/doc';
|
|
|
5
5
|
import { Command, moveByUnit, moveByWord, moveByLine, moveToLineSide, Menu } from 'wordgard/command';
|
|
6
6
|
import { tablePhrases } from 'wordgard/phrases';
|
|
7
7
|
|
|
8
|
-
class Rect {
|
|
9
|
-
startCol;
|
|
10
|
-
startRow;
|
|
11
|
-
endCol;
|
|
12
|
-
endRow;
|
|
13
|
-
constructor(startCol, startRow, endCol, endRow) {
|
|
14
|
-
this.startCol = startCol;
|
|
15
|
-
this.startRow = startRow;
|
|
16
|
-
this.endCol = endCol;
|
|
17
|
-
this.endRow = endRow;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
8
|
class MapData {
|
|
21
9
|
table;
|
|
22
10
|
width;
|
|
@@ -37,7 +25,15 @@ let cache = /*@__PURE__*/(() => new WeakMap())();
|
|
|
37
25
|
class TableMap {
|
|
38
26
|
start;
|
|
39
27
|
data;
|
|
40
|
-
|
|
28
|
+
static get(table, start) {
|
|
29
|
+
let data = cache.get(table);
|
|
30
|
+
if (!data)
|
|
31
|
+
cache.set(table, data = computeMap(table));
|
|
32
|
+
return new TableMap(start, data);
|
|
33
|
+
}
|
|
34
|
+
constructor(
|
|
35
|
+
start,
|
|
36
|
+
data) {
|
|
41
37
|
this.start = start;
|
|
42
38
|
this.data = data;
|
|
43
39
|
}
|
|
@@ -55,7 +51,7 @@ class TableMap {
|
|
|
55
51
|
endCol++;
|
|
56
52
|
for (let j = 1; endRow < height && map[i + (width * j)] == localPos; j++)
|
|
57
53
|
endRow++;
|
|
58
|
-
return new Rect(startCol, startRow, endCol, endRow);
|
|
54
|
+
return new TableMap.Rect(startCol, startRow, endCol, endRow);
|
|
59
55
|
}
|
|
60
56
|
throw new RangeError(`No cell with offset ${pos} found`);
|
|
61
57
|
}
|
|
@@ -87,7 +83,7 @@ class TableMap {
|
|
|
87
83
|
rectBetween(a, b) {
|
|
88
84
|
let { startCol: startColA, endCol: endColA, startRow: startRowA, endRow: endRowA } = this.cellRect(a);
|
|
89
85
|
let { startCol: startColB, endCol: endColB, startRow: startRowB, endRow: endRowB } = this.cellRect(b);
|
|
90
|
-
return new Rect(Math.min(startColA, startColB), Math.min(startRowA, startRowB), Math.max(endColA, endColB), Math.max(endRowA, endRowB));
|
|
86
|
+
return new TableMap.Rect(Math.min(startColA, startColB), Math.min(startRowA, startRowB), Math.max(endColA, endColB), Math.max(endRowA, endRowB));
|
|
91
87
|
}
|
|
92
88
|
cellsInRect(rect) {
|
|
93
89
|
let result = [], { map, width } = this.data;
|
|
@@ -148,13 +144,26 @@ class TableMap {
|
|
|
148
144
|
}
|
|
149
145
|
return false;
|
|
150
146
|
}
|
|
151
|
-
static get(table, start) {
|
|
152
|
-
let data = cache.get(table);
|
|
153
|
-
if (!data)
|
|
154
|
-
cache.set(table, data = computeMap(table));
|
|
155
|
-
return new TableMap(start, data);
|
|
156
|
-
}
|
|
157
147
|
}
|
|
148
|
+
;TableMap = /*@__PURE__*/(function (TableMap) {
|
|
149
|
+
class Rect {
|
|
150
|
+
startCol;
|
|
151
|
+
startRow;
|
|
152
|
+
endCol;
|
|
153
|
+
endRow;
|
|
154
|
+
constructor(
|
|
155
|
+
startCol,
|
|
156
|
+
startRow,
|
|
157
|
+
endCol,
|
|
158
|
+
endRow) {
|
|
159
|
+
this.startCol = startCol;
|
|
160
|
+
this.startRow = startRow;
|
|
161
|
+
this.endCol = endCol;
|
|
162
|
+
this.endRow = endRow;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
TableMap.Rect = Rect;
|
|
166
|
+
;return TableMap})(TableMap);
|
|
158
167
|
function sameCell(a, b) {
|
|
159
168
|
return a != 0 && a == b;
|
|
160
169
|
}
|
|
@@ -227,6 +236,7 @@ function growMap(map, width, height, count) {
|
|
|
227
236
|
}
|
|
228
237
|
|
|
229
238
|
const cellSelectionDeco = /*@__PURE__*/GardState.Field.define({
|
|
239
|
+
name: "cellSelectionDeco",
|
|
230
240
|
create: getCellDeco,
|
|
231
241
|
update: (deco, tr) => {
|
|
232
242
|
return tr.docChanged || tr.selection ? getCellDeco(tr.state) : deco;
|
|
@@ -1318,4 +1328,4 @@ function tables(config = {}) {
|
|
|
1318
1328
|
tables.dropHandler = tableDropHandler;
|
|
1319
1329
|
;return tables})(tables);
|
|
1320
1330
|
|
|
1321
|
-
export { CellSelection, addColumn, addRow, deleteColumn, deleteRow, handleTablePaste, mergeCells, splitCell, tableMenu, tables, toggleHeaderCell };
|
|
1331
|
+
export { CellSelection, TableMap, addColumn, addRow, deleteColumn, deleteRow, handleTablePaste, mergeCells, splitCell, tableMenu, tables, toggleHeaderCell };
|