tableView.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. import {
  2. addClass,
  3. empty,
  4. fastInnerHTML,
  5. fastInnerText,
  6. getScrollbarWidth,
  7. hasClass,
  8. isChildOf,
  9. isInput,
  10. isOutsideInput
  11. } from './helpers/dom/element';
  12. import EventManager from './eventManager';
  13. import { stopPropagation, isImmediatePropagationStopped, isRightClick, isLeftClick } from './helpers/dom/event';
  14. import Walkontable from './3rdparty/walkontable/src';
  15. import { handleMouseEvent } from './selection/mouseEventHandler';
  16. /**
  17. * Cross-platform helper to clear text selection.
  18. */
  19. const clearTextSelection = function() {
  20. // http://stackoverflow.com/questions/3169786/clear-text-selection-with-javascript
  21. if (window.getSelection) {
  22. if (window.getSelection().empty) { // Chrome
  23. window.getSelection().empty();
  24. } else if (window.getSelection().removeAllRanges) { // Firefox
  25. window.getSelection().removeAllRanges();
  26. }
  27. } else if (document.selection) { // IE?
  28. document.selection.empty();
  29. }
  30. };
  31. /**
  32. * Handsontable TableView constructor
  33. * @param {Object} instance
  34. */
  35. function TableView(instance) {
  36. const that = this;
  37. this.eventManager = new EventManager(instance);
  38. this.instance = instance;
  39. this.settings = instance.getSettings();
  40. this.selectionMouseDown = false;
  41. const originalStyle = instance.rootElement.getAttribute('style');
  42. if (originalStyle) {
  43. instance.rootElement.setAttribute('data-originalstyle', originalStyle); // needed to retrieve original style in jsFiddle link generator in HT examples. may be removed in future versions
  44. }
  45. addClass(instance.rootElement, 'handsontable');
  46. const table = document.createElement('TABLE');
  47. addClass(table, 'htCore');
  48. if (instance.getSettings().tableClassName) {
  49. addClass(table, instance.getSettings().tableClassName);
  50. }
  51. this.THEAD = document.createElement('THEAD');
  52. table.appendChild(this.THEAD);
  53. this.TBODY = document.createElement('TBODY');
  54. table.appendChild(this.TBODY);
  55. instance.table = table;
  56. instance.container.insertBefore(table, instance.container.firstChild);
  57. this.eventManager.addEventListener(instance.rootElement, 'mousedown', (event) => {
  58. this.selectionMouseDown = true;
  59. if (!that.isTextSelectionAllowed(event.target)) {
  60. clearTextSelection();
  61. event.preventDefault();
  62. window.focus(); // make sure that window that contains HOT is active. Important when HOT is in iframe.
  63. }
  64. });
  65. this.eventManager.addEventListener(instance.rootElement, 'mouseup', () => {
  66. this.selectionMouseDown = false;
  67. });
  68. this.eventManager.addEventListener(instance.rootElement, 'mousemove', (event) => {
  69. if (this.selectionMouseDown && !that.isTextSelectionAllowed(event.target)) {
  70. // Clear selection only when fragmentSelection is enabled, otherwise clearing selection breakes the IME editor.
  71. if (this.settings.fragmentSelection) {
  72. clearTextSelection();
  73. }
  74. event.preventDefault();
  75. }
  76. });
  77. this.eventManager.addEventListener(document.documentElement, 'keyup', (event) => {
  78. if (instance.selection.isInProgress() && !event.shiftKey) {
  79. instance.selection.finish();
  80. }
  81. });
  82. let isMouseDown;
  83. this.isMouseDown = function() {
  84. return isMouseDown;
  85. };
  86. this.eventManager.addEventListener(document.documentElement, 'mouseup', (event) => {
  87. if (instance.selection.isInProgress() && isLeftClick(event)) { // is left mouse button
  88. instance.selection.finish();
  89. }
  90. isMouseDown = false;
  91. if (isOutsideInput(document.activeElement) || (!instance.selection.isSelected() && !isRightClick(event))) {
  92. instance.unlisten();
  93. }
  94. });
  95. this.eventManager.addEventListener(document.documentElement, 'contextmenu', (event) => {
  96. if (instance.selection.isInProgress() && isRightClick(event)) {
  97. instance.selection.finish();
  98. isMouseDown = false;
  99. }
  100. });
  101. this.eventManager.addEventListener(document.documentElement, 'touchend', () => {
  102. if (instance.selection.isInProgress()) {
  103. instance.selection.finish();
  104. }
  105. isMouseDown = false;
  106. });
  107. this.eventManager.addEventListener(document.documentElement, 'mousedown', (event) => {
  108. const originalTarget = event.target;
  109. const eventX = event.x || event.clientX;
  110. const eventY = event.y || event.clientY;
  111. let next = event.target;
  112. if (isMouseDown || !instance.rootElement) {
  113. return; // it must have been started in a cell
  114. }
  115. // immediate click on "holder" means click on the right side of vertical scrollbar
  116. if (next === instance.view.wt.wtTable.holder) {
  117. const scrollbarWidth = getScrollbarWidth();
  118. if (document.elementFromPoint(eventX + scrollbarWidth, eventY) !== instance.view.wt.wtTable.holder ||
  119. document.elementFromPoint(eventX, eventY + scrollbarWidth) !== instance.view.wt.wtTable.holder) {
  120. return;
  121. }
  122. } else {
  123. while (next !== document.documentElement) {
  124. if (next === null) {
  125. if (event.isTargetWebComponent) {
  126. break;
  127. }
  128. // click on something that was a row but now is detached (possibly because your click triggered a rerender)
  129. return;
  130. }
  131. if (next === instance.rootElement) {
  132. // click inside container
  133. return;
  134. }
  135. next = next.parentNode;
  136. }
  137. }
  138. // function did not return until here, we have an outside click!
  139. const outsideClickDeselects = typeof that.settings.outsideClickDeselects === 'function' ?
  140. that.settings.outsideClickDeselects(originalTarget) :
  141. that.settings.outsideClickDeselects;
  142. if (outsideClickDeselects) {
  143. instance.deselectCell();
  144. } else {
  145. instance.destroyEditor(false, false);
  146. }
  147. });
  148. this.eventManager.addEventListener(table, 'selectstart', (event) => {
  149. if (that.settings.fragmentSelection || isInput(event.target)) {
  150. return;
  151. }
  152. // https://github.com/handsontable/handsontable/issues/160
  153. // Prevent text from being selected when performing drag down.
  154. event.preventDefault();
  155. });
  156. const walkontableConfig = {
  157. debug: () => that.settings.debug,
  158. externalRowCalculator: this.instance.getPlugin('autoRowSize') && this.instance.getPlugin('autoRowSize').isEnabled(),
  159. table,
  160. preventOverflow: () => this.settings.preventOverflow,
  161. stretchH: () => that.settings.stretchH,
  162. data: instance.getDataAtCell,
  163. totalRows: () => instance.countRows(),
  164. totalColumns: () => instance.countCols(),
  165. fixedColumnsLeft: () => that.settings.fixedColumnsLeft,
  166. fixedRowsTop: () => that.settings.fixedRowsTop,
  167. fixedRowsBottom: () => that.settings.fixedRowsBottom,
  168. minSpareRows: () => that.settings.minSpareRows,
  169. renderAllRows: that.settings.renderAllRows,
  170. rowHeaders: () => {
  171. const headerRenderers = [];
  172. if (instance.hasRowHeaders()) {
  173. headerRenderers.push((row, TH) => that.appendRowHeader(row, TH));
  174. }
  175. instance.runHooks('afterGetRowHeaderRenderers', headerRenderers);
  176. return headerRenderers;
  177. },
  178. columnHeaders: () => {
  179. const headerRenderers = [];
  180. if (instance.hasColHeaders()) {
  181. headerRenderers.push((column, TH) => {
  182. that.appendColHeader(column, TH);
  183. });
  184. }
  185. instance.runHooks('afterGetColumnHeaderRenderers', headerRenderers);
  186. return headerRenderers;
  187. },
  188. columnWidth: instance.getColWidth,
  189. rowHeight: instance.getRowHeight,
  190. cellRenderer(row, col, TD) {
  191. const cellProperties = that.instance.getCellMeta(row, col);
  192. const prop = that.instance.colToProp(col);
  193. let value = that.instance.getDataAtRowProp(row, prop);
  194. if (that.instance.hasHook('beforeValueRender')) {
  195. value = that.instance.runHooks('beforeValueRender', value, cellProperties);
  196. }
  197. that.instance.runHooks('beforeRenderer', TD, row, col, prop, value, cellProperties);
  198. that.instance.getCellRenderer(cellProperties)(that.instance, TD, row, col, prop, value, cellProperties);
  199. that.instance.runHooks('afterRenderer', TD, row, col, prop, value, cellProperties);
  200. },
  201. selections: that.instance.selection.highlight,
  202. hideBorderOnMouseDownOver: () => that.settings.fragmentSelection,
  203. onCellMouseDown: (event, coords, TD, wt) => {
  204. const blockCalculations = {
  205. row: false,
  206. column: false,
  207. cell: false
  208. };
  209. instance.listen();
  210. that.activeWt = wt;
  211. isMouseDown = true;
  212. instance.runHooks('beforeOnCellMouseDown', event, coords, TD, blockCalculations);
  213. if (isImmediatePropagationStopped(event)) {
  214. return;
  215. }
  216. handleMouseEvent(event, {
  217. coords,
  218. selection: instance.selection,
  219. controller: blockCalculations,
  220. });
  221. instance.runHooks('afterOnCellMouseDown', event, coords, TD);
  222. that.activeWt = that.wt;
  223. },
  224. onCellContextMenu: (event, coords, TD, wt) => {
  225. that.activeWt = wt;
  226. isMouseDown = false;
  227. if (instance.selection.isInProgress()) {
  228. instance.selection.finish();
  229. }
  230. instance.runHooks('beforeOnCellContextMenu', event, coords, TD);
  231. if (isImmediatePropagationStopped(event)) {
  232. return;
  233. }
  234. instance.runHooks('afterOnCellContextMenu', event, coords, TD);
  235. that.activeWt = that.wt;
  236. },
  237. onCellMouseOut: (event, coords, TD, wt) => {
  238. that.activeWt = wt;
  239. instance.runHooks('beforeOnCellMouseOut', event, coords, TD);
  240. if (isImmediatePropagationStopped(event)) {
  241. return;
  242. }
  243. instance.runHooks('afterOnCellMouseOut', event, coords, TD);
  244. that.activeWt = that.wt;
  245. },
  246. onCellMouseOver: (event, coords, TD, wt) => {
  247. const blockCalculations = {
  248. row: false,
  249. column: false,
  250. cell: false
  251. };
  252. that.activeWt = wt;
  253. instance.runHooks('beforeOnCellMouseOver', event, coords, TD, blockCalculations);
  254. if (isImmediatePropagationStopped(event)) {
  255. return;
  256. }
  257. if (isMouseDown) {
  258. handleMouseEvent(event, {
  259. coords,
  260. selection: instance.selection,
  261. controller: blockCalculations,
  262. });
  263. }
  264. instance.runHooks('afterOnCellMouseOver', event, coords, TD);
  265. that.activeWt = that.wt;
  266. },
  267. onCellMouseUp: (event, coords, TD, wt) => {
  268. that.activeWt = wt;
  269. instance.runHooks('beforeOnCellMouseUp', event, coords, TD);
  270. instance.runHooks('afterOnCellMouseUp', event, coords, TD);
  271. that.activeWt = that.wt;
  272. },
  273. onCellCornerMouseDown(event) {
  274. event.preventDefault();
  275. instance.runHooks('afterOnCellCornerMouseDown', event);
  276. },
  277. onCellCornerDblClick(event) {
  278. event.preventDefault();
  279. instance.runHooks('afterOnCellCornerDblClick', event);
  280. },
  281. beforeDraw(force, skipRender) {
  282. that.beforeRender(force, skipRender);
  283. },
  284. onDraw(force) {
  285. that.onDraw(force);
  286. },
  287. onScrollVertically() {
  288. instance.runHooks('afterScrollVertically');
  289. },
  290. onScrollHorizontally() {
  291. instance.runHooks('afterScrollHorizontally');
  292. },
  293. onBeforeRemoveCellClassNames: () => instance.runHooks('beforeRemoveCellClassNames'),
  294. onAfterDrawSelection: (currentRow, currentColumn, cornersOfSelection, layerLevel) => instance.runHooks('afterDrawSelection',
  295. currentRow, currentColumn, cornersOfSelection, layerLevel),
  296. onBeforeDrawBorders(corners, borderClassName) {
  297. instance.runHooks('beforeDrawBorders', corners, borderClassName);
  298. },
  299. onBeforeTouchScroll() {
  300. instance.runHooks('beforeTouchScroll');
  301. },
  302. onAfterMomentumScroll() {
  303. instance.runHooks('afterMomentumScroll');
  304. },
  305. onBeforeStretchingColumnWidth: (stretchedWidth, column) => instance.runHooks('beforeStretchingColumnWidth', stretchedWidth, column),
  306. onModifyRowHeaderWidth: rowHeaderWidth => instance.runHooks('modifyRowHeaderWidth', rowHeaderWidth),
  307. onModifyGetCellCoords: (row, column, topmost) => instance.runHooks('modifyGetCellCoords', row, column, topmost),
  308. viewportRowCalculatorOverride(calc) {
  309. const rows = instance.countRows();
  310. let viewportOffset = that.settings.viewportRowRenderingOffset;
  311. if (viewportOffset === 'auto' && that.settings.fixedRowsTop) {
  312. viewportOffset = 10;
  313. }
  314. if (typeof viewportOffset === 'number') {
  315. calc.startRow = Math.max(calc.startRow - viewportOffset, 0);
  316. calc.endRow = Math.min(calc.endRow + viewportOffset, rows - 1);
  317. }
  318. if (viewportOffset === 'auto') {
  319. const center = calc.startRow + calc.endRow - calc.startRow;
  320. const offset = Math.ceil(center / rows * 12);
  321. calc.startRow = Math.max(calc.startRow - offset, 0);
  322. calc.endRow = Math.min(calc.endRow + offset, rows - 1);
  323. }
  324. instance.runHooks('afterViewportRowCalculatorOverride', calc);
  325. },
  326. viewportColumnCalculatorOverride(calc) {
  327. const cols = instance.countCols();
  328. let viewportOffset = that.settings.viewportColumnRenderingOffset;
  329. if (viewportOffset === 'auto' && that.settings.fixedColumnsLeft) {
  330. viewportOffset = 10;
  331. }
  332. if (typeof viewportOffset === 'number') {
  333. calc.startColumn = Math.max(calc.startColumn - viewportOffset, 0);
  334. calc.endColumn = Math.min(calc.endColumn + viewportOffset, cols - 1);
  335. }
  336. if (viewportOffset === 'auto') {
  337. const center = calc.startColumn + calc.endColumn - calc.startColumn;
  338. const offset = Math.ceil(center / cols * 12);
  339. calc.startRow = Math.max(calc.startColumn - offset, 0);
  340. calc.endColumn = Math.min(calc.endColumn + offset, cols - 1);
  341. }
  342. instance.runHooks('afterViewportColumnCalculatorOverride', calc);
  343. },
  344. rowHeaderWidth: () => that.settings.rowHeaderWidth,
  345. columnHeaderHeight() {
  346. const columnHeaderHeight = instance.runHooks('modifyColumnHeaderHeight');
  347. return that.settings.columnHeaderHeight || columnHeaderHeight;
  348. }
  349. };
  350. instance.runHooks('beforeInitWalkontable', walkontableConfig);
  351. this.wt = new Walkontable(walkontableConfig);
  352. this.activeWt = this.wt;
  353. this.eventManager.addEventListener(that.wt.wtTable.spreader, 'mousedown', (event) => {
  354. // right mouse button exactly on spreader means right click on the right hand side of vertical scrollbar
  355. if (event.target === that.wt.wtTable.spreader && event.which === 3) {
  356. stopPropagation(event);
  357. }
  358. });
  359. this.eventManager.addEventListener(that.wt.wtTable.spreader, 'contextmenu', (event) => {
  360. // right mouse button exactly on spreader means right click on the right hand side of vertical scrollbar
  361. if (event.target === that.wt.wtTable.spreader && event.which === 3) {
  362. stopPropagation(event);
  363. }
  364. });
  365. this.eventManager.addEventListener(document.documentElement, 'click', () => {
  366. if (that.settings.observeDOMVisibility) {
  367. if (that.wt.drawInterrupted) {
  368. that.instance.forceFullRender = true;
  369. that.render();
  370. }
  371. }
  372. });
  373. }
  374. TableView.prototype.isTextSelectionAllowed = function(el) {
  375. if (isInput(el)) {
  376. return true;
  377. }
  378. const isChildOfTableBody = isChildOf(el, this.instance.view.wt.wtTable.spreader);
  379. if (this.settings.fragmentSelection === true && isChildOfTableBody) {
  380. return true;
  381. }
  382. if (this.settings.fragmentSelection === 'cell' && this.isSelectedOnlyCell() && isChildOfTableBody) {
  383. return true;
  384. }
  385. if (!this.settings.fragmentSelection && this.isCellEdited() && this.isSelectedOnlyCell()) {
  386. return true;
  387. }
  388. return false;
  389. };
  390. /**
  391. * Check if selected only one cell.
  392. *
  393. * @returns {Boolean}
  394. */
  395. TableView.prototype.isSelectedOnlyCell = function() {
  396. const [row, col, rowEnd, colEnd] = this.instance.getSelectedLast() || [];
  397. return row !== void 0 && row === rowEnd && col === colEnd;
  398. };
  399. TableView.prototype.isCellEdited = function() {
  400. const activeEditor = this.instance.getActiveEditor();
  401. return activeEditor && activeEditor.isOpened();
  402. };
  403. TableView.prototype.beforeRender = function(force, skipRender) {
  404. if (force) {
  405. // this.instance.forceFullRender = did Handsontable request full render?
  406. this.instance.runHooks('beforeRender', this.instance.forceFullRender, skipRender);
  407. }
  408. };
  409. TableView.prototype.onDraw = function(force) {
  410. if (force) {
  411. // this.instance.forceFullRender = did Handsontable request full render?
  412. this.instance.runHooks('afterRender', this.instance.forceFullRender);
  413. }
  414. };
  415. TableView.prototype.render = function() {
  416. this.wt.draw(!this.instance.forceFullRender);
  417. this.instance.forceFullRender = false;
  418. this.instance.renderCall = false;
  419. };
  420. /**
  421. * Returns td object given coordinates
  422. *
  423. * @param {CellCoords} coords
  424. * @param {Boolean} topmost
  425. */
  426. TableView.prototype.getCellAtCoords = function(coords, topmost) {
  427. const td = this.wt.getCell(coords, topmost);
  428. if (td < 0) { // there was an exit code (cell is out of bounds)
  429. return null;
  430. }
  431. return td;
  432. };
  433. /**
  434. * Scroll viewport to a cell.
  435. *
  436. * @param {CellCoords} coords
  437. * @param {Boolean} [snapToTop]
  438. * @param {Boolean} [snapToRight]
  439. * @param {Boolean} [snapToBottom]
  440. * @param {Boolean} [snapToLeft]
  441. * @returns {Boolean}
  442. */
  443. TableView.prototype.scrollViewport = function(coords, snapToTop, snapToRight, snapToBottom, snapToLeft) {
  444. return this.wt.scrollViewport(coords, snapToTop, snapToRight, snapToBottom, snapToLeft);
  445. };
  446. /**
  447. * Scroll viewport to a column.
  448. *
  449. * @param {Number} column Visual column index.
  450. * @param {Boolean} [snapToLeft]
  451. * @param {Boolean} [snapToRight]
  452. * @returns {Boolean}
  453. */
  454. TableView.prototype.scrollViewportHorizontally = function(column, snapToRight, snapToLeft) {
  455. return this.wt.scrollViewportHorizontally(column, snapToRight, snapToLeft);
  456. };
  457. /**
  458. * Scroll viewport to a row.
  459. *
  460. * @param {Number} row Visual row index.
  461. * @param {Boolean} [snapToTop]
  462. * @param {Boolean} [snapToBottom]
  463. * @returns {Boolean}
  464. */
  465. TableView.prototype.scrollViewportVertically = function(row, snapToTop, snapToBottom) {
  466. return this.wt.scrollViewportVertically(row, snapToTop, snapToBottom);
  467. };
  468. /**
  469. * Append row header to a TH element
  470. * @param row
  471. * @param TH
  472. */
  473. TableView.prototype.appendRowHeader = function(row, TH) {
  474. if (TH.firstChild) {
  475. const container = TH.firstChild;
  476. if (!hasClass(container, 'relative')) {
  477. empty(TH);
  478. this.appendRowHeader(row, TH);
  479. return;
  480. }
  481. this.updateCellHeader(container.querySelector('.rowHeader'), row, this.instance.getRowHeader);
  482. } else {
  483. const div = document.createElement('div');
  484. const span = document.createElement('span');
  485. div.className = 'relative';
  486. span.className = 'rowHeader';
  487. this.updateCellHeader(span, row, this.instance.getRowHeader);
  488. div.appendChild(span);
  489. TH.appendChild(div);
  490. }
  491. this.instance.runHooks('afterGetRowHeader', row, TH);
  492. };
  493. /**
  494. * Append column header to a TH element
  495. * @param col
  496. * @param TH
  497. */
  498. TableView.prototype.appendColHeader = function(col, TH) {
  499. if (TH.firstChild) {
  500. const container = TH.firstChild;
  501. if (hasClass(container, 'relative')) {
  502. this.updateCellHeader(container.querySelector('.colHeader'), col, this.instance.getColHeader);
  503. } else {
  504. empty(TH);
  505. this.appendColHeader(col, TH);
  506. }
  507. } else {
  508. const div = document.createElement('div');
  509. const span = document.createElement('span');
  510. div.className = 'relative';
  511. span.className = 'colHeader';
  512. this.updateCellHeader(span, col, this.instance.getColHeader);
  513. div.appendChild(span);
  514. TH.appendChild(div);
  515. }
  516. this.instance.runHooks('afterGetColHeader', col, TH);
  517. };
  518. /**
  519. * Update header cell content
  520. *
  521. * @since 0.15.0-beta4
  522. * @param {HTMLElement} element Element to update
  523. * @param {Number} index Row index or column index
  524. * @param {Function} content Function which should be returns content for this cell
  525. */
  526. TableView.prototype.updateCellHeader = function(element, index, content) {
  527. let renderedIndex = index;
  528. const parentOverlay = this.wt.wtOverlays.getParentOverlay(element) || this.wt;
  529. // prevent wrong calculations from SampleGenerator
  530. if (element.parentNode) {
  531. if (hasClass(element, 'colHeader')) {
  532. renderedIndex = parentOverlay.wtTable.columnFilter.sourceToRendered(index);
  533. } else if (hasClass(element, 'rowHeader')) {
  534. renderedIndex = parentOverlay.wtTable.rowFilter.sourceToRendered(index);
  535. }
  536. }
  537. if (renderedIndex > -1) {
  538. fastInnerHTML(element, content(index));
  539. } else {
  540. // workaround for https://github.com/handsontable/handsontable/issues/1946
  541. fastInnerText(element, String.fromCharCode(160));
  542. addClass(element, 'cornerHeader');
  543. }
  544. };
  545. /**
  546. * Given a element's left position relative to the viewport, returns maximum element width until the right
  547. * edge of the viewport (before scrollbar)
  548. *
  549. * @param {Number} leftOffset
  550. * @return {Number}
  551. */
  552. TableView.prototype.maximumVisibleElementWidth = function(leftOffset) {
  553. const workspaceWidth = this.wt.wtViewport.getWorkspaceWidth();
  554. const maxWidth = workspaceWidth - leftOffset;
  555. return maxWidth > 0 ? maxWidth : 0;
  556. };
  557. /**
  558. * Given a element's top position relative to the viewport, returns maximum element height until the bottom
  559. * edge of the viewport (before scrollbar)
  560. *
  561. * @param {Number} topOffset
  562. * @return {Number}
  563. */
  564. TableView.prototype.maximumVisibleElementHeight = function(topOffset) {
  565. const workspaceHeight = this.wt.wtViewport.getWorkspaceHeight();
  566. const maxHeight = workspaceHeight - topOffset;
  567. return maxHeight > 0 ? maxHeight : 0;
  568. };
  569. TableView.prototype.mainViewIsActive = function() {
  570. return this.wt === this.activeWt;
  571. };
  572. TableView.prototype.destroy = function() {
  573. this.wt.destroy();
  574. this.eventManager.destroy();
  575. };
  576. export default TableView;