handsontable 0.0.0-next-802f59c-20241024 → 0.0.0-next-627918e-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 (128) hide show
  1. package/3rdparty/walkontable/src/calculator/index.js +1 -2
  2. package/3rdparty/walkontable/src/calculator/index.mjs +2 -2
  3. package/3rdparty/walkontable/src/calculator/viewportRows.js +3 -3
  4. package/3rdparty/walkontable/src/calculator/viewportRows.mjs +3 -3
  5. package/3rdparty/walkontable/src/core/_base.js +3 -0
  6. package/3rdparty/walkontable/src/core/_base.mjs +3 -0
  7. package/3rdparty/walkontable/src/core/clone.js +1 -0
  8. package/3rdparty/walkontable/src/core/clone.mjs +1 -0
  9. package/3rdparty/walkontable/src/core/core.js +2 -0
  10. package/3rdparty/walkontable/src/core/core.mjs +2 -0
  11. package/3rdparty/walkontable/src/facade/core.js +3 -0
  12. package/3rdparty/walkontable/src/facade/core.mjs +3 -0
  13. package/3rdparty/walkontable/src/index.js +0 -1
  14. package/3rdparty/walkontable/src/index.mjs +2 -2
  15. package/3rdparty/walkontable/src/overlay/_base.js +3 -1
  16. package/3rdparty/walkontable/src/overlay/_base.mjs +3 -1
  17. package/3rdparty/walkontable/src/overlay/bottom.js +2 -2
  18. package/3rdparty/walkontable/src/overlay/bottom.mjs +2 -2
  19. package/3rdparty/walkontable/src/overlay/inlineStart.js +1 -1
  20. package/3rdparty/walkontable/src/overlay/inlineStart.mjs +1 -1
  21. package/3rdparty/walkontable/src/overlay/top.js +1 -1
  22. package/3rdparty/walkontable/src/overlay/top.mjs +1 -1
  23. package/3rdparty/walkontable/src/overlays.js +6 -7
  24. package/3rdparty/walkontable/src/overlays.mjs +6 -7
  25. package/3rdparty/walkontable/src/renderer/colGroup.js +1 -1
  26. package/3rdparty/walkontable/src/renderer/colGroup.mjs +1 -1
  27. package/3rdparty/walkontable/src/renderer/table.js +1 -1
  28. package/3rdparty/walkontable/src/renderer/table.mjs +1 -1
  29. package/3rdparty/walkontable/src/settings.js +8 -2
  30. package/3rdparty/walkontable/src/settings.mjs +8 -2
  31. package/3rdparty/walkontable/src/table.js +35 -8
  32. package/3rdparty/walkontable/src/table.mjs +35 -8
  33. package/3rdparty/walkontable/src/types.js +1 -0
  34. package/3rdparty/walkontable/src/types.mjs +1 -0
  35. package/3rdparty/walkontable/src/utils/column.js +43 -1
  36. package/3rdparty/walkontable/src/utils/column.mjs +43 -1
  37. package/3rdparty/walkontable/src/utils/columnStretching.js +197 -0
  38. package/3rdparty/walkontable/src/utils/columnStretching.mjs +193 -0
  39. package/3rdparty/walkontable/src/utils/stylesHandler.js +179 -0
  40. package/3rdparty/walkontable/src/utils/stylesHandler.mjs +175 -0
  41. package/3rdparty/walkontable/src/viewport.js +88 -66
  42. package/3rdparty/walkontable/src/viewport.mjs +89 -67
  43. package/base.js +2 -2
  44. package/base.mjs +2 -2
  45. package/core/hooks/constants.js +0 -2
  46. package/core/hooks/constants.mjs +0 -2
  47. package/core/hooks/index.d.ts +2 -2
  48. package/core.d.ts +2 -2
  49. package/core.js +18 -6
  50. package/core.mjs +18 -6
  51. package/dataMap/metaManager/metaSchema.js +17 -0
  52. package/dataMap/metaManager/metaSchema.mjs +17 -0
  53. package/dist/handsontable.css +17 -9
  54. package/dist/handsontable.full.css +17 -7
  55. package/dist/handsontable.full.js +4217 -4534
  56. package/dist/handsontable.full.min.css +5 -4
  57. package/dist/handsontable.full.min.js +26 -26
  58. package/dist/handsontable.js +3923 -4234
  59. package/dist/handsontable.min.css +5 -4
  60. package/dist/handsontable.min.js +24 -24
  61. package/editors/autocompleteEditor/autocompleteEditor.js +1 -1
  62. package/editors/autocompleteEditor/autocompleteEditor.mjs +1 -1
  63. package/editors/baseEditor/baseEditor.js +1 -1
  64. package/editors/baseEditor/baseEditor.mjs +1 -1
  65. package/editors/dateEditor/dateEditor.js +2 -0
  66. package/editors/dateEditor/dateEditor.mjs +2 -0
  67. package/editors/handsontableEditor/handsontableEditor.js +1 -1
  68. package/editors/handsontableEditor/handsontableEditor.mjs +1 -1
  69. package/editors/selectEditor/selectEditor.js +20 -9
  70. package/editors/selectEditor/selectEditor.mjs +20 -9
  71. package/editors/textEditor/textEditor.js +4 -11
  72. package/editors/textEditor/textEditor.mjs +4 -11
  73. package/helpers/mixed.js +2 -2
  74. package/helpers/mixed.mjs +2 -2
  75. package/helpers/themes.js +17 -0
  76. package/helpers/themes.mjs +13 -0
  77. package/index.d.ts +0 -7
  78. package/package.json +10 -8
  79. package/plugins/comments/commentEditor.js +8 -1
  80. package/plugins/comments/commentEditor.mjs +8 -1
  81. package/plugins/comments/comments.js +2 -2
  82. package/plugins/comments/comments.mjs +2 -2
  83. package/plugins/contextMenu/menu/menu.js +4 -4
  84. package/plugins/contextMenu/menu/menu.mjs +4 -4
  85. package/plugins/index.d.ts +0 -3
  86. package/plugins/index.js +0 -3
  87. package/plugins/index.mjs +1 -3
  88. package/plugins/manualColumnMove/manualColumnMove.js +3 -1
  89. package/plugins/manualColumnMove/manualColumnMove.mjs +3 -1
  90. package/plugins/manualColumnResize/manualColumnResize.js +12 -24
  91. package/plugins/manualColumnResize/manualColumnResize.mjs +12 -24
  92. package/plugins/manualRowMove/manualRowMove.js +1 -1
  93. package/plugins/manualRowMove/manualRowMove.mjs +1 -1
  94. package/plugins/manualRowResize/manualRowResize.js +1 -2
  95. package/plugins/manualRowResize/manualRowResize.mjs +2 -3
  96. package/plugins/mergeCells/mergeCells.js +1 -1
  97. package/plugins/mergeCells/mergeCells.mjs +1 -1
  98. package/plugins/nestedRows/ui/headers.js +3 -1
  99. package/plugins/nestedRows/ui/headers.mjs +3 -1
  100. package/settings.d.ts +1 -0
  101. package/styles/handsontable.css +1983 -0
  102. package/styles/handsontable.min.css +30 -0
  103. package/styles/ht-theme-gemini.css +706 -0
  104. package/styles/ht-theme-gemini.min.css +30 -0
  105. package/styles/ht-theme-main.css +714 -0
  106. package/styles/ht-theme-main.min.css +30 -0
  107. package/stylesManager.js +1 -0
  108. package/stylesManager.mjs +0 -0
  109. package/tableView.js +40 -39
  110. package/tableView.mjs +40 -39
  111. package/utils/autoResize.js +4 -1
  112. package/utils/autoResize.mjs +4 -1
  113. package/utils/ghostTable.js +1 -1
  114. package/utils/ghostTable.mjs +1 -1
  115. package/plugins/stretchColumns/calculator.js +0 -159
  116. package/plugins/stretchColumns/calculator.mjs +0 -155
  117. package/plugins/stretchColumns/index.d.ts +0 -1
  118. package/plugins/stretchColumns/index.js +0 -7
  119. package/plugins/stretchColumns/index.mjs +0 -1
  120. package/plugins/stretchColumns/strategies/_base.js +0 -85
  121. package/plugins/stretchColumns/strategies/_base.mjs +0 -81
  122. package/plugins/stretchColumns/strategies/all.js +0 -68
  123. package/plugins/stretchColumns/strategies/all.mjs +0 -64
  124. package/plugins/stretchColumns/strategies/last.js +0 -77
  125. package/plugins/stretchColumns/strategies/last.mjs +0 -73
  126. package/plugins/stretchColumns/stretchColumns.d.ts +0 -11
  127. package/plugins/stretchColumns/stretchColumns.js +0 -211
  128. package/plugins/stretchColumns/stretchColumns.mjs +0 -207
