@bigbinary/neeto-editor-frontend 2.0.10 → 2.1.0-beta1

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 (103) hide show
  1. package/dist/.ready +1 -1
  2. package/dist/Editor.js +7 -6
  3. package/dist/Editor.js.map +1 -1
  4. package/dist/EditorContent.js +4 -3
  5. package/dist/EditorContent.js.map +1 -1
  6. package/dist/FormikEditor.js +7 -6
  7. package/dist/FormikEditor.js.map +1 -1
  8. package/dist/Menu.js +5 -4
  9. package/dist/Menu.js.map +1 -1
  10. package/dist/{chunk-DxmX0drN.js → chunk-7ioLE0kx.js} +2 -2
  11. package/dist/{chunk-DxmX0drN.js.map → chunk-7ioLE0kx.js.map} +1 -1
  12. package/dist/{chunk-MLCxAQf7.js → chunk-BNyLNMnb.js} +3 -3
  13. package/dist/{chunk-MLCxAQf7.js.map → chunk-BNyLNMnb.js.map} +1 -1
  14. package/dist/{cjs/chunk-Crp27WMe.cjs.js → chunk-BpMZjml2.js} +147 -3234
  15. package/dist/chunk-BpMZjml2.js.map +1 -0
  16. package/dist/{chunk-C_P2M3zF.js → chunk-Br5h7rjn.js} +7 -3
  17. package/dist/chunk-Br5h7rjn.js.map +1 -0
  18. package/dist/{chunk-Di3ipdfT.js → chunk-CRUXOawK.js} +3 -2
  19. package/dist/{chunk-Di3ipdfT.js.map → chunk-CRUXOawK.js.map} +1 -1
  20. package/dist/chunk-DN9pYQV5.js +3210 -0
  21. package/dist/chunk-DN9pYQV5.js.map +1 -0
  22. package/dist/{chunk-DbtYYDYF.js → chunk-DYRpf9PJ.js} +3 -3
  23. package/dist/{chunk-DbtYYDYF.js.map → chunk-DYRpf9PJ.js.map} +1 -1
  24. package/dist/{chunk-CTLN7kYv.js → chunk-DfH1lF5p.js} +3 -17
  25. package/dist/chunk-DfH1lF5p.js.map +1 -0
  26. package/dist/{chunk-Byc0nnPW.js → chunk-YhV82e9I.js} +8 -4
  27. package/dist/chunk-YhV82e9I.js.map +1 -0
  28. package/dist/{chunk-BAjN56q8.js → chunk-lEnpEBRB.js} +5 -4
  29. package/dist/{chunk-BAjN56q8.js.map → chunk-lEnpEBRB.js.map} +1 -1
  30. package/dist/{chunk-CrQm8ki8.js → chunk-sn8HEeT6.js} +4 -3
  31. package/dist/{chunk-CrQm8ki8.js.map → chunk-sn8HEeT6.js.map} +1 -1
  32. package/dist/cjs/Editor.cjs.js +8 -7
  33. package/dist/cjs/Editor.cjs.js.map +1 -1
  34. package/dist/cjs/EditorContent.cjs.js +4 -3
  35. package/dist/cjs/EditorContent.cjs.js.map +1 -1
  36. package/dist/cjs/FormikEditor.cjs.js +7 -6
  37. package/dist/cjs/FormikEditor.cjs.js.map +1 -1
  38. package/dist/cjs/Menu.cjs.js +5 -4
  39. package/dist/cjs/Menu.cjs.js.map +1 -1
  40. package/dist/cjs/{chunk-CwtiYxqr.cjs.js → chunk-78VpxO0R.cjs.js} +4 -3
  41. package/dist/cjs/{chunk-CwtiYxqr.cjs.js.map → chunk-78VpxO0R.cjs.js.map} +1 -1
  42. package/dist/{chunk-DgZGzqPs.js → cjs/chunk-BPJBeVDI.cjs.js} +166 -3206
  43. package/dist/cjs/chunk-BPJBeVDI.cjs.js.map +1 -0
  44. package/dist/cjs/{chunk-Ty2BpOZ5.cjs.js → chunk-CBswWnmM.cjs.js} +10 -6
  45. package/dist/cjs/chunk-CBswWnmM.cjs.js.map +1 -0
  46. package/dist/cjs/{chunk-Bsk_FDUA.cjs.js → chunk-CQLQEN5P.cjs.js} +5 -22
  47. package/dist/cjs/chunk-CQLQEN5P.cjs.js.map +1 -0
  48. package/dist/cjs/{chunk-CohcWDmm.cjs.js → chunk-CwY6UgZq.cjs.js} +78 -77
  49. package/dist/cjs/{chunk-CohcWDmm.cjs.js.map → chunk-CwY6UgZq.cjs.js.map} +1 -1
  50. package/dist/cjs/chunk-DRnP2LQe.cjs.js +3231 -0
  51. package/dist/cjs/chunk-DRnP2LQe.cjs.js.map +1 -0
  52. package/dist/cjs/{chunk-D9InNR1-.cjs.js → chunk-QnVNXaqt.cjs.js} +11 -7
  53. package/dist/cjs/chunk-QnVNXaqt.cjs.js.map +1 -0
  54. package/dist/cjs/{chunk-D53HfRZd.cjs.js → chunk-V1V-Gqfy.cjs.js} +3 -3
  55. package/dist/cjs/{chunk-D53HfRZd.cjs.js.map → chunk-V1V-Gqfy.cjs.js.map} +1 -1
  56. package/dist/cjs/{chunk-CkdAygKd.cjs.js → chunk-bfmPXyQJ.cjs.js} +3 -3
  57. package/dist/cjs/{chunk-CkdAygKd.cjs.js.map → chunk-bfmPXyQJ.cjs.js.map} +1 -1
  58. package/dist/cjs/{chunk-BwE6pvh2.cjs.js → chunk-bxP1kilM.cjs.js} +2 -2
  59. package/dist/cjs/{chunk-BwE6pvh2.cjs.js.map → chunk-bxP1kilM.cjs.js.map} +1 -1
  60. package/dist/cjs/{chunk-BAEoAF1o.cjs.js → chunk-j4T5BDua.cjs.js} +23 -22
  61. package/dist/cjs/{chunk-BAEoAF1o.cjs.js.map → chunk-j4T5BDua.cjs.js.map} +1 -1
  62. package/dist/cjs/index.cjs.js +9 -8
  63. package/dist/cjs/index.cjs.js.map +1 -1
  64. package/dist/cjs/utils.cjs.js +7 -6
  65. package/dist/cjs/utils.cjs.js.map +1 -1
  66. package/dist/cjs/v2/Editor.cjs.js +7 -6
  67. package/dist/cjs/v2/Editor.cjs.js.map +1 -1
  68. package/dist/cjs/v2/EditorContent.cjs.js +4 -3
  69. package/dist/cjs/v2/EditorContent.cjs.js.map +1 -1
  70. package/dist/cjs/v2/FormikEditor.cjs.js +6 -5
  71. package/dist/cjs/v2/FormikEditor.cjs.js.map +1 -1
  72. package/dist/cjs/v2/Menu.cjs.js +4 -3
  73. package/dist/cjs/v2/Menu.cjs.js.map +1 -1
  74. package/dist/cjs/v2/index.cjs.js +8 -7
  75. package/dist/cjs/v2/index.cjs.js.map +1 -1
  76. package/dist/cjs/v2/utils.cjs.js +7 -6
  77. package/dist/cjs/v2/utils.cjs.js.map +1 -1
  78. package/dist/editor-stats.html +2 -2
  79. package/dist/index.js +9 -8
  80. package/dist/index.js.map +1 -1
  81. package/dist/utils.js +7 -6
  82. package/dist/utils.js.map +1 -1
  83. package/dist/v2/Editor.js +6 -5
  84. package/dist/v2/Editor.js.map +1 -1
  85. package/dist/v2/EditorContent.js +4 -3
  86. package/dist/v2/EditorContent.js.map +1 -1
  87. package/dist/v2/FormikEditor.js +6 -5
  88. package/dist/v2/FormikEditor.js.map +1 -1
  89. package/dist/v2/Menu.js +4 -3
  90. package/dist/v2/Menu.js.map +1 -1
  91. package/dist/v2/index.js +8 -7
  92. package/dist/v2/index.js.map +1 -1
  93. package/dist/v2/utils.js +7 -6
  94. package/dist/v2/utils.js.map +1 -1
  95. package/package.json +7 -5
  96. package/dist/chunk-Byc0nnPW.js.map +0 -1
  97. package/dist/chunk-CTLN7kYv.js.map +0 -1
  98. package/dist/chunk-C_P2M3zF.js.map +0 -1
  99. package/dist/chunk-DgZGzqPs.js.map +0 -1
  100. package/dist/cjs/chunk-Bsk_FDUA.cjs.js.map +0 -1
  101. package/dist/cjs/chunk-Crp27WMe.cjs.js.map +0 -1
  102. package/dist/cjs/chunk-D9InNR1-.cjs.js.map +0 -1
  103. package/dist/cjs/chunk-Ty2BpOZ5.cjs.js.map +0 -1
