handsontable 0.0.0-next-662a118-20241017 → 0.0.0-next-802f59c-20241024

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 +2217 -1821
  28. package/dist/handsontable.full.min.css +2 -2
  29. package/dist/handsontable.full.min.js +10 -10
  30. package/dist/handsontable.js +2219 -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 +211 -0
  59. package/plugins/stretchColumns/stretchColumns.mjs +207 -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,85 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ require("core-js/modules/es.error.cause.js");
5
+ 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
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
7
+ 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); }
8
+ /**
9
+ * @typedef StretchStrategyCalcArgs
10
+ * @property {number} viewportWidth The width of the viewport.
11
+ */
12
+ /**
13
+ * The base strategy stretching strategy to extend from.
14
+ *
15
+ * @private
16
+ * @class StretchStrategy
17
+ */
18
+ class StretchStrategy {
19
+ constructor(overwriteColumnWidthFn) {
20
+ /**
21
+ * The width of the viewport.
22
+ *
23
+ * @type {number}
24
+ */
25
+ _defineProperty(this, "viewportWidth", void 0);
26
+ /**
27
+ * The function to overwrite the column width.
28
+ *
29
+ * @type {function(number, number): number | undefined}
30
+ */
31
+ _defineProperty(this, "overwriteColumnWidthFn", void 0);
32
+ /**
33
+ * The map that stores the base column widths.
34
+ *
35
+ * @type {Map<number, number>}
36
+ */
37
+ _defineProperty(this, "baseWidths", new Map());
38
+ /**
39
+ * The map that stores the calculated, stretched column widths.
40
+ *
41
+ * @type {Map<number, number>}
42
+ */
43
+ _defineProperty(this, "stretchedWidths", new Map());
44
+ this.overwriteColumnWidthFn = overwriteColumnWidthFn;
45
+ }
46
+
47
+ /**
48
+ * Prepares the strategy for the calculation.
49
+ *
50
+ * @param {StretchStrategyCalcArgs} calcArgs The calculation arguments.
51
+ */
52
+ prepare(_ref) {
53
+ let {
54
+ viewportWidth
55
+ } = _ref;
56
+ this.viewportWidth = viewportWidth;
57
+ this.baseWidths.clear();
58
+ this.stretchedWidths.clear();
59
+ }
60
+
61
+ /**
62
+ * Sets the base widths of the columns with which the strategy will work with.
63
+ *
64
+ * @param {number} columnVisualIndex The visual index of the column.
65
+ * @param {number} columnWidth The width of the column.
66
+ */
67
+ setColumnBaseWidth(columnVisualIndex, columnWidth) {
68
+ this.baseWidths.set(columnVisualIndex, columnWidth);
69
+ }
70
+
71
+ /**
72
+ * Calculates the width of the column.
73
+ */
74
+ calculate() {}
75
+
76
+ /**
77
+ * Gets the calculated stretched column widths.
78
+ *
79
+ * @returns {Array<number[]>}
80
+ */
81
+ getWidths() {
82
+ return Array.from(this.stretchedWidths);
83
+ }
84
+ }
85
+ exports.StretchStrategy = StretchStrategy;
@@ -0,0 +1,81 @@
1
+ import "core-js/modules/es.error.cause.js";
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
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
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
+ /**
6
+ * @typedef StretchStrategyCalcArgs
7
+ * @property {number} viewportWidth The width of the viewport.
8
+ */
9
+ /**
10
+ * The base strategy stretching strategy to extend from.
11
+ *
12
+ * @private
13
+ * @class StretchStrategy
14
+ */
15
+ export class StretchStrategy {
16
+ constructor(overwriteColumnWidthFn) {
17
+ /**
18
+ * The width of the viewport.
19
+ *
20
+ * @type {number}
21
+ */
22
+ _defineProperty(this, "viewportWidth", void 0);
23
+ /**
24
+ * The function to overwrite the column width.
25
+ *
26
+ * @type {function(number, number): number | undefined}
27
+ */
28
+ _defineProperty(this, "overwriteColumnWidthFn", void 0);
29
+ /**
30
+ * The map that stores the base column widths.
31
+ *
32
+ * @type {Map<number, number>}
33
+ */
34
+ _defineProperty(this, "baseWidths", new Map());
35
+ /**
36
+ * The map that stores the calculated, stretched column widths.
37
+ *
38
+ * @type {Map<number, number>}
39
+ */
40
+ _defineProperty(this, "stretchedWidths", new Map());
41
+ this.overwriteColumnWidthFn = overwriteColumnWidthFn;
42
+ }
43
+
44
+ /**
45
+ * Prepares the strategy for the calculation.
46
+ *
47
+ * @param {StretchStrategyCalcArgs} calcArgs The calculation arguments.
48
+ */
49
+ prepare(_ref) {
50
+ let {
51
+ viewportWidth
52
+ } = _ref;
53
+ this.viewportWidth = viewportWidth;
54
+ this.baseWidths.clear();
55
+ this.stretchedWidths.clear();
56
+ }
57
+
58
+ /**
59
+ * Sets the base widths of the columns with which the strategy will work with.
60
+ *
61
+ * @param {number} columnVisualIndex The visual index of the column.
62
+ * @param {number} columnWidth The width of the column.
63
+ */
64
+ setColumnBaseWidth(columnVisualIndex, columnWidth) {
65
+ this.baseWidths.set(columnVisualIndex, columnWidth);
66
+ }
67
+
68
+ /**
69
+ * Calculates the width of the column.
70
+ */
71
+ calculate() {}
72
+
73
+ /**
74
+ * Gets the calculated stretched column widths.
75
+ *
76
+ * @returns {Array<number[]>}
77
+ */
78
+ getWidths() {
79
+ return Array.from(this.stretchedWidths);
80
+ }
81
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ require("core-js/modules/es.array.push.js");
5
+ var _src = require("../../../3rdparty/walkontable/src");
6
+ var _base = require("./_base");
7
+ /**
8
+ * The strategy calculates the column widths by stretching all columns evenly.
9
+ *
10
+ * @private
11
+ * @class StretchAllStrategy
12
+ */
13
+ class StretchAllStrategy extends _base.StretchStrategy {
14
+ /**
15
+ * Calculates the columns widths.
16
+ */
17
+ calculate() {
18
+ const allColumnsWidth = Array.from(this.baseWidths).reduce((sum, _ref) => {
19
+ let [, width] = _ref;
20
+ return sum + width;
21
+ }, 0);
22
+ const remainingViewportWidth = this.viewportWidth - allColumnsWidth;
23
+ if (remainingViewportWidth < 0) {
24
+ this.stretchedWidths.clear();
25
+ return;
26
+ }
27
+ const initialStretchRatio = this.viewportWidth / allColumnsWidth;
28
+ const stretchedWidths = [];
29
+ const fixedColumns = [];
30
+ let viewportWidth = this.viewportWidth;
31
+ let allStretchedColumnsWidth = 0;
32
+ this.baseWidths.forEach((columnWidth, columnVisualIndex) => {
33
+ const stretchedWidth = Math.round(columnWidth * initialStretchRatio);
34
+ const finalWidth = this.overwriteColumnWidthFn(stretchedWidth, columnVisualIndex);
35
+ if (stretchedWidth === finalWidth && stretchedWidth >= _src.DEFAULT_COLUMN_WIDTH) {
36
+ stretchedWidths.push([columnVisualIndex, finalWidth]);
37
+ allStretchedColumnsWidth += finalWidth;
38
+ } else if (stretchedWidth !== finalWidth) {
39
+ stretchedWidths.push([columnVisualIndex, finalWidth]);
40
+ fixedColumns.push(columnVisualIndex);
41
+ viewportWidth -= finalWidth;
42
+ }
43
+ });
44
+ if (viewportWidth <= _src.DEFAULT_COLUMN_WIDTH) {
45
+ this.stretchedWidths.clear();
46
+ return;
47
+ }
48
+ const finalStretchRatio = viewportWidth / allStretchedColumnsWidth;
49
+ let lastColumnIndex = -1;
50
+ let sumColumnsWithoutLastOne = 0;
51
+ stretchedWidths.forEach((_ref2, index) => {
52
+ let [columnVisualIndex, columnWidth] = _ref2;
53
+ let newWidth = columnWidth;
54
+ if (!fixedColumns.includes(columnVisualIndex)) {
55
+ newWidth = Math.round(columnWidth * finalStretchRatio);
56
+ }
57
+ this.stretchedWidths.set(columnVisualIndex, newWidth);
58
+ lastColumnIndex = columnVisualIndex;
59
+ if (index < stretchedWidths.length - 1) {
60
+ sumColumnsWithoutLastOne += newWidth;
61
+ }
62
+ });
63
+ if (this.stretchedWidths.size > 1) {
64
+ this.stretchedWidths.set(lastColumnIndex, Math.round(this.viewportWidth - sumColumnsWithoutLastOne));
65
+ }
66
+ }
67
+ }
68
+ exports.StretchAllStrategy = StretchAllStrategy;
@@ -0,0 +1,64 @@
1
+ import "core-js/modules/es.array.push.js";
2
+ import { DEFAULT_COLUMN_WIDTH } from "../../../3rdparty/walkontable/src/index.mjs";
3
+ import { StretchStrategy } from "./_base.mjs";
4
+ /**
5
+ * The strategy calculates the column widths by stretching all columns evenly.
6
+ *
7
+ * @private
8
+ * @class StretchAllStrategy
9
+ */
10
+ export class StretchAllStrategy extends StretchStrategy {
11
+ /**
12
+ * Calculates the columns widths.
13
+ */
14
+ calculate() {
15
+ const allColumnsWidth = Array.from(this.baseWidths).reduce((sum, _ref) => {
16
+ let [, width] = _ref;
17
+ return sum + width;
18
+ }, 0);
19
+ const remainingViewportWidth = this.viewportWidth - allColumnsWidth;
20
+ if (remainingViewportWidth < 0) {
21
+ this.stretchedWidths.clear();
22
+ return;
23
+ }
24
+ const initialStretchRatio = this.viewportWidth / allColumnsWidth;
25
+ const stretchedWidths = [];
26
+ const fixedColumns = [];
27
+ let viewportWidth = this.viewportWidth;
28
+ let allStretchedColumnsWidth = 0;
29
+ this.baseWidths.forEach((columnWidth, columnVisualIndex) => {
30
+ const stretchedWidth = Math.round(columnWidth * initialStretchRatio);
31
+ const finalWidth = this.overwriteColumnWidthFn(stretchedWidth, columnVisualIndex);
32
+ if (stretchedWidth === finalWidth && stretchedWidth >= DEFAULT_COLUMN_WIDTH) {
33
+ stretchedWidths.push([columnVisualIndex, finalWidth]);
34
+ allStretchedColumnsWidth += finalWidth;
35
+ } else if (stretchedWidth !== finalWidth) {
36
+ stretchedWidths.push([columnVisualIndex, finalWidth]);
37
+ fixedColumns.push(columnVisualIndex);
38
+ viewportWidth -= finalWidth;
39
+ }
40
+ });
41
+ if (viewportWidth <= DEFAULT_COLUMN_WIDTH) {
42
+ this.stretchedWidths.clear();
43
+ return;
44
+ }
45
+ const finalStretchRatio = viewportWidth / allStretchedColumnsWidth;
46
+ let lastColumnIndex = -1;
47
+ let sumColumnsWithoutLastOne = 0;
48
+ stretchedWidths.forEach((_ref2, index) => {
49
+ let [columnVisualIndex, columnWidth] = _ref2;
50
+ let newWidth = columnWidth;
51
+ if (!fixedColumns.includes(columnVisualIndex)) {
52
+ newWidth = Math.round(columnWidth * finalStretchRatio);
53
+ }
54
+ this.stretchedWidths.set(columnVisualIndex, newWidth);
55
+ lastColumnIndex = columnVisualIndex;
56
+ if (index < stretchedWidths.length - 1) {
57
+ sumColumnsWithoutLastOne += newWidth;
58
+ }
59
+ });
60
+ if (this.stretchedWidths.size > 1) {
61
+ this.stretchedWidths.set(lastColumnIndex, Math.round(this.viewportWidth - sumColumnsWithoutLastOne));
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ require("core-js/modules/es.error.cause.js");
5
+ var _base = require("./_base");
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 _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
9
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
10
+ 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"); }
11
+ /**
12
+ * @typedef StretchStrategyCalcArgs
13
+ * @property {number} viewportWidth The width of the viewport.
14
+ */
15
+ /**
16
+ * The strategy calculates only the last column widths to fill the viewport.
17
+ *
18
+ * @private
19
+ * @class StretchLastStrategy
20
+ */
21
+ var _lastColumnWidth = /*#__PURE__*/new WeakMap();
22
+ var _lastColumnIndex = /*#__PURE__*/new WeakMap();
23
+ class StretchLastStrategy extends _base.StretchStrategy {
24
+ constructor() {
25
+ super(...arguments);
26
+ /**
27
+ * The width of the last calculated column.
28
+ *
29
+ * @type {number}
30
+ */
31
+ _classPrivateFieldInitSpec(this, _lastColumnWidth, 0);
32
+ /**
33
+ * The index of the last calculated column.
34
+ *
35
+ * @type {number}
36
+ */
37
+ _classPrivateFieldInitSpec(this, _lastColumnIndex, -1);
38
+ }
39
+ /**
40
+ * Prepares the strategy for the calculation.
41
+ *
42
+ * @param {StretchStrategyCalcArgs} calcArgs The calculation arguments.
43
+ */
44
+ prepare(calcArgs) {
45
+ super.prepare(calcArgs);
46
+ _classPrivateFieldSet(_lastColumnWidth, this, 0);
47
+ _classPrivateFieldSet(_lastColumnIndex, this, -1);
48
+ }
49
+
50
+ /**
51
+ * Sets the base widths of the columns with which the strategy will work with.
52
+ *
53
+ * @param {number} columnVisualIndex The visual index of the column.
54
+ * @param {number} columnWidth The width of the column.
55
+ */
56
+ setColumnBaseWidth(columnVisualIndex, columnWidth) {
57
+ super.setColumnBaseWidth(columnVisualIndex, columnWidth);
58
+ _classPrivateFieldSet(_lastColumnIndex, this, columnVisualIndex);
59
+ _classPrivateFieldSet(_lastColumnWidth, this, columnWidth);
60
+ }
61
+
62
+ /**
63
+ * Calculates the columns widths.
64
+ */
65
+ calculate() {
66
+ if (_classPrivateFieldGet(_lastColumnIndex, this) === -1) {
67
+ return;
68
+ }
69
+ const allColumnsWidth = Array.from(this.baseWidths).reduce((sum, _ref) => {
70
+ let [, width] = _ref;
71
+ return sum + width;
72
+ }, 0);
73
+ const lastColumnWidth = Math.max(this.viewportWidth - allColumnsWidth + _classPrivateFieldGet(_lastColumnWidth, this), 0);
74
+ this.stretchedWidths.set(_classPrivateFieldGet(_lastColumnIndex, this), lastColumnWidth);
75
+ }
76
+ }
77
+ exports.StretchLastStrategy = StretchLastStrategy;
@@ -0,0 +1,73 @@
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 _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
5
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
6
+ 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"); }
7
+ import { StretchStrategy } from "./_base.mjs";
8
+ /**
9
+ * @typedef StretchStrategyCalcArgs
10
+ * @property {number} viewportWidth The width of the viewport.
11
+ */
12
+ /**
13
+ * The strategy calculates only the last column widths to fill the viewport.
14
+ *
15
+ * @private
16
+ * @class StretchLastStrategy
17
+ */
18
+ var _lastColumnWidth = /*#__PURE__*/new WeakMap();
19
+ var _lastColumnIndex = /*#__PURE__*/new WeakMap();
20
+ export class StretchLastStrategy extends StretchStrategy {
21
+ constructor() {
22
+ super(...arguments);
23
+ /**
24
+ * The width of the last calculated column.
25
+ *
26
+ * @type {number}
27
+ */
28
+ _classPrivateFieldInitSpec(this, _lastColumnWidth, 0);
29
+ /**
30
+ * The index of the last calculated column.
31
+ *
32
+ * @type {number}
33
+ */
34
+ _classPrivateFieldInitSpec(this, _lastColumnIndex, -1);
35
+ }
36
+ /**
37
+ * Prepares the strategy for the calculation.
38
+ *
39
+ * @param {StretchStrategyCalcArgs} calcArgs The calculation arguments.
40
+ */
41
+ prepare(calcArgs) {
42
+ super.prepare(calcArgs);
43
+ _classPrivateFieldSet(_lastColumnWidth, this, 0);
44
+ _classPrivateFieldSet(_lastColumnIndex, this, -1);
45
+ }
46
+
47
+ /**
48
+ * Sets the base widths of the columns with which the strategy will work with.
49
+ *
50
+ * @param {number} columnVisualIndex The visual index of the column.
51
+ * @param {number} columnWidth The width of the column.
52
+ */
53
+ setColumnBaseWidth(columnVisualIndex, columnWidth) {
54
+ super.setColumnBaseWidth(columnVisualIndex, columnWidth);
55
+ _classPrivateFieldSet(_lastColumnIndex, this, columnVisualIndex);
56
+ _classPrivateFieldSet(_lastColumnWidth, this, columnWidth);
57
+ }
58
+
59
+ /**
60
+ * Calculates the columns widths.
61
+ */
62
+ calculate() {
63
+ if (_classPrivateFieldGet(_lastColumnIndex, this) === -1) {
64
+ return;
65
+ }
66
+ const allColumnsWidth = Array.from(this.baseWidths).reduce((sum, _ref) => {
67
+ let [, width] = _ref;
68
+ return sum + width;
69
+ }, 0);
70
+ const lastColumnWidth = Math.max(this.viewportWidth - allColumnsWidth + _classPrivateFieldGet(_lastColumnWidth, this), 0);
71
+ this.stretchedWidths.set(_classPrivateFieldGet(_lastColumnIndex, this), lastColumnWidth);
72
+ }
73
+ }
@@ -0,0 +1,11 @@
1
+ import Core from '../../core';
2
+ import { BasePlugin } from '../base';
3
+
4
+ export type Settings = 'all' | 'last' | 'none';
5
+
6
+ export class StretchColumns extends BasePlugin {
7
+ constructor(hotInstance: Core);
8
+
9
+ isEnabled(): boolean;
10
+ getColumnWidth(columnVisualIndex: number): number | null;
11
+ }
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ require("core-js/modules/es.error.cause.js");
5
+ var _base = require("../base");
6
+ var _calculator = require("./calculator");
7
+ function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
8
+ function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
9
+ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
10
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
11
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
12
+ 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"); }
13
+ const PLUGIN_KEY = exports.PLUGIN_KEY = 'stretchColumns';
14
+ const PLUGIN_PRIORITY = exports.PLUGIN_PRIORITY = 155;
15
+
16
+ /* eslint-disable jsdoc/require-description-complete-sentence */
17
+ /**
18
+ * @plugin StretchColumns
19
+ * @class StretchColumns
20
+ *
21
+ * @description
22
+ * This plugin allows to set column widths based on their widest cells.
23
+ *
24
+ * By default, the plugin is declared as `'none'`, which makes it disabled (same as if it was declared as `false`).
25
+ *
26
+ * The plugin determines what happens when the declared grid width is different from the calculated sum of all column widths.
27
+ *
28
+ * ```js
29
+ * // fit the grid to the container, by stretching only the last column
30
+ * stretchH: 'last',
31
+ *
32
+ * // fit the grid to the container, by stretching all columns evenly
33
+ * stretchH: 'all',
34
+ * ```
35
+ *
36
+ * To configure this plugin see {@link Options#stretchH}.
37
+ *
38
+ * @example
39
+ *
40
+ * ::: only-for javascript
41
+ * ```js
42
+ * const hot = new Handsontable(document.getElementById('example'), {
43
+ * data: getData(),
44
+ * stretchH: 'all',
45
+ * });
46
+ * ```
47
+ * :::
48
+ *
49
+ * ::: only-for react
50
+ * ```jsx
51
+ * const hotRef = useRef(null);
52
+ *
53
+ * ...
54
+ *
55
+ * // First, let's construct Handsontable
56
+ * <HotTable
57
+ * ref={hotRef}
58
+ * data={getData()}
59
+ * stretchH={'all'}
60
+ * />
61
+ * ```
62
+ * :::
63
+ */
64
+ /* eslint-enable jsdoc/require-description-complete-sentence */
65
+ var _stretchCalculator = /*#__PURE__*/new WeakMap();
66
+ var _previousTableWidth = /*#__PURE__*/new WeakMap();
67
+ var _resizeObserver = /*#__PURE__*/new WeakMap();
68
+ var _StretchColumns_brand = /*#__PURE__*/new WeakSet();
69
+ class StretchColumns extends _base.BasePlugin {
70
+ constructor() {
71
+ super(...arguments);
72
+ /**
73
+ * Hook that modifies the column width - applies by the stretching logic.
74
+ *
75
+ * @param {number} width The column width.
76
+ * @param {number} column The visual column index.
77
+ * @param {string} source The source of the modification.
78
+ * @returns {number}
79
+ */
80
+ _classPrivateMethodInitSpec(this, _StretchColumns_brand);
81
+ /**
82
+ * The stretch calculator.
83
+ *
84
+ * @type {StretchCalculator}
85
+ */
86
+ _classPrivateFieldInitSpec(this, _stretchCalculator, new _calculator.StretchCalculator(this.hot));
87
+ /**
88
+ * The previous width of the root element. Helps to determine if the width has changed.
89
+ *
90
+ * @type {number | null}
91
+ */
92
+ _classPrivateFieldInitSpec(this, _previousTableWidth, null);
93
+ /**
94
+ * It observes the root element to detect changes in its width, and if detected, then it triggers
95
+ * the table dimension calculations. In a situation where the browser's vertical scrollbar
96
+ * appears - caused by some external UI element, the observer triggers the render.
97
+ *
98
+ * @type {ResizeObserver}
99
+ */
100
+ _classPrivateFieldInitSpec(this, _resizeObserver, new ResizeObserver(entries => {
101
+ requestAnimationFrame(() => {
102
+ var _this$hot;
103
+ if (!((_this$hot = this.hot) !== null && _this$hot !== void 0 && _this$hot.view.isHorizontallyScrollableByWindow())) {
104
+ return;
105
+ }
106
+ entries.forEach(_ref => {
107
+ let {
108
+ contentRect
109
+ } = _ref;
110
+ if (_classPrivateFieldGet(_previousTableWidth, this) !== null && _classPrivateFieldGet(_previousTableWidth, this) !== contentRect.width) {
111
+ this.hot.refreshDimensions();
112
+ this.hot.view.adjustElementsSize();
113
+ }
114
+ _classPrivateFieldSet(_previousTableWidth, this, contentRect.width);
115
+ });
116
+ });
117
+ }));
118
+ }
119
+ static get PLUGIN_KEY() {
120
+ return PLUGIN_KEY;
121
+ }
122
+ static get PLUGIN_PRIORITY() {
123
+ return PLUGIN_PRIORITY;
124
+ }
125
+ static get SETTING_KEYS() {
126
+ return true;
127
+ }
128
+ /**
129
+ * Checks if the plugin is enabled in the handsontable settings. This method is executed in {@link Hooks#beforeInit}
130
+ * hook and if it returns `true` then the {@link #enablePlugin} method is called.
131
+ *
132
+ * @returns {boolean}
133
+ */
134
+ isEnabled() {
135
+ return ['all', 'last'].includes(this.hot.getSettings().stretchH);
136
+ }
137
+
138
+ /**
139
+ * Enables the plugin functionality for this Handsontable instance.
140
+ */
141
+ enablePlugin() {
142
+ var _this = this;
143
+ if (this.enabled) {
144
+ return;
145
+ }
146
+ _classPrivateFieldGet(_stretchCalculator, this).useStrategy(this.hot.getSettings().stretchH);
147
+ _classPrivateFieldGet(_resizeObserver, this).observe(this.hot.rootElement);
148
+ this.addHook('beforeRender', () => _assertClassBrand(_StretchColumns_brand, this, _onBeforeRender).call(this));
149
+ this.addHook('modifyColWidth', function () {
150
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
151
+ args[_key] = arguments[_key];
152
+ }
153
+ return _assertClassBrand(_StretchColumns_brand, _this, _onModifyColWidth).call(_this, ...args);
154
+ }, 10);
155
+ super.enablePlugin();
156
+ }
157
+
158
+ /**
159
+ * Updates the plugin's state. This method is executed when {@link Core#updateSettings} is invoked.
160
+ */
161
+ updatePlugin() {
162
+ _classPrivateFieldGet(_stretchCalculator, this).useStrategy(this.hot.getSettings().stretchH);
163
+ super.updatePlugin();
164
+ }
165
+
166
+ /**
167
+ * Disables the plugin functionality for this Handsontable instance.
168
+ */
169
+ disablePlugin() {
170
+ super.disablePlugin();
171
+ _classPrivateFieldGet(_resizeObserver, this).unobserve(this.hot.rootElement);
172
+ }
173
+
174
+ /**
175
+ * Gets the calculated column width based on the stretching
176
+ * strategy defined by {@link Options#stretchH} option.
177
+ *
178
+ * @param {number} columnVisualIndex The visual index of the column.
179
+ * @returns {number | null}
180
+ */
181
+ getColumnWidth(columnVisualIndex) {
182
+ return _classPrivateFieldGet(_stretchCalculator, this).getStretchedWidth(columnVisualIndex);
183
+ }
184
+ /**
185
+ * Destroys the plugin instance.
186
+ */
187
+ destroy() {
188
+ _classPrivateFieldGet(_resizeObserver, this).disconnect();
189
+ _classPrivateFieldSet(_resizeObserver, this, null);
190
+ _classPrivateFieldSet(_stretchCalculator, this, null);
191
+ super.destroy();
192
+ }
193
+ }
194
+ exports.StretchColumns = StretchColumns;
195
+ function _onModifyColWidth(width, column, source) {
196
+ if (source === this.pluginName) {
197
+ return;
198
+ }
199
+ const newWidth = this.getColumnWidth(column);
200
+ if (typeof newWidth === 'number') {
201
+ return newWidth;
202
+ }
203
+ return width;
204
+ }
205
+ /**
206
+ * On each before render the plugin recalculates the column widths
207
+ * based on the chosen stretching strategy.
208
+ */
209
+ function _onBeforeRender() {
210
+ _classPrivateFieldGet(_stretchCalculator, this).refreshStretching();
211
+ }