@tanstack/react-router 0.0.1-beta.25 → 0.0.1-beta.250

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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/build/cjs/CatchBoundary.js +128 -0
  3. package/build/cjs/CatchBoundary.js.map +1 -0
  4. package/build/cjs/Matches.js +244 -0
  5. package/build/cjs/Matches.js.map +1 -0
  6. package/build/cjs/RouterProvider.js +159 -0
  7. package/build/cjs/RouterProvider.js.map +1 -0
  8. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +2 -22
  9. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  10. package/build/cjs/awaited.js +43 -0
  11. package/build/cjs/awaited.js.map +1 -0
  12. package/build/cjs/defer.js +37 -0
  13. package/build/cjs/defer.js.map +1 -0
  14. package/build/cjs/fileRoute.js +27 -0
  15. package/build/cjs/fileRoute.js.map +1 -0
  16. package/build/cjs/index.js +125 -0
  17. package/build/cjs/index.js.map +1 -0
  18. package/build/cjs/lazyRouteComponent.js +54 -0
  19. package/build/cjs/lazyRouteComponent.js.map +1 -0
  20. package/build/cjs/link.js +149 -0
  21. package/build/cjs/link.js.map +1 -0
  22. package/build/cjs/path.js +214 -0
  23. package/build/cjs/path.js.map +1 -0
  24. package/build/cjs/qss.js +63 -0
  25. package/build/cjs/qss.js.map +1 -0
  26. package/build/cjs/redirects.js +25 -0
  27. package/build/cjs/redirects.js.map +1 -0
  28. package/build/cjs/route.js +139 -0
  29. package/build/cjs/route.js.map +1 -0
  30. package/build/cjs/router.js +1134 -0
  31. package/build/cjs/router.js.map +1 -0
  32. package/build/cjs/scroll-restoration.js +202 -0
  33. package/build/cjs/scroll-restoration.js.map +1 -0
  34. package/build/cjs/searchParams.js +81 -0
  35. package/build/cjs/searchParams.js.map +1 -0
  36. package/build/cjs/useBlocker.js +55 -0
  37. package/build/cjs/useBlocker.js.map +1 -0
  38. package/build/cjs/useNavigate.js +76 -0
  39. package/build/cjs/useNavigate.js.map +1 -0
  40. package/build/cjs/useParams.js +26 -0
  41. package/build/cjs/useParams.js.map +1 -0
  42. package/build/cjs/useSearch.js +25 -0
  43. package/build/cjs/useSearch.js.map +1 -0
  44. package/build/cjs/utils.js +239 -0
  45. package/build/cjs/utils.js.map +1 -0
  46. package/build/esm/index.js +2202 -2536
  47. package/build/esm/index.js.map +1 -1
  48. package/build/stats-html.html +3498 -2694
  49. package/build/stats-react.json +1216 -44
  50. package/build/types/CatchBoundary.d.ts +36 -0
  51. package/build/types/Matches.d.ts +57 -0
  52. package/build/types/RouterProvider.d.ts +36 -0
  53. package/build/types/awaited.d.ts +9 -0
  54. package/build/types/defer.d.ts +19 -0
  55. package/build/types/fileRoute.d.ts +34 -0
  56. package/build/types/history.d.ts +7 -0
  57. package/build/types/index.d.ts +27 -114
  58. package/build/types/injectHtml.d.ts +0 -0
  59. package/build/types/lazyRouteComponent.d.ts +2 -0
  60. package/build/types/link.d.ts +105 -0
  61. package/build/types/location.d.ts +14 -0
  62. package/build/types/path.d.ts +17 -0
  63. package/build/types/qss.d.ts +2 -0
  64. package/build/types/redirects.d.ts +10 -0
  65. package/build/types/route.d.ts +279 -0
  66. package/build/types/routeInfo.d.ts +22 -0
  67. package/build/types/router.d.ts +183 -0
  68. package/build/types/scroll-restoration.d.ts +18 -0
  69. package/build/types/searchParams.d.ts +7 -0
  70. package/build/types/useBlocker.d.ts +8 -0
  71. package/build/types/useNavigate.d.ts +20 -0
  72. package/build/types/useParams.d.ts +7 -0
  73. package/build/types/useSearch.d.ts +7 -0
  74. package/build/types/utils.d.ts +66 -0
  75. package/build/umd/index.development.js +2774 -2484
  76. package/build/umd/index.development.js.map +1 -1
  77. package/build/umd/index.production.js +4 -4
  78. package/build/umd/index.production.js.map +1 -1
  79. package/package.json +11 -10
  80. package/src/CatchBoundary.tsx +101 -0
  81. package/src/Matches.tsx +428 -0
  82. package/src/RouterProvider.tsx +241 -0
  83. package/src/awaited.tsx +40 -0
  84. package/src/defer.ts +55 -0
  85. package/src/fileRoute.ts +154 -0
  86. package/src/history.ts +8 -0
  87. package/src/index.tsx +28 -714
  88. package/src/injectHtml.ts +28 -0
  89. package/src/lazyRouteComponent.tsx +33 -0
  90. package/src/link.tsx +509 -0
  91. package/src/location.ts +15 -0
  92. package/src/path.ts +261 -0
  93. package/src/qss.ts +53 -0
  94. package/src/redirects.ts +31 -0
  95. package/src/route.ts +911 -0
  96. package/src/routeInfo.ts +68 -0
  97. package/src/router.ts +1734 -0
  98. package/src/scroll-restoration.tsx +230 -0
  99. package/src/searchParams.ts +79 -0
  100. package/src/useBlocker.tsx +26 -0
  101. package/src/useNavigate.tsx +110 -0
  102. package/src/useParams.tsx +25 -0
  103. package/src/useSearch.tsx +25 -0
  104. package/src/utils.ts +350 -0
  105. package/build/cjs/react-router/src/index.js +0 -473
  106. package/build/cjs/react-router/src/index.js.map +0 -1
  107. package/build/cjs/router-core/build/esm/index.js +0 -2528
  108. package/build/cjs/router-core/build/esm/index.js.map +0 -1
