prosemirror-transform 1.7.1 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 1.7.3 (2023-06-01)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a bug in `canSplit` that made it interpret the `typesAfter` argument incorrectly on splits of depth greater than 1.
6
+
7
+ ## 1.7.2 (2023-05-17)
8
+
9
+ ### Bug fixes
10
+
11
+ Include CommonJS type declarations in the package to please new TypeScript resolution settings.
12
+
1
13
  ## 1.7.1 (2023-01-20)
2
14
 
3
15
  ### Bug fixes
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2015-2017 by Marijn Haverbeke <marijnh@gmail.com> and others
1
+ Copyright (C) 2015-2017 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.cjs CHANGED
@@ -1153,8 +1153,9 @@ function canSplit(doc, pos) {
1153
1153
 
1154
1154
  if (node.type.spec.isolating) return false;
1155
1155
  var rest = node.content.cutByIndex(_index, node.childCount);
1156
+ var overrideChild = typesAfter && typesAfter[i + 1];
1157
+ if (overrideChild) rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs));
1156
1158
  var after = typesAfter && typesAfter[i] || node;
1157
- if (after != node) rest = rest.replaceChild(0, after.type.create(after.attrs));
1158
1159
  if (!node.canReplace(_index + 1, node.childCount) || !after.type.validContent(rest)) return false;
1159
1160
  }
1160
1161
 
