UNPKG

ag-grid-enterprise

Version:

AG Grid Enterprise Features

963 lines (952 loc) 2.08 MB
/** * ag-grid-enterprise - AG Grid Enterprise Features * @version v25.2.0 * @link http://www.ag-grid.com/ ' * @license Commercial */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var agGridCommunity = require('ag-grid-community'); var __extends = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var LicenseManager = /** @class */ (function (_super) { __extends(LicenseManager, _super); function LicenseManager() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.watermarkMessage = undefined; return _this; } LicenseManager_1 = LicenseManager; LicenseManager.prototype.validateLicense = function () { if (agGridCommunity._.missingOrEmpty(LicenseManager_1.licenseKey)) { this.outputMissingLicenseKey(); } else if (LicenseManager_1.licenseKey.length > 32) { var _a = LicenseManager_1.extractLicenseComponents(LicenseManager_1.licenseKey), md5 = _a.md5, license = _a.license, version = _a.version, isTrial = _a.isTrial; if (md5 === this.md5.md5(license)) { if (agGridCommunity._.exists(version) && version) { this.validateLicenseKeyForVersion(version, !!isTrial, license); } else { this.validateLegacyKey(license); } } else { this.outputInvalidLicenseKey(); } } else { this.outputInvalidLicenseKey(); } }; LicenseManager.extractExpiry = function (license) { var restrictionHashed = license.substring(license.lastIndexOf('_') + 1, license.length); return new Date(parseInt(LicenseManager_1.decode(restrictionHashed), 10)); }; LicenseManager.extractLicenseComponents = function (licenseKey) { // when users copy the license key from a PDF extra zero width characters are sometimes copied too // carriage returns and line feeds are problematic too // all of which causes license key validation to fail - strip these out var cleanedLicenseKey = licenseKey.replace(/[\u200B-\u200D\uFEFF]/g, ''); cleanedLicenseKey = cleanedLicenseKey.replace(/\r?\n|\r/g, ''); var hashStart = cleanedLicenseKey.length - 32; var md5 = cleanedLicenseKey.substring(hashStart); var license = cleanedLicenseKey.substring(0, hashStart); var _a = LicenseManager_1.extractBracketedInformation(cleanedLicenseKey), version = _a[0], isTrial = _a[1]; return { md5: md5, license: license, version: version, isTrial: isTrial }; }; LicenseManager.prototype.getLicenseDetails = function (licenseKey) { var _a = LicenseManager_1.extractLicenseComponents(licenseKey), md5 = _a.md5, license = _a.license, version = _a.version, isTrial = _a.isTrial; var valid = (md5 === this.md5.md5(license)); var expiry = null; if (valid) { expiry = LicenseManager_1.extractExpiry(license); valid = !isNaN(expiry.getTime()); } return { licenseKey: licenseKey, valid: valid, expiry: valid ? LicenseManager_1.formatDate(expiry) : null, version: version ? version : 'legacy', isTrial: isTrial }; }; LicenseManager.prototype.isDisplayWatermark = function () { return !agGridCommunity._.missingOrEmpty(this.watermarkMessage); }; LicenseManager.prototype.getWatermarkMessage = function () { return this.watermarkMessage || ''; }; LicenseManager.formatDate = function (date) { var monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; var day = date.getDate(); var monthIndex = date.getMonth(); var year = date.getFullYear(); return day + ' ' + monthNames[monthIndex] + ' ' + year; }; LicenseManager.getGridReleaseDate = function () { return new Date(parseInt(LicenseManager_1.decode(LicenseManager_1.RELEASE_INFORMATION), 10)); }; LicenseManager.decode = function (input) { var keystr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; var t = ''; var n, r, i; var s, o, u, a; var f = 0; var e = input.replace(/[^A-Za-z0-9+/=]/g, ''); while (f < e.length) { s = keystr.indexOf(e.charAt(f++)); o = keystr.indexOf(e.charAt(f++)); u = keystr.indexOf(e.charAt(f++)); a = keystr.indexOf(e.charAt(f++)); n = s << 2 | o >> 4; r = (o & 15) << 4 | u >> 2; i = (u & 3) << 6 | a; t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r); } if (a != 64) { t = t + String.fromCharCode(i); } } t = LicenseManager_1.utf8_decode(t); return t; }; LicenseManager.utf8_decode = function (input) { input = input.replace(/rn/g, 'n'); var t = ''; for (var n = 0; n < input.length; n++) { var r = input.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r); } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192); t += String.fromCharCode(r & 63 | 128); } else { t += String.fromCharCode(r >> 12 | 224); t += String.fromCharCode(r >> 6 & 63 | 128); t += String.fromCharCode(r & 63 | 128); } } return t; }; LicenseManager.setLicenseKey = function (licenseKey) { LicenseManager_1.licenseKey = licenseKey; }; LicenseManager.extractBracketedInformation = function (licenseKey) { var matches = licenseKey.split('[') .filter(function (v) { return v.indexOf(']') > -1; }) .map(function (value) { return value.split(']')[0]; }); if (!matches || matches.length === 0) { return [null, null]; } var isTrial = matches.filter(function (match) { return match === 'TRIAL'; }).length === 1; var version = matches.filter(function (match) { return match.indexOf("v") === 0; }).map(function (match) { return match.replace(/^v/, ""); })[0]; return [version, isTrial]; }; LicenseManager.prototype.validateLicenseKeyForVersion = function (version, isTrial, license) { if (version !== '2') { return; } if (isTrial) { this.validateForTrial(license); } else { this.validateLegacyKey(license); } }; LicenseManager.prototype.validateLegacyKey = function (license) { var gridReleaseDate = LicenseManager_1.getGridReleaseDate(); var expiry = LicenseManager_1.extractExpiry(license); var valid = false; var current = false; if (!isNaN(expiry.getTime())) { valid = true; current = (gridReleaseDate < expiry); } if (!valid) { this.outputInvalidLicenseKey(); } else if (!current) { var formattedExpiryDate = LicenseManager_1.formatDate(expiry); var formattedReleaseDate = LicenseManager_1.formatDate(gridReleaseDate); this.outputIncompatibleVersion(formattedExpiryDate, formattedReleaseDate); } }; LicenseManager.prototype.validateForTrial = function (license) { var expiry = LicenseManager_1.extractExpiry(license); var now = new Date(); var valid = false; var current = false; if (!isNaN(expiry.getTime())) { valid = true; current = (expiry > now); } if (!valid) { this.outputInvalidLicenseKey(); } else if (!current) { var formattedExpiryDate = LicenseManager_1.formatDate(expiry); this.outputExpiredTrialKey(formattedExpiryDate); } }; LicenseManager.prototype.outputInvalidLicenseKey = function () { console.error('*****************************************************************************************************************'); console.error('***************************************** AG Grid Enterprise License ********************************************'); console.error('********************************************* Invalid License ***************************************************'); console.error('* Your license for AG Grid Enterprise is not valid - please contact info@ag-grid.com to obtain a valid license. *'); console.error('*****************************************************************************************************************'); console.error('*****************************************************************************************************************'); this.watermarkMessage = "Invalid License"; }; LicenseManager.prototype.outputExpiredTrialKey = function (formattedExpiryDate) { console.error('****************************************************************************************************************'); console.error('***************************************** AG Grid Enterprise License *******************************************'); console.error('***************************************** Trial Period Expired. *******************************************'); console.error("* Your license for AG Grid Enterprise expired on " + formattedExpiryDate + ". *"); console.error('* Please email info@ag-grid.com to purchase a license. *'); console.error('****************************************************************************************************************'); console.error('****************************************************************************************************************'); this.watermarkMessage = "Trial Period Expired"; }; LicenseManager.prototype.outputMissingLicenseKey = function () { console.error('****************************************************************************************************************'); console.error('***************************************** AG Grid Enterprise License *******************************************'); console.error('****************************************** License Key Not Found ***********************************************'); console.error('* All AG Grid Enterprise features are unlocked. *'); console.error('* This is an evaluation only version, it is not licensed for development projects intended for production. *'); console.error('* If you want to hide the watermark, please email info@ag-grid.com for a trial license. *'); console.error('****************************************************************************************************************'); console.error('****************************************************************************************************************'); this.watermarkMessage = "For Trial Use Only"; }; LicenseManager.prototype.outputIncompatibleVersion = function (formattedExpiryDate, formattedReleaseDate) { console.error('****************************************************************************************************************************'); console.error('****************************************************************************************************************************'); console.error('* AG Grid Enterprise License *'); console.error('* License not compatible with installed version of AG Grid Enterprise. *'); console.error('* *'); console.error("* Your AG Grid License entitles you to all versions of AG Grid that we release within the time covered by your license *"); console.error("* - typically we provide one year licenses which entitles you to all releases / updates of AG Grid within that year. *"); console.error("* Your license has an end (expiry) date which stops the license key working with versions of AG Grid released after the *"); console.error("* license end date. The license key that you have expires on " + formattedExpiryDate + ", however the version of AG Grid you *"); console.error("* are trying to use was released on " + formattedReleaseDate + ". *"); console.error('* *'); console.error('* Please contact info@ag-grid.com to renew your subscription to new versions and get a new license key to work with this *'); console.error('* version of AG Grid. *'); console.error('****************************************************************************************************************************'); console.error('****************************************************************************************************************************'); this.watermarkMessage = "License Expired"; }; var LicenseManager_1; LicenseManager.RELEASE_INFORMATION = 'MTYxOTYxMzM1NTU4Mw=='; __decorate([ agGridCommunity.Autowired('md5') ], LicenseManager.prototype, "md5", void 0); __decorate([ agGridCommunity.PreConstruct ], LicenseManager.prototype, "validateLicense", null); LicenseManager = LicenseManager_1 = __decorate([ agGridCommunity.Bean('licenseManager') ], LicenseManager); return LicenseManager; }(agGridCommunity.BeanStub)); var __extends$1 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var MD5 = /** @class */ (function (_super) { __extends$1(MD5, _super); function MD5() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.ieCompatibility = false; return _this; } MD5.prototype.init = function () { this.ieCompatibility = (this.md5('hello') != '5d41402abc4b2a76b9719d911017c592'); }; MD5.prototype.md5cycle = function (x, k) { var a = x[0], b = x[1], c = x[2], d = x[3]; a = this.ff(a, b, c, d, k[0], 7, -680876936); d = this.ff(d, a, b, c, k[1], 12, -389564586); c = this.ff(c, d, a, b, k[2], 17, 606105819); b = this.ff(b, c, d, a, k[3], 22, -1044525330); a = this.ff(a, b, c, d, k[4], 7, -176418897); d = this.ff(d, a, b, c, k[5], 12, 1200080426); c = this.ff(c, d, a, b, k[6], 17, -1473231341); b = this.ff(b, c, d, a, k[7], 22, -45705983); a = this.ff(a, b, c, d, k[8], 7, 1770035416); d = this.ff(d, a, b, c, k[9], 12, -1958414417); c = this.ff(c, d, a, b, k[10], 17, -42063); b = this.ff(b, c, d, a, k[11], 22, -1990404162); a = this.ff(a, b, c, d, k[12], 7, 1804603682); d = this.ff(d, a, b, c, k[13], 12, -40341101); c = this.ff(c, d, a, b, k[14], 17, -1502002290); b = this.ff(b, c, d, a, k[15], 22, 1236535329); a = this.gg(a, b, c, d, k[1], 5, -165796510); d = this.gg(d, a, b, c, k[6], 9, -1069501632); c = this.gg(c, d, a, b, k[11], 14, 643717713); b = this.gg(b, c, d, a, k[0], 20, -373897302); a = this.gg(a, b, c, d, k[5], 5, -701558691); d = this.gg(d, a, b, c, k[10], 9, 38016083); c = this.gg(c, d, a, b, k[15], 14, -660478335); b = this.gg(b, c, d, a, k[4], 20, -405537848); a = this.gg(a, b, c, d, k[9], 5, 568446438); d = this.gg(d, a, b, c, k[14], 9, -1019803690); c = this.gg(c, d, a, b, k[3], 14, -187363961); b = this.gg(b, c, d, a, k[8], 20, 1163531501); a = this.gg(a, b, c, d, k[13], 5, -1444681467); d = this.gg(d, a, b, c, k[2], 9, -51403784); c = this.gg(c, d, a, b, k[7], 14, 1735328473); b = this.gg(b, c, d, a, k[12], 20, -1926607734); a = this.hh(a, b, c, d, k[5], 4, -378558); d = this.hh(d, a, b, c, k[8], 11, -2022574463); c = this.hh(c, d, a, b, k[11], 16, 1839030562); b = this.hh(b, c, d, a, k[14], 23, -35309556); a = this.hh(a, b, c, d, k[1], 4, -1530992060); d = this.hh(d, a, b, c, k[4], 11, 1272893353); c = this.hh(c, d, a, b, k[7], 16, -155497632); b = this.hh(b, c, d, a, k[10], 23, -1094730640); a = this.hh(a, b, c, d, k[13], 4, 681279174); d = this.hh(d, a, b, c, k[0], 11, -358537222); c = this.hh(c, d, a, b, k[3], 16, -722521979); b = this.hh(b, c, d, a, k[6], 23, 76029189); a = this.hh(a, b, c, d, k[9], 4, -640364487); d = this.hh(d, a, b, c, k[12], 11, -421815835); c = this.hh(c, d, a, b, k[15], 16, 530742520); b = this.hh(b, c, d, a, k[2], 23, -995338651); a = this.ii(a, b, c, d, k[0], 6, -198630844); d = this.ii(d, a, b, c, k[7], 10, 1126891415); c = this.ii(c, d, a, b, k[14], 15, -1416354905); b = this.ii(b, c, d, a, k[5], 21, -57434055); a = this.ii(a, b, c, d, k[12], 6, 1700485571); d = this.ii(d, a, b, c, k[3], 10, -1894986606); c = this.ii(c, d, a, b, k[10], 15, -1051523); b = this.ii(b, c, d, a, k[1], 21, -2054922799); a = this.ii(a, b, c, d, k[8], 6, 1873313359); d = this.ii(d, a, b, c, k[15], 10, -30611744); c = this.ii(c, d, a, b, k[6], 15, -1560198380); b = this.ii(b, c, d, a, k[13], 21, 1309151649); a = this.ii(a, b, c, d, k[4], 6, -145523070); d = this.ii(d, a, b, c, k[11], 10, -1120210379); c = this.ii(c, d, a, b, k[2], 15, 718787259); b = this.ii(b, c, d, a, k[9], 21, -343485551); x[0] = this.add32(a, x[0]); x[1] = this.add32(b, x[1]); x[2] = this.add32(c, x[2]); x[3] = this.add32(d, x[3]); }; MD5.prototype.cmn = function (q, a, b, x, s, t) { a = this.add32(this.add32(a, q), this.add32(x, t)); return this.add32((a << s) | (a >>> (32 - s)), b); }; MD5.prototype.ff = function (a, b, c, d, x, s, t) { return this.cmn((b & c) | ((~b) & d), a, b, x, s, t); }; MD5.prototype.gg = function (a, b, c, d, x, s, t) { return this.cmn((b & d) | (c & (~d)), a, b, x, s, t); }; MD5.prototype.hh = function (a, b, c, d, x, s, t) { return this.cmn(b ^ c ^ d, a, b, x, s, t); }; MD5.prototype.ii = function (a, b, c, d, x, s, t) { return this.cmn(c ^ (b | (~d)), a, b, x, s, t); }; MD5.prototype.md51 = function (s) { var n = s.length; var state = [1732584193, -271733879, -1732584194, 271733878]; var i; for (i = 64; i <= s.length; i += 64) { this.md5cycle(state, this.md5blk(s.substring(i - 64, i))); } s = s.substring(i - 64); var tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; for (i = 0; i < s.length; i++) { tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3); } tail[i >> 2] |= 0x80 << ((i % 4) << 3); if (i > 55) { this.md5cycle(state, tail); for (i = 0; i < 16; i++) { tail[i] = 0; } } tail[14] = n * 8; this.md5cycle(state, tail); return state; }; /* there needs to be support for Unicode here, * unless we pretend that we can redefine the MD-5 * algorithm for multi-byte characters (perhaps by adding every four 16-bit characters and * shortening the sum to 32 bits). Otherwise I suthis.ggest performing MD-5 as if every character * was two bytes--e.g., 0040 0025 = @%--but then how will an ordinary MD-5 sum be matched? * There is no way to standardize text to something like UTF-8 before transformation; speed cost is * utterly prohibitive. The JavaScript standard itself needs to look at this: it should start * providing access to strings as preformed UTF-8 8-bit unsigned value arrays. */ MD5.prototype.md5blk = function (s) { var md5blks = []; /* Andy King said do it this way. */ for (var i = 0; i < 64; i += 4) { md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24); } return md5blks; }; MD5.prototype.rhex = function (n) { var hex_chr = '0123456789abcdef'.split(''); var s = '', j = 0; for (; j < 4; j++) { s += hex_chr[(n >> (j * 8 + 4)) & 0x0F] + hex_chr[(n >> (j * 8)) & 0x0F]; } return s; }; MD5.prototype.hex = function (x) { for (var i = 0; i < x.length; i++) { x[i] = this.rhex(x[i]); } return x.join(''); }; MD5.prototype.md5 = function (s) { return this.hex(this.md51(s)); }; MD5.prototype.add32 = function (a, b) { return this.ieCompatibility ? this.add32Compat(a, b) : this.add32Std(a, b); }; /* this function is much faster, so if possible we use it. Some IEs are the only ones I know of that need the idiotic second function, generated by an if clause. */ MD5.prototype.add32Std = function (a, b) { return (a + b) & 0xFFFFFFFF; }; MD5.prototype.add32Compat = function (x, y) { var lsw = (x & 0xFFFF) + (y & 0xFFFF), msw = (x >> 16) + (y >> 16) + (lsw >> 16); return (msw << 16) | (lsw & 0xFFFF); }; __decorate$1([ agGridCommunity.PostConstruct ], MD5.prototype, "init", null); MD5 = __decorate$1([ agGridCommunity.Bean('md5') ], MD5); return MD5; }(agGridCommunity.BeanStub)); var __extends$2 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var WatermarkComp = /** @class */ (function (_super) { __extends$2(WatermarkComp, _super); function WatermarkComp() { return _super.call(this, "<div class=\"ag-watermark\">\n <div ref=\"eLicenseTextRef\" class=\"ag-watermark-text\"></div>\n </div>") || this; } WatermarkComp.prototype.postConstruct = function () { var _this = this; var show = this.shouldDisplayWatermark(); agGridCommunity._.addOrRemoveCssClass(this.getGui(), 'ag-hidden', !show); if (show) { this.eLicenseTextRef.innerText = this.licenseManager.getWatermarkMessage(); window.setTimeout(function () { return _this.addCssClass('ag-opacity-zero'); }, 0); window.setTimeout(function () { return _this.addCssClass('ag-hidden'); }, 5000); } }; WatermarkComp.prototype.shouldDisplayWatermark = function () { var isDisplayWatermark = this.licenseManager.isDisplayWatermark(); var isWhiteListURL = location.hostname.match('^127\.0\.0\.1|localhost|www\.ag-grid\.com$') != null; var isForceWatermark = location.pathname ? location.pathname.indexOf('forceWatermark') !== -1 : false; return isForceWatermark || (isDisplayWatermark && !isWhiteListURL); }; __decorate$2([ agGridCommunity.Autowired('licenseManager') ], WatermarkComp.prototype, "licenseManager", void 0); __decorate$2([ agGridCommunity.RefSelector('eLicenseTextRef') ], WatermarkComp.prototype, "eLicenseTextRef", void 0); __decorate$2([ agGridCommunity.PostConstruct ], WatermarkComp.prototype, "postConstruct", null); return WatermarkComp; }(agGridCommunity.Component)); var EnterpriseCoreModule = { moduleName: agGridCommunity.ModuleNames.EnterpriseCoreModule, beans: [LicenseManager, MD5], agStackComponents: [ { componentName: 'AgWatermark', componentClass: WatermarkComp } ] }; var __extends$3 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var ExpandState; (function (ExpandState) { ExpandState[ExpandState["EXPANDED"] = 0] = "EXPANDED"; ExpandState[ExpandState["COLLAPSED"] = 1] = "COLLAPSED"; ExpandState[ExpandState["INDETERMINATE"] = 2] = "INDETERMINATE"; })(ExpandState || (ExpandState = {})); var PrimaryColsHeaderPanel = /** @class */ (function (_super) { __extends$3(PrimaryColsHeaderPanel, _super); function PrimaryColsHeaderPanel() { return _super.call(this, PrimaryColsHeaderPanel.TEMPLATE) || this; } PrimaryColsHeaderPanel.prototype.postConstruct = function () { var _this = this; this.createExpandIcons(); this.addManagedListener(this.eExpand, 'click', this.onExpandClicked.bind(this)); this.addManagedListener(this.eExpand, 'keydown', function (e) { if (e.keyCode === agGridCommunity.KeyCode.SPACE) { _this.onExpandClicked(); } }); this.addManagedListener(this.eSelect.getInputElement(), 'click', this.onSelectClicked.bind(this)); this.eFilterTextField.onValueChange(function () { return _this.onFilterTextChanged(); }); this.addManagedListener(this.eFilterTextField.getInputElement(), 'keypress', this.onMiniFilterKeyPress.bind(this)); this.addManagedListener(this.eventService, agGridCommunity.Events.EVENT_NEW_COLUMNS_LOADED, this.showOrHideOptions.bind(this)); var translate = this.gridOptionsWrapper.getLocaleTextFunc(); this.eSelect.setInputAriaLabel(translate('ariaColumnSelectAll', 'Toggle Select All Columns')); this.eFilterTextField.setInputAriaLabel(translate('ariaFilterColumnsInput', 'Filter Columns Input')); }; PrimaryColsHeaderPanel.prototype.init = function (params) { this.params = params; if (this.columnController.isReady()) { this.showOrHideOptions(); } }; PrimaryColsHeaderPanel.prototype.createExpandIcons = function () { this.eExpand.appendChild((this.eExpandChecked = agGridCommunity._.createIconNoSpan('columnSelectOpen', this.gridOptionsWrapper))); this.eExpand.appendChild((this.eExpandUnchecked = agGridCommunity._.createIconNoSpan('columnSelectClosed', this.gridOptionsWrapper))); this.eExpand.appendChild((this.eExpandIndeterminate = agGridCommunity._.createIconNoSpan('columnSelectIndeterminate', this.gridOptionsWrapper))); this.setExpandState(ExpandState.EXPANDED); }; // we only show expand / collapse if we are showing columns PrimaryColsHeaderPanel.prototype.showOrHideOptions = function () { var showFilter = !this.params.suppressColumnFilter; var showSelect = !this.params.suppressColumnSelectAll; var showExpand = !this.params.suppressColumnExpandAll; var groupsPresent = this.columnController.isPrimaryColumnGroupsPresent(); var translate = this.gridOptionsWrapper.getLocaleTextFunc(); this.eFilterTextField.setInputPlaceholder(translate('searchOoo', 'Search...')); agGridCommunity._.setDisplayed(this.eFilterTextField.getGui(), showFilter); agGridCommunity._.setDisplayed(this.eSelect.getGui(), showSelect); agGridCommunity._.setDisplayed(this.eExpand, showExpand && groupsPresent); }; PrimaryColsHeaderPanel.prototype.onFilterTextChanged = function () { var _this = this; if (!this.onFilterTextChangedDebounced) { this.onFilterTextChangedDebounced = agGridCommunity._.debounce(function () { var filterText = _this.eFilterTextField.getValue(); _this.dispatchEvent({ type: "filterChanged", filterText: filterText }); }, PrimaryColsHeaderPanel.DEBOUNCE_DELAY); } this.onFilterTextChangedDebounced(); }; PrimaryColsHeaderPanel.prototype.onMiniFilterKeyPress = function (e) { var _this = this; if (agGridCommunity._.isKeyPressed(e, agGridCommunity.KeyCode.ENTER)) { // we need to add a delay that corresponds to the filter text debounce delay to ensure // the text filtering has happened, otherwise all columns will be deselected setTimeout(function () { return _this.onSelectClicked(); }, PrimaryColsHeaderPanel.DEBOUNCE_DELAY); } }; PrimaryColsHeaderPanel.prototype.onSelectClicked = function () { this.dispatchEvent({ type: this.selectState ? 'unselectAll' : 'selectAll' }); }; PrimaryColsHeaderPanel.prototype.onExpandClicked = function () { this.dispatchEvent({ type: this.expandState === ExpandState.EXPANDED ? 'collapseAll' : 'expandAll' }); }; PrimaryColsHeaderPanel.prototype.setExpandState = function (state) { this.expandState = state; agGridCommunity._.setDisplayed(this.eExpandChecked, this.expandState === ExpandState.EXPANDED); agGridCommunity._.setDisplayed(this.eExpandUnchecked, this.expandState === ExpandState.COLLAPSED); agGridCommunity._.setDisplayed(this.eExpandIndeterminate, this.expandState === ExpandState.INDETERMINATE); }; PrimaryColsHeaderPanel.prototype.setSelectionState = function (state) { this.selectState = state; this.eSelect.setValue(this.selectState); }; PrimaryColsHeaderPanel.DEBOUNCE_DELAY = 300; PrimaryColsHeaderPanel.TEMPLATE = "<div class=\"ag-column-select-header\" role=\"presentation\" tabindex=\"-1\">\n <div ref=\"eExpand\" class=\"ag-column-select-header-icon\" tabindex=\"0\"></div>\n <ag-checkbox ref=\"eSelect\" class=\"ag-column-select-header-checkbox\"></ag-checkbox>\n <ag-input-text-field class=\"ag-column-select-header-filter-wrapper\" ref=\"eFilterTextField\"></ag-input-text-field>\n </div>"; __decorate$3([ agGridCommunity.Autowired('columnController') ], PrimaryColsHeaderPanel.prototype, "columnController", void 0); __decorate$3([ agGridCommunity.RefSelector('eExpand') ], PrimaryColsHeaderPanel.prototype, "eExpand", void 0); __decorate$3([ agGridCommunity.RefSelector('eSelect') ], PrimaryColsHeaderPanel.prototype, "eSelect", void 0); __decorate$3([ agGridCommunity.RefSelector('eFilterTextField') ], PrimaryColsHeaderPanel.prototype, "eFilterTextField", void 0); __decorate$3([ agGridCommunity.PostConstruct ], PrimaryColsHeaderPanel.prototype, "postConstruct", null); return PrimaryColsHeaderPanel; }(agGridCommunity.Component)); var ColumnModelItem = /** @class */ (function () { function ColumnModelItem(displayName, columnOrGroup, dept, group, expanded) { if (group === void 0) { group = false; } this.eventService = new agGridCommunity.EventService(); this.displayName = displayName; this.dept = dept; this.group = group; if (group) { this.columnGroup = columnOrGroup; this.expanded = expanded; this.children = []; } else { this.column = columnOrGroup; } } ColumnModelItem.prototype.isGroup = function () { return this.group; }; ColumnModelItem.prototype.getDisplayName = function () { return this.displayName; }; ColumnModelItem.prototype.getColumnGroup = function () { return this.columnGroup; }; ColumnModelItem.prototype.getColumn = function () { return this.column; }; ColumnModelItem.prototype.getDept = function () { return this.dept; }; ColumnModelItem.prototype.isExpanded = function () { return !!this.expanded; }; ColumnModelItem.prototype.getChildren = function () { return this.children; }; ColumnModelItem.prototype.isPassesFilter = function () { return this.passesFilter; }; ColumnModelItem.prototype.setExpanded = function (expanded) { if (expanded === this.expanded) { return; } this.expanded = expanded; this.eventService.dispatchEvent({ type: ColumnModelItem.EVENT_EXPANDED_CHANGED }); }; ColumnModelItem.prototype.setPassesFilter = function (passesFilter) { this.passesFilter = passesFilter; }; ColumnModelItem.prototype.addEventListener = function (eventType, listener) { this.eventService.addEventListener(eventType, listener); }; ColumnModelItem.prototype.removeEventListener = function (eventType, listener) { this.eventService.removeEventListener(eventType, listener); }; ColumnModelItem.EVENT_EXPANDED_CHANGED = 'expandedChanged'; return ColumnModelItem; }()); var __extends$4 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate$4 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var ToolPanelColumnGroupComp = /** @class */ (function (_super) { __extends$4(ToolPanelColumnGroupComp, _super); function ToolPanelColumnGroupComp(modelItem, allowDragging, eventType, focusWrapper) { var _this = _super.call(this) || this; _this.modelItem = modelItem; _this.allowDragging = allowDragging; _this.eventType = eventType; _this.focusWrapper = focusWrapper; _this.processingColumnStateChange = false; _this.modelItem = modelItem; _this.columnGroup = modelItem.getColumnGroup(); _this.columnDept = modelItem.getDept(); _this.allowDragging = allowDragging; return _this; } ToolPanelColumnGroupComp.prototype.init = function () { this.setTemplate(ToolPanelColumnGroupComp.TEMPLATE); this.eDragHandle = agGridCommunity._.createIconNoSpan('columnDrag', this.gridOptionsWrapper); agGridCommunity._.addCssClass(this.eDragHandle, 'ag-drag-handle'); agGridCommunity._.addCssClass(this.eDragHandle, 'ag-column-select-column-group-drag-handle'); this.cbSelect.getGui().insertAdjacentElement('afterend', this.eDragHandle); this.displayName = this.columnController.getDisplayNameForOriginalColumnGroup(null, this.columnGroup, this.eventType); if (agGridCommunity._.missing(this.displayName)) { this.displayName = '>>'; } this.eLabel.innerHTML = this.displayName ? this.displayName : ''; this.setupExpandContract(); this.addCssClass('ag-column-select-indent-' + this.columnDept); this.addManagedListener(this.eventService, agGridCommunity.Events.EVENT_COLUMN_PIVOT_MODE_CHANGED, this.onColumnStateChanged.bind(this)); this.addManagedListener(this.eLabel, 'click', this.onLabelClicked.bind(this)); this.addManagedListener(this.cbSelect, agGridCommunity.AgCheckbox.EVENT_CHANGED, this.onCheckboxChanged.bind(this)); this.addManagedListener(this.modelItem, ColumnModelItem.EVENT_EXPANDED_CHANGED, this.onExpandChanged.bind(this)); this.addManagedListener(this.focusWrapper, 'keydown', this.handleKeyDown.bind(this)); this.setOpenClosedIcons(); this.setupDragging(); this.onColumnStateChanged(); this.addVisibilityListenersToAllChildren(); this.refreshAriaExpanded(); this.refreshAriaLabel(); this.setupTooltip(); agGridCommunity.CssClassApplier.addToolPanelClassesFromColDef(this.columnGroup.getColGroupDef(), this.getGui(), this.gridOptionsWrapper, null, this.columnGroup); }; ToolPanelColumnGroupComp.prototype.setupTooltip = function () { var _this = this; var colGroupDef = this.columnGroup.getColGroupDef(); if (!colGroupDef) { return; } var refresh = function () { var newTooltipText = colGroupDef.headerTooltip; _this.setTooltip(agGridCommunity._.escapeString(newTooltipText)); }; refresh(); this.addManagedListener(this.eventService, agGridCommunity.Events.EVENT_NEW_COLUMNS_LOADED, refresh); }; ToolPanelColumnGroupComp.prototype.getTooltipParams = function () { var res = _super.prototype.getTooltipParams.call(this); res.location = 'columnToolPanelColumnGroup'; return res; }; ToolPanelColumnGroupComp.prototype.handleKeyDown = function (e) { switch (e.keyCode) { case agGridCommunity.KeyCode.LEFT: e.preventDefault(); this.modelItem.setExpanded(false); break; case agGridCommunity.KeyCode.RIGHT: e.preventDefault(); this.modelItem.setExpanded(true); break; case agGridCommunity.KeyCode.SPACE: e.preventDefault(); if (this.isSelectable()) { this.onSelectAllChanged(!this.isSelected()); } break; } }; ToolPanelColumnGroupComp.prototype.addVisibilityListenersToAllChildren = function () { var _this = this; this.columnGroup.getLeafColumns().forEach(function (column) { _this.addManagedListener(column, agGridCommunity.Column.EVENT_VISIBLE_CHANGED, _this.onColumnStateChanged.bind(_this)); _this.addManagedListener(column, agGridCommunity.Column.EVENT_VALUE_CHANGED, _this.onColumnStateChanged.bind(_this)); _this.addManagedListener(column, agGridCommunity.Column.EVENT_PIVOT_CHANGED, _this.onColumnStateChanged.bind(_this)); _this.addManagedListener(column, agGridCommunity.Column.EVENT_ROW_GROUP_CHANGED, _this.onColumnStateChanged.bind(_this)); }); }; ToolPanelColumnGroupComp.prototype.setupDragging = function () { var _this = this; if (!this.allowDragging) { agGridCommunity._.setDisplayed(this.eDragHandle, false); return; } var dragSource = { type: agGridCommunity.DragSourceType.ToolPanel, eElement: this.eDragHandle, dragItemName: this.displayName, getDragItem: function () { return _this.createDragItem(); } }; this.dragAndDropService.addDragSource(dragSource, true); this.addDestroyFunc(function () { return _this.dragAndDropService.removeDragSource(dragSource); }); }; ToolPanelColumnGroupComp.prototype.createDragItem = function () { var visibleState = {}; this.columnGroup.getLeafColumns().forEach(function (col) { visibleState[col.getId()] = col.isVisible(); }); return { columns: this.columnGroup.getLeafColumns(), visibleState: visibleState }; }; ToolPanelColumnGroupComp.prototype.setupExpandContract = function () { this.eGroupClosedIcon.appendChild(agGridCommunity._.createIcon('columnSelectClosed', this.gridOptionsWrapper, null)); this.eGroupOpenedIcon.appendChild(agGridCommunity._.createIcon('columnSelectOpen', this.gridOptionsWrapper, null)); this.addManagedListener(this.eGroupClosedIcon, 'click', this.onExpandOrContractClicked.bind(this)); this.addManagedListener(this.eGroupOpenedIcon, 'click', this.onExpandOrContractClicked.bind(this)); var touchListener = new agGridCommunity.TouchListener(this.eColumnGroupIcons, true); this.addManagedListener(touchListener, agGridCommunity.TouchListener.EVENT_TAP, this.onExpandOrContractClicked.bind(this)); this.addDestroyFunc(touchListener.destroy.bind(touchListener)); }; ToolPanelColumnGroupComp.prototype.onLabelClicked = function () { var nextState = !this.cbSelect.getValue(); this.onChangeCommon(nextState); }; ToolPanelColumnGroupComp.prototype.onCheckboxChanged = function (event) { this.onChangeCommon(event.selected); }; ToolPanelColumnGroupComp.prototype.getVisibleLeafColumns = function () { var childColumns = []; var extractCols = function (children) { children.forEach(function (child) { if (!child.isPassesFilter()) { return; } if (child.isGroup()) { extractCols(child.getChildren()); } else { childColumns.push(child.getColumn()); } }); }; extractCols(this.modelItem.getChildren()); return childColumns; }; ToolPanelColumnGroupComp.prototype.onChangeCommon = function (nextState) { this.refreshAriaLabel(); if (this.processingColumnStateChange) { return; } this.modelItemUtils.selectAllChildren(this.modelItem.getChildren(), nextState, this.eventType); }; ToolPanelColumnGroupComp.prototype.refreshAriaLabel = function () { var translate = this.gridOptionsWrapper.getLocaleTextFunc(); var state = this.cbSelect.getValue() ? translate('ariaVisible', 'visible') : translate('ariaHidden', 'hidden'); var label = translate('ariaColumnGroupToggleVisibility', 'column group toggle visibility'); agGridCommunity._.setAriaLabel(this.focusWrapper, this.displayName + " " + label + " (" + state + ")"); }; ToolPanelColumnGroupComp.prototype.onColumnStateChanged = function () { var selectedValue = this.workOutSelectedValue(); var readOnlyValue = this.workOutReadOnlyValue(); this.processingColumnStateChange = true; this.cbSelect.setValue(selectedValue); this.cbSelect.setReadOnly(readOnlyValue); agGridCommunity._.addOrRemoveCssClass(this.getGui(), 'ag-column-select-column-group-readonly', readOnlyValue); this.processingColumnStateChange = false; }; ToolPanelColumnGroupComp.prototype.workOutSelectedValue = function () { var _this = this; var pivotMode = this.columnController.isPivotMode(); var visibleLeafColumns = this.getVisibleLeafColumns(); var checkedCount = 0; var uncheckedCount = 0; visibleLeafColumns.forEach(function (column) { if (!pivotMode && column.getColDef().lockVisible) { return; } if (_this.isColumnChecked(column, pivotMode)) { checkedCount++; } else { uncheckedCount++; } }); if (checkedCount > 0 && uncheckedCount > 0) { return undefined; } else { return checkedCount > 0; } }; ToolPanelColumnGroupComp.prototype.workOutReadOnlyValue = function () { var pivotMode = this.columnController.isPivotMode(); var colsThatCanAction = 0; this.columnGroup.getLeafColumns().forEach(function (col) { if (pivotMode) { if (col.isAnyFunctionAllowed()) { colsThatCanAction++; } } else { if (!col.getColDef().lockVisible) { colsThatCanAction++; } } }); return colsThatCanAction === 0; }; ToolPanelColumnGroupComp.prototype.isColumnChecked = function (column, pivotMode) { if (pivotMode) { var pivoted = column.isPivotActive(); var grouped = column.isRowGroupActive(); var aggregated = column.isValueActive(); return pivoted || grouped || aggregated; } else { return column.isVisible(); } }; ToolPanelColumnGroupComp.prototype.onExpandOrContractClicked = function () { var oldState = this.modelItem.isExpanded(); this.modelItem.setExpanded(!oldState); }; ToolPanelColumnGroupComp.prototype.onExpandChanged = function () { this.setOpenClosedIcons(); this.refreshAriaExpanded(); }; ToolPanelColumnGroupComp.prototype.setOpenClosedIcons = function () { var folderOpen = this.modelItem.isExpanded(); agGridCommunity._.setDisplayed(this.eGroupClosedIcon, !folderOpen);