@tanstack/react-router 0.0.1-beta.9 → 1.0.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/LICENSE +21 -0
- package/build/cjs/CatchBoundary.js +128 -0
- package/build/cjs/CatchBoundary.js.map +1 -0
- package/build/cjs/Matches.js +233 -0
- package/build/cjs/Matches.js.map +1 -0
- package/build/cjs/RouterProvider.js +170 -0
- package/build/cjs/RouterProvider.js.map +1 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +2 -22
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/cjs/_virtual/with-selector.development.js +16 -0
- package/build/cjs/_virtual/with-selector.development.js.map +1 -0
- package/build/cjs/_virtual/with-selector.js +16 -0
- package/build/cjs/_virtual/with-selector.js.map +1 -0
- package/build/cjs/_virtual/with-selector.production.min.js +16 -0
- package/build/cjs/_virtual/with-selector.production.min.js.map +1 -0
- package/build/cjs/awaited.js +43 -0
- package/build/cjs/awaited.js.map +1 -0
- package/build/cjs/build/esm/index.js +79 -0
- package/build/cjs/build/esm/index.js.map +1 -0
- package/build/cjs/defer.js +37 -0
- package/build/cjs/defer.js.map +1 -0
- package/build/cjs/fileRoute.js +27 -0
- package/build/cjs/fileRoute.js.map +1 -0
- package/build/cjs/index.js +130 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/lazyRouteComponent.js +54 -0
- package/build/cjs/lazyRouteComponent.js.map +1 -0
- package/build/cjs/link.js +223 -0
- package/build/cjs/link.js.map +1 -0
- package/build/cjs/node_modules/.pnpm/@tanstack_react-store@0.2.1_react-dom@18.2.0_react@18.2.0/node_modules/@tanstack/react-store/build/modern/index.js +47 -0
- package/build/cjs/node_modules/.pnpm/@tanstack_react-store@0.2.1_react-dom@18.2.0_react@18.2.0/node_modules/@tanstack/react-store/build/modern/index.js.map +1 -0
- package/build/cjs/node_modules/.pnpm/@tanstack_store@0.1.3/node_modules/@tanstack/store/build/modern/index.js +70 -0
- package/build/cjs/node_modules/.pnpm/@tanstack_store@0.1.3/node_modules/@tanstack/store/build/modern/index.js.map +1 -0
- package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +188 -0
- package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -0
- package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +39 -0
- package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -0
- package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/shim/with-selector.js +26 -0
- package/build/cjs/node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/shim/with-selector.js.map +1 -0
- package/build/cjs/packages/react-router/src/CatchBoundary.js +123 -0
- package/build/cjs/packages/react-router/src/CatchBoundary.js.map +1 -0
- package/build/cjs/packages/react-router/src/Matches.js +235 -0
- package/build/cjs/packages/react-router/src/Matches.js.map +1 -0
- package/build/cjs/packages/react-router/src/RouterProvider.js +144 -0
- package/build/cjs/packages/react-router/src/RouterProvider.js.map +1 -0
- package/build/cjs/packages/react-router/src/awaited.js +43 -0
- package/build/cjs/packages/react-router/src/awaited.js.map +1 -0
- package/build/cjs/packages/react-router/src/defer.js +37 -0
- package/build/cjs/packages/react-router/src/defer.js.map +1 -0
- package/build/cjs/packages/react-router/src/fileRoute.js +27 -0
- package/build/cjs/packages/react-router/src/fileRoute.js.map +1 -0
- package/build/cjs/packages/react-router/src/index.js +61 -0
- package/build/cjs/packages/react-router/src/index.js.map +1 -0
- package/build/cjs/packages/react-router/src/lazyRouteComponent.js +54 -0
- package/build/cjs/packages/react-router/src/lazyRouteComponent.js.map +1 -0
- package/build/cjs/packages/react-router/src/link.js +148 -0
- package/build/cjs/packages/react-router/src/link.js.map +1 -0
- package/build/cjs/packages/react-router/src/path.js +209 -0
- package/build/cjs/packages/react-router/src/path.js.map +1 -0
- package/build/cjs/packages/react-router/src/qss.js +63 -0
- package/build/cjs/packages/react-router/src/qss.js.map +1 -0
- package/build/cjs/packages/react-router/src/react.js +634 -0
- package/build/cjs/packages/react-router/src/react.js.map +1 -0
- package/build/cjs/packages/react-router/src/redirects.js +25 -0
- package/build/cjs/packages/react-router/src/redirects.js.map +1 -0
- package/build/cjs/packages/react-router/src/route.js +134 -0
- package/build/cjs/packages/react-router/src/route.js.map +1 -0
- package/build/cjs/packages/react-router/src/router.js +1111 -0
- package/build/cjs/packages/react-router/src/router.js.map +1 -0
- package/build/cjs/packages/react-router/src/scroll-restoration.js +53 -0
- package/build/cjs/packages/react-router/src/scroll-restoration.js.map +1 -0
- package/build/cjs/packages/react-router/src/searchParams.js +81 -0
- package/build/cjs/packages/react-router/src/searchParams.js.map +1 -0
- package/build/cjs/packages/react-router/src/useBlocker.js +61 -0
- package/build/cjs/packages/react-router/src/useBlocker.js.map +1 -0
- package/build/cjs/packages/react-router/src/useNavigate.js +75 -0
- package/build/cjs/packages/react-router/src/useNavigate.js.map +1 -0
- package/build/cjs/packages/react-router/src/useParams.js +26 -0
- package/build/cjs/packages/react-router/src/useParams.js.map +1 -0
- package/build/cjs/packages/react-router/src/useSearch.js +25 -0
- package/build/cjs/packages/react-router/src/useSearch.js.map +1 -0
- package/build/cjs/packages/react-router/src/utils.js +239 -0
- package/build/cjs/packages/react-router/src/utils.js.map +1 -0
- package/build/cjs/path.js +214 -0
- package/build/cjs/path.js.map +1 -0
- package/build/cjs/qss.js +63 -0
- package/build/cjs/qss.js.map +1 -0
- package/build/cjs/react/CatchBoundary.js +123 -0
- package/build/cjs/react/CatchBoundary.js.map +1 -0
- package/build/cjs/react/awaited.js +43 -0
- package/build/cjs/react/awaited.js.map +1 -0
- package/build/cjs/react/defer.js +37 -0
- package/build/cjs/react/defer.js.map +1 -0
- package/build/cjs/react.js +650 -0
- package/build/cjs/react.js.map +1 -0
- package/build/cjs/redirects.js +28 -0
- package/build/cjs/redirects.js.map +1 -0
- package/build/cjs/route.js +191 -0
- package/build/cjs/route.js.map +1 -0
- package/build/cjs/router.js +1085 -0
- package/build/cjs/router.js.map +1 -0
- package/build/cjs/routerConfig.js +209 -0
- package/build/cjs/routerConfig.js.map +1 -0
- package/build/cjs/scroll-restoration.js +202 -0
- package/build/cjs/scroll-restoration.js.map +1 -0
- package/build/cjs/searchParams.js +81 -0
- package/build/cjs/searchParams.js.map +1 -0
- package/build/cjs/src/CatchBoundary.js +126 -0
- package/build/cjs/src/CatchBoundary.js.map +1 -0
- package/build/cjs/src/Matches.js +235 -0
- package/build/cjs/src/Matches.js.map +1 -0
- package/build/cjs/src/RouterProvider.js +1051 -0
- package/build/cjs/src/RouterProvider.js.map +1 -0
- package/build/cjs/src/awaited.js +45 -0
- package/build/cjs/src/awaited.js.map +1 -0
- package/build/cjs/src/defer.js +39 -0
- package/build/cjs/src/defer.js.map +1 -0
- package/build/cjs/src/fileRoute.js +29 -0
- package/build/cjs/src/fileRoute.js.map +1 -0
- package/build/cjs/src/index.js +134 -0
- package/build/cjs/src/index.js.map +1 -0
- package/build/cjs/src/lazyRouteComponent.js +57 -0
- package/build/cjs/src/lazyRouteComponent.js.map +1 -0
- package/build/cjs/src/link.js +151 -0
- package/build/cjs/src/link.js.map +1 -0
- package/build/cjs/src/path.js +211 -0
- package/build/cjs/src/path.js.map +1 -0
- package/build/cjs/src/qss.js +65 -0
- package/build/cjs/src/qss.js.map +1 -0
- package/build/cjs/src/redirects.js +27 -0
- package/build/cjs/src/redirects.js.map +1 -0
- package/build/cjs/src/route.js +139 -0
- package/build/cjs/src/route.js.map +1 -0
- package/build/cjs/src/router.js +203 -0
- package/build/cjs/src/router.js.map +1 -0
- package/build/cjs/src/scroll-restoration.js +186 -0
- package/build/cjs/src/scroll-restoration.js.map +1 -0
- package/build/cjs/src/searchParams.js +83 -0
- package/build/cjs/src/searchParams.js.map +1 -0
- package/build/cjs/src/useBlocker.js +64 -0
- package/build/cjs/src/useBlocker.js.map +1 -0
- package/build/cjs/src/useNavigate.js +78 -0
- package/build/cjs/src/useNavigate.js.map +1 -0
- package/build/cjs/src/useParams.js +28 -0
- package/build/cjs/src/useParams.js.map +1 -0
- package/build/cjs/src/useSearch.js +27 -0
- package/build/cjs/src/useSearch.js.map +1 -0
- package/build/cjs/src/utils.js +230 -0
- package/build/cjs/src/utils.js.map +1 -0
- package/build/cjs/useBlocker.js +55 -0
- package/build/cjs/useBlocker.js.map +1 -0
- package/build/cjs/useNavigate.js +86 -0
- package/build/cjs/useNavigate.js.map +1 -0
- package/build/cjs/useParams.js +26 -0
- package/build/cjs/useParams.js.map +1 -0
- package/build/cjs/useSearch.js +25 -0
- package/build/cjs/useSearch.js.map +1 -0
- package/build/cjs/useStore.js +99 -0
- package/build/cjs/useStore.js.map +1 -0
- package/build/cjs/utils.js +241 -0
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +2300 -2534
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +3498 -2694
- package/build/stats-react.json +1204 -44
- package/build/types/CatchBoundary.d.ts +36 -0
- package/build/types/Matches.d.ts +64 -0
- package/build/types/RouteMatch.d.ts +23 -0
- package/build/types/RouterProvider.d.ts +35 -0
- package/build/types/awaited.d.ts +9 -0
- package/build/types/defer.d.ts +19 -0
- package/build/types/fileRoute.d.ts +38 -0
- package/build/types/history.d.ts +7 -0
- package/build/types/index.d.ts +919 -58
- package/build/types/injectHtml.d.ts +0 -0
- package/build/types/lazyRouteComponent.d.ts +2 -0
- package/build/types/link.d.ts +93 -0
- package/build/types/location.d.ts +12 -0
- package/build/types/path.d.ts +17 -0
- package/build/types/qss.d.ts +2 -0
- package/build/types/react/CatchBoundary.d.ts +33 -0
- package/build/types/react/awaited.d.ts +9 -0
- package/build/types/react/defer.d.ts +19 -0
- package/build/types/react.d.ts +141 -0
- package/build/types/redirects.d.ts +11 -0
- package/build/types/route.d.ts +283 -0
- package/build/types/routeInfo.d.ts +31 -0
- package/build/types/router.d.ts +186 -0
- package/build/types/scroll-restoration.d.ts +18 -0
- package/build/types/searchParams.d.ts +7 -0
- package/build/types/useBlocker.d.ts +9 -0
- package/build/types/useNavigate.d.ts +19 -0
- package/build/types/useParams.d.ts +7 -0
- package/build/types/useSearch.d.ts +7 -0
- package/build/types/useStore.d.ts +12 -0
- package/build/types/utils.d.ts +69 -0
- package/build/umd/index.development.js +2897 -2493
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +4 -4
- package/build/umd/index.production.js.map +1 -1
- package/package.json +12 -10
- package/src/CatchBoundary.tsx +101 -0
- package/src/Matches.tsx +423 -0
- package/src/RouterProvider.tsx +252 -0
- package/src/awaited.tsx +40 -0
- package/src/defer.ts +55 -0
- package/src/fileRoute.ts +152 -0
- package/src/history.ts +8 -0
- package/src/index.tsx +28 -619
- package/src/lazyRouteComponent.tsx +33 -0
- package/src/link.tsx +603 -0
- package/src/location.ts +13 -0
- package/src/path.ts +261 -0
- package/src/qss.ts +53 -0
- package/src/redirects.ts +39 -0
- package/src/route.ts +882 -0
- package/src/routeInfo.ts +84 -0
- package/src/router.ts +1671 -0
- package/src/scroll-restoration.tsx +230 -0
- package/src/searchParams.ts +79 -0
- package/src/useBlocker.tsx +27 -0
- package/src/useNavigate.tsx +111 -0
- package/src/useParams.tsx +25 -0
- package/src/useSearch.tsx +25 -0
- package/src/utils.ts +360 -0
- package/build/cjs/react-router/src/index.js +0 -458
- package/build/cjs/react-router/src/index.js.map +0 -1
- package/build/cjs/router-core/build/esm/index.js +0 -2524
- package/build/cjs/router-core/build/esm/index.js.map +0 -1
|
@@ -0,0 +1,634 @@
|
|
|
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
|
+
var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
|
|
14
|
+
var React = require('react');
|
|
15
|
+
var index = require('../../../node_modules/.pnpm/@tanstack_react-store@0.2.1_react-dom@18.2.0_react@18.2.0/node_modules/@tanstack/react-store/build/modern/index.js');
|
|
16
|
+
var invariant = require('tiny-invariant');
|
|
17
|
+
var warning = require('tiny-warning');
|
|
18
|
+
var routerCore = require('@tanstack/router-core');
|
|
19
|
+
|
|
20
|
+
function _interopNamespaceDefault(e) {
|
|
21
|
+
var n = Object.create(null);
|
|
22
|
+
if (e) {
|
|
23
|
+
Object.keys(e).forEach(function (k) {
|
|
24
|
+
if (k !== 'default') {
|
|
25
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
26
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () { return e[k]; }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
n.default = e;
|
|
34
|
+
return Object.freeze(n);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
38
|
+
|
|
39
|
+
routerCore.Route.__onInit = route => {
|
|
40
|
+
Object.assign(route, {
|
|
41
|
+
useMatch: (opts = {}) => {
|
|
42
|
+
return useMatch({
|
|
43
|
+
...opts,
|
|
44
|
+
from: route.id
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
useLoader: (opts = {}) => {
|
|
48
|
+
return useLoader({
|
|
49
|
+
...opts,
|
|
50
|
+
from: route.id
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
useRouteContext: (opts = {}) => {
|
|
54
|
+
return useMatch({
|
|
55
|
+
...opts,
|
|
56
|
+
from: route.id,
|
|
57
|
+
select: d => opts?.select ? opts.select(d.context) : d.context
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
useSearch: (opts = {}) => {
|
|
61
|
+
return useSearch({
|
|
62
|
+
...opts,
|
|
63
|
+
from: route.id
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
useParams: (opts = {}) => {
|
|
67
|
+
return useParams({
|
|
68
|
+
...opts,
|
|
69
|
+
from: route.id
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
//
|
|
76
|
+
|
|
77
|
+
function lazyRouteComponent(importer, exportName) {
|
|
78
|
+
let loadPromise;
|
|
79
|
+
const load = () => {
|
|
80
|
+
if (!loadPromise) {
|
|
81
|
+
loadPromise = importer();
|
|
82
|
+
}
|
|
83
|
+
return loadPromise;
|
|
84
|
+
};
|
|
85
|
+
const lazyComp = /*#__PURE__*/React__namespace.lazy(async () => {
|
|
86
|
+
const moduleExports = await load();
|
|
87
|
+
const comp = moduleExports[exportName ?? 'default'];
|
|
88
|
+
return {
|
|
89
|
+
default: comp
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
lazyComp.preload = load;
|
|
93
|
+
return lazyComp;
|
|
94
|
+
}
|
|
95
|
+
//
|
|
96
|
+
|
|
97
|
+
function useLinkProps(options) {
|
|
98
|
+
const router = useRouter();
|
|
99
|
+
const {
|
|
100
|
+
// custom props
|
|
101
|
+
type,
|
|
102
|
+
children,
|
|
103
|
+
target,
|
|
104
|
+
activeProps = () => ({
|
|
105
|
+
className: 'active'
|
|
106
|
+
}),
|
|
107
|
+
inactiveProps = () => ({}),
|
|
108
|
+
activeOptions,
|
|
109
|
+
disabled,
|
|
110
|
+
// fromCurrent,
|
|
111
|
+
hash,
|
|
112
|
+
search,
|
|
113
|
+
params,
|
|
114
|
+
to = '.',
|
|
115
|
+
state,
|
|
116
|
+
mask,
|
|
117
|
+
preload,
|
|
118
|
+
preloadDelay,
|
|
119
|
+
replace,
|
|
120
|
+
// element props
|
|
121
|
+
style,
|
|
122
|
+
className,
|
|
123
|
+
onClick,
|
|
124
|
+
onFocus,
|
|
125
|
+
onMouseEnter,
|
|
126
|
+
onMouseLeave,
|
|
127
|
+
onTouchStart,
|
|
128
|
+
...rest
|
|
129
|
+
} = options;
|
|
130
|
+
const linkInfo = router.buildLink(options);
|
|
131
|
+
if (linkInfo.type === 'external') {
|
|
132
|
+
const {
|
|
133
|
+
href
|
|
134
|
+
} = linkInfo;
|
|
135
|
+
return {
|
|
136
|
+
href
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const {
|
|
140
|
+
handleClick,
|
|
141
|
+
handleFocus,
|
|
142
|
+
handleEnter,
|
|
143
|
+
handleLeave,
|
|
144
|
+
handleTouchStart,
|
|
145
|
+
isActive,
|
|
146
|
+
next
|
|
147
|
+
} = linkInfo;
|
|
148
|
+
const handleReactClick = e => {
|
|
149
|
+
if (options.startTransition ?? true) {
|
|
150
|
+
(React__namespace.startTransition || (d => d))(() => {
|
|
151
|
+
handleClick(e);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const composeHandlers = handlers => e => {
|
|
156
|
+
if (e.persist) e.persist();
|
|
157
|
+
handlers.filter(Boolean).forEach(handler => {
|
|
158
|
+
if (e.defaultPrevented) return;
|
|
159
|
+
handler(e);
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// Get the active props
|
|
164
|
+
const resolvedActiveProps = isActive ? routerCore.functionalUpdate(activeProps, {}) ?? {} : {};
|
|
165
|
+
|
|
166
|
+
// Get the inactive props
|
|
167
|
+
const resolvedInactiveProps = isActive ? {} : routerCore.functionalUpdate(inactiveProps, {}) ?? {};
|
|
168
|
+
return {
|
|
169
|
+
...resolvedActiveProps,
|
|
170
|
+
...resolvedInactiveProps,
|
|
171
|
+
...rest,
|
|
172
|
+
href: disabled ? undefined : next.maskedLocation ? next.maskedLocation.href : next.href,
|
|
173
|
+
onClick: composeHandlers([onClick, handleReactClick]),
|
|
174
|
+
onFocus: composeHandlers([onFocus, handleFocus]),
|
|
175
|
+
onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),
|
|
176
|
+
onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),
|
|
177
|
+
onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),
|
|
178
|
+
target,
|
|
179
|
+
style: {
|
|
180
|
+
...style,
|
|
181
|
+
...resolvedActiveProps.style,
|
|
182
|
+
...resolvedInactiveProps.style
|
|
183
|
+
},
|
|
184
|
+
className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined,
|
|
185
|
+
...(disabled ? {
|
|
186
|
+
role: 'link',
|
|
187
|
+
'aria-disabled': true
|
|
188
|
+
} : undefined),
|
|
189
|
+
['data-status']: isActive ? 'active' : undefined
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
const Link = /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
|
|
193
|
+
const linkProps = useLinkProps(props);
|
|
194
|
+
return /*#__PURE__*/React__namespace.createElement("a", _rollupPluginBabelHelpers.extends({
|
|
195
|
+
ref: ref
|
|
196
|
+
}, linkProps, {
|
|
197
|
+
children: typeof props.children === 'function' ? props.children({
|
|
198
|
+
isActive: linkProps['data-status'] === 'active'
|
|
199
|
+
}) : props.children
|
|
200
|
+
}));
|
|
201
|
+
});
|
|
202
|
+
function Navigate(props) {
|
|
203
|
+
const router = useRouter();
|
|
204
|
+
React__namespace.useLayoutEffect(() => {
|
|
205
|
+
router.navigate(props);
|
|
206
|
+
}, []);
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
const matchIdsContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
210
|
+
const routerContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
211
|
+
function useRouterState(opts) {
|
|
212
|
+
const router = useRouter();
|
|
213
|
+
return index.useStore(router.__store, opts?.select);
|
|
214
|
+
}
|
|
215
|
+
function RouterProvider({
|
|
216
|
+
router,
|
|
217
|
+
...rest
|
|
218
|
+
}) {
|
|
219
|
+
router.update(rest);
|
|
220
|
+
React__namespace.useEffect(() => {
|
|
221
|
+
let unsub;
|
|
222
|
+
React__namespace.startTransition(() => {
|
|
223
|
+
unsub = router.mount();
|
|
224
|
+
});
|
|
225
|
+
return unsub;
|
|
226
|
+
}, [router]);
|
|
227
|
+
const Wrap = router.options.Wrap || React__namespace.Fragment;
|
|
228
|
+
return /*#__PURE__*/React__namespace.createElement(Wrap, null, /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
|
|
229
|
+
value: router
|
|
230
|
+
}, /*#__PURE__*/React__namespace.createElement(Matches, null)));
|
|
231
|
+
}
|
|
232
|
+
function Matches() {
|
|
233
|
+
const router = useRouter();
|
|
234
|
+
const matchIds = useRouterState({
|
|
235
|
+
select: state => {
|
|
236
|
+
return state.renderedMatchIds;
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
const locationKey = useRouterState({
|
|
240
|
+
select: d => d.resolvedLocation.state?.key
|
|
241
|
+
});
|
|
242
|
+
const route = router.getRoute(routerCore.rootRouteId);
|
|
243
|
+
const errorComponent = React__namespace.useCallback(props => {
|
|
244
|
+
return /*#__PURE__*/React__namespace.createElement(ErrorComponent, {
|
|
245
|
+
...props,
|
|
246
|
+
useMatch: route.useMatch,
|
|
247
|
+
useRouteContext: route.useRouteContext,
|
|
248
|
+
useSearch: route.useSearch,
|
|
249
|
+
useParams: route.useParams
|
|
250
|
+
});
|
|
251
|
+
}, [route]);
|
|
252
|
+
return /*#__PURE__*/React__namespace.createElement(matchIdsContext.Provider, {
|
|
253
|
+
value: [undefined, ...matchIds]
|
|
254
|
+
}, /*#__PURE__*/React__namespace.createElement(CatchBoundary, {
|
|
255
|
+
resetKey: locationKey,
|
|
256
|
+
errorComponent: errorComponent,
|
|
257
|
+
onCatch: () => {
|
|
258
|
+
warning(false, `Error in router! Consider setting an 'errorComponent' in your RootRoute! 👍`);
|
|
259
|
+
}
|
|
260
|
+
}, /*#__PURE__*/React__namespace.createElement(Outlet, null)));
|
|
261
|
+
}
|
|
262
|
+
function useRouter() {
|
|
263
|
+
const value = React__namespace.useContext(routerContext);
|
|
264
|
+
warning(value, 'useRouter must be used inside a <Router> component!');
|
|
265
|
+
return value;
|
|
266
|
+
}
|
|
267
|
+
function useMatches(opts) {
|
|
268
|
+
const matchIds = React__namespace.useContext(matchIdsContext);
|
|
269
|
+
return useRouterState({
|
|
270
|
+
select: state => {
|
|
271
|
+
const matches = state.renderedMatches.slice(state.renderedMatches.findIndex(d => d.id === matchIds[0]));
|
|
272
|
+
return opts?.select ? opts.select(matches) : matches;
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
function useMatch(opts) {
|
|
277
|
+
const router = useRouter();
|
|
278
|
+
const nearestMatchId = React__namespace.useContext(matchIdsContext)[0];
|
|
279
|
+
const nearestMatchRouteId = router.getRouteMatch(nearestMatchId)?.routeId;
|
|
280
|
+
const matchRouteId = useRouterState({
|
|
281
|
+
select: state => {
|
|
282
|
+
const match = opts?.from ? state.renderedMatches.find(d => d.routeId === opts?.from) : state.renderedMatches.find(d => d.id === nearestMatchId);
|
|
283
|
+
return match.routeId;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
if (opts?.strict ?? true) {
|
|
287
|
+
invariant(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?`);
|
|
288
|
+
}
|
|
289
|
+
const matchSelection = useRouterState({
|
|
290
|
+
select: state => {
|
|
291
|
+
const match = opts?.from ? state.renderedMatches.find(d => d.routeId === opts?.from) : state.renderedMatches.find(d => d.id === nearestMatchId);
|
|
292
|
+
invariant(match, `Could not find ${opts?.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
|
|
293
|
+
return opts?.select ? opts.select(match) : match;
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
return matchSelection;
|
|
297
|
+
}
|
|
298
|
+
function useLoader(opts) {
|
|
299
|
+
return useMatch({
|
|
300
|
+
...opts,
|
|
301
|
+
select: match => opts?.select ? opts?.select(match.loaderData) : match.loaderData
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
function useRouterContext(opts) {
|
|
305
|
+
return useMatch({
|
|
306
|
+
...opts,
|
|
307
|
+
select: match => opts?.select ? opts.select(match.context) : match.context
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
function useRouteContext(opts) {
|
|
311
|
+
return useMatch({
|
|
312
|
+
...opts,
|
|
313
|
+
select: match => opts?.select ? opts.select(match.context) : match.context
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
function useSearch(opts) {
|
|
317
|
+
return useMatch({
|
|
318
|
+
...opts,
|
|
319
|
+
select: match => {
|
|
320
|
+
return opts?.select ? opts.select(match.search) : match.search;
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
function useParams(opts) {
|
|
325
|
+
return useRouterState({
|
|
326
|
+
select: state => {
|
|
327
|
+
const params = routerCore.last(state.renderedMatches)?.params;
|
|
328
|
+
return opts?.select ? opts.select(params) : params;
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
function useNavigate(defaultOpts) {
|
|
333
|
+
const router = useRouter();
|
|
334
|
+
return React__namespace.useCallback(opts => {
|
|
335
|
+
return router.navigate({
|
|
336
|
+
...defaultOpts,
|
|
337
|
+
...opts
|
|
338
|
+
});
|
|
339
|
+
}, []);
|
|
340
|
+
}
|
|
341
|
+
function useMatchRoute() {
|
|
342
|
+
const router = useRouter();
|
|
343
|
+
return React__namespace.useCallback(opts => {
|
|
344
|
+
const {
|
|
345
|
+
pending,
|
|
346
|
+
caseSensitive,
|
|
347
|
+
...rest
|
|
348
|
+
} = opts;
|
|
349
|
+
return router.matchRoute(rest, {
|
|
350
|
+
pending,
|
|
351
|
+
caseSensitive
|
|
352
|
+
});
|
|
353
|
+
}, []);
|
|
354
|
+
}
|
|
355
|
+
function MatchRoute(props) {
|
|
356
|
+
const matchRoute = useMatchRoute();
|
|
357
|
+
const params = matchRoute(props);
|
|
358
|
+
if (typeof props.children === 'function') {
|
|
359
|
+
return props.children(params);
|
|
360
|
+
}
|
|
361
|
+
return !!params ? props.children : null;
|
|
362
|
+
}
|
|
363
|
+
function Outlet() {
|
|
364
|
+
const matchIds = React__namespace.useContext(matchIdsContext).slice(1);
|
|
365
|
+
if (!matchIds[0]) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
return /*#__PURE__*/React__namespace.createElement(Match, {
|
|
369
|
+
matchIds: matchIds
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
const defaultPending = () => null;
|
|
373
|
+
function Match({
|
|
374
|
+
matchIds
|
|
375
|
+
}) {
|
|
376
|
+
const router = useRouter();
|
|
377
|
+
const matchId = matchIds[0];
|
|
378
|
+
const routeId = router.getRouteMatch(matchId).routeId;
|
|
379
|
+
const route = router.getRoute(routeId);
|
|
380
|
+
const locationKey = useRouterState({
|
|
381
|
+
select: s => s.resolvedLocation.state?.key
|
|
382
|
+
});
|
|
383
|
+
const PendingComponent = route.options.pendingComponent ?? router.options.defaultPendingComponent ?? defaultPending;
|
|
384
|
+
const routeErrorComponent = route.options.errorComponent ?? router.options.defaultErrorComponent ?? ErrorComponent;
|
|
385
|
+
const ResolvedSuspenseBoundary = route.options.wrapInSuspense ?? !route.isRoot ? React__namespace.Suspense : SafeFragment;
|
|
386
|
+
const ResolvedCatchBoundary = !!routeErrorComponent ? CatchBoundary : SafeFragment;
|
|
387
|
+
const errorComponent = React__namespace.useCallback(props => {
|
|
388
|
+
return /*#__PURE__*/React__namespace.createElement(routeErrorComponent, {
|
|
389
|
+
...props,
|
|
390
|
+
useMatch: route.useMatch,
|
|
391
|
+
useRouteContext: route.useRouteContext,
|
|
392
|
+
useSearch: route.useSearch,
|
|
393
|
+
useParams: route.useParams
|
|
394
|
+
});
|
|
395
|
+
}, [route]);
|
|
396
|
+
return /*#__PURE__*/React__namespace.createElement(matchIdsContext.Provider, {
|
|
397
|
+
value: matchIds
|
|
398
|
+
}, /*#__PURE__*/React__namespace.createElement(ResolvedSuspenseBoundary, {
|
|
399
|
+
fallback: /*#__PURE__*/React__namespace.createElement(PendingComponent, {
|
|
400
|
+
useMatch: route.useMatch,
|
|
401
|
+
useRouteContext: route.useRouteContext,
|
|
402
|
+
useSearch: route.useSearch,
|
|
403
|
+
useParams: route.useParams
|
|
404
|
+
})
|
|
405
|
+
}, /*#__PURE__*/React__namespace.createElement(ResolvedCatchBoundary, {
|
|
406
|
+
resetKey: locationKey,
|
|
407
|
+
errorComponent: errorComponent,
|
|
408
|
+
onCatch: () => {
|
|
409
|
+
warning(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
|
+
useRouteContext: route.useRouteContext,
|
|
436
|
+
useSearch: route.useSearch,
|
|
437
|
+
useParams: route.useParams
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
if (match.status === 'success') {
|
|
441
|
+
let comp = route.options.component ?? router.options.defaultComponent;
|
|
442
|
+
if (comp) {
|
|
443
|
+
return /*#__PURE__*/React__namespace.createElement(comp, {
|
|
444
|
+
useLoader: route.useLoader,
|
|
445
|
+
useMatch: route.useMatch,
|
|
446
|
+
useRouteContext: route.useRouteContext,
|
|
447
|
+
useSearch: route.useSearch,
|
|
448
|
+
useParams: route.useParams
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
return /*#__PURE__*/React__namespace.createElement(Outlet, null);
|
|
452
|
+
}
|
|
453
|
+
invariant(false, 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!');
|
|
454
|
+
}
|
|
455
|
+
function SafeFragment(props) {
|
|
456
|
+
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, props.children);
|
|
457
|
+
}
|
|
458
|
+
function useInjectHtml() {
|
|
459
|
+
const router = useRouter();
|
|
460
|
+
return React__namespace.useCallback(html => {
|
|
461
|
+
router.injectHtml(html);
|
|
462
|
+
}, []);
|
|
463
|
+
}
|
|
464
|
+
function useDehydrate() {
|
|
465
|
+
const router = useRouter();
|
|
466
|
+
return React__namespace.useCallback(function dehydrate(key, data) {
|
|
467
|
+
return router.dehydrateData(key, data);
|
|
468
|
+
}, []);
|
|
469
|
+
}
|
|
470
|
+
function useHydrate() {
|
|
471
|
+
const router = useRouter();
|
|
472
|
+
return function hydrate(key) {
|
|
473
|
+
return router.hydrateData(key);
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// This is the messiest thing ever... I'm either seriously tired (likely) or
|
|
478
|
+
// there has to be a better way to reset error boundaries when the
|
|
479
|
+
// router's location key changes.
|
|
480
|
+
|
|
481
|
+
function CatchBoundary(props) {
|
|
482
|
+
const errorComponent = props.errorComponent ?? ErrorComponent;
|
|
483
|
+
return /*#__PURE__*/React__namespace.createElement(CatchBoundaryImpl, {
|
|
484
|
+
resetKey: props.resetKey,
|
|
485
|
+
onCatch: props.onCatch,
|
|
486
|
+
children: ({
|
|
487
|
+
error
|
|
488
|
+
}) => {
|
|
489
|
+
if (error) {
|
|
490
|
+
return /*#__PURE__*/React__namespace.createElement(errorComponent, {
|
|
491
|
+
error
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
return props.children;
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
class CatchBoundaryImpl extends React__namespace.Component {
|
|
499
|
+
state = {
|
|
500
|
+
error: null
|
|
501
|
+
};
|
|
502
|
+
static getDerivedStateFromError(error) {
|
|
503
|
+
return {
|
|
504
|
+
error
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
componentDidUpdate(prevProps, prevState) {
|
|
508
|
+
if (prevState.error && prevProps.resetKey !== this.props.resetKey) {
|
|
509
|
+
this.setState({
|
|
510
|
+
error: null
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
componentDidCatch(error) {
|
|
515
|
+
this.props.onCatch?.(error);
|
|
516
|
+
}
|
|
517
|
+
render() {
|
|
518
|
+
return this.props.children(this.state);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
function ErrorComponent({
|
|
522
|
+
error
|
|
523
|
+
}) {
|
|
524
|
+
const [show, setShow] = React__namespace.useState(process.env.NODE_ENV !== 'production');
|
|
525
|
+
return /*#__PURE__*/React__namespace.createElement("div", {
|
|
526
|
+
style: {
|
|
527
|
+
padding: '.5rem',
|
|
528
|
+
maxWidth: '100%'
|
|
529
|
+
}
|
|
530
|
+
}, /*#__PURE__*/React__namespace.createElement("div", {
|
|
531
|
+
style: {
|
|
532
|
+
display: 'flex',
|
|
533
|
+
alignItems: 'center',
|
|
534
|
+
gap: '.5rem'
|
|
535
|
+
}
|
|
536
|
+
}, /*#__PURE__*/React__namespace.createElement("strong", {
|
|
537
|
+
style: {
|
|
538
|
+
fontSize: '1rem'
|
|
539
|
+
}
|
|
540
|
+
}, "Something went wrong!"), /*#__PURE__*/React__namespace.createElement("button", {
|
|
541
|
+
style: {
|
|
542
|
+
appearance: 'none',
|
|
543
|
+
fontSize: '.6em',
|
|
544
|
+
border: '1px solid currentColor',
|
|
545
|
+
padding: '.1rem .2rem',
|
|
546
|
+
fontWeight: 'bold',
|
|
547
|
+
borderRadius: '.25rem'
|
|
548
|
+
},
|
|
549
|
+
onClick: () => setShow(d => !d)
|
|
550
|
+
}, show ? 'Hide Error' : 'Show Error')), /*#__PURE__*/React__namespace.createElement("div", {
|
|
551
|
+
style: {
|
|
552
|
+
height: '.25rem'
|
|
553
|
+
}
|
|
554
|
+
}), show ? /*#__PURE__*/React__namespace.createElement("div", null, /*#__PURE__*/React__namespace.createElement("pre", {
|
|
555
|
+
style: {
|
|
556
|
+
fontSize: '.7em',
|
|
557
|
+
border: '1px solid red',
|
|
558
|
+
borderRadius: '.25rem',
|
|
559
|
+
padding: '.3rem',
|
|
560
|
+
color: 'red',
|
|
561
|
+
overflow: 'auto'
|
|
562
|
+
}
|
|
563
|
+
}, error.message ? /*#__PURE__*/React__namespace.createElement("code", null, error.message) : null)) : null);
|
|
564
|
+
}
|
|
565
|
+
function useBlocker(message, condition = true) {
|
|
566
|
+
const router = useRouter();
|
|
567
|
+
React__namespace.useEffect(() => {
|
|
568
|
+
if (!condition) return;
|
|
569
|
+
let unblock = router.history.block((retry, cancel) => {
|
|
570
|
+
if (window.confirm(message)) {
|
|
571
|
+
unblock();
|
|
572
|
+
retry();
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
return unblock;
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
function Block({
|
|
579
|
+
message,
|
|
580
|
+
condition,
|
|
581
|
+
children
|
|
582
|
+
}) {
|
|
583
|
+
useBlocker(message, condition);
|
|
584
|
+
return children ?? null;
|
|
585
|
+
}
|
|
586
|
+
function shallow(objA, objB) {
|
|
587
|
+
if (Object.is(objA, objB)) {
|
|
588
|
+
return true;
|
|
589
|
+
}
|
|
590
|
+
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
591
|
+
return false;
|
|
592
|
+
}
|
|
593
|
+
const keysA = Object.keys(objA);
|
|
594
|
+
if (keysA.length !== Object.keys(objB).length) {
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
598
|
+
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return true;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
exports.Block = Block;
|
|
606
|
+
exports.CatchBoundary = CatchBoundary;
|
|
607
|
+
exports.CatchBoundaryImpl = CatchBoundaryImpl;
|
|
608
|
+
exports.ErrorComponent = ErrorComponent;
|
|
609
|
+
exports.Link = Link;
|
|
610
|
+
exports.MatchRoute = MatchRoute;
|
|
611
|
+
exports.Navigate = Navigate;
|
|
612
|
+
exports.Outlet = Outlet;
|
|
613
|
+
exports.RouterProvider = RouterProvider;
|
|
614
|
+
exports.lazyRouteComponent = lazyRouteComponent;
|
|
615
|
+
exports.matchIdsContext = matchIdsContext;
|
|
616
|
+
exports.routerContext = routerContext;
|
|
617
|
+
exports.shallow = shallow;
|
|
618
|
+
exports.useBlocker = useBlocker;
|
|
619
|
+
exports.useDehydrate = useDehydrate;
|
|
620
|
+
exports.useHydrate = useHydrate;
|
|
621
|
+
exports.useInjectHtml = useInjectHtml;
|
|
622
|
+
exports.useLinkProps = useLinkProps;
|
|
623
|
+
exports.useLoader = useLoader;
|
|
624
|
+
exports.useMatch = useMatch;
|
|
625
|
+
exports.useMatchRoute = useMatchRoute;
|
|
626
|
+
exports.useMatches = useMatches;
|
|
627
|
+
exports.useNavigate = useNavigate;
|
|
628
|
+
exports.useParams = useParams;
|
|
629
|
+
exports.useRouteContext = useRouteContext;
|
|
630
|
+
exports.useRouter = useRouter;
|
|
631
|
+
exports.useRouterContext = useRouterContext;
|
|
632
|
+
exports.useRouterState = useRouterState;
|
|
633
|
+
exports.useSearch = useSearch;
|
|
634
|
+
//# sourceMappingURL=react.js.map
|