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

prosemirror-dropcursor

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-dropcursor - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

CHANGELOG.md

34

dist/dropcursor.js

@@ -6,2 +6,3 @@ 'use strict';

var prosemirrorState = require('prosemirror-state');
var prosemirrorTransform = require('prosemirror-transform');
var prosemirrorView = require('prosemirror-view');

@@ -18,7 +19,7 @@

var timeout = null;
function scheduleRemoval(view) {
function scheduleRemoval(view, time) {
clearTimeout(timeout);
timeout = setTimeout(function () {
if (plugin.getState(view.state)) { dispatch(view, {type: "remove"}); }
}, 1000);
}, time);
}

@@ -34,3 +35,3 @@

if (gecko && linux) { return null }
var command = tr.getMeta(plugin);
var command = tr.getMeta("uiEvent") == "drop" ? {type: "remove"} : tr.getMeta(plugin);
if (!command) { return prev }

@@ -48,8 +49,10 @@ if (command.type == "set") { return pluginStateFor(state, command.pos, options) }

var target = pos.pos;
if (view.dragging)
{ target = dropPos(view.dragging.slice, view.state.doc.resolve(target)); }
if (view.dragging && view.dragging.slice) {
target = prosemirrorTransform.dropPoint(view.state.doc, target, view.dragging.slice);
if (target == null) { target = pos.pos; }
}
if (!active || active.pos != target)
{ dispatch(view, {type: "set", pos: target}); }
}
scheduleRemoval(view);
scheduleRemoval(view, 5000);
return false

@@ -59,3 +62,3 @@ },

dragend: function dragend(view) {
if (plugin.getState(view.state)) { dispatch(view, {type: "remove"}); }
scheduleRemoval(view, 20);
return false

@@ -65,3 +68,3 @@ },

drop: function drop(view) {
if (plugin.getState(view.state)) { dispatch(view, {type: "remove"}); }
scheduleRemoval(view, 20);
return false

@@ -71,3 +74,3 @@ },

dragleave: function dragleave(view, event) {
if (event.target == view.dom) { dispatch(view, {type: "remove"}); }
if (event.target == view.dom || !view.dom.contains(event.relatedTarget)) { dispatch(view, {type: "remove"}); }
return false

@@ -109,16 +112,3 @@ }

function dropPos(slice, $pos) {
if (!slice || !slice.content.size) { return $pos.pos }
var content = slice.content;
for (var i = 0; i < slice.openStart; i++) { content = content.firstChild.content; }
for (var d = $pos.depth; d >= 0; d--) {
var bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1;
var insertPos = $pos.index(d) + (bias > 0 ? 1 : 0);
if ($pos.node(d).canReplace(insertPos, insertPos, content))
{ return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1) }
}
return $pos.pos
}
exports.dropCursor = dropCursor;
//# sourceMappingURL=dropcursor.js.map
{
"name": "prosemirror-dropcursor",
"version": "1.0.0",
"version": "1.0.1",
"description": "Drop cursor plugin for ProseMirror",

@@ -24,3 +24,4 @@ "main": "dist/dropcursor.js",

"prosemirror-state": "^1.0.0",
"prosemirror-view": "^1.0.0"
"prosemirror-view": "^1.1.0",
"prosemirror-transform": "^1.1.0"
},

@@ -27,0 +28,0 @@ "scripts": {

import {Plugin} from "prosemirror-state"
import {dropPoint} from "prosemirror-transform"
import {Decoration, DecorationSet} from "prosemirror-view"

@@ -13,7 +14,7 @@

let timeout = null
function scheduleRemoval(view) {
function scheduleRemoval(view, time) {
clearTimeout(timeout)
timeout = setTimeout(() => {
if (plugin.getState(view.state)) dispatch(view, {type: "remove"})
}, 1000)
}, time)
}

@@ -29,3 +30,3 @@

if (gecko && linux) return null
let command = tr.getMeta(plugin)
let command = tr.getMeta("uiEvent") == "drop" ? {type: "remove"} : tr.getMeta(plugin)
if (!command) return prev

@@ -43,8 +44,10 @@ if (command.type == "set") return pluginStateFor(state, command.pos, options)

let target = pos.pos
if (view.dragging)
target = dropPos(view.dragging.slice, view.state.doc.resolve(target))
if (view.dragging && view.dragging.slice) {
target = dropPoint(view.state.doc, target, view.dragging.slice)
if (target == null) target = pos.pos
}
if (!active || active.pos != target)
dispatch(view, {type: "set", pos: target})
}
scheduleRemoval(view)
scheduleRemoval(view, 5000)
return false

@@ -54,3 +57,3 @@ },

dragend(view) {
if (plugin.getState(view.state)) dispatch(view, {type: "remove"})
scheduleRemoval(view, 20)
return false

@@ -60,3 +63,3 @@ },

drop(view) {
if (plugin.getState(view.state)) dispatch(view, {type: "remove"})
scheduleRemoval(view, 20)
return false

@@ -66,3 +69,3 @@ },

dragleave(view, event) {
if (event.target == view.dom) dispatch(view, {type: "remove"})
if (event.target == view.dom || !view.dom.contains(event.relatedTarget)) dispatch(view, {type: "remove"})
return false

@@ -103,14 +106,1 @@ }

}
function dropPos(slice, $pos) {
if (!slice || !slice.content.size) return $pos.pos
let content = slice.content
for (let i = 0; i < slice.openStart; i++) content = content.firstChild.content
for (let d = $pos.depth; d >= 0; d--) {
let bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1
let insertPos = $pos.index(d) + (bias > 0 ? 1 : 0)
if ($pos.node(d).canReplace(insertPos, insertPos, content))
return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1)
}
return $pos.pos
}

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