11<script setup lang="ts">
2- import type { DockContext } from ' ../state/dock'
2+ import type { DocksContext } from ' ../state/dock'
33import { useEventListener , useScreenSafeArea } from ' @vueuse/core'
44import { computed , onMounted , reactive , ref , useTemplateRef , watchEffect } from ' vue'
55import { useStateHandlers } from ' ../state/state'
@@ -10,7 +10,7 @@ import VitePlusCore from './icons/VitePlusCore.vue'
1010
1111// Here we directly destructure is as we don't expect context to be changed
1212const props = defineProps <{
13- context: DockContext
13+ context: DocksContext
1414}>()
1515const context = props .context
1616
@@ -76,6 +76,7 @@ onMounted(() => {
7676 if (! isDragging .value )
7777 return
7878
79+ const store = context .panel .store
7980 const centerX = window .innerWidth / 2
8081 const centerY = window .innerHeight / 2
8182
@@ -96,16 +97,16 @@ onMounted(() => {
9697 const BL = Math .atan2 (window .innerHeight - HORIZONTAL_MARGIN - centerY , 0 - centerX )
9798 const BR = Math .atan2 (window .innerHeight - HORIZONTAL_MARGIN - centerY , window .innerWidth - centerX )
9899
99- context . state .position = deg >= TL && deg <= TR
100+ store .position = deg >= TL && deg <= TR
100101 ? ' top'
101102 : deg >= TR && deg <= BR
102103 ? ' right'
103104 : deg >= BR && deg <= BL
104105 ? ' bottom'
105106 : ' left'
106107
107- context . state .left = snapToPoints (x / window .innerWidth * 100 )
108- context . state .top = snapToPoints (y / window .innerHeight * 100 )
108+ store .left = snapToPoints (x / window .innerWidth * 100 )
109+ store .top = snapToPoints (y / window .innerHeight * 100 )
109110 })
110111 useEventListener (window , ' pointerup' , () => {
111112 isDragging .value = false
@@ -131,19 +132,20 @@ function clamp(value: number, min: number, max: number) {
131132
132133const recalculateCounter = ref (0 )
133134const isHovering = ref (false )
134- const isVertical = computed (() => context .state .position === ' left' || context .state .position === ' right' )
135135
136136const anchorPos = computed (() => {
137137 // eslint-disable-next-line ts/no-unused-expressions
138138 recalculateCounter .value
139139
140+ const store = context .panel .store
141+
140142 const halfWidth = (dockEl .value ?.clientWidth || 0 ) / 2
141143 const halfHeight = (dockEl .value ?.clientHeight || 0 ) / 2
142144
143- const left = context . state .left * windowSize .width / 100
144- const top = context . state .top * windowSize .height / 100
145+ const left = store .left * windowSize .width / 100
146+ const top = store .top * windowSize .height / 100
145147
146- switch (context . state .position ) {
148+ switch (store .position ) {
147149 case ' top' :
148150 return {
149151 left: clamp (left , halfWidth + panelMargins .left , windowSize .width - halfWidth - panelMargins .right ),
@@ -171,29 +173,29 @@ const anchorPos = computed(() => {
171173let _timer: ReturnType <typeof setTimeout > | null = null
172174function bringUp() {
173175 isHovering .value = true
174- if (context .state . minimizePanelInactive < 0 )
176+ if (context .panel . store . inactiveTimeout < 0 )
175177 return
176178 if (_timer )
177179 clearTimeout (_timer )
178180 _timer = setTimeout (() => {
179181 isHovering .value = false
180- }, + context .state . minimizePanelInactive || 0 )
182+ }, + context .panel . store . inactiveTimeout || 0 )
181183}
182184
183185const isHidden = computed (() => false )
184186
185187const isMinimized = computed (() => {
186- if (context .state . minimizePanelInactive < 0 )
188+ if (context .panel . store . inactiveTimeout < 0 )
187189 return false
188- if (context .state . minimizePanelInactive === 0 )
190+ if (context .panel . store . inactiveTimeout === 0 )
189191 return true
190192 // @ts-expect-error compatibility
191193 const isTouchDevice = ' ontouchstart' in window || navigator .maxTouchPoints > 0 || navigator .msMaxTouchPoints > 0
192194 return ! isDragging .value
193- && ! context .state .open
195+ && ! context .panel . store .open
194196 && ! isHovering .value
195197 && ! isTouchDevice
196- && context .state . minimizePanelInactive
198+ && context .panel . store . inactiveTimeout
197199})
198200
199201const anchorStyle = computed (() => {
@@ -206,7 +208,7 @@ const anchorStyle = computed(() => {
206208
207209const panelStyle = computed (() => {
208210 const style: any = {
209- transform: isVertical . value
211+ transform: context . panel . isVertical
210212 ? ` translate(-50%, -50%) rotate(90deg) `
211213 : ` translate(-50%, -50%) ` ,
212214 }
@@ -233,8 +235,8 @@ onMounted(() => {
233235 ref =" anchorEl"
234236 :style =" [anchorStyle]"
235237 :class =" {
236- 'vite-devtools-horizontal': !isVertical,
237- 'vite-devtools-vertical': isVertical,
238+ 'vite-devtools-horizontal': !context.panel. isVertical,
239+ 'vite-devtools-vertical': context.panel. isVertical,
238240 'vite-devtools-minimized': isMinimized,
239241 }"
240242 @mousemove =" bringUp"
@@ -258,7 +260,7 @@ onMounted(() => {
258260 />
259261 <BracketRight
260262 class =" vite-devtools-dock-bracket absolute right--1 top-1/2 translate-y--1/2 bottom-0 w-2.5 op75 transition-opacity duration-300"
261- :class =" isVertical ? 'scale-y--100' : ''"
263+ :class =" context.panel. isVertical ? 'scale-y--100' : ''"
262264 />
263265 <VitePlusCore
264266 class =" w-3 h-3 absolute left-1/2 top-1/2 translate-x--1/2 translate-y--1/2 transition-opacity duration-300"
@@ -268,7 +270,7 @@ onMounted(() => {
268270 :entries =" context.dockEntries"
269271 class =" transition duration-200 flex items-center w-full h-full justify-center"
270272 :class =" isMinimized ? 'opacity-0 pointer-events-none' : 'opacity-100'"
271- :is-vertical =" isVertical"
273+ :is-vertical =" context.panel. isVertical"
272274 :selected =" context.selected"
273275 @select =" selectDockEntry"
274276 />
0 commit comments