Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prosemirror-transform

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-transform - npm Package Compare versions

Comparing version 0.20.0 to 0.21.0

14

dist/index.js
;var assign;
((assign = require("./transform"), exports.Transform = assign.Transform, exports.TransformError = assign.TransformError, assign))
((assign = require("./transform"), exports.Transform = assign.Transform, exports.TransformError = assign.TransformError))
;var assign$1;
((assign$1 = require("./step"), exports.Step = assign$1.Step, exports.StepResult = assign$1.StepResult, assign$1))
((assign$1 = require("./step"), exports.Step = assign$1.Step, exports.StepResult = assign$1.StepResult))
;var assign$2;
((assign$2 = require("./structure"), exports.joinPoint = assign$2.joinPoint, exports.canJoin = assign$2.canJoin, exports.canSplit = assign$2.canSplit, exports.insertPoint = assign$2.insertPoint, exports.liftTarget = assign$2.liftTarget, exports.findWrapping = assign$2.findWrapping, assign$2))
((assign$2 = require("./structure"), exports.joinPoint = assign$2.joinPoint, exports.canJoin = assign$2.canJoin, exports.canSplit = assign$2.canSplit, exports.insertPoint = assign$2.insertPoint, exports.liftTarget = assign$2.liftTarget, exports.findWrapping = assign$2.findWrapping))
;var assign$3;
((assign$3 = require("./map"), exports.StepMap = assign$3.StepMap, exports.MapResult = assign$3.MapResult, exports.Mapping = assign$3.Mapping, assign$3))
((assign$3 = require("./map"), exports.StepMap = assign$3.StepMap, exports.MapResult = assign$3.MapResult, exports.Mapping = assign$3.Mapping))
;var assign$4;
((assign$4 = require("./mark_step"), exports.AddMarkStep = assign$4.AddMarkStep, exports.RemoveMarkStep = assign$4.RemoveMarkStep, assign$4))
((assign$4 = require("./mark_step"), exports.AddMarkStep = assign$4.AddMarkStep, exports.RemoveMarkStep = assign$4.RemoveMarkStep))
;var assign$5;
((assign$5 = require("./replace_step"), exports.ReplaceStep = assign$5.ReplaceStep, exports.ReplaceAroundStep = assign$5.ReplaceAroundStep, assign$5))
((assign$5 = require("./replace_step"), exports.ReplaceStep = assign$5.ReplaceStep, exports.ReplaceAroundStep = assign$5.ReplaceAroundStep))
require("./mark")
;var assign$6;
((assign$6 = require("./replace"), exports.replaceStep = assign$6.replaceStep, assign$6))
((assign$6 = require("./replace"), exports.replaceStep = assign$6.replaceStep))

@@ -40,3 +40,3 @@ var ref = require("prosemirror-model");

return node.mark(this$1.mark.addToSet(node.marks))
}, parent), oldSlice.openLeft, oldSlice.openRight)
}, parent), oldSlice.openStart, oldSlice.openEnd)
return StepResult.fromReplace(doc, this.from, this.to, slice)

@@ -96,3 +96,3 @@ };

return node.mark(this$1.mark.removeFromSet(node.marks))
}), oldSlice.openLeft, oldSlice.openRight)
}), oldSlice.openStart, oldSlice.openEnd)
return StepResult.fromReplace(doc, this.from, this.to, slice)

@@ -99,0 +99,0 @@ };

@@ -47,9 +47,9 @@ var ref = require("prosemirror-model");

if (this.from + this.slice.size == other.from && !this.slice.openRight && !other.slice.openLeft) {
if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {
var slice = this.slice.size + other.slice.size == 0 ? Slice.empty
: new Slice(this.slice.content.append(other.slice.content), this.slice.openLeft, other.slice.openRight)
: new Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd)
return new ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure)
} else if (other.to == this.from && !this.slice.openLeft && !other.slice.openRight) {
} else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {
var slice$1 = this.slice.size + other.slice.size == 0 ? Slice.empty
: new Slice(other.slice.content.append(this.slice.content), other.slice.openLeft, this.slice.openRight)
: new Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd)
return new ReplaceStep(other.from, this.to, slice$1, this.structure)

