@tanstack/router-core 0.0.1-alpha.2 → 0.0.1-alpha.4

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.
@@ -0,0 +1,30 @@
1
+ /**
2
+ * router-core
3
+ *
4
+ * Copyright (c) TanStack
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ 'use strict';
12
+
13
+ Object.defineProperty(exports, '__esModule', { value: true });
14
+
15
+ var isProduction = process.env.NODE_ENV === 'production';
16
+ var prefix = 'Invariant failed';
17
+ function invariant(condition, message) {
18
+ if (condition) {
19
+ return;
20
+ }
21
+ if (isProduction) {
22
+ throw new Error(prefix);
23
+ }
24
+ var provided = typeof message === 'function' ? message() : message;
25
+ var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
26
+ throw new Error(value);
27
+ }
28
+
29
+ exports["default"] = invariant;
30
+ //# sourceMappingURL=tiny-invariant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiny-invariant.js","sources":["../../../../../../../../node_modules/tiny-invariant/dist/esm/tiny-invariant.js"],"sourcesContent":["var isProduction = process.env.NODE_ENV === 'production';\nvar prefix = 'Invariant failed';\nfunction invariant(condition, message) {\n if (condition) {\n return;\n }\n if (isProduction) {\n throw new Error(prefix);\n }\n var provided = typeof message === 'function' ? message() : message;\n var value = provided ? \"\".concat(prefix, \": \").concat(provided) : prefix;\n throw new Error(value);\n}\n\nexport { invariant as default };\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,IAAI,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;AACzD,IAAI,MAAM,GAAG,kBAAkB,CAAC;AAChC,SAAS,SAAS,CAAC,SAAS,EAAE,OAAO,EAAE;AACvC,IAAI,IAAI,SAAS,EAAE;AACnB,QAAQ,OAAO;AACf,KAAK;AACL,IAAI,IAAI,YAAY,EAAE;AACtB,QAAQ,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AAChC,KAAK;AACL,IAAI,IAAI,QAAQ,GAAG,OAAO,OAAO,KAAK,UAAU,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC;AACvE,IAAI,IAAI,KAAK,GAAG,QAAQ,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC;AAC7E,IAAI,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;AAC3B;;;;"}
@@ -14,9 +14,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
14
14
 
15
15
  var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
16
16
  var index = require('../../../node_modules/history/index.js');
17
+ var tinyInvariant = require('../../../node_modules/tiny-invariant/dist/esm/tiny-invariant.js');
17
18
  var qss = require('./qss.js');
18
19
 
19
- const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId) {
20
+ const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
20
21
  if (options === void 0) {
21
22
  options = {};
22
23
  }
@@ -27,8 +28,6 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
27
28
 
28
29
  if (isRoot) {
29
30
  options.path = rootRouteId;
30
- } else {
31
- warning(!options.path, 'Routes must have a path property.');
32
31
  } // Strip the root from parentIds
33
32
 
34
33
 
@@ -36,13 +35,14 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
36
35
  parentId = '';
37
36
  }
38
37
 
39
- let path = String(isRoot ? rootRouteId : options.path); // If the path is anything other than an index path, trim it up
38
+ let path = isRoot ? rootRouteId : options.path; // If the path is anything other than an index path, trim it up
40
39
 
41
- if (path !== '/') {
40
+ if (path && path !== '/') {
42
41
  path = trimPath(path);
43
42
  }
44
43
 
45
- let id = joinPaths([parentId, path]);
44
+ const routeId = path || options.id;
45
+ let id = joinPaths([parentId, routeId]);
46
46
 
47
47
  if (path === rootRouteId) {
48
48
  path = '/';
@@ -52,14 +52,15 @@ const createRouteConfig = function createRouteConfig(options, children, isRoot,
52
52
  id = joinPaths(['/', id]);
53
53
  }
54
54
 
55
- const fullPath = id === rootRouteId ? '/' : trimPathRight(id);
55
+ const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]));
56
56
  return {
57
57
  id: id,
58
+ routeId: routeId,
58
59
  path: path,
59
60
  fullPath: fullPath,
60
61
  options: options,
61
62
  children,
62
- addChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id)), false, parentId)
63
+ addChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)), false, parentId, parentPath)
63
64
  };
64
65
  };
65
66
  const rootRouteId = '__root__';
@@ -435,55 +436,76 @@ function createRouter(userOptions) {
435
436
 
436
437
  const existingMatches = [...router.state.matches, ...((_router$state$pending3 = (_router$state$pending4 = router.state.pending) == null ? void 0 : _router$state$pending4.matches) != null ? _router$state$pending3 : [])];
437
438
 
438
- const recurse = async (routes, parentMatch) => {
439
- var _parentMatch$params, _router$options$filte, _router$preloadCache$, _route$childRoutes2;
439
+ const recurse = async routes => {
440
+ var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
440
441
 
442
+ const parentMatch = last(matches);
441
443
  let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
442
444
  const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
443
- const route = filteredRoutes == null ? void 0 : filteredRoutes.find(route => {
444
- var _route$childRoutes, _route$options$caseSe;
445
-
446
- const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length);
447
- const matchParams = matchPathname(pathname, {
448
- to: route.fullPath,
449
- fuzzy,
450
- caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
451
- });
445
+ let foundRoutes = [];
452
446
 
453
- if (matchParams) {
454
- let parsedParams;
447
+ const findMatchInRoutes = (parentRoutes, routes) => {
448
+ routes.some(route => {
449
+ var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
455
450
 
456
- try {
457
- var _route$options$parseP;
451
+ if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
452
+ return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
453
+ }
458
454
 
459
- parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
460
- } catch (err) {
461
- if (opts != null && opts.strictParseParams) {
462
- throw err;
455
+ const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
456
+ const matchParams = matchPathname(pathname, {
457
+ to: route.fullPath,
458
+ fuzzy,
459
+ caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
460
+ });
461
+
462
+ if (matchParams) {
463
+ let parsedParams;
464
+
465
+ try {
466
+ var _route$options$parseP;
467
+
468
+ parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
469
+ } catch (err) {
470
+ if (opts != null && opts.strictParseParams) {
471
+ throw err;
472
+ }
463
473
  }
474
+
475
+ params = _rollupPluginBabelHelpers["extends"]({}, params, parsedParams);
464
476
  }
465
477
 
466
- params = _rollupPluginBabelHelpers["extends"]({}, params, parsedParams);
467
- }
478
+ if (!!matchParams) {
479
+ foundRoutes = [...parentRoutes, route];
480
+ }
468
481
 
469
- return !!matchParams;
470
- });
482
+ return !!foundRoutes.length;
483
+ });
484
+ return !!foundRoutes.length;
485
+ };
471
486
 
472
- if (!route) {
487
+ findMatchInRoutes([], filteredRoutes);
488
+
489
+ if (!foundRoutes.length) {
473
490
  return;
474
491
  }
475
492
 
476
- const interpolatedPath = interpolatePath(route.routePath, params);
477
- const matchId = interpolatePath(route.routeId, params, true);
478
- const match = existingMatches.find(d => d.matchId === matchId) || ((_router$preloadCache$ = router.preloadCache[matchId]) == null ? void 0 : _router$preloadCache$.match) || createRouteMatch(router, route, {
479
- matchId,
480
- params,
481
- pathname: joinPaths([pathname, interpolatedPath])
493
+ foundRoutes.forEach(foundRoute => {
494
+ var _router$preloadCache$;
495
+
496
+ const interpolatedPath = interpolatePath(foundRoute.routePath, params);
497
+ const matchId = interpolatePath(foundRoute.routeId, params, true);
498
+ const match = existingMatches.find(d => d.matchId === matchId) || ((_router$preloadCache$ = router.preloadCache[matchId]) == null ? void 0 : _router$preloadCache$.match) || createRouteMatch(router, foundRoute, {
499
+ matchId,
500
+ params,
501
+ pathname: joinPaths([pathname, interpolatedPath])
502
+ });
503
+ matches.push(match);
482
504
  });
483
- matches.push(match);
505
+ const foundRoute = last(foundRoutes);
484
506
 
485
- if ((_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length) {
486
- recurse(route.childRoutes, match);
507
+ if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
508
+ recurse(foundRoute.childRoutes);
487
509
  }
488
510
  };
489
511
 
@@ -587,14 +609,7 @@ function createRouter(userOptions) {
587
609
  isExternal = true;
588
610
  } catch (e) {}
589
611
 
590
- if (isExternal) {
591
- if (process.env.NODE_ENV !== 'production') {
592
- throw new Error('Attempting to navigate to external url with router.navigate!');
593
- }
594
-
595
- return;
596
- }
597
-
612
+ tinyInvariant["default"](!isExternal, 'Attempting to navigate to external url with router.navigate!');
598
613
  return router._navigate({
599
614
  from: fromString,
600
615
  to: toString,
@@ -749,13 +764,14 @@ function createRoute(routeConfig, options, parent, router) {
749
764
  // ]).replace(new RegExp(`^${rootRouteId}`), '')
750
765
  // ) as TRouteInfo['id']
751
766
  const {
752
- id: routeId,
767
+ id,
768
+ routeId,
753
769
  path: routePath,
754
770
  fullPath
755
771
  } = routeConfig;
756
772
 
757
- const action = router.state.actions[routeId] || (() => {
758
- router.state.actions[routeId] = {
773
+ const action = router.state.actions[id] || (() => {
774
+ router.state.actions[id] = {
759
775
  pending: [],
760
776
  submit: async (submission, actionOpts) => {
761
777
  var _actionOpts$invalidat;
@@ -806,11 +822,12 @@ function createRoute(routeConfig, options, parent, router) {
806
822
  }
807
823
  }
808
824
  };
809
- return router.state.actions[routeId];
825
+ return router.state.actions[id];
810
826
  })();
811
827
 
812
828
  let route = {
813
- routeId,
829
+ routeId: id,
830
+ routeRouteId: routeId,
814
831
  routePath,
815
832
  fullPath,
816
833
  options,
@@ -1424,6 +1441,7 @@ function last(arr) {
1424
1441
  exports.createBrowserHistory = index.createBrowserHistory;
1425
1442
  exports.createHashHistory = index.createHashHistory;
1426
1443
  exports.createMemoryHistory = index.createMemoryHistory;
1444
+ exports.invariant = tinyInvariant["default"];
1427
1445
  exports.createRoute = createRoute;
1428
1446
  exports.createRouteConfig = createRouteConfig;
1429
1447
  exports.createRouteMatch = createRouteMatch;