2022-01-14 04:25:47 +00:00
|
|
|
<template>
|
2022-03-20 18:57:45 +00:00
|
|
|
<div class="node" ref="node"></div>
|
2022-01-14 04:25:47 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2022-03-20 18:57:45 +00:00
|
|
|
import { RegisterNodeInjectionKey, UnregisterNodeInjectionKey } from "game/layers";
|
2022-02-27 19:49:34 +00:00
|
|
|
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
|
|
|
|
2022-07-08 13:44:01 +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);
|
|
|
|
}
|
|
|
|
});
|
2022-02-27 19:49:34 +00:00
|
|
|
|
|
|
|
onUnmounted(() => unregister(unref(props.id)));
|
2022-01-14 04:25:47 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
2022-03-20 18:57:45 +00:00
|
|
|
.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>
|