@tanstack/react-router 0.0.1-beta.1 → 0.0.1-beta.11
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 +143 -119
- package/build/cjs/router-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +181 -187
- 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 +181 -187
- 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 +4 -3
- package/src/index.tsx +58 -69
- package/src/qss.ts +0 -53
package/build/esm/index.js
CHANGED
|
@@ -975,6 +975,12 @@ function functionalUpdate(updater, previous) {
|
|
|
975
975
|
|
|
976
976
|
return updater;
|
|
977
977
|
}
|
|
978
|
+
function pick(parent, keys) {
|
|
979
|
+
return keys.reduce((obj, key) => {
|
|
980
|
+
obj[key] = parent[key];
|
|
981
|
+
return obj;
|
|
982
|
+
}, {});
|
|
983
|
+
}
|
|
978
984
|
|
|
979
985
|
function joinPaths(paths) {
|
|
980
986
|
return cleanPath(paths.filter(Boolean).join('/'));
|
|
@@ -1201,6 +1207,7 @@ function toValue(mix) {
|
|
|
1201
1207
|
var str = decodeURIComponent(mix);
|
|
1202
1208
|
if (str === 'false') return false;
|
|
1203
1209
|
if (str === 'true') return true;
|
|
1210
|
+
if (str.charAt(0) === '0') return str;
|
|
1204
1211
|
return +str * 0 === 0 ? +str : str;
|
|
1205
1212
|
}
|
|
1206
1213
|
|
|
@@ -1251,7 +1258,7 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1251
1258
|
|
|
1252
1259
|
const action = router.state.actions[id] || (() => {
|
|
1253
1260
|
router.state.actions[id] = {
|
|
1254
|
-
|
|
1261
|
+
submissions: [],
|
|
1255
1262
|
submit: async (submission, actionOpts) => {
|
|
1256
1263
|
var _actionOpts$invalidat;
|
|
1257
1264
|
|
|
@@ -1260,18 +1267,20 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1260
1267
|
}
|
|
1261
1268
|
|
|
1262
1269
|
const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
|
|
1270
|
+
|
|
1271
|
+
if (!(actionOpts != null && actionOpts.multi)) {
|
|
1272
|
+
action.submissions = action.submissions.filter(d => d.isMulti);
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1263
1275
|
const actionState = {
|
|
1264
1276
|
submittedAt: Date.now(),
|
|
1265
1277
|
status: 'pending',
|
|
1266
|
-
submission
|
|
1278
|
+
submission,
|
|
1279
|
+
isMulti: !!(actionOpts != null && actionOpts.multi)
|
|
1267
1280
|
};
|
|
1268
1281
|
action.current = actionState;
|
|
1269
1282
|
action.latest = actionState;
|
|
1270
|
-
action.
|
|
1271
|
-
router.state = _extends({}, router.state, {
|
|
1272
|
-
currentAction: actionState,
|
|
1273
|
-
latestAction: actionState
|
|
1274
|
-
});
|
|
1283
|
+
action.submissions.push(actionState);
|
|
1275
1284
|
router.notify();
|
|
1276
1285
|
|
|
1277
1286
|
try {
|
|
@@ -1293,11 +1302,6 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1293
1302
|
actionState.error = err;
|
|
1294
1303
|
actionState.status = 'error';
|
|
1295
1304
|
} finally {
|
|
1296
|
-
action.pending = action.pending.filter(d => d !== actionState);
|
|
1297
|
-
router.removeActionQueue.push({
|
|
1298
|
-
action,
|
|
1299
|
-
actionState
|
|
1300
|
-
});
|
|
1301
1305
|
router.notify();
|
|
1302
1306
|
}
|
|
1303
1307
|
}
|
|
@@ -1372,15 +1376,6 @@ function createRoute(routeConfig, options, parent, router) {
|
|
|
1372
1376
|
});
|
|
1373
1377
|
return route;
|
|
1374
1378
|
}
|
|
1375
|
-
function cascadeLoaderData(matches) {
|
|
1376
|
-
matches.forEach((match, index) => {
|
|
1377
|
-
const parent = matches[index - 1];
|
|
1378
|
-
|
|
1379
|
-
if (parent) {
|
|
1380
|
-
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
1381
|
-
}
|
|
1382
|
-
});
|
|
1383
|
-
}
|
|
1384
1379
|
|
|
1385
1380
|
const rootRouteId = '__root__';
|
|
1386
1381
|
const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
|
|
@@ -1446,6 +1441,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1446
1441
|
isFetching: false,
|
|
1447
1442
|
isInvalid: false,
|
|
1448
1443
|
invalidAt: Infinity,
|
|
1444
|
+
// pendingActions: [],
|
|
1449
1445
|
getIsInvalid: () => {
|
|
1450
1446
|
const now = Date.now();
|
|
1451
1447
|
return routeMatch.isInvalid || routeMatch.invalidAt < now;
|
|
@@ -1485,17 +1481,6 @@ function createRouteMatch(router, route, opts) {
|
|
|
1485
1481
|
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
1486
1482
|
delete routeMatch.__.pendingMinPromise;
|
|
1487
1483
|
},
|
|
1488
|
-
// setParentMatch: (parentMatch?: RouteMatch) => {
|
|
1489
|
-
// routeMatch.parentMatch = parentMatch
|
|
1490
|
-
// },
|
|
1491
|
-
// addChildMatch: (childMatch: RouteMatch) => {
|
|
1492
|
-
// if (
|
|
1493
|
-
// routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
|
|
1494
|
-
// ) {
|
|
1495
|
-
// return
|
|
1496
|
-
// }
|
|
1497
|
-
// routeMatch.childMatches.push(childMatch)
|
|
1498
|
-
// },
|
|
1499
1484
|
validate: () => {
|
|
1500
1485
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1501
1486
|
|
|
@@ -1503,9 +1488,11 @@ function createRouteMatch(router, route, opts) {
|
|
|
1503
1488
|
const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
|
|
1504
1489
|
|
|
1505
1490
|
try {
|
|
1491
|
+
var _validator;
|
|
1492
|
+
|
|
1506
1493
|
const prevSearch = routeMatch.routeSearch;
|
|
1507
1494
|
const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
|
|
1508
|
-
let nextSearch = replaceEqualDeep(prevSearch, validator == null ? void 0 : validator(parentSearch)); // Invalidate route matches when search param stability changes
|
|
1495
|
+
let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {}); // Invalidate route matches when search param stability changes
|
|
1509
1496
|
|
|
1510
1497
|
if (prevSearch !== nextSearch) {
|
|
1511
1498
|
routeMatch.isInvalid = true;
|
|
@@ -1513,6 +1500,13 @@ function createRouteMatch(router, route, opts) {
|
|
|
1513
1500
|
|
|
1514
1501
|
routeMatch.routeSearch = nextSearch;
|
|
1515
1502
|
routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
|
|
1503
|
+
elementTypes.map(async type => {
|
|
1504
|
+
const routeElement = routeMatch.options[type];
|
|
1505
|
+
|
|
1506
|
+
if (typeof routeMatch.__[type] !== 'function') {
|
|
1507
|
+
routeMatch.__[type] = routeElement;
|
|
1508
|
+
}
|
|
1509
|
+
});
|
|
1516
1510
|
} catch (err) {
|
|
1517
1511
|
console.error(err);
|
|
1518
1512
|
const error = new Error('Invalid search params found', {
|
|
@@ -1558,7 +1552,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1558
1552
|
|
|
1559
1553
|
if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
|
|
1560
1554
|
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
1561
|
-
routeMatch.fetch({
|
|
1555
|
+
await routeMatch.fetch({
|
|
1562
1556
|
maxAge
|
|
1563
1557
|
});
|
|
1564
1558
|
}
|
|
@@ -1581,7 +1575,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1581
1575
|
routeMatch.isFetching = true;
|
|
1582
1576
|
routeMatch.__.resolve = resolve;
|
|
1583
1577
|
|
|
1584
|
-
|
|
1578
|
+
routeMatch.__.loaderDataPromise = (async () => {
|
|
1585
1579
|
// Load the elements and data in parallel
|
|
1586
1580
|
routeMatch.__.elementsPromise = (async () => {
|
|
1587
1581
|
// then run all element and data loaders in parallel
|
|
@@ -1589,11 +1583,9 @@ function createRouteMatch(router, route, opts) {
|
|
|
1589
1583
|
await Promise.all(elementTypes.map(async type => {
|
|
1590
1584
|
const routeElement = routeMatch.options[type];
|
|
1591
1585
|
|
|
1592
|
-
if (routeMatch.__[type]) {
|
|
1593
|
-
|
|
1586
|
+
if (typeof routeMatch.__[type] === 'function') {
|
|
1587
|
+
routeMatch.__[type] = await router.options.createElement(routeElement);
|
|
1594
1588
|
}
|
|
1595
|
-
|
|
1596
|
-
routeMatch.__[type] = await router.options.createElement(routeElement);
|
|
1597
1589
|
}));
|
|
1598
1590
|
})();
|
|
1599
1591
|
|
|
@@ -1609,7 +1601,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1609
1601
|
});
|
|
1610
1602
|
|
|
1611
1603
|
if (id !== routeMatch.__.latestId) {
|
|
1612
|
-
return routeMatch.__.
|
|
1604
|
+
return routeMatch.__.loadPromise;
|
|
1613
1605
|
}
|
|
1614
1606
|
|
|
1615
1607
|
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
@@ -1621,7 +1613,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1621
1613
|
routeMatch.invalidAt = routeMatch.updatedAt + ((_ref = (_ref2 = (_opts$maxAge = opts == null ? void 0 : opts.maxAge) != null ? _opts$maxAge : routeMatch.options.loaderMaxAge) != null ? _ref2 : router.options.defaultLoaderMaxAge) != null ? _ref : 0);
|
|
1622
1614
|
} catch (err) {
|
|
1623
1615
|
if (id !== routeMatch.__.latestId) {
|
|
1624
|
-
return routeMatch.__.
|
|
1616
|
+
return routeMatch.__.loadPromise;
|
|
1625
1617
|
}
|
|
1626
1618
|
|
|
1627
1619
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -1638,7 +1630,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1638
1630
|
await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
|
|
1639
1631
|
|
|
1640
1632
|
if (id !== routeMatch.__.latestId) {
|
|
1641
|
-
return routeMatch.__.
|
|
1633
|
+
return routeMatch.__.loadPromise;
|
|
1642
1634
|
}
|
|
1643
1635
|
|
|
1644
1636
|
if (routeMatch.__.pendingMinPromise) {
|
|
@@ -1647,7 +1639,7 @@ function createRouteMatch(router, route, opts) {
|
|
|
1647
1639
|
}
|
|
1648
1640
|
} finally {
|
|
1649
1641
|
if (id !== routeMatch.__.latestId) {
|
|
1650
|
-
return routeMatch.__.
|
|
1642
|
+
return routeMatch.__.loadPromise;
|
|
1651
1643
|
}
|
|
1652
1644
|
|
|
1653
1645
|
routeMatch.__.cancelPending();
|
|
@@ -1659,16 +1651,16 @@ function createRouteMatch(router, route, opts) {
|
|
|
1659
1651
|
}
|
|
1660
1652
|
})();
|
|
1661
1653
|
|
|
1662
|
-
routeMatch.__.
|
|
1663
|
-
await loaderPromise;
|
|
1654
|
+
await routeMatch.__.loaderDataPromise;
|
|
1664
1655
|
|
|
1665
1656
|
if (id !== routeMatch.__.latestId) {
|
|
1666
|
-
return routeMatch.__.
|
|
1657
|
+
return routeMatch.__.loadPromise;
|
|
1667
1658
|
}
|
|
1668
1659
|
|
|
1669
|
-
delete routeMatch.__.
|
|
1660
|
+
delete routeMatch.__.loaderDataPromise;
|
|
1670
1661
|
});
|
|
1671
|
-
|
|
1662
|
+
await routeMatch.__.loadPromise;
|
|
1663
|
+
delete routeMatch.__.loadPromise;
|
|
1672
1664
|
}
|
|
1673
1665
|
});
|
|
1674
1666
|
|
|
@@ -1729,9 +1721,22 @@ function stringifySearchWith(stringify) {
|
|
|
1729
1721
|
|
|
1730
1722
|
var _window$document;
|
|
1731
1723
|
// Detect if we're in the DOM
|
|
1732
|
-
const isServer =
|
|
1724
|
+
const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement); // This is the default history object if none is defined
|
|
1733
1725
|
|
|
1734
|
-
const createDefaultHistory = () =>
|
|
1726
|
+
const createDefaultHistory = () => isServer ? createMemoryHistory() : createBrowserHistory();
|
|
1727
|
+
|
|
1728
|
+
function getInitialRouterState() {
|
|
1729
|
+
return {
|
|
1730
|
+
status: 'idle',
|
|
1731
|
+
location: null,
|
|
1732
|
+
matches: [],
|
|
1733
|
+
actions: {},
|
|
1734
|
+
loaders: {},
|
|
1735
|
+
lastUpdated: Date.now(),
|
|
1736
|
+
isFetching: false,
|
|
1737
|
+
isPreloading: false
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1735
1740
|
|
|
1736
1741
|
function createRouter(userOptions) {
|
|
1737
1742
|
var _userOptions$stringif, _userOptions$parseSea;
|
|
@@ -1752,7 +1757,6 @@ function createRouter(userOptions) {
|
|
|
1752
1757
|
history,
|
|
1753
1758
|
options: originalOptions,
|
|
1754
1759
|
listeners: [],
|
|
1755
|
-
removeActionQueue: [],
|
|
1756
1760
|
// Resolved after construction
|
|
1757
1761
|
basepath: '',
|
|
1758
1762
|
routeTree: undefined,
|
|
@@ -1763,16 +1767,10 @@ function createRouter(userOptions) {
|
|
|
1763
1767
|
navigationPromise: Promise.resolve(),
|
|
1764
1768
|
resolveNavigation: () => {},
|
|
1765
1769
|
matchCache: {},
|
|
1766
|
-
state:
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
actions: {},
|
|
1771
|
-
loaders: {},
|
|
1772
|
-
loaderData: {},
|
|
1773
|
-
lastUpdated: Date.now(),
|
|
1774
|
-
isFetching: false,
|
|
1775
|
-
isPreloading: false
|
|
1770
|
+
state: getInitialRouterState(),
|
|
1771
|
+
reset: () => {
|
|
1772
|
+
router.state = getInitialRouterState();
|
|
1773
|
+
router.notify();
|
|
1776
1774
|
},
|
|
1777
1775
|
startedLoadingAt: Date.now(),
|
|
1778
1776
|
subscribe: listener => {
|
|
@@ -1790,7 +1788,27 @@ function createRouter(userOptions) {
|
|
|
1790
1788
|
isPreloading: Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId))
|
|
1791
1789
|
});
|
|
1792
1790
|
cascadeLoaderData(router.state.matches);
|
|
1793
|
-
router.listeners.forEach(listener => listener());
|
|
1791
|
+
router.listeners.forEach(listener => listener(router));
|
|
1792
|
+
},
|
|
1793
|
+
dehydrateState: () => {
|
|
1794
|
+
return _extends({}, pick(router.state, ['status', 'location', 'lastUpdated']), {
|
|
1795
|
+
matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
|
|
1796
|
+
});
|
|
1797
|
+
},
|
|
1798
|
+
hydrateState: dehydratedState => {
|
|
1799
|
+
// Match the routes
|
|
1800
|
+
const matches = router.matchRoutes(router.location.pathname, {
|
|
1801
|
+
strictParseParams: true
|
|
1802
|
+
});
|
|
1803
|
+
matches.forEach((match, index) => {
|
|
1804
|
+
const dehydratedMatch = dehydratedState.matches[index];
|
|
1805
|
+
invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
|
|
1806
|
+
Object.assign(match, dehydratedMatch);
|
|
1807
|
+
});
|
|
1808
|
+
router.loadMatches(matches);
|
|
1809
|
+
router.state = _extends({}, router.state, dehydratedState, {
|
|
1810
|
+
matches
|
|
1811
|
+
});
|
|
1794
1812
|
},
|
|
1795
1813
|
mount: () => {
|
|
1796
1814
|
const next = router.__.buildLocation({
|
|
@@ -1803,12 +1821,11 @@ function createRouter(userOptions) {
|
|
|
1803
1821
|
|
|
1804
1822
|
if (next.href !== router.location.href) {
|
|
1805
1823
|
router.__.commitLocation(next, true);
|
|
1806
|
-
}
|
|
1807
|
-
|
|
1808
|
-
}
|
|
1824
|
+
} // router.load()
|
|
1825
|
+
|
|
1809
1826
|
|
|
1810
|
-
const unsub = history.listen(event => {
|
|
1811
|
-
router.
|
|
1827
|
+
const unsub = router.history.listen(event => {
|
|
1828
|
+
router.load(router.__.parseLocation(event.location, router.location));
|
|
1812
1829
|
}); // addEventListener does not exist in React Native, but window does
|
|
1813
1830
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1814
1831
|
|
|
@@ -1819,16 +1836,30 @@ function createRouter(userOptions) {
|
|
|
1819
1836
|
}
|
|
1820
1837
|
|
|
1821
1838
|
return () => {
|
|
1822
|
-
unsub();
|
|
1839
|
+
unsub();
|
|
1823
1840
|
|
|
1824
|
-
window.removeEventListener
|
|
1825
|
-
|
|
1841
|
+
if (!isServer && window.removeEventListener) {
|
|
1842
|
+
// Be sure to unsubscribe if a new handler is set
|
|
1843
|
+
window.removeEventListener('visibilitychange', router.onFocus);
|
|
1844
|
+
window.removeEventListener('focus', router.onFocus);
|
|
1845
|
+
}
|
|
1826
1846
|
};
|
|
1827
1847
|
},
|
|
1828
1848
|
onFocus: () => {
|
|
1829
|
-
router.
|
|
1849
|
+
router.load();
|
|
1830
1850
|
},
|
|
1831
1851
|
update: opts => {
|
|
1852
|
+
const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
|
|
1853
|
+
|
|
1854
|
+
if (!router.location || newHistory) {
|
|
1855
|
+
if (opts != null && opts.history) {
|
|
1856
|
+
router.history = opts.history;
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
router.location = router.__.parseLocation(router.history.location);
|
|
1860
|
+
router.state.location = router.location;
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1832
1863
|
Object.assign(router.options, opts);
|
|
1833
1864
|
const {
|
|
1834
1865
|
basepath,
|
|
@@ -1849,35 +1880,19 @@ function createRouter(userOptions) {
|
|
|
1849
1880
|
match.cancel();
|
|
1850
1881
|
});
|
|
1851
1882
|
},
|
|
1852
|
-
|
|
1883
|
+
load: async next => {
|
|
1853
1884
|
const id = Math.random();
|
|
1854
1885
|
router.startedLoadingAt = id;
|
|
1855
1886
|
|
|
1856
1887
|
if (next) {
|
|
1857
1888
|
// Ingest the new location
|
|
1858
1889
|
router.location = next;
|
|
1859
|
-
} //
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
router.removeActionQueue.forEach(_ref => {
|
|
1863
|
-
let {
|
|
1864
|
-
action,
|
|
1865
|
-
actionState
|
|
1866
|
-
} = _ref;
|
|
1867
|
-
|
|
1868
|
-
if (router.state.currentAction === actionState) {
|
|
1869
|
-
router.state.currentAction = undefined;
|
|
1870
|
-
}
|
|
1890
|
+
} // Cancel any pending matches
|
|
1871
1891
|
|
|
1872
|
-
if (action.current === actionState) {
|
|
1873
|
-
action.current = undefined;
|
|
1874
|
-
}
|
|
1875
|
-
});
|
|
1876
|
-
router.removeActionQueue = []; // Cancel any pending matches
|
|
1877
1892
|
|
|
1878
1893
|
router.cancelMatches(); // Match the routes
|
|
1879
1894
|
|
|
1880
|
-
const matches = router.matchRoutes(location.pathname, {
|
|
1895
|
+
const matches = router.matchRoutes(router.location.pathname, {
|
|
1881
1896
|
strictParseParams: true
|
|
1882
1897
|
});
|
|
1883
1898
|
router.state = _extends({}, router.state, {
|
|
@@ -1908,9 +1923,12 @@ function createRouter(userOptions) {
|
|
|
1908
1923
|
exiting.push(d);
|
|
1909
1924
|
}
|
|
1910
1925
|
});
|
|
1926
|
+
const entering = matches.filter(d => {
|
|
1927
|
+
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
1928
|
+
});
|
|
1911
1929
|
const now = Date.now();
|
|
1912
1930
|
exiting.forEach(d => {
|
|
1913
|
-
var
|
|
1931
|
+
var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
|
|
1914
1932
|
|
|
1915
1933
|
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
1916
1934
|
params: d.params,
|
|
@@ -1922,7 +1940,7 @@ function createRouter(userOptions) {
|
|
|
1922
1940
|
d.error = undefined;
|
|
1923
1941
|
}
|
|
1924
1942
|
|
|
1925
|
-
const gc = Math.max((
|
|
1943
|
+
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);
|
|
1926
1944
|
|
|
1927
1945
|
if (gc > 0) {
|
|
1928
1946
|
router.matchCache[d.matchId] = {
|
|
@@ -1937,9 +1955,6 @@ function createRouter(userOptions) {
|
|
|
1937
1955
|
search: d.routeSearch
|
|
1938
1956
|
});
|
|
1939
1957
|
});
|
|
1940
|
-
const entering = matches.filter(d => {
|
|
1941
|
-
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
1942
|
-
});
|
|
1943
1958
|
entering.forEach(d => {
|
|
1944
1959
|
d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
|
|
1945
1960
|
params: d.params,
|
|
@@ -1948,16 +1963,18 @@ function createRouter(userOptions) {
|
|
|
1948
1963
|
delete router.matchCache[d.matchId];
|
|
1949
1964
|
});
|
|
1950
1965
|
|
|
1951
|
-
if (matches.some(d => d.status === 'loading')) {
|
|
1952
|
-
router.notify();
|
|
1953
|
-
await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
1966
|
if (router.startedLoadingAt !== id) {
|
|
1957
1967
|
// Ignore side-effects of match loading
|
|
1958
1968
|
return;
|
|
1959
1969
|
}
|
|
1960
1970
|
|
|
1971
|
+
matches.forEach(match => {
|
|
1972
|
+
// Clear actions
|
|
1973
|
+
if (match.action) {
|
|
1974
|
+
match.action.current = undefined;
|
|
1975
|
+
match.action.submissions = [];
|
|
1976
|
+
}
|
|
1977
|
+
});
|
|
1961
1978
|
router.state = _extends({}, router.state, {
|
|
1962
1979
|
location: router.location,
|
|
1963
1980
|
matches,
|
|
@@ -1998,7 +2015,7 @@ function createRouter(userOptions) {
|
|
|
1998
2015
|
return matches;
|
|
1999
2016
|
},
|
|
2000
2017
|
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
2001
|
-
var
|
|
2018
|
+
var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
|
|
2002
2019
|
|
|
2003
2020
|
if (navigateOpts === void 0) {
|
|
2004
2021
|
navigateOpts = router.location;
|
|
@@ -2010,8 +2027,8 @@ function createRouter(userOptions) {
|
|
|
2010
2027
|
});
|
|
2011
2028
|
await router.loadMatches(matches, {
|
|
2012
2029
|
preload: true,
|
|
2013
|
-
maxAge: (
|
|
2014
|
-
gcMaxAge: (
|
|
2030
|
+
maxAge: (_ref3 = (_ref4 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref4 : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0,
|
|
2031
|
+
gcMaxAge: (_ref5 = (_ref6 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref6 : router.options.defaultLoaderGcMaxAge) != null ? _ref5 : 0
|
|
2015
2032
|
});
|
|
2016
2033
|
return matches;
|
|
2017
2034
|
},
|
|
@@ -2113,9 +2130,12 @@ function createRouter(userOptions) {
|
|
|
2113
2130
|
|
|
2114
2131
|
if (match.status === 'loading') {
|
|
2115
2132
|
// If requested, start the pending timers
|
|
2116
|
-
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
|
|
2117
|
-
|
|
2133
|
+
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
|
|
2134
|
+
}
|
|
2118
2135
|
|
|
2136
|
+
if (match.__.loadPromise) {
|
|
2137
|
+
// Wait for the first sign of activity from the match
|
|
2138
|
+
// This might be completion, error, or a pending state
|
|
2119
2139
|
await match.__.loadPromise;
|
|
2120
2140
|
}
|
|
2121
2141
|
});
|
|
@@ -2166,7 +2186,7 @@ function createRouter(userOptions) {
|
|
|
2166
2186
|
to: next.pathname
|
|
2167
2187
|
}));
|
|
2168
2188
|
},
|
|
2169
|
-
navigate: async
|
|
2189
|
+
navigate: async _ref7 => {
|
|
2170
2190
|
let {
|
|
2171
2191
|
from,
|
|
2172
2192
|
to = '.',
|
|
@@ -2174,7 +2194,7 @@ function createRouter(userOptions) {
|
|
|
2174
2194
|
hash,
|
|
2175
2195
|
replace,
|
|
2176
2196
|
params
|
|
2177
|
-
} =
|
|
2197
|
+
} = _ref7;
|
|
2178
2198
|
// If this link simply reloads the current route,
|
|
2179
2199
|
// make sure it has a new key so it will trigger a data refresh
|
|
2180
2200
|
// If this `to` is a valid external URL, return
|
|
@@ -2198,8 +2218,8 @@ function createRouter(userOptions) {
|
|
|
2198
2218
|
params
|
|
2199
2219
|
});
|
|
2200
2220
|
},
|
|
2201
|
-
buildLink:
|
|
2202
|
-
var _preload,
|
|
2221
|
+
buildLink: _ref8 => {
|
|
2222
|
+
var _preload, _ref9;
|
|
2203
2223
|
|
|
2204
2224
|
let {
|
|
2205
2225
|
from,
|
|
@@ -2215,7 +2235,7 @@ function createRouter(userOptions) {
|
|
|
2215
2235
|
preloadGcMaxAge: userPreloadGcMaxAge,
|
|
2216
2236
|
preloadDelay: userPreloadDelay,
|
|
2217
2237
|
disabled
|
|
2218
|
-
} =
|
|
2238
|
+
} = _ref8;
|
|
2219
2239
|
|
|
2220
2240
|
// If this link simply reloads the current route,
|
|
2221
2241
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -2239,7 +2259,7 @@ function createRouter(userOptions) {
|
|
|
2239
2259
|
};
|
|
2240
2260
|
const next = router.buildNext(nextOpts);
|
|
2241
2261
|
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
2242
|
-
const preloadDelay = (
|
|
2262
|
+
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0; // Compare path/hash for matches
|
|
2243
2263
|
|
|
2244
2264
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
2245
2265
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
@@ -2340,11 +2360,7 @@ function createRouter(userOptions) {
|
|
|
2340
2360
|
const recurseRoutes = (routeConfigs, parent) => {
|
|
2341
2361
|
return routeConfigs.map(routeConfig => {
|
|
2342
2362
|
const routeOptions = routeConfig.options;
|
|
2343
|
-
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2344
|
-
// pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
|
|
2345
|
-
// pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
|
|
2346
|
-
// }
|
|
2347
|
-
|
|
2363
|
+
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2348
2364
|
const existingRoute = router.routesById[route.routeId];
|
|
2349
2365
|
|
|
2350
2366
|
if (existingRoute) {
|
|
@@ -2479,8 +2495,6 @@ function createRouter(userOptions) {
|
|
|
2479
2495
|
}
|
|
2480
2496
|
}
|
|
2481
2497
|
};
|
|
2482
|
-
router.location = router.__.parseLocation(history.location);
|
|
2483
|
-
router.state.location = router.location;
|
|
2484
2498
|
router.update(userOptions); // Allow frameworks to hook into the router creation
|
|
2485
2499
|
|
|
2486
2500
|
router.options.createRouter == null ? void 0 : router.options.createRouter(router);
|
|
@@ -2491,6 +2505,16 @@ function isCtrlEvent(e) {
|
|
|
2491
2505
|
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
2492
2506
|
}
|
|
2493
2507
|
|
|
2508
|
+
function cascadeLoaderData(matches) {
|
|
2509
|
+
matches.forEach((match, index) => {
|
|
2510
|
+
const parent = matches[index - 1];
|
|
2511
|
+
|
|
2512
|
+
if (parent) {
|
|
2513
|
+
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
2514
|
+
}
|
|
2515
|
+
});
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2494
2518
|
const _excluded = ["type", "children", "target", "activeProps", "inactiveProps", "activeOptions", "disabled", "hash", "search", "params", "to", "preload", "preloadDelay", "preloadMaxAge", "replace", "style", "className", "onClick", "onFocus", "onMouseEnter", "onMouseLeave", "onTouchStart", "onTouchEnd"],
|
|
2495
2519
|
_excluded2 = ["pending", "caseSensitive", "children"],
|
|
2496
2520
|
_excluded3 = ["children", "router"];
|
|
@@ -2505,7 +2529,7 @@ function MatchesProvider(props) {
|
|
|
2505
2529
|
}
|
|
2506
2530
|
|
|
2507
2531
|
const useRouterSubscription = router => {
|
|
2508
|
-
useSyncExternalStore(cb => router.subscribe(() => cb()), () => router.state);
|
|
2532
|
+
useSyncExternalStore(cb => router.subscribe(() => cb()), () => router.state, () => router.state);
|
|
2509
2533
|
};
|
|
2510
2534
|
|
|
2511
2535
|
function createReactRouter(opts) {
|
|
@@ -2629,18 +2653,17 @@ function createReactRouter(opts) {
|
|
|
2629
2653
|
useRouterSubscription(router);
|
|
2630
2654
|
return router.state;
|
|
2631
2655
|
},
|
|
2632
|
-
useMatch: routeId => {
|
|
2656
|
+
useMatch: (routeId, opts) => {
|
|
2657
|
+
var _useMatches, _opts$strict;
|
|
2658
|
+
|
|
2633
2659
|
useRouterSubscription(router);
|
|
2634
2660
|
invariant(routeId !== rootRouteId, "\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
|
|
2635
|
-
|
|
2636
|
-
const runtimeMatch = _useMatch();
|
|
2637
|
-
|
|
2661
|
+
const runtimeMatch = (_useMatches = useMatches()) == null ? void 0 : _useMatches[0];
|
|
2638
2662
|
const match = router.state.matches.find(d => d.routeId === routeId);
|
|
2639
|
-
invariant(match, "Could not find a match for route \"" + routeId + "\" being rendered in this component!");
|
|
2640
|
-
invariant(runtimeMatch.routeId == (match == null ? void 0 : match.routeId), "useMatch('" + (match == null ? void 0 : match.routeId) + "') is being called in a component that is meant to render the '" + runtimeMatch.routeId + "' route. Did you mean to 'useRoute(" + (match == null ? void 0 : match.routeId) + ")' instead?");
|
|
2641
2663
|
|
|
2642
|
-
if (
|
|
2643
|
-
invariant(
|
|
2664
|
+
if ((_opts$strict = opts == null ? void 0 : opts.strict) != null ? _opts$strict : true) {
|
|
2665
|
+
invariant(match, "Could not find an active match for \"" + routeId + "\"!");
|
|
2666
|
+
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?");
|
|
2644
2667
|
}
|
|
2645
2668
|
|
|
2646
2669
|
return match;
|
|
@@ -2683,7 +2706,9 @@ function RouterProvider(_ref2) {
|
|
|
2683
2706
|
router.update(rest);
|
|
2684
2707
|
useRouterSubscription(router);
|
|
2685
2708
|
useLayoutEffect(() => {
|
|
2686
|
-
|
|
2709
|
+
const unsub = router.mount();
|
|
2710
|
+
router.load();
|
|
2711
|
+
return unsub;
|
|
2687
2712
|
}, [router]);
|
|
2688
2713
|
return /*#__PURE__*/React.createElement(routerContext.Provider, {
|
|
2689
2714
|
value: {
|
|
@@ -2703,61 +2728,49 @@ function useRouter() {
|
|
|
2703
2728
|
|
|
2704
2729
|
function useMatches() {
|
|
2705
2730
|
return React.useContext(matchesContext);
|
|
2706
|
-
} // function useParentMatches(): RouteMatch[] {
|
|
2707
|
-
// const router = useRouter()
|
|
2708
|
-
// const match = useMatch()
|
|
2709
|
-
// const matches = router.state.matches
|
|
2710
|
-
// return matches.slice(
|
|
2711
|
-
// 0,
|
|
2712
|
-
// matches.findIndex((d) => d.matchId === match.matchId) - 1,
|
|
2713
|
-
// )
|
|
2714
|
-
// }
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
function _useMatch() {
|
|
2718
|
-
var _useMatches;
|
|
2719
|
-
|
|
2720
|
-
return (_useMatches = useMatches()) == null ? void 0 : _useMatches[0];
|
|
2721
2731
|
}
|
|
2722
2732
|
|
|
2723
2733
|
function Outlet() {
|
|
2724
|
-
var
|
|
2734
|
+
var _match$options$catchE;
|
|
2725
2735
|
|
|
2726
2736
|
const router = useRouter();
|
|
2727
|
-
const
|
|
2728
|
-
const
|
|
2729
|
-
|
|
2737
|
+
const matches = useMatches().slice(1);
|
|
2738
|
+
const match = matches[0];
|
|
2739
|
+
|
|
2740
|
+
if (!match) {
|
|
2741
|
+
return null;
|
|
2742
|
+
}
|
|
2730
2743
|
|
|
2731
2744
|
const element = (() => {
|
|
2732
|
-
var
|
|
2745
|
+
var _match$__$errorElemen, _ref4, _ref5;
|
|
2733
2746
|
|
|
2734
|
-
if (!
|
|
2747
|
+
if (!match) {
|
|
2735
2748
|
return null;
|
|
2736
2749
|
}
|
|
2737
2750
|
|
|
2738
|
-
const errorElement = (
|
|
2751
|
+
const errorElement = (_match$__$errorElemen = match.__.errorElement) != null ? _match$__$errorElemen : router.options.defaultErrorElement;
|
|
2739
2752
|
|
|
2740
|
-
if (
|
|
2753
|
+
if (match.status === 'error') {
|
|
2741
2754
|
if (errorElement) {
|
|
2742
2755
|
return errorElement;
|
|
2743
2756
|
}
|
|
2744
2757
|
|
|
2745
|
-
if (
|
|
2746
|
-
throw
|
|
2758
|
+
if (match.options.useErrorBoundary || router.options.useErrorBoundary) {
|
|
2759
|
+
throw match.error;
|
|
2747
2760
|
}
|
|
2748
2761
|
|
|
2749
2762
|
return /*#__PURE__*/React.createElement(DefaultErrorBoundary, {
|
|
2750
|
-
error:
|
|
2763
|
+
error: match.error
|
|
2751
2764
|
});
|
|
2752
2765
|
}
|
|
2753
2766
|
|
|
2754
|
-
if (
|
|
2755
|
-
if (
|
|
2756
|
-
var
|
|
2767
|
+
if (match.status === 'loading' || match.status === 'idle') {
|
|
2768
|
+
if (match.isPending) {
|
|
2769
|
+
var _match$__$pendingElem;
|
|
2757
2770
|
|
|
2758
|
-
const pendingElement = (
|
|
2771
|
+
const pendingElement = (_match$__$pendingElem = match.__.pendingElement) != null ? _match$__$pendingElem : router.options.defaultPendingElement;
|
|
2759
2772
|
|
|
2760
|
-
if (
|
|
2773
|
+
if (match.options.pendingMs || pendingElement) {
|
|
2761
2774
|
var _ref3;
|
|
2762
2775
|
|
|
2763
2776
|
return (_ref3 = pendingElement) != null ? _ref3 : null;
|
|
@@ -2767,13 +2780,12 @@ function Outlet() {
|
|
|
2767
2780
|
return null;
|
|
2768
2781
|
}
|
|
2769
2782
|
|
|
2770
|
-
return (_ref4 =
|
|
2783
|
+
return (_ref4 = (_ref5 = match.__.element) != null ? _ref5 : router.options.defaultElement) != null ? _ref4 : /*#__PURE__*/React.createElement(Outlet, null);
|
|
2771
2784
|
})();
|
|
2772
2785
|
|
|
2773
|
-
const catchElement = (
|
|
2786
|
+
const catchElement = (_match$options$catchE = match == null ? void 0 : match.options.catchElement) != null ? _match$options$catchE : router.options.defaultCatchElement;
|
|
2774
2787
|
return /*#__PURE__*/React.createElement(MatchesProvider, {
|
|
2775
|
-
value: matches
|
|
2776
|
-
key: childMatch.matchId
|
|
2788
|
+
value: matches
|
|
2777
2789
|
}, /*#__PURE__*/React.createElement(CatchBoundary, {
|
|
2778
2790
|
catchElement: catchElement
|
|
2779
2791
|
}, element));
|
|
@@ -2785,13 +2797,6 @@ class CatchBoundary extends React.Component {
|
|
|
2785
2797
|
this.state = {
|
|
2786
2798
|
error: false
|
|
2787
2799
|
};
|
|
2788
|
-
|
|
2789
|
-
this.reset = () => {
|
|
2790
|
-
this.setState({
|
|
2791
|
-
error: false,
|
|
2792
|
-
info: false
|
|
2793
|
-
});
|
|
2794
|
-
};
|
|
2795
2800
|
}
|
|
2796
2801
|
|
|
2797
2802
|
componentDidCatch(error, info) {
|
|
@@ -2816,10 +2821,10 @@ class CatchBoundary extends React.Component {
|
|
|
2816
2821
|
|
|
2817
2822
|
}
|
|
2818
2823
|
|
|
2819
|
-
function DefaultErrorBoundary(
|
|
2824
|
+
function DefaultErrorBoundary(_ref6) {
|
|
2820
2825
|
let {
|
|
2821
2826
|
error
|
|
2822
|
-
} =
|
|
2827
|
+
} = _ref6;
|
|
2823
2828
|
return /*#__PURE__*/React.createElement("div", {
|
|
2824
2829
|
style: {
|
|
2825
2830
|
padding: '.5rem',
|
|
@@ -2841,18 +2846,7 @@ function DefaultErrorBoundary(_ref5) {
|
|
|
2841
2846
|
padding: '.5rem',
|
|
2842
2847
|
color: 'red'
|
|
2843
2848
|
}
|
|
2844
|
-
}, error.message) : null))
|
|
2845
|
-
style: {
|
|
2846
|
-
height: '1rem'
|
|
2847
|
-
}
|
|
2848
|
-
}), /*#__PURE__*/React.createElement("div", {
|
|
2849
|
-
style: {
|
|
2850
|
-
fontSize: '.8em',
|
|
2851
|
-
borderLeft: '3px solid rgba(127, 127, 127, 1)',
|
|
2852
|
-
paddingLeft: '.5rem',
|
|
2853
|
-
opacity: 0.5
|
|
2854
|
-
}
|
|
2855
|
-
}, "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."));
|
|
2849
|
+
}, error.message) : null)));
|
|
2856
2850
|
}
|
|
2857
2851
|
function usePrompt(message, when) {
|
|
2858
2852
|
const router = useRouter();
|
|
@@ -2869,15 +2863,15 @@ function usePrompt(message, when) {
|
|
|
2869
2863
|
return unblock;
|
|
2870
2864
|
}, [when, location, message]);
|
|
2871
2865
|
}
|
|
2872
|
-
function Prompt(
|
|
2866
|
+
function Prompt(_ref7) {
|
|
2873
2867
|
let {
|
|
2874
2868
|
message,
|
|
2875
2869
|
when,
|
|
2876
2870
|
children
|
|
2877
|
-
} =
|
|
2871
|
+
} = _ref7;
|
|
2878
2872
|
usePrompt(message, when != null ? when : true);
|
|
2879
2873
|
return children != null ? children : null;
|
|
2880
2874
|
}
|
|
2881
2875
|
|
|
2882
|
-
export { DefaultErrorBoundary, MatchesProvider, Outlet, Prompt, RouterProvider,
|
|
2876
|
+
export { DefaultErrorBoundary, MatchesProvider, Outlet, Prompt, RouterProvider, cleanPath, createBrowserHistory, createHashHistory, createMemoryHistory, createReactRouter, createRoute, createRouteConfig, createRouteMatch, createRouter, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, invariant, joinPaths, last, matchByPath, matchPathname, parsePathname, parseSearchWith, pick, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, usePrompt, warning };
|
|
2883
2877
|
//# sourceMappingURL=index.js.map
|