@celljs/react 3.0.0
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/LICENSE +21 -0
- package/README.md +1 -0
- package/cell-cdn.yml +11 -0
- package/cell.yml +8 -0
- package/lib/browser/annotation/app.d.ts +3 -0
- package/lib/browser/annotation/app.d.ts.map +1 -0
- package/lib/browser/annotation/app.js +12 -0
- package/lib/browser/annotation/app.js.map +1 -0
- package/lib/browser/annotation/context.d.ts +3 -0
- package/lib/browser/annotation/context.d.ts.map +1 -0
- package/lib/browser/annotation/context.js +12 -0
- package/lib/browser/annotation/context.js.map +1 -0
- package/lib/browser/annotation/default-layout.d.ts +3 -0
- package/lib/browser/annotation/default-layout.d.ts.map +1 -0
- package/lib/browser/annotation/default-layout.js +12 -0
- package/lib/browser/annotation/default-layout.js.map +1 -0
- package/lib/browser/annotation/icon.d.ts +3 -0
- package/lib/browser/annotation/icon.d.ts.map +1 -0
- package/lib/browser/annotation/icon.js +12 -0
- package/lib/browser/annotation/icon.js.map +1 -0
- package/lib/browser/annotation/index.d.ts +9 -0
- package/lib/browser/annotation/index.d.ts.map +1 -0
- package/lib/browser/annotation/index.js +25 -0
- package/lib/browser/annotation/index.js.map +1 -0
- package/lib/browser/annotation/react-component.d.ts +4 -0
- package/lib/browser/annotation/react-component.d.ts.map +1 -0
- package/lib/browser/annotation/react-component.js +11 -0
- package/lib/browser/annotation/react-component.js.map +1 -0
- package/lib/browser/annotation/route.d.ts +3 -0
- package/lib/browser/annotation/route.d.ts.map +1 -0
- package/lib/browser/annotation/route.js +24 -0
- package/lib/browser/annotation/route.js.map +1 -0
- package/lib/browser/annotation/router.d.ts +3 -0
- package/lib/browser/annotation/router.d.ts.map +1 -0
- package/lib/browser/annotation/router.js +12 -0
- package/lib/browser/annotation/router.js.map +1 -0
- package/lib/browser/annotation/view.d.ts +3 -0
- package/lib/browser/annotation/view.d.ts.map +1 -0
- package/lib/browser/annotation/view.js +11 -0
- package/lib/browser/annotation/view.js.map +1 -0
- package/lib/browser/app/app-protocol.d.ts +2 -0
- package/lib/browser/app/app-protocol.d.ts.map +1 -0
- package/lib/browser/app/app-protocol.js +5 -0
- package/lib/browser/app/app-protocol.js.map +1 -0
- package/lib/browser/app/app.d.ts +9 -0
- package/lib/browser/app/app.d.ts.map +1 -0
- package/lib/browser/app/app.js +41 -0
- package/lib/browser/app/app.js.map +1 -0
- package/lib/browser/app/index.d.ts +3 -0
- package/lib/browser/app/index.d.ts.map +1 -0
- package/lib/browser/app/index.js +19 -0
- package/lib/browser/app/index.js.map +1 -0
- package/lib/browser/context/context-protocol.d.ts +6 -0
- package/lib/browser/context/context-protocol.d.ts.map +1 -0
- package/lib/browser/context/context-protocol.js +6 -0
- package/lib/browser/context/context-protocol.js.map +1 -0
- package/lib/browser/context/context-provider.d.ts +8 -0
- package/lib/browser/context/context-provider.d.ts.map +1 -0
- package/lib/browser/context/context-provider.js +35 -0
- package/lib/browser/context/context-provider.js.map +1 -0
- package/lib/browser/context/context.d.ts +10 -0
- package/lib/browser/context/context.d.ts.map +1 -0
- package/lib/browser/context/context.js +22 -0
- package/lib/browser/context/context.js.map +1 -0
- package/lib/browser/context/index.d.ts +4 -0
- package/lib/browser/context/index.d.ts.map +1 -0
- package/lib/browser/context/index.js +20 -0
- package/lib/browser/context/index.js.map +1 -0
- package/lib/browser/icon/icon-protocol.d.ts +7 -0
- package/lib/browser/icon/icon-protocol.d.ts.map +1 -0
- package/lib/browser/icon/icon-protocol.js +6 -0
- package/lib/browser/icon/icon-protocol.js.map +1 -0
- package/lib/browser/icon/icon.d.ts +2 -0
- package/lib/browser/icon/icon.d.ts.map +1 -0
- package/lib/browser/icon/icon.js +20 -0
- package/lib/browser/icon/icon.js.map +1 -0
- package/lib/browser/icon/index.d.ts +2 -0
- package/lib/browser/icon/index.d.ts.map +1 -0
- package/lib/browser/icon/index.js +18 -0
- package/lib/browser/icon/index.js.map +1 -0
- package/lib/browser/index.d.ts +12 -0
- package/lib/browser/index.d.ts.map +1 -0
- package/lib/browser/index.js +28 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/layout/index.d.ts +3 -0
- package/lib/browser/layout/index.d.ts.map +1 -0
- package/lib/browser/layout/index.js +19 -0
- package/lib/browser/layout/index.js.map +1 -0
- package/lib/browser/layout/layout-protocol.d.ts +2 -0
- package/lib/browser/layout/layout-protocol.d.ts.map +1 -0
- package/lib/browser/layout/layout-protocol.js +5 -0
- package/lib/browser/layout/layout-protocol.js.map +1 -0
- package/lib/browser/layout/layout.d.ts +5 -0
- package/lib/browser/layout/layout.d.ts.map +1 -0
- package/lib/browser/layout/layout.js +22 -0
- package/lib/browser/layout/layout.js.map +1 -0
- package/lib/browser/locale/index.d.ts +3 -0
- package/lib/browser/locale/index.d.ts.map +1 -0
- package/lib/browser/locale/index.js +19 -0
- package/lib/browser/locale/index.js.map +1 -0
- package/lib/browser/locale/locale-context.d.ts +8 -0
- package/lib/browser/locale/locale-context.d.ts.map +1 -0
- package/lib/browser/locale/locale-context.js +38 -0
- package/lib/browser/locale/locale-context.js.map +1 -0
- package/lib/browser/locale/locale-protocol.d.ts +2 -0
- package/lib/browser/locale/locale-protocol.d.ts.map +1 -0
- package/lib/browser/locale/locale-protocol.js +5 -0
- package/lib/browser/locale/locale-protocol.js.map +1 -0
- package/lib/browser/module.d.ts +4 -0
- package/lib/browser/module.d.ts.map +1 -0
- package/lib/browser/module.js +6 -0
- package/lib/browser/module.js.map +1 -0
- package/lib/browser/resolver/index.d.ts +3 -0
- package/lib/browser/resolver/index.d.ts.map +1 -0
- package/lib/browser/resolver/index.js +19 -0
- package/lib/browser/resolver/index.js.map +1 -0
- package/lib/browser/resolver/path-resolver.d.ts +6 -0
- package/lib/browser/resolver/path-resolver.d.ts.map +1 -0
- package/lib/browser/resolver/path-resolver.js +28 -0
- package/lib/browser/resolver/path-resolver.js.map +1 -0
- package/lib/browser/resolver/resolver-protocol.d.ts +5 -0
- package/lib/browser/resolver/resolver-protocol.d.ts.map +1 -0
- package/lib/browser/resolver/resolver-protocol.js +5 -0
- package/lib/browser/resolver/resolver-protocol.js.map +1 -0
- package/lib/browser/router/index.d.ts +6 -0
- package/lib/browser/router/index.d.ts.map +1 -0
- package/lib/browser/router/index.js +22 -0
- package/lib/browser/router/index.js.map +1 -0
- package/lib/browser/router/route-metadata-converter-provider.d.ts +7 -0
- package/lib/browser/router/route-metadata-converter-provider.d.ts.map +1 -0
- package/lib/browser/router/route-metadata-converter-provider.js +35 -0
- package/lib/browser/router/route-metadata-converter-provider.js.map +1 -0
- package/lib/browser/router/route-metadata-converter.d.ts +11 -0
- package/lib/browser/router/route-metadata-converter.d.ts.map +1 -0
- package/lib/browser/router/route-metadata-converter.js +51 -0
- package/lib/browser/router/route-metadata-converter.js.map +1 -0
- package/lib/browser/router/route-metadata-provider.d.ts +10 -0
- package/lib/browser/router/route-metadata-provider.d.ts.map +1 -0
- package/lib/browser/router/route-metadata-provider.js +49 -0
- package/lib/browser/router/route-metadata-provider.js.map +1 -0
- package/lib/browser/router/router-protocol.d.ts +24 -0
- package/lib/browser/router/router-protocol.d.ts.map +1 -0
- package/lib/browser/router/router-protocol.js +9 -0
- package/lib/browser/router/router-protocol.js.map +1 -0
- package/lib/browser/router/router.d.ts +3 -0
- package/lib/browser/router/router.d.ts.map +1 -0
- package/lib/browser/router/router.js +53 -0
- package/lib/browser/router/router.js.map +1 -0
- package/lib/browser/shell/index.d.ts +2 -0
- package/lib/browser/shell/index.d.ts.map +1 -0
- package/lib/browser/shell/index.js +18 -0
- package/lib/browser/shell/index.js.map +1 -0
- package/lib/browser/shell/shell.d.ts +7 -0
- package/lib/browser/shell/shell.d.ts.map +1 -0
- package/lib/browser/shell/shell.js +31 -0
- package/lib/browser/shell/shell.js.map +1 -0
- package/lib/browser/slot/index.d.ts +2 -0
- package/lib/browser/slot/index.d.ts.map +1 -0
- package/lib/browser/slot/index.js +18 -0
- package/lib/browser/slot/index.js.map +1 -0
- package/lib/browser/slot/slot.d.ts +4 -0
- package/lib/browser/slot/slot.d.ts.map +1 -0
- package/lib/browser/slot/slot.js +20 -0
- package/lib/browser/slot/slot.js.map +1 -0
- package/lib/browser/widget/index.d.ts +2 -0
- package/lib/browser/widget/index.d.ts.map +1 -0
- package/lib/browser/widget/index.js +18 -0
- package/lib/browser/widget/index.js.map +1 -0
- package/lib/browser/widget/widget-factory.d.ts +6 -0
- package/lib/browser/widget/widget-factory.d.ts.map +1 -0
- package/lib/browser/widget/widget-factory.js +23 -0
- package/lib/browser/widget/widget-factory.js.map +1 -0
- package/lib/hooks/webpack.d.ts +4 -0
- package/lib/hooks/webpack.d.ts.map +1 -0
- package/lib/hooks/webpack.js +166 -0
- package/lib/hooks/webpack.js.map +1 -0
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +4 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +65 -0
- package/src/browser/annotation/app.ts +10 -0
- package/src/browser/annotation/context.ts +10 -0
- package/src/browser/annotation/default-layout.ts +10 -0
- package/src/browser/annotation/icon.ts +10 -0
- package/src/browser/annotation/index.ts +8 -0
- package/src/browser/annotation/react-component.ts +9 -0
- package/src/browser/annotation/route.ts +19 -0
- package/src/browser/annotation/router.ts +10 -0
- package/src/browser/annotation/view.ts +8 -0
- package/src/browser/app/app-protocol.ts +1 -0
- package/src/browser/app/app.tsx +25 -0
- package/src/browser/app/index.ts +2 -0
- package/src/browser/context/context-protocol.ts +8 -0
- package/src/browser/context/context-provider.ts +21 -0
- package/src/browser/context/context.tsx +16 -0
- package/src/browser/context/index.ts +3 -0
- package/src/browser/icon/icon-protocol.ts +9 -0
- package/src/browser/icon/icon.tsx +19 -0
- package/src/browser/icon/index.ts +1 -0
- package/src/browser/index.ts +11 -0
- package/src/browser/layout/index.ts +2 -0
- package/src/browser/layout/layout-protocol.ts +1 -0
- package/src/browser/layout/layout.tsx +10 -0
- package/src/browser/locale/index.ts +2 -0
- package/src/browser/locale/locale-context.tsx +30 -0
- package/src/browser/locale/locale-protocol.ts +1 -0
- package/src/browser/module.ts +4 -0
- package/src/browser/resolver/index.ts +2 -0
- package/src/browser/resolver/path-resolver.ts +13 -0
- package/src/browser/resolver/resolver-protocol.ts +5 -0
- package/src/browser/router/index.ts +5 -0
- package/src/browser/router/route-metadata-converter-provider.ts +19 -0
- package/src/browser/router/route-metadata-converter.ts +34 -0
- package/src/browser/router/route-metadata-provider.tsx +39 -0
- package/src/browser/router/router-protocol.ts +28 -0
- package/src/browser/router/router.tsx +44 -0
- package/src/browser/shell/index.ts +1 -0
- package/src/browser/shell/shell.tsx +16 -0
- package/src/browser/slot/index.ts +1 -0
- package/src/browser/slot/slot.tsx +18 -0
- package/src/browser/widget/index.ts +1 -0
- package/src/browser/widget/widget-factory.ts +13 -0
- package/src/hooks/webpack.ts +243 -0
- package/src/package.spec.ts +4 -0
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@celljs/react",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "lib/browser/index.js",
|
|
6
|
+
"typings": "lib/browser/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@celljs/cli-common": "3.0.0",
|
|
9
|
+
"@celljs/core": "3.0.0",
|
|
10
|
+
"@celljs/widget": "3.0.0",
|
|
11
|
+
"@types/react": "^18.0.17",
|
|
12
|
+
"@types/react-dom": "^18.0.6",
|
|
13
|
+
"@types/react-router-dom": "^5.3.3",
|
|
14
|
+
"autoprefixer": "^10.4.20",
|
|
15
|
+
"css-minimizer-webpack-plugin": "^7.0.0",
|
|
16
|
+
"cssnano": "^7.0.6",
|
|
17
|
+
"fs-extra": "^11.1.1",
|
|
18
|
+
"less": "^4.1.1",
|
|
19
|
+
"less-loader": "^9.0.0",
|
|
20
|
+
"mini-css-extract-plugin": "^2.7.6",
|
|
21
|
+
"postcss-loader": "^5.3.0",
|
|
22
|
+
"react": "^18.2.0",
|
|
23
|
+
"react-dom": "^18.2.0",
|
|
24
|
+
"react-intl": "^6.0.5",
|
|
25
|
+
"react-router-dom": "^6.3.0",
|
|
26
|
+
"sass": "^1.32.8",
|
|
27
|
+
"sass-loader": "^11.1.1",
|
|
28
|
+
"style-loader": "^3.3.1",
|
|
29
|
+
"stylus": "^0.54.8",
|
|
30
|
+
"stylus-loader": "^6.0.0"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"cell-component"
|
|
37
|
+
],
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/cellbang/cell.git"
|
|
42
|
+
},
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/cellbang/cell/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/cellbang/cell",
|
|
47
|
+
"files": [
|
|
48
|
+
"lib",
|
|
49
|
+
"src",
|
|
50
|
+
"cell.yml",
|
|
51
|
+
"cell-cdn.yml"
|
|
52
|
+
],
|
|
53
|
+
"scripts": {
|
|
54
|
+
"lint": "cell-component lint",
|
|
55
|
+
"build": "cell-component build",
|
|
56
|
+
"watch": "cell-component watch",
|
|
57
|
+
"clean": "cell-component clean",
|
|
58
|
+
"test": "cell-component test:js"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@celljs/cli-service": "3.0.0",
|
|
62
|
+
"@celljs/component": "3.0.0"
|
|
63
|
+
},
|
|
64
|
+
"gitHead": "c0ef8d269e33a795406bcbb240cac4b845c6c24c"
|
|
65
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ReactComponent } from './react-component';
|
|
3
|
+
import { APP } from '../app/app-protocol';
|
|
4
|
+
|
|
5
|
+
export const App =
|
|
6
|
+
function (component?: React.ComponentType<any>, rebind: boolean = true): ClassDecorator {
|
|
7
|
+
return (t: any) => {
|
|
8
|
+
ReactComponent(APP, component || t, rebind)(t);
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactComponent } from './react-component';
|
|
2
|
+
import { CONTEXT } from '../context/context-protocol';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
export const Context =
|
|
6
|
+
function (component?: React.ComponentType<any>, rebind: boolean = false): ClassDecorator {
|
|
7
|
+
return (t: any) => {
|
|
8
|
+
ReactComponent(CONTEXT, component || t, rebind)(t);
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactComponent } from './react-component';
|
|
2
|
+
import { DEFAULT_LAYOUT } from '../layout/layout-protocol';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
export const DefaultLayout =
|
|
6
|
+
function (component?: React.ComponentType<any>, rebind: boolean = true): ClassDecorator {
|
|
7
|
+
return (t: any) => {
|
|
8
|
+
ReactComponent(DEFAULT_LAYOUT, component || t, rebind)(t);
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactComponent } from './react-component';
|
|
2
|
+
import { ICON } from '../icon/icon-protocol';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
export const Icon =
|
|
6
|
+
function (component?: React.ComponentType<any>, rebind: boolean = false): ClassDecorator {
|
|
7
|
+
return (t: any) => {
|
|
8
|
+
ReactComponent(ICON, component || t, rebind)(t);
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Constant, ComponentId } from '@celljs/core';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
export const ReactComponent =
|
|
5
|
+
function (id?: ComponentId | ComponentId[], component?: React.ComponentType<any>, rebind: boolean = false): ClassDecorator {
|
|
6
|
+
return (t: any) => {
|
|
7
|
+
Constant(id || t, component || t, rebind)(t);
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Constant } from '@celljs/core';
|
|
2
|
+
import { RouteMetadata, ROUTE_METADATA } from '../router/router-protocol';
|
|
3
|
+
import { ReactComponent } from './react-component';
|
|
4
|
+
|
|
5
|
+
export function Route(pathOrRouteMetadata?: string | RouteMetadata, rebind: boolean = false): ClassDecorator {
|
|
6
|
+
return function (target: any) {
|
|
7
|
+
let routeMetadata: RouteMetadata;
|
|
8
|
+
if (typeof pathOrRouteMetadata === 'string') {
|
|
9
|
+
routeMetadata = { path: pathOrRouteMetadata, priority: 1000 };
|
|
10
|
+
} else {
|
|
11
|
+
routeMetadata = <RouteMetadata>{ priority: 1000, isDefaultLayout: true, ...pathOrRouteMetadata };
|
|
12
|
+
}
|
|
13
|
+
if (!routeMetadata.component) {
|
|
14
|
+
routeMetadata.component = target;
|
|
15
|
+
}
|
|
16
|
+
Constant(ROUTE_METADATA, routeMetadata, false)(target);
|
|
17
|
+
ReactComponent('@Route:' + routeMetadata.path, undefined, rebind)(target);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactComponent } from './react-component';
|
|
2
|
+
import { ROUTER } from '../router/router-protocol';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
export const Router =
|
|
6
|
+
function (component?: React.ComponentType<any>, rebind: boolean = true): ClassDecorator {
|
|
7
|
+
return (t: any) => {
|
|
8
|
+
ReactComponent(ROUTER, component || t, rebind)(t);
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RouteMetadata } from '../router/router-protocol';
|
|
2
|
+
import { Route } from './route';
|
|
3
|
+
|
|
4
|
+
export function View(pathOrRouteMetadata?: string | RouteMetadata, rebind: boolean = false): ClassDecorator {
|
|
5
|
+
return function (target: any) {
|
|
6
|
+
Route(pathOrRouteMetadata, rebind)(target);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const APP = Symbol('APP');
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ROUTER } from '../router';
|
|
3
|
+
import { Autowired } from '@celljs/core/lib/common/annotation/detached';
|
|
4
|
+
import { App } from '../annotation';
|
|
5
|
+
import { ContextProvider } from '../context';
|
|
6
|
+
|
|
7
|
+
@App(AppImpl, false)
|
|
8
|
+
export class AppImpl extends React.Component {
|
|
9
|
+
|
|
10
|
+
@Autowired(ContextProvider)
|
|
11
|
+
protected readonly contextProvider: ContextProvider;
|
|
12
|
+
|
|
13
|
+
@Autowired(ROUTER)
|
|
14
|
+
protected readonly router: React.ComponentType;
|
|
15
|
+
|
|
16
|
+
override render(): React.ReactNode {
|
|
17
|
+
return this.createContextAndRouter();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
protected createContextAndRouter() {
|
|
21
|
+
let child = React.createElement(this.router);
|
|
22
|
+
this.contextProvider.provide().forEach((context, index) => child = React.createElement(context, { key: index }, child));
|
|
23
|
+
return child;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Component, Autowired, Prioritizeable } from '@celljs/core';
|
|
2
|
+
import { ContextProvider, CONTEXT } from './context-protocol';
|
|
3
|
+
|
|
4
|
+
@Component(ContextProvider)
|
|
5
|
+
export class ContextProviderImpl implements ContextProvider {
|
|
6
|
+
|
|
7
|
+
protected prioritized: React.ComponentType[];
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
@Autowired(CONTEXT)
|
|
11
|
+
protected readonly contexts: React.ComponentType[]
|
|
12
|
+
) { }
|
|
13
|
+
|
|
14
|
+
provide(): React.ComponentType<any>[] {
|
|
15
|
+
if (!this.prioritized) {
|
|
16
|
+
this.prioritized = Prioritizeable.prioritizeAllSync(this.contexts).map(c => c.value);
|
|
17
|
+
}
|
|
18
|
+
return this.prioritized;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Context } from '../annotation';
|
|
3
|
+
|
|
4
|
+
export interface ContextProps extends React.PropsWithChildren {}
|
|
5
|
+
|
|
6
|
+
export interface ContextState {}
|
|
7
|
+
|
|
8
|
+
@Context()
|
|
9
|
+
export class NoOpContext extends React.Component<ContextProps, ContextState> {
|
|
10
|
+
|
|
11
|
+
static priority = 1000;
|
|
12
|
+
|
|
13
|
+
override render(): React.ReactElement<{}> {
|
|
14
|
+
return <>{this.props.children}</>;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ContainerUtil } from '@celljs/core';
|
|
3
|
+
import { IconResolver } from './icon-protocol';
|
|
4
|
+
|
|
5
|
+
const { useState, useEffect } = React;
|
|
6
|
+
|
|
7
|
+
export function Icon<T>(iconProps: T) {
|
|
8
|
+
const [iconNode, setIconNode] = useState<React.ReactNode>([]);
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const resolve = async () => {
|
|
12
|
+
const iconResolver = ContainerUtil.get<IconResolver<T>>(IconResolver);
|
|
13
|
+
setIconNode(await iconResolver.resolve(iconProps));
|
|
14
|
+
};
|
|
15
|
+
resolve();
|
|
16
|
+
}, [JSON.stringify(iconProps)]);
|
|
17
|
+
|
|
18
|
+
return (<>{iconNode}</>);
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './icon-protocol';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './annotation';
|
|
2
|
+
export * from './app';
|
|
3
|
+
export * from './layout';
|
|
4
|
+
export * from './context';
|
|
5
|
+
export * from './router';
|
|
6
|
+
export * from './shell';
|
|
7
|
+
export * from './resolver';
|
|
8
|
+
export * from './widget';
|
|
9
|
+
export * from './slot';
|
|
10
|
+
export * from './icon';
|
|
11
|
+
export * from './locale';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_LAYOUT = Symbol('DEFAULT_LAYOUT');
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { DefaultLayout } from '../annotation';
|
|
3
|
+
|
|
4
|
+
@DefaultLayout(EmptyLayout, false)
|
|
5
|
+
export class EmptyLayout extends React.Component<React.PropsWithChildren> {
|
|
6
|
+
|
|
7
|
+
override render() {
|
|
8
|
+
return <>{this.props.children}</>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { LOCALE_REACT_CONTEXT_PRIORITY } from './locale-protocol';
|
|
3
|
+
import { IntlProvider } from 'react-intl';
|
|
4
|
+
import { ContainerUtil, Logger } from '@celljs/core';
|
|
5
|
+
import { LocaleManager } from '@celljs/widget';
|
|
6
|
+
import { Context } from '../annotation';
|
|
7
|
+
|
|
8
|
+
export function LocaleContext({ children }: React.PropsWithChildren) {
|
|
9
|
+
const localeManager = ContainerUtil.get<LocaleManager>(LocaleManager);
|
|
10
|
+
const [locale, setLocale] = React.useState(localeManager.currentSubject.value);
|
|
11
|
+
React.useEffect(() => {
|
|
12
|
+
const subscription = localeManager.currentSubject.subscribe(l => setLocale(l));
|
|
13
|
+
return () => subscription.unsubscribe();
|
|
14
|
+
}, []);
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<IntlProvider locale={locale?.lang || navigator.language} messages={locale?.messages} onError={err => {
|
|
18
|
+
const logger = ContainerUtil.get<Logger>(Logger);
|
|
19
|
+
if (err.code !== 'MISSING_TRANSLATION') {
|
|
20
|
+
logger.warn(err);
|
|
21
|
+
}
|
|
22
|
+
}}>
|
|
23
|
+
{children}
|
|
24
|
+
</IntlProvider>);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
LocaleContext.priority = LOCALE_REACT_CONTEXT_PRIORITY;
|
|
28
|
+
|
|
29
|
+
@Context(LocaleContext)
|
|
30
|
+
export default class {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const LOCALE_REACT_CONTEXT_PRIORITY = 3000;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PathResolver } from './resolver-protocol';
|
|
2
|
+
import { Value, Component, UrlUtil } from '@celljs/core';
|
|
3
|
+
|
|
4
|
+
@Component(PathResolver)
|
|
5
|
+
export class PathResolverImpl implements PathResolver {
|
|
6
|
+
|
|
7
|
+
@Value('cell.react.path')
|
|
8
|
+
protected readonly path: string;
|
|
9
|
+
|
|
10
|
+
resolve(...parts: string[]): string {
|
|
11
|
+
return UrlUtil.join(this.path, ...parts.filter(v => !!v));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Component, Autowired, Prioritizeable, Optional } from '@celljs/core';
|
|
2
|
+
import { RouteMetadataConverterProvider, RouteMetadataConverter } from './router-protocol';
|
|
3
|
+
|
|
4
|
+
@Component(RouteMetadataConverterProvider)
|
|
5
|
+
export class RouteMetadataConverterProviderImpl implements RouteMetadataConverterProvider {
|
|
6
|
+
|
|
7
|
+
protected prioritized: RouteMetadataConverter[];
|
|
8
|
+
|
|
9
|
+
@Autowired(RouteMetadataConverter) @Optional()
|
|
10
|
+
protected readonly routeMetadataConverters: RouteMetadataConverter[] = [];
|
|
11
|
+
|
|
12
|
+
provide(): RouteMetadataConverter[] {
|
|
13
|
+
if (!this.prioritized) {
|
|
14
|
+
this.prioritized = Prioritizeable.prioritizeAllSync(this.routeMetadataConverters).map(c => c.value);
|
|
15
|
+
}
|
|
16
|
+
return this.prioritized;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Autowired, Component, Value } from '@celljs/core';
|
|
2
|
+
import { DEFAULT_LAYOUT } from '../layout';
|
|
3
|
+
import { PathResolver } from '../resolver';
|
|
4
|
+
import { RouteMetadata, RouteMetadataConverter } from './router-protocol';
|
|
5
|
+
|
|
6
|
+
@Component(RouteMetadataConverter)
|
|
7
|
+
export class DefaultRouteMetadataConverter implements RouteMetadataConverter {
|
|
8
|
+
readonly priority: number = 500;
|
|
9
|
+
|
|
10
|
+
@Autowired(PathResolver)
|
|
11
|
+
protected readonly pathResolver: PathResolver;
|
|
12
|
+
|
|
13
|
+
@Autowired(DEFAULT_LAYOUT)
|
|
14
|
+
protected readonly defaultLayout: React.ComponentType;
|
|
15
|
+
|
|
16
|
+
@Value('cell.react.router.routes')
|
|
17
|
+
protected readonly routes: any;
|
|
18
|
+
|
|
19
|
+
convert(metadata: RouteMetadata): RouteMetadata {
|
|
20
|
+
if (metadata.path) {
|
|
21
|
+
metadata.path = this.pathResolver.resolve(metadata.path);
|
|
22
|
+
}
|
|
23
|
+
metadata.layout = metadata.layout || this.defaultLayout;
|
|
24
|
+
return metadata;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
protected getMergedConfig(routeMetadata: RouteMetadata): RouteMetadata {
|
|
28
|
+
if (!this.routes || !routeMetadata.path) {
|
|
29
|
+
return routeMetadata;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return { ...routeMetadata, ...this.routes[routeMetadata.path] };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Component, Autowired, Prioritizeable } from '@celljs/core';
|
|
2
|
+
import { RouteMetadataProvider, RouteMetadata, RouteMetadataConverterProvider, ROUTE_METADATA } from './router-protocol';
|
|
3
|
+
|
|
4
|
+
@Component(RouteMetadataProvider)
|
|
5
|
+
export class RouteMetadataProviderImpl implements RouteMetadataProvider {
|
|
6
|
+
|
|
7
|
+
protected prioritized: RouteMetadata[];
|
|
8
|
+
|
|
9
|
+
@Autowired(ROUTE_METADATA)
|
|
10
|
+
protected readonly routeMetadatas: RouteMetadata[];
|
|
11
|
+
|
|
12
|
+
@Autowired(RouteMetadataConverterProvider)
|
|
13
|
+
protected readonly routeMetadataConverterProvider: RouteMetadataConverterProvider;
|
|
14
|
+
|
|
15
|
+
provide(): RouteMetadata[] {
|
|
16
|
+
if (!this.prioritized) {
|
|
17
|
+
this.prioritized = this.parseRouteMetadatas();
|
|
18
|
+
}
|
|
19
|
+
return this.prioritized;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected parseRouteMetadatas(): RouteMetadata[] {
|
|
23
|
+
const list: RouteMetadata[] = [];
|
|
24
|
+
for (const routeMetadata of this.routeMetadatas) {
|
|
25
|
+
let parsed = routeMetadata;
|
|
26
|
+
for (const converter of this.routeMetadataConverterProvider.provide()) {
|
|
27
|
+
parsed = converter.convert(parsed);
|
|
28
|
+
}
|
|
29
|
+
list.push(parsed);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return this.sort(list);
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
protected sort(list: RouteMetadata[]) {
|
|
37
|
+
return Prioritizeable.prioritizeAllSync(list).map(c => c.value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const ROUTER = Symbol('Router');
|
|
2
|
+
export const ROUTE_METADATA = Symbol('ROUTE_METADATA');
|
|
3
|
+
|
|
4
|
+
export const RouteMetadataProvider = Symbol('RouteMetadataProvider');
|
|
5
|
+
export const RouteMetadataConverter = Symbol('RouteMetadataConverter');
|
|
6
|
+
export const RouteMetadataConverterProvider = Symbol('RouteMetadataConverterProvider');
|
|
7
|
+
|
|
8
|
+
export interface RouteMetadata {
|
|
9
|
+
caseSensitive?: boolean;
|
|
10
|
+
index?: boolean;
|
|
11
|
+
path?: string;
|
|
12
|
+
component?: React.ComponentType;
|
|
13
|
+
layout?: React.ComponentType;
|
|
14
|
+
priority?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface RouteMetadataConverter {
|
|
18
|
+
readonly priority: number;
|
|
19
|
+
convert(metadata: RouteMetadata): RouteMetadata;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface RouteMetadataConverterProvider {
|
|
23
|
+
provide(): RouteMetadataConverter[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface RouteMetadataProvider {
|
|
27
|
+
provide(): RouteMetadata[];
|
|
28
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { RouteMetadataProvider } from './router-protocol';
|
|
3
|
+
import { useRoutes, BrowserRouter, HashRouter, RouteObject } from 'react-router-dom';
|
|
4
|
+
import { Router } from '../annotation';
|
|
5
|
+
import { ConfigUtil, ContainerUtil } from '@celljs/core';
|
|
6
|
+
|
|
7
|
+
const routerMap = {
|
|
8
|
+
browser: BrowserRouter,
|
|
9
|
+
hash: HashRouter
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const RouteComponent = () => {
|
|
13
|
+
const element = useRoutes(buildRoutes());
|
|
14
|
+
return element;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const RouterComponent = () => {
|
|
18
|
+
const routerType = ConfigUtil.get<'browser' | 'hash'>('cell.react.router.type');
|
|
19
|
+
return React.createElement(routerMap[routerType], {}, React.createElement(RouteComponent));
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const buildRoutes = (): RouteObject[] => {
|
|
23
|
+
const routeMetadataProvider = ContainerUtil.get<RouteMetadataProvider>(RouteMetadataProvider);
|
|
24
|
+
return routeMetadataProvider.provide().map(metadata => {
|
|
25
|
+
// eslint-disable-next-line no-null/no-null
|
|
26
|
+
let element: React.ReactNode | null;
|
|
27
|
+
if (metadata.component) {
|
|
28
|
+
if (metadata.layout) {
|
|
29
|
+
element = React.createElement(metadata.layout, {}, React.createElement(metadata.component));
|
|
30
|
+
} else {
|
|
31
|
+
element = React.createElement(metadata.component);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
path: metadata.path,
|
|
36
|
+
index: metadata.index,
|
|
37
|
+
caseSensitive: metadata.caseSensitive,
|
|
38
|
+
element
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
@Router(RouterComponent, false)
|
|
44
|
+
export default class {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './shell';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ApplicationShell } from '@celljs/core/lib/browser';
|
|
2
|
+
import { Component, Autowired } from '@celljs/core';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { APP } from '../app';
|
|
6
|
+
|
|
7
|
+
@Component({ id: ApplicationShell, rebind: true })
|
|
8
|
+
export class Shell implements ApplicationShell {
|
|
9
|
+
|
|
10
|
+
@Autowired(APP)
|
|
11
|
+
protected readonly app: React.ComponentType;
|
|
12
|
+
|
|
13
|
+
attach(host: HTMLElement): void {
|
|
14
|
+
createRoot(host).render(React.createElement(this.app));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './slot';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ContainerUtil } from '@celljs/core';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { WidgetManager } from '@celljs/widget';
|
|
4
|
+
const { useState, useEffect } = React;
|
|
5
|
+
|
|
6
|
+
export function Slot({ area }: { area: string }) {
|
|
7
|
+
const [nodes, setNodes] = useState<React.ReactNode[]>([]);
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const load = async () => {
|
|
11
|
+
const widgetManager = ContainerUtil.get<WidgetManager<React.ReactNode>>(WidgetManager);
|
|
12
|
+
setNodes(await widgetManager.render(area));
|
|
13
|
+
};
|
|
14
|
+
load();
|
|
15
|
+
}, [area]);
|
|
16
|
+
|
|
17
|
+
return (<>{nodes.map(n => n)}</>);
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './widget-factory';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Component } from '@celljs/core';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { AbstractWidgetFactory, WidgetFactory, WidgetModel } from '@celljs/widget';
|
|
4
|
+
|
|
5
|
+
@Component(WidgetFactory)
|
|
6
|
+
export class DecoratorWidgetFactory extends AbstractWidgetFactory<React.ReactNode> {
|
|
7
|
+
|
|
8
|
+
protected async doRender(widgetModel: WidgetModel): Promise<React.ReactNode> {
|
|
9
|
+
const component = widgetModel.matedata!.component;
|
|
10
|
+
return React.createElement(component, { key: widgetModel.id, ...widgetModel.props });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
}
|