7d551123240fd77919fd5a31162edc275f2d5fd0175ca50a4ee1ffd22c19340c37090772c4e2543aba9431c6aa143fafeb7005c6f95965bfd1954be4317745 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. 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; }; }();
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. import { addClass, getScrollbarWidth, getScrollLeft, getWindowScrollTop, hasClass, outerWidth, innerHeight, removeClass, setOverlayPosition, resetCssTransform } from './../../../../helpers/dom/element';
  6. import Overlay from './_base';
  7. /**
  8. * @class LeftOverlay
  9. */
  10. var LeftOverlay = function (_Overlay) {
  11. _inherits(LeftOverlay, _Overlay);
  12. /**
  13. * @param {Walkontable} wotInstance
  14. */
  15. function LeftOverlay(wotInstance) {
  16. _classCallCheck(this, LeftOverlay);
  17. var _this = _possibleConstructorReturn(this, (LeftOverlay.__proto__ || Object.getPrototypeOf(LeftOverlay)).call(this, wotInstance));
  18. _this.clone = _this.makeClone(Overlay.CLONE_LEFT);
  19. return _this;
  20. }
  21. /**
  22. * Checks if overlay should be fully rendered
  23. *
  24. * @returns {Boolean}
  25. */
  26. _createClass(LeftOverlay, [{
  27. key: 'shouldBeRendered',
  28. value: function shouldBeRendered() {
  29. return !!(this.wot.getSetting('fixedColumnsLeft') || this.wot.getSetting('rowHeaders').length);
  30. }
  31. /**
  32. * Updates the left overlay position
  33. */
  34. }, {
  35. key: 'resetFixedPosition',
  36. value: function resetFixedPosition() {
  37. if (!this.needFullRender || !this.wot.wtTable.holder.parentNode) {
  38. // removed from DOM
  39. return;
  40. }
  41. var overlayRoot = this.clone.wtTable.holder.parentNode;
  42. var headerPosition = 0;
  43. var preventOverflow = this.wot.getSetting('preventOverflow');
  44. if (this.trimmingContainer === window && (!preventOverflow || preventOverflow !== 'horizontal')) {
  45. var box = this.wot.wtTable.hider.getBoundingClientRect();
  46. var left = Math.ceil(box.left);
  47. var right = Math.ceil(box.right);
  48. var finalLeft = void 0;
  49. var finalTop = void 0;
  50. finalTop = this.wot.wtTable.hider.style.top;
  51. finalTop = finalTop === '' ? 0 : finalTop;
  52. if (left < 0 && right - overlayRoot.offsetWidth > 0) {
  53. finalLeft = -left;
  54. } else {
  55. finalLeft = 0;
  56. }
  57. headerPosition = finalLeft;
  58. finalLeft += 'px';
  59. setOverlayPosition(overlayRoot, finalLeft, finalTop);
  60. } else {
  61. headerPosition = this.getScrollPosition();
  62. resetCssTransform(overlayRoot);
  63. }
  64. this.adjustHeaderBordersPosition(headerPosition);
  65. this.adjustElementsSize();
  66. }
  67. /**
  68. * Sets the main overlay's horizontal scroll position
  69. *
  70. * @param {Number} pos
  71. */
  72. }, {
  73. key: 'setScrollPosition',
  74. value: function setScrollPosition(pos) {
  75. if (this.mainTableScrollableElement === window) {
  76. window.scrollTo(pos, getWindowScrollTop());
  77. } else {
  78. this.mainTableScrollableElement.scrollLeft = pos;
  79. }
  80. }
  81. /**
  82. * Triggers onScroll hook callback
  83. */
  84. }, {
  85. key: 'onScroll',
  86. value: function onScroll() {
  87. this.wot.getSetting('onScrollVertically');
  88. }
  89. /**
  90. * Calculates total sum cells width
  91. *
  92. * @param {Number} from Column index which calculates started from
  93. * @param {Number} to Column index where calculation is finished
  94. * @returns {Number} Width sum
  95. */
  96. }, {
  97. key: 'sumCellSizes',
  98. value: function sumCellSizes(from, to) {
  99. var sum = 0;
  100. var defaultColumnWidth = this.wot.wtSettings.defaultColumnWidth;
  101. while (from < to) {
  102. sum += this.wot.wtTable.getStretchedColumnWidth(from) || defaultColumnWidth;
  103. from++;
  104. }
  105. return sum;
  106. }
  107. /**
  108. * Adjust overlay root element, childs and master table element sizes (width, height).
  109. *
  110. * @param {Boolean} [force=false]
  111. */
  112. }, {
  113. key: 'adjustElementsSize',
  114. value: function adjustElementsSize() {
  115. var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  116. this.updateTrimmingContainer();
  117. if (this.needFullRender || force) {
  118. this.adjustRootElementSize();
  119. this.adjustRootChildrenSize();
  120. if (!force) {
  121. this.areElementSizesAdjusted = true;
  122. }
  123. }
  124. }
  125. /**
  126. * Adjust overlay root element size (width and height).
  127. */
  128. }, {
  129. key: 'adjustRootElementSize',
  130. value: function adjustRootElementSize() {
  131. var masterHolder = this.wot.wtTable.holder;
  132. var scrollbarHeight = masterHolder.clientHeight === masterHolder.offsetHeight ? 0 : getScrollbarWidth();
  133. var overlayRoot = this.clone.wtTable.holder.parentNode;
  134. var overlayRootStyle = overlayRoot.style;
  135. var preventOverflow = this.wot.getSetting('preventOverflow');
  136. var tableWidth = void 0;
  137. if (this.trimmingContainer !== window || preventOverflow === 'vertical') {
  138. var height = this.wot.wtViewport.getWorkspaceHeight() - scrollbarHeight;
  139. height = Math.min(height, innerHeight(this.wot.wtTable.wtRootElement));
  140. overlayRootStyle.height = height + 'px';
  141. } else {
  142. overlayRootStyle.height = '';
  143. }
  144. this.clone.wtTable.holder.style.height = overlayRootStyle.height;
  145. tableWidth = outerWidth(this.clone.wtTable.TABLE);
  146. overlayRootStyle.width = (tableWidth === 0 ? tableWidth : tableWidth + 4) + 'px';
  147. }
  148. /**
  149. * Adjust overlay root childs size
  150. */
  151. }, {
  152. key: 'adjustRootChildrenSize',
  153. value: function adjustRootChildrenSize() {
  154. var scrollbarWidth = getScrollbarWidth();
  155. this.clone.wtTable.hider.style.height = this.hider.style.height;
  156. this.clone.wtTable.holder.style.height = this.clone.wtTable.holder.parentNode.style.height;
  157. if (scrollbarWidth === 0) {
  158. scrollbarWidth = 30;
  159. }
  160. this.clone.wtTable.holder.style.width = parseInt(this.clone.wtTable.holder.parentNode.style.width, 10) + scrollbarWidth + 'px';
  161. }
  162. /**
  163. * Adjust the overlay dimensions and position
  164. */
  165. }, {
  166. key: 'applyToDOM',
  167. value: function applyToDOM() {
  168. var total = this.wot.getSetting('totalColumns');
  169. if (!this.areElementSizesAdjusted) {
  170. this.adjustElementsSize();
  171. }
  172. if (typeof this.wot.wtViewport.columnsRenderCalculator.startPosition === 'number') {
  173. this.spreader.style.left = this.wot.wtViewport.columnsRenderCalculator.startPosition + 'px';
  174. } else if (total === 0) {
  175. this.spreader.style.left = '0';
  176. } else {
  177. throw new Error('Incorrect value of the columnsRenderCalculator');
  178. }
  179. this.spreader.style.right = '';
  180. if (this.needFullRender) {
  181. this.syncOverlayOffset();
  182. }
  183. }
  184. /**
  185. * Synchronize calculated top position to an element
  186. */
  187. }, {
  188. key: 'syncOverlayOffset',
  189. value: function syncOverlayOffset() {
  190. if (typeof this.wot.wtViewport.rowsRenderCalculator.startPosition === 'number') {
  191. this.clone.wtTable.spreader.style.top = this.wot.wtViewport.rowsRenderCalculator.startPosition + 'px';
  192. } else {
  193. this.clone.wtTable.spreader.style.top = '';
  194. }
  195. }
  196. /**
  197. * Scrolls horizontally to a column at the left edge of the viewport
  198. *
  199. * @param sourceCol {Number} Column index which you want to scroll to
  200. * @param [beyondRendered=false] {Boolean} if `true`, scrolls according to the bottom edge (top edge is by default)
  201. */
  202. }, {
  203. key: 'scrollTo',
  204. value: function scrollTo(sourceCol, beyondRendered) {
  205. var newX = this.getTableParentOffset();
  206. var sourceInstance = this.wot.cloneSource ? this.wot.cloneSource : this.wot;
  207. var mainHolder = sourceInstance.wtTable.holder;
  208. var scrollbarCompensation = 0;
  209. if (beyondRendered && mainHolder.offsetWidth !== mainHolder.clientWidth) {
  210. scrollbarCompensation = getScrollbarWidth();
  211. }
  212. if (beyondRendered) {
  213. newX += this.sumCellSizes(0, sourceCol + 1);
  214. newX -= this.wot.wtViewport.getViewportWidth();
  215. } else {
  216. newX += this.sumCellSizes(this.wot.getSetting('fixedColumnsLeft'), sourceCol);
  217. }
  218. newX += scrollbarCompensation;
  219. this.setScrollPosition(newX);
  220. }
  221. /**
  222. * Gets table parent left position
  223. *
  224. * @returns {Number}
  225. */
  226. }, {
  227. key: 'getTableParentOffset',
  228. value: function getTableParentOffset() {
  229. var preventOverflow = this.wot.getSetting('preventOverflow');
  230. var offset = 0;
  231. if (!preventOverflow && this.trimmingContainer === window) {
  232. offset = this.wot.wtTable.holderOffset.left;
  233. }
  234. return offset;
  235. }
  236. /**
  237. * Gets the main overlay's horizontal scroll position
  238. *
  239. * @returns {Number} Main table's vertical scroll position
  240. */
  241. }, {
  242. key: 'getScrollPosition',
  243. value: function getScrollPosition() {
  244. return getScrollLeft(this.mainTableScrollableElement);
  245. }
  246. /**
  247. * Adds css classes to hide the header border's header (cell-selection border hiding issue)
  248. *
  249. * @param {Number} position Header X position if trimming container is window or scroll top if not
  250. */
  251. }, {
  252. key: 'adjustHeaderBordersPosition',
  253. value: function adjustHeaderBordersPosition(position) {
  254. var masterParent = this.wot.wtTable.holder.parentNode;
  255. var rowHeaders = this.wot.getSetting('rowHeaders');
  256. var fixedColumnsLeft = this.wot.getSetting('fixedColumnsLeft');
  257. var totalRows = this.wot.getSetting('totalRows');
  258. if (totalRows) {
  259. removeClass(masterParent, 'emptyRows');
  260. } else {
  261. addClass(masterParent, 'emptyRows');
  262. }
  263. if (fixedColumnsLeft && !rowHeaders.length) {
  264. addClass(masterParent, 'innerBorderLeft');
  265. } else if (!fixedColumnsLeft && rowHeaders.length) {
  266. var previousState = hasClass(masterParent, 'innerBorderLeft');
  267. if (position) {
  268. addClass(masterParent, 'innerBorderLeft');
  269. } else {
  270. removeClass(masterParent, 'innerBorderLeft');
  271. }
  272. if (!previousState && position || previousState && !position) {
  273. this.wot.wtOverlays.adjustElementsSize();
  274. }
  275. }
  276. }
  277. }]);
  278. return LeftOverlay;
  279. }(Overlay);
  280. Overlay.registerOverlay(Overlay.CLONE_LEFT, LeftOverlay);
  281. export default LeftOverlay;