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