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

prosemirror-commands

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-commands - npm Package Compare versions

Comparing version 0.11.2 to 0.12.0

160

dist/commands.js

@@ -28,4 +28,4 @@ var ref = require("prosemirror-transform");

function deleteSelection(state, onAction) {
if (state.selection.empty) return false
if (onAction) onAction(state.tr.replaceSelection().scrollAction())
if (state.selection.empty) { return false }
if (onAction) { onAction(state.tr.replaceSelection().scrollAction()) }
return true

@@ -45,10 +45,10 @@ }

var empty = ref.empty;
if (!empty || $head.parentOffset > 0) return false
if (!empty || $head.parentOffset > 0) { return false }
// Find the node before this one
var before, cut
for (var i = $head.depth - 1; !before && i >= 0; i--) if ($head.index(i) > 0) {
for (var i = $head.depth - 1; !before && i >= 0; i--) { if ($head.index(i) > 0) {
cut = $head.before(i + 1)
before = $head.node(i).child($head.index(i) - 1)
}
} }

@@ -58,4 +58,4 @@ // If there is no node before this, try to lift

var range = $head.blockRange(), target = range && liftTarget(range)
if (target == null) return false
if (onAction) onAction(state.tr.lift(range, target).scrollAction())
if (target == null) { return false }
if (onAction) { onAction(state.tr.lift(range, target).scrollAction()) }
return true

@@ -77,3 +77,3 @@ }

if (before.isLeaf) {
if (onAction) onAction(state.tr.delete(cut - before.nodeSize, cut).scrollAction())
if (onAction) { onAction(state.tr.delete(cut - before.nodeSize, cut).scrollAction()) }
return true

@@ -97,3 +97,3 @@ }

var empty = ref.empty;
if (!empty || $head.parentOffset < $head.parent.content.size) return false
if (!empty || $head.parentOffset < $head.parent.content.size) { return false }

@@ -111,7 +111,7 @@ // Find the node after this one

// If there is no node after this, there's nothing to do
if (!after) return false
if (!after) { return false }
// If the node doesn't allow children, delete it
if (after.isLeaf) {
if (onAction) onAction(state.tr.delete(cut, cut + after.nodeSize).scrollAction())
if (onAction) { onAction(state.tr.delete(cut, cut + after.nodeSize).scrollAction()) }
return true

@@ -131,3 +131,3 @@ }

var empty = ref.empty;
if (!empty || $head.parentOffset == 0) return false
if (!empty || $head.parentOffset == 0) { return false }
if (onAction) {

@@ -148,5 +148,5 @@ var dest = moveBackward($head, "char")

var empty = ref.empty;
if (!empty || $head.parentOffset == 0) return false
if (!empty || $head.parentOffset == 0) { return false }
if (onAction)
onAction(state.tr.delete(moveBackward($head, "word"), $head.pos).scrollAction())
{ onAction(state.tr.delete(moveBackward($head, "word"), $head.pos).scrollAction()) }
return true

@@ -163,5 +163,5 @@ }

var empty = ref.empty;
if (!empty || $head.parentOffset == $head.parent.content.size) return false
if (!empty || $head.parentOffset == $head.parent.content.size) { return false }
if (onAction)
onAction(state.tr.delete($head.pos, moveForward($head, "char")).scrollAction())
{ onAction(state.tr.delete($head.pos, moveForward($head, "char")).scrollAction()) }
return true

@@ -178,5 +178,5 @@ }

var empty = ref.empty;
if (!empty || $head.parentOffset == $head.parent.content.size) return false
if (!empty || $head.parentOffset == $head.parent.content.size) { return false }
if (onAction)
onAction(state.tr.delete($head.pos, moveForward($head, "word")).scrollAction())
{ onAction(state.tr.delete($head.pos, moveForward($head, "word")).scrollAction()) }
return true

@@ -196,11 +196,11 @@ }

if (node) {
if (node.isTextblock || !canJoin(state.doc, from)) return false
if (node.isTextblock || !canJoin(state.doc, from)) { return false }
point = from
} else {
point = joinPoint(state.doc, from, -1)
if (point == null) return false
if (point == null) { return false }
}
if (onAction) {
var tr = state.tr.join(point)
if (state.selection.node) tr.setSelection(new NodeSelection(tr.doc.resolve(point - state.doc.resolve(point).nodeBefore.nodeSize)))
if (state.selection.node) { tr.setSelection(new NodeSelection(tr.doc.resolve(point - state.doc.resolve(point).nodeBefore.nodeSize))) }
onAction(tr.scrollAction())

@@ -218,6 +218,6 @@ }