@@ -107,3 +107,3 @@ } else {

var gap = doc.slice(this.gapFrom, this.gapTo)
if (gap.openLeft || gap.openRight)
if (gap.openStart || gap.openEnd)
{ return StepResult.fail("Gap is not a flat range") }

@@ -110,0 +110,0 @@ var inserted = this.slice.insertAt(this.insert, gap.content)

@@ -15,3 +15,3 @@ var ref = require("prosemirror-model");

// Replace a range of the document with a given slice, using `from`,
// `to`, and the slice's [`openLeft`](#model.Slice.openLeft) property
// `to`, and the slice's [`openStart`](#model.Slice.openStart) property
// as hints, rather than fixed start and end points. This method may

@@ -48,10 +48,10 @@ // grow the replaced area or close open nodes in the slice in order to

var leftNodes = [], preferredDepth = slice.openLeft
var leftNodes = [], preferredDepth = slice.openStart
for (var content = slice.content, i = 0;; i++) {
var node = content.firstChild
leftNodes.push(node)
if (i == slice.openLeft) { break }
if (i == slice.openStart) { break }
content = node.content
}
// Back up if the node directly above openLeft, or the node above
// Back up if the node directly above openStart, or the node above
// that separated only by a non-defining textblock node, is defining.

@@ -63,4 +63,4 @@ if (preferredDepth > 0 && leftNodes[preferredDepth - 1].type.spec.defining)

for (var j = slice.openLeft; j >= 0; j--) {
var openDepth = (j + preferredDepth + 1) % (slice.openLeft + 1)
for (var j = slice.openStart; j >= 0; j--) {
var openDepth = (j + preferredDepth + 1) % (slice.openStart + 1)
var insert = leftNodes[openDepth]

@@ -75,4 +75,4 @@ if (!insert) { continue }

{ return this$1.replace($from.before(expandDepth), expandDepth > $from.depth ? to : $to.after(expandDepth),
new Slice(closeFragment(slice.content, 0, slice.openLeft, openDepth),
openDepth, slice.openRight)) }
new Slice(closeFragment(slice.content, 0, slice.openStart, openDepth),
openDepth, slice.openEnd)) }
}

@@ -208,6 +208,6 @@ }

function fitLeftInner($from, depth, placed, placedBelow) {
var content = Fragment.empty, openRight = 0, placedHere = placed[depth]
var content = Fragment.empty, openEnd = 0, placedHere = placed[depth]
if ($from.depth > depth) {
var inner = fitLeftInner($from, depth + 1, placed, placedBelow || placedHere)
openRight = inner.openRight + 1
openEnd = inner.openEnd + 1
content = Fragment.from($from.node(depth + 1).copy(inner.content))

@@ -218,10 +218,10 @@ }

content = content.append(placedHere.content)
openRight = placedHere.openRight
openEnd = placedHere.openEnd
}
if (placedBelow) {
content = content.append($from.node(depth).contentMatchAt($from.indexAfter(depth)).fillBefore(Fragment.empty, true))
openRight = 0
openEnd = 0
}
return {content: content, openRight: openRight}
return {content: content, openEnd: openEnd}
}

@@ -232,26 +232,26 @@

