UNPKG

20 kBTypeScriptView Raw
1// Type definitions for Angular JS (ui.router module) 1.1.38
2// Project: https://github.com/angular-ui/ui-router
3// Definitions by: Michel Salib <https://github.com/michelsalib>
4// Ivan Matiishyn <https://github.com/matiishyn>
5// Mike Haas <https://github.com/mikehaas763>
6// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7// TypeScript Version: 2.3
8
9import * as angular from 'angular';
10
11declare const exportedString: "ui.router";
12export default exportedString;
13
14export type IState = angular.ui.IState;
15export type IStateProvider = angular.ui.IStateProvider;
16export type IUrlMatcher = angular.ui.IUrlMatcher;
17export type IUrlRouterProvider = angular.ui.IUrlRouterProvider;
18export type IStateOptions = angular.ui.IStateOptions;
19export type IHrefOptions = angular.ui.IHrefOptions;
20export type IStateService = angular.ui.IStateService;
21export type IResolvedState = angular.ui.IResolvedState;
22export type IStateParamsService = angular.ui.IStateParamsService;
23export type IUrlRouterService = angular.ui.IUrlRouterService;
24export type IUiViewScrollProvider = angular.ui.IUiViewScrollProvider;
25export type IType = angular.ui.IType;
26
27declare module 'angular' {
28 export namespace ui {
29 interface IState {
30 name?: string | undefined;
31 /**
32 * String HTML content, or function that returns an HTML string
33 */
34 template?: string | { (params: IStateParamsService): string } | undefined;
35 /**
36 * String URL path to template file OR Function, returns URL path string
37 */
38 templateUrl?: string | { (params: IStateParamsService): string } | undefined;
39 /**
40 * Function, returns HTML content string
41 */
42 templateProvider?: Function | Array<string | Function> | undefined;
43 /**
44 * String, component name
45 */
46 component?: string | undefined;
47 /**
48 * A controller paired to the state. Function, annotated array or name as String
49 */
50 controller?: Function | string | Array<string | Function> | undefined;
51 controllerAs?: string | undefined;
52 /**
53 * Function (injectable), returns the actual controller function or string.
54 */
55 controllerProvider?: Function | Array<string | Function> | undefined;
56
57 /**
58 * Specifies the parent state of this state
59 */
60 parent?: string | IState | undefined;
61
62
63 resolve?: { [name: string]: any } | undefined;
64 /**
65 * A url with optional parameters. When a state is navigated or transitioned to, the $stateParams service will be populated with any parameters that were passed.
66 */
67 url?: string | IUrlMatcher | undefined;
68 /**
69 * A map which optionally configures parameters declared in the url, or defines additional non-url parameters. Only use this within a state if you are not using url. Otherwise you can specify your parameters within the url. When a state is navigated or transitioned to, the $stateParams service will be populated with any parameters that were passed.
70 */
71 params?: any;
72 /**
73 * Use the views property to set up multiple views. If you don't need multiple views within a single state this property is not needed. Tip: remember that often nested views are more useful and powerful than multiple sibling views.
74 */
75 views?: { [name: string]: IState } | undefined;
76 abstract?: boolean | undefined;
77 /**
78 * Callback function for when a state is entered. Good way to trigger an action or dispatch an event, such as opening a dialog.
79 * If minifying your scripts, make sure to explicitly annotate this function, because it won't be automatically annotated by your build tools.
80 */
81 onEnter?: Function | Array<string | Function> | undefined;
82 /**
83 * Callback functions for when a state is entered and exited. Good way to trigger an action or dispatch an event, such as opening a dialog.
84 * If minifying your scripts, make sure to explicitly annotate this function, because it won't be automatically annotated by your build tools.
85 */
86 onExit?: Function | Array<string | Function> | undefined;
87 /**
88 * Arbitrary data object, useful for custom configuration.
89 */
90 data?: any;
91
92 /**
93 * Boolean (default true). If false will not re-trigger the same state just because a search/query parameter has changed. Useful for when you'd like to modify $location.search() without triggering a reload.
94 */
95 reloadOnSearch?: boolean | undefined;
96
97 /**
98 * Boolean (default true). If false will reload state on everytransitions. Useful for when you'd like to restore all data to its initial state.
99 */
100 cache?: boolean | undefined;
101
102 /**
103 * string | function | object
104 * Synchronously or asynchronously redirects Transitions to a different state/params
105 */
106 redirectTo?: string | Function | IState | undefined;
107
108 }
109
110 interface IUnfoundState {
111 to: string,
112 toParams: {},
113 options: IStateOptions
114 }
115
116 interface IStateProvider extends angular.IServiceProvider {
117 state(name: string, config: IState): IStateProvider;
118 state(config: IState): IStateProvider;
119 decorator(name?: string, decorator?: (state: IState, parent: Function) => any): any;
120 }
121
122 interface IUrlMatcher {
123 concat(pattern: string): IUrlMatcher;
124 exec(path: string, search?: any, hash?: string, options?: any): {};
125 parameters(): string[];
126 format(values: {}): string;
127 }
128
129 interface IUrlMatcherFactory {
130 /**
131 * Creates a UrlMatcher for the specified pattern.
132 *
133 * @param pattern {string} The URL pattern.
134 *
135 * @returns {IUrlMatcher} The UrlMatcher.
136 */
137 compile(pattern: string): IUrlMatcher;
138 /**
139 * Returns true if the specified object is a UrlMatcher, or false otherwise.
140 *
141 * @param o {any} The object to perform the type check against.
142 *
143 * @returns {boolean} Returns true if the object matches the IUrlMatcher interface, by implementing all the same methods.
144 */
145 isMatcher(o: any): boolean;
146 /**
147 * Returns a type definition for the specified name
148 *
149 * @param name {string} The type definition name
150 *
151 * @returns {IType} The type definition
152 */
153 type(name: string): IType;
154 /**
155 * Registers a custom Type object that can be used to generate URLs with typed parameters.
156 *
157 * @param {IType} definition The type definition.
158 * @param {any[]} inlineAnnotedDefinitionFn A function that is injected before the app runtime starts. The result of this function is merged into the existing definition.
159 *
160 * @returns {IUrlMatcherFactory} Returns $urlMatcherFactoryProvider.
161 */
162 type(name: string, definition: IType, inlineAnnotedDefinitionFn?: any[]): IUrlMatcherFactory;
163 /**
164 * Registers a custom Type object that can be used to generate URLs with typed parameters.
165 *
166 * @param {IType} definition The type definition.
167 * @param {any[]} inlineAnnotedDefinitionFn A function that is injected before the app runtime starts. The result of this function is merged into the existing definition.
168 *
169 * @returns {IUrlMatcherFactory} Returns $urlMatcherFactoryProvider.
170 */
171 type(name: string, definition: IType, definitionFn?: (...args: any[]) => IType): IUrlMatcherFactory;
172 /**
173 * Defines whether URL matching should be case sensitive (the default behavior), or not.
174 *
175 * @param value {boolean} false to match URL in a case sensitive manner; otherwise true;
176 *
177 * @returns {boolean} the current value of caseInsensitive
178 */
179 caseInsensitive(value?: boolean): boolean;
180 /**
181 * Sets the default behavior when generating or matching URLs with default parameter values
182 *
183 * @param value {string} A string that defines the default parameter URL squashing behavior. nosquash: When generating an href with a default parameter value, do not squash the parameter value from the URL slash: When generating an href with a default parameter value, squash (remove) the parameter value, and, if the parameter is surrounded by slashes, squash (remove) one slash from the URL any other string, e.g. "~": When generating an href with a default parameter value, squash (remove) the parameter value from the URL and replace it with this string.
184 */
185 defaultSquashPolicy(value: string): void;
186 /**
187 * Defines whether URLs should match trailing slashes, or not (the default behavior).
188 *
189 * @param value {boolean} false to match trailing slashes in URLs, otherwise true.
190 *
191 * @returns {boolean} the current value of strictMode
192 */
193 strictMode(value?: boolean): boolean;
194 }
195
196 interface IUrlRouterProvider extends angular.IServiceProvider {
197 when(whenPath: RegExp, handler: Function): IUrlRouterProvider;
198 when(whenPath: RegExp, handler: any[]): IUrlRouterProvider;
199 when(whenPath: RegExp, toPath: string): IUrlRouterProvider;
200 when(whenPath: IUrlMatcher, hanlder: Function): IUrlRouterProvider;
201 when(whenPath: IUrlMatcher, handler: any[]): IUrlRouterProvider;
202 when(whenPath: IUrlMatcher, toPath: string): IUrlRouterProvider;
203 when(whenPath: string, handler: Function): IUrlRouterProvider;
204 when(whenPath: string, handler: any[]): IUrlRouterProvider;
205 when(whenPath: string, toPath: string): IUrlRouterProvider;
206 otherwise(handler: Function): IUrlRouterProvider;
207 otherwise(handler: any[]): IUrlRouterProvider;
208 otherwise(path: string): IUrlRouterProvider;
209 rule(handler: Function): IUrlRouterProvider;
210 rule(handler: any[]): IUrlRouterProvider;
211 /**
212 * Disables (or enables) deferring location change interception.
213 *
214 * If you wish to customize the behavior of syncing the URL (for example, if you wish to defer a transition but maintain the current URL), call this method at configuration time. Then, at run time, call $urlRouter.listen() after you have configured your own $locationChangeSuccess event handler.
215 *
216 * @param {boolean} defer Indicates whether to defer location change interception. Passing no parameter is equivalent to true.
217 */
218 deferIntercept(defer?: boolean): void;
219 }
220
221 interface IStateOptions {
222 /**
223 * {boolean=true|string=} - If true will update the url in the location bar, if false will not. If string, must be "replace", which will update url and also replace last history record.
224 */
225 location?: boolean | string | undefined;
226 /**
227 * {boolean=true}, If true will inherit url parameters from current url.
228 */
229 inherit?: boolean | undefined;
230 /**
231 * {object=$state.$current}, When transitioning with relative path (e.g '^'), defines which state to be relative from.
232 */
233 relative?: IState | undefined;
234 /**
235 * {boolean=true}, If true will broadcast $stateChangeStart and $stateChangeSuccess events.
236 */
237 notify?: boolean | undefined;
238 /**
239 * {boolean=false|string|IState}, If true will force transition even if the state or params have not changed, aka a reload of the same state. It differs from reloadOnSearch because you'd use this when you want to force a reload when everything is the same, including search params.
240 */
241 reload?: boolean | string | IState | undefined;
242 }
243
244 interface IHrefOptions {
245 lossy?: boolean | undefined;
246 inherit?: boolean | undefined;
247 relative?: IState | undefined;
248 absolute?: boolean | undefined;
249 }
250
251 interface IStateService {
252 /**
253 * Convenience method for transitioning to a new state. $state.go calls $state.transitionTo internally but automatically sets options to { location: true, inherit: true, relative: $state.$current, notify: true }. This allows you to easily use an absolute or relative to path and specify only the parameters you'd like to update (while letting unspecified parameters inherit from the currently active ancestor states).
254 *
255 * @param to Absolute state name or relative state path. Some examples:
256 *
257 * $state.go('contact.detail') - will go to the contact.detail state
258 * $state.go('^') - will go to a parent state
259 * $state.go('^.sibling') - will go to a sibling state
260 * $state.go('.child.grandchild') - will go to grandchild state
261 *
262 * @param params A map of the parameters that will be sent to the state, will populate $stateParams. Any parameters that are not specified will be inherited from currently defined parameters. This allows, for example, going to a sibling state that shares parameters specified in a parent state. Parameter inheritance only works between common ancestor states, I.e. transitioning to a sibling will get you the parameters for all parents, transitioning to a child will get you all current parameters, etc.
263 *
264 * @param options Options object.
265 */
266 go(to: string, params?: {}, options?: IStateOptions): angular.IPromise<any>;
267 go(to: IState, params?: {}, options?: IStateOptions): angular.IPromise<any>;
268 transitionTo(state: string, params?: {}, updateLocation?: boolean): angular.IPromise<any>;
269 transitionTo(state: IState, params?: {}, updateLocation?: boolean): angular.IPromise<any>;
270 transitionTo(state: string, params?: {}, options?: IStateOptions): angular.IPromise<any>;
271 transitionTo(state: IState, params?: {}, options?: IStateOptions): angular.IPromise<any>;
272 includes(state: string, params?: {}): boolean;
273 includes(state: string, params?: {}, options?: any): boolean;
274 is(state: string, params?: {}): boolean;
275 is(state: IState, params?: {}): boolean;
276 href(state: IState, params?: {}, options?: IHrefOptions): string;
277 href(state: string, params?: {}, options?: IHrefOptions): string;
278 get(state: string | IState, context?: string | IState): IState;
279 get(): IState[];
280 /** A reference to the state's config object. However you passed it in. Useful for accessing custom data. */
281 current: IState;
282 /** A param object, e.g. {sectionId: section.id)}, that you'd like to test against the current active state. */
283 params: IStateParamsService;
284 reload(reloadState?: string | IState): angular.IPromise<any>;
285
286 /** Currently pending transition. A promise that'll resolve or reject. */
287 transition: angular.IPromise<{}>;
288
289 $current: IResolvedState;
290 }
291
292 interface IResolvedState {
293 locals: {
294 /**
295 * Currently resolved "resolve" values from the current state
296 */
297 globals: { [key: string]: any; };
298 };
299 }
300
301 interface IStateParamsService {
302 [key: string]: any;
303 }
304
305 interface IUrlRouterService {
306 /*
307 * Triggers an update; the same update that happens when the address bar
308 * url changes, aka $locationChangeSuccess.
309 *
310 * This method is useful when you need to use preventDefault() on the
311 * $locationChangeSuccess event, perform some custom logic (route protection,
312 * auth, config, redirection, etc) and then finally proceed with the transition
313 * by calling $urlRouter.sync().
314 *
315 */
316 sync(): void;
317 listen(): Function;
318 href(urlMatcher: IUrlMatcher, params?: IStateParamsService, options?: IHrefOptions): string;
319 update(read?: boolean): void;
320 push(urlMatcher: IUrlMatcher, params?: IStateParamsService, options?: IHrefOptions): void;
321 }
322
323 interface IUiViewScrollProvider {
324 /*
325 * Reverts back to using the core $anchorScroll service for scrolling
326 * based on the url anchor.
327 */
328 useAnchorScroll(): void;
329 }
330
331 interface IType {
332 /**
333 * Converts a parameter value (from URL string or transition param) to a custom/native value.
334 *
335 * @param val {string} The URL parameter value to decode.
336 * @param key {string} The name of the parameter in which val is stored. Can be used for meta-programming of Type objects.
337 *
338 * @returns {any} Returns a custom representation of the URL parameter value.
339 */
340 decode(val: string, key: string): any;
341 /**
342 * Encodes a custom/native type value to a string that can be embedded in a URL. Note that the return value does not need to be URL-safe (i.e. passed through encodeURIComponent()), it only needs to be a representation of val that has been coerced to a string.
343 *
344 * @param val {any} The value to encode.
345 * @param key {string} The name of the parameter in which val is stored. Can be used for meta-programming of Type objects.
346 *
347 * @returns {string} Returns a string representation of val that can be encoded in a URL.
348 */
349 encode(val: any, key: string): string;
350 /**
351 * Determines whether two decoded values are equivalent.
352 *
353 * @param a {any} A value to compare against.
354 * @param b {any} A value to compare against.
355 *
356 * @returns {boolean} Returns true if the values are equivalent/equal, otherwise false.
357 */
358 equals?(a: any, b: any): boolean;
359 /**
360 * Detects whether a value is of a particular type. Accepts a native (decoded) value and determines whether it matches the current Type object.
361 *
362 * @param val {any} The value to check.
363 * @param key {any} Optional. If the type check is happening in the context of a specific UrlMatcher object, this is the name of the parameter in which val is stored. Can be used for meta-programming of Type objects.
364 *
365 * @returns {boolean} Returns true if the value matches the type, otherwise false.
366 */
367 is(val: any, key: string): boolean;
368 /**
369 * The regular expression pattern used to match values of this type when coming from a substring of a URL.
370 */
371 pattern?: RegExp | undefined;
372 }
373 }
374
375}