This commit is contained in:
rizky 2024-07-25 15:40:54 -07:00
parent 3cbe406f67
commit c1b3a9ac51
4 changed files with 51 additions and 30 deletions

View File

@ -1,6 +1,6 @@
import { TableList } from "lib/comps/list/TableList"; import { TableList } from "lib/comps/list/TableList";
import { useLocal } from "lib/utils/use-local"; import { useLocal } from "lib/utils/use-local";
import { FC, useRef } from "react"; import { FC, useEffect, useRef } from "react";
import { FMLocal } from "../../typings"; import { FMLocal } from "../../typings";
export const TableEdit: FC<{ export const TableEdit: FC<{
@ -17,7 +17,6 @@ export const TableEdit: FC<{
const local = useLocal( const local = useLocal(
{ {
tbl: null as any, tbl: null as any,
rowHeight: new WeakMap<any, Record<string, HTMLDivElement>>(),
}, },
() => {} () => {}
); );
@ -32,6 +31,10 @@ export const TableEdit: FC<{
} }
const value = fm.data[name]; const value = fm.data[name];
useEffect(() => {
local.tbl.render();
}, [3000]);
return ( return (
<> <>
<div className="c-w-full c-h-full c-flex c-flex-col"> <div className="c-w-full c-h-full c-flex c-flex-col">
@ -85,16 +88,31 @@ export const TableEdit: FC<{
> >
<TableList <TableList
row_height={(row) => { row_height={(row) => {
const rh = local.rowHeight.get(row);
let h = 50; let h = 50;
if (rh) { if (local.tbl) {
for (const div of Object.values(rh)) { const data = local.tbl.data;
if (div) { const el = local.tbl.el as HTMLDivElement;
if (div.offsetHeight > 50) h = div.offsetHeight + 6; let idx = 0;
if (Array.isArray(data)) {
for (let k = 0; k < data.length; k++) {
if (data[k] === row) {
idx = k;
break;
}
} }
} }
const rowdiv = el.querySelectorAll(`.rdg-row`)[
idx
] as HTMLDivElement;
if (rowdiv) {
rowdiv.querySelectorAll(".field").forEach((field) => {
const div = field as HTMLDivElement;
h = Math.max(h, div.offsetHeight + 10);
});
}
} }
return h; return h;
}} }}
feature={[]} feature={[]}
@ -123,16 +141,8 @@ export const TableEdit: FC<{
const fm_row = { ...fm, render: local.render }; const fm_row = { ...fm, render: local.render };
fm_row.data = props.row; fm_row.data = props.row;
local.tbl = tbl; local.tbl = tbl;
const key = props.column.key; const key = props.column.key;
if (!local.rowHeight.has(props.row)) {
local.rowHeight.set(props.row, {});
}
const rh = local.rowHeight.get(props.row);
if (rh && tbl.el) {
rh[props.column.key] = tbl.el.querySelector(".field");
}
return ( return (
<PassProp <PassProp
idx={props.rowIdx} idx={props.rowIdx}

View File

@ -1,15 +1,13 @@
import { createId } from "@paralleldrive/cuid2";
import { createItem, parseGenField } from "lib/gen/utils"; import { createItem, parseGenField } from "lib/gen/utils";
import { set } from "lib/utils/set"; import { set } from "lib/utils/set";
import get from "lodash.get"; import get from "lodash.get";
import { generateSelect } from "../../md/gen/md-select"; import { generateSelect } from "../../md/gen/md-select";
import { newField } from "./fields"; import { newField } from "./fields";
import { get_rel_many } from "./get_rel_many"; import { genFormOnInit } from "./gen-form/on-init";
import { on_load } from "./on_load";
import { genFormOnLoad } from "./gen-form/on-load"; import { genFormOnLoad } from "./gen-form/on-load";
import { genFormOnSubmit } from "./gen-form/on-submit"; import { genFormOnSubmit } from "./gen-form/on-submit";
import { genFormOnInit } from "./gen-form/on-init";
import { genFormSubmit } from "./gen-form/submit"; import { genFormSubmit } from "./gen-form/submit";
import { get_rel_many } from "./get_rel_many";
import { walkGenForm } from "./walker"; import { walkGenForm } from "./walker";
export const generateForm = async ( export const generateForm = async (
@ -43,12 +41,23 @@ export const generateForm = async (
} }
let is_md = !!_is_md; let is_md = !!_is_md;
if (typeof _is_md === "undefined") { if (typeof _is_md === "undefined") {
if ( let cur = item.edit.parent as any;
item.edit.parent?.item.edit.parent?.item.component?.id === while (cur) {
"cb52075a-14ab-455a-9847-6f1d929a2a73" if (cur) {
) { if (cur.item.component?.id === "cb52075a-14ab-455a-9847-6f1d929a2a73") {
is_md = true; is_md = true;
break;
}
if (cur.item.edit?.parent) {
cur = cur.item.edit.parent;
} else {
break;
}
} else {
break;
}
} }
console.log(is_md);
} }
if (pk) { if (pk) {

View File

@ -4,9 +4,11 @@ export const walkGenForm = (
) => { ) => {
const fields = {} as Record<string, PrasiItem>; const fields = {} as Record<string, PrasiItem>;
for (const item of new_childs[0].childs) { if (Array.isArray(new_childs) && new_childs[0] && new_childs[0].childs) {
const name = item.component?.props?.name; for (const item of new_childs[0].childs) {
console.log(name); const name = item.component?.props?.name;
console.log(name);
}
} }
// for (const item of existing_childs) { // for (const item of existing_childs) {
// walk(item); // walk(item);