tanexpo 0.2.0
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/components/Link.d.mts +7 -0
- package/dist/components/Link.d.ts +7 -0
- package/dist/components/Link.js +81 -0
- package/dist/components/Link.js.map +1 -0
- package/dist/components/Link.mjs +56 -0
- package/dist/components/Link.mjs.map +1 -0
- package/dist/components/Link.native.d.mts +7 -0
- package/dist/components/Link.native.d.ts +7 -0
- package/dist/components/Link.native.js +35 -0
- package/dist/components/Link.native.js.map +1 -0
- package/dist/components/Link.native.mjs +10 -0
- package/dist/components/Link.native.mjs.map +1 -0
- package/dist/components/Redirect.d.mts +16 -0
- package/dist/components/Redirect.d.ts +16 -0
- package/dist/components/Redirect.js +69 -0
- package/dist/components/Redirect.js.map +1 -0
- package/dist/components/Redirect.mjs +44 -0
- package/dist/components/Redirect.mjs.map +1 -0
- package/dist/components/Redirect.native.d.mts +1 -0
- package/dist/components/Redirect.native.d.ts +1 -0
- package/dist/components/Redirect.native.js +31 -0
- package/dist/components/Redirect.native.js.map +1 -0
- package/dist/components/Redirect.native.mjs +6 -0
- package/dist/components/Redirect.native.mjs.map +1 -0
- package/dist/components/index.d.mts +5 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +106 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +78 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/hooks/index.d.mts +5 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.js +91 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +63 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/hooks/useLocalSearchParams.d.mts +13 -0
- package/dist/hooks/useLocalSearchParams.d.ts +13 -0
- package/dist/hooks/useLocalSearchParams.js +39 -0
- package/dist/hooks/useLocalSearchParams.js.map +1 -0
- package/dist/hooks/useLocalSearchParams.mjs +14 -0
- package/dist/hooks/useLocalSearchParams.mjs.map +1 -0
- package/dist/hooks/useLocalSearchParams.native.d.mts +1 -0
- package/dist/hooks/useLocalSearchParams.native.d.ts +1 -0
- package/dist/hooks/useLocalSearchParams.native.js +31 -0
- package/dist/hooks/useLocalSearchParams.native.js.map +1 -0
- package/dist/hooks/useLocalSearchParams.native.mjs +6 -0
- package/dist/hooks/useLocalSearchParams.native.mjs.map +1 -0
- package/dist/hooks/useRouter.d.mts +13 -0
- package/dist/hooks/useRouter.d.ts +13 -0
- package/dist/hooks/useRouter.js +76 -0
- package/dist/hooks/useRouter.js.map +1 -0
- package/dist/hooks/useRouter.mjs +51 -0
- package/dist/hooks/useRouter.mjs.map +1 -0
- package/dist/hooks/useRouter.native.d.mts +12 -0
- package/dist/hooks/useRouter.native.d.ts +12 -0
- package/dist/hooks/useRouter.native.js +41 -0
- package/dist/hooks/useRouter.native.js.map +1 -0
- package/dist/hooks/useRouter.native.mjs +16 -0
- package/dist/hooks/useRouter.native.mjs.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +149 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +119 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.native.d.mts +7 -0
- package/dist/index.native.d.ts +7 -0
- package/dist/index.native.js +62 -0
- package/dist/index.native.js.map +1 -0
- package/dist/index.native.mjs +32 -0
- package/dist/index.native.mjs.map +1 -0
- package/dist/types-BrqVaE2O.d.mts +21 -0
- package/dist/types-BrqVaE2O.d.ts +21 -0
- package/dist/utils/route-utils.d.mts +19 -0
- package/dist/utils/route-utils.d.ts +19 -0
- package/dist/utils/route-utils.js +48 -0
- package/dist/utils/route-utils.js.map +1 -0
- package/dist/utils/route-utils.mjs +22 -0
- package/dist/utils/route-utils.mjs.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
|
|
20
|
+
// src/hooks/useRouter.native.ts
|
|
21
|
+
var useRouter_native_exports = {};
|
|
22
|
+
__export(useRouter_native_exports, {
|
|
23
|
+
useRouter: () => useRouter
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(useRouter_native_exports);
|
|
26
|
+
var import_expo_router = require("expo-router");
|
|
27
|
+
function useRouter() {
|
|
28
|
+
const router = (0, import_expo_router.useRouter)();
|
|
29
|
+
return {
|
|
30
|
+
push: router.push,
|
|
31
|
+
replace: router.replace,
|
|
32
|
+
back: router.back,
|
|
33
|
+
prefetch: router.prefetch,
|
|
34
|
+
navigate: router.push
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
useRouter
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=useRouter.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useRouter.native.ts"],"sourcesContent":["import { useRouter as useExpoRouter } from \"expo-router\";\n\nexport function useRouter() {\n const router = useExpoRouter();\n\n return {\n push: router.push,\n replace: router.replace,\n back: router.back,\n prefetch: router.prefetch,\n navigate: router.push,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA2C;AAEpC,SAAS,YAAY;AAC1B,QAAM,aAAS,mBAAAA,WAAc;AAE7B,SAAO;AAAA,IACL,MAAM,OAAO;AAAA,IACb,SAAS,OAAO;AAAA,IAChB,MAAM,OAAO;AAAA,IACb,UAAU,OAAO;AAAA,IACjB,UAAU,OAAO;AAAA,EACnB;AACF;","names":["useExpoRouter"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/hooks/useRouter.native.ts
|
|
2
|
+
import { useRouter as useExpoRouter } from "expo-router";
|
|
3
|
+
function useRouter() {
|
|
4
|
+
const router = useExpoRouter();
|
|
5
|
+
return {
|
|
6
|
+
push: router.push,
|
|
7
|
+
replace: router.replace,
|
|
8
|
+
back: router.back,
|
|
9
|
+
prefetch: router.prefetch,
|
|
10
|
+
navigate: router.push
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
useRouter
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=useRouter.native.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useRouter.native.ts"],"sourcesContent":["import { useRouter as useExpoRouter } from \"expo-router\";\n\nexport function useRouter() {\n const router = useExpoRouter();\n\n return {\n push: router.push,\n replace: router.replace,\n back: router.back,\n prefetch: router.prefetch,\n navigate: router.push,\n };\n}\n"],"mappings":";AAAA,SAAS,aAAa,qBAAqB;AAEpC,SAAS,YAAY;AAC1B,QAAM,SAAS,cAAc;AAE7B,SAAO;AAAA,IACL,MAAM,OAAO;AAAA,IACb,SAAS,OAAO;AAAA,IAChB,MAAM,OAAO;AAAA,IACb,UAAU,OAAO;AAAA,IACjB,UAAU,OAAO;AAAA,EACnB;AACF;","names":[]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Link } from './components/Link.mjs';
|
|
2
|
+
export { Redirect } from './components/Redirect.mjs';
|
|
3
|
+
export { useLocalSearchParams } from './hooks/useLocalSearchParams.mjs';
|
|
4
|
+
export { useRouter } from './hooks/useRouter.mjs';
|
|
5
|
+
export { H as Href, a as HrefObject, L as LinkProps, b as LocalSearchParams, P as Prefetch } from './types-BrqVaE2O.mjs';
|
|
6
|
+
import 'react/jsx-runtime';
|
|
7
|
+
import '@tanstack/router-core';
|
|
8
|
+
import 'react';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Link } from './components/Link.js';
|
|
2
|
+
export { Redirect } from './components/Redirect.js';
|
|
3
|
+
export { useLocalSearchParams } from './hooks/useLocalSearchParams.js';
|
|
4
|
+
export { useRouter } from './hooks/useRouter.js';
|
|
5
|
+
export { H as Href, a as HrefObject, L as LinkProps, b as LocalSearchParams, P as Prefetch } from './types-BrqVaE2O.js';
|
|
6
|
+
import 'react/jsx-runtime';
|
|
7
|
+
import '@tanstack/router-core';
|
|
8
|
+
import 'react';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Link: () => Link,
|
|
24
|
+
Redirect: () => Redirect,
|
|
25
|
+
useLocalSearchParams: () => useLocalSearchParams,
|
|
26
|
+
useRouter: () => useRouter
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/components/Link.tsx
|
|
31
|
+
var import_react_router = require("@tanstack/react-router");
|
|
32
|
+
|
|
33
|
+
// src/utils/route-utils.ts
|
|
34
|
+
function expoPathToTanStack(pathname) {
|
|
35
|
+
return pathname.replace(/\[([^\]]+)\]/g, (_, key) => `$${key}`);
|
|
36
|
+
}
|
|
37
|
+
function splitParams(pathname, params = {}) {
|
|
38
|
+
const dynamicKeys = Array.from(pathname.matchAll(/\[([^\]]+)\]/g), (m) => m[1]);
|
|
39
|
+
const pathParams = {};
|
|
40
|
+
const searchParams = {};
|
|
41
|
+
for (const [key, value] of Object.entries(params)) {
|
|
42
|
+
if (dynamicKeys.includes(key)) {
|
|
43
|
+
pathParams[key] = value;
|
|
44
|
+
} else {
|
|
45
|
+
searchParams[key] = value;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { pathParams, searchParams };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/components/Link.tsx
|
|
52
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
53
|
+
function mapPrefetchToPreload(prefetch) {
|
|
54
|
+
if (prefetch === void 0 || prefetch === false) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (prefetch === true) {
|
|
58
|
+
return "intent";
|
|
59
|
+
}
|
|
60
|
+
return prefetch;
|
|
61
|
+
}
|
|
62
|
+
function Link({ href, replace, prefetch, children }) {
|
|
63
|
+
const preload = mapPrefetchToPreload(prefetch);
|
|
64
|
+
if (typeof href === "string") {
|
|
65
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_router.Link, { to: href, replace, preload, children });
|
|
66
|
+
}
|
|
67
|
+
const { pathname, params } = href;
|
|
68
|
+
const to = expoPathToTanStack(pathname);
|
|
69
|
+
const { pathParams, searchParams } = splitParams(pathname, params);
|
|
70
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
71
|
+
import_react_router.Link,
|
|
72
|
+
{
|
|
73
|
+
to,
|
|
74
|
+
params: pathParams,
|
|
75
|
+
search: Object.keys(searchParams).length ? searchParams : void 0,
|
|
76
|
+
replace,
|
|
77
|
+
preload,
|
|
78
|
+
children
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/components/Redirect.tsx
|
|
84
|
+
var import_react_router2 = require("@tanstack/react-router");
|
|
85
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
86
|
+
function Redirect({ href, replace }) {
|
|
87
|
+
if (typeof href === "string") {
|
|
88
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_router2.Navigate, { to: href, replace });
|
|
89
|
+
}
|
|
90
|
+
const { pathname, params } = href;
|
|
91
|
+
const to = expoPathToTanStack(pathname);
|
|
92
|
+
const { pathParams, searchParams } = splitParams(pathname, params);
|
|
93
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
94
|
+
import_react_router2.Navigate,
|
|
95
|
+
{
|
|
96
|
+
to,
|
|
97
|
+
params: pathParams,
|
|
98
|
+
search: Object.keys(searchParams).length ? searchParams : void 0,
|
|
99
|
+
replace
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/hooks/useLocalSearchParams.ts
|
|
105
|
+
var import_react_router3 = require("@tanstack/react-router");
|
|
106
|
+
function useLocalSearchParams() {
|
|
107
|
+
const params = (0, import_react_router3.useParams)({ strict: false });
|
|
108
|
+
const search = (0, import_react_router3.useSearch)({ strict: false });
|
|
109
|
+
return {
|
|
110
|
+
...params,
|
|
111
|
+
...search
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/hooks/useRouter.ts
|
|
116
|
+
var import_react_router4 = require("@tanstack/react-router");
|
|
117
|
+
function useRouter() {
|
|
118
|
+
const router = (0, import_react_router4.useRouter)();
|
|
119
|
+
function navigate(href, replace = false) {
|
|
120
|
+
if (typeof href === "string") {
|
|
121
|
+
router.navigate({ to: href, replace });
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const { pathname, params } = href;
|
|
125
|
+
const to = expoPathToTanStack(pathname);
|
|
126
|
+
const { pathParams, searchParams } = splitParams(pathname, params);
|
|
127
|
+
router.navigate({
|
|
128
|
+
to,
|
|
129
|
+
params: pathParams,
|
|
130
|
+
search: Object.keys(searchParams).length ? searchParams : void 0,
|
|
131
|
+
replace
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
push: (href) => navigate(href, false),
|
|
136
|
+
replace: (href) => navigate(href, true),
|
|
137
|
+
navigate,
|
|
138
|
+
back: () => router.history.back(),
|
|
139
|
+
prefetch: router.preloadRoute
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
143
|
+
0 && (module.exports = {
|
|
144
|
+
Link,
|
|
145
|
+
Redirect,
|
|
146
|
+
useLocalSearchParams,
|
|
147
|
+
useRouter
|
|
148
|
+
});
|
|
149
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/components/Link.tsx","../src/utils/route-utils.ts","../src/components/Redirect.tsx","../src/hooks/useLocalSearchParams.ts","../src/hooks/useRouter.ts"],"sourcesContent":["export { Link } from \"./components/Link\";\nexport { Redirect } from \"./components/Redirect\";\nexport { useLocalSearchParams } from \"./hooks/useLocalSearchParams\";\n\nexport { useRouter } from \"./hooks/useRouter\";\nexport type * from \"./types\";\nexport type {\n Href,\n HrefObject,\n LinkProps,\n LocalSearchParams,\n Prefetch,\n} from \"./types\";\n","import { Link as TanStackLink } from \"@tanstack/react-router\";\nimport type { HrefObject, LinkProps, Prefetch } from \"../types\";\nimport { expoPathToTanStack, splitParams } from \"../utils/route-utils\";\n\nfunction mapPrefetchToPreload(prefetch: Prefetch | undefined) {\n if (prefetch === undefined || prefetch === false) {\n return false;\n }\n\n if (prefetch === true) {\n return \"intent\";\n }\n\n return prefetch;\n}\n\nexport function Link({ href, replace, prefetch, children }: LinkProps) {\n const preload = mapPrefetchToPreload(prefetch);\n\n // String href\n if (typeof href === \"string\") {\n return (\n <TanStackLink to={href} replace={replace} preload={preload}>\n {children}\n </TanStackLink>\n );\n }\n\n // Object-based Expo href\n const { pathname, params } = href as HrefObject;\n\n const to = expoPathToTanStack(pathname);\n const { pathParams, searchParams } = splitParams(pathname, params);\n\n return (\n <TanStackLink\n to={to}\n params={pathParams}\n search={Object.keys(searchParams).length ? searchParams : undefined}\n replace={replace}\n preload={preload}\n >\n {children}\n </TanStackLink>\n );\n}\n","import type { HrefObject } from \"../types\";\n\n/**\n * Converts:\n * /user/[id]/post/[slug] → /user/$id/post/$slug\n */\nexport function expoPathToTanStack(pathname: string) {\n return pathname.replace(/\\[([^\\]]+)\\]/g, (_, key) => `$${key}`);\n}\n\n/**\n * Splits params into:\n * - path params (used by dynamic segments)\n * - search params (query string)\n */\nexport function splitParams(pathname: string, params: HrefObject[\"params\"] = {}) {\n const dynamicKeys = Array.from(pathname.matchAll(/\\[([^\\]]+)\\]/g), (m) => m[1]);\n\n const pathParams: Record<string, unknown> = {};\n const searchParams: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(params)) {\n if (dynamicKeys.includes(key)) {\n pathParams[key] = value;\n } else {\n searchParams[key] = value;\n }\n }\n\n return { pathParams, searchParams };\n}\n","import { Navigate } from \"@tanstack/react-router\";\nimport type { Href } from \"../types\";\nimport { expoPathToTanStack, splitParams } from \"../utils/route-utils\";\n\ntype RedirectProps = {\n href: Href;\n replace?: boolean;\n};\n\n/**\n * Expo-compatible Redirect for web.\n *\n * Maps Expo Router <Redirect /> → TanStack Router <Navigate />\n */\nexport function Redirect({ href, replace }: RedirectProps) {\n // String path\n if (typeof href === \"string\") {\n return <Navigate to={href} replace={replace} />;\n }\n\n const { pathname, params } = href;\n\n const to = expoPathToTanStack(pathname);\n const { pathParams, searchParams } = splitParams(pathname, params);\n\n return (\n <Navigate\n to={to}\n params={pathParams}\n search={Object.keys(searchParams).length ? searchParams : undefined}\n replace={replace}\n />\n );\n}\n","import { useParams, useSearch } from \"@tanstack/react-router\";\nimport type { LocalSearchParams } from \"../types\";\n\n/**\n * Expo-compatible useLocalSearchParams for web.\n *\n * Combines:\n * - path params from useParams()\n * - query params from useSearch()\n */\nexport function useLocalSearchParams<T extends LocalSearchParams = LocalSearchParams>(): T {\n const params = useParams({ strict: false }) as Record<string, string | string[] | undefined>;\n\n const search = useSearch({ strict: false }) as Record<string, string | string[] | undefined>;\n\n return {\n ...params,\n ...search,\n } as T;\n}\n","import { useRouter as useTanStackRouter } from \"@tanstack/react-router\";\nimport type { Href } from \"../types\";\nimport { expoPathToTanStack, splitParams } from \"../utils/route-utils\";\n\nexport function useRouter() {\n const router = useTanStackRouter();\n\n function navigate(href: Href, replace = false) {\n if (typeof href === \"string\") {\n router.navigate({ to: href, replace });\n return;\n }\n\n const { pathname, params } = href;\n const to = expoPathToTanStack(pathname);\n const { pathParams, searchParams } = splitParams(pathname, params);\n\n router.navigate({\n to,\n params: pathParams,\n search: Object.keys(searchParams).length ? searchParams : undefined,\n replace,\n });\n }\n\n return {\n push: (href: Href) => navigate(href, false),\n replace: (href: Href) => navigate(href, true),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AC1D;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,MAAM,CAAC,SAAe,SAAS,MAAM,KAAK;AAAA,IAC1C,SAAS,CAAC,SAAe,SAAS,MAAM,IAAI;AAAA,IAC5C;AAAA,IACA,MAAM,MAAM,OAAO,QAAQ,KAAK;AAAA,IAChC,UAAU,OAAO;AAAA,EACnB;AACF;","names":["TanStackLink","import_react_router","import_jsx_runtime","import_react_router","import_react_router","useTanStackRouter"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// src/components/Link.tsx
|
|
2
|
+
import { Link as TanStackLink } from "@tanstack/react-router";
|
|
3
|
+
|
|
4
|
+
// src/utils/route-utils.ts
|
|
5
|
+
function expoPathToTanStack(pathname) {
|
|
6
|
+
return pathname.replace(/\[([^\]]+)\]/g, (_, key) => `$${key}`);
|
|
7
|
+
}
|
|
8
|
+
function splitParams(pathname, params = {}) {
|
|
9
|
+
const dynamicKeys = Array.from(pathname.matchAll(/\[([^\]]+)\]/g), (m) => m[1]);
|
|
10
|
+
const pathParams = {};
|
|
11
|
+
const searchParams = {};
|
|
12
|
+
for (const [key, value] of Object.entries(params)) {
|
|
13
|
+
if (dynamicKeys.includes(key)) {
|
|
14
|
+
pathParams[key] = value;
|
|
15
|
+
} else {
|
|
16
|
+
searchParams[key] = value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return { pathParams, searchParams };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/components/Link.tsx
|
|
23
|
+
import { jsx } from "react/jsx-runtime";
|
|
24
|
+
function mapPrefetchToPreload(prefetch) {
|
|
25
|
+
if (prefetch === void 0 || prefetch === false) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
if (prefetch === true) {
|
|
29
|
+
return "intent";
|
|
30
|
+
}
|
|
31
|
+
return prefetch;
|
|
32
|
+
}
|
|
33
|
+
function Link({ href, replace, prefetch, children }) {
|
|
34
|
+
const preload = mapPrefetchToPreload(prefetch);
|
|
35
|
+
if (typeof href === "string") {
|
|
36
|
+
return /* @__PURE__ */ jsx(TanStackLink, { to: href, replace, preload, children });
|
|
37
|
+
}
|
|
38
|
+
const { pathname, params } = href;
|
|
39
|
+
const to = expoPathToTanStack(pathname);
|
|
40
|
+
const { pathParams, searchParams } = splitParams(pathname, params);
|
|
41
|
+
return /* @__PURE__ */ jsx(
|
|
42
|
+
TanStackLink,
|
|
43
|
+
{
|
|
44
|
+
to,
|
|
45
|
+
params: pathParams,
|
|
46
|
+
search: Object.keys(searchParams).length ? searchParams : void 0,
|
|
47
|
+
replace,
|
|
48
|
+
preload,
|
|
49
|
+
children
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/components/Redirect.tsx
|
|
55
|
+
import { Navigate } from "@tanstack/react-router";
|
|
56
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
57
|
+
function Redirect({ href, replace }) {
|
|
58
|
+
if (typeof href === "string") {
|
|
59
|
+
return /* @__PURE__ */ jsx2(Navigate, { to: href, replace });
|
|
60
|
+
}
|
|
61
|
+
const { pathname, params } = href;
|
|
62
|
+
const to = expoPathToTanStack(pathname);
|
|
63
|
+
const { pathParams, searchParams } = splitParams(pathname, params);
|
|
64
|
+
return /* @__PURE__ */ jsx2(
|
|
65
|
+
Navigate,
|
|
66
|
+
{
|
|
67
|
+
to,
|
|
68
|
+
params: pathParams,
|
|
69
|
+
search: Object.keys(searchParams).length ? searchParams : void 0,
|
|
70
|
+
replace
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/hooks/useLocalSearchParams.ts
|
|
76
|
+
import { useParams, useSearch } from "@tanstack/react-router";
|
|
77
|
+
function useLocalSearchParams() {
|
|
78
|
+
const params = useParams({ strict: false });
|
|
79
|
+
const search = useSearch({ strict: false });
|
|
80
|
+
return {
|
|
81
|
+
...params,
|
|
82
|
+
...search
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/hooks/useRouter.ts
|
|
87
|
+
import { useRouter as useTanStackRouter } from "@tanstack/react-router";
|
|
88
|
+
function useRouter() {
|
|
89
|
+
const router = useTanStackRouter();
|
|
90
|
+
function navigate(href, replace = false) {
|
|
91
|
+
if (typeof href === "string") {
|
|
92
|
+
router.navigate({ to: href, replace });
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const { pathname, params } = href;
|
|
96
|
+
const to = expoPathToTanStack(pathname);
|
|
97
|
+
const { pathParams, searchParams } = splitParams(pathname, params);
|
|
98
|
+
router.navigate({
|
|
99
|
+
to,
|
|
100
|
+
params: pathParams,
|
|
101
|
+
search: Object.keys(searchParams).length ? searchParams : void 0,
|
|
102
|
+
replace
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
push: (href) => navigate(href, false),
|
|
107
|
+
replace: (href) => navigate(href, true),
|
|
108
|
+
navigate,
|
|
109
|
+
back: () => router.history.back(),
|
|
110
|
+
prefetch: router.preloadRoute
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export {
|
|
114
|
+
Link,
|
|
115
|
+
Redirect,
|
|
116
|
+
useLocalSearchParams,
|
|
117
|
+
useRouter
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Link.tsx","../src/utils/route-utils.ts","../src/components/Redirect.tsx","../src/hooks/useLocalSearchParams.ts","../src/hooks/useRouter.ts"],"sourcesContent":["import { Link as TanStackLink } from \"@tanstack/react-router\";\nimport type { HrefObject, LinkProps, Prefetch } from \"../types\";\nimport { expoPathToTanStack, splitParams } from \"../utils/route-utils\";\n\nfunction mapPrefetchToPreload(prefetch: Prefetch | undefined) {\n if (prefetch === undefined || prefetch === false) {\n return false;\n }\n\n if (prefetch === true) {\n return \"intent\";\n }\n\n return prefetch;\n}\n\nexport function Link({ href, replace, prefetch, children }: LinkProps) {\n const preload = mapPrefetchToPreload(prefetch);\n\n // String href\n if (typeof href === \"string\") {\n return (\n <TanStackLink to={href} replace={replace} preload={preload}>\n {children}\n </TanStackLink>\n );\n }\n\n // Object-based Expo href\n const { pathname, params } = href as HrefObject;\n\n const to = expoPathToTanStack(pathname);\n const { pathParams, searchParams } = splitParams(pathname, params);\n\n return (\n <TanStackLink\n to={to}\n params={pathParams}\n search={Object.keys(searchParams).length ? searchParams : undefined}\n replace={replace}\n preload={preload}\n >\n {children}\n </TanStackLink>\n );\n}\n","import type { HrefObject } from \"../types\";\n\n/**\n * Converts:\n * /user/[id]/post/[slug] → /user/$id/post/$slug\n */\nexport function expoPathToTanStack(pathname: string) {\n return pathname.replace(/\\[([^\\]]+)\\]/g, (_, key) => `$${key}`);\n}\n\n/**\n * Splits params into:\n * - path params (used by dynamic segments)\n * - search params (query string)\n */\nexport function splitParams(pathname: string, params: HrefObject[\"params\"] = {}) {\n const dynamicKeys = Array.from(pathname.matchAll(/\\[([^\\]]+)\\]/g), (m) => m[1]);\n\n const pathParams: Record<string, unknown> = {};\n const searchParams: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(params)) {\n if (dynamicKeys.includes(key)) {\n pathParams[key] = value;\n } else {\n searchParams[key] = value;\n }\n }\n\n return { pathParams, searchParams };\n}\n","import { Navigate } from \"@tanstack/react-router\";\nimport type { Href } from \"../types\";\nimport { expoPathToTanStack, splitParams } from \"../utils/route-utils\";\n\ntype RedirectProps = {\n href: Href;\n replace?: boolean;\n};\n\n/**\n * Expo-compatible Redirect for web.\n *\n * Maps Expo Router <Redirect /> → TanStack Router <Navigate />\n */\nexport function Redirect({ href, replace }: RedirectProps) {\n // String path\n if (typeof href === \"string\") {\n return <Navigate to={href} replace={replace} />;\n }\n\n const { pathname, params } = href;\n\n const to = expoPathToTanStack(pathname);\n const { pathParams, searchParams } = splitParams(pathname, params);\n\n return (\n <Navigate\n to={to}\n params={pathParams}\n search={Object.keys(searchParams).length ? searchParams : undefined}\n replace={replace}\n />\n );\n}\n","import { useParams, useSearch } from \"@tanstack/react-router\";\nimport type { LocalSearchParams } from \"../types\";\n\n/**\n * Expo-compatible useLocalSearchParams for web.\n *\n * Combines:\n * - path params from useParams()\n * - query params from useSearch()\n */\nexport function useLocalSearchParams<T extends LocalSearchParams = LocalSearchParams>(): T {\n const params = useParams({ strict: false }) as Record<string, string | string[] | undefined>;\n\n const search = useSearch({ strict: false }) as Record<string, string | string[] | undefined>;\n\n return {\n ...params,\n ...search,\n } as T;\n}\n","import { useRouter as useTanStackRouter } from \"@tanstack/react-router\";\nimport type { Href } from \"../types\";\nimport { expoPathToTanStack, splitParams } from \"../utils/route-utils\";\n\nexport function useRouter() {\n const router = useTanStackRouter();\n\n function navigate(href: Href, replace = false) {\n if (typeof href === \"string\") {\n router.navigate({ to: href, replace });\n return;\n }\n\n const { pathname, params } = href;\n const to = expoPathToTanStack(pathname);\n const { pathParams, searchParams } = splitParams(pathname, params);\n\n router.navigate({\n to,\n params: pathParams,\n search: Object.keys(searchParams).length ? searchParams : undefined,\n replace,\n });\n }\n\n return {\n push: (href: Href) => navigate(href, false),\n replace: (href: Href) => navigate(href, true),\n navigate,\n back: () => router.history.back(),\n prefetch: router.preloadRoute,\n };\n}\n"],"mappings":";AAAA,SAAS,QAAQ,oBAAoB;;;ACM9B,SAAS,mBAAmB,UAAkB;AACnD,SAAO,SAAS,QAAQ,iBAAiB,CAAC,GAAG,QAAQ,IAAI,GAAG,EAAE;AAChE;AAOO,SAAS,YAAY,UAAkB,SAA+B,CAAC,GAAG;AAC/E,QAAM,cAAc,MAAM,KAAK,SAAS,SAAS,eAAe,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;AAE9E,QAAM,aAAsC,CAAC;AAC7C,QAAM,eAAwC,CAAC;AAE/C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACjD,QAAI,YAAY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AAA,MAC1D;AAAA;AAAA,EACF;AAEJ;;;ACjCA,SAAS,WAAW,iBAAiB;AAU9B,SAAS,uBAA2E;AACzF,QAAM,SAAS,UAAU,EAAE,QAAQ,MAAM,CAAC;AAE1C,QAAM,SAAS,UAAU,EAAE,QAAQ,MAAM,CAAC;AAE1C,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;;;ACnBA,SAAS,aAAa,yBAAyB;AAIxC,SAAS,YAAY;AAC1B,QAAM,SAAS,kBAAkB;AAEjC,WAAS,SAAS,MAAY,UAAU,OAAO;AAC7C,QAAI,OAAO,SAAS,UAAU;AAC5B,aAAO,SAAS,EAAE,IAAI,MAAM,QAAQ,CAAC;AACrC;AAAA,IACF;AAEA,UAAM,EAAE,UAAU,OAAO,IAAI;AAC7B,UAAM,KAAK,mBAAmB,QAAQ;AACtC,UAAM,EAAE,YAAY,aAAa,IAAI,YAAY,UAAU,MAAM;AAEjE,WAAO,SAAS;AAAA,MACd;AAAA,MACA,QAAQ;AAAA,MACR,QAAQ,OAAO,KAAK,YAAY,EAAE,SAAS,eAAe;AAAA,MAC1D;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,MAAM,CAAC,SAAe,SAAS,MAAM,KAAK;AAAA,IAC1C,SAAS,CAAC,SAAe,SAAS,MAAM,IAAI;AAAA,IAC5C;AAAA,IACA,MAAM,MAAM,OAAO,QAAQ,KAAK;AAAA,IAChC,UAAU,OAAO;AAAA,EACnB;AACF;","names":["jsx"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Link } from './components/Link.native.mjs';
|
|
2
|
+
export { Redirect, useLocalSearchParams } from 'expo-router';
|
|
3
|
+
export { useRouter } from './hooks/useRouter.native.mjs';
|
|
4
|
+
export { H as Href, a as HrefObject, L as LinkProps, b as LocalSearchParams, P as Prefetch } from './types-BrqVaE2O.mjs';
|
|
5
|
+
import 'react/jsx-runtime';
|
|
6
|
+
import 'expo-router/build/global-state/routing';
|
|
7
|
+
import 'react';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Link } from './components/Link.native.js';
|
|
2
|
+
export { Redirect, useLocalSearchParams } from 'expo-router';
|
|
3
|
+
export { useRouter } from './hooks/useRouter.native.js';
|
|
4
|
+
export { H as Href, a as HrefObject, L as LinkProps, b as LocalSearchParams, P as Prefetch } from './types-BrqVaE2O.js';
|
|
5
|
+
import 'react/jsx-runtime';
|
|
6
|
+
import 'expo-router/build/global-state/routing';
|
|
7
|
+
import 'react';
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
|
|
20
|
+
// src/index.native.ts
|
|
21
|
+
var index_native_exports = {};
|
|
22
|
+
__export(index_native_exports, {
|
|
23
|
+
Link: () => Link,
|
|
24
|
+
Redirect: () => import_expo_router2.Redirect,
|
|
25
|
+
useLocalSearchParams: () => import_expo_router3.useLocalSearchParams,
|
|
26
|
+
useRouter: () => useRouter
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_native_exports);
|
|
29
|
+
|
|
30
|
+
// src/components/Link.native.tsx
|
|
31
|
+
var import_expo_router = require("expo-router");
|
|
32
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
+
function Link({ href, replace, prefetch, push, children }) {
|
|
34
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_expo_router.Link, { href, replace, prefetch: Boolean(prefetch), push, children });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/components/Redirect.native.tsx
|
|
38
|
+
var import_expo_router2 = require("expo-router");
|
|
39
|
+
|
|
40
|
+
// src/hooks/useLocalSearchParams.native.ts
|
|
41
|
+
var import_expo_router3 = require("expo-router");
|
|
42
|
+
|
|
43
|
+
// src/hooks/useRouter.native.ts
|
|
44
|
+
var import_expo_router4 = require("expo-router");
|
|
45
|
+
function useRouter() {
|
|
46
|
+
const router = (0, import_expo_router4.useRouter)();
|
|
47
|
+
return {
|
|
48
|
+
push: router.push,
|
|
49
|
+
replace: router.replace,
|
|
50
|
+
back: router.back,
|
|
51
|
+
prefetch: router.prefetch,
|
|
52
|
+
navigate: router.push
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
Link,
|
|
58
|
+
Redirect,
|
|
59
|
+
useLocalSearchParams,
|
|
60
|
+
useRouter
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.native.ts","../src/components/Link.native.tsx","../src/components/Redirect.native.tsx","../src/hooks/useLocalSearchParams.native.ts","../src/hooks/useRouter.native.ts"],"sourcesContent":["export { Link } from \"./components/Link.native\";\nexport { Redirect } from \"./components/Redirect.native\";\nexport { useLocalSearchParams } from \"./hooks/useLocalSearchParams.native\";\n\nexport { useRouter } from \"./hooks/useRouter.native\";\nexport type * from \"./types\";\nexport type {\n Href,\n HrefObject,\n LinkProps,\n LocalSearchParams,\n Prefetch,\n} from \"./types\";\n","import { Link as ExpoLink } from \"expo-router\";\nimport type { LinkProps } from \"../types\";\nimport type { Href } from \"../types.native\";\n\nexport function Link({ href, replace, prefetch, push, children }: LinkProps) {\n return (\n <ExpoLink href={href as Href} replace={replace} prefetch={Boolean(prefetch)} push={push}>\n {children}\n </ExpoLink>\n );\n}\n","export { Redirect } from \"expo-router\";\n","export { useLocalSearchParams } from \"expo-router\";\n","import { useRouter as useExpoRouter } from \"expo-router\";\n\nexport function useRouter() {\n const router = useExpoRouter();\n\n return {\n push: router.push,\n replace: router.replace,\n back: router.back,\n prefetch: router.prefetch,\n navigate: router.push,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,yBAAiC;AAM7B;AAFG,SAAS,KAAK,EAAE,MAAM,SAAS,UAAU,MAAM,SAAS,GAAc;AAC3E,SACE,4CAAC,mBAAAA,MAAA,EAAS,MAAoB,SAAkB,UAAU,QAAQ,QAAQ,GAAG,MAC1E,UACH;AAEJ;;;ACVA,IAAAC,sBAAyB;;;ACAzB,IAAAC,sBAAqC;;;ACArC,IAAAC,sBAA2C;AAEpC,SAAS,YAAY;AAC1B,QAAM,aAAS,oBAAAC,WAAc;AAE7B,SAAO;AAAA,IACL,MAAM,OAAO;AAAA,IACb,SAAS,OAAO;AAAA,IAChB,MAAM,OAAO;AAAA,IACb,UAAU,OAAO;AAAA,IACjB,UAAU,OAAO;AAAA,EACnB;AACF;","names":["ExpoLink","import_expo_router","import_expo_router","import_expo_router","useExpoRouter"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/components/Link.native.tsx
|
|
2
|
+
import { Link as ExpoLink } from "expo-router";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
function Link({ href, replace, prefetch, push, children }) {
|
|
5
|
+
return /* @__PURE__ */ jsx(ExpoLink, { href, replace, prefetch: Boolean(prefetch), push, children });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// src/components/Redirect.native.tsx
|
|
9
|
+
import { Redirect } from "expo-router";
|
|
10
|
+
|
|
11
|
+
// src/hooks/useLocalSearchParams.native.ts
|
|
12
|
+
import { useLocalSearchParams } from "expo-router";
|
|
13
|
+
|
|
14
|
+
// src/hooks/useRouter.native.ts
|
|
15
|
+
import { useRouter as useExpoRouter } from "expo-router";
|
|
16
|
+
function useRouter() {
|
|
17
|
+
const router = useExpoRouter();
|
|
18
|
+
return {
|
|
19
|
+
push: router.push,
|
|
20
|
+
replace: router.replace,
|
|
21
|
+
back: router.back,
|
|
22
|
+
prefetch: router.prefetch,
|
|
23
|
+
navigate: router.push
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
Link,
|
|
28
|
+
Redirect,
|
|
29
|
+
useLocalSearchParams,
|
|
30
|
+
useRouter
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=index.native.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Link.native.tsx","../src/components/Redirect.native.tsx","../src/hooks/useLocalSearchParams.native.ts","../src/hooks/useRouter.native.ts"],"sourcesContent":["import { Link as ExpoLink } from \"expo-router\";\nimport type { LinkProps } from \"../types\";\nimport type { Href } from \"../types.native\";\n\nexport function Link({ href, replace, prefetch, push, children }: LinkProps) {\n return (\n <ExpoLink href={href as Href} replace={replace} prefetch={Boolean(prefetch)} push={push}>\n {children}\n </ExpoLink>\n );\n}\n","export { Redirect } from \"expo-router\";\n","export { useLocalSearchParams } from \"expo-router\";\n","import { useRouter as useExpoRouter } from \"expo-router\";\n\nexport function useRouter() {\n const router = useExpoRouter();\n\n return {\n push: router.push,\n replace: router.replace,\n back: router.back,\n prefetch: router.prefetch,\n navigate: router.push,\n };\n}\n"],"mappings":";AAAA,SAAS,QAAQ,gBAAgB;AAM7B;AAFG,SAAS,KAAK,EAAE,MAAM,SAAS,UAAU,MAAM,SAAS,GAAc;AAC3E,SACE,oBAAC,YAAS,MAAoB,SAAkB,UAAU,QAAQ,QAAQ,GAAG,MAC1E,UACH;AAEJ;;;ACVA,SAAS,gBAAgB;;;ACAzB,SAAS,4BAA4B;;;ACArC,SAAS,aAAa,qBAAqB;AAEpC,SAAS,YAAY;AAC1B,QAAM,SAAS,cAAc;AAE7B,SAAO;AAAA,IACL,MAAM,OAAO;AAAA,IACb,SAAS,OAAO;AAAA,IAChB,MAAM,OAAO;AAAA,IACb,UAAU,OAAO;AAAA,IACjB,UAAU,OAAO;AAAA,EACnB;AACF;","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type HrefObject = {
|
|
4
|
+
pathname: string;
|
|
5
|
+
params?: Record<string, string | number | boolean | undefined>;
|
|
6
|
+
};
|
|
7
|
+
type Href = string | HrefObject;
|
|
8
|
+
/**
|
|
9
|
+
* Web supports prefetch hints, native treats them as `true`
|
|
10
|
+
*/
|
|
11
|
+
type Prefetch = boolean | "intent" | "viewport" | "render";
|
|
12
|
+
type LinkProps = {
|
|
13
|
+
href: Href;
|
|
14
|
+
replace?: boolean;
|
|
15
|
+
prefetch?: Prefetch;
|
|
16
|
+
push?: boolean;
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
};
|
|
19
|
+
type LocalSearchParams = Record<string, string | string[] | undefined>;
|
|
20
|
+
|
|
21
|
+
export type { Href as H, LinkProps as L, Prefetch as P, HrefObject as a, LocalSearchParams as b };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type HrefObject = {
|
|
4
|
+
pathname: string;
|
|
5
|
+
params?: Record<string, string | number | boolean | undefined>;
|
|
6
|
+
};
|
|
7
|
+
type Href = string | HrefObject;
|
|
8
|
+
/**
|
|
9
|
+
* Web supports prefetch hints, native treats them as `true`
|
|
10
|
+
*/
|
|
11
|
+
type Prefetch = boolean | "intent" | "viewport" | "render";
|
|
12
|
+
type LinkProps = {
|
|
13
|
+
href: Href;
|
|
14
|
+
replace?: boolean;
|
|
15
|
+
prefetch?: Prefetch;
|
|
16
|
+
push?: boolean;
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
};
|
|
19
|
+
type LocalSearchParams = Record<string, string | string[] | undefined>;
|
|
20
|
+
|
|
21
|
+
export type { Href as H, LinkProps as L, Prefetch as P, HrefObject as a, LocalSearchParams as b };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { a as HrefObject } from '../types-BrqVaE2O.mjs';
|
|
2
|
+
import 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts:
|
|
6
|
+
* /user/[id]/post/[slug] → /user/$id/post/$slug
|
|
7
|
+
*/
|
|
8
|
+
declare function expoPathToTanStack(pathname: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Splits params into:
|
|
11
|
+
* - path params (used by dynamic segments)
|
|
12
|
+
* - search params (query string)
|
|
13
|
+
*/
|
|
14
|
+
declare function splitParams(pathname: string, params?: HrefObject["params"]): {
|
|
15
|
+
pathParams: Record<string, unknown>;
|
|
16
|
+
searchParams: Record<string, unknown>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { expoPathToTanStack, splitParams };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { a as HrefObject } from '../types-BrqVaE2O.js';
|
|
2
|
+
import 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts:
|
|
6
|
+
* /user/[id]/post/[slug] → /user/$id/post/$slug
|
|
7
|
+
*/
|
|
8
|
+
declare function expoPathToTanStack(pathname: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Splits params into:
|
|
11
|
+
* - path params (used by dynamic segments)
|
|
12
|
+
* - search params (query string)
|
|
13
|
+
*/
|
|
14
|
+
declare function splitParams(pathname: string, params?: HrefObject["params"]): {
|
|
15
|
+
pathParams: Record<string, unknown>;
|
|
16
|
+
searchParams: Record<string, unknown>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { expoPathToTanStack, splitParams };
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
|
|
20
|
+
// src/utils/route-utils.ts
|
|
21
|
+
var route_utils_exports = {};
|
|
22
|
+
__export(route_utils_exports, {
|
|
23
|
+
expoPathToTanStack: () => expoPathToTanStack,
|
|
24
|
+
splitParams: () => splitParams
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(route_utils_exports);
|
|
27
|
+
function expoPathToTanStack(pathname) {
|
|
28
|
+
return pathname.replace(/\[([^\]]+)\]/g, (_, key) => `$${key}`);
|
|
29
|
+
}
|
|
30
|
+
function splitParams(pathname, params = {}) {
|
|
31
|
+
const dynamicKeys = Array.from(pathname.matchAll(/\[([^\]]+)\]/g), (m) => m[1]);
|
|
32
|
+
const pathParams = {};
|
|
33
|
+
const searchParams = {};
|
|
34
|
+
for (const [key, value] of Object.entries(params)) {
|
|
35
|
+
if (dynamicKeys.includes(key)) {
|
|
36
|
+
pathParams[key] = value;
|
|
37
|
+
} else {
|
|
38
|
+
searchParams[key] = value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { pathParams, searchParams };
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
expoPathToTanStack,
|
|
46
|
+
splitParams
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=route-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/route-utils.ts"],"sourcesContent":["import type { HrefObject } from \"../types\";\n\n/**\n * Converts:\n * /user/[id]/post/[slug] → /user/$id/post/$slug\n */\nexport function expoPathToTanStack(pathname: string) {\n return pathname.replace(/\\[([^\\]]+)\\]/g, (_, key) => `$${key}`);\n}\n\n/**\n * Splits params into:\n * - path params (used by dynamic segments)\n * - search params (query string)\n */\nexport function splitParams(pathname: string, params: HrefObject[\"params\"] = {}) {\n const dynamicKeys = Array.from(pathname.matchAll(/\\[([^\\]]+)\\]/g), (m) => m[1]);\n\n const pathParams: Record<string, unknown> = {};\n const searchParams: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(params)) {\n if (dynamicKeys.includes(key)) {\n pathParams[key] = value;\n } else {\n searchParams[key] = value;\n }\n }\n\n return { pathParams, searchParams };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,SAAS,mBAAmB,UAAkB;AACnD,SAAO,SAAS,QAAQ,iBAAiB,CAAC,GAAG,QAAQ,IAAI,GAAG,EAAE;AAChE;AAOO,SAAS,YAAY,UAAkB,SAA+B,CAAC,GAAG;AAC/E,QAAM,cAAc,MAAM,KAAK,SAAS,SAAS,eAAe,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;AAE9E,QAAM,aAAsC,CAAC;AAC7C,QAAM,eAAwC,CAAC;AAE/C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AACjD,QAAI,YAAY,SAAS,GAAG,GAAG;AAC7B,iBAAW,GAAG,IAAI;AAAA,IACpB,OAAO;AACL,mBAAa,GAAG,IAAI;AAAA,IACtB;AAAA,EACF;AAEA,SAAO,EAAE,YAAY,aAAa;AACpC;","names":[]}
|