prosemirror-transform 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/index.es.js +26 -8
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +26 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/map.js +3 -0
- package/src/replace.js +15 -6
- package/src/structure.js +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## 1.4.0 (2022-03-21)
|
|
2
|
+
|
|
3
|
+
### New features
|
|
4
|
+
|
|
5
|
+
Node specs can now use the `definingForContent` and `definingAsContext` properties to opt in to specific parts of the existing `defining` behavior.
|
|
6
|
+
|
|
7
|
+
## 1.3.4 (2022-02-04)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
Make sure that constructing an empty `StepMap` returns `StepMap.empty`.
|
|
12
|
+
|
|
13
|
+
## 1.3.3 (2021-09-29)
|
|
14
|
+
|
|
15
|
+
### Bug fixes
|
|
16
|
+
|
|
17
|
+
Fix an inconsistency in `deleteRange` where it would delete the parent node for ranges covering all textblocks in a given parent.
|
|
18
|
+
|
|
1
19
|
## 1.3.2 (2021-04-06)
|
|
2
20
|
|
|
3
21
|
### Bug fixes
|
package/dist/index.es.js
CHANGED
|
@@ -57,6 +57,7 @@ var MapResult = function MapResult(pos, deleted, recover) {
|
|
|
57
57
|
var StepMap = function StepMap(ranges, inverted) {
|
|
58
58
|
if ( inverted === void 0 ) inverted = false;
|
|
59
59
|
|
|
60
|
+
if (!ranges.length && StepMap.empty) { return StepMap.empty }
|
|
60
61
|
this.ranges = ranges;
|
|
61
62
|
this.inverted = inverted;
|
|
62
63
|
};
|
|
@@ -141,6 +142,8 @@ StepMap.offset = function offset (n) {
|
|
|
141
142
|
return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n])
|
|
142
143
|
};
|
|
143
144
|
|
|
145
|
+
// :: StepMap
|
|
146
|
+
// A StepMap that contains no changed ranges.
|
|
144
147
|
StepMap.empty = new StepMap([]);
|
|
145
148
|
|
|
146
149
|
// :: class extends Mappable
|
|
@@ -720,8 +723,14 @@ function findWrappingInside(range, type) {
|
|
|
720
723
|
// probably be computed with [`findWrapping`](#transform.findWrapping).
|
|
721
724
|
Transform.prototype.wrap = function(range, wrappers) {
|
|
722
725
|
var content = Fragment.empty;
|
|
723
|
-
for (var i = wrappers.length - 1; i >= 0; i--)
|
|
724
|
-
|
|
726
|
+
for (var i = wrappers.length - 1; i >= 0; i--) {
|
|
727
|
+
if (content.size) {
|
|
728
|
+
var match = wrappers[i].type.contentMatch.matchFragment(content);
|
|
729
|
+
if (!match || !match.validEnd)
|
|
730
|
+
{ throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper") }
|
|
731
|
+
}
|
|
732
|
+
content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
|
|
733
|
+
}
|
|
725
734
|
|
|
726
735
|
var start = range.start, end = range.end;
|
|
727
736
|
return this.step(new ReplaceAroundStep(start, end, start, end, new Slice(content, 0, 0), wrappers.length, true))
|
|
@@ -1529,6 +1538,10 @@ function invalidMarks(type, fragment, start) {
|
|
|
1529
1538
|
return false
|
|
1530
1539
|
}
|
|
1531
1540
|
|
|
1541
|
+
function definesContent(type) {
|
|
1542
|
+
return type.spec.defining || type.spec.definingForContent
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1532
1545
|
// :: (number, number, Slice) → this
|
|
1533
1546
|
// Replace a range of the document with a given slice, using `from`,
|
|
1534
1547
|
// `to`, and the slice's [`openStart`](#model.Slice.openStart) property
|
|
@@ -1536,9 +1549,9 @@ function invalidMarks(type, fragment, start) {
|
|
|
1536
1549
|
// grow the replaced area or close open nodes in the slice in order to
|
|
1537
1550
|
// get a fit that is more in line with WYSIWYG expectations, by
|
|
1538
1551
|
// dropping fully covered parent nodes of the replaced region when
|
|
1539
|
-
// they are marked [non-defining](#model.NodeSpec.
|
|
1552
|
+
// they are marked [non-defining as context](#model.NodeSpec.definingAsContext), or
|
|
1540
1553
|
// including an open parent node from the slice that _is_ marked as
|
|
1541
|
-
// [defining](#model.NodeSpec.
|
|
1554
|
+
// [defining its content](#model.NodeSpec.definingForContent).
|
|
1542
1555
|
//
|
|
1543
1556
|
// This is the method, for example, to handle paste. The similar
|
|
1544
1557
|
// [`replace`](#transform.Transform.replace) method is a more
|
|
@@ -1565,7 +1578,7 @@ Transform.prototype.replaceRange = function(from, to, slice) {
|
|
|
1565
1578
|
// cross a defining node.
|
|
1566
1579
|
for (var d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) {
|
|
1567
1580
|
var spec = $from.node(d).type.spec;
|
|
1568
|
-
if (spec.defining || spec.isolating) { break }
|
|
1581
|
+
if (spec.defining || spec.definingAsContext || spec.isolating) { break }
|
|
1569
1582
|
if (targetDepths.indexOf(d) > -1) { preferredTarget = d; }
|
|
1570
1583
|
else if ($from.before(d) == pos) { targetDepths.splice(1, 0, -d); }
|
|
1571
1584
|
}
|
|
@@ -1582,10 +1595,12 @@ Transform.prototype.replaceRange = function(from, to, slice) {
|
|
|
1582
1595
|
}
|
|
1583
1596
|
// Back up if the node directly above openStart, or the node above
|
|
1584
1597
|
// that separated only by a non-defining textblock node, is defining.
|
|
1585
|
-
if (preferredDepth > 0 && leftNodes[preferredDepth - 1].type
|
|
1598
|
+
if (preferredDepth > 0 && definesContent(leftNodes[preferredDepth - 1].type) &&
|
|
1586
1599
|
$from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 1].type)
|
|
1587
1600
|
{ preferredDepth -= 1; }
|
|
1588
|
-
else if (preferredDepth >= 2 &&
|
|
1601
|
+
else if (preferredDepth >= 2 &&
|
|
1602
|
+
leftNodes[preferredDepth - 1].isTextblock &&
|
|
1603
|
+
definesContent(leftNodes[preferredDepth - 2].type) &&
|
|
1589
1604
|
$from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 2].type)
|
|
1590
1605
|
{ preferredDepth -= 2; }
|
|
1591
1606
|
|
|
@@ -1677,7 +1692,10 @@ function coveredDepths($from, $to) {
|
|
|
1677
1692
|
$to.end(d) > $to.pos + ($to.depth - d) ||
|
|
1678
1693
|
$from.node(d).type.spec.isolating ||
|
|
1679
1694
|
$to.node(d).type.spec.isolating) { break }
|
|
1680
|
-
if (start == $to.start(d)
|
|
1695
|
+
if (start == $to.start(d) ||
|
|
1696
|
+
(d == $from.depth && d == $to.depth && $from.parent.inlineContent && $to.parent.inlineContent &&
|
|
1697
|
+
d && $to.start(d - 1) == start - 1))
|
|
1698
|
+
{ result.push(d); }
|
|
1681
1699
|
}
|
|
1682
1700
|
return result
|
|
1683
1701
|
}
|