UNPKG

12.3 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 constants_1 = require("./constants");
20var columnController_1 = require("./columnController/columnController");
21var utils_1 = require("./utils");
22var gridRow_1 = require("./entities/gridRow");
23var gridCell_1 = require("./entities/gridCell");
24var gridOptionsWrapper_1 = require("./gridOptionsWrapper");
25var pinnedRowModel_1 = require("./rowModels/pinnedRowModel");
26var CellNavigationService = (function () {
27 function CellNavigationService() {
28 }
29 // returns null if no cell to focus on, ie at the end of the grid
30 CellNavigationService.prototype.getNextCellToFocus = function (key, lastCellToFocus) {
31 // starting with the provided cell, we keep moving until we find a cell we can
32 // focus on.
33 var pointer = lastCellToFocus;
34 var finished = false;
35 // finished will be true when either:
36 // a) cell found that we can focus on
37 // b) run out of cells (ie the method returns null)
38 while (!finished) {
39 switch (key) {
40 case constants_1.Constants.KEY_UP:
41 pointer = this.getCellAbove(pointer);
42 break;
43 case constants_1.Constants.KEY_DOWN:
44 pointer = this.getCellBelow(pointer);
45 break;
46 case constants_1.Constants.KEY_RIGHT:
47 if (this.gridOptionsWrapper.isEnableRtl()) {
48 pointer = this.getCellToLeft(pointer);
49 }
50 else {
51 pointer = this.getCellToRight(pointer);
52 }
53 break;
54 case constants_1.Constants.KEY_LEFT:
55 if (this.gridOptionsWrapper.isEnableRtl()) {
56 pointer = this.getCellToRight(pointer);
57 }
58 else {
59 pointer = this.getCellToLeft(pointer);
60 }
61 break;
62 default:
63 console.log('ag-Grid: unknown key for navigation ' + key);
64 pointer = null;
65 break;
66 }
67 if (pointer) {
68 finished = this.isCellGoodToFocusOn(pointer);
69 }
70 else {
71 finished = true;
72 }
73 }
74 return pointer;
75 };
76 CellNavigationService.prototype.isCellGoodToFocusOn = function (gridCell) {
77 var column = gridCell.column;
78 var rowNode;
79 switch (gridCell.floating) {
80 case constants_1.Constants.PINNED_TOP:
81 rowNode = this.pinnedRowModel.getPinnedTopRow(gridCell.rowIndex);
82 break;
83 case constants_1.Constants.PINNED_BOTTOM:
84 rowNode = this.pinnedRowModel.getPinnedBottomRow(gridCell.rowIndex);
85 break;
86 default:
87 rowNode = this.rowModel.getRow(gridCell.rowIndex);
88 break;
89 }
90 var suppressNavigable = column.isSuppressNavigable(rowNode);
91 return !suppressNavigable;
92 };
93 CellNavigationService.prototype.getCellToLeft = function (lastCell) {
94 var colToLeft = this.columnController.getDisplayedColBefore(lastCell.column);
95 if (!colToLeft) {
96 return null;
97 }
98 else {
99 var gridCellDef = { rowIndex: lastCell.rowIndex, column: colToLeft, floating: lastCell.floating };
100 return new gridCell_1.GridCell(gridCellDef);
101 }
102 };
103 CellNavigationService.prototype.getCellToRight = function (lastCell) {
104 var colToRight = this.columnController.getDisplayedColAfter(lastCell.column);
105 // if already on right, do nothing
106 if (!colToRight) {
107 return null;
108 }
109 else {
110 var gridCellDef = { rowIndex: lastCell.rowIndex, column: colToRight, floating: lastCell.floating };
111 return new gridCell_1.GridCell(gridCellDef);
112 }
113 };
114 CellNavigationService.prototype.getRowBelow = function (lastRow) {
115 // if already on top row, do nothing
116 if (this.isLastRowInContainer(lastRow)) {
117 if (lastRow.isFloatingBottom()) {
118 return null;
119 }
120 else if (lastRow.isNotFloating()) {
121 if (this.pinnedRowModel.isRowsToRender(constants_1.Constants.PINNED_BOTTOM)) {
122 return new gridRow_1.GridRow(0, constants_1.Constants.PINNED_BOTTOM);
123 }
124 else {
125 return null;
126 }
127 }
128 else {
129 if (this.rowModel.isRowsToRender()) {
130 return new gridRow_1.GridRow(0, null);
131 }
132 else if (this.pinnedRowModel.isRowsToRender(constants_1.Constants.PINNED_BOTTOM)) {
133 return new gridRow_1.GridRow(0, constants_1.Constants.PINNED_BOTTOM);
134 }
135 else {
136 return null;
137 }
138 }
139 }
140 else {
141 return new gridRow_1.GridRow(lastRow.rowIndex + 1, lastRow.floating);
142 }
143 };
144 CellNavigationService.prototype.getCellBelow = function (lastCell) {
145 var rowBelow = this.getRowBelow(lastCell.getGridRow());
146 if (rowBelow) {
147 var gridCellDef = { rowIndex: rowBelow.rowIndex, column: lastCell.column, floating: rowBelow.floating };
148 return new gridCell_1.GridCell(gridCellDef);
149 }
150 else {
151 return null;
152 }
153 };
154 CellNavigationService.prototype.isLastRowInContainer = function (gridRow) {
155 if (gridRow.isFloatingTop()) {
156 var lastTopIndex = this.pinnedRowModel.getPinnedTopRowData().length - 1;
157 return lastTopIndex <= gridRow.rowIndex;
158 }
159 else if (gridRow.isFloatingBottom()) {
160 var lastBottomIndex = this.pinnedRowModel.getPinnedBottomRowData().length - 1;
161 return lastBottomIndex <= gridRow.rowIndex;
162 }
163 else {
164 var lastBodyIndex = this.rowModel.getPageLastRow();
165 return lastBodyIndex <= gridRow.rowIndex;
166 }
167 };
168 CellNavigationService.prototype.getRowAbove = function (lastRow) {
169 // if already on top row, do nothing
170 if (lastRow.rowIndex === 0) {
171 if (lastRow.isFloatingTop()) {
172 return null;
173 }
174 else if (lastRow.isNotFloating()) {
175 if (this.pinnedRowModel.isRowsToRender(constants_1.Constants.PINNED_TOP)) {
176 return this.getLastFloatingTopRow();
177 }
178 else {
179 return null;
180 }
181 }
182 else {
183 // last floating bottom
184 if (this.rowModel.isRowsToRender()) {
185 return this.getLastBodyCell();
186 }
187 else if (this.pinnedRowModel.isRowsToRender(constants_1.Constants.PINNED_TOP)) {
188 return this.getLastFloatingTopRow();
189 }
190 else {
191 return null;
192 }
193 }
194 }
195 else {
196 return new gridRow_1.GridRow(lastRow.rowIndex - 1, lastRow.floating);
197 }
198 };
199 CellNavigationService.prototype.getCellAbove = function (lastCell) {
200 var rowAbove = this.getRowAbove(lastCell.getGridRow());
201 if (rowAbove) {
202 var gridCellDef = { rowIndex: rowAbove.rowIndex, column: lastCell.column, floating: rowAbove.floating };
203 return new gridCell_1.GridCell(gridCellDef);
204 }
205 else {
206 return null;
207 }
208 };
209 CellNavigationService.prototype.getLastBodyCell = function () {
210 var lastBodyRow = this.rowModel.getPageLastRow();
211 return new gridRow_1.GridRow(lastBodyRow, null);
212 };
213 CellNavigationService.prototype.getLastFloatingTopRow = function () {
214 var lastFloatingRow = this.pinnedRowModel.getPinnedTopRowData().length - 1;
215 return new gridRow_1.GridRow(lastFloatingRow, constants_1.Constants.PINNED_TOP);
216 };
217 CellNavigationService.prototype.getNextTabbedCell = function (gridCell, backwards) {
218 if (backwards) {
219 return this.getNextTabbedCellBackwards(gridCell);
220 }
221 else {
222 return this.getNextTabbedCellForwards(gridCell);
223 }
224 };
225 CellNavigationService.prototype.getNextTabbedCellForwards = function (gridCell) {
226 var displayedColumns = this.columnController.getAllDisplayedColumns();
227 var newRowIndex = gridCell.rowIndex;
228 var newFloating = gridCell.floating;
229 // move along to the next cell
230 var newColumn = this.columnController.getDisplayedColAfter(gridCell.column);
231 // check if end of the row, and if so, go forward a row
232 if (!newColumn) {
233 newColumn = displayedColumns[0];
234 var rowBelow = this.getRowBelow(gridCell.getGridRow());
235 if (utils_1.Utils.missing(rowBelow)) {
236 return;
237 }
238 newRowIndex = rowBelow.rowIndex;
239 newFloating = rowBelow.floating;
240 }
241 var gridCellDef = { rowIndex: newRowIndex, column: newColumn, floating: newFloating };
242 return new gridCell_1.GridCell(gridCellDef);
243 };
244 CellNavigationService.prototype.getNextTabbedCellBackwards = function (gridCell) {
245 var displayedColumns = this.columnController.getAllDisplayedColumns();
246 var newRowIndex = gridCell.rowIndex;
247 var newFloating = gridCell.floating;
248 // move along to the next cell
249 var newColumn = this.columnController.getDisplayedColBefore(gridCell.column);
250 // check if end of the row, and if so, go forward a row
251 if (!newColumn) {
252 newColumn = displayedColumns[displayedColumns.length - 1];
253 var rowAbove = this.getRowAbove(gridCell.getGridRow());
254 if (utils_1.Utils.missing(rowAbove)) {
255 return;
256 }
257 newRowIndex = rowAbove.rowIndex;
258 newFloating = rowAbove.floating;
259 }
260 var gridCellDef = { rowIndex: newRowIndex, column: newColumn, floating: newFloating };
261 return new gridCell_1.GridCell(gridCellDef);
262 };
263 __decorate([
264 context_1.Autowired('columnController'),
265 __metadata("design:type", columnController_1.ColumnController)
266 ], CellNavigationService.prototype, "columnController", void 0);
267 __decorate([
268 context_1.Autowired('rowModel'),
269 __metadata("design:type", Object)
270 ], CellNavigationService.prototype, "rowModel", void 0);
271 __decorate([
272 context_1.Autowired('pinnedRowModel'),
273 __metadata("design:type", pinnedRowModel_1.PinnedRowModel)
274 ], CellNavigationService.prototype, "pinnedRowModel", void 0);
275 __decorate([
276 context_1.Autowired('gridOptionsWrapper'),
277 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
278 ], CellNavigationService.prototype, "gridOptionsWrapper", void 0);
279 CellNavigationService = __decorate([
280 context_1.Bean('cellNavigationService')
281 ], CellNavigationService);
282 return CellNavigationService;
283}());
284exports.CellNavigationService = CellNavigationService;