@yh-ui/flow 0.1.21
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/LICENSE +21 -0
- package/README.md +234 -0
- package/dist/Flow.d.vue.ts +306 -0
- package/dist/Flow.vue +959 -0
- package/dist/Flow.vue.d.ts +306 -0
- package/dist/__tests__/ai-workflow.ssr.test.cjs +352 -0
- package/dist/__tests__/ai-workflow.ssr.test.d.ts +1 -0
- package/dist/__tests__/ai-workflow.ssr.test.mjs +283 -0
- package/dist/__tests__/ai-workflow.test.cjs +109 -0
- package/dist/__tests__/ai-workflow.test.d.ts +1 -0
- package/dist/__tests__/ai-workflow.test.mjs +112 -0
- package/dist/__tests__/bpmn.ssr.test.cjs +278 -0
- package/dist/__tests__/bpmn.ssr.test.d.ts +1 -0
- package/dist/__tests__/bpmn.ssr.test.mjs +237 -0
- package/dist/__tests__/bpmn.test.cjs +103 -0
- package/dist/__tests__/bpmn.test.d.ts +1 -0
- package/dist/__tests__/bpmn.test.mjs +106 -0
- package/dist/__tests__/custom-types.test.cjs +300 -0
- package/dist/__tests__/custom-types.test.d.ts +1 -0
- package/dist/__tests__/custom-types.test.mjs +248 -0
- package/dist/__tests__/edge.test.cjs +56 -0
- package/dist/__tests__/edge.test.d.ts +1 -0
- package/dist/__tests__/edge.test.mjs +69 -0
- package/dist/__tests__/event-bus.test.cjs +80 -0
- package/dist/__tests__/event-bus.test.d.ts +1 -0
- package/dist/__tests__/event-bus.test.mjs +51 -0
- package/dist/__tests__/flow.ssr.test.cjs +156 -0
- package/dist/__tests__/flow.ssr.test.d.ts +1 -0
- package/dist/__tests__/flow.ssr.test.mjs +112 -0
- package/dist/__tests__/geometry.test.cjs +191 -0
- package/dist/__tests__/geometry.test.d.ts +1 -0
- package/dist/__tests__/geometry.test.mjs +105 -0
- package/dist/__tests__/graph.test.cjs +115 -0
- package/dist/__tests__/graph.test.d.ts +1 -0
- package/dist/__tests__/graph.test.mjs +85 -0
- package/dist/__tests__/history-plugin.test.cjs +191 -0
- package/dist/__tests__/history-plugin.test.d.ts +1 -0
- package/dist/__tests__/history-plugin.test.mjs +161 -0
- package/dist/__tests__/history.test.cjs +81 -0
- package/dist/__tests__/history.test.d.ts +1 -0
- package/dist/__tests__/history.test.mjs +43 -0
- package/dist/__tests__/layout.test.cjs +213 -0
- package/dist/__tests__/layout.test.d.ts +1 -0
- package/dist/__tests__/layout.test.mjs +170 -0
- package/dist/__tests__/node-edit-panel.ssr.test.cjs +168 -0
- package/dist/__tests__/node-edit-panel.ssr.test.d.ts +1 -0
- package/dist/__tests__/node-edit-panel.ssr.test.mjs +118 -0
- package/dist/__tests__/node-group-plugin.test.cjs +235 -0
- package/dist/__tests__/node-group-plugin.test.d.ts +1 -0
- package/dist/__tests__/node-group-plugin.test.mjs +187 -0
- package/dist/__tests__/node-handles.test.cjs +340 -0
- package/dist/__tests__/node-handles.test.d.ts +1 -0
- package/dist/__tests__/node-handles.test.mjs +230 -0
- package/dist/__tests__/plugin.test.cjs +151 -0
- package/dist/__tests__/plugin.test.d.ts +1 -0
- package/dist/__tests__/plugin.test.mjs +116 -0
- package/dist/__tests__/transform.test.cjs +58 -0
- package/dist/__tests__/transform.test.d.ts +1 -0
- package/dist/__tests__/transform.test.mjs +38 -0
- package/dist/__tests__/useAlignment.test.cjs +91 -0
- package/dist/__tests__/useAlignment.test.d.ts +1 -0
- package/dist/__tests__/useAlignment.test.mjs +52 -0
- package/dist/__tests__/useEdges.test.cjs +117 -0
- package/dist/__tests__/useEdges.test.d.ts +1 -0
- package/dist/__tests__/useEdges.test.mjs +80 -0
- package/dist/__tests__/useKeyboard.test.cjs +88 -0
- package/dist/__tests__/useKeyboard.test.d.ts +1 -0
- package/dist/__tests__/useKeyboard.test.mjs +56 -0
- package/dist/__tests__/useNodes.test.cjs +150 -0
- package/dist/__tests__/useNodes.test.d.ts +1 -0
- package/dist/__tests__/useNodes.test.mjs +80 -0
- package/dist/__tests__/useSelection.test.cjs +112 -0
- package/dist/__tests__/useSelection.test.d.ts +1 -0
- package/dist/__tests__/useSelection.test.mjs +76 -0
- package/dist/__tests__/useViewport.test.cjs +171 -0
- package/dist/__tests__/useViewport.test.d.ts +1 -0
- package/dist/__tests__/useViewport.test.mjs +82 -0
- package/dist/__tests__/utils/ssr.cjs +124 -0
- package/dist/__tests__/utils/ssr.d.ts +33 -0
- package/dist/__tests__/utils/ssr.mjs +129 -0
- package/dist/__tests__/validation.test.cjs +95 -0
- package/dist/__tests__/validation.test.d.ts +1 -0
- package/dist/__tests__/validation.test.mjs +36 -0
- package/dist/components/AiNodeEditPanel.d.vue.ts +13 -0
- package/dist/components/AiNodeEditPanel.vue +413 -0
- package/dist/components/AiNodeEditPanel.vue.d.ts +13 -0
- package/dist/components/EdgeEditPanel.d.vue.ts +14 -0
- package/dist/components/EdgeEditPanel.vue +205 -0
- package/dist/components/EdgeEditPanel.vue.d.ts +14 -0
- package/dist/components/NodeEditPanel.d.vue.ts +13 -0
- package/dist/components/NodeEditPanel.vue +214 -0
- package/dist/components/NodeEditPanel.vue.d.ts +13 -0
- package/dist/components/edges/BaseEdge.d.vue.ts +23 -0
- package/dist/components/edges/BaseEdge.vue +55 -0
- package/dist/components/edges/BaseEdge.vue.d.ts +23 -0
- package/dist/components/edges/BezierEdge.d.vue.ts +22 -0
- package/dist/components/edges/BezierEdge.vue +57 -0
- package/dist/components/edges/BezierEdge.vue.d.ts +22 -0
- package/dist/components/edges/DataFlowEdge.d.vue.ts +41 -0
- package/dist/components/edges/DataFlowEdge.vue +211 -0
- package/dist/components/edges/DataFlowEdge.vue.d.ts +41 -0
- package/dist/components/edges/SmoothEdge.d.vue.ts +22 -0
- package/dist/components/edges/SmoothEdge.vue +53 -0
- package/dist/components/edges/SmoothEdge.vue.d.ts +22 -0
- package/dist/components/edges/StepEdge.d.vue.ts +22 -0
- package/dist/components/edges/StepEdge.vue +42 -0
- package/dist/components/edges/StepEdge.vue.d.ts +22 -0
- package/dist/components/edges/index.cjs +41 -0
- package/dist/components/edges/index.d.ts +5 -0
- package/dist/components/edges/index.mjs +5 -0
- package/dist/components/nodes/BaseNode.d.vue.ts +25 -0
- package/dist/components/nodes/BaseNode.vue +93 -0
- package/dist/components/nodes/BaseNode.vue.d.ts +25 -0
- package/dist/components/nodes/CustomNode.d.vue.ts +36 -0
- package/dist/components/nodes/CustomNode.vue +44 -0
- package/dist/components/nodes/CustomNode.vue.d.ts +36 -0
- package/dist/components/nodes/DatabaseNode.d.vue.ts +19 -0
- package/dist/components/nodes/DatabaseNode.vue +62 -0
- package/dist/components/nodes/DatabaseNode.vue.d.ts +19 -0
- package/dist/components/nodes/DiamondNode.d.vue.ts +19 -0
- package/dist/components/nodes/DiamondNode.vue +62 -0
- package/dist/components/nodes/DiamondNode.vue.d.ts +19 -0
- package/dist/components/nodes/GroupNode.d.vue.ts +31 -0
- package/dist/components/nodes/GroupNode.vue +48 -0
- package/dist/components/nodes/GroupNode.vue.d.ts +31 -0
- package/dist/components/nodes/InputNode.d.vue.ts +23 -0
- package/dist/components/nodes/InputNode.vue +63 -0
- package/dist/components/nodes/InputNode.vue.d.ts +23 -0
- package/dist/components/nodes/NodeResizer.d.vue.ts +27 -0
- package/dist/components/nodes/NodeResizer.vue +89 -0
- package/dist/components/nodes/NodeResizer.vue.d.ts +27 -0
- package/dist/components/nodes/NodeToolbar.d.vue.ts +32 -0
- package/dist/components/nodes/NodeToolbar.vue +101 -0
- package/dist/components/nodes/NodeToolbar.vue.d.ts +32 -0
- package/dist/components/nodes/OutputNode.d.vue.ts +21 -0
- package/dist/components/nodes/OutputNode.vue +53 -0
- package/dist/components/nodes/OutputNode.vue.d.ts +21 -0
- package/dist/components/nodes/ai-workflow/AiAgentNode.d.vue.ts +20 -0
- package/dist/components/nodes/ai-workflow/AiAgentNode.vue +59 -0
- package/dist/components/nodes/ai-workflow/AiAgentNode.vue.d.ts +20 -0
- package/dist/components/nodes/ai-workflow/AiConditionNode.d.vue.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiConditionNode.vue +65 -0
- package/dist/components/nodes/ai-workflow/AiConditionNode.vue.d.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiEndNode.d.vue.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiEndNode.vue +47 -0
- package/dist/components/nodes/ai-workflow/AiEndNode.vue.d.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiLlmNode.d.vue.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiLlmNode.vue +64 -0
- package/dist/components/nodes/ai-workflow/AiLlmNode.vue.d.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiMemoryNode.d.vue.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiMemoryNode.vue +59 -0
- package/dist/components/nodes/ai-workflow/AiMemoryNode.vue.d.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiPromptNode.d.vue.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiPromptNode.vue +61 -0
- package/dist/components/nodes/ai-workflow/AiPromptNode.vue.d.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiStartNode.d.vue.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiStartNode.vue +47 -0
- package/dist/components/nodes/ai-workflow/AiStartNode.vue.d.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiToolNode.d.vue.ts +19 -0
- package/dist/components/nodes/ai-workflow/AiToolNode.vue +59 -0
- package/dist/components/nodes/ai-workflow/AiToolNode.vue.d.ts +19 -0
- package/dist/components/nodes/ai-workflow/index.cjs +109 -0
- package/dist/components/nodes/ai-workflow/index.d.ts +23 -0
- package/dist/components/nodes/ai-workflow/index.mjs +37 -0
- package/dist/components/nodes/bpmn/BpmnEndEvent.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnEndEvent.vue +50 -0
- package/dist/components/nodes/bpmn/BpmnEndEvent.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnExclusiveGateway.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnExclusiveGateway.vue +60 -0
- package/dist/components/nodes/bpmn/BpmnExclusiveGateway.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnInclusiveGateway.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnInclusiveGateway.vue +60 -0
- package/dist/components/nodes/bpmn/BpmnInclusiveGateway.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnParallelGateway.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnParallelGateway.vue +60 -0
- package/dist/components/nodes/bpmn/BpmnParallelGateway.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnServiceTask.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnServiceTask.vue +55 -0
- package/dist/components/nodes/bpmn/BpmnServiceTask.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnStartEvent.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnStartEvent.vue +50 -0
- package/dist/components/nodes/bpmn/BpmnStartEvent.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnTask.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnTask.vue +54 -0
- package/dist/components/nodes/bpmn/BpmnTask.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnUserTask.d.vue.ts +19 -0
- package/dist/components/nodes/bpmn/BpmnUserTask.vue +55 -0
- package/dist/components/nodes/bpmn/BpmnUserTask.vue.d.ts +19 -0
- package/dist/components/nodes/bpmn/index.cjs +109 -0
- package/dist/components/nodes/bpmn/index.d.ts +23 -0
- package/dist/components/nodes/bpmn/index.mjs +37 -0
- package/dist/components/nodes/index.cjs +246 -0
- package/dist/components/nodes/index.d.ts +13 -0
- package/dist/components/nodes/index.mjs +44 -0
- package/dist/core/FlowContext.cjs +21 -0
- package/dist/core/FlowContext.d.ts +10 -0
- package/dist/core/FlowContext.mjs +13 -0
- package/dist/core/index.cjs +104 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.mjs +9 -0
- package/dist/core/useAlignment.cjs +81 -0
- package/dist/core/useAlignment.d.ts +33 -0
- package/dist/core/useAlignment.mjs +71 -0
- package/dist/core/useEdges.cjs +132 -0
- package/dist/core/useEdges.d.ts +29 -0
- package/dist/core/useEdges.mjs +89 -0
- package/dist/core/useFlow.cjs +40 -0
- package/dist/core/useFlow.d.ts +31 -0
- package/dist/core/useFlow.mjs +32 -0
- package/dist/core/useHistory.cjs +63 -0
- package/dist/core/useHistory.d.ts +15 -0
- package/dist/core/useHistory.mjs +54 -0
- package/dist/core/useKeyboard.cjs +54 -0
- package/dist/core/useKeyboard.d.ts +18 -0
- package/dist/core/useKeyboard.mjs +45 -0
- package/dist/core/useNodeDistribution.cjs +171 -0
- package/dist/core/useNodeDistribution.d.ts +12 -0
- package/dist/core/useNodeDistribution.mjs +145 -0
- package/dist/core/useNodes.cjs +146 -0
- package/dist/core/useNodes.d.ts +26 -0
- package/dist/core/useNodes.mjs +101 -0
- package/dist/core/useSelection.cjs +83 -0
- package/dist/core/useSelection.d.ts +18 -0
- package/dist/core/useSelection.mjs +53 -0
- package/dist/core/useViewport.cjs +157 -0
- package/dist/core/useViewport.d.ts +65 -0
- package/dist/core/useViewport.mjs +125 -0
- package/dist/flow.cjs +240 -0
- package/dist/flow.d.ts +276 -0
- package/dist/flow.mjs +230 -0
- package/dist/index.cjs +378 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.mjs +50 -0
- package/dist/plugins/index.cjs +96 -0
- package/dist/plugins/index.d.ts +34 -0
- package/dist/plugins/index.mjs +47 -0
- package/dist/plugins/plugin.cjs +117 -0
- package/dist/plugins/plugin.d.ts +72 -0
- package/dist/plugins/plugin.mjs +110 -0
- package/dist/plugins/plugins/controls.cjs +38 -0
- package/dist/plugins/plugins/controls.d.ts +12 -0
- package/dist/plugins/plugins/controls.mjs +28 -0
- package/dist/plugins/plugins/export.cjs +102 -0
- package/dist/plugins/plugins/export.d.ts +12 -0
- package/dist/plugins/plugins/export.mjs +89 -0
- package/dist/plugins/plugins/grid.cjs +36 -0
- package/dist/plugins/plugins/grid.d.ts +11 -0
- package/dist/plugins/plugins/grid.mjs +26 -0
- package/dist/plugins/plugins/history.cjs +140 -0
- package/dist/plugins/plugins/history.d.ts +53 -0
- package/dist/plugins/plugins/history.mjs +132 -0
- package/dist/plugins/plugins/index.cjs +104 -0
- package/dist/plugins/plugins/index.d.ts +9 -0
- package/dist/plugins/plugins/index.mjs +9 -0
- package/dist/plugins/plugins/keyboard.cjs +27 -0
- package/dist/plugins/plugins/keyboard.d.ts +10 -0
- package/dist/plugins/plugins/keyboard.mjs +18 -0
- package/dist/plugins/plugins/layout.cjs +275 -0
- package/dist/plugins/plugins/layout.d.ts +34 -0
- package/dist/plugins/plugins/layout.mjs +246 -0
- package/dist/plugins/plugins/minimap.cjs +60 -0
- package/dist/plugins/plugins/minimap.d.ts +25 -0
- package/dist/plugins/plugins/minimap.mjs +50 -0
- package/dist/plugins/plugins/node-group.cjs +209 -0
- package/dist/plugins/plugins/node-group.d.ts +26 -0
- package/dist/plugins/plugins/node-group.mjs +178 -0
- package/dist/plugins/plugins/snap.cjs +36 -0
- package/dist/plugins/plugins/snap.d.ts +12 -0
- package/dist/plugins/plugins/snap.mjs +26 -0
- package/dist/renderer/AlignmentLines.d.vue.ts +5 -0
- package/dist/renderer/AlignmentLines.vue +113 -0
- package/dist/renderer/AlignmentLines.vue.d.ts +5 -0
- package/dist/renderer/Background.d.vue.ts +7 -0
- package/dist/renderer/Background.vue +86 -0
- package/dist/renderer/Background.vue.d.ts +7 -0
- package/dist/renderer/Controls.d.vue.ts +13 -0
- package/dist/renderer/Controls.vue +82 -0
- package/dist/renderer/Controls.vue.d.ts +13 -0
- package/dist/renderer/EdgeHandlesRenderer.d.vue.ts +11 -0
- package/dist/renderer/EdgeHandlesRenderer.vue +75 -0
- package/dist/renderer/EdgeHandlesRenderer.vue.d.ts +11 -0
- package/dist/renderer/EdgeRenderer.d.vue.ts +39 -0
- package/dist/renderer/EdgeRenderer.vue +204 -0
- package/dist/renderer/EdgeRenderer.vue.d.ts +39 -0
- package/dist/renderer/FlowBackground.d.vue.ts +11 -0
- package/dist/renderer/FlowBackground.vue +82 -0
- package/dist/renderer/FlowBackground.vue.d.ts +11 -0
- package/dist/renderer/Minimap.d.vue.ts +30 -0
- package/dist/renderer/Minimap.vue +290 -0
- package/dist/renderer/Minimap.vue.d.ts +30 -0
- package/dist/renderer/NodeRenderer.d.vue.ts +56 -0
- package/dist/renderer/NodeRenderer.vue +328 -0
- package/dist/renderer/NodeRenderer.vue.d.ts +56 -0
- package/dist/renderer/SelectionBox.d.vue.ts +11 -0
- package/dist/renderer/SelectionBox.vue +28 -0
- package/dist/renderer/SelectionBox.vue.d.ts +11 -0
- package/dist/types/edge.cjs +13 -0
- package/dist/types/edge.d.ts +65 -0
- package/dist/types/edge.mjs +6 -0
- package/dist/types/events.cjs +1 -0
- package/dist/types/events.d.ts +115 -0
- package/dist/types/events.mjs +0 -0
- package/dist/types/index.cjs +1 -0
- package/dist/types/index.d.ts +366 -0
- package/dist/types/index.mjs +0 -0
- package/dist/types/node.cjs +9 -0
- package/dist/types/node.d.ts +90 -0
- package/dist/types/node.mjs +3 -0
- package/dist/types/viewport.cjs +42 -0
- package/dist/types/viewport.d.ts +62 -0
- package/dist/types/viewport.mjs +36 -0
- package/dist/utils/bpmn-engine.cjs +390 -0
- package/dist/utils/bpmn-engine.d.ts +164 -0
- package/dist/utils/bpmn-engine.mjs +378 -0
- package/dist/utils/bpmn.cjs +492 -0
- package/dist/utils/bpmn.d.ts +53 -0
- package/dist/utils/bpmn.mjs +430 -0
- package/dist/utils/collaboration.cjs +537 -0
- package/dist/utils/collaboration.d.ts +189 -0
- package/dist/utils/collaboration.mjs +521 -0
- package/dist/utils/custom-types.cjs +138 -0
- package/dist/utils/custom-types.d.ts +78 -0
- package/dist/utils/custom-types.mjs +108 -0
- package/dist/utils/edge.cjs +235 -0
- package/dist/utils/edge.d.ts +79 -0
- package/dist/utils/edge.mjs +172 -0
- package/dist/utils/event-bus.cjs +91 -0
- package/dist/utils/event-bus.d.ts +39 -0
- package/dist/utils/event-bus.mjs +82 -0
- package/dist/utils/geometry.cjs +178 -0
- package/dist/utils/geometry.d.ts +186 -0
- package/dist/utils/geometry.mjs +144 -0
- package/dist/utils/graph.cjs +158 -0
- package/dist/utils/graph.d.ts +40 -0
- package/dist/utils/graph.mjs +147 -0
- package/dist/utils/index.cjs +137 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.mjs +12 -0
- package/dist/utils/performance.cjs +94 -0
- package/dist/utils/performance.d.ts +18 -0
- package/dist/utils/performance.mjs +82 -0
- package/dist/utils/screenshot.cjs +87 -0
- package/dist/utils/screenshot.d.ts +22 -0
- package/dist/utils/screenshot.mjs +66 -0
- package/dist/utils/theme.cjs +228 -0
- package/dist/utils/theme.d.ts +92 -0
- package/dist/utils/theme.mjs +217 -0
- package/dist/utils/transform.cjs +76 -0
- package/dist/utils/transform.d.ts +45 -0
- package/dist/utils/transform.mjs +57 -0
- package/dist/utils/validation.cjs +107 -0
- package/dist/utils/validation.d.ts +29 -0
- package/dist/utils/validation.mjs +85 -0
- package/package.json +61 -0
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _vue = require("vue");
|
|
5
|
+
var _layout = require("../plugins/plugins/layout.cjs");
|
|
6
|
+
function createMockFlowInstance() {
|
|
7
|
+
const nodes = (0, _vue.ref)([]);
|
|
8
|
+
const edges = (0, _vue.ref)([]);
|
|
9
|
+
const viewport = (0, _vue.ref)({
|
|
10
|
+
x: 0,
|
|
11
|
+
y: 0,
|
|
12
|
+
zoom: 1
|
|
13
|
+
});
|
|
14
|
+
const draggingNodeId = (0, _vue.ref)(null);
|
|
15
|
+
return {
|
|
16
|
+
nodes,
|
|
17
|
+
edges,
|
|
18
|
+
viewport,
|
|
19
|
+
draggingNodeId,
|
|
20
|
+
addNode: _vitest.vi.fn(),
|
|
21
|
+
removeNode: _vitest.vi.fn(),
|
|
22
|
+
updateNode: _vitest.vi.fn((id, data) => {
|
|
23
|
+
const node = nodes.value.find(n => n.id === id);
|
|
24
|
+
if (node) Object.assign(node, data);
|
|
25
|
+
}),
|
|
26
|
+
getNode: _vitest.vi.fn(id => nodes.value.find(n => n.id === id)),
|
|
27
|
+
addEdge: _vitest.vi.fn(),
|
|
28
|
+
removeEdge: _vitest.vi.fn(),
|
|
29
|
+
updateEdge: _vitest.vi.fn(),
|
|
30
|
+
getEdge: _vitest.vi.fn(),
|
|
31
|
+
setViewport: _vitest.vi.fn(),
|
|
32
|
+
fitView: _vitest.vi.fn(),
|
|
33
|
+
zoomIn: _vitest.vi.fn(),
|
|
34
|
+
zoomOut: _vitest.vi.fn(),
|
|
35
|
+
centerView: _vitest.vi.fn(),
|
|
36
|
+
selectNode: _vitest.vi.fn(),
|
|
37
|
+
selectEdge: _vitest.vi.fn(),
|
|
38
|
+
clearSelection: _vitest.vi.fn(),
|
|
39
|
+
getNodes: _vitest.vi.fn(() => nodes.value),
|
|
40
|
+
getEdges: _vitest.vi.fn(() => edges.value),
|
|
41
|
+
getViewport: _vitest.vi.fn(() => viewport.value),
|
|
42
|
+
screenToCanvas: _vitest.vi.fn((x, y) => ({
|
|
43
|
+
x,
|
|
44
|
+
y
|
|
45
|
+
})),
|
|
46
|
+
canvasToScreen: _vitest.vi.fn((x, y) => ({
|
|
47
|
+
x,
|
|
48
|
+
y
|
|
49
|
+
})),
|
|
50
|
+
on: _vitest.vi.fn(),
|
|
51
|
+
off: _vitest.vi.fn(),
|
|
52
|
+
emit: _vitest.vi.fn(),
|
|
53
|
+
isValidConnection: _vitest.vi.fn(() => true),
|
|
54
|
+
$el: void 0,
|
|
55
|
+
usePlugin: _vitest.vi.fn(),
|
|
56
|
+
removePlugin: _vitest.vi.fn()
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
(0, _vitest.describe)("flow/plugins/plugins/layout", () => {
|
|
60
|
+
(0, _vitest.describe)("LayoutOptions", () => {
|
|
61
|
+
(0, _vitest.it)("should have correct default options", () => {
|
|
62
|
+
const plugin = (0, _layout.createLayoutPlugin)();
|
|
63
|
+
const flow = createMockFlowInstance();
|
|
64
|
+
plugin.install(flow);
|
|
65
|
+
(0, _vitest.expect)(flow.applyLayout).toBeDefined();
|
|
66
|
+
});
|
|
67
|
+
(0, _vitest.it)("should support dagre layout type", () => {
|
|
68
|
+
const plugin = (0, _layout.createLayoutPlugin)({
|
|
69
|
+
type: "dagre"
|
|
70
|
+
});
|
|
71
|
+
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
72
|
+
(0, _vitest.expect)(plugin.name).toBe("Layout");
|
|
73
|
+
});
|
|
74
|
+
(0, _vitest.it)("should support elk layout type", () => {
|
|
75
|
+
const plugin = (0, _layout.createLayoutPlugin)({
|
|
76
|
+
type: "elk"
|
|
77
|
+
});
|
|
78
|
+
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
79
|
+
(0, _vitest.expect)(plugin.name).toBe("Layout");
|
|
80
|
+
});
|
|
81
|
+
(0, _vitest.it)("should support force layout type", () => {
|
|
82
|
+
const plugin = (0, _layout.createLayoutPlugin)({
|
|
83
|
+
type: "force"
|
|
84
|
+
});
|
|
85
|
+
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
86
|
+
(0, _vitest.expect)(plugin.name).toBe("Layout");
|
|
87
|
+
});
|
|
88
|
+
(0, _vitest.it)("should support grid layout type", () => {
|
|
89
|
+
const plugin = (0, _layout.createLayoutPlugin)({
|
|
90
|
+
type: "grid"
|
|
91
|
+
});
|
|
92
|
+
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
93
|
+
(0, _vitest.expect)(plugin.name).toBe("Layout");
|
|
94
|
+
});
|
|
95
|
+
(0, _vitest.it)("should accept direction option TB", () => {
|
|
96
|
+
const plugin = (0, _layout.createLayoutPlugin)({
|
|
97
|
+
direction: "TB"
|
|
98
|
+
});
|
|
99
|
+
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
100
|
+
});
|
|
101
|
+
(0, _vitest.it)("should accept direction option LR", () => {
|
|
102
|
+
const plugin = (0, _layout.createLayoutPlugin)({
|
|
103
|
+
direction: "LR"
|
|
104
|
+
});
|
|
105
|
+
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
106
|
+
});
|
|
107
|
+
(0, _vitest.it)("should accept node spacing option", () => {
|
|
108
|
+
const plugin = (0, _layout.createLayoutPlugin)({
|
|
109
|
+
nodeSpacing: 100
|
|
110
|
+
});
|
|
111
|
+
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
112
|
+
});
|
|
113
|
+
(0, _vitest.it)("should accept rank spacing option", () => {
|
|
114
|
+
const plugin = (0, _layout.createLayoutPlugin)({
|
|
115
|
+
rankSpacing: 150
|
|
116
|
+
});
|
|
117
|
+
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
118
|
+
});
|
|
119
|
+
(0, _vitest.it)("should accept elk options", () => {
|
|
120
|
+
const plugin = (0, _layout.createLayoutPlugin)({
|
|
121
|
+
type: "elk",
|
|
122
|
+
elkOptions: {
|
|
123
|
+
algorithm: "layered",
|
|
124
|
+
direction: "DOWN",
|
|
125
|
+
spacing: 50,
|
|
126
|
+
edgeRouting: "POLYLINE"
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
130
|
+
});
|
|
131
|
+
(0, _vitest.it)("should accept force options", () => {
|
|
132
|
+
const plugin = (0, _layout.createLayoutPlugin)({
|
|
133
|
+
type: "force",
|
|
134
|
+
forceOptions: {
|
|
135
|
+
strength: -500,
|
|
136
|
+
distance: 200,
|
|
137
|
+
iterations: 500
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
141
|
+
});
|
|
142
|
+
(0, _vitest.it)("should accept grid options", () => {
|
|
143
|
+
const plugin = (0, _layout.createLayoutPlugin)({
|
|
144
|
+
type: "grid",
|
|
145
|
+
gridOptions: {
|
|
146
|
+
columns: 3,
|
|
147
|
+
startX: 100,
|
|
148
|
+
startY: 100
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
(0, _vitest.expect)(plugin.id).toBe("layout");
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
(0, _vitest.describe)("Layout execution", () => {
|
|
155
|
+
(0, _vitest.it)("should add applyLayout method to flow instance", () => {
|
|
156
|
+
const plugin = (0, _layout.createLayoutPlugin)();
|
|
157
|
+
const flow = createMockFlowInstance();
|
|
158
|
+
plugin.install(flow);
|
|
159
|
+
(0, _vitest.expect)(typeof flow.applyLayout).toBe("function");
|
|
160
|
+
});
|
|
161
|
+
(0, _vitest.it)("should return function when calling applyLayout", async () => {
|
|
162
|
+
const plugin = (0, _layout.createLayoutPlugin)({
|
|
163
|
+
type: "dagre"
|
|
164
|
+
});
|
|
165
|
+
const flow = createMockFlowInstance();
|
|
166
|
+
flow.nodes.value = [{
|
|
167
|
+
id: "1",
|
|
168
|
+
type: "default",
|
|
169
|
+
position: {
|
|
170
|
+
x: 0,
|
|
171
|
+
y: 0
|
|
172
|
+
},
|
|
173
|
+
data: {
|
|
174
|
+
label: "Node 1"
|
|
175
|
+
},
|
|
176
|
+
width: 150,
|
|
177
|
+
height: 50
|
|
178
|
+
}];
|
|
179
|
+
flow.edges.value = [];
|
|
180
|
+
plugin.install(flow);
|
|
181
|
+
const result = flow.applyLayout({
|
|
182
|
+
type: "dagre"
|
|
183
|
+
});
|
|
184
|
+
(0, _vitest.expect)(result === void 0 || result instanceof Promise).toBe(true);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
(0, _vitest.describe)("LayoutOptions interface", () => {
|
|
188
|
+
(0, _vitest.it)("should validate LayoutOptions type field accepts dagre", () => {
|
|
189
|
+
const options = {
|
|
190
|
+
type: "dagre"
|
|
191
|
+
};
|
|
192
|
+
(0, _vitest.expect)(options.type).toBe("dagre");
|
|
193
|
+
});
|
|
194
|
+
(0, _vitest.it)("should validate LayoutOptions type field accepts elk", () => {
|
|
195
|
+
const options = {
|
|
196
|
+
type: "elk"
|
|
197
|
+
};
|
|
198
|
+
(0, _vitest.expect)(options.type).toBe("elk");
|
|
199
|
+
});
|
|
200
|
+
(0, _vitest.it)("should validate LayoutOptions type field accepts force", () => {
|
|
201
|
+
const options = {
|
|
202
|
+
type: "force"
|
|
203
|
+
};
|
|
204
|
+
(0, _vitest.expect)(options.type).toBe("force");
|
|
205
|
+
});
|
|
206
|
+
(0, _vitest.it)("should validate LayoutOptions type field accepts grid", () => {
|
|
207
|
+
const options = {
|
|
208
|
+
type: "grid"
|
|
209
|
+
};
|
|
210
|
+
(0, _vitest.expect)(options.type).toBe("grid");
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import { createLayoutPlugin } from "../plugins/plugins/layout.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((id, data) => {
|
|
17
|
+
const node = nodes.value.find((n) => n.id === id);
|
|
18
|
+
if (node) Object.assign(node, data);
|
|
19
|
+
}),
|
|
20
|
+
getNode: vi.fn((id) => nodes.value.find((n) => n.id === id)),
|
|
21
|
+
addEdge: vi.fn(),
|
|
22
|
+
removeEdge: vi.fn(),
|
|
23
|
+
updateEdge: vi.fn(),
|
|
24
|
+
getEdge: vi.fn(),
|
|
25
|
+
setViewport: vi.fn(),
|
|
26
|
+
fitView: vi.fn(),
|
|
27
|
+
zoomIn: vi.fn(),
|
|
28
|
+
zoomOut: vi.fn(),
|
|
29
|
+
centerView: vi.fn(),
|
|
30
|
+
selectNode: vi.fn(),
|
|
31
|
+
selectEdge: vi.fn(),
|
|
32
|
+
clearSelection: vi.fn(),
|
|
33
|
+
getNodes: vi.fn(() => nodes.value),
|
|
34
|
+
getEdges: vi.fn(() => edges.value),
|
|
35
|
+
getViewport: vi.fn(() => viewport.value),
|
|
36
|
+
screenToCanvas: vi.fn((x, y) => ({ x, y })),
|
|
37
|
+
canvasToScreen: vi.fn((x, y) => ({ x, y })),
|
|
38
|
+
on: vi.fn(),
|
|
39
|
+
off: vi.fn(),
|
|
40
|
+
emit: vi.fn(),
|
|
41
|
+
isValidConnection: vi.fn(() => true),
|
|
42
|
+
$el: void 0,
|
|
43
|
+
usePlugin: vi.fn(),
|
|
44
|
+
removePlugin: vi.fn()
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
describe("flow/plugins/plugins/layout", () => {
|
|
48
|
+
describe("LayoutOptions", () => {
|
|
49
|
+
it("should have correct default options", () => {
|
|
50
|
+
const plugin = createLayoutPlugin();
|
|
51
|
+
const flow = createMockFlowInstance();
|
|
52
|
+
plugin.install(flow);
|
|
53
|
+
expect(flow.applyLayout).toBeDefined();
|
|
54
|
+
});
|
|
55
|
+
it("should support dagre layout type", () => {
|
|
56
|
+
const plugin = createLayoutPlugin({ type: "dagre" });
|
|
57
|
+
expect(plugin.id).toBe("layout");
|
|
58
|
+
expect(plugin.name).toBe("Layout");
|
|
59
|
+
});
|
|
60
|
+
it("should support elk layout type", () => {
|
|
61
|
+
const plugin = createLayoutPlugin({ type: "elk" });
|
|
62
|
+
expect(plugin.id).toBe("layout");
|
|
63
|
+
expect(plugin.name).toBe("Layout");
|
|
64
|
+
});
|
|
65
|
+
it("should support force layout type", () => {
|
|
66
|
+
const plugin = createLayoutPlugin({ type: "force" });
|
|
67
|
+
expect(plugin.id).toBe("layout");
|
|
68
|
+
expect(plugin.name).toBe("Layout");
|
|
69
|
+
});
|
|
70
|
+
it("should support grid layout type", () => {
|
|
71
|
+
const plugin = createLayoutPlugin({ type: "grid" });
|
|
72
|
+
expect(plugin.id).toBe("layout");
|
|
73
|
+
expect(plugin.name).toBe("Layout");
|
|
74
|
+
});
|
|
75
|
+
it("should accept direction option TB", () => {
|
|
76
|
+
const plugin = createLayoutPlugin({ direction: "TB" });
|
|
77
|
+
expect(plugin.id).toBe("layout");
|
|
78
|
+
});
|
|
79
|
+
it("should accept direction option LR", () => {
|
|
80
|
+
const plugin = createLayoutPlugin({ direction: "LR" });
|
|
81
|
+
expect(plugin.id).toBe("layout");
|
|
82
|
+
});
|
|
83
|
+
it("should accept node spacing option", () => {
|
|
84
|
+
const plugin = createLayoutPlugin({ nodeSpacing: 100 });
|
|
85
|
+
expect(plugin.id).toBe("layout");
|
|
86
|
+
});
|
|
87
|
+
it("should accept rank spacing option", () => {
|
|
88
|
+
const plugin = createLayoutPlugin({ rankSpacing: 150 });
|
|
89
|
+
expect(plugin.id).toBe("layout");
|
|
90
|
+
});
|
|
91
|
+
it("should accept elk options", () => {
|
|
92
|
+
const plugin = createLayoutPlugin({
|
|
93
|
+
type: "elk",
|
|
94
|
+
elkOptions: {
|
|
95
|
+
algorithm: "layered",
|
|
96
|
+
direction: "DOWN",
|
|
97
|
+
spacing: 50,
|
|
98
|
+
edgeRouting: "POLYLINE"
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
expect(plugin.id).toBe("layout");
|
|
102
|
+
});
|
|
103
|
+
it("should accept force options", () => {
|
|
104
|
+
const plugin = createLayoutPlugin({
|
|
105
|
+
type: "force",
|
|
106
|
+
forceOptions: {
|
|
107
|
+
strength: -500,
|
|
108
|
+
distance: 200,
|
|
109
|
+
iterations: 500
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
expect(plugin.id).toBe("layout");
|
|
113
|
+
});
|
|
114
|
+
it("should accept grid options", () => {
|
|
115
|
+
const plugin = createLayoutPlugin({
|
|
116
|
+
type: "grid",
|
|
117
|
+
gridOptions: {
|
|
118
|
+
columns: 3,
|
|
119
|
+
startX: 100,
|
|
120
|
+
startY: 100
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
expect(plugin.id).toBe("layout");
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe("Layout execution", () => {
|
|
127
|
+
it("should add applyLayout method to flow instance", () => {
|
|
128
|
+
const plugin = createLayoutPlugin();
|
|
129
|
+
const flow = createMockFlowInstance();
|
|
130
|
+
plugin.install(flow);
|
|
131
|
+
expect(typeof flow.applyLayout).toBe("function");
|
|
132
|
+
});
|
|
133
|
+
it("should return function when calling applyLayout", async () => {
|
|
134
|
+
const plugin = createLayoutPlugin({ type: "dagre" });
|
|
135
|
+
const flow = createMockFlowInstance();
|
|
136
|
+
flow.nodes.value = [
|
|
137
|
+
{
|
|
138
|
+
id: "1",
|
|
139
|
+
type: "default",
|
|
140
|
+
position: { x: 0, y: 0 },
|
|
141
|
+
data: { label: "Node 1" },
|
|
142
|
+
width: 150,
|
|
143
|
+
height: 50
|
|
144
|
+
}
|
|
145
|
+
];
|
|
146
|
+
flow.edges.value = [];
|
|
147
|
+
plugin.install(flow);
|
|
148
|
+
const result = flow.applyLayout({ type: "dagre" });
|
|
149
|
+
expect(result === void 0 || result instanceof Promise).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
describe("LayoutOptions interface", () => {
|
|
153
|
+
it("should validate LayoutOptions type field accepts dagre", () => {
|
|
154
|
+
const options = { type: "dagre" };
|
|
155
|
+
expect(options.type).toBe("dagre");
|
|
156
|
+
});
|
|
157
|
+
it("should validate LayoutOptions type field accepts elk", () => {
|
|
158
|
+
const options = { type: "elk" };
|
|
159
|
+
expect(options.type).toBe("elk");
|
|
160
|
+
});
|
|
161
|
+
it("should validate LayoutOptions type field accepts force", () => {
|
|
162
|
+
const options = { type: "force" };
|
|
163
|
+
expect(options.type).toBe("force");
|
|
164
|
+
});
|
|
165
|
+
it("should validate LayoutOptions type field accepts grid", () => {
|
|
166
|
+
const options = { type: "grid" };
|
|
167
|
+
expect(options.type).toBe("grid");
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|