ag-grid-community
Version:
Advanced Data Grid / Data Table supporting Javascript / Typescript / React / Angular / Vue
1,447 lines (1,430 loc) • 1.89 MB
JavaScript
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __decorateClass = (decorators, target, key, kind) => {
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
for (var i = decorators.length - 1, decorator; i >= 0; i--)
if (decorator = decorators[i])
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
if (kind && result)
__defProp(target, key, result);
return result;
};
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
// community-modules/core/src/utils/generic.ts
var generic_exports = {};
__export(generic_exports, {
attrToBoolean: () => attrToBoolean,
attrToNumber: () => attrToNumber,
attrToString: () => attrToString,
defaultComparator: () => defaultComparator,
exists: () => exists,
jsonEquals: () => jsonEquals,
makeNull: () => makeNull,
missing: () => missing,
missingOrEmpty: () => missingOrEmpty,
toStringOrNull: () => toStringOrNull,
values: () => values
});
function makeNull(value) {
if (value == null || value === "") {
return null;
}
return value;
}
function exists(value, allowEmptyString = false) {
return value != null && (value !== "" || allowEmptyString);
}
function missing(value) {
return !exists(value);
}
function missingOrEmpty(value) {
return value == null || value.length === 0;
}
function toStringOrNull(value) {
return value != null && typeof value.toString === "function" ? value.toString() : null;
}
function attrToNumber(value) {
if (value === void 0) {
return;
}
if (value === null || value === "") {
return null;
}
if (typeof value === "number") {
return isNaN(value) ? void 0 : value;
}
const valueParsed = parseInt(value, 10);
return isNaN(valueParsed) ? void 0 : valueParsed;
}
function attrToBoolean(value) {
if (value === void 0) {
return;
}
if (value === null || value === "") {
return false;
}
if (typeof value === "boolean") {
return value;
}
return /true/i.test(value);
}
function attrToString(value) {
if (value == null || value === "") {
return;
}
return value;
}
function jsonEquals(val1, val2) {
const val1Json = val1 ? JSON.stringify(val1) : null;
const val2Json = val2 ? JSON.stringify(val2) : null;
return val1Json === val2Json;
}
function defaultComparator(valueA, valueB, accentedCompare = false) {
const valueAMissing = valueA == null;
const valueBMissing = valueB == null;
if (valueA && valueA.toNumber) {
valueA = valueA.toNumber();
}
if (valueB && valueB.toNumber) {
valueB = valueB.toNumber();
}
if (valueAMissing && valueBMissing) {
return 0;
}
if (valueAMissing) {
return -1;
}
if (valueBMissing) {
return 1;
}
function doQuickCompare(a, b) {
return a > b ? 1 : a < b ? -1 : 0;
}
if (typeof valueA !== "string") {
return doQuickCompare(valueA, valueB);
}
if (!accentedCompare) {
return doQuickCompare(valueA, valueB);
}
try {
return valueA.localeCompare(valueB);
} catch (e) {
return doQuickCompare(valueA, valueB);
}
}
function values(object) {
if (object instanceof Set || object instanceof Map) {
const arr = [];
object.forEach((value) => arr.push(value));
return arr;
}
return Object.values(object);
}
// community-modules/core/src/columns/columnKeyCreator.ts
var ColumnKeyCreator = class {
constructor() {
this.existingKeys = {};
}
addExistingKeys(keys2) {
for (let i = 0; i < keys2.length; i++) {
this.existingKeys[keys2[i]] = true;
}
}
getUniqueKey(colId, colField) {
colId = toStringOrNull(colId);
let count = 0;
while (true) {
let idToTry;
if (colId) {
idToTry = colId;
if (count !== 0) {
idToTry += "_" + count;
}
} else if (colField) {
idToTry = colField;
if (count !== 0) {
idToTry += "_" + count;
}
} else {
idToTry = count;
}
if (!this.existingKeys[idToTry]) {
this.existingKeys[idToTry] = true;
return String(idToTry);
}
count++;
}
}
};
// community-modules/core/src/utils/object.ts
var object_exports = {};
__export(object_exports, {
cloneObject: () => cloneObject,
deepCloneDefinition: () => deepCloneDefinition,
getAllValuesInObject: () => getAllValuesInObject,
getValueUsingField: () => getValueUsingField,
isNonNullObject: () => isNonNullObject,
iterateObject: () => iterateObject,
mergeDeep: () => mergeDeep,
removeAllReferences: () => removeAllReferences
});
function iterateObject(object, callback) {
if (object == null) {
return;
}
if (Array.isArray(object)) {
for (let i = 0; i < object.length; i++) {
callback(i.toString(), object[i]);
}
return;
}
for (const [key, value] of Object.entries(object)) {
callback(key, value);
}
}
function cloneObject(object) {
const copy = {};
const keys2 = Object.keys(object);
for (let i = 0; i < keys2.length; i++) {
const key = keys2[i];
const value = object[key];
copy[key] = value;
}
return copy;
}
function deepCloneDefinition(object, keysToSkip) {
if (!object) {
return;
}
const obj = object;
const res = {};
Object.keys(obj).forEach((key) => {
if (keysToSkip && keysToSkip.indexOf(key) >= 0) {
return;
}
const value = obj[key];
const sourceIsSimpleObject = isNonNullObject(value) && value.constructor === Object;
if (sourceIsSimpleObject) {
res[key] = deepCloneDefinition(value);
} else {
res[key] = value;
}
});
return res;
}
function getAllValuesInObject(obj) {
if (!obj) {
return [];
}
const anyObject = Object;
if (typeof anyObject.values === "function") {
return anyObject.values(obj);
}
const ret = [];
for (const key in obj) {
if (obj.hasOwnProperty(key) && obj.propertyIsEnumerable(key)) {
ret.push(obj[key]);
}
}
return ret;
}
function mergeDeep(dest, source, copyUndefined = true, makeCopyOfSimpleObjects = false) {
if (!exists(source)) {
return;
}
iterateObject(source, (key, sourceValue) => {
let destValue = dest[key];
if (destValue === sourceValue) {
return;
}
if (makeCopyOfSimpleObjects) {
const objectIsDueToBeCopied = destValue == null && sourceValue != null;
if (objectIsDueToBeCopied) {
const sourceIsSimpleObject = typeof sourceValue === "object" && sourceValue.constructor === Object;
const dontCopy = sourceIsSimpleObject;
if (dontCopy) {
destValue = {};
dest[key] = destValue;
}
}
}
if (isNonNullObject(sourceValue) && isNonNullObject(destValue) && !Array.isArray(destValue)) {
mergeDeep(destValue, sourceValue, copyUndefined, makeCopyOfSimpleObjects);
} else if (copyUndefined || sourceValue !== void 0) {
dest[key] = sourceValue;
}
});
}
function getValueUsingField(data, field, fieldContainsDots) {
if (!field || !data) {
return;
}
if (!fieldContainsDots) {
return data[field];
}
const fields = field.split(".");
let currentObject = data;
for (let i = 0; i < fields.length; i++) {
if (currentObject == null) {
return void 0;
}
currentObject = currentObject[fields[i]];
}
return currentObject;
}
function removeAllReferences(obj, preserveKeys = [], preDestroyLink) {
Object.keys(obj).forEach((key) => {
const value = obj[key];
if (typeof value === "object" && !preserveKeys.includes(key)) {
obj[key] = void 0;
}
});
const proto = Object.getPrototypeOf(obj);
const properties = {};
const msgFunc = (key) => `AG Grid: Grid API function ${key}() cannot be called as the grid has been destroyed.
It is recommended to remove local references to the grid api. Alternatively, check gridApi.isDestroyed() to avoid calling methods against a destroyed grid.
To run logic when the grid is about to be destroyed use the gridPreDestroy event. See: ${preDestroyLink}`;
Object.getOwnPropertyNames(proto).forEach((key) => {
const value = proto[key];
if (typeof value === "function" && !preserveKeys.includes(key)) {
const func = () => {
console.warn(msgFunc(key));
};
properties[key] = { value: func, writable: true };
}
});
Object.defineProperties(obj, properties);
}
function isNonNullObject(value) {
return typeof value === "object" && value !== null;
}
// community-modules/core/src/utils/function.ts
var function_exports = {};
__export(function_exports, {
compose: () => compose,
debounce: () => debounce,
doOnce: () => doOnce,
errorOnce: () => errorOnce,
executeAfter: () => executeAfter,
executeInAWhile: () => executeInAWhile,
executeNextVMTurn: () => executeNextVMTurn,
getFunctionName: () => getFunctionName,
isFunction: () => isFunction,
noop: () => noop,
throttle: () => throttle,
waitUntil: () => waitUntil,
warnOnce: () => warnOnce
});
var doOnceFlags = {};
function doOnce(func, key) {
if (doOnceFlags[key]) {
return;
}
func();
doOnceFlags[key] = true;
}
function warnOnce(msg) {
doOnce(() => console.warn("AG Grid: " + msg), msg);
}
function errorOnce(msg) {
doOnce(() => console.error("AG Grid: " + msg), msg);
}
function getFunctionName(funcConstructor) {
if (funcConstructor.name) {
return funcConstructor.name;
}
const matches = /function\s+([^\(]+)/.exec(funcConstructor.toString());
return matches && matches.length === 2 ? matches[1].trim() : null;
}
function isFunction(val) {
return !!(val && val.constructor && val.call && val.apply);
}
function executeInAWhile(funcs) {
executeAfter(funcs, 400);
}
var executeNextVMTurnFuncs = [];
var executeNextVMTurnPending = false;
function executeNextVMTurn(func) {
executeNextVMTurnFuncs.push(func);
if (executeNextVMTurnPending) {
return;
}
executeNextVMTurnPending = true;
window.setTimeout(() => {
const funcsCopy = executeNextVMTurnFuncs.slice();
executeNextVMTurnFuncs.length = 0;
executeNextVMTurnPending = false;
funcsCopy.forEach((func2) => func2());
}, 0);
}
function executeAfter(funcs, milliseconds = 0) {
if (funcs.length > 0) {
window.setTimeout(() => funcs.forEach((func) => func()), milliseconds);
}
}
function debounce(func, delay) {
let timeout;
return function(...args) {
const context = this;
window.clearTimeout(timeout);
timeout = window.setTimeout(function() {
func.apply(context, args);
}, delay);
};
}
function throttle(func, wait) {
let previousCall = 0;
return function(...args) {
const context = this;
const currentCall = (/* @__PURE__ */ new Date()).getTime();
if (currentCall - previousCall < wait) {
return;
}
previousCall = currentCall;
func.apply(context, args);
};
}
function waitUntil(condition, callback, timeout = 100, timeoutMessage) {
const timeStamp = (/* @__PURE__ */ new Date()).getTime();
let interval = null;
let executed = false;
const internalCallback = () => {
const reachedTimeout = (/* @__PURE__ */ new Date()).getTime() - timeStamp > timeout;
if (condition() || reachedTimeout) {
callback();
executed = true;
if (interval != null) {
window.clearInterval(interval);
interval = null;
}
if (reachedTimeout && timeoutMessage) {
console.warn(timeoutMessage);
}
}
};
internalCallback();
if (!executed) {
interval = window.setInterval(internalCallback, 10);
}
}
function compose(...fns) {
return (arg) => fns.reduce((composed, f) => f(composed), arg);
}
var noop = () => {
return;
};
// community-modules/core/src/modules/moduleNames.ts
var ModuleNames = /* @__PURE__ */ ((ModuleNames2) => {
ModuleNames2["CommunityCoreModule"] = "@ag-grid-community/core";
ModuleNames2["InfiniteRowModelModule"] = "@ag-grid-community/infinite-row-model";
ModuleNames2["ClientSideRowModelModule"] = "@ag-grid-community/client-side-row-model";
ModuleNames2["CsvExportModule"] = "@ag-grid-community/csv-export";
ModuleNames2["EnterpriseCoreModule"] = "@ag-grid-enterprise/core";
ModuleNames2["RowGroupingModule"] = "@ag-grid-enterprise/row-grouping";
ModuleNames2["ColumnsToolPanelModule"] = "@ag-grid-enterprise/column-tool-panel";
ModuleNames2["FiltersToolPanelModule"] = "@ag-grid-enterprise/filter-tool-panel";
ModuleNames2["MenuModule"] = "@ag-grid-enterprise/menu";
ModuleNames2["SetFilterModule"] = "@ag-grid-enterprise/set-filter";
ModuleNames2["MultiFilterModule"] = "@ag-grid-enterprise/multi-filter";
ModuleNames2["StatusBarModule"] = "@ag-grid-enterprise/status-bar";
ModuleNames2["SideBarModule"] = "@ag-grid-enterprise/side-bar";
ModuleNames2["RangeSelectionModule"] = "@ag-grid-enterprise/range-selection";
ModuleNames2["MasterDetailModule"] = "@ag-grid-enterprise/master-detail";
ModuleNames2["RichSelectModule"] = "@ag-grid-enterprise/rich-select";
ModuleNames2["GridChartsModule"] = "@ag-grid-enterprise/charts";
ModuleNames2["ViewportRowModelModule"] = "@ag-grid-enterprise/viewport-row-model";
ModuleNames2["ServerSideRowModelModule"] = "@ag-grid-enterprise/server-side-row-model";
ModuleNames2["ExcelExportModule"] = "@ag-grid-enterprise/excel-export";
ModuleNames2["ClipboardModule"] = "@ag-grid-enterprise/clipboard";
ModuleNames2["SparklinesModule"] = "@ag-grid-enterprise/sparklines";
ModuleNames2["AdvancedFilterModule"] = "@ag-grid-enterprise/advanced-filter";
ModuleNames2["AngularModule"] = "@ag-grid-community/angular";
ModuleNames2["ReactModule"] = "@ag-grid-community/react";
ModuleNames2["VueModule"] = "@ag-grid-community/vue";
return ModuleNames2;
})(ModuleNames || {});
// community-modules/core/src/modules/moduleRegistry.ts
var _ModuleRegistry = class _ModuleRegistry {
/**
* Globally register the given module for all grids.
* @param module - module to register
*/
static register(module) {
_ModuleRegistry.__register(module, true, void 0);
}
/**
* Globally register the given modules for all grids.
* @param modules - modules to register
*/
static registerModules(modules) {
_ModuleRegistry.__registerModules(modules, true, void 0);
}
/** AG GRID INTERNAL - Module registration helper. */
static __register(module, moduleBased, gridId) {
_ModuleRegistry.runVersionChecks(module);
if (gridId !== void 0) {
_ModuleRegistry.areGridScopedModules = true;
if (_ModuleRegistry.gridModulesMap[gridId] === void 0) {
_ModuleRegistry.gridModulesMap[gridId] = {};
}
_ModuleRegistry.gridModulesMap[gridId][module.moduleName] = module;
} else {
_ModuleRegistry.globalModulesMap[module.moduleName] = module;
}
_ModuleRegistry.setModuleBased(moduleBased);
}
/** AG GRID INTERNAL - Unregister grid scoped module. */
static __unRegisterGridModules(gridId) {
delete _ModuleRegistry.gridModulesMap[gridId];
}
/** AG GRID INTERNAL - Module registration helper. */
static __registerModules(modules, moduleBased, gridId) {
_ModuleRegistry.setModuleBased(moduleBased);
if (!modules) {
return;
}
modules.forEach((module) => _ModuleRegistry.__register(module, moduleBased, gridId));
}
static isValidModuleVersion(module) {
const [moduleMajor, moduleMinor] = module.version.split(".") || [];
const [currentModuleMajor, currentModuleMinor] = _ModuleRegistry.currentModuleVersion.split(".") || [];
return moduleMajor === currentModuleMajor && moduleMinor === currentModuleMinor;
}
static runVersionChecks(module) {
if (!_ModuleRegistry.currentModuleVersion) {
_ModuleRegistry.currentModuleVersion = module.version;
}
if (!module.version) {
console.error(`AG Grid: You are using incompatible versions of AG Grid modules. Major and minor versions should always match across modules. '${module.moduleName}' is incompatible. Please update all modules to the same version.`);
} else if (!_ModuleRegistry.isValidModuleVersion(module)) {
console.error(`AG Grid: You are using incompatible versions of AG Grid modules. Major and minor versions should always match across modules. '${module.moduleName}' is version ${module.version} but the other modules are version ${this.currentModuleVersion}. Please update all modules to the same version.`);
}
if (module.validate) {
const result = module.validate();
if (!result.isValid) {
const errorResult = result;
console.error(`AG Grid: ${errorResult.message}`);
}
}
}
static setModuleBased(moduleBased) {
if (_ModuleRegistry.moduleBased === void 0) {
_ModuleRegistry.moduleBased = moduleBased;
} else {
if (_ModuleRegistry.moduleBased !== moduleBased) {
doOnce(
() => {
console.warn(`AG Grid: You are mixing modules (i.e. @ag-grid-community/core) and packages (ag-grid-community) - you can only use one or the other of these mechanisms.`);
console.warn("Please see https://www.ag-grid.com/javascript-grid/packages-modules/ for more information.");
},
"ModulePackageCheck"
);
}
}
}
/**
* AG GRID INTERNAL - Set if files are being served from a single UMD bundle to provide accurate enterprise upgrade steps.
*/
static __setIsBundled() {
_ModuleRegistry.isBundled = true;
}
/** AG GRID INTERNAL - Assert a given module has been register, globally or individually with this grid. */
static __assertRegistered(moduleName, reason, gridId) {
var _a;
if (this.__isRegistered(moduleName, gridId)) {
return true;
}
const warningKey = reason + moduleName;
let warningMessage;
if (_ModuleRegistry.isBundled) {
{
warningMessage = `AG Grid: unable to use ${reason} as 'ag-grid-enterprise' has not been loaded. Check you are using the Enterprise bundle:
<script src="https://cdn.jsdelivr.net/npm/ag-grid-enterprise@AG_GRID_VERSION/dist/ag-grid-enterprise.min.js"><\/script>
For more info see: https://ag-grid.com/javascript-data-grid/getting-started/#getting-started-with-ag-grid-enterprise`;
}
} else if (_ModuleRegistry.moduleBased || _ModuleRegistry.moduleBased === void 0) {
let modName = (_a = Object.entries(ModuleNames).find(([k, v]) => v === moduleName)) == null ? void 0 : _a[0];
warningMessage = `AG Grid: unable to use ${reason} as the ${modName} is not registered${_ModuleRegistry.areGridScopedModules ? ` for gridId: ${gridId}` : ""}. Check if you have registered the module:
import { ModuleRegistry } from '@ag-grid-community/core';
import { ${modName} } from '${moduleName}';
ModuleRegistry.registerModules([ ${modName} ]);
For more info see: https://www.ag-grid.com/javascript-grid/modules/`;
} else {
warningMessage = `AG Grid: unable to use ${reason} as package 'ag-grid-enterprise' has not been imported. Check that you have imported the package:
import 'ag-grid-enterprise';
For more info see: https://www.ag-grid.com/javascript-grid/packages/`;
}
doOnce(() => {
console.warn(warningMessage);
}, warningKey);
return false;
}
/**
* AG GRID INTERNAL - Warn that a given integrated chart type is not supported under the community distribution.
*/
static __warnEnterpriseChartDisabled(chartType) {
const reason = "ag-charts-enterprise";
const warningKey = reason + ":" + chartType;
const url = "https://www.ag-grid.com/javascript-data-grid/integrated-charts-installation/";
const warningMessage = `AG Grid: the '${chartType}' chart type is not supported in AG Charts Community as 'ag-grid-charts-enterprise' or '@ag-grid-enterprise/charts-enterprise' hasn't been loaded. See ${url} for more details.`;
doOnce(() => {
console.warn(warningMessage);
}, warningKey);
}
/** AG GRID INTERNAL - Is the given module registered, globally or individually with this grid. */
static __isRegistered(moduleName, gridId) {
var _a;
return !!_ModuleRegistry.globalModulesMap[moduleName] || !!((_a = _ModuleRegistry.gridModulesMap[gridId]) == null ? void 0 : _a[moduleName]);
}
/** AG GRID INTERNAL - Get all registered modules globally / individually for this grid. */
static __getRegisteredModules(gridId) {
return [...values(_ModuleRegistry.globalModulesMap), ...values(_ModuleRegistry.gridModulesMap[gridId] || {})];
}
/** AG GRID INTERNAL - Get the list of modules registered individually for this grid. */
static __getGridRegisteredModules(gridId) {
var _a;
return values((_a = _ModuleRegistry.gridModulesMap[gridId]) != null ? _a : {}) || [];
}
/** INTERNAL */
static __isPackageBased() {
return !_ModuleRegistry.moduleBased;
}
};
// having in a map a) removes duplicates and b) allows fast lookup
_ModuleRegistry.globalModulesMap = {};
_ModuleRegistry.gridModulesMap = {};
_ModuleRegistry.areGridScopedModules = false;
var ModuleRegistry = _ModuleRegistry;
// community-modules/core/src/context/context.ts
var Context = class {
constructor(params, logger) {
this.beanWrappers = {};
this.destroyed = false;
if (!params || !params.beanClasses) {
return;
}
this.contextParams = params;
this.logger = logger;
this.logger.log(">> creating ag-Application Context");
this.createBeans();
const beanInstances = this.getBeanInstances();
this.wireBeans(beanInstances);
this.logger.log(">> ag-Application Context ready - component is alive");
}
getBeanInstances() {
return values(this.beanWrappers).map((beanEntry) => beanEntry.beanInstance);
}
createBean(bean, afterPreCreateCallback) {
if (!bean) {
throw Error(`Can't wire to bean since it is null`);
}
this.wireBeans([bean], afterPreCreateCallback);
return bean;
}
wireBeans(beanInstances, afterPreCreateCallback) {
this.autoWireBeans(beanInstances);
this.methodWireBeans(beanInstances);
this.callLifeCycleMethods(beanInstances, "preConstructMethods");
if (exists(afterPreCreateCallback)) {
beanInstances.forEach(afterPreCreateCallback);
}
this.callLifeCycleMethods(beanInstances, "postConstructMethods");
}
createBeans() {
this.contextParams.beanClasses.forEach(this.createBeanWrapper.bind(this));
iterateObject(this.beanWrappers, (key, beanEntry) => {
let constructorParamsMeta;
if (beanEntry.bean.__agBeanMetaData && beanEntry.bean.__agBeanMetaData.autowireMethods && beanEntry.bean.__agBeanMetaData.autowireMethods.agConstructor) {
constructorParamsMeta = beanEntry.bean.__agBeanMetaData.autowireMethods.agConstructor;
}
const constructorParams = this.getBeansForParameters(constructorParamsMeta, beanEntry.bean.name);
const newInstance = new (beanEntry.bean.bind.apply(beanEntry.bean, [null, ...constructorParams]))();
beanEntry.beanInstance = newInstance;
});
const createdBeanNames = Object.keys(this.beanWrappers).join(", ");
this.logger.log(`created beans: ${createdBeanNames}`);
}
// tslint:disable-next-line
createBeanWrapper(BeanClass) {
const metaData = BeanClass.__agBeanMetaData;
if (!metaData) {
let beanName;
if (BeanClass.prototype.constructor) {
beanName = getFunctionName(BeanClass.prototype.constructor);
} else {
beanName = "" + BeanClass;
}
console.error(`Context item ${beanName} is not a bean`);
return;
}
const beanEntry = {
bean: BeanClass,
beanInstance: null,
beanName: metaData.beanName
};
this.beanWrappers[metaData.beanName] = beanEntry;
}
autoWireBeans(beanInstances) {
beanInstances.forEach((beanInstance) => {
this.forEachMetaDataInHierarchy(beanInstance, (metaData, beanName) => {
const attributes = metaData.agClassAttributes;
if (!attributes) {
return;
}
attributes.forEach((attribute) => {
const otherBean = this.lookupBeanInstance(beanName, attribute.beanName, attribute.optional);
beanInstance[attribute.attributeName] = otherBean;
});
});
});
}
methodWireBeans(beanInstances) {
beanInstances.forEach((beanInstance) => {
this.forEachMetaDataInHierarchy(beanInstance, (metaData, beanName) => {
iterateObject(metaData.autowireMethods, (methodName, wireParams) => {
if (methodName === "agConstructor") {
return;
}
const initParams = this.getBeansForParameters(wireParams, beanName);
beanInstance[methodName].apply(beanInstance, initParams);
});
});
});
}
forEachMetaDataInHierarchy(beanInstance, callback) {
let prototype = Object.getPrototypeOf(beanInstance);
while (prototype != null) {
const constructor = prototype.constructor;
if (constructor.hasOwnProperty("__agBeanMetaData")) {
const metaData = constructor.__agBeanMetaData;
const beanName = this.getBeanName(constructor);
callback(metaData, beanName);
}
prototype = Object.getPrototypeOf(prototype);
}
}
getBeanName(constructor) {
if (constructor.__agBeanMetaData && constructor.__agBeanMetaData.beanName) {
return constructor.__agBeanMetaData.beanName;
}
const constructorString = constructor.toString();
const beanName = constructorString.substring(9, constructorString.indexOf("("));
return beanName;
}
getBeansForParameters(parameters, beanName) {
const beansList = [];
if (parameters) {
iterateObject(parameters, (paramIndex, otherBeanName) => {
const otherBean = this.lookupBeanInstance(beanName, otherBeanName);
beansList[Number(paramIndex)] = otherBean;
});
}
return beansList;
}
lookupBeanInstance(wiringBean, beanName, optional = false) {
if (this.destroyed) {
this.logger.log(`AG Grid: bean reference ${beanName} is used after the grid is destroyed!`);
return null;
}
if (beanName === "context") {
return this;
}
if (this.contextParams.providedBeanInstances && this.contextParams.providedBeanInstances.hasOwnProperty(beanName)) {
return this.contextParams.providedBeanInstances[beanName];
}
const beanEntry = this.beanWrappers[beanName];
if (beanEntry) {
return beanEntry.beanInstance;
}
if (!optional) {
console.error(`AG Grid: unable to find bean reference ${beanName} while initialising ${wiringBean}`);
}
return null;
}
callLifeCycleMethods(beanInstances, lifeCycleMethod) {
beanInstances.forEach((beanInstance) => this.callLifeCycleMethodsOnBean(beanInstance, lifeCycleMethod));
}
callLifeCycleMethodsOnBean(beanInstance, lifeCycleMethod, methodToIgnore) {
const allMethods = {};
this.forEachMetaDataInHierarchy(beanInstance, (metaData) => {
const methods = metaData[lifeCycleMethod];
if (methods) {
methods.forEach((methodName) => {
if (methodName != methodToIgnore) {
allMethods[methodName] = true;
}
});
}
});
const allMethodsList = Object.keys(allMethods);
allMethodsList.forEach((methodName) => beanInstance[methodName]());
}
getBean(name) {
return this.lookupBeanInstance("getBean", name, true);
}
destroy() {
if (this.destroyed) {
return;
}
this.destroyed = true;
this.logger.log(">> Shutting down ag-Application Context");
const beanInstances = this.getBeanInstances();
this.destroyBeans(beanInstances);
this.contextParams.providedBeanInstances = null;
ModuleRegistry.__unRegisterGridModules(this.contextParams.gridId);
this.logger.log(">> ag-Application Context shut down - component is dead");
}
destroyBean(bean) {
if (!bean) {
return;
}
this.destroyBeans([bean]);
}
destroyBeans(beans) {
if (!beans) {
return [];
}
beans.forEach((bean) => {
this.callLifeCycleMethodsOnBean(bean, "preDestroyMethods", "destroy");
const beanAny = bean;
if (typeof beanAny.destroy === "function") {
beanAny.destroy();
}
});
return [];
}
isDestroyed() {
return this.destroyed;
}
getGridId() {
return this.contextParams.gridId;
}
};
function PreConstruct(target, methodName, descriptor) {
const props = getOrCreateProps(target.constructor);
if (!props.preConstructMethods) {
props.preConstructMethods = [];
}
props.preConstructMethods.push(methodName);
}
function PostConstruct(target, methodName, descriptor) {
const props = getOrCreateProps(target.constructor);
if (!props.postConstructMethods) {
props.postConstructMethods = [];
}
props.postConstructMethods.push(methodName);
}
function PreDestroy(target, methodName, descriptor) {
const props = getOrCreateProps(target.constructor);
if (!props.preDestroyMethods) {
props.preDestroyMethods = [];
}
props.preDestroyMethods.push(methodName);
}
function Bean(beanName) {
return (classConstructor) => {
const props = getOrCreateProps(classConstructor);
props.beanName = beanName;
};
}
function Autowired(name) {
return (target, propertyKey, descriptor) => {
autowiredFunc(target, name, false, target, propertyKey, null);
};
}
function Optional(name) {
return (target, propertyKey, descriptor) => {
autowiredFunc(target, name, true, target, propertyKey, null);
};
}
function autowiredFunc(target, name, optional, classPrototype, methodOrAttributeName, index) {
if (name === null) {
console.error("AG Grid: Autowired name should not be null");
return;
}
if (typeof index === "number") {
console.error("AG Grid: Autowired should be on an attribute");
return;
}
const props = getOrCreateProps(target.constructor);
if (!props.agClassAttributes) {
props.agClassAttributes = [];
}
props.agClassAttributes.push({
attributeName: methodOrAttributeName,
beanName: name,
optional
});
}
function Qualifier(name) {
return (classPrototype, methodOrAttributeName, index) => {
const constructor = typeof classPrototype == "function" ? classPrototype : classPrototype.constructor;
let props;
if (typeof index === "number") {
let methodName;
if (methodOrAttributeName) {
props = getOrCreateProps(constructor);
methodName = methodOrAttributeName;
} else {
props = getOrCreateProps(constructor);
methodName = "agConstructor";
}
if (!props.autowireMethods) {
props.autowireMethods = {};
}
if (!props.autowireMethods[methodName]) {
props.autowireMethods[methodName] = {};
}
props.autowireMethods[methodName][index] = name;
}
};
}
function getOrCreateProps(target) {
if (!target.hasOwnProperty("__agBeanMetaData")) {
target.__agBeanMetaData = {};
}
return target.__agBeanMetaData;
}
// community-modules/core/src/eventService.ts
var EventService = class {
constructor() {
this.allSyncListeners = /* @__PURE__ */ new Map();
this.allAsyncListeners = /* @__PURE__ */ new Map();
this.globalSyncListeners = /* @__PURE__ */ new Set();
this.globalAsyncListeners = /* @__PURE__ */ new Set();
this.asyncFunctionsQueue = [];
this.scheduled = false;
// using an object performs better than a Set for the number of different events we have
this.firedEvents = {};
}
// because this class is used both inside the context and outside the context, we do not
// use autowired attributes, as that would be confusing, as sometimes the attributes
// would be wired, and sometimes not.
//
// the global event servers used by AG Grid is autowired by the context once, and this
// setBeans method gets called once.
//
// the times when this class is used outside of the context (eg RowNode has an instance of this
// class) then it is not a bean, and this setBeans method is not called.
setBeans(gridOptionsService, frameworkOverrides, globalEventListener = null, globalSyncEventListener = null) {
this.frameworkOverrides = frameworkOverrides;
this.gridOptionsService = gridOptionsService;
if (globalEventListener) {
const async = gridOptionsService.useAsyncEvents();
this.addGlobalListener(globalEventListener, async);
}
if (globalSyncEventListener) {
this.addGlobalListener(globalSyncEventListener, false);
}
}
setFrameworkOverrides(frameworkOverrides) {
this.frameworkOverrides = frameworkOverrides;
}
getListeners(eventType, async, autoCreateListenerCollection) {
const listenerMap = async ? this.allAsyncListeners : this.allSyncListeners;
let listeners = listenerMap.get(eventType);
if (!listeners && autoCreateListenerCollection) {
listeners = /* @__PURE__ */ new Set();
listenerMap.set(eventType, listeners);
}
return listeners;
}
noRegisteredListenersExist() {
return this.allSyncListeners.size === 0 && this.allAsyncListeners.size === 0 && this.globalSyncListeners.size === 0 && this.globalAsyncListeners.size === 0;
}
addEventListener(eventType, listener, async = false) {
this.getListeners(eventType, async, true).add(listener);
}
removeEventListener(eventType, listener, async = false) {
const listeners = this.getListeners(eventType, async, false);
if (!listeners) {
return;
}
listeners.delete(listener);
if (listeners.size === 0) {
const listenerMap = async ? this.allAsyncListeners : this.allSyncListeners;
listenerMap.delete(eventType);
}
}
addGlobalListener(listener, async = false) {
(async ? this.globalAsyncListeners : this.globalSyncListeners).add(listener);
}
removeGlobalListener(listener, async = false) {
(async ? this.globalAsyncListeners : this.globalSyncListeners).delete(listener);
}
dispatchEvent(event) {
let agEvent = event;
if (this.gridOptionsService) {
this.gridOptionsService.addGridCommonParams(agEvent);
}
this.dispatchToListeners(agEvent, true);
this.dispatchToListeners(agEvent, false);
this.firedEvents[agEvent.type] = true;
}
dispatchEventOnce(event) {
if (!this.firedEvents[event.type]) {
this.dispatchEvent(event);
}
}
dispatchToListeners(event, async) {
var _a;
const eventType = event.type;
if (async && "event" in event) {
const browserEvent = event.event;
if (browserEvent instanceof Event) {
event.eventPath = browserEvent.composedPath();
}
}
const processEventListeners = (listeners2, originalListeners2) => listeners2.forEach((listener) => {
if (!originalListeners2.has(listener)) {
return;
}
const callback = this.frameworkOverrides ? () => this.frameworkOverrides.wrapIncoming(() => listener(event)) : () => listener(event);
if (async) {
this.dispatchAsync(callback);
} else {
callback();
}
});
const originalListeners = (_a = this.getListeners(eventType, async, false)) != null ? _a : /* @__PURE__ */ new Set();
const listeners = new Set(originalListeners);
if (listeners.size > 0) {
processEventListeners(listeners, originalListeners);
}
const globalListeners = new Set(async ? this.globalAsyncListeners : this.globalSyncListeners);
globalListeners.forEach((listener) => {
const callback = this.frameworkOverrides ? () => this.frameworkOverrides.wrapIncoming(() => listener(eventType, event)) : () => listener(eventType, event);
if (async) {
this.dispatchAsync(callback);
} else {
callback();
}
});
}
// this gets called inside the grid's thread, for each event that it
// wants to set async. the grid then batches the events into one setTimeout()
// because setTimeout() is an expensive operation. ideally we would have
// each event in it's own setTimeout(), but we batch for performance.
dispatchAsync(func) {
this.asyncFunctionsQueue.push(func);
if (!this.scheduled) {
this.frameworkOverrides.wrapIncoming(() => {
window.setTimeout(this.flushAsyncQueue.bind(this), 0);
});
this.scheduled = true;
}
}
// this happens in the next VM turn only, and empties the queue of events
flushAsyncQueue() {
this.scheduled = false;
const queueCopy = this.asyncFunctionsQueue.slice();
this.asyncFunctionsQueue = [];
queueCopy.forEach((func) => func());
}
};
__decorateClass([
__decorateParam(0, Qualifier("gridOptionsService")),
__decorateParam(1, Qualifier("frameworkOverrides")),
__decorateParam(2, Qualifier("globalEventListener")),
__decorateParam(3, Qualifier("globalSyncEventListener"))
], EventService.prototype, "setBeans", 1);
EventService = __decorateClass([
Bean("eventService")
], EventService);
// community-modules/core/src/misc/frameworkEventListenerService.ts
var FrameworkEventListenerService = class {
constructor(frameworkOverrides) {
this.frameworkOverrides = frameworkOverrides;
// Map from user listener to wrapped listener so we can remove listener provided by user
this.wrappedListeners = /* @__PURE__ */ new Map();
this.wrappedGlobalListeners = /* @__PURE__ */ new Map();
}
wrap(userListener) {
let listener = userListener;
if (this.frameworkOverrides.shouldWrapOutgoing) {
listener = (event) => {
this.frameworkOverrides.wrapOutgoing(() => userListener(event));
};
this.wrappedListeners.set(userListener, listener);
}
return listener;
}
wrapGlobal(userListener) {
let listener = userListener;
if (this.frameworkOverrides.shouldWrapOutgoing) {
listener = (eventType, event) => {
this.frameworkOverrides.wrapOutgoing(() => userListener(eventType, event));
};
this.wrappedGlobalListeners.set(userListener, listener);
}
return listener;
}
unwrap(userListener) {
var _a;
return (_a = this.wrappedListeners.get(userListener)) != null ? _a : userListener;
}
unwrapGlobal(userListener) {
var _a;
return (_a = this.wrappedGlobalListeners.get(userListener)) != null ? _a : userListener;
}
};
// community-modules/core/src/entities/column.ts
var COL_DEF_DEFAULTS = {
resizable: true,
sortable: true
};
var instanceIdSequence = 0;
function getNextColInstanceId() {
return instanceIdSequence++;
}
var _Column = class _Column {
constructor(colDef, userProvidedColDef, colId, primary) {
// used by React (and possibly other frameworks) as key for rendering. also used to
// identify old vs new columns for destroying cols when no longer used.
this.instanceId = getNextColInstanceId();
// The measured height of this column's header when autoHeaderHeight is enabled
this.autoHeaderHeight = null;
this.moving = false;
this.menuVisible = false;
this.lastLeftPinned = false;
this.firstRightPinned = false;
this.filterActive = false;
this.eventService = new EventService();
this.tooltipEnabled = false;
this.rowGroupActive = false;
this.pivotActive = false;
this.aggregationActive = false;
this.colDef = colDef;
this.userProvidedColDef = userProvidedColDef;
this.colId = colId;
this.primary = primary;
this.setState(colDef);
}
getInstanceId() {
return this.instanceId;
}
setState(colDef) {
if (colDef.sort !== void 0) {
if (colDef.sort === "asc" || colDef.sort === "desc") {
this.sort = colDef.sort;
}
} else {
if (colDef.initialSort === "asc" || colDef.initialSort === "desc") {
this.sort = colDef.initialSort;
}
}
const sortIndex = colDef.sortIndex;
const initialSortIndex = colDef.initialSortIndex;
if (sortIndex !== void 0) {
if (sortIndex !== null) {
this.sortIndex = sortIndex;
}
} else {
if (initialSortIndex !== null) {
this.sortIndex = initialSortIndex;
}
}
const hide = colDef.hide;
const initialHide = colDef.initialHide;
if (hide !== void 0) {
this.visible = !hide;
} else {
this.visible = !initialHide;
}
if (colDef.pinned !== void 0) {
this.setPinned(colDef.pinned);
} else {
this.setPinned(colDef.initialPinned);
}
const flex = colDef.flex;
const initialFlex = colDef.initialFlex;
if (flex !== void 0) {
this.flex = flex;
} else if (initialFlex !== void 0) {
this.flex = initialFlex;
}
}
// gets called when user provides an alternative colDef, eg
setColDef(colDef, userProvidedColDef, source) {
this.colDef = colDef;
this.userProvidedColDef = userProvidedColDef;
this.initMinAndMaxWidths();
this.initDotNotation();
this.initTooltip();
this.eventService.dispatchEvent(this.createColumnEvent("colDefChanged", source));
}
/**
* Returns the column definition provided by the application.
* This may not be correct, as items can be superseded by default column options.
* However it's useful for comparison, eg to know which application column definition matches that column.
*/
getUserProvidedColDef() {
return this.userProvidedColDef;
}
setParent(parent) {
this.parent = parent;
}
/** Returns the parent column group, if column grouping is active. */
getParent() {
return this.parent;
}
setOriginalParent(originalParent) {
this.originalParent = originalParent;
}
/**
* Used for marryChildren, helps with comparing when duplicate groups have been created to manage split groups.
*
* Parent may contain a duplicate but not identical group when the group is split.
*/
getOriginalParent() {
return this.originalParent;
}
initialise() {
this.initMinAndMaxWidths();
this.resetActualWidth("gridInitializing");
this.initDotNotation();
this.initTooltip();
}
initDotNotation() {
const suppressDotNotation = this.gridOptionsService.get("suppressFieldDotNotation");
this.fieldContainsDots = exists(this.colDef.field) && this.colDef.field.indexOf(".") >= 0 && !suppressDotNotation;
this.tooltipFieldContainsDots = exists(this.colDef.tooltipField) && this.colDef.tooltipField.indexOf(".") >= 0 && !suppressDotNotation;
}
initMinAndMaxWidths() {
const colDef = this.colDef;
this.minWidth = this.columnUtils.calculateColMinWidth(colDef);
this.maxWidth = this.columnUtils.calculateColMaxWidth(colDef);
}
initTooltip() {
this.tooltipEnabled = exists(this.colDef.tooltipField) || exists(this.colDef.tooltipValueGetter) || exists(this.colDef.tooltipComponent);
}
resetActualWidth(source) {
const initialWidth = this.columnUtils.calculateColInitialWidth(this.colDef);
this.setActualWidth(initialWidth, source, true);
}
isEmptyGroup() {
return false;
}
isRowGroupDisplayed(colId) {
if (missing(this.colDef) || missing(this.colDef.showRowGroup)) {
return false;
}
const showingAllGroups = this.colDef.showRowGroup === true;
const showingThisGroup = this.colDef.showRowGroup === colId;
return showingAllGroups || showingThisGroup;
}
/** Returns `true` if column is a primary column, `false` if secondary. Secondary columns are used for pivoting. */
isPrimary() {
return this.primary;
}
/** Returns `true` if column filtering is allowed. */
isFilterAllowed() {
const filterDefined = !!this.colDef.filter;
return filterDefined;
}
isFieldContainsDots() {
return this.fieldContainsDots;
}
isTooltipEnabled() {
return this.tooltipEnabled;
}
isTooltipFieldContainsDots() {
return this.tooltipFieldContainsDots;
}
/** Add an event listener to the column. */
addEventListener(eventType, userListener) {
var _a, _b;
if (this.frameworkOverrides.shouldWrapOutgoing && !this.frameworkEventListenerService) {
this.eventService.setFrameworkOverrides(this.frameworkOverrides);
this.frameworkEventListenerService = new FrameworkEventListenerService(this.frameworkOverrides);
}
const listener = (_b = (_a = this.frameworkEventListenerService) == null ? void 0 : _a.wrap(userListener)) != null ? _b : userListener;
this.eventService.addEventListener(eventType, listener);
}
/** Remove event listener from the column. */
removeEventListener(eventType, userListener) {
var _a, _b;
const listener = (_b = (_a = this.frameworkEventListenerService) == null ? void 0 : _a.unwrap(userListener)) != null ? _b : userListener;
this.eventService.removeEventListener(eventType, listener);
}
createColumnFunctionCallbackParams(rowNode) {
return this.gridOptionsService.addGridCommonParams({
node: rowNode,
data: rowNode.data,
column: this,
colDef: this.colDef
});
}
isSuppressNavigable(rowNode) {
if (typeof this.colDef.suppressNavigable === "boolean") {
return this.colDef.suppressNavigable;
}
if (typeof this.colDef.suppressNavigable === "function") {
const params = this.createColumnFunctionCallbackParams(rowNode);
const userFunc = this.colDef.suppressNavigable;
return userFunc(params);
}
return false;
}
/**
* Returns `true` if the cell for this column is editable for the given `rowNode`, otherwise `false`.
*/
isCellEditable(rowNode) {
if (rowNode.group && !this.gridOptionsService.get("enableGroupEdit")) {
return false;
}
return this.isColumnFunc(rowNode, this.colDef.editable);
}
isSuppressFillHandle() {
return !!this.colDef.suppressFillHandle;
}
isAutoHeight() {
return !!this.colDef.autoHeight;
}
isAutoHeaderHeight() {
return !!this.colDef.autoHeaderHeight;
}
isRowDrag(rowNode) {
return this.isColumnFunc(rowNode, this.colDef.rowDrag);
}
isDndSource(rowNode) {
return this.isColumnFunc(rowNode, this.colDef.dndSource);
}
isCellCheckboxSelection(rowNode) {
return this.isColumnFunc(rowNode, this.colDef.checkboxSelection);
}
isSuppressPaste(rowNode) {
return this.isColumnFunc(rowNode, this.colDef ? this.colDef.suppressPaste : null);
}
isResizable() {
return !!this.getColDefValue("resizable");
}
/** Get value from ColDef or default if it exists. */
getColDefValue(key) {
var _a;
return (_a = this.colDef[key]) != null ? _a : COL_DEF_DEFAULTS[key];
}
isColumnFunc(rowNode, value) {
if (typeof value === "boolean") {
return value;
}
if (typeof value === "function") {
const params = this.createColumnFunctionCallbackParams(rowNode);
const editableFunc = value;
return editableFunc(params);
}
return false;
}
setMoving(moving, source) {
this.moving = moving;
this.eventService.dispatchEvent(this.createColumnEvent("movingChanged", source));
}
createColumnEvent(type, source) {
return this.gridOptionsService.addGridCommonParams({
type,
column: this,
columns: [this],
source
});
}
isMoving() {
return this.moving;
}
/** If sorting is active, returns the sort direction e.g. `'asc'` or `'desc'`. */
getSort() {
return this.sort;
}
setSort(sort, source) {
if (this.sort !== sort) {
this.sort = sort;
this.eventService.dispatchEvent(this.createColumnEvent("sortChanged", source));
}
this.dispatchStateUpdatedEvent("sort");
}
setMenuVisible(visible, source) {
if (this.menuVisible !== visible) {
this.menuVisible = visible;
this.eventService.dispatchEvent(this.createColumnEvent("menuVisibleChanged", source));
}
}
isMenuVisible() {
return this.menuVisible;
}
isSortable() {
return !!this.getColDefValue("sortable");
}
isSortAscending() {
return this.sort === "asc";
}
isSortDescending() {
return this.sort === "desc";
}
isSortNone() {
return missing(this.sort);
}
isSorting() {
return exists(this.sort);
}
getSortIndex() {
return this.sortIndex;
}
setSortIndex(sortOrder) {
this.sortIndex = sortOrder;
this.dispatchStateUpdatedEvent("sortIndex");
}
setAggFunc(aggFunc) {
this.aggFunc = aggFunc;
this.dispatchStateUpdatedEvent("aggFunc");
}
/** If aggregation is set for the column, returns the aggregation function. */
getAggFunc() {
return this.aggFunc;
}
getLeft() {
return this.left;
}
getOldLeft() {
return this.oldLeft;
}
getRight() {
return this.left + this.actualWidth;
}
setLeft(left, source) {
this.oldLeft = this.left;
if (this.left !== left) {
this.left = left;
this.eventService.dispatchEvent(this.createColumnEvent("leftChanged", sour