var content = ref.content;
var openRight = ref.openRight;
return new Slice(content, $from.depth, openRight || 0)
var openEnd = ref.openEnd;
return new Slice(content, $from.depth, openEnd || 0)
}
function fitRightJoin(content, parent, $from, $to, depth, openLeft, openRight) {
var match, count = content.childCount, matchCount = count - (openRight > 0 ? 1 : 0)
if (openLeft < 0)
function fitRightJoin(content, parent, $from, $to, depth, openStart, openEnd) {
var match, count = content.childCount, matchCount = count - (openEnd > 0 ? 1 : 0)
if (openStart < 0)
{ match = parent.contentMatchAt(matchCount) }
else if (count == 1 && openRight > 0)
{ match = $from.node(depth).contentMatchAt(openLeft ? $from.index(depth) : $from.indexAfter(depth)) }
else if (count == 1 && openEnd > 0)
{ match = $from.node(depth).contentMatchAt(openStart ? $from.index(depth) : $from.indexAfter(depth)) }
else
{ match = $from.node(depth).contentMatchAt($from.indexAfter(depth))
.matchFragment(content, count > 0 && openLeft ? 1 : 0, matchCount) }
.matchFragment(content, count > 0 && openStart ? 1 : 0, matchCount) }
var toNode = $to.node(depth)
if (openRight > 0 && depth < $to.depth) {
if (openEnd > 0 && depth < $to.depth) {
var after = toNode.content.cutByIndex($to.indexAfter(depth)).addToStart(content.lastChild)
var joinable$1 = match.fillBefore(after, true)
// Can't insert content if there's a single node stretched across this gap
if (joinable$1 && joinable$1.size && openLeft > 0 && count == 1) { joinable$1 = null }
if (joinable$1 && joinable$1.size && openStart > 0 && count == 1) { joinable$1 = null }
if (joinable$1) {
var inner = fitRightJoin(content.lastChild.content, content.lastChild, $from, $to,
depth + 1, count == 1 ? openLeft - 1 : -1, openRight - 1)
depth + 1, count == 1 ? openStart - 1 : -1, openEnd - 1)
if (inner) {

@@ -266,4 +266,4 @@ var last = content.lastChild.copy(inner)

}
if (openRight > 0)
{ match = match.matchNode(count == 1 && openLeft > 0 ? $from.node(depth + 1) : content.lastChild) }
if (openEnd > 0)
{ match = match.matchNode(count == 1 && openStart > 0 ? $from.node(depth + 1) : content.lastChild) }

@@ -277,5 +277,5 @@ // If we're here, the next level can't be joined, so we see what

if (openRight > 0) {
var closed = fitRightClosed(content.lastChild, openRight - 1, $from, depth + 1,
count == 1 ? openLeft - 1 : -1)
if (openEnd > 0) {
var closed = fitRightClosed(content.lastChild, openEnd - 1, $from, depth + 1,
count == 1 ? openStart - 1 : -1)
content = content.replaceChild(count - 1, closed)

@@ -289,13 +289,13 @@ }

function fitRightClosed(node, openRight, $from, depth, openLeft) {
function fitRightClosed(node, openEnd, $from, depth, openStart) {
var match, content = node.content, count = content.childCount
if (openLeft >= 0)
if (openStart >= 0)
{ match = $from.node(depth).contentMatchAt($from.indexAfter(depth))
.matchFragment(content, openLeft > 0 ? 1 : 0, count) }
.matchFragment(content, openStart > 0 ? 1 : 0, count) }
else
{ match = node.contentMatchAt(count) }
if (openRight > 0) {
var closed = fitRightClosed(content.lastChild, openRight - 1, $from, depth + 1,
count == 1 ? openLeft - 1 : -1)
if (openEnd > 0) {
var closed = fitRightClosed(content.lastChild, openEnd - 1, $from, depth + 1,
count == 1 ? openStart - 1 : -1)
content = content.replaceChild(count - 1, closed)

@@ -314,9 +314,9 @@ }

function normalizeSlice(content, openLeft, openRight) {
while (openLeft > 0 && openRight > 0 && content.childCount == 1) {
function normalizeSlice(content, openStart, openEnd) {
while (openStart > 0 && openEnd > 0 && content.childCount == 1) {
content = content.firstChild.content
openLeft--
openRight--
openStart--
openEnd--
}
return new Slice(content, openLeft, openRight)
return new Slice(content, openStart, openEnd)
}

@@ -326,9 +326,9 @@

function fitRight($from, $to, slice) {
var fitted = fitRightJoin(slice.content, $from.node(0), $from, $to, 0, slice.openLeft, slice.openRight)
var fitted = fitRightJoin(slice.content, $from.node(0), $from, $to, 0, slice.openStart, slice.openEnd)
if (!fitted) { return null }
return normalizeSlice(fitted, slice.openLeft, $to.depth)
return normalizeSlice(fitted, slice.openStart, $to.depth)
}
function fitsTrivially($from, $to, slice) {
return !slice.openLeft && !slice.openRight && $from.start() == $to.start() &&
return !slice.openStart && !slice.openEnd && $from.start() == $to.start() &&
$from.parent.canReplace($from.index(), $to.index(), slice.content)

@@ -341,10 +341,10 @@ }

var match
if (!slice.openRight) {
var parent = $from.node($from.depth - (slice.openLeft - slice.openRight))
if (!slice.openEnd) {
var parent = $from.node($from.depth - (slice.openStart - slice.openEnd))
if (!parent.isTextblock) { return false }
match = parent.contentMatchAt(parent.childCount)
if (slice.size)
{ match = match.matchFragment(slice.content, slice.openLeft ? 1 : 0) }
{ match = match.matchFragment(slice.content, slice.openStart ? 1 : 0) }
} else {
var parent$1 = nodeRight(slice.content, slice.openRight)
var parent$1 = nodeRight(slice.content, slice.openEnd)
if (!parent$1.isTextblock) { return false }

@@ -387,3 +387,3 @@ match = parent$1.contentMatchAt(parent$1.childCount)

// : (ResolvedPos, Slice) → [{content: Fragment, openRight: number, depth: number}]
// : (ResolvedPos, Slice) → [{content: Fragment, openEnd: number, depth: number}]
function placeSlice($from, slice) {

@@ -395,3 +395,3 @@ var dFrom = $from.depth, unplaced = null

// each open fragment.
for (var dSlice = slice.openLeft;; --dSlice) {
for (var dSlice = slice.openStart;; --dSlice) {
// Get the components of the node at this level

@@ -402,7 +402,7 @@ var curType = (void 0), curAttrs = (void 0), curFragment = (void 0)

;var assign;
((assign = nodeLeft(slice.content, dSlice), curType = assign.type, curAttrs = assign.attrs, curFragment = assign.content, assign))
((assign = nodeLeft(slice.content, dSlice), curType = assign.type, curAttrs = assign.attrs, curFragment = assign.content))
} else if (dSlice == 0) { // Top of slice
curFragment = slice.content
}
if (dSlice < slice.openLeft) { curFragment = curFragment.cut(curFragment.firstChild.nodeSize) }
if (dSlice < slice.openStart) { curFragment = curFragment.cut(curFragment.firstChild.nodeSize) }
} else { // Outside slice, in generated wrappers (see below)

@@ -430,3 +430,3 @@ curFragment = Fragment.empty

content: found.fragment,
openRight: endOfContent(slice, dSlice) ? slice.openRight - dSlice : 0,
openEnd: endOfContent(slice, dSlice) ? slice.openEnd - dSlice : 0,
depth: found.depth

@@ -452,3 +452,3 @@ } }

;var assign$1;
((assign$1 = last, curType = assign$1.type, curAttrs = assign$1.attrs, assign$1))
((assign$1 = last, curType = assign$1.type, curAttrs = assign$1.attrs))
}

@@ -455,0 +455,0 @@ if (curFragment.size) {

@@ -18,3 +18,4 @@ var ref = require("prosemirror-model");

// Try to find a target depth to which the content in the given range
// can be lifted.
// can be lifted. Will not go across
// [isolating](#model.NodeSpec.isolating) parent nodes.
function liftTarget(range) {

@@ -24,3 +25,5 @@ var parent = range.parent

for (var depth = range.depth;; --depth) {
var node = range.$from.node(depth), index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth)
var node = range.$from.node(depth)
if (node.type.spec.isolating) { break }
var index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth)
if (depth < range.depth && node.canReplace(index, endIndex, content))

@@ -47,3 +50,3 @@ { return depth }

var before = Fragment.empty, openLeft = 0
var before = Fragment.empty, openStart = 0
for (var d = depth, splitting = false; d > target; d--)

@@ -53,7 +56,7 @@ { if (splitting || $from.index(d) > 0) {

before = Fragment.from($from.node(d).copy(before))
openLeft++
openStart++
} else {
start--
} }
var after = Fragment.empty, openRight = 0
var after = Fragment.empty, openEnd = 0
for (var d$1 = depth, splitting$1 = false; d$1 > target; d$1--)

@@ -63,3 +66,3 @@ { if (splitting$1 || $to.after(d$1 + 1) < $to.end(d$1)) {

after = Fragment.from($to.node(d$1).copy(after))
openRight++
openEnd++
} else {

@@ -70,4 +73,4 @@ end++

return this.step(new ReplaceAroundStep(start, end, gapStart, gapEnd,
new Slice(before.append(after), openLeft, openRight),
before.size - openLeft, true))
new Slice(before.append(after), openStart, openEnd),
before.size - openStart, true))
}

@@ -171,3 +174,3 @@

// :: (Node, number, ?[?{type: NodeType, attrs: ?Object}]) → bool
// :: (Node, number, number, ?[?{type: NodeType, attrs: ?Object}]) → bool
// Check whether splitting at the given position is allowed.

@@ -174,0 +177,0 @@ function canSplit(doc, pos, depth, typesAfter) {

{
"name": "prosemirror-transform",
"version": "0.20.0",
"version": "0.21.0",
"description": "ProseMirror document transformations",

@@ -19,3 +19,3 @@ "main": "dist/index.js",

"dependencies": {
"prosemirror-model": "^0.20.0"
"prosemirror-model": "^0.21.0"
},

@@ -27,3 +27,3 @@ "devDependencies": {

"rimraf": "^2.5.4",
"prosemirror-test-builder": "^0.20.0"
"prosemirror-test-builder": "^0.21.0"
},

@@ -30,0 +30,0 @@ "scripts": {

@@ -31,3 +31,3 @@ const {Fragment, Slice} = require("prosemirror-model")

return node.mark(this.mark.addToSet(node.marks))
}, parent), oldSlice.openLeft, oldSlice.openRight)
}, parent), oldSlice.openStart, oldSlice.openEnd)
return StepResult.fromReplace(doc, this.from, this.to, slice)

@@ -80,3 +80,3 @@ }

return node.mark(this.mark.removeFromSet(node.marks))
}), oldSlice.openLeft, oldSlice.openRight)
}), oldSlice.openStart, oldSlice.openEnd)
return StepResult.fromReplace(doc, this.from, this.to, slice)

