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/CHANGELOG.md +18 -0
- package/dist/index.es.js +18 -12
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +18 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/map.js +2 -0
- package/src/replace.js +16 -12
package/package.json
CHANGED
package/src/map.js
CHANGED
package/src/replace.js
CHANGED
|
@@ -241,7 +241,7 @@ class Fitter {
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
mustMoveInline() {
|
|
244
|
-
if (!this.$to.parent.isTextblock
|
|
244
|
+
if (!this.$to.parent.isTextblock) return -1
|
|
245
245
|
let top = this.frontier[this.depth], level
|
|
246
246
|
if (!top.type.isTextblock || !contentAfterFits(this.$to, this.$to.depth, top.type, top.match, false) ||
|
|
247
247
|
(this.$to.depth == this.depth && (level = this.findCloseLevel(this.$to)) && level.depth == this.depth)) return -1
|
|
@@ -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.
|
|
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.
|
|
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
|
}
|
|
@@ -386,14 +390,14 @@ Transform.prototype.replaceRange = function(from, to, slice) {
|
|
|
386
390
|
if (i == slice.openStart) break
|
|
387
391
|
content = node.content
|
|
388
392
|
}
|
|
389
|
-
|
|
390
|
-
//
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
393
|
+
|
|
394
|
+
// Back up preferredDepth to cover defining textblocks directly
|
|
395
|
+
// above it, possibly skipping a non-defining textblock.
|
|
396
|
+
for (let d = preferredDepth - 1; d >= 0; d--) {
|
|
397
|
+
let type = leftNodes[d].type, def = definesContent(type)
|
|
398
|
+
if (def && $from.node(preferredTargetIndex).type != type) preferredDepth = d
|
|
399
|
+
else if (def || !type.isTextblock) break
|
|
400
|
+
}
|
|
397
401
|
|
|
398
402
|
for (let j = slice.openStart; j >= 0; j--) {
|
|
399
403
|
let openDepth = (j + preferredDepth + 1) % (slice.openStart + 1)
|