var point = joinPointBelow(state)
if (!point) return false
if (!point) { return false }
if (onAction) {
var tr = state.tr.join(point)
if (node) tr.setSelection(new NodeSelection(tr.doc.resolve(nodeAt)))
if (node) { tr.setSelection(new NodeSelection(tr.doc.resolve(nodeAt))) }
onAction(tr.scrollAction())

@@ -237,4 +237,4 @@ }

var range = $from.blockRange($to), target = range && liftTarget(range)
if (target == null) return false
if (onAction) onAction(state.tr.lift(range, target).scrollAction())
if (target == null) { return false }
if (onAction) { onAction(state.tr.lift(range, target).scrollAction()) }
return true

@@ -253,5 +253,5 @@ }

var node = ref.node;
if (node) return false
if (!$from.parent.type.spec.code || $to.pos >= $from.end()) return false
if (onAction) onAction(state.tr.insertText("\n").scrollAction())
if (node) { return false }
if (!$from.parent.type.spec.code || $to.pos >= $from.end()) { return false }
if (onAction) { onAction(state.tr.insertText("\n").scrollAction()) }
return true

@@ -269,5 +269,5 @@ }

var node = ref.node;
if (!node || !node.isBlock) return false
if (!node || !node.isBlock) { return false }
var type = $from.parent.defaultContentType($to.indexAfter())
if (!type || !type.isTextblock) return false
if (!type || !type.isTextblock) { return false }
if (onAction) {

@@ -290,7 +290,7 @@ var side = ($from.parentOffset ? $to : $from).pos

var empty = ref.empty;
if (!empty || $head.parent.content.size) return false
if (!empty || $head.parent.content.size) { return false }
if ($head.depth > 1 && $head.after() != $head.end(-1)) {
var before = $head.before()
if (canSplit(state.doc, before)) {
if (onAction) onAction(state.tr.split(before).scrollAction())
if (onAction) { onAction(state.tr.split(before).scrollAction()) }
return true

@@ -300,4 +300,4 @@ }

var range = $head.blockRange(), target = range && liftTarget(range)
if (target == null) return false
if (onAction) onAction(state.tr.lift(range, target).scrollAction())
if (target == null) { return false }
if (onAction) { onAction(state.tr.lift(range, target).scrollAction()) }
return true

@@ -316,4 +316,4 @@ }

if (node && node.isBlock) {
if (!$from.parentOffset || !canSplit(state.doc, $from.pos)) return false
if (onAction) onAction(state.tr.split($from.pos).scrollAction())
if (!$from.parentOffset || !canSplit(state.doc, $from.pos)) { return false }
if (onAction) { onAction(state.tr.split($from.pos).scrollAction()) }
return true

@@ -336,3 +336,3 @@ }

$from.node(-1).canReplace($from.index(-1), $from.indexAfter(-1), Fragment.from(deflt.create(), $from.parent)))
tr.setNodeType($from.before(), deflt)
{ tr.setNodeType($from.before(), deflt) }
}

@@ -351,10 +351,10 @@ onAction(tr.scrollAction())

if (sel.node) {
if (!sel.$from.depth) return false
if (!sel.$from.depth) { return false }
pos = sel.$from.before()
} else {
var same = sel.$head.sameDepth(sel.$anchor)
if (same == 0) return false
if (same == 0) { return false }
pos = sel.$head.before(same)
}
if (onAction) onAction(new NodeSelection(state.doc.resolve(pos)).action())
if (onAction) { onAction(new NodeSelection(state.doc.resolve(pos)).action()) }
return true

@@ -365,3 +365,3 @@ }

function deleteBarrier(state, cut, onAction) {
var $cut = state.doc.resolve(cut), before = $cut.nodeBefore, after = $cut.nodeAfter, conn
var $cut = state.doc.resolve(cut), before = $cut.nodeBefore, after = $cut.nodeAfter, conn, match
if (canJoin(state.doc, cut)) {

@@ -372,15 +372,17 @@ if (onAction) {

$cut.parent.canReplace($cut.index() - 1, $cut.index()))
tr.setNodeType(cut - before.nodeSize, after.type, after.attrs)
{ tr.setNodeType(cut - before.nodeSize, after.type, after.attrs) }
onAction(tr.scrollAction())
}
return true
} else if (after.isTextblock && (conn = before.contentMatchAt($cut.index()).findWrapping(after.type, after.attrs))) {
} else if (after.isTextblock && $cut.parent.canReplace($cut.index(), $cut.index() + 1) &&
(conn = (match = before.contentMatchAt(before.childCount)).findWrapping(after.type, after.attrs)) &&
match.matchType((conn[0] || after).type, (conn[0] || after).attrs).validEnd()) {
if (onAction) {
var end = cut + after.nodeSize, wrap = Fragment.empty
for (var i = conn.length - 1; i >= 0; i--)
wrap = Fragment.from(conn[i].type.create(conn[i].attrs, wrap))
{ wrap = Fragment.from(conn[i].type.create(conn[i].attrs, wrap)) }
wrap = Fragment.from(before.copy(wrap))
var tr$1 = state.tr.step(new ReplaceAroundStep(cut - 1, end, cut, end, new Slice(wrap, 1, 0), conn.length, true))
var joinAt = end + 2 * conn.length
if (canJoin(tr$1.doc, joinAt)) tr$1.join(joinAt)
if (canJoin(tr$1.doc, joinAt)) { tr$1.join(joinAt) }
onAction(tr$1.scrollAction())

@@ -392,4 +394,4 @@ }

var range = selAfter.$from.blockRange(selAfter.$to), target = range && liftTarget(range)
if (target == null) return false
if (onAction) onAction(state.tr.lift(range, target).scrollAction())
if (target == null) { return false }
if (onAction) { onAction(state.tr.lift(range, target).scrollAction()) }
return true

@@ -402,3 +404,3 @@ }

