@tanstack/react-router 0.0.1-beta.2 → 0.0.1-beta.200
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +1 -19
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/cjs/awaited.js +45 -0
- package/build/cjs/awaited.js.map +1 -0
- package/build/cjs/index.js +66 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/react.js +642 -0
- package/build/cjs/react.js.map +1 -0
- package/build/cjs/scroll-restoration.js +56 -0
- package/build/cjs/scroll-restoration.js.map +1 -0
- package/build/esm/index.js +548 -2789
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +312 -37
- package/build/types/awaited.d.ts +8 -0
- package/build/types/index.d.ts +4 -73
- package/build/types/react.d.ts +200 -0
- package/build/types/scroll-restoration.d.ts +3 -0
- package/build/umd/index.development.js +2539 -2427
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +35 -4
- package/build/umd/index.production.js.map +1 -1
- package/package.json +12 -10
- package/src/awaited.tsx +40 -0
- package/src/index.tsx +5 -624
- package/src/react.tsx +1228 -0
- package/src/scroll-restoration.tsx +27 -0
- package/build/cjs/react-router/src/index.js +0 -465
- package/build/cjs/react-router/src/index.js.map +0 -1
- package/build/cjs/router-core/build/esm/index.js +0 -2493
- package/build/cjs/router-core/build/esm/index.js.map +0 -1
package/build/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router
|
|
2
|
+
* @tanstack/react-router/src/index.tsx
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) TanStack
|
|
5
5
|
*
|
|
@@ -8,2876 +8,635 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
+
import { useStore } from '@tanstack/react-store';
|
|
12
|
+
export { useStore } from '@tanstack/react-store';
|
|
13
|
+
import { Route, functionalUpdate, rootRouteId, last, pick, watchScrollPositions, restoreScrollPositions, isDehydratedDeferred } from '@tanstack/router-core';
|
|
14
|
+
export * from '@tanstack/router-core';
|
|
11
15
|
import * as React from 'react';
|
|
12
|
-
import
|
|
16
|
+
import invariant from 'tiny-invariant';
|
|
17
|
+
import warning from 'tiny-warning';
|
|
13
18
|
|
|
14
|
-
function _extends
|
|
15
|
-
_extends
|
|
16
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
17
|
-
var source = arguments[i];
|
|
18
|
-
|
|
19
|
-
for (var key in source) {
|
|
20
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
21
|
-
target[key] = source[key];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return target;
|
|
27
|
-
};
|
|
28
|
-
return _extends$2.apply(this, arguments);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
32
|
-
if (source == null) return {};
|
|
33
|
-
var target = {};
|
|
34
|
-
var sourceKeys = Object.keys(source);
|
|
35
|
-
var key, i;
|
|
36
|
-
|
|
37
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
38
|
-
key = sourceKeys[i];
|
|
39
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
40
|
-
target[key] = source[key];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return target;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* router-core
|
|
48
|
-
*
|
|
49
|
-
* Copyright (c) TanStack
|
|
50
|
-
*
|
|
51
|
-
* This source code is licensed under the MIT license found in the
|
|
52
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
53
|
-
*
|
|
54
|
-
* @license MIT
|
|
55
|
-
*/
|
|
56
|
-
function _extends$1() {
|
|
57
|
-
_extends$1 = Object.assign ? Object.assign.bind() : function (target) {
|
|
19
|
+
function _extends() {
|
|
20
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
58
21
|
for (var i = 1; i < arguments.length; i++) {
|
|
59
22
|
var source = arguments[i];
|
|
60
|
-
|
|
61
23
|
for (var key in source) {
|
|
62
24
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
63
25
|
target[key] = source[key];
|
|
64
26
|
}
|
|
65
27
|
}
|
|
66
28
|
}
|
|
67
|
-
|
|
68
29
|
return target;
|
|
69
30
|
};
|
|
70
|
-
return _extends
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Actions represent the type of change to a location value.
|
|
75
|
-
*
|
|
76
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#action
|
|
77
|
-
*/
|
|
78
|
-
var Action;
|
|
79
|
-
|
|
80
|
-
(function (Action) {
|
|
81
|
-
/**
|
|
82
|
-
* A POP indicates a change to an arbitrary index in the history stack, such
|
|
83
|
-
* as a back or forward navigation. It does not describe the direction of the
|
|
84
|
-
* navigation, only that the current index changed.
|
|
85
|
-
*
|
|
86
|
-
* Note: This is the default action for newly created history objects.
|
|
87
|
-
*/
|
|
88
|
-
Action["Pop"] = "POP";
|
|
89
|
-
/**
|
|
90
|
-
* A PUSH indicates a new entry being added to the history stack, such as when
|
|
91
|
-
* a link is clicked and a new page loads. When this happens, all subsequent
|
|
92
|
-
* entries in the stack are lost.
|
|
93
|
-
*/
|
|
94
|
-
|
|
95
|
-
Action["Push"] = "PUSH";
|
|
96
|
-
/**
|
|
97
|
-
* A REPLACE indicates the entry at the current index in the history stack
|
|
98
|
-
* being replaced by a new one.
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
Action["Replace"] = "REPLACE";
|
|
102
|
-
})(Action || (Action = {}));
|
|
103
|
-
|
|
104
|
-
var readOnly = process.env.NODE_ENV !== "production" ? function (obj) {
|
|
105
|
-
return Object.freeze(obj);
|
|
106
|
-
} : function (obj) {
|
|
107
|
-
return obj;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
function warning$1(cond, message) {
|
|
111
|
-
if (!cond) {
|
|
112
|
-
// eslint-disable-next-line no-console
|
|
113
|
-
if (typeof console !== 'undefined') console.warn(message);
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
// Welcome to debugging history!
|
|
117
|
-
//
|
|
118
|
-
// This error is thrown as a convenience so you can more easily
|
|
119
|
-
// find the source for a warning that appears in the console by
|
|
120
|
-
// enabling "pause on exceptions" in your JavaScript debugger.
|
|
121
|
-
throw new Error(message); // eslint-disable-next-line no-empty
|
|
122
|
-
} catch (e) {}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
var BeforeUnloadEventType = 'beforeunload';
|
|
127
|
-
var HashChangeEventType = 'hashchange';
|
|
128
|
-
var PopStateEventType = 'popstate';
|
|
129
|
-
/**
|
|
130
|
-
* Browser history stores the location in regular URLs. This is the standard for
|
|
131
|
-
* most web apps, but it requires some configuration on the server to ensure you
|
|
132
|
-
* serve the same app at multiple URLs.
|
|
133
|
-
*
|
|
134
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
|
|
135
|
-
*/
|
|
136
|
-
|
|
137
|
-
function createBrowserHistory(options) {
|
|
138
|
-
if (options === void 0) {
|
|
139
|
-
options = {};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
var _options = options,
|
|
143
|
-
_options$window = _options.window,
|
|
144
|
-
window = _options$window === void 0 ? document.defaultView : _options$window;
|
|
145
|
-
var globalHistory = window.history;
|
|
146
|
-
|
|
147
|
-
function getIndexAndLocation() {
|
|
148
|
-
var _window$location = window.location,
|
|
149
|
-
pathname = _window$location.pathname,
|
|
150
|
-
search = _window$location.search,
|
|
151
|
-
hash = _window$location.hash;
|
|
152
|
-
var state = globalHistory.state || {};
|
|
153
|
-
return [state.idx, readOnly({
|
|
154
|
-
pathname: pathname,
|
|
155
|
-
search: search,
|
|
156
|
-
hash: hash,
|
|
157
|
-
state: state.usr || null,
|
|
158
|
-
key: state.key || 'default'
|
|
159
|
-
})];
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
var blockedPopTx = null;
|
|
163
|
-
|
|
164
|
-
function handlePop() {
|
|
165
|
-
if (blockedPopTx) {
|
|
166
|
-
blockers.call(blockedPopTx);
|
|
167
|
-
blockedPopTx = null;
|
|
168
|
-
} else {
|
|
169
|
-
var nextAction = Action.Pop;
|
|
170
|
-
|
|
171
|
-
var _getIndexAndLocation = getIndexAndLocation(),
|
|
172
|
-
nextIndex = _getIndexAndLocation[0],
|
|
173
|
-
nextLocation = _getIndexAndLocation[1];
|
|
174
|
-
|
|
175
|
-
if (blockers.length) {
|
|
176
|
-
if (nextIndex != null) {
|
|
177
|
-
var delta = index - nextIndex;
|
|
178
|
-
|
|
179
|
-
if (delta) {
|
|
180
|
-
// Revert the POP
|
|
181
|
-
blockedPopTx = {
|
|
182
|
-
action: nextAction,
|
|
183
|
-
location: nextLocation,
|
|
184
|
-
retry: function retry() {
|
|
185
|
-
go(delta * -1);
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
go(delta);
|
|
189
|
-
}
|
|
190
|
-
} else {
|
|
191
|
-
// Trying to POP to a location with no index. We did not create
|
|
192
|
-
// this location, so we can't effectively block the navigation.
|
|
193
|
-
process.env.NODE_ENV !== "production" ? warning$1(false, // TODO: Write up a doc that explains our blocking strategy in
|
|
194
|
-
// detail and link to it here so people can understand better what
|
|
195
|
-
// is going on and how to avoid it.
|
|
196
|
-
"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;
|
|
197
|
-
}
|
|
198
|
-
} else {
|
|
199
|
-
applyTx(nextAction);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
window.addEventListener(PopStateEventType, handlePop);
|
|
205
|
-
var action = Action.Pop;
|
|
206
|
-
|
|
207
|
-
var _getIndexAndLocation2 = getIndexAndLocation(),
|
|
208
|
-
index = _getIndexAndLocation2[0],
|
|
209
|
-
location = _getIndexAndLocation2[1];
|
|
210
|
-
|
|
211
|
-
var listeners = createEvents();
|
|
212
|
-
var blockers = createEvents();
|
|
213
|
-
|
|
214
|
-
if (index == null) {
|
|
215
|
-
index = 0;
|
|
216
|
-
globalHistory.replaceState(_extends$1({}, globalHistory.state, {
|
|
217
|
-
idx: index
|
|
218
|
-
}), '');
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function createHref(to) {
|
|
222
|
-
return typeof to === 'string' ? to : createPath(to);
|
|
223
|
-
} // state defaults to `null` because `window.history.state` does
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
function getNextLocation(to, state) {
|
|
227
|
-
if (state === void 0) {
|
|
228
|
-
state = null;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return readOnly(_extends$1({
|
|
232
|
-
pathname: location.pathname,
|
|
233
|
-
hash: '',
|
|
234
|
-
search: ''
|
|
235
|
-
}, typeof to === 'string' ? parsePath(to) : to, {
|
|
236
|
-
state: state,
|
|
237
|
-
key: createKey()
|
|
238
|
-
}));
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function getHistoryStateAndUrl(nextLocation, index) {
|
|
242
|
-
return [{
|
|
243
|
-
usr: nextLocation.state,
|
|
244
|
-
key: nextLocation.key,
|
|
245
|
-
idx: index
|
|
246
|
-
}, createHref(nextLocation)];
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
function allowTx(action, location, retry) {
|
|
250
|
-
return !blockers.length || (blockers.call({
|
|
251
|
-
action: action,
|
|
252
|
-
location: location,
|
|
253
|
-
retry: retry
|
|
254
|
-
}), false);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function applyTx(nextAction) {
|
|
258
|
-
action = nextAction;
|
|
259
|
-
|
|
260
|
-
var _getIndexAndLocation3 = getIndexAndLocation();
|
|
261
|
-
|
|
262
|
-
index = _getIndexAndLocation3[0];
|
|
263
|
-
location = _getIndexAndLocation3[1];
|
|
264
|
-
listeners.call({
|
|
265
|
-
action: action,
|
|
266
|
-
location: location
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function push(to, state) {
|
|
271
|
-
var nextAction = Action.Push;
|
|
272
|
-
var nextLocation = getNextLocation(to, state);
|
|
273
|
-
|
|
274
|
-
function retry() {
|
|
275
|
-
push(to, state);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
279
|
-
var _getHistoryStateAndUr = getHistoryStateAndUrl(nextLocation, index + 1),
|
|
280
|
-
historyState = _getHistoryStateAndUr[0],
|
|
281
|
-
url = _getHistoryStateAndUr[1]; // TODO: Support forced reloading
|
|
282
|
-
// try...catch because iOS limits us to 100 pushState calls :/
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
try {
|
|
286
|
-
globalHistory.pushState(historyState, '', url);
|
|
287
|
-
} catch (error) {
|
|
288
|
-
// They are going to lose state here, but there is no real
|
|
289
|
-
// way to warn them about it since the page will refresh...
|
|
290
|
-
window.location.assign(url);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
applyTx(nextAction);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
function replace(to, state) {
|
|
298
|
-
var nextAction = Action.Replace;
|
|
299
|
-
var nextLocation = getNextLocation(to, state);
|
|
300
|
-
|
|
301
|
-
function retry() {
|
|
302
|
-
replace(to, state);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
306
|
-
var _getHistoryStateAndUr2 = getHistoryStateAndUrl(nextLocation, index),
|
|
307
|
-
historyState = _getHistoryStateAndUr2[0],
|
|
308
|
-
url = _getHistoryStateAndUr2[1]; // TODO: Support forced reloading
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
globalHistory.replaceState(historyState, '', url);
|
|
312
|
-
applyTx(nextAction);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
function go(delta) {
|
|
317
|
-
globalHistory.go(delta);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
var history = {
|
|
321
|
-
get action() {
|
|
322
|
-
return action;
|
|
323
|
-
},
|
|
324
|
-
|
|
325
|
-
get location() {
|
|
326
|
-
return location;
|
|
327
|
-
},
|
|
328
|
-
|
|
329
|
-
createHref: createHref,
|
|
330
|
-
push: push,
|
|
331
|
-
replace: replace,
|
|
332
|
-
go: go,
|
|
333
|
-
back: function back() {
|
|
334
|
-
go(-1);
|
|
335
|
-
},
|
|
336
|
-
forward: function forward() {
|
|
337
|
-
go(1);
|
|
338
|
-
},
|
|
339
|
-
listen: function listen(listener) {
|
|
340
|
-
return listeners.push(listener);
|
|
341
|
-
},
|
|
342
|
-
block: function block(blocker) {
|
|
343
|
-
var unblock = blockers.push(blocker);
|
|
344
|
-
|
|
345
|
-
if (blockers.length === 1) {
|
|
346
|
-
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return function () {
|
|
350
|
-
unblock(); // Remove the beforeunload listener so the document may
|
|
351
|
-
// still be salvageable in the pagehide event.
|
|
352
|
-
// See https://html.spec.whatwg.org/#unloading-documents
|
|
353
|
-
|
|
354
|
-
if (!blockers.length) {
|
|
355
|
-
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
return history;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Hash history stores the location in window.location.hash. This makes it ideal
|
|
364
|
-
* for situations where you don't want to send the location to the server for
|
|
365
|
-
* some reason, either because you do cannot configure it or the URL space is
|
|
366
|
-
* reserved for something else.
|
|
367
|
-
*
|
|
368
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
|
|
369
|
-
*/
|
|
370
|
-
|
|
371
|
-
function createHashHistory(options) {
|
|
372
|
-
if (options === void 0) {
|
|
373
|
-
options = {};
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
var _options2 = options,
|
|
377
|
-
_options2$window = _options2.window,
|
|
378
|
-
window = _options2$window === void 0 ? document.defaultView : _options2$window;
|
|
379
|
-
var globalHistory = window.history;
|
|
380
|
-
|
|
381
|
-
function getIndexAndLocation() {
|
|
382
|
-
var _parsePath = parsePath(window.location.hash.substr(1)),
|
|
383
|
-
_parsePath$pathname = _parsePath.pathname,
|
|
384
|
-
pathname = _parsePath$pathname === void 0 ? '/' : _parsePath$pathname,
|
|
385
|
-
_parsePath$search = _parsePath.search,
|
|
386
|
-
search = _parsePath$search === void 0 ? '' : _parsePath$search,
|
|
387
|
-
_parsePath$hash = _parsePath.hash,
|
|
388
|
-
hash = _parsePath$hash === void 0 ? '' : _parsePath$hash;
|
|
389
|
-
|
|
390
|
-
var state = globalHistory.state || {};
|
|
391
|
-
return [state.idx, readOnly({
|
|
392
|
-
pathname: pathname,
|
|
393
|
-
search: search,
|
|
394
|
-
hash: hash,
|
|
395
|
-
state: state.usr || null,
|
|
396
|
-
key: state.key || 'default'
|
|
397
|
-
})];
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
var blockedPopTx = null;
|
|
401
|
-
|
|
402
|
-
function handlePop() {
|
|
403
|
-
if (blockedPopTx) {
|
|
404
|
-
blockers.call(blockedPopTx);
|
|
405
|
-
blockedPopTx = null;
|
|
406
|
-
} else {
|
|
407
|
-
var nextAction = Action.Pop;
|
|
408
|
-
|
|
409
|
-
var _getIndexAndLocation4 = getIndexAndLocation(),
|
|
410
|
-
nextIndex = _getIndexAndLocation4[0],
|
|
411
|
-
nextLocation = _getIndexAndLocation4[1];
|
|
412
|
-
|
|
413
|
-
if (blockers.length) {
|
|
414
|
-
if (nextIndex != null) {
|
|
415
|
-
var delta = index - nextIndex;
|
|
416
|
-
|
|
417
|
-
if (delta) {
|
|
418
|
-
// Revert the POP
|
|
419
|
-
blockedPopTx = {
|
|
420
|
-
action: nextAction,
|
|
421
|
-
location: nextLocation,
|
|
422
|
-
retry: function retry() {
|
|
423
|
-
go(delta * -1);
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
go(delta);
|
|
427
|
-
}
|
|
428
|
-
} else {
|
|
429
|
-
// Trying to POP to a location with no index. We did not create
|
|
430
|
-
// this location, so we can't effectively block the navigation.
|
|
431
|
-
process.env.NODE_ENV !== "production" ? warning$1(false, // TODO: Write up a doc that explains our blocking strategy in
|
|
432
|
-
// detail and link to it here so people can understand better
|
|
433
|
-
// what is going on and how to avoid it.
|
|
434
|
-
"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;
|
|
435
|
-
}
|
|
436
|
-
} else {
|
|
437
|
-
applyTx(nextAction);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
window.addEventListener(PopStateEventType, handlePop); // popstate does not fire on hashchange in IE 11 and old (trident) Edge
|
|
443
|
-
// https://developer.mozilla.org/de/docs/Web/API/Window/popstate_event
|
|
444
|
-
|
|
445
|
-
window.addEventListener(HashChangeEventType, function () {
|
|
446
|
-
var _getIndexAndLocation5 = getIndexAndLocation(),
|
|
447
|
-
nextLocation = _getIndexAndLocation5[1]; // Ignore extraneous hashchange events.
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
if (createPath(nextLocation) !== createPath(location)) {
|
|
451
|
-
handlePop();
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
var action = Action.Pop;
|
|
455
|
-
|
|
456
|
-
var _getIndexAndLocation6 = getIndexAndLocation(),
|
|
457
|
-
index = _getIndexAndLocation6[0],
|
|
458
|
-
location = _getIndexAndLocation6[1];
|
|
459
|
-
|
|
460
|
-
var listeners = createEvents();
|
|
461
|
-
var blockers = createEvents();
|
|
462
|
-
|
|
463
|
-
if (index == null) {
|
|
464
|
-
index = 0;
|
|
465
|
-
globalHistory.replaceState(_extends$1({}, globalHistory.state, {
|
|
466
|
-
idx: index
|
|
467
|
-
}), '');
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
function getBaseHref() {
|
|
471
|
-
var base = document.querySelector('base');
|
|
472
|
-
var href = '';
|
|
473
|
-
|
|
474
|
-
if (base && base.getAttribute('href')) {
|
|
475
|
-
var url = window.location.href;
|
|
476
|
-
var hashIndex = url.indexOf('#');
|
|
477
|
-
href = hashIndex === -1 ? url : url.slice(0, hashIndex);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
return href;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
function createHref(to) {
|
|
484
|
-
return getBaseHref() + '#' + (typeof to === 'string' ? to : createPath(to));
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
function getNextLocation(to, state) {
|
|
488
|
-
if (state === void 0) {
|
|
489
|
-
state = null;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
return readOnly(_extends$1({
|
|
493
|
-
pathname: location.pathname,
|
|
494
|
-
hash: '',
|
|
495
|
-
search: ''
|
|
496
|
-
}, typeof to === 'string' ? parsePath(to) : to, {
|
|
497
|
-
state: state,
|
|
498
|
-
key: createKey()
|
|
499
|
-
}));
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
function getHistoryStateAndUrl(nextLocation, index) {
|
|
503
|
-
return [{
|
|
504
|
-
usr: nextLocation.state,
|
|
505
|
-
key: nextLocation.key,
|
|
506
|
-
idx: index
|
|
507
|
-
}, createHref(nextLocation)];
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
function allowTx(action, location, retry) {
|
|
511
|
-
return !blockers.length || (blockers.call({
|
|
512
|
-
action: action,
|
|
513
|
-
location: location,
|
|
514
|
-
retry: retry
|
|
515
|
-
}), false);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
function applyTx(nextAction) {
|
|
519
|
-
action = nextAction;
|
|
520
|
-
|
|
521
|
-
var _getIndexAndLocation7 = getIndexAndLocation();
|
|
522
|
-
|
|
523
|
-
index = _getIndexAndLocation7[0];
|
|
524
|
-
location = _getIndexAndLocation7[1];
|
|
525
|
-
listeners.call({
|
|
526
|
-
action: action,
|
|
527
|
-
location: location
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
function push(to, state) {
|
|
532
|
-
var nextAction = Action.Push;
|
|
533
|
-
var nextLocation = getNextLocation(to, state);
|
|
534
|
-
|
|
535
|
-
function retry() {
|
|
536
|
-
push(to, state);
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
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;
|
|
540
|
-
|
|
541
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
542
|
-
var _getHistoryStateAndUr3 = getHistoryStateAndUrl(nextLocation, index + 1),
|
|
543
|
-
historyState = _getHistoryStateAndUr3[0],
|
|
544
|
-
url = _getHistoryStateAndUr3[1]; // TODO: Support forced reloading
|
|
545
|
-
// try...catch because iOS limits us to 100 pushState calls :/
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
try {
|
|
549
|
-
globalHistory.pushState(historyState, '', url);
|
|
550
|
-
} catch (error) {
|
|
551
|
-
// They are going to lose state here, but there is no real
|
|
552
|
-
// way to warn them about it since the page will refresh...
|
|
553
|
-
window.location.assign(url);
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
applyTx(nextAction);
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
function replace(to, state) {
|
|
561
|
-
var nextAction = Action.Replace;
|
|
562
|
-
var nextLocation = getNextLocation(to, state);
|
|
563
|
-
|
|
564
|
-
function retry() {
|
|
565
|
-
replace(to, state);
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
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;
|
|
569
|
-
|
|
570
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
571
|
-
var _getHistoryStateAndUr4 = getHistoryStateAndUrl(nextLocation, index),
|
|
572
|
-
historyState = _getHistoryStateAndUr4[0],
|
|
573
|
-
url = _getHistoryStateAndUr4[1]; // TODO: Support forced reloading
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
globalHistory.replaceState(historyState, '', url);
|
|
577
|
-
applyTx(nextAction);
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
function go(delta) {
|
|
582
|
-
globalHistory.go(delta);
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
var history = {
|
|
586
|
-
get action() {
|
|
587
|
-
return action;
|
|
588
|
-
},
|
|
589
|
-
|
|
590
|
-
get location() {
|
|
591
|
-
return location;
|
|
592
|
-
},
|
|
593
|
-
|
|
594
|
-
createHref: createHref,
|
|
595
|
-
push: push,
|
|
596
|
-
replace: replace,
|
|
597
|
-
go: go,
|
|
598
|
-
back: function back() {
|
|
599
|
-
go(-1);
|
|
600
|
-
},
|
|
601
|
-
forward: function forward() {
|
|
602
|
-
go(1);
|
|
603
|
-
},
|
|
604
|
-
listen: function listen(listener) {
|
|
605
|
-
return listeners.push(listener);
|
|
606
|
-
},
|
|
607
|
-
block: function block(blocker) {
|
|
608
|
-
var unblock = blockers.push(blocker);
|
|
609
|
-
|
|
610
|
-
if (blockers.length === 1) {
|
|
611
|
-
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
return function () {
|
|
615
|
-
unblock(); // Remove the beforeunload listener so the document may
|
|
616
|
-
// still be salvageable in the pagehide event.
|
|
617
|
-
// See https://html.spec.whatwg.org/#unloading-documents
|
|
618
|
-
|
|
619
|
-
if (!blockers.length) {
|
|
620
|
-
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
621
|
-
}
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
};
|
|
625
|
-
return history;
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* Memory history stores the current location in memory. It is designed for use
|
|
629
|
-
* in stateful non-browser environments like tests and React Native.
|
|
630
|
-
*
|
|
631
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#creatememoryhistory
|
|
632
|
-
*/
|
|
633
|
-
|
|
634
|
-
function createMemoryHistory(options) {
|
|
635
|
-
if (options === void 0) {
|
|
636
|
-
options = {};
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
var _options3 = options,
|
|
640
|
-
_options3$initialEntr = _options3.initialEntries,
|
|
641
|
-
initialEntries = _options3$initialEntr === void 0 ? ['/'] : _options3$initialEntr,
|
|
642
|
-
initialIndex = _options3.initialIndex;
|
|
643
|
-
var entries = initialEntries.map(function (entry) {
|
|
644
|
-
var location = readOnly(_extends$1({
|
|
645
|
-
pathname: '/',
|
|
646
|
-
search: '',
|
|
647
|
-
hash: '',
|
|
648
|
-
state: null,
|
|
649
|
-
key: createKey()
|
|
650
|
-
}, typeof entry === 'string' ? parsePath(entry) : entry));
|
|
651
|
-
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;
|
|
652
|
-
return location;
|
|
653
|
-
});
|
|
654
|
-
var index = clamp(initialIndex == null ? entries.length - 1 : initialIndex, 0, entries.length - 1);
|
|
655
|
-
var action = Action.Pop;
|
|
656
|
-
var location = entries[index];
|
|
657
|
-
var listeners = createEvents();
|
|
658
|
-
var blockers = createEvents();
|
|
659
|
-
|
|
660
|
-
function createHref(to) {
|
|
661
|
-
return typeof to === 'string' ? to : createPath(to);
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
function getNextLocation(to, state) {
|
|
665
|
-
if (state === void 0) {
|
|
666
|
-
state = null;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
return readOnly(_extends$1({
|
|
670
|
-
pathname: location.pathname,
|
|
671
|
-
search: '',
|
|
672
|
-
hash: ''
|
|
673
|
-
}, typeof to === 'string' ? parsePath(to) : to, {
|
|
674
|
-
state: state,
|
|
675
|
-
key: createKey()
|
|
676
|
-
}));
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
function allowTx(action, location, retry) {
|
|
680
|
-
return !blockers.length || (blockers.call({
|
|
681
|
-
action: action,
|
|
682
|
-
location: location,
|
|
683
|
-
retry: retry
|
|
684
|
-
}), false);
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
function applyTx(nextAction, nextLocation) {
|
|
688
|
-
action = nextAction;
|
|
689
|
-
location = nextLocation;
|
|
690
|
-
listeners.call({
|
|
691
|
-
action: action,
|
|
692
|
-
location: location
|
|
693
|
-
});
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
function push(to, state) {
|
|
697
|
-
var nextAction = Action.Push;
|
|
698
|
-
var nextLocation = getNextLocation(to, state);
|
|
699
|
-
|
|
700
|
-
function retry() {
|
|
701
|
-
push(to, state);
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
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;
|
|
705
|
-
|
|
706
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
707
|
-
index += 1;
|
|
708
|
-
entries.splice(index, entries.length, nextLocation);
|
|
709
|
-
applyTx(nextAction, nextLocation);
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
function replace(to, state) {
|
|
714
|
-
var nextAction = Action.Replace;
|
|
715
|
-
var nextLocation = getNextLocation(to, state);
|
|
716
|
-
|
|
717
|
-
function retry() {
|
|
718
|
-
replace(to, state);
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
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;
|
|
722
|
-
|
|
723
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
724
|
-
entries[index] = nextLocation;
|
|
725
|
-
applyTx(nextAction, nextLocation);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
function go(delta) {
|
|
730
|
-
var nextIndex = clamp(index + delta, 0, entries.length - 1);
|
|
731
|
-
var nextAction = Action.Pop;
|
|
732
|
-
var nextLocation = entries[nextIndex];
|
|
733
|
-
|
|
734
|
-
function retry() {
|
|
735
|
-
go(delta);
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
739
|
-
index = nextIndex;
|
|
740
|
-
applyTx(nextAction, nextLocation);
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
var history = {
|
|
745
|
-
get index() {
|
|
746
|
-
return index;
|
|
747
|
-
},
|
|
748
|
-
|
|
749
|
-
get action() {
|
|
750
|
-
return action;
|
|
751
|
-
},
|
|
752
|
-
|
|
753
|
-
get location() {
|
|
754
|
-
return location;
|
|
755
|
-
},
|
|
756
|
-
|
|
757
|
-
createHref: createHref,
|
|
758
|
-
push: push,
|
|
759
|
-
replace: replace,
|
|
760
|
-
go: go,
|
|
761
|
-
back: function back() {
|
|
762
|
-
go(-1);
|
|
763
|
-
},
|
|
764
|
-
forward: function forward() {
|
|
765
|
-
go(1);
|
|
766
|
-
},
|
|
767
|
-
listen: function listen(listener) {
|
|
768
|
-
return listeners.push(listener);
|
|
769
|
-
},
|
|
770
|
-
block: function block(blocker) {
|
|
771
|
-
return blockers.push(blocker);
|
|
772
|
-
}
|
|
773
|
-
};
|
|
774
|
-
return history;
|
|
775
|
-
} ////////////////////////////////////////////////////////////////////////////////
|
|
776
|
-
// UTILS
|
|
777
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
778
|
-
|
|
779
|
-
function clamp(n, lowerBound, upperBound) {
|
|
780
|
-
return Math.min(Math.max(n, lowerBound), upperBound);
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
function promptBeforeUnload(event) {
|
|
784
|
-
// Cancel the event.
|
|
785
|
-
event.preventDefault(); // Chrome (and legacy IE) requires returnValue to be set.
|
|
786
|
-
|
|
787
|
-
event.returnValue = '';
|
|
31
|
+
return _extends.apply(this, arguments);
|
|
788
32
|
}
|
|
789
33
|
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
return
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
handlers.push(fn);
|
|
799
|
-
return function () {
|
|
800
|
-
handlers = handlers.filter(function (handler) {
|
|
801
|
-
return handler !== fn;
|
|
802
|
-
});
|
|
803
|
-
};
|
|
804
|
-
},
|
|
805
|
-
call: function call(arg) {
|
|
806
|
-
handlers.forEach(function (fn) {
|
|
807
|
-
return fn && fn(arg);
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
function createKey() {
|
|
814
|
-
return Math.random().toString(36).substr(2, 8);
|
|
815
|
-
}
|
|
816
|
-
/**
|
|
817
|
-
* Creates a string URL path from the given pathname, search, and hash components.
|
|
818
|
-
*
|
|
819
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createpath
|
|
820
|
-
*/
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
function createPath(_ref) {
|
|
824
|
-
var _ref$pathname = _ref.pathname,
|
|
825
|
-
pathname = _ref$pathname === void 0 ? '/' : _ref$pathname,
|
|
826
|
-
_ref$search = _ref.search,
|
|
827
|
-
search = _ref$search === void 0 ? '' : _ref$search,
|
|
828
|
-
_ref$hash = _ref.hash,
|
|
829
|
-
hash = _ref$hash === void 0 ? '' : _ref$hash;
|
|
830
|
-
if (search && search !== '?') pathname += search.charAt(0) === '?' ? search : '?' + search;
|
|
831
|
-
if (hash && hash !== '#') pathname += hash.charAt(0) === '#' ? hash : '#' + hash;
|
|
832
|
-
return pathname;
|
|
833
|
-
}
|
|
834
|
-
/**
|
|
835
|
-
* Parses a string URL path into its separate pathname, search, and hash components.
|
|
836
|
-
*
|
|
837
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#parsepath
|
|
838
|
-
*/
|
|
839
|
-
|
|
840
|
-
function parsePath(path) {
|
|
841
|
-
var parsedPath = {};
|
|
842
|
-
|
|
843
|
-
if (path) {
|
|
844
|
-
var hashIndex = path.indexOf('#');
|
|
845
|
-
|
|
846
|
-
if (hashIndex >= 0) {
|
|
847
|
-
parsedPath.hash = path.substr(hashIndex);
|
|
848
|
-
path = path.substr(0, hashIndex);
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
var searchIndex = path.indexOf('?');
|
|
852
|
-
|
|
853
|
-
if (searchIndex >= 0) {
|
|
854
|
-
parsedPath.search = path.substr(searchIndex);
|
|
855
|
-
path = path.substr(0, searchIndex);
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
if (path) {
|
|
859
|
-
parsedPath.pathname = path;
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
return parsedPath;
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
var isProduction = process.env.NODE_ENV === 'production';
|
|
867
|
-
var prefix = 'Invariant failed';
|
|
868
|
-
function invariant(condition, message) {
|
|
869
|
-
if (condition) {
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
if (isProduction) {
|
|
873
|
-
throw new Error(prefix);
|
|
874
|
-
}
|
|
875
|
-
var provided = typeof message === 'function' ? message() : message;
|
|
876
|
-
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
|
877
|
-
throw new Error(value);
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
// type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
881
|
-
// k: infer I,
|
|
882
|
-
// ) => any
|
|
883
|
-
// ? I
|
|
884
|
-
// : never
|
|
885
|
-
|
|
886
|
-
/**
|
|
887
|
-
* This function returns `a` if `b` is deeply equal.
|
|
888
|
-
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
889
|
-
* This can be used for structural sharing between JSON values for example.
|
|
890
|
-
*/
|
|
891
|
-
function replaceEqualDeep(prev, next) {
|
|
892
|
-
if (prev === next) {
|
|
893
|
-
return prev;
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
const array = Array.isArray(prev) && Array.isArray(next);
|
|
897
|
-
|
|
898
|
-
if (array || isPlainObject(prev) && isPlainObject(next)) {
|
|
899
|
-
const aSize = array ? prev.length : Object.keys(prev).length;
|
|
900
|
-
const bItems = array ? next : Object.keys(next);
|
|
901
|
-
const bSize = bItems.length;
|
|
902
|
-
const copy = array ? [] : {};
|
|
903
|
-
let equalItems = 0;
|
|
904
|
-
|
|
905
|
-
for (let i = 0; i < bSize; i++) {
|
|
906
|
-
const key = array ? i : bItems[i];
|
|
907
|
-
copy[key] = replaceEqualDeep(prev[key], next[key]);
|
|
908
|
-
|
|
909
|
-
if (copy[key] === prev[key]) {
|
|
910
|
-
equalItems++;
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
return aSize === bSize && equalItems === aSize ? prev : copy;
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
return next;
|
|
918
|
-
} // Copied from: https://github.com/jonschlinkert/is-plain-object
|
|
919
|
-
|
|
920
|
-
function isPlainObject(o) {
|
|
921
|
-
if (!hasObjectPrototype(o)) {
|
|
922
|
-
return false;
|
|
923
|
-
} // If has modified constructor
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
const ctor = o.constructor;
|
|
927
|
-
|
|
928
|
-
if (typeof ctor === 'undefined') {
|
|
929
|
-
return true;
|
|
930
|
-
} // If has modified prototype
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
const prot = ctor.prototype;
|
|
934
|
-
|
|
935
|
-
if (!hasObjectPrototype(prot)) {
|
|
936
|
-
return false;
|
|
937
|
-
} // If constructor does not have an Object-specific method
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
if (!prot.hasOwnProperty('isPrototypeOf')) {
|
|
941
|
-
return false;
|
|
942
|
-
} // Most likely a plain Object
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
return true;
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
function hasObjectPrototype(o) {
|
|
949
|
-
return Object.prototype.toString.call(o) === '[object Object]';
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
function last(arr) {
|
|
953
|
-
return arr[arr.length - 1];
|
|
954
|
-
}
|
|
955
|
-
function warning(cond, message) {
|
|
956
|
-
if (cond) {
|
|
957
|
-
if (typeof console !== 'undefined') console.warn(message);
|
|
958
|
-
|
|
959
|
-
try {
|
|
960
|
-
throw new Error(message);
|
|
961
|
-
} catch (_unused) {}
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
return true;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
function isFunction(d) {
|
|
968
|
-
return typeof d === 'function';
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
function functionalUpdate(updater, previous) {
|
|
972
|
-
if (isFunction(updater)) {
|
|
973
|
-
return updater(previous);
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
return updater;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
function joinPaths(paths) {
|
|
980
|
-
return cleanPath(paths.filter(Boolean).join('/'));
|
|
981
|
-
}
|
|
982
|
-
function cleanPath(path) {
|
|
983
|
-
// remove double slashes
|
|
984
|
-
return path.replace(/\/{2,}/g, '/');
|
|
985
|
-
}
|
|
986
|
-
function trimPathLeft(path) {
|
|
987
|
-
return path === '/' ? path : path.replace(/^\/{1,}/, '');
|
|
988
|
-
}
|
|
989
|
-
function trimPathRight(path) {
|
|
990
|
-
return path === '/' ? path : path.replace(/\/{1,}$/, '');
|
|
991
|
-
}
|
|
992
|
-
function trimPath(path) {
|
|
993
|
-
return trimPathRight(trimPathLeft(path));
|
|
994
|
-
}
|
|
995
|
-
function resolvePath(basepath, base, to) {
|
|
996
|
-
base = base.replace(new RegExp("^" + basepath), '/');
|
|
997
|
-
to = to.replace(new RegExp("^" + basepath), '/');
|
|
998
|
-
let baseSegments = parsePathname(base);
|
|
999
|
-
const toSegments = parsePathname(to);
|
|
1000
|
-
toSegments.forEach((toSegment, index) => {
|
|
1001
|
-
if (toSegment.value === '/') {
|
|
1002
|
-
if (!index) {
|
|
1003
|
-
// Leading slash
|
|
1004
|
-
baseSegments = [toSegment];
|
|
1005
|
-
} else if (index === toSegments.length - 1) {
|
|
1006
|
-
// Trailing Slash
|
|
1007
|
-
baseSegments.push(toSegment);
|
|
1008
|
-
} else ;
|
|
1009
|
-
} else if (toSegment.value === '..') {
|
|
1010
|
-
var _last;
|
|
1011
|
-
|
|
1012
|
-
// Extra trailing slash? pop it off
|
|
1013
|
-
if (baseSegments.length > 1 && ((_last = last(baseSegments)) == null ? void 0 : _last.value) === '/') {
|
|
1014
|
-
baseSegments.pop();
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
baseSegments.pop();
|
|
1018
|
-
} else if (toSegment.value === '.') {
|
|
1019
|
-
return;
|
|
1020
|
-
} else {
|
|
1021
|
-
baseSegments.push(toSegment);
|
|
1022
|
-
}
|
|
1023
|
-
});
|
|
1024
|
-
const joined = joinPaths([basepath, ...baseSegments.map(d => d.value)]);
|
|
1025
|
-
return cleanPath(joined);
|
|
1026
|
-
}
|
|
1027
|
-
function parsePathname(pathname) {
|
|
1028
|
-
if (!pathname) {
|
|
1029
|
-
return [];
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
pathname = cleanPath(pathname);
|
|
1033
|
-
const segments = [];
|
|
1034
|
-
|
|
1035
|
-
if (pathname.slice(0, 1) === '/') {
|
|
1036
|
-
pathname = pathname.substring(1);
|
|
1037
|
-
segments.push({
|
|
1038
|
-
type: 'pathname',
|
|
1039
|
-
value: '/'
|
|
1040
|
-
});
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
if (!pathname) {
|
|
1044
|
-
return segments;
|
|
1045
|
-
} // Remove empty segments and '.' segments
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
const split = pathname.split('/').filter(Boolean);
|
|
1049
|
-
segments.push(...split.map(part => {
|
|
1050
|
-
if (part.startsWith('*')) {
|
|
1051
|
-
return {
|
|
1052
|
-
type: 'wildcard',
|
|
1053
|
-
value: part
|
|
1054
|
-
};
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
if (part.charAt(0) === ':') {
|
|
1058
|
-
return {
|
|
1059
|
-
type: 'param',
|
|
1060
|
-
value: part
|
|
1061
|
-
};
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
return {
|
|
1065
|
-
type: 'pathname',
|
|
1066
|
-
value: part
|
|
1067
|
-
};
|
|
1068
|
-
}));
|
|
1069
|
-
|
|
1070
|
-
if (pathname.slice(-1) === '/') {
|
|
1071
|
-
pathname = pathname.substring(1);
|
|
1072
|
-
segments.push({
|
|
1073
|
-
type: 'pathname',
|
|
1074
|
-
value: '/'
|
|
1075
|
-
});
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
return segments;
|
|
1079
|
-
}
|
|
1080
|
-
function interpolatePath(path, params, leaveWildcard) {
|
|
1081
|
-
const interpolatedPathSegments = parsePathname(path);
|
|
1082
|
-
return joinPaths(interpolatedPathSegments.map(segment => {
|
|
1083
|
-
if (segment.value === '*' && !leaveWildcard) {
|
|
1084
|
-
return '';
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
if (segment.type === 'param') {
|
|
1088
|
-
var _segment$value$substr;
|
|
1089
|
-
|
|
1090
|
-
return (_segment$value$substr = params[segment.value.substring(1)]) != null ? _segment$value$substr : '';
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
return segment.value;
|
|
1094
|
-
}));
|
|
1095
|
-
}
|
|
1096
|
-
function matchPathname(currentPathname, matchLocation) {
|
|
1097
|
-
const pathParams = matchByPath(currentPathname, matchLocation); // const searchMatched = matchBySearch(currentLocation.search, matchLocation)
|
|
1098
|
-
|
|
1099
|
-
if (matchLocation.to && !pathParams) {
|
|
1100
|
-
return;
|
|
1101
|
-
} // if (matchLocation.search && !searchMatched) {
|
|
1102
|
-
// return
|
|
1103
|
-
// }
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
return pathParams != null ? pathParams : {};
|
|
1107
|
-
}
|
|
1108
|
-
function matchByPath(from, matchLocation) {
|
|
1109
|
-
var _matchLocation$to;
|
|
1110
|
-
|
|
1111
|
-
const baseSegments = parsePathname(from);
|
|
1112
|
-
const routeSegments = parsePathname("" + ((_matchLocation$to = matchLocation.to) != null ? _matchLocation$to : '*'));
|
|
1113
|
-
const params = {};
|
|
1114
|
-
|
|
1115
|
-
let isMatch = (() => {
|
|
1116
|
-
for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
|
|
1117
|
-
const baseSegment = baseSegments[i];
|
|
1118
|
-
const routeSegment = routeSegments[i];
|
|
1119
|
-
const isLastRouteSegment = i === routeSegments.length - 1;
|
|
1120
|
-
const isLastBaseSegment = i === baseSegments.length - 1;
|
|
1121
|
-
|
|
1122
|
-
if (routeSegment) {
|
|
1123
|
-
if (routeSegment.type === 'wildcard') {
|
|
1124
|
-
if (baseSegment != null && baseSegment.value) {
|
|
1125
|
-
params['*'] = joinPaths(baseSegments.slice(i).map(d => d.value));
|
|
1126
|
-
return true;
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
return false;
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
if (routeSegment.type === 'pathname') {
|
|
1133
|
-
if (routeSegment.value === '/' && !(baseSegment != null && baseSegment.value)) {
|
|
1134
|
-
return true;
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
if (baseSegment) {
|
|
1138
|
-
if (matchLocation.caseSensitive) {
|
|
1139
|
-
if (routeSegment.value !== baseSegment.value) {
|
|
1140
|
-
return false;
|
|
1141
|
-
}
|
|
1142
|
-
} else if (routeSegment.value.toLowerCase() !== baseSegment.value.toLowerCase()) {
|
|
1143
|
-
return false;
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
if (!baseSegment) {
|
|
1149
|
-
return false;
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
if (routeSegment.type === 'param') {
|
|
1153
|
-
if ((baseSegment == null ? void 0 : baseSegment.value) === '/') {
|
|
1154
|
-
return false;
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
if (!baseSegment.value.startsWith(':')) {
|
|
1158
|
-
params[routeSegment.value.substring(1)] = baseSegment.value;
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
if (isLastRouteSegment && !isLastBaseSegment) {
|
|
1164
|
-
return !!matchLocation.fuzzy;
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
return true;
|
|
1169
|
-
})();
|
|
1170
|
-
|
|
1171
|
-
return isMatch ? params : undefined;
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
// @ts-nocheck
|
|
1175
|
-
// 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.
|
|
1176
|
-
function encode(obj, pfx) {
|
|
1177
|
-
var k,
|
|
1178
|
-
i,
|
|
1179
|
-
tmp,
|
|
1180
|
-
str = '';
|
|
1181
|
-
|
|
1182
|
-
for (k in obj) {
|
|
1183
|
-
if ((tmp = obj[k]) !== void 0) {
|
|
1184
|
-
if (Array.isArray(tmp)) {
|
|
1185
|
-
for (i = 0; i < tmp.length; i++) {
|
|
1186
|
-
str && (str += '&');
|
|
1187
|
-
str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i]);
|
|
1188
|
-
}
|
|
1189
|
-
} else {
|
|
1190
|
-
str && (str += '&');
|
|
1191
|
-
str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp);
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
|
-
return (pfx || '') + str;
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
function toValue(mix) {
|
|
1200
|
-
if (!mix) return '';
|
|
1201
|
-
var str = decodeURIComponent(mix);
|
|
1202
|
-
if (str === 'false') return false;
|
|
1203
|
-
if (str === 'true') return true;
|
|
1204
|
-
return +str * 0 === 0 ? +str : str;
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
function decode(str) {
|
|
1208
|
-
var tmp,
|
|
1209
|
-
k,
|
|
1210
|
-
out = {},
|
|
1211
|
-
arr = str.split('&');
|
|
1212
|
-
|
|
1213
|
-
while (tmp = arr.shift()) {
|
|
1214
|
-
tmp = tmp.split('=');
|
|
1215
|
-
k = tmp.shift();
|
|
1216
|
-
|
|
1217
|
-
if (out[k] !== void 0) {
|
|
1218
|
-
out[k] = [].concat(out[k], toValue(tmp.shift()));
|
|
1219
|
-
} else {
|
|
1220
|
-
out[k] = toValue(tmp.shift());
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
return out;
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
function _extends() {
|
|
1228
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
1229
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
1230
|
-
var source = arguments[i];
|
|
1231
|
-
|
|
1232
|
-
for (var key in source) {
|
|
1233
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1234
|
-
target[key] = source[key];
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
|
-
return target;
|
|
1240
|
-
};
|
|
1241
|
-
return _extends.apply(this, arguments);
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
function createRoute(routeConfig, options, parent, router) {
|
|
1245
|
-
const {
|
|
1246
|
-
id,
|
|
1247
|
-
routeId,
|
|
1248
|
-
path: routePath,
|
|
1249
|
-
fullPath
|
|
1250
|
-
} = routeConfig;
|
|
1251
|
-
|
|
1252
|
-
const action = router.state.actions[id] || (() => {
|
|
1253
|
-
router.state.actions[id] = {
|
|
1254
|
-
pending: [],
|
|
1255
|
-
submit: async (submission, actionOpts) => {
|
|
1256
|
-
var _actionOpts$invalidat;
|
|
1257
|
-
|
|
1258
|
-
if (!route) {
|
|
1259
|
-
return;
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
|
|
1263
|
-
const actionState = {
|
|
1264
|
-
submittedAt: Date.now(),
|
|
1265
|
-
status: 'pending',
|
|
1266
|
-
submission
|
|
1267
|
-
};
|
|
1268
|
-
action.current = actionState;
|
|
1269
|
-
action.latest = actionState;
|
|
1270
|
-
action.pending.push(actionState);
|
|
1271
|
-
router.state = _extends({}, router.state, {
|
|
1272
|
-
currentAction: actionState,
|
|
1273
|
-
latestAction: actionState
|
|
1274
|
-
});
|
|
1275
|
-
router.notify();
|
|
1276
|
-
|
|
1277
|
-
try {
|
|
1278
|
-
const res = await (route.options.action == null ? void 0 : route.options.action(submission));
|
|
1279
|
-
actionState.data = res;
|
|
1280
|
-
|
|
1281
|
-
if (invalidate) {
|
|
1282
|
-
router.invalidateRoute({
|
|
1283
|
-
to: '.',
|
|
1284
|
-
fromCurrent: true
|
|
1285
|
-
});
|
|
1286
|
-
await router.reload();
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
actionState.status = 'success';
|
|
1290
|
-
return res;
|
|
1291
|
-
} catch (err) {
|
|
1292
|
-
console.error(err);
|
|
1293
|
-
actionState.error = err;
|
|
1294
|
-
actionState.status = 'error';
|
|
1295
|
-
} finally {
|
|
1296
|
-
action.pending = action.pending.filter(d => d !== actionState);
|
|
1297
|
-
router.removeActionQueue.push({
|
|
1298
|
-
action,
|
|
1299
|
-
actionState
|
|
1300
|
-
});
|
|
1301
|
-
router.notify();
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
};
|
|
1305
|
-
return router.state.actions[id];
|
|
1306
|
-
})();
|
|
1307
|
-
|
|
1308
|
-
const loader = router.state.loaders[id] || (() => {
|
|
1309
|
-
router.state.loaders[id] = {
|
|
1310
|
-
pending: [],
|
|
1311
|
-
fetch: async loaderContext => {
|
|
1312
|
-
if (!route) {
|
|
1313
|
-
return;
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
const loaderState = {
|
|
1317
|
-
loadedAt: Date.now(),
|
|
1318
|
-
loaderContext
|
|
1319
|
-
};
|
|
1320
|
-
loader.current = loaderState;
|
|
1321
|
-
loader.latest = loaderState;
|
|
1322
|
-
loader.pending.push(loaderState); // router.state = {
|
|
1323
|
-
// ...router.state,
|
|
1324
|
-
// currentAction: loaderState,
|
|
1325
|
-
// latestAction: loaderState,
|
|
1326
|
-
// }
|
|
1327
|
-
|
|
1328
|
-
router.notify();
|
|
1329
|
-
|
|
1330
|
-
try {
|
|
1331
|
-
return await (route.options.loader == null ? void 0 : route.options.loader(loaderContext));
|
|
1332
|
-
} finally {
|
|
1333
|
-
loader.pending = loader.pending.filter(d => d !== loaderState); // router.removeActionQueue.push({ loader, loaderState })
|
|
1334
|
-
|
|
1335
|
-
router.notify();
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
};
|
|
1339
|
-
return router.state.loaders[id];
|
|
1340
|
-
})();
|
|
1341
|
-
|
|
1342
|
-
let route = {
|
|
1343
|
-
routeId: id,
|
|
1344
|
-
routeRouteId: routeId,
|
|
1345
|
-
routePath,
|
|
1346
|
-
fullPath,
|
|
1347
|
-
options,
|
|
1348
|
-
router,
|
|
1349
|
-
childRoutes: undefined,
|
|
1350
|
-
parentRoute: parent,
|
|
1351
|
-
action,
|
|
1352
|
-
loader: loader,
|
|
1353
|
-
buildLink: options => {
|
|
1354
|
-
return router.buildLink(_extends({}, options, {
|
|
1355
|
-
from: fullPath
|
|
1356
|
-
}));
|
|
1357
|
-
},
|
|
1358
|
-
navigate: options => {
|
|
1359
|
-
return router.navigate(_extends({}, options, {
|
|
1360
|
-
from: fullPath
|
|
1361
|
-
}));
|
|
1362
|
-
},
|
|
1363
|
-
matchRoute: (matchLocation, opts) => {
|
|
1364
|
-
return router.matchRoute(_extends({}, matchLocation, {
|
|
1365
|
-
from: fullPath
|
|
1366
|
-
}), opts);
|
|
1367
|
-
}
|
|
1368
|
-
};
|
|
1369
|
-
router.options.createRoute == null ? void 0 : router.options.createRoute({
|
|
1370
|
-
router,
|
|
1371
|
-
route
|
|
1372
|
-
});
|
|
1373
|
-
return route;
|
|
1374
|
-
}
|
|
1375
|
-
function cascadeLoaderData(matches) {
|
|
1376
|
-
matches.forEach((match, index) => {
|
|
1377
|
-
const parent = matches[index - 1];
|
|
1378
|
-
|
|
1379
|
-
if (parent) {
|
|
1380
|
-
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
1381
|
-
}
|
|
1382
|
-
});
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
|
-
const rootRouteId = '__root__';
|
|
1386
|
-
const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
|
|
1387
|
-
if (options === void 0) {
|
|
1388
|
-
options = {};
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
if (isRoot === void 0) {
|
|
1392
|
-
isRoot = true;
|
|
1393
|
-
}
|
|
1394
|
-
|
|
1395
|
-
if (isRoot) {
|
|
1396
|
-
options.path = rootRouteId;
|
|
1397
|
-
} // Strip the root from parentIds
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
if (parentId === rootRouteId) {
|
|
1401
|
-
parentId = '';
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
let path = isRoot ? rootRouteId : options.path; // If the path is anything other than an index path, trim it up
|
|
1405
|
-
|
|
1406
|
-
if (path && path !== '/') {
|
|
1407
|
-
path = trimPath(path);
|
|
1408
|
-
}
|
|
1409
|
-
|
|
1410
|
-
const routeId = path || options.id;
|
|
1411
|
-
let id = joinPaths([parentId, routeId]);
|
|
1412
|
-
|
|
1413
|
-
if (path === rootRouteId) {
|
|
1414
|
-
path = '/';
|
|
1415
|
-
}
|
|
1416
|
-
|
|
1417
|
-
if (id !== rootRouteId) {
|
|
1418
|
-
id = joinPaths(['/', id]);
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]));
|
|
1422
|
-
return {
|
|
1423
|
-
id: id,
|
|
1424
|
-
routeId: routeId,
|
|
1425
|
-
path: path,
|
|
1426
|
-
fullPath: fullPath,
|
|
1427
|
-
options: options,
|
|
1428
|
-
children,
|
|
1429
|
-
createChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)), false, parentId, parentPath),
|
|
1430
|
-
addChildren: children => createRouteConfig(options, children, false, parentId, parentPath),
|
|
1431
|
-
createRoute: childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)
|
|
1432
|
-
};
|
|
1433
|
-
};
|
|
1434
|
-
|
|
1435
|
-
const elementTypes = ['element', 'errorElement', 'catchElement', 'pendingElement'];
|
|
1436
|
-
function createRouteMatch(router, route, opts) {
|
|
1437
|
-
const routeMatch = _extends({}, route, opts, {
|
|
1438
|
-
router,
|
|
1439
|
-
routeSearch: {},
|
|
1440
|
-
search: {},
|
|
1441
|
-
childMatches: [],
|
|
1442
|
-
status: 'idle',
|
|
1443
|
-
routeLoaderData: {},
|
|
1444
|
-
loaderData: {},
|
|
1445
|
-
isPending: false,
|
|
1446
|
-
isFetching: false,
|
|
1447
|
-
isInvalid: false,
|
|
1448
|
-
invalidAt: Infinity,
|
|
1449
|
-
getIsInvalid: () => {
|
|
1450
|
-
const now = Date.now();
|
|
1451
|
-
return routeMatch.isInvalid || routeMatch.invalidAt < now;
|
|
1452
|
-
},
|
|
1453
|
-
__: {
|
|
1454
|
-
abortController: new AbortController(),
|
|
1455
|
-
latestId: '',
|
|
1456
|
-
resolve: () => {},
|
|
1457
|
-
notify: () => {
|
|
1458
|
-
routeMatch.__.resolve();
|
|
1459
|
-
|
|
1460
|
-
routeMatch.router.notify();
|
|
1461
|
-
},
|
|
1462
|
-
startPending: () => {
|
|
1463
|
-
var _routeMatch$options$p, _routeMatch$options$p2;
|
|
1464
|
-
|
|
1465
|
-
const pendingMs = (_routeMatch$options$p = routeMatch.options.pendingMs) != null ? _routeMatch$options$p : router.options.defaultPendingMs;
|
|
1466
|
-
const pendingMinMs = (_routeMatch$options$p2 = routeMatch.options.pendingMinMs) != null ? _routeMatch$options$p2 : router.options.defaultPendingMinMs;
|
|
1467
|
-
|
|
1468
|
-
if (routeMatch.__.pendingTimeout || routeMatch.status !== 'loading' || typeof pendingMs === 'undefined') {
|
|
1469
|
-
return;
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
routeMatch.__.pendingTimeout = setTimeout(() => {
|
|
1473
|
-
routeMatch.isPending = true;
|
|
1474
|
-
|
|
1475
|
-
routeMatch.__.resolve();
|
|
1476
|
-
|
|
1477
|
-
if (typeof pendingMinMs !== 'undefined') {
|
|
1478
|
-
routeMatch.__.pendingMinPromise = new Promise(r => routeMatch.__.pendingMinTimeout = setTimeout(r, pendingMinMs));
|
|
1479
|
-
}
|
|
1480
|
-
}, pendingMs);
|
|
1481
|
-
},
|
|
1482
|
-
cancelPending: () => {
|
|
1483
|
-
routeMatch.isPending = false;
|
|
1484
|
-
clearTimeout(routeMatch.__.pendingTimeout);
|
|
1485
|
-
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
1486
|
-
delete routeMatch.__.pendingMinPromise;
|
|
1487
|
-
},
|
|
1488
|
-
// setParentMatch: (parentMatch?: RouteMatch) => {
|
|
1489
|
-
// routeMatch.parentMatch = parentMatch
|
|
1490
|
-
// },
|
|
1491
|
-
// addChildMatch: (childMatch: RouteMatch) => {
|
|
1492
|
-
// if (
|
|
1493
|
-
// routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
|
|
1494
|
-
// ) {
|
|
1495
|
-
// return
|
|
1496
|
-
// }
|
|
1497
|
-
// routeMatch.childMatches.push(childMatch)
|
|
1498
|
-
// },
|
|
1499
|
-
validate: () => {
|
|
1500
|
-
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1501
|
-
|
|
1502
|
-
// Validate the search params and stabilize them
|
|
1503
|
-
const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
|
|
1504
|
-
|
|
1505
|
-
try {
|
|
1506
|
-
const prevSearch = routeMatch.routeSearch;
|
|
1507
|
-
const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
|
|
1508
|
-
let nextSearch = replaceEqualDeep(prevSearch, validator == null ? void 0 : validator(parentSearch)); // Invalidate route matches when search param stability changes
|
|
1509
|
-
|
|
1510
|
-
if (prevSearch !== nextSearch) {
|
|
1511
|
-
routeMatch.isInvalid = true;
|
|
1512
|
-
}
|
|
1513
|
-
|
|
1514
|
-
routeMatch.routeSearch = nextSearch;
|
|
1515
|
-
routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
|
|
1516
|
-
} catch (err) {
|
|
1517
|
-
console.error(err);
|
|
1518
|
-
const error = new Error('Invalid search params found', {
|
|
1519
|
-
cause: err
|
|
1520
|
-
});
|
|
1521
|
-
error.code = 'INVALID_SEARCH_PARAMS';
|
|
1522
|
-
routeMatch.status = 'error';
|
|
1523
|
-
routeMatch.error = error; // Do not proceed with loading the route
|
|
1524
|
-
|
|
1525
|
-
return;
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
},
|
|
1529
|
-
cancel: () => {
|
|
1530
|
-
var _routeMatch$__$abortC;
|
|
1531
|
-
|
|
1532
|
-
(_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
|
|
1533
|
-
|
|
1534
|
-
routeMatch.__.cancelPending();
|
|
1535
|
-
},
|
|
1536
|
-
invalidate: () => {
|
|
1537
|
-
routeMatch.isInvalid = true;
|
|
1538
|
-
},
|
|
1539
|
-
hasLoaders: () => {
|
|
1540
|
-
return !!(route.options.loader || elementTypes.some(d => typeof route.options[d] === 'function'));
|
|
1541
|
-
},
|
|
1542
|
-
load: async loaderOpts => {
|
|
1543
|
-
const now = Date.now();
|
|
1544
|
-
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
|
|
1545
|
-
|
|
1546
|
-
if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
|
|
1547
|
-
// If the match is currently active, don't preload it
|
|
1548
|
-
if (router.state.matches.find(d => d.matchId === routeMatch.matchId)) {
|
|
1549
|
-
return;
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
|
-
router.matchCache[routeMatch.matchId] = {
|
|
1553
|
-
gc: now + loaderOpts.gcMaxAge,
|
|
1554
|
-
match: routeMatch
|
|
1555
|
-
};
|
|
1556
|
-
} // If the match is invalid, errored or idle, trigger it to load
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
|
|
1560
|
-
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
1561
|
-
routeMatch.fetch({
|
|
1562
|
-
maxAge
|
|
1563
|
-
});
|
|
1564
|
-
}
|
|
1565
|
-
},
|
|
1566
|
-
fetch: async opts => {
|
|
1567
|
-
const id = '' + Date.now() + Math.random();
|
|
1568
|
-
routeMatch.__.latestId = id; // If the match was in an error state, set it
|
|
1569
|
-
// to a loading state again. Otherwise, keep it
|
|
1570
|
-
// as loading or resolved
|
|
1571
|
-
|
|
1572
|
-
if (routeMatch.status === 'idle') {
|
|
1573
|
-
routeMatch.status = 'loading';
|
|
1574
|
-
} // We started loading the route, so it's no longer invalid
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
routeMatch.isInvalid = false;
|
|
1578
|
-
routeMatch.__.loadPromise = new Promise(async resolve => {
|
|
1579
|
-
// We are now fetching, even if it's in the background of a
|
|
1580
|
-
// resolved state
|
|
1581
|
-
routeMatch.isFetching = true;
|
|
1582
|
-
routeMatch.__.resolve = resolve;
|
|
1583
|
-
|
|
1584
|
-
const loaderPromise = (async () => {
|
|
1585
|
-
// Load the elements and data in parallel
|
|
1586
|
-
routeMatch.__.elementsPromise = (async () => {
|
|
1587
|
-
// then run all element and data loaders in parallel
|
|
1588
|
-
// For each element type, potentially load it asynchronously
|
|
1589
|
-
await Promise.all(elementTypes.map(async type => {
|
|
1590
|
-
const routeElement = routeMatch.options[type];
|
|
1591
|
-
|
|
1592
|
-
if (routeMatch.__[type]) {
|
|
1593
|
-
return;
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
routeMatch.__[type] = await router.options.createElement(routeElement);
|
|
1597
|
-
}));
|
|
1598
|
-
})();
|
|
1599
|
-
|
|
1600
|
-
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1601
|
-
try {
|
|
1602
|
-
var _ref, _ref2, _opts$maxAge;
|
|
1603
|
-
|
|
1604
|
-
if (routeMatch.options.loader) {
|
|
1605
|
-
const data = await routeMatch.options.loader({
|
|
1606
|
-
params: routeMatch.params,
|
|
1607
|
-
search: routeMatch.routeSearch,
|
|
1608
|
-
signal: routeMatch.__.abortController.signal
|
|
1609
|
-
});
|
|
1610
|
-
|
|
1611
|
-
if (id !== routeMatch.__.latestId) {
|
|
1612
|
-
return routeMatch.__.loaderPromise;
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1616
|
-
}
|
|
1617
|
-
|
|
1618
|
-
routeMatch.error = undefined;
|
|
1619
|
-
routeMatch.status = 'success';
|
|
1620
|
-
routeMatch.updatedAt = Date.now();
|
|
1621
|
-
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);
|
|
1622
|
-
} catch (err) {
|
|
1623
|
-
if (id !== routeMatch.__.latestId) {
|
|
1624
|
-
return routeMatch.__.loaderPromise;
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1628
|
-
console.error(err);
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
routeMatch.error = err;
|
|
1632
|
-
routeMatch.status = 'error';
|
|
1633
|
-
routeMatch.updatedAt = Date.now();
|
|
1634
|
-
}
|
|
1635
|
-
});
|
|
1636
|
-
|
|
1637
|
-
try {
|
|
1638
|
-
await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
|
|
1639
|
-
|
|
1640
|
-
if (id !== routeMatch.__.latestId) {
|
|
1641
|
-
return routeMatch.__.loaderPromise;
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
if (routeMatch.__.pendingMinPromise) {
|
|
1645
|
-
await routeMatch.__.pendingMinPromise;
|
|
1646
|
-
delete routeMatch.__.pendingMinPromise;
|
|
1647
|
-
}
|
|
1648
|
-
} finally {
|
|
1649
|
-
if (id !== routeMatch.__.latestId) {
|
|
1650
|
-
return routeMatch.__.loaderPromise;
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
routeMatch.__.cancelPending();
|
|
1654
|
-
|
|
1655
|
-
routeMatch.isPending = false;
|
|
1656
|
-
routeMatch.isFetching = false;
|
|
1657
|
-
|
|
1658
|
-
routeMatch.__.notify();
|
|
1659
|
-
}
|
|
1660
|
-
})();
|
|
1661
|
-
|
|
1662
|
-
routeMatch.__.loaderPromise = loaderPromise;
|
|
1663
|
-
await loaderPromise;
|
|
1664
|
-
|
|
1665
|
-
if (id !== routeMatch.__.latestId) {
|
|
1666
|
-
return routeMatch.__.loaderPromise;
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
delete routeMatch.__.loaderPromise;
|
|
1670
|
-
});
|
|
1671
|
-
return await routeMatch.__.loadPromise;
|
|
1672
|
-
}
|
|
1673
|
-
});
|
|
1674
|
-
|
|
1675
|
-
if (!routeMatch.hasLoaders()) {
|
|
1676
|
-
routeMatch.status = 'success';
|
|
1677
|
-
}
|
|
1678
|
-
|
|
1679
|
-
return routeMatch;
|
|
1680
|
-
}
|
|
1681
|
-
|
|
1682
|
-
const defaultParseSearch = parseSearchWith(JSON.parse);
|
|
1683
|
-
const defaultStringifySearch = stringifySearchWith(JSON.stringify);
|
|
1684
|
-
function parseSearchWith(parser) {
|
|
1685
|
-
return searchStr => {
|
|
1686
|
-
if (searchStr.substring(0, 1) === '?') {
|
|
1687
|
-
searchStr = searchStr.substring(1);
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
|
-
let query = decode(searchStr); // Try to parse any query params that might be json
|
|
1691
|
-
|
|
1692
|
-
for (let key in query) {
|
|
1693
|
-
const value = query[key];
|
|
1694
|
-
|
|
1695
|
-
if (typeof value === 'string') {
|
|
1696
|
-
try {
|
|
1697
|
-
query[key] = parser(value);
|
|
1698
|
-
} catch (err) {//
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1703
|
-
return query;
|
|
1704
|
-
};
|
|
1705
|
-
}
|
|
1706
|
-
function stringifySearchWith(stringify) {
|
|
1707
|
-
return search => {
|
|
1708
|
-
search = _extends({}, search);
|
|
1709
|
-
|
|
1710
|
-
if (search) {
|
|
1711
|
-
Object.keys(search).forEach(key => {
|
|
1712
|
-
const val = search[key];
|
|
1713
|
-
|
|
1714
|
-
if (typeof val === 'undefined' || val === undefined) {
|
|
1715
|
-
delete search[key];
|
|
1716
|
-
} else if (val && typeof val === 'object' && val !== null) {
|
|
1717
|
-
try {
|
|
1718
|
-
search[key] = stringify(val);
|
|
1719
|
-
} catch (err) {// silent
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
});
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
const searchStr = encode(search).toString();
|
|
1726
|
-
return searchStr ? "?" + searchStr : '';
|
|
1727
|
-
};
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1730
|
-
var _window$document;
|
|
1731
|
-
// Detect if we're in the DOM
|
|
1732
|
-
const isServer = Boolean(typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement)); // This is the default history object if none is defined
|
|
1733
|
-
|
|
1734
|
-
const createDefaultHistory = () => !isServer ? createBrowserHistory() : createMemoryHistory();
|
|
1735
|
-
|
|
1736
|
-
function createRouter(userOptions) {
|
|
1737
|
-
var _userOptions$stringif, _userOptions$parseSea;
|
|
1738
|
-
|
|
1739
|
-
const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
|
|
1740
|
-
|
|
1741
|
-
const originalOptions = _extends({
|
|
1742
|
-
defaultLoaderGcMaxAge: 5 * 60 * 1000,
|
|
1743
|
-
defaultLoaderMaxAge: 0,
|
|
1744
|
-
defaultPreloadMaxAge: 2000,
|
|
1745
|
-
defaultPreloadDelay: 50
|
|
1746
|
-
}, userOptions, {
|
|
1747
|
-
stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
|
|
1748
|
-
parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
|
|
1749
|
-
});
|
|
1750
|
-
|
|
1751
|
-
let router = {
|
|
1752
|
-
history,
|
|
1753
|
-
options: originalOptions,
|
|
1754
|
-
listeners: [],
|
|
1755
|
-
removeActionQueue: [],
|
|
1756
|
-
// Resolved after construction
|
|
1757
|
-
basepath: '',
|
|
1758
|
-
routeTree: undefined,
|
|
1759
|
-
routesById: {},
|
|
1760
|
-
location: undefined,
|
|
1761
|
-
allRouteInfo: undefined,
|
|
1762
|
-
//
|
|
1763
|
-
navigationPromise: Promise.resolve(),
|
|
1764
|
-
resolveNavigation: () => {},
|
|
1765
|
-
matchCache: {},
|
|
1766
|
-
state: {
|
|
1767
|
-
status: 'idle',
|
|
1768
|
-
location: null,
|
|
1769
|
-
matches: [],
|
|
1770
|
-
actions: {},
|
|
1771
|
-
loaders: {},
|
|
1772
|
-
loaderData: {},
|
|
1773
|
-
lastUpdated: Date.now(),
|
|
1774
|
-
isFetching: false,
|
|
1775
|
-
isPreloading: false
|
|
1776
|
-
},
|
|
1777
|
-
startedLoadingAt: Date.now(),
|
|
1778
|
-
subscribe: listener => {
|
|
1779
|
-
router.listeners.push(listener);
|
|
1780
|
-
return () => {
|
|
1781
|
-
router.listeners = router.listeners.filter(x => x !== listener);
|
|
1782
|
-
};
|
|
1783
|
-
},
|
|
1784
|
-
getRoute: id => {
|
|
1785
|
-
return router.routesById[id];
|
|
1786
|
-
},
|
|
1787
|
-
notify: () => {
|
|
1788
|
-
router.state = _extends({}, router.state, {
|
|
1789
|
-
isFetching: router.state.status === 'loading' || router.state.matches.some(d => d.isFetching),
|
|
1790
|
-
isPreloading: Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId))
|
|
1791
|
-
});
|
|
1792
|
-
cascadeLoaderData(router.state.matches);
|
|
1793
|
-
router.listeners.forEach(listener => listener(router));
|
|
1794
|
-
},
|
|
1795
|
-
mount: () => {
|
|
1796
|
-
const next = router.__.buildLocation({
|
|
1797
|
-
to: '.',
|
|
1798
|
-
search: true,
|
|
1799
|
-
hash: true
|
|
1800
|
-
}); // If the current location isn't updated, trigger a navigation
|
|
1801
|
-
// to the current location. Otherwise, load the current location.
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
if (next.href !== router.location.href) {
|
|
1805
|
-
router.__.commitLocation(next, true);
|
|
1806
|
-
} else {
|
|
1807
|
-
router.loadLocation();
|
|
1808
|
-
}
|
|
1809
|
-
|
|
1810
|
-
const unsub = history.listen(event => {
|
|
1811
|
-
router.loadLocation(router.__.parseLocation(event.location, router.location));
|
|
1812
|
-
}); // addEventListener does not exist in React Native, but window does
|
|
1813
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1814
|
-
|
|
1815
|
-
if (!isServer && window.addEventListener) {
|
|
1816
|
-
// Listen to visibillitychange and focus
|
|
1817
|
-
window.addEventListener('visibilitychange', router.onFocus, false);
|
|
1818
|
-
window.addEventListener('focus', router.onFocus, false);
|
|
1819
|
-
}
|
|
1820
|
-
|
|
1821
|
-
return () => {
|
|
1822
|
-
unsub(); // Be sure to unsubscribe if a new handler is set
|
|
1823
|
-
|
|
1824
|
-
window.removeEventListener('visibilitychange', router.onFocus);
|
|
1825
|
-
window.removeEventListener('focus', router.onFocus);
|
|
1826
|
-
};
|
|
1827
|
-
},
|
|
1828
|
-
onFocus: () => {
|
|
1829
|
-
router.loadLocation();
|
|
1830
|
-
},
|
|
1831
|
-
update: opts => {
|
|
1832
|
-
Object.assign(router.options, opts);
|
|
1833
|
-
const {
|
|
1834
|
-
basepath,
|
|
1835
|
-
routeConfig
|
|
1836
|
-
} = router.options;
|
|
1837
|
-
router.basepath = cleanPath("/" + (basepath != null ? basepath : ''));
|
|
1838
|
-
|
|
1839
|
-
if (routeConfig) {
|
|
1840
|
-
router.routesById = {};
|
|
1841
|
-
router.routeTree = router.__.buildRouteTree(routeConfig);
|
|
1842
|
-
}
|
|
1843
|
-
|
|
1844
|
-
return router;
|
|
1845
|
-
},
|
|
1846
|
-
cancelMatches: () => {
|
|
1847
|
-
var _router$state$pending, _router$state$pending2;
|
|
1848
|
-
[...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 => {
|
|
1849
|
-
match.cancel();
|
|
1850
|
-
});
|
|
1851
|
-
},
|
|
1852
|
-
loadLocation: async next => {
|
|
1853
|
-
const id = Math.random();
|
|
1854
|
-
router.startedLoadingAt = id;
|
|
1855
|
-
|
|
1856
|
-
if (next) {
|
|
1857
|
-
// Ingest the new location
|
|
1858
|
-
router.location = next;
|
|
1859
|
-
} // Clear out old actions
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
router.removeActionQueue.forEach(_ref => {
|
|
1863
|
-
let {
|
|
1864
|
-
action,
|
|
1865
|
-
actionState
|
|
1866
|
-
} = _ref;
|
|
1867
|
-
|
|
1868
|
-
if (router.state.currentAction === actionState) {
|
|
1869
|
-
router.state.currentAction = undefined;
|
|
1870
|
-
}
|
|
1871
|
-
|
|
1872
|
-
if (action.current === actionState) {
|
|
1873
|
-
action.current = undefined;
|
|
1874
|
-
}
|
|
1875
|
-
});
|
|
1876
|
-
router.removeActionQueue = []; // Cancel any pending matches
|
|
1877
|
-
|
|
1878
|
-
router.cancelMatches(); // Match the routes
|
|
1879
|
-
|
|
1880
|
-
const matches = router.matchRoutes(location.pathname, {
|
|
1881
|
-
strictParseParams: true
|
|
1882
|
-
});
|
|
1883
|
-
router.state = _extends({}, router.state, {
|
|
1884
|
-
pending: {
|
|
1885
|
-
matches: matches,
|
|
1886
|
-
location: router.location
|
|
1887
|
-
},
|
|
1888
|
-
status: 'loading'
|
|
1889
|
-
});
|
|
1890
|
-
router.notify(); // Load the matches
|
|
1891
|
-
|
|
1892
|
-
await router.loadMatches(matches, {
|
|
1893
|
-
withPending: true
|
|
1894
|
-
});
|
|
1895
|
-
|
|
1896
|
-
if (router.startedLoadingAt !== id) {
|
|
1897
|
-
// Ignore side-effects of match loading
|
|
1898
|
-
return router.navigationPromise;
|
|
1899
|
-
}
|
|
1900
|
-
|
|
1901
|
-
const previousMatches = router.state.matches;
|
|
1902
|
-
const exiting = [],
|
|
1903
|
-
staying = [];
|
|
1904
|
-
previousMatches.forEach(d => {
|
|
1905
|
-
if (matches.find(dd => dd.matchId === d.matchId)) {
|
|
1906
|
-
staying.push(d);
|
|
1907
|
-
} else {
|
|
1908
|
-
exiting.push(d);
|
|
1909
|
-
}
|
|
1910
|
-
});
|
|
1911
|
-
const now = Date.now();
|
|
1912
|
-
exiting.forEach(d => {
|
|
1913
|
-
var _ref2, _d$options$loaderGcMa, _ref3, _d$options$loaderMaxA;
|
|
1914
|
-
|
|
1915
|
-
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
1916
|
-
params: d.params,
|
|
1917
|
-
search: d.routeSearch
|
|
1918
|
-
}); // Clear idle error states when match leaves
|
|
1919
|
-
|
|
1920
|
-
if (d.status === 'error' && !d.isFetching) {
|
|
1921
|
-
d.status = 'idle';
|
|
1922
|
-
d.error = undefined;
|
|
1923
|
-
}
|
|
1924
|
-
|
|
1925
|
-
const gc = Math.max((_ref2 = (_d$options$loaderGcMa = d.options.loaderGcMaxAge) != null ? _d$options$loaderGcMa : router.options.defaultLoaderGcMaxAge) != null ? _ref2 : 0, (_ref3 = (_d$options$loaderMaxA = d.options.loaderMaxAge) != null ? _d$options$loaderMaxA : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0);
|
|
1926
|
-
|
|
1927
|
-
if (gc > 0) {
|
|
1928
|
-
router.matchCache[d.matchId] = {
|
|
1929
|
-
gc: gc == Infinity ? Number.MAX_SAFE_INTEGER : now + gc,
|
|
1930
|
-
match: d
|
|
1931
|
-
};
|
|
1932
|
-
}
|
|
1933
|
-
});
|
|
1934
|
-
staying.forEach(d => {
|
|
1935
|
-
d.options.onTransition == null ? void 0 : d.options.onTransition({
|
|
1936
|
-
params: d.params,
|
|
1937
|
-
search: d.routeSearch
|
|
1938
|
-
});
|
|
1939
|
-
});
|
|
1940
|
-
const entering = matches.filter(d => {
|
|
1941
|
-
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
1942
|
-
});
|
|
1943
|
-
entering.forEach(d => {
|
|
1944
|
-
d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
|
|
1945
|
-
params: d.params,
|
|
1946
|
-
search: d.search
|
|
1947
|
-
});
|
|
1948
|
-
delete router.matchCache[d.matchId];
|
|
1949
|
-
});
|
|
1950
|
-
|
|
1951
|
-
if (matches.some(d => d.status === 'loading')) {
|
|
1952
|
-
router.notify();
|
|
1953
|
-
await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
|
-
if (router.startedLoadingAt !== id) {
|
|
1957
|
-
// Ignore side-effects of match loading
|
|
1958
|
-
return;
|
|
1959
|
-
}
|
|
1960
|
-
|
|
1961
|
-
router.state = _extends({}, router.state, {
|
|
1962
|
-
location: router.location,
|
|
1963
|
-
matches,
|
|
1964
|
-
pending: undefined,
|
|
1965
|
-
status: 'idle'
|
|
1966
|
-
});
|
|
1967
|
-
router.notify();
|
|
1968
|
-
router.resolveNavigation();
|
|
1969
|
-
},
|
|
1970
|
-
cleanMatchCache: () => {
|
|
1971
|
-
const now = Date.now();
|
|
1972
|
-
Object.keys(router.matchCache).forEach(matchId => {
|
|
1973
|
-
const entry = router.matchCache[matchId]; // Don't remove loading matches
|
|
1974
|
-
|
|
1975
|
-
if (entry.match.status === 'loading') {
|
|
1976
|
-
return;
|
|
1977
|
-
} // Do not remove successful matches that are still valid
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
if (entry.gc > 0 && entry.gc > now) {
|
|
1981
|
-
return;
|
|
1982
|
-
} // Everything else gets removed
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
delete router.matchCache[matchId];
|
|
1986
|
-
});
|
|
1987
|
-
},
|
|
1988
|
-
loadRoute: async function loadRoute(navigateOpts) {
|
|
1989
|
-
if (navigateOpts === void 0) {
|
|
1990
|
-
navigateOpts = router.location;
|
|
1991
|
-
}
|
|
1992
|
-
|
|
1993
|
-
const next = router.buildNext(navigateOpts);
|
|
1994
|
-
const matches = router.matchRoutes(next.pathname, {
|
|
1995
|
-
strictParseParams: true
|
|
1996
|
-
});
|
|
1997
|
-
await router.loadMatches(matches);
|
|
1998
|
-
return matches;
|
|
1999
|
-
},
|
|
2000
|
-
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
2001
|
-
var _ref4, _ref5, _loaderOpts$maxAge, _ref6, _ref7, _loaderOpts$gcMaxAge;
|
|
2002
|
-
|
|
2003
|
-
if (navigateOpts === void 0) {
|
|
2004
|
-
navigateOpts = router.location;
|
|
2005
|
-
}
|
|
2006
|
-
|
|
2007
|
-
const next = router.buildNext(navigateOpts);
|
|
2008
|
-
const matches = router.matchRoutes(next.pathname, {
|
|
2009
|
-
strictParseParams: true
|
|
2010
|
-
});
|
|
2011
|
-
await router.loadMatches(matches, {
|
|
2012
|
-
preload: true,
|
|
2013
|
-
maxAge: (_ref4 = (_ref5 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref5 : router.options.defaultLoaderMaxAge) != null ? _ref4 : 0,
|
|
2014
|
-
gcMaxAge: (_ref6 = (_ref7 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref7 : router.options.defaultLoaderGcMaxAge) != null ? _ref6 : 0
|
|
2015
|
-
});
|
|
2016
|
-
return matches;
|
|
2017
|
-
},
|
|
2018
|
-
matchRoutes: (pathname, opts) => {
|
|
2019
|
-
var _router$state$pending3, _router$state$pending4;
|
|
2020
|
-
|
|
2021
|
-
router.cleanMatchCache();
|
|
2022
|
-
const matches = [];
|
|
2023
|
-
|
|
2024
|
-
if (!router.routeTree) {
|
|
2025
|
-
return matches;
|
|
2026
|
-
}
|
|
2027
|
-
|
|
2028
|
-
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 : [])];
|
|
2029
|
-
|
|
2030
|
-
const recurse = async routes => {
|
|
2031
|
-
var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
|
|
2032
|
-
|
|
2033
|
-
const parentMatch = last(matches);
|
|
2034
|
-
let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
|
|
2035
|
-
const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
|
|
2036
|
-
let foundRoutes = [];
|
|
2037
|
-
|
|
2038
|
-
const findMatchInRoutes = (parentRoutes, routes) => {
|
|
2039
|
-
routes.some(route => {
|
|
2040
|
-
var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
|
|
2041
|
-
|
|
2042
|
-
if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
|
|
2043
|
-
return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
|
|
2044
|
-
}
|
|
2045
|
-
|
|
2046
|
-
const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
|
|
2047
|
-
const matchParams = matchPathname(pathname, {
|
|
2048
|
-
to: route.fullPath,
|
|
2049
|
-
fuzzy,
|
|
2050
|
-
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
2051
|
-
});
|
|
2052
|
-
|
|
2053
|
-
if (matchParams) {
|
|
2054
|
-
let parsedParams;
|
|
2055
|
-
|
|
2056
|
-
try {
|
|
2057
|
-
var _route$options$parseP;
|
|
2058
|
-
|
|
2059
|
-
parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
|
|
2060
|
-
} catch (err) {
|
|
2061
|
-
if (opts != null && opts.strictParseParams) {
|
|
2062
|
-
throw err;
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
|
|
2066
|
-
params = _extends({}, params, parsedParams);
|
|
2067
|
-
}
|
|
2068
|
-
|
|
2069
|
-
if (!!matchParams) {
|
|
2070
|
-
foundRoutes = [...parentRoutes, route];
|
|
2071
|
-
}
|
|
2072
|
-
|
|
2073
|
-
return !!foundRoutes.length;
|
|
2074
|
-
});
|
|
2075
|
-
return !!foundRoutes.length;
|
|
2076
|
-
};
|
|
2077
|
-
|
|
2078
|
-
findMatchInRoutes([], filteredRoutes);
|
|
2079
|
-
|
|
2080
|
-
if (!foundRoutes.length) {
|
|
2081
|
-
return;
|
|
2082
|
-
}
|
|
2083
|
-
|
|
2084
|
-
foundRoutes.forEach(foundRoute => {
|
|
2085
|
-
var _router$matchCache$ma;
|
|
2086
|
-
|
|
2087
|
-
const interpolatedPath = interpolatePath(foundRoute.routePath, params);
|
|
2088
|
-
const matchId = interpolatePath(foundRoute.routeId, params, true);
|
|
2089
|
-
const match = existingMatches.find(d => d.matchId === matchId) || ((_router$matchCache$ma = router.matchCache[matchId]) == null ? void 0 : _router$matchCache$ma.match) || createRouteMatch(router, foundRoute, {
|
|
2090
|
-
matchId,
|
|
2091
|
-
params,
|
|
2092
|
-
pathname: joinPaths([pathname, interpolatedPath])
|
|
2093
|
-
});
|
|
2094
|
-
matches.push(match);
|
|
2095
|
-
});
|
|
2096
|
-
const foundRoute = last(foundRoutes);
|
|
2097
|
-
|
|
2098
|
-
if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
|
|
2099
|
-
recurse(foundRoute.childRoutes);
|
|
2100
|
-
}
|
|
2101
|
-
};
|
|
2102
|
-
|
|
2103
|
-
recurse([router.routeTree]);
|
|
2104
|
-
cascadeLoaderData(matches);
|
|
2105
|
-
return matches;
|
|
2106
|
-
},
|
|
2107
|
-
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
2108
|
-
const matchPromises = resolvedMatches.map(async match => {
|
|
2109
|
-
// Validate the match (loads search params etc)
|
|
2110
|
-
match.__.validate();
|
|
2111
|
-
|
|
2112
|
-
match.load(loaderOpts);
|
|
2113
|
-
|
|
2114
|
-
if (match.status === 'loading') {
|
|
2115
|
-
// If requested, start the pending timers
|
|
2116
|
-
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending(); // Wait for the first sign of activity from the match
|
|
2117
|
-
// This might be completion, error, or a pending state
|
|
2118
|
-
|
|
2119
|
-
await match.__.loadPromise;
|
|
2120
|
-
}
|
|
2121
|
-
});
|
|
2122
|
-
router.notify();
|
|
2123
|
-
await Promise.all(matchPromises);
|
|
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
|
-
}));
|
|
34
|
+
const useLayoutEffect$1 = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
35
|
+
Route.__onInit = route => {
|
|
36
|
+
Object.assign(route, {
|
|
37
|
+
useMatch: (opts = {}) => {
|
|
38
|
+
return useMatch({
|
|
39
|
+
...opts,
|
|
40
|
+
from: route.id
|
|
41
|
+
});
|
|
2168
42
|
},
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
search,
|
|
2174
|
-
hash,
|
|
2175
|
-
replace,
|
|
2176
|
-
params
|
|
2177
|
-
} = _ref8;
|
|
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
|
|
43
|
+
useLoader: (opts = {}) => {
|
|
44
|
+
return useLoader({
|
|
45
|
+
...opts,
|
|
46
|
+
from: route.id
|
|
2199
47
|
});
|
|
2200
48
|
},
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
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
|
-
} = _ref9;
|
|
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 = (_ref10 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref10 : 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
|
-
};
|
|
49
|
+
useRouteContext: (opts = {}) => {
|
|
50
|
+
return useMatch({
|
|
51
|
+
...opts,
|
|
52
|
+
from: route.id,
|
|
53
|
+
select: d => opts?.select ? opts.select(d.context) : d.context
|
|
54
|
+
});
|
|
2315
55
|
},
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
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
|
-
}));
|
|
56
|
+
useSearch: (opts = {}) => {
|
|
57
|
+
return useSearch({
|
|
58
|
+
...opts,
|
|
59
|
+
from: route.id
|
|
60
|
+
});
|
|
2337
61
|
},
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
// }
|
|
2347
|
-
|
|
2348
|
-
const existingRoute = router.routesById[route.routeId];
|
|
2349
|
-
|
|
2350
|
-
if (existingRoute) {
|
|
2351
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2352
|
-
console.warn("Duplicate routes found with id: " + String(route.routeId), router.routesById, route);
|
|
2353
|
-
}
|
|
2354
|
-
|
|
2355
|
-
throw new Error();
|
|
2356
|
-
}
|
|
2357
|
-
router.routesById[route.routeId] = route;
|
|
2358
|
-
const children = routeConfig.children;
|
|
2359
|
-
route.childRoutes = children != null && children.length ? recurseRoutes(children, route) : undefined;
|
|
2360
|
-
return route;
|
|
2361
|
-
});
|
|
2362
|
-
};
|
|
2363
|
-
|
|
2364
|
-
const routes = recurseRoutes([rootRouteConfig]);
|
|
2365
|
-
return routes[0];
|
|
2366
|
-
},
|
|
2367
|
-
parseLocation: (location, previousLocation) => {
|
|
2368
|
-
var _location$hash$split$;
|
|
2369
|
-
|
|
2370
|
-
const parsedSearch = router.options.parseSearch(location.search);
|
|
2371
|
-
return {
|
|
2372
|
-
pathname: location.pathname,
|
|
2373
|
-
searchStr: location.search,
|
|
2374
|
-
search: replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
|
|
2375
|
-
hash: (_location$hash$split$ = location.hash.split('#').reverse()[0]) != null ? _location$hash$split$ : '',
|
|
2376
|
-
href: "" + location.pathname + location.search + location.hash,
|
|
2377
|
-
state: location.state,
|
|
2378
|
-
key: location.key
|
|
2379
|
-
};
|
|
2380
|
-
},
|
|
2381
|
-
navigate: location => {
|
|
2382
|
-
const next = router.buildNext(location);
|
|
2383
|
-
return router.__.commitLocation(next, location.replace);
|
|
2384
|
-
},
|
|
2385
|
-
buildLocation: function buildLocation(dest) {
|
|
2386
|
-
var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
|
|
2387
|
-
|
|
2388
|
-
if (dest === void 0) {
|
|
2389
|
-
dest = {};
|
|
2390
|
-
}
|
|
2391
|
-
|
|
2392
|
-
// const resolvedFrom: Location = {
|
|
2393
|
-
// ...router.location,
|
|
2394
|
-
const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
|
|
2395
|
-
|
|
2396
|
-
let pathname = resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
|
|
2397
|
-
|
|
2398
|
-
const fromMatches = router.matchRoutes(router.location.pathname, {
|
|
2399
|
-
strictParseParams: true
|
|
2400
|
-
});
|
|
2401
|
-
const toMatches = router.matchRoutes(pathname);
|
|
2402
|
-
|
|
2403
|
-
const prevParams = _extends({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
|
|
2404
|
-
|
|
2405
|
-
let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
|
|
2406
|
-
|
|
2407
|
-
if (nextParams) {
|
|
2408
|
-
toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
|
|
2409
|
-
Object.assign({}, nextParams, fn(nextParams));
|
|
2410
|
-
});
|
|
2411
|
-
}
|
|
2412
|
-
|
|
2413
|
-
pathname = interpolatePath(pathname, nextParams != null ? nextParams : {}); // Pre filters first
|
|
2414
|
-
|
|
2415
|
-
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
|
|
2416
|
-
|
|
2417
|
-
const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
|
|
2418
|
-
: dest.search ? (_functionalUpdate = functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
|
|
2419
|
-
: (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
|
|
2420
|
-
: {}; // Then post filters
|
|
2421
|
-
|
|
2422
|
-
const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
|
|
2423
|
-
const search = replaceEqualDeep(router.location.search, postFilteredSearch);
|
|
2424
|
-
const searchStr = router.options.stringifySearch(search);
|
|
2425
|
-
let hash = dest.hash === true ? router.location.hash : functionalUpdate(dest.hash, router.location.hash);
|
|
2426
|
-
hash = hash ? "#" + hash : '';
|
|
2427
|
-
return {
|
|
2428
|
-
pathname,
|
|
2429
|
-
search,
|
|
2430
|
-
searchStr,
|
|
2431
|
-
state: router.location.state,
|
|
2432
|
-
hash,
|
|
2433
|
-
href: "" + pathname + searchStr + hash,
|
|
2434
|
-
key: dest.key
|
|
2435
|
-
};
|
|
2436
|
-
},
|
|
2437
|
-
commitLocation: (next, replace) => {
|
|
2438
|
-
const id = '' + Date.now() + Math.random();
|
|
2439
|
-
if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
|
|
2440
|
-
let nextAction = 'replace';
|
|
2441
|
-
|
|
2442
|
-
if (!replace) {
|
|
2443
|
-
nextAction = 'push';
|
|
2444
|
-
}
|
|
2445
|
-
|
|
2446
|
-
const isSameUrl = router.__.parseLocation(history.location).href === next.href;
|
|
2447
|
-
|
|
2448
|
-
if (isSameUrl && !next.key) {
|
|
2449
|
-
nextAction = 'replace';
|
|
2450
|
-
}
|
|
2451
|
-
|
|
2452
|
-
if (nextAction === 'replace') {
|
|
2453
|
-
history.replace({
|
|
2454
|
-
pathname: next.pathname,
|
|
2455
|
-
hash: next.hash,
|
|
2456
|
-
search: next.searchStr
|
|
2457
|
-
}, {
|
|
2458
|
-
id
|
|
2459
|
-
});
|
|
2460
|
-
} else {
|
|
2461
|
-
history.push({
|
|
2462
|
-
pathname: next.pathname,
|
|
2463
|
-
hash: next.hash,
|
|
2464
|
-
search: next.searchStr
|
|
2465
|
-
}, {
|
|
2466
|
-
id
|
|
2467
|
-
});
|
|
2468
|
-
}
|
|
62
|
+
useParams: (opts = {}) => {
|
|
63
|
+
return useParams({
|
|
64
|
+
...opts,
|
|
65
|
+
from: route.id
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
2469
70
|
|
|
2470
|
-
|
|
2471
|
-
const previousNavigationResolve = router.resolveNavigation;
|
|
71
|
+
//
|
|
2472
72
|
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
return router.navigationPromise;
|
|
2479
|
-
}
|
|
73
|
+
function lazyRouteComponent(importer, exportName) {
|
|
74
|
+
let loadPromise;
|
|
75
|
+
const load = () => {
|
|
76
|
+
if (!loadPromise) {
|
|
77
|
+
loadPromise = importer();
|
|
2480
78
|
}
|
|
79
|
+
return loadPromise;
|
|
2481
80
|
};
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
}
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
81
|
+
const lazyComp = /*#__PURE__*/React.lazy(async () => {
|
|
82
|
+
const moduleExports = await load();
|
|
83
|
+
const comp = moduleExports[exportName ?? 'default'];
|
|
84
|
+
return {
|
|
85
|
+
default: comp
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
lazyComp.preload = load;
|
|
89
|
+
return lazyComp;
|
|
2492
90
|
}
|
|
2493
|
-
|
|
2494
|
-
const _excluded = ["type", "children", "target", "activeProps", "inactiveProps", "activeOptions", "disabled", "hash", "search", "params", "to", "preload", "preloadDelay", "preloadMaxAge", "replace", "style", "className", "onClick", "onFocus", "onMouseEnter", "onMouseLeave", "onTouchStart", "onTouchEnd"],
|
|
2495
|
-
_excluded2 = ["pending", "caseSensitive", "children"],
|
|
2496
|
-
_excluded3 = ["children", "router"];
|
|
2497
91
|
//
|
|
2498
|
-
const matchesContext = /*#__PURE__*/React.createContext(null);
|
|
2499
|
-
const routerContext = /*#__PURE__*/React.createContext(null); // Detect if we're in the DOM
|
|
2500
|
-
|
|
2501
|
-
const isDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
2502
|
-
const useLayoutEffect = isDOM ? React.useLayoutEffect : React.useEffect;
|
|
2503
|
-
function MatchesProvider(props) {
|
|
2504
|
-
return /*#__PURE__*/React.createElement(matchesContext.Provider, props);
|
|
2505
|
-
}
|
|
2506
|
-
|
|
2507
|
-
const useRouterSubscription = router => {
|
|
2508
|
-
useSyncExternalStore(cb => router.subscribe(() => cb()), () => router.state, () => router.state);
|
|
2509
|
-
};
|
|
2510
92
|
|
|
2511
|
-
function
|
|
2512
|
-
const
|
|
93
|
+
function useLinkProps(options) {
|
|
94
|
+
const router = useRouter();
|
|
95
|
+
const {
|
|
96
|
+
// custom props
|
|
97
|
+
type,
|
|
98
|
+
children,
|
|
99
|
+
target,
|
|
100
|
+
activeProps = () => ({
|
|
101
|
+
className: 'active'
|
|
102
|
+
}),
|
|
103
|
+
inactiveProps = () => ({}),
|
|
104
|
+
activeOptions,
|
|
105
|
+
disabled,
|
|
106
|
+
// fromCurrent,
|
|
107
|
+
hash,
|
|
108
|
+
search,
|
|
109
|
+
params,
|
|
110
|
+
to = '.',
|
|
111
|
+
state,
|
|
112
|
+
mask,
|
|
113
|
+
preload,
|
|
114
|
+
preloadDelay,
|
|
115
|
+
replace,
|
|
116
|
+
// element props
|
|
117
|
+
style,
|
|
118
|
+
className,
|
|
119
|
+
onClick,
|
|
120
|
+
onFocus,
|
|
121
|
+
onMouseEnter,
|
|
122
|
+
onMouseLeave,
|
|
123
|
+
onTouchStart,
|
|
124
|
+
...rest
|
|
125
|
+
} = options;
|
|
126
|
+
const linkInfo = router.buildLink(options);
|
|
127
|
+
if (linkInfo.type === 'external') {
|
|
128
|
+
const {
|
|
129
|
+
href
|
|
130
|
+
} = linkInfo;
|
|
2513
131
|
return {
|
|
2514
|
-
|
|
2515
|
-
if (subRouteId === void 0) {
|
|
2516
|
-
subRouteId = '.';
|
|
2517
|
-
}
|
|
2518
|
-
|
|
2519
|
-
const resolvedRouteId = router.resolvePath(route.routeId, subRouteId);
|
|
2520
|
-
const resolvedRoute = router.getRoute(resolvedRouteId);
|
|
2521
|
-
useRouterSubscription(router);
|
|
2522
|
-
invariant(resolvedRoute, "Could not find a route for route \"" + resolvedRouteId + "\"! Did you forget to add it to your route config?");
|
|
2523
|
-
return resolvedRoute;
|
|
2524
|
-
},
|
|
2525
|
-
linkProps: options => {
|
|
2526
|
-
var _functionalUpdate, _functionalUpdate2;
|
|
2527
|
-
|
|
2528
|
-
const {
|
|
2529
|
-
// custom props
|
|
2530
|
-
target,
|
|
2531
|
-
activeProps = () => ({
|
|
2532
|
-
className: 'active'
|
|
2533
|
-
}),
|
|
2534
|
-
inactiveProps = () => ({}),
|
|
2535
|
-
disabled,
|
|
2536
|
-
// element props
|
|
2537
|
-
style,
|
|
2538
|
-
className,
|
|
2539
|
-
onClick,
|
|
2540
|
-
onFocus,
|
|
2541
|
-
onMouseEnter,
|
|
2542
|
-
onMouseLeave
|
|
2543
|
-
} = options,
|
|
2544
|
-
rest = _objectWithoutPropertiesLoose(options, _excluded);
|
|
2545
|
-
|
|
2546
|
-
const linkInfo = route.buildLink(options);
|
|
2547
|
-
|
|
2548
|
-
if (linkInfo.type === 'external') {
|
|
2549
|
-
const {
|
|
2550
|
-
href
|
|
2551
|
-
} = linkInfo;
|
|
2552
|
-
return {
|
|
2553
|
-
href
|
|
2554
|
-
};
|
|
2555
|
-
}
|
|
2556
|
-
|
|
2557
|
-
const {
|
|
2558
|
-
handleClick,
|
|
2559
|
-
handleFocus,
|
|
2560
|
-
handleEnter,
|
|
2561
|
-
handleLeave,
|
|
2562
|
-
isActive,
|
|
2563
|
-
next
|
|
2564
|
-
} = linkInfo;
|
|
2565
|
-
|
|
2566
|
-
const composeHandlers = handlers => e => {
|
|
2567
|
-
e.persist();
|
|
2568
|
-
handlers.forEach(handler => {
|
|
2569
|
-
if (handler) handler(e);
|
|
2570
|
-
});
|
|
2571
|
-
}; // Get the active props
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
const resolvedActiveProps = isActive ? (_functionalUpdate = functionalUpdate(activeProps, {})) != null ? _functionalUpdate : {} : {}; // Get the inactive props
|
|
2575
|
-
|
|
2576
|
-
const resolvedInactiveProps = isActive ? {} : (_functionalUpdate2 = functionalUpdate(inactiveProps, {})) != null ? _functionalUpdate2 : {};
|
|
2577
|
-
return _extends$2({}, resolvedActiveProps, resolvedInactiveProps, rest, {
|
|
2578
|
-
href: disabled ? undefined : next.href,
|
|
2579
|
-
onClick: composeHandlers([handleClick, onClick]),
|
|
2580
|
-
onFocus: composeHandlers([handleFocus, onFocus]),
|
|
2581
|
-
onMouseEnter: composeHandlers([handleEnter, onMouseEnter]),
|
|
2582
|
-
onMouseLeave: composeHandlers([handleLeave, onMouseLeave]),
|
|
2583
|
-
target,
|
|
2584
|
-
style: _extends$2({}, style, resolvedActiveProps.style, resolvedInactiveProps.style),
|
|
2585
|
-
className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined
|
|
2586
|
-
}, disabled ? {
|
|
2587
|
-
role: 'link',
|
|
2588
|
-
'aria-disabled': true
|
|
2589
|
-
} : undefined, {
|
|
2590
|
-
['data-status']: isActive ? 'active' : undefined
|
|
2591
|
-
});
|
|
2592
|
-
},
|
|
2593
|
-
Link: /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
2594
|
-
const linkProps = route.linkProps(props);
|
|
2595
|
-
useRouterSubscription(router);
|
|
2596
|
-
return /*#__PURE__*/React.createElement("a", _extends$2({
|
|
2597
|
-
ref: ref
|
|
2598
|
-
}, linkProps, {
|
|
2599
|
-
children: typeof props.children === 'function' ? props.children({
|
|
2600
|
-
isActive: linkProps['data-status'] === 'active'
|
|
2601
|
-
}) : props.children
|
|
2602
|
-
}));
|
|
2603
|
-
}),
|
|
2604
|
-
MatchRoute: opts => {
|
|
2605
|
-
const {
|
|
2606
|
-
pending,
|
|
2607
|
-
caseSensitive
|
|
2608
|
-
} = opts,
|
|
2609
|
-
rest = _objectWithoutPropertiesLoose(opts, _excluded2);
|
|
2610
|
-
|
|
2611
|
-
const params = route.matchRoute(rest, {
|
|
2612
|
-
pending,
|
|
2613
|
-
caseSensitive
|
|
2614
|
-
});
|
|
2615
|
-
|
|
2616
|
-
if (!params) {
|
|
2617
|
-
return null;
|
|
2618
|
-
}
|
|
2619
|
-
|
|
2620
|
-
return typeof opts.children === 'function' ? opts.children(params) : opts.children;
|
|
2621
|
-
}
|
|
132
|
+
href
|
|
2622
133
|
};
|
|
134
|
+
}
|
|
135
|
+
const {
|
|
136
|
+
handleClick,
|
|
137
|
+
handleFocus,
|
|
138
|
+
handleEnter,
|
|
139
|
+
handleLeave,
|
|
140
|
+
handleTouchStart,
|
|
141
|
+
isActive,
|
|
142
|
+
next
|
|
143
|
+
} = linkInfo;
|
|
144
|
+
const handleReactClick = e => {
|
|
145
|
+
if (options.startTransition ?? true) {
|
|
146
|
+
(React.startTransition || (d => d))(() => {
|
|
147
|
+
handleClick(e);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const composeHandlers = handlers => e => {
|
|
152
|
+
if (e.persist) e.persist();
|
|
153
|
+
handlers.filter(Boolean).forEach(handler => {
|
|
154
|
+
if (e.defaultPrevented) return;
|
|
155
|
+
handler(e);
|
|
156
|
+
});
|
|
2623
157
|
};
|
|
2624
158
|
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
const routerExt = {
|
|
2628
|
-
useState: () => {
|
|
2629
|
-
useRouterSubscription(router);
|
|
2630
|
-
return router.state;
|
|
2631
|
-
},
|
|
2632
|
-
useMatch: routeId => {
|
|
2633
|
-
useRouterSubscription(router);
|
|
2634
|
-
invariant(routeId !== rootRouteId, "\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
|
|
2635
|
-
|
|
2636
|
-
const runtimeMatch = _useMatch();
|
|
2637
|
-
|
|
2638
|
-
const match = router.state.matches.find(d => d.routeId === routeId);
|
|
2639
|
-
invariant(match, "Could not find a match for route \"" + routeId + "\" being rendered in this component!");
|
|
2640
|
-
invariant(runtimeMatch.routeId == (match == null ? void 0 : match.routeId), "useMatch('" + (match == null ? void 0 : match.routeId) + "') is being called in a component that is meant to render the '" + runtimeMatch.routeId + "' route. Did you mean to 'useRoute(" + (match == null ? void 0 : match.routeId) + ")' instead?");
|
|
2641
|
-
|
|
2642
|
-
if (!match) {
|
|
2643
|
-
invariant('Match not found!');
|
|
2644
|
-
}
|
|
2645
|
-
|
|
2646
|
-
return match;
|
|
2647
|
-
}
|
|
2648
|
-
};
|
|
2649
|
-
const routeExt = makeRouteExt(router.getRoute('/'), router);
|
|
2650
|
-
Object.assign(router, routerExt, routeExt);
|
|
2651
|
-
},
|
|
2652
|
-
createRoute: _ref => {
|
|
2653
|
-
let {
|
|
2654
|
-
router,
|
|
2655
|
-
route
|
|
2656
|
-
} = _ref;
|
|
2657
|
-
const routeExt = makeRouteExt(route, router);
|
|
2658
|
-
Object.assign(route, routeExt);
|
|
2659
|
-
},
|
|
2660
|
-
createElement: async element => {
|
|
2661
|
-
if (typeof element === 'function') {
|
|
2662
|
-
const res = await element(); // Support direct import() calls
|
|
2663
|
-
|
|
2664
|
-
if (typeof res === 'object' && res.default) {
|
|
2665
|
-
return /*#__PURE__*/React.createElement(res.default);
|
|
2666
|
-
} else {
|
|
2667
|
-
return res;
|
|
2668
|
-
}
|
|
2669
|
-
}
|
|
159
|
+
// Get the active props
|
|
160
|
+
const resolvedActiveProps = isActive ? functionalUpdate(activeProps, {}) ?? {} : {};
|
|
2670
161
|
|
|
2671
|
-
|
|
2672
|
-
|
|
162
|
+
// Get the inactive props
|
|
163
|
+
const resolvedInactiveProps = isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {};
|
|
164
|
+
return {
|
|
165
|
+
...resolvedActiveProps,
|
|
166
|
+
...resolvedInactiveProps,
|
|
167
|
+
...rest,
|
|
168
|
+
href: disabled ? undefined : next.maskedLocation ? next.maskedLocation.href : next.href,
|
|
169
|
+
onClick: composeHandlers([onClick, handleReactClick]),
|
|
170
|
+
onFocus: composeHandlers([onFocus, handleFocus]),
|
|
171
|
+
onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),
|
|
172
|
+
onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),
|
|
173
|
+
onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),
|
|
174
|
+
target,
|
|
175
|
+
style: {
|
|
176
|
+
...style,
|
|
177
|
+
...resolvedActiveProps.style,
|
|
178
|
+
...resolvedInactiveProps.style
|
|
179
|
+
},
|
|
180
|
+
className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined,
|
|
181
|
+
...(disabled ? {
|
|
182
|
+
role: 'link',
|
|
183
|
+
'aria-disabled': true
|
|
184
|
+
} : undefined),
|
|
185
|
+
['data-status']: isActive ? 'active' : undefined
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const Link = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
189
|
+
const linkProps = useLinkProps(props);
|
|
190
|
+
return /*#__PURE__*/React.createElement("a", _extends({
|
|
191
|
+
ref: ref
|
|
192
|
+
}, linkProps, {
|
|
193
|
+
children: typeof props.children === 'function' ? props.children({
|
|
194
|
+
isActive: linkProps['data-status'] === 'active'
|
|
195
|
+
}) : props.children
|
|
2673
196
|
}));
|
|
2674
|
-
|
|
197
|
+
});
|
|
198
|
+
function Navigate(props) {
|
|
199
|
+
const router = useRouter();
|
|
200
|
+
useLayoutEffect$1(() => {
|
|
201
|
+
router.navigate(props);
|
|
202
|
+
}, []);
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
const matchIdsContext = /*#__PURE__*/React.createContext(null);
|
|
206
|
+
const routerContext = /*#__PURE__*/React.createContext(null);
|
|
207
|
+
function useRouterState(opts) {
|
|
208
|
+
const router = useRouter();
|
|
209
|
+
return useStore(router.__store, opts?.select);
|
|
2675
210
|
}
|
|
2676
|
-
function RouterProvider(
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
} = _ref2,
|
|
2681
|
-
rest = _objectWithoutPropertiesLoose(_ref2, _excluded3);
|
|
2682
|
-
|
|
211
|
+
function RouterProvider({
|
|
212
|
+
router,
|
|
213
|
+
...rest
|
|
214
|
+
}) {
|
|
2683
215
|
router.update(rest);
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
216
|
+
React.useEffect(() => {
|
|
217
|
+
let unsub;
|
|
218
|
+
React.startTransition(() => {
|
|
219
|
+
unsub = router.mount();
|
|
220
|
+
});
|
|
221
|
+
return unsub;
|
|
2687
222
|
}, [router]);
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
223
|
+
const Wrap = router.options.Wrap || React.Fragment;
|
|
224
|
+
return /*#__PURE__*/React.createElement(Wrap, null, /*#__PURE__*/React.createElement(routerContext.Provider, {
|
|
225
|
+
value: router
|
|
226
|
+
}, /*#__PURE__*/React.createElement(Matches, null)));
|
|
227
|
+
}
|
|
228
|
+
function Matches() {
|
|
229
|
+
const router = useRouter();
|
|
230
|
+
const matchIds = useRouterState({
|
|
231
|
+
select: state => {
|
|
232
|
+
return state.renderedMatchIds;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
const locationKey = useRouterState({
|
|
236
|
+
select: d => d.resolvedLocation.state?.key
|
|
237
|
+
});
|
|
238
|
+
const route = router.getRoute(rootRouteId);
|
|
239
|
+
const errorComponent = React.useCallback(props => {
|
|
240
|
+
return /*#__PURE__*/React.createElement(ErrorComponent, {
|
|
241
|
+
...props,
|
|
242
|
+
useMatch: route.useMatch,
|
|
243
|
+
useRouteContext: route.useRouteContext,
|
|
244
|
+
useSearch: route.useSearch,
|
|
245
|
+
useParams: route.useParams
|
|
246
|
+
});
|
|
247
|
+
}, [route]);
|
|
248
|
+
return /*#__PURE__*/React.createElement(matchIdsContext.Provider, {
|
|
249
|
+
value: [undefined, ...matchIds]
|
|
250
|
+
}, /*#__PURE__*/React.createElement(CatchBoundary, {
|
|
251
|
+
resetKey: locationKey,
|
|
252
|
+
errorComponent: errorComponent,
|
|
253
|
+
onCatch: () => {
|
|
254
|
+
warning(false, `Error in router! Consider setting an 'errorComponent' in your RootRoute! 👍`);
|
|
2691
255
|
}
|
|
2692
|
-
}, /*#__PURE__*/React.createElement(
|
|
2693
|
-
value: router.state.matches
|
|
2694
|
-
}, children != null ? children : /*#__PURE__*/React.createElement(Outlet, null)));
|
|
256
|
+
}, /*#__PURE__*/React.createElement(Outlet, null)));
|
|
2695
257
|
}
|
|
2696
|
-
|
|
2697
258
|
function useRouter() {
|
|
2698
259
|
const value = React.useContext(routerContext);
|
|
2699
|
-
warning(
|
|
2700
|
-
|
|
2701
|
-
return value.router;
|
|
260
|
+
warning(value, 'useRouter must be used inside a <Router> component!');
|
|
261
|
+
return value;
|
|
2702
262
|
}
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
return
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
263
|
+
function useMatches(opts) {
|
|
264
|
+
const matchIds = React.useContext(matchIdsContext);
|
|
265
|
+
return useRouterState({
|
|
266
|
+
select: state => {
|
|
267
|
+
const matches = state.renderedMatches.slice(state.renderedMatches.findIndex(d => d.id === matchIds[0]));
|
|
268
|
+
return opts?.select ? opts.select(matches) : matches;
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
function useMatch(opts) {
|
|
273
|
+
const router = useRouter();
|
|
274
|
+
const nearestMatchId = React.useContext(matchIdsContext)[0];
|
|
275
|
+
const nearestMatchRouteId = router.getRouteMatch(nearestMatchId)?.routeId;
|
|
276
|
+
const matchRouteId = useRouterState({
|
|
277
|
+
select: state => {
|
|
278
|
+
const match = opts?.from ? state.renderedMatches.find(d => d.routeId === opts?.from) : state.renderedMatches.find(d => d.id === nearestMatchId);
|
|
279
|
+
return match.routeId;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
if (opts?.strict ?? true) {
|
|
283
|
+
invariant(nearestMatchRouteId == matchRouteId, `useMatch("${matchRouteId}") is being called in a component that is meant to render the '${nearestMatchRouteId}' route. Did you mean to 'useMatch("${matchRouteId}", { strict: false })' or 'useRoute("${matchRouteId}")' instead?`);
|
|
284
|
+
}
|
|
285
|
+
const matchSelection = useRouterState({
|
|
286
|
+
select: state => {
|
|
287
|
+
const match = opts?.from ? state.renderedMatches.find(d => d.routeId === opts?.from) : state.renderedMatches.find(d => d.id === nearestMatchId);
|
|
288
|
+
invariant(match, `Could not find ${opts?.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
|
|
289
|
+
return opts?.select ? opts.select(match) : match;
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
return matchSelection;
|
|
293
|
+
}
|
|
294
|
+
function useLoader(opts) {
|
|
295
|
+
return useMatch({
|
|
296
|
+
...opts,
|
|
297
|
+
select: match => opts?.select ? opts?.select(match.loaderData) : match.loaderData
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
function useRouterContext(opts) {
|
|
301
|
+
return useMatch({
|
|
302
|
+
...opts,
|
|
303
|
+
select: match => opts?.select ? opts.select(match.context) : match.context
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
function useRouteContext(opts) {
|
|
307
|
+
return useMatch({
|
|
308
|
+
...opts,
|
|
309
|
+
select: match => opts?.select ? opts.select(match.context) : match.context
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
function useSearch(opts) {
|
|
313
|
+
return useMatch({
|
|
314
|
+
...opts,
|
|
315
|
+
select: match => {
|
|
316
|
+
return opts?.select ? opts.select(match.search) : match.search;
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
function useParams(opts) {
|
|
321
|
+
return useRouterState({
|
|
322
|
+
select: state => {
|
|
323
|
+
const params = last(state.renderedMatches)?.params;
|
|
324
|
+
return opts?.select ? opts.select(params) : params;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
function useNavigate(defaultOpts) {
|
|
329
|
+
const router = useRouter();
|
|
330
|
+
return React.useCallback(opts => {
|
|
331
|
+
return router.navigate({
|
|
332
|
+
...defaultOpts,
|
|
333
|
+
...opts
|
|
334
|
+
});
|
|
335
|
+
}, []);
|
|
336
|
+
}
|
|
337
|
+
function useMatchRoute() {
|
|
338
|
+
const router = useRouter();
|
|
339
|
+
return React.useCallback(opts => {
|
|
340
|
+
const {
|
|
341
|
+
pending,
|
|
342
|
+
caseSensitive,
|
|
343
|
+
...rest
|
|
344
|
+
} = opts;
|
|
345
|
+
return router.matchRoute(rest, {
|
|
346
|
+
pending,
|
|
347
|
+
caseSensitive
|
|
348
|
+
});
|
|
349
|
+
}, []);
|
|
350
|
+
}
|
|
351
|
+
function MatchRoute(props) {
|
|
352
|
+
const matchRoute = useMatchRoute();
|
|
353
|
+
const params = matchRoute(props);
|
|
354
|
+
if (typeof props.children === 'function') {
|
|
355
|
+
return props.children(params);
|
|
356
|
+
}
|
|
357
|
+
return !!params ? props.children : null;
|
|
2721
358
|
}
|
|
2722
|
-
|
|
2723
359
|
function Outlet() {
|
|
2724
|
-
|
|
2725
|
-
|
|
360
|
+
const matchIds = React.useContext(matchIdsContext).slice(1);
|
|
361
|
+
if (!matchIds[0]) {
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
return /*#__PURE__*/React.createElement(Match, {
|
|
365
|
+
matchIds: matchIds
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
const defaultPending = () => null;
|
|
369
|
+
function Match({
|
|
370
|
+
matchIds
|
|
371
|
+
}) {
|
|
2726
372
|
const router = useRouter();
|
|
2727
|
-
const
|
|
2728
|
-
const
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
373
|
+
const matchId = matchIds[0];
|
|
374
|
+
const routeId = router.getRouteMatch(matchId).routeId;
|
|
375
|
+
const route = router.getRoute(routeId);
|
|
376
|
+
const locationKey = useRouterState({
|
|
377
|
+
select: s => s.resolvedLocation.state?.key
|
|
378
|
+
});
|
|
379
|
+
const PendingComponent = route.options.pendingComponent ?? router.options.defaultPendingComponent ?? defaultPending;
|
|
380
|
+
const routeErrorComponent = route.options.errorComponent ?? router.options.defaultErrorComponent ?? ErrorComponent;
|
|
381
|
+
const ResolvedSuspenseBoundary = route.options.wrapInSuspense ?? !route.isRoot ? React.Suspense : SafeFragment;
|
|
382
|
+
const ResolvedCatchBoundary = !!routeErrorComponent ? CatchBoundary : SafeFragment;
|
|
383
|
+
const errorComponent = React.useCallback(props => {
|
|
384
|
+
return /*#__PURE__*/React.createElement(routeErrorComponent, {
|
|
385
|
+
...props,
|
|
386
|
+
useMatch: route.useMatch,
|
|
387
|
+
useRouteContext: route.useRouteContext,
|
|
388
|
+
useSearch: route.useSearch,
|
|
389
|
+
useParams: route.useParams
|
|
390
|
+
});
|
|
391
|
+
}, [route]);
|
|
392
|
+
return /*#__PURE__*/React.createElement(matchIdsContext.Provider, {
|
|
393
|
+
value: matchIds
|
|
394
|
+
}, /*#__PURE__*/React.createElement(ResolvedSuspenseBoundary, {
|
|
395
|
+
fallback: /*#__PURE__*/React.createElement(PendingComponent, {
|
|
396
|
+
useMatch: route.useMatch,
|
|
397
|
+
useRouteContext: route.useRouteContext,
|
|
398
|
+
useSearch: route.useSearch,
|
|
399
|
+
useParams: route.useParams
|
|
400
|
+
})
|
|
401
|
+
}, /*#__PURE__*/React.createElement(ResolvedCatchBoundary, {
|
|
402
|
+
resetKey: locationKey,
|
|
403
|
+
errorComponent: errorComponent,
|
|
404
|
+
onCatch: () => {
|
|
405
|
+
warning(false, `Error in route match: ${matchId}`);
|
|
406
|
+
}
|
|
407
|
+
}, /*#__PURE__*/React.createElement(MatchInner, {
|
|
408
|
+
matchId: matchId,
|
|
409
|
+
PendingComponent: PendingComponent
|
|
410
|
+
}))));
|
|
411
|
+
}
|
|
412
|
+
function MatchInner({
|
|
413
|
+
matchId,
|
|
414
|
+
PendingComponent
|
|
415
|
+
}) {
|
|
416
|
+
const router = useRouter();
|
|
417
|
+
const match = useRouterState({
|
|
418
|
+
select: d => {
|
|
419
|
+
const match = d.matchesById[matchId];
|
|
420
|
+
return pick(match, ['status', 'loadPromise', 'routeId', 'error']);
|
|
2736
421
|
}
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
422
|
+
});
|
|
423
|
+
const route = router.getRoute(match.routeId);
|
|
424
|
+
if (match.status === 'error') {
|
|
425
|
+
throw match.error;
|
|
426
|
+
}
|
|
427
|
+
if (match.status === 'pending') {
|
|
428
|
+
return /*#__PURE__*/React.createElement(PendingComponent, {
|
|
429
|
+
useLoader: route.useLoader,
|
|
430
|
+
useMatch: route.useMatch,
|
|
431
|
+
useRouteContext: route.useRouteContext,
|
|
432
|
+
useSearch: route.useSearch,
|
|
433
|
+
useParams: route.useParams
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
if (match.status === 'success') {
|
|
437
|
+
let comp = route.options.component ?? router.options.defaultComponent;
|
|
438
|
+
if (comp) {
|
|
439
|
+
return /*#__PURE__*/React.createElement(comp, {
|
|
440
|
+
useLoader: route.useLoader,
|
|
441
|
+
useMatch: route.useMatch,
|
|
442
|
+
useRouteContext: route.useRouteContext,
|
|
443
|
+
useSearch: route.useSearch,
|
|
444
|
+
useParams: route.useParams
|
|
2751
445
|
});
|
|
2752
446
|
}
|
|
447
|
+
return /*#__PURE__*/React.createElement(Outlet, null);
|
|
448
|
+
}
|
|
449
|
+
invariant(false, 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!');
|
|
450
|
+
}
|
|
451
|
+
function SafeFragment(props) {
|
|
452
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, props.children);
|
|
453
|
+
}
|
|
454
|
+
function useInjectHtml() {
|
|
455
|
+
const router = useRouter();
|
|
456
|
+
return React.useCallback(html => {
|
|
457
|
+
router.injectHtml(html);
|
|
458
|
+
}, []);
|
|
459
|
+
}
|
|
460
|
+
function useDehydrate() {
|
|
461
|
+
const router = useRouter();
|
|
462
|
+
return React.useCallback(function dehydrate(key, data) {
|
|
463
|
+
return router.dehydrateData(key, data);
|
|
464
|
+
}, []);
|
|
465
|
+
}
|
|
466
|
+
function useHydrate() {
|
|
467
|
+
const router = useRouter();
|
|
468
|
+
return function hydrate(key) {
|
|
469
|
+
return router.hydrateData(key);
|
|
470
|
+
};
|
|
471
|
+
}
|
|
2753
472
|
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
473
|
+
// This is the messiest thing ever... I'm either seriously tired (likely) or
|
|
474
|
+
// there has to be a better way to reset error boundaries when the
|
|
475
|
+
// router's location key changes.
|
|
476
|
+
|
|
477
|
+
function CatchBoundary(props) {
|
|
478
|
+
const errorComponent = props.errorComponent ?? ErrorComponent;
|
|
479
|
+
return /*#__PURE__*/React.createElement(CatchBoundaryImpl, {
|
|
480
|
+
resetKey: props.resetKey,
|
|
481
|
+
onCatch: props.onCatch,
|
|
482
|
+
children: ({
|
|
483
|
+
error
|
|
484
|
+
}) => {
|
|
485
|
+
if (error) {
|
|
486
|
+
return /*#__PURE__*/React.createElement(errorComponent, {
|
|
487
|
+
error
|
|
488
|
+
});
|
|
2765
489
|
}
|
|
2766
|
-
|
|
2767
|
-
return null;
|
|
490
|
+
return props.children;
|
|
2768
491
|
}
|
|
2769
|
-
|
|
2770
|
-
return (_ref4 = childMatch.__.element) != null ? _ref4 : router.options.defaultElement;
|
|
2771
|
-
})();
|
|
2772
|
-
|
|
2773
|
-
const catchElement = (_childMatch$options$c = childMatch == null ? void 0 : childMatch.options.catchElement) != null ? _childMatch$options$c : router.options.defaultCatchElement;
|
|
2774
|
-
return /*#__PURE__*/React.createElement(MatchesProvider, {
|
|
2775
|
-
value: matches,
|
|
2776
|
-
key: childMatch.matchId
|
|
2777
|
-
}, /*#__PURE__*/React.createElement(CatchBoundary, {
|
|
2778
|
-
catchElement: catchElement
|
|
2779
|
-
}, element));
|
|
492
|
+
});
|
|
2780
493
|
}
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
494
|
+
class CatchBoundaryImpl extends React.Component {
|
|
495
|
+
state = {
|
|
496
|
+
error: null
|
|
497
|
+
};
|
|
498
|
+
static getDerivedStateFromError(error) {
|
|
499
|
+
return {
|
|
500
|
+
error
|
|
2787
501
|
};
|
|
2788
|
-
|
|
2789
|
-
|
|
502
|
+
}
|
|
503
|
+
componentDidUpdate(prevProps, prevState) {
|
|
504
|
+
if (prevState.error && prevProps.resetKey !== this.props.resetKey) {
|
|
2790
505
|
this.setState({
|
|
2791
|
-
error:
|
|
2792
|
-
info: false
|
|
506
|
+
error: null
|
|
2793
507
|
});
|
|
2794
|
-
}
|
|
508
|
+
}
|
|
2795
509
|
}
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
console.error(error);
|
|
2799
|
-
this.setState({
|
|
2800
|
-
error,
|
|
2801
|
-
info
|
|
2802
|
-
});
|
|
510
|
+
componentDidCatch(error) {
|
|
511
|
+
this.props.onCatch?.(error);
|
|
2803
512
|
}
|
|
2804
|
-
|
|
2805
513
|
render() {
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
const catchElement = (_this$props$catchElem = this.props.catchElement) != null ? _this$props$catchElem : DefaultErrorBoundary;
|
|
2809
|
-
|
|
2810
|
-
if (this.state.error) {
|
|
2811
|
-
return typeof catchElement === 'function' ? catchElement(this.state) : catchElement;
|
|
2812
|
-
}
|
|
2813
|
-
|
|
2814
|
-
return this.props.children;
|
|
514
|
+
return this.props.children(this.state);
|
|
2815
515
|
}
|
|
2816
|
-
|
|
2817
516
|
}
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
} = _ref5;
|
|
517
|
+
function ErrorComponent({
|
|
518
|
+
error
|
|
519
|
+
}) {
|
|
520
|
+
const [show, setShow] = React.useState(process.env.NODE_ENV !== 'production');
|
|
2823
521
|
return /*#__PURE__*/React.createElement("div", {
|
|
2824
522
|
style: {
|
|
2825
523
|
padding: '.5rem',
|
|
2826
524
|
maxWidth: '100%'
|
|
2827
525
|
}
|
|
526
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
527
|
+
style: {
|
|
528
|
+
display: 'flex',
|
|
529
|
+
alignItems: 'center',
|
|
530
|
+
gap: '.5rem'
|
|
531
|
+
}
|
|
2828
532
|
}, /*#__PURE__*/React.createElement("strong", {
|
|
2829
533
|
style: {
|
|
2830
|
-
fontSize: '
|
|
534
|
+
fontSize: '1rem'
|
|
2831
535
|
}
|
|
2832
|
-
}, "Something went wrong!"), /*#__PURE__*/React.createElement("
|
|
536
|
+
}, "Something went wrong!"), /*#__PURE__*/React.createElement("button", {
|
|
537
|
+
style: {
|
|
538
|
+
appearance: 'none',
|
|
539
|
+
fontSize: '.6em',
|
|
540
|
+
border: '1px solid currentColor',
|
|
541
|
+
padding: '.1rem .2rem',
|
|
542
|
+
fontWeight: 'bold',
|
|
543
|
+
borderRadius: '.25rem'
|
|
544
|
+
},
|
|
545
|
+
onClick: () => setShow(d => !d)
|
|
546
|
+
}, show ? 'Hide Error' : 'Show Error')), /*#__PURE__*/React.createElement("div", {
|
|
2833
547
|
style: {
|
|
2834
|
-
height: '.
|
|
548
|
+
height: '.25rem'
|
|
2835
549
|
}
|
|
2836
|
-
}), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("pre",
|
|
550
|
+
}), show ? /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("pre", {
|
|
2837
551
|
style: {
|
|
2838
552
|
fontSize: '.7em',
|
|
2839
553
|
border: '1px solid red',
|
|
2840
554
|
borderRadius: '.25rem',
|
|
2841
|
-
padding: '.
|
|
2842
|
-
color: 'red'
|
|
2843
|
-
|
|
2844
|
-
}, error.message) : null)), /*#__PURE__*/React.createElement("div", {
|
|
2845
|
-
style: {
|
|
2846
|
-
height: '1rem'
|
|
2847
|
-
}
|
|
2848
|
-
}), /*#__PURE__*/React.createElement("div", {
|
|
2849
|
-
style: {
|
|
2850
|
-
fontSize: '.8em',
|
|
2851
|
-
borderLeft: '3px solid rgba(127, 127, 127, 1)',
|
|
2852
|
-
paddingLeft: '.5rem',
|
|
2853
|
-
opacity: 0.5
|
|
555
|
+
padding: '.3rem',
|
|
556
|
+
color: 'red',
|
|
557
|
+
overflow: 'auto'
|
|
2854
558
|
}
|
|
2855
|
-
},
|
|
559
|
+
}, error.message ? /*#__PURE__*/React.createElement("code", null, error.message) : null)) : null);
|
|
2856
560
|
}
|
|
2857
|
-
function
|
|
561
|
+
function useBlocker(message, condition = true) {
|
|
2858
562
|
const router = useRouter();
|
|
2859
563
|
React.useEffect(() => {
|
|
2860
|
-
if (!
|
|
2861
|
-
let unblock = router.history.block(
|
|
564
|
+
if (!condition) return;
|
|
565
|
+
let unblock = router.history.block((retry, cancel) => {
|
|
2862
566
|
if (window.confirm(message)) {
|
|
2863
567
|
unblock();
|
|
2864
|
-
|
|
2865
|
-
} else {
|
|
2866
|
-
router.location.pathname = window.location.pathname;
|
|
568
|
+
retry();
|
|
2867
569
|
}
|
|
2868
570
|
});
|
|
2869
571
|
return unblock;
|
|
2870
|
-
}
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
function Block({
|
|
575
|
+
message,
|
|
576
|
+
condition,
|
|
577
|
+
children
|
|
578
|
+
}) {
|
|
579
|
+
useBlocker(message, condition);
|
|
580
|
+
return children ?? null;
|
|
581
|
+
}
|
|
582
|
+
function shallow(objA, objB) {
|
|
583
|
+
if (Object.is(objA, objB)) {
|
|
584
|
+
return true;
|
|
585
|
+
}
|
|
586
|
+
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
587
|
+
return false;
|
|
588
|
+
}
|
|
589
|
+
const keysA = Object.keys(objA);
|
|
590
|
+
if (keysA.length !== Object.keys(objB).length) {
|
|
591
|
+
return false;
|
|
592
|
+
}
|
|
593
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
594
|
+
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const useLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
602
|
+
function useScrollRestoration(options) {
|
|
603
|
+
const router = useRouter();
|
|
604
|
+
useLayoutEffect(() => {
|
|
605
|
+
return watchScrollPositions(router, options);
|
|
606
|
+
}, []);
|
|
607
|
+
useLayoutEffect(() => {
|
|
608
|
+
restoreScrollPositions(router, options);
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
function ScrollRestoration(props) {
|
|
612
|
+
useScrollRestoration(props);
|
|
613
|
+
return null;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function useAwaited({
|
|
617
|
+
promise
|
|
618
|
+
}) {
|
|
619
|
+
const router = useRouter();
|
|
620
|
+
let state = promise.__deferredState;
|
|
621
|
+
const key = `__TSR__DEFERRED__${state.uid}`;
|
|
622
|
+
if (isDehydratedDeferred(promise)) {
|
|
623
|
+
state = router.hydrateData(key);
|
|
624
|
+
promise = Promise.resolve(state.data);
|
|
625
|
+
promise.__deferredState = state;
|
|
626
|
+
}
|
|
627
|
+
if (state.status === 'pending') {
|
|
628
|
+
throw promise;
|
|
629
|
+
}
|
|
630
|
+
if (state.status === 'error') {
|
|
631
|
+
throw state.error;
|
|
632
|
+
}
|
|
633
|
+
router.dehydrateData(key, state);
|
|
634
|
+
return [state.data];
|
|
2871
635
|
}
|
|
2872
|
-
function
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
when,
|
|
2876
|
-
children
|
|
2877
|
-
} = _ref6;
|
|
2878
|
-
usePrompt(message, when != null ? when : true);
|
|
2879
|
-
return children != null ? children : null;
|
|
636
|
+
function Await(props) {
|
|
637
|
+
const awaited = useAwaited(props);
|
|
638
|
+
return props.children(...awaited);
|
|
2880
639
|
}
|
|
2881
640
|
|
|
2882
|
-
export {
|
|
641
|
+
export { Await, Block, CatchBoundary, CatchBoundaryImpl, ErrorComponent, Link, MatchRoute, Navigate, Outlet, RouterProvider, ScrollRestoration, lazyRouteComponent, matchIdsContext, routerContext, shallow, useAwaited, useBlocker, useDehydrate, useHydrate, useInjectHtml, useLinkProps, useLoader, useMatch, useMatchRoute, useMatches, useNavigate, useParams, useRouteContext, useRouter, useRouterContext, useRouterState, useScrollRestoration, useSearch };
|
|
2883
642
|
//# sourceMappingURL=index.js.map
|