@yh-ui/flow 1.0.26 → 1.0.36
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/package.json +6 -6
- package/dist/__tests__/ai-workflow.ssr.test.cjs +0 -352
- package/dist/__tests__/ai-workflow.ssr.test.d.ts +0 -1
- package/dist/__tests__/ai-workflow.ssr.test.mjs +0 -283
- package/dist/__tests__/ai-workflow.test.cjs +0 -109
- package/dist/__tests__/ai-workflow.test.d.ts +0 -1
- package/dist/__tests__/ai-workflow.test.mjs +0 -112
- package/dist/__tests__/bpmn-engine.test.cjs +0 -357
- package/dist/__tests__/bpmn-engine.test.d.ts +0 -1
- package/dist/__tests__/bpmn-engine.test.mjs +0 -406
- package/dist/__tests__/bpmn-utils.test.cjs +0 -268
- package/dist/__tests__/bpmn-utils.test.d.ts +0 -1
- package/dist/__tests__/bpmn-utils.test.mjs +0 -227
- package/dist/__tests__/bpmn-xml.test.cjs +0 -150
- package/dist/__tests__/bpmn-xml.test.d.ts +0 -1
- package/dist/__tests__/bpmn-xml.test.mjs +0 -112
- package/dist/__tests__/bpmn.ssr.test.cjs +0 -278
- package/dist/__tests__/bpmn.ssr.test.d.ts +0 -1
- package/dist/__tests__/bpmn.ssr.test.mjs +0 -237
- package/dist/__tests__/bpmn.test.cjs +0 -103
- package/dist/__tests__/bpmn.test.d.ts +0 -1
- package/dist/__tests__/bpmn.test.mjs +0 -106
- package/dist/__tests__/collaboration.test.cjs +0 -487
- package/dist/__tests__/collaboration.test.d.ts +0 -1
- package/dist/__tests__/collaboration.test.mjs +0 -424
- package/dist/__tests__/custom-types.test.cjs +0 -300
- package/dist/__tests__/custom-types.test.d.ts +0 -1
- package/dist/__tests__/custom-types.test.mjs +0 -248
- package/dist/__tests__/edge-types.test.cjs +0 -275
- package/dist/__tests__/edge-types.test.d.ts +0 -1
- package/dist/__tests__/edge-types.test.mjs +0 -234
- package/dist/__tests__/edge-utils.test.cjs +0 -375
- package/dist/__tests__/edge-utils.test.d.ts +0 -1
- package/dist/__tests__/edge-utils.test.mjs +0 -376
- package/dist/__tests__/edge.test.cjs +0 -56
- package/dist/__tests__/edge.test.d.ts +0 -1
- package/dist/__tests__/edge.test.mjs +0 -69
- package/dist/__tests__/event-bus.test.cjs +0 -80
- package/dist/__tests__/event-bus.test.d.ts +0 -1
- package/dist/__tests__/event-bus.test.mjs +0 -51
- package/dist/__tests__/events-types.test.cjs +0 -184
- package/dist/__tests__/events-types.test.d.ts +0 -1
- package/dist/__tests__/events-types.test.mjs +0 -184
- package/dist/__tests__/export-image-plugin.test.cjs +0 -142
- package/dist/__tests__/export-image-plugin.test.d.ts +0 -1
- package/dist/__tests__/export-image-plugin.test.mjs +0 -118
- package/dist/__tests__/export.test.cjs +0 -237
- package/dist/__tests__/export.test.d.ts +0 -1
- package/dist/__tests__/export.test.mjs +0 -171
- package/dist/__tests__/flow-context.test.cjs +0 -16
- package/dist/__tests__/flow-context.test.d.ts +0 -1
- package/dist/__tests__/flow-context.test.mjs +0 -16
- package/dist/__tests__/flow-props.test.cjs +0 -94
- package/dist/__tests__/flow-props.test.d.ts +0 -1
- package/dist/__tests__/flow-props.test.mjs +0 -92
- package/dist/__tests__/flow.ssr.test.cjs +0 -156
- package/dist/__tests__/flow.ssr.test.d.ts +0 -1
- package/dist/__tests__/flow.ssr.test.mjs +0 -112
- package/dist/__tests__/geometry.test.cjs +0 -191
- package/dist/__tests__/geometry.test.d.ts +0 -1
- package/dist/__tests__/geometry.test.mjs +0 -105
- package/dist/__tests__/graph.test.cjs +0 -115
- package/dist/__tests__/graph.test.d.ts +0 -1
- package/dist/__tests__/graph.test.mjs +0 -85
- package/dist/__tests__/history-plugin.test.cjs +0 -191
- package/dist/__tests__/history-plugin.test.d.ts +0 -1
- package/dist/__tests__/history-plugin.test.mjs +0 -161
- package/dist/__tests__/history.test.cjs +0 -81
- package/dist/__tests__/history.test.d.ts +0 -1
- package/dist/__tests__/history.test.mjs +0 -43
- package/dist/__tests__/layout-plugin.test.cjs +0 -233
- package/dist/__tests__/layout-plugin.test.d.ts +0 -1
- package/dist/__tests__/layout-plugin.test.mjs +0 -215
- package/dist/__tests__/layout.test.cjs +0 -213
- package/dist/__tests__/layout.test.d.ts +0 -1
- package/dist/__tests__/layout.test.mjs +0 -170
- package/dist/__tests__/node-edit-panel.ssr.test.cjs +0 -168
- package/dist/__tests__/node-edit-panel.ssr.test.d.ts +0 -1
- package/dist/__tests__/node-edit-panel.ssr.test.mjs +0 -118
- package/dist/__tests__/node-group-plugin.test.cjs +0 -235
- package/dist/__tests__/node-group-plugin.test.d.ts +0 -1
- package/dist/__tests__/node-group-plugin.test.mjs +0 -187
- package/dist/__tests__/node-handles.test.cjs +0 -340
- package/dist/__tests__/node-handles.test.d.ts +0 -1
- package/dist/__tests__/node-handles.test.mjs +0 -230
- package/dist/__tests__/node-types.test.cjs +0 -368
- package/dist/__tests__/node-types.test.d.ts +0 -1
- package/dist/__tests__/node-types.test.mjs +0 -292
- package/dist/__tests__/performance.test.cjs +0 -313
- package/dist/__tests__/performance.test.d.ts +0 -1
- package/dist/__tests__/performance.test.mjs +0 -218
- package/dist/__tests__/plugin-advanced.test.cjs +0 -301
- package/dist/__tests__/plugin-advanced.test.d.ts +0 -1
- package/dist/__tests__/plugin-advanced.test.mjs +0 -225
- package/dist/__tests__/plugin.test.cjs +0 -151
- package/dist/__tests__/plugin.test.d.ts +0 -1
- package/dist/__tests__/plugin.test.mjs +0 -116
- package/dist/__tests__/plugins.test.cjs +0 -412
- package/dist/__tests__/plugins.test.d.ts +0 -1
- package/dist/__tests__/plugins.test.mjs +0 -402
- package/dist/__tests__/screenshot-capture.test.cjs +0 -183
- package/dist/__tests__/screenshot-capture.test.d.ts +0 -1
- package/dist/__tests__/screenshot-capture.test.mjs +0 -124
- package/dist/__tests__/screenshot.test.cjs +0 -74
- package/dist/__tests__/screenshot.test.d.ts +0 -1
- package/dist/__tests__/screenshot.test.mjs +0 -69
- package/dist/__tests__/theme.test.cjs +0 -185
- package/dist/__tests__/theme.test.d.ts +0 -1
- package/dist/__tests__/theme.test.mjs +0 -191
- package/dist/__tests__/transform.test.cjs +0 -384
- package/dist/__tests__/transform.test.d.ts +0 -1
- package/dist/__tests__/transform.test.mjs +0 -239
- package/dist/__tests__/useAlignment.test.cjs +0 -128
- package/dist/__tests__/useAlignment.test.d.ts +0 -1
- package/dist/__tests__/useAlignment.test.mjs +0 -72
- package/dist/__tests__/useEdges.test.cjs +0 -117
- package/dist/__tests__/useEdges.test.d.ts +0 -1
- package/dist/__tests__/useEdges.test.mjs +0 -80
- package/dist/__tests__/useKeyboard.test.cjs +0 -88
- package/dist/__tests__/useKeyboard.test.d.ts +0 -1
- package/dist/__tests__/useKeyboard.test.mjs +0 -56
- package/dist/__tests__/useNodeDistribution.test.cjs +0 -643
- package/dist/__tests__/useNodeDistribution.test.d.ts +0 -1
- package/dist/__tests__/useNodeDistribution.test.mjs +0 -297
- package/dist/__tests__/useNodes.test.cjs +0 -150
- package/dist/__tests__/useNodes.test.d.ts +0 -1
- package/dist/__tests__/useNodes.test.mjs +0 -80
- package/dist/__tests__/useSelection.test.cjs +0 -112
- package/dist/__tests__/useSelection.test.d.ts +0 -1
- package/dist/__tests__/useSelection.test.mjs +0 -76
- package/dist/__tests__/useViewport.test.cjs +0 -171
- package/dist/__tests__/useViewport.test.d.ts +0 -1
- package/dist/__tests__/useViewport.test.mjs +0 -82
- package/dist/__tests__/utils/ssr.cjs +0 -124
- package/dist/__tests__/utils/ssr.d.ts +0 -33
- package/dist/__tests__/utils/ssr.mjs +0 -129
- package/dist/__tests__/validation.test.cjs +0 -95
- package/dist/__tests__/validation.test.d.ts +0 -1
- package/dist/__tests__/validation.test.mjs +0 -36
- package/dist/__tests__/viewport-types.test.cjs +0 -324
- package/dist/__tests__/viewport-types.test.d.ts +0 -1
- package/dist/__tests__/viewport-types.test.mjs +0 -207
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
getHandlePosition,
|
|
4
|
-
getBezierPath,
|
|
5
|
-
getStraightPath,
|
|
6
|
-
getStepPath,
|
|
7
|
-
getSmoothStepPath,
|
|
8
|
-
getEdgePath,
|
|
9
|
-
getEdgeCenter,
|
|
10
|
-
shortenEndpoint
|
|
11
|
-
} from "../utils/edge.mjs";
|
|
12
|
-
function createMockNode(x, y, width = 150, height = 80, style) {
|
|
13
|
-
return {
|
|
14
|
-
id: "test",
|
|
15
|
-
type: "default",
|
|
16
|
-
position: { x, y },
|
|
17
|
-
width,
|
|
18
|
-
height,
|
|
19
|
-
style,
|
|
20
|
-
data: {},
|
|
21
|
-
selected: false,
|
|
22
|
-
dragging: false
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
describe("flow/utils/edge", () => {
|
|
26
|
-
describe("getHandlePosition", () => {
|
|
27
|
-
it("should return center for unknown position", () => {
|
|
28
|
-
const node = createMockNode(0, 0, 100, 50);
|
|
29
|
-
const result = getHandlePosition(node, "unknown");
|
|
30
|
-
expect(result.x).toBe(50);
|
|
31
|
-
expect(result.y).toBe(25);
|
|
32
|
-
});
|
|
33
|
-
it("should return top handle position", () => {
|
|
34
|
-
const node = createMockNode(10, 20, 100, 50);
|
|
35
|
-
const result = getHandlePosition(node, "top");
|
|
36
|
-
expect(result.x).toBe(60);
|
|
37
|
-
expect(result.y).toBe(20);
|
|
38
|
-
});
|
|
39
|
-
it("should return bottom handle position", () => {
|
|
40
|
-
const node = createMockNode(10, 20, 100, 50);
|
|
41
|
-
const result = getHandlePosition(node, "bottom");
|
|
42
|
-
expect(result.x).toBe(60);
|
|
43
|
-
expect(result.y).toBe(70);
|
|
44
|
-
});
|
|
45
|
-
it("should return left handle position", () => {
|
|
46
|
-
const node = createMockNode(10, 20, 100, 50);
|
|
47
|
-
const result = getHandlePosition(node, "left");
|
|
48
|
-
expect(result.x).toBe(10);
|
|
49
|
-
expect(result.y).toBe(45);
|
|
50
|
-
});
|
|
51
|
-
it("should return right handle position", () => {
|
|
52
|
-
const node = createMockNode(10, 20, 100, 50);
|
|
53
|
-
const result = getHandlePosition(node, "right");
|
|
54
|
-
expect(result.x).toBe(110);
|
|
55
|
-
expect(result.y).toBe(45);
|
|
56
|
-
});
|
|
57
|
-
it("should fallback to default dimensions when width/height are undefined", () => {
|
|
58
|
-
const node = {
|
|
59
|
-
position: { x: 0, y: 0 },
|
|
60
|
-
data: {},
|
|
61
|
-
selected: false,
|
|
62
|
-
dragging: false
|
|
63
|
-
};
|
|
64
|
-
const result = getHandlePosition(node, "right");
|
|
65
|
-
expect(result.x).toBe(150);
|
|
66
|
-
expect(result.y).toBe(20);
|
|
67
|
-
});
|
|
68
|
-
it("should use right as default position", () => {
|
|
69
|
-
const node = createMockNode(0, 0, 100, 50);
|
|
70
|
-
const result = getHandlePosition(node);
|
|
71
|
-
expect(result.x).toBe(100);
|
|
72
|
-
expect(result.y).toBe(25);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
describe("getBezierPath", () => {
|
|
76
|
-
it("should generate bezier path", () => {
|
|
77
|
-
const result = getBezierPath({
|
|
78
|
-
sourceX: 0,
|
|
79
|
-
sourceY: 0,
|
|
80
|
-
targetX: 100,
|
|
81
|
-
targetY: 50,
|
|
82
|
-
sourcePosition: "right",
|
|
83
|
-
targetPosition: "left"
|
|
84
|
-
});
|
|
85
|
-
expect(result).toContain("M0,0");
|
|
86
|
-
expect(result).toContain("100,50");
|
|
87
|
-
expect(result).toContain("C");
|
|
88
|
-
});
|
|
89
|
-
it("should use custom curvature", () => {
|
|
90
|
-
const result = getBezierPath({
|
|
91
|
-
sourceX: 0,
|
|
92
|
-
sourceY: 0,
|
|
93
|
-
targetX: 100,
|
|
94
|
-
targetY: 50,
|
|
95
|
-
sourcePosition: "right",
|
|
96
|
-
targetPosition: "left",
|
|
97
|
-
curvature: 0.5
|
|
98
|
-
});
|
|
99
|
-
expect(result).toContain("M0,0");
|
|
100
|
-
expect(result).toContain("100,50");
|
|
101
|
-
});
|
|
102
|
-
it("should handle vertical movement", () => {
|
|
103
|
-
const result = getBezierPath({
|
|
104
|
-
sourceX: 50,
|
|
105
|
-
sourceY: 0,
|
|
106
|
-
targetX: 50,
|
|
107
|
-
targetY: 100,
|
|
108
|
-
sourcePosition: "bottom",
|
|
109
|
-
targetPosition: "top"
|
|
110
|
-
});
|
|
111
|
-
expect(result).toContain("M50,0");
|
|
112
|
-
expect(result).toContain("50,100");
|
|
113
|
-
});
|
|
114
|
-
it("should handle top to bottom direction", () => {
|
|
115
|
-
const result = getBezierPath({
|
|
116
|
-
sourceX: 50,
|
|
117
|
-
sourceY: 0,
|
|
118
|
-
targetX: 50,
|
|
119
|
-
targetY: 100,
|
|
120
|
-
sourcePosition: "top",
|
|
121
|
-
targetPosition: "bottom"
|
|
122
|
-
});
|
|
123
|
-
expect(result).toContain("M50,0");
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
describe("getStraightPath", () => {
|
|
127
|
-
it("should generate straight line path", () => {
|
|
128
|
-
const result = getStraightPath({
|
|
129
|
-
sourceX: 0,
|
|
130
|
-
sourceY: 0,
|
|
131
|
-
targetX: 100,
|
|
132
|
-
targetY: 50,
|
|
133
|
-
sourcePosition: "right",
|
|
134
|
-
targetPosition: "left"
|
|
135
|
-
});
|
|
136
|
-
expect(result).toBe("M0,0 L100,50");
|
|
137
|
-
});
|
|
138
|
-
it("should handle diagonal line", () => {
|
|
139
|
-
const result = getStraightPath({
|
|
140
|
-
sourceX: 10,
|
|
141
|
-
sourceY: 20,
|
|
142
|
-
targetX: 300,
|
|
143
|
-
targetY: 400,
|
|
144
|
-
sourcePosition: "right",
|
|
145
|
-
targetPosition: "left"
|
|
146
|
-
});
|
|
147
|
-
expect(result).toBe("M10,20 L300,400");
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
describe("getStepPath", () => {
|
|
151
|
-
it("should generate step path when source is horizontal and target is vertical", () => {
|
|
152
|
-
const result = getStepPath({
|
|
153
|
-
sourceX: 0,
|
|
154
|
-
sourceY: 0,
|
|
155
|
-
targetX: 100,
|
|
156
|
-
targetY: 50,
|
|
157
|
-
sourcePosition: "right",
|
|
158
|
-
targetPosition: "top"
|
|
159
|
-
});
|
|
160
|
-
expect(result).toContain("M0,0");
|
|
161
|
-
expect(result).toContain("L");
|
|
162
|
-
expect(result).toContain("100,50");
|
|
163
|
-
});
|
|
164
|
-
it("should generate step path when source is vertical and target is horizontal", () => {
|
|
165
|
-
const result = getStepPath({
|
|
166
|
-
sourceX: 0,
|
|
167
|
-
sourceY: 0,
|
|
168
|
-
targetX: 100,
|
|
169
|
-
targetY: 50,
|
|
170
|
-
sourcePosition: "top",
|
|
171
|
-
targetPosition: "right"
|
|
172
|
-
});
|
|
173
|
-
expect(result).toContain("M0,0");
|
|
174
|
-
expect(result).toContain("L");
|
|
175
|
-
});
|
|
176
|
-
it("should handle both horizontal", () => {
|
|
177
|
-
const result = getStepPath({
|
|
178
|
-
sourceX: 0,
|
|
179
|
-
sourceY: 50,
|
|
180
|
-
targetX: 100,
|
|
181
|
-
targetY: 50,
|
|
182
|
-
sourcePosition: "right",
|
|
183
|
-
targetPosition: "left"
|
|
184
|
-
});
|
|
185
|
-
expect(result).toContain("M0,50");
|
|
186
|
-
expect(result).toContain("L");
|
|
187
|
-
});
|
|
188
|
-
it("should handle both vertical", () => {
|
|
189
|
-
const result = getStepPath({
|
|
190
|
-
sourceX: 50,
|
|
191
|
-
sourceY: 0,
|
|
192
|
-
targetX: 50,
|
|
193
|
-
targetY: 100,
|
|
194
|
-
sourcePosition: "bottom",
|
|
195
|
-
targetPosition: "top"
|
|
196
|
-
});
|
|
197
|
-
expect(result).toContain("M50,0");
|
|
198
|
-
expect(result).toContain("L");
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
describe("getSmoothStepPath", () => {
|
|
202
|
-
it("should generate smooth step path for horizontal source", () => {
|
|
203
|
-
const result = getSmoothStepPath({
|
|
204
|
-
sourceX: 0,
|
|
205
|
-
sourceY: 0,
|
|
206
|
-
targetX: 100,
|
|
207
|
-
targetY: 50,
|
|
208
|
-
sourcePosition: "right",
|
|
209
|
-
targetPosition: "top"
|
|
210
|
-
});
|
|
211
|
-
expect(result).toContain("M0,0");
|
|
212
|
-
expect(result).toContain("Q");
|
|
213
|
-
expect(result).toContain("100,50");
|
|
214
|
-
});
|
|
215
|
-
it("should generate smooth step path for vertical source", () => {
|
|
216
|
-
const result = getSmoothStepPath({
|
|
217
|
-
sourceX: 0,
|
|
218
|
-
sourceY: 0,
|
|
219
|
-
targetX: 100,
|
|
220
|
-
targetY: 50,
|
|
221
|
-
sourcePosition: "bottom",
|
|
222
|
-
targetPosition: "right"
|
|
223
|
-
});
|
|
224
|
-
expect(result).toContain("M0,0");
|
|
225
|
-
expect(result).toContain("Q");
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
describe("getEdgePath", () => {
|
|
229
|
-
it("should return bezier path for bezier type", () => {
|
|
230
|
-
const result = getEdgePath("bezier", {
|
|
231
|
-
sourceX: 0,
|
|
232
|
-
sourceY: 0,
|
|
233
|
-
targetX: 100,
|
|
234
|
-
targetY: 50,
|
|
235
|
-
sourcePosition: "right",
|
|
236
|
-
targetPosition: "left"
|
|
237
|
-
});
|
|
238
|
-
expect(result).toContain("C");
|
|
239
|
-
});
|
|
240
|
-
it("should return straight path for straight type", () => {
|
|
241
|
-
const result = getEdgePath("straight", {
|
|
242
|
-
sourceX: 0,
|
|
243
|
-
sourceY: 0,
|
|
244
|
-
targetX: 100,
|
|
245
|
-
targetY: 50,
|
|
246
|
-
sourcePosition: "right",
|
|
247
|
-
targetPosition: "left"
|
|
248
|
-
});
|
|
249
|
-
expect(result).toBe("M0,0 L100,50");
|
|
250
|
-
});
|
|
251
|
-
it("should return step path for step type", () => {
|
|
252
|
-
const result = getEdgePath("step", {
|
|
253
|
-
sourceX: 0,
|
|
254
|
-
sourceY: 0,
|
|
255
|
-
targetX: 100,
|
|
256
|
-
targetY: 50,
|
|
257
|
-
sourcePosition: "right",
|
|
258
|
-
targetPosition: "top"
|
|
259
|
-
});
|
|
260
|
-
expect(result).toContain("L");
|
|
261
|
-
});
|
|
262
|
-
it("should return smooth step path for smoothstep type", () => {
|
|
263
|
-
const result = getEdgePath("smoothstep", {
|
|
264
|
-
sourceX: 0,
|
|
265
|
-
sourceY: 0,
|
|
266
|
-
targetX: 100,
|
|
267
|
-
targetY: 50,
|
|
268
|
-
sourcePosition: "right",
|
|
269
|
-
targetPosition: "top"
|
|
270
|
-
});
|
|
271
|
-
expect(result).toContain("Q");
|
|
272
|
-
});
|
|
273
|
-
it("should default to bezier for unknown type", () => {
|
|
274
|
-
const result = getEdgePath("unknown", {
|
|
275
|
-
sourceX: 0,
|
|
276
|
-
sourceY: 0,
|
|
277
|
-
targetX: 100,
|
|
278
|
-
targetY: 50,
|
|
279
|
-
sourcePosition: "right",
|
|
280
|
-
targetPosition: "left"
|
|
281
|
-
});
|
|
282
|
-
expect(result).toContain("C");
|
|
283
|
-
});
|
|
284
|
-
it("should default to bezier for default type", () => {
|
|
285
|
-
const result = getEdgePath("default", {
|
|
286
|
-
sourceX: 0,
|
|
287
|
-
sourceY: 0,
|
|
288
|
-
targetX: 100,
|
|
289
|
-
targetY: 50,
|
|
290
|
-
sourcePosition: "right",
|
|
291
|
-
targetPosition: "left"
|
|
292
|
-
});
|
|
293
|
-
expect(result).toContain("C");
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
describe("getEdgeCenter", () => {
|
|
297
|
-
it("should return center for bezier type", () => {
|
|
298
|
-
const result = getEdgeCenter({
|
|
299
|
-
sourceX: 0,
|
|
300
|
-
sourceY: 0,
|
|
301
|
-
targetX: 100,
|
|
302
|
-
targetY: 50,
|
|
303
|
-
sourcePosition: "right",
|
|
304
|
-
targetPosition: "left",
|
|
305
|
-
type: "bezier"
|
|
306
|
-
});
|
|
307
|
-
expect(result).toHaveProperty("x");
|
|
308
|
-
expect(result).toHaveProperty("y");
|
|
309
|
-
expect(result).toHaveProperty("ox");
|
|
310
|
-
expect(result).toHaveProperty("oy");
|
|
311
|
-
});
|
|
312
|
-
it("should return center for straight type", () => {
|
|
313
|
-
const result = getEdgeCenter({
|
|
314
|
-
sourceX: 0,
|
|
315
|
-
sourceY: 0,
|
|
316
|
-
targetX: 100,
|
|
317
|
-
targetY: 50,
|
|
318
|
-
sourcePosition: "right",
|
|
319
|
-
targetPosition: "left",
|
|
320
|
-
type: "straight"
|
|
321
|
-
});
|
|
322
|
-
expect(result.x).toBe(50);
|
|
323
|
-
expect(result.y).toBe(25);
|
|
324
|
-
});
|
|
325
|
-
it("should return center for step type", () => {
|
|
326
|
-
const result = getEdgeCenter({
|
|
327
|
-
sourceX: 0,
|
|
328
|
-
sourceY: 0,
|
|
329
|
-
targetX: 100,
|
|
330
|
-
targetY: 50,
|
|
331
|
-
sourcePosition: "right",
|
|
332
|
-
targetPosition: "left",
|
|
333
|
-
type: "step"
|
|
334
|
-
});
|
|
335
|
-
expect(result.x).toBe(50);
|
|
336
|
-
expect(result.y).toBe(25);
|
|
337
|
-
});
|
|
338
|
-
it("should default to bezier when type is undefined", () => {
|
|
339
|
-
const result = getEdgeCenter({
|
|
340
|
-
sourceX: 0,
|
|
341
|
-
sourceY: 0,
|
|
342
|
-
targetX: 100,
|
|
343
|
-
targetY: 50,
|
|
344
|
-
sourcePosition: "right",
|
|
345
|
-
targetPosition: "left"
|
|
346
|
-
});
|
|
347
|
-
expect(result).toHaveProperty("x");
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
describe("shortenEndpoint", () => {
|
|
351
|
-
it("should shorten endpoint in the direction of source", () => {
|
|
352
|
-
const result = shortenEndpoint(100, 50, 0, 0, 10);
|
|
353
|
-
expect(result.x).toBeLessThan(100);
|
|
354
|
-
expect(result.y).toBeLessThan(50);
|
|
355
|
-
});
|
|
356
|
-
it("should not shorten when distance is too small", () => {
|
|
357
|
-
const result = shortenEndpoint(5, 5, 0, 0, 10);
|
|
358
|
-
expect(result.x).toBe(5);
|
|
359
|
-
expect(result.y).toBe(5);
|
|
360
|
-
});
|
|
361
|
-
it("should shorten towards source", () => {
|
|
362
|
-
const result = shortenEndpoint(200, 100, 100, 50, 10);
|
|
363
|
-
const dx = 200 - 100;
|
|
364
|
-
const dy = 100 - 50;
|
|
365
|
-
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
366
|
-
const factor = 10 / dist;
|
|
367
|
-
expect(result.x).toBeCloseTo(200 - dx * factor, 5);
|
|
368
|
-
expect(result.y).toBeCloseTo(100 - dy * factor, 5);
|
|
369
|
-
});
|
|
370
|
-
it("should handle vertical movement", () => {
|
|
371
|
-
const result = shortenEndpoint(50, 100, 50, 0, 10);
|
|
372
|
-
expect(result.x).toBe(50);
|
|
373
|
-
expect(result.y).toBeCloseTo(90, 0);
|
|
374
|
-
});
|
|
375
|
-
});
|
|
376
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _vitest = require("vitest");
|
|
4
|
-
var _edge = require("../utils/edge.cjs");
|
|
5
|
-
const params = {
|
|
6
|
-
sourceX: 0,
|
|
7
|
-
sourceY: 0,
|
|
8
|
-
targetX: 100,
|
|
9
|
-
targetY: 80,
|
|
10
|
-
sourcePosition: "right",
|
|
11
|
-
targetPosition: "left"
|
|
12
|
-
};
|
|
13
|
-
(0, _vitest.describe)("flow/utils/edge", () => {
|
|
14
|
-
(0, _vitest.it)("getStraightPath should return M and L", () => {
|
|
15
|
-
const d = (0, _edge.getStraightPath)(params);
|
|
16
|
-
(0, _vitest.expect)(d).toMatch(/^M\d+,\d+\s+L\d+,\d+$/);
|
|
17
|
-
(0, _vitest.expect)(d).toContain("M0,0");
|
|
18
|
-
(0, _vitest.expect)(d).toContain("L100,80");
|
|
19
|
-
});
|
|
20
|
-
(0, _vitest.it)("getBezierPath should return M and C", () => {
|
|
21
|
-
const d = (0, _edge.getBezierPath)(params);
|
|
22
|
-
(0, _vitest.expect)(d).toMatch(/^M\d+,\d+\s+C[\d.,\s]+$/);
|
|
23
|
-
(0, _vitest.expect)(d).toContain("M0,0");
|
|
24
|
-
(0, _vitest.expect)(d).toContain("C");
|
|
25
|
-
});
|
|
26
|
-
(0, _vitest.it)("getStepPath should return path with L segments", () => {
|
|
27
|
-
const d = (0, _edge.getStepPath)(params);
|
|
28
|
-
(0, _vitest.expect)(d).toMatch(/^M[\d.,]+(?:\s+L[\d.,]+)+$/);
|
|
29
|
-
});
|
|
30
|
-
(0, _vitest.it)("getSmoothStepPath should return path with M and L", () => {
|
|
31
|
-
const d = (0, _edge.getSmoothStepPath)(params);
|
|
32
|
-
(0, _vitest.expect)(d).toContain("M");
|
|
33
|
-
(0, _vitest.expect)(d).toContain("L");
|
|
34
|
-
});
|
|
35
|
-
(0, _vitest.it)("getEdgePath should dispatch by type", () => {
|
|
36
|
-
(0, _vitest.expect)((0, _edge.getEdgePath)("straight", params)).toContain("L");
|
|
37
|
-
(0, _vitest.expect)((0, _edge.getEdgePath)("bezier", params)).toContain("C");
|
|
38
|
-
(0, _vitest.expect)((0, _edge.getEdgePath)("step", params)).toContain("M");
|
|
39
|
-
(0, _vitest.expect)((0, _edge.getEdgePath)("smoothstep", params)).toContain("M");
|
|
40
|
-
(0, _vitest.expect)((0, _edge.getEdgePath)("default", params)).toContain("C");
|
|
41
|
-
});
|
|
42
|
-
(0, _vitest.it)("getEdgeCenter should return midpoint", () => {
|
|
43
|
-
const c = (0, _edge.getEdgeCenter)(params);
|
|
44
|
-
(0, _vitest.expect)(c.x).toBe(50);
|
|
45
|
-
(0, _vitest.expect)(c.y).toBe(40);
|
|
46
|
-
(0, _vitest.expect)(c.ox).toBe(50);
|
|
47
|
-
(0, _vitest.expect)(c.oy).toBe(40);
|
|
48
|
-
});
|
|
49
|
-
(0, _vitest.it)("getEdgePosition should return source/target with direction offset", () => {
|
|
50
|
-
const pos = (0, _edge.getEdgePosition)(params.sourceX, params.sourceY, params.targetX, params.targetY, params.sourcePosition, params.targetPosition);
|
|
51
|
-
(0, _vitest.expect)(pos).toHaveProperty("sx");
|
|
52
|
-
(0, _vitest.expect)(pos).toHaveProperty("sy");
|
|
53
|
-
(0, _vitest.expect)(pos).toHaveProperty("tx");
|
|
54
|
-
(0, _vitest.expect)(pos).toHaveProperty("ty");
|
|
55
|
-
});
|
|
56
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
getEdgePath,
|
|
4
|
-
getStraightPath,
|
|
5
|
-
getBezierPath,
|
|
6
|
-
getStepPath,
|
|
7
|
-
getSmoothStepPath,
|
|
8
|
-
getEdgeCenter,
|
|
9
|
-
getEdgePosition
|
|
10
|
-
} from "../utils/edge.mjs";
|
|
11
|
-
const params = {
|
|
12
|
-
sourceX: 0,
|
|
13
|
-
sourceY: 0,
|
|
14
|
-
targetX: 100,
|
|
15
|
-
targetY: 80,
|
|
16
|
-
sourcePosition: "right",
|
|
17
|
-
targetPosition: "left"
|
|
18
|
-
};
|
|
19
|
-
describe("flow/utils/edge", () => {
|
|
20
|
-
it("getStraightPath should return M and L", () => {
|
|
21
|
-
const d = getStraightPath(params);
|
|
22
|
-
expect(d).toMatch(/^M\d+,\d+\s+L\d+,\d+$/);
|
|
23
|
-
expect(d).toContain("M0,0");
|
|
24
|
-
expect(d).toContain("L100,80");
|
|
25
|
-
});
|
|
26
|
-
it("getBezierPath should return M and C", () => {
|
|
27
|
-
const d = getBezierPath(params);
|
|
28
|
-
expect(d).toMatch(/^M\d+,\d+\s+C[\d.,\s]+$/);
|
|
29
|
-
expect(d).toContain("M0,0");
|
|
30
|
-
expect(d).toContain("C");
|
|
31
|
-
});
|
|
32
|
-
it("getStepPath should return path with L segments", () => {
|
|
33
|
-
const d = getStepPath(params);
|
|
34
|
-
expect(d).toMatch(/^M[\d.,]+(?:\s+L[\d.,]+)+$/);
|
|
35
|
-
});
|
|
36
|
-
it("getSmoothStepPath should return path with M and L", () => {
|
|
37
|
-
const d = getSmoothStepPath(params);
|
|
38
|
-
expect(d).toContain("M");
|
|
39
|
-
expect(d).toContain("L");
|
|
40
|
-
});
|
|
41
|
-
it("getEdgePath should dispatch by type", () => {
|
|
42
|
-
expect(getEdgePath("straight", params)).toContain("L");
|
|
43
|
-
expect(getEdgePath("bezier", params)).toContain("C");
|
|
44
|
-
expect(getEdgePath("step", params)).toContain("M");
|
|
45
|
-
expect(getEdgePath("smoothstep", params)).toContain("M");
|
|
46
|
-
expect(getEdgePath("default", params)).toContain("C");
|
|
47
|
-
});
|
|
48
|
-
it("getEdgeCenter should return midpoint", () => {
|
|
49
|
-
const c = getEdgeCenter(params);
|
|
50
|
-
expect(c.x).toBe(50);
|
|
51
|
-
expect(c.y).toBe(40);
|
|
52
|
-
expect(c.ox).toBe(50);
|
|
53
|
-
expect(c.oy).toBe(40);
|
|
54
|
-
});
|
|
55
|
-
it("getEdgePosition should return source/target with direction offset", () => {
|
|
56
|
-
const pos = getEdgePosition(
|
|
57
|
-
params.sourceX,
|
|
58
|
-
params.sourceY,
|
|
59
|
-
params.targetX,
|
|
60
|
-
params.targetY,
|
|
61
|
-
params.sourcePosition,
|
|
62
|
-
params.targetPosition
|
|
63
|
-
);
|
|
64
|
-
expect(pos).toHaveProperty("sx");
|
|
65
|
-
expect(pos).toHaveProperty("sy");
|
|
66
|
-
expect(pos).toHaveProperty("tx");
|
|
67
|
-
expect(pos).toHaveProperty("ty");
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _vitest = require("vitest");
|
|
4
|
-
var _eventBus = require("../utils/event-bus.cjs");
|
|
5
|
-
(0, _vitest.describe)("flow/utils/event-bus", () => {
|
|
6
|
-
(0, _vitest.it)("should subscribe and emit", () => {
|
|
7
|
-
const bus = (0, _eventBus.createEventBus)();
|
|
8
|
-
const fn = _vitest.vi.fn();
|
|
9
|
-
bus.on("viewport:change", fn);
|
|
10
|
-
bus.emit("viewport:change", {
|
|
11
|
-
transform: {
|
|
12
|
-
x: 10,
|
|
13
|
-
y: 20,
|
|
14
|
-
zoom: 1
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
(0, _vitest.expect)(fn).toHaveBeenCalledTimes(1);
|
|
18
|
-
(0, _vitest.expect)(fn).toHaveBeenCalledWith({
|
|
19
|
-
transform: {
|
|
20
|
-
x: 10,
|
|
21
|
-
y: 20,
|
|
22
|
-
zoom: 1
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
(0, _vitest.it)("should off unsubscribe", () => {
|
|
27
|
-
const bus = (0, _eventBus.createEventBus)();
|
|
28
|
-
const fn = _vitest.vi.fn();
|
|
29
|
-
bus.on("viewport:change", fn);
|
|
30
|
-
bus.off("viewport:change", fn);
|
|
31
|
-
bus.emit("viewport:change", {
|
|
32
|
-
transform: {
|
|
33
|
-
x: 0,
|
|
34
|
-
y: 0,
|
|
35
|
-
zoom: 1
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
(0, _vitest.expect)(fn).not.toHaveBeenCalled();
|
|
39
|
-
});
|
|
40
|
-
(0, _vitest.it)("should once call handler only once", () => {
|
|
41
|
-
const bus = (0, _eventBus.createEventBus)();
|
|
42
|
-
const fn = _vitest.vi.fn();
|
|
43
|
-
bus.once("selection:change", fn);
|
|
44
|
-
bus.emit("selection:change", {
|
|
45
|
-
selectedNodes: [],
|
|
46
|
-
selectedEdges: []
|
|
47
|
-
});
|
|
48
|
-
(0, _vitest.expect)(fn).toHaveBeenCalledTimes(1);
|
|
49
|
-
});
|
|
50
|
-
(0, _vitest.it)("should emit void event without payload", () => {
|
|
51
|
-
const bus = (0, _eventBus.createEventBus)();
|
|
52
|
-
const fn = _vitest.vi.fn();
|
|
53
|
-
bus.on("connect:cancel", fn);
|
|
54
|
-
bus.emit("connect:cancel");
|
|
55
|
-
(0, _vitest.expect)(fn).toHaveBeenCalledTimes(1);
|
|
56
|
-
});
|
|
57
|
-
(0, _vitest.it)("listenerCount", () => {
|
|
58
|
-
const bus = (0, _eventBus.createEventBus)();
|
|
59
|
-
const f1 = _vitest.vi.fn();
|
|
60
|
-
const f2 = _vitest.vi.fn();
|
|
61
|
-
bus.on("node:click", f1);
|
|
62
|
-
bus.on("node:click", f2);
|
|
63
|
-
(0, _vitest.expect)(bus.listenerCount("node:click")).toBe(2);
|
|
64
|
-
(0, _vitest.expect)(bus.listenerCount()).toBe(2);
|
|
65
|
-
});
|
|
66
|
-
(0, _vitest.it)("clear should remove all handlers", () => {
|
|
67
|
-
const bus = (0, _eventBus.createEventBus)();
|
|
68
|
-
const fn = _vitest.vi.fn();
|
|
69
|
-
bus.on("viewport:change", fn);
|
|
70
|
-
bus.clear();
|
|
71
|
-
bus.emit("viewport:change", {
|
|
72
|
-
transform: {
|
|
73
|
-
x: 0,
|
|
74
|
-
y: 0,
|
|
75
|
-
zoom: 1
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
(0, _vitest.expect)(fn).not.toHaveBeenCalled();
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { createEventBus } from "../utils/event-bus.mjs";
|
|
3
|
-
describe("flow/utils/event-bus", () => {
|
|
4
|
-
it("should subscribe and emit", () => {
|
|
5
|
-
const bus = createEventBus();
|
|
6
|
-
const fn = vi.fn();
|
|
7
|
-
bus.on("viewport:change", fn);
|
|
8
|
-
bus.emit("viewport:change", { transform: { x: 10, y: 20, zoom: 1 } });
|
|
9
|
-
expect(fn).toHaveBeenCalledTimes(1);
|
|
10
|
-
expect(fn).toHaveBeenCalledWith({ transform: { x: 10, y: 20, zoom: 1 } });
|
|
11
|
-
});
|
|
12
|
-
it("should off unsubscribe", () => {
|
|
13
|
-
const bus = createEventBus();
|
|
14
|
-
const fn = vi.fn();
|
|
15
|
-
bus.on("viewport:change", fn);
|
|
16
|
-
bus.off("viewport:change", fn);
|
|
17
|
-
bus.emit("viewport:change", { transform: { x: 0, y: 0, zoom: 1 } });
|
|
18
|
-
expect(fn).not.toHaveBeenCalled();
|
|
19
|
-
});
|
|
20
|
-
it("should once call handler only once", () => {
|
|
21
|
-
const bus = createEventBus();
|
|
22
|
-
const fn = vi.fn();
|
|
23
|
-
bus.once("selection:change", fn);
|
|
24
|
-
bus.emit("selection:change", { selectedNodes: [], selectedEdges: [] });
|
|
25
|
-
expect(fn).toHaveBeenCalledTimes(1);
|
|
26
|
-
});
|
|
27
|
-
it("should emit void event without payload", () => {
|
|
28
|
-
const bus = createEventBus();
|
|
29
|
-
const fn = vi.fn();
|
|
30
|
-
bus.on("connect:cancel", fn);
|
|
31
|
-
bus.emit("connect:cancel");
|
|
32
|
-
expect(fn).toHaveBeenCalledTimes(1);
|
|
33
|
-
});
|
|
34
|
-
it("listenerCount", () => {
|
|
35
|
-
const bus = createEventBus();
|
|
36
|
-
const f1 = vi.fn();
|
|
37
|
-
const f2 = vi.fn();
|
|
38
|
-
bus.on("node:click", f1);
|
|
39
|
-
bus.on("node:click", f2);
|
|
40
|
-
expect(bus.listenerCount("node:click")).toBe(2);
|
|
41
|
-
expect(bus.listenerCount()).toBe(2);
|
|
42
|
-
});
|
|
43
|
-
it("clear should remove all handlers", () => {
|
|
44
|
-
const bus = createEventBus();
|
|
45
|
-
const fn = vi.fn();
|
|
46
|
-
bus.on("viewport:change", fn);
|
|
47
|
-
bus.clear();
|
|
48
|
-
bus.emit("viewport:change", { transform: { x: 0, y: 0, zoom: 1 } });
|
|
49
|
-
expect(fn).not.toHaveBeenCalled();
|
|
50
|
-
});
|
|
51
|
-
});
|