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,311 lines (1,310 loc) • 230 kB
JavaScript
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(":root{--e-virt-table-color-white: #fff;--e-virt-table-color-black: #000000;--e-virt-table-color-primary: rgb(82, 146, 247);--e-virt-table-text-color-primary: #333;--e-virt-table-text-color-regular: #666;--e-virt-table-text-color-secondary: #999;--e-virt-table-box-shadow: 0 2px 12px 0 #0000001a;--e-virt-table-editor-bg-color: #fff;--e-virt-table-border-color: #e1e6eb}.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(--e-virt-table-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(--e-virt-table-editor-bg-color);border:2px solid var(--e-virt-table-color-primary);box-sizing:border-box;box-shadow:var(--e-virt-table-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(--e-virt-table-color-white);overflow-y:auto;resize:none}.e-virt-table-context-menu{position:absolute;font-size:14px;color:var(--e-virt-table-text-color-regular);background-color:var(--e-virt-table-color-white);border-radius:4px;border:1px solid #e4e7ed;box-shadow:var(--e-virt-table-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(--e-virt-table-text-color-regular)}.e-virt-table-context-menu-item:hover{color:var(--e-virt-table-color-primary);background-color:#f5f7fa}")),document.head.appendChild(e)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})();
var Ce = Object.defineProperty;
var be = (a, t, e) => t in a ? Ce(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
var l = (a, t, e) => be(a, typeof t != "symbol" ? t + "" : t, e);
function q() {
return q = Object.assign ? Object.assign.bind() : function(a) {
for (var t = 1; t < arguments.length; t++) {
var e = arguments[t];
for (var i in e)
Object.prototype.hasOwnProperty.call(e, i) && (a[i] = e[i]);
}
return a;
}, q.apply(this, arguments);
}
function ve(a, t) {
a.prototype = Object.create(t.prototype), a.prototype.constructor = a, st(a, t);
}
function mt(a) {
return mt = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(e) {
return e.__proto__ || Object.getPrototypeOf(e);
}, mt(a);
}
function st(a, t) {
return st = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(i, s) {
return i.__proto__ = s, i;
}, st(a, t);
}
function Re() {
if (typeof Reflect > "u" || !Reflect.construct || Reflect.construct.sham) return !1;
if (typeof Proxy == "function") return !0;
try {
return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
})), !0;
} catch {
return !1;
}
}
function dt(a, t, e) {
return Re() ? dt = Reflect.construct.bind() : dt = function(s, r, o) {
var n = [null];
n.push.apply(n, r);
var h = Function.bind.apply(s, n), c = new h();
return o && st(c, o.prototype), c;
}, dt.apply(null, arguments);
}
function Ie(a) {
return Function.toString.call(a).indexOf("[native code]") !== -1;
}
function Ct(a) {
var t = typeof Map == "function" ? /* @__PURE__ */ new Map() : void 0;
return Ct = function(i) {
if (i === null || !Ie(i)) return i;
if (typeof i != "function")
throw new TypeError("Super expression must either be null or a function");
if (typeof t < "u") {
if (t.has(i)) return t.get(i);
t.set(i, s);
}
function s() {
return dt(i, arguments, mt(this).constructor);
}
return s.prototype = Object.create(i.prototype, {
constructor: {
value: s,
enumerable: !1,
writable: !0,
configurable: !0
}
}), st(s, i);
}, Ct(a);
}
var _e = /%[sdj%]/g, jt = function() {
};
typeof process < "u" && process.env && process.env.NODE_ENV !== "production" && typeof window < "u" && typeof document < "u" && (jt = function(t, e) {
typeof console < "u" && console.warn && typeof ASYNC_VALIDATOR_NO_WARNING > "u" && e.every(function(i) {
return typeof i == "string";
}) && console.warn(t, e);
});
function bt(a) {
if (!a || !a.length) return null;
var t = {};
return a.forEach(function(e) {
var i = e.field;
t[i] = t[i] || [], t[i].push(e);
}), t;
}
function D(a) {
for (var t = arguments.length, e = new Array(t > 1 ? t - 1 : 0), i = 1; i < t; i++)
e[i - 1] = arguments[i];
var s = 0, r = e.length;
if (typeof a == "function")
return a.apply(null, e);
if (typeof a == "string") {
var o = a.replace(_e, function(n) {
if (n === "%%")
return "%";
if (s >= r)
return n;
switch (n) {
case "%s":
return String(e[s++]);
case "%d":
return Number(e[s++]);
case "%j":
try {
return JSON.stringify(e[s++]);
} catch {
return "[Circular]";
}
break;
default:
return n;
}
});
return o;
}
return a;
}
function Oe(a) {
return a === "string" || a === "url" || a === "hex" || a === "email" || a === "date" || a === "pattern";
}
function H(a, t) {
return !!(a == null || t === "array" && Array.isArray(a) && !a.length || Oe(t) && typeof a == "string" && !a);
}
function Ae(a, t, e) {
var i = [], s = 0, r = a.length;
function o(n) {
i.push.apply(i, n || []), s++, s === r && e(i);
}
a.forEach(function(n) {
t(n, o);
});
}
function kt(a, t, e) {
var i = 0, s = a.length;
function r(o) {
if (o && o.length) {
e(o);
return;
}
var n = i;
i = i + 1, n < s ? t(a[n], r) : e([]);
}
r([]);
}
function Le(a) {
var t = [];
return Object.keys(a).forEach(function(e) {
t.push.apply(t, a[e] || []);
}), t;
}
var Xt = /* @__PURE__ */ function(a) {
ve(t, a);
function t(e, i) {
var s;
return s = a.call(this, "Async Validation Error") || this, s.errors = e, s.fields = i, s;
}
return t;
}(/* @__PURE__ */ Ct(Error));
function Se(a, t, e, i, s) {
if (t.first) {
var r = new Promise(function(u, x) {
var p = function(y) {
return i(y), y.length ? x(new Xt(y, bt(y))) : u(s);
}, g = Le(a);
kt(g, e, p);
});
return r.catch(function(u) {
return u;
}), r;
}
var o = t.firstFields === !0 ? Object.keys(a) : t.firstFields || [], n = Object.keys(a), h = n.length, c = 0, d = [], f = new Promise(function(u, x) {
var p = function(w) {
if (d.push.apply(d, w), c++, c === h)
return i(d), d.length ? x(new Xt(d, bt(d))) : u(s);
};
n.length || (i(d), u(s)), n.forEach(function(g) {
var w = a[g];
o.indexOf(g) !== -1 ? kt(w, e, p) : Ae(w, e, p);
});
});
return f.catch(function(u) {
return u;
}), f;
}
function Te(a) {
return !!(a && a.message !== void 0);
}
function Me(a, t) {
for (var e = a, i = 0; i < t.length; i++) {
if (e == null)
return e;
e = e[t[i]];
}
return e;
}
function Nt(a, t) {
return function(e) {
var i;
return a.fullFields ? i = Me(t, a.fullFields) : i = t[e.field || a.fullField], Te(e) ? (e.field = e.field || a.fullField, e.fieldValue = i, e) : {
message: typeof e == "function" ? e() : e,
fieldValue: i,
field: e.field || a.fullField
};
};
}
function Kt(a, t) {
if (t) {
for (var e in t)
if (t.hasOwnProperty(e)) {
var i = t[e];
typeof i == "object" && typeof a[e] == "object" ? a[e] = q({}, a[e], i) : a[e] = i;
}
}
return a;
}
var Ut = function(t, e, i, s, r, o) {
t.required && (!i.hasOwnProperty(t.field) || H(e, o || t.type)) && s.push(D(r.messages.required, t.fullField));
}, He = function(t, e, i, s, r) {
(/^\s+$/.test(e) || e === "") && s.push(D(r.messages.whitespace, t.fullField));
}, ct, De = function() {
if (ct)
return ct;
var a = "[a-fA-F\\d:]", t = function(C) {
return C && C.includeBoundaries ? "(?:(?<=\\s|^)(?=" + a + ")|(?<=" + a + ")(?=\\s|$))" : "";
}, e = "(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}", i = "[a-fA-F\\d]{1,4}", s = (`
(?:
(?:` + i + ":){7}(?:" + i + `|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
(?:` + i + ":){6}(?:" + e + "|:" + i + `|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
(?:` + i + ":){5}(?::" + e + "|(?::" + i + `){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
(?:` + i + ":){4}(?:(?::" + i + "){0,1}:" + e + "|(?::" + i + `){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
(?:` + i + ":){3}(?:(?::" + i + "){0,2}:" + e + "|(?::" + i + `){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
(?:` + i + ":){2}(?:(?::" + i + "){0,3}:" + e + "|(?::" + i + `){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
(?:` + i + ":){1}(?:(?::" + i + "){0,4}:" + e + "|(?::" + i + `){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
(?::(?:(?::` + i + "){0,5}:" + e + "|(?::" + i + `){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
`).replace(/\s*\/\/.*$/gm, "").replace(/\n/g, "").trim(), r = new RegExp("(?:^" + e + "$)|(?:^" + s + "$)"), o = new RegExp("^" + e + "$"), n = new RegExp("^" + s + "$"), h = function(C) {
return C && C.exact ? r : new RegExp("(?:" + t(C) + e + t(C) + ")|(?:" + t(C) + s + t(C) + ")", "g");
};
h.v4 = function(E) {
return E && E.exact ? o : new RegExp("" + t(E) + e + t(E), "g");
}, h.v6 = function(E) {
return E && E.exact ? n : new RegExp("" + t(E) + s + t(E), "g");
};
var c = "(?:(?:[a-z]+:)?//)", d = "(?:\\S+(?::\\S*)?@)?", f = h.v4().source, u = h.v6().source, x = "(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)", p = "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*", g = "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))", w = "(?::\\d{2,5})?", y = '(?:[/?#][^\\s"]*)?', m = "(?:" + c + "|www\\.)" + d + "(?:localhost|" + f + "|" + u + "|" + x + p + g + ")" + w + y;
return ct = new RegExp("(?:^" + m + "$)", "i"), ct;
}, Bt = {
// http://emailregex.com/
email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+\.)+[a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}))$/,
// url: new RegExp(
// '^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$',
// 'i',
// ),
hex: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/i
}, et = {
integer: function(t) {
return et.number(t) && parseInt(t, 10) === t;
},
float: function(t) {
return et.number(t) && !et.integer(t);
},
array: function(t) {
return Array.isArray(t);
},
regexp: function(t) {
if (t instanceof RegExp)
return !0;
try {
return !!new RegExp(t);
} catch {
return !1;
}
},
date: function(t) {
return typeof t.getTime == "function" && typeof t.getMonth == "function" && typeof t.getYear == "function" && !isNaN(t.getTime());
},
number: function(t) {
return isNaN(t) ? !1 : typeof t == "number";
},
object: function(t) {
return typeof t == "object" && !et.array(t);
},
method: function(t) {
return typeof t == "function";
},
email: function(t) {
return typeof t == "string" && t.length <= 320 && !!t.match(Bt.email);
},
url: function(t) {
return typeof t == "string" && t.length <= 2048 && !!t.match(De());
},
hex: function(t) {
return typeof t == "string" && !!t.match(Bt.hex);
}
}, Fe = function(t, e, i, s, r) {
if (t.required && e === void 0) {
Ut(t, e, i, s, r);
return;
}
var o = ["integer", "float", "array", "regexp", "object", "method", "email", "number", "date", "url", "hex"], n = t.type;
o.indexOf(n) > -1 ? et[n](e) || s.push(D(r.messages.types[n], t.fullField, t.type)) : n && typeof e !== t.type && s.push(D(r.messages.types[n], t.fullField, t.type));
}, ke = function(t, e, i, s, r) {
var o = typeof t.len == "number", n = typeof t.min == "number", h = typeof t.max == "number", c = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, d = e, f = null, u = typeof e == "number", x = typeof e == "string", p = Array.isArray(e);
if (u ? f = "number" : x ? f = "string" : p && (f = "array"), !f)
return !1;
p && (d = e.length), x && (d = e.replace(c, "_").length), o ? d !== t.len && s.push(D(r.messages[f].len, t.fullField, t.len)) : n && !h && d < t.min ? s.push(D(r.messages[f].min, t.fullField, t.min)) : h && !n && d > t.max ? s.push(D(r.messages[f].max, t.fullField, t.max)) : n && h && (d < t.min || d > t.max) && s.push(D(r.messages[f].range, t.fullField, t.min, t.max));
}, j = "enum", Xe = function(t, e, i, s, r) {
t[j] = Array.isArray(t[j]) ? t[j] : [], t[j].indexOf(e) === -1 && s.push(D(r.messages[j], t.fullField, t[j].join(", ")));
}, Ne = function(t, e, i, s, r) {
if (t.pattern) {
if (t.pattern instanceof RegExp)
t.pattern.lastIndex = 0, t.pattern.test(e) || s.push(D(r.messages.pattern.mismatch, t.fullField, e, t.pattern));
else if (typeof t.pattern == "string") {
var o = new RegExp(t.pattern);
o.test(e) || s.push(D(r.messages.pattern.mismatch, t.fullField, e, t.pattern));
}
}
}, _ = {
required: Ut,
whitespace: He,
type: Fe,
range: ke,
enum: Xe,
pattern: Ne
}, Ke = function(t, e, i, s, r) {
var o = [], n = t.required || !t.required && s.hasOwnProperty(t.field);
if (n) {
if (H(e, "string") && !t.required)
return i();
_.required(t, e, s, o, r, "string"), H(e, "string") || (_.type(t, e, s, o, r), _.range(t, e, s, o, r), _.pattern(t, e, s, o, r), t.whitespace === !0 && _.whitespace(t, e, s, o, r));
}
i(o);
}, Be = function(t, e, i, s, r) {
var o = [], n = t.required || !t.required && s.hasOwnProperty(t.field);
if (n) {
if (H(e) && !t.required)
return i();
_.required(t, e, s, o, r), e !== void 0 && _.type(t, e, s, o, r);
}
i(o);
}, Ye = function(t, e, i, s, r) {
var o = [], n = t.required || !t.required && s.hasOwnProperty(t.field);
if (n) {
if (e === "" && (e = void 0), H(e) && !t.required)
return i();
_.required(t, e, s, o, r), e !== void 0 && (_.type(t, e, s, o, r), _.range(t, e, s, o, r));
}
i(o);
}, Ve = function(t, e, i, s, r) {
var o = [], n = t.required || !t.required && s.hasOwnProperty(t.field);
if (n) {
if (H(e) && !t.required)
return i();
_.required(t, e, s, o, r), e !== void 0 && _.type(t, e, s, o, r);
}
i(o);
}, We = function(t, e, i, s, r) {
var o = [], n = t.required || !t.required && s.hasOwnProperty(t.field);
if (n) {
if (H(e) && !t.required)
return i();
_.required(t, e, s, o, r), H(e) || _.type(t, e, s, o, r);
}
i(o);
}, Pe = function(t, e, i, s, r) {
var o = [], n = t.required || !t.required && s.hasOwnProperty(t.field);
if (n) {
if (H(e) && !t.required)
return i();
_.required(t, e, s, o, r), e !== void 0 && (_.type(t, e, s, o, r), _.range(t, e, s, o, r));
}
i(o);
}, ze = function(t, e, i, s, r) {
var o = [], n = t.required || !t.required && s.hasOwnProperty(t.field);
if (n) {
if (H(e) && !t.required)
return i();
_.required(t, e, s, o, r), e !== void 0 && (_.type(t, e, s, o, r), _.range(t, e, s, o, r));
}
i(o);
}, $e = function(t, e, i, s, r) {
var o = [], n = t.required || !t.required && s.hasOwnProperty(t.field);
if (n) {
if (e == null && !t.required)
return i();
_.required(t, e, s, o, r, "array"), e != null && (_.type(t, e, s, o, r), _.range(t, e, s, o, r));
}
i(o);
}, qe = function(t, e, i, s, r) {
var o = [], n = t.required || !t.required && s.hasOwnProperty(t.field);
if (n) {
if (H(e) && !t.required)
return i();
_.required(t, e, s, o, r), e !== void 0 && _.type(t, e, s, o, r);
}
i(o);
}, Ge = "enum", je = function(t, e, i, s, r) {
var o = [], n = t.required || !t.required && s.hasOwnProperty(t.field);
if (n) {
if (H(e) && !t.required)
return i();
_.required(t, e, s, o, r), e !== void 0 && _[Ge](t, e, s, o, r);
}
i(o);
}, Ue = function(t, e, i, s, r) {
var o = [], n = t.required || !t.required && s.hasOwnProperty(t.field);
if (n) {
if (H(e, "string") && !t.required)
return i();
_.required(t, e, s, o, r), H(e, "string") || _.pattern(t, e, s, o, r);
}
i(o);
}, Ze = function(t, e, i, s, r) {
var o = [], n = t.required || !t.required && s.hasOwnProperty(t.field);
if (n) {
if (H(e, "date") && !t.required)
return i();
if (_.required(t, e, s, o, r), !H(e, "date")) {
var h;
e instanceof Date ? h = e : h = new Date(e), _.type(t, h, s, o, r), h && _.range(t, h.getTime(), s, o, r);
}
}
i(o);
}, Je = function(t, e, i, s, r) {
var o = [], n = Array.isArray(e) ? "array" : typeof e;
_.required(t, e, s, o, r, n), i(o);
}, yt = function(t, e, i, s, r) {
var o = t.type, n = [], h = t.required || !t.required && s.hasOwnProperty(t.field);
if (h) {
if (H(e, o) && !t.required)
return i();
_.required(t, e, s, n, r, o), H(e, o) || _.type(t, e, s, n, r);
}
i(n);
}, Qe = function(t, e, i, s, r) {
var o = [], n = t.required || !t.required && s.hasOwnProperty(t.field);
if (n) {
if (H(e) && !t.required)
return i();
_.required(t, e, s, o, r);
}
i(o);
}, it = {
string: Ke,
method: Be,
number: Ye,
boolean: Ve,
regexp: We,
integer: Pe,
float: ze,
array: $e,
object: qe,
enum: je,
pattern: Ue,
date: Ze,
url: yt,
hex: yt,
email: yt,
required: Je,
any: Qe
};
function vt() {
return {
default: "Validation error on field %s",
required: "%s is required",
enum: "%s must be one of %s",
whitespace: "%s cannot be empty",
date: {
format: "%s date %s is invalid for format %s",
parse: "%s date could not be parsed, %s is invalid ",
invalid: "%s date %s is invalid"
},
types: {
string: "%s is not a %s",
method: "%s is not a %s (function)",
array: "%s is not an %s",
object: "%s is not an %s",
number: "%s is not a %s",
date: "%s is not a %s",
boolean: "%s is not a %s",
integer: "%s is not an %s",
float: "%s is not a %s",
regexp: "%s is not a valid %s",
email: "%s is not a valid %s",
url: "%s is not a valid %s",
hex: "%s is not a valid %s"
},
string: {
len: "%s must be exactly %s characters",
min: "%s must be at least %s characters",
max: "%s cannot be longer than %s characters",
range: "%s must be between %s and %s characters"
},
number: {
len: "%s must equal %s",
min: "%s cannot be less than %s",
max: "%s cannot be greater than %s",
range: "%s must be between %s and %s"
},
array: {
len: "%s must be exactly %s in length",
min: "%s cannot be less than %s in length",
max: "%s cannot be greater than %s in length",
range: "%s must be between %s and %s in length"
},
pattern: {
mismatch: "%s value %s does not match pattern %s"
},
clone: function() {
var t = JSON.parse(JSON.stringify(this));
return t.clone = this.clone, t;
}
};
}
var Rt = vt(), nt = /* @__PURE__ */ function() {
function a(e) {
this.rules = null, this._messages = Rt, this.define(e);
}
var t = a.prototype;
return t.define = function(i) {
var s = this;
if (!i)
throw new Error("Cannot configure a schema with no rules");
if (typeof i != "object" || Array.isArray(i))
throw new Error("Rules must be an object");
this.rules = {}, Object.keys(i).forEach(function(r) {
var o = i[r];
s.rules[r] = Array.isArray(o) ? o : [o];
});
}, t.messages = function(i) {
return i && (this._messages = Kt(vt(), i)), this._messages;
}, t.validate = function(i, s, r) {
var o = this;
s === void 0 && (s = {}), r === void 0 && (r = function() {
});
var n = i, h = s, c = r;
if (typeof h == "function" && (c = h, h = {}), !this.rules || Object.keys(this.rules).length === 0)
return c && c(null, n), Promise.resolve(n);
function d(g) {
var w = [], y = {};
function m(C) {
if (Array.isArray(C)) {
var b;
w = (b = w).concat.apply(b, C);
} else
w.push(C);
}
for (var E = 0; E < g.length; E++)
m(g[E]);
w.length ? (y = bt(w), c(w, y)) : c(null, n);
}
if (h.messages) {
var f = this.messages();
f === Rt && (f = vt()), Kt(f, h.messages), h.messages = f;
} else
h.messages = this.messages();
var u = {}, x = h.keys || Object.keys(this.rules);
x.forEach(function(g) {
var w = o.rules[g], y = n[g];
w.forEach(function(m) {
var E = m;
typeof E.transform == "function" && (n === i && (n = q({}, n)), y = n[g] = E.transform(y)), typeof E == "function" ? E = {
validator: E
} : E = q({}, E), E.validator = o.getValidationMethod(E), E.validator && (E.field = g, E.fullField = E.fullField || g, E.type = o.getType(E), u[g] = u[g] || [], u[g].push({
rule: E,
value: y,
source: n,
field: g
}));
});
});
var p = {};
return Se(u, h, function(g, w) {
var y = g.rule, m = (y.type === "object" || y.type === "array") && (typeof y.fields == "object" || typeof y.defaultField == "object");
m = m && (y.required || !y.required && g.value), y.field = g.field;
function E(R, A) {
return q({}, A, {
fullField: y.fullField + "." + R,
fullFields: y.fullFields ? [].concat(y.fullFields, [R]) : [R]
});
}
function C(R) {
R === void 0 && (R = []);
var A = Array.isArray(R) ? R : [R];
!h.suppressWarning && A.length && a.warning("async-validator:", A), A.length && y.message !== void 0 && (A = [].concat(y.message));
var L = A.map(Nt(y, n));
if (h.first && L.length)
return p[y.field] = 1, w(L);
if (!m)
w(L);
else {
if (y.required && !g.value)
return y.message !== void 0 ? L = [].concat(y.message).map(Nt(y, n)) : h.error && (L = [h.error(y, D(h.messages.required, y.field))]), w(L);
var I = {};
y.defaultField && Object.keys(g.value).map(function(O) {
I[O] = y.defaultField;
}), I = q({}, I, g.rule.fields);
var v = {};
Object.keys(I).forEach(function(O) {
var M = I[O], T = Array.isArray(M) ? M : [M];
v[O] = T.map(E.bind(null, O));
});
var S = new a(v);
S.messages(h.messages), g.rule.options && (g.rule.options.messages = h.messages, g.rule.options.error = h.error), S.validate(g.value, g.rule.options || h, function(O) {
var M = [];
L && L.length && M.push.apply(M, L), O && O.length && M.push.apply(M, O), w(M.length ? M : null);
});
}
}
var b;
if (y.asyncValidator)
b = y.asyncValidator(y, g.value, C, g.source, h);
else if (y.validator) {
try {
b = y.validator(y, g.value, C, g.source, h);
} catch (R) {
console.error == null || console.error(R), h.suppressValidatorError || setTimeout(function() {
throw R;
}, 0), C(R.message);
}
b === !0 ? C() : b === !1 ? C(typeof y.message == "function" ? y.message(y.fullField || y.field) : y.message || (y.fullField || y.field) + " fails") : b instanceof Array ? C(b) : b instanceof Error && C(b.message);
}
b && b.then && b.then(function() {
return C();
}, function(R) {
return C(R);
});
}, function(g) {
d(g);
}, n);
}, t.getType = function(i) {
if (i.type === void 0 && i.pattern instanceof RegExp && (i.type = "pattern"), typeof i.validator != "function" && i.type && !it.hasOwnProperty(i.type))
throw new Error(D("Unknown rule type %s", i.type));
return i.type || "string";
}, t.getValidationMethod = function(i) {
if (typeof i.validator == "function")
return i.validator;
var s = Object.keys(i), r = s.indexOf("message");
return r !== -1 && s.splice(r, 1), s.length === 1 && s[0] === "required" ? it.required : it[this.getType(i)] || void 0;
}, a;
}();
nt.register = function(t, e) {
if (typeof e != "function")
throw new Error("Cannot register a validator by type, validator is not a function");
it[t] = e;
};
nt.warning = jt;
nt.messages = Rt;
nt.validators = it;
function Zt() {
return "xxxxxxxxxxxxxxxxxx".replace(/[x]/g, function(a) {
const t = Math.random() * 16 | 0;
return (a === "x" ? t : t & 3 | 8).toString(16);
});
}
function Jt(a, t) {
let e = 0, i;
return function(...s) {
const r = (/* @__PURE__ */ new Date()).getTime(), o = r - e;
!e || o >= t ? (a.apply(this, s), e = r) : i || (i = setTimeout(() => {
a.apply(this, s), e = (/* @__PURE__ */ new Date()).getTime(), i = void 0;
}, t - o));
};
}
function Qt(a = []) {
return a.length ? a.map((t) => Qt(t.children) + 1).sort((t, e) => e - t)[0] : 0;
}
function ti(a = []) {
let t = [], e = [], i = [];
return a.forEach((s) => {
s.fixed === "left" ? t.push(s) : s.fixed === "right" ? i.push(s) : e.push(s);
}), [
...t.sort((s, r) => (s.sort ?? 0) - (r.sort ?? 0)),
...e.sort((s, r) => (s.sort ?? 0) - (r.sort ?? 0)),
...i.sort((s, r) => (s.sort ?? 0) - (r.sort ?? 0))
];
}
function te(a = [], t = 1, e = 0) {
return a.map((i) => {
if (i.children) {
let s = 0, r = i.fixed;
i.children.forEach((n) => {
n.fixed = r;
});
const o = te(i.children, t - 1, e + 1);
return o && o.forEach((n) => {
s += n.colspan ?? 0;
}), {
...i,
width: i.width,
level: e,
rowspan: 1,
colspan: s,
children: o
};
}
return {
...i,
level: e,
rowspan: t,
colspan: 1
};
});
}
function It(a = []) {
let t = [];
return a.forEach((e) => {
e.children ? t = t.concat(It(e.children)) : t.push(e);
}), t;
}
const Yt = /^(\r\n|\n\r|\r|\n)/, ei = /^[^\t\r\n]+/, Vt = /^\t/;
function ii(a) {
let t = [[""]];
if (a.length === 0)
return t;
let e = 0, i = 0, s;
for (; a.length > 0 && s !== a.length; )
if (s = a.length, a.match(Vt))
a = a.replace(Vt, ""), e += 1, t[i][e] = "";
else if (a.match(Yt))
a = a.replace(Yt, ""), e = 0, i += 1, t[i] = [""];
else {
let r = "";
if (a.startsWith('"')) {
let o = 0, n = !0;
for (; n; ) {
const h = a.slice(0, 1);
h === '"' && (o += 1), r += h, a = a.slice(1), (a.length === 0 || a.match(/^[\t\r\n]/) && o % 2 === 0) && (n = !1);
}
r = r.replace(/^"/, "").replace(/"$/, "").replace(/["]*/g, (h) => new Array(Math.floor(h.length / 2)).fill('"').join(""));
} else {
const o = a.match(ei);
r = o ? o[0] : "", a = a.slice(r.length);
}
t[i][e] = r;
}
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 si(a) {
let t, e, i, s, r = "", o;
for (t = 0, e = a.length; t < e; t += 1) {
for (s = a[t].length, i = 0; i < s; i += 1)
i > 0 && (r += " "), o = a[t][i], typeof o == "string" ? o.indexOf(`
`) > -1 ? r += `"${o.replace(/"/g, '""')}"` : r += o : o == null ? r += "" : r += o;
t !== e - 1 && (r += `
`);
}
return r;
}
function ee(a, t, e = []) {
let i = 0;
const s = [];
return a.forEach((r, o) => {
if (o === 0)
s.push(1);
else {
const n = e.reduce((c, d) => `${c}${r[d] ?? ""}`, "") || r[t], h = e.reduce((c, d) => `${c}${a[o - 1][d] ?? ""}`, "") || a[o - 1][t];
n === h ? (s[i] += 1, s.push(0)) : (s.push(1), i = o);
}
}), s;
}
function ie(a, t) {
let e = "", i = "";
const s = {};
return t.forEach((r, o) => {
o === 0 ? (e = r.key, i = r.key, s[r.key] = 1) : a[r.key] === a[e] ? (s[r.key] = 0, s[i] += 1) : (s[r.key] = 1, e = r.key, i = r.key);
}), s;
}
function ri(a, t, e = []) {
const { visibleRows: i, rowIndex: s, headIndex: r } = a, o = ee(i, t, e);
return o[s - r] === 0 ? {
rowspan: 0,
colspan: 0,
relationRowKeys: e,
mergeRow: !0
} : {
rowspan: o[s - r],
colspan: 1,
relationRowKeys: e,
mergeRow: !0
};
}
function oi(a, t = []) {
const { column: e, row: i, visibleLeafColumns: s } = a, r = s.filter((o) => t.includes(o.key));
if (t.includes(e.key)) {
const o = ie(i, r);
return o[e.key] === 0 ? {
rowspan: 0,
colspan: 0,
relationColKeys: t,
mergeCol: !0
} : {
rowspan: 1,
colspan: o[e.key],
relationColKeys: t,
mergeCol: !0
};
}
}
class se {
constructor(t, e, i, s, r, o, n) {
l(this, "ctx");
l(this, "x", 0);
l(this, "y", 0);
l(this, "width", 0);
l(this, "height", 0);
l(this, "fixed");
l(this, "cellType");
this.ctx = t, this.x = e, this.y = i, this.width = s, this.height = r, this.fixed = n, this.cellType = o;
}
isHorizontalVisible() {
if (this.fixed)
return !0;
const { stageWidth: t, fixedLeftWidth: e, scrollX: i, fixedRightWidth: s } = this.ctx, r = t;
return !(this.x + this.width - e - i <= 0 || this.x - i >= r - 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 + 1;
}
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 Tt extends se {
constructor(e, i, s, r, o, n, h, c, d, f = "body") {
super(e, r, o, n, h, f, c.fixed);
l(this, "formatter");
l(this, "formatterFooter");
l(this, "hoverIconName", "");
l(this, "operation", !1);
l(this, "align");
l(this, "verticalAlign");
l(this, "fixed");
l(this, "type");
l(this, "editorType");
l(this, "editorProps");
l(this, "cellType");
l(this, "level");
l(this, "colspan", 1);
l(this, "rowspan", 1);
l(this, "mergeRow", !1);
l(this, "mergeCol", !1);
l(this, "relationRowKeys", []);
// 合并单元格关联key
l(this, "relationColKeys", []);
// 合并单元格关联key
l(this, "key");
l(this, "column");
l(this, "rowIndex");
l(this, "colIndex");
l(this, "rowKey");
l(this, "row");
l(this, "value");
l(this, "render");
l(this, "renderFooter");
l(this, "style", {});
l(this, "rules", []);
l(this, "message", "");
l(this, "text", "");
l(this, "displayText", "");
l(this, "visibleWidth", 0);
l(this, "visibleHeight", 0);
l(this, "isHasChanged", !1);
l(this, "drawX", 0);
l(this, "drawY", 0);
l(this, "drawCellBgColor", "");
l(this, "drawCellSkyBgColor", "");
l(this, "drawTextColor", "");
l(this, "drawTextX", 0);
l(this, "drawTextY", 0);
l(this, "drawImageX", 0);
l(this, "drawImageY", 0);
l(this, "drawImageWidth", 0);
l(this, "drawImageHeight", 0);
l(this, "drawImageName", "");
l(this, "drawImageSource");
l(this, "ellipsis", !1);
l(this, "rowExpand", !1);
l(this, "rowHasChildren", !1);
l(this, "overflowTooltipShow", !0);
l(this, "overflowTooltipMaxWidth", 500);
l(this, "overflowTooltipPlacement", "top");
this.visibleWidth = this.width, this.visibleHeight = this.height, this.colIndex = s, this.rowIndex = i, this.key = c.key, this.type = c.type || "", this.editorType = c.editorType || "text", this.editorProps = c.editorProps || {}, this.cellType = f, this.align = c.align || "center", this.verticalAlign = c.verticalAlign || "middle", this.fixed = c.fixed, this.level = c.level || 0, this.operation = c.operation || !1, this.column = c, this.rules = c.rules || [], this.row = d, this.rowKey = this.cellType === "body" ? this.ctx.database.getRowKeyForRowIndex(i) : `${this.cellType}_${this.rowIndex}`, this.value = this.getValue(), this.render = c.render, this.overflowTooltipShow = c.overflowTooltipShow !== !1, this.overflowTooltipMaxWidth = c.overflowTooltipMaxWidth || 500, this.overflowTooltipPlacement = c.overflowTooltipPlacement || "top", this.renderFooter = c.renderFooter, this.hoverIconName = c.hoverIconName, this.formatter = c.formatter, this.formatterFooter = c.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: r = 1,
relationRowKeys: o,
relationColKeys: n,
mergeRow: h = !1,
mergeCol: c = !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(o) && o.length > 0 ? this.relationRowKeys = o : this.relationRowKeys = [this.key], Array.isArray(n) && n.length > 0 ? this.relationColKeys = n : this.relationColKeys = [this.key], this.mergeCol = c, this.mergeRow = h, this.colspan = s, this.rowspan = r, 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: r, props: o = {} } = s;
this.editorType = r, this.editorProps = o;
}
}
}
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 r, o = 0, n = "";
if (this.type === "tree" && s === "body") {
const h = this.ctx.database.getRowForRowKey(i), { expand: c = !1, hasChildren: d = !1, expandLoading: f = !1, level: u = 0 } = h || {};
if (this.rowExpand = c, this.rowHasChildren = d, f) {
const g = this.ctx.icons.get("loading");
n = "loading", r = g, o = u * 8;
} else if (d) {
const g = this.ctx.icons.get("expand"), w = this.ctx.icons.get("shrink");
r = c ? w : g, n = c ? "shrink" : "expand", o = u * 8;
} else
o = u * 8;
let x = 20, p = 20;
if (r) {
let g = this.drawX + o + e, w = this.drawY + (this.visibleHeight - p) / 2;
this.ctx.paint.drawImage(r, g, w, x, p), this.drawImageX = g, this.drawImageY = w, this.drawImageWidth = x, this.drawImageHeight = p, this.drawImageName = n, this.drawImageSource = r;
}
this.align = "left", this.drawTextX = o + this.drawX + x - 0.5;
}
}
updateContainer() {
const {
BODY_BG_COLOR: e,
EDIT_BG_COLOR: i,
BODY_CELL_STYLE_METHOD: s,
FOOTER_CELL_STYLE_METHOD: r,
READONLY_TEXT_COLOR: o,
FOOTER_BG_COLOR: n,
HIGHLIGHT_SELECTED_ROW: h,
HIGHLIGHT_SELECTED_ROW_COLOR: c,
HIGHLIGHT_HOVER_ROW: d,
HIGHLIGHT_HOVER_ROW_COLOR: f
} = this.ctx.config;
if (this.cellType === "footer") {
let y = n, m = o;
if (typeof r == "function") {
const E = r, { backgroundColor: C, color: b } = E({
row: this.row,
rowIndex: this.rowIndex,
colIndex: this.colIndex,
column: this.column,
value: this.getValue()
}) || {};
C && (y = C), b && (m = b);
}
this.drawCellSkyBgColor = "transparent", this.drawCellBgColor = y, this.drawTextColor = m;
return;
}
let u = "transparent";
const x = this.ctx.focusCell, p = this.ctx.hoverCell;
d && (p == null ? void 0 : p.rowKey) === this.rowKey && (u = f), h && (x == null ? void 0 : x.rowKey) === this.rowKey && (u = c), this.drawCellSkyBgColor = u;
let g = e, w = o;
if (["index", "index-selection", "selection"].includes(this.type)) {
this.drawCellBgColor = e, this.drawTextColor = o;
return;
}
if (this.ctx.database.getReadonly(this.rowKey, this.key) || (g = i, w = o), typeof s == "function") {
const y = s, { backgroundColor: m, color: E } = y({
row: this.row,
rowIndex: this.rowIndex,
colIndex: this.colIndex,
column: this.column,
isHasChanged: this.isHasChanged,
value: this.getValue()
}) || {};
m && (g = m), E && (w = E);
}
this.drawCellBgColor = g, this.drawTextColor = w;
}
updateSelection() {
const { visibleWidth: e, visibleHeight: i, rowspan: s, colspan: r, cellType: o, type: n, rowIndex: h, rowKey: c } = this;
if (!(s === 0 || r === 0) && o !== "footer" && ["index-selection", "selection"].includes(n)) {
const d = this.ctx.database.getRowSelection(c), f = this.ctx.database.getRowSelectable(c), { CHECKBOX_SIZE: u = 0 } = this.ctx.config, x = this.drawX + (e - u) / 2, p = this.drawY + (i - u) / 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 && n == "index-selection" ? (this.ctx.hoverCell && this.ctx.hoverCell.rowIndex === h || ["checkbox-disabled", "checkbox-check"].includes(w)) && (this.drawImageX = x, this.drawImageY = p, this.drawImageWidth = u, this.drawImageHeight = u, this.drawImageName = w, this.drawImageSource = g) : g && n === "selection" && (this.drawImageX = x, this.drawImageY = p, this.drawImageWidth = u, this.drawImageHeight = u, this.drawImageName = w, this.drawImageSource = g);
}
}
updateHoverIcon() {
const { BODY_CELL_HOVER_ICON_METHOD: e, CELL_HOVER_ICON_SIZE: i, CELL_PADDING: s } = this.ctx.config;
if (typeof e == "function") {
const h = e({
row: this.row,
rowIndex: this.rowIndex,
colIndex: this.colIndex,
column: this.column,
value: this.getValue()
});
h !== void 0 && (this.hoverIconName = h);
}
const r = this.drawX + this.width - i - s, o = this.drawY + (this.height - i) / 2;
if (this.hoverIconName && this.ctx.hoverCell && this.ctx.hoverCell.rowIndex === this.rowIndex) {
const n = this.ctx.icons.get(this.hoverIconName);
this.drawImageX = r, this.drawImageY = o, this.drawImageWidth = i, this.drawImageHeight = i, this.drawImageName = this.hoverIconName, this.drawImageSource = n;
}
}
// 过去跨度配置
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"
};
}
draw() {
const {
paint: e,
config: { BORDER_COLOR: i }
} = this.ctx, { drawX: s, drawY: r } = this;
e.drawRect(s, r, this.visibleWidth, this.visibleHeight, {
borderColor: i,
fillColor: this.drawCellBgColor
}), e.drawRect(s, r, this.width, this.height, {
borderColor: "transparent",
borderWidth: 1,
fillColor: this.drawCellSkyBgColor
}), 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 r = e; r < e + i; r++) {
const o = this.ctx.header.leafCellHeaders[r];
s += o.width;
}
return s;
}
drawText() {
const { CELL_PADDING: e, BODY_FONT: i } = this.ctx.config, { ellipsis: s } = this.ctx.paint.handleEllipsis(this.text, this.width, e, i);
return this.ellipsis = s, this.ctx.paint.drawText(
this.displayText,
this.drawTextX,
this.drawTextY,
this.visibleWidth,
this.visibleHeight,
{
font: i,
padding: e,
align: this.align,
verticalAlign: this.verticalAlign,
color: this.drawTextColor
}
);
}
drawImage() {
this.drawImageSource && this.ctx.paint.drawImage(
this.drawImageSource,
this.drawImageX,
this.drawImageY,
this.drawImageWidth,
this.drawImageHeight
);
}
drawAutofillPiont() {
if (this.cellType === "footer")
return;
const { SELECT_BORDER_COLOR: e, ENABLE_AUTOFILL: i, ENABLE_SELECTOR: s, AUTOFILL_POINT_BORDER_COLOR: r } = this.ctx.config;
if (!s || !i)
return;
const { xArr: o, yArr: n } = this.ctx.selector, h = o[1], c = n[1], { colIndex: d, rowIndex: f, drawX: u, drawY: x } = this;
d === h && f === c && this.ctx.paint.drawRect(u + this.width - 6, x + this.height - 6, 6, 6, {
borderColor: r,
fillColor: e
});
}
drawSelector() {
if (this.cellType === "footer")
return;
const { ENABLE_SELECTOR: e } = this.ctx.config;
if (!e)
return;
const { xArr: i, yArr: s, xArrCopy: r, yArrCopy: o } = this.ctx.selector;
this.drawBorder({
xArr: r,
yArr: o,
borderColor: this.ctx.config.SELECT_BORDER_COLOR || "rgb(82,146,247)",
fillColor: this.ctx.config.SELECT_AREA_COLOR || "rgba(82,146,247,0.1)",
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: this.ctx.config.SELECT_AREA_COLOR || "rgba(82,146,247,0.1)",
borderWidth: 1,
lineDash: [4, 4]
}), this.drawBorder({
xArr: i,
yArr: s,
borderColor: this.ctx.config.SELECT_BORDER_COLOR || "rgb(82,146,247)",
fillColor: this.ctx.config.SELECT_AREA_COLOR || "rgba(82,146,247,0.1)",
borderWidth: 1
});
}
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, r = this.drawX, o = this.drawY, n = [
r + s - e - 0.5,
o,
r + s - 0.5,
o,
r + s - 0.5,
o + e
];
this.ctx.paint.drawLine(n, {
borderColor: i,
fillColor: i,
borderWidth: 1,
lineCap: "round",
lineJoin: "round"
});
}
drawBorder(e) {
const { drawX: i, drawY: s, width: r, rowIndex: o, colIndex: n } = this;
let h = i + 0.5, c = s + 0.5, d = this.height;
o === 0 && (c = this.y + 1, d = d - 1), n === this.ctx.maxColIndex && (h = h - 1);
const { xArr: f, yArr: u, lineDash: x = [], borderWidth: p = 1, borderColor: g, fillColor: w } = e, y = f[0], m = f[1], E = u[0], C = u[1];
n >= y && n <= m && o === E && this.ctx.paint.drawLine([h, c, h + r - 2, c], {
borderColor: g,
fillColor: w,
borderWidth: p,
lineCap: "round",
lineJoin: "round",
lineDash: x
}), n >= y && n <= m && o === C && this.ctx.paint.drawLine([h, c + d - 1.5, h + r, c + d - 1.5], {
borderColor: g,
fillColor: w,
borderWidth: p,
lineCap: "round",
lineJoin: "round",
lineDash: x
}), n === y && o >= E && o <= C && this.ctx.paint.drawLine([h, c, h, c + d - 1], {
borderColor: g,
fillColor: w,
borderWidth: p,