igniteui-react-grids
Version:
Ignite UI React grid components.
765 lines (764 loc) • 22.9 kB
JavaScript
/*
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 { 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
*/
export let CanvasGridCellBase = /*@__PURE__*/ (() => {
class CanvasGridCellBase extends Base {
get ad() {
return this.r;
}
set ad(a) {
this.r = a;
}
cp(a) {
this.n = a;
}
ca() {
this.r = true;
if (this.n != null) {
this.n();
}
}
get isCanvasBased() {
return true;
}
get bq() {
return this.bp;
}
get isRemoved() {
return this.t;
}
set isRemoved(a) {
this.t = a;
}
cr(a) {
this.b3 = a;
this.r = true;
this.v = true;
}
constructor(a) {
super();
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 = ((() => {
let $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;
}
get templateContext() {
return this.m.h();
}
get z() {
return this.o;
}
set z(a) {
this.o = a;
}
get_af() {
return false;
}
get af() {
return this.get_af();
}
ch(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;
}
ci(a) {
this.r = true;
this.at = a;
this.c0._opacity = this.at;
}
get bf() {
return this.ax;
}
get bh() {
return this.az;
}
get bg() {
return this.ay;
}
get be() {
return this.aw;
}
get ba() {
return this.al;
}
get bc() {
return this.an;
}
get bb() {
return this.am;
}
get a9() {
return this.ak;
}
get bj() {
return this.a3;
}
get bl() {
return this.a5;
}
get bm() {
return this.a7;
}
get_ag() {
return false;
}
get ag() {
return this.get_ag();
}
b6(a, b, c, d, e, f) {
let g = true;
let h = true;
let i = false;
if (this.ag) {
g = false;
h = false;
i = false;
}
this.b7(a, b, c, d, e, f, g, h, i);
}
get resized() {
return this.x;
}
ensureCorrectSize() {
this.x = this.aa(this.a0);
return this.x;
}
b7(a, b, c, d, e, f, g, h, i) {
if (!this.w) {
return;
}
if (this.b2 != 1) {
a.ae(this.b2);
}
let 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();
let k = Math.round((d - b));
let 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) {
let m = Math.round((d - b) * f);
let 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);
}
}
bx() {
return this.br.getNativeElement();
}
cb(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);
}
}
}
co(a) {
this.a0 = a;
}
renderStandardContent() {
this.b7(this.m, 0, 0, 0, 0, this.a0, false, true, true);
}
renderStandardBackground() {
this.b7(this.m, 0, 0, 0, 0, this.a0, true, false, true);
}
cc(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);
}
}
}
b8() {
if (this.br == null && this.y) {
this.br = this.bp.createElement("canvas");
let a = this.bp.get2DCanvasContext(this.br);
let b = ((() => {
let $ret = new CanvasViewRenderer();
$ret.h$d = a;
return $ret;
})());
this.m = new RenderingContext(b, a);
this.v = true;
}
}
aa(a) {
let b = Math.round(this.a8 * a);
let c = Math.round(this.av * a);
this.ap = b;
this.ao = c;
let d = this.bi(b);
let 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;
}
bi(a) {
return a;
}
cn(a, b, c, d) {
this.r = true;
this.ax = a;
this.az = b;
this.ay = c;
this.aw = d;
this.v = true;
}
get bk() {
return this.a4;
}
set bk(a) {
this.a4 = a;
}
cs(a) {
this.r = true;
this.c3 = a;
this.c0.ao = ((() => {
let $ret = new Brush();
$ret.color = this.c3;
return $ret;
})());
}
get_ae() {
return false;
}
get ae() {
return this.get_ae();
}
get ah() {
return this.w;
}
set ah(a) {
this.r = true;
this.w = a;
}
get bd() {
return this.av;
}
get bo() {
return this.a8;
}
ck(a) {
this.r = true;
this.av = a;
this.c9.height = this.av;
}
cu(a) {
this.r = true;
this.a8 = a;
this.c9.width = this.a8;
this.v = true;
}
b5() {
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;
}
cg(a) {
this.r = true;
this.c2 = a;
this.p = this.c2.l == 255;
this.c9._fill = ((() => {
let $ret = new Brush();
$ret.color = this.c2;
return $ret;
})());
}
cm(a) {
this.r = true;
this.b2 = a;
}
cq(a) {
this.u = a;
this.r = true;
}
l() {
if (TestRandomness.instance.testRandomnessSource != null) {
return TestRandomness.instance.testRandomnessSource;
}
return new DefaultRandomnessSource(1, CanvasGridCellBase.bz);
}
k() {
let a = this.l();
return a.getGenerator("PlaceholderWidths");
}
cy(a) {
if (!this.af) {
return;
}
this.r = true;
this.a.h = (a * 0.20000000298023224);
}
b9(a, b, c, d) {
if (this.a != null) {
let e = this.a2;
let 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)));
}
}
}
cj(a) {
this.i = a;
this.s = true;
this.r = true;
this.v = true;
}
cx(a) {
if (!this.af) {
return;
}
this.r = true;
let b = DeviceUtils.f(12);
if (a.ag != null && !isNaN_(a.ag.f)) {
b = a.ag.f;
}
if (this.a1 != b) {
this.a1 = b;
}
let c = a.hd * 0.2;
let d = a.fu * 0.6;
if (this.a2 >= c && this.a2 <= d) {
return;
}
if (CanvasGridCellBase.j == null) {
CanvasGridCellBase.j = this.k();
}
let e = (CanvasGridCellBase.j.nextDouble() * (d - c) + c);
if (this.a2 != e) {
this.a2 = e;
}
}
cv(a, b) {
if (!this.af) {
return;
}
this.r = true;
this.d = a;
this.f = b;
}
cw(a) {
if (!this.af) {
return;
}
this.r = true;
}
cf(a) {
this.b = a;
}
get e() {
return this.c;
}
cl(a) {
this.c = a;
this.r = true;
this.v = true;
}
cz(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);
}
let 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;
let c = 0;
let d = 0;
let e = this.a8;
let 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);
let g = e;
if (!isNaN_(this.a4) && this.a4 < e) {
g = this.a4;
}
let 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;
}
bn(a, b, c, d) {
let e = b;
let f = e.length;
let g = ("\u2026");
if (isNaN_(this.as)) {
this.as = d.g(g);
}
if (c <= this.as) {
a.al = g;
return this.as;
}
let h = d.g(e);
if (h <= c) {
a.al = b;
return h;
}
let i = c / h;
let j = truncate(Math.ceil(f * i));
let k = e.substr(0, j) + g;
let 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;
}
ct(a) {
this.g = a;
this.r = true;
this.v = true;
}
aj(a) {
return a.isClickActionDesired;
}
onContactStarted(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);
}
}
onContactMoved(a, b) {
if (this.b != null && this.aj(this.b)) {
let c = a.pageX;
let 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();
}
}
}
}
}
}
onContactCompleted(a, b) {
if (this.b != null && this.aj(this.b)) {
let c = a.pageX;
let 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);
}
}
}
onDoubleClick(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;
}
}
detach() {
}
}
CanvasGridCellBase.$t = /*@__PURE__*/ markType(CanvasGridCellBase, 'CanvasGridCellBase', Base.$, [INativeCell_$type]);
CanvasGridCellBase.j = null;
CanvasGridCellBase.bz = /*@__PURE__*/ new Random(0);
CanvasGridCellBase.bv = 10;
CanvasGridCellBase.bt = 3;
return CanvasGridCellBase;
})();