@extclp/vexip-ui
Version:
A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good
330 lines (329 loc) • 13.4 kB
JavaScript
import { defineComponent as ue, inject as A, ref as G, computed as y, watchEffect as me, nextTick as se, openBlock as d, createElementBlock as m, mergeProps as xe, normalizeClass as f, unref as l, createCommentVNode as C, Fragment as h, createBlock as k, withModifiers as D, toDisplayString as S, createVNode as J, withCtx as K, createElementVNode as L, normalizeStyle as fe, createTextVNode as z } from "vue";
import "../checkbox/index.mjs";
import "../ellipsis/index.mjs";
import "../radio/index.mjs";
import "../renderer/index.mjs";
import "../resize-observer/index.mjs";
import { useNameHelper as he, useIcons as we } from "@vexip-ui/config";
import "./table-icon.vue.mjs";
import { useRtl as ye } from "@vexip-ui/hooks";
import { getLast as ke, isFunction as E } from "@vexip-ui/utils";
import { TABLE_STORE as ge, TABLE_ACTIONS as be, columnTypes as ve, noopFormatter as Ce } from "./symbol.mjs";
import Ie from "../radio/radio.vue2.mjs";
import Se from "../checkbox/checkbox.vue2.mjs";
import $ from "./table-icon.vue2.mjs";
import Ee from "../resize-observer/resize-observer.mjs";
import Re from "../ellipsis/ellipsis.vue2.mjs";
import Q from "../renderer/renderer.mjs";
const Te = ["scope", "colspan", "rowspan"], Ge = /* @__PURE__ */ ue({
name: "TableCell",
__name: "table-cell",
props: {
row: {
type: Object,
default: () => ({})
},
rowIndex: {
type: Number,
default: -1
},
column: {
type: Object,
default: () => ({})
},
colIndex: {
type: Number,
default: -1
},
fixed: {
type: String,
default: null
}
},
setup(e) {
const t = e, { state: i, getters: s, mutations: g } = A(ge), r = A(be), a = he("table"), R = we(), { isRtl: U } = ye(), F = G(0), X = G(), p = y(() => t.column.index + b.value.colSpan >= i.columns.length), Y = y(() => {
let n = null;
typeof i.cellClass == "function" ? n = i.cellClass({
row: t.row.data,
rowIndex: t.rowIndex,
column: t.column,
columnIndex: t.column.index
}) : n = i.cellClass;
const o = ve.includes(t.column.type);
return [
a.be("cell"),
{
[a.bem("cell", "typed")]: o,
[a.bem("cell", "center")]: o || t.column.textAlign === "center",
[a.bem("cell", "right")]: t.column.textAlign === "right",
[a.bem("cell", "last")]: p.value
},
t.column.class,
n
];
}), N = y(() => t.fixed === "left" ? i.leftFixedColumns : t.fixed === "right" ? i.rightFixedColumns : i.normalColumns), b = y(() => i.cellSpanMap.get(t.fixed || "default").get(`${t.row.index},${t.column.index}`) || { colSpan: 1, rowSpan: 1 }), Z = y(() => typeof i.cellStyle == "function" ? i.cellStyle({
row: t.row.data,
rowIndex: t.rowIndex,
column: t.column,
columnIndex: t.column.index
}) : i.cellStyle), _ = y(() => {
var H, q;
const n = t.fixed === "left" ? s.leftFixedWidths : t.fixed === "right" ? s.rightFixedWidths : s.normalWidths, { colSpan: o, rowSpan: c } = b.value, u = !s.hasFixedColumn, x = (u || ((H = N.value[0]) == null ? void 0 : H.fixed) === "left") && i.sidePadding[0] || 0, w = (u || ((q = ke(N.value)) == null ? void 0 : q.fixed) === "right") && i.sidePadding[1] || 0, v = n[t.colIndex + o] - n[t.colIndex];
let B;
return c > 1 && i.heightBITree && (B = i.heightBITree.sum(t.row.listIndex + c) - i.heightBITree.sum(t.row.listIndex)), [
t.column.style || "",
Z.value,
{
display: !o || !c ? "none" : void 0,
width: `${(t.column.index ? 0 : x) + (p.value ? w : 0) + v}px`,
height: B ? `${B}px` : void 0,
visibility: t.column.fixed && !t.fixed ? "hidden" : void 0,
borderRightWidth: !i.border && o > 1 && t.colIndex + o >= n.length - 1 ? 0 : void 0,
borderBottomWidth: c > 1 && t.rowIndex + c >= s.processedData.length ? 0 : void 0,
transform: `translate3d(${U.value ? "-" : ""}${(t.column.index ? x : 0) + n[t.colIndex]}px, 0, 0)`
}
];
}), ee = y(() => {
let n;
return typeof i.cellAttrs == "function" ? n = i.cellAttrs({
row: t.row.data,
rowIndex: t.rowIndex,
column: t.column,
columnIndex: t.colIndex
}) : n = i.cellAttrs, { ...t.column.attrs || {}, ...n || {} };
}), T = y(() => E(t.column.formatter) ? t.column.formatter : Ce);
me(() => {
V(t.column) || g.setCellHeight(t.row.key, t.column.key, F.value);
});
function W(n) {
return n.type === "selection";
}
function M(n) {
return n.type === "order";
}
function O(n) {
return n.type === "expand";
}
function P(n) {
return n.type === "drag";
}
function V(n) {
return W(n) || M(n) || O(n) || P(n);
}
function I(n) {
return {
row: t.row.data,
key: t.row.key,
rowIndex: t.rowIndex,
column: t.column,
columnIndex: t.colIndex,
event: n
};
}
function ne(n) {
r == null || r.emitCellEvent("Enter", I(n));
}
function te(n) {
r == null || r.emitCellEvent("Leave", I(n));
}
function le(n) {
r == null || r.emitCellEvent("Click", I(n));
}
function oe(n) {
r == null || r.emitCellEvent("Dblclick", I(n));
}
function ie(n) {
r == null || r.emitCellEvent("Contextmenu", I(n));
}
function j(n, o, c = !1) {
if (!s.disableCheckRows.has(n.key)) {
const u = !n.checked, { data: x, key: w, index: v } = n;
g.handleCheck(w, u, c), r.emitRowCheck({ row: x, key: w, index: v, event: o, checked: u });
}
}
function de(n, o) {
if (!s.disableExpandRows.has(n.key)) {
const c = !n.expanded, { data: u, key: x, index: w } = n;
g.setRowProp(x, "expandAnimate", !0), se(() => {
g.handleExpand(x, c), r.emitRowExpand({ row: u, key: x, index: w, event: o, expanded: c });
});
}
}
function ae(n) {
s.disableDragRows.has(n.key) || g.handleDrag(n.key, !0);
}
function re(n, o) {
var v;
if (!((v = n.children) != null && v.length)) return;
const c = !n.treeExpanded, { data: u, key: x, index: w } = n;
r.runInLocked(), g.setTreeExpanded(n.key, c), r.emitRowExpand({ row: u, key: x, index: w, event: o, expanded: c });
}
function ce(n) {
var o, c;
F.value = (((c = (o = n.borderBoxSize) == null ? void 0 : o[0]) == null ? void 0 : c.blockSize) ?? n.contentRect.height) + i.borderWidth;
}
return (n, o) => {
var c;
return d(), m("div", xe(ee.value, {
ref_key: "wrapper",
ref: X,
class: Y.value,
role: "cell",
scope: e.column.first ? "row" : void 0,
colspan: b.value.colSpan !== 1 ? b.value.colSpan : void 0,
rowspan: b.value.rowSpan !== 1 ? b.value.rowSpan : void 0,
style: _.value,
onMouseenter: ne,
onMouseleave: te,
onClick: le,
onDblclick: oe,
onContextmenu: ie
}), [
e.column.index === 0 ? (d(), m("div", {
key: 0,
class: f(l(a).be("side-pad")),
role: "none",
"aria-hidden": ""
}, null, 2)) : C("", !0),
V(e.column) ? (d(), m("div", {
key: 1,
class: f(l(a).be("content"))
}, [
W(e.column) ? (d(), m(h, { key: 0 }, [
e.column.singleSelect ? (d(), k(l(Ie), {
key: 0,
inherit: "",
label: e.row.key,
value: e.row.checked ? e.row.key : null,
class: f(l(a).be("selection")),
size: e.column.selectionSize || "default",
disabled: l(s).disableCheckRows.has(e.row.key),
onClick: o[0] || (o[0] = D((u) => j(e.row, u, !0), ["prevent", "stop"]))
}, null, 8, ["label", "value", "class", "size", "disabled"])) : (d(), k(l(Se), {
key: 1,
inherit: "",
class: f(l(a).be("selection")),
checked: e.row.checked,
size: e.column.selectionSize || "default",
disabled: l(s).disableCheckRows.has(e.row.key),
partial: e.row.partial,
control: !!((c = e.row.children) != null && c.length),
onClick: o[1] || (o[1] = D((u) => j(e.row, u), ["prevent", "stop"]))
}, null, 8, ["class", "checked", "size", "disabled", "partial", "control"]))
], 64)) : M(e.column) ? (d(), m("span", {
key: 1,
class: f(l(a).be("order"))
}, S(e.column.orderLabel && e.column.orderLabel(e.column.truthIndex ? e.row.index : e.rowIndex)), 3)) : O(e.column) ? (d(), m(h, { key: 2 }, [
l(s).disableExpandRows.has(e.row.key) ? C("", !0) : (d(), m("button", {
key: 0,
type: "button",
class: f({
[l(a).be("expand")]: !0,
[l(a).bem("expand", "active")]: e.row.expanded
}),
onClick: o[2] || (o[2] = D((u) => de(e.row, u), ["stop"]))
}, [
J($, {
name: "expand",
origin: l(R).angleRight
}, null, 8, ["origin"])
], 2))
], 64)) : P(e.column) ? (d(), m(h, { key: 3 }, [
l(s).disableDragRows.has(e.row.key) ? C("", !0) : (d(), m("button", {
key: 0,
type: "button",
class: f(l(a).be("dragger")),
onMousedown: o[3] || (o[3] = (u) => ae(e.row))
}, [
J($, {
name: "dragger",
origin: l(R).dragger
}, null, 8, ["origin"])
], 34))
], 64)) : C("", !0)
], 2)) : (d(), k(l(Ee), {
key: 2,
"on-resize": ce
}, {
default: K(() => {
var u;
return [
L("span", {
class: f(l(a).be("content"))
}, [
l(s).usingTree && (l(s).indentedColumn ? e.column.key === l(s).indentedColumn.key : e.column.first) ? (d(), m(h, { key: 0 }, [
L("span", {
class: f(l(a).be("pad")),
style: fe({
[l(a).cv("row-depth")]: e.row.depth
})
}, null, 6),
L("button", {
type: "button",
class: f([
l(a).be("tree-expand"),
!((u = e.row.children) != null && u.length) && l(a).bem("tree-expand", "hidden")
]),
onClick: o[4] || (o[4] = (x) => re(e.row, x))
}, [
e.row.treeExpanded ? (d(), k($, {
key: 0,
name: "minus",
origin: l(R).minusSquare
}, null, 8, ["origin"])) : (d(), k($, {
key: 1,
name: "plus",
origin: l(R).plusSquare
}, null, 8, ["origin"]))
], 2)
], 64)) : C("", !0),
e.column.ellipsis ?? l(i).ellipsis ? (d(), k(l(Re), {
key: 1,
inherit: "",
class: f(l(a).be("ellipsis")),
"tip-disabled": l(i).barScrolling,
"tooltip-theme": l(i).tooltipTheme,
"tip-max-width": l(i).tooltipWidth
}, {
default: K(() => [
l(E)(e.column.renderer) ? (d(), k(l(Q), {
key: 0,
renderer: e.column.renderer,
data: { row: e.row.data, rowIndex: e.rowIndex, column: e.column, columnIndex: e.column.index }
}, null, 8, ["renderer", "data"])) : l(E)(e.column.accessor) ? (d(), m(h, { key: 1 }, [
z(S(T.value(e.column.accessor(e.row.data, e.rowIndex))), 1)
], 64)) : (d(), m(h, { key: 2 }, [
z(S(T.value(e.row.data[e.column.key])), 1)
], 64))
]),
_: 1
}, 8, ["class", "tip-disabled", "tooltip-theme", "tip-max-width"])) : (d(), m(h, { key: 2 }, [
l(E)(e.column.renderer) ? (d(), k(l(Q), {
key: 0,
renderer: e.column.renderer,
data: { row: e.row.data, rowIndex: e.rowIndex, column: e.column, columnIndex: e.column.index }
}, null, 8, ["renderer", "data"])) : l(E)(e.column.accessor) ? (d(), m(h, { key: 1 }, [
z(S(T.value(e.column.accessor(e.row.data, e.rowIndex))), 1)
], 64)) : (d(), m(h, { key: 2 }, [
z(S(T.value(e.row.data[e.column.key])), 1)
], 64))
], 64))
], 2)
];
}),
_: 1
})),
p.value ? (d(), m("div", {
key: 3,
class: f([l(a).be("side-pad"), l(a).bem("side-pad", "right")]),
role: "none",
"aria-hidden": ""
}, null, 2)) : C("", !0)
], 16, Te);
};
}
});
export {
Ge as default
};
//# sourceMappingURL=table-cell.vue2.mjs.map