Skip to content

Commit 3498399

Browse files
committed
refactor(core): render null if node is hidden
1 parent ea45545 commit 3498399

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

packages/core/src/components/Nodes/NodeWrapper.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { computed, defineComponent, h, nextTick, onBeforeUnmount, onMounted, provide, ref, toRef, watch } from 'vue'
1+
import { computed, defineComponent, h, nextTick, onMounted, provide, ref, toRef, watch } from 'vue'
22
import { until, useVModel } from '@vueuse/core'
33
import {
44
ARIA_NODE_DESC_KEY,
@@ -76,6 +76,7 @@ const NodeWrapper = defineComponent({
7676
selectable: () => props.selectable,
7777
dragHandle: () => node.value.dragHandle,
7878
onStart(args) {
79+
// todo: remove intersections from here - they are not needed and only reduce performance
7980
emit.dragStart({ ...args, intersections: getIntersectingNodes(node.value) })
8081
},
8182
onDrag(args) {
@@ -114,11 +115,21 @@ const NodeWrapper = defineComponent({
114115
})
115116

116117
onMounted(() => {
117-
props.resizeObserver.observe(nodeElement.value as HTMLDivElement)
118-
})
119-
120-
onBeforeUnmount(() => {
121-
props.resizeObserver.unobserve(nodeElement.value as HTMLDivElement)
118+
watch(
119+
() => node.value.hidden,
120+
(isHidden = false, _, onCleanup) => {
121+
if (!isHidden && nodeElement.value) {
122+
props.resizeObserver.observe(nodeElement.value)
123+
124+
onCleanup(() => {
125+
if (nodeElement.value) {
126+
props.resizeObserver.unobserve(nodeElement.value)
127+
}
128+
})
129+
}
130+
},
131+
{ immediate: true, flush: 'post' },
132+
)
122133
})
123134

124135
watch([() => node.value.type, () => node.value.sourcePosition, () => node.value.targetPosition], () => {
@@ -180,8 +191,12 @@ const NodeWrapper = defineComponent({
180191
clampPosition()
181192
}
182193

183-
return () =>
184-
h(
194+
return () => {
195+
if (node.value.hidden) {
196+
return null
197+
}
198+
199+
return h(
185200
'div',
186201
{
187202
'ref': nodeElement,
@@ -243,7 +258,7 @@ const NodeWrapper = defineComponent({
243258
}),
244259
],
245260
)
246-
261+
}
247262
/** this re-calculates the current position, necessary for clamping by a node's extent */
248263
function clampPosition() {
249264
const nextPos = node.value.computedPosition

0 commit comments

Comments
 (0)