@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 +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/slot-router.d.ts +7 -10
- package/dist/slot-router.js +19 -10
- package/dist/slot-router.js.map +1 -1
- package/index.ts +1 -1
- package/package-tar/teambit-ui-foundation.ui.react-router.slot-router-0.0.490.tgz +0 -0
- package/package.json +5 -7
- package/{preview-1649647448813.js → preview-1653827208409.js} +0 -0
- package/slot-router.tsx +31 -26
- package/tsconfig.json +1 -0
- package/package-tar/teambit-ui-foundation.ui.react-router.slot-router-0.0.489.tgz +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { SlotRouter,
|
|
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.
|
|
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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6CAAuF;AAA9E,yGAAA,UAAU,OAAA"}
|
package/dist/slot-router.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { SlotRegistry } from '@teambit/harmony';
|
|
3
3
|
import { RouteProps } from 'react-router-dom';
|
|
4
|
-
import {
|
|
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<
|
|
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
|
-
|
|
12
|
-
export declare function
|
|
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;
|
package/dist/slot-router.js
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
package/dist/slot-router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slot-router.js","sourceRoot":"","sources":["../slot-router.tsx"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"slot-router.js","sourceRoot":"","sources":["../slot-router.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAAiD;AAEjD,uDAA6D;AAC7D,mCAAiC;AAYjC,SAAgB,UAAU,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAmB;IACpF,MAAM,MAAM,GAAG,IAAA,gBAAO,EAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;IAEjD,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,8BAAC,wBAAK,kBAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,IAAM,KAAK,EAAI,CAAC,CAAC;IAEnF,IAAI,UAAU,EAAE;QACd,OAAO,CACL,8BAAC,yBAAM;YACL,8BAAC,wBAAK,IAAC,IAAI,EAAE,UAAU;gBACpB,SAAS;gBACT,QAAQ,CACH,CACD,CACV,CAAC;KACH;IAED,OAAO,CACL,8BAAC,yBAAM;QACL,8BAAC,wBAAK,IAAC,IAAI,EAAE,UAAU;YACpB,SAAS;YACT,QAAQ,CACH,CACD,CACV,CAAC;AACJ,CAAC;AAzBD,gCAyBC;AAED,SAAS,KAAK,CAAC,KAAiB;IAC9B,IAAI,KAAK,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC,IAAI,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,
|
|
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.
|
|
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.
|
|
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-
|
|
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
|
},
|
|
File without changes
|
package/slot-router.tsx
CHANGED
|
@@ -1,42 +1,47 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
1
2
|
import { SlotRegistry } from '@teambit/harmony';
|
|
2
|
-
import
|
|
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 {
|
|
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<
|
|
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
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
<
|
|
37
|
-
{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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