@@ -0,0 +1,809 @@
1
+ import { Node, Schema, Slice, Fragment, NodeRange, NodeType, Attrs, Mark, MarkType, ContentMatch } from 'prosemirror-model';
2
+
3
+ /**
4
+ There are several things that positions can be mapped through.
5
+ Such objects conform to this interface.
6
+ */
7
+ interface Mappable {
8
+ /**
9
+ Map a position through this object. When given, `assoc` (should
10
+ be -1 or 1, defaults to 1) determines with which side the
11
+ position is associated, which determines in which direction to
12
+ move when a chunk of content is inserted at the mapped position.
13
+ */
14
+ map: (pos: number, assoc?: number) => number;
15
+ /**
16
+ Map a position, and return an object containing additional
17
+ information about the mapping. The result's `deleted` field tells
18
+ you whether the position was deleted (completely enclosed in a
19
+ replaced range) during the mapping. When content on only one side
20
+ is deleted, the position itself is only considered deleted when
21
+ `assoc` points in the direction of the deleted content.
22
+ */
23
+ mapResult: (pos: number, assoc?: number) => MapResult;
24
+ }
25
+ /**
26
+ An object representing a mapped position with extra
27
+ information.
28
+ */
29
+ declare class MapResult {
30
+ /**
31
+ The mapped version of the position.
32
+ */
33
+ readonly pos: number;
34
+ /**
35
+ Tells you whether the position was deleted, that is, whether the
36
+ step removed the token on the side queried (via the `assoc`)
37
+ argument from the document.
38
+ */
39
+ get deleted(): boolean;
40
+ /**
41
+ Tells you whether the token before the mapped position was deleted.
42
+ */
43
+ get deletedBefore(): boolean;
44
+ /**
45
+ True when the token after the mapped position was deleted.
46
+ */
47
+ get deletedAfter(): boolean;
48
+ /**
49
+ Tells whether any of the steps mapped through deletes across the
50
+ position (including both the token before and after the
51
+ position).
52
+ */
53
+ get deletedAcross(): boolean;
54
+ }
55
+ /**
56
+ A map describing the deletions and insertions made by a step, which
57
+ can be used to find the correspondence between positions in the
58
+ pre-step version of a document and the same position in the
59
+ post-step version.
60
+ */
61
+ declare class StepMap implements Mappable {
62
+ /**
63
+ Create a position map. The modifications to the document are
64
+ represented as an array of numbers, in which each group of three
65
+ represents a modified chunk as `[start, oldSize, newSize]`.
66
+ */
67
+ constructor(
68
+ /**
69
+ @internal
70
+ */
71
+ ranges: readonly number[],
72
+ /**
73
+ @internal
74
+ */
75
+ inverted?: boolean);
76
+ mapResult(pos: number, assoc?: number): MapResult;
77
+ map(pos: number, assoc?: number): number;
78
+ /**
79
+ Calls the given function on each of the changed ranges included in
80
+ this map.
81
+ */
82
+ forEach(f: (oldStart: number, oldEnd: number, newStart: number, newEnd: number) => void): void;
83
+ /**
84
+ Create an inverted version of this map. The result can be used to
85
+ map positions in the post-step document to the pre-step document.
86
+ */
87
+ invert(): StepMap;
88
+ /**
89
+ Create a map that moves all positions by offset `n` (which may be
90
+ negative). This can be useful when applying steps meant for a
91
+ sub-document to a larger document, or vice-versa.
92
+ */
93
+ static offset(n: number): StepMap;
94
+ /**
95
+ A StepMap that contains no changed ranges.
96
+ */
97
+ static empty: StepMap;
98
+ }
99
+ /**
100
+ A mapping represents a pipeline of zero or more [step
101
+ maps](https://prosemirror.net/docs/ref/#transform.StepMap). It has special provisions for losslessly
102
+ handling mapping positions through a series of steps in which some
103
+ steps are inverted versions of earlier steps. (This comes up when
104
+ ‘[rebasing](/docs/guide/#transform.rebasing)’ steps for
105
+ collaboration or history management.)
106
+ */
107
+ declare class Mapping implements Mappable {
108
+ /**
109
+ The step maps in this mapping.
110
+ */
111
+ readonly maps: StepMap[];
112
+ /**
113
+ The starting position in the `maps` array, used when `map` or
114
+ `mapResult` is called.
115
+ */
116
+ from: number;
117
+ /**
118
+ The end position in the `maps` array.
119
+ */
120
+ to: number;
121
+ /**
122
+ Create a new mapping with the given position maps.
123
+ */
124
+ constructor(
125
+ /**
126
+ The step maps in this mapping.
127
+ */
128
+ maps?: StepMap[],
129
+ /**
130
+ @internal
131
+ */
132
+ mirror?: number[] | undefined,
133
+ /**
134
+ The starting position in the `maps` array, used when `map` or
135
+ `mapResult` is called.
136
+ */
137
+ from?: number,
138
+ /**
139
+ The end position in the `maps` array.
140
+ */
141
+ to?: number);
142
+ /**
143
+ Create a mapping that maps only through a part of this one.
144
+ */
145
+ slice(from?: number, to?: number): Mapping;
146
+ /**
147
+ Add a step map to the end of this mapping. If `mirrors` is
148
+ given, it should be the index of the step map that is the mirror
149
+ image of this one.
150
+ */
151
+ appendMap(map: StepMap, mirrors?: number): void;
152
+ /**
153
+ Add all the step maps in a given mapping to this one (preserving
154
+ mirroring information).
155
+ */
156
+ appendMapping(mapping: Mapping): void;
157
+ /**
158
+ Finds the offset of the step map that mirrors the map at the
159
+ given offset, in this mapping (as per the second argument to
160
+ `appendMap`).
161
+ */
162
+ getMirror(n: number): number | undefined;
163
+ /**
164
+ Append the inverse of the given mapping to this one.
165
+ */
166
+ appendMappingInverted(mapping: Mapping): void;
167
+ /**
168
+ Create an inverted version of this mapping.
169
+ */
170
+ invert(): Mapping;
171
+ /**
172
+ Map a position through this mapping.
173
+ */
174
+ map(pos: number, assoc?: number): number;
175
+ /**
176
+ Map a position through this mapping, returning a mapping
177
+ result.
178
+ */
179
+ mapResult(pos: number, assoc?: number): MapResult;
180
+ }
181
+
182
+ /**
183
+ A step object represents an atomic change. It generally applies
184
+ only to the document it was created for, since the positions
185
+ stored in it will only make sense for that document.
186
+
187
+ New steps are defined by creating classes that extend `Step`,
188
+ overriding the `apply`, `invert`, `map`, `getMap` and `fromJSON`
189
+ methods, and registering your class with a unique
190
+ JSON-serialization identifier using
191
+ [`Step.jsonID`](https://prosemirror.net/docs/ref/#transform.Step^jsonID).
192
+ */
193
+ declare abstract class Step {
194
+ /**
195
+ Applies this step to the given document, returning a result
196
+ object that either indicates failure, if the step can not be
197
+ applied to this document, or indicates success by containing a
198
+ transformed document.
199
+ */
200
+ abstract apply(doc: Node): StepResult;
201
+ /**
202
+ Get the step map that represents the changes made by this step,
203
+ and which can be used to transform between positions in the old
204
+ and the new document.
205
+ */
206
+ getMap(): StepMap;
207
+ /**
208
+ Create an inverted version of this step. Needs the document as it
209
+ was before the step as argument.
210
+ */
211
+ abstract invert(doc: Node): Step;
212
+ /**
213
+ Map this step through a mappable thing, returning either a
214
+ version of that step with its positions adjusted, or `null` if
215
+ the step was entirely deleted by the mapping.
216
+ */
217
+ abstract map(mapping: Mappable): Step | null;
218
+ /**
219
+ Try to merge this step with another one, to be applied directly
220
+ after it. Returns the merged step when possible, null if the
221
+ steps can't be merged.
222
+ */
223
+ merge(other: Step): Step | null;
224
+ /**
225
+ Create a JSON-serializeable representation of this step. When
226
+ defining this for a custom subclass, make sure the result object
227
+ includes the step type's [JSON id](https://prosemirror.net/docs/ref/#transform.Step^jsonID) under
228
+ the `stepType` property.
229
+ */
230
+ abstract toJSON(): any;
231
+ /**
232
+ Deserialize a step from its JSON representation. Will call
233
+ through to the step class' own implementation of this method.
234
+ */
235
+ static fromJSON(schema: Schema, json: any): Step;
236
+ /**
237
+ To be able to serialize steps to JSON, each step needs a string
238
+ ID to attach to its JSON representation. Use this method to
239
+ register an ID for your step classes. Try to pick something
240
+ that's unlikely to clash with steps from other modules.
241
+ */
242
+ static jsonID(id: string, stepClass: {
243
+ fromJSON(schema: Schema, json: any): Step;
244
+ }): {
245
+ fromJSON(schema: Schema, json: any): Step;
246
+ };
247
+ }
248
+ /**
249
+ The result of [applying](https://prosemirror.net/docs/ref/#transform.Step.apply) a step. Contains either a
250
+ new document or a failure value.
251
+ */
252
+ declare class StepResult {
253
+ /**
254
+ The transformed document, if successful.
255
+ */
256
+ readonly doc: Node | null;
257
+ /**
258
+ The failure message, if unsuccessful.
259
+ */
260
+ readonly failed: string | null;
261
+ /**
262
+ Create a successful step result.
263
+ */
264
+ static ok(doc: Node): StepResult;
265
+ /**
266
+ Create a failed step result.
267
+ */
268
+ static fail(message: string): StepResult;
269
+ /**
270
+ Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given
271
+ arguments. Create a successful result if it succeeds, and a
272
+ failed one if it throws a `ReplaceError`.
273
+ */
274
+ static fromReplace(doc: Node, from: number, to: number, slice: Slice): StepResult;
275
+ }
276
+
277
+ /**
278
+ Abstraction to build up and track an array of
279
+ [steps](https://prosemirror.net/docs/ref/#transform.Step) representing a document transformation.
280
+
281
+ Most transforming methods return the `Transform` object itself, so
282
+ that they can be chained.
283
+ */
284
+ declare class Transform {
285
+ /**
286
+ The current document (the result of applying the steps in the
287
+ transform).
288
+ */
289
+ doc: Node;
290
+ /**
291
+ The steps in this transform.
292
+ */
293
+ readonly steps: Step[];
294
+ /**
295
+ The documents before each of the steps.
296
+ */
297
+ readonly docs: Node[];
298
+ /**
299
+ A mapping with the maps for each of the steps in this transform.
300
+ */
301
+ readonly mapping: Mapping;
302
+ /**
303
+ Create a transform that starts with the given document.
304
+ */
305
+ constructor(
306
+ /**
307
+ The current document (the result of applying the steps in the
308
+ transform).
309
+ */
310
+ doc: Node);
311
+ /**
312
+ The starting document.
313
+ */
314
+ get before(): Node;
315
+ /**
316
+ Apply a new step in this transform, saving the result. Throws an
317
+ error when the step fails.
318
+ */
319
+ step(step: Step): this;
320
+ /**
321
+ Try to apply a step in this transformation, ignoring it if it
322
+ fails. Returns the step result.
323
+ */
324
+ maybeStep(step: Step): StepResult;
325
+ /**
326
+ True when the document has been changed (when there are any
327
+ steps).
328
+ */
329
+ get docChanged(): boolean;
330
+ /**
331
+ Replace the part of the document between `from` and `to` with the
332
+ given `slice`.
333
+ */
334
+ replace(from: number, to?: number, slice?: Slice): this;
335
+ /**
336
+ Replace the given range with the given content, which may be a
337
+ fragment, node, or array of nodes.
338
+ */
339
+ replaceWith(from: number, to: number, content: Fragment | Node | readonly Node[]): this;
340
+ /**
341
+ Delete the content between the given positions.
342
+ */
343
+ delete(from: number, to: number): this;
344
+ /**
345
+ Insert the given content at the given position.
346
+ */
347
+ insert(pos: number, content: Fragment | Node | readonly Node[]): this;
348
+ /**
349
+ Replace a range of the document with a given slice, using
350
+ `from`, `to`, and the slice's
351
+ [`openStart`](https://prosemirror.net/docs/ref/#model.Slice.openStart) property as hints, rather
352
+ than fixed start and end points. This method may grow the
353
+ replaced area or close open nodes in the slice in order to get a
354
+ fit that is more in line with WYSIWYG expectations, by dropping
355
+ fully covered parent nodes of the replaced region when they are
356
+ marked [non-defining as
357
+ context](https://prosemirror.net/docs/ref/#model.NodeSpec.definingAsContext), or including an
358
+ open parent node from the slice that _is_ marked as [defining
359
+ its content](https://prosemirror.net/docs/ref/#model.NodeSpec.definingForContent).
360
+
361
+ This is the method, for example, to handle paste. The similar
362
+ [`replace`](https://prosemirror.net/docs/ref/#transform.Transform.replace) method is a more
363
+ primitive tool which will _not_ move the start and end of its given
364
+ range, and is useful in situations where you need more precise
365
+ control over what happens.
366
+ */
367
+ replaceRange(from: number, to: number, slice: Slice): this;
368
+ /**
369
+ Replace the given range with a node, but use `from` and `to` as
370
+ hints, rather than precise positions. When from and to are the same
371
+ and are at the start or end of a parent node in which the given
372
+ node doesn't fit, this method may _move_ them out towards a parent
373
+ that does allow the given node to be placed. When the given range
374
+ completely covers a parent node, this method may completely replace
375
+ that parent node.
376
+ */
377
+ replaceRangeWith(from: number, to: number, node: Node): this;
378
+ /**
379
+ Delete the given range, expanding it to cover fully covered
380
+ parent nodes until a valid replace is found.
381
+ */
382
+ deleteRange(from: number, to: number): this;
383
+ /**
384
+ Split the content in the given range off from its parent, if there
385
+ is sibling content before or after it, and move it up the tree to
386
+ the depth specified by `target`. You'll probably want to use
387
+ [`liftTarget`](https://prosemirror.net/docs/ref/#transform.liftTarget) to compute `target`, to make
388
+ sure the lift is valid.
389
+ */
390
+ lift(range: NodeRange, target: number): this;
391
+ /**
392
+ Join the blocks around the given position. If depth is 2, their
393
+ last and first siblings are also joined, and so on.
394
+ */
395
+ join(pos: number, depth?: number): this;
396
+ /**
397
+ Wrap the given [range](https://prosemirror.net/docs/ref/#model.NodeRange) in the given set of wrappers.
398
+ The wrappers are assumed to be valid in this position, and should
399
+ probably be computed with [`findWrapping`](https://prosemirror.net/docs/ref/#transform.findWrapping).
400
+ */
401
+ wrap(range: NodeRange, wrappers: readonly {
402
+ type: NodeType;
403
+ attrs?: Attrs | null;
404
+ }[]): this;
405
+ /**
406
+ Set the type of all textblocks (partly) between `from` and `to` to
407
+ the given node type with the given attributes.
408
+ */
409
+ setBlockType(from: number, to: number | undefined, type: NodeType, attrs?: Attrs | null): this;
410
+ /**
411
+ Change the type, attributes, and/or marks of the node at `pos`.
412
+ When `type` isn't given, the existing node type is preserved,
413
+ */
414
+ setNodeMarkup(pos: number, type?: NodeType | null, attrs?: Attrs | null, marks?: readonly Mark[]): this;
415
+ /**
416
+ Set a single attribute on a given node to a new value.
417
+ */
418
+ setNodeAttribute(pos: number, attr: string, value: any): this;
419
+ /**
420
+ Add a mark to the node at position `pos`.
421
+ */
422
+ addNodeMark(pos: number, mark: Mark): this;
423
+ /**
424
+ Remove a mark (or a mark of the given type) from the node at
425
+ position `pos`.
426
+ */
427
+ removeNodeMark(pos: number, mark: Mark | MarkType): this;
428
+ /**
429
+ Split the node at the given position, and optionally, if `depth` is
430
+ greater than one, any number of nodes above that. By default, the
431
+ parts split off will inherit the node type of the original node.
432
+ This can be changed by passing an array of types and attributes to
433
+ use after the split.
434
+ */
435
+ split(pos: number, depth?: number, typesAfter?: (null | {
436
+ type: NodeType;
437
+ attrs?: Attrs | null;
438
+ })[]): this;
439
+ /**
440
+ Add the given mark to the inline content between `from` and `to`.
441
+ */
442
+ addMark(from: number, to: number, mark: Mark): this;
443
+ /**
444
+ Remove marks from inline nodes between `from` and `to`. When
445
+ `mark` is a single mark, remove precisely that mark. When it is
446
+ a mark type, remove all marks of that type. When it is null,
447
+ remove all marks of any type.
448
+ */
449
+ removeMark(from: number, to: number, mark?: Mark | MarkType | null): this;
450
+ /**
451
+ Removes all marks and nodes from the content of the node at
452
+ `pos` that don't match the given new parent node type. Accepts
453
+ an optional starting [content match](https://prosemirror.net/docs/ref/#model.ContentMatch) as
454
+ third argument.
455
+ */
456
+ clearIncompatible(pos: number, parentType: NodeType, match?: ContentMatch): this;
457
+ }
458
+
459
+ /**
460
+ Try to find a target depth to which the content in the given range
461
+ can be lifted. Will not go across
462
+ [isolating](https://prosemirror.net/docs/ref/#model.NodeSpec.isolating) parent nodes.
463
+ */
464
+ declare function liftTarget(range: NodeRange): number | null;
465
+ /**
466
+ Try to find a valid way to wrap the content in the given range in a
467
+ node of the given type. May introduce extra nodes around and inside
468
+ the wrapper node, if necessary. Returns null if no valid wrapping
469
+ could be found. When `innerRange` is given, that range's content is
470
+ used as the content to fit into the wrapping, instead of the
471
+ content of `range`.
472
+ */
473
+ declare function findWrapping(range: NodeRange, nodeType: NodeType, attrs?: Attrs | null, innerRange?: NodeRange): {
474
+ type: NodeType;
475
+ attrs: Attrs | null;
476
+ }[] | null;
477
+ /**
478
+ Check whether splitting at the given position is allowed.
479
+ */
480
+ declare function canSplit(doc: Node, pos: number, depth?: number, typesAfter?: (null | {
481
+ type: NodeType;
482
+ attrs?: Attrs | null;
483
+ })[]): boolean;
484
+ /**
485
+ Test whether the blocks before and after a given position can be
486
+ joined.
487
+ */
488
+ declare function canJoin(doc: Node, pos: number): boolean;
489
+ /**
490
+ Find an ancestor of the given position that can be joined to the
491
+ block before (or after if `dir` is positive). Returns the joinable
492
+ point, if any.
493
+ */
494
+ declare function joinPoint(doc: Node, pos: number, dir?: number): number | undefined;
495
+ /**
496
+ Try to find a point where a node of the given type can be inserted
497
+ near `pos`, by searching up the node hierarchy when `pos` itself
498
+ isn't a valid place but is at the start or end of a node. Return
499
+ null if no position was found.
500
+ */
501
+ declare function insertPoint(doc: Node, pos: number, nodeType: NodeType): number | null;
502
+ /**
503
+ Finds a position at or around the given position where the given
504
+ slice can be inserted. Will look at parent nodes' nearest boundary
505
+ and try there, even if the original position wasn't directly at the
506
+ start or end of that node. Returns null when no position was found.
507
+ */
508
+ declare function dropPoint(doc: Node, pos: number, slice: Slice): number | null;
509
+
510
+ /**
511
+ Add a mark to all inline content between two positions.
512
+ */
513
+ declare class AddMarkStep extends Step {
514
+ /**
515
+ The start of the marked range.
516
+ */
517
+ readonly from: number;
518
+ /**
519
+ The end of the marked range.
520
+ */
521
+ readonly to: number;
522
+ /**
523
+ The mark to add.
524
+ */
525
+ readonly mark: Mark;
526
+ /**
527
+ Create a mark step.
528
+ */
529
+ constructor(
530
+ /**
531
+ The start of the marked range.
532
+ */
533
+ from: number,
534
+ /**
535
+ The end of the marked range.
536
+ */
537
+ to: number,
538
+ /**
539
+ The mark to add.
540
+ */
541
+ mark: Mark);
542
+ apply(doc: Node): StepResult;
543
+ invert(): Step;
544
+ map(mapping: Mappable): Step | null;
545
+ merge(other: Step): Step | null;
546
+ toJSON(): any;
547
+ }
548
+ /**
549
+ Remove a mark from all inline content between two positions.
550
+ */
551
+ declare class RemoveMarkStep extends Step {
552
+ /**
553
+ The start of the unmarked range.
554
+ */
555
+ readonly from: number;
556
+ /**
557
+ The end of the unmarked range.
558
+ */
559
+ readonly to: number;
560
+ /**
561
+ The mark to remove.
562
+ */
563
+ readonly mark: Mark;
564
+ /**
565
+ Create a mark-removing step.
566
+ */
567
+ constructor(
568
+ /**
569
+ The start of the unmarked range.
570
+ */
571
+ from: number,
572
+ /**
573
+ The end of the unmarked range.
574
+ */
575
+ to: number,
576
+ /**
577
+ The mark to remove.
578
+ */
579
+ mark: Mark);
580
+ apply(doc: Node): StepResult;
581
+ invert(): Step;
582
+ map(mapping: Mappable): Step | null;
583
+ merge(other: Step): Step | null;
584
+ toJSON(): any;
585
+ }
586
+ /**
587
+ Add a mark to a specific node.
588
+ */
589
+ declare class AddNodeMarkStep extends Step {
590
+ /**
591
+ The position of the target node.
592
+ */
593
+ readonly pos: number;
594
+ /**
595
+ The mark to add.
596
+ */
597
+ readonly mark: Mark;
598
+ /**
599
+ Create a node mark step.
600
+ */
601
+ constructor(
602
+ /**
603
+ The position of the target node.
604
+ */
605
+ pos: number,
606
+ /**
607
+ The mark to add.
608
+ */
609
+ mark: Mark);
610
+ apply(doc: Node): StepResult;
611
+ invert(doc: Node): Step;
612
+ map(mapping: Mappable): Step | null;
613
+ toJSON(): any;
614
+ }
615
+ /**
616
+ Remove a mark from a specific node.
617
+ */
618
+ declare class RemoveNodeMarkStep extends Step {
619
+ /**
620
+ The position of the target node.
621
+ */
622
+ readonly pos: number;
623
+ /**
624
+ The mark to remove.
625
+ */
626
+ readonly mark: Mark;
627
+ /**
628
+ Create a mark-removing step.
629
+ */
630
+ constructor(
631
+ /**
632
+ The position of the target node.
633
+ */
634
+ pos: number,
635
+ /**
636
+ The mark to remove.
637
+ */
638
+ mark: Mark);
639
+ apply(doc: Node): StepResult;
640
+ invert(doc: Node): Step;
641
+ map(mapping: Mappable): Step | null;
642
+ toJSON(): any;
643
+ }
644
+
645
+ /**
646
+ Replace a part of the document with a slice of new content.
647
+ */
648
+ declare class ReplaceStep extends Step {
649
+ /**
650
+ The start position of the replaced range.
651
+ */
652
+ readonly from: number;
653
+ /**
654
+ The end position of the replaced range.
655
+ */
656
+ readonly to: number;
657
+ /**
658
+ The slice to insert.
659
+ */
660
+ readonly slice: Slice;
661
+ /**
662
+ The given `slice` should fit the 'gap' between `from` and
663
+ `to`—the depths must line up, and the surrounding nodes must be
664
+ able to be joined with the open sides of the slice. When
665
+ `structure` is true, the step will fail if the content between
666
+ from and to is not just a sequence of closing and then opening
667
+ tokens (this is to guard against rebased replace steps
668
+ overwriting something they weren't supposed to).
669
+ */
670
+ constructor(
671
+ /**
672
+ The start position of the replaced range.
673
+ */
674
+ from: number,
675
+ /**
676
+ The end position of the replaced range.
677
+ */
678
+ to: number,
679
+ /**
680
+ The slice to insert.
681
+ */
682
+ slice: Slice,
683
+ /**
684
+ @internal
685
+ */
686
+ structure?: boolean);
687
+ apply(doc: Node): StepResult;
688
+ getMap(): StepMap;
689
+ invert(doc: Node): ReplaceStep;
690
+ map(mapping: Mappable): ReplaceStep | null;
691
+ merge(other: Step): ReplaceStep | null;
692
+ toJSON(): any;
693
+ }
694
+ /**
695
+ Replace a part of the document with a slice of content, but
696
+ preserve a range of the replaced content by moving it into the
697
+ slice.
698
+ */
699
+ declare class ReplaceAroundStep extends Step {
700
+ /**
701
+ The start position of the replaced range.
702
+ */
703
+ readonly from: number;
704
+ /**
705
+ The end position of the replaced range.
706
+ */
707
+ readonly to: number;
708
+ /**
709
+ The start of preserved range.
710
+ */
711
+ readonly gapFrom: number;
712
+ /**
713
+ The end of preserved range.
714
+ */
715
+ readonly gapTo: number;
716
+ /**
717
+ The slice to insert.
718
+ */
719
+ readonly slice: Slice;
720
+ /**
721
+ The position in the slice where the preserved range should be
722
+ inserted.
723
+ */
724
+ readonly insert: number;
725
+ /**
726
+ Create a replace-around step with the given range and gap.
727
+ `insert` should be the point in the slice into which the content
728
+ of the gap should be moved. `structure` has the same meaning as
729
+ it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class.
730
+ */
731
+ constructor(
732
+ /**
733
+ The start position of the replaced range.
734
+ */
735
+ from: number,
736
+ /**
737
+ The end position of the replaced range.
738
+ */
739
+ to: number,
740
+ /**
741
+ The start of preserved range.
742
+ */
743
+ gapFrom: number,
744
+ /**
745
+ The end of preserved range.
746
+ */
747
+ gapTo: number,
748
+ /**
749
+ The slice to insert.
750
+ */
751
+ slice: Slice,
752
+ /**
753
+ The position in the slice where the preserved range should be
754
+ inserted.
755
+ */
756
+ insert: number,
757
+ /**
758
+ @internal
759
+ */
760
+ structure?: boolean);
761
+ apply(doc: Node): StepResult;
762
+ getMap(): StepMap;
763
+ invert(doc: Node): ReplaceAroundStep;
764
+ map(mapping: Mappable): ReplaceAroundStep | null;
765
+ toJSON(): any;
766
+ }
767
+
768
+ /**
769
+ Update an attribute in a specific node.
770
+ */
771
+ declare class AttrStep extends Step {
772
+ /**
773
+ The position of the target node.
774
+ */
775
+ readonly pos: number;
776
+ /**
777
+ The attribute to set.
778
+ */
779
+ readonly attr: string;
780
+ readonly value: any;
781
+ /**
782
+ Construct an attribute step.
783
+ */
784
+ constructor(
785
+ /**
786
+ The position of the target node.
787
+ */
788
+ pos: number,
789
+ /**
790
+ The attribute to set.
791
+ */
792
+ attr: string, value: any);
793
+ apply(doc: Node): StepResult;
794
+ getMap(): StepMap;
795
+ invert(doc: Node): AttrStep;
796
+ map(mapping: Mappable): AttrStep | null;
797
+ toJSON(): any;
798
+ static fromJSON(schema: Schema, json: any): AttrStep;
799
+ }
800
+
801
+ /**
802
+ ‘Fit’ a slice into a given position in the document, producing a
803
+ [step](https://prosemirror.net/docs/ref/#transform.Step) that inserts it. Will return null if
804
+ there's no meaningful way to insert the slice here, or inserting it
805
+ would be a no-op (an empty slice over an empty range).
806
+ */
807
+ declare function replaceStep(doc: Node, from: number, to?: number, slice?: Slice): Step | null;
808
+
809
+ export { AddMarkStep, AddNodeMarkStep, AttrStep, MapResult, Mappable, Mapping, RemoveMarkStep, RemoveNodeMarkStep, ReplaceAroundStep, ReplaceStep, Step, StepMap, StepResult, Transform, canJoin, canSplit, dropPoint, findWrapping, insertPoint, joinPoint, liftTarget, replaceStep };
package/dist/index.js CHANGED
@@ -1112,9 +1112,10 @@ function canSplit(doc, pos, depth = 1, typesAfter) {
1112
1112
  if (node.type.spec.isolating)
1113
1113
  return false;
1114
1114
  let rest = node.content.cutByIndex(index, node.childCount);
1115
+ let overrideChild = typesAfter && typesAfter[i + 1];
1116
+ if (overrideChild)
1117
+ rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs));
1115
1118
  let after = (typesAfter && typesAfter[i]) || node;
