-
-
Notifications
You must be signed in to change notification settings - Fork 107
/
NodeInterface.vue
92 lines (80 loc) · 2.71 KB
/
NodeInterface.vue
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
<template>
<div :id="intf.id" ref="el" class="baklava-node-interface" :class="classes">
<div
v-if="intf.port"
class="__port"
:class="{ '--selected': temporaryConnection?.from === intf }"
@pointerover="startHover"
@pointerout="endHover"
>
<slot name="portTooltip" :show-tooltip="showTooltip">
<span v-if="showTooltip === true" class="__tooltip">
{{ ellipsis(intf.value) }}
</span>
</slot>
</div>
<component
:is="intf.component"
v-if="showComponent"
v-model="intf.value"
:node="node"
:intf="intf"
@open-sidebar="openSidebar"
/>
<span v-else class="align-middle">
{{ intf.name }}
</span>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, onUpdated, Ref, ref } from "vue";
import { AbstractNode, NodeInterface } from "@baklavajs/core";
import { useViewModel } from "../utility";
import { useTemporaryConnection } from "../editor/temporaryConnection";
const ellipsis = (value: any, characters = 100) => {
const stringValue: string = typeof value?.toString === "function" ? String(value) : "";
if (stringValue.length > characters) {
return stringValue.slice(0, characters) + "...";
}
return stringValue;
};
const props = defineProps<{
node: AbstractNode;
intf: NodeInterface;
}>();
const { viewModel } = useViewModel();
const { hoveredOver, temporaryConnection } = useTemporaryConnection();
const el = ref<HTMLElement | null>(null) as Ref<HTMLElement>;
const isConnected = computed(() => props.intf.connectionCount > 0);
const isHovered = ref<boolean>(false);
const showTooltip = computed(() => viewModel.value.settings.displayValueOnHover && isHovered.value);
const classes = computed(() => ({
"--input": props.intf.isInput,
"--output": !props.intf.isInput,
"--connected": isConnected.value,
}));
const showComponent = computed<boolean>(
() => props.intf.component && (!props.intf.isInput || !props.intf.port || props.intf.connectionCount === 0),
);
const startHover = () => {
isHovered.value = true;
hoveredOver(props.intf);
};
const endHover = () => {
isHovered.value = false;
hoveredOver(undefined);
};
const onRender = () => {
if (el.value) {
viewModel.value.hooks.renderInterface.execute({ intf: props.intf, el: el.value });
}
};
const openSidebar = () => {
const sidebar = viewModel.value.displayedGraph.sidebar;
sidebar.nodeId = props.node.id;
sidebar.optionName = props.intf.name;
sidebar.visible = true;
};
onMounted(onRender);
onUpdated(onRender);
</script>