prosekit 0.0.0-next-20230627094841

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.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -0
  3. package/dist/basic/style.css +133 -0
  4. package/dist/chunk-23S3SZFA.js +46 -0
  5. package/dist/chunk-2MVHS73Q.js +709 -0
  6. package/dist/chunk-4GDRVRDP.js +0 -0
  7. package/dist/chunk-5PFF57NB.js +1546 -0
  8. package/dist/chunk-6A2XHVFY.js +46 -0
  9. package/dist/chunk-7OYIOTDD.js +16472 -0
  10. package/dist/chunk-ARJTWYPA.js +1321 -0
  11. package/dist/chunk-CDGN4JUS.js +1546 -0
  12. package/dist/chunk-CG5B6PMC.js +973 -0
  13. package/dist/chunk-DDN3TFRH.js +185 -0
  14. package/dist/chunk-EQV3CWHZ.js +2213 -0
  15. package/dist/chunk-ERNIDFFW.js +1711 -0
  16. package/dist/chunk-FAVXZAF7.js +3279 -0
  17. package/dist/chunk-HSPTUO6P.js +53 -0
  18. package/dist/chunk-JMNJUDT7.js +165 -0
  19. package/dist/chunk-LXCCO2LO.js +52 -0
  20. package/dist/chunk-MIPON3OH.js +922 -0
  21. package/dist/chunk-NAWSCY5F.js +166 -0
  22. package/dist/chunk-S64NFSV2.js +236 -0
  23. package/dist/chunk-S65R2BUY.js +15 -0
  24. package/dist/chunk-T2V5UU6H.js +204 -0
  25. package/dist/chunk-TWIMWRRZ.js +57 -0
  26. package/dist/chunk-US2P3K6I.js +185 -0
  27. package/dist/chunk-UTNVEPBA.js +950 -0
  28. package/dist/chunk-UWHQRU5N.js +4883 -0
  29. package/dist/chunk-VIKPJJET.js +662 -0
  30. package/dist/chunk-WAMZOD5I.js +67 -0
  31. package/dist/chunk-YUY5I2TY.js +236 -0
  32. package/dist/core/style.css +54 -0
  33. package/dist/extension-list/style.css +78 -0
  34. package/dist/pm/view/style/prosemirror.css +52 -0
  35. package/dist/prosekit-basic.js +2 -0
  36. package/dist/prosekit-core.js +2 -0
  37. package/dist/prosekit-extension-blockquote.js +2 -0
  38. package/dist/prosekit-extension-bold.js +2 -0
  39. package/dist/prosekit-extension-code-block.js +2 -0
  40. package/dist/prosekit-extension-code.js +2 -0
  41. package/dist/prosekit-extension-heading.js +2 -0
  42. package/dist/prosekit-extension-horizontal-rule.js +2 -0
  43. package/dist/prosekit-extension-italic.js +2 -0
  44. package/dist/prosekit-extension-list.js +2 -0
  45. package/dist/prosekit-extension-suggestion.js +2 -0
  46. package/dist/prosekit-lit-elements-menu-item.js +2 -0
  47. package/dist/prosekit-lit-elements-menu.js +2 -0
  48. package/dist/prosekit-lit-elements-popover.js +2 -0
  49. package/dist/prosekit-lit.js +2 -0
  50. package/dist/prosekit-pm-commands.js +2 -0
  51. package/dist/prosekit-pm-inputrules.js +2 -0
  52. package/dist/prosekit-pm-keymap.js +2 -0
  53. package/dist/prosekit-pm-model.js +2 -0
  54. package/dist/prosekit-pm-state.js +2 -0
  55. package/dist/prosekit-pm-transform.js +2 -0
  56. package/dist/prosekit-pm-view.js +2 -0
  57. package/dist/prosekit-pm.js +2 -0
  58. package/dist/prosekit-react-components-menu-item.js +2 -0
  59. package/dist/prosekit-react-components-menu.js +2 -0
  60. package/dist/prosekit-react-components-popover-suggestion.js +2 -0
  61. package/dist/prosekit-react-components-popover.js +2 -0
  62. package/dist/prosekit-react.js +2 -0
  63. package/dist/prosekit-vue-components-menu-item.js +2 -0
  64. package/dist/prosekit-vue-components-menu.js +2 -0
  65. package/dist/prosekit-vue-components-popover-suggestion.js +2 -0
  66. package/dist/prosekit-vue-components-popover.js +2 -0
  67. package/dist/prosekit-vue.js +2 -0
  68. package/dist/prosekit.js +0 -0
  69. package/package.json +262 -0
  70. package/src/index.ts +1 -0
