/
interface.ts
173 lines (153 loc) · 5.02 KB
/
interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
* # URL subsystem
*
* Contains code related to managing the URL
*
* The primary API is found in [[UrlService]], [[UrlService.config]], and [[UrlService.rules]].
*
* @packageDocumentation
* @preferred
*/
import { LocationConfig } from '../common';
import { UIRouter } from '../router';
import { StateDeclaration, StateObject, TargetState, TargetStateDef } from '../state';
import { UrlMatcher } from './urlMatcher';
import { UrlConfig } from './urlConfig';
import { UrlRules } from './urlRules';
import { UrlService } from './urlService';
export interface UrlMatcherCompileConfig {
// If state is provided, use the configuration in the `params` block
state?: StateDeclaration;
strict?: boolean;
caseInsensitive?: boolean;
}
/** @deprecated use [[UrlConfig]] */
export interface UrlConfigApi extends LocationConfig, UrlMatcherConfig {}
/** @deprecated use [[UrlConfig]] */
export interface UrlMatcherConfig {
/** See: [[UrlConfig.caseInsensitive]] */ caseInsensitive: UrlConfig['caseInsensitive'];
/** See: [[UrlConfig.strictMode]] */ strictMode: UrlConfig['strictMode'];
/** See: [[UrlConfig.defaultSquashPolicy]] */ defaultSquashPolicy: UrlConfig['defaultSquashPolicy'];
/** See: [[UrlConfig.type]] */ type: UrlConfig['type'];
}
/** @deprecated use [[UrlService]] */
export interface UrlSyncApi {
/** See: [[UrlService.sync]] */ sync: UrlService['sync'];
/** See: [[UrlService.listen]] */ listen: UrlService['listen'];
/** See: [[UrlService.deferIntercept]] */ deferIntercept: UrlService['deferIntercept'];
}
/** @deprecated use [[UrlRules]] */
export interface UrlRulesApi {
/** See: [[UrlRules.sort]] */ sort: UrlRules['sort'];
/** See: [[UrlRules.when]] */ when: UrlRules['when'];
/** See: [[UrlRules.otherwise]] */ otherwise: UrlRules['otherwise'];
/** See: [[UrlRules.initial]] */ initial: UrlRules['initial'];
/** See: [[UrlRules.rules]] */ rules: UrlRules['rules'];
/** See: [[UrlRules.rule]] */ rule: UrlRules['rule'];
/** See: [[UrlRules.removeRule]] */ removeRule: UrlRules['removeRule'];
}
/**
* An object containing the three parts of a URL
*/
export interface UrlParts {
path: string;
search?: { [key: string]: any };
hash?: string;
}
/**
* A UrlRule match result
*
* The result of UrlRouter.match()
*/
export interface MatchResult {
/** The matched value from a [[UrlRule]] */
match: any;
/** The rule that matched */
rule: UrlRule;
/** The match result weight */
weight: number;
}
/**
* A function that matches the URL for a [[UrlRule]]
*
* Implementations should match against the provided [[UrlParts]] and return the matched value (truthy) if the rule matches.
* If this rule is selected, the matched value is passed to the [[UrlRuleHandlerFn]].
*
* @return the matched value, either truthy or falsey
*/
export interface UrlRuleMatchFn {
(url?: UrlParts, router?: UIRouter): any;
}
/**
* Handler invoked when a rule is matched
*
* The matched value from the rule's [[UrlRuleMatchFn]] is passed as the first argument
* The handler should return a string (to redirect), a [[TargetState]]/[[TargetStateDef]], or void
*
* If the handler returns a string, the url is replaced with the string.
* If the handler returns a [[TargetState]], the target state is activated.
*/
export interface UrlRuleHandlerFn {
(matchValue?: any, url?: UrlParts, router?: UIRouter): string | TargetState | TargetStateDef | void;
}
/** @internal */
export type UrlRuleType = 'STATE' | 'URLMATCHER' | 'REGEXP' | 'RAW' | 'OTHER';
/**
* The interface for a URL Rule
*
* If you are creating a rule for use with [[UrlRules.rule]], it should implement this interface.
*/
export interface UrlRule {
/**
* The rule's ID.
*
* IDs are auto-assigned when the rule is registered, in increasing order.
*/
$id: number;
/**
* The rule's priority (defaults to 0).
*
* This can be used to explicitly modify the rule's priority.
* Higher numbers are higher priority.
*/
priority: number;
/** @internal */
_group: number;
/** The type of the rule */
type: UrlRuleType;
/**
* This function should match the url and return the match details
*
* See [[UrlRuleMatchFn]] for details
*/
match: UrlRuleMatchFn;
/**
* This function is called if the rule matched, and was selected as the "best match".
* This function handles the rule match event.
*
* See [[UrlRuleHandlerFn]] for details
*/
handler: UrlRuleHandlerFn;
/**
* The priority of a given match.
*
* Sometimes more than one UrlRule might have matched.
* This method is used to choose the best match.
*
* If multiple rules matched, each rule's `matchPriority` is called with the value from [[match]].
* The rule with the highest `matchPriority` has its [[handler]] called.
*/
matchPriority(match: any): number;
}
export interface MatcherUrlRule extends UrlRule {
type: 'URLMATCHER' | 'STATE';
urlMatcher: UrlMatcher;
}
export interface StateRule extends MatcherUrlRule {
type: 'STATE';
state: StateObject;
}
export interface RegExpRule extends UrlRule {
type: 'REGEXP';
regexp: RegExp;
}