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