one 1.21.6 → 1.21.8
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/dist/cjs/cli/dev.native.js.map +1 -1
- package/dist/cjs/cli.cjs +0 -3
- package/dist/cjs/cli.native.js +0 -3
- package/dist/cjs/cli.native.js.map +1 -1
- package/dist/cjs/image/getImageData.cjs +1 -1
- package/dist/cjs/image/getImageData.native.js +1 -1
- package/dist/cjs/image/getImageData.native.js.map +1 -1
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/layouts/Stack.cjs +5 -5
- package/dist/cjs/layouts/Stack.native.js +5 -5
- package/dist/cjs/layouts/Stack.native.js.map +1 -1
- package/dist/cjs/layouts/stack-utils/StackScreen.cjs +3 -0
- package/dist/cjs/layouts/stack-utils/StackScreen.native.js +3 -0
- package/dist/cjs/layouts/stack-utils/StackScreen.native.js.map +1 -1
- package/dist/cjs/layouts/stack-utils/StackToolbar.cjs +419 -0
- package/dist/cjs/layouts/stack-utils/StackToolbar.native.js +453 -0
- package/dist/cjs/layouts/stack-utils/StackToolbar.native.js.map +1 -0
- package/dist/cjs/layouts/stack-utils/StackToolbar.types.cjs +18 -0
- package/dist/cjs/layouts/stack-utils/StackToolbar.types.native.js +21 -0
- package/dist/cjs/layouts/stack-utils/StackToolbar.types.native.js.map +1 -0
- package/dist/cjs/layouts/stack-utils/__tests__/StackToolbar.runtime.test.cjs +63 -0
- package/dist/cjs/layouts/stack-utils/__tests__/StackToolbar.runtime.test.native.js +73 -0
- package/dist/cjs/layouts/stack-utils/__tests__/StackToolbar.runtime.test.native.js.map +1 -0
- package/dist/cjs/layouts/stack-utils/__tests__/composition.test.cjs +205 -0
- package/dist/cjs/layouts/stack-utils/__tests__/composition.test.native.js +220 -0
- package/dist/cjs/layouts/stack-utils/__tests__/composition.test.native.js.map +1 -1
- package/dist/cjs/layouts/stack-utils/index.cjs +2 -0
- package/dist/cjs/layouts/stack-utils/index.native.js +2 -0
- package/dist/cjs/layouts/stack-utils/index.native.js.map +1 -1
- package/dist/cjs/layouts/withLayoutContext.cjs +39 -8
- package/dist/cjs/layouts/withLayoutContext.native.js +43 -8
- package/dist/cjs/layouts/withLayoutContext.native.js.map +1 -1
- package/dist/cjs/layouts/withLayoutContext.test.cjs +96 -0
- package/dist/cjs/layouts/withLayoutContext.test.native.js +100 -0
- package/dist/cjs/layouts/withLayoutContext.test.native.js.map +1 -0
- package/dist/cjs/router/Route.cjs +3 -0
- package/dist/cjs/router/Route.native.js +3 -0
- package/dist/cjs/router/Route.native.js.map +1 -1
- package/dist/cjs/router/protectedRoutes.test.cjs +22 -0
- package/dist/cjs/router/protectedRoutes.test.native.js +25 -0
- package/dist/cjs/router/protectedRoutes.test.native.js.map +1 -0
- package/dist/cjs/router/router.cjs +26 -8
- package/dist/cjs/router/router.native.js +26 -8
- package/dist/cjs/router/router.native.js.map +1 -1
- package/dist/cjs/router/useScreens.cjs +38 -11
- package/dist/cjs/router/useScreens.native.js +39 -11
- package/dist/cjs/router/useScreens.native.js.map +1 -1
- package/dist/cjs/router/useScreens.test.cjs +134 -0
- package/dist/cjs/router/useScreens.test.native.js +163 -0
- package/dist/cjs/router/useScreens.test.native.js.map +1 -0
- package/dist/cjs/views/Navigator.cjs +14 -6
- package/dist/cjs/views/Navigator.native.js +14 -6
- package/dist/cjs/views/Navigator.native.js.map +1 -1
- package/dist/cjs/views/Protected.native.js.map +1 -1
- package/dist/cjs/views/SuspenseFallback.cjs +18 -0
- package/dist/cjs/views/SuspenseFallback.native.js +21 -0
- package/dist/cjs/views/SuspenseFallback.native.js.map +1 -0
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.cjs +47 -7
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js +47 -7
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.test.cjs +15 -6
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.test.native.js +15 -6
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.test.native.js.map +1 -1
- package/dist/esm/cli/dev.mjs.map +1 -1
- package/dist/esm/cli/dev.native.js.map +1 -1
- package/dist/esm/cli.mjs +0 -3
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/cli.native.js +0 -3
- package/dist/esm/cli.native.js.map +1 -1
- package/dist/esm/image/getImageData.mjs +1 -1
- package/dist/esm/image/getImageData.mjs.map +1 -1
- package/dist/esm/image/getImageData.native.js +1 -1
- package/dist/esm/image/getImageData.native.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/layouts/Stack.mjs +6 -6
- package/dist/esm/layouts/Stack.mjs.map +1 -1
- package/dist/esm/layouts/Stack.native.js +6 -6
- package/dist/esm/layouts/Stack.native.js.map +1 -1
- package/dist/esm/layouts/stack-utils/StackScreen.mjs +3 -0
- package/dist/esm/layouts/stack-utils/StackScreen.mjs.map +1 -1
- package/dist/esm/layouts/stack-utils/StackScreen.native.js +3 -0
- package/dist/esm/layouts/stack-utils/StackScreen.native.js.map +1 -1
- package/dist/esm/layouts/stack-utils/StackToolbar.mjs +384 -0
- package/dist/esm/layouts/stack-utils/StackToolbar.mjs.map +1 -0
- package/dist/esm/layouts/stack-utils/StackToolbar.native.js +416 -0
- package/dist/esm/layouts/stack-utils/StackToolbar.native.js.map +1 -0
- package/dist/esm/layouts/stack-utils/StackToolbar.types.mjs +2 -0
- package/dist/esm/layouts/stack-utils/StackToolbar.types.mjs.map +1 -0
- package/dist/esm/layouts/stack-utils/StackToolbar.types.native.js +2 -0
- package/dist/esm/layouts/stack-utils/StackToolbar.types.native.js.map +1 -0
- package/dist/esm/layouts/stack-utils/__tests__/StackToolbar.runtime.test.mjs +40 -0
- package/dist/esm/layouts/stack-utils/__tests__/StackToolbar.runtime.test.mjs.map +1 -0
- package/dist/esm/layouts/stack-utils/__tests__/StackToolbar.runtime.test.native.js +47 -0
- package/dist/esm/layouts/stack-utils/__tests__/StackToolbar.runtime.test.native.js.map +1 -0
- package/dist/esm/layouts/stack-utils/__tests__/composition.test.mjs +205 -0
- package/dist/esm/layouts/stack-utils/__tests__/composition.test.mjs.map +1 -1
- package/dist/esm/layouts/stack-utils/__tests__/composition.test.native.js +220 -0
- package/dist/esm/layouts/stack-utils/__tests__/composition.test.native.js.map +1 -1
- package/dist/esm/layouts/stack-utils/index.mjs +2 -1
- package/dist/esm/layouts/stack-utils/index.mjs.map +1 -1
- package/dist/esm/layouts/stack-utils/index.native.js +2 -1
- package/dist/esm/layouts/stack-utils/index.native.js.map +1 -1
- package/dist/esm/layouts/withLayoutContext.mjs +41 -11
- package/dist/esm/layouts/withLayoutContext.mjs.map +1 -1
- package/dist/esm/layouts/withLayoutContext.native.js +45 -11
- package/dist/esm/layouts/withLayoutContext.native.js.map +1 -1
- package/dist/esm/layouts/withLayoutContext.test.mjs +73 -0
- package/dist/esm/layouts/withLayoutContext.test.mjs.map +1 -0
- package/dist/esm/layouts/withLayoutContext.test.native.js +74 -0
- package/dist/esm/layouts/withLayoutContext.test.native.js.map +1 -0
- package/dist/esm/router/Route.mjs +3 -1
- package/dist/esm/router/Route.mjs.map +1 -1
- package/dist/esm/router/Route.native.js +3 -1
- package/dist/esm/router/Route.native.js.map +1 -1
- package/dist/esm/router/protectedRoutes.test.mjs +23 -0
- package/dist/esm/router/protectedRoutes.test.mjs.map +1 -0
- package/dist/esm/router/protectedRoutes.test.native.js +23 -0
- package/dist/esm/router/protectedRoutes.test.native.js.map +1 -0
- package/dist/esm/router/router.mjs +26 -9
- package/dist/esm/router/router.mjs.map +1 -1
- package/dist/esm/router/router.native.js +26 -9
- package/dist/esm/router/router.native.js.map +1 -1
- package/dist/esm/router/useScreens.mjs +39 -11
- package/dist/esm/router/useScreens.mjs.map +1 -1
- package/dist/esm/router/useScreens.native.js +40 -11
- package/dist/esm/router/useScreens.native.js.map +1 -1
- package/dist/esm/router/useScreens.test.mjs +105 -0
- package/dist/esm/router/useScreens.test.mjs.map +1 -0
- package/dist/esm/router/useScreens.test.native.js +130 -0
- package/dist/esm/router/useScreens.test.native.js.map +1 -0
- package/dist/esm/views/Navigator.mjs +15 -7
- package/dist/esm/views/Navigator.mjs.map +1 -1
- package/dist/esm/views/Navigator.native.js +15 -7
- package/dist/esm/views/Navigator.native.js.map +1 -1
- package/dist/esm/views/Protected.mjs.map +1 -1
- package/dist/esm/views/Protected.native.js.map +1 -1
- package/dist/esm/views/SuspenseFallback.mjs +2 -0
- package/dist/esm/views/SuspenseFallback.mjs.map +1 -0
- package/dist/esm/views/SuspenseFallback.native.js +2 -0
- package/dist/esm/views/SuspenseFallback.native.js.map +1 -0
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs +47 -7
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js +47 -7
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.test.mjs +15 -6
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.test.mjs.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.test.native.js +15 -6
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.test.native.js.map +1 -1
- package/package.json +12 -11
- package/src/cli/dev.ts +0 -1
- package/src/cli.ts +0 -3
- package/src/image/getImageData.ts +2 -2
- package/src/index.ts +12 -0
- package/src/layouts/Stack.tsx +6 -4
- package/src/layouts/stack-utils/README.md +1 -0
- package/src/layouts/stack-utils/StackScreen.tsx +7 -0
- package/src/layouts/stack-utils/StackToolbar.tsx +550 -0
- package/src/layouts/stack-utils/StackToolbar.types.ts +98 -0
- package/src/layouts/stack-utils/__tests__/StackToolbar.runtime.test.tsx +46 -0
- package/src/layouts/stack-utils/__tests__/composition.test.tsx +176 -0
- package/src/layouts/stack-utils/index.tsx +16 -0
- package/src/layouts/withLayoutContext.test.tsx +74 -0
- package/src/layouts/withLayoutContext.tsx +71 -12
- package/src/router/Route.tsx +8 -0
- package/src/router/protectedRoutes.test.ts +35 -0
- package/src/router/router.ts +48 -20
- package/src/router/useScreens.test.tsx +139 -0
- package/src/router/useScreens.tsx +59 -13
- package/src/views/Navigator.tsx +25 -5
- package/src/views/Protected.tsx +3 -0
- package/src/views/SuspenseFallback.ts +7 -0
- package/src/vite/plugins/fileSystemRouterPlugin.test.ts +15 -6
- package/src/vite/plugins/fileSystemRouterPlugin.tsx +52 -7
- package/types/cli/dev.d.ts +0 -1
- package/types/cli/dev.d.ts.map +1 -1
- package/types/image/getImageData.d.ts +1 -1
- package/types/image/getImageData.d.ts.map +1 -1
- package/types/index.d.ts +2 -1
- package/types/index.d.ts.map +1 -1
- package/types/layouts/Stack.d.ts +11 -0
- package/types/layouts/Stack.d.ts.map +1 -1
- package/types/layouts/stack-utils/StackScreen.d.ts.map +1 -1
- package/types/layouts/stack-utils/StackToolbar.d.ts +26 -0
- package/types/layouts/stack-utils/StackToolbar.d.ts.map +1 -0
- package/types/layouts/stack-utils/StackToolbar.types.d.ts +82 -0
- package/types/layouts/stack-utils/StackToolbar.types.d.ts.map +1 -0
- package/types/layouts/stack-utils/index.d.ts +3 -1
- package/types/layouts/stack-utils/index.d.ts.map +1 -1
- package/types/layouts/withLayoutContext.d.ts +7 -0
- package/types/layouts/withLayoutContext.d.ts.map +1 -1
- package/types/layouts/withLayoutContext.test.d.ts +2 -0
- package/types/layouts/withLayoutContext.test.d.ts.map +1 -0
- package/types/router/Route.d.ts +4 -0
- package/types/router/Route.d.ts.map +1 -1
- package/types/router/protectedRoutes.test.d.ts +2 -0
- package/types/router/protectedRoutes.test.d.ts.map +1 -0
- package/types/router/router.d.ts +4 -6
- package/types/router/router.d.ts.map +1 -1
- package/types/router/useScreens.d.ts.map +1 -1
- package/types/router/useScreens.test.d.ts +2 -0
- package/types/router/useScreens.test.d.ts.map +1 -0
- package/types/views/Navigator.d.ts.map +1 -1
- package/types/views/Protected.d.ts +3 -0
- package/types/views/Protected.d.ts.map +1 -1
- package/types/views/SuspenseFallback.d.ts +8 -0
- package/types/views/SuspenseFallback.d.ts.map +1 -0
- package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","stack_utils_exports","__export","StackHeader","StackHeaderBackButton","import_StackHeaderBackButton","StackHeaderComponent","import_StackHeaderComponent","StackHeaderLeft","import_StackHeaderLeft","StackHeaderRight","import_StackHeaderRight","StackHeaderSearchBar","import_StackHeaderSearchBar","StackHeaderTitle","import_StackHeaderTitle","StackScreen","import_StackScreen","appendScreenStackPropsToOptions","validateStackPresentation","module","exports","require","Object","assign","Left","Right","BackButton","Title","SearchBar"],"sources":["../../../../src/layouts/stack-utils/index.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,mBAAA;AAAAC,QAAA,CAAAD,mBAAA;EAAAE,WAAA,EAAAA,CAAA,KAAAA,WAAA;EAAAC,qBAAA,EAAAA,CAAA,KAAAC,4BAAA,CAAAD,qBAAA;EAAAE,oBAAA,EAAAA,CAAA,KAAAC,2BAAA,CAAAD,oBAAA;EAAAE,eAAA,EAAAA,CAAA,KAAAC,sBAAA,CAAAD,eAAA;EAAAE,gBAAA,EAAAA,CAAA,KAAAC,uBAAA,CAAAD,gBAAA;EAAAE,oBAAA,EAAAA,CAAA,KAAAC,2BAAA,CAAAD,oBAAA;EAAAE,gBAAA,EAAAA,CAAA,KAAAC,uBAAA,CAAAD,gBAAA;EAAAE,WAAA,EAAAA,CAAA,KAAAC,kBAAA,CAAAD,WAAA;EAAAE,+BAAA,EAAAA,CAAA,
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","stack_utils_exports","__export","StackHeader","StackHeaderBackButton","import_StackHeaderBackButton","StackHeaderComponent","import_StackHeaderComponent","StackHeaderLeft","import_StackHeaderLeft","StackHeaderRight","import_StackHeaderRight","StackHeaderSearchBar","import_StackHeaderSearchBar","StackHeaderTitle","import_StackHeaderTitle","StackScreen","import_StackScreen","StackToolbar","import_StackToolbar","appendScreenStackPropsToOptions","validateStackPresentation","module","exports","require","Object","assign","Left","Right","BackButton","Title","SearchBar"],"sources":["../../../../src/layouts/stack-utils/index.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,mBAAA;AAAAC,QAAA,CAAAD,mBAAA;EAAAE,WAAA,EAAAA,CAAA,KAAAA,WAAA;EAAAC,qBAAA,EAAAA,CAAA,KAAAC,4BAAA,CAAAD,qBAAA;EAAAE,oBAAA,EAAAA,CAAA,KAAAC,2BAAA,CAAAD,oBAAA;EAAAE,eAAA,EAAAA,CAAA,KAAAC,sBAAA,CAAAD,eAAA;EAAAE,gBAAA,EAAAA,CAAA,KAAAC,uBAAA,CAAAD,gBAAA;EAAAE,oBAAA,EAAAA,CAAA,KAAAC,2BAAA,CAAAD,oBAAA;EAAAE,gBAAA,EAAAA,CAAA,KAAAC,uBAAA,CAAAD,gBAAA;EAAAE,WAAA,EAAAA,CAAA,KAAAC,kBAAA,CAAAD,WAAA;EAAAE,YAAA,EAAAA,CAAA,KAAAC,mBAAA,CAAAD,YAAA;EAAAE,+BAAA,EAAAA,CAAA,KAAAH,kBAAA,CAAAG,+BAAA;EAAAC,yBAAA,EAAAA,CAAA,KAAAJ,kBAAA,CAAAI;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAA3B,YAAA,CAAAK,mBAGO;AACP,IAAAI,4BAAA,GAA4DmB,OAAA;AAC5D,IAAAjB,2BAA2D,GAAAiB,OAAA;AAC3D,IAAAf,sBAAA,GAAAe,OAA6D;AAC7D,IAAAb,uBAAA,GAAAa,OAGO;AACP,IAAAX,2BAA6D,GAAAW,OAAA;AAC7D,IAAAT,uBAA6B,GAAAS,OAAA;AA4C7B,IAAAL,mBAAA,GAMOK,OAAA;AA5CA,IAAAP,kBAAoB,GAAAO,OAAO,0BAAO;AAAsB,IAC7DrB,WAAM,GAAAsB,MAAA,CAAAC,MAAA,CAAAnB,2BAAA,CAAAD,oBAAA;EACNqB,IAAA,EAAAlB,sBAAO,CAAAD,eAAA;EACPoB,KAAA,EAAAjB,uBAAY,CAAAD,gBAAA;EACZmB,UAAO,EAAAxB,4BAAA,CAAAD,qBAAA;EACP0B,KAAA,EAAAf,uBAAW,CAAAD,gBAAA;EACZiB,SAAA,EAAAlB,2BAAA,CAAAD","ignoreList":[]}
|
|
@@ -34,13 +34,16 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
|
34
34
|
var withLayoutContext_exports = {};
|
|
35
35
|
__export(withLayoutContext_exports, {
|
|
36
36
|
useFilterScreenChildren: () => useFilterScreenChildren,
|
|
37
|
+
useResolvedGuardedRedirects: () => useResolvedGuardedRedirects,
|
|
37
38
|
withLayoutContext: () => withLayoutContext
|
|
38
39
|
});
|
|
39
40
|
module.exports = __toCommonJS(withLayoutContext_exports);
|
|
40
41
|
var import_react = __toESM(require("react"), 1);
|
|
42
|
+
var import_matchers = require("../router/matchers.cjs");
|
|
41
43
|
var import_Route = require("../router/Route.cjs");
|
|
42
44
|
var import_router = require("../router/router.cjs");
|
|
43
45
|
var import_useScreens = require("../router/useScreens.cjs");
|
|
46
|
+
var import_sortRoutes = require("../router/sortRoutes.cjs");
|
|
44
47
|
var import_withStaticProperties = require("../utils/withStaticProperties.cjs");
|
|
45
48
|
var import_Protected = require("../views/Protected.cjs");
|
|
46
49
|
var import_Screen = require("../views/Screen.cjs");
|
|
@@ -54,7 +57,8 @@ function useFilterScreenChildren(children, {
|
|
|
54
57
|
const customChildren = [];
|
|
55
58
|
const screens = [];
|
|
56
59
|
const protectedScreens = /* @__PURE__ */new Set();
|
|
57
|
-
|
|
60
|
+
const guardedRedirects = /* @__PURE__ */new Map();
|
|
61
|
+
function flattenChild(child, exclude = false, redirectTo) {
|
|
58
62
|
if (import_react.default.isValidElement(child) && (child.type === import_Screen.Screen || child.type === import_StackScreen.StackScreen)) {
|
|
59
63
|
if (typeof child.props === "object" && child.props && "name" in child.props && !child.props.name) {
|
|
60
64
|
throw new Error(`<Screen /> component in \`default export\` at \`app${contextKey}/_layout\` must have a \`name\` prop when used as a child of a Layout Route.`);
|
|
@@ -67,15 +71,18 @@ function useFilterScreenChildren(children, {
|
|
|
67
71
|
const screenProps = child.props;
|
|
68
72
|
if (exclude && screenProps.name) {
|
|
69
73
|
protectedScreens.add(screenProps.name);
|
|
74
|
+
guardedRedirects.set(screenProps.name, redirectTo);
|
|
70
75
|
} else {
|
|
71
76
|
screens.push(screenProps);
|
|
72
77
|
}
|
|
73
78
|
return;
|
|
74
79
|
}
|
|
75
80
|
if ((0, import_Protected.isProtectedElement)(child)) {
|
|
76
|
-
const
|
|
81
|
+
const guardFails = !child.props.guard;
|
|
82
|
+
const excludeChildren = exclude || guardFails;
|
|
83
|
+
const childRedirectTo = guardFails ? child.props.redirectTo : redirectTo;
|
|
77
84
|
import_react.default.Children.forEach(child.props.children, nested => {
|
|
78
|
-
flattenChild(nested, excludeChildren);
|
|
85
|
+
flattenChild(nested, excludeChildren, childRedirectTo);
|
|
79
86
|
});
|
|
80
87
|
return;
|
|
81
88
|
}
|
|
@@ -95,10 +102,25 @@ function useFilterScreenChildren(children, {
|
|
|
95
102
|
return {
|
|
96
103
|
screens,
|
|
97
104
|
children: customChildren,
|
|
98
|
-
protectedScreens
|
|
105
|
+
protectedScreens,
|
|
106
|
+
guardedRedirects
|
|
99
107
|
};
|
|
100
108
|
}, [children, contextKey, isCustomNavigator]);
|
|
101
109
|
}
|
|
110
|
+
function useResolvedGuardedRedirects(guardedRedirects) {
|
|
111
|
+
const node = (0, import_Route.useRouteNode)();
|
|
112
|
+
return import_react.default.useMemo(() => {
|
|
113
|
+
if (!node) {
|
|
114
|
+
return guardedRedirects;
|
|
115
|
+
}
|
|
116
|
+
const defaultRoute = [...node.children].sort((0, import_sortRoutes.sortRoutesWithInitial)(node.initialRouteName)).find(child => {
|
|
117
|
+
const normalized = child.route.replace(/\/index$/, "");
|
|
118
|
+
return !(guardedRedirects.has(child.route) || guardedRedirects.has(normalized));
|
|
119
|
+
});
|
|
120
|
+
const defaultHref = defaultRoute ? (0, import_matchers.stripInvisibleSegmentsFromPath)((0, import_matchers.getContextKey)(defaultRoute.contextKey)) || "/" : void 0;
|
|
121
|
+
return new Map(Array.from(guardedRedirects, ([name, redirectTo]) => [name, redirectTo ?? defaultHref]));
|
|
122
|
+
}, [guardedRedirects, node]);
|
|
123
|
+
}
|
|
102
124
|
function withLayoutContext(Nav, processor, options) {
|
|
103
125
|
return (0, import_withStaticProperties.withStaticProperties)(import_react.default.forwardRef((propsIn, ref) => {
|
|
104
126
|
const {
|
|
@@ -108,17 +130,26 @@ function withLayoutContext(Nav, processor, options) {
|
|
|
108
130
|
const contextKey = (0, import_Route.useContextKey)();
|
|
109
131
|
const {
|
|
110
132
|
screens,
|
|
111
|
-
protectedScreens
|
|
133
|
+
protectedScreens,
|
|
134
|
+
guardedRedirects
|
|
112
135
|
} = useFilterScreenChildren(children, {
|
|
113
136
|
contextKey
|
|
114
137
|
});
|
|
115
|
-
|
|
138
|
+
const resolvedGuardedRedirects = useResolvedGuardedRedirects(guardedRedirects);
|
|
139
|
+
(0, import_router.registerProtectedRoutes)(contextKey, resolvedGuardedRedirects);
|
|
140
|
+
const currentPathname = import_router.routeInfo?.pathname;
|
|
141
|
+
const protectedHref = currentPathname ? (0, import_router.resolveProtectedHref)(currentPathname) : currentPathname;
|
|
116
142
|
import_react.default.useEffect(() => {
|
|
117
|
-
(0, import_router.registerProtectedRoutes)(contextKey,
|
|
143
|
+
(0, import_router.registerProtectedRoutes)(contextKey, resolvedGuardedRedirects);
|
|
118
144
|
return () => {
|
|
119
145
|
(0, import_router.unregisterProtectedRoutes)(contextKey);
|
|
120
146
|
};
|
|
121
|
-
}, [contextKey,
|
|
147
|
+
}, [contextKey, resolvedGuardedRedirects]);
|
|
148
|
+
import_react.default.useEffect(() => {
|
|
149
|
+
if (currentPathname && protectedHref && protectedHref !== currentPathname) {
|
|
150
|
+
(0, import_router.replace)(protectedHref);
|
|
151
|
+
}
|
|
152
|
+
}, [currentPathname, protectedHref]);
|
|
122
153
|
const processed = processor ? processor(screens ?? []) : screens;
|
|
123
154
|
const sorted = (0, import_useScreens.useSortedScreens)(processed ?? [], {
|
|
124
155
|
onlyMatching: true,
|
|
@@ -36,14 +36,17 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
|
36
36
|
var withLayoutContext_exports = {};
|
|
37
37
|
__export(withLayoutContext_exports, {
|
|
38
38
|
useFilterScreenChildren: () => useFilterScreenChildren,
|
|
39
|
+
useResolvedGuardedRedirects: () => useResolvedGuardedRedirects,
|
|
39
40
|
withLayoutContext: () => withLayoutContext
|
|
40
41
|
});
|
|
41
42
|
module.exports = __toCommonJS(withLayoutContext_exports);
|
|
42
43
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
43
44
|
var import_react = __toESM(require("react"), 1);
|
|
45
|
+
var import_matchers = require("../router/matchers.native.js");
|
|
44
46
|
var import_Route = require("../router/Route.native.js");
|
|
45
47
|
var import_router = require("../router/router.native.js");
|
|
46
48
|
var import_useScreens = require("../router/useScreens.native.js");
|
|
49
|
+
var import_sortRoutes = require("../router/sortRoutes.native.js");
|
|
47
50
|
var import_withStaticProperties = require("../utils/withStaticProperties.native.js");
|
|
48
51
|
var import_Protected = require("../views/Protected.native.js");
|
|
49
52
|
var import_Screen = require("../views/Screen.native.js");
|
|
@@ -63,8 +66,10 @@ function useFilterScreenChildren(children) {
|
|
|
63
66
|
var customChildren = [];
|
|
64
67
|
var screens = [];
|
|
65
68
|
var protectedScreens = /* @__PURE__ */new Set();
|
|
69
|
+
var guardedRedirects = /* @__PURE__ */new Map();
|
|
66
70
|
function flattenChild(child) {
|
|
67
|
-
var exclude = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false
|
|
71
|
+
var exclude = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false,
|
|
72
|
+
redirectTo = arguments.length > 2 ? arguments[2] : void 0;
|
|
68
73
|
if (/* @__PURE__ */import_react.default.isValidElement(child) && (child.type === import_Screen.Screen || child.type === import_StackScreen.StackScreen)) {
|
|
69
74
|
if (_type_of(child.props) === "object" && child.props && "name" in child.props && !child.props.name) {
|
|
70
75
|
throw new Error(`<Screen /> component in \`default export\` at \`app${contextKey}/_layout\` must have a \`name\` prop when used as a child of a Layout Route.`);
|
|
@@ -79,15 +84,18 @@ function useFilterScreenChildren(children) {
|
|
|
79
84
|
var screenProps = child.props;
|
|
80
85
|
if (exclude && screenProps.name) {
|
|
81
86
|
protectedScreens.add(screenProps.name);
|
|
87
|
+
guardedRedirects.set(screenProps.name, redirectTo);
|
|
82
88
|
} else {
|
|
83
89
|
screens.push(screenProps);
|
|
84
90
|
}
|
|
85
91
|
return;
|
|
86
92
|
}
|
|
87
93
|
if ((0, import_Protected.isProtectedElement)(child)) {
|
|
88
|
-
var
|
|
94
|
+
var guardFails = !child.props.guard;
|
|
95
|
+
var excludeChildren = exclude || guardFails;
|
|
96
|
+
var childRedirectTo = guardFails ? child.props.redirectTo : redirectTo;
|
|
89
97
|
import_react.default.Children.forEach(child.props.children, function (nested) {
|
|
90
|
-
flattenChild(nested, excludeChildren);
|
|
98
|
+
flattenChild(nested, excludeChildren, childRedirectTo);
|
|
91
99
|
});
|
|
92
100
|
return;
|
|
93
101
|
}
|
|
@@ -111,10 +119,28 @@ function useFilterScreenChildren(children) {
|
|
|
111
119
|
return {
|
|
112
120
|
screens,
|
|
113
121
|
children: customChildren,
|
|
114
|
-
protectedScreens
|
|
122
|
+
protectedScreens,
|
|
123
|
+
guardedRedirects
|
|
115
124
|
};
|
|
116
125
|
}, [children, contextKey, isCustomNavigator]);
|
|
117
126
|
}
|
|
127
|
+
function useResolvedGuardedRedirects(guardedRedirects) {
|
|
128
|
+
var node = (0, import_Route.useRouteNode)();
|
|
129
|
+
return import_react.default.useMemo(function () {
|
|
130
|
+
if (!node) {
|
|
131
|
+
return guardedRedirects;
|
|
132
|
+
}
|
|
133
|
+
var defaultRoute = [...node.children].sort((0, import_sortRoutes.sortRoutesWithInitial)(node.initialRouteName)).find(function (child) {
|
|
134
|
+
var normalized = child.route.replace(/\/index$/, "");
|
|
135
|
+
return !(guardedRedirects.has(child.route) || guardedRedirects.has(normalized));
|
|
136
|
+
});
|
|
137
|
+
var defaultHref = defaultRoute ? (0, import_matchers.stripInvisibleSegmentsFromPath)((0, import_matchers.getContextKey)(defaultRoute.contextKey)) || "/" : void 0;
|
|
138
|
+
return new Map(Array.from(guardedRedirects, function (param) {
|
|
139
|
+
var [name, redirectTo] = param;
|
|
140
|
+
return [name, redirectTo !== null && redirectTo !== void 0 ? redirectTo : defaultHref];
|
|
141
|
+
}));
|
|
142
|
+
}, [guardedRedirects, node]);
|
|
143
|
+
}
|
|
118
144
|
function withLayoutContext(Nav, processor, options) {
|
|
119
145
|
return (0, import_withStaticProperties.withStaticProperties)(/* @__PURE__ */import_react.default.forwardRef(function (propsIn, ref) {
|
|
120
146
|
var {
|
|
@@ -124,17 +150,26 @@ function withLayoutContext(Nav, processor, options) {
|
|
|
124
150
|
var contextKey = (0, import_Route.useContextKey)();
|
|
125
151
|
var {
|
|
126
152
|
screens,
|
|
127
|
-
protectedScreens
|
|
153
|
+
protectedScreens,
|
|
154
|
+
guardedRedirects
|
|
128
155
|
} = useFilterScreenChildren(children, {
|
|
129
156
|
contextKey
|
|
130
157
|
});
|
|
131
|
-
|
|
158
|
+
var resolvedGuardedRedirects = useResolvedGuardedRedirects(guardedRedirects);
|
|
159
|
+
(0, import_router.registerProtectedRoutes)(contextKey, resolvedGuardedRedirects);
|
|
160
|
+
var currentPathname = import_router.routeInfo === null || import_router.routeInfo === void 0 ? void 0 : import_router.routeInfo.pathname;
|
|
161
|
+
var protectedHref = currentPathname ? (0, import_router.resolveProtectedHref)(currentPathname) : currentPathname;
|
|
132
162
|
import_react.default.useEffect(function () {
|
|
133
|
-
(0, import_router.registerProtectedRoutes)(contextKey,
|
|
163
|
+
(0, import_router.registerProtectedRoutes)(contextKey, resolvedGuardedRedirects);
|
|
134
164
|
return function () {
|
|
135
165
|
(0, import_router.unregisterProtectedRoutes)(contextKey);
|
|
136
166
|
};
|
|
137
|
-
}, [contextKey,
|
|
167
|
+
}, [contextKey, resolvedGuardedRedirects]);
|
|
168
|
+
import_react.default.useEffect(function () {
|
|
169
|
+
if (currentPathname && protectedHref && protectedHref !== currentPathname) {
|
|
170
|
+
(0, import_router.replace)(protectedHref);
|
|
171
|
+
}
|
|
172
|
+
}, [currentPathname, protectedHref]);
|
|
138
173
|
var processed = processor ? processor(screens !== null && screens !== void 0 ? screens : []) : screens;
|
|
139
174
|
var sorted = (0, import_useScreens.useSortedScreens)(processed !== null && processed !== void 0 ? processed : [], {
|
|
140
175
|
onlyMatching: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","withLayoutContext_exports","__export","useFilterScreenChildren","withLayoutContext","module","exports","import_jsx_runtime","require","import_react","__toESM","import_Route","import_router","import_useScreens","import_withStaticProperties","import_Protected","import_Screen","import_StackScreen","_type_of","obj","Symbol","constructor","children","isCustomNavigator","contextKey","arguments","length","default","useMemo","customChildren","screens","protectedScreens","Set","flattenChild","child","exclude","isValidElement","type","Screen","StackScreen","props","name","Error","process","env","NODE_ENV","some","key","screenProps","add","push","isProtectedElement","
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","withLayoutContext_exports","__export","useFilterScreenChildren","useResolvedGuardedRedirects","withLayoutContext","module","exports","import_jsx_runtime","require","import_react","__toESM","import_matchers","import_Route","import_router","import_useScreens","import_sortRoutes","import_withStaticProperties","import_Protected","import_Screen","import_StackScreen","_type_of","obj","Symbol","constructor","children","isCustomNavigator","contextKey","arguments","length","default","useMemo","customChildren","screens","protectedScreens","Set","guardedRedirects","Map","flattenChild","child","exclude","redirectTo","isValidElement","type","Screen","StackScreen","props","name","Error","process","env","NODE_ENV","some","key","screenProps","add","set","push","isProtectedElement","guardFails","guard","excludeChildren","childRedirectTo","Children","forEach","nested","console","warn","names","map","screen","size","node","useRouteNode","defaultRoute","sort","sortRoutesWithInitial","initialRouteName","find","normalized","route","replace","has","defaultHref","stripInvisibleSegmentsFromPath","getContextKey","Array","from","param","Nav","processor","options","withStaticProperties","forwardRef","propsIn","ref","useContextKey","resolvedGuardedRedirects","registerProtectedRoutes","currentPathname","routeInfo","pathname","protectedHref","resolveProtectedHref","useEffect","unregisterProtectedRoutes"],"sources":["../../../src/layouts/withLayoutContext.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,yBAAA;AAAAC,QAAA,CAAAD,yBAAA;EAAAE,uBAAA,EAAAA,CAAA,KAAAA,uBAAA;EAAAC,2BAAA,EAAAA,CAAA,KAAAA,2BAAA;EAAAC,iBAAA,EAAAA,CAAA,KAAAA;AAAA;AACAC,MAAA,CAAAC,OAAA,GAAAX,YAAkB,CAAAK,yBAAA;AAElB,IAAAO,kBAA8D,GAAAC,OAAA;AAC9D,IAAAC,YAAA,GAA4CC,OAAA,CAAAF,OAAA;AAC5C,IAAAG,eAAA,GAMOH,OAAA;AACP,IAAAI,YAAA,GAAAJ,OAAmD;AACnD,IAAAK,aAAA,GAAAL,OAAsC;AAEtC,IAAAM,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
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
10
|
+
get: () => from[key],
|
|
11
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
22
|
+
value: mod,
|
|
23
|
+
enumerable: true
|
|
24
|
+
}) : target, mod));
|
|
25
|
+
var import_react_test_renderer = __toESM(require("react-test-renderer"), 1);
|
|
26
|
+
var import_vitest = require("vitest");
|
|
27
|
+
var import_Protected = require("../views/Protected.cjs");
|
|
28
|
+
var import_Screen = require("../views/Screen.cjs");
|
|
29
|
+
var import_withLayoutContext = require("./withLayoutContext.cjs");
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
+
function readGuardedRedirects(children) {
|
|
32
|
+
let result;
|
|
33
|
+
function Capture() {
|
|
34
|
+
result = (0, import_withLayoutContext.useFilterScreenChildren)(children);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
(0, import_react_test_renderer.act)(() => {
|
|
38
|
+
import_react_test_renderer.default.create(/* @__PURE__ */(0, import_jsx_runtime.jsx)(Capture, {}));
|
|
39
|
+
});
|
|
40
|
+
return result.guardedRedirects;
|
|
41
|
+
}
|
|
42
|
+
(0, import_vitest.describe)("Protected redirectTo", () => {
|
|
43
|
+
(0, import_vitest.it)("associates a failed guard redirect with each protected screen", () => {
|
|
44
|
+
const redirects = readGuardedRedirects(/* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_Protected.Protected, {
|
|
45
|
+
guard: false,
|
|
46
|
+
redirectTo: "/login",
|
|
47
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, {
|
|
48
|
+
name: "dashboard"
|
|
49
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, {
|
|
50
|
+
name: "settings"
|
|
51
|
+
})]
|
|
52
|
+
}));
|
|
53
|
+
(0, import_vitest.expect)(Array.from(redirects)).toEqual([["dashboard", "/login"], ["settings", "/login"]]);
|
|
54
|
+
});
|
|
55
|
+
(0, import_vitest.it)("uses the innermost failing guard redirect", () => {
|
|
56
|
+
const redirects = readGuardedRedirects(/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, {
|
|
57
|
+
guard: false,
|
|
58
|
+
redirectTo: "/login",
|
|
59
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, {
|
|
60
|
+
guard: false,
|
|
61
|
+
redirectTo: "/subscribe",
|
|
62
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, {
|
|
63
|
+
name: "premium"
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
}));
|
|
67
|
+
(0, import_vitest.expect)(redirects.get("premium")).toBe("/subscribe");
|
|
68
|
+
});
|
|
69
|
+
(0, import_vitest.it)("inherits a failed parent redirect through a passing child guard", () => {
|
|
70
|
+
const redirects = readGuardedRedirects(/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, {
|
|
71
|
+
guard: false,
|
|
72
|
+
redirectTo: "/login",
|
|
73
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, {
|
|
74
|
+
guard: true,
|
|
75
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, {
|
|
76
|
+
name: "account"
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
}));
|
|
80
|
+
(0, import_vitest.expect)(redirects.get("account")).toBe("/login");
|
|
81
|
+
});
|
|
82
|
+
(0, import_vitest.it)("ignores redirectTo on a passing parent guard", () => {
|
|
83
|
+
const redirects = readGuardedRedirects(/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, {
|
|
84
|
+
guard: true,
|
|
85
|
+
redirectTo: "/login",
|
|
86
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, {
|
|
87
|
+
guard: false,
|
|
88
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, {
|
|
89
|
+
name: "account"
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
}));
|
|
93
|
+
(0, import_vitest.expect)(redirects.has("account")).toBe(true);
|
|
94
|
+
(0, import_vitest.expect)(redirects.get("account")).toBeUndefined();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: () => from[key],
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
|
+
var import_react = __toESM(require("react"), 1);
|
|
29
|
+
var import_react_test_renderer = __toESM(require("react-test-renderer"), 1);
|
|
30
|
+
var import_vitest = require("vitest");
|
|
31
|
+
var import_Protected = require("../views/Protected.native.js");
|
|
32
|
+
var import_Screen = require("../views/Screen.native.js");
|
|
33
|
+
var import_withLayoutContext = require("./withLayoutContext.native.js");
|
|
34
|
+
function readGuardedRedirects(children) {
|
|
35
|
+
var result;
|
|
36
|
+
function Capture() {
|
|
37
|
+
result = (0, import_withLayoutContext.useFilterScreenChildren)(children);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
(0, import_react_test_renderer.act)(function () {
|
|
41
|
+
import_react_test_renderer.default.create(/* @__PURE__ */(0, import_jsx_runtime.jsx)(Capture, {}));
|
|
42
|
+
});
|
|
43
|
+
return result.guardedRedirects;
|
|
44
|
+
}
|
|
45
|
+
(0, import_vitest.describe)("Protected redirectTo", function () {
|
|
46
|
+
(0, import_vitest.it)("associates a failed guard redirect with each protected screen", function () {
|
|
47
|
+
var redirects = readGuardedRedirects(/* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_Protected.Protected, {
|
|
48
|
+
guard: false,
|
|
49
|
+
redirectTo: "/login",
|
|
50
|
+
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, {
|
|
51
|
+
name: "dashboard"
|
|
52
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, {
|
|
53
|
+
name: "settings"
|
|
54
|
+
})]
|
|
55
|
+
}));
|
|
56
|
+
(0, import_vitest.expect)(Array.from(redirects)).toEqual([["dashboard", "/login"], ["settings", "/login"]]);
|
|
57
|
+
});
|
|
58
|
+
(0, import_vitest.it)("uses the innermost failing guard redirect", function () {
|
|
59
|
+
var redirects = readGuardedRedirects(/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, {
|
|
60
|
+
guard: false,
|
|
61
|
+
redirectTo: "/login",
|
|
62
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, {
|
|
63
|
+
guard: false,
|
|
64
|
+
redirectTo: "/subscribe",
|
|
65
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, {
|
|
66
|
+
name: "premium"
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
}));
|
|
70
|
+
(0, import_vitest.expect)(redirects.get("premium")).toBe("/subscribe");
|
|
71
|
+
});
|
|
72
|
+
(0, import_vitest.it)("inherits a failed parent redirect through a passing child guard", function () {
|
|
73
|
+
var redirects = readGuardedRedirects(/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, {
|
|
74
|
+
guard: false,
|
|
75
|
+
redirectTo: "/login",
|
|
76
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, {
|
|
77
|
+
guard: true,
|
|
78
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, {
|
|
79
|
+
name: "account"
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
}));
|
|
83
|
+
(0, import_vitest.expect)(redirects.get("account")).toBe("/login");
|
|
84
|
+
});
|
|
85
|
+
(0, import_vitest.it)("ignores redirectTo on a passing parent guard", function () {
|
|
86
|
+
var redirects = readGuardedRedirects(/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, {
|
|
87
|
+
guard: true,
|
|
88
|
+
redirectTo: "/login",
|
|
89
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, {
|
|
90
|
+
guard: false,
|
|
91
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, {
|
|
92
|
+
name: "account"
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
}));
|
|
96
|
+
(0, import_vitest.expect)(redirects.has("account")).toBe(true);
|
|
97
|
+
(0, import_vitest.expect)(redirects.get("account")).toBeUndefined();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=withLayoutContext.test.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["import_jsx_runtime","require","import_react","__toESM","import_react_test_renderer","import_vitest","import_Protected","import_Screen","import_withLayoutContext","readGuardedRedirects","children","result","Capture","useFilterScreenChildren","act","default","create","jsx","guardedRedirects","describe","it","redirects","jsxs","Protected","guard","redirectTo","Screen","name","expect","Array","from","toEqual"],"sources":["../../../src/layouts/withLayoutContext.test.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;gBACA;AACA,IAAAA,kBAAqC,GAAAC,OAAA;AACrC,IAAAC,YAAA,GAAAC,OAA0B,CAAAF,OAAA;AAC1B,IAAAG,0BAAuB,GAAAD,OAAA,CAAAF,OAAA;AACvB,IAAAI,aAAA,GAAAJ,OAAA,SAAwC;AAWhB,IAAAK,gBAAA,GAAAL,OAAA;AATxB,IAAAM,aAAS,GAAAN,OAAA,4BAAgD;AACvD,IAAAO,wBAAI,GAAAP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teParamsContext,
|
|
38
|
+
SuspenseFallbackContext: () => SuspenseFallbackContext,
|
|
38
39
|
useContextKey: () => useContextKey,
|
|
39
40
|
useRouteNode: () => useRouteNode
|
|
40
41
|
});
|
|
@@ -50,8 +51,10 @@ var import_RouteInfoContext = require("./RouteInfoContext.cjs");
|
|
|
50
51
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
51
52
|
const RouteParamsContext = (0, import_react.createContext)({});
|
|
52
53
|
const CurrentRouteContext = import_react.default.createContext(null);
|
|
54
|
+
const SuspenseFallbackContext = (0, import_react.createContext)(void 0);
|
|
53
55
|
if (process.env.NODE_ENV !== "production") {
|
|
54
56
|
CurrentRouteContext.displayName = "RouteNode";
|
|
57
|
+
SuspenseFallbackContext.displayName = "SuspenseFallback";
|
|
55
58
|
}
|
|
56
59
|
function useRouteNode() {
|
|
57
60
|
return (0, import_react.useContext)(CurrentRouteContext);
|
|
@@ -37,6 +37,7 @@ var Route_exports = {};
|
|
|
37
37
|
__export(Route_exports, {
|
|
38
38
|
Route: () => Route,
|
|
39
39
|
RouteParamsContext: () => RouteParamsContext,
|
|
40
|
+
SuspenseFallbackContext: () => SuspenseFallbackContext,
|
|
40
41
|
useContextKey: () => useContextKey,
|
|
41
42
|
useRouteNode: () => useRouteNode
|
|
42
43
|
});
|
|
@@ -52,8 +53,10 @@ var import_router = require("./router.native.js");
|
|
|
52
53
|
var import_RouteInfoContext = require("./RouteInfoContext.native.js");
|
|
53
54
|
var RouteParamsContext = /* @__PURE__ */(0, import_react.createContext)({});
|
|
54
55
|
var CurrentRouteContext = /* @__PURE__ */import_react.default.createContext(null);
|
|
56
|
+
var SuspenseFallbackContext = /* @__PURE__ */(0, import_react.createContext)(void 0);
|
|
55
57
|
if (process.env.NODE_ENV !== "production") {
|
|
56
58
|
CurrentRouteContext.displayName = "RouteNode";
|
|
59
|
+
SuspenseFallbackContext.displayName = "SuspenseFallback";
|
|
57
60
|
}
|
|
58
61
|
function useRouteNode() {
|
|
59
62
|
return (0, import_react.useContext)(CurrentRouteContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","Route_exports","__export","Route","RouteParamsContext","useContextKey","useRouteNode","module","exports","import_jsx_runtime","require","import_react","__toESM","import_findFocusedRoute","import_linkingConfig","import_matchers","import_params","import_path","import_router","import_RouteInfoContext","createContext","CurrentRouteContext","default","process","env","NODE_ENV","displayName","useContext","node","Error","getContextKey","contextKey","getParamsFromCurrentUrl","route","linking","getResolvedLinking","getStateFromPath","path","getPathWithRecoveredDynamicSegment","routeInfo","unstable_globalHref","state","config","focused","findFocusedRoute","params","param","children","parentParams","resolvedParams","useMemo","_node_dynamic","rp","ownParams","dynamic","length","mergeDynamicParams"],"sources":["../../../src/router/Route.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,QAAA,CAAAD,aAAA;EAAAE,KAAA,EAAAA,CAAA,KAAAA,KAAA;EAAAC,kBAAA,EAAAA,CAAA,KAAAA,kBAAA;EAAAC,aAAA,EAAAA,CAAA,KAAAA,aAAA;EAAAC,YAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","Route_exports","__export","Route","RouteParamsContext","SuspenseFallbackContext","useContextKey","useRouteNode","module","exports","import_jsx_runtime","require","import_react","__toESM","import_findFocusedRoute","import_linkingConfig","import_matchers","import_params","import_path","import_router","import_RouteInfoContext","createContext","CurrentRouteContext","default","process","env","NODE_ENV","displayName","useContext","node","Error","getContextKey","contextKey","getParamsFromCurrentUrl","route","linking","getResolvedLinking","getStateFromPath","path","getPathWithRecoveredDynamicSegment","routeInfo","unstable_globalHref","state","config","focused","findFocusedRoute","params","param","children","parentParams","resolvedParams","useMemo","_node_dynamic","rp","ownParams","dynamic","length","mergeDynamicParams"],"sources":["../../../src/router/Route.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,QAAA,CAAAD,aAAA;EAAAE,KAAA,EAAAA,CAAA,KAAAA,KAAA;EAAAC,kBAAA,EAAAA,CAAA,KAAAA,kBAAA;EAAAC,uBAAA,EAAAA,CAAA,KAAAA,uBAAA;EAAAC,aAAA,EAAAA,CAAA,KAAAA,aAAA;EAAAC,YAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAb,YAAiE,CAAAK,aAAA;AACjE,IAAAS,kBAAA,GAAAC,OAAiC;AAMjC,IAAAC,YAAA,GAAAC,OAAA,CAAmCF,OAAA;AACnC,IAAAG,uBAA8B,GAAAH,OAAA;AAC9B,IAAAI,oBAAmC,GAAAJ,OAAA;AACnC,IAAAK,eAAmD,GAAAL,OAAA;AACnD,IAAAM,aAAA,GAA0BN,OAAA;AAC1B,IAAAO,WAAA,GAAAP,OAAA,mBAAyC;AA0MjC,IAAAQ,aAAA,GAAAR,OAAA;AA5FD,IAAAS,uBAAM,GAAAT,OAAqB,gCAEhC;AAEF,IAAAP,kBAAM,kBAAsB,IAAAQ,YAAM,CAAAS,aAAoC;AAG/D,IAAAC,mBAAM,kBAA0BV,YAAA,CAAAW,OAAA,CAAAF,aAE5B;AAEX,IAAIhB,uBAAY,GAAa,eAAc,IAAAO,YAAA,CAAAS,aAAA;AACzC,IAAAG,OAAA,CAAAC,GAAA,CAAAC,QAAoB,iBAAc;EAClCJ,mBAAA,CAAAK,WAAwB,cAAc;EACxCtB,uBAAA,CAAAsB,WAAA;AAGO;AACL,SAAApB,YAAOA,C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F,aAAA,GAAAvB,IAAA,CAAA0B,OAAA,cAAAH,aAAA,uBAAAA,aAAA,CAAAI,MAAA,QAAAvC,aAAA,CAAAwC,kBAAA,EAAAJ,EAAA,EAAAxB,IAAA,CAAA0B,OAAA,EAAAtB,uBAAA,CAAAC,KAAA,KAAAmB,EAAA;IAClB,KAAAJ,YAAM,EAAY,OAAKK,SAAS;IAIhC,IAAI,CAACA,SAAA,SAAcL,YAAO;IAC1B,OAAK;MACL,GAAAA,YAAY;MACV,GAAAK;IAEJ;EAOF,I","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var import_vitest = require("vitest");
|
|
2
|
+
var import_router = require("./router.cjs");
|
|
3
|
+
const contextKey = "/account";
|
|
4
|
+
(0, import_vitest.afterEach)(() => {
|
|
5
|
+
(0, import_router.unregisterProtectedRoutes)(contextKey);
|
|
6
|
+
});
|
|
7
|
+
(0, import_vitest.describe)("protected route redirects", () => {
|
|
8
|
+
(0, import_vitest.it)("resolves a protected href to its redirect target", () => {
|
|
9
|
+
(0, import_router.registerProtectedRoutes)(contextKey, /* @__PURE__ */new Map([["settings", "/login"]]));
|
|
10
|
+
(0, import_vitest.expect)((0, import_router.isRouteProtected)("/account/settings?tab=billing")).toBe(true);
|
|
11
|
+
(0, import_vitest.expect)((0, import_router.resolveProtectedHref)("/account/settings?tab=billing")).toBe("/login");
|
|
12
|
+
});
|
|
13
|
+
(0, import_vitest.it)("blocks a protected href without an explicit target", () => {
|
|
14
|
+
(0, import_router.registerProtectedRoutes)(contextKey, /* @__PURE__ */new Map([["settings", void 0]]));
|
|
15
|
+
(0, import_vitest.expect)((0, import_router.resolveProtectedHref)("/account/settings")).toBeUndefined();
|
|
16
|
+
});
|
|
17
|
+
(0, import_vitest.it)("leaves allowed and similarly prefixed routes unchanged", () => {
|
|
18
|
+
(0, import_router.registerProtectedRoutes)(contextKey, /* @__PURE__ */new Map([["settings", "/login"]]));
|
|
19
|
+
(0, import_vitest.expect)((0, import_router.resolveProtectedHref)("/account/profile")).toBe("/account/profile");
|
|
20
|
+
(0, import_vitest.expect)((0, import_router.resolveProtectedHref)("/accounting/settings")).toBe("/accounting/settings");
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var import_vitest = require("vitest");
|
|
4
|
+
var import_router = require("./router.native.js");
|
|
5
|
+
var contextKey = "/account";
|
|
6
|
+
(0, import_vitest.afterEach)(function () {
|
|
7
|
+
(0, import_router.unregisterProtectedRoutes)(contextKey);
|
|
8
|
+
});
|
|
9
|
+
(0, import_vitest.describe)("protected route redirects", function () {
|
|
10
|
+
(0, import_vitest.it)("resolves a protected href to its redirect target", function () {
|
|
11
|
+
(0, import_router.registerProtectedRoutes)(contextKey, /* @__PURE__ */new Map([["settings", "/login"]]));
|
|
12
|
+
(0, import_vitest.expect)((0, import_router.isRouteProtected)("/account/settings?tab=billing")).toBe(true);
|
|
13
|
+
(0, import_vitest.expect)((0, import_router.resolveProtectedHref)("/account/settings?tab=billing")).toBe("/login");
|
|
14
|
+
});
|
|
15
|
+
(0, import_vitest.it)("blocks a protected href without an explicit target", function () {
|
|
16
|
+
(0, import_router.registerProtectedRoutes)(contextKey, /* @__PURE__ */new Map([["settings", void 0]]));
|
|
17
|
+
(0, import_vitest.expect)((0, import_router.resolveProtectedHref)("/account/settings")).toBeUndefined();
|
|
18
|
+
});
|
|
19
|
+
(0, import_vitest.it)("leaves allowed and similarly prefixed routes unchanged", function () {
|
|
20
|
+
(0, import_router.registerProtectedRoutes)(contextKey, /* @__PURE__ */new Map([["settings", "/login"]]));
|
|
21
|
+
(0, import_vitest.expect)((0, import_router.resolveProtectedHref)("/account/profile")).toBe("/account/profile");
|
|
22
|
+
(0, import_vitest.expect)((0, import_router.resolveProtectedHref)("/accounting/settings")).toBe("/accounting/settings");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=protectedRoutes.test.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["import_vitest","require","import_router","contextKey","afterEach","unregisterProtectedRoutes","describe","it","registerProtectedRoutes","Map","expect","isRouteProtected","toBe","resolveProtectedHref"],"sources":["../../../src/router/protectedRoutes.test.ts"],"sourcesContent":[null],"mappings":"AAAA;;AACA,IAAAA,aAAA,GAKOC,OAAA;AAEP,IAAAC,aAAM,GAAaD,OAAA;AAAA,IAEnBE,UAAA;AACE,IAAAH,aAAA,CAAAI,SAAA;EACD,IAAAF,aAAA,CAAAG,yBAAA,EAAAF,UAAA;AAAA;AAGC,IAAAH,aAAA,CAAAM,QAAG;EACD,IAAAN,aAAA,CAAAO,EAAA,oDAAoC,cAAU;IAE9C,IAAAL,aAAA,CAAAM,uBAAO,EAAAL,UAAA,iBAAiB,IAAAM,GAAA,EACxB,CACD,YAED,SACE,CAEA;IACD,IAAAT,aAAA,CAAAU,MAAA,MAAAR,aAAA,CAAAS,gBAAA,oCAAAC,IAAA;IAED,IAAAZ,aAAA,CAAAU,MAAG,MAAAR,aAAA,CAAAW,oBAAA,iCAAgE,GAAAD,IAAA;EACjE;EAEA,IAAAZ,aAAA,CAAAO,EAAA,sDAA4B,cAAmB;IAC/C,IAAAL,aAAA,CAAAM,uBAAO,EAAAL,UAAA,iBAAqB,IAAAM,GAAA,EAC7B,CACF,Y","ignoreList":[]}
|