react-router 7.9.4 → 7.9.6

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/dist/development/browser-BbBXFHbO.d.ts +310 -0
  3. package/dist/development/browser-C07r42Tt.d.mts +310 -0
  4. package/dist/development/{chunk-OIYGIGL5.mjs → chunk-4WY6JWTD.mjs} +458 -43
  5. package/dist/development/{chunk-DI2QHYMJ.js → chunk-AMVS5XVJ.js} +1314 -138
  6. package/dist/development/{chunk-WY5IRSCW.mjs → chunk-G3INQAYP.mjs} +197 -857
  7. package/dist/development/chunk-O4JVZSOY.js +1310 -0
  8. package/dist/development/chunk-PZWDWJAY.js +188 -0
  9. package/dist/development/dom-export.d.mts +103 -6
  10. package/dist/development/dom-export.d.ts +103 -4
  11. package/dist/development/dom-export.js +708 -20
  12. package/dist/development/dom-export.mjs +692 -11
  13. package/dist/{production/index-react-server-client-BbRcBjrA.d.ts → development/index-react-server-client-Da3kmxNd.d.ts} +195 -135
  14. package/dist/{production/index-react-server-client-BIz4AUNd.d.mts → development/index-react-server-client-rcoGPJhU.d.mts} +137 -78
  15. package/dist/development/index-react-server-client.d.mts +2 -3
  16. package/dist/development/index-react-server-client.d.ts +2 -2
  17. package/dist/development/index-react-server-client.js +4 -4
  18. package/dist/development/index-react-server-client.mjs +2 -2
  19. package/dist/development/index-react-server.d.mts +107 -3
  20. package/dist/development/index-react-server.d.ts +107 -3
  21. package/dist/development/index-react-server.js +259 -13
  22. package/dist/development/index-react-server.mjs +259 -13
  23. package/dist/development/index.d.mts +14 -320
  24. package/dist/development/index.d.ts +14 -362
  25. package/dist/development/index.js +146 -962
  26. package/dist/development/index.mjs +3 -9
  27. package/dist/development/{routeModules-D5iJ6JYT.d.ts → instrumentation-Unc20tLk.d.ts} +178 -25
  28. package/dist/development/lib/types/internal.d.mts +2 -3
  29. package/dist/development/lib/types/internal.d.ts +2 -2
  30. package/dist/development/lib/types/internal.js +1 -1
  31. package/dist/development/lib/types/internal.mjs +1 -1
  32. package/dist/{production/register-C34pU-in.d.ts → development/register-BpU9rFBJ.d.ts} +1 -1
  33. package/dist/development/{register-CI4bTprK.d.mts → register-QkB3HGjm.d.mts} +1 -1
  34. package/dist/{production/context-DSyS5mLj.d.mts → development/router-CAvh_Drx.d.mts} +1877 -1254
  35. package/dist/production/browser-BbBXFHbO.d.ts +310 -0
  36. package/dist/production/browser-C07r42Tt.d.mts +310 -0
  37. package/dist/production/{chunk-4E5LHRQP.js → chunk-EAIF67OW.js} +1314 -138
  38. package/dist/production/{chunk-FR6HSPLK.mjs → chunk-FDUMZGKM.mjs} +197 -857
  39. package/dist/production/{chunk-3TADTUL4.mjs → chunk-FUSXQSWG.mjs} +458 -43
  40. package/dist/production/chunk-G5A35OQU.js +188 -0
  41. package/dist/production/chunk-QN64DHI4.js +1310 -0
  42. package/dist/production/dom-export.d.mts +103 -6
  43. package/dist/production/dom-export.d.ts +103 -4
  44. package/dist/production/dom-export.js +708 -20
  45. package/dist/production/dom-export.mjs +692 -11
  46. package/dist/{development/index-react-server-client-BIz4AUNd.d.mts → production/index-react-server-client-Da3kmxNd.d.ts} +137 -78
  47. package/dist/{development/index-react-server-client-BbRcBjrA.d.ts → production/index-react-server-client-rcoGPJhU.d.mts} +195 -135
  48. package/dist/production/index-react-server-client.d.mts +2 -3
  49. package/dist/production/index-react-server-client.d.ts +2 -2
  50. package/dist/production/index-react-server-client.js +4 -4
  51. package/dist/production/index-react-server-client.mjs +2 -2
  52. package/dist/production/index-react-server.d.mts +107 -3
  53. package/dist/production/index-react-server.d.ts +107 -3
  54. package/dist/production/index-react-server.js +259 -13
  55. package/dist/production/index-react-server.mjs +259 -13
  56. package/dist/production/index.d.mts +14 -320
  57. package/dist/production/index.d.ts +14 -362
  58. package/dist/production/index.js +146 -962
  59. package/dist/production/index.mjs +3 -9
  60. package/dist/production/{routeModules-D5iJ6JYT.d.ts → instrumentation-Unc20tLk.d.ts} +178 -25
  61. package/dist/production/lib/types/internal.d.mts +2 -3
  62. package/dist/production/lib/types/internal.d.ts +2 -2
  63. package/dist/production/lib/types/internal.js +1 -1
  64. package/dist/production/lib/types/internal.mjs +1 -1
  65. package/dist/{development/register-C34pU-in.d.ts → production/register-BpU9rFBJ.d.ts} +1 -1
  66. package/dist/production/{register-CI4bTprK.d.mts → register-QkB3HGjm.d.mts} +1 -1
  67. package/dist/{development/context-DSyS5mLj.d.mts → production/router-CAvh_Drx.d.mts} +1877 -1254
  68. package/package.json +1 -1
  69. package/dist/development/browser-z32v5KVN.d.mts +0 -46
  70. package/dist/development/chunk-72XNTZCV.js +0 -2089
  71. package/dist/development/route-data-DZQOUSqV.d.mts +0 -473
  72. package/dist/production/browser-z32v5KVN.d.mts +0 -46
  73. package/dist/production/chunk-WNLQ53P5.js +0 -2089
  74. package/dist/production/route-data-DZQOUSqV.d.mts +0 -473
