e49ccfafb1e26e0887d03ea02d19aead7bc97c4ea9245684329920debf278e9b94a4c27ed3d5aa67164701d0b3414e32ad1165cd035a83d11c0f3e1520de8f 24 KB

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