11/** @publicapi @module directives */ /** */
22import {
33 $QLike ,
4- ActiveUIView ,
54 extend ,
65 filter ,
76 HookRegOptions ,
@@ -23,8 +22,11 @@ import {
2322 TypedMap ,
2423 UIViewPortalRenderCommand ,
2524 unnestR ,
25+ ViewConfig ,
26+ ViewContext ,
2627 ViewService ,
2728} from '@uirouter/core' ;
29+ import { UIViewPortalRegistration } from '@uirouter/core/lib/view/interface' ;
2830import { IAugmentedJQuery , IInterpolateService , IScope , ITranscludeFunction } from 'angular' ;
2931import { ng as angular } from '../angular' ;
3032import { Ng1Controller , Ng1StateDeclaration } from '../interface' ;
@@ -172,6 +174,26 @@ export type UIViewAnimData = {
172174 * ```
173175 */
174176export 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+
175197// eslint-disable-next-line prefer-const
176198uiView = [
177199 '$view' ,
@@ -244,14 +266,22 @@ uiView = [
244266 // },
245267 } ;
246268
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 ) ;
249278
250279 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 ) ;
253282 } ) ;
254283
284+ // backwards compat
255285 $element . data ( '$uiView' , { $uiView : activeUIView } ) ;
256286
257287 function cleanupLastView ( ) {
@@ -262,7 +292,7 @@ uiView = [
262292 }
263293
264294 if ( currentScope ) {
265- trace . traceUIViewEvent ( 'Destroying scope' , activeUIView ) ;
295+ trace . traceUIViewEvent ( 'Destroying scope' , registration ) ;
266296 currentScope . $destroy ( ) ;
267297 currentScope = null ;
268298 }
@@ -281,16 +311,17 @@ uiView = [
281311 }
282312
283313 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 ) {
285316 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 } `
287318 ) ;
288319 }
289320
290- activeUIView . id = renderCommand . id ;
321+ activeUIView . id = renderCmdViewId ;
291322 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 )
294325 : undefined ;
295326
296327 const newScope = scope . $new ( ) ;
@@ -384,20 +415,22 @@ function $ViewDirectiveFill(
384415 return function ( scope : IScope , $element : JQuery ) {
385416 const data : UIViewData = $element . data ( '$uiView' ) || { } ;
386417 const { $renderCommand, $uiView } = data ;
387- if ( ! $renderCommand || $renderCommand . command === 'RENDER_DEFAULT_CONTENT' ) {
418+ if ( ! $renderCommand || $renderCommand . portalContentType === 'RENDER_DEFAULT_CONTENT' ) {
388419 $element . html ( initial ) ;
389420 $compile ( $element . contents ( ) as any ) ( scope ) ;
390421 return ;
391- } else if ( $renderCommand . command === 'RENDER_INTEROP_DIV' ) {
422+ } else if ( $renderCommand . portalContentType === 'RENDER_INTEROP_DIV' ) {
392423 $element . html ( '<div></div>' ) ;
393424 $renderCommand . giveDiv ( $element . find ( 'div' ) [ 0 ] ) ;
394425 return ;
395426 }
396427
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 ) ;
398431 const resolveCtx : ResolveContext = cfg . path && new ResolveContext ( cfg . path ) ;
399432 $element . html ( cfg . getTemplate ( $element , resolveCtx ) || initial ) ;
400- trace . traceUIViewFill ( $uiView , $element . html ( ) ) ;
433+ trace . traceUIViewFill ( uiViewPortalRegistration as any , $element . html ( ) ) ;
401434
402435 const link = $compile ( $element . contents ( ) as any ) ;
403436 const controller = cfg . controller as angular . IControllerService ;
0 commit comments