@yh-ui/flow 1.0.26 → 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 (142) hide show
  1. package/package.json +4 -4
  2. package/dist/__tests__/ai-workflow.ssr.test.cjs +0 -352
  3. package/dist/__tests__/ai-workflow.ssr.test.d.ts +0 -1
  4. package/dist/__tests__/ai-workflow.ssr.test.mjs +0 -283
  5. package/dist/__tests__/ai-workflow.test.cjs +0 -109
  6. package/dist/__tests__/ai-workflow.test.d.ts +0 -1
  7. package/dist/__tests__/ai-workflow.test.mjs +0 -112
  8. package/dist/__tests__/bpmn-engine.test.cjs +0 -357
  9. package/dist/__tests__/bpmn-engine.test.d.ts +0 -1
  10. package/dist/__tests__/bpmn-engine.test.mjs +0 -406
  11. package/dist/__tests__/bpmn-utils.test.cjs +0 -268
  12. package/dist/__tests__/bpmn-utils.test.d.ts +0 -1
  13. package/dist/__tests__/bpmn-utils.test.mjs +0 -227
  14. package/dist/__tests__/bpmn-xml.test.cjs +0 -150
  15. package/dist/__tests__/bpmn-xml.test.d.ts +0 -1
  16. package/dist/__tests__/bpmn-xml.test.mjs +0 -112
  17. package/dist/__tests__/bpmn.ssr.test.cjs +0 -278
  18. package/dist/__tests__/bpmn.ssr.test.d.ts +0 -1
  19. package/dist/__tests__/bpmn.ssr.test.mjs +0 -237
  20. package/dist/__tests__/bpmn.test.cjs +0 -103
  21. package/dist/__tests__/bpmn.test.d.ts +0 -1
  22. package/dist/__tests__/bpmn.test.mjs +0 -106
  23. package/dist/__tests__/collaboration.test.cjs +0 -487
  24. package/dist/__tests__/collaboration.test.d.ts +0 -1
  25. package/dist/__tests__/collaboration.test.mjs +0 -424
  26. package/dist/__tests__/custom-types.test.cjs +0 -300
  27. package/dist/__tests__/custom-types.test.d.ts +0 -1
  28. package/dist/__tests__/custom-types.test.mjs +0 -248
  29. package/dist/__tests__/edge-types.test.cjs +0 -275
  30. package/dist/__tests__/edge-types.test.d.ts +0 -1
  31. package/dist/__tests__/edge-types.test.mjs +0 -234
  32. package/dist/__tests__/edge-utils.test.cjs +0 -375
  33. package/dist/__tests__/edge-utils.test.d.ts +0 -1
  34. package/dist/__tests__/edge-utils.test.mjs +0 -376
  35. package/dist/__tests__/edge.test.cjs +0 -56
  36. package/dist/__tests__/edge.test.d.ts +0 -1
  37. package/dist/__tests__/edge.test.mjs +0 -69
  38. package/dist/__tests__/event-bus.test.cjs +0 -80
  39. package/dist/__tests__/event-bus.test.d.ts +0 -1
  40. package/dist/__tests__/event-bus.test.mjs +0 -51
  41. package/dist/__tests__/events-types.test.cjs +0 -184
  42. package/dist/__tests__/events-types.test.d.ts +0 -1
  43. package/dist/__tests__/events-types.test.mjs +0 -184
  44. package/dist/__tests__/export-image-plugin.test.cjs +0 -142
  45. package/dist/__tests__/export-image-plugin.test.d.ts +0 -1
  46. package/dist/__tests__/export-image-plugin.test.mjs +0 -118
  47. package/dist/__tests__/export.test.cjs +0 -237
  48. package/dist/__tests__/export.test.d.ts +0 -1
  49. package/dist/__tests__/export.test.mjs +0 -171
  50. package/dist/__tests__/flow-context.test.cjs +0 -16
  51. package/dist/__tests__/flow-context.test.d.ts +0 -1
  52. package/dist/__tests__/flow-context.test.mjs +0 -16
  53. package/dist/__tests__/flow-props.test.cjs +0 -94
  54. package/dist/__tests__/flow-props.test.d.ts +0 -1
  55. package/dist/__tests__/flow-props.test.mjs +0 -92
  56. package/dist/__tests__/flow.ssr.test.cjs +0 -156
  57. package/dist/__tests__/flow.ssr.test.d.ts +0 -1
  58. package/dist/__tests__/flow.ssr.test.mjs +0 -112
  59. package/dist/__tests__/geometry.test.cjs +0 -191
  60. package/dist/__tests__/geometry.test.d.ts +0 -1
  61. package/dist/__tests__/geometry.test.mjs +0 -105
  62. package/dist/__tests__/graph.test.cjs +0 -115
  63. package/dist/__tests__/graph.test.d.ts +0 -1
  64. package/dist/__tests__/graph.test.mjs +0 -85
  65. package/dist/__tests__/history-plugin.test.cjs +0 -191
  66. package/dist/__tests__/history-plugin.test.d.ts +0 -1
  67. package/dist/__tests__/history-plugin.test.mjs +0 -161
  68. package/dist/__tests__/history.test.cjs +0 -81
  69. package/dist/__tests__/history.test.d.ts +0 -1
  70. package/dist/__tests__/history.test.mjs +0 -43
  71. package/dist/__tests__/layout-plugin.test.cjs +0 -233
  72. package/dist/__tests__/layout-plugin.test.d.ts +0 -1
  73. package/dist/__tests__/layout-plugin.test.mjs +0 -215
  74. package/dist/__tests__/layout.test.cjs +0 -213
  75. package/dist/__tests__/layout.test.d.ts +0 -1
  76. package/dist/__tests__/layout.test.mjs +0 -170
  77. package/dist/__tests__/node-edit-panel.ssr.test.cjs +0 -168
  78. package/dist/__tests__/node-edit-panel.ssr.test.d.ts +0 -1
  79. package/dist/__tests__/node-edit-panel.ssr.test.mjs +0 -118
  80. package/dist/__tests__/node-group-plugin.test.cjs +0 -235
  81. package/dist/__tests__/node-group-plugin.test.d.ts +0 -1
  82. package/dist/__tests__/node-group-plugin.test.mjs +0 -187
  83. package/dist/__tests__/node-handles.test.cjs +0 -340
  84. package/dist/__tests__/node-handles.test.d.ts +0 -1
  85. package/dist/__tests__/node-handles.test.mjs +0 -230
  86. package/dist/__tests__/node-types.test.cjs +0 -368
  87. package/dist/__tests__/node-types.test.d.ts +0 -1
  88. package/dist/__tests__/node-types.test.mjs +0 -292
  89. package/dist/__tests__/performance.test.cjs +0 -313
  90. package/dist/__tests__/performance.test.d.ts +0 -1
  91. package/dist/__tests__/performance.test.mjs +0 -218
  92. package/dist/__tests__/plugin-advanced.test.cjs +0 -301
  93. package/dist/__tests__/plugin-advanced.test.d.ts +0 -1
  94. package/dist/__tests__/plugin-advanced.test.mjs +0 -225
  95. package/dist/__tests__/plugin.test.cjs +0 -151
  96. package/dist/__tests__/plugin.test.d.ts +0 -1
  97. package/dist/__tests__/plugin.test.mjs +0 -116
  98. package/dist/__tests__/plugins.test.cjs +0 -412
  99. package/dist/__tests__/plugins.test.d.ts +0 -1
  100. package/dist/__tests__/plugins.test.mjs +0 -402
  101. package/dist/__tests__/screenshot-capture.test.cjs +0 -183
  102. package/dist/__tests__/screenshot-capture.test.d.ts +0 -1
  103. package/dist/__tests__/screenshot-capture.test.mjs +0 -124
  104. package/dist/__tests__/screenshot.test.cjs +0 -74
  105. package/dist/__tests__/screenshot.test.d.ts +0 -1
  106. package/dist/__tests__/screenshot.test.mjs +0 -69
  107. package/dist/__tests__/theme.test.cjs +0 -185
  108. package/dist/__tests__/theme.test.d.ts +0 -1
  109. package/dist/__tests__/theme.test.mjs +0 -191
  110. package/dist/__tests__/transform.test.cjs +0 -384
  111. package/dist/__tests__/transform.test.d.ts +0 -1
  112. package/dist/__tests__/transform.test.mjs +0 -239
  113. package/dist/__tests__/useAlignment.test.cjs +0 -128
  114. package/dist/__tests__/useAlignment.test.d.ts +0 -1
  115. package/dist/__tests__/useAlignment.test.mjs +0 -72
  116. package/dist/__tests__/useEdges.test.cjs +0 -117
  117. package/dist/__tests__/useEdges.test.d.ts +0 -1
  118. package/dist/__tests__/useEdges.test.mjs +0 -80
  119. package/dist/__tests__/useKeyboard.test.cjs +0 -88
  120. package/dist/__tests__/useKeyboard.test.d.ts +0 -1
  121. package/dist/__tests__/useKeyboard.test.mjs +0 -56
  122. package/dist/__tests__/useNodeDistribution.test.cjs +0 -643
  123. package/dist/__tests__/useNodeDistribution.test.d.ts +0 -1
  124. package/dist/__tests__/useNodeDistribution.test.mjs +0 -297
  125. package/dist/__tests__/useNodes.test.cjs +0 -150
  126. package/dist/__tests__/useNodes.test.d.ts +0 -1
  127. package/dist/__tests__/useNodes.test.mjs +0 -80
  128. package/dist/__tests__/useSelection.test.cjs +0 -112
  129. package/dist/__tests__/useSelection.test.d.ts +0 -1
  130. package/dist/__tests__/useSelection.test.mjs +0 -76
  131. package/dist/__tests__/useViewport.test.cjs +0 -171
  132. package/dist/__tests__/useViewport.test.d.ts +0 -1
  133. package/dist/__tests__/useViewport.test.mjs +0 -82
  134. package/dist/__tests__/utils/ssr.cjs +0 -124
  135. package/dist/__tests__/utils/ssr.d.ts +0 -33
  136. package/dist/__tests__/utils/ssr.mjs +0 -129
  137. package/dist/__tests__/validation.test.cjs +0 -95
  138. package/dist/__tests__/validation.test.d.ts +0 -1
  139. package/dist/__tests__/validation.test.mjs +0 -36
  140. package/dist/__tests__/viewport-types.test.cjs +0 -324
  141. package/dist/__tests__/viewport-types.test.d.ts +0 -1
  142. package/dist/__tests__/viewport-types.test.mjs +0 -207