@@ -1,2089 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/**
2
- * react-router v7.9.4
3
- *
4
- * Copyright (c) Remix Software Inc.
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
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
- var _chunkDI2QHYMJjs = require('./chunk-DI2QHYMJ.js');
65
-
66
- // lib/components.tsx
67
- var _react = require('react'); var React = _interopRequireWildcard(_react); var React2 = _interopRequireWildcard(_react); var React3 = _interopRequireWildcard(_react);
68
- function mapRouteProperties(route) {
69
- let updates = {
70
- // Note: this check also occurs in createRoutesFromChildren so update
71
- // there if you change this -- please and thank you!
72
- hasErrorBoundary: route.hasErrorBoundary || route.ErrorBoundary != null || route.errorElement != null
73
- };
74
- if (route.Component) {
75
- if (_chunkDI2QHYMJjs.ENABLE_DEV_WARNINGS) {
76
- if (route.element) {
77
- _chunkDI2QHYMJjs.warning.call(void 0,
78
- false,
79
- "You should not include both `Component` and `element` on your route - `Component` will be used."
80
- );
81
- }
82
- }
83
- Object.assign(updates, {
84
- element: React.createElement(route.Component),
85
- Component: void 0
86
- });
87
- }
88
- if (route.HydrateFallback) {
89
- if (_chunkDI2QHYMJjs.ENABLE_DEV_WARNINGS) {
90
- if (route.hydrateFallbackElement) {
91
- _chunkDI2QHYMJjs.warning.call(void 0,
92
- false,
93
- "You should not include both `HydrateFallback` and `hydrateFallbackElement` on your route - `HydrateFallback` will be used."
94
- );
95
- }
96
- }
97
- Object.assign(updates, {
98
- hydrateFallbackElement: React.createElement(route.HydrateFallback),
99
- HydrateFallback: void 0
100
- });
101
- }
102
- if (route.ErrorBoundary) {
103
- if (_chunkDI2QHYMJjs.ENABLE_DEV_WARNINGS) {
104
- if (route.errorElement) {
105
- _chunkDI2QHYMJjs.warning.call(void 0,
106
- false,
107
- "You should not include both `ErrorBoundary` and `errorElement` on your route - `ErrorBoundary` will be used."
108
- );
109
- }
110
- }
111
- Object.assign(updates, {
112
- errorElement: React.createElement(route.ErrorBoundary),
113
- ErrorBoundary: void 0
114
- });
115
- }
116
- return updates;
117
- }
118
- var hydrationRouteProperties = [
119
- "HydrateFallback",
120
- "hydrateFallbackElement"
121
- ];
122
- function createMemoryRouter(routes, opts) {
123
- return _chunkDI2QHYMJjs.createRouter.call(void 0, {
124
- basename: _optionalChain([opts, 'optionalAccess', _2 => _2.basename]),
125
- getContext: _optionalChain([opts, 'optionalAccess', _3 => _3.getContext]),
126
- future: _optionalChain([opts, 'optionalAccess', _4 => _4.future]),
127
- history: _chunkDI2QHYMJjs.createMemoryHistory.call(void 0, {
128
- initialEntries: _optionalChain([opts, 'optionalAccess', _5 => _5.initialEntries]),
129
- initialIndex: _optionalChain([opts, 'optionalAccess', _6 => _6.initialIndex])
130
- }),
131
- hydrationData: _optionalChain([opts, 'optionalAccess', _7 => _7.hydrationData]),
132
- routes,
133
- hydrationRouteProperties,
134
- mapRouteProperties,
135
- dataStrategy: _optionalChain([opts, 'optionalAccess', _8 => _8.dataStrategy]),
136
- patchRoutesOnNavigation: _optionalChain([opts, 'optionalAccess', _9 => _9.patchRoutesOnNavigation])
137
- }).initialize();
138
- }
139
- var Deferred = class {
140
- constructor() {
141
- this.status = "pending";
142
- this.promise = new Promise((resolve, reject) => {
143
- this.resolve = (value) => {
144
- if (this.status === "pending") {
145
- this.status = "resolved";
146
- resolve(value);
147
- }
148
- };
149
- this.reject = (reason) => {
150
- if (this.status === "pending") {
151
- this.status = "rejected";
152
- reject(reason);
153
- }
154
- };
155
- });
156
- }
157
- };
158
- function shallowDiff(a, b) {
159
- if (a === b) {
160
- return false;
161
- }
162
- let aKeys = Object.keys(a);
163
- let bKeys = Object.keys(b);
164
- if (aKeys.length !== bKeys.length) {
165
- return true;
166
- }
167
- for (let key of aKeys) {
168
- if (a[key] !== b[key]) {
169
- return true;
170
- }
171
- }
172
- return false;
173
- }
174
- function UNSTABLE_TransitionEnabledRouterProvider({
175
- router,
176
- flushSync: reactDomFlushSyncImpl,
177
- unstable_onError
178
- }) {
179
- let fetcherData = React.useRef(/* @__PURE__ */ new Map());
180
- let [revalidating, startRevalidation] = React.useTransition();
181
- let [state, setState] = React.useState(router.state);
182
- router.__setPendingRerender = (promise) => startRevalidation(
183
- // @ts-expect-error - need react 19 types for this to be async
184
- async () => {
185
- const rerender = await promise;
186
- startRevalidation(() => {
187
- rerender();
188
- });
189
- }
190
- );
191
- let navigator = React.useMemo(() => {
192
- return {
193
- createHref: router.createHref,
194
- encodeLocation: router.encodeLocation,
195
- go: (n) => router.navigate(n),
196
- push: (to, state2, opts) => router.navigate(to, {
197
- state: state2,
198
- preventScrollReset: _optionalChain([opts, 'optionalAccess', _10 => _10.preventScrollReset])
199
- }),
200
- replace: (to, state2, opts) => router.navigate(to, {
201
- replace: true,
202
- state: state2,
203
- preventScrollReset: _optionalChain([opts, 'optionalAccess', _11 => _11.preventScrollReset])
204
- })
205
- };
206
- }, [router]);
207
- let basename = router.basename || "/";
208
- let dataRouterContext = React.useMemo(
209
- () => ({
210
- router,
211
- navigator,
212
- static: false,
213
- basename,
214
- unstable_onError
215
- }),
216
- [router, navigator, basename, unstable_onError]
217
- );
218
- React.useLayoutEffect(() => {
219
- return router.subscribe(
220
- (newState, { deletedFetchers, flushSync, viewTransitionOpts }) => {
221
- newState.fetchers.forEach((fetcher, key) => {
222
- if (fetcher.data !== void 0) {
223
- fetcherData.current.set(key, fetcher.data);
224
- }
225
- });
226
- deletedFetchers.forEach((key) => fetcherData.current.delete(key));
227
- const diff = shallowDiff(state, newState);
228
- if (!diff) return;
229
- if (flushSync) {
230
- if (reactDomFlushSyncImpl) {
231
- reactDomFlushSyncImpl(() => setState(newState));
232
- } else {
233
- setState(newState);
234
- }
235
- } else {
236
- React.startTransition(() => {
237
- setState(newState);
238
- });
239
- }
240
- }
241
- );
242
- }, [router, reactDomFlushSyncImpl, state]);
243
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(_chunkDI2QHYMJjs.DataRouterContext.Provider, { value: dataRouterContext }, /* @__PURE__ */ React.createElement(
244
- _chunkDI2QHYMJjs.DataRouterStateContext.Provider,
245
- {
246
- value: {
247
- ...state,
248
- revalidation: revalidating ? "loading" : state.revalidation
249
- }
250
- },
251
- /* @__PURE__ */ React.createElement(_chunkDI2QHYMJjs.FetchersContext.Provider, { value: fetcherData.current }, /* @__PURE__ */ React.createElement(
252
- Router,
253
- {
254
- basename,
255
- location: state.location,
256
- navigationType: state.historyAction,
257
- navigator
258
- },
259
- /* @__PURE__ */ React.createElement(
260
- MemoizedDataRoutes,
261
- {
262
- routes: router.routes,
263
- future: router.future,
264
- state,
265
- unstable_onError
266
- }
267
- )
268
- ))
269
- )), null);
270
- }
271
- function RouterProvider({
272
- router,
273
- flushSync: reactDomFlushSyncImpl,
274
- unstable_onError
275
- }) {
276
- let [state, setStateImpl] = React.useState(router.state);
277
- let [pendingState, setPendingState] = React.useState();
278
- let [vtContext, setVtContext] = React.useState({
279
- isTransitioning: false
280
- });
281
- let [renderDfd, setRenderDfd] = React.useState();
282
- let [transition, setTransition] = React.useState();
283
- let [interruption, setInterruption] = React.useState();
284
- let fetcherData = React.useRef(/* @__PURE__ */ new Map());
285
- let logErrorsAndSetState = React.useCallback(
286
- (newState) => {
287
- setStateImpl((prevState) => {
288
- if (newState.errors && unstable_onError) {
289
- Object.entries(newState.errors).forEach(([routeId, error]) => {
290
- if (_optionalChain([prevState, 'access', _12 => _12.errors, 'optionalAccess', _13 => _13[routeId]]) !== error) {
291
- unstable_onError(error);
292
- }
293
- });
294
- }
295
- return newState;
296
- });
297
- },
298
- [unstable_onError]
299
- );
300
- let setState = React.useCallback(
301
- (newState, { deletedFetchers, flushSync, viewTransitionOpts }) => {
302
- newState.fetchers.forEach((fetcher, key) => {
303
- if (fetcher.data !== void 0) {
304
- fetcherData.current.set(key, fetcher.data);
305
- }
306
- });
307
- deletedFetchers.forEach((key) => fetcherData.current.delete(key));
308
- _chunkDI2QHYMJjs.warnOnce.call(void 0,
309
- flushSync === false || reactDomFlushSyncImpl != null,
310
- 'You provided the `flushSync` option to a router update, but you are not using the `<RouterProvider>` from `react-router/dom` so `ReactDOM.flushSync()` is unavailable. Please update your app to `import { RouterProvider } from "react-router/dom"` and ensure you have `react-dom` installed as a dependency to use the `flushSync` option.'
311
- );
312
- let isViewTransitionAvailable = router.window != null && router.window.document != null && typeof router.window.document.startViewTransition === "function";
313
- _chunkDI2QHYMJjs.warnOnce.call(void 0,
314
- viewTransitionOpts == null || isViewTransitionAvailable,
315
- "You provided the `viewTransition` option to a router update, but you do not appear to be running in a DOM environment as `window.startViewTransition` is not available."
316
- );
317
- if (!viewTransitionOpts || !isViewTransitionAvailable) {
318
- if (reactDomFlushSyncImpl && flushSync) {
319
- reactDomFlushSyncImpl(() => logErrorsAndSetState(newState));
320
- } else {
321
- React.startTransition(() => logErrorsAndSetState(newState));
322
- }
323
- return;
324
- }
325
- if (reactDomFlushSyncImpl && flushSync) {
326
- reactDomFlushSyncImpl(() => {
327
- if (transition) {
328
- renderDfd && renderDfd.resolve();
329
- transition.skipTransition();
330
- }
331
- setVtContext({
332
- isTransitioning: true,
333
- flushSync: true,
334
- currentLocation: viewTransitionOpts.currentLocation,
335
- nextLocation: viewTransitionOpts.nextLocation
336
- });
337
- });
338
- let t = router.window.document.startViewTransition(() => {
339
- reactDomFlushSyncImpl(() => logErrorsAndSetState(newState));
340
- });
341
- t.finished.finally(() => {
342
- reactDomFlushSyncImpl(() => {
343
- setRenderDfd(void 0);
344
- setTransition(void 0);
345
- setPendingState(void 0);
346
- setVtContext({ isTransitioning: false });
347
- });
348
- });
349
- reactDomFlushSyncImpl(() => setTransition(t));
350
- return;
351
- }
352
- if (transition) {
353
- renderDfd && renderDfd.resolve();
354
- transition.skipTransition();
355
- setInterruption({
356
- state: newState,
357
- currentLocation: viewTransitionOpts.currentLocation,
358
- nextLocation: viewTransitionOpts.nextLocation
359
- });
360
- } else {
361
- setPendingState(newState);
362
- setVtContext({
363
- isTransitioning: true,
364
- flushSync: false,
365
- currentLocation: viewTransitionOpts.currentLocation,
366
- nextLocation: viewTransitionOpts.nextLocation
367
- });
368
- }
369
- },
370
- [
371
- router.window,
372
- reactDomFlushSyncImpl,
373
- transition,
374
- renderDfd,
375
- logErrorsAndSetState
376
- ]
377
- );
378
- React.useLayoutEffect(() => router.subscribe(setState), [router, setState]);
379
- React.useEffect(() => {
380
- if (vtContext.isTransitioning && !vtContext.flushSync) {
381
- setRenderDfd(new Deferred());
382
- }
383
- }, [vtContext]);
384
- React.useEffect(() => {
385
- if (renderDfd && pendingState && router.window) {
386
- let newState = pendingState;
387
- let renderPromise = renderDfd.promise;
388
- let transition2 = router.window.document.startViewTransition(async () => {
389
- React.startTransition(() => logErrorsAndSetState(newState));
390
- await renderPromise;
391
- });
392
- transition2.finished.finally(() => {
393
- setRenderDfd(void 0);
394
- setTransition(void 0);
395
- setPendingState(void 0);
396
- setVtContext({ isTransitioning: false });
397
- });
398
- setTransition(transition2);
399
- }
400
- }, [pendingState, renderDfd, router.window, logErrorsAndSetState]);
401
- React.useEffect(() => {
402
- if (renderDfd && pendingState && state.location.key === pendingState.location.key) {
403
- renderDfd.resolve();
404
- }
405
- }, [renderDfd, transition, state.location, pendingState]);
406
- React.useEffect(() => {
407
- if (!vtContext.isTransitioning && interruption) {
408
- setPendingState(interruption.state);
409
- setVtContext({
410
- isTransitioning: true,
411
- flushSync: false,
412
- currentLocation: interruption.currentLocation,
413
- nextLocation: interruption.nextLocation
414
- });
415
- setInterruption(void 0);
416
- }
417
- }, [vtContext.isTransitioning, interruption]);
418
- let navigator = React.useMemo(() => {
419
- return {
420
- createHref: router.createHref,
421
- encodeLocation: router.encodeLocation,
422
- go: (n) => router.navigate(n),
423
- push: (to, state2, opts) => router.navigate(to, {
424
- state: state2,
425
- preventScrollReset: _optionalChain([opts, 'optionalAccess', _14 => _14.preventScrollReset])
426
- }),
427
- replace: (to, state2, opts) => router.navigate(to, {
428
- replace: true,
429
- state: state2,
430
- preventScrollReset: _optionalChain([opts, 'optionalAccess', _15 => _15.preventScrollReset])
431
- })
432
- };
433
- }, [router]);
434
- let basename = router.basename || "/";
435
- let dataRouterContext = React.useMemo(
436
- () => ({
437
- router,
438
- navigator,
439
- static: false,
440
- basename,
441
- unstable_onError
442
- }),
443
- [router, navigator, basename, unstable_onError]
444
- );
445
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(_chunkDI2QHYMJjs.DataRouterContext.Provider, { value: dataRouterContext }, /* @__PURE__ */ React.createElement(_chunkDI2QHYMJjs.DataRouterStateContext.Provider, { value: state }, /* @__PURE__ */ React.createElement(_chunkDI2QHYMJjs.FetchersContext.Provider, { value: fetcherData.current }, /* @__PURE__ */ React.createElement(_chunkDI2QHYMJjs.ViewTransitionContext.Provider, { value: vtContext }, /* @__PURE__ */ React.createElement(
446
- Router,
447
- {
448
- basename,
449
- location: state.location,
450
- navigationType: state.historyAction,
451
- navigator
452
- },
453
- /* @__PURE__ */ React.createElement(
454
- MemoizedDataRoutes,
455
- {
456
- routes: router.routes,
457
- future: router.future,
458
- state,
459
- unstable_onError
460
- }
461
- )
462
- ))))), null);
463
- }
464
- var MemoizedDataRoutes = React.memo(DataRoutes);
465
- function DataRoutes({
466
- routes,
467
- future,
468
- state,
469
- unstable_onError
470
- }) {
471
- return _chunkDI2QHYMJjs.useRoutesImpl.call(void 0, routes, void 0, state, unstable_onError, future);
472
- }
473
- function MemoryRouter({
474
- basename,
475
- children,
476
- initialEntries,
477
- initialIndex
478
- }) {
479
- let historyRef = React.useRef();
480
- if (historyRef.current == null) {
481
- historyRef.current = _chunkDI2QHYMJjs.createMemoryHistory.call(void 0, {
482
- initialEntries,
483
- initialIndex,
484
- v5Compat: true
485
- });
486
- }
487
- let history = historyRef.current;
488
- let [state, setStateImpl] = React.useState({
489
- action: history.action,
490
- location: history.location
491
- });
492
- let setState = React.useCallback(
493
- (newState) => {
494
- React.startTransition(() => setStateImpl(newState));
495
- },
496
- [setStateImpl]
497
- );
498
- React.useLayoutEffect(() => history.listen(setState), [history, setState]);
499
- return /* @__PURE__ */ React.createElement(
500
- Router,
501
- {
502
- basename,
503
- children,
504
- location: state.location,
505
- navigationType: state.action,
506
- navigator: history
507
- }
508
- );
509
- }
510
- function Navigate({
511
- to,
512
- replace,
513
- state,
514
- relative
515
- }) {
516
- _chunkDI2QHYMJjs.invariant.call(void 0,
517
- _chunkDI2QHYMJjs.useInRouterContext.call(void 0, ),
518
- // TODO: This error is probably because they somehow have 2 versions of
519
- // the router loaded. We can help them understand how to avoid that.
520
- `<Navigate> may be used only in the context of a <Router> component.`
521
- );
522
- let { static: isStatic } = React.useContext(_chunkDI2QHYMJjs.NavigationContext);
523
- _chunkDI2QHYMJjs.warning.call(void 0,
524
- !isStatic,
525
- `<Navigate> must not be used on the initial render in a <StaticRouter>. This is a no-op, but you should modify your code so the <Navigate> is only ever rendered in response to some user interaction or state change.`
526
- );
527
- let { matches } = React.useContext(_chunkDI2QHYMJjs.RouteContext);
528
- let { pathname: locationPathname } = _chunkDI2QHYMJjs.useLocation.call(void 0, );
529
- let navigate = _chunkDI2QHYMJjs.useNavigate.call(void 0, );
530
- let path = _chunkDI2QHYMJjs.resolveTo.call(void 0,
531
- to,
532
- _chunkDI2QHYMJjs.getResolveToMatches.call(void 0, matches),
533
- locationPathname,
534
- relative === "path"
535
- );
536
- let jsonPath = JSON.stringify(path);
537
- React.useEffect(() => {
538
- navigate(JSON.parse(jsonPath), { replace, state, relative });
539
- }, [navigate, jsonPath, relative, replace, state]);
540
- return null;
541
- }
542
- function Outlet(props) {
543
- return _chunkDI2QHYMJjs.useOutlet.call(void 0, props.context);
544
- }
545
- function Route(props) {
546
- _chunkDI2QHYMJjs.invariant.call(void 0,
547
- false,
548
- `A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.`
549
- );
550
- }
551
- function Router({
552
- basename: basenameProp = "/",
553
- children = null,
554
- location: locationProp,
555
- navigationType = "POP" /* Pop */,
556
- navigator,
557
- static: staticProp = false
558
- }) {
559
- _chunkDI2QHYMJjs.invariant.call(void 0,
560
- !_chunkDI2QHYMJjs.useInRouterContext.call(void 0, ),
561
- `You cannot render a <Router> inside another <Router>. You should never have more than one in your app.`
562
- );
563
- let basename = basenameProp.replace(/^\/*/, "/");
564
- let navigationContext = React.useMemo(
565
- () => ({
566
- basename,
567
- navigator,
568
- static: staticProp,
569
- future: {}
570
- }),
571
- [basename, navigator, staticProp]
572
- );
573
- if (typeof locationProp === "string") {
574
- locationProp = _chunkDI2QHYMJjs.parsePath.call(void 0, locationProp);
575
- }
576
- let {
577
- pathname = "/",
578
- search = "",
579
- hash = "",
580
- state = null,
581
- key = "default"
582
- } = locationProp;
583
- let locationContext = React.useMemo(() => {
584
- let trailingPathname = _chunkDI2QHYMJjs.stripBasename.call(void 0, pathname, basename);
585
- if (trailingPathname == null) {
586
- return null;
587
- }
588
- return {
589
- location: {
590
- pathname: trailingPathname,
591
- search,
592
- hash,
593
- state,
594
- key
595
- },
596
- navigationType
597
- };
598
- }, [basename, pathname, search, hash, state, key, navigationType]);
599
- _chunkDI2QHYMJjs.warning.call(void 0,
600
- locationContext != null,
601
- `<Router basename="${basename}"> is not able to match the URL "${pathname}${search}${hash}" because it does not start with the basename, so the <Router> won't render anything.`
602
- );
603
- if (locationContext == null) {
604
- return null;
605
- }
606
- return /* @__PURE__ */ React.createElement(_chunkDI2QHYMJjs.NavigationContext.Provider, { value: navigationContext }, /* @__PURE__ */ React.createElement(_chunkDI2QHYMJjs.LocationContext.Provider, { children, value: locationContext }));
607
- }
608
- function Routes({
609
- children,
610
- location
611
- }) {
612
- return _chunkDI2QHYMJjs.useRoutes.call(void 0, createRoutesFromChildren(children), location);
613
- }
614
- function Await({
615
- children,
616
- errorElement,
617
- resolve
618
- }) {
619
- let dataRouterContext = React.useContext(_chunkDI2QHYMJjs.DataRouterContext);
620
- return /* @__PURE__ */ React.createElement(
621
- AwaitErrorBoundary,
622
- {
623
- resolve,
624
- errorElement,
625
- unstable_onError: _optionalChain([dataRouterContext, 'optionalAccess', _16 => _16.unstable_onError])
626
- },
627
- /* @__PURE__ */ React.createElement(ResolveAwait, null, children)
628
- );
629
- }
630
- var AwaitErrorBoundary = class extends React.Component {
631
- constructor(props) {
632
- super(props);
633
- this.state = { error: null };
634
- }
635
- static getDerivedStateFromError(error) {
636
- return { error };
637
- }
638
- componentDidCatch(error, errorInfo) {
639
- if (this.props.unstable_onError) {
640
- this.props.unstable_onError(error, errorInfo);
641
- } else {
642
- console.error(
643
- "<Await> caught the following error during render",
644
- error,
645
- errorInfo
646
- );
647
- }
648
- }
649
- render() {
650
- let { children, errorElement, resolve } = this.props;
651
- let promise = null;
652
- let status = 0 /* pending */;
653
- if (!(resolve instanceof Promise)) {
654
- status = 1 /* success */;
655
- promise = Promise.resolve();
656
- Object.defineProperty(promise, "_tracked", { get: () => true });
657
- Object.defineProperty(promise, "_data", { get: () => resolve });
658
- } else if (this.state.error) {
659
- status = 2 /* error */;
660
- let renderError = this.state.error;
661
- promise = Promise.reject().catch(() => {
662
- });
663
- Object.defineProperty(promise, "_tracked", { get: () => true });
664
- Object.defineProperty(promise, "_error", { get: () => renderError });
665
- } else if (resolve._tracked) {
666
- promise = resolve;
667
- status = "_error" in promise ? 2 /* error */ : "_data" in promise ? 1 /* success */ : 0 /* pending */;
668
- } else {
669
- status = 0 /* pending */;
670
- Object.defineProperty(resolve, "_tracked", { get: () => true });
671
- promise = resolve.then(
672
- (data) => Object.defineProperty(resolve, "_data", { get: () => data }),
673
- (error) => {
674
- _optionalChain([this, 'access', _17 => _17.props, 'access', _18 => _18.unstable_onError, 'optionalCall', _19 => _19(error)]);
675
- Object.defineProperty(resolve, "_error", { get: () => error });
676
- }
677
- );
678
- }
679
- if (status === 2 /* error */ && !errorElement) {
680
- throw promise._error;
681
- }
682
- if (status === 2 /* error */) {
683
- return /* @__PURE__ */ React.createElement(_chunkDI2QHYMJjs.AwaitContext.Provider, { value: promise, children: errorElement });
684
- }
685
- if (status === 1 /* success */) {
686
- return /* @__PURE__ */ React.createElement(_chunkDI2QHYMJjs.AwaitContext.Provider, { value: promise, children });
687
- }
688
- throw promise;
689
- }
690
- };
691
- function ResolveAwait({
692
- children
693
- }) {
694
- let data = _chunkDI2QHYMJjs.useAsyncValue.call(void 0, );
695
- let toRender = typeof children === "function" ? children(data) : children;
696
- return /* @__PURE__ */ React.createElement(React.Fragment, null, toRender);
697
- }
698
- function createRoutesFromChildren(children, parentPath = []) {
699
- let routes = [];
700
- React.Children.forEach(children, (element, index) => {
701
- if (!React.isValidElement(element)) {
702
- return;
703
- }
704
- let treePath = [...parentPath, index];
705
- if (element.type === React.Fragment) {
706
- routes.push.apply(
707
- routes,
708
- createRoutesFromChildren(element.props.children, treePath)
709
- );
710
- return;
711
- }
712
- _chunkDI2QHYMJjs.invariant.call(void 0,
713
- element.type === Route,
714
- `[${typeof element.type === "string" ? element.type : element.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`
715
- );
716
- _chunkDI2QHYMJjs.invariant.call(void 0,
717
- !element.props.index || !element.props.children,
718
- "An index route cannot have child routes."
719
- );
720
- let route = {
721
- id: element.props.id || treePath.join("-"),
722
- caseSensitive: element.props.caseSensitive,
723
- element: element.props.element,
724
- Component: element.props.Component,
725
- index: element.props.index,
726
- path: element.props.path,
727
- middleware: element.props.middleware,
728
- loader: element.props.loader,
729
- action: element.props.action,
730
- hydrateFallbackElement: element.props.hydrateFallbackElement,
731
- HydrateFallback: element.props.HydrateFallback,
732
- errorElement: element.props.errorElement,
733
- ErrorBoundary: element.props.ErrorBoundary,
734
- hasErrorBoundary: element.props.hasErrorBoundary === true || element.props.ErrorBoundary != null || element.props.errorElement != null,
735
- shouldRevalidate: element.props.shouldRevalidate,
736
- handle: element.props.handle,
737
- lazy: element.props.lazy
738
- };
739
- if (element.props.children) {
740
- route.children = createRoutesFromChildren(
741
- element.props.children,
742
- treePath
743
- );
744
- }
745
- routes.push(route);
746
- });
747
- return routes;
748
- }
749
- var createRoutesFromElements = createRoutesFromChildren;
750
- function renderMatches(matches) {
751
- return _chunkDI2QHYMJjs._renderMatches.call(void 0, matches);
752
- }
753
- function useRouteComponentProps() {
754
- return {
755
- params: _chunkDI2QHYMJjs.useParams.call(void 0, ),
756
- loaderData: _chunkDI2QHYMJjs.useLoaderData.call(void 0, ),
757
- actionData: _chunkDI2QHYMJjs.useActionData.call(void 0, ),
758
- matches: _chunkDI2QHYMJjs.useMatches.call(void 0, )
759
- };
760
- }
761
- function WithComponentProps({
762
- children
763
- }) {
764
- const props = useRouteComponentProps();
765
- return React.cloneElement(children, props);
766
- }
767
- function withComponentProps(Component2) {
768
- return function WithComponentProps2() {
769
- const props = useRouteComponentProps();
770
- return React.createElement(Component2, props);
771
- };
772
- }
773
- function useHydrateFallbackProps() {
774
- return {
775
- params: _chunkDI2QHYMJjs.useParams.call(void 0, ),
776
- loaderData: _chunkDI2QHYMJjs.useLoaderData.call(void 0, ),
777
- actionData: _chunkDI2QHYMJjs.useActionData.call(void 0, )
778
- };
779
- }
780
- function WithHydrateFallbackProps({
781
- children
782
- }) {
783
- const props = useHydrateFallbackProps();
784
- return React.cloneElement(children, props);
785
- }
786
- function withHydrateFallbackProps(HydrateFallback) {
787
- return function WithHydrateFallbackProps2() {
788
- const props = useHydrateFallbackProps();
789
- return React.createElement(HydrateFallback, props);
790
- };
791
- }
792
- function useErrorBoundaryProps() {
793
- return {
794
- params: _chunkDI2QHYMJjs.useParams.call(void 0, ),
795
- loaderData: _chunkDI2QHYMJjs.useLoaderData.call(void 0, ),
796
- actionData: _chunkDI2QHYMJjs.useActionData.call(void 0, ),
797
- error: _chunkDI2QHYMJjs.useRouteError.call(void 0, )
798
- };
799
- }
800
- function WithErrorBoundaryProps({
801
- children
802
- }) {
803
- const props = useErrorBoundaryProps();
804
- return React.cloneElement(children, props);
805
- }
806
- function withErrorBoundaryProps(ErrorBoundary) {
807
- return function WithErrorBoundaryProps2() {
808
- const props = useErrorBoundaryProps();
809
- return React.createElement(ErrorBoundary, props);
810
- };
811
- }
812
-
813
- // lib/dom/dom.ts
814
- var defaultMethod = "get";
815
- var defaultEncType = "application/x-www-form-urlencoded";
816
- function isHtmlElement(object) {
817
- return object != null && typeof object.tagName === "string";
818
- }
819
- function isButtonElement(object) {
820
- return isHtmlElement(object) && object.tagName.toLowerCase() === "button";
821
- }
822
- function isFormElement(object) {
823
- return isHtmlElement(object) && object.tagName.toLowerCase() === "form";
824
- }
825
- function isInputElement(object) {
826
- return isHtmlElement(object) && object.tagName.toLowerCase() === "input";
827
- }
828
- function isModifiedEvent(event) {
829
- return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
830
- }
831
- function shouldProcessLinkClick(event, target) {
832
- return event.button === 0 && // Ignore everything but left clicks
833
- (!target || target === "_self") && // Let browser handle "target=_blank" etc.
834
- !isModifiedEvent(event);
835
- }
836
- function createSearchParams(init = "") {
837
- return new URLSearchParams(
838
- typeof init === "string" || Array.isArray(init) || init instanceof URLSearchParams ? init : Object.keys(init).reduce((memo2, key) => {
839
- let value = init[key];
840
- return memo2.concat(
841
- Array.isArray(value) ? value.map((v) => [key, v]) : [[key, value]]
842
- );
843
- }, [])
844
- );
845
- }
846
- function getSearchParamsForLocation(locationSearch, defaultSearchParams) {
847
- let searchParams = createSearchParams(locationSearch);
848
- if (defaultSearchParams) {
849
- defaultSearchParams.forEach((_, key) => {
850
- if (!searchParams.has(key)) {
851
- defaultSearchParams.getAll(key).forEach((value) => {
852
- searchParams.append(key, value);
853
- });
854
- }
855
- });
856
- }
857
- return searchParams;
858
- }
859
- var _formDataSupportsSubmitter = null;
860
- function isFormDataSubmitterSupported() {
861
- if (_formDataSupportsSubmitter === null) {
862
- try {
863
- new FormData(
864
- document.createElement("form"),
865
- // @ts-expect-error if FormData supports the submitter parameter, this will throw
866
- 0
867
- );
868
- _formDataSupportsSubmitter = false;
869
- } catch (e) {
870
- _formDataSupportsSubmitter = true;
871
- }
872
- }
873
- return _formDataSupportsSubmitter;
874
- }
875
- var supportedFormEncTypes = /* @__PURE__ */ new Set([
876
- "application/x-www-form-urlencoded",
877
- "multipart/form-data",
878
- "text/plain"
879
- ]);
880
- function getFormEncType(encType) {
881
- if (encType != null && !supportedFormEncTypes.has(encType)) {
882
- _chunkDI2QHYMJjs.warning.call(void 0,
883
- false,
884
- `"${encType}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${defaultEncType}"`
885
- );
886
- return null;
887
- }
888
- return encType;
889
- }
890
- function getFormSubmissionInfo(target, basename) {
891
- let method;
892
- let action;
893
- let encType;
894
- let formData;
895
- let body;
896
- if (isFormElement(target)) {
897
- let attr = target.getAttribute("action");
898
- action = attr ? _chunkDI2QHYMJjs.stripBasename.call(void 0, attr, basename) : null;
899
- method = target.getAttribute("method") || defaultMethod;
900
- encType = getFormEncType(target.getAttribute("enctype")) || defaultEncType;
901
- formData = new FormData(target);
902
- } else if (isButtonElement(target) || isInputElement(target) && (target.type === "submit" || target.type === "image")) {
903
- let form = target.form;
904
- if (form == null) {
905
- throw new Error(
906
- `Cannot submit a <button> or <input type="submit"> without a <form>`
907
- );
908
- }
909
- let attr = target.getAttribute("formaction") || form.getAttribute("action");
910
- action = attr ? _chunkDI2QHYMJjs.stripBasename.call(void 0, attr, basename) : null;
911
- method = target.getAttribute("formmethod") || form.getAttribute("method") || defaultMethod;
912
- encType = getFormEncType(target.getAttribute("formenctype")) || getFormEncType(form.getAttribute("enctype")) || defaultEncType;
913
- formData = new FormData(form, target);
914
- if (!isFormDataSubmitterSupported()) {
915
- let { name, type, value } = target;
916
- if (type === "image") {
917
- let prefix = name ? `${name}.` : "";
918
- formData.append(`${prefix}x`, "0");
919
- formData.append(`${prefix}y`, "0");
920
- } else if (name) {
921
- formData.append(name, value);
922
- }
923
- }
924
- } else if (isHtmlElement(target)) {
925
- throw new Error(
926
- `Cannot submit element that is not <form>, <button>, or <input type="submit|image">`
927
- );
928
- } else {
929
- method = defaultMethod;
930
- action = null;
931
- encType = defaultEncType;
932
- body = target;
933
- }
934
- if (formData && encType === "text/plain") {
935
- body = formData;
936
- formData = void 0;
937
- }
938
- return { action, method: method.toLowerCase(), encType, formData, body };
939
- }
940
-
941
- // lib/dom/lib.tsx
942
-
943
- var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
944
- try {
945
- if (isBrowser) {
946
- window.__reactRouterVersion = // @ts-expect-error
947
- "7.9.4";
948
- }
949
- } catch (e) {
950
- }
951
- function createBrowserRouter(routes, opts) {
952
- return _chunkDI2QHYMJjs.createRouter.call(void 0, {
953
- basename: _optionalChain([opts, 'optionalAccess', _20 => _20.basename]),
954
- getContext: _optionalChain([opts, 'optionalAccess', _21 => _21.getContext]),
955
- future: _optionalChain([opts, 'optionalAccess', _22 => _22.future]),
956
- history: _chunkDI2QHYMJjs.createBrowserHistory.call(void 0, { window: _optionalChain([opts, 'optionalAccess', _23 => _23.window]) }),
957
- hydrationData: _optionalChain([opts, 'optionalAccess', _24 => _24.hydrationData]) || parseHydrationData(),
958
- routes,
959
- mapRouteProperties,
960
- hydrationRouteProperties,
961
- dataStrategy: _optionalChain([opts, 'optionalAccess', _25 => _25.dataStrategy]),
962
- patchRoutesOnNavigation: _optionalChain([opts, 'optionalAccess', _26 => _26.patchRoutesOnNavigation]),
963
- window: _optionalChain([opts, 'optionalAccess', _27 => _27.window])
964
- }).initialize();
965
- }
966
- function createHashRouter(routes, opts) {
967
- return _chunkDI2QHYMJjs.createRouter.call(void 0, {
968
- basename: _optionalChain([opts, 'optionalAccess', _28 => _28.basename]),
969
- getContext: _optionalChain([opts, 'optionalAccess', _29 => _29.getContext]),
970
- future: _optionalChain([opts, 'optionalAccess', _30 => _30.future]),
971
- history: _chunkDI2QHYMJjs.createHashHistory.call(void 0, { window: _optionalChain([opts, 'optionalAccess', _31 => _31.window]) }),
972
- hydrationData: _optionalChain([opts, 'optionalAccess', _32 => _32.hydrationData]) || parseHydrationData(),
973
- routes,
974
- mapRouteProperties,
975
- hydrationRouteProperties,
976
- dataStrategy: _optionalChain([opts, 'optionalAccess', _33 => _33.dataStrategy]),
977
- patchRoutesOnNavigation: _optionalChain([opts, 'optionalAccess', _34 => _34.patchRoutesOnNavigation]),
978
- window: _optionalChain([opts, 'optionalAccess', _35 => _35.window])
979
- }).initialize();
980
- }
981
- function parseHydrationData() {
982
- let state = _optionalChain([window, 'optionalAccess', _36 => _36.__staticRouterHydrationData]);
983
- if (state && state.errors) {
984
- state = {
985
- ...state,
986
- errors: deserializeErrors(state.errors)
987
- };
988
- }
989
- return state;
990
- }
991
- function deserializeErrors(errors) {
992
- if (!errors) return null;
993
- let entries = Object.entries(errors);
994
- let serialized = {};
995
- for (let [key, val] of entries) {
996
- if (val && val.__type === "RouteErrorResponse") {
997
- serialized[key] = new (0, _chunkDI2QHYMJjs.ErrorResponseImpl)(
998
- val.status,
999
- val.statusText,
1000
- val.data,
1001
- val.internal === true
1002
- );
1003
- } else if (val && val.__type === "Error") {
1004
- if (val.__subType) {
1005
- let ErrorConstructor = window[val.__subType];
1006
- if (typeof ErrorConstructor === "function") {
1007
- try {
1008
- let error = new ErrorConstructor(val.message);
1009
- error.stack = "";
1010
- serialized[key] = error;
1011
- } catch (e) {
1012
- }
1013
- }
1014
- }
1015
- if (serialized[key] == null) {
1016
- let error = new Error(val.message);
1017
- error.stack = "";
1018
- serialized[key] = error;
1019
- }
1020
- } else {
1021
- serialized[key] = val;
1022
- }
1023
- }
1024
- return serialized;
1025
- }
1026
- function BrowserRouter({
1027
- basename,
1028
- children,
1029
- window: window2
1030
- }) {
1031
- let historyRef = React2.useRef();
1032
- if (historyRef.current == null) {
1033
- historyRef.current = _chunkDI2QHYMJjs.createBrowserHistory.call(void 0, { window: window2, v5Compat: true });
1034
- }
1035
- let history = historyRef.current;
1036
- let [state, setStateImpl] = React2.useState({
1037
- action: history.action,
1038
- location: history.location
1039
- });
1040
- let setState = React2.useCallback(
1041
- (newState) => {
1042
- React2.startTransition(() => setStateImpl(newState));
1043
- },
1044
- [setStateImpl]
1045
- );
1046
- React2.useLayoutEffect(() => history.listen(setState), [history, setState]);
1047
- return /* @__PURE__ */ React2.createElement(
1048
- Router,
1049
- {
1050
- basename,
1051
- children,
1052
- location: state.location,
1053
- navigationType: state.action,
1054
- navigator: history
1055
- }
1056
- );
1057
- }
1058
- function HashRouter({ basename, children, window: window2 }) {
1059
- let historyRef = React2.useRef();
1060
- if (historyRef.current == null) {
1061
- historyRef.current = _chunkDI2QHYMJjs.createHashHistory.call(void 0, { window: window2, v5Compat: true });
1062
- }
1063
- let history = historyRef.current;
1064
- let [state, setStateImpl] = React2.useState({
1065
- action: history.action,
1066
- location: history.location
1067
- });
1068
- let setState = React2.useCallback(
1069
- (newState) => {
1070
- React2.startTransition(() => setStateImpl(newState));
1071
- },
1072
- [setStateImpl]
1073
- );
1074
- React2.useLayoutEffect(() => history.listen(setState), [history, setState]);
1075
- return /* @__PURE__ */ React2.createElement(
1076
- Router,
1077
- {
1078
- basename,
1079
- children,
1080
- location: state.location,
1081
- navigationType: state.action,
1082
- navigator: history
1083
- }
1084
- );
1085
- }
1086
- function HistoryRouter({
1087
- basename,
1088
- children,
1089
- history
1090
- }) {
1091
- let [state, setStateImpl] = React2.useState({
1092
- action: history.action,
1093
- location: history.location
1094
- });
1095
- let setState = React2.useCallback(
1096
- (newState) => {
1097
- React2.startTransition(() => setStateImpl(newState));
1098
- },
1099
- [setStateImpl]
1100
- );
1101
- React2.useLayoutEffect(() => history.listen(setState), [history, setState]);
1102
- return /* @__PURE__ */ React2.createElement(
1103
- Router,
1104
- {
1105
- basename,
1106
- children,
1107
- location: state.location,
1108
- navigationType: state.action,
1109
- navigator: history
1110
- }
1111
- );
1112
- }
1113
- HistoryRouter.displayName = "unstable_HistoryRouter";
1114
- var ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
1115
- var Link = React2.forwardRef(
1116
- function LinkWithRef({
1117
- onClick,
1118
- discover = "render",
1119
- prefetch = "none",
1120
- relative,
1121
- reloadDocument,
1122
- replace,
1123
- state,
1124
- target,
1125
- to,
1126
- preventScrollReset,
1127
- viewTransition,
1128
- ...rest
1129
- }, forwardedRef) {
1130
- let { basename } = React2.useContext(_chunkDI2QHYMJjs.NavigationContext);
1131
- let isAbsolute = typeof to === "string" && ABSOLUTE_URL_REGEX.test(to);
1132
- let absoluteHref;
1133
- let isExternal = false;
1134
- if (typeof to === "string" && isAbsolute) {
1135
- absoluteHref = to;
1136
- if (isBrowser) {
1137
- try {
1138
- let currentUrl = new URL(window.location.href);
1139
- let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to);
1140
- let path = _chunkDI2QHYMJjs.stripBasename.call(void 0, targetUrl.pathname, basename);
1141
- if (targetUrl.origin === currentUrl.origin && path != null) {
1142
- to = path + targetUrl.search + targetUrl.hash;
1143
- } else {
1144
- isExternal = true;
1145
- }
1146
- } catch (e) {
1147
- _chunkDI2QHYMJjs.warning.call(void 0,
1148
- false,
1149
- `<Link to="${to}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`
1150
- );
1151
- }
1152
- }
1153
- }
1154
- let href = _chunkDI2QHYMJjs.useHref.call(void 0, to, { relative });
1155
- let [shouldPrefetch, prefetchRef, prefetchHandlers] = _chunkDI2QHYMJjs.usePrefetchBehavior.call(void 0,
1156
- prefetch,
1157
- rest
1158
- );
1159
- let internalOnClick = useLinkClickHandler(to, {
1160
- replace,
1161
- state,
1162
- target,
1163
- preventScrollReset,
1164
- relative,
1165
- viewTransition
1166
- });
1167
- function handleClick(event) {
1168
- if (onClick) onClick(event);
1169
- if (!event.defaultPrevented) {
1170
- internalOnClick(event);
1171
- }
1172
- }
1173
- let link = (
1174
- // eslint-disable-next-line jsx-a11y/anchor-has-content
1175
- /* @__PURE__ */ React2.createElement(
1176
- "a",
1177
- {
1178
- ...rest,
1179
- ...prefetchHandlers,
1180
- href: absoluteHref || href,
1181
- onClick: isExternal || reloadDocument ? onClick : handleClick,
1182
- ref: _chunkDI2QHYMJjs.mergeRefs.call(void 0, forwardedRef, prefetchRef),
1183
- target,
1184
- "data-discover": !isAbsolute && discover === "render" ? "true" : void 0
1185
- }
1186
- )
1187
- );
1188
- return shouldPrefetch && !isAbsolute ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, link, /* @__PURE__ */ React2.createElement(_chunkDI2QHYMJjs.PrefetchPageLinks, { page: href })) : link;
1189
- }
1190
- );
1191
- Link.displayName = "Link";
1192
- var NavLink = React2.forwardRef(
1193
- function NavLinkWithRef({
1194
- "aria-current": ariaCurrentProp = "page",
1195
- caseSensitive = false,
1196
- className: classNameProp = "",
1197
- end = false,
1198
- style: styleProp,
1199
- to,
1200
- viewTransition,
1201
- children,
1202
- ...rest
1203
- }, ref) {
1204
- let path = _chunkDI2QHYMJjs.useResolvedPath.call(void 0, to, { relative: rest.relative });
1205
- let location = _chunkDI2QHYMJjs.useLocation.call(void 0, );
1206
- let routerState = React2.useContext(_chunkDI2QHYMJjs.DataRouterStateContext);
1207
- let { navigator, basename } = React2.useContext(_chunkDI2QHYMJjs.NavigationContext);
1208
- let isTransitioning = routerState != null && // Conditional usage is OK here because the usage of a data router is static
1209
- // eslint-disable-next-line react-hooks/rules-of-hooks
1210
- useViewTransitionState(path) && viewTransition === true;
1211
- let toPathname = navigator.encodeLocation ? navigator.encodeLocation(path).pathname : path.pathname;
1212
- let locationPathname = location.pathname;
1213
- let nextLocationPathname = routerState && routerState.navigation && routerState.navigation.location ? routerState.navigation.location.pathname : null;
1214
- if (!caseSensitive) {
1215
- locationPathname = locationPathname.toLowerCase();
1216
- nextLocationPathname = nextLocationPathname ? nextLocationPathname.toLowerCase() : null;
1217
- toPathname = toPathname.toLowerCase();
1218
- }
1219
- if (nextLocationPathname && basename) {
1220
- nextLocationPathname = _chunkDI2QHYMJjs.stripBasename.call(void 0, nextLocationPathname, basename) || nextLocationPathname;
1221
- }
1222
- const endSlashPosition = toPathname !== "/" && toPathname.endsWith("/") ? toPathname.length - 1 : toPathname.length;
1223
- let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(endSlashPosition) === "/";
1224
- let isPending = nextLocationPathname != null && (nextLocationPathname === toPathname || !end && nextLocationPathname.startsWith(toPathname) && nextLocationPathname.charAt(toPathname.length) === "/");
1225
- let renderProps = {
1226
- isActive,
1227
- isPending,
1228
- isTransitioning
1229
- };
1230
- let ariaCurrent = isActive ? ariaCurrentProp : void 0;
1231
- let className;
1232
- if (typeof classNameProp === "function") {
1233
- className = classNameProp(renderProps);
1234
- } else {
1235
- className = [
1236
- classNameProp,
1237
- isActive ? "active" : null,
1238
- isPending ? "pending" : null,
1239
- isTransitioning ? "transitioning" : null
1240
- ].filter(Boolean).join(" ");
1241
- }
1242
- let style = typeof styleProp === "function" ? styleProp(renderProps) : styleProp;
1243
- return /* @__PURE__ */ React2.createElement(
1244
- Link,
1245
- {
1246
- ...rest,
1247
- "aria-current": ariaCurrent,
1248
- className,
1249
- ref,
1250
- style,
1251
- to,
1252
- viewTransition
1253
- },
1254
- typeof children === "function" ? children(renderProps) : children
1255
- );
1256
- }
1257
- );
1258
- NavLink.displayName = "NavLink";
1259
- var Form = React2.forwardRef(
1260
- ({
1261
- discover = "render",
1262
- fetcherKey,
1263
- navigate,
1264
- reloadDocument,
1265
- replace,
1266
- state,
1267
- method = defaultMethod,
1268
- action,
1269
- onSubmit,
1270
- relative,
1271
- preventScrollReset,
1272
- viewTransition,
1273
- ...props
1274
- }, forwardedRef) => {
1275
- let submit = useSubmit();
1276
- let formAction = useFormAction(action, { relative });
1277
- let formMethod = method.toLowerCase() === "get" ? "get" : "post";
1278
- let isAbsolute = typeof action === "string" && ABSOLUTE_URL_REGEX.test(action);
1279
- let submitHandler = (event) => {
1280
- onSubmit && onSubmit(event);
1281
- if (event.defaultPrevented) return;
1282
- event.preventDefault();
1283
- let submitter = event.nativeEvent.submitter;
1284
- let submitMethod = _optionalChain([submitter, 'optionalAccess', _37 => _37.getAttribute, 'call', _38 => _38("formmethod")]) || method;
1285
- submit(submitter || event.currentTarget, {
1286
- fetcherKey,
1287
- method: submitMethod,
1288
- navigate,
1289
- replace,
1290
- state,
1291
- relative,
1292
- preventScrollReset,
1293
- viewTransition
1294
- });
1295
- };
1296
- return /* @__PURE__ */ React2.createElement(
1297
- "form",
1298
- {
1299
- ref: forwardedRef,
1300
- method: formMethod,
1301
- action: formAction,
1302
- onSubmit: reloadDocument ? onSubmit : submitHandler,
1303
- ...props,
1304
- "data-discover": !isAbsolute && discover === "render" ? "true" : void 0
1305
- }
1306
- );
1307
- }
1308
- );
1309
- Form.displayName = "Form";
1310
- function ScrollRestoration({
1311
- getKey,
1312
- storageKey,
1313
- ...props
1314
- }) {
1315
- let remixContext = React2.useContext(_chunkDI2QHYMJjs.FrameworkContext);
1316
- let { basename } = React2.useContext(_chunkDI2QHYMJjs.NavigationContext);
1317
- let location = _chunkDI2QHYMJjs.useLocation.call(void 0, );
1318
- let matches = _chunkDI2QHYMJjs.useMatches.call(void 0, );
1319
- useScrollRestoration({ getKey, storageKey });
1320
- let ssrKey = React2.useMemo(
1321
- () => {
1322
- if (!remixContext || !getKey) return null;
1323
- let userKey = getScrollRestorationKey(
1324
- location,
1325
- matches,
1326
- basename,
1327
- getKey
1328
- );
1329
- return userKey !== location.key ? userKey : null;
1330
- },
1331
- // Nah, we only need this the first time for the SSR render
1332
- // eslint-disable-next-line react-hooks/exhaustive-deps
1333
- []
1334
- );
1335
- if (!remixContext || remixContext.isSpaMode) {
1336
- return null;
1337
- }
1338
- let restoreScroll = ((storageKey2, restoreKey) => {
1339
- if (!window.history.state || !window.history.state.key) {
1340
- let key = Math.random().toString(32).slice(2);
1341
- window.history.replaceState({ key }, "");
1342
- }
1343
- try {
1344
- let positions = JSON.parse(sessionStorage.getItem(storageKey2) || "{}");
1345
- let storedY = positions[restoreKey || window.history.state.key];
1346
- if (typeof storedY === "number") {
1347
- window.scrollTo(0, storedY);
1348
- }
1349
- } catch (error) {
1350
- console.error(error);
1351
- sessionStorage.removeItem(storageKey2);
1352
- }
1353
- }).toString();
1354
- return /* @__PURE__ */ React2.createElement(
1355
- "script",
1356
- {
1357
- ...props,
1358
- suppressHydrationWarning: true,
1359
- dangerouslySetInnerHTML: {
1360
- __html: `(${restoreScroll})(${JSON.stringify(
1361
- storageKey || SCROLL_RESTORATION_STORAGE_KEY
1362
- )}, ${JSON.stringify(ssrKey)})`
1363
- }
1364
- }
1365
- );
1366
- }
1367
- ScrollRestoration.displayName = "ScrollRestoration";
1368
- function getDataRouterConsoleError(hookName) {
1369
- return `${hookName} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
1370
- }
1371
- function useDataRouterContext(hookName) {
1372
- let ctx = React2.useContext(_chunkDI2QHYMJjs.DataRouterContext);
1373
- _chunkDI2QHYMJjs.invariant.call(void 0, ctx, getDataRouterConsoleError(hookName));
1374
- return ctx;
1375
- }
1376
- function useDataRouterState(hookName) {
1377
- let state = React2.useContext(_chunkDI2QHYMJjs.DataRouterStateContext);
1378
- _chunkDI2QHYMJjs.invariant.call(void 0, state, getDataRouterConsoleError(hookName));
1379
- return state;
1380
- }
1381
- function useLinkClickHandler(to, {
1382
- target,
1383
- replace: replaceProp,
1384
- state,
1385
- preventScrollReset,
1386
- relative,
1387
- viewTransition
1388
- } = {}) {
1389
- let navigate = _chunkDI2QHYMJjs.useNavigate.call(void 0, );
1390
- let location = _chunkDI2QHYMJjs.useLocation.call(void 0, );
1391
- let path = _chunkDI2QHYMJjs.useResolvedPath.call(void 0, to, { relative });
1392
- return React2.useCallback(
1393
- (event) => {
1394
- if (shouldProcessLinkClick(event, target)) {
1395
- event.preventDefault();
1396
- let replace = replaceProp !== void 0 ? replaceProp : _chunkDI2QHYMJjs.createPath.call(void 0, location) === _chunkDI2QHYMJjs.createPath.call(void 0, path);
1397
- navigate(to, {
1398
- replace,
1399
- state,
1400
- preventScrollReset,
1401
- relative,
1402
- viewTransition
1403
- });
1404
- }
1405
- },
1406
- [
1407
- location,
1408
- navigate,
1409
- path,
1410
- replaceProp,
1411
- state,
1412
- target,
1413
- to,
1414
- preventScrollReset,
1415
- relative,
1416
- viewTransition
1417
- ]
1418
- );
1419
- }
1420
- function useSearchParams(defaultInit) {
1421
- _chunkDI2QHYMJjs.warning.call(void 0,
1422
- typeof URLSearchParams !== "undefined",
1423
- `You cannot use the \`useSearchParams\` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.`
1424
- );
1425
- let defaultSearchParamsRef = React2.useRef(createSearchParams(defaultInit));
1426
- let hasSetSearchParamsRef = React2.useRef(false);
1427
- let location = _chunkDI2QHYMJjs.useLocation.call(void 0, );
1428
- let searchParams = React2.useMemo(
1429
- () => (
1430
- // Only merge in the defaults if we haven't yet called setSearchParams.
1431
- // Once we call that we want those to take precedence, otherwise you can't
1432
- // remove a param with setSearchParams({}) if it has an initial value
1433
- getSearchParamsForLocation(
1434
- location.search,
1435
- hasSetSearchParamsRef.current ? null : defaultSearchParamsRef.current
1436
- )
1437
- ),
1438
- [location.search]
1439
- );
1440
- let navigate = _chunkDI2QHYMJjs.useNavigate.call(void 0, );
1441
- let setSearchParams = React2.useCallback(
1442
- (nextInit, navigateOptions) => {
1443
- const newSearchParams = createSearchParams(
1444
- typeof nextInit === "function" ? nextInit(new URLSearchParams(searchParams)) : nextInit
1445
- );
1446
- hasSetSearchParamsRef.current = true;
1447
- navigate("?" + newSearchParams, navigateOptions);
1448
- },
1449
- [navigate, searchParams]
1450
- );
1451
- return [searchParams, setSearchParams];
1452
- }
1453
- var fetcherId = 0;
1454
- var getUniqueFetcherId = () => `__${String(++fetcherId)}__`;
1455
- function useSubmit() {
1456
- let { router } = useDataRouterContext("useSubmit" /* UseSubmit */);
1457
- let { basename } = React2.useContext(_chunkDI2QHYMJjs.NavigationContext);
1458
- let currentRouteId = _chunkDI2QHYMJjs.useRouteId.call(void 0, );
1459
- return React2.useCallback(
1460
- async (target, options = {}) => {
1461
- let { action, method, encType, formData, body } = getFormSubmissionInfo(
1462
- target,
1463
- basename
1464
- );
1465
- if (options.navigate === false) {
1466
- let key = options.fetcherKey || getUniqueFetcherId();
1467
- await router.fetch(key, currentRouteId, options.action || action, {
1468
- preventScrollReset: options.preventScrollReset,
1469
- formData,
1470
- body,
1471
- formMethod: options.method || method,
1472
- formEncType: options.encType || encType,
1473
- flushSync: options.flushSync
1474
- });
1475
- } else {
1476
- await router.navigate(options.action || action, {
1477
- preventScrollReset: options.preventScrollReset,
1478
- formData,
1479
- body,
1480
- formMethod: options.method || method,
1481
- formEncType: options.encType || encType,
1482
- replace: options.replace,
1483
- state: options.state,
1484
- fromRouteId: currentRouteId,
1485
- flushSync: options.flushSync,
1486
- viewTransition: options.viewTransition
1487
- });
1488
- }
1489
- },
1490
- [router, basename, currentRouteId]
1491
- );
1492
- }
1493
- function useFormAction(action, { relative } = {}) {
1494
- let { basename } = React2.useContext(_chunkDI2QHYMJjs.NavigationContext);
1495
- let routeContext = React2.useContext(_chunkDI2QHYMJjs.RouteContext);
1496
- _chunkDI2QHYMJjs.invariant.call(void 0, routeContext, "useFormAction must be used inside a RouteContext");
1497
- let [match] = routeContext.matches.slice(-1);
1498
- let path = { ..._chunkDI2QHYMJjs.useResolvedPath.call(void 0, action ? action : ".", { relative }) };
1499
- let location = _chunkDI2QHYMJjs.useLocation.call(void 0, );
1500
- if (action == null) {
1501
- path.search = location.search;
1502
- let params = new URLSearchParams(path.search);
1503
- let indexValues = params.getAll("index");
1504
- let hasNakedIndexParam = indexValues.some((v) => v === "");
1505
- if (hasNakedIndexParam) {
1506
- params.delete("index");
1507
- indexValues.filter((v) => v).forEach((v) => params.append("index", v));
1508
- let qs = params.toString();
1509
- path.search = qs ? `?${qs}` : "";
1510
- }
1511
- }
1512
- if ((!action || action === ".") && match.route.index) {
1513
- path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
1514
- }
1515
- if (basename !== "/") {
1516
- path.pathname = path.pathname === "/" ? basename : _chunkDI2QHYMJjs.joinPaths.call(void 0, [basename, path.pathname]);
1517
- }
1518
- return _chunkDI2QHYMJjs.createPath.call(void 0, path);
1519
- }
1520
- function useFetcher({
1521
- key
1522
- } = {}) {
1523
- let { router } = useDataRouterContext("useFetcher" /* UseFetcher */);
1524
- let state = useDataRouterState("useFetcher" /* UseFetcher */);
1525
- let fetcherData = React2.useContext(_chunkDI2QHYMJjs.FetchersContext);
1526
- let route = React2.useContext(_chunkDI2QHYMJjs.RouteContext);
1527
- let routeId = _optionalChain([route, 'access', _39 => _39.matches, 'access', _40 => _40[route.matches.length - 1], 'optionalAccess', _41 => _41.route, 'access', _42 => _42.id]);
1528
- _chunkDI2QHYMJjs.invariant.call(void 0, fetcherData, `useFetcher must be used inside a FetchersContext`);
1529
- _chunkDI2QHYMJjs.invariant.call(void 0, route, `useFetcher must be used inside a RouteContext`);
1530
- _chunkDI2QHYMJjs.invariant.call(void 0,
1531
- routeId != null,
1532
- `useFetcher can only be used on routes that contain a unique "id"`
1533
- );
1534
- let defaultKey = React2.useId();
1535
- let [fetcherKey, setFetcherKey] = React2.useState(key || defaultKey);
1536
- if (key && key !== fetcherKey) {
1537
- setFetcherKey(key);
1538
- }
1539
- React2.useEffect(() => {
1540
- router.getFetcher(fetcherKey);
1541
- return () => router.deleteFetcher(fetcherKey);
1542
- }, [router, fetcherKey]);
1543
- let load = React2.useCallback(
1544
- async (href, opts) => {
1545
- _chunkDI2QHYMJjs.invariant.call(void 0, routeId, "No routeId available for fetcher.load()");
1546
- await router.fetch(fetcherKey, routeId, href, opts);
1547
- },
1548
- [fetcherKey, routeId, router]
1549
- );
1550
- let submitImpl = useSubmit();
1551
- let submit = React2.useCallback(
1552
- async (target, opts) => {
1553
- await submitImpl(target, {
1554
- ...opts,
1555
- navigate: false,
1556
- fetcherKey
1557
- });
1558
- },
1559
- [fetcherKey, submitImpl]
1560
- );
1561
- let unstable_reset = React2.useCallback((opts) => router.resetFetcher(fetcherKey, opts), [router, fetcherKey]);
1562
- let FetcherForm = React2.useMemo(() => {
1563
- let FetcherForm2 = React2.forwardRef(
1564
- (props, ref) => {
1565
- return /* @__PURE__ */ React2.createElement(Form, { ...props, navigate: false, fetcherKey, ref });
1566
- }
1567
- );
1568
- FetcherForm2.displayName = "fetcher.Form";
1569
- return FetcherForm2;
1570
- }, [fetcherKey]);
1571
- let fetcher = state.fetchers.get(fetcherKey) || _chunkDI2QHYMJjs.IDLE_FETCHER;
1572
- let data = fetcherData.get(fetcherKey);
1573
- let fetcherWithComponents = React2.useMemo(
1574
- () => ({
1575
- Form: FetcherForm,
1576
- submit,
1577
- load,
1578
- unstable_reset,
1579
- ...fetcher,
1580
- data
1581
- }),
1582
- [FetcherForm, submit, load, unstable_reset, fetcher, data]
1583
- );
1584
- return fetcherWithComponents;
1585
- }
1586
- function useFetchers() {
1587
- let state = useDataRouterState("useFetchers" /* UseFetchers */);
1588
- return Array.from(state.fetchers.entries()).map(([key, fetcher]) => ({
1589
- ...fetcher,
1590
- key
1591
- }));
1592
- }
1593
- var SCROLL_RESTORATION_STORAGE_KEY = "react-router-scroll-positions";
1594
- var savedScrollPositions = {};
1595
- function getScrollRestorationKey(location, matches, basename, getKey) {
1596
- let key = null;
1597
- if (getKey) {
1598
- if (basename !== "/") {
1599
- key = getKey(
1600
- {
1601
- ...location,
1602
- pathname: _chunkDI2QHYMJjs.stripBasename.call(void 0, location.pathname, basename) || location.pathname
1603
- },
1604
- matches
1605
- );
1606
- } else {
1607
- key = getKey(location, matches);
1608
- }
1609
- }
1610
- if (key == null) {
1611
- key = location.key;
1612
- }
1613
- return key;
1614
- }
1615
- function useScrollRestoration({
1616
- getKey,
1617
- storageKey
1618
- } = {}) {
1619
- let { router } = useDataRouterContext("useScrollRestoration" /* UseScrollRestoration */);
1620
- let { restoreScrollPosition, preventScrollReset } = useDataRouterState(
1621
- "useScrollRestoration" /* UseScrollRestoration */
1622
- );
1623
- let { basename } = React2.useContext(_chunkDI2QHYMJjs.NavigationContext);
1624
- let location = _chunkDI2QHYMJjs.useLocation.call(void 0, );
1625
- let matches = _chunkDI2QHYMJjs.useMatches.call(void 0, );
1626
- let navigation = _chunkDI2QHYMJjs.useNavigation.call(void 0, );
1627
- React2.useEffect(() => {
1628
- window.history.scrollRestoration = "manual";
1629
- return () => {
1630
- window.history.scrollRestoration = "auto";
1631
- };
1632
- }, []);
1633
- usePageHide(
1634
- React2.useCallback(() => {
1635
- if (navigation.state === "idle") {
1636
- let key = getScrollRestorationKey(location, matches, basename, getKey);
1637
- savedScrollPositions[key] = window.scrollY;
1638
- }
1639
- try {
1640
- sessionStorage.setItem(
1641
- storageKey || SCROLL_RESTORATION_STORAGE_KEY,
1642
- JSON.stringify(savedScrollPositions)
1643
- );
1644
- } catch (error) {
1645
- _chunkDI2QHYMJjs.warning.call(void 0,
1646
- false,
1647
- `Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly (${error}).`
1648
- );
1649
- }
1650
- window.history.scrollRestoration = "auto";
1651
- }, [navigation.state, getKey, basename, location, matches, storageKey])
1652
- );
1653
- if (typeof document !== "undefined") {
1654
- React2.useLayoutEffect(() => {
1655
- try {
1656
- let sessionPositions = sessionStorage.getItem(
1657
- storageKey || SCROLL_RESTORATION_STORAGE_KEY
1658
- );
1659
- if (sessionPositions) {
1660
- savedScrollPositions = JSON.parse(sessionPositions);
1661
- }
1662
- } catch (e) {
1663
- }
1664
- }, [storageKey]);
1665
- React2.useLayoutEffect(() => {
1666
- let disableScrollRestoration = _optionalChain([router, 'optionalAccess', _43 => _43.enableScrollRestoration, 'call', _44 => _44(
1667
- savedScrollPositions,
1668
- () => window.scrollY,
1669
- getKey ? (location2, matches2) => getScrollRestorationKey(location2, matches2, basename, getKey) : void 0
1670
- )]);
1671
- return () => disableScrollRestoration && disableScrollRestoration();
1672
- }, [router, basename, getKey]);
1673
- React2.useLayoutEffect(() => {
1674
- if (restoreScrollPosition === false) {
1675
- return;
1676
- }
1677
- if (typeof restoreScrollPosition === "number") {
1678
- window.scrollTo(0, restoreScrollPosition);
1679
- return;
1680
- }
1681
- try {
1682
- if (location.hash) {
1683
- let el = document.getElementById(
1684
- decodeURIComponent(location.hash.slice(1))
1685
- );
1686
- if (el) {
1687
- el.scrollIntoView();
1688
- return;
1689
- }
1690
- }
1691
- } catch (e2) {
1692
- _chunkDI2QHYMJjs.warning.call(void 0,
1693
- false,
1694
- `"${location.hash.slice(
1695
- 1
1696
- )}" is not a decodable element ID. The view will not scroll to it.`
1697
- );
1698
- }
1699
- if (preventScrollReset === true) {
1700
- return;
1701
- }
1702
- window.scrollTo(0, 0);
1703
- }, [location, restoreScrollPosition, preventScrollReset]);
1704
- }
1705
- }
1706
- function useBeforeUnload(callback, options) {
1707
- let { capture } = options || {};
1708
- React2.useEffect(() => {
1709
- let opts = capture != null ? { capture } : void 0;
1710
- window.addEventListener("beforeunload", callback, opts);
1711
- return () => {
1712
- window.removeEventListener("beforeunload", callback, opts);
1713
- };
1714
- }, [callback, capture]);
1715
- }
1716
- function usePageHide(callback, options) {
1717
- let { capture } = options || {};
1718
- React2.useEffect(() => {
1719
- let opts = capture != null ? { capture } : void 0;
1720
- window.addEventListener("pagehide", callback, opts);
1721
- return () => {
1722
- window.removeEventListener("pagehide", callback, opts);
1723
- };
1724
- }, [callback, capture]);
1725
- }
1726
- function usePrompt({
1727
- when,
1728
- message
1729
- }) {
1730
- let blocker = _chunkDI2QHYMJjs.useBlocker.call(void 0, when);
1731
- React2.useEffect(() => {
1732
- if (blocker.state === "blocked") {
1733
- let proceed = window.confirm(message);
1734
- if (proceed) {
1735
- setTimeout(blocker.proceed, 0);
1736
- } else {
1737
- blocker.reset();
1738
- }
1739
- }
1740
- }, [blocker, message]);
1741
- React2.useEffect(() => {
1742
- if (blocker.state === "blocked" && !when) {
1743
- blocker.reset();
1744
- }
1745
- }, [blocker, when]);
1746
- }
1747
- function useViewTransitionState(to, { relative } = {}) {
1748
- let vtContext = React2.useContext(_chunkDI2QHYMJjs.ViewTransitionContext);
1749
- _chunkDI2QHYMJjs.invariant.call(void 0,
1750
- vtContext != null,
1751
- "`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?"
1752
- );
1753
- let { basename } = useDataRouterContext(
1754
- "useViewTransitionState" /* useViewTransitionState */
1755
- );
1756
- let path = _chunkDI2QHYMJjs.useResolvedPath.call(void 0, to, { relative });
1757
- if (!vtContext.isTransitioning) {
1758
- return false;
1759
- }
1760
- let currentPath = _chunkDI2QHYMJjs.stripBasename.call(void 0, vtContext.currentLocation.pathname, basename) || vtContext.currentLocation.pathname;
1761
- let nextPath = _chunkDI2QHYMJjs.stripBasename.call(void 0, vtContext.nextLocation.pathname, basename) || vtContext.nextLocation.pathname;
1762
- return _chunkDI2QHYMJjs.matchPath.call(void 0, path.pathname, nextPath) != null || _chunkDI2QHYMJjs.matchPath.call(void 0, path.pathname, currentPath) != null;
1763
- }
1764
-
1765
- // lib/dom/server.tsx
1766
-
1767
- function StaticRouter({
1768
- basename,
1769
- children,
1770
- location: locationProp = "/"
1771
- }) {
1772
- if (typeof locationProp === "string") {
1773
- locationProp = _chunkDI2QHYMJjs.parsePath.call(void 0, locationProp);
1774
- }
1775
- let action = "POP" /* Pop */;
1776
- let location = {
1777
- pathname: locationProp.pathname || "/",
1778
- search: locationProp.search || "",
1779
- hash: locationProp.hash || "",
1780
- state: locationProp.state != null ? locationProp.state : null,
1781
- key: locationProp.key || "default"
1782
- };
1783
- let staticNavigator = getStatelessNavigator();
1784
- return /* @__PURE__ */ React3.createElement(
1785
- Router,
1786
- {
1787
- basename,
1788
- children,
1789
- location,
1790
- navigationType: action,
1791
- navigator: staticNavigator,
1792
- static: true
1793
- }
1794
- );
1795
- }
1796
- function StaticRouterProvider({
1797
- context,
1798
- router,
1799
- hydrate = true,
1800
- nonce
1801
- }) {
1802
- _chunkDI2QHYMJjs.invariant.call(void 0,
1803
- router && context,
1804
- "You must provide `router` and `context` to <StaticRouterProvider>"
1805
- );
1806
- let dataRouterContext = {
1807
- router,
1808
- navigator: getStatelessNavigator(),
1809
- static: true,
1810
- staticContext: context,
1811
- basename: context.basename || "/"
1812
- };
1813
- let fetchersContext = /* @__PURE__ */ new Map();
1814
- let hydrateScript = "";
1815
- if (hydrate !== false) {
1816
- let data = {
1817
- loaderData: context.loaderData,
1818
- actionData: context.actionData,
1819
- errors: serializeErrors(context.errors)
1820
- };
1821
- let json = htmlEscape(JSON.stringify(JSON.stringify(data)));
1822
- hydrateScript = `window.__staticRouterHydrationData = JSON.parse(${json});`;
1823
- }
1824
- let { state } = dataRouterContext.router;
1825
- return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(_chunkDI2QHYMJjs.DataRouterContext.Provider, { value: dataRouterContext }, /* @__PURE__ */ React3.createElement(_chunkDI2QHYMJjs.DataRouterStateContext.Provider, { value: state }, /* @__PURE__ */ React3.createElement(_chunkDI2QHYMJjs.FetchersContext.Provider, { value: fetchersContext }, /* @__PURE__ */ React3.createElement(_chunkDI2QHYMJjs.ViewTransitionContext.Provider, { value: { isTransitioning: false } }, /* @__PURE__ */ React3.createElement(
1826
- Router,
1827
- {
1828
- basename: dataRouterContext.basename,
1829
- location: state.location,
1830
- navigationType: state.historyAction,
1831
- navigator: dataRouterContext.navigator,
1832
- static: dataRouterContext.static
1833
- },
1834
- /* @__PURE__ */ React3.createElement(
1835
- DataRoutes2,
1836
- {
1837
- routes: router.routes,
1838
- future: router.future,
1839
- state
1840
- }
1841
- )
1842
- ))))), hydrateScript ? /* @__PURE__ */ React3.createElement(
1843
- "script",
1844
- {
1845
- suppressHydrationWarning: true,
1846
- nonce,
1847
- dangerouslySetInnerHTML: { __html: hydrateScript }
1848
- }
1849
- ) : null);
1850
- }
1851
- function DataRoutes2({
1852
- routes,
1853
- future,
1854
- state
1855
- }) {
1856
- return _chunkDI2QHYMJjs.useRoutesImpl.call(void 0, routes, void 0, state, void 0, future);
1857
- }
1858
- function serializeErrors(errors) {
1859
- if (!errors) return null;
1860
- let entries = Object.entries(errors);
1861
- let serialized = {};
1862
- for (let [key, val] of entries) {
1863
- if (_chunkDI2QHYMJjs.isRouteErrorResponse.call(void 0, val)) {
1864
- serialized[key] = { ...val, __type: "RouteErrorResponse" };
1865
- } else if (val instanceof Error) {
1866
- serialized[key] = {
1867
- message: val.message,
1868
- __type: "Error",
1869
- // If this is a subclass (i.e., ReferenceError), send up the type so we
1870
- // can re-create the same type during hydration.
1871
- ...val.name !== "Error" ? {
1872
- __subType: val.name
1873
- } : {}
1874
- };
1875
- } else {
1876
- serialized[key] = val;
1877
- }
1878
- }
1879
- return serialized;
1880
- }
1881
- function getStatelessNavigator() {
1882
- return {
1883
- createHref,
1884
- encodeLocation,
1885
- push(to) {
1886
- throw new Error(
1887
- `You cannot use navigator.push() on the server because it is a stateless environment. This error was probably triggered when you did a \`navigate(${JSON.stringify(to)})\` somewhere in your app.`
1888
- );
1889
- },
1890
- replace(to) {
1891
- throw new Error(
1892
- `You cannot use navigator.replace() on the server because it is a stateless environment. This error was probably triggered when you did a \`navigate(${JSON.stringify(to)}, { replace: true })\` somewhere in your app.`
1893
- );
1894
- },
1895
- go(delta) {
1896
- throw new Error(
1897
- `You cannot use navigator.go() on the server because it is a stateless environment. This error was probably triggered when you did a \`navigate(${delta})\` somewhere in your app.`
1898
- );
1899
- },
1900
- back() {
1901
- throw new Error(
1902
- `You cannot use navigator.back() on the server because it is a stateless environment.`
1903
- );
1904
- },
1905
- forward() {
1906
- throw new Error(
1907
- `You cannot use navigator.forward() on the server because it is a stateless environment.`
1908
- );
1909
- }
1910
- };
1911
- }
1912
- function createStaticHandler2(routes, opts) {
1913
- return _chunkDI2QHYMJjs.createStaticHandler.call(void 0, routes, {
1914
- ...opts,
1915
- mapRouteProperties
1916
- });
1917
- }
1918
- function createStaticRouter(routes, context, opts = {}) {
1919
- let manifest = {};
1920
- let dataRoutes = _chunkDI2QHYMJjs.convertRoutesToDataRoutes.call(void 0,
1921
- routes,
1922
- mapRouteProperties,
1923
- void 0,
1924
- manifest
1925
- );
1926
- let matches = context.matches.map((match) => {
1927
- let route = manifest[match.route.id] || match.route;
1928
- return {
1929
- ...match,
1930
- route
1931
- };
1932
- });
1933
- let msg = (method) => `You cannot use router.${method}() on the server because it is a stateless environment`;
1934
- return {
1935
- get basename() {
1936
- return context.basename;
1937
- },
1938
- get future() {
1939
- return {
1940
- v8_middleware: false,
1941
- ..._optionalChain([opts, 'optionalAccess', _45 => _45.future])
1942
- };
1943
- },
1944
- get state() {
1945
- return {
1946
- historyAction: "POP" /* Pop */,
1947
- location: context.location,
1948
- matches,
1949
- loaderData: context.loaderData,
1950
- actionData: context.actionData,
1951
- errors: context.errors,
1952
- initialized: true,
1953
- navigation: _chunkDI2QHYMJjs.IDLE_NAVIGATION,
1954
- restoreScrollPosition: null,
1955
- preventScrollReset: false,
1956
- revalidation: "idle",
1957
- fetchers: /* @__PURE__ */ new Map(),
1958
- blockers: /* @__PURE__ */ new Map()
1959
- };
1960
- },
1961
- get routes() {
1962
- return dataRoutes;
1963
- },
1964
- get window() {
1965
- return void 0;
1966
- },
1967
- initialize() {
1968
- throw msg("initialize");
1969
- },
1970
- subscribe() {
1971
- throw msg("subscribe");
1972
- },
1973
- enableScrollRestoration() {
1974
- throw msg("enableScrollRestoration");
1975
- },
1976
- navigate() {
1977
- throw msg("navigate");
1978
- },
1979
- fetch() {
1980
- throw msg("fetch");
1981
- },
1982
- revalidate() {
1983
- throw msg("revalidate");
1984
- },
1985
- createHref,
1986
- encodeLocation,
1987
- getFetcher() {
1988
- return _chunkDI2QHYMJjs.IDLE_FETCHER;
1989
- },
1990
- deleteFetcher() {
1991
- throw msg("deleteFetcher");
1992
- },
1993
- resetFetcher() {
1994
- throw msg("resetFetcher");
1995
- },
1996
- dispose() {
1997
- throw msg("dispose");
1998
- },
1999
- getBlocker() {
2000
- return _chunkDI2QHYMJjs.IDLE_BLOCKER;
2001
- },
2002
- deleteBlocker() {
2003
- throw msg("deleteBlocker");
2004
- },
2005
- patchRoutes() {
2006
- throw msg("patchRoutes");
2007
- },
2008
- _internalFetchControllers: /* @__PURE__ */ new Map(),
2009
- _internalSetRoutes() {
2010
- throw msg("_internalSetRoutes");
2011
- },
2012
- _internalSetStateDoNotUseOrYouWillBreakYourApp() {
2013
- throw msg("_internalSetStateDoNotUseOrYouWillBreakYourApp");
2014
- }
2015
- };
2016
- }
2017
- function createHref(to) {
2018
- return typeof to === "string" ? to : _chunkDI2QHYMJjs.createPath.call(void 0, to);
2019
- }
2020
- function encodeLocation(to) {
2021
- let href = typeof to === "string" ? to : _chunkDI2QHYMJjs.createPath.call(void 0, to);
2022
- href = href.replace(/ $/, "%20");
2023
- let encoded = ABSOLUTE_URL_REGEX2.test(href) ? new URL(href) : new URL(href, "http://localhost");
2024
- return {
2025
- pathname: encoded.pathname,
2026
- search: encoded.search,
2027
- hash: encoded.hash
2028
- };
2029
- }
2030
- var ABSOLUTE_URL_REGEX2 = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
2031
- var ESCAPE_LOOKUP = {
2032
- "&": "\\u0026",
2033
- ">": "\\u003e",
2034
- "<": "\\u003c",
2035
- "\u2028": "\\u2028",
2036
- "\u2029": "\\u2029"
2037
- };
2038
- var ESCAPE_REGEX = /[&><\u2028\u2029]/g;
2039
- function htmlEscape(str) {
2040
- return str.replace(ESCAPE_REGEX, (match) => ESCAPE_LOOKUP[match]);
2041
- }
2042
-
2043
-
2044
-
2045
-
2046
-
2047
-
2048
-
2049
-
2050
-
2051
-
2052
-
2053
-
2054
-
2055
-
2056
-
2057
-
2058
-
2059
-
2060
-
2061
-
2062
-
2063
-
2064
-
2065
-
2066
-
2067
-
2068
-
2069
-
2070
-
2071
-
2072
-
2073
-
2074
-
2075
-
2076
-
2077
-
2078
-
2079
-
2080
-
2081
-
2082
-
2083
-
2084
-
2085
-
2086
-
2087
-
2088
-
2089
- exports.mapRouteProperties = mapRouteProperties; exports.hydrationRouteProperties = hydrationRouteProperties; exports.createMemoryRouter = createMemoryRouter; exports.UNSTABLE_TransitionEnabledRouterProvider = UNSTABLE_TransitionEnabledRouterProvider; exports.RouterProvider = RouterProvider; exports.MemoryRouter = MemoryRouter; exports.Navigate = Navigate; exports.Outlet = Outlet; exports.Route = Route; exports.Router = Router; exports.Routes = Routes; exports.Await = Await; exports.createRoutesFromChildren = createRoutesFromChildren; exports.createRoutesFromElements = createRoutesFromElements; exports.renderMatches = renderMatches; exports.WithComponentProps = WithComponentProps; exports.withComponentProps = withComponentProps; exports.WithHydrateFallbackProps = WithHydrateFallbackProps; exports.withHydrateFallbackProps = withHydrateFallbackProps; exports.WithErrorBoundaryProps = WithErrorBoundaryProps; exports.withErrorBoundaryProps = withErrorBoundaryProps; exports.createSearchParams = createSearchParams; exports.createBrowserRouter = createBrowserRouter; exports.createHashRouter = createHashRouter; exports.BrowserRouter = BrowserRouter; exports.HashRouter = HashRouter; exports.HistoryRouter = HistoryRouter; exports.Link = Link; exports.NavLink = NavLink; exports.Form = Form; exports.ScrollRestoration = ScrollRestoration; exports.useLinkClickHandler = useLinkClickHandler; exports.useSearchParams = useSearchParams; exports.useSubmit = useSubmit; exports.useFormAction = useFormAction; exports.useFetcher = useFetcher; exports.useFetchers = useFetchers; exports.useScrollRestoration = useScrollRestoration; exports.useBeforeUnload = useBeforeUnload; exports.usePrompt = usePrompt; exports.useViewTransitionState = useViewTransitionState; exports.StaticRouter = StaticRouter; exports.StaticRouterProvider = StaticRouterProvider; exports.createStaticHandler = createStaticHandler2; exports.createStaticRouter = createStaticRouter;