@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
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
|
-
router.loadLocation();
|
|
1808
|
-
}
|
|
1824
|
+
} // router.load()
|
|
1809
1825
|
|
|
1810
|
-
|
|
1811
|
-
|
|
1826
|
+
|
|
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
|
-
|
|
1890
|
+
} // Cancel any pending matches
|
|
1861
1891
|
|
|
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
|
-
}
|
|
1871
|
-
|
|
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, {
|
|
@@ -1910,19 +1925,24 @@ function createRouter(userOptions) {
|
|
|
1910
1925
|
});
|
|
1911
1926
|
const now = Date.now();
|
|
1912
1927
|
exiting.forEach(d => {
|
|
1913
|
-
var
|
|
1928
|
+
var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
|
|
1914
1929
|
|
|
1915
1930
|
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
1916
1931
|
params: d.params,
|
|
1917
1932
|
search: d.routeSearch
|
|
1918
|
-
}); // Clear
|
|
1933
|
+
}); // // Clear actions
|
|
1934
|
+
// if (d.action) {
|
|
1935
|
+
// d.action.current = undefined
|
|
1936
|
+
// d.action.submissions = []
|
|
1937
|
+
// }
|
|
1938
|
+
// Clear idle error states when match leaves
|
|
1919
1939
|
|
|
1920
1940
|
if (d.status === 'error' && !d.isFetching) {
|
|
1921
1941
|
d.status = 'idle';
|
|
1922
1942
|
d.error = undefined;
|
|
1923
1943
|
}
|
|
1924
1944
|
|
|
1925
|
-
const gc = Math.max((
|
|
1945
|
+
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
1946
|
|
|
1927
1947
|
if (gc > 0) {
|
|
1928
1948
|
router.matchCache[d.matchId] = {
|
|
@@ -1946,18 +1966,20 @@ function createRouter(userOptions) {
|
|
|
1946
1966
|
search: d.search
|
|
1947
1967
|
});
|
|
1948
1968
|
delete router.matchCache[d.matchId];
|
|
1949
|
-
});
|
|
1950
|
-
|
|
1951
|
-
if (matches.some(d => d.status === 'loading')) {
|
|
1952
|
-
router.notify();
|
|
1953
|
-
await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
|
|
1954
|
-
}
|
|
1969
|
+
}); // router.notify()
|
|
1955
1970
|
|
|
1956
1971
|
if (router.startedLoadingAt !== id) {
|
|
1957
1972
|
// Ignore side-effects of match loading
|
|
1958
1973
|
return;
|
|
1959
1974
|
}
|
|
1960
1975
|
|
|
1976
|
+
matches.forEach(match => {
|
|
1977
|
+
// Clear actions
|
|
1978
|
+
if (match.action) {
|
|
1979
|
+
match.action.current = undefined;
|
|
1980
|
+
match.action.submissions = [];
|
|
1981
|
+
}
|
|
1982
|
+
});
|
|
1961
1983
|
router.state = _extends({}, router.state, {
|
|
1962
1984
|
location: router.location,
|
|
1963
1985
|
matches,
|
|
@@ -1998,7 +2020,7 @@ function createRouter(userOptions) {
|
|
|
1998
2020
|
return matches;
|
|
1999
2021
|
},
|
|
2000
2022
|
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
2001
|
-
var
|
|
2023
|
+
var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
|
|
2002
2024
|
|
|
2003
2025
|
if (navigateOpts === void 0) {
|
|
2004
2026
|
navigateOpts = router.location;
|
|
@@ -2010,8 +2032,8 @@ function createRouter(userOptions) {
|
|
|
2010
2032
|
});
|
|
2011
2033
|
await router.loadMatches(matches, {
|
|
2012
2034
|
preload: true,
|
|
2013
|
-
maxAge: (
|
|
2014
|
-
gcMaxAge: (
|
|
2035
|
+
maxAge: (_ref3 = (_ref4 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref4 : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0,
|
|
2036
|
+
gcMaxAge: (_ref5 = (_ref6 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref6 : router.options.defaultLoaderGcMaxAge) != null ? _ref5 : 0
|
|
2015
2037
|
});
|
|
2016
2038
|
return matches;
|
|
2017
2039
|
},
|
|
@@ -2113,9 +2135,12 @@ function createRouter(userOptions) {
|
|
|
2113
2135
|
|
|
2114
2136
|
if (match.status === 'loading') {
|
|
2115
2137
|
// If requested, start the pending timers
|
|
2116
|
-
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
|
|
2117
|
-
|
|
2138
|
+
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending();
|
|
2139
|
+
}
|
|
2118
2140
|
|
|
2141
|
+
if (match.__.loadPromise) {
|
|
2142
|
+
// Wait for the first sign of activity from the match
|
|
2143
|
+
// This might be completion, error, or a pending state
|
|
2119
2144
|
await match.__.loadPromise;
|
|
2120
2145
|
}
|
|
2121
2146
|
});
|
|
@@ -2166,7 +2191,7 @@ function createRouter(userOptions) {
|
|
|
2166
2191
|
to: next.pathname
|
|
2167
2192
|
}));
|
|
2168
2193
|
},
|
|
2169
|
-
navigate: async
|
|
2194
|
+
navigate: async _ref7 => {
|
|
2170
2195
|
let {
|
|
2171
2196
|
from,
|
|
2172
2197
|
to = '.',
|
|
@@ -2174,7 +2199,7 @@ function createRouter(userOptions) {
|
|
|
2174
2199
|
hash,
|
|
2175
2200
|
replace,
|
|
2176
2201
|
params
|
|
2177
|
-
} =
|
|
2202
|
+
} = _ref7;
|
|
2178
2203
|
// If this link simply reloads the current route,
|
|
2179
2204
|
// make sure it has a new key so it will trigger a data refresh
|
|
2180
2205
|
// If this `to` is a valid external URL, return
|
|
@@ -2198,8 +2223,8 @@ function createRouter(userOptions) {
|
|
|
2198
2223
|
params
|
|
2199
2224
|
});
|
|
2200
2225
|
},
|
|
2201
|
-
buildLink:
|
|
2202
|
-
var _preload,
|
|
2226
|
+
buildLink: _ref8 => {
|
|
2227
|
+
var _preload, _ref9;
|
|
2203
2228
|
|
|
2204
2229
|
let {
|
|
2205
2230
|
from,
|
|
@@ -2215,7 +2240,7 @@ function createRouter(userOptions) {
|
|
|
2215
2240
|
preloadGcMaxAge: userPreloadGcMaxAge,
|
|
2216
2241
|
preloadDelay: userPreloadDelay,
|
|
2217
2242
|
disabled
|
|
2218
|
-
} =
|
|
2243
|
+
} = _ref8;
|
|
2219
2244
|
|
|
2220
2245
|
// If this link simply reloads the current route,
|
|
2221
2246
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -2239,7 +2264,7 @@ function createRouter(userOptions) {
|
|
|
2239
2264
|
};
|
|
2240
2265
|
const next = router.buildNext(nextOpts);
|
|
2241
2266
|
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
2242
|
-
const preloadDelay = (
|
|
2267
|
+
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0; // Compare path/hash for matches
|
|
2243
2268
|
|
|
2244
2269
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
2245
2270
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
@@ -2340,11 +2365,7 @@ function createRouter(userOptions) {
|
|
|
2340
2365
|
const recurseRoutes = (routeConfigs, parent) => {
|
|
2341
2366
|
return routeConfigs.map(routeConfig => {
|
|
2342
2367
|
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
|
-
|
|
2368
|
+
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2348
2369
|
const existingRoute = router.routesById[route.routeId];
|
|
2349
2370
|
|
|
2350
2371
|
if (existingRoute) {
|
|
@@ -2479,8 +2500,6 @@ function createRouter(userOptions) {
|
|
|
2479
2500
|
}
|
|
2480
2501
|
}
|
|
2481
2502
|
};
|
|
2482
|
-
router.location = router.__.parseLocation(history.location);
|
|
2483
|
-
router.state.location = router.location;
|
|
2484
2503
|
router.update(userOptions); // Allow frameworks to hook into the router creation
|
|
2485
2504
|
|
|
2486
2505
|
router.options.createRouter == null ? void 0 : router.options.createRouter(router);
|
|
@@ -2491,6 +2510,16 @@ function isCtrlEvent(e) {
|
|
|
2491
2510
|
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
2492
2511
|
}
|
|
2493
2512
|
|
|
2513
|
+
function cascadeLoaderData(matches) {
|
|
2514
|
+
matches.forEach((match, index) => {
|
|
2515
|
+
const parent = matches[index - 1];
|
|
2516
|
+
|
|
2517
|
+
if (parent) {
|
|
2518
|
+
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
2519
|
+
}
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2494
2523
|
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
2524
|
_excluded2 = ["pending", "caseSensitive", "children"],
|
|
2496
2525
|
_excluded3 = ["children", "router"];
|
|
@@ -2505,7 +2534,7 @@ function MatchesProvider(props) {
|
|
|
2505
2534
|
}
|
|
2506
2535
|
|
|
2507
2536
|
const useRouterSubscription = router => {
|
|
2508
|
-
useSyncExternalStore(cb => router.subscribe(() => cb()), () => router.state);
|
|
2537
|
+
useSyncExternalStore(cb => router.subscribe(() => cb()), () => router.state, () => router.state);
|
|
2509
2538
|
};
|
|
2510
2539
|
|
|
2511
2540
|
function createReactRouter(opts) {
|
|
@@ -2629,18 +2658,17 @@ function createReactRouter(opts) {
|
|
|
2629
2658
|
useRouterSubscription(router);
|
|
2630
2659
|
return router.state;
|
|
2631
2660
|
},
|
|
2632
|
-
useMatch: routeId => {
|
|
2661
|
+
useMatch: (routeId, opts) => {
|
|
2662
|
+
var _useMatches, _opts$strict;
|
|
2663
|
+
|
|
2633
2664
|
useRouterSubscription(router);
|
|
2634
2665
|
invariant(routeId !== rootRouteId, "\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
|
|
2635
|
-
|
|
2636
|
-
const runtimeMatch = _useMatch();
|
|
2637
|
-
|
|
2666
|
+
const runtimeMatch = (_useMatches = useMatches()) == null ? void 0 : _useMatches[0];
|
|
2638
2667
|
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
2668
|
|
|
2642
|
-
if (
|
|
2643
|
-
invariant(
|
|
2669
|
+
if ((_opts$strict = opts == null ? void 0 : opts.strict) != null ? _opts$strict : true) {
|
|
2670
|
+
invariant(match, "Could not find an active match for \"" + routeId + "\"!");
|
|
2671
|
+
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
2672
|
}
|
|
2645
2673
|
|
|
2646
2674
|
return match;
|
|
@@ -2683,7 +2711,9 @@ function RouterProvider(_ref2) {
|
|
|
2683
2711
|
router.update(rest);
|
|
2684
2712
|
useRouterSubscription(router);
|
|
2685
2713
|
useLayoutEffect(() => {
|
|
2686
|
-
|
|
2714
|
+
const unsub = router.mount();
|
|
2715
|
+
router.load();
|
|
2716
|
+
return unsub;
|
|
2687
2717
|
}, [router]);
|
|
2688
2718
|
return /*#__PURE__*/React.createElement(routerContext.Provider, {
|
|
2689
2719
|
value: {
|
|
@@ -2703,61 +2733,49 @@ function useRouter() {
|
|
|
2703
2733
|
|
|
2704
2734
|
function useMatches() {
|
|
2705
2735
|
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
2736
|
}
|
|
2722
2737
|
|
|
2723
2738
|
function Outlet() {
|
|
2724
|
-
var
|
|
2739
|
+
var _match$options$catchE;
|
|
2725
2740
|
|
|
2726
2741
|
const router = useRouter();
|
|
2727
|
-
const
|
|
2728
|
-
const
|
|
2729
|
-
|
|
2742
|
+
const matches = useMatches().slice(1);
|
|
2743
|
+
const match = matches[0];
|
|
2744
|
+
|
|
2745
|
+
if (!match) {
|
|
2746
|
+
return null;
|
|
2747
|
+
}
|
|
2730
2748
|
|
|
2731
2749
|
const element = (() => {
|
|
2732
|
-
var
|
|
2750
|
+
var _match$__$errorElemen, _ref4, _ref5;
|
|
2733
2751
|
|
|
2734
|
-
if (!
|
|
2752
|
+
if (!match) {
|
|
2735
2753
|
return null;
|
|
2736
2754
|
}
|
|
2737
2755
|
|
|
2738
|
-
const errorElement = (
|
|
2756
|
+
const errorElement = (_match$__$errorElemen = match.__.errorElement) != null ? _match$__$errorElemen : router.options.defaultErrorElement;
|
|
2739
2757
|
|
|
2740
|
-
if (
|
|
2758
|
+
if (match.status === 'error') {
|
|
2741
2759
|
if (errorElement) {
|
|
2742
2760
|
return errorElement;
|
|
2743
2761
|
}
|
|
2744
2762
|
|
|
2745
|
-
if (
|
|
2746
|
-
throw
|
|
2763
|
+
if (match.options.useErrorBoundary || router.options.useErrorBoundary) {
|
|
2764
|
+
throw match.error;
|
|
2747
2765
|
}
|
|
2748
2766
|
|
|
2749
2767
|
return /*#__PURE__*/React.createElement(DefaultErrorBoundary, {
|
|
2750
|
-
error:
|
|
2768
|
+
error: match.error
|
|
2751
2769
|
});
|
|
2752
2770
|
}
|
|
2753
2771
|
|
|
2754
|
-
if (
|
|
2755
|
-
if (
|
|
2756
|
-
var
|
|
2772
|
+
if (match.status === 'loading' || match.status === 'idle') {
|
|
2773
|
+
if (match.isPending) {
|
|
2774
|
+
var _match$__$pendingElem;
|
|
2757
2775
|
|
|
2758
|
-
const pendingElement = (
|
|
2776
|
+
const pendingElement = (_match$__$pendingElem = match.__.pendingElement) != null ? _match$__$pendingElem : router.options.defaultPendingElement;
|
|
2759
2777
|
|
|
2760
|
-
if (
|
|
2778
|
+
if (match.options.pendingMs || pendingElement) {
|
|
2761
2779
|
var _ref3;
|
|
2762
2780
|
|
|
2763
2781
|
return (_ref3 = pendingElement) != null ? _ref3 : null;
|
|
@@ -2767,13 +2785,12 @@ function Outlet() {
|
|
|
2767
2785
|
return null;
|
|
2768
2786
|
}
|
|
2769
2787
|
|
|
2770
|
-
return (_ref4 =
|
|
2788
|
+
return (_ref4 = (_ref5 = match.__.element) != null ? _ref5 : router.options.defaultElement) != null ? _ref4 : /*#__PURE__*/React.createElement(Outlet, null);
|
|
2771
2789
|
})();
|
|
2772
2790
|
|
|
2773
|
-
const catchElement = (
|
|
2791
|
+
const catchElement = (_match$options$catchE = match == null ? void 0 : match.options.catchElement) != null ? _match$options$catchE : router.options.defaultCatchElement;
|
|
2774
2792
|
return /*#__PURE__*/React.createElement(MatchesProvider, {
|
|
2775
|
-
value: matches
|
|
2776
|
-
key: childMatch.matchId
|
|
2793
|
+
value: matches
|
|
2777
2794
|
}, /*#__PURE__*/React.createElement(CatchBoundary, {
|
|
2778
2795
|
catchElement: catchElement
|
|
2779
2796
|
}, element));
|
|
@@ -2785,13 +2802,6 @@ class CatchBoundary extends React.Component {
|
|
|
2785
2802
|
this.state = {
|
|
2786
2803
|
error: false
|
|
2787
2804
|
};
|
|
2788
|
-
|
|
2789
|
-
this.reset = () => {
|
|
2790
|
-
this.setState({
|
|
2791
|
-
error: false,
|
|
2792
|
-
info: false
|
|
2793
|
-
});
|
|
2794
|
-
};
|
|
2795
2805
|
}
|
|
2796
2806
|
|
|
2797
2807
|
componentDidCatch(error, info) {
|
|
@@ -2816,10 +2826,10 @@ class CatchBoundary extends React.Component {
|
|
|
2816
2826
|
|
|
2817
2827
|
}
|
|
2818
2828
|
|
|
2819
|
-
function DefaultErrorBoundary(
|
|
2829
|
+
function DefaultErrorBoundary(_ref6) {
|
|
2820
2830
|
let {
|
|
2821
2831
|
error
|
|
2822
|
-
} =
|
|
2832
|
+
} = _ref6;
|
|
2823
2833
|
return /*#__PURE__*/React.createElement("div", {
|
|
2824
2834
|
style: {
|
|
2825
2835
|
padding: '.5rem',
|
|
@@ -2841,18 +2851,7 @@ function DefaultErrorBoundary(_ref5) {
|
|
|
2841
2851
|
padding: '.5rem',
|
|
2842
2852
|
color: 'red'
|
|
2843
2853
|
}
|
|
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."));
|
|
2854
|
+
}, error.message) : null)));
|
|
2856
2855
|
}
|
|
2857
2856
|
function usePrompt(message, when) {
|
|
2858
2857
|
const router = useRouter();
|
|
@@ -2869,15 +2868,15 @@ function usePrompt(message, when) {
|
|
|
2869
2868
|
return unblock;
|
|
2870
2869
|
}, [when, location, message]);
|
|
2871
2870
|
}
|
|
2872
|
-
function Prompt(
|
|
2871
|
+
function Prompt(_ref7) {
|
|
2873
2872
|
let {
|
|
2874
2873
|
message,
|
|
2875
2874
|
when,
|
|
2876
2875
|
children
|
|
2877
|
-
} =
|
|
2876
|
+
} = _ref7;
|
|
2878
2877
|
usePrompt(message, when != null ? when : true);
|
|
2879
2878
|
return children != null ? children : null;
|
|
2880
2879
|
}
|
|
2881
2880
|
|
|
2882
|
-
export { DefaultErrorBoundary, MatchesProvider, Outlet, Prompt, RouterProvider,
|
|
2881
|
+
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
2882
|
//# sourceMappingURL=index.js.map
|