@yh-ui/flow 1.0.25 → 1.0.30

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.
Files changed (143) hide show
  1. package/package.json +13 -11
  2. package/LICENSE +0 -21
  3. package/dist/__tests__/ai-workflow.ssr.test.cjs +0 -352
  4. package/dist/__tests__/ai-workflow.ssr.test.d.ts +0 -1
  5. package/dist/__tests__/ai-workflow.ssr.test.mjs +0 -283
  6. package/dist/__tests__/ai-workflow.test.cjs +0 -109
  7. package/dist/__tests__/ai-workflow.test.d.ts +0 -1
  8. package/dist/__tests__/ai-workflow.test.mjs +0 -112
  9. package/dist/__tests__/bpmn-engine.test.cjs +0 -357
  10. package/dist/__tests__/bpmn-engine.test.d.ts +0 -1
  11. package/dist/__tests__/bpmn-engine.test.mjs +0 -406
  12. package/dist/__tests__/bpmn-utils.test.cjs +0 -268
  13. package/dist/__tests__/bpmn-utils.test.d.ts +0 -1
  14. package/dist/__tests__/bpmn-utils.test.mjs +0 -227
  15. package/dist/__tests__/bpmn-xml.test.cjs +0 -150
  16. package/dist/__tests__/bpmn-xml.test.d.ts +0 -1
  17. package/dist/__tests__/bpmn-xml.test.mjs +0 -112
  18. package/dist/__tests__/bpmn.ssr.test.cjs +0 -278
  19. package/dist/__tests__/bpmn.ssr.test.d.ts +0 -1
  20. package/dist/__tests__/bpmn.ssr.test.mjs +0 -237
  21. package/dist/__tests__/bpmn.test.cjs +0 -103
  22. package/dist/__tests__/bpmn.test.d.ts +0 -1
  23. package/dist/__tests__/bpmn.test.mjs +0 -106
  24. package/dist/__tests__/collaboration.test.cjs +0 -487
  25. package/dist/__tests__/collaboration.test.d.ts +0 -1
  26. package/dist/__tests__/collaboration.test.mjs +0 -424
  27. package/dist/__tests__/custom-types.test.cjs +0 -300
  28. package/dist/__tests__/custom-types.test.d.ts +0 -1
  29. package/dist/__tests__/custom-types.test.mjs +0 -248
  30. package/dist/__tests__/edge-types.test.cjs +0 -275
  31. package/dist/__tests__/edge-types.test.d.ts +0 -1
  32. package/dist/__tests__/edge-types.test.mjs +0 -234
  33. package/dist/__tests__/edge-utils.test.cjs +0 -375
  34. package/dist/__tests__/edge-utils.test.d.ts +0 -1
  35. package/dist/__tests__/edge-utils.test.mjs +0 -376
  36. package/dist/__tests__/edge.test.cjs +0 -56
  37. package/dist/__tests__/edge.test.d.ts +0 -1
  38. package/dist/__tests__/edge.test.mjs +0 -69
  39. package/dist/__tests__/event-bus.test.cjs +0 -80
  40. package/dist/__tests__/event-bus.test.d.ts +0 -1
  41. package/dist/__tests__/event-bus.test.mjs +0 -51
  42. package/dist/__tests__/events-types.test.cjs +0 -184
  43. package/dist/__tests__/events-types.test.d.ts +0 -1
  44. package/dist/__tests__/events-types.test.mjs +0 -184
  45. package/dist/__tests__/export-image-plugin.test.cjs +0 -142
  46. package/dist/__tests__/export-image-plugin.test.d.ts +0 -1
  47. package/dist/__tests__/export-image-plugin.test.mjs +0 -118
  48. package/dist/__tests__/export.test.cjs +0 -237
  49. package/dist/__tests__/export.test.d.ts +0 -1
  50. package/dist/__tests__/export.test.mjs +0 -171
  51. package/dist/__tests__/flow-context.test.cjs +0 -16
  52. package/dist/__tests__/flow-context.test.d.ts +0 -1
  53. package/dist/__tests__/flow-context.test.mjs +0 -16
  54. package/dist/__tests__/flow-props.test.cjs +0 -94
  55. package/dist/__tests__/flow-props.test.d.ts +0 -1
  56. package/dist/__tests__/flow-props.test.mjs +0 -92
  57. package/dist/__tests__/flow.ssr.test.cjs +0 -156
  58. package/dist/__tests__/flow.ssr.test.d.ts +0 -1
  59. package/dist/__tests__/flow.ssr.test.mjs +0 -112
  60. package/dist/__tests__/geometry.test.cjs +0 -191
  61. package/dist/__tests__/geometry.test.d.ts +0 -1
  62. package/dist/__tests__/geometry.test.mjs +0 -105
  63. package/dist/__tests__/graph.test.cjs +0 -115
  64. package/dist/__tests__/graph.test.d.ts +0 -1
  65. package/dist/__tests__/graph.test.mjs +0 -85
  66. package/dist/__tests__/history-plugin.test.cjs +0 -191
  67. package/dist/__tests__/history-plugin.test.d.ts +0 -1
  68. package/dist/__tests__/history-plugin.test.mjs +0 -161
  69. package/dist/__tests__/history.test.cjs +0 -81
  70. package/dist/__tests__/history.test.d.ts +0 -1
  71. package/dist/__tests__/history.test.mjs +0 -43
  72. package/dist/__tests__/layout-plugin.test.cjs +0 -233
  73. package/dist/__tests__/layout-plugin.test.d.ts +0 -1
  74. package/dist/__tests__/layout-plugin.test.mjs +0 -215
  75. package/dist/__tests__/layout.test.cjs +0 -213
  76. package/dist/__tests__/layout.test.d.ts +0 -1
  77. package/dist/__tests__/layout.test.mjs +0 -170
  78. package/dist/__tests__/node-edit-panel.ssr.test.cjs +0 -168
  79. package/dist/__tests__/node-edit-panel.ssr.test.d.ts +0 -1
  80. package/dist/__tests__/node-edit-panel.ssr.test.mjs +0 -118
  81. package/dist/__tests__/node-group-plugin.test.cjs +0 -235
  82. package/dist/__tests__/node-group-plugin.test.d.ts +0 -1
  83. package/dist/__tests__/node-group-plugin.test.mjs +0 -187
  84. package/dist/__tests__/node-handles.test.cjs +0 -340
  85. package/dist/__tests__/node-handles.test.d.ts +0 -1
  86. package/dist/__tests__/node-handles.test.mjs +0 -230
  87. package/dist/__tests__/node-types.test.cjs +0 -368
  88. package/dist/__tests__/node-types.test.d.ts +0 -1
  89. package/dist/__tests__/node-types.test.mjs +0 -292
  90. package/dist/__tests__/performance.test.cjs +0 -313
  91. package/dist/__tests__/performance.test.d.ts +0 -1
  92. package/dist/__tests__/performance.test.mjs +0 -218
  93. package/dist/__tests__/plugin-advanced.test.cjs +0 -301
  94. package/dist/__tests__/plugin-advanced.test.d.ts +0 -1
  95. package/dist/__tests__/plugin-advanced.test.mjs +0 -225
  96. package/dist/__tests__/plugin.test.cjs +0 -151
  97. package/dist/__tests__/plugin.test.d.ts +0 -1
  98. package/dist/__tests__/plugin.test.mjs +0 -116
  99. package/dist/__tests__/plugins.test.cjs +0 -412
  100. package/dist/__tests__/plugins.test.d.ts +0 -1
  101. package/dist/__tests__/plugins.test.mjs +0 -402
  102. package/dist/__tests__/screenshot-capture.test.cjs +0 -183
  103. package/dist/__tests__/screenshot-capture.test.d.ts +0 -1
  104. package/dist/__tests__/screenshot-capture.test.mjs +0 -124
  105. package/dist/__tests__/screenshot.test.cjs +0 -74
  106. package/dist/__tests__/screenshot.test.d.ts +0 -1
  107. package/dist/__tests__/screenshot.test.mjs +0 -69
  108. package/dist/__tests__/theme.test.cjs +0 -185
  109. package/dist/__tests__/theme.test.d.ts +0 -1
  110. package/dist/__tests__/theme.test.mjs +0 -191
  111. package/dist/__tests__/transform.test.cjs +0 -384
  112. package/dist/__tests__/transform.test.d.ts +0 -1
  113. package/dist/__tests__/transform.test.mjs +0 -239
  114. package/dist/__tests__/useAlignment.test.cjs +0 -128
  115. package/dist/__tests__/useAlignment.test.d.ts +0 -1
  116. package/dist/__tests__/useAlignment.test.mjs +0 -72
  117. package/dist/__tests__/useEdges.test.cjs +0 -117
  118. package/dist/__tests__/useEdges.test.d.ts +0 -1
  119. package/dist/__tests__/useEdges.test.mjs +0 -80
  120. package/dist/__tests__/useKeyboard.test.cjs +0 -88
  121. package/dist/__tests__/useKeyboard.test.d.ts +0 -1
  122. package/dist/__tests__/useKeyboard.test.mjs +0 -56
  123. package/dist/__tests__/useNodeDistribution.test.cjs +0 -643
  124. package/dist/__tests__/useNodeDistribution.test.d.ts +0 -1
  125. package/dist/__tests__/useNodeDistribution.test.mjs +0 -297
  126. package/dist/__tests__/useNodes.test.cjs +0 -150
  127. package/dist/__tests__/useNodes.test.d.ts +0 -1
  128. package/dist/__tests__/useNodes.test.mjs +0 -80
  129. package/dist/__tests__/useSelection.test.cjs +0 -112
  130. package/dist/__tests__/useSelection.test.d.ts +0 -1
  131. package/dist/__tests__/useSelection.test.mjs +0 -76
  132. package/dist/__tests__/useViewport.test.cjs +0 -171
  133. package/dist/__tests__/useViewport.test.d.ts +0 -1
  134. package/dist/__tests__/useViewport.test.mjs +0 -82
  135. package/dist/__tests__/utils/ssr.cjs +0 -124
  136. package/dist/__tests__/utils/ssr.d.ts +0 -33
  137. package/dist/__tests__/utils/ssr.mjs +0 -129
  138. package/dist/__tests__/validation.test.cjs +0 -95
  139. package/dist/__tests__/validation.test.d.ts +0 -1
  140. package/dist/__tests__/validation.test.mjs +0 -36
  141. package/dist/__tests__/viewport-types.test.cjs +0 -324
  142. package/dist/__tests__/viewport-types.test.d.ts +0 -1
  143. package/dist/__tests__/viewport-types.test.mjs +0 -207
