@teambit/ui-foundation.ui.react-router.slot-router 0.0.489 → 0.0.490

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/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { SlotRouter, SlotSubRouter, SlotRouterProps, RouteSlot, NavigationSlot } from './slot-router';
1
+ export { SlotRouter, SlotRouterProps, RouteSlot, NavigationSlot } from './slot-router';
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SlotSubRouter = exports.SlotRouter = void 0;
3
+ exports.SlotRouter = void 0;
4
4
  var slot_router_1 = require("./slot-router");
5
5
  Object.defineProperty(exports, "SlotRouter", { enumerable: true, get: function () { return slot_router_1.SlotRouter; } });
6
- Object.defineProperty(exports, "SlotSubRouter", { enumerable: true, get: function () { return slot_router_1.SlotSubRouter; } });
7
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6CAAsG;AAA7F,yGAAA,UAAU,OAAA;AAAE,4GAAA,aAAa,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6CAAuF;AAA9E,yGAAA,UAAU,OAAA"}
@@ -1,15 +1,12 @@
1
- /// <reference types="react" />
1
+ import { PropsWithChildren } from 'react';
2
2
  import { SlotRegistry } from '@teambit/harmony';
3
3
  import { RouteProps } from 'react-router-dom';
4
- import { NavLinkProps } from '@teambit/base-ui.routing.nav-link';
4
+ import type { LinkProps } from '@teambit/base-react.navigation.link';
5
5
  export declare type RouteSlot = SlotRegistry<RouteProps | RouteProps[]>;
6
- export declare type NavigationSlot = SlotRegistry<NavLinkProps>;
7
- export declare type SlotRouterProps = {
6
+ export declare type NavigationSlot = SlotRegistry<LinkProps>;
7
+ export declare type SlotRouterProps = PropsWithChildren<{
8
8
  slot: RouteSlot;
9
9
  rootRoutes?: RouteProps[];
10
- };
11
- export declare function SlotRouter({ slot, rootRoutes }: SlotRouterProps): JSX.Element;
12
- export declare function SlotSubRouter({ slot, basePath }: {
13
- slot: RouteSlot;
14
- basePath?: string;
15
- }): JSX.Element;
10
+ parentPath?: string;
11
+ }>;
12
+ export declare function SlotRouter({ slot, rootRoutes, children, parentPath }: SlotRouterProps): JSX.Element;
@@ -3,22 +3,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SlotSubRouter = exports.SlotRouter = void 0;
6
+ exports.SlotRouter = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const react_router_dom_1 = require("react-router-dom");
9
9
  const lodash_1 = require("lodash");
