mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 17:48:13 +00:00
fix: upgradePropsReducer
This commit is contained in:
parent
c287bad37b
commit
e68977f7e5
@ -49,38 +49,38 @@ function isVariable(obj: any): obj is Variable {
|
||||
}
|
||||
|
||||
function upgradePropsReducer(props: any) {
|
||||
if (!isPlainObject(props)) {
|
||||
if (!props || !isPlainObject(props)) {
|
||||
return props;
|
||||
}
|
||||
if (isJSBlock(props)) {
|
||||
if (props.value.componentName === 'Slot') {
|
||||
return {
|
||||
type: 'JSSlot',
|
||||
title: (props.value.props as any)?.slotTitle,
|
||||
name: (props.value.props as any)?.slotName,
|
||||
value: props.value.children,
|
||||
};
|
||||
} else {
|
||||
return props.value;
|
||||
}
|
||||
}
|
||||
if (isVariable(props)) {
|
||||
return {
|
||||
type: 'JSExpression',
|
||||
value: props.variable,
|
||||
mock: props.value,
|
||||
};
|
||||
}
|
||||
const newProps: any = {};
|
||||
Object.entries<any>(props).forEach(([key, val]) => {
|
||||
if (/^__slot__/.test(key) && val === true) {
|
||||
Object.keys(props).forEach(key => {
|
||||
if (/^__slot__/.test(key) && props[key] === true) {
|
||||
return;
|
||||
}
|
||||
if (isJSBlock(val)) {
|
||||
if (val.value.componentName === 'Slot') {
|
||||
val = {
|
||||
type: 'JSSlot',
|
||||
title: (val.value.props as any)?.slotTitle,
|
||||
name: (val.value.props as any)?.slotName,
|
||||
value: val.value.children,
|
||||
};
|
||||
} else {
|
||||
val = val.value;
|
||||
}
|
||||
}
|
||||
// todo: deep find
|
||||
if (isVariable(val)) {
|
||||
val = {
|
||||
type: 'JSExpression',
|
||||
value: val.variable,
|
||||
mock: val.value,
|
||||
};
|
||||
}
|
||||
newProps[key] = val;
|
||||
newProps[key] = upgradePropsReducer(props[key]);
|
||||
});
|
||||
return newProps;
|
||||
}
|
||||
|
||||
// 升级 Props
|
||||
designer.addPropsReducer(upgradePropsReducer, TransformStage.Upgrade);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user