@tanstack/react-router 0.0.1-beta.15 → 0.0.1-beta.151

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Tanner Linsley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router
2
+ * @tanstack/react-router/src/index.tsx
3
3
  *
4
4
  * Copyright (c) TanStack
5
5
  *
@@ -16,34 +16,16 @@ function _extends() {
16
16
  _extends = Object.assign ? Object.assign.bind() : function (target) {
17
17
  for (var i = 1; i < arguments.length; i++) {
18
18
  var source = arguments[i];
19
-
20
19
  for (var key in source) {
21
20
  if (Object.prototype.hasOwnProperty.call(source, key)) {
22
21
  target[key] = source[key];
23
22
  }
24
23
  }
25
24
  }
26
-
27
25
  return target;
28
26
  };
29
27
  return _extends.apply(this, arguments);
30
28
  }
31
29
 
32
- function _objectWithoutPropertiesLoose(source, excluded) {
33
- if (source == null) return {};
34
- var target = {};
35
- var sourceKeys = Object.keys(source);
36
- var key, i;
37
-
38
- for (i = 0; i < sourceKeys.length; i++) {
39
- key = sourceKeys[i];
40
- if (excluded.indexOf(key) >= 0) continue;
41
- target[key] = source[key];
42
- }
43
-
44
- return target;
45
- }
46
-
47
30
  exports["extends"] = _extends;
48
- exports.objectWithoutPropertiesLoose = _objectWithoutPropertiesLoose;
49
31
  //# sourceMappingURL=_rollupPluginBabelHelpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_rollupPluginBabelHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"_rollupPluginBabelHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,649 @@
