Profectus/src/components/system/LinkNode.vue

41 lines
1,005 B
Vue
Raw Normal View History

2022-01-13 22:25:47 -06:00
<template>
<div class="branch" ref="node"></div>
</template>
<script setup lang="ts">
import { RegisterLinkNodeInjectionKey, UnregisterLinkNodeInjectionKey } from "@/features/links";
import { computed, inject, ref, toRefs, unref, watch } from "vue";
2022-01-24 22:25:34 -06:00
const _props = defineProps<{ id: string }>();
const props = toRefs(_props);
2022-01-13 22:25:47 -06:00
const register = inject(RegisterLinkNodeInjectionKey);
const unregister = inject(UnregisterLinkNodeInjectionKey);
const node = ref<HTMLElement | null>(null);
const parentNode = computed(() => node.value && node.value.parentElement);
if (register && unregister) {
watch([parentNode, props.id], ([newNode, newID], [prevNode, prevID]) => {
if (prevNode) {
unregister(unref(prevID));
}
if (newNode) {
register(newID, newNode);
}
});
}
</script>
<style scoped>
.branch {
position: absolute;
z-index: -10;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
</style>