From c1b3a9ac514b4434a7652b05a4515d29fe446023 Mon Sep 17 00:00:00 2001 From: rizky Date: Thu, 25 Jul 2024 15:40:54 -0700 Subject: [PATCH] fix --- comps/form/field/table-edit/TableEdit.tsx | 42 ++++++++++++++--------- comps/form/gen/gen-form.ts | 27 ++++++++++----- comps/form/gen/walker.ts | 8 +++-- comps/list/TableList.tsx | 4 +-- 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/comps/form/field/table-edit/TableEdit.tsx b/comps/form/field/table-edit/TableEdit.tsx index 1f3b4ef..ec687ba 100755 --- a/comps/form/field/table-edit/TableEdit.tsx +++ b/comps/form/field/table-edit/TableEdit.tsx @@ -1,6 +1,6 @@ import { TableList } from "lib/comps/list/TableList"; import { useLocal } from "lib/utils/use-local"; -import { FC, useRef } from "react"; +import { FC, useEffect, useRef } from "react"; import { FMLocal } from "../../typings"; export const TableEdit: FC<{ @@ -17,7 +17,6 @@ export const TableEdit: FC<{ const local = useLocal( { tbl: null as any, - rowHeight: new WeakMap>(), }, () => {} ); @@ -32,6 +31,10 @@ export const TableEdit: FC<{ } const value = fm.data[name]; + useEffect(() => { + local.tbl.render(); + }, [3000]); + return ( <>
@@ -85,16 +88,31 @@ export const TableEdit: FC<{ > { - const rh = local.rowHeight.get(row); - let h = 50; - if (rh) { - for (const div of Object.values(rh)) { - if (div) { - if (div.offsetHeight > 50) h = div.offsetHeight + 6; + if (local.tbl) { + const data = local.tbl.data; + const el = local.tbl.el as HTMLDivElement; + 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; }} feature={[]} @@ -123,16 +141,8 @@ export const TableEdit: FC<{ const fm_row = { ...fm, render: local.render }; fm_row.data = props.row; local.tbl = tbl; - 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 ( { const fields = {} as Record; - for (const item of new_childs[0].childs) { - const name = item.component?.props?.name; - console.log(name); + if (Array.isArray(new_childs) && new_childs[0] && new_childs[0].childs) { + for (const item of new_childs[0].childs) { + const name = item.component?.props?.name; + console.log(name); + } } // for (const item of existing_childs) { // walk(item); diff --git a/comps/list/TableList.tsx b/comps/list/TableList.tsx index b5b98c5..d14e9d3 100755 --- a/comps/list/TableList.tsx +++ b/comps/list/TableList.tsx @@ -635,8 +635,8 @@ export const TableList: FC = ({ }, }, ]} - rows={genRows(200)} - /> + rows={genRows(200)} + /> ) : ( <>