fix gen-form
This commit is contained in:
parent
b2b34659c6
commit
f44456cbdf
|
|
@ -147,71 +147,68 @@ export const generateForm = async (
|
||||||
walkGenForm(new_body, existing_childs as any);
|
walkGenForm(new_body, existing_childs as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.edit) {
|
const prop_item = propFromItem(item);
|
||||||
const current_body = propFromItem(item)?.body?.value as IItem;
|
const current_body = prop_item?.body?.value as IItem;
|
||||||
|
|
||||||
if (current_body) {
|
if (current_body) {
|
||||||
const mapping = mapCompItemTree(new_body, {
|
const mapping = mapCompItemTree(new_body, {
|
||||||
shouldAdd({ item }) {
|
shouldAdd({ item }) {
|
||||||
if (item.component?.props?.sub_type?.value === "table-edit")
|
if (item.component?.props?.sub_type?.value === "table-edit")
|
||||||
return "add-skip-children";
|
return "add-skip-children";
|
||||||
|
|
||||||
return "add";
|
return "add";
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
reduceItemMapping(current_body, mapping, (old_item, new_item) => {
|
reduceItemMapping(current_body, mapping, (old_item, new_item) => {
|
||||||
const pold = propFromItem(old_item);
|
const pold = propFromItem(old_item);
|
||||||
const pnew = propFromItem(new_item);
|
const pnew = propFromItem(new_item);
|
||||||
|
|
||||||
let result = old_item;
|
|
||||||
if (
|
|
||||||
result.component &&
|
|
||||||
result.component?.id === "32550d01-42a3-4b15-a04a-2c2d5c3c8e67"
|
|
||||||
) {
|
|
||||||
if (pold.type.value !== pnew.type.value) {
|
|
||||||
result = new_item;
|
|
||||||
} else if (pold.sub_type.value !== pnew.sub_type.value) {
|
|
||||||
result = new_item;
|
|
||||||
}
|
|
||||||
|
|
||||||
copyProps(old_item, new_item, [
|
|
||||||
"placeholder",
|
|
||||||
"label",
|
|
||||||
"link__url",
|
|
||||||
"ext__width",
|
|
||||||
"opt__load_trigger",
|
|
||||||
"ext__on_change",
|
|
||||||
"ext__description",
|
|
||||||
"ext__show_label",
|
|
||||||
"ext__disabled",
|
|
||||||
"ext__prefix",
|
|
||||||
"ext__suffix",
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
let result = old_item;
|
||||||
if (
|
if (
|
||||||
mapping["32550d01-42a3-4b15-a04a-2c2d5c3c8e67"] &&
|
result.component &&
|
||||||
Object.keys(mapping["32550d01-42a3-4b15-a04a-2c2d5c3c8e67"]).length >
|
result.component?.id === "32550d01-42a3-4b15-a04a-2c2d5c3c8e67"
|
||||||
0
|
|
||||||
) {
|
) {
|
||||||
for (const val of Object.values(
|
if (pold.type.value !== pnew.type.value) {
|
||||||
mapping["32550d01-42a3-4b15-a04a-2c2d5c3c8e67"]
|
result = new_item;
|
||||||
)) {
|
} else if (pold.sub_type.value !== pnew.sub_type.value) {
|
||||||
current_body.childs?.[0]?.childs.push(val);
|
result = new_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copyProps(old_item, new_item, [
|
||||||
|
"placeholder",
|
||||||
|
"label",
|
||||||
|
"link__url",
|
||||||
|
"ext__width",
|
||||||
|
"opt__load_trigger",
|
||||||
|
"ext__on_change",
|
||||||
|
"ext__description",
|
||||||
|
"ext__show_label",
|
||||||
|
"ext__disabled",
|
||||||
|
"ext__prefix",
|
||||||
|
"ext__suffix",
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_body?.childs?.length > 0) {
|
return result;
|
||||||
new_body = current_body;
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
mapping["32550d01-42a3-4b15-a04a-2c2d5c3c8e67"] &&
|
||||||
|
Object.keys(mapping["32550d01-42a3-4b15-a04a-2c2d5c3c8e67"]).length > 0
|
||||||
|
) {
|
||||||
|
for (const val of Object.values(
|
||||||
|
mapping["32550d01-42a3-4b15-a04a-2c2d5c3c8e67"]
|
||||||
|
)) {
|
||||||
|
current_body.childs?.[0]?.childs.push(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (current_body?.childs?.length > 0) {
|
||||||
|
new_body = current_body;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(result);
|
|
||||||
if (commit) {
|
if (commit) {
|
||||||
Object.keys(result).map((e) => {
|
Object.keys(result).map((e) => {
|
||||||
item.edit.setProp(e, result[e]);
|
item.edit.setProp(e, result[e]);
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ export const generateMDForm = async (
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const newitem: any = {
|
const raw_new_item: any = {
|
||||||
type: "item",
|
type: "item",
|
||||||
name: "item",
|
name: "item",
|
||||||
component: {
|
component: {
|
||||||
|
|
@ -53,7 +53,28 @@ export const generateMDForm = async (
|
||||||
props,
|
props,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
generateForm(async (props: any) => {}, props, newitem, false, true);
|
|
||||||
|
let cur_item = (
|
||||||
|
item.edit.childs
|
||||||
|
.find((e) => e.name.includes("child"))
|
||||||
|
?.edit?.childs?.find((e) => e.name === "tab")?.component?.props as any
|
||||||
|
)?.child?.content?.childs?.[0];
|
||||||
|
|
||||||
|
if (cur_item) {
|
||||||
|
const new_item = createItem(raw_new_item) as IItem;
|
||||||
|
for (const [k, v] of Object.entries(new_item.component?.props || {})) {
|
||||||
|
if (cur_item.component) {
|
||||||
|
const prop = v as any;
|
||||||
|
if (prop.meta.type !== "content-element") {
|
||||||
|
cur_item.component.props[k] = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cur_item = raw_new_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
generateForm(async (props: any) => {}, props, cur_item, false, true);
|
||||||
|
|
||||||
tab_detail?.edit.setProp("breadcrumb", {
|
tab_detail?.edit.setProp("breadcrumb", {
|
||||||
mode: "raw",
|
mode: "raw",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue