@tanstack/react-router 0.0.1-beta.1 → 0.0.1-beta.10
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 +39 -69
- package/build/cjs/react-router/src/index.js.map +1 -1
- package/build/cjs/router-core/build/esm/index.js +147 -118
- package/build/cjs/router-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +185 -186
- 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 +6 -2
- package/build/umd/index.development.js +185 -186
- 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 -3
- package/src/index.tsx +58 -69
- package/src/qss.ts +0 -53
|
@@ -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) {
|
|
@@ -1462,6 +1457,7 @@
|
|
|
1462
1457
|
isFetching: false,
|
|
1463
1458
|
isInvalid: false,
|
|
1464
1459
|
invalidAt: Infinity,
|
|
1460
|
+
// pendingActions: [],
|
|
1465
1461
|
getIsInvalid: () => {
|
|
1466
1462
|
const now = Date.now();
|
|
1467
1463
|
return routeMatch.isInvalid || routeMatch.invalidAt < now;
|
|
@@ -1501,17 +1497,6 @@
|
|
|
1501
1497
|
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
1502
1498
|
delete routeMatch.__.pendingMinPromise;
|
|
1503
1499
|
},
|
|
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
1500
|
validate: () => {
|
|
1516
1501
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1517
1502
|
|
|
@@ -1519,9 +1504,11 @@
|
|
|
1519
1504
|
const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
|
|
1520
1505
|
|
|
1521
1506
|
try {
|
|
1507
|
+
var _validator;
|
|
1508
|
+
|
|
1522
1509
|
const prevSearch = routeMatch.routeSearch;
|
|
1523
1510
|
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
|
|
1511
|
+
let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {}); // Invalidate route matches when search param stability changes
|
|
1525
1512
|
|
|
1526
1513
|
if (prevSearch !== nextSearch) {
|
|
1527
1514
|
routeMatch.isInvalid = true;
|
|
@@ -1529,6 +1516,13 @@
|
|
|
1529
1516
|
|
|
1530
1517
|
routeMatch.routeSearch = nextSearch;
|
|
1531
1518
|
routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
|
|
1519
|
+
elementTypes.map(async type => {
|
|
1520
|
+
const routeElement = routeMatch.options[type];
|
|
1521
|
+
|
|
1522
|
+
if (typeof routeMatch.__[type] !== 'function') {
|
|
1523
|
+
routeMatch.__[type] = routeElement;
|
|
1524
|
+
}
|
|
1525
|
+
});
|
|
1532
1526
|
} catch (err) {
|
|
1533
1527
|
console.error(err);
|
|
1534
1528
|
const error = new Error('Invalid search params found', {
|
|
@@ -1574,7 +1568,7 @@
|
|
|
1574
1568
|
|
|
1575
1569
|
if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
|
|
1576
1570
|
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
1577
|
-
routeMatch.fetch({
|
|
1571
|
+
await routeMatch.fetch({
|
|
1578
1572
|
maxAge
|
|
1579
1573
|
});
|
|
1580
1574
|
}
|
|
@@ -1597,7 +1591,7 @@
|
|
|
1597
1591
|
routeMatch.isFetching = true;
|
|
1598
1592
|
routeMatch.__.resolve = resolve;
|
|
1599
1593
|
|
|
1600
|
-
|
|
1594
|
+
routeMatch.__.loaderDataPromise = (async () => {
|
|
1601
1595
|
// Load the elements and data in parallel
|
|
1602
1596
|
routeMatch.__.elementsPromise = (async () => {
|
|
1603
1597
|
// then run all element and data loaders in parallel
|
|
@@ -1605,11 +1599,9 @@
|
|
|
1605
1599
|
await Promise.all(elementTypes.map(async type => {
|
|
1606
1600
|
const routeElement = routeMatch.options[type];
|
|
1607
1601
|
|
|
1608
|
-
if (routeMatch.__[type]) {
|
|
1609
|
-
|
|
1602
|
+
if (typeof routeMatch.__[type] === 'function') {
|
|
1603
|
+
routeMatch.__[type] = await router.options.createElement(routeElement);
|
|
1610
1604
|
}
|
|
1611
|
-
|
|
1612
|
-
routeMatch.__[type] = await router.options.createElement(routeElement);
|
|
1613
1605
|
}));
|
|
1614
1606
|
})();
|
|
1615
1607
|
|
|
@@ -1625,7 +1617,7 @@
|
|
|
1625
1617
|
});
|
|
1626
1618
|
|
|
1627
1619
|
if (id !== routeMatch.__.latestId) {
|
|
1628
|
-
return routeMatch.__.
|
|
1620
|
+
return routeMatch.__.loadPromise;
|
|
1629
1621
|
}
|
|
1630
1622
|
|
|
1631
1623
|
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
@@ -1637,7 +1629,7 @@
|
|
|
1637
1629
|
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
1630
|
} catch (err) {
|
|
1639
1631
|
if (id !== routeMatch.__.latestId) {
|
|
1640
|
-
return routeMatch.__.
|
|
1632
|
+
return routeMatch.__.loadPromise;
|
|
1641
1633
|
}
|
|
1642
1634
|
|
|
1643
1635
|
{
|
|
@@ -1654,7 +1646,7 @@
|
|
|
1654
1646
|
await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
|
|
1655
1647
|
|
|
1656
1648
|
if (id !== routeMatch.__.latestId) {
|
|
1657
|
-
return routeMatch.__.
|
|
1649
|
+
return routeMatch.__.loadPromise;
|
|
1658
1650
|
}
|
|
1659
1651
|
|
|
1660
1652
|
if (routeMatch.__.pendingMinPromise) {
|
|
@@ -1663,7 +1655,7 @@
|
|
|
1663
1655
|
}
|
|
1664
1656
|
} finally {
|
|
1665
1657
|
if (id !== routeMatch.__.latestId) {
|
|
1666
|
-
return routeMatch.__.
|
|
1658
|
+
return routeMatch.__.loadPromise;
|
|
1667
1659
|
}
|
|
1668
1660
|
|
|
1669
1661
|
routeMatch.__.cancelPending();
|
|
@@ -1675,16 +1667,16 @@
|
|
|
1675
1667
|
}
|
|
1676
1668
|
})();
|
|
1677
1669
|
|
|
1678
|
-
routeMatch.__.
|
|
1679
|
-
await loaderPromise;
|
|
1670
|
+
await routeMatch.__.loaderDataPromise;
|
|
1680
1671
|
|
|
1681
1672
|
if (id !== routeMatch.__.latestId) {
|
|
1682
|
-
return routeMatch.__.
|
|
1673
|
+
return routeMatch.__.loadPromise;
|
|
1683
1674
|
}
|
|
1684
1675
|
|
|
1685
|
-
delete routeMatch.__.
|
|
1676
|
+
delete routeMatch.__.loaderDataPromise;
|
|
1686
1677
|
});
|
|
1687
|
-
|
|
1678
|
+
await routeMatch.__.loadPromise;
|
|
1679
|
+
delete routeMatch.__.loadPromise;
|
|
1688
1680
|
}
|
|
1689
1681
|
});
|
|
1690
1682
|
|
|
@@ -1745,9 +1737,22 @@
|
|
|
1745
1737
|
|
|
1746
1738
|
var _window$document;
|
|
1747
1739
|
// Detect if we're in the DOM
|
|
1748
|
-
const isServer =
|
|
1740
|
+
const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement); // This is the default history object if none is defined
|
|
1749
1741
|
|
|
1750
|
-
const createDefaultHistory = () =>
|
|
1742
|
+
const createDefaultHistory = () => isServer ? createMemoryHistory() : createBrowserHistory();
|
|
1743
|
+
|
|
1744
|
+
function getInitialRouterState() {
|
|
1745
|
+
return {
|
|
1746
|
+
status: 'idle',
|
|
1747
|
+
location: null,
|
|
1748
|
+
matches: [],
|
|
1749
|
+
actions: {},
|
|
1750
|
+
loaders: {},
|
|
1751
|
+
lastUpdated: Date.now(),
|
|
1752
|
+
isFetching: false,
|
|
1753
|
+
isPreloading: false
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1751
1756
|
|
|
1752
1757
|
function createRouter(userOptions) {
|
|
1753
1758
|
var _userOptions$stringif, _userOptions$parseSea;
|
|
@@ -1768,7 +1773,6 @@
|
|
|
1768
1773
|
history,
|
|
1769
1774
|
options: originalOptions,
|
|
1770
1775
|
listeners: [],
|
|
1771
|
-
removeActionQueue: [],
|
|
1772
1776
|
// Resolved after construction
|
|
1773
1777
|
basepath: '',
|
|
1774
1778
|
routeTree: undefined,
|
|
@@ -1779,16 +1783,10 @@
|
|
|
1779
1783
|
navigationPromise: Promise.resolve(),
|
|
1780
1784
|
resolveNavigation: () => {},
|
|
1781
1785
|
matchCache: {},
|
|
1782
|
-
state:
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
actions: {},
|
|
1787
|
-
loaders: {},
|
|
1788
|
-
loaderData: {},
|
|
1789
|
-
lastUpdated: Date.now(),
|
|
1790
|
-
isFetching: false,
|
|
1791
|
-
isPreloading: false
|
|
1786
|
+
state: getInitialRouterState(),
|
|
1787
|
+
reset: () => {
|
|
1788
|
+
router.state = getInitialRouterState();
|
|
1789
|
+
router.notify();
|
|
1792
1790
|
},
|
|
1793
1791
|
startedLoadingAt: Date.now(),
|
|
1794
1792
|
subscribe: listener => {
|
|
@@ -1806,7 +1804,27 @@
|
|
|
1806
1804
|
isPreloading: Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId))
|
|
1807
1805
|
});
|
|
1808
1806
|
cascadeLoaderData(router.state.matches);
|
|
1809
|
-
router.listeners.forEach(listener => listener());
|
|
1807
|
+
router.listeners.forEach(listener => listener(router));
|
|
1808
|
+
},
|
|
1809
|
+
dehydrateState: () => {
|
|
1810
|
+
return _extends({}, pick(router.state, ['status', 'location', 'lastUpdated']), {
|
|
1811
|
+
matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
|
|
1812
|
+
});
|
|
1813
|
+
},
|
|
1814
|
+
hydrateState: dehydratedState => {
|
|
1815
|
+
// Match the routes
|
|
1816
|
+
const matches = router.matchRoutes(router.location.pathname, {
|
|
1817
|
+
strictParseParams: true
|
|
1818
|
+
});
|
|
1819
|
+
matches.forEach((match, index) => {
|
|
1820
|
+
const dehydratedMatch = dehydratedState.matches[index];
|
|
1821
|
+
invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
|
|
1822
|
+
Object.assign(match, dehydratedMatch);
|
|
1823
|
+
});
|
|
1824
|
+
router.loadMatches(matches);
|
|
1825
|
+
router.state = _extends({}, router.state, dehydratedState, {
|
|
1826
|
+
matches
|
|
1827
|
+
});
|
|
1810
1828
|
},
|
|
1811
1829
|
mount: () => {
|
|
1812
1830
|
const next = router.__.buildLocation({
|
|
@@ -1819,12 +1837,11 @@
|
|
|
1819
1837
|
|
|
1820
1838
|
if (next.href !== router.location.href) {
|
|
1821
1839
|
router.__.commitLocation(next, true);
|
|
1822
|
-
}
|
|
1823
|
-
router.loadLocation();
|
|
1824
|
-
}
|
|
1840
|
+
} // router.load()
|
|
1825
1841
|
|
|
1826
|
-
|
|
1827
|
-
|
|
1842
|
+
|
|
1843
|
+
const unsub = router.history.listen(event => {
|
|
1844
|
+
router.load(router.__.parseLocation(event.location, router.location));
|
|
1828
1845
|
}); // addEventListener does not exist in React Native, but window does
|
|
1829
1846
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1830
1847
|
|
|
@@ -1835,16 +1852,30 @@
|
|
|
1835
1852
|
}
|
|
1836
1853
|
|
|
1837
1854
|
return () => {
|
|
1838
|
-
unsub();
|
|
1855
|
+
unsub();
|
|
1839
1856
|
|
|
1840
|
-
window.removeEventListener
|
|
1841
|
-
|
|
1857
|
+
if (!isServer && window.removeEventListener) {
|
|
1858
|
+
// Be sure to unsubscribe if a new handler is set
|
|
1859
|
+
window.removeEventListener('visibilitychange', router.onFocus);
|
|
1860
|
+
window.removeEventListener('focus', router.onFocus);
|
|
1861
|
+
}
|
|
1842
1862
|
};
|
|
1843
1863
|
},
|
|
1844
1864
|
onFocus: () => {
|
|
1845
|
-
router.
|
|
1865
|
+
router.load();
|
|
1846
1866
|
},
|
|
1847
1867
|
update: opts => {
|
|
1868
|
+
const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
|
|
1869
|
+
|
|
1870
|
+
if (!router.location || newHistory) {
|
|
1871
|
+
if (opts != null && opts.history) {
|
|
1872
|
+
router.history = opts.history;
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
router.location = router.__.parseLocation(router.history.location);
|
|
1876
|
+
router.state.location = router.location;
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1848
1879
|
Object.assign(router.options, opts);
|
|
1849
1880
|
const {
|
|
1850
1881
|
basepath,
|
|
@@ -1865,35 +1896,19 @@
|
|
|
1865
1896
|
match.cancel();
|
|
1866
1897
|
});
|
|
1867
1898
|
},
|
|
1868
|
-
|
|
1899
|
+
load: async next => {
|
|
1869
1900
|
const id = Math.random();
|
|
1870
1901
|
router.startedLoadingAt = id;
|
|
1871
1902
|
|
|
1872
1903
|
if (next) {
|
|
1873
1904
|
// Ingest the new location
|
|
1874
1905
|
router.location = next;
|
|
1875
|
-
} //
|
|
1876
|
-
|
|
1906
|
+
} // Cancel any pending matches
|
|
1877
1907
|
|
|
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
1908
|
|
|
1894
1909
|
router.cancelMatches(); // Match the routes
|
|
1895
1910
|
|
|
1896
|
-
const matches = router.matchRoutes(location.pathname, {
|
|
1911
|
+
const matches = router.matchRoutes(router.location.pathname, {
|
|
1897
1912
|
strictParseParams: true
|
|
1898
1913
|
});
|
|
1899
1914
|
router.state = _extends({}, router.state, {
|
|
@@ -1926,19 +1941,24 @@
|
|
|
1926
1941
|
});
|
|
1927
1942
|
const now = Date.now();
|
|
1928
1943
|
exiting.forEach(d => {
|
|
1929
|
-
var
|
|
1944
|
+
var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
|
|
1930
1945
|
|
|
1931
1946
|
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
1932
1947
|
params: d.params,
|
|
1933
1948
|
search: d.routeSearch
|
|
1934
|
-
}); // Clear
|
|
1949
|
+
}); // // Clear actions
|
|
1950
|
+
// if (d.action) {
|
|
1951
|
+
// d.action.current = undefined
|
|
1952
|
+
// d.action.submissions = []
|
|
1953
|
+
// }
|
|
1954
|
+
// Clear idle error states when match leaves
|
|
1935
1955
|
|
|
1936
1956
|
if (d.status === 'error' && !d.isFetching) {
|
|
1937
1957
|
d.status = 'idle';
|
|
1938
1958
|
d.error = undefined;
|
|
1939
1959
|
}
|
|
1940
1960
|
|
|
1941
|
-
const gc = Math.max((
|
|
1961
|
+
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
1962
|
|
|
1943
1963
|
if (gc > 0) {
|
|
1944
1964
|
router.matchCache[d.matchId] = {
|
|
@@ -1962,18 +1982,20 @@
|
|
|
1962
1982
|
search: d.search
|
|
1963
1983
|
});
|
|
1964
1984
|
delete router.matchCache[d.matchId];
|
|
1965
|
-
});
|
|
1966
|
-
|
|
1967
|
-
if (matches.some(d => d.status === 'loading')) {
|
|
1968
|
-
router.notify();
|
|
1969
|
-
await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
|
|
1970
|
-
}
|
|
1985
|
+
}); // router.notify()
|
|
1971
1986
|
|
|
1972
1987
|
if (router.startedLoadingAt !== id) {
|
|
1973
1988
|
// Ignore side-effects of match loading
|
|
1974
1989
|
return;
|
|
1975
1990
|
}
|
|
1976
1991
|
|
|
1992
|
+
matches.forEach(match => {
|
|
1993
|
+
// Clear actions
|
|
1994
|
+
if (match.action) {
|
|
1995
|
+
match.action.current = undefined;
|
|
1996
|
+
match.action.submissions = [];
|
|
1997
|
+
}
|
|
1998
|
+
});
|
|
1977
1999
|
router.state = _extends({}, router.state, {
|
|
1978
2000
|
location: router.location,
|
|
1979
2001
|
matches,
|
|
@@ -2014,7 +2036,7 @@
|
|
|
2014
2036
|
return matches;
|
|
2015
2037
|
},
|
|
2016
2038
|
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
2017
|
-
var
|
|
2039
|
+
var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
|
|
2018
2040
|
|
|
2019
2041
|
if (navigateOpts === void 0) {
|
|
2020
2042
|
navigateOpts = router.location;
|
|
@@ -2026,8 +2048,8 @@
|
|
|
2026
2048
|
});
|
|
2027
2049
|
await router.loadMatches(matches, {
|
|
2028
2050
|
preload: true,
|
|
2029
|
-
maxAge: (
|
|
2030
|
-
gcMaxAge: (
|
|
2051
|
+
maxAge: (_ref3 = (_ref4 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref4 : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0,
|
|
2052
|
+
gcMaxAge: (_ref5 = (_ref6 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref6 : router.options.defaultLoaderGcMaxAge) != null ? _ref5 : 0
|
|
2031
2053
|
});
|
|
2032
2054
|
return matches;
|
|
2033
2055
|
},
|
|
@@ -2129,9 +2151,12 @@
|
|
|
2129
2151
|
|
|
2130
2152
|
if (match.status === 'loading') {
|
|
2131
2153
|
// If requested, start the pending timers
|
|
2132
|
-
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
|
|
2133
|
-
|
|
2154
|
+
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
|
|
2155
|
+
}
|
|
2134
2156
|
|
|
2157
|
+
if (match.__.loadPromise) {
|
|
2158
|
+
// Wait for the first sign of activity from the match
|
|
2159
|
+
// This might be completion, error, or a pending state
|
|
2135
2160
|
await match.__.loadPromise;
|
|
2136
2161
|
}
|
|
2137
2162
|
});
|
|
@@ -2182,7 +2207,7 @@
|
|
|
2182
2207
|
to: next.pathname
|
|
2183
2208
|
}));
|
|
2184
2209
|
},
|
|
2185
|
-
navigate: async
|
|
2210
|
+
navigate: async _ref7 => {
|
|
2186
2211
|
let {
|
|
2187
2212
|
from,
|
|
2188
2213
|
to = '.',
|
|
@@ -2190,7 +2215,7 @@
|
|
|
2190
2215
|
hash,
|
|
2191
2216
|
replace,
|
|
2192
2217
|
params
|
|
2193
|
-
} =
|
|
2218
|
+
} = _ref7;
|
|
2194
2219
|
// If this link simply reloads the current route,
|
|
2195
2220
|
// make sure it has a new key so it will trigger a data refresh
|
|
2196
2221
|
// If this `to` is a valid external URL, return
|
|
@@ -2214,8 +2239,8 @@
|
|
|
2214
2239
|
params
|
|
2215
2240
|
});
|
|
2216
2241
|
},
|
|
2217
|
-
buildLink:
|
|
2218
|
-
var _preload,
|
|
2242
|
+
buildLink: _ref8 => {
|
|
2243
|
+
var _preload, _ref9;
|
|
2219
2244
|
|
|
2220
2245
|
let {
|
|
2221
2246
|
from,
|
|
@@ -2231,7 +2256,7 @@
|
|
|
2231
2256
|
preloadGcMaxAge: userPreloadGcMaxAge,
|
|
2232
2257
|
preloadDelay: userPreloadDelay,
|
|
2233
2258
|
disabled
|
|
2234
|
-
} =
|
|
2259
|
+
} = _ref8;
|
|
2235
2260
|
|
|
2236
2261
|
// If this link simply reloads the current route,
|
|
2237
2262
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -2255,7 +2280,7 @@
|
|
|
2255
2280
|
};
|
|
2256
2281
|
const next = router.buildNext(nextOpts);
|
|
2257
2282
|
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
2258
|
-
const preloadDelay = (
|
|
2283
|
+
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0; // Compare path/hash for matches
|
|
2259
2284
|
|
|
2260
2285
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
2261
2286
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
@@ -2356,11 +2381,7 @@
|
|
|
2356
2381
|
const recurseRoutes = (routeConfigs, parent) => {
|
|
2357
2382
|
return routeConfigs.map(routeConfig => {
|
|
2358
2383
|
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
|
-
|
|
2384
|
+
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2364
2385
|
const existingRoute = router.routesById[route.routeId];
|
|
2365
2386
|
|
|
2366
2387
|
if (existingRoute) {
|
|
@@ -2495,8 +2516,6 @@
|
|
|
2495
2516
|
}
|
|
2496
2517
|
}
|
|
2497
2518
|
};
|
|
2498
|
-
router.location = router.__.parseLocation(history.location);
|
|
2499
|
-
router.state.location = router.location;
|
|
2500
2519
|
router.update(userOptions); // Allow frameworks to hook into the router creation
|
|
2501
2520
|
|
|
2502
2521
|
router.options.createRouter == null ? void 0 : router.options.createRouter(router);
|
|
@@ -2507,6 +2526,16 @@
|
|
|
2507
2526
|
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
2508
2527
|
}
|
|
2509
2528
|
|
|
2529
|
+
function cascadeLoaderData(matches) {
|
|
2530
|
+
matches.forEach((match, index) => {
|
|
2531
|
+
const parent = matches[index - 1];
|
|
2532
|
+
|
|
2533
|
+
if (parent) {
|
|
2534
|
+
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
2535
|
+
}
|
|
2536
|
+
});
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2510
2539
|
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
2540
|
_excluded2 = ["pending", "caseSensitive", "children"],
|
|
2512
2541
|
_excluded3 = ["children", "router"];
|
|
@@ -2521,7 +2550,7 @@
|
|
|
2521
2550
|
}
|
|
2522
2551
|
|
|
2523
2552
|
const useRouterSubscription = router => {
|
|
2524
|
-
shim.useSyncExternalStore(cb => router.subscribe(() => cb()), () => router.state);
|
|
2553
|
+
shim.useSyncExternalStore(cb => router.subscribe(() => cb()), () => router.state, () => router.state);
|
|
2525
2554
|
};
|
|
2526
2555
|
|
|
2527
2556
|
function createReactRouter(opts) {
|
|
@@ -2645,18 +2674,17 @@
|
|
|
2645
2674
|
useRouterSubscription(router);
|
|
2646
2675
|
return router.state;
|
|
2647
2676
|
},
|
|
2648
|
-
useMatch: routeId => {
|
|
2677
|
+
useMatch: (routeId, opts) => {
|
|
2678
|
+
var _useMatches, _opts$strict;
|
|
2679
|
+
|
|
2649
2680
|
useRouterSubscription(router);
|
|
2650
2681
|
invariant(routeId !== rootRouteId, "\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
|
|
2651
|
-
|
|
2652
|
-
const runtimeMatch = _useMatch();
|
|
2653
|
-
|
|
2682
|
+
const runtimeMatch = (_useMatches = useMatches()) == null ? void 0 : _useMatches[0];
|
|
2654
2683
|
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
2684
|
|
|
2658
|
-
if (
|
|
2659
|
-
invariant(
|
|
2685
|
+
if ((_opts$strict = opts == null ? void 0 : opts.strict) != null ? _opts$strict : true) {
|
|
2686
|
+
invariant(match, "Could not find an active match for \"" + routeId + "\"!");
|
|
2687
|
+
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
2688
|
}
|
|
2661
2689
|
|
|
2662
2690
|
return match;
|
|
@@ -2699,7 +2727,9 @@
|
|
|
2699
2727
|
router.update(rest);
|
|
2700
2728
|
useRouterSubscription(router);
|
|
2701
2729
|
useLayoutEffect(() => {
|
|
2702
|
-
|
|
2730
|
+
const unsub = router.mount();
|
|
2731
|
+
router.load();
|
|
2732
|
+
return unsub;
|
|
2703
2733
|
}, [router]);
|
|
2704
2734
|
return /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
|
|
2705
2735
|
value: {
|
|
@@ -2719,61 +2749,49 @@
|
|
|
2719
2749
|
|
|
2720
2750
|
function useMatches() {
|
|
2721
2751
|
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
2752
|
}
|
|
2738
2753
|
|
|
2739
2754
|
function Outlet() {
|
|
2740
|
-
var
|
|
2755
|
+
var _match$options$catchE;
|
|
2741
2756
|
|
|
2742
2757
|
const router = useRouter();
|
|
2743
|
-
const
|
|
2744
|
-
const
|
|
2745
|
-
|
|
2758
|
+
const matches = useMatches().slice(1);
|
|
2759
|
+
const match = matches[0];
|
|
2760
|
+
|
|
2761
|
+
if (!match) {
|
|
2762
|
+
return null;
|
|
2763
|
+
}
|
|
2746
2764
|
|
|
2747
2765
|
const element = (() => {
|
|
2748
|
-
var
|
|
2766
|
+
var _match$__$errorElemen, _ref4, _ref5;
|
|
2749
2767
|
|
|
2750
|
-
if (!
|
|
2768
|
+
if (!match) {
|
|
2751
2769
|
return null;
|
|
2752
2770
|
}
|
|
2753
2771
|
|
|
2754
|
-
const errorElement = (
|
|
2772
|
+
const errorElement = (_match$__$errorElemen = match.__.errorElement) != null ? _match$__$errorElemen : router.options.defaultErrorElement;
|
|
2755
2773
|
|
|
2756
|
-
if (
|
|
2774
|
+
if (match.status === 'error') {
|
|
2757
2775
|
if (errorElement) {
|
|
2758
2776
|
return errorElement;
|
|
2759
2777
|
}
|
|
2760
2778
|
|
|
2761
|
-
if (
|
|
2762
|
-
throw
|
|
2779
|
+
if (match.options.useErrorBoundary || router.options.useErrorBoundary) {
|
|
2780
|
+
throw match.error;
|
|
2763
2781
|
}
|
|
2764
2782
|
|
|
2765
2783
|
return /*#__PURE__*/React__namespace.createElement(DefaultErrorBoundary, {
|
|
2766
|
-
error:
|
|
2784
|
+
error: match.error
|
|
2767
2785
|
});
|
|
2768
2786
|
}
|
|
2769
2787
|
|
|
2770
|
-
if (
|
|
2771
|
-
if (
|
|
2772
|
-
var
|
|
2788
|
+
if (match.status === 'loading' || match.status === 'idle') {
|
|
2789
|
+
if (match.isPending) {
|
|
2790
|
+
var _match$__$pendingElem;
|
|
2773
2791
|
|
|
2774
|
-
const pendingElement = (
|
|
2792
|
+
const pendingElement = (_match$__$pendingElem = match.__.pendingElement) != null ? _match$__$pendingElem : router.options.defaultPendingElement;
|
|
2775
2793
|
|
|
2776
|
-
if (
|
|
2794
|
+
if (match.options.pendingMs || pendingElement) {
|
|
2777
2795
|
var _ref3;
|
|
2778
2796
|
|
|
2779
2797
|
return (_ref3 = pendingElement) != null ? _ref3 : null;
|
|
@@ -2783,13 +2801,12 @@
|
|
|
2783
2801
|
return null;
|
|
2784
2802
|
}
|
|
2785
2803
|
|
|
2786
|
-
return (_ref4 =
|
|
2804
|
+
return (_ref4 = (_ref5 = match.__.element) != null ? _ref5 : router.options.defaultElement) != null ? _ref4 : /*#__PURE__*/React__namespace.createElement(Outlet, null);
|
|
2787
2805
|
})();
|
|
2788
2806
|
|
|
2789
|
-
const catchElement = (
|
|
2807
|
+
const catchElement = (_match$options$catchE = match == null ? void 0 : match.options.catchElement) != null ? _match$options$catchE : router.options.defaultCatchElement;
|
|
2790
2808
|
return /*#__PURE__*/React__namespace.createElement(MatchesProvider, {
|
|
2791
|
-
value: matches
|
|
2792
|
-
key: childMatch.matchId
|
|
2809
|
+
value: matches
|
|
2793
2810
|
}, /*#__PURE__*/React__namespace.createElement(CatchBoundary, {
|
|
2794
2811
|
catchElement: catchElement
|
|
2795
2812
|
}, element));
|
|
@@ -2801,13 +2818,6 @@
|
|
|
2801
2818
|
this.state = {
|
|
2802
2819
|
error: false
|
|
2803
2820
|
};
|
|
2804
|
-
|
|
2805
|
-
this.reset = () => {
|
|
2806
|
-
this.setState({
|
|
2807
|
-
error: false,
|
|
2808
|
-
info: false
|
|
2809
|
-
});
|
|
2810
|
-
};
|
|
2811
2821
|
}
|
|
2812
2822
|
|
|
2813
2823
|
componentDidCatch(error, info) {
|
|
@@ -2832,10 +2842,10 @@
|
|
|
2832
2842
|
|
|
2833
2843
|
}
|
|
2834
2844
|
|
|
2835
|
-
function DefaultErrorBoundary(
|
|
2845
|
+
function DefaultErrorBoundary(_ref6) {
|
|
2836
2846
|
let {
|
|
2837
2847
|
error
|
|
2838
|
-
} =
|
|
2848
|
+
} = _ref6;
|
|
2839
2849
|
return /*#__PURE__*/React__namespace.createElement("div", {
|
|
2840
2850
|
style: {
|
|
2841
2851
|
padding: '.5rem',
|
|
@@ -2857,18 +2867,7 @@
|
|
|
2857
2867
|
padding: '.5rem',
|
|
2858
2868
|
color: 'red'
|
|
2859
2869
|
}
|
|
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."));
|
|
2870
|
+
}, error.message) : null)));
|
|
2872
2871
|
}
|
|
2873
2872
|
function usePrompt(message, when) {
|
|
2874
2873
|
const router = useRouter();
|
|
@@ -2885,12 +2884,12 @@
|
|
|
2885
2884
|
return unblock;
|
|
2886
2885
|
}, [when, location, message]);
|
|
2887
2886
|
}
|
|
2888
|
-
function Prompt(
|
|
2887
|
+
function Prompt(_ref7) {
|
|
2889
2888
|
let {
|
|
2890
2889
|
message,
|
|
2891
2890
|
when,
|
|
2892
2891
|
children
|
|
2893
|
-
} =
|
|
2892
|
+
} = _ref7;
|
|
2894
2893
|
usePrompt(message, when != null ? when : true);
|
|
2895
2894
|
return children != null ? children : null;
|
|
2896
2895
|
}
|
|
@@ -2900,7 +2899,6 @@
|
|
|
2900
2899
|
exports.Outlet = Outlet;
|
|
2901
2900
|
exports.Prompt = Prompt;
|
|
2902
2901
|
exports.RouterProvider = RouterProvider;
|
|
2903
|
-
exports.cascadeLoaderData = cascadeLoaderData;
|
|
2904
2902
|
exports.cleanPath = cleanPath;
|
|
2905
2903
|
exports.createBrowserHistory = createBrowserHistory;
|
|
2906
2904
|
exports.createHashHistory = createHashHistory;
|
|
@@ -2923,6 +2921,7 @@
|
|
|
2923
2921
|
exports.matchPathname = matchPathname;
|
|
2924
2922
|
exports.parsePathname = parsePathname;
|
|
2925
2923
|
exports.parseSearchWith = parseSearchWith;
|
|
2924
|
+
exports.pick = pick;
|
|
2926
2925
|
exports.replaceEqualDeep = replaceEqualDeep;
|
|
2927
2926
|
exports.resolvePath = resolvePath;
|
|
2928
2927
|
exports.rootRouteId = rootRouteId;
|