1
- import captureRenderTree from ' ./capture-render-tree' ;
2
- import { guidFor } from ' ember-debug/utils/ember/object/internals' ;
3
- import { EmberLoader } from ' ember-debug/utils/ember/loader' ;
1
+ import captureRenderTree from " ./capture-render-tree" ;
2
+ import { guidFor } from " ember-debug/utils/ember/object/internals" ;
3
+ import { EmberLoader } from " ember-debug/utils/ember/loader" ;
4
4
5
5
class InElementSupportProvider {
6
6
constructor ( owner ) {
@@ -32,105 +32,56 @@ class InElementSupportProvider {
32
32
33
33
const NewElementBuilder = this . NewElementBuilder ;
34
34
const remoteStack = [ ] ;
35
- const componentStack = [ ] ;
36
-
37
- function createRef ( value ) {
38
- if ( self . reference . createUnboundRef ) {
39
- return self . reference . createUnboundRef ( value ) ;
40
- } else {
41
- return value ;
42
- }
43
- }
44
-
45
- const appendChild = this . debugRenderTree . appendChild ;
46
- this . debugRenderTree . appendChild = function ( node , state ) {
47
- if ( node . type === 'component' ) {
48
- componentStack . push ( node ) ;
49
- }
50
- return appendChild . call ( this , node , state ) ;
51
- } ;
52
-
53
- const exit = this . debugRenderTree . exit ;
54
- this . debugRenderTree . exit = function ( state ) {
55
- const node = this . nodeFor ( this . stack . current ) ;
56
- if ( node ?. type === 'component' ) {
57
- componentStack . pop ( ) ;
58
- }
59
- exit . call ( this , state ) ;
60
- } ;
61
35
62
36
const didAppendNode = NewElementBuilder . prototype . didAppendNode ;
63
37
NewElementBuilder . prototype . didAppendNode = function ( ...args ) {
64
- args [ 0 ] . __emberInspectorParentNode = componentStack . at ( - 1 ) ;
38
+ args [ 0 ] . __emberInspectorParentNode = self . currentNode ;
65
39
return didAppendNode . call ( this , ...args ) ;
66
40
} ;
67
41
68
42
const pushElement = NewElementBuilder . prototype . pushElement ;
69
43
NewElementBuilder . prototype . pushElement = function ( ...args ) {
70
- pushElement . call ( this , ... args ) ;
71
- args [ 0 ] . __emberInspectorParentNode = componentStack . at ( - 1 ) ;
44
+ args [ 0 ] . __emberInspectorParentNode = self . currentNode ;
45
+ return pushElement . call ( this , ... args ) ;
72
46
} ;
73
47
74
48
const pushRemoteElement = NewElementBuilder . prototype . pushRemoteElement ;
75
- NewElementBuilder . prototype . pushRemoteElement = function (
76
- element ,
77
- guid ,
78
- insertBefore
79
- ) {
80
- remoteStack . push ( { element } ) ;
81
- const ref = createRef ( element ) ;
82
- const capturedArgs = {
83
- positional : [ ref ] ,
84
- named : { } ,
85
- } ;
86
- if ( insertBefore ) {
87
- capturedArgs . named . insertBefore = insertBefore ;
88
- }
89
- const inElementArgs = self . reference . createUnboundRef
90
- ? capturedArgs
91
- : {
92
- value ( ) {
93
- return capturedArgs ;
94
- } ,
95
- } ;
96
- const debugRenderTree = self . debugRenderTree ;
97
- debugRenderTree ?. create ( remoteStack . at ( - 1 ) , {
98
- type : 'keyword' ,
99
- name : 'in-element' ,
100
- args : inElementArgs ,
49
+ NewElementBuilder . prototype . pushRemoteElement = function ( ...args ) {
50
+ const element = args [ 0 ] ;
51
+ remoteStack . push ( { } ) ;
52
+ const ref = self . reference . createUnboundRef ( element ) ;
53
+ this . env . debugRenderTree ?. create ( remoteStack . at ( - 1 ) , {
54
+ type : 'remote-element' ,
55
+ name : 'InElement' ,
56
+ args : {
57
+ positional : [ ] ,
58
+ named : {
59
+ destination : ref ,
60
+ } ,
61
+ } ,
101
62
instance : {
102
63
args : {
103
- named : {
104
- insertBefore,
105
- } ,
106
- positional : [ element ] ,
64
+ destination : ref ,
107
65
} ,
108
66
constructor : {
109
67
name : 'InElement' ,
110
68
} ,
111
69
} ,
112
70
} ) ;
113
- return pushRemoteElement . call ( this , element , guid , insertBefore ) ;
71
+ return pushRemoteElement . call ( this , ... args ) ;
114
72
} ;
115
73
116
74
const popRemoteElement = NewElementBuilder . prototype . popRemoteElement ;
117
75
NewElementBuilder . prototype . popRemoteElement = function ( ...args ) {
118
- const element = this . element ;
119
- popRemoteElement . call ( this , ...args ) ;
120
- const parentElement = this . element ;
121
- const debugRenderTree = self . debugRenderTree ;
122
- debugRenderTree ?. didRender ( remoteStack . at ( - 1 ) , {
123
- parentElement : ( ) => parentElement ,
124
- firstNode : ( ) => element ,
125
- lastNode : ( ) => element ,
76
+ this . env . debugRenderTree ?. didRender ( remoteStack . at ( - 1 ) , {
77
+ parentElement : ( ) => this . element . parentElement ,
78
+ firstNode : ( ) => this . element ,
79
+ lastNode : ( ) => this . element ,
126
80
} ) ;
127
81
remoteStack . pop ( ) ;
128
- } ;
82
+ return popRemoteElement . call ( this , ...args ) ;
83
+ }
129
84
130
- this . debugRenderTreeFunctions = {
131
- appendChild,
132
- exit,
133
- } ;
134
85
this . NewElementBuilderFunctions = {
135
86
pushElement,
136
87
pushRemoteElement,
@@ -143,7 +94,6 @@ class InElementSupportProvider {
143
94
if ( ! this . NewElementBuilderFunctions ) {
144
95
return ;
145
96
}
146
- Object . assign ( this . debugRenderTree , this . debugRenderTreeFunctions ) ;
147
97
Object . assign (
148
98
this . NewElementBuilder . prototype ,
149
99
this . NewElementBuilderFunctions
@@ -175,7 +125,6 @@ export default class RenderTree {
175
125
try {
176
126
this . inElementSupport = new InElementSupportProvider ( owner ) ;
177
127
} catch ( e ) {
178
- console . error ( 'failed to setup in element support' , e ) ;
179
128
// not supported
180
129
}
181
130
@@ -259,7 +208,7 @@ export default class RenderTree {
259
208
let hintNode = this . _findUp ( this . nodes [ hint ] ) ;
260
209
let hints = [ hintNode ] ;
261
210
if ( node . __emberInspectorParentNode ) {
262
- const remoteNode = this . inElementSupport ? .nodeMap . get ( node ) ;
211
+ const remoteNode = this . inElementSupport . nodeMap . get ( node ) ;
263
212
const n = remoteNode && this . nodes [ remoteNode ] ;
264
213
hints . push ( n ) ;
265
214
}
@@ -430,16 +379,12 @@ export default class RenderTree {
430
379
431
380
if ( serialized === undefined ) {
432
381
this . nodes [ node . id ] = node ;
433
- if ( node . type === 'keyword' ) {
434
- node . type = 'component' ;
382
+ if ( node . type === 'remote-element' ) {
435
383
this . inElementSupport ?. nodeMap . set ( node , node . id ) ;
436
384
this . inElementSupport ?. remoteRoots . push ( node ) ;
437
385
}
438
386
439
- if (
440
- this . inElementSupport ?. Wormhole &&
441
- node . instance instanceof this . inElementSupport . Wormhole . default
442
- ) {
387
+ if ( this . inElementSupport ?. Wormhole && node . instance instanceof this . inElementSupport ?. Wormhole . default ) {
443
388
this . inElementSupport ?. remoteRoots . push ( node ) ;
444
389
const bounds = node . bounds ;
445
390
Object . defineProperty ( node , 'bounds' , {
@@ -465,9 +410,9 @@ export default class RenderTree {
465
410
args : this . _serializeArgs ( node . args ) ,
466
411
instance : this . _serializeItem (
467
412
node . instance ||
468
- ( node . type === 'component'
469
- ? this . _createTemplateOnlyComponent ( node . args . named )
470
- : undefined )
413
+ ( node . type === 'component'
414
+ ? this . _createTemplateOnlyComponent ( node . args . named )
415
+ : undefined )
471
416
) ,
472
417
bounds : this . _serializeBounds ( node . bounds ) ,
473
418
children : this . _serializeRenderNodes ( node . children , node ) ,
@@ -642,8 +587,11 @@ function isSingleNode({ firstNode, lastNode }) {
642
587
return firstNode === lastNode ;
643
588
}
644
589
645
- function isAttached ( { firstNode, lastNode } ) {
646
- return firstNode . isConnected && lastNode . isConnected ;
590
+ function isAttached ( { parentElement, firstNode, lastNode } ) {
591
+ return (
592
+ parentElement === firstNode . parentElement &&
593
+ parentElement === lastNode . parentElement
594
+ ) ;
647
595
}
648
596
649
597
function isEmptyRect ( { x, y, width, height } ) {
0 commit comments