prosemirror-transform 1.3.0 → 1.3.4
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 +26 -0
- package/dist/index.es.js +22 -7
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +22 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/map.js +1 -0
- package/src/replace.js +5 -2
- package/src/structure.js +15 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prosemirror-transform",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
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
|
}
|
package/src/replace.js
CHANGED
|
@@ -417,7 +417,7 @@ Transform.prototype.replaceRange = function(from, to, slice) {
|
|
|
417
417
|
this.replace(from, to, slice)
|
|
418
418
|
if (this.steps.length > startSteps) break
|
|
419
419
|
let depth = targetDepths[i]
|
|
420
|
-
if (
|
|
420
|
+
if (depth < 0) continue
|
|
421
421
|
from = $from.before(depth); to = $to.after(depth)
|
|
422
422
|
}
|
|
423
423
|
return this
|
|
@@ -483,7 +483,10 @@ function coveredDepths($from, $to) {
|
|
|
483
483
|
$to.end(d) > $to.pos + ($to.depth - d) ||
|
|
484
484
|
$from.node(d).type.spec.isolating ||
|
|
485
485
|
$to.node(d).type.spec.isolating) break
|
|
486
|
-
if (start == $to.start(d)
|
|
486
|
+
if (start == $to.start(d) ||
|
|
487
|
+
(d == $from.depth && d == $to.depth && $from.parent.inlineContent && $to.parent.inlineContent &&
|
|
488
|
+
d && $to.start(d - 1) == start - 1))
|
|
489
|
+
result.push(d)
|
|
487
490
|
}
|
|
488
491
|
return result
|
|
489
492
|
}
|
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))
|
|
@@ -276,9 +282,14 @@ export function dropPoint(doc, pos, slice) {
|
|
|
276
282
|
for (let d = $pos.depth; d >= 0; d--) {
|
|
277
283
|
let bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1
|
|
278
284
|
let insertPos = $pos.index(d) + (bias > 0 ? 1 : 0)
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
285
|
+
let parent = $pos.node(d), fits = false
|
|
286
|
+
if (pass == 1) {
|
|
287
|
+
fits = parent.canReplace(insertPos, insertPos, content)
|
|
288
|
+
} else {
|
|
289
|
+
let wrapping = parent.contentMatchAt(insertPos).findWrapping(content.firstChild.type)
|
|
290
|
+
fits = wrapping && parent.canReplaceWith(insertPos, insertPos, wrapping[0])
|
|
291
|
+
}
|
|
292
|
+
if (fits)
|
|
282
293
|
return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1)
|
|
283
294
|
}
|
|
284
295
|
}
|