mikuru 1.0.14 → 1.0.16
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/CHANGELOG.md +38 -1
- package/README.md +38 -7
- package/dist/compiler/analyzeTemplate.js +0 -3
- package/dist/compiler/analyzeTemplate.js.map +1 -1
- package/dist/compiler/generate.js +972 -73
- package/dist/compiler/generate.js.map +1 -1
- package/dist/router/index.d.ts +168 -7
- package/dist/router/index.js +610 -66
- package/dist/router/index.js.map +1 -1
- package/dist/runtime/dom.d.ts +4 -0
- package/dist/runtime/dom.js +39 -0
- package/dist/runtime/dom.js.map +1 -1
- package/dist/runtime/index.d.ts +2 -2
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/index.js.map +1 -1
- package/package.json +26 -26
package/dist/router/index.d.ts
CHANGED
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
import type { Ref } from "../runtime/index.js";
|
|
2
|
-
export type RouteParams = Record<string, string>;
|
|
3
|
-
export type
|
|
2
|
+
export type RouteParams = Record<string, string | string[]>;
|
|
3
|
+
export type RouteParamsRaw = Record<string, string | number | boolean | Array<string | number | boolean>>;
|
|
4
|
+
export type RouteQueryValue = string | string[] | undefined;
|
|
5
|
+
export type RouteQuery = Record<string, RouteQueryValue>;
|
|
4
6
|
export type RouteComponent = {
|
|
5
7
|
mount(target: Element | DocumentFragment, props?: Record<string, unknown>): {
|
|
6
8
|
element: Element | Comment;
|
|
7
9
|
unmount(): void;
|
|
8
10
|
};
|
|
9
11
|
};
|
|
12
|
+
export type LazyRouteComponent = () => Promise<RouteComponent | {
|
|
13
|
+
default: RouteComponent;
|
|
14
|
+
}>;
|
|
15
|
+
export type RoutePropsOption = boolean | Record<string, unknown> | ((route: RouteLocation) => Record<string, unknown> | undefined);
|
|
16
|
+
export type RouteRecordInput = Omit<RouteRecord, "children" | "__mikuru_resolvedComponent"> & {
|
|
17
|
+
children?: readonly RouteRecordInput[];
|
|
18
|
+
};
|
|
10
19
|
export type RouteRecord = {
|
|
11
20
|
path: string;
|
|
12
21
|
name?: string;
|
|
13
|
-
component?: RouteComponent;
|
|
22
|
+
component?: RouteComponent | LazyRouteComponent;
|
|
23
|
+
loadingComponent?: RouteComponent;
|
|
24
|
+
errorComponent?: RouteComponent;
|
|
25
|
+
redirect?: RouteLocationRaw | ((to: RouteLocation) => RouteLocationRaw);
|
|
26
|
+
alias?: string | string[];
|
|
14
27
|
meta?: Record<string, unknown>;
|
|
28
|
+
beforeEnter?: NavigationGuard | NavigationGuard[];
|
|
29
|
+
props?: RoutePropsOption;
|
|
30
|
+
children?: RouteRecord[];
|
|
31
|
+
__mikuru_resolvedComponent?: RouteComponent;
|
|
32
|
+
};
|
|
33
|
+
export type QueryCodec = {
|
|
34
|
+
parseQuery?(query: string): RouteQuery;
|
|
35
|
+
stringifyQuery?(query: RouteQuery): string;
|
|
15
36
|
};
|
|
16
37
|
export type RouteLocation = {
|
|
17
38
|
path: string;
|
|
@@ -20,6 +41,7 @@ export type RouteLocation = {
|
|
|
20
41
|
hash: string;
|
|
21
42
|
params: RouteParams;
|
|
22
43
|
matched?: RouteRecord;
|
|
44
|
+
matchedRecords: RouteRecord[];
|
|
23
45
|
name?: string;
|
|
24
46
|
meta: Record<string, unknown>;
|
|
25
47
|
};
|
|
@@ -27,10 +49,34 @@ export type RouteLocationRaw = string | {
|
|
|
27
49
|
path: string;
|
|
28
50
|
query?: RouteQuery;
|
|
29
51
|
hash?: string;
|
|
52
|
+
} | {
|
|
53
|
+
name: string;
|
|
54
|
+
params?: RouteParamsRaw;
|
|
55
|
+
query?: RouteQuery;
|
|
56
|
+
hash?: string;
|
|
30
57
|
};
|
|
31
58
|
export type NavigationGuardResult = void | boolean | string | RouteLocationRaw;
|
|
32
59
|
export type NavigationGuard = (to: RouteLocation, from: RouteLocation) => NavigationGuardResult | Promise<NavigationGuardResult>;
|
|
33
|
-
export
|
|
60
|
+
export declare const NavigationFailureType: {
|
|
61
|
+
readonly aborted: "aborted";
|
|
62
|
+
readonly cancelled: "cancelled";
|
|
63
|
+
readonly duplicated: "duplicated";
|
|
64
|
+
};
|
|
65
|
+
export type NavigationFailureType = (typeof NavigationFailureType)[keyof typeof NavigationFailureType];
|
|
66
|
+
export type NavigationFailure = {
|
|
67
|
+
type: NavigationFailureType;
|
|
68
|
+
to: RouteLocation;
|
|
69
|
+
from: RouteLocation;
|
|
70
|
+
message: string;
|
|
71
|
+
};
|
|
72
|
+
export type NavigationResult = RouteLocation | NavigationFailure;
|
|
73
|
+
export type AfterNavigationHook = (to: RouteLocation, from: RouteLocation, failure?: NavigationFailure) => void;
|
|
74
|
+
export type RouterErrorHandler = (error: unknown, to: RouteLocation, from?: RouteLocation) => void;
|
|
75
|
+
export type ScrollPosition = ScrollToOptions;
|
|
76
|
+
export type ScrollBehavior = (to: RouteLocation, from: RouteLocation) => ScrollPosition | false | void | Promise<ScrollPosition | false | void>;
|
|
77
|
+
export type ScrollMeta = {
|
|
78
|
+
scroll?: ScrollPosition | false | ((to: RouteLocation, from: RouteLocation) => ScrollPosition | false | void | Promise<ScrollPosition | false | void>);
|
|
79
|
+
};
|
|
34
80
|
export type RouterHistory = {
|
|
35
81
|
mode: "hash" | "history" | "memory";
|
|
36
82
|
location(): string;
|
|
@@ -43,25 +89,140 @@ export type RouterHistory = {
|
|
|
43
89
|
};
|
|
44
90
|
export type RouterOptions = {
|
|
45
91
|
history?: RouterHistory;
|
|
46
|
-
routes: RouteRecord[];
|
|
92
|
+
routes: readonly RouteRecord[];
|
|
47
93
|
notFound?: RouteComponent;
|
|
94
|
+
scrollBehavior?: ScrollBehavior;
|
|
95
|
+
parseQuery?: QueryCodec["parseQuery"];
|
|
96
|
+
stringifyQuery?: QueryCodec["stringifyQuery"];
|
|
97
|
+
loadingComponent?: RouteComponent;
|
|
98
|
+
errorComponent?: RouteComponent;
|
|
48
99
|
};
|
|
49
100
|
export type Router = {
|
|
50
101
|
currentRoute: Ref<RouteLocation>;
|
|
51
102
|
routes: RouteRecord[];
|
|
52
|
-
push(to: RouteLocationRaw): Promise<
|
|
53
|
-
replace(to: RouteLocationRaw): Promise<
|
|
103
|
+
push(to: RouteLocationRaw): Promise<NavigationResult>;
|
|
104
|
+
replace(to: RouteLocationRaw): Promise<NavigationResult>;
|
|
54
105
|
back(): void;
|
|
55
106
|
forward(): void;
|
|
56
107
|
resolve(to: RouteLocationRaw): RouteLocation;
|
|
108
|
+
preload(to: RouteLocationRaw): Promise<RouteLocation>;
|
|
109
|
+
isReady(): Promise<void>;
|
|
57
110
|
beforeEach(guard: NavigationGuard): () => void;
|
|
58
111
|
afterEach(hook: AfterNavigationHook): () => void;
|
|
112
|
+
onError(handler: RouterErrorHandler): () => void;
|
|
113
|
+
addRoute(record: RouteRecord): () => void;
|
|
114
|
+
addRoute(parentName: string, record: RouteRecord): () => void;
|
|
115
|
+
removeRoute(name: string): boolean;
|
|
116
|
+
hasRoute(name: string): boolean;
|
|
59
117
|
listen(): () => void;
|
|
60
118
|
createHref(to: RouteLocationRaw): string;
|
|
119
|
+
loadingComponent?: RouteComponent;
|
|
120
|
+
errorComponent?: RouteComponent;
|
|
121
|
+
};
|
|
122
|
+
type RouteRecordTree = {
|
|
123
|
+
path: string;
|
|
124
|
+
name?: string;
|
|
125
|
+
children?: readonly RouteRecordTree[];
|
|
126
|
+
};
|
|
127
|
+
type JoinRouteLiteral<Parent extends string, Path extends string> = Path extends `/${string}` ? Path : Parent extends "" | "/" ? Path extends "" ? "/" : `/${Path}` : Path extends "" ? Parent : `${Parent}/${Path}`;
|
|
128
|
+
type RouteEntries<Routes extends readonly RouteRecordTree[], Parent extends string = ""> = Routes[number] extends infer Record ? Record extends RouteRecordTree ? (Record extends {
|
|
129
|
+
name: infer Name extends string;
|
|
130
|
+
} ? {
|
|
131
|
+
name: Name;
|
|
132
|
+
path: JoinRouteLiteral<Parent, Record["path"]>;
|
|
133
|
+
} : never) | (Record extends {
|
|
134
|
+
children: infer Children extends readonly RouteRecordTree[];
|
|
135
|
+
} ? RouteEntries<Children, JoinRouteLiteral<Parent, Record["path"]>> : never) : never : never;
|
|
136
|
+
type RoutePathByName<Routes extends readonly RouteRecordTree[], Name extends string> = Extract<RouteEntries<Routes>, {
|
|
137
|
+
name: Name;
|
|
138
|
+
}> extends {
|
|
139
|
+
path: infer Path extends string;
|
|
140
|
+
} ? Path : never;
|
|
141
|
+
type RouteParamInfo<Segment extends string> = Segment extends `:${infer Name}(${string})*` ? {
|
|
142
|
+
name: Name;
|
|
143
|
+
optional: true;
|
|
144
|
+
repeat: true;
|
|
145
|
+
} : Segment extends `:${infer Name}(${string})+` ? {
|
|
146
|
+
name: Name;
|
|
147
|
+
optional: false;
|
|
148
|
+
repeat: true;
|
|
149
|
+
} : Segment extends `:${infer Name}(${string})?` ? {
|
|
150
|
+
name: Name;
|
|
151
|
+
optional: true;
|
|
152
|
+
repeat: false;
|
|
153
|
+
} : Segment extends `:${infer Name}(${string})` ? {
|
|
154
|
+
name: Name;
|
|
155
|
+
optional: false;
|
|
156
|
+
repeat: false;
|
|
157
|
+
} : Segment extends `:${infer Name}?` ? {
|
|
158
|
+
name: Name;
|
|
159
|
+
optional: true;
|
|
160
|
+
repeat: false;
|
|
161
|
+
} : Segment extends `:${infer Name}+` ? {
|
|
162
|
+
name: Name;
|
|
163
|
+
optional: false;
|
|
164
|
+
repeat: true;
|
|
165
|
+
} : Segment extends `:${infer Name}*` ? {
|
|
166
|
+
name: Name;
|
|
167
|
+
optional: true;
|
|
168
|
+
repeat: true;
|
|
169
|
+
} : Segment extends `:${infer Name}` ? {
|
|
170
|
+
name: Name;
|
|
171
|
+
optional: false;
|
|
172
|
+
repeat: false;
|
|
173
|
+
} : never;
|
|
174
|
+
type RouteParamInfosFromPath<Path extends string> = Path extends `${infer Segment}/${infer Rest}` ? RouteParamInfo<Segment> | RouteParamInfosFromPath<Rest> : RouteParamInfo<Path>;
|
|
175
|
+
type RequiredRouteParams<Path extends string> = {
|
|
176
|
+
[Param in RouteParamInfosFromPath<Path> as Param extends {
|
|
177
|
+
optional: false;
|
|
178
|
+
name: infer Name extends string;
|
|
179
|
+
} ? Name : never]: Param extends {
|
|
180
|
+
repeat: true;
|
|
181
|
+
} ? string[] : string;
|
|
182
|
+
};
|
|
183
|
+
type OptionalRouteParams<Path extends string> = {
|
|
184
|
+
[Param in RouteParamInfosFromPath<Path> as Param extends {
|
|
185
|
+
optional: true;
|
|
186
|
+
name: infer Name extends string;
|
|
187
|
+
} ? Name : never]?: Param extends {
|
|
188
|
+
repeat: true;
|
|
189
|
+
} ? string[] : string;
|
|
190
|
+
};
|
|
191
|
+
type RouteParamsForPath<Path extends string> = RequiredRouteParams<Path> & OptionalRouteParams<Path>;
|
|
192
|
+
type HasRouteParams<Path extends string> = keyof RouteParamsForPath<Path> extends never ? false : true;
|
|
193
|
+
type HasRequiredRouteParams<Path extends string> = keyof RequiredRouteParams<Path> extends never ? false : true;
|
|
194
|
+
export type RouteNames<Routes extends readonly RouteRecordTree[]> = RouteEntries<Routes> extends {
|
|
195
|
+
name: infer Name extends string;
|
|
196
|
+
} ? Name : never;
|
|
197
|
+
export type RouteParamNames<Path extends string> = RouteParamInfosFromPath<Path> extends {
|
|
198
|
+
name: infer Name extends string;
|
|
199
|
+
} ? Name : never;
|
|
200
|
+
export type RouteLocationForName<Routes extends readonly RouteRecordTree[], Name extends RouteNames<Routes>> = HasRouteParams<RoutePathByName<Routes, Name>> extends false ? {
|
|
201
|
+
name: Name;
|
|
202
|
+
query?: RouteQuery;
|
|
203
|
+
hash?: string;
|
|
204
|
+
} : HasRequiredRouteParams<RoutePathByName<Routes, Name>> extends true ? {
|
|
205
|
+
name: Name;
|
|
206
|
+
params: RouteParamsForPath<RoutePathByName<Routes, Name>>;
|
|
207
|
+
query?: RouteQuery;
|
|
208
|
+
hash?: string;
|
|
209
|
+
} : {
|
|
210
|
+
name: Name;
|
|
211
|
+
params?: RouteParamsForPath<RoutePathByName<Routes, Name>>;
|
|
212
|
+
query?: RouteQuery;
|
|
213
|
+
hash?: string;
|
|
61
214
|
};
|
|
215
|
+
export declare function defineRoutes<const Routes extends readonly RouteRecordInput[]>(routes: Routes): Routes;
|
|
216
|
+
export declare function provideRouter(router: Router): void;
|
|
217
|
+
export declare function useRouter(): Router;
|
|
218
|
+
export declare function useRoute(): RouteLocation;
|
|
219
|
+
export declare function isNavigationFailure(value: unknown, type?: NavigationFailureType): value is NavigationFailure;
|
|
62
220
|
export declare function createRouter(options: RouterOptions): Router;
|
|
63
221
|
export declare function createWebHistory(base?: string): RouterHistory;
|
|
64
222
|
export declare function createWebHashHistory(base?: string): RouterHistory;
|
|
65
223
|
export declare function createMemoryHistory(initial?: string): RouterHistory;
|
|
66
224
|
export declare const RouterView: RouteComponent;
|
|
67
225
|
export declare const RouterLink: RouteComponent;
|
|
226
|
+
export declare function parseRouteQuery(raw: string): RouteQuery;
|
|
227
|
+
export declare function stringifyRouteQuery(query: RouteQuery): string;
|
|
228
|
+
export {};
|