@cedarjs/router 0.0.4
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 +36 -0
- package/dist/ActivePageContext.d.ts +15 -0
- package/dist/ActivePageContext.d.ts.map +1 -0
- package/dist/ActivePageContext.js +17 -0
- package/dist/AuthenticatedRoute.d.ts +11 -0
- package/dist/AuthenticatedRoute.d.ts.map +1 -0
- package/dist/AuthenticatedRoute.js +49 -0
- package/dist/PageLoadingContext.d.ts +14 -0
- package/dist/PageLoadingContext.d.ts.map +1 -0
- package/dist/PageLoadingContext.js +29 -0
- package/dist/Route.d.ts +32 -0
- package/dist/Route.d.ts.map +1 -0
- package/dist/Route.js +7 -0
- package/dist/Set.d.ts +58 -0
- package/dist/Set.d.ts.map +1 -0
- package/dist/Set.js +28 -0
- package/dist/a11yUtils.d.ts +14 -0
- package/dist/a11yUtils.d.ts.map +1 -0
- package/dist/a11yUtils.js +35 -0
- package/dist/active-route-loader.d.ts +12 -0
- package/dist/active-route-loader.d.ts.map +1 -0
- package/dist/active-route-loader.js +82 -0
- package/dist/analyzeRoutes.d.ts +44 -0
- package/dist/analyzeRoutes.d.ts.map +1 -0
- package/dist/analyzeRoutes.js +128 -0
- package/dist/cjs/ActivePageContext.d.ts +15 -0
- package/dist/cjs/ActivePageContext.d.ts.map +1 -0
- package/dist/cjs/ActivePageContext.js +42 -0
- package/dist/cjs/AuthenticatedRoute.d.ts +11 -0
- package/dist/cjs/AuthenticatedRoute.d.ts.map +1 -0
- package/dist/cjs/AuthenticatedRoute.js +83 -0
- package/dist/cjs/PageLoadingContext.d.ts +14 -0
- package/dist/cjs/PageLoadingContext.d.ts.map +1 -0
- package/dist/cjs/PageLoadingContext.js +64 -0
- package/dist/cjs/Route.d.ts +32 -0
- package/dist/cjs/Route.d.ts.map +1 -0
- package/dist/cjs/Route.js +41 -0
- package/dist/cjs/Set.d.ts +58 -0
- package/dist/cjs/Set.d.ts.map +1 -0
- package/dist/cjs/Set.js +67 -0
- package/dist/cjs/a11yUtils.d.ts +14 -0
- package/dist/cjs/a11yUtils.d.ts.map +1 -0
- package/dist/cjs/a11yUtils.js +61 -0
- package/dist/cjs/active-route-loader.d.ts +12 -0
- package/dist/cjs/active-route-loader.d.ts.map +1 -0
- package/dist/cjs/active-route-loader.js +116 -0
- package/dist/cjs/analyzeRoutes.d.ts +44 -0
- package/dist/cjs/analyzeRoutes.d.ts.map +1 -0
- package/dist/cjs/analyzeRoutes.js +143 -0
- package/dist/cjs/createNamedContext.d.ts +3 -0
- package/dist/cjs/createNamedContext.d.ts.map +1 -0
- package/dist/cjs/createNamedContext.js +33 -0
- package/dist/cjs/dummyComponent.d.ts +3 -0
- package/dist/cjs/dummyComponent.d.ts.map +1 -0
- package/dist/cjs/dummyComponent.js +24 -0
- package/dist/cjs/history.d.ts +24 -0
- package/dist/cjs/history.d.ts.map +1 -0
- package/dist/cjs/history.js +146 -0
- package/dist/cjs/index.d.ts +35 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +110 -0
- package/dist/cjs/link.d.ts +9 -0
- package/dist/cjs/link.d.ts.map +1 -0
- package/dist/cjs/link.js +62 -0
- package/dist/cjs/location.d.ts +28 -0
- package/dist/cjs/location.d.ts.map +1 -0
- package/dist/cjs/location.js +110 -0
- package/dist/cjs/namedRoutes.d.ts +3 -0
- package/dist/cjs/namedRoutes.d.ts.map +1 -0
- package/dist/cjs/namedRoutes.js +28 -0
- package/dist/cjs/navLink.d.ts +11 -0
- package/dist/cjs/navLink.d.ts.map +1 -0
- package/dist/cjs/navLink.js +70 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/page.d.ts +28 -0
- package/dist/cjs/page.d.ts.map +1 -0
- package/dist/cjs/page.js +42 -0
- package/dist/cjs/params.d.ts +13 -0
- package/dist/cjs/params.d.ts.map +1 -0
- package/dist/cjs/params.js +64 -0
- package/dist/cjs/react-util.d.ts +3 -0
- package/dist/cjs/react-util.d.ts.map +1 -0
- package/dist/cjs/react-util.js +37 -0
- package/dist/cjs/redirect.d.ts +12 -0
- package/dist/cjs/redirect.d.ts.map +1 -0
- package/dist/cjs/redirect.js +35 -0
- package/dist/cjs/route-announcement.d.ts +13 -0
- package/dist/cjs/route-announcement.d.ts.map +1 -0
- package/dist/cjs/route-announcement.js +61 -0
- package/dist/cjs/route-focus.d.ts +12 -0
- package/dist/cjs/route-focus.d.ts.map +1 -0
- package/dist/cjs/route-focus.js +36 -0
- package/dist/cjs/route-validators.d.ts +21 -0
- package/dist/cjs/route-validators.d.ts.map +1 -0
- package/dist/cjs/route-validators.js +71 -0
- package/dist/cjs/routeParamsTypes.d.ts +49 -0
- package/dist/cjs/routeParamsTypes.d.ts.map +1 -0
- package/dist/cjs/routeParamsTypes.js +16 -0
- package/dist/cjs/router-context.d.ts +21 -0
- package/dist/cjs/router-context.d.ts.map +1 -0
- package/dist/cjs/router-context.js +69 -0
- package/dist/cjs/router.d.ts +11 -0
- package/dist/cjs/router.d.ts.map +1 -0
- package/dist/cjs/router.js +207 -0
- package/dist/cjs/rsc/ClientRouter.d.ts +4 -0
- package/dist/cjs/rsc/ClientRouter.d.ts.map +1 -0
- package/dist/cjs/rsc/ClientRouter.js +90 -0
- package/dist/cjs/rsc/RscCache.d.ts +23 -0
- package/dist/cjs/rsc/RscCache.d.ts.map +1 -0
- package/dist/cjs/rsc/RscCache.js +110 -0
- package/dist/cjs/rsc/RscRoutes.d.ts +7 -0
- package/dist/cjs/rsc/RscRoutes.d.ts.map +1 -0
- package/dist/cjs/rsc/RscRoutes.js +124 -0
- package/dist/cjs/rsc/ServerRouteLoader.d.ts +12 -0
- package/dist/cjs/rsc/ServerRouteLoader.d.ts.map +1 -0
- package/dist/cjs/rsc/ServerRouteLoader.js +65 -0
- package/dist/cjs/rsc/ServerRouter.d.ts +11 -0
- package/dist/cjs/rsc/ServerRouter.d.ts.map +1 -0
- package/dist/cjs/rsc/ServerRouter.js +170 -0
- package/dist/cjs/rsc/SsrRouter.d.ts +4 -0
- package/dist/cjs/rsc/SsrRouter.d.ts.map +1 -0
- package/dist/cjs/rsc/SsrRouter.js +56 -0
- package/dist/cjs/rsc/clientSsr.d.ts +2 -0
- package/dist/cjs/rsc/clientSsr.d.ts.map +1 -0
- package/dist/cjs/rsc/clientSsr.js +114 -0
- package/dist/cjs/rsc/rscCss.d.ts +2 -0
- package/dist/cjs/rsc/rscCss.d.ts.map +1 -0
- package/dist/cjs/rsc/rscCss.js +94 -0
- package/dist/cjs/rsc/ssrModuleMap.d.ts +14 -0
- package/dist/cjs/rsc/ssrModuleMap.d.ts.map +1 -0
- package/dist/cjs/rsc/ssrModuleMap.js +49 -0
- package/dist/cjs/rsc/utils.d.ts +20 -0
- package/dist/cjs/rsc/utils.d.ts.map +1 -0
- package/dist/cjs/rsc/utils.js +68 -0
- package/dist/cjs/rsc-link.d.ts +6 -0
- package/dist/cjs/rsc-link.d.ts.map +1 -0
- package/dist/cjs/rsc-link.js +41 -0
- package/dist/cjs/skipNav.d.ts +81 -0
- package/dist/cjs/skipNav.d.ts.map +1 -0
- package/dist/cjs/skipNav.js +69 -0
- package/dist/cjs/splash-page.d.ts +12 -0
- package/dist/cjs/splash-page.d.ts.map +1 -0
- package/dist/cjs/splash-page.js +515 -0
- package/dist/cjs/useBlocker.d.ts +11 -0
- package/dist/cjs/useBlocker.d.ts.map +1 -0
- package/dist/cjs/useBlocker.js +65 -0
- package/dist/cjs/useIsMounted.d.ts +2 -0
- package/dist/cjs/useIsMounted.d.ts.map +1 -0
- package/dist/cjs/useIsMounted.js +37 -0
- package/dist/cjs/useMatch.d.ts +43 -0
- package/dist/cjs/useMatch.d.ts.map +1 -0
- package/dist/cjs/useMatch.js +72 -0
- package/dist/cjs/useRouteName.d.ts +3 -0
- package/dist/cjs/useRouteName.d.ts.map +1 -0
- package/dist/cjs/useRouteName.js +40 -0
- package/dist/cjs/useRoutePaths.d.ts +4 -0
- package/dist/cjs/useRoutePaths.d.ts.map +1 -0
- package/dist/cjs/useRoutePaths.js +50 -0
- package/dist/cjs/util.d.ts +121 -0
- package/dist/cjs/util.d.ts.map +1 -0
- package/dist/cjs/util.js +214 -0
- package/dist/createNamedContext.d.ts +3 -0
- package/dist/createNamedContext.d.ts.map +1 -0
- package/dist/createNamedContext.js +9 -0
- package/dist/dummyComponent.d.ts +3 -0
- package/dist/dummyComponent.d.ts.map +1 -0
- package/dist/dummyComponent.js +4 -0
- package/dist/history.d.ts +24 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +118 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/link.d.ts +9 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +28 -0
- package/dist/location.d.ts +28 -0
- package/dist/location.d.ts.map +1 -0
- package/dist/location.js +74 -0
- package/dist/namedRoutes.d.ts +3 -0
- package/dist/namedRoutes.d.ts.map +1 -0
- package/dist/namedRoutes.js +4 -0
- package/dist/navLink.d.ts +11 -0
- package/dist/navLink.d.ts.map +1 -0
- package/dist/navLink.js +36 -0
- package/dist/page.d.ts +28 -0
- package/dist/page.d.ts.map +1 -0
- package/dist/page.js +17 -0
- package/dist/params.d.ts +13 -0
- package/dist/params.d.ts.map +1 -0
- package/dist/params.js +28 -0
- package/dist/react-util.d.ts +3 -0
- package/dist/react-util.d.ts.map +1 -0
- package/dist/react-util.js +13 -0
- package/dist/redirect.d.ts +12 -0
- package/dist/redirect.d.ts.map +1 -0
- package/dist/redirect.js +11 -0
- package/dist/route-announcement.d.ts +13 -0
- package/dist/route-announcement.d.ts.map +1 -0
- package/dist/route-announcement.js +31 -0
- package/dist/route-focus.d.ts +12 -0
- package/dist/route-focus.d.ts.map +1 -0
- package/dist/route-focus.js +6 -0
- package/dist/route-validators.d.ts +21 -0
- package/dist/route-validators.d.ts.map +1 -0
- package/dist/route-validators.js +44 -0
- package/dist/routeParamsTypes.d.ts +49 -0
- package/dist/routeParamsTypes.d.ts.map +1 -0
- package/dist/routeParamsTypes.js +0 -0
- package/dist/router-context.d.ts +21 -0
- package/dist/router-context.d.ts.map +1 -0
- package/dist/router-context.js +34 -0
- package/dist/router.d.ts +11 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +173 -0
- package/dist/rsc/ClientRouter.d.ts +4 -0
- package/dist/rsc/ClientRouter.d.ts.map +1 -0
- package/dist/rsc/ClientRouter.js +56 -0
- package/dist/rsc/RscCache.d.ts +23 -0
- package/dist/rsc/RscCache.d.ts.map +1 -0
- package/dist/rsc/RscCache.js +86 -0
- package/dist/rsc/RscRoutes.d.ts +7 -0
- package/dist/rsc/RscRoutes.d.ts.map +1 -0
- package/dist/rsc/RscRoutes.js +100 -0
- package/dist/rsc/ServerRouteLoader.d.ts +12 -0
- package/dist/rsc/ServerRouteLoader.d.ts.map +1 -0
- package/dist/rsc/ServerRouteLoader.js +31 -0
- package/dist/rsc/ServerRouter.d.ts +11 -0
- package/dist/rsc/ServerRouter.d.ts.map +1 -0
- package/dist/rsc/ServerRouter.js +136 -0
- package/dist/rsc/SsrRouter.d.ts +4 -0
- package/dist/rsc/SsrRouter.d.ts.map +1 -0
- package/dist/rsc/SsrRouter.js +22 -0
- package/dist/rsc/clientSsr.d.ts +2 -0
- package/dist/rsc/clientSsr.d.ts.map +1 -0
- package/dist/rsc/clientSsr.js +80 -0
- package/dist/rsc/rscCss.d.ts +2 -0
- package/dist/rsc/rscCss.d.ts.map +1 -0
- package/dist/rsc/rscCss.js +60 -0
- package/dist/rsc/ssrModuleMap.d.ts +14 -0
- package/dist/rsc/ssrModuleMap.d.ts.map +1 -0
- package/dist/rsc/ssrModuleMap.js +25 -0
- package/dist/rsc/utils.d.ts +20 -0
- package/dist/rsc/utils.d.ts.map +1 -0
- package/dist/rsc/utils.js +31 -0
- package/dist/rsc-link.d.ts +6 -0
- package/dist/rsc-link.d.ts.map +1 -0
- package/dist/rsc-link.js +7 -0
- package/dist/skipNav.d.ts +81 -0
- package/dist/skipNav.d.ts.map +1 -0
- package/dist/skipNav.js +34 -0
- package/dist/splash-page.d.ts +12 -0
- package/dist/splash-page.d.ts.map +1 -0
- package/dist/splash-page.js +481 -0
- package/dist/useBlocker.d.ts +11 -0
- package/dist/useBlocker.d.ts.map +1 -0
- package/dist/useBlocker.js +41 -0
- package/dist/useIsMounted.d.ts +2 -0
- package/dist/useIsMounted.d.ts.map +1 -0
- package/dist/useIsMounted.js +13 -0
- package/dist/useMatch.d.ts +43 -0
- package/dist/useMatch.d.ts.map +1 -0
- package/dist/useMatch.js +48 -0
- package/dist/useRouteName.d.ts +3 -0
- package/dist/useRouteName.d.ts.map +1 -0
- package/dist/useRouteName.js +16 -0
- package/dist/useRoutePaths.d.ts +4 -0
- package/dist/useRoutePaths.d.ts.map +1 -0
- package/dist/useRoutePaths.js +25 -0
- package/dist/util.d.ts +121 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +183 -0
- package/package.json +127 -0
- package/skip-nav.css +31 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { FlattenSearchParams } from './util.js';
|
|
2
|
+
type UseMatchOptions = {
|
|
3
|
+
routeParams?: Record<string, any>;
|
|
4
|
+
searchParams?: FlattenSearchParams;
|
|
5
|
+
matchSubPaths?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Returns an object of { match: boolean; params: Record<string, unknown>; }
|
|
9
|
+
* If the path matches the current location `match` will be true.
|
|
10
|
+
* Params will be an object of the matched params, if there are any.
|
|
11
|
+
*
|
|
12
|
+
* Provide routeParams options to match specific route param values
|
|
13
|
+
* Provide searchParams options to match the current location.search
|
|
14
|
+
*
|
|
15
|
+
* This is useful for components that need to know "active" state, e.g.
|
|
16
|
+
* <NavLink>.
|
|
17
|
+
*
|
|
18
|
+
* Examples:
|
|
19
|
+
*
|
|
20
|
+
* Match search params key existence
|
|
21
|
+
* const match = useMatch('/about', { searchParams: ['category', 'page'] })
|
|
22
|
+
*
|
|
23
|
+
* Match search params key and value
|
|
24
|
+
* const match = useMatch('/items', { searchParams: [{page: 2}, {category: 'book'}] })
|
|
25
|
+
*
|
|
26
|
+
* Mix match
|
|
27
|
+
* const match = useMatch('/list', { searchParams: [{page: 2}, 'gtm'] })
|
|
28
|
+
*
|
|
29
|
+
* Match sub paths
|
|
30
|
+
* const match = useMatch('/product', { matchSubPaths: true })
|
|
31
|
+
*
|
|
32
|
+
* Match only specific route param values
|
|
33
|
+
* const match = useMatch('/product/{category}/{id}', { routeParams: { category: 'shirts' } })
|
|
34
|
+
*/
|
|
35
|
+
export declare const useMatch: (routePath: string, options?: UseMatchOptions) => {
|
|
36
|
+
match: boolean;
|
|
37
|
+
params?: undefined;
|
|
38
|
+
} | {
|
|
39
|
+
match: boolean;
|
|
40
|
+
params: Record<string, unknown>;
|
|
41
|
+
};
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=useMatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMatch.d.ts","sourceRoot":"","sources":["../../src/useMatch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAEpD,KAAK,eAAe,GAAG;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACjC,YAAY,CAAC,EAAE,mBAAmB,CAAA;IAClC,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,QAAQ,cAAe,MAAM,YAAY,eAAe;;;;;;CAiDpE,CAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useMatch_exports = {};
|
|
20
|
+
__export(useMatch_exports, {
|
|
21
|
+
useMatch: () => useMatch
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useMatch_exports);
|
|
24
|
+
var import_location = require("./location.js");
|
|
25
|
+
var import_util = require("./util.js");
|
|
26
|
+
const useMatch = (routePath, options) => {
|
|
27
|
+
const location = (0, import_location.useLocation)();
|
|
28
|
+
if (!location) {
|
|
29
|
+
return { match: false };
|
|
30
|
+
}
|
|
31
|
+
if (options?.searchParams) {
|
|
32
|
+
const locationParams = new URLSearchParams(location.search);
|
|
33
|
+
const hasUnmatched = options.searchParams.some((param) => {
|
|
34
|
+
if (typeof param === "string") {
|
|
35
|
+
return !locationParams.has(param);
|
|
36
|
+
} else {
|
|
37
|
+
return Object.keys(param).some(
|
|
38
|
+
(key) => param[key] != locationParams.get(key)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (hasUnmatched) {
|
|
43
|
+
return { match: false };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const matchInfo = (0, import_util.matchPath)(routePath, location.pathname, {
|
|
47
|
+
matchSubPaths: options?.matchSubPaths
|
|
48
|
+
});
|
|
49
|
+
if (!matchInfo.match) {
|
|
50
|
+
return { match: false };
|
|
51
|
+
}
|
|
52
|
+
const routeParams = Object.entries(options?.routeParams || {});
|
|
53
|
+
if (routeParams.length > 0) {
|
|
54
|
+
if (!isMatchWithParams(matchInfo) || !matchInfo.params) {
|
|
55
|
+
return { match: false };
|
|
56
|
+
}
|
|
57
|
+
const isParamMatch = routeParams.every(([key, value]) => {
|
|
58
|
+
return matchInfo.params[key] === value;
|
|
59
|
+
});
|
|
60
|
+
if (!isParamMatch) {
|
|
61
|
+
return { match: false };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return matchInfo;
|
|
65
|
+
};
|
|
66
|
+
function isMatchWithParams(match) {
|
|
67
|
+
return match !== null && typeof match === "object" && "params" in match;
|
|
68
|
+
}
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
useMatch
|
|
72
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRouteName.d.ts","sourceRoot":"","sources":["../../src/useRouteName.ts"],"names":[],"mappings":"AAOA,0EAA0E;AAC1E,wBAAgB,YAAY,cAS3B"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useRouteName_exports = {};
|
|
20
|
+
__export(useRouteName_exports, {
|
|
21
|
+
useRouteName: () => useRouteName
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useRouteName_exports);
|
|
24
|
+
var import_router_context = require("./router-context.js");
|
|
25
|
+
var import_index = require("./index.js");
|
|
26
|
+
function useRouteName() {
|
|
27
|
+
const routerState = (0, import_router_context.useRouterState)();
|
|
28
|
+
const routeName = routerState.activeRouteName;
|
|
29
|
+
if (isAvailableRouteName(routeName)) {
|
|
30
|
+
return routeName;
|
|
31
|
+
}
|
|
32
|
+
return void 0;
|
|
33
|
+
}
|
|
34
|
+
function isAvailableRouteName(name) {
|
|
35
|
+
return typeof name === "string" && Object.keys(import_index.routes).includes(name);
|
|
36
|
+
}
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
useRouteName
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRoutePaths.d.ts","sourceRoot":"","sources":["../../src/useRoutePaths.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAGjD,wBAAgB,aAAa,oCAc5B;AAED,wBAAgB,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,eAAe,sBAW7D"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useRoutePaths_exports = {};
|
|
20
|
+
__export(useRoutePaths_exports, {
|
|
21
|
+
useRoutePath: () => useRoutePath,
|
|
22
|
+
useRoutePaths: () => useRoutePaths
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useRoutePaths_exports);
|
|
25
|
+
var import_router_context = require("./router-context.js");
|
|
26
|
+
var import_useRouteName = require("./useRouteName.js");
|
|
27
|
+
function useRoutePaths() {
|
|
28
|
+
const routerState = (0, import_router_context.useRouterState)();
|
|
29
|
+
const routePaths = Object.values(routerState.routes.pathRouteMap).reduce((routePathsAcc, currRoute) => {
|
|
30
|
+
if (currRoute.name) {
|
|
31
|
+
routePathsAcc[currRoute.name] = currRoute.path;
|
|
32
|
+
}
|
|
33
|
+
return routePathsAcc;
|
|
34
|
+
}, {});
|
|
35
|
+
return routePaths;
|
|
36
|
+
}
|
|
37
|
+
function useRoutePath(routeName) {
|
|
38
|
+
const currentRouteName = (0, import_useRouteName.useRouteName)();
|
|
39
|
+
const routePaths = useRoutePaths();
|
|
40
|
+
const name = routeName || currentRouteName;
|
|
41
|
+
if (!name) {
|
|
42
|
+
return void 0;
|
|
43
|
+
}
|
|
44
|
+
return routePaths[name];
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
useRoutePath,
|
|
49
|
+
useRoutePaths
|
|
50
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get param name, type, and match for a route.
|
|
3
|
+
*
|
|
4
|
+
* '/blog/{year}/{month}/{day:Int}/{filePath...}'
|
|
5
|
+
* => [
|
|
6
|
+
* ['year', 'String', '{year}'],
|
|
7
|
+
* ['month', 'String', '{month}'],
|
|
8
|
+
* ['day', 'Int', '{day:Int}'],
|
|
9
|
+
* ['filePath', 'Glob', '{filePath...}']
|
|
10
|
+
* ]
|
|
11
|
+
*
|
|
12
|
+
* Only exported to be able to test it
|
|
13
|
+
*/
|
|
14
|
+
export declare function paramsForRoute(route: string): string[][];
|
|
15
|
+
export type TrailingSlashesTypes = 'never' | 'always' | 'preserve';
|
|
16
|
+
export interface ParamType {
|
|
17
|
+
match?: RegExp;
|
|
18
|
+
parse?: (value: any) => unknown;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Determine if the given route is a match for the given pathname. If so,
|
|
22
|
+
* extract any named params and return them in an object.
|
|
23
|
+
*
|
|
24
|
+
* route - The route path as specified in the <Route path={...} />
|
|
25
|
+
* pathname - The pathname from the window.location.
|
|
26
|
+
* paramTypes - The object containing all param type definitions.
|
|
27
|
+
* matchSubPaths - Also match sub routes
|
|
28
|
+
*
|
|
29
|
+
* Examples:
|
|
30
|
+
*
|
|
31
|
+
* matchPath('/blog/{year}/{month}/{day}', '/blog/2019/12/07')
|
|
32
|
+
* => { match: true, params: { year: '2019', month: '12', day: '07' }}
|
|
33
|
+
*
|
|
34
|
+
* matchPath('/about', '/')
|
|
35
|
+
* => { match: false }
|
|
36
|
+
*
|
|
37
|
+
* matchPath('/post/{id:Int}', '/post/7')
|
|
38
|
+
* => { match: true, params: { id: 7 }}
|
|
39
|
+
*
|
|
40
|
+
* matchPath('/post/1', '/post/', { matchSubPaths: true })
|
|
41
|
+
* => { match: true, params: {} }
|
|
42
|
+
*/
|
|
43
|
+
export declare function matchPath(routeDefinition: string, pathname: string, { userParamTypes, matchSubPaths, }?: {
|
|
44
|
+
userParamTypes?: Record<string, ParamType>;
|
|
45
|
+
matchSubPaths?: boolean;
|
|
46
|
+
}): {
|
|
47
|
+
match: boolean;
|
|
48
|
+
params?: undefined;
|
|
49
|
+
} | {
|
|
50
|
+
match: boolean;
|
|
51
|
+
params: Record<string, unknown>;
|
|
52
|
+
};
|
|
53
|
+
interface GetRouteRegexOptions {
|
|
54
|
+
matchSubPaths?: boolean;
|
|
55
|
+
allParamTypes?: Record<string, ParamType>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* This function will return a regex for each route path i.e. /blog/{year}/{month}/{day}
|
|
59
|
+
* will return a regex like /blog/([^/$1*]+)/([^/$1*]+)/([^/$1*]+)
|
|
60
|
+
*
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
export declare function getRouteRegexAndParams(route: string, { matchSubPaths, allParamTypes, }?: GetRouteRegexOptions | undefined): {
|
|
64
|
+
matchRegex: RegExp;
|
|
65
|
+
routeParams: string[][];
|
|
66
|
+
matchRegexString: string;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Parse the given search string into key/value pairs and return them in an
|
|
70
|
+
* object.
|
|
71
|
+
*
|
|
72
|
+
* Examples:
|
|
73
|
+
*
|
|
74
|
+
* parseSearch('?key1=val1&key2=val2')
|
|
75
|
+
* => { key1: 'val1', key2: 'val2' }
|
|
76
|
+
*
|
|
77
|
+
* @fixme
|
|
78
|
+
* This utility ignores keys with multiple values such as `?foo=1&foo=2`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function parseSearch(search: string | string[][] | Record<string, string> | URLSearchParams | undefined): {};
|
|
81
|
+
/**
|
|
82
|
+
* Validate a path to make sure it follows the router's rules. If any problems
|
|
83
|
+
* are found, a descriptive Error will be thrown, as problems with routes are
|
|
84
|
+
* critical enough to be considered fatal.
|
|
85
|
+
*/
|
|
86
|
+
export declare function validatePath(path: string, routeName: string): void;
|
|
87
|
+
/**
|
|
88
|
+
* Take a given route path and replace any named parameters with those in the
|
|
89
|
+
* given args object. Any extra params not used in the path will be appended
|
|
90
|
+
* as key=value pairs in the search part.
|
|
91
|
+
*
|
|
92
|
+
* Examples:
|
|
93
|
+
*
|
|
94
|
+
* replaceParams('/tags/{tag}', { tag: 'code', extra: 'foo' })
|
|
95
|
+
* => '/tags/code?extra=foo
|
|
96
|
+
*/
|
|
97
|
+
export declare function replaceParams(route: string, args?: Record<string, unknown>): string;
|
|
98
|
+
export type FlattenSearchParams = ReturnType<typeof flattenSearchParams>;
|
|
99
|
+
/**
|
|
100
|
+
* Returns a flat array of search params
|
|
101
|
+
*
|
|
102
|
+
* `useMatch` hook options `searchParams` requires a flat array
|
|
103
|
+
*
|
|
104
|
+
* Example:
|
|
105
|
+
* ```
|
|
106
|
+
* parseSearch('?key1=val1&key2=val2')
|
|
107
|
+
* => { key1: 'val1', key2: 'val2' }
|
|
108
|
+
*
|
|
109
|
+
* flattenSearchParams(parseSearch('?key1=val1&key2=val2'))
|
|
110
|
+
* => [ { key1: 'val1' }, { key2: 'val2' } ]
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare function flattenSearchParams(queryString: string): Record<string, unknown>[];
|
|
114
|
+
/**
|
|
115
|
+
* Detect if we're in an iframe.
|
|
116
|
+
*
|
|
117
|
+
* From https://stackoverflow.com/questions/326069/how-to-identify-if-a-webpage-is-being-loaded-inside-an-iframe-or-directly-into-t
|
|
118
|
+
*/
|
|
119
|
+
export declare function inIframe(): boolean;
|
|
120
|
+
export {};
|
|
121
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,cAyB3C;AAED,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAA;AAElE,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAA;CAChC;AAwBD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,SAAS,CACvB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,EACE,cAAc,EACd,aAAa,GACd,GAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAC1C,aAAa,CAAC,EAAE,OAAO,CAAA;CAIxB;;;;;;EA2CF;AAED,UAAU,oBAAoB;IAC5B,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;CAC1C;AACD;;;;;GAKG;AAEH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,EACb,EACE,aAAqB,EACrB,aAA8B,GAC/B,GAAE,oBAAoB,GAAG,SAAc;;;;EA+BzC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CACzB,MAAM,EACF,MAAM,GACN,MAAM,EAAE,EAAE,GACV,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACtB,eAAe,GACf,SAAS,MAWd;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAyC3D;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,UAgCnC;AAED,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAExE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,6BAQtD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,YAMvB"}
|
package/dist/cjs/util.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var util_exports = {};
|
|
20
|
+
__export(util_exports, {
|
|
21
|
+
flattenSearchParams: () => flattenSearchParams,
|
|
22
|
+
getRouteRegexAndParams: () => getRouteRegexAndParams,
|
|
23
|
+
inIframe: () => inIframe,
|
|
24
|
+
matchPath: () => matchPath,
|
|
25
|
+
paramsForRoute: () => paramsForRoute,
|
|
26
|
+
parseSearch: () => parseSearch,
|
|
27
|
+
replaceParams: () => replaceParams,
|
|
28
|
+
validatePath: () => validatePath
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(util_exports);
|
|
31
|
+
function paramsForRoute(route) {
|
|
32
|
+
const params = [...route.matchAll(/\{([^}]+)\}/g)];
|
|
33
|
+
return params.map((match) => match[1]).map((match) => {
|
|
34
|
+
const parts = match.split(":");
|
|
35
|
+
let name = parts[0];
|
|
36
|
+
if (name.endsWith("...")) {
|
|
37
|
+
name = name.slice(0, -3);
|
|
38
|
+
}
|
|
39
|
+
let type = parts[1];
|
|
40
|
+
if (!type) {
|
|
41
|
+
type = match.endsWith("...") ? "Glob" : "String";
|
|
42
|
+
}
|
|
43
|
+
return [name, type, `{${match}}`];
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const coreParamTypes = {
|
|
47
|
+
String: {
|
|
48
|
+
match: /[^/]+/
|
|
49
|
+
},
|
|
50
|
+
Int: {
|
|
51
|
+
match: /\d+/,
|
|
52
|
+
parse: Number
|
|
53
|
+
},
|
|
54
|
+
Float: {
|
|
55
|
+
match: /[-+]?(?:\d*\.?\d+|\d+\.?\d*)(?:[eE][-+]?\d+)?/,
|
|
56
|
+
parse: Number
|
|
57
|
+
},
|
|
58
|
+
Boolean: {
|
|
59
|
+
match: /true|false/,
|
|
60
|
+
parse: (boolAsString) => boolAsString === "true"
|
|
61
|
+
},
|
|
62
|
+
Glob: {
|
|
63
|
+
match: /.*/
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
function matchPath(routeDefinition, pathname, {
|
|
67
|
+
userParamTypes,
|
|
68
|
+
matchSubPaths
|
|
69
|
+
} = {
|
|
70
|
+
userParamTypes: {},
|
|
71
|
+
matchSubPaths: false
|
|
72
|
+
}) {
|
|
73
|
+
const allParamTypes = { ...coreParamTypes, ...userParamTypes };
|
|
74
|
+
const { matchRegex, routeParams: routeParamsDefinition } = getRouteRegexAndParams(routeDefinition, {
|
|
75
|
+
matchSubPaths,
|
|
76
|
+
allParamTypes
|
|
77
|
+
});
|
|
78
|
+
const matches = [...pathname.matchAll(matchRegex)];
|
|
79
|
+
if (matches.length === 0) {
|
|
80
|
+
return { match: false };
|
|
81
|
+
}
|
|
82
|
+
const providedParams = matches[0].slice(1);
|
|
83
|
+
if (routeParamsDefinition.length > 0) {
|
|
84
|
+
const params = providedParams.reduce(
|
|
85
|
+
(acc, value, index) => {
|
|
86
|
+
const [name, transformName] = routeParamsDefinition[index];
|
|
87
|
+
const typeInfo = allParamTypes[transformName];
|
|
88
|
+
let transformedValue = value;
|
|
89
|
+
if (typeof typeInfo?.parse === "function") {
|
|
90
|
+
transformedValue = typeInfo.parse(value);
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
...acc,
|
|
94
|
+
[name]: transformedValue
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
{}
|
|
98
|
+
);
|
|
99
|
+
return { match: true, params };
|
|
100
|
+
}
|
|
101
|
+
return { match: true };
|
|
102
|
+
}
|
|
103
|
+
function getRouteRegexAndParams(route, {
|
|
104
|
+
matchSubPaths = false,
|
|
105
|
+
allParamTypes = coreParamTypes
|
|
106
|
+
} = {}) {
|
|
107
|
+
let typeMatchingRoute = route;
|
|
108
|
+
const routeParams = paramsForRoute(route);
|
|
109
|
+
for (const [_name, type, match] of routeParams) {
|
|
110
|
+
const matcher = allParamTypes[type]?.match;
|
|
111
|
+
const typeRegexp = matcher?.source || "[^/]+";
|
|
112
|
+
typeMatchingRoute = typeMatchingRoute.replace(match, `(${typeRegexp})`);
|
|
113
|
+
}
|
|
114
|
+
const matchRegex = matchSubPaths ? new RegExp(`^${typeMatchingRoute}(?:/.*)?$`, "g") : new RegExp(`^${typeMatchingRoute}$`, "g");
|
|
115
|
+
const matchRegexString = matchSubPaths ? `^${typeMatchingRoute}(?:/.*)?$` : `^${typeMatchingRoute}$`;
|
|
116
|
+
return {
|
|
117
|
+
matchRegex,
|
|
118
|
+
routeParams,
|
|
119
|
+
matchRegexString
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function parseSearch(search) {
|
|
123
|
+
const searchParams = new URLSearchParams(search);
|
|
124
|
+
return [...searchParams.keys()].reduce(
|
|
125
|
+
(params, key) => ({
|
|
126
|
+
...params,
|
|
127
|
+
[key]: searchParams.get(key)
|
|
128
|
+
}),
|
|
129
|
+
{}
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
function validatePath(path, routeName) {
|
|
133
|
+
if (!path.startsWith("/")) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
`Route path for ${routeName} does not begin with a slash: "${path}"`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
if (path.includes(" ")) {
|
|
139
|
+
throw new Error(`Route path for ${routeName} contains spaces: "${path}"`);
|
|
140
|
+
}
|
|
141
|
+
if (/{(?:ref|key)(?::|})/.test(path)) {
|
|
142
|
+
throw new Error(
|
|
143
|
+
[
|
|
144
|
+
`Route for ${routeName} contains ref or key as a path parameter: "${path}"`,
|
|
145
|
+
"`ref` and `key` shouldn't be used as path parameters because they're special React props.",
|
|
146
|
+
"You can fix this by renaming the path parameter."
|
|
147
|
+
].join("\n")
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
if (path.length > 2e3) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`Route path for ${routeName} is too long to process at ${path.length} characters, limit is 2000 characters.`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
const matches = path.matchAll(/\{([^}]+)\}/g);
|
|
156
|
+
const memo = {};
|
|
157
|
+
for (const match of matches) {
|
|
158
|
+
const param = match[1].split(":")[0];
|
|
159
|
+
if (memo[param]) {
|
|
160
|
+
throw new Error(`Route path contains duplicate parameter: "${path}"`);
|
|
161
|
+
} else {
|
|
162
|
+
memo[param] = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function replaceParams(route, args = {}) {
|
|
167
|
+
const params = paramsForRoute(route);
|
|
168
|
+
let path = route;
|
|
169
|
+
params.forEach((param) => {
|
|
170
|
+
const [name, _type, match] = param;
|
|
171
|
+
const value = args[name];
|
|
172
|
+
if (value !== void 0) {
|
|
173
|
+
path = path.replace(match, value);
|
|
174
|
+
} else {
|
|
175
|
+
throw new Error(
|
|
176
|
+
`Missing parameter '${name}' for route '${route}' when generating a navigation URL.`
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
const paramNames = params.map((param) => param[0]);
|
|
181
|
+
const extraArgKeys = Object.keys(args).filter((x) => !paramNames.includes(x)).filter((x) => args[x] !== void 0 && args[x] !== null);
|
|
182
|
+
if (extraArgKeys.length) {
|
|
183
|
+
const extraArgs = Object.fromEntries(
|
|
184
|
+
extraArgKeys.map((key) => [key, `${args[key]}`])
|
|
185
|
+
);
|
|
186
|
+
path += `?${new URLSearchParams(extraArgs).toString()}`;
|
|
187
|
+
}
|
|
188
|
+
return path;
|
|
189
|
+
}
|
|
190
|
+
function flattenSearchParams(queryString) {
|
|
191
|
+
const searchParams = [];
|
|
192
|
+
for (const [key, value] of Object.entries(parseSearch(queryString))) {
|
|
193
|
+
searchParams.push({ [key]: value });
|
|
194
|
+
}
|
|
195
|
+
return searchParams;
|
|
196
|
+
}
|
|
197
|
+
function inIframe() {
|
|
198
|
+
try {
|
|
199
|
+
return global?.self !== global?.top;
|
|
200
|
+
} catch {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
205
|
+
0 && (module.exports = {
|
|
206
|
+
flattenSearchParams,
|
|
207
|
+
getRouteRegexAndParams,
|
|
208
|
+
inIframe,
|
|
209
|
+
matchPath,
|
|
210
|
+
paramsForRoute,
|
|
211
|
+
parseSearch,
|
|
212
|
+
replaceParams,
|
|
213
|
+
validatePath
|
|
214
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createNamedContext.d.ts","sourceRoot":"","sources":["../src/createNamedContext.ts"],"names":[],"mappings":"AAEA,kDAAkD;AAClD,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,0CAInE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dummyComponent.d.ts","sourceRoot":"","sources":["../src/dummyComponent.ts"],"names":[],"mappings":";AAEA,wBAAyB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface NavigateOptions {
|
|
2
|
+
replace?: boolean;
|
|
3
|
+
scroll?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export type Listener = (ev?: PopStateEvent, options?: NavigateOptions) => any;
|
|
6
|
+
export type BeforeUnloadListener = (ev: BeforeUnloadEvent) => any;
|
|
7
|
+
export type BlockerCallback = (tx: {
|
|
8
|
+
retry: () => void;
|
|
9
|
+
}) => void;
|
|
10
|
+
export type Blocker = {
|
|
11
|
+
id: string;
|
|
12
|
+
callback: BlockerCallback;
|
|
13
|
+
};
|
|
14
|
+
declare const gHistory: {
|
|
15
|
+
listen: (listener: Listener) => string;
|
|
16
|
+
navigate: (to: string, options?: NavigateOptions) => void;
|
|
17
|
+
back: () => void;
|
|
18
|
+
remove: (listenerId: string) => void;
|
|
19
|
+
block: (id: string, callback: BlockerCallback) => void;
|
|
20
|
+
unblock: (id: string) => void;
|
|
21
|
+
};
|
|
22
|
+
declare const navigate: (to: string, options?: NavigateOptions) => void, back: () => void, block: (id: string, callback: BlockerCallback) => void, unblock: (id: string) => void;
|
|
23
|
+
export { gHistory, navigate, back, block, unblock };
|
|
24
|
+
//# sourceMappingURL=history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.tsx"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,MAAM,QAAQ,GAAG,CAAC,EAAE,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,eAAe,KAAK,GAAG,CAAA;AAC7E,MAAM,MAAM,oBAAoB,GAAG,CAAC,EAAE,EAAE,iBAAiB,KAAK,GAAG,CAAA;AACjE,MAAM,MAAM,eAAe,GAAG,CAAC,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,IAAI,CAAA;CAAE,KAAK,IAAI,CAAA;AACjE,MAAM,MAAM,OAAO,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,eAAe,CAAA;CAAE,CAAA;AAgI/D,QAAA,MAAM,QAAQ;uBAxHS,QAAQ;mBAOrB,MAAM,YACD,eAAe;;yBA8CL,MAAM;gBAWf,MAAM,YAAY,eAAe;kBAa/B,MAAM;CA0CQ,CAAA;AAEhC,QAAA,MAAQ,QAAQ,OAnHN,MAAM,YACD,eAAe,WAkHZ,IAAI,cAAE,KAAK,OAzDb,MAAM,YAAY,eAAe,WAyDlB,OAAO,OA5CpB,MAAM,SA4C2B,CAAA;AAEnD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA"}
|