UNPKG

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