power-link 2.0.1 → 2.0.3

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
@@ -7,9 +7,7 @@ A pure TypeScript visual node connector for creating draggable connections betwe
7
7
 
8
8
  ![Node Link Connector Demo](https://github.com/Tem-man/power-link/blob/main/public/images/screen-shot.png)
9
9
 
10
-
11
10
  ### online demo
12
- <!-- 访问线上demo -->
13
11
  visit [online demo](https://tem-man.github.io/power-link)
14
12
 
15
13
  ## ✨ Features
@@ -159,6 +157,7 @@ Register a node for connection.
159
157
  - `id` (String): Unique identifier for the node
160
158
  - `element` (HTMLElement): DOM element of the node
161
159
  - `options` (Object): Node configuration
160
+ - `label` (String): Node name/label (optional)
162
161
  - `dotPositions` (String | Array): Connection dot positions
163
162
  - `'both'`: Both left and right dots
164
163
  - `'left'`: Only left dot (string format)
@@ -174,6 +173,7 @@ Register a node for connection.
174
173
 
175
174
  ```javascript
176
175
  connector.registerNode("myNode", element, {
176
+ label: "My Node",
177
177
  dotPositions: ["right"],
178
178
  info: {
179
179
  id: "123",
@@ -410,8 +410,8 @@ connector.updateAllConnections(); // Refresh all connection lines
410
410
  Export the current topology (nodes, connections, and view state) as a JSON object.
411
411
 
412
412
  **Returns:** ExportData object containing:
413
- - `nodes`: Array of node data (id, x, y, info, dotPositions)
414
- - `connections`: Array of connection data (from, to, fromDot, toDot)
413
+ - `nodes`: Array of node data (id, label, x, y, info, dotPositions)
414
+ - `connections`: Array of connection data (from, fromLabel, fromInfo, to, toLabel, toInfo, fromDot, toDot)
415
415
  - `viewState`: Current view state (scale, translateX, translateY)
416
416
 
417
417
  **Example:**
@@ -421,11 +421,20 @@ const data = connector.export();
421
421
  console.log(data);
422
422
  // {
423
423
  // nodes: [
424
- // { id: 'node1', x: 100, y: 100, info: {...}, dotPositions: ['right'] },
425
- // { id: 'node2', x: 400, y: 100, info: {...}, dotPositions: ['left'] }
424
+ // { id: 'node1', label: 'Node 1', x: 100, y: 100, info: {...}, dotPositions: ['right'] },
425
+ // { id: 'node2', label: 'Node 2', x: 400, y: 100, info: {...}, dotPositions: ['left'] }
426
426
  // ],
427
427
  // connections: [
428
- // { from: 'node1', to: 'node2', fromDot: 'right', toDot: 'left' }
428
+ // {
429
+ // from: 'node1',
430
+ // fromLabel: 'Node 1',
431
+ // fromInfo: {...},
432
+ // to: 'node2',
433
+ // toLabel: 'Node 2',
434
+ // toInfo: {...},
435
+ // fromDot: 'right',
436
+ // toDot: 'left'
437
+ // }
429
438
  // ],
430
439
  // viewState: { scale: 1, translateX: 0, translateY: 0 }
431
440
  // }
@@ -1006,10 +1015,11 @@ let connector = null;
1006
1015
 
1007
1016
  const saveTopology = () => {
1008
1017
  const data = connector.export();
1009
- // Merge custom fields (label, type, etc.) if needed
1018
+ // label is now included in export() by default
1019
+ // Merge other custom fields (type, etc.) if needed
1010
1020
  data.nodes = data.nodes.map(exportNode => {
1011
1021
  const origin = nodes.value.find(n => n.id === exportNode.id);
1012
- return { ...exportNode, label: origin?.label, type: origin?.type };
1022
+ return { ...exportNode, type: origin?.type };
1013
1023
  });
1014
1024
  localStorage.setItem('topology', JSON.stringify(data));
1015
1025
  };
@@ -1056,8 +1066,8 @@ const loadTopology = async () => {
1056
1066
 
1057
1067
  **What's Included in Export:**
1058
1068
 
1059
- - **Nodes**: ID, position (x, y), custom info, dot positions
1060
- - **Connections**: Source/target nodes, dot positions
1069
+ - **Nodes**: ID, label (node name), position (x, y), custom info, dot positions
1070
+ - **Connections**: Source/target nodes, source/target labels, source/target info, dot positions
1061
1071
  - **View State**: Current zoom level and pan position (scale, translateX, translateY)
1062
1072
 
1063
1073
  **Benefits:**
package/dist/index.d.mts CHANGED
@@ -23,6 +23,8 @@ interface Dot {
23
23
  /** 节点对象 */
24
24
  interface ConnectorNode {
25
25
  id: string;
26
+ /** 节点名称 */
27
+ label?: string;
26
28
  element: HTMLElement;
27
29
  info?: Record<string, unknown>;
28
30
  dots: Partial<Record<DotPosition, Dot>>;
@@ -104,6 +106,8 @@ interface ConnectorOptions extends Partial<ConnectorConfig> {
104
106
  }
105
107
  /** 节点注册选项 */
106
108
  interface RegisterNodeOptions {
109
+ /** 节点名称 */
110
+ label?: string;
107
111
  info?: Record<string, unknown>;
108
112
  dotPositions?: 'both' | DotPosition | DotPosition[];
109
113
  }
@@ -114,6 +118,8 @@ interface SilentOptions {
114
118
  /** 导出的单个节点数据 */
115
119
  interface ExportNodeData {
116
120
  id: string;
121
+ /** 节点名称 */
122
+ label?: string;
117
123
  x: number;
118
124
  y: number;
119
125
  info?: Record<string, unknown>;
@@ -122,7 +128,15 @@ interface ExportNodeData {
122
128
  /** 导出的单条连接数据 */
123
129
  interface ExportConnectionData {
124
130
  from: string;
131
+ /** from 节点名称 */
132
+ fromLabel?: string;
133
+ /** from 节点附加信息 */
134
+ fromInfo?: Record<string, unknown>;
125
135
  to: string;
136
+ /** to 节点名称 */
137
+ toLabel?: string;
138
+ /** to 节点附加信息 */
139
+ toInfo?: Record<string, unknown>;
126
140
  fromDot: DotPosition;
127
141
  toDot: DotPosition;
128
142
  }
package/dist/index.d.ts CHANGED
@@ -23,6 +23,8 @@ interface Dot {
23
23
  /** 节点对象 */
24
24
  interface ConnectorNode {
25
25
  id: string;
26
+ /** 节点名称 */
27
+ label?: string;
26
28
  element: HTMLElement;
27
29
  info?: Record<string, unknown>;
28
30
  dots: Partial<Record<DotPosition, Dot>>;
@@ -104,6 +106,8 @@ interface ConnectorOptions extends Partial<ConnectorConfig> {
104
106
  }
105
107
  /** 节点注册选项 */
106
108
  interface RegisterNodeOptions {
109
+ /** 节点名称 */
110
+ label?: string;
107
111
  info?: Record<string, unknown>;
108
112
  dotPositions?: 'both' | DotPosition | DotPosition[];
109
113
  }
@@ -114,6 +118,8 @@ interface SilentOptions {
114
118
  /** 导出的单个节点数据 */
115
119
  interface ExportNodeData {
116
120
  id: string;
121
+ /** 节点名称 */
122
+ label?: string;
117
123
  x: number;
118
124
  y: number;
119
125
  info?: Record<string, unknown>;
@@ -122,7 +128,15 @@ interface ExportNodeData {
122
128
  /** 导出的单条连接数据 */
123
129
  interface ExportConnectionData {
124
130
  from: string;
131
+ /** from 节点名称 */
132
+ fromLabel?: string;
133
+ /** from 节点附加信息 */
134
+ fromInfo?: Record<string, unknown>;
125
135
  to: string;
136
+ /** to 节点名称 */
137
+ toLabel?: string;
138
+ /** to 节点附加信息 */
139
+ toInfo?: Record<string, unknown>;
126
140
  fromDot: DotPosition;
127
141
  toDot: DotPosition;
128
142
  }
@@ -445,6 +445,7 @@ var PowerLink = (function (exports) {
445
445
  const y = parseFloat(element.style.top) || 0;
446
446
  const node = {
447
447
  id,
448
+ label: options.label,
448
449
  element,
449
450
  info: options.info,
450
451
  dots,
@@ -1362,6 +1363,7 @@ var PowerLink = (function (exports) {
1362
1363
  return {
1363
1364
  nodes: this.ctx.nodes.map((node) => ({
1364
1365
  id: node.id,
1366
+ label: node.label,
1365
1367
  x: node.x,
1366
1368
  y: node.y,
1367
1369
  info: node.info,
@@ -1369,7 +1371,11 @@ var PowerLink = (function (exports) {
1369
1371
  })),
1370
1372
  connections: this.ctx.connections.map((conn) => ({
1371
1373
  from: conn.fromNode.id,
1374
+ fromLabel: conn.fromNode.label,
1375
+ fromInfo: conn.fromNode.info,
1372
1376
  to: conn.toNode.id,
1377
+ toLabel: conn.toNode.label,
1378
+ toInfo: conn.toNode.info,
1373
1379
  fromDot: conn.fromDot.position,
1374
1380
  toDot: conn.toDot.position
1375
1381
  })),
package/dist/index.js CHANGED
@@ -446,6 +446,7 @@ var _NodeManager = class _NodeManager {
446
446
  const y = parseFloat(element.style.top) || 0;
447
447
  const node = {
448
448
  id,
449
+ label: options.label,
449
450
  element,
450
451
  info: options.info,
451
452
  dots,
@@ -1363,6 +1364,7 @@ var _Connector = class _Connector {
1363
1364
  return {
1364
1365
  nodes: this.ctx.nodes.map((node) => ({
1365
1366
  id: node.id,
1367
+ label: node.label,
1366
1368
  x: node.x,
1367
1369
  y: node.y,
1368
1370
  info: node.info,
@@ -1370,7 +1372,11 @@ var _Connector = class _Connector {
1370
1372
  })),
1371
1373
  connections: this.ctx.connections.map((conn) => ({
1372
1374
  from: conn.fromNode.id,
1375
+ fromLabel: conn.fromNode.label,
1376
+ fromInfo: conn.fromNode.info,
1373
1377
  to: conn.toNode.id,
1378
+ toLabel: conn.toNode.label,
1379
+ toInfo: conn.toNode.info,
1374
1380
  fromDot: conn.fromDot.position,
1375
1381
  toDot: conn.toDot.position
1376
1382
  })),
package/dist/index.mjs CHANGED
@@ -442,6 +442,7 @@ var _NodeManager = class _NodeManager {
442
442
  const y = parseFloat(element.style.top) || 0;
443
443
  const node = {
444
444
  id,
445
+ label: options.label,
445
446
  element,
446
447
  info: options.info,
447
448
  dots,
@@ -1359,6 +1360,7 @@ var _Connector = class _Connector {
1359
1360
  return {
1360
1361
  nodes: this.ctx.nodes.map((node) => ({
1361
1362
  id: node.id,
1363
+ label: node.label,
1362
1364
  x: node.x,
1363
1365
  y: node.y,
1364
1366
  info: node.info,
@@ -1366,7 +1368,11 @@ var _Connector = class _Connector {
1366
1368
  })),
1367
1369
  connections: this.ctx.connections.map((conn) => ({
1368
1370
  from: conn.fromNode.id,
1371
+ fromLabel: conn.fromNode.label,
1372
+ fromInfo: conn.fromNode.info,
1369
1373
  to: conn.toNode.id,
1374
+ toLabel: conn.toNode.label,
1375
+ toInfo: conn.toNode.info,
1370
1376
  fromDot: conn.fromDot.position,
1371
1377
  toDot: conn.toDot.position
1372
1378
  })),
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "power-link",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "A pure TypeScript visual node connector for creating draggable connections between nodes. Framework-agnostic and easy to use",
5
5
  "author": {
6
6
  "name": "Lin Ji Man",
7
7
  "email": "Temman_lin@qq.com"
8
8
  },
9
9
  "keywords": [
10
- "power-link",
11
10
  "connector",
12
11
  "node-link",
13
12
  "visual-connector",
14
13
  "drag-line",
15
- "bezier-curve"
14
+ "bezier-curve",
15
+ "high-customization",
16
+ "flow-chart"
16
17
  ],
17
18
  "license": "MIT",
18
19
  "homepage": "https://tem-man.github.io/power-link",