@tanstack/react-router 0.0.1-beta.37 → 0.0.1-beta.39
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/_virtual/_rollupPluginBabelHelpers.js +0 -13
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/cjs/index.js +308 -238
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +297 -249
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +87 -56
- package/build/types/index.d.ts +50 -41
- package/build/umd/index.development.js +1369 -854
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -2
- package/src/index.tsx +470 -420
- package/src/uSES/useSyncExternalStore.ts +16 -0
- package/src/uSES/useSyncExternalStoreShim.ts +20 -0
- package/src/uSES/useSyncExternalStoreShimClient.ts +87 -0
- package/src/uSES/useSyncExternalStoreShimServer.ts +20 -0
package/build/esm/index.js
CHANGED
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import * as React from 'react';
|
|
12
12
|
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
13
|
-
import {
|
|
13
|
+
import { createStore, createRoot, createEffect, untrack, unwrap } from '@solidjs/reactivity';
|
|
14
|
+
export * from '@solidjs/reactivity';
|
|
15
|
+
import { sharedClone, functionalUpdate, createRouter, warning, invariant, last } from '@tanstack/router-core';
|
|
14
16
|
export * from '@tanstack/router-core';
|
|
15
17
|
|
|
16
18
|
function _extends() {
|
|
@@ -27,276 +29,316 @@ function _extends() {
|
|
|
27
29
|
};
|
|
28
30
|
return _extends.apply(this, arguments);
|
|
29
31
|
}
|
|
30
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
31
|
-
if (source == null) return {};
|
|
32
|
-
var target = {};
|
|
33
|
-
var sourceKeys = Object.keys(source);
|
|
34
|
-
var key, i;
|
|
35
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
36
|
-
key = sourceKeys[i];
|
|
37
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
38
|
-
target[key] = source[key];
|
|
39
|
-
}
|
|
40
|
-
return target;
|
|
41
|
-
}
|
|
42
32
|
|
|
43
|
-
const _excluded = ["type", "children", "target", "activeProps", "inactiveProps", "activeOptions", "disabled", "hash", "search", "params", "to", "preload", "preloadDelay", "preloadMaxAge", "replace", "style", "className", "onClick", "onFocus", "onMouseEnter", "onMouseLeave", "onTouchStart", "onTouchEnd"],
|
|
44
|
-
_excluded2 = ["pending", "caseSensitive", "children"],
|
|
45
|
-
_excluded3 = ["router"];
|
|
46
33
|
function lazy(importer) {
|
|
47
34
|
const lazyComp = /*#__PURE__*/React.lazy(importer);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return /*#__PURE__*/React.createElement(resolvedCompRef.current, _extends({}, ref ? {
|
|
53
|
-
ref
|
|
54
|
-
} : {}, props));
|
|
55
|
-
});
|
|
56
|
-
const finalComp = forwardedComp;
|
|
57
|
-
finalComp.preload = () => {
|
|
58
|
-
if (!promise) {
|
|
59
|
-
promise = importer().then(module => {
|
|
60
|
-
resolvedComp = module.default;
|
|
61
|
-
return resolvedComp;
|
|
62
|
-
});
|
|
35
|
+
const finalComp = lazyComp;
|
|
36
|
+
finalComp.preload = async () => {
|
|
37
|
+
{
|
|
38
|
+
await importer();
|
|
63
39
|
}
|
|
64
|
-
return promise;
|
|
65
40
|
};
|
|
66
41
|
return finalComp;
|
|
67
42
|
}
|
|
68
43
|
//
|
|
69
44
|
|
|
70
|
-
function
|
|
45
|
+
function useLinkProps(options) {
|
|
71
46
|
const router = useRouter();
|
|
72
|
-
|
|
47
|
+
const {
|
|
48
|
+
// custom props
|
|
49
|
+
type,
|
|
50
|
+
children,
|
|
51
|
+
target,
|
|
52
|
+
activeProps = () => ({
|
|
53
|
+
className: 'active'
|
|
54
|
+
}),
|
|
55
|
+
inactiveProps = () => ({}),
|
|
56
|
+
activeOptions,
|
|
57
|
+
disabled,
|
|
58
|
+
// fromCurrent,
|
|
59
|
+
hash,
|
|
60
|
+
search,
|
|
61
|
+
params,
|
|
62
|
+
to,
|
|
63
|
+
preload,
|
|
64
|
+
preloadDelay,
|
|
65
|
+
preloadMaxAge,
|
|
66
|
+
replace,
|
|
67
|
+
// element props
|
|
68
|
+
style,
|
|
69
|
+
className,
|
|
70
|
+
onClick,
|
|
71
|
+
onFocus,
|
|
72
|
+
onMouseEnter,
|
|
73
|
+
onMouseLeave,
|
|
74
|
+
onTouchStart,
|
|
75
|
+
onTouchEnd,
|
|
76
|
+
...rest
|
|
77
|
+
} = options;
|
|
78
|
+
const linkInfo = router.buildLink(options);
|
|
79
|
+
if (linkInfo.type === 'external') {
|
|
80
|
+
const {
|
|
81
|
+
href
|
|
82
|
+
} = linkInfo;
|
|
83
|
+
return {
|
|
84
|
+
href
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const {
|
|
88
|
+
handleClick,
|
|
89
|
+
handleFocus,
|
|
90
|
+
handleEnter,
|
|
91
|
+
handleLeave,
|
|
92
|
+
isActive,
|
|
93
|
+
next
|
|
94
|
+
} = linkInfo;
|
|
95
|
+
const reactHandleClick = e => {
|
|
96
|
+
if (React.startTransition) {
|
|
97
|
+
// This is a hack for react < 18
|
|
98
|
+
React.startTransition(() => {
|
|
99
|
+
handleClick(e);
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
handleClick(e);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const composeHandlers = handlers => e => {
|
|
106
|
+
if (e.persist) e.persist();
|
|
107
|
+
handlers.filter(Boolean).forEach(handler => {
|
|
108
|
+
if (e.defaultPrevented) return;
|
|
109
|
+
handler(e);
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// Get the active props
|
|
114
|
+
const resolvedActiveProps = isActive ? functionalUpdate(activeProps, {}) ?? {} : {};
|
|
115
|
+
|
|
116
|
+
// Get the inactive props
|
|
117
|
+
const resolvedInactiveProps = isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {};
|
|
118
|
+
return {
|
|
119
|
+
...resolvedActiveProps,
|
|
120
|
+
...resolvedInactiveProps,
|
|
121
|
+
...rest,
|
|
122
|
+
href: disabled ? undefined : next.href,
|
|
123
|
+
onClick: composeHandlers([onClick, reactHandleClick]),
|
|
124
|
+
onFocus: composeHandlers([onFocus, handleFocus]),
|
|
125
|
+
onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),
|
|
126
|
+
onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),
|
|
127
|
+
target,
|
|
128
|
+
style: {
|
|
129
|
+
...style,
|
|
130
|
+
...resolvedActiveProps.style,
|
|
131
|
+
...resolvedInactiveProps.style
|
|
132
|
+
},
|
|
133
|
+
className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined,
|
|
134
|
+
...(disabled ? {
|
|
135
|
+
role: 'link',
|
|
136
|
+
'aria-disabled': true
|
|
137
|
+
} : undefined),
|
|
138
|
+
['data-status']: isActive ? 'active' : undefined
|
|
139
|
+
};
|
|
73
140
|
}
|
|
141
|
+
const Link = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
142
|
+
const linkProps = useLinkProps(props);
|
|
143
|
+
return /*#__PURE__*/React.createElement("a", _extends({
|
|
144
|
+
ref: ref
|
|
145
|
+
}, linkProps, {
|
|
146
|
+
children: typeof props.children === 'function' ? props.children({
|
|
147
|
+
isActive: linkProps['data-status'] === 'active'
|
|
148
|
+
}) : props.children
|
|
149
|
+
}));
|
|
150
|
+
});
|
|
74
151
|
const matchesContext = /*#__PURE__*/React.createContext(null);
|
|
75
152
|
const routerContext = /*#__PURE__*/React.createContext(null);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const useRouterSubscription = router => {
|
|
80
|
-
useSyncExternalStore(cb => router.subscribe(() => cb()), () => router.state, () => router.state);
|
|
81
|
-
};
|
|
82
|
-
function createReactRouter(opts) {
|
|
83
|
-
const makeRouteExt = (route, router) => {
|
|
84
|
-
return {
|
|
85
|
-
useRoute: function useRoute(subRouteId) {
|
|
86
|
-
if (subRouteId === void 0) {
|
|
87
|
-
subRouteId = '.';
|
|
88
|
-
}
|
|
89
|
-
const resolvedRouteId = router.resolvePath(route.routeId, subRouteId);
|
|
90
|
-
const resolvedRoute = router.getRoute(resolvedRouteId);
|
|
91
|
-
useRouterSubscription(router);
|
|
92
|
-
invariant(resolvedRoute, "Could not find a route for route \"" + resolvedRouteId + "\"! Did you forget to add it to your route config?");
|
|
93
|
-
return resolvedRoute;
|
|
94
|
-
},
|
|
95
|
-
linkProps: options => {
|
|
96
|
-
var _functionalUpdate, _functionalUpdate2;
|
|
97
|
-
const {
|
|
98
|
-
// custom props
|
|
153
|
+
const EMPTY = {};
|
|
154
|
+
const __useStoreValue = (seed, selector) => {
|
|
155
|
+
const valueRef = React.useRef(EMPTY);
|
|
99
156
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}),
|
|
104
|
-
inactiveProps = () => ({}),
|
|
105
|
-
disabled,
|
|
106
|
-
// element props
|
|
107
|
-
style,
|
|
108
|
-
className,
|
|
109
|
-
onClick,
|
|
110
|
-
onFocus,
|
|
111
|
-
onMouseEnter,
|
|
112
|
-
onMouseLeave
|
|
113
|
-
} = options,
|
|
114
|
-
rest = _objectWithoutPropertiesLoose(options, _excluded);
|
|
115
|
-
const linkInfo = route.buildLink(options);
|
|
116
|
-
if (linkInfo.type === 'external') {
|
|
117
|
-
const {
|
|
118
|
-
href
|
|
119
|
-
} = linkInfo;
|
|
120
|
-
return {
|
|
121
|
-
href
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
const {
|
|
125
|
-
handleClick,
|
|
126
|
-
handleFocus,
|
|
127
|
-
handleEnter,
|
|
128
|
-
handleLeave,
|
|
129
|
-
isActive,
|
|
130
|
-
next
|
|
131
|
-
} = linkInfo;
|
|
132
|
-
const reactHandleClick = e => {
|
|
133
|
-
if (React.startTransition)
|
|
134
|
-
// This is a hack for react < 18
|
|
135
|
-
React.startTransition(() => {
|
|
136
|
-
handleClick(e);
|
|
137
|
-
});else handleClick(e);
|
|
138
|
-
};
|
|
139
|
-
const composeHandlers = handlers => e => {
|
|
140
|
-
if (e.persist) e.persist();
|
|
141
|
-
handlers.forEach(handler => {
|
|
142
|
-
if (e.defaultPrevented) return;
|
|
143
|
-
if (handler) handler(e);
|
|
144
|
-
});
|
|
145
|
-
};
|
|
157
|
+
// If there is no selector, track the seed
|
|
158
|
+
// If there is a selector, do not track the seed
|
|
159
|
+
const getValue = () => !selector ? seed() : selector(untrack(() => seed()));
|
|
146
160
|
|
|
147
|
-
|
|
148
|
-
|
|
161
|
+
// If empty, initialize the value
|
|
162
|
+
if (valueRef.current === EMPTY) {
|
|
163
|
+
valueRef.current = sharedClone(undefined, getValue());
|
|
164
|
+
}
|
|
149
165
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
};
|
|
196
|
-
const coreRouter = createRouter(_extends({}, opts, {
|
|
197
|
-
createRouter: router => {
|
|
198
|
-
const routerExt = {
|
|
199
|
-
useState: () => {
|
|
200
|
-
useRouterSubscription(router);
|
|
201
|
-
return router.state;
|
|
202
|
-
},
|
|
203
|
-
useMatch: (routeId, opts) => {
|
|
204
|
-
var _opts$strict;
|
|
205
|
-
useRouterSubscription(router);
|
|
206
|
-
const nearestMatch = useNearestMatch();
|
|
207
|
-
const match = router.state.currentMatches.find(d => d.routeId === routeId);
|
|
208
|
-
if ((_opts$strict = opts == null ? void 0 : opts.strict) != null ? _opts$strict : true) {
|
|
209
|
-
invariant(match, "Could not find an active match for \"" + routeId + "\"!");
|
|
210
|
-
invariant(nearestMatch.routeId == (match == null ? void 0 : match.routeId), "useMatch(\"" + (match == null ? void 0 : match.routeId) + "\") is being called in a component that is meant to render the '" + nearestMatch.routeId + "' route. Did you mean to 'useMatch(\"" + (match == null ? void 0 : match.routeId) + "\", { strict: false })' or 'useRoute(\"" + (match == null ? void 0 : match.routeId) + "\")' instead?");
|
|
211
|
-
}
|
|
212
|
-
return match;
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
const routeExt = makeRouteExt(router.getRoute(rootRouteId), router);
|
|
216
|
-
Object.assign(router, routerExt, routeExt);
|
|
217
|
-
},
|
|
218
|
-
createRoute: _ref => {
|
|
219
|
-
let {
|
|
220
|
-
router,
|
|
221
|
-
route
|
|
222
|
-
} = _ref;
|
|
223
|
-
const routeExt = makeRouteExt(route, router);
|
|
224
|
-
Object.assign(route, routeExt);
|
|
225
|
-
},
|
|
166
|
+
// Snapshot should just return the current cached value
|
|
167
|
+
const getSnapshot = React.useCallback(() => valueRef.current, []);
|
|
168
|
+
const getStore = React.useCallback(cb => {
|
|
169
|
+
// A root is necessary to track effects
|
|
170
|
+
return createRoot(() => {
|
|
171
|
+
createEffect(() => {
|
|
172
|
+
// Read and update the value
|
|
173
|
+
// getValue will handle which values are accessed and
|
|
174
|
+
// thus tracked.
|
|
175
|
+
// sharedClone will both recursively track the end result
|
|
176
|
+
// and ensure that the previous value is structurally shared
|
|
177
|
+
// into the new version.
|
|
178
|
+
valueRef.current = unwrap(
|
|
179
|
+
// Unwrap the value to get rid of any proxy structures
|
|
180
|
+
sharedClone(valueRef.current, getValue()));
|
|
181
|
+
cb();
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
}, []);
|
|
185
|
+
return useSyncExternalStore(getStore, getSnapshot, getSnapshot);
|
|
186
|
+
};
|
|
187
|
+
const [store, setStore] = createStore({
|
|
188
|
+
foo: 'foo',
|
|
189
|
+
bar: {
|
|
190
|
+
baz: 'baz'
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
createRoot(() => {
|
|
194
|
+
let prev;
|
|
195
|
+
createEffect(() => {
|
|
196
|
+
console.log('effect');
|
|
197
|
+
const next = sharedClone(prev, store);
|
|
198
|
+
console.log(next);
|
|
199
|
+
prev = untrack(() => next);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
setStore(s => {
|
|
203
|
+
s.foo = '1';
|
|
204
|
+
});
|
|
205
|
+
setStore(s => {
|
|
206
|
+
s.bar.baz = '2';
|
|
207
|
+
});
|
|
208
|
+
function createReactRouter(opts) {
|
|
209
|
+
const coreRouter = createRouter({
|
|
210
|
+
...opts,
|
|
226
211
|
loadComponent: async component => {
|
|
227
|
-
if (component.preload
|
|
228
|
-
component.preload();
|
|
229
|
-
// return await component.preload()
|
|
212
|
+
if (component.preload) {
|
|
213
|
+
await component.preload();
|
|
230
214
|
}
|
|
231
|
-
|
|
232
215
|
return component;
|
|
233
216
|
}
|
|
234
|
-
})
|
|
217
|
+
});
|
|
235
218
|
return coreRouter;
|
|
236
219
|
}
|
|
237
|
-
function RouterProvider(
|
|
220
|
+
function RouterProvider(_ref) {
|
|
238
221
|
let {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
222
|
+
router,
|
|
223
|
+
...rest
|
|
224
|
+
} = _ref;
|
|
242
225
|
router.update(rest);
|
|
243
|
-
|
|
244
|
-
React.useEffect(
|
|
245
|
-
|
|
246
|
-
}, [router]);
|
|
226
|
+
const [,, currentMatches] = __useStoreValue(() => router.store, s => [s.status, s.pendingMatches, s.currentMatches]);
|
|
227
|
+
React.useEffect(router.mount, [router]);
|
|
228
|
+
console.log('current', currentMatches);
|
|
247
229
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(routerContext.Provider, {
|
|
248
230
|
value: {
|
|
249
231
|
router: router
|
|
250
232
|
}
|
|
251
|
-
}, /*#__PURE__*/React.createElement(
|
|
252
|
-
value: [undefined, ...
|
|
233
|
+
}, /*#__PURE__*/React.createElement(matchesContext.Provider, {
|
|
234
|
+
value: [undefined, ...currentMatches]
|
|
253
235
|
}, /*#__PURE__*/React.createElement(Outlet, null))));
|
|
254
236
|
}
|
|
255
237
|
function useRouter() {
|
|
256
238
|
const value = React.useContext(routerContext);
|
|
257
239
|
warning(!value, 'useRouter must be used inside a <Router> component!');
|
|
258
|
-
useRouterSubscription(value.router);
|
|
259
240
|
return value.router;
|
|
260
241
|
}
|
|
242
|
+
function useRouterStore(selector) {
|
|
243
|
+
const router = useRouter();
|
|
244
|
+
return __useStoreValue(() => router.store, selector);
|
|
245
|
+
}
|
|
261
246
|
function useMatches() {
|
|
262
247
|
return React.useContext(matchesContext);
|
|
263
248
|
}
|
|
264
|
-
function useMatch(
|
|
249
|
+
function useMatch(opts) {
|
|
265
250
|
const router = useRouter();
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
251
|
+
const nearestMatch = useMatches()[0];
|
|
252
|
+
const match = opts != null && opts.from ? router.store.currentMatches.find(d => d.routeId === (opts == null ? void 0 : opts.from)) : nearestMatch;
|
|
253
|
+
invariant(match, `Could not find ${opts != null && opts.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
|
|
254
|
+
if ((opts == null ? void 0 : opts.strict) ?? true) {
|
|
255
|
+
invariant(nearestMatch.routeId == (match == null ? void 0 : match.routeId), `useMatch("${match == null ? void 0 : match.routeId}") is being called in a component that is meant to render the '${nearestMatch.routeId}' route. Did you mean to 'useMatch("${match == null ? void 0 : match.routeId}", { strict: false })' or 'useRoute("${match == null ? void 0 : match.routeId}")' instead?`);
|
|
256
|
+
}
|
|
257
|
+
__useStoreValue(() => match.store);
|
|
258
|
+
return match;
|
|
272
259
|
}
|
|
273
260
|
function useRoute(routeId) {
|
|
274
261
|
const router = useRouter();
|
|
275
|
-
|
|
262
|
+
const resolvedRoute = router.getRoute(routeId);
|
|
263
|
+
invariant(resolvedRoute, `Could not find a route for route "${routeId}"! Did you forget to add it to your route config?`);
|
|
264
|
+
return resolvedRoute;
|
|
265
|
+
}
|
|
266
|
+
function useLoaderData(opts) {
|
|
267
|
+
const match = useMatch(opts);
|
|
268
|
+
return __useStoreValue(() => match == null ? void 0 : match.store.loaderData, opts == null ? void 0 : opts.select);
|
|
276
269
|
}
|
|
277
|
-
function useSearch(
|
|
278
|
-
|
|
270
|
+
function useSearch(opts) {
|
|
271
|
+
const match = useMatch(opts);
|
|
272
|
+
return __useStoreValue(() => match == null ? void 0 : match.store.search, opts == null ? void 0 : opts.select);
|
|
279
273
|
}
|
|
280
|
-
function
|
|
274
|
+
function useParams(opts) {
|
|
281
275
|
const router = useRouter();
|
|
282
|
-
return
|
|
276
|
+
return __useStoreValue(() => {
|
|
277
|
+
var _last;
|
|
278
|
+
return (_last = last(router.store.currentMatches)) == null ? void 0 : _last.params;
|
|
279
|
+
}, opts == null ? void 0 : opts.select);
|
|
283
280
|
}
|
|
284
|
-
function
|
|
281
|
+
function useNavigate(defaultOpts) {
|
|
282
|
+
return opts => {
|
|
283
|
+
const router = useRouter();
|
|
284
|
+
return router.navigate({
|
|
285
|
+
...defaultOpts,
|
|
286
|
+
...opts
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function useAction(opts) {
|
|
291
|
+
const route = useRoute(opts.from);
|
|
292
|
+
const action = route.action;
|
|
293
|
+
__useStoreValue(() => action);
|
|
294
|
+
return action;
|
|
295
|
+
}
|
|
296
|
+
function useMatchRoute() {
|
|
285
297
|
const router = useRouter();
|
|
286
|
-
return
|
|
298
|
+
return opts => {
|
|
299
|
+
const {
|
|
300
|
+
pending,
|
|
301
|
+
caseSensitive,
|
|
302
|
+
...rest
|
|
303
|
+
} = opts;
|
|
304
|
+
return router.matchRoute(rest, {
|
|
305
|
+
pending,
|
|
306
|
+
caseSensitive
|
|
307
|
+
});
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function MatchRoute(props) {
|
|
311
|
+
const matchRoute = useMatchRoute();
|
|
312
|
+
const params = matchRoute(props);
|
|
313
|
+
if (!params) {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
return /*#__PURE__*/React.createElement(typeof props.children === 'function' ? props.children(params) : props.children, props);
|
|
287
317
|
}
|
|
288
318
|
function Outlet() {
|
|
289
|
-
var _ref3, _match$__$pendingComp, _match$__$errorCompon;
|
|
290
319
|
const router = useRouter();
|
|
291
320
|
const matches = useMatches().slice(1);
|
|
292
321
|
const match = matches[0];
|
|
293
322
|
const defaultPending = React.useCallback(() => null, []);
|
|
323
|
+
__useStoreValue(() => match == null ? void 0 : match.store);
|
|
324
|
+
const Inner = React.useCallback(props => {
|
|
325
|
+
if (props.match.store.status === 'error') {
|
|
326
|
+
throw props.match.store.error;
|
|
327
|
+
}
|
|
328
|
+
if (props.match.store.status === 'success') {
|
|
329
|
+
return /*#__PURE__*/React.createElement(props.match.__.component ?? router.options.defaultComponent ?? Outlet);
|
|
330
|
+
}
|
|
331
|
+
if (props.match.store.status === 'loading') {
|
|
332
|
+
throw props.match.__.loadPromise;
|
|
333
|
+
}
|
|
334
|
+
invariant(false, 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!');
|
|
335
|
+
}, []);
|
|
294
336
|
if (!match) {
|
|
295
337
|
return null;
|
|
296
338
|
}
|
|
297
|
-
const PendingComponent =
|
|
298
|
-
const errorComponent =
|
|
299
|
-
return /*#__PURE__*/React.createElement(
|
|
339
|
+
const PendingComponent = match.__.pendingComponent ?? router.options.defaultPendingComponent ?? defaultPending;
|
|
340
|
+
const errorComponent = match.__.errorComponent ?? router.options.defaultErrorComponent;
|
|
341
|
+
return /*#__PURE__*/React.createElement(matchesContext.Provider, {
|
|
300
342
|
value: matches
|
|
301
343
|
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
302
344
|
fallback: /*#__PURE__*/React.createElement(PendingComponent, null)
|
|
@@ -304,27 +346,17 @@ function Outlet() {
|
|
|
304
346
|
key: match.routeId,
|
|
305
347
|
errorComponent: errorComponent,
|
|
306
348
|
match: match
|
|
307
|
-
}, (
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
if (match.status === 'success') {
|
|
312
|
-
var _ref4, _ref5;
|
|
313
|
-
return /*#__PURE__*/React.createElement((_ref4 = (_ref5 = match.__.component) != null ? _ref5 : router.options.defaultComponent) != null ? _ref4 : Outlet);
|
|
314
|
-
}
|
|
315
|
-
throw match.__.loadPromise;
|
|
316
|
-
})())));
|
|
349
|
+
}, /*#__PURE__*/React.createElement(Inner, {
|
|
350
|
+
match: match
|
|
351
|
+
}))));
|
|
317
352
|
}
|
|
318
353
|
class CatchBoundary extends React.Component {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
info: undefined
|
|
324
|
-
};
|
|
325
|
-
}
|
|
354
|
+
state = {
|
|
355
|
+
error: false,
|
|
356
|
+
info: undefined
|
|
357
|
+
};
|
|
326
358
|
componentDidCatch(error, info) {
|
|
327
|
-
console.error(
|
|
359
|
+
console.error(`Error in route match: ${this.props.match.matchId}`);
|
|
328
360
|
console.error(error);
|
|
329
361
|
this.setState({
|
|
330
362
|
error,
|
|
@@ -343,19 +375,18 @@ class CatchBoundary extends React.Component {
|
|
|
343
375
|
// there has to be a better way to reset error boundaries when the
|
|
344
376
|
// router's location key changes.
|
|
345
377
|
function CatchBoundaryInner(props) {
|
|
346
|
-
var _props$errorComponent;
|
|
347
378
|
const [activeErrorState, setActiveErrorState] = React.useState(props.errorState);
|
|
348
379
|
const router = useRouter();
|
|
349
|
-
const errorComponent =
|
|
380
|
+
const errorComponent = props.errorComponent ?? DefaultErrorBoundary;
|
|
350
381
|
React.useEffect(() => {
|
|
351
382
|
if (activeErrorState) {
|
|
352
|
-
let prevKey = router.
|
|
353
|
-
return
|
|
354
|
-
if (router.
|
|
355
|
-
prevKey = router.
|
|
383
|
+
let prevKey = router.store.currentLocation.key;
|
|
384
|
+
return createRoot(() => createEffect(() => {
|
|
385
|
+
if (router.store.currentLocation.key !== prevKey) {
|
|
386
|
+
prevKey = router.store.currentLocation.key;
|
|
356
387
|
setActiveErrorState({});
|
|
357
388
|
}
|
|
358
|
-
});
|
|
389
|
+
}));
|
|
359
390
|
}
|
|
360
391
|
return;
|
|
361
392
|
}, [activeErrorState]);
|
|
@@ -365,15 +396,15 @@ function CatchBoundaryInner(props) {
|
|
|
365
396
|
}
|
|
366
397
|
props.reset();
|
|
367
398
|
}, [props.errorState.error]);
|
|
368
|
-
if (
|
|
399
|
+
if (props.errorState.error) {
|
|
369
400
|
return /*#__PURE__*/React.createElement(errorComponent, activeErrorState);
|
|
370
401
|
}
|
|
371
402
|
return props.children;
|
|
372
403
|
}
|
|
373
|
-
function DefaultErrorBoundary(
|
|
404
|
+
function DefaultErrorBoundary(_ref2) {
|
|
374
405
|
let {
|
|
375
406
|
error
|
|
376
|
-
} =
|
|
407
|
+
} = _ref2;
|
|
377
408
|
return /*#__PURE__*/React.createElement("div", {
|
|
378
409
|
style: {
|
|
379
410
|
padding: '.5rem',
|
|
@@ -406,21 +437,38 @@ function usePrompt(message, when) {
|
|
|
406
437
|
unblock();
|
|
407
438
|
transition.retry();
|
|
408
439
|
} else {
|
|
409
|
-
router.
|
|
440
|
+
router.store.currentLocation.pathname = window.location.pathname;
|
|
410
441
|
}
|
|
411
442
|
});
|
|
412
443
|
return unblock;
|
|
413
444
|
}, [when, message]);
|
|
414
445
|
}
|
|
415
|
-
function Prompt(
|
|
446
|
+
function Prompt(_ref3) {
|
|
416
447
|
let {
|
|
417
448
|
message,
|
|
418
449
|
when,
|
|
419
450
|
children
|
|
420
|
-
} =
|
|
421
|
-
usePrompt(message, when
|
|
422
|
-
return children
|
|
451
|
+
} = _ref3;
|
|
452
|
+
usePrompt(message, when ?? true);
|
|
453
|
+
return children ?? null;
|
|
423
454
|
}
|
|
424
455
|
|
|
425
|
-
|
|
456
|
+
// function circularStringify(obj: any) {
|
|
457
|
+
// const seen = new Set()
|
|
458
|
+
|
|
459
|
+
// return (
|
|
460
|
+
// JSON.stringify(obj, (_, value) => {
|
|
461
|
+
// if (typeof value === 'function') {
|
|
462
|
+
// return undefined
|
|
463
|
+
// }
|
|
464
|
+
// if (typeof value === 'object' && value !== null) {
|
|
465
|
+
// if (seen.has(value)) return
|
|
466
|
+
// seen.add(value)
|
|
467
|
+
// }
|
|
468
|
+
// return value
|
|
469
|
+
// }) || ''
|
|
470
|
+
// )
|
|
471
|
+
// }
|
|
472
|
+
|
|
473
|
+
export { DefaultErrorBoundary, Link, MatchRoute, Outlet, Prompt, RouterProvider, __useStoreValue, createReactRouter, lazy, matchesContext, routerContext, useAction, useLinkProps, useLoaderData, useMatch, useMatchRoute, useMatches, useNavigate, useParams, usePrompt, useRoute, useRouter, useRouterStore, useSearch };
|
|
426
474
|
//# sourceMappingURL=index.js.map
|