cytoscape-clipboard
Advanced tools
Comparing version 2.1.1 to 2.2.0
@@ -16,2 +16,11 @@ ;(function () { | ||
//Global variables to hold x and y coordinates in case of pasting | ||
var mouseX, mouseY; | ||
cy.on('mousemove', function onmousemove (e) { | ||
var pos = e.position || e.cyPosition; | ||
mouseX = pos.x; | ||
mouseY = pos.y; | ||
}); | ||
var options = { | ||
@@ -64,3 +73,3 @@ clipboardSize: 0, | ||
function changeIds(jsons) { | ||
function changeIds(jsons, pasteAtMouseLoc) { | ||
jsons = $.extend(true, [], jsons); | ||
@@ -74,2 +83,38 @@ for (var i = 0; i < jsons.length; i++) { | ||
//Paste the elements centered at the mouse location | ||
var topLeftX, topLeftY; | ||
var bottomRightX, bottomRightY; | ||
var centerX, centerY; | ||
var diffX, diffY; | ||
//Checks only for nodes | ||
if (jsons[0] !== undefined && jsons[0].position.x) | ||
{ | ||
topLeftX = jsons[0].position.x; | ||
topLeftY = jsons[0].position.y; | ||
bottomRightX = jsons[0].position.x; | ||
bottomRightY = jsons[0].position.y; | ||
for (var k = 1; k < jsons.length; k++) { | ||
var ele = jsons[k]; | ||
if (ele.position.x < topLeftX) { | ||
topLeftX = ele.position.x; | ||
} | ||
if (ele.position.y < topLeftY) { | ||
topLeftY = ele.position.y; | ||
} | ||
if (ele.position.x > bottomRightX) { | ||
bottomRightX = ele.position.x; | ||
} | ||
if (ele.position.y > bottomRightY) { | ||
bottomRightY = ele.position.y; | ||
} | ||
} | ||
centerX = (topLeftX+bottomRightX)/2; | ||
centerY = (topLeftY+bottomRightY)/2; | ||
diffX = mouseX -centerX; | ||
diffY = mouseY - centerY; | ||
} | ||
for (var j = 0; j < jsons.length; j++) { | ||
@@ -83,7 +128,13 @@ var json = jsons[j]; | ||
} | ||
if (json.position.x) { | ||
json.position.x += 50; | ||
json.position.y += 50; | ||
if (pasteAtMouseLoc == false) { | ||
json.position.x += 50; | ||
json.position.y += 50; | ||
} | ||
else { | ||
json.position.x += diffX; | ||
json.position.y += diffY; | ||
} | ||
} | ||
@@ -118,3 +169,3 @@ } | ||
}, | ||
paste: function (_id) { | ||
paste: function (_id, pasteAtMouseLoc) { | ||
var id = _id ? _id : getItemId(true); | ||
@@ -126,3 +177,3 @@ var res = cy.collection(); | ||
if (clipboard[id]) { | ||
var nodes = changeIds(clipboard[id].nodes); | ||
var nodes = changeIds(clipboard[id].nodes, pasteAtMouseLoc); | ||
var edges = changeIds(clipboard[id].edges); | ||
@@ -146,3 +197,3 @@ oldIdToNewId = {}; | ||
ur.action("paste", function (eles) { | ||
return eles.firstTime ? scratchPad.instance.paste(eles.id) : eles.restore(); | ||
return eles.firstTime ? scratchPad.instance.paste(eles.id, eles.pasteAtMouseLoc) : eles.restore(); | ||
}, function (eles) { | ||
@@ -149,0 +200,0 @@ return eles.remove(); |
{ | ||
"name": "cytoscape-clipboard", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "Adds copy-paste utilities to cytoscape.", | ||
@@ -5,0 +5,0 @@ "main": "cytoscape-clipboard.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
35460
663
2
2