Skip to content

Commit f1711e0

Browse files
committed
fix: 调整一些类型声明
1 parent 42a53b5 commit f1711e0

File tree

5 files changed

+40
-37
lines changed

5 files changed

+40
-37
lines changed

packages/react-renderer/src/components/app.tsx

+13-25
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,14 @@
1-
import { isLowCodeComponentSchema } from '@alilc/lowcode-shared';
21
import { useRenderContext } from '../context/render';
3-
import { createComponentBySchema, ReactComponent } from '../runtime';
2+
import { getComponentByName } from '../runtime';
43
import Route from './route';
54
import { rendererExtends } from '../plugin';
65

76
export default function App() {
8-
const { schema, packageManager } = useRenderContext();
7+
const renderContext = useRenderContext();
8+
const { schema } = renderContext;
99
const appWrappers = rendererExtends.getAppWrappers();
1010
const wrappers = rendererExtends.getRouteWrappers();
1111

12-
function getLayoutComponent() {
13-
const config = schema.get('config');
14-
const componentName = config?.layout?.componentName as string;
15-
16-
if (componentName) {
17-
const Component = packageManager.getComponent<ReactComponent>(componentName);
18-
19-
if (isLowCodeComponentSchema(Component)) {
20-
return createComponentBySchema(Component.schema, {
21-
displayName: componentName,
22-
});
23-
}
24-
25-
return Component;
26-
}
27-
}
28-
29-
const Layout = getLayoutComponent();
30-
3112
let element = <Route />;
3213

3314
if (wrappers.length > 0) {
@@ -36,9 +17,16 @@ export default function App() {
3617
}, element);
3718
}
3819

39-
if (Layout) {
40-
const layoutProps: any = schema.get('config')?.layout?.props ?? {};
41-
element = <Layout {...layoutProps}>{element}</Layout>;
20+
const layoutConfig = schema.get('config')?.layout;
21+
22+
if (layoutConfig) {
23+
const componentName = layoutConfig.componentName as string;
24+
const Layout = getComponentByName(componentName, renderContext);
25+
26+
if (Layout) {
27+
const layoutProps: any = layoutConfig.props ?? {};
28+
element = <Layout {...layoutProps}>{element}</Layout>;
29+
}
4230
}
4331

4432
if (appWrappers.length > 0) {

packages/react-renderer/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export { defineRendererPlugin } from './plugin';
44
export * from './context/render';
55
export * from './context/router';
66

7+
export type { Spec, ProCodeComponent, LowCodeComponent } from '@alilc/lowcode-shared';
78
export type { PackageLoader, CodeScope, Plugin } from '@alilc/lowcode-renderer-core';
89
export type { RendererExtends } from './plugin';

packages/react-renderer/src/runtime/index.tsx

+21-2
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,34 @@ export interface LowCodeComponentProps {
5353

5454
const lowCodeComponentsCache = new Map<string, ReactComponent>();
5555

56-
function getComponentByName(name: string, { packageManager }: RenderContext): ReactComponent {
56+
export function getComponentByName(
57+
name: string,
58+
{ packageManager, boostsManager }: RenderContext,
59+
): ReactComponent {
5760
const componentsRecord = packageManager.getComponentsNameRecord<ReactComponent>();
5861
// read cache first
5962
const result = lowCodeComponentsCache.get(name) || componentsRecord[name];
6063

6164
invariant(result, `${name} component not found in componentsRecord`);
6265

6366
if (isLowCodeComponentSchema(result)) {
64-
const lowCodeComponent = createComponentBySchema(result.schema, {
67+
const { componentsMap, componentsTree, utils, i18n } = result.schema;
68+
69+
if (componentsMap.length > 0) {
70+
packageManager.resolveComponentMaps(componentsMap);
71+
}
72+
73+
const boosts = boostsManager.toExpose();
74+
75+
utils?.forEach((util) => boosts.util.add(util));
76+
77+
if (i18n) {
78+
Object.keys(i18n).forEach((locale) => {
79+
boosts.intl.addTranslations(locale, i18n[locale]);
80+
});
81+
}
82+
83+
const lowCodeComponent = createComponentBySchema(componentsTree[0], {
6584
displayName: name,
6685
});
6786

packages/shared/src/types/material.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Package } from './specs/asset-spec';
2-
import { ComponentTree } from './specs/lowcode-spec';
2+
import { Project } from './specs/lowcode-spec';
33

44
export interface ProCodeComponent extends Package {
55
package: string;
66
type: 'proCode';
77
}
88

9-
export interface LowCodeComponent extends Omit<Package, 'schema'> {
9+
export interface LowCodeComponent extends Package {
1010
id: string;
1111
type: 'lowCode';
1212
componentName: string;
13-
schema: ComponentTree;
13+
schema: Project;
1414
}

packages/shared/src/types/specs/asset-spec.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ export interface Package {
2828
/**
2929
* 组件多个渲染态视图打包后的 CDN url 列表,包含 js 和 css,优先级高于 urls
3030
*/
31-
advancedUrls?: ComplexUrls;
31+
advancedUrls?: MultiModeUrls;
3232
/**
3333
* 组件编辑态视图打包后的 CDN url 列表,包含 js 和 css
3434
*/
3535
editUrls?: string[];
3636
/**
3737
* 组件多个编辑态视图打包后的 CDN url 列表,包含 js 和 css,优先级高于 editUrls
3838
*/
39-
advancedEditUrls?: ComplexUrls;
39+
advancedEditUrls?: MultiModeUrls;
4040
/**
4141
* 低代码组件的 schema 内容
4242
*/
@@ -79,11 +79,6 @@ export interface Package {
7979
exportSourceLibrary?: string;
8080
}
8181

82-
/**
83-
* 复杂 urls 结构,同时兼容简单结构和多模态结构
84-
*/
85-
export type ComplexUrls = string[] | MultiModeUrls;
86-
8782
/**
8883
* 多模态资源
8984
*/

0 commit comments

Comments
 (0)