11<script setup lang="ts">
2- import type { DockProps } from ' ../types/DockProps '
2+ import type { DockContext } from ' ../state/dock '
33import { useEventListener , useScreenSafeArea } from ' @vueuse/core'
4- import { computed , onMounted , reactive , ref , toRefs , useTemplateRef , watchEffect } from ' vue'
4+ import { computed , onMounted , reactive , ref , useTemplateRef , watchEffect } from ' vue'
55import { useStateHandlers } from ' ../state/state'
66import DockEntries from ' ./DockEntries.vue'
77import BracketLeft from ' ./icons/BracketLeft.vue'
88import BracketRight from ' ./icons/BracketRight.vue'
99import VitePlusCore from ' ./icons/VitePlusCore.vue'
1010
11- const props = defineProps <DockProps >()
12-
13- const { state, docks } = toRefs (props )
11+ // Here we directly destructure is as we don't expect context to be changed
12+ const props = defineProps <{
13+ context: DockContext
14+ }>()
15+ const context = props .context
1416
1517const isDragging = defineModel <boolean >(' isDragging' , { default: false })
1618
@@ -94,16 +96,16 @@ onMounted(() => {
9496 const BL = Math .atan2 (window .innerHeight - HORIZONTAL_MARGIN - centerY , 0 - centerX )
9597 const BR = Math .atan2 (window .innerHeight - HORIZONTAL_MARGIN - centerY , window .innerWidth - centerX )
9698
97- state . value .position = deg >= TL && deg <= TR
99+ context . state .position = deg >= TL && deg <= TR
98100 ? ' top'
99101 : deg >= TR && deg <= BR
100102 ? ' right'
101103 : deg >= BR && deg <= BL
102104 ? ' bottom'
103105 : ' left'
104106
105- state . value .left = snapToPoints (x / window .innerWidth * 100 )
106- state . value .top = snapToPoints (y / window .innerHeight * 100 )
107+ context . state .left = snapToPoints (x / window .innerWidth * 100 )
108+ context . state .top = snapToPoints (y / window .innerHeight * 100 )
107109 })
108110 useEventListener (window , ' pointerup' , () => {
109111 isDragging .value = false
@@ -129,7 +131,7 @@ function clamp(value: number, min: number, max: number) {
129131
130132const recalculateCounter = ref (0 )
131133const isHovering = ref (false )
132- const isVertical = computed (() => state .value . position === ' left' || state . value .position === ' right' )
134+ const isVertical = computed (() => context . state .position === ' left' || context . state .position === ' right' )
133135
134136const anchorPos = computed (() => {
135137 // eslint-disable-next-line ts/no-unused-expressions
@@ -138,10 +140,10 @@ const anchorPos = computed(() => {
138140 const halfWidth = (dockEl .value ?.clientWidth || 0 ) / 2
139141 const halfHeight = (dockEl .value ?.clientHeight || 0 ) / 2
140142
141- const left = state . value .left * windowSize .width / 100
142- const top = state . value .top * windowSize .height / 100
143+ const left = context . state .left * windowSize .width / 100
144+ const top = context . state .top * windowSize .height / 100
143145
144- switch (state . value .position ) {
146+ switch (context . state .position ) {
145147 case ' top' :
146148 return {
147149 left: clamp (left , halfWidth + panelMargins .left , windowSize .width - halfWidth - panelMargins .right ),
@@ -169,29 +171,29 @@ const anchorPos = computed(() => {
169171let _timer: ReturnType <typeof setTimeout > | null = null
170172function bringUp() {
171173 isHovering .value = true
172- if (state . value .minimizePanelInactive < 0 )
174+ if (context . state .minimizePanelInactive < 0 )
173175 return
174176 if (_timer )
175177 clearTimeout (_timer )
176178 _timer = setTimeout (() => {
177179 isHovering .value = false
178- }, + state . value .minimizePanelInactive || 0 )
180+ }, + context . state .minimizePanelInactive || 0 )
179181}
180182
181183const isHidden = computed (() => false )
182184
183185const isMinimized = computed (() => {
184- if (state . value .minimizePanelInactive < 0 )
186+ if (context . state .minimizePanelInactive < 0 )
185187 return false
186- if (state . value .minimizePanelInactive === 0 )
188+ if (context . state .minimizePanelInactive === 0 )
187189 return true
188190 // @ts-expect-error compatibility
189191 const isTouchDevice = ' ontouchstart' in window || navigator .maxTouchPoints > 0 || navigator .msMaxTouchPoints > 0
190192 return ! isDragging .value
191- && ! state . value .open
193+ && ! context . state .open
192194 && ! isHovering .value
193195 && ! isTouchDevice
194- && state . value .minimizePanelInactive
196+ && context . state .minimizePanelInactive
195197})
196198
197199const anchorStyle = computed (() => {
@@ -217,7 +219,7 @@ const panelStyle = computed(() => {
217219 return style
218220})
219221
220- const { selectDockEntry } = useStateHandlers (state , docks , props . rpc , ' embedded ' )
222+ const { selectDockEntry } = useStateHandlers (context )
221223
222224onMounted (() => {
223225 bringUp ()
@@ -263,21 +265,20 @@ onMounted(() => {
263265 :class =" isMinimized ? 'op100' : 'op0'"
264266 />
265267 <DockEntries
266- :entries =" docks "
268+ :entries =" context.dockEntries "
267269 class =" transition duration-200 flex items-center w-full h-full justify-center"
268270 :class =" isMinimized ? 'opacity-0 pointer-events-none' : 'opacity-100'"
269271 :is-vertical =" isVertical"
270- :selected =" state.dockEntry "
272+ :selected =" context.selected "
271273 @select =" selectDockEntry"
272274 />
273275 </div >
274276 </div >
275277 <slot
278+ :context =" context"
276279 :dock-el =" dockEl"
280+ :selected =" context.selected"
277281 :panel-margins =" panelMargins"
278- :state =" state"
279- :is-dragging =" isDragging"
280- :entry =" state.dockEntry?.type === 'action' ? undefined : state.dockEntry"
281282 />
282283 </div >
283284</template >
0 commit comments