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E,CAAC;QAEjC,yGAAyG;QACzG,IAAM,SAAS,GAAG,UAAC,IAAa;YAC9B,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,KAAI,CAAC,MAAM,CAAC,CAAC;YAC3C,OAAO,KAAK,IAAI,EAAE,KAAK,OAAA,EAAE,IAAI,MAAA,EAAE,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACrE,CAAC,CAAC;QAEF,4BAA4B;QAC5B,kCAAkC;QAClC,yFAAyF;QACzF,mDAAmD;QACnD,IAAI,IAAiB,CAAC;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACrC,gFAAgF;YAChF,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM;gBAAE,MAAM;YAExD,IAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACpC,4BAA4B;YAC5B,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;SAC5E;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAqGH,iBAAC;AAAD,CAAC,AAxQD,IAwQC;AAxQY,gCAAU",
|
10 | "sourcesContent": [
|
11 | "import { UIRouter } from '../router';\nimport { extend, is, isString, LocationServices, pattern } from '../common';\nimport { MatchResult, UrlParts, UrlRule, UrlSyncApi } from './interface';\nimport { UrlRules } from './urlRules';\nimport { UrlConfig } from './urlConfig';\nimport { TargetState, TargetStateDef } from '../state';\n\n/**\n * API for URL management\n */\nexport class UrlService implements LocationServices, UrlSyncApi {\n /** @internal */ private _stopListeningFn: Function;\n /** @internal */ interceptDeferred = false;\n\n /**\n * The nested [[UrlRules]] API for managing URL rules and rewrites\n *\n * See: [[UrlRules]] for details\n */\n public rules = new UrlRules(this.router);\n\n /**\n * The nested [[UrlConfig]] API to configure the URL and retrieve URL information\n *\n * See: [[UrlConfig]] for details\n */\n public config = new UrlConfig(this.router);\n\n /** @internal */\n constructor(/** @internal */ private router: UIRouter) {}\n /** @internal */\n public dispose() {\n this.listen(false);\n (this.rules as UrlRules).dispose();\n }\n\n /**\n * Gets the current URL parts\n *\n * This method returns the different parts of the current URL (the [[path]], [[search]], and [[hash]]) as a [[UrlParts]] object.\n */\n public parts(): UrlParts {\n return { path: this.path(), search: this.search(), hash: this.hash() };\n }\n\n /**\n * Activates the best rule for the current URL\n *\n * Checks the current URL for a matching [[UrlRule]], then invokes that rule's handler.\n * This method is called internally any time the URL has changed.\n *\n * This effectively activates the state (or redirect, etc) which matches the current URL.\n *\n * #### Example:\n * ```js\n * urlService.deferIntercept();\n *\n * fetch('/states.json').then(resp => resp.json()).then(data => {\n * data.forEach(state => $stateRegistry.register(state));\n * urlService.listen();\n * // Find the matching URL and invoke the handler.\n * urlService.sync();\n * });\n * ```\n */\n public sync(evt?) {\n if (evt && evt.defaultPrevented) return;\n const { urlService, stateService } = this.router;\n\n const url: UrlParts = { path: urlService.path(), search: urlService.search(), hash: urlService.hash() };\n const best = this.match(url);\n\n const applyResult = pattern([\n [isString, (newurl: string) => urlService.url(newurl, true)],\n [TargetState.isDef, (def: TargetStateDef) => stateService.go(def.state, def.params, def.options)],\n [is(TargetState), (target: TargetState) => stateService.go(target.state(), target.params(), target.options())],\n ]);\n\n applyResult(best && best.rule.handler(best.match, url, this.router));\n }\n\n /**\n * Starts or stops listening for URL changes\n *\n * Call this sometime after calling [[deferIntercept]] to start monitoring the url.\n * This causes UI-Router to start listening for changes to the URL, if it wasn't already listening.\n *\n * If called with `false`, UI-Router will stop listening (call listen(true) to start listening again).\n *\n * #### Example:\n * ```js\n * urlService.deferIntercept();\n *\n * fetch('/states.json').then(resp => resp.json()).then(data => {\n * data.forEach(state => $stateRegistry.register(state));\n * // Start responding to URL changes\n * urlService.listen();\n * urlService.sync();\n * });\n * ```\n *\n * @param enabled `true` or `false` to start or stop listening to URL changes\n */\n public listen(enabled?: boolean): Function {\n if (enabled === false) {\n this._stopListeningFn && this._stopListeningFn();\n delete this._stopListeningFn;\n } else {\n return (this._stopListeningFn =\n this._stopListeningFn || this.router.urlService.onChange((evt) => this.sync(evt)));\n }\n }\n\n /**\n * Disables monitoring of the URL.\n *\n * Call this method before UI-Router has bootstrapped.\n * It will stop UI-Router from performing the initial url sync.\n *\n * This can be useful to perform some asynchronous initialization before the router starts.\n * Once the initialization is complete, call [[listen]] to tell UI-Router to start watching and synchronizing the URL.\n *\n * #### Example:\n * ```js\n * // Prevent UI-Router from automatically intercepting URL changes when it starts;\n * urlService.deferIntercept();\n *\n * fetch('/states.json').then(resp => resp.json()).then(data => {\n * data.forEach(state => $stateRegistry.register(state));\n * urlService.listen();\n * urlService.sync();\n * });\n * ```\n *\n * @param defer Indicates whether to defer location change interception.\n * Passing no parameter is equivalent to `true`.\n */\n public deferIntercept(defer?: boolean) {\n if (defer === undefined) defer = true;\n this.interceptDeferred = defer;\n }\n\n /**\n * Matches a URL\n *\n * Given a URL (as a [[UrlParts]] object), check all rules and determine the best matching rule.\n * Return the result as a [[MatchResult]].\n */\n public match(url: UrlParts): MatchResult {\n url = extend({ path: '', search: {}, hash: '' }, url);\n const rules = this.rules.rules();\n\n // Checks a single rule. Returns { rule: rule, match: match, weight: weight } if it matched, or undefined\n const checkRule = (rule: UrlRule): MatchResult => {\n const match = rule.match(url, this.router);\n return match && { match, rule, weight: rule.matchPriority(match) };\n };\n\n // The rules are pre-sorted.\n // - Find the first matching rule.\n // - Find any other matching rule that sorted *exactly the same*, according to `.sort()`.\n // - Choose the rule with the highest match weight.\n let best: MatchResult;\n for (let i = 0; i < rules.length; i++) {\n // Stop when there is a 'best' rule and the next rule sorts differently than it.\n if (best && best.rule._group !== rules[i]._group) break;\n\n const current = checkRule(rules[i]);\n // Pick the best MatchResult\n best = !best || (current && current.weight > best.weight) ? current : best;\n }\n\n return best;\n }\n\n // Delegate these calls to the current LocationServices implementation\n /**\n * Gets the current url, or updates the url\n *\n * ### Getting the current URL\n *\n * When no arguments are passed, returns the current URL.\n * The URL is normalized using the internal [[path]]/[[search]]/[[hash]] values.\n *\n * For example, the URL may be stored in the hash ([[HashLocationServices]]) or\n * have a base HREF prepended ([[PushStateLocationServices]]).\n *\n * The raw URL in the browser might be:\n *\n * ```\n * http://mysite.com/somepath/index.html#/internal/path/123?param1=foo#anchor\n * ```\n *\n * or\n *\n * ```\n * http://mysite.com/basepath/internal/path/123?param1=foo#anchor\n * ```\n *\n * then this method returns:\n *\n * ```\n * /internal/path/123?param1=foo#anchor\n * ```\n *\n *\n * #### Example:\n * ```js\n * locationServices.url(); // \"/some/path?query=value#anchor\"\n * ```\n *\n * ### Updating the URL\n *\n * When `newurl` arguments is provided, changes the URL to reflect `newurl`\n *\n * #### Example:\n * ```js\n * locationServices.url(\"/some/path?query=value#anchor\", true);\n * ```\n *\n * @param newurl The new value for the URL.\n * This url should reflect only the new internal [[path]], [[search]], and [[hash]] values.\n * It should not include the protocol, site, port, or base path of an absolute HREF.\n * @param replace When true, replaces the current history entry (instead of appending it) with this new url\n * @param state The history's state object, i.e., pushState (if the LocationServices implementation supports it)\n *\n * @return the url (after potentially being processed)\n */\n public url = (newurl?: string, replace?: boolean, state?: any): string =>\n this.router.locationService.url(newurl, replace, state);\n\n /**\n * Gets the path part of the current url\n *\n * If the current URL is `/some/path?query=value#anchor`, this returns `/some/path`\n *\n * @return the path portion of the url\n */\n public path = (): string => this.router.locationService.path();\n\n /**\n * Gets the search part of the current url as an object\n *\n * If the current URL is `/some/path?query=value#anchor`, this returns `{ query: 'value' }`\n *\n * @return the search (query) portion of the url, as an object\n */\n public search = (): { [key: string]: any } => this.router.locationService.search();\n\n /**\n * Gets the hash part of the current url\n *\n * If the current URL is `/some/path?query=value#anchor`, this returns `anchor`\n *\n * @return the hash (anchor) portion of the url\n */\n public hash = (): string => this.router.locationService.hash();\n\n /**\n * @internal\n *\n * Registers a low level url change handler\n *\n * Note: Because this is a low level handler, it's not recommended for general use.\n *\n * #### Example:\n * ```js\n * let deregisterFn = locationServices.onChange((evt) => console.log(\"url change\", evt));\n * ```\n *\n * @param callback a function that will be called when the url is changing\n * @return a function that de-registers the callback\n */\n public onChange = (callback: EventListener): Function => this.router.locationService.onChange(callback);\n}\n"
|
12 | ]
|
13 | } |
\ | No newline at end of file |