BasicEdge.vue
3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<script setup lang="ts">
import { BaseEdge, EdgeLabelRenderer, getBezierPath } from '@vue-flow/core';
import type { EdgeProps } from '@vue-flow/core';
import { computed, toRaw, unref } from 'vue';
import type { EdgeData, NodeData } from '../../../types/node';
import { useConnectionFocus } from '../../../hook/useConnectionFocus';
import { useFlowContext } from '../../../hook/useFlowContext';
import { useTextWidth } from '../../../hook/useTextWidth';
import { ElementsTypeEnum } from '../../../enum';
const props = defineProps<EdgeProps>();
const { flowActionType, updateEdgeDrawerActionType } = useFlowContext();
const { getMarkerEnd, getSelected } = useConnectionFocus(props);
const getData = computed(() => props.data as EdgeData);
const getLabel = computed(() => {
let { data } = unref(getData);
const type = data?.type || [];
return type.join(' / ');
});
const getLabelWidth = computed(() => useTextWidth(unref(getLabel), 14) + 10);
const path = computed(() => getBezierPath(props));
const handleOpenEdit = async () => {
if (unref(props.sourceNode.data as NodeData).config?.disableAction) return;
const { flag, data } =
(await unref(updateEdgeDrawerActionType)?.open(
toRaw(unref(props.sourceNode?.data as unknown as NodeData)),
toRaw(unref(props.data as EdgeData)),
{ id: props.id, type: ElementsTypeEnum.EDGE }
)) || {};
if (!flag) return;
const currentEdge = flowActionType.findEdge(props.id);
(currentEdge!.data as EdgeData).data = data;
};
const handleDelete = () => {
flowActionType?.removeEdges(props.id);
};
</script>
<template>
<BaseEdge
v-bind="props"
:path="path[0]"
:marker-end="getMarkerEnd"
class="dark:stroke-light-500"
:label="getLabel"
:label-x="path[1]"
:label-y="path[2]"
:label-style="{ fill: '#003a79', fontWeight: 700, fontSize: 14 }"
:label-show-bg="true"
:label-bg-style="{ fill: '#fff', stroke: '#003a79', strokeWidth: 2, width: getLabelWidth }"
:label-bg-padding="[5, 5]"
:label-bg-border-radius="10"
/>
<EdgeLabelRenderer>
<section
:style="{
pointerEvents: 'all',
position: 'absolute',
transform: `translate(0, -3rem) translate(${path[1]}px,${path[2]}px)`,
}"
class="nodrag nopan label-container relative"
>
<div
v-if="getSelected"
class="actions flex absolute gap-1 -top-full transform translate-y-1 right w-16 h-7 justify-center"
>
<div
class="border-2 rounded-1 border-light-50 bg-red-500 w-7 h-7 flex justify-center items-center cursor-pointer"
@click="handleOpenEdit"
>
<Icon icon="mdi:lead-pencil" color="#fff" />
</div>
<div
class="border-2 rounded-1 border-light-50 bg-red-500 w-7 h-7 flex justify-center items-center cursor-pointer"
@click="handleDelete"
>
<Icon icon="mdi:close" color="#fff" />
</div>
</div>
</section>
</EdgeLabelRenderer>
</template>