mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-15 10:48:17 +00:00
fix: children 在 schema 和 props 中并存的情况处理
This commit is contained in:
parent
180da7ce1c
commit
7b639eb316
@ -1,6 +1,9 @@
|
|||||||
# 出码模块
|
# 出码模块
|
||||||
|
|
||||||
详细介绍看这里:<https://yuque.antfin-inc.com/docs/share/2b342641-6e01-4c77-b8e0-30421f55f69b>
|
**重要!!! 本模块是 Node 端运行的!本模块是 Node 端运行的!本模块是 Node 端运行的!暂不支持 Web 端直接跑。**
|
||||||
|
如果有业务诉求需要在 Web 端运行,可以联系 @春希(armslave.yy),会在架构组讨论优先度。
|
||||||
|
|
||||||
|
详细介绍看这里:[出码模块 语雀文档](https://yuque.antfin.com/docs/share/2b342641-6e01-4c77-b8e0-30421f55f69b)
|
||||||
|
|
||||||
## 安装接入
|
## 安装接入
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
* 本解析器面向的是标准 schema 协议。
|
* 本解析器面向的是标准 schema 协议。
|
||||||
*/
|
*/
|
||||||
import changeCase from 'change-case';
|
import changeCase from 'change-case';
|
||||||
import { UtilItem, NodeDataType, NodeSchema, ContainerSchema, ProjectSchema, PropsMap } from '@ali/lowcode-types';
|
import { UtilItem, NodeDataType, NodeSchema, ContainerSchema, ProjectSchema, PropsMap, NodeData } from '@ali/lowcode-types';
|
||||||
import { IPageMeta,
|
import { IPageMeta,
|
||||||
CodeGeneratorError,
|
CodeGeneratorError,
|
||||||
CompatibilityError,
|
CompatibilityError,
|
||||||
@ -46,6 +46,38 @@ function getRootComponentName(typeName: string, maps: Record<string, IExternalDe
|
|||||||
return typeName;
|
return typeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processChildren(schema: NodeSchema): void {
|
||||||
|
if (schema.props) {
|
||||||
|
if (Array.isArray(schema.props)) {
|
||||||
|
// FIXME: is array type props description
|
||||||
|
} else {
|
||||||
|
const nodeProps = schema.props as PropsMap;
|
||||||
|
if (nodeProps.children) {
|
||||||
|
if (!schema.children) {
|
||||||
|
schema.children = nodeProps.children as NodeDataType;
|
||||||
|
} else {
|
||||||
|
let _children: NodeData[] = [];
|
||||||
|
|
||||||
|
if (Array.isArray(schema.children)) {
|
||||||
|
_children = _children.concat(schema.children);
|
||||||
|
} else {
|
||||||
|
_children.push(schema.children);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(nodeProps.children)) {
|
||||||
|
_children = _children.concat(nodeProps.children as NodeData[]);
|
||||||
|
} else {
|
||||||
|
_children.push(nodeProps.children as NodeData);
|
||||||
|
}
|
||||||
|
|
||||||
|
schema.children = _children;
|
||||||
|
}
|
||||||
|
delete nodeProps.children;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SchemaParser implements ISchemaParser {
|
class SchemaParser implements ISchemaParser {
|
||||||
validate(schema: ProjectSchema): boolean {
|
validate(schema: ProjectSchema): boolean {
|
||||||
if (SUPPORT_SCHEMA_VERSION_LIST.indexOf(schema.version) < 0) {
|
if (SUPPORT_SCHEMA_VERSION_LIST.indexOf(schema.version) < 0) {
|
||||||
@ -146,22 +178,10 @@ class SchemaParser implements ISchemaParser {
|
|||||||
// 处理 children 写在了 props 里的情况
|
// 处理 children 写在了 props 里的情况
|
||||||
containers.forEach((container) => {
|
containers.forEach((container) => {
|
||||||
if (container.children) {
|
if (container.children) {
|
||||||
handleSubNodes<string>(
|
handleSubNodes<void>(
|
||||||
container.children,
|
container.children,
|
||||||
{
|
{
|
||||||
node: (i: NodeSchema) => {
|
node: (i: NodeSchema) => processChildren(i),
|
||||||
if (i.props) {
|
|
||||||
if (Array.isArray(i.props)) {
|
|
||||||
// FIXME: is array type props description
|
|
||||||
} else {
|
|
||||||
const nodeProps = i.props as PropsMap;
|
|
||||||
if (nodeProps.children && !i.children) {
|
|
||||||
i.children = nodeProps.children as NodeDataType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
rerun: true,
|
rerun: true,
|
||||||
|
|||||||
@ -53,5 +53,5 @@
|
|||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"registry": "http://registry.npm.alibaba-inc.com"
|
"registry": "http://registry.npm.alibaba-inc.com"
|
||||||
},
|
},
|
||||||
"homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@1.0.11/build/index.html"
|
"homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@1.0.12/build/index.html"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user