11import type { DevToolsDockEntry } from '@vitejs/devtools-kit'
2- import type { ImportScriptContext } from '@vitejs/devtools-kit/client'
2+ import type { DockClientScriptContext } from '@vitejs/devtools-kit/client'
33import type { Ref } from 'vue'
44import type { DevToolsDockState } from '../components/DockProps'
55import { computed , reactive } from 'vue'
66
77export function useStateHandlers ( state : Ref < DevToolsDockState > ) {
8- function importScript ( entry : DevToolsDockEntry ) : Promise < ( context : ImportScriptContext ) => void | Promise < void > > {
9- const id = entry . id
8+ function importScript ( entry : DevToolsDockEntry ) : Promise < ( context : DockClientScriptContext ) => void | Promise < void > > {
9+ const id = ` ${ entry . type } : ${ entry . id } `
1010 return import ( /* @vite -ignore */ [ '/.devtools' , 'imports' ] . join ( '-' ) )
1111 . then ( ( module ) => {
1212 const importsMap = module . importsMap as Record < string , ( ) => Promise < ( ) => void > >
@@ -17,21 +17,21 @@ export function useStateHandlers(state: Ref<DevToolsDockState>) {
1717 return importFn ( )
1818 } )
1919 . catch ( ( error ) => {
20- // TODO: maybe popup a error toast here?
21- // TODO: A unified logger API
20+ // TODO: maybe popup a error toast here?
21+ // TODO: A unified logger API
2222 console . error ( '[VITE DEVTOOLS] Error executing import action' , error )
2323 return Promise . reject ( error )
2424 } )
2525 }
2626
27- function selectDockEntry ( entry ?: DevToolsDockEntry ) {
27+ async function selectDockEntry ( entry ?: DevToolsDockEntry ) {
2828 if ( ! entry ) {
2929 state . value . open = false
3030 state . value . dockEntry = undefined
3131 return
3232 }
3333
34- const scriptContext : ImportScriptContext = reactive ( {
34+ const scriptContext : DockClientScriptContext = reactive ( {
3535 dockEntry : entry ,
3636 // @ts -expect-error cast for unwraping
3737 dockState : computed < 'active' | 'inactive' > ( {
@@ -52,16 +52,14 @@ export function useStateHandlers(state: Ref<DevToolsDockState>) {
5252
5353 // If it's an action, run and return (early exit)
5454 if ( entry ?. type === 'action' ) {
55- return importScript ( entry ) . then ( fn => fn ( scriptContext ) )
55+ return await importScript ( entry ) . then ( fn => fn ( scriptContext ) )
5656 }
5757
5858 state . value . dockEntry = entry
5959 state . value . open = true
6060
6161 // If has import script, run it
62- if ( entry . import ) {
63- importScript ( entry ) . then ( fn => fn ( scriptContext ) )
64- }
62+ await importScript ( entry ) . then ( fn => fn ?.( scriptContext ) )
6563 }
6664
6765 return {
0 commit comments