cytoscape-js-node-resizer 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,2 +1,32 @@
1
- A zero dependency extension for Cytoscape.js that adds node resizing functionality.
2
- ```
1
+
2
+ ## Zero dependency extension for Cytoscape.js that adds node resizing functionality.
3
+
4
+ A replacement for [cytoscape.js-noderesize](https://github.com/jhonatandarosa/cytoscape.js-noderesize)
5
+ and [cytoscape.js-node-editing](https://github.com/iVis-at-Bilkent/cytoscape.js-node-editing) that requires neither jQuery nor Konva.
6
+
7
+ ![Export-1735055174526](https://github.com/user-attachments/assets/3ea4de90-9720-40d0-a87c-f80456dec1d0)
8
+
9
+ Created and maintained by [NodeLand team](https://nodeland.io)
10
+
11
+
12
+ ## Installation
13
+ ```
14
+ npm install cytoscape-js-node-resizer
15
+ ```
16
+
17
+ ## Usage
18
+ ```js
19
+ import Cytoscape from "cytoscape";
20
+ import resizeHandler from "cytoscape-js-node-resizer";
21
+
22
+ Cytoscape.use(resizeHandler);
23
+
24
+ ...
25
+
26
+ cy.resizeHandler({
27
+ grapperColor: "#7711C0", // default color
28
+ grapperRadius: "50%", // default radius
29
+ grapperSize: "8px", // default size
30
+ });
31
+
32
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cytoscape-js-node-resizer",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A zero dependency extension for Cytoscape.js that adds node resizing functionality.",
5
5
  "main": "resizeHandler.js",
6
6
  "scripts": {
package/resizeHandler.js CHANGED
@@ -3,13 +3,16 @@
3
3
 
4
4
  let activeNode = null;
5
5
 
6
- const createResizeHandle = (node, cy) => {
6
+ const createResizeHandle = (node, cy, customStyle) => {
7
7
  let resizeBox = document.getElementById("resize-box");
8
8
 
9
9
  activeNode = node;
10
10
 
11
11
  const styles = {
12
12
  grapperColor: "#7711C0",
13
+ grapperRadius: "50%",
14
+ grapperSize: "8px",
15
+ ...customStyle,
13
16
  };
14
17
 
15
18
  if (!resizeBox) {
@@ -27,9 +30,10 @@
27
30
  // Grapper Handle - Bottom Right
28
31
  let resizeHandleBottomRight = document.createElement("div");
29
32
  resizeHandleBottomRight.id = "resize-handle-bottom-right";
30
- resizeHandleBottomRight.style.width = "8px";
31
- resizeHandleBottomRight.style.height = "8px";
32
- resizeHandleBottomRight.style.border = `"4px solid ${styles.grapperColor}"`;
33
+ resizeHandleBottomRight.style.width = styles.grapperSize;
34
+ resizeHandleBottomRight.style.height = styles.grapperSize;
35
+ resizeHandleBottomRight.style.backgroundColor = styles.grapperColor;
36
+ resizeHandleBottomRight.style.borderRadius = styles.grapperRadius;
33
37
  resizeHandleBottomRight.style.position = "absolute";
34
38
  resizeHandleBottomRight.style.cursor = "nwse-resize";
35
39
  parentDiv.appendChild(resizeHandleBottomRight);
@@ -37,9 +41,10 @@
37
41
  // Grapper Handle - Bottom Left
38
42
  let resizeHandleBottomLeft = document.createElement("div");
39
43
  resizeHandleBottomLeft.id = "resize-handle-bottom-left";
40
- resizeHandleBottomLeft.style.width = "8px";
41
- resizeHandleBottomLeft.style.height = "8px";
42
- resizeHandleBottomLeft.style.border = `"4px solid ${styles.grapperColor}"`;
44
+ resizeHandleBottomLeft.style.width = styles.grapperSize;
45
+ resizeHandleBottomLeft.style.height = styles.grapperSize;
46
+ resizeHandleBottomLeft.style.backgroundColor = styles.grapperColor;
47
+ resizeHandleBottomLeft.style.borderRadius = styles.grapperRadius;
43
48
  resizeHandleBottomLeft.style.position = "absolute";
44
49
  resizeHandleBottomLeft.style.cursor = "nesw-resize";
45
50
  parentDiv.appendChild(resizeHandleBottomLeft);
@@ -47,9 +52,10 @@
47
52
  // Grapper Handle - Top Right
48
53
  let resizeHandleTopRight = document.createElement("div");
49
54
  resizeHandleTopRight.id = "resize-handle-top-right";
50
- resizeHandleTopRight.style.width = "8px";
51
- resizeHandleTopRight.style.height = "8px";
52
- resizeHandleTopRight.style.border = `"4px solid ${styles.grapperColor}"`;
55
+ resizeHandleTopRight.style.width = styles.grapperSize;
56
+ resizeHandleTopRight.style.height = styles.grapperSize;
57
+ resizeHandleTopRight.style.backgroundColor = styles.grapperColor;
58
+ resizeHandleTopRight.style.borderRadius = styles.grapperRadius;
53
59
  resizeHandleTopRight.style.position = "absolute";
54
60
  resizeHandleTopRight.style.cursor = "nesw-resize";
55
61
  parentDiv.appendChild(resizeHandleTopRight);
@@ -57,14 +63,16 @@
57
63
  // Grapper Handle - Top Left
58
64
  let resizeHandleTopLeft = document.createElement("div");
59
65
  resizeHandleTopLeft.id = "resize-handle-top-left";
60
- resizeHandleTopLeft.style.width = "8px";
61
- resizeHandleTopLeft.style.height = "8px";
62
- resizeHandleTopLeft.style.border = `"4px solid ${styles.grapperColor}"`;
66
+ resizeHandleTopLeft.style.width = styles.grapperSize;
67
+ resizeHandleTopLeft.style.height = styles.grapperSize;
68
+ resizeHandleTopLeft.style.backgroundColor = styles.grapperColor;
69
+ resizeHandleTopLeft.style.borderRadius = styles.grapperRadius;
63
70
  resizeHandleTopLeft.style.position = "absolute";
64
71
  resizeHandleTopLeft.style.cursor = "nwse-resize";
65
72
  parentDiv.appendChild(resizeHandleTopLeft);
66
73
  }
67
74
 
75
+ // Handle dragging to resize
68
76
  let isResizing = false;
69
77
  let initialX = 0;
70
78
  let initialY = 0;
@@ -241,7 +249,7 @@
241
249
  cy.on("tap", "node", function (evt) {
242
250
  const node = evt.target;
243
251
 
244
- createResizeHandle(node, cy);
252
+ createResizeHandle(node, cy, opts);
245
253
  positionHandle(node);
246
254
  });
247
255