@kitbag/router 0.10.1 → 0.11.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.
@@ -1,6 +1,7 @@
1
1
  import { AsyncComponentLoader } from 'vue';
2
2
  import { Component } from 'vue';
3
3
  import { ComponentOptionsMixin } from 'vue';
4
+ import { ComputedRef } from 'vue';
4
5
  import { DefineComponent } from 'vue';
5
6
  import { ExtractPropTypes } from 'vue';
6
7
  import { FunctionalComponent } from 'vue';
@@ -238,6 +239,7 @@ export declare type CreateRouteOptions<TName extends string | undefined = string
238
239
  * The Route properties originally provided to `createRoute`. The only change is normalizing meta to always default to an empty object.
239
240
  */
240
241
  declare type CreateRouteOptionsMatched = CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithComponent | WithComponents | WithoutComponents) & (WithParent | WithoutParent) & (WithState | WithoutState) & {
242
+ id: string;
241
243
  meta: RouteMeta;
242
244
  };
243
245
 
@@ -288,13 +290,9 @@ export declare class DuplicateParamsError extends Error {
288
290
  */
289
291
  declare type ExtractParamName<TParam extends PropertyKey> = TParam extends `?${infer Param}` ? Param extends '' ? never : Param : TParam extends '' ? never : TParam;
290
292
 
291
- declare type ExtractParamsFromHostString<THost extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = THost extends `${string}${ParamStart}${infer Param}${ParamEnd}${infer Rest}` ? {
292
- [P in Param]: ExtractPathParamType<Param, TParams>;
293
- } & ExtractParamsFromHostString<Rest, TParams> : Record<never, never>;
293
+ declare type ExtractParamsFromHostString<THost extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = THost extends `${string}${ParamStart}${infer Param}${ParamEnd}${infer Rest}` ? Record<Param, ExtractPathParamType<Param, TParams>> & ExtractParamsFromHostString<Rest, TParams> : Record<never, never>;
294
294
 
295
- declare type ExtractParamsFromPathString<TPath extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TPath extends `${string}${ParamStart}${infer Param}${ParamEnd}${infer Rest}` ? {
296
- [P in Param]: ExtractPathParamType<Param, TParams>;
297
- } & ExtractParamsFromPathString<Rest, TParams> : Record<never, never>;
295
+ declare type ExtractParamsFromPathString<TPath extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TPath extends `${string}${ParamStart}${infer Param}${ParamEnd}${infer Rest}` ? Record<Param, ExtractPathParamType<Param, TParams>> & ExtractParamsFromPathString<Rest, TParams> : Record<never, never>;
298
296
 
299
297
  /**
300
298
  * Extracts the actual type from a parameter type, handling getters, setters, and potential undefined values.
@@ -327,9 +325,7 @@ declare type ExtractParamTypeWithoutLosingOptional<TParam extends Param, TParamK
327
325
  */
328
326
  declare type ExtractPathParamType<TParam extends string, TParams extends Record<string, Param | undefined>> = TParam extends `?${infer OptionalParam}` ? OptionalParam extends keyof TParams ? TParams[OptionalParam] : StringConstructor : TParam extends keyof TParams ? TParams[TParam] : StringConstructor;
329
327
 
330
- declare type ExtractQueryParamsFromQueryString<TQuery extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TQuery extends `${string}=${ParamStart}${infer Param}${ParamEnd}${infer Rest}` ? {
331
- [P in Param]: ExtractPathParamType<Param, TParams>;
332
- } & ExtractQueryParamsFromQueryString<Rest, TParams> : Record<never, never>;
328
+ declare type ExtractQueryParamsFromQueryString<TQuery extends string, TParams extends Record<string, Param | undefined> = Record<never, never>> = TQuery extends `${string}=${ParamStart}${infer Param}${ParamEnd}${infer Rest}` ? Record<Param, ExtractPathParamType<Param, TParams>> & ExtractQueryParamsFromQueryString<Rest, TParams> : Record<never, never>;
333
329
 
334
330
  /**
335
331
  * Extracts combined types of path and query parameters for a given route, creating a unified parameter object.
@@ -423,6 +419,8 @@ declare type IsRouteOptions = {
423
419
 
424
420
  declare type IsRouteUnnamed<T extends Route> = StringHasValue<T['name']> extends true ? false : true;
425
421
 
422
+ export declare function isUrl(value: unknown): value is Url;
423
+
426
424
  declare type MakeOptional<T> = {
427
425
  [P in WithOptionalProperties<T>]?: T[P];
428
426
  } & {
@@ -556,6 +554,11 @@ declare type PrefetchConfigOptions = {
556
554
  * @default true
557
555
  */
558
556
  components?: boolean;
557
+ /**
558
+ * When true any props for routes will be prefetched
559
+ * @default false
560
+ */
561
+ props?: boolean;
559
562
  };
