@teambit/react-router 0.0.802 → 0.0.803
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/react-router.ui.runtime.d.ts +4 -3
- package/dist/react-router.ui.runtime.js +17 -13
- package/dist/react-router.ui.runtime.js.map +1 -1
- package/package-tar/teambit-react-router-0.0.803.tgz +0 -0
- package/package.json +4 -5
- package/{preview-1659151732866.js → preview-1659271062546.js} +2 -2
- package/react-router.ui.runtime.tsx +19 -6
- package/package-tar/teambit-react-router-0.0.802.tgz +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { Location, NavigationType, RouteProps } from 'react-router-dom';
|
|
3
3
|
import { SlotRegistry } from '@teambit/harmony';
|
|
4
|
-
import {
|
|
4
|
+
import type { SSR } from '@teambit/ui';
|
|
5
5
|
import { RouteSlot } from '@teambit/ui-foundation.ui.react-router.slot-router';
|
|
6
6
|
import { Routing } from './routing-method';
|
|
7
7
|
export declare type LocationListener = (location: Location, action: NavigationType) => void;
|
|
@@ -49,8 +49,9 @@ export declare class ReactRouterUI {
|
|
|
49
49
|
navigateTo: (path: Location | string, action?: NavigationType | undefined) => void;
|
|
50
50
|
private navigate?;
|
|
51
51
|
private handleLocationChange;
|
|
52
|
-
private
|
|
53
|
-
|
|
52
|
+
private RoutingContext;
|
|
53
|
+
private ServerRouting;
|
|
54
|
+
renderPlugin: SSR.RenderPlugin<RenderContext>;
|
|
54
55
|
static slots: (((registerFn: () => string) => SlotRegistry<RouteProps>) | ((registerFn: () => string) => SlotRegistry<LocationListener>))[];
|
|
55
56
|
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
|
56
57
|
static provider(deps: any, config: any, [routeSlot, routeChangeSlot]: [RouteSlot, RouteChangeSlot]): Promise<ReactRouterUI>;
|
|
@@ -53,16 +53,6 @@ function _ui() {
|
|
|
53
53
|
return data;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
function _uiFoundationUi() {
|
|
57
|
-
const data = require("@teambit/ui-foundation.ui.is-browser");
|
|
58
|
-
|
|
59
|
-
_uiFoundationUi = function () {
|
|
60
|
-
return data;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return data;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
56
|
function _reactRouter() {
|
|
67
57
|
const data = require("./react-router.aspect");
|
|
68
58
|
|
|
@@ -115,7 +105,7 @@ class ReactRouterUI {
|
|
|
115
105
|
routeChangeListener) {
|
|
116
106
|
this.routeSlot = routeSlot;
|
|
117
107
|
this.routeChangeListener = routeChangeListener;
|
|
118
|
-
(0, _defineProperty2().default)(this, "routingMode",
|
|
108
|
+
(0, _defineProperty2().default)(this, "routingMode", _routingMethod().Routing.url);
|
|
119
109
|
(0, _defineProperty2().default)(this, "navigateTo", (path, action) => {
|
|
120
110
|
var _this$navigate, _this$navigate2;
|
|
121
111
|
|
|
@@ -145,7 +135,7 @@ class ReactRouterUI {
|
|
|
145
135
|
const listeners = this.routeChangeListener.values();
|
|
146
136
|
listeners.forEach(listener => listener(location, action));
|
|
147
137
|
});
|
|
148
|
-
(0, _defineProperty2().default)(this, "
|
|
138
|
+
(0, _defineProperty2().default)(this, "RoutingContext", ({
|
|
149
139
|
children,
|
|
150
140
|
renderCtx
|
|
151
141
|
}) => {
|
|
@@ -158,6 +148,19 @@ class ReactRouterUI {
|
|
|
158
148
|
onNavigatorChange: nav => this.navigate = nav
|
|
159
149
|
}));
|
|
160
150
|
});
|
|
151
|
+
(0, _defineProperty2().default)(this, "ServerRouting", ({
|
|
152
|
+
children,
|
|
153
|
+
renderCtx
|
|
154
|
+
}) => {
|
|
155
|
+
return /*#__PURE__*/_react().default.createElement(_routeContext().RouteContext, {
|
|
156
|
+
reactRouterUi: this,
|
|
157
|
+
routing: _routingMethod().Routing.static,
|
|
158
|
+
location: renderCtx === null || renderCtx === void 0 ? void 0 : renderCtx.initialLocation
|
|
159
|
+
}, children, /*#__PURE__*/_react().default.createElement(_LocationHooks().LocationHooks, {
|
|
160
|
+
onLocationChange: this.handleLocationChange,
|
|
161
|
+
onNavigatorChange: nav => this.navigate = nav
|
|
162
|
+
}));
|
|
163
|
+
});
|
|
161
164
|
(0, _defineProperty2().default)(this, "renderPlugin", {
|
|
162
165
|
browserInit: () => {
|
|
163
166
|
const initialLocation = `${window.location.pathname}${window.location.search}${window.location.hash}`;
|
|
@@ -173,7 +176,8 @@ class ReactRouterUI {
|
|
|
173
176
|
initialLocation
|
|
174
177
|
};
|
|
175
178
|
},
|
|
176
|
-
|
|
179
|
+
reactClientContext: this.RoutingContext,
|
|
180
|
+
reactServerContext: this.ServerRouting
|
|
177
181
|
});
|
|
178
182
|
}
|
|
179
183
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ReactRouterUI","constructor","routeSlot","routeChangeListener","
|
|
1
|
+
{"version":3,"names":["ReactRouterUI","constructor","routeSlot","routeChangeListener","Routing","url","path","action","state","undefined","navigate","replace","location","listeners","values","forEach","listener","children","renderCtx","routingMode","initialLocation","handleLocationChange","nav","static","browserInit","window","pathname","search","hash","serverInit","browser","reactClientContext","RoutingContext","reactServerContext","ServerRouting","renderRoutes","routes","setRoutingMode","routing","register","route","registerListener","provider","deps","config","routeChangeSlot","Slot","withType","UIRuntime","ReactRouterAspect","addRuntime"],"sources":["react-router.ui.runtime.tsx"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport { NavigateFunction } from 'react-router-dom';\nimport type { Location, NavigationType, RouteProps } from 'react-router-dom';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { UIRuntime } from '@teambit/ui';\nimport type { SSR } from '@teambit/ui';\nimport { RouteSlot } from '@teambit/ui-foundation.ui.react-router.slot-router';\n\nimport { ReactRouterAspect } from './react-router.aspect';\nimport { RouteContext, RootRoute } from './route-context';\nimport { Routing } from './routing-method';\nimport { LocationHooks } from './LocationHooks';\n\nexport type LocationListener = (location: Location, action: NavigationType) => void;\ntype RouteChangeSlot = SlotRegistry<LocationListener>;\ntype RenderContext = { initialLocation?: string };\n\nexport class ReactRouterUI {\n private routingMode = Routing.url;\n\n constructor(\n /**\n * route slot.\n */\n private routeSlot: RouteSlot,\n /**\n *\n */\n private routeChangeListener: RouteChangeSlot\n ) {}\n\n /**\n * render all slot routes.\n */\n renderRoutes(routes: RouteProps[]) {\n return <RootRoute routeSlot={this.routeSlot} rootRoutes={routes} />;\n }\n\n /** decides how navigation is stored and applied.\n * Url - updates the `window.location.pathname`.\n * Hash - updates `window.location.hash`.\n * InMemory - store state internally and don't update the browser.\n */\n setRoutingMode(routing: Routing) {\n this.routingMode = routing;\n }\n\n /**\n * register a new route.\n */\n register(route: RouteProps) {\n this.routeSlot.register(route);\n return this;\n }\n\n registerListener(listener: LocationListener) {\n this.routeChangeListener.register(listener);\n }\n\n /**\n * change browser location\n */\n navigateTo = (\n /** destination */\n path: Location | string,\n /** history action to execute (pop / push / replace) */\n action?: NavigationType\n ) => {\n const state = typeof path !== 'string' ? path.state : undefined;\n\n switch (action) {\n case 'POP':\n return; // TBD;\n case 'REPLACE':\n this.navigate?.(path, { replace: true, state });\n return;\n case 'PUSH':\n default:\n this.navigate?.(path, { state });\n }\n };\n\n private navigate?: NavigateFunction = undefined;\n\n private handleLocationChange = (location: Location, action: NavigationType) => {\n const listeners = this.routeChangeListener.values();\n listeners.forEach((listener) => listener(location, action));\n };\n\n private RoutingContext = ({ children, renderCtx }: { children: ReactNode; renderCtx?: RenderContext }) => {\n return (\n <RouteContext reactRouterUi={this} routing={this.routingMode} location={renderCtx?.initialLocation}>\n {children}\n <LocationHooks\n onLocationChange={this.handleLocationChange}\n onNavigatorChange={(nav) => (this.navigate = nav)}\n />\n </RouteContext>\n );\n };\n\n private ServerRouting = ({ children, renderCtx }: { children: ReactNode; renderCtx?: RenderContext }) => {\n return (\n <RouteContext reactRouterUi={this} routing={Routing.static} location={renderCtx?.initialLocation}>\n {children}\n <LocationHooks\n onLocationChange={this.handleLocationChange}\n onNavigatorChange={(nav) => (this.navigate = nav)}\n />\n </RouteContext>\n );\n };\n\n public renderPlugin: SSR.RenderPlugin<RenderContext> = {\n browserInit: () => {\n const initialLocation = `${window.location.pathname}${window.location.search}${window.location.hash}`;\n return { initialLocation };\n },\n serverInit: ({ browser }) => {\n const initialLocation = browser?.location.url;\n return { initialLocation };\n },\n reactClientContext: this.RoutingContext,\n reactServerContext: this.ServerRouting,\n };\n\n static slots = [Slot.withType<RouteProps>(), Slot.withType<LocationListener>()];\n static runtime = UIRuntime;\n\n static async provider(deps, config, [routeSlot, routeChangeSlot]: [RouteSlot, RouteChangeSlot]) {\n return new ReactRouterUI(routeSlot, routeChangeSlot);\n }\n}\n\nReactRouterAspect.addRuntime(ReactRouterUI);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAIA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAMO,MAAMA,aAAN,CAAoB;EAGzBC,WAAW;EACT;AACJ;AACA;EACYC,SAJC;EAKT;AACJ;AACA;EACYC,mBARC,EAST;IAAA,KALQD,SAKR,GALQA,SAKR;IAAA,KADQC,mBACR,GADQA,mBACR;IAAA,qDAXoBC,wBAAA,CAAQC,GAW5B;IAAA,oDAiCW,CAEXC,IAFW,EAIXC,MAJW,KAKR;MAAA;;MACH,MAAMC,KAAK,GAAG,OAAOF,IAAP,KAAgB,QAAhB,GAA2BA,IAAI,CAACE,KAAhC,GAAwCC,SAAtD;;MAEA,QAAQF,MAAR;QACE,KAAK,KAAL;UACE;QAAQ;;QACV,KAA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A7GJ/C,a,aA8GMgD,e;;AAOnBC,gCAAA,CAAkBC,UAAlB,CAA6BlD,aAA7B"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/react-router",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.803",
|
|
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.803"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@babel/runtime": "7.12.18",
|
|
@@ -14,9 +14,8 @@
|
|
|
14
14
|
"@teambit/base-react.navigation.link": "2.0.27",
|
|
15
15
|
"@teambit/harmony": "0.3.3",
|
|
16
16
|
"@teambit/ui-foundation.ui.navigation.react-router-adapter": "6.1.1",
|
|
17
|
-
"@teambit/ui-foundation.ui.is-browser": "0.0.486",
|
|
18
17
|
"@teambit/ui-foundation.ui.react-router.slot-router": "0.0.490",
|
|
19
|
-
"@teambit/ui": "0.0.
|
|
18
|
+
"@teambit/ui": "0.0.803"
|
|
20
19
|
},
|
|
21
20
|
"devDependencies": {
|
|
22
21
|
"@types/react": "^17.0.8",
|
|
@@ -28,7 +27,7 @@
|
|
|
28
27
|
},
|
|
29
28
|
"peerDependencies": {
|
|
30
29
|
"react-router-dom": "^6.0.0",
|
|
31
|
-
"@teambit/legacy": "1.0.
|
|
30
|
+
"@teambit/legacy": "1.0.317",
|
|
32
31
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
33
32
|
"react": "^16.8.0 || ^17.0.0"
|
|
34
33
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.ui-foundation_react-router@0.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.ui-foundation_react-router@0.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.ui-foundation_react-router@0.0.803/dist/react-router.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.ui-foundation_react-router@0.0.803/dist/react-router.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
|
@@ -2,9 +2,9 @@ import React, { ReactNode } from 'react';
|
|
|
2
2
|
import { NavigateFunction } from 'react-router-dom';
|
|
3
3
|
import type { Location, NavigationType, RouteProps } from 'react-router-dom';
|
|
4
4
|
import { Slot, SlotRegistry } from '@teambit/harmony';
|
|
5
|
-
import {
|
|
5
|
+
import { UIRuntime } from '@teambit/ui';
|
|
6
|
+
import type { SSR } from '@teambit/ui';
|
|
6
7
|
import { RouteSlot } from '@teambit/ui-foundation.ui.react-router.slot-router';
|
|
7
|
-
import { isBrowser } from '@teambit/ui-foundation.ui.is-browser';
|
|
8
8
|
|
|
9
9
|
import { ReactRouterAspect } from './react-router.aspect';
|
|
10
10
|
import { RouteContext, RootRoute } from './route-context';
|
|
@@ -16,7 +16,7 @@ type RouteChangeSlot = SlotRegistry<LocationListener>;
|
|
|
16
16
|
type RenderContext = { initialLocation?: string };
|
|
17
17
|
|
|
18
18
|
export class ReactRouterUI {
|
|
19
|
-
private routingMode =
|
|
19
|
+
private routingMode = Routing.url;
|
|
20
20
|
|
|
21
21
|
constructor(
|
|
22
22
|
/**
|
|
@@ -87,7 +87,7 @@ export class ReactRouterUI {
|
|
|
87
87
|
listeners.forEach((listener) => listener(location, action));
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
-
private
|
|
90
|
+
private RoutingContext = ({ children, renderCtx }: { children: ReactNode; renderCtx?: RenderContext }) => {
|
|
91
91
|
return (
|
|
92
92
|
<RouteContext reactRouterUi={this} routing={this.routingMode} location={renderCtx?.initialLocation}>
|
|
93
93
|
{children}
|
|
@@ -99,7 +99,19 @@ export class ReactRouterUI {
|
|
|
99
99
|
);
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
private ServerRouting = ({ children, renderCtx }: { children: ReactNode; renderCtx?: RenderContext }) => {
|
|
103
|
+
return (
|
|
104
|
+
<RouteContext reactRouterUi={this} routing={Routing.static} location={renderCtx?.initialLocation}>
|
|
105
|
+
{children}
|
|
106
|
+
<LocationHooks
|
|
107
|
+
onLocationChange={this.handleLocationChange}
|
|
108
|
+
onNavigatorChange={(nav) => (this.navigate = nav)}
|
|
109
|
+
/>
|
|
110
|
+
</RouteContext>
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
public renderPlugin: SSR.RenderPlugin<RenderContext> = {
|
|
103
115
|
browserInit: () => {
|
|
104
116
|
const initialLocation = `${window.location.pathname}${window.location.search}${window.location.hash}`;
|
|
105
117
|
return { initialLocation };
|
|
@@ -108,7 +120,8 @@ export class ReactRouterUI {
|
|
|
108
120
|
const initialLocation = browser?.location.url;
|
|
109
121
|
return { initialLocation };
|
|
110
122
|
},
|
|
111
|
-
|
|
123
|
+
reactClientContext: this.RoutingContext,
|
|
124
|
+
reactServerContext: this.ServerRouting,
|
|
112
125
|
};
|
|
113
126
|
|
|
114
127
|
static slots = [Slot.withType<RouteProps>(), Slot.withType<LocationListener>()];
|
|
Binary file
|