-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.d.ts
219 lines (213 loc) · 5.27 KB
/
index.d.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import { FC, CSSProperties, ComponentType, DependencyList } from 'react';
import { match } from 'react-router';
interface IConfig {
name: string;
beforeRoute?: IBeforeRoute;
afterRoute?: IAfterRoute;
alive: boolean;
selfMatched: boolean[];
path: string;
switchRoute: boolean;
transition?: ITransition;
delay: number;
haveBeforeEach: boolean;
ready: boolean;
prefetch?: string[];
prefetchDelay?: number;
}
export interface IRefObj {
historyChangeHandler?: () => void;
stack: string[];
isReplace: boolean;
originalTitle: string;
map: {
[path: string]: IConfig;
};
actives: {
[path: string]: {
[id: string]: EffectHook
};
};
deactives: {
[path: string]: {
[id: string]: EffectHook;
}
};
matched: boolean[];
preload: {
[path: string]: () => Promise<{ default: any }>;
};
}
export type IBeforeRoute = (from: string, to: string) => boolean | undefined | void | Promise<boolean | undefined | void>;
export type IAfterRoute = (from: string, to: string) => void;
export type ITransition = {
match: CSSProperties;
notMatch: CSSProperties;
trans: CSSProperties;
/**
* keep component after unmatched
* - default is `500`ms
*/
delay?: number;
};
export type EffectHook = () => void;
export type ActiveHook = (effect: EffectHook, deps?: DependencyList) => void;
/**
* Router Configuration
* the path in children will be jointed with the path in parent
*/
export interface IPageRouter {
/**
* route path
*/
path: string;
/**
* document.title, if not set, will use original title in html
*/
name?: string;
/**
* the lazy load Component
*/
Component?: () => (Promise<ComponentType<any>> | ComponentType<any>);
/**
* children configuration
*/
children?: IPageRouter[];
/**
* triggered before entering route
* - if return false, deny to enter route\
* - after `beforeEach`
*/
beforeRoute?: IBeforeRoute;
/**
* triggered after entering route
* - if return false, deny to enter route
* - ahead of `afterEach`
*/
afterRoute?: IAfterRoute;
/**
* maintains component state and avoids repeated re-rendering for the route
* - default is `false`
* - its priority is higher than `keepAlive` in props
*/
keepAlive?: boolean;
/**
* transition animation
*/
transition?: ITransition;
/**
* the path list to prefetch
* - parent node prefetch will be append after current node prefetch
*/
prefetch?: string[];
}
/**
* `react-routers` props
*/
export interface IRouterProps {
/**
* routers config
*/
routers: IPageRouter[];
/**
* A fallback react tree to show when a Suspense child (like React.lazy) suspends, and before entering the route
*/
fallback?: ComponentType<{ from: string; to: string }>;
/**
* redirect path
*/
redirect?: string;
/**
* css style
*/
style?: CSSProperties;
/**
* triggered before entering route
* - if return false, deny to enter route
* - ahead of any `beforeRoute`
*/
beforeEach?: IBeforeRoute;
/**
* triggered after entering route
* - if return false, deny to enter route
* - after any `afterRoute`
*/
afterEach?: IAfterRoute;
/**
* do maintains component state and avoids repeated re-rendering for each route
* - default is `false`
*/
keepAlive?: boolean;
/**
* switch
* - default is `true`
*/
switchRoute?: boolean;
/**
* transition animation
*/
transition?: ITransition;
/**
* loading delay
* - default is `100`ms
*/
delay?: number;
/**
* how much time delayed to start prefetch after main thread is idle
* - default is `0` ms
*/
prefetchDelay?: number;
}
declare module 'react-routers' {
/**
* `react-routers`, see document or demo in:
* - <https://github.com/Bert0324/react-routers>
*/
const Routers: FC<IRouterProps>;
/**
* triggered when first entering route and every time active it
*/
const useActive: ActiveHook;
/**
* triggered when leave the route
*/
const useDeactive: ActiveHook;
/**
* `useRouteMatch` like <https://reactrouter.com/web/api/Hooks/useroutematch>
*/
const useRouteMatch: <T = {}>() => match<T>;
/**
* `useParams` like <https://reactrouter.com/core/api/Hooks/useparams>
*/
const useParams: <T = {}>() => T;
/**
* get current configuration
*/
const useRefContext: () => IRefObj | null;
const Fade: ITransition;
const LeftFade: ITransition;
const RightFade: ITransition;
const TopFade: ITransition;
const BottomFade: ITransition;
const LeftSlide: ITransition;
const RightSlide: ITransition;
const TopSlide: ITransition;
const BottomSlide: ITransition;
export {
Routers,
useActive,
useDeactive,
useParams,
useRouteMatch,
useRefContext,
Fade,
LeftFade,
RightFade,
TopFade,
BottomFade,
LeftSlide,
RightSlide,
TopSlide,
BottomSlide
};
}