ag-grid
Version:
Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components
157 lines (156 loc) • 7.74 kB
JavaScript
/**
* ag-grid - Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components
* @version v18.1.2
* @link http://www.ag-grid.com/
* @license MIT
*/
"use strict";
var __decorate = (this && this.__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 __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var context_1 = require("./context/context");
var eventService_1 = require("./eventService");
var events_1 = require("./events");
var gridOptionsWrapper_1 = require("./gridOptionsWrapper");
var columnApi_1 = require("./columnController/columnApi");
var columnController_1 = require("./columnController/columnController");
var utils_1 = require("./utils");
var gridCell_1 = require("./entities/gridCell");
var gridApi_1 = require("./gridApi");
var cellComp_1 = require("./rendering/cellComp");
var FocusedCellController = (function () {
function FocusedCellController() {
}
FocusedCellController.prototype.init = function () {
this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_PIVOT_MODE_CHANGED, this.clearFocusedCell.bind(this));
this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_EVERYTHING_CHANGED, this.clearFocusedCell.bind(this));
this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_GROUP_OPENED, this.clearFocusedCell.bind(this));
this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_MOVED, this.clearFocusedCell.bind(this));
this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_PINNED, this.clearFocusedCell.bind(this));
this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_ROW_GROUP_CHANGED, this.clearFocusedCell.bind(this));
this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_VISIBLE, this.clearFocusedCell.bind(this));
};
FocusedCellController.prototype.clearFocusedCell = function () {
this.focusedCell = null;
this.onCellFocused(false);
};
FocusedCellController.prototype.getFocusedCell = function () {
return this.focusedCell;
};
// we check if the browser is focusing something, and if it is, and
// it's the cell we think is focused, then return the cell. so this
// methods returns the cell if a) we think it has focus and b) the
// browser thinks it has focus. this then returns nothing if we
// first focus a cell, then second click outside the grid, as then the
// grid cell will still be focused as far as the grid is concerned,
// however the browser focus will have moved somewhere else.
FocusedCellController.prototype.getFocusCellToUseAfterRefresh = function () {
if (this.gridOptionsWrapper.isSuppressFocusAfterRefresh()) {
return null;
}
if (!this.focusedCell) {
return null;
}
// we check that the browser is actually focusing on the grid, if it is not, then
// we have nothing to worry about
var browserFocusedCell = this.getGridCellForDomElement(document.activeElement);
if (!browserFocusedCell) {
return null;
}
return this.focusedCell;
};
FocusedCellController.prototype.getGridCellForDomElement = function (eBrowserCell) {
var ePointer = eBrowserCell;
while (ePointer) {
var cellComp = this.gridOptionsWrapper.getDomData(ePointer, cellComp_1.CellComp.DOM_DATA_KEY_CELL_COMP);
if (cellComp) {
return cellComp.getGridCell();
}
ePointer = ePointer.parentNode;
}
return null;
};
FocusedCellController.prototype.setFocusedCell = function (rowIndex, colKey, floating, forceBrowserFocus) {
if (forceBrowserFocus === void 0) { forceBrowserFocus = false; }
var column = utils_1.Utils.makeNull(this.columnController.getGridColumn(colKey));
this.focusedCell = new gridCell_1.GridCell({ rowIndex: rowIndex,
floating: utils_1.Utils.makeNull(floating),
column: column });
this.onCellFocused(forceBrowserFocus);
};
FocusedCellController.prototype.isCellFocused = function (gridCell) {
if (utils_1.Utils.missing(this.focusedCell)) {
return false;
}
return this.focusedCell.column === gridCell.column && this.isRowFocused(gridCell.rowIndex, gridCell.floating);
};
FocusedCellController.prototype.isRowNodeFocused = function (rowNode) {
return this.isRowFocused(rowNode.rowIndex, rowNode.rowPinned);
};
FocusedCellController.prototype.isAnyCellFocused = function () {
return !!this.focusedCell;
};
FocusedCellController.prototype.isRowFocused = function (rowIndex, floating) {
if (utils_1.Utils.missing(this.focusedCell)) {
return false;
}
var floatingOrNull = utils_1.Utils.makeNull(floating);
return this.focusedCell.rowIndex === rowIndex && this.focusedCell.floating === floatingOrNull;
};
FocusedCellController.prototype.onCellFocused = function (forceBrowserFocus) {
var event = {
type: events_1.Events.EVENT_CELL_FOCUSED,
forceBrowserFocus: forceBrowserFocus,
rowIndex: null,
column: null,
floating: null,
api: this.gridApi,
columnApi: this.columnApi,
rowPinned: null
};
if (this.focusedCell) {
event.rowIndex = this.focusedCell.rowIndex;
event.column = this.focusedCell.column;
event.rowPinned = this.focusedCell.floating;
}
this.eventService.dispatchEvent(event);
};
__decorate([
context_1.Autowired('eventService'),
__metadata("design:type", eventService_1.EventService)
], FocusedCellController.prototype, "eventService", void 0);
__decorate([
context_1.Autowired('gridOptionsWrapper'),
__metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
], FocusedCellController.prototype, "gridOptionsWrapper", void 0);
__decorate([
context_1.Autowired('columnController'),
__metadata("design:type", columnController_1.ColumnController)
], FocusedCellController.prototype, "columnController", void 0);
__decorate([
context_1.Autowired('columnApi'),
__metadata("design:type", columnApi_1.ColumnApi)
], FocusedCellController.prototype, "columnApi", void 0);
__decorate([
context_1.Autowired('gridApi'),
__metadata("design:type", gridApi_1.GridApi)
], FocusedCellController.prototype, "gridApi", void 0);
__decorate([
context_1.PostConstruct,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], FocusedCellController.prototype, "init", null);
FocusedCellController = __decorate([
context_1.Bean('focusedCellController')
], FocusedCellController);
return FocusedCellController;
}());
exports.FocusedCellController = FocusedCellController;