@nerd-bible/wordgard 0.5.3-beta7 → 0.6.2-beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/command.js +11 -10
- package/dist/doc.d.ts +45 -48
- package/dist/doc.js +131 -128
- package/dist/editor.d.ts +190 -104
- package/dist/editor.js +1982 -1624
- package/dist/highlight-code.d.ts +249 -0
- package/dist/highlight-code.js +264 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/phrases.d.ts +3 -2
- package/dist/phrases.js +20 -1
- package/dist/schema.d.ts +37 -1
- package/dist/schema.js +154 -127
- package/dist/set.d.ts +3 -2
- package/dist/set.js +8 -6
- package/dist/state.d.ts +68 -22
- package/dist/state.js +137 -107
- package/dist/table.d.ts +3 -2
- package/dist/table.js +32 -14
- package/package.json +3 -2
package/dist/command.js
CHANGED
|
@@ -111,7 +111,7 @@ function enterInCode(state) {
|
|
|
111
111
|
function splitTextblock(state, splitListItem = true) {
|
|
112
112
|
let { from, to } = state.sel.replacementRange, { schema } = state.doc;
|
|
113
113
|
let before = from.textblockParent;
|
|
114
|
-
if (!before || !before.parent)
|
|
114
|
+
if (!before || !before.parent || before.node.type.isolating)
|
|
115
115
|
return false;
|
|
116
116
|
let tokens = [];
|
|
117
117
|
for (let p = from.parent;; p = p.parent) {
|
|
@@ -196,7 +196,7 @@ function joinBackward(state) {
|
|
|
196
196
|
if (!state.selection.isCursor)
|
|
197
197
|
return false;
|
|
198
198
|
let { head } = state.sel, block = head.textblockParent;
|
|
199
|
-
if (!block || !head.isAtStart(block))
|
|
199
|
+
if (!block || !head.isAtStart(block) || block.node.type.isolating)
|
|
200
200
|
return false;
|
|
201
201
|
let scan = block, target = scan.node;
|
|
202
202
|
while (!scan.index) {
|
|
@@ -264,7 +264,7 @@ function joinForward(state) {
|
|
|
264
264
|
if (!state.selection.isCursor)
|
|
265
265
|
return false;
|
|
266
266
|
let { head } = state.sel, block = head.textblockParent;
|
|
267
|
-
if (!block || !head.isAtEnd(block))
|
|
267
|
+
if (!block || !head.isAtEnd(block) || block.node.type.isolating)
|
|
268
268
|
return false;
|
|
269
269
|
let scan = block, target = scan.node;
|
|
270
270
|
for (;;) {
|
|
@@ -831,7 +831,7 @@ const killBuffer = /*@__PURE__*/GardState.Field.define({
|
|
|
831
831
|
}
|
|
832
832
|
});
|
|
833
833
|
function killText(state, from, to) {
|
|
834
|
-
let add = addToKillBuffer.of(state.doc.slice(from, to)
|
|
834
|
+
let add = addToKillBuffer.of(state.doc.slice(from, to));
|
|
835
835
|
return state.field(killBuffer, false) ? [add] : [GardState.appendConfig.of(killBuffer), add];
|
|
836
836
|
}
|
|
837
837
|
const killToLineEnd = wg => {
|
|
@@ -1181,7 +1181,7 @@ function isForward(dir, state) {
|
|
|
1181
1181
|
}
|
|
1182
1182
|
function asTextSel(sel, forward) {
|
|
1183
1183
|
if (sel instanceof GardSelection.Text)
|
|
1184
|
-
return sel;
|
|
1184
|
+
return sel.directional ? sel : forward ? GardSelection.range(sel.from, sel.to) : GardSelection.range(sel.to, sel.from);
|
|
1185
1185
|
let { from, to } = sel.replacementRange;
|
|
1186
1186
|
return forward ? GardSelection.range(from, to) : GardSelection.range(to, from);
|
|
1187
1187
|
}
|
|
@@ -1246,13 +1246,13 @@ function pageHeight(wg) {
|
|
|
1246
1246
|
return Math.max(10, Math.min(wg.scrollDOM.clientHeight - marginTop - marginBottom, (wg.dom.ownerDocument.defaultView || window).innerHeight) - 10);
|
|
1247
1247
|
}
|
|
1248
1248
|
const moveByPage = (wg, { dir, extend }) => {
|
|
1249
|
-
let { state } = wg,
|
|
1249
|
+
let { state } = wg, forward = dir == "down", selection = asTextSel(state.selection, forward);
|
|
1250
1250
|
let moved = selection.empty || extend ? nextVertical(wg, selection, forward, pageHeight(wg), !extend)
|
|
1251
1251
|
: forward ? GardSelection.cursor(selection.to, -1) : GardSelection.cursor(selection.from, 1);
|
|
1252
1252
|
return moved ? setSelection(extend ? extendSel(selection, moved) : moved) : false;
|
|
1253
1253
|
};
|
|
1254
1254
|
const moveToLineSide = (wg, { dir, extend }) => {
|
|
1255
|
-
let forward = isForward(dir, wg.state),
|
|
1255
|
+
let forward = isForward(dir, wg.state), selection = asTextSel(wg.state.selection, forward);
|
|
1256
1256
|
let pos = wg.moveToLineBoundary(selection, forward);
|
|
1257
1257
|
return pos ? setSelection(extend ? extendSel(selection, pos) : pos)
|
|
1258
1258
|
: extend || selection.empty ? false
|
|
@@ -1262,15 +1262,16 @@ const moveToTextblockSide = (wg, { dir, extend }) => {
|
|
|
1262
1262
|
let { state } = wg, block = state.sel.head.textblockParent;
|
|
1263
1263
|
if (!block)
|
|
1264
1264
|
return false;
|
|
1265
|
-
let
|
|
1266
|
-
|
|
1265
|
+
let forward = isForward(dir, wg.state);
|
|
1266
|
+
let pos = forward ? GardSelection.atEnd(state, block) : GardSelection.atStart(state, block);
|
|
1267
|
+
return setSelection(extend ? extendSel(asTextSel(wg.state.selection, forward), pos) : pos);
|
|
1267
1268
|
};
|
|
1268
1269
|
const moveToDocSide = (target, { side, extend }) => {
|
|
1269
1270
|
let { state } = target;
|
|
1270
1271
|
let pos = side == "start" ? GardSelection.atStart(state) : GardSelection.atEnd(state);
|
|
1271
1272
|
if (state.selection.empty && pos.head == state.selection.head)
|
|
1272
1273
|
return false;
|
|
1273
|
-
return setSelection(extend ? extendSel(state.selection, pos) : pos);
|
|
1274
|
+
return setSelection(extend ? extendSel(asTextSel(state.selection, side == "end"), pos) : pos);
|
|
1274
1275
|
};
|
|
1275
1276
|
const selectAll = ({ state }) => {
|
|
1276
1277
|
return {
|
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.
|
|
835
|
+
Create a slice (with context) from the given range of document
|
|
836
|
+
content. `to` defaults to the end of the document.
|
|
828
837
|
*/
|
|
829
|
-
static
|
|
830
|
-
}
|
|
831
|
-
declare namespace Slice {
|
|
832
|
-
/**
|
|
833
|
-
A slice's JSON representation.
|
|
834
|
-
*/
|
|
835
|
-
type JSON = readonly (Node.JSON | ".")[];
|
|
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.
|
|
@@ -1623,6 +1626,7 @@ declare namespace Plot {
|
|
|
1623
1626
|
*/
|
|
1624
1627
|
const End: {
|
|
1625
1628
|
tokenType: Token.Type.Close;
|
|
1629
|
+
toJSON(): any;
|
|
1626
1630
|
};
|
|
1627
1631
|
/**
|
|
1628
1632
|
A plot tag holds the type of the plot, its parameter (if any),
|
|
@@ -1867,9 +1871,9 @@ declare namespace Plot {
|
|
|
1867
1871
|
*/
|
|
1868
1872
|
contextAt(pos: number, maxDepth?: number): readonly Plot.Tag[];
|
|
1869
1873
|
/**
|
|
1870
|
-
Create a slice of the content between `from` and `to`.
|
|
1874
|
+
Create a token slice of the content between `from` and `to`.
|
|
1871
1875
|
*/
|
|
1872
|
-
slice(from: number, to?: number):
|
|
1876
|
+
slice(from: number, to?: number): readonly Token[];
|
|
1873
1877
|
}
|
|
1874
1878
|
}
|
|
1875
1879
|
|
|
@@ -2013,7 +2017,7 @@ declare class ChangeSet {
|
|
|
2013
2017
|
that are either preserved as-is (when `modifications` is null)
|
|
2014
2018
|
or only have marks modified.
|
|
2015
2019
|
*/
|
|
2016
|
-
iterChanges(replaced: (fromA: number, toA: number, fromB: number, toB: number, inserted:
|
|
2020
|
+
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
2021
|
/**
|
|
2018
2022
|
Iterate over the sections of the document this change leaves
|
|
2019
2023
|
unchanged or which have only mark changes. `posA` provides the
|
|
@@ -2083,18 +2087,16 @@ declare namespace ChangeSet {
|
|
|
2083
2087
|
*/
|
|
2084
2088
|
to?: number;
|
|
2085
2089
|
/**
|
|
2086
|
-
Replace the given range with this slice.
|
|
2090
|
+
Replace the given range with this slice. If `fit` is `true`
|
|
2091
|
+
and a {@link Slice} is given here, its context will be used to
|
|
2092
|
+
do the fitting.
|
|
2087
2093
|
*/
|
|
2088
2094
|
insert?: Slice | readonly Token[];
|
|
2089
2095
|
/**
|
|
2090
2096
|
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.
|
|
2097
|
+
replacement will produce a valid document, set this to `true`.
|
|
2096
2098
|
*/
|
|
2097
|
-
fit?: boolean
|
|
2099
|
+
fit?: boolean;
|
|
2098
2100
|
/**
|
|
2099
2101
|
Add the given mark to this change's range. Cannot be combined
|
|
2100
2102
|
with `insert`.
|
|
@@ -2150,7 +2152,7 @@ declare namespace ChangeSet {
|
|
|
2150
2152
|
/**
|
|
2151
2153
|
The JSON representation of a change set.
|
|
2152
2154
|
*/
|
|
2153
|
-
type JSON = readonly (number | [number,
|
|
2155
|
+
type JSON = readonly (number | [number, readonly Token.JSON[] | readonly ModificationJSON[]])[];
|
|
2154
2156
|
/**
|
|
2155
2157
|
Modes available in {@link ChangeSet.mapPos} to control whether
|
|
2156
2158
|
`null` is returned on nearby deletions.
|
|
@@ -2193,11 +2195,11 @@ declare namespace serialize {
|
|
|
2193
2195
|
/**
|
|
2194
2196
|
Serialize a single node.
|
|
2195
2197
|
*/
|
|
2196
|
-
function node(node: Node, options
|
|
2198
|
+
function node(node: Node, options?: serialize.Options): Elt | string;
|
|
2197
2199
|
/**
|
|
2198
2200
|
Serialize a slice.
|
|
2199
2201
|
*/
|
|
2200
|
-
function slice(slice: Slice, options
|
|
2202
|
+
function slice(slice: Slice, options?: slice.Options): Elt.Fragment;
|
|
2201
2203
|
namespace slice {
|
|
2202
2204
|
/**
|
|
2203
2205
|
Options passed to {@link serialize.slice}.
|
|
@@ -2210,11 +2212,6 @@ declare namespace serialize {
|
|
|
2210
2212
|
*/
|
|
2211
2213
|
openAttr?: string;
|
|
2212
2214
|
/**
|
|
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
2215
|
The amount of context nodes to include in the output.
|
|
2219
2216
|
Defaults to 0, meaning only use those that are open at the
|
|
2220
2217
|
start of the slice.
|