prosemirror-transform 1.3.4 → 1.4.2

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/dist/index.js CHANGED
@@ -146,6 +146,8 @@ StepMap.offset = function offset (n) {
146
146
  return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n])
147
147
  };
148
148
 
149
+ // :: StepMap
150
+ // A StepMap that contains no changed ranges.
149
151
  StepMap.empty = new StepMap([]);
150
152
 
151
153
  // :: class extends Mappable
@@ -1439,7 +1441,7 @@ Fitter.prototype.placeNodes = function placeNodes (ref) {
1439
1441
  };
1440
1442
 
1441
1443
  Fitter.prototype.mustMoveInline = function mustMoveInline () {
1442
- if (!this.$to.parent.isTextblock || this.$to.end() == this.$to.pos) { return -1 }
1444
+ if (!this.$to.parent.isTextblock) { return -1 }
1443
1445
  var top = this.frontier[this.depth], level;
1444
1446
  if (!top.type.isTextblock || !contentAfterFits(this.$to, this.$to.depth, top.type, top.match, false) ||
1445
1447
  (this.$to.depth == this.depth && (level = this.findCloseLevel(this.$to)) && level.depth == this.depth)) { return -1 }
@@ -1540,6 +1542,10 @@ function invalidMarks(type, fragment, start) {
1540
1542
  return false
1541
1543
  }
1542
1544
 
1545
+ function definesContent(type) {
1546
+ return type.spec.defining || type.spec.definingForContent
1547
+ }
1548
+
1543
1549
  // :: (number, number, Slice) → this
1544
1550
  // Replace a range of the document with a given slice, using `from`,
1545
1551
  // `to`, and the slice's [`openStart`](#model.Slice.openStart) property
@@ -1547,9 +1553,9 @@ function invalidMarks(type, fragment, start) {
1547
1553
  // grow the replaced area or close open nodes in the slice in order to
1548
1554
  // get a fit that is more in line with WYSIWYG expectations, by
1549
1555
  // dropping fully covered parent nodes of the replaced region when
1550
- // they are marked [non-defining](#model.NodeSpec.defining), or
1556
+ // they are marked [non-defining as context](#model.NodeSpec.definingAsContext), or
1551
1557
  // including an open parent node from the slice that _is_ marked as
1552
- // [defining](#model.NodeSpec.defining).
1558
+ // [defining its content](#model.NodeSpec.definingForContent).
1553
1559
  //
1554
1560
  // This is the method, for example, to handle paste. The similar
1555
1561
  // [`replace`](#transform.Transform.replace) method is a more
@@ -1576,7 +1582,7 @@ Transform.prototype.replaceRange = function(from, to, slice) {
1576
1582
  // cross a defining node.
1577
1583
  for (var d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) {
1578
1584
  var spec = $from.node(d).type.spec;
1579
- if (spec.defining || spec.isolating) { break }
1585
+ if (spec.defining || spec.definingAsContext || spec.isolating) { break }
1580
1586
  if (targetDepths.indexOf(d) > -1) { preferredTarget = d; }
1581
1587
  else if ($from.before(d) == pos) { targetDepths.splice(1, 0, -d); }
1582
1588
  }
@@ -1591,14 +1597,14 @@ Transform.prototype.replaceRange = function(from, to, slice) {
1591
1597
  if (i == slice.openStart) { break }
1592
1598
  content = node.content;
1593
1599
  }
1594
- // Back up if the node directly above openStart, or the node above
1595
- // that separated only by a non-defining textblock node, is defining.
1596
- if (preferredDepth > 0 && leftNodes[preferredDepth - 1].type.spec.defining &&
1597
- $from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 1].type)
1598
- { preferredDepth -= 1; }
1599
- else if (preferredDepth >= 2 && leftNodes[preferredDepth - 1].isTextblock && leftNodes[preferredDepth - 2].type.spec.defining &&
1600
- $from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 2].type)
1601
- { preferredDepth -= 2; }
1600
+
1601
+ // Back up preferredDepth to cover defining textblocks directly
1602
+ // above it, possibly skipping a non-defining textblock.
1603
+ for (var d$1 = preferredDepth - 1; d$1 >= 0; d$1--) {
1604
+ var type = leftNodes[d$1].type, def = definesContent(type);
1605
+ if (def && $from.node(preferredTargetIndex).type != type) { preferredDepth = d$1; }
1606
+ else if (def || !type.isTextblock) { break }
1607
+ }
1602
1608
 
1603
1609
  for (var j = slice.openStart; j >= 0; j--) {
1604
1610
  var openDepth = (j + preferredDepth + 1) % (slice.openStart + 1);