@kitbag/router 0.20.6 → 0.20.8
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/components/echo.d.ts +6 -0
- package/dist/components/helloWorld.d.ts +2 -0
- package/dist/components/rejection.d.ts +2 -0
- package/dist/components/routerLink.browser.spec.d.ts +1 -0
- package/dist/components/routerLink.d.ts +36 -0
- package/dist/components/routerView.browser.spec.d.ts +1 -0
- package/dist/components/routerView.d.ts +20 -0
- package/dist/components/routerView.spec.d.ts +1 -0
- package/dist/compositions/useComponentsStore.d.ts +5 -0
- package/dist/compositions/useEventListener.d.ts +2 -0
- package/dist/compositions/useLink.d.ts +16 -0
- package/dist/compositions/usePrefetching.d.ts +14 -0
- package/dist/compositions/usePropStore.d.ts +7 -0
- package/dist/compositions/useQueryValue.browser.spec.d.ts +1 -0
- package/dist/compositions/useQueryValue.d.ts +15 -0
- package/dist/compositions/useRejection.d.ts +7 -0
- package/dist/compositions/useRoute.browser.spec.d.ts +1 -0
- package/dist/compositions/useRoute.d.ts +16 -0
- package/dist/compositions/useRouter.d.ts +3 -0
- package/dist/compositions/useRouterDepth.d.ts +8 -0
- package/dist/compositions/useRouterHooks.d.ts +4 -0
- package/dist/compositions/useVisibilityObserver.d.ts +8 -0
- package/dist/errors/callbackContextAbortError.d.ts +5 -0
- package/dist/errors/callbackContextPushError.d.ts +5 -0
- package/dist/errors/callbackContextRejectionError.d.ts +6 -0
- package/dist/errors/duplicateNamesError.d.ts +11 -0
- package/dist/errors/duplicateParamsError.d.ts +13 -0
- package/dist/errors/initialRouteMissingError.d.ts +3 -0
- package/dist/errors/invalidRouteParamValueError.d.ts +2 -0
- package/dist/errors/metaPropertyConflict.d.ts +8 -0
- package/dist/errors/routeNotFoundError.d.ts +6 -0
- package/dist/errors/routerNotInstalledError.d.ts +7 -0
- package/dist/errors/useRouteInvalidError.d.ts +13 -0
- package/dist/guards/routes.d.ts +46 -0
- package/dist/guards/routes.spec-d.d.ts +1 -0
- package/dist/keys.d.ts +3 -0
- package/dist/kitbag-router.d.ts +2 -1433
- package/dist/kitbag-router.js +2067 -1959
- package/dist/kitbag-router.umd.cjs +3 -3
- package/dist/main.d.ts +302 -0
- package/dist/models/RouteHooks.d.ts +9 -0
- package/dist/models/RouterRouteHooks.d.ts +10 -0
- package/dist/services/arrayOf.d.ts +7 -0
- package/dist/services/arrayOf.spec.d.ts +1 -0
- package/dist/services/combineHash.d.ts +4 -0
- package/dist/services/combineHash.spec.d.ts +1 -0
- package/dist/services/combineMeta.d.ts +2 -0
- package/dist/services/combineMeta.spec.d.ts +1 -0
- package/dist/services/combinePath.d.ts +12 -0
- package/dist/services/combinePath.spec-d.d.ts +1 -0
- package/dist/services/combinePath.spec.d.ts +1 -0
- package/dist/services/combineQuery.d.ts +13 -0
- package/dist/services/combineQuery.spec.d.ts +1 -0
- package/dist/services/combineState.d.ts +3 -0
- package/dist/services/combineState.spec.d.ts +1 -0
- package/dist/services/component.browser.spec.d.ts +1 -0
- package/dist/services/component.d.ts +12 -0
- package/dist/services/createCallbackContext.d.ts +44 -0
- package/dist/services/createComponentHooks.d.ts +11 -0
- package/dist/services/createComponentsStore.d.ts +7 -0
- package/dist/services/createCurrentRoute.d.ts +13 -0
- package/dist/services/createExternalRoute.d.ts +3 -0
- package/dist/services/createExternalRoute.spec.d.ts +1 -0
- package/dist/services/createIsExternal.d.ts +1 -0
- package/dist/services/createIsExternal.spec.d.ts +1 -0
- package/dist/services/createParam.d.ts +6 -0
- package/dist/services/createPropStore.d.ts +13 -0
- package/dist/services/createResolvedRoute.d.ts +4 -0
- package/dist/services/createResolvedRouteForUrl.browser.spec.d.ts +1 -0
- package/dist/services/createResolvedRouteForUrl.d.ts +3 -0
- package/dist/services/createResolvedRouteQuery.d.ts +5 -0
- package/dist/services/createRoute.d.ts +4 -0
- package/dist/services/createRoute.spec-d.d.ts +1 -0
- package/dist/services/createRoute.spec.d.ts +1 -0
- package/dist/services/createRouteId.d.ts +1 -0
- package/dist/services/createRouter.browser.spec.d.ts +1 -0
- package/dist/services/createRouter.d.ts +28 -0
- package/dist/services/createRouter.spec-d.d.ts +1 -0
- package/dist/services/createRouter.spec.d.ts +1 -0
- package/dist/services/createRouterAssets.d.ts +118 -0
- package/dist/services/createRouterCallbackContext.d.ts +45 -0
- package/dist/services/createRouterHistory.browser.spec.d.ts +1 -0
- package/dist/services/createRouterHistory.d.ts +20 -0
- package/dist/services/createRouterHooks.d.ts +20 -0
- package/dist/services/createRouterKeyStore.d.ts +3 -0
- package/dist/services/createRouterPlugin.browser.spec.d.ts +1 -0
- package/dist/services/createRouterPlugin.d.ts +4 -0
- package/dist/services/createRouterReject.d.ts +16 -0
- package/dist/services/createRouterRoute.d.ts +7 -0
- package/dist/services/createRouterRoute.spec.d.ts +1 -0
- package/dist/services/createUniqueIdSequence.d.ts +2 -0
- package/dist/services/createVisibilityObserver.d.ts +7 -0
- package/dist/services/createVueAppStore.d.ts +8 -0
- package/dist/services/getGlobalHooksForRouter.d.ts +4 -0
- package/dist/services/getGlobalRouteHooks.d.ts +5 -0
- package/dist/services/getInitialUrl.browser.spec.d.ts +1 -0
- package/dist/services/getInitialUrl.d.ts +1 -0
- package/dist/services/getInitialUrl.spec.d.ts +1 -0
- package/dist/services/getMatchesForUrl.d.ts +2 -0
- package/dist/services/getMatchesForUrl.spec.d.ts +1 -0
- package/dist/services/getParamsForString.d.ts +2 -0
- package/dist/services/getRouteHooks.d.ts +10 -0
- package/dist/services/getRouteHooks.spec.d.ts +1 -0
- package/dist/services/getRoutesForRouter.d.ts +9 -0
- package/dist/services/getRoutesForRouter.spec.d.ts +1 -0
- package/dist/services/hooks.browser.spec.d.ts +1 -0
- package/dist/services/hooks.d.ts +8 -0
- package/dist/services/hooks.spec.d.ts +1 -0
- package/dist/services/insertBaseRoute.d.ts +2 -0
- package/dist/services/insertBaseRoute.spec.d.ts +1 -0
- package/dist/services/paramValidation.d.ts +4 -0
- package/dist/services/paramValidation.spec.d.ts +1 -0
- package/dist/services/params.d.ts +7 -0
- package/dist/services/params.spec.d.ts +1 -0
- package/dist/services/paramsFinder.d.ts +3 -0
- package/dist/services/paramsFinder.spec.d.ts +1 -0
- package/dist/services/routeMatchRules.d.ts +5 -0
- package/dist/services/routeMatchRules.spec.d.ts +1 -0
- package/dist/services/routeMatchScore.d.ts +7 -0
- package/dist/services/routeMatchScore.spec.d.ts +1 -0
- package/dist/services/routeRegex.d.ts +18 -0
- package/dist/services/routeRegex.spec.d.ts +1 -0
- package/dist/services/state.d.ts +9 -0
- package/dist/services/state.spec.d.ts +1 -0
- package/dist/services/tupleOf.d.ts +10 -0
- package/dist/services/tupleOf.spec.d.ts +1 -0
- package/dist/services/unionOf.d.ts +3 -0
- package/dist/services/unionOf.spec.d.ts +1 -0
- package/dist/services/urlAssembly.d.ts +10 -0
- package/dist/services/urlAssembly.spec.d.ts +1 -0
- package/dist/services/urlCombine.d.ts +2 -0
- package/dist/services/urlCombine.spec.d.ts +1 -0
- package/dist/services/urlCreator.d.ts +2 -0
- package/dist/services/urlCreator.spec.d.ts +1 -0
- package/dist/services/urlParser.d.ts +2 -0
- package/dist/services/urlParser.spec.d.ts +1 -0
- package/dist/services/valibot.d.ts +7 -0
- package/dist/services/valibot.spec-d.d.ts +1 -0
- package/dist/services/valibot.spec.d.ts +1 -0
- package/dist/services/withDefault.d.ts +5 -0
- package/dist/services/withParams.d.ts +15 -0
- package/dist/services/withParams.spec-d.d.ts +1 -0
- package/dist/services/withParams.spec.d.ts +1 -0
- package/dist/services/zod.d.ts +11 -0
- package/dist/services/zod.spec-d.d.ts +1 -0
- package/dist/services/zod.spec.d.ts +1 -0
- package/dist/tests/hooks.spec.d.ts +1 -0
- package/dist/tests/routeProps.browser.spec.d.ts +1 -0
- package/dist/tests/routeProps.spec.d.ts +1 -0
- package/dist/types/createRouteOptions.d.ts +120 -0
- package/dist/types/hooks.d.ts +129 -0
- package/dist/types/meta.d.ts +2 -0
- package/dist/types/name.d.ts +2 -0
- package/dist/types/paramTypes.d.ts +14 -0
- package/dist/types/params.d.ts +71 -0
- package/dist/types/prefetch.d.ts +27 -0
- package/dist/types/props.d.ts +23 -0
- package/dist/types/querySource.d.ts +1 -0
- package/dist/types/register.d.ts +68 -0
- package/dist/types/register.spec.d.ts +1 -0
- package/dist/types/resolved.d.ts +47 -0
- package/dist/types/resolved.spec-d.d.ts +1 -0
- package/dist/types/route.d.ts +76 -0
- package/dist/types/route.spec-d.d.ts +1 -0
- package/dist/types/routeMatchRule.d.ts +2 -0
- package/dist/types/routeUpdate.d.ts +9 -0
- package/dist/types/routeWithParams.d.ts +5 -0
- package/dist/types/routeWithParams.spec-d.d.ts +1 -0
- package/dist/types/router.d.ts +186 -0
- package/dist/types/routerLink.d.ts +16 -0
- package/dist/types/routerPlugin.d.ts +18 -0
- package/dist/types/routerPush.d.ts +33 -0
- package/dist/types/routerReject.d.ts +3 -0
- package/dist/types/routerReplace.d.ts +20 -0
- package/dist/types/routerResolve.d.ts +15 -0
- package/dist/types/routerRoute.d.ts +16 -0
- package/dist/types/routesMap.d.ts +9 -0
- package/dist/types/routesMap.spec-ts.d.ts +1 -0
- package/dist/types/state.d.ts +18 -0
- package/dist/types/url.d.ts +23 -0
- package/dist/types/useLink.d.ts +51 -0
- package/dist/types/utilities.d.ts +22 -0
- package/dist/utilities/array.d.ts +2 -0
- package/dist/utilities/checkDuplicateKeys.d.ts +1 -0
- package/dist/utilities/checkDuplicateKeys.spec.d.ts +1 -0
- package/dist/utilities/checkDuplicateNames.d.ts +2 -0
- package/dist/utilities/checkDuplicateNames.spec.d.ts +1 -0
- package/dist/utilities/components.d.ts +6 -0
- package/dist/utilities/components.spec.d.ts +1 -0
- package/dist/utilities/guards.d.ts +5 -0
- package/dist/utilities/guards.spec.d.ts +1 -0
- package/dist/utilities/index.d.ts +6 -0
- package/dist/utilities/isBrowser.browser.spec.d.ts +1 -0
- package/dist/utilities/isBrowser.d.ts +1 -0
- package/dist/utilities/isBrowser.spec.d.ts +1 -0
- package/dist/utilities/makeOptional.d.ts +9 -0
- package/dist/utilities/prefetch.d.ts +4 -0
- package/dist/utilities/prefetch.spec.d.ts +1 -0
- package/dist/utilities/promises.d.ts +1 -0
- package/dist/utilities/props.d.ts +6 -0
- package/dist/utilities/testHelpers.d.ts +144 -0
- package/dist/utilities/urlSearchParams.d.ts +2 -0
- package/dist/utilities/urlSearchParams.spec.d.ts +1 -0
- package/package.json +12 -12
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CallbackContext } from '../services/createCallbackContext';
|
|
2
|
+
import { PropsGetter } from './createRouteOptions';
|
|
3
|
+
import { Route } from './route';
|
|
4
|
+
/**
|
|
5
|
+
* Context provided to props callback functions
|
|
6
|
+
*/
|
|
7
|
+
export type PropsCallbackContext<TParent extends Route | undefined = Route | undefined> = {
|
|
8
|
+
push: CallbackContext['push'];
|
|
9
|
+
replace: CallbackContext['replace'];
|
|
10
|
+
reject: CallbackContext['reject'];
|
|
11
|
+
parent: PropsCallbackParent<TParent>;
|
|
12
|
+
};
|
|
13
|
+
export type PropsCallbackParent<TParent extends Route | undefined = Route | undefined> = Route | undefined extends TParent ? undefined | {
|
|
14
|
+
name: string;
|
|
15
|
+
props: unknown;
|
|
16
|
+
} : TParent extends Route ? {
|
|
17
|
+
name: TParent['name'];
|
|
18
|
+
props: GetParentPropsReturnType<TParent>;
|
|
19
|
+
} : undefined;
|
|
20
|
+
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> ? {
|
|
21
|
+
[K in keyof TParent['matched']['props']]: ReturnType<TParent['matched']['props'][K]>;
|
|
22
|
+
} : undefined : undefined;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type QuerySource = ConstructorParameters<typeof URLSearchParams>[0];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { BuiltInRejectionType } from '../services/createRouterReject';
|
|
2
|
+
import { Route, Routes } from './route';
|
|
3
|
+
import { Router, RouterOptions } from './router';
|
|
4
|
+
import { RouterPush } from './routerPush';
|
|
5
|
+
import { RouterReplace } from './routerReplace';
|
|
6
|
+
import { RoutesName } from './routesMap';
|
|
7
|
+
/**
|
|
8
|
+
* Represents the state of currently registered router, and route meta. Used to provide correct type context for
|
|
9
|
+
* components like `RouterLink`, as well as for composables like `useRouter`, `useRoute`, and hooks.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* declare module '@kitbag/router' {
|
|
14
|
+
* interface Register {
|
|
15
|
+
* router: typeof router
|
|
16
|
+
* routeMeta: { public?: boolean }
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export interface Register {
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Represents the Router property within {@link Register}
|
|
25
|
+
*/
|
|
26
|
+
export type RegisteredRouter<T = Register> = T extends {
|
|
27
|
+
router: infer TRouter;
|
|
28
|
+
} ? TRouter : Router;
|
|
29
|
+
/**
|
|
30
|
+
* Represents the Router routes property within {@link Register}
|
|
31
|
+
* @deprecated will be removed in a future version
|
|
32
|
+
*/
|
|
33
|
+
export type RegisteredRoutes<T = Register> = T extends {
|
|
34
|
+
router: Router<infer TRoutes extends Routes>;
|
|
35
|
+
} ? TRoutes : Route[];
|
|
36
|
+
/**
|
|
37
|
+
* Represents the possible Rejections registered within {@link Register}
|
|
38
|
+
* @deprecated use `createRouter(..., { rejections: {}}) instead
|
|
39
|
+
*/
|
|
40
|
+
export type RegisteredRejectionType<T = Register> = T extends {
|
|
41
|
+
router: Router<any, infer TOptions extends RouterOptions>;
|
|
42
|
+
} ? keyof TOptions['rejections'] | BuiltInRejectionType : BuiltInRejectionType;
|
|
43
|
+
/**
|
|
44
|
+
* Represents additional metadata associated with a route, customizable via declaration merging.
|
|
45
|
+
*/
|
|
46
|
+
export type RouteMeta<T = Register> = T extends {
|
|
47
|
+
routeMeta: infer RouteMeta extends Record<string, unknown>;
|
|
48
|
+
} ? RouteMeta : Record<string, unknown>;
|
|
49
|
+
/**
|
|
50
|
+
* Represents the type for router `push`, with types for routes registered within {@link Register}
|
|
51
|
+
* @deprecated will be removed in a future version
|
|
52
|
+
*/
|
|
53
|
+
export type RegisteredRouterPush = RouterPush<RegisteredRoutes>;
|
|
54
|
+
/**
|
|
55
|
+
* Represents the type for router `replace`, with types for routes registered within {@link Register}
|
|
56
|
+
* @deprecated will be removed in a future version
|
|
57
|
+
*/
|
|
58
|
+
export type RegisteredRouterReplace = RouterReplace<RegisteredRoutes>;
|
|
59
|
+
/**
|
|
60
|
+
* Type for Router Reject method. Triggers rejections registered within {@link Register}
|
|
61
|
+
* @deprecated will be removed in a future version
|
|
62
|
+
*/
|
|
63
|
+
export type RegisteredRouterReject = (type: RegisteredRejectionType) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Represents the union of all possible route names registered within {@link Register}
|
|
66
|
+
* @deprecated will be removed in a future version
|
|
67
|
+
*/
|
|
68
|
+
export type RegisteredRoutesName = RoutesName<RegisteredRoutes>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ExtractRouteParamTypesReading } from './params';
|
|
2
|
+
import { Route } from './route';
|
|
3
|
+
import { ExtractRouteStateParamsAsOptional } from './state';
|
|
4
|
+
import { Url } from './url';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a route that the router has matched to current browser location.
|
|
7
|
+
* @template TRoute - Underlying Route that has been resolved.
|
|
8
|
+
*/
|
|
9
|
+
export type ResolvedRoute<TRoute extends Route = Route> = Readonly<{
|
|
10
|
+
/**
|
|
11
|
+
* Unique identifier for the route, generated by router.
|
|
12
|
+
*/
|
|
13
|
+
id: TRoute['id'];
|
|
14
|
+
/**
|
|
15
|
+
* The specific route properties that were matched in the current route.
|
|
16
|
+
*/
|
|
17
|
+
matched: TRoute['matched'];
|
|
18
|
+
/**
|
|
19
|
+
* The specific route properties that were matched in the current route, including any ancestors.
|
|
20
|
+
* Order of routes will be from greatest ancestor to narrowest matched.
|
|
21
|
+
*/
|
|
22
|
+
matches: TRoute['matches'];
|
|
23
|
+
/**
|
|
24
|
+
* Unique identifier for the route. Name is used for routing and for matching.
|
|
25
|
+
*/
|
|
26
|
+
name: TRoute['name'];
|
|
27
|
+
/**
|
|
28
|
+
* Accessor for query string values from user in the current browser location.
|
|
29
|
+
*/
|
|
30
|
+
query: URLSearchParams;
|
|
31
|
+
/**
|
|
32
|
+
* Hash value of the route.
|
|
33
|
+
*/
|
|
34
|
+
hash: string;
|
|
35
|
+
/**
|
|
36
|
+
* Key value pair for route params, values will be the user provided value from current browser location.
|
|
37
|
+
*/
|
|
38
|
+
params: ExtractRouteParamTypesReading<TRoute>;
|
|
39
|
+
/**
|
|
40
|
+
* Type for additional data intended to be stored in history state.
|
|
41
|
+
*/
|
|
42
|
+
state: ExtractRouteStateParamsAsOptional<TRoute['state']>;
|
|
43
|
+
/**
|
|
44
|
+
* String value of the resolved URL.
|
|
45
|
+
*/
|
|
46
|
+
href: Url;
|
|
47
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Param } from './paramTypes';
|
|
2
|
+
import { PrefetchConfig } from './prefetch';
|
|
3
|
+
import { RouteMeta } from './register';
|
|
4
|
+
import { LastInArray } from './utilities';
|
|
5
|
+
import { CreateRouteOptions } from './createRouteOptions';
|
|
6
|
+
import { WithHooks } from './hooks';
|
|
7
|
+
import { WithParams } from '../services/withParams';
|
|
8
|
+
/**
|
|
9
|
+
* Represents an immutable array of Route instances. Return value of `createRoute`, expected param for `createRouter`.
|
|
10
|
+
*/
|
|
11
|
+
export type Routes = readonly Route[];
|
|
12
|
+
/**
|
|
13
|
+
* The Route properties originally provided to `createRoute`. The only change is normalizing meta to always default to an empty object.
|
|
14
|
+
*/
|
|
15
|
+
export type CreatedRouteOptions = Omit<CreateRouteOptions, 'props'> & WithHooks & {
|
|
16
|
+
id: string;
|
|
17
|
+
props?: unknown;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Represents the structure of a route within the application. Return value of `createRoute`
|
|
21
|
+
* @template TName - Represents the unique name identifying the route, typically a string.
|
|
22
|
+
* @template TPath - The type or structure of the route's path.
|
|
23
|
+
* @template TQuery - The type or structure of the query parameters associated with the route.
|
|
24
|
+
*/
|
|
25
|
+
export type Route<TName extends string = string, THost extends WithParams = WithParams, TPath extends WithParams = WithParams, TQuery extends WithParams = WithParams, THash extends WithParams = WithParams, TMeta extends RouteMeta = RouteMeta, TState extends Record<string, Param> = Record<string, Param>, TMatches extends CreatedRouteOptions[] = CreatedRouteOptions[]> = {
|
|
26
|
+
/**
|
|
27
|
+
* Unique identifier for the route, generated by router.
|
|
28
|
+
*/
|
|
29
|
+
id: string;
|
|
30
|
+
/**
|
|
31
|
+
* The specific route properties that were matched in the current route.
|
|
32
|
+
*/
|
|
33
|
+
matched: LastInArray<TMatches, CreatedRouteOptions>;
|
|
34
|
+
/**
|
|
35
|
+
* The specific route properties that were matched in the current route, including any ancestors.
|
|
36
|
+
* Order of routes will be from greatest ancestor to narrowest matched.
|
|
37
|
+
*/
|
|
38
|
+
matches: TMatches;
|
|
39
|
+
/**
|
|
40
|
+
* Identifier for the route as defined by user. Name must be unique among named routes. Name is used for routing and for matching.
|
|
41
|
+
*/
|
|
42
|
+
name: TName;
|
|
43
|
+
/**
|
|
44
|
+
* Represents the host for this route. Used for external routes.
|
|
45
|
+
*/
|
|
46
|
+
host: THost;
|
|
47
|
+
/**
|
|
48
|
+
* Represents the structured path of the route, including path params.
|
|
49
|
+
*/
|
|
50
|
+
path: TPath;
|
|
51
|
+
/**
|
|
52
|
+
* Represents the structured query of the route, including query params.
|
|
53
|
+
*/
|
|
54
|
+
query: TQuery;
|
|
55
|
+
/**
|
|
56
|
+
* Represents the hash of the route.
|
|
57
|
+
*/
|
|
58
|
+
hash: THash;
|
|
59
|
+
/**
|
|
60
|
+
* Represents additional metadata associated with a route, combined with any parents.
|
|
61
|
+
*/
|
|
62
|
+
meta: TMeta;
|
|
63
|
+
/**
|
|
64
|
+
* Represents the schema of the route state, combined with any parents.
|
|
65
|
+
*/
|
|
66
|
+
state: TState;
|
|
67
|
+
/**
|
|
68
|
+
* Determines what assets are prefetched when router-link is rendered for this route. Overrides router level prefetch.
|
|
69
|
+
*/
|
|
70
|
+
prefetch?: PrefetchConfig;
|
|
71
|
+
/**
|
|
72
|
+
* A value that represents how many parents a route has. Used for route matching
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
depth: number;
|
|
76
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ResolvedRoute } from './resolved';
|
|
2
|
+
import { RouterPushOptions } from './routerPush';
|
|
3
|
+
export type RouteUpdate<TRoute extends ResolvedRoute = ResolvedRoute> = ResolvedRoute extends TRoute ? {
|
|
4
|
+
(paramName: string, paramValue: unknown, options?: RouterPushOptions): Promise<void>;
|
|
5
|
+
(params: Partial<TRoute['params']>, options?: RouterPushOptions): Promise<void>;
|
|
6
|
+
} : {
|
|
7
|
+
<TParamName extends keyof TRoute['params']>(paramName: TParamName, paramValue: TRoute['params'][TParamName], options?: RouterPushOptions): Promise<void>;
|
|
8
|
+
(params: Partial<TRoute['params']>, options?: RouterPushOptions): Promise<void>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ExtractRouteParamTypesWriting } from './params';
|
|
2
|
+
import { Route, Routes } from './route';
|
|
3
|
+
import { RoutesName, RoutesMap } from './routesMap';
|
|
4
|
+
export type RouteGetByKey<TRoutes extends Routes, TKey extends RoutesName<TRoutes>> = RoutesMap<TRoutes>[TKey];
|
|
5
|
+
export type RouteParamsByKey<TRoutes extends Routes, TKey extends string> = RouteGetByKey<TRoutes, TKey> extends Route ? ExtractRouteParamTypesWriting<RouteGetByKey<TRoutes, TKey>> : Record<string, unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { App, Component, InjectionKey, Ref } from 'vue';
|
|
2
|
+
import { RouterHistoryMode } from '../services/createRouterHistory';
|
|
3
|
+
import { RouterRoute } from './routerRoute';
|
|
4
|
+
import { RouteHookRemove, WithHooks } from './hooks';
|
|
5
|
+
import { PrefetchConfig } from './prefetch';
|
|
6
|
+
import { ResolvedRoute } from './resolved';
|
|
7
|
+
import { Route, Routes } from './route';
|
|
8
|
+
import { RouterPush } from './routerPush';
|
|
9
|
+
import { RouterReplace } from './routerReplace';
|
|
10
|
+
import { RouterResolve, RouterResolveOptions } from './routerResolve';
|
|
11
|
+
import { RouterReject } from './routerReject';
|
|
12
|
+
import { RouterPlugin } from './routerPlugin';
|
|
13
|
+
import { KeysOfUnion, MaybePromise } from './utilities';
|
|
14
|
+
import { RoutesName } from './routesMap';
|
|
15
|
+
import { AfterRouteHookResponse, BeforeRouteHookResponse } from '../main';
|
|
16
|
+
import { CallbackContextAbort } from '../services/createCallbackContext';
|
|
17
|
+
/**
|
|
18
|
+
* Options to initialize a {@link Router} instance.
|
|
19
|
+
*/
|
|
20
|
+
export type RouterOptions = WithHooks & {
|
|
21
|
+
/**
|
|
22
|
+
* Initial URL for the router to use. Required if using Node environment. Defaults to window.location when using browser.
|
|
23
|
+
*
|
|
24
|
+
* @default window.location.toString()
|
|
25
|
+
*/
|
|
26
|
+
initialUrl?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Specifies the history mode for the router, such as "browser", "memory", or "hash".
|
|
29
|
+
*
|
|
30
|
+
* @default "auto"
|
|
31
|
+
*/
|
|
32
|
+
historyMode?: RouterHistoryMode;
|
|
33
|
+
/**
|
|
34
|
+
* Base path to be prepended to any URL. Can be used for Vue applications that run in nested folder for domain.
|
|
35
|
+
* For example having `base` of `/foo` would assume all routes should start with `your.domain.com/foo`.
|
|
36
|
+
*/
|
|
37
|
+
base?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Determines what assets are prefetched when router-link is rendered for a specific route
|
|
40
|
+
*/
|
|
41
|
+
prefetch?: PrefetchConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Components assigned to each type of rejection your router supports.
|
|
44
|
+
*/
|
|
45
|
+
rejections?: Partial<Record<string, Component>>;
|
|
46
|
+
/**
|
|
47
|
+
* When false, createRouterAssets must be used for component and hooks. Assets exported by the library
|
|
48
|
+
* will not work with the created router instance.
|
|
49
|
+
*
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
isGlobalRouter?: boolean;
|
|
53
|
+
};
|
|
54
|
+
export type Router<TRoutes extends Routes = any, TOptions extends RouterOptions = any, TPlugin extends RouterPlugin = any> = {
|
|
55
|
+
/**
|
|
56
|
+
* Installs the router into a Vue application instance.
|
|
57
|
+
* @param app The Vue application instance to install the router into
|
|
58
|
+
*/
|
|
59
|
+
install: (app: App) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Manages the current route state.
|
|
62
|
+
*/
|
|
63
|
+
route: RouterRouteUnion<TRoutes> | RouterRouteUnion<TPlugin['routes']>;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a ResolvedRoute record for a given route name and params.
|
|
66
|
+
*/
|
|
67
|
+
resolve: RouterResolve<TRoutes | TPlugin['routes']>;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a ResolvedRoute record for a given URL.
|
|
70
|
+
*/
|
|
71
|
+
find: (url: string, options?: RouterResolveOptions) => ResolvedRoute | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Navigates to a specified path or route object in the history stack, adding a new entry.
|
|
74
|
+
*/
|
|
75
|
+
push: RouterPush<TRoutes | TPlugin['routes']>;
|
|
76
|
+
/**
|
|
77
|
+
* Replaces the current entry in the history stack with a new one.
|
|
78
|
+
*/
|
|
79
|
+
replace: RouterReplace<TRoutes | TPlugin['routes']>;
|
|
80
|
+
/**
|
|
81
|
+
* Handles route rejection based on a specified rejection type.
|
|
82
|
+
*/
|
|
83
|
+
reject: RouterReject<keyof TOptions['rejections'] | KeysOfUnion<TPlugin['rejections']>>;
|
|
84
|
+
/**
|
|
85
|
+
* Forces the router to re-evaluate the current route.
|
|
86
|
+
*/
|
|
87
|
+
refresh: () => void;
|
|
88
|
+
/**
|
|
89
|
+
* Navigates to the previous entry in the browser's history stack.
|
|
90
|
+
*/
|
|
91
|
+
back: () => void;
|
|
92
|
+
/**
|
|
93
|
+
* Navigates to the next entry in the browser's history stack.
|
|
94
|
+
*/
|
|
95
|
+
forward: () => void;
|
|
96
|
+
/**
|
|
97
|
+
* Moves the current history entry to a specific point in the history stack.
|
|
98
|
+
*/
|
|
99
|
+
go: (delta: number) => void;
|
|
100
|
+
/**
|
|
101
|
+
* Registers a hook to be called before a route is entered.
|
|
102
|
+
*/
|
|
103
|
+
onBeforeRouteEnter: AddRouterBeforeRouteHook<TRoutes | TPlugin['routes'], keyof TOptions['rejections'] | KeysOfUnion<TPlugin['rejections']>>;
|
|
104
|
+
/**
|
|
105
|
+
* Registers a hook to be called before a route is left.
|
|
106
|
+
*/
|
|
107
|
+
onBeforeRouteLeave: AddRouterBeforeRouteHook<TRoutes | TPlugin['routes'], keyof TOptions['rejections'] | KeysOfUnion<TPlugin['rejections']>>;
|
|
108
|
+
/**
|
|
109
|
+
* Registers a hook to be called before a route is updated.
|
|
110
|
+
*/
|
|
111
|
+
onBeforeRouteUpdate: AddRouterBeforeRouteHook<TRoutes | TPlugin['routes'], keyof TOptions['rejections'] | KeysOfUnion<TPlugin['rejections']>>;
|
|
112
|
+
/**
|
|
113
|
+
* Registers a hook to be called after a route is entered.
|
|
114
|
+
*/
|
|
115
|
+
onAfterRouteEnter: AddRouterAfterRouteHook<TRoutes | TPlugin['routes'], keyof TOptions['rejections'] | KeysOfUnion<TPlugin['rejections']>>;
|
|
116
|
+
/**
|
|
117
|
+
* Registers a hook to be called after a route is left.
|
|
118
|
+
*/
|
|
119
|
+
onAfterRouteLeave: AddRouterAfterRouteHook<TRoutes | TPlugin['routes'], keyof TOptions['rejections'] | KeysOfUnion<TPlugin['rejections']>>;
|
|
120
|
+
/**
|
|
121
|
+
* Registers a hook to be called after a route is updated.
|
|
122
|
+
*/
|
|
123
|
+
onAfterRouteUpdate: AddRouterAfterRouteHook<TRoutes | TPlugin['routes'], keyof TOptions['rejections'] | KeysOfUnion<TPlugin['rejections']>>;
|
|
124
|
+
/**
|
|
125
|
+
* Given a URL, returns true if host does not match host stored on router instance
|
|
126
|
+
*/
|
|
127
|
+
isExternal: (url: string) => boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Determines what assets are prefetched.
|
|
130
|
+
*/
|
|
131
|
+
prefetch?: PrefetchConfig;
|
|
132
|
+
/**
|
|
133
|
+
* Initializes the router based on the initial route. Automatically called when the router is installed. Calling this more than once has no effect.
|
|
134
|
+
*/
|
|
135
|
+
start: () => Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* Returns true if the router has been started.
|
|
138
|
+
*/
|
|
139
|
+
started: Ref<boolean>;
|
|
140
|
+
/**
|
|
141
|
+
* Stops the router and teardown any listeners.
|
|
142
|
+
*/
|
|
143
|
+
stop: () => void;
|
|
144
|
+
/**
|
|
145
|
+
* Returns the key of the router.
|
|
146
|
+
*
|
|
147
|
+
* @private
|
|
148
|
+
*/
|
|
149
|
+
key: InjectionKey<Router<TRoutes, TOptions, TPlugin>>;
|
|
150
|
+
};
|
|
151
|
+
type RouterHookContext<TRoutes extends Routes, TRejections extends PropertyKey> = {
|
|
152
|
+
from: RouterResolvedRouteUnion<TRoutes> | null;
|
|
153
|
+
reject: RouterReject<TRejections>;
|
|
154
|
+
push: RouterPush<TRoutes>;
|
|
155
|
+
replace: RouterReplace<TRoutes>;
|
|
156
|
+
};
|
|
157
|
+
type RouterBeforeRouteHookContext<TRoutes extends Routes, TRejections extends PropertyKey> = RouterHookContext<TRoutes, TRejections> & {
|
|
158
|
+
abort: CallbackContextAbort;
|
|
159
|
+
};
|
|
160
|
+
export type HookContext<TRoutes extends Routes> = {
|
|
161
|
+
to: RouterResolvedRouteUnion<TRoutes>;
|
|
162
|
+
from: RouterResolvedRouteUnion<TRoutes> | null;
|
|
163
|
+
};
|
|
164
|
+
export type RouterBeforeRouteHook<TRoutes extends Routes, TRejections extends PropertyKey> = (to: RouterResolvedRouteUnion<TRoutes>, context: RouterBeforeRouteHookContext<TRoutes, TRejections>) => MaybePromise<void>;
|
|
165
|
+
export type AddRouterBeforeRouteHook<TRoutes extends Routes, TRejections extends PropertyKey> = (hook: RouterBeforeRouteHook<TRoutes, TRejections>) => RouteHookRemove;
|
|
166
|
+
type RouterAfterRouteHookContext<TRoutes extends Routes, TRejections extends PropertyKey> = RouterHookContext<TRoutes, TRejections>;
|
|
167
|
+
export type RouterAfterRouteHook<TRoutes extends Routes, TRejections extends PropertyKey> = (to: RouterResolvedRouteUnion<TRoutes>, context: RouterAfterRouteHookContext<TRoutes, TRejections>) => MaybePromise<void>;
|
|
168
|
+
export type AddRouterAfterRouteHook<TRoutes extends Routes, TRejections extends PropertyKey> = (hook: RouterAfterRouteHook<TRoutes, TRejections>) => RouteHookRemove;
|
|
169
|
+
export type RouterRouteHookBeforeRunner<TRoutes extends Routes> = (context: HookContext<TRoutes>) => Promise<BeforeRouteHookResponse>;
|
|
170
|
+
export type RouterRouteHookAfterRunner<TRoutes extends Routes> = (context: HookContext<TRoutes>) => Promise<AfterRouteHookResponse>;
|
|
171
|
+
/**
|
|
172
|
+
* This type is the same as `RouterRoute<ResolvedRoute<TRoutes[number]>>` while remaining distributive
|
|
173
|
+
*/
|
|
174
|
+
export type RouterRouteUnion<TRoutes extends Routes> = {
|
|
175
|
+
[K in keyof TRoutes]: RouterRoute<ResolvedRoute<TRoutes[K]>>;
|
|
176
|
+
}[number];
|
|
177
|
+
/**
|
|
178
|
+
* This type is the same as `ResolvedRoute<TRoutes[number]>` while remaining distributive
|
|
179
|
+
*/
|
|
180
|
+
type RouterResolvedRouteUnion<TRoutes extends Routes> = {
|
|
181
|
+
[K in keyof TRoutes]: ResolvedRoute<TRoutes[K]>;
|
|
182
|
+
}[number];
|
|
183
|
+
export type RouterRoutes<TRouter extends Router> = TRouter extends Router<infer TRoutes extends Routes> ? TRoutes : Routes;
|
|
184
|
+
export type RouterRejections<TRouter extends Router> = TRouter extends Router<any, infer TOptions extends RouterOptions, infer TPlugins extends RouterPlugin> ? keyof TOptions['rejections'] | KeysOfUnion<TPlugins['rejections']> : PropertyKey;
|
|
185
|
+
export type RouterRouteName<TRouter extends Router> = TRouter extends Router<infer TRoutes extends Routes> ? RoutesName<TRoutes> : RoutesName<Route[]>;
|
|
186
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PrefetchConfig } from './prefetch';
|
|
2
|
+
import { Url } from './url';
|
|
3
|
+
import { ResolvedRoute } from './resolved';
|
|
4
|
+
import { Router } from './router';
|
|
5
|
+
import { RouterPushOptions } from './routerPush';
|
|
6
|
+
export type ToCallback<TRouter extends Router> = (resolve: TRouter['resolve']) => ResolvedRoute | Url | undefined;
|
|
7
|
+
export type RouterLinkProps<TRouter extends Router> = RouterPushOptions & {
|
|
8
|
+
/**
|
|
9
|
+
* The url string to navigate to or a callback that returns a url string
|
|
10
|
+
*/
|
|
11
|
+
to: Url | ResolvedRoute | ToCallback<TRouter>;
|
|
12
|
+
/**
|
|
13
|
+
* Determines what assets are prefetched when router-link is rendered for this route. Overrides route level prefetch.
|
|
14
|
+
*/
|
|
15
|
+
prefetch?: PrefetchConfig;
|
|
16
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Component } from 'vue';
|
|
2
|
+
import { BeforeRouteHook, AfterRouteHook } from './hooks';
|
|
3
|
+
import { Routes } from './route';
|
|
4
|
+
import { MaybeArray } from './utilities';
|
|
5
|
+
export type EmptyRouterPlugin = {
|
|
6
|
+
routes: [];
|
|
7
|
+
rejections: {};
|
|
8
|
+
};
|
|
9
|
+
export type RouterPlugin<TRoutes extends Routes = Routes, TRejections extends Record<string, Component> = Record<string, Component>> = {
|
|
10
|
+
routes: TRoutes;
|
|
11
|
+
rejections: TRejections;
|
|
12
|
+
onBeforeRouteEnter?: MaybeArray<BeforeRouteHook>;
|
|
13
|
+
onAfterRouteEnter?: MaybeArray<AfterRouteHook>;
|
|
14
|
+
onBeforeRouteUpdate?: MaybeArray<BeforeRouteHook>;
|
|
15
|
+
onAfterRouteUpdate?: MaybeArray<AfterRouteHook>;
|
|
16
|
+
onBeforeRouteLeave?: MaybeArray<BeforeRouteHook>;
|
|
17
|
+
onAfterRouteLeave?: MaybeArray<AfterRouteHook>;
|
|
18
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Routes } from './route';
|
|
2
|
+
import { RoutesName } from './routesMap';
|
|
3
|
+
import { RouteParamsByKey } from './routeWithParams';
|
|
4
|
+
import { RouteStateByName } from './state';
|
|
5
|
+
import { Url } from './url';
|
|
6
|
+
import { AllPropertiesAreOptional } from './utilities';
|
|
7
|
+
import { QuerySource } from './querySource';
|
|
8
|
+
import { ResolvedRoute } from './resolved';
|
|
9
|
+
export type RouterPushOptions<TState = unknown> = {
|
|
10
|
+
/**
|
|
11
|
+
* The query string to add to the url.
|
|
12
|
+
*/
|
|
13
|
+
query?: QuerySource;
|
|
14
|
+
/**
|
|
15
|
+
* The hash to append to the url.
|
|
16
|
+
*/
|
|
17
|
+
hash?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to replace the current history entry.
|
|
20
|
+
*/
|
|
21
|
+
replace?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* State values to pass to the route.
|
|
24
|
+
*/
|
|
25
|
+
state?: Partial<TState>;
|
|
26
|
+
};
|
|
27
|
+
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>>];
|
|
28
|
+
export type RouterPush<TRoutes extends Routes = any> = {
|
|
29
|
+
<TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterPushArgs<TRoutes, TSource>): Promise<void>;
|
|
30
|
+
(route: ResolvedRoute, options?: RouterPushOptions): Promise<void>;
|
|
31
|
+
(url: Url, options?: RouterPushOptions): Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Routes } from './route';
|
|
2
|
+
import { RoutesName } from './routesMap';
|
|
3
|
+
import { RouteParamsByKey } from './routeWithParams';
|
|
4
|
+
import { RouteStateByName } from './state';
|
|
5
|
+
import { Url } from './url';
|
|
6
|
+
import { AllPropertiesAreOptional } from './utilities';
|
|
7
|
+
import { QuerySource } from './querySource';
|
|
8
|
+
import { ResolvedRoute } from './resolved';
|
|
9
|
+
export type RouterReplaceOptions<TState = unknown> = {
|
|
10
|
+
query?: QuerySource;
|
|
11
|
+
hash?: string;
|
|
12
|
+
state?: Partial<TState>;
|
|
13
|
+
};
|
|
14
|
+
type RouterReplaceArgs<TRoutes extends Routes, TSource extends RoutesName<TRoutes>> = AllPropertiesAreOptional<RouteParamsByKey<TRoutes, TSource>> extends true ? [params?: RouteParamsByKey<TRoutes, TSource>, options?: RouterReplaceOptions<RouteStateByName<TRoutes, TSource>>] : [params: RouteParamsByKey<TRoutes, TSource>, options?: RouterReplaceOptions<RouteStateByName<TRoutes, TSource>>];
|
|
15
|
+
export type RouterReplace<TRoutes extends Routes> = {
|
|
16
|
+
<TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterReplaceArgs<TRoutes, TSource>): Promise<void>;
|
|
17
|
+
(route: ResolvedRoute, options?: RouterReplaceOptions): Promise<void>;
|
|
18
|
+
(url: Url, options?: RouterReplaceOptions): Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Routes } from './route';
|
|
2
|
+
import { RoutesName } from './routesMap';
|
|
3
|
+
import { RouteParamsByKey } from './routeWithParams';
|
|
4
|
+
import { AllPropertiesAreOptional } from './utilities';
|
|
5
|
+
import { QuerySource } from './querySource';
|
|
6
|
+
import { ResolvedRoute } from './resolved';
|
|
7
|
+
import { RouteStateByName } from './state';
|
|
8
|
+
export type RouterResolveOptions<TState = unknown> = {
|
|
9
|
+
query?: QuerySource;
|
|
10
|
+
hash?: string;
|
|
11
|
+
state?: Partial<TState>;
|
|
12
|
+
};
|
|
13
|
+
type RouterResolveArgs<TRoutes extends Routes, TSource extends RoutesName<TRoutes>> = AllPropertiesAreOptional<RouteParamsByKey<TRoutes, TSource>> extends true ? [params?: RouteParamsByKey<TRoutes, TSource>, options?: RouterResolveOptions<RouteStateByName<TRoutes, TSource>>] : [params: RouteParamsByKey<TRoutes, TSource>, options?: RouterResolveOptions<RouteStateByName<TRoutes, TSource>>];
|
|
14
|
+
export type RouterResolve<TRoutes extends Routes> = <TSource extends RoutesName<TRoutes>>(name: TSource, ...args: RouterResolveArgs<TRoutes, TSource>) => ResolvedRoute;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RouteUpdate } from './routeUpdate';
|
|
2
|
+
import { ResolvedRoute } from './resolved';
|
|
3
|
+
import { QuerySource } from './querySource';
|
|
4
|
+
export type RouterRoute<TRoute extends ResolvedRoute = ResolvedRoute> = {
|
|
5
|
+
readonly id: TRoute['id'];
|
|
6
|
+
readonly name: TRoute['name'];
|
|
7
|
+
readonly matched: TRoute['matched'];
|
|
8
|
+
readonly matches: TRoute['matches'];
|
|
9
|
+
readonly hash: TRoute['hash'];
|
|
10
|
+
readonly update: RouteUpdate<TRoute>;
|
|
11
|
+
readonly href: TRoute['href'];
|
|
12
|
+
params: TRoute['params'];
|
|
13
|
+
state: TRoute['state'];
|
|
14
|
+
get query(): URLSearchParams;
|
|
15
|
+
set query(value: QuerySource);
|
|
16
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Route, Routes } from './route';
|
|
2
|
+
import { StringHasValue } from '../utilities/guards';
|
|
3
|
+
type IsRouteUnnamed<T extends Route> = StringHasValue<T['name']> extends true ? false : true;
|
|
4
|
+
type AsNamedRoute<T extends Route> = IsRouteUnnamed<T> extends true ? never : T;
|
|
5
|
+
export type RoutesMap<TRoutes extends Routes = []> = {
|
|
6
|
+
[K in TRoutes[number] as AsNamedRoute<K>['name']]: AsNamedRoute<K>;
|
|
7
|
+
};
|
|
8
|
+
export type RoutesName<TRoutes extends Routes> = string & keyof RoutesMap<TRoutes>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ExtractParamName, ExtractParamType } from './params';
|
|
2
|
+
import { Param } from './paramTypes';
|
|
3
|
+
import { Routes } from './route';
|
|
4
|
+
import { RouteGetByKey } from './routeWithParams';
|
|
5
|
+
import { MakeOptional } from '../utilities/makeOptional';
|
|
6
|
+
import { Identity } from './utilities';
|
|
7
|
+
export type ToState<TState extends Record<string, Param> | undefined> = TState extends undefined ? Record<string, Param> : unknown extends TState ? {} : TState;
|
|
8
|
+
export type ExtractRouteStateParamsAsOptional<TParams extends Record<string, Param>> = {
|
|
9
|
+
[K in keyof TParams]: ExtractParamType<TParams[K]> | undefined;
|
|
10
|
+
};
|
|
11
|
+
export type RouteStateByName<TRoutes extends Routes, TName extends string> = ExtractStateParams<RouteGetByKey<TRoutes, TName>>;
|
|
12
|
+
type ExtractStateParams<TRoute> = TRoute extends {
|
|
13
|
+
state: infer TState extends Record<string, Param>;
|
|
14
|
+
} ? ExtractParamTypes<TState> : Record<string, unknown>;
|
|
15
|
+
type ExtractParamTypes<TParams extends Record<string, Param>> = Identity<MakeOptional<{
|
|
16
|
+
[K in keyof TParams as ExtractParamName<K>]: ExtractParamType<TParams[K]>;
|
|
17
|
+
}>>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { QuerySource } from './querySource';
|
|
2
|
+
export type Url = `http://${string}` | `https://${string}` | `/${string}`;
|
|
3
|
+
export type UrlParts = {
|
|
4
|
+
protocol?: string;
|
|
5
|
+
host?: string;
|
|
6
|
+
pathname: string;
|
|
7
|
+
searchParams: QuerySource;
|
|
8
|
+
search: string;
|
|
9
|
+
hash: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A type guard for determining if a value is a valid URL.
|
|
13
|
+
* @param value - The value to check.
|
|
14
|
+
* @returns `true` if the value is a valid URL, otherwise `false`.
|
|
15
|
+
* @group Type Guards
|
|
16
|
+
*/
|
|
17
|
+
export declare function isUrl(value: unknown): value is Url;
|
|
18
|
+
/**
|
|
19
|
+
* Converts a string to a valid URL.
|
|
20
|
+
* @param value - The string to convert.
|
|
21
|
+
* @returns The valid URL.
|
|
22
|
+
*/
|
|
23
|
+
export declare function asUrl(value: string): Url;
|