Skip to content

Commit 619de37

Browse files
committed
fix: panel dragging issue, close #874, close #871, close #873
1 parent 8d2ca01 commit 619de37

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

packages/devtools/client/app.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { useRoute } from '#app/composables/router'
3-
import { useHead } from '@unhead/vue'
3+
import { useHead } from '#imports'
44
import { useEventListener, useEyeDropper } from '@vueuse/core'
55
import { computed, onMounted, watch, watchEffect } from 'vue'
66
import { getColorMode, showConnectionWarning, useClient, useInjectionClient } from '~/composables/client'

packages/devtools/src/webcomponents/components/NuxtDevtoolsFrame.vue

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { DevToolsFrameState, NuxtDevtoolsHostClient, NuxtDevToolsOptions } from '@nuxt/devtools/types'
33
import type { CSSProperties } from 'vue'
44
import { toRefs, useElementBounding, useEventListener, useScreenSafeArea } from '@vueuse/core'
5-
import { computed, onMounted, reactive, ref, watchEffect } from 'vue'
5+
import { computed, onMounted, reactive, ref, useTemplateRef, watchEffect } from 'vue'
66
import FrameBox from './NuxtDevtoolsFrameBox.vue'
77
88
const props = defineProps<{
@@ -38,11 +38,18 @@ const panelMargins = reactive({
3838
const safeArea = useScreenSafeArea()
3939
const isSafari = navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome')
4040
41+
function toNumber(value: string) {
42+
const num = +value
43+
if (Number.isNaN(num))
44+
return 0
45+
return num
46+
}
47+
4148
watchEffect(() => {
42-
panelMargins.left = +safeArea.left.value + 10
43-
panelMargins.top = +safeArea.top.value + 10
44-
panelMargins.right = +safeArea.right.value + 10
45-
panelMargins.bottom = +safeArea.bottom.value + 10
49+
panelMargins.left = toNumber(safeArea.left.value) + 10
50+
panelMargins.top = toNumber(safeArea.top.value) + 10
51+
panelMargins.right = toNumber(safeArea.right.value) + 10
52+
panelMargins.bottom = toNumber(safeArea.bottom.value) + 10
4653
})
4754
4855
const SNAP_THRESHOLD = 2
@@ -57,11 +64,14 @@ const vars = computed(() => {
5764
}
5865
})
5966
60-
const frameBox = ref<HTMLDivElement>()
61-
const panelEl = ref<HTMLDivElement>()
62-
const anchorEl = ref<HTMLDivElement>()
67+
const frameBox = useTemplateRef<HTMLDivElement>('frameBox')
68+
const panelEl = useTemplateRef<HTMLDivElement>('panelEl')
69+
const anchorEl = useTemplateRef<HTMLDivElement>('anchorEl')
6370
64-
const windowSize = reactive({ width: 0, height: 0 })
71+
const windowSize = reactive({
72+
width: window.innerWidth,
73+
height: window.innerHeight,
74+
})
6575
const isDragging = ref(false)
6676
const draggingOffset = reactive({ x: 0, y: 0 })
6777
const mousePosition = reactive({ x: 0, y: 0 })
@@ -88,22 +98,25 @@ onMounted(() => {
8898
if (!isDragging.value)
8999
return
90100
91-
const centerX = windowSize.width / 2
92-
const centerY = windowSize.height / 2
101+
const centerX = window.innerWidth / 2
102+
const centerY = window.innerHeight / 2
93103
94104
const x = e.clientX - draggingOffset.x
95105
const y = e.clientY - draggingOffset.y
96106
107+
if (Number.isNaN(x) || Number.isNaN(y))
108+
return
109+
97110
mousePosition.x = x
98111
mousePosition.y = y
99112
100113
// Get position
101114
const deg = Math.atan2(y - centerY, x - centerX)
102115
const HORIZONTAL_MARGIN = 70
103116
const TL = Math.atan2(0 - centerY + HORIZONTAL_MARGIN, 0 - centerX)
104-
const TR = Math.atan2(0 - centerY + HORIZONTAL_MARGIN, windowSize.width - centerX)
105-
const BL = Math.atan2(windowSize.height - HORIZONTAL_MARGIN - centerY, 0 - centerX)
106-
const BR = Math.atan2(windowSize.height - HORIZONTAL_MARGIN - centerY, windowSize.width - centerX)
117+
const TR = Math.atan2(0 - centerY + HORIZONTAL_MARGIN, window.innerWidth - centerX)
118+
const BL = Math.atan2(window.innerHeight - HORIZONTAL_MARGIN - centerY, 0 - centerX)
119+
const BR = Math.atan2(window.innerHeight - HORIZONTAL_MARGIN - centerY, window.innerWidth - centerX)
107120
108121
state.value.position = deg >= TL && deg <= TR
109122
? 'top'
@@ -113,8 +126,8 @@ onMounted(() => {
113126
? 'bottom'
114127
: 'left'
115128
116-
state.value.left = snapToPoints(x / windowSize.width * 100)
117-
state.value.top = snapToPoints(y / windowSize.height * 100)
129+
state.value.left = snapToPoints(x / window.innerWidth * 100)
130+
state.value.top = snapToPoints(y / window.innerHeight * 100)
118131
})
119132
useEventListener(window, 'pointerup', () => {
120133
isDragging.value = false

0 commit comments

Comments
 (0)