560
563
 
561
564
  declare type Query<TQuery extends string = string, TQueryParams extends QueryParamsWithParamNameExtracted<TQuery> = Record<string, Param | undefined>> = {
@@ -665,6 +668,10 @@ declare type RemoveLeadingQuestionMarkFromKeys<T extends Record<string, unknown>
665
668
  * @template TRoute - Underlying Route that has been resolved.
666
669
  */
667
670
  declare type ResolvedRoute<TRoute extends Route = Route> = Readonly<{
671
+ /**
672
+ * Unique identifier for the route, generated by router.
673
+ */
674
+ id: TRoute['id'];
668
675
  /**
669
676
  * The specific route properties that were matched in the current route.
670
677
  */
@@ -901,10 +908,6 @@ export declare type Router<TRoutes extends Routes = any, __TOptions extends Rout
901
908
  * Registers a hook to be called after a route is updated.
902
909
  */
903
910
  onAfterRouteUpdate: AddAfterRouteHook;
904
- /**
905
- * A promise that resolves when the router is fully initialized.
906
- */
907
- initialized: Promise<void>;
908
911
  /**
909
912
  * Given a URL, returns true if host does not match host stored on router instance
910
913
  */
@@ -913,6 +916,10 @@ export declare type Router<TRoutes extends Routes = any, __TOptions extends Rout
913
916
  * Determines what assets are prefetched.
914
917
  */
915
918
  prefetch?: PrefetchConfig;
919
+ /**
920
+ * Initializes the router based on the initial route. Automatically called when the router is installed. Calling this more than once has no effect.
921
+ */
922
+ start: () => Promise<void>;
916
923
  };
917
924
 
918
925
  declare type RouterFind<TRoutes extends Routes> = {
@@ -1046,6 +1053,7 @@ declare type RouterResolveOptions = {
1046
1053
  };
1047
1054
 
1048
1055
  declare type RouterRoute<TRoute extends ResolvedRoute = ResolvedRoute> = Readonly<{
1056
+ id: TRoute['id'];
1049
1057
  name: TRoute['name'];
1050
1058
  matched: TRoute['matched'];
1051
1059
  matches: TRoute['matches'];
@@ -1070,11 +1078,14 @@ name?: string | undefined;
1070
1078
  }>>>, {}, {}>, Readonly<{
1071
1079
  default?: ((props: {
1072
1080
  route: Readonly<{
1081
+ id: string;
1073
1082
  name: string;
1074
- matched: CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithoutComponents | WithComponent | WithComponents) & (WithoutParent | WithParent) & (WithoutState | WithState) & {
1083
+ matched: CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithComponent | WithComponents | WithoutComponents) & (WithParent | WithoutParent) & (WithState | WithoutState) & {
1084
+ id: string;
1075
1085
  meta: Record<string, unknown>;
1076
1086
  };
1077
- matches: (CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithoutComponents | WithComponent | WithComponents) & (WithoutParent | WithParent) & (WithoutState | WithState) & {
1087
+ matches: (CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithComponent | WithComponents | WithoutComponents) & (WithParent | WithoutParent) & (WithState | WithoutState) & {
1088
+ id: string;
1078
1089
  meta: Record<string, unknown>;
1079
1090
  })[];
1080
1091
  state: {
@@ -1106,11 +1117,14 @@ name?: string | undefined;
1106
1117
  }> & {
1107
1118
  default?: ((props: {
1108
1119
  route: Readonly<{
1120
+ id: string;
1109
1121
  name: string;
1110
- matched: CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithoutComponents | WithComponent | WithComponents) & (WithoutParent | WithParent) & (WithoutState | WithState) & {
1122
+ matched: CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithComponent | WithComponents | WithoutComponents) & (WithParent | WithoutParent) & (WithState | WithoutState) & {
1123
+ id: string;
1111
1124
  meta: Record<string, unknown>;
1112
1125
  };
1113
- matches: (CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithoutComponents | WithComponent | WithComponents) & (WithoutParent | WithParent) & (WithoutState | WithState) & {
1126
+ matches: (CreateRouteOptions & WithHooks & (WithHost | WithoutHost) & (WithComponent | WithComponents | WithoutComponents) & (WithParent | WithoutParent) & (WithState | WithoutState) & {
1127
+ id: string;
1114
1128
  meta: Record<string, unknown>;
1115
1129
  })[];
1116
1130
  state: {
@@ -1144,7 +1158,7 @@ name?: string | undefined;
1144
1158
  /**
1145
1159
  * Represents an immutable array of Route instances. Return value of `createRoute`, expected param for `createRouter`.
1146
1160
  */
1147
- export declare type Routes = Readonly<Route[]>;
1161
+ export declare type Routes = readonly Route[];
1148
1162
 
1149
1163
  declare type RoutesMap<TRoutes extends Routes = []> = {
1150
1164
  [K in TRoutes[number] as AsNamedRoute<K>['name']]: AsNamedRoute<K>;
@@ -1176,25 +1190,29 @@ declare type ToPath<T extends string | Path | undefined> = T extends string ? Pa
1176
1190
 
1177
1191
  declare type ToQuery<T extends string | Query | undefined> = T extends string ? Query<T, {}> : T extends undefined ? Query<'', {}> : unknown extends T ? Query<'', {}> : T;
1178
1192
 
1179
- declare type Url = `http://${string}` | `https://${string}` | `/${string}` | '/';
1193
+ export declare type Url = `http://${string}` | `https://${string}` | `/${string}` | '/';
1180
1194
 
1181
1195
  export declare type UseLink = {
1182
1196
  /**
1183
1197
  * ResolvedRoute if matched. Same value as `router.find`
1184
1198
  */
1185
- route: Ref<ResolvedRoute | undefined>;
1199
+ route: ComputedRef<ResolvedRoute | undefined>;
1186
1200
  /**
1187
1201
  * Resolved URL with params interpolated and query applied. Same value as `router.resolve`.
1188
1202
  */
1189
- href: Ref<string>;
1203
+ href: ComputedRef<string>;
1190
1204
  /**
1191
1205
  * True if route matches current URL or is ancestor of route that matches current URL
1192
1206
  */
1193
- isMatch: Ref<boolean>;
1207
+ isMatch: ComputedRef<boolean>;
1194
1208
  /**
1195
1209
  * True if route matches current URL. Route is the same as what's currently stored at `router.route`.
1196
1210
  */
1197
- isExactMatch: Ref<boolean>;
1211
+ isExactMatch: ComputedRef<boolean>;
1212
+ /**
1213
+ *
1214
+ */
1215
+ isExternal: ComputedRef<boolean>;
1198
1216
  /**
1199
1217
  * Convenience method for executing `router.push` with route context passed in.
1200
1218
  */