@@ -1,2528 +0,0 @@
1
- /**
2
- * react-router
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- /**
16
- * router-core
17
- *
18
- * Copyright (c) TanStack
19
- *
20
- * This source code is licensed under the MIT license found in the
21
- * LICENSE.md file in the root directory of this source tree.
22
- *
23
- * @license MIT
24
- */
25
- function _extends$1() {
26
- _extends$1 = Object.assign ? Object.assign.bind() : function (target) {
27
- for (var i = 1; i < arguments.length; i++) {
28
- var source = arguments[i];
29
-
30
- for (var key in source) {
31
- if (Object.prototype.hasOwnProperty.call(source, key)) {
32
- target[key] = source[key];
33
- }
34
- }
35
- }
36
-
37
- return target;
38
- };
39
- return _extends$1.apply(this, arguments);
40
- }
41
-
42
- /**
43
- * Actions represent the type of change to a location value.
44
- *
45
- * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#action
46
- */
47
- var Action;
48
-
49
- (function (Action) {
50
- /**
51
- * A POP indicates a change to an arbitrary index in the history stack, such
52
- * as a back or forward navigation. It does not describe the direction of the
53
- * navigation, only that the current index changed.
54
- *
55
- * Note: This is the default action for newly created history objects.
56
- */
57
- Action["Pop"] = "POP";
58
- /**
59
- * A PUSH indicates a new entry being added to the history stack, such as when
60
- * a link is clicked and a new page loads. When this happens, all subsequent
61
- * entries in the stack are lost.
62
- */
63
-
64
- Action["Push"] = "PUSH";
65
- /**
66
- * A REPLACE indicates the entry at the current index in the history stack
67
- * being replaced by a new one.
68
- */
69
-
70
- Action["Replace"] = "REPLACE";
71
- })(Action || (Action = {}));
72
-
73
- var readOnly = process.env.NODE_ENV !== "production" ? function (obj) {
74
- return Object.freeze(obj);
75
- } : function (obj) {
76
- return obj;
77
- };
78
-
79
- function warning$1(cond, message) {
80
- if (!cond) {
81
- // eslint-disable-next-line no-console
82
- if (typeof console !== 'undefined') console.warn(message);
83
-
84
- try {
85
- // Welcome to debugging history!
86
- //
87
- // This error is thrown as a convenience so you can more easily
88
- // find the source for a warning that appears in the console by
89
- // enabling "pause on exceptions" in your JavaScript debugger.
90
- throw new Error(message); // eslint-disable-next-line no-empty
91
- } catch (e) {}
92
- }
93
- }
94
-
95
- var BeforeUnloadEventType = 'beforeunload';
96
- var HashChangeEventType = 'hashchange';
97
- var PopStateEventType = 'popstate';
98
- /**
99
- * Browser history stores the location in regular URLs. This is the standard for
100
- * most web apps, but it requires some configuration on the server to ensure you
101
- * serve the same app at multiple URLs.
102
- *
103
- * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
104
- */
105
-
106
- function createBrowserHistory(options) {
107
- if (options === void 0) {
108
- options = {};
109
- }
110
-
111
- var _options = options,
112
- _options$window = _options.window,
113
- window = _options$window === void 0 ? document.defaultView : _options$window;
114
- var globalHistory = window.history;
115
-
116
- function getIndexAndLocation() {
117
- var _window$location = window.location,
118
- pathname = _window$location.pathname,
119
- search = _window$location.search,
120
- hash = _window$location.hash;
121
- var state = globalHistory.state || {};
122
- return [state.idx, readOnly({
123
- pathname: pathname,
124
- search: search,
125
- hash: hash,
126
- state: state.usr || null,
127
- key: state.key || 'default'
128
- })];
129
- }
130
-
131
- var blockedPopTx = null;
132
-
133
- function handlePop() {
134
- if (blockedPopTx) {
135
- blockers.call(blockedPopTx);
136
- blockedPopTx = null;
137
- } else {
138
- var nextAction = Action.Pop;
139
-
140
- var _getIndexAndLocation = getIndexAndLocation(),
141
- nextIndex = _getIndexAndLocation[0],
142
- nextLocation = _getIndexAndLocation[1];
143
-
144
- if (blockers.length) {
145
- if (nextIndex != null) {
146
- var delta = index - nextIndex;
147
-
148
- if (delta) {
149
- // Revert the POP
150
- blockedPopTx = {
151
- action: nextAction,
152
- location: nextLocation,
153
- retry: function retry() {
154
- go(delta * -1);
155
- }
156
- };
157
- go(delta);
158
- }
159
- } else {
160
- // Trying to POP to a location with no index. We did not create
161
- // this location, so we can't effectively block the navigation.
162
- process.env.NODE_ENV !== "production" ? warning$1(false, // TODO: Write up a doc that explains our blocking strategy in
163
- // detail and link to it here so people can understand better what
164
- // is going on and how to avoid it.
165
- "You are trying to block a POP navigation to a location that was not " + "created by the history library. The block will fail silently in " + "production, but in general you should do all navigation with the " + "history library (instead of using window.history.pushState directly) " + "to avoid this situation.") : void 0;
166
- }
167
- } else {
168
- applyTx(nextAction);
169
- }
170
- }
171
- }
172
-
173
- window.addEventListener(PopStateEventType, handlePop);
174
- var action = Action.Pop;
175
-
176
- var _getIndexAndLocation2 = getIndexAndLocation(),
177
- index = _getIndexAndLocation2[0],
178
- location = _getIndexAndLocation2[1];
179
-
180
- var listeners = createEvents();
181
- var blockers = createEvents();
182
-
183
- if (index == null) {
184
- index = 0;
185
- globalHistory.replaceState(_extends$1({}, globalHistory.state, {
186
- idx: index
187
- }), '');
188
- }
189
-
190
- function createHref(to) {
191
- return typeof to === 'string' ? to : createPath(to);
192
- } // state defaults to `null` because `window.history.state` does
193
-
194
-
195
- function getNextLocation(to, state) {
196
- if (state === void 0) {
197
- state = null;
198
- }
199
-
200
- return readOnly(_extends$1({
201
- pathname: location.pathname,
202
- hash: '',
203
- search: ''
204
- }, typeof to === 'string' ? parsePath(to) : to, {
205
- state: state,
206
- key: createKey()
207
- }));
208
- }
209
-
210
- function getHistoryStateAndUrl(nextLocation, index) {
211
- return [{
212
- usr: nextLocation.state,
213
- key: nextLocation.key,
214
- idx: index
215
- }, createHref(nextLocation)];
216
- }
217
-
218
- function allowTx(action, location, retry) {
219
- return !blockers.length || (blockers.call({
220
- action: action,
221
- location: location,
222
- retry: retry
223
- }), false);
224
- }
225
-
226
- function applyTx(nextAction) {
227
- action = nextAction;
228
-
229
- var _getIndexAndLocation3 = getIndexAndLocation();
230
-
231
- index = _getIndexAndLocation3[0];
232
- location = _getIndexAndLocation3[1];
233
- listeners.call({
234
- action: action,
235
- location: location
236
- });
237
- }
238
-
239
- function push(to, state) {
240
- var nextAction = Action.Push;
241
- var nextLocation = getNextLocation(to, state);
242
-
243
- function retry() {
244
- push(to, state);
245
- }
246
-
247
- if (allowTx(nextAction, nextLocation, retry)) {
248
- var _getHistoryStateAndUr = getHistoryStateAndUrl(nextLocation, index + 1),
249
- historyState = _getHistoryStateAndUr[0],
250
- url = _getHistoryStateAndUr[1]; // TODO: Support forced reloading
251
- // try...catch because iOS limits us to 100 pushState calls :/
252
-
253
-
254
- try {
255
- globalHistory.pushState(historyState, '', url);
256
- } catch (error) {
257
- // They are going to lose state here, but there is no real
258
- // way to warn them about it since the page will refresh...
259
- window.location.assign(url);
260
- }
261
-
262
- applyTx(nextAction);
263
- }
264
- }
265
-
266
- function replace(to, state) {
267
- var nextAction = Action.Replace;
268
- var nextLocation = getNextLocation(to, state);
269
-
270
- function retry() {
271
- replace(to, state);
272
- }
273
-
274
- if (allowTx(nextAction, nextLocation, retry)) {
275
- var _getHistoryStateAndUr2 = getHistoryStateAndUrl(nextLocation, index),
276
- historyState = _getHistoryStateAndUr2[0],
277
- url = _getHistoryStateAndUr2[1]; // TODO: Support forced reloading
278
-
279
-
280
- globalHistory.replaceState(historyState, '', url);
281
- applyTx(nextAction);
282
- }
283
- }
284
-
285
- function go(delta) {
286
- globalHistory.go(delta);
287
- }
288
-
289
- var history = {
290
- get action() {
291
- return action;
292
- },
293
-
294
- get location() {
295
- return location;
296
- },
297
-
298
- createHref: createHref,
299
- push: push,
300
- replace: replace,
301
- go: go,
302
- back: function back() {
303
- go(-1);
304
- },
305
- forward: function forward() {
306
- go(1);
307
- },
308
- listen: function listen(listener) {
309
- return listeners.push(listener);
310
- },
311
- block: function block(blocker) {
312
- var unblock = blockers.push(blocker);
313
-
314
- if (blockers.length === 1) {
315
- window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
316
- }
317
-
318
- return function () {
319
- unblock(); // Remove the beforeunload listener so the document may
320
- // still be salvageable in the pagehide event.
321
- // See https://html.spec.whatwg.org/#unloading-documents
322
-
323
- if (!blockers.length) {
324
- window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
325
- }
326
- };
327
- }
328
- };
329
- return history;
330
- }
331
- /**
332
- * Hash history stores the location in window.location.hash. This makes it ideal
333
- * for situations where you don't want to send the location to the server for
334
- * some reason, either because you do cannot configure it or the URL space is
335
- * reserved for something else.
336
- *
337
- * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
338
- */
339
-
340
- function createHashHistory(options) {
341
- if (options === void 0) {
342
- options = {};
343
- }
344
-
345
- var _options2 = options,
346
- _options2$window = _options2.window,
347
- window = _options2$window === void 0 ? document.defaultView : _options2$window;
348
- var globalHistory = window.history;
349
-
350
- function getIndexAndLocation() {
351
- var _parsePath = parsePath(window.location.hash.substr(1)),
352
- _parsePath$pathname = _parsePath.pathname,
353
- pathname = _parsePath$pathname === void 0 ? '/' : _parsePath$pathname,
354
- _parsePath$search = _parsePath.search,
355
- search = _parsePath$search === void 0 ? '' : _parsePath$search,
356
- _parsePath$hash = _parsePath.hash,
357
- hash = _parsePath$hash === void 0 ? '' : _parsePath$hash;
358
-
359
- var state = globalHistory.state || {};
360
- return [state.idx, readOnly({
361
- pathname: pathname,
362
- search: search,
363
- hash: hash,
364
- state: state.usr || null,
365
- key: state.key || 'default'
366
- })];
367
- }
368
-
369
- var blockedPopTx = null;
370
-
371
- function handlePop() {
372
- if (blockedPopTx) {
373
- blockers.call(blockedPopTx);
374
- blockedPopTx = null;
375
- } else {
376
- var nextAction = Action.Pop;
377
-
378
- var _getIndexAndLocation4 = getIndexAndLocation(),
379
- nextIndex = _getIndexAndLocation4[0],
380
- nextLocation = _getIndexAndLocation4[1];
381
-
382
- if (blockers.length) {
383
- if (nextIndex != null) {
384
- var delta = index - nextIndex;
385
-
386
- if (delta) {
387
- // Revert the POP
388
- blockedPopTx = {
389
- action: nextAction,
390
- location: nextLocation,
391
- retry: function retry() {
392
- go(delta * -1);
393
- }
394
- };
395
- go(delta);
396
- }
397
- } else {
398
- // Trying to POP to a location with no index. We did not create
399
- // this location, so we can't effectively block the navigation.
400
- process.env.NODE_ENV !== "production" ? warning$1(false, // TODO: Write up a doc that explains our blocking strategy in
401
- // detail and link to it here so people can understand better
402
- // what is going on and how to avoid it.
403
- "You are trying to block a POP navigation to a location that was not " + "created by the history library. The block will fail silently in " + "production, but in general you should do all navigation with the " + "history library (instead of using window.history.pushState directly) " + "to avoid this situation.") : void 0;
404
- }
405
- } else {
406
- applyTx(nextAction);
407
- }
408
- }
409
- }
410
-
411
- window.addEventListener(PopStateEventType, handlePop); // popstate does not fire on hashchange in IE 11 and old (trident) Edge
412
- // https://developer.mozilla.org/de/docs/Web/API/Window/popstate_event
413
-
414
- window.addEventListener(HashChangeEventType, function () {
415
- var _getIndexAndLocation5 = getIndexAndLocation(),
416
- nextLocation = _getIndexAndLocation5[1]; // Ignore extraneous hashchange events.
417
-
418
-
419
- if (createPath(nextLocation) !== createPath(location)) {
420
- handlePop();
421
- }
422
- });
423
- var action = Action.Pop;
424
-
425
- var _getIndexAndLocation6 = getIndexAndLocation(),
426
- index = _getIndexAndLocation6[0],
427
- location = _getIndexAndLocation6[1];
428
-
429
- var listeners = createEvents();
430
- var blockers = createEvents();
431
-
432
- if (index == null) {
433
- index = 0;
434
- globalHistory.replaceState(_extends$1({}, globalHistory.state, {
435
- idx: index
436
- }), '');
437
- }
438
-
439
- function getBaseHref() {
440
- var base = document.querySelector('base');
441
- var href = '';
442
-
443
- if (base && base.getAttribute('href')) {
444
- var url = window.location.href;
445
- var hashIndex = url.indexOf('#');
446
- href = hashIndex === -1 ? url : url.slice(0, hashIndex);
447
- }
448
-
449
- return href;
450
- }
451
-
452
- function createHref(to) {
453
- return getBaseHref() + '#' + (typeof to === 'string' ? to : createPath(to));
454
- }
455
-
456
- function getNextLocation(to, state) {
457
- if (state === void 0) {
458
- state = null;
459
- }
460
-
461
- return readOnly(_extends$1({
462
- pathname: location.pathname,
463
- hash: '',
464
- search: ''
465
- }, typeof to === 'string' ? parsePath(to) : to, {
466
- state: state,
467
- key: createKey()
468
- }));
469
- }
470
-
471
- function getHistoryStateAndUrl(nextLocation, index) {
472
- return [{
473
- usr: nextLocation.state,
474
- key: nextLocation.key,
475
- idx: index
476
- }, createHref(nextLocation)];
477
- }
478
-
479
- function allowTx(action, location, retry) {
480
- return !blockers.length || (blockers.call({
481
- action: action,
482
- location: location,
483
- retry: retry
484
- }), false);
485
- }
486
-
487
- function applyTx(nextAction) {
488
- action = nextAction;
489
-
490
- var _getIndexAndLocation7 = getIndexAndLocation();
491
-
492
- index = _getIndexAndLocation7[0];
493
- location = _getIndexAndLocation7[1];
494
- listeners.call({
495
- action: action,
496
- location: location
497
- });
498
- }
499
-
500
- function push(to, state) {
501
- var nextAction = Action.Push;
502
- var nextLocation = getNextLocation(to, state);
503
-
504
- function retry() {
505
- push(to, state);
506
- }
507
-
508
- process.env.NODE_ENV !== "production" ? warning$1(nextLocation.pathname.charAt(0) === '/', "Relative pathnames are not supported in hash history.push(" + JSON.stringify(to) + ")") : void 0;
509
-
510
- if (allowTx(nextAction, nextLocation, retry)) {
511
- var _getHistoryStateAndUr3 = getHistoryStateAndUrl(nextLocation, index + 1),
512
- historyState = _getHistoryStateAndUr3[0],
513
- url = _getHistoryStateAndUr3[1]; // TODO: Support forced reloading
514
- // try...catch because iOS limits us to 100 pushState calls :/
515
-
516
-
517
- try {
518
- globalHistory.pushState(historyState, '', url);
519
- } catch (error) {
520
- // They are going to lose state here, but there is no real
521
- // way to warn them about it since the page will refresh...
522
- window.location.assign(url);
523
- }
524
-
525
- applyTx(nextAction);
526
- }
527
- }
528
-
529
- function replace(to, state) {
530
- var nextAction = Action.Replace;
531
- var nextLocation = getNextLocation(to, state);
532
-
533
- function retry() {
534
- replace(to, state);
535
- }
536
-
537
- process.env.NODE_ENV !== "production" ? warning$1(nextLocation.pathname.charAt(0) === '/', "Relative pathnames are not supported in hash history.replace(" + JSON.stringify(to) + ")") : void 0;
538
-
539
- if (allowTx(nextAction, nextLocation, retry)) {
540
- var _getHistoryStateAndUr4 = getHistoryStateAndUrl(nextLocation, index),
541
- historyState = _getHistoryStateAndUr4[0],
542
- url = _getHistoryStateAndUr4[1]; // TODO: Support forced reloading
543
-
544
-
545
- globalHistory.replaceState(historyState, '', url);
546
- applyTx(nextAction);
547
- }
548
- }
549
-
550
- function go(delta) {
551
- globalHistory.go(delta);
552
- }
553
-
554
- var history = {
555
- get action() {
556
- return action;
557
- },
558
-
559
- get location() {
560
- return location;
561
- },
562
-
563
- createHref: createHref,
564
- push: push,
565
- replace: replace,
566
- go: go,
567
- back: function back() {
568
- go(-1);
569
- },
570
- forward: function forward() {
571
- go(1);
572
- },
573
- listen: function listen(listener) {
574
- return listeners.push(listener);
575
- },
576
- block: function block(blocker) {
577
- var unblock = blockers.push(blocker);
578
-
579
- if (blockers.length === 1) {
580
- window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
581
- }
582
-
583
- return function () {
584
- unblock(); // Remove the beforeunload listener so the document may
585
- // still be salvageable in the pagehide event.
586
- // See https://html.spec.whatwg.org/#unloading-documents
587
-
588
- if (!blockers.length) {
589
- window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
590
- }
591
- };
592
- }
593
- };
594
- return history;
595
- }
596
- /**
597
- * Memory history stores the current location in memory. It is designed for use
598
- * in stateful non-browser environments like tests and React Native.
599
- *
600
- * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#creatememoryhistory
601
- */
602
-
603
- function createMemoryHistory(options) {
604
- if (options === void 0) {
605
- options = {};
606
- }
607
-
608
- var _options3 = options,
609
- _options3$initialEntr = _options3.initialEntries,
610
- initialEntries = _options3$initialEntr === void 0 ? ['/'] : _options3$initialEntr,
611
- initialIndex = _options3.initialIndex;
612
- var entries = initialEntries.map(function (entry) {
613
- var location = readOnly(_extends$1({
614
- pathname: '/',
615
- search: '',
616
- hash: '',
617
- state: null,
618
- key: createKey()
619
- }, typeof entry === 'string' ? parsePath(entry) : entry));
620
- process.env.NODE_ENV !== "production" ? warning$1(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: " + JSON.stringify(entry) + ")") : void 0;
621
- return location;
622
- });
623
- var index = clamp(initialIndex == null ? entries.length - 1 : initialIndex, 0, entries.length - 1);
624
- var action = Action.Pop;
625
- var location = entries[index];
626
- var listeners = createEvents();
627
- var blockers = createEvents();
628
-
629
- function createHref(to) {
630
- return typeof to === 'string' ? to : createPath(to);
631
- }
632
-
633
- function getNextLocation(to, state) {
634
- if (state === void 0) {
635
- state = null;
636
- }
637
-
638
- return readOnly(_extends$1({
639
- pathname: location.pathname,
640
- search: '',
641
- hash: ''
642
- }, typeof to === 'string' ? parsePath(to) : to, {
643
- state: state,
644
- key: createKey()
645
- }));
646
- }
647
-
648
- function allowTx(action, location, retry) {
649
- return !blockers.length || (blockers.call({
650
- action: action,
651
- location: location,
652
- retry: retry
653
- }), false);
654
- }
655
-
656
- function applyTx(nextAction, nextLocation) {
657
- action = nextAction;
658
- location = nextLocation;
659
- listeners.call({
660
- action: action,
661
- location: location
662
- });
663
- }
664
-
665
- function push(to, state) {
666
- var nextAction = Action.Push;
667
- var nextLocation = getNextLocation(to, state);
668
-
669
- function retry() {
670
- push(to, state);
671
- }
672
-
673
- process.env.NODE_ENV !== "production" ? warning$1(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in memory history.push(" + JSON.stringify(to) + ")") : void 0;
674
-
675
- if (allowTx(nextAction, nextLocation, retry)) {
676
- index += 1;
677
- entries.splice(index, entries.length, nextLocation);
678
- applyTx(nextAction, nextLocation);
679
- }
680
- }
681
-
682
- function replace(to, state) {
683
- var nextAction = Action.Replace;
684
- var nextLocation = getNextLocation(to, state);
685
-
686
- function retry() {
687
- replace(to, state);
688
- }
689
-
690
- process.env.NODE_ENV !== "production" ? warning$1(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in memory history.replace(" + JSON.stringify(to) + ")") : void 0;
691
-
692
- if (allowTx(nextAction, nextLocation, retry)) {
693
- entries[index] = nextLocation;
694
- applyTx(nextAction, nextLocation);
695
- }
696
- }
697
-
698
- function go(delta) {
699
- var nextIndex = clamp(index + delta, 0, entries.length - 1);
700
- var nextAction = Action.Pop;
701
- var nextLocation = entries[nextIndex];
702
-
703
- function retry() {
704
- go(delta);
705
- }
706
-
707
- if (allowTx(nextAction, nextLocation, retry)) {
708
- index = nextIndex;
709
- applyTx(nextAction, nextLocation);
710
- }
711
- }
712
-
713
- var history = {
714
- get index() {
715
- return index;
716
- },
717
-
718
- get action() {
719
- return action;
720
- },
721
-
722
- get location() {
723
- return location;
724
- },
725
-
726
- createHref: createHref,
727
- push: push,
728
- replace: replace,
729
- go: go,
730
- back: function back() {
731
- go(-1);
732
- },
733
- forward: function forward() {
734
- go(1);
735
- },
736
- listen: function listen(listener) {
737
- return listeners.push(listener);
738
- },
739
- block: function block(blocker) {
740
- return blockers.push(blocker);
741
- }
742
- };
743
- return history;
744
- } ////////////////////////////////////////////////////////////////////////////////
745
- // UTILS
746
- ////////////////////////////////////////////////////////////////////////////////
747
-
748
- function clamp(n, lowerBound, upperBound) {
749
- return Math.min(Math.max(n, lowerBound), upperBound);
750
- }
751
-
752
- function promptBeforeUnload(event) {
753
- // Cancel the event.
754
- event.preventDefault(); // Chrome (and legacy IE) requires returnValue to be set.
755
-
756
- event.returnValue = '';
757
- }
758
-
759
- function createEvents() {
760
- var handlers = [];
761
- return {
762
- get length() {
763
- return handlers.length;
764
- },
765
-
766
- push: function push(fn) {
767
- handlers.push(fn);
768
- return function () {
769
- handlers = handlers.filter(function (handler) {
770
- return handler !== fn;
771
- });
772
- };
773
- },
774
- call: function call(arg) {
775
- handlers.forEach(function (fn) {
776
- return fn && fn(arg);
777
- });
778
- }
779
- };
780
- }
781
-
782
- function createKey() {
783
- return Math.random().toString(36).substr(2, 8);
784
- }
785
- /**
786
- * Creates a string URL path from the given pathname, search, and hash components.
787
- *
788
- * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createpath
789
- */
790
-
791
-
792
- function createPath(_ref) {
793
- var _ref$pathname = _ref.pathname,
794
- pathname = _ref$pathname === void 0 ? '/' : _ref$pathname,
795
- _ref$search = _ref.search,
796
- search = _ref$search === void 0 ? '' : _ref$search,
797
- _ref$hash = _ref.hash,
798
- hash = _ref$hash === void 0 ? '' : _ref$hash;
799
- if (search && search !== '?') pathname += search.charAt(0) === '?' ? search : '?' + search;
800
- if (hash && hash !== '#') pathname += hash.charAt(0) === '#' ? hash : '#' + hash;
801
- return pathname;
802
- }
803
- /**
804
- * Parses a string URL path into its separate pathname, search, and hash components.
805
- *
806
- * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#parsepath
807
- */
808
-
809
- function parsePath(path) {
810
- var parsedPath = {};
811
-
812
- if (path) {
813
- var hashIndex = path.indexOf('#');
814
-
815
- if (hashIndex >= 0) {
816
- parsedPath.hash = path.substr(hashIndex);
817
- path = path.substr(0, hashIndex);
818
- }
819
-
820
- var searchIndex = path.indexOf('?');
821
-
822
- if (searchIndex >= 0) {
823
- parsedPath.search = path.substr(searchIndex);
824
- path = path.substr(0, searchIndex);
825
- }
826
-
827
- if (path) {
828
- parsedPath.pathname = path;
829
- }
830
- }
831
-
832
- return parsedPath;
833
- }
834
-
835
- var isProduction = process.env.NODE_ENV === 'production';
836
- var prefix = 'Invariant failed';
837
- function invariant(condition, message) {
838
- if (condition) {
839
- return;
840
- }
841
- if (isProduction) {
842
- throw new Error(prefix);
843
- }
844
- var provided = typeof message === 'function' ? message() : message;
845
- var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
846
- throw new Error(value);
847
- }
848
-
849
- /**
850
- * This function returns `a` if `b` is deeply equal.
851
- * If not, it will replace any deeply equal children of `b` with those of `a`.
852
- * This can be used for structural sharing between JSON values for example.
853
- */
854
- function replaceEqualDeep(prev, next) {
855
- if (prev === next) {
856
- return prev;
857
- }
858
-
859
- const array = Array.isArray(prev) && Array.isArray(next);
860
-
861
- if (array || isPlainObject(prev) && isPlainObject(next)) {
862
- const aSize = array ? prev.length : Object.keys(prev).length;
863
- const bItems = array ? next : Object.keys(next);
864
- const bSize = bItems.length;
865
- const copy = array ? [] : {};
866
- let equalItems = 0;
867
-
868
- for (let i = 0; i < bSize; i++) {
869
- const key = array ? i : bItems[i];
870
- copy[key] = replaceEqualDeep(prev[key], next[key]);
871
-
872
- if (copy[key] === prev[key]) {
873
- equalItems++;
874
- }
875
- }
876
-
877
- return aSize === bSize && equalItems === aSize ? prev : copy;
878
- }
879
-
880
- return next;
881
- } // Copied from: https://github.com/jonschlinkert/is-plain-object
882
-
883
- function isPlainObject(o) {
884
- if (!hasObjectPrototype(o)) {
885
- return false;
886
- } // If has modified constructor
887
-
888
-
889
- const ctor = o.constructor;
890
-
891
- if (typeof ctor === 'undefined') {
892
- return true;
893
- } // If has modified prototype
894
-
895
-
896
- const prot = ctor.prototype;
897
-
898
- if (!hasObjectPrototype(prot)) {
899
- return false;
900
- } // If constructor does not have an Object-specific method
901
-
902
-
903
- if (!prot.hasOwnProperty('isPrototypeOf')) {
904
- return false;
905
- } // Most likely a plain Object
906
-
907
-
908
- return true;
909
- }
910
-
911
- function hasObjectPrototype(o) {
912
- return Object.prototype.toString.call(o) === '[object Object]';
913
- }
914
-
915
- function last(arr) {
916
- return arr[arr.length - 1];
917
- }
918
- function warning(cond, message) {
919
- if (cond) {
920
- if (typeof console !== 'undefined') console.warn(message);
921
-
922
- try {
923
- throw new Error(message);
924
- } catch (_unused) {}
925
- }
926
-
927
- return true;
928
- }
929
-
930
- function isFunction(d) {
931
- return typeof d === 'function';
932
- }
933
-
934
- function functionalUpdate(updater, previous) {
935
- if (isFunction(updater)) {
936
- return updater(previous);
937
- }
938
-
939
- return updater;
940
- }
941
- function pick(parent, keys) {
942
- return keys.reduce((obj, key) => {
943
- obj[key] = parent[key];
944
- return obj;
945
- }, {});
946
- }
947
-
948
- function joinPaths(paths) {
949
- return cleanPath(paths.filter(Boolean).join('/'));
950
- }
951
- function cleanPath(path) {
952
- // remove double slashes
953
- return path.replace(/\/{2,}/g, '/');
954
- }
955
- function trimPathLeft(path) {
956
- return path === '/' ? path : path.replace(/^\/{1,}/, '');
957
- }
958
- function trimPathRight(path) {
959
- return path === '/' ? path : path.replace(/\/{1,}$/, '');
960
- }
961
- function trimPath(path) {
962
- return trimPathRight(trimPathLeft(path));
963
- }
964
- function resolvePath(basepath, base, to) {
965
- base = base.replace(new RegExp("^" + basepath), '/');
966
- to = to.replace(new RegExp("^" + basepath), '/');
967
- let baseSegments = parsePathname(base);
968
- const toSegments = parsePathname(to);
969
- toSegments.forEach((toSegment, index) => {
970
- if (toSegment.value === '/') {
971
- if (!index) {
972
- // Leading slash
973
- baseSegments = [toSegment];
974
- } else if (index === toSegments.length - 1) {
975
- // Trailing Slash
976
- baseSegments.push(toSegment);
977
- } else ;
978
- } else if (toSegment.value === '..') {
979
- var _last;
980
-
981
- // Extra trailing slash? pop it off
982
- if (baseSegments.length > 1 && ((_last = last(baseSegments)) == null ? void 0 : _last.value) === '/') {
983
- baseSegments.pop();
984
- }
985
-
986
- baseSegments.pop();
987
- } else if (toSegment.value === '.') {
988
- return;
989
- } else {
990
- baseSegments.push(toSegment);
991
- }
992
- });
993
- const joined = joinPaths([basepath, ...baseSegments.map(d => d.value)]);
994
- return cleanPath(joined);
995
- }
996
- function parsePathname(pathname) {
997
- if (!pathname) {
998
- return [];
999
- }
1000
-
1001
- pathname = cleanPath(pathname);
1002
- const segments = [];
1003
-
1004
- if (pathname.slice(0, 1) === '/') {
1005
- pathname = pathname.substring(1);
1006
- segments.push({
1007
- type: 'pathname',
1008
- value: '/'
1009
- });
1010
- }
1011
-
1012
- if (!pathname) {
1013
- return segments;
1014
- } // Remove empty segments and '.' segments
1015
-
1016
-
1017
- const split = pathname.split('/').filter(Boolean);
1018
- segments.push(...split.map(part => {
1019
- if (part.startsWith('*')) {
1020
- return {
1021
- type: 'wildcard',
1022
- value: part
1023
- };
1024
- }
1025
-
1026
- if (part.charAt(0) === ':') {
1027
- return {
1028
- type: 'param',
1029
- value: part
1030
- };
1031
- }
1032
-
1033
- return {
1034
- type: 'pathname',
1035
- value: part
1036
- };
1037
- }));
1038
-
1039
- if (pathname.slice(-1) === '/') {
1040
- pathname = pathname.substring(1);
1041
- segments.push({
1042
- type: 'pathname',
1043
- value: '/'
1044
- });
1045
- }
1046
-
1047
- return segments;
1048
- }
1049
- function interpolatePath(path, params, leaveWildcard) {
1050
- const interpolatedPathSegments = parsePathname(path);
1051
- return joinPaths(interpolatedPathSegments.map(segment => {
1052
- if (segment.value === '*' && !leaveWildcard) {
1053
- return '';
1054
- }
1055
-
1056
- if (segment.type === 'param') {
1057
- var _segment$value$substr;
1058
-
1059
- return (_segment$value$substr = params[segment.value.substring(1)]) != null ? _segment$value$substr : '';
1060
- }
1061
-
1062
- return segment.value;
1063
- }));
1064
- }
1065
- function matchPathname(currentPathname, matchLocation) {
1066
- const pathParams = matchByPath(currentPathname, matchLocation); // const searchMatched = matchBySearch(currentLocation.search, matchLocation)
1067
-
1068
- if (matchLocation.to && !pathParams) {
1069
- return;
1070
- }
1071
-
1072
- return pathParams != null ? pathParams : {};
1073
- }
1074
- function matchByPath(from, matchLocation) {
1075
- var _matchLocation$to;
1076
-
1077
- const baseSegments = parsePathname(from);
1078
- const routeSegments = parsePathname("" + ((_matchLocation$to = matchLocation.to) != null ? _matchLocation$to : '*'));
1079
- const params = {};
1080
-
1081
- let isMatch = (() => {
1082
- for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
1083
- const baseSegment = baseSegments[i];
1084
- const routeSegment = routeSegments[i];
1085
- const isLastRouteSegment = i === routeSegments.length - 1;
1086
- const isLastBaseSegment = i === baseSegments.length - 1;
1087
-
1088
- if (routeSegment) {
1089
- if (routeSegment.type === 'wildcard') {
1090
- if (baseSegment != null && baseSegment.value) {
1091
- params['*'] = joinPaths(baseSegments.slice(i).map(d => d.value));
1092
- return true;
1093
- }
1094
-
1095
- return false;
1096
- }
1097
-
1098
- if (routeSegment.type === 'pathname') {
1099
- if (routeSegment.value === '/' && !(baseSegment != null && baseSegment.value)) {
1100
- return true;
1101
- }
1102
-
1103
- if (baseSegment) {
1104
- if (matchLocation.caseSensitive) {
1105
- if (routeSegment.value !== baseSegment.value) {
1106
- return false;
1107
- }
1108
- } else if (routeSegment.value.toLowerCase() !== baseSegment.value.toLowerCase()) {
1109
- return false;
1110
- }
1111
- }
1112
- }
1113
-
1114
- if (!baseSegment) {
1115
- return false;
1116
- }
1117
-
1118
- if (routeSegment.type === 'param') {
1119
- if ((baseSegment == null ? void 0 : baseSegment.value) === '/') {
1120
- return false;
1121
- }
1122
-
1123
- if (!baseSegment.value.startsWith(':')) {
1124
- params[routeSegment.value.substring(1)] = baseSegment.value;
1125
- }
1126
- }
1127
- }
1128
-
1129
- if (isLastRouteSegment && !isLastBaseSegment) {
1130
- return !!matchLocation.fuzzy;
1131
- }
1132
- }
1133
-
1134
- return true;
1135
- })();
1136
-
1137
- return isMatch ? params : undefined;
1138
- }
1139
-
1140
- // @ts-nocheck
1141
- // qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.
1142
- function encode(obj, pfx) {
1143
- var k,
1144
- i,
1145
- tmp,
1146
- str = '';
1147
-
1148
- for (k in obj) {
1149
- if ((tmp = obj[k]) !== void 0) {
1150
- if (Array.isArray(tmp)) {
1151
- for (i = 0; i < tmp.length; i++) {
1152
- str && (str += '&');
1153
- str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i]);
1154
- }
1155
- } else {
1156
- str && (str += '&');
1157
- str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp);
1158
- }
1159
- }
1160
- }
1161
-
1162
- return (pfx || '') + str;
1163
- }
1164
-
1165
- function toValue(mix) {
1166
- if (!mix) return '';
1167
- var str = decodeURIComponent(mix);
1168
- if (str === 'false') return false;
1169
- if (str === 'true') return true;
1170
- if (str.charAt(0) === '0') return str;
1171
- return +str * 0 === 0 ? +str : str;
1172
- }
1173
-
1174
- function decode(str) {
1175
- var tmp,
1176
- k,
1177
- out = {},
1178
- arr = str.split('&');
1179
-
1180
- while (tmp = arr.shift()) {
1181
- tmp = tmp.split('=');
1182
- k = tmp.shift();
1183
-
1184
- if (out[k] !== void 0) {
1185
- out[k] = [].concat(out[k], toValue(tmp.shift()));
1186
- } else {
1187
- out[k] = toValue(tmp.shift());
1188
- }
1189
- }
1190
-
1191
- return out;
1192
- }
1193
-
1194
- function _extends() {
1195
- _extends = Object.assign ? Object.assign.bind() : function (target) {
1196
- for (var i = 1; i < arguments.length; i++) {
1197
- var source = arguments[i];
1198
-
1199
- for (var key in source) {
1200
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1201
- target[key] = source[key];
1202
- }
1203
- }
1204
- }
1205
-
1206
- return target;
1207
- };
1208
- return _extends.apply(this, arguments);
1209
- }
1210
-
1211
- function createRoute(routeConfig, options, parent, router) {
1212
- const {
1213
- id,
1214
- routeId,
1215
- path: routePath,
1216
- fullPath
1217
- } = routeConfig;
1218
-
1219
- const action = router.state.actions[id] || (() => {
1220
- router.state.actions[id] = {
1221
- submissions: [],
1222
- submit: async (submission, actionOpts) => {
1223
- var _actionOpts$invalidat;
1224
-
1225
- if (!route) {
1226
- return;
1227
- }
1228
-
1229
- const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
1230
-
1231
- if (!(actionOpts != null && actionOpts.multi)) {
1232
- action.submissions = action.submissions.filter(d => d.isMulti);
1233
- }
1234
-
1235
- const actionState = {
1236
- submittedAt: Date.now(),
1237
- status: 'pending',
1238
- submission,
1239
- isMulti: !!(actionOpts != null && actionOpts.multi)
1240
- };
1241
- action.current = actionState;
1242
- action.latest = actionState;
1243
- action.submissions.push(actionState);
1244
- router.notify();
1245
-
1246
- try {
1247
- const res = await (route.options.action == null ? void 0 : route.options.action(submission));
1248
- actionState.data = res;
1249
-
1250
- if (invalidate) {
1251
- router.invalidateRoute({
1252
- to: '.',
1253
- fromCurrent: true
1254
- });
1255
- await router.reload();
1256
- }
1257
-
1258
- actionState.status = 'success';
1259
- return res;
1260
- } catch (err) {
1261
- console.error(err);
1262
- actionState.error = err;
1263
- actionState.status = 'error';
1264
- } finally {
1265
- router.notify();
1266
- }
1267
- }
1268
- };
1269
- return router.state.actions[id];
1270
- })();
1271
-
1272
- const loader = router.state.loaders[id] || (() => {
1273
- router.state.loaders[id] = {
1274
- pending: [],
1275
- fetch: async loaderContext => {
1276
- if (!route) {
1277
- return;
1278
- }
1279
-
1280
- const loaderState = {
1281
- loadedAt: Date.now(),
1282
- loaderContext
1283
- };
1284
- loader.current = loaderState;
1285
- loader.latest = loaderState;
1286
- loader.pending.push(loaderState); // router.state = {
1287
- // ...router.state,
1288
- // currentAction: loaderState,
1289
- // latestAction: loaderState,
1290
- // }
1291
-
1292
- router.notify();
1293
-
1294
- try {
1295
- return await (route.options.loader == null ? void 0 : route.options.loader(loaderContext));
1296
- } finally {
1297
- loader.pending = loader.pending.filter(d => d !== loaderState); // router.removeActionQueue.push({ loader, loaderState })
1298
-
1299
- router.notify();
1300
- }
1301
- }
1302
- };
1303
- return router.state.loaders[id];
1304
- })();
1305
-
1306
- let route = {
1307
- routeInfo: undefined,
1308
- routeId: id,
1309
- routeRouteId: routeId,
1310
- routePath,
1311
- fullPath,
1312
- options,
1313
- router,
1314
- childRoutes: undefined,
1315
- parentRoute: parent,
1316
- action,
1317
- loader: loader,
1318
- buildLink: options => {
1319
- return router.buildLink(_extends({}, options, {
1320
- from: fullPath
1321
- }));
1322
- },
1323
- navigate: options => {
1324
- return router.navigate(_extends({}, options, {
1325
- from: fullPath
1326
- }));
1327
- },
1328
- matchRoute: (matchLocation, opts) => {
1329
- return router.matchRoute(_extends({}, matchLocation, {
1330
- from: fullPath
1331
- }), opts);
1332
- }
1333
- };
1334
- router.options.createRoute == null ? void 0 : router.options.createRoute({
1335
- router,
1336
- route
1337
- });
1338
- return route;
1339
- }
1340
-
1341
- const rootRouteId = '__root__';
1342
- const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
1343
- if (options === void 0) {
1344
- options = {};
1345
- }
1346
-
1347
- if (isRoot === void 0) {
1348
- isRoot = true;
1349
- }
1350
-
1351
- if (isRoot) {
1352
- options.path = rootRouteId;
1353
- } // Strip the root from parentIds
1354
-
1355
-
1356
- if (parentId === rootRouteId) {
1357
- parentId = '';
1358
- }
1359
-
1360
- let path = isRoot ? rootRouteId : options.path; // If the path is anything other than an index path, trim it up
1361
-
1362
- if (path && path !== '/') {
1363
- path = trimPath(path);
1364
- }
1365
-
1366
- const routeId = path || options.id;
1367
- let id = joinPaths([parentId, routeId]);
1368
-
1369
- if (path === rootRouteId) {
1370
- path = '/';
1371
- }
1372
-
1373
- if (id !== rootRouteId) {
1374
- id = joinPaths(['/', id]);
1375
- }
1376
-
1377
- const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]));
1378
- return {
1379
- id: id,
1380
- routeId: routeId,
1381
- path: path,
1382
- fullPath: fullPath,
1383
- options: options,
1384
- children,
1385
- createChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)), false, parentId, parentPath),
1386
- addChildren: children => createRouteConfig(options, children, false, parentId, parentPath),
1387
- createRoute: childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)
1388
- };
1389
- };
1390
-
1391
- const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
1392
- function createRouteMatch(router, route, opts) {
1393
- const routeMatch = _extends({}, route, opts, {
1394
- router,
1395
- routeSearch: {},
1396
- search: {},
1397
- childMatches: [],
1398
- status: 'idle',
1399
- routeLoaderData: {},
1400
- loaderData: {},
1401
- isFetching: false,
1402
- isInvalid: false,
1403
- invalidAt: Infinity,
1404
- // pendingActions: [],
1405
- getIsInvalid: () => {
1406
- const now = Date.now();
1407
- return routeMatch.isInvalid || routeMatch.invalidAt < now;
1408
- },
1409
- __: {
1410
- abortController: new AbortController(),
1411
- latestId: '',
1412
- resolve: () => {},
1413
- notify: () => {
1414
- routeMatch.__.resolve();
1415
-
1416
- routeMatch.router.notify();
1417
- },
1418
- validate: () => {
1419
- var _routeMatch$parentMat, _routeMatch$parentMat2;
1420
-
1421
- // Validate the search params and stabilize them
1422
- const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
1423
-
1424
- try {
1425
- var _validator;
1426
-
1427
- const prevSearch = routeMatch.routeSearch;
1428
- const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
1429
- let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {}); // Invalidate route matches when search param stability changes
1430
-
1431
- if (prevSearch !== nextSearch) {
1432
- routeMatch.isInvalid = true;
1433
- }
1434
-
1435
- routeMatch.routeSearch = nextSearch;
1436
- routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
1437
- componentTypes.map(async type => {
1438
- const component = routeMatch.options[type];
1439
-
1440
- if (typeof routeMatch.__[type] !== 'function') {
1441
- routeMatch.__[type] = component;
1442
- }
1443
- });
1444
- } catch (err) {
1445
- console.error(err);
1446
- const error = new Error('Invalid search params found', {
1447
- cause: err
1448
- });
1449
- error.code = 'INVALID_SEARCH_PARAMS';
1450
- routeMatch.status = 'error';
1451
- routeMatch.error = error; // Do not proceed with loading the route
1452
-
1453
- return;
1454
- }
1455
- }
1456
- },
1457
- cancel: () => {
1458
- var _routeMatch$__$abortC;
1459
-
1460
- (_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
1461
- },
1462
- invalidate: () => {
1463
- routeMatch.isInvalid = true;
1464
- },
1465
- hasLoaders: () => {
1466
- return !!(route.options.loader || componentTypes.some(d => {
1467
- var _route$options$d;
1468
-
1469
- return (_route$options$d = route.options[d]) == null ? void 0 : _route$options$d.preload;
1470
- }));
1471
- },
1472
- load: async loaderOpts => {
1473
- const now = Date.now();
1474
- const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0; // If this is a preload, add it to the preload cache
1475
-
1476
- if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
1477
- // If the match is currently active, don't preload it
1478
- if (router.state.matches.find(d => d.matchId === routeMatch.matchId)) {
1479
- return;
1480
- }
1481
-
1482
- router.matchCache[routeMatch.matchId] = {
1483
- gc: now + loaderOpts.gcMaxAge,
1484
- match: routeMatch
1485
- };
1486
- } // If the match is invalid, errored or idle, trigger it to load
1487
-
1488
-
1489
- if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
1490
- const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
1491
- await routeMatch.fetch({
1492
- maxAge
1493
- });
1494
- }
1495
- },
1496
- fetch: async opts => {
1497
- const loadId = '' + Date.now() + Math.random();
1498
- routeMatch.__.latestId = loadId;
1499
-
1500
- const checkLatest = async () => {
1501
- if (loadId !== routeMatch.__.latestId) {
1502
- // warning(true, 'Data loader is out of date!')
1503
- return new Promise(() => {});
1504
- }
1505
- }; // If the match was in an error state, set it
1506
- // to a loading state again. Otherwise, keep it
1507
- // as loading or resolved
1508
-
1509
-
1510
- if (routeMatch.status === 'idle') {
1511
- routeMatch.status = 'loading';
1512
- } // We started loading the route, so it's no longer invalid
1513
-
1514
-
1515
- routeMatch.isInvalid = false;
1516
- routeMatch.__.loadPromise = new Promise(async resolve => {
1517
- // We are now fetching, even if it's in the background of a
1518
- // resolved state
1519
- routeMatch.isFetching = true;
1520
- routeMatch.__.resolve = resolve;
1521
-
1522
- routeMatch.__.componentsPromise = (async () => {
1523
- // then run all component and data loaders in parallel
1524
- // For each component type, potentially load it asynchronously
1525
- await Promise.all(componentTypes.map(async type => {
1526
- var _routeMatch$__$type;
1527
-
1528
- const component = routeMatch.options[type];
1529
-
1530
- if ((_routeMatch$__$type = routeMatch.__[type]) != null && _routeMatch$__$type.preload) {
1531
- routeMatch.__[type] = await router.options.loadComponent(component);
1532
- }
1533
- }));
1534
- })();
1535
-
1536
- routeMatch.__.dataPromise = Promise.resolve().then(async () => {
1537
- try {
1538
- var _ref, _ref2, _opts$maxAge;
1539
-
1540
- if (routeMatch.options.loader) {
1541
- const data = await router.loadMatchData(routeMatch);
1542
- await checkLatest();
1543
- routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
1544
- }
1545
-
1546
- routeMatch.error = undefined;
1547
- routeMatch.status = 'success';
1548
- routeMatch.updatedAt = Date.now();
1549
- routeMatch.invalidAt = routeMatch.updatedAt + ((_ref = (_ref2 = (_opts$maxAge = opts == null ? void 0 : opts.maxAge) != null ? _opts$maxAge : routeMatch.options.loaderMaxAge) != null ? _ref2 : router.options.defaultLoaderMaxAge) != null ? _ref : 0);
1550
- return routeMatch.routeLoaderData;
1551
- } catch (err) {
1552
- await checkLatest();
1553
-
1554
- if (process.env.NODE_ENV !== 'production') {
1555
- console.error(err);
1556
- }
1557
-
1558
- routeMatch.error = err;
1559
- routeMatch.status = 'error';
1560
- routeMatch.updatedAt = Date.now();
1561
- throw err;
1562
- }
1563
- });
1564
-
1565
- const after = async () => {
1566
- await checkLatest();
1567
- routeMatch.isFetching = false;
1568
- delete routeMatch.__.loadPromise;
1569
-
1570
- routeMatch.__.notify();
1571
- };
1572
-
1573
- try {
1574
- await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise.catch(() => {})]);
1575
- after();
1576
- } catch (_unused) {
1577
- after();
1578
- }
1579
- });
1580
- await routeMatch.__.loadPromise;
1581
- await checkLatest();
1582
- }
1583
- });
1584
-
1585
- if (!routeMatch.hasLoaders()) {
1586
- routeMatch.status = 'success';
1587
- }
1588
-
1589
- return routeMatch;
1590
- }
1591
-
1592
- const defaultParseSearch = parseSearchWith(JSON.parse);
1593
- const defaultStringifySearch = stringifySearchWith(JSON.stringify);
1594
- function parseSearchWith(parser) {
1595
- return searchStr => {
1596
- if (searchStr.substring(0, 1) === '?') {
1597
- searchStr = searchStr.substring(1);
1598
- }
1599
-
1600
- let query = decode(searchStr); // Try to parse any query params that might be json
1601
-
1602
- for (let key in query) {
1603
- const value = query[key];
1604
-
1605
- if (typeof value === 'string') {
1606
- try {
1607
- query[key] = parser(value);
1608
- } catch (err) {//
1609
- }
1610
- }
1611
- }
1612
-
1613
- return query;
1614
- };
1615
- }
1616
- function stringifySearchWith(stringify) {
1617
- return search => {
1618
- search = _extends({}, search);
1619
-
1620
- if (search) {
1621
- Object.keys(search).forEach(key => {
1622
- const val = search[key];
1623
-
1624
- if (typeof val === 'undefined' || val === undefined) {
1625
- delete search[key];
1626
- } else if (val && typeof val === 'object' && val !== null) {
1627
- try {
1628
- search[key] = stringify(val);
1629
- } catch (err) {// silent
1630
- }
1631
- }
1632
- });
1633
- }
1634
-
1635
- const searchStr = encode(search).toString();
1636
- return searchStr ? "?" + searchStr : '';
1637
- };
1638
- }
1639
-
1640
- var _window$document;
1641
- // Detect if we're in the DOM
1642
- const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement); // This is the default history object if none is defined
1643
-
1644
- const createDefaultHistory = () => isServer ? createMemoryHistory() : createBrowserHistory();
1645
-
1646
- function getInitialRouterState() {
1647
- return {
1648
- status: 'idle',
1649
- location: null,
1650
- matches: [],
1651
- actions: {},
1652
- loaders: {},
1653
- lastUpdated: Date.now(),
1654
- isFetching: false,
1655
- isPreloading: false
1656
- };
1657
- }
1658
-
1659
- function createRouter(userOptions) {
1660
- var _userOptions$stringif, _userOptions$parseSea;
1661
-
1662
- const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
1663
-
1664
- const originalOptions = _extends({
1665
- defaultLoaderGcMaxAge: 5 * 60 * 1000,
1666
- defaultLoaderMaxAge: 0,
1667
- defaultPreloadMaxAge: 2000,
1668
- defaultPreloadDelay: 50
1669
- }, userOptions, {
1670
- stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
1671
- parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
1672
- });
1673
-
1674
- let router = {
1675
- types: undefined,
1676
- // public api
1677
- history,
1678
- options: originalOptions,
1679
- listeners: [],
1680
- // Resolved after construction
1681
- context: {},
1682
- basepath: '',
1683
- routeTree: undefined,
1684
- routesById: {},
1685
- location: undefined,
1686
- //
1687
- navigationPromise: Promise.resolve(),
1688
- resolveNavigation: () => {},
1689
- matchCache: {},
1690
- state: getInitialRouterState(),
1691
- reset: () => {
1692
- router.state = getInitialRouterState();
1693
- router.notify();
1694
- },
1695
- startedLoadingAt: Date.now(),
1696
- subscribe: listener => {
1697
- router.listeners.push(listener);
1698
- return () => {
1699
- router.listeners = router.listeners.filter(x => x !== listener);
1700
- };
1701
- },
1702
- getRoute: id => {
1703
- return router.routesById[id];
1704
- },
1705
- notify: () => {
1706
- const isFetching = router.state.status === 'loading' || router.state.matches.some(d => d.isFetching);
1707
- const isPreloading = Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId));
1708
-
1709
- if (router.state.isFetching !== isFetching || router.state.isPreloading !== isPreloading) {
1710
- router.state = _extends({}, router.state, {
1711
- isFetching,
1712
- isPreloading
1713
- });
1714
- }
1715
-
1716
- cascadeLoaderData(router.state.matches);
1717
- router.listeners.forEach(listener => listener(router));
1718
- },
1719
- dehydrateState: () => {
1720
- return _extends({}, pick(router.state, ['status', 'location', 'lastUpdated']), {
1721
- matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
1722
- });
1723
- },
1724
- hydrateState: dehydratedState => {
1725
- // Match the routes
1726
- const matches = router.matchRoutes(router.location.pathname, {
1727
- strictParseParams: true
1728
- });
1729
- matches.forEach((match, index) => {
1730
- const dehydratedMatch = dehydratedState.matches[index];
1731
- invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
1732
- Object.assign(match, dehydratedMatch);
1733
- });
1734
- matches.forEach(match => match.__.validate());
1735
- router.state = _extends({}, router.state, dehydratedState, {
1736
- matches
1737
- });
1738
- },
1739
- mount: () => {
1740
- const next = router.__.buildLocation({
1741
- to: '.',
1742
- search: true,
1743
- hash: true
1744
- }); // If the current location isn't updated, trigger a navigation
1745
- // to the current location. Otherwise, load the current location.
1746
-
1747
-
1748
- if (next.href !== router.location.href) {
1749
- router.__.commitLocation(next, true);
1750
- }
1751
-
1752
- if (!router.state.matches.length) {
1753
- router.load();
1754
- }
1755
-
1756
- const unsub = router.history.listen(event => {
1757
- router.load(router.__.parseLocation(event.location, router.location));
1758
- }); // addEventListener does not exist in React Native, but window does
1759
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1760
-
1761
- if (!isServer && window.addEventListener) {
1762
- // Listen to visibillitychange and focus
1763
- window.addEventListener('visibilitychange', router.onFocus, false);
1764
- window.addEventListener('focus', router.onFocus, false);
1765
- }
1766
-
1767
- return () => {
1768
- unsub();
1769
-
1770
- if (!isServer && window.removeEventListener) {
1771
- // Be sure to unsubscribe if a new handler is set
1772
- window.removeEventListener('visibilitychange', router.onFocus);
1773
- window.removeEventListener('focus', router.onFocus);
1774
- }
1775
- };
1776
- },
1777
- onFocus: () => {
1778
- router.load();
1779
- },
1780
- update: opts => {
1781
- const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
1782
-
1783
- if (!router.location || newHistory) {
1784
- if (opts != null && opts.history) {
1785
- router.history = opts.history;
1786
- }
1787
-
1788
- router.location = router.__.parseLocation(router.history.location);
1789
- router.state.location = router.location;
1790
- }
1791
-
1792
- Object.assign(router.options, opts);
1793
- const {
1794
- basepath,
1795
- routeConfig
1796
- } = router.options;
1797
- router.basepath = cleanPath("/" + (basepath != null ? basepath : ''));
1798
-
1799
- if (routeConfig) {
1800
- router.routesById = {};
1801
- router.routeTree = router.__.buildRouteTree(routeConfig);
1802
- }
1803
-
1804
- return router;
1805
- },
1806
- cancelMatches: () => {
1807
- var _router$state$pending, _router$state$pending2;
1808
- [...router.state.matches, ...((_router$state$pending = (_router$state$pending2 = router.state.pending) == null ? void 0 : _router$state$pending2.matches) != null ? _router$state$pending : [])].forEach(match => {
1809
- match.cancel();
1810
- });
1811
- },
1812
- load: async next => {
1813
- const id = Math.random();
1814
- router.startedLoadingAt = id;
1815
-
1816
- if (next) {
1817
- // Ingest the new location
1818
- router.location = next;
1819
- } // Cancel any pending matches
1820
-
1821
-
1822
- router.cancelMatches(); // Match the routes
1823
-
1824
- const matches = router.matchRoutes(router.location.pathname, {
1825
- strictParseParams: true
1826
- }); // Check if each match middleware to see if the route can be accessed
1827
-
1828
- try {
1829
- await Promise.all(matches.map(match => match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
1830
- context: router.context
1831
- })));
1832
- } catch (err) {
1833
- if (err != null && err.then) {
1834
- await new Promise(() => {});
1835
- }
1836
-
1837
- throw err;
1838
- }
1839
-
1840
- if (typeof document !== 'undefined') {
1841
- router.state = _extends({}, router.state, {
1842
- pending: {
1843
- matches: matches,
1844
- location: router.location
1845
- },
1846
- status: 'loading'
1847
- });
1848
- } else {
1849
- router.state = _extends({}, router.state, {
1850
- matches: matches,
1851
- location: router.location,
1852
- status: 'loading'
1853
- });
1854
- }
1855
-
1856
- router.notify(); // Load the matches
1857
-
1858
- await router.loadMatches(matches);
1859
-
1860
- if (router.startedLoadingAt !== id) {
1861
- // Ignore side-effects of match loading
1862
- return router.navigationPromise;
1863
- }
1864
-
1865
- const previousMatches = router.state.matches;
1866
- const exiting = [],
1867
- staying = [];
1868
- previousMatches.forEach(d => {
1869
- if (matches.find(dd => dd.matchId === d.matchId)) {
1870
- staying.push(d);
1871
- } else {
1872
- exiting.push(d);
1873
- }
1874
- });
1875
- const entering = matches.filter(d => {
1876
- return !previousMatches.find(dd => dd.matchId === d.matchId);
1877
- });
1878
- const now = Date.now();
1879
- exiting.forEach(d => {
1880
- var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
1881
-
1882
- d.__.onExit == null ? void 0 : d.__.onExit({
1883
- params: d.params,
1884
- search: d.routeSearch
1885
- }); // Clear idle error states when match leaves
1886
-
1887
- if (d.status === 'error' && !d.isFetching) {
1888
- d.status = 'idle';
1889
- d.error = undefined;
1890
- }
1891
-
1892
- const gc = Math.max((_ref = (_d$options$loaderGcMa = d.options.loaderGcMaxAge) != null ? _d$options$loaderGcMa : router.options.defaultLoaderGcMaxAge) != null ? _ref : 0, (_ref2 = (_d$options$loaderMaxA = d.options.loaderMaxAge) != null ? _d$options$loaderMaxA : router.options.defaultLoaderMaxAge) != null ? _ref2 : 0);
1893
-
1894
- if (gc > 0) {
1895
- router.matchCache[d.matchId] = {
1896
- gc: gc == Infinity ? Number.MAX_SAFE_INTEGER : now + gc,
1897
- match: d
1898
- };
1899
- }
1900
- });
1901
- staying.forEach(d => {
1902
- d.options.onTransition == null ? void 0 : d.options.onTransition({
1903
- params: d.params,
1904
- search: d.routeSearch
1905
- });
1906
- });
1907
- entering.forEach(d => {
1908
- d.__.onExit = d.options.onLoaded == null ? void 0 : d.options.onLoaded({
1909
- params: d.params,
1910
- search: d.search
1911
- });
1912
- delete router.matchCache[d.matchId];
1913
- });
1914
-
1915
- if (router.startedLoadingAt !== id) {
1916
- // Ignore side-effects of match loading
1917
- return;
1918
- }
1919
-
1920
- matches.forEach(match => {
1921
- // Clear actions
1922
- if (match.action) {
1923
- match.action.current = undefined;
1924
- match.action.submissions = [];
1925
- }
1926
- });
1927
- router.state = _extends({}, router.state, {
1928
- location: router.location,
1929
- matches,
1930
- pending: undefined,
1931
- status: 'idle'
1932
- });
1933
- router.notify();
1934
- router.resolveNavigation();
1935
- },
1936
- cleanMatchCache: () => {
1937
- const now = Date.now();
1938
- Object.keys(router.matchCache).forEach(matchId => {
1939
- const entry = router.matchCache[matchId]; // Don't remove loading matches
1940
-
1941
- if (entry.match.status === 'loading') {
1942
- return;
1943
- } // Do not remove successful matches that are still valid
1944
-
1945
-
1946
- if (entry.gc > 0 && entry.gc > now) {
1947
- return;
1948
- } // Everything else gets removed
1949
-
1950
-
1951
- delete router.matchCache[matchId];
1952
- });
1953
- },
1954
- loadRoute: async function loadRoute(navigateOpts) {
1955
- if (navigateOpts === void 0) {
1956
- navigateOpts = router.location;
1957
- }
1958
-
1959
- const next = router.buildNext(navigateOpts);
1960
- const matches = router.matchRoutes(next.pathname, {
1961
- strictParseParams: true
1962
- });
1963
- await router.loadMatches(matches);
1964
- return matches;
1965
- },
1966
- preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
1967
- var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
1968
-
1969
- if (navigateOpts === void 0) {
1970
- navigateOpts = router.location;
1971
- }
1972
-
1973
- const next = router.buildNext(navigateOpts);
1974
- const matches = router.matchRoutes(next.pathname, {
1975
- strictParseParams: true
1976
- });
1977
- await router.loadMatches(matches, {
1978
- preload: true,
1979
- maxAge: (_ref3 = (_ref4 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref4 : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0,
1980
- gcMaxAge: (_ref5 = (_ref6 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref6 : router.options.defaultLoaderGcMaxAge) != null ? _ref5 : 0
1981
- });
1982
- return matches;
1983
- },
1984
- matchRoutes: (pathname, opts) => {
1985
- var _router$state$pending3, _router$state$pending4;
1986
-
1987
- router.cleanMatchCache();
1988
- const matches = [];
1989
-
1990
- if (!router.routeTree) {
1991
- return matches;
1992
- }
1993
-
1994
- const existingMatches = [...router.state.matches, ...((_router$state$pending3 = (_router$state$pending4 = router.state.pending) == null ? void 0 : _router$state$pending4.matches) != null ? _router$state$pending3 : [])];
1995
-
1996
- const recurse = async routes => {
1997
- var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
1998
-
1999
- const parentMatch = last(matches);
2000
- let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
2001
- const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
2002
- let foundRoutes = [];
2003
-
2004
- const findMatchInRoutes = (parentRoutes, routes) => {
2005
- routes.some(route => {
2006
- var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
2007
-
2008
- if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
2009
- return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
2010
- }
2011
-
2012
- const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
2013
- const matchParams = matchPathname(pathname, {
2014
- to: route.fullPath,
2015
- fuzzy,
2016
- caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
2017
- });
2018
-
2019
- if (matchParams) {
2020
- let parsedParams;
2021
-
2022
- try {
2023
- var _route$options$parseP;
2024
-
2025
- parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
2026
- } catch (err) {
2027
- if (opts != null && opts.strictParseParams) {
2028
- throw err;
2029
- }
2030
- }
2031
-
2032
- params = _extends({}, params, parsedParams);
2033
- }
2034
-
2035
- if (!!matchParams) {
2036
- foundRoutes = [...parentRoutes, route];
2037
- }
2038
-
2039
- return !!foundRoutes.length;
2040
- });
2041
- return !!foundRoutes.length;
2042
- };
2043
-
2044
- findMatchInRoutes([], filteredRoutes);
2045
-
2046
- if (!foundRoutes.length) {
2047
- return;
2048
- }
2049
-
2050
- foundRoutes.forEach(foundRoute => {
2051
- var _router$matchCache$ma;
2052
-
2053
- const interpolatedPath = interpolatePath(foundRoute.routePath, params);
2054
- const matchId = interpolatePath(foundRoute.routeId, params, true);
2055
- const match = existingMatches.find(d => d.matchId === matchId) || ((_router$matchCache$ma = router.matchCache[matchId]) == null ? void 0 : _router$matchCache$ma.match) || createRouteMatch(router, foundRoute, {
2056
- parentMatch,
2057
- matchId,
2058
- params,
2059
- pathname: joinPaths([pathname, interpolatedPath])
2060
- });
2061
- matches.push(match);
2062
- });
2063
- const foundRoute = last(foundRoutes);
2064
-
2065
- if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
2066
- recurse(foundRoute.childRoutes);
2067
- }
2068
- };
2069
-
2070
- recurse([router.routeTree]);
2071
- cascadeLoaderData(matches);
2072
- return matches;
2073
- },
2074
- loadMatches: async (resolvedMatches, loaderOpts) => {
2075
- const matchPromises = resolvedMatches.map(async match => {
2076
- // Validate the match (loads search params etc)
2077
- match.__.validate();
2078
-
2079
- match.load(loaderOpts);
2080
- const search = match.search;
2081
-
2082
- if (search.__data && search.__data.matchId !== match.matchId) {
2083
- return;
2084
- }
2085
-
2086
- if (match.__.loadPromise) {
2087
- // Wait for the first sign of activity from the match
2088
- await match.__.loadPromise;
2089
- }
2090
- });
2091
- router.notify();
2092
- await Promise.all(matchPromises);
2093
- },
2094
- loadMatchData: async routeMatch => {
2095
- if (isServer || !router.options.useServerData) {
2096
- var _await$routeMatch$opt;
2097
-
2098
- return (_await$routeMatch$opt = await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
2099
- // parentLoaderPromise: routeMatch.parentMatch?.__.dataPromise,
2100
- params: routeMatch.params,
2101
- search: routeMatch.routeSearch,
2102
- signal: routeMatch.__.abortController.signal
2103
- }))) != null ? _await$routeMatch$opt : {};
2104
- } else {
2105
- const next = router.buildNext({
2106
- to: '.',
2107
- search: d => _extends({}, d != null ? d : {}, {
2108
- __data: {
2109
- matchId: routeMatch.matchId
2110
- }
2111
- })
2112
- });
2113
- const res = await fetch(next.href, {
2114
- method: 'GET' // signal: routeMatch.__.abortController.signal,
2115
-
2116
- });
2117
-
2118
- if (res.ok) {
2119
- return res.json();
2120
- }
2121
-
2122
- throw new Error('Failed to fetch match data');
2123
- }
2124
- },
2125
- invalidateRoute: opts => {
2126
- var _router$state$pending5, _router$state$pending6;
2127
-
2128
- const next = router.buildNext(opts);
2129
- const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
2130
- [...router.state.matches, ...((_router$state$pending5 = (_router$state$pending6 = router.state.pending) == null ? void 0 : _router$state$pending6.matches) != null ? _router$state$pending5 : [])].forEach(match => {
2131
- if (unloadedMatchIds.includes(match.matchId)) {
2132
- match.invalidate();
2133
- }
2134
- });
2135
- },
2136
- reload: () => router.__.navigate({
2137
- fromCurrent: true,
2138
- replace: true,
2139
- search: true
2140
- }),
2141
- resolvePath: (from, path) => {
2142
- return resolvePath(router.basepath, from, cleanPath(path));
2143
- },
2144
- matchRoute: (location, opts) => {
2145
- var _location$from;
2146
-
2147
- // const location = router.buildNext(opts)
2148
- location = _extends({}, location, {
2149
- to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
2150
- });
2151
- const next = router.buildNext(location);
2152
-
2153
- if (opts != null && opts.pending) {
2154
- var _router$state$pending7;
2155
-
2156
- if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
2157
- return false;
2158
- }
2159
-
2160
- return !!matchPathname(router.state.pending.location.pathname, _extends({}, opts, {
2161
- to: next.pathname
2162
- }));
2163
- }
2164
-
2165
- return !!matchPathname(router.state.location.pathname, _extends({}, opts, {
2166
- to: next.pathname
2167
- }));
2168
- },
2169
- navigate: async _ref7 => {
2170
- let {
2171
- from,
2172
- to = '.',
2173
- search,
2174
- hash,
2175
- replace,
2176
- params
2177
- } = _ref7;
2178
- // If this link simply reloads the current route,
2179
- // make sure it has a new key so it will trigger a data refresh
2180
- // If this `to` is a valid external URL, return
2181
- // null for LinkUtils
2182
- const toString = String(to);
2183
- const fromString = String(from);
2184
- let isExternal;
2185
-
2186
- try {
2187
- new URL("" + toString);
2188
- isExternal = true;
2189
- } catch (e) {}
2190
-
2191
- invariant(!isExternal, 'Attempting to navigate to external url with router.navigate!');
2192
- return router.__.navigate({
2193
- from: fromString,
2194
- to: toString,
2195
- search,
2196
- hash,
2197
- replace,
2198
- params
2199
- });
2200
- },
2201
- buildLink: _ref8 => {
2202
- var _preload, _ref9;
2203
-
2204
- let {
2205
- from,
2206
- to = '.',
2207
- search,
2208
- params,
2209
- hash,
2210
- target,
2211
- replace,
2212
- activeOptions,
2213
- preload,
2214
- preloadMaxAge: userPreloadMaxAge,
2215
- preloadGcMaxAge: userPreloadGcMaxAge,
2216
- preloadDelay: userPreloadDelay,
2217
- disabled
2218
- } = _ref8;
2219
-
2220
- // If this link simply reloads the current route,
2221
- // make sure it has a new key so it will trigger a data refresh
2222
- // If this `to` is a valid external URL, return
2223
- // null for LinkUtils
2224
- try {
2225
- new URL("" + to);
2226
- return {
2227
- type: 'external',
2228
- href: to
2229
- };
2230
- } catch (e) {}
2231
-
2232
- const nextOpts = {
2233
- from,
2234
- to,
2235
- search,
2236
- params,
2237
- hash,
2238
- replace
2239
- };
2240
- const next = router.buildNext(nextOpts);
2241
- preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
2242
- const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0; // Compare path/hash for matches
2243
-
2244
- const pathIsEqual = router.state.location.pathname === next.pathname;
2245
- const currentPathSplit = router.state.location.pathname.split('/');
2246
- const nextPathSplit = next.pathname.split('/');
2247
- const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
2248
- const hashIsEqual = router.state.location.hash === next.hash; // Combine the matches based on user options
2249
-
2250
- const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
2251
- const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true; // The final "active" test
2252
-
2253
- const isActive = pathTest && hashTest; // The click handler
2254
-
2255
- const handleClick = e => {
2256
- if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
2257
- e.preventDefault();
2258
-
2259
- if (pathIsEqual && !search && !hash) {
2260
- router.invalidateRoute(nextOpts);
2261
- } // All is well? Navigate!)
2262
-
2263
-
2264
- router.__.navigate(nextOpts);
2265
- }
2266
- }; // The click handler
2267
-
2268
-
2269
- const handleFocus = e => {
2270
- if (preload) {
2271
- router.preloadRoute(nextOpts, {
2272
- maxAge: userPreloadMaxAge,
2273
- gcMaxAge: userPreloadGcMaxAge
2274
- });
2275
- }
2276
- };
2277
-
2278
- const handleEnter = e => {
2279
- const target = e.target || {};
2280
-
2281
- if (preload) {
2282
- if (target.preloadTimeout) {
2283
- return;
2284
- }
2285
-
2286
- target.preloadTimeout = setTimeout(() => {
2287
- target.preloadTimeout = null;
2288
- router.preloadRoute(nextOpts, {
2289
- maxAge: userPreloadMaxAge,
2290
- gcMaxAge: userPreloadGcMaxAge
2291
- });
2292
- }, preloadDelay);
2293
- }
2294
- };
2295
-
2296
- const handleLeave = e => {
2297
- const target = e.target || {};
2298
-
2299
- if (target.preloadTimeout) {
2300
- clearTimeout(target.preloadTimeout);
2301
- target.preloadTimeout = null;
2302
- }
2303
- };
2304
-
2305
- return {
2306
- type: 'internal',
2307
- next,
2308
- handleFocus,
2309
- handleClick,
2310
- handleEnter,
2311
- handleLeave,
2312
- isActive,
2313
- disabled
2314
- };
2315
- },
2316
- buildNext: opts => {
2317
- const next = router.__.buildLocation(opts);
2318
-
2319
- const matches = router.matchRoutes(next.pathname);
2320
-
2321
- const __preSearchFilters = matches.map(match => {
2322
- var _match$options$preSea;
2323
-
2324
- return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
2325
- }).flat().filter(Boolean);
2326
-
2327
- const __postSearchFilters = matches.map(match => {
2328
- var _match$options$postSe;
2329
-
2330
- return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
2331
- }).flat().filter(Boolean);
2332
-
2333
- return router.__.buildLocation(_extends({}, opts, {
2334
- __preSearchFilters,
2335
- __postSearchFilters
2336
- }));
2337
- },
2338
- __: {
2339
- buildRouteTree: rootRouteConfig => {
2340
- const recurseRoutes = (routeConfigs, parent) => {
2341
- return routeConfigs.map(routeConfig => {
2342
- const routeOptions = routeConfig.options;
2343
- const route = createRoute(routeConfig, routeOptions, parent, router);
2344
- const existingRoute = router.routesById[route.routeId];
2345
-
2346
- if (existingRoute) {
2347
- if (process.env.NODE_ENV !== 'production') {
2348
- console.warn("Duplicate routes found with id: " + String(route.routeId), router.routesById, route);
2349
- }
2350
-
2351
- throw new Error();
2352
- }
2353
- router.routesById[route.routeId] = route;
2354
- const children = routeConfig.children;
2355
- route.childRoutes = children != null && children.length ? recurseRoutes(children, route) : undefined;
2356
- return route;
2357
- });
2358
- };
2359
-
2360
- const routes = recurseRoutes([rootRouteConfig]);
2361
- return routes[0];
2362
- },
2363
- parseLocation: (location, previousLocation) => {
2364
- var _location$hash$split$;
2365
-
2366
- const parsedSearch = router.options.parseSearch(location.search);
2367
- return {
2368
- pathname: location.pathname,
2369
- searchStr: location.search,
2370
- search: replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
2371
- hash: (_location$hash$split$ = location.hash.split('#').reverse()[0]) != null ? _location$hash$split$ : '',
2372
- href: "" + location.pathname + location.search + location.hash,
2373
- state: location.state,
2374
- key: location.key
2375
- };
2376
- },
2377
- navigate: location => {
2378
- const next = router.buildNext(location);
2379
- return router.__.commitLocation(next, location.replace);
2380
- },
2381
- buildLocation: function buildLocation(dest) {
2382
- var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
2383
-
2384
- if (dest === void 0) {
2385
- dest = {};
2386
- }
2387
-
2388
- // const resolvedFrom: Location = {
2389
- // ...router.location,
2390
- const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
2391
-
2392
- let pathname = resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
2393
-
2394
- const fromMatches = router.matchRoutes(router.location.pathname, {
2395
- strictParseParams: true
2396
- });
2397
- const toMatches = router.matchRoutes(pathname);
2398
-
2399
- const prevParams = _extends({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
2400
-
2401
- let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
2402
-
2403
- if (nextParams) {
2404
- toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
2405
- Object.assign({}, nextParams, fn(nextParams));
2406
- });
2407
- }
2408
-
2409
- pathname = interpolatePath(pathname, nextParams != null ? nextParams : {}); // Pre filters first
2410
-
2411
- const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.location.search) : router.location.search; // Then the link/navigate function
2412
-
2413
- const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
2414
- : dest.search ? (_functionalUpdate = functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
2415
- : (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
2416
- : {}; // Then post filters
2417
-
2418
- const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
2419
- const search = replaceEqualDeep(router.location.search, postFilteredSearch);
2420
- const searchStr = router.options.stringifySearch(search);
2421
- let hash = dest.hash === true ? router.location.hash : functionalUpdate(dest.hash, router.location.hash);
2422
- hash = hash ? "#" + hash : '';
2423
- return {
2424
- pathname,
2425
- search,
2426
- searchStr,
2427
- state: router.location.state,
2428
- hash,
2429
- href: "" + pathname + searchStr + hash,
2430
- key: dest.key
2431
- };
2432
- },
2433
- commitLocation: (next, replace) => {
2434
- const id = '' + Date.now() + Math.random();
2435
- if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
2436
- let nextAction = 'replace';
2437
-
2438
- if (!replace) {
2439
- nextAction = 'push';
2440
- }
2441
-
2442
- const isSameUrl = router.__.parseLocation(history.location).href === next.href;
2443
-
2444
- if (isSameUrl && !next.key) {
2445
- nextAction = 'replace';
2446
- }
2447
-
2448
- if (nextAction === 'replace') {
2449
- history.replace({
2450
- pathname: next.pathname,
2451
- hash: next.hash,
2452
- search: next.searchStr
2453
- }, _extends({
2454
- id
2455
- }, next.state));
2456
- } else {
2457
- history.push({
2458
- pathname: next.pathname,
2459
- hash: next.hash,
2460
- search: next.searchStr
2461
- }, {
2462
- id
2463
- });
2464
- }
2465
-
2466
- router.navigationPromise = new Promise(resolve => {
2467
- const previousNavigationResolve = router.resolveNavigation;
2468
-
2469
- router.resolveNavigation = () => {
2470
- previousNavigationResolve();
2471
- resolve();
2472
- };
2473
- });
2474
- return router.navigationPromise;
2475
- }
2476
- }
2477
- };
2478
- router.update(userOptions); // Allow frameworks to hook into the router creation
2479
-
2480
- router.options.createRouter == null ? void 0 : router.options.createRouter(router);
2481
- return router;
2482
- }
2483
-
2484
- function isCtrlEvent(e) {
2485
- return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
2486
- }
2487
-
2488
- function cascadeLoaderData(matches) {
2489
- matches.forEach((match, index) => {
2490
- const parent = matches[index - 1];
2491
-
2492
- if (parent) {
2493
- match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
2494
- }
2495
- });
2496
- }
2497
-
2498
- exports.cleanPath = cleanPath;
2499
- exports.createBrowserHistory = createBrowserHistory;
2500
- exports.createHashHistory = createHashHistory;
2501
- exports.createMemoryHistory = createMemoryHistory;
2502
- exports.createRoute = createRoute;
2503
- exports.createRouteConfig = createRouteConfig;
2504
- exports.createRouteMatch = createRouteMatch;
2505
- exports.createRouter = createRouter;
2506
- exports.decode = decode;
2507
- exports.defaultParseSearch = defaultParseSearch;
2508
- exports.defaultStringifySearch = defaultStringifySearch;
2509
- exports.encode = encode;
2510
- exports.functionalUpdate = functionalUpdate;
2511
- exports.interpolatePath = interpolatePath;
2512
- exports.invariant = invariant;
2513
- exports.joinPaths = joinPaths;
2514
- exports.last = last;
2515
- exports.matchByPath = matchByPath;
2516
- exports.matchPathname = matchPathname;
2517
- exports.parsePathname = parsePathname;
2518
- exports.parseSearchWith = parseSearchWith;
2519
- exports.pick = pick;
2520
- exports.replaceEqualDeep = replaceEqualDeep;
2521
- exports.resolvePath = resolvePath;
2522
- exports.rootRouteId = rootRouteId;
2523
- exports.stringifySearchWith = stringifySearchWith;
2524
- exports.trimPath = trimPath;
2525
- exports.trimPathLeft = trimPathLeft;
2526
- exports.trimPathRight = trimPathRight;
2527
- exports.warning = warning;
2528
- //# sourceMappingURL=index.js.map