if (by != "char" && by != "word")
throw new RangeError("Unknown motion unit: " + by)
{ throw new RangeError("Unknown motion unit: " + by) }

@@ -409,8 +411,8 @@ var parent = $pos.parent, offset = $pos.parentOffset

for (;;) {
if (offset == 0) return pos
if (offset == 0) { return pos }
var ref = parent.childBefore(offset);
var start = ref.offset;
var node = ref.node;
if (!node) return pos
if (!node.isText) return cat ? pos : pos - 1
if (!node) { return pos }
if (!node.isText) { return cat ? pos : pos - 1 }

@@ -420,3 +422,3 @@ if (by == "char") {

if (!isExtendingCharAt(node.text, i - 1))
return pos - 1
{ return pos - 1 }
offset--

@@ -431,4 +433,4 @@ pos--

var nextCharCat = charCategory(node.text.charAt(i$1 - 1))
if (cat == null || counted == 1 && cat == "space") cat = nextCharCat
else if (cat != nextCharCat) return pos
if (cat == null || counted == 1 && cat == "space") { cat = nextCharCat }
else if (cat != nextCharCat) { return pos }
offset--

@@ -444,3 +446,3 @@ pos--

if (by != "char" && by != "word")
throw new RangeError("Unknown motion unit: " + by)
{ throw new RangeError("Unknown motion unit: " + by) }

@@ -451,8 +453,8 @@ var parent = $pos.parent, offset = $pos.parentOffset, pos = $pos.pos

for (;;) {
if (offset == parent.content.size) return pos
if (offset == parent.content.size) { return pos }
var ref = parent.childAfter(offset);
var start = ref.offset;
var node = ref.node;
if (!node) return pos
if (!node.isText) return cat ? pos : pos + 1
if (!node) { return pos }
if (!node.isText) { return cat ? pos : pos + 1 }

@@ -462,3 +464,3 @@ if (by == "char") {

if (!isExtendingCharAt(node.text, i + 1))
return pos + 1
{ return pos + 1 }
offset++

@@ -470,4 +472,4 @@ pos++

var nextCharCat = charCategory(node.text.charAt(i$1))
if (cat == null || counted == 1 && cat == "space") cat = nextCharCat
else if (cat != nextCharCat) return pos
if (cat == null || counted == 1 && cat == "space") { cat = nextCharCat }
else if (cat != nextCharCat) { return pos }
offset++

@@ -487,4 +489,4 @@ pos++

var to = ref.to;
if (node) return canJoin(state.doc, to) ? to : null
else return joinPoint(state.doc, to, 1)
if (node) { return canJoin(state.doc, to) ? to : null }
else { return joinPoint(state.doc, to, 1) }
}

@@ -501,4 +503,4 @@

var range = $from.blockRange($to), wrapping = range && findWrapping(range, nodeType, attrs)
if (!wrapping) return false
if (onAction) onAction(state.tr.wrap(range, wrapping).scrollAction())
if (!wrapping) { return false }
if (onAction) { onAction(state.tr.wrap(range, wrapping).scrollAction()) }
return true

@@ -522,9 +524,9 @@ }

} else {
if (!$from.depth || $to.pos > $from.end()) return false
if (!$from.depth || $to.pos > $from.end()) { return false }
depth = $from.depth - 1
}
var target = node || $from.parent
if (!target.isTextblock || target.hasMarkup(nodeType, attrs)) return false
if (!target.isTextblock || target.hasMarkup(nodeType, attrs)) { return false }
var index = $from.index(depth)
if (!$from.node(depth).canReplaceWith(index, index + 1, nodeType)) return false
if (!$from.node(depth).canReplaceWith(index, index + 1, nodeType)) { return false }
if (onAction) {

@@ -545,3 +547,3 @@ var where = $from.before(depth + 1)

doc.nodesBetween(from, to, function (node) {
if (can) return false
if (can) { return false }
can = node.isTextblock && node.contentMatchAt(0).allowsMark(type)

@@ -566,14 +568,14 @@ })

var to = ref.to;
if (!markApplies(state.doc, from, to, markType)) return false
if (!markApplies(state.doc, from, to, markType)) { return false }
if (onAction) {
if (empty) {
if (markType.isInSet(state.storedMarks || state.doc.marksAt(from)))
onAction({type: "removeStoredMark", markType: markType})
{ onAction({type: "removeStoredMark", markType: markType}) }
else
onAction({type: "addStoredMark", mark: markType.create(attrs)})
{ onAction({type: "addStoredMark", mark: markType.create(attrs)}) }
} else {
if (state.doc.rangeHasMark(from, to, markType))
onAction(state.tr.removeMark(from, to, markType).scrollAction())
{ onAction(state.tr.removeMark(from, to, markType).scrollAction()) }
else
onAction(state.tr.addMark(from, to, markType.create(attrs)).scrollAction())
{ onAction(state.tr.addMark(from, to, markType.create(attrs)).scrollAction()) }
}

@@ -595,3 +597,3 @@ }

for (var i = 0; i < commands.length; i++)
if (commands[i](state, onAction)) return true
{ if (commands[i](state, onAction)) { return true } }
return false

@@ -632,12 +634,12 @@ }

var extra = {
"Ctrl-KeyH": baseKeymap["Backspace"],
"Ctrl-h": baseKeymap["Backspace"],
"Alt-Backspace": baseKeymap["Cmd-Backspace"],
"Ctrl-KeyD": baseKeymap["Delete"],
"Ctrl-d": baseKeymap["Delete"],
"Ctrl-Alt-Backspace": baseKeymap["Cmd-Delete"],
"Alt-Delete": baseKeymap["Cmd-Delete"],
"Alt-KeyD": baseKeymap["Cmd-Delete"]
"Alt-d": baseKeymap["Cmd-Delete"]
}
for (var prop in extra) baseKeymap[prop] = extra[prop]
for (var prop in extra) { baseKeymap[prop] = extra[prop] }
}
exports.baseKeymap = baseKeymap
{
"name": "prosemirror-commands",
"version": "0.11.2",
"version": "0.12.0",
"description": "Editing commands for ProseMirror",

@@ -19,5 +19,5 @@ "main": "dist/commands.js",

"dependencies": {
"prosemirror-model": "^0.11.0",
"prosemirror-transform": "^0.11.0",
"prosemirror-state": "^0.11.0",
"prosemirror-model": "^0.12.0",
"prosemirror-transform": "^0.12.0",
"prosemirror-state": "^0.12.0",
"extending-char": "^1.0.0"

@@ -24,0 +24,0 @@ },

@@ -301,3 +301,3 @@ const {joinPoint, canJoin, findWrapping, liftTarget, canSplit, ReplaceAroundStep} = require("prosemirror-transform")

function deleteBarrier(state, cut, onAction) {
let $cut = state.doc.resolve(cut), before = $cut.nodeBefore, after = $cut.nodeAfter, conn
let $cut = state.doc.resolve(cut), before = $cut.nodeBefore, after = $cut.nodeAfter, conn, match
if (canJoin(state.doc, cut)) {

@@ -312,3 +312,5 @@ if (onAction) {

return true
} else if (after.isTextblock && (conn = before.contentMatchAt($cut.index()).findWrapping(after.type, after.attrs))) {
} else if (after.isTextblock && $cut.parent.canReplace($cut.index(), $cut.index() + 1) &&
(conn = (match = before.contentMatchAt(before.childCount)).findWrapping(after.type, after.attrs)) &&
match.matchType((conn[0] || after).type, (conn[0] || after).attrs).validEnd()) {
if (onAction) {

@@ -535,8 +537,8 @@ let end = cut + after.nodeSize, wrap = Fragment.empty

let extra = {
"Ctrl-KeyH": baseKeymap["Backspace"],
"Ctrl-h": baseKeymap["Backspace"],
"Alt-Backspace": baseKeymap["Cmd-Backspace"],
"Ctrl-KeyD": baseKeymap["Delete"],
"Ctrl-d": baseKeymap["Delete"],
"Ctrl-Alt-Backspace": baseKeymap["Cmd-Delete"],
"Alt-Delete": baseKeymap["Cmd-Delete"],
"Alt-KeyD": baseKeymap["Cmd-Delete"]
"Alt-d": baseKeymap["Cmd-Delete"]
}

@@ -543,0 +545,0 @@ for (let prop in extra) baseKeymap[prop] = extra[prop]

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