@@ -0,0 +1,3210 @@
1
+ import { S as Slice, R as ReplaceError, F as Fragment, M as Mark, a as MarkType, N as Node } from './chunk-BpMZjml2.js';
2
+
3
+ // Recovery values encode a range index and an offset. They are
4
+ // represented as numbers, because tons of them will be created when
5
+ // mapping, for example, a large number of decorations. The number's
6
+ // lower 16 bits provide the index, the remaining bits the offset.
7
+ //
8
+ // Note: We intentionally don't use bit shift operators to en- and
9
+ // decode these, since those clip to 32 bits, which we might in rare
10
+ // cases want to overflow. A 64-bit float can represent 48-bit
11
+ // integers precisely.
12
+ const lower16 = 0xffff;
13
+ const factor16 = Math.pow(2, 16);
14
+ function makeRecover(index, offset) { return index + offset * factor16; }
15
+ function recoverIndex(value) { return value & lower16; }
16
+ function recoverOffset(value) { return (value - (value & lower16)) / factor16; }
17
+ const DEL_BEFORE = 1, DEL_AFTER = 2, DEL_ACROSS = 4, DEL_SIDE = 8;
18
+ /**
19
+ An object representing a mapped position with extra
20
+ information.
21
+ */
22
+ class MapResult {
23
+ /**
24
+ @internal
25
+ */
26
+ constructor(
27
+ /**
28
+ The mapped version of the position.
29
+ */
30
+ pos,
31
+ /**
32
+ @internal
33
+ */
34
+ delInfo,
35
+ /**
36
+ @internal
37
+ */
38
+ recover) {
39
+ this.pos = pos;
40
+ this.delInfo = delInfo;
41
+ this.recover = recover;
42
+ }
43
+ /**
44
+ Tells you whether the position was deleted, that is, whether the
45
+ step removed the token on the side queried (via the `assoc`)
46
+ argument from the document.
47
+ */
48
+ get deleted() { return (this.delInfo & DEL_SIDE) > 0; }
49
+ /**
50
+ Tells you whether the token before the mapped position was deleted.
51
+ */
52
+ get deletedBefore() { return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0; }
53
+ /**
54
+ True when the token after the mapped position was deleted.
55
+ */
56
+ get deletedAfter() { return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0; }
57
+ /**
58
+ Tells whether any of the steps mapped through deletes across the
59
+ position (including both the token before and after the
60
+ position).
61
+ */
62
+ get deletedAcross() { return (this.delInfo & DEL_ACROSS) > 0; }
63
+ }
64
+ /**
65
+ A map describing the deletions and insertions made by a step, which
66
+ can be used to find the correspondence between positions in the
67
+ pre-step version of a document and the same position in the
68
+ post-step version.
69
+ */
70
+ class StepMap {
71
+ /**
72
+ Create a position map. The modifications to the document are
73
+ represented as an array of numbers, in which each group of three
74
+ represents a modified chunk as `[start, oldSize, newSize]`.
75
+ */
76
+ constructor(
77
+ /**
78
+ @internal
79
+ */
80
+ ranges,
81
+ /**
82
+ @internal
83
+ */
84
+ inverted = false) {
85
+ this.ranges = ranges;
86
+ this.inverted = inverted;
87
+ if (!ranges.length && StepMap.empty)
88
+ return StepMap.empty;
89
+ }
90
+ /**
91
+ @internal
92
+ */
93
+ recover(value) {
94
+ let diff = 0, index = recoverIndex(value);
95
+ if (!this.inverted)
96
+ for (let i = 0; i < index; i++)
97
+ diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1];
98
+ return this.ranges[index * 3] + diff + recoverOffset(value);
99
+ }
100
+ mapResult(pos, assoc = 1) { return this._map(pos, assoc, false); }
101
+ map(pos, assoc = 1) { return this._map(pos, assoc, true); }
102
+ /**
103
+ @internal
104
+ */
105
+ _map(pos, assoc, simple) {
106
+ let diff = 0, oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
107
+ for (let i = 0; i < this.ranges.length; i += 3) {
108
+ let start = this.ranges[i] - (this.inverted ? diff : 0);
109
+ if (start > pos)
110
+ break;
111
+ let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex], end = start + oldSize;
112
+ if (pos <= end) {
113
+ let side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc;
114
+ let result = start + diff + (side < 0 ? 0 : newSize);
115
+ if (simple)
116
+ return result;
117
+ let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);
118
+ let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;
119
+ if (assoc < 0 ? pos != start : pos != end)
120
+ del |= DEL_SIDE;
121
+ return new MapResult(result, del, recover);
122
+ }
123
+ diff += newSize - oldSize;
124
+ }
125
+ return simple ? pos + diff : new MapResult(pos + diff, 0, null);
126
+ }
127
+ /**
128
+ @internal
129
+ */
130
+ touches(pos, recover) {
131
+ let diff = 0, index = recoverIndex(recover);
132
+ let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
133
+ for (let i = 0; i < this.ranges.length; i += 3) {
134
+ let start = this.ranges[i] - (this.inverted ? diff : 0);
135
+ if (start > pos)
136
+ break;
137
+ let oldSize = this.ranges[i + oldIndex], end = start + oldSize;
138
+ if (pos <= end && i == index * 3)
139
+ return true;
140
+ diff += this.ranges[i + newIndex] - oldSize;
141
+ }
142
+ return false;
143
+ }
144
+ /**
145
+ Calls the given function on each of the changed ranges included in
146
+ this map.
147
+ */
148
+ forEach(f) {
149
+ let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
150
+ for (let i = 0, diff = 0; i < this.ranges.length; i += 3) {
151
+ let start = this.ranges[i], oldStart = start - (this.inverted ? diff : 0), newStart = start + (this.inverted ? 0 : diff);
152
+ let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex];
153
+ f(oldStart, oldStart + oldSize, newStart, newStart + newSize);
154
+ diff += newSize - oldSize;
155
+ }
156
+ }
157
+ /**
158
+ Create an inverted version of this map. The result can be used to
159
+ map positions in the post-step document to the pre-step document.
160
+ */
161
+ invert() {
162
+ return new StepMap(this.ranges, !this.inverted);
163
+ }
164
+ /**
165
+ @internal
166
+ */
167
+ toString() {
168
+ return (this.inverted ? "-" : "") + JSON.stringify(this.ranges);
169
+ }
170
+ /**
171
+ Create a map that moves all positions by offset `n` (which may be
172
+ negative). This can be useful when applying steps meant for a
173
+ sub-document to a larger document, or vice-versa.
174
+ */
175
+ static offset(n) {
176
+ return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]);
177
+ }
178
+ }
179
+ /**
180
+ A StepMap that contains no changed ranges.
181
+ */
182
+ StepMap.empty = new StepMap([]);
183
+ /**
184
+ A mapping represents a pipeline of zero or more [step
185
+ maps](https://prosemirror.net/docs/ref/#transform.StepMap). It has special provisions for losslessly
186
+ handling mapping positions through a series of steps in which some
187
+ steps are inverted versions of earlier steps. (This comes up when
188
+ ‘[rebasing](https://prosemirror.net/docs/guide/#transform.rebasing)’ steps for
189
+ collaboration or history management.)
190
+ */
191
+ class Mapping {
192
+ /**
193
+ Create a new mapping with the given position maps.
194
+ */
195
+ constructor(maps,
196
+ /**
197
+ @internal
198
+ */
199
+ mirror,
200
+ /**
201
+ The starting position in the `maps` array, used when `map` or
202
+ `mapResult` is called.
203
+ */
204
+ from = 0,
205
+ /**
206
+ The end position in the `maps` array.
207
+ */
208
+ to = maps ? maps.length : 0) {
209
+ this.mirror = mirror;
210
+ this.from = from;
211
+ this.to = to;
212
+ this._maps = maps || [];
213
+ this.ownData = !(maps || mirror);
214
+ }
215
+ /**
216
+ The step maps in this mapping.
217
+ */
218
+ get maps() { return this._maps; }
219
+ /**
220
+ Create a mapping that maps only through a part of this one.
221
+ */
222
+ slice(from = 0, to = this.maps.length) {
223
+ return new Mapping(this._maps, this.mirror, from, to);
224
+ }
225
+ /**
226
+ Add a step map to the end of this mapping. If `mirrors` is
227
+ given, it should be the index of the step map that is the mirror
228
+ image of this one.
229
+ */
230
+ appendMap(map, mirrors) {
231
+ if (!this.ownData) {
232
+ this._maps = this._maps.slice();
233
+ this.mirror = this.mirror && this.mirror.slice();
234
+ this.ownData = true;
235
+ }
236
+ this.to = this._maps.push(map);
237
+ if (mirrors != null)
238
+ this.setMirror(this._maps.length - 1, mirrors);
239
+ }
240
+ /**
241
+ Add all the step maps in a given mapping to this one (preserving
242
+ mirroring information).
243
+ */
244
+ appendMapping(mapping) {
245
+ for (let i = 0, startSize = this._maps.length; i < mapping._maps.length; i++) {
246
+ let mirr = mapping.getMirror(i);
247
+ this.appendMap(mapping._maps[i], mirr != null && mirr < i ? startSize + mirr : undefined);
248
+ }
249
+ }
250
+ /**
251
+ Finds the offset of the step map that mirrors the map at the
252
+ given offset, in this mapping (as per the second argument to
253
+ `appendMap`).
254
+ */
255
+ getMirror(n) {
256
+ if (this.mirror)
257
+ for (let i = 0; i < this.mirror.length; i++)
258
+ if (this.mirror[i] == n)
259
+ return this.mirror[i + (i % 2 ? -1 : 1)];
260
+ }
261
+ /**
262
+ @internal
263
+ */
264
+ setMirror(n, m) {
265
+ if (!this.mirror)
266
+ this.mirror = [];
267
+ this.mirror.push(n, m);
268
+ }
269
+ /**
270
+ Append the inverse of the given mapping to this one.
271
+ */
272
+ appendMappingInverted(mapping) {
273
+ for (let i = mapping.maps.length - 1, totalSize = this._maps.length + mapping._maps.length; i >= 0; i--) {
274
+ let mirr = mapping.getMirror(i);
275
+ this.appendMap(mapping._maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : undefined);
276
+ }
277
+ }
278
+ /**
279
+ Create an inverted version of this mapping.
280
+ */
281
+ invert() {
282
+ let inverse = new Mapping;
283
+ inverse.appendMappingInverted(this);
284
+ return inverse;
285
+ }
286
+ /**
287
+ Map a position through this mapping.
288
+ */
289
+ map(pos, assoc = 1) {
290
+ if (this.mirror)
291
+ return this._map(pos, assoc, true);
292
+ for (let i = this.from; i < this.to; i++)
293
+ pos = this._maps[i].map(pos, assoc);
294
+ return pos;
295
+ }
296
+ /**
297
+ Map a position through this mapping, returning a mapping
298
+ result.
299
+ */
300
+ mapResult(pos, assoc = 1) { return this._map(pos, assoc, false); }
301
+ /**
302
+ @internal
303
+ */
304
+ _map(pos, assoc, simple) {
305
+ let delInfo = 0;
306
+ for (let i = this.from; i < this.to; i++) {
307
+ let map = this._maps[i], result = map.mapResult(pos, assoc);
308
+ if (result.recover != null) {
309
+ let corr = this.getMirror(i);
310
+ if (corr != null && corr > i && corr < this.to) {
311
+ i = corr;
312
+ pos = this._maps[corr].recover(result.recover);
313
+ continue;
314
+ }
315
+ }
316
+ delInfo |= result.delInfo;
317
+ pos = result.pos;
318
+ }
319
+ return simple ? pos : new MapResult(pos, delInfo, null);
320
+ }
321
+ }
322
+
323
+ const stepsByID = Object.create(null);
324
+ /**
325
+ A step object represents an atomic change. It generally applies
326
+ only to the document it was created for, since the positions
327
+ stored in it will only make sense for that document.
328
+
329
+ New steps are defined by creating classes that extend `Step`,
330
+ overriding the `apply`, `invert`, `map`, `getMap` and `fromJSON`
331
+ methods, and registering your class with a unique
332
+ JSON-serialization identifier using
333
+ [`Step.jsonID`](https://prosemirror.net/docs/ref/#transform.Step^jsonID).
334
+ */
335
+ class Step {
336
+ /**
337
+ Get the step map that represents the changes made by this step,
338
+ and which can be used to transform between positions in the old
339
+ and the new document.
340
+ */
341
+ getMap() { return StepMap.empty; }
342
+ /**
343
+ Try to merge this step with another one, to be applied directly
344
+ after it. Returns the merged step when possible, null if the
345
+ steps can't be merged.
346
+ */
347
+ merge(other) { return null; }
348
+ /**
349
+ Deserialize a step from its JSON representation. Will call
350
+ through to the step class' own implementation of this method.
351
+ */
352
+ static fromJSON(schema, json) {
353
+ if (!json || !json.stepType)
354
+ throw new RangeError("Invalid input for Step.fromJSON");
355
+ let type = stepsByID[json.stepType];
356
+ if (!type)
357
+ throw new RangeError(`No step type ${json.stepType} defined`);
358
+ return type.fromJSON(schema, json);
359
+ }
360
+ /**
361
+ To be able to serialize steps to JSON, each step needs a string
362
+ ID to attach to its JSON representation. Use this method to
363
+ register an ID for your step classes. Try to pick something
364
+ that's unlikely to clash with steps from other modules.
365
+ */
366
+ static jsonID(id, stepClass) {
367
+ if (id in stepsByID)
368
+ throw new RangeError("Duplicate use of step JSON ID " + id);
369
+ stepsByID[id] = stepClass;
370
+ stepClass.prototype.jsonID = id;
371
+ return stepClass;
372
+ }
373
+ }
374
+ /**
375
+ The result of [applying](https://prosemirror.net/docs/ref/#transform.Step.apply) a step. Contains either a
376
+ new document or a failure value.
377
+ */
378
+ class StepResult {
379
+ /**
380
+ @internal
381
+ */
382
+ constructor(
383
+ /**
384
+ The transformed document, if successful.
385
+ */
386
+ doc,
387
+ /**
388
+ The failure message, if unsuccessful.
389
+ */
390
+ failed) {
391
+ this.doc = doc;
392
+ this.failed = failed;
393
+ }
394
+ /**
395
+ Create a successful step result.
396
+ */
397
+ static ok(doc) { return new StepResult(doc, null); }
398
+ /**
399
+ Create a failed step result.
400
+ */
401
+ static fail(message) { return new StepResult(null, message); }
402
+ /**
403
+ Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given
404
+ arguments. Create a successful result if it succeeds, and a
405
+ failed one if it throws a `ReplaceError`.
406
+ */
407
+ static fromReplace(doc, from, to, slice) {
408
+ try {
409
+ return StepResult.ok(doc.replace(from, to, slice));
410
+ }
411
+ catch (e) {
412
+ if (e instanceof ReplaceError)
413
+ return StepResult.fail(e.message);
414
+ throw e;
415
+ }
416
+ }
417
+ }
418
+
419
+ function mapFragment(fragment, f, parent) {
420
+ let mapped = [];
421
+ for (let i = 0; i < fragment.childCount; i++) {
422
+ let child = fragment.child(i);
423
+ if (child.content.size)
424
+ child = child.copy(mapFragment(child.content, f, child));
425
+ if (child.isInline)
426
+ child = f(child, parent, i);
427
+ mapped.push(child);
428
+ }
429
+ return Fragment.fromArray(mapped);
430
+ }
431
+ /**
432
+ Add a mark to all inline content between two positions.
433
+ */
434
+ class AddMarkStep extends Step {
435
+ /**
436
+ Create a mark step.
437
+ */
438
+ constructor(
439
+ /**
440
+ The start of the marked range.
441
+ */
442
+ from,
443
+ /**
444
+ The end of the marked range.
445
+ */
446
+ to,
447
+ /**
448
+ The mark to add.
449
+ */
450
+ mark) {
451
+ super();
452
+ this.from = from;
453
+ this.to = to;
454
+ this.mark = mark;
455
+ }
456
+ apply(doc) {
457
+ let oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from);
458
+ let parent = $from.node($from.sharedDepth(this.to));
459
+ let slice = new Slice(mapFragment(oldSlice.content, (node, parent) => {
460
+ if (!node.isAtom || !parent.type.allowsMarkType(this.mark.type))
461
+ return node;
462
+ return node.mark(this.mark.addToSet(node.marks));
463
+ }, parent), oldSlice.openStart, oldSlice.openEnd);
464
+ return StepResult.fromReplace(doc, this.from, this.to, slice);
465
+ }
466
+ invert() {
467
+ return new RemoveMarkStep(this.from, this.to, this.mark);
468
+ }
469
+ map(mapping) {
470
+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
471
+ if (from.deleted && to.deleted || from.pos >= to.pos)
472
+ return null;
473
+ return new AddMarkStep(from.pos, to.pos, this.mark);
474
+ }
475
+ merge(other) {
476
+ if (other instanceof AddMarkStep &&
477
+ other.mark.eq(this.mark) &&
478
+ this.from <= other.to && this.to >= other.from)
479
+ return new AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
480
+ return null;
481
+ }
482
+ toJSON() {
483
+ return { stepType: "addMark", mark: this.mark.toJSON(),
484
+ from: this.from, to: this.to };
485
+ }
486
+ /**
487
+ @internal
488
+ */
489
+ static fromJSON(schema, json) {
490
+ if (typeof json.from != "number" || typeof json.to != "number")
491
+ throw new RangeError("Invalid input for AddMarkStep.fromJSON");
492
+ return new AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
493
+ }
494
+ }
495
+ Step.jsonID("addMark", AddMarkStep);
496
+ /**
497
+ Remove a mark from all inline content between two positions.
498
+ */
499
+ class RemoveMarkStep extends Step {
500
+ /**
501
+ Create a mark-removing step.
502
+ */
503
+ constructor(
504
+ /**
505
+ The start of the unmarked range.
506
+ */
507
+ from,
508
+ /**
509
+ The end of the unmarked range.
510
+ */
511
+ to,
512
+ /**
513
+ The mark to remove.
514
+ */
515
+ mark) {
516
+ super();
517
+ this.from = from;
518
+ this.to = to;
519
+ this.mark = mark;
520
+ }
521
+ apply(doc) {
522
+ let oldSlice = doc.slice(this.from, this.to);
523
+ let slice = new Slice(mapFragment(oldSlice.content, node => {
524
+ return node.mark(this.mark.removeFromSet(node.marks));
525
+ }, doc), oldSlice.openStart, oldSlice.openEnd);
526
+ return StepResult.fromReplace(doc, this.from, this.to, slice);
527
+ }
528
+ invert() {
529
+ return new AddMarkStep(this.from, this.to, this.mark);
530
+ }
531
+ map(mapping) {
532
+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
533
+ if (from.deleted && to.deleted || from.pos >= to.pos)
534
+ return null;
535
+ return new RemoveMarkStep(from.pos, to.pos, this.mark);
536
+ }
537
+ merge(other) {
538
+ if (other instanceof RemoveMarkStep &&
539
+ other.mark.eq(this.mark) &&
540
+ this.from <= other.to && this.to >= other.from)
541
+ return new RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
542
+ return null;
543
+ }
544
+ toJSON() {
545
+ return { stepType: "removeMark", mark: this.mark.toJSON(),
546
+ from: this.from, to: this.to };
547
+ }
548
+ /**
549
+ @internal
550
+ */
551
+ static fromJSON(schema, json) {
552
+ if (typeof json.from != "number" || typeof json.to != "number")
553
+ throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");
554
+ return new RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
555
+ }
556
+ }
557
+ Step.jsonID("removeMark", RemoveMarkStep);
558
+ /**
559
+ Add a mark to a specific node.
560
+ */
561
+ class AddNodeMarkStep extends Step {
562
+ /**
563
+ Create a node mark step.
564
+ */
565
+ constructor(
566
+ /**
567
+ The position of the target node.
568
+ */
569
+ pos,
570
+ /**
571
+ The mark to add.
572
+ */
573
+ mark) {
574
+ super();
575
+ this.pos = pos;
576
+ this.mark = mark;
577
+ }
578
+ apply(doc) {
579
+ let node = doc.nodeAt(this.pos);
580
+ if (!node)
581
+ return StepResult.fail("No node at mark step's position");
582
+ let updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));
583
+ return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
584
+ }
585
+ invert(doc) {
586
+ let node = doc.nodeAt(this.pos);
587
+ if (node) {
588
+ let newSet = this.mark.addToSet(node.marks);
589
+ if (newSet.length == node.marks.length) {
590
+ for (let i = 0; i < node.marks.length; i++)
591
+ if (!node.marks[i].isInSet(newSet))
592
+ return new AddNodeMarkStep(this.pos, node.marks[i]);
593
+ return new AddNodeMarkStep(this.pos, this.mark);
594
+ }
595
+ }
596
+ return new RemoveNodeMarkStep(this.pos, this.mark);
597
+ }
598
+ map(mapping) {
599
+ let pos = mapping.mapResult(this.pos, 1);
600
+ return pos.deletedAfter ? null : new AddNodeMarkStep(pos.pos, this.mark);
601
+ }
602
+ toJSON() {
603
+ return { stepType: "addNodeMark", pos: this.pos, mark: this.mark.toJSON() };
604
+ }
605
+ /**
606
+ @internal
607
+ */
608
+ static fromJSON(schema, json) {
609
+ if (typeof json.pos != "number")
610
+ throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");
611
+ return new AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
612
+ }
613
+ }
614
+ Step.jsonID("addNodeMark", AddNodeMarkStep);
615
+ /**
616
+ Remove a mark from a specific node.
617
+ */
618
+ class RemoveNodeMarkStep extends Step {
619
+ /**
620
+ Create a mark-removing step.
621
+ */
622
+ constructor(
623
+ /**
624
+ The position of the target node.
625
+ */
626
+ pos,
627
+ /**
628
+ The mark to remove.
629
+ */
630
+ mark) {
631
+ super();
632
+ this.pos = pos;
633
+ this.mark = mark;
634
+ }
635
+ apply(doc) {
636
+ let node = doc.nodeAt(this.pos);
637
+ if (!node)
638
+ return StepResult.fail("No node at mark step's position");
639
+ let updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));
640
+ return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
641
+ }
642
+ invert(doc) {
643
+ let node = doc.nodeAt(this.pos);
644
+ if (!node || !this.mark.isInSet(node.marks))
645
+ return this;
646
+ return new AddNodeMarkStep(this.pos, this.mark);
647
+ }
648
+ map(mapping) {
649
+ let pos = mapping.mapResult(this.pos, 1);
650
+ return pos.deletedAfter ? null : new RemoveNodeMarkStep(pos.pos, this.mark);
651
+ }
652
+ toJSON() {
653
+ return { stepType: "removeNodeMark", pos: this.pos, mark: this.mark.toJSON() };
654
+ }
655
+ /**
656
+ @internal
657
+ */
658
+ static fromJSON(schema, json) {
659
+ if (typeof json.pos != "number")
660
+ throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
661
+ return new RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
662
+ }
663
+ }
664
+ Step.jsonID("removeNodeMark", RemoveNodeMarkStep);
665
+
666
+ /**
667
+ Replace a part of the document with a slice of new content.
668
+ */
669
+ class ReplaceStep extends Step {
670
+ /**
671
+ The given `slice` should fit the 'gap' between `from` and
672
+ `to`—the depths must line up, and the surrounding nodes must be
673
+ able to be joined with the open sides of the slice. When
674
+ `structure` is true, the step will fail if the content between
675
+ from and to is not just a sequence of closing and then opening
676
+ tokens (this is to guard against rebased replace steps
677
+ overwriting something they weren't supposed to).
678
+ */
679
+ constructor(
680
+ /**
681
+ The start position of the replaced range.
682
+ */
683
+ from,
684
+ /**
685
+ The end position of the replaced range.
686
+ */
687
+ to,
688
+ /**
689
+ The slice to insert.
690
+ */
691
+ slice,
692
+ /**
693
+ @internal
694
+ */
695
+ structure = false) {
696
+ super();
697
+ this.from = from;
698
+ this.to = to;
699
+ this.slice = slice;
700
+ this.structure = structure;
701
+ }
702
+ apply(doc) {
703
+ if (this.structure && contentBetween(doc, this.from, this.to))
704
+ return StepResult.fail("Structure replace would overwrite content");
705
+ return StepResult.fromReplace(doc, this.from, this.to, this.slice);
706
+ }
707
+ getMap() {
708
+ return new StepMap([this.from, this.to - this.from, this.slice.size]);
709
+ }
710
+ invert(doc) {
711
+ return new ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));
712
+ }
713
+ map(mapping) {
714
+ let to = mapping.mapResult(this.to, -1);
715
+ let from = this.from == this.to && ReplaceStep.MAP_BIAS < 0 ? to : mapping.mapResult(this.from, 1);
716
+ if (from.deletedAcross && to.deletedAcross)
717
+ return null;
718
+ return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice, this.structure);
719
+ }
720
+ merge(other) {
721
+ if (!(other instanceof ReplaceStep) || other.structure || this.structure)
722
+ return null;
723
+ if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {
724
+ let slice = this.slice.size + other.slice.size == 0 ? Slice.empty
725
+ : new Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd);
726
+ return new ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure);
727
+ }
728
+ else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {
729
+ let slice = this.slice.size + other.slice.size == 0 ? Slice.empty
730
+ : new Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd);
731
+ return new ReplaceStep(other.from, this.to, slice, this.structure);
732
+ }
733
+ else {
734
+ return null;
735
+ }
736
+ }
737
+ toJSON() {
738
+ let json = { stepType: "replace", from: this.from, to: this.to };
739
+ if (this.slice.size)
740
+ json.slice = this.slice.toJSON();
741
+ if (this.structure)
742
+ json.structure = true;
743
+ return json;
744
+ }
745
+ /**
746
+ @internal
747
+ */
748
+ static fromJSON(schema, json) {
749
+ if (typeof json.from != "number" || typeof json.to != "number")
750
+ throw new RangeError("Invalid input for ReplaceStep.fromJSON");
751
+ return new ReplaceStep(json.from, json.to, Slice.fromJSON(schema, json.slice), !!json.structure);
752
+ }
753
+ }
754
+ /**
755
+ By default, for backwards compatibility, an inserting step
756
+ mapped over an insertion at that same position fill move after
757
+ the inserted content. In a collaborative editing situation, that
758
+ can make redone insertions appear in unexpected places. You can
759
+ set this to -1 to make such mapping keep the step before the
760
+ insertion instead.
761
+ */
762
+ ReplaceStep.MAP_BIAS = 1;
763
+ Step.jsonID("replace", ReplaceStep);
764
+ /**
765
+ Replace a part of the document with a slice of content, but
766
+ preserve a range of the replaced content by moving it into the
767
+ slice.
768
+ */
769
+ class ReplaceAroundStep extends Step {
770
+ /**
771
+ Create a replace-around step with the given range and gap.
772
+ `insert` should be the point in the slice into which the content
773
+ of the gap should be moved. `structure` has the same meaning as
774
+ it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class.
775
+ */
776
+ constructor(
777
+ /**
778
+ The start position of the replaced range.
779
+ */
780
+ from,
781
+ /**
782
+ The end position of the replaced range.
783
+ */
784
+ to,
785
+ /**
786
+ The start of preserved range.
787
+ */
788
+ gapFrom,
789
+ /**
790
+ The end of preserved range.
791
+ */
792
+ gapTo,
793
+ /**
794
+ The slice to insert.
795
+ */
796
+ slice,
797
+ /**
798
+ The position in the slice where the preserved range should be
799
+ inserted.
800
+ */
801
+ insert,
802
+ /**
803
+ @internal
804
+ */
805
+ structure = false) {
806
+ super();
807
+ this.from = from;
808
+ this.to = to;
809
+ this.gapFrom = gapFrom;
810
+ this.gapTo = gapTo;
811
+ this.slice = slice;
812
+ this.insert = insert;
813
+ this.structure = structure;
814
+ }
815
+ apply(doc) {
816
+ if (this.structure && (contentBetween(doc, this.from, this.gapFrom) ||
817
+ contentBetween(doc, this.gapTo, this.to)))
818
+ return StepResult.fail("Structure gap-replace would overwrite content");
819
+ let gap = doc.slice(this.gapFrom, this.gapTo);
820
+ if (gap.openStart || gap.openEnd)
821
+ return StepResult.fail("Gap is not a flat range");
822
+ let inserted = this.slice.insertAt(this.insert, gap.content);
823
+ if (!inserted)
824
+ return StepResult.fail("Content does not fit in gap");
825
+ return StepResult.fromReplace(doc, this.from, this.to, inserted);
826
+ }
827
+ getMap() {
828
+ return new StepMap([this.from, this.gapFrom - this.from, this.insert,
829
+ this.gapTo, this.to - this.gapTo, this.slice.size - this.insert]);
830
+ }
831
+ invert(doc) {
832
+ let gap = this.gapTo - this.gapFrom;
833
+ 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);
834
+ }
835
+ map(mapping) {
836
+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
837
+ let gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1);
838
+ let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
839
+ if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos)
840
+ return null;
841
+ return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
842
+ }
843
+ toJSON() {
844
+ let json = { stepType: "replaceAround", from: this.from, to: this.to,
845
+ gapFrom: this.gapFrom, gapTo: this.gapTo, insert: this.insert };
846
+ if (this.slice.size)
847
+ json.slice = this.slice.toJSON();
848
+ if (this.structure)
849
+ json.structure = true;
850
+ return json;
851
+ }
852
+ /**
853
+ @internal
854
+ */
855
+ static fromJSON(schema, json) {
856
+ if (typeof json.from != "number" || typeof json.to != "number" ||
857
+ typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number")
858
+ throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
859
+ return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
860
+ }
861
+ }
862
+ Step.jsonID("replaceAround", ReplaceAroundStep);
863
+ function contentBetween(doc, from, to) {
864
+ let $from = doc.resolve(from), dist = to - from, depth = $from.depth;
865
+ while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {
866
+ depth--;
867
+ dist--;
868
+ }
869
+ if (dist > 0) {
870
+ let next = $from.node(depth).maybeChild($from.indexAfter(depth));
871
+ while (dist > 0) {
872
+ if (!next || next.isLeaf)
873
+ return true;
874
+ next = next.firstChild;
875
+ dist--;
876
+ }
877
+ }
878
+ return false;
879
+ }
880
+
881
+ function addMark(tr, from, to, mark) {
882
+ let removed = [], added = [];
883
+ let removing, adding;
884
+ tr.doc.nodesBetween(from, to, (node, pos, parent) => {
885
+ if (!node.isInline)
886
+ return;
887
+ let marks = node.marks;
888
+ if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) {
889
+ let start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to);
890
+ let newSet = mark.addToSet(marks);
891
+ for (let i = 0; i < marks.length; i++) {
892
+ if (!marks[i].isInSet(newSet)) {
893
+ if (removing && removing.to == start && removing.mark.eq(marks[i]))
894
+ removing.to = end;
895
+ else
896
+ removed.push(removing = new RemoveMarkStep(start, end, marks[i]));
897
+ }
898
+ }
899
+ if (adding && adding.to == start)
900
+ adding.to = end;
901
+ else
902
+ added.push(adding = new AddMarkStep(start, end, mark));
903
+ }
904
+ });
905
+ removed.forEach(s => tr.step(s));
906
+ added.forEach(s => tr.step(s));
907
+ }
908
+ function removeMark(tr, from, to, mark) {
909
+ let matched = [], step = 0;
910
+ tr.doc.nodesBetween(from, to, (node, pos) => {
911
+ if (!node.isInline)
912
+ return;
913
+ step++;
914
+ let toRemove = null;
915
+ if (mark instanceof MarkType) {
916
+ let set = node.marks, found;
917
+ while (found = mark.isInSet(set)) {
918
+ (toRemove || (toRemove = [])).push(found);
919
+ set = found.removeFromSet(set);
920
+ }
921
+ }
922
+ else if (mark) {
923
+ if (mark.isInSet(node.marks))
924
+ toRemove = [mark];
925
+ }
926
+ else {
927
+ toRemove = node.marks;
928
+ }
929
+ if (toRemove && toRemove.length) {
930
+ let end = Math.min(pos + node.nodeSize, to);
931
+ for (let i = 0; i < toRemove.length; i++) {
932
+ let style = toRemove[i], found;
933
+ for (let j = 0; j < matched.length; j++) {
934
+ let m = matched[j];
935
+ if (m.step == step - 1 && style.eq(matched[j].style))
936
+ found = m;
937
+ }
938
+ if (found) {
939
+ found.to = end;
940
+ found.step = step;
941
+ }
942
+ else {
943
+ matched.push({ style, from: Math.max(pos, from), to: end, step });
944
+ }
945
+ }
946
+ }
947
+ });
948
+ matched.forEach(m => tr.step(new RemoveMarkStep(m.from, m.to, m.style)));
949
+ }
950
+ function clearIncompatible(tr, pos, parentType, match = parentType.contentMatch, clearNewlines = true) {
951
+ let node = tr.doc.nodeAt(pos);
952
+ let replSteps = [], cur = pos + 1;
953
+ for (let i = 0; i < node.childCount; i++) {
954
+ let child = node.child(i), end = cur + child.nodeSize;
955
+ let allowed = match.matchType(child.type);
956
+ if (!allowed) {
957
+ replSteps.push(new ReplaceStep(cur, end, Slice.empty));
958
+ }
959
+ else {
960
+ match = allowed;
961
+ for (let j = 0; j < child.marks.length; j++)
962
+ if (!parentType.allowsMarkType(child.marks[j].type))
963
+ tr.step(new RemoveMarkStep(cur, end, child.marks[j]));
964
+ if (clearNewlines && child.isText && parentType.whitespace != "pre") {
965
+ let m, newline = /\r?\n|\r/g, slice;
966
+ while (m = newline.exec(child.text)) {
967
+ if (!slice)
968
+ slice = new Slice(Fragment.from(parentType.schema.text(" ", parentType.allowedMarks(child.marks))), 0, 0);
969
+ replSteps.push(new ReplaceStep(cur + m.index, cur + m.index + m[0].length, slice));
970
+ }
971
+ }
972
+ }
973
+ cur = end;
974
+ }
975
+ if (!match.validEnd) {
976
+ let fill = match.fillBefore(Fragment.empty, true);
977
+ tr.replace(cur, cur, new Slice(fill, 0, 0));
978
+ }
979
+ for (let i = replSteps.length - 1; i >= 0; i--)
980
+ tr.step(replSteps[i]);
981
+ }
982
+
983
+ function canCut(node, start, end) {
984
+ return (start == 0 || node.canReplace(start, node.childCount)) &&
985
+ (end == node.childCount || node.canReplace(0, end));
986
+ }
987
+ /**
988
+ Try to find a target depth to which the content in the given range
989
+ can be lifted. Will not go across
990
+ [isolating](https://prosemirror.net/docs/ref/#model.NodeSpec.isolating) parent nodes.
991
+ */
992
+ function liftTarget(range) {
993
+ let parent = range.parent;
994
+ let content = parent.content.cutByIndex(range.startIndex, range.endIndex);
995
+ for (let depth = range.depth, contentBefore = 0, contentAfter = 0;; --depth) {
996
+ let node = range.$from.node(depth);
997
+ let index = range.$from.index(depth) + contentBefore, endIndex = range.$to.indexAfter(depth) - contentAfter;
998
+ if (depth < range.depth && node.canReplace(index, endIndex, content))
999
+ return depth;
1000
+ if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex))
1001
+ break;
1002
+ if (index)
1003
+ contentBefore = 1;
1004
+ if (endIndex < node.childCount)
1005
+ contentAfter = 1;
1006
+ }
1007
+ return null;
1008
+ }
1009
+ function lift(tr, range, target) {
1010
+ let { $from, $to, depth } = range;
1011
+ let gapStart = $from.before(depth + 1), gapEnd = $to.after(depth + 1);
1012
+ let start = gapStart, end = gapEnd;
1013
+ let before = Fragment.empty, openStart = 0;
1014
+ for (let d = depth, splitting = false; d > target; d--)
1015
+ if (splitting || $from.index(d) > 0) {
1016
+ splitting = true;
1017
+ before = Fragment.from($from.node(d).copy(before));
1018
+ openStart++;
1019
+ }
1020
+ else {
1021
+ start--;
1022
+ }
1023
+ let after = Fragment.empty, openEnd = 0;
1024
+ for (let d = depth, splitting = false; d > target; d--)
1025
+ if (splitting || $to.after(d + 1) < $to.end(d)) {
1026
+ splitting = true;
1027
+ after = Fragment.from($to.node(d).copy(after));
1028
+ openEnd++;
1029
+ }
1030
+ else {
1031
+ end++;
1032
+ }
1033
+ tr.step(new ReplaceAroundStep(start, end, gapStart, gapEnd, new Slice(before.append(after), openStart, openEnd), before.size - openStart, true));
1034
+ }
1035
+ /**
1036
+ Try to find a valid way to wrap the content in the given range in a
1037
+ node of the given type. May introduce extra nodes around and inside
1038
+ the wrapper node, if necessary. Returns null if no valid wrapping
1039
+ could be found. When `innerRange` is given, that range's content is
1040
+ used as the content to fit into the wrapping, instead of the
1041
+ content of `range`.
1042
+ */
1043
+ function findWrapping(range, nodeType, attrs = null, innerRange = range) {
1044
+ let around = findWrappingOutside(range, nodeType);
1045
+ let inner = around && findWrappingInside(innerRange, nodeType);
1046
+ if (!inner)
1047
+ return null;
1048
+ return around.map(withAttrs)
1049
+ .concat({ type: nodeType, attrs }).concat(inner.map(withAttrs));
1050
+ }
1051
+ function withAttrs(type) { return { type, attrs: null }; }
1052
+ function findWrappingOutside(range, type) {
1053
+ let { parent, startIndex, endIndex } = range;
1054
+ let around = parent.contentMatchAt(startIndex).findWrapping(type);
1055
+ if (!around)
1056
+ return null;
1057
+ let outer = around.length ? around[0] : type;
1058
+ return parent.canReplaceWith(startIndex, endIndex, outer) ? around : null;
1059
+ }
1060
+ function findWrappingInside(range, type) {
1061
+ let { parent, startIndex, endIndex } = range;
1062
+ let inner = parent.child(startIndex);
1063
+ let inside = type.contentMatch.findWrapping(inner.type);
1064
+ if (!inside)
1065
+ return null;
1066
+ let lastType = inside.length ? inside[inside.length - 1] : type;
1067
+ let innerMatch = lastType.contentMatch;
1068
+ for (let i = startIndex; innerMatch && i < endIndex; i++)
1069
+ innerMatch = innerMatch.matchType(parent.child(i).type);
1070
+ if (!innerMatch || !innerMatch.validEnd)
1071
+ return null;
1072
+ return inside;
1073
+ }
1074
+ function wrap(tr, range, wrappers) {
1075
+ let content = Fragment.empty;
1076
+ for (let i = wrappers.length - 1; i >= 0; i--) {
1077
+ if (content.size) {
1078
+ let match = wrappers[i].type.contentMatch.matchFragment(content);
1079
+ if (!match || !match.validEnd)
1080
+ throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper");
1081
+ }
1082
+ content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
1083
+ }
1084
+ let start = range.start, end = range.end;
1085
+ tr.step(new ReplaceAroundStep(start, end, start, end, new Slice(content, 0, 0), wrappers.length, true));
1086
+ }
1087
+ function setBlockType(tr, from, to, type, attrs) {
1088
+ if (!type.isTextblock)
1089
+ throw new RangeError("Type given to setBlockType should be a textblock");
1090
+ let mapFrom = tr.steps.length;
1091
+ tr.doc.nodesBetween(from, to, (node, pos) => {
1092
+ let attrsHere = typeof attrs == "function" ? attrs(node) : attrs;
1093
+ if (node.isTextblock && !node.hasMarkup(type, attrsHere) &&
1094
+ canChangeType(tr.doc, tr.mapping.slice(mapFrom).map(pos), type)) {
1095
+ let convertNewlines = null;
1096
+ if (type.schema.linebreakReplacement) {
1097
+ let pre = type.whitespace == "pre", supportLinebreak = !!type.contentMatch.matchType(type.schema.linebreakReplacement);
1098
+ if (pre && !supportLinebreak)
1099
+ convertNewlines = false;
1100
+ else if (!pre && supportLinebreak)
1101
+ convertNewlines = true;
1102
+ }
1103
+ // Ensure all markup that isn't allowed in the new node type is cleared
1104
+ if (convertNewlines === false)
1105
+ replaceLinebreaks(tr, node, pos, mapFrom);
1106
+ clearIncompatible(tr, tr.mapping.slice(mapFrom).map(pos, 1), type, undefined, convertNewlines === null);
1107
+ let mapping = tr.mapping.slice(mapFrom);
1108
+ let startM = mapping.map(pos, 1), endM = mapping.map(pos + node.nodeSize, 1);
1109
+ tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new Slice(Fragment.from(type.create(attrsHere, null, node.marks)), 0, 0), 1, true));
1110
+ if (convertNewlines === true)
1111
+ replaceNewlines(tr, node, pos, mapFrom);
1112
+ return false;
1113
+ }
1114
+ });
1115
+ }
1116
+ function replaceNewlines(tr, node, pos, mapFrom) {
1117
+ node.forEach((child, offset) => {
1118
+ if (child.isText) {
1119
+ let m, newline = /\r?\n|\r/g;
1120
+ while (m = newline.exec(child.text)) {
1121
+ let start = tr.mapping.slice(mapFrom).map(pos + 1 + offset + m.index);
1122
+ tr.replaceWith(start, start + 1, node.type.schema.linebreakReplacement.create());
1123
+ }
1124
+ }
1125
+ });
1126
+ }
1127
+ function replaceLinebreaks(tr, node, pos, mapFrom) {
1128
+ node.forEach((child, offset) => {
1129
+ if (child.type == child.type.schema.linebreakReplacement) {
1130
+ let start = tr.mapping.slice(mapFrom).map(pos + 1 + offset);
1131
+ tr.replaceWith(start, start + 1, node.type.schema.text("\n"));
1132
+ }
1133
+ });
1134
+ }
1135
+ function canChangeType(doc, pos, type) {
1136
+ let $pos = doc.resolve(pos), index = $pos.index();
1137
+ return $pos.parent.canReplaceWith(index, index + 1, type);
1138
+ }
1139
+ /**
1140
+ Change the type, attributes, and/or marks of the node at `pos`.
1141
+ When `type` isn't given, the existing node type is preserved,
1142
+ */
1143
+ function setNodeMarkup(tr, pos, type, attrs, marks) {
1144
+ let node = tr.doc.nodeAt(pos);
1145
+ if (!node)
1146
+ throw new RangeError("No node at given position");
1147
+ if (!type)
1148
+ type = node.type;
1149
+ let newNode = type.create(attrs, null, marks || node.marks);
1150
+ if (node.isLeaf)
1151
+ return tr.replaceWith(pos, pos + node.nodeSize, newNode);
1152
+ if (!type.validContent(node.content))
1153
+ throw new RangeError("Invalid content for node type " + type.name);
1154
+ tr.step(new ReplaceAroundStep(pos, pos + node.nodeSize, pos + 1, pos + node.nodeSize - 1, new Slice(Fragment.from(newNode), 0, 0), 1, true));
1155
+ }
1156
+ /**
1157
+ Check whether splitting at the given position is allowed.
1158
+ */
1159
+ function canSplit(doc, pos, depth = 1, typesAfter) {
1160
+ let $pos = doc.resolve(pos), base = $pos.depth - depth;
1161
+ let innerType = (typesAfter && typesAfter[typesAfter.length - 1]) || $pos.parent;
1162
+ if (base < 0 || $pos.parent.type.spec.isolating ||
1163
+ !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) ||
1164
+ !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount)))
1165
+ return false;
1166
+ for (let d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) {
1167
+ let node = $pos.node(d), index = $pos.index(d);
1168
+ if (node.type.spec.isolating)
1169
+ return false;
1170
+ let rest = node.content.cutByIndex(index, node.childCount);
1171
+ let overrideChild = typesAfter && typesAfter[i + 1];
1172
+ if (overrideChild)
1173
+ rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs));
1174
+ let after = (typesAfter && typesAfter[i]) || node;
1175
+ if (!node.canReplace(index + 1, node.childCount) || !after.type.validContent(rest))
1176
+ return false;
1177
+ }
1178
+ let index = $pos.indexAfter(base);
1179
+ let baseType = typesAfter && typesAfter[0];
1180
+ return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type);
1181
+ }
1182
+ function split(tr, pos, depth = 1, typesAfter) {
1183
+ let $pos = tr.doc.resolve(pos), before = Fragment.empty, after = Fragment.empty;
1184
+ for (let d = $pos.depth, e = $pos.depth - depth, i = depth - 1; d > e; d--, i--) {
1185
+ before = Fragment.from($pos.node(d).copy(before));
1186
+ let typeAfter = typesAfter && typesAfter[i];
1187
+ after = Fragment.from(typeAfter ? typeAfter.type.create(typeAfter.attrs, after) : $pos.node(d).copy(after));
1188
+ }
1189
+ tr.step(new ReplaceStep(pos, pos, new Slice(before.append(after), depth, depth), true));
1190
+ }
1191
+ /**
1192
+ Test whether the blocks before and after a given position can be
1193
+ joined.
1194
+ */
1195
+ function canJoin(doc, pos) {
1196
+ let $pos = doc.resolve(pos), index = $pos.index();
1197
+ return joinable($pos.nodeBefore, $pos.nodeAfter) &&
1198
+ $pos.parent.canReplace(index, index + 1);
1199
+ }
1200
+ function canAppendWithSubstitutedLinebreaks(a, b) {
1201
+ if (!b.content.size)
1202
+ a.type.compatibleContent(b.type);
1203
+ let match = a.contentMatchAt(a.childCount);
1204
+ let { linebreakReplacement } = a.type.schema;
1205
+ for (let i = 0; i < b.childCount; i++) {
1206
+ let child = b.child(i);
1207
+ let type = child.type == linebreakReplacement ? a.type.schema.nodes.text : child.type;
1208
+ match = match.matchType(type);
1209
+ if (!match)
1210
+ return false;
1211
+ if (!a.type.allowsMarks(child.marks))
1212
+ return false;
1213
+ }
1214
+ return match.validEnd;
1215
+ }
1216
+ function joinable(a, b) {
1217
+ return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebreaks(a, b));
1218
+ }
1219
+ /**
1220
+ Find an ancestor of the given position that can be joined to the
1221
+ block before (or after if `dir` is positive). Returns the joinable
1222
+ point, if any.
1223
+ */
1224
+ function joinPoint(doc, pos, dir = -1) {
1225
+ let $pos = doc.resolve(pos);
1226
+ for (let d = $pos.depth;; d--) {
1227
+ let before, after, index = $pos.index(d);
1228
+ if (d == $pos.depth) {
1229
+ before = $pos.nodeBefore;
1230
+ after = $pos.nodeAfter;
1231
+ }
1232
+ else if (dir > 0) {
1233
+ before = $pos.node(d + 1);
1234
+ index++;
1235
+ after = $pos.node(d).maybeChild(index);
1236
+ }
1237
+ else {
1238
+ before = $pos.node(d).maybeChild(index - 1);
1239
+ after = $pos.node(d + 1);
1240
+ }
1241
+ if (before && !before.isTextblock && joinable(before, after) &&
1242
+ $pos.node(d).canReplace(index, index + 1))
1243
+ return pos;
1244
+ if (d == 0)
1245
+ break;
1246
+ pos = dir < 0 ? $pos.before(d) : $pos.after(d);
1247
+ }
1248
+ }
1249
+ function join(tr, pos, depth) {
1250
+ let convertNewlines = null;
1251
+ let { linebreakReplacement } = tr.doc.type.schema;
1252
+ let $before = tr.doc.resolve(pos - depth), beforeType = $before.node().type;
1253
+ if (linebreakReplacement && beforeType.inlineContent) {
1254
+ let pre = beforeType.whitespace == "pre";
1255
+ let supportLinebreak = !!beforeType.contentMatch.matchType(linebreakReplacement);
1256
+ if (pre && !supportLinebreak)
1257
+ convertNewlines = false;
1258
+ else if (!pre && supportLinebreak)
1259
+ convertNewlines = true;
1260
+ }
1261
+ let mapFrom = tr.steps.length;
1262
+ if (convertNewlines === false) {
1263
+ let $after = tr.doc.resolve(pos + depth);
1264
+ replaceLinebreaks(tr, $after.node(), $after.before(), mapFrom);
1265
+ }
1266
+ if (beforeType.inlineContent)
1267
+ clearIncompatible(tr, pos + depth - 1, beforeType, $before.node().contentMatchAt($before.index()), convertNewlines == null);
1268
+ let mapping = tr.mapping.slice(mapFrom), start = mapping.map(pos - depth);
1269
+ tr.step(new ReplaceStep(start, mapping.map(pos + depth, -1), Slice.empty, true));
1270
+ if (convertNewlines === true) {
1271
+ let $full = tr.doc.resolve(start);
1272
+ replaceNewlines(tr, $full.node(), $full.before(), tr.steps.length);
1273
+ }
1274
+ return tr;
1275
+ }
1276
+ /**
1277
+ Try to find a point where a node of the given type can be inserted
1278
+ near `pos`, by searching up the node hierarchy when `pos` itself
1279
+ isn't a valid place but is at the start or end of a node. Return
1280
+ null if no position was found.
1281
+ */
1282
+ function insertPoint(doc, pos, nodeType) {
1283
+ let $pos = doc.resolve(pos);
1284
+ if ($pos.parent.canReplaceWith($pos.index(), $pos.index(), nodeType))
1285
+ return pos;
1286
+ if ($pos.parentOffset == 0)
1287
+ for (let d = $pos.depth - 1; d >= 0; d--) {
1288
+ let index = $pos.index(d);
1289
+ if ($pos.node(d).canReplaceWith(index, index, nodeType))
1290
+ return $pos.before(d + 1);
1291
+ if (index > 0)
1292
+ return null;
1293
+ }
1294
+ if ($pos.parentOffset == $pos.parent.content.size)
1295
+ for (let d = $pos.depth - 1; d >= 0; d--) {
1296
+ let index = $pos.indexAfter(d);
1297
+ if ($pos.node(d).canReplaceWith(index, index, nodeType))
1298
+ return $pos.after(d + 1);
1299
+ if (index < $pos.node(d).childCount)
1300
+ return null;
1301
+ }
1302
+ return null;
1303
+ }
1304
+ /**
1305
+ Finds a position at or around the given position where the given
1306
+ slice can be inserted. Will look at parent nodes' nearest boundary
1307
+ and try there, even if the original position wasn't directly at the
1308
+ start or end of that node. Returns null when no position was found.
1309
+ */
1310
+ function dropPoint(doc, pos, slice) {
1311
+ let $pos = doc.resolve(pos);
1312
+ if (!slice.content.size)
1313
+ return pos;
1314
+ let content = slice.content;
1315
+ for (let i = 0; i < slice.openStart; i++)
1316
+ content = content.firstChild.content;
1317
+ for (let pass = 1; pass <= (slice.openStart == 0 && slice.size ? 2 : 1); pass++) {
1318
+ for (let d = $pos.depth; d >= 0; d--) {
1319
+ let bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1;
1320
+ let insertPos = $pos.index(d) + (bias > 0 ? 1 : 0);
1321
+ let parent = $pos.node(d), fits = false;
1322
+ if (pass == 1) {
1323
+ fits = parent.canReplace(insertPos, insertPos, content);
1324
+ }
1325
+ else {
1326
+ let wrapping = parent.contentMatchAt(insertPos).findWrapping(content.firstChild.type);
1327
+ fits = wrapping && parent.canReplaceWith(insertPos, insertPos, wrapping[0]);
1328
+ }
1329
+ if (fits)
1330
+ return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1);
1331
+ }
1332
+ }
1333
+ return null;
1334
+ }
1335
+
1336
+ /**
1337
+ ‘Fit’ a slice into a given position in the document, producing a
1338
+ [step](https://prosemirror.net/docs/ref/#transform.Step) that inserts it. Will return null if
1339
+ there's no meaningful way to insert the slice here, or inserting it
1340
+ would be a no-op (an empty slice over an empty range).
1341
+ */
1342
+ function replaceStep(doc, from, to = from, slice = Slice.empty) {
1343
+ if (from == to && !slice.size)
1344
+ return null;
1345
+ let $from = doc.resolve(from), $to = doc.resolve(to);
1346
+ // Optimization -- avoid work if it's obvious that it's not needed.
1347
+ if (fitsTrivially($from, $to, slice))
1348
+ return new ReplaceStep(from, to, slice);
1349
+ return new Fitter($from, $to, slice).fit();
1350
+ }
1351
+ function fitsTrivially($from, $to, slice) {
1352
+ return !slice.openStart && !slice.openEnd && $from.start() == $to.start() &&
1353
+ $from.parent.canReplace($from.index(), $to.index(), slice.content);
1354
+ }
1355
+ // Algorithm for 'placing' the elements of a slice into a gap:
1356
+ //
1357
+ // We consider the content of each node that is open to the left to be
1358
+ // independently placeable. I.e. in <p("foo"), p("bar")>, when the
1359
+ // paragraph on the left is open, "foo" can be placed (somewhere on
1360
+ // the left side of the replacement gap) independently from p("bar").
1361
+ //
1362
+ // This class tracks the state of the placement progress in the
1363
+ // following properties:
1364
+ //
1365
+ // - `frontier` holds a stack of `{type, match}` objects that
1366
+ // represent the open side of the replacement. It starts at
1367
+ // `$from`, then moves forward as content is placed, and is finally
1368
+ // reconciled with `$to`.
1369
+ //
1370
+ // - `unplaced` is a slice that represents the content that hasn't
1371
+ // been placed yet.
1372
+ //
1373
+ // - `placed` is a fragment of placed content. Its open-start value
1374
+ // is implicit in `$from`, and its open-end value in `frontier`.
1375
+ class Fitter {
1376
+ constructor($from, $to, unplaced) {
1377
+ this.$from = $from;
1378
+ this.$to = $to;
1379
+ this.unplaced = unplaced;
1380
+ this.frontier = [];
1381
+ this.placed = Fragment.empty;
1382
+ for (let i = 0; i <= $from.depth; i++) {
1383
+ let node = $from.node(i);
1384
+ this.frontier.push({
1385
+ type: node.type,
1386
+ match: node.contentMatchAt($from.indexAfter(i))
1387
+ });
1388
+ }
1389
+ for (let i = $from.depth; i > 0; i--)
1390
+ this.placed = Fragment.from($from.node(i).copy(this.placed));
1391
+ }
1392
+ get depth() { return this.frontier.length - 1; }
1393
+ fit() {
1394
+ // As long as there's unplaced content, try to place some of it.
1395
+ // If that fails, either increase the open score of the unplaced
1396
+ // slice, or drop nodes from it, and then try again.
1397
+ while (this.unplaced.size) {
1398
+ let fit = this.findFittable();
1399
+ if (fit)
1400
+ this.placeNodes(fit);
1401
+ else
1402
+ this.openMore() || this.dropNode();
1403
+ }
1404
+ // When there's inline content directly after the frontier _and_
1405
+ // directly after `this.$to`, we must generate a `ReplaceAround`
1406
+ // step that pulls that content into the node after the frontier.
1407
+ // That means the fitting must be done to the end of the textblock
1408
+ // node after `this.$to`, not `this.$to` itself.
1409
+ let moveInline = this.mustMoveInline(), placedSize = this.placed.size - this.depth - this.$from.depth;
1410
+ let $from = this.$from, $to = this.close(moveInline < 0 ? this.$to : $from.doc.resolve(moveInline));
1411
+ if (!$to)
1412
+ return null;
1413
+ // If closing to `$to` succeeded, create a step
1414
+ let content = this.placed, openStart = $from.depth, openEnd = $to.depth;
1415
+ while (openStart && openEnd && content.childCount == 1) { // Normalize by dropping open parent nodes
1416
+ content = content.firstChild.content;
1417
+ openStart--;
1418
+ openEnd--;
1419
+ }
1420
+ let slice = new Slice(content, openStart, openEnd);
1421
+ if (moveInline > -1)
1422
+ return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice, placedSize);
1423
+ if (slice.size || $from.pos != this.$to.pos) // Don't generate no-op steps
1424
+ return new ReplaceStep($from.pos, $to.pos, slice);
1425
+ return null;
1426
+ }
1427
+ // Find a position on the start spine of `this.unplaced` that has
1428
+ // content that can be moved somewhere on the frontier. Returns two
1429
+ // depths, one for the slice and one for the frontier.
1430
+ findFittable() {
1431
+ let startDepth = this.unplaced.openStart;
1432
+ for (let cur = this.unplaced.content, d = 0, openEnd = this.unplaced.openEnd; d < startDepth; d++) {
1433
+ let node = cur.firstChild;
1434
+ if (cur.childCount > 1)
1435
+ openEnd = 0;
1436
+ if (node.type.spec.isolating && openEnd <= d) {
1437
+ startDepth = d;
1438
+ break;
1439
+ }
1440
+ cur = node.content;
1441
+ }
1442
+ // Only try wrapping nodes (pass 2) after finding a place without
1443
+ // wrapping failed.
1444
+ for (let pass = 1; pass <= 2; pass++) {
1445
+ for (let sliceDepth = pass == 1 ? startDepth : this.unplaced.openStart; sliceDepth >= 0; sliceDepth--) {
1446
+ let fragment, parent = null;
1447
+ if (sliceDepth) {
1448
+ parent = contentAt(this.unplaced.content, sliceDepth - 1).firstChild;
1449
+ fragment = parent.content;
1450
+ }
1451
+ else {
1452
+ fragment = this.unplaced.content;
1453
+ }
1454
+ let first = fragment.firstChild;
1455
+ for (let frontierDepth = this.depth; frontierDepth >= 0; frontierDepth--) {
1456
+ let { type, match } = this.frontier[frontierDepth], wrap, inject = null;
1457
+ // In pass 1, if the next node matches, or there is no next
1458
+ // node but the parents look compatible, we've found a
1459
+ // place.
1460
+ if (pass == 1 && (first ? match.matchType(first.type) || (inject = match.fillBefore(Fragment.from(first), false))
1461
+ : parent && type.compatibleContent(parent.type)))
1462
+ return { sliceDepth, frontierDepth, parent, inject };
1463
+ // In pass 2, look for a set of wrapping nodes that make
1464
+ // `first` fit here.
1465
+ else if (pass == 2 && first && (wrap = match.findWrapping(first.type)))
1466
+ return { sliceDepth, frontierDepth, parent, wrap };
1467
+ // Don't continue looking further up if the parent node
1468
+ // would fit here.
1469
+ if (parent && match.matchType(parent.type))
1470
+ break;
1471
+ }
1472
+ }
1473
+ }
1474
+ }
1475
+ openMore() {
1476
+ let { content, openStart, openEnd } = this.unplaced;
1477
+ let inner = contentAt(content, openStart);
1478
+ if (!inner.childCount || inner.firstChild.isLeaf)
1479
+ return false;
1480
+ this.unplaced = new Slice(content, openStart + 1, Math.max(openEnd, inner.size + openStart >= content.size - openEnd ? openStart + 1 : 0));
1481
+ return true;
1482
+ }
1483
+ dropNode() {
1484
+ let { content, openStart, openEnd } = this.unplaced;
1485
+ let inner = contentAt(content, openStart);
1486
+ if (inner.childCount <= 1 && openStart > 0) {
1487
+ let openAtEnd = content.size - openStart <= openStart + inner.size;
1488
+ this.unplaced = new Slice(dropFromFragment(content, openStart - 1, 1), openStart - 1, openAtEnd ? openStart - 1 : openEnd);
1489
+ }
1490
+ else {
1491
+ this.unplaced = new Slice(dropFromFragment(content, openStart, 1), openStart, openEnd);
1492
+ }
1493
+ }
1494
+ // Move content from the unplaced slice at `sliceDepth` to the
1495
+ // frontier node at `frontierDepth`. Close that frontier node when
1496
+ // applicable.
1497
+ placeNodes({ sliceDepth, frontierDepth, parent, inject, wrap }) {
1498
+ while (this.depth > frontierDepth)
1499
+ this.closeFrontierNode();
1500
+ if (wrap)
1501
+ for (let i = 0; i < wrap.length; i++)
1502
+ this.openFrontierNode(wrap[i]);
1503
+ let slice = this.unplaced, fragment = parent ? parent.content : slice.content;
1504
+ let openStart = slice.openStart - sliceDepth;
1505
+ let taken = 0, add = [];
1506
+ let { match, type } = this.frontier[frontierDepth];
1507
+ if (inject) {
1508
+ for (let i = 0; i < inject.childCount; i++)
1509
+ add.push(inject.child(i));
1510
+ match = match.matchFragment(inject);
1511
+ }
1512
+ // Computes the amount of (end) open nodes at the end of the
1513
+ // fragment. When 0, the parent is open, but no more. When
1514
+ // negative, nothing is open.
1515
+ let openEndCount = (fragment.size + sliceDepth) - (slice.content.size - slice.openEnd);
1516
+ // Scan over the fragment, fitting as many child nodes as
1517
+ // possible.
1518
+ while (taken < fragment.childCount) {
1519
+ let next = fragment.child(taken), matches = match.matchType(next.type);
1520
+ if (!matches)
1521
+ break;
1522
+ taken++;
1523
+ if (taken > 1 || openStart == 0 || next.content.size) { // Drop empty open nodes
1524
+ match = matches;
1525
+ add.push(closeNodeStart(next.mark(type.allowedMarks(next.marks)), taken == 1 ? openStart : 0, taken == fragment.childCount ? openEndCount : -1));
1526
+ }
1527
+ }
1528
+ let toEnd = taken == fragment.childCount;
1529
+ if (!toEnd)
1530
+ openEndCount = -1;
1531
+ this.placed = addToFragment(this.placed, frontierDepth, Fragment.from(add));
1532
+ this.frontier[frontierDepth].match = match;
1533
+ // If the parent types match, and the entire node was moved, and
1534
+ // it's not open, close this frontier node right away.
1535
+ if (toEnd && openEndCount < 0 && parent && parent.type == this.frontier[this.depth].type && this.frontier.length > 1)
1536
+ this.closeFrontierNode();
1537
+ // Add new frontier nodes for any open nodes at the end.
1538
+ for (let i = 0, cur = fragment; i < openEndCount; i++) {
1539
+ let node = cur.lastChild;
1540
+ this.frontier.push({ type: node.type, match: node.contentMatchAt(node.childCount) });
1541
+ cur = node.content;
1542
+ }
1543
+ // Update `this.unplaced`. Drop the entire node from which we
1544
+ // placed it we got to its end, otherwise just drop the placed
1545
+ // nodes.
1546
+ this.unplaced = !toEnd ? new Slice(dropFromFragment(slice.content, sliceDepth, taken), slice.openStart, slice.openEnd)
1547
+ : sliceDepth == 0 ? Slice.empty
1548
+ : new Slice(dropFromFragment(slice.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1);
1549
+ }
1550
+ mustMoveInline() {
1551
+ if (!this.$to.parent.isTextblock)
1552
+ return -1;
1553
+ let top = this.frontier[this.depth], level;
1554
+ if (!top.type.isTextblock || !contentAfterFits(this.$to, this.$to.depth, top.type, top.match, false) ||
1555
+ (this.$to.depth == this.depth && (level = this.findCloseLevel(this.$to)) && level.depth == this.depth))
1556
+ return -1;
1557
+ let { depth } = this.$to, after = this.$to.after(depth);
1558
+ while (depth > 1 && after == this.$to.end(--depth))
1559
+ ++after;
1560
+ return after;
1561
+ }
1562
+ findCloseLevel($to) {
1563
+ scan: for (let i = Math.min(this.depth, $to.depth); i >= 0; i--) {
1564
+ let { match, type } = this.frontier[i];
1565
+ let dropInner = i < $to.depth && $to.end(i + 1) == $to.pos + ($to.depth - (i + 1));
1566
+ let fit = contentAfterFits($to, i, type, match, dropInner);
1567
+ if (!fit)
1568
+ continue;
1569
+ for (let d = i - 1; d >= 0; d--) {
1570
+ let { match, type } = this.frontier[d];
1571
+ let matches = contentAfterFits($to, d, type, match, true);
1572
+ if (!matches || matches.childCount)
1573
+ continue scan;
1574
+ }
1575
+ return { depth: i, fit, move: dropInner ? $to.doc.resolve($to.after(i + 1)) : $to };
1576
+ }
1577
+ }
1578
+ close($to) {
1579
+ let close = this.findCloseLevel($to);
1580
+ if (!close)
1581
+ return null;
1582
+ while (this.depth > close.depth)
1583
+ this.closeFrontierNode();
1584
+ if (close.fit.childCount)
1585
+ this.placed = addToFragment(this.placed, close.depth, close.fit);
1586
+ $to = close.move;
1587
+ for (let d = close.depth + 1; d <= $to.depth; d++) {
1588
+ let node = $to.node(d), add = node.type.contentMatch.fillBefore(node.content, true, $to.index(d));
1589
+ this.openFrontierNode(node.type, node.attrs, add);
1590
+ }
1591
+ return $to;
1592
+ }
1593
+ openFrontierNode(type, attrs = null, content) {
1594
+ let top = this.frontier[this.depth];
1595
+ top.match = top.match.matchType(type);
1596
+ this.placed = addToFragment(this.placed, this.depth, Fragment.from(type.create(attrs, content)));
1597
+ this.frontier.push({ type, match: type.contentMatch });
1598
+ }
1599
+ closeFrontierNode() {
1600
+ let open = this.frontier.pop();
1601
+ let add = open.match.fillBefore(Fragment.empty, true);
1602
+ if (add.childCount)
1603
+ this.placed = addToFragment(this.placed, this.frontier.length, add);
1604
+ }
1605
+ }
1606
+ function dropFromFragment(fragment, depth, count) {
1607
+ if (depth == 0)
1608
+ return fragment.cutByIndex(count, fragment.childCount);
1609
+ return fragment.replaceChild(0, fragment.firstChild.copy(dropFromFragment(fragment.firstChild.content, depth - 1, count)));
1610
+ }
1611
+ function addToFragment(fragment, depth, content) {
1612
+ if (depth == 0)
1613
+ return fragment.append(content);
1614
+ return fragment.replaceChild(fragment.childCount - 1, fragment.lastChild.copy(addToFragment(fragment.lastChild.content, depth - 1, content)));
1615
+ }
1616
+ function contentAt(fragment, depth) {
1617
+ for (let i = 0; i < depth; i++)
1618
+ fragment = fragment.firstChild.content;
1619
+ return fragment;
1620
+ }
1621
+ function closeNodeStart(node, openStart, openEnd) {
1622
+ if (openStart <= 0)
1623
+ return node;
1624
+ let frag = node.content;
1625
+ if (openStart > 1)
1626
+ frag = frag.replaceChild(0, closeNodeStart(frag.firstChild, openStart - 1, frag.childCount == 1 ? openEnd - 1 : 0));
1627
+ if (openStart > 0) {
1628
+ frag = node.type.contentMatch.fillBefore(frag).append(frag);
1629
+ if (openEnd <= 0)
1630
+ frag = frag.append(node.type.contentMatch.matchFragment(frag).fillBefore(Fragment.empty, true));
1631
+ }
1632
+ return node.copy(frag);
1633
+ }
1634
+ function contentAfterFits($to, depth, type, match, open) {
1635
+ let node = $to.node(depth), index = open ? $to.indexAfter(depth) : $to.index(depth);
1636
+ if (index == node.childCount && !type.compatibleContent(node.type))
1637
+ return null;
1638
+ let fit = match.fillBefore(node.content, true, index);
1639
+ return fit && !invalidMarks(type, node.content, index) ? fit : null;
1640
+ }
1641
+ function invalidMarks(type, fragment, start) {
1642
+ for (let i = start; i < fragment.childCount; i++)
1643
+ if (!type.allowsMarks(fragment.child(i).marks))
1644
+ return true;
1645
+ return false;
1646
+ }
1647
+ function definesContent(type) {
1648
+ return type.spec.defining || type.spec.definingForContent;
1649
+ }
1650
+ function replaceRange(tr, from, to, slice) {
1651
+ if (!slice.size)
1652
+ return tr.deleteRange(from, to);
1653
+ let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);
1654
+ if (fitsTrivially($from, $to, slice))
1655
+ return tr.step(new ReplaceStep(from, to, slice));
1656
+ let targetDepths = coveredDepths($from, $to);
1657
+ // Can't replace the whole document, so remove 0 if it's present
1658
+ if (targetDepths[targetDepths.length - 1] == 0)
1659
+ targetDepths.pop();
1660
+ // Negative numbers represent not expansion over the whole node at
1661
+ // that depth, but replacing from $from.before(-D) to $to.pos.
1662
+ let preferredTarget = -($from.depth + 1);
1663
+ targetDepths.unshift(preferredTarget);
1664
+ // This loop picks a preferred target depth, if one of the covering
1665
+ // depths is not outside of a defining node, and adds negative
1666
+ // depths for any depth that has $from at its start and does not
1667
+ // cross a defining node.
1668
+ for (let d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) {
1669
+ let spec = $from.node(d).type.spec;
1670
+ if (spec.defining || spec.definingAsContext || spec.isolating)
1671
+ break;
1672
+ if (targetDepths.indexOf(d) > -1)
1673
+ preferredTarget = d;
1674
+ else if ($from.before(d) == pos)
1675
+ targetDepths.splice(1, 0, -d);
1676
+ }
1677
+ // Try to fit each possible depth of the slice into each possible
1678
+ // target depth, starting with the preferred depths.
1679
+ let preferredTargetIndex = targetDepths.indexOf(preferredTarget);
1680
+ let leftNodes = [], preferredDepth = slice.openStart;
1681
+ for (let content = slice.content, i = 0;; i++) {
1682
+ let node = content.firstChild;
1683
+ leftNodes.push(node);
1684
+ if (i == slice.openStart)
1685
+ break;
1686
+ content = node.content;
1687
+ }
1688
+ // Back up preferredDepth to cover defining textblocks directly
1689
+ // above it, possibly skipping a non-defining textblock.
1690
+ for (let d = preferredDepth - 1; d >= 0; d--) {
1691
+ let leftNode = leftNodes[d], def = definesContent(leftNode.type);
1692
+ if (def && !leftNode.sameMarkup($from.node(Math.abs(preferredTarget) - 1)))
1693
+ preferredDepth = d;
1694
+ else if (def || !leftNode.type.isTextblock)
1695
+ break;
1696
+ }
1697
+ for (let j = slice.openStart; j >= 0; j--) {
1698
+ let openDepth = (j + preferredDepth + 1) % (slice.openStart + 1);
1699
+ let insert = leftNodes[openDepth];
1700
+ if (!insert)
1701
+ continue;
1702
+ for (let i = 0; i < targetDepths.length; i++) {
1703
+ // Loop over possible expansion levels, starting with the
1704
+ // preferred one
1705
+ let targetDepth = targetDepths[(i + preferredTargetIndex) % targetDepths.length], expand = true;
1706
+ if (targetDepth < 0) {
1707
+ expand = false;
1708
+ targetDepth = -targetDepth;
1709
+ }
1710
+ let parent = $from.node(targetDepth - 1), index = $from.index(targetDepth - 1);
1711
+ if (parent.canReplaceWith(index, index, insert.type, insert.marks))
1712
+ return tr.replace($from.before(targetDepth), expand ? $to.after(targetDepth) : to, new Slice(closeFragment(slice.content, 0, slice.openStart, openDepth), openDepth, slice.openEnd));
1713
+ }
1714
+ }
1715
+ let startSteps = tr.steps.length;
1716
+ for (let i = targetDepths.length - 1; i >= 0; i--) {
1717
+ tr.replace(from, to, slice);
1718
+ if (tr.steps.length > startSteps)
1719
+ break;
1720
+ let depth = targetDepths[i];
1721
+ if (depth < 0)
1722
+ continue;
1723
+ from = $from.before(depth);
1724
+ to = $to.after(depth);
1725
+ }
1726
+ }
1727
+ function closeFragment(fragment, depth, oldOpen, newOpen, parent) {
1728
+ if (depth < oldOpen) {
1729
+ let first = fragment.firstChild;
1730
+ fragment = fragment.replaceChild(0, first.copy(closeFragment(first.content, depth + 1, oldOpen, newOpen, first)));
1731
+ }
1732
+ if (depth > newOpen) {
1733
+ let match = parent.contentMatchAt(0);
1734
+ let start = match.fillBefore(fragment).append(fragment);
1735
+ fragment = start.append(match.matchFragment(start).fillBefore(Fragment.empty, true));
1736
+ }
1737
+ return fragment;
1738
+ }
1739
+ function replaceRangeWith(tr, from, to, node) {
1740
+ if (!node.isInline && from == to && tr.doc.resolve(from).parent.content.size) {
1741
+ let point = insertPoint(tr.doc, from, node.type);
1742
+ if (point != null)
1743
+ from = to = point;
1744
+ }
1745
+ tr.replaceRange(from, to, new Slice(Fragment.from(node), 0, 0));
1746
+ }
1747
+ function deleteRange(tr, from, to) {
1748
+ let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);
1749
+ // When the deleted range spans from the start of one textblock to
1750
+ // the start of another one, move out of the start of both blocks.
1751
+ if ($from.parent.isTextblock && $to.parent.isTextblock && $from.start() != $to.start() &&
1752
+ $from.parentOffset == 0 && $to.parentOffset == 0) {
1753
+ let shared = $from.sharedDepth(to), isolated = false;
1754
+ for (let d = $from.depth; d > shared; d--)
1755
+ if ($from.node(d).type.spec.isolating)
1756
+ isolated = true;
1757
+ for (let d = $to.depth; d > shared; d--)
1758
+ if ($to.node(d).type.spec.isolating)
1759
+ isolated = true;
1760
+ if (!isolated) {
1761
+ for (let d = $from.depth; d > 0 && from == $from.start(d); d--)
1762
+ from = $from.before(d);
1763
+ for (let d = $to.depth; d > 0 && to == $to.start(d); d--)
1764
+ to = $to.before(d);
1765
+ $from = tr.doc.resolve(from);
1766
+ $to = tr.doc.resolve(to);
1767
+ }
1768
+ }
1769
+ let covered = coveredDepths($from, $to);
1770
+ for (let i = 0; i < covered.length; i++) {
1771
+ let depth = covered[i], last = i == covered.length - 1;
1772
+ if ((last && depth == 0) || $from.node(depth).type.contentMatch.validEnd)
1773
+ return tr.delete($from.start(depth), $to.end(depth));
1774
+ if (depth > 0 && (last || $from.node(depth - 1).canReplace($from.index(depth - 1), $to.indexAfter(depth - 1))))
1775
+ return tr.delete($from.before(depth), $to.after(depth));
1776
+ }
1777
+ for (let d = 1; d <= $from.depth && d <= $to.depth; d++) {
1778
+ if (from - $from.start(d) == $from.depth - d && to > $from.end(d) && $to.end(d) - to != $to.depth - d &&
1779
+ $from.start(d - 1) == $to.start(d - 1) && $from.node(d - 1).canReplace($from.index(d - 1), $to.index(d - 1)))
1780
+ return tr.delete($from.before(d), to);
1781
+ }
1782
+ tr.delete(from, to);
1783
+ }
1784
+ // Returns an array of all depths for which $from - $to spans the
1785
+ // whole content of the nodes at that depth.
1786
+ function coveredDepths($from, $to) {
1787
+ let result = [], minDepth = Math.min($from.depth, $to.depth);
1788
+ for (let d = minDepth; d >= 0; d--) {
1789
+ let start = $from.start(d);
1790
+ if (start < $from.pos - ($from.depth - d) ||
1791
+ $to.end(d) > $to.pos + ($to.depth - d) ||
1792
+ $from.node(d).type.spec.isolating ||
1793
+ $to.node(d).type.spec.isolating)
1794
+ break;
1795
+ if (start == $to.start(d) ||
1796
+ (d == $from.depth && d == $to.depth && $from.parent.inlineContent && $to.parent.inlineContent &&
1797
+ d && $to.start(d - 1) == start - 1))
1798
+ result.push(d);
1799
+ }
1800
+ return result;
1801
+ }
1802
+
1803
+ /**
1804
+ Update an attribute in a specific node.
1805
+ */
1806
+ class AttrStep extends Step {
1807
+ /**
1808
+ Construct an attribute step.
1809
+ */
1810
+ constructor(
1811
+ /**
1812
+ The position of the target node.
1813
+ */
1814
+ pos,
1815
+ /**
1816
+ The attribute to set.
1817
+ */
1818
+ attr,
1819
+ // The attribute's new value.
1820
+ value) {
1821
+ super();
1822
+ this.pos = pos;
1823
+ this.attr = attr;
1824
+ this.value = value;
1825
+ }
1826
+ apply(doc) {
1827
+ let node = doc.nodeAt(this.pos);
1828
+ if (!node)
1829
+ return StepResult.fail("No node at attribute step's position");
1830
+ let attrs = Object.create(null);
1831
+ for (let name in node.attrs)
1832
+ attrs[name] = node.attrs[name];
1833
+ attrs[this.attr] = this.value;
1834
+ let updated = node.type.create(attrs, null, node.marks);
1835
+ return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));
1836
+ }
1837
+ getMap() {
1838
+ return StepMap.empty;
1839
+ }
1840
+ invert(doc) {
1841
+ return new AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);
1842
+ }
1843
+ map(mapping) {
1844
+ let pos = mapping.mapResult(this.pos, 1);
1845
+ return pos.deletedAfter ? null : new AttrStep(pos.pos, this.attr, this.value);
1846
+ }
1847
+ toJSON() {
1848
+ return { stepType: "attr", pos: this.pos, attr: this.attr, value: this.value };
1849
+ }
1850
+ static fromJSON(schema, json) {
1851
+ if (typeof json.pos != "number" || typeof json.attr != "string")
1852
+ throw new RangeError("Invalid input for AttrStep.fromJSON");
1853
+ return new AttrStep(json.pos, json.attr, json.value);
1854
+ }
1855
+ }
1856
+ Step.jsonID("attr", AttrStep);
1857
+ /**
1858
+ Update an attribute in the doc node.
1859
+ */
1860
+ class DocAttrStep extends Step {
1861
+ /**
1862
+ Construct an attribute step.
1863
+ */
1864
+ constructor(
1865
+ /**
1866
+ The attribute to set.
1867
+ */
1868
+ attr,
1869
+ // The attribute's new value.
1870
+ value) {
1871
+ super();
1872
+ this.attr = attr;
1873
+ this.value = value;
1874
+ }
1875
+ apply(doc) {
1876
+ let attrs = Object.create(null);
1877
+ for (let name in doc.attrs)
1878
+ attrs[name] = doc.attrs[name];
1879
+ attrs[this.attr] = this.value;
1880
+ let updated = doc.type.create(attrs, doc.content, doc.marks);
1881
+ return StepResult.ok(updated);
1882
+ }
1883
+ getMap() {
1884
+ return StepMap.empty;
1885
+ }
1886
+ invert(doc) {
1887
+ return new DocAttrStep(this.attr, doc.attrs[this.attr]);
1888
+ }
1889
+ map(mapping) {
1890
+ return this;
1891
+ }
1892
+ toJSON() {
1893
+ return { stepType: "docAttr", attr: this.attr, value: this.value };
1894
+ }
1895
+ static fromJSON(schema, json) {
1896
+ if (typeof json.attr != "string")
1897
+ throw new RangeError("Invalid input for DocAttrStep.fromJSON");
1898
+ return new DocAttrStep(json.attr, json.value);
1899
+ }
1900
+ }
1901
+ Step.jsonID("docAttr", DocAttrStep);
1902
+
1903
+ /**
1904
+ @internal
1905
+ */
1906
+ let TransformError = class extends Error {
1907
+ };
1908
+ TransformError = function TransformError(message) {
1909
+ let err = Error.call(this, message);
1910
+ err.__proto__ = TransformError.prototype;
1911
+ return err;
1912
+ };
1913
+ TransformError.prototype = Object.create(Error.prototype);
1914
+ TransformError.prototype.constructor = TransformError;
1915
+ TransformError.prototype.name = "TransformError";
1916
+ /**
1917
+ Abstraction to build up and track an array of
1918
+ [steps](https://prosemirror.net/docs/ref/#transform.Step) representing a document transformation.
1919
+
1920
+ Most transforming methods return the `Transform` object itself, so
1921
+ that they can be chained.
1922
+ */
1923
+ class Transform {
1924
+ /**
1925
+ Create a transform that starts with the given document.
1926
+ */
1927
+ constructor(
1928
+ /**
1929
+ The current document (the result of applying the steps in the
1930
+ transform).
1931
+ */
1932
+ doc) {
1933
+ this.doc = doc;
1934
+ /**
1935
+ The steps in this transform.
1936
+ */
1937
+ this.steps = [];
1938
+ /**
1939
+ The documents before each of the steps.
1940
+ */
1941
+ this.docs = [];
1942
+ /**
1943
+ A mapping with the maps for each of the steps in this transform.
1944
+ */
1945
+ this.mapping = new Mapping;
1946
+ }
1947
+ /**
1948
+ The starting document.
1949
+ */
1950
+ get before() { return this.docs.length ? this.docs[0] : this.doc; }
1951
+ /**
1952
+ Apply a new step in this transform, saving the result. Throws an
1953
+ error when the step fails.
1954
+ */
1955
+ step(step) {
1956
+ let result = this.maybeStep(step);
1957
+ if (result.failed)
1958
+ throw new TransformError(result.failed);
1959
+ return this;
1960
+ }
1961
+ /**
1962
+ Try to apply a step in this transformation, ignoring it if it
1963
+ fails. Returns the step result.
1964
+ */
1965
+ maybeStep(step) {
1966
+ let result = step.apply(this.doc);
1967
+ if (!result.failed)
1968
+ this.addStep(step, result.doc);
1969
+ return result;
1970
+ }
1971
+ /**
1972
+ True when the document has been changed (when there are any
1973
+ steps).
1974
+ */
1975
+ get docChanged() {
1976
+ return this.steps.length > 0;
1977
+ }
1978
+ /**
1979
+ Return a single range, in post-transform document positions,
1980
+ that covers all content changed by this transform. Returns null
1981
+ if no replacements are made. Note that this will ignore changes
1982
+ that add/remove marks without replacing the underlying content.
1983
+ */
1984
+ changedRange() {
1985
+ let from = 1e9, to = -1e9;
1986
+ for (let i = 0; i < this.mapping.maps.length; i++) {
1987
+ let map = this.mapping.maps[i];
1988
+ if (i) {
1989
+ from = map.map(from, 1);
1990
+ to = map.map(to, -1);
1991
+ }
1992
+ map.forEach((_f, _t, fromB, toB) => {
1993
+ from = Math.min(from, fromB);
1994
+ to = Math.max(to, toB);
1995
+ });
1996
+ }
1997
+ return from == 1e9 ? null : { from, to };
1998
+ }
1999
+ /**
2000
+ @internal
2001
+ */
2002
+ addStep(step, doc) {
2003
+ this.docs.push(this.doc);
2004
+ this.steps.push(step);
2005
+ this.mapping.appendMap(step.getMap());
2006
+ this.doc = doc;
2007
+ }
2008
+ /**
2009
+ Replace the part of the document between `from` and `to` with the
2010
+ given `slice`.
2011
+ */
2012
+ replace(from, to = from, slice = Slice.empty) {
2013
+ let step = replaceStep(this.doc, from, to, slice);
2014
+ if (step)
2015
+ this.step(step);
2016
+ return this;
2017
+ }
2018
+ /**
2019
+ Replace the given range with the given content, which may be a
2020
+ fragment, node, or array of nodes.
2021
+ */
2022
+ replaceWith(from, to, content) {
2023
+ return this.replace(from, to, new Slice(Fragment.from(content), 0, 0));
2024
+ }
2025
+ /**
2026
+ Delete the content between the given positions.
2027
+ */
2028
+ delete(from, to) {
2029
+ return this.replace(from, to, Slice.empty);
2030
+ }
2031
+ /**
2032
+ Insert the given content at the given position.
2033
+ */
2034
+ insert(pos, content) {
2035
+ return this.replaceWith(pos, pos, content);
2036
+ }
2037
+ /**
2038
+ Replace a range of the document with a given slice, using
2039
+ `from`, `to`, and the slice's
2040
+ [`openStart`](https://prosemirror.net/docs/ref/#model.Slice.openStart) property as hints, rather
2041
+ than fixed start and end points. This method may grow the
2042
+ replaced area or close open nodes in the slice in order to get a
2043
+ fit that is more in line with WYSIWYG expectations, by dropping
2044
+ fully covered parent nodes of the replaced region when they are
2045
+ marked [non-defining as
2046
+ context](https://prosemirror.net/docs/ref/#model.NodeSpec.definingAsContext), or including an
2047
+ open parent node from the slice that _is_ marked as [defining
2048
+ its content](https://prosemirror.net/docs/ref/#model.NodeSpec.definingForContent).
2049
+
2050
+ This is the method, for example, to handle paste. The similar
2051
+ [`replace`](https://prosemirror.net/docs/ref/#transform.Transform.replace) method is a more
2052
+ primitive tool which will _not_ move the start and end of its given
2053
+ range, and is useful in situations where you need more precise
2054
+ control over what happens.
2055
+ */
2056
+ replaceRange(from, to, slice) {
2057
+ replaceRange(this, from, to, slice);
2058
+ return this;
2059
+ }
2060
+ /**
2061
+ Replace the given range with a node, but use `from` and `to` as
2062
+ hints, rather than precise positions. When from and to are the same
2063
+ and are at the start or end of a parent node in which the given
2064
+ node doesn't fit, this method may _move_ them out towards a parent
2065
+ that does allow the given node to be placed. When the given range
2066
+ completely covers a parent node, this method may completely replace
2067
+ that parent node.
2068
+ */
2069
+ replaceRangeWith(from, to, node) {
2070
+ replaceRangeWith(this, from, to, node);
2071
+ return this;
2072
+ }
2073
+ /**
2074
+ Delete the given range, expanding it to cover fully covered
2075
+ parent nodes until a valid replace is found.
2076
+ */
2077
+ deleteRange(from, to) {
2078
+ deleteRange(this, from, to);
2079
+ return this;
2080
+ }
2081
+ /**
2082
+ Split the content in the given range off from its parent, if there
2083
+ is sibling content before or after it, and move it up the tree to
2084
+ the depth specified by `target`. You'll probably want to use
2085
+ [`liftTarget`](https://prosemirror.net/docs/ref/#transform.liftTarget) to compute `target`, to make
2086
+ sure the lift is valid.
2087
+ */
2088
+ lift(range, target) {
2089
+ lift(this, range, target);
2090
+ return this;
2091
+ }
2092
+ /**
2093
+ Join the blocks around the given position. If depth is 2, their
2094
+ last and first siblings are also joined, and so on.
2095
+ */
2096
+ join(pos, depth = 1) {
2097
+ join(this, pos, depth);
2098
+ return this;
2099
+ }
2100
+ /**
2101
+ Wrap the given [range](https://prosemirror.net/docs/ref/#model.NodeRange) in the given set of wrappers.
2102
+ The wrappers are assumed to be valid in this position, and should
2103
+ probably be computed with [`findWrapping`](https://prosemirror.net/docs/ref/#transform.findWrapping).
2104
+ */
2105
+ wrap(range, wrappers) {
2106
+ wrap(this, range, wrappers);
2107
+ return this;
2108
+ }
2109
+ /**
2110
+ Set the type of all textblocks (partly) between `from` and `to` to
2111
+ the given node type with the given attributes.
2112
+ */
2113
+ setBlockType(from, to = from, type, attrs = null) {
2114
+ setBlockType(this, from, to, type, attrs);
2115
+ return this;
2116
+ }
2117
+ /**
2118
+ Change the type, attributes, and/or marks of the node at `pos`.
2119
+ When `type` isn't given, the existing node type is preserved,
2120
+ */
2121
+ setNodeMarkup(pos, type, attrs = null, marks) {
2122
+ setNodeMarkup(this, pos, type, attrs, marks);
2123
+ return this;
2124
+ }
2125
+ /**
2126
+ Set a single attribute on a given node to a new value.
2127
+ The `pos` addresses the document content. Use `setDocAttribute`
2128
+ to set attributes on the document itself.
2129
+ */
2130
+ setNodeAttribute(pos, attr, value) {
2131
+ this.step(new AttrStep(pos, attr, value));
2132
+ return this;
2133
+ }
2134
+ /**
2135
+ Set a single attribute on the document to a new value.
2136
+ */
2137
+ setDocAttribute(attr, value) {
2138
+ this.step(new DocAttrStep(attr, value));
2139
+ return this;
2140
+ }
2141
+ /**
2142
+ Add a mark to the node at position `pos`.
2143
+ */
2144
+ addNodeMark(pos, mark) {
2145
+ this.step(new AddNodeMarkStep(pos, mark));
2146
+ return this;
2147
+ }
2148
+ /**
2149
+ Remove a mark (or all marks of the given type) from the node at
2150
+ position `pos`.
2151
+ */
2152
+ removeNodeMark(pos, mark) {
2153
+ let node = this.doc.nodeAt(pos);
2154
+ if (!node)
2155
+ throw new RangeError("No node at position " + pos);
2156
+ if (mark instanceof Mark) {
2157
+ if (mark.isInSet(node.marks))
2158
+ this.step(new RemoveNodeMarkStep(pos, mark));
2159
+ }
2160
+ else {
2161
+ let set = node.marks, found, steps = [];
2162
+ while (found = mark.isInSet(set)) {
2163
+ steps.push(new RemoveNodeMarkStep(pos, found));
2164
+ set = found.removeFromSet(set);
2165
+ }
2166
+ for (let i = steps.length - 1; i >= 0; i--)
2167
+ this.step(steps[i]);
2168
+ }
2169
+ return this;
2170
+ }
2171
+ /**
2172
+ Split the node at the given position, and optionally, if `depth` is
2173
+ greater than one, any number of nodes above that. By default, the
2174
+ parts split off will inherit the node type of the original node.
2175
+ This can be changed by passing an array of types and attributes to
2176
+ use after the split (with the outermost nodes coming first).
2177
+ */
2178
+ split(pos, depth = 1, typesAfter) {
2179
+ split(this, pos, depth, typesAfter);
2180
+ return this;
2181
+ }
2182
+ /**
2183
+ Add the given mark to the inline content between `from` and `to`.
2184
+ */
2185
+ addMark(from, to, mark) {
2186
+ addMark(this, from, to, mark);
2187
+ return this;
2188
+ }
2189
+ /**
2190
+ Remove marks from inline nodes between `from` and `to`. When
2191
+ `mark` is a single mark, remove precisely that mark. When it is
2192
+ a mark type, remove all marks of that type. When it is null,
2193
+ remove all marks of any type.
2194
+ */
2195
+ removeMark(from, to, mark) {
2196
+ removeMark(this, from, to, mark);
2197
+ return this;
2198
+ }
2199
+ /**
2200
+ Removes all marks and nodes from the content of the node at
2201
+ `pos` that don't match the given new parent node type. Accepts
2202
+ an optional starting [content match](https://prosemirror.net/docs/ref/#model.ContentMatch) as
2203
+ third argument.
2204
+ */
2205
+ clearIncompatible(pos, parentType, match) {
2206
+ clearIncompatible(this, pos, parentType, match);
2207
+ return this;
2208
+ }
2209
+ }
2210
+
2211
+ const classesById = Object.create(null);
2212
+ /**
2213
+ Superclass for editor selections. Every selection type should
2214
+ extend this. Should not be instantiated directly.
2215
+ */
2216
+ class Selection {
2217
+ /**
2218
+ Initialize a selection with the head and anchor and ranges. If no
2219
+ ranges are given, constructs a single range across `$anchor` and
2220
+ `$head`.
2221
+ */
2222
+ constructor(
2223
+ /**
2224
+ The resolved anchor of the selection (the side that stays in
2225
+ place when the selection is modified).
2226
+ */
2227
+ $anchor,
2228
+ /**
2229
+ The resolved head of the selection (the side that moves when
2230
+ the selection is modified).
2231
+ */
2232
+ $head, ranges) {
2233
+ this.$anchor = $anchor;
2234
+ this.$head = $head;
2235
+ this.ranges = ranges || [new SelectionRange($anchor.min($head), $anchor.max($head))];
2236
+ }
2237
+ /**
2238
+ The selection's anchor, as an unresolved position.
2239
+ */
2240
+ get anchor() { return this.$anchor.pos; }
2241
+ /**
2242
+ The selection's head.
2243
+ */
2244
+ get head() { return this.$head.pos; }
2245
+ /**
2246
+ The lower bound of the selection's main range.
2247
+ */
2248
+ get from() { return this.$from.pos; }
2249
+ /**
2250
+ The upper bound of the selection's main range.
2251
+ */
2252
+ get to() { return this.$to.pos; }
2253
+ /**
2254
+ The resolved lower bound of the selection's main range.
2255
+ */
2256
+ get $from() {
2257
+ return this.ranges[0].$from;
2258
+ }
2259
+ /**
2260
+ The resolved upper bound of the selection's main range.
2261
+ */
2262
+ get $to() {
2263
+ return this.ranges[0].$to;
2264
+ }
2265
+ /**
2266
+ Indicates whether the selection contains any content.
2267
+ */
2268
+ get empty() {
2269
+ let ranges = this.ranges;
2270
+ for (let i = 0; i < ranges.length; i++)
2271
+ if (ranges[i].$from.pos != ranges[i].$to.pos)
2272
+ return false;
2273
+ return true;
2274
+ }
2275
+ /**
2276
+ Get the content of this selection as a slice.
2277
+ */
2278
+ content() {
2279
+ return this.$from.doc.slice(this.from, this.to, true);
2280
+ }
2281
+ /**
2282
+ Replace the selection with a slice or, if no slice is given,
2283
+ delete the selection. Will append to the given transaction.
2284
+ */
2285
+ replace(tr, content = Slice.empty) {
2286
+ // Put the new selection at the position after the inserted
2287
+ // content. When that ended in an inline node, search backwards,
2288
+ // to get the position after that node. If not, search forward.
2289
+ let lastNode = content.content.lastChild, lastParent = null;
2290
+ for (let i = 0; i < content.openEnd; i++) {
2291
+ lastParent = lastNode;
2292
+ lastNode = lastNode.lastChild;
2293
+ }
2294
+ let mapFrom = tr.steps.length, ranges = this.ranges;
2295
+ for (let i = 0; i < ranges.length; i++) {
2296
+ let { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
2297
+ tr.replaceRange(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
2298
+ if (i == 0)
2299
+ selectionToInsertionEnd(tr, mapFrom, (lastNode ? lastNode.isInline : lastParent && lastParent.isTextblock) ? -1 : 1);
2300
+ }
2301
+ }
2302
+ /**
2303
+ Replace the selection with the given node, appending the changes
2304
+ to the given transaction.
2305
+ */
2306
+ replaceWith(tr, node) {
2307
+ let mapFrom = tr.steps.length, ranges = this.ranges;
2308
+ for (let i = 0; i < ranges.length; i++) {
2309
+ let { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
2310
+ let from = mapping.map($from.pos), to = mapping.map($to.pos);
2311
+ if (i) {
2312
+ tr.deleteRange(from, to);
2313
+ }
2314
+ else {
2315
+ tr.replaceRangeWith(from, to, node);
2316
+ selectionToInsertionEnd(tr, mapFrom, node.isInline ? -1 : 1);
2317
+ }
2318
+ }
2319
+ }
2320
+ /**
2321
+ Find a valid cursor or leaf node selection starting at the given
2322
+ position and searching back if `dir` is negative, and forward if
2323
+ positive. When `textOnly` is true, only consider cursor
2324
+ selections. Will return null when no valid selection position is
2325
+ found.
2326
+ */
2327
+ static findFrom($pos, dir, textOnly = false) {
2328
+ let inner = $pos.parent.inlineContent ? new TextSelection($pos)
2329
+ : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly);
2330
+ if (inner)
2331
+ return inner;
2332
+ for (let depth = $pos.depth - 1; depth >= 0; depth--) {
2333
+ let found = dir < 0
2334
+ ? findSelectionIn($pos.node(0), $pos.node(depth), $pos.before(depth + 1), $pos.index(depth), dir, textOnly)
2335
+ : findSelectionIn($pos.node(0), $pos.node(depth), $pos.after(depth + 1), $pos.index(depth) + 1, dir, textOnly);
2336
+ if (found)
2337
+ return found;
2338
+ }
2339
+ return null;
2340
+ }
2341
+ /**
2342
+ Find a valid cursor or leaf node selection near the given
2343
+ position. Searches forward first by default, but if `bias` is
2344
+ negative, it will search backwards first.
2345
+ */
2346
+ static near($pos, bias = 1) {
2347
+ return this.findFrom($pos, bias) || this.findFrom($pos, -bias) || new AllSelection($pos.node(0));
2348
+ }
2349
+ /**
2350
+ Find the cursor or leaf node selection closest to the start of
2351
+ the given document. Will return an
2352
+ [`AllSelection`](https://prosemirror.net/docs/ref/#state.AllSelection) if no valid position
2353
+ exists.
2354
+ */
2355
+ static atStart(doc) {
2356
+ return findSelectionIn(doc, doc, 0, 0, 1) || new AllSelection(doc);
2357
+ }
2358
+ /**
2359
+ Find the cursor or leaf node selection closest to the end of the
2360
+ given document.
2361
+ */
2362
+ static atEnd(doc) {
2363
+ return findSelectionIn(doc, doc, doc.content.size, doc.childCount, -1) || new AllSelection(doc);
2364
+ }
2365
+ /**
2366
+ Deserialize the JSON representation of a selection. Must be
2367
+ implemented for custom classes (as a static class method).
2368
+ */
2369
+ static fromJSON(doc, json) {
2370
+ if (!json || !json.type)
2371
+ throw new RangeError("Invalid input for Selection.fromJSON");
2372
+ let cls = classesById[json.type];
2373
+ if (!cls)
2374
+ throw new RangeError(`No selection type ${json.type} defined`);
2375
+ return cls.fromJSON(doc, json);
2376
+ }
2377
+ /**
2378
+ To be able to deserialize selections from JSON, custom selection
2379
+ classes must register themselves with an ID string, so that they
2380
+ can be disambiguated. Try to pick something that's unlikely to
2381
+ clash with classes from other modules.
2382
+ */
2383
+ static jsonID(id, selectionClass) {
2384
+ if (id in classesById)
2385
+ throw new RangeError("Duplicate use of selection JSON ID " + id);
2386
+ classesById[id] = selectionClass;
2387
+ selectionClass.prototype.jsonID = id;
2388
+ return selectionClass;
2389
+ }
2390
+ /**
2391
+ Get a [bookmark](https://prosemirror.net/docs/ref/#state.SelectionBookmark) for this selection,
2392
+ which is a value that can be mapped without having access to a
2393
+ current document, and later resolved to a real selection for a
2394
+ given document again. (This is used mostly by the history to
2395
+ track and restore old selections.) The default implementation of
2396
+ this method just converts the selection to a text selection and
2397
+ returns the bookmark for that.
2398
+ */
2399
+ getBookmark() {
2400
+ return TextSelection.between(this.$anchor, this.$head).getBookmark();
2401
+ }
2402
+ }
2403
+ Selection.prototype.visible = true;
2404
+ /**
2405
+ Represents a selected range in a document.
2406
+ */
2407
+ class SelectionRange {
2408
+ /**
2409
+ Create a range.
2410
+ */
2411
+ constructor(
2412
+ /**
2413
+ The lower bound of the range.
2414
+ */
2415
+ $from,
2416
+ /**
2417
+ The upper bound of the range.
2418
+ */
2419
+ $to) {
2420
+ this.$from = $from;
2421
+ this.$to = $to;
2422
+ }
2423
+ }
2424
+ let warnedAboutTextSelection = false;
2425
+ function checkTextSelection($pos) {
2426
+ if (!warnedAboutTextSelection && !$pos.parent.inlineContent) {
2427
+ warnedAboutTextSelection = true;
2428
+ console["warn"]("TextSelection endpoint not pointing into a node with inline content (" + $pos.parent.type.name + ")");
2429
+ }
2430
+ }
2431
+ /**
2432
+ A text selection represents a classical editor selection, with a
2433
+ head (the moving side) and anchor (immobile side), both of which
2434
+ point into textblock nodes. It can be empty (a regular cursor
2435
+ position).
2436
+ */
2437
+ class TextSelection extends Selection {
2438
+ /**
2439
+ Construct a text selection between the given points.
2440
+ */
2441
+ constructor($anchor, $head = $anchor) {
2442
+ checkTextSelection($anchor);
2443
+ checkTextSelection($head);
2444
+ super($anchor, $head);
2445
+ }
2446
+ /**
2447
+ Returns a resolved position if this is a cursor selection (an
2448
+ empty text selection), and null otherwise.
2449
+ */
2450
+ get $cursor() { return this.$anchor.pos == this.$head.pos ? this.$head : null; }
2451
+ map(doc, mapping) {
2452
+ let $head = doc.resolve(mapping.map(this.head));
2453
+ if (!$head.parent.inlineContent)
2454
+ return Selection.near($head);
2455
+ let $anchor = doc.resolve(mapping.map(this.anchor));
2456
+ return new TextSelection($anchor.parent.inlineContent ? $anchor : $head, $head);
2457
+ }
2458
+ replace(tr, content = Slice.empty) {
2459
+ super.replace(tr, content);
2460
+ if (content == Slice.empty) {
2461
+ let marks = this.$from.marksAcross(this.$to);
2462
+ if (marks)
2463
+ tr.ensureMarks(marks);
2464
+ }
2465
+ }
2466
+ eq(other) {
2467
+ return other instanceof TextSelection && other.anchor == this.anchor && other.head == this.head;
2468
+ }
2469
+ getBookmark() {
2470
+ return new TextBookmark(this.anchor, this.head);
2471
+ }
2472
+ toJSON() {
2473
+ return { type: "text", anchor: this.anchor, head: this.head };
2474
+ }
2475
+ /**
2476
+ @internal
2477
+ */
2478
+ static fromJSON(doc, json) {
2479
+ if (typeof json.anchor != "number" || typeof json.head != "number")
2480
+ throw new RangeError("Invalid input for TextSelection.fromJSON");
2481
+ return new TextSelection(doc.resolve(json.anchor), doc.resolve(json.head));
2482
+ }
2483
+ /**
2484
+ Create a text selection from non-resolved positions.
2485
+ */
2486
+ static create(doc, anchor, head = anchor) {
2487
+ let $anchor = doc.resolve(anchor);
2488
+ return new this($anchor, head == anchor ? $anchor : doc.resolve(head));
2489
+ }
2490
+ /**
2491
+ Return a text selection that spans the given positions or, if
2492
+ they aren't text positions, find a text selection near them.
2493
+ `bias` determines whether the method searches forward (default)
2494
+ or backwards (negative number) first. Will fall back to calling
2495
+ [`Selection.near`](https://prosemirror.net/docs/ref/#state.Selection^near) when the document
2496
+ doesn't contain a valid text position.
2497
+ */
2498
+ static between($anchor, $head, bias) {
2499
+ let dPos = $anchor.pos - $head.pos;
2500
+ if (!bias || dPos)
2501
+ bias = dPos >= 0 ? 1 : -1;
2502
+ if (!$head.parent.inlineContent) {
2503
+ let found = Selection.findFrom($head, bias, true) || Selection.findFrom($head, -bias, true);
2504
+ if (found)
2505
+ $head = found.$head;
2506
+ else
2507
+ return Selection.near($head, bias);
2508
+ }
2509
+ if (!$anchor.parent.inlineContent) {
2510
+ if (dPos == 0) {
2511
+ $anchor = $head;
2512
+ }
2513
+ else {
2514
+ $anchor = (Selection.findFrom($anchor, -bias, true) || Selection.findFrom($anchor, bias, true)).$anchor;
2515
+ if (($anchor.pos < $head.pos) != (dPos < 0))
2516
+ $anchor = $head;
2517
+ }
2518
+ }
2519
+ return new TextSelection($anchor, $head);
2520
+ }
2521
+ }
2522
+ Selection.jsonID("text", TextSelection);
2523
+ class TextBookmark {
2524
+ constructor(anchor, head) {
2525
+ this.anchor = anchor;
2526
+ this.head = head;
2527
+ }
2528
+ map(mapping) {
2529
+ return new TextBookmark(mapping.map(this.anchor), mapping.map(this.head));
2530
+ }
2531
+ resolve(doc) {
2532
+ return TextSelection.between(doc.resolve(this.anchor), doc.resolve(this.head));
2533
+ }
2534
+ }
2535
+ /**
2536
+ A node selection is a selection that points at a single node. All
2537
+ nodes marked [selectable](https://prosemirror.net/docs/ref/#model.NodeSpec.selectable) can be the
2538
+ target of a node selection. In such a selection, `from` and `to`
2539
+ point directly before and after the selected node, `anchor` equals
2540
+ `from`, and `head` equals `to`..
2541
+ */
2542
+ class NodeSelection extends Selection {
2543
+ /**
2544
+ Create a node selection. Does not verify the validity of its
2545
+ argument.
2546
+ */
2547
+ constructor($pos) {
2548
+ let node = $pos.nodeAfter;
2549
+ let $end = $pos.node(0).resolve($pos.pos + node.nodeSize);
2550
+ super($pos, $end);
2551
+ this.node = node;
2552
+ }
2553
+ map(doc, mapping) {
2554
+ let { deleted, pos } = mapping.mapResult(this.anchor);
2555
+ let $pos = doc.resolve(pos);
2556
+ if (deleted)
2557
+ return Selection.near($pos);
2558
+ return new NodeSelection($pos);
2559
+ }
2560
+ content() {
2561
+ return new Slice(Fragment.from(this.node), 0, 0);
2562
+ }
2563
+ eq(other) {
2564
+ return other instanceof NodeSelection && other.anchor == this.anchor;
2565
+ }
2566
+ toJSON() {
2567
+ return { type: "node", anchor: this.anchor };
2568
+ }
2569
+ getBookmark() { return new NodeBookmark(this.anchor); }
2570
+ /**
2571
+ @internal
2572
+ */
2573
+ static fromJSON(doc, json) {
2574
+ if (typeof json.anchor != "number")
2575
+ throw new RangeError("Invalid input for NodeSelection.fromJSON");
2576
+ return new NodeSelection(doc.resolve(json.anchor));
2577
+ }
2578
+ /**
2579
+ Create a node selection from non-resolved positions.
2580
+ */
2581
+ static create(doc, from) {
2582
+ return new NodeSelection(doc.resolve(from));
2583
+ }
2584
+ /**
2585
+ Determines whether the given node may be selected as a node
2586
+ selection.
2587
+ */
2588
+ static isSelectable(node) {
2589
+ return !node.isText && node.type.spec.selectable !== false;
2590
+ }
2591
+ }
2592
+ NodeSelection.prototype.visible = false;
2593
+ Selection.jsonID("node", NodeSelection);
2594
+ class NodeBookmark {
2595
+ constructor(anchor) {
2596
+ this.anchor = anchor;
2597
+ }
2598
+ map(mapping) {
2599
+ let { deleted, pos } = mapping.mapResult(this.anchor);
2600
+ return deleted ? new TextBookmark(pos, pos) : new NodeBookmark(pos);
2601
+ }
2602
+ resolve(doc) {
2603
+ let $pos = doc.resolve(this.anchor), node = $pos.nodeAfter;
2604
+ if (node && NodeSelection.isSelectable(node))
2605
+ return new NodeSelection($pos);
2606
+ return Selection.near($pos);
2607
+ }
2608
+ }
2609
+ /**
2610
+ A selection type that represents selecting the whole document
2611
+ (which can not necessarily be expressed with a text selection, when
2612
+ there are for example leaf block nodes at the start or end of the
2613
+ document).
2614
+ */
2615
+ class AllSelection extends Selection {
2616
+ /**
2617
+ Create an all-selection over the given document.
2618
+ */
2619
+ constructor(doc) {
2620
+ super(doc.resolve(0), doc.resolve(doc.content.size));
2621
+ }
2622
+ replace(tr, content = Slice.empty) {
2623
+ if (content == Slice.empty) {
2624
+ tr.delete(0, tr.doc.content.size);
2625
+ let sel = Selection.atStart(tr.doc);
2626
+ if (!sel.eq(tr.selection))
2627
+ tr.setSelection(sel);
2628
+ }
2629
+ else {
2630
+ super.replace(tr, content);
2631
+ }
2632
+ }
2633
+ toJSON() { return { type: "all" }; }
2634
+ /**
2635
+ @internal
2636
+ */
2637
+ static fromJSON(doc) { return new AllSelection(doc); }
2638
+ map(doc) { return new AllSelection(doc); }
2639
+ eq(other) { return other instanceof AllSelection; }
2640
+ getBookmark() { return AllBookmark; }
2641
+ }
2642
+ Selection.jsonID("all", AllSelection);
2643
+ const AllBookmark = {
2644
+ map() { return this; },
2645
+ resolve(doc) { return new AllSelection(doc); }
2646
+ };
2647
+ // FIXME we'll need some awareness of text direction when scanning for selections
2648
+ // Try to find a selection inside the given node. `pos` points at the
2649
+ // position where the search starts. When `text` is true, only return
2650
+ // text selections.
2651
+ function findSelectionIn(doc, node, pos, index, dir, text = false) {
2652
+ if (node.inlineContent)
2653
+ return TextSelection.create(doc, pos);
2654
+ for (let i = index - (dir > 0 ? 0 : 1); dir > 0 ? i < node.childCount : i >= 0; i += dir) {
2655
+ let child = node.child(i);
2656
+ if (!child.isAtom) {
2657
+ let inner = findSelectionIn(doc, child, pos + dir, dir < 0 ? child.childCount : 0, dir, text);
2658
+ if (inner)
2659
+ return inner;
2660
+ }
2661
+ else if (!text && NodeSelection.isSelectable(child)) {
2662
+ return NodeSelection.create(doc, pos - (dir < 0 ? child.nodeSize : 0));
2663
+ }
2664
+ pos += child.nodeSize * dir;
2665
+ }
2666
+ return null;
2667
+ }
2668
+ function selectionToInsertionEnd(tr, startLen, bias) {
2669
+ let last = tr.steps.length - 1;
2670
+ if (last < startLen)
2671
+ return;
2672
+ let step = tr.steps[last];
2673
+ if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep))
2674
+ return;
2675
+ let map = tr.mapping.maps[last], end;
2676
+ map.forEach((_from, _to, _newFrom, newTo) => { if (end == null)
2677
+ end = newTo; });
2678
+ tr.setSelection(Selection.near(tr.doc.resolve(end), bias));
2679
+ }
2680
+
2681
+ const UPDATED_SEL = 1, UPDATED_MARKS = 2, UPDATED_SCROLL = 4;
2682
+ /**
2683
+ An editor state transaction, which can be applied to a state to
2684
+ create an updated state. Use
2685
+ [`EditorState.tr`](https://prosemirror.net/docs/ref/#state.EditorState.tr) to create an instance.
2686
+
2687
+ Transactions track changes to the document (they are a subclass of
2688
+ [`Transform`](https://prosemirror.net/docs/ref/#transform.Transform)), but also other state changes,
2689
+ like selection updates and adjustments of the set of [stored
2690
+ marks](https://prosemirror.net/docs/ref/#state.EditorState.storedMarks). In addition, you can store
2691
+ metadata properties in a transaction, which are extra pieces of
2692
+ information that client code or plugins can use to describe what a
2693
+ transaction represents, so that they can update their [own
2694
+ state](https://prosemirror.net/docs/ref/#state.StateField) accordingly.
2695
+
2696
+ The [editor view](https://prosemirror.net/docs/ref/#view.EditorView) uses a few metadata
2697
+ properties: it will attach a property `"pointer"` with the value
2698
+ `true` to selection transactions directly caused by mouse or touch
2699
+ input, a `"composition"` property holding an ID identifying the
2700
+ composition that caused it to transactions caused by composed DOM
2701
+ input, and a `"uiEvent"` property of that may be `"paste"`,
2702
+ `"cut"`, or `"drop"`.
2703
+ */
2704
+ class Transaction extends Transform {
2705
+ /**
2706
+ @internal
2707
+ */
2708
+ constructor(state) {
2709
+ super(state.doc);
2710
+ // The step count for which the current selection is valid.
2711
+ this.curSelectionFor = 0;
2712
+ // Bitfield to track which aspects of the state were updated by
2713
+ // this transaction.
2714
+ this.updated = 0;
2715
+ // Object used to store metadata properties for the transaction.
2716
+ this.meta = Object.create(null);
2717
+ this.time = Date.now();
2718
+ this.curSelection = state.selection;
2719
+ this.storedMarks = state.storedMarks;
2720
+ }
2721
+ /**
2722
+ The transaction's current selection. This defaults to the editor
2723
+ selection [mapped](https://prosemirror.net/docs/ref/#state.Selection.map) through the steps in the
2724
+ transaction, but can be overwritten with
2725
+ [`setSelection`](https://prosemirror.net/docs/ref/#state.Transaction.setSelection).
2726
+ */
2727
+ get selection() {
2728
+ if (this.curSelectionFor < this.steps.length) {
2729
+ this.curSelection = this.curSelection.map(this.doc, this.mapping.slice(this.curSelectionFor));
2730
+ this.curSelectionFor = this.steps.length;
2731
+ }
2732
+ return this.curSelection;
2733
+ }
2734
+ /**
2735
+ Update the transaction's current selection. Will determine the
2736
+ selection that the editor gets when the transaction is applied.
2737
+ */
2738
+ setSelection(selection) {
2739
+ if (selection.$from.doc != this.doc)
2740
+ throw new RangeError("Selection passed to setSelection must point at the current document");
2741
+ this.curSelection = selection;
2742
+ this.curSelectionFor = this.steps.length;
2743
+ this.updated = (this.updated | UPDATED_SEL) & ~UPDATED_MARKS;
2744
+ this.storedMarks = null;
2745
+ return this;
2746
+ }
2747
+ /**
2748
+ Whether the selection was explicitly updated by this transaction.
2749
+ */
2750
+ get selectionSet() {
2751
+ return (this.updated & UPDATED_SEL) > 0;
2752
+ }
2753
+ /**
2754
+ Set the current stored marks.
2755
+ */
2756
+ setStoredMarks(marks) {
2757
+ this.storedMarks = marks;
2758
+ this.updated |= UPDATED_MARKS;
2759
+ return this;
2760
+ }
2761
+ /**
2762
+ Make sure the current stored marks or, if that is null, the marks
2763
+ at the selection, match the given set of marks. Does nothing if
2764
+ this is already the case.
2765
+ */
2766
+ ensureMarks(marks) {
2767
+ if (!Mark.sameSet(this.storedMarks || this.selection.$from.marks(), marks))
2768
+ this.setStoredMarks(marks);
2769
+ return this;
2770
+ }
2771
+ /**
2772
+ Add a mark to the set of stored marks.
2773
+ */
2774
+ addStoredMark(mark) {
2775
+ return this.ensureMarks(mark.addToSet(this.storedMarks || this.selection.$head.marks()));
2776
+ }
2777
+ /**
2778
+ Remove a mark or mark type from the set of stored marks.
2779
+ */
2780
+ removeStoredMark(mark) {
2781
+ return this.ensureMarks(mark.removeFromSet(this.storedMarks || this.selection.$head.marks()));
2782
+ }
2783
+ /**
2784
+ Whether the stored marks were explicitly set for this transaction.
2785
+ */
2786
+ get storedMarksSet() {
2787
+ return (this.updated & UPDATED_MARKS) > 0;
2788
+ }
2789
+ /**
2790
+ @internal
2791
+ */
2792
+ addStep(step, doc) {
2793
+ super.addStep(step, doc);
2794
+ this.updated = this.updated & ~UPDATED_MARKS;
2795
+ this.storedMarks = null;
2796
+ }
2797
+ /**
2798
+ Update the timestamp for the transaction.
2799
+ */
2800
+ setTime(time) {
2801
+ this.time = time;
2802
+ return this;
2803
+ }
2804
+ /**
2805
+ Replace the current selection with the given slice.
2806
+ */
2807
+ replaceSelection(slice) {
2808
+ this.selection.replace(this, slice);
2809
+ return this;
2810
+ }
2811
+ /**
2812
+ Replace the selection with the given node. When `inheritMarks` is
2813
+ true and the content is inline, it inherits the marks from the
2814
+ place where it is inserted.
2815
+ */
2816
+ replaceSelectionWith(node, inheritMarks = true) {
2817
+ let selection = this.selection;
2818
+ if (inheritMarks)
2819
+ node = node.mark(this.storedMarks || (selection.empty ? selection.$from.marks() : (selection.$from.marksAcross(selection.$to) || Mark.none)));
2820
+ selection.replaceWith(this, node);
2821
+ return this;
2822
+ }
2823
+ /**
2824
+ Delete the selection.
2825
+ */
2826
+ deleteSelection() {
2827
+ this.selection.replace(this);
2828
+ return this;
2829
+ }
2830
+ /**
2831
+ Replace the given range, or the selection if no range is given,
2832
+ with a text node containing the given string.
2833
+ */
2834
+ insertText(text, from, to) {
2835
+ let schema = this.doc.type.schema;
2836
+ if (from == null) {
2837
+ if (!text)
2838
+ return this.deleteSelection();
2839
+ return this.replaceSelectionWith(schema.text(text), true);
2840
+ }
2841
+ else {
2842
+ if (to == null)
2843
+ to = from;
2844
+ if (!text)
2845
+ return this.deleteRange(from, to);
2846
+ let marks = this.storedMarks;
2847
+ if (!marks) {
2848
+ let $from = this.doc.resolve(from);
2849
+ marks = to == from ? $from.marks() : $from.marksAcross(this.doc.resolve(to));
2850
+ }
2851
+ this.replaceRangeWith(from, to, schema.text(text, marks));
2852
+ if (!this.selection.empty && this.selection.to == from + text.length)
2853
+ this.setSelection(Selection.near(this.selection.$to));
2854
+ return this;
2855
+ }
2856
+ }
2857
+ /**
2858
+ Store a metadata property in this transaction, keyed either by
2859
+ name or by plugin.
2860
+ */
2861
+ setMeta(key, value) {
2862
+ this.meta[typeof key == "string" ? key : key.key] = value;
2863
+ return this;
2864
+ }
2865
+ /**
2866
+ Retrieve a metadata property for a given name or plugin.
2867
+ */
2868
+ getMeta(key) {
2869
+ return this.meta[typeof key == "string" ? key : key.key];
2870
+ }
2871
+ /**
2872
+ Returns true if this transaction doesn't contain any metadata,
2873
+ and can thus safely be extended.
2874
+ */
2875
+ get isGeneric() {
2876
+ for (let _ in this.meta)
2877
+ return false;
2878
+ return true;
2879
+ }
2880
+ /**
2881
+ Indicate that the editor should scroll the selection into view
2882
+ when updated to the state produced by this transaction.
2883
+ */
2884
+ scrollIntoView() {
2885
+ this.updated |= UPDATED_SCROLL;
2886
+ return this;
2887
+ }
2888
+ /**
2889
+ True when this transaction has had `scrollIntoView` called on it.
2890
+ */
2891
+ get scrolledIntoView() {
2892
+ return (this.updated & UPDATED_SCROLL) > 0;
2893
+ }
2894
+ }
2895
+
2896
+ function bind(f, self) {
2897
+ return !self || !f ? f : f.bind(self);
2898
+ }
2899
+ class FieldDesc {
2900
+ constructor(name, desc, self) {
2901
+ this.name = name;
2902
+ this.init = bind(desc.init, self);
2903
+ this.apply = bind(desc.apply, self);
2904
+ }
2905
+ }
2906
+ const baseFields = [
2907
+ new FieldDesc("doc", {
2908
+ init(config) { return config.doc || config.schema.topNodeType.createAndFill(); },
2909
+ apply(tr) { return tr.doc; }
2910
+ }),
2911
+ new FieldDesc("selection", {
2912
+ init(config, instance) { return config.selection || Selection.atStart(instance.doc); },
2913
+ apply(tr) { return tr.selection; }
2914
+ }),
2915
+ new FieldDesc("storedMarks", {
2916
+ init(config) { return config.storedMarks || null; },
2917
+ apply(tr, _marks, _old, state) { return state.selection.$cursor ? tr.storedMarks : null; }
2918
+ }),
2919
+ new FieldDesc("scrollToSelection", {
2920
+ init() { return 0; },
2921
+ apply(tr, prev) { return tr.scrolledIntoView ? prev + 1 : prev; }
2922
+ })
2923
+ ];
2924
+ // Object wrapping the part of a state object that stays the same
2925
+ // across transactions. Stored in the state's `config` property.
2926
+ class Configuration {
2927
+ constructor(schema, plugins) {
2928
+ this.schema = schema;
2929
+ this.plugins = [];
2930
+ this.pluginsByKey = Object.create(null);
2931
+ this.fields = baseFields.slice();
2932
+ if (plugins)
2933
+ plugins.forEach(plugin => {
2934
+ if (this.pluginsByKey[plugin.key])
2935
+ throw new RangeError("Adding different instances of a keyed plugin (" + plugin.key + ")");
2936
+ this.plugins.push(plugin);
2937
+ this.pluginsByKey[plugin.key] = plugin;
2938
+ if (plugin.spec.state)
2939
+ this.fields.push(new FieldDesc(plugin.key, plugin.spec.state, plugin));
2940
+ });
2941
+ }
2942
+ }
2943
+ /**
2944
+ The state of a ProseMirror editor is represented by an object of
2945
+ this type. A state is a persistent data structure—it isn't
2946
+ updated, but rather a new state value is computed from an old one
2947
+ using the [`apply`](https://prosemirror.net/docs/ref/#state.EditorState.apply) method.
2948
+
2949
+ A state holds a number of built-in fields, and plugins can
2950
+ [define](https://prosemirror.net/docs/ref/#state.PluginSpec.state) additional fields.
2951
+ */
2952
+ class EditorState {
2953
+ /**
2954
+ @internal
2955
+ */
2956
+ constructor(
2957
+ /**
2958
+ @internal
2959
+ */
2960
+ config) {
2961
+ this.config = config;
2962
+ }
2963
+ /**
2964
+ The schema of the state's document.
2965
+ */
2966
+ get schema() {
2967
+ return this.config.schema;
2968
+ }
2969
+ /**
2970
+ The plugins that are active in this state.
2971
+ */
2972
+ get plugins() {
2973
+ return this.config.plugins;
2974
+ }
2975
+ /**
2976
+ Apply the given transaction to produce a new state.
2977
+ */
2978
+ apply(tr) {
2979
+ return this.applyTransaction(tr).state;
2980
+ }
2981
+ /**
2982
+ @internal
2983
+ */
2984
+ filterTransaction(tr, ignore = -1) {
2985
+ for (let i = 0; i < this.config.plugins.length; i++)
2986
+ if (i != ignore) {
2987
+ let plugin = this.config.plugins[i];
2988
+ if (plugin.spec.filterTransaction && !plugin.spec.filterTransaction.call(plugin, tr, this))
2989
+ return false;
2990
+ }
2991
+ return true;
2992
+ }
2993
+ /**
2994
+ Verbose variant of [`apply`](https://prosemirror.net/docs/ref/#state.EditorState.apply) that
2995
+ returns the precise transactions that were applied (which might
2996
+ be influenced by the [transaction
2997
+ hooks](https://prosemirror.net/docs/ref/#state.PluginSpec.filterTransaction) of
2998
+ plugins) along with the new state.
2999
+ */
3000
+ applyTransaction(rootTr) {
3001
+ if (!this.filterTransaction(rootTr))
3002
+ return { state: this, transactions: [] };
3003
+ let trs = [rootTr], newState = this.applyInner(rootTr), seen = null;
3004
+ // This loop repeatedly gives plugins a chance to respond to
3005
+ // transactions as new transactions are added, making sure to only
3006
+ // pass the transactions the plugin did not see before.
3007
+ for (;;) {
3008
+ let haveNew = false;
3009
+ for (let i = 0; i < this.config.plugins.length; i++) {
3010
+ let plugin = this.config.plugins[i];
3011
+ if (plugin.spec.appendTransaction) {
3012
+ let n = seen ? seen[i].n : 0, oldState = seen ? seen[i].state : this;
3013
+ let tr = n < trs.length &&
3014
+ plugin.spec.appendTransaction.call(plugin, n ? trs.slice(n) : trs, oldState, newState);
3015
+ if (tr && newState.filterTransaction(tr, i)) {
3016
+ tr.setMeta("appendedTransaction", rootTr);
3017
+ if (!seen) {
3018
+ seen = [];
3019
+ for (let j = 0; j < this.config.plugins.length; j++)
3020
+ seen.push(j < i ? { state: newState, n: trs.length } : { state: this, n: 0 });
3021
+ }
3022
+ trs.push(tr);
3023
+ newState = newState.applyInner(tr);
3024
+ haveNew = true;
3025
+ }
3026
+ if (seen)
3027
+ seen[i] = { state: newState, n: trs.length };
3028
+ }
3029
+ }
3030
+ if (!haveNew)
3031
+ return { state: newState, transactions: trs };
3032
+ }
3033
+ }
3034
+ /**
3035
+ @internal
3036
+ */
3037
+ applyInner(tr) {
3038
+ if (!tr.before.eq(this.doc))
3039
+ throw new RangeError("Applying a mismatched transaction");
3040
+ let newInstance = new EditorState(this.config), fields = this.config.fields;
3041
+ for (let i = 0; i < fields.length; i++) {
3042
+ let field = fields[i];
3043
+ newInstance[field.name] = field.apply(tr, this[field.name], this, newInstance);
3044
+ }
3045
+ return newInstance;
3046
+ }
3047
+ /**
3048
+ Accessor that constructs and returns a new [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state.
3049
+ */
3050
+ get tr() { return new Transaction(this); }
3051
+ /**
3052
+ Create a new state.
3053
+ */
3054
+ static create(config) {
3055
+ let $config = new Configuration(config.doc ? config.doc.type.schema : config.schema, config.plugins);
3056
+ let instance = new EditorState($config);
3057
+ for (let i = 0; i < $config.fields.length; i++)
3058
+ instance[$config.fields[i].name] = $config.fields[i].init(config, instance);
3059
+ return instance;
3060
+ }
3061
+ /**
3062
+ Create a new state based on this one, but with an adjusted set
3063
+ of active plugins. State fields that exist in both sets of
3064
+ plugins are kept unchanged. Those that no longer exist are
3065
+ dropped, and those that are new are initialized using their
3066
+ [`init`](https://prosemirror.net/docs/ref/#state.StateField.init) method, passing in the new
3067
+ configuration object..
3068
+ */
3069
+ reconfigure(config) {
3070
+ let $config = new Configuration(this.schema, config.plugins);
3071
+ let fields = $config.fields, instance = new EditorState($config);
3072
+ for (let i = 0; i < fields.length; i++) {
3073
+ let name = fields[i].name;
3074
+ instance[name] = this.hasOwnProperty(name) ? this[name] : fields[i].init(config, instance);
3075
+ }
3076
+ return instance;
3077
+ }
3078
+ /**
3079
+ Serialize this state to JSON. If you want to serialize the state
3080
+ of plugins, pass an object mapping property names to use in the
3081
+ resulting JSON object to plugin objects. The argument may also be
3082
+ a string or number, in which case it is ignored, to support the
3083
+ way `JSON.stringify` calls `toString` methods.
3084
+ */
3085
+ toJSON(pluginFields) {
3086
+ let result = { doc: this.doc.toJSON(), selection: this.selection.toJSON() };
3087
+ if (this.storedMarks)
3088
+ result.storedMarks = this.storedMarks.map(m => m.toJSON());
3089
+ if (pluginFields && typeof pluginFields == 'object')
3090
+ for (let prop in pluginFields) {
3091
+ if (prop == "doc" || prop == "selection")
3092
+ throw new RangeError("The JSON fields `doc` and `selection` are reserved");
3093
+ let plugin = pluginFields[prop], state = plugin.spec.state;
3094
+ if (state && state.toJSON)
3095
+ result[prop] = state.toJSON.call(plugin, this[plugin.key]);
3096
+ }
3097
+ return result;
3098
+ }
3099
+ /**
3100
+ Deserialize a JSON representation of a state. `config` should
3101
+ have at least a `schema` field, and should contain array of
3102
+ plugins to initialize the state with. `pluginFields` can be used
3103
+ to deserialize the state of plugins, by associating plugin
3104
+ instances with the property names they use in the JSON object.
3105
+ */
3106
+ static fromJSON(config, json, pluginFields) {
3107
+ if (!json)
3108
+ throw new RangeError("Invalid input for EditorState.fromJSON");
3109
+ if (!config.schema)
3110
+ throw new RangeError("Required config field 'schema' missing");
3111
+ let $config = new Configuration(config.schema, config.plugins);
3112
+ let instance = new EditorState($config);
3113
+ $config.fields.forEach(field => {
3114
+ if (field.name == "doc") {
3115
+ instance.doc = Node.fromJSON(config.schema, json.doc);
3116
+ }
3117
+ else if (field.name == "selection") {
3118
+ instance.selection = Selection.fromJSON(instance.doc, json.selection);
3119
+ }
3120
+ else if (field.name == "storedMarks") {
3121
+ if (json.storedMarks)
3122
+ instance.storedMarks = json.storedMarks.map(config.schema.markFromJSON);
3123
+ }
3124
+ else {
3125
+ if (pluginFields)
3126
+ for (let prop in pluginFields) {
3127
+ let plugin = pluginFields[prop], state = plugin.spec.state;
3128
+ if (plugin.key == field.name && state && state.fromJSON &&
3129
+ Object.prototype.hasOwnProperty.call(json, prop)) {
3130
+ instance[field.name] = state.fromJSON.call(plugin, config, json[prop], instance);
3131
+ return;
3132
+ }
3133
+ }
3134
+ instance[field.name] = field.init(config, instance);
3135
+ }
3136
+ });
3137
+ return instance;
3138
+ }
3139
+ }
3140
+
3141
+ function bindProps(obj, self, target) {
3142
+ for (let prop in obj) {
3143
+ let val = obj[prop];
3144
+ if (val instanceof Function)
3145
+ val = val.bind(self);
3146
+ else if (prop == "handleDOMEvents")
3147
+ val = bindProps(val, self, {});
3148
+ target[prop] = val;
3149
+ }
3150
+ return target;
3151
+ }
3152
+ /**
3153
+ Plugins bundle functionality that can be added to an editor.
3154
+ They are part of the [editor state](https://prosemirror.net/docs/ref/#state.EditorState) and
3155
+ may influence that state and the view that contains it.
3156
+ */
3157
+ class Plugin {
3158
+ /**
3159
+ Create a plugin.
3160
+ */
3161
+ constructor(
3162
+ /**
3163
+ The plugin's [spec object](https://prosemirror.net/docs/ref/#state.PluginSpec).
3164
+ */
3165
+ spec) {
3166
+ this.spec = spec;
3167
+ /**
3168
+ The [props](https://prosemirror.net/docs/ref/#view.EditorProps) exported by this plugin.
3169
+ */
3170
+ this.props = {};
3171
+ if (spec.props)
3172
+ bindProps(spec.props, this, this.props);
3173
+ this.key = spec.key ? spec.key.key : createKey("plugin");
3174
+ }
3175
+ /**
3176
+ Extract the plugin's state field from an editor state.
3177
+ */
3178
+ getState(state) { return state[this.key]; }
3179
+ }
3180
+ const keys = Object.create(null);
3181
+ function createKey(name) {
3182
+ if (name in keys)
3183
+ return name + "$" + ++keys[name];
3184
+ keys[name] = 0;
3185
+ return name + "$";
3186
+ }
3187
+ /**
3188
+ A key is used to [tag](https://prosemirror.net/docs/ref/#state.PluginSpec.key) plugins in a way
3189
+ that makes it possible to find them, given an editor state.
3190
+ Assigning a key does mean only one plugin of that type can be
3191
+ active in a state.
3192
+ */
3193
+ class PluginKey {
3194
+ /**
3195
+ Create a plugin key.
3196
+ */
3197
+ constructor(name = "key") { this.key = createKey(name); }
3198
+ /**
3199
+ Get the active plugin with this key, if any, from an editor
3200
+ state.
3201
+ */
3202
+ get(state) { return state.config.pluginsByKey[this.key]; }
3203
+ /**
3204
+ Get the plugin's state from an editor state.
3205
+ */
3206
+ getState(state) { return state[this.key]; }
3207
+ }
3208
+
3209
+ export { AllSelection as A, EditorState as E, Mapping as M, NodeSelection as N, Plugin as P, ReplaceStep as R, Selection as S, TextSelection as T, canJoin as a, ReplaceAroundStep as b, canSplit as c, dropPoint as d, Transform as e, findWrapping as f, PluginKey as g, RemoveMarkStep as h, SelectionRange as i, joinPoint as j, liftTarget as l, replaceStep as r };
3210
+ //# sourceMappingURL=chunk-DN9pYQV5.js.map