@angular-wave/angular.ts 0.0.59 → 0.0.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/README.md +3 -0
  2. package/dist/angular-ts.esm.js +2 -2
  3. package/dist/angular-ts.umd.js +2 -2
  4. package/package.json +5 -1
  5. package/src/core/parser/lexer.html +18 -0
  6. package/src/core/parser/lexer.spec.js +300 -0
  7. package/src/core/parser/parse.js +19 -0
  8. package/src/core/parser/parser.js +1 -1
  9. package/src/core/parser/parser.test.js +19 -0
  10. package/src/core/q/q.js +46 -289
  11. package/src/core/q/q.md +229 -0
  12. package/src/core/sanitize/sanitize-uri.js +2 -3
  13. package/src/core/scope/scope.js +18 -8
  14. package/src/directive/if/if.js +6 -1
  15. package/src/filters/limit-to.js +5 -2
  16. package/src/loader.js +1 -5
  17. package/src/router/params/param-type.js +2 -1
  18. package/src/router/state/views.js +3 -0
  19. package/src/router/transition/reject-factory.js +1 -0
  20. package/src/router/url/url-rule.js +1 -1
  21. package/src/router/url/url-service.js +4 -4
  22. package/src/services/http/http.js +7 -5
  23. package/src/services/template-request.js +2 -7
  24. package/src/shared/common.js +1 -1
  25. package/src/shared/utils.js +1 -1
  26. package/src/types.js +9 -1
  27. package/types/core/parser/parse.d.ts +3 -4
  28. package/types/core/parser/parser.d.ts +1 -1
  29. package/types/core/q/q.d.ts +2 -2
  30. package/types/core/sanitize/sanitize-uri.d.ts +4 -5
  31. package/types/core/scope/scope.d.ts +19 -7
  32. package/types/loader.d.ts +0 -4
  33. package/types/router/params/param-type.d.ts +2 -1
  34. package/types/router/state/views.d.ts +2 -0
  35. package/types/router/transition/reject-factory.d.ts +1 -0
  36. package/types/router/url/url-rule.d.ts +0 -1
  37. package/types/router/url/url-service.d.ts +7 -7
  38. package/types/services/template-request.d.ts +4 -9
  39. package/types/types.d.ts +6 -1
  40. package/src/core/parser/parse.test.js +0 -12
  41. package/types-back/README.md +0 -2
  42. package/types-back/angular.d.ts +0 -146
  43. package/types-back/index.d.ts +0 -2126
  44. package/types-back/jqlite.d.ts +0 -374
  45. package/types-back/router/core/common/common.d.ts +0 -416
  46. package/types-back/router/core/common/coreservices.d.ts +0 -77
  47. package/types-back/router/core/common/glob.d.ts +0 -60
  48. package/types-back/router/core/common/hof.d.ts +0 -168
  49. package/types-back/router/core/common/index.d.ts +0 -8
  50. package/types-back/router/core/common/predicates.d.ts +0 -25
  51. package/types-back/router/core/common/queue.d.ts +0 -15
  52. package/types-back/router/core/common/safeConsole.d.ts +0 -5
  53. package/types-back/router/core/common/strings.d.ts +0 -66
  54. package/types-back/router/core/common/trace.d.ts +0 -126
  55. package/types-back/router/core/globals.d.ts +0 -43
  56. package/types-back/router/core/hooks/coreResolvables.d.ts +0 -6
  57. package/types-back/router/core/hooks/ignoredTransition.d.ts +0 -4
  58. package/types-back/router/core/hooks/invalidTransition.d.ts +0 -4
  59. package/types-back/router/core/hooks/lazyLoad.d.ts +0 -17
  60. package/types-back/router/core/hooks/onEnterExitRetain.d.ts +0 -10
  61. package/types-back/router/core/hooks/redirectTo.d.ts +0 -4
  62. package/types-back/router/core/hooks/resolve.d.ts +0 -11
  63. package/types-back/router/core/hooks/updateGlobals.d.ts +0 -4
  64. package/types-back/router/core/hooks/url.d.ts +0 -4
  65. package/types-back/router/core/hooks/views.d.ts +0 -7
  66. package/types-back/router/core/index.d.ts +0 -11
  67. package/types-back/router/core/interface.d.ts +0 -91
  68. package/types-back/router/core/params/index.d.ts +0 -12
  69. package/types-back/router/core/params/interface.d.ts +0 -606
  70. package/types-back/router/core/params/param.d.ts +0 -77
  71. package/types-back/router/core/params/paramType.d.ts +0 -65
  72. package/types-back/router/core/params/paramTypes.d.ts +0 -193
  73. package/types-back/router/core/params/stateParams.d.ts +0 -15
  74. package/types-back/router/core/path/index.d.ts +0 -2
  75. package/types-back/router/core/path/pathNode.d.ts +0 -60
  76. package/types-back/router/core/path/pathUtils.d.ts +0 -105
  77. package/types-back/router/core/resolve/index.d.ts +0 -3
  78. package/types-back/router/core/resolve/interface.d.ts +0 -210
  79. package/types-back/router/core/resolve/resolvable.d.ts +0 -75
  80. package/types-back/router/core/resolve/resolveContext.d.ts +0 -97
  81. package/types-back/router/core/router.d.ts +0 -57
  82. package/types-back/router/core/state/index.d.ts +0 -28
  83. package/types-back/router/core/state/interface.d.ts +0 -732
  84. package/types-back/router/core/state/stateBuilder.d.ts +0 -107
  85. package/types-back/router/core/state/stateMatcher.d.ts +0 -13
  86. package/types-back/router/core/state/stateObject.d.ts +0 -170
  87. package/types-back/router/core/state/stateQueueManager.d.ts +0 -27
  88. package/types-back/router/core/state/stateRegistry.d.ts +0 -138
  89. package/types-back/router/core/state/stateService.d.ts +0 -386
  90. package/types-back/router/core/state/targetState.d.ts +0 -105
  91. package/types-back/router/core/transition/hookBuilder.d.ts +0 -49
  92. package/types-back/router/core/transition/hookRegistry.d.ts +0 -115
  93. package/types-back/router/core/transition/index.d.ts +0 -20
  94. package/types-back/router/core/transition/interface.d.ts +0 -862
  95. package/types-back/router/core/transition/rejectFactory.d.ts +0 -103
  96. package/types-back/router/core/transition/transition.d.ts +0 -575
  97. package/types-back/router/core/transition/transitionEventType.d.ts +0 -26
  98. package/types-back/router/core/transition/transitionHook.d.ts +0 -96
  99. package/types-back/router/core/transition/transitionService.d.ts +0 -253
  100. package/types-back/router/core/url/index.d.ts +0 -8
  101. package/types-back/router/core/url/interface.d.ts +0 -169
  102. package/types-back/router/core/url/urlConfig.d.ts +0 -144
  103. package/types-back/router/core/url/urlMatcher.d.ts +0 -185
  104. package/types-back/router/core/url/urlMatcherFactory.d.ts +0 -56
  105. package/types-back/router/core/url/urlRouter.d.ts +0 -101
  106. package/types-back/router/core/url/urlRule.d.ts +0 -143
  107. package/types-back/router/core/url/urlRules.d.ts +0 -251
  108. package/types-back/router/core/url/urlService.d.ts +0 -205
  109. package/types-back/router/core/view/index.d.ts +0 -2
  110. package/types-back/router/core/view/interface.d.ts +0 -46
  111. package/types-back/router/core/view/view.d.ts +0 -176
  112. package/types-back/router/directives/viewDirective.d.ts +0 -144
  113. package/types-back/router/index.d.ts +0 -17
  114. package/types-back/router/interface.d.ts +0 -500
  115. package/types-back/router/legacy/resolveService.d.ts +0 -47
  116. package/types-back/router/legacy/stateEvents.d.ts +0 -124
  117. package/types-back/router/services.d.ts +0 -15
  118. package/types-back/router/stateFilters.d.ts +0 -10
  119. package/types-back/router/stateProvider.d.ts +0 -258
  120. package/types-back/router/statebuilders/onEnterExitRetain.d.ts +0 -13
  121. package/types-back/router/statebuilders/views.d.ts +0 -53
  122. package/types-back/router/templateFactory.d.ts +0 -104
  123. package/types-back/router/viewScroll.d.ts +0 -9