@@ -83,0 +83,0 @@ }

@@ -47,9 +47,9 @@ const {Slice} = require("prosemirror-model")

if (this.from + this.slice.size == other.from && !this.slice.openRight && !other.slice.openLeft) {
if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {
let slice = this.slice.size + other.slice.size == 0 ? Slice.empty
: new Slice(this.slice.content.append(other.slice.content), this.slice.openLeft, other.slice.openRight)
: new Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd)
return new ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure)
} else if (other.to == this.from && !this.slice.openLeft && !other.slice.openRight) {
} else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {
let slice = this.slice.size + other.slice.size == 0 ? Slice.empty
: new Slice(other.slice.content.append(this.slice.content), other.slice.openLeft, this.slice.openRight)
: new Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd)
return new ReplaceStep(other.from, this.to, slice, this.structure)

@@ -106,3 +106,3 @@ } else {

let gap = doc.slice(this.gapFrom, this.gapTo)
if (gap.openLeft || gap.openRight)
if (gap.openStart || gap.openEnd)
return StepResult.fail("Gap is not a flat range")

@@ -109,0 +109,0 @@ let inserted = this.slice.insertAt(this.insert, gap.content)

@@ -9,3 +9,3 @@ const {Fragment, Slice} = require("prosemirror-model")

// Replace a range of the document with a given slice, using `from`,
// `to`, and the slice's [`openLeft`](#model.Slice.openLeft) property
// `to`, and the slice's [`openStart`](#model.Slice.openStart) property
// as hints, rather than fixed start and end points. This method may

@@ -40,10 +40,10 @@ // grow the replaced area or close open nodes in the slice in order to

let leftNodes = [], preferredDepth = slice.openLeft
let leftNodes = [], preferredDepth = slice.openStart
for (let content = slice.content, i = 0;; i++) {
let node = content.firstChild
leftNodes.push(node)
if (i == slice.openLeft) break
if (i == slice.openStart) break
content = node.content
}
// Back up if the node directly above openLeft, or the node above
// Back up if the node directly above openStart, or the node above
// that separated only by a non-defining textblock node, is defining.

@@ -55,4 +55,4 @@ if (preferredDepth > 0 && leftNodes[preferredDepth - 1].type.spec.defining)

for (let j = slice.openLeft; j >= 0; j--) {
let openDepth = (j + preferredDepth + 1) % (slice.openLeft + 1)
for (let j = slice.openStart; j >= 0; j--) {
let openDepth = (j + preferredDepth + 1) % (slice.openStart + 1)
let insert = leftNodes[openDepth]

@@ -67,4 +67,4 @@ if (!insert) continue

return this.replace($from.before(expandDepth), expandDepth > $from.depth ? to : $to.after(expandDepth),
new Slice(closeFragment(slice.content, 0, slice.openLeft, openDepth),
openDepth, slice.openRight))
new Slice(closeFragment(slice.content, 0, slice.openStart, openDepth),
openDepth, slice.openEnd))
}

@@ -194,6 +194,6 @@ }

