NodeItem.vue
3.56 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<script lang="ts" setup>
import { Tooltip } from 'ant-design-vue';
import { computed, ref, toRaw, unref } from 'vue';
import { EFFECT_SYMBOL, TRANSFER_DATA_KEY } from '../../../hook/useDragCreate';
import { CategoryConfigType, NodeItemConfigType } from '../../../types/node';
const props = defineProps<{
categoryConfig?: CategoryConfigType;
config?: NodeItemConfigType;
}>();
const visible = ref(false);
const getNodeDefinition = computed(() => {
const { config } = props;
const { configurationDescriptor } = config || {};
const { nodeDefinition } = configurationDescriptor || {};
return nodeDefinition || {};
});
const getHasInEnabledFlag = computed(() => unref(getNodeDefinition).inEnabled);
const getHasOutEnabledFlag = computed(() => unref(getNodeDefinition).outEnabled);
const getIcon = computed(() => {
const { icon } = unref(getNodeDefinition);
const { icon: categoryIcon } = props.categoryConfig || {};
return icon || categoryIcon || 'tabler:circuit-ground';
});
const getIconUrl = computed(() => {
const { iconUrl } = unref(getNodeDefinition);
return iconUrl;
});
const getBackgroundColor = computed(() => {
const { config, categoryConfig } = props;
const { backgroundColor } = config || {};
const { backgroundColor: categoryBackgroundColor } = categoryConfig || {};
return backgroundColor || categoryBackgroundColor;
});
const handleOnDragStart = (event: DragEvent, options: object) => {
if (event.dataTransfer) {
event.dataTransfer.setData(
TRANSFER_DATA_KEY,
JSON.stringify({ offsetX: event.offsetX, offsetY: event.offsetY, options })
);
event.dataTransfer.effectAllowed = EFFECT_SYMBOL;
}
};
const handleDragStart = (event: DragEvent) => {
visible.value = false;
handleOnDragStart(event, toRaw(unref(props)));
};
</script>
<template>
<Tooltip
v-model:visible="visible"
placement="right"
color="#fff"
trigger="hover"
:mouse-enter-delay="0.5"
overlay-class-name="!max-w-90"
>
<template #title>
<section class="text-dark-900">
<h1 class="font-bold dark:text-dark-50">
{{ config?.name }}
</h1>
<p class="italic text-gray-600">
{{ getNodeDefinition.description }}
</p>
<p v-html="getNodeDefinition.details"></p>
</section>
</template>
<main
class="node flex items-center cursor-pointer w-44 h-12 min-h-12 rounded border relative px-4 py-2 border-gray-700 z-10"
:style="{ backgroundColor: getBackgroundColor }"
:draggable="true"
@dragstart="handleDragStart"
>
<div>
<img v-if="getIconUrl" class="w-4 h-4" :src="getIconUrl" alt="" />
<Icon v-if="!getIconUrl" class="text-2xl dark:text-light-50" :icon="getIcon" />
</div>
<div class="flex flex-1 text-xs flex-col ml-2 text-left truncate">
<span class="text-gray-700 w-full truncate text-xs dark:text-light-50">
{{ config?.name }}
</span>
</div>
<div
v-if="getHasInEnabledFlag"
class="w-4 h-4 bg-gray-300 rounded-md border absolute -left-3 border-gray-500"
></div>
<div
v-if="getHasOutEnabledFlag"
class="w-4 h-4 bg-gray-300 rounded-md border absolute -right-3 border-gray-500"
></div>
</main>
</Tooltip>
</template>
<style lang="css" scoped>
.node::before {
content: '';
position: absolute;
width: 100%;
height: 100%;
left: 0;
display: none;
background-color: #00000027;
}
.node:hover::before {
display: block;
}
</style>