@aplus-frontend/ui
Version:
67 lines (66 loc) • 2.26 kB
JavaScript
import { useToken as I } from "@aplus-frontend/antdv/es/theme/internal";
import { clsx as T } from "clsx";
import { isFunction as y, isArray as u } from "lodash-unified";
import { useSlots as E, computed as R, unref as s } from "vue";
import { updateFormProps as k, getFieldProps as A } from "../../ap-table/utils.mjs";
import "../../config-provider/index.mjs";
import { getEditableTableTitle as q } from "../../editable-table/utils.mjs";
import { getFinalEditableNode as v } from "../utils/editable.mjs";
import { useNamespace as w } from "../../config-provider/hooks/use-namespace.mjs";
const L = (o, m) => {
const {
em: f,
be: x
} = w("editable-grid"), b = E(), [, g] = I();
return R(() => {
const a = o.columns;
if (!a)
return [];
function r(h) {
return h.map((e) => ({
...e,
children: r(e.children || []),
title: q(e, x("table-header", "title"), f("header-cell", "required"), b.headerCell, s(g).colorTextTertiary),
// tips: 已经处理了title,传递tooltip为undefined不会再内部处理
tooltip: void 0,
customRender({
value: l,
originalNode: F,
...n
}) {
const i = y(e.editable) ? e.editable(n.text, n.record, n.index) : !!e.editable;
let d = F;
if (i) {
const t = k(e, A(e.fieldProps, {
value: l,
...n
})), c = {};
o.onFieldChange && (c[`onUpdate:${t.valuePropName || "value"}`] = (C) => o.onFieldChange?.(n.index, e.dataIndex, C));
const N = u(e.dataIndex) ? e.dataIndex : [e.dataIndex], p = {
name: [...u(o.name) ? o.name : [o.name], n.index, ...N],
...t || {},
field: {
style: "width: 100%",
...t?.field || {},
...c,
class: T("is-editable", t.class)
}
};
d = v(e, p, n.record, s(m));
}
return e.customRender ? e.customRender({
value: l,
...n,
editable: i,
originalNode: d
}) : d;
}
}));
}
return r(a);
});
};
export {
L as default,
L as useGetEditableColumns
};