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