This commit is contained in:
rizky 2024-04-12 19:33:11 -07:00
parent 69753fe0e0
commit 72bcba5bb5
7 changed files with 58 additions and 14 deletions

View File

@ -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")}>

View File

@ -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);
}
}
}
}

View File

@ -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;

View File

@ -53,6 +53,7 @@ export type FieldProp = {
width: "auto" | "full" | "½" | "⅓" | "¼";
_meta: any;
_item: any;
_sync: any;
};
export type FMInternal = {

View File

@ -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) {
}
}
};

View File

@ -40,7 +40,9 @@ export const newField = (arg: GFCol) => {
createItem({
component: {
id: "ca7ac237-8f22-4492-bb9d-4b715b1f5c25",
props: {},
props: {
type: "text",
},
},
}),
],

View File

@ -91,9 +91,11 @@ export const createItem = (arg: SimplifiedItem): any => {
value: v[0],
valueBuilt: v[1],
};
} else {
if ((v as any)?.meta?.type) {
component.props[k] = v;
} else {
let newItem = createItem(v);
component.props[k] = {
meta: {
type: "content-element",
@ -103,6 +105,7 @@ export const createItem = (arg: SimplifiedItem): any => {
valueBuilt: "",
};
}
}
} else {
component.props[k] = {
meta: { type: "text" },