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