handsontable 0.0.0-next-fd98d33-20241029 → 0.0.0-next-4c8e3b1-20241029

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 +7 -6
  4. package/3rdparty/walkontable/src/overlays.mjs +7 -6
  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 +0 -7
  10. package/3rdparty/walkontable/src/settings.mjs +0 -7
  11. package/3rdparty/walkontable/src/table.js +0 -24
  12. package/3rdparty/walkontable/src/table.mjs +0 -24
  13. package/3rdparty/walkontable/src/utils/column.js +0 -42
  14. package/3rdparty/walkontable/src/utils/column.mjs +0 -42
  15. package/3rdparty/walkontable/src/viewport.js +66 -87
  16. package/3rdparty/walkontable/src/viewport.mjs +67 -88
  17. package/base.js +2 -2
  18. package/base.mjs +2 -2
  19. package/core/hooks/constants.js +2 -0
  20. package/core/hooks/constants.mjs +2 -0
  21. package/core/hooks/index.d.ts +2 -2
  22. package/core.d.ts +2 -2
  23. package/core.js +6 -4
  24. package/core.mjs +6 -4
  25. package/dist/handsontable.css +2 -2
  26. package/dist/handsontable.full.css +2 -2
  27. package/dist/handsontable.full.js +2226 -1821
  28. package/dist/handsontable.full.min.css +2 -2
  29. package/dist/handsontable.full.min.js +10 -10
  30. package/dist/handsontable.js +2228 -1823
  31. package/dist/handsontable.min.css +2 -2
  32. package/dist/handsontable.min.js +10 -10
  33. package/helpers/mixed.js +1 -1
  34. package/helpers/mixed.mjs +1 -1
  35. package/index.d.ts +7 -0
  36. package/package.json +6 -1
  37. package/plugins/comments/comments.js +1 -1
  38. package/plugins/comments/comments.mjs +1 -1
  39. package/plugins/index.d.ts +3 -0
  40. package/plugins/index.js +3 -0
  41. package/plugins/index.mjs +3 -1
  42. package/plugins/manualColumnMove/manualColumnMove.js +1 -3
  43. package/plugins/manualColumnMove/manualColumnMove.mjs +1 -3
  44. package/plugins/manualColumnResize/manualColumnResize.js +24 -12
  45. package/plugins/manualColumnResize/manualColumnResize.mjs +24 -12
  46. package/plugins/stretchColumns/calculator.js +159 -0
  47. package/plugins/stretchColumns/calculator.mjs +155 -0
  48. package/plugins/stretchColumns/index.d.ts +1 -0
  49. package/plugins/stretchColumns/index.js +7 -0
  50. package/plugins/stretchColumns/index.mjs +1 -0
  51. package/plugins/stretchColumns/strategies/_base.js +85 -0
  52. package/plugins/stretchColumns/strategies/_base.mjs +81 -0
  53. package/plugins/stretchColumns/strategies/all.js +68 -0
  54. package/plugins/stretchColumns/strategies/all.mjs +64 -0
  55. package/plugins/stretchColumns/strategies/last.js +77 -0
  56. package/plugins/stretchColumns/strategies/last.mjs +73 -0
  57. package/plugins/stretchColumns/stretchColumns.d.ts +11 -0
  58. package/plugins/stretchColumns/stretchColumns.js +220 -0
  59. package/plugins/stretchColumns/stretchColumns.mjs +216 -0
  60. package/tableView.js +39 -6
  61. package/tableView.mjs +39 -6
  62. package/3rdparty/walkontable/src/utils/columnStretching.js +0 -197
  63. package/3rdparty/walkontable/src/utils/columnStretching.mjs +0 -193
