UNPKG

ag-grid-community

Version:

Advanced Data Grid / Data Table supporting Javascript / Typescript / React / Angular / Vue

1,547 lines (1,532 loc) 2.33 MB
// packages/ag-grid-community/src/entities/agColumn.ts import { LocalEventService, _escapeString } from "ag-stack"; // packages/ag-grid-community/src/entities/defaultColumnTypes.ts var DefaultColumnTypes = { numericColumn: { headerClass: "ag-right-aligned-header", cellClass: "ag-right-aligned-cell" }, rightAligned: { headerClass: "ag-right-aligned-header", cellClass: "ag-right-aligned-cell" } }; // packages/ag-grid-community/src/gridOptionsUtils.ts import { _doOnce, _missing } from "ag-stack"; // packages/ag-grid-community/src/utils/mergeDeep.ts import { _areEqual } from "ag-stack"; var _isProtoPollutionKey = (key) => key === "__proto__" || key === "constructor" || key === "prototype"; var isPlainProto = (value) => { const proto = Object.getPrototypeOf(value); return proto === Object.prototype || proto === null; }; var _isPlainObject = (value) => value !== null && typeof value === "object" && isPlainProto(value); var setKey = (out, key, value, copyUndef, simpleObjects) => { let destValue = out[key]; if (destValue === value) { return; } if (value === null || typeof value !== "object") { if (copyUndef || value !== void 0) { out[key] = value; } return; } if (simpleObjects && destValue == null && isPlainProto(value)) { destValue = {}; out[key] = destValue; } if (destValue !== null && typeof destValue === "object" && !Array.isArray(destValue)) { _mergeDeep(destValue, value, copyUndef, simpleObjects); } else { out[key] = value; } }; var _mergeDeep = (dest, source, copyUndefined = true, makeCopyOfSimpleObjects = false) => { if (source == null || source === "") { return; } if (Array.isArray(source)) { for (let i = 0, len = source.length; i < len; ++i) { setKey(dest, i, source[i], copyUndefined, makeCopyOfSimpleObjects); } return; } for (const key of Object.keys(source)) { if (!_isProtoPollutionKey(key)) { setKey(dest, key, source[key], copyUndefined, makeCopyOfSimpleObjects); } } }; var _cloneDeep = (value) => { if (value === null || typeof value !== "object") { return value; } if (Array.isArray(value)) { const len = value.length; const arr = new Array(len); for (let i = 0; i < len; ++i) { arr[i] = _cloneDeep(value[i]); } return arr; } if (!isPlainProto(value)) { return value; } const out = {}; for (const key of Object.keys(value)) { if (!_isProtoPollutionKey(key)) { out[key] = _cloneDeep(value[key]); } } return out; }; var _mergedEqual = (a, b, topLevelSkipKey) => { if (a === b) { return true; } if (a === null || b === null || typeof a !== "object" || typeof b !== "object") { return false; } const aIsArr = Array.isArray(a); if (aIsArr !== Array.isArray(b)) { return false; } if (aIsArr) { return _areEqual(a, b); } if (!isPlainProto(a) || !isPlainProto(b)) { return false; } const aKeys = Object.keys(a); const bKeys = Object.keys(b); const aLen = aKeys.length; const bLen = bKeys.length; if (topLevelSkipKey === void 0) { if (aLen !== bLen) { return false; } for (let i = 0; i < aLen; ++i) { const k = aKeys[i]; if (!(k in b) || !_mergedEqual(a[k], b[k])) { return false; } } return true; } let aSkip = 0; for (let i = 0; i < aLen; ++i) { const k = aKeys[i]; if (aSkip === 0 && k === topLevelSkipKey) { aSkip = 1; continue; } if (!(k in b) || !_mergedEqual(a[k], b[k])) { return false; } } const bSkip = topLevelSkipKey in b ? 1 : 0; return aLen - aSkip === bLen - bSkip; }; // packages/ag-grid-community/src/globalGridOptions.ts var _GlobalGridOptions = class _GlobalGridOptions { /** * @param providedOptions * @returns Shallow copy of the provided options with global options merged in. */ static applyGlobalGridOptions(providedOptions) { if (!_GlobalGridOptions.gridOptions) { return { ...providedOptions }; } let mergedGridOps = {}; _mergeDeep(mergedGridOps, _GlobalGridOptions.gridOptions, true, true); if (_GlobalGridOptions.mergeStrategy === "deep") { _mergeDeep(mergedGridOps, providedOptions, true, true); } else { mergedGridOps = { ...mergedGridOps, ...providedOptions }; } if (_GlobalGridOptions.gridOptions.context) { mergedGridOps.context = _GlobalGridOptions.gridOptions.context; } if (providedOptions.context) { if (_GlobalGridOptions.mergeStrategy === "deep" && mergedGridOps.context) { _mergeDeep(providedOptions.context, mergedGridOps.context, true, true); } mergedGridOps.context = providedOptions.context; } return mergedGridOps; } /** * Apply global grid option for a specific option key. * If the merge strategy is 'deep' and both global and provided values are objects, they will be merged deeply. * Otherwise, the provided value is returned as is. * @param optionKey - The key of the grid option to apply. * @param providedValue - The value provided to the grid instance. * @returns The merged value if applicable, otherwise the provided value. */ static applyGlobalGridOption(optionKey, providedValue) { if (_GlobalGridOptions.mergeStrategy === "deep") { const globalValue = _getGlobalGridOption(optionKey); if (globalValue && typeof globalValue === "object" && typeof providedValue === "object") { return _GlobalGridOptions.applyGlobalGridOptions({ [optionKey]: providedValue })[optionKey]; } } return providedValue; } }; // eslint-disable-next-line no-restricted-syntax _GlobalGridOptions.gridOptions = void 0; // eslint-disable-next-line no-restricted-syntax _GlobalGridOptions.mergeStrategy = "shallow"; var GlobalGridOptions = _GlobalGridOptions; function provideGlobalGridOptions(gridOptions, mergeStrategy = "shallow") { GlobalGridOptions.gridOptions = gridOptions; GlobalGridOptions.mergeStrategy = mergeStrategy; } function _getGlobalGridOption(gridOption) { return GlobalGridOptions.gridOptions?.[gridOption]; } // packages/ag-grid-community/src/gridOptionsDefault.ts var GRID_OPTION_DEFAULTS = { suppressContextMenu: false, preventDefaultOnContextMenu: false, allowContextMenuWithControlKey: false, suppressMenuHide: true, enableBrowserTooltips: false, tooltipTrigger: "hover", tooltipShowDelay: 2e3, tooltipSwitchShowDelay: 200, tooltipHideDelay: 1e4, noteTrigger: "hover", noteShowDelay: 180, noteHideDelay: 220, tooltipMouseTrack: false, tooltipShowMode: "standard", tooltipInteraction: false, copyHeadersToClipboard: false, copyGroupHeadersToClipboard: false, clipboardDelimiter: " ", suppressCopyRowsToClipboard: false, suppressCopySingleCellRanges: false, suppressLastEmptyLineOnPaste: false, suppressClipboardPaste: false, suppressClipboardApi: false, suppressCutToClipboard: false, maintainColumnOrder: false, enableStrictPivotColumnOrder: false, suppressFieldDotNotation: false, allowDragFromColumnsToolPanel: false, suppressMovableColumns: false, suppressColumnMoveAnimation: false, suppressMoveWhenColumnDragging: false, suppressDragLeaveHidesColumns: false, suppressRowGroupHidesColumns: false, suppressAutoSize: false, autoSizePadding: 20, skipHeaderOnAutoSize: false, singleClickEdit: false, suppressClickEdit: false, readOnlyEdit: false, stopEditingWhenCellsLoseFocus: false, enterNavigatesVertically: false, enterNavigatesVerticallyAfterEdit: false, enableCellEditingOnBackspace: false, undoRedoCellEditing: false, undoRedoCellEditingLimit: 10, suppressCsvExport: false, suppressExcelExport: false, cacheQuickFilter: false, includeHiddenColumnsInQuickFilter: false, excludeChildrenWhenTreeDataFiltering: false, enableAdvancedFilter: false, includeHiddenColumnsInAdvancedFilter: false, enableCharts: false, includeHiddenColumnsInCharts: true, masterDetail: false, keepDetailRows: false, keepDetailRowsCount: 10, detailRowAutoHeight: false, tabIndex: 0, rowBuffer: 10, valueCache: false, valueCacheNeverExpires: false, enableCellExpressions: false, suppressTouch: false, suppressFocusAfterRefresh: false, suppressBrowserResizeObserver: false, suppressPropertyNamesCheck: false, suppressChangeDetection: false, debug: false, suppressLoadingOverlay: false, suppressNoRowsOverlay: false, pagination: false, paginationPageSize: 100, paginationPageSizeSelector: true, paginationAutoPageSize: false, paginateChildRows: false, suppressPaginationPanel: false, pivotMode: false, pivotPanelShow: "never", pivotDefaultExpanded: 0, pivotSuppressAutoColumn: false, suppressExpandablePivotGroups: false, functionsReadOnly: false, suppressAggFuncInHeader: false, alwaysAggregateAtRootLevel: false, aggregateOnlyChangedColumns: false, suppressAggFilteredOnly: false, removePivotHeaderRowWhenSingleValueColumn: false, animateRows: true, cellFlashDuration: 500, cellFadeDuration: 1e3, allowShowChangeAfterFilter: false, domLayout: "normal", ensureDomOrder: false, enableRtl: false, suppressColumnVirtualisation: false, suppressMaxRenderedRowRestriction: false, suppressRowVirtualisation: false, rowDragManaged: false, refreshAfterGroupEdit: false, rowDragInsertDelay: 500, suppressRowDrag: false, suppressMoveWhenRowDragging: false, rowDragEntireRow: false, rowDragMultiRow: false, embedFullWidthRows: false, groupDisplayType: "singleColumn", groupDefaultExpanded: 0, groupMaintainOrder: false, groupSelectsChildren: false, groupSuppressBlankHeader: false, groupSelectsFiltered: false, showOpenedGroup: false, groupRemoveSingleChildren: false, groupRemoveLowestSingleChildren: false, groupHideOpenParents: false, groupHideColumnsUntilExpanded: false, groupAllowUnbalanced: false, rowGroupPanelShow: "never", suppressMakeColumnVisibleAfterUnGroup: false, treeData: false, rowGroupPanelSuppressSort: false, pivotPanelSuppressSort: false, suppressGroupRowsSticky: false, rowModelType: "clientSide", asyncTransactionWaitMillis: 50, suppressModelUpdateAfterUpdateTransaction: false, cacheOverflowSize: 1, infiniteInitialRowCount: 1, serverSideInitialRowCount: 1, cacheBlockSize: 100, maxBlocksInCache: -1, maxConcurrentDatasourceRequests: 2, blockLoadDebounceMillis: 0, purgeClosedRowNodes: false, serverSideSortAllLevels: false, serverSideOnlyRefreshFilteredGroups: false, serverSidePivotResultFieldSeparator: "_", viewportRowModelPageSize: 5, viewportRowModelBufferSize: 5, alwaysShowHorizontalScroll: false, alwaysShowVerticalScroll: false, debounceVerticalScrollbar: false, suppressHorizontalScroll: false, suppressScrollOnNewData: false, suppressScrollWhenPopupsAreOpen: false, suppressAnimationFrame: false, suppressMiddleClickScrolls: false, suppressPreventDefaultOnMouseWheel: false, rowMultiSelectWithClick: false, suppressRowDeselection: false, suppressRowClickSelection: false, suppressCellFocus: false, suppressHeaderFocus: false, suppressMultiRangeSelection: false, enableCellTextSelection: false, enableRangeSelection: false, enableRangeHandle: false, enableFillHandle: false, fillHandleDirection: "xy", suppressClearOnFillReduction: false, accentedSort: false, unSortIcon: false, suppressMultiSort: false, alwaysMultiSort: false, suppressMaintainUnsortedOrder: false, suppressRowHoverHighlight: false, suppressRowTransform: false, suppressContentVisibilityAuto: true, contentVisibilityAutoDelay: 1e3, columnHoverHighlight: false, deltaSort: false, enableGroupEdit: false, groupLockGroupColumns: 0, serverSideEnableClientSideSort: false, suppressServerSideFullWidthLoadingRow: false, pivotMaxGeneratedColumns: -1, columnMenu: "new", reactiveCustomComponents: true, suppressSetFilterByDefault: false, enableFilterHandlers: false }; // packages/ag-grid-community/src/utils/number.ts function _isFiniteNumber(v) { return typeof v === "number" && Number.isFinite(v); } function _toFiniteNumber(v) { const n = Number(v); return Number.isFinite(n) ? n : null; } function _clamp(value, min, max) { return Math.max(min, Math.min(value, max)); } function _formatNumberCommas(value, getLocaleTextFunc) { if (typeof value !== "number") { return ""; } const localeTextFunc = getLocaleTextFunc(); const thousandSeparator = localeTextFunc("thousandSeparator", ","); const decimalSeparator = localeTextFunc("decimalSeparator", "."); return value.toString().replace(".", decimalSeparator).replace(/(\d)(?=(\d{3})+(?!\d))/g, `$1${thousandSeparator}`); } // packages/ag-grid-community/src/gridOptionsUtils.ts function isRowModelType(gos, rowModelType) { return gos.get("rowModelType") === rowModelType; } function _isClientSideRowModel(gos, _rowModel) { return isRowModelType(gos, "clientSide"); } function _isServerSideRowModel(gos, _rowModel) { return isRowModelType(gos, "serverSide"); } function _isDomLayout(gos, domLayout) { return gos.get("domLayout") === domLayout; } function _isRowSelection(gos) { return _getRowSelectionMode(gos) !== void 0; } function _isGetRowHeightFunction(gos) { return typeof gos.get("getRowHeight") === "function"; } function _shouldMaintainColumnOrder(gos, isPivotColumns) { if (isPivotColumns) { return !gos.get("enableStrictPivotColumnOrder"); } return gos.get("maintainColumnOrder"); } function _isRowNumbers({ gos, formula }) { const rowNumbers = gos.get("rowNumbers"); return rowNumbers || !!formula?.active && rowNumbers !== false; } function _getRowHeightForNode(beans, rowNode, allowEstimate = false, defaultRowHeight) { const { gos, environment } = beans; if (defaultRowHeight == null) { defaultRowHeight = environment.getDefaultRowHeight(); } if (_isGetRowHeightFunction(gos)) { if (allowEstimate) { return { height: defaultRowHeight, estimated: true }; } const params = { node: rowNode, data: rowNode.data }; const height = gos.getCallback("getRowHeight")(params); if (_isFiniteNumber(height)) { if (height === 0) { beans.log.warn(23); } return { height: Math.max(1, height), estimated: false }; } } if (rowNode.detail && gos.get("masterDetail")) { return getMasterDetailRowHeight(gos); } const gridOptionsRowHeight = gos.get("rowHeight"); const rowHeight = gridOptionsRowHeight && _isFiniteNumber(gridOptionsRowHeight) ? gridOptionsRowHeight : defaultRowHeight; return { height: rowHeight, estimated: false }; } function getMasterDetailRowHeight(gos) { if (gos.get("detailRowAutoHeight")) { return { height: 1, estimated: false }; } const defaultRowHeight = gos.get("detailRowHeight"); if (_isFiniteNumber(defaultRowHeight)) { return { height: defaultRowHeight, estimated: false }; } return { height: 300, estimated: false }; } function _getRowHeightAsNumber(beans) { const { environment, gos } = beans; const gridOptionsRowHeight = gos.get("rowHeight"); if (!gridOptionsRowHeight || _missing(gridOptionsRowHeight)) { return environment.getDefaultRowHeight(); } const rowHeight = environment.refreshRowHeightVariable(); if (rowHeight !== -1) { return rowHeight; } beans.log.warn(24); return environment.getDefaultRowHeight(); } function _getDomData(gos, element, key) { const domData = element[gos.getDomDataKey()]; return domData ? domData[key] : void 0; } function _setDomData(gos, element, key, value) { const domDataKey = gos.getDomDataKey(); let domData = element[domDataKey]; if (_missing(domData)) { domData = {}; element[domDataKey] = domData; } domData[key] = value; } function _isAnimateRows(gos) { if (gos.get("ensureDomOrder")) { return false; } return gos.get("animateRows"); } function _isGroupRowsSticky(gos) { return !(gos.get("paginateChildRows") || gos.get("groupHideOpenParents") || _isDomLayout(gos, "print")); } function _isColumnsSortingCoupledToGroup(gos) { const autoGroupColumnDef = gos.get("autoGroupColumnDef"); return !autoGroupColumnDef?.comparator && !gos.get("treeData"); } function _getGroupAggFiltering(gos) { const userValue = gos.get("groupAggFiltering"); if (typeof userValue === "function") { return gos.getCallback("groupAggFiltering"); } if (userValue === true) { return () => true; } return void 0; } function _getGrandTotalRow(gos) { return gos.get("grandTotalRow"); } function _getGrandTotalPinnedFloat(grandTotalRow) { switch (grandTotalRow) { case "pinnedTop": return "top"; case "pinnedBottom": return "bottom"; default: return null; } } function _getGroupTotalRowCallback(gos) { const userValue = gos.get("groupTotalRow"); if (typeof userValue === "function") { return gos.getCallback("groupTotalRow"); } return () => userValue ?? void 0; } function _isGroupMultiAutoColumn(gos) { const isHideOpenParents = !!gos.get("groupHideOpenParents"); if (isHideOpenParents) { return true; } return gos.get("groupDisplayType") === "multipleColumns"; } function _isGroupHideColumnsUntilExpanded(gos) { return _isGroupMultiAutoColumn(gos) && gos.get("groupHideColumnsUntilExpanded") && _isClientSideRowModel(gos); } function _isGroupUseEntireRow(gos, pivotMode) { if (pivotMode) { return false; } return gos.get("groupDisplayType") === "groupRows"; } function _isFullWidthGroupRow(gos, node, pivotMode) { return !!node.group && !node.footer && _isGroupUseEntireRow(gos, pivotMode); } function _getRowIdCallback(beans) { const getRowId = beans.gos.getCallback("getRowId"); if (getRowId === void 0) { return getRowId; } return (params) => { let id = getRowId(params); if (typeof id !== "string") { _doOnce(() => beans.log.warn(25, { id }), `getRowIdString:${beans.context.getId()}`); id = String(id); } return id; }; } function _canSkipShowingRowGroup(gos, node) { const isSkippingGroups = gos.get("groupHideParentOfSingleChild"); if (isSkippingGroups === true) { return true; } if (isSkippingGroups === "leafGroupsOnly" && node.leafGroup) { return true; } if (gos.get("groupRemoveSingleChildren")) { return true; } if (gos.get("groupRemoveLowestSingleChildren") && node.leafGroup) { return true; } return false; } function _getMaxConcurrentDatasourceRequests(gos) { const res = gos.get("maxConcurrentDatasourceRequests"); return res > 0 ? res : void 0; } function _shouldUpdateColVisibilityAfterGroup(gos, isGrouped) { const preventVisibilityChanges = gos.get("suppressGroupChangesColumnVisibility"); if (preventVisibilityChanges === true) { return false; } if (isGrouped && preventVisibilityChanges === "suppressHideOnGroup") { return false; } if (!isGrouped && preventVisibilityChanges === "suppressShowOnUngroup") { return false; } const legacySuppressOnGroup = gos.get("suppressRowGroupHidesColumns"); if (isGrouped && legacySuppressOnGroup === true) { return false; } const legacySuppressOnUngroup = gos.get("suppressMakeColumnVisibleAfterUnGroup"); if (!isGrouped && legacySuppressOnUngroup === true) { return false; } return true; } function _getCheckboxes(selection) { return selection?.checkboxes ?? true; } function _getHeaderCheckbox(selection) { return selection?.mode === "multiRow" && (selection.headerCheckbox ?? true); } function _getCheckboxLocation(rowSelection) { if (typeof rowSelection !== "object") { return void 0; } return rowSelection.checkboxLocation ?? "selectionColumn"; } function _getHideDisabledCheckboxes(selection) { return selection?.hideDisabledCheckboxes ?? false; } function _isUsingNewRowSelectionAPI(gos) { const rowSelection = gos.get("rowSelection"); return typeof rowSelection !== "string"; } function _isUsingNewCellSelectionAPI(gos) { return gos.get("cellSelection") !== void 0; } function _getSuppressMultiRanges(gos) { const selection = gos.get("cellSelection"); const useNewAPI = selection !== void 0; if (!useNewAPI) { return gos.get("suppressMultiRangeSelection"); } return typeof selection !== "boolean" ? selection?.suppressMultiRanges ?? false : false; } function _isCellSelectionEnabled(gos) { const selection = gos.get("cellSelection"); const useNewAPI = selection !== void 0; return useNewAPI ? !!selection : gos.get("enableRangeSelection"); } function _getFillHandle(gos) { const selection = gos.get("cellSelection"); const useNewAPI = selection !== void 0; if (!useNewAPI) { return { mode: "fill", setFillValue: gos.get("fillOperation"), direction: gos.get("fillHandleDirection"), suppressClearOnFillReduction: gos.get("suppressClearOnFillReduction") }; } return typeof selection !== "boolean" && selection.handle?.mode === "fill" ? selection.handle : void 0; } function _getEnableColumnSelection(gos) { const cellSelection = gos.get("cellSelection") ?? false; return (typeof cellSelection === "object" && cellSelection.enableColumnSelection) ?? false; } function _getEnableClickSelection(gos) { const selection = gos.get("rowSelection") ?? "single"; if (typeof selection === "string") { const suppressRowClickSelection = gos.get("suppressRowClickSelection"); const suppressRowDeselection = gos.get("suppressRowDeselection"); if (suppressRowClickSelection && suppressRowDeselection) { return false; } else if (suppressRowClickSelection) { return "enableDeselection"; } else if (suppressRowDeselection) { return "enableSelection"; } else { return true; } } return selection.mode === "singleRow" || selection.mode === "multiRow" ? selection.enableClickSelection ?? false : false; } function _getEnableSelection(gos) { const enableClickSelection = _getEnableClickSelection(gos); return enableClickSelection === true || enableClickSelection === "enableSelection"; } function _getEnableDeselection(gos) { const enableClickSelection = _getEnableClickSelection(gos); return enableClickSelection === true || enableClickSelection === "enableDeselection"; } function _getIsRowSelectable(gos) { const selection = gos.get("rowSelection"); if (typeof selection === "string") { return gos.get("isRowSelectable"); } return selection?.isRowSelectable; } function _getRowSelectionMode(arg) { const selection = "beanName" in arg && arg.beanName === "gos" ? arg.get("rowSelection") : arg.rowSelection; if (typeof selection === "string") { switch (selection) { case "multiple": return "multiRow"; case "single": return "singleRow"; default: return; } } switch (selection?.mode) { case "multiRow": case "singleRow": return selection.mode; default: return; } } function _isMultiRowSelection(arg) { const mode = _getRowSelectionMode(arg); return mode === "multiRow"; } function _getEnableSelectionWithoutKeys(gos) { const selection = gos.get("rowSelection"); if (typeof selection === "string") { return gos.get("rowMultiSelectWithClick"); } return selection?.enableSelectionWithoutKeys ?? false; } function _getGroupSelection(gos) { const selection = gos.get("rowSelection"); if (typeof selection === "string") { const groupSelectsChildren = gos.get("groupSelectsChildren"); const groupSelectsFiltered = gos.get("groupSelectsFiltered"); if (groupSelectsChildren && groupSelectsFiltered) { return "filteredDescendants"; } else if (groupSelectsChildren) { return "descendants"; } else { return "self"; } } return selection?.mode === "multiRow" ? selection.groupSelects : void 0; } function _getSelectAll(gos, defaultValue = true) { const rowSelection = gos.get("rowSelection"); if (typeof rowSelection !== "object") { return defaultValue ? "all" : void 0; } return rowSelection.mode === "multiRow" ? rowSelection.selectAll : "all"; } function _getCtrlASelectsRows(gos) { const rowSelection = gos.get("rowSelection"); if (typeof rowSelection === "string") { return false; } return rowSelection?.mode === "multiRow" ? rowSelection.ctrlASelectsRows ?? false : false; } function _getGroupSelectsDescendants(gos) { const groupSelection = _getGroupSelection(gos); return groupSelection === "descendants" || groupSelection === "filteredDescendants"; } function _getMasterSelects(gos) { const rowSelection = gos.get("rowSelection"); return typeof rowSelection === "object" && rowSelection.masterSelects || "self"; } function _isSetFilterByDefault(gos) { return gos.isModuleRegistered("SetFilter") && !gos.get("suppressSetFilterByDefault"); } function _isLegacyMenuEnabled(gos) { return gos.get("columnMenu") === "legacy"; } function _isColumnMenuAnchoringEnabled(gos) { return !_isLegacyMenuEnabled(gos); } function _getCallbackForEvent(eventName) { if (!eventName || eventName.length < 2) { return eventName; } return "on" + eventName[0].toUpperCase() + eventName.substring(1); } function _combineAttributesAndGridOptions(gridOptions, component, gridOptionsKeys) { if (typeof gridOptions !== "object") { gridOptions = {}; } const mergedOptions = { ...gridOptions }; for (const key of gridOptionsKeys) { const value = component[key]; if (typeof value !== "undefined") { mergedOptions[key] = value; } } return mergedOptions; } function _processOnChange(changes, api) { if (!changes) { return; } const gridChanges = {}; let hasChanges = false; for (const key of Object.keys(changes)) { gridChanges[key] = changes[key]; hasChanges = true; } if (!hasChanges) { return; } const internalUpdateEvent = { type: "gridOptionsChanged", options: gridChanges }; api.dispatchEvent(internalUpdateEvent); const event = { type: "componentStateChanged", ...gridChanges }; api.dispatchEvent(event); } function _addGridCommonParams(gos, params) { return gos.addCommon(params); } function _getGridOption(providedGridOptions, gridOption) { return providedGridOptions[gridOption] ?? providedGridOptions[`gridOptions`]?.[gridOption] ?? _getGlobalGridOption(gridOption) ?? GRID_OPTION_DEFAULTS[gridOption]; } function _interpretAsRightClick({ gos }, event) { return event.button === 2 || event.ctrlKey && gos.get("allowContextMenuWithControlKey"); } // packages/ag-grid-community/src/columns/colDefUtils.ts function _createUserColumn(beans, userColDef, colId, isPrimary, buildToken) { const merged = _addColumnDefaultAndTypes(beans, userColDef, colId); const column = new AgColumn(merged, userColDef, colId, isPrimary, "user"); column.buildToken = buildToken; beans.context.createBean(column); return column; } function _addColumnDefaultAndTypes(beans, colDef, colId, isAutoCol) { const { gos, dataTypeSvc } = beans; const res = {}; const defaultColDef = gos.get("defaultColDef"); _mergeDeep(res, defaultColDef, false, true); const dataTypeDefinitionColumnType = dataTypeSvc?.updateColDefAndGetColumnType(res, colDef, colId); const columnTypes = colDef.type ?? dataTypeDefinitionColumnType ?? res.type; res.type = columnTypes; if (columnTypes) { assignColumnTypes(beans, convertColumnTypes(columnTypes), res); } const cellDataType = res.cellDataType; _mergeDeep(res, colDef, false, true); if (cellDataType !== void 0) { res.cellDataType = cellDataType; } const autoGroupColDef = gos.get("autoGroupColumnDef"); if (autoGroupColDef && colDef.rowGroup && _isColumnsSortingCoupledToGroup(gos)) { _mergeDeep( res, { sort: autoGroupColDef.sort, initialSort: autoGroupColDef.initialSort }, false, true ); } dataTypeSvc?.postProcess(res); dataTypeSvc?.validateColDef(res, colDef, defaultColDef, colId); gos.validateColDef(res, colId, isAutoCol); return res; } function assignColumnTypes(beans, typeKeys, colDefMerged) { const typeKeysLen = typeKeys.length; if (typeKeysLen === 0) { return; } const userTypes = beans.gos.get("columnTypes"); if (userTypes == null) { mergeTypeKeys(beans, colDefMerged, typeKeys, typeKeysLen, DefaultColumnTypes); return; } const allColumnTypes = { ...DefaultColumnTypes }; const userKeys = Object.keys(userTypes); for (let i = 0, len = userKeys.length; i < len; ++i) { const key = userKeys[i]; const value = userTypes[key]; if (key in allColumnTypes) { beans.log.warn(34, { key }); } else { if (value.type) { beans.log.warn(35); } allColumnTypes[key] = value; } } mergeTypeKeys(beans, colDefMerged, typeKeys, typeKeysLen, allColumnTypes); } function mergeTypeKeys(beans, colDefMerged, typeKeys, typeKeysLen, typeMap) { for (let i = 0; i < typeKeysLen; ++i) { const t = typeKeys[i].trim(); const typeColDef = typeMap[t]; if (typeColDef) { _mergeDeep(colDefMerged, typeColDef, false, true); } else { beans.log.warn(36, { t }); } } } // packages/ag-grid-community/src/columns/columnStateUtils.ts import { _areEqual as _areEqual2, _symmetricDiff } from "ag-stack"; // packages/ag-grid-community/src/columnMove/columnMoveUtils.ts import { _indexMap } from "ag-stack"; // packages/ag-grid-community/src/context/beanStub.ts import { AgBeanStub } from "ag-stack"; var BeanStub = class extends AgBeanStub { warn(...args) { this.beans.log.warn(...args); } error(...args) { this.beans.log.error(...args); } deprecated(...args) { this.beans.log.deprecated(...args); } }; // packages/ag-grid-community/src/entities/agProvidedColumnGroup.ts function isProvidedColumnGroup(col) { return col instanceof AgProvidedColumnGroup; } var AgProvidedColumnGroup = class extends BeanStub { constructor(colGroupDef, groupId, padding, level) { super(); this.colGroupDef = colGroupDef; this.groupId = groupId; this.padding = padding; this.level = level; this.isColumn = false; this.expandable = false; this.expanded = false; /** Most recent build token that claimed this group — detects "already used in this refresh". */ this.buildToken = 0; /** Packed `AgColumnGroup` display instances by dense per-refresh `partId` (`displayInstances[0]` is primary), lazily allocated and pruned by `columnGroupService`. */ this.displayInstances = null; /** Cache previous `setExpandable` visibility so `AgColumn.setVisible` ancestor walk can stop when unchanged. */ this.lastVisible = false; // stable key for framework (React) rendering and old-vs-new destroy diffing this.instanceId = getNextColInstanceId(); this.expanded = !!colGroupDef?.openByDefault; } getInstanceId() { return this.instanceId; } getOriginalParent() { return this.originalParent; } getLevel() { return this.level; } /** Visible iff at least one child is visible. */ isVisible() { const children = this.children; for (let i = 0, len = children.length; i < len; ++i) { if (children[i].isVisible()) { return true; } } return false; } isPadding() { return this.padding; } setExpanded(expanded) { expanded = !!expanded; if (this.expanded === expanded) { return false; } this.expanded = expanded; this.dispatchLocalEvent({ type: "expandedChanged" }); return true; } isExpandable() { return this.expandable; } isExpanded() { return this.expanded; } getGroupId() { return this.groupId; } getId() { return this.groupId; } getChildren() { return this.children; } getColGroupDef() { return this.colGroupDef; } getLeafColumns() { const result = []; this.addLeafColumns(result); return result; } addLeafColumns(leafColumns) { const children = this.children; for (let i = 0, len = children.length; i < len; ++i) { const child = children[i]; if (child.isColumn) { leafColumns.push(child); } else { child.addLeafColumns(leafColumns); } } } getColumnGroupShow() { return this.colGroupDef?.columnGroupShow; } /** Recompute child-driven expandability and return whether `AgColumn.setVisible` should continue ancestor walking. */ setExpandable() { if (this.padding) { return true; } const flags = walkForExpandFlags(this.children, 0); const expandable = flags === EXPANDABLE_ALL; if (this.expandable !== expandable) { this.expandable = expandable; this.dispatchLocalEvent({ type: "expandableChanged" }); } const visible = flags !== 0; if (this.lastVisible === visible) { return false; } this.lastVisible = visible; return true; } }; var FLAG_SHOWING_WHEN_OPEN = 1; var FLAG_SHOWING_WHEN_CLOSED = 2; var FLAG_CHANGEABLE = 4; var EXPANDABLE_ALL = 7; var walkForExpandFlags = (items, flags) => { for (let i = 0, n = items.length; i < n; ++i) { const item = items[i]; if (isProvidedColumnGroup(item) && item.padding) { flags = walkForExpandFlags(item.children, flags); } else if (item.isVisible()) { const show = item.getColumnGroupShow(); if (show === "open") { flags |= FLAG_SHOWING_WHEN_OPEN | FLAG_CHANGEABLE; } else if (show === "closed") { flags |= FLAG_SHOWING_WHEN_CLOSED | FLAG_CHANGEABLE; } else { flags |= FLAG_SHOWING_WHEN_OPEN | FLAG_SHOWING_WHEN_CLOSED; } } if (flags === EXPANDABLE_ALL) { return flags; } } return flags; }; // packages/ag-grid-community/src/columnMove/columnMoveUtils.ts function placeLockedColumns(cols, gos) { let leftCount = 0; let rightCount = 0; const len = cols.length; let firstLeftIdx = len; let lastLeftIdx = -1; let firstRightIdx = len; let lastRightIdx = -1; for (let i = 0; i < len; ++i) { const pos = cols[i].colDef.lockPosition; if (pos === "right") { ++rightCount; if (firstRightIdx === len) { firstRightIdx = i; } lastRightIdx = i; } else if (pos === "left" || pos === true) { ++leftCount; if (firstLeftIdx === len) { firstLeftIdx = i; } lastLeftIdx = i; } } if (leftCount === 0 && rightCount === 0) { return cols; } let leftIdx; let normalIdx; let rightIdx; if (gos.get("enableRtl")) { if (lastRightIdx === rightCount - 1 && firstLeftIdx === len - leftCount) { return cols; } rightIdx = 0; normalIdx = rightCount; leftIdx = len - leftCount; } else { if (lastLeftIdx === leftCount - 1 && firstRightIdx === len - rightCount) { return cols; } leftIdx = 0; normalIdx = leftCount; rightIdx = len - rightCount; } const result = new Array(len); for (let i = 0; i < len; ++i) { const col = cols[i]; const pos = col.colDef.lockPosition; let idx; if (pos === "right") { idx = rightIdx++; } else if (pos === "left" || pos === true) { idx = leftIdx++; } else { idx = normalIdx++; } result[idx] = col; } return result; } function doesMovePassMarryChildren(allColumnsCopy, gridBalancedTree) { const positionByCol = _indexMap(allColumnsCopy); let min = 0; let max = 0; let count = 0; const accumulate = (children) => { for (let i = 0, len = children.length; i < len; ++i) { const child = children[i]; if (isProvidedColumnGroup(child)) { accumulate(child.children); continue; } const idx = positionByCol.get(child) ?? -1; if (count === 0) { min = idx; max = idx; } else if (idx < min) { min = idx; } else if (idx > max) { max = idx; } ++count; } }; const visit = (tree) => { for (let i = 0, len = tree.length; i < len; ++i) { const child = tree[i]; if (!isProvidedColumnGroup(child)) { continue; } if (child.colGroupDef?.marryChildren) { count = 0; accumulate(child.children); if (count > 1 && max - min > count - 1) { return false; } } if (!visit(child.children)) { return false; } } return true; }; return visit(gridBalancedTree); } // packages/ag-grid-community/src/columns/columnEventUtils.ts function getCommonValue(cols, valueGetter) { if (!cols || cols.length == 0) { return void 0; } const firstValue = valueGetter(cols[0]); for (let i = 1; i < cols.length; i++) { if (firstValue !== valueGetter(cols[i])) { return void 0; } } return firstValue; } function dispatchColumnPinnedEvent(eventSvc, changedColumns, source) { if (!changedColumns.length) { return; } const column = changedColumns.length === 1 ? changedColumns[0] : null; const pinned = getCommonValue(changedColumns, (col) => col.getPinned()); eventSvc.dispatchEvent({ type: "columnPinned", // mistake in typing, 'undefined' should be allowed, as 'null' means 'not pinned' pinned: pinned != null ? pinned : null, columns: changedColumns, column, source }); } function dispatchColumnVisibleEvent(eventSvc, changedColumns, source) { if (!changedColumns.length) { return; } const column = changedColumns.length === 1 ? changedColumns[0] : null; const visible = getCommonValue(changedColumns, (col) => col.isVisible()); eventSvc.dispatchEvent({ type: "columnVisible", visible, columns: changedColumns, column, source }); } function _dispatchColumnChangedEvent(eventSvc, type, columns, source) { eventSvc.dispatchEvent({ type, columns, column: columns?.length == 1 ? columns[0] : null, source }); } function dispatchColumnResizedEvent(eventSvc, columns, finished, source, flexColumns = null) { if (columns?.length) { eventSvc.dispatchEvent({ type: "columnResized", columns, column: columns.length === 1 ? columns[0] : null, flexColumns, finished, source }); } } // packages/ag-grid-community/src/columns/columnStateUtils.ts var updateSomeColumnState = (beans, column, hide, sort, sortIndex, pinned, flex, source) => { const { sortSvc, pinnedCols, colFlex } = beans; if (hide !== void 0) { column.setVisible(!hide, source); } if (sortSvc) { sortSvc.updateColSort(column, sort, source); if (sortIndex !== void 0) { sortSvc.setColSortIndex(column, sortIndex); } } if (pinned !== void 0) { pinnedCols?.setColPinned(column, pinned); } if (flex !== void 0) { colFlex?.setColFlex(column, flex); } }; function _setColsVisible(beans, keys, visible = false, source, filterLockedColumns = false) { const colModel = beans.colModel; const newVisible = visible === true; let changed = null; for (let i = 0, len = keys.length; i < len; ++i) { const key = keys[i]; const col = typeof key === "string" ? colModel.getCol(key) : key; if (col === void 0 || filterLockedColumns && col.colDef.lockVisible) { continue; } if (col.visible !== newVisible) { col.setVisible(newVisible, source); changed ?? (changed = []); changed.push(col); } } if (changed) { const { colAnimation, eventSvc } = beans; colAnimation?.start(); try { colModel.refreshColsDerivedState(); beans.visibleCols.refresh(source, false); eventSvc.dispatchEvent({ type: "columnEverythingChanged", source }); dispatchColumnVisibleEvent(eventSvc, changed, source); } finally { colAnimation?.finish(); } } } function _applyColumnState(beans, params, source) { const { colModel, colAnimation, calculatedColsSvc } = beans; const state = params.state; if (state && !Array.isArray(state)) { beans.log.warn(32); return false; } if (state && calculatedColsSvc?.restoreDynamicColumnDefs(state)) { calculatedColsSvc.refreshDynamicColumns(source); } const providedCols = colModel.colDefList; const selectionCol = beans.selectionColSvc?.column; if (!providedCols.length && !selectionCol) { return false; } colAnimation?.start(); try { const stateChanges = captureColumnStateChanges(beans); let unmatched = applyStateToCols(beans, state ?? null, providedCols, params, source, true); if (unmatched !== null || params.defaultState) { const pivotResultColsList = beans.pivotResultCols?.pivotCols; unmatched = applyStateToCols(beans, unmatched, pivotResultColsList, params, source, false); } finalizeChange(beans, params, source, stateChanges); return unmatched === null; } finally { colAnimation?.finish(); } } function applyStateToCols(beans, states, existingColumns, params, source, primaryPass) { const colModel = beans.colModel; const defaultState = params.defaultState; let autoColStates = null; let selectionColStates = null; let unmatchedStates = null; const matched = defaultState ? /* @__PURE__ */ new Set() : null; if (states) { for (let i = 0, len = states.length; i < len; ++i) { const state = states[i]; const colId = state.colId; let column; if (colId != null) { if (colId.startsWith(GROUP_AUTO_COLUMN_ID)) { autoColStates ?? (autoColStates = []); autoColStates.push(state); continue; } if (colId.startsWith(SELECTION_COLUMN_ID)) { selectionColStates ?? (selectionColStates = []); selectionColStates.push(state); continue; } if (primaryPass) { column = colModel.getNonPivotColById(colId); } else { const col = colModel.getCol(colId); column = col?.colDef.pivotKeys == null ? null : col; } } if (!column) { unmatchedStates ?? (unmatchedStates = []); unmatchedStates.push(state); } else { applyFieldState(beans, column, state, defaultState, source); matched?.add(column); } } } if (matched !== null && existingColumns) { for (let i = 0, len = existingColumns.length; i < len; ++i) { const col = existingColumns[i]; if (!matched.has(col)) { applyFieldState(beans, col, null, defaultState, source); } } } if (primaryPass) { applyStructuralStateChanges(beans, autoColStates, selectionColStates, defaultState, source); } return unmatchedStates; } function applyStructuralStateChanges(beans, autoColStates, selectionColStates, defaultState, source) { const { autoColSvc, selectionColSvc, rowGroupColsSvc, pivotColsSvc, valueColsSvc } = beans; rowGroupColsSvc?.sortByPendingState(); pivotColsSvc?.sortByPendingState(); valueColsSvc?.sortByPendingState(); beans.colModel.refreshCols(false, source); const selectionCol = selectionColSvc?.column; syncServiceColumnsWithState(beans, autoColStates, autoColSvc?.columns ?? [], defaultState, source); syncServiceColumnsWithState(beans, selectionColStates, selectionCol ? [selectionCol] : [], defaultState, source); } function syncServiceColumnsWithState(beans, colStates, serviceCols, defaultState, source) { let matched = null; if (colStates !== null) { matched = /* @__PURE__ */ new Set(); for (let s = 0, sLen = colStates.length; s < sLen; ++s) { const stateItem = colStates[s]; const stateColId = stateItem.colId; for (let i = 0, len = serviceCols.length; i < len; ++i) { const sc = serviceCols[i]; if (sc.colId === stateColId) { matched.add(sc); applyFieldState(beans, sc, stateItem, defaultState, source); break; } } } } if (defaultState) { for (let i = 0, len = serviceCols.length; i < len; ++i) { const c = serviceCols[i]; if (!matched?.has(c)) { applyFieldState(beans, c, null, defaultState, source); } } } } function applyFieldState(beans, column, stateItem, defaultState, source) { const flex = orDefault(stateItem?.flex, defaultState?.flex); const maybeSortDir = orDefault(stateItem?.sort, defaultState?.sort); const maybeSortType = orDefault(stateItem?.sortType, defaultState?.sortType); const isSortUpdate = isSortDirectionValid(maybeSortDir) || isSortTypeValid(maybeSortType); const newSortDef = isSortUpdate ? { type: _normalizeSortType(maybeSortType), direction: normalizeSortDirection(maybeSortDir) } : void 0; updateSomeColumnState( beans, column, orDefault(stateItem?.hide, defaultState?.hide), newSortDef, orDefault(stateItem?.sortIndex, defaultState?.sortIndex), orDefault(stateItem?.pinned, defaultState?.pinned), flex, source ); const headerName = orDefault(stateItem?.headerName, defaultState?.headerName); if (headerName !== void 0) { column.setHeaderNameOverride(headerName); } if (flex == null) { const width = orDefault(stateItem?.width, defaultState?.width); if (width != null) { const minColWidth = column.colDef.minWidth ?? beans.environment.getDefaultColumnMinWidth(); if (minColWidth != null && width >= minColWidth) { column.setActualWidth(width, source); } } } if (column.colKind === "auto-group" || !column.primary) { return; } beans.valueColsSvc?.syncColState(column, stateItem, defaultState, source); beans.rowGroupColsSvc?.syncColState(column, stateItem, defaultState, source); beans.pivotColsSvc?.syncColState(column, stateItem, defaultState, source); beans.showValuesAsSvc?.syncColState(column, stateItem, defaultState, source); const maybePivotSort = orDefault(stateItem?.pivotSort, defaultState?.pivotSort); if (maybePivotSort !== void 0) { column.pivotSort = normalizeSortDirection(maybePivotSort); } } function _resetColumnState(beans, source) { const { colModel, autoColSvc, selectionColSvc, eventSvc, gos, colAnimation, calculatedColsSvc } = beans; const userColumnsCleared = beans.userColumnSvc?.clear() ?? false; if (calculatedColsSvc) { const dynamicColsReset = calculatedColsSvc.resetDynamicColumnDefs(true); if (dynamicColsReset || userColumnsCleared) { calculatedColsSvc.refreshDynamicColumns(source); } } else if (userColumnsCleared) { colModel.rebuildCols(source); } if (!colModel.colDefList.length) { return; } const selectionCol = selectionColSvc?.column ?? null; const initialAutoCols = autoColSvc?.columns; const initialAutoLen = initialAutoCols?.length ?? 0; const columnStates = new Array(initialAutoLen + (selectionCol ? 1 : 0) + colModel.colDefList.length); let stateIdx = 0; let maxRowGroupIndex = -1; let maxPivotIndex = -1; const addColState = (col) => { const stateItem = getColumnStateFromColDef(beans, col); const { rowGroupIndex, pivotIndex } = stateItem; if (rowGroupIndex != null && rowGroupIndex > maxRowGroupIndex) { maxRowGroupIndex = rowGroupIndex; } if (pivotIndex != null && pivotIndex > maxPivotIndex) { maxPivotIndex = pivotIndex; } columnStates[stateIdx++] = stateItem; }; if (initialAutoCols) { for (let i = 0; i < initialAutoLen; ++i) { addColState(initialAutoCols[i]); } } if (selectionCol) { addColState(selectionCol); } forEachColTreeLeaf(colModel.colDefTree, addColState); for (let i = 0, len = columnStates.length; i < len; ++i) { const stateItem = columnStates[i]; if (stateItem.rowGroup && stateItem.rowGroupIndex == null) { stateItem.rowGroupIndex = ++maxRowGroupIndex; } if (stateItem.pivot && stateItem.pivotIndex == null) { stateItem.pivotIndex = ++maxPivotIndex; } } colAnimation?.start(); try { const stateChanges = captureColumnStateChanges(beans); applyStateToCols(beans, columnStates, colModel.colDefList, {}, source, true); const primaryCols = colModel.colDefList; for (let i = 0, len = primaryCols.length; i < len; ++i) { const col = primaryCols[i]; col.pivotSort = _resolvePivotSortFromColDef(col.colDef); } const autoCols = autoColSvc?.columns; const autoColsLen = autoCols?.length ?? 0; const orderState = new Array((selectionCol ? 1 : 0) + autoColsLen + colModel.colDefList.length); let orderIdx = 0; if (selectionCol) { orderState[orderIdx++] = { colId: selectionCol.colId }; } for (let i = 0; i < autoColsLen; ++i) { orderState[orderIdx++] = { colId: autoCols[i].colId }; } forEachColTreeLeaf(colModel.colDefTree, (col) => { orderState[orderIdx++] = { colId: col.colId }; }); const groupOverrides = colModel.groupHeaderNameOverrides; if (groupOverrides.size) { groupOverrides.clear(); eventSvc.dispatchEvent({ type: "columnHeaderNameChanged", column: null, columns: null, columnGroup: null, source }); } finalizeChange(beans, { state: orderState, applyOrder: true }, source, stateChanges); } finally { colAnimation?.finish(); } eventSvc.dispatchEvent(_addGridCommonParams(gos, { type: "columnsReset", source })); } function finalizeChange(beans, params, source, changes) { orderLiveColsLikeState(beans, params); beans.visibleCols.refresh(source, false); beans.eventSvc.dispatchEvent({ type: "columnEverythingChanged", source }); dispatchColStateChanges(beans, source, changes); } function orderLiveColsLikeState(beans, params) { const colModel = beans.colModel; const state = params.state; if (!params.applyOrder || !state || !colModel.ready) { return; } const colsById = colModel.colsById; const currentList = colModel.colsList; const consumed = /* @__PURE__ */ new Set(); const newOrder = []; for (let i = 0, len = state.length; i < len; ++i) { const colId = state[i].colId; if (colId == null) { continue; } const col = colsById[colId]; if (col != null && col.inColsList && !consumed.has(col)) { newOrder.push(col); consume