prosemirror-transform 1.4.0 → 1.5.0-beta.1

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.es.js CHANGED
@@ -300,10 +300,10 @@ var Transform = function Transform(doc) {
300
300
  this.mapping = new Mapping;
301
301
  };
302
302
 
303
- var prototypeAccessors = { before: { configurable: true },docChanged: { configurable: true } };
303
+ var prototypeAccessors$1 = { before: { configurable: true },docChanged: { configurable: true } };
304
304
 
305
305
  // :: Node The starting document.
306
- prototypeAccessors.before.get = function () { return this.docs.length ? this.docs[0] : this.doc };
306
+ prototypeAccessors$1.before.get = function () { return this.docs.length ? this.docs[0] : this.doc };
307
307
 
308
308
  // :: (step: Step) → this
309
309
  // Apply a new step in this transform, saving the result. Throws an
@@ -326,7 +326,7 @@ Transform.prototype.maybeStep = function maybeStep (step) {
326
326
  // :: bool
327
327
  // True when the document has been changed (when there are any
328
328
  // steps).
329
- prototypeAccessors.docChanged.get = function () {
329
+ prototypeAccessors$1.docChanged.get = function () {
330
330
  return this.steps.length > 0
331
331
  };
332
332
 
@@ -337,7 +337,7 @@ Transform.prototype.addStep = function addStep (step, doc) {
337
337
  this.doc = doc;
338
338
  };
339
339
 
340
- Object.defineProperties( Transform.prototype, prototypeAccessors );
340
+ Object.defineProperties( Transform.prototype, prototypeAccessors$1 );
341
341
 
342
342
  function mustOverride() { throw new Error("Override me") }
343
343
 
@@ -740,18 +740,18 @@ Transform.prototype.wrap = function(range, wrappers) {
740
740
  // Set the type of all textblocks (partly) between `from` and `to` to
741
741
  // the given node type with the given attributes.
742
742
  Transform.prototype.setBlockType = function(from, to, type, attrs) {
743
- var this$1 = this;
743
+ var this$1$1 = this;
744
744
  if ( to === void 0 ) to = from;
745
745
 
746
746
  if (!type.isTextblock) { throw new RangeError("Type given to setBlockType should be a textblock") }
747
747
  var mapFrom = this.steps.length;
748
748
  this.doc.nodesBetween(from, to, function (node, pos) {
749
- if (node.isTextblock && !node.hasMarkup(type, attrs) && canChangeType(this$1.doc, this$1.mapping.slice(mapFrom).map(pos), type)) {
749
+ if (node.isTextblock && !node.hasMarkup(type, attrs) && canChangeType(this$1$1.doc, this$1$1.mapping.slice(mapFrom).map(pos), type)) {
750
750
  // Ensure all markup that isn't allowed in the new node type is cleared
751
- this$1.clearIncompatible(this$1.mapping.slice(mapFrom).map(pos, 1), type);
752
- var mapping = this$1.mapping.slice(mapFrom);
751
+ this$1$1.clearIncompatible(this$1$1.mapping.slice(mapFrom).map(pos, 1), type);
752
+ var mapping = this$1$1.mapping.slice(mapFrom);
753
753
  var startM = mapping.map(pos, 1), endM = mapping.map(pos + node.nodeSize, 1);
754
- this$1.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1,
754
+ this$1$1.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1,
755
755
  new Slice(Fragment.from(type.create(attrs, null, node.marks)), 0, 0), 1, true));
756
756
  return false
757
757
  }
@@ -958,13 +958,13 @@ var AddMarkStep = /*@__PURE__*/(function (Step) {
958
958
  AddMarkStep.prototype.constructor = AddMarkStep;
959
959
 
960
960
  AddMarkStep.prototype.apply = function apply (doc) {
961
- var this$1 = this;
961
+ var this$1$1 = this;
962
962
 
963
963
  var oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from);
964
964
  var parent = $from.node($from.sharedDepth(this.to));
965
965
  var slice = new Slice(mapFragment(oldSlice.content, function (node, parent) {
966
- if (!node.isAtom || !parent.type.allowsMarkType(this$1.mark.type)) { return node }
967
- return node.mark(this$1.mark.addToSet(node.marks))
966
+ if (!node.isAtom || !parent.type.allowsMarkType(this$1$1.mark.type)) { return node }
967
+ return node.mark(this$1$1.mark.addToSet(node.marks))
968
968
  }, parent), oldSlice.openStart, oldSlice.openEnd);
969
969
  return StepResult.fromReplace(doc, this.from, this.to, slice)
970
970
  };
@@ -1023,11 +1023,11 @@ var RemoveMarkStep = /*@__PURE__*/(function (Step) {
1023
1023
  RemoveMarkStep.prototype.constructor = RemoveMarkStep;
1024
1024
 
1025
1025
  RemoveMarkStep.prototype.apply = function apply (doc) {
1026
- var this$1 = this;
1026
+ var this$1$1 = this;
1027
1027
 
1028
1028
  var oldSlice = doc.slice(this.from, this.to);
1029
1029
  var slice = new Slice(mapFragment(oldSlice.content, function (node) {
1030
- return node.mark(this$1.mark.removeFromSet(node.marks))
1030
+ return node.mark(this$1$1.mark.removeFromSet(node.marks))
1031
1031
  }), oldSlice.openStart, oldSlice.openEnd);
1032
1032
  return StepResult.fromReplace(doc, this.from, this.to, slice)
1033
1033
  };
@@ -1069,7 +1069,7 @@ Step.jsonID("removeMark", RemoveMarkStep);
1069
1069
  // :: (number, number, Mark) → this
1070
1070
  // Add the given mark to the inline content between `from` and `to`.
1071
1071
  Transform.prototype.addMark = function(from, to, mark) {
1072
- var this$1 = this;
1072
+ var this$1$1 = this;
1073
1073
 
1074
1074
  var removed = [], added = [], removing = null, adding = null;
1075
1075
  this.doc.nodesBetween(from, to, function (node, pos, parent) {
@@ -1095,8 +1095,8 @@ Transform.prototype.addMark = function(from, to, mark) {
1095
1095
  }
1096
1096
  });
1097
1097
 
1098
- removed.forEach(function (s) { return this$1.step(s); });
1099
- added.forEach(function (s) { return this$1.step(s); });
1098
+ removed.forEach(function (s) { return this$1$1.step(s); });
1099
+ added.forEach(function (s) { return this$1$1.step(s); });
1100
1100
  return this
1101
1101
  };
1102
1102
 
@@ -1106,7 +1106,7 @@ Transform.prototype.addMark = function(from, to, mark) {
1106
1106
  // remove all marks of that type. When it is null, remove all marks of
1107
1107
  // any type.
1108
1108
  Transform.prototype.removeMark = function(from, to, mark) {
1109
- var this$1 = this;
1109
+ var this$1$1 = this;
1110
1110
  if ( mark === void 0 ) mark = null;
1111
1111
 
1112
1112
  var matched = [], step = 0;
@@ -1142,7 +1142,7 @@ Transform.prototype.removeMark = function(from, to, mark) {
1142
1142
  }
1143
1143
  }
1144
1144
  });
1145
- matched.forEach(function (m) { return this$1.step(new RemoveMarkStep(m.from, m.to, m.style)); });
1145
+ matched.forEach(function (m) { return this$1$1.step(new RemoveMarkStep(m.from, m.to, m.style)); });
1146
1146
  return this
1147
1147
  };
1148
1148
 
@@ -1268,9 +1268,9 @@ var Fitter = function Fitter($from, $to, slice) {
1268
1268
  { this.placed = Fragment.from($from.node(i$1).copy(this.placed)); }
1269
1269
  };
1270
1270
 
1271
- var prototypeAccessors$1 = { depth: { configurable: true } };
1271
+ var prototypeAccessors = { depth: { configurable: true } };
1272
1272
 
1273
- prototypeAccessors$1.depth.get = function () { return this.frontier.length - 1 };
1273
+ prototypeAccessors.depth.get = function () { return this.frontier.length - 1 };
1274
1274
 
1275
1275
  Fitter.prototype.fit = function fit () {
1276
1276
  // As long as there's unplaced content, try to place some of it.
@@ -1437,7 +1437,7 @@ Fitter.prototype.placeNodes = function placeNodes (ref) {
1437
1437
  };
1438
1438
 
1439
1439
  Fitter.prototype.mustMoveInline = function mustMoveInline () {
1440
- if (!this.$to.parent.isTextblock || this.$to.end() == this.$to.pos) { return -1 }
1440
+ if (!this.$to.parent.isTextblock) { return -1 }
1441
1441
  var top = this.frontier[this.depth], level;
1442
1442
  if (!top.type.isTextblock || !contentAfterFits(this.$to, this.$to.depth, top.type, top.match, false) ||
1443
1443
  (this.$to.depth == this.depth && (level = this.findCloseLevel(this.$to)) && level.depth == this.depth)) { return -1 }
@@ -1495,7 +1495,7 @@ Fitter.prototype.closeFrontierNode = function closeFrontierNode () {
1495
1495
  if (add.childCount) { this.placed = addToFragment(this.placed, this.frontier.length, add); }
1496
1496
  };
1497
1497
 
1498
- Object.defineProperties( Fitter.prototype, prototypeAccessors$1 );
1498
+ Object.defineProperties( Fitter.prototype, prototypeAccessors );
1499
1499
 
1500
1500
  function dropFromFragment(fragment, depth, count) {
1501
1501
  if (depth == 0) { return fragment.cutByIndex(count) }
@@ -1593,16 +1593,14 @@ Transform.prototype.replaceRange = function(from, to, slice) {
1593
1593
  if (i == slice.openStart) { break }
1594
1594
  content = node.content;
1595
1595
  }
1596
- // Back up if the node directly above openStart, or the node above
1597
- // that separated only by a non-defining textblock node, is defining.
1598
- if (preferredDepth > 0 && definesContent(leftNodes[preferredDepth - 1].type) &&
1599
- $from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 1].type)
1600
- { preferredDepth -= 1; }
1601
- else if (preferredDepth >= 2 &&
1602
- leftNodes[preferredDepth - 1].isTextblock &&
1603
- definesContent(leftNodes[preferredDepth - 2].type) &&
1604
- $from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 2].type)
1605
- { preferredDepth -= 2; }
1596
+
1597
+ // Back up preferredDepth to cover defining textblocks directly
1598
+ // above it, possibly skipping a non-defining textblock.
1599
+ for (var d$1 = preferredDepth - 1; d$1 >= 0; d$1--) {
1600
+ var type = leftNodes[d$1].type, def = definesContent(type);
1601
+ if (def && $from.node(preferredTargetIndex).type != type) { preferredDepth = d$1; }
1602
+ else if (def || !type.isTextblock) { break }
1603
+ }
1606
1604
 
1607
1605
  for (var j = slice.openStart; j >= 0; j--) {
1608
1606
  var openDepth = (j + preferredDepth + 1) % (slice.openStart + 1);