handsontable 0.0.0-next-802f59c-20241024 → 0.0.0-next-adeb5a2-20241025

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of handsontable might be problematic. Click here for more details.

Files changed (63) hide show
  1. package/3rdparty/walkontable/src/overlay/inlineStart.js +1 -1
  2. package/3rdparty/walkontable/src/overlay/inlineStart.mjs +1 -1
  3. package/3rdparty/walkontable/src/overlays.js +6 -7
  4. package/3rdparty/walkontable/src/overlays.mjs +6 -7
  5. package/3rdparty/walkontable/src/renderer/colGroup.js +1 -1
  6. package/3rdparty/walkontable/src/renderer/colGroup.mjs +1 -1
  7. package/3rdparty/walkontable/src/renderer/table.js +1 -1
  8. package/3rdparty/walkontable/src/renderer/table.mjs +1 -1
  9. package/3rdparty/walkontable/src/settings.js +7 -0
  10. package/3rdparty/walkontable/src/settings.mjs +7 -0
  11. package/3rdparty/walkontable/src/table.js +24 -0
  12. package/3rdparty/walkontable/src/table.mjs +24 -0
  13. package/3rdparty/walkontable/src/utils/column.js +42 -0
  14. package/3rdparty/walkontable/src/utils/column.mjs +42 -0
  15. package/3rdparty/walkontable/src/utils/columnStretching.js +197 -0
  16. package/3rdparty/walkontable/src/utils/columnStretching.mjs +193 -0
  17. package/3rdparty/walkontable/src/viewport.js +87 -66
  18. package/3rdparty/walkontable/src/viewport.mjs +88 -67
  19. package/base.js +2 -2
  20. package/base.mjs +2 -2
  21. package/core/hooks/constants.js +0 -2
  22. package/core/hooks/constants.mjs +0 -2
  23. package/core/hooks/index.d.ts +2 -2
  24. package/core.d.ts +2 -2
  25. package/core.js +4 -6
  26. package/core.mjs +4 -6
  27. package/dist/handsontable.css +2 -2
  28. package/dist/handsontable.full.css +2 -2
  29. package/dist/handsontable.full.js +1821 -2217
  30. package/dist/handsontable.full.min.css +2 -2
  31. package/dist/handsontable.full.min.js +10 -10
  32. package/dist/handsontable.js +1823 -2219
  33. package/dist/handsontable.min.css +2 -2
  34. package/dist/handsontable.min.js +10 -10
  35. package/helpers/mixed.js +1 -1
  36. package/helpers/mixed.mjs +1 -1
  37. package/index.d.ts +0 -7
  38. package/package.json +1 -6
  39. package/plugins/comments/comments.js +1 -1
  40. package/plugins/comments/comments.mjs +1 -1
  41. package/plugins/index.d.ts +0 -3
  42. package/plugins/index.js +0 -3
  43. package/plugins/index.mjs +1 -3
  44. package/plugins/manualColumnMove/manualColumnMove.js +3 -1
  45. package/plugins/manualColumnMove/manualColumnMove.mjs +3 -1
  46. package/plugins/manualColumnResize/manualColumnResize.js +12 -24
  47. package/plugins/manualColumnResize/manualColumnResize.mjs +12 -24
  48. package/tableView.js +6 -39
  49. package/tableView.mjs +6 -39
  50. package/plugins/stretchColumns/calculator.js +0 -159
  51. package/plugins/stretchColumns/calculator.mjs +0 -155
  52. package/plugins/stretchColumns/index.d.ts +0 -1
  53. package/plugins/stretchColumns/index.js +0 -7
  54. package/plugins/stretchColumns/index.mjs +0 -1
  55. package/plugins/stretchColumns/strategies/_base.js +0 -85
  56. package/plugins/stretchColumns/strategies/_base.mjs +0 -81
  57. package/plugins/stretchColumns/strategies/all.js +0 -68
  58. package/plugins/stretchColumns/strategies/all.mjs +0 -64
  59. package/plugins/stretchColumns/strategies/last.js +0 -77
  60. package/plugins/stretchColumns/strategies/last.mjs +0 -73
  61. package/plugins/stretchColumns/stretchColumns.d.ts +0 -11
  62. package/plugins/stretchColumns/stretchColumns.js +0 -211
  63. package/plugins/stretchColumns/stretchColumns.mjs +0 -207
@@ -119,7 +119,7 @@ class InlineStartOverlay extends _base.Overlay {
119
119
  let column = from;
120
120
  let sum = 0;
121
121
  while (column < to) {
122
- sum += this.wot.wtTable.getColumnWidth(column) || defaultColumnWidth;
122
+ sum += this.wot.wtTable.getStretchedColumnWidth(column) || defaultColumnWidth;
123
123
  column += 1;
124
124
  }
125
125
  return sum;
@@ -115,7 +115,7 @@ export class InlineStartOverlay extends Overlay {
115
115
  let column = from;
116
116
  let sum = 0;
117
117
  while (column < to) {
118
- sum += this.wot.wtTable.getColumnWidth(column) || defaultColumnWidth;
118
+ sum += this.wot.wtTable.getStretchedColumnWidth(column) || defaultColumnWidth;
119
119
  column += 1;
120
120
  }
121
121
  return sum;
@@ -329,14 +329,13 @@ class Overlays {
329
329
  });
330
330
  let resizeTimeout;
331
331
  this.eventManager.addEventListener(rootWindow, 'resize', () => {
332
- (0, _feature.requestAnimationFrame)(() => {
333
- clearTimeout(resizeTimeout);
332
+ clearTimeout(resizeTimeout);
333
+ resizeTimeout = setTimeout(() => {
334
334
  this.wtSettings.getSetting('onWindowResize');
335
- resizeTimeout = setTimeout(() => {
336
- // Remove resizing the window from the ResizeObserver's endless-loop-blocking logic.
337
- _classPrivateFieldSet(_containerDomResizeCount, this, 0);
338
- }, 200);
339
- });
335
+
336
+ // Remove resizing the window from the ResizeObserver's endless-loop-blocking logic.
337
+ _classPrivateFieldSet(_containerDomResizeCount, this, 0);
338
+ }, 200);
340
339
  });
341
340
  if (!isScrollOnWindow) {
342
341
  this.resizeObserver.observe(this.wtTable.wtRootElement.parentElement);
@@ -326,14 +326,13 @@ class Overlays {
326
326
  });
327
327
  let resizeTimeout;
328
328
  this.eventManager.addEventListener(rootWindow, 'resize', () => {
329
- requestAnimationFrame(() => {
330
- clearTimeout(resizeTimeout);
329
+ clearTimeout(resizeTimeout);
330
+ resizeTimeout = setTimeout(() => {
331
331
  this.wtSettings.getSetting('onWindowResize');
332
- resizeTimeout = setTimeout(() => {
333
- // Remove resizing the window from the ResizeObserver's endless-loop-blocking logic.
334
- _classPrivateFieldSet(_containerDomResizeCount, this, 0);
335
- }, 200);
336
- });
332
+
333
+ // Remove resizing the window from the ResizeObserver's endless-loop-blocking logic.
334
+ _classPrivateFieldSet(_containerDomResizeCount, this, 0);
335
+ }, 200);
337
336
  });
338
337
  if (!isScrollOnWindow) {
339
338
  this.resizeObserver.observe(this.wtTable.wtRootElement.parentElement);
@@ -70,7 +70,7 @@ class ColGroupRenderer extends _base.default {
70
70
  // Render column nodes for cells
71
71
  for (let visibleColumnIndex = 0; visibleColumnIndex < columnsToRender; visibleColumnIndex++) {
72
72
  const sourceColumnIndex = this.table.renderedColumnToSource(visibleColumnIndex);
73
- const width = this.table.columnUtils.getWidth(sourceColumnIndex);
73
+ const width = this.table.columnUtils.getStretchedColumnWidth(sourceColumnIndex);
74
74
  this.rootNode.childNodes[visibleColumnIndex + rowHeadersCount].style.width = `${width}px`;
75
75
  }
76
76
  const firstChild = this.rootNode.firstChild;
@@ -66,7 +66,7 @@ export default class ColGroupRenderer extends BaseRenderer {
66
66
  // Render column nodes for cells
67
67
  for (let visibleColumnIndex = 0; visibleColumnIndex < columnsToRender; visibleColumnIndex++) {
68
68
  const sourceColumnIndex = this.table.renderedColumnToSource(visibleColumnIndex);
69
- const width = this.table.columnUtils.getWidth(sourceColumnIndex);
69
+ const width = this.table.columnUtils.getStretchedColumnWidth(sourceColumnIndex);
70
70
  this.rootNode.childNodes[visibleColumnIndex + rowHeadersCount].style.width = `${width}px`;
71
71
  }
72
72
  const firstChild = this.rootNode.firstChild;
@@ -301,7 +301,7 @@ class TableRenderer {
301
301
  this.rowHeaders.render();
302
302
  this.cells.render();
303
303
 
304
- // After the cells are rendered calculate columns width to prepare proper values
304
+ // After the cells are rendered calculate columns width (or columns stretch width) to prepare proper values
305
305
  // for colGroup renderer (which renders COL elements).
306
306
  this.columnUtils.calculateWidths();
307
307
  this.colGroup.render();
@@ -298,7 +298,7 @@ export default class TableRenderer {
298
298
  this.rowHeaders.render();
299
299
  this.cells.render();
300
300
 
301
- // After the cells are rendered calculate columns width to prepare proper values
301
+ // After the cells are rendered calculate columns width (or columns stretch width) to prepare proper values
302
302
  // for colGroup renderer (which renders COL elements).
303
303
  this.columnUtils.calculateWidths();
304
304
  this.colGroup.render();
@@ -24,6 +24,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
24
24
  * @property {Option} fixedColumnsStart Option `fixedColumnsStart`.
25
25
  * @property {Option} fixedRowsBottom Option `fixedRowsBottom`.
26
26
  * @property {Option} fixedRowsTop Option `fixedRowsTop`.
27
+ * @property {Option} freezeOverlays Option `freezeOverlays`.
27
28
  * @property {Option} groups Option `groups`.
28
29
  * @property {Option} hideBorderOnMouseDownOver Option `hideBorderOnMouseDownOver`.
29
30
  * @property {Option} isRtl Option `isRtl`.
@@ -32,6 +33,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
32
33
  * @property {Option} onBeforeHighlightingColumnHeader Option `onBeforeHighlightingColumnHeader`.
33
34
  * @property {Option} onBeforeHighlightingRowHeader Option `onBeforeHighlightingRowHeader`.
34
35
  * @property {Option} onBeforeRemoveCellClassNames Option `onBeforeRemoveCellClassNames`.
36
+ * @property {Option} onBeforeStretchingColumnWidth Option `onBeforeStretchingColumnWidth`.
35
37
  * @property {Option} preventOverflow Option `preventOverflow`.
36
38
  * @property {Option} preventWheel Option `preventWheel`.
37
39
  * @property {Option} renderAllColumns Option `renderAllColumns`.
@@ -42,6 +44,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
42
44
  * @property {Option} shouldRenderBottomOverlay Option `shouldRenderBottomOverlay`.
43
45
  * @property {Option} shouldRenderInlineStartOverlay Option `shouldRenderInlineStartOverlay`.
44
46
  * @property {Option} shouldRenderTopOverlay Option `shouldRenderTopOverlay`.
47
+ * @property {Option} stretchH Option `stretchH`.
45
48
  * @property {Option} table Option `table`.
46
49
  * @property {Option} totalColumns Option `totalColumns`.
47
50
  * @property {Option} totalRows Option `totalRows`.
@@ -134,6 +137,8 @@ class Settings {
134
137
  isDataViewInstance: true,
135
138
  // presentation mode
136
139
  externalRowCalculator: false,
140
+ stretchH: 'none',
141
+ // values: all, last, none
137
142
  currentRowClassName: null,
138
143
  currentColumnClassName: null,
139
144
  preventOverflow() {
@@ -142,6 +147,7 @@ class Settings {
142
147
  preventWheel: false,
143
148
  // data source
144
149
  data: undefined,
150
+ freezeOverlays: false,
145
151
  // Number of renderable columns for the left overlay.
146
152
  fixedColumnsStart: 0,
147
153
  // Number of renderable rows for the top overlay.
@@ -217,6 +223,7 @@ class Settings {
217
223
  //
218
224
  onBeforeTouchScroll: null,
219
225
  onAfterMomentumScroll: null,
226
+ onBeforeStretchingColumnWidth: width => width,
220
227
  onModifyRowHeaderWidth: null,
221
228
  onModifyGetCellCoords: null,
222
229
  onModifyGetCoordsElement: null,
@@ -21,6 +21,7 @@ import { objectEach } from "../../../helpers/object.mjs";
21
21
  * @property {Option} fixedColumnsStart Option `fixedColumnsStart`.
22
22
  * @property {Option} fixedRowsBottom Option `fixedRowsBottom`.
23
23
  * @property {Option} fixedRowsTop Option `fixedRowsTop`.
24
+ * @property {Option} freezeOverlays Option `freezeOverlays`.
24
25
  * @property {Option} groups Option `groups`.
25
26
  * @property {Option} hideBorderOnMouseDownOver Option `hideBorderOnMouseDownOver`.
26
27
  * @property {Option} isRtl Option `isRtl`.
@@ -29,6 +30,7 @@ import { objectEach } from "../../../helpers/object.mjs";
29
30
  * @property {Option} onBeforeHighlightingColumnHeader Option `onBeforeHighlightingColumnHeader`.
30
31
  * @property {Option} onBeforeHighlightingRowHeader Option `onBeforeHighlightingRowHeader`.
31
32
  * @property {Option} onBeforeRemoveCellClassNames Option `onBeforeRemoveCellClassNames`.
33
+ * @property {Option} onBeforeStretchingColumnWidth Option `onBeforeStretchingColumnWidth`.
32
34
  * @property {Option} preventOverflow Option `preventOverflow`.
33
35
  * @property {Option} preventWheel Option `preventWheel`.
34
36
  * @property {Option} renderAllColumns Option `renderAllColumns`.
@@ -39,6 +41,7 @@ import { objectEach } from "../../../helpers/object.mjs";
39
41
  * @property {Option} shouldRenderBottomOverlay Option `shouldRenderBottomOverlay`.
40
42
  * @property {Option} shouldRenderInlineStartOverlay Option `shouldRenderInlineStartOverlay`.
41
43
  * @property {Option} shouldRenderTopOverlay Option `shouldRenderTopOverlay`.
44
+ * @property {Option} stretchH Option `stretchH`.
42
45
  * @property {Option} table Option `table`.
43
46
  * @property {Option} totalColumns Option `totalColumns`.
44
47
  * @property {Option} totalRows Option `totalRows`.
@@ -129,6 +132,8 @@ export default class Settings {
129
132
  isDataViewInstance: true,
130
133
  // presentation mode
131
134
  externalRowCalculator: false,
135
+ stretchH: 'none',
136
+ // values: all, last, none
132
137
  currentRowClassName: null,
133
138
  currentColumnClassName: null,
134
139
  preventOverflow() {
@@ -137,6 +142,7 @@ export default class Settings {
137
142
  preventWheel: false,
138
143
  // data source
139
144
  data: undefined,
145
+ freezeOverlays: false,
140
146
  // Number of renderable columns for the left overlay.
141
147
  fixedColumnsStart: 0,
142
148
  // Number of renderable rows for the top overlay.
@@ -212,6 +218,7 @@ export default class Settings {
212
218
  //
213
219
  onBeforeTouchScroll: null,
214
220
  onAfterMomentumScroll: null,
221
+ onBeforeStretchingColumnWidth: width => width,
215
222
  onModifyRowHeaderWidth: null,
216
223
  onModifyGetCellCoords: null,
217
224
  onModifyGetCoordsElement: null,
@@ -296,7 +296,10 @@ class Table {
296
296
  }
297
297
  this.resetOversizedRows();
298
298
  this.tableRenderer.setActiveOverlayName(this.name).setViewportSize(this.getRenderedRowsCount(), this.getRenderedColumnsCount()).setFilters(this.rowFilter, this.columnFilter).render();
299
+ let workspaceWidth;
299
300
  if (this.isMaster) {
301
+ workspaceWidth = this.dataAccessObject.workspaceWidth;
302
+ wtViewport.containerWidth = null;
300
303
  this.markOversizedColumnHeaders();
301
304
  }
302
305
  this.adjustColumnHeaderHeights();
@@ -309,6 +312,19 @@ class Table {
309
312
  }
310
313
  wtOverlays.refresh(false);
311
314
  wtOverlays.applyToDOM();
315
+ const hiderWidth = (0, _element.outerWidth)(this.hider);
316
+ const tableWidth = (0, _element.outerWidth)(this.TABLE);
317
+ if (hiderWidth !== 0 && tableWidth !== hiderWidth) {
318
+ // Recalculate the column widths, if width changes made in the overlays removed the scrollbar, thus changing the viewport width.
319
+ this.columnUtils.calculateWidths();
320
+ this.tableRenderer.renderer.colGroup.render();
321
+ }
322
+ if (workspaceWidth !== wtViewport.getWorkspaceWidth()) {
323
+ // workspace width changed though to shown/hidden vertical scrollbar. Let's reapply stretching
324
+ wtViewport.containerWidth = null;
325
+ this.columnUtils.calculateWidths();
326
+ this.tableRenderer.renderer.colGroup.render();
327
+ }
312
328
  this.wtSettings.getSetting('onDraw', true);
313
329
  } else if (this.is(_overlay.CLONE_BOTTOM)) {
314
330
  this.dataAccessObject.cloneSource.wtOverlays.adjustElementsSize();
@@ -897,6 +913,14 @@ class Table {
897
913
  return this.columnUtils.getWidth(sourceColumn);
898
914
  }
899
915
 
916
+ /**
917
+ * @param {number} sourceColumn The physical column index.
918
+ * @returns {number}
919
+ */
920
+ getStretchedColumnWidth(sourceColumn) {
921
+ return this.columnUtils.getStretchedColumnWidth(sourceColumn);
922
+ }
923
+
900
924
  /**
901
925
  * Checks if the table has defined size. It returns `true` when the table has width and height
902
926
  * set bigger than `0px`.
@@ -292,7 +292,10 @@ class Table {
292
292
  }
293
293
  this.resetOversizedRows();
294
294
  this.tableRenderer.setActiveOverlayName(this.name).setViewportSize(this.getRenderedRowsCount(), this.getRenderedColumnsCount()).setFilters(this.rowFilter, this.columnFilter).render();
295
+ let workspaceWidth;
295
296
  if (this.isMaster) {
297
+ workspaceWidth = this.dataAccessObject.workspaceWidth;
298
+ wtViewport.containerWidth = null;
296
299
  this.markOversizedColumnHeaders();
297
300
  }
298
301
  this.adjustColumnHeaderHeights();
@@ -305,6 +308,19 @@ class Table {
305
308
  }
306
309
  wtOverlays.refresh(false);
307
310
  wtOverlays.applyToDOM();
311
+ const hiderWidth = outerWidth(this.hider);
312
+ const tableWidth = outerWidth(this.TABLE);
313
+ if (hiderWidth !== 0 && tableWidth !== hiderWidth) {
314
+ // Recalculate the column widths, if width changes made in the overlays removed the scrollbar, thus changing the viewport width.
315
+ this.columnUtils.calculateWidths();
316
+ this.tableRenderer.renderer.colGroup.render();
317
+ }
318
+ if (workspaceWidth !== wtViewport.getWorkspaceWidth()) {
319
+ // workspace width changed though to shown/hidden vertical scrollbar. Let's reapply stretching
320
+ wtViewport.containerWidth = null;
321
+ this.columnUtils.calculateWidths();
322
+ this.tableRenderer.renderer.colGroup.render();
323
+ }
308
324
  this.wtSettings.getSetting('onDraw', true);
309
325
  } else if (this.is(CLONE_BOTTOM)) {
310
326
  this.dataAccessObject.cloneSource.wtOverlays.adjustElementsSize();
@@ -893,6 +909,14 @@ class Table {
893
909
  return this.columnUtils.getWidth(sourceColumn);
894
910
  }
895
911
 
912
+ /**
913
+ * @param {number} sourceColumn The physical column index.
914
+ * @returns {number}
915
+ */
916
+ getStretchedColumnWidth(sourceColumn) {
917
+ return this.columnUtils.getStretchedColumnWidth(sourceColumn);
918
+ }
919
+
896
920
  /**
897
921
  * Checks if the table has defined size. It returns `true` when the table has width and height
898
922
  * set bigger than `0px`.
@@ -2,6 +2,8 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  require("core-js/modules/es.error.cause.js");
5
+ var _element = require("./../../../../helpers/dom/element");
6
+ var _columnStretching = require("./columnStretching");
5
7
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
6
8
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
7
9
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
@@ -28,8 +30,18 @@ class ColumnUtils {
28
30
  * @type {Map<number, number>}
29
31
  */
30
32
  _defineProperty(this, "headerWidths", new Map());
33
+ /**
34
+ * @type {ColumnStretching}
35
+ */
36
+ _defineProperty(this, "stretching", void 0);
31
37
  this.dataAccessObject = dataAccessObject;
32
38
  this.wtSettings = wtSettings;
39
+ this.stretching = new _columnStretching.ColumnStretching({
40
+ totalColumns: () => this.wtSettings.getSetting('totalColumns'),
41
+ stretchMode: () => this.wtSettings.getSetting('stretchH'),
42
+ stretchingColumnWidthFn: (stretchedWidth, column) => this.wtSettings.getSetting('onBeforeStretchingColumnWidth', stretchedWidth, column),
43
+ columnWidthFn: sourceCol => this.dataAccessObject.wtTable.getColumnWidth(sourceCol)
44
+ });
33
45
  }
34
46
 
35
47
  /**
@@ -43,6 +55,21 @@ class ColumnUtils {
43
55
  return width;
44
56
  }
45
57
 
58
+ /**
59
+ * Returns stretched column width based on passed source index.
60
+ *
61
+ * @param {number} sourceIndex Column source index.
62
+ * @returns {number}
63
+ */
64
+ getStretchedColumnWidth(sourceIndex) {
65
+ let width = this.getWidth(sourceIndex);
66
+ const stretchedWidth = this.stretching.getStretchedColumnWidth(sourceIndex, width);
67
+ if (stretchedWidth) {
68
+ width = stretchedWidth;
69
+ }
70
+ return width;
71
+ }
72
+
46
73
  /**
47
74
  * Returns column header height based on passed header level.
48
75
  *
@@ -68,6 +95,20 @@ class ColumnUtils {
68
95
  return this.headerWidths.get(this.dataAccessObject.wtTable.columnFilter.sourceToRendered(sourceIndex));
69
96
  }
70
97
 
98
+ /**
99
+ * Refreshes the stretching column width by recalculating the widths of the columns.
100
+ */
101
+ refreshStretching() {
102
+ const {
103
+ wtTable,
104
+ wtViewport,
105
+ cloneSource
106
+ } = this.dataAccessObject;
107
+ const mainHolder = cloneSource ? cloneSource.wtTable.holder : wtTable.holder;
108
+ const scrollbarCompensation = mainHolder.offsetHeight < mainHolder.scrollHeight ? (0, _element.getScrollbarWidth)() : 0;
109
+ this.stretching.refreshStretching(wtViewport.getViewportWidth() - scrollbarCompensation);
110
+ }
111
+
71
112
  /**
72
113
  * Calculates column header widths that can be retrieved from the cache.
73
114
  */
@@ -76,6 +117,7 @@ class ColumnUtils {
76
117
  wtSettings
77
118
  } = this;
78
119
  let rowHeaderWidthSetting = wtSettings.getSetting('rowHeaderWidth');
120
+ this.refreshStretching();
79
121
  rowHeaderWidthSetting = wtSettings.getSetting('onModifyRowHeaderWidth', rowHeaderWidthSetting);
80
122
  if (rowHeaderWidthSetting !== null && rowHeaderWidthSetting !== undefined) {
81
123
  const rowHeadersCount = wtSettings.getSetting('rowHeaders').length;
@@ -2,6 +2,8 @@ import "core-js/modules/es.error.cause.js";
2
2
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
3
3
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
4
4
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
+ import { getScrollbarWidth } from "./../../../../helpers/dom/element.mjs";
6
+ import { ColumnStretching } from "./columnStretching.mjs";
5
7
  /**
6
8
  * Column utils class contains all necessary information about sizes of the columns.
7
9
  *
@@ -25,8 +27,18 @@ export default class ColumnUtils {
25
27
  * @type {Map<number, number>}
26
28
  */
27
29
  _defineProperty(this, "headerWidths", new Map());
30
+ /**
31
+ * @type {ColumnStretching}
32
+ */
33
+ _defineProperty(this, "stretching", void 0);
28
34
  this.dataAccessObject = dataAccessObject;
29
35
  this.wtSettings = wtSettings;
36
+ this.stretching = new ColumnStretching({
37
+ totalColumns: () => this.wtSettings.getSetting('totalColumns'),
38
+ stretchMode: () => this.wtSettings.getSetting('stretchH'),
39
+ stretchingColumnWidthFn: (stretchedWidth, column) => this.wtSettings.getSetting('onBeforeStretchingColumnWidth', stretchedWidth, column),
40
+ columnWidthFn: sourceCol => this.dataAccessObject.wtTable.getColumnWidth(sourceCol)
41
+ });
30
42
  }
31
43
 
32
44
  /**
@@ -40,6 +52,21 @@ export default class ColumnUtils {
40
52
  return width;
41
53
  }
42
54
 
55
+ /**
56
+ * Returns stretched column width based on passed source index.
57
+ *
58
+ * @param {number} sourceIndex Column source index.
59
+ * @returns {number}
60
+ */
61
+ getStretchedColumnWidth(sourceIndex) {
62
+ let width = this.getWidth(sourceIndex);
63
+ const stretchedWidth = this.stretching.getStretchedColumnWidth(sourceIndex, width);
64
+ if (stretchedWidth) {
65
+ width = stretchedWidth;
66
+ }
67
+ return width;
68
+ }
69
+
43
70
  /**
44
71
  * Returns column header height based on passed header level.
45
72
  *
@@ -65,6 +92,20 @@ export default class ColumnUtils {
65
92
  return this.headerWidths.get(this.dataAccessObject.wtTable.columnFilter.sourceToRendered(sourceIndex));
66
93
  }
67
94
 
95
+ /**
96
+ * Refreshes the stretching column width by recalculating the widths of the columns.
97
+ */
98
+ refreshStretching() {
99
+ const {
100
+ wtTable,
101
+ wtViewport,
102
+ cloneSource
103
+ } = this.dataAccessObject;
104
+ const mainHolder = cloneSource ? cloneSource.wtTable.holder : wtTable.holder;
105
+ const scrollbarCompensation = mainHolder.offsetHeight < mainHolder.scrollHeight ? getScrollbarWidth() : 0;
106
+ this.stretching.refreshStretching(wtViewport.getViewportWidth() - scrollbarCompensation);
107
+ }
108
+
68
109
  /**
69
110
  * Calculates column header widths that can be retrieved from the cache.
70
111
  */
@@ -73,6 +114,7 @@ export default class ColumnUtils {
73
114
  wtSettings
74
115
  } = this;
75
116
  let rowHeaderWidthSetting = wtSettings.getSetting('rowHeaderWidth');
117
+ this.refreshStretching();
76
118
  rowHeaderWidthSetting = wtSettings.getSetting('onModifyRowHeaderWidth', rowHeaderWidthSetting);
77
119
  if (rowHeaderWidthSetting !== null && rowHeaderWidthSetting !== undefined) {
78
120
  const rowHeadersCount = wtSettings.getSetting('rowHeaders').length;
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ require("core-js/modules/es.error.cause.js");
5
+ var _calculator = require("../calculator");
6
+ function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
7
+ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
8
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
9
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
10
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
11
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
12
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
13
+ function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
14
+ /**
15
+ * @typedef {object} ColumnStretchingOptions
16
+ * @property {number} totalColumns Total number of columns.
17
+ * @property {Function} columnWidthFn Function that returns the width of the column at a given index (in px).
18
+ * @property {'all' | 'last' | 'none'} stretchMode Stretch mode 'all', 'last' or 'none'.
19
+ * @property {Function} stretchingColumnWidthFn Function that returns the new width of the stretched column.
20
+ */
21
+ /**
22
+ * @class ColumnStretching
23
+ */
24
+ var _totalTargetWidth = /*#__PURE__*/new WeakMap();
25
+ var _totalColumns = /*#__PURE__*/new WeakMap();
26
+ var _stretchingColumnWidthFn = /*#__PURE__*/new WeakMap();
27
+ var _columnWidthFn = /*#__PURE__*/new WeakMap();
28
+ var _stretchMode = /*#__PURE__*/new WeakMap();
29
+ class ColumnStretching {
30
+ /**
31
+ * @param {ColumnStretchingOptions} options Object with all options specified for column viewport calculation.
32
+ */
33
+ constructor(_ref) {
34
+ let {
35
+ totalColumns,
36
+ stretchMode,
37
+ stretchingColumnWidthFn,
38
+ columnWidthFn
39
+ } = _ref;
40
+ /**
41
+ * @type {number}
42
+ */
43
+ _defineProperty(this, "stretchAllRatio", 0);
44
+ /**
45
+ * @type {number}
46
+ */
47
+ _defineProperty(this, "stretchLastWidth", 0);
48
+ /**
49
+ * @type {number[]}
50
+ */
51
+ _defineProperty(this, "stretchAllColumnsWidth", []);
52
+ /**
53
+ * @type {number}
54
+ */
55
+ _classPrivateFieldInitSpec(this, _totalTargetWidth, 0);
56
+ /**
57
+ * @type {boolean}
58
+ */
59
+ _defineProperty(this, "needVerifyLastColumnWidth", true);
60
+ /**
61
+ * The total number of columns.
62
+ *
63
+ * @type {function(): number}
64
+ */
65
+ _classPrivateFieldInitSpec(this, _totalColumns, () => 0);
66
+ /**
67
+ * Function that returns the width of the stretched column at a given index (in px).
68
+ *
69
+ * @type {function(): number}
70
+ */
71
+ _classPrivateFieldInitSpec(this, _stretchingColumnWidthFn, width => width);
72
+ /**
73
+ * Function that returns the width of the column at a given index (in px).
74
+ *
75
+ * @type {function(): number}
76
+ */
77
+ _classPrivateFieldInitSpec(this, _columnWidthFn, width => width);
78
+ /**
79
+ * Stretch mode.
80
+ *
81
+ * @type {function(): 'all' | 'last' | 'none'}
82
+ */
83
+ _classPrivateFieldInitSpec(this, _stretchMode, () => 'none');
84
+ _classPrivateFieldSet(_totalColumns, this, totalColumns);
85
+ _classPrivateFieldSet(_stretchMode, this, stretchMode);
86
+ _classPrivateFieldSet(_stretchingColumnWidthFn, this, stretchingColumnWidthFn !== null && stretchingColumnWidthFn !== void 0 ? stretchingColumnWidthFn : _classPrivateFieldGet(_stretchingColumnWidthFn, this));
87
+ _classPrivateFieldSet(_columnWidthFn, this, columnWidthFn !== null && columnWidthFn !== void 0 ? columnWidthFn : _classPrivateFieldGet(_columnWidthFn, this));
88
+ }
89
+
90
+ /**
91
+ * Recalculate columns stretching.
92
+ *
93
+ * @param {number} totalWidth The total width of the table.
94
+ */
95
+ refreshStretching(totalWidth) {
96
+ if (_classPrivateFieldGet(_stretchMode, this).call(this) === 'none') {
97
+ return;
98
+ }
99
+ this.stretchAllRatio = 0;
100
+ this.stretchAllColumnsWidth = [];
101
+ this.needVerifyLastColumnWidth = true;
102
+ this.stretchLastWidth = 0;
103
+ _classPrivateFieldSet(_totalTargetWidth, this, totalWidth);
104
+ let sumAll = 0;
105
+ for (let i = 0; i < _classPrivateFieldGet(_totalColumns, this).call(this); i++) {
106
+ const columnWidth = this._getColumnWidth(i);
107
+ const permanentColumnWidth = _classPrivateFieldGet(_stretchingColumnWidthFn, this).call(this, undefined, i);
108
+ if (typeof permanentColumnWidth === 'number') {
109
+ totalWidth -= permanentColumnWidth;
110
+ } else {
111
+ sumAll += columnWidth;
112
+ }
113
+ }
114
+ const remainingSize = totalWidth - sumAll;
115
+ if (_classPrivateFieldGet(_stretchMode, this).call(this) === 'all' && remainingSize > 0) {
116
+ this.stretchAllRatio = totalWidth / sumAll;
117
+ this.stretchAllColumnsWidth = [];
118
+ this.needVerifyLastColumnWidth = true;
119
+ } else if (_classPrivateFieldGet(_stretchMode, this).call(this) === 'last' && totalWidth !== Infinity) {
120
+ const columnWidth = this._getColumnWidth(_classPrivateFieldGet(_totalColumns, this).call(this) - 1);
121
+ const lastColumnWidth = remainingSize + columnWidth;
122
+ this.stretchLastWidth = lastColumnWidth >= 0 ? lastColumnWidth : columnWidth;
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Get stretched column width based on stretchH (all or last) setting passed in handsontable instance.
128
+ *
129
+ * @param {number} column The visual column index.
130
+ * @param {number} baseWidth The default column width.
131
+ * @returns {number|null}
132
+ */
133
+ getStretchedColumnWidth(column, baseWidth) {
134
+ let result = null;
135
+ if (_classPrivateFieldGet(_stretchMode, this).call(this) === 'all' && this.stretchAllRatio !== 0) {
136
+ result = this._getStretchedAllColumnWidth(column, baseWidth);
137
+ } else if (_classPrivateFieldGet(_stretchMode, this).call(this) === 'last' && this.stretchLastWidth !== 0) {
138
+ result = this._getStretchedLastColumnWidth(column);
139
+ }
140
+ return result;
141
+ }
142
+
143
+ /**
144
+ * @param {number} column The visual column index.
145
+ * @param {number} baseWidth The default column width.
146
+ * @returns {number}
147
+ * @private
148
+ */
149
+ _getStretchedAllColumnWidth(column, baseWidth) {
150
+ let sumRatioWidth = 0;
151
+ if (!this.stretchAllColumnsWidth[column]) {
152
+ const stretchedWidth = Math.round(baseWidth * this.stretchAllRatio);
153
+ const newStretchedWidth = _classPrivateFieldGet(_stretchingColumnWidthFn, this).call(this, stretchedWidth, column);
154
+ if (newStretchedWidth === undefined) {
155
+ this.stretchAllColumnsWidth[column] = stretchedWidth;
156
+ } else {
157
+ this.stretchAllColumnsWidth[column] = isNaN(newStretchedWidth) ? this._getColumnWidth(column) : newStretchedWidth;
158
+ }
159
+ }
160
+ if (this.stretchAllColumnsWidth.length === _classPrivateFieldGet(_totalColumns, this).call(this) && this.needVerifyLastColumnWidth) {
161
+ this.needVerifyLastColumnWidth = false;
162
+ for (let i = 0; i < this.stretchAllColumnsWidth.length; i++) {
163
+ sumRatioWidth += this.stretchAllColumnsWidth[i];
164
+ }
165
+ if (sumRatioWidth !== _classPrivateFieldGet(_totalTargetWidth, this)) {
166
+ this.stretchAllColumnsWidth[this.stretchAllColumnsWidth.length - 1] += _classPrivateFieldGet(_totalTargetWidth, this) - sumRatioWidth;
167
+ }
168
+ }
169
+ return this.stretchAllColumnsWidth[column];
170
+ }
171
+
172
+ /**
173
+ * @param {number} column The visual column index.
174
+ * @returns {number|null}
175
+ * @private
176
+ */
177
+ _getStretchedLastColumnWidth(column) {
178
+ if (column === _classPrivateFieldGet(_totalColumns, this).call(this) - 1) {
179
+ return this.stretchLastWidth;
180
+ }
181
+ return null;
182
+ }
183
+
184
+ /**
185
+ * @param {number} column The visual column index.
186
+ * @returns {number}
187
+ * @private
188
+ */
189
+ _getColumnWidth(column) {
190
+ let width = _classPrivateFieldGet(_columnWidthFn, this).call(this, column);
191
+ if (isNaN(width)) {
192
+ width = _calculator.DEFAULT_COLUMN_WIDTH;
193
+ }
194
+ return width;
195
+ }
196
+ }
197
+ exports.ColumnStretching = ColumnStretching;