@@ -6,10 +6,8 @@ class InElementSupportProvider {
6
6
constructor ( owner ) {
7
7
this . nodeMap = new Map ( ) ;
8
8
this . remoteRoots = [ ] ;
9
- this . currentNode = null ;
10
- this . nodeStack = [ ] ;
11
- this . remoteNodeStack = [ ] ;
12
9
this . runtime = this . require ( '@glimmer/runtime' ) ;
10
+ this . reference = this . require ( '@glimmer/reference' ) ;
13
11
try {
14
12
this . Wormhole = requireModule ( 'ember-wormhole/components/ember-wormhole' ) ;
15
13
} catch ( e ) {
@@ -27,115 +25,80 @@ class InElementSupportProvider {
27
25
reset ( ) {
28
26
this . nodeMap . clear ( ) ;
29
27
this . remoteRoots . length = 0 ;
30
- this . nodeStack . length = 0 ;
31
- this . remoteNodeStack . length = 0 ;
32
- this . currentRemoteNode = null ;
33
- this . currentNode = null ;
34
- }
35
-
36
- buildInElementNode ( node ) {
37
- const obj = Object . create ( null ) ;
38
- obj . index = this . currentNode ?. refs ?. size || 0 ;
39
- obj . name = 'in-element' ;
40
- obj . type = 'component' ;
41
- obj . template = null ;
42
- obj . isRemote = true ;
43
- obj . args = {
44
- positional : [ ] ,
45
- named : {
46
- destination : node ,
47
- } ,
48
- } ;
49
- obj . instance = {
50
- args : obj . args . named ,
51
- constructor : {
52
- name : 'InElement' ,
53
- } ,
54
- } ;
55
- obj . bounds = {
56
- firstNode : node ,
57
- lastNode : node ,
58
- parentElement : node . parentElement ,
59
- } ;
60
- obj . children = [ ] ;
61
- return obj ;
62
28
}
63
29
64
30
patch ( ) {
65
31
const self = this ;
66
32
67
- const captureNode = this . debugRenderTree . captureNode ;
68
- this . debugRenderTree . captureNode = function ( ...args ) {
69
- const capture = captureNode . call ( this , ...args ) ;
70
- const [ id , state ] = args ;
71
- const node = this . nodeFor ( state ) ;
72
- self . setupNodeRemotes ( node , id , capture ) ;
73
- return capture ;
74
- } ;
75
-
76
- const enter = this . debugRenderTree . enter ;
77
- this . debugRenderTree . enter = function ( ...args ) {
78
- const state = args [ 0 ] ;
79
- self . enter ( this . nodeFor ( state ) ) ;
80
- return enter . call ( this , ...args ) ;
81
- } ;
82
-
83
- const exit = this . debugRenderTree . exit ;
84
- this . debugRenderTree . exit = function ( ...args ) {
85
- self . exit ( ) ;
86
- return exit . call ( this , ...args ) ;
87
- } ;
88
-
89
33
const NewElementBuilder = this . NewElementBuilder ;
34
+ const remoteStack = [ ] ;
35
+
90
36
const didAppendNode = NewElementBuilder . prototype . didAppendNode ;
91
37
NewElementBuilder . prototype . didAppendNode = function ( ...args ) {
92
- args [ 0 ] . __emberInspectorParentNode = self . currentNode ;
38
+ const parent = this . env . debugRenderTree . stack . current ;
39
+ args [ 0 ] . __emberInspectorParentNode =
40
+ this . env . debugRenderTree . nodeFor ( parent ) ;
93
41
return didAppendNode . call ( this , ...args ) ;
94
42
} ;
95
43
96
44
const pushElement = NewElementBuilder . prototype . pushElement ;
97
45
NewElementBuilder . prototype . pushElement = function ( ...args ) {
98
- args [ 0 ] . __emberInspectorParentNode = self . currentNode ;
46
+ const parent = this . env ?. debugRenderTree . stack . current ;
47
+ args [ 0 ] . __emberInspectorParentNode =
48
+ this . env ?. debugRenderTree . nodeFor ( parent ) ;
99
49
return pushElement . call ( this , ...args ) ;
100
50
} ;
101
51
102
52
const pushRemoteElement = NewElementBuilder . prototype . pushRemoteElement ;
103
53
NewElementBuilder . prototype . pushRemoteElement = function ( ...args ) {
104
- const block = pushRemoteElement . call ( this , ...args ) ;
105
- self . registerRemote ( block , ...args ) ;
106
- self . nodeStack . push ( self . currentNode ) ;
107
- self . remoteNodeStack . push ( self . currentNode ) ;
108
- self . currentRemoteNode = self . currentNode ;
109
- return block ;
54
+ const element = args [ 0 ] ;
55
+ remoteStack . push ( { } ) ;
56
+ const ref = self . reference . createUnboundRef ( element ) ;
57
+ this . env . debugRenderTree ?. create ( remoteStack . at ( - 1 ) , {
58
+ type : 'remote-element' ,
59
+ name : 'in-element' ,
60
+ args : {
61
+ positional : [ ] ,
62
+ named : {
63
+ destination : ref ,
64
+ } ,
65
+ } ,
66
+ instance : {
67
+ args : {
68
+ destination : ref ,
69
+ } ,
70
+ constructor : {
71
+ name : 'InElement' ,
72
+ } ,
73
+ } ,
74
+ } ) ;
75
+ return pushRemoteElement . call ( this , ...args ) ;
110
76
} ;
111
77
112
78
const popRemoteElement = NewElementBuilder . prototype . popRemoteElement ;
113
79
NewElementBuilder . prototype . popRemoteElement = function ( ...args ) {
114
- const block = popRemoteElement . call ( this , ...args ) ;
115
- self . remoteNodeStack . pop ( ) ;
116
- self . nodeStack . pop ( ) ;
117
- self . currentRemoteNode =
118
- self . remoteNodeStack [ self . remoteNodeStack . length - 1 ] ;
119
- return block ;
80
+ const element = this . element ;
81
+ this . env . debugRenderTree ?. didRender ( remoteStack . at ( - 1 ) , {
82
+ parentElement : ( ) => element . parentElement ,
83
+ firstNode : ( ) => element ,
84
+ lastNode : ( ) => element ,
85
+ } ) ;
86
+ remoteStack . pop ( ) ;
87
+ return popRemoteElement . call ( this , ...args ) ;
120
88
} ;
121
89
122
- this . debugRenderTreeFunctions = {
123
- exit,
124
- enter,
125
- captureNode,
126
- } ;
127
90
this . NewElementBuilderFunctions = {
128
91
pushElement,
129
92
pushRemoteElement,
93
+ popRemoteElement,
130
94
didAppendNode,
131
95
} ;
132
96
}
133
97
134
98
teardown ( ) {
135
- if ( ! this . debugRenderTreeFunctions ) {
99
+ if ( ! this . NewElementBuilderFunctions ) {
136
100
return ;
137
101
}
138
- Object . assign ( this . debugRenderTree , this . debugRenderTreeFunctions ) ;
139
102
Object . assign (
140
103
this . NewElementBuilder . prototype ,
141
104
this . NewElementBuilderFunctions
@@ -147,81 +110,6 @@ class InElementSupportProvider {
147
110
? requireModule ( req )
148
111
: EmberLoader . require ( req ) ;
149
112
}
150
-
151
- enter ( node ) {
152
- if ( this . currentNode && this . currentNode === this . currentRemoteNode ) {
153
- this . currentRemoteNode . children . push ( node ) ;
154
- node . remoteParent = this . currentRemoteNode ;
155
- }
156
- this . currentNode = node ;
157
- this . nodeStack . push ( this . currentNode ) ;
158
- }
159
-
160
- exit ( ) {
161
- this . nodeStack . pop ( ) ;
162
- this . currentNode = this . nodeStack [ this . nodeStack . length - 1 ] ;
163
- }
164
-
165
- registerRemote ( block , node ) {
166
- const obj = this . buildInElementNode ( node ) ;
167
- if ( this . currentNode ) {
168
- if ( ! this . currentNode . remotes ) {
169
- Object . defineProperty ( this . currentNode , 'remotes' , {
170
- value : [ ] ,
171
- } ) ;
172
- }
173
- this . currentNode . remotes . push ( obj ) ;
174
- }
175
- this . remoteRoots . push ( obj ) ;
176
- this . currentNode = obj ;
177
- }
178
-
179
- setupNodeRemotes ( node , id , capture ) {
180
- capture . isInRemote = ! ! node . remoteParent ;
181
- this . nodeMap . set ( node , id ) ;
182
- if ( node . remoteParent ) {
183
- const idx = node . remoteParent . children . indexOf ( node ) ;
184
- if ( idx >= 0 ) {
185
- node . remoteParent . children [ idx ] = capture ;
186
- }
187
- }
188
- capture . children = capture . children . filter ( ( c ) => ! c . isInRemote ) ;
189
- node . remotes ?. forEach ( ( remote ) => {
190
- remote . id = 'remote-render-node:' + this . remoteRoots . length ;
191
- this . nodeMap . set ( remote , remote . id ) ;
192
- this . remoteRoots . push ( remote ) ;
193
- capture . children . splice ( remote . index , 0 , remote ) ;
194
- } ) ;
195
- if ( capture . instance ?. __emberInspectorTargetNode ) {
196
- Object . defineProperty ( capture , 'bounds' , {
197
- get ( ) {
198
- return {
199
- firstNode : capture . instance . __emberInspectorTargetNode ,
200
- lastNode : capture . instance . __emberInspectorTargetNode ,
201
- parentElement :
202
- capture . instance . __emberInspectorTargetNode . parentElement ,
203
- } ;
204
- } ,
205
- } ) ;
206
- }
207
- if ( this . Wormhole && capture . instance instanceof this . Wormhole . default ) {
208
- this . remoteRoots . push ( capture ) ;
209
- const bounds = capture . bounds ;
210
- Object . defineProperty ( capture , 'bounds' , {
211
- get ( ) {
212
- if ( capture . instance . _destination ) {
213
- return {
214
- firstNode : capture . instance . _destination ,
215
- lastNode : capture . instance . _destination ,
216
- parentElement : capture . instance . _destination . parentElement ,
217
- } ;
218
- }
219
- return bounds ;
220
- } ,
221
- } ) ;
222
- }
223
- return capture ;
224
- }
225
113
}
226
114
227
115
export default class RenderTree {
@@ -496,6 +384,31 @@ export default class RenderTree {
496
384
497
385
if ( serialized === undefined ) {
498
386
this . nodes [ node . id ] = node ;
387
+ if ( node . type === 'remote-element' ) {
388
+ node . type = 'component' ;
389
+ this . inElementSupport ?. nodeMap . set ( node , node . id ) ;
390
+ this . inElementSupport ?. remoteRoots . push ( node ) ;
391
+ }
392
+
393
+ if (
394
+ this . inElementSupport ?. Wormhole &&
395
+ node . instance instanceof this . inElementSupport . Wormhole . default
396
+ ) {
397
+ this . inElementSupport ?. remoteRoots . push ( node ) ;
398
+ const bounds = node . bounds ;
399
+ Object . defineProperty ( node , 'bounds' , {
400
+ get ( ) {
401
+ if ( node . instance . _destination ) {
402
+ return {
403
+ firstNode : node . instance . _destination ,
404
+ lastNode : node . instance . _destination ,
405
+ parentElement : node . instance . _destination . parentElement ,
406
+ } ;
407
+ }
408
+ return bounds ;
409
+ } ,
410
+ } ) ;
411
+ }
499
412
500
413
if ( parentNode ) {
501
414
this . parentNodes [ node . id ] = parentNode ;
0 commit comments