1
+ /**
2
+ * @tanstack/react-router/src/index.tsx
3
+ *
4
+ * Copyright (c) TanStack
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ 'use strict';
12
+
13
+ Object.defineProperty(exports, '__esModule', { value: true });
14
+
15
+ var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
16
+ var React = require('react');
17
+ var reactStore = require('@tanstack/react-store');
18
+ var invariant = require('tiny-invariant');
19
+ var warning = require('tiny-warning');
20
+ var routerCore = require('@tanstack/router-core');
21
+
22
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
23
+
24
+ function _interopNamespace(e) {
25
+ if (e && e.__esModule) return e;
26
+ var n = Object.create(null);
27
+ if (e) {
28
+ Object.keys(e).forEach(function (k) {
29
+ if (k !== 'default') {
30
+ var d = Object.getOwnPropertyDescriptor(e, k);
31
+ Object.defineProperty(n, k, d.get ? d : {
32
+ enumerable: true,
33
+ get: function () { return e[k]; }
34
+ });
35
+ }
36
+ });
37
+ }
38
+ n["default"] = e;
39
+ return Object.freeze(n);
40
+ }
41
+
42
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
43
+ var invariant__default = /*#__PURE__*/_interopDefaultLegacy(invariant);
44
+ var warning__default = /*#__PURE__*/_interopDefaultLegacy(warning);
45
+
46
+ routerCore.Route.__onInit = route => {
47
+ Object.assign(route, {
48
+ useMatch: (opts = {}) => {
49
+ return useMatch({
50
+ ...opts,
51
+ from: route.id
52
+ });
53
+ },
54
+ useLoader: (opts = {}) => {
55
+ return useLoader({
56
+ ...opts,
57
+ from: route.id
58
+ });
59
+ },
60
+ useContext: (opts = {}) => {
61
+ return useMatch({
62
+ ...opts,
63
+ from: route.id,
64
+ select: d => opts?.select?.(d.context) ?? d.context
65
+ });
66
+ },
67
+ useRouteContext: (opts = {}) => {
68
+ return useMatch({
69
+ ...opts,
70
+ from: route.id,
71
+ select: d => opts?.select?.(d.routeContext) ?? d.routeContext
72
+ });
73
+ },
74
+ useSearch: (opts = {}) => {
75
+ return useSearch({
76
+ ...opts,
77
+ from: route.id
78
+ });
79
+ },
80
+ useParams: (opts = {}) => {
81
+ return useParams({
82
+ ...opts,
83
+ from: route.id
84
+ });
85
+ }
86
+ });
87
+ };
88
+
89
+ //
90
+
91
+ function lazyRouteComponent(importer, exportName) {
92
+ let loadPromise;
93
+ const load = () => {
94
+ if (!loadPromise) {
95
+ loadPromise = importer();
96
+ }
97
+ return loadPromise;
98
+ };
99
+ const lazyComp = /*#__PURE__*/React__namespace.lazy(async () => {
100
+ const moduleExports = await load();
101
+ const comp = moduleExports[exportName ?? 'default'];
102
+ return {
103
+ default: comp
104
+ };
105
+ });
106
+ lazyComp.preload = load;
107
+ return lazyComp;
108
+ }
109
+ //
110
+
111
+ function useLinkProps(options) {
112
+ const router = useRouter();
113
+ const {
114
+ // custom props
115
+ type,
116
+ children,
117
+ target,
118
+ activeProps = () => ({
119
+ className: 'active'
120
+ }),
121
+ inactiveProps = () => ({}),
122
+ activeOptions,
123
+ disabled,
124
+ // fromCurrent,
125
+ hash,
126
+ search,
127
+ params,
128
+ to = '.',
129
+ preload,
130
+ preloadDelay,
131
+ replace,
132
+ // element props
133
+ style,
134
+ className,
135
+ onClick,
136
+ onFocus,
137
+ onMouseEnter,
138
+ onMouseLeave,
139
+ onTouchStart,
140
+ ...rest
141
+ } = options;
142
+ const linkInfo = router.buildLink(options);
143
+ if (linkInfo.type === 'external') {
144
+ const {
145
+ href
146
+ } = linkInfo;
147
+ return {
148
+ href
149
+ };
150
+ }
151
+ const {
152
+ handleClick,
153
+ handleFocus,
154
+ handleEnter,
155
+ handleLeave,
156
+ handleTouchStart,
157
+ isActive,
158
+ next
159
+ } = linkInfo;
160
+ const handleReactClick = e => {
161
+ if (options.startTransition ?? true) {
162
+ (React__namespace.startTransition || (d => d))(() => {
163
+ handleClick(e);
164
+ });
165
+ }
166
+ };
167
+ const composeHandlers = handlers => e => {
168
+ if (e.persist) e.persist();
169
+ handlers.filter(Boolean).forEach(handler => {
170
+ if (e.defaultPrevented) return;
171
+ handler(e);
172
+ });
173
+ };
174
+
175
+ // Get the active props
176
+ const resolvedActiveProps = isActive ? routerCore.functionalUpdate(activeProps, {}) ?? {} : {};
177
+
178
+ // Get the inactive props
179
+ const resolvedInactiveProps = isActive ? {} : routerCore.functionalUpdate(inactiveProps, {}) ?? {};
180
+ return {
181
+ ...resolvedActiveProps,
182
+ ...resolvedInactiveProps,
183
+ ...rest,
184
+ href: disabled ? undefined : next.href,
185
+ onClick: composeHandlers([onClick, handleReactClick]),
186
+ onFocus: composeHandlers([onFocus, handleFocus]),
187
+ onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),
188
+ onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),
189
+ onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),
190
+ target,
191
+ style: {
192
+ ...style,
193
+ ...resolvedActiveProps.style,
194
+ ...resolvedInactiveProps.style
195
+ },
196
+ className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined,
197
+ ...(disabled ? {
198
+ role: 'link',
199
+ 'aria-disabled': true
200
+ } : undefined),
201
+ ['data-status']: isActive ? 'active' : undefined
202
+ };
203
+ }
204
+ const Link = /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
205
+ const linkProps = useLinkProps(props);
206
+ return /*#__PURE__*/React__namespace.createElement("a", _rollupPluginBabelHelpers["extends"]({
207
+ ref: ref
208
+ }, linkProps, {
209
+ children: typeof props.children === 'function' ? props.children({
210
+ isActive: linkProps['data-status'] === 'active'
211
+ }) : props.children
212
+ }));
213
+ });
214
+ function Navigate(props) {
215
+ const router = useRouter();
216
+ React__namespace.useLayoutEffect(() => {
217
+ router.navigate(props);
218
+ }, []);
219
+ return null;
220
+ }
221
+ const matchIdsContext = /*#__PURE__*/React__namespace.createContext(null);
222
+ const routerContext = /*#__PURE__*/React__namespace.createContext(null);
223
+ function useRouterState(opts) {
224
+ const router = useRouter();
225
+ return reactStore.useStore(router.__store, opts?.select);
226
+ }
227
+ function RouterProvider({
228
+ router,
229
+ ...rest
230
+ }) {
231
+ router.update(rest);
232
+ React__namespace.useEffect(() => {
233
+ let unsub;
234
+ React__namespace.startTransition(() => {
235
+ unsub = router.mount();
236
+ });
237
+ return unsub;
238
+ }, [router]);
239
+ const Wrap = router.options.Wrap || React__namespace.Fragment;
240
+ return /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
241
+ fallback: null
242
+ }, /*#__PURE__*/React__namespace.createElement(Wrap, null, /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
243
+ value: router
244
+ }, /*#__PURE__*/React__namespace.createElement(Matches, null))));
245
+ }
246
+ function Matches() {
247
+ const router = useRouter();
248
+ const matchIds = useRouterState({
249
+ select: state => {
250
+ const hasPendingComponent = state.pendingMatches.some(d => {
251
+ const route = router.getRoute(d.routeId);
252
+ return !!route?.options.pendingComponent;
253
+ });
254
+ if (hasPendingComponent) {
255
+ console.log('hasPending');
256
+ return state.pendingMatchIds;
257
+ }
258
+ return state.matchIds;
259
+ }
260
+ });
261
+ return /*#__PURE__*/React__namespace.createElement(matchIdsContext.Provider, {
262
+ value: [undefined, ...matchIds]
263
+ }, /*#__PURE__*/React__namespace.createElement(CatchBoundary, {
264
+ errorComponent: ErrorComponent,
265
+ onCatch: () => {
266
+ warning__default["default"](false, `Error in router! Consider setting an 'errorComponent' in your RootRoute! 👍`);
267
+ }
268
+ }, /*#__PURE__*/React__namespace.createElement(Outlet, null)));
269
+ }
270
+ function useRouter() {
271
+ const value = React__namespace.useContext(routerContext);
272
+ warning__default["default"](value, 'useRouter must be used inside a <Router> component!');
273
+ return value;
274
+ }
275
+ function useMatches(opts) {
276
+ const matchIds = React__namespace.useContext(matchIdsContext);
277
+ return useRouterState({
278
+ select: state => {
279
+ const matches = state.matches.slice(state.matches.findIndex(d => d.id === matchIds[0]));
280
+ return opts?.select?.(matches) ?? matches;
281
+ }
282
+ });
283
+ }
284
+ function useMatch(opts) {
285
+ const router = useRouter();
286
+ const nearestMatchId = React__namespace.useContext(matchIdsContext)[0];
287
+ const nearestMatchRouteId = router.getRouteMatch(nearestMatchId)?.routeId;
288
+ const matchRouteId = useRouterState({
289
+ select: state => {
290
+ const matches = state.matches;
291
+ const match = opts?.from ? matches.find(d => d.routeId === opts?.from) : matches.find(d => d.id === nearestMatchId);
292
+ return match.routeId;
293
+ }
294
+ });
295
+ if (opts?.strict ?? true) {
296
+ invariant__default["default"](nearestMatchRouteId == matchRouteId, `useMatch("${matchRouteId}") is being called in a component that is meant to render the '${nearestMatchRouteId}' route. Did you mean to 'useMatch("${matchRouteId}", { strict: false })' or 'useRoute("${matchRouteId}")' instead?`);
297
+ }
298
+ const match = useRouterState({
299
+ select: state => {
300
+ const matches = state.matches;
301
+ const match = opts?.from ? matches.find(d => d.routeId === opts?.from) : matches.find(d => d.id === nearestMatchId);
302
+ invariant__default["default"](match, `Could not find ${opts?.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
303
+ return opts?.select?.(match) ?? match;
304
+ }
305
+ });
306
+ return match;
307
+ }
308
+ function useLoader(opts) {
309
+ return useMatch({
310
+ ...opts,
311
+ select: match => opts?.select?.(match.loaderData) ?? match.loaderData
312
+ });
313
+ }
314
+ function useRouterContext(opts) {
315
+ return useMatch({
316
+ ...opts,
317
+ select: match => opts?.select?.(match.context) ?? match.context
318
+ });
319
+ }
320
+ function useRouteContext(opts) {
321
+ return useMatch({
322
+ ...opts,
323
+ select: match => opts?.select?.(match.routeContext) ?? match.routeContext
324
+ });
325
+ }
326
+ function useSearch(opts) {
327
+ return useMatch({
328
+ ...opts,
329
+ select: match => {
330
+ return opts?.select?.(match.search) ?? match.search;
331
+ }
332
+ });
333
+ }
334
+ function useParams(opts) {
335
+ return useRouterState({
336
+ select: state => {
337
+ const params = routerCore.last(state.matches)?.params;
338
+ return opts?.select?.(params) ?? params;
339
+ }
340
+ });
341
+ }
342
+ function useNavigate(defaultOpts) {
343
+ const router = useRouter();
344
+ return React__namespace.useCallback(opts => {
345
+ return router.navigate({
346
+ ...defaultOpts,
347
+ ...opts
348
+ });
349
+ }, []);
350
+ }
351
+ function useMatchRoute() {
352
+ const router = useRouter();
353
+ return React__namespace.useCallback(opts => {
354
+ const {
355
+ pending,
356
+ caseSensitive,
357
+ ...rest
358
+ } = opts;
359
+ return router.matchRoute(rest, {
360
+ pending,
361
+ caseSensitive
362
+ });
363
+ }, []);
364
+ }
365
+ function MatchRoute(props) {
366
+ const matchRoute = useMatchRoute();
367
+ const params = matchRoute(props);
368
+ if (typeof props.children === 'function') {
369
+ return props.children(params);
370
+ }
371
+ return !!params ? props.children : null;
372
+ }
373
+ function Outlet() {
374
+ const matchIds = React__namespace.useContext(matchIdsContext).slice(1);
375
+ if (!matchIds[0]) {
376
+ return null;
377
+ }
378
+ return /*#__PURE__*/React__namespace.createElement(Match, {
379
+ matchIds: matchIds
380
+ });
381
+ }
382
+ const defaultPending = () => null;
383
+ function Match({
384
+ matchIds
385
+ }) {
386
+ const router = useRouter();
387
+ const matchId = matchIds[0];
388
+ const routeId = router.getRouteMatch(matchId).routeId;
389
+ const route = router.getRoute(routeId);
390
+ const PendingComponent = route.options.pendingComponent ?? router.options.defaultPendingComponent ?? defaultPending;
391
+ const errorComponent = route.options.errorComponent ?? router.options.defaultErrorComponent ?? ErrorComponent;
392
+ const ResolvedSuspenseBoundary = route.options.wrapInSuspense ?? !route.isRoot ? React__namespace.Suspense : SafeFragment;
393
+ const ResolvedCatchBoundary = !!errorComponent ? CatchBoundary : SafeFragment;
394
+ return /*#__PURE__*/React__namespace.createElement(matchIdsContext.Provider, {
395
+ value: matchIds
396
+ }, /*#__PURE__*/React__namespace.createElement(ResolvedSuspenseBoundary, {
397
+ fallback: /*#__PURE__*/React__namespace.createElement(PendingComponent, {
398
+ useLoader: route.useLoader,
399
+ useMatch: route.useMatch,
400
+ useContext: route.useContext,
401
+ useRouteContext: route.useRouteContext,
402
+ useSearch: route.useSearch,
403
+ useParams: route.useParams
404
+ })
405
+ }, /*#__PURE__*/React__namespace.createElement(ResolvedCatchBoundary, {
406
+ key: route.id,
407
+ errorComponent: errorComponent,
408
+ onCatch: () => {
409
+ warning__default["default"](false, `Error in route match: ${matchId}`);
410
+ }
411
+ }, /*#__PURE__*/React__namespace.createElement(MatchInner, {
412
+ matchId: matchId,
413
+ PendingComponent: PendingComponent
414
+ }))));
415
+ }
416
+ function MatchInner({
417
+ matchId,
418
+ PendingComponent
419
+ }) {
420
+ const router = useRouter();
421
+ const match = useRouterState({
422
+ select: d => {
423
+ const match = d.matchesById[matchId];
424
+ return routerCore.pick(match, ['status', 'loadPromise', 'routeId', 'error']);
425
+ }
426
+ });
427
+ const route = router.getRoute(match.routeId);
428
+ if (match.status === 'error') {
429
+ throw match.error;
430
+ }
431
+ if (match.status === 'pending') {
432
+ return /*#__PURE__*/React__namespace.createElement(PendingComponent, {
433
+ useLoader: route.useLoader,
434
+ useMatch: route.useMatch,
435
+ useContext: route.useContext,
436
+ useRouteContext: route.useRouteContext,
437
+ useSearch: route.useSearch,
438
+ useParams: route.useParams
439
+ });
440
+ }
441
+ if (match.status === 'success') {
442
+ let comp = route.options.component ?? router.options.defaultComponent;
443
+ if (comp) {
444
+ return /*#__PURE__*/React__namespace.createElement(comp, {
445
+ useLoader: route.useLoader,
446
+ useMatch: route.useMatch,
447
+ useContext: route.useContext,
448
+ useRouteContext: route.useRouteContext,
449
+ useSearch: route.useSearch,
450
+ useParams: route.useParams
451
+ });
452
+ }
453
+ return /*#__PURE__*/React__namespace.createElement(Outlet, null);
454
+ }
455
+ invariant__default["default"](false, 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!');
456
+ }
457
+ function SafeFragment(props) {
458
+ return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, props.children);
459
+ }
460
+ function useInjectHtml() {
461
+ const router = useRouter();
462
+ return React__namespace.useCallback(html => {
463
+ router.injectHtml(html);
464
+ }, []);
465
+ }
466
+ function useDehydrate() {
467
+ const router = useRouter();
468
+ return React__namespace.useCallback(function dehydrate(key, data) {
469
+ return router.dehydrateData(key, data);
470
+ }, []);
471
+ }
472
+ function useHydrate() {
473
+ const router = useRouter();
474
+ return function hydrate(key) {
475
+ return router.hydrateData(key);
476
+ };
477
+ }
478
+
479
+ // This is the messiest thing ever... I'm either seriously tired (likely) or
480
+ // there has to be a better way to reset error boundaries when the
481
+ // router's location key changes.
482
+
483
+ class CatchBoundary extends React__namespace.Component {
484
+ state = {
485
+ error: false,
486
+ info: undefined
487
+ };
488
+ componentDidCatch(error, info) {
489
+ this.props.onCatch(error, info);
490
+ this.setState({
491
+ error,
492
+ info
493
+ });
494
+ }
495
+ render() {
496
+ return /*#__PURE__*/React__namespace.createElement(CatchBoundaryInner, _rollupPluginBabelHelpers["extends"]({}, this.props, {
497
+ errorState: this.state,
498
+ reset: () => this.setState({})
499
+ }));
500
+ }
501
+ }
502
+ function CatchBoundaryInner(props) {
503
+ const locationKey = useRouterState({
504
+ select: d => d.resolvedLocation.key
505
+ });
506
+ const [activeErrorState, setActiveErrorState] = React__namespace.useState(props.errorState);
507
+ const errorComponent = props.errorComponent ?? ErrorComponent;
508
+ const prevKeyRef = React__namespace.useRef('');
509
+ React__namespace.useEffect(() => {
510
+ if (activeErrorState) {
511
+ if (locationKey !== prevKeyRef.current) {
512
+ setActiveErrorState({});
513
+ }
514
+ }
515
+ prevKeyRef.current = locationKey;
516
+ }, [activeErrorState, locationKey]);
517
+ React__namespace.useEffect(() => {
518
+ if (props.errorState.error) {
519
+ setActiveErrorState(props.errorState);
520
+ }
521
+ // props.reset()
522
+ }, [props.errorState.error]);
523
+ if (props.errorState.error && activeErrorState.error) {
524
+ return /*#__PURE__*/React__namespace.createElement(errorComponent, activeErrorState);
525
+ }
526
+ return props.children;
527
+ }
528
+ function ErrorComponent({
529
+ error
530
+ }) {
531
+ const [show, setShow] = React__namespace.useState(process.env.NODE_ENV !== 'production');
532
+ return /*#__PURE__*/React__namespace.createElement("div", {
533
+ style: {
534
+ padding: '.5rem',
535
+ maxWidth: '100%'
536
+ }
537
+ }, /*#__PURE__*/React__namespace.createElement("div", {
538
+ style: {
539
+ display: 'flex',
540
+ alignItems: 'center',
541
+ gap: '.5rem'
542
+ }
543
+ }, /*#__PURE__*/React__namespace.createElement("strong", {
544
+ style: {
545
+ fontSize: '1rem'
546
+ }
547
+ }, "Something went wrong!"), /*#__PURE__*/React__namespace.createElement("button", {
548
+ style: {
549
+ appearance: 'none',
550
+ fontSize: '.6em',
551
+ border: '1px solid currentColor',
552
+ padding: '.1rem .2rem',
553
+ fontWeight: 'bold',
554
+ borderRadius: '.25rem'
555
+ },
556
+ onClick: () => setShow(d => !d)
557
+ }, show ? 'Hide Error' : 'Show Error')), /*#__PURE__*/React__namespace.createElement("div", {
558
+ style: {
559
+ height: '.25rem'
560
+ }
561
+ }), show ? /*#__PURE__*/React__namespace.createElement("div", null, /*#__PURE__*/React__namespace.createElement("pre", {
562
+ style: {
563
+ fontSize: '.7em',
564
+ border: '1px solid red',
565
+ borderRadius: '.25rem',
566
+ padding: '.3rem',
567
+ color: 'red',
568
+ overflow: 'auto'
569
+ }
570
+ }, error.message ? /*#__PURE__*/React__namespace.createElement("code", null, error.message) : null)) : null);
571
+ }
572
+ function useBlocker(message, condition = true) {
573
+ const router = useRouter();
574
+ React__namespace.useEffect(() => {
575
+ if (!condition) return;
576
+ let unblock = router.history.block((retry, cancel) => {
577
+ if (window.confirm(message)) {
578
+ unblock();
579
+ retry();
580
+ }
581
+ });
582
+ return unblock;
583
+ });
584
+ }
585
+ function Block({
586
+ message,
587
+ condition,
588
+ children
589
+ }) {
590
+ useBlocker(message, condition);
591
+ return children ?? null;
592
+ }
593
+ function shallow(objA, objB) {
594
+ if (Object.is(objA, objB)) {
595
+ return true;
596
+ }
597
+ if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
598
+ return false;
599
+ }
600
+ const keysA = Object.keys(objA);
601
+ if (keysA.length !== Object.keys(objB).length) {
602
+ return false;
603
+ }
604
+ for (let i = 0; i < keysA.length; i++) {
605
+ if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
606
+ return false;
607
+ }
608
+ }
609
+ return true;
610
+ }
611
+
612
+ Object.defineProperty(exports, 'useStore', {
613
+ enumerable: true,
614
+ get: function () { return reactStore.useStore; }
615
+ });
616
+ exports.Block = Block;
617
+ exports.ErrorComponent = ErrorComponent;
618
+ exports.Link = Link;
619
+ exports.MatchRoute = MatchRoute;
620
+ exports.Navigate = Navigate;
621
+ exports.Outlet = Outlet;
622
+ exports.RouterProvider = RouterProvider;
623
+ exports.lazyRouteComponent = lazyRouteComponent;
624
+ exports.matchIdsContext = matchIdsContext;
625
+ exports.routerContext = routerContext;
626
+ exports.shallow = shallow;
627
+ exports.useBlocker = useBlocker;
628
+ exports.useDehydrate = useDehydrate;
629
+ exports.useHydrate = useHydrate;
630
+ exports.useInjectHtml = useInjectHtml;
631
+ exports.useLinkProps = useLinkProps;
632
+ exports.useLoader = useLoader;
633
+ exports.useMatch = useMatch;
634
+ exports.useMatchRoute = useMatchRoute;
635
+ exports.useMatches = useMatches;
636
+ exports.useNavigate = useNavigate;
637
+ exports.useParams = useParams;
638
+ exports.useRouteContext = useRouteContext;
639
+ exports.useRouter = useRouter;
640
+ exports.useRouterContext = useRouterContext;
641
+ exports.useRouterState = useRouterState;
642
+ exports.useSearch = useSearch;
643
+ Object.keys(routerCore).forEach(function (k) {
644
+ if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
645
+ enumerable: true,
646
+ get: function () { return routerCore[k]; }
647
+ });
648
+ });
649
+ //# sourceMappingURL=index.js.map