@tanstack/react-router 0.0.1-beta.2 → 0.0.1-beta.21
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/react-router/src/index.js +117 -116
- package/build/cjs/react-router/src/index.js.map +1 -1
- package/build/cjs/router-core/build/esm/index.js +257 -227
- package/build/cjs/router-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +362 -342
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +29 -29
- package/build/types/index.d.ts +61 -31
- package/build/umd/index.development.js +373 -342
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -2
- package/src/index.tsx +260 -192
|
@@ -991,6 +991,12 @@
|
|
|
991
991
|
|
|
992
992
|
return updater;
|
|
993
993
|
}
|
|
994
|
+
function pick(parent, keys) {
|
|
995
|
+
return keys.reduce((obj, key) => {
|
|
996
|
+
obj[key] = parent[key];
|
|
997
|
+
return obj;
|
|
998
|
+
}, {});
|
|
999
|
+
}
|
|
994
1000
|
|
|
995
1001
|
function joinPaths(paths) {
|
|
996
1002
|
return cleanPath(paths.filter(Boolean).join('/'));
|
|
@@ -1217,6 +1223,7 @@
|
|
|
1217
1223
|
var str = decodeURIComponent(mix);
|
|
1218
1224
|
if (str === 'false') return false;
|
|
1219
1225
|
if (str === 'true') return true;
|
|
1226
|
+
if (str.charAt(0) === '0') return str;
|
|
1220
1227
|
return +str * 0 === 0 ? +str : str;
|
|
1221
1228
|
}
|
|
1222
1229
|
|
|
@@ -1267,7 +1274,7 @@
|
|
|
1267
1274
|
|
|
1268
1275
|
const action = router.state.actions[id] || (() => {
|
|
1269
1276
|
router.state.actions[id] = {
|
|
1270
|
-
|
|
1277
|
+
submissions: [],
|
|
1271
1278
|
submit: async (submission, actionOpts) => {
|
|
1272
1279
|
var _actionOpts$invalidat;
|
|
1273
1280
|
|
|
@@ -1276,18 +1283,20 @@
|
|
|
1276
1283
|
}
|
|
1277
1284
|
|
|
1278
1285
|
const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
|
|
1286
|
+
|
|
1287
|
+
if (!(actionOpts != null && actionOpts.multi)) {
|
|
1288
|
+
action.submissions = action.submissions.filter(d => d.isMulti);
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1279
1291
|
const actionState = {
|
|
1280
1292
|
submittedAt: Date.now(),
|
|
1281
1293
|
status: 'pending',
|
|
1282
|
-
submission
|
|
1294
|
+
submission,
|
|
1295
|
+
isMulti: !!(actionOpts != null && actionOpts.multi)
|
|
1283
1296
|
};
|
|
1284
1297
|
action.current = actionState;
|
|
1285
1298
|
action.latest = actionState;
|
|
1286
|
-
action.
|
|
1287
|
-
router.state = _extends({}, router.state, {
|
|
1288
|
-
currentAction: actionState,
|
|
1289
|
-
latestAction: actionState
|
|
1290
|
-
});
|
|
1299
|
+
action.submissions.push(actionState);
|
|
1291
1300
|
router.notify();
|
|
1292
1301
|
|
|
1293
1302
|
try {
|
|
@@ -1309,11 +1318,6 @@
|
|
|
1309
1318
|
actionState.error = err;
|
|
1310
1319
|
actionState.status = 'error';
|
|
1311
1320
|
} finally {
|
|
1312
|
-
action.pending = action.pending.filter(d => d !== actionState);
|
|
1313
|
-
router.removeActionQueue.push({
|
|
1314
|
-
action,
|
|
1315
|
-
actionState
|
|
1316
|
-
});
|
|
1317
1321
|
router.notify();
|
|
1318
1322
|
}
|
|
1319
1323
|
}
|
|
@@ -1388,15 +1392,6 @@
|
|
|
1388
1392
|
});
|
|
1389
1393
|
return route;
|
|
1390
1394
|
}
|
|
1391
|
-
function cascadeLoaderData(matches) {
|
|
1392
|
-
matches.forEach((match, index) => {
|
|
1393
|
-
const parent = matches[index - 1];
|
|
1394
|
-
|
|
1395
|
-
if (parent) {
|
|
1396
|
-
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
1397
|
-
}
|
|
1398
|
-
});
|
|
1399
|
-
}
|
|
1400
1395
|
|
|
1401
1396
|
const rootRouteId = '__root__';
|
|
1402
1397
|
const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
|
|
@@ -1448,7 +1443,7 @@
|
|
|
1448
1443
|
};
|
|
1449
1444
|
};
|
|
1450
1445
|
|
|
1451
|
-
const
|
|
1446
|
+
const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
|
|
1452
1447
|
function createRouteMatch(router, route, opts) {
|
|
1453
1448
|
const routeMatch = _extends({}, route, opts, {
|
|
1454
1449
|
router,
|
|
@@ -1458,10 +1453,10 @@
|
|
|
1458
1453
|
status: 'idle',
|
|
1459
1454
|
routeLoaderData: {},
|
|
1460
1455
|
loaderData: {},
|
|
1461
|
-
isPending: false,
|
|
1462
1456
|
isFetching: false,
|
|
1463
1457
|
isInvalid: false,
|
|
1464
1458
|
invalidAt: Infinity,
|
|
1459
|
+
// pendingActions: [],
|
|
1465
1460
|
getIsInvalid: () => {
|
|
1466
1461
|
const now = Date.now();
|
|
1467
1462
|
return routeMatch.isInvalid || routeMatch.invalidAt < now;
|
|
@@ -1475,43 +1470,6 @@
|
|
|
1475
1470
|
|
|
1476
1471
|
routeMatch.router.notify();
|
|
1477
1472
|
},
|
|
1478
|
-
startPending: () => {
|
|
1479
|
-
var _routeMatch$options$p, _routeMatch$options$p2;
|
|
1480
|
-
|
|
1481
|
-
const pendingMs = (_routeMatch$options$p = routeMatch.options.pendingMs) != null ? _routeMatch$options$p : router.options.defaultPendingMs;
|
|
1482
|
-
const pendingMinMs = (_routeMatch$options$p2 = routeMatch.options.pendingMinMs) != null ? _routeMatch$options$p2 : router.options.defaultPendingMinMs;
|
|
1483
|
-
|
|
1484
|
-
if (routeMatch.__.pendingTimeout || routeMatch.status !== 'loading' || typeof pendingMs === 'undefined') {
|
|
1485
|
-
return;
|
|
1486
|
-
}
|
|
1487
|
-
|
|
1488
|
-
routeMatch.__.pendingTimeout = setTimeout(() => {
|
|
1489
|
-
routeMatch.isPending = true;
|
|
1490
|
-
|
|
1491
|
-
routeMatch.__.resolve();
|
|
1492
|
-
|
|
1493
|
-
if (typeof pendingMinMs !== 'undefined') {
|
|
1494
|
-
routeMatch.__.pendingMinPromise = new Promise(r => routeMatch.__.pendingMinTimeout = setTimeout(r, pendingMinMs));
|
|
1495
|
-
}
|
|
1496
|
-
}, pendingMs);
|
|
1497
|
-
},
|
|
1498
|
-
cancelPending: () => {
|
|
1499
|
-
routeMatch.isPending = false;
|
|
1500
|
-
clearTimeout(routeMatch.__.pendingTimeout);
|
|
1501
|
-
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
1502
|
-
delete routeMatch.__.pendingMinPromise;
|
|
1503
|
-
},
|
|
1504
|
-
// setParentMatch: (parentMatch?: RouteMatch) => {
|
|
1505
|
-
// routeMatch.parentMatch = parentMatch
|
|
1506
|
-
// },
|
|
1507
|
-
// addChildMatch: (childMatch: RouteMatch) => {
|
|
1508
|
-
// if (
|
|
1509
|
-
// routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
|
|
1510
|
-
// ) {
|
|
1511
|
-
// return
|
|
1512
|
-
// }
|
|
1513
|
-
// routeMatch.childMatches.push(childMatch)
|
|
1514
|
-
// },
|
|
1515
1473
|
validate: () => {
|
|
1516
1474
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1517
1475
|
|
|
@@ -1519,9 +1477,11 @@
|
|
|
1519
1477
|
const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
|
|
1520
1478
|
|
|
1521
1479
|
try {
|
|
1480
|
+
var _validator;
|
|
1481
|
+
|
|
1522
1482
|
const prevSearch = routeMatch.routeSearch;
|
|
1523
1483
|
const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
|
|
1524
|
-
let nextSearch = replaceEqualDeep(prevSearch, validator == null ? void 0 : validator(parentSearch)); // Invalidate route matches when search param stability changes
|
|
1484
|
+
let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {}); // Invalidate route matches when search param stability changes
|
|
1525
1485
|
|
|
1526
1486
|
if (prevSearch !== nextSearch) {
|
|
1527
1487
|
routeMatch.isInvalid = true;
|
|
@@ -1529,6 +1489,13 @@
|
|
|
1529
1489
|
|
|
1530
1490
|
routeMatch.routeSearch = nextSearch;
|
|
1531
1491
|
routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
|
|
1492
|
+
componentTypes.map(async type => {
|
|
1493
|
+
const component = routeMatch.options[type];
|
|
1494
|
+
|
|
1495
|
+
if (typeof routeMatch.__[type] !== 'function') {
|
|
1496
|
+
routeMatch.__[type] = component;
|
|
1497
|
+
}
|
|
1498
|
+
});
|
|
1532
1499
|
} catch (err) {
|
|
1533
1500
|
console.error(err);
|
|
1534
1501
|
const error = new Error('Invalid search params found', {
|
|
@@ -1546,14 +1513,16 @@
|
|
|
1546
1513
|
var _routeMatch$__$abortC;
|
|
1547
1514
|
|
|
1548
1515
|
(_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
|
|
1549
|
-
|
|
1550
|
-
routeMatch.__.cancelPending();
|
|
1551
1516
|
},
|
|
1552
1517
|
invalidate: () => {
|
|
1553
1518
|
routeMatch.isInvalid = true;
|
|
1554
1519
|
},
|
|
1555
1520
|
hasLoaders: () => {
|
|
1556
|
-
return !!(route.options.loader ||
|
|
1521
|
+
return !!(route.options.loader || componentTypes.some(d => {
|
|
1522
|
+
var _route$options$d;
|
|
1523
|
+
|
|
1524
|
+
return (_route$options$d = route.options[d]) == null ? void 0 : _route$options$d.preload;
|
|
1525
|
+
}));
|
|
1557
1526
|
},
|
|
1558
1527
|
load: async loaderOpts => {
|
|
1559
1528
|
const now = Date.now();
|
|
@@ -1574,17 +1543,25 @@
|
|
|
1574
1543
|
|
|
1575
1544
|
if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
|
|
1576
1545
|
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
1577
|
-
routeMatch.fetch({
|
|
1546
|
+
await routeMatch.fetch({
|
|
1578
1547
|
maxAge
|
|
1579
1548
|
});
|
|
1580
1549
|
}
|
|
1581
1550
|
},
|
|
1582
1551
|
fetch: async opts => {
|
|
1583
|
-
const
|
|
1584
|
-
routeMatch.__.latestId =
|
|
1552
|
+
const loadId = '' + Date.now() + Math.random();
|
|
1553
|
+
routeMatch.__.latestId = loadId;
|
|
1554
|
+
|
|
1555
|
+
const checkLatest = async () => {
|
|
1556
|
+
if (loadId !== routeMatch.__.latestId) {
|
|
1557
|
+
// warning(true, 'Data loader is out of date!')
|
|
1558
|
+
return new Promise(() => {});
|
|
1559
|
+
}
|
|
1560
|
+
}; // If the match was in an error state, set it
|
|
1585
1561
|
// to a loading state again. Otherwise, keep it
|
|
1586
1562
|
// as loading or resolved
|
|
1587
1563
|
|
|
1564
|
+
|
|
1588
1565
|
if (routeMatch.status === 'idle') {
|
|
1589
1566
|
routeMatch.status = 'loading';
|
|
1590
1567
|
} // We started loading the route, so it's no longer invalid
|
|
@@ -1597,94 +1574,66 @@
|
|
|
1597
1574
|
routeMatch.isFetching = true;
|
|
1598
1575
|
routeMatch.__.resolve = resolve;
|
|
1599
1576
|
|
|
1600
|
-
|
|
1601
|
-
//
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
await Promise.all(elementTypes.map(async type => {
|
|
1606
|
-
const routeElement = routeMatch.options[type];
|
|
1607
|
-
|
|
1608
|
-
if (routeMatch.__[type]) {
|
|
1609
|
-
return;
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
routeMatch.__[type] = await router.options.createElement(routeElement);
|
|
1613
|
-
}));
|
|
1614
|
-
})();
|
|
1615
|
-
|
|
1616
|
-
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1617
|
-
try {
|
|
1618
|
-
var _ref, _ref2, _opts$maxAge;
|
|
1577
|
+
routeMatch.__.componentsPromise = (async () => {
|
|
1578
|
+
// then run all component and data loaders in parallel
|
|
1579
|
+
// For each component type, potentially load it asynchronously
|
|
1580
|
+
await Promise.all(componentTypes.map(async type => {
|
|
1581
|
+
var _routeMatch$__$type;
|
|
1619
1582
|
|
|
1620
|
-
|
|
1621
|
-
const data = await routeMatch.options.loader({
|
|
1622
|
-
params: routeMatch.params,
|
|
1623
|
-
search: routeMatch.routeSearch,
|
|
1624
|
-
signal: routeMatch.__.abortController.signal
|
|
1625
|
-
});
|
|
1583
|
+
const component = routeMatch.options[type];
|
|
1626
1584
|
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
|
-
routeMatch.error = undefined;
|
|
1635
|
-
routeMatch.status = 'success';
|
|
1636
|
-
routeMatch.updatedAt = Date.now();
|
|
1637
|
-
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);
|
|
1638
|
-
} catch (err) {
|
|
1639
|
-
if (id !== routeMatch.__.latestId) {
|
|
1640
|
-
return routeMatch.__.loaderPromise;
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
{
|
|
1644
|
-
console.error(err);
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
routeMatch.error = err;
|
|
1648
|
-
routeMatch.status = 'error';
|
|
1649
|
-
routeMatch.updatedAt = Date.now();
|
|
1585
|
+
if ((_routeMatch$__$type = routeMatch.__[type]) != null && _routeMatch$__$type.preload) {
|
|
1586
|
+
routeMatch.__[type] = await router.options.loadComponent(component);
|
|
1650
1587
|
}
|
|
1651
|
-
});
|
|
1588
|
+
}));
|
|
1589
|
+
})();
|
|
1652
1590
|
|
|
1591
|
+
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1653
1592
|
try {
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
if (id !== routeMatch.__.latestId) {
|
|
1657
|
-
return routeMatch.__.loaderPromise;
|
|
1658
|
-
}
|
|
1593
|
+
var _ref, _ref2, _opts$maxAge;
|
|
1659
1594
|
|
|
1660
|
-
if (routeMatch.
|
|
1661
|
-
await routeMatch
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
} finally {
|
|
1665
|
-
if (id !== routeMatch.__.latestId) {
|
|
1666
|
-
return routeMatch.__.loaderPromise;
|
|
1595
|
+
if (routeMatch.options.loader) {
|
|
1596
|
+
const data = await router.loadMatchData(routeMatch);
|
|
1597
|
+
await checkLatest();
|
|
1598
|
+
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1667
1599
|
}
|
|
1668
1600
|
|
|
1669
|
-
routeMatch.
|
|
1601
|
+
routeMatch.error = undefined;
|
|
1602
|
+
routeMatch.status = 'success';
|
|
1603
|
+
routeMatch.updatedAt = Date.now();
|
|
1604
|
+
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);
|
|
1605
|
+
return routeMatch.routeLoaderData;
|
|
1606
|
+
} catch (err) {
|
|
1607
|
+
await checkLatest();
|
|
1670
1608
|
|
|
1671
|
-
|
|
1672
|
-
|
|
1609
|
+
{
|
|
1610
|
+
console.error(err);
|
|
1611
|
+
}
|
|
1673
1612
|
|
|
1674
|
-
routeMatch.
|
|
1613
|
+
routeMatch.error = err;
|
|
1614
|
+
routeMatch.status = 'error';
|
|
1615
|
+
routeMatch.updatedAt = Date.now();
|
|
1616
|
+
throw err;
|
|
1675
1617
|
}
|
|
1676
|
-
})
|
|
1618
|
+
});
|
|
1677
1619
|
|
|
1678
|
-
|
|
1679
|
-
|
|
1620
|
+
const after = async () => {
|
|
1621
|
+
await checkLatest();
|
|
1622
|
+
routeMatch.isFetching = false;
|
|
1623
|
+
delete routeMatch.__.loadPromise;
|
|
1680
1624
|
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
}
|
|
1625
|
+
routeMatch.__.notify();
|
|
1626
|
+
};
|
|
1684
1627
|
|
|
1685
|
-
|
|
1628
|
+
try {
|
|
1629
|
+
await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise.catch(() => {})]);
|
|
1630
|
+
after();
|
|
1631
|
+
} catch (_unused) {
|
|
1632
|
+
after();
|
|
1633
|
+
}
|
|
1686
1634
|
});
|
|
1687
|
-
|
|
1635
|
+
await routeMatch.__.loadPromise;
|
|
1636
|
+
await checkLatest();
|
|
1688
1637
|
}
|
|
1689
1638
|
});
|
|
1690
1639
|
|
|
@@ -1745,9 +1694,22 @@
|
|
|
1745
1694
|
|
|
1746
1695
|
var _window$document;
|
|
1747
1696
|
// Detect if we're in the DOM
|
|
1748
|
-
const isServer =
|
|
1697
|
+
const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement); // This is the default history object if none is defined
|
|
1698
|
+
|
|
1699
|
+
const createDefaultHistory = () => isServer ? createMemoryHistory() : createBrowserHistory();
|
|
1749
1700
|
|
|
1750
|
-
|
|
1701
|
+
function getInitialRouterState() {
|
|
1702
|
+
return {
|
|
1703
|
+
status: 'idle',
|
|
1704
|
+
location: null,
|
|
1705
|
+
matches: [],
|
|
1706
|
+
actions: {},
|
|
1707
|
+
loaders: {},
|
|
1708
|
+
lastUpdated: Date.now(),
|
|
1709
|
+
isFetching: false,
|
|
1710
|
+
isPreloading: false
|
|
1711
|
+
};
|
|
1712
|
+
}
|
|
1751
1713
|
|
|
1752
1714
|
function createRouter(userOptions) {
|
|
1753
1715
|
var _userOptions$stringif, _userOptions$parseSea;
|
|
@@ -1765,30 +1727,24 @@
|
|
|
1765
1727
|
});
|
|
1766
1728
|
|
|
1767
1729
|
let router = {
|
|
1730
|
+
types: undefined,
|
|
1731
|
+
// public api
|
|
1768
1732
|
history,
|
|
1769
1733
|
options: originalOptions,
|
|
1770
1734
|
listeners: [],
|
|
1771
|
-
removeActionQueue: [],
|
|
1772
1735
|
// Resolved after construction
|
|
1773
1736
|
basepath: '',
|
|
1774
1737
|
routeTree: undefined,
|
|
1775
1738
|
routesById: {},
|
|
1776
1739
|
location: undefined,
|
|
1777
|
-
allRouteInfo: undefined,
|
|
1778
1740
|
//
|
|
1779
1741
|
navigationPromise: Promise.resolve(),
|
|
1780
1742
|
resolveNavigation: () => {},
|
|
1781
1743
|
matchCache: {},
|
|
1782
|
-
state:
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
actions: {},
|
|
1787
|
-
loaders: {},
|
|
1788
|
-
loaderData: {},
|
|
1789
|
-
lastUpdated: Date.now(),
|
|
1790
|
-
isFetching: false,
|
|
1791
|
-
isPreloading: false
|
|
1744
|
+
state: getInitialRouterState(),
|
|
1745
|
+
reset: () => {
|
|
1746
|
+
router.state = getInitialRouterState();
|
|
1747
|
+
router.notify();
|
|
1792
1748
|
},
|
|
1793
1749
|
startedLoadingAt: Date.now(),
|
|
1794
1750
|
subscribe: listener => {
|
|
@@ -1801,13 +1757,39 @@
|
|
|
1801
1757
|
return router.routesById[id];
|
|
1802
1758
|
},
|
|
1803
1759
|
notify: () => {
|
|
1804
|
-
router.state
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1760
|
+
const isFetching = router.state.status === 'loading' || router.state.matches.some(d => d.isFetching);
|
|
1761
|
+
const isPreloading = Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId));
|
|
1762
|
+
|
|
1763
|
+
if (router.state.isFetching !== isFetching || router.state.isPreloading !== isPreloading) {
|
|
1764
|
+
router.state = _extends({}, router.state, {
|
|
1765
|
+
isFetching,
|
|
1766
|
+
isPreloading
|
|
1767
|
+
});
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1808
1770
|
cascadeLoaderData(router.state.matches);
|
|
1809
1771
|
router.listeners.forEach(listener => listener(router));
|
|
1810
1772
|
},
|
|
1773
|
+
dehydrateState: () => {
|
|
1774
|
+
return _extends({}, pick(router.state, ['status', 'location', 'lastUpdated']), {
|
|
1775
|
+
matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
|
|
1776
|
+
});
|
|
1777
|
+
},
|
|
1778
|
+
hydrateState: dehydratedState => {
|
|
1779
|
+
// Match the routes
|
|
1780
|
+
const matches = router.matchRoutes(router.location.pathname, {
|
|
1781
|
+
strictParseParams: true
|
|
1782
|
+
});
|
|
1783
|
+
matches.forEach((match, index) => {
|
|
1784
|
+
const dehydratedMatch = dehydratedState.matches[index];
|
|
1785
|
+
invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
|
|
1786
|
+
Object.assign(match, dehydratedMatch);
|
|
1787
|
+
});
|
|
1788
|
+
matches.forEach(match => match.__.validate());
|
|
1789
|
+
router.state = _extends({}, router.state, dehydratedState, {
|
|
1790
|
+
matches
|
|
1791
|
+
});
|
|
1792
|
+
},
|
|
1811
1793
|
mount: () => {
|
|
1812
1794
|
const next = router.__.buildLocation({
|
|
1813
1795
|
to: '.',
|
|
@@ -1819,12 +1801,14 @@
|
|
|
1819
1801
|
|
|
1820
1802
|
if (next.href !== router.location.href) {
|
|
1821
1803
|
router.__.commitLocation(next, true);
|
|
1822
|
-
} else {
|
|
1823
|
-
router.loadLocation();
|
|
1824
1804
|
}
|
|
1825
1805
|
|
|
1826
|
-
|
|
1827
|
-
router.
|
|
1806
|
+
if (!router.state.matches.length) {
|
|
1807
|
+
router.load();
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
const unsub = router.history.listen(event => {
|
|
1811
|
+
router.load(router.__.parseLocation(event.location, router.location));
|
|
1828
1812
|
}); // addEventListener does not exist in React Native, but window does
|
|
1829
1813
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1830
1814
|
|
|
@@ -1835,16 +1819,30 @@
|
|
|
1835
1819
|
}
|
|
1836
1820
|
|
|
1837
1821
|
return () => {
|
|
1838
|
-
unsub();
|
|
1822
|
+
unsub();
|
|
1839
1823
|
|
|
1840
|
-
window.removeEventListener
|
|
1841
|
-
|
|
1824
|
+
if (!isServer && window.removeEventListener) {
|
|
1825
|
+
// Be sure to unsubscribe if a new handler is set
|
|
1826
|
+
window.removeEventListener('visibilitychange', router.onFocus);
|
|
1827
|
+
window.removeEventListener('focus', router.onFocus);
|
|
1828
|
+
}
|
|
1842
1829
|
};
|
|
1843
1830
|
},
|
|
1844
1831
|
onFocus: () => {
|
|
1845
|
-
router.
|
|
1832
|
+
router.load();
|
|
1846
1833
|
},
|
|
1847
1834
|
update: opts => {
|
|
1835
|
+
const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
|
|
1836
|
+
|
|
1837
|
+
if (!router.location || newHistory) {
|
|
1838
|
+
if (opts != null && opts.history) {
|
|
1839
|
+
router.history = opts.history;
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
router.location = router.__.parseLocation(router.history.location);
|
|
1843
|
+
router.state.location = router.location;
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1848
1846
|
Object.assign(router.options, opts);
|
|
1849
1847
|
const {
|
|
1850
1848
|
basepath,
|
|
@@ -1865,49 +1863,41 @@
|
|
|
1865
1863
|
match.cancel();
|
|
1866
1864
|
});
|
|
1867
1865
|
},
|
|
1868
|
-
|
|
1866
|
+
load: async next => {
|
|
1869
1867
|
const id = Math.random();
|
|
1870
1868
|
router.startedLoadingAt = id;
|
|
1871
1869
|
|
|
1872
1870
|
if (next) {
|
|
1873
1871
|
// Ingest the new location
|
|
1874
1872
|
router.location = next;
|
|
1875
|
-
} //
|
|
1873
|
+
} // Cancel any pending matches
|
|
1876
1874
|
|
|
1877
1875
|
|
|
1878
|
-
router.removeActionQueue.forEach(_ref => {
|
|
1879
|
-
let {
|
|
1880
|
-
action,
|
|
1881
|
-
actionState
|
|
1882
|
-
} = _ref;
|
|
1883
|
-
|
|
1884
|
-
if (router.state.currentAction === actionState) {
|
|
1885
|
-
router.state.currentAction = undefined;
|
|
1886
|
-
}
|
|
1887
|
-
|
|
1888
|
-
if (action.current === actionState) {
|
|
1889
|
-
action.current = undefined;
|
|
1890
|
-
}
|
|
1891
|
-
});
|
|
1892
|
-
router.removeActionQueue = []; // Cancel any pending matches
|
|
1893
|
-
|
|
1894
1876
|
router.cancelMatches(); // Match the routes
|
|
1895
1877
|
|
|
1896
|
-
const matches = router.matchRoutes(location.pathname, {
|
|
1878
|
+
const matches = router.matchRoutes(router.location.pathname, {
|
|
1897
1879
|
strictParseParams: true
|
|
1898
1880
|
});
|
|
1899
|
-
|
|
1900
|
-
|
|
1881
|
+
|
|
1882
|
+
if (typeof document !== 'undefined') {
|
|
1883
|
+
router.state = _extends({}, router.state, {
|
|
1884
|
+
pending: {
|
|
1885
|
+
matches: matches,
|
|
1886
|
+
location: router.location
|
|
1887
|
+
},
|
|
1888
|
+
status: 'loading'
|
|
1889
|
+
});
|
|
1890
|
+
} else {
|
|
1891
|
+
router.state = _extends({}, router.state, {
|
|
1901
1892
|
matches: matches,
|
|
1902
|
-
location: router.location
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
}
|
|
1893
|
+
location: router.location,
|
|
1894
|
+
status: 'loading'
|
|
1895
|
+
});
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1906
1898
|
router.notify(); // Load the matches
|
|
1907
1899
|
|
|
1908
|
-
await router.loadMatches(matches
|
|
1909
|
-
withPending: true
|
|
1910
|
-
});
|
|
1900
|
+
await router.loadMatches(matches);
|
|
1911
1901
|
|
|
1912
1902
|
if (router.startedLoadingAt !== id) {
|
|
1913
1903
|
// Ignore side-effects of match loading
|
|
@@ -1924,9 +1914,12 @@
|
|
|
1924
1914
|
exiting.push(d);
|
|
1925
1915
|
}
|
|
1926
1916
|
});
|
|
1917
|
+
const entering = matches.filter(d => {
|
|
1918
|
+
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
1919
|
+
});
|
|
1927
1920
|
const now = Date.now();
|
|
1928
1921
|
exiting.forEach(d => {
|
|
1929
|
-
var
|
|
1922
|
+
var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
|
|
1930
1923
|
|
|
1931
1924
|
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
1932
1925
|
params: d.params,
|
|
@@ -1938,7 +1931,7 @@
|
|
|
1938
1931
|
d.error = undefined;
|
|
1939
1932
|
}
|
|
1940
1933
|
|
|
1941
|
-
const gc = Math.max((
|
|
1934
|
+
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);
|
|
1942
1935
|
|
|
1943
1936
|
if (gc > 0) {
|
|
1944
1937
|
router.matchCache[d.matchId] = {
|
|
@@ -1953,9 +1946,6 @@
|
|
|
1953
1946
|
search: d.routeSearch
|
|
1954
1947
|
});
|
|
1955
1948
|
});
|
|
1956
|
-
const entering = matches.filter(d => {
|
|
1957
|
-
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
1958
|
-
});
|
|
1959
1949
|
entering.forEach(d => {
|
|
1960
1950
|
d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
|
|
1961
1951
|
params: d.params,
|
|
@@ -1964,16 +1954,18 @@
|
|
|
1964
1954
|
delete router.matchCache[d.matchId];
|
|
1965
1955
|
});
|
|
1966
1956
|
|
|
1967
|
-
if (matches.some(d => d.status === 'loading')) {
|
|
1968
|
-
router.notify();
|
|
1969
|
-
await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
|
|
1970
|
-
}
|
|
1971
|
-
|
|
1972
1957
|
if (router.startedLoadingAt !== id) {
|
|
1973
1958
|
// Ignore side-effects of match loading
|
|
1974
1959
|
return;
|
|
1975
1960
|
}
|
|
1976
1961
|
|
|
1962
|
+
matches.forEach(match => {
|
|
1963
|
+
// Clear actions
|
|
1964
|
+
if (match.action) {
|
|
1965
|
+
match.action.current = undefined;
|
|
1966
|
+
match.action.submissions = [];
|
|
1967
|
+
}
|
|
1968
|
+
});
|
|
1977
1969
|
router.state = _extends({}, router.state, {
|
|
1978
1970
|
location: router.location,
|
|
1979
1971
|
matches,
|
|
@@ -2014,7 +2006,7 @@
|
|
|
2014
2006
|
return matches;
|
|
2015
2007
|
},
|
|
2016
2008
|
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
2017
|
-
var
|
|
2009
|
+
var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
|
|
2018
2010
|
|
|
2019
2011
|
if (navigateOpts === void 0) {
|
|
2020
2012
|
navigateOpts = router.location;
|
|
@@ -2026,8 +2018,8 @@
|
|
|
2026
2018
|
});
|
|
2027
2019
|
await router.loadMatches(matches, {
|
|
2028
2020
|
preload: true,
|
|
2029
|
-
maxAge: (
|
|
2030
|
-
gcMaxAge: (
|
|
2021
|
+
maxAge: (_ref3 = (_ref4 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref4 : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0,
|
|
2022
|
+
gcMaxAge: (_ref5 = (_ref6 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref6 : router.options.defaultLoaderGcMaxAge) != null ? _ref5 : 0
|
|
2031
2023
|
});
|
|
2032
2024
|
return matches;
|
|
2033
2025
|
},
|
|
@@ -2103,6 +2095,7 @@
|
|
|
2103
2095
|
const interpolatedPath = interpolatePath(foundRoute.routePath, params);
|
|
2104
2096
|
const matchId = interpolatePath(foundRoute.routeId, params, true);
|
|
2105
2097
|
const match = existingMatches.find(d => d.matchId === matchId) || ((_router$matchCache$ma = router.matchCache[matchId]) == null ? void 0 : _router$matchCache$ma.match) || createRouteMatch(router, foundRoute, {
|
|
2098
|
+
parentMatch,
|
|
2106
2099
|
matchId,
|
|
2107
2100
|
params,
|
|
2108
2101
|
pathname: joinPaths([pathname, interpolatedPath])
|
|
@@ -2126,18 +2119,51 @@
|
|
|
2126
2119
|
match.__.validate();
|
|
2127
2120
|
|
|
2128
2121
|
match.load(loaderOpts);
|
|
2122
|
+
const search = match.search;
|
|
2129
2123
|
|
|
2130
|
-
if (
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
// This might be completion, error, or a pending state
|
|
2124
|
+
if (search.__data && search.__data.matchId !== match.matchId) {
|
|
2125
|
+
return;
|
|
2126
|
+
}
|
|
2134
2127
|
|
|
2128
|
+
if (match.__.loadPromise) {
|
|
2129
|
+
// Wait for the first sign of activity from the match
|
|
2135
2130
|
await match.__.loadPromise;
|
|
2136
2131
|
}
|
|
2137
2132
|
});
|
|
2138
2133
|
router.notify();
|
|
2139
2134
|
await Promise.all(matchPromises);
|
|
2140
2135
|
},
|
|
2136
|
+
loadMatchData: async routeMatch => {
|
|
2137
|
+
if (isServer || !router.options.useServerData) {
|
|
2138
|
+
var _await$routeMatch$opt;
|
|
2139
|
+
|
|
2140
|
+
return (_await$routeMatch$opt = await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
|
|
2141
|
+
// parentLoaderPromise: routeMatch.parentMatch?.__.dataPromise,
|
|
2142
|
+
params: routeMatch.params,
|
|
2143
|
+
search: routeMatch.routeSearch,
|
|
2144
|
+
signal: routeMatch.__.abortController.signal
|
|
2145
|
+
}))) != null ? _await$routeMatch$opt : {};
|
|
2146
|
+
} else {
|
|
2147
|
+
const next = router.buildNext({
|
|
2148
|
+
to: '.',
|
|
2149
|
+
search: d => _extends({}, d != null ? d : {}, {
|
|
2150
|
+
__data: {
|
|
2151
|
+
matchId: routeMatch.matchId
|
|
2152
|
+
}
|
|
2153
|
+
})
|
|
2154
|
+
});
|
|
2155
|
+
const res = await fetch(next.href, {
|
|
2156
|
+
method: 'GET' // signal: routeMatch.__.abortController.signal,
|
|
2157
|
+
|
|
2158
|
+
});
|
|
2159
|
+
|
|
2160
|
+
if (res.ok) {
|
|
2161
|
+
return res.json();
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
throw new Error('Failed to fetch match data');
|
|
2165
|
+
}
|
|
2166
|
+
},
|
|
2141
2167
|
invalidateRoute: opts => {
|
|
2142
2168
|
var _router$state$pending5, _router$state$pending6;
|
|
2143
2169
|
|
|
@@ -2182,7 +2208,7 @@
|
|
|
2182
2208
|
to: next.pathname
|
|
2183
2209
|
}));
|
|
2184
2210
|
},
|
|
2185
|
-
navigate: async
|
|
2211
|
+
navigate: async _ref7 => {
|
|
2186
2212
|
let {
|
|
2187
2213
|
from,
|
|
2188
2214
|
to = '.',
|
|
@@ -2190,7 +2216,7 @@
|
|
|
2190
2216
|
hash,
|
|
2191
2217
|
replace,
|
|
2192
2218
|
params
|
|
2193
|
-
} =
|
|
2219
|
+
} = _ref7;
|
|
2194
2220
|
// If this link simply reloads the current route,
|
|
2195
2221
|
// make sure it has a new key so it will trigger a data refresh
|
|
2196
2222
|
// If this `to` is a valid external URL, return
|
|
@@ -2214,8 +2240,8 @@
|
|
|
2214
2240
|
params
|
|
2215
2241
|
});
|
|
2216
2242
|
},
|
|
2217
|
-
buildLink:
|
|
2218
|
-
var _preload,
|
|
2243
|
+
buildLink: _ref8 => {
|
|
2244
|
+
var _preload, _ref9;
|
|
2219
2245
|
|
|
2220
2246
|
let {
|
|
2221
2247
|
from,
|
|
@@ -2231,7 +2257,7 @@
|
|
|
2231
2257
|
preloadGcMaxAge: userPreloadGcMaxAge,
|
|
2232
2258
|
preloadDelay: userPreloadDelay,
|
|
2233
2259
|
disabled
|
|
2234
|
-
} =
|
|
2260
|
+
} = _ref8;
|
|
2235
2261
|
|
|
2236
2262
|
// If this link simply reloads the current route,
|
|
2237
2263
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -2255,7 +2281,7 @@
|
|
|
2255
2281
|
};
|
|
2256
2282
|
const next = router.buildNext(nextOpts);
|
|
2257
2283
|
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
2258
|
-
const preloadDelay = (
|
|
2284
|
+
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0; // Compare path/hash for matches
|
|
2259
2285
|
|
|
2260
2286
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
2261
2287
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
@@ -2356,11 +2382,7 @@
|
|
|
2356
2382
|
const recurseRoutes = (routeConfigs, parent) => {
|
|
2357
2383
|
return routeConfigs.map(routeConfig => {
|
|
2358
2384
|
const routeOptions = routeConfig.options;
|
|
2359
|
-
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2360
|
-
// pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
|
|
2361
|
-
// pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
|
|
2362
|
-
// }
|
|
2363
|
-
|
|
2385
|
+
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2364
2386
|
const existingRoute = router.routesById[route.routeId];
|
|
2365
2387
|
|
|
2366
2388
|
if (existingRoute) {
|
|
@@ -2470,9 +2492,9 @@
|
|
|
2470
2492
|
pathname: next.pathname,
|
|
2471
2493
|
hash: next.hash,
|
|
2472
2494
|
search: next.searchStr
|
|
2473
|
-
}, {
|
|
2495
|
+
}, _extends({
|
|
2474
2496
|
id
|
|
2475
|
-
});
|
|
2497
|
+
}, next.state));
|
|
2476
2498
|
} else {
|
|
2477
2499
|
history.push({
|
|
2478
2500
|
pathname: next.pathname,
|
|
@@ -2495,8 +2517,6 @@
|
|
|
2495
2517
|
}
|
|
2496
2518
|
}
|
|
2497
2519
|
};
|
|
2498
|
-
router.location = router.__.parseLocation(history.location);
|
|
2499
|
-
router.state.location = router.location;
|
|
2500
2520
|
router.update(userOptions); // Allow frameworks to hook into the router creation
|
|
2501
2521
|
|
|
2502
2522
|
router.options.createRouter == null ? void 0 : router.options.createRouter(router);
|
|
@@ -2507,15 +2527,51 @@
|
|
|
2507
2527
|
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
2508
2528
|
}
|
|
2509
2529
|
|
|
2530
|
+
function cascadeLoaderData(matches) {
|
|
2531
|
+
matches.forEach((match, index) => {
|
|
2532
|
+
const parent = matches[index - 1];
|
|
2533
|
+
|
|
2534
|
+
if (parent) {
|
|
2535
|
+
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
2536
|
+
}
|
|
2537
|
+
});
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2510
2540
|
const _excluded = ["type", "children", "target", "activeProps", "inactiveProps", "activeOptions", "disabled", "hash", "search", "params", "to", "preload", "preloadDelay", "preloadMaxAge", "replace", "style", "className", "onClick", "onFocus", "onMouseEnter", "onMouseLeave", "onTouchStart", "onTouchEnd"],
|
|
2511
2541
|
_excluded2 = ["pending", "caseSensitive", "children"],
|
|
2512
2542
|
_excluded3 = ["children", "router"];
|
|
2543
|
+
function lazy(importer) {
|
|
2544
|
+
const lazyComp = /*#__PURE__*/React__namespace.lazy(importer);
|
|
2545
|
+
let promise;
|
|
2546
|
+
let resolvedComp;
|
|
2547
|
+
const forwardedComp = /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
|
|
2548
|
+
const resolvedCompRef = React__namespace.useRef(resolvedComp || lazyComp);
|
|
2549
|
+
return /*#__PURE__*/React__namespace.createElement(resolvedCompRef.current, _extends$2({}, ref ? {
|
|
2550
|
+
ref
|
|
2551
|
+
} : {}, props));
|
|
2552
|
+
});
|
|
2553
|
+
const finalComp = forwardedComp;
|
|
2554
|
+
|
|
2555
|
+
finalComp.preload = () => {
|
|
2556
|
+
if (!promise) {
|
|
2557
|
+
promise = importer().then(module => {
|
|
2558
|
+
resolvedComp = module.default;
|
|
2559
|
+
return resolvedComp;
|
|
2560
|
+
});
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
return promise;
|
|
2564
|
+
};
|
|
2565
|
+
|
|
2566
|
+
return finalComp;
|
|
2567
|
+
}
|
|
2513
2568
|
//
|
|
2569
|
+
function Link(props) {
|
|
2570
|
+
const router = useRouter();
|
|
2571
|
+
return /*#__PURE__*/React__namespace.createElement(router.Link, props);
|
|
2572
|
+
}
|
|
2514
2573
|
const matchesContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
2515
|
-
const routerContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
2516
|
-
|
|
2517
|
-
const isDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
2518
|
-
const useLayoutEffect = isDOM ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
2574
|
+
const routerContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
2519
2575
|
function MatchesProvider(props) {
|
|
2520
2576
|
return /*#__PURE__*/React__namespace.createElement(matchesContext.Provider, props);
|
|
2521
2577
|
}
|
|
@@ -2579,6 +2635,12 @@
|
|
|
2579
2635
|
next
|
|
2580
2636
|
} = linkInfo;
|
|
2581
2637
|
|
|
2638
|
+
const reactHandleClick = e => {
|
|
2639
|
+
React__namespace.startTransition(() => {
|
|
2640
|
+
handleClick(e);
|
|
2641
|
+
});
|
|
2642
|
+
};
|
|
2643
|
+
|
|
2582
2644
|
const composeHandlers = handlers => e => {
|
|
2583
2645
|
e.persist();
|
|
2584
2646
|
handlers.forEach(handler => {
|
|
@@ -2592,7 +2654,7 @@
|
|
|
2592
2654
|
const resolvedInactiveProps = isActive ? {} : (_functionalUpdate2 = functionalUpdate(inactiveProps, {})) != null ? _functionalUpdate2 : {};
|
|
2593
2655
|
return _extends$2({}, resolvedActiveProps, resolvedInactiveProps, rest, {
|
|
2594
2656
|
href: disabled ? undefined : next.href,
|
|
2595
|
-
onClick: composeHandlers([
|
|
2657
|
+
onClick: composeHandlers([reactHandleClick, onClick]),
|
|
2596
2658
|
onFocus: composeHandlers([handleFocus, onFocus]),
|
|
2597
2659
|
onMouseEnter: composeHandlers([handleEnter, onMouseEnter]),
|
|
2598
2660
|
onMouseLeave: composeHandlers([handleLeave, onMouseLeave]),
|
|
@@ -2645,18 +2707,17 @@
|
|
|
2645
2707
|
useRouterSubscription(router);
|
|
2646
2708
|
return router.state;
|
|
2647
2709
|
},
|
|
2648
|
-
useMatch: routeId => {
|
|
2710
|
+
useMatch: (routeId, opts) => {
|
|
2711
|
+
var _useMatches, _opts$strict;
|
|
2712
|
+
|
|
2649
2713
|
useRouterSubscription(router);
|
|
2650
2714
|
invariant(routeId !== rootRouteId, "\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
|
|
2651
|
-
|
|
2652
|
-
const runtimeMatch = _useMatch();
|
|
2653
|
-
|
|
2715
|
+
const runtimeMatch = (_useMatches = useMatches()) == null ? void 0 : _useMatches[0];
|
|
2654
2716
|
const match = router.state.matches.find(d => d.routeId === routeId);
|
|
2655
|
-
invariant(match, "Could not find a match for route \"" + routeId + "\" being rendered in this component!");
|
|
2656
|
-
invariant(runtimeMatch.routeId == (match == null ? void 0 : match.routeId), "useMatch('" + (match == null ? void 0 : match.routeId) + "') is being called in a component that is meant to render the '" + runtimeMatch.routeId + "' route. Did you mean to 'useRoute(" + (match == null ? void 0 : match.routeId) + ")' instead?");
|
|
2657
2717
|
|
|
2658
|
-
if (
|
|
2659
|
-
invariant(
|
|
2718
|
+
if ((_opts$strict = opts == null ? void 0 : opts.strict) != null ? _opts$strict : true) {
|
|
2719
|
+
invariant(match, "Could not find an active match for \"" + routeId + "\"!");
|
|
2720
|
+
invariant(runtimeMatch.routeId == (match == null ? void 0 : match.routeId), "useMatch(\"" + (match == null ? void 0 : match.routeId) + "\") is being called in a component that is meant to render the '" + runtimeMatch.routeId + "' route. Did you mean to 'useMatch(\"" + (match == null ? void 0 : match.routeId) + "\", { strict: false })' or 'useRoute(\"" + (match == null ? void 0 : match.routeId) + "\")' instead?");
|
|
2660
2721
|
}
|
|
2661
2722
|
|
|
2662
2723
|
return match;
|
|
@@ -2673,18 +2734,12 @@
|
|
|
2673
2734
|
const routeExt = makeRouteExt(route, router);
|
|
2674
2735
|
Object.assign(route, routeExt);
|
|
2675
2736
|
},
|
|
2676
|
-
|
|
2677
|
-
if (typeof
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
if (typeof res === 'object' && res.default) {
|
|
2681
|
-
return /*#__PURE__*/React__namespace.createElement(res.default);
|
|
2682
|
-
} else {
|
|
2683
|
-
return res;
|
|
2684
|
-
}
|
|
2737
|
+
loadComponent: async component => {
|
|
2738
|
+
if (component.preload && typeof document !== 'undefined') {
|
|
2739
|
+
component.preload(); // return await component.preload()
|
|
2685
2740
|
}
|
|
2686
2741
|
|
|
2687
|
-
return
|
|
2742
|
+
return component;
|
|
2688
2743
|
}
|
|
2689
2744
|
}));
|
|
2690
2745
|
return coreRouter;
|
|
@@ -2698,101 +2753,84 @@
|
|
|
2698
2753
|
|
|
2699
2754
|
router.update(rest);
|
|
2700
2755
|
useRouterSubscription(router);
|
|
2701
|
-
|
|
2756
|
+
React__namespace.useEffect(() => {
|
|
2757
|
+
console.log('hello');
|
|
2702
2758
|
return router.mount();
|
|
2703
2759
|
}, [router]);
|
|
2704
2760
|
return /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
|
|
2705
2761
|
value: {
|
|
2706
|
-
router
|
|
2762
|
+
router: router
|
|
2707
2763
|
}
|
|
2708
2764
|
}, /*#__PURE__*/React__namespace.createElement(MatchesProvider, {
|
|
2709
2765
|
value: router.state.matches
|
|
2710
2766
|
}, children != null ? children : /*#__PURE__*/React__namespace.createElement(Outlet, null)));
|
|
2711
2767
|
}
|
|
2712
|
-
|
|
2713
2768
|
function useRouter() {
|
|
2714
2769
|
const value = React__namespace.useContext(routerContext);
|
|
2715
2770
|
warning(!value, 'useRouter must be used inside a <Router> component!');
|
|
2716
2771
|
useRouterSubscription(value.router);
|
|
2717
2772
|
return value.router;
|
|
2718
2773
|
}
|
|
2719
|
-
|
|
2720
2774
|
function useMatches() {
|
|
2721
2775
|
return React__namespace.useContext(matchesContext);
|
|
2722
|
-
} // function useParentMatches(): RouteMatch[] {
|
|
2723
|
-
// const router = useRouter()
|
|
2724
|
-
// const match = useMatch()
|
|
2725
|
-
// const matches = router.state.matches
|
|
2726
|
-
// return matches.slice(
|
|
2727
|
-
// 0,
|
|
2728
|
-
// matches.findIndex((d) => d.matchId === match.matchId) - 1,
|
|
2729
|
-
// )
|
|
2730
|
-
// }
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
function _useMatch() {
|
|
2734
|
-
var _useMatches;
|
|
2735
|
-
|
|
2736
|
-
return (_useMatches = useMatches()) == null ? void 0 : _useMatches[0];
|
|
2737
2776
|
}
|
|
2777
|
+
function useMatch(routeId, opts) {
|
|
2778
|
+
const router = useRouter();
|
|
2779
|
+
return router.useMatch(routeId, opts);
|
|
2780
|
+
}
|
|
2781
|
+
function useNearestMatch() {
|
|
2782
|
+
var _useMatches2;
|
|
2738
2783
|
|
|
2784
|
+
const runtimeMatch = (_useMatches2 = useMatches()) == null ? void 0 : _useMatches2[0];
|
|
2785
|
+
invariant(runtimeMatch, "Could not find a nearest match!");
|
|
2786
|
+
return runtimeMatch;
|
|
2787
|
+
}
|
|
2788
|
+
function useRoute(routeId) {
|
|
2789
|
+
const router = useRouter();
|
|
2790
|
+
return router.useRoute(routeId);
|
|
2791
|
+
}
|
|
2792
|
+
function linkProps(props) {
|
|
2793
|
+
const router = useRouter();
|
|
2794
|
+
return router.linkProps(props);
|
|
2795
|
+
}
|
|
2796
|
+
function MatchRoute(props) {
|
|
2797
|
+
const router = useRouter();
|
|
2798
|
+
return /*#__PURE__*/React__namespace.createElement(router.MatchRoute, props);
|
|
2799
|
+
}
|
|
2739
2800
|
function Outlet() {
|
|
2740
|
-
var
|
|
2801
|
+
var _ref3, _match$__$pendingComp, _match$__$errorCompon;
|
|
2741
2802
|
|
|
2742
2803
|
const router = useRouter();
|
|
2743
|
-
const
|
|
2744
|
-
const
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
const element = (() => {
|
|
2748
|
-
var _childMatch$__$errorE, _ref4;
|
|
2749
|
-
|
|
2750
|
-
if (!childMatch) {
|
|
2751
|
-
return null;
|
|
2752
|
-
}
|
|
2804
|
+
const matches = useMatches().slice(1);
|
|
2805
|
+
const match = matches[0];
|
|
2806
|
+
const defaultPending = React__namespace.useCallback(() => null, []);
|
|
2753
2807
|
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
if (errorElement) {
|
|
2758
|
-
return errorElement;
|
|
2759
|
-
}
|
|
2760
|
-
|
|
2761
|
-
if (childMatch.options.useErrorBoundary || router.options.useErrorBoundary) {
|
|
2762
|
-
throw childMatch.error;
|
|
2763
|
-
}
|
|
2808
|
+
if (!match) {
|
|
2809
|
+
return null;
|
|
2810
|
+
}
|
|
2764
2811
|
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2812
|
+
const PendingComponent = (_ref3 = (_match$__$pendingComp = match.__.pendingComponent) != null ? _match$__$pendingComp : router.options.defaultPendingComponent) != null ? _ref3 : defaultPending;
|
|
2813
|
+
const errorComponent = (_match$__$errorCompon = match.__.errorComponent) != null ? _match$__$errorCompon : router.options.defaultErrorComponent;
|
|
2814
|
+
return /*#__PURE__*/React__namespace.createElement(MatchesProvider, {
|
|
2815
|
+
value: matches
|
|
2816
|
+
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
2817
|
+
fallback: /*#__PURE__*/React__namespace.createElement(PendingComponent, null)
|
|
2818
|
+
}, /*#__PURE__*/React__namespace.createElement(CatchBoundary, {
|
|
2819
|
+
errorComponent: errorComponent
|
|
2820
|
+
}, (() => {
|
|
2821
|
+
if (match.status === 'error') {
|
|
2822
|
+
throw match.error;
|
|
2768
2823
|
}
|
|
2769
2824
|
|
|
2770
|
-
if (
|
|
2771
|
-
|
|
2772
|
-
var _childMatch$__$pendin;
|
|
2773
|
-
|
|
2774
|
-
const pendingElement = (_childMatch$__$pendin = childMatch.__.pendingElement) != null ? _childMatch$__$pendin : router.options.defaultPendingElement;
|
|
2775
|
-
|
|
2776
|
-
if (childMatch.options.pendingMs || pendingElement) {
|
|
2777
|
-
var _ref3;
|
|
2778
|
-
|
|
2779
|
-
return (_ref3 = pendingElement) != null ? _ref3 : null;
|
|
2780
|
-
}
|
|
2781
|
-
}
|
|
2825
|
+
if (match.status === 'success') {
|
|
2826
|
+
var _ref4, _ref5;
|
|
2782
2827
|
|
|
2783
|
-
return null;
|
|
2828
|
+
return /*#__PURE__*/React__namespace.createElement((_ref4 = (_ref5 = match.__.component) != null ? _ref5 : router.options.defaultComponent) != null ? _ref4 : Outlet);
|
|
2784
2829
|
}
|
|
2785
2830
|
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
const catchElement = (_childMatch$options$c = childMatch == null ? void 0 : childMatch.options.catchElement) != null ? _childMatch$options$c : router.options.defaultCatchElement;
|
|
2790
|
-
return /*#__PURE__*/React__namespace.createElement(MatchesProvider, {
|
|
2791
|
-
value: matches,
|
|
2792
|
-
key: childMatch.matchId
|
|
2793
|
-
}, /*#__PURE__*/React__namespace.createElement(CatchBoundary, {
|
|
2794
|
-
catchElement: catchElement
|
|
2795
|
-
}, element));
|
|
2831
|
+
console.log(match.matchId, 'suspend');
|
|
2832
|
+
throw match.__.loadPromise;
|
|
2833
|
+
})())));
|
|
2796
2834
|
}
|
|
2797
2835
|
|
|
2798
2836
|
class CatchBoundary extends React__namespace.Component {
|
|
@@ -2801,13 +2839,6 @@
|
|
|
2801
2839
|
this.state = {
|
|
2802
2840
|
error: false
|
|
2803
2841
|
};
|
|
2804
|
-
|
|
2805
|
-
this.reset = () => {
|
|
2806
|
-
this.setState({
|
|
2807
|
-
error: false,
|
|
2808
|
-
info: false
|
|
2809
|
-
});
|
|
2810
|
-
};
|
|
2811
2842
|
}
|
|
2812
2843
|
|
|
2813
2844
|
componentDidCatch(error, info) {
|
|
@@ -2819,12 +2850,12 @@
|
|
|
2819
2850
|
}
|
|
2820
2851
|
|
|
2821
2852
|
render() {
|
|
2822
|
-
var _this$props$
|
|
2853
|
+
var _this$props$errorComp;
|
|
2823
2854
|
|
|
2824
|
-
const
|
|
2855
|
+
const errorComponent = (_this$props$errorComp = this.props.errorComponent) != null ? _this$props$errorComp : DefaultErrorBoundary;
|
|
2825
2856
|
|
|
2826
2857
|
if (this.state.error) {
|
|
2827
|
-
return
|
|
2858
|
+
return /*#__PURE__*/React__namespace.createElement(errorComponent, this.state);
|
|
2828
2859
|
}
|
|
2829
2860
|
|
|
2830
2861
|
return this.props.children;
|
|
@@ -2832,10 +2863,10 @@
|
|
|
2832
2863
|
|
|
2833
2864
|
}
|
|
2834
2865
|
|
|
2835
|
-
function DefaultErrorBoundary(
|
|
2866
|
+
function DefaultErrorBoundary(_ref6) {
|
|
2836
2867
|
let {
|
|
2837
2868
|
error
|
|
2838
|
-
} =
|
|
2869
|
+
} = _ref6;
|
|
2839
2870
|
return /*#__PURE__*/React__namespace.createElement("div", {
|
|
2840
2871
|
style: {
|
|
2841
2872
|
padding: '.5rem',
|
|
@@ -2857,18 +2888,7 @@
|
|
|
2857
2888
|
padding: '.5rem',
|
|
2858
2889
|
color: 'red'
|
|
2859
2890
|
}
|
|
2860
|
-
}, error.message) : null))
|
|
2861
|
-
style: {
|
|
2862
|
-
height: '1rem'
|
|
2863
|
-
}
|
|
2864
|
-
}), /*#__PURE__*/React__namespace.createElement("div", {
|
|
2865
|
-
style: {
|
|
2866
|
-
fontSize: '.8em',
|
|
2867
|
-
borderLeft: '3px solid rgba(127, 127, 127, 1)',
|
|
2868
|
-
paddingLeft: '.5rem',
|
|
2869
|
-
opacity: 0.5
|
|
2870
|
-
}
|
|
2871
|
-
}, "If you are the owner of this website, it's highly recommended that you configure your own custom Catch/Error boundaries for the router. You can optionally configure a boundary for each route."));
|
|
2891
|
+
}, error.message) : null)));
|
|
2872
2892
|
}
|
|
2873
2893
|
function usePrompt(message, when) {
|
|
2874
2894
|
const router = useRouter();
|
|
@@ -2885,22 +2905,23 @@
|
|
|
2885
2905
|
return unblock;
|
|
2886
2906
|
}, [when, location, message]);
|
|
2887
2907
|
}
|
|
2888
|
-
function Prompt(
|
|
2908
|
+
function Prompt(_ref7) {
|
|
2889
2909
|
let {
|
|
2890
2910
|
message,
|
|
2891
2911
|
when,
|
|
2892
2912
|
children
|
|
2893
|
-
} =
|
|
2913
|
+
} = _ref7;
|
|
2894
2914
|
usePrompt(message, when != null ? when : true);
|
|
2895
2915
|
return children != null ? children : null;
|
|
2896
2916
|
}
|
|
2897
2917
|
|
|
2898
2918
|
exports.DefaultErrorBoundary = DefaultErrorBoundary;
|
|
2919
|
+
exports.Link = Link;
|
|
2920
|
+
exports.MatchRoute = MatchRoute;
|
|
2899
2921
|
exports.MatchesProvider = MatchesProvider;
|
|
2900
2922
|
exports.Outlet = Outlet;
|
|
2901
2923
|
exports.Prompt = Prompt;
|
|
2902
2924
|
exports.RouterProvider = RouterProvider;
|
|
2903
|
-
exports.cascadeLoaderData = cascadeLoaderData;
|
|
2904
2925
|
exports.cleanPath = cleanPath;
|
|
2905
2926
|
exports.createBrowserHistory = createBrowserHistory;
|
|
2906
2927
|
exports.createHashHistory = createHashHistory;
|
|
@@ -2919,18 +2940,28 @@
|
|
|
2919
2940
|
exports.invariant = invariant;
|
|
2920
2941
|
exports.joinPaths = joinPaths;
|
|
2921
2942
|
exports.last = last;
|
|
2943
|
+
exports.lazy = lazy;
|
|
2944
|
+
exports.linkProps = linkProps;
|
|
2922
2945
|
exports.matchByPath = matchByPath;
|
|
2923
2946
|
exports.matchPathname = matchPathname;
|
|
2947
|
+
exports.matchesContext = matchesContext;
|
|
2924
2948
|
exports.parsePathname = parsePathname;
|
|
2925
2949
|
exports.parseSearchWith = parseSearchWith;
|
|
2950
|
+
exports.pick = pick;
|
|
2926
2951
|
exports.replaceEqualDeep = replaceEqualDeep;
|
|
2927
2952
|
exports.resolvePath = resolvePath;
|
|
2928
2953
|
exports.rootRouteId = rootRouteId;
|
|
2954
|
+
exports.routerContext = routerContext;
|
|
2929
2955
|
exports.stringifySearchWith = stringifySearchWith;
|
|
2930
2956
|
exports.trimPath = trimPath;
|
|
2931
2957
|
exports.trimPathLeft = trimPathLeft;
|
|
2932
2958
|
exports.trimPathRight = trimPathRight;
|
|
2959
|
+
exports.useMatch = useMatch;
|
|
2960
|
+
exports.useMatches = useMatches;
|
|
2961
|
+
exports.useNearestMatch = useNearestMatch;
|
|
2933
2962
|
exports.usePrompt = usePrompt;
|
|
2963
|
+
exports.useRoute = useRoute;
|
|
2964
|
+
exports.useRouter = useRouter;
|
|
2934
2965
|
exports.warning = warning;
|
|
2935
2966
|
|
|
2936
2967
|
Object.defineProperty(exports, '__esModule', { value: true });
|