@kitbag/router 0.15.0 → 0.15.1
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/dist/kitbag-router.d.ts +107 -26
- package/dist/kitbag-router.js +1116 -1089
- package/dist/kitbag-router.umd.cjs +1 -1
- package/package.json +6 -6
package/dist/kitbag-router.d.ts
CHANGED
|
@@ -38,6 +38,17 @@ export declare type AddAfterRouteHook = (hook: AfterRouteHook) => RouteHookRemov
|
|
|
38
38
|
*/
|
|
39
39
|
export declare type AddBeforeRouteHook = (hook: BeforeRouteHook) => RouteHookRemove;
|
|
40
40
|
|
|
41
|
+
export declare type AddComponentAfterRouteHook = (hook: AfterRouteHookRegistration) => RouteHookRemove;
|
|
42
|
+
|
|
43
|
+
export declare type AddComponentBeforeRouteHook = (hook: BeforeRouteHookRegistration) => RouteHookRemove;
|
|
44
|
+
|
|
45
|
+
export declare type AddGlobalRouteHooks = (hooks: RouteHooks) => void;
|
|
46
|
+
|
|
47
|
+
export declare type AfterHookContext = {
|
|
48
|
+
to: ResolvedRoute;
|
|
49
|
+
from: ResolvedRoute | null;
|
|
50
|
+
};
|
|
51
|
+
|
|
41
52
|
/**
|
|
42
53
|
* Represents a function called after a route change has occurred.
|
|
43
54
|
* @param to - {@link ResolvedRoute} The resolved route the router has navigated to.
|
|
@@ -56,6 +67,12 @@ export declare type AfterRouteHookContext = RouteHookContext;
|
|
|
56
67
|
*/
|
|
57
68
|
export declare type AfterRouteHookLifecycle = 'onAfterRouteEnter' | 'onAfterRouteUpdate' | 'onAfterRouteLeave';
|
|
58
69
|
|
|
70
|
+
export declare type AfterRouteHookRegistration = {
|
|
71
|
+
lifecycle: 'onAfterRouteEnter' | 'onAfterRouteUpdate' | 'onAfterRouteLeave';
|
|
72
|
+
hook: AfterRouteHook;
|
|
73
|
+
depth: number;
|
|
74
|
+
};
|
|
75
|
+
|
|
59
76
|
/**
|
|
60
77
|
* Type for responses from an after route hook, which may indicate different outcomes such as success, push, or reject.
|
|
61
78
|
* @template TRoutes - The type of the routes configuration.
|
|
@@ -66,6 +83,13 @@ declare type AllPropertiesAreOptional<T> = Record<string, unknown> extends T ? t
|
|
|
66
83
|
|
|
67
84
|
declare type AsNamedRoute<T extends Route> = IsRouteUnnamed<T> extends true ? never : T;
|
|
68
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Converts a type to a string if it is a string, otherwise returns never.
|
|
88
|
+
* Specifically useful when using keyof T to produce a union of strings
|
|
89
|
+
* rather than string | number | symbol.
|
|
90
|
+
*/
|
|
91
|
+
declare type AsString<T> = T extends string ? T : never;
|
|
92
|
+
|
|
69
93
|
/**
|
|
70
94
|
* Converts a string to a valid URL.
|
|
71
95
|
* @param value - The string to convert.
|
|
@@ -73,6 +97,11 @@ declare type AsNamedRoute<T extends Route> = IsRouteUnnamed<T> extends true ? ne
|
|
|
73
97
|
*/
|
|
74
98
|
export declare function asUrl(value: string): Url;
|
|
75
99
|
|
|
100
|
+
export declare type BeforeHookContext = {
|
|
101
|
+
to: ResolvedRoute;
|
|
102
|
+
from: ResolvedRoute | null;
|
|
103
|
+
};
|
|
104
|
+
|
|
76
105
|
/**
|
|
77
106
|
* Represents a function called before a route change, potentially altering the routing operation.
|
|
78
107
|
* @param to - {@link ResolvedRoute} The resolved route the router is navigating to.
|
|
@@ -94,15 +123,19 @@ export declare type BeforeRouteHookContext = RouteHookContext & {
|
|
|
94
123
|
*/
|
|
95
124
|
export declare type BeforeRouteHookLifecycle = 'onBeforeRouteEnter' | 'onBeforeRouteUpdate' | 'onBeforeRouteLeave';
|
|
96
125
|
|
|
126
|
+
export declare type BeforeRouteHookRegistration = {
|
|
127
|
+
lifecycle: 'onBeforeRouteEnter' | 'onBeforeRouteUpdate' | 'onBeforeRouteLeave';
|
|
128
|
+
hook: BeforeRouteHook;
|
|
129
|
+
depth: number;
|
|
130
|
+
};
|
|
131
|
+
|
|
97
132
|
/**
|
|
98
133
|
* Type for responses from a before route hook, which may indicate different outcomes such as success, push, reject, or abort.
|
|
99
134
|
* @template TRoutes - The type of the routes configuration.
|
|
100
135
|
*/
|
|
101
136
|
export declare type BeforeRouteHookResponse = CallbackSuccessResponse | CallbackPushResponse | CallbackRejectResponse | CallbackAbortResponse;
|
|
102
137
|
|
|
103
|
-
declare
|
|
104
|
-
|
|
105
|
-
declare type BuiltInRejectionType = typeof builtInRejections[number];
|
|
138
|
+
declare type BuiltInRejectionType = 'NotFound';
|
|
106
139
|
|
|
107
140
|
/**
|
|
108
141
|
* Defines the structure of an aborted callback response.
|
|
@@ -258,9 +291,11 @@ declare type CreateRouteOptionsMatched<TName extends string | undefined = string
|
|
|
258
291
|
* const router = createRouter(routes)
|
|
259
292
|
* ```
|
|
260
293
|
*/
|
|
261
|
-
export declare function createRouter<const TRoutes extends Routes, const TOptions extends RouterOptions>(routes: TRoutes, options?: TOptions): Router<TRoutes, TOptions>;
|
|
294
|
+
export declare function createRouter<const TRoutes extends Routes, const TOptions extends RouterOptions, const TPlugin extends RouterPlugin = EmptyRouterPlugin>(routes: TRoutes, options?: TOptions, plugins?: TPlugin[]): Router<TRoutes, TOptions, TPlugin>;
|
|
262
295
|
|
|
263
|
-
export declare function createRouter<const TRoutes extends Routes, const TOptions extends RouterOptions>(
|
|
296
|
+
export declare function createRouter<const TRoutes extends Routes, const TOptions extends RouterOptions, const TPlugin extends RouterPlugin = EmptyRouterPlugin>(routes: TRoutes[], options?: TOptions, plugins?: TPlugin[]): Router<TRoutes, TOptions, TPlugin>;
|
|
297
|
+
|
|
298
|
+
export declare function createRouterPlugin<TRoutes extends Routes = [], TRejections extends Record<string, Component> = {}>(plugin: Partial<RouterPlugin<TRoutes, TRejections>>): RouterPlugin<TRoutes, TRejections>;
|
|
264
299
|
|
|
265
300
|
/**
|
|
266
301
|
* An error thrown when duplicate parameters are detected in a route.
|
|
@@ -276,6 +311,11 @@ export declare class DuplicateParamsError extends Error {
|
|
|
276
311
|
constructor(paramName: string);
|
|
277
312
|
}
|
|
278
313
|
|
|
314
|
+
declare type EmptyRouterPlugin = {
|
|
315
|
+
routes: [];
|
|
316
|
+
rejections: {};
|
|
317
|
+
};
|
|
318
|
+
|
|
279
319
|
/**
|
|
280
320
|
* Extracts the parameter name from a string, handling optional parameters denoted by a leading '?'.
|
|
281
321
|
* @template TParam - The string from which to extract the parameter name.
|
|
@@ -452,6 +492,11 @@ declare type IsRouteUnnamed<T extends Route> = StringHasValue<T['name']> extends
|
|
|
452
492
|
*/
|
|
453
493
|
export declare function isUrl(value: unknown): value is Url;
|
|
454
494
|
|
|
495
|
+
/**
|
|
496
|
+
* Extracts the keys of a union type.
|
|
497
|
+
*/
|
|
498
|
+
declare type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
499
|
+
|
|
455
500
|
declare type MakeOptional<T> = {
|
|
456
501
|
[P in WithOptionalProperties<T>]?: T[P];
|
|
457
502
|
} & {
|
|
@@ -611,7 +656,7 @@ export declare type PrefetchStrategy = 'eager' | 'lazy' | 'intent';
|
|
|
611
656
|
/**
|
|
612
657
|
* Context provided to props callback functions
|
|
613
658
|
*/
|
|
614
|
-
declare type PropsCallbackContext = {
|
|
659
|
+
export declare type PropsCallbackContext = {
|
|
615
660
|
push: CallbackContext['push'];
|
|
616
661
|
replace: CallbackContext['replace'];
|
|
617
662
|
reject: CallbackContext['reject'];
|
|
@@ -831,6 +876,10 @@ declare type RouteGetByKey<TRoutes extends Routes, TKey extends RoutesName<TRout
|
|
|
831
876
|
*/
|
|
832
877
|
export declare type RouteHook = BeforeRouteHook | AfterRouteHook;
|
|
833
878
|
|
|
879
|
+
export declare type RouteHookAfterRunner = (context: AfterHookContext) => Promise<AfterRouteHookResponse>;
|
|
880
|
+
|
|
881
|
+
export declare type RouteHookBeforeRunner = (context: BeforeHookContext) => Promise<BeforeRouteHookResponse>;
|
|
882
|
+
|
|
834
883
|
/**
|
|
835
884
|
* Context provided to route hooks, containing context of previous route and functions for triggering rejections and push/replace to another route.
|
|
836
885
|
*/
|
|
@@ -857,6 +906,17 @@ export declare type RouteHookRemove = () => void;
|
|
|
857
906
|
*/
|
|
858
907
|
export declare type RouteHookResponse = BeforeRouteHookResponse | AfterRouteHookResponse;
|
|
859
908
|
|
|
909
|
+
declare class RouteHooks {
|
|
910
|
+
onBeforeRouteEnter: Set<BeforeRouteHook>;
|
|
911
|
+
onBeforeRouteUpdate: Set<BeforeRouteHook>;
|
|
912
|
+
onBeforeRouteLeave: Set<BeforeRouteHook>;
|
|
913
|
+
onAfterRouteEnter: Set<AfterRouteHook>;
|
|
914
|
+
onAfterRouteUpdate: Set<AfterRouteHook>;
|
|
915
|
+
onAfterRouteLeave: Set<AfterRouteHook>;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
export declare type RouteHookTiming = 'global' | 'component';
|
|
919
|
+
|
|
860
920
|
/**
|
|
861
921
|
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
862
922
|
*/
|
|
@@ -866,7 +926,7 @@ export declare type RouteMeta<T = Register> = T extends {
|
|
|
866
926
|
|
|
867
927
|
declare type RouteParamsByKey<TRoutes extends Routes, TKey extends string> = ExtractRouteParamTypesWithoutLosingOptional<RouteGetByKey<TRoutes, TKey>>;
|
|
868
928
|
|
|
869
|
-
export declare type Router<TRoutes extends Routes = any,
|
|
929
|
+
export declare type Router<TRoutes extends Routes = any, TOptions extends RouterOptions = any, TPlugin extends RouterPlugin = any> = {
|
|
870
930
|
/**
|
|
871
931
|
* Installs the router into a Vue application instance.
|
|
872
932
|
* @param app The Vue application instance to install the router into
|
|
@@ -875,11 +935,11 @@ export declare type Router<TRoutes extends Routes = any, __TOptions extends Rout
|
|
|
875
935
|
/**
|
|
876
936
|
* Manages the current route state.
|
|
877
937
|
*/
|
|
878
|
-
route: RouterRoutes<TRoutes>;
|
|
938
|
+
route: RouterRoutes<TRoutes> | RouterRoutes<TPlugin['routes']>;
|
|
879
939
|
/**
|
|
880
940
|
* Creates a ResolvedRoute record for a given route name and params.
|
|
881
941
|
*/
|
|
882
|
-
resolve: RouterResolve<TRoutes>;
|
|
942
|
+
resolve: RouterResolve<TRoutes | TPlugin['routes']>;
|
|
883
943
|
/**
|
|
884
944
|
* Creates a ResolvedRoute record for a given URL.
|
|
885
945
|
*/
|
|
@@ -887,15 +947,15 @@ export declare type Router<TRoutes extends Routes = any, __TOptions extends Rout
|
|
|
887
947
|
/**
|
|
888
948
|
* Navigates to a specified path or route object in the history stack, adding a new entry.
|
|
889
949
|
*/
|
|
890
|
-
push: RouterPush<TRoutes>;
|
|
950
|
+
push: RouterPush<TRoutes | TPlugin['routes']>;
|
|
891
951
|
/**
|
|
892
952
|
* Replaces the current entry in the history stack with a new one.
|
|
893
953
|
*/
|
|
894
|
-
replace: RouterReplace<TRoutes>;
|
|
954
|
+
replace: RouterReplace<TRoutes | TPlugin['routes']>;
|
|
895
955
|
/**
|
|
896
956
|
* Handles route rejection based on a specified rejection type.
|
|
897
957
|
*/
|
|
898
|
-
reject: RouterReject
|
|
958
|
+
reject: RouterReject<keyof TOptions['rejections'] | KeysOfUnion<TPlugin['rejections']>>;
|
|
899
959
|
/**
|
|
900
960
|
* Forces the router to re-evaluate the current route.
|
|
901
961
|
*/
|
|
@@ -948,13 +1008,14 @@ export declare type Router<TRoutes extends Routes = any, __TOptions extends Rout
|
|
|
948
1008
|
* Initializes the router based on the initial route. Automatically called when the router is installed. Calling this more than once has no effect.
|
|
949
1009
|
*/
|
|
950
1010
|
start: () => Promise<void>;
|
|
1011
|
+
/**
|
|
1012
|
+
* Stops the router and teardown any listeners.
|
|
1013
|
+
*/
|
|
1014
|
+
stop: () => void;
|
|
951
1015
|
};
|
|
952
1016
|
|
|
953
1017
|
declare type RouterHistoryMode = 'auto' | 'browser' | 'memory' | 'hash';
|
|
954
1018
|
|
|
955
|
-
/**
|
|
956
|
-
* @ignore
|
|
957
|
-
*/
|
|
958
1019
|
export declare const RouterLink: __VLS_WithTemplateSlots_2<DefineComponent< {
|
|
959
1020
|
/**
|
|
960
1021
|
* The url string to navigate to or a callback that returns a url string
|
|
@@ -973,9 +1034,9 @@ to: Url | ResolvedRoute | ToCallback;
|
|
|
973
1034
|
* Determines what assets are prefetched when router-link is rendered for this route. Overrides route level prefetch.
|
|
974
1035
|
*/
|
|
975
1036
|
prefetch?: PrefetchConfig;
|
|
976
|
-
} & RouterPushOptions & {}>, {
|
|
1037
|
+
} & RouterPushOptions> & Readonly<{}>, {
|
|
977
1038
|
prefetch: PrefetchConfig;
|
|
978
|
-
}, {}, {}, {}, string, ComponentProvideOptions, false, {}>, Readonly<{
|
|
1039
|
+
}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLAnchorElement>, Readonly<{
|
|
979
1040
|
default?: (props: {
|
|
980
1041
|
route: ResolvedRoute | undefined;
|
|
981
1042
|
isMatch: boolean;
|
|
@@ -1002,7 +1063,7 @@ export declare class RouterNotInstalledError extends Error {
|
|
|
1002
1063
|
/**
|
|
1003
1064
|
* Options to initialize a {@link Router} instance.
|
|
1004
1065
|
*/
|
|
1005
|
-
export declare type RouterOptions = {
|
|
1066
|
+
export declare type RouterOptions = WithHooks & {
|
|
1006
1067
|
/**
|
|
1007
1068
|
* Initial URL for the router to use. Required if using Node environment. Defaults to window.location when using browser.
|
|
1008
1069
|
*
|
|
@@ -1030,6 +1091,17 @@ export declare type RouterOptions = {
|
|
|
1030
1091
|
rejections?: Partial<Record<string, Component>>;
|
|
1031
1092
|
};
|
|
1032
1093
|
|
|
1094
|
+
export declare type RouterPlugin<TRoutes extends Routes = Routes, TRejections extends Record<string, Component> = Record<string, Component>> = {
|
|
1095
|
+
routes: TRoutes;
|
|
1096
|
+
rejections: TRejections;
|
|
1097
|
+
onBeforeRouteEnter?: MaybeArray<BeforeRouteHook>;
|
|
1098
|
+
onAfterRouteEnter?: MaybeArray<AfterRouteHook>;
|
|
1099
|
+
onBeforeRouteUpdate?: MaybeArray<BeforeRouteHook>;
|
|
1100
|
+
onAfterRouteUpdate?: MaybeArray<AfterRouteHook>;
|
|
1101
|
+
onBeforeRouteLeave?: MaybeArray<BeforeRouteHook>;
|
|
1102
|
+
onAfterRouteLeave?: MaybeArray<AfterRouteHook>;
|
|
1103
|
+
};
|
|
1104
|
+
|
|
1033
1105
|
declare type RouterPush<TRoutes extends Routes = any> = {
|
|
1034
1106
|
<TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterPushArgs<TRoutes, TSource>): Promise<void>;
|
|
1035
1107
|
(route: ResolvedRoute, options?: RouterPushOptions): Promise<void>;
|
|
@@ -1038,17 +1110,29 @@ declare type RouterPush<TRoutes extends Routes = any> = {
|
|
|
1038
1110
|
|
|
1039
1111
|
declare type RouterPushArgs<TRoutes extends Routes, TSource extends RoutesName<TRoutes>> = AllPropertiesAreOptional<RouteParamsByKey<TRoutes, TSource>> extends true ? [params?: RouteParamsByKey<TRoutes, TSource>, options?: RouterPushOptions<RouteStateByName<TRoutes, TSource>>] : [params: RouteParamsByKey<TRoutes, TSource>, options?: RouterPushOptions<RouteStateByName<TRoutes, TSource>>];
|
|
1040
1112
|
|
|
1041
|
-
declare type RouterPushOptions<TState = unknown> = {
|
|
1113
|
+
export declare type RouterPushOptions<TState = unknown> = {
|
|
1114
|
+
/**
|
|
1115
|
+
* The query string to add to the url.
|
|
1116
|
+
*/
|
|
1042
1117
|
query?: QuerySource;
|
|
1118
|
+
/**
|
|
1119
|
+
* The hash to append to the url.
|
|
1120
|
+
*/
|
|
1043
1121
|
hash?: string;
|
|
1122
|
+
/**
|
|
1123
|
+
* Whether to replace the current history entry.
|
|
1124
|
+
*/
|
|
1044
1125
|
replace?: boolean;
|
|
1126
|
+
/**
|
|
1127
|
+
* State values to pass to the route.
|
|
1128
|
+
*/
|
|
1045
1129
|
state?: Partial<TState>;
|
|
1046
1130
|
};
|
|
1047
1131
|
|
|
1048
|
-
|
|
1132
|
+
declare type RouterReject<TRejectionType extends PropertyKey> = (type: AsString<TRejectionType> | BuiltInRejectionType) => void;
|
|
1049
1133
|
|
|
1050
1134
|
declare type RouterRejection = Ref<null | {
|
|
1051
|
-
type:
|
|
1135
|
+
type: string;
|
|
1052
1136
|
component: Component;
|
|
1053
1137
|
}>;
|
|
1054
1138
|
|
|
@@ -1097,14 +1181,11 @@ export declare type RouterRoutes<TRoutes extends Routes> = {
|
|
|
1097
1181
|
[K in keyof TRoutes]: RouterRoute<ResolvedRoute<TRoutes[K]>>;
|
|
1098
1182
|
}[number];
|
|
1099
1183
|
|
|
1100
|
-
/**
|
|
1101
|
-
* @ignore
|
|
1102
|
-
*/
|
|
1103
1184
|
export declare const RouterView: __VLS_WithTemplateSlots<DefineComponent< {
|
|
1104
1185
|
name?: string;
|
|
1105
1186
|
}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{
|
|
1106
1187
|
name?: string;
|
|
1107
|
-
} & {}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}>, Readonly<{
|
|
1188
|
+
}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>, Readonly<{
|
|
1108
1189
|
default?: (props: {
|
|
1109
1190
|
route: RouterRoute;
|
|
1110
1191
|
component: Component;
|
|
@@ -1300,7 +1381,7 @@ export declare function withDefault<TParam extends Param>(param: TParam, default
|
|
|
1300
1381
|
/**
|
|
1301
1382
|
* Defines route hooks that can be applied before entering, updating, or leaving a route, as well as after these events.
|
|
1302
1383
|
*/
|
|
1303
|
-
declare type WithHooks = {
|
|
1384
|
+
export declare type WithHooks = {
|
|
1304
1385
|
onBeforeRouteEnter?: MaybeArray<BeforeRouteHook>;
|
|
1305
1386
|
onBeforeRouteUpdate?: MaybeArray<BeforeRouteHook>;
|
|
1306
1387
|
onBeforeRouteLeave?: MaybeArray<BeforeRouteHook>;
|