@tanstack/react-router 0.0.1-alpha.2 → 0.0.1-alpha.3

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.
@@ -4014,7 +4014,7 @@ var drawChart = (function (exports) {
4014
4014
  </script>
4015
4015
  <script>
4016
4016
  /*<!--*/
4017
- const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"uid":"bdf7-21","name":"\u0000rollupPluginBabelHelpers.js"},{"name":"packages","children":[{"name":"router-core/build/esm/index.js","uid":"bdf7-23"},{"name":"react-router/src/index.tsx","uid":"bdf7-25"}]}]}],"isRoot":true},"nodeParts":{"bdf7-21":{"renderedLength":798,"gzipLength":366,"brotliLength":0,"mainUid":"bdf7-20"},"bdf7-23":{"renderedLength":68622,"gzipLength":14235,"brotliLength":0,"mainUid":"bdf7-22"},"bdf7-25":{"renderedLength":11931,"gzipLength":3038,"brotliLength":0,"mainUid":"bdf7-24"}},"nodeMetas":{"bdf7-20":{"id":"\u0000rollupPluginBabelHelpers.js","moduleParts":{"index.production.js":"bdf7-21"},"imported":[],"importedBy":[{"uid":"bdf7-24"}]},"bdf7-22":{"id":"/packages/router-core/build/esm/index.js","moduleParts":{"index.production.js":"bdf7-23"},"imported":[],"importedBy":[{"uid":"bdf7-24"}]},"bdf7-24":{"id":"/packages/react-router/src/index.tsx","moduleParts":{"index.production.js":"bdf7-25"},"imported":[{"uid":"bdf7-20"},{"uid":"bdf7-26"},{"uid":"bdf7-27"},{"uid":"bdf7-22"}],"importedBy":[],"isEntry":true},"bdf7-26":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"bdf7-24"}],"isExternal":true},"bdf7-27":{"id":"use-sync-external-store/shim","moduleParts":{},"imported":[],"importedBy":[{"uid":"bdf7-24"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4017
+ const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"uid":"b6e9-21","name":"\u0000rollupPluginBabelHelpers.js"},{"name":"packages","children":[{"name":"router-core/build/esm/index.js","uid":"b6e9-23"},{"name":"react-router/src/index.tsx","uid":"b6e9-25"}]}]}],"isRoot":true},"nodeParts":{"b6e9-21":{"renderedLength":798,"gzipLength":366,"brotliLength":0,"mainUid":"b6e9-20"},"b6e9-23":{"renderedLength":68622,"gzipLength":14235,"brotliLength":0,"mainUid":"b6e9-22"},"b6e9-25":{"renderedLength":11932,"gzipLength":3067,"brotliLength":0,"mainUid":"b6e9-24"}},"nodeMetas":{"b6e9-20":{"id":"\u0000rollupPluginBabelHelpers.js","moduleParts":{"index.production.js":"b6e9-21"},"imported":[],"importedBy":[{"uid":"b6e9-24"}]},"b6e9-22":{"id":"/packages/router-core/build/esm/index.js","moduleParts":{"index.production.js":"b6e9-23"},"imported":[],"importedBy":[{"uid":"b6e9-24"}]},"b6e9-24":{"id":"/packages/react-router/src/index.tsx","moduleParts":{"index.production.js":"b6e9-25"},"imported":[{"uid":"b6e9-20"},{"uid":"b6e9-26"},{"uid":"b6e9-27"},{"uid":"b6e9-22"}],"importedBy":[],"isEntry":true},"b6e9-26":{"id":"react","moduleParts":{},"imported":[],"importedBy":[{"uid":"b6e9-24"}],"isExternal":true},"b6e9-27":{"id":"use-sync-external-store/shim","moduleParts":{},"imported":[],"importedBy":[{"uid":"b6e9-24"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4018
4018
 
4019
4019
  const run = () => {
4020
4020
  const width = window.innerWidth;
@@ -7,7 +7,7 @@
7
7
  "name": "index.production.js",
8
8
  "children": [
9
9
  {
10
- "uid": "bdf7-29",
10
+ "uid": "b6e9-29",
11
11
  "name": "\u0000rollupPluginBabelHelpers.js"
12
12
  },
13
13
  {
@@ -15,11 +15,11 @@
15
15
  "children": [
16
16
  {
17
17
  "name": "router-core/build/esm/index.js",
18
- "uid": "bdf7-31"
18
+ "uid": "b6e9-31"
19
19
  },
20
20
  {
21
21
  "name": "react-router/src/index.tsx",
22
- "uid": "bdf7-33"
22
+ "uid": "b6e9-33"
23
23
  }
24
24
  ]
25
25
  }
@@ -29,90 +29,90 @@
29
29
  "isRoot": true
30
30
  },
31
31
  "nodeParts": {
32
- "bdf7-29": {
32
+ "b6e9-29": {
33
33
  "renderedLength": 798,
34
34
  "gzipLength": 366,
35
35
  "brotliLength": 0,
36
- "mainUid": "bdf7-28"
36
+ "mainUid": "b6e9-28"
37
37
  },
38
- "bdf7-31": {
38
+ "b6e9-31": {
39
39
  "renderedLength": 68622,
40
40
  "gzipLength": 14235,
41
41
  "brotliLength": 0,
42
- "mainUid": "bdf7-30"
42
+ "mainUid": "b6e9-30"
43
43
  },
44
- "bdf7-33": {
45
- "renderedLength": 11931,
46
- "gzipLength": 3038,
44
+ "b6e9-33": {
45
+ "renderedLength": 11932,
46
+ "gzipLength": 3067,
47
47
  "brotliLength": 0,
48
- "mainUid": "bdf7-32"
48
+ "mainUid": "b6e9-32"
49
49
  }
50
50
  },
51
51
  "nodeMetas": {
52
- "bdf7-28": {
52
+ "b6e9-28": {
53
53
  "id": "\u0000rollupPluginBabelHelpers.js",
54
54
  "moduleParts": {
55
- "index.production.js": "bdf7-29"
55
+ "index.production.js": "b6e9-29"
56
56
  },
57
57
  "imported": [],
58
58
  "importedBy": [
59
59
  {
60
- "uid": "bdf7-32"
60
+ "uid": "b6e9-32"
61
61
  }
62
62
  ]
63
63
  },
64
- "bdf7-30": {
64
+ "b6e9-30": {
65
65
  "id": "/packages/router-core/build/esm/index.js",
66
66
  "moduleParts": {
67
- "index.production.js": "bdf7-31"
67
+ "index.production.js": "b6e9-31"
68
68
  },
69
69
  "imported": [],
70
70
  "importedBy": [
71
71
  {
72
- "uid": "bdf7-32"
72
+ "uid": "b6e9-32"
73
73
  }
74
74
  ]
75
75
  },
76
- "bdf7-32": {
76
+ "b6e9-32": {
77
77
  "id": "/packages/react-router/src/index.tsx",
78
78
  "moduleParts": {
79
- "index.production.js": "bdf7-33"
79
+ "index.production.js": "b6e9-33"
80
80
  },
81
81
  "imported": [
82
82
  {
83
- "uid": "bdf7-28"
83
+ "uid": "b6e9-28"
84
84
  },
85
85
  {
86
- "uid": "bdf7-34"
86
+ "uid": "b6e9-34"
87
87
  },
88
88
  {
89
- "uid": "bdf7-35"
89
+ "uid": "b6e9-35"
90
90
  },
91
91
  {
92
- "uid": "bdf7-30"
92
+ "uid": "b6e9-30"
93
93
  }
94
94
  ],
95
95
  "importedBy": [],
96
96
  "isEntry": true
97
97
  },
98
- "bdf7-34": {
98
+ "b6e9-34": {
99
99
  "id": "react",
100
100
  "moduleParts": {},
101
101
  "imported": [],
102
102
  "importedBy": [
103
103
  {
104
- "uid": "bdf7-32"
104
+ "uid": "b6e9-32"
105
105
  }
106
106
  ],
107
107
  "isExternal": true
108
108
  },
109
- "bdf7-35": {
109
+ "b6e9-35": {
110
110
  "id": "use-sync-external-store/shim",
111
111
  "moduleParts": {},
112
112
  "imported": [],
113
113
  "importedBy": [
114
114
  {
115
- "uid": "bdf7-32"
115
+ "uid": "b6e9-32"
116
116
  }
117
117
  ],
118
118
  "isExternal": true
@@ -9,7 +9,7 @@
9
9
  * @license MIT
10
10
  */
11
11
  import * as React from 'react';
12
- import { AnyRouteConfig, RouteConfig, AnyAllRouteInfo, AllRouteInfo, RootRouteId, RouteMatch, DefaultAllRouteInfo, AnyRouteInfo, RouteInfo, ToOptions, MatchRouteOptions, RouteInfoByPath, ResolveRelativePath, NoInfer, ValidFromPath, LinkOptions, RouterOptions, Router } from '@tanstack/router-core';
12
+ import { AnyRouteConfig, RouteConfig, AnyAllRouteInfo, AllRouteInfo, RootRouteId, RouteMatch, ToOptions, MatchRouteOptions, RouteInfoByPath, ResolveRelativePath, NoInfer, DefaultAllRouteInfo, AnyRouteInfo, RouteInfo, ValidFromPath, LinkOptions, RouterOptions, Router } from '@tanstack/router-core';
13
13
  export * from '@tanstack/router-core';
14
14
 
15
15
  declare module '@tanstack/router-core' {
@@ -23,6 +23,15 @@ declare module '@tanstack/router-core' {
23
23
  interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>> extends Pick<Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][RootRouteId]>, 'linkProps' | 'Link' | 'MatchRoute'> {
24
24
  useRoute: <TId extends keyof TAllRouteInfo['routeInfoById']>(routeId: TId) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>;
25
25
  useMatch: <TId extends keyof TAllRouteInfo['routeInfoById']>(routeId: TId) => RouteMatch<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>;
26
+ linkProps: <TTo extends string = '.'>(props: LinkPropsOptions<TAllRouteInfo, '/', TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement>) => React.AnchorHTMLAttributes<HTMLAnchorElement>;
27
+ Link: <TTo extends string = '.'>(props: LinkPropsOptions<TAllRouteInfo, '/', TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement> & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {
28
+ children?: React.ReactNode | ((state: {
29
+ isActive: boolean;
30
+ }) => React.ReactNode);
31
+ }) => JSX.Element;
32
+ MatchRoute: <TTo extends string = '.'>(props: ToOptions<TAllRouteInfo, '/', TTo> & MatchRouteOptions & {
33
+ children?: React.ReactNode | ((params: RouteInfoByPath<TAllRouteInfo, ResolveRelativePath<'/', NoInfer<TTo>>>['allParams']) => React.ReactNode);
34
+ }) => JSX.Element;
26
35
  }
27
36
  interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
28
37
  linkProps: <TTo extends string = '.'>(props: LinkPropsOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement>) => React.AnchorHTMLAttributes<HTMLAnchorElement>;
@@ -2375,6 +2375,108 @@
2375
2375
  };
2376
2376
 
2377
2377
  function createReactRouter(opts) {
2378
+ const makeRouteExt = (route, router) => {
2379
+ return {
2380
+ linkProps: options => {
2381
+ var _functionalUpdate, _functionalUpdate2;
2382
+
2383
+ const {
2384
+ // custom props
2385
+ target,
2386
+ activeProps = () => ({
2387
+ className: 'active'
2388
+ }),
2389
+ inactiveProps = () => ({}),
2390
+ disabled,
2391
+ // element props
2392
+ style,
2393
+ className,
2394
+ onClick,
2395
+ onFocus,
2396
+ onMouseEnter,
2397
+ onMouseLeave
2398
+ } = options,
2399
+ rest = _objectWithoutPropertiesLoose(options, _excluded);
2400
+
2401
+ const linkInfo = route.buildLink(options);
2402
+
2403
+ if (linkInfo.type === 'external') {
2404
+ const {
2405
+ href
2406
+ } = linkInfo;
2407
+ return {
2408
+ href
2409
+ };
2410
+ }
2411
+
2412
+ const {
2413
+ handleClick,
2414
+ handleFocus,
2415
+ handleEnter,
2416
+ handleLeave,
2417
+ isActive,
2418
+ next
2419
+ } = linkInfo;
2420
+
2421
+ const composeHandlers = handlers => e => {
2422
+ e.persist();
2423
+ handlers.forEach(handler => {
2424
+ if (handler) handler(e);
2425
+ });
2426
+ }; // Get the active props
2427
+
2428
+
2429
+ const resolvedActiveProps = isActive ? (_functionalUpdate = functionalUpdate(activeProps)) != null ? _functionalUpdate : {} : {}; // Get the inactive props
2430
+
2431
+ const resolvedInactiveProps = isActive ? {} : (_functionalUpdate2 = functionalUpdate(inactiveProps)) != null ? _functionalUpdate2 : {};
2432
+ return _extends$2({}, resolvedActiveProps, resolvedInactiveProps, rest, {
2433
+ href: disabled ? undefined : next.href,
2434
+ onClick: composeHandlers([handleClick, onClick]),
2435
+ onFocus: composeHandlers([handleFocus, onFocus]),
2436
+ onMouseEnter: composeHandlers([handleEnter, onMouseEnter]),
2437
+ onMouseLeave: composeHandlers([handleLeave, onMouseLeave]),
2438
+ target,
2439
+ style: _extends$2({}, style, resolvedActiveProps.style, resolvedInactiveProps.style),
2440
+ className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined
2441
+ }, disabled ? {
2442
+ role: 'link',
2443
+ 'aria-disabled': true
2444
+ } : undefined, {
2445
+ ['data-status']: isActive ? 'active' : undefined
2446
+ });
2447
+ },
2448
+ Link: /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
2449
+ const linkProps = route.linkProps(props);
2450
+ useRouterSubscription(router);
2451
+ return /*#__PURE__*/React__namespace.createElement("a", _extends$2({
2452
+ ref: ref
2453
+ }, linkProps, {
2454
+ children: typeof props.children === 'function' ? props.children({
2455
+ isActive: linkProps['data-status'] === 'active'
2456
+ }) : props.children
2457
+ }));
2458
+ }),
2459
+ MatchRoute: opts => {
2460
+ const {
2461
+ pending,
2462
+ caseSensitive
2463
+ } = opts,
2464
+ rest = _objectWithoutPropertiesLoose(opts, _excluded2);
2465
+
2466
+ const params = route.matchRoute(rest, {
2467
+ pending,
2468
+ caseSensitive
2469
+ }); // useRouterSubscription(router)
2470
+
2471
+ if (!params) {
2472
+ return null;
2473
+ }
2474
+
2475
+ return typeof opts.children === 'function' ? opts.children(params) : opts.children;
2476
+ }
2477
+ };
2478
+ };
2479
+
2378
2480
  const coreRouter = createRouter(_extends$2({}, opts, {
2379
2481
  createRouter: router => {
2380
2482
  const routerExt = {
@@ -2414,112 +2516,15 @@
2414
2516
  return match;
2415
2517
  }
2416
2518
  };
2417
- Object.assign(router, routerExt);
2519
+ const routeExt = makeRouteExt(router.getRoute('/'), router);
2520
+ Object.assign(router, routerExt, routeExt);
2418
2521
  },
2419
2522
  createRoute: _ref => {
2420
2523
  let {
2421
2524
  router,
2422
2525
  route
2423
2526
  } = _ref;
2424
- const routeExt = {
2425
- linkProps: options => {
2426
- var _functionalUpdate, _functionalUpdate2;
2427
-
2428
- const {
2429
- // custom props
2430
- target,
2431
- activeProps = () => ({
2432
- className: 'active'
2433
- }),
2434
- inactiveProps = () => ({}),
2435
- disabled,
2436
- // element props
2437
- style,
2438
- className,
2439
- onClick,
2440
- onFocus,
2441
- onMouseEnter,
2442
- onMouseLeave
2443
- } = options,
2444
- rest = _objectWithoutPropertiesLoose(options, _excluded);
2445
-
2446
- const linkInfo = route.buildLink(options);
2447
-
2448
- if (linkInfo.type === 'external') {
2449
- const {
2450
- href
2451
- } = linkInfo;
2452
- return {
2453
- href
2454
- };
2455
- }
2456
-
2457
- const {
2458
- handleClick,
2459
- handleFocus,
2460
- handleEnter,
2461
- handleLeave,
2462
- isActive,
2463
- next
2464
- } = linkInfo;
2465
-
2466
- const composeHandlers = handlers => e => {
2467
- e.persist();
2468
- handlers.forEach(handler => {
2469
- if (handler) handler(e);
2470
- });
2471
- }; // Get the active props
2472
-
2473
-
2474
- const resolvedActiveProps = isActive ? (_functionalUpdate = functionalUpdate(activeProps)) != null ? _functionalUpdate : {} : {}; // Get the inactive props
2475
-
2476
- const resolvedInactiveProps = isActive ? {} : (_functionalUpdate2 = functionalUpdate(inactiveProps)) != null ? _functionalUpdate2 : {};
2477
- return _extends$2({}, resolvedActiveProps, resolvedInactiveProps, rest, {
2478
- href: disabled ? undefined : next.href,
2479
- onClick: composeHandlers([handleClick, onClick]),
2480
- onFocus: composeHandlers([handleFocus, onFocus]),
2481
- onMouseEnter: composeHandlers([handleEnter, onMouseEnter]),
2482
- onMouseLeave: composeHandlers([handleLeave, onMouseLeave]),
2483
- target,
2484
- style: _extends$2({}, style, resolvedActiveProps.style, resolvedInactiveProps.style),
2485
- className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined
2486
- }, disabled ? {
2487
- role: 'link',
2488
- 'aria-disabled': true
2489
- } : undefined, {
2490
- ['data-status']: isActive ? 'active' : undefined
2491
- });
2492
- },
2493
- Link: /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
2494
- const linkProps = route.linkProps(props);
2495
- useRouterSubscription(router);
2496
- return /*#__PURE__*/React__namespace.createElement("a", _extends$2({
2497
- ref: ref
2498
- }, linkProps, {
2499
- children: typeof props.children === 'function' ? props.children({
2500
- isActive: linkProps['data-status'] === 'active'
2501
- }) : props.children
2502
- }));
2503
- }),
2504
- MatchRoute: opts => {
2505
- const {
2506
- pending,
2507
- caseSensitive
2508
- } = opts,
2509
- rest = _objectWithoutPropertiesLoose(opts, _excluded2);
2510
-
2511
- const params = route.matchRoute(rest, {
2512
- pending,
2513
- caseSensitive
2514
- }); // useRouterSubscription(router)
2515
-
2516
- if (!params) {
2517
- return null;
2518
- }
2519
-
2520
- return typeof opts.children === 'function' ? opts.children(params) : opts.children;
2521
- }
2522
- };
2527
+ const routeExt = makeRouteExt(route, router);
2523
2528
  Object.assign(route, routeExt);
2524
2529
  }
2525
2530
  }));