prosemirror-transform 1.3.4 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-transform",
3
- "version": "1.3.4",
3
+ "version": "1.4.0",
4
4
  "description": "ProseMirror document transformations",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
package/src/map.js CHANGED
@@ -139,6 +139,8 @@ export class StepMap {
139
139
  }
140
140
  }
141
141
 
142
+ // :: StepMap
143
+ // A StepMap that contains no changed ranges.
142
144
  StepMap.empty = new StepMap([])
143
145
 
144
146
  // :: class extends Mappable
package/src/replace.js CHANGED
@@ -335,6 +335,10 @@ function invalidMarks(type, fragment, start) {
335
335
  return false
336
336
  }
337
337
 
338
+ function definesContent(type) {
339
+ return type.spec.defining || type.spec.definingForContent
340
+ }
341
+
338
342
  // :: (number, number, Slice) → this
339
343
  // Replace a range of the document with a given slice, using `from`,
340
344
  // `to`, and the slice's [`openStart`](#model.Slice.openStart) property
@@ -342,9 +346,9 @@ function invalidMarks(type, fragment, start) {
342
346
  // grow the replaced area or close open nodes in the slice in order to
343
347
  // get a fit that is more in line with WYSIWYG expectations, by
344
348
  // dropping fully covered parent nodes of the replaced region when
345
- // they are marked [non-defining](#model.NodeSpec.defining), or
349
+ // they are marked [non-defining as context](#model.NodeSpec.definingAsContext), or
346
350
  // including an open parent node from the slice that _is_ marked as
347
- // [defining](#model.NodeSpec.defining).
351
+ // [defining its content](#model.NodeSpec.definingForContent).
348
352
  //
349
353
  // This is the method, for example, to handle paste. The similar
350
354
  // [`replace`](#transform.Transform.replace) method is a more
@@ -371,7 +375,7 @@ Transform.prototype.replaceRange = function(from, to, slice) {
371
375
  // cross a defining node.
372
376
  for (let d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) {
373
377
  let spec = $from.node(d).type.spec
374
- if (spec.defining || spec.isolating) break
378
+ if (spec.defining || spec.definingAsContext || spec.isolating) break
375
379
  if (targetDepths.indexOf(d) > -1) preferredTarget = d
376
380
  else if ($from.before(d) == pos) targetDepths.splice(1, 0, -d)
377
381
  }
@@ -388,10 +392,12 @@ Transform.prototype.replaceRange = function(from, to, slice) {
388
392
  }
389
393
  // Back up if the node directly above openStart, or the node above
390
394
  // that separated only by a non-defining textblock node, is defining.
391
- if (preferredDepth > 0 && leftNodes[preferredDepth - 1].type.spec.defining &&
395
+ if (preferredDepth > 0 && definesContent(leftNodes[preferredDepth - 1].type) &&
392
396
  $from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 1].type)
393
397
  preferredDepth -= 1
394
- else if (preferredDepth >= 2 && leftNodes[preferredDepth - 1].isTextblock && leftNodes[preferredDepth - 2].type.spec.defining &&
398
+ else if (preferredDepth >= 2 &&
399
+ leftNodes[preferredDepth - 1].isTextblock &&
400
+ definesContent(leftNodes[preferredDepth - 2].type) &&
395
401
  $from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 2].type)
396
402
  preferredDepth -= 2
397
403