Profectus/src/components/Node.vue

45 lines
1.2 KiB
Vue
Raw Normal View History

2022-01-14 04:25:47 +00:00
<template>
<div class="node" ref="node"></div>
2022-01-14 04:25:47 +00:00
</template>
<script setup lang="ts">
import { RegisterNodeInjectionKey, UnregisterNodeInjectionKey } from "game/layers";
import { computed, inject, onUnmounted, ref, toRefs, unref, watch } from "vue";
2022-01-14 04:25:47 +00:00
2022-01-25 04:25:34 +00:00
const _props = defineProps<{ id: string }>();
const props = toRefs(_props);
2022-01-14 04:25:47 +00:00
// eslint-disable-next-line @typescript-eslint/no-empty-function
const register = inject(RegisterNodeInjectionKey, () => {});
// eslint-disable-next-line @typescript-eslint/no-empty-function
const unregister = inject(UnregisterNodeInjectionKey, () => {});
2022-01-14 04:25:47 +00:00
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);
}
});
onUnmounted(() => unregister(unref(props.id)));
2022-01-14 04:25:47 +00:00
}
</script>
<style scoped>
.node {
2022-01-14 04:25:47 +00:00
position: absolute;
z-index: -10;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
</style>