|
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' |
2 | 2 | import { until, useVModel } from '@vueuse/core'
|
3 | 3 | import {
|
4 | 4 | ARIA_NODE_DESC_KEY,
|
@@ -76,6 +76,7 @@ const NodeWrapper = defineComponent({
|
76 | 76 | selectable: () => props.selectable,
|
77 | 77 | dragHandle: () => node.value.dragHandle,
|
78 | 78 | onStart(args) {
|
| 79 | + // todo: remove intersections from here - they are not needed and only reduce performance |
79 | 80 | emit.dragStart({ ...args, intersections: getIntersectingNodes(node.value) })
|
80 | 81 | },
|
81 | 82 | onDrag(args) {
|
@@ -114,11 +115,21 @@ const NodeWrapper = defineComponent({
|
114 | 115 | })
|
115 | 116 |
|
116 | 117 | 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 | + ) |
122 | 133 | })
|
123 | 134 |
|
124 | 135 | watch([() => node.value.type, () => node.value.sourcePosition, () => node.value.targetPosition], () => {
|
@@ -180,8 +191,12 @@ const NodeWrapper = defineComponent({
|
180 | 191 | clampPosition()
|
181 | 192 | }
|
182 | 193 |
|
183 |
| - return () => |
184 |
| - h( |
| 194 | + return () => { |
| 195 | + if (node.value.hidden) { |
| 196 | + return null |
| 197 | + } |
| 198 | + |
| 199 | + return h( |
185 | 200 | 'div',
|
186 | 201 | {
|
187 | 202 | 'ref': nodeElement,
|
@@ -243,7 +258,7 @@ const NodeWrapper = defineComponent({
|
243 | 258 | }),
|
244 | 259 | ],
|
245 | 260 | )
|
246 |
| - |
| 261 | + } |
247 | 262 | /** this re-calculates the current position, necessary for clamping by a node's extent */
|
248 | 263 | function clampPosition() {
|
249 | 264 | const nextPos = node.value.computedPosition
|
|
0 commit comments