UNPKG

igniteui-react-grids

Version:

Ignite UI React grid components.

873 lines (872 loc) 26.2 kB
/* THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE AGREEMENT ("AGREEMENT") LOCATED HERE: https://www.infragistics.com/legal/license/igultimate-la https://www.infragistics.com/legal/license/igultimate-eula GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE: you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company. */ import { __extends } from "tslib"; import { Base, markType, PointUtil } from "igniteui-react-core"; import { INativeCell_$type } from "./INativeCell"; import { RenderingContext } from "igniteui-react-core"; import { Rectangle } from "igniteui-react-core"; import { Line } from "igniteui-react-core"; import { TextBlock } from "igniteui-react-core"; import { Color } from "igniteui-react-core"; import { FontInfo } from "igniteui-react-core"; import { Brush } from "igniteui-react-core"; import { CanvasViewRenderer } from "igniteui-react-core"; import { CanvasPlaceholderView } from "./CanvasPlaceholderView"; import { TestRandomness } from "igniteui-react-core"; import { Random } from "igniteui-react-core"; import { DefaultRandomnessSource } from "igniteui-react-core"; import { DeviceUtils } from "igniteui-react-core"; import { FontUtil } from "igniteui-react-core"; import { truncate, isNaN_ } from "igniteui-react-core"; /** * @hidden */ var CanvasGridCellBase = /** @class */ /*@__PURE__*/ (function (_super) { __extends(CanvasGridCellBase, _super); function CanvasGridCellBase(a) { var _this = _super.call(this) || this; _this.b = null; _this.v = true; _this.r = true; _this.n = null; _this.bp = null; _this.t = false; _this.b3 = null; _this.o = false; _this.at = 1; _this.ax = 5; _this.az = 5; _this.ay = 5; _this.aw = 5; _this.c1 = null; _this.al = 0; _this.an = 0; _this.am = 0; _this.ak = 0; _this.c9 = new Rectangle(); _this.c5 = new Line(); _this.c8 = new Line(); _this.c6 = new Line(); _this.c4 = new Line(); _this.c7 = new Line(); _this.a3 = 0; _this.a5 = 0; _this.a6 = 0; _this.a7 = 0; _this.br = null; _this.m = null; _this.ap = 0; _this.ao = 0; _this.ar = 0; _this.aq = 0; _this.x = true; _this.y = true; _this.a4 = NaN; _this.c0 = new TextBlock(); _this.c3 = Color.u(255, 0, 0, 0); _this.w = true; _this.av = 0; _this.a8 = 0; _this.c2 = Color.u(255, 255, 255, 255); _this.p = false; _this.a = null; _this.d = 0; _this.f = 0; _this.b2 = 1; _this.u = false; _this.a2 = 0; _this.a1 = 0; _this.i = ((function () { var $ret = new FontInfo(); $ret.q = "Verdana"; $ret.f = 12; return $ret; })()); _this.s = true; _this.bu = -1; _this.b0 = 0; _this.b1 = 0; _this.q = false; _this.bs = 0; _this.c = 0; _this.au = NaN; _this.h = null; _this.bw = -1; _this.as = NaN; _this.g = 1; _this.a0 = 1; _this.bp = a; return _this; } Object.defineProperty(CanvasGridCellBase.prototype, "ad", { get: function () { return this.r; }, set: function (a) { this.r = a; }, enumerable: false, configurable: true }); CanvasGridCellBase.prototype.cp = function (a) { this.n = a; }; CanvasGridCellBase.prototype.ca = function () { this.r = true; if (this.n != null) { this.n(); } }; Object.defineProperty(CanvasGridCellBase.prototype, "isCanvasBased", { get: function () { return true; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "bq", { get: function () { return this.bp; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "isRemoved", { get: function () { return this.t; }, set: function (a) { this.t = a; }, enumerable: false, configurable: true }); CanvasGridCellBase.prototype.cr = function (a) { this.b3 = a; this.r = true; this.v = true; }; Object.defineProperty(CanvasGridCellBase.prototype, "templateContext", { get: function () { return this.m.h(); }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "z", { get: function () { return this.o; }, set: function (a) { this.o = a; }, enumerable: false, configurable: true }); CanvasGridCellBase.prototype.get_af = function () { return false; }; Object.defineProperty(CanvasGridCellBase.prototype, "af", { get: function () { return this.get_af(); }, enumerable: false, configurable: true }); CanvasGridCellBase.prototype.ch = function (a, b, c, d, e) { this.r = true; this.c1 = a; this.al = b; this.an = c; this.am = d; this.ak = e; this.v = true; }; CanvasGridCellBase.prototype.ci = function (a) { this.r = true; this.at = a; this.c0._opacity = this.at; }; Object.defineProperty(CanvasGridCellBase.prototype, "bf", { get: function () { return this.ax; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "bh", { get: function () { return this.az; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "bg", { get: function () { return this.ay; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "be", { get: function () { return this.aw; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "ba", { get: function () { return this.al; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "bc", { get: function () { return this.an; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "bb", { get: function () { return this.am; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "a9", { get: function () { return this.ak; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "bj", { get: function () { return this.a3; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "bl", { get: function () { return this.a5; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "bm", { get: function () { return this.a7; }, enumerable: false, configurable: true }); CanvasGridCellBase.prototype.get_ag = function () { return false; }; Object.defineProperty(CanvasGridCellBase.prototype, "ag", { get: function () { return this.get_ag(); }, enumerable: false, configurable: true }); CanvasGridCellBase.prototype.b6 = function (a, b, c, d, e, f) { var g = true; var h = true; var i = false; if (this.ag) { g = false; h = false; i = false; } this.b7(a, b, c, d, e, f, g, h, i); }; Object.defineProperty(CanvasGridCellBase.prototype, "resized", { get: function () { return this.x; }, enumerable: false, configurable: true }); CanvasGridCellBase.prototype.ensureCorrectSize = function () { this.x = this.aa(this.a0); return this.x; }; CanvasGridCellBase.prototype.b7 = function (a, b, c, d, e, f, g, h, i) { if (!this.w) { return; } if (this.b2 != 1) { a.ae(this.b2); } var j = this.m; if (!this.y) { j = a; } this.a0 = f; if (!i) { this.b8(); this.ensureCorrectSize(); } if (this.ad || this.x || i || !this.y) { this.ad = false; if (this.s || this.x || (this.i != null && this.i.j != this.bu)) { this.s = false; this.bu = this.i.j; j.ad(this.i); } if (f != 1) { j.aa(); j.ab(f, f); } if (!this.y) { j.aa(); var k = Math.round((d - b)); var l = Math.round((e - c)); j.ag(k, l); } if (g) { this.cb(j); } if (h) { this.cc(j); } if (!this.y) { j.z(); } if (f != 1) { j.z(); } } if (!i && this.y) { var m = Math.round((d - b) * f); var n = Math.round((e - c) * f); if (this.ap == this.ar && this.ao == this.aq) { a.n(this.bx(), 1, m, n, this.ap, this.ao); } else { a.o(this.bx(), 1, 0, 0, this.ap, this.ao, m, n, this.ap, this.ao); } } if (this.b2 != 1) { a.ae(1); } }; CanvasGridCellBase.prototype.bx = function () { return this.br.getNativeElement(); }; CanvasGridCellBase.prototype.cb = function (a) { if (!this.p) { a.l(0, 0, this.ar, this.aq); } this.c9.n = 0; this.c9.o = 0; this.c9.width = this.a8; this.c9.height = this.av; a.w(this.c9); if (this.c1 != null) { if (this.al > 0) { this.c5.ap = 0; this.c5.an = this.al / 2; this.c5.aq = this.av; this.c5.ao = this.al / 2; this.c5._stroke = this.c1; this.c5.ad = this.al; a.s(this.c5); } if (this.am > 0) { this.c6.ap = 0; this.c6.an = Math.max(0, (this.a8 - (this.am / 2))); this.c6.aq = this.av; this.c6.ao = Math.max(0, (this.a8 - (this.am / 2))); this.c6._stroke = this.c1; this.c6.ad = this.am; a.s(this.c6); } if (this.an > 0) { this.c8.ap = this.an / 2; this.c8.an = this.al; this.c8.aq = this.an / 2; this.c8.ao = Math.max(0, (this.a8 - (this.am / 2))); this.c8._stroke = this.c1; this.c8.ad = this.an; a.s(this.c8); } if (this.ak > 0) { this.c4.ap = Math.max(0, this.av - (this.ak / 2)); this.c4.an = this.al; this.c4.aq = Math.max(0, this.av - (this.ak / 2)); this.c4.ao = Math.max(0, (this.a8 - (this.am / 2))); this.c4._stroke = this.c1; this.c4.ad = this.ak; a.s(this.c4); } } }; CanvasGridCellBase.prototype.co = function (a) { this.a0 = a; }; CanvasGridCellBase.prototype.renderStandardContent = function () { this.b7(this.m, 0, 0, 0, 0, this.a0, false, true, true); }; CanvasGridCellBase.prototype.renderStandardBackground = function () { this.b7(this.m, 0, 0, 0, 0, this.a0, true, false, true); }; CanvasGridCellBase.prototype.cc = function (a) { if (this.v) { this.cz(a); this.v = false; } if (this.c0.al != null) { this.c0.n = this.a3; this.c0.o = this.a6; a.x(this.c0); if (this.u) { this.c7.ad = 1; this.c7.an = this.a3; this.c7.ap = this.a7 - 2; this.c7.ao = this.a3 + (this.a5 - this.a3); this.c7.aq = this.a7 - 2; this.c7._stroke = this.c0.ao; this.m.s(this.c7); } } }; CanvasGridCellBase.prototype.b8 = function () { if (this.br == null && this.y) { this.br = this.bp.createElement("canvas"); var a_1 = this.bp.get2DCanvasContext(this.br); var b = ((function () { var $ret = new CanvasViewRenderer(); $ret.h$d = a_1; return $ret; })()); this.m = new RenderingContext(b, a_1); this.v = true; } }; CanvasGridCellBase.prototype.aa = function (a) { var b = Math.round(this.a8 * a); var c = Math.round(this.av * a); this.ap = b; this.ao = c; var d = this.bi(b); var e = this.bi(c); if (d != this.ar || e != this.aq) { this.br.setAttribute("width", d + "px"); this.br.setAttribute("height", e + "px"); this.ar = d; this.aq = e; this.ap = b; this.ao = c; return true; } return false; }; CanvasGridCellBase.prototype.bi = function (a) { return a; }; CanvasGridCellBase.prototype.cn = function (a, b, c, d) { this.r = true; this.ax = a; this.az = b; this.ay = c; this.aw = d; this.v = true; }; Object.defineProperty(CanvasGridCellBase.prototype, "bk", { get: function () { return this.a4; }, set: function (a) { this.a4 = a; }, enumerable: false, configurable: true }); CanvasGridCellBase.prototype.cs = function (a) { var _this = this; this.r = true; this.c3 = a; this.c0.ao = ((function () { var $ret = new Brush(); $ret.color = _this.c3; return $ret; })()); }; CanvasGridCellBase.prototype.get_ae = function () { return false; }; Object.defineProperty(CanvasGridCellBase.prototype, "ae", { get: function () { return this.get_ae(); }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "ah", { get: function () { return this.w; }, set: function (a) { this.r = true; this.w = a; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "bd", { get: function () { return this.av; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasGridCellBase.prototype, "bo", { get: function () { return this.a8; }, enumerable: false, configurable: true }); CanvasGridCellBase.prototype.ck = function (a) { this.r = true; this.av = a; this.c9.height = this.av; }; CanvasGridCellBase.prototype.cu = function (a) { this.r = true; this.a8 = a; this.c9.width = this.a8; this.v = true; }; CanvasGridCellBase.prototype.b5 = function () { if (!this.af) { return; } this.o = true; this.a = new CanvasPlaceholderView(); this.d = 0; this.f = 1; this.a.l = Color.u(120, 120, 120, 120); this.a.h = 0; }; CanvasGridCellBase.prototype.cg = function (a) { var _this = this; this.r = true; this.c2 = a; this.p = this.c2.l == 255; this.c9._fill = ((function () { var $ret = new Brush(); $ret.color = _this.c2; return $ret; })()); }; CanvasGridCellBase.prototype.cm = function (a) { this.r = true; this.b2 = a; }; CanvasGridCellBase.prototype.cq = function (a) { this.u = a; this.r = true; }; CanvasGridCellBase.prototype.l = function () { if (TestRandomness.instance.testRandomnessSource != null) { return TestRandomness.instance.testRandomnessSource; } return new DefaultRandomnessSource(1, CanvasGridCellBase.bz); }; CanvasGridCellBase.prototype.k = function () { var a = this.l(); return a.getGenerator("PlaceholderWidths"); }; CanvasGridCellBase.prototype.cy = function (a) { if (!this.af) { return; } this.r = true; this.a.h = (a * 0.20000000298023224); }; CanvasGridCellBase.prototype.b9 = function (a, b, c, d) { if (this.a != null) { var e = this.a2; var f = this.a1; if (this.f == 1) { b = truncate((b + (d / 2) - (f / 2))); } else if (this.f == 2) { b = truncate((b + (d) - (f))); } if (this.d == 1) { a = truncate((a + (c / 2) - (e / 2))); } else if (this.d == 2) { a = truncate((a + (c) - (e))); } } }; CanvasGridCellBase.prototype.cj = function (a) { this.i = a; this.s = true; this.r = true; this.v = true; }; CanvasGridCellBase.prototype.cx = function (a) { if (!this.af) { return; } this.r = true; var b = DeviceUtils.f(12); if (a.ag != null && !isNaN_(a.ag.f)) { b = a.ag.f; } if (this.a1 != b) { this.a1 = b; } var c = a.hd * 0.2; var d = a.fu * 0.6; if (this.a2 >= c && this.a2 <= d) { return; } if (CanvasGridCellBase.j == null) { CanvasGridCellBase.j = this.k(); } var e = (CanvasGridCellBase.j.nextDouble() * (d - c) + c); if (this.a2 != e) { this.a2 = e; } }; CanvasGridCellBase.prototype.cv = function (a, b) { if (!this.af) { return; } this.r = true; this.d = a; this.f = b; }; CanvasGridCellBase.prototype.cw = function (a) { if (!this.af) { return; } this.r = true; }; CanvasGridCellBase.prototype.cf = function (a) { this.b = a; }; Object.defineProperty(CanvasGridCellBase.prototype, "e", { get: function () { return this.c; }, enumerable: false, configurable: true }); CanvasGridCellBase.prototype.cl = function (a) { this.c = a; this.r = true; this.v = true; }; CanvasGridCellBase.prototype.cz = function (a) { if (this.b3 == null) { return; } if (a == null) { return; } if (this.s || (this.i != null && this.i.j != this.bu)) { this.s = false; this.bu = this.i.j; a.ad(this.i); } var b; if (this.h != this.i || this.bw != this.i.j) { this.h = this.i; this.bw = this.i.j; this.au = FontUtil.getCurrentFontHeight(this.bp, this.i); } b = this.au; var c = 0; var d = 0; var e = this.a8; var f = this.av; e -= (this.al + this.ax + this.am + this.ay); f -= (this.an + this.az + this.ak + this.aw); e = Math.max(e, 0); f = Math.max(f, 0); var g = e; if (!isNaN_(this.a4) && this.a4 < e) { g = this.a4; } var h = this.bn(this.c0, this.b3, g, a); switch (this.c) { case 0: c = this.ax + this.al; break; case 3: case 1: c = this.ax + this.al + ((e / 2) - (h / 2)); break; case 2: c = Math.max(0, (this.a8 - (this.ay + this.am))) - h; break; } switch (this.g) { case 0: d = this.az + this.an; break; case 3: case 1: d = this.az + this.an + ((f / 2) - (b / 2)); break; case 2: d = Math.max(0, (this.av - (this.aw + this.ak))) - b; break; } this.a3 = c; this.a5 = this.a3 + h; this.a6 = d; this.a7 = this.a6 + (b / 2); this.r = true; }; CanvasGridCellBase.prototype.bn = function (a, b, c, d) { var e = b; var f = e.length; var g = ("\u2026"); if (isNaN_(this.as)) { this.as = d.g(g); } if (c <= this.as) { a.al = g; return this.as; } var h = d.g(e); if (h <= c) { a.al = b; return h; } var i = c / h; var j = truncate(Math.ceil(f * i)); var k = e.substr(0, j) + g; var l = d.g(k); if (l > c) { f = j; } else { j = j + 1; k = e.substr(0, j) + g; l = d.g(k); if (l > c) { f = j; } } while (h > c && f > 0) { f--; e = e.substr(0, f) + g; h = d.g(e); } a.al = e; return h; }; CanvasGridCellBase.prototype.ct = function (a) { this.g = a; this.r = true; this.v = true; }; CanvasGridCellBase.prototype.aj = function (a) { return a.isClickActionDesired; }; CanvasGridCellBase.prototype.onContactStarted = function (a, b) { if (this.b != null && this.aj(this.b)) { this.b0 = a.pageX; this.b1 = a.pageY; this.b.mouseDownCell(this.b0, this.b1); } }; CanvasGridCellBase.prototype.onContactMoved = function (a, b) { if (this.b != null && this.aj(this.b)) { var c = a.pageX; var d = a.pageY; if (this.b.isMouseDown) { if (b) { if (PointUtil.equals(this.b.mousePosition, null) || Math.abs(c - this.b.mousePosition.x) > CanvasGridCellBase.bv || Math.abs(d - this.b.mousePosition.y) > CanvasGridCellBase.bv) { this.b.mouseUpCell(c, d); } else { a.stopPropagation(); } } else { if (PointUtil.equals(this.b.mousePosition, null)) { this.b.mouseUpCell(c, d); } else { if (Math.abs(c - this.b.mousePosition.x) > CanvasGridCellBase.bt || Math.abs(d - this.b.mousePosition.y) > CanvasGridCellBase.bt) { this.b.isControlPressed = a.ctrlKey; this.b.dragStarted(); } } } } } }; CanvasGridCellBase.prototype.onContactCompleted = function (a, b) { if (this.b != null && this.aj(this.b)) { var c = a.pageX; var d = a.pageY; if (PointUtil.equals(this.b.mousePosition, null) || Math.abs(c - this.b.mousePosition.x) > CanvasGridCellBase.bv || Math.abs(d - this.b.mousePosition.y) > CanvasGridCellBase.bv || this.b.isDrag) { this.b.mouseUpCell(c, d); } if (this.b.isCellDown()) { this.b.isControlPressed = a.ctrlKey; this.b.isShiftPressed = a.shiftKey; switch (a.which) { case 1: this.b.clickCell(0); break; case 2: this.b.clickCell(1); break; case 3: this.b.clickCell(2); break; default: this.b.clickCell(3); break; } this.b.mouseUpCell(a.pageX, a.pageY); } } }; CanvasGridCellBase.prototype.onDoubleClick = function (a) { switch (a.which) { case 1: this.b.doubleClicked(0); break; case 2: this.b.doubleClicked(1); break; case 3: this.b.doubleClicked(2); break; default: this.b.doubleClicked(3); break; } }; CanvasGridCellBase.prototype.detach = function () { }; CanvasGridCellBase.$t = markType(CanvasGridCellBase, 'CanvasGridCellBase', Base.$, [INativeCell_$type]); CanvasGridCellBase.j = null; CanvasGridCellBase.bz = new Random(0); CanvasGridCellBase.bv = 10; CanvasGridCellBase.bt = 3; return CanvasGridCellBase; }(Base)); export { CanvasGridCellBase };