@nerd-bible/wordgard 0.6.2-beta6 → 0.6.2-beta8
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.d.ts +15 -7
- package/dist/command.js +20 -5
- package/dist/doc.js +35 -6
- package/dist/editor.d.ts +3 -2
- package/dist/editor.js +28 -18
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/table.d.ts +111 -1
- package/dist/table.js +31 -22
- package/package.json +1 -1
package/dist/command.d.ts
CHANGED
|
@@ -518,10 +518,10 @@ declare const enter: Command.Pure;
|
|
|
518
518
|
/**
|
|
519
519
|
Delete the selection, or the unit after or before the selection.
|
|
520
520
|
If that unit is the start or end of a textblock, this will try to
|
|
521
|
-
join that textblock to the next one. Otherwise, if
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
521
|
+
join that textblock to the next one. Otherwise, if the cursor is
|
|
522
|
+
in an empty textblock, this will delete the textblock. Finally, if
|
|
523
|
+
there is a character or leaf node in the given direction, that is
|
|
524
|
+
deleted.
|
|
525
525
|
|
|
526
526
|
When deleting backward at the start of a list item that has a
|
|
527
527
|
sibling before it, this command will try to join those list items.
|
|
@@ -709,9 +709,17 @@ declare const redo: Command;
|
|
|
709
709
|
|
|
710
710
|
/**
|
|
711
711
|
If the cursor is in an empty textblock that can be lifted out of a
|
|
712
|
-
parent, return a transaction that does this.
|
|
712
|
+
parent, return a transaction that does this. Unless
|
|
713
|
+
`splitListItem` is set to false, if the block is part of a
|
|
714
|
+
continued list item, this function will split the item above the
|
|
715
|
+
block before it lifts it.
|
|
713
716
|
*/
|
|
714
|
-
declare function liftEmptyBlock(state: GardState): Transaction.Spec | false;
|
|
717
|
+
declare function liftEmptyBlock(state: GardState, splitListItem?: boolean): Transaction.Spec | false;
|
|
718
|
+
/**
|
|
719
|
+
Lift the textblock that the cursor is at the start of out of its
|
|
720
|
+
innermost parent, if possible.
|
|
721
|
+
*/
|
|
722
|
+
declare function liftTextblock(state: GardState): Transaction.Spec | false;
|
|
715
723
|
/**
|
|
716
724
|
If the selection is in a {@link Plot.Spec.preserveWhitespace
|
|
717
725
|
`preserveWhitespace`} textblock, replace the selected content with
|
|
@@ -823,4 +831,4 @@ updated to perform those joins.
|
|
|
823
831
|
*/
|
|
824
832
|
declare function autoJoinBlocks(state: GardState, tr: Transaction.Spec): Transaction.Spec;
|
|
825
833
|
|
|
826
|
-
export { Command, Menu, autoJoinBlocks, canAddMarkInRange, clearNonFitting, deleteBackward, deleteEmptyPlot, deleteForward, deleteLine, deleteSelection, deleteToLineEnd, deleteUnit, deleteWord, doUnwrapBlock, enter, enterInCode, findUnwrappable, findWrappable, insertLineBreak, insertText, joinBackward, joinBlocks, joinForward, joinListItems, killToLineEnd, liftEmptyBlock, listIsActive, moveByLine, moveByPage, moveByUnit, moveByWord, moveToDocSide, moveToLineSide, moveToTextblockSide, redo, selectAll, selectedTextblocks, setAlignment, setDirection, setTextblockType, splitTextblock, toggleBlock, toggleEmphasis, toggleList, toggleMark, toggleStrong, toggleUnderline, transposeChars, undo, unwrapBlock, wrapBlock, wrapBlockRange, yankKilled };
|
|
834
|
+
export { Command, Menu, autoJoinBlocks, canAddMarkInRange, clearNonFitting, deleteBackward, deleteEmptyPlot, deleteForward, deleteLine, deleteSelection, deleteToLineEnd, deleteUnit, deleteWord, doUnwrapBlock, enter, enterInCode, findUnwrappable, findWrappable, insertLineBreak, insertText, joinBackward, joinBlocks, joinForward, joinListItems, killToLineEnd, liftEmptyBlock, liftTextblock, listIsActive, moveByLine, moveByPage, moveByUnit, moveByWord, moveToDocSide, moveToLineSide, moveToTextblockSide, redo, selectAll, selectedTextblocks, setAlignment, setDirection, setTextblockType, splitTextblock, toggleBlock, toggleEmphasis, toggleList, toggleMark, toggleStrong, toggleUnderline, transposeChars, undo, unwrapBlock, wrapBlock, wrapBlockRange, yankKilled };
|
package/dist/command.js
CHANGED
|
@@ -45,12 +45,27 @@ const Command = /*@__PURE__*/(function (Command) {
|
|
|
45
45
|
Command.dispatch = dispatch;
|
|
46
46
|
;return Command})({});
|
|
47
47
|
|
|
48
|
-
function liftEmptyBlock(state) {
|
|
48
|
+
function liftEmptyBlock(state, splitListItem = true) {
|
|
49
49
|
if (!state.selection.isCursor)
|
|
50
50
|
return false;
|
|
51
51
|
let sel = state.sel, block = sel.head.textblockParent;
|
|
52
52
|
if (!block || !sel.head.isAtStart(block) || !sel.head.isAtEnd(block))
|
|
53
53
|
return false;
|
|
54
|
+
if (splitListItem && block.parent?.parent && block.index && block.parent.parent.node.type.hasRole(Node.Role.List))
|
|
55
|
+
return {
|
|
56
|
+
changes: { from: block.before, insert: [Plot.End, block.parent.node.tag] },
|
|
57
|
+
scrollIntoView: true,
|
|
58
|
+
userEvent: "split.list"
|
|
59
|
+
};
|
|
60
|
+
return liftBlock(state, block);
|
|
61
|
+
}
|
|
62
|
+
function liftTextblock(state) {
|
|
63
|
+
if (!state.selection.isCursor)
|
|
64
|
+
return false;
|
|
65
|
+
let { head } = state.sel, block = head.textblockParent;
|
|
66
|
+
return !block || !head.isAtStart(block) ? false : liftBlock(state, block);
|
|
67
|
+
}
|
|
68
|
+
function liftBlock(state, block) {
|
|
54
69
|
let start = block.before, end = block.after, before = [], after = [];
|
|
55
70
|
for (let level = block.parent, index = block.index, atStart = true, atEnd = true, first = true; level; first = false, index = level.index, level = level.parent) {
|
|
56
71
|
if (!first && state.schema.canContain(level.node.type, block.node.type))
|
|
@@ -60,7 +75,7 @@ function liftEmptyBlock(state) {
|
|
|
60
75
|
{ from: block.after, to: end, insert: after }
|
|
61
76
|
],
|
|
62
77
|
scrollIntoView: true,
|
|
63
|
-
userEvent: "unwrap
|
|
78
|
+
userEvent: "unwrap"
|
|
64
79
|
};
|
|
65
80
|
if (level.node.isInline || level.node.type.isolating)
|
|
66
81
|
break;
|
|
@@ -792,8 +807,8 @@ const deleteUnit = ({ state }, dir) => {
|
|
|
792
807
|
if (state.readOnly)
|
|
793
808
|
return false;
|
|
794
809
|
return deleteSelection(state) || (dir == "forward"
|
|
795
|
-
? joinForward(state) ||
|
|
796
|
-
: joinListItems(state) ||
|
|
810
|
+
? joinForward(state) || deleteEmptyPlot(state, 1) || deleteForward(state)
|
|
811
|
+
: joinListItems(state) || liftTextblock(state) || joinBackward(state) || deleteEmptyPlot(state, -1) || deleteBackward(state));
|
|
797
812
|
};
|
|
798
813
|
const deleteWord = ({ state }, dir) => {
|
|
799
814
|
if (state.readOnly)
|
|
@@ -1541,4 +1556,4 @@ const Menu = /*@__PURE__*/(function (Menu) {
|
|
|
1541
1556
|
Menu.resolve = resolve;
|
|
1542
1557
|
;return Menu})({});
|
|
1543
1558
|
|
|
1544
|
-
export { Command, Menu, autoJoinBlocks, canAddMarkInRange, clearNonFitting, deleteBackward, deleteEmptyPlot, deleteForward, deleteLine, deleteSelection, deleteToLineEnd, deleteUnit, deleteWord, doUnwrapBlock, enter, enterInCode, findUnwrappable, findWrappable, insertLineBreak, insertText, joinBackward, joinBlocks, joinForward, joinListItems, killToLineEnd, liftEmptyBlock, listIsActive, moveByLine, moveByPage, moveByUnit, moveByWord, moveToDocSide, moveToLineSide, moveToTextblockSide, redo, selectAll, selectedTextblocks, setAlignment, setDirection, setTextblockType, splitTextblock, toggleBlock, toggleEmphasis, toggleList, toggleMark, toggleStrong, toggleUnderline, transposeChars, undo, unwrapBlock, wrapBlock, wrapBlockRange, yankKilled };
|
|
1559
|
+
export { Command, Menu, autoJoinBlocks, canAddMarkInRange, clearNonFitting, deleteBackward, deleteEmptyPlot, deleteForward, deleteLine, deleteSelection, deleteToLineEnd, deleteUnit, deleteWord, doUnwrapBlock, enter, enterInCode, findUnwrappable, findWrappable, insertLineBreak, insertText, joinBackward, joinBlocks, joinForward, joinListItems, killToLineEnd, liftEmptyBlock, liftTextblock, listIsActive, moveByLine, moveByPage, moveByUnit, moveByWord, moveToDocSide, moveToLineSide, moveToTextblockSide, redo, selectAll, selectedTextblocks, setAlignment, setDirection, setTextblockType, splitTextblock, toggleBlock, toggleEmphasis, toggleList, toggleMark, toggleStrong, toggleUnderline, transposeChars, undo, unwrapBlock, wrapBlock, wrapBlockRange, yankKilled };
|
package/dist/doc.js
CHANGED
|
@@ -412,7 +412,7 @@ const Attributes = /*@__PURE__*/(function (Attributes) {
|
|
|
412
412
|
score--;
|
|
413
413
|
iA += 2;
|
|
414
414
|
}
|
|
415
|
-
else if (iB < b.length
|
|
415
|
+
else if (iB < b.length) {
|
|
416
416
|
score--;
|
|
417
417
|
iB += 2;
|
|
418
418
|
}
|
|
@@ -1392,6 +1392,8 @@ class Plot {
|
|
|
1392
1392
|
constructor(type, param, marks) {
|
|
1393
1393
|
super(param, marks);
|
|
1394
1394
|
this.type = type;
|
|
1395
|
+
if (this.type.isDoc && marks.length)
|
|
1396
|
+
throw new Error("Document nodes cannot have marks");
|
|
1395
1397
|
}
|
|
1396
1398
|
static new(type, param, marks) {
|
|
1397
1399
|
return new Tag(type, param, marks);
|
|
@@ -2399,6 +2401,36 @@ class ChangeSetBuilder {
|
|
|
2399
2401
|
sections = [];
|
|
2400
2402
|
data = [];
|
|
2401
2403
|
pos = 0;
|
|
2404
|
+
addSection(from, to, ins, value) {
|
|
2405
|
+
if (from >= this.pos) {
|
|
2406
|
+
addSection(this.sections, this.data, from - this.pos, -1, null);
|
|
2407
|
+
addSection(this.sections, this.data, to - from, ins, value);
|
|
2408
|
+
this.pos = to;
|
|
2409
|
+
return true;
|
|
2410
|
+
}
|
|
2411
|
+
if (this.sections.length && this.sections[0] > to && this.sections[1] == -1) {
|
|
2412
|
+
this.spliceSection(0, from, to, ins, value);
|
|
2413
|
+
return true;
|
|
2414
|
+
}
|
|
2415
|
+
for (let pos = this.pos, i = this.sections.length; i > 2 && pos > to;) {
|
|
2416
|
+
let nextIns = this.sections[--i], nextLen = this.sections[--i];
|
|
2417
|
+
let start = pos - nextLen;
|
|
2418
|
+
if (nextIns == -1 && start < from) {
|
|
2419
|
+
this.spliceSection(i, from - start, to - start, ins, value);
|
|
2420
|
+
return true;
|
|
2421
|
+
}
|
|
2422
|
+
pos = start;
|
|
2423
|
+
}
|
|
2424
|
+
return false;
|
|
2425
|
+
}
|
|
2426
|
+
spliceSection(i, from, to, ins, value) {
|
|
2427
|
+
let sections = [], data = [];
|
|
2428
|
+
addSection(sections, data, from, -1, null);
|
|
2429
|
+
addSection(sections, data, to - from, ins, value);
|
|
2430
|
+
addSection(sections, data, this.sections[i] - to, -1, null);
|
|
2431
|
+
this.sections.splice(i, 2, ...sections);
|
|
2432
|
+
this.data.splice(i >> 1, 1, ...data);
|
|
2433
|
+
}
|
|
2402
2434
|
}
|
|
2403
2435
|
function sliceLen(tokens) {
|
|
2404
2436
|
return tokens.reduce((l, e) => l + (e.tokenType == Token.Type.Node ? e.length : 1), 0);
|
|
@@ -2419,14 +2451,11 @@ function createChangeSet(doc, spec, mayCorrect = true) {
|
|
|
2419
2451
|
accum = accum ? accum.compose(transform(set, accum, doc, false, false).set) : set;
|
|
2420
2452
|
};
|
|
2421
2453
|
let section = (from, to, ins, value) => {
|
|
2422
|
-
if (!cur
|
|
2454
|
+
if (!cur?.addSection(from, to, ins, value)) {
|
|
2423
2455
|
flush();
|
|
2424
2456
|
cur = new ChangeSetBuilder(doc.length);
|
|
2457
|
+
cur.addSection(from, to, ins, value);
|
|
2425
2458
|
}
|
|
2426
|
-
if (from > cur.pos)
|
|
2427
|
-
addSection(cur.sections, cur.data, from - cur.pos, -1, null);
|
|
2428
|
-
addSection(cur.sections, cur.data, to - from, ins, value);
|
|
2429
|
-
cur.pos = to;
|
|
2430
2459
|
};
|
|
2431
2460
|
let build = (spec) => {
|
|
2432
2461
|
if (Array.isArray(spec)) {
|
package/dist/editor.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { PointSet, Set, RangeSet } from 'wordgard/set';
|
|
|
8
8
|
|
|
9
9
|
type MakeSelectionStyle = (wg: Wordgard, event: MouseEvent) => Wordgard.MouseSelectionStyle | null;
|
|
10
10
|
|
|
11
|
+
import Mark_ = Mark;
|
|
11
12
|
/**
|
|
12
13
|
A widget describes a piece of DOM content that can be used to
|
|
13
14
|
render a node, a part of a node, or an extra element added via a
|
|
@@ -193,8 +194,8 @@ declare namespace Decoration {
|
|
|
193
194
|
/**
|
|
194
195
|
Override the shape used for a given mark inside the editor.
|
|
195
196
|
*/
|
|
196
|
-
function shape<V>(type:
|
|
197
|
-
function shape(mark:
|
|
197
|
+
function shape<V>(type: Mark_.Type<V>, shape: Shape.Element<V> | Shape.Attribute<V> | Shape.Attributes<V>): GardState.Extension;
|
|
198
|
+
function shape(mark: Mark_<null>, shape: Shape.Element<null> | Shape.Attribute<null> | Shape.Attributes<null>): GardState.Extension;
|
|
198
199
|
}
|
|
199
200
|
/**
|
|
200
201
|
A point decoration is a decoration that targets a given position
|
package/dist/editor.js
CHANGED
|
@@ -132,6 +132,7 @@ function joinRanges(ranges) {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
var Mark_ = Mark;
|
|
135
136
|
class Widget {
|
|
136
137
|
value;
|
|
137
138
|
constructor(type,
|
|
@@ -286,15 +287,15 @@ const Decoration = /*@__PURE__*/(function (Decoration) {
|
|
|
286
287
|
}
|
|
287
288
|
Tag.attribute = attribute;
|
|
288
289
|
})(Decoration.Tag || (Decoration.Tag = {}));
|
|
289
|
-
(function (Mark
|
|
290
|
+
(function (Mark) {
|
|
290
291
|
function shape(type, shape) {
|
|
291
|
-
if (type instanceof
|
|
292
|
+
if (type instanceof Mark_)
|
|
292
293
|
type = type.type;
|
|
293
294
|
if (type.spanning && !("element" in shape))
|
|
294
295
|
throw new Error("Spanning marks must have an element shape");
|
|
295
|
-
return markShape.of({ type, modified:
|
|
296
|
+
return markShape.of({ type, modified: Mark_.Type.define(type.name, { ...type.spec, shape }) });
|
|
296
297
|
}
|
|
297
|
-
Mark
|
|
298
|
+
Mark.shape = shape;
|
|
298
299
|
})(Decoration.Mark || (Decoration.Mark = {}));
|
|
299
300
|
class Point {
|
|
300
301
|
constructor() { }
|
|
@@ -743,7 +744,7 @@ class DecoIterator {
|
|
|
743
744
|
else
|
|
744
745
|
started = true;
|
|
745
746
|
let hasPending = pendingPos == pos && !node.isText;
|
|
746
|
-
let shape =
|
|
747
|
+
let shape = this.tagShape(node.tag, iter.active, hasPending ? pendingShape : null);
|
|
747
748
|
if (hasPending)
|
|
748
749
|
for (let deco of pendingDeco)
|
|
749
750
|
shape = applyDeco(shape, deco, node.tag);
|
|
@@ -757,22 +758,23 @@ class DecoIterator {
|
|
|
757
758
|
this.widgets(node.tag, 0, walker);
|
|
758
759
|
else
|
|
759
760
|
started = true;
|
|
760
|
-
let shape = pendingShape && pendingPos == pos ? pendingShape
|
|
761
|
-
: this.tagShape(node.tag, iter.active);
|
|
761
|
+
let shape = this.tagShape(node.tag, iter.active, pendingShape && pendingPos == pos ? pendingShape : null);
|
|
762
762
|
if (pendingPos == pos)
|
|
763
763
|
for (let deco of pendingDeco)
|
|
764
764
|
shape = applyDeco(shape, deco, node.tag);
|
|
765
765
|
let wrappers = this.nodeWrappers(node.tag, iter.active, !shape.hasContent);
|
|
766
766
|
let atom = !shape.hasContent;
|
|
767
|
-
if (atom)
|
|
767
|
+
if (atom) {
|
|
768
768
|
walker.node(node, shape, wrappers, pos + node.length > to ? to - pos : undefined);
|
|
769
|
-
|
|
769
|
+
}
|
|
770
|
+
else {
|
|
770
771
|
walker.enter(node, shape, wrappers);
|
|
771
|
-
|
|
772
|
+
this.widgets(node.tag, 2, walker);
|
|
773
|
+
}
|
|
772
774
|
return !atom;
|
|
773
775
|
},
|
|
774
776
|
leavePlot: tag => {
|
|
775
|
-
if (started)
|
|
777
|
+
if (started && !atomParent)
|
|
776
778
|
this.widgets(tag, 3, walker);
|
|
777
779
|
else
|
|
778
780
|
started = true;
|
|
@@ -780,7 +782,7 @@ class DecoIterator {
|
|
|
780
782
|
this.widgets(tag, 1, walker);
|
|
781
783
|
}
|
|
782
784
|
};
|
|
783
|
-
if (inclusiveStart) {
|
|
785
|
+
if (inclusiveStart && !atomParent) {
|
|
784
786
|
let before = pos.nodeBefore;
|
|
785
787
|
if (before)
|
|
786
788
|
this.widgets(before.tag, 1, walker);
|
|
@@ -792,9 +794,10 @@ class DecoIterator {
|
|
|
792
794
|
let end = Math.min(to, atomParent.after), done = atomParent.after <= to;
|
|
793
795
|
walker.nodePart(atomParent.node, end - pos.pos, done);
|
|
794
796
|
pos = pos.advance(end - pos.pos);
|
|
795
|
-
if (done)
|
|
797
|
+
if (done) {
|
|
796
798
|
this.widgets(atomParent.node.tag, 1, walker);
|
|
797
|
-
|
|
799
|
+
atomParent = undefined;
|
|
800
|
+
}
|
|
798
801
|
while (iter.point && iter.from < end)
|
|
799
802
|
iter.next();
|
|
800
803
|
}
|
|
@@ -837,9 +840,8 @@ class DecoIterator {
|
|
|
837
840
|
}
|
|
838
841
|
this.pos = pos;
|
|
839
842
|
}
|
|
840
|
-
tagShape(tag, active) {
|
|
841
|
-
let
|
|
842
|
-
let shape = override ? override(tag) : baseTagShape(tag);
|
|
843
|
+
tagShape(tag, active, fromPoint) {
|
|
844
|
+
let shape = fromPoint ? fromPoint.shape : this.tagShapes.get(tag.type)?.(tag) ?? baseTagShape(tag);
|
|
843
845
|
if (tag.marks.length)
|
|
844
846
|
shape = addMarkAttributes(this.markShapes, shape, tag);
|
|
845
847
|
let add;
|
|
@@ -2084,6 +2086,9 @@ class ContentUpdate {
|
|
|
2084
2086
|
this.partialNode = null;
|
|
2085
2087
|
this.new.addChild(this.buildNodeShape(tag, length + (to - from), shape, reuse));
|
|
2086
2088
|
}
|
|
2089
|
+
else {
|
|
2090
|
+
this.partialNode.length += to - from;
|
|
2091
|
+
}
|
|
2087
2092
|
}
|
|
2088
2093
|
}
|
|
2089
2094
|
else if (this.new.lastChild instanceof TextTile && !this.new.lastChild.isComposition) {
|
|
@@ -2297,6 +2302,9 @@ class ContentUpdate {
|
|
|
2297
2302
|
for (let i = 0; i < wrappers; i++)
|
|
2298
2303
|
this.up();
|
|
2299
2304
|
}
|
|
2305
|
+
else {
|
|
2306
|
+
this.partialNode.length += length;
|
|
2307
|
+
}
|
|
2300
2308
|
},
|
|
2301
2309
|
widget: (widget, side) => {
|
|
2302
2310
|
let sideFlag = side < 0 ? 32 : side > 0 ? 64 : 0;
|
|
@@ -2532,8 +2540,10 @@ class ContentUpdate {
|
|
|
2532
2540
|
prev = copy;
|
|
2533
2541
|
prev.parent = cur;
|
|
2534
2542
|
}
|
|
2535
|
-
for (let j = i + 1; j < cur.children.length; j++)
|
|
2543
|
+
for (let j = i + 1; j < cur.children.length; j++) {
|
|
2536
2544
|
prev.addChild(cur.children[j]);
|
|
2545
|
+
cur.children.splice(j, 1);
|
|
2546
|
+
}
|
|
2537
2547
|
return prev;
|
|
2538
2548
|
}
|
|
2539
2549
|
return null;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export * as collab from "wordgard/collab"
|
|
|
2
2
|
export * as command from "wordgard/command"
|
|
3
3
|
export * as doc from "wordgard/doc"
|
|
4
4
|
export * as editor from "wordgard/editor"
|
|
5
|
-
export * as
|
|
5
|
+
export * as highlightCode from "wordgard/highlight-code"
|
|
6
6
|
export * as history from "wordgard/history"
|
|
7
7
|
export * as phrases from "wordgard/phrases"
|
|
8
8
|
export * as schema from "wordgard/schema"
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export * as collab from "wordgard/collab"
|
|
|
2
2
|
export * as command from "wordgard/command"
|
|
3
3
|
export * as doc from "wordgard/doc"
|
|
4
4
|
export * as editor from "wordgard/editor"
|
|
5
|
-
export * as
|
|
5
|
+
export * as highlightCode from "wordgard/highlight-code"
|
|
6
6
|
export * as history from "wordgard/history"
|
|
7
7
|
export * as phrases from "wordgard/phrases"
|
|
8
8
|
export * as schema from "wordgard/schema"
|
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
|
}
|
|
@@ -1318,4 +1327,4 @@ function tables(config = {}) {
|
|
|
1318
1327
|
tables.dropHandler = tableDropHandler;
|
|
1319
1328
|
;return tables})(tables);
|
|
1320
1329
|
|
|
1321
|
-
export { CellSelection, addColumn, addRow, deleteColumn, deleteRow, handleTablePaste, mergeCells, splitCell, tableMenu, tables, toggleHeaderCell };
|
|
1330
|
+
export { CellSelection, TableMap, addColumn, addRow, deleteColumn, deleteRow, handleTablePaste, mergeCells, splitCell, tableMenu, tables, toggleHeaderCell };
|