@kitbag/router 0.7.2 → 0.8.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 +78 -25
- package/dist/kitbag-router.js +952 -886
- package/dist/kitbag-router.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/kitbag-router.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
|
18
18
|
|
|
19
19
|
declare type __VLS_NonUndefinedable_2<T> = T extends undefined ? never : T;
|
|
20
20
|
|
|
21
|
+
declare type __VLS_Prettify<T> = {
|
|
22
|
+
[K in keyof T]: T[K];
|
|
23
|
+
} & {};
|
|
24
|
+
|
|
21
25
|
declare type __VLS_TypePropsToRuntimeProps<T> = {
|
|
22
26
|
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
23
27
|
type: PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
@@ -36,6 +40,12 @@ declare type __VLS_TypePropsToRuntimeProps_2<T> = {
|
|
|
36
40
|
};
|
|
37
41
|
};
|
|
38
42
|
|
|
43
|
+
declare type __VLS_WithDefaults<P, D> = {
|
|
44
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
45
|
+
default: D[K];
|
|
46
|
+
}> : P[K];
|
|
47
|
+
};
|
|
48
|
+
|
|
39
49
|
declare type __VLS_WithTemplateSlots<T, S> = T & {
|
|
40
50
|
new (): {
|
|
41
51
|
$slots: S;
|
|
@@ -208,6 +218,10 @@ export declare type CreateRouteOptions<TName extends string | undefined = string
|
|
|
208
218
|
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
209
219
|
*/
|
|
210
220
|
meta?: TMeta;
|
|
221
|
+
/**
|
|
222
|
+
* Determines what assets are prefetched when router-link is rendered for this route. Overrides router level prefetch.
|
|
223
|
+
*/
|
|
224
|
+
prefetch?: PrefetchConfig;
|
|
211
225
|
};
|
|
212
226
|
|
|
213
227
|
/**
|
|
@@ -240,9 +254,9 @@ declare type CreateRouteOptionsMatched = CreateRouteOptions & WithHooks & (WithH
|
|
|
240
254
|
* const router = createRouter(routes)
|
|
241
255
|
* ```
|
|
242
256
|
*/
|
|
243
|
-
export declare function createRouter<const
|
|
257
|
+
export declare function createRouter<const TRoutes extends Routes, const TOptions extends RouterOptions>(routes: TRoutes, options?: TOptions): Router<TRoutes, TOptions>;
|
|
244
258
|
|
|
245
|
-
export declare function createRouter<const
|
|
259
|
+
export declare function createRouter<const TRoutes extends Routes, const TOptions extends RouterOptions>(arrayOfRoutes: TRoutes[], options?: TOptions): Router<TRoutes, TOptions>;
|
|
246
260
|
|
|
247
261
|
/**
|
|
248
262
|
* An error thrown when duplicate parameters are detected in a route.
|
|
@@ -515,6 +529,19 @@ declare type PathParamsWithParamNameExtracted<TPath extends string> = {
|
|
|
515
529
|
[K in keyof ExtractParamsFromPathString<TPath> as ExtractParamName<K>]?: Param;
|
|
516
530
|
};
|
|
517
531
|
|
|
532
|
+
/**
|
|
533
|
+
* Determines what assets are prefetched. A boolean enables or disables all prefetching.
|
|
534
|
+
*/
|
|
535
|
+
declare type PrefetchConfig = boolean | PrefetchConfigOptions;
|
|
536
|
+
|
|
537
|
+
declare type PrefetchConfigOptions = {
|
|
538
|
+
/**
|
|
539
|
+
* When true any component that is wrapped in vue's defineAsyncComponent will be prefetched
|
|
540
|
+
* @default true
|
|
541
|
+
*/
|
|
542
|
+
components?: boolean;
|
|
543
|
+
};
|
|
544
|
+
|
|
518
545
|
declare type Query<TQuery extends string = string, TQueryParams extends QueryParamsWithParamNameExtracted<TQuery> = Record<string, Param | undefined>> = {
|
|
519
546
|
query: TQuery;
|
|
520
547
|
params: string extends TQuery ? Record<string, Param> : Identity<ExtractQueryParamsFromQueryString<TQuery, TQueryParams>>;
|
|
@@ -549,7 +576,7 @@ declare type QueryParamsWithParamNameExtracted<T extends string> = {
|
|
|
549
576
|
};
|
|
550
577
|
|
|
551
578
|
/**
|
|
552
|
-
* Represents the state of currently registered router,
|
|
579
|
+
* Represents the state of currently registered router, and route meta. Used to provide correct type context for
|
|
553
580
|
* components like `RouterLink`, as well as for composables like `useRouter`, `useRoute`, and hooks.
|
|
554
581
|
*
|
|
555
582
|
* @example
|
|
@@ -557,7 +584,6 @@ declare type QueryParamsWithParamNameExtracted<T extends string> = {
|
|
|
557
584
|
* declare module '@kitbag/router' {
|
|
558
585
|
* interface Register {
|
|
559
586
|
* router: typeof router
|
|
560
|
-
* rejections: ["NotAuthorized"],
|
|
561
587
|
* routeMeta: { public?: boolean }
|
|
562
588
|
* }
|
|
563
589
|
* }
|
|
@@ -570,8 +596,8 @@ export declare interface Register {
|
|
|
570
596
|
* Represents the possible Rejections registered within {@link Register}
|
|
571
597
|
*/
|
|
572
598
|
export declare type RegisteredRejectionType = Register extends {
|
|
573
|
-
|
|
574
|
-
} ?
|
|
599
|
+
router: Router<Routes, infer TOptions extends RouterOptions>;
|
|
600
|
+
} ? keyof TOptions['rejections'] | BuiltInRejectionType : BuiltInRejectionType;
|
|
575
601
|
|
|
576
602
|
/**
|
|
577
603
|
* Represents the a map of all possible route names with corresponding Route registered within {@link Register}
|
|
@@ -695,7 +721,11 @@ export declare type Route<TName extends string = string, THost extends Host = Ho
|
|
|
695
721
|
* Represents the schema of the route state, combined with any parents.
|
|
696
722
|
*/
|
|
697
723
|
state: TState;
|
|
698
|
-
|
|
724
|
+
/**
|
|
725
|
+
* Determines what assets are prefetched when router-link is rendered for this route. Overrides router level prefetch.
|
|
726
|
+
*/
|
|
727
|
+
prefetch?: PrefetchConfig;
|
|
728
|
+
/* Excluded from this release type: depth */
|
|
699
729
|
};
|
|
700
730
|
|
|
701
731
|
declare type RouteGetByKey<TRoutes extends Routes, TKey extends RoutesName<TRoutes>> = RoutesMap<TRoutes>[TKey];
|
|
@@ -746,7 +776,7 @@ declare type RouteHookPushResponse<T extends Routes> = {
|
|
|
746
776
|
*/
|
|
747
777
|
declare type RouteHookRejectResponse = {
|
|
748
778
|
status: 'REJECT';
|
|
749
|
-
type:
|
|
779
|
+
type: RegisteredRejectionType;
|
|
750
780
|
};
|
|
751
781
|
|
|
752
782
|
/**
|
|
@@ -778,7 +808,7 @@ declare type RouteParams<TPath extends string | Path | undefined, TQuery extends
|
|
|
778
808
|
|
|
779
809
|
declare type RouteParamsByKey<TRoutes extends Routes, TKey extends string> = ExtractRouteParamTypesWithoutLosingOptional<RouteGetByKey<TRoutes, TKey>>;
|
|
780
810
|
|
|
781
|
-
export declare type Router<TRoutes extends Routes = any> = Plugin_2 & {
|
|
811
|
+
export declare type Router<TRoutes extends Routes = any, __TOptions extends RouterOptions = any> = Plugin_2 & {
|
|
782
812
|
/**
|
|
783
813
|
* Manages the current route state.
|
|
784
814
|
*/
|
|
@@ -851,6 +881,10 @@ export declare type Router<TRoutes extends Routes = any> = Plugin_2 & {
|
|
|
851
881
|
* Given a URL, returns true if host does not match host stored on router instance
|
|
852
882
|
*/
|
|
853
883
|
isExternal: (url: string) => boolean;
|
|
884
|
+
/**
|
|
885
|
+
* Determines what assets are prefetched.
|
|
886
|
+
*/
|
|
887
|
+
prefetch?: PrefetchConfig;
|
|
854
888
|
};
|
|
855
889
|
|
|
856
890
|
declare type RouterFind<TRoutes extends Routes> = {
|
|
@@ -864,11 +898,13 @@ declare type RouterHistoryMode = 'auto' | 'browser' | 'memory' | 'hash';
|
|
|
864
898
|
|
|
865
899
|
export declare const routerInjectionKey: InjectionKey<RegisteredRouter>;
|
|
866
900
|
|
|
867
|
-
export declare const RouterLink: __VLS_WithTemplateSlots_2<DefineComponent<__VLS_TypePropsToRuntimeProps_2<{
|
|
868
|
-
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
}
|
|
901
|
+
export declare const RouterLink: __VLS_WithTemplateSlots_2<DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps_2<RouterLinkProps & RouterPushOptions>, {
|
|
902
|
+
prefetch: undefined;
|
|
903
|
+
}>, {}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps_2<RouterLinkProps & RouterPushOptions>, {
|
|
904
|
+
prefetch: undefined;
|
|
905
|
+
}>>>, {
|
|
906
|
+
prefetch: PrefetchConfig;
|
|
907
|
+
}, {}>, Readonly<{
|
|
872
908
|
default?: ((props: {
|
|
873
909
|
resolved: string;
|
|
874
910
|
isMatch: boolean;
|
|
@@ -884,6 +920,17 @@ to: Url | ToCallback;
|
|
|
884
920
|
}) => unknown) | undefined;
|
|
885
921
|
}>;
|
|
886
922
|
|
|
923
|
+
declare type RouterLinkProps = {
|
|
924
|
+
/**
|
|
925
|
+
* The url string to navigate to or a callback that returns a url string
|
|
926
|
+
*/
|
|
927
|
+
to: Url | ToCallback;
|
|
928
|
+
/**
|
|
929
|
+
* Determines what assets are prefetched when router-link is rendered for this route. Overrides route level prefetch.
|
|
930
|
+
*/
|
|
931
|
+
prefetch?: PrefetchConfig;
|
|
932
|
+
};
|
|
933
|
+
|
|
887
934
|
/**
|
|
888
935
|
* An error thrown when an attempt is made to use routing functionality before the router has been installed.
|
|
889
936
|
*/
|
|
@@ -912,7 +959,15 @@ export declare type RouterOptions = {
|
|
|
912
959
|
* For example having `base` of `/foo` would assume all routes should start with `your.domain.com/foo`.
|
|
913
960
|
*/
|
|
914
961
|
base?: string;
|
|
915
|
-
|
|
962
|
+
/**
|
|
963
|
+
* Determines what assets are prefetched when router-link is rendered for a specific route
|
|
964
|
+
*/
|
|
965
|
+
prefetch?: PrefetchConfig;
|
|
966
|
+
/**
|
|
967
|
+
* Components assigned to each type of rejection your router supports.
|
|
968
|
+
*/
|
|
969
|
+
rejections?: Partial<Record<string, Component>>;
|
|
970
|
+
};
|
|
916
971
|
|
|
917
972
|
declare type RouterPush<TRoutes extends Routes = any> = {
|
|
918
973
|
<TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterPushArgs<TRoutes, TSource>): Promise<void>;
|
|
@@ -927,21 +982,15 @@ declare type RouterPushOptions<TState = unknown> = {
|
|
|
927
982
|
state?: Partial<TState>;
|
|
928
983
|
};
|
|
929
984
|
|
|
930
|
-
export declare type RouterReject = (type:
|
|
985
|
+
export declare type RouterReject = (type: RegisteredRejectionType) => void;
|
|
931
986
|
|
|
932
987
|
declare type RouterRejection = Ref<null | {
|
|
933
|
-
type:
|
|
988
|
+
type: RegisteredRejectionType;
|
|
934
989
|
component: Component;
|
|
935
990
|
}>;
|
|
936
991
|
|
|
937
|
-
declare type RouterRejectionComponents = {
|
|
938
|
-
rejections?: Partial<Record<RouterRejectionType, Component>>;
|
|
939
|
-
};
|
|
940
|
-
|
|
941
992
|
export declare const routerRejectionKey: InjectionKey<RouterRejection>;
|
|
942
993
|
|
|
943
|
-
declare type RouterRejectionType = BuiltInRejectionType | RegisteredRejectionType;
|
|
944
|
-
|
|
945
994
|
declare type RouterReplace<TRoutes extends Routes> = {
|
|
946
995
|
<TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterReplaceArgs<TRoutes, TSource>): Promise<void>;
|
|
947
996
|
(url: Url, options?: RouterReplaceOptions): Promise<void>;
|
|
@@ -1133,9 +1182,13 @@ export declare type UseLink = {
|
|
|
1133
1182
|
*/
|
|
1134
1183
|
export declare function useLink<TRouteKey extends RegisteredRoutesName>(name: MaybeRefOrGetter<TRouteKey>, ...args: UseLinkArgs<TRouteKey>): UseLink;
|
|
1135
1184
|
|
|
1136
|
-
export declare function useLink(url: MaybeRefOrGetter<Url>): UseLink;
|
|
1185
|
+
export declare function useLink(url: MaybeRefOrGetter<Url>, options?: MaybeRefOrGetter<UseLinkOptions>): UseLink;
|
|
1137
1186
|
|
|
1138
|
-
declare type UseLinkArgs<TSource extends RegisteredRoutesName, TParams = RouteParamsByKey<RegisteredRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: MaybeRefOrGetter<TParams>, options?: MaybeRefOrGetter<
|
|
1187
|
+
declare type UseLinkArgs<TSource extends RegisteredRoutesName, TParams = RouteParamsByKey<RegisteredRoutes, TSource>> = AllPropertiesAreOptional<TParams> extends true ? [params?: MaybeRefOrGetter<TParams>, options?: MaybeRefOrGetter<UseLinkOptions>] : [params: MaybeRefOrGetter<TParams>, options?: MaybeRefOrGetter<UseLinkOptions>];
|
|
1188
|
+
|
|
1189
|
+
export declare type UseLinkOptions = RouterResolveOptions & {
|
|
1190
|
+
prefetch?: PrefetchConfig;
|
|
1191
|
+
};
|
|
1139
1192
|
|
|
1140
1193
|
/**
|
|
1141
1194
|
* A composition to access the router's rejection state.
|