mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-15 10:48:17 +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) {
|
function upgradePropsReducer(props: any) {
|
||||||
if (!isPlainObject(props)) {
|
if (!props || !isPlainObject(props)) {
|
||||||
return 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 = {};
|
const newProps: any = {};
|
||||||
Object.entries<any>(props).forEach(([key, val]) => {
|
Object.keys(props).forEach(key => {
|
||||||
if (/^__slot__/.test(key) && val === true) {
|
if (/^__slot__/.test(key) && props[key] === true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isJSBlock(val)) {
|
newProps[key] = upgradePropsReducer(props[key]);
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
return newProps;
|
return newProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 升级 Props
|
// 升级 Props
|
||||||
designer.addPropsReducer(upgradePropsReducer, TransformStage.Upgrade);
|
designer.addPropsReducer(upgradePropsReducer, TransformStage.Upgrade);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user