@@ -1,862 +0,0 @@
1
- import { StateDeclaration } from "../state/interface";
2
- import { PredicateBinary } from "../common/common";
3
- import { Transition } from "./transition";
4
- import { StateObject } from "../state/stateObject";
5
- import { PathNode } from "../path/pathNode";
6
- import { TargetState } from "../state/targetState";
7
- import { RegisteredHook } from "./hookRegistry";
8
- /**
9
- * The TransitionOptions object can be used to change the behavior of a transition.
10
- *
11
- * It is passed as the third argument to [[StateService.go]], [[StateService.transitionTo]].
12
- * It can also be used with a `ngSref`.
13
- */
14
- export interface TransitionOptions {
15
- /**
16
- * This option changes how the Transition interacts with the browser's location bar (URL).
17
- *
18
- * - If `true`, it will update the url in the location bar.
19
- * - If `false`, it will not update the url in the location bar.
20
- * - If it is the string `"replace"`, it will update the url and also replace the last history record.
21
- *
22
- * @default `true`
23
- */
24
- location?: boolean | "replace";
25
- /**
26
- * When transitioning to relative path (e.g '`^`'), this option defines which state to be relative from.
27
- * @default `$state.current`
28
- */
29
- relative?: string | StateDeclaration | StateObject;
30
- /**
31
- * This option sets whether or not the transition's parameter values should be inherited from
32
- * the current parameter values.
33
- *
34
- * - If `true`, it will inherit parameter values from the current parameter values.
35
- * - If `false`, only the parameters which are provided to `transitionTo` will be used.
36
- *
37
- * @default `true`
38
- */
39
- inherit?: boolean;
40
- /**
41
- * @deprecated
42
- */
43
- notify?: boolean;
44
- /**
45
- * This option may be used to force states which are currently active to reload.
46
- *
47
- * During a normal transition, a state is "retained" if:
48
- * - It was previously active
49
- * - The state's parameter values have not changed
50
- * - All the parent states' parameter values have not changed
51
- *
52
- * Forcing a reload of a state will cause it to be exited and entered, which will:
53
- * - Refetch that state's resolve data
54
- * - Exit the state (onExit hook)
55
- * - Re-enter the state (onEnter hook)
56
- * - Re-render the views (controllers and templates)
57
- *
58
- * - When `true`, the destination state (and all parent states) will be reloaded.
59
- * - When it is a string and is the name of a state, or when it is a State object,
60
- * that state and any children states will be reloaded.
61
- *
62
- * @default `false`
63
- */
64
- reload?: boolean | string | StateDeclaration | StateObject;
65
- /**
66
- * You can define your own Transition Options inside this property and use them, e.g., from a Transition Hook
67
- */
68
- custom?: any;
69
- /**
70
- * This option may be used to cancel the active transition (if one is active) in favour of the this one.
71
- * This is the default behaviour or ui-router.
72
- *
73
- *
74
- * - When `true`, the active transition will be canceled and new transition will begin.
75
- * - when `false`, the transition will be canceled if a transition is already running. This can be useful in cases where
76
- * you only want to navigate to a different state if you are not already navigating somewhere.
77
- *
78
- * @default `true`
79
- */
80
- supercede?: boolean;
81
- /** @internal */
82
- reloadState?: StateObject;
83
- /** @internal
84
- * If this transition is a redirect, this property should be the original Transition (which was redirected to this one)
85
- */
86
- redirectedFrom?: Transition;
87
- /** @internal */
88
- current?: () => Transition;
89
- /** @internal */
90
- source?: "sref" | "url" | "redirect" | "otherwise" | "unknown";
91
- }
92
- export interface TransitionHookOptions {
93
- current?: () => Transition;
94
- transition?: Transition;
95
- hookType?: string;
96
- target?: any;
97
- traceData?: any;
98
- bind?: any;
99
- stateHook?: boolean;
100
- }
101
- /**
102
- * TreeChanges encapsulates the various Paths that are involved in a Transition.
103
- *
104
- * Get a TreeChanges object using [[Transition.treeChanges]]
105
- *
106
- * A Router Transition is from one Path in a State Tree to another Path. For a given Transition,
107
- * this object stores the "to" and "from" paths, as well as subsets of those: the "retained",
108
- * "exiting" and "entering" paths.
109
- *
110
- * Each path in TreeChanges is an array of [[PathNode]] objects. Each PathNode in the array corresponds to a portion
111
- * of a nested state.
112
- *
113
- * For example, if you had a nested state named `foo.bar.baz`, it would have three
114
- * portions, `foo, bar, baz`. If you transitioned **to** `foo.bar.baz` and inspected the [[TreeChanges.to]]
115
- * Path, you would find a node in the array for each portion: `foo`, `bar`, and `baz`.
116
- *
117
- * ---
118
- *
119
- * @todo show visual state tree
120
- */
121
- export interface TreeChanges {
122
- /** @nodoc */
123
- [key: string]: PathNode[] | undefined;
124
- /** The path of nodes in the state tree that the transition is coming *from* */
125
- from: PathNode[];
126
- /** The path of nodes in the state tree that the transition is going *to* */
127
- to: PathNode[];
128
- /**
129
- * The path of active nodes that the transition is retaining.
130
- *
131
- * These nodes are neither exited, nor entered.
132
- * Before and after the transition is successful, these nodes are active.
133
- */
134
- retained: PathNode[];
135
- /**
136
- * The path of active nodes that the transition is retaining with updated "to params" applied.
137
- *
138
- * These nodes are neither exited, nor entered.
139
- * Before and after the transition is successful, these nodes are active.
140
- *
141
- * This is a shallow copy of [[retained]], but with new (dynamic) parameter values from [[to]] applied.
142
- */
143
- retainedWithToParams: PathNode[];
144
- /**
145
- * The path of previously active nodes that the transition is exiting.
146
- *
147
- * After the Transition is successful, these nodes are no longer active.
148
- *
149
- * Note that a state that is being reloaded (due to parameter values changing, or `reload: true`) may be in both the
150
- * `exiting` and `entering` paths.
151
- */
152
- exiting: PathNode[];
153
- /**
154
- * The path of nodes that the transition is entering.
155
- *
156
- * After the Transition is successful, these nodes will be active.
157
- * Because they are entering, they have their resolves fetched, `onEnter` hooks run, and their views
158
- * (component(s) or controller(s)+template(s)) refreshed.
159
- *
160
- * Note that a state that is reloaded (due to parameter values changing, or `reload: true`) may be in both the
161
- * `exiting` and `entering` paths.
162
- */
163
- entering: PathNode[];
164
- }
165
- export declare type IHookRegistration = (
166
- matchCriteria: HookMatchCriteria,
167
- callback: HookFn,
168
- options?: HookRegOptions,
169
- ) => Function;
170
- /**
171
- * The signature for Transition Hooks.
172
- *
173
- * Transition hooks are callback functions that hook into the lifecycle of transitions.
174
- * As a transition runs, it reaches certain lifecycle events.
175
- * As each event occurs, the hooks which are registered for the event are called (in priority order).
176
- *
177
- * A transition hook may alter a Transition by returning a [[HookResult]].
178
- *
179
- * #### See:
180
- *
181
- * - [[IHookRegistry.onBefore]]
182
- * - [[IHookRegistry.onStart]]
183
- * - [[IHookRegistry.onFinish]]
184
- * - [[IHookRegistry.onSuccess]]
185
- * - [[IHookRegistry.onError]]
186
- *
187
- * @param transition the current [[Transition]]
188
- * @param injector (for ng1 or ng2 only) the injector service
189
- *
190
- * @returns a [[HookResult]] which may alter the transition
191
- *
192
- */
193
- export interface TransitionHookFn {
194
- (transition: Transition): HookResult;
195
- }
196
- /**
197
- * The signature for Transition State Hooks.
198
- *
199
- * A function which hooks into a lifecycle event for a specific state.
200
- *
201
- * Transition State Hooks are callback functions that hook into the lifecycle events of specific states during a transition.
202
- * As a transition runs, it may exit some states, retain (keep) states, and enter states.
203
- * As each lifecycle event occurs, the hooks which are registered for the event and that state are called (in priority order).
204
- *
205
- * #### See:
206
- *
207
- * - [[IHookRegistry.onExit]]
208
- * - [[IHookRegistry.onRetain]]
209
- * - [[IHookRegistry.onEnter]]
210
- *
211
- * @param transition the current [[Transition]]
212
- * @param state the [[StateObject]] that the hook is bound to
213
- * @param injector (for ng1 or ng2 only) the injector service
214
- *
215
- * @returns a [[HookResult]] which may alter the transition
216
- */
217
- export interface TransitionStateHookFn {
218
- (transition: Transition, state: StateDeclaration): HookResult;
219
- }
220
- /**
221
- * The signature for Transition onCreate Hooks.
222
- *
223
- * Transition onCreate Hooks are callbacks that allow customization or preprocessing of
224
- * a Transition before it is returned from [[TransitionService.create]]
225
- *
226
- * @param transition the [[Transition]] that was just created
227
- * @return a [[Transition]] which will then be returned from [[TransitionService.create]]
228
- */
229
- export interface TransitionCreateHookFn {
230
- (transition: Transition): void;
231
- }
232
- export declare type HookFn =
233
- | TransitionHookFn
234
- | TransitionStateHookFn
235
- | TransitionCreateHookFn;
236
- /**
237
- * The return value of a [[TransitionHookFn]] or [[TransitionStateHookFn]]
238
- *
239
- * When returned from a [[TransitionHookFn]] or [[TransitionStateHookFn]], these values alter the running [[Transition]]:
240
- *
241
- * - `false`: the transition will be cancelled.
242
- * - [[TargetState]]: the transition will be redirected to the new target state (see: [[StateService.target]])
243
- * - `Promise`: the transition will wait for the promise to resolve or reject
244
- * - If the promise is rejected (or resolves to `false`), the transition will be cancelled
245
- * - If the promise resolves to a [[TargetState]], the transition will be redirected
246
- * - If the promise resolves to anything else, the transition will resume
247
- * - Anything else: the transition will resume
248
- */
249
- export declare type HookResult =
250
- | boolean
251
- | TargetState
252
- | void
253
- | Promise<boolean | TargetState | void>;
254
- /**
255
- * These options may be provided when registering a Transition Hook (such as `onStart`)
256
- */
257
- export interface HookRegOptions {
258
- /**
259
- * Sets the priority of the registered hook
260
- *
261
- * Hooks of the same type (onBefore, onStart, etc) are invoked in priority order. A hook with a higher priority
262
- * is invoked before a hook with a lower priority.
263
- *
264
- * The default hook priority is 0
265
- */
266
- priority?: number;
267
- /**
268
- * Specifies what `this` is bound to during hook invocation.
269
- */
270
- bind?: any;
271
- /**
272
- * Limits the number of times that the hook will be invoked.
273
- * Once the hook has been invoked this many times, it is automatically deregistered.
274
- */
275
- invokeLimit?: number;
276
- }
277
- /**
278
- * This interface specifies the api for registering Transition Hooks. Both the
279
- * [[TransitionService]] and also the [[Transition]] object itself implement this interface.
280
- * Note: the Transition object only allows hooks to be registered before the Transition is started.
281
- */
282
- export interface IHookRegistry {
283
- /** @internal place to store the hooks */
284
- _registeredHooks: {
285
- [key: string]: RegisteredHook[];
286
- };
287
- /**
288
- * Registers a [[TransitionHookFn]], called *before a transition starts*.
289
- *
290
- * Registers a transition lifecycle hook, which is invoked before a transition even begins.
291
- * This hook can be useful to implement logic which prevents a transition from even starting, such
292
- * as authentication, redirection
293
- *
294
- * See [[TransitionHookFn]] for the signature of the function.
295
- *
296
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
297
- * To match all Transitions, use an empty criteria object `{}`.
298
- *
299
- * ### Lifecycle
300
- *
301
- * `onBefore` hooks are invoked *before a Transition starts*.
302
- * No resolves have been fetched yet.
303
- * Each `onBefore` hook is invoked synchronously, in the same call stack as [[StateService.transitionTo]].
304
- * The registered `onBefore` hooks are invoked in priority order.
305
- *
306
- * Note: during the `onBefore` phase, additional hooks can be added to the specific [[Transition]] instance.
307
- * These "on-the-fly" hooks only affect the currently running transition..
308
- *
309
- * ### Return value
310
- *
311
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
312
- * See [[HookResult]] for more information.
313
- *
314
- * If any hook modifies the transition *synchronously* (by throwing, returning `false`, or returning
315
- * a [[TargetState]]), the remainder of the hooks are skipped.
316
- * If a hook returns a promise, the remainder of the `onBefore` hooks are still invoked synchronously.
317
- * All promises are resolved, and processed asynchronously before the `onStart` phase of the Transition.
318
- *
319
- * ### Examples
320
- *
321
- * #### Default Substate
322
- *
323
- * This example redirects any transition from 'home' to 'home.dashboard'. This is commonly referred to as a
324
- * "default substate".
325
- *
326
- * @example
327
- * ```js
328
- * // ng2
329
- * transitionService.onBefore({ to: 'home' }, (trans: Transition) =>
330
- * stateService.target("home.dashboard"));
331
- * ```
332
- *
333
- * #### Data Driven Default Substate
334
- *
335
- * This example provides data-driven default substate functionality. It matches on a transition to any state
336
- * which has `defaultSubstate: "some.sub.state"` defined. See: [[Transition.to]] which returns the "to state"
337
- * definition.
338
- *
339
- * @example
340
- * ```js
341
- * // ng1
342
- * // state declaration
343
- * {
344
- * name: 'home',
345
- * template: '<div ui-view/>',
346
- * defaultSubstate: 'home.dashboard'
347
- * }
348
- *
349
- * var criteria = {
350
- * to: function(state) {
351
- * return state.defaultSubstate != null;
352
- * }
353
- * }
354
- *
355
- * $transitions.onBefore(criteria, function(trans: Transition) {
356
- * var substate = trans.to().defaultSubstate;
357
- * return stateService.target(substate);
358
- * });
359
- * ```
360
- *
361
- *
362
- * #### Require authentication
363
- *
364
- * This example cancels a transition to a state which requires authentication, if the user is not currently authenticated.
365
- *
366
- * This example assumes a state tree where all states which require authentication are children of a parent `'requireauth'` state.
367
- * This example assumes `MyAuthService` synchronously returns a boolean from `isAuthenticated()`.
368
- *
369
- * #### Example:
370
- * ```js
371
- * // ng1
372
- * $transitions.onBefore( { to: 'requireauth.**' }, function(trans) {
373
- * var myAuthService = trans.injector().get('MyAuthService');
374
- * // If isAuthenticated returns false, the transition is cancelled.
375
- * return myAuthService.isAuthenticated();
376
- * });
377
- * ```
378
- *
379
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
380
- * @param callback the hook function which will be invoked.
381
- * @returns a function which deregisters the hook.
382
- */
383
- onBefore(
384
- matchCriteria: HookMatchCriteria,
385
- callback: TransitionHookFn,
386
- options?: HookRegOptions,
387
- ): Function;
388
- /**
389
- * Registers a [[TransitionHookFn]], called when a transition starts.
390
- *
391
- * Registers a transition lifecycle hook, which is invoked as a transition starts running.
392
- * This hook can be useful to perform some asynchronous action before completing a transition.
393
- *
394
- * See [[TransitionHookFn]] for the signature of the function.
395
- *
396
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
397
- * To match all Transitions, use an empty criteria object `{}`.
398
- *
399
- * ### Lifecycle
400
- *
401
- * `onStart` hooks are invoked asynchronously when the Transition starts running.
402
- * This happens after the `onBefore` phase is complete.
403
- * At this point, the Transition has not yet exited nor entered any states.
404
- * The registered `onStart` hooks are invoked in priority order.
405
- *
406
- * Note: A built-in `onStart` hook with high priority is used to fetch any eager resolve data.
407
- *
408
- * ### Return value
409
- *
410
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
411
- * See [[HookResult]] for more information.
412
- *
413
- * ### Example
414
- *
415
- * #### Login during transition
416
- *
417
- * This example intercepts any transition to a state which requires authentication, when the user is
418
- * not currently authenticated. It allows the user to authenticate asynchronously, then resumes the
419
- * transition. If the user did not authenticate successfully, it redirects to the "guest" state, which
420
- * does not require authentication.
421
- *
422
- * This example assumes:
423
- * - a state tree where all states which require authentication are children of a parent `'auth'` state.
424
- * - `MyAuthService.isAuthenticated()` synchronously returns a boolean.
425
- * - `MyAuthService.authenticate()` presents a login dialog, and returns a promise which is resolved
426
- * or rejected, whether or not the login attempt was successful.
427
- *
428
- * #### Example:
429
- * ```js
430
- * // ng1
431
- * $transitions.onStart( { to: 'auth.**' }, function(trans) {
432
- * var $state = stateService;
433
- * var MyAuthService = trans.injector().get('MyAuthService');
434
- *
435
- * // If the user is not authenticated
436
- * if (!MyAuthService.isAuthenticated()) {
437
- *
438
- * // Then return a promise for a successful login.
439
- * // The transition will wait for this promise to settle
440
- *
441
- * return MyAuthService.authenticate().catch(function() {
442
- *
443
- * // If the authenticate() method failed for whatever reason,
444
- * // redirect to a 'guest' state which doesn't require auth.
445
- * return $state.target("guest");
446
- * });
447
- * }
448
- * });
449
- * ```
450
- *
451
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
452
- * @param callback the hook function which will be injected and invoked.
453
- * @returns a function which deregisters the hook.
454
- */
455
- onStart(
456
- matchCriteria: HookMatchCriteria,
457
- callback: TransitionHookFn,
458
- options?: HookRegOptions,
459
- ): Function;
460
- /**
461
- * Registers a [[TransitionStateHookFn]], called when a specific state is entered.
462
- *
463
- * Registers a lifecycle hook, which is invoked (during a transition) when a specific state is being entered.
464
- *
465
- * Since this hook is run only when the specific state is being *entered*, it can be useful for
466
- * performing tasks when entering a submodule/feature area such as initializing a stateful service,
467
- * or for guarding access to a submodule/feature area.
468
- *
469
- * See [[TransitionStateHookFn]] for the signature of the function.
470
- *
471
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
472
- * `onEnter` hooks generally specify `{ entering: 'somestate' }`.
473
- * To match all Transitions, use an empty criteria object `{}`.
474
- *
475
- * ### Lifecycle
476
- *
477
- * `onEnter` hooks are invoked when the Transition is entering a state.
478
- * States are entered after the `onRetain` phase is complete.
479
- * If more than one state is being entered, the parent state is entered first.
480
- * The registered `onEnter` hooks for a state are invoked in priority order.
481
- *
482
- * Note: A built-in `onEnter` hook with high priority is used to fetch lazy resolve data for states being entered.
483
- *
484
- * ### Return value
485
- *
486
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
487
- * See [[HookResult]] for more information.
488
- *
489
- * ### Inside a state declaration
490
- *
491
- * Instead of registering `onEnter` hooks using the [[TransitionService]], you may define an `onEnter` hook
492
- * directly on a state declaration (see: [[StateDeclaration.onEnter]]).
493
- *
494
- *
495
- * ### Examples
496
- *
497
- * #### Audit Log
498
- *
499
- * This example uses a service to log that a user has entered the admin section of an app.
500
- * This assumes that there are substates of the "admin" state, such as "admin.users", "admin.pages", etc.
501
- * @example
502
- * ```
503
- *
504
- * $transitions.onEnter({ entering: 'admin' }, function(transition, state) {
505
- * var AuditService = trans.injector().get('AuditService');
506
- * AuditService.log("Entered " + state.name + " module while transitioning to " + transition.to().name);
507
- * }
508
- * ```
509
- *
510
- * #### Audit Log (inside a state declaration)
511
- *
512
- * The `onEnter` inside this state declaration is syntactic sugar for the previous Audit Log example.
513
- * ```
514
- * {
515
- * name: 'admin',
516
- * component: 'admin',
517
- * onEnter: function($transition$, $state$) {
518
- * var AuditService = $transition$.injector().get('AuditService');
519
- * AuditService.log("Entered " + state.name + " module while transitioning to " + transition.to().name);
520
- * }
521
- * }
522
- * ```
523
- *
524
- * Note: A state declaration's `onEnter` function is injected for Angular 1 only.
525
- *
526
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
527
- * @param callback the hook function which will be injected and invoked.
528
- * @returns a function which deregisters the hook.
529
- */
530
- onEnter(
531
- matchCriteria: HookMatchCriteria,
532
- callback: TransitionStateHookFn,
533
- options?: HookRegOptions,
534
- ): Function;
535
- /**
536
- * Registers a [[TransitionStateHookFn]], called when a specific state is retained/kept.
537
- *
538
- * Registers a lifecycle hook, which is invoked (during a transition) for
539
- * a specific state that was previously active will remain active (is not being entered nor exited).
540
- *
541
- * This hook is invoked when a state is "retained" or "kept".
542
- * It means the transition is coming *from* a substate of the retained state *to* a substate of the retained state.
543
- * This hook can be used to perform actions when the user moves from one substate to another, such as between steps in a wizard.
544
- *
545
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
546
- * `onRetain` hooks generally specify `{ retained: 'somestate' }`.
547
- * To match all Transitions, use an empty criteria object `{}`.
548
- *
549
- * ### Lifecycle
550
- *
551
- * `onRetain` hooks are invoked after any `onExit` hooks have been fired.
552
- * If more than one state is retained, the child states' `onRetain` hooks are invoked first.
553
- * The registered `onRetain` hooks for a state are invoked in priority order.
554
- *
555
- * ### Return value
556
- *
557
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
558
- * See [[HookResult]] for more information.
559
- *
560
- * ### Inside a state declaration
561
- *
562
- * Instead of registering `onRetain` hooks using the [[TransitionService]], you may define an `onRetain` hook
563
- * directly on a state declaration (see: [[StateDeclaration.onRetain]]).
564
- *
565
- * Note: A state declaration's `onRetain` function is injected for Angular 1 only.
566
- *
567
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
568
- * @param callback the hook function which will be injected and invoked.
569
- * @returns a function which deregisters the hook.
570
- */
571
- onRetain(
572
- matchCriteria: HookMatchCriteria,
573
- callback: TransitionStateHookFn,
574
- options?: HookRegOptions,
575
- ): Function;
576
- /**
577
- * Registers a [[TransitionStateHookFn]], called when a specific state is exited.
578
- *
579
- * Registers a lifecycle hook, which is invoked (during a transition) when a specific state is being exited.
580
- *
581
- * Since this hook is run only when the specific state is being *exited*, it can be useful for
582
- * performing tasks when leaving a submodule/feature area such as cleaning up a stateful service,
583
- * or for preventing the user from leaving a state or submodule until some criteria is satisfied.
584
- *
585
- * See [[TransitionStateHookFn]] for the signature of the function.
586
- *
587
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
588
- * `onExit` hooks generally specify `{ exiting: 'somestate' }`.
589
- * To match all Transitions, use an empty criteria object `{}`.
590
- *
591
- * ### Lifecycle
592
- *
593
- * `onExit` hooks are invoked when the Transition is exiting a state.
594
- * States are exited after any `onStart` phase is complete.
595
- * If more than one state is being exited, the child states are exited first.
596
- * The registered `onExit` hooks for a state are invoked in priority order.
597
- *
598
- * ### Return value
599
- *
600
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
601
- * See [[HookResult]] for more information.
602
- *
603
- * ### Inside a state declaration
604
- *
605
- * Instead of registering `onExit` hooks using the [[TransitionService]], you may define an `onExit` hook
606
- * directly on a state declaration (see: [[StateDeclaration.onExit]]).
607
- *
608
- * Note: A state declaration's `onExit` function is injected for Angular 1 only.
609
- *
610
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
611
- * @param callback the hook function which will be injected and invoked.
612
- * @returns a function which deregisters the hook.
613
- */
614
- onExit(
615
- matchCriteria: HookMatchCriteria,
616
- callback: TransitionStateHookFn,
617
- options?: HookRegOptions,
618
- ): Function;
619
- /**
620
- * Registers a [[TransitionHookFn]], called *just before a transition finishes*.
621
- *
622
- * Registers a transition lifecycle hook, which is invoked just before a transition finishes.
623
- * This hook is a last chance to cancel or redirect a transition.
624
- *
625
- * See [[TransitionHookFn]] for the signature of the function.
626
- *
627
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
628
- * To match all Transitions, use an empty criteria object `{}`.
629
- *
630
- * ### Lifecycle
631
- *
632
- * `onFinish` hooks are invoked after the `onEnter` phase is complete.
633
- * These hooks are invoked just before the transition is "committed".
634
- * Each hook is invoked in priority order.
635
- *
636
- * ### Return value
637
- *
638
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
639
- * See [[HookResult]] for more information.
640
- *
641
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
642
- * @param callback the hook function which will be injected and invoked.
643
- * @returns a function which deregisters the hook.
644
- */
645
- onFinish(
646
- matchCriteria: HookMatchCriteria,
647
- callback: TransitionHookFn,
648
- options?: HookRegOptions,
649
- ): Function;
650
- /**
651
- * Registers a [[TransitionHookFn]], called after a successful transition completed.
652
- *
653
- * Registers a transition lifecycle hook, which is invoked after a transition successfully completes.
654
- *
655
- * See [[TransitionHookFn]] for the signature of the function.
656
- *
657
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
658
- * To match all Transitions, use an empty criteria object `{}`.
659
- *
660
- * ### Lifecycle
661
- *
662
- * `onSuccess` hooks are chained off the Transition's promise (see [[Transition.promise]]).
663
- * If the Transition is successful and its promise is resolved, then the `onSuccess` hooks are invoked.
664
- * Since these hooks are run after the transition is over, their return value is ignored.
665
- * The `onSuccess` hooks are invoked in priority order.
666
- *
667
- * ### Return value
668
- *
669
- * Since the Transition is already completed, the hook's return value is ignored
670
- *
671
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
672
- * @param callback the hook function which will be injected and invoked.
673
- * @returns a function which deregisters the hook.
674
- */
675
- onSuccess(
676
- matchCriteria: HookMatchCriteria,
677
- callback: TransitionHookFn,
678
- options?: HookRegOptions,
679
- ): Function;
680
- /**
681
- * Registers a [[TransitionHookFn]], called after a transition has errored.
682
- *
683
- * Registers a transition lifecycle hook, which is invoked after a transition has been rejected for any reason.
684
- *
685
- * See [[TransitionHookFn]] for the signature of the function.
686
- *
687
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
688
- * To match all Transitions, use an empty criteria object `{}`.
689
- *
690
- * ### Lifecycle
691
- *
692
- * The `onError` hooks are chained off the Transition's promise (see [[Transition.promise]]).
693
- * If a Transition fails, its promise is rejected and the `onError` hooks are invoked.
694
- * The `onError` hooks are invoked in priority order.
695
- *
696
- * Since these hooks are run after the transition is over, their return value is ignored.
697
- *
698
- * A transition "errors" if it was started, but failed to complete (for any reason).
699
- * A *non-exhaustive list* of reasons a transition can error:
700
- *
701
- * - A transition was cancelled because a new transition started while it was still running (`Transition superseded`)
702
- * - A transition was cancelled by a Transition Hook returning false
703
- * - A transition was redirected by a Transition Hook returning a [[TargetState]]
704
- * - A Transition Hook or resolve function threw an error
705
- * - A Transition Hook returned a rejected promise
706
- * - A resolve function returned a rejected promise
707
- *
708
- * To check the failure reason, inspect the return value of [[Transition.error]].
709
- *
710
- * Note: `onError` should be used for targeted error handling, or error recovery.
711
- * For simple catch-all error reporting, use [[StateService.defaultErrorHandler]].
712
- *
713
- * ### Return value
714
- *
715
- * Since the Transition is already completed, the hook's return value is ignored
716
- *
717
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
718
- * @param callback the hook function which will be injected and invoked.
719
- * @returns a function which deregisters the hook.
720
- */
721
- onError(
722
- matchCriteria: HookMatchCriteria,
723
- callback: TransitionHookFn,
724
- options?: HookRegOptions,
725
- ): Function;
726
- /**
727
- * Returns all the registered hooks of a given `hookName` type
728
- *
729
- * #### Example:
730
- * ```
731
- * $transitions.getHooks("onEnter")
732
- * ```
733
- */
734
- getHooks(hookName: string): RegisteredHook[];
735
- }
736
- /** A predicate type which tests if a [[StateObject]] and [[Transition]] passes some test. Returns a boolean. */
737
- export declare type IStateMatch = PredicateBinary<StateObject, Transition>;
738
- /**
739
- * This object is used to configure whether or not a Transition Hook is invoked for a particular transition,
740
- * based on the Transition's "to state" and "from state".
741
- *
742
- * Each property (`to`, `from`, `exiting`, `retained`, and `entering`) can be a state [[Glob]] string,
743
- * a boolean, or a function that takes a state and returns a boolean (see [[HookMatchCriterion]])
744
- *
745
- * All properties are optional. If any property is omitted, it is replaced with the value `true`, and always matches.
746
- * To match any transition, use an empty criteria object `{}`.
747
- *
748
- * #### Example:
749
- * ```js
750
- * // This matches a transition coming from the `parent` state and going to the `parent.child` state.
751
- * var match = {
752
- * to: 'parent',
753
- * from: 'parent.child'
754
- * }
755
- * ```
756
- *
757
- * #### Example:
758
- * ```js
759
- * // This matches a transition coming from any substate of `parent` and going directly to the `parent` state.
760
- * var match = {
761
- * to: 'parent',
762
- * from: 'parent.**'
763
- * }
764
- * ```
765
- *
766
- * #### Example:
767
- * ```js
768
- * // This matches a transition coming from any state and going to any substate of `mymodule`
769
- * var match = {
770
- * to: 'mymodule.**'
771
- * }
772
- * ```
773
- *
774
- * #### Example:
775
- * ```js
776
- * // This matches a transition coming from any state and going to any state that has `data.authRequired`
777
- * // set to a truthy value.
778
- * var match = {
779
- * to: function(state) {
780
- * return state.data != null && state.data.authRequired === true;
781
- * }
782
- * }
783
- * ```
784
- * #### Example:
785
- * ```js
786
- * // This will match when route is just entered (initial load) or when the state is hard-refreshed
787
- * // by specifying `{refresh: true}` as transition options.
788
- * var match = {
789
- * from: (state, transition) => state.self.name === '' || transition.options().reload
790
- * }
791
- * ```
792
- *
793
- * #### Example:
794
- * ```js
795
- * // This matches a transition that is exiting `parent.child`
796
- * var match = {
797
- * exiting: 'parent.child'
798
- * }
799
- * ```
800
- */
801
- export interface HookMatchCriteria {
802
- [key: string]: HookMatchCriterion | undefined;
803
- /** A [[HookMatchCriterion]] to match the destination state */
804
- to?: HookMatchCriterion;
805
- /** A [[HookMatchCriterion]] to match the original (from) state */
806
- from?: HookMatchCriterion;
807
- /** A [[HookMatchCriterion]] to match any state that would be exiting */
808
- exiting?: HookMatchCriterion;
809
- /** A [[HookMatchCriterion]] to match any state that would be retained */
810
- retained?: HookMatchCriterion;
811
- /** A [[HookMatchCriterion]] to match any state that would be entering */
812
- entering?: HookMatchCriterion;
813
- }
814
- export interface IMatchingNodes {
815
- [key: string]: PathNode[];
816
- to: PathNode[];
817
- from: PathNode[];
818
- exiting: PathNode[];
819
- retained: PathNode[];
820
- entering: PathNode[];
821
- }
822
- /** @internal */
823
- export interface RegisteredHooks {
824
- [key: string]: RegisteredHook[];
825
- }
826
- /** @internal */
827
- export interface PathTypes {
828
- [key: string]: PathType;
829
- to: PathType;
830
- from: PathType;
831
- exiting: PathType;
832
- retained: PathType;
833
- entering: PathType;
834
- }
835
- /** @internal */
836
- export interface PathType {
837
- name: string;
838
- scope: TransitionHookScope;
839
- }
840
- /**
841
- * Hook Criterion used to match a transition.
842
- *
843
- * A [[Glob]] string that matches the name of a state.
844
- *
845
- * Or, a function with the signature `function(state, transition) { return matches; }`
846
- * which should return a boolean to indicate if a state matches.
847
- *
848
- * Or, `true` to always match
849
- */
850
- export declare type HookMatchCriterion = string | IStateMatch | boolean;
851
- declare enum TransitionHookPhase {
852
- CREATE = 0,
853
- BEFORE = 1,
854
- RUN = 2,
855
- SUCCESS = 3,
856
- ERROR = 4,
857
- }
858
- declare enum TransitionHookScope {
859
- TRANSITION = 0,
860
- STATE = 1,
861
- }
862
- export { TransitionHookPhase, TransitionHookScope };