UNPKG

16.9 kBSource Map (JSON)View Raw
1{
2 "version": 3,
3 "file": "stateEvents.min.js",
4 "sources": [
5 "@uirouter/angularjs/src/angular.ts",
6 "@uirouter/angularjs/src/legacy/stateEvents.ts"
7 ],
8 "sourcesContent": [
9 "/** @publicapi @module ng1 */ /** */\nimport * as ng_from_import from 'angular';\n/** @hidden */ declare let angular;\n/** @hidden */ const ng_from_global = angular;\n/** @hidden */ export const ng = ng_from_import && ng_from_import.module ? ng_from_import : ng_from_global;\n",
10 "/**\n * # Legacy state events\n *\n * Polyfill implementation of the UI-Router 0.2.x state events.\n *\n * The 0.2.x state events are deprecated. We recommend moving to Transition Hooks instead, as they\n * provide much more flexibility, support async, and provide the context (the Transition, etc) necessary\n * to implement meaningful application behaviors.\n *\n * To enable these state events, include the `stateEvents.js` file in your project, e.g.,\n * ```\n * <script src=\"stateEvents.js\"></script>\n * ```\n * and also make sure you depend on the `ui.router.state.events` angular module, e.g.,\n * ```\n * angular.module(\"myApplication\", ['ui.router', 'ui.router.state.events']\n * ```\n *\n * @publicapi @module ng1_state_events\n */ /** */\nimport { ng as angular } from '../angular';\nimport { IScope, IAngularEvent, IServiceProviderFactory } from 'angular';\nimport {\n Obj,\n TargetState,\n StateService,\n Transition,\n TransitionService,\n UrlRouter,\n HookResult,\n UIInjector,\n} from '@uirouter/core';\nimport { StateProvider } from '../stateProvider';\n\n/**\n * An event broadcast on `$rootScope` when the state transition **begins**.\n *\n * ### Deprecation warning: use [[TransitionService.onStart]] instead\n *\n * You can use `event.preventDefault()`\n * to prevent the transition from happening and then the transition promise will be\n * rejected with a `'transition prevented'` value.\n *\n * Additional arguments to the event handler are provided:\n * - `toState`: the Transition Target state\n * - `toParams`: the Transition Target Params\n * - `fromState`: the state the transition is coming from\n * - `fromParams`: the parameters from the state the transition is coming from\n * - `options`: any Transition Options\n * - `$transition$`: the [[Transition]]\n *\n * #### Example:\n * ```js\n * $rootScope.$on('$stateChangeStart', function(event, transition) {\n * event.preventDefault();\n * // transitionTo() promise will be rejected with\n * // a 'transition prevented' error\n * })\n * ```\n *\n * @event $stateChangeStart\n * @deprecated\n */\nexport let $stateChangeStart: IAngularEvent;\n\n/**\n * An event broadcast on `$rootScope` if a transition is **cancelled**.\n *\n * ### Deprecation warning: use [[TransitionService.onStart]] instead\n *\n * Additional arguments to the event handler are provided:\n * - `toState`: the Transition Target state\n * - `toParams`: the Transition Target Params\n * - `fromState`: the state the transition is coming from\n * - `fromParams`: the parameters from the state the transition is coming from\n * - `options`: any Transition Options\n * - `$transition$`: the [[Transition]] that was cancelled\n *\n * @event $stateChangeCancel\n * @deprecated\n */\nexport let $stateChangeCancel: IAngularEvent;\n\n/**\n * An event broadcast on `$rootScope` once the state transition is **complete**.\n *\n * ### Deprecation warning: use [[TransitionService.onStart]] and [[Transition.promise]], or [[Transition.onSuccess]]\n *\n * Additional arguments to the event handler are provided:\n * - `toState`: the Transition Target state\n * - `toParams`: the Transition Target Params\n * - `fromState`: the state the transition is coming from\n * - `fromParams`: the parameters from the state the transition is coming from\n * - `options`: any Transition Options\n * - `$transition$`: the [[Transition]] that just succeeded\n *\n * @event $stateChangeSuccess\n * @deprecated\n */\nexport let $stateChangeSuccess: IAngularEvent;\n\n/**\n * An event broadcast on `$rootScope` when an **error occurs** during transition.\n *\n * ### Deprecation warning: use [[TransitionService.onStart]] and [[Transition.promise]], or [[Transition.onError]]\n *\n * It's important to note that if you\n * have any errors in your resolve functions (javascript errors, non-existent services, etc)\n * they will not throw traditionally. You must listen for this $stateChangeError event to\n * catch **ALL** errors.\n *\n * Additional arguments to the event handler are provided:\n * - `toState`: the Transition Target state\n * - `toParams`: the Transition Target Params\n * - `fromState`: the state the transition is coming from\n * - `fromParams`: the parameters from the state the transition is coming from\n * - `error`: The reason the transition errored.\n * - `options`: any Transition Options\n * - `$transition$`: the [[Transition]] that errored\n *\n * @event $stateChangeError\n * @deprecated\n */\nexport let $stateChangeError: IAngularEvent;\n\n/**\n * An event broadcast on `$rootScope` when a requested state **cannot be found** using the provided state name.\n *\n * ### Deprecation warning: use [[StateService.onInvalid]] instead\n *\n * The event is broadcast allowing any handlers a single chance to deal with the error (usually by\n * lazy-loading the unfound state). A `TargetState` object is passed to the listener handler,\n * you can see its properties in the example. You can use `event.preventDefault()` to abort the\n * transition and the promise returned from `transitionTo()` will be rejected with a\n * `'transition aborted'` error.\n *\n * Additional arguments to the event handler are provided:\n * - `unfoundState` Unfound State information. Contains: `to, toParams, options` properties.\n * - `fromState`: the state the transition is coming from\n * - `fromParams`: the parameters from the state the transition is coming from\n * - `options`: any Transition Options\n *\n * #### Example:\n * ```js\n * // somewhere, assume lazy.state has not been defined\n * $state.go(\"lazy.state\", { a: 1, b: 2 }, { inherit: false });\n *\n * // somewhere else\n * $scope.$on('$stateNotFound', function(event, transition) {\n * function(event, unfoundState, fromState, fromParams){\n * console.log(unfoundState.to); // \"lazy.state\"\n * console.log(unfoundState.toParams); // {a:1, b:2}\n * console.log(unfoundState.options); // {inherit:false} + default options\n * });\n * ```\n *\n * @event $stateNotFound\n * @deprecated\n */\nexport let $stateNotFound: IAngularEvent;\n\n(function () {\n const { isFunction, isString } = angular;\n\n function applyPairs(memo: Obj, keyValTuple: any[]) {\n let key: string, value: any;\n if (Array.isArray(keyValTuple)) [key, value] = keyValTuple;\n if (!isString(key)) throw new Error('invalid parameters to applyPairs');\n memo[key] = value;\n return memo;\n }\n\n function stateChangeStartHandler($transition$: Transition) {\n if (!$transition$.options().notify || !$transition$.valid() || $transition$.ignored()) return;\n\n const $injector = $transition$.injector();\n const $stateEvents = $injector.get('$stateEvents');\n const $rootScope = $injector.get('$rootScope');\n const $state = $injector.get('$state');\n const $urlRouter = $injector.get('$urlRouter');\n\n const enabledEvents = $stateEvents.provider.enabled();\n\n const toParams = $transition$.params('to');\n const fromParams = $transition$.params('from');\n\n if (enabledEvents.$stateChangeSuccess) {\n const startEvent = $rootScope.$broadcast(\n '$stateChangeStart',\n $transition$.to(),\n toParams,\n $transition$.from(),\n fromParams,\n $transition$.options(),\n $transition$\n );\n\n if (startEvent.defaultPrevented) {\n if (enabledEvents.$stateChangeCancel) {\n $rootScope.$broadcast(\n '$stateChangeCancel',\n $transition$.to(),\n toParams,\n $transition$.from(),\n fromParams,\n $transition$.options(),\n $transition$\n );\n }\n // Don't update and resync url if there's been a new transition started. see issue #2238, #600\n if ($state.transition == null) $urlRouter.update();\n return false;\n }\n\n // right after global state is updated\n const successOpts = { priority: 9999 };\n $transition$.onSuccess(\n {},\n function () {\n $rootScope.$broadcast(\n '$stateChangeSuccess',\n $transition$.to(),\n toParams,\n $transition$.from(),\n fromParams,\n $transition$.options(),\n $transition$\n );\n },\n successOpts\n );\n }\n\n if (enabledEvents.$stateChangeError) {\n $transition$.promise['catch'](function (error) {\n if (error && (error.type === 2 /* RejectType.SUPERSEDED */ || error.type === 3) /* RejectType.ABORTED */)\n return;\n\n const evt = $rootScope.$broadcast(\n '$stateChangeError',\n $transition$.to(),\n toParams,\n $transition$.from(),\n fromParams,\n error,\n $transition$.options(),\n $transition$\n );\n\n if (!evt.defaultPrevented) {\n $urlRouter.update();\n }\n });\n }\n }\n\n stateNotFoundHandler.$inject = ['$to$', '$from$', '$state', '$rootScope', '$urlRouter'];\n function stateNotFoundHandler($to$: TargetState, $from$: TargetState, injector: UIInjector): HookResult {\n const $state: StateService = injector.get('$state');\n const $rootScope: IScope = injector.get('$rootScope');\n const $urlRouter: UrlRouter = injector.get('$urlRouter');\n\n interface StateNotFoundEvent extends IAngularEvent {\n retry: Promise<any>;\n }\n\n const redirect = { to: $to$.identifier(), toParams: $to$.params(), options: $to$.options() };\n const e = <StateNotFoundEvent>$rootScope.$broadcast('$stateNotFound', redirect, $from$.state(), $from$.params());\n\n if (e.defaultPrevented || e.retry) $urlRouter.update();\n\n function redirectFn(): TargetState {\n return $state.target(redirect.to, redirect.toParams, redirect.options);\n }\n\n if (e.defaultPrevented) {\n return false;\n } else if (e.retry || !!$state.get(redirect.to)) {\n return e.retry && isFunction(e.retry.then) ? e.retry.then(redirectFn) : redirectFn();\n }\n }\n\n $StateEventsProvider.$inject = ['$stateProvider'];\n function $StateEventsProvider($stateProvider: StateProvider) {\n $StateEventsProvider.prototype.instance = this;\n\n interface IEventsToggle {\n [key: string]: boolean;\n $stateChangeStart: boolean;\n $stateNotFound: boolean;\n $stateChangeSuccess: boolean;\n $stateChangeError: boolean;\n }\n\n let runtime = false;\n const allEvents = ['$stateChangeStart', '$stateNotFound', '$stateChangeSuccess', '$stateChangeError'];\n const enabledStateEvents = <IEventsToggle>allEvents.map((e) => [e, true]).reduce(applyPairs, {});\n\n function assertNotRuntime() {\n if (runtime) throw new Error('Cannot enable events at runtime (use $stateEventsProvider');\n }\n\n /**\n * Enables the deprecated UI-Router 0.2.x State Events\n * [ '$stateChangeStart', '$stateNotFound', '$stateChangeSuccess', '$stateChangeError' ]\n */\n this.enable = function (...events: string[]) {\n assertNotRuntime();\n if (!events || !events.length) events = allEvents;\n events.forEach((event) => (enabledStateEvents[event] = true));\n };\n\n /**\n * Disables the deprecated UI-Router 0.2.x State Events\n * [ '$stateChangeStart', '$stateNotFound', '$stateChangeSuccess', '$stateChangeError' ]\n */\n this.disable = function (...events: string[]) {\n assertNotRuntime();\n if (!events || !events.length) events = allEvents;\n events.forEach((event) => delete enabledStateEvents[event]);\n };\n\n this.enabled = () => enabledStateEvents;\n\n this.$get = $get;\n $get.$inject = ['$transitions'];\n function $get($transitions: TransitionService) {\n runtime = true;\n\n if (enabledStateEvents['$stateNotFound']) $stateProvider.onInvalid(stateNotFoundHandler);\n if (enabledStateEvents.$stateChangeStart) $transitions.onBefore({}, stateChangeStartHandler, { priority: 1000 });\n\n return {\n provider: $StateEventsProvider.prototype.instance,\n };\n }\n }\n\n angular\n .module('ui.router.state.events', ['ui.router.state'])\n .provider('$stateEvents', ($StateEventsProvider as any) as IServiceProviderFactory)\n .run([\n '$stateEvents',\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n function ($stateEvents: any) {\n /* Invokes $get() */\n },\n ]);\n})();\n"
11 ],
12 "names": [
13 "ng_from_global",
14 "angular",
15 "ng",
16 "ng_from_import",
17 "ng_from_import.module",
18 "isFunction",
19 "isString",
20 "applyPairs",
21 "memo",
22 "keyValTuple",
23 "key",
24 "value",
25 "Array",
26 "isArray",
27 "Error",
28 "stateChangeStartHandler",
29 "$transition$",
30 "options",
31 "notify",
32 "valid",
33 "ignored",
34 "$injector",
35 "injector",
36 "$stateEvents",
37 "get",
38 "$rootScope",
39 "$state",
40 "$urlRouter",
41 "enabledEvents",
42 "provider",
43 "enabled",
44 "toParams",
45 "params",
46 "fromParams",
47 "$stateChangeSuccess",
48 "$broadcast",
49 "to",
50 "from",
51 "defaultPrevented",
52 "$stateChangeCancel",
53 "transition",
54 "update",
55 "onSuccess",
56 "priority",
57 "$stateChangeError",
58 "promise",
59 "error",
60 "type",
61 "stateNotFoundHandler",
62 "$to$",
63 "$from$",
64 "redirect",
65 "identifier",
66 "e",
67 "state",
68 "redirectFn",
69 "target",
70 "retry",
71 "then",
72 "$StateEventsProvider",
73 "$stateProvider",
74 "prototype",
75 "instance",
76 "this",
77 "runtime",
78 "allEvents",
79 "enabledStateEvents",
80 "map",
81 "reduce",
82 "assertNotRuntime",
83 "$get",
84 "$transitions",
85 "onInvalid",
86 "$stateChangeStart",
87 "onBefore",
88 "enable",
89 "_i",
90 "events",
91 "length",
92 "forEach",
93 "event",
94 "disable",
95 "$inject",
96 "module",
97 "run",
98 "$stateNotFound"
99 ],
100 "mappings": ";;;;;;0QAGe,IAAMA,EAAiBC,QACVC,EAAKC,GAAkBC,SAAwBD,EAAiBH,GC6J5F,WACU,IAAAK,EAAyBJ,aAAbK,EAAaL,WAEjC,SAASM,EAAWC,EAAWC,GAC7B,IAAIC,EAAaC,EAEjB,GADIC,MAAMC,QAAQJ,KAAeC,EAAcD,KAATE,EAASF,OAC1CH,EAASI,GAAM,MAAM,IAAII,MAAM,oCAEpC,OADAN,EAAKE,GAAOC,EACLH,EAGT,SAASO,EAAwBC,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