fix
This commit is contained in:
parent
69753fe0e0
commit
72bcba5bb5
|
|
@ -53,6 +53,7 @@ export const Field: FC<FieldProp> = (arg) => {
|
|||
child={arg.child}
|
||||
_meta={arg._meta}
|
||||
_item={arg._item}
|
||||
_sync={arg._sync}
|
||||
/>
|
||||
{field.desc && (
|
||||
<div className={cx("c-p-2 c-text-xs", errors.length > 0 && "c-pb-1")}>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ import { FC, useEffect } from "react";
|
|||
import { FMLocal, FieldLocal } from "../typings";
|
||||
import { fieldMapping } from "./mapping";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { genFieldMitem } from "../utils/gen-mitem";
|
||||
import { genFieldMitem, updateFieldMItem } from "../utils/gen-mitem";
|
||||
import { createItem } from "@/gen/utils";
|
||||
|
||||
const modify = {
|
||||
timeout: null as any,
|
||||
|
|
@ -17,6 +18,7 @@ export const FieldInput: FC<{
|
|||
child: any;
|
||||
_item: any;
|
||||
_meta: any;
|
||||
_sync: (mitem: any, item: any) => void;
|
||||
}> = ({ field, fm, PassProp, child, _meta, _item }) => {
|
||||
const prefix = typeof field.prefix === "function" ? field.prefix() : null;
|
||||
const suffix = typeof field.suffix === "function" ? field.suffix() : null;
|
||||
|
|
@ -31,6 +33,25 @@ export const FieldInput: FC<{
|
|||
for (const child of childs) {
|
||||
if (child.component?.id === fieldMapping[field.type].id) {
|
||||
found = child;
|
||||
|
||||
const item = createItem({
|
||||
component: { id: "--", props: fieldMapping[field.type].props },
|
||||
});
|
||||
|
||||
const props = found.component.props;
|
||||
let should_update = false;
|
||||
for (const [k, v] of Object.entries(item.component.props) as any) {
|
||||
if (props[k] && props[k].valueBuilt === v.valueBuilt) {
|
||||
continue;
|
||||
} else {
|
||||
props[k] = v;
|
||||
should_update = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (should_update) {
|
||||
updateFieldMItem(_meta, found);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,12 @@
|
|||
import { FieldProp } from "../typings";
|
||||
|
||||
export const fieldMapping: Record<FieldProp["type"], { id: string }> = {
|
||||
text: { id: "ca7ac237-8f22-4492-bb9d-4b715b1f5c25" },
|
||||
export const fieldMapping: Record<
|
||||
FieldProp["type"],
|
||||
{ id: string; props: any }
|
||||
> = {
|
||||
text: { id: "ca7ac237-8f22-4492-bb9d-4b715b1f5c25", props: { type: "text" } },
|
||||
number: {
|
||||
id: "ca7ac237-8f22-4492-bb9d-4b715b1f5c25",
|
||||
props: { type: "number" },
|
||||
},
|
||||
} as any;
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ export type FieldProp = {
|
|||
width: "auto" | "full" | "½" | "⅓" | "¼";
|
||||
_meta: any;
|
||||
_item: any;
|
||||
_sync: any;
|
||||
};
|
||||
|
||||
export type FMInternal = {
|
||||
|
|
|
|||
|
|
@ -22,3 +22,12 @@ export const genFieldMitem = (arg: {
|
|||
}
|
||||
}
|
||||
};
|
||||
export const updateFieldMItem = (_meta: any, _item: any) => {
|
||||
const m = _meta[_item.id];
|
||||
if (m) {
|
||||
const mitem = m.mitem;
|
||||
if (mitem) {
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -40,7 +40,9 @@ export const newField = (arg: GFCol) => {
|
|||
createItem({
|
||||
component: {
|
||||
id: "ca7ac237-8f22-4492-bb9d-4b715b1f5c25",
|
||||
props: {},
|
||||
props: {
|
||||
type: "text",
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
|
|
|
|||
23
gen/utils.ts
23
gen/utils.ts
|
|
@ -92,16 +92,19 @@ export const createItem = (arg: SimplifiedItem): any => {
|
|||
valueBuilt: v[1],
|
||||
};
|
||||
} else {
|
||||
let newItem = createItem(v);
|
||||
|
||||
component.props[k] = {
|
||||
meta: {
|
||||
type: "content-element",
|
||||
},
|
||||
content: newItem,
|
||||
value: "",
|
||||
valueBuilt: "",
|
||||
};
|
||||
if ((v as any)?.meta?.type) {
|
||||
component.props[k] = v;
|
||||
} else {
|
||||
let newItem = createItem(v);
|
||||
component.props[k] = {
|
||||
meta: {
|
||||
type: "content-element",
|
||||
},
|
||||
content: newItem,
|
||||
value: "",
|
||||
valueBuilt: "",
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
component.props[k] = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue