@etsoo/react 1.6.0 → 1.6.1

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.
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ /**
3
+ * Dynamic router props
4
+ */
5
+ export declare type DynamicRouterProps = {
6
+ basename: string;
7
+ };
8
+ /**
9
+ * Dynamic router
10
+ * @param props Props
11
+ * @returns Component
12
+ */
13
+ export declare function DynamicRouter(props: React.PropsWithChildren<DynamicRouterProps>): JSX.Element;
@@ -0,0 +1,19 @@
1
+ import { BridgeUtils } from '@etsoo/appscript';
2
+ import React from 'react';
3
+ import { BrowserRouter, MemoryRouter } from 'react-router-dom';
4
+ function getEntries(host) {
5
+ const startUrl = host.getStartUrl();
6
+ return startUrl == null ? undefined : [startUrl];
7
+ }
8
+ /**
9
+ * Dynamic router
10
+ * @param props Props
11
+ * @returns Component
12
+ */
13
+ export function DynamicRouter(props) {
14
+ // Destruct
15
+ const { basename, children } = props;
16
+ // Layout
17
+ const host = BridgeUtils.host;
18
+ return host == null ? (React.createElement(BrowserRouter, { basename: basename }, children)) : (React.createElement(MemoryRouter, { basename: basename, initialEntries: getEntries(host) }, children));
19
+ }
package/lib/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from './app/InputDialogProps';
4
4
  export * from './app/ReactUtils';
5
5
  export * from './app/RefreshTokenRQ';
6
6
  export * from './components/DnDList';
7
+ export * from './components/DynamicRouter';
7
8
  export * from './components/GridColumn';
8
9
  export * from './components/GridLoader';
9
10
  export * from './components/GridMethodRef';
package/lib/index.js CHANGED
@@ -6,6 +6,7 @@ export * from './app/ReactUtils';
6
6
  export * from './app/RefreshTokenRQ';
7
7
  // components
8
8
  export * from './components/DnDList';
9
+ export * from './components/DynamicRouter';
9
10
  export * from './components/GridColumn';
10
11
  export * from './components/GridLoader';
11
12
  export * from './components/GridMethodRef';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "TypeScript ReactJs UI Independent Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -0,0 +1,35 @@
1
+ import { BridgeUtils, IBridgeHost } from '@etsoo/appscript';
2
+ import React from 'react';
3
+ import { BrowserRouter, MemoryRouter } from 'react-router-dom';
4
+
5
+ /**
6
+ * Dynamic router props
7
+ */
8
+ export type DynamicRouterProps = { basename: string };
9
+
10
+ function getEntries(host: IBridgeHost) {
11
+ const startUrl = host.getStartUrl();
12
+ return startUrl == null ? undefined : [startUrl];
13
+ }
14
+
15
+ /**
16
+ * Dynamic router
17
+ * @param props Props
18
+ * @returns Component
19
+ */
20
+ export function DynamicRouter(
21
+ props: React.PropsWithChildren<DynamicRouterProps>
22
+ ) {
23
+ // Destruct
24
+ const { basename, children } = props;
25
+
26
+ // Layout
27
+ const host = BridgeUtils.host;
28
+ return host == null ? (
29
+ <BrowserRouter basename={basename}>{children}</BrowserRouter>
30
+ ) : (
31
+ <MemoryRouter basename={basename} initialEntries={getEntries(host)}>
32
+ {children}
33
+ </MemoryRouter>
34
+ );
35
+ }
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export * from './app/RefreshTokenRQ';
7
7
 
8
8
  // components
9
9
  export * from './components/DnDList';
10
+ export * from './components/DynamicRouter';
10
11
  export * from './components/GridColumn';
11
12
  export * from './components/GridLoader';
12
13
  export * from './components/GridMethodRef';