@@ -21,24 +21,25 @@ import {
21
21
} from " @ikun-ui/core" ;
22
22
import {rpc } from " ../composables/rpc" ;
23
23
import {darkLight } from " @ikun-svelte-devtools/utils-client" ;
24
+ // @ts-ignore
24
25
import { useDevtoolsClient } from " ../composables/client" ;
25
-
26
+ import type { ModuleInfo , SvelteDevtoolsHostClient } from ' @ikun-svelte-devtools/shared ' ;
26
27
let rootPath = ' '
27
28
const modulesMap = new Map <string , { filePath: string }>()
28
- rpc .root ().then (res => {
29
+ rpc .root ().then (( res : any ) => {
29
30
rootPath = res
30
- }).catch (err => {
31
+ }).catch (( err : Error ) => {
31
32
console .error (err )
32
33
})
33
34
34
35
let keyPress = false
35
- const handleKeyPressDown = (event ) => {
36
+ const handleKeyPressDown = (event : KeyboardEvent ) => {
36
37
if (event .key === ' Alt' || event .key === ' Meta' || event .key === ' Cmd' ){
37
38
keyPress = true
38
39
}
39
40
}
40
41
41
- const handleKeyPressUp = (event ) => {
42
+ const handleKeyPressUp = (event : KeyboardEvent ) => {
42
43
if (event .key === ' Alt' || event .key === ' Meta' || event .key === ' Cmd' ){
43
44
keyPress = false
44
45
}
@@ -48,14 +49,14 @@ onDestroy(() => {
48
49
document .removeEventListener (' keyup' , handleKeyPressUp )
49
50
})
50
51
/** ******* render chart ***********/
51
- const handleDataToChartData = (initData ) => {
52
+ const handleDataToChartData = (initData : {data : ModuleInfo [], main : ModuleInfo []} ) => {
52
53
53
54
if (! initData )
54
55
return { node: [], edges: [] }
55
56
56
57
const { data, main } = initData
57
58
const { level } = getGraphConfig ()
58
- const nodes: Data [' nodes' ] = data .map ((mod ) => {
59
+ const nodes: Data [' nodes' ] = ( data ) .map ((mod ) => {
59
60
const path = mod .id .replace (/ \? . * $ / , ' ' ).replace (/ #. * $ / , ' ' )
60
61
const pathSegments = path .split (' /' )
61
62
const id = mod .id
@@ -80,7 +81,7 @@ const handleDataToChartData = (initData) =>{
80
81
: darkLight () === ' dark' ? ' white' : ' black' ,
81
82
multi: ' html' ,
82
83
},
83
- shape: mod .id .includes (' /node_modules/' )
84
+ shape: mod .id ! .includes (' /node_modules/' )
84
85
? ' hexagon'
85
86
: mod .virtual
86
87
? ' diamond'
@@ -106,20 +107,20 @@ const handleDataToChartData = (initData) =>{
106
107
}
107
108
108
109
let searchValue = ' '
109
- let graphData = null
110
+ let graphData: any = null
110
111
const searchNode = debounce ((e ) => {
111
112
updateChart (e .detail )
112
113
}, 300 )
113
114
114
- let lastSelectedNode = null
115
- let networkChart = null
115
+ let lastSelectedNode: any = null
116
+ let networkChart: InstanceType < typeof Network > | null = null
116
117
const client = useDevtoolsClient ()
117
118
onMount (async () => {
118
119
graphData = await getGraphData ()
119
120
let finalGraphData = initGraphData (' ' , graphData )
120
121
121
122
const container = document .getElementById (' __svelte_devtools_graph' )
122
- networkChart = new Network (container , handleDataToChartData (finalGraphData ) as Data , visNetworkOptions )
123
+ networkChart = new Network (container ! , handleDataToChartData (finalGraphData ) as Data , visNetworkOptions )
123
124
124
125
const resetNodeStyle = () => {
125
126
// @ts-expect-error network body typing error
@@ -143,7 +144,7 @@ onMount(async () => {
143
144
144
145
const { highlight, openEditor } = getGraphConfig ()
145
146
if (openEditor .open && keyPress ){
146
- return client .inspector .openInEditor (location .origin , modulesMap .get (nodeId )! .filePath , 1 , 1 )
147
+ return ( client as SvelteDevtoolsHostClient ) .inspector ! .openInEditor (location .origin , modulesMap .get (nodeId )! .filePath , 1 , 1 )
147
148
}
148
149
149
150
@@ -219,15 +220,15 @@ const handleSwitch = (value: boolean, type: 'h' | 'o') => {
219
220
/** **************** custom hover path level **********************/
220
221
let hoverPathLevel = level .value
221
222
let hoverPathLevelCustom = level .levelCustom
222
- const handleHoverPathLevel = (data ) => {
223
+ const handleHoverPathLevel = (data : CustomEvent ) => {
223
224
hoverPathLevel = data .detail
224
225
const curConfig = getGraphConfig ()
225
226
curConfig .level .value = hoverPathLevel
226
227
// update config
227
228
setGraphConfigCache (curConfig )
228
229
updateChart ()
229
230
}
230
- const handlePathLevelCustom = (data ) => {
231
+ const handlePathLevelCustom = (data : CustomEvent ) => {
231
232
hoverPathLevelCustom = data .detail
232
233
const curConfig = getGraphConfig ()
233
234
curConfig .level .levelCustom = hoverPathLevelCustom
0 commit comments