@nerd-bible/wordgard 0.5.3-beta7 → 0.6.2-beta10
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 +38 -18
- package/dist/doc.d.ts +58 -50
- package/dist/doc.js +224 -169
- package/dist/editor.d.ts +212 -111
- package/dist/editor.js +2263 -1767
- package/dist/highlight-code.d.ts +249 -0
- package/dist/highlight-code.js +264 -0
- package/dist/history.js +7 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/phrases.d.ts +3 -2
- package/dist/phrases.js +21 -1
- package/dist/schema.d.ts +37 -1
- package/dist/schema.js +164 -134
- package/dist/set.d.ts +3 -2
- package/dist/set.js +19 -13
- package/dist/state.d.ts +120 -29
- package/dist/state.js +224 -136
- package/dist/table.d.ts +114 -3
- package/dist/table.js +64 -36
- package/package.json +3 -2
package/dist/collab.js
CHANGED
|
@@ -37,6 +37,7 @@ class CollabState {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
const collabConfig = /*@__PURE__*/GardState.Facet.define({
|
|
40
|
+
name: "collabConfig",
|
|
40
41
|
combine(configs) {
|
|
41
42
|
let combined = GardState.Facet.combineConfig(configs, {
|
|
42
43
|
startVersion: 0,
|
|
@@ -52,12 +53,14 @@ const collabConfig = /*@__PURE__*/GardState.Facet.define({
|
|
|
52
53
|
}
|
|
53
54
|
});
|
|
54
55
|
const collabReceive = /*@__PURE__*/Transaction.Effect.define({
|
|
56
|
+
name: "collabReceive",
|
|
55
57
|
map(state, changes) {
|
|
56
58
|
return changes.empty ? state
|
|
57
59
|
: new CollabState(state.version, state.syncedDoc, state.nextUpdate, addUpdate(state.openUpdate, changes));
|
|
58
60
|
}
|
|
59
61
|
});
|
|
60
62
|
const collabField = /*@__PURE__*/GardState.Field.define({
|
|
63
|
+
name: "collab",
|
|
61
64
|
create(state) {
|
|
62
65
|
return new CollabState(state.facet(collabConfig).startVersion, state.doc, null, null);
|
|
63
66
|
},
|
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
|
@@ -5,6 +5,7 @@ import { findClusterBreak } from '@marijn/find-cluster-break';
|
|
|
5
5
|
import { Alignment, Direction, Emphasis, Strong, Underline } from 'wordgard/types';
|
|
6
6
|
|
|
7
7
|
const commandHandler = /*@__PURE__*/GardState.Facet.define({
|
|
8
|
+
name: "commandHandler",
|
|
8
9
|
combine(handlers) {
|
|
9
10
|
let map = new Map();
|
|
10
11
|
for (let [cmd, handler] of handlers) {
|
|
@@ -45,12 +46,27 @@ const Command = /*@__PURE__*/(function (Command) {
|
|
|
45
46
|
Command.dispatch = dispatch;
|
|
46
47
|
;return Command})({});
|
|
47
48
|
|
|
48
|
-
function liftEmptyBlock(state) {
|
|
49
|
+
function liftEmptyBlock(state, splitListItem = true) {
|
|
49
50
|
if (!state.selection.isCursor)
|
|
50
51
|
return false;
|
|
51
52
|
let sel = state.sel, block = sel.head.textblockParent;
|
|
52
53
|
if (!block || !sel.head.isAtStart(block) || !sel.head.isAtEnd(block))
|
|
53
54
|
return false;
|
|
55
|
+
if (splitListItem && block.parent?.parent && block.index && block.parent.parent.node.type.hasRole(Node.Role.List))
|
|
56
|
+
return {
|
|
57
|
+
changes: { from: block.before, insert: [Plot.End, block.parent.node.tag] },
|
|
58
|
+
scrollIntoView: true,
|
|
59
|
+
userEvent: "split.list"
|
|
60
|
+
};
|
|
61
|
+
return liftBlock(state, block);
|
|
62
|
+
}
|
|
63
|
+
function liftTextblock(state) {
|
|
64
|
+
if (!state.selection.isCursor)
|
|
65
|
+
return false;
|
|
66
|
+
let { head } = state.sel, block = head.textblockParent;
|
|
67
|
+
return !block || !head.isAtStart(block) ? false : liftBlock(state, block);
|
|
68
|
+
}
|
|
69
|
+
function liftBlock(state, block) {
|
|
54
70
|
let start = block.before, end = block.after, before = [], after = [];
|
|
55
71
|
for (let level = block.parent, index = block.index, atStart = true, atEnd = true, first = true; level; first = false, index = level.index, level = level.parent) {
|
|
56
72
|
if (!first && state.schema.canContain(level.node.type, block.node.type))
|
|
@@ -60,7 +76,7 @@ function liftEmptyBlock(state) {
|
|
|
60
76
|
{ from: block.after, to: end, insert: after }
|
|
61
77
|
],
|
|
62
78
|
scrollIntoView: true,
|
|
63
|
-
userEvent: "unwrap
|
|
79
|
+
userEvent: "unwrap"
|
|
64
80
|
};
|
|
65
81
|
if (level.node.isInline || level.node.type.isolating)
|
|
66
82
|
break;
|
|
@@ -111,7 +127,7 @@ function enterInCode(state) {
|
|
|
111
127
|
function splitTextblock(state, splitListItem = true) {
|
|
112
128
|
let { from, to } = state.sel.replacementRange, { schema } = state.doc;
|
|
113
129
|
let before = from.textblockParent;
|
|
114
|
-
if (!before || !before.parent)
|
|
130
|
+
if (!before || !before.parent || before.node.type.isolating)
|
|
115
131
|
return false;
|
|
116
132
|
let tokens = [];
|
|
117
133
|
for (let p = from.parent;; p = p.parent) {
|
|
@@ -196,7 +212,7 @@ function joinBackward(state) {
|
|
|
196
212
|
if (!state.selection.isCursor)
|
|
197
213
|
return false;
|
|
198
214
|
let { head } = state.sel, block = head.textblockParent;
|
|
199
|
-
if (!block || !head.isAtStart(block))
|
|
215
|
+
if (!block || !head.isAtStart(block) || block.node.type.isolating)
|
|
200
216
|
return false;
|
|
201
217
|
let scan = block, target = scan.node;
|
|
202
218
|
while (!scan.index) {
|
|
@@ -264,7 +280,7 @@ function joinForward(state) {
|
|
|
264
280
|
if (!state.selection.isCursor)
|
|
265
281
|
return false;
|
|
266
282
|
let { head } = state.sel, block = head.textblockParent;
|
|
267
|
-
if (!block || !head.isAtEnd(block))
|
|
283
|
+
if (!block || !head.isAtEnd(block) || block.node.type.isolating)
|
|
268
284
|
return false;
|
|
269
285
|
let scan = block, target = scan.node;
|
|
270
286
|
for (;;) {
|
|
@@ -740,7 +756,7 @@ const insertText = ({ state }, { from, to, insert, userEvent }) => {
|
|
|
740
756
|
let marks = (from == selection.from && to == selection.to && state.sel.activeMarks) ||
|
|
741
757
|
state.doc.resolve(from).marks(state.doc.resolve(to));
|
|
742
758
|
return {
|
|
743
|
-
changes: { from, to, insert: [Leaf.
|
|
759
|
+
changes: { from, to, insert: insert ? [Leaf.text(insert, marks)] : undefined, fit: true },
|
|
744
760
|
scrollIntoView: true,
|
|
745
761
|
selection: (cx, changes) => GardSelection.near(cx, changes.mapPos(to, 1), -1),
|
|
746
762
|
userEvent
|
|
@@ -792,8 +808,8 @@ const deleteUnit = ({ state }, dir) => {
|
|
|
792
808
|
if (state.readOnly)
|
|
793
809
|
return false;
|
|
794
810
|
return deleteSelection(state) || (dir == "forward"
|
|
795
|
-
? joinForward(state) ||
|
|
796
|
-
: joinListItems(state) ||
|
|
811
|
+
? joinForward(state) || deleteEmptyPlot(state, 1) || deleteForward(state)
|
|
812
|
+
: joinListItems(state) || liftTextblock(state) || joinBackward(state) || deleteEmptyPlot(state, -1) || deleteBackward(state));
|
|
797
813
|
};
|
|
798
814
|
const deleteWord = ({ state }, dir) => {
|
|
799
815
|
if (state.readOnly)
|
|
@@ -819,8 +835,9 @@ const deleteToLineEnd = (wg, dir) => {
|
|
|
819
835
|
userEvent: "delete." + dir
|
|
820
836
|
};
|
|
821
837
|
};
|
|
822
|
-
const addToKillBuffer = /*@__PURE__*/Transaction.Effect.define();
|
|
838
|
+
const addToKillBuffer = /*@__PURE__*/Transaction.Effect.define({ name: "addToKillBuffer" });
|
|
823
839
|
const killBuffer = /*@__PURE__*/GardState.Field.define({
|
|
840
|
+
name: "killBuffer",
|
|
824
841
|
create() { return { content: [], active: false }; },
|
|
825
842
|
update(value, tr) {
|
|
826
843
|
let add = tr.effects.find(e => e.is(addToKillBuffer));
|
|
@@ -831,7 +848,7 @@ const killBuffer = /*@__PURE__*/GardState.Field.define({
|
|
|
831
848
|
}
|
|
832
849
|
});
|
|
833
850
|
function killText(state, from, to) {
|
|
834
|
-
let add = addToKillBuffer.of(state.doc.slice(from, to)
|
|
851
|
+
let add = addToKillBuffer.of(state.doc.slice(from, to));
|
|
835
852
|
return state.field(killBuffer, false) ? [add] : [GardState.appendConfig.of(killBuffer), add];
|
|
836
853
|
}
|
|
837
854
|
const killToLineEnd = wg => {
|
|
@@ -1181,7 +1198,7 @@ function isForward(dir, state) {
|
|
|
1181
1198
|
}
|
|
1182
1199
|
function asTextSel(sel, forward) {
|
|
1183
1200
|
if (sel instanceof GardSelection.Text)
|
|
1184
|
-
return sel;
|
|
1201
|
+
return sel.directional ? sel : forward ? GardSelection.range(sel.from, sel.to) : GardSelection.range(sel.to, sel.from);
|
|
1185
1202
|
let { from, to } = sel.replacementRange;
|
|
1186
1203
|
return forward ? GardSelection.range(from, to) : GardSelection.range(to, from);
|
|
1187
1204
|
}
|
|
@@ -1246,13 +1263,13 @@ function pageHeight(wg) {
|
|
|
1246
1263
|
return Math.max(10, Math.min(wg.scrollDOM.clientHeight - marginTop - marginBottom, (wg.dom.ownerDocument.defaultView || window).innerHeight) - 10);
|
|
1247
1264
|
}
|
|
1248
1265
|
const moveByPage = (wg, { dir, extend }) => {
|
|
1249
|
-
let { state } = wg,
|
|
1266
|
+
let { state } = wg, forward = dir == "down", selection = asTextSel(state.selection, forward);
|
|
1250
1267
|
let moved = selection.empty || extend ? nextVertical(wg, selection, forward, pageHeight(wg), !extend)
|
|
1251
1268
|
: forward ? GardSelection.cursor(selection.to, -1) : GardSelection.cursor(selection.from, 1);
|
|
1252
1269
|
return moved ? setSelection(extend ? extendSel(selection, moved) : moved) : false;
|
|
1253
1270
|
};
|
|
1254
1271
|
const moveToLineSide = (wg, { dir, extend }) => {
|
|
1255
|
-
let forward = isForward(dir, wg.state),
|
|
1272
|
+
let forward = isForward(dir, wg.state), selection = asTextSel(wg.state.selection, forward);
|
|
1256
1273
|
let pos = wg.moveToLineBoundary(selection, forward);
|
|
1257
1274
|
return pos ? setSelection(extend ? extendSel(selection, pos) : pos)
|
|
1258
1275
|
: extend || selection.empty ? false
|
|
@@ -1262,15 +1279,16 @@ const moveToTextblockSide = (wg, { dir, extend }) => {
|
|
|
1262
1279
|
let { state } = wg, block = state.sel.head.textblockParent;
|
|
1263
1280
|
if (!block)
|
|
1264
1281
|
return false;
|
|
1265
|
-
let
|
|
1266
|
-
|
|
1282
|
+
let forward = isForward(dir, wg.state);
|
|
1283
|
+
let pos = forward ? GardSelection.atEnd(state, block) : GardSelection.atStart(state, block);
|
|
1284
|
+
return setSelection(extend ? extendSel(asTextSel(wg.state.selection, forward), pos) : pos);
|
|
1267
1285
|
};
|
|
1268
1286
|
const moveToDocSide = (target, { side, extend }) => {
|
|
1269
1287
|
let { state } = target;
|
|
1270
1288
|
let pos = side == "start" ? GardSelection.atStart(state) : GardSelection.atEnd(state);
|
|
1271
1289
|
if (state.selection.empty && pos.head == state.selection.head)
|
|
1272
1290
|
return false;
|
|
1273
|
-
return setSelection(extend ? extendSel(state.selection, pos) : pos);
|
|
1291
|
+
return setSelection(extend ? extendSel(asTextSel(state.selection, side == "end"), pos) : pos);
|
|
1274
1292
|
};
|
|
1275
1293
|
const selectAll = ({ state }) => {
|
|
1276
1294
|
return {
|
|
@@ -1302,9 +1320,10 @@ const Menu = /*@__PURE__*/(function (Menu) {
|
|
|
1302
1320
|
let src = Menu.Item.source.of(this);
|
|
1303
1321
|
this.extension = this.parent ? [src, this.parent] : src;
|
|
1304
1322
|
}
|
|
1323
|
+
toString() { return "Menu.Item"; }
|
|
1305
1324
|
}
|
|
1306
1325
|
Item.Base = Base;
|
|
1307
|
-
Item.source = GardState.Facet.define();
|
|
1326
|
+
Item.source = GardState.Facet.define({ name: "menuItem" });
|
|
1308
1327
|
})(Item = Menu.Item || (Menu.Item = {}));
|
|
1309
1328
|
class Button extends Item.Base {
|
|
1310
1329
|
spec;
|
|
@@ -1379,6 +1398,7 @@ const Menu = /*@__PURE__*/(function (Menu) {
|
|
|
1379
1398
|
template(...content) {
|
|
1380
1399
|
return Template.new(this, content.length ? content : ["..."]);
|
|
1381
1400
|
}
|
|
1401
|
+
toString() { return "Menu.Group"; }
|
|
1382
1402
|
}
|
|
1383
1403
|
Menu.Group = Group;
|
|
1384
1404
|
(function (Group) {
|
|
@@ -1540,4 +1560,4 @@ const Menu = /*@__PURE__*/(function (Menu) {
|
|
|
1540
1560
|
Menu.resolve = resolve;
|
|
1541
1561
|
;return Menu})({});
|
|
1542
1562
|
|
|
1543
|
-
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 };
|
|
1563
|
+
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.d.ts
CHANGED
|
@@ -32,10 +32,7 @@ declare namespace parse {
|
|
|
32
32
|
/**
|
|
33
33
|
Parse the given DOM structure as a slice.
|
|
34
34
|
*/
|
|
35
|
-
function slice(schema: Schema, doc: Element | DocumentFragment, options?: parse.Options):
|
|
36
|
-
slice: Slice;
|
|
37
|
-
context: Plot.Tag<unknown>[];
|
|
38
|
-
};
|
|
35
|
+
function slice(schema: Schema, doc: Element | DocumentFragment, options?: parse.Options): Slice;
|
|
39
36
|
/**
|
|
40
37
|
Parse rules describe how DOM constructs should map to Wordgard
|
|
41
38
|
document nodes. Many can be automatically derived from node and
|
|
@@ -779,15 +776,38 @@ declare namespace Token {
|
|
|
779
776
|
Close = 1,
|
|
780
777
|
Node = 2
|
|
781
778
|
}
|
|
779
|
+
/**
|
|
780
|
+
A token's JSON representation.
|
|
781
|
+
*/
|
|
782
|
+
type JSON = Node.JSON | ".";
|
|
783
|
+
/**
|
|
784
|
+
Read a token from its JSON representation.
|
|
785
|
+
*/
|
|
786
|
+
function fromJSON(schema: Schema, value: JSON): Leaf<unknown> | Plot | Plot.Tag<unknown> | {
|
|
787
|
+
tokenType: Token.Type.Close;
|
|
788
|
+
toJSON(): any;
|
|
789
|
+
};
|
|
782
790
|
}
|
|
783
791
|
/**
|
|
784
|
-
A slice represents a part of a document
|
|
785
|
-
|
|
786
|
-
|
|
792
|
+
A slice represents a part of a document, as an array of tokens
|
|
793
|
+
plus a context. It is used to represent things like clipboard
|
|
794
|
+
content and insertions given when building a {@link ChangeSet
|
|
795
|
+
change set}.
|
|
787
796
|
*/
|
|
788
797
|
declare class Slice {
|
|
798
|
+
/**
|
|
799
|
+
The tokens contained in this slice.
|
|
800
|
+
*/
|
|
789
801
|
readonly content: readonly Token[];
|
|
790
802
|
/**
|
|
803
|
+
This slice's context, an array of tags that can be used as a
|
|
804
|
+
hint when the slice's content needs to be wrapped in
|
|
805
|
+
additional content to fit somewhere, ordered with the
|
|
806
|
+
innermost nodes in front. May be empty when there
|
|
807
|
+
is no context available.
|
|
808
|
+
*/
|
|
809
|
+
readonly context: readonly Plot.Tag[];
|
|
810
|
+
/**
|
|
791
811
|
The length of the slice's content.
|
|
792
812
|
*/
|
|
793
813
|
readonly length: number;
|
|
@@ -795,15 +815,7 @@ declare class Slice {
|
|
|
795
815
|
/**
|
|
796
816
|
Create a slice.
|
|
797
817
|
*/
|
|
798
|
-
static of(content: readonly Token[]): Slice;
|
|
799
|
-
/**
|
|
800
|
-
Compare a slice to another one.
|
|
801
|
-
*/
|
|
802
|
-
eq(other: Slice): boolean;
|
|
803
|
-
/**
|
|
804
|
-
Create a sub-slice of this slice.
|
|
805
|
-
*/
|
|
806
|
-
slice(from: number, to?: number): Slice;
|
|
818
|
+
static of(content: readonly Token[], context?: readonly Plot.Tag[]): Slice;
|
|
807
819
|
/**
|
|
808
820
|
Concatenate this slice to another slice.
|
|
809
821
|
*/
|
|
@@ -820,19 +832,10 @@ declare class Slice {
|
|
|
820
832
|
*/
|
|
821
833
|
static empty: Slice;
|
|
822
834
|
/**
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
toJSON(): Slice.JSON;
|
|
826
|
-
/**
|
|
827
|
-
Build a slice from its JSON representation.
|
|
828
|
-
*/
|
|
829
|
-
static fromJSON(schema: Schema, json: Slice.JSON): Slice;
|
|
830
|
-
}
|
|
831
|
-
declare namespace Slice {
|
|
832
|
-
/**
|
|
833
|
-
A slice's JSON representation.
|
|
835
|
+
Create a slice (with context) from the given range of document
|
|
836
|
+
content. `to` defaults to the end of the document.
|
|
834
837
|
*/
|
|
835
|
-
|
|
838
|
+
static get(doc: Plot.Doc, from: number, to?: number): Slice;
|
|
836
839
|
}
|
|
837
840
|
|
|
838
841
|
type _Node = Node;
|
|
@@ -1017,11 +1020,11 @@ declare namespace Pos {
|
|
|
1017
1020
|
/**
|
|
1018
1021
|
The node before this one, if any.
|
|
1019
1022
|
*/
|
|
1020
|
-
get nextSibling():
|
|
1023
|
+
get nextSibling(): _Node | null;
|
|
1021
1024
|
/**
|
|
1022
1025
|
The node after this node, if any.
|
|
1023
1026
|
*/
|
|
1024
|
-
get previousSibling():
|
|
1027
|
+
get previousSibling(): _Node | null;
|
|
1025
1028
|
}
|
|
1026
1029
|
/**
|
|
1027
1030
|
Subclass of {@link Pos.Node} that points at a plot node.
|
|
@@ -1307,12 +1310,19 @@ declare namespace Node {
|
|
|
1307
1310
|
implies membership of its parent groups.
|
|
1308
1311
|
*/
|
|
1309
1312
|
readonly parent: Group | undefined;
|
|
1313
|
+
/**
|
|
1314
|
+
This group's debug name.
|
|
1315
|
+
*/
|
|
1316
|
+
readonly name: string | null;
|
|
1310
1317
|
private tag;
|
|
1311
1318
|
private constructor();
|
|
1312
1319
|
/**
|
|
1313
1320
|
Define a custom node group.
|
|
1314
1321
|
*/
|
|
1315
|
-
static define(
|
|
1322
|
+
static define(spec?: {
|
|
1323
|
+
parent?: Group;
|
|
1324
|
+
name?: string;
|
|
1325
|
+
}): Group;
|
|
1316
1326
|
/**
|
|
1317
1327
|
A group that contains every node type.
|
|
1318
1328
|
*/
|
|
@@ -1371,11 +1381,15 @@ declare namespace Node {
|
|
|
1371
1381
|
whether a given node has the role attached.
|
|
1372
1382
|
*/
|
|
1373
1383
|
class Role {
|
|
1384
|
+
/**
|
|
1385
|
+
This role's name.
|
|
1386
|
+
*/
|
|
1387
|
+
readonly name: string | null;
|
|
1374
1388
|
private constructor();
|
|
1375
1389
|
/**
|
|
1376
1390
|
Define a new role.
|
|
1377
1391
|
*/
|
|
1378
|
-
static define(): Role;
|
|
1392
|
+
static define(name?: string): Role;
|
|
1379
1393
|
/**
|
|
1380
1394
|
This role indicates that a plot contains code, and makes some
|
|
1381
1395
|
commands behave differently inside such a plot.
|
|
@@ -1623,6 +1637,7 @@ declare namespace Plot {
|
|
|
1623
1637
|
*/
|
|
1624
1638
|
const End: {
|
|
1625
1639
|
tokenType: Token.Type.Close;
|
|
1640
|
+
toJSON(): any;
|
|
1626
1641
|
};
|
|
1627
1642
|
/**
|
|
1628
1643
|
A plot tag holds the type of the plot, its parameter (if any),
|
|
@@ -1867,9 +1882,9 @@ declare namespace Plot {
|
|
|
1867
1882
|
*/
|
|
1868
1883
|
contextAt(pos: number, maxDepth?: number): readonly Plot.Tag[];
|
|
1869
1884
|
/**
|
|
1870
|
-
Create a slice of the content between `from` and `to`.
|
|
1885
|
+
Create a token slice of the content between `from` and `to`.
|
|
1871
1886
|
*/
|
|
1872
|
-
slice(from: number, to?: number):
|
|
1887
|
+
slice(from: number, to?: number): readonly Token[];
|
|
1873
1888
|
}
|
|
1874
1889
|
}
|
|
1875
1890
|
|
|
@@ -2013,7 +2028,7 @@ declare class ChangeSet {
|
|
|
2013
2028
|
that are either preserved as-is (when `modifications` is null)
|
|
2014
2029
|
or only have marks modified.
|
|
2015
2030
|
*/
|
|
2016
|
-
iterChanges(replaced: (fromA: number, toA: number, fromB: number, toB: number, inserted:
|
|
2031
|
+
iterChanges(replaced: (fromA: number, toA: number, fromB: number, toB: number, inserted: readonly Token[]) => void, preserved?: (fromA: number, toA: number, fromB: number, toB: number, modifications: readonly Modification[] | null) => void): void;
|
|
2017
2032
|
/**
|
|
2018
2033
|
Iterate over the sections of the document this change leaves
|
|
2019
2034
|
unchanged or which have only mark changes. `posA` provides the
|
|
@@ -2083,18 +2098,16 @@ declare namespace ChangeSet {
|
|
|
2083
2098
|
*/
|
|
2084
2099
|
to?: number;
|
|
2085
2100
|
/**
|
|
2086
|
-
Replace the given range with this slice.
|
|
2101
|
+
Replace the given range with this slice. If `fit` is `true`
|
|
2102
|
+
and a {@link Slice} is given here, its context will be used to
|
|
2103
|
+
do the fitting.
|
|
2087
2104
|
*/
|
|
2088
2105
|
insert?: Slice | readonly Token[];
|
|
2089
2106
|
/**
|
|
2090
2107
|
For deletions or insertions where it isn't obvious that the
|
|
2091
|
-
replacement will produce a valid document, set this to `true
|
|
2092
|
-
or a stack of context tags to make the library process the
|
|
2093
|
-
replacement to make sure it fits. Context tags (passed with
|
|
2094
|
-
the innermost tag first, as in {@link Plot.Doc.contextAt} may
|
|
2095
|
-
be used as wrappers when fitting the slice.
|
|
2108
|
+
replacement will produce a valid document, set this to `true`.
|
|
2096
2109
|
*/
|
|
2097
|
-
fit?: boolean
|
|
2110
|
+
fit?: boolean;
|
|
2098
2111
|
/**
|
|
2099
2112
|
Add the given mark to this change's range. Cannot be combined
|
|
2100
2113
|
with `insert`.
|
|
@@ -2150,7 +2163,7 @@ declare namespace ChangeSet {
|
|
|
2150
2163
|
/**
|
|
2151
2164
|
The JSON representation of a change set.
|
|
2152
2165
|
*/
|
|
2153
|
-
type JSON = readonly (number | [number,
|
|
2166
|
+
type JSON = readonly (number | [number, readonly Token.JSON[] | readonly ModificationJSON[]])[];
|
|
2154
2167
|
/**
|
|
2155
2168
|
Modes available in {@link ChangeSet.mapPos} to control whether
|
|
2156
2169
|
`null` is returned on nearby deletions.
|
|
@@ -2193,11 +2206,11 @@ declare namespace serialize {
|
|
|
2193
2206
|
/**
|
|
2194
2207
|
Serialize a single node.
|
|
2195
2208
|
*/
|
|
2196
|
-
function node(node: Node, options
|
|
2209
|
+
function node(node: Node, options?: serialize.Options): Elt | string;
|
|
2197
2210
|
/**
|
|
2198
2211
|
Serialize a slice.
|
|
2199
2212
|
*/
|
|
2200
|
-
function slice(slice: Slice, options
|
|
2213
|
+
function slice(slice: Slice, options?: slice.Options): Elt.Fragment;
|
|
2201
2214
|
namespace slice {
|
|
2202
2215
|
/**
|
|
2203
2216
|
Options passed to {@link serialize.slice}.
|
|
@@ -2210,11 +2223,6 @@ declare namespace serialize {
|
|
|
2210
2223
|
*/
|
|
2211
2224
|
openAttr?: string;
|
|
2212
2225
|
/**
|
|
2213
|
-
The slice's context. Will be used to determine the type of
|
|
2214
|
-
open nodes at the start of the slice.
|
|
2215
|
-
*/
|
|
2216
|
-
context?: readonly Plot.Tag[];
|
|
2217
|
-
/**
|
|
2218
2226
|
The amount of context nodes to include in the output.
|
|
2219
2227
|
Defaults to 0, meaning only use those that are open at the
|
|
2220
2228
|
start of the slice.
|