UNPKG

koval-ui

Version:

React components collection with minimalistic design. Supports theming, layout, and input validation.

54 lines (53 loc) 1.59 kB
"use client"; import { useCallback as e, useMemo as K } from "react"; /* empty css */ import { set as M } from "../../../internal/utils/set.js"; import { ProcessingModes as C } from "../types.js"; import { useDialogState as E } from "../../Dialog/useDialogState.js"; const B = ({ rowSelection: c, table: i, tableData: u, processingMode: d, setTableData: l, onEdit: h, clearSelection: p }) => { var D, j; const { openDialog: f } = E( (D = i.options.meta) == null ? void 0 : D.deleteModalId ), { openDialog: a } = E((j = i.options.meta) == null ? void 0 : j.editModalId), O = e(() => { f(); }, [f]), q = e(() => { a({ selectionAmount: Object.keys(c).length }); }, [c, a]), o = K( () => Object.keys(c).map((t) => Number(t)), [c] ), R = e( (t, s, n, m) => { const r = [...t]; return s.forEach((A) => { var k, y; const I = (y = (k = i.getColumn(n)) == null ? void 0 : k.columnDef.meta) == null ? void 0 : y.accessorKey; M(r[A], I, m); }), r; }, [i] ), w = e( (t, s) => { const n = R(u, o, t, s), m = Object.fromEntries( o.map((r) => [r, n[r]]) ); d === C.internal && l(n), h(m), p(); }, [p, R, h, d, o, l, u] ), g = e((t, s) => t.filter((n, m) => !s.has(m)), []), x = e(() => { const t = g(u, new Set(o)); d === C.internal && l(t), h({}), p(); }, [g, u, o, d, l, h, p]); return { handleDeleteRequest: O, handleDelete: x, handleEdit: w, handleEditRequest: q }; }; export { B as useEdit }; //# sourceMappingURL=useEdit.js.map