@angular-wave/angular.ts 0.9.1 → 0.9.3
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.
- package/@types/angular.d.ts +150 -0
- package/@types/animations/animate-cache.d.ts +50 -0
- package/@types/animations/animate-children-directive.d.ts +10 -0
- package/@types/animations/animate-css-driver.d.ts +18 -0
- package/@types/animations/animate-css.d.ts +18 -0
- package/@types/animations/animate-js-driver.d.ts +14 -0
- package/@types/animations/animate-js.d.ts +23 -0
- package/@types/animations/animate-queue.d.ts +28 -0
- package/@types/animations/animate-runner.d.ts +31 -0
- package/@types/animations/animate-swap.d.ts +9 -0
- package/@types/animations/animate.d.ts +450 -0
- package/@types/animations/animation.d.ts +14 -0
- package/@types/animations/interface.d.ts +17 -0
- package/@types/animations/raf-scheduler.d.ts +37 -0
- package/@types/animations/shared.d.ts +74 -0
- package/@types/core/compile/compile.d.ts +201 -0
- package/@types/core/controller/controller.d.ts +54 -0
- package/@types/core/di/injector.d.ts +22 -0
- package/@types/core/filter/filter.d.ts +23 -0
- package/@types/core/interpolate/interpolate.d.ts +38 -0
- package/@types/core/parse/ast/ast-node.d.ts +56 -0
- package/@types/core/parse/ast/ast.d.ts +164 -0
- package/@types/core/parse/lexer/lexer.d.ts +119 -0
- package/@types/core/parse/lexer/token.d.ts +17 -0
- package/@types/core/parse/parse.d.ts +33 -0
- package/@types/core/parse/parser/parser.d.ts +41 -0
- package/@types/core/sanitize/sanitize-uri.d.ts +40 -0
- package/@types/directive/aria/aria.d.ts +104 -0
- package/@types/directive/attrs/attrs.d.ts +8 -0
- package/@types/directive/bind/bind.d.ts +18 -0
- package/@types/directive/channel/channel.d.ts +10 -0
- package/@types/directive/class/class.d.ts +3 -0
- package/@types/directive/cloak/cloak.d.ts +4 -0
- package/@types/directive/controller/controller.d.ts +4 -0
- package/@types/directive/events/events.d.ts +21 -0
- package/@types/directive/form/form.d.ts +264 -0
- package/@types/directive/http/http.d.ts +46 -0
- package/@types/directive/if/if.d.ts +10 -0
- package/@types/directive/include/include.d.ts +28 -0
- package/@types/directive/init/init.d.ts +4 -0
- package/@types/directive/input/input.d.ts +70 -0
- package/@types/directive/messages/messages.d.ts +63 -0
- package/@types/directive/model/model.d.ts +515 -0
- package/@types/directive/model-options/model-options.d.ts +56 -0
- package/@types/directive/non-bindable/non-bindable.d.ts +4 -0
- package/@types/directive/observe/observe.d.ts +9 -0
- package/@types/directive/options/options.d.ts +13 -0
- package/@types/directive/ref/ref.d.ts +11 -0
- package/@types/directive/repeat/repeat.d.ts +11 -0
- package/@types/directive/script/script.d.ts +10 -0
- package/@types/directive/select/select.d.ts +15 -0
- package/@types/directive/setter/setter.d.ts +12 -0
- package/@types/directive/show-hide/show-hide.d.ts +19 -0
- package/@types/directive/style/style.d.ts +4 -0
- package/@types/directive/switch/switch.d.ts +18 -0
- package/@types/directive/transclude/transclude.d.ts +10 -0
- package/@types/directive/validators/validators.d.ts +149 -0
- package/@types/filters/filter.d.ts +4 -0
- package/@types/filters/filters.d.ts +38 -0
- package/@types/filters/limit-to.d.ts +4 -0
- package/@types/filters/order-by.d.ts +7 -0
- package/@types/index.d.ts +2 -0
- package/@types/interface.d.ts +5 -4
- package/@types/ng.d.ts +8 -0
- package/@types/router/common/trace.d.ts +66 -0
- package/@types/router/directives/state-directives.d.ts +46 -0
- package/@types/router/directives/view-directive.d.ts +138 -0
- package/@types/router/glob/glob.d.ts +81 -0
- package/@types/router/hooks/core-resolvables.d.ts +2 -0
- package/@types/router/hooks/ignored-transition.d.ts +1 -0
- package/@types/router/hooks/invalid-transition.d.ts +1 -0
- package/@types/router/hooks/lazy-load.d.ts +42 -0
- package/@types/router/hooks/on-enter-exit-retain.d.ts +3 -0
- package/@types/router/hooks/redirect-to.d.ts +4 -0
- package/@types/router/hooks/resolve.d.ts +4 -0
- package/@types/router/hooks/update-globals.d.ts +1 -0
- package/@types/router/hooks/url.d.ts +5 -0
- package/@types/router/hooks/views.d.ts +5 -0
- package/@types/router/params/interface.d.ts +606 -0
- package/@types/router/params/param-factory.d.ts +16 -0
- package/@types/router/params/param-type.d.ts +59 -0
- package/@types/router/params/param.d.ts +71 -0
- package/@types/router/params/state-params.d.ts +12 -0
- package/@types/router/path/path-node.d.ts +38 -0
- package/@types/router/path/path-utils.d.ts +88 -0
- package/@types/router/resolve/interface.d.ts +200 -0
- package/@types/router/resolve/resolvable.d.ts +50 -0
- package/@types/router/resolve/resolve-context.d.ts +93 -0
- package/@types/router/router.d.ts +47 -0
- package/@types/router/state/interface.d.ts +983 -0
- package/@types/router/state/state-builder.d.ts +95 -0
- package/@types/router/state/state-matcher.d.ts +7 -0
- package/@types/router/state/state-object.d.ts +83 -0
- package/@types/router/state/state-queue-manager.d.ts +29 -0
- package/@types/router/state/state-registry.d.ts +133 -0
- package/@types/router/state/state-service.d.ts +425 -0
- package/@types/router/state/target-state.d.ts +102 -0
- package/@types/router/state/views.d.ts +58 -0
- package/@types/router/state-filters.d.ts +39 -0
- package/@types/router/template-factory.d.ts +117 -0
- package/@types/router/transition/hook-builder.d.ts +45 -0
- package/@types/router/transition/hook-registry.d.ts +102 -0
- package/@types/router/transition/interface.d.ts +880 -0
- package/@types/router/transition/reject-factory.d.ts +43 -0
- package/@types/router/transition/transition-event-type.d.ts +24 -0
- package/@types/router/transition/transition-hook.d.ts +86 -0
- package/@types/router/transition/transition-service.d.ts +116 -0
- package/@types/router/transition/transition.d.ts +331 -0
- package/@types/router/url/url-config.d.ts +99 -0
- package/@types/router/url/url-matcher.d.ts +174 -0
- package/@types/router/url/url-rule.d.ts +161 -0
- package/@types/router/url/url-rules.d.ts +249 -0
- package/@types/router/url/url-service.d.ts +254 -0
- package/@types/router/view/interface.d.ts +44 -0
- package/@types/router/view/view.d.ts +149 -0
- package/@types/router/view-scroll.d.ts +10 -0
- package/@types/services/anchor-scroll.d.ts +25 -0
- package/@types/services/cookie-reader.d.ts +4 -0
- package/@types/services/http/http.d.ts +134 -0
- package/@types/services/http-backend/http-backend.d.ts +58 -0
- package/@types/services/sce/sce.d.ts +238 -0
- package/@types/services/template-request.d.ts +55 -0
- package/@types/shared/common.d.ts +197 -0
- package/@types/shared/hof.d.ts +108 -0
- package/@types/shared/predicates.d.ts +17 -0
- package/@types/shared/queue.d.ts +64 -0
- package/@types/shared/strings.d.ts +58 -0
- package/dist/angular-ts.esm.js +2 -3
- package/dist/angular-ts.umd.js +2 -3
- package/dist/angular-ts.umd.min.js +1 -1
- package/docs/layouts/shortcodes/version.html +1 -1
- package/package.json +1 -1
- package/src/interface.ts +5 -4
- package/src/services/pubsub/pubsub.js +0 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches URLs against patterns.
|
|
3
|
+
*
|
|
4
|
+
* Matches URLs against patterns and extracts named parameters from the path or the search
|
|
5
|
+
* part of the URL.
|
|
6
|
+
*
|
|
7
|
+
* A URL pattern consists of a path pattern, optionally followed by '?' and a list of search (query)
|
|
8
|
+
* parameters. Multiple search parameter names are separated by '&'. Search parameters
|
|
9
|
+
* do not influence whether or not a URL is matched, but their values are passed through into
|
|
10
|
+
* the matched parameters returned by [[UrlMatcher.exec]].
|
|
11
|
+
*
|
|
12
|
+
* - *Path parameters* are defined using curly brace placeholders (`/somepath/{param}`)
|
|
13
|
+
* or colon placeholders (`/somePath/:param`).
|
|
14
|
+
*
|
|
15
|
+
* - *A parameter RegExp* may be defined for a param after a colon
|
|
16
|
+
* (`/somePath/{param:[a-zA-Z0-9]+}`) in a curly brace placeholder.
|
|
17
|
+
* The regexp must match for the url to be matched.
|
|
18
|
+
* Should the regexp itself contain curly braces, they must be in matched pairs or escaped with a backslash.
|
|
19
|
+
*
|
|
20
|
+
* Note: a RegExp parameter will encode its value using either [[ParamTypes.path]] or [[ParamTypes.query]].
|
|
21
|
+
*
|
|
22
|
+
* - *Custom parameter types* may also be specified after a colon (`/somePath/{param:int}`) in curly brace parameters.
|
|
23
|
+
* See [[UrlMatcherFactory.type]] for more information.
|
|
24
|
+
*
|
|
25
|
+
* - *Catch-all parameters* are defined using an asterisk placeholder (`/somepath/*catchallparam`).
|
|
26
|
+
* A catch-all * parameter value will contain the remainder of the URL.
|
|
27
|
+
*
|
|
28
|
+
* ---
|
|
29
|
+
*
|
|
30
|
+
* Parameter names may contain only word characters (latin letters, digits, and underscore) and
|
|
31
|
+
* must be unique within the pattern (across both path and search parameters).
|
|
32
|
+
* A path parameter matches any number of characters other than '/'. For catch-all
|
|
33
|
+
* placeholders the path parameter matches any number of characters.
|
|
34
|
+
*
|
|
35
|
+
* Examples:
|
|
36
|
+
*
|
|
37
|
+
* * `'/hello/'` - Matches only if the path is exactly '/hello/'. There is no special treatment for
|
|
38
|
+
* trailing slashes, and patterns have to match the entire path, not just a prefix.
|
|
39
|
+
* * `'/user/:id'` - Matches '/user/bob' or '/user/1234!!!' or even '/user/' but not '/user' or
|
|
40
|
+
* '/user/bob/details'. The second path segment will be captured as the parameter 'id'.
|
|
41
|
+
* * `'/user/{id}'` - Same as the previous example, but using curly brace syntax.
|
|
42
|
+
* * `'/user/{id:[^/]*}'` - Same as the previous example.
|
|
43
|
+
* * `'/user/{id:[0-9a-fA-F]{1,8}}'` - Similar to the previous example, but only matches if the id
|
|
44
|
+
* parameter consists of 1 to 8 hex digits.
|
|
45
|
+
* * `'/files/{path:.*}'` - Matches any URL starting with '/files/' and captures the rest of the
|
|
46
|
+
* path into the parameter 'path'.
|
|
47
|
+
* * `'/files/*path'` - ditto.
|
|
48
|
+
* * `'/calendar/{start:date}'` - Matches "/calendar/2014-11-12" (because the pattern defined
|
|
49
|
+
* in the built-in `date` ParamType matches `2014-11-12`) and provides a Date object in $stateParams.start
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
export class UrlMatcher {
|
|
53
|
+
/** @internal Given a matcher, return an array with the matcher's path segments and path params, in order */
|
|
54
|
+
static pathSegmentsAndParams(matcher: any): any;
|
|
55
|
+
/** @internal Given a matcher, return an array with the matcher's query params */
|
|
56
|
+
static queryParams(matcher: any): any;
|
|
57
|
+
/**
|
|
58
|
+
* Compare two UrlMatchers
|
|
59
|
+
*
|
|
60
|
+
* This comparison function converts a UrlMatcher into static and dynamic path segments.
|
|
61
|
+
* Each static path segment is a static string between a path separator (slash character).
|
|
62
|
+
* Each dynamic segment is a path parameter.
|
|
63
|
+
*
|
|
64
|
+
* The comparison function sorts static segments before dynamic ones.
|
|
65
|
+
*/
|
|
66
|
+
static compare(a: any, b: any): number;
|
|
67
|
+
/**
|
|
68
|
+
* @param pattern The pattern to compile into a matcher.
|
|
69
|
+
* @param paramTypes The [[ParamTypes]] registry
|
|
70
|
+
* @param paramFactory A [[ParamFactory]] object
|
|
71
|
+
* @param config A [[UrlMatcherCompileConfig]] configuration object
|
|
72
|
+
*/
|
|
73
|
+
constructor(pattern: any, paramTypes: any, paramFactory: any, config: any);
|
|
74
|
+
_cache: {
|
|
75
|
+
path: UrlMatcher[];
|
|
76
|
+
};
|
|
77
|
+
_children: any[];
|
|
78
|
+
_params: any[];
|
|
79
|
+
_segments: any[];
|
|
80
|
+
_compiled: any[];
|
|
81
|
+
config: any;
|
|
82
|
+
pattern: any;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a new concatenated UrlMatcher
|
|
85
|
+
*
|
|
86
|
+
* Builds a new UrlMatcher by appending another UrlMatcher to this one.
|
|
87
|
+
*
|
|
88
|
+
* @param url A `UrlMatcher` instance to append as a child of the current `UrlMatcher`.
|
|
89
|
+
*/
|
|
90
|
+
append(url: any): any;
|
|
91
|
+
isRoot(): boolean;
|
|
92
|
+
/** Returns the input pattern string */
|
|
93
|
+
toString(): any;
|
|
94
|
+
_getDecodedParamValue(value: any, param: any): any;
|
|
95
|
+
/**
|
|
96
|
+
* Tests the specified url/path against this matcher.
|
|
97
|
+
*
|
|
98
|
+
* Tests if the given url matches this matcher's pattern, and returns an object containing the captured
|
|
99
|
+
* parameter values. Returns null if the path does not match.
|
|
100
|
+
*
|
|
101
|
+
* The returned object contains the values
|
|
102
|
+
* of any search parameters that are mentioned in the pattern, but their value may be null if
|
|
103
|
+
* they are not present in `search`. This means that search parameters are always treated
|
|
104
|
+
* as optional.
|
|
105
|
+
*
|
|
106
|
+
* #### Example:
|
|
107
|
+
* ```js
|
|
108
|
+
* new UrlMatcher('/user/{id}?q&r').exec('/user/bob', {
|
|
109
|
+
* x: '1', q: 'hello'
|
|
110
|
+
* });
|
|
111
|
+
* // returns { id: 'bob', q: 'hello', r: null }
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @param path The URL path to match, e.g. `$location.getPath()`.
|
|
115
|
+
* @param search URL search parameters, e.g. `$location.getSearch()`.
|
|
116
|
+
* @param hash URL hash e.g. `$location.getHash()`.
|
|
117
|
+
*
|
|
118
|
+
* @returns The captured parameter values.
|
|
119
|
+
*/
|
|
120
|
+
exec(
|
|
121
|
+
path: any,
|
|
122
|
+
search: {},
|
|
123
|
+
hash: any,
|
|
124
|
+
): {
|
|
125
|
+
"#": any;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* @internal
|
|
129
|
+
* Returns all the [[Param]] objects of all path and search parameters of this pattern in order of appearance.
|
|
130
|
+
*
|
|
131
|
+
* @returns {Array.<Param>} An array of [[Param]] objects. Must be treated as read-only. If the
|
|
132
|
+
* pattern has no parameters, an empty array is returned.
|
|
133
|
+
*/
|
|
134
|
+
parameters(opts?: {}): Array<Param>;
|
|
135
|
+
/**
|
|
136
|
+
* @internal
|
|
137
|
+
* Returns a single parameter from this UrlMatcher by id
|
|
138
|
+
*
|
|
139
|
+
* @param id
|
|
140
|
+
* @param opts
|
|
141
|
+
* @returns {Param|any|boolean|UrlMatcher|null}
|
|
142
|
+
*/
|
|
143
|
+
parameter(id: any, opts?: {}): Param | any | boolean | UrlMatcher | null;
|
|
144
|
+
/**
|
|
145
|
+
* Validates the input parameter values against this UrlMatcher
|
|
146
|
+
*
|
|
147
|
+
* Checks an object hash of parameters to validate their correctness according to the parameter
|
|
148
|
+
* types of this `UrlMatcher`.
|
|
149
|
+
*
|
|
150
|
+
* @param params The object hash of parameters to validate.
|
|
151
|
+
* @returns Returns `true` if `params` validates, otherwise `false`.
|
|
152
|
+
*/
|
|
153
|
+
validates(params: any): any;
|
|
154
|
+
/**
|
|
155
|
+
* Given a set of parameter values, creates a URL from this UrlMatcher.
|
|
156
|
+
*
|
|
157
|
+
* Creates a URL that matches this pattern by substituting the specified values
|
|
158
|
+
* for the path and search parameters.
|
|
159
|
+
*
|
|
160
|
+
* #### Example:
|
|
161
|
+
* ```js
|
|
162
|
+
* new UrlMatcher('/user/{id}?q').format({ id:'bob', q:'yes' });
|
|
163
|
+
* // returns '/user/bob?q=yes'
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @param values the values to substitute for the parameters in this pattern.
|
|
167
|
+
* @returns the formatted URL (path and optionally search part).
|
|
168
|
+
*/
|
|
169
|
+
format(values?: {}): string;
|
|
170
|
+
}
|
|
171
|
+
export namespace UrlMatcher {
|
|
172
|
+
let nameValidator: RegExp;
|
|
173
|
+
}
|
|
174
|
+
import { Param } from "../params/param.js";
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a [[UrlRule]]
|
|
3
|
+
*
|
|
4
|
+
* Creates a [[UrlRule]] from a:
|
|
5
|
+
*
|
|
6
|
+
* - `string`
|
|
7
|
+
* - [[UrlMatcher]]
|
|
8
|
+
* - `RegExp`
|
|
9
|
+
* - [[StateObject]]
|
|
10
|
+
*/
|
|
11
|
+
export class UrlRuleFactory {
|
|
12
|
+
/**
|
|
13
|
+
* @param {import('../url/url-service.js').UrlService} urlService
|
|
14
|
+
* @param {import('../state/state-service.js').StateProvider} stateService
|
|
15
|
+
* @param {import('../router.js').Router} routerGlobals
|
|
16
|
+
*/
|
|
17
|
+
constructor(
|
|
18
|
+
urlService: import("../url/url-service.js").UrlService,
|
|
19
|
+
stateService: import("../state/state-service.js").StateProvider,
|
|
20
|
+
routerGlobals: import("../router.js").Router,
|
|
21
|
+
);
|
|
22
|
+
urlService: import("../url/url-service.js").UrlService;
|
|
23
|
+
stateService: import("../state/state-service.js").StateProvider;
|
|
24
|
+
routerGlobals: import("../router.js").Router;
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param {*} what
|
|
28
|
+
* @param {*} handler
|
|
29
|
+
* @returns {BaseUrlRule}
|
|
30
|
+
*/
|
|
31
|
+
create(what: any, handler: any): BaseUrlRule;
|
|
32
|
+
/**
|
|
33
|
+
* A UrlRule which matches based on a UrlMatcher
|
|
34
|
+
*
|
|
35
|
+
* The `handler` may be either a `string`, a [[UrlRuleHandlerFn]] or another [[UrlMatcher]]
|
|
36
|
+
*
|
|
37
|
+
* ## Handler as a function
|
|
38
|
+
*
|
|
39
|
+
* If `handler` is a function, the function is invoked with:
|
|
40
|
+
*
|
|
41
|
+
* - matched parameter values ([[RawParams]] from [[UrlMatcher.exec]])
|
|
42
|
+
* - url: the current Url ([[UrlParts]])
|
|
43
|
+
* - router: the router object ([[UIRouter]])
|
|
44
|
+
*
|
|
45
|
+
* #### Example:
|
|
46
|
+
* ```js
|
|
47
|
+
* var urlMatcher = $umf.compile("/foo/:fooId/:barId");
|
|
48
|
+
* var rule = factory.fromUrlMatcher(urlMatcher, match => "/home/" + match.fooId + "/" + match.barId);
|
|
49
|
+
* var match = rule.match('/foo/123/456'); // results in { fooId: '123', barId: '456' }
|
|
50
|
+
* var result = rule.handler(match); // '/home/123/456'
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* ## Handler as UrlMatcher
|
|
54
|
+
*
|
|
55
|
+
* If `handler` is a UrlMatcher, the handler matcher is used to create the new url.
|
|
56
|
+
* The `handler` UrlMatcher is formatted using the matched param from the first matcher.
|
|
57
|
+
* The url is replaced with the result.
|
|
58
|
+
*
|
|
59
|
+
* #### Example:
|
|
60
|
+
* ```js
|
|
61
|
+
* var urlMatcher = $umf.compile("/foo/:fooId/:barId");
|
|
62
|
+
* var handler = $umf.compile("/home/:fooId/:barId");
|
|
63
|
+
* var rule = factory.fromUrlMatcher(urlMatcher, handler);
|
|
64
|
+
* var match = rule.match('/foo/123/456'); // results in { fooId: '123', barId: '456' }
|
|
65
|
+
* var result = rule.handler(match); // '/home/123/456'
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
fromUrlMatcher(
|
|
69
|
+
urlMatcher: any,
|
|
70
|
+
handler: any,
|
|
71
|
+
): BaseUrlRule & {
|
|
72
|
+
urlMatcher: any;
|
|
73
|
+
matchPriority: (params: any) => number;
|
|
74
|
+
type: string;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* A UrlRule which matches a state by its url
|
|
78
|
+
*
|
|
79
|
+
* #### Example:
|
|
80
|
+
* ```js
|
|
81
|
+
* var rule = factory.fromState($state.get('foo'), router);
|
|
82
|
+
* var match = rule.match('/foo/123/456'); // results in { fooId: '123', barId: '456' }
|
|
83
|
+
* var result = rule.handler(match);
|
|
84
|
+
* // Starts a transition to 'foo' with params: { fooId: '123', barId: '456' }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
fromState(
|
|
88
|
+
stateOrDecl: any,
|
|
89
|
+
stateService: any,
|
|
90
|
+
globals: any,
|
|
91
|
+
): BaseUrlRule & {
|
|
92
|
+
urlMatcher: any;
|
|
93
|
+
matchPriority: (params: any) => number;
|
|
94
|
+
type: string;
|
|
95
|
+
} & {
|
|
96
|
+
state: any;
|
|
97
|
+
type: string;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* A UrlRule which matches based on a regular expression
|
|
101
|
+
*
|
|
102
|
+
* The `handler` may be either a [[UrlRuleHandlerFn]] or a string.
|
|
103
|
+
*
|
|
104
|
+
* ## Handler as a function
|
|
105
|
+
*
|
|
106
|
+
* If `handler` is a function, the function is invoked with:
|
|
107
|
+
*
|
|
108
|
+
* - regexp match array (from `regexp`)
|
|
109
|
+
* - url: the current Url ([[UrlParts]])
|
|
110
|
+
* - router: the router object ([[UIRouter]])
|
|
111
|
+
*
|
|
112
|
+
* #### Example:
|
|
113
|
+
* ```js
|
|
114
|
+
* var rule = factory.fromRegExp(/^\/foo\/(bar|baz)$/, match => "/home/" + match[1])
|
|
115
|
+
* var match = rule.match('/foo/bar'); // results in [ '/foo/bar', 'bar' ]
|
|
116
|
+
* var result = rule.handler(match); // '/home/bar'
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* ## Handler as string
|
|
120
|
+
*
|
|
121
|
+
* If `handler` is a string, the url is *replaced by the string* when the Rule is invoked.
|
|
122
|
+
* The string is first interpolated using `string.replace()` style pattern.
|
|
123
|
+
*
|
|
124
|
+
* #### Example:
|
|
125
|
+
* ```js
|
|
126
|
+
* var rule = factory.fromRegExp(/^\/foo\/(bar|baz)$/, "/home/$1")
|
|
127
|
+
* var match = rule.match('/foo/bar'); // results in [ '/foo/bar', 'bar' ]
|
|
128
|
+
* var result = rule.handler(match); // '/home/bar'
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
fromRegExp(
|
|
132
|
+
regexp: any,
|
|
133
|
+
handler: any,
|
|
134
|
+
): BaseUrlRule & {
|
|
135
|
+
regexp: any;
|
|
136
|
+
type: string;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export namespace UrlRuleFactory {
|
|
140
|
+
function isUrlRule(obj: any): boolean;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* A base rule which calls `match`
|
|
144
|
+
*
|
|
145
|
+
* The value from the `match` function is passed through to the `handler`.
|
|
146
|
+
*/
|
|
147
|
+
export class BaseUrlRule {
|
|
148
|
+
constructor(match: any, handler: any);
|
|
149
|
+
match: any;
|
|
150
|
+
type: string;
|
|
151
|
+
$id: number;
|
|
152
|
+
_group: any;
|
|
153
|
+
handler: any;
|
|
154
|
+
priority: any;
|
|
155
|
+
/**
|
|
156
|
+
* This function should be overridden
|
|
157
|
+
* @param {*} [params]
|
|
158
|
+
* @returns {number}
|
|
159
|
+
*/
|
|
160
|
+
matchPriority(params?: any): number;
|
|
161
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API for managing URL rules
|
|
3
|
+
*
|
|
4
|
+
* This API is used to create and manage URL rules.
|
|
5
|
+
* URL rules are a mechanism to respond to specific URL patterns.
|
|
6
|
+
*
|
|
7
|
+
* The most commonly used methods are [[otherwise]] and [[when]].
|
|
8
|
+
*
|
|
9
|
+
* This API is found at `$url.rules` (see: [[UIRouter.urlService]], [[URLService.rules]])
|
|
10
|
+
*/
|
|
11
|
+
export class UrlRules {
|
|
12
|
+
/** @param {UrlRuleFactory} urlRuleFactory */
|
|
13
|
+
constructor(urlRuleFactory: UrlRuleFactory);
|
|
14
|
+
_sortFn: typeof defaultRuleSortFn;
|
|
15
|
+
_rules: any[];
|
|
16
|
+
_id: number;
|
|
17
|
+
urlRuleFactory: UrlRuleFactory;
|
|
18
|
+
/**
|
|
19
|
+
* Defines the initial state, path, or behavior to use when the app starts.
|
|
20
|
+
*
|
|
21
|
+
* This rule defines the initial/starting state for the application.
|
|
22
|
+
*
|
|
23
|
+
* This rule is triggered the first time the URL is checked (when the app initially loads).
|
|
24
|
+
* The rule is triggered only when the url matches either `""` or `"/"`.
|
|
25
|
+
*
|
|
26
|
+
* Note: The rule is intended to be used when the root of the application is directly linked to.
|
|
27
|
+
* When the URL is *not* `""` or `"/"` and doesn't match other rules, the [[otherwise]] rule is triggered.
|
|
28
|
+
* This allows 404-like behavior when an unknown URL is deep-linked.
|
|
29
|
+
*
|
|
30
|
+
* #### Example:
|
|
31
|
+
* Start app at `home` state.
|
|
32
|
+
* ```js
|
|
33
|
+
* .initial({ state: 'home' });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* #### Example:
|
|
37
|
+
* Start app at `/home` (by url)
|
|
38
|
+
* ```js
|
|
39
|
+
* .initial('/home');
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* #### Example:
|
|
43
|
+
* When no other url rule matches, go to `home` state
|
|
44
|
+
* ```js
|
|
45
|
+
* .initial((matchValue, url, router) => {
|
|
46
|
+
* console.log('initial state');
|
|
47
|
+
* return { state: 'home' };
|
|
48
|
+
* })
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @param handler The initial state or url path, or a function which returns the state or url path (or performs custom logic).
|
|
52
|
+
*/
|
|
53
|
+
initial(handler: any): void;
|
|
54
|
+
/**
|
|
55
|
+
* Defines the state, url, or behavior to use when no other rule matches the URL.
|
|
56
|
+
*
|
|
57
|
+
* This rule is matched when *no other rule* matches.
|
|
58
|
+
* It is generally used to handle unknown URLs (similar to "404" behavior, but on the client side).
|
|
59
|
+
*
|
|
60
|
+
* - If `handler` a string, it is treated as a url redirect
|
|
61
|
+
*
|
|
62
|
+
* #### Example:
|
|
63
|
+
* When no other url rule matches, redirect to `/index`
|
|
64
|
+
* ```js
|
|
65
|
+
* .otherwise('/index');
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* - If `handler` is an object with a `state` property, the state is activated.
|
|
69
|
+
*
|
|
70
|
+
* #### Example:
|
|
71
|
+
* When no other url rule matches, redirect to `home` and provide a `dashboard` parameter value.
|
|
72
|
+
* ```js
|
|
73
|
+
* .otherwise({ state: 'home', params: { dashboard: 'default' } });
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* - If `handler` is a function, the function receives the current url ([[UrlParts]]) and the [[UIRouter]] object.
|
|
77
|
+
* The function can perform actions, and/or return a value.
|
|
78
|
+
*
|
|
79
|
+
* #### Example:
|
|
80
|
+
* When no other url rule matches, manually trigger a transition to the `home` state
|
|
81
|
+
* ```js
|
|
82
|
+
* .otherwise((matchValue, urlParts, router) => {
|
|
83
|
+
* router.stateService.go('home');
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* #### Example:
|
|
88
|
+
* When no other url rule matches, go to `home` state
|
|
89
|
+
* ```js
|
|
90
|
+
* .otherwise((matchValue, urlParts, router) => {
|
|
91
|
+
* return { state: 'home' };
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @param handler The url path to redirect to, or a function which returns the url path (or performs custom logic).
|
|
96
|
+
*/
|
|
97
|
+
otherwise(handler: any): void;
|
|
98
|
+
_otherwiseFn: import("./url-rule.js").BaseUrlRule;
|
|
99
|
+
_sorted: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Remove a rule previously registered
|
|
102
|
+
*
|
|
103
|
+
* @param rule the matcher rule that was previously registered using [[rule]]
|
|
104
|
+
*/
|
|
105
|
+
removeRule(rule: any): void;
|
|
106
|
+
/**
|
|
107
|
+
* Manually adds a URL Rule.
|
|
108
|
+
*
|
|
109
|
+
* Usually, a url rule is added using [[StateDeclaration.url]] or [[when]].
|
|
110
|
+
* This api can be used directly for more control (to register a [[BaseUrlRule]], for example).
|
|
111
|
+
* Rules can be created using [[urlRuleFactory]], or created manually as simple objects.
|
|
112
|
+
*
|
|
113
|
+
* A rule should have a `match` function which returns truthy if the rule matched.
|
|
114
|
+
* It should also have a `handler` function which is invoked if the rule is the best match.
|
|
115
|
+
*
|
|
116
|
+
* @return a function that deregisters the rule
|
|
117
|
+
*/
|
|
118
|
+
rule(rule: any): () => void;
|
|
119
|
+
/**
|
|
120
|
+
* Gets all registered rules
|
|
121
|
+
*
|
|
122
|
+
* @returns an array of all the registered rules
|
|
123
|
+
*/
|
|
124
|
+
rules(): any[];
|
|
125
|
+
/**
|
|
126
|
+
* Defines URL Rule priorities
|
|
127
|
+
*
|
|
128
|
+
* More than one rule ([[UrlRule]]) might match a given URL.
|
|
129
|
+
* This `compareFn` is used to sort the rules by priority.
|
|
130
|
+
* Higher priority rules should sort earlier.
|
|
131
|
+
*
|
|
132
|
+
* The [[defaultRuleSortFn]] is used by default.
|
|
133
|
+
*
|
|
134
|
+
* You only need to call this function once.
|
|
135
|
+
* The `compareFn` will be used to sort the rules as each is registered.
|
|
136
|
+
*
|
|
137
|
+
* If called without any parameter, it will re-sort the rules.
|
|
138
|
+
*
|
|
139
|
+
* ---
|
|
140
|
+
*
|
|
141
|
+
* Url rules may come from multiple sources: states's urls ([[StateDeclaration.url]]), [[when]], and [[rule]].
|
|
142
|
+
* Each rule has a (user-provided) [[UrlRule.priority]], a [[UrlRule.type]], and a [[UrlRule.$id]]
|
|
143
|
+
* The `$id` is is the order in which the rule was registered.
|
|
144
|
+
*
|
|
145
|
+
* The sort function should use these data, or data found on a specific type
|
|
146
|
+
* of [[UrlRule]] (such as [[StateRule.state]]), to order the rules as desired.
|
|
147
|
+
*
|
|
148
|
+
* #### Example:
|
|
149
|
+
* This compare function prioritizes rules by the order in which the rules were registered.
|
|
150
|
+
* A rule registered earlier has higher priority.
|
|
151
|
+
*
|
|
152
|
+
* ```js
|
|
153
|
+
* function compareFn(a, b) {
|
|
154
|
+
* return a.$id - b.$id;
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @param compareFn a function that compares to [[UrlRule]] objects.
|
|
159
|
+
* The `compareFn` should abide by the `Array.sort` compare function rules.
|
|
160
|
+
* Given two rules, `a` and `b`, return a negative number if `a` should be higher priority.
|
|
161
|
+
* Return a positive number if `b` should be higher priority.
|
|
162
|
+
* Return `0` if the rules are identical.
|
|
163
|
+
*
|
|
164
|
+
* See the [mozilla reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Description)
|
|
165
|
+
* for details.
|
|
166
|
+
*/
|
|
167
|
+
sort(compareFn: any): void;
|
|
168
|
+
ensureSorted(): void;
|
|
169
|
+
stableSort(arr: any, compareFn: any): any;
|
|
170
|
+
/**
|
|
171
|
+
* Registers a `matcher` and `handler` for custom URLs handling.
|
|
172
|
+
*
|
|
173
|
+
* The `matcher` can be:
|
|
174
|
+
*
|
|
175
|
+
* - a [[UrlMatcher]]: See: [[UrlMatcherFactory.compile]]
|
|
176
|
+
* - a `string`: The string is compiled to a [[UrlMatcher]]
|
|
177
|
+
* - a `RegExp`: The regexp is used to match the url.
|
|
178
|
+
*
|
|
179
|
+
* The `handler` can be:
|
|
180
|
+
*
|
|
181
|
+
* - a string: The url is redirected to the value of the string.
|
|
182
|
+
* - a function: The url is redirected to the return value of the function.
|
|
183
|
+
*
|
|
184
|
+
* ---
|
|
185
|
+
*
|
|
186
|
+
* When the `handler` is a `string` and the `matcher` is a `UrlMatcher` (or string), the redirect
|
|
187
|
+
* string is interpolated with parameter values.
|
|
188
|
+
*
|
|
189
|
+
* #### Example:
|
|
190
|
+
* When the URL is `/foo/123` the rule will redirect to `/bar/123`.
|
|
191
|
+
* ```js
|
|
192
|
+
* .when("/foo/:param1", "/bar/:param1")
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* ---
|
|
196
|
+
*
|
|
197
|
+
* When the `handler` is a string and the `matcher` is a `RegExp`, the redirect string is
|
|
198
|
+
* interpolated with capture groups from the RegExp.
|
|
199
|
+
*
|
|
200
|
+
* #### Example:
|
|
201
|
+
* When the URL is `/foo/123` the rule will redirect to `/bar/123`.
|
|
202
|
+
* ```js
|
|
203
|
+
* .when(new RegExp("^/foo/(.*)$"), "/bar/$1");
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* ---
|
|
207
|
+
*
|
|
208
|
+
* When the handler is a function, it receives the matched value, the current URL, and the `UIRouter` object (See [[UrlRuleHandlerFn]]).
|
|
209
|
+
* The "matched value" differs based on the `matcher`.
|
|
210
|
+
* For [[UrlMatcher]]s, it will be the matched state params.
|
|
211
|
+
* For `RegExp`, it will be the match array from `regexp.exec()`.
|
|
212
|
+
*
|
|
213
|
+
* If the handler returns a string, the URL is redirected to the string.
|
|
214
|
+
*
|
|
215
|
+
* #### Example:
|
|
216
|
+
* When the URL is `/foo/123` the rule will redirect to `/bar/123`.
|
|
217
|
+
* ```js
|
|
218
|
+
* .when(new RegExp("^/foo/(.*)$"), match => "/bar/" + match[1]);
|
|
219
|
+
* ```
|
|
220
|
+
*
|
|
221
|
+
* Note: the `handler` may also invoke arbitrary code, such as `$state.go()`
|
|
222
|
+
*
|
|
223
|
+
* @param matcher A pattern `string` to match, compiled as a [[UrlMatcher]], or a `RegExp`.
|
|
224
|
+
* @param handler The path to redirect to, or a function that returns the path.
|
|
225
|
+
* @param options `{ priority: number }`
|
|
226
|
+
*
|
|
227
|
+
* @return the registered [[UrlRule]]
|
|
228
|
+
*/
|
|
229
|
+
when(
|
|
230
|
+
matcher: any,
|
|
231
|
+
handler: any,
|
|
232
|
+
options: any,
|
|
233
|
+
): import("./url-rule.js").BaseUrlRule;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Default rule priority sorting function.
|
|
237
|
+
*
|
|
238
|
+
* Sorts rules by:
|
|
239
|
+
*
|
|
240
|
+
* - Explicit priority (set rule priority using [[UrlRules.when]])
|
|
241
|
+
* - Rule type (STATE: 4, URLMATCHER: 4, REGEXP: 3, RAW: 2, OTHER: 1)
|
|
242
|
+
* - `UrlMatcher` specificity ([[UrlMatcher.compare]]): works for STATE and URLMATCHER types to pick the most specific rule.
|
|
243
|
+
* - Rule registration order (for rule types other than STATE and URLMATCHER)
|
|
244
|
+
* - Equally sorted State and UrlMatcher rules will each match the URL.
|
|
245
|
+
* Then, the *best* match is chosen based on how many parameter values were matched.
|
|
246
|
+
*/
|
|
247
|
+
declare function defaultRuleSortFn(a: any, b: any): number;
|
|
248
|
+
import { UrlRuleFactory } from "./url-rule.js";
|
|
249
|
+
export {};
|