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 1.0.5 to 1.0.6

CHANGELOG.md

31

dist/commands.js

@@ -132,3 +132,3 @@ 'use strict';

var tr = state.tr.deleteRange($cursor.before(), $cursor.after());
tr.setSelection(textblockAt(after, "start") ? prosemirrorState.Selection.findFrom($cut, 1)
tr.setSelection(textblockAt(after, "start") ? prosemirrorState.Selection.findFrom(tr.doc.resolve(tr.mapping.map($cut.pos)), 1)
: prosemirrorState.NodeSelection.create(tr.doc, tr.mapping.map($cut.pos)));

@@ -252,3 +252,3 @@ dispatch(tr.scrollIntoView());

if (!$head.parent.type.spec.code || !$head.sameParent($anchor)) { return false }
var above = $head.node(-1), after = $head.indexAfter(-1), type = above.defaultContentType(after);
var above = $head.node(-1), after = $head.indexAfter(-1), type = above.contentMatchAt(after).defaultType;
if (!above.canReplaceWith(after, after, type)) { return false }

@@ -271,3 +271,3 @@ if (dispatch) {

if ($from.parent.inlineContent || $to.parent.inlineContent) { return false }
var type = $from.parent.defaultContentType($to.indexAfter());
var type = $from.parent.contentMatchAt($to.indexAfter()).defaultType;
if (!type || !type.isTextblock) { return false }

@@ -316,2 +316,4 @@ if (dispatch) {

if (!$from.parent.isBlock) { return false }
if (dispatch) {

@@ -321,3 +323,3 @@ var atEnd = $to.parentOffset == $to.parent.content.size;

if (state.selection instanceof prosemirrorState.TextSelection) { tr.deleteSelection(); }
var deflt = $from.depth == 0 ? null : $from.node(-1).defaultContentType($from.indexAfter(-1));
var deflt = $from.depth == 0 ? null : $from.node(-1).contentMatchAt($from.indexAfter(-1)).defaultType;
var types = atEnd && deflt ? [{type: deflt}] : null;

@@ -439,4 +441,4 @@ var can = prosemirrorTransform.canSplit(tr.doc, $from.pos, 1, types);

// :: (NodeType, ?Object) → (state: EditorState, dispatch: ?(tr: Transaction)) → bool
// Returns a command that tries to set the textblock around the
// selection to the given node type with the given attributes.
// Returns a command that tries to set the selected textblocks to the
// given node type with the given attributes.
function setBlockType(nodeType, attrs) {

@@ -447,13 +449,14 @@ return function(state, dispatch) {

var to = ref.to;
var firstTextblock = null, firstPos = -1;
var applicable = false;
state.doc.nodesBetween(from, to, function (node, pos) {
if (firstTextblock) { return false }
if (node.isTextblock) {
firstTextblock = node;
firstPos = pos;
if (applicable) { return false }
if (!node.isTextblock || node.hasMarkup(nodeType, attrs)) { return }
if (node.type == nodeType) {
applicable = true;
} else {
var $pos = state.doc.resolve(pos), index = $pos.index();
applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType);
}
});
if (!firstTextblock || firstTextblock.hasMarkup(nodeType, attrs)) { return false }
var $firstPos = state.doc.resolve(firstPos), index = $firstPos.index();
if (!$firstPos.parent.canReplaceWith(index, index + 1, nodeType)) { return false }
if (!applicable) { return false }
if (dispatch) { dispatch(state.tr.setBlockType(from, to, nodeType, attrs).scrollIntoView()); }

@@ -460,0 +463,0 @@ return true

{
"name": "prosemirror-commands",
"version": "1.0.5",
"version": "1.0.6",
"description": "Editing commands for ProseMirror",

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

@@ -125,3 +125,3 @@ import {joinPoint, canJoin, findWrapping, liftTarget, canSplit, ReplaceAroundStep} from "prosemirror-transform"

let tr = state.tr.deleteRange($cursor.before(), $cursor.after())
tr.setSelection(textblockAt(after, "start") ? Selection.findFrom($cut, 1)
tr.setSelection(textblockAt(after, "start") ? Selection.findFrom(tr.doc.resolve(tr.mapping.map($cut.pos)), 1)
: NodeSelection.create(tr.doc, tr.mapping.map($cut.pos)))

@@ -238,3 +238,3 @@ dispatch(tr.scrollIntoView())

if (!$head.parent.type.spec.code || !$head.sameParent($anchor)) return false
let above = $head.node(-1), after = $head.indexAfter(-1), type = above.defaultContentType(after)
let above = $head.node(-1), after = $head.indexAfter(-1), type = above.contentMatchAt(after).defaultType
if (!above.canReplaceWith(after, after, type)) return false

@@ -255,3 +255,3 @@ if (dispatch) {

if ($from.parent.inlineContent || $to.parent.inlineContent) return false
let type = $from.parent.defaultContentType($to.indexAfter())
let type = $from.parent.contentMatchAt($to.indexAfter()).defaultType
if (!type || !type.isTextblock) return false

@@ -297,2 +297,4 @@ if (dispatch) {

if (!$from.parent.isBlock) return false
if (dispatch) {

@@ -302,3 +304,3 @@ let atEnd = $to.parentOffset == $to.parent.content.size

if (state.selection instanceof TextSelection) tr.deleteSelection()
let deflt = $from.depth == 0 ? null : $from.node(-1).defaultContentType($from.indexAfter(-1))
let deflt = $from.depth == 0 ? null : $from.node(-1).contentMatchAt($from.indexAfter(-1)).defaultType
let types = atEnd && deflt ? [{type: deflt}] : null

@@ -415,18 +417,19 @@ let can = canSplit(tr.doc, $from.pos, 1, types)

// :: (NodeType, ?Object) → (state: EditorState, dispatch: ?(tr: Transaction)) → bool
// Returns a command that tries to set the textblock around the
// selection to the given node type with the given attributes.
// Returns a command that tries to set the selected textblocks to the
// given node type with the given attributes.
export function setBlockType(nodeType, attrs) {
return function(state, dispatch) {
let {from, to} = state.selection
let firstTextblock = null, firstPos = -1
let applicable = false
state.doc.nodesBetween(from, to, (node, pos) => {
if (firstTextblock) return false
if (node.isTextblock) {
firstTextblock = node
firstPos = pos
if (applicable) return false
if (!node.isTextblock || node.hasMarkup(nodeType, attrs)) return
if (node.type == nodeType) {
applicable = true
} else {
let $pos = state.doc.resolve(pos), index = $pos.index()
applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType)
}
})
if (!firstTextblock || firstTextblock.hasMarkup(nodeType, attrs)) return false
let $firstPos = state.doc.resolve(firstPos), index = $firstPos.index()
if (!$firstPos.parent.canReplaceWith(index, index + 1, nodeType)) return false
if (!applicable) return false
if (dispatch) dispatch(state.tr.setBlockType(from, to, nodeType, attrs).scrollIntoView())

@@ -433,0 +436,0 @@ return true

Sorry, the diff of this file is not supported yet

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