react-router 0.0.0-experimental-e0b6ce9 → 0.0.0-experimental-de3b900

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