@@ -0,0 +1,1711 @@
1
+ import {
2
+ Fragment,
3
+ Mark,
4
+ MarkType,
5
+ ReplaceError,
6
+ Slice
7
+ } from "./chunk-FAVXZAF7.js";
8
+
9
+ // ../../node_modules/.pnpm/prosemirror-transform@1.7.3/node_modules/prosemirror-transform/dist/index.js
10
+ var lower16 = 65535;
11
+ var factor16 = Math.pow(2, 16);
12
+ function makeRecover(index, offset) {
13
+ return index + offset * factor16;
14
+ }
15
+ function recoverIndex(value) {
16
+ return value & lower16;
17
+ }
18
+ function recoverOffset(value) {
19
+ return (value - (value & lower16)) / factor16;
20
+ }
21
+ var DEL_BEFORE = 1;
22
+ var DEL_AFTER = 2;
23
+ var DEL_ACROSS = 4;
24
+ var DEL_SIDE = 8;
25
+ var MapResult = class {
26
+ /**
27
+ @internal
28
+ */
29
+ constructor(pos, delInfo, recover) {
30
+ this.pos = pos;
31
+ this.delInfo = delInfo;
32
+ this.recover = recover;
33
+ }
34
+ /**
35
+ Tells you whether the position was deleted, that is, whether the
36
+ step removed the token on the side queried (via the `assoc`)
37
+ argument from the document.
38
+ */
39
+ get deleted() {
40
+ return (this.delInfo & DEL_SIDE) > 0;
41
+ }
42
+ /**
43
+ Tells you whether the token before the mapped position was deleted.
44
+ */
45
+ get deletedBefore() {
46
+ return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0;
47
+ }
48
+ /**
49
+ True when the token after the mapped position was deleted.
50
+ */
51
+ get deletedAfter() {
52
+ return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0;
53
+ }
54
+ /**
55
+ Tells whether any of the steps mapped through deletes across the
56
+ position (including both the token before and after the
57
+ position).
58
+ */
59
+ get deletedAcross() {
60
+ return (this.delInfo & DEL_ACROSS) > 0;
61
+ }
62
+ };
63
+ var StepMap = class _StepMap {
64
+ /**
65
+ Create a position map. The modifications to the document are
66
+ represented as an array of numbers, in which each group of three
67
+ represents a modified chunk as `[start, oldSize, newSize]`.
68
+ */
69
+ constructor(ranges, inverted = false) {
70
+ this.ranges = ranges;
71
+ this.inverted = inverted;
72
+ if (!ranges.length && _StepMap.empty)
73
+ return _StepMap.empty;
74
+ }
75
+ /**
76
+ @internal
77
+ */
78
+ recover(value) {
79
+ let diff = 0, index = recoverIndex(value);
80
+ if (!this.inverted)
81
+ for (let i = 0; i < index; i++)
82
+ diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1];
83
+ return this.ranges[index * 3] + diff + recoverOffset(value);
84
+ }
85
+ mapResult(pos, assoc = 1) {
86
+ return this._map(pos, assoc, false);
87
+ }
88
+ map(pos, assoc = 1) {
89
+ return this._map(pos, assoc, true);
90
+ }
91
+ /**
92
+ @internal
93
+ */
94
+ _map(pos, assoc, simple) {
95
+ let diff = 0, oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
96
+ for (let i = 0; i < this.ranges.length; i += 3) {
97
+ let start = this.ranges[i] - (this.inverted ? diff : 0);
98
+ if (start > pos)
99
+ break;
100
+ let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex], end = start + oldSize;
101
+ if (pos <= end) {
102
+ let side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc;
103
+ let result = start + diff + (side < 0 ? 0 : newSize);
104
+ if (simple)
105
+ return result;
106
+ let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);
107
+ let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;
108
+ if (assoc < 0 ? pos != start : pos != end)
109
+ del |= DEL_SIDE;
110
+ return new MapResult(result, del, recover);
111
+ }
112
+ diff += newSize - oldSize;
113
+ }
114
+ return simple ? pos + diff : new MapResult(pos + diff, 0, null);
115
+ }
116
+ /**
117
+ @internal
118
+ */
119
+ touches(pos, recover) {
120
+ let diff = 0, index = recoverIndex(recover);
121
+ let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
122
+ for (let i = 0; i < this.ranges.length; i += 3) {
123
+ let start = this.ranges[i] - (this.inverted ? diff : 0);
124
+ if (start > pos)
125
+ break;
126
+ let oldSize = this.ranges[i + oldIndex], end = start + oldSize;
127
+ if (pos <= end && i == index * 3)
128
+ return true;
129
+ diff += this.ranges[i + newIndex] - oldSize;
130
+ }
131
+ return false;
132
+ }
133
+ /**
134
+ Calls the given function on each of the changed ranges included in
135
+ this map.
136
+ */
137
+ forEach(f) {
138
+ let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
139
+ for (let i = 0, diff = 0; i < this.ranges.length; i += 3) {
140
+ let start = this.ranges[i], oldStart = start - (this.inverted ? diff : 0), newStart = start + (this.inverted ? 0 : diff);
141
+ let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex];
142
+ f(oldStart, oldStart + oldSize, newStart, newStart + newSize);
143
+ diff += newSize - oldSize;
144
+ }
145
+ }
146
+ /**
147
+ Create an inverted version of this map. The result can be used to
148
+ map positions in the post-step document to the pre-step document.
149
+ */
150
+ invert() {
151
+ return new _StepMap(this.ranges, !this.inverted);
152
+ }
153
+ /**
154
+ @internal
155
+ */
156
+ toString() {
157
+ return (this.inverted ? "-" : "") + JSON.stringify(this.ranges);
158
+ }
159
+ /**
160
+ Create a map that moves all positions by offset `n` (which may be
161
+ negative). This can be useful when applying steps meant for a
162
+ sub-document to a larger document, or vice-versa.
163
+ */
164
+ static offset(n) {
165
+ return n == 0 ? _StepMap.empty : new _StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]);
166
+ }
167
+ };
168
+ StepMap.empty = new StepMap([]);
169
+ var Mapping = class _Mapping {
170
+ /**
171
+ Create a new mapping with the given position maps.
172
+ */
173
+ constructor(maps = [], mirror, from = 0, to = maps.length) {
174
+ this.maps = maps;
175
+ this.mirror = mirror;
176
+ this.from = from;
177
+ this.to = to;
178
+ }
179
+ /**
180
+ Create a mapping that maps only through a part of this one.
181
+ */
182
+ slice(from = 0, to = this.maps.length) {
183
+ return new _Mapping(this.maps, this.mirror, from, to);
184
+ }
185
+ /**
186
+ @internal
187
+ */
188
+ copy() {
189
+ return new _Mapping(this.maps.slice(), this.mirror && this.mirror.slice(), this.from, this.to);
190
+ }
191
+ /**
192
+ Add a step map to the end of this mapping. If `mirrors` is
193
+ given, it should be the index of the step map that is the mirror
194
+ image of this one.
195
+ */
196
+ appendMap(map, mirrors) {
197
+ this.to = this.maps.push(map);
198
+ if (mirrors != null)
199
+ this.setMirror(this.maps.length - 1, mirrors);
200
+ }
201
+ /**
202
+ Add all the step maps in a given mapping to this one (preserving
203
+ mirroring information).
204
+ */
205
+ appendMapping(mapping) {
206
+ for (let i = 0, startSize = this.maps.length; i < mapping.maps.length; i++) {
207
+ let mirr = mapping.getMirror(i);
208
+ this.appendMap(mapping.maps[i], mirr != null && mirr < i ? startSize + mirr : void 0);
209
+ }
210
+ }
211
+ /**
212
+ Finds the offset of the step map that mirrors the map at the
213
+ given offset, in this mapping (as per the second argument to
214
+ `appendMap`).
215
+ */
216
+ getMirror(n) {
217
+ if (this.mirror) {
218
+ for (let i = 0; i < this.mirror.length; i++)
219
+ if (this.mirror[i] == n)
220
+ return this.mirror[i + (i % 2 ? -1 : 1)];
221
+ }
222
+ }
223
+ /**
224
+ @internal
225
+ */
226
+ setMirror(n, m) {
227
+ if (!this.mirror)
228
+ this.mirror = [];
229
+ this.mirror.push(n, m);
230
+ }
231
+ /**
232
+ Append the inverse of the given mapping to this one.
233
+ */
234
+ appendMappingInverted(mapping) {
235
+ for (let i = mapping.maps.length - 1, totalSize = this.maps.length + mapping.maps.length; i >= 0; i--) {
236
+ let mirr = mapping.getMirror(i);
237
+ this.appendMap(mapping.maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : void 0);
238
+ }
239
+ }
240
+ /**
241
+ Create an inverted version of this mapping.
242
+ */
243
+ invert() {
244
+ let inverse = new _Mapping();
245
+ inverse.appendMappingInverted(this);
246
+ return inverse;
247
+ }
248
+ /**
249
+ Map a position through this mapping.
250
+ */
251
+ map(pos, assoc = 1) {
252
+ if (this.mirror)
253
+ return this._map(pos, assoc, true);
254
+ for (let i = this.from; i < this.to; i++)
255
+ pos = this.maps[i].map(pos, assoc);
256
+ return pos;
257
+ }
258
+ /**
259
+ Map a position through this mapping, returning a mapping
260
+ result.
261
+ */
262
+ mapResult(pos, assoc = 1) {
263
+ return this._map(pos, assoc, false);
264
+ }
265
+ /**
266
+ @internal
267
+ */
268
+ _map(pos, assoc, simple) {
269
+ let delInfo = 0;
270
+ for (let i = this.from; i < this.to; i++) {
271
+ let map = this.maps[i], result = map.mapResult(pos, assoc);
272
+ if (result.recover != null) {
273
+ let corr = this.getMirror(i);
274
+ if (corr != null && corr > i && corr < this.to) {
275
+ i = corr;
276
+ pos = this.maps[corr].recover(result.recover);
277
+ continue;
278
+ }
279
+ }
280
+ delInfo |= result.delInfo;
281
+ pos = result.pos;
282
+ }
283
+ return simple ? pos : new MapResult(pos, delInfo, null);
284
+ }
285
+ };
286
+ var stepsByID = /* @__PURE__ */ Object.create(null);
287
+ var Step = class {
288
+ /**
289
+ Get the step map that represents the changes made by this step,
290
+ and which can be used to transform between positions in the old
291
+ and the new document.
292
+ */
293
+ getMap() {
294
+ return StepMap.empty;
295
+ }
296
+ /**
297
+ Try to merge this step with another one, to be applied directly
298
+ after it. Returns the merged step when possible, null if the
299
+ steps can't be merged.
300
+ */
301
+ merge(other) {
302
+ return null;
303
+ }
304
+ /**
305
+ Deserialize a step from its JSON representation. Will call
306
+ through to the step class' own implementation of this method.
307
+ */
308
+ static fromJSON(schema, json) {
309
+ if (!json || !json.stepType)
310
+ throw new RangeError("Invalid input for Step.fromJSON");
311
+ let type = stepsByID[json.stepType];
312
+ if (!type)
313
+ throw new RangeError(`No step type ${json.stepType} defined`);
314
+ return type.fromJSON(schema, json);
315
+ }
316
+ /**
317
+ To be able to serialize steps to JSON, each step needs a string
318
+ ID to attach to its JSON representation. Use this method to
319
+ register an ID for your step classes. Try to pick something
320
+ that's unlikely to clash with steps from other modules.
321
+ */
322
+ static jsonID(id, stepClass) {
323
+ if (id in stepsByID)
324
+ throw new RangeError("Duplicate use of step JSON ID " + id);
325
+ stepsByID[id] = stepClass;
326
+ stepClass.prototype.jsonID = id;
327
+ return stepClass;
328
+ }
329
+ };
330
+ var StepResult = class _StepResult {
331
+ /**
332
+ @internal
333
+ */
334
+ constructor(doc, failed) {
335
+ this.doc = doc;
336
+ this.failed = failed;
337
+ }
338
+ /**
339
+ Create a successful step result.
340
+ */
341
+ static ok(doc) {
342
+ return new _StepResult(doc, null);
343
+ }
344
+ /**
345
+ Create a failed step result.
346
+ */
347
+ static fail(message) {
348
+ return new _StepResult(null, message);
349
+ }
350
+ /**
351
+ Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given
352
+ arguments. Create a successful result if it succeeds, and a
353
+ failed one if it throws a `ReplaceError`.
354
+ */
355
+ static fromReplace(doc, from, to, slice) {
356
+ try {
357
+ return _StepResult.ok(doc.replace(from, to, slice));
358
+ } catch (e) {
359
+ if (e instanceof ReplaceError)
360
+ return _StepResult.fail(e.message);
361
+ throw e;
362
+ }
363
+ }
364
+ };
365
+ function mapFragment(fragment, f, parent) {
366
+ let mapped = [];
367
+ for (let i = 0; i < fragment.childCount; i++) {
368
+ let child = fragment.child(i);
369
+ if (child.content.size)
370
+ child = child.copy(mapFragment(child.content, f, child));
371
+ if (child.isInline)
372
+ child = f(child, parent, i);
373
+ mapped.push(child);
374
+ }
375
+ return Fragment.fromArray(mapped);
376
+ }
377
+ var AddMarkStep = class _AddMarkStep extends Step {
378
+ /**
379
+ Create a mark step.
380
+ */
381
+ constructor(from, to, mark) {
382
+ super();
383
+ this.from = from;
384
+ this.to = to;
385
+ this.mark = mark;
386
+ }
387
+ apply(doc) {
388
+ let oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from);
389
+ let parent = $from.node($from.sharedDepth(this.to));
390
+ let slice = new Slice(mapFragment(oldSlice.content, (node, parent2) => {
391
+ if (!node.isAtom || !parent2.type.allowsMarkType(this.mark.type))
392
+ return node;
393
+ return node.mark(this.mark.addToSet(node.marks));
394
+ }, parent), oldSlice.openStart, oldSlice.openEnd);
395
+ return StepResult.fromReplace(doc, this.from, this.to, slice);
396
+ }
397
+ invert() {
398
+ return new RemoveMarkStep(this.from, this.to, this.mark);
399
+ }
400
+ map(mapping) {
401
+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
402
+ if (from.deleted && to.deleted || from.pos >= to.pos)
403
+ return null;
404
+ return new _AddMarkStep(from.pos, to.pos, this.mark);
405
+ }
406
+ merge(other) {
407
+ if (other instanceof _AddMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from)
408
+ return new _AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
409
+ return null;
410
+ }
411
+ toJSON() {
412
+ return {
413
+ stepType: "addMark",
414
+ mark: this.mark.toJSON(),
415
+ from: this.from,
416
+ to: this.to
417
+ };
418
+ }
419
+ /**
420
+ @internal
421
+ */
422
+ static fromJSON(schema, json) {
423
+ if (typeof json.from != "number" || typeof json.to != "number")
424
+ throw new RangeError("Invalid input for AddMarkStep.fromJSON");
425
+ return new _AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
426
+ }
427
+ };
428
+ Step.jsonID("addMark", AddMarkStep);
429
+ var RemoveMarkStep = class _RemoveMarkStep extends Step {
430
+ /**
431
+ Create a mark-removing step.
432
+ */
433
+ constructor(from, to, mark) {
434
+ super();
435
+ this.from = from;
436
+ this.to = to;
437
+ this.mark = mark;
438
+ }
439
+ apply(doc) {
440
+ let oldSlice = doc.slice(this.from, this.to);
441
+ let slice = new Slice(mapFragment(oldSlice.content, (node) => {
442
+ return node.mark(this.mark.removeFromSet(node.marks));
443
+ }, doc), oldSlice.openStart, oldSlice.openEnd);
444
+ return StepResult.fromReplace(doc, this.from, this.to, slice);
445
+ }
446
+ invert() {
447
+ return new AddMarkStep(this.from, this.to, this.mark);
448
+ }
449
+ map(mapping) {
450
+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
451
+ if (from.deleted && to.deleted || from.pos >= to.pos)
452
+ return null;
453
+ return new _RemoveMarkStep(from.pos, to.pos, this.mark);
454
+ }
455
+ merge(other) {
456
+ if (other instanceof _RemoveMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from)
457
+ return new _RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
458
+ return null;
459
+ }
460
+ toJSON() {
461
+ return {
462
+ stepType: "removeMark",
463
+ mark: this.mark.toJSON(),
464
+ from: this.from,
465
+ to: this.to
466
+ };
467
+ }
468
+ /**
469
+ @internal
470
+ */
471
+ static fromJSON(schema, json) {
472
+ if (typeof json.from != "number" || typeof json.to != "number")
473
+ throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");
474
+ return new _RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
475
+ }
476
+ };
477
+ Step.jsonID("removeMark", RemoveMarkStep);
478
+ var AddNodeMarkStep = class _AddNodeMarkStep extends Step {
479
+ /**
480
+ Create a node mark step.
481
+ */
482
+ constructor(pos, mark) {
483
+ super();
484
+ this.pos = pos;
485
+ this.mark = mark;
486
+ }
487
+ apply(doc) {
488
+ let node = doc.nodeAt(this.pos);
489
+ if (!node)
490
+ return StepResult.fail("No node at mark step's position");
491
+ let updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));
492
+ return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
493
+ }
494
+ invert(doc) {
495
+ let node = doc.nodeAt(this.pos);
496
+ if (node) {
497
+ let newSet = this.mark.addToSet(node.marks);
498
+ if (newSet.length == node.marks.length) {
499
+ for (let i = 0; i < node.marks.length; i++)
500
+ if (!node.marks[i].isInSet(newSet))
501
+ return new _AddNodeMarkStep(this.pos, node.marks[i]);
502
+ return new _AddNodeMarkStep(this.pos, this.mark);
503
+ }
504
+ }
505
+ return new RemoveNodeMarkStep(this.pos, this.mark);
506
+ }
507
+ map(mapping) {
508
+ let pos = mapping.mapResult(this.pos, 1);
509
+ return pos.deletedAfter ? null : new _AddNodeMarkStep(pos.pos, this.mark);
510
+ }
511
+ toJSON() {
512
+ return { stepType: "addNodeMark", pos: this.pos, mark: this.mark.toJSON() };
513
+ }
514
+ /**
515
+ @internal
516
+ */
517
+ static fromJSON(schema, json) {
518
+ if (typeof json.pos != "number")
519
+ throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");
520
+ return new _AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
521
+ }
522
+ };
523
+ Step.jsonID("addNodeMark", AddNodeMarkStep);
524
+ var RemoveNodeMarkStep = class _RemoveNodeMarkStep extends Step {
525
+ /**
526
+ Create a mark-removing step.
527
+ */
528
+ constructor(pos, mark) {
529
+ super();
530
+ this.pos = pos;
531
+ this.mark = mark;
532
+ }
533
+ apply(doc) {
534
+ let node = doc.nodeAt(this.pos);
535
+ if (!node)
536
+ return StepResult.fail("No node at mark step's position");
537
+ let updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));
538
+ return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
539
+ }
540
+ invert(doc) {
541
+ let node = doc.nodeAt(this.pos);
542
+ if (!node || !this.mark.isInSet(node.marks))
543
+ return this;
544
+ return new AddNodeMarkStep(this.pos, this.mark);
545
+ }
546
+ map(mapping) {
547
+ let pos = mapping.mapResult(this.pos, 1);
548
+ return pos.deletedAfter ? null : new _RemoveNodeMarkStep(pos.pos, this.mark);
549
+ }
550
+ toJSON() {
551
+ return { stepType: "removeNodeMark", pos: this.pos, mark: this.mark.toJSON() };
552
+ }
553
+ /**
554
+ @internal
555
+ */
556
+ static fromJSON(schema, json) {
557
+ if (typeof json.pos != "number")
558
+ throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
559
+ return new _RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
560
+ }
561
+ };
562
+ Step.jsonID("removeNodeMark", RemoveNodeMarkStep);
563
+ var ReplaceStep = class _ReplaceStep extends Step {
564
+ /**
565
+ The given `slice` should fit the 'gap' between `from` and
566
+ `to`—the depths must line up, and the surrounding nodes must be
567
+ able to be joined with the open sides of the slice. When
568
+ `structure` is true, the step will fail if the content between
569
+ from and to is not just a sequence of closing and then opening
570
+ tokens (this is to guard against rebased replace steps
571
+ overwriting something they weren't supposed to).
572
+ */
573
+ constructor(from, to, slice, structure = false) {
574
+ super();
575
+ this.from = from;
576
+ this.to = to;
577
+ this.slice = slice;
578
+ this.structure = structure;
579
+ }
580
+ apply(doc) {
581
+ if (this.structure && contentBetween(doc, this.from, this.to))
582
+ return StepResult.fail("Structure replace would overwrite content");
583
+ return StepResult.fromReplace(doc, this.from, this.to, this.slice);
584
+ }
585
+ getMap() {
586
+ return new StepMap([this.from, this.to - this.from, this.slice.size]);
587
+ }
588
+ invert(doc) {
589
+ return new _ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));
590
+ }
591
+ map(mapping) {
592
+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
593
+ if (from.deletedAcross && to.deletedAcross)
594
+ return null;
595
+ return new _ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice);
596
+ }
597
+ merge(other) {
598
+ if (!(other instanceof _ReplaceStep) || other.structure || this.structure)
599
+ return null;
600
+ if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {
601
+ 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);
602
+ return new _ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure);
603
+ } else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {
604
+ 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);
605
+ return new _ReplaceStep(other.from, this.to, slice, this.structure);
606
+ } else {
607
+ return null;
608
+ }
609
+ }
610
+ toJSON() {
611
+ let json = { stepType: "replace", from: this.from, to: this.to };
612
+ if (this.slice.size)
613
+ json.slice = this.slice.toJSON();
614
+ if (this.structure)
615
+ json.structure = true;
616
+ return json;
617
+ }
618
+ /**
619
+ @internal
620
+ */
621
+ static fromJSON(schema, json) {
622
+ if (typeof json.from != "number" || typeof json.to != "number")
623
+ throw new RangeError("Invalid input for ReplaceStep.fromJSON");
624
+ return new _ReplaceStep(json.from, json.to, Slice.fromJSON(schema, json.slice), !!json.structure);
625
+ }
626
+ };
627
+ Step.jsonID("replace", ReplaceStep);
628
+ var ReplaceAroundStep = class _ReplaceAroundStep extends Step {
629
+ /**
630
+ Create a replace-around step with the given range and gap.
631
+ `insert` should be the point in the slice into which the content
632
+ of the gap should be moved. `structure` has the same meaning as
633
+ it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class.
634
+ */
635
+ constructor(from, to, gapFrom, gapTo, slice, insert, structure = false) {
636
+ super();
637
+ this.from = from;
638
+ this.to = to;
639
+ this.gapFrom = gapFrom;
640
+ this.gapTo = gapTo;
641
+ this.slice = slice;
642
+ this.insert = insert;
643
+ this.structure = structure;
644
+ }
645
+ apply(doc) {
646
+ if (this.structure && (contentBetween(doc, this.from, this.gapFrom) || contentBetween(doc, this.gapTo, this.to)))
647
+ return StepResult.fail("Structure gap-replace would overwrite content");
648
+ let gap = doc.slice(this.gapFrom, this.gapTo);
649
+ if (gap.openStart || gap.openEnd)
650
+ return StepResult.fail("Gap is not a flat range");
651
+ let inserted = this.slice.insertAt(this.insert, gap.content);
652
+ if (!inserted)
653
+ return StepResult.fail("Content does not fit in gap");
654
+ return StepResult.fromReplace(doc, this.from, this.to, inserted);
655
+ }
656
+ getMap() {
657
+ return new StepMap([
658
+ this.from,
659
+ this.gapFrom - this.from,
660
+ this.insert,
661
+ this.gapTo,
662
+ this.to - this.gapTo,
663
+ this.slice.size - this.insert
664
+ ]);
665
+ }
666
+ invert(doc) {
667
+ let gap = this.gapTo - this.gapFrom;
668
+ 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);
669
+ }
670
+ map(mapping) {
671
+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
672
+ let gapFrom = mapping.map(this.gapFrom, -1), gapTo = mapping.map(this.gapTo, 1);
673
+ if (from.deletedAcross && to.deletedAcross || gapFrom < from.pos || gapTo > to.pos)
674
+ return null;
675
+ return new _ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
676
+ }
677
+ toJSON() {
678
+ let json = {
679
+ stepType: "replaceAround",
680
+ from: this.from,
681
+ to: this.to,
682
+ gapFrom: this.gapFrom,
683
+ gapTo: this.gapTo,
684
+ insert: this.insert
685
+ };
686
+ if (this.slice.size)
687
+ json.slice = this.slice.toJSON();
688
+ if (this.structure)
689
+ json.structure = true;
690
+ return json;
691
+ }
692
+ /**
693
+ @internal
694
+ */
695
+ static fromJSON(schema, json) {
696
+ if (typeof json.from != "number" || typeof json.to != "number" || typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number")
697
+ throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
698
+ return new _ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
699
+ }
700
+ };
701
+ Step.jsonID("replaceAround", ReplaceAroundStep);
702
+ function contentBetween(doc, from, to) {
703
+ let $from = doc.resolve(from), dist = to - from, depth = $from.depth;
704
+ while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {
705
+ depth--;
706
+ dist--;
707
+ }
708
+ if (dist > 0) {
709
+ let next = $from.node(depth).maybeChild($from.indexAfter(depth));
710
+ while (dist > 0) {
711
+ if (!next || next.isLeaf)
712
+ return true;
713
+ next = next.firstChild;
714
+ dist--;
715
+ }
716
+ }
717
+ return false;
718
+ }
719
+ function addMark(tr, from, to, mark) {
720
+ let removed = [], added = [];
721
+ let removing, adding;
722
+ tr.doc.nodesBetween(from, to, (node, pos, parent) => {
723
+ if (!node.isInline)
724
+ return;
725
+ let marks = node.marks;
726
+ if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) {
727
+ let start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to);
728
+ let newSet = mark.addToSet(marks);
729
+ for (let i = 0; i < marks.length; i++) {
730
+ if (!marks[i].isInSet(newSet)) {
731
+ if (removing && removing.to == start && removing.mark.eq(marks[i]))
732
+ removing.to = end;
733
+ else
734
+ removed.push(removing = new RemoveMarkStep(start, end, marks[i]));
735
+ }
736
+ }
737
+ if (adding && adding.to == start)
738
+ adding.to = end;
739
+ else
740
+ added.push(adding = new AddMarkStep(start, end, mark));
741
+ }
742
+ });
743
+ removed.forEach((s) => tr.step(s));
744
+ added.forEach((s) => tr.step(s));
745
+ }
746
+ function removeMark(tr, from, to, mark) {
747
+ let matched = [], step = 0;
748
+ tr.doc.nodesBetween(from, to, (node, pos) => {
749
+ if (!node.isInline)
750
+ return;
751
+ step++;
752
+ let toRemove = null;
753
+ if (mark instanceof MarkType) {
754
+ let set = node.marks, found;
755
+ while (found = mark.isInSet(set)) {
756
+ (toRemove || (toRemove = [])).push(found);
757
+ set = found.removeFromSet(set);
758
+ }
759
+ } else if (mark) {
760
+ if (mark.isInSet(node.marks))
761
+ toRemove = [mark];
762
+ } else {
763
+ toRemove = node.marks;
764
+ }
765
+ if (toRemove && toRemove.length) {
766
+ let end = Math.min(pos + node.nodeSize, to);
767
+ for (let i = 0; i < toRemove.length; i++) {
768
+ let style = toRemove[i], found;
769
+ for (let j = 0; j < matched.length; j++) {
770
+ let m = matched[j];
771
+ if (m.step == step - 1 && style.eq(matched[j].style))
772
+ found = m;
773
+ }
774
+ if (found) {
775
+ found.to = end;
776
+ found.step = step;
777
+ } else {
778
+ matched.push({ style, from: Math.max(pos, from), to: end, step });
779
+ }
780
+ }
781
+ }
782
+ });
783
+ matched.forEach((m) => tr.step(new RemoveMarkStep(m.from, m.to, m.style)));
784
+ }
785
+ function clearIncompatible(tr, pos, parentType, match = parentType.contentMatch) {
786
+ let node = tr.doc.nodeAt(pos);
787
+ let delSteps = [], cur = pos + 1;
788
+ for (let i = 0; i < node.childCount; i++) {
789
+ let child = node.child(i), end = cur + child.nodeSize;
790
+ let allowed = match.matchType(child.type);
791
+ if (!allowed) {
792
+ delSteps.push(new ReplaceStep(cur, end, Slice.empty));
793
+ } else {
794
+ match = allowed;
795
+ for (let j = 0; j < child.marks.length; j++)
796
+ if (!parentType.allowsMarkType(child.marks[j].type))
797
+ tr.step(new RemoveMarkStep(cur, end, child.marks[j]));
798
+ }
799
+ cur = end;
800
+ }
801
+ if (!match.validEnd) {
802
+ let fill = match.fillBefore(Fragment.empty, true);
803
+ tr.replace(cur, cur, new Slice(fill, 0, 0));
804
+ }
805
+ for (let i = delSteps.length - 1; i >= 0; i--)
806
+ tr.step(delSteps[i]);
807
+ }
808
+ function canCut(node, start, end) {
809
+ return (start == 0 || node.canReplace(start, node.childCount)) && (end == node.childCount || node.canReplace(0, end));
810
+ }
811
+ function liftTarget(range) {
812
+ let parent = range.parent;
813
+ let content = parent.content.cutByIndex(range.startIndex, range.endIndex);
814
+ for (let depth = range.depth; ; --depth) {
815
+ let node = range.$from.node(depth);
816
+ let index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth);
817
+ if (depth < range.depth && node.canReplace(index, endIndex, content))
818
+ return depth;
819
+ if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex))
820
+ break;
821
+ }
822
+ return null;
823
+ }
824
+ function lift(tr, range, target) {
825
+ let { $from, $to, depth } = range;
826
+ let gapStart = $from.before(depth + 1), gapEnd = $to.after(depth + 1);
827
+ let start = gapStart, end = gapEnd;
828
+ let before = Fragment.empty, openStart = 0;
829
+ for (let d = depth, splitting = false; d > target; d--)
830
+ if (splitting || $from.index(d) > 0) {
831
+ splitting = true;
832
+ before = Fragment.from($from.node(d).copy(before));
833
+ openStart++;
834
+ } else {
835
+ start--;
836
+ }
837
+ let after = Fragment.empty, openEnd = 0;
838
+ for (let d = depth, splitting = false; d > target; d--)
839
+ if (splitting || $to.after(d + 1) < $to.end(d)) {
840
+ splitting = true;
841
+ after = Fragment.from($to.node(d).copy(after));
842
+ openEnd++;
843
+ } else {
844
+ end++;
845
+ }
846
+ tr.step(new ReplaceAroundStep(start, end, gapStart, gapEnd, new Slice(before.append(after), openStart, openEnd), before.size - openStart, true));
847
+ }
848
+ function findWrapping(range, nodeType, attrs = null, innerRange = range) {
849
+ let around = findWrappingOutside(range, nodeType);
850
+ let inner = around && findWrappingInside(innerRange, nodeType);
851
+ if (!inner)
852
+ return null;
853
+ return around.map(withAttrs).concat({ type: nodeType, attrs }).concat(inner.map(withAttrs));
854
+ }
855
+ function withAttrs(type) {
856
+ return { type, attrs: null };
857
+ }
858
+ function findWrappingOutside(range, type) {
859
+ let { parent, startIndex, endIndex } = range;
860
+ let around = parent.contentMatchAt(startIndex).findWrapping(type);
861
+ if (!around)
862
+ return null;
863
+ let outer = around.length ? around[0] : type;
864
+ return parent.canReplaceWith(startIndex, endIndex, outer) ? around : null;
865
+ }
866
+ function findWrappingInside(range, type) {
867
+ let { parent, startIndex, endIndex } = range;
868
+ let inner = parent.child(startIndex);
869
+ let inside = type.contentMatch.findWrapping(inner.type);
870
+ if (!inside)
871
+ return null;
872
+ let lastType = inside.length ? inside[inside.length - 1] : type;
873
+ let innerMatch = lastType.contentMatch;
874
+ for (let i = startIndex; innerMatch && i < endIndex; i++)
875
+ innerMatch = innerMatch.matchType(parent.child(i).type);
876
+ if (!innerMatch || !innerMatch.validEnd)
877
+ return null;
878
+ return inside;
879
+ }
880
+ function wrap(tr, range, wrappers) {
881
+ let content = Fragment.empty;
882
+ for (let i = wrappers.length - 1; i >= 0; i--) {
883
+ if (content.size) {
884
+ let match = wrappers[i].type.contentMatch.matchFragment(content);
885
+ if (!match || !match.validEnd)
886
+ throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper");
887
+ }
888
+ content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
889
+ }
890
+ let start = range.start, end = range.end;
891
+ tr.step(new ReplaceAroundStep(start, end, start, end, new Slice(content, 0, 0), wrappers.length, true));
892
+ }
893
+ function setBlockType(tr, from, to, type, attrs) {
894
+ if (!type.isTextblock)
895
+ throw new RangeError("Type given to setBlockType should be a textblock");
896
+ let mapFrom = tr.steps.length;
897
+ tr.doc.nodesBetween(from, to, (node, pos) => {
898
+ if (node.isTextblock && !node.hasMarkup(type, attrs) && canChangeType(tr.doc, tr.mapping.slice(mapFrom).map(pos), type)) {
899
+ tr.clearIncompatible(tr.mapping.slice(mapFrom).map(pos, 1), type);
900
+ let mapping = tr.mapping.slice(mapFrom);
901
+ let startM = mapping.map(pos, 1), endM = mapping.map(pos + node.nodeSize, 1);
902
+ tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new Slice(Fragment.from(type.create(attrs, null, node.marks)), 0, 0), 1, true));
903
+ return false;
904
+ }
905
+ });
906
+ }
907
+ function canChangeType(doc, pos, type) {
908
+ let $pos = doc.resolve(pos), index = $pos.index();
909
+ return $pos.parent.canReplaceWith(index, index + 1, type);
910
+ }
911
+ function setNodeMarkup(tr, pos, type, attrs, marks) {
912
+ let node = tr.doc.nodeAt(pos);
913
+ if (!node)
914
+ throw new RangeError("No node at given position");
915
+ if (!type)
916
+ type = node.type;
917
+ let newNode = type.create(attrs, null, marks || node.marks);
918
+ if (node.isLeaf)
919
+ return tr.replaceWith(pos, pos + node.nodeSize, newNode);
920
+ if (!type.validContent(node.content))
921
+ throw new RangeError("Invalid content for node type " + type.name);
922
+ tr.step(new ReplaceAroundStep(pos, pos + node.nodeSize, pos + 1, pos + node.nodeSize - 1, new Slice(Fragment.from(newNode), 0, 0), 1, true));
923
+ }
924
+ function canSplit(doc, pos, depth = 1, typesAfter) {
925
+ let $pos = doc.resolve(pos), base = $pos.depth - depth;
926
+ let innerType = typesAfter && typesAfter[typesAfter.length - 1] || $pos.parent;
927
+ if (base < 0 || $pos.parent.type.spec.isolating || !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) || !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount)))
928
+ return false;
929
+ for (let d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) {
930
+ let node = $pos.node(d), index2 = $pos.index(d);
931
+ if (node.type.spec.isolating)
932
+ return false;
933
+ let rest = node.content.cutByIndex(index2, node.childCount);
934
+ let overrideChild = typesAfter && typesAfter[i + 1];
935
+ if (overrideChild)
936
+ rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs));
937
+ let after = typesAfter && typesAfter[i] || node;
938
+ if (!node.canReplace(index2 + 1, node.childCount) || !after.type.validContent(rest))
939
+ return false;
940
+ }
941
+ let index = $pos.indexAfter(base);
942
+ let baseType = typesAfter && typesAfter[0];
943
+ return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type);
944
+ }
945
+ function split(tr, pos, depth = 1, typesAfter) {
946
+ let $pos = tr.doc.resolve(pos), before = Fragment.empty, after = Fragment.empty;
947
+ for (let d = $pos.depth, e = $pos.depth - depth, i = depth - 1; d > e; d--, i--) {
948
+ before = Fragment.from($pos.node(d).copy(before));
949
+ let typeAfter = typesAfter && typesAfter[i];
950
+ after = Fragment.from(typeAfter ? typeAfter.type.create(typeAfter.attrs, after) : $pos.node(d).copy(after));
951
+ }
952
+ tr.step(new ReplaceStep(pos, pos, new Slice(before.append(after), depth, depth), true));
953
+ }
954
+ function canJoin(doc, pos) {
955
+ let $pos = doc.resolve(pos), index = $pos.index();
956
+ return joinable($pos.nodeBefore, $pos.nodeAfter) && $pos.parent.canReplace(index, index + 1);
957
+ }
958
+ function joinable(a, b) {
959
+ return !!(a && b && !a.isLeaf && a.canAppend(b));
960
+ }
961
+ function joinPoint(doc, pos, dir = -1) {
962
+ let $pos = doc.resolve(pos);
963
+ for (let d = $pos.depth; ; d--) {
964
+ let before, after, index = $pos.index(d);
965
+ if (d == $pos.depth) {
966
+ before = $pos.nodeBefore;
967
+ after = $pos.nodeAfter;
968
+ } else if (dir > 0) {
969
+ before = $pos.node(d + 1);
970
+ index++;
971
+ after = $pos.node(d).maybeChild(index);
972
+ } else {
973
+ before = $pos.node(d).maybeChild(index - 1);
974
+ after = $pos.node(d + 1);
975
+ }
976
+ if (before && !before.isTextblock && joinable(before, after) && $pos.node(d).canReplace(index, index + 1))
977
+ return pos;
978
+ if (d == 0)
979
+ break;
980
+ pos = dir < 0 ? $pos.before(d) : $pos.after(d);
981
+ }
982
+ }
983
+ function join(tr, pos, depth) {
984
+ let step = new ReplaceStep(pos - depth, pos + depth, Slice.empty, true);
985
+ tr.step(step);
986
+ }
987
+ function insertPoint(doc, pos, nodeType) {
988
+ let $pos = doc.resolve(pos);
989
+ if ($pos.parent.canReplaceWith($pos.index(), $pos.index(), nodeType))
990
+ return pos;
991
+ if ($pos.parentOffset == 0)
992
+ for (let d = $pos.depth - 1; d >= 0; d--) {
993
+ let index = $pos.index(d);
994
+ if ($pos.node(d).canReplaceWith(index, index, nodeType))
995
+ return $pos.before(d + 1);
996
+ if (index > 0)
997
+ return null;
998
+ }
999
+ if ($pos.parentOffset == $pos.parent.content.size)
1000
+ for (let d = $pos.depth - 1; d >= 0; d--) {
1001
+ let index = $pos.indexAfter(d);
1002
+ if ($pos.node(d).canReplaceWith(index, index, nodeType))
1003
+ return $pos.after(d + 1);
1004
+ if (index < $pos.node(d).childCount)
1005
+ return null;
1006
+ }
1007
+ return null;
1008
+ }
1009
+ function dropPoint(doc, pos, slice) {
1010
+ let $pos = doc.resolve(pos);
1011
+ if (!slice.content.size)
1012
+ return pos;
1013
+ let content = slice.content;
1014
+ for (let i = 0; i < slice.openStart; i++)
1015
+ content = content.firstChild.content;
1016
+ for (let pass = 1; pass <= (slice.openStart == 0 && slice.size ? 2 : 1); pass++) {
1017
+ for (let d = $pos.depth; d >= 0; d--) {
1018
+ let bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1;
1019
+ let insertPos = $pos.index(d) + (bias > 0 ? 1 : 0);
1020
+ let parent = $pos.node(d), fits = false;
1021
+ if (pass == 1) {
1022
+ fits = parent.canReplace(insertPos, insertPos, content);
1023
+ } else {
1024
+ let wrapping = parent.contentMatchAt(insertPos).findWrapping(content.firstChild.type);
1025
+ fits = wrapping && parent.canReplaceWith(insertPos, insertPos, wrapping[0]);
1026
+ }
1027
+ if (fits)
1028
+ return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1);
1029
+ }
1030
+ }
1031
+ return null;
1032
+ }
1033
+ function replaceStep(doc, from, to = from, slice = Slice.empty) {
1034
+ if (from == to && !slice.size)
1035
+ return null;
1036
+ let $from = doc.resolve(from), $to = doc.resolve(to);
1037
+ if (fitsTrivially($from, $to, slice))
1038
+ return new ReplaceStep(from, to, slice);
1039
+ return new Fitter($from, $to, slice).fit();
1040
+ }
1041
+ function fitsTrivially($from, $to, slice) {
1042
+ return !slice.openStart && !slice.openEnd && $from.start() == $to.start() && $from.parent.canReplace($from.index(), $to.index(), slice.content);
1043
+ }
1044
+ var Fitter = class {
1045
+ constructor($from, $to, unplaced) {
1046
+ this.$from = $from;
1047
+ this.$to = $to;
1048
+ this.unplaced = unplaced;
1049
+ this.frontier = [];
1050
+ this.placed = Fragment.empty;
1051
+ for (let i = 0; i <= $from.depth; i++) {
1052
+ let node = $from.node(i);
1053
+ this.frontier.push({
1054
+ type: node.type,
1055
+ match: node.contentMatchAt($from.indexAfter(i))
1056
+ });
1057
+ }
1058
+ for (let i = $from.depth; i > 0; i--)
1059
+ this.placed = Fragment.from($from.node(i).copy(this.placed));
1060
+ }
1061
+ get depth() {
1062
+ return this.frontier.length - 1;
1063
+ }
1064
+ fit() {
1065
+ while (this.unplaced.size) {
1066
+ let fit = this.findFittable();
1067
+ if (fit)
1068
+ this.placeNodes(fit);
1069
+ else
1070
+ this.openMore() || this.dropNode();
1071
+ }
1072
+ let moveInline = this.mustMoveInline(), placedSize = this.placed.size - this.depth - this.$from.depth;
1073
+ let $from = this.$from, $to = this.close(moveInline < 0 ? this.$to : $from.doc.resolve(moveInline));
1074
+ if (!$to)
1075
+ return null;
1076
+ let content = this.placed, openStart = $from.depth, openEnd = $to.depth;
1077
+ while (openStart && openEnd && content.childCount == 1) {
1078
+ content = content.firstChild.content;
1079
+ openStart--;
1080
+ openEnd--;
1081
+ }
1082
+ let slice = new Slice(content, openStart, openEnd);
1083
+ if (moveInline > -1)
1084
+ return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice, placedSize);
1085
+ if (slice.size || $from.pos != this.$to.pos)
1086
+ return new ReplaceStep($from.pos, $to.pos, slice);
1087
+ return null;
1088
+ }
1089
+ // Find a position on the start spine of `this.unplaced` that has
1090
+ // content that can be moved somewhere on the frontier. Returns two
1091
+ // depths, one for the slice and one for the frontier.
1092
+ findFittable() {
1093
+ let startDepth = this.unplaced.openStart;
1094
+ for (let cur = this.unplaced.content, d = 0, openEnd = this.unplaced.openEnd; d < startDepth; d++) {
1095
+ let node = cur.firstChild;
1096
+ if (cur.childCount > 1)
1097
+ openEnd = 0;
1098
+ if (node.type.spec.isolating && openEnd <= d) {
1099
+ startDepth = d;
1100
+ break;
1101
+ }
1102
+ cur = node.content;
1103
+ }
1104
+ for (let pass = 1; pass <= 2; pass++) {
1105
+ for (let sliceDepth = pass == 1 ? startDepth : this.unplaced.openStart; sliceDepth >= 0; sliceDepth--) {
1106
+ let fragment, parent = null;
1107
+ if (sliceDepth) {
1108
+ parent = contentAt(this.unplaced.content, sliceDepth - 1).firstChild;
1109
+ fragment = parent.content;
1110
+ } else {
1111
+ fragment = this.unplaced.content;
1112
+ }
1113
+ let first = fragment.firstChild;
1114
+ for (let frontierDepth = this.depth; frontierDepth >= 0; frontierDepth--) {
1115
+ let { type, match } = this.frontier[frontierDepth], wrap2, inject = null;
1116
+ if (pass == 1 && (first ? match.matchType(first.type) || (inject = match.fillBefore(Fragment.from(first), false)) : parent && type.compatibleContent(parent.type)))
1117
+ return { sliceDepth, frontierDepth, parent, inject };
1118
+ else if (pass == 2 && first && (wrap2 = match.findWrapping(first.type)))
1119
+ return { sliceDepth, frontierDepth, parent, wrap: wrap2 };
1120
+ if (parent && match.matchType(parent.type))
1121
+ break;
1122
+ }
1123
+ }
1124
+ }
1125
+ }
1126
+ openMore() {
1127
+ let { content, openStart, openEnd } = this.unplaced;
1128
+ let inner = contentAt(content, openStart);
1129
+ if (!inner.childCount || inner.firstChild.isLeaf)
1130
+ return false;
1131
+ this.unplaced = new Slice(content, openStart + 1, Math.max(openEnd, inner.size + openStart >= content.size - openEnd ? openStart + 1 : 0));
1132
+ return true;
1133
+ }
1134
+ dropNode() {
1135
+ let { content, openStart, openEnd } = this.unplaced;
1136
+ let inner = contentAt(content, openStart);
1137
+ if (inner.childCount <= 1 && openStart > 0) {
1138
+ let openAtEnd = content.size - openStart <= openStart + inner.size;
1139
+ this.unplaced = new Slice(dropFromFragment(content, openStart - 1, 1), openStart - 1, openAtEnd ? openStart - 1 : openEnd);
1140
+ } else {
1141
+ this.unplaced = new Slice(dropFromFragment(content, openStart, 1), openStart, openEnd);
1142
+ }
1143
+ }
1144
+ // Move content from the unplaced slice at `sliceDepth` to the
1145
+ // frontier node at `frontierDepth`. Close that frontier node when
1146
+ // applicable.
1147
+ placeNodes({ sliceDepth, frontierDepth, parent, inject, wrap: wrap2 }) {
1148
+ while (this.depth > frontierDepth)
1149
+ this.closeFrontierNode();
1150
+ if (wrap2)
1151
+ for (let i = 0; i < wrap2.length; i++)
1152
+ this.openFrontierNode(wrap2[i]);
1153
+ let slice = this.unplaced, fragment = parent ? parent.content : slice.content;
1154
+ let openStart = slice.openStart - sliceDepth;
1155
+ let taken = 0, add = [];
1156
+ let { match, type } = this.frontier[frontierDepth];
1157
+ if (inject) {
1158
+ for (let i = 0; i < inject.childCount; i++)
1159
+ add.push(inject.child(i));
1160
+ match = match.matchFragment(inject);
1161
+ }
1162
+ let openEndCount = fragment.size + sliceDepth - (slice.content.size - slice.openEnd);
1163
+ while (taken < fragment.childCount) {
1164
+ let next = fragment.child(taken), matches = match.matchType(next.type);
1165
+ if (!matches)
1166
+ break;
1167
+ taken++;
1168
+ if (taken > 1 || openStart == 0 || next.content.size) {
1169
+ match = matches;
1170
+ add.push(closeNodeStart(next.mark(type.allowedMarks(next.marks)), taken == 1 ? openStart : 0, taken == fragment.childCount ? openEndCount : -1));
1171
+ }
1172
+ }
1173
+ let toEnd = taken == fragment.childCount;
1174
+ if (!toEnd)
1175
+ openEndCount = -1;
1176
+ this.placed = addToFragment(this.placed, frontierDepth, Fragment.from(add));
1177
+ this.frontier[frontierDepth].match = match;
1178
+ if (toEnd && openEndCount < 0 && parent && parent.type == this.frontier[this.depth].type && this.frontier.length > 1)
1179
+ this.closeFrontierNode();
1180
+ for (let i = 0, cur = fragment; i < openEndCount; i++) {
1181
+ let node = cur.lastChild;
1182
+ this.frontier.push({ type: node.type, match: node.contentMatchAt(node.childCount) });
1183
+ cur = node.content;
1184
+ }
1185
+ this.unplaced = !toEnd ? new Slice(dropFromFragment(slice.content, sliceDepth, taken), slice.openStart, slice.openEnd) : sliceDepth == 0 ? Slice.empty : new Slice(dropFromFragment(slice.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1);
1186
+ }
1187
+ mustMoveInline() {
1188
+ if (!this.$to.parent.isTextblock)
1189
+ return -1;
1190
+ let top = this.frontier[this.depth], level;
1191
+ if (!top.type.isTextblock || !contentAfterFits(this.$to, this.$to.depth, top.type, top.match, false) || this.$to.depth == this.depth && (level = this.findCloseLevel(this.$to)) && level.depth == this.depth)
1192
+ return -1;
1193
+ let { depth } = this.$to, after = this.$to.after(depth);
1194
+ while (depth > 1 && after == this.$to.end(--depth))
1195
+ ++after;
1196
+ return after;
1197
+ }
1198
+ findCloseLevel($to) {
1199
+ scan:
1200
+ for (let i = Math.min(this.depth, $to.depth); i >= 0; i--) {
1201
+ let { match, type } = this.frontier[i];
1202
+ let dropInner = i < $to.depth && $to.end(i + 1) == $to.pos + ($to.depth - (i + 1));
1203
+ let fit = contentAfterFits($to, i, type, match, dropInner);
1204
+ if (!fit)
1205
+ continue;
1206
+ for (let d = i - 1; d >= 0; d--) {
1207
+ let { match: match2, type: type2 } = this.frontier[d];
1208
+ let matches = contentAfterFits($to, d, type2, match2, true);
1209
+ if (!matches || matches.childCount)
1210
+ continue scan;
1211
+ }
1212
+ return { depth: i, fit, move: dropInner ? $to.doc.resolve($to.after(i + 1)) : $to };
1213
+ }
1214
+ }
1215
+ close($to) {
1216
+ let close = this.findCloseLevel($to);
1217
+ if (!close)
1218
+ return null;
1219
+ while (this.depth > close.depth)
1220
+ this.closeFrontierNode();
1221
+ if (close.fit.childCount)
1222
+ this.placed = addToFragment(this.placed, close.depth, close.fit);
1223
+ $to = close.move;
1224
+ for (let d = close.depth + 1; d <= $to.depth; d++) {
1225
+ let node = $to.node(d), add = node.type.contentMatch.fillBefore(node.content, true, $to.index(d));
1226
+ this.openFrontierNode(node.type, node.attrs, add);
1227
+ }
1228
+ return $to;
1229
+ }
1230
+ openFrontierNode(type, attrs = null, content) {
1231
+ let top = this.frontier[this.depth];
1232
+ top.match = top.match.matchType(type);
1233
+ this.placed = addToFragment(this.placed, this.depth, Fragment.from(type.create(attrs, content)));
1234
+ this.frontier.push({ type, match: type.contentMatch });
1235
+ }
1236
+ closeFrontierNode() {
1237
+ let open = this.frontier.pop();
1238
+ let add = open.match.fillBefore(Fragment.empty, true);
1239
+ if (add.childCount)
1240
+ this.placed = addToFragment(this.placed, this.frontier.length, add);
1241
+ }
1242
+ };
1243
+ function dropFromFragment(fragment, depth, count) {
1244
+ if (depth == 0)
1245
+ return fragment.cutByIndex(count, fragment.childCount);
1246
+ return fragment.replaceChild(0, fragment.firstChild.copy(dropFromFragment(fragment.firstChild.content, depth - 1, count)));
1247
+ }
1248
+ function addToFragment(fragment, depth, content) {
1249
+ if (depth == 0)
1250
+ return fragment.append(content);
1251
+ return fragment.replaceChild(fragment.childCount - 1, fragment.lastChild.copy(addToFragment(fragment.lastChild.content, depth - 1, content)));
1252
+ }
1253
+ function contentAt(fragment, depth) {
1254
+ for (let i = 0; i < depth; i++)
1255
+ fragment = fragment.firstChild.content;
1256
+ return fragment;
1257
+ }
1258
+ function closeNodeStart(node, openStart, openEnd) {
1259
+ if (openStart <= 0)
1260
+ return node;
1261
+ let frag = node.content;
1262
+ if (openStart > 1)
1263
+ frag = frag.replaceChild(0, closeNodeStart(frag.firstChild, openStart - 1, frag.childCount == 1 ? openEnd - 1 : 0));
1264
+ if (openStart > 0) {
1265
+ frag = node.type.contentMatch.fillBefore(frag).append(frag);
1266
+ if (openEnd <= 0)
1267
+ frag = frag.append(node.type.contentMatch.matchFragment(frag).fillBefore(Fragment.empty, true));
1268
+ }
1269
+ return node.copy(frag);
1270
+ }
1271
+ function contentAfterFits($to, depth, type, match, open) {
1272
+ let node = $to.node(depth), index = open ? $to.indexAfter(depth) : $to.index(depth);
1273
+ if (index == node.childCount && !type.compatibleContent(node.type))
1274
+ return null;
1275
+ let fit = match.fillBefore(node.content, true, index);
1276
+ return fit && !invalidMarks(type, node.content, index) ? fit : null;
1277
+ }
1278
+ function invalidMarks(type, fragment, start) {
1279
+ for (let i = start; i < fragment.childCount; i++)
1280
+ if (!type.allowsMarks(fragment.child(i).marks))
1281
+ return true;
1282
+ return false;
1283
+ }
1284
+ function definesContent(type) {
1285
+ return type.spec.defining || type.spec.definingForContent;
1286
+ }
1287
+ function replaceRange(tr, from, to, slice) {
1288
+ if (!slice.size)
1289
+ return tr.deleteRange(from, to);
1290
+ let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);
1291
+ if (fitsTrivially($from, $to, slice))
1292
+ return tr.step(new ReplaceStep(from, to, slice));
1293
+ let targetDepths = coveredDepths($from, tr.doc.resolve(to));
1294
+ if (targetDepths[targetDepths.length - 1] == 0)
1295
+ targetDepths.pop();
1296
+ let preferredTarget = -($from.depth + 1);
1297
+ targetDepths.unshift(preferredTarget);
1298
+ for (let d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) {
1299
+ let spec = $from.node(d).type.spec;
1300
+ if (spec.defining || spec.definingAsContext || spec.isolating)
1301
+ break;
1302
+ if (targetDepths.indexOf(d) > -1)
1303
+ preferredTarget = d;
1304
+ else if ($from.before(d) == pos)
1305
+ targetDepths.splice(1, 0, -d);
1306
+ }
1307
+ let preferredTargetIndex = targetDepths.indexOf(preferredTarget);
1308
+ let leftNodes = [], preferredDepth = slice.openStart;
1309
+ for (let content = slice.content, i = 0; ; i++) {
1310
+ let node = content.firstChild;
1311
+ leftNodes.push(node);
1312
+ if (i == slice.openStart)
1313
+ break;
1314
+ content = node.content;
1315
+ }
1316
+ for (let d = preferredDepth - 1; d >= 0; d--) {
1317
+ let type = leftNodes[d].type, def = definesContent(type);
1318
+ if (def && $from.node(preferredTargetIndex).type != type)
1319
+ preferredDepth = d;
1320
+ else if (def || !type.isTextblock)
1321
+ break;
1322
+ }
1323
+ for (let j = slice.openStart; j >= 0; j--) {
1324
+ let openDepth = (j + preferredDepth + 1) % (slice.openStart + 1);
1325
+ let insert = leftNodes[openDepth];
1326
+ if (!insert)
1327
+ continue;
1328
+ for (let i = 0; i < targetDepths.length; i++) {
1329
+ let targetDepth = targetDepths[(i + preferredTargetIndex) % targetDepths.length], expand = true;
1330
+ if (targetDepth < 0) {
1331
+ expand = false;
1332
+ targetDepth = -targetDepth;
1333
+ }
1334
+ let parent = $from.node(targetDepth - 1), index = $from.index(targetDepth - 1);
1335
+ if (parent.canReplaceWith(index, index, insert.type, insert.marks))
1336
+ return tr.replace($from.before(targetDepth), expand ? $to.after(targetDepth) : to, new Slice(closeFragment(slice.content, 0, slice.openStart, openDepth), openDepth, slice.openEnd));
1337
+ }
1338
+ }
1339
+ let startSteps = tr.steps.length;
1340
+ for (let i = targetDepths.length - 1; i >= 0; i--) {
1341
+ tr.replace(from, to, slice);
1342
+ if (tr.steps.length > startSteps)
1343
+ break;
1344
+ let depth = targetDepths[i];
1345
+ if (depth < 0)
1346
+ continue;
1347
+ from = $from.before(depth);
1348
+ to = $to.after(depth);
1349
+ }
1350
+ }
1351
+ function closeFragment(fragment, depth, oldOpen, newOpen, parent) {
1352
+ if (depth < oldOpen) {
1353
+ let first = fragment.firstChild;
1354
+ fragment = fragment.replaceChild(0, first.copy(closeFragment(first.content, depth + 1, oldOpen, newOpen, first)));
1355
+ }
1356
+ if (depth > newOpen) {
1357
+ let match = parent.contentMatchAt(0);
1358
+ let start = match.fillBefore(fragment).append(fragment);
1359
+ fragment = start.append(match.matchFragment(start).fillBefore(Fragment.empty, true));
1360
+ }
1361
+ return fragment;
1362
+ }
1363
+ function replaceRangeWith(tr, from, to, node) {
1364
+ if (!node.isInline && from == to && tr.doc.resolve(from).parent.content.size) {
1365
+ let point = insertPoint(tr.doc, from, node.type);
1366
+ if (point != null)
1367
+ from = to = point;
1368
+ }
1369
+ tr.replaceRange(from, to, new Slice(Fragment.from(node), 0, 0));
1370
+ }
1371
+ function deleteRange(tr, from, to) {
1372
+ let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);
1373
+ let covered = coveredDepths($from, $to);
1374
+ for (let i = 0; i < covered.length; i++) {
1375
+ let depth = covered[i], last = i == covered.length - 1;
1376
+ if (last && depth == 0 || $from.node(depth).type.contentMatch.validEnd)
1377
+ return tr.delete($from.start(depth), $to.end(depth));
1378
+ if (depth > 0 && (last || $from.node(depth - 1).canReplace($from.index(depth - 1), $to.indexAfter(depth - 1))))
1379
+ return tr.delete($from.before(depth), $to.after(depth));
1380
+ }
1381
+ for (let d = 1; d <= $from.depth && d <= $to.depth; d++) {
1382
+ if (from - $from.start(d) == $from.depth - d && to > $from.end(d) && $to.end(d) - to != $to.depth - d)
1383
+ return tr.delete($from.before(d), to);
1384
+ }
1385
+ tr.delete(from, to);
1386
+ }
1387
+ function coveredDepths($from, $to) {
1388
+ let result = [], minDepth = Math.min($from.depth, $to.depth);
1389
+ for (let d = minDepth; d >= 0; d--) {
1390
+ let start = $from.start(d);
1391
+ if (start < $from.pos - ($from.depth - d) || $to.end(d) > $to.pos + ($to.depth - d) || $from.node(d).type.spec.isolating || $to.node(d).type.spec.isolating)
1392
+ break;
1393
+ if (start == $to.start(d) || d == $from.depth && d == $to.depth && $from.parent.inlineContent && $to.parent.inlineContent && d && $to.start(d - 1) == start - 1)
1394
+ result.push(d);
1395
+ }
1396
+ return result;
1397
+ }
1398
+ var AttrStep = class _AttrStep extends Step {
1399
+ /**
1400
+ Construct an attribute step.
1401
+ */
1402
+ constructor(pos, attr, value) {
1403
+ super();
1404
+ this.pos = pos;
1405
+ this.attr = attr;
1406
+ this.value = value;
1407
+ }
1408
+ apply(doc) {
1409
+ let node = doc.nodeAt(this.pos);
1410
+ if (!node)
1411
+ return StepResult.fail("No node at attribute step's position");
1412
+ let attrs = /* @__PURE__ */ Object.create(null);
1413
+ for (let name in node.attrs)
1414
+ attrs[name] = node.attrs[name];
1415
+ attrs[this.attr] = this.value;
1416
+ let updated = node.type.create(attrs, null, node.marks);
1417
+ return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
1418
+ }
1419
+ getMap() {
1420
+ return StepMap.empty;
1421
+ }
1422
+ invert(doc) {
1423
+ return new _AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);
1424
+ }
1425
+ map(mapping) {
1426
+ let pos = mapping.mapResult(this.pos, 1);
1427
+ return pos.deletedAfter ? null : new _AttrStep(pos.pos, this.attr, this.value);
1428
+ }
1429
+ toJSON() {
1430
+ return { stepType: "attr", pos: this.pos, attr: this.attr, value: this.value };
1431
+ }
1432
+ static fromJSON(schema, json) {
1433
+ if (typeof json.pos != "number" || typeof json.attr != "string")
1434
+ throw new RangeError("Invalid input for AttrStep.fromJSON");
1435
+ return new _AttrStep(json.pos, json.attr, json.value);
1436
+ }
1437
+ };
1438
+ Step.jsonID("attr", AttrStep);
1439
+ var TransformError = class extends Error {
1440
+ };
1441
+ TransformError = function TransformError2(message) {
1442
+ let err = Error.call(this, message);
1443
+ err.__proto__ = TransformError2.prototype;
1444
+ return err;
1445
+ };
1446
+ TransformError.prototype = Object.create(Error.prototype);
1447
+ TransformError.prototype.constructor = TransformError;
1448
+ TransformError.prototype.name = "TransformError";
1449
+ var Transform = class {
1450
+ /**
1451
+ Create a transform that starts with the given document.
1452
+ */
1453
+ constructor(doc) {
1454
+ this.doc = doc;
1455
+ this.steps = [];
1456
+ this.docs = [];
1457
+ this.mapping = new Mapping();
1458
+ }
1459
+ /**
1460
+ The starting document.
1461
+ */
1462
+ get before() {
1463
+ return this.docs.length ? this.docs[0] : this.doc;
1464
+ }
1465
+ /**
1466
+ Apply a new step in this transform, saving the result. Throws an
1467
+ error when the step fails.
1468
+ */
1469
+ step(step) {
1470
+ let result = this.maybeStep(step);
1471
+ if (result.failed)
1472
+ throw new TransformError(result.failed);
1473
+ return this;
1474
+ }
1475
+ /**
1476
+ Try to apply a step in this transformation, ignoring it if it
1477
+ fails. Returns the step result.
1478
+ */
1479
+ maybeStep(step) {
1480
+ let result = step.apply(this.doc);
1481
+ if (!result.failed)
1482
+ this.addStep(step, result.doc);
1483
+ return result;
1484
+ }
1485
+ /**
1486
+ True when the document has been changed (when there are any
1487
+ steps).
1488
+ */
1489
+ get docChanged() {
1490
+ return this.steps.length > 0;
1491
+ }
1492
+ /**
1493
+ @internal
1494
+ */
1495
+ addStep(step, doc) {
1496
+ this.docs.push(this.doc);
1497
+ this.steps.push(step);
1498
+ this.mapping.appendMap(step.getMap());
1499
+ this.doc = doc;
1500
+ }
1501
+ /**
1502
+ Replace the part of the document between `from` and `to` with the
1503
+ given `slice`.
1504
+ */
1505
+ replace(from, to = from, slice = Slice.empty) {
1506
+ let step = replaceStep(this.doc, from, to, slice);
1507
+ if (step)
1508
+ this.step(step);
1509
+ return this;
1510
+ }
1511
+ /**
1512
+ Replace the given range with the given content, which may be a
1513
+ fragment, node, or array of nodes.
1514
+ */
1515
+ replaceWith(from, to, content) {
1516
+ return this.replace(from, to, new Slice(Fragment.from(content), 0, 0));
1517
+ }
1518
+ /**
1519
+ Delete the content between the given positions.
1520
+ */
1521
+ delete(from, to) {
1522
+ return this.replace(from, to, Slice.empty);
1523
+ }
1524
+ /**
1525
+ Insert the given content at the given position.
1526
+ */
1527
+ insert(pos, content) {
1528
+ return this.replaceWith(pos, pos, content);
1529
+ }
1530
+ /**
1531
+ Replace a range of the document with a given slice, using
1532
+ `from`, `to`, and the slice's
1533
+ [`openStart`](https://prosemirror.net/docs/ref/#model.Slice.openStart) property as hints, rather
1534
+ than fixed start and end points. This method may grow the
1535
+ replaced area or close open nodes in the slice in order to get a
1536
+ fit that is more in line with WYSIWYG expectations, by dropping
1537
+ fully covered parent nodes of the replaced region when they are
1538
+ marked [non-defining as
1539
+ context](https://prosemirror.net/docs/ref/#model.NodeSpec.definingAsContext), or including an
1540
+ open parent node from the slice that _is_ marked as [defining
1541
+ its content](https://prosemirror.net/docs/ref/#model.NodeSpec.definingForContent).
1542
+
1543
+ This is the method, for example, to handle paste. The similar
1544
+ [`replace`](https://prosemirror.net/docs/ref/#transform.Transform.replace) method is a more
1545
+ primitive tool which will _not_ move the start and end of its given
1546
+ range, and is useful in situations where you need more precise
1547
+ control over what happens.
1548
+ */
1549
+ replaceRange(from, to, slice) {
1550
+ replaceRange(this, from, to, slice);
1551
+ return this;
1552
+ }
1553
+ /**
1554
+ Replace the given range with a node, but use `from` and `to` as
1555
+ hints, rather than precise positions. When from and to are the same
1556
+ and are at the start or end of a parent node in which the given
1557
+ node doesn't fit, this method may _move_ them out towards a parent
1558
+ that does allow the given node to be placed. When the given range
1559
+ completely covers a parent node, this method may completely replace
1560
+ that parent node.
1561
+ */
1562
+ replaceRangeWith(from, to, node) {
1563
+ replaceRangeWith(this, from, to, node);
1564
+ return this;
1565
+ }
1566
+ /**
1567
+ Delete the given range, expanding it to cover fully covered
1568
+ parent nodes until a valid replace is found.
1569
+ */
1570
+ deleteRange(from, to) {
1571
+ deleteRange(this, from, to);
1572
+ return this;
1573
+ }
1574
+ /**
1575
+ Split the content in the given range off from its parent, if there
1576
+ is sibling content before or after it, and move it up the tree to
1577
+ the depth specified by `target`. You'll probably want to use
1578
+ [`liftTarget`](https://prosemirror.net/docs/ref/#transform.liftTarget) to compute `target`, to make
1579
+ sure the lift is valid.
1580
+ */
1581
+ lift(range, target) {
1582
+ lift(this, range, target);
1583
+ return this;
1584
+ }
1585
+ /**
1586
+ Join the blocks around the given position. If depth is 2, their
1587
+ last and first siblings are also joined, and so on.
1588
+ */
1589
+ join(pos, depth = 1) {
1590
+ join(this, pos, depth);
1591
+ return this;
1592
+ }
1593
+ /**
1594
+ Wrap the given [range](https://prosemirror.net/docs/ref/#model.NodeRange) in the given set of wrappers.
1595
+ The wrappers are assumed to be valid in this position, and should
1596
+ probably be computed with [`findWrapping`](https://prosemirror.net/docs/ref/#transform.findWrapping).
1597
+ */
1598
+ wrap(range, wrappers) {
1599
+ wrap(this, range, wrappers);
1600
+ return this;
1601
+ }
1602
+ /**
1603
+ Set the type of all textblocks (partly) between `from` and `to` to
1604
+ the given node type with the given attributes.
1605
+ */
1606
+ setBlockType(from, to = from, type, attrs = null) {
1607
+ setBlockType(this, from, to, type, attrs);
1608
+ return this;
1609
+ }
1610
+ /**
1611
+ Change the type, attributes, and/or marks of the node at `pos`.
1612
+ When `type` isn't given, the existing node type is preserved,
1613
+ */
1614
+ setNodeMarkup(pos, type, attrs = null, marks) {
1615
+ setNodeMarkup(this, pos, type, attrs, marks);
1616
+ return this;
1617
+ }
1618
+ /**
1619
+ Set a single attribute on a given node to a new value.
1620
+ */
1621
+ setNodeAttribute(pos, attr, value) {
1622
+ this.step(new AttrStep(pos, attr, value));
1623
+ return this;
1624
+ }
1625
+ /**
1626
+ Add a mark to the node at position `pos`.
1627
+ */
1628
+ addNodeMark(pos, mark) {
1629
+ this.step(new AddNodeMarkStep(pos, mark));
1630
+ return this;
1631
+ }
1632
+ /**
1633
+ Remove a mark (or a mark of the given type) from the node at
1634
+ position `pos`.
1635
+ */
1636
+ removeNodeMark(pos, mark) {
1637
+ if (!(mark instanceof Mark)) {
1638
+ let node = this.doc.nodeAt(pos);
1639
+ if (!node)
1640
+ throw new RangeError("No node at position " + pos);
1641
+ mark = mark.isInSet(node.marks);
1642
+ if (!mark)
1643
+ return this;
1644
+ }
1645
+ this.step(new RemoveNodeMarkStep(pos, mark));
1646
+ return this;
1647
+ }
1648
+ /**
1649
+ Split the node at the given position, and optionally, if `depth` is
1650
+ greater than one, any number of nodes above that. By default, the
1651
+ parts split off will inherit the node type of the original node.
1652
+ This can be changed by passing an array of types and attributes to
1653
+ use after the split.
1654
+ */
1655
+ split(pos, depth = 1, typesAfter) {
1656
+ split(this, pos, depth, typesAfter);
1657
+ return this;
1658
+ }
1659
+ /**
1660
+ Add the given mark to the inline content between `from` and `to`.
1661
+ */
1662
+ addMark(from, to, mark) {
1663
+ addMark(this, from, to, mark);
1664
+ return this;
1665
+ }
1666
+ /**
1667
+ Remove marks from inline nodes between `from` and `to`. When
1668
+ `mark` is a single mark, remove precisely that mark. When it is
1669
+ a mark type, remove all marks of that type. When it is null,
1670
+ remove all marks of any type.
1671
+ */
1672
+ removeMark(from, to, mark) {
1673
+ removeMark(this, from, to, mark);
1674
+ return this;
1675
+ }
1676
+ /**
1677
+ Removes all marks and nodes from the content of the node at
1678
+ `pos` that don't match the given new parent node type. Accepts
1679
+ an optional starting [content match](https://prosemirror.net/docs/ref/#model.ContentMatch) as
1680
+ third argument.
1681
+ */
1682
+ clearIncompatible(pos, parentType, match) {
1683
+ clearIncompatible(this, pos, parentType, match);
1684
+ return this;
1685
+ }
1686
+ };
1687
+
1688
+ export {
1689
+ MapResult,
1690
+ StepMap,
1691
+ Mapping,
1692
+ Step,
1693
+ StepResult,
1694
+ AddMarkStep,
1695
+ RemoveMarkStep,
1696
+ AddNodeMarkStep,
1697
+ RemoveNodeMarkStep,
1698
+ ReplaceStep,
1699
+ ReplaceAroundStep,
1700
+ liftTarget,
1701
+ findWrapping,
1702
+ canSplit,
1703
+ canJoin,
1704
+ joinPoint,
1705
+ insertPoint,
1706
+ dropPoint,
1707
+ replaceStep,
1708
+ AttrStep,
1709
+ TransformError,
1710
+ Transform
1711
+ };