1
1
import { highlight } from './highlight.js' ;
2
2
import { addListener } from './listener.js' ;
3
3
// import { profiler } from './profiler.js';
4
- import { getNode } from './svelte.js' ;
5
-
6
- // @ts -ignore - possibly find an alternative
7
- window . __svelte_devtools_inject_state = function ( id , key , value ) {
8
- const { detail : component } = getNode ( id ) || { } ;
9
- component && component . $inject_state ( { [ key ] : value } ) ;
10
- } ;
11
-
12
- // @ts -ignore - possibly find an alternative
13
- window . __svelte_devtools_select_element = function ( element ) {
14
- const node = getNode ( element ) ;
15
- if ( node ) send ( 'inspect' , { node : serialize ( node ) } ) ;
4
+ import { nodes } from './svelte.js' ;
5
+
6
+ // @ts -ignore - for the app to call with `eval`
7
+ window [ '#SvelteDevTools' ] = {
8
+ /**
9
+ * @param {string } id
10
+ * @param {string } key
11
+ * @param {any } value
12
+ */
13
+ inject ( id , key , value ) {
14
+ const { detail : component } = nodes . map . get ( id ) || { } ;
15
+ component && component . $inject_state ( { [ key ] : value } ) ;
16
+ } ,
16
17
} ;
17
18
18
19
const previous = {
@@ -56,7 +57,7 @@ const inspect = {
56
57
click ( event ) {
57
58
event . preventDefault ( ) ;
58
59
document . removeEventListener ( 'mousemove' , inspect . handle , true ) ;
59
- const node = getNode ( /** @type {Node } */ ( event . target ) ) ;
60
+ const node = nodes . map . get ( /** @type {Node } */ ( event . target ) ) ;
60
61
if ( node ) send ( 'bridge::ext/inspect' , { node : serialize ( node ) } ) ;
61
62
previous . clear ( ) ;
62
63
} ,
@@ -67,11 +68,11 @@ window.addEventListener('message', ({ data, source }) => {
67
68
if ( source !== window || data ?. source !== 'svelte-devtools' ) return ;
68
69
69
70
if ( data . type === 'bridge::ext/select' ) {
70
- const node = getNode ( data . payload ) ;
71
+ const node = nodes . map . get ( data . payload ) ;
71
72
// @ts -expect-error - saved for `devtools.inspect()`
72
73
if ( node ) window . $n = node . detail ;
73
74
} else if ( data . type === 'bridge::ext/highlight' ) {
74
- const node = getNode ( data . payload ) ;
75
+ const node = nodes . map . get ( data . payload ) ;
75
76
return highlight ( node ) ;
76
77
} else if ( data . type === 'bridge::ext/inspect' ) {
77
78
switch ( data . payload ) {
0 commit comments