ar-design 0.2.97 → 0.2.99
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 +223 -0
- package/dist/assets/css/components/data-display/diagram/styles.css +113 -0
- package/dist/assets/css/components/feedback/tooltip/styles.css +1 -0
- package/dist/assets/css/core/variants/borderless.css +45 -56
- package/dist/assets/css/core/variants/dashed.css +11 -22
- package/dist/assets/css/core/variants/outlined.css +11 -22
- package/dist/assets/css/core/variants/surface.css +11 -22
- package/dist/components/charts/pie/index.js +1 -0
- package/dist/components/data-display/diagram/IProps.d.ts +48 -0
- package/dist/components/data-display/diagram/IProps.js +1 -0
- package/dist/components/data-display/diagram/index.d.ts +4 -0
- package/dist/components/data-display/diagram/index.js +258 -0
- package/dist/components/data-display/dnd/index.js +0 -12
- package/dist/components/data-display/table/FilterPopup.js +1 -0
- package/dist/components/form/upload/Dropzone.js +1 -0
- package/dist/components/form/upload/index.js +1 -0
- package/dist/components/icons/Compiler.js +19 -17
- package/dist/components/navigation/breadcrumb/index.js +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/libs/core/application/hooks/index.js +1 -0
- package/dist/libs/core/service/Api.d.ts +5 -8
- package/dist/libs/core/service/Api.js +15 -7
- package/dist/libs/core/service/index.d.ts +5 -8
- package/dist/libs/core/service/index.js +2 -5
- package/dist/libs/types/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -23,8 +23,7 @@ iframe.dashed:not(.disabled) {
|
|
|
23
23
|
|
|
24
24
|
button.dashed:not(.disabled) {
|
|
25
25
|
&.blue {
|
|
26
|
-
&:hover
|
|
27
|
-
&:focus {
|
|
26
|
+
&:hover {
|
|
28
27
|
background-color: var(--blue-100);
|
|
29
28
|
}
|
|
30
29
|
}
|
|
@@ -57,8 +56,7 @@ iframe.dashed:not(.disabled) {
|
|
|
57
56
|
|
|
58
57
|
button.dashed:not(.disabled) {
|
|
59
58
|
&.purple {
|
|
60
|
-
&:hover
|
|
61
|
-
&:focus {
|
|
59
|
+
&:hover {
|
|
62
60
|
background-color: var(--purple-100);
|
|
63
61
|
}
|
|
64
62
|
}
|
|
@@ -91,8 +89,7 @@ iframe.dashed:not(.disabled) {
|
|
|
91
89
|
|
|
92
90
|
button.dashed:not(.disabled) {
|
|
93
91
|
&.pink {
|
|
94
|
-
&:hover
|
|
95
|
-
&:focus {
|
|
92
|
+
&:hover {
|
|
96
93
|
background-color: var(--pink-100);
|
|
97
94
|
}
|
|
98
95
|
}
|
|
@@ -125,8 +122,7 @@ iframe.dashed:not(.disabled) {
|
|
|
125
122
|
|
|
126
123
|
button.dashed:not(.disabled) {
|
|
127
124
|
&.red {
|
|
128
|
-
&:hover
|
|
129
|
-
&:focus {
|
|
125
|
+
&:hover {
|
|
130
126
|
background-color: var(--red-100);
|
|
131
127
|
}
|
|
132
128
|
}
|
|
@@ -159,8 +155,7 @@ iframe.dashed:not(.disabled) {
|
|
|
159
155
|
|
|
160
156
|
button.dashed:not(.disabled) {
|
|
161
157
|
&.orange {
|
|
162
|
-
&:hover
|
|
163
|
-
&:focus {
|
|
158
|
+
&:hover {
|
|
164
159
|
background-color: var(--orange-100);
|
|
165
160
|
}
|
|
166
161
|
}
|
|
@@ -193,8 +188,7 @@ iframe.dashed:not(.disabled) {
|
|
|
193
188
|
|
|
194
189
|
button.dashed:not(.disabled) {
|
|
195
190
|
&.yellow {
|
|
196
|
-
&:hover
|
|
197
|
-
&:focus {
|
|
191
|
+
&:hover {
|
|
198
192
|
background-color: var(--yellow-100);
|
|
199
193
|
}
|
|
200
194
|
}
|
|
@@ -227,8 +221,7 @@ iframe.dashed:not(.disabled) {
|
|
|
227
221
|
|
|
228
222
|
button.dashed:not(.disabled) {
|
|
229
223
|
&.green {
|
|
230
|
-
&:hover
|
|
231
|
-
&:focus {
|
|
224
|
+
&:hover {
|
|
232
225
|
background-color: var(--green-100);
|
|
233
226
|
}
|
|
234
227
|
}
|
|
@@ -261,8 +254,7 @@ iframe.dashed:not(.disabled) {
|
|
|
261
254
|
|
|
262
255
|
button.dashed:not(.disabled) {
|
|
263
256
|
&.teal {
|
|
264
|
-
&:hover
|
|
265
|
-
&:focus {
|
|
257
|
+
&:hover {
|
|
266
258
|
background-color: var(--teal-100);
|
|
267
259
|
}
|
|
268
260
|
}
|
|
@@ -295,8 +287,7 @@ iframe.dashed:not(.disabled) {
|
|
|
295
287
|
|
|
296
288
|
button.dashed:not(.disabled) {
|
|
297
289
|
&.cyan {
|
|
298
|
-
&:hover
|
|
299
|
-
&:focus {
|
|
290
|
+
&:hover {
|
|
300
291
|
background-color: var(--cyan-100);
|
|
301
292
|
}
|
|
302
293
|
}
|
|
@@ -329,8 +320,7 @@ iframe.dashed:not(.disabled) {
|
|
|
329
320
|
|
|
330
321
|
button.dashed:not(.disabled) {
|
|
331
322
|
&.gray {
|
|
332
|
-
&:hover
|
|
333
|
-
&:focus {
|
|
323
|
+
&:hover {
|
|
334
324
|
background-color: var(--gray-100);
|
|
335
325
|
}
|
|
336
326
|
}
|
|
@@ -363,8 +353,7 @@ iframe.dashed:not(.disabled) {
|
|
|
363
353
|
|
|
364
354
|
button.dashed:not(.disabled) {
|
|
365
355
|
&.light {
|
|
366
|
-
&:hover
|
|
367
|
-
&:focus {
|
|
356
|
+
&:hover {
|
|
368
357
|
background-color: var(--light-100);
|
|
369
358
|
}
|
|
370
359
|
}
|
|
@@ -27,8 +27,7 @@ button.outlined:not(.disabled) {
|
|
|
27
27
|
border-color: var(--blue-500);
|
|
28
28
|
color: var(--blue-500);
|
|
29
29
|
|
|
30
|
-
&:hover
|
|
31
|
-
&:focus {
|
|
30
|
+
&:hover {
|
|
32
31
|
background-color: var(--blue-100);
|
|
33
32
|
}
|
|
34
33
|
}
|
|
@@ -65,8 +64,7 @@ button.outlined:not(.disabled) {
|
|
|
65
64
|
border-color: var(--purple-500);
|
|
66
65
|
color: var(--purple-500);
|
|
67
66
|
|
|
68
|
-
&:hover
|
|
69
|
-
&:focus {
|
|
67
|
+
&:hover {
|
|
70
68
|
background-color: var(--purple-100);
|
|
71
69
|
}
|
|
72
70
|
}
|
|
@@ -103,8 +101,7 @@ button.outlined:not(.disabled) {
|
|
|
103
101
|
border-color: var(--pink-500);
|
|
104
102
|
color: var(--pink-500);
|
|
105
103
|
|
|
106
|
-
&:hover
|
|
107
|
-
&:focus {
|
|
104
|
+
&:hover {
|
|
108
105
|
background-color: var(--pink-100);
|
|
109
106
|
}
|
|
110
107
|
}
|
|
@@ -141,8 +138,7 @@ button.outlined:not(.disabled) {
|
|
|
141
138
|
border-color: var(--red-500);
|
|
142
139
|
color: var(--red-500);
|
|
143
140
|
|
|
144
|
-
&:hover
|
|
145
|
-
&:focus {
|
|
141
|
+
&:hover {
|
|
146
142
|
background-color: var(--red-100);
|
|
147
143
|
}
|
|
148
144
|
}
|
|
@@ -179,8 +175,7 @@ button.outlined:not(.disabled) {
|
|
|
179
175
|
border-color: var(--orange-500);
|
|
180
176
|
color: var(--orange-500);
|
|
181
177
|
|
|
182
|
-
&:hover
|
|
183
|
-
&:focus {
|
|
178
|
+
&:hover {
|
|
184
179
|
background-color: var(--orange-100);
|
|
185
180
|
}
|
|
186
181
|
}
|
|
@@ -217,8 +212,7 @@ button.outlined:not(.disabled) {
|
|
|
217
212
|
border-color: var(--yellow-500);
|
|
218
213
|
color: var(--yellow-500);
|
|
219
214
|
|
|
220
|
-
&:hover
|
|
221
|
-
&:focus {
|
|
215
|
+
&:hover {
|
|
222
216
|
background-color: var(--yellow-100);
|
|
223
217
|
}
|
|
224
218
|
}
|
|
@@ -255,8 +249,7 @@ button.outlined:not(.disabled) {
|
|
|
255
249
|
border-color: var(--green-500);
|
|
256
250
|
color: var(--green-500);
|
|
257
251
|
|
|
258
|
-
&:hover
|
|
259
|
-
&:focus {
|
|
252
|
+
&:hover {
|
|
260
253
|
background-color: var(--green-100);
|
|
261
254
|
}
|
|
262
255
|
}
|
|
@@ -293,8 +286,7 @@ button.outlined:not(.disabled) {
|
|
|
293
286
|
border-color: var(--teal-500);
|
|
294
287
|
color: var(--teal-500);
|
|
295
288
|
|
|
296
|
-
&:hover
|
|
297
|
-
&:focus {
|
|
289
|
+
&:hover {
|
|
298
290
|
background-color: var(--teal-100);
|
|
299
291
|
}
|
|
300
292
|
}
|
|
@@ -331,8 +323,7 @@ button.outlined:not(.disabled) {
|
|
|
331
323
|
border-color: var(--cyan-500);
|
|
332
324
|
color: var(--cyan-500);
|
|
333
325
|
|
|
334
|
-
&:hover
|
|
335
|
-
&:focus {
|
|
326
|
+
&:hover {
|
|
336
327
|
background-color: var(--cyan-100);
|
|
337
328
|
}
|
|
338
329
|
}
|
|
@@ -369,8 +360,7 @@ button.outlined:not(.disabled) {
|
|
|
369
360
|
border-color: var(--gray-500);
|
|
370
361
|
color: var(--gray-500);
|
|
371
362
|
|
|
372
|
-
&:hover
|
|
373
|
-
&:focus {
|
|
363
|
+
&:hover {
|
|
374
364
|
background-color: var(--gray-100);
|
|
375
365
|
}
|
|
376
366
|
}
|
|
@@ -407,8 +397,7 @@ button.outlined:not(.disabled) {
|
|
|
407
397
|
border-color: var(--light-500);
|
|
408
398
|
color: var(--light-500);
|
|
409
399
|
|
|
410
|
-
&:hover
|
|
411
|
-
&:focus {
|
|
400
|
+
&:hover {
|
|
412
401
|
background-color: var(--light-100);
|
|
413
402
|
}
|
|
414
403
|
}
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
button.surface:not(.disabled) {
|
|
15
15
|
&.blue {
|
|
16
|
-
&:hover
|
|
17
|
-
&:focus {
|
|
16
|
+
&:hover {
|
|
18
17
|
background-color: var(--blue-300);
|
|
19
18
|
}
|
|
20
19
|
}
|
|
@@ -37,8 +36,7 @@ button.surface:not(.disabled) {
|
|
|
37
36
|
|
|
38
37
|
button.surface:not(.disabled) {
|
|
39
38
|
&.purple {
|
|
40
|
-
&:hover
|
|
41
|
-
&:focus {
|
|
39
|
+
&:hover {
|
|
42
40
|
background-color: var(--purple-300);
|
|
43
41
|
}
|
|
44
42
|
}
|
|
@@ -61,8 +59,7 @@ button.surface:not(.disabled) {
|
|
|
61
59
|
|
|
62
60
|
button.surface:not(.disabled) {
|
|
63
61
|
&.pink {
|
|
64
|
-
&:hover
|
|
65
|
-
&:focus {
|
|
62
|
+
&:hover {
|
|
66
63
|
background-color: var(--pink-300);
|
|
67
64
|
}
|
|
68
65
|
}
|
|
@@ -85,8 +82,7 @@ button.surface:not(.disabled) {
|
|
|
85
82
|
|
|
86
83
|
button.surface:not(.disabled) {
|
|
87
84
|
&.red {
|
|
88
|
-
&:hover
|
|
89
|
-
&:focus {
|
|
85
|
+
&:hover {
|
|
90
86
|
background-color: var(--red-300);
|
|
91
87
|
}
|
|
92
88
|
}
|
|
@@ -109,8 +105,7 @@ button.surface:not(.disabled) {
|
|
|
109
105
|
|
|
110
106
|
button.surface:not(.disabled) {
|
|
111
107
|
&.orange {
|
|
112
|
-
&:hover
|
|
113
|
-
&:focus {
|
|
108
|
+
&:hover {
|
|
114
109
|
background-color: var(--orange-300);
|
|
115
110
|
}
|
|
116
111
|
}
|
|
@@ -133,8 +128,7 @@ button.surface:not(.disabled) {
|
|
|
133
128
|
|
|
134
129
|
button.surface:not(.disabled) {
|
|
135
130
|
&.yellow {
|
|
136
|
-
&:hover
|
|
137
|
-
&:focus {
|
|
131
|
+
&:hover {
|
|
138
132
|
background-color: var(--yellow-300);
|
|
139
133
|
}
|
|
140
134
|
}
|
|
@@ -157,8 +151,7 @@ button.surface:not(.disabled) {
|
|
|
157
151
|
|
|
158
152
|
button.surface:not(.disabled) {
|
|
159
153
|
&.green {
|
|
160
|
-
&:hover
|
|
161
|
-
&:focus {
|
|
154
|
+
&:hover {
|
|
162
155
|
background-color: var(--green-300);
|
|
163
156
|
}
|
|
164
157
|
}
|
|
@@ -181,8 +174,7 @@ button.surface:not(.disabled) {
|
|
|
181
174
|
|
|
182
175
|
button.surface:not(.disabled) {
|
|
183
176
|
&.teal {
|
|
184
|
-
&:hover
|
|
185
|
-
&:focus {
|
|
177
|
+
&:hover {
|
|
186
178
|
background-color: var(--teal-300);
|
|
187
179
|
}
|
|
188
180
|
}
|
|
@@ -205,8 +197,7 @@ button.surface:not(.disabled) {
|
|
|
205
197
|
|
|
206
198
|
button.surface:not(.disabled) {
|
|
207
199
|
&.cyan {
|
|
208
|
-
&:hover
|
|
209
|
-
&:focus {
|
|
200
|
+
&:hover {
|
|
210
201
|
background-color: var(--cyan-300);
|
|
211
202
|
}
|
|
212
203
|
}
|
|
@@ -229,8 +220,7 @@ button.surface:not(.disabled) {
|
|
|
229
220
|
|
|
230
221
|
button.surface:not(.disabled) {
|
|
231
222
|
&.gray {
|
|
232
|
-
&:hover
|
|
233
|
-
&:focus {
|
|
223
|
+
&:hover {
|
|
234
224
|
background-color: var(--gray-300);
|
|
235
225
|
}
|
|
236
226
|
}
|
|
@@ -253,8 +243,7 @@ button.surface:not(.disabled) {
|
|
|
253
243
|
|
|
254
244
|
button.surface:not(.disabled) {
|
|
255
245
|
&.light {
|
|
256
|
-
&:hover
|
|
257
|
-
&:focus {
|
|
246
|
+
&:hover {
|
|
258
247
|
background-color: var(--light-300);
|
|
259
248
|
}
|
|
260
249
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type NodeData = {
|
|
2
|
+
id: number;
|
|
3
|
+
position: {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
};
|
|
7
|
+
data: {
|
|
8
|
+
label: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
type Port = "top" | "bottom";
|
|
12
|
+
export type EdgeData = {
|
|
13
|
+
id: number;
|
|
14
|
+
from: {
|
|
15
|
+
id: number;
|
|
16
|
+
port: Port;
|
|
17
|
+
};
|
|
18
|
+
to: {
|
|
19
|
+
id: number;
|
|
20
|
+
port: Port;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
interface IProps {
|
|
24
|
+
/**
|
|
25
|
+
* Sürüklenebilir liste verisi.
|
|
26
|
+
*
|
|
27
|
+
* Örneğin;
|
|
28
|
+
*
|
|
29
|
+
* ```jsx
|
|
30
|
+
* <Diagram data={[{ id: 1, ... }, { id: 2, ... }]} />
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
nodes: NodeData[];
|
|
34
|
+
/**
|
|
35
|
+
* Her bir öğenin nasıl render edileceğini tanımlar.
|
|
36
|
+
*
|
|
37
|
+
* - `item`: Mevcut öğe.
|
|
38
|
+
* - `index`: Öğenin listedeki sırası.
|
|
39
|
+
*
|
|
40
|
+
* Örneğin;
|
|
41
|
+
*
|
|
42
|
+
* ```jsx
|
|
43
|
+
* <Diagram renderItem={(item) => <div>{item.label}</div>} />
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
edges: EdgeData[];
|
|
47
|
+
}
|
|
48
|
+
export default IProps;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import React, { useMemo, useRef, useState } from "react";
|
|
2
|
+
import "../../../assets/css/components/data-display/diagram/styles.css";
|
|
3
|
+
import Grid from "../grid-system";
|
|
4
|
+
import Button from "../../form/button";
|
|
5
|
+
import Tooltip from "../../feedback/tooltip";
|
|
6
|
+
import { ARIcon } from "../../icons";
|
|
7
|
+
const { Box } = Grid;
|
|
8
|
+
export default function Diagram({ nodes, edges }) {
|
|
9
|
+
// refs
|
|
10
|
+
const _arDiagram = useRef(null);
|
|
11
|
+
const _content = useRef(null);
|
|
12
|
+
const _arNodes = useRef({});
|
|
13
|
+
const _path = useRef(null);
|
|
14
|
+
// refs -> Start Position
|
|
15
|
+
const _dragStartMousePosition = useRef({ x: 0, y: 0 });
|
|
16
|
+
const _dragStartNodePosition = useRef({ x: 0, y: 0 });
|
|
17
|
+
// refs -> Zoom
|
|
18
|
+
const _zoomIntensity = 0.1;
|
|
19
|
+
const _maxScale = 4;
|
|
20
|
+
const _minScale = 0.1;
|
|
21
|
+
// states
|
|
22
|
+
const [_nodes, setNodes] = useState(nodes);
|
|
23
|
+
const [_edges, setEdges] = useState(edges);
|
|
24
|
+
const [trigger, setTrigger] = useState(false);
|
|
25
|
+
// states -> Pan
|
|
26
|
+
const [pan, setPan] = useState({ x: 0, y: 0 });
|
|
27
|
+
const [panning, setPanning] = useState(false);
|
|
28
|
+
const [startPan, setStartPan] = useState({ x: 0, y: 0 });
|
|
29
|
+
// states -> Zoom
|
|
30
|
+
const [scale, setScale] = useState(1);
|
|
31
|
+
// states -> Drag
|
|
32
|
+
const [draggedNode, setDraggedNode] = useState(null);
|
|
33
|
+
// states -> Drawing
|
|
34
|
+
const [drawingEdge, setDrawingEdge] = useState(null);
|
|
35
|
+
const [mousePos, setMousePos] = useState(null);
|
|
36
|
+
// methods
|
|
37
|
+
const getPortCenter = (id, port) => {
|
|
38
|
+
const node = _arNodes.current[`${id}_${port}`];
|
|
39
|
+
const diagram = _arDiagram.current;
|
|
40
|
+
if (!node || !diagram)
|
|
41
|
+
return null;
|
|
42
|
+
const diagramRect = diagram.getBoundingClientRect();
|
|
43
|
+
const nodeRect = node.getBoundingClientRect();
|
|
44
|
+
return {
|
|
45
|
+
x: (nodeRect.left - diagramRect.left + nodeRect.width / 2 - pan.x) / scale,
|
|
46
|
+
y: (nodeRect.top - diagramRect.top + nodeRect.height / 2 - pan.y) / scale,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const getClosestPort = (position, threshold = 20) => {
|
|
50
|
+
for (const key in _arNodes.current) {
|
|
51
|
+
const el = _arNodes.current[key];
|
|
52
|
+
if (!el)
|
|
53
|
+
continue;
|
|
54
|
+
const [idStr, port] = key.split("_");
|
|
55
|
+
const id = parseInt(idStr, 10);
|
|
56
|
+
const rect = el.getBoundingClientRect();
|
|
57
|
+
const diagramRect = _arDiagram.current.getBoundingClientRect();
|
|
58
|
+
const portCenter = {
|
|
59
|
+
x: (rect.left - diagramRect.left + rect.width / 2 - pan.x) / scale,
|
|
60
|
+
y: (rect.top - diagramRect.top + rect.height / 2 - pan.y) / scale,
|
|
61
|
+
};
|
|
62
|
+
const distance = Math.hypot(position.x - portCenter.x, position.y - portCenter.y);
|
|
63
|
+
if (distance <= threshold)
|
|
64
|
+
return { id, port: port };
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
};
|
|
68
|
+
const renderEdges = useMemo(() => {
|
|
69
|
+
return _edges.map((edge, index) => {
|
|
70
|
+
const from = getPortCenter(edge.from.id, edge.from.port);
|
|
71
|
+
const to = getPortCenter(edge.to.id, edge.to.port);
|
|
72
|
+
if (!from || !to)
|
|
73
|
+
return null;
|
|
74
|
+
const dx = to.x - from.x;
|
|
75
|
+
const dy = to.y - from.y;
|
|
76
|
+
const distance = Math.hypot(dx, dy);
|
|
77
|
+
const offset = Math.min(40, distance * 0.25); // maksimum sapma sınırı
|
|
78
|
+
// S biçimli kontrol noktaları
|
|
79
|
+
const controlPoint1 = {
|
|
80
|
+
x: from.x,
|
|
81
|
+
y: from.y + (dy < 0 ? -offset : offset),
|
|
82
|
+
};
|
|
83
|
+
const controlPoint2 = {
|
|
84
|
+
x: to.x,
|
|
85
|
+
y: to.y + (dy < 0 ? offset : -offset),
|
|
86
|
+
};
|
|
87
|
+
const pathData = `M${from.x} ${from.y} C${controlPoint1.x} ${controlPoint1.y}, ${controlPoint2.x} ${controlPoint2.y}, ${to.x} ${to.y}`;
|
|
88
|
+
return (React.createElement("svg", { key: index, className: "edge" },
|
|
89
|
+
React.createElement("path", { ref: _path, d: pathData, fill: "none", stroke: "var(--purple-500)", strokeWidth: 2, strokeDasharray: 10, strokeDashoffset: 10, strokeLinecap: "round", onClick: () => {
|
|
90
|
+
setEdges((prev) => prev.filter((x) => x.id !== edge.id));
|
|
91
|
+
} },
|
|
92
|
+
React.createElement("animate", { attributeName: "stroke-dashoffset", values: `${20 / scale};0`, dur: "1s", repeatCount: "indefinite" }))));
|
|
93
|
+
});
|
|
94
|
+
}, [_nodes, _edges, trigger]);
|
|
95
|
+
const onPanStart = (e) => {
|
|
96
|
+
setPanning(true);
|
|
97
|
+
setStartPan({ x: e.clientX - pan.x, y: e.clientY - pan.y });
|
|
98
|
+
};
|
|
99
|
+
const onPanMove = (e) => {
|
|
100
|
+
if (panning) {
|
|
101
|
+
setPan({ x: e.clientX - startPan.x, y: e.clientY - startPan.y });
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const onPanEnd = () => setPanning(false);
|
|
105
|
+
// methods -> Zoom
|
|
106
|
+
const handleWheel = (event) => {
|
|
107
|
+
const direction = event.deltaY > 0 ? -1 : 1;
|
|
108
|
+
let newScale = scale + direction * _zoomIntensity;
|
|
109
|
+
newScale = Math.max(_minScale, Math.min(_maxScale, newScale));
|
|
110
|
+
// Mouse'un container içindeki konumunu al.
|
|
111
|
+
const rect = _content.current.getBoundingClientRect();
|
|
112
|
+
const mouseX = event.clientX - rect.left;
|
|
113
|
+
const mouseY = event.clientY - rect.top;
|
|
114
|
+
// İçerik düzleminde mouse'un bulunduğu noktayı bul.
|
|
115
|
+
const zoomPointX = (mouseX - pan.x) / scale;
|
|
116
|
+
const zoomPointY = (mouseY - pan.y) / scale;
|
|
117
|
+
// Yeni pan değerini hesapla ki zoomPoint sabit kalsın.
|
|
118
|
+
const newPanX = mouseX - zoomPointX * newScale;
|
|
119
|
+
const newPanY = mouseY - zoomPointY * newScale;
|
|
120
|
+
setScale(newScale);
|
|
121
|
+
setPan({ x: newPanX, y: newPanY });
|
|
122
|
+
};
|
|
123
|
+
const handleZoom = (process) => {
|
|
124
|
+
let newScale = 0;
|
|
125
|
+
if (process === "increment")
|
|
126
|
+
newScale = Math.max(_minScale, Math.min(_maxScale, scale + _zoomIntensity));
|
|
127
|
+
if (process === "decrement")
|
|
128
|
+
newScale = Math.max(_minScale, Math.min(_maxScale, scale - _zoomIntensity));
|
|
129
|
+
if (_content.current && _content.current) {
|
|
130
|
+
const containerRect = _content.current.getBoundingClientRect();
|
|
131
|
+
// Ortadaki noktayı bul (container açısından)
|
|
132
|
+
const centerX = containerRect.width / 2;
|
|
133
|
+
const centerY = containerRect.height / 2;
|
|
134
|
+
// İçerik düzleminde bu noktaya karşılık gelen nokta
|
|
135
|
+
const zoomPointX = (centerX - pan.x) / scale;
|
|
136
|
+
const zoomPointY = (centerY - pan.y) / scale;
|
|
137
|
+
// Yeni pan hesapla ki center aynı yerde kalsın
|
|
138
|
+
const newPanX = centerX - zoomPointX * newScale;
|
|
139
|
+
const newPanY = centerY - zoomPointY * newScale;
|
|
140
|
+
setPan({ x: newPanX, y: newPanY });
|
|
141
|
+
setScale(newScale);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
// methods -> Node
|
|
145
|
+
const onNodeMouseDown = (event, id, node) => {
|
|
146
|
+
event.stopPropagation();
|
|
147
|
+
setDraggedNode(id);
|
|
148
|
+
_dragStartMousePosition.current = { x: event.clientX, y: event.clientY };
|
|
149
|
+
_dragStartNodePosition.current = { x: node.x, y: node.y };
|
|
150
|
+
};
|
|
151
|
+
const onMouseMove = (event) => {
|
|
152
|
+
if (drawingEdge) {
|
|
153
|
+
const rect = _arDiagram.current.getBoundingClientRect();
|
|
154
|
+
const x = (event.clientX - rect.left - pan.x) / scale;
|
|
155
|
+
const y = (event.clientY - rect.top - pan.y) / scale;
|
|
156
|
+
setMousePos({ x, y });
|
|
157
|
+
}
|
|
158
|
+
if (draggedNode) {
|
|
159
|
+
const deltaX = (event.clientX - _dragStartMousePosition.current.x) / scale;
|
|
160
|
+
const deltaY = (event.clientY - _dragStartMousePosition.current.y) / scale;
|
|
161
|
+
const newX = _dragStartNodePosition.current.x + deltaX;
|
|
162
|
+
const newY = _dragStartNodePosition.current.y + deltaY;
|
|
163
|
+
setNodes((prev) => prev.map((node) => (node.id === draggedNode ? { ...node, position: { x: newX, y: newY } } : node)));
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const onMouseUp = () => {
|
|
167
|
+
if (drawingEdge && mousePos) {
|
|
168
|
+
const closest = getClosestPort(mousePos);
|
|
169
|
+
if (closest) {
|
|
170
|
+
// Yakın port varsa, oraya bağla
|
|
171
|
+
const newEdge = {
|
|
172
|
+
id: _edges[_edges.length - 1]?.id + 1 || 1,
|
|
173
|
+
from: { id: drawingEdge.id, port: drawingEdge.port },
|
|
174
|
+
to: { id: closest.id, port: closest.port },
|
|
175
|
+
};
|
|
176
|
+
setEdges((prev) => [...prev, newEdge]);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
// Yakın port yoksa yeni node oluştur
|
|
180
|
+
const newNodeId = _nodes[_nodes.length - 1]?.id + 1 || 1;
|
|
181
|
+
const newNode = {
|
|
182
|
+
id: newNodeId,
|
|
183
|
+
position: mousePos,
|
|
184
|
+
data: { label: `Node - ${newNodeId}` },
|
|
185
|
+
};
|
|
186
|
+
const newPort = mousePos.y < drawingEdge.start.y ? "bottom" : "top";
|
|
187
|
+
const newEdge = {
|
|
188
|
+
id: _edges[_edges.length - 1]?.id + 1 || 1,
|
|
189
|
+
from: { id: drawingEdge.id, port: drawingEdge.port },
|
|
190
|
+
to: { id: newNodeId, port: newPort },
|
|
191
|
+
};
|
|
192
|
+
setNodes((prev) => [...prev, newNode]);
|
|
193
|
+
setEdges((prev) => [...prev, newEdge]);
|
|
194
|
+
}
|
|
195
|
+
setDrawingEdge(null);
|
|
196
|
+
setMousePos(null);
|
|
197
|
+
}
|
|
198
|
+
setDraggedNode(null);
|
|
199
|
+
setTrigger((prev) => !prev);
|
|
200
|
+
};
|
|
201
|
+
return (React.createElement("div", { ref: _arDiagram, className: "ar-diagram", onMouseDown: onPanStart, onMouseMove: (event) => {
|
|
202
|
+
onPanMove(event);
|
|
203
|
+
onMouseMove(event);
|
|
204
|
+
}, onMouseUp: () => {
|
|
205
|
+
onMouseUp();
|
|
206
|
+
onPanEnd();
|
|
207
|
+
} },
|
|
208
|
+
React.createElement("div", { ref: _content, className: "content", style: { backgroundPosition: `${pan.x}px ${pan.y}px` }, onWheel: handleWheel },
|
|
209
|
+
React.createElement("div", { className: "nodes-wrapper", style: {
|
|
210
|
+
transform: `translate(${pan.x}px, ${pan.y}px) scale(${scale})`,
|
|
211
|
+
} },
|
|
212
|
+
React.createElement("div", { className: "edges" },
|
|
213
|
+
renderEdges,
|
|
214
|
+
drawingEdge && mousePos && (React.createElement("svg", { className: "edge-temp" },
|
|
215
|
+
React.createElement("path", { ref: _path, d: `M${drawingEdge.start.x} ${drawingEdge.start.y} L${mousePos.x} ${mousePos.y}`, fill: "none", stroke: "var(--purple-500)", strokeWidth: 2, strokeDasharray: 10, strokeDashoffset: 10, strokeLinecap: "round" })))),
|
|
216
|
+
React.createElement("div", { className: "nodes" }, _nodes.map((node, index) => (React.createElement("div", { key: index, className: "node", style: {
|
|
217
|
+
left: node.position.x,
|
|
218
|
+
top: node.position.y,
|
|
219
|
+
}, onMouseDown: (event) => onNodeMouseDown(event, node.id, node.position) },
|
|
220
|
+
React.createElement("span", { ref: (el) => {
|
|
221
|
+
_arNodes.current[`${node.id}_top`] = el;
|
|
222
|
+
}, className: "port top", onMouseDown: (event) => {
|
|
223
|
+
event.stopPropagation();
|
|
224
|
+
const port = "top";
|
|
225
|
+
const from = getPortCenter(node.id, port);
|
|
226
|
+
if (from) {
|
|
227
|
+
setDrawingEdge({
|
|
228
|
+
id: node.id,
|
|
229
|
+
port,
|
|
230
|
+
start: from,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
} }),
|
|
234
|
+
React.createElement("span", null, node.data.label),
|
|
235
|
+
React.createElement("span", { ref: (el) => {
|
|
236
|
+
_arNodes.current[`${node.id}_bottom`] = el;
|
|
237
|
+
}, className: "port bottom", onMouseDown: (event) => {
|
|
238
|
+
event.stopPropagation();
|
|
239
|
+
const from = getPortCenter(node.id, "bottom");
|
|
240
|
+
if (from) {
|
|
241
|
+
setDrawingEdge({
|
|
242
|
+
id: node.id,
|
|
243
|
+
port: "bottom",
|
|
244
|
+
start: from,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
} }))))))),
|
|
248
|
+
React.createElement("div", { className: "zoom-buttons", onMouseDown: (event) => event.stopPropagation() },
|
|
249
|
+
React.createElement(Box, null,
|
|
250
|
+
React.createElement(Tooltip, { text: "Zoom Out" },
|
|
251
|
+
React.createElement(Button, { variant: "borderless", color: "light", icon: { element: React.createElement(ARIcon, { icon: "Dash", fill: "currentColor" }) }, onClick: () => handleZoom("decrement") })),
|
|
252
|
+
React.createElement("div", { className: "zoom-percent" },
|
|
253
|
+
Math.round(scale * 100),
|
|
254
|
+
"%"),
|
|
255
|
+
React.createElement(Tooltip, { text: "Zoom In" },
|
|
256
|
+
React.createElement(Button, { variant: "borderless", color: "light", icon: { element: React.createElement(ARIcon, { icon: "Add", fill: "currentColor" }) }, onClick: () => handleZoom("increment") })))),
|
|
257
|
+
React.createElement("div", { style: { zIndex: 555 } }, JSON.stringify(drawingEdge))));
|
|
258
|
+
}
|
|
@@ -36,9 +36,6 @@ const DnD = function ({ data, renderItem, onChange }) {
|
|
|
36
36
|
window.scrollBy(0, -20);
|
|
37
37
|
if (rect.bottom > window.innerHeight - 150)
|
|
38
38
|
window.scrollBy(0, 20);
|
|
39
|
-
// if (!overItem.classList.contains("over-item")) {
|
|
40
|
-
// overItem.classList.add("over-item");
|
|
41
|
-
// }
|
|
42
39
|
const nodes = document.querySelectorAll("[data-id='ar-firewall']");
|
|
43
40
|
nodes.forEach((node) => node.remove());
|
|
44
41
|
if (_dragItem.current !== overItem) {
|
|
@@ -56,15 +53,6 @@ const DnD = function ({ data, renderItem, onChange }) {
|
|
|
56
53
|
onChange(data);
|
|
57
54
|
}
|
|
58
55
|
};
|
|
59
|
-
// _item.ondragleave = (event) => {
|
|
60
|
-
// const leaveItem = event.currentTarget as HTMLElement;
|
|
61
|
-
// leaveItem.classList.remove("over-item");
|
|
62
|
-
// };
|
|
63
|
-
// _item.ondrop = (event) => {
|
|
64
|
-
// // const dropItem = event.currentTarget as HTMLElement;
|
|
65
|
-
// // Temizlik...
|
|
66
|
-
// // dropItem.classList.remove("over-item");
|
|
67
|
-
// };
|
|
68
56
|
_item.ondragend = (event) => {
|
|
69
57
|
const item = event.currentTarget;
|
|
70
58
|
item.classList.remove("drag-item");
|