1
1
/** @publicapi @module directives */ /** */
2
2
import {
3
3
$QLike ,
4
- ActiveUIView ,
5
4
extend ,
6
5
filter ,
7
6
HookRegOptions ,
@@ -23,8 +22,11 @@ import {
23
22
TypedMap ,
24
23
UIViewPortalRenderCommand ,
25
24
unnestR ,
25
+ ViewConfig ,
26
+ ViewContext ,
26
27
ViewService ,
27
28
} from '@uirouter/core' ;
29
+ import { UIViewPortalRegistration } from '@uirouter/core/lib/view/interface' ;
28
30
import { IAugmentedJQuery , IInterpolateService , IScope , ITranscludeFunction } from 'angular' ;
29
31
import { ng as angular } from '../angular' ;
30
32
import { Ng1Controller , Ng1StateDeclaration } from '../interface' ;
@@ -172,6 +174,26 @@ export type UIViewAnimData = {
172
174
* ```
173
175
*/
174
176
export let uiView : ng1_directive ;
177
+
178
+ // No longer exported from @uirouter /core
179
+ // for backwards compat only
180
+ export interface ActiveUIView {
181
+ /** type of framework, e.g., "ng1" or "ng2" */
182
+ $type : string ;
183
+ /** An auto-incremented id */
184
+ id : number | string ;
185
+ /** The ui-view short name */
186
+ name : string ;
187
+ /** The ui-view's fully qualified name */
188
+ fqn : string ;
189
+ /** The ViewConfig that is currently loaded into the ui-view */
190
+ config : ViewConfig ;
191
+ /** The state context in which the ui-view tag was created. */
192
+ creationContext : ViewContext ;
193
+ /** A callback that should apply a ViewConfig (or clear the ui-view, if config is undefined) */
194
+ configUpdated : ( config : ViewConfig ) => void ;
195
+ }
196
+
175
197
// eslint-disable-next-line prefer-const
176
198
uiView = [
177
199
'$view' ,
@@ -244,14 +266,22 @@ uiView = [
244
266
// },
245
267
} ;
246
268
247
- trace . traceUIViewEvent ( 'Linking' , activeUIView ) ;
248
- const uiViewId = $view . registerView ( 'ng1' , inherited . $uiView . id , name , renderContentIntoUIViewPortal ) ;
269
+ const uiViewId = $view . _pluginapi . _registerView (
270
+ 'ng1' ,
271
+ inherited . $uiView . id ,
272
+ name ,
273
+ renderContentIntoUIViewPortal
274
+ ) ;
275
+ // as any: trace requires the internal interface, hmmm... this isn't good
276
+ const registration = $view . _pluginapi . _registeredUIView ( uiViewId ) as any ;
277
+ trace . traceUIViewEvent ( 'Linking' , registration ) ;
249
278
250
279
scope . $on ( '$destroy' , function ( ) {
251
- trace . traceUIViewEvent ( 'Destroying/Unregistering' , activeUIView ) ;
252
- $view . deregisterView ( uiViewId ) ;
280
+ trace . traceUIViewEvent ( 'Destroying/Unregistering' , registration ) ;
281
+ $view . _pluginapi . _deregisterView ( uiViewId ) ;
253
282
} ) ;
254
283
284
+ // backwards compat
255
285
$element . data ( '$uiView' , { $uiView : activeUIView } ) ;
256
286
257
287
function cleanupLastView ( ) {
@@ -262,7 +292,7 @@ uiView = [
262
292
}
263
293
264
294
if ( currentScope ) {
265
- trace . traceUIViewEvent ( 'Destroying scope' , activeUIView ) ;
295
+ trace . traceUIViewEvent ( 'Destroying scope' , registration ) ;
266
296
currentScope . $destroy ( ) ;
267
297
currentScope = null ;
268
298
}
@@ -281,16 +311,17 @@ uiView = [
281
311
}
282
312
283
313
function renderContentIntoUIViewPortal ( renderCommand : UIViewPortalRenderCommand ) {
284
- if ( isString ( activeUIView ) && activeUIView . id !== renderCommand . id ) {
314
+ const renderCmdViewId = renderCommand . uiViewPortalRegistration . id ;
315
+ if ( isString ( activeUIView . id ) && activeUIView . id !== renderCmdViewId ) {
285
316
throw new Error (
286
- `Received a render command for wrong UIView. Render command id: ${ renderCommand . id } , but this UIView id: ${ activeUIView . id } `
317
+ `Received a render command for wrong UIView. Render command id: ${ renderCmdViewId } , but this UIView id: ${ activeUIView . id } `
287
318
) ;
288
319
}
289
320
290
- activeUIView . id = renderCommand . id ;
321
+ activeUIView . id = renderCmdViewId ;
291
322
const viewConfig =
292
- renderCommand . command === 'RENDER_ROUTED_VIEW'
293
- ? ( renderCommand . routedViewConfig as Ng1ViewConfig )
323
+ renderCommand . portalContentType === 'RENDER_ROUTED_VIEW'
324
+ ? ( renderCommand . uiViewPortalRegistration . viewConfig as Ng1ViewConfig )
294
325
: undefined ;
295
326
296
327
const newScope = scope . $new ( ) ;
@@ -384,20 +415,22 @@ function $ViewDirectiveFill(
384
415
return function ( scope : IScope , $element : JQuery ) {
385
416
const data : UIViewData = $element . data ( '$uiView' ) || { } ;
386
417
const { $renderCommand, $uiView } = data ;
387
- if ( ! $renderCommand || $renderCommand . command === 'RENDER_DEFAULT_CONTENT' ) {
418
+ if ( ! $renderCommand || $renderCommand . portalContentType === 'RENDER_DEFAULT_CONTENT' ) {
388
419
$element . html ( initial ) ;
389
420
$compile ( $element . contents ( ) as any ) ( scope ) ;
390
421
return ;
391
- } else if ( $renderCommand . command === 'RENDER_INTEROP_DIV' ) {
422
+ } else if ( $renderCommand . portalContentType === 'RENDER_INTEROP_DIV' ) {
392
423
$element . html ( '<div></div>' ) ;
393
424
$renderCommand . giveDiv ( $element . find ( 'div' ) [ 0 ] ) ;
394
425
return ;
395
426
}
396
427
397
- const cfg : Ng1ViewConfig = $renderCommand . routedViewConfig || ( { viewDecl : { } , getTemplate : noop } as any ) ;
428
+ const { uiViewPortalRegistration } = $renderCommand ;
429
+ const { viewConfig } = uiViewPortalRegistration ;
430
+ const cfg : Ng1ViewConfig = viewConfig || ( { viewDecl : { } , getTemplate : noop } as any ) ;
398
431
const resolveCtx : ResolveContext = cfg . path && new ResolveContext ( cfg . path ) ;
399
432
$element . html ( cfg . getTemplate ( $element , resolveCtx ) || initial ) ;
400
- trace . traceUIViewFill ( $uiView , $element . html ( ) ) ;
433
+ trace . traceUIViewFill ( uiViewPortalRegistration as any , $element . html ( ) ) ;
401
434
402
435
const link = $compile ( $element . contents ( ) as any ) ;
403
436
const controller = cfg . controller as angular . IControllerService ;
0 commit comments