@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,207 @@
|
|
|
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 router_exports = {};
|
|
30
|
+
__export(router_exports, {
|
|
31
|
+
Router: () => Router
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(router_exports);
|
|
34
|
+
var import_react = __toESM(require("react"), 1);
|
|
35
|
+
var import_active_route_loader = require("./active-route-loader.js");
|
|
36
|
+
var import_analyzeRoutes = require("./analyzeRoutes.js");
|
|
37
|
+
var import_AuthenticatedRoute = require("./AuthenticatedRoute.js");
|
|
38
|
+
var import_location = require("./location.js");
|
|
39
|
+
var import_namedRoutes = require("./namedRoutes.js");
|
|
40
|
+
var import_page = require("./page.js");
|
|
41
|
+
var import_PageLoadingContext = require("./PageLoadingContext.js");
|
|
42
|
+
var import_params = require("./params.js");
|
|
43
|
+
var import_redirect = require("./redirect.js");
|
|
44
|
+
var import_router_context = require("./router-context.js");
|
|
45
|
+
var import_splash_page = require("./splash-page.js");
|
|
46
|
+
var import_util = require("./util.js");
|
|
47
|
+
const Router = ({
|
|
48
|
+
useAuth,
|
|
49
|
+
paramTypes,
|
|
50
|
+
pageLoadingDelay,
|
|
51
|
+
trailingSlashes = "never",
|
|
52
|
+
children
|
|
53
|
+
}) => {
|
|
54
|
+
return (
|
|
55
|
+
// Level 1/3 (outer-most)
|
|
56
|
+
// Wrap it in the provider so that useLocation can be used
|
|
57
|
+
/* @__PURE__ */ import_react.default.createElement(import_location.LocationProvider, { trailingSlashes }, /* @__PURE__ */ import_react.default.createElement(
|
|
58
|
+
LocationAwareRouter,
|
|
59
|
+
{
|
|
60
|
+
useAuth,
|
|
61
|
+
paramTypes,
|
|
62
|
+
pageLoadingDelay
|
|
63
|
+
},
|
|
64
|
+
children
|
|
65
|
+
))
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
const LocationAwareRouter = ({
|
|
69
|
+
useAuth,
|
|
70
|
+
paramTypes,
|
|
71
|
+
pageLoadingDelay,
|
|
72
|
+
children
|
|
73
|
+
}) => {
|
|
74
|
+
const location = (0, import_location.useLocation)();
|
|
75
|
+
const analyzeRoutesResult = (0, import_react.useMemo)(() => {
|
|
76
|
+
return (0, import_analyzeRoutes.analyzeRoutes)(children, {
|
|
77
|
+
currentPathName: location.pathname,
|
|
78
|
+
// @TODO We haven't handled this with SSR/Streaming yet.
|
|
79
|
+
// May need a babel plugin to extract userParamTypes from Routes.tsx
|
|
80
|
+
userParamTypes: paramTypes
|
|
81
|
+
});
|
|
82
|
+
}, [location.pathname, children, paramTypes]);
|
|
83
|
+
const {
|
|
84
|
+
pathRouteMap,
|
|
85
|
+
hasRootRoute,
|
|
86
|
+
namedRoutesMap,
|
|
87
|
+
NotFoundPage,
|
|
88
|
+
activeRoutePath
|
|
89
|
+
} = analyzeRoutesResult;
|
|
90
|
+
const hasGeneratedRoutes = hasCustomRoutes(namedRoutesMap);
|
|
91
|
+
const splashPageExists = typeof import_splash_page.SplashPage !== "undefined";
|
|
92
|
+
const isOnNonExistentRootRoute = !hasRootRoute && location.pathname === "/";
|
|
93
|
+
if (!hasRootRoute && splashPageExists) {
|
|
94
|
+
namedRoutesMap["home"] = () => "/";
|
|
95
|
+
}
|
|
96
|
+
Object.assign(import_namedRoutes.namedRoutes, namedRoutesMap);
|
|
97
|
+
const shouldShowSplash = (isOnNonExistentRootRoute || !hasGeneratedRoutes) && splashPageExists;
|
|
98
|
+
if (shouldShowSplash) {
|
|
99
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
100
|
+
import_splash_page.SplashPage,
|
|
101
|
+
{
|
|
102
|
+
hasGeneratedRoutes,
|
|
103
|
+
allStandardRoutes: pathRouteMap
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
if (!activeRoutePath) {
|
|
108
|
+
if (NotFoundPage) {
|
|
109
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
110
|
+
import_router_context.RouterContextProvider,
|
|
111
|
+
{
|
|
112
|
+
useAuth,
|
|
113
|
+
paramTypes,
|
|
114
|
+
routes: analyzeRoutesResult
|
|
115
|
+
},
|
|
116
|
+
/* @__PURE__ */ import_react.default.createElement(import_params.ParamsProvider, null, /* @__PURE__ */ import_react.default.createElement(import_PageLoadingContext.PageLoadingContextProvider, { delay: pageLoadingDelay }, /* @__PURE__ */ import_react.default.createElement(
|
|
117
|
+
import_active_route_loader.ActiveRouteLoader,
|
|
118
|
+
{
|
|
119
|
+
spec: (0, import_page.normalizePage)(NotFoundPage),
|
|
120
|
+
path: location.pathname
|
|
121
|
+
}
|
|
122
|
+
)))
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const { path, page, name, redirect, whileLoadingPage, sets } = pathRouteMap[activeRoutePath];
|
|
128
|
+
if (!path) {
|
|
129
|
+
throw new Error(`Route "${name}" needs to specify a path`);
|
|
130
|
+
}
|
|
131
|
+
(0, import_util.validatePath)(path, name || path);
|
|
132
|
+
const { params: pathParams } = (0, import_util.matchPath)(path, location.pathname, {
|
|
133
|
+
userParamTypes: paramTypes
|
|
134
|
+
});
|
|
135
|
+
const searchParams = (0, import_util.parseSearch)(location.search);
|
|
136
|
+
const allParams = { ...searchParams, ...pathParams };
|
|
137
|
+
let redirectPath = void 0;
|
|
138
|
+
if (redirect) {
|
|
139
|
+
if (redirect.startsWith("/")) {
|
|
140
|
+
redirectPath = (0, import_util.replaceParams)(redirect, allParams);
|
|
141
|
+
} else {
|
|
142
|
+
const redirectRouteObject = Object.values(pathRouteMap).find(
|
|
143
|
+
(route) => route.name === redirect
|
|
144
|
+
);
|
|
145
|
+
if (!redirectRouteObject) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
`Redirect target route "${redirect}" does not exist for route "${name}"`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
redirectPath = (0, import_util.replaceParams)(redirectRouteObject.path, allParams);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
154
|
+
import_router_context.RouterContextProvider,
|
|
155
|
+
{
|
|
156
|
+
useAuth,
|
|
157
|
+
paramTypes,
|
|
158
|
+
routes: analyzeRoutesResult,
|
|
159
|
+
activeRouteName: name
|
|
160
|
+
},
|
|
161
|
+
/* @__PURE__ */ import_react.default.createElement(import_params.ParamsProvider, { allParams }, /* @__PURE__ */ import_react.default.createElement(import_PageLoadingContext.PageLoadingContextProvider, { delay: pageLoadingDelay }, redirectPath && /* @__PURE__ */ import_react.default.createElement(import_redirect.Redirect, { to: redirectPath }), !redirectPath && page && /* @__PURE__ */ import_react.default.createElement(WrappedPage, { sets }, /* @__PURE__ */ import_react.default.createElement(
|
|
162
|
+
import_active_route_loader.ActiveRouteLoader,
|
|
163
|
+
{
|
|
164
|
+
path,
|
|
165
|
+
spec: (0, import_page.normalizePage)(page),
|
|
166
|
+
params: allParams,
|
|
167
|
+
whileLoadingPage
|
|
168
|
+
}
|
|
169
|
+
))))
|
|
170
|
+
);
|
|
171
|
+
};
|
|
172
|
+
const WrappedPage = (0, import_react.memo)(({ sets, children }) => {
|
|
173
|
+
if (!sets || sets.length === 0) {
|
|
174
|
+
return children;
|
|
175
|
+
}
|
|
176
|
+
return sets.reduceRight((acc, set) => {
|
|
177
|
+
let wrapped = set.wrappers.reduceRight((acc2, Wrapper, index) => {
|
|
178
|
+
return import_react.default.createElement(
|
|
179
|
+
Wrapper,
|
|
180
|
+
{ ...set.props, key: set.id + "-" + index },
|
|
181
|
+
acc2
|
|
182
|
+
);
|
|
183
|
+
}, acc);
|
|
184
|
+
if (set.isPrivate) {
|
|
185
|
+
const unauthenticated = set.props.unauthenticated;
|
|
186
|
+
if (!unauthenticated || typeof unauthenticated !== "string") {
|
|
187
|
+
throw new Error(
|
|
188
|
+
"You must specify an `unauthenticated` route when using PrivateSet"
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
wrapped = /* @__PURE__ */ import_react.default.createElement(import_AuthenticatedRoute.AuthenticatedRoute, { ...set.props, unauthenticated }, wrapped);
|
|
192
|
+
}
|
|
193
|
+
return wrapped;
|
|
194
|
+
}, children);
|
|
195
|
+
});
|
|
196
|
+
function hasCustomRoutes(obj) {
|
|
197
|
+
for (const prop in obj) {
|
|
198
|
+
if (Object.hasOwn(obj, prop)) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
205
|
+
0 && (module.exports = {
|
|
206
|
+
Router
|
|
207
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientRouter.d.ts","sourceRoot":"","sources":["../../../src/rsc/ClientRouter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAA;AAOtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAI/C,eAAO,MAAM,MAAM,sCAAuC,WAAW,sBASpE,CAAA"}
|
|
@@ -0,0 +1,90 @@
|
|
|
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 ClientRouter_exports = {};
|
|
30
|
+
__export(ClientRouter_exports, {
|
|
31
|
+
Router: () => Router
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(ClientRouter_exports);
|
|
34
|
+
var import_react = __toESM(require("react"), 1);
|
|
35
|
+
var import_analyzeRoutes = require("../analyzeRoutes.js");
|
|
36
|
+
var import_AuthenticatedRoute = require("../AuthenticatedRoute.js");
|
|
37
|
+
var import_location = require("../location.js");
|
|
38
|
+
var import_namedRoutes = require("../namedRoutes.js");
|
|
39
|
+
var import_router_context = require("../router-context.js");
|
|
40
|
+
var import_RscRoutes = require("./RscRoutes.js");
|
|
41
|
+
const Router = ({ useAuth, paramTypes, children }) => {
|
|
42
|
+
return (
|
|
43
|
+
// Wrap it in the provider so that useLocation can be used
|
|
44
|
+
/* @__PURE__ */ import_react.default.createElement(import_location.LocationProvider, null, /* @__PURE__ */ import_react.default.createElement(LocationAwareRouter, { paramTypes, useAuth }, children))
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
const LocationAwareRouter = ({
|
|
48
|
+
useAuth,
|
|
49
|
+
paramTypes,
|
|
50
|
+
children
|
|
51
|
+
}) => {
|
|
52
|
+
const { pathname, search } = (0, import_location.useLocation)();
|
|
53
|
+
const analyzeRoutesResult = (0, import_react.useMemo)(() => {
|
|
54
|
+
return (0, import_analyzeRoutes.analyzeRoutes)(children, {
|
|
55
|
+
currentPathName: pathname,
|
|
56
|
+
userParamTypes: paramTypes
|
|
57
|
+
});
|
|
58
|
+
}, [pathname, children, paramTypes]);
|
|
59
|
+
const { namedRoutesMap, pathRouteMap, activeRoutePath } = analyzeRoutesResult;
|
|
60
|
+
Object.assign(import_namedRoutes.namedRoutes, namedRoutesMap);
|
|
61
|
+
if (!activeRoutePath) {
|
|
62
|
+
return /* @__PURE__ */ import_react.default.createElement(import_RscRoutes.RscRoutes, { pathname, search });
|
|
63
|
+
}
|
|
64
|
+
const requestedRoute = pathRouteMap[activeRoutePath];
|
|
65
|
+
const reversedSets = requestedRoute.sets.toReversed();
|
|
66
|
+
const privateSet = reversedSets.find((set) => set.isPrivate);
|
|
67
|
+
if (privateSet) {
|
|
68
|
+
const unauthenticated = privateSet.props.unauthenticated;
|
|
69
|
+
if (!unauthenticated || typeof unauthenticated !== "string") {
|
|
70
|
+
throw new Error(
|
|
71
|
+
"You must specify an `unauthenticated` route when using PrivateSet"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
75
|
+
import_router_context.RouterContextProvider,
|
|
76
|
+
{
|
|
77
|
+
useAuth,
|
|
78
|
+
paramTypes,
|
|
79
|
+
routes: analyzeRoutesResult,
|
|
80
|
+
activeRouteName: requestedRoute.name
|
|
81
|
+
},
|
|
82
|
+
/* @__PURE__ */ import_react.default.createElement(import_AuthenticatedRoute.AuthenticatedRoute, { unauthenticated }, /* @__PURE__ */ import_react.default.createElement(import_RscRoutes.RscRoutes, { pathname, search }))
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return /* @__PURE__ */ import_react.default.createElement(import_RscRoutes.RscRoutes, { pathname, search });
|
|
86
|
+
};
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
Router
|
|
90
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface RscModel {
|
|
2
|
+
__rwjs__Routes: [React.ReactElement];
|
|
3
|
+
__rwjs__rsa_data?: unknown;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* This cache is used for RSC fetches, so that we don't re-fetch the same
|
|
7
|
+
* component (i.e. page) multiple times and get stuck in a loop.
|
|
8
|
+
*
|
|
9
|
+
* `key`: A stringified location-like object.
|
|
10
|
+
* `value`: A Promise that resolves to a React element.
|
|
11
|
+
*/
|
|
12
|
+
export declare class RscCache {
|
|
13
|
+
private cache;
|
|
14
|
+
private socket;
|
|
15
|
+
private sendRetries;
|
|
16
|
+
private isEnabled;
|
|
17
|
+
constructor();
|
|
18
|
+
get(key: string): Thenable<RscModel> | undefined;
|
|
19
|
+
set(key: string, value: Thenable<RscModel>): void;
|
|
20
|
+
private sendToWebSocket;
|
|
21
|
+
private sendUpdateToWebSocket;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=RscCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RscCache.d.ts","sourceRoot":"","sources":["../../../src/rsc/RscCache.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,cAAc,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;IACpC,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED;;;;;;GAMG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,KAAK,CAAwC;IACrD,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,WAAW,CAAI;IAEvB,OAAO,CAAC,SAAS,CAAQ;;IAgDzB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,GAAG,SAAS;IAMhD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC;IA2B1C,OAAO,CAAC,eAAe;IAsBvB,OAAO,CAAC,qBAAqB;CAW9B"}
|
|
@@ -0,0 +1,110 @@
|
|
|
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 RscCache_exports = {};
|
|
20
|
+
__export(RscCache_exports, {
|
|
21
|
+
RscCache: () => RscCache
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(RscCache_exports);
|
|
24
|
+
class RscCache {
|
|
25
|
+
cache = /* @__PURE__ */ new Map();
|
|
26
|
+
socket;
|
|
27
|
+
sendRetries = 0;
|
|
28
|
+
// Turn the cache off for now. We can turn it on later if we decide we need it
|
|
29
|
+
isEnabled = false;
|
|
30
|
+
constructor() {
|
|
31
|
+
this.socket = new WebSocket("ws://localhost:18998");
|
|
32
|
+
this.socket.addEventListener("open", () => {
|
|
33
|
+
});
|
|
34
|
+
this.socket.addEventListener("message", (event) => {
|
|
35
|
+
if (event.data.startsWith("{")) {
|
|
36
|
+
const data = JSON.parse(event.data);
|
|
37
|
+
if (data.id === "rsc-cache-delete") {
|
|
38
|
+
if (!this.cache.has(data.key)) {
|
|
39
|
+
}
|
|
40
|
+
this.cache.delete(data.key);
|
|
41
|
+
this.sendUpdateToWebSocket();
|
|
42
|
+
} else if (data.id === "rsc-cache-clear") {
|
|
43
|
+
this.cache.clear();
|
|
44
|
+
this.sendToWebSocket("update", { fullCache: {} });
|
|
45
|
+
} else if (data.id === "rsc-cache-enable") {
|
|
46
|
+
this.isEnabled = true;
|
|
47
|
+
this.sendUpdateToWebSocket();
|
|
48
|
+
} else if (data.id === "rsc-cache-disable") {
|
|
49
|
+
this.isEnabled = false;
|
|
50
|
+
} else if (data.id === "rsc-cache-read") {
|
|
51
|
+
this.sendUpdateToWebSocket();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
get(key) {
|
|
57
|
+
const value = this.cache.get(key);
|
|
58
|
+
console.log("RscCache.get", key, value);
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
set(key, value) {
|
|
62
|
+
console.log("RscCache.set", key, value);
|
|
63
|
+
if (!this.isEnabled) {
|
|
64
|
+
this.cache.clear();
|
|
65
|
+
}
|
|
66
|
+
this.cache.set(key, value);
|
|
67
|
+
value.then((_resolvedValue) => {
|
|
68
|
+
this.sendToWebSocket("set", {
|
|
69
|
+
updatedKey: key,
|
|
70
|
+
fullCache: Object.fromEntries(
|
|
71
|
+
Array.from(this.cache.entries()).map(
|
|
72
|
+
// @ts-expect-error hack to get the value of a Thenable
|
|
73
|
+
([location, elementThenable]) => [location, elementThenable.value]
|
|
74
|
+
)
|
|
75
|
+
)
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
sendToWebSocket(action, payload) {
|
|
80
|
+
if (this.socket.readyState === WebSocket?.OPEN) {
|
|
81
|
+
this.sendRetries = 0;
|
|
82
|
+
this.socket.send(JSON.stringify({ id: "rsc-cache-" + action, payload }));
|
|
83
|
+
} else if (this.socket.readyState === WebSocket?.CONNECTING && this.sendRetries < 10) {
|
|
84
|
+
const backoff = 300 + this.sendRetries * 100;
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
this.sendRetries++;
|
|
87
|
+
this.sendToWebSocket(action, payload);
|
|
88
|
+
}, backoff);
|
|
89
|
+
} else if (this.sendRetries >= 10) {
|
|
90
|
+
console.error("Exhausted retries to send message to WebSocket server.");
|
|
91
|
+
} else {
|
|
92
|
+
console.error("WebSocket connection is closed.");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
sendUpdateToWebSocket() {
|
|
96
|
+
this.sendToWebSocket("update", {
|
|
97
|
+
fullCache: Object.fromEntries(
|
|
98
|
+
Array.from(this.cache.entries()).map(([location, elementThenable]) => [
|
|
99
|
+
location,
|
|
100
|
+
// @ts-expect-error hack to get the value of a Thenable
|
|
101
|
+
elementThenable.value
|
|
102
|
+
])
|
|
103
|
+
)
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
RscCache
|
|
110
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
pathname: string;
|
|
3
|
+
search: string;
|
|
4
|
+
}
|
|
5
|
+
export declare const RscRoutes: ({ pathname, search }: Props) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=RscRoutes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RscRoutes.d.ts","sourceRoot":"","sources":["../../../src/rsc/RscRoutes.tsx"],"names":[],"mappings":"AAiIA,UAAU,KAAK;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,eAAO,MAAM,SAAS,yBAA0B,KAAK,2FAkCpD,CAAA"}
|
|
@@ -0,0 +1,124 @@
|
|
|
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 RscRoutes_exports = {};
|
|
20
|
+
__export(RscRoutes_exports, {
|
|
21
|
+
RscRoutes: () => RscRoutes
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(RscRoutes_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
var import_client = require("react-server-dom-webpack/client");
|
|
26
|
+
var import_RscCache = require("./RscCache.js");
|
|
27
|
+
const BASE_PATH = "/rw-rsc/";
|
|
28
|
+
const rscCache = new import_RscCache.RscCache();
|
|
29
|
+
let updateCurrentRscCacheKey = (key) => {
|
|
30
|
+
console.error("updateCurrentRscCacheKey called before it was set");
|
|
31
|
+
console.error("updateCurrentRscCacheKey key", key);
|
|
32
|
+
};
|
|
33
|
+
function onStreamFinished(fetchPromise, onFinished) {
|
|
34
|
+
return fetchPromise.then((response) => response.clone().text()).then(onFinished);
|
|
35
|
+
}
|
|
36
|
+
async function rsaFetch(serializedLocation, rsaId, rsaArgs) {
|
|
37
|
+
const rscId = "_";
|
|
38
|
+
const searchParams = new URLSearchParams();
|
|
39
|
+
searchParams.set("action_id", rsaId);
|
|
40
|
+
const url = BASE_PATH + rscId + "?" + searchParams + "&" + serializedLocation;
|
|
41
|
+
let body = "";
|
|
42
|
+
try {
|
|
43
|
+
body = await (0, import_client.encodeReply)(rsaArgs);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
console.error("Error encoding Server Action arguments", e);
|
|
46
|
+
}
|
|
47
|
+
return fetch(url, {
|
|
48
|
+
method: "POST",
|
|
49
|
+
body,
|
|
50
|
+
headers: { "rw-rsc": "1" }
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function rscFetch(serializedLocation) {
|
|
54
|
+
const rscId = "__rwjs__Routes";
|
|
55
|
+
return fetch(BASE_PATH + rscId + "?" + serializedLocation, {
|
|
56
|
+
headers: { "rw-rsc": "1" }
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function rscFetchRoutes(serializedLocation) {
|
|
60
|
+
console.log(
|
|
61
|
+
"rscFetchRoutes :: args:\n serializedProps: " + serializedLocation
|
|
62
|
+
);
|
|
63
|
+
const rscCacheKey = serializedLocation;
|
|
64
|
+
const cached = rscCache.get(rscCacheKey);
|
|
65
|
+
if (cached) {
|
|
66
|
+
console.log("rscFetchRoutes :: cache hit for", rscCacheKey);
|
|
67
|
+
return cached;
|
|
68
|
+
} else {
|
|
69
|
+
console.log("rscFetchRoutes :: cache miss for", rscCacheKey);
|
|
70
|
+
}
|
|
71
|
+
const options = {
|
|
72
|
+
// React will hold on to `callServer` and use that when it detects a server
|
|
73
|
+
// action is invoked (like `action={onSubmit}` in a <form> element). So for
|
|
74
|
+
// now at least we need to send it with every RSC request, so React knows
|
|
75
|
+
// what `callServer` method to use for server actions inside the RSC.
|
|
76
|
+
// TODO (RSC): Need to figure out the types for callServer
|
|
77
|
+
// @ts-expect-error types
|
|
78
|
+
callServer: async function(rsaId, args) {
|
|
79
|
+
console.log("RscRoutes :: callServer rsaId", rsaId, "args", args);
|
|
80
|
+
const rscCacheKey2 = `${serializedLocation}::${rsaId}::${Date.now()}`;
|
|
81
|
+
const responsePromise = rsaFetch(serializedLocation, rsaId, args);
|
|
82
|
+
onStreamFinished(responsePromise, () => {
|
|
83
|
+
updateCurrentRscCacheKey(rscCacheKey2);
|
|
84
|
+
});
|
|
85
|
+
const modelPromise2 = (0, import_client.createFromFetch)(responsePromise, options);
|
|
86
|
+
rscCache.set(rscCacheKey2, modelPromise2);
|
|
87
|
+
const model = await modelPromise2;
|
|
88
|
+
return model.__rwjs__rsa_data;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const modelPromise = (0, import_client.createFromFetch)(rscFetch(serializedLocation), options);
|
|
92
|
+
rscCache.set(rscCacheKey, modelPromise);
|
|
93
|
+
return modelPromise;
|
|
94
|
+
}
|
|
95
|
+
const RscRoutes = ({ pathname, search }) => {
|
|
96
|
+
const serializedLocation = `__rwjs__pathname=${pathname}&__rwjs__search=${search}`;
|
|
97
|
+
const [currentRscCacheKey, setCurrentRscCacheKey] = (0, import_react.useState)(() => {
|
|
98
|
+
console.log("RscRoutes :: useState initial value");
|
|
99
|
+
rscFetchRoutes(serializedLocation);
|
|
100
|
+
return serializedLocation;
|
|
101
|
+
});
|
|
102
|
+
(0, import_react.useEffect)(() => {
|
|
103
|
+
console.log("RscRoutes :: useEffect set updateCurrentRscCacheKey");
|
|
104
|
+
updateCurrentRscCacheKey = (key) => {
|
|
105
|
+
console.log("RscRoutes inside updateCurrentRscCacheKey", key);
|
|
106
|
+
setCurrentRscCacheKey(key);
|
|
107
|
+
};
|
|
108
|
+
}, []);
|
|
109
|
+
(0, import_react.useEffect)(() => {
|
|
110
|
+
console.log("RscRoutes :: useEffect about to call rscFetchRoutes");
|
|
111
|
+
rscFetchRoutes(serializedLocation);
|
|
112
|
+
setCurrentRscCacheKey(serializedLocation);
|
|
113
|
+
}, [serializedLocation]);
|
|
114
|
+
console.log("RscRoutes :: rendering cache entry for\n" + currentRscCacheKey);
|
|
115
|
+
const rscModelPromise = rscCache.get(currentRscCacheKey);
|
|
116
|
+
if (!rscModelPromise) {
|
|
117
|
+
throw new Error("Missing RSC cache entry for " + currentRscCacheKey);
|
|
118
|
+
}
|
|
119
|
+
return (0, import_react.use)(rscModelPromise).__rwjs__Routes[0];
|
|
120
|
+
};
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
RscRoutes
|
|
124
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Spec } from '../page.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
path: string;
|
|
5
|
+
spec: Spec;
|
|
6
|
+
params?: Record<string, string>;
|
|
7
|
+
whileLoadingPage?: () => React.ReactNode | null;
|
|
8
|
+
children?: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export declare const ServerRouteLoader: ({ spec, params }: Props) => React.JSX.Element;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=ServerRouteLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerRouteLoader.d.ts","sourceRoot":"","sources":["../../../src/rsc/ServerRouteLoader.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAEvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEtC,UAAU,KAAK;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,gBAAgB,CAAC,EAAE,MAAM,KAAK,CAAC,SAAS,GAAG,IAAI,CAAA;IAC/C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B;AAED,eAAO,MAAM,iBAAiB,qBAAsB,KAAK,sBA+BxD,CAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 ServerRouteLoader_exports = {};
|
|
30
|
+
__export(ServerRouteLoader_exports, {
|
|
31
|
+
ServerRouteLoader: () => ServerRouteLoader
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(ServerRouteLoader_exports);
|
|
34
|
+
var import_react = __toESM(require("react"), 1);
|
|
35
|
+
const ServerRouteLoader = ({ spec, params }) => {
|
|
36
|
+
const LazyRouteComponent = spec.LazyComponent;
|
|
37
|
+
if (params) {
|
|
38
|
+
delete params["ref"];
|
|
39
|
+
delete params["key"];
|
|
40
|
+
}
|
|
41
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.Suspense, { fallback: /* @__PURE__ */ import_react.default.createElement("div", null, "Loading...") }, /* @__PURE__ */ import_react.default.createElement(LazyRouteComponent, { ...params }), /* @__PURE__ */ import_react.default.createElement(
|
|
42
|
+
"div",
|
|
43
|
+
{
|
|
44
|
+
id: "redwood-announcer",
|
|
45
|
+
style: {
|
|
46
|
+
position: "absolute",
|
|
47
|
+
top: 0,
|
|
48
|
+
width: 1,
|
|
49
|
+
height: 1,
|
|
50
|
+
padding: 0,
|
|
51
|
+
overflow: "hidden",
|
|
52
|
+
clip: "rect(0, 0, 0, 0)",
|
|
53
|
+
whiteSpace: "nowrap",
|
|
54
|
+
border: 0
|
|
55
|
+
},
|
|
56
|
+
role: "alert",
|
|
57
|
+
"aria-live": "assertive",
|
|
58
|
+
"aria-atomic": "true"
|
|
59
|
+
}
|
|
60
|
+
));
|
|
61
|
+
};
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
ServerRouteLoader
|
|
65
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { RouterContextProviderProps } from '../router-context.js';
|
|
4
|
+
import type { TrailingSlashesTypes } from '../util.js';
|
|
5
|
+
export interface RouterProps extends Omit<RouterContextProviderProps, 'routes' | 'activeRouteName'> {
|
|
6
|
+
trailingSlashes?: TrailingSlashesTypes;
|
|
7
|
+
pageLoadingDelay?: number;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export declare const Router: React.FC<RouterProps>;
|
|
11
|
+
//# sourceMappingURL=ServerRouter.d.ts.map
|