@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,128 @@
|
|
|
1
|
+
import { Children } from "react";
|
|
2
|
+
import {
|
|
3
|
+
isNotFoundRoute,
|
|
4
|
+
isRedirectRoute,
|
|
5
|
+
isStandardRoute,
|
|
6
|
+
isValidRoute
|
|
7
|
+
} from "./route-validators.js";
|
|
8
|
+
import { isPrivateNode, isPrivateSetNode, isSetNode } from "./Set.js";
|
|
9
|
+
import {
|
|
10
|
+
matchPath,
|
|
11
|
+
replaceParams,
|
|
12
|
+
validatePath
|
|
13
|
+
} from "./util.js";
|
|
14
|
+
function analyzeRoutes(children, { currentPathName, userParamTypes }) {
|
|
15
|
+
const pathRouteMap = {};
|
|
16
|
+
const namedRoutesMap = {};
|
|
17
|
+
let hasRootRoute = false;
|
|
18
|
+
let NotFoundPage;
|
|
19
|
+
let activeRoutePath;
|
|
20
|
+
const recurseThroughRouter = ({
|
|
21
|
+
nodes,
|
|
22
|
+
whileLoadingPageFromSet,
|
|
23
|
+
sets: previousSets = []
|
|
24
|
+
}) => {
|
|
25
|
+
let nextSetId = 0;
|
|
26
|
+
nodes.forEach((node) => {
|
|
27
|
+
if (isValidRoute(node)) {
|
|
28
|
+
const route = node;
|
|
29
|
+
if (isNotFoundRoute(route)) {
|
|
30
|
+
NotFoundPage = route.props.page;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (route.props.path === "/") {
|
|
34
|
+
hasRootRoute = true;
|
|
35
|
+
}
|
|
36
|
+
if (isRedirectRoute(route)) {
|
|
37
|
+
const { name, redirect, path } = route.props;
|
|
38
|
+
validatePath(path, name || path);
|
|
39
|
+
const { match } = matchPath(path, currentPathName, {
|
|
40
|
+
userParamTypes
|
|
41
|
+
});
|
|
42
|
+
if (match && !activeRoutePath) {
|
|
43
|
+
activeRoutePath = path;
|
|
44
|
+
}
|
|
45
|
+
pathRouteMap[path] = {
|
|
46
|
+
redirect,
|
|
47
|
+
name: name || null,
|
|
48
|
+
path,
|
|
49
|
+
page: null,
|
|
50
|
+
// Redirects don't need pages. We set this to null for consistency
|
|
51
|
+
sets: previousSets
|
|
52
|
+
};
|
|
53
|
+
if (name) {
|
|
54
|
+
namedRoutesMap[name] = (args = {}) => replaceParams(path, args);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (isStandardRoute(route)) {
|
|
58
|
+
const { name, path, page } = route.props;
|
|
59
|
+
validatePath(path, name);
|
|
60
|
+
const { match } = matchPath(path, currentPathName, {
|
|
61
|
+
userParamTypes
|
|
62
|
+
});
|
|
63
|
+
if (match && !activeRoutePath) {
|
|
64
|
+
activeRoutePath = path;
|
|
65
|
+
}
|
|
66
|
+
pathRouteMap[path] = {
|
|
67
|
+
redirect: null,
|
|
68
|
+
name,
|
|
69
|
+
path,
|
|
70
|
+
whileLoadingPage: route.props.whileLoadingPage || whileLoadingPageFromSet,
|
|
71
|
+
page,
|
|
72
|
+
sets: previousSets
|
|
73
|
+
};
|
|
74
|
+
namedRoutesMap[name] = (args = {}) => replaceParams(path, args);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (isSetNode(node)) {
|
|
78
|
+
const {
|
|
79
|
+
children: children2,
|
|
80
|
+
whileLoadingPage: whileLoadingPageFromCurrentSet,
|
|
81
|
+
wrap: wrapFromCurrentSet,
|
|
82
|
+
...otherPropsFromCurrentSet
|
|
83
|
+
} = node.props;
|
|
84
|
+
let wrapperComponentsArray = [];
|
|
85
|
+
if (wrapFromCurrentSet) {
|
|
86
|
+
wrapperComponentsArray = Array.isArray(wrapFromCurrentSet) ? wrapFromCurrentSet : [wrapFromCurrentSet];
|
|
87
|
+
}
|
|
88
|
+
nextSetId = nextSetId + 1;
|
|
89
|
+
recurseThroughRouter({
|
|
90
|
+
nodes: Children.toArray(children2),
|
|
91
|
+
// When there's a whileLoadingPage prop on a Set, we pass it down to all its children
|
|
92
|
+
// If the parent node was also a Set with whileLoadingPage, we pass it down. The child's whileLoadingPage
|
|
93
|
+
// will always take precedence over the parent's
|
|
94
|
+
whileLoadingPageFromSet: whileLoadingPageFromCurrentSet || whileLoadingPageFromSet,
|
|
95
|
+
sets: [
|
|
96
|
+
...previousSets,
|
|
97
|
+
{
|
|
98
|
+
id: createSetId(nextSetId, previousSets),
|
|
99
|
+
wrappers: wrapperComponentsArray,
|
|
100
|
+
isPrivate: isPrivateSetNode(node) || // The following two conditions can be removed when we remove
|
|
101
|
+
// the deprecated private prop
|
|
102
|
+
isPrivateNode(node) || !!otherPropsFromCurrentSet.private,
|
|
103
|
+
props: otherPropsFromCurrentSet
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
recurseThroughRouter({ nodes: Children.toArray(children) });
|
|
111
|
+
return {
|
|
112
|
+
pathRouteMap,
|
|
113
|
+
namedRoutesMap,
|
|
114
|
+
hasRootRoute,
|
|
115
|
+
NotFoundPage,
|
|
116
|
+
activeRoutePath
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function createSetId(nextSetId, previousSets) {
|
|
120
|
+
const firstLevel = previousSets.length === 0;
|
|
121
|
+
if (firstLevel) {
|
|
122
|
+
return nextSetId.toString();
|
|
123
|
+
}
|
|
124
|
+
return previousSets.at(-1)?.id + "." + nextSetId;
|
|
125
|
+
}
|
|
126
|
+
export {
|
|
127
|
+
analyzeRoutes
|
|
128
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LocationContextType } from './location.js';
|
|
2
|
+
export type LoadingState = 'PRE_SHOW' | 'SHOW_LOADING' | 'DONE';
|
|
3
|
+
export type LoadingStateRecord = Record<string, {
|
|
4
|
+
specName: string;
|
|
5
|
+
state: LoadingState;
|
|
6
|
+
page: React.ComponentType<unknown>;
|
|
7
|
+
location: LocationContextType;
|
|
8
|
+
} | undefined>;
|
|
9
|
+
interface ActivePageState {
|
|
10
|
+
loadingState: LoadingStateRecord;
|
|
11
|
+
}
|
|
12
|
+
export declare const ActivePageContextProvider: import("react").Provider<ActivePageState | undefined>;
|
|
13
|
+
export declare const useActivePageContext: () => ActivePageState;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=ActivePageContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActivePageContext.d.ts","sourceRoot":"","sources":["../../src/ActivePageContext.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAExD,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,cAAc,GAAG,MAAM,CAAA;AAC/D,MAAM,MAAM,kBAAkB,GAAG,MAAM,CACrC,MAAM,EACJ;IACE,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,YAAY,CAAA;IACnB,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IAClC,QAAQ,EAAE,mBAAmB,CAAA;CAC9B,GACD,SAAS,CACZ,CAAA;AAED,UAAU,eAAe;IACvB,YAAY,EAAE,kBAAkB,CAAA;CACjC;AAID,eAAO,MAAM,yBAAyB,uDAA6B,CAAA;AAEnE,eAAO,MAAM,oBAAoB,uBAUhC,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 ActivePageContext_exports = {};
|
|
20
|
+
__export(ActivePageContext_exports, {
|
|
21
|
+
ActivePageContextProvider: () => ActivePageContextProvider,
|
|
22
|
+
useActivePageContext: () => useActivePageContext
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(ActivePageContext_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
var import_createNamedContext = require("./createNamedContext.js");
|
|
27
|
+
const ActivePageContext = (0, import_createNamedContext.createNamedContext)("ActivePage");
|
|
28
|
+
const ActivePageContextProvider = ActivePageContext.Provider;
|
|
29
|
+
const useActivePageContext = () => {
|
|
30
|
+
const activePageContext = (0, import_react.useContext)(ActivePageContext);
|
|
31
|
+
if (!activePageContext) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
"useActivePageContext must be used within a ActivePageContext provider"
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return activePageContext;
|
|
37
|
+
};
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
ActivePageContextProvider,
|
|
41
|
+
useActivePageContext
|
|
42
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { GeneratedRoutesMap } from './analyzeRoutes.js';
|
|
3
|
+
interface AuthenticatedRouteProps {
|
|
4
|
+
children: React.ReactNode | Thenable<React.ReactNode>;
|
|
5
|
+
roles?: string | string[];
|
|
6
|
+
unauthenticated: keyof GeneratedRoutesMap;
|
|
7
|
+
whileLoadingAuth?: () => React.ReactElement | null;
|
|
8
|
+
}
|
|
9
|
+
export declare const AuthenticatedRoute: React.FC<AuthenticatedRouteProps>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=AuthenticatedRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthenticatedRoute.d.ts","sourceRoot":"","sources":["../../src/AuthenticatedRoute.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsB,MAAM,OAAO,CAAA;AAE1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAK5D,UAAU,uBAAuB;IAC/B,QAAQ,EAAE,KAAK,CAAC,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IACrD,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACzB,eAAe,EAAE,MAAM,kBAAkB,CAAA;IACzC,gBAAgB,CAAC,EAAE,MAAM,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;CACnD;AAED,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CA6DhE,CAAA"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var AuthenticatedRoute_exports = {};
|
|
30
|
+
__export(AuthenticatedRoute_exports, {
|
|
31
|
+
AuthenticatedRoute: () => AuthenticatedRoute
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(AuthenticatedRoute_exports);
|
|
34
|
+
var import_react = __toESM(require("react"), 1);
|
|
35
|
+
var import_namedRoutes = require("./namedRoutes.js");
|
|
36
|
+
var import_redirect = require("./redirect.js");
|
|
37
|
+
var import_router_context = require("./router-context.js");
|
|
38
|
+
const AuthenticatedRoute = ({
|
|
39
|
+
unauthenticated,
|
|
40
|
+
roles,
|
|
41
|
+
whileLoadingAuth,
|
|
42
|
+
children
|
|
43
|
+
}) => {
|
|
44
|
+
const routerState = (0, import_router_context.useRouterState)();
|
|
45
|
+
const {
|
|
46
|
+
loading: authLoading,
|
|
47
|
+
isAuthenticated,
|
|
48
|
+
hasRole
|
|
49
|
+
} = routerState.useAuth();
|
|
50
|
+
const unauthorized = (0, import_react.useCallback)(() => {
|
|
51
|
+
return !(isAuthenticated && (!roles || hasRole(roles)));
|
|
52
|
+
}, [isAuthenticated, roles, hasRole]);
|
|
53
|
+
if (unauthorized()) {
|
|
54
|
+
if (authLoading) {
|
|
55
|
+
return whileLoadingAuth?.() || null;
|
|
56
|
+
} else {
|
|
57
|
+
const currentLocation = globalThis.location.pathname + encodeURIComponent(globalThis.location.search);
|
|
58
|
+
const generatedRoutesMap = import_namedRoutes.namedRoutes;
|
|
59
|
+
if (!generatedRoutesMap[unauthenticated]) {
|
|
60
|
+
throw new Error(`We could not find a route named ${unauthenticated}`);
|
|
61
|
+
}
|
|
62
|
+
let unauthenticatedPath;
|
|
63
|
+
try {
|
|
64
|
+
unauthenticatedPath = generatedRoutesMap[unauthenticated]();
|
|
65
|
+
} catch (e) {
|
|
66
|
+
if (e instanceof Error && /Missing parameter .* for route/.test(e.message)) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Redirecting to route "${unauthenticated}" would require route parameters, which currently is not supported. Please choose a different route`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Could not redirect to the route named ${unauthenticated}`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return /* @__PURE__ */ import_react.default.createElement(import_redirect.Redirect, { to: `${unauthenticatedPath}?redirectTo=${currentLocation}` });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children);
|
|
79
|
+
};
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
AuthenticatedRoute
|
|
83
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface PageLoadingContextInterface {
|
|
3
|
+
loading: boolean;
|
|
4
|
+
setPageLoadingContext: (loading: boolean) => void;
|
|
5
|
+
delay?: number;
|
|
6
|
+
}
|
|
7
|
+
interface Props {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
delay?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const PageLoadingContextProvider: React.FC<Props>;
|
|
12
|
+
export declare const usePageLoadingContext: () => PageLoadingContextInterface;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=PageLoadingContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PageLoadingContext.d.ts","sourceRoot":"","sources":["../../src/PageLoadingContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+B,MAAM,OAAO,CAAA;AAInD,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,OAAO,CAAA;IAChB,qBAAqB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IACjD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAKD,UAAU,KAAK;IACb,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,eAAO,MAAM,0BAA0B,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAatD,CAAA;AAED,eAAO,MAAM,qBAAqB,mCAUjC,CAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var PageLoadingContext_exports = {};
|
|
30
|
+
__export(PageLoadingContext_exports, {
|
|
31
|
+
PageLoadingContextProvider: () => PageLoadingContextProvider,
|
|
32
|
+
usePageLoadingContext: () => usePageLoadingContext
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(PageLoadingContext_exports);
|
|
35
|
+
var import_react = __toESM(require("react"), 1);
|
|
36
|
+
var import_createNamedContext = require("./createNamedContext.js");
|
|
37
|
+
const PageLoadingContext = (0, import_createNamedContext.createNamedContext)("PageLoading");
|
|
38
|
+
const PageLoadingContextProvider = ({
|
|
39
|
+
children,
|
|
40
|
+
delay = 1e3
|
|
41
|
+
}) => {
|
|
42
|
+
const [loading, setPageLoadingContext] = (0, import_react.useState)(false);
|
|
43
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
44
|
+
PageLoadingContext.Provider,
|
|
45
|
+
{
|
|
46
|
+
value: { loading, setPageLoadingContext, delay }
|
|
47
|
+
},
|
|
48
|
+
children
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
const usePageLoadingContext = () => {
|
|
52
|
+
const pageLoadingContext = (0, import_react.useContext)(PageLoadingContext);
|
|
53
|
+
if (!pageLoadingContext) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
"usePageLoadingContext must be used within a PageLoadingContext provider"
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return pageLoadingContext;
|
|
59
|
+
};
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
PageLoadingContextProvider,
|
|
63
|
+
usePageLoadingContext
|
|
64
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import type { PageType } from './page.js';
|
|
3
|
+
export type RenderMode = 'stream' | 'html';
|
|
4
|
+
export interface RedirectRouteProps {
|
|
5
|
+
redirect: string;
|
|
6
|
+
path: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface NotFoundRouteProps {
|
|
10
|
+
notfound: boolean;
|
|
11
|
+
page: PageType;
|
|
12
|
+
prerender?: boolean;
|
|
13
|
+
renderMode?: RenderMode;
|
|
14
|
+
}
|
|
15
|
+
export interface RouteProps {
|
|
16
|
+
path: string;
|
|
17
|
+
page: PageType;
|
|
18
|
+
name: string;
|
|
19
|
+
prerender?: boolean;
|
|
20
|
+
renderMode?: RenderMode;
|
|
21
|
+
whileLoadingPage?: () => ReactElement | null;
|
|
22
|
+
}
|
|
23
|
+
export type InternalRouteProps = Partial<RouteProps & RedirectRouteProps & NotFoundRouteProps>;
|
|
24
|
+
/**
|
|
25
|
+
* Route is now a "virtual" component
|
|
26
|
+
* it is actually never rendered. All the page loading logic happens in active-route-loader
|
|
27
|
+
* and all the validation happens within utility functions called from the Router
|
|
28
|
+
*/
|
|
29
|
+
export declare function Route(props: RouteProps): JSX.Element;
|
|
30
|
+
export declare function Route(props: RedirectRouteProps): JSX.Element;
|
|
31
|
+
export declare function Route(props: NotFoundRouteProps): JSX.Element;
|
|
32
|
+
//# sourceMappingURL=Route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../../src/Route.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAEzC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEzC,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAA;AAE1C,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,OAAO,CAAA;IACjB,IAAI,EAAE,QAAQ,CAAA;IACd,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,UAAU,CAAC,EAAE,UAAU,CAAA;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,QAAQ,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,YAAY,GAAG,IAAI,CAAA;CAC7C;AAED,MAAM,MAAM,kBAAkB,GAAG,OAAO,CACtC,UAAU,GAAG,kBAAkB,GAAG,kBAAkB,CACrD,CAAA;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,GAAG,CAAC,OAAO,CAAA;AACrD,wBAAgB,KAAK,CAAC,KAAK,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAAA;AAC7D,wBAAgB,KAAK,CAAC,KAAK,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Route_exports = {};
|
|
30
|
+
__export(Route_exports, {
|
|
31
|
+
Route: () => Route
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(Route_exports);
|
|
34
|
+
var import_react = __toESM(require("react"), 1);
|
|
35
|
+
function Route(_props) {
|
|
36
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null);
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
Route
|
|
41
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export type WrapperType<WTProps> = (props: Omit<WTProps, 'wrap' | 'children'> & {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}) => ReactElement | null;
|
|
6
|
+
type SetProps<P> = P & {
|
|
7
|
+
/**
|
|
8
|
+
* P is the interface for the props that are forwarded to the wrapper
|
|
9
|
+
* components. TypeScript will most likely infer this for you, but if you
|
|
10
|
+
* need to you can specify it yourself in your JSX like so:
|
|
11
|
+
* <Set<{theme: string}> wrap={ThemableLayout} theme="dark">
|
|
12
|
+
*/
|
|
13
|
+
wrap?: WrapperType<P> | WrapperType<P>[];
|
|
14
|
+
/**
|
|
15
|
+
*`Routes` nested in a `<Set>` with `private` specified require
|
|
16
|
+
* authentication. When a user is not authenticated and attempts to visit
|
|
17
|
+
* the wrapped route they will be redirected to `unauthenticated` route.
|
|
18
|
+
*
|
|
19
|
+
* @deprecated Please use `<PrivateSet>` instead
|
|
20
|
+
*/
|
|
21
|
+
private?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The page name where a user will be redirected when not authenticated
|
|
24
|
+
*
|
|
25
|
+
* @deprecated Please use `<PrivateSet>` instead and specify this prop there
|
|
26
|
+
*/
|
|
27
|
+
unauthenticated?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Route is permitted when authenticated and user has any of the provided
|
|
30
|
+
* roles such as "admin" or ["admin", "editor"]
|
|
31
|
+
*/
|
|
32
|
+
roles?: string | string[];
|
|
33
|
+
/** Prerender all pages in the set */
|
|
34
|
+
prerender?: boolean;
|
|
35
|
+
children: ReactNode;
|
|
36
|
+
/** Loading state for auth to distinguish with whileLoading */
|
|
37
|
+
whileLoadingAuth?: () => ReactElement | null;
|
|
38
|
+
whileLoadingPage?: () => ReactElement | null;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* TypeScript will often infer the type of the props you can forward to the
|
|
42
|
+
* wrappers for you, but if you need to you can specify it yourself in your
|
|
43
|
+
* JSX like so:
|
|
44
|
+
* <Set<{theme: string}> wrap={ThemeableLayout} theme="dark">
|
|
45
|
+
*/
|
|
46
|
+
export declare function Set<WrapperProps>(props: SetProps<WrapperProps>): React.JSX.Element;
|
|
47
|
+
type PrivateSetProps<P> = P & Omit<SetProps<P>, 'private' | 'unauthenticated'> & {
|
|
48
|
+
/** The page name where a user will be redirected when not authenticated */
|
|
49
|
+
unauthenticated: string;
|
|
50
|
+
};
|
|
51
|
+
/** @deprecated Please use `<PrivateSet>` instead */
|
|
52
|
+
export declare function Private<WrapperProps>(props: PrivateSetProps<WrapperProps>): React.JSX.Element;
|
|
53
|
+
export declare function PrivateSet<WrapperProps>(props: PrivateSetProps<WrapperProps>): React.JSX.Element;
|
|
54
|
+
export declare const isSetNode: (node: ReactNode) => node is ReactElement<SetProps<any>>;
|
|
55
|
+
export declare const isPrivateSetNode: (node: ReactNode) => node is ReactElement<PrivateSetProps<unknown>>;
|
|
56
|
+
export declare const isPrivateNode: (node: ReactNode) => node is ReactElement<SetProps<any>>;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=Set.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Set.d.ts","sourceRoot":"","sources":["../../src/Set.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACpD,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,MAAM,WAAW,CAAC,OAAO,IAAI,CACjC,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC,GAAG;IAC1C,QAAQ,EAAE,SAAS,CAAA;CACpB,KACE,YAAY,GAAG,IAAI,CAAA;AAExB,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG;IACrB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,CAAA;IACxC;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACzB,qCAAqC;IACrC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,QAAQ,EAAE,SAAS,CAAA;IACnB,8DAA8D;IAC9D,gBAAgB,CAAC,EAAE,MAAM,YAAY,GAAG,IAAI,CAAA;IAC5C,gBAAgB,CAAC,EAAE,MAAM,YAAY,GAAG,IAAI,CAAA;CAC7C,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,YAAY,EAAE,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,qBAI9D;AAED,KAAK,eAAe,CAAC,CAAC,IAAI,CAAC,GACzB,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,GAAG,iBAAiB,CAAC,GAAG;IACjD,2EAA2E;IAC3E,eAAe,EAAE,MAAM,CAAA;CACxB,CAAA;AAEH,oDAAoD;AACpD,wBAAgB,OAAO,CAAC,YAAY,EAAE,KAAK,EAAE,eAAe,CAAC,YAAY,CAAC,qBAIzE;AAED,wBAAgB,UAAU,CAAC,YAAY,EAAE,KAAK,EAAE,eAAe,CAAC,YAAY,CAAC,qBAI5E;AAED,eAAO,MAAM,SAAS,SACd,SAAS,KACd,IAAI,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAOpC,CAAA;AAED,eAAO,MAAM,gBAAgB,SACrB,SAAS,KACd,IAAI,IAAI,YAAY,CAAC,eAAe,CAAC,OAAO,CAAC,CAE/C,CAAA;AAGD,eAAO,MAAM,aAAa,SAClB,SAAS,KACd,IAAI,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAEpC,CAAA"}
|
package/dist/cjs/Set.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Set_exports = {};
|
|
30
|
+
__export(Set_exports, {
|
|
31
|
+
Private: () => Private,
|
|
32
|
+
PrivateSet: () => PrivateSet,
|
|
33
|
+
Set: () => Set,
|
|
34
|
+
isPrivateNode: () => isPrivateNode,
|
|
35
|
+
isPrivateSetNode: () => isPrivateSetNode,
|
|
36
|
+
isSetNode: () => isSetNode
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(Set_exports);
|
|
39
|
+
var import_react = __toESM(require("react"), 1);
|
|
40
|
+
function Set(props) {
|
|
41
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.children);
|
|
42
|
+
}
|
|
43
|
+
function Private(props) {
|
|
44
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.children);
|
|
45
|
+
}
|
|
46
|
+
function PrivateSet(props) {
|
|
47
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.children);
|
|
48
|
+
}
|
|
49
|
+
const isSetNode = (node) => {
|
|
50
|
+
return import_react.default.isValidElement(node) && (node.type === Set || node.type === PrivateSet || node.type === Private) && // Don't even bother including Sets without children. They're useless.
|
|
51
|
+
node.props.children;
|
|
52
|
+
};
|
|
53
|
+
const isPrivateSetNode = (node) => {
|
|
54
|
+
return import_react.default.isValidElement(node) && node.type === PrivateSet;
|
|
55
|
+
};
|
|
56
|
+
const isPrivateNode = (node) => {
|
|
57
|
+
return import_react.default.isValidElement(node) && node.type === Private;
|
|
58
|
+
};
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
Private,
|
|
62
|
+
PrivateSet,
|
|
63
|
+
Set,
|
|
64
|
+
isPrivateNode,
|
|
65
|
+
isPrivateSetNode,
|
|
66
|
+
isSetNode
|
|
67
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gets the announcement for the new page.
|
|
3
|
+
* called in one of active-route-loader's `useEffect`.
|
|
4
|
+
*
|
|
5
|
+
* the order of priority is:
|
|
6
|
+
* 1. RouteAnnouncement (the most specific one)
|
|
7
|
+
* 2. h1
|
|
8
|
+
* 3. document.title
|
|
9
|
+
* 4. location.pathname
|
|
10
|
+
*/
|
|
11
|
+
export declare const getAnnouncement: () => string;
|
|
12
|
+
export declare const getFocus: () => HTMLElement | null;
|
|
13
|
+
export declare const resetFocus: () => void;
|
|
14
|
+
//# sourceMappingURL=a11yUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a11yUtils.d.ts","sourceRoot":"","sources":["../../src/a11yUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,cAkB3B,CAAA;AAED,eAAO,MAAM,QAAQ,0BAapB,CAAA;AAGD,eAAO,MAAM,UAAU,YAItB,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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 a11yUtils_exports = {};
|
|
20
|
+
__export(a11yUtils_exports, {
|
|
21
|
+
getAnnouncement: () => getAnnouncement,
|
|
22
|
+
getFocus: () => getFocus,
|
|
23
|
+
resetFocus: () => resetFocus
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(a11yUtils_exports);
|
|
26
|
+
const getAnnouncement = () => {
|
|
27
|
+
const routeAnnouncement = globalThis?.document.querySelectorAll(
|
|
28
|
+
"[data-redwood-route-announcement]"
|
|
29
|
+
)?.[0];
|
|
30
|
+
if (routeAnnouncement?.textContent) {
|
|
31
|
+
return routeAnnouncement.textContent;
|
|
32
|
+
}
|
|
33
|
+
const pageHeading = globalThis?.document.querySelector(`h1`);
|
|
34
|
+
if (pageHeading?.textContent) {
|
|
35
|
+
return pageHeading.textContent;
|
|
36
|
+
}
|
|
37
|
+
if (globalThis?.document.title) {
|
|
38
|
+
return document.title;
|
|
39
|
+
}
|
|
40
|
+
return `new page at ${globalThis?.location.pathname}`;
|
|
41
|
+
};
|
|
42
|
+
const getFocus = () => {
|
|
43
|
+
const routeFocus = globalThis?.document.querySelectorAll(
|
|
44
|
+
"[data-redwood-route-focus]"
|
|
45
|
+
)?.[0];
|
|
46
|
+
if (!routeFocus?.children.length || routeFocus.children[0].tabIndex < 0) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return routeFocus.children[0];
|
|
50
|
+
};
|
|
51
|
+
const resetFocus = () => {
|
|
52
|
+
globalThis?.document.body.setAttribute("tabindex", "-1");
|
|
53
|
+
globalThis?.document.body.focus();
|
|
54
|
+
globalThis?.document.body.removeAttribute("tabindex");
|
|
55
|
+
};
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
getAnnouncement,
|
|
59
|
+
getFocus,
|
|
60
|
+
resetFocus
|
|
61
|
+
});
|