mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 17:48:13 +00:00
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import {
|
|
BuilderComponentPlugin,
|
|
BuilderComponentPluginFactory,
|
|
ChunkType,
|
|
FileType,
|
|
ICodeStruct,
|
|
IContainerInfo,
|
|
} from '../../../types';
|
|
|
|
import { REACT_CHUNK_NAME } from './const';
|
|
|
|
import { createReactNodeGenerator } from '../../../utils/nodeToJSX';
|
|
|
|
type PluginConfig = {
|
|
fileType?: string;
|
|
nodeTypeMapping?: Record<string, string>;
|
|
}
|
|
|
|
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
|
|
const cfg = {
|
|
fileType: FileType.JSX,
|
|
nodeTypeMapping: {},
|
|
...config,
|
|
};
|
|
|
|
const generator = createReactNodeGenerator({ nodeTypeMapping: cfg.nodeTypeMapping });
|
|
|
|
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
|
|
const next: ICodeStruct = {
|
|
...pre,
|
|
};
|
|
|
|
const ir = next.ir as IContainerInfo;
|
|
const jsxContent = generator(ir);
|
|
|
|
next.chunks.push({
|
|
type: ChunkType.STRING,
|
|
fileType: cfg.fileType,
|
|
name: REACT_CHUNK_NAME.ClassRenderJSX,
|
|
content: `return ${jsxContent};`,
|
|
linkAfter: [
|
|
REACT_CHUNK_NAME.ClassRenderStart,
|
|
REACT_CHUNK_NAME.ClassRenderPre,
|
|
],
|
|
});
|
|
|
|
return next;
|
|
};
|
|
return plugin;
|
|
};
|
|
|
|
export default pluginFactory;
|