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aAAa,CAAC,IAAI,CAAC,CAAC;IAC3E,CAAC,EAnBgF,CAmBhF,CAAC;IA8LJ,kBAAC;CAAA,AA9RD,IA8RC;AA9RY,kCAAW",
10 "sourcesContent": [
11 "import { equals, applyPairs, removeFrom, TypedMap, inArray, find } from '../common/common';\nimport { curry, prop } from '../common/hof';\nimport { isString, isArray } from '../common/predicates';\nimport { trace } from '../common/trace';\nimport { PathNode } from '../path/pathNode';\nimport { ActiveUIView, ViewContext, ViewConfig } from './interface';\nimport { _ViewDeclaration } from '../state/interface';\nimport { UIRouter } from '../router';\n\nexport type ViewConfigFactory = (path: PathNode[], decl: _ViewDeclaration) => ViewConfig | ViewConfig[];\n\nexport interface ViewServicePluginAPI {\n _rootViewContext(context?: ViewContext): ViewContext;\n _viewConfigFactory(viewType: string, factory: ViewConfigFactory);\n /** @param id router.$id + \".\" + uiView.id */\n _registeredUIView(id: string): ActiveUIView;\n _registeredUIViews(): ActiveUIView[];\n _activeViewConfigs(): ViewConfig[];\n _onSync(listener: ViewSyncListener): Function;\n}\n\n// A uiView and its matching viewConfig\nexport interface ViewTuple {\n uiView: ActiveUIView;\n viewConfig: ViewConfig;\n}\n\nexport interface ViewSyncListener {\n (viewTuples: ViewTuple[]): void;\n}\n\n/**\n * The View service\n *\n * This service pairs existing `ui-view` components (which live in the DOM)\n * with view configs (from the state declaration objects: [[StateDeclaration.views]]).\n *\n * - After a successful Transition, the views from the newly entered states are activated via [[activateViewConfig]].\n * The views from exited states are deactivated via [[deactivateViewConfig]].\n * (See: the [[registerActivateViews]] Transition Hook)\n *\n * - As `ui-view` components pop in and out of existence, they register themselves using [[registerUIView]].\n *\n * - When the [[sync]] function is called, the registered `ui-view`(s) ([[ActiveUIView]])\n * are configured with the matching [[ViewConfig]](s)\n *\n */\nexport class ViewService {\n /** @internal */ private _uiViews: ActiveUIView[] = [];\n /** @internal */ private _viewConfigs: ViewConfig[] = [];\n /** @internal */ private _rootContext: ViewContext;\n /** @internal */ private _viewConfigFactories: { [key: string]: ViewConfigFactory } = {};\n /** @internal */ private _listeners: ViewSyncListener[] = [];\n\n /** @internal */\n public _pluginapi: ViewServicePluginAPI = {\n _rootViewContext: this._rootViewContext.bind(this),\n _viewConfigFactory: this._viewConfigFactory.bind(this),\n _registeredUIView: (id: string) => find(this._uiViews, (view) => `${this.router.$id}.${view.id}` === id),\n _registeredUIViews: () => this._uiViews,\n _activeViewConfigs: () => this._viewConfigs,\n _onSync: (listener: ViewSyncListener) => {\n this._listeners.push(listener);\n return () => removeFrom(this._listeners, listener);\n },\n };\n\n /**\n * Given a ui-view and a ViewConfig, determines if they \"match\".\n *\n * A ui-view has a fully qualified name (fqn) and a context object. The fqn is built from its overall location in\n * the DOM, describing its nesting relationship to any parent ui-view tags it is nested inside of.\n *\n * A ViewConfig has a target ui-view name and a context anchor. The ui-view name can be a simple name, or\n * can be a segmented ui-view path, describing a portion of a ui-view fqn.\n *\n * In order for a ui-view to match ViewConfig, ui-view's $type must match the ViewConfig's $type\n *\n * If the ViewConfig's target ui-view name is a simple name (no dots), then a ui-view matches if:\n * - the ui-view's name matches the ViewConfig's target name\n * - the ui-view's context matches the ViewConfig's anchor\n *\n * If the ViewConfig's target ui-view name is a segmented name (with dots), then a ui-view matches if:\n * - There exists a parent ui-view where:\n * - the parent ui-view's name matches the first segment (index 0) of the ViewConfig's target name\n * - the parent ui-view's context matches the ViewConfig's anchor\n * - And the remaining segments (index 1..n) of the ViewConfig's target name match the tail of the ui-view's fqn\n *\n * Example:\n *\n * DOM:\n * <ui-view> <!-- created in the root context (name: \"\") -->\n * <ui-view name=\"foo\"> <!-- created in the context named: \"A\" -->\n * <ui-view> <!-- created in the context named: \"A.B\" -->\n * <ui-view name=\"bar\"> <!-- created in the context named: \"A.B.C\" -->\n * </ui-view>\n * </ui-view>\n * </ui-view>\n * </ui-view>\n *\n * uiViews: [\n * { fqn: \"$default\", creationContext: { name: \"\" } },\n * { fqn: \"$default.foo\", creationContext: { name: \"A\" } },\n * { fqn: \"$default.foo.$default\", creationContext: { name: \"A.B\" } }\n * { fqn: \"$default.foo.$default.bar\", creationContext: { name: \"A.B.C\" } }\n * ]\n *\n * These four view configs all match the ui-view with the fqn: \"$default.foo.$default.bar\":\n *\n * - ViewConfig1: { uiViewName: \"bar\", uiViewContextAnchor: \"A.B.C\" }\n * - ViewConfig2: { uiViewName: \"$default.bar\", uiViewContextAnchor: \"A.B\" }\n * - ViewConfig3: { uiViewName: \"foo.$default.bar\", uiViewContextAnchor: \"A\" }\n * - ViewConfig4: { uiViewName: \"$default.foo.$default.bar\", uiViewContextAnchor: \"\" }\n *\n * Using ViewConfig3 as an example, it matches the ui-view with fqn \"$default.foo.$default.bar\" because:\n * - The ViewConfig's segmented target name is: [ \"foo\", \"$default\", \"bar\" ]\n * - There exists a parent ui-view (which has fqn: \"$default.foo\") where:\n * - the parent ui-view's name \"foo\" matches the first segment \"foo\" of the ViewConfig's target name\n * - the parent ui-view's context \"A\" matches the ViewConfig's anchor context \"A\"\n * - And the remaining segments [ \"$default\", \"bar\" ].join(\".\"_ of the ViewConfig's target name match\n * the tail of the ui-view's fqn \"default.bar\"\n *\n * @internal\n */\n static matches = (uiViewsByFqn: TypedMap<ActiveUIView>, uiView: ActiveUIView) => (viewConfig: ViewConfig) => {\n // Don't supply an ng1 ui-view with an ng2 ViewConfig, etc\n if (uiView.$type !== viewConfig.viewDecl.$type) return false;\n\n // Split names apart from both viewConfig and uiView into segments\n const vc = viewConfig.viewDecl;\n const vcSegments = vc.$uiViewName.split('.');\n const uivSegments = uiView.fqn.split('.');\n\n // Check if the tails of the segment arrays match. ex, these arrays' tails match:\n // vc: [\"foo\", \"bar\"], uiv fqn: [\"$default\", \"foo\", \"bar\"]\n if (!equals(vcSegments, uivSegments.slice(0 - vcSegments.length))) return false;\n\n // Now check if the fqn ending at the first segment of the viewConfig matches the context:\n // [\"$default\", \"foo\"].join(\".\") == \"$default.foo\", does the ui-view $default.foo context match?\n const negOffset = 1 - vcSegments.length || undefined;\n const fqnToFirstSegment = uivSegments.slice(0, negOffset).join('.');\n const uiViewContext = uiViewsByFqn[fqnToFirstSegment].creationContext;\n return vc.$uiViewContextAnchor === (uiViewContext && uiViewContext.name);\n };\n\n /**\n * Normalizes a view's name from a state.views configuration block.\n *\n * This should be used by a framework implementation to calculate the values for\n * [[_ViewDeclaration.$uiViewName]] and [[_ViewDeclaration.$uiViewContextAnchor]].\n *\n * @param context the context object (state declaration) that the view belongs to\n * @param rawViewName the name of the view, as declared in the [[StateDeclaration.views]]\n *\n * @returns the normalized uiViewName and uiViewContextAnchor that the view targets\n */\n static normalizeUIViewTarget(context: ViewContext, rawViewName = '') {\n // TODO: Validate incoming view name with a regexp to allow:\n // ex: \"view.name@foo.bar\" , \"^.^.view.name\" , \"view.name@^.^\" , \"\" ,\n // \"@\" , \"$default@^\" , \"!$default.$default\" , \"!foo.bar\"\n const viewAtContext: string[] = rawViewName.split('@');\n let uiViewName = viewAtContext[0] || '$default'; // default to unnamed view\n let uiViewContextAnchor = isString(viewAtContext[1]) ? viewAtContext[1] : '^'; // default to parent context\n\n // Handle relative view-name sugar syntax.\n // Matches rawViewName \"^.^.^.foo.bar\" into array: [\"^.^.^.foo.bar\", \"^.^.^\", \"foo.bar\"],\n const relativeViewNameSugar = /^(\\^(?:\\.\\^)*)\\.(.*$)/.exec(uiViewName);\n if (relativeViewNameSugar) {\n // Clobbers existing contextAnchor (rawViewName validation will fix this)\n uiViewContextAnchor = relativeViewNameSugar[1]; // set anchor to \"^.^.^\"\n uiViewName = relativeViewNameSugar[2]; // set view-name to \"foo.bar\"\n }\n\n if (uiViewName.charAt(0) === '!') {\n uiViewName = uiViewName.substr(1);\n uiViewContextAnchor = ''; // target absolutely from root\n }\n\n // handle parent relative targeting \"^.^.^\"\n const relativeMatch = /^(\\^(?:\\.\\^)*)$/;\n if (relativeMatch.exec(uiViewContextAnchor)) {\n const anchorState = uiViewContextAnchor.split('.').reduce((anchor, x) => anchor.parent, context);\n uiViewContextAnchor = anchorState.name;\n } else if (uiViewContextAnchor === '.') {\n uiViewContextAnchor = context.name;\n }\n\n return { uiViewName, uiViewContextAnchor };\n }\n\n /** @internal */\n constructor(/** @internal */ private router: UIRouter) {}\n\n /** @internal */\n private _rootViewContext(context?: ViewContext): ViewContext {\n return (this._rootContext = context || this._rootContext);\n }\n /** @internal */\n private _viewConfigFactory(viewType: string, factory: ViewConfigFactory) {\n this._viewConfigFactories[viewType] = factory;\n }\n\n createViewConfig(path: PathNode[], decl: _ViewDeclaration): ViewConfig[] {\n const cfgFactory = this._viewConfigFactories[decl.$type];\n if (!cfgFactory) throw new Error('ViewService: No view config factory registered for type ' + decl.$type);\n const cfgs = cfgFactory(path, decl);\n return isArray(cfgs) ? cfgs : [cfgs];\n }\n\n /**\n * Deactivates a ViewConfig.\n *\n * This function deactivates a `ViewConfig`.\n * After calling [[sync]], it will un-pair from any `ui-view` with which it is currently paired.\n *\n * @param viewConfig The ViewConfig view to deregister.\n */\n deactivateViewConfig(viewConfig: ViewConfig) {\n trace.traceViewServiceEvent('<- Removing', viewConfig);\n removeFrom(this._viewConfigs, viewConfig);\n }\n\n activateViewConfig(viewConfig: ViewConfig) {\n trace.traceViewServiceEvent('-> Registering', <any>viewConfig);\n this._viewConfigs.push(viewConfig);\n }\n\n sync() {\n const uiViewsByFqn: TypedMap<ActiveUIView> = this._uiViews.map((uiv) => [uiv.fqn, uiv]).reduce(applyPairs, <any>{});\n\n // Return a weighted depth value for a uiView.\n // The depth is the nesting depth of ui-views (based on FQN; times 10,000)\n // plus the depth of the state that is populating the uiView\n function uiViewDepth(uiView: ActiveUIView) {\n const stateDepth = (context: ViewContext) => (context && context.parent ? stateDepth(context.parent) + 1 : 1);\n return uiView.fqn.split('.').length * 10000 + stateDepth(uiView.creationContext);\n }\n\n // Return the ViewConfig's context's depth in the context tree.\n function viewConfigDepth(config: ViewConfig) {\n let context: ViewContext = config.viewDecl.$context,\n count = 0;\n while (++count && context.parent) context = context.parent;\n return count;\n }\n\n // Given a depth function, returns a compare function which can return either ascending or descending order\n const depthCompare = curry((depthFn, posNeg, left, right) => posNeg * (depthFn(left) - depthFn(right)));\n\n const matchingConfigPair = (uiView: ActiveUIView): ViewTuple => {\n const matchingConfigs = this._viewConfigs.filter(ViewService.matches(uiViewsByFqn, uiView));\n if (matchingConfigs.length > 1) {\n // This is OK. Child states can target a ui-view that the parent state also targets (the child wins)\n // Sort by depth and return the match from the deepest child\n // console.log(`Multiple matching view configs for ${uiView.fqn}`, matchingConfigs);\n matchingConfigs.sort(depthCompare(viewConfigDepth, -1)); // descending\n }\n return { uiView, viewConfig: matchingConfigs[0] };\n };\n\n const configureUIView = (tuple: ViewTuple) => {\n // If a parent ui-view is reconfigured, it could destroy child ui-views.\n // Before configuring a child ui-view, make sure it's still in the active uiViews array.\n if (this._uiViews.indexOf(tuple.uiView) !== -1) tuple.uiView.configUpdated(tuple.viewConfig);\n };\n\n // Sort views by FQN and state depth. Process uiviews nearest the root first.\n const uiViewTuples = this._uiViews.sort(depthCompare(uiViewDepth, 1)).map(matchingConfigPair);\n const matchedViewConfigs = uiViewTuples.map((tuple) => tuple.viewConfig);\n const unmatchedConfigTuples = this._viewConfigs\n .filter((config) => !inArray(matchedViewConfigs, config))\n .map((viewConfig) => ({ uiView: undefined, viewConfig }));\n\n uiViewTuples.forEach(configureUIView);\n\n const allTuples: ViewTuple[] = uiViewTuples.concat(unmatchedConfigTuples);\n this._listeners.forEach((cb) => cb(allTuples));\n trace.traceViewSync(allTuples);\n }\n\n /**\n * Registers a `ui-view` component\n *\n * When a `ui-view` component is created, it uses this method to register itself.\n * After registration the [[sync]] method is used to ensure all `ui-view` are configured with the proper [[ViewConfig]].\n *\n * Note: the `ui-view` component uses the `ViewConfig` to determine what view should be loaded inside the `ui-view`,\n * and what the view's state context is.\n *\n * Note: There is no corresponding `deregisterUIView`.\n * A `ui-view` should hang on to the return value of `registerUIView` and invoke it to deregister itself.\n *\n * @param uiView The metadata for a UIView\n * @return a de-registration function used when the view is destroyed.\n */\n registerUIView(uiView: ActiveUIView) {\n trace.traceViewServiceUIViewEvent('-> Registering', uiView);\n const uiViews = this._uiViews;\n const fqnAndTypeMatches = (uiv: ActiveUIView) => uiv.fqn === uiView.fqn && uiv.$type === uiView.$type;\n if (uiViews.filter(fqnAndTypeMatches).length)\n trace.traceViewServiceUIViewEvent('!!!! duplicate uiView named:', uiView);\n\n uiViews.push(uiView);\n this.sync();\n\n return () => {\n const idx = uiViews.indexOf(uiView);\n if (idx === -1) {\n trace.traceViewServiceUIViewEvent('Tried removing non-registered uiView', uiView);\n return;\n }\n trace.traceViewServiceUIViewEvent('<- Deregistering', uiView);\n removeFrom(uiViews)(uiView);\n };\n }\n\n /**\n * Returns the list of views currently available on the page, by fully-qualified name.\n *\n * @return {Array} Returns an array of fully-qualified view names.\n */\n available() {\n return this._uiViews.map(prop('fqn'));\n }\n\n /**\n * Returns the list of views on the page containing loaded content.\n *\n * @return {Array} Returns an array of fully-qualified view names.\n */\n active() {\n return this._uiViews.filter(prop('$config')).map(prop('name'));\n }\n}\n"
12 ]
13}
\No newline at end of file