|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import type { DevframeDockEntry, DevframeViewGroup } from '@devframes/hub' |
3 | 3 | import type { DocksContext } from '@devframes/hub/client' |
4 | | -import { useElementBounding, watchDebounced } from '@vueuse/core' |
5 | | -import { computed, h, ref, useTemplateRef } from 'vue' |
| 4 | +import { watchDebounced } from '@vueuse/core' |
| 5 | +import { computed, h, ref, useTemplateRef, watch } from 'vue' |
6 | 6 | import { deriveSidebarCapacity, docksSplitGroupsWithCapacity, getGroupMembersGrouped } from '../../state/dock-settings' |
7 | 7 | import { sharedStateToRef } from '../../state/docks' |
8 | 8 | import { setDocksSidebarOverflowPanel, setFloatingTooltip, useDocksSidebarOverflowPanel } from '../../state/floating-tooltip' |
@@ -36,7 +36,29 @@ const memberGroups = computed(() => getGroupMembersGrouped( |
36 | 36 | )) |
37 | 37 |
|
38 | 38 | const sidebar = useTemplateRef<HTMLDivElement>('sidebar') |
39 | | -const { height: frameHeight } = useElementBounding(sidebar) |
| 39 | +
|
| 40 | +// Bind the ResizeObserver via the sidebar element's own document/window |
| 41 | +// rather than a global one: in popup dock mode the sidebar renders inside |
| 42 | +// the popup's own realm, and `useElementBounding`'s window-level resize |
| 43 | +// listener only fires for the host page, so the rail wouldn't collapse or |
| 44 | +// restore until the mouse moved back into the host page. |
| 45 | +const frameHeight = ref(0) |
| 46 | +watch(sidebar, (el, _prev, onCleanup) => { |
| 47 | + if (!el) { |
| 48 | + frameHeight.value = 0 |
| 49 | + return |
| 50 | + } |
| 51 | + const ResizeObserverCtor = el.ownerDocument?.defaultView?.ResizeObserver ?? globalThis.ResizeObserver |
| 52 | + if (!ResizeObserverCtor) |
| 53 | + return |
| 54 | + const observer = new ResizeObserverCtor(([entry]) => { |
| 55 | + if (!entry) |
| 56 | + return |
| 57 | + frameHeight.value = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height |
| 58 | + }) |
| 59 | + observer.observe(el) |
| 60 | + onCleanup(() => observer.disconnect()) |
| 61 | +}, { immediate: true, flush: 'post' }) |
40 | 62 |
|
41 | 63 | const totalItems = computed(() => memberGroups.value.reduce((acc, [, items]) => acc + items.length, 0)) |
42 | 64 |
|
|
0 commit comments