Made all properties in FeatureNode non-optional
This commit is contained in:
parent
3fa7ccf0c1
commit
572e543ba8
5 changed files with 22 additions and 26 deletions
|
@ -24,11 +24,11 @@ const observerOptions = {
|
||||||
provide(RegisterNodeInjectionKey, (id, element) => {
|
provide(RegisterNodeInjectionKey, (id, element) => {
|
||||||
const observer = new MutationObserver(() => updateNode(id));
|
const observer = new MutationObserver(() => updateNode(id));
|
||||||
observer.observe(element, observerOptions);
|
observer.observe(element, observerOptions);
|
||||||
nodes.value[id] = { element, observer };
|
nodes.value[id] = { element, observer, rect: element.getBoundingClientRect() };
|
||||||
nextTick(() => updateNode(id));
|
nextTick(() => updateNode(id));
|
||||||
});
|
});
|
||||||
provide(UnregisterNodeInjectionKey, id => {
|
provide(UnregisterNodeInjectionKey, id => {
|
||||||
nodes.value[id]?.observer?.disconnect();
|
nodes.value[id]?.observer.disconnect();
|
||||||
nodes.value[id] = undefined;
|
nodes.value[id] = undefined;
|
||||||
});
|
});
|
||||||
provide(NodesInjectionKey, nodes);
|
provide(NodesInjectionKey, nodes);
|
||||||
|
|
|
@ -26,8 +26,7 @@ const props = toRefs(_props);
|
||||||
const startPosition = computed(() => {
|
const startPosition = computed(() => {
|
||||||
const rect = props.startNode.value.rect;
|
const rect = props.startNode.value.rect;
|
||||||
const boundingRect = props.boundingRect.value;
|
const boundingRect = props.boundingRect.value;
|
||||||
const position =
|
const position = boundingRect
|
||||||
rect && boundingRect
|
|
||||||
? {
|
? {
|
||||||
x: rect.x + rect.width / 2 - boundingRect.x,
|
x: rect.x + rect.width / 2 - boundingRect.x,
|
||||||
y: rect.y + rect.height / 2 - boundingRect.y
|
y: rect.y + rect.height / 2 - boundingRect.y
|
||||||
|
@ -43,8 +42,7 @@ const startPosition = computed(() => {
|
||||||
const endPosition = computed(() => {
|
const endPosition = computed(() => {
|
||||||
const rect = props.endNode.value.rect;
|
const rect = props.endNode.value.rect;
|
||||||
const boundingRect = props.boundingRect.value;
|
const boundingRect = props.boundingRect.value;
|
||||||
const position =
|
const position = boundingRect
|
||||||
rect && boundingRect
|
|
||||||
? {
|
? {
|
||||||
x: rect.x + rect.width / 2 - boundingRect.x,
|
x: rect.x + rect.width / 2 - boundingRect.x,
|
||||||
y: rect.y + rect.height / 2 - boundingRect.y
|
y: rect.y + rect.height / 2 - boundingRect.y
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Link } from "features/links/links";
|
import { Link } from "features/links/links";
|
||||||
import { NodesInjectionKey } from "game/layers";
|
import { FeatureNode, NodesInjectionKey } from "game/layers";
|
||||||
import { computed, inject, nextTick, onMounted, ref, toRef } from "vue";
|
import { computed, inject, nextTick, onMounted, ref, toRef } from "vue";
|
||||||
import LinkVue from "./Link.vue";
|
import LinkVue from "./Link.vue";
|
||||||
|
|
||||||
|
@ -43,9 +43,8 @@ function updateNodes() {
|
||||||
isDirty = false;
|
isDirty = false;
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
boundingRect.value = resizeListener.value?.getBoundingClientRect();
|
boundingRect.value = resizeListener.value?.getBoundingClientRect();
|
||||||
Object.values(nodes.value).forEach(
|
(Object.values(nodes.value) as FeatureNode[]).forEach(
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
node => (node.rect = node.element.getBoundingClientRect())
|
||||||
node => (node!.rect = node?.element.getBoundingClientRect())
|
|
||||||
);
|
);
|
||||||
isDirty = true;
|
isDirty = true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -35,7 +35,7 @@ import { Emitters } from "tsparticles-plugin-emitters/Emitters";
|
||||||
import { EmitterContainer } from "tsparticles-plugin-emitters/EmitterContainer";
|
import { EmitterContainer } from "tsparticles-plugin-emitters/EmitterContainer";
|
||||||
import { defineComponent, inject, nextTick, onMounted, PropType, ref } from "vue";
|
import { defineComponent, inject, nextTick, onMounted, PropType, ref } from "vue";
|
||||||
import { ParticlesComponent } from "particles.vue3";
|
import { ParticlesComponent } from "particles.vue3";
|
||||||
import { NodesInjectionKey } from "game/layers";
|
import { FeatureNode, NodesInjectionKey } from "game/layers";
|
||||||
|
|
||||||
// TODO get typing support on the Particles component
|
// TODO get typing support on the Particles component
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
|
@ -93,9 +93,8 @@ export default defineComponent({
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
if (resizeListener.value != null && props.onContainerResized) {
|
if (resizeListener.value != null && props.onContainerResized) {
|
||||||
// TODO don't overlap with Links.vue
|
// TODO don't overlap with Links.vue
|
||||||
Object.values(nodes.value).forEach(
|
(Object.values(nodes.value) as FeatureNode[]).forEach(
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
node => (node.rect = node.element.getBoundingClientRect())
|
||||||
node => (node!.rect = node?.element.getBoundingClientRect())
|
|
||||||
);
|
);
|
||||||
props.onContainerResized(resizeListener.value.getBoundingClientRect());
|
props.onContainerResized(resizeListener.value.getBoundingClientRect());
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,8 @@ import { persistent, PersistentRef } from "./persistence";
|
||||||
import player from "./player";
|
import player from "./player";
|
||||||
|
|
||||||
export interface FeatureNode {
|
export interface FeatureNode {
|
||||||
rect?: DOMRect;
|
rect: DOMRect;
|
||||||
observer?: MutationObserver;
|
observer: MutationObserver;
|
||||||
element: HTMLElement;
|
element: HTMLElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue