igniteui-react-grids
Version:
Ignite UI React grid components.
665 lines (664 loc) • 22.3 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, runOn, markType, PointUtil } from "igniteui-react-core";
import { INativeCell_$type } from "./INativeCell";
import { GridExpansionIndicator } from "./GridExpansionIndicator";
import { PlaceholderView } from "./PlaceholderView";
import { Color } from "igniteui-react-core";
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 { intDivide, truncate, isNaN_ } from "igniteui-react-core";
/**
* @hidden
*/
export let GridCellBase = /*@__PURE__*/ (() => {
class GridCellBase extends Base {
get b() {
return this.a;
}
get f() {
return this.e;
}
get d() {
return this.c;
}
get ae() {
return this.ad;
}
get ah() {
return this.af;
}
get isRemoved() {
return this.s;
}
set isRemoved(a) {
let b = this.s;
this.s = a;
if (b != this.s) {
this.bs("IsRemoved", b, this.s);
}
}
get a5() {
return this.as;
}
get a3() {
return this.aq;
}
get a4() {
return this.ar;
}
get a6() {
return this.av;
}
set a6(a) {
let b = this.av;
this.av = a;
if (b != this.av) {
this.bs("Indent", b, this.av);
}
}
get v() {
return this.p;
}
set v(a) {
let b = this.p;
this.p = a;
if (b != this.p) {
this.bs("IsCollapsable", b, this.p);
}
}
get w() {
return this.q;
}
set w(a) {
let b = this.q;
this.q = a;
if (b != this.q) {
this.bs("IsExpanded", b, this.q);
}
}
get y() {
return this.r;
}
set y(a) {
let b = this.r;
this.r = a;
if (b != this.r) {
this.bs("IsHitTestVisible", b, this.r);
}
}
constructor(a) {
super();
this.a = null;
this.e = null;
this.c = null;
this.ad = null;
this.af = null;
this.s = false;
this.ag = null;
this.i = null;
this.as = 0;
this.ap = 24;
this.ar = 0;
this.aq = 0;
this.av = 0;
this.p = false;
this.q = false;
this.r = true;
this.n = false;
this.ax = 0;
this.az = 0;
this.ay = 0;
this.aw = 0;
this.ak = 0;
this.am = 0;
this.al = 0;
this.aj = 0;
this.cj = null;
this.at = 0;
this.a2 = 0;
this.au = 0;
this.j = null;
this.g = 0;
this.h = 0;
this.ac = 0;
this.ab = 0;
this.t = false;
this.a8 = 0;
this.a9 = 0;
this.ai = 0;
this.a1 = -1;
this.an = 0;
this.o = false;
this.ad = a;
this.af = this.ad.createElement("div");
this.af.setAttribute("tabindex", "-1");
this.af.setRawStyleProperty("position", "absolute");
this.af.setRawStyleProperty("overflow", "hidden");
this.af.setRawStyleProperty("box-sizing", "border-box");
this.af.setRawStyleProperty("outline", "none");
let b = (window.navigator.msPointerEnabled && window.MSGesture !== undefined);
let c = (window.PointerEvent !== undefined);
let d = (window.TouchEvent);
if ((b || c)) {
this.af.listen("pointerdown", runOn(this, this.bt));
this.af.listen("pointerup", runOn(this, this.bx));
this.af.listen("pointermove", runOn(this, this.bw));
this.af.listen("pointerleave", runOn(this, this.bv));
this.af.listen("pointerenter", runOn(this, this.bu));
}
else {
this.af.listen("mousedown", runOn(this, this.bj));
this.af.listen("mouseup", runOn(this, this.bn));
this.af.listen("mousemove", runOn(this, this.bm));
this.af.listen("mouseleave", runOn(this, this.bl));
this.af.listen("touchstart", runOn(this, this.cb));
this.af.listen("touchend", runOn(this, this.cd));
this.af.listen("touchmove", runOn(this, this.cc));
}
}
bi() {
this.ar = 10;
this.aq = this.a6 * 24;
this.as = 24;
if (this.ag == null) {
this.ag = this.ad.createElement("div");
this.ag.setRawStyleProperty("display", "inline-block");
this.ag.setRawStyleProperty("vertical-align", "middle");
this.ag.setRawStyleProperty("width", this.as + "px");
this.ag.setRawStyleProperty("height", this.as + "px");
this.ag.setRawStyleProperty("cursor", "pointer");
this.ag.setRawStyleProperty("position", "absolute");
this.ag.setRawXPosition(this.ax + this.aq);
this.ag.setRawYPosition(intDivide(this.at, 2) - intDivide(this.ap, 2));
}
if (this.i == null) {
let a = this.ad.getSubRenderer(this.ag);
this.i = new GridExpansionIndicator();
this.i.ab(a);
this.i.y(24, 24);
}
if (this.ag.parent() == null) {
this.af.append(this.ag);
}
}
by() {
this.as = 0;
this.ar = 0;
if (this.ag != null) {
if (this.ag.parent() != null) {
this.ag.remove();
}
}
}
get u() {
return this.n;
}
set u(a) {
this.n = a;
}
get_z() {
return false;
}
get z() {
return this.get_z();
}
b7(a, b, c, d) {
this.ax = a;
this.az = b;
this.ay = c;
this.aw = d;
this.af.setRawStyleProperty("padding-left", a.toString() + "px");
this.af.setRawStyleProperty("padding-top", b.toString() + "px");
this.af.setRawStyleProperty("padding-right", c.toString() + "px");
this.af.setRawStyleProperty("padding-bottom", d.toString() + "px");
}
b1(a, b, c, d, e) {
this.ak = b;
this.am = c;
this.al = d;
this.aj = e;
this.cj = a;
if (a == null) {
this.af.setRawStyleProperty("border", "");
}
else {
this.af.setRawStyleProperty("border-color", a._fill);
this.af.setRawStyleProperty("border-left-width", b.toString() + "px");
this.af.setRawStyleProperty("border-top-width", c.toString() + "px");
this.af.setRawStyleProperty("border-right-width", d.toString() + "px");
this.af.setRawStyleProperty("border-bottom-width", e.toString() + "px");
this.af.setRawStyleProperty("border-style", "solid");
}
}
get_x() {
return false;
}
get x() {
return this.get_x();
}
b3(a, b) {
if (this.at != a || this.au != b) {
let c = this.at;
this.at = a;
this.au = b;
let d = Math.max(0, this.at - this.au);
this.af.setRawStyleProperty("height", a.toString() + "px");
this.af.setRawStyleProperty("line-height", d.toString() + "px");
if (this.ag != null) {
this.ag.setRawYPosition(intDivide(this.at, 2) - intDivide(this.as, 2));
}
this.ca(this.a2, this.at, this.a2, c);
}
}
b9(a, b) {
if (this.a2 != a) {
let c = this.a2;
this.a2 = a;
this.af.setRawStyleProperty("width", a.toString() + "px");
this.ca(this.a2, this.at, c, this.at);
}
}
ca(a, b, c, d) {
}
bg() {
if (!this.z) {
return;
}
this.n = true;
this.j = new PlaceholderView(this.ad);
this.g = 0;
this.h = 1;
this.j.l = Color.u(120, 120, 120, 120);
this.j.i = 0;
this.af.append(this.j.g);
}
b0(a) {
this.af.setRawStyleProperty("background-color", a.colorString);
}
b6(a) {
this.af.setRawStyleProperty("opacity", a.toString());
}
m() {
if (TestRandomness.instance.testRandomnessSource != null) {
return TestRandomness.instance.testRandomnessSource;
}
return new DefaultRandomnessSource(1, GridCellBase.a7);
}
l() {
let a = this.m();
return a.getGenerator("PlaceholderWidths");
}
ci(a) {
if (!this.z) {
return;
}
this.j.i = (a * 0.20000000298023224);
}
cg(a, b, c, d) {
if (this.j != null) {
let e = this.ac;
let f = this.ab;
if (this.h == 1) {
b = truncate((b + (d / 2) - (f / 2)));
}
else if (this.h == 2) {
b = truncate((b + (d) - (f)));
}
if (this.g == 1) {
a = truncate((a + (c / 2) - (e / 2)));
}
else if (this.g == 2) {
a = truncate((a + (c) - (e)));
}
this.j.g.setRawXPosition(a);
this.j.g.setRawYPosition(b);
}
}
bq(a, b, c) {
}
ch(a) {
if (!this.z) {
return;
}
let b = DeviceUtils.f(12);
if (a.ag != null && !isNaN_(a.ag.f)) {
b = a.ag.f;
}
if (this.ab != b) {
this.ab = b;
this.j.d = (b);
}
let c = a.hd * 0.2;
let d = a.fu * 0.6;
if (this.ac >= c && this.ac <= d && !this.t) {
return;
}
this.t = false;
if (GridCellBase.k == null) {
GridCellBase.k = this.l();
}
let e = (GridCellBase.k.nextDouble() * (d - c) + c);
if (this.ac != e) {
this.ac = e;
this.j.e = e;
}
this.cg(this.ax + this.aq + this.as, this.az, this.a2 - (this.ax + this.ay), this.at - (this.az + this.aw));
}
ce(a, b) {
if (!this.z) {
return;
}
this.g = a;
this.h = b;
this.t = true;
}
cf(a) {
if (!this.z) {
return;
}
if (a != null) {
this.j.l = a.color;
}
}
bz(a) {
this.a = a;
}
b5(a) {
this.e = a;
}
b2(a) {
this.c = a;
}
b4(a, b) {
switch (b) {
case 0:
this.ah.setRawStyleProperty("text-align", "left");
break;
case 1:
this.ah.setRawStyleProperty("text-align", "center");
break;
case 2:
this.ah.setRawStyleProperty("text-align", "right");
break;
case 3:
this.ah.setRawStyleProperty("text-align", "center");
break;
}
}
b8(a, b) {
switch (b) {
case 0:
a.setRawStyleProperty("vertical-align", "top");
break;
case 1:
a.setRawStyleProperty("vertical-align", "center");
break;
case 2:
a.setRawStyleProperty("vertical-align", "bottom");
break;
case 3:
a.setRawStyleProperty("vertical-align", "center");
break;
}
}
aa(a) {
return a.isClickActionDesired;
}
bj(a) {
this.onContactStarted(a, false);
}
bn(a) {
this.onContactCompleted(a, false);
}
bm(a) {
this.onContactMoved(a, false);
}
bl(a) {
this.bp(a, false);
}
bk(a) {
this.bo(a, false);
}
bt(e_) {
let a = (e_.originalEvent.pointerType);
if (a == "touch") {
this.cb(e_);
}
else {
this.bj(e_);
}
}
bw(e_) {
let a = (e_.originalEvent.pointerType);
if (a == "touch") {
this.cc(e_);
}
else {
this.bm(e_);
}
}
bx(e_) {
let a = (e_.originalEvent.pointerType);
if (a == "touch") {
this.cd(e_);
}
else {
this.bn(e_);
}
}
bv(e_) {
let a = (e_.originalEvent.pointerType);
if (a != "touch") {
this.bl(e_);
}
}
bu(e_) {
let a = (e_.originalEvent.pointerType);
if (a != "touch") {
this.bk(e_);
}
}
cb(a) {
this.onContactStarted(a, true);
}
cc(a) {
this.onContactMoved(a, true);
}
cd(a) {
this.onContactCompleted(a, true);
}
onContactStarted(e_, a) {
let b = false;
if (this.v) {
let indicator_ = this.i.q();
b = (e_.originalEvent.srcElement === indicator_ || e_.originalEvent.target === indicator_);
}
this.o = false;
if (b) {
this.o = true;
}
else {
if (this.a != null && this.aa(this.a)) {
this.a8 = e_.pageX;
this.a9 = e_.pageY;
if (this.a1 != e_.which) {
this.an = 0;
}
this.a1 = e_.which;
this.a.mouseDownCell(this.a8, this.a9);
}
}
}
onContactMoved(a, b) {
if (this.a != null) {
let c = a.pageX;
let d = a.pageY;
if (this.aa(this.a)) {
if (this.a.isMouseDown) {
if (b) {
if (PointUtil.equals(this.a.mousePosition, null) || Math.abs(c - this.a.mousePosition.x) > GridCellBase.a0 || Math.abs(d - this.a.mousePosition.y) > GridCellBase.a0) {
this.a.mouseUpCell(c, d);
}
else {
a.stopPropagation();
}
}
else {
if (PointUtil.equals(this.a.mousePosition, null)) {
this.a.mouseUpCell(c, d);
}
else if (this.a1 == 1) {
if (Math.abs(c - this.a.mousePosition.x) > GridCellBase.ao || Math.abs(d - this.a.mousePosition.y) > GridCellBase.ao) {
this.a.isControlPressed = a.ctrlKey;
this.a.dragStarted();
}
}
}
}
}
if (this.a.isHoverActionDesired) {
this.a.mouseIsOver(c, d);
}
}
}
onContactCompleted(e_, a) {
this.an++;
window.setTimeout(() => this.an = 0, 250);
let b = false;
if (this.v) {
let indicator_ = this.i.q();
b = (e_.originalEvent.srcElement === indicator_ || e_.originalEvent.target === indicator_);
}
if (this.o && b) {
this.b.clickExpansionIndicator();
}
else {
if (this.a != null && this.aa(this.a)) {
let c = e_.pageX;
let d = e_.pageY;
if (PointUtil.equals(this.a.mousePosition, null) || Math.abs(c - this.a.mousePosition.x) > GridCellBase.a0 || Math.abs(d - this.a.mousePosition.y) > GridCellBase.a0 || this.a.isDrag) {
this.a.mouseUpCell(c, d);
}
if (this.a.isCellDown()) {
this.a.isControlPressed = e_.ctrlKey;
this.a.isShiftPressed = e_.shiftKey;
if (this.an > 1) {
switch (this.a1) {
case 1:
this.a.doubleClicked(0);
break;
case 2:
this.a.doubleClicked(1);
break;
case 3:
this.a.doubleClicked(2);
break;
default:
this.a.doubleClicked(3);
break;
}
}
else {
switch (e_.which) {
case 1:
this.a.clickCell(0);
break;
case 2:
this.a.clickCell(1);
break;
case 3:
this.a.clickCell(2);
break;
default:
this.a.clickCell(3);
break;
}
}
this.a.mouseUpCell(e_.pageX, e_.pageY);
}
}
}
this.o = false;
}
bp(a, b) {
if (this.a != null) {
if (this.aa(this.a)) {
if (this.a.isMouseDown) {
if (!b && PointUtil.notEquals(this.a.mousePosition, null)) {
this.a.isControlPressed = a.ctrlKey;
this.a.dragStarted();
}
}
}
if (this.a.isLeaveActionDesired) {
let c = a.pageX;
let d = a.pageY;
this.a.mouseLeaveCell(c, d);
}
}
}
bo(a, b) {
if (this.a != null && this.a.isEnterActionDesired) {
let c = a.pageX;
let d = a.pageY;
this.a.mouseEnterCell(c, d);
}
}
onDoubleClick(a) {
}
bs(a, b, c) {
switch (a) {
case "Indent":
this.aq = this.a6 * 24;
this.ar = this.a6 > 0 ? 10 : 0;
if (this.ag != null) {
this.ag.setRawXPosition(this.ax + this.aq);
this.ag.setRawYPosition(intDivide(this.at, 2) - intDivide(this.ap, 2));
}
break;
case "IsCollapsable":
if (this.v) {
this.bi();
}
else {
this.by();
}
break;
case "IsExpanded":
if (this.i != null) {
this.i.g = this.w;
}
break;
case "IsHitTestVisible":
this.ah.setRawStyleProperty("pointer-events", this.y ? "auto" : "none");
break;
}
}
br() {
}
bh() {
this.af.focus(true);
}
bf() {
if (this.a != null) {
let a = this.af.clone();
this.a.passCellClone(a);
}
}
detach() {
}
}
GridCellBase.$t = /*@__PURE__*/ markType(GridCellBase, 'GridCellBase', Base.$, [INativeCell_$type]);
GridCellBase.k = null;
GridCellBase.a7 = /*@__PURE__*/ new Random(0);
GridCellBase.a0 = 10;
GridCellBase.ao = 3;
return GridCellBase;
})();