one 1.1.390 → 1.1.392
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/Root.cjs +6 -17
- package/dist/cjs/Root.js +9 -13
- package/dist/cjs/Root.js.map +1 -1
- package/dist/cjs/Root.native.js +4 -12
- package/dist/cjs/Root.native.js.map +1 -1
- package/dist/cjs/cli/build.cjs +2 -3
- package/dist/cjs/cli/build.js +2 -3
- package/dist/cjs/cli/build.js.map +1 -1
- package/dist/cjs/cli/build.native.js +2 -3
- package/dist/cjs/cli/build.native.js.map +2 -2
- package/dist/cjs/constants.cjs +9 -1
- package/dist/cjs/constants.js +7 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/constants.native.js +9 -1
- package/dist/cjs/constants.native.js.map +2 -2
- package/dist/cjs/fork/NavigationContainer.cjs +49 -31
- package/dist/cjs/fork/NavigationContainer.js +40 -21
- package/dist/cjs/fork/NavigationContainer.js.map +2 -2
- package/dist/cjs/fork/NavigationContainer.native.js +51 -29
- package/dist/cjs/fork/NavigationContainer.native.js.map +2 -2
- package/dist/cjs/fork/createMemoryHistory.cjs +4 -3
- package/dist/cjs/fork/createMemoryHistory.js +3 -2
- package/dist/cjs/fork/createMemoryHistory.js.map +1 -1
- package/dist/cjs/fork/createMemoryHistory.native.js +8 -4
- package/dist/cjs/fork/createMemoryHistory.native.js.map +2 -2
- package/dist/cjs/fork/extractPathFromURL.cjs +48 -28
- package/dist/cjs/fork/extractPathFromURL.js +44 -21
- package/dist/cjs/fork/extractPathFromURL.js.map +2 -2
- package/dist/cjs/fork/extractPathFromURL.native.js +58 -26
- package/dist/cjs/fork/extractPathFromURL.native.js.map +2 -2
- package/dist/cjs/fork/findFocusedRoute.js.map +1 -1
- package/dist/cjs/fork/findFocusedRoute.native.js.map +1 -1
- package/dist/cjs/fork/getPathFromState-mods.cjs +65 -0
- package/dist/cjs/fork/getPathFromState-mods.js +56 -0
- package/dist/cjs/fork/getPathFromState-mods.js.map +6 -0
- package/dist/cjs/fork/getPathFromState-mods.native.js +70 -0
- package/dist/cjs/fork/getPathFromState-mods.native.js.map +6 -0
- package/dist/cjs/fork/getPathFromState.cjs +75 -224
- package/dist/cjs/fork/getPathFromState.js +68 -223
- package/dist/cjs/fork/getPathFromState.js.map +2 -2
- package/dist/cjs/fork/getPathFromState.native.js +79 -261
- package/dist/cjs/fork/getPathFromState.native.js.map +2 -2
- package/dist/cjs/fork/getStateFromPath-mods.cjs +187 -0
- package/dist/cjs/fork/getStateFromPath-mods.js +199 -0
- package/dist/cjs/fork/getStateFromPath-mods.js.map +6 -0
- package/dist/cjs/fork/getStateFromPath-mods.native.js +284 -0
- package/dist/cjs/fork/getStateFromPath-mods.native.js.map +6 -0
- package/dist/cjs/fork/getStateFromPath.cjs +181 -263
- package/dist/cjs/fork/getStateFromPath.js +148 -264
- package/dist/cjs/fork/getStateFromPath.js.map +2 -2
- package/dist/cjs/fork/getStateFromPath.native.js +164 -304
- package/dist/cjs/fork/getStateFromPath.native.js.map +2 -2
- package/dist/cjs/fork/useBackButton.js.map +1 -1
- package/dist/cjs/fork/useBackButton.native.js.map +1 -1
- package/dist/cjs/fork/useDocumentTitle.js +4 -1
- package/dist/cjs/fork/useDocumentTitle.js.map +1 -1
- package/dist/cjs/fork/useDocumentTitle.native.js +1 -1
- package/dist/cjs/fork/useDocumentTitle.native.js.map +2 -2
- package/dist/cjs/fork/useLinking.cjs +21 -24
- package/dist/cjs/fork/useLinking.js +21 -25
- package/dist/cjs/fork/useLinking.js.map +2 -2
- package/dist/cjs/fork/useLinking.native.js +68 -66
- package/dist/cjs/fork/useLinking.native.js.map +2 -2
- package/dist/cjs/fork/useThenable.js.map +1 -1
- package/dist/cjs/fork/useThenable.native.js.map +1 -1
- package/dist/cjs/fork/validatePathConfig.cjs +32 -11
- package/dist/cjs/fork/validatePathConfig.js +41 -11
- package/dist/cjs/fork/validatePathConfig.js.map +1 -1
- package/dist/cjs/fork/validatePathConfig.native.js +47 -18
- package/dist/cjs/fork/validatePathConfig.native.js.map +2 -2
- package/dist/cjs/layouts/withLayoutContext.cjs +1 -1
- package/dist/cjs/layouts/withLayoutContext.js +1 -1
- package/dist/cjs/layouts/withLayoutContext.js.map +1 -1
- package/dist/cjs/layouts/withLayoutContext.native.js +1 -1
- package/dist/cjs/layouts/withLayoutContext.native.js.map +1 -1
- package/dist/cjs/link/linking.cjs +4 -4
- package/dist/cjs/link/linking.js +3 -3
- package/dist/cjs/link/linking.js.map +2 -2
- package/dist/cjs/link/linking.native.js +3 -3
- package/dist/cjs/link/linking.native.js.map +1 -1
- package/dist/cjs/link/useLinkTo.cjs +2 -2
- package/dist/cjs/link/useLinkTo.js +2 -2
- package/dist/cjs/link/useLinkTo.js.map +1 -1
- package/dist/cjs/link/useLinkTo.native.js +2 -2
- package/dist/cjs/link/useLinkTo.native.js.map +1 -1
- package/dist/cjs/router/getNormalizedStatePath.cjs +2 -2
- package/dist/cjs/router/getNormalizedStatePath.js +2 -2
- package/dist/cjs/router/getNormalizedStatePath.js.map +1 -1
- package/dist/cjs/router/getNormalizedStatePath.native.js +2 -2
- package/dist/cjs/router/getNormalizedStatePath.native.js.map +1 -1
- package/dist/cjs/router/router.cjs +19 -3
- package/dist/cjs/router/router.js +25 -3
- package/dist/cjs/router/router.js.map +1 -1
- package/dist/cjs/router/router.native.js +39 -3
- package/dist/cjs/router/router.native.js.map +2 -2
- package/dist/cjs/utils/serverContext.cjs +7 -7
- package/dist/cjs/utils/serverContext.js +7 -7
- package/dist/cjs/utils/serverContext.js.map +1 -1
- package/dist/cjs/utils/serverContext.native.js +5 -5
- package/dist/cjs/utils/serverContext.native.js.map +2 -2
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.cjs +6 -6
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js +3 -4
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js.map +2 -2
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js +3 -4
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js.map +2 -2
- package/dist/esm/Root.js +6 -2
- package/dist/esm/Root.js.map +1 -1
- package/dist/esm/Root.mjs +1 -1
- package/dist/esm/Root.mjs.map +1 -1
- package/dist/esm/Root.native.js +1 -1
- package/dist/esm/Root.native.js.map +2 -2
- package/dist/esm/cli/build.js +2 -3
- package/dist/esm/cli/build.js.map +1 -1
- package/dist/esm/cli/build.mjs +2 -3
- package/dist/esm/cli/build.mjs.map +1 -1
- package/dist/esm/cli/build.native.js +2 -3
- package/dist/esm/cli/build.native.js.map +2 -2
- package/dist/esm/constants.js +7 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/constants.mjs +8 -2
- package/dist/esm/constants.mjs.map +1 -1
- package/dist/esm/constants.native.js +7 -1
- package/dist/esm/constants.native.js.map +2 -2
- package/dist/esm/fork/NavigationContainer.js +43 -20
- package/dist/esm/fork/NavigationContainer.js.map +1 -1
- package/dist/esm/fork/NavigationContainer.mjs +42 -24
- package/dist/esm/fork/NavigationContainer.mjs.map +1 -1
- package/dist/esm/fork/NavigationContainer.native.js +44 -24
- package/dist/esm/fork/NavigationContainer.native.js.map +2 -2
- package/dist/esm/fork/createMemoryHistory.js +3 -2
- package/dist/esm/fork/createMemoryHistory.js.map +1 -1
- package/dist/esm/fork/createMemoryHistory.mjs +4 -3
- package/dist/esm/fork/createMemoryHistory.mjs.map +1 -1
- package/dist/esm/fork/createMemoryHistory.native.js +4 -4
- package/dist/esm/fork/createMemoryHistory.native.js.map +2 -2
- package/dist/esm/fork/extractPathFromURL.js +42 -11
- package/dist/esm/fork/extractPathFromURL.js.map +1 -1
- package/dist/esm/fork/extractPathFromURL.mjs +39 -11
- package/dist/esm/fork/extractPathFromURL.mjs.map +1 -1
- package/dist/esm/fork/extractPathFromURL.native.js +52 -15
- package/dist/esm/fork/extractPathFromURL.native.js.map +2 -2
- package/dist/esm/fork/findFocusedRoute.js.map +1 -1
- package/dist/esm/fork/findFocusedRoute.mjs.map +1 -1
- package/dist/esm/fork/findFocusedRoute.native.js.map +1 -1
- package/dist/esm/fork/getPathFromState-mods.js +40 -0
- package/dist/esm/fork/getPathFromState-mods.js.map +6 -0
- package/dist/esm/fork/getPathFromState-mods.mjs +40 -0
- package/dist/esm/fork/getPathFromState-mods.mjs.map +1 -0
- package/dist/esm/fork/getPathFromState-mods.native.js +47 -0
- package/dist/esm/fork/getPathFromState-mods.native.js.map +6 -0
- package/dist/esm/fork/getPathFromState.js +71 -228
- package/dist/esm/fork/getPathFromState.js.map +2 -2
- package/dist/esm/fork/getPathFromState.mjs +73 -221
- package/dist/esm/fork/getPathFromState.mjs.map +1 -1
- package/dist/esm/fork/getPathFromState.native.js +79 -260
- package/dist/esm/fork/getPathFromState.native.js.map +2 -2
- package/dist/esm/fork/getStateFromPath-mods.js +176 -0
- package/dist/esm/fork/getStateFromPath-mods.js.map +6 -0
- package/dist/esm/fork/getStateFromPath-mods.mjs +143 -0
- package/dist/esm/fork/getStateFromPath-mods.mjs.map +1 -0
- package/dist/esm/fork/getStateFromPath-mods.native.js +246 -0
- package/dist/esm/fork/getStateFromPath-mods.native.js.map +6 -0
- package/dist/esm/fork/getStateFromPath.js +160 -265
- package/dist/esm/fork/getStateFromPath.js.map +2 -2
- package/dist/esm/fork/getStateFromPath.mjs +181 -260
- package/dist/esm/fork/getStateFromPath.mjs.map +1 -1
- package/dist/esm/fork/getStateFromPath.native.js +164 -302
- package/dist/esm/fork/getStateFromPath.native.js.map +2 -2
- package/dist/esm/fork/useBackButton.js.map +1 -1
- package/dist/esm/fork/useBackButton.mjs.map +1 -1
- package/dist/esm/fork/useBackButton.native.js.map +1 -1
- package/dist/esm/fork/useDocumentTitle.js +4 -1
- package/dist/esm/fork/useDocumentTitle.js.map +1 -1
- package/dist/esm/fork/useDocumentTitle.mjs.map +1 -1
- package/dist/esm/fork/useDocumentTitle.native.js +1 -1
- package/dist/esm/fork/useDocumentTitle.native.js.map +2 -2
- package/dist/esm/fork/useLinking.js +22 -26
- package/dist/esm/fork/useLinking.js.map +1 -1
- package/dist/esm/fork/useLinking.mjs +20 -23
- package/dist/esm/fork/useLinking.mjs.map +1 -1
- package/dist/esm/fork/useLinking.native.js +65 -67
- package/dist/esm/fork/useLinking.native.js.map +2 -2
- package/dist/esm/fork/useThenable.js.map +1 -1
- package/dist/esm/fork/useThenable.mjs.map +1 -1
- package/dist/esm/fork/useThenable.native.js.map +1 -1
- package/dist/esm/fork/validatePathConfig.js +41 -11
- package/dist/esm/fork/validatePathConfig.js.map +1 -1
- package/dist/esm/fork/validatePathConfig.mjs +32 -11
- package/dist/esm/fork/validatePathConfig.mjs.map +1 -1
- package/dist/esm/fork/validatePathConfig.native.js +43 -18
- package/dist/esm/fork/validatePathConfig.native.js.map +2 -2
- package/dist/esm/layouts/withLayoutContext.js +1 -1
- package/dist/esm/layouts/withLayoutContext.js.map +1 -1
- package/dist/esm/layouts/withLayoutContext.mjs +1 -1
- package/dist/esm/layouts/withLayoutContext.mjs.map +1 -1
- package/dist/esm/layouts/withLayoutContext.native.js +1 -1
- package/dist/esm/layouts/withLayoutContext.native.js.map +1 -1
- package/dist/esm/link/linking.js +2 -2
- package/dist/esm/link/linking.js.map +1 -1
- package/dist/esm/link/linking.mjs +2 -2
- package/dist/esm/link/linking.mjs.map +1 -1
- package/dist/esm/link/linking.native.js +2 -2
- package/dist/esm/link/linking.native.js.map +1 -1
- package/dist/esm/link/useLinkTo.js +1 -1
- package/dist/esm/link/useLinkTo.mjs +1 -1
- package/dist/esm/link/useLinkTo.native.js +1 -1
- package/dist/esm/router/getNormalizedStatePath.js +1 -1
- package/dist/esm/router/getNormalizedStatePath.mjs +1 -1
- package/dist/esm/router/getNormalizedStatePath.native.js +1 -1
- package/dist/esm/router/router.js +24 -2
- package/dist/esm/router/router.js.map +1 -1
- package/dist/esm/router/router.mjs +18 -2
- package/dist/esm/router/router.mjs.map +1 -1
- package/dist/esm/router/router.native.js +38 -2
- package/dist/esm/router/router.native.js.map +2 -2
- package/dist/esm/utils/serverContext.js +2 -1
- package/dist/esm/utils/serverContext.js.map +1 -1
- package/dist/esm/utils/serverContext.mjs +1 -1
- package/dist/esm/utils/serverContext.mjs.map +1 -1
- package/dist/esm/utils/serverContext.native.js +2 -1
- package/dist/esm/utils/serverContext.native.js.map +2 -2
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js +3 -3
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs +3 -3
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js +3 -3
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js.map +2 -2
- package/package.json +8 -9
- package/src/Root.tsx +6 -2
- package/src/cli/build.ts +2 -3
- package/src/constants.ts +8 -0
- package/src/fork/NavigationContainer.tsx +101 -39
- package/src/fork/createMemoryHistory.tsx +15 -13
- package/src/fork/extractPathFromURL.ts +85 -40
- package/src/fork/findFocusedRoute.tsx +9 -1
- package/src/fork/getPathFromState-mods.ts +142 -0
- package/src/fork/getPathFromState.ts +244 -501
- package/src/fork/getStateFromPath-mods.ts +400 -0
- package/src/fork/getStateFromPath.ts +447 -538
- package/src/fork/useBackButton.native.tsx +16 -2
- package/src/fork/useBackButton.tsx +11 -2
- package/src/fork/useDocumentTitle.native.tsx +9 -4
- package/src/fork/useDocumentTitle.tsx +12 -7
- package/src/fork/useLinking.native.ts +71 -63
- package/src/fork/useLinking.ts +75 -40
- package/src/fork/useThenable.tsx +7 -1
- package/src/fork/validatePathConfig.ts +64 -12
- package/src/layouts/withLayoutContext.tsx +1 -1
- package/src/link/linking.ts +2 -2
- package/src/link/useLinkTo.tsx +1 -1
- package/src/router/getNormalizedStatePath.tsx +1 -1
- package/src/router/router.ts +41 -2
- package/src/utils/serverContext.tsx +3 -1
- package/src/vite/plugins/fileSystemRouterPlugin.tsx +3 -3
- package/types/Root.d.ts.map +1 -1
- package/types/cli/build.d.ts.map +1 -1
- package/types/constants.d.ts +2 -0
- package/types/constants.d.ts.map +1 -1
- package/types/fork/NavigationContainer.d.ts +19 -8
- package/types/fork/NavigationContainer.d.ts.map +1 -1
- package/types/fork/createMemoryHistory.d.ts +10 -1
- package/types/fork/createMemoryHistory.d.ts.map +1 -1
- package/types/fork/extractPathFromURL.d.ts +7 -1
- package/types/fork/extractPathFromURL.d.ts.map +1 -1
- package/types/fork/findFocusedRoute.d.ts +9 -0
- package/types/fork/findFocusedRoute.d.ts.map +1 -1
- package/types/fork/getPathFromState-mods.d.ts +23 -0
- package/types/fork/getPathFromState-mods.d.ts.map +1 -0
- package/types/fork/getPathFromState.d.ts +15 -14
- package/types/fork/getPathFromState.d.ts.map +1 -1
- package/types/fork/getStateFromPath-mods.d.ts +58 -0
- package/types/fork/getStateFromPath-mods.d.ts.map +1 -0
- package/types/fork/getStateFromPath.d.ts +28 -29
- package/types/fork/getStateFromPath.d.ts.map +1 -1
- package/types/fork/useBackButton.d.ts +6 -0
- package/types/fork/useBackButton.d.ts.map +1 -1
- package/types/fork/useBackButton.native.d.ts +9 -1
- package/types/fork/useBackButton.native.d.ts.map +1 -1
- package/types/fork/useDocumentTitle.d.ts +8 -6
- package/types/fork/useDocumentTitle.d.ts.map +1 -1
- package/types/fork/useDocumentTitle.native.d.ts +5 -2
- package/types/fork/useDocumentTitle.native.d.ts.map +1 -1
- package/types/fork/useLinking.d.ts +8 -1
- package/types/fork/useLinking.d.ts.map +1 -1
- package/types/fork/useLinking.native.d.ts +9 -2
- package/types/fork/useLinking.native.d.ts.map +1 -1
- package/types/fork/useThenable.d.ts +6 -0
- package/types/fork/useThenable.d.ts.map +1 -1
- package/types/fork/validatePathConfig.d.ts +8 -1
- package/types/fork/validatePathConfig.d.ts.map +1 -1
- package/types/link/linking.d.ts +2 -2
- package/types/link/linking.d.ts.map +1 -1
- package/types/utils/serverContext.d.ts.map +1 -1
- package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
@@ -31,246 +31,182 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
31
31
|
}), mod);
|
32
32
|
var getStateFromPath_exports = {};
|
33
33
|
__export(getStateFromPath_exports, {
|
34
|
-
|
35
|
-
getMatchableRouteConfigs: () => getMatchableRouteConfigs,
|
36
|
-
getUrlWithReactNavigationConcessions: () => getUrlWithReactNavigationConcessions,
|
37
|
-
stripBaseUrl: () => stripBaseUrl
|
34
|
+
getStateFromPath: () => getStateFromPath
|
38
35
|
});
|
39
36
|
module.exports = __toCommonJS(getStateFromPath_exports);
|
40
37
|
var import_escape_string_regexp = __toESM(require("escape-string-regexp"), 1),
|
41
|
-
import_matchers = require("../router/matchers.cjs"),
|
42
38
|
import_findFocusedRoute = require("./findFocusedRoute.cjs"),
|
43
|
-
import_validatePathConfig =
|
44
|
-
|
45
|
-
let parsed;
|
46
|
-
try {
|
47
|
-
parsed = new URL(path, baseUrl || "http://phony.example");
|
48
|
-
} catch (err) {
|
49
|
-
return console.warn(`Error parsing url ${path}: ${err?.message}`), {
|
50
|
-
nonstandardPathname: path,
|
51
|
-
inputPathnameWithoutHash: path.replace(/#.*$/g, ""),
|
52
|
-
url: null
|
53
|
-
};
|
54
|
-
}
|
55
|
-
const pathname = parsed.pathname;
|
56
|
-
return {
|
57
|
-
// The slashes are at the end, not the beginning
|
58
|
-
nonstandardPathname: stripBaseUrl(pathname, baseUrl).replace(/^\/+/g, "").replace(/\/+$/g, "") + "/",
|
59
|
-
url: parsed
|
60
|
-
};
|
61
|
-
}
|
39
|
+
import_validatePathConfig = require("./validatePathConfig.cjs"),
|
40
|
+
import_getStateFromPath_mods = require("./getStateFromPath-mods.cjs");
|
62
41
|
function getStateFromPath(path, options) {
|
63
42
|
const {
|
43
|
+
initialRoutes,
|
44
|
+
configs,
|
45
|
+
configWithRegexes
|
46
|
+
} = getConfigResources(options),
|
47
|
+
screens = options?.screens,
|
48
|
+
pathData = (0, import_getStateFromPath_mods.getUrlWithReactNavigationConcessions)(path);
|
49
|
+
let remaining = pathData.nonstandardPathname.replace(/\/+/g, "/").replace(/^\//, "").replace(/\?.*$/, "");
|
50
|
+
remaining = remaining.endsWith("/") ? remaining : `${remaining}/`;
|
51
|
+
const prefix = options?.path?.replace(/^\//, "");
|
52
|
+
if (prefix) {
|
53
|
+
const normalizedPrefix = prefix.endsWith("/") ? prefix : `${prefix}/`;
|
54
|
+
if (!remaining.startsWith(normalizedPrefix)) return;
|
55
|
+
remaining = remaining.replace(normalizedPrefix, "");
|
56
|
+
}
|
57
|
+
if (screens === void 0) {
|
58
|
+
const routes2 = remaining.split("/").filter(Boolean).map(segment => ({
|
59
|
+
name: decodeURIComponent(segment)
|
60
|
+
}));
|
61
|
+
return routes2.length ? createNestedStateObject(pathData, routes2, initialRoutes, [], pathData.url.hash) : void 0;
|
62
|
+
}
|
63
|
+
if (remaining === "/") {
|
64
|
+
const match = (0, import_getStateFromPath_mods.matchForEmptyPath)(configWithRegexes);
|
65
|
+
return match ? createNestedStateObject(pathData,
|
66
|
+
// @modified: pass pathData instead of path
|
67
|
+
match.routeNames.map(name => ({
|
68
|
+
name
|
69
|
+
})), initialRoutes, configs) : void 0;
|
70
|
+
}
|
71
|
+
let result, current;
|
72
|
+
const {
|
73
|
+
routes,
|
74
|
+
remainingPath
|
75
|
+
} = matchAgainstConfigs(remaining, configWithRegexes);
|
76
|
+
if (routes !== void 0 && (current = createNestedStateObject(pathData, routes, initialRoutes, configs), remaining = remainingPath, result = current), !(current == null || result == null)) return result;
|
77
|
+
}
|
78
|
+
const cachedConfigResources = /* @__PURE__ */new WeakMap();
|
79
|
+
function getConfigResources(options) {
|
80
|
+
if (!options) return prepareConfigResources();
|
81
|
+
const cached = cachedConfigResources.get(options);
|
82
|
+
if (cached) return cached;
|
83
|
+
const resources = prepareConfigResources(options);
|
84
|
+
return cachedConfigResources.set(options, resources), resources;
|
85
|
+
}
|
86
|
+
function prepareConfigResources(options, previousSegments) {
|
87
|
+
options && (0, import_validatePathConfig.validatePathConfig)(options);
|
88
|
+
const initialRoutes = getInitialRoutes(options),
|
89
|
+
configs = getNormalizedConfigs(initialRoutes, options?.screens, previousSegments);
|
90
|
+
checkForDuplicatedConfigs(configs);
|
91
|
+
const configWithRegexes = getConfigsWithRegexes(configs);
|
92
|
+
return {
|
64
93
|
initialRoutes,
|
65
|
-
configs
|
66
|
-
|
67
|
-
|
94
|
+
configs,
|
95
|
+
configWithRegexes
|
96
|
+
};
|
68
97
|
}
|
69
|
-
function
|
70
|
-
options && (0, import_validatePathConfig.default)(options);
|
71
|
-
const screens = options?.screens;
|
72
|
-
if (!screens) throw Error("You must pass a 'screens' object to 'getStateFromPath' to generate a path.");
|
98
|
+
function getInitialRoutes(options) {
|
73
99
|
const initialRoutes = [];
|
74
|
-
options?.initialRouteName && initialRoutes.push({
|
100
|
+
return options?.initialRouteName && initialRoutes.push({
|
75
101
|
initialRouteName: options.initialRouteName,
|
76
102
|
parentScreens: []
|
77
|
-
});
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
...config,
|
82
|
-
// TODO: Probably a safer way to do this
|
83
|
-
// Mark initial routes to give them potential priority over other routes that match.
|
84
|
-
isInitial: resolvedInitialPatterns.includes(config.routeNames.join("/"))
|
85
|
-
})).sort(sortConfigs);
|
86
|
-
return assertConfigDuplicates(configs), {
|
87
|
-
configs,
|
88
|
-
initialRoutes
|
89
|
-
};
|
103
|
+
}), initialRoutes;
|
104
|
+
}
|
105
|
+
function getNormalizedConfigs(initialRoutes, screens = {}, previousSegments) {
|
106
|
+
return [].concat(...Object.keys(screens).map(key => createNormalizedConfigs(key, screens, [], initialRoutes, []))).map((0, import_getStateFromPath_mods.appendIsInitial)(initialRoutes)).sort((0, import_getStateFromPath_mods.getRouteConfigSorter)(previousSegments));
|
90
107
|
}
|
91
|
-
function
|
108
|
+
function checkForDuplicatedConfigs(configs) {
|
92
109
|
configs.reduce((acc, config) => {
|
93
|
-
|
94
|
-
|
95
|
-
if (alpha && !alpha.hasChildren && !config.hasChildren) {
|
96
|
-
const a = alpha.routeNames,
|
110
|
+
if (acc[config.pattern]) {
|
111
|
+
const a = acc[config.pattern].routeNames,
|
97
112
|
b = config.routeNames;
|
98
|
-
if (!(a.length > b.length ? b.every((it, i) => a[i] === it) : a.every((it, i) => b[i] === it))) {
|
99
|
-
const last = config.pattern.split("/").pop();
|
100
|
-
if (!last?.match(/^\*not-found$/)) {
|
101
|
-
const routeType = last?.startsWith(":") ? "dynamic route" : last?.startsWith("*") ? "dynamic-rest route" : "route";
|
102
|
-
throw new Error(`The ${routeType} pattern '${config.pattern || "/"}' resolves to both '${alpha.userReadableName}' and '${config.userReadableName}'. Patterns must be unique and cannot resolve to more than one route.`);
|
103
|
-
}
|
104
|
-
}
|
113
|
+
if (!(a.length > b.length ? b.every((it, i) => a[i] === it) : a.every((it, i) => b[i] === it))) throw new Error(`Found conflicting screens with the same pattern. The pattern '${config.pattern}' resolves to both '${a.join(" > ")}' and '${b.join(" > ")}'. Patterns must be unique and cannot resolve to more than one screen.`);
|
105
114
|
}
|
106
115
|
return Object.assign(acc, {
|
107
|
-
[
|
116
|
+
[config.pattern]: config
|
108
117
|
});
|
109
118
|
}, {});
|
110
119
|
}
|
111
|
-
function
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
(b.screen === "index" || b.screen.match(/\/index$/)) && bParts.push("index");
|
121
|
-
for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
|
122
|
-
if (aParts[i] == null) return 1;
|
123
|
-
if (bParts[i] == null) return -1;
|
124
|
-
const aWildCard = aParts[i].startsWith("*"),
|
125
|
-
bWildCard = bParts[i].startsWith("*");
|
126
|
-
if (aWildCard && bWildCard) {
|
127
|
-
const aNotFound = aParts[i].match(/^[*]not-found$/),
|
128
|
-
bNotFound = bParts[i].match(/^[*]not-found$/);
|
129
|
-
if (aNotFound && bNotFound) continue;
|
130
|
-
if (aNotFound) return 1;
|
131
|
-
if (bNotFound) return -1;
|
132
|
-
continue;
|
133
|
-
}
|
134
|
-
if (aWildCard) return 1;
|
135
|
-
if (bWildCard) return -1;
|
136
|
-
const aSlug = aParts[i].startsWith(":"),
|
137
|
-
bSlug = bParts[i].startsWith(":");
|
138
|
-
if (aSlug && bSlug) {
|
139
|
-
const aNotFound = aParts[i].match(/^[*]not-found$/),
|
140
|
-
bNotFound = bParts[i].match(/^[*]not-found$/);
|
141
|
-
if (aNotFound && bNotFound) continue;
|
142
|
-
if (aNotFound) return 1;
|
143
|
-
if (bNotFound) return -1;
|
144
|
-
continue;
|
145
|
-
}
|
146
|
-
if (aSlug) return 1;
|
147
|
-
if (bSlug) return -1;
|
148
|
-
}
|
149
|
-
return a.isInitial && !b.isInitial ? -1 : !a.isInitial && b.isInitial ? 1 : bParts.length - aParts.length;
|
150
|
-
}
|
151
|
-
function getStateFromEmptyPathWithConfigs(path, hash, configs, initialRoutes) {
|
152
|
-
const leafNodes = configs.filter(config => !config.hasChildren).map(value => ({
|
153
|
-
...value,
|
154
|
-
// Collapse all levels of group segments before testing.
|
155
|
-
// This enables `app/(one)/(two)/index.js` to be matched.
|
156
|
-
path: (0, import_matchers.stripGroupSegmentsFromPath)(value.path)
|
157
|
-
})),
|
158
|
-
match = leafNodes.find(config =>
|
159
|
-
// NOTE: Test leaf node index routes that either don't have a regex or match an empty string.
|
160
|
-
config.path === "" && (!config.regex || config.regex.test(""))) ?? leafNodes.find(config =>
|
161
|
-
// NOTE: Test leaf node dynamic routes that match an empty string.
|
162
|
-
config.path.startsWith(":") && config.regex.test("")) ??
|
163
|
-
// NOTE: Test leaf node deep dynamic routes that match a slash.
|
164
|
-
// This should be done last to enable dynamic routes having a higher priority.
|
165
|
-
leafNodes.find(config => config.path.startsWith("*") && config.regex.test("/"));
|
166
|
-
if (!match) return;
|
167
|
-
const routes = match.routeNames.map(name => match._route ? {
|
168
|
-
name,
|
169
|
-
_route: match._route
|
170
|
-
} : {
|
171
|
-
name
|
172
|
-
});
|
173
|
-
return createNestedStateObject(path, hash, routes, configs, initialRoutes);
|
120
|
+
function getConfigsWithRegexes(configs) {
|
121
|
+
return configs.map(c => ({
|
122
|
+
...c,
|
123
|
+
// Add `$` to the regex to make sure it matches till end of the path and not just beginning
|
124
|
+
// @modified - start
|
125
|
+
// regex: c.regex ? new RegExp(c.regex.source + '$') : undefined,
|
126
|
+
regex: c.pattern ? new RegExp(`^(${c.pattern.split("/").map(import_getStateFromPath_mods.formatRegexPattern).join("")})$`) : void 0
|
127
|
+
// @modified - end
|
128
|
+
}));
|
174
129
|
}
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
}
|
221
|
-
|
222
|
-
|
223
|
-
};
|
224
|
-
routes = config.routeNames.map(name => config._route ? {
|
225
|
-
...routeFromName(name),
|
226
|
-
_route: config._route
|
227
|
-
} : {
|
228
|
-
...routeFromName(name)
|
229
|
-
});
|
230
|
-
const combinedParams = routes.reduce((acc, r) => Object.assign(acc, r.params), {}),
|
231
|
-
hasCombinedParams = Object.keys(combinedParams).length > 0;
|
232
|
-
routes = routes.map(r => (hasCombinedParams && (r.params = combinedParams), r)), remainingPath = remainingPath.replace(match[1], "");
|
233
|
-
break;
|
234
|
-
}
|
235
|
-
return routes;
|
236
|
-
}
|
237
|
-
function equalHeritage(a, b) {
|
238
|
-
if (a.length !== b.length) return !1;
|
239
|
-
for (let i = 0; i < a.length; i++) if (a[i].localeCompare(b[i]) !== 0) return !1;
|
240
|
-
return !0;
|
241
|
-
}
|
242
|
-
const createNormalizedConfigs = (screen, routeConfig, routeNames = [], initials = [], parentScreens = [], parentPattern) => {
|
243
|
-
const configs = [];
|
244
|
-
routeNames.push(screen), parentScreens.push(screen);
|
245
|
-
const config = routeConfig[screen];
|
246
|
-
if (typeof config == "string") {
|
247
|
-
const pattern = parentPattern ? joinPaths(parentPattern, config) : config;
|
248
|
-
configs.push(createConfigItem(screen, routeNames, pattern, config, !1));
|
249
|
-
} else if (typeof config == "object") {
|
250
|
-
let pattern;
|
251
|
-
const {
|
252
|
-
_route
|
253
|
-
} = config;
|
254
|
-
if (typeof config.path == "string") {
|
255
|
-
if (config.exact && config.path === void 0) throw new Error("A 'path' needs to be specified when specifying 'exact: true'. If you don't want this screen in the URL, specify it as empty string, e.g. `path: ''`.");
|
256
|
-
pattern = config.exact !== !0 ? joinPaths(parentPattern || "", config.path || "") : config.path || "", configs.push(createConfigItem(screen, routeNames, pattern, config.path, config.screens ? !!Object.keys(config.screens)?.length : !1, config.parse, _route));
|
130
|
+
const joinPaths = (...paths) => [].concat(...paths.map(p => p.split("/"))).filter(Boolean).join("/"),
|
131
|
+
matchAgainstConfigs = (remaining, configs) => {
|
132
|
+
let routes,
|
133
|
+
remainingPath = remaining;
|
134
|
+
const allParams = /* @__PURE__ */Object.create(null);
|
135
|
+
for (const config of configs) {
|
136
|
+
if (!config.regex) continue;
|
137
|
+
const match = remainingPath.match(config.regex);
|
138
|
+
if (match) {
|
139
|
+
const matchedParams = (config.pattern?.split("/").reduce((acc, p, index) => {
|
140
|
+
if (!p.startsWith(":")) return acc;
|
141
|
+
acc.pos += 1;
|
142
|
+
const decodedParamSegment = (0, import_getStateFromPath_mods.decodeURIComponentSafe)(
|
143
|
+
// @modified: use decodeURIComponent**Safe**
|
144
|
+
// The param segments appear every second item starting from 2 in the regex match result
|
145
|
+
match[(acc.pos + 1) * 2].replace(/\/$/, ""));
|
146
|
+
return Object.assign(acc.matchedParams, {
|
147
|
+
[p]: Object.assign(acc.matchedParams[p] || {}, {
|
148
|
+
[index]: decodedParamSegment
|
149
|
+
})
|
150
|
+
}), acc;
|
151
|
+
}, {
|
152
|
+
pos: -1,
|
153
|
+
matchedParams: {}
|
154
|
+
})).matchedParams || {};
|
155
|
+
routes = config.routeNames.map(name => {
|
156
|
+
const routeConfig = configs.find(c => c.screen === name && config.pattern.startsWith(c.pattern)),
|
157
|
+
normalizedPath = routeConfig?.path.split("/").filter(Boolean).join("/"),
|
158
|
+
numInitialSegments = routeConfig?.pattern.replace(new RegExp(`${(0, import_escape_string_regexp.default)(normalizedPath)}$`), "")?.split("/").length,
|
159
|
+
params = normalizedPath?.split("/").reduce((acc, p, index) => {
|
160
|
+
if (!p.startsWith(":")) return acc;
|
161
|
+
const offset = numInitialSegments ? numInitialSegments - 1 : 0,
|
162
|
+
value = (0, import_getStateFromPath_mods.getParamValue)(p, matchedParams[p]?.[index + offset]);
|
163
|
+
if (value) {
|
164
|
+
const key = p.replace(/^:/, "").replace(/\?$/, "");
|
165
|
+
acc[key] = routeConfig?.parse?.[key] ? routeConfig.parse[key](value) : value;
|
166
|
+
}
|
167
|
+
return acc;
|
168
|
+
}, {});
|
169
|
+
return params && Object.keys(params).length ? {
|
170
|
+
name,
|
171
|
+
params
|
172
|
+
} : {
|
173
|
+
name
|
174
|
+
};
|
175
|
+
}), remainingPath = remainingPath.replace(match[1], "");
|
176
|
+
break;
|
177
|
+
}
|
257
178
|
}
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
}
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
}
|
271
|
-
|
179
|
+
return (0, import_getStateFromPath_mods.populateParams)(routes, allParams), {
|
180
|
+
routes,
|
181
|
+
remainingPath
|
182
|
+
};
|
183
|
+
},
|
184
|
+
createNormalizedConfigs = (screen, routeConfig, routeNames = [], initials, parentScreens, parentPattern) => {
|
185
|
+
const configs = [];
|
186
|
+
routeNames.push(screen), parentScreens.push(screen);
|
187
|
+
const config = routeConfig[screen];
|
188
|
+
if (typeof config == "string") {
|
189
|
+
const pattern = parentPattern ? joinPaths(parentPattern, config) : config;
|
190
|
+
configs.push(createConfigItem(screen, routeNames, pattern, config));
|
191
|
+
} else if (typeof config == "object") {
|
192
|
+
let pattern;
|
193
|
+
if (typeof config.path == "string") {
|
194
|
+
if (config.exact && config.path === void 0) throw new Error("A 'path' needs to be specified when specifying 'exact: true'. If you don't want this screen in the URL, specify it as empty string, e.g. `path: ''`.");
|
195
|
+
pattern = config.exact !== !0 ? joinPaths(parentPattern || "", config.path || "") : config.path || "", configs.push(createConfigItem(screen, routeNames, pattern, config.path, config.parse, config));
|
196
|
+
}
|
197
|
+
config.screens && (config.initialRouteName && initials.push({
|
198
|
+
initialRouteName: config.initialRouteName,
|
199
|
+
parentScreens
|
200
|
+
}), Object.keys(config.screens).forEach(nestedConfig => {
|
201
|
+
const result = createNormalizedConfigs(nestedConfig, config.screens, routeNames, initials, [...parentScreens], pattern ?? parentPattern);
|
202
|
+
configs.push(...result);
|
203
|
+
}));
|
204
|
+
}
|
205
|
+
return routeNames.pop(), configs;
|
206
|
+
},
|
207
|
+
createConfigItem = (screen, routeNames, pattern, path, parse = void 0, config = {}) => {
|
272
208
|
pattern = pattern.split("/").filter(Boolean).join("/");
|
273
|
-
const regex = pattern ? new RegExp(`^(${pattern.split("/").map(
|
209
|
+
const regex = pattern ? new RegExp(`^(${pattern.split("/").map(it => it.startsWith(":") ? `(([^/]+\\/)${it.endsWith("?") ? "?" : ""})` : `${it === "*" ? ".*" : (0, import_escape_string_regexp.default)(it)}\\/`).join("")})`) : void 0;
|
274
210
|
return {
|
275
211
|
screen,
|
276
212
|
regex,
|
@@ -279,18 +215,25 @@ const createConfigItem = (screen, routeNames, pattern, path, hasChildren, parse,
|
|
279
215
|
// The routeNames array is mutated, so copy it to keep the current state
|
280
216
|
routeNames: [...routeNames],
|
281
217
|
parse,
|
282
|
-
|
283
|
-
|
284
|
-
|
218
|
+
// @modified - start
|
219
|
+
...(0, import_getStateFromPath_mods.createConfigItemAdditionalProperties)(screen, pattern, routeNames, config)
|
220
|
+
// @modified - end
|
285
221
|
};
|
286
222
|
},
|
287
|
-
findParseConfigForRoute = (routeName,
|
288
|
-
for (const config of
|
223
|
+
findParseConfigForRoute = (routeName, flatConfig) => {
|
224
|
+
for (const config of flatConfig) if (routeName === config.routeNames[config.routeNames.length - 1]) return config.parse;
|
289
225
|
},
|
290
226
|
findInitialRoute = (routeName, parentScreens, initialRoutes) => {
|
291
|
-
for (const config of initialRoutes) if (
|
227
|
+
for (const config of initialRoutes) if (parentScreens.length === config.parentScreens.length) {
|
228
|
+
let sameParents = !0;
|
229
|
+
for (let i = 0; i < parentScreens.length; i++) if (parentScreens[i].localeCompare(config.parentScreens[i]) !== 0) {
|
230
|
+
sameParents = !1;
|
231
|
+
break;
|
232
|
+
}
|
233
|
+
if (sameParents) return routeName !== config.initialRouteName ? config.initialRouteName : void 0;
|
234
|
+
}
|
292
235
|
},
|
293
|
-
createStateObject = (route, isEmpty
|
236
|
+
createStateObject = (initialRoute, route, isEmpty) => isEmpty ? initialRoute ? {
|
294
237
|
index: 1,
|
295
238
|
routes: [{
|
296
239
|
name: initialRoute
|
@@ -315,52 +258,27 @@ const createConfigItem = (screen, routeNames, pattern, path, hasChildren, parse,
|
|
315
258
|
}
|
316
259
|
}]
|
317
260
|
},
|
318
|
-
createNestedStateObject = (
|
261
|
+
createNestedStateObject = ({
|
262
|
+
path,
|
263
|
+
...restPathData
|
264
|
+
}, routes, initialRoutes, flatConfig, hash) => {
|
319
265
|
let route = routes.shift();
|
320
266
|
const parentScreens = [];
|
321
267
|
let initialRoute = findInitialRoute(route.name, parentScreens, initialRoutes);
|
322
268
|
parentScreens.push(route.name);
|
323
|
-
const state = createStateObject(route, routes.length === 0
|
269
|
+
const state = createStateObject(initialRoute, route, routes.length === 0);
|
324
270
|
if (routes.length > 0) {
|
325
271
|
let nestedState = state;
|
326
272
|
for (; route = routes.shift();) {
|
327
273
|
initialRoute = findInitialRoute(route.name, parentScreens, initialRoutes);
|
328
274
|
const nestedStateIndex = nestedState.index || nestedState.routes.length - 1;
|
329
|
-
nestedState.routes[nestedStateIndex].state = createStateObject(route, routes.length === 0
|
275
|
+
nestedState.routes[nestedStateIndex].state = createStateObject(initialRoute, route, routes.length === 0), routes.length > 0 && (nestedState = nestedState.routes[nestedStateIndex].state), parentScreens.push(route.name);
|
330
276
|
}
|
331
277
|
}
|
332
|
-
route = (0, import_findFocusedRoute.findFocusedRoute)(state), route.path =
|
333
|
-
const params =
|
334
|
-
|
335
|
-
route.params
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
}
|
340
|
-
Object.keys(route.params).length === 0 && delete route.params;
|
341
|
-
}
|
342
|
-
return hash && (route.params = Object.assign(/* @__PURE__ */Object.create(null), route.params), route.params["#"] = hash), state;
|
343
|
-
},
|
344
|
-
parseQueryParams = (path, parseConfig) => {
|
345
|
-
const query = path.split("?")[1],
|
346
|
-
searchParams = new URLSearchParams(query),
|
347
|
-
params = Object.fromEntries(
|
348
|
-
// @ts-ignore: [Symbol.iterator] is indeed, available on every platform.
|
349
|
-
searchParams);
|
350
|
-
return parseConfig && Object.keys(params).forEach(name => {
|
351
|
-
Object.hasOwnProperty.call(parseConfig, name) && typeof params[name] == "string" && (params[name] = parseConfig[name](params[name]));
|
352
|
-
}), Object.keys(params).length ? params : void 0;
|
353
|
-
},
|
354
|
-
baseUrlCache = /* @__PURE__ */new Map();
|
355
|
-
function getBaseUrlRegex(baseUrl) {
|
356
|
-
if (baseUrlCache.has(baseUrl)) return baseUrlCache.get(baseUrl);
|
357
|
-
const regex = new RegExp(`^\\/?${(0, import_escape_string_regexp.default)(baseUrl)}`, "g");
|
358
|
-
return baseUrlCache.set(baseUrl, regex), regex;
|
359
|
-
}
|
360
|
-
function stripBaseUrl(path, baseUrl = process.env.EXPO_BASE_URL) {
|
361
|
-
if (process.env.NODE_ENV !== "development" && baseUrl) {
|
362
|
-
const reg = getBaseUrlRegex(baseUrl);
|
363
|
-
return path.replace(/^\/+/g, "/").replace(reg, "");
|
364
|
-
}
|
365
|
-
return path;
|
366
|
-
}
|
278
|
+
route = (0, import_findFocusedRoute.findFocusedRoute)(state), route.path = restPathData.pathWithoutGroups;
|
279
|
+
const params = (0, import_getStateFromPath_mods.parseQueryParamsExtended)(path, route, flatConfig ? findParseConfigForRoute(route.name, flatConfig) : void 0, hash);
|
280
|
+
return params && (route.params = {
|
281
|
+
...route.params,
|
282
|
+
...params
|
283
|
+
}), state;
|
284
|
+
};
|