@nerd-bible/wordgard 0.5.3-beta4 → 0.5.3-beta5
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 +30 -136
- package/dist/editor.js +160 -568
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/schema.js +4 -4
- package/dist/set.d.ts +305 -0
- package/dist/set.js +814 -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:
|
|
836
|
+
return { target: -1, resizing: -1, deco: Decoration.Point.none };
|
|
837
837
|
let deco = [[target, resizeWrapper]];
|
|
838
838
|
if (resizing > -1)
|
|
839
839
|
deco.push([target, Decoration.Point.attributes({ style: `width: ${resizing}px` }, { target: "img" })]);
|
|
840
|
-
return { target, resizing, deco:
|
|
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,305 @@
|
|
|
1
|
+
import { ChangeSet } from 'wordgard/doc';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Data structure that stores sets of ranges, for use with {@link
|
|
5
|
+
Decoration.Range range decorations} or other data types
|
|
6
|
+
implementing {@link RangeSet.Value}.
|
|
7
|
+
*/
|
|
8
|
+
declare class RangeSet<T extends RangeSet.Value> {
|
|
9
|
+
private constructor();
|
|
10
|
+
/**
|
|
11
|
+
Create a range set from an iterable of `[from, to, value]`
|
|
12
|
+
tuples, or a function that calls its argument for every range to
|
|
13
|
+
add.
|
|
14
|
+
*/
|
|
15
|
+
static create<T extends RangeSet.Value>(source: RangeSet.Source<T>): RangeSet<T>;
|
|
16
|
+
/**
|
|
17
|
+
The number of ranges stored in this set.
|
|
18
|
+
*/
|
|
19
|
+
get length(): number;
|
|
20
|
+
/**
|
|
21
|
+
Returns true when this set is empty.
|
|
22
|
+
*/
|
|
23
|
+
get empty(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
Create a cursor over this set, starting at the given position.
|
|
26
|
+
*/
|
|
27
|
+
cursor(from?: number): RangeSet.Cursor<T>;
|
|
28
|
+
/**
|
|
29
|
+
Create a cursor over a collection of range sets.
|
|
30
|
+
*/
|
|
31
|
+
static cursor<T extends RangeSet.Value>(sets: readonly RangeSet<T>[], from?: number): RangeSet.Cursor<T>;
|
|
32
|
+
/**
|
|
33
|
+
Adjust the positions of the ranges for the given change set.
|
|
34
|
+
Returns a set with the updated ranges. Optionally takes an array
|
|
35
|
+
of replacement ranges. Any ranges overlapping such a replacement
|
|
36
|
+
will be dropped, and new ranges provided by their `add`
|
|
37
|
+
properties will be added to the new set.
|
|
38
|
+
*/
|
|
39
|
+
map(map: ChangeSet, replace?: readonly RangeSet.Replacement<T>[]): RangeSet<T>;
|
|
40
|
+
private mapInner;
|
|
41
|
+
/**
|
|
42
|
+
Modify this set.
|
|
43
|
+
*/
|
|
44
|
+
modify(spec: {
|
|
45
|
+
/**
|
|
46
|
+
Drop any ranges inside the given replacement ranges,
|
|
47
|
+
optionally add new ranges provided by their `add` property.
|
|
48
|
+
*/
|
|
49
|
+
replace?: readonly RangeSet.Replacement<T>[];
|
|
50
|
+
/**
|
|
51
|
+
Add new ranges to the set.
|
|
52
|
+
*/
|
|
53
|
+
add?: RangeSet.Source<T>;
|
|
54
|
+
/**
|
|
55
|
+
Drop any range for which this predicate function returns
|
|
56
|
+
`false`.
|
|
57
|
+
*/
|
|
58
|
+
filter?: (from: number, to: number, value: T) => boolean;
|
|
59
|
+
}): RangeSet<T>;
|
|
60
|
+
private modifyInner;
|
|
61
|
+
/**
|
|
62
|
+
Compare a section of this set with a section of the same length
|
|
63
|
+
in another set. Calls `change` for any range where the two do
|
|
64
|
+
not contain identical ranges.
|
|
65
|
+
*/
|
|
66
|
+
compareRange(fromA: number, b: RangeSet<T>, fromB: number, len: number, change: (from: number, to: number) => void): void;
|
|
67
|
+
/**
|
|
68
|
+
The empty range set.
|
|
69
|
+
*/
|
|
70
|
+
static empty: RangeSet<any>;
|
|
71
|
+
}
|
|
72
|
+
declare namespace RangeSet {
|
|
73
|
+
/**
|
|
74
|
+
Values stored in a range set must conform to this interface.
|
|
75
|
+
*/
|
|
76
|
+
interface Value {
|
|
77
|
+
/**
|
|
78
|
+
Whether content inserted at the start of this value's range is
|
|
79
|
+
included in the range.
|
|
80
|
+
*/
|
|
81
|
+
inclusiveStart: boolean;
|
|
82
|
+
/**
|
|
83
|
+
Whether content inserted at the end is included.
|
|
84
|
+
*/
|
|
85
|
+
inclusiveEnd: boolean;
|
|
86
|
+
/**
|
|
87
|
+
Compare this value to another.
|
|
88
|
+
*/
|
|
89
|
+
eq(other: Value): boolean;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
A range source, used to construct or extend a range set, must
|
|
93
|
+
either be an array of `[from, to, value]` tuples, or a function
|
|
94
|
+
that calls its argument for each range to add. Ranges must be
|
|
95
|
+
provided ordered by their `from` position.
|
|
96
|
+
*/
|
|
97
|
+
type Source<T extends Value> = Iterable<[number, number, T]> | ((add: (from: number, to: number, value: T) => void) => void);
|
|
98
|
+
/**
|
|
99
|
+
Represents a replaced section in a range set.
|
|
100
|
+
*/
|
|
101
|
+
type Replacement<T extends Value> = {
|
|
102
|
+
/**
|
|
103
|
+
The start of the section.
|
|
104
|
+
*/
|
|
105
|
+
from: number;
|
|
106
|
+
/**
|
|
107
|
+
The end of the section.
|
|
108
|
+
*/
|
|
109
|
+
to: number;
|
|
110
|
+
/**
|
|
111
|
+
An optional collection of ranges to replace the section with.
|
|
112
|
+
Must fall within `from` and `to`.
|
|
113
|
+
*/
|
|
114
|
+
add?: Source<T>;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
A cursor over a range set.
|
|
118
|
+
*/
|
|
119
|
+
interface Cursor<T extends Value> {
|
|
120
|
+
/**
|
|
121
|
+
The current range's value, or `null` if the end of the set has
|
|
122
|
+
been reached.
|
|
123
|
+
*/
|
|
124
|
+
value: T | null;
|
|
125
|
+
/**
|
|
126
|
+
The start position of the current range.
|
|
127
|
+
*/
|
|
128
|
+
from: number;
|
|
129
|
+
/**
|
|
130
|
+
The end position of the current range.
|
|
131
|
+
*/
|
|
132
|
+
to: number;
|
|
133
|
+
/**
|
|
134
|
+
Move the cursor to a new position.
|
|
135
|
+
*/
|
|
136
|
+
goto(pos: number): void;
|
|
137
|
+
/**
|
|
138
|
+
Move to the next range, if any.
|
|
139
|
+
*/
|
|
140
|
+
next(): void;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
Data structure used to store sets of points and then track them
|
|
146
|
+
across document changes. Mostly used for {@link Decoration.Point
|
|
147
|
+
point decorations}, but can also track your own types, if you make
|
|
148
|
+
sure they implement the {@link PointSet.Value} interface.
|
|
149
|
+
*/
|
|
150
|
+
declare class PointSet<T extends PointSet.Value> {
|
|
151
|
+
private constructor();
|
|
152
|
+
/**
|
|
153
|
+
Create a point set from an iterable of `[position, value]`
|
|
154
|
+
tuples, or a function that calls its argument for every point to
|
|
155
|
+
add.
|
|
156
|
+
*/
|
|
157
|
+
static create<T extends PointSet.Value>(source: PointSet.Source<T>): PointSet<T>;
|
|
158
|
+
/**
|
|
159
|
+
The number of points in this set.
|
|
160
|
+
*/
|
|
161
|
+
get length(): number;
|
|
162
|
+
/**
|
|
163
|
+
Returns `true` when this set is empty.
|
|
164
|
+
*/
|
|
165
|
+
get empty(): boolean;
|
|
166
|
+
/**
|
|
167
|
+
Create a cursor over this point set, starting at the given
|
|
168
|
+
position and side.
|
|
169
|
+
*/
|
|
170
|
+
cursor(from?: number, side?: number): PointSet.Cursor<T>;
|
|
171
|
+
/**
|
|
172
|
+
Create a cursor over a collection of point sets.
|
|
173
|
+
*/
|
|
174
|
+
static cursor<T extends PointSet.Value>(sets: readonly PointSet<T>[], from?: number, side?: number): PointSet.Cursor<T>;
|
|
175
|
+
/**
|
|
176
|
+
Get the value at the given position, if any. If there's multiple
|
|
177
|
+
values at that position, the one with the lowest side is
|
|
178
|
+
returned.
|
|
179
|
+
*/
|
|
180
|
+
at(pos: number): T | undefined;
|
|
181
|
+
/**
|
|
182
|
+
Adjust the points for a set of document changes. Returns a new
|
|
183
|
+
set with the adjusted points. May delete points when the content
|
|
184
|
+
around them was deleted. Optionally accepts an ordered sequence
|
|
185
|
+
of replacements.
|
|
186
|
+
*/
|
|
187
|
+
map(map: ChangeSet, replace?: readonly PointSet.Replacement<T>[]): PointSet<T>;
|
|
188
|
+
private mapInner;
|
|
189
|
+
/**
|
|
190
|
+
Create an updated copy of this set.
|
|
191
|
+
*/
|
|
192
|
+
modify(spec: {
|
|
193
|
+
/**
|
|
194
|
+
If given, replace all points in these ranges.
|
|
195
|
+
*/
|
|
196
|
+
replace?: readonly PointSet.Replacement<T>[];
|
|
197
|
+
/**
|
|
198
|
+
Add the points from this source.
|
|
199
|
+
*/
|
|
200
|
+
add?: PointSet.Source<T>;
|
|
201
|
+
/**
|
|
202
|
+
Optionally filter out any point where this predicate returns
|
|
203
|
+
false.
|
|
204
|
+
*/
|
|
205
|
+
filter?: (pos: number, value: T) => boolean;
|
|
206
|
+
}): PointSet<T>;
|
|
207
|
+
private modifyInner;
|
|
208
|
+
/**
|
|
209
|
+
Compare a range in this set with a range in another set. Call
|
|
210
|
+
`change` for every point that exists in one but not the other.
|
|
211
|
+
*/
|
|
212
|
+
compareRange(fromA: number, b: PointSet<T>, fromB: number, len: number, change: (pos: number, value: T) => void): void;
|
|
213
|
+
/**
|
|
214
|
+
The empty point set.
|
|
215
|
+
*/
|
|
216
|
+
static empty: PointSet<any>;
|
|
217
|
+
}
|
|
218
|
+
declare namespace PointSet {
|
|
219
|
+
/**
|
|
220
|
+
Objects stored in a point set must conform to this interface.
|
|
221
|
+
*/
|
|
222
|
+
interface Value {
|
|
223
|
+
/**
|
|
224
|
+
The side of the point. Used to provide a sorting of points at
|
|
225
|
+
the same position, and to determine cursor position relative to
|
|
226
|
+
the points. Points with side < 0 are always displayed before a
|
|
227
|
+
cursor at their position, those with side > 0 always after, and
|
|
228
|
+
those with side == 0 before or after depending on the cursor's
|
|
229
|
+
side.
|
|
230
|
+
*/
|
|
231
|
+
side: number;
|
|
232
|
+
/**
|
|
233
|
+
Configures whether the point should be deleted when content next
|
|
234
|
+
to it is deleted. See {@link ChangeSet.mapPos}.
|
|
235
|
+
*/
|
|
236
|
+
trackMode: ChangeSet.TrackMode | undefined;
|
|
237
|
+
/**
|
|
238
|
+
Method to compare this value to another.
|
|
239
|
+
*/
|
|
240
|
+
eq(other: Value): boolean;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
A point source, used to create or extend a point set, is either
|
|
244
|
+
an array of `[pos, value]` tuples, or a function that calls its
|
|
245
|
+
argument to add a point. Point sources must provide their points
|
|
246
|
+
ordered by position and {@link PointSet.Value.side side}.
|
|
247
|
+
*/
|
|
248
|
+
type Source<T extends Value> = Iterable<[number, T]> | ((add: (pos: number, value: T) => void) => void);
|
|
249
|
+
/**
|
|
250
|
+
Represents a replaced section in a point set.
|
|
251
|
+
*/
|
|
252
|
+
type Replacement<T extends Value> = {
|
|
253
|
+
/**
|
|
254
|
+
The start of the replacement.
|
|
255
|
+
*/
|
|
256
|
+
from: number;
|
|
257
|
+
/**
|
|
258
|
+
The end of the replaced range.
|
|
259
|
+
*/
|
|
260
|
+
to: number;
|
|
261
|
+
/**
|
|
262
|
+
An optional source of points to to this section.
|
|
263
|
+
*/
|
|
264
|
+
add?: PointSet.Source<T>;
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
A cursor over a point set.
|
|
268
|
+
*/
|
|
269
|
+
interface Cursor<T extends Value> {
|
|
270
|
+
/**
|
|
271
|
+
The value of the current point, or `null` when there are no
|
|
272
|
+
more points.
|
|
273
|
+
*/
|
|
274
|
+
value: T | null;
|
|
275
|
+
/**
|
|
276
|
+
The position of the current point.
|
|
277
|
+
*/
|
|
278
|
+
pos: number;
|
|
279
|
+
/**
|
|
280
|
+
The side value of the current point.
|
|
281
|
+
*/
|
|
282
|
+
side: number;
|
|
283
|
+
/**
|
|
284
|
+
Move the cursor to a given position and side.
|
|
285
|
+
*/
|
|
286
|
+
goto(pos: number, side: number): void;
|
|
287
|
+
/**
|
|
288
|
+
Continue to the next point, if any.
|
|
289
|
+
*/
|
|
290
|
+
next(): void;
|
|
291
|
+
/**
|
|
292
|
+
The set object that the current point belongs to.
|
|
293
|
+
*/
|
|
294
|
+
set: PointSet<T>;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
Perform a binary search on the given array (starting at start) and
|
|
300
|
+
return the index of the first element > n (or the length if no
|
|
301
|
+
such element exists) @hidden
|
|
302
|
+
*/
|
|
303
|
+
declare function findAbove(array: readonly number[], start: number, n: number): number;
|
|
304
|
+
|
|
305
|
+
export { PointSet, RangeSet, findAbove };
|