@@ -1,297 +0,0 @@
1
- import { describe, it, expect, vi } from "vitest";
2
- import { ref } from "vue";
3
- import { useNodeDistribution } from "../core/useNodeDistribution.mjs";
4
- function createMockFlowInstance() {
5
- const nodes = ref([]);
6
- const edges = ref([]);
7
- const viewport = ref({ x: 0, y: 0, zoom: 1 });
8
- const draggingNodeId = ref(null);
9
- return {
10
- nodes,
11
- edges,
12
- viewport,
13
- draggingNodeId,
14
- addNode: vi.fn(),
15
- removeNode: vi.fn(),
16
- updateNode: vi.fn(),
17
- getNode: vi.fn(),
18
- addEdge: vi.fn(),
19
- removeEdge: vi.fn(),
20
- updateEdge: vi.fn(),
21
- getEdge: vi.fn(),
22
- setViewport: vi.fn(),
23
- fitView: vi.fn(),
24
- zoomIn: vi.fn(),
25
- zoomOut: vi.fn(),
26
- centerView: vi.fn(),
27
- selectNode: vi.fn(),
28
- selectEdge: vi.fn(),
29
- clearSelection: vi.fn(),
30
- getNodes: vi.fn(() => nodes.value),
31
- getEdges: vi.fn(() => edges.value),
32
- getViewport: vi.fn(() => viewport.value),
33
- screenToCanvas: vi.fn(),
34
- canvasToScreen: vi.fn(),
35
- on: vi.fn(),
36
- off: vi.fn(),
37
- emit: vi.fn(),
38
- isValidConnection: vi.fn(() => true),
39
- $el: void 0,
40
- usePlugin: vi.fn(),
41
- removePlugin: vi.fn()
42
- };
43
- }
44
- describe("flow/core/useNodeDistribution", () => {
45
- it("should return all distribution functions", () => {
46
- const flow = createMockFlowInstance();
47
- const {
48
- distributeHorizontally,
49
- distributeVertically,
50
- alignNodesHorizontal,
51
- alignNodesVertical
52
- } = useNodeDistribution({ nodes: flow.nodes });
53
- expect(typeof distributeHorizontally).toBe("function");
54
- expect(typeof distributeVertically).toBe("function");
55
- expect(typeof alignNodesHorizontal).toBe("function");
56
- expect(typeof alignNodesVertical).toBe("function");
57
- });
58
- describe("distributeHorizontally", () => {
59
- it("should not distribute when fewer than 3 nodes", () => {
60
- const flow = createMockFlowInstance();
61
- flow.nodes.value = [
62
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: {} },
63
- { id: "2", type: "default", position: { x: 100, y: 0 }, data: {} }
64
- ];
65
- const { distributeHorizontally } = useNodeDistribution({ nodes: flow.nodes });
66
- distributeHorizontally(["1", "2"]);
67
- expect(flow.nodes.value[0].position.x).toBe(0);
68
- expect(flow.nodes.value[1].position.x).toBe(100);
69
- });
70
- it("should distribute 3 nodes horizontally with custom gap", () => {
71
- const flow = createMockFlowInstance();
72
- flow.nodes.value = [
73
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 50, height: 50 },
74
- { id: "2", type: "default", position: { x: 50, y: 0 }, data: {}, width: 50, height: 50 },
75
- { id: "3", type: "default", position: { x: 100, y: 0 }, data: {}, width: 50, height: 50 }
76
- ];
77
- const { distributeHorizontally } = useNodeDistribution({ nodes: flow.nodes });
78
- distributeHorizontally(["1", "2", "3"], 100);
79
- const positions = flow.nodes.value.map((n) => n.position.x);
80
- expect(positions[0]).toBe(0);
81
- expect(positions[1]).toBe(150);
82
- expect(positions[2]).toBe(300);
83
- });
84
- it("should distribute nodes that are too close", () => {
85
- const flow = createMockFlowInstance();
86
- flow.nodes.value = [
87
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 50, height: 50 },
88
- { id: "2", type: "default", position: { x: 10, y: 0 }, data: {}, width: 50, height: 50 },
89
- { id: "3", type: "default", position: { x: 20, y: 0 }, data: {}, width: 50, height: 50 }
90
- ];
91
- const { distributeHorizontally } = useNodeDistribution({ nodes: flow.nodes });
92
- distributeHorizontally(["1", "2", "3"], 50);
93
- const positions = flow.nodes.value.map((n) => n.position.x);
94
- expect(positions[0]).toBe(0);
95
- expect(positions[1]).toBeGreaterThan(positions[0]);
96
- expect(positions[2]).toBeGreaterThan(positions[1]);
97
- });
98
- it("should use selected nodes when no nodeIds provided", () => {
99
- const flow = createMockFlowInstance();
100
- flow.nodes.value = [
101
- {
102
- id: "1",
103
- type: "default",
104
- position: { x: 0, y: 0 },
105
- data: {},
106
- width: 50,
107
- height: 50,
108
- selected: true
109
- },
110
- {
111
- id: "2",
112
- type: "default",
113
- position: { x: 50, y: 0 },
114
- data: {},
115
- width: 50,
116
- height: 50,
117
- selected: true
118
- },
119
- {
120
- id: "3",
121
- type: "default",
122
- position: { x: 100, y: 0 },
123
- data: {},
124
- width: 50,
125
- height: 50,
126
- selected: true
127
- }
128
- ];
129
- const { distributeHorizontally } = useNodeDistribution({ nodes: flow.nodes });
130
- distributeHorizontally(void 0, 50);
131
- const positions = flow.nodes.value.map((n) => n.position.x);
132
- expect(positions[0]).toBe(0);
133
- expect(positions[1]).toBe(100);
134
- expect(positions[2]).toBe(200);
135
- });
136
- });
137
- describe("distributeVertically", () => {
138
- it("should not distribute when fewer than 3 nodes", () => {
139
- const flow = createMockFlowInstance();
140
- flow.nodes.value = [
141
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: {} },
142
- { id: "2", type: "default", position: { x: 0, y: 100 }, data: {} }
143
- ];
144
- const { distributeVertically } = useNodeDistribution({ nodes: flow.nodes });
145
- distributeVertically(["1", "2"]);
146
- expect(flow.nodes.value[0].position.y).toBe(0);
147
- expect(flow.nodes.value[1].position.y).toBe(100);
148
- });
149
- it("should distribute 3 nodes vertically", () => {
150
- const flow = createMockFlowInstance();
151
- flow.nodes.value = [
152
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 50, height: 50 },
153
- { id: "2", type: "default", position: { x: 0, y: 50 }, data: {}, width: 50, height: 50 },
154
- { id: "3", type: "default", position: { x: 0, y: 100 }, data: {}, width: 50, height: 50 }
155
- ];
156
- const { distributeVertically } = useNodeDistribution({ nodes: flow.nodes });
157
- distributeVertically(["1", "2", "3"], 100);
158
- const positions = flow.nodes.value.map((n) => n.position.y);
159
- expect(positions[0]).toBe(0);
160
- expect(positions[1]).toBe(150);
161
- expect(positions[2]).toBe(300);
162
- });
163
- it("should distribute nodes that are too close vertically", () => {
164
- const flow = createMockFlowInstance();
165
- flow.nodes.value = [
166
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 50, height: 50 },
167
- { id: "2", type: "default", position: { x: 0, y: 10 }, data: {}, width: 50, height: 50 },
168
- { id: "3", type: "default", position: { x: 0, y: 20 }, data: {}, width: 50, height: 50 }
169
- ];
170
- const { distributeVertically } = useNodeDistribution({ nodes: flow.nodes });
171
- distributeVertically(["1", "2", "3"], 50);
172
- const positions = flow.nodes.value.map((n) => n.position.y);
173
- expect(positions[0]).toBe(0);
174
- expect(positions[1]).toBeGreaterThan(positions[0]);
175
- expect(positions[2]).toBeGreaterThan(positions[1]);
176
- });
177
- });
178
- describe("alignNodesHorizontal", () => {
179
- it("should not align when fewer than 2 nodes", () => {
180
- const flow = createMockFlowInstance();
181
- flow.nodes.value = [
182
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 }
183
- ];
184
- const { alignNodesHorizontal } = useNodeDistribution({ nodes: flow.nodes });
185
- alignNodesHorizontal(["1"]);
186
- expect(flow.nodes.value[0].position.x).toBe(0);
187
- });
188
- it("should align to left edge", () => {
189
- const flow = createMockFlowInstance();
190
- flow.nodes.value = [
191
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 },
192
- { id: "2", type: "default", position: { x: 50, y: 50 }, data: {}, width: 100, height: 50 },
193
- { id: "3", type: "default", position: { x: 100, y: 100 }, data: {}, width: 100, height: 50 }
194
- ];
195
- const { alignNodesHorizontal } = useNodeDistribution({ nodes: flow.nodes });
196
- alignNodesHorizontal(["1", "2", "3"], "left");
197
- expect(flow.nodes.value[0].position.x).toBe(0);
198
- expect(flow.nodes.value[1].position.x).toBe(0);
199
- expect(flow.nodes.value[2].position.x).toBe(0);
200
- });
201
- it("should align to right edge", () => {
202
- const flow = createMockFlowInstance();
203
- flow.nodes.value = [
204
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 },
205
- { id: "2", type: "default", position: { x: 50, y: 50 }, data: {}, width: 100, height: 50 }
206
- ];
207
- const { alignNodesHorizontal } = useNodeDistribution({ nodes: flow.nodes });
208
- alignNodesHorizontal(["1", "2"], "right");
209
- expect(flow.nodes.value[0].position.x).toBe(50);
210
- expect(flow.nodes.value[1].position.x).toBe(50);
211
- });
212
- it("should align to center", () => {
213
- const flow = createMockFlowInstance();
214
- flow.nodes.value = [
215
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 },
216
- { id: "2", type: "default", position: { x: 50, y: 50 }, data: {}, width: 200, height: 50 }
217
- ];
218
- const { alignNodesHorizontal } = useNodeDistribution({ nodes: flow.nodes });
219
- alignNodesHorizontal(["1", "2"], "center");
220
- expect(flow.nodes.value[0].position.x).toBe(50);
221
- expect(flow.nodes.value[1].position.x).toBe(0);
222
- });
223
- it("should use selected nodes when no nodeIds provided", () => {
224
- const flow = createMockFlowInstance();
225
- flow.nodes.value = [
226
- {
227
- id: "1",
228
- type: "default",
229
- position: { x: 0, y: 0 },
230
- data: {},
231
- width: 100,
232
- height: 50,
233
- selected: true
234
- },
235
- {
236
- id: "2",
237
- type: "default",
238
- position: { x: 50, y: 0 },
239
- data: {},
240
- width: 100,
241
- height: 50,
242
- selected: true
243
- }
244
- ];
245
- const { alignNodesHorizontal } = useNodeDistribution({ nodes: flow.nodes });
246
- alignNodesHorizontal(void 0, "left");
247
- expect(flow.nodes.value[0].position.x).toBe(0);
248
- expect(flow.nodes.value[1].position.x).toBe(0);
249
- });
250
- });
251
- describe("alignNodesVertical", () => {
252
- it("should not align when fewer than 2 nodes", () => {
253
- const flow = createMockFlowInstance();
254
- flow.nodes.value = [
255
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 }
256
- ];
257
- const { alignNodesVertical } = useNodeDistribution({ nodes: flow.nodes });
258
- alignNodesVertical(["1"]);
259
- expect(flow.nodes.value[0].position.y).toBe(0);
260
- });
261
- it("should align to top edge", () => {
262
- const flow = createMockFlowInstance();
263
- flow.nodes.value = [
264
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 },
265
- { id: "2", type: "default", position: { x: 0, y: 50 }, data: {}, width: 100, height: 50 },
266
- { id: "3", type: "default", position: { x: 0, y: 100 }, data: {}, width: 100, height: 50 }
267
- ];
268
- const { alignNodesVertical } = useNodeDistribution({ nodes: flow.nodes });
269
- alignNodesVertical(["1", "2", "3"], "top");
270
- expect(flow.nodes.value[0].position.y).toBe(0);
271
- expect(flow.nodes.value[1].position.y).toBe(0);
272
- expect(flow.nodes.value[2].position.y).toBe(0);
273
- });
274
- it("should align to bottom edge", () => {
275
- const flow = createMockFlowInstance();
276
- flow.nodes.value = [
277
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 },
278
- { id: "2", type: "default", position: { x: 0, y: 50 }, data: {}, width: 100, height: 50 }
279
- ];
280
- const { alignNodesVertical } = useNodeDistribution({ nodes: flow.nodes });
281
- alignNodesVertical(["1", "2"], "bottom");
282
- expect(flow.nodes.value[0].position.y).toBe(50);
283
- expect(flow.nodes.value[1].position.y).toBe(50);
284
- });
285
- it("should align to middle", () => {
286
- const flow = createMockFlowInstance();
287
- flow.nodes.value = [
288
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: {}, width: 100, height: 50 },
289
- { id: "2", type: "default", position: { x: 0, y: 50 }, data: {}, width: 100, height: 100 }
290
- ];
291
- const { alignNodesVertical } = useNodeDistribution({ nodes: flow.nodes });
292
- alignNodesVertical(["1", "2"], "middle");
293
- expect(flow.nodes.value[0].position.y).toBe(37.5);
294
- expect(flow.nodes.value[1].position.y).toBe(12.5);
295
- });
296
- });
297
- });
@@ -1,150 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _vue = require("vue");
5
- var _useNodes = require("../core/useNodes.cjs");
6
- const defaultNode = (id, x = 0, y = 0) => ({
7
- id,
8
- type: "default",
9
- position: {
10
- x,
11
- y
12
- },
13
- data: {
14
- label: id
15
- },
16
- width: 160,
17
- height: 50
18
- });
19
- (0, _vitest.describe)("flow/core/useNodes", () => {
20
- (0, _vitest.it)("should add and remove node", () => {
21
- const nodes = (0, _vue.ref)([]);
22
- const viewport = (0, _vue.ref)({
23
- x: 0,
24
- y: 0,
25
- zoom: 1
26
- });
27
- const n = (0, _useNodes.useNodes)(viewport, {
28
- nodes
29
- });
30
- n.addNode(defaultNode("1"));
31
- (0, _vitest.expect)(nodes.value).toHaveLength(1);
32
- (0, _vitest.expect)(n.getNode("1")).toBeDefined();
33
- n.removeNode("1");
34
- (0, _vitest.expect)(nodes.value).toHaveLength(0);
35
- (0, _vitest.expect)(n.getNode("1")).toBeUndefined();
36
- });
37
- (0, _vitest.it)("should update node and position", () => {
38
- const nodes = (0, _vue.ref)([defaultNode("1", 10, 20)]);
39
- const viewport = (0, _vue.ref)({
40
- x: 0,
41
- y: 0,
42
- zoom: 1
43
- });
44
- const n = (0, _useNodes.useNodes)(viewport, {
45
- nodes
46
- });
47
- n.updateNode("1", {
48
- data: {
49
- label: "updated"
50
- }
51
- });
52
- (0, _vitest.expect)(nodes.value[0].data?.label).toBe("updated");
53
- n.updateNodePosition("1", {
54
- x: 100,
55
- y: 200
56
- });
57
- (0, _vitest.expect)(nodes.value[0].position).toEqual({
58
- x: 100,
59
- y: 200
60
- });
61
- });
62
- (0, _vitest.it)("should snap position to grid when snapToGrid true", () => {
63
- const nodes = (0, _vue.ref)([defaultNode("1", 0, 0)]);
64
- const viewport = (0, _vue.ref)({
65
- x: 0,
66
- y: 0,
67
- zoom: 1
68
- });
69
- const n = (0, _useNodes.useNodes)(viewport, {
70
- nodes,
71
- snapToGrid: true,
72
- snapGrid: [20, 20]
73
- });
74
- n.updateNodePosition("1", {
75
- x: 17,
76
- y: 23
77
- });
78
- (0, _vitest.expect)(nodes.value[0].position.x).toBe(20);
79
- (0, _vitest.expect)(nodes.value[0].position.y).toBe(20);
80
- });
81
- (0, _vitest.it)("should select single node (clear others when multi false)", () => {
82
- const nodes = (0, _vue.ref)([{
83
- ...defaultNode("1"),
84
- selected: true
85
- }, {
86
- ...defaultNode("2"),
87
- selected: false
88
- }]);
89
- const viewport = (0, _vue.ref)({
90
- x: 0,
91
- y: 0,
92
- zoom: 1
93
- });
94
- const n = (0, _useNodes.useNodes)(viewport, {
95
- nodes
96
- });
97
- n.selectNode("2", true, false);
98
- (0, _vitest.expect)(nodes.value.find(x => x.id === "1")?.selected).toBe(false);
99
- (0, _vitest.expect)(nodes.value.find(x => x.id === "2")?.selected).toBe(true);
100
- });
101
- (0, _vitest.it)("should multi-select when multi true", () => {
102
- const nodes = (0, _vue.ref)([{
103
- ...defaultNode("1"),
104
- selected: true
105
- }, {
106
- ...defaultNode("2"),
107
- selected: false
108
- }]);
109
- const viewport = (0, _vue.ref)({
110
- x: 0,
111
- y: 0,
112
- zoom: 1
113
- });
114
- const n = (0, _useNodes.useNodes)(viewport, {
115
- nodes
116
- });
117
- n.selectNode("2", true, true);
118
- (0, _vitest.expect)(nodes.value.find(x => x.id === "1")?.selected).toBe(true);
119
- (0, _vitest.expect)(nodes.value.find(x => x.id === "2")?.selected).toBe(true);
120
- });
121
- (0, _vitest.it)("should selectNodes and clearSelection", () => {
122
- const nodes = (0, _vue.ref)([defaultNode("1"), defaultNode("2"), defaultNode("3")]);
123
- const viewport = (0, _vue.ref)({
124
- x: 0,
125
- y: 0,
126
- zoom: 1
127
- });
128
- const n = (0, _useNodes.useNodes)(viewport, {
129
- nodes
130
- });
131
- n.selectNodes(["1", "3"], true);
132
- (0, _vitest.expect)(n.getSelectedNodes()).toHaveLength(2);
133
- n.clearSelection();
134
- (0, _vitest.expect)(n.getSelectedNodes()).toHaveLength(0);
135
- });
136
- (0, _vitest.it)("should setNodes and findNode", () => {
137
- const nodes = (0, _vue.ref)([]);
138
- const viewport = (0, _vue.ref)({
139
- x: 0,
140
- y: 0,
141
- zoom: 1
142
- });
143
- const n = (0, _useNodes.useNodes)(viewport, {
144
- nodes
145
- });
146
- n.setNodes([defaultNode("a"), defaultNode("b")]);
147
- (0, _vitest.expect)(nodes.value).toHaveLength(2);
148
- (0, _vitest.expect)(n.findNode("b")?.id).toBe("b");
149
- });
150
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,80 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { ref } from "vue";
3
- import { useNodes } from "../core/useNodes.mjs";
4
- const defaultNode = (id, x = 0, y = 0) => ({
5
- id,
6
- type: "default",
7
- position: { x, y },
8
- data: { label: id },
9
- width: 160,
10
- height: 50
11
- });
12
- describe("flow/core/useNodes", () => {
13
- it("should add and remove node", () => {
14
- const nodes = ref([]);
15
- const viewport = ref({ x: 0, y: 0, zoom: 1 });
16
- const n = useNodes(viewport, { nodes });
17
- n.addNode(defaultNode("1"));
18
- expect(nodes.value).toHaveLength(1);
19
- expect(n.getNode("1")).toBeDefined();
20
- n.removeNode("1");
21
- expect(nodes.value).toHaveLength(0);
22
- expect(n.getNode("1")).toBeUndefined();
23
- });
24
- it("should update node and position", () => {
25
- const nodes = ref([defaultNode("1", 10, 20)]);
26
- const viewport = ref({ x: 0, y: 0, zoom: 1 });
27
- const n = useNodes(viewport, { nodes });
28
- n.updateNode("1", { data: { label: "updated" } });
29
- expect(nodes.value[0].data?.label).toBe("updated");
30
- n.updateNodePosition("1", { x: 100, y: 200 });
31
- expect(nodes.value[0].position).toEqual({ x: 100, y: 200 });
32
- });
33
- it("should snap position to grid when snapToGrid true", () => {
34
- const nodes = ref([defaultNode("1", 0, 0)]);
35
- const viewport = ref({ x: 0, y: 0, zoom: 1 });
36
- const n = useNodes(viewport, { nodes, snapToGrid: true, snapGrid: [20, 20] });
37
- n.updateNodePosition("1", { x: 17, y: 23 });
38
- expect(nodes.value[0].position.x).toBe(20);
39
- expect(nodes.value[0].position.y).toBe(20);
40
- });
41
- it("should select single node (clear others when multi false)", () => {
42
- const nodes = ref([
43
- { ...defaultNode("1"), selected: true },
44
- { ...defaultNode("2"), selected: false }
45
- ]);
46
- const viewport = ref({ x: 0, y: 0, zoom: 1 });
47
- const n = useNodes(viewport, { nodes });
48
- n.selectNode("2", true, false);
49
- expect(nodes.value.find((x) => x.id === "1")?.selected).toBe(false);
50
- expect(nodes.value.find((x) => x.id === "2")?.selected).toBe(true);
51
- });
52
- it("should multi-select when multi true", () => {
53
- const nodes = ref([
54
- { ...defaultNode("1"), selected: true },
55
- { ...defaultNode("2"), selected: false }
56
- ]);
57
- const viewport = ref({ x: 0, y: 0, zoom: 1 });
58
- const n = useNodes(viewport, { nodes });
59
- n.selectNode("2", true, true);
60
- expect(nodes.value.find((x) => x.id === "1")?.selected).toBe(true);
61
- expect(nodes.value.find((x) => x.id === "2")?.selected).toBe(true);
62
- });
63
- it("should selectNodes and clearSelection", () => {
64
- const nodes = ref([defaultNode("1"), defaultNode("2"), defaultNode("3")]);
65
- const viewport = ref({ x: 0, y: 0, zoom: 1 });
66
- const n = useNodes(viewport, { nodes });
67
- n.selectNodes(["1", "3"], true);
68
- expect(n.getSelectedNodes()).toHaveLength(2);
69
- n.clearSelection();
70
- expect(n.getSelectedNodes()).toHaveLength(0);
71
- });
72
- it("should setNodes and findNode", () => {
73
- const nodes = ref([]);
74
- const viewport = ref({ x: 0, y: 0, zoom: 1 });
75
- const n = useNodes(viewport, { nodes });
76
- n.setNodes([defaultNode("a"), defaultNode("b")]);
77
- expect(nodes.value).toHaveLength(2);
78
- expect(n.findNode("b")?.id).toBe("b");
79
- });
80
- });
@@ -1,112 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _vue = require("vue");
5
- var _useSelection = require("../core/useSelection.cjs");
6
- const node = (id, x, y, w = 100, h = 50) => ({
7
- id,
8
- type: "default",
9
- position: {
10
- x,
11
- y
12
- },
13
- data: {},
14
- width: w,
15
- height: h,
16
- selected: false
17
- });
18
- const edge = (id, source, target) => ({
19
- id,
20
- source,
21
- target,
22
- type: "bezier",
23
- selected: false
24
- });
25
- (0, _vitest.describe)("flow/core/useSelection", () => {
26
- (0, _vitest.it)("should start and update selection rect", () => {
27
- const nodes = (0, _vue.ref)([node("1", 0, 0), node("2", 200, 100)]);
28
- const edges = (0, _vue.ref)([]);
29
- const s = (0, _useSelection.useSelection)({
30
- nodes,
31
- edges
32
- });
33
- s.startSelection(10, 20);
34
- (0, _vitest.expect)(s.isSelecting.value).toBe(true);
35
- (0, _vitest.expect)(s.selectionRect.value).toEqual({
36
- x: 10,
37
- y: 20,
38
- width: 0,
39
- height: 0
40
- });
41
- s.updateSelection(50, 60);
42
- (0, _vitest.expect)(s.selectionRect.value).toEqual({
43
- x: 10,
44
- y: 20,
45
- width: 40,
46
- height: 40
47
- });
48
- });
49
- (0, _vitest.it)("should select nodes inside rect on updateSelection", () => {
50
- const nodes = (0, _vue.ref)([node("1", 20, 20, 50, 50), node("2", 100, 100, 50, 50)]);
51
- const edges = (0, _vue.ref)([]);
52
- const s = (0, _useSelection.useSelection)({
53
- nodes,
54
- edges
55
- });
56
- s.startSelection(0, 0);
57
- s.updateSelection(80, 80);
58
- (0, _vitest.expect)(nodes.value.find(n => n.id === "1")?.selected).toBe(true);
59
- (0, _vitest.expect)(nodes.value.find(n => n.id === "2")?.selected).toBe(false);
60
- });
61
- (0, _vitest.it)("should end selection and clear rect", () => {
62
- const nodes = (0, _vue.ref)([node("1", 0, 0)]);
63
- const edges = (0, _vue.ref)([]);
64
- const s = (0, _useSelection.useSelection)({
65
- nodes,
66
- edges
67
- });
68
- s.startSelection(0, 0);
69
- s.updateSelection(10, 10);
70
- s.endSelection();
71
- (0, _vitest.expect)(s.isSelecting.value).toBe(false);
72
- (0, _vitest.expect)(s.selectionRect.value).toBeNull();
73
- });
74
- (0, _vitest.it)("should clearSelection clear nodes and edges selected", () => {
75
- const nodes = (0, _vue.ref)([{
76
- ...node("1", 0, 0),
77
- selected: true
78
- }]);
79
- const edges = (0, _vue.ref)([{
80
- ...edge("e1", "1", "2"),
81
- selected: true
82
- }]);
83
- const s = (0, _useSelection.useSelection)({
84
- nodes,
85
- edges
86
- });
87
- s.clearSelection();
88
- (0, _vitest.expect)(nodes.value[0].selected).toBeFalsy();
89
- (0, _vitest.expect)(edges.value[0].selected).toBeFalsy();
90
- });
91
- (0, _vitest.it)("should call onSelectionChange on endSelection", () => {
92
- const nodes = (0, _vue.ref)([node("1", 20, 20, 50, 50)]);
93
- const edges = (0, _vue.ref)([]);
94
- let captured = null;
95
- const s = (0, _useSelection.useSelection)({
96
- nodes,
97
- edges,
98
- onSelectionChange: (selectedNodes, selectedEdges) => {
99
- captured = {
100
- nodes: selectedNodes,
101
- edges: selectedEdges
102
- };
103
- }
104
- });
105
- s.startSelection(0, 0);
106
- s.updateSelection(80, 80);
107
- s.endSelection();
108
- (0, _vitest.expect)(captured).not.toBeNull();
109
- (0, _vitest.expect)(Array.isArray(captured.nodes)).toBe(true);
110
- (0, _vitest.expect)(Array.isArray(captured.edges)).toBe(true);
111
- });
112
- });
@@ -1 +0,0 @@
1
- export {};