@aplus-frontend/ui
Version:
144 lines (143 loc) • 3.88 kB
JavaScript
import { createVNode as o, Fragment as p } from "vue";
import { isArray as c, isUndefined as N, isString as b, isBoolean as F, isNumber as E, pick as x } from "lodash-unified";
import { valueEnumToArray as O, objectToString as $, getTableTitle as v, getTableRenderType as w, getTableRenderProps as S, getTableCellRenderNode as V } from "../../ap-table/utils.mjs";
import { noRenderAsFormItemValueList as B } from "../../ap-table/constants.mjs";
import "../../ap-table/components/paragraph-ellipsis/index.vue.mjs";
import M from "../../ap-table/components/paragraph-ellipsis/index.vue2.mjs";
function h(e, r) {
if (r)
return c(r) ? r.reduce((t, l) => t?.[l], e) : e?.[r];
}
function A(e) {
if (!N(e))
return c(e) ? e.reduce((r, t) => b(t) ? `${r}${r ? "." : ""}${t}` : `${r}[${t}]`, "") : String(e);
}
function R(e) {
if (e)
return e === !0 ? "left" : e;
}
function j(e) {
return F(e) ? {
sortable: e
} : e ? {
sortable: !0,
sortType: e?.type,
sortBy: e?.by
} : {
sortable: !1
};
}
function q(e) {
let r;
return F(e.filters) && e.valueEnum ? r = O(e.valueEnum) : r = e.filters, r?.map((t) => ({
label: b(t.text) ? t.text : "",
value: t.value
}));
}
function W(e) {
if (e)
return (r) => e(r.value, r.row);
}
function _(e, r) {
return e ? E(e) ? {
tooltip: r,
rows: e
} : e === !0 || e === "tooltip" ? {
tooltip: r,
rows: 1
} : {
tooltip: null,
rows: 1,
htmlTitle: e === "title" ? r : ""
} : !1;
}
function k(e, r, t) {
if (B.includes(e.valueType))
return t;
if (e.copyable || e.ellipsis) {
const l = _(e.ellipsis, r), i = $(r);
return o(M, {
rawValue: i,
copyable: e.copyable,
ellipsis: l,
content: t
}, null);
}
return t;
}
function T(e, r, t) {
const l = x(e, ["width", "minWidth", "align"]);
return l.field = A(e.dataIndex), l.fixed = R(e.fixed), l.slots = {
header: () => v(e, t, void 0, r)
}, l.headerAlign = e.align, l.showOverflow = !1, l.showFooterOverflow = !1, l;
}
const z = ({
value: e,
...r
}, t, l, i = !0) => {
const s = w(t), d = S({
...t,
valueType: s
}, {
value: e,
...r
}), n = V(s, d, r.record, l), a = t.renderText?.({
value: e,
...r
}) || e, u = t.renderText ? o(p, null, [t.renderText?.({
value: e,
...r
})]) : n;
let f = i ? k(t, a, u) : u;
return t.customRender && (f = t.customRender({
value: e,
...r,
column: t,
originalNode: f,
originalText: a
})), o(p, null, [f]);
};
function y(e, r, t, l) {
const i = x(e, ["width", "minWidth", "align", "resizable", "className", "headerClassName", "footerClassName", "treeNode"]);
i.field = A(e.dataIndex), i.fixed = R(e.fixed), i.headerAlign = e.align, i.footerAlign = e.align, i.showOverflow = !1, i.showFooterOverflow = !1, Object.assign(i, j(e.sorter)), i.filters = q(e), i.filterMultiple = e.filterMultiple, i.filterMethod = W(e.onFilter);
const s = ({
row: d,
rowIndex: n
}) => z({
value: h(d, e.dataIndex),
text: h(d, e.dataIndex),
record: d,
index: n,
renderIndex: n,
column: e
}, e, l);
return i.slots = {
header: () => v(e, t, void 0, r),
default: s,
footer: s
}, e.html && (delete i.slots.default, delete i.slots.footer, i.type = "html"), e.seq && (i.type = "seq", i.slots = {}), i;
}
function J(e, r, t, l) {
if (!e.children?.length)
return y(e, r, t, l);
function i(d) {
return d.map((n) => {
if (n.children?.length) {
const a = T(n, r, t);
return a.children = i(n.children), a;
}
return y(n, r, t, l);
});
}
const s = T(e, r, t);
return s.children = i(e.children), s;
}
export {
z as contentCustom,
A as dataIndexToField,
h as getValueByDataIndex,
J as transformCol,
R as transformFixed,
T as transformToColGroup,
y as transformToColumn
};