BasicToolbar.vue
1.67 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
<script lang="ts" setup>
import { Icon } from '/@/components/Icon';
import { NodeProps, Position } from '@vue-flow/core';
import { NodeToolbar } from '@vue-flow/node-toolbar';
import { computed, toRaw, unref } from 'vue';
import { useFlowContext } from '../../../hook/useFlowContext';
import type { NodeData } from '../../../types/node';
import { ElementsTypeEnum } from '../../../enum';
const props = defineProps<NodeProps>();
const getData = computed(() => props.data as NodeData);
const { updateNodeDrawerActionType, flowActionType } = useFlowContext();
const handleOpenEdit = async () => {
const { flag, data } =
(await unref(updateNodeDrawerActionType)?.open(toRaw(unref(getData)), void 0, {
id: props.id,
type: ElementsTypeEnum.NODE,
})) || {};
if (!flag) return;
const currentNode = flowActionType?.findNode(props.id);
(currentNode!.data as NodeData).data = data;
};
const handleDelete = () => {
flowActionType?.removeNodes(props.id);
};
</script>
<template>
<NodeToolbar :is-visible="data.toolbarVisible" :position="Position.Top" align="end" :offset="2">
<section class="flex gap-1 transform translate-y-1">
<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>
</section>
</NodeToolbar>
</template>