13a579663ba74e3b82e38a9162508a706408fb79fffb78d1f50892297758e21b9bfa74e0509e07ade70cadd377fc3bbcdad406ef536999c7dd2f7469c31b77 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  2. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  3. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  4. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5. import { getStyle, getTrimmingContainer, hasClass, index, offset, removeClass, removeTextNodes, overlayContainsElement, closest } from './../../../helpers/dom/element';
  6. import { isFunction } from './../../../helpers/function';
  7. import CellCoords from './cell/coords';
  8. import CellRange from './cell/range';
  9. import ColumnFilter from './filter/column';
  10. import RowFilter from './filter/row';
  11. import TableRenderer from './tableRenderer';
  12. import Overlay from './overlay/_base';
  13. /**
  14. *
  15. */
  16. var Table = function () {
  17. /**
  18. * @param {Walkontable} wotInstance
  19. * @param {HTMLTableElement} table
  20. */
  21. function Table(wotInstance, table) {
  22. var _this = this;
  23. _classCallCheck(this, Table);
  24. this.wot = wotInstance;
  25. // legacy support
  26. this.instance = this.wot;
  27. this.TABLE = table;
  28. this.TBODY = null;
  29. this.THEAD = null;
  30. this.COLGROUP = null;
  31. this.tableOffset = 0;
  32. this.holderOffset = 0;
  33. removeTextNodes(this.TABLE);
  34. this.spreader = this.createSpreader(this.TABLE);
  35. this.hider = this.createHider(this.spreader);
  36. this.holder = this.createHolder(this.hider);
  37. this.wtRootElement = this.holder.parentNode;
  38. this.alignOverlaysWithTrimmingContainer();
  39. this.fixTableDomTree();
  40. this.colgroupChildrenLength = this.COLGROUP.childNodes.length;
  41. this.theadChildrenLength = this.THEAD.firstChild ? this.THEAD.firstChild.childNodes.length : 0;
  42. this.tbodyChildrenLength = this.TBODY.childNodes.length;
  43. this.rowFilter = null;
  44. this.columnFilter = null;
  45. this.correctHeaderWidth = false;
  46. var origRowHeaderWidth = this.wot.wtSettings.settings.rowHeaderWidth;
  47. // Fix for jumping row headers (https://github.com/handsontable/handsontable/issues/3850)
  48. this.wot.wtSettings.settings.rowHeaderWidth = function () {
  49. return _this._modifyRowHeaderWidth(origRowHeaderWidth);
  50. };
  51. }
  52. /**
  53. *
  54. */
  55. _createClass(Table, [{
  56. key: 'fixTableDomTree',
  57. value: function fixTableDomTree() {
  58. this.TBODY = this.TABLE.querySelector('tbody');
  59. if (!this.TBODY) {
  60. this.TBODY = document.createElement('tbody');
  61. this.TABLE.appendChild(this.TBODY);
  62. }
  63. this.THEAD = this.TABLE.querySelector('thead');
  64. if (!this.THEAD) {
  65. this.THEAD = document.createElement('thead');
  66. this.TABLE.insertBefore(this.THEAD, this.TBODY);
  67. }
  68. this.COLGROUP = this.TABLE.querySelector('colgroup');
  69. if (!this.COLGROUP) {
  70. this.COLGROUP = document.createElement('colgroup');
  71. this.TABLE.insertBefore(this.COLGROUP, this.THEAD);
  72. }
  73. if (this.wot.getSetting('columnHeaders').length && !this.THEAD.childNodes.length) {
  74. this.THEAD.appendChild(document.createElement('TR'));
  75. }
  76. }
  77. /**
  78. * @param table
  79. * @returns {HTMLElement}
  80. */
  81. }, {
  82. key: 'createSpreader',
  83. value: function createSpreader(table) {
  84. var parent = table.parentNode;
  85. var spreader = void 0;
  86. if (!parent || parent.nodeType !== 1 || !hasClass(parent, 'wtHolder')) {
  87. spreader = document.createElement('div');
  88. spreader.className = 'wtSpreader';
  89. if (parent) {
  90. // if TABLE is detached (e.g. in Jasmine test), it has no parentNode so we cannot attach holder to it
  91. parent.insertBefore(spreader, table);
  92. }
  93. spreader.appendChild(table);
  94. }
  95. spreader.style.position = 'relative';
  96. return spreader;
  97. }
  98. /**
  99. * @param spreader
  100. * @returns {HTMLElement}
  101. */
  102. }, {
  103. key: 'createHider',
  104. value: function createHider(spreader) {
  105. var parent = spreader.parentNode;
  106. var hider = void 0;
  107. if (!parent || parent.nodeType !== 1 || !hasClass(parent, 'wtHolder')) {
  108. hider = document.createElement('div');
  109. hider.className = 'wtHider';
  110. if (parent) {
  111. // if TABLE is detached (e.g. in Jasmine test), it has no parentNode so we cannot attach holder to it
  112. parent.insertBefore(hider, spreader);
  113. }
  114. hider.appendChild(spreader);
  115. }
  116. return hider;
  117. }
  118. /**
  119. *
  120. * @param hider
  121. * @returns {HTMLElement}
  122. */
  123. }, {
  124. key: 'createHolder',
  125. value: function createHolder(hider) {
  126. var parent = hider.parentNode;
  127. var holder = void 0;
  128. if (!parent || parent.nodeType !== 1 || !hasClass(parent, 'wtHolder')) {
  129. holder = document.createElement('div');
  130. holder.style.position = 'relative';
  131. holder.className = 'wtHolder';
  132. if (parent) {
  133. // if TABLE is detached (e.g. in Jasmine test), it has no parentNode so we cannot attach holder to it
  134. parent.insertBefore(holder, hider);
  135. }
  136. if (!this.isWorkingOnClone()) {
  137. holder.parentNode.className += 'ht_master handsontable';
  138. }
  139. holder.appendChild(hider);
  140. }
  141. return holder;
  142. }
  143. }, {
  144. key: 'alignOverlaysWithTrimmingContainer',
  145. value: function alignOverlaysWithTrimmingContainer() {
  146. var trimmingElement = getTrimmingContainer(this.wtRootElement);
  147. if (!this.isWorkingOnClone()) {
  148. this.holder.parentNode.style.position = 'relative';
  149. if (trimmingElement === window) {
  150. var preventOverflow = this.wot.getSetting('preventOverflow');
  151. if (!preventOverflow) {
  152. this.holder.style.overflow = 'visible';
  153. this.wtRootElement.style.overflow = 'visible';
  154. }
  155. } else {
  156. this.holder.style.width = getStyle(trimmingElement, 'width');
  157. this.holder.style.height = getStyle(trimmingElement, 'height');
  158. this.holder.style.overflow = '';
  159. }
  160. }
  161. }
  162. }, {
  163. key: 'isWorkingOnClone',
  164. value: function isWorkingOnClone() {
  165. return !!this.wot.cloneSource;
  166. }
  167. /**
  168. * Redraws the table
  169. *
  170. * @param {Boolean} fastDraw If TRUE, will try to avoid full redraw and only update the border positions. If FALSE or UNDEFINED, will perform a full redraw
  171. * @returns {Table}
  172. */
  173. }, {
  174. key: 'draw',
  175. value: function draw(fastDraw) {
  176. var _wot = this.wot,
  177. wtOverlays = _wot.wtOverlays,
  178. wtViewport = _wot.wtViewport;
  179. var totalRows = this.instance.getSetting('totalRows');
  180. var rowHeaders = this.wot.getSetting('rowHeaders').length;
  181. var columnHeaders = this.wot.getSetting('columnHeaders').length;
  182. var syncScroll = false;
  183. if (!this.isWorkingOnClone()) {
  184. this.holderOffset = offset(this.holder);
  185. fastDraw = wtViewport.createRenderCalculators(fastDraw);
  186. if (rowHeaders && !this.wot.getSetting('fixedColumnsLeft')) {
  187. var leftScrollPos = wtOverlays.leftOverlay.getScrollPosition();
  188. var previousState = this.correctHeaderWidth;
  189. this.correctHeaderWidth = leftScrollPos > 0;
  190. if (previousState !== this.correctHeaderWidth) {
  191. fastDraw = false;
  192. }
  193. }
  194. }
  195. if (!this.isWorkingOnClone()) {
  196. syncScroll = wtOverlays.prepareOverlays();
  197. }
  198. if (fastDraw) {
  199. if (!this.isWorkingOnClone()) {
  200. // in case we only scrolled without redraw, update visible rows information in oldRowsCalculator
  201. wtViewport.createVisibleCalculators();
  202. }
  203. if (wtOverlays) {
  204. wtOverlays.refresh(true);
  205. }
  206. } else {
  207. if (this.isWorkingOnClone()) {
  208. this.tableOffset = this.wot.cloneSource.wtTable.tableOffset;
  209. } else {
  210. this.tableOffset = offset(this.TABLE);
  211. }
  212. var startRow = void 0;
  213. if (Overlay.isOverlayTypeOf(this.wot.cloneOverlay, Overlay.CLONE_DEBUG) || Overlay.isOverlayTypeOf(this.wot.cloneOverlay, Overlay.CLONE_TOP) || Overlay.isOverlayTypeOf(this.wot.cloneOverlay, Overlay.CLONE_TOP_LEFT_CORNER)) {
  214. startRow = 0;
  215. } else if (Overlay.isOverlayTypeOf(this.instance.cloneOverlay, Overlay.CLONE_BOTTOM) || Overlay.isOverlayTypeOf(this.instance.cloneOverlay, Overlay.CLONE_BOTTOM_LEFT_CORNER)) {
  216. startRow = Math.max(totalRows - this.wot.getSetting('fixedRowsBottom'), 0);
  217. } else {
  218. startRow = wtViewport.rowsRenderCalculator.startRow;
  219. }
  220. var startColumn = void 0;
  221. if (Overlay.isOverlayTypeOf(this.wot.cloneOverlay, Overlay.CLONE_DEBUG) || Overlay.isOverlayTypeOf(this.wot.cloneOverlay, Overlay.CLONE_LEFT) || Overlay.isOverlayTypeOf(this.wot.cloneOverlay, Overlay.CLONE_TOP_LEFT_CORNER) || Overlay.isOverlayTypeOf(this.wot.cloneOverlay, Overlay.CLONE_BOTTOM_LEFT_CORNER)) {
  222. startColumn = 0;
  223. } else {
  224. startColumn = wtViewport.columnsRenderCalculator.startColumn;
  225. }
  226. this.rowFilter = new RowFilter(startRow, totalRows, columnHeaders);
  227. this.columnFilter = new ColumnFilter(startColumn, this.wot.getSetting('totalColumns'), rowHeaders);
  228. this.alignOverlaysWithTrimmingContainer();
  229. this._doDraw(); // creates calculator after draw
  230. }
  231. this.refreshSelections(fastDraw);
  232. if (!this.isWorkingOnClone()) {
  233. wtOverlays.topOverlay.resetFixedPosition();
  234. if (wtOverlays.bottomOverlay.clone) {
  235. wtOverlays.bottomOverlay.resetFixedPosition();
  236. }
  237. wtOverlays.leftOverlay.resetFixedPosition();
  238. if (wtOverlays.topLeftCornerOverlay) {
  239. wtOverlays.topLeftCornerOverlay.resetFixedPosition();
  240. }
  241. if (wtOverlays.bottomLeftCornerOverlay && wtOverlays.bottomLeftCornerOverlay.clone) {
  242. wtOverlays.bottomLeftCornerOverlay.resetFixedPosition();
  243. }
  244. }
  245. if (syncScroll) {
  246. wtOverlays.syncScrollWithMaster();
  247. }
  248. this.wot.drawn = true;
  249. return this;
  250. }
  251. }, {
  252. key: '_doDraw',
  253. value: function _doDraw() {
  254. var wtRenderer = new TableRenderer(this);
  255. wtRenderer.render();
  256. }
  257. }, {
  258. key: 'removeClassFromCells',
  259. value: function removeClassFromCells(className) {
  260. var nodes = this.TABLE.querySelectorAll('.' + className);
  261. for (var i = 0, len = nodes.length; i < len; i++) {
  262. removeClass(nodes[i], className);
  263. }
  264. }
  265. }, {
  266. key: 'refreshSelections',
  267. value: function refreshSelections(fastDraw) {
  268. if (!this.wot.selections) {
  269. return;
  270. }
  271. var len = this.wot.selections.length;
  272. if (fastDraw) {
  273. for (var i = 0; i < len; i++) {
  274. // there was no rerender, so we need to remove classNames by ourselves
  275. if (this.wot.selections[i].settings.className) {
  276. this.removeClassFromCells(this.wot.selections[i].settings.className);
  277. }
  278. if (this.wot.selections[i].settings.highlightHeaderClassName) {
  279. this.removeClassFromCells(this.wot.selections[i].settings.highlightHeaderClassName);
  280. }
  281. if (this.wot.selections[i].settings.highlightRowClassName) {
  282. this.removeClassFromCells(this.wot.selections[i].settings.highlightRowClassName);
  283. }
  284. if (this.wot.selections[i].settings.highlightColumnClassName) {
  285. this.removeClassFromCells(this.wot.selections[i].settings.highlightColumnClassName);
  286. }
  287. }
  288. }
  289. for (var _i = 0; _i < len; _i++) {
  290. this.wot.selections[_i].draw(this.wot, fastDraw);
  291. }
  292. }
  293. /**
  294. * Get cell element at coords.
  295. *
  296. * @param {CellCoords} coords
  297. * @returns {HTMLElement|Number} HTMLElement on success or Number one of the exit codes on error:
  298. * -1 row before viewport
  299. * -2 row after viewport
  300. */
  301. }, {
  302. key: 'getCell',
  303. value: function getCell(coords) {
  304. if (this.isRowBeforeRenderedRows(coords.row)) {
  305. // row before rendered rows
  306. return -1;
  307. } else if (this.isRowAfterRenderedRows(coords.row)) {
  308. // row after rendered rows
  309. return -2;
  310. }
  311. var TR = this.TBODY.childNodes[this.rowFilter.sourceToRendered(coords.row)];
  312. if (TR) {
  313. return TR.childNodes[this.columnFilter.sourceColumnToVisibleRowHeadedColumn(coords.col)];
  314. }
  315. }
  316. /**
  317. * getColumnHeader
  318. *
  319. * @param {Number} col Column index
  320. * @param {Number} [level=0] Header level (0 = most distant to the table)
  321. * @returns {Object} HTMLElement on success or undefined on error
  322. */
  323. }, {
  324. key: 'getColumnHeader',
  325. value: function getColumnHeader(col) {
  326. var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  327. var TR = this.THEAD.childNodes[level];
  328. if (TR) {
  329. return TR.childNodes[this.columnFilter.sourceColumnToVisibleRowHeadedColumn(col)];
  330. }
  331. }
  332. /**
  333. * getRowHeader
  334. *
  335. * @param {Number} row Row index
  336. * @returns {HTMLElement} HTMLElement on success or Number one of the exit codes on error: `null table doesn't have row headers`
  337. */
  338. }, {
  339. key: 'getRowHeader',
  340. value: function getRowHeader(row) {
  341. if (this.columnFilter.sourceColumnToVisibleRowHeadedColumn(0) === 0) {
  342. return null;
  343. }
  344. var TR = this.TBODY.childNodes[this.rowFilter.sourceToRendered(row)];
  345. if (TR) {
  346. return TR.childNodes[0];
  347. }
  348. }
  349. /**
  350. * Returns cell coords object for a given TD (or a child element of a TD element).
  351. *
  352. * @param {HTMLTableCellElement} TD A cell DOM element (or a child of one).
  353. * @returns {CellCoords|null} The coordinates of the provided TD element (or the closest TD element) or null, if the provided element is not applicable.
  354. */
  355. }, {
  356. key: 'getCoords',
  357. value: function getCoords(TD) {
  358. if (TD.nodeName !== 'TD' && TD.nodeName !== 'TH') {
  359. TD = closest(TD, ['TD', 'TH']);
  360. }
  361. if (TD === null) {
  362. return null;
  363. }
  364. var TR = TD.parentNode;
  365. var CONTAINER = TR.parentNode;
  366. var row = index(TR);
  367. var col = TD.cellIndex;
  368. if (overlayContainsElement(Overlay.CLONE_TOP_LEFT_CORNER, TD) || overlayContainsElement(Overlay.CLONE_TOP, TD)) {
  369. if (CONTAINER.nodeName === 'THEAD') {
  370. row -= CONTAINER.childNodes.length;
  371. }
  372. } else if (CONTAINER === this.THEAD) {
  373. row = this.rowFilter.visibleColHeadedRowToSourceRow(row);
  374. } else {
  375. row = this.rowFilter.renderedToSource(row);
  376. }
  377. if (overlayContainsElement(Overlay.CLONE_TOP_LEFT_CORNER, TD) || overlayContainsElement(Overlay.CLONE_LEFT, TD)) {
  378. col = this.columnFilter.offsettedTH(col);
  379. } else {
  380. col = this.columnFilter.visibleRowHeadedColumnToSourceColumn(col);
  381. }
  382. return new CellCoords(row, col);
  383. }
  384. }, {
  385. key: 'getTrForRow',
  386. value: function getTrForRow(row) {
  387. return this.TBODY.childNodes[this.rowFilter.sourceToRendered(row)];
  388. }
  389. }, {
  390. key: 'getFirstRenderedRow',
  391. value: function getFirstRenderedRow() {
  392. return this.wot.wtViewport.rowsRenderCalculator.startRow;
  393. }
  394. }, {
  395. key: 'getFirstVisibleRow',
  396. value: function getFirstVisibleRow() {
  397. return this.wot.wtViewport.rowsVisibleCalculator.startRow;
  398. }
  399. }, {
  400. key: 'getFirstRenderedColumn',
  401. value: function getFirstRenderedColumn() {
  402. return this.wot.wtViewport.columnsRenderCalculator.startColumn;
  403. }
  404. /**
  405. * @returns {Number} Returns -1 if no row is visible
  406. */
  407. }, {
  408. key: 'getFirstVisibleColumn',
  409. value: function getFirstVisibleColumn() {
  410. return this.wot.wtViewport.columnsVisibleCalculator.startColumn;
  411. }
  412. /**
  413. * @returns {Number} Returns -1 if no row is visible
  414. */
  415. }, {
  416. key: 'getLastRenderedRow',
  417. value: function getLastRenderedRow() {
  418. return this.wot.wtViewport.rowsRenderCalculator.endRow;
  419. }
  420. }, {
  421. key: 'getLastVisibleRow',
  422. value: function getLastVisibleRow() {
  423. return this.wot.wtViewport.rowsVisibleCalculator.endRow;
  424. }
  425. }, {
  426. key: 'getLastRenderedColumn',
  427. value: function getLastRenderedColumn() {
  428. return this.wot.wtViewport.columnsRenderCalculator.endColumn;
  429. }
  430. /**
  431. * @returns {Number} Returns -1 if no column is visible
  432. */
  433. }, {
  434. key: 'getLastVisibleColumn',
  435. value: function getLastVisibleColumn() {
  436. return this.wot.wtViewport.columnsVisibleCalculator.endColumn;
  437. }
  438. }, {
  439. key: 'isRowBeforeRenderedRows',
  440. value: function isRowBeforeRenderedRows(row) {
  441. return this.rowFilter && this.rowFilter.sourceToRendered(row) < 0 && row >= 0;
  442. }
  443. }, {
  444. key: 'isRowAfterViewport',
  445. value: function isRowAfterViewport(row) {
  446. return this.rowFilter && this.rowFilter.sourceToRendered(row) > this.getLastVisibleRow();
  447. }
  448. }, {
  449. key: 'isRowAfterRenderedRows',
  450. value: function isRowAfterRenderedRows(row) {
  451. return this.rowFilter && this.rowFilter.sourceToRendered(row) > this.getLastRenderedRow();
  452. }
  453. }, {
  454. key: 'isColumnBeforeViewport',
  455. value: function isColumnBeforeViewport(column) {
  456. return this.columnFilter && this.columnFilter.sourceToRendered(column) < 0 && column >= 0;
  457. }
  458. }, {
  459. key: 'isColumnAfterViewport',
  460. value: function isColumnAfterViewport(column) {
  461. return this.columnFilter && this.columnFilter.sourceToRendered(column) > this.getLastVisibleColumn();
  462. }
  463. }, {
  464. key: 'isLastRowFullyVisible',
  465. value: function isLastRowFullyVisible() {
  466. return this.getLastVisibleRow() === this.getLastRenderedRow();
  467. }
  468. }, {
  469. key: 'isLastColumnFullyVisible',
  470. value: function isLastColumnFullyVisible() {
  471. return this.getLastVisibleColumn() === this.getLastRenderedColumn();
  472. }
  473. }, {
  474. key: 'getRenderedColumnsCount',
  475. value: function getRenderedColumnsCount() {
  476. var columnsCount = this.wot.wtViewport.columnsRenderCalculator.count;
  477. var totalColumns = this.wot.getSetting('totalColumns');
  478. if (this.wot.isOverlayName(Overlay.CLONE_DEBUG)) {
  479. columnsCount = totalColumns;
  480. } else if (this.wot.isOverlayName(Overlay.CLONE_LEFT) || this.wot.isOverlayName(Overlay.CLONE_TOP_LEFT_CORNER) || this.wot.isOverlayName(Overlay.CLONE_BOTTOM_LEFT_CORNER)) {
  481. return Math.min(this.wot.getSetting('fixedColumnsLeft'), totalColumns);
  482. }
  483. return columnsCount;
  484. }
  485. }, {
  486. key: 'getRenderedRowsCount',
  487. value: function getRenderedRowsCount() {
  488. var rowsCount = this.wot.wtViewport.rowsRenderCalculator.count;
  489. var totalRows = this.wot.getSetting('totalRows');
  490. if (this.wot.isOverlayName(Overlay.CLONE_DEBUG)) {
  491. rowsCount = totalRows;
  492. } else if (this.wot.isOverlayName(Overlay.CLONE_TOP) || this.wot.isOverlayName(Overlay.CLONE_TOP_LEFT_CORNER)) {
  493. rowsCount = Math.min(this.wot.getSetting('fixedRowsTop'), totalRows);
  494. } else if (this.wot.isOverlayName(Overlay.CLONE_BOTTOM) || this.wot.isOverlayName(Overlay.CLONE_BOTTOM_LEFT_CORNER)) {
  495. rowsCount = Math.min(this.wot.getSetting('fixedRowsBottom'), totalRows);
  496. }
  497. return rowsCount;
  498. }
  499. }, {
  500. key: 'getVisibleRowsCount',
  501. value: function getVisibleRowsCount() {
  502. return this.wot.wtViewport.rowsVisibleCalculator.count;
  503. }
  504. }, {
  505. key: 'allRowsInViewport',
  506. value: function allRowsInViewport() {
  507. return this.wot.getSetting('totalRows') == this.getVisibleRowsCount();
  508. }
  509. /**
  510. * Checks if any of the row's cells content exceeds its initial height, and if so, returns the oversized height
  511. *
  512. * @param {Number} sourceRow
  513. * @returns {Number}
  514. */
  515. }, {
  516. key: 'getRowHeight',
  517. value: function getRowHeight(sourceRow) {
  518. var height = this.wot.wtSettings.settings.rowHeight(sourceRow);
  519. var oversizedHeight = this.wot.wtViewport.oversizedRows[sourceRow];
  520. if (oversizedHeight !== void 0) {
  521. height = height === void 0 ? oversizedHeight : Math.max(height, oversizedHeight);
  522. }
  523. return height;
  524. }
  525. }, {
  526. key: 'getColumnHeaderHeight',
  527. value: function getColumnHeaderHeight(level) {
  528. var height = this.wot.wtSettings.settings.defaultRowHeight;
  529. var oversizedHeight = this.wot.wtViewport.oversizedColumnHeaders[level];
  530. if (oversizedHeight !== void 0) {
  531. height = height ? Math.max(height, oversizedHeight) : oversizedHeight;
  532. }
  533. return height;
  534. }
  535. }, {
  536. key: 'getVisibleColumnsCount',
  537. value: function getVisibleColumnsCount() {
  538. return this.wot.wtViewport.columnsVisibleCalculator.count;
  539. }
  540. }, {
  541. key: 'allColumnsInViewport',
  542. value: function allColumnsInViewport() {
  543. return this.wot.getSetting('totalColumns') == this.getVisibleColumnsCount();
  544. }
  545. }, {
  546. key: 'getColumnWidth',
  547. value: function getColumnWidth(sourceColumn) {
  548. var width = this.wot.wtSettings.settings.columnWidth;
  549. if (typeof width === 'function') {
  550. width = width(sourceColumn);
  551. } else if ((typeof width === 'undefined' ? 'undefined' : _typeof(width)) === 'object') {
  552. width = width[sourceColumn];
  553. }
  554. return width || this.wot.wtSettings.settings.defaultColumnWidth;
  555. }
  556. }, {
  557. key: 'getStretchedColumnWidth',
  558. value: function getStretchedColumnWidth(sourceColumn) {
  559. var columnWidth = this.getColumnWidth(sourceColumn);
  560. var width = columnWidth == null ? this.instance.wtSettings.settings.defaultColumnWidth : columnWidth;
  561. var calculator = this.wot.wtViewport.columnsRenderCalculator;
  562. if (calculator) {
  563. var stretchedWidth = calculator.getStretchedColumnWidth(sourceColumn, width);
  564. if (stretchedWidth) {
  565. width = stretchedWidth;
  566. }
  567. }
  568. return width;
  569. }
  570. /**
  571. * Modify row header widths provided by user in class contructor.
  572. *
  573. * @private
  574. */
  575. }, {
  576. key: '_modifyRowHeaderWidth',
  577. value: function _modifyRowHeaderWidth(rowHeaderWidthFactory) {
  578. var widths = isFunction(rowHeaderWidthFactory) ? rowHeaderWidthFactory() : null;
  579. if (Array.isArray(widths)) {
  580. widths = [].concat(_toConsumableArray(widths));
  581. widths[widths.length - 1] = this._correctRowHeaderWidth(widths[widths.length - 1]);
  582. } else {
  583. widths = this._correctRowHeaderWidth(widths);
  584. }
  585. return widths;
  586. }
  587. /**
  588. * Correct row header width if necessary.
  589. *
  590. * @private
  591. */
  592. }, {
  593. key: '_correctRowHeaderWidth',
  594. value: function _correctRowHeaderWidth(width) {
  595. if (typeof width !== 'number') {
  596. width = this.wot.getSetting('defaultColumnWidth');
  597. }
  598. if (this.correctHeaderWidth) {
  599. width++;
  600. }
  601. return width;
  602. }
  603. }]);
  604. return Table;
  605. }();
  606. export default Table;