@teambit/react-router 1.0.107 → 1.0.108
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/LocationHooks.d.ts +1 -1
- package/dist/{preview-1703590665075.js → preview-1703647408454.js} +2 -2
- package/dist/react-router.composition.d.ts +2 -2
- package/dist/react-router.ui.runtime.d.ts +5 -5
- package/dist/react-router.ui.runtime.js +5 -6
- package/dist/react-router.ui.runtime.js.map +1 -1
- package/dist/route-context.d.ts +5 -5
- package/index.ts +10 -0
- package/package.json +13 -20
- package/react-router.aspect.ts +7 -0
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
package/dist/LocationHooks.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.ui-foundation_react-router@1.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.ui-foundation_react-router@1.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.ui-foundation_react-router@1.0.108/dist/react-router.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.ui-foundation_react-router@1.0.108/dist/react-router.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const Logo: () =>
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const Logo: () => JSX.Element;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import type { Location, NavigationType, RouteProps } from 'react-router-dom';
|
|
3
3
|
import { SlotRegistry } from '@teambit/harmony';
|
|
4
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
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
export type LocationListener = (location: Location, action: NavigationType) => void;
|
|
8
|
+
type RouteChangeSlot = SlotRegistry<LocationListener>;
|
|
9
|
+
type RenderContext = {
|
|
10
10
|
initialLocation?: string;
|
|
11
11
|
};
|
|
12
12
|
export declare class ReactRouterUI {
|
|
@@ -31,7 +31,7 @@ export declare class ReactRouterUI {
|
|
|
31
31
|
/**
|
|
32
32
|
* render all slot routes.
|
|
33
33
|
*/
|
|
34
|
-
renderRoutes(routes: RouteProps[]):
|
|
34
|
+
renderRoutes(routes: RouteProps[]): JSX.Element;
|
|
35
35
|
/** decides how navigation is stored and applied.
|
|
36
36
|
* Url - updates the `window.location.pathname`.
|
|
37
37
|
* Hash - updates `window.location.hash`.
|
|
@@ -74,21 +74,20 @@ class ReactRouterUI {
|
|
|
74
74
|
* change browser location
|
|
75
75
|
*/
|
|
76
76
|
_defineProperty(this, "navigateTo", (path, action) => {
|
|
77
|
-
var _this$navigate, _this$navigate2;
|
|
78
77
|
const state = typeof path !== 'string' ? path.state : undefined;
|
|
79
78
|
switch (action) {
|
|
80
79
|
case 'POP':
|
|
81
80
|
return;
|
|
82
81
|
// TBD;
|
|
83
82
|
case 'REPLACE':
|
|
84
|
-
|
|
83
|
+
this.navigate?.(path, {
|
|
85
84
|
replace: true,
|
|
86
85
|
state
|
|
87
86
|
});
|
|
88
87
|
return;
|
|
89
88
|
case 'PUSH':
|
|
90
89
|
default:
|
|
91
|
-
|
|
90
|
+
this.navigate?.(path, {
|
|
92
91
|
state
|
|
93
92
|
});
|
|
94
93
|
}
|
|
@@ -105,7 +104,7 @@ class ReactRouterUI {
|
|
|
105
104
|
return /*#__PURE__*/_react().default.createElement(_routeContext().RouteContext, {
|
|
106
105
|
reactRouterUi: this,
|
|
107
106
|
routing: this.routingMode,
|
|
108
|
-
location: renderCtx
|
|
107
|
+
location: renderCtx?.initialLocation
|
|
109
108
|
}, children, /*#__PURE__*/_react().default.createElement(_LocationHooks().LocationHooks, {
|
|
110
109
|
onLocationChange: this.handleLocationChange,
|
|
111
110
|
onNavigatorChange: nav => this.navigate = nav
|
|
@@ -118,7 +117,7 @@ class ReactRouterUI {
|
|
|
118
117
|
return /*#__PURE__*/_react().default.createElement(_routeContext().RouteContext, {
|
|
119
118
|
reactRouterUi: this,
|
|
120
119
|
routing: _routingMethod().Routing.static,
|
|
121
|
-
location: renderCtx
|
|
120
|
+
location: renderCtx?.initialLocation
|
|
122
121
|
}, children, /*#__PURE__*/_react().default.createElement(_LocationHooks().LocationHooks, {
|
|
123
122
|
onLocationChange: this.handleLocationChange,
|
|
124
123
|
onNavigatorChange: nav => this.navigate = nav
|
|
@@ -134,7 +133,7 @@ class ReactRouterUI {
|
|
|
134
133
|
serverInit: ({
|
|
135
134
|
browser
|
|
136
135
|
}) => {
|
|
137
|
-
const initialLocation = browser
|
|
136
|
+
const initialLocation = browser?.location.url;
|
|
138
137
|
return {
|
|
139
138
|
initialLocation
|
|
140
139
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","data","_interopRequireDefault","require","_harmony","_ui","_reactRouter","_routeContext","_routingMethod","_LocationHooks","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","ReactRouterUI","constructor","routeSlot","routeChangeListener","Routing","url","path","action","_this$navigate","_this$navigate2","state","undefined","navigate","replace","location","listeners","values","forEach","listener","children","renderCtx","createElement","RouteContext","reactRouterUi","routing","routingMode","initialLocation","LocationHooks","onLocationChange","handleLocationChange","onNavigatorChange","nav","static","browserInit","window","pathname","search","hash","serverInit","browser","reactClientContext","RoutingContext","reactServerContext","ServerRouting","renderRoutes","routes","RootRoute","rootRoutes","setRoutingMode","register","route","registerListener","provider","deps","config","routeChangeSlot","exports","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,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAG,SAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EA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AAA,CAAAxD,aAAA,GAAAA,aAAA;AAAApB,eAAA,CAnHYoB,aAAa,WA6GT,CAACyD,eAAI,CAACC,QAAQ,CAAa,CAAC,EAAED,eAAI,CAACC,QAAQ,CAAmB,CAAC,CAAC;AAAA9E,eAAA,CA7GpEoB,aAAa,aA8GP2D,eAAS;AAO5BC,gCAAiB,CAACC,UAAU,CAAC7D,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"names":["_react","data","_interopRequireDefault","require","_harmony","_ui","_reactRouter","_routeContext","_routingMethod","_LocationHooks","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","ReactRouterUI","constructor","routeSlot","routeChangeListener","Routing","url","path","action","state","undefined","navigate","replace","location","listeners","values","forEach","listener","children","renderCtx","createElement","RouteContext","reactRouterUi","routing","routingMode","initialLocation","LocationHooks","onLocationChange","handleLocationChange","onNavigatorChange","nav","static","browserInit","window","pathname","search","hash","serverInit","browser","reactClientContext","RoutingContext","reactServerContext","ServerRouting","renderRoutes","routes","RootRoute","rootRoutes","setRoutingMode","register","route","registerListener","provider","deps","config","routeChangeSlot","exports","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,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAG,SAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,QAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,IAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,GAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAIA,SAAAK,aAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,YAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,cAAA;EAAA,MAAAN,IAAA,GAAAE,OAAA;EAAAI,aAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAO,eAAA;EAAA,MAAAP,IAAA,GAAAE,OAAA;EAAAK,cAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SA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AACA;EACEyB,QAAQA,CAACC,KAAiB,EAAE;IAC1B,IAAI,CAAC9C,SAAS,CAAC6C,QAAQ,CAACC,KAAK,CAAC;IAC9B,OAAO,IAAI;EACb;EAEAC,gBAAgBA,CAACjC,QAA0B,EAAE;IAC3C,IAAI,CAACb,mBAAmB,CAAC4C,QAAQ,CAAC/B,QAAQ,CAAC;EAC7C;EAwEA,aAAakC,QAAQA,CAACC,IAAI,EAAEC,MAAM,EAAE,CAAClD,SAAS,EAAEmD,eAAe,CAA+B,EAAE;IAC9F,OAAO,IAAIrD,aAAa,CAACE,SAAS,EAAEmD,eAAe,CAAC;EACtD;AACF;AAACC,OAAA,CAAAtD,aAAA,GAAAA,aAAA;AAAApB,eAAA,CAnHYoB,aAAa,WA6GT,CAACuD,eAAI,CAACC,QAAQ,CAAa,CAAC,EAAED,eAAI,CAACC,QAAQ,CAAmB,CAAC,CAAC;AAAA5E,eAAA,CA7GpEoB,aAAa,aA8GPyD,eAAS;AAO5BC,gCAAiB,CAACC,UAAU,CAAC3D,aAAa,CAAC"}
|
package/dist/route-context.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
2
|
import { RouteProps } from 'react-router-dom';
|
|
3
3
|
import { RouteSlot } from '@teambit/ui-foundation.ui.react-router.slot-router';
|
|
4
4
|
import { ReactRouterUI } from './react-router.ui.runtime';
|
|
5
5
|
import { Routing } from './routing-method';
|
|
6
|
-
|
|
6
|
+
type RouterContextProps = {
|
|
7
7
|
reactRouterUi: ReactRouterUI;
|
|
8
8
|
routing?: Routing;
|
|
9
9
|
children: ReactNode;
|
|
10
10
|
location?: string;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
type RootRouteProps = {
|
|
13
13
|
rootRoutes: RouteProps[];
|
|
14
14
|
routeSlot: RouteSlot;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Setup context needed for routing.
|
|
18
18
|
*/
|
|
19
|
-
export declare function RouteContext({ routing, children, location }: RouterContextProps):
|
|
20
|
-
export declare function RootRoute({ rootRoutes, routeSlot }: RootRouteProps):
|
|
19
|
+
export declare function RouteContext({ routing, children, location }: RouterContextProps): JSX.Element;
|
|
20
|
+
export declare function RootRoute({ rootRoutes, routeSlot }: RootRouteProps): JSX.Element;
|
|
21
21
|
export {};
|
package/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
export * as navigation from '@teambit/base-react.navigation.link';
|
|
7
|
+
export * as ReactRouter from 'react-router-dom';
|
|
8
|
+
|
|
9
|
+
export { ReactRouterAspect };
|
|
10
|
+
export default ReactRouterAspect;
|
package/package.json
CHANGED
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/react-router",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.108",
|
|
4
4
|
"homepage": "https://bit.cloud/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": "1.0.
|
|
9
|
+
"version": "1.0.108"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"core-js": "^3.0.0",
|
|
13
|
-
"@babel/runtime": "7.20.0",
|
|
14
12
|
"@teambit/base-react.navigation.link": "2.0.27",
|
|
15
13
|
"@teambit/harmony": "0.4.6",
|
|
16
14
|
"@teambit/ui-foundation.ui.react-router.slot-router": "0.0.506",
|
|
17
15
|
"@teambit/ui-foundation.ui.navigation.react-router-adapter": "6.1.1",
|
|
18
|
-
"@teambit/ui": "1.0.
|
|
16
|
+
"@teambit/ui": "1.0.108"
|
|
19
17
|
},
|
|
20
18
|
"devDependencies": {
|
|
21
|
-
"@types/react": "^17.0.8",
|
|
22
19
|
"@types/mocha": "9.1.0",
|
|
23
|
-
"@types/
|
|
24
|
-
"@types/
|
|
25
|
-
"@
|
|
26
|
-
"@types/testing-library__jest-dom": "5.9.5"
|
|
20
|
+
"@types/jest": "^29.2.2",
|
|
21
|
+
"@types/testing-library__jest-dom": "^5.9.5",
|
|
22
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.13"
|
|
27
23
|
},
|
|
28
24
|
"peerDependencies": {
|
|
29
|
-
"react
|
|
30
|
-
"
|
|
31
|
-
"react": "^
|
|
32
|
-
"
|
|
25
|
+
"react": "^17.0.0 || ^18.0.0",
|
|
26
|
+
"react-router-dom": "^6.8.1",
|
|
27
|
+
"@types/react": "^18.2.12",
|
|
28
|
+
"@teambit/legacy": "1.0.624"
|
|
33
29
|
},
|
|
34
30
|
"license": "Apache-2.0",
|
|
35
31
|
"optionalDependencies": {},
|
|
@@ -43,7 +39,7 @@
|
|
|
43
39
|
},
|
|
44
40
|
"private": false,
|
|
45
41
|
"engines": {
|
|
46
|
-
"node": ">=
|
|
42
|
+
"node": ">=16.0.0"
|
|
47
43
|
},
|
|
48
44
|
"repository": {
|
|
49
45
|
"type": "git",
|
|
@@ -52,12 +48,9 @@
|
|
|
52
48
|
"keywords": [
|
|
53
49
|
"bit",
|
|
54
50
|
"bit-aspect",
|
|
51
|
+
"bit-core-aspect",
|
|
55
52
|
"components",
|
|
56
53
|
"collaboration",
|
|
57
|
-
"web"
|
|
58
|
-
"react",
|
|
59
|
-
"react-components",
|
|
60
|
-
"angular",
|
|
61
|
-
"angular-components"
|
|
54
|
+
"web"
|
|
62
55
|
]
|
|
63
56
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"lib": [
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"DOM.Iterable",
|
|
8
|
-
"ScriptHost"
|
|
4
|
+
"esnext",
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.Iterable"
|
|
9
7
|
],
|
|
10
|
-
"target": "
|
|
11
|
-
"module": "
|
|
12
|
-
"jsx": "react",
|
|
13
|
-
"allowJs": true,
|
|
14
|
-
"composite": true,
|
|
8
|
+
"target": "es2020",
|
|
9
|
+
"module": "es2020",
|
|
10
|
+
"jsx": "react-jsx",
|
|
15
11
|
"declaration": true,
|
|
16
12
|
"sourceMap": true,
|
|
17
|
-
"skipLibCheck": true,
|
|
18
13
|
"experimentalDecorators": true,
|
|
19
|
-
"
|
|
14
|
+
"skipLibCheck": true,
|
|
20
15
|
"moduleResolution": "node",
|
|
21
16
|
"esModuleInterop": true,
|
|
22
|
-
"rootDir": ".",
|
|
23
17
|
"resolveJsonModule": true,
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"strictPropertyInitialization": false,
|
|
28
|
-
"strict": true,
|
|
29
|
-
"noImplicitAny": false,
|
|
30
|
-
"preserveConstEnums": true
|
|
18
|
+
"allowJs": true,
|
|
19
|
+
"outDir": "dist",
|
|
20
|
+
"emitDeclarationOnly": true
|
|
31
21
|
},
|
|
32
22
|
"exclude": [
|
|
23
|
+
"artifacts",
|
|
24
|
+
"public",
|
|
33
25
|
"dist",
|
|
26
|
+
"node_modules",
|
|
27
|
+
"package.json",
|
|
34
28
|
"esm.mjs",
|
|
35
|
-
"
|
|
29
|
+
"**/*.cjs",
|
|
30
|
+
"./dist"
|
|
36
31
|
],
|
|
37
32
|
"include": [
|
|
38
33
|
"**/*",
|
package/types/asset.d.ts
CHANGED
|
@@ -5,12 +5,12 @@ declare module '*.png' {
|
|
|
5
5
|
declare module '*.svg' {
|
|
6
6
|
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
7
|
|
|
8
|
-
export const ReactComponent: FunctionComponent<
|
|
8
|
+
export const ReactComponent: FunctionComponent<
|
|
9
|
+
SVGProps<SVGSVGElement> & { title?: string }
|
|
10
|
+
>;
|
|
9
11
|
const src: string;
|
|
10
12
|
export default src;
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
// @TODO Gilad
|
|
14
14
|
declare module '*.jpg' {
|
|
15
15
|
const value: any;
|
|
16
16
|
export = value;
|
|
@@ -27,3 +27,15 @@ declare module '*.bmp' {
|
|
|
27
27
|
const value: any;
|
|
28
28
|
export = value;
|
|
29
29
|
}
|
|
30
|
+
declare module '*.otf' {
|
|
31
|
+
const value: any;
|
|
32
|
+
export = value;
|
|
33
|
+
}
|
|
34
|
+
declare module '*.woff' {
|
|
35
|
+
const value: any;
|
|
36
|
+
export = value;
|
|
37
|
+
}
|
|
38
|
+
declare module '*.woff2' {
|
|
39
|
+
const value: any;
|
|
40
|
+
export = value;
|
|
41
|
+
}
|