@teambit/react-router 0.0.555 → 0.0.556
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/package.json +16 -10
- package/index.ts +0 -13
- package/package-tar/teambit-react-router-0.0.555.tgz +0 -0
- package/react-router-routing/index.ts +0 -1
- package/react-router-routing/react-router-routing.tsx +0 -15
- package/react-router.aspect.ts +0 -5
- package/react-router.ui.runtime.tsx +0 -124
- package/route-context.tsx +0 -74
- package/routing-method.tsx +0 -6
- package/tsconfig.json +0 -34
- package/types/asset.d.ts +0 -29
- package/types/style.d.ts +0 -42
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/react-router",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.556",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/ui-foundation/react-router",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.ui-foundation",
|
|
8
8
|
"name": "react-router",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.556"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@teambit/harmony": "0.2.11",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"@teambit/base-ui.routing.link": "1.0.0",
|
|
18
18
|
"@teambit/base-ui.routing.nav-link": "1.0.0",
|
|
19
19
|
"@teambit/base-ui.routing.routing-provider": "1.0.0",
|
|
20
|
-
"@teambit/ui-foundation.ui.react-router.link-anchor": "0.0.
|
|
21
|
-
"@teambit/ui-foundation.ui.is-browser": "0.0.
|
|
22
|
-
"@teambit/ui-foundation.ui.react-router.slot-router": "0.0.
|
|
23
|
-
"@teambit/ui": "0.0.
|
|
24
|
-
"@teambit/ui-foundation.ui.react-router.link": "0.0.
|
|
25
|
-
"@teambit/ui-foundation.ui.react-router.nav-link": "0.0.
|
|
20
|
+
"@teambit/ui-foundation.ui.react-router.link-anchor": "0.0.101",
|
|
21
|
+
"@teambit/ui-foundation.ui.is-browser": "0.0.464",
|
|
22
|
+
"@teambit/ui-foundation.ui.react-router.slot-router": "0.0.466",
|
|
23
|
+
"@teambit/ui": "0.0.556",
|
|
24
|
+
"@teambit/ui-foundation.ui.react-router.link": "0.0.466",
|
|
25
|
+
"@teambit/ui-foundation.ui.react-router.nav-link": "0.0.466"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/history": "4.7.8",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@types/node": "12.20.4"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@teambit/legacy": "1.0.
|
|
38
|
+
"@teambit/legacy": "1.0.173",
|
|
39
39
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
40
40
|
"react": "^16.8.0 || ^17.0.0"
|
|
41
41
|
},
|
|
@@ -63,12 +63,18 @@
|
|
|
63
63
|
"react": "-"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"@teambit/legacy": "1.0.
|
|
66
|
+
"@teambit/legacy": "1.0.173",
|
|
67
67
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
68
68
|
"react": "^16.8.0 || ^17.0.0"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
|
+
"files": [
|
|
73
|
+
"dist",
|
|
74
|
+
"!dist/tsconfig.tsbuildinfo",
|
|
75
|
+
"README.md",
|
|
76
|
+
"README.mdx"
|
|
77
|
+
],
|
|
72
78
|
"private": false,
|
|
73
79
|
"engines": {
|
|
74
80
|
"node": ">=12.22.0"
|
package/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ReactRouterAspect } from './react-router.aspect';
|
|
2
|
-
|
|
3
|
-
export { Routing } from './routing-method';
|
|
4
|
-
export type { ReactRouterUI } from './react-router.ui.runtime';
|
|
5
|
-
|
|
6
|
-
// TODO - replace with resolveFromHost / resolveFromApp when available
|
|
7
|
-
// this exposes the Link components installed in bit bin, so they can use the same RoutingProvider file from node_modules
|
|
8
|
-
export { Link, LinkProps } from '@teambit/base-ui.routing.link';
|
|
9
|
-
export { NavLink, NavLinkProps } from '@teambit/base-ui.routing.nav-link';
|
|
10
|
-
export { LinkAnchor, LinkContextProvider, useLinkContext } from '@teambit/ui-foundation.ui.react-router.link-anchor';
|
|
11
|
-
|
|
12
|
-
export { ReactRouterAspect };
|
|
13
|
-
export default ReactRouterAspect;
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { reactRouterRouting } from './react-router-routing';
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useLocation } from 'react-router-dom';
|
|
2
|
-
// eslint-disable-next-line no-restricted-imports
|
|
3
|
-
import { Link } from '@teambit/ui-foundation.ui.react-router.link';
|
|
4
|
-
// eslint-disable-next-line no-restricted-imports
|
|
5
|
-
import { NavLink } from '@teambit/ui-foundation.ui.react-router.nav-link';
|
|
6
|
-
|
|
7
|
-
// React Router Link and NavLink are internal implementations of our isomorphic routing components.
|
|
8
|
-
// do not use them, use @teambit/base-ui.routing.link and @teambit/base-ui.routing.nav-link instead
|
|
9
|
-
//
|
|
10
|
-
// here we define them as the routing components of the application.
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* defines react-router's routing components (link, useLocation, etc)
|
|
14
|
-
*/
|
|
15
|
-
export const reactRouterRouting = { Link, NavLink, useLocation };
|
package/react-router.aspect.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { RouteProps } from 'react-router-dom';
|
|
3
|
-
import { History, UnregisterCallback, LocationListener, LocationDescriptor, Action } from 'history';
|
|
4
|
-
import { Slot, SlotRegistry } from '@teambit/harmony';
|
|
5
|
-
import { UIRuntime } from '@teambit/ui';
|
|
6
|
-
import { RouteSlot } from '@teambit/ui-foundation.ui.react-router.slot-router';
|
|
7
|
-
import { isBrowser } from '@teambit/ui-foundation.ui.is-browser';
|
|
8
|
-
|
|
9
|
-
import { ReactRouterAspect } from './react-router.aspect';
|
|
10
|
-
import { RouteContext, RootRoute } from './route-context';
|
|
11
|
-
import { Routing } from './routing-method';
|
|
12
|
-
|
|
13
|
-
type RouteChangeSlot = SlotRegistry<LocationListener>;
|
|
14
|
-
type RenderRoutesOptions = {
|
|
15
|
-
initialLocation?: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export class ReactRouterUI {
|
|
19
|
-
private routerHistory?: History;
|
|
20
|
-
private routingMode = isBrowser ? Routing.url : Routing.static;
|
|
21
|
-
|
|
22
|
-
constructor(
|
|
23
|
-
/**
|
|
24
|
-
* route slot.
|
|
25
|
-
*/
|
|
26
|
-
private routeSlot: RouteSlot,
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
private routeChangeListener: RouteChangeSlot
|
|
31
|
-
) {}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* render all slot routes.
|
|
35
|
-
*/
|
|
36
|
-
renderRoutes(routes: RouteProps[], options: RenderRoutesOptions = {}): JSX.Element {
|
|
37
|
-
return (
|
|
38
|
-
<RouteContext reactRouterUi={this} routing={this.routingMode} location={options.initialLocation}>
|
|
39
|
-
<RootRoute routeSlot={this.routeSlot} rootRoutes={routes}></RootRoute>
|
|
40
|
-
</RouteContext>
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private unregisterListener?: UnregisterCallback = undefined;
|
|
45
|
-
/** (internal method) sets the routing engine for navigation methods */
|
|
46
|
-
setRouter = (routerHistory: History) => {
|
|
47
|
-
this.routerHistory = routerHistory;
|
|
48
|
-
|
|
49
|
-
this.unregisterListener?.();
|
|
50
|
-
this.unregisterListener = routerHistory.listen((...args) => {
|
|
51
|
-
this.routeChangeListener.values().forEach((listener) => listener(...args));
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/** decides how navigation is stored and applied.
|
|
56
|
-
* Url - updates the `window.location.pathname`.
|
|
57
|
-
* Hash - updates `window.location.hash`.
|
|
58
|
-
* InMemory - store state internally and don't update the browser.
|
|
59
|
-
*/
|
|
60
|
-
setRoutingMode(routing: Routing) {
|
|
61
|
-
this.routingMode = routing;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* register a new route.
|
|
66
|
-
*/
|
|
67
|
-
register(route: RouteProps) {
|
|
68
|
-
this.routeSlot.register(route);
|
|
69
|
-
return this;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
registerListener(listener: LocationListener) {
|
|
73
|
-
this.routeChangeListener.register(listener);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* change browser location
|
|
78
|
-
*/
|
|
79
|
-
navigateTo = (
|
|
80
|
-
/** destination */
|
|
81
|
-
path: LocationDescriptor,
|
|
82
|
-
/**
|
|
83
|
-
* type of history action to execute (pop / push / replace).
|
|
84
|
-
* Supports state-object for legacy calls. (this will be removed when supported by symphony)
|
|
85
|
-
*/
|
|
86
|
-
action?: Action | Record<string, any>
|
|
87
|
-
) => {
|
|
88
|
-
if (typeof action !== 'string') {
|
|
89
|
-
this.legacyNavigateTo(path as string, action);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
switch (action) {
|
|
94
|
-
case 'POP':
|
|
95
|
-
return; // TBD;
|
|
96
|
-
case 'REPLACE':
|
|
97
|
-
this.routerHistory?.replace(path);
|
|
98
|
-
return;
|
|
99
|
-
case 'PUSH':
|
|
100
|
-
default:
|
|
101
|
-
this.routerHistory?.push(path);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* change browser location
|
|
107
|
-
*/
|
|
108
|
-
private legacyNavigateTo = (
|
|
109
|
-
/** destination */
|
|
110
|
-
path: string,
|
|
111
|
-
state?: Record<string, any>
|
|
112
|
-
) => {
|
|
113
|
-
this.routerHistory?.push(path, state);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
static slots = [Slot.withType<RouteProps>(), Slot.withType<LocationListener>()];
|
|
117
|
-
static runtime = UIRuntime;
|
|
118
|
-
|
|
119
|
-
static async provider(deps, config, [routeSlot, routeChangeSlot]: [RouteSlot, RouteChangeSlot]) {
|
|
120
|
-
return new ReactRouterUI(routeSlot, routeChangeSlot);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
ReactRouterAspect.addRuntime(ReactRouterUI);
|
package/route-context.tsx
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, ReactNode } from 'react';
|
|
2
|
-
import { BrowserRouter, StaticRouter, MemoryRouter, HashRouter, RouteProps, useHistory } from 'react-router-dom';
|
|
3
|
-
import { RoutingProvider } from '@teambit/base-ui.routing.routing-provider';
|
|
4
|
-
import { RouteSlot, SlotRouter } from '@teambit/ui-foundation.ui.react-router.slot-router';
|
|
5
|
-
import { ReactRouterUI } from './react-router.ui.runtime';
|
|
6
|
-
import { reactRouterRouting } from './react-router-routing';
|
|
7
|
-
import { Routing } from './routing-method';
|
|
8
|
-
|
|
9
|
-
export type History = ReturnType<typeof useHistory>;
|
|
10
|
-
|
|
11
|
-
type RouterContextProps = {
|
|
12
|
-
reactRouterUi: ReactRouterUI;
|
|
13
|
-
routing?: Routing;
|
|
14
|
-
children: ReactNode;
|
|
15
|
-
location?: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type RootRouteProps = {
|
|
19
|
-
rootRoutes: RouteProps[];
|
|
20
|
-
routeSlot: RouteSlot;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Setup context needed for routing.
|
|
25
|
-
*/
|
|
26
|
-
export function RouteContext({ reactRouterUi, routing = Routing.url, children, location }: RouterContextProps) {
|
|
27
|
-
return (
|
|
28
|
-
// {/* set up the virtual router (browser, inMemory, etc) */}
|
|
29
|
-
<Router type={routing} location={location}>
|
|
30
|
-
{/* injects History object back to reactRouterUi */}
|
|
31
|
-
<HistoryGetter onRouterChange={reactRouterUi.setRouter} />
|
|
32
|
-
{/* injects react-router Link into context */}
|
|
33
|
-
<RoutingProvider value={reactRouterRouting}>
|
|
34
|
-
{/* route tree root: */}
|
|
35
|
-
{children}
|
|
36
|
-
</RoutingProvider>
|
|
37
|
-
</Router>
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function RootRoute({ rootRoutes, routeSlot }: RootRouteProps) {
|
|
42
|
-
return <SlotRouter slot={routeSlot} rootRoutes={rootRoutes} />;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** provides the router engine (browser, inMemory, etc) */
|
|
46
|
-
function Router({ type, children, location }: { type: Routing; children: ReactNode; location?: string }) {
|
|
47
|
-
switch (type) {
|
|
48
|
-
case Routing.static:
|
|
49
|
-
return <StaticRouter location={location}>{children}</StaticRouter>;
|
|
50
|
-
case Routing.inMemory:
|
|
51
|
-
return (
|
|
52
|
-
<MemoryRouter initialEntries={[location || '/']} initialIndex={1}>
|
|
53
|
-
{children}
|
|
54
|
-
</MemoryRouter>
|
|
55
|
-
);
|
|
56
|
-
case Routing.hash:
|
|
57
|
-
return <HashRouter>{children}</HashRouter>;
|
|
58
|
-
case Routing.url:
|
|
59
|
-
default:
|
|
60
|
-
return <BrowserRouter>{children}</BrowserRouter>;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Calls onRouterChange when routing History object changes.
|
|
66
|
-
* Used to inject history back into reactRouterUi
|
|
67
|
-
* (needs to be rendered inside of <BrowserRouter/>)
|
|
68
|
-
*/
|
|
69
|
-
function HistoryGetter({ onRouterChange }: { onRouterChange: (routerHistory: History) => void }) {
|
|
70
|
-
const history = useHistory();
|
|
71
|
-
useEffect(() => onRouterChange(history), [history]);
|
|
72
|
-
|
|
73
|
-
return null;
|
|
74
|
-
}
|
package/routing-method.tsx
DELETED
package/tsconfig.json
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": [
|
|
4
|
-
"es2019",
|
|
5
|
-
"DOM",
|
|
6
|
-
"ES6",
|
|
7
|
-
"DOM.Iterable",
|
|
8
|
-
"ScriptHost"
|
|
9
|
-
],
|
|
10
|
-
"target": "es2015",
|
|
11
|
-
"module": "commonjs",
|
|
12
|
-
"jsx": "react",
|
|
13
|
-
"declaration": true,
|
|
14
|
-
"sourceMap": true,
|
|
15
|
-
"skipLibCheck": true,
|
|
16
|
-
"moduleResolution": "node",
|
|
17
|
-
"esModuleInterop": true,
|
|
18
|
-
"outDir": "dist",
|
|
19
|
-
"composite": true,
|
|
20
|
-
"emitDeclarationOnly": true,
|
|
21
|
-
"experimentalDecorators": true,
|
|
22
|
-
"emitDecoratorMetadata": true,
|
|
23
|
-
"allowSyntheticDefaultImports": true,
|
|
24
|
-
"strictPropertyInitialization": false,
|
|
25
|
-
"strict": true,
|
|
26
|
-
"noImplicitAny": false,
|
|
27
|
-
"rootDir": ".",
|
|
28
|
-
"preserveConstEnums": true,
|
|
29
|
-
"resolveJsonModule": true
|
|
30
|
-
},
|
|
31
|
-
"exclude": [
|
|
32
|
-
"dist"
|
|
33
|
-
]
|
|
34
|
-
}
|
package/types/asset.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
declare module '*.png' {
|
|
2
|
-
const value: any;
|
|
3
|
-
export = value;
|
|
4
|
-
}
|
|
5
|
-
declare module '*.svg' {
|
|
6
|
-
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
|
-
|
|
8
|
-
export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
|
|
9
|
-
const src: string;
|
|
10
|
-
export default src;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// @TODO Gilad
|
|
14
|
-
declare module '*.jpg' {
|
|
15
|
-
const value: any;
|
|
16
|
-
export = value;
|
|
17
|
-
}
|
|
18
|
-
declare module '*.jpeg' {
|
|
19
|
-
const value: any;
|
|
20
|
-
export = value;
|
|
21
|
-
}
|
|
22
|
-
declare module '*.gif' {
|
|
23
|
-
const value: any;
|
|
24
|
-
export = value;
|
|
25
|
-
}
|
|
26
|
-
declare module '*.bmp' {
|
|
27
|
-
const value: any;
|
|
28
|
-
export = value;
|
|
29
|
-
}
|
package/types/style.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
declare module '*.module.css' {
|
|
2
|
-
const classes: { readonly [key: string]: string };
|
|
3
|
-
export default classes;
|
|
4
|
-
}
|
|
5
|
-
declare module '*.module.scss' {
|
|
6
|
-
const classes: { readonly [key: string]: string };
|
|
7
|
-
export default classes;
|
|
8
|
-
}
|
|
9
|
-
declare module '*.module.sass' {
|
|
10
|
-
const classes: { readonly [key: string]: string };
|
|
11
|
-
export default classes;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
declare module '*.module.less' {
|
|
15
|
-
const classes: { readonly [key: string]: string };
|
|
16
|
-
export default classes;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
declare module '*.less' {
|
|
20
|
-
const classes: { readonly [key: string]: string };
|
|
21
|
-
export default classes;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
declare module '*.css' {
|
|
25
|
-
const classes: { readonly [key: string]: string };
|
|
26
|
-
export default classes;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
declare module '*.sass' {
|
|
30
|
-
const classes: { readonly [key: string]: string };
|
|
31
|
-
export default classes;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
declare module '*.scss' {
|
|
35
|
-
const classes: { readonly [key: string]: string };
|
|
36
|
-
export default classes;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
declare module '*.mdx' {
|
|
40
|
-
const component: any;
|
|
41
|
-
export default component;
|
|
42
|
-
}
|