6
6
* found in the LICENSE file at https://angular.dev/license
7
7
*/
8
8
9
- import { ɵHydratedNode as HydrationNode } from '@angular/core' ;
9
+ import type {
10
+ ɵFrameworkAgnosticGlobalUtils as FrameworkAgnosticGlobalUtils ,
11
+ ɵHydratedNode as HydrationNode ,
12
+ } from '@angular/core' ;
10
13
import { HydrationStatus } from 'protocol' ;
11
14
12
15
import { ComponentTreeNode } from '../interfaces' ;
@@ -16,8 +19,9 @@ import {isCustomElement} from '../utils';
16
19
const extractViewTree = (
17
20
domNode : Node | Element ,
18
21
result : ComponentTreeNode [ ] ,
19
- getComponent ?: ( element : Element ) => { } | null ,
20
- getDirectives ?: ( node : Node ) => { } [ ] ,
22
+ getComponent ?: FrameworkAgnosticGlobalUtils [ 'getComponent' ] ,
23
+ getDirectives ?: FrameworkAgnosticGlobalUtils [ 'getDirectives' ] ,
24
+ getDirectiveMetadata ?: FrameworkAgnosticGlobalUtils [ 'getDirectiveMetadata' ] ,
21
25
) : ComponentTreeNode [ ] => {
22
26
// Ignore DOM Node if it came from a different frame. Use instanceof Node to check this.
23
27
if ( ! ( domNode instanceof Node ) ) {
@@ -50,19 +54,25 @@ const extractViewTree = (
50
54
componentTreeNode . component = {
51
55
instance : component ,
52
56
isElement : isCustomElement ( domNode ) ,
53
- name : domNode . nodeName . toLowerCase ( ) ,
57
+ name : getDirectiveMetadata ?. ( component ) ?. name ?? domNode . nodeName . toLowerCase ( ) ,
54
58
} ;
55
59
}
56
60
if ( component || componentTreeNode . directives . length ) {
57
61
result . push ( componentTreeNode ) ;
58
62
}
59
63
if ( componentTreeNode . component || componentTreeNode . directives . length ) {
60
64
domNode . childNodes . forEach ( ( node ) =>
61
- extractViewTree ( node , componentTreeNode . children , getComponent , getDirectives ) ,
65
+ extractViewTree (
66
+ node ,
67
+ componentTreeNode . children ,
68
+ getComponent ,
69
+ getDirectives ,
70
+ getDirectiveMetadata ,
71
+ ) ,
62
72
) ;
63
73
} else {
64
74
domNode . childNodes . forEach ( ( node ) =>
65
- extractViewTree ( node , result , getComponent , getDirectives ) ,
75
+ extractViewTree ( node , result , getComponent , getDirectives , getDirectiveMetadata ) ,
66
76
) ;
67
77
}
68
78
return result ;
@@ -98,8 +108,8 @@ export class RTreeStrategy {
98
108
while ( element . parentElement ) {
99
109
element = element . parentElement ;
100
110
}
101
- const getComponent = ngDebugClient ( ) . getComponent ;
102
- const getDirectives = ngDebugClient ( ) . getDirectives ;
103
- return extractViewTree ( element , [ ] , getComponent , getDirectives ) ;
111
+
112
+ const ng = ngDebugClient ( ) ;
113
+ return extractViewTree ( element , [ ] , ng . getComponent , ng . getDirectives , ng . getDirectiveMetadata ) ;
104
114
}
105
115
}
0 commit comments