Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions packages/hub-ui/src/client/components/dock/Dock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import type { DocksContext } from '@devframes/hub/client'
import type { CSSProperties } from 'vue'
import type { DockLayout } from './dock-layout'
import { useEventListener, useScreenSafeArea, whenever } from '@vueuse/core'
import { useEventListener, whenever } from '@vueuse/core'
import { computed, onMounted, reactive, ref, useTemplateRef, watch } from 'vue'
import { BUILTIN_ENTRY_CLIENT_AUTH_NOTICE } from '../../constants'
import { t } from '../../i18n'
import { docksSplitGroupsWithCapacity, getEntryGroup, resolveNextRecentDockIds, resolveRecentDockEntries } from '../../state/dock-settings'
import { setDocksOverflowPanel, useDocksGroupPanel } from '../../state/floating-tooltip'
import { useSettings } from '../../state/settings-defaults'
import { useIsRpcTrusted } from '../../utils/useIsRpcTrusted'
import { useSafeArea } from '../../utils/useSafeArea'
import BrandMark from '../icons/BrandMark.vue'
import {
dockLayoutCssVars,
Expand Down Expand Up @@ -39,29 +40,15 @@ const layout = computed(() => resolveDockLayout(props.layout))

const isSafari = navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome')

const safeArea = useScreenSafeArea()
const anchorEl = useTemplateRef<HTMLDivElement>('anchorEl')

function toNumber(value: string) {
const num = +value
if (Number.isNaN(num))
return 0
return num
}
const safeArea = useSafeArea(anchorEl)

// Effective spacing from the viewport edge: device safe-area insets plus the
// configured viewport margin. Passed down to the panel so both stay in sync.
const panelMargins = computed(() => resolveViewportMargins(
{
left: toNumber(safeArea.left.value),
top: toNumber(safeArea.top.value),
right: toNumber(safeArea.right.value),
bottom: toNumber(safeArea.bottom.value),
},
layout.value,
))
const panelMargins = computed(() => resolveViewportMargins(safeArea.value, layout.value))

const dockEl = useTemplateRef<HTMLDivElement>('dockEl')
const anchorEl = useTemplateRef<HTMLDivElement>('anchorEl')

const recalculateCounter = ref(0)
const isHovering = ref(false)
Expand Down
4 changes: 4 additions & 0 deletions packages/hub-ui/src/client/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
--app-scrollbar-radius: 1px;
--app-scrollbar-thumb: #8884;
--app-scrollbar-thumb-hover: #8885;
--devframes-safe-area-top: env(safe-area-inset-top, 0px);
--devframes-safe-area-right: env(safe-area-inset-right, 0px);
--devframes-safe-area-bottom: env(safe-area-inset-bottom, 0px);
--devframes-safe-area-left: env(safe-area-inset-left, 0px);
}

::-webkit-scrollbar {
Expand Down
36 changes: 36 additions & 0 deletions packages/hub-ui/src/client/utils/useSafeArea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { MaybeElementRef } from '@vueuse/core'
import type { DockMargins } from '../components/dock/dock-layout'
import { tryOnMounted, unrefElement, useDebounceFn, useEventListener } from '@vueuse/core'
import { shallowRef } from 'vue'

/**
* Ported from VueUse's `useScreenSafeArea` for now: it always sets its CSS variables on
* `<html>` and has no option for a custom element, which breaks hydration on SSR hosts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antfu I wasn't sure about this part, so I added this "port" to suggest whether this addition should be added to VueUse, didn't want to make too many decisions, do let me know if this is even a good direction, or:

  1. Port back the fix to VueUse
  2. Remove the safeArea usage all together? probably not
  3. Close PR and accept the warning and have the users manually import the Dock

* Reads the `--devframes-safe-area-*` variables (see `style.css`) from `target`, in px.
*/
export function useSafeArea(target: MaybeElementRef) {
const insets = shallowRef<DockMargins>({ top: 0, right: 0, bottom: 0, left: 0 })

function read(style: CSSStyleDeclaration, side: keyof DockMargins) {
// The computed value is a length such as `34px`, so parse it as a float.
return Number.parseFloat(style.getPropertyValue(`--devframes-safe-area-${side}`)) || 0
}

function update() {
const element = unrefElement(target)
if (!element)
return
const style = getComputedStyle(element)
insets.value = {
top: read(style, 'top'),
right: read(style, 'right'),
bottom: read(style, 'bottom'),
left: read(style, 'left'),
}
}

tryOnMounted(update)
useEventListener('resize', useDebounceFn(update), { passive: true })

return insets
}
Loading