@nerd-bible/wordgard 0.5.3-beta4 → 0.5.3-beta6
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/doc.js +49 -42
- package/dist/editor.d.ts +60 -137
- package/dist/editor.js +241 -569
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/schema.js +6 -6
- package/dist/set.d.ts +258 -0
- package/dist/set.js +781 -0
- package/dist/table.js +3 -3
- package/package.json +2 -11
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * as editor from "wordgard/editor"
|
|
|
5
5
|
export * as history from "wordgard/history"
|
|
6
6
|
export * as phrases from "wordgard/phrases"
|
|
7
7
|
export * as schema from "wordgard/schema"
|
|
8
|
+
export * as set from "wordgard/set"
|
|
8
9
|
export * as state from "wordgard/state"
|
|
9
10
|
export * as table from "wordgard/table"
|
|
10
11
|
export * as types from "wordgard/types"
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * as editor from "wordgard/editor"
|
|
|
5
5
|
export * as history from "wordgard/history"
|
|
6
6
|
export * as phrases from "wordgard/phrases"
|
|
7
7
|
export * as schema from "wordgard/schema"
|
|
8
|
+
export * as set from "wordgard/set"
|
|
8
9
|
export * as state from "wordgard/state"
|
|
9
10
|
export * as table from "wordgard/table"
|
|
10
11
|
export * as types from "wordgard/types"
|
package/dist/schema.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Paragraph, Heading, Direction, Blockquote, HorizontalRule, Alignment, D
|
|
|
4
4
|
import { phrases, imagePhrases, colorNames } from 'wordgard/phrases';
|
|
5
5
|
import { Command, setTextblockType, Menu, setAlignment, setDirection, toggleBlock, listIsActive, toggleList, enter, toggleMark } from 'wordgard/command';
|
|
6
6
|
import { history } from 'wordgard/history';
|
|
7
|
-
import { KeyBinding, InputRule, Wordgard, Widget, Decoration, Panel, Dialog,
|
|
7
|
+
import { KeyBinding, InputRule, Wordgard, Widget, Decoration, Panel, Dialog, Tooltip } from 'wordgard/editor';
|
|
8
8
|
import cr from 'crelt';
|
|
9
9
|
|
|
10
10
|
function blockDoc() {
|
|
@@ -827,17 +827,17 @@ const handleElt = /*@__PURE__*/(() => Elt.mk("svg:svg", { class: "wg-resize-hand
|
|
|
827
827
|
]))();
|
|
828
828
|
const resizeWrapper = /*@__PURE__*/(() => Decoration.Point.wrapper(Elt.mk("span", { class: "wg-resize-hover" }, [handleElt, 0]), { target: "img" }))();
|
|
829
829
|
const resizeState = /*@__PURE__*/GardState.Field.define({
|
|
830
|
-
create: () => ({ target: -1, resizing: -1, deco:
|
|
830
|
+
create: () => ({ target: -1, resizing: -1, deco: Decoration.Point.none }),
|
|
831
831
|
update: (value, tr) => {
|
|
832
832
|
for (let e of tr.effects) {
|
|
833
833
|
if (e.is(setResizing)) {
|
|
834
834
|
let { target, resizing } = e.value;
|
|
835
835
|
if (target < 0)
|
|
836
|
-
return { target: -1, resizing: -1, deco:
|
|
837
|
-
let deco = [[
|
|
836
|
+
return { target: -1, resizing: -1, deco: Decoration.Point.none };
|
|
837
|
+
let deco = [[resizeWrapper, target]];
|
|
838
838
|
if (resizing > -1)
|
|
839
|
-
deco.push([
|
|
840
|
-
return { target, resizing, deco:
|
|
839
|
+
deco.push([Decoration.Point.attributes({ style: `width: ${resizing}px` }, { target: "img" }), target]);
|
|
840
|
+
return { target, resizing, deco: Decoration.Point.set(deco) };
|
|
841
841
|
}
|
|
842
842
|
}
|
|
843
843
|
return value.target < 0 || !tr.docChanged ? value
|
package/dist/set.d.ts
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { ChangeSet } from 'wordgard/doc';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
The interface shared between {@link RangeSet} and {@link
|
|
5
|
+
PointSet}.
|
|
6
|
+
*/
|
|
7
|
+
declare abstract class Set<T> {
|
|
8
|
+
/**
|
|
9
|
+
The number of values in this set.
|
|
10
|
+
*/
|
|
11
|
+
abstract length: number;
|
|
12
|
+
/**
|
|
13
|
+
Returns `true` when this set is empty.
|
|
14
|
+
*/
|
|
15
|
+
abstract empty: boolean;
|
|
16
|
+
/**
|
|
17
|
+
Create a cursor over this point set, starting at the given
|
|
18
|
+
position and side.
|
|
19
|
+
*/
|
|
20
|
+
abstract cursor(from?: number): Set.Cursor<T>;
|
|
21
|
+
/**
|
|
22
|
+
Adjust this set's positions for a set of document changes.
|
|
23
|
+
Returns a new set with the adjusted positions. Will delete
|
|
24
|
+
values when the content around them was deleted. Optionally
|
|
25
|
+
accepts an ordered sequence of replacements, whose positions
|
|
26
|
+
should refer to the post-change document.
|
|
27
|
+
*/
|
|
28
|
+
abstract map(map: ChangeSet, replace?: readonly Set.Replacement<T>[]): this;
|
|
29
|
+
/**
|
|
30
|
+
Create an updated copy of this set.
|
|
31
|
+
*/
|
|
32
|
+
abstract modify(spec: {
|
|
33
|
+
/**
|
|
34
|
+
If given, replace all values in these ranges.
|
|
35
|
+
*/
|
|
36
|
+
replace?: readonly Set.Replacement<T>[];
|
|
37
|
+
/**
|
|
38
|
+
Add values from this source.
|
|
39
|
+
*/
|
|
40
|
+
add?: Set.Source<T>;
|
|
41
|
+
/**
|
|
42
|
+
Optionally filter out any value where this predicate returns
|
|
43
|
+
false.
|
|
44
|
+
*/
|
|
45
|
+
filter?: (value: T, from: number, to: number) => boolean;
|
|
46
|
+
}): this;
|
|
47
|
+
}
|
|
48
|
+
declare namespace Set {
|
|
49
|
+
/**
|
|
50
|
+
A cursor over a point or range set.
|
|
51
|
+
*/
|
|
52
|
+
interface Cursor<T> {
|
|
53
|
+
/**
|
|
54
|
+
The value of the current range or point, or `null` when there
|
|
55
|
+
are no more values.
|
|
56
|
+
*/
|
|
57
|
+
value: T | null;
|
|
58
|
+
/**
|
|
59
|
+
The start position of the current range or point.
|
|
60
|
+
*/
|
|
61
|
+
from: number;
|
|
62
|
+
/**
|
|
63
|
+
The end position of the current range. Will be equal to `from`
|
|
64
|
+
for points.
|
|
65
|
+
*/
|
|
66
|
+
to: number;
|
|
67
|
+
/**
|
|
68
|
+
Move the cursor to a given position.
|
|
69
|
+
*/
|
|
70
|
+
goto(pos: number, side?: number): void;
|
|
71
|
+
/**
|
|
72
|
+
Continue to the next value, if any.
|
|
73
|
+
*/
|
|
74
|
+
next(): void;
|
|
75
|
+
/**
|
|
76
|
+
The set object that the current value points at, if any.
|
|
77
|
+
*/
|
|
78
|
+
set: any;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
A source, used to create or extend a set, is either
|
|
82
|
+
an array of `[value, pos, pos?]` tuples, or a function that calls its
|
|
83
|
+
argument to add a value.
|
|
84
|
+
|
|
85
|
+
For ranges, `to` must be given, and ranges must be provided
|
|
86
|
+
ordered by start position. For points, `to` must be omitted or
|
|
87
|
+
be the same as `from`, and the points must be ordered by
|
|
88
|
+
position and {@link PointSet.Value.side side}.
|
|
89
|
+
*/
|
|
90
|
+
type Source<T> = Iterable<[T, number, number?]> | ((add: (value: T, pos: number, to?: number) => void) => void);
|
|
91
|
+
/**
|
|
92
|
+
Represents a replaced section in a set.
|
|
93
|
+
*/
|
|
94
|
+
type Replacement<T> = {
|
|
95
|
+
/**
|
|
96
|
+
The start of the replacement.
|
|
97
|
+
*/
|
|
98
|
+
from: number;
|
|
99
|
+
/**
|
|
100
|
+
The end of the replaced range.
|
|
101
|
+
*/
|
|
102
|
+
to: number;
|
|
103
|
+
/**
|
|
104
|
+
An optional source of points to to this section.
|
|
105
|
+
*/
|
|
106
|
+
add?: Source<T>;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
Data structure that stores sets of ranges, for use with {@link
|
|
112
|
+
Decoration.Range range decorations} or other data types
|
|
113
|
+
implementing {@link RangeSet.Value}.
|
|
114
|
+
*/
|
|
115
|
+
declare class RangeSet<T extends RangeSet.Value> extends Set<T> {
|
|
116
|
+
private constructor();
|
|
117
|
+
/**
|
|
118
|
+
Create a range set from an iterable of `[from, to, value]`
|
|
119
|
+
tuples, or a function that calls its argument for every range to
|
|
120
|
+
add.
|
|
121
|
+
*/
|
|
122
|
+
static create<T extends RangeSet.Value>(source: Set.Source<T>): RangeSet<T>;
|
|
123
|
+
get length(): number;
|
|
124
|
+
get empty(): boolean;
|
|
125
|
+
cursor(from?: number): Set.Cursor<T>;
|
|
126
|
+
/**
|
|
127
|
+
Create a cursor over a collection of range sets.
|
|
128
|
+
*/
|
|
129
|
+
static cursor<T extends RangeSet.Value>(sets: readonly RangeSet<T>[], from?: number): Set.Cursor<T>;
|
|
130
|
+
map(map: ChangeSet, replace?: readonly Set.Replacement<T>[]): this;
|
|
131
|
+
private mapInner;
|
|
132
|
+
modify(spec: {
|
|
133
|
+
replace?: readonly Set.Replacement<T>[];
|
|
134
|
+
add?: Set.Source<T>;
|
|
135
|
+
filter?: (value: T, from: number, to: number) => boolean;
|
|
136
|
+
}): this;
|
|
137
|
+
private modifyInner;
|
|
138
|
+
/**
|
|
139
|
+
Compare a section of this set with a section of the same length
|
|
140
|
+
in another set. Calls `change` for any range where the two do
|
|
141
|
+
not contain identical ranges.
|
|
142
|
+
*/
|
|
143
|
+
compareRange(fromA: number, b: RangeSet<T>, fromB: number, len: number, change: (from: number, to: number) => void): void;
|
|
144
|
+
/**
|
|
145
|
+
The empty range set.
|
|
146
|
+
*/
|
|
147
|
+
static empty: RangeSet<any>;
|
|
148
|
+
}
|
|
149
|
+
declare namespace RangeSet {
|
|
150
|
+
/**
|
|
151
|
+
Values stored in a range set must conform to this interface.
|
|
152
|
+
*/
|
|
153
|
+
interface Value {
|
|
154
|
+
/**
|
|
155
|
+
Whether content inserted at the start of this value's range is
|
|
156
|
+
included in the range.
|
|
157
|
+
*/
|
|
158
|
+
inclusiveStart: boolean;
|
|
159
|
+
/**
|
|
160
|
+
Whether content inserted at the end is included.
|
|
161
|
+
*/
|
|
162
|
+
inclusiveEnd: boolean;
|
|
163
|
+
/**
|
|
164
|
+
Compare this value to another.
|
|
165
|
+
*/
|
|
166
|
+
eq(other: Value): boolean;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
Data structure used to store sets of points and then track them
|
|
172
|
+
across document changes. Mostly used for {@link Decoration.Point
|
|
173
|
+
point decorations}, but can also track your own types, if you make
|
|
174
|
+
sure they implement the {@link PointSet.Value} interface.
|
|
175
|
+
*/
|
|
176
|
+
declare class PointSet<T extends PointSet.Value> implements Set<T> {
|
|
177
|
+
private constructor();
|
|
178
|
+
/**
|
|
179
|
+
Create a point set from an iterable of `[position, value]`
|
|
180
|
+
tuples, or a function that calls its argument for every point to
|
|
181
|
+
add.
|
|
182
|
+
*/
|
|
183
|
+
static create<T extends PointSet.Value>(source: Set.Source<T>): PointSet<T>;
|
|
184
|
+
get length(): number;
|
|
185
|
+
get empty(): boolean;
|
|
186
|
+
/**
|
|
187
|
+
Create a cursor over this point set, starting at the given
|
|
188
|
+
position and side.
|
|
189
|
+
*/
|
|
190
|
+
cursor(from?: number, side?: number): Set.Cursor<T>;
|
|
191
|
+
/**
|
|
192
|
+
Create a cursor over a collection of point sets.
|
|
193
|
+
*/
|
|
194
|
+
static cursor<T extends PointSet.Value>(sets: readonly PointSet<T>[], from?: number, side?: number): Set.Cursor<T>;
|
|
195
|
+
/**
|
|
196
|
+
Get the value at the given position, if any. If there's multiple
|
|
197
|
+
values at that position, the one with the lowest side is
|
|
198
|
+
returned.
|
|
199
|
+
*/
|
|
200
|
+
at(pos: number): T | undefined;
|
|
201
|
+
/**
|
|
202
|
+
Adjust the points for a set of document changes. Returns a new
|
|
203
|
+
set with the adjusted points. May delete points when the content
|
|
204
|
+
around them was deleted. Optionally accepts an ordered sequence
|
|
205
|
+
of replacements.
|
|
206
|
+
*/
|
|
207
|
+
map(map: ChangeSet, replace?: readonly Set.Replacement<T>[]): this;
|
|
208
|
+
private mapInner;
|
|
209
|
+
modify(spec: {
|
|
210
|
+
replace?: readonly Set.Replacement<T>[];
|
|
211
|
+
add?: Set.Source<T>;
|
|
212
|
+
filter?: (value: T, from: number, to: number) => boolean;
|
|
213
|
+
}): this;
|
|
214
|
+
private modifyInner;
|
|
215
|
+
/**
|
|
216
|
+
Compare a range in this set with a range in another set. Call
|
|
217
|
+
`change` for every point that exists in one but not the other.
|
|
218
|
+
*/
|
|
219
|
+
compareRange(fromA: number, b: PointSet<T>, fromB: number, len: number, change: (pos: number, value: T) => void): void;
|
|
220
|
+
/**
|
|
221
|
+
The empty point set.
|
|
222
|
+
*/
|
|
223
|
+
static empty: PointSet<any>;
|
|
224
|
+
}
|
|
225
|
+
declare namespace PointSet {
|
|
226
|
+
/**
|
|
227
|
+
Objects stored in a point set must conform to this interface.
|
|
228
|
+
*/
|
|
229
|
+
interface Value {
|
|
230
|
+
/**
|
|
231
|
+
The side of the point. Used to provide a sorting of points at
|
|
232
|
+
the same position, and to determine cursor position relative to
|
|
233
|
+
the points. Points with side < 0 are always displayed before a
|
|
234
|
+
cursor at their position, those with side > 0 always after, and
|
|
235
|
+
those with side == 0 before or after depending on the cursor's
|
|
236
|
+
side.
|
|
237
|
+
*/
|
|
238
|
+
side: number;
|
|
239
|
+
/**
|
|
240
|
+
Configures whether the point should be deleted when content next
|
|
241
|
+
to it is deleted. See {@link ChangeSet.mapPos}.
|
|
242
|
+
*/
|
|
243
|
+
trackMode: ChangeSet.TrackMode | undefined;
|
|
244
|
+
/**
|
|
245
|
+
Method to compare this value to another.
|
|
246
|
+
*/
|
|
247
|
+
eq(other: Value): boolean;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
Perform a binary search on the given array (starting at start) and
|
|
253
|
+
return the index of the first element > n (or the length if no
|
|
254
|
+
such element exists) @hidden
|
|
255
|
+
*/
|
|
256
|
+
declare function findAbove(array: readonly number[], start: number, n: number): number;
|
|
257
|
+
|
|
258
|
+
export { PointSet, RangeSet, Set, findAbove };
|