@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,85 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import {
3
- hasCycle,
4
- topologicalSort,
5
- findAllPaths,
6
- findConnectedComponents,
7
- bfs,
8
- dfs
9
- } from "../utils/graph.mjs";
10
- describe("flow/utils/graph", () => {
11
- it("hasCycle should detect cycle", () => {
12
- const edges = [
13
- { source: "A", target: "B" },
14
- { source: "B", target: "C" },
15
- { source: "C", target: "A" }
16
- ];
17
- expect(hasCycle(edges, "A")).toBe(true);
18
- });
19
- it("hasCycle should return false for DAG", () => {
20
- const edges = [
21
- { source: "A", target: "B" },
22
- { source: "B", target: "C" }
23
- ];
24
- expect(hasCycle(edges, "A")).toBe(false);
25
- });
26
- it("topologicalSort should return order for DAG", () => {
27
- const nodes = [{ id: "A" }, { id: "B" }, { id: "C" }];
28
- const edges = [
29
- { source: "A", target: "B" },
30
- { source: "B", target: "C" }
31
- ];
32
- const order = topologicalSort(nodes, edges);
33
- expect(order).toHaveLength(3);
34
- const ai = order.indexOf("A");
35
- const bi = order.indexOf("B");
36
- const ci = order.indexOf("C");
37
- expect(ai).toBeLessThan(bi);
38
- expect(bi).toBeLessThan(ci);
39
- });
40
- it("findAllPaths should return paths between two nodes", () => {
41
- const edges = [
42
- { source: "1", target: "2" },
43
- { source: "1", target: "3" },
44
- { source: "2", target: "4" },
45
- { source: "3", target: "4" }
46
- ];
47
- const paths = findAllPaths(edges, "1", "4");
48
- expect(paths.length).toBeGreaterThanOrEqual(1);
49
- expect(paths.every((p) => p[0] === "1" && p[p.length - 1] === "4")).toBe(true);
50
- });
51
- it("findConnectedComponents should return components", () => {
52
- const nodes = [{ id: "A" }, { id: "B" }, { id: "C" }, { id: "D" }];
53
- const edges = [
54
- { source: "A", target: "B" },
55
- { source: "C", target: "D" }
56
- ];
57
- const components = findConnectedComponents(nodes, edges);
58
- expect(components).toHaveLength(2);
59
- expect(components.some((c) => c.includes("A") && c.includes("B"))).toBe(true);
60
- expect(components.some((c) => c.includes("C") && c.includes("D"))).toBe(true);
61
- });
62
- it("bfs should traverse in breadth order", () => {
63
- const adj = /* @__PURE__ */ new Map();
64
- adj.set("1", ["2", "3"]);
65
- adj.set("2", ["4"]);
66
- adj.set("3", []);
67
- adj.set("4", []);
68
- const result = bfs(adj, "1");
69
- expect(result).toContain("1");
70
- expect(result).toContain("2");
71
- expect(result).toContain("3");
72
- expect(result).toContain("4");
73
- expect(result[0]).toBe("1");
74
- });
75
- it("dfs should traverse in depth order", () => {
76
- const adj = /* @__PURE__ */ new Map();
77
- adj.set("1", ["2", "3"]);
78
- adj.set("2", ["4"]);
79
- adj.set("3", []);
80
- adj.set("4", []);
81
- const result = dfs(adj, "1");
82
- expect(result).toHaveLength(4);
83
- expect(result[0]).toBe("1");
84
- });
85
- });
@@ -1,191 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _vue = require("vue");
5
- var _history = require("../plugins/plugins/history.cjs");
6
- function createMockFlow() {
7
- const nodes = (0, _vue.ref)([{
8
- id: "1",
9
- type: "default",
10
- position: {
11
- x: 0,
12
- y: 0
13
- },
14
- data: {
15
- label: "A"
16
- }
17
- }]);
18
- const edges = (0, _vue.ref)([]);
19
- const eventHandlers = {};
20
- const flow = {
21
- nodes,
22
- edges,
23
- viewport: (0, _vue.ref)({
24
- x: 0,
25
- y: 0,
26
- zoom: 1
27
- }),
28
- addNode: _vitest.vi.fn(),
29
- removeNode: _vitest.vi.fn(),
30
- updateNode: _vitest.vi.fn(),
31
- getNode: _vitest.vi.fn(),
32
- addEdge: _vitest.vi.fn(),
33
- removeEdge: _vitest.vi.fn(),
34
- updateEdge: _vitest.vi.fn(),
35
- getEdge: _vitest.vi.fn(),
36
- setViewport: _vitest.vi.fn(),
37
- fitView: _vitest.vi.fn(),
38
- zoomIn: _vitest.vi.fn(),
39
- zoomOut: _vitest.vi.fn(),
40
- centerView: _vitest.vi.fn(),
41
- selectNode: _vitest.vi.fn(),
42
- selectEdge: _vitest.vi.fn(),
43
- clearSelection: _vitest.vi.fn(),
44
- getNodes: () => nodes.value,
45
- getEdges: () => edges.value,
46
- getViewport: () => ({
47
- x: 0,
48
- y: 0,
49
- zoom: 1
50
- }),
51
- screenToCanvas: _vitest.vi.fn().mockReturnValue({
52
- x: 0,
53
- y: 0
54
- }),
55
- canvasToScreen: _vitest.vi.fn().mockReturnValue({
56
- x: 0,
57
- y: 0
58
- }),
59
- on: _vitest.vi.fn((event, handler) => {
60
- if (!eventHandlers[event]) eventHandlers[event] = [];
61
- eventHandlers[event].push(handler);
62
- }),
63
- off: _vitest.vi.fn(),
64
- emit: _vitest.vi.fn(),
65
- isValidConnection: _vitest.vi.fn().mockReturnValue(true),
66
- $el: void 0,
67
- draggingNodeId: (0, _vue.ref)(null),
68
- draggingPosition: (0, _vue.ref)(null),
69
- usePlugin: _vitest.vi.fn(),
70
- removePlugin: _vitest.vi.fn()
71
- };
72
- return flow;
73
- }
74
- (0, _vitest.describe)("createHistoryPlugin", () => {
75
- (0, _vitest.it)("should be created with correct metadata", () => {
76
- const plugin = (0, _history.createHistoryPlugin)();
77
- (0, _vitest.expect)(plugin.id).toBe("history");
78
- (0, _vitest.expect)(plugin.name).toBe("History");
79
- (0, _vitest.expect)(plugin.version).toBe("1.0.0");
80
- });
81
- (0, _vitest.it)("should install and expose undo/redo on flow instance", () => {
82
- const flow = createMockFlow();
83
- const plugin = (0, _history.createHistoryPlugin)();
84
- plugin.install(flow);
85
- (0, _vitest.expect)(typeof flow.undo).toBe("function");
86
- (0, _vitest.expect)(typeof flow.redo).toBe("function");
87
- (0, _vitest.expect)(typeof flow.saveSnapshot).toBe("function");
88
- (0, _vitest.expect)(typeof flow.clearHistory).toBe("function");
89
- (0, _vitest.expect)(typeof flow.jumpToStep).toBe("function");
90
- (0, _vitest.expect)(typeof flow.getHistory).toBe("function");
91
- });
92
- (0, _vitest.it)("should save initial snapshot on install", () => {
93
- const flow = createMockFlow();
94
- const plugin = (0, _history.createHistoryPlugin)();
95
- plugin.install(flow);
96
- const history = plugin.getHistory();
97
- (0, _vitest.expect)(history.length).toBe(1);
98
- (0, _vitest.expect)(history[0].description).toBe("initial");
99
- });
100
- (0, _vitest.it)("should correctly undo and redo node position changes", () => {
101
- const flow = createMockFlow();
102
- const plugin = (0, _history.createHistoryPlugin)();
103
- plugin.install(flow);
104
- flow.nodes.value[0].position.x = 100;
105
- plugin.saveSnapshot("move node");
106
- (0, _vitest.expect)(plugin.canUndo.value).toBe(true);
107
- (0, _vitest.expect)(plugin.canRedo.value).toBe(false);
108
- plugin.undo();
109
- (0, _vitest.expect)(flow.nodes.value[0].position.x).toBe(0);
110
- (0, _vitest.expect)(plugin.canRedo.value).toBe(true);
111
- plugin.redo();
112
- (0, _vitest.expect)(flow.nodes.value[0].position.x).toBe(100);
113
- });
114
- (0, _vitest.it)("should clear redo stack when new snapshot is pushed after undo", () => {
115
- const flow = createMockFlow();
116
- const plugin = (0, _history.createHistoryPlugin)();
117
- plugin.install(flow);
118
- flow.nodes.value[0].position.x = 50;
119
- plugin.saveSnapshot("step1");
120
- flow.nodes.value[0].position.x = 100;
121
- plugin.saveSnapshot("step2");
122
- plugin.undo();
123
- (0, _vitest.expect)(flow.nodes.value[0].position.x).toBe(50);
124
- (0, _vitest.expect)(plugin.canRedo.value).toBe(true);
125
- flow.nodes.value[0].position.x = 200;
126
- plugin.saveSnapshot("step3");
127
- (0, _vitest.expect)(plugin.canRedo.value).toBe(false);
128
- });
129
- (0, _vitest.it)("should respect maxHistory limit", () => {
130
- const flow = createMockFlow();
131
- const plugin = (0, _history.createHistoryPlugin)({
132
- maxHistory: 3
133
- });
134
- plugin.install(flow);
135
- for (let i = 1; i <= 5; i++) {
136
- flow.nodes.value[0].position.x = i * 10;
137
- plugin.saveSnapshot(`step${i}`);
138
- }
139
- (0, _vitest.expect)(plugin.getHistory().length).toBe(3);
140
- });
141
- (0, _vitest.it)("should clear history", () => {
142
- const flow = createMockFlow();
143
- const plugin = (0, _history.createHistoryPlugin)();
144
- plugin.install(flow);
145
- flow.nodes.value[0].position.x = 100;
146
- plugin.saveSnapshot("move");
147
- plugin.clearHistory();
148
- (0, _vitest.expect)(plugin.getHistory().length).toBe(0);
149
- (0, _vitest.expect)(plugin.canUndo.value).toBe(false);
150
- (0, _vitest.expect)(plugin.canRedo.value).toBe(false);
151
- });
152
- (0, _vitest.it)("should call onHistoryChange callback", () => {
153
- const onHistoryChange = _vitest.vi.fn();
154
- const flow = createMockFlow();
155
- const plugin = (0, _history.createHistoryPlugin)({
156
- onHistoryChange
157
- });
158
- plugin.install(flow);
159
- (0, _vitest.expect)(onHistoryChange).toHaveBeenCalled();
160
- });
161
- (0, _vitest.it)("should jump to a specific step", () => {
162
- const flow = createMockFlow();
163
- const plugin = (0, _history.createHistoryPlugin)();
164
- plugin.install(flow);
165
- flow.nodes.value[0].position.x = 100;
166
- plugin.saveSnapshot("step1");
167
- flow.nodes.value[0].position.x = 200;
168
- plugin.saveSnapshot("step2");
169
- plugin.jumpToStep(0);
170
- (0, _vitest.expect)(flow.nodes.value[0].position.x).toBe(0);
171
- });
172
- (0, _vitest.it)("should not undo below 0 or redo beyond end", () => {
173
- const flow = createMockFlow();
174
- const plugin = (0, _history.createHistoryPlugin)();
175
- plugin.install(flow);
176
- (0, _vitest.expect)(plugin.canUndo.value).toBe(false);
177
- plugin.undo();
178
- (0, _vitest.expect)(plugin.canRedo.value).toBe(false);
179
- plugin.redo();
180
- });
181
- (0, _vitest.it)("should destroy and cleanup", () => {
182
- const removeEventListener = _vitest.vi.spyOn(window, "removeEventListener");
183
- const flow = createMockFlow();
184
- const plugin = (0, _history.createHistoryPlugin)({
185
- enableKeyboard: true
186
- });
187
- plugin.install(flow);
188
- plugin.destroy?.();
189
- (0, _vitest.expect)(removeEventListener).toHaveBeenCalledWith("keydown", _vitest.expect.any(Function));
190
- });
191
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,161 +0,0 @@
1
- import { describe, it, expect, vi } from "vitest";
2
- import { ref } from "vue";
3
- import { createHistoryPlugin } from "../plugins/plugins/history.mjs";
4
- function createMockFlow() {
5
- const nodes = ref([
6
- { id: "1", type: "default", position: { x: 0, y: 0 }, data: { label: "A" } }
7
- ]);
8
- const edges = ref([]);
9
- const eventHandlers = {};
10
- const flow = {
11
- nodes,
12
- edges,
13
- viewport: ref({ x: 0, y: 0, zoom: 1 }),
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: () => nodes.value,
31
- getEdges: () => edges.value,
32
- getViewport: () => ({ x: 0, y: 0, zoom: 1 }),
33
- screenToCanvas: vi.fn().mockReturnValue({ x: 0, y: 0 }),
34
- canvasToScreen: vi.fn().mockReturnValue({ x: 0, y: 0 }),
35
- on: vi.fn((event, handler) => {
36
- if (!eventHandlers[event]) eventHandlers[event] = [];
37
- eventHandlers[event].push(handler);
38
- }),
39
- off: vi.fn(),
40
- emit: vi.fn(),
41
- isValidConnection: vi.fn().mockReturnValue(true),
42
- $el: void 0,
43
- draggingNodeId: ref(null),
44
- draggingPosition: ref(null),
45
- usePlugin: vi.fn(),
46
- removePlugin: vi.fn()
47
- };
48
- return flow;
49
- }
50
- describe("createHistoryPlugin", () => {
51
- it("should be created with correct metadata", () => {
52
- const plugin = createHistoryPlugin();
53
- expect(plugin.id).toBe("history");
54
- expect(plugin.name).toBe("History");
55
- expect(plugin.version).toBe("1.0.0");
56
- });
57
- it("should install and expose undo/redo on flow instance", () => {
58
- const flow = createMockFlow();
59
- const plugin = createHistoryPlugin();
60
- plugin.install(flow);
61
- expect(typeof flow.undo).toBe("function");
62
- expect(typeof flow.redo).toBe("function");
63
- expect(typeof flow.saveSnapshot).toBe("function");
64
- expect(typeof flow.clearHistory).toBe("function");
65
- expect(typeof flow.jumpToStep).toBe("function");
66
- expect(typeof flow.getHistory).toBe("function");
67
- });
68
- it("should save initial snapshot on install", () => {
69
- const flow = createMockFlow();
70
- const plugin = createHistoryPlugin();
71
- plugin.install(flow);
72
- const history = plugin.getHistory();
73
- expect(history.length).toBe(1);
74
- expect(history[0].description).toBe("initial");
75
- });
76
- it("should correctly undo and redo node position changes", () => {
77
- const flow = createMockFlow();
78
- const plugin = createHistoryPlugin();
79
- plugin.install(flow);
80
- flow.nodes.value[0].position.x = 100;
81
- plugin.saveSnapshot("move node");
82
- expect(plugin.canUndo.value).toBe(true);
83
- expect(plugin.canRedo.value).toBe(false);
84
- plugin.undo();
85
- expect(flow.nodes.value[0].position.x).toBe(0);
86
- expect(plugin.canRedo.value).toBe(true);
87
- plugin.redo();
88
- expect(flow.nodes.value[0].position.x).toBe(100);
89
- });
90
- it("should clear redo stack when new snapshot is pushed after undo", () => {
91
- const flow = createMockFlow();
92
- const plugin = createHistoryPlugin();
93
- plugin.install(flow);
94
- flow.nodes.value[0].position.x = 50;
95
- plugin.saveSnapshot("step1");
96
- flow.nodes.value[0].position.x = 100;
97
- plugin.saveSnapshot("step2");
98
- plugin.undo();
99
- expect(flow.nodes.value[0].position.x).toBe(50);
100
- expect(plugin.canRedo.value).toBe(true);
101
- flow.nodes.value[0].position.x = 200;
102
- plugin.saveSnapshot("step3");
103
- expect(plugin.canRedo.value).toBe(false);
104
- });
105
- it("should respect maxHistory limit", () => {
106
- const flow = createMockFlow();
107
- const plugin = createHistoryPlugin({ maxHistory: 3 });
108
- plugin.install(flow);
109
- for (let i = 1; i <= 5; i++) {
110
- flow.nodes.value[0].position.x = i * 10;
111
- plugin.saveSnapshot(`step${i}`);
112
- }
113
- expect(plugin.getHistory().length).toBe(3);
114
- });
115
- it("should clear history", () => {
116
- const flow = createMockFlow();
117
- const plugin = createHistoryPlugin();
118
- plugin.install(flow);
119
- flow.nodes.value[0].position.x = 100;
120
- plugin.saveSnapshot("move");
121
- plugin.clearHistory();
122
- expect(plugin.getHistory().length).toBe(0);
123
- expect(plugin.canUndo.value).toBe(false);
124
- expect(plugin.canRedo.value).toBe(false);
125
- });
126
- it("should call onHistoryChange callback", () => {
127
- const onHistoryChange = vi.fn();
128
- const flow = createMockFlow();
129
- const plugin = createHistoryPlugin({ onHistoryChange });
130
- plugin.install(flow);
131
- expect(onHistoryChange).toHaveBeenCalled();
132
- });
133
- it("should jump to a specific step", () => {
134
- const flow = createMockFlow();
135
- const plugin = createHistoryPlugin();
136
- plugin.install(flow);
137
- flow.nodes.value[0].position.x = 100;
138
- plugin.saveSnapshot("step1");
139
- flow.nodes.value[0].position.x = 200;
140
- plugin.saveSnapshot("step2");
141
- plugin.jumpToStep(0);
142
- expect(flow.nodes.value[0].position.x).toBe(0);
143
- });
144
- it("should not undo below 0 or redo beyond end", () => {
145
- const flow = createMockFlow();
146
- const plugin = createHistoryPlugin();
147
- plugin.install(flow);
148
- expect(plugin.canUndo.value).toBe(false);
149
- plugin.undo();
150
- expect(plugin.canRedo.value).toBe(false);
151
- plugin.redo();
152
- });
153
- it("should destroy and cleanup", () => {
154
- const removeEventListener = vi.spyOn(window, "removeEventListener");
155
- const flow = createMockFlow();
156
- const plugin = createHistoryPlugin({ enableKeyboard: true });
157
- plugin.install(flow);
158
- plugin.destroy?.();
159
- expect(removeEventListener).toHaveBeenCalledWith("keydown", expect.any(Function));
160
- });
161
- });
@@ -1,81 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _vue = require("vue");
5
- var _useHistory = require("../core/useHistory.cjs");
6
- (0, _vitest.describe)("flow/core/useHistory", () => {
7
- (0, _vitest.it)("should push, undo, redo", () => {
8
- const nodes = (0, _vue.ref)([{
9
- id: "1",
10
- type: "default",
11
- position: {
12
- x: 0,
13
- y: 0
14
- },
15
- data: {}
16
- }]);
17
- const edges = (0, _vue.ref)([]);
18
- const historyEvents = [];
19
- const h = (0, _useHistory.useHistory)(nodes, edges, {
20
- maxHistory: 10,
21
- onHistoryChange: (canUndo, canRedo) => historyEvents.push({
22
- canUndo,
23
- canRedo
24
- })
25
- });
26
- h.push({
27
- nodes: nodes.value,
28
- edges: edges.value
29
- });
30
- (0, _vitest.expect)(h.canUndo.value).toBe(false);
31
- (0, _vitest.expect)(h.canRedo.value).toBe(false);
32
- nodes.value[0].position.x = 100;
33
- h.push({
34
- nodes: nodes.value,
35
- edges: edges.value
36
- });
37
- (0, _vitest.expect)(h.canUndo.value).toBe(true);
38
- (0, _vitest.expect)(h.canRedo.value).toBe(false);
39
- h.undo();
40
- (0, _vitest.expect)(nodes.value[0].position.x).toBe(0);
41
- (0, _vitest.expect)(h.canRedo.value).toBe(true);
42
- h.redo();
43
- (0, _vitest.expect)(nodes.value[0].position.x).toBe(100);
44
- h.clear();
45
- (0, _vitest.expect)(h.canUndo.value).toBe(false);
46
- (0, _vitest.expect)(h.canRedo.value).toBe(false);
47
- (0, _vitest.expect)(historyEvents.length).toBeGreaterThan(0);
48
- });
49
- (0, _vitest.it)("should respect maxHistory", () => {
50
- const nodes = (0, _vue.ref)([{
51
- id: "1",
52
- type: "default",
53
- position: {
54
- x: 0,
55
- y: 0
56
- },
57
- data: {}
58
- }]);
59
- const edges = (0, _vue.ref)([]);
60
- const h = (0, _useHistory.useHistory)(nodes, edges, {
61
- maxHistory: 2
62
- });
63
- h.push({
64
- nodes: nodes.value,
65
- edges: edges.value
66
- });
67
- nodes.value[0].position.x = 1;
68
- h.push({
69
- nodes: nodes.value,
70
- edges: edges.value
71
- });
72
- nodes.value[0].position.x = 2;
73
- h.push({
74
- nodes: nodes.value,
75
- edges: edges.value
76
- });
77
- h.undo();
78
- (0, _vitest.expect)(nodes.value[0].position.x).toBe(1);
79
- (0, _vitest.expect)(h.canUndo.value).toBe(false);
80
- });
81
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,43 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { ref } from "vue";
3
- import { useHistory } from "../core/useHistory.mjs";
4
- describe("flow/core/useHistory", () => {
5
- it("should push, undo, redo", () => {
6
- const nodes = ref([{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {} }]);
7
- const edges = ref([]);
8
- const historyEvents = [];
9
- const h = useHistory(nodes, edges, {
10
- maxHistory: 10,
11
- onHistoryChange: (canUndo, canRedo) => historyEvents.push({ canUndo, canRedo })
12
- });
13
- h.push({ nodes: nodes.value, edges: edges.value });
14
- expect(h.canUndo.value).toBe(false);
15
- expect(h.canRedo.value).toBe(false);
16
- nodes.value[0].position.x = 100;
17
- h.push({ nodes: nodes.value, edges: edges.value });
18
- expect(h.canUndo.value).toBe(true);
19
- expect(h.canRedo.value).toBe(false);
20
- h.undo();
21
- expect(nodes.value[0].position.x).toBe(0);
22
- expect(h.canRedo.value).toBe(true);
23
- h.redo();
24
- expect(nodes.value[0].position.x).toBe(100);
25
- h.clear();
26
- expect(h.canUndo.value).toBe(false);
27
- expect(h.canRedo.value).toBe(false);
28
- expect(historyEvents.length).toBeGreaterThan(0);
29
- });
30
- it("should respect maxHistory", () => {
31
- const nodes = ref([{ id: "1", type: "default", position: { x: 0, y: 0 }, data: {} }]);
32
- const edges = ref([]);
33
- const h = useHistory(nodes, edges, { maxHistory: 2 });
34
- h.push({ nodes: nodes.value, edges: edges.value });
35
- nodes.value[0].position.x = 1;
36
- h.push({ nodes: nodes.value, edges: edges.value });
37
- nodes.value[0].position.x = 2;
38
- h.push({ nodes: nodes.value, edges: edges.value });
39
- h.undo();
40
- expect(nodes.value[0].position.x).toBe(1);
41
- expect(h.canUndo.value).toBe(false);
42
- });
43
- });