@@ -0,0 +1,216 @@
1
+ import "core-js/modules/es.error.cause.js";
2
+ function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
3
+ function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
4
+ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
5
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
6
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
7
+ 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"); }
8
+ import { BasePlugin } from "../base/index.mjs";
9
+ import { StretchCalculator } from "./calculator.mjs";
10
+ export const PLUGIN_KEY = 'stretchColumns';
11
+ export const PLUGIN_PRIORITY = 155;
12
+
13
+ /* eslint-disable jsdoc/require-description-complete-sentence */
14
+ /**
15
+ * @plugin StretchColumns
16
+ * @class StretchColumns
17
+ *
18
+ * @description
19
+ * This plugin allows to set column widths based on their widest cells.
20
+ *
21
+ * By default, the plugin is declared as `'none'`, which makes it disabled (same as if it was declared as `false`).
22
+ *
23
+ * The plugin determines what happens when the declared grid width is different from the calculated sum of all column widths.
24
+ *
25
+ * ```js
26
+ * // fit the grid to the container, by stretching only the last column
27
+ * stretchH: 'last',
28
+ *
29
+ * // fit the grid to the container, by stretching all columns evenly
30
+ * stretchH: 'all',
31
+ * ```
32
+ *
33
+ * To configure this plugin see {@link Options#stretchH}.
34
+ *
35
+ * @example
36
+ *
37
+ * ::: only-for javascript
38
+ * ```js
39
+ * const hot = new Handsontable(document.getElementById('example'), {
40
+ * data: getData(),
41
+ * stretchH: 'all',
42
+ * });
43
+ * ```
44
+ * :::
45
+ *
46
+ * ::: only-for react
47
+ * ```jsx
48
+ * const hotRef = useRef(null);
49
+ *
50
+ * ...
51
+ *
52
+ * // First, let's construct Handsontable
53
+ * <HotTable
54
+ * ref={hotRef}
55
+ * data={getData()}
56
+ * stretchH={'all'}
57
+ * />
58
+ * ```
59
+ * :::
60
+ */
61
+ /* eslint-enable jsdoc/require-description-complete-sentence */
62
+ var _stretchCalculator = /*#__PURE__*/new WeakMap();
63
+ var _previousTableWidth = /*#__PURE__*/new WeakMap();
64
+ var _resizeObserver = /*#__PURE__*/new WeakMap();
65
+ var _StretchColumns_brand = /*#__PURE__*/new WeakSet();
66
+ export class StretchColumns extends BasePlugin {
67
+ constructor() {
68
+ super(...arguments);
69
+ /**
70
+ * Hook that modifies the column width - applies by the stretching logic.
71
+ *
72
+ * @param {number} width The column width.
73
+ * @param {number} column The visual column index.
74
+ * @param {string} source The source of the modification.
75
+ * @returns {number}
76
+ */
77
+ _classPrivateMethodInitSpec(this, _StretchColumns_brand);
78
+ /**
79
+ * The stretch calculator.
80
+ *
81
+ * @type {StretchCalculator}
82
+ */
83
+ _classPrivateFieldInitSpec(this, _stretchCalculator, new StretchCalculator(this.hot));
84
+ /**
85
+ * The previous width of the root element. Helps to determine if the width has changed.
86
+ *
87
+ * @type {number | null}
88
+ */
89
+ _classPrivateFieldInitSpec(this, _previousTableWidth, null);
90
+ /**
91
+ * It observes the root element to detect changes in its width, and if detected, then it triggers
92
+ * the table dimension calculations. In a situation where the browser's vertical scrollbar
93
+ * appears - caused by some external UI element, the observer triggers the render.
94
+ *
95
+ * @type {ResizeObserver}
96
+ */
97
+ _classPrivateFieldInitSpec(this, _resizeObserver, new ResizeObserver(entries => {
98
+ requestAnimationFrame(() => {
99
+ var _this$hot;
100
+ if (!((_this$hot = this.hot) !== null && _this$hot !== void 0 && _this$hot.view.isHorizontallyScrollableByWindow())) {
101
+ return;
102
+ }
103
+ entries.forEach(_ref => {
104
+ let {
105
+ contentRect
106
+ } = _ref;
107
+ if (_classPrivateFieldGet(_previousTableWidth, this) !== null && _classPrivateFieldGet(_previousTableWidth, this) !== contentRect.width) {
108
+ this.hot.refreshDimensions();
109
+ this.hot.view.adjustElementsSize();
110
+ }
111
+ _classPrivateFieldSet(_previousTableWidth, this, contentRect.width);
112
+ });
113
+ });
114
+ }));
115
+ }
116
+ static get PLUGIN_KEY() {
117
+ return PLUGIN_KEY;
118
+ }
119
+ static get PLUGIN_PRIORITY() {
120
+ return PLUGIN_PRIORITY;
121
+ }
122
+ static get SETTING_KEYS() {
123
+ return true;
124
+ }
125
+ /**
126
+ * Checks if the plugin is enabled in the handsontable settings. This method is executed in {@link Hooks#beforeInit}
127
+ * hook and if it returns `true` then the {@link #enablePlugin} method is called.
128
+ *
129
+ * @returns {boolean}
130
+ */
131
+ isEnabled() {
132
+ return ['all', 'last'].includes(this.hot.getSettings().stretchH);
133
+ }
134
+
135
+ /**
136
+ * Enables the plugin functionality for this Handsontable instance.
137
+ */
138
+ enablePlugin() {
139
+ var _this = this;
140
+ if (this.enabled) {
141
+ return;
142
+ }
143
+ _classPrivateFieldGet(_stretchCalculator, this).useStrategy(this.hot.getSettings().stretchH);
144
+ _classPrivateFieldGet(_resizeObserver, this).observe(this.hot.rootElement);
145
+ this.addHook('beforeRender', function () {
146
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
147
+ args[_key] = arguments[_key];
148
+ }
149
+ return _assertClassBrand(_StretchColumns_brand, _this, _onBeforeRender).call(_this, ...args);
150
+ });
151
+ this.addHook('modifyColWidth', function () {
152
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
153
+ args[_key2] = arguments[_key2];
154
+ }
155
+ return _assertClassBrand(_StretchColumns_brand, _this, _onModifyColWidth).call(_this, ...args);
156
+ }, 10);
157
+ super.enablePlugin();
158
+ }
159
+
160
+ /**
161
+ * Updates the plugin's state. This method is executed when {@link Core#updateSettings} is invoked.
162
+ */
163
+ updatePlugin() {
164
+ _classPrivateFieldGet(_stretchCalculator, this).useStrategy(this.hot.getSettings().stretchH);
165
+ super.updatePlugin();
166
+ }
167
+
168
+ /**
169
+ * Disables the plugin functionality for this Handsontable instance.
170
+ */
171
+ disablePlugin() {
172
+ super.disablePlugin();
173
+ _classPrivateFieldGet(_resizeObserver, this).unobserve(this.hot.rootElement);
174
+ }
175
+
176
+ /**
177
+ * Gets the calculated column width based on the stretching
178
+ * strategy defined by {@link Options#stretchH} option.
179
+ *
180
+ * @param {number} columnVisualIndex The visual index of the column.
181
+ * @returns {number | null}
182
+ */
183
+ getColumnWidth(columnVisualIndex) {
184
+ return _classPrivateFieldGet(_stretchCalculator, this).getStretchedWidth(columnVisualIndex);
185
+ }
186
+ /**
187
+ * Destroys the plugin instance.
188
+ */
189
+ destroy() {
190
+ _classPrivateFieldGet(_resizeObserver, this).disconnect();
191
+ _classPrivateFieldSet(_resizeObserver, this, null);
192
+ _classPrivateFieldSet(_stretchCalculator, this, null);
193
+ super.destroy();
194
+ }
195
+ }
196
+ function _onModifyColWidth(width, column, source) {
197
+ if (source === this.pluginName) {
198
+ return;
199
+ }
200
+ const newWidth = this.getColumnWidth(column);
201
+ if (typeof newWidth === 'number') {
202
+ return newWidth;
203
+ }
204
+ return width;
205
+ }
206
+ /**
207
+ * On each before render the plugin recalculates the column widths
208
+ * based on the chosen stretching strategy.
209
+ *
210
+ * @param {boolean} fullRender If `true` then the full render is in progress.
211
+ */
212
+ function _onBeforeRender(fullRender) {
213
+ if (fullRender) {
214
+ _classPrivateFieldGet(_stretchCalculator, this).refreshStretching();
215
+ }
216
+ }
package/tableView.js CHANGED
@@ -158,7 +158,7 @@ class TableView {
158
158
  this.hot.runHooks('beforeRender', this.hot.forceFullRender);
159
159
  if (this.postponedAdjustElementsSize) {
160
160
  this.postponedAdjustElementsSize = false;
161
- this.adjustElementsSize(true);
161
+ this.adjustElementsSize();
162
162
  }
163
163
  this._wt.draw(!this.hot.forceFullRender);
164
164
  this.hot.runHooks('afterRender', this.hot.forceFullRender);
@@ -613,7 +613,6 @@ class TableView {
613
613
  isDataViewInstance: () => (0, _rootInstance.isRootInstance)(this.hot),
614
614
  preventOverflow: () => this.settings.preventOverflow,
615
615
  preventWheel: () => this.settings.preventWheel,
616
- stretchH: () => this.settings.stretchH,
617
616
  viewportColumnRenderingThreshold: () => this.settings.viewportColumnRenderingThreshold,
618
617
  viewportRowRenderingThreshold: () => this.settings.viewportRowRenderingThreshold,
619
618
  data: (renderableRow, renderableColumn) => {
@@ -912,10 +911,6 @@ class TableView {
912
911
  },
913
912
  onBeforeTouchScroll: () => this.hot.runHooks('beforeTouchScroll'),
914
913
  onAfterMomentumScroll: () => this.hot.runHooks('afterMomentumScroll'),
915
- onBeforeStretchingColumnWidth: (stretchedWidth, renderedColumnIndex) => {
916
- const visualColumnIndex = this.hot.columnIndexMapper.getVisualFromRenderableIndex(renderedColumnIndex);
917
- return this.hot.runHooks('beforeStretchingColumnWidth', stretchedWidth, visualColumnIndex);
918
- },
919
914
  onModifyRowHeaderWidth: rowHeaderWidth => this.hot.runHooks('modifyRowHeaderWidth', rowHeaderWidth),
920
915
  onModifyGetCellCoords: (renderableRowIndex, renderableColumnIndex, topmost, source) => {
921
916
  const rowMapper = this.hot.rowIndexMapper;
@@ -1539,6 +1534,44 @@ class TableView {
1539
1534
  getTableHeight() {
1540
1535
  return this._wt.wtTable.getHeight();
1541
1536
  }
1537
+
1538
+ /**
1539
+ * Gets the row header width. If there are multiple row headers, the width of
1540
+ * the sum of all of them is returned.
1541
+ *
1542
+ * @returns {number}
1543
+ */
1544
+ getRowHeaderWidth() {
1545
+ return this._wt.wtViewport.getRowHeaderWidth();
1546
+ }
1547
+
1548
+ /**
1549
+ * Gets the column header height. If there are multiple column headers, the height
1550
+ * of the sum of all of them is returned.
1551
+ *
1552
+ * @returns {number}
1553
+ */
1554
+ getColumnHeaderHeight() {
1555
+ return this._wt.wtViewport.getColumnHeaderHeight();
1556
+ }
1557
+
1558
+ /**
1559
+ * Checks if the table uses the window as a viewport and if there is a vertical scrollbar.
1560
+ *
1561
+ * @returns {boolean}
1562
+ */
1563
+ isVerticallyScrollableByWindow() {
1564
+ return this._wt.wtViewport.isVerticallyScrollableByWindow();
1565
+ }
1566
+
1567
+ /**
1568
+ * Checks if the table uses the window as a viewport and if there is a horizontal scrollbar.
1569
+ *
1570
+ * @returns {boolean}
1571
+ */
1572
+ isHorizontallyScrollableByWindow() {
1573
+ return this._wt.wtViewport.isHorizontallyScrollableByWindow();
1574
+ }
1542
1575
  /**
1543
1576
  * Destroys internal WalkOnTable's instance. Detaches all of the bonded listeners.
1544
1577
  *
package/tableView.mjs CHANGED
@@ -154,7 +154,7 @@ class TableView {
154
154
  this.hot.runHooks('beforeRender', this.hot.forceFullRender);
155
155
  if (this.postponedAdjustElementsSize) {
156
156
  this.postponedAdjustElementsSize = false;
157
- this.adjustElementsSize(true);
157
+ this.adjustElementsSize();
158
158
  }
159
159
  this._wt.draw(!this.hot.forceFullRender);
160
160
  this.hot.runHooks('afterRender', this.hot.forceFullRender);
@@ -609,7 +609,6 @@ class TableView {
609
609
  isDataViewInstance: () => isRootInstance(this.hot),
610
610
  preventOverflow: () => this.settings.preventOverflow,
611
611
  preventWheel: () => this.settings.preventWheel,
612
- stretchH: () => this.settings.stretchH,
613
612
  viewportColumnRenderingThreshold: () => this.settings.viewportColumnRenderingThreshold,
614
613
  viewportRowRenderingThreshold: () => this.settings.viewportRowRenderingThreshold,
615
614
  data: (renderableRow, renderableColumn) => {
@@ -908,10 +907,6 @@ class TableView {
908
907
  },
909
908
  onBeforeTouchScroll: () => this.hot.runHooks('beforeTouchScroll'),
910
909
  onAfterMomentumScroll: () => this.hot.runHooks('afterMomentumScroll'),
911
- onBeforeStretchingColumnWidth: (stretchedWidth, renderedColumnIndex) => {
912
- const visualColumnIndex = this.hot.columnIndexMapper.getVisualFromRenderableIndex(renderedColumnIndex);
913
- return this.hot.runHooks('beforeStretchingColumnWidth', stretchedWidth, visualColumnIndex);
914
- },
915
910
  onModifyRowHeaderWidth: rowHeaderWidth => this.hot.runHooks('modifyRowHeaderWidth', rowHeaderWidth),
916
911
  onModifyGetCellCoords: (renderableRowIndex, renderableColumnIndex, topmost, source) => {
917
912
  const rowMapper = this.hot.rowIndexMapper;
@@ -1535,6 +1530,44 @@ class TableView {
1535
1530
  getTableHeight() {
1536
1531
  return this._wt.wtTable.getHeight();
1537
1532
  }
1533
+
1534
+ /**
1535
+ * Gets the row header width. If there are multiple row headers, the width of
1536
+ * the sum of all of them is returned.
1537
+ *
1538
+ * @returns {number}
1539
+ */
1540
+ getRowHeaderWidth() {
1541
+ return this._wt.wtViewport.getRowHeaderWidth();
1542
+ }
1543
+
1544
+ /**
1545
+ * Gets the column header height. If there are multiple column headers, the height
1546
+ * of the sum of all of them is returned.
1547
+ *
1548
+ * @returns {number}
1549
+ */
1550
+ getColumnHeaderHeight() {
1551
+ return this._wt.wtViewport.getColumnHeaderHeight();
1552
+ }
1553
+
1554
+ /**
1555
+ * Checks if the table uses the window as a viewport and if there is a vertical scrollbar.
1556
+ *
1557
+ * @returns {boolean}
1558
+ */
1559
+ isVerticallyScrollableByWindow() {
1560
+ return this._wt.wtViewport.isVerticallyScrollableByWindow();
1561
+ }
1562
+
1563
+ /**
1564
+ * Checks if the table uses the window as a viewport and if there is a horizontal scrollbar.
1565
+ *
1566
+ * @returns {boolean}
1567
+ */
1568
+ isHorizontallyScrollableByWindow() {
1569
+ return this._wt.wtViewport.isHorizontallyScrollableByWindow();
1570
+ }
1538
1571
  /**
1539
1572
  * Destroys internal WalkOnTable's instance. Detaches all of the bonded listeners.
1540
1573
  *
@@ -1,197 +0,0 @@
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;