@blockslides/extension-add-slide-button 0.1.0
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/LICENSE.md +36 -0
- package/dist/index.cjs +3263 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +43 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +3236 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -0
- package/src/add-slide-button.ts +250 -0
- package/src/index.ts +5 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3236 @@
|
|
|
1
|
+
// src/add-slide-button.ts
|
|
2
|
+
import { Extension, createStyleTag } from "@blockslides/core";
|
|
3
|
+
|
|
4
|
+
// ../../node_modules/.pnpm/prosemirror-model@1.25.3/node_modules/prosemirror-model/dist/index.js
|
|
5
|
+
function findDiffStart(a, b, pos) {
|
|
6
|
+
for (let i = 0; ; i++) {
|
|
7
|
+
if (i == a.childCount || i == b.childCount)
|
|
8
|
+
return a.childCount == b.childCount ? null : pos;
|
|
9
|
+
let childA = a.child(i), childB = b.child(i);
|
|
10
|
+
if (childA == childB) {
|
|
11
|
+
pos += childA.nodeSize;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (!childA.sameMarkup(childB))
|
|
15
|
+
return pos;
|
|
16
|
+
if (childA.isText && childA.text != childB.text) {
|
|
17
|
+
for (let j = 0; childA.text[j] == childB.text[j]; j++)
|
|
18
|
+
pos++;
|
|
19
|
+
return pos;
|
|
20
|
+
}
|
|
21
|
+
if (childA.content.size || childB.content.size) {
|
|
22
|
+
let inner = findDiffStart(childA.content, childB.content, pos + 1);
|
|
23
|
+
if (inner != null)
|
|
24
|
+
return inner;
|
|
25
|
+
}
|
|
26
|
+
pos += childA.nodeSize;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function findDiffEnd(a, b, posA, posB) {
|
|
30
|
+
for (let iA = a.childCount, iB = b.childCount; ; ) {
|
|
31
|
+
if (iA == 0 || iB == 0)
|
|
32
|
+
return iA == iB ? null : { a: posA, b: posB };
|
|
33
|
+
let childA = a.child(--iA), childB = b.child(--iB), size = childA.nodeSize;
|
|
34
|
+
if (childA == childB) {
|
|
35
|
+
posA -= size;
|
|
36
|
+
posB -= size;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (!childA.sameMarkup(childB))
|
|
40
|
+
return { a: posA, b: posB };
|
|
41
|
+
if (childA.isText && childA.text != childB.text) {
|
|
42
|
+
let same = 0, minSize = Math.min(childA.text.length, childB.text.length);
|
|
43
|
+
while (same < minSize && childA.text[childA.text.length - same - 1] == childB.text[childB.text.length - same - 1]) {
|
|
44
|
+
same++;
|
|
45
|
+
posA--;
|
|
46
|
+
posB--;
|
|
47
|
+
}
|
|
48
|
+
return { a: posA, b: posB };
|
|
49
|
+
}
|
|
50
|
+
if (childA.content.size || childB.content.size) {
|
|
51
|
+
let inner = findDiffEnd(childA.content, childB.content, posA - 1, posB - 1);
|
|
52
|
+
if (inner)
|
|
53
|
+
return inner;
|
|
54
|
+
}
|
|
55
|
+
posA -= size;
|
|
56
|
+
posB -= size;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
var Fragment = class _Fragment {
|
|
60
|
+
/**
|
|
61
|
+
@internal
|
|
62
|
+
*/
|
|
63
|
+
constructor(content, size) {
|
|
64
|
+
this.content = content;
|
|
65
|
+
this.size = size || 0;
|
|
66
|
+
if (size == null)
|
|
67
|
+
for (let i = 0; i < content.length; i++)
|
|
68
|
+
this.size += content[i].nodeSize;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
Invoke a callback for all descendant nodes between the given two
|
|
72
|
+
positions (relative to start of this fragment). Doesn't descend
|
|
73
|
+
into a node when the callback returns `false`.
|
|
74
|
+
*/
|
|
75
|
+
nodesBetween(from, to, f, nodeStart = 0, parent) {
|
|
76
|
+
for (let i = 0, pos = 0; pos < to; i++) {
|
|
77
|
+
let child = this.content[i], end = pos + child.nodeSize;
|
|
78
|
+
if (end > from && f(child, nodeStart + pos, parent || null, i) !== false && child.content.size) {
|
|
79
|
+
let start = pos + 1;
|
|
80
|
+
child.nodesBetween(Math.max(0, from - start), Math.min(child.content.size, to - start), f, nodeStart + start);
|
|
81
|
+
}
|
|
82
|
+
pos = end;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
Call the given callback for every descendant node. `pos` will be
|
|
87
|
+
relative to the start of the fragment. The callback may return
|
|
88
|
+
`false` to prevent traversal of a given node's children.
|
|
89
|
+
*/
|
|
90
|
+
descendants(f) {
|
|
91
|
+
this.nodesBetween(0, this.size, f);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
Extract the text between `from` and `to`. See the same method on
|
|
95
|
+
[`Node`](https://prosemirror.net/docs/ref/#model.Node.textBetween).
|
|
96
|
+
*/
|
|
97
|
+
textBetween(from, to, blockSeparator, leafText) {
|
|
98
|
+
let text = "", first = true;
|
|
99
|
+
this.nodesBetween(from, to, (node, pos) => {
|
|
100
|
+
let nodeText = node.isText ? node.text.slice(Math.max(from, pos) - pos, to - pos) : !node.isLeaf ? "" : leafText ? typeof leafText === "function" ? leafText(node) : leafText : node.type.spec.leafText ? node.type.spec.leafText(node) : "";
|
|
101
|
+
if (node.isBlock && (node.isLeaf && nodeText || node.isTextblock) && blockSeparator) {
|
|
102
|
+
if (first)
|
|
103
|
+
first = false;
|
|
104
|
+
else
|
|
105
|
+
text += blockSeparator;
|
|
106
|
+
}
|
|
107
|
+
text += nodeText;
|
|
108
|
+
}, 0);
|
|
109
|
+
return text;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
Create a new fragment containing the combined content of this
|
|
113
|
+
fragment and the other.
|
|
114
|
+
*/
|
|
115
|
+
append(other) {
|
|
116
|
+
if (!other.size)
|
|
117
|
+
return this;
|
|
118
|
+
if (!this.size)
|
|
119
|
+
return other;
|
|
120
|
+
let last = this.lastChild, first = other.firstChild, content = this.content.slice(), i = 0;
|
|
121
|
+
if (last.isText && last.sameMarkup(first)) {
|
|
122
|
+
content[content.length - 1] = last.withText(last.text + first.text);
|
|
123
|
+
i = 1;
|
|
124
|
+
}
|
|
125
|
+
for (; i < other.content.length; i++)
|
|
126
|
+
content.push(other.content[i]);
|
|
127
|
+
return new _Fragment(content, this.size + other.size);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
Cut out the sub-fragment between the two given positions.
|
|
131
|
+
*/
|
|
132
|
+
cut(from, to = this.size) {
|
|
133
|
+
if (from == 0 && to == this.size)
|
|
134
|
+
return this;
|
|
135
|
+
let result = [], size = 0;
|
|
136
|
+
if (to > from)
|
|
137
|
+
for (let i = 0, pos = 0; pos < to; i++) {
|
|
138
|
+
let child = this.content[i], end = pos + child.nodeSize;
|
|
139
|
+
if (end > from) {
|
|
140
|
+
if (pos < from || end > to) {
|
|
141
|
+
if (child.isText)
|
|
142
|
+
child = child.cut(Math.max(0, from - pos), Math.min(child.text.length, to - pos));
|
|
143
|
+
else
|
|
144
|
+
child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1));
|
|
145
|
+
}
|
|
146
|
+
result.push(child);
|
|
147
|
+
size += child.nodeSize;
|
|
148
|
+
}
|
|
149
|
+
pos = end;
|
|
150
|
+
}
|
|
151
|
+
return new _Fragment(result, size);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
@internal
|
|
155
|
+
*/
|
|
156
|
+
cutByIndex(from, to) {
|
|
157
|
+
if (from == to)
|
|
158
|
+
return _Fragment.empty;
|
|
159
|
+
if (from == 0 && to == this.content.length)
|
|
160
|
+
return this;
|
|
161
|
+
return new _Fragment(this.content.slice(from, to));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
Create a new fragment in which the node at the given index is
|
|
165
|
+
replaced by the given node.
|
|
166
|
+
*/
|
|
167
|
+
replaceChild(index, node) {
|
|
168
|
+
let current = this.content[index];
|
|
169
|
+
if (current == node)
|
|
170
|
+
return this;
|
|
171
|
+
let copy = this.content.slice();
|
|
172
|
+
let size = this.size + node.nodeSize - current.nodeSize;
|
|
173
|
+
copy[index] = node;
|
|
174
|
+
return new _Fragment(copy, size);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
Create a new fragment by prepending the given node to this
|
|
178
|
+
fragment.
|
|
179
|
+
*/
|
|
180
|
+
addToStart(node) {
|
|
181
|
+
return new _Fragment([node].concat(this.content), this.size + node.nodeSize);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
Create a new fragment by appending the given node to this
|
|
185
|
+
fragment.
|
|
186
|
+
*/
|
|
187
|
+
addToEnd(node) {
|
|
188
|
+
return new _Fragment(this.content.concat(node), this.size + node.nodeSize);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
Compare this fragment to another one.
|
|
192
|
+
*/
|
|
193
|
+
eq(other) {
|
|
194
|
+
if (this.content.length != other.content.length)
|
|
195
|
+
return false;
|
|
196
|
+
for (let i = 0; i < this.content.length; i++)
|
|
197
|
+
if (!this.content[i].eq(other.content[i]))
|
|
198
|
+
return false;
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
The first child of the fragment, or `null` if it is empty.
|
|
203
|
+
*/
|
|
204
|
+
get firstChild() {
|
|
205
|
+
return this.content.length ? this.content[0] : null;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
The last child of the fragment, or `null` if it is empty.
|
|
209
|
+
*/
|
|
210
|
+
get lastChild() {
|
|
211
|
+
return this.content.length ? this.content[this.content.length - 1] : null;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
The number of child nodes in this fragment.
|
|
215
|
+
*/
|
|
216
|
+
get childCount() {
|
|
217
|
+
return this.content.length;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
Get the child node at the given index. Raise an error when the
|
|
221
|
+
index is out of range.
|
|
222
|
+
*/
|
|
223
|
+
child(index) {
|
|
224
|
+
let found2 = this.content[index];
|
|
225
|
+
if (!found2)
|
|
226
|
+
throw new RangeError("Index " + index + " out of range for " + this);
|
|
227
|
+
return found2;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
Get the child node at the given index, if it exists.
|
|
231
|
+
*/
|
|
232
|
+
maybeChild(index) {
|
|
233
|
+
return this.content[index] || null;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
Call `f` for every child node, passing the node, its offset
|
|
237
|
+
into this parent node, and its index.
|
|
238
|
+
*/
|
|
239
|
+
forEach(f) {
|
|
240
|
+
for (let i = 0, p = 0; i < this.content.length; i++) {
|
|
241
|
+
let child = this.content[i];
|
|
242
|
+
f(child, p, i);
|
|
243
|
+
p += child.nodeSize;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
Find the first position at which this fragment and another
|
|
248
|
+
fragment differ, or `null` if they are the same.
|
|
249
|
+
*/
|
|
250
|
+
findDiffStart(other, pos = 0) {
|
|
251
|
+
return findDiffStart(this, other, pos);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
Find the first position, searching from the end, at which this
|
|
255
|
+
fragment and the given fragment differ, or `null` if they are
|
|
256
|
+
the same. Since this position will not be the same in both
|
|
257
|
+
nodes, an object with two separate positions is returned.
|
|
258
|
+
*/
|
|
259
|
+
findDiffEnd(other, pos = this.size, otherPos = other.size) {
|
|
260
|
+
return findDiffEnd(this, other, pos, otherPos);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
Find the index and inner offset corresponding to a given relative
|
|
264
|
+
position in this fragment. The result object will be reused
|
|
265
|
+
(overwritten) the next time the function is called. @internal
|
|
266
|
+
*/
|
|
267
|
+
findIndex(pos) {
|
|
268
|
+
if (pos == 0)
|
|
269
|
+
return retIndex(0, pos);
|
|
270
|
+
if (pos == this.size)
|
|
271
|
+
return retIndex(this.content.length, pos);
|
|
272
|
+
if (pos > this.size || pos < 0)
|
|
273
|
+
throw new RangeError(`Position ${pos} outside of fragment (${this})`);
|
|
274
|
+
for (let i = 0, curPos = 0; ; i++) {
|
|
275
|
+
let cur = this.child(i), end = curPos + cur.nodeSize;
|
|
276
|
+
if (end >= pos) {
|
|
277
|
+
if (end == pos)
|
|
278
|
+
return retIndex(i + 1, end);
|
|
279
|
+
return retIndex(i, curPos);
|
|
280
|
+
}
|
|
281
|
+
curPos = end;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
Return a debugging string that describes this fragment.
|
|
286
|
+
*/
|
|
287
|
+
toString() {
|
|
288
|
+
return "<" + this.toStringInner() + ">";
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
@internal
|
|
292
|
+
*/
|
|
293
|
+
toStringInner() {
|
|
294
|
+
return this.content.join(", ");
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
Create a JSON-serializeable representation of this fragment.
|
|
298
|
+
*/
|
|
299
|
+
toJSON() {
|
|
300
|
+
return this.content.length ? this.content.map((n) => n.toJSON()) : null;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
Deserialize a fragment from its JSON representation.
|
|
304
|
+
*/
|
|
305
|
+
static fromJSON(schema, value) {
|
|
306
|
+
if (!value)
|
|
307
|
+
return _Fragment.empty;
|
|
308
|
+
if (!Array.isArray(value))
|
|
309
|
+
throw new RangeError("Invalid input for Fragment.fromJSON");
|
|
310
|
+
return new _Fragment(value.map(schema.nodeFromJSON));
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
Build a fragment from an array of nodes. Ensures that adjacent
|
|
314
|
+
text nodes with the same marks are joined together.
|
|
315
|
+
*/
|
|
316
|
+
static fromArray(array) {
|
|
317
|
+
if (!array.length)
|
|
318
|
+
return _Fragment.empty;
|
|
319
|
+
let joined, size = 0;
|
|
320
|
+
for (let i = 0; i < array.length; i++) {
|
|
321
|
+
let node = array[i];
|
|
322
|
+
size += node.nodeSize;
|
|
323
|
+
if (i && node.isText && array[i - 1].sameMarkup(node)) {
|
|
324
|
+
if (!joined)
|
|
325
|
+
joined = array.slice(0, i);
|
|
326
|
+
joined[joined.length - 1] = node.withText(joined[joined.length - 1].text + node.text);
|
|
327
|
+
} else if (joined) {
|
|
328
|
+
joined.push(node);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return new _Fragment(joined || array, size);
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
Create a fragment from something that can be interpreted as a
|
|
335
|
+
set of nodes. For `null`, it returns the empty fragment. For a
|
|
336
|
+
fragment, the fragment itself. For a node or array of nodes, a
|
|
337
|
+
fragment containing those nodes.
|
|
338
|
+
*/
|
|
339
|
+
static from(nodes) {
|
|
340
|
+
if (!nodes)
|
|
341
|
+
return _Fragment.empty;
|
|
342
|
+
if (nodes instanceof _Fragment)
|
|
343
|
+
return nodes;
|
|
344
|
+
if (Array.isArray(nodes))
|
|
345
|
+
return this.fromArray(nodes);
|
|
346
|
+
if (nodes.attrs)
|
|
347
|
+
return new _Fragment([nodes], nodes.nodeSize);
|
|
348
|
+
throw new RangeError("Can not convert " + nodes + " to a Fragment" + (nodes.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : ""));
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
Fragment.empty = new Fragment([], 0);
|
|
352
|
+
var found = { index: 0, offset: 0 };
|
|
353
|
+
function retIndex(index, offset) {
|
|
354
|
+
found.index = index;
|
|
355
|
+
found.offset = offset;
|
|
356
|
+
return found;
|
|
357
|
+
}
|
|
358
|
+
function compareDeep(a, b) {
|
|
359
|
+
if (a === b)
|
|
360
|
+
return true;
|
|
361
|
+
if (!(a && typeof a == "object") || !(b && typeof b == "object"))
|
|
362
|
+
return false;
|
|
363
|
+
let array = Array.isArray(a);
|
|
364
|
+
if (Array.isArray(b) != array)
|
|
365
|
+
return false;
|
|
366
|
+
if (array) {
|
|
367
|
+
if (a.length != b.length)
|
|
368
|
+
return false;
|
|
369
|
+
for (let i = 0; i < a.length; i++)
|
|
370
|
+
if (!compareDeep(a[i], b[i]))
|
|
371
|
+
return false;
|
|
372
|
+
} else {
|
|
373
|
+
for (let p in a)
|
|
374
|
+
if (!(p in b) || !compareDeep(a[p], b[p]))
|
|
375
|
+
return false;
|
|
376
|
+
for (let p in b)
|
|
377
|
+
if (!(p in a))
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
var Mark = class _Mark {
|
|
383
|
+
/**
|
|
384
|
+
@internal
|
|
385
|
+
*/
|
|
386
|
+
constructor(type, attrs) {
|
|
387
|
+
this.type = type;
|
|
388
|
+
this.attrs = attrs;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
Given a set of marks, create a new set which contains this one as
|
|
392
|
+
well, in the right position. If this mark is already in the set,
|
|
393
|
+
the set itself is returned. If any marks that are set to be
|
|
394
|
+
[exclusive](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) with this mark are present,
|
|
395
|
+
those are replaced by this one.
|
|
396
|
+
*/
|
|
397
|
+
addToSet(set) {
|
|
398
|
+
let copy, placed = false;
|
|
399
|
+
for (let i = 0; i < set.length; i++) {
|
|
400
|
+
let other = set[i];
|
|
401
|
+
if (this.eq(other))
|
|
402
|
+
return set;
|
|
403
|
+
if (this.type.excludes(other.type)) {
|
|
404
|
+
if (!copy)
|
|
405
|
+
copy = set.slice(0, i);
|
|
406
|
+
} else if (other.type.excludes(this.type)) {
|
|
407
|
+
return set;
|
|
408
|
+
} else {
|
|
409
|
+
if (!placed && other.type.rank > this.type.rank) {
|
|
410
|
+
if (!copy)
|
|
411
|
+
copy = set.slice(0, i);
|
|
412
|
+
copy.push(this);
|
|
413
|
+
placed = true;
|
|
414
|
+
}
|
|
415
|
+
if (copy)
|
|
416
|
+
copy.push(other);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (!copy)
|
|
420
|
+
copy = set.slice();
|
|
421
|
+
if (!placed)
|
|
422
|
+
copy.push(this);
|
|
423
|
+
return copy;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
Remove this mark from the given set, returning a new set. If this
|
|
427
|
+
mark is not in the set, the set itself is returned.
|
|
428
|
+
*/
|
|
429
|
+
removeFromSet(set) {
|
|
430
|
+
for (let i = 0; i < set.length; i++)
|
|
431
|
+
if (this.eq(set[i]))
|
|
432
|
+
return set.slice(0, i).concat(set.slice(i + 1));
|
|
433
|
+
return set;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
Test whether this mark is in the given set of marks.
|
|
437
|
+
*/
|
|
438
|
+
isInSet(set) {
|
|
439
|
+
for (let i = 0; i < set.length; i++)
|
|
440
|
+
if (this.eq(set[i]))
|
|
441
|
+
return true;
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
Test whether this mark has the same type and attributes as
|
|
446
|
+
another mark.
|
|
447
|
+
*/
|
|
448
|
+
eq(other) {
|
|
449
|
+
return this == other || this.type == other.type && compareDeep(this.attrs, other.attrs);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
Convert this mark to a JSON-serializeable representation.
|
|
453
|
+
*/
|
|
454
|
+
toJSON() {
|
|
455
|
+
let obj = { type: this.type.name };
|
|
456
|
+
for (let _ in this.attrs) {
|
|
457
|
+
obj.attrs = this.attrs;
|
|
458
|
+
break;
|
|
459
|
+
}
|
|
460
|
+
return obj;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
Deserialize a mark from JSON.
|
|
464
|
+
*/
|
|
465
|
+
static fromJSON(schema, json) {
|
|
466
|
+
if (!json)
|
|
467
|
+
throw new RangeError("Invalid input for Mark.fromJSON");
|
|
468
|
+
let type = schema.marks[json.type];
|
|
469
|
+
if (!type)
|
|
470
|
+
throw new RangeError(`There is no mark type ${json.type} in this schema`);
|
|
471
|
+
let mark = type.create(json.attrs);
|
|
472
|
+
type.checkAttrs(mark.attrs);
|
|
473
|
+
return mark;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
Test whether two sets of marks are identical.
|
|
477
|
+
*/
|
|
478
|
+
static sameSet(a, b) {
|
|
479
|
+
if (a == b)
|
|
480
|
+
return true;
|
|
481
|
+
if (a.length != b.length)
|
|
482
|
+
return false;
|
|
483
|
+
for (let i = 0; i < a.length; i++)
|
|
484
|
+
if (!a[i].eq(b[i]))
|
|
485
|
+
return false;
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
Create a properly sorted mark set from null, a single mark, or an
|
|
490
|
+
unsorted array of marks.
|
|
491
|
+
*/
|
|
492
|
+
static setFrom(marks) {
|
|
493
|
+
if (!marks || Array.isArray(marks) && marks.length == 0)
|
|
494
|
+
return _Mark.none;
|
|
495
|
+
if (marks instanceof _Mark)
|
|
496
|
+
return [marks];
|
|
497
|
+
let copy = marks.slice();
|
|
498
|
+
copy.sort((a, b) => a.type.rank - b.type.rank);
|
|
499
|
+
return copy;
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
Mark.none = [];
|
|
503
|
+
var ReplaceError = class extends Error {
|
|
504
|
+
};
|
|
505
|
+
var Slice = class _Slice {
|
|
506
|
+
/**
|
|
507
|
+
Create a slice. When specifying a non-zero open depth, you must
|
|
508
|
+
make sure that there are nodes of at least that depth at the
|
|
509
|
+
appropriate side of the fragment—i.e. if the fragment is an
|
|
510
|
+
empty paragraph node, `openStart` and `openEnd` can't be greater
|
|
511
|
+
than 1.
|
|
512
|
+
|
|
513
|
+
It is not necessary for the content of open nodes to conform to
|
|
514
|
+
the schema's content constraints, though it should be a valid
|
|
515
|
+
start/end/middle for such a node, depending on which sides are
|
|
516
|
+
open.
|
|
517
|
+
*/
|
|
518
|
+
constructor(content, openStart, openEnd) {
|
|
519
|
+
this.content = content;
|
|
520
|
+
this.openStart = openStart;
|
|
521
|
+
this.openEnd = openEnd;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
The size this slice would add when inserted into a document.
|
|
525
|
+
*/
|
|
526
|
+
get size() {
|
|
527
|
+
return this.content.size - this.openStart - this.openEnd;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
@internal
|
|
531
|
+
*/
|
|
532
|
+
insertAt(pos, fragment) {
|
|
533
|
+
let content = insertInto(this.content, pos + this.openStart, fragment);
|
|
534
|
+
return content && new _Slice(content, this.openStart, this.openEnd);
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
@internal
|
|
538
|
+
*/
|
|
539
|
+
removeBetween(from, to) {
|
|
540
|
+
return new _Slice(removeRange(this.content, from + this.openStart, to + this.openStart), this.openStart, this.openEnd);
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
Tests whether this slice is equal to another slice.
|
|
544
|
+
*/
|
|
545
|
+
eq(other) {
|
|
546
|
+
return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd;
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
@internal
|
|
550
|
+
*/
|
|
551
|
+
toString() {
|
|
552
|
+
return this.content + "(" + this.openStart + "," + this.openEnd + ")";
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
Convert a slice to a JSON-serializable representation.
|
|
556
|
+
*/
|
|
557
|
+
toJSON() {
|
|
558
|
+
if (!this.content.size)
|
|
559
|
+
return null;
|
|
560
|
+
let json = { content: this.content.toJSON() };
|
|
561
|
+
if (this.openStart > 0)
|
|
562
|
+
json.openStart = this.openStart;
|
|
563
|
+
if (this.openEnd > 0)
|
|
564
|
+
json.openEnd = this.openEnd;
|
|
565
|
+
return json;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
Deserialize a slice from its JSON representation.
|
|
569
|
+
*/
|
|
570
|
+
static fromJSON(schema, json) {
|
|
571
|
+
if (!json)
|
|
572
|
+
return _Slice.empty;
|
|
573
|
+
let openStart = json.openStart || 0, openEnd = json.openEnd || 0;
|
|
574
|
+
if (typeof openStart != "number" || typeof openEnd != "number")
|
|
575
|
+
throw new RangeError("Invalid input for Slice.fromJSON");
|
|
576
|
+
return new _Slice(Fragment.fromJSON(schema, json.content), openStart, openEnd);
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
Create a slice from a fragment by taking the maximum possible
|
|
580
|
+
open value on both side of the fragment.
|
|
581
|
+
*/
|
|
582
|
+
static maxOpen(fragment, openIsolating = true) {
|
|
583
|
+
let openStart = 0, openEnd = 0;
|
|
584
|
+
for (let n = fragment.firstChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.firstChild)
|
|
585
|
+
openStart++;
|
|
586
|
+
for (let n = fragment.lastChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.lastChild)
|
|
587
|
+
openEnd++;
|
|
588
|
+
return new _Slice(fragment, openStart, openEnd);
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
Slice.empty = new Slice(Fragment.empty, 0, 0);
|
|
592
|
+
function removeRange(content, from, to) {
|
|
593
|
+
let { index, offset } = content.findIndex(from), child = content.maybeChild(index);
|
|
594
|
+
let { index: indexTo, offset: offsetTo } = content.findIndex(to);
|
|
595
|
+
if (offset == from || child.isText) {
|
|
596
|
+
if (offsetTo != to && !content.child(indexTo).isText)
|
|
597
|
+
throw new RangeError("Removing non-flat range");
|
|
598
|
+
return content.cut(0, from).append(content.cut(to));
|
|
599
|
+
}
|
|
600
|
+
if (index != indexTo)
|
|
601
|
+
throw new RangeError("Removing non-flat range");
|
|
602
|
+
return content.replaceChild(index, child.copy(removeRange(child.content, from - offset - 1, to - offset - 1)));
|
|
603
|
+
}
|
|
604
|
+
function insertInto(content, dist, insert, parent) {
|
|
605
|
+
let { index, offset } = content.findIndex(dist), child = content.maybeChild(index);
|
|
606
|
+
if (offset == dist || child.isText) {
|
|
607
|
+
if (parent && !parent.canReplace(index, index, insert))
|
|
608
|
+
return null;
|
|
609
|
+
return content.cut(0, dist).append(insert).append(content.cut(dist));
|
|
610
|
+
}
|
|
611
|
+
let inner = insertInto(child.content, dist - offset - 1, insert, child);
|
|
612
|
+
return inner && content.replaceChild(index, child.copy(inner));
|
|
613
|
+
}
|
|
614
|
+
function replace($from, $to, slice) {
|
|
615
|
+
if (slice.openStart > $from.depth)
|
|
616
|
+
throw new ReplaceError("Inserted content deeper than insertion position");
|
|
617
|
+
if ($from.depth - slice.openStart != $to.depth - slice.openEnd)
|
|
618
|
+
throw new ReplaceError("Inconsistent open depths");
|
|
619
|
+
return replaceOuter($from, $to, slice, 0);
|
|
620
|
+
}
|
|
621
|
+
function replaceOuter($from, $to, slice, depth) {
|
|
622
|
+
let index = $from.index(depth), node = $from.node(depth);
|
|
623
|
+
if (index == $to.index(depth) && depth < $from.depth - slice.openStart) {
|
|
624
|
+
let inner = replaceOuter($from, $to, slice, depth + 1);
|
|
625
|
+
return node.copy(node.content.replaceChild(index, inner));
|
|
626
|
+
} else if (!slice.content.size) {
|
|
627
|
+
return close(node, replaceTwoWay($from, $to, depth));
|
|
628
|
+
} else if (!slice.openStart && !slice.openEnd && $from.depth == depth && $to.depth == depth) {
|
|
629
|
+
let parent = $from.parent, content = parent.content;
|
|
630
|
+
return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset)));
|
|
631
|
+
} else {
|
|
632
|
+
let { start, end } = prepareSliceForReplace(slice, $from);
|
|
633
|
+
return close(node, replaceThreeWay($from, start, end, $to, depth));
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
function checkJoin(main, sub) {
|
|
637
|
+
if (!sub.type.compatibleContent(main.type))
|
|
638
|
+
throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name);
|
|
639
|
+
}
|
|
640
|
+
function joinable($before, $after, depth) {
|
|
641
|
+
let node = $before.node(depth);
|
|
642
|
+
checkJoin(node, $after.node(depth));
|
|
643
|
+
return node;
|
|
644
|
+
}
|
|
645
|
+
function addNode(child, target) {
|
|
646
|
+
let last = target.length - 1;
|
|
647
|
+
if (last >= 0 && child.isText && child.sameMarkup(target[last]))
|
|
648
|
+
target[last] = child.withText(target[last].text + child.text);
|
|
649
|
+
else
|
|
650
|
+
target.push(child);
|
|
651
|
+
}
|
|
652
|
+
function addRange($start, $end, depth, target) {
|
|
653
|
+
let node = ($end || $start).node(depth);
|
|
654
|
+
let startIndex = 0, endIndex = $end ? $end.index(depth) : node.childCount;
|
|
655
|
+
if ($start) {
|
|
656
|
+
startIndex = $start.index(depth);
|
|
657
|
+
if ($start.depth > depth) {
|
|
658
|
+
startIndex++;
|
|
659
|
+
} else if ($start.textOffset) {
|
|
660
|
+
addNode($start.nodeAfter, target);
|
|
661
|
+
startIndex++;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
for (let i = startIndex; i < endIndex; i++)
|
|
665
|
+
addNode(node.child(i), target);
|
|
666
|
+
if ($end && $end.depth == depth && $end.textOffset)
|
|
667
|
+
addNode($end.nodeBefore, target);
|
|
668
|
+
}
|
|
669
|
+
function close(node, content) {
|
|
670
|
+
node.type.checkContent(content);
|
|
671
|
+
return node.copy(content);
|
|
672
|
+
}
|
|
673
|
+
function replaceThreeWay($from, $start, $end, $to, depth) {
|
|
674
|
+
let openStart = $from.depth > depth && joinable($from, $start, depth + 1);
|
|
675
|
+
let openEnd = $to.depth > depth && joinable($end, $to, depth + 1);
|
|
676
|
+
let content = [];
|
|
677
|
+
addRange(null, $from, depth, content);
|
|
678
|
+
if (openStart && openEnd && $start.index(depth) == $end.index(depth)) {
|
|
679
|
+
checkJoin(openStart, openEnd);
|
|
680
|
+
addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content);
|
|
681
|
+
} else {
|
|
682
|
+
if (openStart)
|
|
683
|
+
addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content);
|
|
684
|
+
addRange($start, $end, depth, content);
|
|
685
|
+
if (openEnd)
|
|
686
|
+
addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content);
|
|
687
|
+
}
|
|
688
|
+
addRange($to, null, depth, content);
|
|
689
|
+
return new Fragment(content);
|
|
690
|
+
}
|
|
691
|
+
function replaceTwoWay($from, $to, depth) {
|
|
692
|
+
let content = [];
|
|
693
|
+
addRange(null, $from, depth, content);
|
|
694
|
+
if ($from.depth > depth) {
|
|
695
|
+
let type = joinable($from, $to, depth + 1);
|
|
696
|
+
addNode(close(type, replaceTwoWay($from, $to, depth + 1)), content);
|
|
697
|
+
}
|
|
698
|
+
addRange($to, null, depth, content);
|
|
699
|
+
return new Fragment(content);
|
|
700
|
+
}
|
|
701
|
+
function prepareSliceForReplace(slice, $along) {
|
|
702
|
+
let extra = $along.depth - slice.openStart, parent = $along.node(extra);
|
|
703
|
+
let node = parent.copy(slice.content);
|
|
704
|
+
for (let i = extra - 1; i >= 0; i--)
|
|
705
|
+
node = $along.node(i).copy(Fragment.from(node));
|
|
706
|
+
return {
|
|
707
|
+
start: node.resolveNoCache(slice.openStart + extra),
|
|
708
|
+
end: node.resolveNoCache(node.content.size - slice.openEnd - extra)
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
var ResolvedPos = class _ResolvedPos {
|
|
712
|
+
/**
|
|
713
|
+
@internal
|
|
714
|
+
*/
|
|
715
|
+
constructor(pos, path, parentOffset) {
|
|
716
|
+
this.pos = pos;
|
|
717
|
+
this.path = path;
|
|
718
|
+
this.parentOffset = parentOffset;
|
|
719
|
+
this.depth = path.length / 3 - 1;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
@internal
|
|
723
|
+
*/
|
|
724
|
+
resolveDepth(val) {
|
|
725
|
+
if (val == null)
|
|
726
|
+
return this.depth;
|
|
727
|
+
if (val < 0)
|
|
728
|
+
return this.depth + val;
|
|
729
|
+
return val;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
The parent node that the position points into. Note that even if
|
|
733
|
+
a position points into a text node, that node is not considered
|
|
734
|
+
the parent—text nodes are ‘flat’ in this model, and have no content.
|
|
735
|
+
*/
|
|
736
|
+
get parent() {
|
|
737
|
+
return this.node(this.depth);
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
The root node in which the position was resolved.
|
|
741
|
+
*/
|
|
742
|
+
get doc() {
|
|
743
|
+
return this.node(0);
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
The ancestor node at the given level. `p.node(p.depth)` is the
|
|
747
|
+
same as `p.parent`.
|
|
748
|
+
*/
|
|
749
|
+
node(depth) {
|
|
750
|
+
return this.path[this.resolveDepth(depth) * 3];
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
The index into the ancestor at the given level. If this points
|
|
754
|
+
at the 3rd node in the 2nd paragraph on the top level, for
|
|
755
|
+
example, `p.index(0)` is 1 and `p.index(1)` is 2.
|
|
756
|
+
*/
|
|
757
|
+
index(depth) {
|
|
758
|
+
return this.path[this.resolveDepth(depth) * 3 + 1];
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
The index pointing after this position into the ancestor at the
|
|
762
|
+
given level.
|
|
763
|
+
*/
|
|
764
|
+
indexAfter(depth) {
|
|
765
|
+
depth = this.resolveDepth(depth);
|
|
766
|
+
return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1);
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
The (absolute) position at the start of the node at the given
|
|
770
|
+
level.
|
|
771
|
+
*/
|
|
772
|
+
start(depth) {
|
|
773
|
+
depth = this.resolveDepth(depth);
|
|
774
|
+
return depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
The (absolute) position at the end of the node at the given
|
|
778
|
+
level.
|
|
779
|
+
*/
|
|
780
|
+
end(depth) {
|
|
781
|
+
depth = this.resolveDepth(depth);
|
|
782
|
+
return this.start(depth) + this.node(depth).content.size;
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
The (absolute) position directly before the wrapping node at the
|
|
786
|
+
given level, or, when `depth` is `this.depth + 1`, the original
|
|
787
|
+
position.
|
|
788
|
+
*/
|
|
789
|
+
before(depth) {
|
|
790
|
+
depth = this.resolveDepth(depth);
|
|
791
|
+
if (!depth)
|
|
792
|
+
throw new RangeError("There is no position before the top-level node");
|
|
793
|
+
return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1];
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
The (absolute) position directly after the wrapping node at the
|
|
797
|
+
given level, or the original position when `depth` is `this.depth + 1`.
|
|
798
|
+
*/
|
|
799
|
+
after(depth) {
|
|
800
|
+
depth = this.resolveDepth(depth);
|
|
801
|
+
if (!depth)
|
|
802
|
+
throw new RangeError("There is no position after the top-level node");
|
|
803
|
+
return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize;
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
When this position points into a text node, this returns the
|
|
807
|
+
distance between the position and the start of the text node.
|
|
808
|
+
Will be zero for positions that point between nodes.
|
|
809
|
+
*/
|
|
810
|
+
get textOffset() {
|
|
811
|
+
return this.pos - this.path[this.path.length - 1];
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
Get the node directly after the position, if any. If the position
|
|
815
|
+
points into a text node, only the part of that node after the
|
|
816
|
+
position is returned.
|
|
817
|
+
*/
|
|
818
|
+
get nodeAfter() {
|
|
819
|
+
let parent = this.parent, index = this.index(this.depth);
|
|
820
|
+
if (index == parent.childCount)
|
|
821
|
+
return null;
|
|
822
|
+
let dOff = this.pos - this.path[this.path.length - 1], child = parent.child(index);
|
|
823
|
+
return dOff ? parent.child(index).cut(dOff) : child;
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
Get the node directly before the position, if any. If the
|
|
827
|
+
position points into a text node, only the part of that node
|
|
828
|
+
before the position is returned.
|
|
829
|
+
*/
|
|
830
|
+
get nodeBefore() {
|
|
831
|
+
let index = this.index(this.depth);
|
|
832
|
+
let dOff = this.pos - this.path[this.path.length - 1];
|
|
833
|
+
if (dOff)
|
|
834
|
+
return this.parent.child(index).cut(0, dOff);
|
|
835
|
+
return index == 0 ? null : this.parent.child(index - 1);
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
Get the position at the given index in the parent node at the
|
|
839
|
+
given depth (which defaults to `this.depth`).
|
|
840
|
+
*/
|
|
841
|
+
posAtIndex(index, depth) {
|
|
842
|
+
depth = this.resolveDepth(depth);
|
|
843
|
+
let node = this.path[depth * 3], pos = depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
|
|
844
|
+
for (let i = 0; i < index; i++)
|
|
845
|
+
pos += node.child(i).nodeSize;
|
|
846
|
+
return pos;
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
Get the marks at this position, factoring in the surrounding
|
|
850
|
+
marks' [`inclusive`](https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive) property. If the
|
|
851
|
+
position is at the start of a non-empty node, the marks of the
|
|
852
|
+
node after it (if any) are returned.
|
|
853
|
+
*/
|
|
854
|
+
marks() {
|
|
855
|
+
let parent = this.parent, index = this.index();
|
|
856
|
+
if (parent.content.size == 0)
|
|
857
|
+
return Mark.none;
|
|
858
|
+
if (this.textOffset)
|
|
859
|
+
return parent.child(index).marks;
|
|
860
|
+
let main = parent.maybeChild(index - 1), other = parent.maybeChild(index);
|
|
861
|
+
if (!main) {
|
|
862
|
+
let tmp = main;
|
|
863
|
+
main = other;
|
|
864
|
+
other = tmp;
|
|
865
|
+
}
|
|
866
|
+
let marks = main.marks;
|
|
867
|
+
for (var i = 0; i < marks.length; i++)
|
|
868
|
+
if (marks[i].type.spec.inclusive === false && (!other || !marks[i].isInSet(other.marks)))
|
|
869
|
+
marks = marks[i--].removeFromSet(marks);
|
|
870
|
+
return marks;
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
Get the marks after the current position, if any, except those
|
|
874
|
+
that are non-inclusive and not present at position `$end`. This
|
|
875
|
+
is mostly useful for getting the set of marks to preserve after a
|
|
876
|
+
deletion. Will return `null` if this position is at the end of
|
|
877
|
+
its parent node or its parent node isn't a textblock (in which
|
|
878
|
+
case no marks should be preserved).
|
|
879
|
+
*/
|
|
880
|
+
marksAcross($end) {
|
|
881
|
+
let after = this.parent.maybeChild(this.index());
|
|
882
|
+
if (!after || !after.isInline)
|
|
883
|
+
return null;
|
|
884
|
+
let marks = after.marks, next = $end.parent.maybeChild($end.index());
|
|
885
|
+
for (var i = 0; i < marks.length; i++)
|
|
886
|
+
if (marks[i].type.spec.inclusive === false && (!next || !marks[i].isInSet(next.marks)))
|
|
887
|
+
marks = marks[i--].removeFromSet(marks);
|
|
888
|
+
return marks;
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
The depth up to which this position and the given (non-resolved)
|
|
892
|
+
position share the same parent nodes.
|
|
893
|
+
*/
|
|
894
|
+
sharedDepth(pos) {
|
|
895
|
+
for (let depth = this.depth; depth > 0; depth--)
|
|
896
|
+
if (this.start(depth) <= pos && this.end(depth) >= pos)
|
|
897
|
+
return depth;
|
|
898
|
+
return 0;
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
Returns a range based on the place where this position and the
|
|
902
|
+
given position diverge around block content. If both point into
|
|
903
|
+
the same textblock, for example, a range around that textblock
|
|
904
|
+
will be returned. If they point into different blocks, the range
|
|
905
|
+
around those blocks in their shared ancestor is returned. You can
|
|
906
|
+
pass in an optional predicate that will be called with a parent
|
|
907
|
+
node to see if a range into that parent is acceptable.
|
|
908
|
+
*/
|
|
909
|
+
blockRange(other = this, pred) {
|
|
910
|
+
if (other.pos < this.pos)
|
|
911
|
+
return other.blockRange(this);
|
|
912
|
+
for (let d = this.depth - (this.parent.inlineContent || this.pos == other.pos ? 1 : 0); d >= 0; d--)
|
|
913
|
+
if (other.pos <= this.end(d) && (!pred || pred(this.node(d))))
|
|
914
|
+
return new NodeRange(this, other, d);
|
|
915
|
+
return null;
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
Query whether the given position shares the same parent node.
|
|
919
|
+
*/
|
|
920
|
+
sameParent(other) {
|
|
921
|
+
return this.pos - this.parentOffset == other.pos - other.parentOffset;
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
Return the greater of this and the given position.
|
|
925
|
+
*/
|
|
926
|
+
max(other) {
|
|
927
|
+
return other.pos > this.pos ? other : this;
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
Return the smaller of this and the given position.
|
|
931
|
+
*/
|
|
932
|
+
min(other) {
|
|
933
|
+
return other.pos < this.pos ? other : this;
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
@internal
|
|
937
|
+
*/
|
|
938
|
+
toString() {
|
|
939
|
+
let str = "";
|
|
940
|
+
for (let i = 1; i <= this.depth; i++)
|
|
941
|
+
str += (str ? "/" : "") + this.node(i).type.name + "_" + this.index(i - 1);
|
|
942
|
+
return str + ":" + this.parentOffset;
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
@internal
|
|
946
|
+
*/
|
|
947
|
+
static resolve(doc, pos) {
|
|
948
|
+
if (!(pos >= 0 && pos <= doc.content.size))
|
|
949
|
+
throw new RangeError("Position " + pos + " out of range");
|
|
950
|
+
let path = [];
|
|
951
|
+
let start = 0, parentOffset = pos;
|
|
952
|
+
for (let node = doc; ; ) {
|
|
953
|
+
let { index, offset } = node.content.findIndex(parentOffset);
|
|
954
|
+
let rem = parentOffset - offset;
|
|
955
|
+
path.push(node, index, start + offset);
|
|
956
|
+
if (!rem)
|
|
957
|
+
break;
|
|
958
|
+
node = node.child(index);
|
|
959
|
+
if (node.isText)
|
|
960
|
+
break;
|
|
961
|
+
parentOffset = rem - 1;
|
|
962
|
+
start += offset + 1;
|
|
963
|
+
}
|
|
964
|
+
return new _ResolvedPos(pos, path, parentOffset);
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
@internal
|
|
968
|
+
*/
|
|
969
|
+
static resolveCached(doc, pos) {
|
|
970
|
+
let cache = resolveCache.get(doc);
|
|
971
|
+
if (cache) {
|
|
972
|
+
for (let i = 0; i < cache.elts.length; i++) {
|
|
973
|
+
let elt = cache.elts[i];
|
|
974
|
+
if (elt.pos == pos)
|
|
975
|
+
return elt;
|
|
976
|
+
}
|
|
977
|
+
} else {
|
|
978
|
+
resolveCache.set(doc, cache = new ResolveCache());
|
|
979
|
+
}
|
|
980
|
+
let result = cache.elts[cache.i] = _ResolvedPos.resolve(doc, pos);
|
|
981
|
+
cache.i = (cache.i + 1) % resolveCacheSize;
|
|
982
|
+
return result;
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
var ResolveCache = class {
|
|
986
|
+
constructor() {
|
|
987
|
+
this.elts = [];
|
|
988
|
+
this.i = 0;
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
var resolveCacheSize = 12;
|
|
992
|
+
var resolveCache = /* @__PURE__ */ new WeakMap();
|
|
993
|
+
var NodeRange = class {
|
|
994
|
+
/**
|
|
995
|
+
Construct a node range. `$from` and `$to` should point into the
|
|
996
|
+
same node until at least the given `depth`, since a node range
|
|
997
|
+
denotes an adjacent set of nodes in a single parent node.
|
|
998
|
+
*/
|
|
999
|
+
constructor($from, $to, depth) {
|
|
1000
|
+
this.$from = $from;
|
|
1001
|
+
this.$to = $to;
|
|
1002
|
+
this.depth = depth;
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
The position at the start of the range.
|
|
1006
|
+
*/
|
|
1007
|
+
get start() {
|
|
1008
|
+
return this.$from.before(this.depth + 1);
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
The position at the end of the range.
|
|
1012
|
+
*/
|
|
1013
|
+
get end() {
|
|
1014
|
+
return this.$to.after(this.depth + 1);
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
The parent node that the range points into.
|
|
1018
|
+
*/
|
|
1019
|
+
get parent() {
|
|
1020
|
+
return this.$from.node(this.depth);
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
The start index of the range in the parent node.
|
|
1024
|
+
*/
|
|
1025
|
+
get startIndex() {
|
|
1026
|
+
return this.$from.index(this.depth);
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
The end index of the range in the parent node.
|
|
1030
|
+
*/
|
|
1031
|
+
get endIndex() {
|
|
1032
|
+
return this.$to.indexAfter(this.depth);
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
var emptyAttrs = /* @__PURE__ */ Object.create(null);
|
|
1036
|
+
var Node = class _Node {
|
|
1037
|
+
/**
|
|
1038
|
+
@internal
|
|
1039
|
+
*/
|
|
1040
|
+
constructor(type, attrs, content, marks = Mark.none) {
|
|
1041
|
+
this.type = type;
|
|
1042
|
+
this.attrs = attrs;
|
|
1043
|
+
this.marks = marks;
|
|
1044
|
+
this.content = content || Fragment.empty;
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
The array of this node's child nodes.
|
|
1048
|
+
*/
|
|
1049
|
+
get children() {
|
|
1050
|
+
return this.content.content;
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
The size of this node, as defined by the integer-based [indexing
|
|
1054
|
+
scheme](https://prosemirror.net/docs/guide/#doc.indexing). For text nodes, this is the
|
|
1055
|
+
amount of characters. For other leaf nodes, it is one. For
|
|
1056
|
+
non-leaf nodes, it is the size of the content plus two (the
|
|
1057
|
+
start and end token).
|
|
1058
|
+
*/
|
|
1059
|
+
get nodeSize() {
|
|
1060
|
+
return this.isLeaf ? 1 : 2 + this.content.size;
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
The number of children that the node has.
|
|
1064
|
+
*/
|
|
1065
|
+
get childCount() {
|
|
1066
|
+
return this.content.childCount;
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
Get the child node at the given index. Raises an error when the
|
|
1070
|
+
index is out of range.
|
|
1071
|
+
*/
|
|
1072
|
+
child(index) {
|
|
1073
|
+
return this.content.child(index);
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
Get the child node at the given index, if it exists.
|
|
1077
|
+
*/
|
|
1078
|
+
maybeChild(index) {
|
|
1079
|
+
return this.content.maybeChild(index);
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
Call `f` for every child node, passing the node, its offset
|
|
1083
|
+
into this parent node, and its index.
|
|
1084
|
+
*/
|
|
1085
|
+
forEach(f) {
|
|
1086
|
+
this.content.forEach(f);
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
Invoke a callback for all descendant nodes recursively between
|
|
1090
|
+
the given two positions that are relative to start of this
|
|
1091
|
+
node's content. The callback is invoked with the node, its
|
|
1092
|
+
position relative to the original node (method receiver),
|
|
1093
|
+
its parent node, and its child index. When the callback returns
|
|
1094
|
+
false for a given node, that node's children will not be
|
|
1095
|
+
recursed over. The last parameter can be used to specify a
|
|
1096
|
+
starting position to count from.
|
|
1097
|
+
*/
|
|
1098
|
+
nodesBetween(from, to, f, startPos = 0) {
|
|
1099
|
+
this.content.nodesBetween(from, to, f, startPos, this);
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
Call the given callback for every descendant node. Doesn't
|
|
1103
|
+
descend into a node when the callback returns `false`.
|
|
1104
|
+
*/
|
|
1105
|
+
descendants(f) {
|
|
1106
|
+
this.nodesBetween(0, this.content.size, f);
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
Concatenates all the text nodes found in this fragment and its
|
|
1110
|
+
children.
|
|
1111
|
+
*/
|
|
1112
|
+
get textContent() {
|
|
1113
|
+
return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, "");
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
Get all text between positions `from` and `to`. When
|
|
1117
|
+
`blockSeparator` is given, it will be inserted to separate text
|
|
1118
|
+
from different block nodes. If `leafText` is given, it'll be
|
|
1119
|
+
inserted for every non-text leaf node encountered, otherwise
|
|
1120
|
+
[`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec.leafText) will be used.
|
|
1121
|
+
*/
|
|
1122
|
+
textBetween(from, to, blockSeparator, leafText) {
|
|
1123
|
+
return this.content.textBetween(from, to, blockSeparator, leafText);
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
Returns this node's first child, or `null` if there are no
|
|
1127
|
+
children.
|
|
1128
|
+
*/
|
|
1129
|
+
get firstChild() {
|
|
1130
|
+
return this.content.firstChild;
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
Returns this node's last child, or `null` if there are no
|
|
1134
|
+
children.
|
|
1135
|
+
*/
|
|
1136
|
+
get lastChild() {
|
|
1137
|
+
return this.content.lastChild;
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
Test whether two nodes represent the same piece of document.
|
|
1141
|
+
*/
|
|
1142
|
+
eq(other) {
|
|
1143
|
+
return this == other || this.sameMarkup(other) && this.content.eq(other.content);
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
Compare the markup (type, attributes, and marks) of this node to
|
|
1147
|
+
those of another. Returns `true` if both have the same markup.
|
|
1148
|
+
*/
|
|
1149
|
+
sameMarkup(other) {
|
|
1150
|
+
return this.hasMarkup(other.type, other.attrs, other.marks);
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
Check whether this node's markup correspond to the given type,
|
|
1154
|
+
attributes, and marks.
|
|
1155
|
+
*/
|
|
1156
|
+
hasMarkup(type, attrs, marks) {
|
|
1157
|
+
return this.type == type && compareDeep(this.attrs, attrs || type.defaultAttrs || emptyAttrs) && Mark.sameSet(this.marks, marks || Mark.none);
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
Create a new node with the same markup as this node, containing
|
|
1161
|
+
the given content (or empty, if no content is given).
|
|
1162
|
+
*/
|
|
1163
|
+
copy(content = null) {
|
|
1164
|
+
if (content == this.content)
|
|
1165
|
+
return this;
|
|
1166
|
+
return new _Node(this.type, this.attrs, content, this.marks);
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
Create a copy of this node, with the given set of marks instead
|
|
1170
|
+
of the node's own marks.
|
|
1171
|
+
*/
|
|
1172
|
+
mark(marks) {
|
|
1173
|
+
return marks == this.marks ? this : new _Node(this.type, this.attrs, this.content, marks);
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
Create a copy of this node with only the content between the
|
|
1177
|
+
given positions. If `to` is not given, it defaults to the end of
|
|
1178
|
+
the node.
|
|
1179
|
+
*/
|
|
1180
|
+
cut(from, to = this.content.size) {
|
|
1181
|
+
if (from == 0 && to == this.content.size)
|
|
1182
|
+
return this;
|
|
1183
|
+
return this.copy(this.content.cut(from, to));
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
Cut out the part of the document between the given positions, and
|
|
1187
|
+
return it as a `Slice` object.
|
|
1188
|
+
*/
|
|
1189
|
+
slice(from, to = this.content.size, includeParents = false) {
|
|
1190
|
+
if (from == to)
|
|
1191
|
+
return Slice.empty;
|
|
1192
|
+
let $from = this.resolve(from), $to = this.resolve(to);
|
|
1193
|
+
let depth = includeParents ? 0 : $from.sharedDepth(to);
|
|
1194
|
+
let start = $from.start(depth), node = $from.node(depth);
|
|
1195
|
+
let content = node.content.cut($from.pos - start, $to.pos - start);
|
|
1196
|
+
return new Slice(content, $from.depth - depth, $to.depth - depth);
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
Replace the part of the document between the given positions with
|
|
1200
|
+
the given slice. The slice must 'fit', meaning its open sides
|
|
1201
|
+
must be able to connect to the surrounding content, and its
|
|
1202
|
+
content nodes must be valid children for the node they are placed
|
|
1203
|
+
into. If any of this is violated, an error of type
|
|
1204
|
+
[`ReplaceError`](https://prosemirror.net/docs/ref/#model.ReplaceError) is thrown.
|
|
1205
|
+
*/
|
|
1206
|
+
replace(from, to, slice) {
|
|
1207
|
+
return replace(this.resolve(from), this.resolve(to), slice);
|
|
1208
|
+
}
|
|
1209
|
+
/**
|
|
1210
|
+
Find the node directly after the given position.
|
|
1211
|
+
*/
|
|
1212
|
+
nodeAt(pos) {
|
|
1213
|
+
for (let node = this; ; ) {
|
|
1214
|
+
let { index, offset } = node.content.findIndex(pos);
|
|
1215
|
+
node = node.maybeChild(index);
|
|
1216
|
+
if (!node)
|
|
1217
|
+
return null;
|
|
1218
|
+
if (offset == pos || node.isText)
|
|
1219
|
+
return node;
|
|
1220
|
+
pos -= offset + 1;
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
Find the (direct) child node after the given offset, if any,
|
|
1225
|
+
and return it along with its index and offset relative to this
|
|
1226
|
+
node.
|
|
1227
|
+
*/
|
|
1228
|
+
childAfter(pos) {
|
|
1229
|
+
let { index, offset } = this.content.findIndex(pos);
|
|
1230
|
+
return { node: this.content.maybeChild(index), index, offset };
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
Find the (direct) child node before the given offset, if any,
|
|
1234
|
+
and return it along with its index and offset relative to this
|
|
1235
|
+
node.
|
|
1236
|
+
*/
|
|
1237
|
+
childBefore(pos) {
|
|
1238
|
+
if (pos == 0)
|
|
1239
|
+
return { node: null, index: 0, offset: 0 };
|
|
1240
|
+
let { index, offset } = this.content.findIndex(pos);
|
|
1241
|
+
if (offset < pos)
|
|
1242
|
+
return { node: this.content.child(index), index, offset };
|
|
1243
|
+
let node = this.content.child(index - 1);
|
|
1244
|
+
return { node, index: index - 1, offset: offset - node.nodeSize };
|
|
1245
|
+
}
|
|
1246
|
+
/**
|
|
1247
|
+
Resolve the given position in the document, returning an
|
|
1248
|
+
[object](https://prosemirror.net/docs/ref/#model.ResolvedPos) with information about its context.
|
|
1249
|
+
*/
|
|
1250
|
+
resolve(pos) {
|
|
1251
|
+
return ResolvedPos.resolveCached(this, pos);
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
@internal
|
|
1255
|
+
*/
|
|
1256
|
+
resolveNoCache(pos) {
|
|
1257
|
+
return ResolvedPos.resolve(this, pos);
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
Test whether a given mark or mark type occurs in this document
|
|
1261
|
+
between the two given positions.
|
|
1262
|
+
*/
|
|
1263
|
+
rangeHasMark(from, to, type) {
|
|
1264
|
+
let found2 = false;
|
|
1265
|
+
if (to > from)
|
|
1266
|
+
this.nodesBetween(from, to, (node) => {
|
|
1267
|
+
if (type.isInSet(node.marks))
|
|
1268
|
+
found2 = true;
|
|
1269
|
+
return !found2;
|
|
1270
|
+
});
|
|
1271
|
+
return found2;
|
|
1272
|
+
}
|
|
1273
|
+
/**
|
|
1274
|
+
True when this is a block (non-inline node)
|
|
1275
|
+
*/
|
|
1276
|
+
get isBlock() {
|
|
1277
|
+
return this.type.isBlock;
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
True when this is a textblock node, a block node with inline
|
|
1281
|
+
content.
|
|
1282
|
+
*/
|
|
1283
|
+
get isTextblock() {
|
|
1284
|
+
return this.type.isTextblock;
|
|
1285
|
+
}
|
|
1286
|
+
/**
|
|
1287
|
+
True when this node allows inline content.
|
|
1288
|
+
*/
|
|
1289
|
+
get inlineContent() {
|
|
1290
|
+
return this.type.inlineContent;
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
True when this is an inline node (a text node or a node that can
|
|
1294
|
+
appear among text).
|
|
1295
|
+
*/
|
|
1296
|
+
get isInline() {
|
|
1297
|
+
return this.type.isInline;
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
True when this is a text node.
|
|
1301
|
+
*/
|
|
1302
|
+
get isText() {
|
|
1303
|
+
return this.type.isText;
|
|
1304
|
+
}
|
|
1305
|
+
/**
|
|
1306
|
+
True when this is a leaf node.
|
|
1307
|
+
*/
|
|
1308
|
+
get isLeaf() {
|
|
1309
|
+
return this.type.isLeaf;
|
|
1310
|
+
}
|
|
1311
|
+
/**
|
|
1312
|
+
True when this is an atom, i.e. when it does not have directly
|
|
1313
|
+
editable content. This is usually the same as `isLeaf`, but can
|
|
1314
|
+
be configured with the [`atom` property](https://prosemirror.net/docs/ref/#model.NodeSpec.atom)
|
|
1315
|
+
on a node's spec (typically used when the node is displayed as
|
|
1316
|
+
an uneditable [node view](https://prosemirror.net/docs/ref/#view.NodeView)).
|
|
1317
|
+
*/
|
|
1318
|
+
get isAtom() {
|
|
1319
|
+
return this.type.isAtom;
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
Return a string representation of this node for debugging
|
|
1323
|
+
purposes.
|
|
1324
|
+
*/
|
|
1325
|
+
toString() {
|
|
1326
|
+
if (this.type.spec.toDebugString)
|
|
1327
|
+
return this.type.spec.toDebugString(this);
|
|
1328
|
+
let name = this.type.name;
|
|
1329
|
+
if (this.content.size)
|
|
1330
|
+
name += "(" + this.content.toStringInner() + ")";
|
|
1331
|
+
return wrapMarks(this.marks, name);
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
Get the content match in this node at the given index.
|
|
1335
|
+
*/
|
|
1336
|
+
contentMatchAt(index) {
|
|
1337
|
+
let match = this.type.contentMatch.matchFragment(this.content, 0, index);
|
|
1338
|
+
if (!match)
|
|
1339
|
+
throw new Error("Called contentMatchAt on a node with invalid content");
|
|
1340
|
+
return match;
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
Test whether replacing the range between `from` and `to` (by
|
|
1344
|
+
child index) with the given replacement fragment (which defaults
|
|
1345
|
+
to the empty fragment) would leave the node's content valid. You
|
|
1346
|
+
can optionally pass `start` and `end` indices into the
|
|
1347
|
+
replacement fragment.
|
|
1348
|
+
*/
|
|
1349
|
+
canReplace(from, to, replacement = Fragment.empty, start = 0, end = replacement.childCount) {
|
|
1350
|
+
let one = this.contentMatchAt(from).matchFragment(replacement, start, end);
|
|
1351
|
+
let two = one && one.matchFragment(this.content, to);
|
|
1352
|
+
if (!two || !two.validEnd)
|
|
1353
|
+
return false;
|
|
1354
|
+
for (let i = start; i < end; i++)
|
|
1355
|
+
if (!this.type.allowsMarks(replacement.child(i).marks))
|
|
1356
|
+
return false;
|
|
1357
|
+
return true;
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
Test whether replacing the range `from` to `to` (by index) with
|
|
1361
|
+
a node of the given type would leave the node's content valid.
|
|
1362
|
+
*/
|
|
1363
|
+
canReplaceWith(from, to, type, marks) {
|
|
1364
|
+
if (marks && !this.type.allowsMarks(marks))
|
|
1365
|
+
return false;
|
|
1366
|
+
let start = this.contentMatchAt(from).matchType(type);
|
|
1367
|
+
let end = start && start.matchFragment(this.content, to);
|
|
1368
|
+
return end ? end.validEnd : false;
|
|
1369
|
+
}
|
|
1370
|
+
/**
|
|
1371
|
+
Test whether the given node's content could be appended to this
|
|
1372
|
+
node. If that node is empty, this will only return true if there
|
|
1373
|
+
is at least one node type that can appear in both nodes (to avoid
|
|
1374
|
+
merging completely incompatible nodes).
|
|
1375
|
+
*/
|
|
1376
|
+
canAppend(other) {
|
|
1377
|
+
if (other.content.size)
|
|
1378
|
+
return this.canReplace(this.childCount, this.childCount, other.content);
|
|
1379
|
+
else
|
|
1380
|
+
return this.type.compatibleContent(other.type);
|
|
1381
|
+
}
|
|
1382
|
+
/**
|
|
1383
|
+
Check whether this node and its descendants conform to the
|
|
1384
|
+
schema, and raise an exception when they do not.
|
|
1385
|
+
*/
|
|
1386
|
+
check() {
|
|
1387
|
+
this.type.checkContent(this.content);
|
|
1388
|
+
this.type.checkAttrs(this.attrs);
|
|
1389
|
+
let copy = Mark.none;
|
|
1390
|
+
for (let i = 0; i < this.marks.length; i++) {
|
|
1391
|
+
let mark = this.marks[i];
|
|
1392
|
+
mark.type.checkAttrs(mark.attrs);
|
|
1393
|
+
copy = mark.addToSet(copy);
|
|
1394
|
+
}
|
|
1395
|
+
if (!Mark.sameSet(copy, this.marks))
|
|
1396
|
+
throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((m) => m.type.name)}`);
|
|
1397
|
+
this.content.forEach((node) => node.check());
|
|
1398
|
+
}
|
|
1399
|
+
/**
|
|
1400
|
+
Return a JSON-serializeable representation of this node.
|
|
1401
|
+
*/
|
|
1402
|
+
toJSON() {
|
|
1403
|
+
let obj = { type: this.type.name };
|
|
1404
|
+
for (let _ in this.attrs) {
|
|
1405
|
+
obj.attrs = this.attrs;
|
|
1406
|
+
break;
|
|
1407
|
+
}
|
|
1408
|
+
if (this.content.size)
|
|
1409
|
+
obj.content = this.content.toJSON();
|
|
1410
|
+
if (this.marks.length)
|
|
1411
|
+
obj.marks = this.marks.map((n) => n.toJSON());
|
|
1412
|
+
return obj;
|
|
1413
|
+
}
|
|
1414
|
+
/**
|
|
1415
|
+
Deserialize a node from its JSON representation.
|
|
1416
|
+
*/
|
|
1417
|
+
static fromJSON(schema, json) {
|
|
1418
|
+
if (!json)
|
|
1419
|
+
throw new RangeError("Invalid input for Node.fromJSON");
|
|
1420
|
+
let marks = void 0;
|
|
1421
|
+
if (json.marks) {
|
|
1422
|
+
if (!Array.isArray(json.marks))
|
|
1423
|
+
throw new RangeError("Invalid mark data for Node.fromJSON");
|
|
1424
|
+
marks = json.marks.map(schema.markFromJSON);
|
|
1425
|
+
}
|
|
1426
|
+
if (json.type == "text") {
|
|
1427
|
+
if (typeof json.text != "string")
|
|
1428
|
+
throw new RangeError("Invalid text node in JSON");
|
|
1429
|
+
return schema.text(json.text, marks);
|
|
1430
|
+
}
|
|
1431
|
+
let content = Fragment.fromJSON(schema, json.content);
|
|
1432
|
+
let node = schema.nodeType(json.type).create(json.attrs, content, marks);
|
|
1433
|
+
node.type.checkAttrs(node.attrs);
|
|
1434
|
+
return node;
|
|
1435
|
+
}
|
|
1436
|
+
};
|
|
1437
|
+
Node.prototype.text = void 0;
|
|
1438
|
+
function wrapMarks(marks, str) {
|
|
1439
|
+
for (let i = marks.length - 1; i >= 0; i--)
|
|
1440
|
+
str = marks[i].type.name + "(" + str + ")";
|
|
1441
|
+
return str;
|
|
1442
|
+
}
|
|
1443
|
+
var ContentMatch = class _ContentMatch {
|
|
1444
|
+
/**
|
|
1445
|
+
@internal
|
|
1446
|
+
*/
|
|
1447
|
+
constructor(validEnd) {
|
|
1448
|
+
this.validEnd = validEnd;
|
|
1449
|
+
this.next = [];
|
|
1450
|
+
this.wrapCache = [];
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
@internal
|
|
1454
|
+
*/
|
|
1455
|
+
static parse(string, nodeTypes) {
|
|
1456
|
+
let stream = new TokenStream(string, nodeTypes);
|
|
1457
|
+
if (stream.next == null)
|
|
1458
|
+
return _ContentMatch.empty;
|
|
1459
|
+
let expr = parseExpr(stream);
|
|
1460
|
+
if (stream.next)
|
|
1461
|
+
stream.err("Unexpected trailing text");
|
|
1462
|
+
let match = dfa(nfa(expr));
|
|
1463
|
+
checkForDeadEnds(match, stream);
|
|
1464
|
+
return match;
|
|
1465
|
+
}
|
|
1466
|
+
/**
|
|
1467
|
+
Match a node type, returning a match after that node if
|
|
1468
|
+
successful.
|
|
1469
|
+
*/
|
|
1470
|
+
matchType(type) {
|
|
1471
|
+
for (let i = 0; i < this.next.length; i++)
|
|
1472
|
+
if (this.next[i].type == type)
|
|
1473
|
+
return this.next[i].next;
|
|
1474
|
+
return null;
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
Try to match a fragment. Returns the resulting match when
|
|
1478
|
+
successful.
|
|
1479
|
+
*/
|
|
1480
|
+
matchFragment(frag, start = 0, end = frag.childCount) {
|
|
1481
|
+
let cur = this;
|
|
1482
|
+
for (let i = start; cur && i < end; i++)
|
|
1483
|
+
cur = cur.matchType(frag.child(i).type);
|
|
1484
|
+
return cur;
|
|
1485
|
+
}
|
|
1486
|
+
/**
|
|
1487
|
+
@internal
|
|
1488
|
+
*/
|
|
1489
|
+
get inlineContent() {
|
|
1490
|
+
return this.next.length != 0 && this.next[0].type.isInline;
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
Get the first matching node type at this match position that can
|
|
1494
|
+
be generated.
|
|
1495
|
+
*/
|
|
1496
|
+
get defaultType() {
|
|
1497
|
+
for (let i = 0; i < this.next.length; i++) {
|
|
1498
|
+
let { type } = this.next[i];
|
|
1499
|
+
if (!(type.isText || type.hasRequiredAttrs()))
|
|
1500
|
+
return type;
|
|
1501
|
+
}
|
|
1502
|
+
return null;
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
@internal
|
|
1506
|
+
*/
|
|
1507
|
+
compatible(other) {
|
|
1508
|
+
for (let i = 0; i < this.next.length; i++)
|
|
1509
|
+
for (let j = 0; j < other.next.length; j++)
|
|
1510
|
+
if (this.next[i].type == other.next[j].type)
|
|
1511
|
+
return true;
|
|
1512
|
+
return false;
|
|
1513
|
+
}
|
|
1514
|
+
/**
|
|
1515
|
+
Try to match the given fragment, and if that fails, see if it can
|
|
1516
|
+
be made to match by inserting nodes in front of it. When
|
|
1517
|
+
successful, return a fragment of inserted nodes (which may be
|
|
1518
|
+
empty if nothing had to be inserted). When `toEnd` is true, only
|
|
1519
|
+
return a fragment if the resulting match goes to the end of the
|
|
1520
|
+
content expression.
|
|
1521
|
+
*/
|
|
1522
|
+
fillBefore(after, toEnd = false, startIndex = 0) {
|
|
1523
|
+
let seen = [this];
|
|
1524
|
+
function search(match, types) {
|
|
1525
|
+
let finished = match.matchFragment(after, startIndex);
|
|
1526
|
+
if (finished && (!toEnd || finished.validEnd))
|
|
1527
|
+
return Fragment.from(types.map((tp) => tp.createAndFill()));
|
|
1528
|
+
for (let i = 0; i < match.next.length; i++) {
|
|
1529
|
+
let { type, next } = match.next[i];
|
|
1530
|
+
if (!(type.isText || type.hasRequiredAttrs()) && seen.indexOf(next) == -1) {
|
|
1531
|
+
seen.push(next);
|
|
1532
|
+
let found2 = search(next, types.concat(type));
|
|
1533
|
+
if (found2)
|
|
1534
|
+
return found2;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
return null;
|
|
1538
|
+
}
|
|
1539
|
+
return search(this, []);
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1542
|
+
Find a set of wrapping node types that would allow a node of the
|
|
1543
|
+
given type to appear at this position. The result may be empty
|
|
1544
|
+
(when it fits directly) and will be null when no such wrapping
|
|
1545
|
+
exists.
|
|
1546
|
+
*/
|
|
1547
|
+
findWrapping(target) {
|
|
1548
|
+
for (let i = 0; i < this.wrapCache.length; i += 2)
|
|
1549
|
+
if (this.wrapCache[i] == target)
|
|
1550
|
+
return this.wrapCache[i + 1];
|
|
1551
|
+
let computed = this.computeWrapping(target);
|
|
1552
|
+
this.wrapCache.push(target, computed);
|
|
1553
|
+
return computed;
|
|
1554
|
+
}
|
|
1555
|
+
/**
|
|
1556
|
+
@internal
|
|
1557
|
+
*/
|
|
1558
|
+
computeWrapping(target) {
|
|
1559
|
+
let seen = /* @__PURE__ */ Object.create(null), active = [{ match: this, type: null, via: null }];
|
|
1560
|
+
while (active.length) {
|
|
1561
|
+
let current = active.shift(), match = current.match;
|
|
1562
|
+
if (match.matchType(target)) {
|
|
1563
|
+
let result = [];
|
|
1564
|
+
for (let obj = current; obj.type; obj = obj.via)
|
|
1565
|
+
result.push(obj.type);
|
|
1566
|
+
return result.reverse();
|
|
1567
|
+
}
|
|
1568
|
+
for (let i = 0; i < match.next.length; i++) {
|
|
1569
|
+
let { type, next } = match.next[i];
|
|
1570
|
+
if (!type.isLeaf && !type.hasRequiredAttrs() && !(type.name in seen) && (!current.type || next.validEnd)) {
|
|
1571
|
+
active.push({ match: type.contentMatch, type, via: current });
|
|
1572
|
+
seen[type.name] = true;
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
return null;
|
|
1577
|
+
}
|
|
1578
|
+
/**
|
|
1579
|
+
The number of outgoing edges this node has in the finite
|
|
1580
|
+
automaton that describes the content expression.
|
|
1581
|
+
*/
|
|
1582
|
+
get edgeCount() {
|
|
1583
|
+
return this.next.length;
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
Get the _n_th outgoing edge from this node in the finite
|
|
1587
|
+
automaton that describes the content expression.
|
|
1588
|
+
*/
|
|
1589
|
+
edge(n) {
|
|
1590
|
+
if (n >= this.next.length)
|
|
1591
|
+
throw new RangeError(`There's no ${n}th edge in this content match`);
|
|
1592
|
+
return this.next[n];
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
@internal
|
|
1596
|
+
*/
|
|
1597
|
+
toString() {
|
|
1598
|
+
let seen = [];
|
|
1599
|
+
function scan(m) {
|
|
1600
|
+
seen.push(m);
|
|
1601
|
+
for (let i = 0; i < m.next.length; i++)
|
|
1602
|
+
if (seen.indexOf(m.next[i].next) == -1)
|
|
1603
|
+
scan(m.next[i].next);
|
|
1604
|
+
}
|
|
1605
|
+
scan(this);
|
|
1606
|
+
return seen.map((m, i) => {
|
|
1607
|
+
let out = i + (m.validEnd ? "*" : " ") + " ";
|
|
1608
|
+
for (let i2 = 0; i2 < m.next.length; i2++)
|
|
1609
|
+
out += (i2 ? ", " : "") + m.next[i2].type.name + "->" + seen.indexOf(m.next[i2].next);
|
|
1610
|
+
return out;
|
|
1611
|
+
}).join("\n");
|
|
1612
|
+
}
|
|
1613
|
+
};
|
|
1614
|
+
ContentMatch.empty = new ContentMatch(true);
|
|
1615
|
+
var TokenStream = class {
|
|
1616
|
+
constructor(string, nodeTypes) {
|
|
1617
|
+
this.string = string;
|
|
1618
|
+
this.nodeTypes = nodeTypes;
|
|
1619
|
+
this.inline = null;
|
|
1620
|
+
this.pos = 0;
|
|
1621
|
+
this.tokens = string.split(/\s*(?=\b|\W|$)/);
|
|
1622
|
+
if (this.tokens[this.tokens.length - 1] == "")
|
|
1623
|
+
this.tokens.pop();
|
|
1624
|
+
if (this.tokens[0] == "")
|
|
1625
|
+
this.tokens.shift();
|
|
1626
|
+
}
|
|
1627
|
+
get next() {
|
|
1628
|
+
return this.tokens[this.pos];
|
|
1629
|
+
}
|
|
1630
|
+
eat(tok) {
|
|
1631
|
+
return this.next == tok && (this.pos++ || true);
|
|
1632
|
+
}
|
|
1633
|
+
err(str) {
|
|
1634
|
+
throw new SyntaxError(str + " (in content expression '" + this.string + "')");
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
function parseExpr(stream) {
|
|
1638
|
+
let exprs = [];
|
|
1639
|
+
do {
|
|
1640
|
+
exprs.push(parseExprSeq(stream));
|
|
1641
|
+
} while (stream.eat("|"));
|
|
1642
|
+
return exprs.length == 1 ? exprs[0] : { type: "choice", exprs };
|
|
1643
|
+
}
|
|
1644
|
+
function parseExprSeq(stream) {
|
|
1645
|
+
let exprs = [];
|
|
1646
|
+
do {
|
|
1647
|
+
exprs.push(parseExprSubscript(stream));
|
|
1648
|
+
} while (stream.next && stream.next != ")" && stream.next != "|");
|
|
1649
|
+
return exprs.length == 1 ? exprs[0] : { type: "seq", exprs };
|
|
1650
|
+
}
|
|
1651
|
+
function parseExprSubscript(stream) {
|
|
1652
|
+
let expr = parseExprAtom(stream);
|
|
1653
|
+
for (; ; ) {
|
|
1654
|
+
if (stream.eat("+"))
|
|
1655
|
+
expr = { type: "plus", expr };
|
|
1656
|
+
else if (stream.eat("*"))
|
|
1657
|
+
expr = { type: "star", expr };
|
|
1658
|
+
else if (stream.eat("?"))
|
|
1659
|
+
expr = { type: "opt", expr };
|
|
1660
|
+
else if (stream.eat("{"))
|
|
1661
|
+
expr = parseExprRange(stream, expr);
|
|
1662
|
+
else
|
|
1663
|
+
break;
|
|
1664
|
+
}
|
|
1665
|
+
return expr;
|
|
1666
|
+
}
|
|
1667
|
+
function parseNum(stream) {
|
|
1668
|
+
if (/\D/.test(stream.next))
|
|
1669
|
+
stream.err("Expected number, got '" + stream.next + "'");
|
|
1670
|
+
let result = Number(stream.next);
|
|
1671
|
+
stream.pos++;
|
|
1672
|
+
return result;
|
|
1673
|
+
}
|
|
1674
|
+
function parseExprRange(stream, expr) {
|
|
1675
|
+
let min = parseNum(stream), max = min;
|
|
1676
|
+
if (stream.eat(",")) {
|
|
1677
|
+
if (stream.next != "}")
|
|
1678
|
+
max = parseNum(stream);
|
|
1679
|
+
else
|
|
1680
|
+
max = -1;
|
|
1681
|
+
}
|
|
1682
|
+
if (!stream.eat("}"))
|
|
1683
|
+
stream.err("Unclosed braced range");
|
|
1684
|
+
return { type: "range", min, max, expr };
|
|
1685
|
+
}
|
|
1686
|
+
function resolveName(stream, name) {
|
|
1687
|
+
let types = stream.nodeTypes, type = types[name];
|
|
1688
|
+
if (type)
|
|
1689
|
+
return [type];
|
|
1690
|
+
let result = [];
|
|
1691
|
+
for (let typeName in types) {
|
|
1692
|
+
let type2 = types[typeName];
|
|
1693
|
+
if (type2.isInGroup(name))
|
|
1694
|
+
result.push(type2);
|
|
1695
|
+
}
|
|
1696
|
+
if (result.length == 0)
|
|
1697
|
+
stream.err("No node type or group '" + name + "' found");
|
|
1698
|
+
return result;
|
|
1699
|
+
}
|
|
1700
|
+
function parseExprAtom(stream) {
|
|
1701
|
+
if (stream.eat("(")) {
|
|
1702
|
+
let expr = parseExpr(stream);
|
|
1703
|
+
if (!stream.eat(")"))
|
|
1704
|
+
stream.err("Missing closing paren");
|
|
1705
|
+
return expr;
|
|
1706
|
+
} else if (!/\W/.test(stream.next)) {
|
|
1707
|
+
let exprs = resolveName(stream, stream.next).map((type) => {
|
|
1708
|
+
if (stream.inline == null)
|
|
1709
|
+
stream.inline = type.isInline;
|
|
1710
|
+
else if (stream.inline != type.isInline)
|
|
1711
|
+
stream.err("Mixing inline and block content");
|
|
1712
|
+
return { type: "name", value: type };
|
|
1713
|
+
});
|
|
1714
|
+
stream.pos++;
|
|
1715
|
+
return exprs.length == 1 ? exprs[0] : { type: "choice", exprs };
|
|
1716
|
+
} else {
|
|
1717
|
+
stream.err("Unexpected token '" + stream.next + "'");
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
function nfa(expr) {
|
|
1721
|
+
let nfa2 = [[]];
|
|
1722
|
+
connect(compile(expr, 0), node());
|
|
1723
|
+
return nfa2;
|
|
1724
|
+
function node() {
|
|
1725
|
+
return nfa2.push([]) - 1;
|
|
1726
|
+
}
|
|
1727
|
+
function edge(from, to, term) {
|
|
1728
|
+
let edge2 = { term, to };
|
|
1729
|
+
nfa2[from].push(edge2);
|
|
1730
|
+
return edge2;
|
|
1731
|
+
}
|
|
1732
|
+
function connect(edges, to) {
|
|
1733
|
+
edges.forEach((edge2) => edge2.to = to);
|
|
1734
|
+
}
|
|
1735
|
+
function compile(expr2, from) {
|
|
1736
|
+
if (expr2.type == "choice") {
|
|
1737
|
+
return expr2.exprs.reduce((out, expr3) => out.concat(compile(expr3, from)), []);
|
|
1738
|
+
} else if (expr2.type == "seq") {
|
|
1739
|
+
for (let i = 0; ; i++) {
|
|
1740
|
+
let next = compile(expr2.exprs[i], from);
|
|
1741
|
+
if (i == expr2.exprs.length - 1)
|
|
1742
|
+
return next;
|
|
1743
|
+
connect(next, from = node());
|
|
1744
|
+
}
|
|
1745
|
+
} else if (expr2.type == "star") {
|
|
1746
|
+
let loop = node();
|
|
1747
|
+
edge(from, loop);
|
|
1748
|
+
connect(compile(expr2.expr, loop), loop);
|
|
1749
|
+
return [edge(loop)];
|
|
1750
|
+
} else if (expr2.type == "plus") {
|
|
1751
|
+
let loop = node();
|
|
1752
|
+
connect(compile(expr2.expr, from), loop);
|
|
1753
|
+
connect(compile(expr2.expr, loop), loop);
|
|
1754
|
+
return [edge(loop)];
|
|
1755
|
+
} else if (expr2.type == "opt") {
|
|
1756
|
+
return [edge(from)].concat(compile(expr2.expr, from));
|
|
1757
|
+
} else if (expr2.type == "range") {
|
|
1758
|
+
let cur = from;
|
|
1759
|
+
for (let i = 0; i < expr2.min; i++) {
|
|
1760
|
+
let next = node();
|
|
1761
|
+
connect(compile(expr2.expr, cur), next);
|
|
1762
|
+
cur = next;
|
|
1763
|
+
}
|
|
1764
|
+
if (expr2.max == -1) {
|
|
1765
|
+
connect(compile(expr2.expr, cur), cur);
|
|
1766
|
+
} else {
|
|
1767
|
+
for (let i = expr2.min; i < expr2.max; i++) {
|
|
1768
|
+
let next = node();
|
|
1769
|
+
edge(cur, next);
|
|
1770
|
+
connect(compile(expr2.expr, cur), next);
|
|
1771
|
+
cur = next;
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
return [edge(cur)];
|
|
1775
|
+
} else if (expr2.type == "name") {
|
|
1776
|
+
return [edge(from, void 0, expr2.value)];
|
|
1777
|
+
} else {
|
|
1778
|
+
throw new Error("Unknown expr type");
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
function cmp(a, b) {
|
|
1783
|
+
return b - a;
|
|
1784
|
+
}
|
|
1785
|
+
function nullFrom(nfa2, node) {
|
|
1786
|
+
let result = [];
|
|
1787
|
+
scan(node);
|
|
1788
|
+
return result.sort(cmp);
|
|
1789
|
+
function scan(node2) {
|
|
1790
|
+
let edges = nfa2[node2];
|
|
1791
|
+
if (edges.length == 1 && !edges[0].term)
|
|
1792
|
+
return scan(edges[0].to);
|
|
1793
|
+
result.push(node2);
|
|
1794
|
+
for (let i = 0; i < edges.length; i++) {
|
|
1795
|
+
let { term, to } = edges[i];
|
|
1796
|
+
if (!term && result.indexOf(to) == -1)
|
|
1797
|
+
scan(to);
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
function dfa(nfa2) {
|
|
1802
|
+
let labeled = /* @__PURE__ */ Object.create(null);
|
|
1803
|
+
return explore(nullFrom(nfa2, 0));
|
|
1804
|
+
function explore(states) {
|
|
1805
|
+
let out = [];
|
|
1806
|
+
states.forEach((node) => {
|
|
1807
|
+
nfa2[node].forEach(({ term, to }) => {
|
|
1808
|
+
if (!term)
|
|
1809
|
+
return;
|
|
1810
|
+
let set;
|
|
1811
|
+
for (let i = 0; i < out.length; i++)
|
|
1812
|
+
if (out[i][0] == term)
|
|
1813
|
+
set = out[i][1];
|
|
1814
|
+
nullFrom(nfa2, to).forEach((node2) => {
|
|
1815
|
+
if (!set)
|
|
1816
|
+
out.push([term, set = []]);
|
|
1817
|
+
if (set.indexOf(node2) == -1)
|
|
1818
|
+
set.push(node2);
|
|
1819
|
+
});
|
|
1820
|
+
});
|
|
1821
|
+
});
|
|
1822
|
+
let state = labeled[states.join(",")] = new ContentMatch(states.indexOf(nfa2.length - 1) > -1);
|
|
1823
|
+
for (let i = 0; i < out.length; i++) {
|
|
1824
|
+
let states2 = out[i][1].sort(cmp);
|
|
1825
|
+
state.next.push({ type: out[i][0], next: labeled[states2.join(",")] || explore(states2) });
|
|
1826
|
+
}
|
|
1827
|
+
return state;
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
function checkForDeadEnds(match, stream) {
|
|
1831
|
+
for (let i = 0, work = [match]; i < work.length; i++) {
|
|
1832
|
+
let state = work[i], dead = !state.validEnd, nodes = [];
|
|
1833
|
+
for (let j = 0; j < state.next.length; j++) {
|
|
1834
|
+
let { type, next } = state.next[j];
|
|
1835
|
+
nodes.push(type.name);
|
|
1836
|
+
if (dead && !(type.isText || type.hasRequiredAttrs()))
|
|
1837
|
+
dead = false;
|
|
1838
|
+
if (work.indexOf(next) == -1)
|
|
1839
|
+
work.push(next);
|
|
1840
|
+
}
|
|
1841
|
+
if (dead)
|
|
1842
|
+
stream.err("Only non-generatable nodes (" + nodes.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)");
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
// ../../node_modules/.pnpm/prosemirror-transform@1.10.4/node_modules/prosemirror-transform/dist/index.js
|
|
1847
|
+
var lower16 = 65535;
|
|
1848
|
+
var factor16 = Math.pow(2, 16);
|
|
1849
|
+
function makeRecover(index, offset) {
|
|
1850
|
+
return index + offset * factor16;
|
|
1851
|
+
}
|
|
1852
|
+
function recoverIndex(value) {
|
|
1853
|
+
return value & lower16;
|
|
1854
|
+
}
|
|
1855
|
+
function recoverOffset(value) {
|
|
1856
|
+
return (value - (value & lower16)) / factor16;
|
|
1857
|
+
}
|
|
1858
|
+
var DEL_BEFORE = 1;
|
|
1859
|
+
var DEL_AFTER = 2;
|
|
1860
|
+
var DEL_ACROSS = 4;
|
|
1861
|
+
var DEL_SIDE = 8;
|
|
1862
|
+
var MapResult = class {
|
|
1863
|
+
/**
|
|
1864
|
+
@internal
|
|
1865
|
+
*/
|
|
1866
|
+
constructor(pos, delInfo, recover) {
|
|
1867
|
+
this.pos = pos;
|
|
1868
|
+
this.delInfo = delInfo;
|
|
1869
|
+
this.recover = recover;
|
|
1870
|
+
}
|
|
1871
|
+
/**
|
|
1872
|
+
Tells you whether the position was deleted, that is, whether the
|
|
1873
|
+
step removed the token on the side queried (via the `assoc`)
|
|
1874
|
+
argument from the document.
|
|
1875
|
+
*/
|
|
1876
|
+
get deleted() {
|
|
1877
|
+
return (this.delInfo & DEL_SIDE) > 0;
|
|
1878
|
+
}
|
|
1879
|
+
/**
|
|
1880
|
+
Tells you whether the token before the mapped position was deleted.
|
|
1881
|
+
*/
|
|
1882
|
+
get deletedBefore() {
|
|
1883
|
+
return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0;
|
|
1884
|
+
}
|
|
1885
|
+
/**
|
|
1886
|
+
True when the token after the mapped position was deleted.
|
|
1887
|
+
*/
|
|
1888
|
+
get deletedAfter() {
|
|
1889
|
+
return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0;
|
|
1890
|
+
}
|
|
1891
|
+
/**
|
|
1892
|
+
Tells whether any of the steps mapped through deletes across the
|
|
1893
|
+
position (including both the token before and after the
|
|
1894
|
+
position).
|
|
1895
|
+
*/
|
|
1896
|
+
get deletedAcross() {
|
|
1897
|
+
return (this.delInfo & DEL_ACROSS) > 0;
|
|
1898
|
+
}
|
|
1899
|
+
};
|
|
1900
|
+
var StepMap = class _StepMap {
|
|
1901
|
+
/**
|
|
1902
|
+
Create a position map. The modifications to the document are
|
|
1903
|
+
represented as an array of numbers, in which each group of three
|
|
1904
|
+
represents a modified chunk as `[start, oldSize, newSize]`.
|
|
1905
|
+
*/
|
|
1906
|
+
constructor(ranges, inverted = false) {
|
|
1907
|
+
this.ranges = ranges;
|
|
1908
|
+
this.inverted = inverted;
|
|
1909
|
+
if (!ranges.length && _StepMap.empty)
|
|
1910
|
+
return _StepMap.empty;
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
@internal
|
|
1914
|
+
*/
|
|
1915
|
+
recover(value) {
|
|
1916
|
+
let diff = 0, index = recoverIndex(value);
|
|
1917
|
+
if (!this.inverted)
|
|
1918
|
+
for (let i = 0; i < index; i++)
|
|
1919
|
+
diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1];
|
|
1920
|
+
return this.ranges[index * 3] + diff + recoverOffset(value);
|
|
1921
|
+
}
|
|
1922
|
+
mapResult(pos, assoc = 1) {
|
|
1923
|
+
return this._map(pos, assoc, false);
|
|
1924
|
+
}
|
|
1925
|
+
map(pos, assoc = 1) {
|
|
1926
|
+
return this._map(pos, assoc, true);
|
|
1927
|
+
}
|
|
1928
|
+
/**
|
|
1929
|
+
@internal
|
|
1930
|
+
*/
|
|
1931
|
+
_map(pos, assoc, simple) {
|
|
1932
|
+
let diff = 0, oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
|
|
1933
|
+
for (let i = 0; i < this.ranges.length; i += 3) {
|
|
1934
|
+
let start = this.ranges[i] - (this.inverted ? diff : 0);
|
|
1935
|
+
if (start > pos)
|
|
1936
|
+
break;
|
|
1937
|
+
let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex], end = start + oldSize;
|
|
1938
|
+
if (pos <= end) {
|
|
1939
|
+
let side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc;
|
|
1940
|
+
let result = start + diff + (side < 0 ? 0 : newSize);
|
|
1941
|
+
if (simple)
|
|
1942
|
+
return result;
|
|
1943
|
+
let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);
|
|
1944
|
+
let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;
|
|
1945
|
+
if (assoc < 0 ? pos != start : pos != end)
|
|
1946
|
+
del |= DEL_SIDE;
|
|
1947
|
+
return new MapResult(result, del, recover);
|
|
1948
|
+
}
|
|
1949
|
+
diff += newSize - oldSize;
|
|
1950
|
+
}
|
|
1951
|
+
return simple ? pos + diff : new MapResult(pos + diff, 0, null);
|
|
1952
|
+
}
|
|
1953
|
+
/**
|
|
1954
|
+
@internal
|
|
1955
|
+
*/
|
|
1956
|
+
touches(pos, recover) {
|
|
1957
|
+
let diff = 0, index = recoverIndex(recover);
|
|
1958
|
+
let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
|
|
1959
|
+
for (let i = 0; i < this.ranges.length; i += 3) {
|
|
1960
|
+
let start = this.ranges[i] - (this.inverted ? diff : 0);
|
|
1961
|
+
if (start > pos)
|
|
1962
|
+
break;
|
|
1963
|
+
let oldSize = this.ranges[i + oldIndex], end = start + oldSize;
|
|
1964
|
+
if (pos <= end && i == index * 3)
|
|
1965
|
+
return true;
|
|
1966
|
+
diff += this.ranges[i + newIndex] - oldSize;
|
|
1967
|
+
}
|
|
1968
|
+
return false;
|
|
1969
|
+
}
|
|
1970
|
+
/**
|
|
1971
|
+
Calls the given function on each of the changed ranges included in
|
|
1972
|
+
this map.
|
|
1973
|
+
*/
|
|
1974
|
+
forEach(f) {
|
|
1975
|
+
let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
|
|
1976
|
+
for (let i = 0, diff = 0; i < this.ranges.length; i += 3) {
|
|
1977
|
+
let start = this.ranges[i], oldStart = start - (this.inverted ? diff : 0), newStart = start + (this.inverted ? 0 : diff);
|
|
1978
|
+
let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex];
|
|
1979
|
+
f(oldStart, oldStart + oldSize, newStart, newStart + newSize);
|
|
1980
|
+
diff += newSize - oldSize;
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
/**
|
|
1984
|
+
Create an inverted version of this map. The result can be used to
|
|
1985
|
+
map positions in the post-step document to the pre-step document.
|
|
1986
|
+
*/
|
|
1987
|
+
invert() {
|
|
1988
|
+
return new _StepMap(this.ranges, !this.inverted);
|
|
1989
|
+
}
|
|
1990
|
+
/**
|
|
1991
|
+
@internal
|
|
1992
|
+
*/
|
|
1993
|
+
toString() {
|
|
1994
|
+
return (this.inverted ? "-" : "") + JSON.stringify(this.ranges);
|
|
1995
|
+
}
|
|
1996
|
+
/**
|
|
1997
|
+
Create a map that moves all positions by offset `n` (which may be
|
|
1998
|
+
negative). This can be useful when applying steps meant for a
|
|
1999
|
+
sub-document to a larger document, or vice-versa.
|
|
2000
|
+
*/
|
|
2001
|
+
static offset(n) {
|
|
2002
|
+
return n == 0 ? _StepMap.empty : new _StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]);
|
|
2003
|
+
}
|
|
2004
|
+
};
|
|
2005
|
+
StepMap.empty = new StepMap([]);
|
|
2006
|
+
var stepsByID = /* @__PURE__ */ Object.create(null);
|
|
2007
|
+
var Step = class {
|
|
2008
|
+
/**
|
|
2009
|
+
Get the step map that represents the changes made by this step,
|
|
2010
|
+
and which can be used to transform between positions in the old
|
|
2011
|
+
and the new document.
|
|
2012
|
+
*/
|
|
2013
|
+
getMap() {
|
|
2014
|
+
return StepMap.empty;
|
|
2015
|
+
}
|
|
2016
|
+
/**
|
|
2017
|
+
Try to merge this step with another one, to be applied directly
|
|
2018
|
+
after it. Returns the merged step when possible, null if the
|
|
2019
|
+
steps can't be merged.
|
|
2020
|
+
*/
|
|
2021
|
+
merge(other) {
|
|
2022
|
+
return null;
|
|
2023
|
+
}
|
|
2024
|
+
/**
|
|
2025
|
+
Deserialize a step from its JSON representation. Will call
|
|
2026
|
+
through to the step class' own implementation of this method.
|
|
2027
|
+
*/
|
|
2028
|
+
static fromJSON(schema, json) {
|
|
2029
|
+
if (!json || !json.stepType)
|
|
2030
|
+
throw new RangeError("Invalid input for Step.fromJSON");
|
|
2031
|
+
let type = stepsByID[json.stepType];
|
|
2032
|
+
if (!type)
|
|
2033
|
+
throw new RangeError(`No step type ${json.stepType} defined`);
|
|
2034
|
+
return type.fromJSON(schema, json);
|
|
2035
|
+
}
|
|
2036
|
+
/**
|
|
2037
|
+
To be able to serialize steps to JSON, each step needs a string
|
|
2038
|
+
ID to attach to its JSON representation. Use this method to
|
|
2039
|
+
register an ID for your step classes. Try to pick something
|
|
2040
|
+
that's unlikely to clash with steps from other modules.
|
|
2041
|
+
*/
|
|
2042
|
+
static jsonID(id, stepClass) {
|
|
2043
|
+
if (id in stepsByID)
|
|
2044
|
+
throw new RangeError("Duplicate use of step JSON ID " + id);
|
|
2045
|
+
stepsByID[id] = stepClass;
|
|
2046
|
+
stepClass.prototype.jsonID = id;
|
|
2047
|
+
return stepClass;
|
|
2048
|
+
}
|
|
2049
|
+
};
|
|
2050
|
+
var StepResult = class _StepResult {
|
|
2051
|
+
/**
|
|
2052
|
+
@internal
|
|
2053
|
+
*/
|
|
2054
|
+
constructor(doc, failed) {
|
|
2055
|
+
this.doc = doc;
|
|
2056
|
+
this.failed = failed;
|
|
2057
|
+
}
|
|
2058
|
+
/**
|
|
2059
|
+
Create a successful step result.
|
|
2060
|
+
*/
|
|
2061
|
+
static ok(doc) {
|
|
2062
|
+
return new _StepResult(doc, null);
|
|
2063
|
+
}
|
|
2064
|
+
/**
|
|
2065
|
+
Create a failed step result.
|
|
2066
|
+
*/
|
|
2067
|
+
static fail(message) {
|
|
2068
|
+
return new _StepResult(null, message);
|
|
2069
|
+
}
|
|
2070
|
+
/**
|
|
2071
|
+
Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given
|
|
2072
|
+
arguments. Create a successful result if it succeeds, and a
|
|
2073
|
+
failed one if it throws a `ReplaceError`.
|
|
2074
|
+
*/
|
|
2075
|
+
static fromReplace(doc, from, to, slice) {
|
|
2076
|
+
try {
|
|
2077
|
+
return _StepResult.ok(doc.replace(from, to, slice));
|
|
2078
|
+
} catch (e) {
|
|
2079
|
+
if (e instanceof ReplaceError)
|
|
2080
|
+
return _StepResult.fail(e.message);
|
|
2081
|
+
throw e;
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
};
|
|
2085
|
+
function mapFragment(fragment, f, parent) {
|
|
2086
|
+
let mapped = [];
|
|
2087
|
+
for (let i = 0; i < fragment.childCount; i++) {
|
|
2088
|
+
let child = fragment.child(i);
|
|
2089
|
+
if (child.content.size)
|
|
2090
|
+
child = child.copy(mapFragment(child.content, f, child));
|
|
2091
|
+
if (child.isInline)
|
|
2092
|
+
child = f(child, parent, i);
|
|
2093
|
+
mapped.push(child);
|
|
2094
|
+
}
|
|
2095
|
+
return Fragment.fromArray(mapped);
|
|
2096
|
+
}
|
|
2097
|
+
var AddMarkStep = class _AddMarkStep extends Step {
|
|
2098
|
+
/**
|
|
2099
|
+
Create a mark step.
|
|
2100
|
+
*/
|
|
2101
|
+
constructor(from, to, mark) {
|
|
2102
|
+
super();
|
|
2103
|
+
this.from = from;
|
|
2104
|
+
this.to = to;
|
|
2105
|
+
this.mark = mark;
|
|
2106
|
+
}
|
|
2107
|
+
apply(doc) {
|
|
2108
|
+
let oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from);
|
|
2109
|
+
let parent = $from.node($from.sharedDepth(this.to));
|
|
2110
|
+
let slice = new Slice(mapFragment(oldSlice.content, (node, parent2) => {
|
|
2111
|
+
if (!node.isAtom || !parent2.type.allowsMarkType(this.mark.type))
|
|
2112
|
+
return node;
|
|
2113
|
+
return node.mark(this.mark.addToSet(node.marks));
|
|
2114
|
+
}, parent), oldSlice.openStart, oldSlice.openEnd);
|
|
2115
|
+
return StepResult.fromReplace(doc, this.from, this.to, slice);
|
|
2116
|
+
}
|
|
2117
|
+
invert() {
|
|
2118
|
+
return new RemoveMarkStep(this.from, this.to, this.mark);
|
|
2119
|
+
}
|
|
2120
|
+
map(mapping) {
|
|
2121
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
2122
|
+
if (from.deleted && to.deleted || from.pos >= to.pos)
|
|
2123
|
+
return null;
|
|
2124
|
+
return new _AddMarkStep(from.pos, to.pos, this.mark);
|
|
2125
|
+
}
|
|
2126
|
+
merge(other) {
|
|
2127
|
+
if (other instanceof _AddMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from)
|
|
2128
|
+
return new _AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
|
|
2129
|
+
return null;
|
|
2130
|
+
}
|
|
2131
|
+
toJSON() {
|
|
2132
|
+
return {
|
|
2133
|
+
stepType: "addMark",
|
|
2134
|
+
mark: this.mark.toJSON(),
|
|
2135
|
+
from: this.from,
|
|
2136
|
+
to: this.to
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
/**
|
|
2140
|
+
@internal
|
|
2141
|
+
*/
|
|
2142
|
+
static fromJSON(schema, json) {
|
|
2143
|
+
if (typeof json.from != "number" || typeof json.to != "number")
|
|
2144
|
+
throw new RangeError("Invalid input for AddMarkStep.fromJSON");
|
|
2145
|
+
return new _AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
|
|
2146
|
+
}
|
|
2147
|
+
};
|
|
2148
|
+
Step.jsonID("addMark", AddMarkStep);
|
|
2149
|
+
var RemoveMarkStep = class _RemoveMarkStep extends Step {
|
|
2150
|
+
/**
|
|
2151
|
+
Create a mark-removing step.
|
|
2152
|
+
*/
|
|
2153
|
+
constructor(from, to, mark) {
|
|
2154
|
+
super();
|
|
2155
|
+
this.from = from;
|
|
2156
|
+
this.to = to;
|
|
2157
|
+
this.mark = mark;
|
|
2158
|
+
}
|
|
2159
|
+
apply(doc) {
|
|
2160
|
+
let oldSlice = doc.slice(this.from, this.to);
|
|
2161
|
+
let slice = new Slice(mapFragment(oldSlice.content, (node) => {
|
|
2162
|
+
return node.mark(this.mark.removeFromSet(node.marks));
|
|
2163
|
+
}, doc), oldSlice.openStart, oldSlice.openEnd);
|
|
2164
|
+
return StepResult.fromReplace(doc, this.from, this.to, slice);
|
|
2165
|
+
}
|
|
2166
|
+
invert() {
|
|
2167
|
+
return new AddMarkStep(this.from, this.to, this.mark);
|
|
2168
|
+
}
|
|
2169
|
+
map(mapping) {
|
|
2170
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
2171
|
+
if (from.deleted && to.deleted || from.pos >= to.pos)
|
|
2172
|
+
return null;
|
|
2173
|
+
return new _RemoveMarkStep(from.pos, to.pos, this.mark);
|
|
2174
|
+
}
|
|
2175
|
+
merge(other) {
|
|
2176
|
+
if (other instanceof _RemoveMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from)
|
|
2177
|
+
return new _RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
|
|
2178
|
+
return null;
|
|
2179
|
+
}
|
|
2180
|
+
toJSON() {
|
|
2181
|
+
return {
|
|
2182
|
+
stepType: "removeMark",
|
|
2183
|
+
mark: this.mark.toJSON(),
|
|
2184
|
+
from: this.from,
|
|
2185
|
+
to: this.to
|
|
2186
|
+
};
|
|
2187
|
+
}
|
|
2188
|
+
/**
|
|
2189
|
+
@internal
|
|
2190
|
+
*/
|
|
2191
|
+
static fromJSON(schema, json) {
|
|
2192
|
+
if (typeof json.from != "number" || typeof json.to != "number")
|
|
2193
|
+
throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");
|
|
2194
|
+
return new _RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
|
|
2195
|
+
}
|
|
2196
|
+
};
|
|
2197
|
+
Step.jsonID("removeMark", RemoveMarkStep);
|
|
2198
|
+
var AddNodeMarkStep = class _AddNodeMarkStep extends Step {
|
|
2199
|
+
/**
|
|
2200
|
+
Create a node mark step.
|
|
2201
|
+
*/
|
|
2202
|
+
constructor(pos, mark) {
|
|
2203
|
+
super();
|
|
2204
|
+
this.pos = pos;
|
|
2205
|
+
this.mark = mark;
|
|
2206
|
+
}
|
|
2207
|
+
apply(doc) {
|
|
2208
|
+
let node = doc.nodeAt(this.pos);
|
|
2209
|
+
if (!node)
|
|
2210
|
+
return StepResult.fail("No node at mark step's position");
|
|
2211
|
+
let updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));
|
|
2212
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
2213
|
+
}
|
|
2214
|
+
invert(doc) {
|
|
2215
|
+
let node = doc.nodeAt(this.pos);
|
|
2216
|
+
if (node) {
|
|
2217
|
+
let newSet = this.mark.addToSet(node.marks);
|
|
2218
|
+
if (newSet.length == node.marks.length) {
|
|
2219
|
+
for (let i = 0; i < node.marks.length; i++)
|
|
2220
|
+
if (!node.marks[i].isInSet(newSet))
|
|
2221
|
+
return new _AddNodeMarkStep(this.pos, node.marks[i]);
|
|
2222
|
+
return new _AddNodeMarkStep(this.pos, this.mark);
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
return new RemoveNodeMarkStep(this.pos, this.mark);
|
|
2226
|
+
}
|
|
2227
|
+
map(mapping) {
|
|
2228
|
+
let pos = mapping.mapResult(this.pos, 1);
|
|
2229
|
+
return pos.deletedAfter ? null : new _AddNodeMarkStep(pos.pos, this.mark);
|
|
2230
|
+
}
|
|
2231
|
+
toJSON() {
|
|
2232
|
+
return { stepType: "addNodeMark", pos: this.pos, mark: this.mark.toJSON() };
|
|
2233
|
+
}
|
|
2234
|
+
/**
|
|
2235
|
+
@internal
|
|
2236
|
+
*/
|
|
2237
|
+
static fromJSON(schema, json) {
|
|
2238
|
+
if (typeof json.pos != "number")
|
|
2239
|
+
throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");
|
|
2240
|
+
return new _AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
|
|
2241
|
+
}
|
|
2242
|
+
};
|
|
2243
|
+
Step.jsonID("addNodeMark", AddNodeMarkStep);
|
|
2244
|
+
var RemoveNodeMarkStep = class _RemoveNodeMarkStep extends Step {
|
|
2245
|
+
/**
|
|
2246
|
+
Create a mark-removing step.
|
|
2247
|
+
*/
|
|
2248
|
+
constructor(pos, mark) {
|
|
2249
|
+
super();
|
|
2250
|
+
this.pos = pos;
|
|
2251
|
+
this.mark = mark;
|
|
2252
|
+
}
|
|
2253
|
+
apply(doc) {
|
|
2254
|
+
let node = doc.nodeAt(this.pos);
|
|
2255
|
+
if (!node)
|
|
2256
|
+
return StepResult.fail("No node at mark step's position");
|
|
2257
|
+
let updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));
|
|
2258
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
2259
|
+
}
|
|
2260
|
+
invert(doc) {
|
|
2261
|
+
let node = doc.nodeAt(this.pos);
|
|
2262
|
+
if (!node || !this.mark.isInSet(node.marks))
|
|
2263
|
+
return this;
|
|
2264
|
+
return new AddNodeMarkStep(this.pos, this.mark);
|
|
2265
|
+
}
|
|
2266
|
+
map(mapping) {
|
|
2267
|
+
let pos = mapping.mapResult(this.pos, 1);
|
|
2268
|
+
return pos.deletedAfter ? null : new _RemoveNodeMarkStep(pos.pos, this.mark);
|
|
2269
|
+
}
|
|
2270
|
+
toJSON() {
|
|
2271
|
+
return { stepType: "removeNodeMark", pos: this.pos, mark: this.mark.toJSON() };
|
|
2272
|
+
}
|
|
2273
|
+
/**
|
|
2274
|
+
@internal
|
|
2275
|
+
*/
|
|
2276
|
+
static fromJSON(schema, json) {
|
|
2277
|
+
if (typeof json.pos != "number")
|
|
2278
|
+
throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
|
|
2279
|
+
return new _RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
|
|
2280
|
+
}
|
|
2281
|
+
};
|
|
2282
|
+
Step.jsonID("removeNodeMark", RemoveNodeMarkStep);
|
|
2283
|
+
var ReplaceStep = class _ReplaceStep extends Step {
|
|
2284
|
+
/**
|
|
2285
|
+
The given `slice` should fit the 'gap' between `from` and
|
|
2286
|
+
`to`—the depths must line up, and the surrounding nodes must be
|
|
2287
|
+
able to be joined with the open sides of the slice. When
|
|
2288
|
+
`structure` is true, the step will fail if the content between
|
|
2289
|
+
from and to is not just a sequence of closing and then opening
|
|
2290
|
+
tokens (this is to guard against rebased replace steps
|
|
2291
|
+
overwriting something they weren't supposed to).
|
|
2292
|
+
*/
|
|
2293
|
+
constructor(from, to, slice, structure = false) {
|
|
2294
|
+
super();
|
|
2295
|
+
this.from = from;
|
|
2296
|
+
this.to = to;
|
|
2297
|
+
this.slice = slice;
|
|
2298
|
+
this.structure = structure;
|
|
2299
|
+
}
|
|
2300
|
+
apply(doc) {
|
|
2301
|
+
if (this.structure && contentBetween(doc, this.from, this.to))
|
|
2302
|
+
return StepResult.fail("Structure replace would overwrite content");
|
|
2303
|
+
return StepResult.fromReplace(doc, this.from, this.to, this.slice);
|
|
2304
|
+
}
|
|
2305
|
+
getMap() {
|
|
2306
|
+
return new StepMap([this.from, this.to - this.from, this.slice.size]);
|
|
2307
|
+
}
|
|
2308
|
+
invert(doc) {
|
|
2309
|
+
return new _ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));
|
|
2310
|
+
}
|
|
2311
|
+
map(mapping) {
|
|
2312
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
2313
|
+
if (from.deletedAcross && to.deletedAcross)
|
|
2314
|
+
return null;
|
|
2315
|
+
return new _ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice, this.structure);
|
|
2316
|
+
}
|
|
2317
|
+
merge(other) {
|
|
2318
|
+
if (!(other instanceof _ReplaceStep) || other.structure || this.structure)
|
|
2319
|
+
return null;
|
|
2320
|
+
if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {
|
|
2321
|
+
let slice = this.slice.size + other.slice.size == 0 ? Slice.empty : new Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd);
|
|
2322
|
+
return new _ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure);
|
|
2323
|
+
} else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {
|
|
2324
|
+
let slice = this.slice.size + other.slice.size == 0 ? Slice.empty : new Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd);
|
|
2325
|
+
return new _ReplaceStep(other.from, this.to, slice, this.structure);
|
|
2326
|
+
} else {
|
|
2327
|
+
return null;
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
toJSON() {
|
|
2331
|
+
let json = { stepType: "replace", from: this.from, to: this.to };
|
|
2332
|
+
if (this.slice.size)
|
|
2333
|
+
json.slice = this.slice.toJSON();
|
|
2334
|
+
if (this.structure)
|
|
2335
|
+
json.structure = true;
|
|
2336
|
+
return json;
|
|
2337
|
+
}
|
|
2338
|
+
/**
|
|
2339
|
+
@internal
|
|
2340
|
+
*/
|
|
2341
|
+
static fromJSON(schema, json) {
|
|
2342
|
+
if (typeof json.from != "number" || typeof json.to != "number")
|
|
2343
|
+
throw new RangeError("Invalid input for ReplaceStep.fromJSON");
|
|
2344
|
+
return new _ReplaceStep(json.from, json.to, Slice.fromJSON(schema, json.slice), !!json.structure);
|
|
2345
|
+
}
|
|
2346
|
+
};
|
|
2347
|
+
Step.jsonID("replace", ReplaceStep);
|
|
2348
|
+
var ReplaceAroundStep = class _ReplaceAroundStep extends Step {
|
|
2349
|
+
/**
|
|
2350
|
+
Create a replace-around step with the given range and gap.
|
|
2351
|
+
`insert` should be the point in the slice into which the content
|
|
2352
|
+
of the gap should be moved. `structure` has the same meaning as
|
|
2353
|
+
it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class.
|
|
2354
|
+
*/
|
|
2355
|
+
constructor(from, to, gapFrom, gapTo, slice, insert, structure = false) {
|
|
2356
|
+
super();
|
|
2357
|
+
this.from = from;
|
|
2358
|
+
this.to = to;
|
|
2359
|
+
this.gapFrom = gapFrom;
|
|
2360
|
+
this.gapTo = gapTo;
|
|
2361
|
+
this.slice = slice;
|
|
2362
|
+
this.insert = insert;
|
|
2363
|
+
this.structure = structure;
|
|
2364
|
+
}
|
|
2365
|
+
apply(doc) {
|
|
2366
|
+
if (this.structure && (contentBetween(doc, this.from, this.gapFrom) || contentBetween(doc, this.gapTo, this.to)))
|
|
2367
|
+
return StepResult.fail("Structure gap-replace would overwrite content");
|
|
2368
|
+
let gap = doc.slice(this.gapFrom, this.gapTo);
|
|
2369
|
+
if (gap.openStart || gap.openEnd)
|
|
2370
|
+
return StepResult.fail("Gap is not a flat range");
|
|
2371
|
+
let inserted = this.slice.insertAt(this.insert, gap.content);
|
|
2372
|
+
if (!inserted)
|
|
2373
|
+
return StepResult.fail("Content does not fit in gap");
|
|
2374
|
+
return StepResult.fromReplace(doc, this.from, this.to, inserted);
|
|
2375
|
+
}
|
|
2376
|
+
getMap() {
|
|
2377
|
+
return new StepMap([
|
|
2378
|
+
this.from,
|
|
2379
|
+
this.gapFrom - this.from,
|
|
2380
|
+
this.insert,
|
|
2381
|
+
this.gapTo,
|
|
2382
|
+
this.to - this.gapTo,
|
|
2383
|
+
this.slice.size - this.insert
|
|
2384
|
+
]);
|
|
2385
|
+
}
|
|
2386
|
+
invert(doc) {
|
|
2387
|
+
let gap = this.gapTo - this.gapFrom;
|
|
2388
|
+
return new _ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
|
|
2389
|
+
}
|
|
2390
|
+
map(mapping) {
|
|
2391
|
+
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
2392
|
+
let gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1);
|
|
2393
|
+
let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
|
|
2394
|
+
if (from.deletedAcross && to.deletedAcross || gapFrom < from.pos || gapTo > to.pos)
|
|
2395
|
+
return null;
|
|
2396
|
+
return new _ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
|
|
2397
|
+
}
|
|
2398
|
+
toJSON() {
|
|
2399
|
+
let json = {
|
|
2400
|
+
stepType: "replaceAround",
|
|
2401
|
+
from: this.from,
|
|
2402
|
+
to: this.to,
|
|
2403
|
+
gapFrom: this.gapFrom,
|
|
2404
|
+
gapTo: this.gapTo,
|
|
2405
|
+
insert: this.insert
|
|
2406
|
+
};
|
|
2407
|
+
if (this.slice.size)
|
|
2408
|
+
json.slice = this.slice.toJSON();
|
|
2409
|
+
if (this.structure)
|
|
2410
|
+
json.structure = true;
|
|
2411
|
+
return json;
|
|
2412
|
+
}
|
|
2413
|
+
/**
|
|
2414
|
+
@internal
|
|
2415
|
+
*/
|
|
2416
|
+
static fromJSON(schema, json) {
|
|
2417
|
+
if (typeof json.from != "number" || typeof json.to != "number" || typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number")
|
|
2418
|
+
throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
|
|
2419
|
+
return new _ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
|
|
2420
|
+
}
|
|
2421
|
+
};
|
|
2422
|
+
Step.jsonID("replaceAround", ReplaceAroundStep);
|
|
2423
|
+
function contentBetween(doc, from, to) {
|
|
2424
|
+
let $from = doc.resolve(from), dist = to - from, depth = $from.depth;
|
|
2425
|
+
while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {
|
|
2426
|
+
depth--;
|
|
2427
|
+
dist--;
|
|
2428
|
+
}
|
|
2429
|
+
if (dist > 0) {
|
|
2430
|
+
let next = $from.node(depth).maybeChild($from.indexAfter(depth));
|
|
2431
|
+
while (dist > 0) {
|
|
2432
|
+
if (!next || next.isLeaf)
|
|
2433
|
+
return true;
|
|
2434
|
+
next = next.firstChild;
|
|
2435
|
+
dist--;
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
return false;
|
|
2439
|
+
}
|
|
2440
|
+
var AttrStep = class _AttrStep extends Step {
|
|
2441
|
+
/**
|
|
2442
|
+
Construct an attribute step.
|
|
2443
|
+
*/
|
|
2444
|
+
constructor(pos, attr, value) {
|
|
2445
|
+
super();
|
|
2446
|
+
this.pos = pos;
|
|
2447
|
+
this.attr = attr;
|
|
2448
|
+
this.value = value;
|
|
2449
|
+
}
|
|
2450
|
+
apply(doc) {
|
|
2451
|
+
let node = doc.nodeAt(this.pos);
|
|
2452
|
+
if (!node)
|
|
2453
|
+
return StepResult.fail("No node at attribute step's position");
|
|
2454
|
+
let attrs = /* @__PURE__ */ Object.create(null);
|
|
2455
|
+
for (let name in node.attrs)
|
|
2456
|
+
attrs[name] = node.attrs[name];
|
|
2457
|
+
attrs[this.attr] = this.value;
|
|
2458
|
+
let updated = node.type.create(attrs, null, node.marks);
|
|
2459
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
|
|
2460
|
+
}
|
|
2461
|
+
getMap() {
|
|
2462
|
+
return StepMap.empty;
|
|
2463
|
+
}
|
|
2464
|
+
invert(doc) {
|
|
2465
|
+
return new _AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);
|
|
2466
|
+
}
|
|
2467
|
+
map(mapping) {
|
|
2468
|
+
let pos = mapping.mapResult(this.pos, 1);
|
|
2469
|
+
return pos.deletedAfter ? null : new _AttrStep(pos.pos, this.attr, this.value);
|
|
2470
|
+
}
|
|
2471
|
+
toJSON() {
|
|
2472
|
+
return { stepType: "attr", pos: this.pos, attr: this.attr, value: this.value };
|
|
2473
|
+
}
|
|
2474
|
+
static fromJSON(schema, json) {
|
|
2475
|
+
if (typeof json.pos != "number" || typeof json.attr != "string")
|
|
2476
|
+
throw new RangeError("Invalid input for AttrStep.fromJSON");
|
|
2477
|
+
return new _AttrStep(json.pos, json.attr, json.value);
|
|
2478
|
+
}
|
|
2479
|
+
};
|
|
2480
|
+
Step.jsonID("attr", AttrStep);
|
|
2481
|
+
var DocAttrStep = class _DocAttrStep extends Step {
|
|
2482
|
+
/**
|
|
2483
|
+
Construct an attribute step.
|
|
2484
|
+
*/
|
|
2485
|
+
constructor(attr, value) {
|
|
2486
|
+
super();
|
|
2487
|
+
this.attr = attr;
|
|
2488
|
+
this.value = value;
|
|
2489
|
+
}
|
|
2490
|
+
apply(doc) {
|
|
2491
|
+
let attrs = /* @__PURE__ */ Object.create(null);
|
|
2492
|
+
for (let name in doc.attrs)
|
|
2493
|
+
attrs[name] = doc.attrs[name];
|
|
2494
|
+
attrs[this.attr] = this.value;
|
|
2495
|
+
let updated = doc.type.create(attrs, doc.content, doc.marks);
|
|
2496
|
+
return StepResult.ok(updated);
|
|
2497
|
+
}
|
|
2498
|
+
getMap() {
|
|
2499
|
+
return StepMap.empty;
|
|
2500
|
+
}
|
|
2501
|
+
invert(doc) {
|
|
2502
|
+
return new _DocAttrStep(this.attr, doc.attrs[this.attr]);
|
|
2503
|
+
}
|
|
2504
|
+
map(mapping) {
|
|
2505
|
+
return this;
|
|
2506
|
+
}
|
|
2507
|
+
toJSON() {
|
|
2508
|
+
return { stepType: "docAttr", attr: this.attr, value: this.value };
|
|
2509
|
+
}
|
|
2510
|
+
static fromJSON(schema, json) {
|
|
2511
|
+
if (typeof json.attr != "string")
|
|
2512
|
+
throw new RangeError("Invalid input for DocAttrStep.fromJSON");
|
|
2513
|
+
return new _DocAttrStep(json.attr, json.value);
|
|
2514
|
+
}
|
|
2515
|
+
};
|
|
2516
|
+
Step.jsonID("docAttr", DocAttrStep);
|
|
2517
|
+
var TransformError = class extends Error {
|
|
2518
|
+
};
|
|
2519
|
+
TransformError = function TransformError2(message) {
|
|
2520
|
+
let err = Error.call(this, message);
|
|
2521
|
+
err.__proto__ = TransformError2.prototype;
|
|
2522
|
+
return err;
|
|
2523
|
+
};
|
|
2524
|
+
TransformError.prototype = Object.create(Error.prototype);
|
|
2525
|
+
TransformError.prototype.constructor = TransformError;
|
|
2526
|
+
TransformError.prototype.name = "TransformError";
|
|
2527
|
+
|
|
2528
|
+
// ../../node_modules/.pnpm/prosemirror-state@1.4.3/node_modules/prosemirror-state/dist/index.js
|
|
2529
|
+
var classesById = /* @__PURE__ */ Object.create(null);
|
|
2530
|
+
var Selection = class {
|
|
2531
|
+
/**
|
|
2532
|
+
Initialize a selection with the head and anchor and ranges. If no
|
|
2533
|
+
ranges are given, constructs a single range across `$anchor` and
|
|
2534
|
+
`$head`.
|
|
2535
|
+
*/
|
|
2536
|
+
constructor($anchor, $head, ranges) {
|
|
2537
|
+
this.$anchor = $anchor;
|
|
2538
|
+
this.$head = $head;
|
|
2539
|
+
this.ranges = ranges || [new SelectionRange($anchor.min($head), $anchor.max($head))];
|
|
2540
|
+
}
|
|
2541
|
+
/**
|
|
2542
|
+
The selection's anchor, as an unresolved position.
|
|
2543
|
+
*/
|
|
2544
|
+
get anchor() {
|
|
2545
|
+
return this.$anchor.pos;
|
|
2546
|
+
}
|
|
2547
|
+
/**
|
|
2548
|
+
The selection's head.
|
|
2549
|
+
*/
|
|
2550
|
+
get head() {
|
|
2551
|
+
return this.$head.pos;
|
|
2552
|
+
}
|
|
2553
|
+
/**
|
|
2554
|
+
The lower bound of the selection's main range.
|
|
2555
|
+
*/
|
|
2556
|
+
get from() {
|
|
2557
|
+
return this.$from.pos;
|
|
2558
|
+
}
|
|
2559
|
+
/**
|
|
2560
|
+
The upper bound of the selection's main range.
|
|
2561
|
+
*/
|
|
2562
|
+
get to() {
|
|
2563
|
+
return this.$to.pos;
|
|
2564
|
+
}
|
|
2565
|
+
/**
|
|
2566
|
+
The resolved lower bound of the selection's main range.
|
|
2567
|
+
*/
|
|
2568
|
+
get $from() {
|
|
2569
|
+
return this.ranges[0].$from;
|
|
2570
|
+
}
|
|
2571
|
+
/**
|
|
2572
|
+
The resolved upper bound of the selection's main range.
|
|
2573
|
+
*/
|
|
2574
|
+
get $to() {
|
|
2575
|
+
return this.ranges[0].$to;
|
|
2576
|
+
}
|
|
2577
|
+
/**
|
|
2578
|
+
Indicates whether the selection contains any content.
|
|
2579
|
+
*/
|
|
2580
|
+
get empty() {
|
|
2581
|
+
let ranges = this.ranges;
|
|
2582
|
+
for (let i = 0; i < ranges.length; i++)
|
|
2583
|
+
if (ranges[i].$from.pos != ranges[i].$to.pos)
|
|
2584
|
+
return false;
|
|
2585
|
+
return true;
|
|
2586
|
+
}
|
|
2587
|
+
/**
|
|
2588
|
+
Get the content of this selection as a slice.
|
|
2589
|
+
*/
|
|
2590
|
+
content() {
|
|
2591
|
+
return this.$from.doc.slice(this.from, this.to, true);
|
|
2592
|
+
}
|
|
2593
|
+
/**
|
|
2594
|
+
Replace the selection with a slice or, if no slice is given,
|
|
2595
|
+
delete the selection. Will append to the given transaction.
|
|
2596
|
+
*/
|
|
2597
|
+
replace(tr, content = Slice.empty) {
|
|
2598
|
+
let lastNode = content.content.lastChild, lastParent = null;
|
|
2599
|
+
for (let i = 0; i < content.openEnd; i++) {
|
|
2600
|
+
lastParent = lastNode;
|
|
2601
|
+
lastNode = lastNode.lastChild;
|
|
2602
|
+
}
|
|
2603
|
+
let mapFrom = tr.steps.length, ranges = this.ranges;
|
|
2604
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
2605
|
+
let { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
|
|
2606
|
+
tr.replaceRange(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
|
|
2607
|
+
if (i == 0)
|
|
2608
|
+
selectionToInsertionEnd(tr, mapFrom, (lastNode ? lastNode.isInline : lastParent && lastParent.isTextblock) ? -1 : 1);
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
/**
|
|
2612
|
+
Replace the selection with the given node, appending the changes
|
|
2613
|
+
to the given transaction.
|
|
2614
|
+
*/
|
|
2615
|
+
replaceWith(tr, node) {
|
|
2616
|
+
let mapFrom = tr.steps.length, ranges = this.ranges;
|
|
2617
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
2618
|
+
let { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
|
|
2619
|
+
let from = mapping.map($from.pos), to = mapping.map($to.pos);
|
|
2620
|
+
if (i) {
|
|
2621
|
+
tr.deleteRange(from, to);
|
|
2622
|
+
} else {
|
|
2623
|
+
tr.replaceRangeWith(from, to, node);
|
|
2624
|
+
selectionToInsertionEnd(tr, mapFrom, node.isInline ? -1 : 1);
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
/**
|
|
2629
|
+
Find a valid cursor or leaf node selection starting at the given
|
|
2630
|
+
position and searching back if `dir` is negative, and forward if
|
|
2631
|
+
positive. When `textOnly` is true, only consider cursor
|
|
2632
|
+
selections. Will return null when no valid selection position is
|
|
2633
|
+
found.
|
|
2634
|
+
*/
|
|
2635
|
+
static findFrom($pos, dir, textOnly = false) {
|
|
2636
|
+
let inner = $pos.parent.inlineContent ? new TextSelection($pos) : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly);
|
|
2637
|
+
if (inner)
|
|
2638
|
+
return inner;
|
|
2639
|
+
for (let depth = $pos.depth - 1; depth >= 0; depth--) {
|
|
2640
|
+
let found2 = dir < 0 ? findSelectionIn($pos.node(0), $pos.node(depth), $pos.before(depth + 1), $pos.index(depth), dir, textOnly) : findSelectionIn($pos.node(0), $pos.node(depth), $pos.after(depth + 1), $pos.index(depth) + 1, dir, textOnly);
|
|
2641
|
+
if (found2)
|
|
2642
|
+
return found2;
|
|
2643
|
+
}
|
|
2644
|
+
return null;
|
|
2645
|
+
}
|
|
2646
|
+
/**
|
|
2647
|
+
Find a valid cursor or leaf node selection near the given
|
|
2648
|
+
position. Searches forward first by default, but if `bias` is
|
|
2649
|
+
negative, it will search backwards first.
|
|
2650
|
+
*/
|
|
2651
|
+
static near($pos, bias = 1) {
|
|
2652
|
+
return this.findFrom($pos, bias) || this.findFrom($pos, -bias) || new AllSelection($pos.node(0));
|
|
2653
|
+
}
|
|
2654
|
+
/**
|
|
2655
|
+
Find the cursor or leaf node selection closest to the start of
|
|
2656
|
+
the given document. Will return an
|
|
2657
|
+
[`AllSelection`](https://prosemirror.net/docs/ref/#state.AllSelection) if no valid position
|
|
2658
|
+
exists.
|
|
2659
|
+
*/
|
|
2660
|
+
static atStart(doc) {
|
|
2661
|
+
return findSelectionIn(doc, doc, 0, 0, 1) || new AllSelection(doc);
|
|
2662
|
+
}
|
|
2663
|
+
/**
|
|
2664
|
+
Find the cursor or leaf node selection closest to the end of the
|
|
2665
|
+
given document.
|
|
2666
|
+
*/
|
|
2667
|
+
static atEnd(doc) {
|
|
2668
|
+
return findSelectionIn(doc, doc, doc.content.size, doc.childCount, -1) || new AllSelection(doc);
|
|
2669
|
+
}
|
|
2670
|
+
/**
|
|
2671
|
+
Deserialize the JSON representation of a selection. Must be
|
|
2672
|
+
implemented for custom classes (as a static class method).
|
|
2673
|
+
*/
|
|
2674
|
+
static fromJSON(doc, json) {
|
|
2675
|
+
if (!json || !json.type)
|
|
2676
|
+
throw new RangeError("Invalid input for Selection.fromJSON");
|
|
2677
|
+
let cls = classesById[json.type];
|
|
2678
|
+
if (!cls)
|
|
2679
|
+
throw new RangeError(`No selection type ${json.type} defined`);
|
|
2680
|
+
return cls.fromJSON(doc, json);
|
|
2681
|
+
}
|
|
2682
|
+
/**
|
|
2683
|
+
To be able to deserialize selections from JSON, custom selection
|
|
2684
|
+
classes must register themselves with an ID string, so that they
|
|
2685
|
+
can be disambiguated. Try to pick something that's unlikely to
|
|
2686
|
+
clash with classes from other modules.
|
|
2687
|
+
*/
|
|
2688
|
+
static jsonID(id, selectionClass) {
|
|
2689
|
+
if (id in classesById)
|
|
2690
|
+
throw new RangeError("Duplicate use of selection JSON ID " + id);
|
|
2691
|
+
classesById[id] = selectionClass;
|
|
2692
|
+
selectionClass.prototype.jsonID = id;
|
|
2693
|
+
return selectionClass;
|
|
2694
|
+
}
|
|
2695
|
+
/**
|
|
2696
|
+
Get a [bookmark](https://prosemirror.net/docs/ref/#state.SelectionBookmark) for this selection,
|
|
2697
|
+
which is a value that can be mapped without having access to a
|
|
2698
|
+
current document, and later resolved to a real selection for a
|
|
2699
|
+
given document again. (This is used mostly by the history to
|
|
2700
|
+
track and restore old selections.) The default implementation of
|
|
2701
|
+
this method just converts the selection to a text selection and
|
|
2702
|
+
returns the bookmark for that.
|
|
2703
|
+
*/
|
|
2704
|
+
getBookmark() {
|
|
2705
|
+
return TextSelection.between(this.$anchor, this.$head).getBookmark();
|
|
2706
|
+
}
|
|
2707
|
+
};
|
|
2708
|
+
Selection.prototype.visible = true;
|
|
2709
|
+
var SelectionRange = class {
|
|
2710
|
+
/**
|
|
2711
|
+
Create a range.
|
|
2712
|
+
*/
|
|
2713
|
+
constructor($from, $to) {
|
|
2714
|
+
this.$from = $from;
|
|
2715
|
+
this.$to = $to;
|
|
2716
|
+
}
|
|
2717
|
+
};
|
|
2718
|
+
var warnedAboutTextSelection = false;
|
|
2719
|
+
function checkTextSelection($pos) {
|
|
2720
|
+
if (!warnedAboutTextSelection && !$pos.parent.inlineContent) {
|
|
2721
|
+
warnedAboutTextSelection = true;
|
|
2722
|
+
console["warn"]("TextSelection endpoint not pointing into a node with inline content (" + $pos.parent.type.name + ")");
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
var TextSelection = class _TextSelection extends Selection {
|
|
2726
|
+
/**
|
|
2727
|
+
Construct a text selection between the given points.
|
|
2728
|
+
*/
|
|
2729
|
+
constructor($anchor, $head = $anchor) {
|
|
2730
|
+
checkTextSelection($anchor);
|
|
2731
|
+
checkTextSelection($head);
|
|
2732
|
+
super($anchor, $head);
|
|
2733
|
+
}
|
|
2734
|
+
/**
|
|
2735
|
+
Returns a resolved position if this is a cursor selection (an
|
|
2736
|
+
empty text selection), and null otherwise.
|
|
2737
|
+
*/
|
|
2738
|
+
get $cursor() {
|
|
2739
|
+
return this.$anchor.pos == this.$head.pos ? this.$head : null;
|
|
2740
|
+
}
|
|
2741
|
+
map(doc, mapping) {
|
|
2742
|
+
let $head = doc.resolve(mapping.map(this.head));
|
|
2743
|
+
if (!$head.parent.inlineContent)
|
|
2744
|
+
return Selection.near($head);
|
|
2745
|
+
let $anchor = doc.resolve(mapping.map(this.anchor));
|
|
2746
|
+
return new _TextSelection($anchor.parent.inlineContent ? $anchor : $head, $head);
|
|
2747
|
+
}
|
|
2748
|
+
replace(tr, content = Slice.empty) {
|
|
2749
|
+
super.replace(tr, content);
|
|
2750
|
+
if (content == Slice.empty) {
|
|
2751
|
+
let marks = this.$from.marksAcross(this.$to);
|
|
2752
|
+
if (marks)
|
|
2753
|
+
tr.ensureMarks(marks);
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
eq(other) {
|
|
2757
|
+
return other instanceof _TextSelection && other.anchor == this.anchor && other.head == this.head;
|
|
2758
|
+
}
|
|
2759
|
+
getBookmark() {
|
|
2760
|
+
return new TextBookmark(this.anchor, this.head);
|
|
2761
|
+
}
|
|
2762
|
+
toJSON() {
|
|
2763
|
+
return { type: "text", anchor: this.anchor, head: this.head };
|
|
2764
|
+
}
|
|
2765
|
+
/**
|
|
2766
|
+
@internal
|
|
2767
|
+
*/
|
|
2768
|
+
static fromJSON(doc, json) {
|
|
2769
|
+
if (typeof json.anchor != "number" || typeof json.head != "number")
|
|
2770
|
+
throw new RangeError("Invalid input for TextSelection.fromJSON");
|
|
2771
|
+
return new _TextSelection(doc.resolve(json.anchor), doc.resolve(json.head));
|
|
2772
|
+
}
|
|
2773
|
+
/**
|
|
2774
|
+
Create a text selection from non-resolved positions.
|
|
2775
|
+
*/
|
|
2776
|
+
static create(doc, anchor, head = anchor) {
|
|
2777
|
+
let $anchor = doc.resolve(anchor);
|
|
2778
|
+
return new this($anchor, head == anchor ? $anchor : doc.resolve(head));
|
|
2779
|
+
}
|
|
2780
|
+
/**
|
|
2781
|
+
Return a text selection that spans the given positions or, if
|
|
2782
|
+
they aren't text positions, find a text selection near them.
|
|
2783
|
+
`bias` determines whether the method searches forward (default)
|
|
2784
|
+
or backwards (negative number) first. Will fall back to calling
|
|
2785
|
+
[`Selection.near`](https://prosemirror.net/docs/ref/#state.Selection^near) when the document
|
|
2786
|
+
doesn't contain a valid text position.
|
|
2787
|
+
*/
|
|
2788
|
+
static between($anchor, $head, bias) {
|
|
2789
|
+
let dPos = $anchor.pos - $head.pos;
|
|
2790
|
+
if (!bias || dPos)
|
|
2791
|
+
bias = dPos >= 0 ? 1 : -1;
|
|
2792
|
+
if (!$head.parent.inlineContent) {
|
|
2793
|
+
let found2 = Selection.findFrom($head, bias, true) || Selection.findFrom($head, -bias, true);
|
|
2794
|
+
if (found2)
|
|
2795
|
+
$head = found2.$head;
|
|
2796
|
+
else
|
|
2797
|
+
return Selection.near($head, bias);
|
|
2798
|
+
}
|
|
2799
|
+
if (!$anchor.parent.inlineContent) {
|
|
2800
|
+
if (dPos == 0) {
|
|
2801
|
+
$anchor = $head;
|
|
2802
|
+
} else {
|
|
2803
|
+
$anchor = (Selection.findFrom($anchor, -bias, true) || Selection.findFrom($anchor, bias, true)).$anchor;
|
|
2804
|
+
if ($anchor.pos < $head.pos != dPos < 0)
|
|
2805
|
+
$anchor = $head;
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
return new _TextSelection($anchor, $head);
|
|
2809
|
+
}
|
|
2810
|
+
};
|
|
2811
|
+
Selection.jsonID("text", TextSelection);
|
|
2812
|
+
var TextBookmark = class _TextBookmark {
|
|
2813
|
+
constructor(anchor, head) {
|
|
2814
|
+
this.anchor = anchor;
|
|
2815
|
+
this.head = head;
|
|
2816
|
+
}
|
|
2817
|
+
map(mapping) {
|
|
2818
|
+
return new _TextBookmark(mapping.map(this.anchor), mapping.map(this.head));
|
|
2819
|
+
}
|
|
2820
|
+
resolve(doc) {
|
|
2821
|
+
return TextSelection.between(doc.resolve(this.anchor), doc.resolve(this.head));
|
|
2822
|
+
}
|
|
2823
|
+
};
|
|
2824
|
+
var NodeSelection = class _NodeSelection extends Selection {
|
|
2825
|
+
/**
|
|
2826
|
+
Create a node selection. Does not verify the validity of its
|
|
2827
|
+
argument.
|
|
2828
|
+
*/
|
|
2829
|
+
constructor($pos) {
|
|
2830
|
+
let node = $pos.nodeAfter;
|
|
2831
|
+
let $end = $pos.node(0).resolve($pos.pos + node.nodeSize);
|
|
2832
|
+
super($pos, $end);
|
|
2833
|
+
this.node = node;
|
|
2834
|
+
}
|
|
2835
|
+
map(doc, mapping) {
|
|
2836
|
+
let { deleted, pos } = mapping.mapResult(this.anchor);
|
|
2837
|
+
let $pos = doc.resolve(pos);
|
|
2838
|
+
if (deleted)
|
|
2839
|
+
return Selection.near($pos);
|
|
2840
|
+
return new _NodeSelection($pos);
|
|
2841
|
+
}
|
|
2842
|
+
content() {
|
|
2843
|
+
return new Slice(Fragment.from(this.node), 0, 0);
|
|
2844
|
+
}
|
|
2845
|
+
eq(other) {
|
|
2846
|
+
return other instanceof _NodeSelection && other.anchor == this.anchor;
|
|
2847
|
+
}
|
|
2848
|
+
toJSON() {
|
|
2849
|
+
return { type: "node", anchor: this.anchor };
|
|
2850
|
+
}
|
|
2851
|
+
getBookmark() {
|
|
2852
|
+
return new NodeBookmark(this.anchor);
|
|
2853
|
+
}
|
|
2854
|
+
/**
|
|
2855
|
+
@internal
|
|
2856
|
+
*/
|
|
2857
|
+
static fromJSON(doc, json) {
|
|
2858
|
+
if (typeof json.anchor != "number")
|
|
2859
|
+
throw new RangeError("Invalid input for NodeSelection.fromJSON");
|
|
2860
|
+
return new _NodeSelection(doc.resolve(json.anchor));
|
|
2861
|
+
}
|
|
2862
|
+
/**
|
|
2863
|
+
Create a node selection from non-resolved positions.
|
|
2864
|
+
*/
|
|
2865
|
+
static create(doc, from) {
|
|
2866
|
+
return new _NodeSelection(doc.resolve(from));
|
|
2867
|
+
}
|
|
2868
|
+
/**
|
|
2869
|
+
Determines whether the given node may be selected as a node
|
|
2870
|
+
selection.
|
|
2871
|
+
*/
|
|
2872
|
+
static isSelectable(node) {
|
|
2873
|
+
return !node.isText && node.type.spec.selectable !== false;
|
|
2874
|
+
}
|
|
2875
|
+
};
|
|
2876
|
+
NodeSelection.prototype.visible = false;
|
|
2877
|
+
Selection.jsonID("node", NodeSelection);
|
|
2878
|
+
var NodeBookmark = class _NodeBookmark {
|
|
2879
|
+
constructor(anchor) {
|
|
2880
|
+
this.anchor = anchor;
|
|
2881
|
+
}
|
|
2882
|
+
map(mapping) {
|
|
2883
|
+
let { deleted, pos } = mapping.mapResult(this.anchor);
|
|
2884
|
+
return deleted ? new TextBookmark(pos, pos) : new _NodeBookmark(pos);
|
|
2885
|
+
}
|
|
2886
|
+
resolve(doc) {
|
|
2887
|
+
let $pos = doc.resolve(this.anchor), node = $pos.nodeAfter;
|
|
2888
|
+
if (node && NodeSelection.isSelectable(node))
|
|
2889
|
+
return new NodeSelection($pos);
|
|
2890
|
+
return Selection.near($pos);
|
|
2891
|
+
}
|
|
2892
|
+
};
|
|
2893
|
+
var AllSelection = class _AllSelection extends Selection {
|
|
2894
|
+
/**
|
|
2895
|
+
Create an all-selection over the given document.
|
|
2896
|
+
*/
|
|
2897
|
+
constructor(doc) {
|
|
2898
|
+
super(doc.resolve(0), doc.resolve(doc.content.size));
|
|
2899
|
+
}
|
|
2900
|
+
replace(tr, content = Slice.empty) {
|
|
2901
|
+
if (content == Slice.empty) {
|
|
2902
|
+
tr.delete(0, tr.doc.content.size);
|
|
2903
|
+
let sel = Selection.atStart(tr.doc);
|
|
2904
|
+
if (!sel.eq(tr.selection))
|
|
2905
|
+
tr.setSelection(sel);
|
|
2906
|
+
} else {
|
|
2907
|
+
super.replace(tr, content);
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2910
|
+
toJSON() {
|
|
2911
|
+
return { type: "all" };
|
|
2912
|
+
}
|
|
2913
|
+
/**
|
|
2914
|
+
@internal
|
|
2915
|
+
*/
|
|
2916
|
+
static fromJSON(doc) {
|
|
2917
|
+
return new _AllSelection(doc);
|
|
2918
|
+
}
|
|
2919
|
+
map(doc) {
|
|
2920
|
+
return new _AllSelection(doc);
|
|
2921
|
+
}
|
|
2922
|
+
eq(other) {
|
|
2923
|
+
return other instanceof _AllSelection;
|
|
2924
|
+
}
|
|
2925
|
+
getBookmark() {
|
|
2926
|
+
return AllBookmark;
|
|
2927
|
+
}
|
|
2928
|
+
};
|
|
2929
|
+
Selection.jsonID("all", AllSelection);
|
|
2930
|
+
var AllBookmark = {
|
|
2931
|
+
map() {
|
|
2932
|
+
return this;
|
|
2933
|
+
},
|
|
2934
|
+
resolve(doc) {
|
|
2935
|
+
return new AllSelection(doc);
|
|
2936
|
+
}
|
|
2937
|
+
};
|
|
2938
|
+
function findSelectionIn(doc, node, pos, index, dir, text = false) {
|
|
2939
|
+
if (node.inlineContent)
|
|
2940
|
+
return TextSelection.create(doc, pos);
|
|
2941
|
+
for (let i = index - (dir > 0 ? 0 : 1); dir > 0 ? i < node.childCount : i >= 0; i += dir) {
|
|
2942
|
+
let child = node.child(i);
|
|
2943
|
+
if (!child.isAtom) {
|
|
2944
|
+
let inner = findSelectionIn(doc, child, pos + dir, dir < 0 ? child.childCount : 0, dir, text);
|
|
2945
|
+
if (inner)
|
|
2946
|
+
return inner;
|
|
2947
|
+
} else if (!text && NodeSelection.isSelectable(child)) {
|
|
2948
|
+
return NodeSelection.create(doc, pos - (dir < 0 ? child.nodeSize : 0));
|
|
2949
|
+
}
|
|
2950
|
+
pos += child.nodeSize * dir;
|
|
2951
|
+
}
|
|
2952
|
+
return null;
|
|
2953
|
+
}
|
|
2954
|
+
function selectionToInsertionEnd(tr, startLen, bias) {
|
|
2955
|
+
let last = tr.steps.length - 1;
|
|
2956
|
+
if (last < startLen)
|
|
2957
|
+
return;
|
|
2958
|
+
let step = tr.steps[last];
|
|
2959
|
+
if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep))
|
|
2960
|
+
return;
|
|
2961
|
+
let map = tr.mapping.maps[last], end;
|
|
2962
|
+
map.forEach((_from, _to, _newFrom, newTo) => {
|
|
2963
|
+
if (end == null)
|
|
2964
|
+
end = newTo;
|
|
2965
|
+
});
|
|
2966
|
+
tr.setSelection(Selection.near(tr.doc.resolve(end), bias));
|
|
2967
|
+
}
|
|
2968
|
+
function bind(f, self) {
|
|
2969
|
+
return !self || !f ? f : f.bind(self);
|
|
2970
|
+
}
|
|
2971
|
+
var FieldDesc = class {
|
|
2972
|
+
constructor(name, desc, self) {
|
|
2973
|
+
this.name = name;
|
|
2974
|
+
this.init = bind(desc.init, self);
|
|
2975
|
+
this.apply = bind(desc.apply, self);
|
|
2976
|
+
}
|
|
2977
|
+
};
|
|
2978
|
+
var baseFields = [
|
|
2979
|
+
new FieldDesc("doc", {
|
|
2980
|
+
init(config) {
|
|
2981
|
+
return config.doc || config.schema.topNodeType.createAndFill();
|
|
2982
|
+
},
|
|
2983
|
+
apply(tr) {
|
|
2984
|
+
return tr.doc;
|
|
2985
|
+
}
|
|
2986
|
+
}),
|
|
2987
|
+
new FieldDesc("selection", {
|
|
2988
|
+
init(config, instance) {
|
|
2989
|
+
return config.selection || Selection.atStart(instance.doc);
|
|
2990
|
+
},
|
|
2991
|
+
apply(tr) {
|
|
2992
|
+
return tr.selection;
|
|
2993
|
+
}
|
|
2994
|
+
}),
|
|
2995
|
+
new FieldDesc("storedMarks", {
|
|
2996
|
+
init(config) {
|
|
2997
|
+
return config.storedMarks || null;
|
|
2998
|
+
},
|
|
2999
|
+
apply(tr, _marks, _old, state) {
|
|
3000
|
+
return state.selection.$cursor ? tr.storedMarks : null;
|
|
3001
|
+
}
|
|
3002
|
+
}),
|
|
3003
|
+
new FieldDesc("scrollToSelection", {
|
|
3004
|
+
init() {
|
|
3005
|
+
return 0;
|
|
3006
|
+
},
|
|
3007
|
+
apply(tr, prev) {
|
|
3008
|
+
return tr.scrolledIntoView ? prev + 1 : prev;
|
|
3009
|
+
}
|
|
3010
|
+
})
|
|
3011
|
+
];
|
|
3012
|
+
function bindProps(obj, self, target) {
|
|
3013
|
+
for (let prop in obj) {
|
|
3014
|
+
let val = obj[prop];
|
|
3015
|
+
if (val instanceof Function)
|
|
3016
|
+
val = val.bind(self);
|
|
3017
|
+
else if (prop == "handleDOMEvents")
|
|
3018
|
+
val = bindProps(val, self, {});
|
|
3019
|
+
target[prop] = val;
|
|
3020
|
+
}
|
|
3021
|
+
return target;
|
|
3022
|
+
}
|
|
3023
|
+
var Plugin = class {
|
|
3024
|
+
/**
|
|
3025
|
+
Create a plugin.
|
|
3026
|
+
*/
|
|
3027
|
+
constructor(spec) {
|
|
3028
|
+
this.spec = spec;
|
|
3029
|
+
this.props = {};
|
|
3030
|
+
if (spec.props)
|
|
3031
|
+
bindProps(spec.props, this, this.props);
|
|
3032
|
+
this.key = spec.key ? spec.key.key : createKey("plugin");
|
|
3033
|
+
}
|
|
3034
|
+
/**
|
|
3035
|
+
Extract the plugin's state field from an editor state.
|
|
3036
|
+
*/
|
|
3037
|
+
getState(state) {
|
|
3038
|
+
return state[this.key];
|
|
3039
|
+
}
|
|
3040
|
+
};
|
|
3041
|
+
var keys = /* @__PURE__ */ Object.create(null);
|
|
3042
|
+
function createKey(name) {
|
|
3043
|
+
if (name in keys)
|
|
3044
|
+
return name + "$" + ++keys[name];
|
|
3045
|
+
keys[name] = 0;
|
|
3046
|
+
return name + "$";
|
|
3047
|
+
}
|
|
3048
|
+
var PluginKey = class {
|
|
3049
|
+
/**
|
|
3050
|
+
Create a plugin key.
|
|
3051
|
+
*/
|
|
3052
|
+
constructor(name = "key") {
|
|
3053
|
+
this.key = createKey(name);
|
|
3054
|
+
}
|
|
3055
|
+
/**
|
|
3056
|
+
Get the active plugin with this key, if any, from an editor
|
|
3057
|
+
state.
|
|
3058
|
+
*/
|
|
3059
|
+
get(state) {
|
|
3060
|
+
return state.config.pluginsByKey[this.key];
|
|
3061
|
+
}
|
|
3062
|
+
/**
|
|
3063
|
+
Get the plugin's state from an editor state.
|
|
3064
|
+
*/
|
|
3065
|
+
getState(state) {
|
|
3066
|
+
return state[this.key];
|
|
3067
|
+
}
|
|
3068
|
+
};
|
|
3069
|
+
|
|
3070
|
+
// src/add-slide-button.ts
|
|
3071
|
+
var SlideNodeView = class {
|
|
3072
|
+
constructor(node, view, getPos, options) {
|
|
3073
|
+
this.node = node;
|
|
3074
|
+
this.view = view;
|
|
3075
|
+
this.getPos = getPos;
|
|
3076
|
+
this.options = options;
|
|
3077
|
+
this.dom = document.createElement("div");
|
|
3078
|
+
this.dom.classList.add("slide-wrapper");
|
|
3079
|
+
const slideSpec = node.type.spec;
|
|
3080
|
+
const rendered = slideSpec.toDOM ? slideSpec.toDOM(node) : null;
|
|
3081
|
+
if (rendered && Array.isArray(rendered)) {
|
|
3082
|
+
const [tag, attrs] = rendered;
|
|
3083
|
+
this.contentDOM = document.createElement(tag);
|
|
3084
|
+
if (attrs && typeof attrs === "object") {
|
|
3085
|
+
Object.entries(attrs).forEach(([key, value]) => {
|
|
3086
|
+
if (key === "class") {
|
|
3087
|
+
this.contentDOM.className = value;
|
|
3088
|
+
} else {
|
|
3089
|
+
this.contentDOM.setAttribute(key, String(value));
|
|
3090
|
+
}
|
|
3091
|
+
});
|
|
3092
|
+
}
|
|
3093
|
+
} else {
|
|
3094
|
+
this.contentDOM = document.createElement("div");
|
|
3095
|
+
this.contentDOM.className = "slide";
|
|
3096
|
+
this.contentDOM.setAttribute("data-node-type", "slide");
|
|
3097
|
+
}
|
|
3098
|
+
this.button = document.createElement("button");
|
|
3099
|
+
this.button.className = "add-slide-button";
|
|
3100
|
+
this.button.innerHTML = options.content;
|
|
3101
|
+
this.button.setAttribute("type", "button");
|
|
3102
|
+
this.button.contentEditable = "false";
|
|
3103
|
+
if (options.buttonStyle) {
|
|
3104
|
+
Object.entries(options.buttonStyle).forEach(([key, value]) => {
|
|
3105
|
+
const camelKey = key.replace(
|
|
3106
|
+
/-([a-z])/g,
|
|
3107
|
+
(_, letter) => letter.toUpperCase()
|
|
3108
|
+
);
|
|
3109
|
+
this.button.style[camelKey] = value;
|
|
3110
|
+
});
|
|
3111
|
+
}
|
|
3112
|
+
this.button.onclick = (event) => {
|
|
3113
|
+
event.preventDefault();
|
|
3114
|
+
event.stopPropagation();
|
|
3115
|
+
const pos = this.getPos();
|
|
3116
|
+
if (pos === void 0) return;
|
|
3117
|
+
if (options.onClick) {
|
|
3118
|
+
let slideIndex = 0;
|
|
3119
|
+
this.view.state.doc.nodesBetween(0, pos, (n) => {
|
|
3120
|
+
if (n.type.name === "slide") slideIndex++;
|
|
3121
|
+
});
|
|
3122
|
+
options.onClick({
|
|
3123
|
+
slideIndex,
|
|
3124
|
+
position: pos + this.node.nodeSize,
|
|
3125
|
+
view: this.view,
|
|
3126
|
+
event
|
|
3127
|
+
});
|
|
3128
|
+
} else {
|
|
3129
|
+
const schema = this.view.state.schema;
|
|
3130
|
+
const slideType = schema.nodes.slide;
|
|
3131
|
+
const paragraphType = schema.nodes.paragraph;
|
|
3132
|
+
const slideContent = paragraphType.create();
|
|
3133
|
+
const slide = slideType.create(null, slideContent);
|
|
3134
|
+
const tr = this.view.state.tr.insert(pos + this.node.nodeSize, slide);
|
|
3135
|
+
this.view.dispatch(tr);
|
|
3136
|
+
}
|
|
3137
|
+
};
|
|
3138
|
+
this.dom.appendChild(this.contentDOM);
|
|
3139
|
+
this.dom.appendChild(this.button);
|
|
3140
|
+
}
|
|
3141
|
+
update(node) {
|
|
3142
|
+
if (node.type.name !== "slide") return false;
|
|
3143
|
+
this.node = node;
|
|
3144
|
+
return true;
|
|
3145
|
+
}
|
|
3146
|
+
destroy() {
|
|
3147
|
+
this.button.onclick = null;
|
|
3148
|
+
}
|
|
3149
|
+
};
|
|
3150
|
+
var addSlideButtonStyles = `
|
|
3151
|
+
.slide-wrapper {
|
|
3152
|
+
position: relative;
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3155
|
+
.add-slide-button {
|
|
3156
|
+
display: flex;
|
|
3157
|
+
align-items: center;
|
|
3158
|
+
justify-content: center;
|
|
3159
|
+
width: 48px;
|
|
3160
|
+
height: 48px;
|
|
3161
|
+
margin: 16px auto 32px auto;
|
|
3162
|
+
padding: 0;
|
|
3163
|
+
border: 2px solid var(--slide-border, #e5e5e5);
|
|
3164
|
+
border-radius: 25%;
|
|
3165
|
+
background-color: var(--slide-bg, #ffffff);
|
|
3166
|
+
color: var(--editor-fg, #1a1a1a);
|
|
3167
|
+
font-size: 24px;
|
|
3168
|
+
font-weight: 300;
|
|
3169
|
+
cursor: pointer;
|
|
3170
|
+
transition: all 0.2s ease;
|
|
3171
|
+
box-shadow: var(--slide-shadow, 0 4px 12px rgba(0, 0, 0, 0.08));
|
|
3172
|
+
}
|
|
3173
|
+
|
|
3174
|
+
.add-slide-button:hover {
|
|
3175
|
+
background-color: var(--editor-hover, #f0f0f0);
|
|
3176
|
+
border-color: var(--editor-selection, #3b82f6);
|
|
3177
|
+
transform: scale(1.05);
|
|
3178
|
+
}
|
|
3179
|
+
|
|
3180
|
+
.add-slide-button:active {
|
|
3181
|
+
background-color: var(--editor-active, #e8e8e8);
|
|
3182
|
+
transform: scale(0.95);
|
|
3183
|
+
}
|
|
3184
|
+
|
|
3185
|
+
.add-slide-button:focus {
|
|
3186
|
+
outline: 2px solid var(--editor-focus, #3b82f6);
|
|
3187
|
+
outline-offset: 2px;
|
|
3188
|
+
}
|
|
3189
|
+
`;
|
|
3190
|
+
var AddSlideButton = Extension.create({
|
|
3191
|
+
name: "addSlideButton",
|
|
3192
|
+
addOptions() {
|
|
3193
|
+
return {
|
|
3194
|
+
injectCSS: true,
|
|
3195
|
+
injectNonce: void 0,
|
|
3196
|
+
buttonStyle: {},
|
|
3197
|
+
content: "+",
|
|
3198
|
+
onClick: null
|
|
3199
|
+
};
|
|
3200
|
+
},
|
|
3201
|
+
addProseMirrorPlugins() {
|
|
3202
|
+
const options = this.options;
|
|
3203
|
+
if (options.injectCSS) {
|
|
3204
|
+
createStyleTag(
|
|
3205
|
+
addSlideButtonStyles,
|
|
3206
|
+
options.injectNonce,
|
|
3207
|
+
"add-slide-button"
|
|
3208
|
+
);
|
|
3209
|
+
}
|
|
3210
|
+
return [
|
|
3211
|
+
new Plugin({
|
|
3212
|
+
key: new PluginKey("addSlideButton"),
|
|
3213
|
+
props: {
|
|
3214
|
+
nodeViews: {
|
|
3215
|
+
slide: (node, view, getPos) => {
|
|
3216
|
+
return new SlideNodeView(
|
|
3217
|
+
node,
|
|
3218
|
+
view,
|
|
3219
|
+
getPos,
|
|
3220
|
+
options
|
|
3221
|
+
);
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
3225
|
+
})
|
|
3226
|
+
];
|
|
3227
|
+
}
|
|
3228
|
+
});
|
|
3229
|
+
|
|
3230
|
+
// src/index.ts
|
|
3231
|
+
var index_default = AddSlideButton;
|
|
3232
|
+
export {
|
|
3233
|
+
AddSlideButton,
|
|
3234
|
+
index_default as default
|
|
3235
|
+
};
|
|
3236
|
+
//# sourceMappingURL=index.js.map
|