@tanstack/router-core 0.0.1-beta.9 → 1.97.24
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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/cjs/Matches.cjs +13 -0
- package/dist/cjs/Matches.cjs.map +1 -0
- package/dist/cjs/Matches.d.cts +28 -0
- package/dist/cjs/RouterProvider.d.cts +18 -0
- package/dist/cjs/defer.cjs +25 -0
- package/dist/cjs/defer.cjs.map +1 -0
- package/dist/cjs/defer.d.cts +20 -0
- package/dist/cjs/index.cjs +50 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +25 -0
- package/dist/cjs/link.cjs +5 -0
- package/dist/cjs/link.cjs.map +1 -0
- package/dist/cjs/link.d.cts +51 -0
- package/dist/cjs/location.d.cts +12 -0
- package/dist/cjs/manifest.d.cts +24 -0
- package/dist/cjs/path.cjs +289 -0
- package/dist/cjs/path.cjs.map +1 -0
- package/dist/cjs/path.d.cts +34 -0
- package/dist/cjs/qss.cjs +51 -0
- package/dist/cjs/qss.cjs.map +1 -0
- package/dist/cjs/qss.d.cts +27 -0
- package/dist/cjs/root.cjs +5 -0
- package/dist/cjs/root.cjs.map +1 -0
- package/dist/cjs/root.d.cts +2 -0
- package/dist/cjs/route.d.cts +148 -0
- package/dist/cjs/router.cjs +19 -0
- package/dist/cjs/router.cjs.map +1 -0
- package/dist/cjs/router.d.cts +31 -0
- package/dist/cjs/searchMiddleware.cjs +42 -0
- package/dist/cjs/searchMiddleware.cjs.map +1 -0
- package/dist/cjs/searchMiddleware.d.cts +5 -0
- package/dist/cjs/searchParams.cjs +61 -0
- package/dist/cjs/searchParams.cjs.map +1 -0
- package/dist/cjs/searchParams.d.cts +7 -0
- package/dist/cjs/serializer.d.cts +15 -0
- package/dist/cjs/structuralSharing.d.cts +4 -0
- package/dist/cjs/utils.cjs +155 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +81 -0
- package/dist/cjs/validators.d.cts +51 -0
- package/dist/esm/Matches.d.ts +28 -0
- package/dist/esm/Matches.js +13 -0
- package/dist/esm/Matches.js.map +1 -0
- package/dist/esm/RouterProvider.d.ts +18 -0
- package/dist/esm/defer.d.ts +20 -0
- package/dist/esm/defer.js +25 -0
- package/dist/esm/defer.js.map +1 -0
- package/dist/esm/index.d.ts +25 -0
- package/dist/esm/index.js +50 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/link.d.ts +51 -0
- package/dist/esm/link.js +5 -0
- package/dist/esm/link.js.map +1 -0
- package/dist/esm/location.d.ts +12 -0
- package/dist/esm/manifest.d.ts +24 -0
- package/dist/esm/path.d.ts +34 -0
- package/dist/esm/path.js +289 -0
- package/dist/esm/path.js.map +1 -0
- package/dist/esm/qss.d.ts +27 -0
- package/dist/esm/qss.js +51 -0
- package/dist/esm/qss.js.map +1 -0
- package/dist/esm/root.d.ts +2 -0
- package/dist/esm/root.js +5 -0
- package/dist/esm/root.js.map +1 -0
- package/dist/esm/route.d.ts +148 -0
- package/dist/esm/router.d.ts +31 -0
- package/dist/esm/router.js +19 -0
- package/dist/esm/router.js.map +1 -0
- package/dist/esm/searchMiddleware.d.ts +5 -0
- package/dist/esm/searchMiddleware.js +42 -0
- package/dist/esm/searchMiddleware.js.map +1 -0
- package/dist/esm/searchParams.d.ts +7 -0
- package/dist/esm/searchParams.js +61 -0
- package/dist/esm/searchParams.js.map +1 -0
- package/dist/esm/serializer.d.ts +15 -0
- package/dist/esm/structuralSharing.d.ts +4 -0
- package/dist/esm/utils.d.ts +81 -0
- package/dist/esm/utils.js +155 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/validators.d.ts +51 -0
- package/package.json +35 -32
- package/src/Matches.ts +94 -0
- package/src/RouterProvider.ts +20 -0
- package/src/defer.ts +52 -0
- package/src/index.ts +206 -19
- package/src/link.ts +122 -300
- package/src/location.ts +13 -0
- package/src/manifest.ts +32 -0
- package/src/path.ts +238 -47
- package/src/qss.ts +56 -19
- package/src/root.ts +2 -0
- package/src/route.ts +296 -223
- package/src/router.ts +34 -1281
- package/src/searchMiddleware.ts +54 -0
- package/src/searchParams.ts +43 -20
- package/src/serializer.ts +24 -0
- package/src/structuralSharing.ts +7 -0
- package/src/utils.ts +314 -75
- package/src/validators.ts +121 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
- package/build/cjs/node_modules/history/index.js +0 -815
- package/build/cjs/node_modules/history/index.js.map +0 -1
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
- package/build/cjs/packages/router-core/src/index.js +0 -58
- package/build/cjs/packages/router-core/src/index.js.map +0 -1
- package/build/cjs/packages/router-core/src/path.js +0 -222
- package/build/cjs/packages/router-core/src/path.js.map +0 -1
- package/build/cjs/packages/router-core/src/qss.js +0 -71
- package/build/cjs/packages/router-core/src/qss.js.map +0 -1
- package/build/cjs/packages/router-core/src/route.js +0 -150
- package/build/cjs/packages/router-core/src/route.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeConfig.js +0 -69
- package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
- package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
- package/build/cjs/packages/router-core/src/router.js +0 -822
- package/build/cjs/packages/router-core/src/router.js.map +0 -1
- package/build/cjs/packages/router-core/src/searchParams.js +0 -70
- package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
- package/build/cjs/packages/router-core/src/utils.js +0 -125
- package/build/cjs/packages/router-core/src/utils.js.map +0 -1
- package/build/esm/index.js +0 -2481
- package/build/esm/index.js.map +0 -1
- package/build/stats-html.html +0 -4034
- package/build/stats-react.json +0 -493
- package/build/types/index.d.ts +0 -618
- package/build/umd/index.development.js +0 -2514
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -12
- package/build/umd/index.production.js.map +0 -1
- package/src/frameworks.ts +0 -12
- package/src/routeConfig.ts +0 -495
- package/src/routeInfo.ts +0 -228
- package/src/routeMatch.ts +0 -374
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Tanner Linsley
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const isMatch = (match, path) => {
|
|
4
|
+
const parts = path.split(".");
|
|
5
|
+
let part;
|
|
6
|
+
let value = match;
|
|
7
|
+
while ((part = parts.shift()) != null && value != null) {
|
|
8
|
+
value = value[part];
|
|
9
|
+
}
|
|
10
|
+
return value != null;
|
|
11
|
+
};
|
|
12
|
+
exports.isMatch = isMatch;
|
|
13
|
+
//# sourceMappingURL=Matches.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Matches.cjs","sources":["../../src/Matches.ts"],"sourcesContent":["import type { Constrain } from './utils'\n\nexport type AnyMatchAndValue = { match: any; value: any }\n\nexport type FindValueByIndex<\n TKey,\n TValue extends ReadonlyArray<any>,\n> = TKey extends `${infer TIndex extends number}` ? TValue[TIndex] : never\n\nexport type FindValueByKey<TKey, TValue> =\n TValue extends ReadonlyArray<any>\n ? FindValueByIndex<TKey, TValue>\n : TValue[TKey & keyof TValue]\n\nexport type CreateMatchAndValue<TMatch, TValue> = TValue extends any\n ? {\n match: TMatch\n value: TValue\n }\n : never\n\nexport type NextMatchAndValue<\n TKey,\n TMatchAndValue extends AnyMatchAndValue,\n> = TMatchAndValue extends any\n ? CreateMatchAndValue<\n TMatchAndValue['match'],\n FindValueByKey<TKey, TMatchAndValue['value']>\n >\n : never\n\nexport type IsMatchKeyOf<TValue> =\n TValue extends ReadonlyArray<any>\n ? number extends TValue['length']\n ? `${number}`\n : keyof TValue & `${number}`\n : TValue extends object\n ? keyof TValue & string\n : never\n\nexport type IsMatchPath<\n TParentPath extends string,\n TMatchAndValue extends AnyMatchAndValue,\n> = `${TParentPath}${IsMatchKeyOf<TMatchAndValue['value']>}`\n\nexport type IsMatchResult<\n TKey,\n TMatchAndValue extends AnyMatchAndValue,\n> = TMatchAndValue extends any\n ? TKey extends keyof TMatchAndValue['value']\n ? TMatchAndValue['match']\n : never\n : never\n\nexport type IsMatchParse<\n TPath,\n TMatchAndValue extends AnyMatchAndValue,\n TParentPath extends string = '',\n> = TPath extends `${string}.${string}`\n ? TPath extends `${infer TFirst}.${infer TRest}`\n ? IsMatchParse<\n TRest,\n NextMatchAndValue<TFirst, TMatchAndValue>,\n `${TParentPath}${TFirst}.`\n >\n : never\n : {\n path: IsMatchPath<TParentPath, TMatchAndValue>\n result: IsMatchResult<TPath, TMatchAndValue>\n }\n\nexport type IsMatch<TMatch, TPath> = IsMatchParse<\n TPath,\n TMatch extends any ? { match: TMatch; value: TMatch } : never\n>\n\n/**\n * Narrows matches based on a path\n * @experimental\n */\nexport const isMatch = <TMatch, TPath extends string>(\n match: TMatch,\n path: Constrain<TPath, IsMatch<TMatch, TPath>['path']>,\n): match is IsMatch<TMatch, TPath>['result'] => {\n const parts = (path as string).split('.')\n let part\n let value: any = match\n\n while ((part = parts.shift()) != null && value != null) {\n value = value[part]\n }\n\n return value != null\n}\n"],"names":[],"mappings":";;AAgFa,MAAA,UAAU,CACrB,OACA,SAC8C;AACxC,QAAA,QAAS,KAAgB,MAAM,GAAG;AACpC,MAAA;AACJ,MAAI,QAAa;AAEjB,UAAQ,OAAO,MAAM,MAAY,MAAA,QAAQ,SAAS,MAAM;AACtD,YAAQ,MAAM,IAAI;AAAA,EAAA;AAGpB,SAAO,SAAS;AAClB;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Constrain } from './utils.cjs';
|
|
2
|
+
export type AnyMatchAndValue = {
|
|
3
|
+
match: any;
|
|
4
|
+
value: any;
|
|
5
|
+
};
|
|
6
|
+
export type FindValueByIndex<TKey, TValue extends ReadonlyArray<any>> = TKey extends `${infer TIndex extends number}` ? TValue[TIndex] : never;
|
|
7
|
+
export type FindValueByKey<TKey, TValue> = TValue extends ReadonlyArray<any> ? FindValueByIndex<TKey, TValue> : TValue[TKey & keyof TValue];
|
|
8
|
+
export type CreateMatchAndValue<TMatch, TValue> = TValue extends any ? {
|
|
9
|
+
match: TMatch;
|
|
10
|
+
value: TValue;
|
|
11
|
+
} : never;
|
|
12
|
+
export type NextMatchAndValue<TKey, TMatchAndValue extends AnyMatchAndValue> = TMatchAndValue extends any ? CreateMatchAndValue<TMatchAndValue['match'], FindValueByKey<TKey, TMatchAndValue['value']>> : never;
|
|
13
|
+
export type IsMatchKeyOf<TValue> = TValue extends ReadonlyArray<any> ? number extends TValue['length'] ? `${number}` : keyof TValue & `${number}` : TValue extends object ? keyof TValue & string : never;
|
|
14
|
+
export type IsMatchPath<TParentPath extends string, TMatchAndValue extends AnyMatchAndValue> = `${TParentPath}${IsMatchKeyOf<TMatchAndValue['value']>}`;
|
|
15
|
+
export type IsMatchResult<TKey, TMatchAndValue extends AnyMatchAndValue> = TMatchAndValue extends any ? TKey extends keyof TMatchAndValue['value'] ? TMatchAndValue['match'] : never : never;
|
|
16
|
+
export type IsMatchParse<TPath, TMatchAndValue extends AnyMatchAndValue, TParentPath extends string = ''> = TPath extends `${string}.${string}` ? TPath extends `${infer TFirst}.${infer TRest}` ? IsMatchParse<TRest, NextMatchAndValue<TFirst, TMatchAndValue>, `${TParentPath}${TFirst}.`> : never : {
|
|
17
|
+
path: IsMatchPath<TParentPath, TMatchAndValue>;
|
|
18
|
+
result: IsMatchResult<TPath, TMatchAndValue>;
|
|
19
|
+
};
|
|
20
|
+
export type IsMatch<TMatch, TPath> = IsMatchParse<TPath, TMatch extends any ? {
|
|
21
|
+
match: TMatch;
|
|
22
|
+
value: TMatch;
|
|
23
|
+
} : never>;
|
|
24
|
+
/**
|
|
25
|
+
* Narrows matches based on a path
|
|
26
|
+
* @experimental
|
|
27
|
+
*/
|
|
28
|
+
export declare const isMatch: <TMatch, TPath extends string>(match: TMatch, path: Constrain<TPath, IsMatch<TMatch, TPath>["path"]>) => match is IsMatch<TMatch, TPath>["result"];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ViewTransitionOptions } from './router.cjs';
|
|
2
|
+
export interface MatchLocation {
|
|
3
|
+
to?: string | number | null;
|
|
4
|
+
fuzzy?: boolean;
|
|
5
|
+
caseSensitive?: boolean;
|
|
6
|
+
from?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CommitLocationOptions {
|
|
9
|
+
replace?: boolean;
|
|
10
|
+
resetScroll?: boolean;
|
|
11
|
+
hashScrollIntoView?: boolean | ScrollIntoViewOptions;
|
|
12
|
+
viewTransition?: boolean | ViewTransitionOptions;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated All navigations use React transitions under the hood now
|
|
15
|
+
**/
|
|
16
|
+
startTransition?: boolean;
|
|
17
|
+
ignoreBlocker?: boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const router = require("./router.cjs");
|
|
4
|
+
const TSR_DEFERRED_PROMISE = Symbol.for("TSR_DEFERRED_PROMISE");
|
|
5
|
+
function defer(_promise, options) {
|
|
6
|
+
const promise = _promise;
|
|
7
|
+
if (promise[TSR_DEFERRED_PROMISE]) {
|
|
8
|
+
return promise;
|
|
9
|
+
}
|
|
10
|
+
promise[TSR_DEFERRED_PROMISE] = { status: "pending" };
|
|
11
|
+
promise.then((data) => {
|
|
12
|
+
promise[TSR_DEFERRED_PROMISE].status = "success";
|
|
13
|
+
promise[TSR_DEFERRED_PROMISE].data = data;
|
|
14
|
+
}).catch((error) => {
|
|
15
|
+
promise[TSR_DEFERRED_PROMISE].status = "error";
|
|
16
|
+
promise[TSR_DEFERRED_PROMISE].error = {
|
|
17
|
+
data: ((options == null ? void 0 : options.serializeError) ?? router.defaultSerializeError)(error),
|
|
18
|
+
__isServerError: true
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
return promise;
|
|
22
|
+
}
|
|
23
|
+
exports.TSR_DEFERRED_PROMISE = TSR_DEFERRED_PROMISE;
|
|
24
|
+
exports.defer = defer;
|
|
25
|
+
//# sourceMappingURL=defer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defer.cjs","sources":["../../src/defer.ts"],"sourcesContent":["import { defaultSerializeError } from './router'\n\nexport const TSR_DEFERRED_PROMISE = Symbol.for('TSR_DEFERRED_PROMISE')\n\nexport type DeferredPromiseState<T> =\n | {\n status: 'pending'\n data?: T\n error?: unknown\n }\n | {\n status: 'success'\n data: T\n }\n | {\n status: 'error'\n data?: T\n error: unknown\n }\n\nexport type DeferredPromise<T> = Promise<T> & {\n [TSR_DEFERRED_PROMISE]: DeferredPromiseState<T>\n}\n\nexport function defer<T>(\n _promise: Promise<T>,\n options?: {\n serializeError?: typeof defaultSerializeError\n },\n) {\n const promise = _promise as DeferredPromise<T>\n // this is already deferred promise\n if ((promise as any)[TSR_DEFERRED_PROMISE]) {\n return promise\n }\n promise[TSR_DEFERRED_PROMISE] = { status: 'pending' }\n\n promise\n .then((data) => {\n promise[TSR_DEFERRED_PROMISE].status = 'success'\n promise[TSR_DEFERRED_PROMISE].data = data\n })\n .catch((error) => {\n promise[TSR_DEFERRED_PROMISE].status = 'error'\n ;(promise[TSR_DEFERRED_PROMISE] as any).error = {\n data: (options?.serializeError ?? defaultSerializeError)(error),\n __isServerError: true,\n }\n })\n\n return promise\n}\n"],"names":["defaultSerializeError"],"mappings":";;;AAEa,MAAA,uBAAuB,OAAO,IAAI,sBAAsB;AAsBrD,SAAA,MACd,UACA,SAGA;AACA,QAAM,UAAU;AAEX,MAAA,QAAgB,oBAAoB,GAAG;AACnC,WAAA;AAAA,EAAA;AAET,UAAQ,oBAAoB,IAAI,EAAE,QAAQ,UAAU;AAGjD,UAAA,KAAK,CAAC,SAAS;AACN,YAAA,oBAAoB,EAAE,SAAS;AAC/B,YAAA,oBAAoB,EAAE,OAAO;AAAA,EAAA,CACtC,EACA,MAAM,CAAC,UAAU;AACR,YAAA,oBAAoB,EAAE,SAAS;AACrC,YAAQ,oBAAoB,EAAU,QAAQ;AAAA,MAC9C,QAAO,mCAAS,mBAAkBA,OAAAA,uBAAuB,KAAK;AAAA,MAC9D,iBAAiB;AAAA,IACnB;AAAA,EAAA,CACD;AAEI,SAAA;AACT;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defaultSerializeError } from './router.cjs';
|
|
2
|
+
export declare const TSR_DEFERRED_PROMISE: unique symbol;
|
|
3
|
+
export type DeferredPromiseState<T> = {
|
|
4
|
+
status: 'pending';
|
|
5
|
+
data?: T;
|
|
6
|
+
error?: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
status: 'success';
|
|
9
|
+
data: T;
|
|
10
|
+
} | {
|
|
11
|
+
status: 'error';
|
|
12
|
+
data?: T;
|
|
13
|
+
error: unknown;
|
|
14
|
+
};
|
|
15
|
+
export type DeferredPromise<T> = Promise<T> & {
|
|
16
|
+
[TSR_DEFERRED_PROMISE]: DeferredPromiseState<T>;
|
|
17
|
+
};
|
|
18
|
+
export declare function defer<T>(_promise: Promise<T>, options?: {
|
|
19
|
+
serializeError?: typeof defaultSerializeError;
|
|
20
|
+
}): DeferredPromise<T>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const defer = require("./defer.cjs");
|
|
4
|
+
const link = require("./link.cjs");
|
|
5
|
+
const Matches = require("./Matches.cjs");
|
|
6
|
+
const path = require("./path.cjs");
|
|
7
|
+
const qss = require("./qss.cjs");
|
|
8
|
+
const root = require("./root.cjs");
|
|
9
|
+
const router = require("./router.cjs");
|
|
10
|
+
const searchMiddleware = require("./searchMiddleware.cjs");
|
|
11
|
+
const searchParams = require("./searchParams.cjs");
|
|
12
|
+
const utils = require("./utils.cjs");
|
|
13
|
+
exports.TSR_DEFERRED_PROMISE = defer.TSR_DEFERRED_PROMISE;
|
|
14
|
+
exports.defer = defer.defer;
|
|
15
|
+
exports.preloadWarning = link.preloadWarning;
|
|
16
|
+
exports.isMatch = Matches.isMatch;
|
|
17
|
+
exports.cleanPath = path.cleanPath;
|
|
18
|
+
exports.exactPathTest = path.exactPathTest;
|
|
19
|
+
exports.interpolatePath = path.interpolatePath;
|
|
20
|
+
exports.joinPaths = path.joinPaths;
|
|
21
|
+
exports.matchByPath = path.matchByPath;
|
|
22
|
+
exports.matchPathname = path.matchPathname;
|
|
23
|
+
exports.parsePathname = path.parsePathname;
|
|
24
|
+
exports.removeBasepath = path.removeBasepath;
|
|
25
|
+
exports.removeTrailingSlash = path.removeTrailingSlash;
|
|
26
|
+
exports.resolvePath = path.resolvePath;
|
|
27
|
+
exports.trimPath = path.trimPath;
|
|
28
|
+
exports.trimPathLeft = path.trimPathLeft;
|
|
29
|
+
exports.trimPathRight = path.trimPathRight;
|
|
30
|
+
exports.decode = qss.decode;
|
|
31
|
+
exports.encode = qss.encode;
|
|
32
|
+
exports.rootRouteId = root.rootRouteId;
|
|
33
|
+
exports.defaultSerializeError = router.defaultSerializeError;
|
|
34
|
+
exports.retainSearchParams = searchMiddleware.retainSearchParams;
|
|
35
|
+
exports.stripSearchParams = searchMiddleware.stripSearchParams;
|
|
36
|
+
exports.defaultParseSearch = searchParams.defaultParseSearch;
|
|
37
|
+
exports.defaultStringifySearch = searchParams.defaultStringifySearch;
|
|
38
|
+
exports.parseSearchWith = searchParams.parseSearchWith;
|
|
39
|
+
exports.stringifySearchWith = searchParams.stringifySearchWith;
|
|
40
|
+
exports.createControlledPromise = utils.createControlledPromise;
|
|
41
|
+
exports.deepEqual = utils.deepEqual;
|
|
42
|
+
exports.escapeJSON = utils.escapeJSON;
|
|
43
|
+
exports.functionalUpdate = utils.functionalUpdate;
|
|
44
|
+
exports.isPlainArray = utils.isPlainArray;
|
|
45
|
+
exports.isPlainObject = utils.isPlainObject;
|
|
46
|
+
exports.last = utils.last;
|
|
47
|
+
exports.pick = utils.pick;
|
|
48
|
+
exports.replaceEqualDeep = utils.replaceEqualDeep;
|
|
49
|
+
exports.shallow = utils.shallow;
|
|
50
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { TSR_DEFERRED_PROMISE, defer } from './defer.cjs';
|
|
2
|
+
export type { DeferredPromiseState, DeferredPromise } from './defer.cjs';
|
|
3
|
+
export { preloadWarning } from './link.cjs';
|
|
4
|
+
export type { IsRequiredParams, ParsePathParams, AddTrailingSlash, RemoveTrailingSlashes, AddLeadingSlash, RemoveLeadingSlashes, ActiveOptions, LinkOptionsProps, ResolveCurrentPath, ResolveParentPath, ResolveRelativePath, LinkCurrentTargetElement, } from './link.cjs';
|
|
5
|
+
export type { StartSerializer, Serializable, SerializerParse, SerializerParseBy, SerializerStringify, SerializerStringifyBy, } from './serializer.cjs';
|
|
6
|
+
export type { ParsedLocation } from './location.cjs';
|
|
7
|
+
export type { Manifest, RouterManagedTag } from './manifest.cjs';
|
|
8
|
+
export { isMatch } from './Matches.cjs';
|
|
9
|
+
export type { AnyMatchAndValue, FindValueByIndex, FindValueByKey, CreateMatchAndValue, NextMatchAndValue, IsMatchKeyOf, IsMatchPath, IsMatchResult, IsMatchParse, IsMatch, } from './Matches.cjs';
|
|
10
|
+
export { joinPaths, cleanPath, trimPathLeft, trimPathRight, trimPath, removeTrailingSlash, exactPathTest, resolvePath, parsePathname, interpolatePath, matchPathname, removeBasepath, matchByPath, } from './path.cjs';
|
|
11
|
+
export type { Segment } from './path.cjs';
|
|
12
|
+
export { encode, decode } from './qss.cjs';
|
|
13
|
+
export { rootRouteId } from './root.cjs';
|
|
14
|
+
export type { RootRouteId } from './root.cjs';
|
|
15
|
+
export type { AnyPathParams, SearchSchemaInput, AnyContext, RouteContext, PreloadableObj, RoutePathOptions, StaticDataRouteOption, RoutePathOptionsIntersection, SearchFilter, SearchMiddlewareContext, SearchMiddleware, ResolveId, InferFullSearchSchema, InferFullSearchSchemaInput, InferAllParams, InferAllContext, MetaDescriptor, RouteLinkEntry, SearchValidator, AnySearchValidator, DefaultSearchValidator, ErrorRouteProps, ErrorComponentProps, NotFoundRouteProps, ParseSplatParams, SplatParams, ResolveParams, ParseParamsFn, StringifyParamsFn, ParamsOptions, UpdatableStaticRouteOption, LooseReturnType, LooseAsyncReturnType, ContextReturnType, ContextAsyncReturnType, ResolveRouteContext, ResolveLoaderData, RoutePrefix, TrimPath, TrimPathLeft, TrimPathRight, ResolveSearchSchemaFnInput, ResolveSearchSchemaInput, ResolveSearchSchemaFn, ResolveSearchSchema, } from './route.cjs';
|
|
16
|
+
export { defaultSerializeError } from './router.cjs';
|
|
17
|
+
export type { ViewTransitionOptions, ExtractedBaseEntry, ExtractedStream, ExtractedPromise, ExtractedEntry, StreamState, TrailingSlashOption, } from './router.cjs';
|
|
18
|
+
export type { MatchLocation, CommitLocationOptions } from './RouterProvider.cjs';
|
|
19
|
+
export { retainSearchParams, stripSearchParams } from './searchMiddleware.cjs';
|
|
20
|
+
export { defaultParseSearch, defaultStringifySearch, parseSearchWith, stringifySearchWith, } from './searchParams.cjs';
|
|
21
|
+
export type { SearchSerializer, SearchParser } from './searchParams.cjs';
|
|
22
|
+
export type { OptionalStructuralSharing } from './structuralSharing.cjs';
|
|
23
|
+
export { last, functionalUpdate, pick, replaceEqualDeep, isPlainObject, isPlainArray, deepEqual, escapeJSON, shallow, createControlledPromise, } from './utils.cjs';
|
|
24
|
+
export type { NoInfer, IsAny, PickAsRequired, PickRequired, PickOptional, WithoutEmpty, Expand, DeepPartial, MakeDifferenceOptional, IsUnion, IsNonEmptyObject, Assign, IntersectAssign, Timeout, Updater, NonNullableUpdater, StringLiteral, ThrowOrOptional, ControlledPromise, ExtractObjects, PartialMergeAllObject, MergeAllPrimitive, ExtractPrimitives, PartialMergeAll, Constrain, ConstrainLiteral, UnionToIntersection, MergeAllObjects, MergeAll, ValidateJSON, } from './utils.cjs';
|
|
25
|
+
export type { StandardSchemaValidatorProps, StandardSchemaValidator, AnyStandardSchemaValidator, StandardSchemaValidatorTypes, AnyStandardSchemaValidateSuccess, AnyStandardSchemaValidateFailure, AnyStandardSchemaValidateIssue, AnyStandardSchemaValidateInput, AnyStandardSchemaValidate, ValidatorObj, AnyValidatorObj, ValidatorAdapter, AnyValidatorAdapter, AnyValidatorFn, ValidatorFn, Validator, AnyValidator, AnySchema, DefaultValidator, ResolveSearchValidatorInputFn, ResolveSearchValidatorInput, ResolveValidatorInputFn, ResolveValidatorInput, ResolveValidatorOutputFn, ResolveValidatorOutput, } from './validators.cjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link.cjs","sources":["../../src/link.ts"],"sourcesContent":["export type IsRequiredParams<TParams> =\n Record<never, never> extends TParams ? never : true\n\nexport type ParsePathParams<T extends string, TAcc = never> = T &\n `${string}$${string}` extends never\n ? TAcc\n : T extends `${string}$${infer TPossiblyParam}`\n ? TPossiblyParam extends ''\n ? TAcc\n : TPossiblyParam & `${string}/${string}` extends never\n ? TPossiblyParam | TAcc\n : TPossiblyParam extends `${infer TParam}/${infer TRest}`\n ? ParsePathParams<TRest, TParam extends '' ? TAcc : TParam | TAcc>\n : never\n : TAcc\n\nexport type AddTrailingSlash<T> = T & `${string}/` extends never\n ? `${T & string}/`\n : T\n\nexport type RemoveTrailingSlashes<T> = T & `${string}/` extends never\n ? T\n : T extends `${infer R}/`\n ? R\n : T\n\nexport type AddLeadingSlash<T> = T & `/${string}` extends never\n ? `/${T & string}`\n : T\n\nexport type RemoveLeadingSlashes<T> = T & `/${string}` extends never\n ? T\n : T extends `/${infer R}`\n ? R\n : T\n\nexport interface ActiveOptions {\n exact?: boolean\n includeHash?: boolean\n includeSearch?: boolean\n explicitUndefined?: boolean\n}\n\nexport interface LinkOptionsProps {\n /**\n * The standard anchor tag target attribute\n */\n target?: HTMLAnchorElement['target']\n /**\n * Configurable options to determine if the link should be considered active or not\n * @default {exact:true,includeHash:true}\n */\n activeOptions?: ActiveOptions\n /**\n * The preloading strategy for this link\n * - `false` - No preloading\n * - `'intent'` - Preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.\n * - `'viewport'` - Preload the linked route when it enters the viewport\n */\n preload?: false | 'intent' | 'viewport' | 'render'\n /**\n * When a preload strategy is set, this delays the preload by this many milliseconds.\n * If the user exits the link before this delay, the preload will be cancelled.\n */\n preloadDelay?: number\n /**\n * Control whether the link should be disabled or not\n * If set to `true`, the link will be rendered without an `href` attribute\n * @default false\n */\n disabled?: boolean\n}\n\ntype JoinPath<TLeft extends string, TRight extends string> = TRight extends ''\n ? TLeft\n : TLeft extends ''\n ? TRight\n : `${RemoveTrailingSlashes<TLeft>}/${RemoveLeadingSlashes<TRight>}`\n\ntype RemoveLastSegment<\n T extends string,\n TAcc extends string = '',\n> = T extends `${infer TSegment}/${infer TRest}`\n ? TRest & `${string}/${string}` extends never\n ? TRest extends ''\n ? TAcc\n : `${TAcc}${TSegment}`\n : RemoveLastSegment<TRest, `${TAcc}${TSegment}/`>\n : TAcc\n\nexport type ResolveCurrentPath<\n TFrom extends string,\n TTo extends string,\n> = TTo extends '.'\n ? TFrom\n : TTo extends './'\n ? AddTrailingSlash<TFrom>\n : TTo & `./${string}` extends never\n ? never\n : TTo extends `./${infer TRest}`\n ? AddLeadingSlash<JoinPath<TFrom, TRest>>\n : never\n\nexport type ResolveParentPath<\n TFrom extends string,\n TTo extends string,\n> = TTo extends '../' | '..'\n ? TFrom extends '' | '/'\n ? never\n : AddLeadingSlash<RemoveLastSegment<TFrom>>\n : TTo & `../${string}` extends never\n ? AddLeadingSlash<JoinPath<TFrom, TTo>>\n : TFrom extends '' | '/'\n ? never\n : TTo extends `../${infer ToRest}`\n ? ResolveParentPath<RemoveLastSegment<TFrom>, ToRest>\n : AddLeadingSlash<JoinPath<TFrom, TTo>>\n\nexport type ResolveRelativePath<TFrom, TTo = '.'> = string extends TFrom\n ? TTo\n : string extends TTo\n ? TFrom\n : undefined extends TTo\n ? TFrom\n : TTo extends string\n ? TFrom extends string\n ? TTo extends `/${string}`\n ? TTo\n : TTo extends `..${string}`\n ? ResolveParentPath<TFrom, TTo>\n : TTo extends `.${string}`\n ? ResolveCurrentPath<TFrom, TTo>\n : AddLeadingSlash<JoinPath<TFrom, TTo>>\n : never\n : never\n\nexport type LinkCurrentTargetElement = {\n preloadTimeout?: null | ReturnType<typeof setTimeout>\n}\n\nexport const preloadWarning = 'Error preloading route! ☝️'\n"],"names":[],"mappings":";;AA4IO,MAAM,iBAAiB;;"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type IsRequiredParams<TParams> = Record<never, never> extends TParams ? never : true;
|
|
2
|
+
export type ParsePathParams<T extends string, TAcc = never> = T & `${string}$${string}` extends never ? TAcc : T extends `${string}$${infer TPossiblyParam}` ? TPossiblyParam extends '' ? TAcc : TPossiblyParam & `${string}/${string}` extends never ? TPossiblyParam | TAcc : TPossiblyParam extends `${infer TParam}/${infer TRest}` ? ParsePathParams<TRest, TParam extends '' ? TAcc : TParam | TAcc> : never : TAcc;
|
|
3
|
+
export type AddTrailingSlash<T> = T & `${string}/` extends never ? `${T & string}/` : T;
|
|
4
|
+
export type RemoveTrailingSlashes<T> = T & `${string}/` extends never ? T : T extends `${infer R}/` ? R : T;
|
|
5
|
+
export type AddLeadingSlash<T> = T & `/${string}` extends never ? `/${T & string}` : T;
|
|
6
|
+
export type RemoveLeadingSlashes<T> = T & `/${string}` extends never ? T : T extends `/${infer R}` ? R : T;
|
|
7
|
+
export interface ActiveOptions {
|
|
8
|
+
exact?: boolean;
|
|
9
|
+
includeHash?: boolean;
|
|
10
|
+
includeSearch?: boolean;
|
|
11
|
+
explicitUndefined?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface LinkOptionsProps {
|
|
14
|
+
/**
|
|
15
|
+
* The standard anchor tag target attribute
|
|
16
|
+
*/
|
|
17
|
+
target?: HTMLAnchorElement['target'];
|
|
18
|
+
/**
|
|
19
|
+
* Configurable options to determine if the link should be considered active or not
|
|
20
|
+
* @default {exact:true,includeHash:true}
|
|
21
|
+
*/
|
|
22
|
+
activeOptions?: ActiveOptions;
|
|
23
|
+
/**
|
|
24
|
+
* The preloading strategy for this link
|
|
25
|
+
* - `false` - No preloading
|
|
26
|
+
* - `'intent'` - Preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.
|
|
27
|
+
* - `'viewport'` - Preload the linked route when it enters the viewport
|
|
28
|
+
*/
|
|
29
|
+
preload?: false | 'intent' | 'viewport' | 'render';
|
|
30
|
+
/**
|
|
31
|
+
* When a preload strategy is set, this delays the preload by this many milliseconds.
|
|
32
|
+
* If the user exits the link before this delay, the preload will be cancelled.
|
|
33
|
+
*/
|
|
34
|
+
preloadDelay?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Control whether the link should be disabled or not
|
|
37
|
+
* If set to `true`, the link will be rendered without an `href` attribute
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
disabled?: boolean;
|
|
41
|
+
}
|
|
42
|
+
type JoinPath<TLeft extends string, TRight extends string> = TRight extends '' ? TLeft : TLeft extends '' ? TRight : `${RemoveTrailingSlashes<TLeft>}/${RemoveLeadingSlashes<TRight>}`;
|
|
43
|
+
type RemoveLastSegment<T extends string, TAcc extends string = ''> = T extends `${infer TSegment}/${infer TRest}` ? TRest & `${string}/${string}` extends never ? TRest extends '' ? TAcc : `${TAcc}${TSegment}` : RemoveLastSegment<TRest, `${TAcc}${TSegment}/`> : TAcc;
|
|
44
|
+
export type ResolveCurrentPath<TFrom extends string, TTo extends string> = TTo extends '.' ? TFrom : TTo extends './' ? AddTrailingSlash<TFrom> : TTo & `./${string}` extends never ? never : TTo extends `./${infer TRest}` ? AddLeadingSlash<JoinPath<TFrom, TRest>> : never;
|
|
45
|
+
export type ResolveParentPath<TFrom extends string, TTo extends string> = TTo extends '../' | '..' ? TFrom extends '' | '/' ? never : AddLeadingSlash<RemoveLastSegment<TFrom>> : TTo & `../${string}` extends never ? AddLeadingSlash<JoinPath<TFrom, TTo>> : TFrom extends '' | '/' ? never : TTo extends `../${infer ToRest}` ? ResolveParentPath<RemoveLastSegment<TFrom>, ToRest> : AddLeadingSlash<JoinPath<TFrom, TTo>>;
|
|
46
|
+
export type ResolveRelativePath<TFrom, TTo = '.'> = string extends TFrom ? TTo : string extends TTo ? TFrom : undefined extends TTo ? TFrom : TTo extends string ? TFrom extends string ? TTo extends `/${string}` ? TTo : TTo extends `..${string}` ? ResolveParentPath<TFrom, TTo> : TTo extends `.${string}` ? ResolveCurrentPath<TFrom, TTo> : AddLeadingSlash<JoinPath<TFrom, TTo>> : never : never;
|
|
47
|
+
export type LinkCurrentTargetElement = {
|
|
48
|
+
preloadTimeout?: null | ReturnType<typeof setTimeout>;
|
|
49
|
+
};
|
|
50
|
+
export declare const preloadWarning = "Error preloading route! \u261D\uFE0F";
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ParsedHistoryState } from '@tanstack/history';
|
|
2
|
+
import { AnySchema } from './validators.cjs';
|
|
3
|
+
export interface ParsedLocation<TSearchObj extends AnySchema = {}> {
|
|
4
|
+
href: string;
|
|
5
|
+
pathname: string;
|
|
6
|
+
search: TSearchObj;
|
|
7
|
+
searchStr: string;
|
|
8
|
+
state: ParsedHistoryState;
|
|
9
|
+
hash: string;
|
|
10
|
+
maskedLocation?: ParsedLocation<TSearchObj>;
|
|
11
|
+
unmaskOnReload?: boolean;
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type Manifest = {
|
|
2
|
+
routes: Record<string, {
|
|
3
|
+
filePath?: string;
|
|
4
|
+
preloads?: Array<string>;
|
|
5
|
+
assets?: Array<RouterManagedTag>;
|
|
6
|
+
}>;
|
|
7
|
+
};
|
|
8
|
+
export type RouterManagedTag = {
|
|
9
|
+
tag: 'title';
|
|
10
|
+
attrs?: Record<string, any>;
|
|
11
|
+
children: string;
|
|
12
|
+
} | {
|
|
13
|
+
tag: 'meta' | 'link';
|
|
14
|
+
attrs?: Record<string, any>;
|
|
15
|
+
children?: never;
|
|
16
|
+
} | {
|
|
17
|
+
tag: 'script';
|
|
18
|
+
attrs?: Record<string, any>;
|
|
19
|
+
children?: string;
|
|
20
|
+
} | {
|
|
21
|
+
tag: 'style';
|
|
22
|
+
attrs?: Record<string, any>;
|
|
23
|
+
children?: string;
|
|
24
|
+
};
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const utils = require("./utils.cjs");
|
|
4
|
+
function joinPaths(paths) {
|
|
5
|
+
return cleanPath(
|
|
6
|
+
paths.filter((val) => {
|
|
7
|
+
return val !== void 0;
|
|
8
|
+
}).join("/")
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
function cleanPath(path) {
|
|
12
|
+
return path.replace(/\/{2,}/g, "/");
|
|
13
|
+
}
|
|
14
|
+
function trimPathLeft(path) {
|
|
15
|
+
return path === "/" ? path : path.replace(/^\/{1,}/, "");
|
|
16
|
+
}
|
|
17
|
+
function trimPathRight(path) {
|
|
18
|
+
return path === "/" ? path : path.replace(/\/{1,}$/, "");
|
|
19
|
+
}
|
|
20
|
+
function trimPath(path) {
|
|
21
|
+
return trimPathRight(trimPathLeft(path));
|
|
22
|
+
}
|
|
23
|
+
function removeTrailingSlash(value, basepath) {
|
|
24
|
+
if (value.endsWith("/") && value !== "/" && value !== `${basepath}/`) {
|
|
25
|
+
return value.slice(0, -1);
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
function exactPathTest(pathName1, pathName2, basepath) {
|
|
30
|
+
return removeTrailingSlash(pathName1, basepath) === removeTrailingSlash(pathName2, basepath);
|
|
31
|
+
}
|
|
32
|
+
function resolvePath({
|
|
33
|
+
basepath,
|
|
34
|
+
base,
|
|
35
|
+
to,
|
|
36
|
+
trailingSlash = "never",
|
|
37
|
+
caseSensitive
|
|
38
|
+
}) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
base = removeBasepath(basepath, base, caseSensitive);
|
|
41
|
+
to = removeBasepath(basepath, to, caseSensitive);
|
|
42
|
+
let baseSegments = parsePathname(base);
|
|
43
|
+
const toSegments = parsePathname(to);
|
|
44
|
+
if (baseSegments.length > 1 && ((_a = utils.last(baseSegments)) == null ? void 0 : _a.value) === "/") {
|
|
45
|
+
baseSegments.pop();
|
|
46
|
+
}
|
|
47
|
+
toSegments.forEach((toSegment, index) => {
|
|
48
|
+
if (toSegment.value === "/") {
|
|
49
|
+
if (!index) {
|
|
50
|
+
baseSegments = [toSegment];
|
|
51
|
+
} else if (index === toSegments.length - 1) {
|
|
52
|
+
baseSegments.push(toSegment);
|
|
53
|
+
} else ;
|
|
54
|
+
} else if (toSegment.value === "..") {
|
|
55
|
+
baseSegments.pop();
|
|
56
|
+
} else if (toSegment.value === ".") ;
|
|
57
|
+
else {
|
|
58
|
+
baseSegments.push(toSegment);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
if (baseSegments.length > 1) {
|
|
62
|
+
if (((_b = utils.last(baseSegments)) == null ? void 0 : _b.value) === "/") {
|
|
63
|
+
if (trailingSlash === "never") {
|
|
64
|
+
baseSegments.pop();
|
|
65
|
+
}
|
|
66
|
+
} else if (trailingSlash === "always") {
|
|
67
|
+
baseSegments.push({ type: "pathname", value: "/" });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const joined = joinPaths([basepath, ...baseSegments.map((d) => d.value)]);
|
|
71
|
+
return cleanPath(joined);
|
|
72
|
+
}
|
|
73
|
+
function parsePathname(pathname) {
|
|
74
|
+
if (!pathname) {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
pathname = cleanPath(pathname);
|
|
78
|
+
const segments = [];
|
|
79
|
+
if (pathname.slice(0, 1) === "/") {
|
|
80
|
+
pathname = pathname.substring(1);
|
|
81
|
+
segments.push({
|
|
82
|
+
type: "pathname",
|
|
83
|
+
value: "/"
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (!pathname) {
|
|
87
|
+
return segments;
|
|
88
|
+
}
|
|
89
|
+
const split = pathname.split("/").filter(Boolean);
|
|
90
|
+
segments.push(
|
|
91
|
+
...split.map((part) => {
|
|
92
|
+
if (part === "$" || part === "*") {
|
|
93
|
+
return {
|
|
94
|
+
type: "wildcard",
|
|
95
|
+
value: part
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (part.charAt(0) === "$") {
|
|
99
|
+
return {
|
|
100
|
+
type: "param",
|
|
101
|
+
value: part
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
type: "pathname",
|
|
106
|
+
value: decodeURI(part)
|
|
107
|
+
};
|
|
108
|
+
})
|
|
109
|
+
);
|
|
110
|
+
if (pathname.slice(-1) === "/") {
|
|
111
|
+
pathname = pathname.substring(1);
|
|
112
|
+
segments.push({
|
|
113
|
+
type: "pathname",
|
|
114
|
+
value: "/"
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return segments;
|
|
118
|
+
}
|
|
119
|
+
function interpolatePath({
|
|
120
|
+
path,
|
|
121
|
+
params,
|
|
122
|
+
leaveWildcards,
|
|
123
|
+
leaveParams,
|
|
124
|
+
decodeCharMap
|
|
125
|
+
}) {
|
|
126
|
+
const interpolatedPathSegments = parsePathname(path);
|
|
127
|
+
const encodedParams = {};
|
|
128
|
+
for (const [key, value] of Object.entries(params)) {
|
|
129
|
+
const isValueString = typeof value === "string";
|
|
130
|
+
if (["*", "_splat"].includes(key)) {
|
|
131
|
+
encodedParams[key] = isValueString ? encodeURI(value) : value;
|
|
132
|
+
} else {
|
|
133
|
+
encodedParams[key] = isValueString ? encodePathParam(value, decodeCharMap) : value;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return joinPaths(
|
|
137
|
+
interpolatedPathSegments.map((segment) => {
|
|
138
|
+
if (segment.type === "wildcard") {
|
|
139
|
+
const value = encodedParams._splat;
|
|
140
|
+
if (leaveWildcards) return `${segment.value}${value ?? ""}`;
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
if (segment.type === "param") {
|
|
144
|
+
if (leaveParams) {
|
|
145
|
+
const value = encodedParams[segment.value];
|
|
146
|
+
return `${segment.value}${value ?? ""}`;
|
|
147
|
+
}
|
|
148
|
+
return encodedParams[segment.value.substring(1)] ?? "undefined";
|
|
149
|
+
}
|
|
150
|
+
return segment.value;
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
function encodePathParam(value, decodeCharMap) {
|
|
155
|
+
let encoded = encodeURIComponent(value);
|
|
156
|
+
if (decodeCharMap) {
|
|
157
|
+
for (const [encodedChar, char] of decodeCharMap) {
|
|
158
|
+
encoded = encoded.replaceAll(encodedChar, char);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return encoded;
|
|
162
|
+
}
|
|
163
|
+
function matchPathname(basepath, currentPathname, matchLocation) {
|
|
164
|
+
const pathParams = matchByPath(basepath, currentPathname, matchLocation);
|
|
165
|
+
if (matchLocation.to && !pathParams) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
return pathParams ?? {};
|
|
169
|
+
}
|
|
170
|
+
function removeBasepath(basepath, pathname, caseSensitive = false) {
|
|
171
|
+
const normalizedBasepath = caseSensitive ? basepath : basepath.toLowerCase();
|
|
172
|
+
const normalizedPathname = caseSensitive ? pathname : pathname.toLowerCase();
|
|
173
|
+
switch (true) {
|
|
174
|
+
// default behaviour is to serve app from the root - pathname
|
|
175
|
+
// left untouched
|
|
176
|
+
case normalizedBasepath === "/":
|
|
177
|
+
return pathname;
|
|
178
|
+
// shortcut for removing the basepath if it matches the pathname
|
|
179
|
+
case normalizedPathname === normalizedBasepath:
|
|
180
|
+
return "";
|
|
181
|
+
// in case pathname is shorter than basepath - there is
|
|
182
|
+
// nothing to remove
|
|
183
|
+
case pathname.length < basepath.length:
|
|
184
|
+
return pathname;
|
|
185
|
+
// avoid matching partial segments - strict equality handled
|
|
186
|
+
// earlier, otherwise, basepath separated from pathname with
|
|
187
|
+
// separator, therefore lack of separator means partial
|
|
188
|
+
// segment match (`/app` should not match `/application`)
|
|
189
|
+
case normalizedPathname[normalizedBasepath.length] !== "/":
|
|
190
|
+
return pathname;
|
|
191
|
+
// remove the basepath from the pathname if it starts with it
|
|
192
|
+
case normalizedPathname.startsWith(normalizedBasepath):
|
|
193
|
+
return pathname.slice(basepath.length);
|
|
194
|
+
// otherwise, return the pathname as is
|
|
195
|
+
default:
|
|
196
|
+
return pathname;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function matchByPath(basepath, from, matchLocation) {
|
|
200
|
+
if (basepath !== "/" && !from.startsWith(basepath)) {
|
|
201
|
+
return void 0;
|
|
202
|
+
}
|
|
203
|
+
from = removeBasepath(basepath, from, matchLocation.caseSensitive);
|
|
204
|
+
const to = removeBasepath(
|
|
205
|
+
basepath,
|
|
206
|
+
`${matchLocation.to ?? "$"}`,
|
|
207
|
+
matchLocation.caseSensitive
|
|
208
|
+
);
|
|
209
|
+
const baseSegments = parsePathname(from);
|
|
210
|
+
const routeSegments = parsePathname(to);
|
|
211
|
+
if (!from.startsWith("/")) {
|
|
212
|
+
baseSegments.unshift({
|
|
213
|
+
type: "pathname",
|
|
214
|
+
value: "/"
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
if (!to.startsWith("/")) {
|
|
218
|
+
routeSegments.unshift({
|
|
219
|
+
type: "pathname",
|
|
220
|
+
value: "/"
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
const params = {};
|
|
224
|
+
const isMatch = (() => {
|
|
225
|
+
for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
|
|
226
|
+
const baseSegment = baseSegments[i];
|
|
227
|
+
const routeSegment = routeSegments[i];
|
|
228
|
+
const isLastBaseSegment = i >= baseSegments.length - 1;
|
|
229
|
+
const isLastRouteSegment = i >= routeSegments.length - 1;
|
|
230
|
+
if (routeSegment) {
|
|
231
|
+
if (routeSegment.type === "wildcard") {
|
|
232
|
+
const _splat = decodeURI(
|
|
233
|
+
joinPaths(baseSegments.slice(i).map((d) => d.value))
|
|
234
|
+
);
|
|
235
|
+
params["*"] = _splat;
|
|
236
|
+
params["_splat"] = _splat;
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
if (routeSegment.type === "pathname") {
|
|
240
|
+
if (routeSegment.value === "/" && !(baseSegment == null ? void 0 : baseSegment.value)) {
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
if (baseSegment) {
|
|
244
|
+
if (matchLocation.caseSensitive) {
|
|
245
|
+
if (routeSegment.value !== baseSegment.value) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
} else if (routeSegment.value.toLowerCase() !== baseSegment.value.toLowerCase()) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (!baseSegment) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
if (routeSegment.type === "param") {
|
|
257
|
+
if (baseSegment.value === "/") {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
if (baseSegment.value.charAt(0) !== "$") {
|
|
261
|
+
params[routeSegment.value.substring(1)] = decodeURIComponent(
|
|
262
|
+
baseSegment.value
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (!isLastBaseSegment && isLastRouteSegment) {
|
|
268
|
+
params["**"] = joinPaths(baseSegments.slice(i + 1).map((d) => d.value));
|
|
269
|
+
return !!matchLocation.fuzzy && (routeSegment == null ? void 0 : routeSegment.value) !== "/";
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return true;
|
|
273
|
+
})();
|
|
274
|
+
return isMatch ? params : void 0;
|
|
275
|
+
}
|
|
276
|
+
exports.cleanPath = cleanPath;
|
|
277
|
+
exports.exactPathTest = exactPathTest;
|
|
278
|
+
exports.interpolatePath = interpolatePath;
|
|
279
|
+
exports.joinPaths = joinPaths;
|
|
280
|
+
exports.matchByPath = matchByPath;
|
|
281
|
+
exports.matchPathname = matchPathname;
|
|
282
|
+
exports.parsePathname = parsePathname;
|
|
283
|
+
exports.removeBasepath = removeBasepath;
|
|
284
|
+
exports.removeTrailingSlash = removeTrailingSlash;
|
|
285
|
+
exports.resolvePath = resolvePath;
|
|
286
|
+
exports.trimPath = trimPath;
|
|
287
|
+
exports.trimPathLeft = trimPathLeft;
|
|
288
|
+
exports.trimPathRight = trimPathRight;
|
|
289
|
+
//# sourceMappingURL=path.cjs.map
|