@tanstack/react-router 0.0.1-beta.2 → 0.0.1-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/react-router/src/index.js +117 -116
- package/build/cjs/react-router/src/index.js.map +1 -1
- package/build/cjs/router-core/build/esm/index.js +257 -227
- package/build/cjs/router-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +362 -342
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +29 -29
- package/build/types/index.d.ts +61 -31
- package/build/umd/index.development.js +373 -342
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -2
- package/src/index.tsx +260 -192
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) {
|
|
@@ -1432,7 +1427,7 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
|
|
|
1432
1427
|
};
|
|
1433
1428
|
};
|
|
1434
1429
|
|
|
1435
|
-
const
|
|
1430
|
+
const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
|
|
1436
1431
|
function createRouteMatch(router, route, opts) {
|
|
1437
1432
|
const routeMatch = _extends({}, route, opts, {
|
|
1438
1433
|
router,
|
|
@@ -1442,10 +1437,10 @@ function createRouteMatch(router, route, opts) {
|
|
|
1442
1437
|
status: 'idle',
|
|
1443
1438
|
routeLoaderData: {},
|
|
1444
1439
|
loaderData: {},
|
|
1445
|
-
isPending: false,
|
|
1446
1440
|
isFetching: false,
|
|
1447
1441
|
isInvalid: false,
|
|
1448
1442
|
invalidAt: Infinity,
|
|
1443
|
+
// pendingActions: [],
|
|
1449
1444
|
getIsInvalid: () => {
|
|
1450
1445
|
const now = Date.now();
|
|
1451
1446
|
return routeMatch.isInvalid || routeMatch.invalidAt < now;
|
|
@@ -1459,43 +1454,6 @@ function createRouteMatch(router, route, opts) {
|
|
|
1459
1454
|
|
|
1460
1455
|
routeMatch.router.notify();
|
|
1461
1456
|
},
|
|
1462
|
-
startPending: () => {
|
|
1463
|
-
var _routeMatch$options$p, _routeMatch$options$p2;
|
|
1464
|
-
|
|
1465
|
-
const pendingMs = (_routeMatch$options$p = routeMatch.options.pendingMs) != null ? _routeMatch$options$p : router.options.defaultPendingMs;
|
|
1466
|
-
const pendingMinMs = (_routeMatch$options$p2 = routeMatch.options.pendingMinMs) != null ? _routeMatch$options$p2 : router.options.defaultPendingMinMs;
|
|
1467
|
-
|
|
1468
|
-
if (routeMatch.__.pendingTimeout || routeMatch.status !== 'loading' || typeof pendingMs === 'undefined') {
|
|
1469
|
-
return;
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
routeMatch.__.pendingTimeout = setTimeout(() => {
|
|
1473
|
-
routeMatch.isPending = true;
|
|
1474
|
-
|
|
1475
|
-
routeMatch.__.resolve();
|
|
1476
|
-
|
|
1477
|
-
if (typeof pendingMinMs !== 'undefined') {
|
|
1478
|
-
routeMatch.__.pendingMinPromise = new Promise(r => routeMatch.__.pendingMinTimeout = setTimeout(r, pendingMinMs));
|
|
1479
|
-
}
|
|
1480
|
-
}, pendingMs);
|
|
1481
|
-
},
|
|
1482
|
-
cancelPending: () => {
|
|
1483
|
-
routeMatch.isPending = false;
|
|
1484
|
-
clearTimeout(routeMatch.__.pendingTimeout);
|
|
1485
|
-
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
1486
|
-
delete routeMatch.__.pendingMinPromise;
|
|
1487
|
-
},
|
|
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
1457
|
validate: () => {
|
|
1500
1458
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1501
1459
|
|
|
@@ -1503,9 +1461,11 @@ function createRouteMatch(router, route, opts) {
|
|
|
1503
1461
|
const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
|
|
1504
1462
|
|
|
1505
1463
|
try {
|
|
1464
|
+
var _validator;
|
|
1465
|
+
|
|
1506
1466
|
const prevSearch = routeMatch.routeSearch;
|
|
1507
1467
|
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
|
|
1468
|
+
let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {}); // Invalidate route matches when search param stability changes
|
|
1509
1469
|
|
|
1510
1470
|
if (prevSearch !== nextSearch) {
|
|
1511
1471
|
routeMatch.isInvalid = true;
|
|
@@ -1513,6 +1473,13 @@ function createRouteMatch(router, route, opts) {
|
|
|
1513
1473
|
|
|
1514
1474
|
routeMatch.routeSearch = nextSearch;
|
|
1515
1475
|
routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
|
|
1476
|
+
componentTypes.map(async type => {
|
|
1477
|
+
const component = routeMatch.options[type];
|
|
1478
|
+
|
|
1479
|
+
if (typeof routeMatch.__[type] !== 'function') {
|
|
1480
|
+
routeMatch.__[type] = component;
|
|
1481
|
+
}
|
|
1482
|
+
});
|
|
1516
1483
|
} catch (err) {
|
|
1517
1484
|
console.error(err);
|
|
1518
1485
|
const error = new Error('Invalid search params found', {
|
|
@@ -1530,14 +1497,16 @@ function createRouteMatch(router, route, opts) {
|
|
|
1530
1497
|
var _routeMatch$__$abortC;
|
|
1531
1498
|
|
|
1532
1499
|
(_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
|
|
1533
|
-
|
|
1534
|
-
routeMatch.__.cancelPending();
|
|
1535
1500
|
},
|
|
1536
1501
|
invalidate: () => {
|
|
1537
1502
|
routeMatch.isInvalid = true;
|
|
1538
1503
|
},
|
|
1539
1504
|
hasLoaders: () => {
|
|
1540
|
-
return !!(route.options.loader ||
|
|
1505
|
+
return !!(route.options.loader || componentTypes.some(d => {
|
|
1506
|
+
var _route$options$d;
|
|
1507
|
+
|
|
1508
|
+
return (_route$options$d = route.options[d]) == null ? void 0 : _route$options$d.preload;
|
|
1509
|
+
}));
|
|
1541
1510
|
},
|
|
1542
1511
|
load: async loaderOpts => {
|
|
1543
1512
|
const now = Date.now();
|
|
@@ -1558,17 +1527,25 @@ function createRouteMatch(router, route, opts) {
|
|
|
1558
1527
|
|
|
1559
1528
|
if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
|
|
1560
1529
|
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
1561
|
-
routeMatch.fetch({
|
|
1530
|
+
await routeMatch.fetch({
|
|
1562
1531
|
maxAge
|
|
1563
1532
|
});
|
|
1564
1533
|
}
|
|
1565
1534
|
},
|
|
1566
1535
|
fetch: async opts => {
|
|
1567
|
-
const
|
|
1568
|
-
routeMatch.__.latestId =
|
|
1536
|
+
const loadId = '' + Date.now() + Math.random();
|
|
1537
|
+
routeMatch.__.latestId = loadId;
|
|
1538
|
+
|
|
1539
|
+
const checkLatest = async () => {
|
|
1540
|
+
if (loadId !== routeMatch.__.latestId) {
|
|
1541
|
+
// warning(true, 'Data loader is out of date!')
|
|
1542
|
+
return new Promise(() => {});
|
|
1543
|
+
}
|
|
1544
|
+
}; // If the match was in an error state, set it
|
|
1569
1545
|
// to a loading state again. Otherwise, keep it
|
|
1570
1546
|
// as loading or resolved
|
|
1571
1547
|
|
|
1548
|
+
|
|
1572
1549
|
if (routeMatch.status === 'idle') {
|
|
1573
1550
|
routeMatch.status = 'loading';
|
|
1574
1551
|
} // We started loading the route, so it's no longer invalid
|
|
@@ -1581,94 +1558,66 @@ function createRouteMatch(router, route, opts) {
|
|
|
1581
1558
|
routeMatch.isFetching = true;
|
|
1582
1559
|
routeMatch.__.resolve = resolve;
|
|
1583
1560
|
|
|
1584
|
-
|
|
1585
|
-
//
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
await Promise.all(elementTypes.map(async type => {
|
|
1590
|
-
const routeElement = routeMatch.options[type];
|
|
1591
|
-
|
|
1592
|
-
if (routeMatch.__[type]) {
|
|
1593
|
-
return;
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
routeMatch.__[type] = await router.options.createElement(routeElement);
|
|
1597
|
-
}));
|
|
1598
|
-
})();
|
|
1599
|
-
|
|
1600
|
-
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1601
|
-
try {
|
|
1602
|
-
var _ref, _ref2, _opts$maxAge;
|
|
1561
|
+
routeMatch.__.componentsPromise = (async () => {
|
|
1562
|
+
// then run all component and data loaders in parallel
|
|
1563
|
+
// For each component type, potentially load it asynchronously
|
|
1564
|
+
await Promise.all(componentTypes.map(async type => {
|
|
1565
|
+
var _routeMatch$__$type;
|
|
1603
1566
|
|
|
1604
|
-
|
|
1605
|
-
const data = await routeMatch.options.loader({
|
|
1606
|
-
params: routeMatch.params,
|
|
1607
|
-
search: routeMatch.routeSearch,
|
|
1608
|
-
signal: routeMatch.__.abortController.signal
|
|
1609
|
-
});
|
|
1567
|
+
const component = routeMatch.options[type];
|
|
1610
1568
|
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1616
|
-
}
|
|
1617
|
-
|
|
1618
|
-
routeMatch.error = undefined;
|
|
1619
|
-
routeMatch.status = 'success';
|
|
1620
|
-
routeMatch.updatedAt = Date.now();
|
|
1621
|
-
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
|
-
} catch (err) {
|
|
1623
|
-
if (id !== routeMatch.__.latestId) {
|
|
1624
|
-
return routeMatch.__.loaderPromise;
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1628
|
-
console.error(err);
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
routeMatch.error = err;
|
|
1632
|
-
routeMatch.status = 'error';
|
|
1633
|
-
routeMatch.updatedAt = Date.now();
|
|
1569
|
+
if ((_routeMatch$__$type = routeMatch.__[type]) != null && _routeMatch$__$type.preload) {
|
|
1570
|
+
routeMatch.__[type] = await router.options.loadComponent(component);
|
|
1634
1571
|
}
|
|
1635
|
-
});
|
|
1572
|
+
}));
|
|
1573
|
+
})();
|
|
1636
1574
|
|
|
1575
|
+
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1637
1576
|
try {
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
if (id !== routeMatch.__.latestId) {
|
|
1641
|
-
return routeMatch.__.loaderPromise;
|
|
1642
|
-
}
|
|
1577
|
+
var _ref, _ref2, _opts$maxAge;
|
|
1643
1578
|
|
|
1644
|
-
if (routeMatch.
|
|
1645
|
-
await routeMatch
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
} finally {
|
|
1649
|
-
if (id !== routeMatch.__.latestId) {
|
|
1650
|
-
return routeMatch.__.loaderPromise;
|
|
1579
|
+
if (routeMatch.options.loader) {
|
|
1580
|
+
const data = await router.loadMatchData(routeMatch);
|
|
1581
|
+
await checkLatest();
|
|
1582
|
+
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1651
1583
|
}
|
|
1652
1584
|
|
|
1653
|
-
routeMatch.
|
|
1585
|
+
routeMatch.error = undefined;
|
|
1586
|
+
routeMatch.status = 'success';
|
|
1587
|
+
routeMatch.updatedAt = Date.now();
|
|
1588
|
+
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);
|
|
1589
|
+
return routeMatch.routeLoaderData;
|
|
1590
|
+
} catch (err) {
|
|
1591
|
+
await checkLatest();
|
|
1654
1592
|
|
|
1655
|
-
|
|
1656
|
-
|
|
1593
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1594
|
+
console.error(err);
|
|
1595
|
+
}
|
|
1657
1596
|
|
|
1658
|
-
routeMatch.
|
|
1597
|
+
routeMatch.error = err;
|
|
1598
|
+
routeMatch.status = 'error';
|
|
1599
|
+
routeMatch.updatedAt = Date.now();
|
|
1600
|
+
throw err;
|
|
1659
1601
|
}
|
|
1660
|
-
})
|
|
1602
|
+
});
|
|
1661
1603
|
|
|
1662
|
-
|
|
1663
|
-
|
|
1604
|
+
const after = async () => {
|
|
1605
|
+
await checkLatest();
|
|
1606
|
+
routeMatch.isFetching = false;
|
|
1607
|
+
delete routeMatch.__.loadPromise;
|
|
1664
1608
|
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
}
|
|
1609
|
+
routeMatch.__.notify();
|
|
1610
|
+
};
|
|
1668
1611
|
|
|
1669
|
-
|
|
1612
|
+
try {
|
|
1613
|
+
await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise.catch(() => {})]);
|
|
1614
|
+
after();
|
|
1615
|
+
} catch (_unused) {
|
|
1616
|
+
after();
|
|
1617
|
+
}
|
|
1670
1618
|
});
|
|
1671
|
-
|
|
1619
|
+
await routeMatch.__.loadPromise;
|
|
1620
|
+
await checkLatest();
|
|
1672
1621
|
}
|
|
1673
1622
|
});
|
|
1674
1623
|
|
|
@@ -1729,9 +1678,22 @@ function stringifySearchWith(stringify) {
|
|
|
1729
1678
|
|
|
1730
1679
|
var _window$document;
|
|
1731
1680
|
// Detect if we're in the DOM
|
|
1732
|
-
const isServer =
|
|
1681
|
+
const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement); // This is the default history object if none is defined
|
|
1682
|
+
|
|
1683
|
+
const createDefaultHistory = () => isServer ? createMemoryHistory() : createBrowserHistory();
|
|
1733
1684
|
|
|
1734
|
-
|
|
1685
|
+
function getInitialRouterState() {
|
|
1686
|
+
return {
|
|
1687
|
+
status: 'idle',
|
|
1688
|
+
location: null,
|
|
1689
|
+
matches: [],
|
|
1690
|
+
actions: {},
|
|
1691
|
+
loaders: {},
|
|
1692
|
+
lastUpdated: Date.now(),
|
|
1693
|
+
isFetching: false,
|
|
1694
|
+
isPreloading: false
|
|
1695
|
+
};
|
|
1696
|
+
}
|
|
1735
1697
|
|
|
1736
1698
|
function createRouter(userOptions) {
|
|
1737
1699
|
var _userOptions$stringif, _userOptions$parseSea;
|
|
@@ -1749,30 +1711,24 @@ function createRouter(userOptions) {
|
|
|
1749
1711
|
});
|
|
1750
1712
|
|
|
1751
1713
|
let router = {
|
|
1714
|
+
types: undefined,
|
|
1715
|
+
// public api
|
|
1752
1716
|
history,
|
|
1753
1717
|
options: originalOptions,
|
|
1754
1718
|
listeners: [],
|
|
1755
|
-
removeActionQueue: [],
|
|
1756
1719
|
// Resolved after construction
|
|
1757
1720
|
basepath: '',
|
|
1758
1721
|
routeTree: undefined,
|
|
1759
1722
|
routesById: {},
|
|
1760
1723
|
location: undefined,
|
|
1761
|
-
allRouteInfo: undefined,
|
|
1762
1724
|
//
|
|
1763
1725
|
navigationPromise: Promise.resolve(),
|
|
1764
1726
|
resolveNavigation: () => {},
|
|
1765
1727
|
matchCache: {},
|
|
1766
|
-
state:
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
actions: {},
|
|
1771
|
-
loaders: {},
|
|
1772
|
-
loaderData: {},
|
|
1773
|
-
lastUpdated: Date.now(),
|
|
1774
|
-
isFetching: false,
|
|
1775
|
-
isPreloading: false
|
|
1728
|
+
state: getInitialRouterState(),
|
|
1729
|
+
reset: () => {
|
|
1730
|
+
router.state = getInitialRouterState();
|
|
1731
|
+
router.notify();
|
|
1776
1732
|
},
|
|
1777
1733
|
startedLoadingAt: Date.now(),
|
|
1778
1734
|
subscribe: listener => {
|
|
@@ -1785,13 +1741,39 @@ function createRouter(userOptions) {
|
|
|
1785
1741
|
return router.routesById[id];
|
|
1786
1742
|
},
|
|
1787
1743
|
notify: () => {
|
|
1788
|
-
router.state
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1744
|
+
const isFetching = router.state.status === 'loading' || router.state.matches.some(d => d.isFetching);
|
|
1745
|
+
const isPreloading = Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId));
|
|
1746
|
+
|
|
1747
|
+
if (router.state.isFetching !== isFetching || router.state.isPreloading !== isPreloading) {
|
|
1748
|
+
router.state = _extends({}, router.state, {
|
|
1749
|
+
isFetching,
|
|
1750
|
+
isPreloading
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1792
1754
|
cascadeLoaderData(router.state.matches);
|
|
1793
1755
|
router.listeners.forEach(listener => listener(router));
|
|
1794
1756
|
},
|
|
1757
|
+
dehydrateState: () => {
|
|
1758
|
+
return _extends({}, pick(router.state, ['status', 'location', 'lastUpdated']), {
|
|
1759
|
+
matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
|
|
1760
|
+
});
|
|
1761
|
+
},
|
|
1762
|
+
hydrateState: dehydratedState => {
|
|
1763
|
+
// Match the routes
|
|
1764
|
+
const matches = router.matchRoutes(router.location.pathname, {
|
|
1765
|
+
strictParseParams: true
|
|
1766
|
+
});
|
|
1767
|
+
matches.forEach((match, index) => {
|
|
1768
|
+
const dehydratedMatch = dehydratedState.matches[index];
|
|
1769
|
+
invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
|
|
1770
|
+
Object.assign(match, dehydratedMatch);
|
|
1771
|
+
});
|
|
1772
|
+
matches.forEach(match => match.__.validate());
|
|
1773
|
+
router.state = _extends({}, router.state, dehydratedState, {
|
|
1774
|
+
matches
|
|
1775
|
+
});
|
|
1776
|
+
},
|
|
1795
1777
|
mount: () => {
|
|
1796
1778
|
const next = router.__.buildLocation({
|
|
1797
1779
|
to: '.',
|
|
@@ -1803,12 +1785,14 @@ function createRouter(userOptions) {
|
|
|
1803
1785
|
|
|
1804
1786
|
if (next.href !== router.location.href) {
|
|
1805
1787
|
router.__.commitLocation(next, true);
|
|
1806
|
-
} else {
|
|
1807
|
-
router.loadLocation();
|
|
1808
1788
|
}
|
|
1809
1789
|
|
|
1810
|
-
|
|
1811
|
-
router.
|
|
1790
|
+
if (!router.state.matches.length) {
|
|
1791
|
+
router.load();
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
const unsub = router.history.listen(event => {
|
|
1795
|
+
router.load(router.__.parseLocation(event.location, router.location));
|
|
1812
1796
|
}); // addEventListener does not exist in React Native, but window does
|
|
1813
1797
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1814
1798
|
|
|
@@ -1819,16 +1803,30 @@ function createRouter(userOptions) {
|
|
|
1819
1803
|
}
|
|
1820
1804
|
|
|
1821
1805
|
return () => {
|
|
1822
|
-
unsub();
|
|
1806
|
+
unsub();
|
|
1823
1807
|
|
|
1824
|
-
window.removeEventListener
|
|
1825
|
-
|
|
1808
|
+
if (!isServer && window.removeEventListener) {
|
|
1809
|
+
// Be sure to unsubscribe if a new handler is set
|
|
1810
|
+
window.removeEventListener('visibilitychange', router.onFocus);
|
|
1811
|
+
window.removeEventListener('focus', router.onFocus);
|
|
1812
|
+
}
|
|
1826
1813
|
};
|
|
1827
1814
|
},
|
|
1828
1815
|
onFocus: () => {
|
|
1829
|
-
router.
|
|
1816
|
+
router.load();
|
|
1830
1817
|
},
|
|
1831
1818
|
update: opts => {
|
|
1819
|
+
const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
|
|
1820
|
+
|
|
1821
|
+
if (!router.location || newHistory) {
|
|
1822
|
+
if (opts != null && opts.history) {
|
|
1823
|
+
router.history = opts.history;
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
router.location = router.__.parseLocation(router.history.location);
|
|
1827
|
+
router.state.location = router.location;
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1832
1830
|
Object.assign(router.options, opts);
|
|
1833
1831
|
const {
|
|
1834
1832
|
basepath,
|
|
@@ -1849,49 +1847,41 @@ function createRouter(userOptions) {
|
|
|
1849
1847
|
match.cancel();
|
|
1850
1848
|
});
|
|
1851
1849
|
},
|
|
1852
|
-
|
|
1850
|
+
load: async next => {
|
|
1853
1851
|
const id = Math.random();
|
|
1854
1852
|
router.startedLoadingAt = id;
|
|
1855
1853
|
|
|
1856
1854
|
if (next) {
|
|
1857
1855
|
// Ingest the new location
|
|
1858
1856
|
router.location = next;
|
|
1859
|
-
} //
|
|
1857
|
+
} // Cancel any pending matches
|
|
1860
1858
|
|
|
1861
1859
|
|
|
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
|
-
|
|
1878
1860
|
router.cancelMatches(); // Match the routes
|
|
1879
1861
|
|
|
1880
|
-
const matches = router.matchRoutes(location.pathname, {
|
|
1862
|
+
const matches = router.matchRoutes(router.location.pathname, {
|
|
1881
1863
|
strictParseParams: true
|
|
1882
1864
|
});
|
|
1883
|
-
|
|
1884
|
-
|
|
1865
|
+
|
|
1866
|
+
if (typeof document !== 'undefined') {
|
|
1867
|
+
router.state = _extends({}, router.state, {
|
|
1868
|
+
pending: {
|
|
1869
|
+
matches: matches,
|
|
1870
|
+
location: router.location
|
|
1871
|
+
},
|
|
1872
|
+
status: 'loading'
|
|
1873
|
+
});
|
|
1874
|
+
} else {
|
|
1875
|
+
router.state = _extends({}, router.state, {
|
|
1885
1876
|
matches: matches,
|
|
1886
|
-
location: router.location
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
}
|
|
1877
|
+
location: router.location,
|
|
1878
|
+
status: 'loading'
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1890
1882
|
router.notify(); // Load the matches
|
|
1891
1883
|
|
|
1892
|
-
await router.loadMatches(matches
|
|
1893
|
-
withPending: true
|
|
1894
|
-
});
|
|
1884
|
+
await router.loadMatches(matches);
|
|
1895
1885
|
|
|
1896
1886
|
if (router.startedLoadingAt !== id) {
|
|
1897
1887
|
// Ignore side-effects of match loading
|
|
@@ -1908,9 +1898,12 @@ function createRouter(userOptions) {
|
|
|
1908
1898
|
exiting.push(d);
|
|
1909
1899
|
}
|
|
1910
1900
|
});
|
|
1901
|
+
const entering = matches.filter(d => {
|
|
1902
|
+
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
1903
|
+
});
|
|
1911
1904
|
const now = Date.now();
|
|
1912
1905
|
exiting.forEach(d => {
|
|
1913
|
-
var
|
|
1906
|
+
var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
|
|
1914
1907
|
|
|
1915
1908
|
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
1916
1909
|
params: d.params,
|
|
@@ -1922,7 +1915,7 @@ function createRouter(userOptions) {
|
|
|
1922
1915
|
d.error = undefined;
|
|
1923
1916
|
}
|
|
1924
1917
|
|
|
1925
|
-
const gc = Math.max((
|
|
1918
|
+
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
1919
|
|
|
1927
1920
|
if (gc > 0) {
|
|
1928
1921
|
router.matchCache[d.matchId] = {
|
|
@@ -1937,9 +1930,6 @@ function createRouter(userOptions) {
|
|
|
1937
1930
|
search: d.routeSearch
|
|
1938
1931
|
});
|
|
1939
1932
|
});
|
|
1940
|
-
const entering = matches.filter(d => {
|
|
1941
|
-
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
1942
|
-
});
|
|
1943
1933
|
entering.forEach(d => {
|
|
1944
1934
|
d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
|
|
1945
1935
|
params: d.params,
|
|
@@ -1948,16 +1938,18 @@ function createRouter(userOptions) {
|
|
|
1948
1938
|
delete router.matchCache[d.matchId];
|
|
1949
1939
|
});
|
|
1950
1940
|
|
|
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
1941
|
if (router.startedLoadingAt !== id) {
|
|
1957
1942
|
// Ignore side-effects of match loading
|
|
1958
1943
|
return;
|
|
1959
1944
|
}
|
|
1960
1945
|
|
|
1946
|
+
matches.forEach(match => {
|
|
1947
|
+
// Clear actions
|
|
1948
|
+
if (match.action) {
|
|
1949
|
+
match.action.current = undefined;
|
|
1950
|
+
match.action.submissions = [];
|
|
1951
|
+
}
|
|
1952
|
+
});
|
|
1961
1953
|
router.state = _extends({}, router.state, {
|
|
1962
1954
|
location: router.location,
|
|
1963
1955
|
matches,
|
|
@@ -1998,7 +1990,7 @@ function createRouter(userOptions) {
|
|
|
1998
1990
|
return matches;
|
|
1999
1991
|
},
|
|
2000
1992
|
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
2001
|
-
var
|
|
1993
|
+
var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
|
|
2002
1994
|
|
|
2003
1995
|
if (navigateOpts === void 0) {
|
|
2004
1996
|
navigateOpts = router.location;
|
|
@@ -2010,8 +2002,8 @@ function createRouter(userOptions) {
|
|
|
2010
2002
|
});
|
|
2011
2003
|
await router.loadMatches(matches, {
|
|
2012
2004
|
preload: true,
|
|
2013
|
-
maxAge: (
|
|
2014
|
-
gcMaxAge: (
|
|
2005
|
+
maxAge: (_ref3 = (_ref4 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref4 : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0,
|
|
2006
|
+
gcMaxAge: (_ref5 = (_ref6 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref6 : router.options.defaultLoaderGcMaxAge) != null ? _ref5 : 0
|
|
2015
2007
|
});
|
|
2016
2008
|
return matches;
|
|
2017
2009
|
},
|
|
@@ -2087,6 +2079,7 @@ function createRouter(userOptions) {
|
|
|
2087
2079
|
const interpolatedPath = interpolatePath(foundRoute.routePath, params);
|
|
2088
2080
|
const matchId = interpolatePath(foundRoute.routeId, params, true);
|
|
2089
2081
|
const match = existingMatches.find(d => d.matchId === matchId) || ((_router$matchCache$ma = router.matchCache[matchId]) == null ? void 0 : _router$matchCache$ma.match) || createRouteMatch(router, foundRoute, {
|
|
2082
|
+
parentMatch,
|
|
2090
2083
|
matchId,
|
|
2091
2084
|
params,
|
|
2092
2085
|
pathname: joinPaths([pathname, interpolatedPath])
|
|
@@ -2110,18 +2103,51 @@ function createRouter(userOptions) {
|
|
|
2110
2103
|
match.__.validate();
|
|
2111
2104
|
|
|
2112
2105
|
match.load(loaderOpts);
|
|
2106
|
+
const search = match.search;
|
|
2113
2107
|
|
|
2114
|
-
if (
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
// This might be completion, error, or a pending state
|
|
2108
|
+
if (search.__data && search.__data.matchId !== match.matchId) {
|
|
2109
|
+
return;
|
|
2110
|
+
}
|
|
2118
2111
|
|
|
2112
|
+
if (match.__.loadPromise) {
|
|
2113
|
+
// Wait for the first sign of activity from the match
|
|
2119
2114
|
await match.__.loadPromise;
|
|
2120
2115
|
}
|
|
2121
2116
|
});
|
|
2122
2117
|
router.notify();
|
|
2123
2118
|
await Promise.all(matchPromises);
|
|
2124
2119
|
},
|
|
2120
|
+
loadMatchData: async routeMatch => {
|
|
2121
|
+
if (isServer || !router.options.useServerData) {
|
|
2122
|
+
var _await$routeMatch$opt;
|
|
2123
|
+
|
|
2124
|
+
return (_await$routeMatch$opt = await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
|
|
2125
|
+
// parentLoaderPromise: routeMatch.parentMatch?.__.dataPromise,
|
|
2126
|
+
params: routeMatch.params,
|
|
2127
|
+
search: routeMatch.routeSearch,
|
|
2128
|
+
signal: routeMatch.__.abortController.signal
|
|
2129
|
+
}))) != null ? _await$routeMatch$opt : {};
|
|
2130
|
+
} else {
|
|
2131
|
+
const next = router.buildNext({
|
|
2132
|
+
to: '.',
|
|
2133
|
+
search: d => _extends({}, d != null ? d : {}, {
|
|
2134
|
+
__data: {
|
|
2135
|
+
matchId: routeMatch.matchId
|
|
2136
|
+
}
|
|
2137
|
+
})
|
|
2138
|
+
});
|
|
2139
|
+
const res = await fetch(next.href, {
|
|
2140
|
+
method: 'GET' // signal: routeMatch.__.abortController.signal,
|
|
2141
|
+
|
|
2142
|
+
});
|
|
2143
|
+
|
|
2144
|
+
if (res.ok) {
|
|
2145
|
+
return res.json();
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
throw new Error('Failed to fetch match data');
|
|
2149
|
+
}
|
|
2150
|
+
},
|
|
2125
2151
|
invalidateRoute: opts => {
|
|
2126
2152
|
var _router$state$pending5, _router$state$pending6;
|
|
2127
2153
|
|
|
@@ -2166,7 +2192,7 @@ function createRouter(userOptions) {
|
|
|
2166
2192
|
to: next.pathname
|
|
2167
2193
|
}));
|
|
2168
2194
|
},
|
|
2169
|
-
navigate: async
|
|
2195
|
+
navigate: async _ref7 => {
|
|
2170
2196
|
let {
|
|
2171
2197
|
from,
|
|
2172
2198
|
to = '.',
|
|
@@ -2174,7 +2200,7 @@ function createRouter(userOptions) {
|
|
|
2174
2200
|
hash,
|
|
2175
2201
|
replace,
|
|
2176
2202
|
params
|
|
2177
|
-
} =
|
|
2203
|
+
} = _ref7;
|
|
2178
2204
|
// If this link simply reloads the current route,
|
|
2179
2205
|
// make sure it has a new key so it will trigger a data refresh
|
|
2180
2206
|
// If this `to` is a valid external URL, return
|
|
@@ -2198,8 +2224,8 @@ function createRouter(userOptions) {
|
|
|
2198
2224
|
params
|
|
2199
2225
|
});
|
|
2200
2226
|
},
|
|
2201
|
-
buildLink:
|
|
2202
|
-
var _preload,
|
|
2227
|
+
buildLink: _ref8 => {
|
|
2228
|
+
var _preload, _ref9;
|
|
2203
2229
|
|
|
2204
2230
|
let {
|
|
2205
2231
|
from,
|
|
@@ -2215,7 +2241,7 @@ function createRouter(userOptions) {
|
|
|
2215
2241
|
preloadGcMaxAge: userPreloadGcMaxAge,
|
|
2216
2242
|
preloadDelay: userPreloadDelay,
|
|
2217
2243
|
disabled
|
|
2218
|
-
} =
|
|
2244
|
+
} = _ref8;
|
|
2219
2245
|
|
|
2220
2246
|
// If this link simply reloads the current route,
|
|
2221
2247
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -2239,7 +2265,7 @@ function createRouter(userOptions) {
|
|
|
2239
2265
|
};
|
|
2240
2266
|
const next = router.buildNext(nextOpts);
|
|
2241
2267
|
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
2242
|
-
const preloadDelay = (
|
|
2268
|
+
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0; // Compare path/hash for matches
|
|
2243
2269
|
|
|
2244
2270
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
2245
2271
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
@@ -2340,11 +2366,7 @@ function createRouter(userOptions) {
|
|
|
2340
2366
|
const recurseRoutes = (routeConfigs, parent) => {
|
|
2341
2367
|
return routeConfigs.map(routeConfig => {
|
|
2342
2368
|
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
|
-
|
|
2369
|
+
const route = createRoute(routeConfig, routeOptions, parent, router);
|
|
2348
2370
|
const existingRoute = router.routesById[route.routeId];
|
|
2349
2371
|
|
|
2350
2372
|
if (existingRoute) {
|
|
@@ -2454,9 +2476,9 @@ function createRouter(userOptions) {
|
|
|
2454
2476
|
pathname: next.pathname,
|
|
2455
2477
|
hash: next.hash,
|
|
2456
2478
|
search: next.searchStr
|
|
2457
|
-
}, {
|
|
2479
|
+
}, _extends({
|
|
2458
2480
|
id
|
|
2459
|
-
});
|
|
2481
|
+
}, next.state));
|
|
2460
2482
|
} else {
|
|
2461
2483
|
history.push({
|
|
2462
2484
|
pathname: next.pathname,
|
|
@@ -2479,8 +2501,6 @@ function createRouter(userOptions) {
|
|
|
2479
2501
|
}
|
|
2480
2502
|
}
|
|
2481
2503
|
};
|
|
2482
|
-
router.location = router.__.parseLocation(history.location);
|
|
2483
|
-
router.state.location = router.location;
|
|
2484
2504
|
router.update(userOptions); // Allow frameworks to hook into the router creation
|
|
2485
2505
|
|
|
2486
2506
|
router.options.createRouter == null ? void 0 : router.options.createRouter(router);
|
|
@@ -2491,15 +2511,51 @@ function isCtrlEvent(e) {
|
|
|
2491
2511
|
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
2492
2512
|
}
|
|
2493
2513
|
|
|
2514
|
+
function cascadeLoaderData(matches) {
|
|
2515
|
+
matches.forEach((match, index) => {
|
|
2516
|
+
const parent = matches[index - 1];
|
|
2517
|
+
|
|
2518
|
+
if (parent) {
|
|
2519
|
+
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
2520
|
+
}
|
|
2521
|
+
});
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2494
2524
|
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
2525
|
_excluded2 = ["pending", "caseSensitive", "children"],
|
|
2496
2526
|
_excluded3 = ["children", "router"];
|
|
2527
|
+
function lazy(importer) {
|
|
2528
|
+
const lazyComp = /*#__PURE__*/React.lazy(importer);
|
|
2529
|
+
let promise;
|
|
2530
|
+
let resolvedComp;
|
|
2531
|
+
const forwardedComp = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
2532
|
+
const resolvedCompRef = React.useRef(resolvedComp || lazyComp);
|
|
2533
|
+
return /*#__PURE__*/React.createElement(resolvedCompRef.current, _extends$2({}, ref ? {
|
|
2534
|
+
ref
|
|
2535
|
+
} : {}, props));
|
|
2536
|
+
});
|
|
2537
|
+
const finalComp = forwardedComp;
|
|
2538
|
+
|
|
2539
|
+
finalComp.preload = () => {
|
|
2540
|
+
if (!promise) {
|
|
2541
|
+
promise = importer().then(module => {
|
|
2542
|
+
resolvedComp = module.default;
|
|
2543
|
+
return resolvedComp;
|
|
2544
|
+
});
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
return promise;
|
|
2548
|
+
};
|
|
2549
|
+
|
|
2550
|
+
return finalComp;
|
|
2551
|
+
}
|
|
2497
2552
|
//
|
|
2553
|
+
function Link(props) {
|
|
2554
|
+
const router = useRouter();
|
|
2555
|
+
return /*#__PURE__*/React.createElement(router.Link, props);
|
|
2556
|
+
}
|
|
2498
2557
|
const matchesContext = /*#__PURE__*/React.createContext(null);
|
|
2499
|
-
const routerContext = /*#__PURE__*/React.createContext(null);
|
|
2500
|
-
|
|
2501
|
-
const isDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
2502
|
-
const useLayoutEffect = isDOM ? React.useLayoutEffect : React.useEffect;
|
|
2558
|
+
const routerContext = /*#__PURE__*/React.createContext(null);
|
|
2503
2559
|
function MatchesProvider(props) {
|
|
2504
2560
|
return /*#__PURE__*/React.createElement(matchesContext.Provider, props);
|
|
2505
2561
|
}
|
|
@@ -2563,6 +2619,12 @@ function createReactRouter(opts) {
|
|
|
2563
2619
|
next
|
|
2564
2620
|
} = linkInfo;
|
|
2565
2621
|
|
|
2622
|
+
const reactHandleClick = e => {
|
|
2623
|
+
React.startTransition(() => {
|
|
2624
|
+
handleClick(e);
|
|
2625
|
+
});
|
|
2626
|
+
};
|
|
2627
|
+
|
|
2566
2628
|
const composeHandlers = handlers => e => {
|
|
2567
2629
|
e.persist();
|
|
2568
2630
|
handlers.forEach(handler => {
|
|
@@ -2576,7 +2638,7 @@ function createReactRouter(opts) {
|
|
|
2576
2638
|
const resolvedInactiveProps = isActive ? {} : (_functionalUpdate2 = functionalUpdate(inactiveProps, {})) != null ? _functionalUpdate2 : {};
|
|
2577
2639
|
return _extends$2({}, resolvedActiveProps, resolvedInactiveProps, rest, {
|
|
2578
2640
|
href: disabled ? undefined : next.href,
|
|
2579
|
-
onClick: composeHandlers([
|
|
2641
|
+
onClick: composeHandlers([reactHandleClick, onClick]),
|
|
2580
2642
|
onFocus: composeHandlers([handleFocus, onFocus]),
|
|
2581
2643
|
onMouseEnter: composeHandlers([handleEnter, onMouseEnter]),
|
|
2582
2644
|
onMouseLeave: composeHandlers([handleLeave, onMouseLeave]),
|
|
@@ -2629,18 +2691,17 @@ function createReactRouter(opts) {
|
|
|
2629
2691
|
useRouterSubscription(router);
|
|
2630
2692
|
return router.state;
|
|
2631
2693
|
},
|
|
2632
|
-
useMatch: routeId => {
|
|
2694
|
+
useMatch: (routeId, opts) => {
|
|
2695
|
+
var _useMatches, _opts$strict;
|
|
2696
|
+
|
|
2633
2697
|
useRouterSubscription(router);
|
|
2634
2698
|
invariant(routeId !== rootRouteId, "\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
|
|
2635
|
-
|
|
2636
|
-
const runtimeMatch = _useMatch();
|
|
2637
|
-
|
|
2699
|
+
const runtimeMatch = (_useMatches = useMatches()) == null ? void 0 : _useMatches[0];
|
|
2638
2700
|
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
2701
|
|
|
2642
|
-
if (
|
|
2643
|
-
invariant(
|
|
2702
|
+
if ((_opts$strict = opts == null ? void 0 : opts.strict) != null ? _opts$strict : true) {
|
|
2703
|
+
invariant(match, "Could not find an active match for \"" + routeId + "\"!");
|
|
2704
|
+
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
2705
|
}
|
|
2645
2706
|
|
|
2646
2707
|
return match;
|
|
@@ -2657,18 +2718,12 @@ function createReactRouter(opts) {
|
|
|
2657
2718
|
const routeExt = makeRouteExt(route, router);
|
|
2658
2719
|
Object.assign(route, routeExt);
|
|
2659
2720
|
},
|
|
2660
|
-
|
|
2661
|
-
if (typeof
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
if (typeof res === 'object' && res.default) {
|
|
2665
|
-
return /*#__PURE__*/React.createElement(res.default);
|
|
2666
|
-
} else {
|
|
2667
|
-
return res;
|
|
2668
|
-
}
|
|
2721
|
+
loadComponent: async component => {
|
|
2722
|
+
if (component.preload && typeof document !== 'undefined') {
|
|
2723
|
+
component.preload(); // return await component.preload()
|
|
2669
2724
|
}
|
|
2670
2725
|
|
|
2671
|
-
return
|
|
2726
|
+
return component;
|
|
2672
2727
|
}
|
|
2673
2728
|
}));
|
|
2674
2729
|
return coreRouter;
|
|
@@ -2682,101 +2737,84 @@ function RouterProvider(_ref2) {
|
|
|
2682
2737
|
|
|
2683
2738
|
router.update(rest);
|
|
2684
2739
|
useRouterSubscription(router);
|
|
2685
|
-
|
|
2740
|
+
React.useEffect(() => {
|
|
2741
|
+
console.log('hello');
|
|
2686
2742
|
return router.mount();
|
|
2687
2743
|
}, [router]);
|
|
2688
2744
|
return /*#__PURE__*/React.createElement(routerContext.Provider, {
|
|
2689
2745
|
value: {
|
|
2690
|
-
router
|
|
2746
|
+
router: router
|
|
2691
2747
|
}
|
|
2692
2748
|
}, /*#__PURE__*/React.createElement(MatchesProvider, {
|
|
2693
2749
|
value: router.state.matches
|
|
2694
2750
|
}, children != null ? children : /*#__PURE__*/React.createElement(Outlet, null)));
|
|
2695
2751
|
}
|
|
2696
|
-
|
|
2697
2752
|
function useRouter() {
|
|
2698
2753
|
const value = React.useContext(routerContext);
|
|
2699
2754
|
warning(!value, 'useRouter must be used inside a <Router> component!');
|
|
2700
2755
|
useRouterSubscription(value.router);
|
|
2701
2756
|
return value.router;
|
|
2702
2757
|
}
|
|
2703
|
-
|
|
2704
2758
|
function useMatches() {
|
|
2705
2759
|
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
2760
|
}
|
|
2761
|
+
function useMatch(routeId, opts) {
|
|
2762
|
+
const router = useRouter();
|
|
2763
|
+
return router.useMatch(routeId, opts);
|
|
2764
|
+
}
|
|
2765
|
+
function useNearestMatch() {
|
|
2766
|
+
var _useMatches2;
|
|
2722
2767
|
|
|
2768
|
+
const runtimeMatch = (_useMatches2 = useMatches()) == null ? void 0 : _useMatches2[0];
|
|
2769
|
+
invariant(runtimeMatch, "Could not find a nearest match!");
|
|
2770
|
+
return runtimeMatch;
|
|
2771
|
+
}
|
|
2772
|
+
function useRoute(routeId) {
|
|
2773
|
+
const router = useRouter();
|
|
2774
|
+
return router.useRoute(routeId);
|
|
2775
|
+
}
|
|
2776
|
+
function linkProps(props) {
|
|
2777
|
+
const router = useRouter();
|
|
2778
|
+
return router.linkProps(props);
|
|
2779
|
+
}
|
|
2780
|
+
function MatchRoute(props) {
|
|
2781
|
+
const router = useRouter();
|
|
2782
|
+
return /*#__PURE__*/React.createElement(router.MatchRoute, props);
|
|
2783
|
+
}
|
|
2723
2784
|
function Outlet() {
|
|
2724
|
-
var
|
|
2785
|
+
var _ref3, _match$__$pendingComp, _match$__$errorCompon;
|
|
2725
2786
|
|
|
2726
2787
|
const router = useRouter();
|
|
2727
|
-
const
|
|
2728
|
-
const
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
const element = (() => {
|
|
2732
|
-
var _childMatch$__$errorE, _ref4;
|
|
2733
|
-
|
|
2734
|
-
if (!childMatch) {
|
|
2735
|
-
return null;
|
|
2736
|
-
}
|
|
2788
|
+
const matches = useMatches().slice(1);
|
|
2789
|
+
const match = matches[0];
|
|
2790
|
+
const defaultPending = React.useCallback(() => null, []);
|
|
2737
2791
|
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
if (errorElement) {
|
|
2742
|
-
return errorElement;
|
|
2743
|
-
}
|
|
2744
|
-
|
|
2745
|
-
if (childMatch.options.useErrorBoundary || router.options.useErrorBoundary) {
|
|
2746
|
-
throw childMatch.error;
|
|
2747
|
-
}
|
|
2792
|
+
if (!match) {
|
|
2793
|
+
return null;
|
|
2794
|
+
}
|
|
2748
2795
|
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2796
|
+
const PendingComponent = (_ref3 = (_match$__$pendingComp = match.__.pendingComponent) != null ? _match$__$pendingComp : router.options.defaultPendingComponent) != null ? _ref3 : defaultPending;
|
|
2797
|
+
const errorComponent = (_match$__$errorCompon = match.__.errorComponent) != null ? _match$__$errorCompon : router.options.defaultErrorComponent;
|
|
2798
|
+
return /*#__PURE__*/React.createElement(MatchesProvider, {
|
|
2799
|
+
value: matches
|
|
2800
|
+
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
2801
|
+
fallback: /*#__PURE__*/React.createElement(PendingComponent, null)
|
|
2802
|
+
}, /*#__PURE__*/React.createElement(CatchBoundary, {
|
|
2803
|
+
errorComponent: errorComponent
|
|
2804
|
+
}, (() => {
|
|
2805
|
+
if (match.status === 'error') {
|
|
2806
|
+
throw match.error;
|
|
2752
2807
|
}
|
|
2753
2808
|
|
|
2754
|
-
if (
|
|
2755
|
-
|
|
2756
|
-
var _childMatch$__$pendin;
|
|
2757
|
-
|
|
2758
|
-
const pendingElement = (_childMatch$__$pendin = childMatch.__.pendingElement) != null ? _childMatch$__$pendin : router.options.defaultPendingElement;
|
|
2759
|
-
|
|
2760
|
-
if (childMatch.options.pendingMs || pendingElement) {
|
|
2761
|
-
var _ref3;
|
|
2762
|
-
|
|
2763
|
-
return (_ref3 = pendingElement) != null ? _ref3 : null;
|
|
2764
|
-
}
|
|
2765
|
-
}
|
|
2809
|
+
if (match.status === 'success') {
|
|
2810
|
+
var _ref4, _ref5;
|
|
2766
2811
|
|
|
2767
|
-
return null;
|
|
2812
|
+
return /*#__PURE__*/React.createElement((_ref4 = (_ref5 = match.__.component) != null ? _ref5 : router.options.defaultComponent) != null ? _ref4 : Outlet);
|
|
2768
2813
|
}
|
|
2769
2814
|
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
const catchElement = (_childMatch$options$c = childMatch == null ? void 0 : childMatch.options.catchElement) != null ? _childMatch$options$c : router.options.defaultCatchElement;
|
|
2774
|
-
return /*#__PURE__*/React.createElement(MatchesProvider, {
|
|
2775
|
-
value: matches,
|
|
2776
|
-
key: childMatch.matchId
|
|
2777
|
-
}, /*#__PURE__*/React.createElement(CatchBoundary, {
|
|
2778
|
-
catchElement: catchElement
|
|
2779
|
-
}, element));
|
|
2815
|
+
console.log(match.matchId, 'suspend');
|
|
2816
|
+
throw match.__.loadPromise;
|
|
2817
|
+
})())));
|
|
2780
2818
|
}
|
|
2781
2819
|
|
|
2782
2820
|
class CatchBoundary extends React.Component {
|
|
@@ -2785,13 +2823,6 @@ class CatchBoundary extends React.Component {
|
|
|
2785
2823
|
this.state = {
|
|
2786
2824
|
error: false
|
|
2787
2825
|
};
|
|
2788
|
-
|
|
2789
|
-
this.reset = () => {
|
|
2790
|
-
this.setState({
|
|
2791
|
-
error: false,
|
|
2792
|
-
info: false
|
|
2793
|
-
});
|
|
2794
|
-
};
|
|
2795
2826
|
}
|
|
2796
2827
|
|
|
2797
2828
|
componentDidCatch(error, info) {
|
|
@@ -2803,12 +2834,12 @@ class CatchBoundary extends React.Component {
|
|
|
2803
2834
|
}
|
|
2804
2835
|
|
|
2805
2836
|
render() {
|
|
2806
|
-
var _this$props$
|
|
2837
|
+
var _this$props$errorComp;
|
|
2807
2838
|
|
|
2808
|
-
const
|
|
2839
|
+
const errorComponent = (_this$props$errorComp = this.props.errorComponent) != null ? _this$props$errorComp : DefaultErrorBoundary;
|
|
2809
2840
|
|
|
2810
2841
|
if (this.state.error) {
|
|
2811
|
-
return
|
|
2842
|
+
return /*#__PURE__*/React.createElement(errorComponent, this.state);
|
|
2812
2843
|
}
|
|
2813
2844
|
|
|
2814
2845
|
return this.props.children;
|
|
@@ -2816,10 +2847,10 @@ class CatchBoundary extends React.Component {
|
|
|
2816
2847
|
|
|
2817
2848
|
}
|
|
2818
2849
|
|
|
2819
|
-
function DefaultErrorBoundary(
|
|
2850
|
+
function DefaultErrorBoundary(_ref6) {
|
|
2820
2851
|
let {
|
|
2821
2852
|
error
|
|
2822
|
-
} =
|
|
2853
|
+
} = _ref6;
|
|
2823
2854
|
return /*#__PURE__*/React.createElement("div", {
|
|
2824
2855
|
style: {
|
|
2825
2856
|
padding: '.5rem',
|
|
@@ -2841,18 +2872,7 @@ function DefaultErrorBoundary(_ref5) {
|
|
|
2841
2872
|
padding: '.5rem',
|
|
2842
2873
|
color: 'red'
|
|
2843
2874
|
}
|
|
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."));
|
|
2875
|
+
}, error.message) : null)));
|
|
2856
2876
|
}
|
|
2857
2877
|
function usePrompt(message, when) {
|
|
2858
2878
|
const router = useRouter();
|
|
@@ -2869,15 +2889,15 @@ function usePrompt(message, when) {
|
|
|
2869
2889
|
return unblock;
|
|
2870
2890
|
}, [when, location, message]);
|
|
2871
2891
|
}
|
|
2872
|
-
function Prompt(
|
|
2892
|
+
function Prompt(_ref7) {
|
|
2873
2893
|
let {
|
|
2874
2894
|
message,
|
|
2875
2895
|
when,
|
|
2876
2896
|
children
|
|
2877
|
-
} =
|
|
2897
|
+
} = _ref7;
|
|
2878
2898
|
usePrompt(message, when != null ? when : true);
|
|
2879
2899
|
return children != null ? children : null;
|
|
2880
2900
|
}
|
|
2881
2901
|
|
|
2882
|
-
export { DefaultErrorBoundary, MatchesProvider, Outlet, Prompt, RouterProvider,
|
|
2902
|
+
export { DefaultErrorBoundary, Link, MatchRoute, MatchesProvider, Outlet, Prompt, RouterProvider, cleanPath, createBrowserHistory, createHashHistory, createMemoryHistory, createReactRouter, createRoute, createRouteConfig, createRouteMatch, createRouter, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, invariant, joinPaths, last, lazy, linkProps, matchByPath, matchPathname, matchesContext, parsePathname, parseSearchWith, pick, replaceEqualDeep, resolvePath, rootRouteId, routerContext, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, useMatch, useMatches, useNearestMatch, usePrompt, useRoute, useRouter, warning };
|
|
2883
2903
|
//# sourceMappingURL=index.js.map
|