function fitLeftInner($from, depth, placed, placedBelow) {
let content = Fragment.empty, openRight = 0, placedHere = placed[depth]
let content = Fragment.empty, openEnd = 0, placedHere = placed[depth]
if ($from.depth > depth) {
let inner = fitLeftInner($from, depth + 1, placed, placedBelow || placedHere)
openRight = inner.openRight + 1
openEnd = inner.openEnd + 1
content = Fragment.from($from.node(depth + 1).copy(inner.content))

@@ -204,37 +204,37 @@ }

content = content.append(placedHere.content)
openRight = placedHere.openRight
openEnd = placedHere.openEnd
}
if (placedBelow) {
content = content.append($from.node(depth).contentMatchAt($from.indexAfter(depth)).fillBefore(Fragment.empty, true))
openRight = 0
openEnd = 0
}
return {content, openRight}
return {content, openEnd}
}
function fitLeft($from, placed) {
let {content, openRight} = fitLeftInner($from, 0, placed, false)
return new Slice(content, $from.depth, openRight || 0)
let {content, openEnd} = fitLeftInner($from, 0, placed, false)
return new Slice(content, $from.depth, openEnd || 0)
}
function fitRightJoin(content, parent, $from, $to, depth, openLeft, openRight) {
let match, count = content.childCount, matchCount = count - (openRight > 0 ? 1 : 0)
if (openLeft < 0)
function fitRightJoin(content, parent, $from, $to, depth, openStart, openEnd) {
let match, count = content.childCount, matchCount = count - (openEnd > 0 ? 1 : 0)
if (openStart < 0)
match = parent.contentMatchAt(matchCount)
else if (count == 1 && openRight > 0)
match = $from.node(depth).contentMatchAt(openLeft ? $from.index(depth) : $from.indexAfter(depth))
else if (count == 1 && openEnd > 0)
match = $from.node(depth).contentMatchAt(openStart ? $from.index(depth) : $from.indexAfter(depth))
else
match = $from.node(depth).contentMatchAt($from.indexAfter(depth))
.matchFragment(content, count > 0 && openLeft ? 1 : 0, matchCount)
.matchFragment(content, count > 0 && openStart ? 1 : 0, matchCount)
let toNode = $to.node(depth)
if (openRight > 0 && depth < $to.depth) {
if (openEnd > 0 && depth < $to.depth) {
let after = toNode.content.cutByIndex($to.indexAfter(depth)).addToStart(content.lastChild)
let joinable = match.fillBefore(after, true)
// Can't insert content if there's a single node stretched across this gap
if (joinable && joinable.size && openLeft > 0 && count == 1) joinable = null
if (joinable && joinable.size && openStart > 0 && count == 1) joinable = null
if (joinable) {
let inner = fitRightJoin(content.lastChild.content, content.lastChild, $from, $to,
depth + 1, count == 1 ? openLeft - 1 : -1, openRight - 1)
depth + 1, count == 1 ? openStart - 1 : -1, openEnd - 1)
if (inner) {

@@ -249,4 +249,4 @@ let last = content.lastChild.copy(inner)

}
if (openRight > 0)
match = match.matchNode(count == 1 && openLeft > 0 ? $from.node(depth + 1) : content.lastChild)
if (openEnd > 0)
match = match.matchNode(count == 1 && openStart > 0 ? $from.node(depth + 1) : content.lastChild)

@@ -260,5 +260,5 @@ // If we're here, the next level can't be joined, so we see what

if (openRight > 0) {
let closed = fitRightClosed(content.lastChild, openRight - 1, $from, depth + 1,
count == 1 ? openLeft - 1 : -1)
if (openEnd > 0) {
let closed = fitRightClosed(content.lastChild, openEnd - 1, $from, depth + 1,
count == 1 ? openStart - 1 : -1)
content = content.replaceChild(count - 1, closed)

@@ -272,13 +272,13 @@ }

function fitRightClosed(node, openRight, $from, depth, openLeft) {
function fitRightClosed(node, openEnd, $from, depth, openStart) {
let match, content = node.content, count = content.childCount
if (openLeft >= 0)
if (openStart >= 0)
match = $from.node(depth).contentMatchAt($from.indexAfter(depth))
.matchFragment(content, openLeft > 0 ? 1 : 0, count)
.matchFragment(content, openStart > 0 ? 1 : 0, count)
else
match = node.contentMatchAt(count)
if (openRight > 0) {
let closed = fitRightClosed(content.lastChild, openRight - 1, $from, depth + 1,
count == 1 ? openLeft - 1 : -1)
if (openEnd > 0) {
let closed = fitRightClosed(content.lastChild, openEnd - 1, $from, depth + 1,
count == 1 ? openStart - 1 : -1)
content = content.replaceChild(count - 1, closed)

@@ -297,9 +297,9 @@ }

function normalizeSlice(content, openLeft, openRight) {
while (openLeft > 0 && openRight > 0 && content.childCount == 1) {
function normalizeSlice(content, openStart, openEnd) {
while (openStart > 0 && openEnd > 0 && content.childCount == 1) {
content = content.firstChild.content
openLeft--
openRight--
openStart--
openEnd--
}
return new Slice(content, openLeft, openRight)
return new Slice(content, openStart, openEnd)
}

@@ -309,9 +309,9 @@

function fitRight($from, $to, slice) {
let fitted = fitRightJoin(slice.content, $from.node(0), $from, $to, 0, slice.openLeft, slice.openRight)
let fitted = fitRightJoin(slice.content, $from.node(0), $from, $to, 0, slice.openStart, slice.openEnd)
if (!fitted) return null
return normalizeSlice(fitted, slice.openLeft, $to.depth)
return normalizeSlice(fitted, slice.openStart, $to.depth)
}
function fitsTrivially($from, $to, slice) {
return !slice.openLeft && !slice.openRight && $from.start() == $to.start() &&
return !slice.openStart && !slice.openEnd && $from.start() == $to.start() &&
$from.parent.canReplace($from.index(), $to.index(), slice.content)

@@ -324,10 +324,10 @@ }

let match
if (!slice.openRight) {
let parent = $from.node($from.depth - (slice.openLeft - slice.openRight))
if (!slice.openEnd) {
let parent = $from.node($from.depth - (slice.openStart - slice.openEnd))
if (!parent.isTextblock) return false
match = parent.contentMatchAt(parent.childCount)
if (slice.size)
match = match.matchFragment(slice.content, slice.openLeft ? 1 : 0)
match = match.matchFragment(slice.content, slice.openStart ? 1 : 0)
} else {
let parent = nodeRight(slice.content, slice.openRight)
let parent = nodeRight(slice.content, slice.openEnd)
if (!parent.isTextblock) return false

@@ -370,3 +370,3 @@ match = parent.contentMatchAt(parent.childCount)

// : (ResolvedPos, Slice) → [{content: Fragment, openRight: number, depth: number}]
// : (ResolvedPos, Slice) → [{content: Fragment, openEnd: number, depth: number}]
function placeSlice($from, slice) {

@@ -378,3 +378,3 @@ let dFrom = $from.depth, unplaced = null

// each open fragment.
for (let dSlice = slice.openLeft;; --dSlice) {
for (let dSlice = slice.openStart;; --dSlice) {
// Get the components of the node at this level

@@ -388,3 +388,3 @@ let curType, curAttrs, curFragment

}
if (dSlice < slice.openLeft) curFragment = curFragment.cut(curFragment.firstChild.nodeSize)
if (dSlice < slice.openStart) curFragment = curFragment.cut(curFragment.firstChild.nodeSize)
} else { // Outside slice, in generated wrappers (see below)

@@ -412,3 +412,3 @@ curFragment = Fragment.empty

content: found.fragment,
openRight: endOfContent(slice, dSlice) ? slice.openRight - dSlice : 0,
openEnd: endOfContent(slice, dSlice) ? slice.openEnd - dSlice : 0,
depth: found.depth

@@ -415,0 +415,0 @@ }

@@ -13,3 +13,4 @@ const {Slice, Fragment} = require("prosemirror-model")

// Try to find a target depth to which the content in the given range
// can be lifted.
// can be lifted. Will not go across
// [isolating](#model.NodeSpec.isolating) parent nodes.
function liftTarget(range) {

@@ -19,3 +20,5 @@ let parent = range.parent

for (let depth = range.depth;; --depth) {
let node = range.$from.node(depth), index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth)
let node = range.$from.node(depth)
if (node.type.spec.isolating) break
let index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth)
if (depth < range.depth && node.canReplace(index, endIndex, content))

@@ -40,3 +43,3 @@ return depth

let before = Fragment.empty, openLeft = 0
let before = Fragment.empty, openStart = 0
for (let d = depth, splitting = false; d > target; d--)

@@ -46,7 +49,7 @@ if (splitting || $from.index(d) > 0) {

before = Fragment.from($from.node(d).copy(before))
openLeft++
openStart++
} else {
start--
}
let after = Fragment.empty, openRight = 0
let after = Fragment.empty, openEnd = 0
for (let d = depth, splitting = false; d > target; d--)

@@ -56,3 +59,3 @@ if (splitting || $to.after(d + 1) < $to.end(d)) {

after = Fragment.from($to.node(d).copy(after))
openRight++
openEnd++
} else {

@@ -63,4 +66,4 @@ end++

return this.step(new ReplaceAroundStep(start, end, gapStart, gapEnd,
new Slice(before.append(after), openLeft, openRight),
before.size - openLeft, true))
new Slice(before.append(after), openStart, openEnd),
before.size - openStart, true))
}

@@ -155,3 +158,3 @@

// :: (Node, number, ?[?{type: NodeType, attrs: ?Object}]) → bool
// :: (Node, number, number, ?[?{type: NodeType, attrs: ?Object}]) → bool
// Check whether splitting at the given position is allowed.

@@ -158,0 +161,0 @@ function canSplit(doc, pos, depth = 1, typesAfter) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc