495eb8f5c384cd752339d36ed5f4106d632de7084842b03d7a8193b1c77b6a579ea13396a106e664e1c4b679dd0a9ea48ad3ebd125831fba14dd6c0fd22f7e 12 KB

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