-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf128f1
commit 5cbc4e9
Showing
9 changed files
with
745 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { vueflow } from "@/router/enums"; | ||
|
||
export default { | ||
path: "/vue-flow", | ||
redirect: "/vue-flow/index", | ||
meta: { | ||
icon: "ep:set-up", | ||
title: "vue-flow", | ||
rank: vueflow | ||
}, | ||
children: [ | ||
{ | ||
path: "/vue-flow/index", | ||
name: "VueFlow", | ||
component: () => import("@/views/vue-flow/layouting/index.vue"), | ||
meta: { | ||
title: "vue-flow" | ||
} | ||
} | ||
] | ||
} satisfies RouteConfigsTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<script setup lang="ts"> | ||
import type { EdgeProps } from "@vue-flow/core"; | ||
import { ref, toRef, computed, watch } from "vue"; | ||
import { TransitionPresets, executeTransition } from "@vueuse/core"; | ||
import { | ||
BaseEdge, | ||
EdgeLabelRenderer, | ||
getSmoothStepPath, | ||
useNodesData | ||
} from "@vue-flow/core"; | ||
const props = defineProps<EdgeProps>(); | ||
const edgePoint = ref(0); | ||
const sourceNodeData = useNodesData(() => props.source); | ||
const isFinished = toRef(() => sourceNodeData.value.isFinished); | ||
const isAnimating = ref(false); | ||
const edgeColor = toRef(() => { | ||
if (sourceNodeData.value.hasError) { | ||
return "#f87171"; | ||
} | ||
if (sourceNodeData.value.isFinished) { | ||
return "#10b981"; | ||
} | ||
if (sourceNodeData.value.isCancelled) { | ||
return "#fbbf24"; | ||
} | ||
if (sourceNodeData.value.isSkipped) { | ||
return "#f59e0b"; | ||
} | ||
return "#6b7280"; | ||
}); | ||
const edgeRef = ref<InstanceType<typeof BaseEdge>>(); | ||
const circlePosition = ref({ x: 0, y: 0 }); | ||
const currentLength = ref(0); | ||
const path = computed(() => getSmoothStepPath(props)); | ||
watch(edgePoint, point => { | ||
const pathEl = edgeRef.value?.pathEl; | ||
if (!pathEl || point === 0) { | ||
return; | ||
} | ||
const currLength = pathEl.getTotalLength(); | ||
if (currentLength.value !== currLength) { | ||
return runAnimation(); | ||
} | ||
circlePosition.value = pathEl.getPointAtLength(point); | ||
}); | ||
watch(isFinished, async (isFinished, _, onCleanup) => { | ||
if (isFinished) { | ||
await runAnimation(); | ||
edgePoint.value = 0; | ||
currentLength.value = 0; | ||
circlePosition.value = { x: 0, y: 0 }; | ||
} | ||
}); | ||
async function runAnimation() { | ||
const pathEl = edgeRef.value?.pathEl; | ||
if (!pathEl) { | ||
return; | ||
} | ||
isAnimating.value = true; | ||
const totalLength = pathEl.getTotalLength(); | ||
const from = edgePoint.value || 0; | ||
if (currentLength.value !== totalLength) { | ||
currentLength.value = totalLength; | ||
} | ||
await executeTransition(edgePoint, from, totalLength, { | ||
transition: TransitionPresets.easeInOutCubic | ||
}); | ||
isAnimating.value = false; | ||
} | ||
</script> | ||
|
||
<template> | ||
<BaseEdge | ||
v-bind="$attrs" | ||
:id="id" | ||
ref="edgeRef" | ||
:path="path[0]" | ||
:marker-end="markerEnd" | ||
:style="{ stroke: edgeColor }" | ||
/> | ||
|
||
<EdgeLabelRenderer v-if="isAnimating"> | ||
<div | ||
:style="{ | ||
position: 'absolute', | ||
transform: `translate(-50%, -50%) translate(${circlePosition.x}px,${circlePosition.y}px)`, | ||
pointerEvents: 'all' | ||
}" | ||
class="nodrag nopan" | ||
> | ||
📦 | ||
</div> | ||
</EdgeLabelRenderer> | ||
</template> |
Oops, something went wrong.