@@ -1,128 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _vue = require("vue");
5
- var _useAlignment = require("../core/useAlignment.cjs");
6
- const node = (id, x, y, w = 200, h = 50) => ({
7
- id,
8
- type: "default",
9
- position: {
10
- x,
11
- y
12
- },
13
- data: {},
14
- width: w,
15
- height: h
16
- });
17
- (0, _vitest.describe)("flow/core/useAlignment", () => {
18
- (0, _vitest.it)("should return same position when no other nodes", () => {
19
- const nodes = (0, _vue.ref)([node("1", 100, 50)]);
20
- const a = (0, _useAlignment.useAlignment)({
21
- nodes,
22
- snapThreshold: 10
23
- });
24
- const result = a.getAlignmentSnap("1", {
25
- x: 100,
26
- y: 50
27
- });
28
- (0, _vitest.expect)(result.x).toBe(100);
29
- (0, _vitest.expect)(result.y).toBe(50);
30
- (0, _vitest.expect)(result.snappedX).toBe(false);
31
- (0, _vitest.expect)(result.snappedY).toBe(false);
32
- });
33
- (0, _vitest.it)("should snap Y when dragging node center aligns with other center", () => {
34
- const nodes = (0, _vue.ref)([node("1", 0, 0), node("2", 300, 100)]);
35
- const a = (0, _useAlignment.useAlignment)({
36
- nodes,
37
- snapThreshold: 10
38
- });
39
- const pos = {
40
- x: 300,
41
- y: 100
42
- };
43
- const result = a.getAlignmentSnap("1", pos);
44
- (0, _vitest.expect)(result.snappedY).toBe(true);
45
- (0, _vitest.expect)(result.y).toBe(100);
46
- });
47
- (0, _vitest.it)("should snap X when left edges align", () => {
48
- const nodes = (0, _vue.ref)([node("1", 0, 0), node("2", 100, 200)]);
49
- const a = (0, _useAlignment.useAlignment)({
50
- nodes,
51
- snapThreshold: 15
52
- });
53
- const pos = {
54
- x: 98,
55
- y: 200
56
- };
57
- const result = a.getAlignmentSnap("1", pos);
58
- (0, _vitest.expect)(result.snappedX).toBe(true);
59
- (0, _vitest.expect)(result.x).toBe(100);
60
- });
61
- (0, _vitest.it)("snapToAlignment should return only x,y", () => {
62
- const nodes = (0, _vue.ref)([node("1", 0, 0), node("2", 100, 100)]);
63
- const a = (0, _useAlignment.useAlignment)({
64
- nodes,
65
- snapThreshold: 20
66
- });
67
- const out = a.snapToAlignment("1", {
68
- x: 105,
69
- y: 105
70
- });
71
- (0, _vitest.expect)(out).toHaveProperty("x");
72
- (0, _vitest.expect)(out).toHaveProperty("y");
73
- (0, _vitest.expect)(Object.keys(out)).toHaveLength(2);
74
- });
75
- (0, _vitest.it)("should not snap when nodes are far apart vertically", () => {
76
- const nodes = (0, _vue.ref)([node("1", 0, 0), node("2", 0, 500)]);
77
- const a = (0, _useAlignment.useAlignment)({
78
- nodes,
79
- snapThreshold: 10
80
- });
81
- const pos = {
82
- x: 0,
83
- y: 100
84
- };
85
- const result = a.getAlignmentSnap("1", pos);
86
- (0, _vitest.expect)(result.snappedY).toBe(false);
87
- });
88
- (0, _vitest.it)("should not snap when nodes are far apart horizontally", () => {
89
- const nodes = (0, _vue.ref)([node("1", 0, 0), node("2", 500, 0)]);
90
- const a = (0, _useAlignment.useAlignment)({
91
- nodes,
92
- snapThreshold: 10
93
- });
94
- const pos = {
95
- x: 100,
96
- y: 0
97
- };
98
- const result = a.getAlignmentSnap("1", pos);
99
- (0, _vitest.expect)(result.snappedX).toBe(false);
100
- });
101
- (0, _vitest.it)("should use default snap threshold of 10", () => {
102
- const nodes = (0, _vue.ref)([node("1", 0, 0), node("2", 210, 0)]);
103
- const a = (0, _useAlignment.useAlignment)({
104
- nodes
105
- });
106
- const result = a.getAlignmentSnap("1", {
107
- x: 0,
108
- y: 0
109
- });
110
- (0, _vitest.expect)(result.snappedX).toBe(false);
111
- });
112
- (0, _vitest.it)("should return position when nodeId not found", () => {
113
- const nodes = (0, _vue.ref)([node("1", 0, 0)]);
114
- const a = (0, _useAlignment.useAlignment)({
115
- nodes
116
- });
117
- const result = a.getAlignmentSnap("missing", {
118
- x: 50,
119
- y: 50
120
- });
121
- (0, _vitest.expect)(result).toEqual({
122
- x: 50,
123
- y: 50,
124
- snappedX: false,
125
- snappedY: false
126
- });
127
- });
128
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,72 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { ref } from "vue";
3
- import { useAlignment } from "../core/useAlignment.mjs";
4
- const node = (id, x, y, w = 200, h = 50) => ({
5
- id,
6
- type: "default",
7
- position: { x, y },
8
- data: {},
9
- width: w,
10
- height: h
11
- });
12
- describe("flow/core/useAlignment", () => {
13
- it("should return same position when no other nodes", () => {
14
- const nodes = ref([node("1", 100, 50)]);
15
- const a = useAlignment({ nodes, snapThreshold: 10 });
16
- const result = a.getAlignmentSnap("1", { x: 100, y: 50 });
17
- expect(result.x).toBe(100);
18
- expect(result.y).toBe(50);
19
- expect(result.snappedX).toBe(false);
20
- expect(result.snappedY).toBe(false);
21
- });
22
- it("should snap Y when dragging node center aligns with other center", () => {
23
- const nodes = ref([node("1", 0, 0), node("2", 300, 100)]);
24
- const a = useAlignment({ nodes, snapThreshold: 10 });
25
- const pos = { x: 300, y: 100 };
26
- const result = a.getAlignmentSnap("1", pos);
27
- expect(result.snappedY).toBe(true);
28
- expect(result.y).toBe(100);
29
- });
30
- it("should snap X when left edges align", () => {
31
- const nodes = ref([node("1", 0, 0), node("2", 100, 200)]);
32
- const a = useAlignment({ nodes, snapThreshold: 15 });
33
- const pos = { x: 98, y: 200 };
34
- const result = a.getAlignmentSnap("1", pos);
35
- expect(result.snappedX).toBe(true);
36
- expect(result.x).toBe(100);
37
- });
38
- it("snapToAlignment should return only x,y", () => {
39
- const nodes = ref([node("1", 0, 0), node("2", 100, 100)]);
40
- const a = useAlignment({ nodes, snapThreshold: 20 });
41
- const out = a.snapToAlignment("1", { x: 105, y: 105 });
42
- expect(out).toHaveProperty("x");
43
- expect(out).toHaveProperty("y");
44
- expect(Object.keys(out)).toHaveLength(2);
45
- });
46
- it("should not snap when nodes are far apart vertically", () => {
47
- const nodes = ref([node("1", 0, 0), node("2", 0, 500)]);
48
- const a = useAlignment({ nodes, snapThreshold: 10 });
49
- const pos = { x: 0, y: 100 };
50
- const result = a.getAlignmentSnap("1", pos);
51
- expect(result.snappedY).toBe(false);
52
- });
53
- it("should not snap when nodes are far apart horizontally", () => {
54
- const nodes = ref([node("1", 0, 0), node("2", 500, 0)]);
55
- const a = useAlignment({ nodes, snapThreshold: 10 });
56
- const pos = { x: 100, y: 0 };
57
- const result = a.getAlignmentSnap("1", pos);
58
- expect(result.snappedX).toBe(false);
59
- });
60
- it("should use default snap threshold of 10", () => {
61
- const nodes = ref([node("1", 0, 0), node("2", 210, 0)]);
62
- const a = useAlignment({ nodes });
63
- const result = a.getAlignmentSnap("1", { x: 0, y: 0 });
64
- expect(result.snappedX).toBe(false);
65
- });
66
- it("should return position when nodeId not found", () => {
67
- const nodes = ref([node("1", 0, 0)]);
68
- const a = useAlignment({ nodes });
69
- const result = a.getAlignmentSnap("missing", { x: 50, y: 50 });
70
- expect(result).toEqual({ x: 50, y: 50, snappedX: false, snappedY: false });
71
- });
72
- });
@@ -1,117 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _vue = require("vue");
5
- var _useEdges = require("../core/useEdges.cjs");
6
- const node = id => ({
7
- id,
8
- type: "default",
9
- position: {
10
- x: 0,
11
- y: 0
12
- },
13
- data: {}
14
- });
15
- const edge = (id, source, target) => ({
16
- id,
17
- source,
18
- target,
19
- type: "bezier"
20
- });
21
- (0, _vitest.describe)("flow/core/useEdges", () => {
22
- (0, _vitest.it)("should add and remove edge", () => {
23
- const edges = (0, _vue.ref)([]);
24
- const nodes = (0, _vue.ref)([node("1"), node("2")]);
25
- const e = (0, _useEdges.useEdges)({
26
- edges,
27
- nodes
28
- });
29
- e.addEdge(edge("e1", "1", "2"));
30
- (0, _vitest.expect)(edges.value).toHaveLength(1);
31
- (0, _vitest.expect)(e.getEdge("e1")).toBeDefined();
32
- e.removeEdge("e1");
33
- (0, _vitest.expect)(edges.value).toHaveLength(0);
34
- });
35
- (0, _vitest.it)("should not add duplicate connection", () => {
36
- const edges = (0, _vue.ref)([edge("e1", "1", "2")]);
37
- const nodes = (0, _vue.ref)([node("1"), node("2")]);
38
- const e = (0, _useEdges.useEdges)({
39
- edges,
40
- nodes
41
- });
42
- e.addEdge(edge("e2", "1", "2"));
43
- (0, _vitest.expect)(edges.value).toHaveLength(1);
44
- });
45
- (0, _vitest.it)("should respect isValidConnection", () => {
46
- const edges = (0, _vue.ref)([]);
47
- const nodes = (0, _vue.ref)([node("1"), node("2"), node("3")]);
48
- const e = (0, _useEdges.useEdges)({
49
- edges,
50
- nodes,
51
- isValidConnection: c => c.target !== "2"
52
- });
53
- e.addEdge(edge("e1", "1", "2"));
54
- (0, _vitest.expect)(edges.value).toHaveLength(0);
55
- e.addEdge(edge("e2", "1", "3"));
56
- (0, _vitest.expect)(edges.value).toHaveLength(1);
57
- });
58
- (0, _vitest.it)("should update edge", () => {
59
- const edges = (0, _vue.ref)([edge("e1", "1", "2")]);
60
- const nodes = (0, _vue.ref)([node("1"), node("2")]);
61
- const e = (0, _useEdges.useEdges)({
62
- edges,
63
- nodes
64
- });
65
- e.updateEdge("e1", {
66
- label: "updated",
67
- type: "straight"
68
- });
69
- (0, _vitest.expect)(edges.value[0].label).toBe("updated");
70
- (0, _vitest.expect)(edges.value[0].type).toBe("straight");
71
- });
72
- (0, _vitest.it)("should select edge single and multi", () => {
73
- const edges = (0, _vue.ref)([{
74
- ...edge("e1", "1", "2"),
75
- selected: true
76
- }, {
77
- ...edge("e2", "2", "3"),
78
- selected: false
79
- }]);
80
- const nodes = (0, _vue.ref)([node("1"), node("2"), node("3")]);
81
- const e = (0, _useEdges.useEdges)({
82
- edges,
83
- nodes
84
- });
85
- e.selectEdge("e2", true, false);
86
- (0, _vitest.expect)(edges.value.find(x => x.id === "e1")?.selected).toBe(false);
87
- (0, _vitest.expect)(edges.value.find(x => x.id === "e2")?.selected).toBe(true);
88
- e.selectEdge("e1", true, true);
89
- (0, _vitest.expect)(edges.value.filter(x => x.selected)).toHaveLength(2);
90
- });
91
- (0, _vitest.it)("should getEdgesForNode and getConnectedEdges", () => {
92
- const edges = (0, _vue.ref)([edge("e1", "1", "2"), edge("e2", "2", "3"), edge("e3", "1", "3")]);
93
- const nodes = (0, _vue.ref)([node("1"), node("2"), node("3")]);
94
- const e = (0, _useEdges.useEdges)({
95
- edges,
96
- nodes
97
- });
98
- (0, _vitest.expect)(e.getEdgesForNode("1")).toHaveLength(2);
99
- (0, _vitest.expect)(e.getConnectedEdges("2")).toHaveLength(2);
100
- });
101
- (0, _vitest.it)("should clearSelection and setEdges", () => {
102
- const edges = (0, _vue.ref)([{
103
- ...edge("e1", "1", "2"),
104
- selected: true
105
- }]);
106
- const nodes = (0, _vue.ref)([node("1"), node("2")]);
107
- const e = (0, _useEdges.useEdges)({
108
- edges,
109
- nodes
110
- });
111
- e.clearSelection();
112
- (0, _vitest.expect)(edges.value[0].selected).toBeFalsy();
113
- e.setEdges([edge("e2", "1", "2")]);
114
- (0, _vitest.expect)(edges.value).toHaveLength(1);
115
- (0, _vitest.expect)(edges.value[0].id).toBe("e2");
116
- });
117
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,80 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { ref } from "vue";
3
- import { useEdges } from "../core/useEdges.mjs";
4
- const node = (id) => ({ id, type: "default", position: { x: 0, y: 0 }, data: {} });
5
- const edge = (id, source, target) => ({
6
- id,
7
- source,
8
- target,
9
- type: "bezier"
10
- });
11
- describe("flow/core/useEdges", () => {
12
- it("should add and remove edge", () => {
13
- const edges = ref([]);
14
- const nodes = ref([node("1"), node("2")]);
15
- const e = useEdges({ edges, nodes });
16
- e.addEdge(edge("e1", "1", "2"));
17
- expect(edges.value).toHaveLength(1);
18
- expect(e.getEdge("e1")).toBeDefined();
19
- e.removeEdge("e1");
20
- expect(edges.value).toHaveLength(0);
21
- });
22
- it("should not add duplicate connection", () => {
23
- const edges = ref([edge("e1", "1", "2")]);
24
- const nodes = ref([node("1"), node("2")]);
25
- const e = useEdges({ edges, nodes });
26
- e.addEdge(edge("e2", "1", "2"));
27
- expect(edges.value).toHaveLength(1);
28
- });
29
- it("should respect isValidConnection", () => {
30
- const edges = ref([]);
31
- const nodes = ref([node("1"), node("2"), node("3")]);
32
- const e = useEdges({
33
- edges,
34
- nodes,
35
- isValidConnection: (c) => c.target !== "2"
36
- });
37
- e.addEdge(edge("e1", "1", "2"));
38
- expect(edges.value).toHaveLength(0);
39
- e.addEdge(edge("e2", "1", "3"));
40
- expect(edges.value).toHaveLength(1);
41
- });
42
- it("should update edge", () => {
43
- const edges = ref([edge("e1", "1", "2")]);
44
- const nodes = ref([node("1"), node("2")]);
45
- const e = useEdges({ edges, nodes });
46
- e.updateEdge("e1", { label: "updated", type: "straight" });
47
- expect(edges.value[0].label).toBe("updated");
48
- expect(edges.value[0].type).toBe("straight");
49
- });
50
- it("should select edge single and multi", () => {
51
- const edges = ref([
52
- { ...edge("e1", "1", "2"), selected: true },
53
- { ...edge("e2", "2", "3"), selected: false }
54
- ]);
55
- const nodes = ref([node("1"), node("2"), node("3")]);
56
- const e = useEdges({ edges, nodes });
57
- e.selectEdge("e2", true, false);
58
- expect(edges.value.find((x) => x.id === "e1")?.selected).toBe(false);
59
- expect(edges.value.find((x) => x.id === "e2")?.selected).toBe(true);
60
- e.selectEdge("e1", true, true);
61
- expect(edges.value.filter((x) => x.selected)).toHaveLength(2);
62
- });
63
- it("should getEdgesForNode and getConnectedEdges", () => {
64
- const edges = ref([edge("e1", "1", "2"), edge("e2", "2", "3"), edge("e3", "1", "3")]);
65
- const nodes = ref([node("1"), node("2"), node("3")]);
66
- const e = useEdges({ edges, nodes });
67
- expect(e.getEdgesForNode("1")).toHaveLength(2);
68
- expect(e.getConnectedEdges("2")).toHaveLength(2);
69
- });
70
- it("should clearSelection and setEdges", () => {
71
- const edges = ref([{ ...edge("e1", "1", "2"), selected: true }]);
72
- const nodes = ref([node("1"), node("2")]);
73
- const e = useEdges({ edges, nodes });
74
- e.clearSelection();
75
- expect(edges.value[0].selected).toBeFalsy();
76
- e.setEdges([edge("e2", "1", "2")]);
77
- expect(edges.value).toHaveLength(1);
78
- expect(edges.value[0].id).toBe("e2");
79
- });
80
- });
@@ -1,88 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _useKeyboard = require("../core/useKeyboard.cjs");
5
- (0, _vitest.describe)("flow/core/useKeyboard", () => {
6
- const createKeyEvent = (key, opts = {}) => new KeyboardEvent("keydown", {
7
- key,
8
- ctrlKey: opts.ctrlKey ?? false,
9
- metaKey: opts.metaKey ?? false,
10
- shiftKey: opts.shiftKey ?? false
11
- });
12
- (0, _vitest.it)("should call onDelete on Delete key", () => {
13
- const onDelete = _vitest.vi.fn();
14
- const k = (0, _useKeyboard.useKeyboard)({
15
- onDelete
16
- });
17
- k.handleKeyDown(createKeyEvent("Delete"));
18
- (0, _vitest.expect)(onDelete).toHaveBeenCalledTimes(1);
19
- });
20
- (0, _vitest.it)("should call onUndo on Ctrl+Z", () => {
21
- const onUndo = _vitest.vi.fn();
22
- const k = (0, _useKeyboard.useKeyboard)({
23
- onUndo
24
- });
25
- k.handleKeyDown(createKeyEvent("z", {
26
- ctrlKey: true
27
- }));
28
- (0, _vitest.expect)(onUndo).toHaveBeenCalledTimes(1);
29
- });
30
- (0, _vitest.it)("should call onRedo on Ctrl+Shift+Z", () => {
31
- const onRedo = _vitest.vi.fn();
32
- const k = (0, _useKeyboard.useKeyboard)({
33
- onRedo
34
- });
35
- k.handleKeyDown(createKeyEvent("z", {
36
- ctrlKey: true,
37
- shiftKey: true
38
- }));
39
- (0, _vitest.expect)(onRedo).toHaveBeenCalledTimes(1);
40
- });
41
- (0, _vitest.it)("should call onSelectAll on Ctrl+A", () => {
42
- const onSelectAll = _vitest.vi.fn();
43
- const k = (0, _useKeyboard.useKeyboard)({
44
- onSelectAll
45
- });
46
- k.handleKeyDown(createKeyEvent("a", {
47
- ctrlKey: true
48
- }));
49
- (0, _vitest.expect)(onSelectAll).toHaveBeenCalledTimes(1);
50
- });
51
- (0, _vitest.it)("should call onEscape on Escape", () => {
52
- const onEscape = _vitest.vi.fn();
53
- const k = (0, _useKeyboard.useKeyboard)({
54
- onEscape
55
- });
56
- k.handleKeyDown(createKeyEvent("Escape"));
57
- (0, _vitest.expect)(onEscape).toHaveBeenCalledTimes(1);
58
- });
59
- (0, _vitest.it)("should not fire when enabled false", () => {
60
- const onDelete = _vitest.vi.fn();
61
- const k = (0, _useKeyboard.useKeyboard)({
62
- enabled: false,
63
- onDelete
64
- });
65
- k.handleKeyDown(createKeyEvent("Delete"));
66
- (0, _vitest.expect)(onDelete).not.toHaveBeenCalled();
67
- });
68
- (0, _vitest.it)("should call onCopy on Ctrl+C and onPaste on Ctrl+V", () => {
69
- const onCopy = _vitest.vi.fn();
70
- const onPaste = _vitest.vi.fn();
71
- const k = (0, _useKeyboard.useKeyboard)({
72
- onCopy,
73
- onPaste
74
- });
75
- k.handleKeyDown(createKeyEvent("c", {
76
- ctrlKey: true
77
- }));
78
- (0, _vitest.expect)(onCopy).toHaveBeenCalledTimes(1);
79
- k.handleKeyDown(createKeyEvent("v", {
80
- ctrlKey: true
81
- }));
82
- (0, _vitest.expect)(onPaste).toHaveBeenCalledTimes(1);
83
- (0, _vitest.expect)(onPaste).toHaveBeenCalledWith({
84
- nodes: [],
85
- edges: []
86
- });
87
- });
88
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,56 +0,0 @@
1
- import { describe, it, expect, vi } from "vitest";
2
- import { useKeyboard } from "../core/useKeyboard.mjs";
3
- describe("flow/core/useKeyboard", () => {
4
- const createKeyEvent = (key, opts = {}) => new KeyboardEvent("keydown", {
5
- key,
6
- ctrlKey: opts.ctrlKey ?? false,
7
- metaKey: opts.metaKey ?? false,
8
- shiftKey: opts.shiftKey ?? false
9
- });
10
- it("should call onDelete on Delete key", () => {
11
- const onDelete = vi.fn();
12
- const k = useKeyboard({ onDelete });
13
- k.handleKeyDown(createKeyEvent("Delete"));
14
- expect(onDelete).toHaveBeenCalledTimes(1);
15
- });
16
- it("should call onUndo on Ctrl+Z", () => {
17
- const onUndo = vi.fn();
18
- const k = useKeyboard({ onUndo });
19
- k.handleKeyDown(createKeyEvent("z", { ctrlKey: true }));
20
- expect(onUndo).toHaveBeenCalledTimes(1);
21
- });
22
- it("should call onRedo on Ctrl+Shift+Z", () => {
23
- const onRedo = vi.fn();
24
- const k = useKeyboard({ onRedo });
25
- k.handleKeyDown(createKeyEvent("z", { ctrlKey: true, shiftKey: true }));
26
- expect(onRedo).toHaveBeenCalledTimes(1);
27
- });
28
- it("should call onSelectAll on Ctrl+A", () => {
29
- const onSelectAll = vi.fn();
30
- const k = useKeyboard({ onSelectAll });
31
- k.handleKeyDown(createKeyEvent("a", { ctrlKey: true }));
32
- expect(onSelectAll).toHaveBeenCalledTimes(1);
33
- });
34
- it("should call onEscape on Escape", () => {
35
- const onEscape = vi.fn();
36
- const k = useKeyboard({ onEscape });
37
- k.handleKeyDown(createKeyEvent("Escape"));
38
- expect(onEscape).toHaveBeenCalledTimes(1);
39
- });
40
- it("should not fire when enabled false", () => {
41
- const onDelete = vi.fn();
42
- const k = useKeyboard({ enabled: false, onDelete });
43
- k.handleKeyDown(createKeyEvent("Delete"));
44
- expect(onDelete).not.toHaveBeenCalled();
45
- });
46
- it("should call onCopy on Ctrl+C and onPaste on Ctrl+V", () => {
47
- const onCopy = vi.fn();
48
- const onPaste = vi.fn();
49
- const k = useKeyboard({ onCopy, onPaste });
50
- k.handleKeyDown(createKeyEvent("c", { ctrlKey: true }));
51
- expect(onCopy).toHaveBeenCalledTimes(1);
52
- k.handleKeyDown(createKeyEvent("v", { ctrlKey: true }));
53
- expect(onPaste).toHaveBeenCalledTimes(1);
54
- expect(onPaste).toHaveBeenCalledWith({ nodes: [], edges: [] });
55
- });
56
- });