@@ -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();
@@ -347,7 +363,7 @@ class Table {
347
363
  markIfOversizedColumnHeader(col) {
348
364
  const sourceColIndex = this.columnFilter.renderedToSource(col);
349
365
  let level = this.wtSettings.getSetting('columnHeaders').length;
350
- const defaultRowHeight = this.wtSettings.getSetting('defaultRowHeight');
366
+ const defaultRowHeight = this.dataAccessObject.stylesHandler.getDefaultRowHeight();
351
367
  let previousColHeaderHeight;
352
368
  let currentHeader;
353
369
  let currentHeaderHeight;
@@ -625,10 +641,13 @@ class Table {
625
641
  return;
626
642
  }
627
643
  let rowCount = this.TBODY.childNodes.length;
628
- const expectedTableHeight = rowCount * this.wtSettings.getSetting('defaultRowHeight');
644
+ const expectedTableHeight = rowCount * this.dataAccessObject.stylesHandler.getDefaultRowHeight();
629
645
  const actualTableHeight = innerHeight(this.TBODY) - 1;
646
+ const borderBoxSizing = this.wot.stylesHandler.getStyleForTD('box-sizing') === 'border-box';
647
+ const rowHeightFn = borderBoxSizing ? outerHeight : innerHeight;
648
+ const borderCompensation = borderBoxSizing ? 0 : 1;
630
649
  let previousRowHeight;
631
- let rowInnerHeight;
650
+ let rowCurrentHeight;
632
651
  let sourceRowIndex;
633
652
  let currentTr;
634
653
  let rowHeader;
@@ -643,13 +662,13 @@ class Table {
643
662
  currentTr = this.getTrForRow(sourceRowIndex);
644
663
  rowHeader = currentTr.querySelector('th');
645
664
  if (rowHeader) {
646
- rowInnerHeight = innerHeight(rowHeader);
665
+ rowCurrentHeight = rowHeightFn(rowHeader);
647
666
  } else {
648
- rowInnerHeight = innerHeight(currentTr) - 1;
667
+ rowCurrentHeight = rowHeightFn(currentTr) - borderCompensation;
649
668
  }
650
- if (!previousRowHeight && this.wtSettings.getSetting('defaultRowHeight') < rowInnerHeight || previousRowHeight < rowInnerHeight) {
651
- rowInnerHeight += 1;
652
- this.dataAccessObject.wtViewport.oversizedRows[sourceRowIndex] = rowInnerHeight;
669
+ if (!previousRowHeight && this.dataAccessObject.stylesHandler.getDefaultRowHeight() < rowCurrentHeight || previousRowHeight < rowCurrentHeight) {
670
+ rowCurrentHeight += 1;
671
+ this.dataAccessObject.wtViewport.oversizedRows[sourceRowIndex] = rowCurrentHeight;
653
672
  }
654
673
  }
655
674
  }
@@ -893,6 +912,14 @@ class Table {
893
912
  return this.columnUtils.getWidth(sourceColumn);
894
913
  }
895
914
 
915
+ /**
916
+ * @param {number} sourceColumn The physical column index.
917
+ * @returns {number}
918
+ */
919
+ getStretchedColumnWidth(sourceColumn) {
920
+ return this.columnUtils.getStretchedColumnWidth(sourceColumn);
921
+ }
922
+
896
923
  /**
897
924
  * Checks if the table has defined size. It returns `true` when the table has width and height
898
925
  * set bigger than `0px`.
@@ -66,6 +66,7 @@
66
66
  * @property {Walkontable} cloneSource CloneSource.
67
67
  * @property {Walkontable} wot Wot.
68
68
  * @property {number} parentTableOffset ParentTableOffset.
69
+ * @property {StylesHandler} stylesHandler StylesHandler.
69
70
  * @property {number|null} startColumnRendered StartColumnRendered.
70
71
  * @property {number|null} startColumnVisible StartColumnVisible.
71
72
  * @property {number|null} endColumnRendered EndColumnRendered.
@@ -66,6 +66,7 @@
66
66
  * @property {Walkontable} cloneSource CloneSource.
67
67
  * @property {Walkontable} wot Wot.
68
68
  * @property {number} parentTableOffset ParentTableOffset.
69
+ * @property {StylesHandler} stylesHandler StylesHandler.
69
70
  * @property {number|null} startColumnRendered StartColumnRendered.
70
71
  * @property {number|null} startColumnVisible StartColumnVisible.
71
72
  * @property {number|null} endColumnRendered EndColumnRendered.
@@ -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
  *
@@ -50,7 +77,7 @@ class ColumnUtils {
50
77
  * @returns {number}
51
78
  */
52
79
  getHeaderHeight(level) {
53
- let height = this.wtSettings.getSetting('defaultRowHeight');
80
+ let height = this.dataAccessObject.stylesHandler.getDefaultRowHeight();
54
81
  const oversizedHeight = this.dataAccessObject.wtViewport.oversizedColumnHeaders[level];
55
82
  if (oversizedHeight !== undefined) {
56
83
  height = height ? Math.max(height, oversizedHeight) : oversizedHeight;
@@ -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
  *
@@ -47,7 +74,7 @@ export default class ColumnUtils {
47
74
  * @returns {number}
48
75
  */
49
76
  getHeaderHeight(level) {
50
- let height = this.wtSettings.getSetting('defaultRowHeight');
77
+ let height = this.dataAccessObject.stylesHandler.getDefaultRowHeight();
51
78
  const oversizedHeight = this.dataAccessObject.wtViewport.oversizedColumnHeaders[level];
52
79
  if (oversizedHeight !== undefined) {
53
80
  height = height ? Math.max(height, oversizedHeight) : oversizedHeight;
@@ -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;
@@ -0,0 +1,193 @@
1
+ import "core-js/modules/es.error.cause.js";
2
+ function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
3
+ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
6
+ 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); }
7
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
8
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
9
+ 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"); }
10
+ import { DEFAULT_COLUMN_WIDTH } from "../calculator/index.mjs";
11
+ /**
12
+ * @typedef {object} ColumnStretchingOptions
13
+ * @property {number} totalColumns Total number of columns.
14
+ * @property {Function} columnWidthFn Function that returns the width of the column at a given index (in px).
15
+ * @property {'all' | 'last' | 'none'} stretchMode Stretch mode 'all', 'last' or 'none'.
16
+ * @property {Function} stretchingColumnWidthFn Function that returns the new width of the stretched column.
17
+ */
18
+ /**
19
+ * @class ColumnStretching
20
+ */
21
+ var _totalTargetWidth = /*#__PURE__*/new WeakMap();
22
+ var _totalColumns = /*#__PURE__*/new WeakMap();
23
+ var _stretchingColumnWidthFn = /*#__PURE__*/new WeakMap();
24
+ var _columnWidthFn = /*#__PURE__*/new WeakMap();
25
+ var _stretchMode = /*#__PURE__*/new WeakMap();
26
+ export class ColumnStretching {
27
+ /**
28
+ * @param {ColumnStretchingOptions} options Object with all options specified for column viewport calculation.
29
+ */
30
+ constructor(_ref) {
31
+ let {
32
+ totalColumns,
33
+ stretchMode,
34
+ stretchingColumnWidthFn,
35
+ columnWidthFn
36
+ } = _ref;
37
+ /**
38
+ * @type {number}
39
+ */
40
+ _defineProperty(this, "stretchAllRatio", 0);
41
+ /**
42
+ * @type {number}
43
+ */
44
+ _defineProperty(this, "stretchLastWidth", 0);
45
+ /**
46
+ * @type {number[]}
47
+ */
48
+ _defineProperty(this, "stretchAllColumnsWidth", []);
49
+ /**
50
+ * @type {number}
51
+ */
52
+ _classPrivateFieldInitSpec(this, _totalTargetWidth, 0);
53
+ /**
54
+ * @type {boolean}
55
+ */
56
+ _defineProperty(this, "needVerifyLastColumnWidth", true);
57
+ /**
58
+ * The total number of columns.
59
+ *
60
+ * @type {function(): number}
61
+ */
62
+ _classPrivateFieldInitSpec(this, _totalColumns, () => 0);
63
+ /**
64
+ * Function that returns the width of the stretched column at a given index (in px).
65
+ *
66
+ * @type {function(): number}
67
+ */
68
+ _classPrivateFieldInitSpec(this, _stretchingColumnWidthFn, width => width);
69
+ /**
70
+ * Function that returns the width of the column at a given index (in px).
71
+ *
72
+ * @type {function(): number}
73
+ */
74
+ _classPrivateFieldInitSpec(this, _columnWidthFn, width => width);
75
+ /**
76
+ * Stretch mode.
77
+ *
78
+ * @type {function(): 'all' | 'last' | 'none'}
79
+ */
80
+ _classPrivateFieldInitSpec(this, _stretchMode, () => 'none');
81
+ _classPrivateFieldSet(_totalColumns, this, totalColumns);
82
+ _classPrivateFieldSet(_stretchMode, this, stretchMode);
83
+ _classPrivateFieldSet(_stretchingColumnWidthFn, this, stretchingColumnWidthFn !== null && stretchingColumnWidthFn !== void 0 ? stretchingColumnWidthFn : _classPrivateFieldGet(_stretchingColumnWidthFn, this));
84
+ _classPrivateFieldSet(_columnWidthFn, this, columnWidthFn !== null && columnWidthFn !== void 0 ? columnWidthFn : _classPrivateFieldGet(_columnWidthFn, this));
85
+ }
86
+
87
+ /**
88
+ * Recalculate columns stretching.
89
+ *
90
+ * @param {number} totalWidth The total width of the table.
91
+ */
92
+ refreshStretching(totalWidth) {
93
+ if (_classPrivateFieldGet(_stretchMode, this).call(this) === 'none') {
94
+ return;
95
+ }
96
+ this.stretchAllRatio = 0;
97
+ this.stretchAllColumnsWidth = [];
98
+ this.needVerifyLastColumnWidth = true;
99
+ this.stretchLastWidth = 0;
100
+ _classPrivateFieldSet(_totalTargetWidth, this, totalWidth);
101
+ let sumAll = 0;
102
+ for (let i = 0; i < _classPrivateFieldGet(_totalColumns, this).call(this); i++) {
103
+ const columnWidth = this._getColumnWidth(i);
104
+ const permanentColumnWidth = _classPrivateFieldGet(_stretchingColumnWidthFn, this).call(this, undefined, i);
105
+ if (typeof permanentColumnWidth === 'number') {
106
+ totalWidth -= permanentColumnWidth;
107
+ } else {
108
+ sumAll += columnWidth;
109
+ }
110
+ }
111
+ const remainingSize = totalWidth - sumAll;
112
+ if (_classPrivateFieldGet(_stretchMode, this).call(this) === 'all' && remainingSize > 0) {
113
+ this.stretchAllRatio = totalWidth / sumAll;
114
+ this.stretchAllColumnsWidth = [];
115
+ this.needVerifyLastColumnWidth = true;
116
+ } else if (_classPrivateFieldGet(_stretchMode, this).call(this) === 'last' && totalWidth !== Infinity) {
117
+ const columnWidth = this._getColumnWidth(_classPrivateFieldGet(_totalColumns, this).call(this) - 1);
118
+ const lastColumnWidth = remainingSize + columnWidth;
119
+ this.stretchLastWidth = lastColumnWidth >= 0 ? lastColumnWidth : columnWidth;
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Get stretched column width based on stretchH (all or last) setting passed in handsontable instance.
125
+ *
126
+ * @param {number} column The visual column index.
127
+ * @param {number} baseWidth The default column width.
128
+ * @returns {number|null}
129
+ */
130
+ getStretchedColumnWidth(column, baseWidth) {
131
+ let result = null;
132
+ if (_classPrivateFieldGet(_stretchMode, this).call(this) === 'all' && this.stretchAllRatio !== 0) {
133
+ result = this._getStretchedAllColumnWidth(column, baseWidth);
134
+ } else if (_classPrivateFieldGet(_stretchMode, this).call(this) === 'last' && this.stretchLastWidth !== 0) {
135
+ result = this._getStretchedLastColumnWidth(column);
136
+ }
137
+ return result;
138
+ }
139
+
140
+ /**
141
+ * @param {number} column The visual column index.
142
+ * @param {number} baseWidth The default column width.
143
+ * @returns {number}
144
+ * @private
145
+ */
146
+ _getStretchedAllColumnWidth(column, baseWidth) {
147
+ let sumRatioWidth = 0;
148
+ if (!this.stretchAllColumnsWidth[column]) {
149
+ const stretchedWidth = Math.round(baseWidth * this.stretchAllRatio);
150
+ const newStretchedWidth = _classPrivateFieldGet(_stretchingColumnWidthFn, this).call(this, stretchedWidth, column);
151
+ if (newStretchedWidth === undefined) {
152
+ this.stretchAllColumnsWidth[column] = stretchedWidth;
153
+ } else {
154
+ this.stretchAllColumnsWidth[column] = isNaN(newStretchedWidth) ? this._getColumnWidth(column) : newStretchedWidth;
155
+ }
156
+ }
157
+ if (this.stretchAllColumnsWidth.length === _classPrivateFieldGet(_totalColumns, this).call(this) && this.needVerifyLastColumnWidth) {
158
+ this.needVerifyLastColumnWidth = false;
159
+ for (let i = 0; i < this.stretchAllColumnsWidth.length; i++) {
160
+ sumRatioWidth += this.stretchAllColumnsWidth[i];
161
+ }
162
+ if (sumRatioWidth !== _classPrivateFieldGet(_totalTargetWidth, this)) {
163
+ this.stretchAllColumnsWidth[this.stretchAllColumnsWidth.length - 1] += _classPrivateFieldGet(_totalTargetWidth, this) - sumRatioWidth;
164
+ }
165
+ }
166
+ return this.stretchAllColumnsWidth[column];
167
+ }
168
+
169
+ /**
170
+ * @param {number} column The visual column index.
171
+ * @returns {number|null}
172
+ * @private
173
+ */
174
+ _getStretchedLastColumnWidth(column) {
175
+ if (column === _classPrivateFieldGet(_totalColumns, this).call(this) - 1) {
176
+ return this.stretchLastWidth;
177
+ }
178
+ return null;
179
+ }
180
+
181
+ /**
182
+ * @param {number} column The visual column index.
183
+ * @returns {number}
184
+ * @private
185
+ */
186
+ _getColumnWidth(column) {
187
+ let width = _classPrivateFieldGet(_columnWidthFn, this).call(this, column);
188
+ if (isNaN(width)) {
189
+ width = DEFAULT_COLUMN_WIDTH;
190
+ }
191
+ return width;
192
+ }
193
+ }