react-design-editor 0.0.50 → 0.0.52
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/dist/react-design-editor.js +7739 -7114
- package/dist/react-design-editor.min.js +1 -1
- package/dist/react-design-editor.min.js.LICENSE.txt +2 -0
- package/lib/Canvas.d.ts +18 -18
- package/lib/Canvas.js +172 -172
- package/lib/CanvasObject.d.ts +10 -10
- package/lib/CanvasObject.js +96 -96
- package/lib/constants/code.d.ts +19 -19
- package/lib/constants/code.js +22 -22
- package/lib/constants/defaults.d.ts +38 -38
- package/lib/constants/defaults.js +69 -69
- package/lib/constants/index.d.ts +3 -3
- package/lib/constants/index.js +26 -26
- package/lib/handlers/AlignmentHandler.d.ts +18 -18
- package/lib/handlers/AlignmentHandler.js +58 -58
- package/lib/handlers/AnimationHandler.d.ts +50 -50
- package/lib/handlers/AnimationHandler.js +346 -346
- package/lib/handlers/ChartHandler.d.ts +8 -8
- package/lib/handlers/ChartHandler.js +8 -8
- package/lib/handlers/ContextmenuHandler.d.ts +28 -28
- package/lib/handlers/ContextmenuHandler.js +65 -65
- package/lib/handlers/CropHandler.d.ts +43 -43
- package/lib/handlers/CropHandler.js +261 -261
- package/lib/handlers/CustomHandler.d.ts +7 -7
- package/lib/handlers/CustomHandler.js +10 -10
- package/lib/handlers/DrawingHandler.d.ts +28 -28
- package/lib/handlers/DrawingHandler.js +318 -318
- package/lib/handlers/ElementHandler.d.ts +80 -80
- package/lib/handlers/ElementHandler.js +154 -154
- package/lib/handlers/EventHandler.d.ts +170 -170
- package/lib/handlers/EventHandler.js +880 -880
- package/lib/handlers/FiberHandler.d.ts +6 -6
- package/lib/handlers/FiberHandler.js +23 -23
- package/lib/handlers/GridHandler.d.ts +19 -19
- package/lib/handlers/GridHandler.js +77 -77
- package/lib/handlers/GuidelineHandler.d.ts +61 -61
- package/lib/handlers/GuidelineHandler.js +315 -315
- package/lib/handlers/Handler.d.ts +618 -618
- package/lib/handlers/Handler.js +1645 -1645
- package/lib/handlers/ImageHandler.d.ts +307 -307
- package/lib/handlers/ImageHandler.js +528 -528
- package/lib/handlers/InteractionHandler.d.ts +45 -45
- package/lib/handlers/InteractionHandler.js +168 -164
- package/lib/handlers/LinkHandler.d.ts +115 -115
- package/lib/handlers/LinkHandler.js +247 -247
- package/lib/handlers/NodeHandler.d.ts +50 -50
- package/lib/handlers/NodeHandler.js +274 -274
- package/lib/handlers/PortHandler.d.ts +22 -22
- package/lib/handlers/PortHandler.js +179 -179
- package/lib/handlers/ShortcutHandler.d.ts +119 -119
- package/lib/handlers/ShortcutHandler.js +151 -151
- package/lib/handlers/TooltipHandler.d.ts +33 -33
- package/lib/handlers/TooltipHandler.js +91 -91
- package/lib/handlers/TransactionHandler.d.ts +59 -59
- package/lib/handlers/TransactionHandler.js +137 -137
- package/lib/handlers/WorkareaHandler.d.ts +43 -43
- package/lib/handlers/WorkareaHandler.js +354 -354
- package/lib/handlers/ZoomHandler.d.ts +48 -48
- package/lib/handlers/ZoomHandler.js +143 -143
- package/lib/handlers/index.d.ts +23 -23
- package/lib/handlers/index.js +48 -48
- package/lib/index.d.ts +6 -6
- package/lib/index.js +20 -20
- package/lib/objects/Arrow.d.ts +2 -2
- package/lib/objects/Arrow.js +40 -40
- package/lib/objects/Chart.d.ts +10 -10
- package/lib/objects/Chart.js +117 -117
- package/lib/objects/CirclePort.d.ts +2 -2
- package/lib/objects/CirclePort.js +28 -28
- package/lib/objects/Cube.d.ts +5 -5
- package/lib/objects/Cube.js +71 -71
- package/lib/objects/CurvedLink.d.ts +2 -2
- package/lib/objects/CurvedLink.js +51 -51
- package/lib/objects/Element.d.ts +13 -13
- package/lib/objects/Element.js +77 -77
- package/lib/objects/Gif.d.ts +3 -3
- package/lib/objects/Gif.js +41 -41
- package/lib/objects/Iframe.d.ts +9 -9
- package/lib/objects/Iframe.js +63 -63
- package/lib/objects/Line.d.ts +2 -2
- package/lib/objects/Line.js +24 -24
- package/lib/objects/Link.d.ts +15 -15
- package/lib/objects/Link.js +107 -107
- package/lib/objects/Node.d.ts +59 -59
- package/lib/objects/Node.js +271 -271
- package/lib/objects/OrthogonalLink.d.ts +2 -2
- package/lib/objects/OrthogonalLink.js +54 -54
- package/lib/objects/Port.d.ts +12 -12
- package/lib/objects/Port.js +28 -28
- package/lib/objects/Svg.d.ts +12 -12
- package/lib/objects/Svg.js +93 -93
- package/lib/objects/Video.d.ts +14 -14
- package/lib/objects/Video.js +113 -113
- package/lib/objects/index.d.ts +15 -15
- package/lib/objects/index.js +32 -32
- package/lib/utils/ObjectUtil.d.ts +408 -408
- package/lib/utils/ObjectUtil.js +13 -13
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +13 -13
- package/package.json +1 -1
|
@@ -1,247 +1,247 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const warning_1 = __importDefault(require("warning"));
|
|
7
|
-
const objects_1 = require("../objects");
|
|
8
|
-
/**
|
|
9
|
-
* Link Handler Class
|
|
10
|
-
* @author salgum1114
|
|
11
|
-
* @class LinkHandler
|
|
12
|
-
*/
|
|
13
|
-
class LinkHandler {
|
|
14
|
-
constructor(handler) {
|
|
15
|
-
this.port = null;
|
|
16
|
-
/**
|
|
17
|
-
* On source port click, start link
|
|
18
|
-
* @param {PortObject} port
|
|
19
|
-
*/
|
|
20
|
-
this.init = (port) => {
|
|
21
|
-
if (this.isDrawing()) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (this.isConnected(port)) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
this.port = port;
|
|
28
|
-
this.port.set({
|
|
29
|
-
fill: port.selectFill,
|
|
30
|
-
});
|
|
31
|
-
this.handler.interactionHandler.linking();
|
|
32
|
-
const { left, top, nodeId, id } = port;
|
|
33
|
-
const fromPort = { left, top, id };
|
|
34
|
-
const toPort = { left, top };
|
|
35
|
-
const fromNode = this.handler.objectMap[nodeId];
|
|
36
|
-
this.handler.activeLine = new objects_1.CurvedLink(fromNode, fromPort, null, toPort, {
|
|
37
|
-
strokeWidth: 4,
|
|
38
|
-
fill: '#999999',
|
|
39
|
-
stroke: '#999999',
|
|
40
|
-
class: 'line',
|
|
41
|
-
originX: 'center',
|
|
42
|
-
originY: 'center',
|
|
43
|
-
selectable: false,
|
|
44
|
-
hasBorders: false,
|
|
45
|
-
hasControls: false,
|
|
46
|
-
evented: false,
|
|
47
|
-
});
|
|
48
|
-
this.handler.canvas.add(this.handler.activeLine);
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* End drawing link.
|
|
52
|
-
*/
|
|
53
|
-
this.finish = (link) => {
|
|
54
|
-
if (!link) {
|
|
55
|
-
this.port.set({
|
|
56
|
-
fill: this.port.originFill,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
this.handler.interactionHandler.selection();
|
|
60
|
-
this.handler.canvas.remove(this.handler.activeLine);
|
|
61
|
-
this.handler.activeLine = null;
|
|
62
|
-
this.handler.canvas.renderAll();
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* On dest port click, finish link
|
|
66
|
-
* @param {PortObject} port
|
|
67
|
-
*/
|
|
68
|
-
this.generate = (port) => {
|
|
69
|
-
if (!port) {
|
|
70
|
-
warning_1.default(!port, 'Does not exist target port.');
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (this.isDuplicate(port)) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (this.isSameNode(port)) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const link = {
|
|
80
|
-
type: 'curvedLink',
|
|
81
|
-
fromNodeId: this.handler.activeLine.fromNode.id,
|
|
82
|
-
fromPortId: this.handler.activeLine.fromPort.id,
|
|
83
|
-
toNodeId: port.nodeId,
|
|
84
|
-
toPortId: port.id,
|
|
85
|
-
};
|
|
86
|
-
const createdLink = this.create(link);
|
|
87
|
-
this.finish(createdLink);
|
|
88
|
-
// TODO...
|
|
89
|
-
// Save transactions unconditionally
|
|
90
|
-
if (!this.handler.transactionHandler.active) {
|
|
91
|
-
this.handler.transactionHandler.save('add');
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Add link in Canvas
|
|
96
|
-
* @param {LinkOption} link
|
|
97
|
-
* @param {boolean} [loaded=false]
|
|
98
|
-
* @returns
|
|
99
|
-
*/
|
|
100
|
-
this.create = (link, loaded = false) => {
|
|
101
|
-
const fromNode = this.handler.objectMap[link.fromNodeId];
|
|
102
|
-
const fromPort = fromNode.fromPort.filter(port => port.id === link.fromPortId || !port.id)[0];
|
|
103
|
-
const toNode = this.handler.objectMap[link.toNodeId];
|
|
104
|
-
const { toPort } = toNode;
|
|
105
|
-
const createdObj = this.handler.fabricObjects[link.type].create(fromNode, fromPort, toNode, toPort, {
|
|
106
|
-
...link,
|
|
107
|
-
});
|
|
108
|
-
this.handler.canvas.add(createdObj);
|
|
109
|
-
this.handler.objects = this.handler.getObjects();
|
|
110
|
-
const { editable } = this.handler;
|
|
111
|
-
if (this.handler.onAdd && editable && !loaded) {
|
|
112
|
-
this.handler.onAdd(createdObj);
|
|
113
|
-
}
|
|
114
|
-
this.handler.canvas.renderAll();
|
|
115
|
-
createdObj.setPort(fromNode, fromPort, toNode, toPort);
|
|
116
|
-
this.handler.portHandler.setCoords(fromNode);
|
|
117
|
-
this.handler.portHandler.setCoords(toNode);
|
|
118
|
-
this.handler.canvas.requestRenderAll();
|
|
119
|
-
return createdObj;
|
|
120
|
-
};
|
|
121
|
-
/**
|
|
122
|
-
* Set coordinate of link
|
|
123
|
-
* @param {number} x1
|
|
124
|
-
* @param {number} y1
|
|
125
|
-
* @param {number} x2
|
|
126
|
-
* @param {number} y2
|
|
127
|
-
* @param {LinkObject} link
|
|
128
|
-
*/
|
|
129
|
-
this.setCoords = (x1, y1, x2, y2, link) => {
|
|
130
|
-
link.set({
|
|
131
|
-
x1,
|
|
132
|
-
y1,
|
|
133
|
-
x2,
|
|
134
|
-
y2,
|
|
135
|
-
});
|
|
136
|
-
link.setCoords();
|
|
137
|
-
};
|
|
138
|
-
/**
|
|
139
|
-
* When the link is deleted, linked FromNode delete
|
|
140
|
-
* @param {LinkObject} link
|
|
141
|
-
*/
|
|
142
|
-
this.removeFrom = (link) => {
|
|
143
|
-
if (link.fromPort) {
|
|
144
|
-
let index = -1;
|
|
145
|
-
if (link.fromPort.links.length) {
|
|
146
|
-
link.fromPort.links.some((portLink, i) => {
|
|
147
|
-
if (link.id === portLink.id) {
|
|
148
|
-
index = i;
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
return false;
|
|
152
|
-
});
|
|
153
|
-
if (index > -1) {
|
|
154
|
-
link.fromPort.links.splice(index, 1);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
link.setPortEnabled(link.fromNode, link.fromPort, true);
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
/**
|
|
161
|
-
* When the link is deleted, linked ToNode delete
|
|
162
|
-
* @param {LinkObject} link
|
|
163
|
-
*/
|
|
164
|
-
this.removeTo = (link) => {
|
|
165
|
-
if (link.toNode.toPort.links.length) {
|
|
166
|
-
let index = -1;
|
|
167
|
-
link.toNode.toPort.links.some((portLink, i) => {
|
|
168
|
-
if (link.id === portLink.id) {
|
|
169
|
-
index = i;
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
return false;
|
|
173
|
-
});
|
|
174
|
-
if (index > -1) {
|
|
175
|
-
link.toNode.toPort.links.splice(index, 1);
|
|
176
|
-
}
|
|
177
|
-
link.setPortEnabled(link.toNode, link.toNode.toPort, true);
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
/**
|
|
181
|
-
* When the link is deleted, linked node delete
|
|
182
|
-
* @param {LinkObject} link
|
|
183
|
-
*/
|
|
184
|
-
this.removeAll = (link) => {
|
|
185
|
-
this.removeFrom(link);
|
|
186
|
-
this.removeTo(link);
|
|
187
|
-
};
|
|
188
|
-
/**
|
|
189
|
-
* Remove link in canvas
|
|
190
|
-
* @param {LinkObject} link
|
|
191
|
-
* @param {string} [type]
|
|
192
|
-
*/
|
|
193
|
-
this.remove = (link, type) => {
|
|
194
|
-
if (type === 'from') {
|
|
195
|
-
this.removeFrom(link);
|
|
196
|
-
}
|
|
197
|
-
else if (type === 'to') {
|
|
198
|
-
this.removeTo(link);
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
this.removeAll(link);
|
|
202
|
-
}
|
|
203
|
-
this.handler.canvas.remove(link);
|
|
204
|
-
this.handler.objects = this.handler.getObjects();
|
|
205
|
-
};
|
|
206
|
-
/**
|
|
207
|
-
* Check if there is a port connected
|
|
208
|
-
* @param {PortObject} port
|
|
209
|
-
* @returns
|
|
210
|
-
*/
|
|
211
|
-
this.isConnected = (port) => {
|
|
212
|
-
warning_1.default(port.enabled, 'A connected node already exists.');
|
|
213
|
-
return !port.enabled;
|
|
214
|
-
};
|
|
215
|
-
/**
|
|
216
|
-
* Check if select same node
|
|
217
|
-
* @param {PortObject} port
|
|
218
|
-
* @returns
|
|
219
|
-
*/
|
|
220
|
-
this.isSameNode = (port) => {
|
|
221
|
-
const validate = port.nodeId === this.handler.activeLine.fromNode.id;
|
|
222
|
-
warning_1.default(!validate, 'Cannot select the same node.');
|
|
223
|
-
return validate;
|
|
224
|
-
};
|
|
225
|
-
/**
|
|
226
|
-
* Check if select same node
|
|
227
|
-
* @param {PortObject} port
|
|
228
|
-
* @returns
|
|
229
|
-
*/
|
|
230
|
-
this.isDuplicate = (port) => {
|
|
231
|
-
const validate = port.links.some(link => link.fromNode.id === this.handler.activeLine.fromNode.id);
|
|
232
|
-
warning_1.default(!validate, 'Duplicate connections cannot be made.');
|
|
233
|
-
return validate;
|
|
234
|
-
};
|
|
235
|
-
/**
|
|
236
|
-
* Check if draw the link
|
|
237
|
-
* @returns
|
|
238
|
-
*/
|
|
239
|
-
this.isDrawing = () => {
|
|
240
|
-
const validate = this.handler.interactionMode === 'link' && this.handler.activeLine;
|
|
241
|
-
warning_1.default(!validate, 'Already drawing links.');
|
|
242
|
-
return validate;
|
|
243
|
-
};
|
|
244
|
-
this.handler = handler;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
exports.default = LinkHandler;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const warning_1 = __importDefault(require("warning"));
|
|
7
|
+
const objects_1 = require("../objects");
|
|
8
|
+
/**
|
|
9
|
+
* Link Handler Class
|
|
10
|
+
* @author salgum1114
|
|
11
|
+
* @class LinkHandler
|
|
12
|
+
*/
|
|
13
|
+
class LinkHandler {
|
|
14
|
+
constructor(handler) {
|
|
15
|
+
this.port = null;
|
|
16
|
+
/**
|
|
17
|
+
* On source port click, start link
|
|
18
|
+
* @param {PortObject} port
|
|
19
|
+
*/
|
|
20
|
+
this.init = (port) => {
|
|
21
|
+
if (this.isDrawing()) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (this.isConnected(port)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this.port = port;
|
|
28
|
+
this.port.set({
|
|
29
|
+
fill: port.selectFill,
|
|
30
|
+
});
|
|
31
|
+
this.handler.interactionHandler.linking();
|
|
32
|
+
const { left, top, nodeId, id } = port;
|
|
33
|
+
const fromPort = { left, top, id };
|
|
34
|
+
const toPort = { left, top };
|
|
35
|
+
const fromNode = this.handler.objectMap[nodeId];
|
|
36
|
+
this.handler.activeLine = new objects_1.CurvedLink(fromNode, fromPort, null, toPort, {
|
|
37
|
+
strokeWidth: 4,
|
|
38
|
+
fill: '#999999',
|
|
39
|
+
stroke: '#999999',
|
|
40
|
+
class: 'line',
|
|
41
|
+
originX: 'center',
|
|
42
|
+
originY: 'center',
|
|
43
|
+
selectable: false,
|
|
44
|
+
hasBorders: false,
|
|
45
|
+
hasControls: false,
|
|
46
|
+
evented: false,
|
|
47
|
+
});
|
|
48
|
+
this.handler.canvas.add(this.handler.activeLine);
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* End drawing link.
|
|
52
|
+
*/
|
|
53
|
+
this.finish = (link) => {
|
|
54
|
+
if (!link) {
|
|
55
|
+
this.port.set({
|
|
56
|
+
fill: this.port.originFill,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
this.handler.interactionHandler.selection();
|
|
60
|
+
this.handler.canvas.remove(this.handler.activeLine);
|
|
61
|
+
this.handler.activeLine = null;
|
|
62
|
+
this.handler.canvas.renderAll();
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* On dest port click, finish link
|
|
66
|
+
* @param {PortObject} port
|
|
67
|
+
*/
|
|
68
|
+
this.generate = (port) => {
|
|
69
|
+
if (!port) {
|
|
70
|
+
warning_1.default(!port, 'Does not exist target port.');
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (this.isDuplicate(port)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (this.isSameNode(port)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const link = {
|
|
80
|
+
type: 'curvedLink',
|
|
81
|
+
fromNodeId: this.handler.activeLine.fromNode.id,
|
|
82
|
+
fromPortId: this.handler.activeLine.fromPort.id,
|
|
83
|
+
toNodeId: port.nodeId,
|
|
84
|
+
toPortId: port.id,
|
|
85
|
+
};
|
|
86
|
+
const createdLink = this.create(link);
|
|
87
|
+
this.finish(createdLink);
|
|
88
|
+
// TODO...
|
|
89
|
+
// Save transactions unconditionally
|
|
90
|
+
if (!this.handler.transactionHandler.active) {
|
|
91
|
+
this.handler.transactionHandler.save('add');
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Add link in Canvas
|
|
96
|
+
* @param {LinkOption} link
|
|
97
|
+
* @param {boolean} [loaded=false]
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
this.create = (link, loaded = false) => {
|
|
101
|
+
const fromNode = this.handler.objectMap[link.fromNodeId];
|
|
102
|
+
const fromPort = fromNode.fromPort.filter(port => port.id === link.fromPortId || !port.id)[0];
|
|
103
|
+
const toNode = this.handler.objectMap[link.toNodeId];
|
|
104
|
+
const { toPort } = toNode;
|
|
105
|
+
const createdObj = this.handler.fabricObjects[link.type].create(fromNode, fromPort, toNode, toPort, {
|
|
106
|
+
...link,
|
|
107
|
+
});
|
|
108
|
+
this.handler.canvas.add(createdObj);
|
|
109
|
+
this.handler.objects = this.handler.getObjects();
|
|
110
|
+
const { editable } = this.handler;
|
|
111
|
+
if (this.handler.onAdd && editable && !loaded) {
|
|
112
|
+
this.handler.onAdd(createdObj);
|
|
113
|
+
}
|
|
114
|
+
this.handler.canvas.renderAll();
|
|
115
|
+
createdObj.setPort(fromNode, fromPort, toNode, toPort);
|
|
116
|
+
this.handler.portHandler.setCoords(fromNode);
|
|
117
|
+
this.handler.portHandler.setCoords(toNode);
|
|
118
|
+
this.handler.canvas.requestRenderAll();
|
|
119
|
+
return createdObj;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Set coordinate of link
|
|
123
|
+
* @param {number} x1
|
|
124
|
+
* @param {number} y1
|
|
125
|
+
* @param {number} x2
|
|
126
|
+
* @param {number} y2
|
|
127
|
+
* @param {LinkObject} link
|
|
128
|
+
*/
|
|
129
|
+
this.setCoords = (x1, y1, x2, y2, link) => {
|
|
130
|
+
link.set({
|
|
131
|
+
x1,
|
|
132
|
+
y1,
|
|
133
|
+
x2,
|
|
134
|
+
y2,
|
|
135
|
+
});
|
|
136
|
+
link.setCoords();
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* When the link is deleted, linked FromNode delete
|
|
140
|
+
* @param {LinkObject} link
|
|
141
|
+
*/
|
|
142
|
+
this.removeFrom = (link) => {
|
|
143
|
+
if (link.fromPort) {
|
|
144
|
+
let index = -1;
|
|
145
|
+
if (link.fromPort.links.length) {
|
|
146
|
+
link.fromPort.links.some((portLink, i) => {
|
|
147
|
+
if (link.id === portLink.id) {
|
|
148
|
+
index = i;
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
});
|
|
153
|
+
if (index > -1) {
|
|
154
|
+
link.fromPort.links.splice(index, 1);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
link.setPortEnabled(link.fromNode, link.fromPort, true);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* When the link is deleted, linked ToNode delete
|
|
162
|
+
* @param {LinkObject} link
|
|
163
|
+
*/
|
|
164
|
+
this.removeTo = (link) => {
|
|
165
|
+
if (link.toNode.toPort.links.length) {
|
|
166
|
+
let index = -1;
|
|
167
|
+
link.toNode.toPort.links.some((portLink, i) => {
|
|
168
|
+
if (link.id === portLink.id) {
|
|
169
|
+
index = i;
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
});
|
|
174
|
+
if (index > -1) {
|
|
175
|
+
link.toNode.toPort.links.splice(index, 1);
|
|
176
|
+
}
|
|
177
|
+
link.setPortEnabled(link.toNode, link.toNode.toPort, true);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* When the link is deleted, linked node delete
|
|
182
|
+
* @param {LinkObject} link
|
|
183
|
+
*/
|
|
184
|
+
this.removeAll = (link) => {
|
|
185
|
+
this.removeFrom(link);
|
|
186
|
+
this.removeTo(link);
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Remove link in canvas
|
|
190
|
+
* @param {LinkObject} link
|
|
191
|
+
* @param {string} [type]
|
|
192
|
+
*/
|
|
193
|
+
this.remove = (link, type) => {
|
|
194
|
+
if (type === 'from') {
|
|
195
|
+
this.removeFrom(link);
|
|
196
|
+
}
|
|
197
|
+
else if (type === 'to') {
|
|
198
|
+
this.removeTo(link);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
this.removeAll(link);
|
|
202
|
+
}
|
|
203
|
+
this.handler.canvas.remove(link);
|
|
204
|
+
this.handler.objects = this.handler.getObjects();
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Check if there is a port connected
|
|
208
|
+
* @param {PortObject} port
|
|
209
|
+
* @returns
|
|
210
|
+
*/
|
|
211
|
+
this.isConnected = (port) => {
|
|
212
|
+
warning_1.default(port.enabled, 'A connected node already exists.');
|
|
213
|
+
return !port.enabled;
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Check if select same node
|
|
217
|
+
* @param {PortObject} port
|
|
218
|
+
* @returns
|
|
219
|
+
*/
|
|
220
|
+
this.isSameNode = (port) => {
|
|
221
|
+
const validate = port.nodeId === this.handler.activeLine.fromNode.id;
|
|
222
|
+
warning_1.default(!validate, 'Cannot select the same node.');
|
|
223
|
+
return validate;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Check if select same node
|
|
227
|
+
* @param {PortObject} port
|
|
228
|
+
* @returns
|
|
229
|
+
*/
|
|
230
|
+
this.isDuplicate = (port) => {
|
|
231
|
+
const validate = port.links.some(link => link.fromNode.id === this.handler.activeLine.fromNode.id);
|
|
232
|
+
warning_1.default(!validate, 'Duplicate connections cannot be made.');
|
|
233
|
+
return validate;
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Check if draw the link
|
|
237
|
+
* @returns
|
|
238
|
+
*/
|
|
239
|
+
this.isDrawing = () => {
|
|
240
|
+
const validate = this.handler.interactionMode === 'link' && this.handler.activeLine;
|
|
241
|
+
warning_1.default(!validate, 'Already drawing links.');
|
|
242
|
+
return validate;
|
|
243
|
+
};
|
|
244
|
+
this.handler = handler;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
exports.default = LinkHandler;
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { NodeObject } from '../objects/Node';
|
|
2
|
-
import { FabricObject } from '../utils';
|
|
3
|
-
import Handler from './Handler';
|
|
4
|
-
declare class NodeHandler {
|
|
5
|
-
handler: Handler;
|
|
6
|
-
constructor(handler: Handler);
|
|
7
|
-
/**
|
|
8
|
-
* Get the node path by target object
|
|
9
|
-
* @param {NodeObject} target
|
|
10
|
-
* @param {NodeObject[]} [nodes=[]]
|
|
11
|
-
* @param {string} [direction='init']
|
|
12
|
-
*/
|
|
13
|
-
getNodePath: (target: NodeObject, nodes?: NodeObject[], direction?: string) => void;
|
|
14
|
-
/**
|
|
15
|
-
* Select the node path
|
|
16
|
-
* @param {string[]} [path]
|
|
17
|
-
*/
|
|
18
|
-
selectByPath: (path?: string[]) => void;
|
|
19
|
-
/**
|
|
20
|
-
* Select node by id
|
|
21
|
-
* @param {string} id
|
|
22
|
-
*/
|
|
23
|
-
selectById: (id: string) => void;
|
|
24
|
-
/**
|
|
25
|
-
* Deselect nodes
|
|
26
|
-
*/
|
|
27
|
-
deselect: () => void;
|
|
28
|
-
/**
|
|
29
|
-
* Highlight path by ids
|
|
30
|
-
* @param {string[]} [path]
|
|
31
|
-
*/
|
|
32
|
-
highlightingByPath: (path?: string[]) => void;
|
|
33
|
-
/**
|
|
34
|
-
* Highlight link
|
|
35
|
-
* @param {FabricObject} object
|
|
36
|
-
* @param {FabricObject} targetObject
|
|
37
|
-
* @param {number} [duration=500]
|
|
38
|
-
*/
|
|
39
|
-
highlightingLink: (object: FabricObject, targetObject: FabricObject, duration?: number) => void;
|
|
40
|
-
/**
|
|
41
|
-
* Highlight node
|
|
42
|
-
*
|
|
43
|
-
* @param {*} object
|
|
44
|
-
* @param {number} [duration=500]
|
|
45
|
-
* @param {number} [minBlur=0]
|
|
46
|
-
* @param {number} [maxBlur=50]
|
|
47
|
-
*/
|
|
48
|
-
highlightingNode: (object: FabricObject, duration?: number, minBlur?: number, maxBlur?: number) => void;
|
|
49
|
-
}
|
|
50
|
-
export default NodeHandler;
|
|
1
|
+
import { NodeObject } from '../objects/Node';
|
|
2
|
+
import { FabricObject } from '../utils';
|
|
3
|
+
import Handler from './Handler';
|
|
4
|
+
declare class NodeHandler {
|
|
5
|
+
handler: Handler;
|
|
6
|
+
constructor(handler: Handler);
|
|
7
|
+
/**
|
|
8
|
+
* Get the node path by target object
|
|
9
|
+
* @param {NodeObject} target
|
|
10
|
+
* @param {NodeObject[]} [nodes=[]]
|
|
11
|
+
* @param {string} [direction='init']
|
|
12
|
+
*/
|
|
13
|
+
getNodePath: (target: NodeObject, nodes?: NodeObject[], direction?: string) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Select the node path
|
|
16
|
+
* @param {string[]} [path]
|
|
17
|
+
*/
|
|
18
|
+
selectByPath: (path?: string[]) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Select node by id
|
|
21
|
+
* @param {string} id
|
|
22
|
+
*/
|
|
23
|
+
selectById: (id: string) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Deselect nodes
|
|
26
|
+
*/
|
|
27
|
+
deselect: () => void;
|
|
28
|
+
/**
|
|
29
|
+
* Highlight path by ids
|
|
30
|
+
* @param {string[]} [path]
|
|
31
|
+
*/
|
|
32
|
+
highlightingByPath: (path?: string[]) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Highlight link
|
|
35
|
+
* @param {FabricObject} object
|
|
36
|
+
* @param {FabricObject} targetObject
|
|
37
|
+
* @param {number} [duration=500]
|
|
38
|
+
*/
|
|
39
|
+
highlightingLink: (object: FabricObject, targetObject: FabricObject, duration?: number) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Highlight node
|
|
42
|
+
*
|
|
43
|
+
* @param {*} object
|
|
44
|
+
* @param {number} [duration=500]
|
|
45
|
+
* @param {number} [minBlur=0]
|
|
46
|
+
* @param {number} [maxBlur=50]
|
|
47
|
+
*/
|
|
48
|
+
highlightingNode: (object: FabricObject, duration?: number, minBlur?: number, maxBlur?: number) => void;
|
|
49
|
+
}
|
|
50
|
+
export default NodeHandler;
|