@aplus-frontend/ui
Version:
71 lines (70 loc) • 2.51 kB
JavaScript
import { useSlots as p, computed as C, unref as u } from "vue";
import { omit as N, isFunction as y, isArray as m } from "lodash-unified";
import { getEditableTableTitle as k, mergeClass as v, getFinalNode as w } from "../utils.mjs";
import { updateFormProps as A, getFieldProps as E, getTableRenderProps as q } from "../../ap-table/utils.mjs";
import "../../config-provider/index.mjs";
import { useToken as D } from "@aplus-frontend/antdv/es/theme/internal";
import { useDevWarning as G } from "../../utils/warning.mjs";
import { useNamespace as S } from "../../config-provider/hooks/use-namespace.mjs";
const M = (r, f) => {
const {
em: b,
be: g
} = S("editable-table"), x = G("EditableTable"), F = p(), [, T] = D();
return C(() => {
const d = r.columns;
if (!d)
return [];
function c(h) {
return h.map((e) => ({
...N(e, ["ellipsis"]),
children: c(e.children || []),
title: k(e, g("table-header", "title"), b("header-cell", "required"), F.headerCell, u(T).colorTextTertiary),
customRender({
value: a,
...n
}) {
const l = y(e.editable) ? e.editable(n.text, n.record, n.index) : !!e.editable;
if (!e.valueType && !e.customRender && !e.customRenderFormItem)
return x(!1, "usage", "'can not render table cell because no `valueType` / `customRender` / `customRenderFormItem`'"), null;
let t;
if (l) {
const o = A(e, E(e.fieldProps, {
value: a,
...n
})), i = {};
r.onFieldChange && (i[`onUpdate:${o.valuePropName || "value"}`] = (R) => r.onFieldChange?.(n.index, e.dataIndex, R));
const I = m(e.dataIndex) ? e.dataIndex : [e.dataIndex];
t = {
name: [...m(r.name) ? r.name : [r.name], n.index, ...I],
...o || {},
field: {
style: "width: 100%",
...o?.field || {},
...i,
class: v("is-editable", o.class)
}
};
} else
t = {
field: q(e, {
value: a,
...n
})
};
const s = w(e, l, t, a, n.record, u(f));
return e.customRender ? e.customRender({
value: a,
...n,
editable: l,
originalNode: s
}) : s;
}
}));
}
return c(d);
});
};
export {
M as default
};