@kitbag/router 0.16.0 → 0.17.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.
@@ -12,6 +12,33 @@ import { Ref } from 'vue';
12
12
  import { UnwrapRef } from 'vue';
13
13
  import { VNode } from 'vue';
14
14
 
15
+ declare const __VLS_component: DefineComponent<__VLS_Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>;
16
+
17
+ declare type __VLS_Props = {
18
+ name?: string;
19
+ };
20
+
21
+ declare function __VLS_template(): {
22
+ attrs: Partial<{}>;
23
+ slots: Readonly<{
24
+ default?: (props: {
25
+ route: RouterRoute;
26
+ component: Component;
27
+ rejection: UnwrapRef<RouterRejection>;
28
+ }) => VNode;
29
+ }> & {
30
+ default?: (props: {
31
+ route: RouterRoute;
32
+ component: Component;
33
+ rejection: UnwrapRef<RouterRejection>;
34
+ }) => VNode;
35
+ };
36
+ refs: {};
37
+ rootEl: any;
38
+ };
39
+
40
+ declare type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
41
+
15
42
  declare type __VLS_WithTemplateSlots<T, S> = T & {
16
43
  new (): {
17
44
  $slots: S;
@@ -81,6 +108,8 @@ export declare type AfterRouteHookResponse = CallbackSuccessResponse | CallbackP
81
108
 
82
109
  declare type AllPropertiesAreOptional<T> = Record<string, unknown> extends T ? true : IsEmptyObject<OnlyRequiredProperties<T>>;
83
110
 
111
+ export declare function arrayOf<const T extends Param[]>(...params: T): ParamGetSet<ExtractParamType<T[number]>[]>;
112
+
84
113
  declare type AsNamedRoute<T extends Route> = IsRouteUnnamed<T> extends true ? never : T;
85
114
 
86
115
  /**
@@ -353,7 +382,7 @@ declare type ExtractParamsFromPathString<TPath extends string, TParams extends R
353
382
  * @template TParam - The parameter type.
354
383
  * @returns The extracted type, or 'string' as a fallback.
355
384
  */
356
- declare type ExtractParamType<TParam extends Param, TParamKey extends PropertyKey = string> = TParam extends ParamGetSet<infer Type> ? TParamKey extends `?${string}` ? TParam extends ParamWithDefault ? Type : Type | undefined : Type : TParam extends ParamGetter ? TParamKey extends `?${string}` ? ReturnType<TParam> | undefined : ReturnType<TParam> : TParamKey extends `?${string}` ? string | undefined : string;
385
+ declare type ExtractParamType<TParam extends Param, TParamKey extends PropertyKey = string> = TParam extends Required<ParamGetSet> ? Exclude<ExtractParamTypeWithoutLosingOptional<TParam, TParamKey>, undefined> : ExtractParamTypeWithoutLosingOptional<TParam, TParamKey>;
357
386
 
358
387
  /**
359
388
  * Transforms a record of parameter types into a type with optional properties where the original type allows undefined.
@@ -368,7 +397,7 @@ declare type ExtractParamTypesWithoutLosingOptional<TParams extends Record<strin
368
397
  [K in keyof TParams as ExtractParamName<K>]: ExtractParamTypeWithoutLosingOptional<TParams[K], K>;
369
398
  }>>;
370
399
 
371
- declare type ExtractParamTypeWithoutLosingOptional<TParam extends Param, TParamKey extends PropertyKey> = TParam extends ParamGetSet<infer Type> ? TParamKey extends `?${string}` ? Type | undefined : Type : TParam extends ParamGetter ? TParamKey extends `?${string}` ? ReturnType<TParam> | undefined : ReturnType<TParam> : TParamKey extends `?${string}` ? string | undefined : string;
400
+ declare type ExtractParamTypeWithoutLosingOptional<TParam extends Param, TParamKey extends PropertyKey> = TParam extends ParamGetSet<infer Type> ? TParamKey extends `?${string}` ? Type | undefined : Type : TParam extends ParamGetter ? TParamKey extends `?${string}` ? ReturnType<TParam> | undefined : ReturnType<TParam> : TParam extends LiteralParam ? TParamKey extends `?${string}` ? TParam | undefined : TParam : TParamKey extends `?${string}` ? string | undefined : string;
372
401
 
373
402
  /**
374
403
  * Determines the type of a path parameter from a record of parameter types, considering optional parameters.
@@ -418,6 +447,10 @@ declare type ExtractStateParams<TRoute> = TRoute extends {
418
447
  state: infer TState extends Record<string, Param>;
419
448
  } ? ExtractParamTypes<TState> : Record<string, unknown>;
420
449
 
450
+ declare type GetParentPropsReturnType<TParent extends Route | undefined = Route | undefined> = TParent extends Route ? TParent['matched']['props'] extends PropsGetter ? ReturnType<TParent['matched']['props']> : TParent['matched']['props'] extends Record<string, PropsGetter> ? {
451
+ [K in keyof TParent['matched']['props']]: ReturnType<TParent['matched']['props'][K]>;
452
+ } : undefined : undefined;
453
+
421
454
  declare type Hash<THash extends string | undefined = string | undefined> = {
422
455
  value: THash;
423
456
  };
@@ -519,6 +552,8 @@ declare type KeysOfUnion<T> = T extends T ? keyof T : never;
519
552
 
520
553
  declare type LastInArray<T, TFallback = never> = T extends [...any[], infer Last] ? Last : TFallback;
521
554
 
555
+ export declare type LiteralParam = string | number | boolean;
556
+
522
557
  declare type MakeOptional<T> = {
523
558
  [P in WithOptionalProperties<T>]?: T[P];
524
559
  } & {
@@ -582,7 +617,7 @@ declare type OnlyRequiredProperties<T> = {
582
617
  [K in keyof T as Extract<T[K], undefined> extends never ? K : never]: T[K];
583
618
  };
584
619
 
585
- export declare type Param = ParamGetter | ParamGetSet | RegExp | BooleanConstructor | NumberConstructor | StringConstructor | DateConstructor | JSON;
620
+ export declare type Param = ParamGetter | ParamGetSet | RegExp | BooleanConstructor | NumberConstructor | StringConstructor | DateConstructor | JSON | LiteralParam;
586
621
 
587
622
  declare type ParamEnd = typeof paramEnd;
588
623
 
@@ -634,7 +669,7 @@ declare type Path<TPath extends string = string, TParams extends PathParamsWithP
634
669
  * })
635
670
  * ```
636
671
  */
637
- export declare function path<TPath extends string, TParams extends PathParamsWithParamNameExtracted<TPath>>(value: TPath, params: Identity<TParams>): Path<TPath, TParams>;
672
+ export declare function path<const TPath extends string, const TParams extends PathParamsWithParamNameExtracted<TPath>>(value: TPath, params: TParams): Path<TPath, TParams>;
638
673
 
639
674
  declare type PathParamsWithParamNameExtracted<TPath extends string> = {
640
675
  [K in keyof ExtractParamsFromPathString<TPath> as ExtractParamName<K>]?: Param;
@@ -668,13 +703,22 @@ export declare type PrefetchStrategy = 'eager' | 'lazy' | 'intent';
668
703
  /**
669
704
  * Context provided to props callback functions
670
705
  */
671
- export declare type PropsCallbackContext = {
706
+ export declare type PropsCallbackContext<TParent extends Route | undefined = Route | undefined> = {
672
707
  push: CallbackContext['push'];
673
708
  replace: CallbackContext['replace'];
674
709
  reject: CallbackContext['reject'];
710
+ parent: PropsCallbackParent<TParent>;
675
711
  };
676
712
 
677
- declare type PropsGetter<TOptions extends CreateRouteOptions = CreateRouteOptions, TComponent extends Component = Component> = (route: ResolvedRoute<ToRoute<TOptions, undefined>>, context: PropsCallbackContext) => MaybePromise<ComponentProps<TComponent>>;
713
+ declare type PropsCallbackParent<TParent extends Route | undefined = Route | undefined> = Route | undefined extends TParent ? undefined | {
714
+ name: string;
715
+ props: unknown;
716
+ } : TParent extends Route ? {
717
+ name: TParent['name'];
718
+ props: GetParentPropsReturnType<TParent>;
719
+ } : undefined;
720
+
721
+ declare type PropsGetter<TOptions extends CreateRouteOptions = CreateRouteOptions, TComponent extends Component = Component> = (route: ResolvedRoute<ToRoute<TOptions, undefined>>, context: PropsCallbackContext<TOptions['parent']>) => MaybePromise<ComponentProps<TComponent>>;
678
722
 
679
723
  declare type Query<TQuery extends string = string, TQueryParams extends QueryParamsWithParamNameExtracted<TQuery> = Record<string, Param | undefined>> = {
680
724
  value: TQuery;
@@ -702,7 +746,7 @@ declare type Query<TQuery extends string = string, TQueryParams extends QueryPar
702
746
  * })
703
747
  * ```
704
748
  */
705
- export declare function query<TQuery extends string, TParams extends QueryParamsWithParamNameExtracted<TQuery>>(value: TQuery, params: Identity<TParams>): Query<TQuery, TParams>;
749
+ export declare function query<const TQuery extends string, const TParams extends QueryParamsWithParamNameExtracted<TQuery>>(value: TQuery, params: TParams): Query<TQuery, TParams>;
706
750
 
707
751
  declare type QueryParamsWithParamNameExtracted<T extends string> = {
708
752
  [K in keyof ExtractQueryParamsFromQueryString<T> as ExtractParamName<K>]?: Param;
@@ -1056,7 +1100,9 @@ to: Url | ResolvedRoute | ToCallback;
1056
1100
  prefetch?: PrefetchConfig;
1057
1101
  } & RouterPushOptions> & Readonly<{}>, {
1058
1102
  prefetch: PrefetchConfig;
1059
- }, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLAnchorElement>, Readonly<{
1103
+ }, {}, {}, {}, string, ComponentProvideOptions, false, {
1104
+ element: HTMLAnchorElement;
1105
+ }, HTMLAnchorElement>, Readonly<{
1060
1106
  default?: (props: {
1061
1107
  route: ResolvedRoute | undefined;
1062
1108
  isMatch: boolean;
@@ -1201,23 +1247,7 @@ export declare type RouterRoutes<TRoutes extends Routes> = {
1201
1247
  [K in keyof TRoutes]: RouterRoute<ResolvedRoute<TRoutes[K]>>;
1202
1248
  }[number];
1203
1249
 
1204
- export declare const RouterView: __VLS_WithTemplateSlots<DefineComponent< {
1205
- name?: string;
1206
- }, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{
1207
- name?: string;
1208
- }> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, any>, Readonly<{
1209
- default?: (props: {
1210
- route: RouterRoute;
1211
- component: Component;
1212
- rejection: UnwrapRef<RouterRejection>;
1213
- }) => VNode;
1214
- }> & {
1215
- default?: (props: {
1216
- route: RouterRoute;
1217
- component: Component;
1218
- rejection: UnwrapRef<RouterRejection>;
1219
- }) => VNode;
1220
- }>;
1250
+ export declare const RouterView: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
1221
1251
 
1222
1252
  /**
1223
1253
  * Represents an immutable array of Route instances. Return value of `createRoute`, expected param for `createRouter`.
@@ -1273,6 +1303,14 @@ declare type ToRoute<TOptions extends CreateRouteOptions, TProps extends CreateR
1273
1303
 
1274
1304
  declare type ToState<TState extends Record<string, Param> | undefined> = TState extends undefined ? Record<string, Param> : unknown extends TState ? {} : TState;
1275
1305
 
1306
+ declare type TupleOf<T extends Param[]> = {
1307
+ [K in keyof T]: ExtractParamType<T[K]>;
1308
+ };
1309
+
1310
+ export declare function tupleOf<const T extends Param[]>(...params: T): ParamGetSet<TupleOf<T>>;
1311
+
1312
+ export declare function unionOf<const T extends Param[]>(...params: T): ParamGetSet<ExtractParamType<T[number]>>;
1313
+
1276
1314
  export declare type Url = `http://${string}` | `https://${string}` | `/${string}`;
1277
1315
 
1278
1316
  export declare type UrlParts = {