blob: 47af08e22660909c40fa19139ded7a5317a1015a [file] [log] [blame]
Matteo Scandolof6acdbe2016-12-13 10:29:37 -08001// Generated by typings
2// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/b38cd68fe2dacaea0bb4efd6a3c638ceeae4fb25/angular-ui-router/angular-ui-router.d.ts
3declare module 'angular-ui-router' {
4 // Since angular-ui-router adds providers for a bunch of
5 // injectable dependencies, it doesn't really return any
6 // actual data except the plain string 'ui.router'.
7 //
8 // As such, I don't think anybody will ever use the actual
9 // default value of the module. So I've only included the
10 // the types. (@xogeny)
11 export type IState = angular.ui.IState;
12 export type IStateProvider = angular.ui.IStateProvider;
13 export type IUrlMatcher = angular.ui.IUrlMatcher;
14 export type IUrlRouterProvider = angular.ui.IUrlRouterProvider;
15 export type IStateOptions = angular.ui.IStateOptions;
16 export type IHrefOptions = angular.ui.IHrefOptions;
17 export type IStateService = angular.ui.IStateService;
18 export type IResolvedState = angular.ui.IResolvedState;
19 export type IStateParamsService = angular.ui.IStateParamsService;
20 export type IUrlRouterService = angular.ui.IUrlRouterService;
21 export type IUiViewScrollProvider = angular.ui.IUiViewScrollProvider;
22 export type IType = angular.ui.IType;
23}
24
25declare namespace angular.ui {
26
27 interface IState {
28 name?: string;
29 /**
30 * String HTML content, or function that returns an HTML string
31 */
32 template?: string | {(params: IStateParamsService): string};
33 /**
34 * String URL path to template file OR Function, returns URL path string
35 */
36 templateUrl?: string | {(params: IStateParamsService): string};
37 /**
38 * Function, returns HTML content string
39 */
40 templateProvider?: Function | Array<string|Function>;
41 /**
42 * String, component name
43 */
44 component?: string;
45 /**
46 * A controller paired to the state. Function, annotated array or name as String
47 */
48 controller?: Function|string|Array<string|Function>;
49 controllerAs?: string;
50 /**
51 * Function (injectable), returns the actual controller function or string.
52 */
53 controllerProvider?: Function|Array<string|Function>;
54
55 /**
56 * Specifies the parent state of this state
57 */
58 parent?: string | IState;
59
60
61 resolve?: { [name:string]: any };
62 /**
63 * 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.
64 */
65 url?: string | IUrlMatcher;
66 /**
67 * 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.
68 */
69 params?: any;
70 /**
71 * 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.
72 */
73 views?: { [name:string]: IState };
74 abstract?: boolean;
75 /**
76 * Callback function for when a state is entered. Good way to trigger an action or dispatch an event, such as opening a dialog.
77 * If minifying your scripts, make sure to explicitly annotate this function, because it won't be automatically annotated by your build tools.
78 */
79 onEnter?: Function|Array<string|Function>;
80 /**
81 * 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.
82 * If minifying your scripts, make sure to explicitly annotate this function, because it won't be automatically annotated by your build tools.
83 */
84 onExit?: Function|Array<string|Function>;
85 /**
86 * Arbitrary data object, useful for custom configuration.
87 */
88 data?: any;
89
90 /**
91 * 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.
92 */
93 reloadOnSearch?: boolean;
94
95 /**
96 * Boolean (default true). If false will reload state on everytransitions. Useful for when you'd like to restore all data to its initial state.
97 */
98 cache?: boolean;
99 }
100
101 interface IUnfoundState {
102 to: string,
103 toParams: {},
104 options: IStateOptions
105 }
106
107 interface IStateProvider extends angular.IServiceProvider {
108 state(name:string, config:IState): IStateProvider;
109 state(config:IState): IStateProvider;
110 decorator(name?: string, decorator?: (state: IState, parent: Function) => any): any;
111 }
112
113 interface IUrlMatcher {
114 concat(pattern: string): IUrlMatcher;
115 exec(path: string, searchParams: {}): {};
116 parameters(): string[];
117 format(values: {}): string;
118 }
119
120 interface IUrlMatcherFactory {
121 /**
122 * Creates a UrlMatcher for the specified pattern.
123 *
124 * @param pattern {string} The URL pattern.
125 *
126 * @returns {IUrlMatcher} The UrlMatcher.
127 */
128 compile(pattern: string): IUrlMatcher;
129 /**
130 * Returns true if the specified object is a UrlMatcher, or false otherwise.
131 *
132 * @param o {any} The object to perform the type check against.
133 *
134 * @returns {boolean} Returns true if the object matches the IUrlMatcher interface, by implementing all the same methods.
135 */
136 isMatcher(o: any): boolean;
137 /**
138 * Returns a type definition for the specified name
139 *
140 * @param name {string} The type definition name
141 *
142 * @returns {IType} The type definition
143 */
144 type(name: string): IType;
145 /**
146 * Registers a custom Type object that can be used to generate URLs with typed parameters.
147 *
148 * @param {IType} definition The type definition.
149 * @param {any[]} inlineAnnotedDefinitionFn A function that is injected before the app runtime starts. The result of this function is merged into the existing definition.
150 *
151 * @returns {IUrlMatcherFactory} Returns $urlMatcherFactoryProvider.
152 */
153 type(name: string, definition: IType, inlineAnnotedDefinitionFn?: any[]): IUrlMatcherFactory;
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, definitionFn?: (...args:any[]) => IType): IUrlMatcherFactory;
163 /**
164 * Defines whether URL matching should be case sensitive (the default behavior), or not.
165 *
166 * @param value {boolean} false to match URL in a case sensitive manner; otherwise true;
167 *
168 * @returns {boolean} the current value of caseInsensitive
169 */
170 caseInsensitive(value?: boolean): boolean;
171 /**
172 * Sets the default behavior when generating or matching URLs with default parameter values
173 *
174 * @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.
175 */
176 defaultSquashPolicy(value: string): void;
177 /**
178 * Defines whether URLs should match trailing slashes, or not (the default behavior).
179 *
180 * @param value {boolean} false to match trailing slashes in URLs, otherwise true.
181 *
182 * @returns {boolean} the current value of strictMode
183 */
184 strictMode(value?: boolean): boolean;
185 }
186
187 interface IUrlRouterProvider extends angular.IServiceProvider {
188 when(whenPath: RegExp, handler: Function): IUrlRouterProvider;
189 when(whenPath: RegExp, handler: any[]): IUrlRouterProvider;
190 when(whenPath: RegExp, toPath: string): IUrlRouterProvider;
191 when(whenPath: IUrlMatcher, hanlder: Function): IUrlRouterProvider;
192 when(whenPath: IUrlMatcher, handler: any[]): IUrlRouterProvider;
193 when(whenPath: IUrlMatcher, toPath: string): IUrlRouterProvider;
194 when(whenPath: string, handler: Function): IUrlRouterProvider;
195 when(whenPath: string, handler: any[]): IUrlRouterProvider;
196 when(whenPath: string, toPath: string): IUrlRouterProvider;
197 otherwise(handler: Function): IUrlRouterProvider;
198 otherwise(handler: any[]): IUrlRouterProvider;
199 otherwise(path: string): IUrlRouterProvider;
200 rule(handler: Function): IUrlRouterProvider;
201 rule(handler: any[]): IUrlRouterProvider;
202 /**
203 * Disables (or enables) deferring location change interception.
204 *
205 * 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.
206 *
207 * @param {boolean} defer Indicates whether to defer location change interception. Passing no parameter is equivalent to true.
208 */
209 deferIntercept(defer?: boolean): void;
210 }
211
212 interface IStateOptions {
213 /**
214 * {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.
215 */
216 location?: boolean | string;
217 /**
218 * {boolean=true}, If true will inherit url parameters from current url.
219 */
220 inherit?: boolean;
221 /**
222 * {object=$state.$current}, When transitioning with relative path (e.g '^'), defines which state to be relative from.
223 */
224 relative?: IState;
225 /**
226 * {boolean=true}, If true will broadcast $stateChangeStart and $stateChangeSuccess events.
227 */
228 notify?: boolean;
229 /**
230 * {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.
231 */
232 reload?: boolean | string | IState;
233 }
234
235 interface IHrefOptions {
236 lossy?: boolean;
237 inherit?: boolean;
238 relative?: IState;
239 absolute?: boolean;
240 }
241
242 interface IStateService {
243 /**
244 * 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).
245 *
246 * @param to Absolute state name or relative state path. Some examples:
247 *
248 * $state.go('contact.detail') - will go to the contact.detail state
249 * $state.go('^') - will go to a parent state
250 * $state.go('^.sibling') - will go to a sibling state
251 * $state.go('.child.grandchild') - will go to grandchild state
252 *
253 * @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.
254 *
255 * @param options Options object.
256 */
257 go(to: string, params?: {}, options?: IStateOptions): angular.IPromise<any>;
258 go(to: IState, params?: {}, options?: IStateOptions): angular.IPromise<any>;
259 transitionTo(state: string, params?: {}, updateLocation?: boolean): angular.IPromise<any>;
260 transitionTo(state: IState, params?: {}, updateLocation?: boolean): angular.IPromise<any>;
261 transitionTo(state: string, params?: {}, options?: IStateOptions): angular.IPromise<any>;
262 transitionTo(state: IState, params?: {}, options?: IStateOptions): angular.IPromise<any>;
263 includes(state: string, params?: {}): boolean;
264 includes(state: string, params?: {}, options?:any): boolean;
265 is(state:string, params?: {}): boolean;
266 is(state: IState, params?: {}): boolean;
267 href(state: IState, params?: {}, options?: IHrefOptions): string;
268 href(state: string, params?: {}, options?: IHrefOptions): string;
269 get(state: string, context?: string): IState;
270 get(state: IState, context?: string): IState;
271 get(state: string, context?: IState): IState;
272 get(state: IState, context?: IState): IState;
273 get(): IState[];
274 /** A reference to the state's config object. However you passed it in. Useful for accessing custom data. */
275 current: IState;
276 /** A param object, e.g. {sectionId: section.id)}, that you'd like to test against the current active state. */
277 params: IStateParamsService;
278 reload(): angular.IPromise<any>;
279
280 /** Currently pending transition. A promise that'll resolve or reject. */
281 transition: angular.IPromise<{}>;
282
283 $current: IResolvedState;
284 }
285
286 interface IResolvedState {
287 locals: {
288 /**
289 * Currently resolved "resolve" values from the current state
290 */
291 globals: { [key: string]: any; };
292 };
293 }
294
295 interface IStateParamsService {
296 [key: string]: any;
297 }
298
299 interface IUrlRouterService {
300 /*
301 * Triggers an update; the same update that happens when the address bar
302 * url changes, aka $locationChangeSuccess.
303 *
304 * This method is useful when you need to use preventDefault() on the
305 * $locationChangeSuccess event, perform some custom logic (route protection,
306 * auth, config, redirection, etc) and then finally proceed with the transition
307 * by calling $urlRouter.sync().
308 *
309 */
310 sync(): void;
311 listen(): Function;
312 href(urlMatcher: IUrlMatcher, params?: IStateParamsService, options?: IHrefOptions): string;
313 update(read?: boolean): void;
314 push(urlMatcher: IUrlMatcher, params?: IStateParamsService, options?: IHrefOptions): void;
315 }
316
317 interface IUiViewScrollProvider {
318 /*
319 * Reverts back to using the core $anchorScroll service for scrolling
320 * based on the url anchor.
321 */
322 useAnchorScroll(): void;
323 }
324
325 interface IType {
326 /**
327 * Converts a parameter value (from URL string or transition param) to a custom/native value.
328 *
329 * @param val {string} The URL parameter value to decode.
330 * @param key {string} The name of the parameter in which val is stored. Can be used for meta-programming of Type objects.
331 *
332 * @returns {any} Returns a custom representation of the URL parameter value.
333 */
334 decode(val: string, key: string): any;
335 /**
336 * 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.
337 *
338 * @param val {any} The value to encode.
339 * @param key {string} The name of the parameter in which val is stored. Can be used for meta-programming of Type objects.
340 *
341 * @returns {string} Returns a string representation of val that can be encoded in a URL.
342 */
343 encode(val: any, key: string): string;
344 /**
345 * Determines whether two decoded values are equivalent.
346 *
347 * @param a {any} A value to compare against.
348 * @param b {any} A value to compare against.
349 *
350 * @returns {boolean} Returns true if the values are equivalent/equal, otherwise false.
351 */
352 equals? (a: any, b: any): boolean;
353 /**
354 * Detects whether a value is of a particular type. Accepts a native (decoded) value and determines whether it matches the current Type object.
355 *
356 * @param val {any} The value to check.
357 * @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.
358 *
359 * @returns {boolean} Returns true if the value matches the type, otherwise false.
360 */
361 is(val: any, key: string): boolean;
362 /**
363 * The regular expression pattern used to match values of this type when coming from a substring of a URL.
364 */
365 pattern?: RegExp;
366 }
367}