11import type { DevToolsDockEntry , DevToolsRpcClientFunctions } from '@vitejs/devtools-kit'
2- import type { ClientRpcReturn , DockEntryState , DockEntryStateEvents , DockPanelStorage , DocksContext } from '@vitejs/devtools-kit/client'
2+ import type { ClientRpcReturn , DockEntryState , DockEntryStateEvents , DockPanelStorage } from '@vitejs/devtools-kit/client'
33import type { Ref , ShallowRef } from 'vue'
44import { createEventEmitter } from '@vitejs/devtools-kit/utils/events'
5- import { computed , markRaw , reactive , ref , shallowRef , watch , watchEffect } from 'vue'
5+ import { markRaw , reactive , shallowRef , watch } from 'vue'
66
77export function DEFAULT_DOCK_PANEL_STORE ( ) : DockPanelStorage {
88 return {
@@ -16,7 +16,7 @@ export function DEFAULT_DOCK_PANEL_STORE(): DockPanelStorage {
1616 }
1717}
1818
19- function createDockEntryState (
19+ export function createDockEntryState (
2020 entry : DevToolsDockEntry ,
2121 selected : Ref < DevToolsDockEntry | null > ,
2222) : DockEntryState {
@@ -71,67 +71,3 @@ export async function useDocksEntries(rpcReturn: ClientRpcReturn): Promise<Ref<D
7171 await updateDocksEntries ( )
7272 return dockEntries
7373}
74-
75- let _docksContext : DocksContext | undefined
76- export async function createDocksContext (
77- clientType : 'embedded' | 'standalone' ,
78- rpcReturn : ClientRpcReturn ,
79- panelStore ?: Ref < DockPanelStorage > ,
80- ) : Promise < DocksContext > {
81- if ( _docksContext ) {
82- return _docksContext
83- }
84-
85- const selectedId = ref < string | null > ( null )
86- const dockEntries = await useDocksEntries ( rpcReturn )
87- const selected = computed ( ( ) => dockEntries . value . find ( entry => entry . id === selectedId . value ) ?? null )
88-
89- const dockEntryStateMap : Map < string , DockEntryState > = reactive ( new Map ( ) )
90- watchEffect ( ( ) => {
91- for ( const entry of dockEntries . value ) {
92- if ( dockEntryStateMap . has ( entry . id ) ) {
93- dockEntryStateMap . get ( entry . id ) ! . entryMeta = entry
94- continue
95- }
96- dockEntryStateMap . set (
97- entry . id ,
98- createDockEntryState ( entry , selected ) ,
99- )
100- }
101- } )
102-
103- panelStore ||= ref ( DEFAULT_DOCK_PANEL_STORE ( ) )
104-
105- _docksContext = reactive ( {
106- panel : {
107- store : panelStore ,
108- isDragging : false ,
109- isResizing : false ,
110- isVertical : computed ( ( ) => panelStore . value . position === 'left' || panelStore . value . position === 'right' ) ,
111- } ,
112- docks : {
113- selectedId,
114- selected,
115- entries : dockEntries ,
116- entryToStateMap : markRaw ( dockEntryStateMap ) ,
117- getStateById : ( id : string ) => dockEntryStateMap . get ( id ) ,
118- switchEntry : async ( id : string | null ) => {
119- if ( id === null ) {
120- selectedId . value = null
121- return true
122- }
123- const entry = dockEntries . value . find ( e => e . id === id )
124- if ( ! entry )
125- return false
126- selectedId . value = entry . id
127- // TODO: run action
128- return true
129- } ,
130- } ,
131- rpc : rpcReturn . rpc ,
132- clientRpc : rpcReturn . clientRpc ,
133- clientType,
134- } )
135-
136- return _docksContext
137- }
0 commit comments