UNPKG

7.74 kBJavaScriptView Raw
1/**
2 * ag-grid - Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components
3 * @version v18.1.2
4 * @link http://www.ag-grid.com/
5 * @license MIT
6 */
7"use strict";
8var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
9 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
11 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;
12 return c > 3 && r && Object.defineProperty(target, key, r), r;
13};
14var __metadata = (this && this.__metadata) || function (k, v) {
15 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
16};
17Object.defineProperty(exports, "__esModule", { value: true });
18var context_1 = require("./context/context");
19var eventService_1 = require("./eventService");
20var events_1 = require("./events");
21var gridOptionsWrapper_1 = require("./gridOptionsWrapper");
22var columnApi_1 = require("./columnController/columnApi");
23var columnController_1 = require("./columnController/columnController");
24var utils_1 = require("./utils");
25var gridCell_1 = require("./entities/gridCell");
26var gridApi_1 = require("./gridApi");
27var cellComp_1 = require("./rendering/cellComp");
28var FocusedCellController = (function () {
29 function FocusedCellController() {
30 }
31 FocusedCellController.prototype.init = function () {
32 this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_PIVOT_MODE_CHANGED, this.clearFocusedCell.bind(this));
33 this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_EVERYTHING_CHANGED, this.clearFocusedCell.bind(this));
34 this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_GROUP_OPENED, this.clearFocusedCell.bind(this));
35 this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_MOVED, this.clearFocusedCell.bind(this));
36 this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_PINNED, this.clearFocusedCell.bind(this));
37 this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_ROW_GROUP_CHANGED, this.clearFocusedCell.bind(this));
38 this.eventService.addEventListener(events_1.Events.EVENT_COLUMN_VISIBLE, this.clearFocusedCell.bind(this));
39 };
40 FocusedCellController.prototype.clearFocusedCell = function () {
41 this.focusedCell = null;
42 this.onCellFocused(false);
43 };
44 FocusedCellController.prototype.getFocusedCell = function () {
45 return this.focusedCell;
46 };
47 // we check if the browser is focusing something, and if it is, and
48 // it's the cell we think is focused, then return the cell. so this
49 // methods returns the cell if a) we think it has focus and b) the
50 // browser thinks it has focus. this then returns nothing if we
51 // first focus a cell, then second click outside the grid, as then the
52 // grid cell will still be focused as far as the grid is concerned,
53 // however the browser focus will have moved somewhere else.
54 FocusedCellController.prototype.getFocusCellToUseAfterRefresh = function () {
55 if (this.gridOptionsWrapper.isSuppressFocusAfterRefresh()) {
56 return null;
57 }
58 if (!this.focusedCell) {
59 return null;
60 }
61 // we check that the browser is actually focusing on the grid, if it is not, then
62 // we have nothing to worry about
63 var browserFocusedCell = this.getGridCellForDomElement(document.activeElement);
64 if (!browserFocusedCell) {
65 return null;
66 }
67 return this.focusedCell;
68 };
69 FocusedCellController.prototype.getGridCellForDomElement = function (eBrowserCell) {
70 var ePointer = eBrowserCell;
71 while (ePointer) {
72 var cellComp = this.gridOptionsWrapper.getDomData(ePointer, cellComp_1.CellComp.DOM_DATA_KEY_CELL_COMP);
73 if (cellComp) {
74 return cellComp.getGridCell();
75 }
76 ePointer = ePointer.parentNode;
77 }
78 return null;
79 };
80 FocusedCellController.prototype.setFocusedCell = function (rowIndex, colKey, floating, forceBrowserFocus) {
81 if (forceBrowserFocus === void 0) { forceBrowserFocus = false; }
82 var column = utils_1.Utils.makeNull(this.columnController.getGridColumn(colKey));
83 this.focusedCell = new gridCell_1.GridCell({ rowIndex: rowIndex,
84 floating: utils_1.Utils.makeNull(floating),
85 column: column });
86 this.onCellFocused(forceBrowserFocus);
87 };
88 FocusedCellController.prototype.isCellFocused = function (gridCell) {
89 if (utils_1.Utils.missing(this.focusedCell)) {
90 return false;
91 }
92 return this.focusedCell.column === gridCell.column && this.isRowFocused(gridCell.rowIndex, gridCell.floating);
93 };
94 FocusedCellController.prototype.isRowNodeFocused = function (rowNode) {
95 return this.isRowFocused(rowNode.rowIndex, rowNode.rowPinned);
96 };
97 FocusedCellController.prototype.isAnyCellFocused = function () {
98 return !!this.focusedCell;
99 };
100 FocusedCellController.prototype.isRowFocused = function (rowIndex, floating) {
101 if (utils_1.Utils.missing(this.focusedCell)) {
102 return false;
103 }
104 var floatingOrNull = utils_1.Utils.makeNull(floating);
105 return this.focusedCell.rowIndex === rowIndex && this.focusedCell.floating === floatingOrNull;
106 };
107 FocusedCellController.prototype.onCellFocused = function (forceBrowserFocus) {
108 var event = {
109 type: events_1.Events.EVENT_CELL_FOCUSED,
110 forceBrowserFocus: forceBrowserFocus,
111 rowIndex: null,
112 column: null,
113 floating: null,
114 api: this.gridApi,
115 columnApi: this.columnApi,
116 rowPinned: null
117 };
118 if (this.focusedCell) {
119 event.rowIndex = this.focusedCell.rowIndex;
120 event.column = this.focusedCell.column;
121 event.rowPinned = this.focusedCell.floating;
122 }
123 this.eventService.dispatchEvent(event);
124 };
125 __decorate([
126 context_1.Autowired('eventService'),
127 __metadata("design:type", eventService_1.EventService)
128 ], FocusedCellController.prototype, "eventService", void 0);
129 __decorate([
130 context_1.Autowired('gridOptionsWrapper'),
131 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
132 ], FocusedCellController.prototype, "gridOptionsWrapper", void 0);
133 __decorate([
134 context_1.Autowired('columnController'),
135 __metadata("design:type", columnController_1.ColumnController)
136 ], FocusedCellController.prototype, "columnController", void 0);
137 __decorate([
138 context_1.Autowired('columnApi'),
139 __metadata("design:type", columnApi_1.ColumnApi)
140 ], FocusedCellController.prototype, "columnApi", void 0);
141 __decorate([
142 context_1.Autowired('gridApi'),
143 __metadata("design:type", gridApi_1.GridApi)
144 ], FocusedCellController.prototype, "gridApi", void 0);
145 __decorate([
146 context_1.PostConstruct,
147 __metadata("design:type", Function),
148 __metadata("design:paramtypes", []),
149 __metadata("design:returntype", void 0)
150 ], FocusedCellController.prototype, "init", null);
151 FocusedCellController = __decorate([
152 context_1.Bean('focusedCellController')
153 ], FocusedCellController);
154 return FocusedCellController;
155}());
156exports.FocusedCellController = FocusedCellController;