1116
- if (after != node)
1117
- rest = rest.replaceChild(0, after.type.create(after.attrs));
1118
1119
  if (!node.canReplace(index + 1, node.childCount) || !after.type.validContent(rest))
1119
1120
  return false;
1120
1121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-transform",
3
- "version": "1.7.1",
3
+ "version": "1.7.3",
4
4
  "description": "ProseMirror document transformations",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -15,7 +15,7 @@
15
15
  "maintainers": [
16
16
  {
17
17
  "name": "Marijn Haverbeke",
18
- "email": "marijnh@gmail.com",
18
+ "email": "marijn@haverbeke.berlin",
19
19
  "web": "http://marijnhaverbeke.nl"
20
20
  }
21
21
  ],
package/src/structure.ts CHANGED
@@ -163,8 +163,10 @@ export function canSplit(doc: Node, pos: number, depth = 1,
163
163
  let node = $pos.node(d), index = $pos.index(d)
164
164
  if (node.type.spec.isolating) return false
165
165
  let rest = node.content.cutByIndex(index, node.childCount)
166
+ let overrideChild = typesAfter && typesAfter[i + 1]
167
+ if (overrideChild)
168
+ rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs))
166
169
  let after = (typesAfter && typesAfter[i]) || node
167
- if (after != node) rest = rest.replaceChild(0, after.type.create(after.attrs))
168
170
  if (!node.canReplace(index + 1, node.childCount) || !after.type.validContent(rest))
169
171
  return false
170
172
  }