e-virt-table
Version:
A powerful data table based on canvas. You can use it as data grid、Microsoft Excel or Google sheets. It supports virtual scroll、cell edit etc.
1,396 lines • 235 kB
JavaScript
(function(){"use strict";try{if(typeof document<"u"){var o=document.createElement("style");o.appendChild(document.createTextNode(":root{--evt-header-font: 12px normal Arial;--evt-body-font: 12px normal Arial;--evt-color-white: #fff;--evt-color-black: #000000;--evt-color-primary: rgb(82, 146, 247);--evt-text-color-primary: #333;--evt-text-color-regular: #666;--evt-text-color-secondary: #999;--evt-box-shadow: 0 2px 12px 0 #0000001a;--evt-editor-bg-color: #fff;--evt-editor-text-color: #333;--evt-border-color: #e1e6eb;--evt-stripe-color: #fafafa;--evt-placeholder-color: #cdd0dc;--evt-header-bg-color: #f8faff;--evt-body-bg-color: #fff;--evt-header-text-color: #1d2129;--evt-body-text-color: #4e5969;--evt-footer-text-color: #4e5969;--evt-loading-icon-color: #4e5969;--evt-expand-icon-color: #4e5969;--evt-shrink-icon-color: #4e5969;--evt-error-tip-icon-color: red;--evt-cell-hover-icon-bg-color: #fff;--evt-cell-hover-icon-border-color: #dde0ea;--evt-scroller-color: #dee0e3;--evt-scroller-track-color: #fff;--evt-scroller-focus-color: #bbbec4;--evt-select-border-color: var(--evt-color-primary);--evt-select-area-color: rgba(82, 146, 247, .1);--evt-select-row-col-bg-color: transparent;--evt-autofill-point-border-color: #fff;--evt-edit-bg-color: #fcf6ed;--evt-checkbox-color: var(--evt-color-primary);--evt-readonly-color: #fff;--evt-readonly-text-color: var(--evt-body-text-color);--evt-error-tip-color: #ed3f14;--evt-footer-bg-color: #fafafa;--evt-highlight-hover-row-color: rgba(186, 203, 231, .1);--evt-highlight-selected-row-color: rgba(82, 146, 247, .1);--evt-tooltip-bg-color: #303133;--evt-tooltip-text-color: #fff;--evt-resize-row-line-color: #e1e6eb;--evt-resize-column-line-color: #e1e6eb}.dark{--evt-border-color: #363637;--evt-header-bg-color: #141414;--evt-body-bg-color: #141414;--evt-header-text-color: #a3a6ad;--evt-scroller-color: #414243;--evt-scroller-track-color: #141414;--evt-scroller-focus-color: #a3a6ad;--evt-edit-bg-color: #141414;--evt-readonly-text-color: #cfd3dc;--evt-footer-bg-color: #262727;--evt-autofill-point-border-color: #fff;--evt-editor-bg-color: #434343;--evt-editor-text-color: #cfd3dc}.e-virt-table-container{position:relative;outline:none}.e-virt-table-stage{position:relative;overflow:hidden;outline:none;box-sizing:border-box;z-index:10;border-radius:8px;border:1px solid var(--evt-border-color)}.e-virt-table-canvas{position:absolute;left:0;top:0;box-sizing:border-box;border:none;outline:none;z-index:10}.e-virt-table-editor{position:absolute;top:-10000px;left:-10000px;text-align:left;height:auto;line-height:0;z-index:100;overflow:hidden;background-color:var(--evt-editor-bg-color);border:2px solid var(--evt-color-primary);box-sizing:border-box;box-shadow:var(--evt-box-shadow);display:flex;align-items:center}.e-virt-table-overlayer{position:absolute;left:0;top:0;overflow:hidden;z-index:100;pointer-events:none}.e-virt-table-editor-textarea{width:100%;box-sizing:border-box;outline:none;font-weight:400;padding:8px;font-size:12px;color:inherit;white-space:pre-wrap;word-wrap:break-word;word-break:break-all;line-height:1.5;margin:0;border:none;vertical-align:middle;background:var(--evt-editor-bg-color);color:var(--evt-editor-text-color);overflow-y:auto;resize:none}.e-virt-table-context-menu{position:absolute;font-size:14px;color:var(--evt-text-color-regular);background-color:var(--evt-color-white);border-radius:4px;border:1px solid #e4e7ed;box-shadow:var(--evt-box-shadow);width:fit-content;padding:6px 0;z-index:9999;left:-99999px;top:-99999px}.e-virt-table-context-menu-item{cursor:pointer;padding:8px 24px;color:var(--evt-text-color-regular)}.e-virt-table-context-menu-item:hover{color:var(--evt-color-primary);background-color:#f5f7fa}")),document.head.appendChild(o)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
var Jt = Object.defineProperty;
var Qt = (c, t, e) => t in c ? Jt(c, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[t] = e;
var n = (c, t, e) => Qt(c, typeof t != "symbol" ? t + "" : t, e);
class te {
constructor(t) {
n(this, "rules");
this.rules = t;
}
validate(t) {
const e = [], { column: i, row: s, key: o, rowKey: r, colIndex: l, rowIndex: a, value: h, field: d, fieldValue: f } = t;
Array.isArray(this.rules) || (this.rules = [this.rules]);
for (const x of this.rules) {
if (!x.required && (h == null || h === ""))
return e;
if (x.validator) {
const u = {
field: d,
fieldValue: f,
value: h,
column: i,
colIndex: l,
rowIndex: a,
row: s,
key: o,
rowKey: r,
...x
};
x.validator(u, h, (p) => {
p && e.push({
...u,
message: p
});
});
}
x.pattern && !x.pattern.test(h) && e.push({
value: h,
column: i,
row: s,
key: o,
rowKey: r,
colIndex: l,
rowIndex: a,
field: d,
fieldValue: f,
message: x.message || `${o} is pattern validation error`
}), x.required && (h == null || h === "") && e.push({
value: h,
column: i,
row: s,
key: o,
rowKey: r,
colIndex: l,
rowIndex: a,
field: d,
fieldValue: f,
message: x.message || `${o} is required`
});
}
return e;
}
}
function St() {
return "xxxxxxxxxxxxxxxxxx".replace(/[x]/g, function(c) {
const t = Math.random() * 16 | 0;
return (c === "x" ? t : t & 3 | 8).toString(16);
});
}
function Lt(c, t) {
let e = 0, i;
return function(...s) {
const o = (/* @__PURE__ */ new Date()).getTime(), r = o - e;
!e || r >= t ? (c.apply(this, s), e = o) : i || (i = setTimeout(() => {
c.apply(this, s), e = (/* @__PURE__ */ new Date()).getTime(), i = void 0;
}, t - r));
};
}
function Tt(c = []) {
return c.length ? c.map((t) => Tt(t.children) + 1).sort((t, e) => e - t)[0] : 0;
}
function ee(c = []) {
let t = [], e = [], i = [];
return c.forEach((s) => {
s.fixed === "left" ? t.push(s) : s.fixed === "right" ? i.push(s) : e.push(s);
}), [
...t.sort((s, o) => (s.sort ?? 0) - (o.sort ?? 0)),
...e.sort((s, o) => (s.sort ?? 0) - (o.sort ?? 0)),
...i.sort((s, o) => (s.sort ?? 0) - (o.sort ?? 0))
];
}
function At(c = [], t = 1, e = 0) {
return c.map((i) => {
if (i.children) {
let s = 0, o = i.fixed;
i.children.forEach((l) => {
l.fixed = o;
});
const r = At(i.children, t - 1, e + 1);
return r && r.forEach((l) => {
s += l.colspan ?? 0;
}), {
...i,
width: i.width,
level: e,
rowspan: 1,
colspan: s,
children: r
};
}
return {
...i,
level: e,
rowspan: t,
colspan: 1
};
});
}
function et(c = []) {
let t = [];
return c.forEach((e) => {
e.children ? t = t.concat(et(e.children)) : t.push(e);
}), t;
}
const mt = /^(\r\n|\n\r|\r|\n)/, ie = /^[^\t\r\n]+/, yt = /^\t/;
function se(c) {
let t = [[""]];
if (c.length === 0)
return t;
let e = 0, i = 0, s;
for (; c.length > 0 && s !== c.length; )
if (s = c.length, c.match(yt))
c = c.replace(yt, ""), e += 1, t[i][e] = "";
else if (c.match(mt))
c = c.replace(mt, ""), e = 0, i += 1, t[i] = [""];
else {
let o = "";
if (c.startsWith('"')) {
let r = 0, l = !0;
for (; l; ) {
const a = c.slice(0, 1);
a === '"' && (r += 1), o += a, c = c.slice(1), (c.length === 0 || c.match(/^[\t\r\n]/) && r % 2 === 0) && (l = !1);
}
o = o.replace(/^"/, "").replace(/"$/, "").replace(/["]*/g, (a) => new Array(Math.floor(a.length / 2)).fill('"').join(""));
} else {
const r = c.match(ie);
o = r ? r[0] : "", c = c.slice(o.length);
}
t[i][e] = o;
}
return Array.isArray(t) && t.length > 1 && t[t.length - 1].length === 1 && t[t.length - 1][0] === "" && (t = t.slice(0, t.length - 1)), t;
}
function oe(c) {
let t, e, i, s, o = "", r;
for (t = 0, e = c.length; t < e; t += 1) {
for (s = c[t].length, i = 0; i < s; i += 1)
i > 0 && (o += " "), r = c[t][i], typeof r == "string" ? r.indexOf(`
`) > -1 ? o += `"${r.replace(/"/g, '""')}"` : o += r : r == null ? o += "" : o += r;
t !== e - 1 && (o += `
`);
}
return o;
}
function Mt(c, t, e = []) {
let i = 0;
const s = [];
return c.forEach((o, r) => {
if (r === 0)
s.push(1);
else {
const l = e.reduce((h, d) => `${h}${o[d] ?? ""}`, "") || o[t], a = e.reduce((h, d) => `${h}${c[r - 1][d] ?? ""}`, "") || c[r - 1][t];
l === a ? (s[i] += 1, s.push(0)) : (s.push(1), i = r);
}
}), s;
}
function Ht(c, t) {
let e = "", i = "";
const s = {};
return t.forEach((o, r) => {
r === 0 ? (e = o.key, i = o.key, s[o.key] = 1) : c[o.key] === c[e] ? (s[o.key] = 0, s[i] += 1) : (s[o.key] = 1, e = o.key, i = o.key);
}), s;
}
function re(c, t, e = []) {
const { visibleRows: i, rowIndex: s, headIndex: o } = c, r = Mt(i, t, e);
return r[s - o] === 0 ? {
rowspan: 0,
colspan: 0,
relationRowKeys: e,
mergeRow: !0
} : {
rowspan: r[s - o],
colspan: 1,
relationRowKeys: e,
mergeRow: !0
};
}
function ne(c, t = []) {
const { column: e, row: i, visibleLeafColumns: s } = c, o = s.filter((r) => t.includes(r.key));
if (t.includes(e.key)) {
const r = Ht(i, o);
return r[e.key] === 0 ? {
rowspan: 0,
colspan: 0,
relationColKeys: t,
mergeCol: !0
} : {
rowspan: 1,
colspan: r[e.key],
relationColKeys: t,
mergeCol: !0
};
}
}
function le(c, t = document.documentElement) {
const e = c.startsWith("--") ? c : `--${c}`;
return getComputedStyle(t).getPropertyValue(e).trim();
}
class Dt {
constructor(t, e, i, s, o, r, l) {
n(this, "ctx");
n(this, "x", 0);
n(this, "y", 0);
n(this, "width", 0);
n(this, "height", 0);
n(this, "fixed");
n(this, "cellType");
this.ctx = t, this.x = e, this.y = i, this.width = s, this.height = o, this.fixed = l, this.cellType = r;
}
isHorizontalVisible() {
if (this.fixed)
return !0;
const { stageWidth: t, fixedLeftWidth: e, scrollX: i, fixedRightWidth: s } = this.ctx, o = t;
return !(this.x + this.width - e - i <= 0 || this.x - i >= o - s);
}
isVerticalVisible() {
const { stageHeight: t, scrollY: e } = this.ctx, i = t;
return !(this.y + this.height - e <= 0 || this.y - e >= i);
}
getDrawX() {
if (this.fixed === "left")
return this.x;
if (this.fixed === "right") {
const {
stageWidth: t,
config: { SCROLLER_TRACK_SIZE: e }
} = this.ctx;
return t - (this.ctx.header.width - this.x) - e;
}
return this.x - this.ctx.scrollX;
}
getDrawY() {
return this.cellType === "header" ? this.y : this.cellType === "footer" && this.ctx.config.FOOTER_FIXED ? this.y : this.y - this.ctx.scrollY;
}
getLeftFixedX() {
return this.x - this.ctx.scrollX;
}
/**
* RightFixed时相对StageX
* @returns
*/
getRightFixedX() {
}
}
class ut extends Dt {
constructor(e, i, s, o, r, l, a, h, d, f = "body") {
super(e, o, r, l, a, f, h.fixed);
n(this, "formatter");
n(this, "formatterFooter");
n(this, "hoverIconName", "");
n(this, "operation", !1);
n(this, "align");
n(this, "verticalAlign");
n(this, "fixed");
n(this, "type");
n(this, "editorType");
n(this, "editorProps");
n(this, "cellType");
n(this, "level");
n(this, "colspan", 1);
n(this, "rowspan", 1);
n(this, "mergeRow", !1);
n(this, "mergeCol", !1);
n(this, "relationRowKeys", []);
// 合并单元格关联key
n(this, "relationColKeys", []);
// 合并单元格关联key
n(this, "key");
n(this, "column");
n(this, "rowIndex");
n(this, "colIndex");
n(this, "rowKey");
n(this, "row");
n(this, "value");
n(this, "render");
n(this, "renderFooter");
n(this, "style", {});
n(this, "rules", []);
n(this, "message", "");
n(this, "text", "");
n(this, "displayText", "");
n(this, "visibleWidth", 0);
n(this, "visibleHeight", 0);
n(this, "isHasChanged", !1);
n(this, "drawX", 0);
n(this, "drawY", 0);
n(this, "drawCellBgColor", "");
n(this, "drawCellSkyBgColor", "");
n(this, "drawTextColor", "");
n(this, "drawTextX", 0);
n(this, "drawTextY", 0);
n(this, "drawImageX", 0);
n(this, "drawImageY", 0);
n(this, "drawImageWidth", 0);
n(this, "drawImageHeight", 0);
n(this, "drawImageName", "");
n(this, "drawImageSource");
n(this, "ellipsis", !1);
n(this, "rowExpand", !1);
n(this, "rowHasChildren", !1);
n(this, "overflowTooltipShow", !0);
n(this, "selectorCellValueType", "value");
n(this, "overflowTooltipMaxWidth", 500);
n(this, "overflowTooltipPlacement", "top");
this.visibleWidth = this.width, this.visibleHeight = this.height, this.colIndex = s, this.rowIndex = i, this.key = h.key, this.type = h.type || "", this.editorType = h.editorType || "text", this.selectorCellValueType = h.selectorCellValueType || this.ctx.config.SELECTOR_CELL_VALUE_TYPE || "value", this.editorProps = h.editorProps || {}, this.cellType = f, this.align = h.align || "center", this.verticalAlign = h.verticalAlign || "middle", this.fixed = h.fixed, this.level = h.level || 0, this.operation = h.operation || !1, this.column = h, this.rules = h.rules || [], this.row = d, this.rowKey = this.cellType === "body" ? this.ctx.database.getRowKeyForRowIndex(i) : `${this.cellType}_${this.rowIndex}`, this.value = this.getValue(), this.render = h.render, this.overflowTooltipShow = h.overflowTooltipShow !== !1, this.overflowTooltipMaxWidth = h.overflowTooltipMaxWidth || 500, this.overflowTooltipPlacement = h.overflowTooltipPlacement || "top", this.renderFooter = h.renderFooter, this.hoverIconName = h.hoverIconName, this.formatter = h.formatter, this.formatterFooter = h.formatterFooter, this.update();
}
setWidthHeight(e, i) {
this.width = e, this.height = i;
}
getValidationMessage() {
const e = this.ctx.database.getValidationError(this.rowKey, this.key);
if (Array.isArray(e) && e.length) {
const [i] = e;
this.message = i.message || "";
}
return this.message;
}
update() {
this.drawX = this.getDrawX(), this.drawY = this.getDrawY(), this.drawTextX = this.drawX, this.drawTextY = this.drawY, this.isHasChanged = this.ctx.database.isHasChangedData(this.rowKey, this.key), this.updateSpan(), this.updateStyle(), this.updateType(), this.updateHoverIcon(), this.updateSelection(), this.updateTree(), this.updateEditor(), this.updateRender(), this.getValidationMessage(), this.updateContainer(), this.text = this.getText(), this.displayText = this.getDisplayText();
}
updateSpan() {
if (this.cellType === "footer")
return;
const { SPAN_METHOD: e } = this.ctx.config;
if (typeof e == "function") {
const i = e, {
colspan: s = 1,
rowspan: o = 1,
relationRowKeys: r,
relationColKeys: l,
mergeRow: a = !1,
mergeCol: h = !1
} = i({
row: this.row,
rowIndex: this.rowIndex,
colIndex: this.colIndex,
column: this.column,
value: this.getValue(),
headIndex: this.ctx.body.headIndex,
headPosition: this.ctx.database.getPositionForRowIndex(this.ctx.body.headIndex),
visibleRows: this.ctx.body.visibleRows,
visibleLeafColumns: this.ctx.header.visibleLeafColumns,
rows: this.ctx.body.data
}) || {};
Array.isArray(r) && r.length > 0 ? this.relationRowKeys = r : this.relationRowKeys = [this.key], Array.isArray(l) && l.length > 0 ? this.relationColKeys = l : this.relationColKeys = [this.key], this.mergeCol = h, this.mergeRow = a, this.colspan = s, this.rowspan = o, this.visibleWidth = this.getWidthByColIndexColSpan(this.colIndex, this.colspan), this.visibleHeight = this.ctx.database.getHeightByRowIndexRowSpan(this.rowIndex, this.rowspan);
}
}
updateSpanInfo() {
if (this.mergeRow || this.mergeCol) {
const e = this.getSpanInfo();
this.height = e.height, this.width = e.width, this.drawX = this.getDrawX(), this.drawY = this.getDrawY(), this.drawY -= e.offsetTop, this.drawX -= e.offsetLeft;
}
}
updateType() {
const { BODY_CELL_TYPE_METHOD: e } = this.ctx.config;
if (typeof e == "function") {
const s = e({
row: this.row,
rowIndex: this.rowIndex,
colIndex: this.colIndex,
column: this.column,
value: this.getValue()
});
s !== void 0 && (this.type = s);
}
}
updateEditor() {
const { BODY_CELL_EDITOR_METHOD: e } = this.ctx.config;
if (typeof e == "function") {
const s = e({
row: this.row,
rowIndex: this.rowIndex,
colIndex: this.colIndex,
column: this.column,
value: this.getValue()
});
if (s !== void 0) {
const { type: o, props: r = {} } = s;
this.editorType = o, this.editorProps = r;
}
}
}
updateRender() {
const { BODY_CELL_RENDER_METHOD: e } = this.ctx.config;
if (typeof e == "function") {
const s = e({
row: this.row,
rowIndex: this.rowIndex,
colIndex: this.colIndex,
column: this.column,
value: this.getValue()
});
s !== void 0 && (this.render = s);
}
}
validate() {
this.ctx.database.getValidator(this.rowKey, this.key).then(() => {
this.ctx.database.setValidationError(this.rowKey, this.key, []), this.message = "";
}).catch((e) => {
if (Array.isArray(e) && e.length) {
const [i] = e;
this.message = i.message, this.ctx.database.setValidationError(this.rowKey, this.key, e);
}
}).finally(() => {
this.ctx.emit("draw");
});
}
/**
* 更新样式
*/
updateStyle() {
this.style = this.getOverlayerViewsStyle();
}
updateTree() {
const { CELL_PADDING: e = 0 } = this.ctx.config, { rowKey: i, cellType: s } = this;
let o, r = 0, l = "";
if (this.type === "tree" && s === "body") {
const a = this.ctx.database.getRowForRowKey(i), { expand: h = !1, hasChildren: d = !1, expandLoading: f = !1, level: x = 0 } = a || {};
if (this.rowExpand = h, this.rowHasChildren = d, f) {
const g = this.ctx.icons.get("loading");
l = "loading", o = g, r = x * 8;
} else if (d) {
const g = this.ctx.icons.get("expand"), w = this.ctx.icons.get("shrink");
o = h ? w : g, l = h ? "shrink" : "expand", r = x * 8;
} else
r = x * 8;
let u = 20, p = 20;
if (o) {
let g = this.drawX + r + e, w = this.drawY + (this.visibleHeight - p) / 2;
this.ctx.paint.drawImage(o, g, w, u, p), this.drawImageX = g, this.drawImageY = w, this.drawImageWidth = u, this.drawImageHeight = p, this.drawImageName = l, this.drawImageSource = o;
}
this.align = "left", this.drawTextX = r + this.drawX + u - 0.5;
}
}
updateContainer() {
const {
BODY_BG_COLOR: e,
EDIT_BG_COLOR: i,
BODY_CELL_STYLE_METHOD: s,
FOOTER_CELL_STYLE_METHOD: o,
READONLY_TEXT_COLOR: r,
BODY_TEXT_COLOR: l,
FOOTER_TEXT_COLOR: a,
FOOTER_BG_COLOR: h,
HIGHLIGHT_SELECTED_ROW: d,
HIGHLIGHT_SELECTED_ROW_COLOR: f,
HIGHLIGHT_HOVER_ROW: x,
HIGHLIGHT_HOVER_ROW_COLOR: u,
STRIPE: p,
STRIPE_COLOR: g
} = this.ctx.config;
if (this.cellType === "footer") {
let _ = h, S = a;
if (typeof o == "function") {
const I = o, { backgroundColor: b, color: O } = I({
row: this.row,
rowIndex: this.rowIndex,
colIndex: this.colIndex,
column: this.column,
value: this.getValue()
}) || {};
b && (_ = b), O && (S = O);
}
this.drawCellSkyBgColor = "transparent", this.drawCellBgColor = _, this.drawTextColor = S;
return;
}
let w = "transparent";
const E = this.ctx.hoverCell, y = this.ctx.currentCell;
let m = this.rowIndex, R = this.rowIndex;
if (this.rowspan !== 1 && (x || d)) {
const _ = this.getSpanInfo(), { yArr: S } = _;
m = S[0], R = S[1];
}
x && E && (E.rowKey === this.rowKey && (w = u), E.rowIndex >= m && E.rowIndex <= R && (w = u)), d && y && (y.rowKey === this.rowKey && (w = f), y.rowIndex >= m && y.rowIndex <= R && (w = f)), this.drawCellSkyBgColor = w;
let C = e, v = l;
if (this.ctx.database.getReadonly(this.rowKey, this.key) || (C = i, v = r), p && (this.rowIndex % 2 ? C = g : C = e), typeof s == "function") {
const _ = s, { backgroundColor: S, color: I } = _({
row: this.row,
rowIndex: this.rowIndex,
colIndex: this.colIndex,
column: this.column,
isHasChanged: this.isHasChanged,
value: this.getValue()
}) || {};
S && (C = S), I && (v = I);
}
this.drawCellBgColor = C, this.drawTextColor = v;
}
updateSelection() {
const { visibleWidth: e, visibleHeight: i, rowspan: s, colspan: o, cellType: r, type: l, rowIndex: a, rowKey: h } = this;
if (!(s === 0 || o === 0) && r !== "footer" && ["index-selection", "selection"].includes(l)) {
const d = this.ctx.database.getRowSelection(h), f = this.ctx.database.getRowSelectable(h), { CHECKBOX_SIZE: x = 0 } = this.ctx.config, u = this.drawX + (e - x) / 2, p = this.drawY + (i - x) / 2;
let g = this.ctx.icons.get("checkbox-uncheck"), w = "checkbox-uncheck";
d && f ? (g = this.ctx.icons.get("checkbox-check"), w = "checkbox-check") : d && f ? (g = this.ctx.icons.get("checkbox-check-disabled"), w = "checkbox-check-disabled") : !d && f ? (g = this.ctx.icons.get("checkbox-uncheck"), w = "checkbox-uncheck") : (g = this.ctx.icons.get("checkbox-disabled"), w = "checkbox-disabled"), g && l == "index-selection" ? (this.ctx.hoverCell && this.ctx.hoverCell.rowIndex === a || ["checkbox-disabled", "checkbox-check"].includes(w)) && (this.drawImageX = u, this.drawImageY = p, this.drawImageWidth = x, this.drawImageHeight = x, this.drawImageName = w, this.drawImageSource = g) : g && l === "selection" && (this.drawImageX = u, this.drawImageY = p, this.drawImageWidth = x, this.drawImageHeight = x, this.drawImageName = w, this.drawImageSource = g);
}
}
updateHoverIcon() {
if (this.ctx.database.getReadonly(this.rowKey, this.key))
return;
const { BODY_CELL_HOVER_ICON_METHOD: i, CELL_HOVER_ICON_SIZE: s, CELL_PADDING: o, ENABLE_MERGE_CELL_LINK: r } = this.ctx.config;
if (typeof i == "function") {
const h = i({
row: this.row,
rowIndex: this.rowIndex,
colIndex: this.colIndex,
column: this.column,
value: this.getValue()
});
h !== void 0 && (this.hoverIconName = h);
}
const { hoverCell: l } = this.ctx;
if (this.hoverIconName && !this.ctx.editing && l) {
let a = 0, h = 0;
if (l.rowKey === this.rowKey && (a = this.drawX + this.width - s - o, h = this.drawY + (this.height - s) / 2), this.rowspan !== 1 && r) {
const f = this.getSpanInfo(), { yArr: x } = f, u = x[0], p = x[1];
if (l.rowIndex >= u && l.rowIndex <= p) {
const { width: g, height: w, offsetTop: E, offsetLeft: y } = f;
a = this.drawX - y + g - s - o, h = this.drawY - E + (w - s) / 2;
}
}
const d = this.ctx.icons.get(this.hoverIconName);
this.drawImageX = a, this.drawImageY = h, this.drawImageWidth = s, this.drawImageHeight = s, this.drawImageName = this.hoverIconName, this.drawImageSource = d;
}
}
// 过去跨度配置
getSpanInfo() {
return this.ctx.database.getSpanInfo(this);
}
/**
* 获取显示文本
* @returns
*/
getDisplayText() {
return this.cellType === "footer" ? this.renderFooter || this.text === null || this.text === void 0 ? "" : this.text : this.rowspan === 0 || this.colspan === 0 || this.render || this.type === "index-selection" && (this.ctx.hoverCell && this.ctx.hoverCell.rowIndex === this.rowIndex || ["checkbox-disabled", "checkbox-check"].includes(this.drawImageName)) || this.text === null || this.text === void 0 ? "" : `${this.text}`;
}
/**
* 获取文本
* @returns
*/
getText() {
if (this.cellType === "footer")
return typeof this.formatterFooter == "function" ? this.formatterFooter({
row: this.row,
rowIndex: this.rowIndex,
colIndex: this.colIndex,
column: this.column,
value: this.row[this.key]
}) : this.row[this.key];
if (typeof this.formatter == "function")
return this.formatter({
row: this.row,
rowIndex: this.rowIndex,
colIndex: this.colIndex,
column: this.column,
value: this.getValue()
});
const { BODY_CELL_FORMATTER_METHOD: e } = this.ctx.config;
return typeof e == "function" ? e({
row: this.row,
rowIndex: this.rowIndex,
colIndex: this.colIndex,
column: this.column,
value: this.getValue()
}) : ["index-selection", "index"].includes(this.type) ? `${this.rowIndex + 1}` : (this.value = this.ctx.database.getItemValue(this.rowKey, this.key), this.value);
}
getValue() {
return this.ctx.database.getItemValue(this.rowKey, this.key);
}
// 拓展格子可设置数据
setValue(e) {
this.ctx.setItemValueByEditor(this.rowKey, this.key, e);
}
/**
* 获取样式
*/
getOverlayerViewsStyle() {
let e = `${this.drawX - this.ctx.fixedLeftWidth}px`, i = `${this.drawY - this.ctx.body.y}px`;
return this.fixed === "left" ? e = `${this.drawX}px` : this.fixed === "right" && (e = `${this.drawX - (this.ctx.stageWidth - this.ctx.fixedRightWidth)}px`), this.cellType === "footer" && this.ctx.config.FOOTER_FIXED && (i = `${this.drawY - this.ctx.footer.y}px`), {
position: "absolute",
overflow: "hidden",
left: e,
top: i,
width: `${this.visibleWidth}px`,
height: `${this.visibleHeight}px`,
pointerEvents: "initial",
userSelect: "none"
};
}
drawContainer() {
const {
paint: e,
config: { BORDER_COLOR: i, BORDER: s }
} = this.ctx, { drawX: o, drawY: r } = this;
e.drawRect(o, r, this.visibleWidth, this.visibleHeight, {
borderColor: s ? i : "transparent",
fillColor: this.drawCellBgColor
}), e.drawRect(o, r, this.width, this.height, {
borderColor: "transparent",
fillColor: this.drawCellSkyBgColor
}), s || this.ctx.paint.drawLine(
[o, r + this.visibleHeight, o + this.visibleWidth, r + this.visibleHeight],
{
borderColor: i,
fillColor: i,
borderWidth: 1,
lineCap: "round",
lineJoin: "round"
}
);
}
drawAutofillPiont() {
if (this.cellType === "footer")
return;
const { SELECT_BORDER_COLOR: e, ENABLE_AUTOFILL: i, ENABLE_SELECTOR: s, AUTOFILL_POINT_BORDER_COLOR: o } = this.ctx.config;
if (!s || !i || this.ctx.editing)
return;
const { xArr: r, yArr: l } = this.ctx.selector, a = r[1], h = l[1], { colIndex: d, rowIndex: f, drawX: x, drawY: u } = this;
if (d === a && f === h) {
const g = d === this.ctx.maxColIndex || f === this.ctx.maxRowIndex || d === this.ctx.lastCenterColIndex ? 6 : 4;
this.ctx.paint.drawRect(x + this.width - g, u + this.height - g, 6, 6, {
borderColor: o,
fillColor: e
});
}
}
draw() {
this.drawText(), this.drawImage(), this.drawSelector(), this.drawAutofillPiont(), this.drawErrorTip();
}
/**
* 根据列的索引获取列的宽度
* @param {Number} colIndex
*/
getWidthByColIndexColSpan(e, i) {
if (i === 0)
return 0;
let s = 0;
for (let o = e; o < e + i; o++) {
const r = this.ctx.header.leafCellHeaders[o];
s += r.width;
}
return s;
}
drawText() {
const { CELL_PADDING: e, BODY_FONT: i, PLACEHOLDER_COLOR: s } = this.ctx.config;
let o = this.visibleWidth;
if (this.type === "tree") {
const f = this.drawTextX - this.drawX;
o = this.visibleWidth - f;
}
const { ellipsis: r } = this.ctx.paint.handleEllipsis(this.displayText, o, e, i);
this.ellipsis = r;
const { placeholder: l } = this.column;
let a = this.displayText, h = this.drawTextColor;
return !this.ctx.database.getReadonly(this.rowKey, this.key) && l && ["", null, void 0].includes(this.text) && this.cellType === "body" && !(this.rowspan === 0 || this.colspan === 0) && (a = l, h = s), this.ctx.paint.drawText(a, this.drawTextX, this.drawTextY, o, this.visibleHeight, {
font: i,
padding: e,
align: this.align,
verticalAlign: this.verticalAlign,
color: h
});
}
drawImage() {
if (this.drawImageSource) {
if (this.hoverIconName) {
const { CELL_HOVER_ICON_BG_COLOR: e, CELL_HOVER_ICON_BORDER_COLOR: i } = this.ctx.config;
this.ctx.paint.drawRect(
this.drawImageX - 2,
this.drawImageY - 2,
this.drawImageWidth + 4,
this.drawImageHeight + 4,
{
borderColor: i,
radius: 4,
borderWidth: 1,
fillColor: e
}
);
}
this.ctx.paint.drawImage(
this.drawImageSource,
this.drawImageX,
this.drawImageY,
this.drawImageWidth,
this.drawImageHeight
);
}
}
drawSelector() {
if (this.cellType === "footer")
return;
const { ENABLE_SELECTOR: e } = this.ctx.config;
if (!e)
return;
const { xArr: i, yArr: s, xArrCopy: o, yArrCopy: r } = this.ctx.selector;
this.drawBorder({
xArr: o,
yArr: r,
borderColor: this.ctx.config.SELECT_BORDER_COLOR || "rgb(82,146,247)",
fillColor: "transparent",
borderWidth: 1,
lineDash: [4, 4]
}), this.drawBorder({
xArr: this.ctx.autofill.xArr,
yArr: this.ctx.autofill.yArr,
borderColor: this.ctx.config.SELECT_BORDER_COLOR || "rgb(82,146,247)",
fillColor: "transparent",
borderWidth: 1,
lineDash: [4, 4]
}), this.drawBorder({
xArr: i,
yArr: s,
borderColor: this.ctx.config.SELECT_BORDER_COLOR || "rgb(82,146,247)",
fillColor: "transparent",
borderWidth: 1
});
const [l, a] = i, [h, d] = s;
!(l === a && h === d) && this.colIndex >= l && this.colIndex <= a && this.rowIndex >= h && this.rowIndex <= d && this.ctx.paint.drawRect(this.drawX, this.drawY, this.width, this.height, {
borderColor: "transparent",
fillColor: this.ctx.config.SELECT_AREA_COLOR || "rgba(82,146,247,0.1)"
}), this.operation && this.rowIndex >= h && this.rowIndex <= d && this.ctx.paint.drawRect(this.drawX, this.drawY, this.visibleWidth, this.visibleHeight, {
borderColor: "transparent",
fillColor: this.ctx.config.SELECT_ROW_COL_BG_COLOR || "transparent"
});
}
drawErrorTip() {
if (this.cellType === "footer" || !this.message || this.rowspan === 0 || this.colspan === 0)
return;
const { ERROR_TIP_ICON_SIZE: e, ERROR_TIP_COLOR: i } = this.ctx.config, { width: s } = this, o = this.drawX, r = this.drawY, l = [
o + s - e - 0.5,
r,
o + s - 0.5,
r,
o + s - 0.5,
r + e
];
this.ctx.paint.drawLine(l, {
borderColor: i,
fillColor: i,
borderWidth: 1,
lineCap: "round",
lineJoin: "round"
});
}
drawBorder(e) {
const { drawX: i, drawY: s, rowIndex: o, colIndex: r, height: l, width: a } = this;
let h = i, d = s;
const { xArr: f, yArr: x, lineDash: u = [], borderWidth: p = 1, borderColor: g, fillColor: w } = e, E = f[0], y = f[1], m = x[0], R = x[1];
if (r >= E && r <= y && o === m) {
const C = r === y ? 1 : 0, v = r === E ? 1 : 0;
this.ctx.paint.drawLine([h + v, d + 1, h + a - C, d + 1], {
borderColor: g,
fillColor: w,
borderWidth: p,
lineCap: "round",
lineJoin: "round",
lineDash: u
});
}
if (r === y && o >= m && o <= R) {
const C = o === m ? 1 : 0, v = o === R ? 1 : 0;
this.ctx.paint.drawLine([h + a - 1, d + C, h + a - 1, d + l - v], {
borderColor: g,
fillColor: w,
borderWidth: p,
lineCap: "round",
lineJoin: "round",
lineDash: u
});
}
if (r >= E && r <= y && o === R) {
const C = r === y ? 1 : 0, v = r === E ? 1 : 0;
this.ctx.paint.drawLine([h + v, d + l - 1, h + a - C, d + l - 1], {
borderColor: g,
fillColor: w,
borderWidth: p,
lineCap: "round",
lineJoin: "round",
lineDash: u
});
}
if (r === E && o >= m && o <= R) {
const C = o === R ? 1 : 0, v = o === m ? 1 : 0;
this.ctx.paint.drawLine([h + 1, d + v, h + 1, d + l - C], {
borderColor: g,
fillColor: w,
borderWidth: p,
lineCap: "round",
lineJoin: "round",
lineDash: u
});
}
}
}
class ae {
//虚拟滚动位置
constructor(t, e) {
n(this, "loading", !1);
n(this, "ctx");
n(this, "data");
n(this, "columns");
n(this, "footerData", []);
n(this, "rowKeyMap", /* @__PURE__ */ new Map());
n(this, "colIndexKeyMap", /* @__PURE__ */ new Map());
n(this, "headerMap", /* @__PURE__ */ new Map());
n(this, "rowIndexRowKeyMap", /* @__PURE__ */ new Map());
n(this, "rowKeyRowIndexMap", /* @__PURE__ */ new Map());
n(this, "checkboxKeyMap", /* @__PURE__ */ new Map());
n(this, "selectionMap", /* @__PURE__ */ new Map());
n(this, "expandMap", /* @__PURE__ */ new Map());
n(this, "originalDataMap", /* @__PURE__ */ new Map());
n(this, "changedDataMap", /* @__PURE__ */ new Map());
n(this, "validationErrorMap", /* @__PURE__ */ new Map());
n(this, "itemRowKeyMap", /* @__PURE__ */ new WeakMap());
n(this, "bufferData", []);
n(this, "bufferCheckState", {
buffer: !1,
check: !1,
indeterminate: !1,
selectable: !0
});
n(this, "sumHeight", 0);
n(this, "filterMethod");
n(this, "positions", []);
this.ctx = t;
const { data: i = [], columns: s = [], footerData: o = [] } = e;
this.data = i, this.footerData = o, this.columns = s, this.setLoading(!0), this.init();
}
// 初始化默认不忽略清空改变值和校验map
init(t = !0) {
this.clearBufferData(), this.rowKeyMap.clear(), this.checkboxKeyMap.clear(), this.colIndexKeyMap.clear(), this.rowIndexRowKeyMap.clear(), this.rowKeyRowIndexMap.clear();
const e = this.getColumns(), i = et(e);
if (this.ctx.hasSelection = i.some((s) => s.type === "selection"), this.ctx.hasTree = i.some((s) => s.type === "tree"), t) {
this.originalDataMap.clear(), this.changedDataMap.clear(), this.validationErrorMap.clear();
const { ROW_KEY: s } = this.ctx.config;
s ? (this.ctx.hasSelection || this.selectionMap.clear(), this.ctx.hasTree || this.expandMap.clear()) : (this.selectionMap.clear(), this.expandMap.clear());
}
this.itemRowKeyMap = /* @__PURE__ */ new WeakMap(), this.initData(this.data), this.getData(), this.bufferCheckState.buffer = !1;
}
/**
* 清除缓存数据
*/
clearBufferData() {
this.bufferData = [];
}
/**
* 初始化数据
* @param dataList
* @param level
*/
initData(t, e = 0, i = []) {
t.forEach((s, o) => {
var E;
const { ROW_KEY: r = "", DEFAULT_EXPAND_ALL: l, CELL_HEIGHT: a, SELECTABLE_METHOD: h, CHECKBOX_KEY: d } = this.ctx.config, f = s[r], x = f != null ? `${f}` : St();
this.itemRowKeyMap.set(s, x);
const u = s._height || a, p = s._readonly;
let g = !0;
if (typeof h == "function" && (g = h), d) {
const y = s[d];
if (this.checkboxKeyMap.has(y)) {
const m = this.checkboxKeyMap.get(y) || [];
m.push(x), this.checkboxKeyMap.set(y, m);
} else
this.checkboxKeyMap.set(y, [x]);
}
this.selectionMap.set(x, {
key: d ? s[d] : x,
row: s,
check: ((E = this.selectionMap.get(x)) == null ? void 0 : E.check) || !1
});
const w = l || this.expandMap.get(x) || s._expand || !1;
this.expandMap.set(x, w), this.rowKeyMap.set(x, {
readonly: p,
index: o,
rowIndex: o,
level: e,
height: u,
check: !1,
selectable: g,
expand: w,
expandLazy: !1,
hasChildren: s._hasChildren || (Array.isArray(s.children) ? s.children.length > 0 : !1),
expandLoading: !1,
item: s,
parentRowKeys: i
}), Array.isArray(s.children) && s.children.length && this.initData(s.children, e + 1, [...i, x]);
});
}
/**
*
* @param rowKey 设置Row高度
* @param height
*/
setRowHeight(t, e) {
const i = this.rowIndexRowKeyMap.get(t);
if (i === void 0)
return;
const s = this.rowKeyMap.get(i);
s.height = e, s.item._height = e, this.clearBufferData();
}
/**
*
* @returns 获取转化平铺数据
*/
getAllRowsData() {
let t = [];
const e = (i) => {
i.forEach((s) => {
t.push(s), Array.isArray(s.children) && e(s.children);
});
};
return e(this.data), t;
}
filterColumns(t) {
return t.reduce((e, i) => {
if (!(typeof i.hide == "function" ? i.hide() : i.hide)) {
const o = { ...i };
o.children && Array.isArray(o.children) && (o.children = this.filterColumns(o.children)), e.push(o);
}
return e;
}, []);
}
getColumns() {
return this.filterColumns(this.columns);
}
setColumns(t) {
this.columns = t, this.clearBufferData();
}
setData(t) {
this.data = t, this.columns.length && this.init();
}
/**
* 统一转化数据,给画body使用,包括过滤树状等,统一入口
* @returns
*/
getData() {
if (this.bufferData.length > 0)
return {
data: this.bufferData,
sumHeight: this.sumHeight,
positions: this.positions
};
let t = [], e = 0;
this.sumHeight = 0, this.positions = [];
const i = (o) => {
o.forEach((r) => {
t.push(r);
const l = this.itemRowKeyMap.get(r), { expand: a, hasChildren: h, height: d } = this.rowKeyMap.get(l), f = this.sumHeight;
this.sumHeight += d, this.rowIndexRowKeyMap.set(e, l), this.rowKeyRowIndexMap.set(l, e), this.positions.push({
top: f,
height: d,
bottom: this.sumHeight
}), e += 1, a && h && i(r.children);
});
};
this.rowIndexRowKeyMap.clear(), this.rowKeyRowIndexMap.clear();
let s = this.data;
return typeof this.filterMethod == "function" && (s = this.filterMethod(s)), i(s), this.bufferData = t, {
data: t,
sumHeight: this.sumHeight,
positions: this.positions
};
}
setFooterData(t) {
this.footerData = t;
}
getFooterData() {
return this.footerData;
}
/**
* 设置过滤方法
*/
setFilterMethod(t) {
this.filterMethod = t;
}
/**
* 清空过滤方法
*/
clearFilterMethod() {
this.filterMethod = void 0;
}
/**
* 根据rowKey,控制指定展开行
* @param rowKey
* @param expand
*/
expandItem(t, e = !1) {
const i = this.rowKeyMap.get(t);
i.expand = e, this.expandMap.set(t, e), this.clearBufferData(), this.ctx.emit("draw");
}
setExpandRowKeys(t, e = !0) {
this.expandMap.clear(), t.forEach((i) => {
const s = this.rowKeyMap.get(i);
this.expandMap.set(i, e), s.expand = e;
}), this.clearBufferData(), this.ctx.emit("draw");
}
getExpandRowKeys() {
let t = [];
return this.rowKeyMap.forEach((e, i) => {
e.expand && t.push(i);
}), t;
}
expandAll(t) {
this.expandMap.clear(), this.rowKeyMap.forEach((e) => {
e.expand = t, this.expandMap.set(e.key, t);
}), this.clearBufferData(), this.ctx.emit("draw");
}
expandLoading(t, e = !1) {
const i = this.rowKeyMap.get(t);
i.expandLoading = e, this.clearBufferData(), this.ctx.emit("draw");
}
setExpandChildren(t, e) {
const i = this.rowKeyMap.get(t);
i.expand = !0, this.expandMap.set(t, !0), i.expandLazy = !0, i.item.children = e, this.initData(i.item.children, i.level + 1), this.clearBufferData();
}
getIsExpandLoading(t) {
return this.rowKeyMap.get(t).expandLoading;
}
getIsExpandLazy(t) {
return this.rowKeyMap.get(t).expandLazy;
}
/**
* 根据rowKey获取是否展开
* @param rowKey
* @returns
*/
getIsExpand(t) {
return this.rowKeyMap.get(t).expand;
}
/**
* 根据rowKey获取行数据
* @param rowKey
* @returns
*/
getRowForRowKey(t) {
return this.rowKeyMap.get(t);
}
getRowForRowIndex(t) {
const e = this.getRowKeyForRowIndex(t);
return this.rowKeyMap.get(e);
}
/**
* 根据rowIndex获取rowKey
* @param rowKey
* @returns
*/
getRowKeyForRowIndex(t) {
return this.rowIndexRowKeyMap.get(t) || "";
}
getRowKeyByItem(t) {
return this.itemRowKeyMap.get(t);
}
getRowIndexForRowKey(t) {
return this.rowKeyRowIndexMap.get(t);
}
/**
* 根据rowIndex和colIndex获取单元格数据
* @param rowIndex
* @param colIndex
* @returns
*/
getItemValueForRowIndexAndColIndex(t, e) {
if (!(this.rowIndexRowKeyMap.has(t) && this.colIndexKeyMap.get(e)))
return null;
const s = this.rowIndexRowKeyMap.get(t), o = this.colIndexKeyMap.get(e);
return s === void 0 || o === void 0 ? null : {
rowKey: s,
key: o,
value: this.getItemValue(s, o)
};
}
/**
* 根据rowKey和key获取单元格数据
* @param rowKey
* @param key
* @returns
*/
getItemValue(t, e) {
const i = this.rowKeyMap.get(t);
return i && i.item ? i.item[e] === void 0 ? null : i.item[e] : null;
}
/**
* 批量设置数据
* @param list
* @param history
* @returns
*/
async batchSetItemValue(t, e = !1, i = !0, s = "none") {
let o = [], r = i;
const l = /* @__PURE__ */ new Set();
let a = [], h = t.map((u) => {
const { rowKey: p, key: g } = u;
let w = u.value, E = w;
const y = this.getRowDataItemForRowKey(p), m = this.getItemValue(p, g), R = this.getVirtualBodyCellByKey(p, g);
return (R == null ? void 0 : R.type) === "number" && (["", void 0, null].includes(w) ? E = null : /^-?\d+(\.\d+)?$/.test(`${w}`) ? E = Number(w) : (E = m, a.push({
...u,
value: E,
oldValue: m,
row: y
}))), {
...u,
value: E,
oldValue: m,
row: y
};
});
if (h = h.filter((u) => !a.some((p) => u.rowKey === p.rowKey && u.key === p.key)), a.length) {
const u = {
code: "ERR_BATCH_SET_NUMBER_VALUE",
message: "Assignment failed, not a numeric type",
data: a
};
this.ctx.emit("error", u);
}
if (!h.length)
return;
const { BEFORE_VALUE_CHANGE_METHOD: d } = this.ctx.config;
s === "none" && typeof d == "function" && (h = await d(h), r = !1), h.forEach((u) => {
const { value: p, rowKey: g, key: w } = u, E = this.getItemValue(g, w);
l.add(g), this.setItemValue(g, w, p, !1, !1, !1, r), o.push({
rowKey: g,
key: w,
oldValue: E,
newValue: p
});
});
let f = [];
l.forEach((u) => {
f.push(this.ctx.database.getRowDataItemForRowKey(u));
});
const x = h.map(({ rowKey: u, key: p }) => this.getValidator(u, p));
Promise.all(x).then(() => {
this.validationErrorMap.size === 0 && this.changedDataMap.size > 0 && this.ctx.emit("validateChangedData", this.getChangedData());
}), this.ctx.emit("change", h, f), e && this.ctx.history.pushState({
changeList: o,
scrollX: this.ctx.scrollX,
scrollY: this.ctx.scrollY,
type: "multiple"
}), this.ctx.emit("draw");
}
/**
*设置单一数据
* @param rowKey
* @param key
* @param value
* @param history 是否添加历史记录
* @param reDraw 是否刷新重绘
* @param isEditor 是否是编辑器
* @param checkReadonly 是否检查只读
* @returns
*/
async setItemValue(t, e, i, s = !1, o = !1, r = !1, l = !0) {
if (!this.rowKeyMap.has(t))
return {};
const { item: a } = this.rowKeyMap.get(t);
let h = a[e], d = i;
if (l && this.ctx.database.getReadonly(t, e))
return {
oldValue: h,
newValue: h
};
a[e] !== null && typeof a[e] == "object" && (h = JSON.parse(JSON.stringify(a[e])));
const f = `${t}_${e}`;
this.originalDataMap.has(f) || this.originalDataMap.set(f, h);
const x = this.originalDataMap.get(f), u = this.getRowDataItemForRowKey(t);
if (r) {
const p = this.getVirtualBodyCellByKey(t, e);
if ((p == null ? void 0 : p.type) === "number")
if (["", void 0, null].includes(i))
d = null;
else if (/^-?\d+(\.\d+)?$/.test(`${i}`))
d = Number(i);
else {
d = h;
const w = {
code: "ERR_SET_NUMBER_VALUE",
message: "Assignment failed, not a numeric type",
data: [
{
rowKey: t,
key: e,
value: d,
oldValue: h,
row: u
}
]
};
this.ctx.emit("error", w);
}
if (d === h)
return {
oldValue: h,
newValue: h
};
let g = [
{
rowKey: t,
key: e,
value: d,
oldValue: h,
row: u
}
];
this.batchSetItemValue(g, s, !1), this.ctx.emit("editChange", {
rowKey: t,
key: e,
oldValue: h,
value: d,
originalValue: x,
row: u
});
} else
this.changedDataMap.set(f, d), a[e] = d;
return this.ctx.hasEvent("iterationChange") && this.ctx.emit("iterationChange", {
rowKey: t,
key: e,
oldValue: h,
value: d,
originalValue: this.originalDataMap.get(f),
row: u
}), o && this.ctx.emit("draw"), {
oldValue: h,
newValue: d
};
}
/**
* 根据rowKey 获取行数据
* @param rowKey
* @returns
*/
getRowDataItemForRowKey(t) {
if (!this.rowKeyMap.has(t))
return {};
const { item: e } = this.rowKeyMap.get(t);
return e;
}
/**
*
* @param rowKey 设置选中状态ByCheckboxKey,用于合并Checkbox单元格时声明唯一key
* @param check
*/
setRowSelectionByCheckboxKey(t, e) {
const { CHECKBOX_KEY: i } = this.ctx.config;
if (i) {
if (!this.rowKeyMap.has(t))
return !1;
const { item: s } = this.rowKeyMap.get(t), o = s[i];
this.checkboxKeyMap.has(o) && (this.checkboxKeyMap.get(o) || []).forEach((l) => {
const a = this.selectionMap.get(l);
a && (a.check = e);
});
}
}
/**
* 根据rowKey 取反选中
* @param rowKey
*/
toggleRowSelection(t) {
const e = this.rowKeyMap.get(t), i = this.selectionMap.get(t);
if (!i)
return;
i.check = !i.check, this.setRowSelectionByCheckboxKey(t, i.check), this.ctx.emit("toggleRowSelection", e);
const s = this.getSelectionRows();
this.ctx.emit("selectionChange", s), this.bufferCheckState.buffer = !1, this.ctx.emit("draw");
}
/**
* 根据rowKey 设置选中状态
* @param rowKey
*/
setRowSelection(t, e, i = !0) {
const s = this.selectionMap.get(t);
s && (s.check = e, this.setRowSelectionByCheckboxKey(t, s.check), this.ctx.emit("setRowSelection", e, s.row), i && (this.bufferCheckState.buffer = !1, this.ctx.emit("draw")));
}
getSelectionRows() {
let t = [];
return this.selectionMap.forEach((e) => {
e.check && t.push(e.row);
}), t;
}
/**
* 根据rowKey 获取选中状态
* @param rowKey
*/
getRowSelection(t) {
const e = this.selectionMap.get(t);
return e ? e.check : !1;
}
/**
* 根据rowKey 获取选中状态
* @param rowKey
*/
getRowSelectable(t) {
const { selectable: e, item: i, rowIndex: s } = this.rowKeyMap.get(t);
return typeof e == "function" ? e({
row: i,
rowIndex: s
}) : e;
}
/**
* 全选
* @param rowKey
*/
toggleAllSelection() {
this.rowKeyMap.forEach((e, i) => {
let s = e.selectable;
typeof s == "function" && (s = s({
row: e.item,
rowIndex: e.rowIndex
})), s && this.setRowSelection(i, !0, !1);
});
const t = this.getSelectionRows();
this.ctx.emit("toggleAllSelection", t), this.ctx.emit("selectionChange", t), this.bufferCheckState.buffer = !1, this.ctx.emit("draw");
}
/**
* 清除选中
* @param rowKey
*/
clearSelection(t = !1) {
t ? this.rowKeyMap.forEach((i, s) => {
this.setRowSelection(s, !1, !1);
}) : (this.selectionMap.clear(), this.rowKeyMap.forEach((i, s) => {
this.selectionMap.set(s, {
check: !1,
row: i.item,
key: s
});
}));
const e = this.getSelectionRows();
this.ctx.emit("clearSelection"), this.ctx.emit("selectionChange", e), this.bufferCheckState.buffer = !1, this.ctx.emit("draw");
}
/**
* 获取选中状态,表头用
* @param rowKey
*/
getCheckedState() {
const { buffer: t, ...e } = this.bufferCheckState;
if (t)
return e;
const i = this.rowKeyMap.size;
let s = 0, o = 0;
const r = this.selectionMap.size, l = Array.from(this.selectionMap.values()).some((x) => x.check);
this.rowKeyMap.forEach((x, u) => {
var g;
(g = this.selectionMap.get(u)) != null && g.check && (s += 1);
let p = x.selectable;
typeof p == "function" && (p = p({
row: x.item,
rowIndex: x.rowIndex
})), p && (o += 1);
});
const a = r > i && s === 0 && l, h = o && o > s && s > 0 || a, d = o !== 0, f = !!o && o === s;
return this.bufferCheckState = {
buffer: !0,
check: f,
indeterminate: h,
selectable: d
}, {
check: f,
indeterminate: h,
selectable: d
};
}
/**
* 更新列索引
* @param list 表头末级列表
*/
updateColIndexKeyMap(t = []) {
this.colIndexKeyMap.clear(), t.forEach((e) => {
this.colIndexKeyMap.set(e.colIndex, e.key);
});
}
getColumnByColIndex(t) {
var i;
const e = this.colIndexKeyMap.get(t);
if (e && this.headerMap.has(e))
return (i = this.headerMap.get(e)) == null ? void 0 : i.column;
}
getColumnByKey(t) {
const