@tanstack/router-core 0.0.1-beta.155 → 0.0.1-beta.157
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/build/cjs/fileRoute.js.map +1 -1
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/searchParams.js +25 -8
- package/build/cjs/searchParams.js.map +1 -1
- package/build/esm/index.js +25 -8
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +116 -116
- package/build/types/index.d.ts +14 -14
- package/build/umd/index.development.js +25 -8
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/fileRoute.ts +1 -1
- package/src/route.ts +49 -21
- package/src/searchParams.ts +32 -8
package/build/types/index.d.ts
CHANGED
|
@@ -392,13 +392,13 @@ type RouteProps<TLoader = unknown, TFullSearchSchema extends AnySearchSchema = A
|
|
|
392
392
|
select?: (context: TDefaultSelected) => TSelected;
|
|
393
393
|
}) => TSelected;
|
|
394
394
|
};
|
|
395
|
-
type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoader = unknown, TParentSearchSchema extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TParentContext extends AnyContext = AnyContext, TAllParentContext extends AnyContext = AnyContext, TRouteContext extends RouteContext = RouteContext,
|
|
395
|
+
type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoader = unknown, TParentSearchSchema extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TParentContext extends AnyContext = AnyContext, TAllParentContext extends AnyContext = AnyContext, TRouteContext extends RouteContext = RouteContext, TAllContext extends AnyContext = AnyContext> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TLoader, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
|
|
396
396
|
type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
|
|
397
|
-
type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoader = unknown, TParentSearchSchema extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParams = unknown, TAllParams = ParamsFallback<TPath, TParams>, TParentContext extends AnyContext = AnyContext, TAllParentContext extends AnyContext = AnyContext, TRouteContext extends RouteContext = RouteContext,
|
|
397
|
+
type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoader = unknown, TParentSearchSchema extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParams = unknown, TAllParams = ParamsFallback<TPath, TParams>, TParentContext extends AnyContext = AnyContext, TAllParentContext extends AnyContext = AnyContext, TRouteContext extends RouteContext = RouteContext, TAllContext extends AnyContext = AnyContext> = RoutePathOptions<TCustomId, TPath> & {
|
|
398
398
|
layoutLimit?: string;
|
|
399
399
|
getParentRoute: () => TParentRoute;
|
|
400
400
|
validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>;
|
|
401
|
-
loader?: LoaderFn<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, NoInfer<TRouteContext>,
|
|
401
|
+
loader?: LoaderFn<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, NoInfer<TRouteContext>, TAllContext>;
|
|
402
402
|
} & ({
|
|
403
403
|
parseParams?: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object';
|
|
404
404
|
stringifyParams?: (params: NoInfer<ParamsFallback<TPath, TParams>>) => Record<ParsePathParams<TPath>, string>;
|
|
@@ -527,12 +527,12 @@ type RouteConstraints = {
|
|
|
527
527
|
TParentContext: AnyContext;
|
|
528
528
|
TAllParentContext: AnyContext;
|
|
529
529
|
TRouteContext: RouteContext;
|
|
530
|
-
|
|
530
|
+
TAllContext: AnyContext;
|
|
531
531
|
TRouterContext: AnyContext;
|
|
532
532
|
TChildren: unknown;
|
|
533
533
|
TRouteTree: AnyRoute;
|
|
534
534
|
};
|
|
535
|
-
declare class Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, TLoader = unknown, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Record<ParsePathParams<TPath>, string>, TAllParams extends RouteConstraints['TAllParams'] = MergeParamsFromParent<TParentRoute['__types']['allParams'], TParams>, TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['__types']['routeContext'], TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['__types']['context'], TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
|
|
535
|
+
declare class Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, TLoader = unknown, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Record<ParsePathParams<TPath>, string>, TAllParams extends RouteConstraints['TAllParams'] = MergeParamsFromParent<TParentRoute['__types']['allParams'], TParams>, TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['__types']['routeContext'], TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['__types']['context'], TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends RouteConstraints['TAllContext'] = MergeParamsFromParent<TParentRoute['__types']['context'], TRouteContext>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
|
|
536
536
|
__types: {
|
|
537
537
|
parentRoute: TParentRoute;
|
|
538
538
|
path: TPath;
|
|
@@ -548,13 +548,13 @@ declare class Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyR
|
|
|
548
548
|
parentContext: TParentContext;
|
|
549
549
|
allParentContext: TAllParentContext;
|
|
550
550
|
routeContext: TRouteContext;
|
|
551
|
-
context:
|
|
551
|
+
context: TAllContext;
|
|
552
552
|
children: TChildren;
|
|
553
553
|
routeTree: TRouteTree;
|
|
554
554
|
routerContext: TRouterContext;
|
|
555
555
|
};
|
|
556
556
|
isRoot: TParentRoute extends Route<any> ? true : false;
|
|
557
|
-
options: RouteOptions<TParentRoute, TCustomId, TPath, TLoader, InferFullSearchSchema<TParentRoute>, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext,
|
|
557
|
+
options: RouteOptions<TParentRoute, TCustomId, TPath, TLoader, InferFullSearchSchema<TParentRoute>, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
|
|
558
558
|
parentRoute: TParentRoute;
|
|
559
559
|
id: TId;
|
|
560
560
|
path: TPath;
|
|
@@ -564,22 +564,22 @@ declare class Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyR
|
|
|
564
564
|
originalIndex?: number;
|
|
565
565
|
router?: AnyRouter;
|
|
566
566
|
rank: number;
|
|
567
|
-
constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TLoader, InferFullSearchSchema<TParentRoute>, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext,
|
|
567
|
+
constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TLoader, InferFullSearchSchema<TParentRoute>, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>);
|
|
568
568
|
init: (opts: {
|
|
569
569
|
originalIndex: number;
|
|
570
570
|
router: AnyRouter;
|
|
571
571
|
}) => void;
|
|
572
|
-
addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext,
|
|
573
|
-
update: (options: UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext,
|
|
572
|
+
addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext, TRouterContext, TNewChildren, TRouteTree>;
|
|
573
|
+
update: (options: UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>) => this;
|
|
574
574
|
static __onInit: (route: typeof this$1) => void;
|
|
575
575
|
}
|
|
576
576
|
type AnyRootRoute = RootRoute<any, any, any, any>;
|
|
577
577
|
declare class RouterContext<TRouterContext extends {}> {
|
|
578
578
|
constructor();
|
|
579
|
-
createRootRoute: <TLoader = unknown, TSearchSchema extends AnySearchSchema = {},
|
|
579
|
+
createRootRoute: <TLoader = unknown, TSearchSchema extends AnySearchSchema = {}, TRouteContext extends RouteContext = RouteContext>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TLoader, TSearchSchema, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, IsAny<TRouterContext, TRouteContext, TRouterContext & TRouteContext>>, "caseSensitive" | "id" | "path" | "getParentRoute" | "stringifyParams" | "parseParams"> | undefined) => RootRoute<TLoader, TSearchSchema, TRouteContext, TRouterContext>;
|
|
580
580
|
}
|
|
581
|
-
declare class RootRoute<TLoader = unknown, TSearchSchema extends AnySearchSchema = {},
|
|
582
|
-
constructor(options?: Omit<RouteOptions<AnyRoute, RootRouteId, '', TLoader, TSearchSchema, {}
|
|
581
|
+
declare class RootRoute<TLoader = unknown, TSearchSchema extends AnySearchSchema = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}> extends Route<any, '/', '/', string, RootRouteId, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, MergeParamsFromParent<TRouterContext, TRouteContext>, TRouterContext, any, any> {
|
|
582
|
+
constructor(options?: Omit<RouteOptions<AnyRoute, RootRouteId, '', TLoader, TSearchSchema, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, MergeParamsFromParent<TRouterContext, TRouteContext>>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
|
|
583
583
|
}
|
|
584
584
|
type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
|
|
585
585
|
type RoutePrefix<TPrefix extends string, TPath extends string> = string extends TPath ? RootRouteId : TPath extends string ? TPrefix extends RootRouteId ? TPath extends '/' ? '/' : `/${TrimPath<TPath>}` : `${TPrefix}/${TPath}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}` : never;
|
|
@@ -742,6 +742,6 @@ declare function decode(str: any): {};
|
|
|
742
742
|
declare const defaultParseSearch: (searchStr: string) => AnySearchSchema;
|
|
743
743
|
declare const defaultStringifySearch: (search: Record<string, any>) => string;
|
|
744
744
|
declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySearchSchema;
|
|
745
|
-
declare function stringifySearchWith(stringify: (search: any) => string): (search: Record<string, any>) => string;
|
|
745
|
+
declare function stringifySearchWith(stringify: (search: any) => string, parser?: (str: string) => any): (search: Record<string, any>) => string;
|
|
746
746
|
|
|
747
747
|
export { ActiveOptions, AllParams, AnyContext, AnyPathParams, AnyRedirect, AnyRootRoute, AnyRoute, AnyRouteMatch, AnyRouteProps, AnyRouter, AnySearchSchema, BaseRouteOptions, BuildNextOptions, CheckId, CheckIdError, CheckPath, CheckPathError, CheckRelativePath, CleanPath, ComponentFromRoute, ComponentPropsFromRoute, DeepAwaited, DefinedPathParamWarning, DehydratedRouter, DehydratedRouterState, Expand, FileRoute, FileRoutePath, FileRoutesByPath, FromLocation, FullSearchSchema, GetKeyFn, HydrationCtx, InferFullSearchSchema, IsAny, IsAnyBoolean, IsKnown, Join, Last, LinkInfo, LinkOptions, ListenerFn, LoaderContext, LoaderFn, LocationState, MatchLocation, MatchRouteOptions, MergeParamsFromParent, MergeUnion, MetaOptions, NavigateOptions, NoInfer, ParamsFallback, ParentParams, ParseParamsFn, ParseParamsObj, ParseParamsOption, ParsePathParams, ParseRoute, ParseRouteChildren, ParsedLocation, ParsedPath, PathParamError, PathParamMask, PathParamOptions, PickAsPartial, PickAsRequired, PickExclude, PickExtra, PickExtract, PickRequired, PickUnsafe, PreloadableObj, Redirect, Register, RegisterRouteComponent, RegisterRouteErrorComponent, RegisteredRouteComponent, RegisteredRouteErrorComponent, RegisteredRouter, RelativeToPathAutoComplete, RemoveUnderScores, ResolveFilePath, ResolveFullPath, ResolveFullSearchSchema, ResolveId, ResolveRelativePath, RootRoute, RootRouteId, Route, RouteById, RouteByPath, RouteConstraints, RouteContext, RouteIds, RouteLoaderFromRoute, RouteMatch, RouteMeta, RouteOptions, RoutePathOptions, RoutePathOptionsIntersection, RoutePaths, RouteProps, Router, RouterConstructorOptions, RouterContext, RouterContextOptions, RouterHistory, RouterLocation, RouterOptions, RouterState, RoutesById, RoutesByPath, SearchFilter, SearchParamError, SearchParamOptions, SearchParser, SearchSchemaValidator, SearchSchemaValidatorFn, SearchSchemaValidatorObj, SearchSerializer, Segment, Split, StreamedPromise, Timeout, ToIdOption, ToOptions, ToPathOption, Trim, TrimLeft, TrimPath, TrimPathLeft, TrimPathRight, TrimRight, UnionToIntersection, UnloaderFn, UpdatableRouteOptions, Updater, UseLoaderResult, UseLoaderResultPromise, ValueKeys, Values, cleanPath, componentTypes, createBrowserHistory, createHashHistory, createMemoryHistory, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, isPlainObject, isRedirect, joinPaths, last, lazyFn, matchByPath, matchPathname, parsePathname, parseSearchWith, partialDeepEqual, pick, redirect, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, trimPath, trimPathLeft, trimPathRight };
|
|
@@ -731,7 +731,7 @@
|
|
|
731
731
|
}
|
|
732
732
|
|
|
733
733
|
const defaultParseSearch = parseSearchWith(JSON.parse);
|
|
734
|
-
const defaultStringifySearch = stringifySearchWith(JSON.stringify);
|
|
734
|
+
const defaultStringifySearch = stringifySearchWith(JSON.stringify, JSON.parse);
|
|
735
735
|
function parseSearchWith(parser) {
|
|
736
736
|
return searchStr => {
|
|
737
737
|
if (searchStr.substring(0, 1) === '?') {
|
|
@@ -753,7 +753,26 @@
|
|
|
753
753
|
return query;
|
|
754
754
|
};
|
|
755
755
|
}
|
|
756
|
-
function stringifySearchWith(stringify) {
|
|
756
|
+
function stringifySearchWith(stringify, parser) {
|
|
757
|
+
function stringifyValue(val) {
|
|
758
|
+
if (typeof val === 'object' && val !== null) {
|
|
759
|
+
try {
|
|
760
|
+
return stringify(val);
|
|
761
|
+
} catch (err) {
|
|
762
|
+
// silent
|
|
763
|
+
}
|
|
764
|
+
} else if (typeof val === 'string' && typeof parser === 'function') {
|
|
765
|
+
try {
|
|
766
|
+
// Check if it's a valid parseable string.
|
|
767
|
+
// If it is, then stringify it again.
|
|
768
|
+
parser(val);
|
|
769
|
+
return stringify(val);
|
|
770
|
+
} catch (err) {
|
|
771
|
+
// silent
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
return val;
|
|
775
|
+
}
|
|
757
776
|
return search => {
|
|
758
777
|
search = {
|
|
759
778
|
...search
|
|
@@ -763,12 +782,10 @@
|
|
|
763
782
|
const val = search[key];
|
|
764
783
|
if (typeof val === 'undefined' || val === undefined) {
|
|
765
784
|
delete search[key];
|
|
766
|
-
} else if (val
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
// silent
|
|
771
|
-
}
|
|
785
|
+
} else if (Array.isArray(val)) {
|
|
786
|
+
search[key] = val.map(stringifyValue);
|
|
787
|
+
} else {
|
|
788
|
+
search[key] = stringifyValue(val);
|
|
772
789
|
}
|
|
773
790
|
});
|
|
774
791
|
}
|