@tanstack/react-router 0.0.1-beta.261 → 0.0.1-beta.262
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/build/cjs/link.js +96 -22
- package/build/cjs/link.js.map +1 -1
- package/build/cjs/router.js +0 -112
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +96 -134
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +355 -355
- package/build/types/router.d.ts +1 -2
- package/build/umd/index.development.js +96 -134
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/link.tsx +126 -19
- package/src/router.ts +0 -139
package/build/esm/index.js
CHANGED
|
@@ -1032,17 +1032,15 @@ function _extends() {
|
|
|
1032
1032
|
return _extends.apply(this, arguments);
|
|
1033
1033
|
}
|
|
1034
1034
|
|
|
1035
|
+
const preloadWarning = 'Error preloading route! ☝️';
|
|
1035
1036
|
function useLinkProps(options) {
|
|
1036
|
-
const
|
|
1037
|
-
buildLink
|
|
1038
|
-
} = useRouter();
|
|
1037
|
+
const router = useRouter();
|
|
1039
1038
|
const matchPathname = useMatch({
|
|
1040
1039
|
strict: false,
|
|
1041
1040
|
select: s => s.pathname
|
|
1042
1041
|
});
|
|
1043
1042
|
const {
|
|
1044
1043
|
// custom props
|
|
1045
|
-
type,
|
|
1046
1044
|
children,
|
|
1047
1045
|
target,
|
|
1048
1046
|
activeProps = () => ({
|
|
@@ -1057,8 +1055,8 @@ function useLinkProps(options) {
|
|
|
1057
1055
|
to,
|
|
1058
1056
|
state,
|
|
1059
1057
|
mask,
|
|
1060
|
-
preload,
|
|
1061
|
-
preloadDelay,
|
|
1058
|
+
preload: userPreload,
|
|
1059
|
+
preloadDelay: userPreloadDelay,
|
|
1062
1060
|
replace,
|
|
1063
1061
|
startTransition,
|
|
1064
1062
|
resetScroll,
|
|
@@ -1072,27 +1070,100 @@ function useLinkProps(options) {
|
|
|
1072
1070
|
onTouchStart,
|
|
1073
1071
|
...rest
|
|
1074
1072
|
} = options;
|
|
1075
|
-
|
|
1073
|
+
|
|
1074
|
+
// If this link simply reloads the current route,
|
|
1075
|
+
// make sure it has a new key so it will trigger a data refresh
|
|
1076
|
+
|
|
1077
|
+
// If this `to` is a valid external URL, return
|
|
1078
|
+
// null for LinkUtils
|
|
1079
|
+
|
|
1080
|
+
const dest = {
|
|
1076
1081
|
from: options.to ? matchPathname : undefined,
|
|
1077
1082
|
...options
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
+
};
|
|
1084
|
+
let type = 'internal';
|
|
1085
|
+
try {
|
|
1086
|
+
new URL(`${to}`);
|
|
1087
|
+
type = 'external';
|
|
1088
|
+
} catch {}
|
|
1089
|
+
if (type === 'external') {
|
|
1083
1090
|
return {
|
|
1084
|
-
href
|
|
1091
|
+
href: to
|
|
1085
1092
|
};
|
|
1086
1093
|
}
|
|
1087
|
-
const
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1094
|
+
const next = router.buildLocation(dest);
|
|
1095
|
+
const preload = userPreload ?? router.options.defaultPreload;
|
|
1096
|
+
const preloadDelay = userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0;
|
|
1097
|
+
const isActive = useRouterState({
|
|
1098
|
+
select: s => {
|
|
1099
|
+
// Compare path/hash for matches
|
|
1100
|
+
const currentPathSplit = s.location.pathname.split('/');
|
|
1101
|
+
const nextPathSplit = next.pathname.split('/');
|
|
1102
|
+
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
1103
|
+
// Combine the matches based on user router.options
|
|
1104
|
+
const pathTest = activeOptions?.exact ? s.location.pathname === next.pathname : pathIsFuzzyEqual;
|
|
1105
|
+
const hashTest = activeOptions?.includeHash ? s.location.hash === next.hash : true;
|
|
1106
|
+
const searchTest = activeOptions?.includeSearch ?? true ? deepEqual(s.location.search, next.search, true) : true;
|
|
1107
|
+
|
|
1108
|
+
// The final "active" test
|
|
1109
|
+
return pathTest && hashTest && searchTest;
|
|
1110
|
+
}
|
|
1111
|
+
});
|
|
1112
|
+
|
|
1113
|
+
// The click handler
|
|
1114
|
+
const handleClick = e => {
|
|
1115
|
+
if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
|
|
1116
|
+
e.preventDefault();
|
|
1117
|
+
|
|
1118
|
+
// All is well? Navigate!
|
|
1119
|
+
router.commitLocation({
|
|
1120
|
+
...next,
|
|
1121
|
+
replace,
|
|
1122
|
+
resetScroll,
|
|
1123
|
+
startTransition
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
// The click handler
|
|
1129
|
+
const handleFocus = e => {
|
|
1130
|
+
if (preload) {
|
|
1131
|
+
router.preloadRoute(dest).catch(err => {
|
|
1132
|
+
console.warn(err);
|
|
1133
|
+
console.warn(preloadWarning);
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
const handleTouchStart = e => {
|
|
1138
|
+
if (preload) {
|
|
1139
|
+
router.preloadRoute(dest).catch(err => {
|
|
1140
|
+
console.warn(err);
|
|
1141
|
+
console.warn(preloadWarning);
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
const handleEnter = e => {
|
|
1146
|
+
const target = e.target || {};
|
|
1147
|
+
if (preload) {
|
|
1148
|
+
if (target.preloadTimeout) {
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
target.preloadTimeout = setTimeout(() => {
|
|
1152
|
+
target.preloadTimeout = null;
|
|
1153
|
+
router.preloadRoute(dest).catch(err => {
|
|
1154
|
+
console.warn(err);
|
|
1155
|
+
console.warn(preloadWarning);
|
|
1156
|
+
});
|
|
1157
|
+
}, preloadDelay);
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
const handleLeave = e => {
|
|
1161
|
+
const target = e.target || {};
|
|
1162
|
+
if (target.preloadTimeout) {
|
|
1163
|
+
clearTimeout(target.preloadTimeout);
|
|
1164
|
+
target.preloadTimeout = null;
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1096
1167
|
const composeHandlers = handlers => e => {
|
|
1097
1168
|
if (e.persist) e.persist();
|
|
1098
1169
|
handlers.filter(Boolean).forEach(handler => {
|
|
@@ -1140,6 +1211,9 @@ const Link = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
1140
1211
|
}) : props.children
|
|
1141
1212
|
}));
|
|
1142
1213
|
});
|
|
1214
|
+
function isCtrlEvent(e) {
|
|
1215
|
+
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
1216
|
+
}
|
|
1143
1217
|
|
|
1144
1218
|
// @ts-nocheck
|
|
1145
1219
|
|
|
@@ -1269,7 +1343,6 @@ function stringifySearchWith(stringify, parser) {
|
|
|
1269
1343
|
//
|
|
1270
1344
|
|
|
1271
1345
|
const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
|
|
1272
|
-
const preloadWarning = 'Error preloading route! ☝️';
|
|
1273
1346
|
class Router {
|
|
1274
1347
|
// Option-independent properties
|
|
1275
1348
|
tempLocationKey = `${Math.round(Math.random() * 10000000)}`;
|
|
@@ -2147,114 +2220,6 @@ class Router {
|
|
|
2147
2220
|
});
|
|
2148
2221
|
return matches;
|
|
2149
2222
|
};
|
|
2150
|
-
buildLink = dest => {
|
|
2151
|
-
// If this link simply reloads the current route,
|
|
2152
|
-
// make sure it has a new key so it will trigger a data refresh
|
|
2153
|
-
|
|
2154
|
-
// If this `to` is a valid external URL, return
|
|
2155
|
-
// null for LinkUtils
|
|
2156
|
-
|
|
2157
|
-
const {
|
|
2158
|
-
to,
|
|
2159
|
-
preload: userPreload,
|
|
2160
|
-
preloadDelay: userPreloadDelay,
|
|
2161
|
-
activeOptions,
|
|
2162
|
-
disabled,
|
|
2163
|
-
target,
|
|
2164
|
-
replace,
|
|
2165
|
-
resetScroll,
|
|
2166
|
-
startTransition
|
|
2167
|
-
} = dest;
|
|
2168
|
-
try {
|
|
2169
|
-
new URL(`${to}`);
|
|
2170
|
-
return {
|
|
2171
|
-
type: 'external',
|
|
2172
|
-
href: to
|
|
2173
|
-
};
|
|
2174
|
-
} catch (e) {}
|
|
2175
|
-
const nextOpts = dest;
|
|
2176
|
-
const next = this.buildLocation(nextOpts);
|
|
2177
|
-
const preload = userPreload ?? this.options.defaultPreload;
|
|
2178
|
-
const preloadDelay = userPreloadDelay ?? this.options.defaultPreloadDelay ?? 0;
|
|
2179
|
-
|
|
2180
|
-
// Compare path/hash for matches
|
|
2181
|
-
const currentPathSplit = this.latestLocation.pathname.split('/');
|
|
2182
|
-
const nextPathSplit = next.pathname.split('/');
|
|
2183
|
-
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
2184
|
-
// Combine the matches based on user this.options
|
|
2185
|
-
const pathTest = activeOptions?.exact ? this.latestLocation.pathname === next.pathname : pathIsFuzzyEqual;
|
|
2186
|
-
const hashTest = activeOptions?.includeHash ? this.latestLocation.hash === next.hash : true;
|
|
2187
|
-
const searchTest = activeOptions?.includeSearch ?? true ? deepEqual(this.latestLocation.search, next.search, true) : true;
|
|
2188
|
-
|
|
2189
|
-
// The final "active" test
|
|
2190
|
-
const isActive = pathTest && hashTest && searchTest;
|
|
2191
|
-
|
|
2192
|
-
// The click handler
|
|
2193
|
-
const handleClick = e => {
|
|
2194
|
-
if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
|
|
2195
|
-
e.preventDefault();
|
|
2196
|
-
|
|
2197
|
-
// All is well? Navigate!
|
|
2198
|
-
this.commitLocation({
|
|
2199
|
-
...next,
|
|
2200
|
-
replace,
|
|
2201
|
-
resetScroll,
|
|
2202
|
-
startTransition
|
|
2203
|
-
});
|
|
2204
|
-
}
|
|
2205
|
-
};
|
|
2206
|
-
|
|
2207
|
-
// The click handler
|
|
2208
|
-
const handleFocus = e => {
|
|
2209
|
-
if (preload) {
|
|
2210
|
-
this.preloadRoute(nextOpts).catch(err => {
|
|
2211
|
-
console.warn(err);
|
|
2212
|
-
console.warn(preloadWarning);
|
|
2213
|
-
});
|
|
2214
|
-
}
|
|
2215
|
-
};
|
|
2216
|
-
const handleTouchStart = e => {
|
|
2217
|
-
if (preload) {
|
|
2218
|
-
this.preloadRoute(nextOpts).catch(err => {
|
|
2219
|
-
console.warn(err);
|
|
2220
|
-
console.warn(preloadWarning);
|
|
2221
|
-
});
|
|
2222
|
-
}
|
|
2223
|
-
};
|
|
2224
|
-
const handleEnter = e => {
|
|
2225
|
-
const target = e.target || {};
|
|
2226
|
-
if (preload) {
|
|
2227
|
-
if (target.preloadTimeout) {
|
|
2228
|
-
return;
|
|
2229
|
-
}
|
|
2230
|
-
target.preloadTimeout = setTimeout(() => {
|
|
2231
|
-
target.preloadTimeout = null;
|
|
2232
|
-
this.preloadRoute(nextOpts).catch(err => {
|
|
2233
|
-
console.warn(err);
|
|
2234
|
-
console.warn(preloadWarning);
|
|
2235
|
-
});
|
|
2236
|
-
}, preloadDelay);
|
|
2237
|
-
}
|
|
2238
|
-
};
|
|
2239
|
-
const handleLeave = e => {
|
|
2240
|
-
const target = e.target || {};
|
|
2241
|
-
if (target.preloadTimeout) {
|
|
2242
|
-
clearTimeout(target.preloadTimeout);
|
|
2243
|
-
target.preloadTimeout = null;
|
|
2244
|
-
}
|
|
2245
|
-
};
|
|
2246
|
-
return {
|
|
2247
|
-
type: 'internal',
|
|
2248
|
-
next,
|
|
2249
|
-
handleFocus,
|
|
2250
|
-
handleClick,
|
|
2251
|
-
handleEnter,
|
|
2252
|
-
handleLeave,
|
|
2253
|
-
handleTouchStart,
|
|
2254
|
-
isActive,
|
|
2255
|
-
disabled
|
|
2256
|
-
};
|
|
2257
|
-
};
|
|
2258
2223
|
matchRoute = (location, opts) => {
|
|
2259
2224
|
location = {
|
|
2260
2225
|
...location,
|
|
@@ -2360,9 +2325,6 @@ function lazyFn(fn, key) {
|
|
|
2360
2325
|
return imported[key || 'default'](...args);
|
|
2361
2326
|
};
|
|
2362
2327
|
}
|
|
2363
|
-
function isCtrlEvent(e) {
|
|
2364
|
-
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
2365
|
-
}
|
|
2366
2328
|
class SearchParamError extends Error {}
|
|
2367
2329
|
class PathParamError extends Error {}
|
|
2368
2330
|
function getInitialRouterState(location) {
|