10
- const ui_foundation_ui_react_router_extend_path_1 = require("@teambit/ui-foundation.ui.react-router.extend-path");
11
- function SlotRouter({ slot, rootRoutes }) {
10
+ function SlotRouter({ slot, rootRoutes, children, parentPath }) {
12
11
  const routes = (0, lodash_1.flatten)(slot.values());
13
12
  const withRoot = routes.concat(rootRoutes || []);
14
- return (react_1.default.createElement(react_router_dom_1.Switch, null, withRoot.map((route, idx) => (react_1.default.createElement(react_router_dom_1.Route, Object.assign({ key: idx }, route))))));
13
+ const jsxRoutes = withRoot.map((route) => react_1.default.createElement(react_router_dom_1.Route, Object.assign({ key: toKey(route) }, route)));
14
+ if (parentPath) {
15
+ return (react_1.default.createElement(react_router_dom_1.Routes, null,
16
+ react_1.default.createElement(react_router_dom_1.Route, { path: parentPath },
17
+ jsxRoutes,
18
+ children)));
19
+ }
20
+ return (react_1.default.createElement(react_router_dom_1.Routes, null,
21
+ react_1.default.createElement(react_router_dom_1.Route, { path: parentPath },
22
+ jsxRoutes,
23
+ children)));
15
24
  }
16
25
  exports.SlotRouter = SlotRouter;
17
- function SlotSubRouter({ slot, basePath }) {
18
- const routes = (0, lodash_1.flatten)(slot.values());
19
- const { path: contextPath } = (0, react_router_dom_1.useRouteMatch)();
20
- // TODO - generate key as part of the slot.
21
- return (react_1.default.createElement(react_router_dom_1.Switch, null, routes.map((route, idx) => (react_1.default.createElement(react_router_dom_1.Route, Object.assign({ key: idx }, route, { path: (0, ui_foundation_ui_react_router_extend_path_1.extendPath)(basePath || contextPath, route.path) }))))));
26
+ function toKey(route) {
27
+ if (route.path)
28
+ return route.path;
29
+ if (route.index)
30
+ return '/';
31
+ return '.';
22
32
  }
23
- exports.SlotSubRouter = SlotSubRouter;
24
33
  //# sourceMappingURL=slot-router.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"slot-router.js","sourceRoot":"","sources":["../slot-router.tsx"],"names":[],"mappings":";;;;;;AACA,kDAA0B;AAC1B,uDAA4E;AAC5E,mCAAiC;AACjC,kHAAgF;AAWhF,SAAgB,UAAU,CAAC,EAAE,IAAI,EAAE,UAAU,EAAmB;IAC9D,MAAM,MAAM,GAAG,IAAA,gBAAO,EAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAEtC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;IAEjD,OAAO,CACL,8BAAC,yBAAM,QACJ,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,CAC5B,8BAAC,wBAAK,kBAAC,GAAG,EAAE,GAAG,IAAM,KAAK,EAAI,CAC/B,CAAC,CACK,CACV,CAAC;AACJ,CAAC;AAZD,gCAYC;AAED,SAAgB,aAAa,CAAC,EAAE,IAAI,EAAE,QAAQ,EAA0C;IACtF,MAAM,MAAM,GAAG,IAAA,gBAAO,EAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACtC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAA,gCAAa,GAAE,CAAC;IAC9C,2CAA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,CAAC;IAClC,IAAI,KAAK,CAAC,KAAK;QAAE,OAAO,GAAG,CAAC;IAC5B,OAAO,GAAG,CAAC;AACb,CAAC"}
package/index.ts CHANGED
@@ -1 +1 @@
1
- export { SlotRouter, SlotSubRouter, SlotRouterProps, RouteSlot, NavigationSlot } from './slot-router';
1
+ export { SlotRouter, SlotRouterProps, RouteSlot, NavigationSlot } from './slot-router';
package/package.json CHANGED
@@ -1,24 +1,21 @@
1
1
  {
2
2
  "name": "@teambit/ui-foundation.ui.react-router.slot-router",
3
- "version": "0.0.489",
3
+ "version": "0.0.490",
4
4
  "homepage": "https://bit.dev/teambit/ui-foundation/ui/react-router/slot-router",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.ui-foundation",
8
8
  "name": "ui/react-router/slot-router",
9
- "version": "0.0.489"
9
+ "version": "0.0.490"
10
10
  },
11
11
  "dependencies": {
12
12
  "lodash": "4.17.21",
13
- "react-router-dom": "5.2.0",
14
13
  "core-js": "^3.0.0",
15
- "@teambit/base-ui.routing.nav-link": "1.0.0",
16
- "@teambit/harmony": "0.3.3",
17
- "@teambit/ui-foundation.ui.react-router.extend-path": "0.0.486"
14
+ "@teambit/base-react.navigation.link": "2.0.27",
15
+ "@teambit/harmony": "0.3.3"
18
16
  },
19
17
  "devDependencies": {
20
18
  "@types/lodash": "4.14.165",
21
- "@types/react-router-dom": "5.1.7",
22
19
  "@types/react": "^17.0.8",
23
20
  "@types/mocha": "9.1.0",
24
21
  "@types/testing-library__jest-dom": "5.9.5",
@@ -28,6 +25,7 @@
28
25
  "@types/node": "12.20.4"
29
26
  },
30
27
  "peerDependencies": {
28
+ "react-router-dom": "^6.0.0",
31
29
  "react-dom": "^16.8.0 || ^17.0.0",
32
30
  "react": "^16.8.0 || ^17.0.0"
33
31
  },
package/slot-router.tsx CHANGED
@@ -1,42 +1,47 @@
1
+ import React, { PropsWithChildren } from 'react';
1
2
  import { SlotRegistry } from '@teambit/harmony';
2
- import React from 'react';
3
- import { Route, RouteProps, Switch, useRouteMatch } from 'react-router-dom';
3
+ import { Routes, Route, RouteProps } from 'react-router-dom';
4
4
  import { flatten } from 'lodash';
5
- import { extendPath } from '@teambit/ui-foundation.ui.react-router.extend-path';
6
- import { NavLinkProps } from '@teambit/base-ui.routing.nav-link';
5
+ import type { LinkProps } from '@teambit/base-react.navigation.link';
7
6
 
8
7
  export type RouteSlot = SlotRegistry<RouteProps | RouteProps[]>;
9
- export type NavigationSlot = SlotRegistry<NavLinkProps>;
8
+ export type NavigationSlot = SlotRegistry<LinkProps>;
10
9
 
11
- export type SlotRouterProps = {
10
+ export type SlotRouterProps = PropsWithChildren<{
12
11
  slot: RouteSlot;
13
12
  rootRoutes?: RouteProps[];
14
- };
13
+ parentPath?: string;
14
+ }>;
15
15
 
16
- export function SlotRouter({ slot, rootRoutes }: SlotRouterProps) {
16
+ export function SlotRouter({ slot, rootRoutes, children, parentPath }: SlotRouterProps) {
17
17
  const routes = flatten(slot.values());
18
-
19
18
  const withRoot = routes.concat(rootRoutes || []);
20
19
 
21
- return (
22
- <Switch>
23
- {withRoot.map((route, idx) => (
24
- <Route key={idx} {...route} />
25
- ))}
26
- </Switch>
27
- );
28
- }
20
+ const jsxRoutes = withRoot.map((route) => <Route key={toKey(route)} {...route} />);
29
21
 
30
- export function SlotSubRouter({ slot, basePath }: { slot: RouteSlot; basePath?: string }) {
31
- const routes = flatten(slot.values());
32
- const { path: contextPath } = useRouteMatch();
33
- // TODO - generate key as part of the slot.
22
+ if (parentPath) {
23
+ return (
24
+ <Routes>
25
+ <Route path={parentPath}>
26
+ {jsxRoutes}
27
+ {children}
28
+ </Route>
29
+ </Routes>
30
+ );
31
+ }
34
32
 
35
33
  return (
36
- <Switch>
37
- {routes.map((route, idx) => (
38
- <Route key={idx} {...route} path={extendPath(basePath || contextPath, route.path as any)} />
39
- ))}
40
- </Switch>
34
+ <Routes>
35
+ <Route path={parentPath}>
36
+ {jsxRoutes}
37
+ {children}
38
+ </Route>
39
+ </Routes>
41
40
  );
42
41
  }
42
+
43
+ function toKey(route: RouteProps) {
44
+ if (route.path) return route.path;
45
+ if (route.index) return '/';
46
+ return '.';
47
+ }
package/tsconfig.json CHANGED
@@ -14,6 +14,7 @@
14
14
  "declaration": true,
15
15
  "sourceMap": true,
16
16
  "skipLibCheck": true,
17
+ "experimentalDecorators": true,
17
18
  "outDir": "dist",
18
19
  "moduleResolution": "node",
19
20
  "esModuleInterop": true,