UNPKG

@adyen/adyen-platform-experience-web

Version:

![Platform Experience header](https://github.com/Adyen/adyen-platform-experience-web/assets/7926613/18094965-9e01-450e-8dc9-ea84e6b22c2b)

49 lines (48 loc) 1.8 kB
import { useMemo as f } from "../external/preact/hooks/dist/hooks.module.js"; import { getLabel as g } from "../components/utils/getLabel.js"; import h from "../core/Context/useCoreContext.js"; import { useResponsiveContainer as E, containerQueries as U } from "./useResponsiveContainer.js"; import { EMPTY_OBJECT as w } from "../utils/value/constants.js"; import { isUndefined as A } from "../utils/value/is.js"; function O(t) { let i = {}; for (const r of Object.keys(t)) A(t[r]) || (i = { ...i, [r]: t[r] }); return i; } const S = ({ fields: t, customColumns: i, columnConfig: r }) => { const { i18n: s } = h(), k = f(() => t.map((y) => ({ key: y })), [t]), o = E(U.up.sm); return f(() => { const y = (i == null ? void 0 : i.filter((e) => !(t != null && t.some((n) => n === e.key))).map((e) => e.key)) || [], b = [...k, ...(i == null ? void 0 : i.filter((e) => e == null ? void 0 : e.key)) || []], v = (i == null ? void 0 : i.reduce((e, n) => (e[n.key] = n, e), {})) || {}, a = /* @__PURE__ */ new Map(); return b.forEach((e) => { const n = v[e.key]; if ((n == null ? void 0 : n.visibility) !== "hidden") if (a.has(e.key)) { const p = a.get(e.key); a.set(e.key, { ...p, ...e, visible: e.visibility !== "hidden", position: e.align || p.position }); } else { const { key: p, flex: M, align: d } = e, x = s.get(g(p)), T = O((r == null ? void 0 : r[p]) || w); a.set(e.key, { key: p, label: x, visible: y.includes(e.key) ? o : !0, flex: M, position: d, ...T }); } }), Array.from(a.values()); }, [r, i, t, s, o, k]); }; export { S as useTableColumns };