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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prosemirror-transform",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "ProseMirror document transformations",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"prosemirror-model": "^1.0.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"mocha": "^
|
|
23
|
+
"mocha": "^9.1.2",
|
|
24
24
|
"ist": "^1.0.0",
|
|
25
25
|
"prosemirror-test-builder": "^1.0.0",
|
|
26
26
|
"rollup": "^2.26.3",
|
package/src/map.js
CHANGED
|
@@ -57,6 +57,7 @@ export class StepMap {
|
|
|
57
57
|
// represented as an array of numbers, in which each group of three
|
|
58
58
|
// represents a modified chunk as `[start, oldSize, newSize]`.
|
|
59
59
|
constructor(ranges, inverted = false) {
|
|
60
|
+
if (!ranges.length && StepMap.empty) return StepMap.empty
|
|
60
61
|
this.ranges = ranges
|
|
61
62
|
this.inverted = inverted
|
|
62
63
|
}
|
|
@@ -138,6 +139,8 @@ export class StepMap {
|
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
|
|
142
|
+
// :: StepMap
|
|
143
|
+
// A StepMap that contains no changed ranges.
|
|
141
144
|
StepMap.empty = new StepMap([])
|
|
142
145
|
|
|
143
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.
|
|
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
|
}
|
|
@@ -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
|
|
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 &&
|
|
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
|
|
|
@@ -483,7 +489,10 @@ function coveredDepths($from, $to) {
|
|
|
483
489
|
$to.end(d) > $to.pos + ($to.depth - d) ||
|
|
484
490
|
$from.node(d).type.spec.isolating ||
|
|
485
491
|
$to.node(d).type.spec.isolating) break
|
|
486
|
-
if (start == $to.start(d)
|
|
492
|
+
if (start == $to.start(d) ||
|
|
493
|
+
(d == $from.depth && d == $to.depth && $from.parent.inlineContent && $to.parent.inlineContent &&
|
|
494
|
+
d && $to.start(d - 1) == start - 1))
|
|
495
|
+
result.push(d)
|
|
487
496
|
}
|
|
488
497
|
return result
|
|
489
498
|
}
|
package/src/structure.js
CHANGED
|
@@ -103,8 +103,14 @@ function findWrappingInside(range, type) {
|
|
|
103
103
|
// probably be computed with [`findWrapping`](#transform.findWrapping).
|
|
104
104
|
Transform.prototype.wrap = function(range, wrappers) {
|
|
105
105
|
let content = Fragment.empty
|
|
106
|
-
for (let i = wrappers.length - 1; i >= 0; i--)
|
|
106
|
+
for (let i = wrappers.length - 1; i >= 0; i--) {
|
|
107
|
+
if (content.size) {
|
|
108
|
+
let match = wrappers[i].type.contentMatch.matchFragment(content)
|
|
109
|
+
if (!match || !match.validEnd)
|
|
110
|
+
throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")
|
|
111
|
+
}
|
|
107
112
|
content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content))
|
|
113
|
+
}
|
|
108
114
|
|
|
109
115
|
let start = range.start, end = range.end
|
|
110
116
|
return this.step(new ReplaceAroundStep(start, end, start, end, new Slice(content, 0, 0), wrappers.length, true))
|