handsontable 0.0.0-next-eaf150e-20240823 → 0.0.0-next-0306a1a-20240826

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 (104) hide show
  1. package/3rdparty/walkontable/src/calculator/constants.js +26 -0
  2. package/3rdparty/walkontable/src/calculator/constants.mjs +23 -0
  3. package/3rdparty/walkontable/src/calculator/index.js +17 -18
  4. package/3rdparty/walkontable/src/calculator/index.mjs +6 -11
  5. package/3rdparty/walkontable/src/calculator/{calculationType/renderedAllColumns.js → renderAllColumns.js} +9 -32
  6. package/3rdparty/walkontable/src/calculator/{calculationType/renderedAllColumns.mjs → renderAllColumns.mjs} +8 -31
  7. package/3rdparty/walkontable/src/calculator/{calculationType/renderedAllRows.js → renderAllRows.js} +9 -32
  8. package/3rdparty/walkontable/src/calculator/{calculationType/renderedAllRows.mjs → renderAllRows.mjs} +8 -31
  9. package/3rdparty/walkontable/src/calculator/viewportColumns.js +145 -51
  10. package/3rdparty/walkontable/src/calculator/viewportColumns.mjs +145 -51
  11. package/3rdparty/walkontable/src/calculator/viewportRows.js +141 -59
  12. package/3rdparty/walkontable/src/calculator/viewportRows.mjs +141 -59
  13. package/3rdparty/walkontable/src/index.js +0 -2
  14. package/3rdparty/walkontable/src/index.mjs +2 -2
  15. package/3rdparty/walkontable/src/table.js +11 -5
  16. package/3rdparty/walkontable/src/table.mjs +11 -5
  17. package/3rdparty/walkontable/src/utils/column.js +1 -2
  18. package/3rdparty/walkontable/src/utils/column.mjs +1 -2
  19. package/3rdparty/walkontable/src/utils/columnStretching.js +19 -10
  20. package/3rdparty/walkontable/src/utils/columnStretching.mjs +19 -10
  21. package/3rdparty/walkontable/src/viewport.js +46 -35
  22. package/3rdparty/walkontable/src/viewport.mjs +47 -36
  23. package/CHANGELOG.md +0 -27
  24. package/base.js +2 -2
  25. package/base.mjs +2 -2
  26. package/core.d.ts +2 -1
  27. package/core.js +1 -1
  28. package/core.mjs +2 -2
  29. package/dataMap/metaManager/metaSchema.js +6 -5
  30. package/dataMap/metaManager/metaSchema.mjs +6 -5
  31. package/dist/handsontable.css +20 -32
  32. package/dist/handsontable.full.css +20 -32
  33. package/dist/handsontable.full.js +2091 -2741
  34. package/dist/handsontable.full.min.css +5 -5
  35. package/dist/handsontable.full.min.js +148 -148
  36. package/dist/handsontable.js +2092 -2742
  37. package/dist/handsontable.min.css +4 -4
  38. package/dist/handsontable.min.js +32 -32
  39. package/editors/autocompleteEditor/autocompleteEditor.d.ts +1 -1
  40. package/helpers/a11y.js +0 -2
  41. package/helpers/a11y.mjs +0 -1
  42. package/helpers/mixed.js +2 -2
  43. package/helpers/mixed.mjs +2 -2
  44. package/package.json +1 -1
  45. package/pluginHooks.d.ts +1 -1
  46. package/pluginHooks.js +1 -1
  47. package/pluginHooks.mjs +1 -1
  48. package/plugins/autoColumnSize/autoColumnSize.js +1 -1
  49. package/plugins/autoColumnSize/autoColumnSize.mjs +2 -2
  50. package/plugins/autoRowSize/autoRowSize.js +2 -1
  51. package/plugins/autoRowSize/autoRowSize.mjs +2 -1
  52. package/plugins/columnSorting/columnSorting.js +1 -10
  53. package/plugins/columnSorting/columnSorting.mjs +1 -10
  54. package/plugins/contextMenu/menu/menuItemRenderer.js +4 -3
  55. package/plugins/contextMenu/menu/menuItemRenderer.mjs +6 -5
  56. package/plugins/contextMenu/menu/positioner.js +12 -4
  57. package/plugins/contextMenu/menu/positioner.mjs +12 -4
  58. package/plugins/contextMenu/menu/utils.js +0 -11
  59. package/plugins/contextMenu/menu/utils.mjs +0 -10
  60. package/plugins/contextMenu/predefinedItems/alignment.js +49 -67
  61. package/plugins/contextMenu/predefinedItems/alignment.mjs +50 -68
  62. package/plugins/contextMenu/predefinedItems/readOnly.js +0 -11
  63. package/plugins/contextMenu/predefinedItems/readOnly.mjs +0 -11
  64. package/plugins/contextMenu/utils.js +0 -26
  65. package/plugins/contextMenu/utils.mjs +0 -24
  66. package/plugins/copyPaste/copyPaste.js +14 -14
  67. package/plugins/copyPaste/copyPaste.mjs +14 -14
  68. package/plugins/dropdownMenu/dropdownMenu.js +4 -10
  69. package/plugins/dropdownMenu/dropdownMenu.mjs +4 -10
  70. package/plugins/filters/component/condition.js +1 -6
  71. package/plugins/filters/component/condition.mjs +1 -6
  72. package/plugins/filters/component/value.js +1 -6
  73. package/plugins/filters/component/value.mjs +1 -6
  74. package/plugins/filters/conditionCollection.d.ts +3 -4
  75. package/plugins/filters/conditionCollection.js +0 -26
  76. package/plugins/filters/conditionCollection.mjs +0 -26
  77. package/plugins/filters/filters.js +1 -2
  78. package/plugins/filters/filters.mjs +1 -2
  79. package/plugins/filters/ui/multipleSelect.js +9 -7
  80. package/plugins/filters/ui/multipleSelect.mjs +9 -7
  81. package/plugins/manualRowResize/manualRowResize.js +1 -1
  82. package/plugins/manualRowResize/manualRowResize.mjs +2 -2
  83. package/plugins/mergeCells/cellsCollection.js +9 -11
  84. package/plugins/mergeCells/cellsCollection.mjs +10 -12
  85. package/plugins/undoRedo/undoRedo.js +5 -9
  86. package/plugins/undoRedo/undoRedo.mjs +5 -9
  87. package/shortcuts/utils.js +1 -3
  88. package/shortcuts/utils.mjs +1 -3
  89. package/utils/ghostTable.js +9 -11
  90. package/utils/ghostTable.mjs +10 -12
  91. package/3rdparty/walkontable/src/calculator/calculationType/fullyVisibleColumns.js +0 -126
  92. package/3rdparty/walkontable/src/calculator/calculationType/fullyVisibleColumns.mjs +0 -122
  93. package/3rdparty/walkontable/src/calculator/calculationType/fullyVisibleRows.js +0 -119
  94. package/3rdparty/walkontable/src/calculator/calculationType/fullyVisibleRows.mjs +0 -115
  95. package/3rdparty/walkontable/src/calculator/calculationType/partiallyVisibleColumns.js +0 -125
  96. package/3rdparty/walkontable/src/calculator/calculationType/partiallyVisibleColumns.mjs +0 -121
  97. package/3rdparty/walkontable/src/calculator/calculationType/partiallyVisibleRows.js +0 -118
  98. package/3rdparty/walkontable/src/calculator/calculationType/partiallyVisibleRows.mjs +0 -114
  99. package/3rdparty/walkontable/src/calculator/calculationType/renderedColumns.js +0 -37
  100. package/3rdparty/walkontable/src/calculator/calculationType/renderedColumns.mjs +0 -33
  101. package/3rdparty/walkontable/src/calculator/calculationType/renderedRows.js +0 -37
  102. package/3rdparty/walkontable/src/calculator/calculationType/renderedRows.mjs +0 -33
  103. package/3rdparty/walkontable/src/calculator/viewportBase.js +0 -92
  104. package/3rdparty/walkontable/src/calculator/viewportBase.mjs +0 -88
@@ -1,59 +1,87 @@
1
1
  import "core-js/modules/es.error.cause.js";
2
+ import "core-js/modules/es.array.at.js";
2
3
  import "core-js/modules/es.array.push.js";
4
+ function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
5
+ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
3
6
  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; }
4
7
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
5
8
  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); }
6
- import { ViewportBaseCalculator } from "./viewportBase.mjs";
7
- export const DEFAULT_WIDTH = 50;
8
-
9
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
10
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
11
+ 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"); }
12
+ import { RENDER_TYPE, FULLY_VISIBLE_TYPE } from "./constants.mjs";
9
13
  /**
10
14
  * @typedef {object} ViewportColumnsCalculatorOptions
11
- * @property {Map<string, ViewportBaseCalculator>} calculationTypes The calculation types to be performed.
12
15
  * @property {number} viewportWidth Width of the viewport.
13
16
  * @property {number} scrollOffset Current horizontal scroll position of the viewport.
14
17
  * @property {number} totalColumns Total number of columns.
15
18
  * @property {Function} columnWidthFn Function that returns the width of the column at a given index (in px).
16
- * @property {Function} overrideFn Function that allows to adjust the `startRow` and `endRow` parameters.
19
+ * @property {Function} overrideFn Function that changes calculated this.startRow, this.endRow (used by
20
+ * MergeCells plugin).
21
+ * @property {string} calculationType String which describes types of calculation which will be performed.
17
22
  * @property {string} inlineStartOffset Inline-start offset of the parent container.
23
+ * @property {string} stretchMode Stretch mode 'all' or 'last'.
24
+ * @property {Function} stretchingColumnWidthFn Function that returns the new width of the stretched column.
18
25
  */
19
26
  /**
20
- * Calculates indexes of columns to render OR columns that are visible OR partially visible in the viewport.
27
+ * Calculates indexes of columns to render OR columns that are visible.
28
+ * To redo the calculation, you need to create a new calculator.
21
29
  *
22
30
  * @class ViewportColumnsCalculator
23
31
  */
24
- export class ViewportColumnsCalculator extends ViewportBaseCalculator {
32
+ var _options = /*#__PURE__*/new WeakMap();
33
+ export class ViewportColumnsCalculator {
34
+ /**
35
+ * Default column width.
36
+ *
37
+ * @type {number}
38
+ */
39
+ static get DEFAULT_WIDTH() {
40
+ return 50;
41
+ }
42
+
43
+ /**
44
+ * Number of rendered/visible columns.
45
+ *
46
+ * @type {number}
47
+ */
48
+
25
49
  /**
26
50
  * @param {ViewportColumnsCalculatorOptions} options Object with all options specified for column viewport calculation.
27
51
  */
28
- constructor(_ref) {
29
- let {
30
- calculationTypes,
31
- viewportWidth,
32
- scrollOffset,
33
- totalColumns,
34
- columnWidthFn,
35
- overrideFn,
36
- inlineStartOffset
37
- } = _ref;
38
- super(calculationTypes);
39
- _defineProperty(this, "viewportWidth", 0);
40
- _defineProperty(this, "scrollOffset", 0);
41
- _defineProperty(this, "zeroBasedScrollOffset", 0);
42
- _defineProperty(this, "totalColumns", 0);
43
- _defineProperty(this, "columnWidthFn", null);
44
- _defineProperty(this, "columnWidth", 0);
45
- _defineProperty(this, "overrideFn", null);
46
- _defineProperty(this, "inlineStartOffset", 0);
47
- _defineProperty(this, "totalCalculatedWidth", 0);
48
- _defineProperty(this, "startPositions", []);
49
- _defineProperty(this, "needReverse", true);
50
- this.viewportWidth = viewportWidth;
51
- this.scrollOffset = scrollOffset;
52
- this.zeroBasedScrollOffset = Math.max(scrollOffset, 0);
53
- this.totalColumns = totalColumns;
54
- this.columnWidthFn = columnWidthFn;
55
- this.overrideFn = overrideFn;
56
- this.inlineStartOffset = inlineStartOffset;
52
+ constructor(options) {
53
+ _defineProperty(this, "count", 0);
54
+ /**
55
+ * Index of the first rendered/visible column (can be overwritten using overrideFn).
56
+ *
57
+ * @type {number|null}
58
+ */
59
+ _defineProperty(this, "startColumn", null);
60
+ /**
61
+ * Index of the last rendered/visible column (can be overwritten using overrideFn).
62
+ *
63
+ * @type {null}
64
+ */
65
+ _defineProperty(this, "endColumn", null);
66
+ /**
67
+ * Position of the first rendered/visible column (in px).
68
+ *
69
+ * @type {number|null}
70
+ */
71
+ _defineProperty(this, "startPosition", null);
72
+ /**
73
+ * Determines if the viewport is visible in the trimming container.
74
+ *
75
+ * @type {boolean}
76
+ */
77
+ _defineProperty(this, "isVisibleInTrimmingContainer", false);
78
+ /**
79
+ * The calculator options.
80
+ *
81
+ * @type {ViewportColumnsCalculatorOptions}
82
+ */
83
+ _classPrivateFieldInitSpec(this, _options, void 0);
84
+ _classPrivateFieldSet(_options, this, options);
57
85
  this.calculate();
58
86
  }
59
87
 
@@ -61,30 +89,96 @@ export class ViewportColumnsCalculator extends ViewportBaseCalculator {
61
89
  * Calculates viewport.
62
90
  */
63
91
  calculate() {
64
- this._initialize(this);
65
- for (let column = 0; column < this.totalColumns; column++) {
66
- this.columnWidth = this.getColumnWidth(column);
67
- this._process(column, this);
68
- this.startPositions.push(this.totalCalculatedWidth);
69
- this.totalCalculatedWidth += this.columnWidth;
70
- if (this.totalCalculatedWidth >= this.zeroBasedScrollOffset + this.viewportWidth) {
71
- this.needReverse = false;
92
+ const {
93
+ calculationType,
94
+ overrideFn,
95
+ scrollOffset,
96
+ totalColumns,
97
+ viewportWidth
98
+ } = _classPrivateFieldGet(_options, this);
99
+ const zeroBasedScrollOffset = Math.max(_classPrivateFieldGet(_options, this).scrollOffset, 0);
100
+ // +1 pixel for row header width compensation for horizontal scroll > 0
101
+ const compensatedViewportWidth = zeroBasedScrollOffset > 0 ? viewportWidth + 1 : viewportWidth;
102
+ let sum = 0;
103
+ let needReverse = true;
104
+ const startPositions = [];
105
+ let columnWidth;
106
+ let firstVisibleColumnWidth = 0;
107
+ let lastVisibleColumnWidth = 0;
108
+ for (let i = 0; i < totalColumns; i++) {
109
+ columnWidth = this._getColumnWidth(i);
110
+ if (sum <= zeroBasedScrollOffset && calculationType !== FULLY_VISIBLE_TYPE) {
111
+ this.startColumn = i;
112
+ firstVisibleColumnWidth = columnWidth;
113
+ }
114
+ if (sum >= zeroBasedScrollOffset && sum + (calculationType === FULLY_VISIBLE_TYPE ? columnWidth : 0) <= zeroBasedScrollOffset + compensatedViewportWidth) {
115
+ if (this.startColumn === null || this.startColumn === undefined) {
116
+ this.startColumn = i;
117
+ firstVisibleColumnWidth = columnWidth;
118
+ }
119
+ this.endColumn = i;
120
+ }
121
+ startPositions.push(sum);
122
+ sum += columnWidth;
123
+ lastVisibleColumnWidth = columnWidth;
124
+ if (calculationType !== FULLY_VISIBLE_TYPE) {
125
+ this.endColumn = i;
126
+ }
127
+ if (sum >= zeroBasedScrollOffset + viewportWidth) {
128
+ needReverse = false;
72
129
  break;
73
130
  }
74
131
  }
75
- this._finalize(this);
132
+ const mostRightScrollOffset = scrollOffset + viewportWidth - compensatedViewportWidth;
133
+ const inlineEndColumnOffset = calculationType === FULLY_VISIBLE_TYPE ? 0 : lastVisibleColumnWidth;
134
+ const inlineStartColumnOffset = calculationType === FULLY_VISIBLE_TYPE ? firstVisibleColumnWidth : 0;
135
+ if (
136
+ // the table is to the left of the viewport
137
+ mostRightScrollOffset < -1 * _classPrivateFieldGet(_options, this).inlineStartOffset || scrollOffset > startPositions.at(-1) + inlineEndColumnOffset ||
138
+ // the table is to the right of the viewport
139
+ -1 * _classPrivateFieldGet(_options, this).scrollOffset - _classPrivateFieldGet(_options, this).viewportWidth > -1 * inlineStartColumnOffset) {
140
+ this.isVisibleInTrimmingContainer = false;
141
+ } else {
142
+ this.isVisibleInTrimmingContainer = true;
143
+ }
144
+ if (this.endColumn === totalColumns - 1 && needReverse) {
145
+ this.startColumn = this.endColumn;
146
+ while (this.startColumn > 0) {
147
+ const viewportSum = startPositions[this.endColumn] + columnWidth - startPositions[this.startColumn - 1];
148
+ if (viewportSum <= viewportWidth || calculationType !== FULLY_VISIBLE_TYPE) {
149
+ this.startColumn -= 1;
150
+ }
151
+ if (viewportSum > viewportWidth) {
152
+ break;
153
+ }
154
+ }
155
+ }
156
+ if (calculationType === RENDER_TYPE && this.startColumn !== null && overrideFn) {
157
+ overrideFn(this);
158
+ }
159
+ this.startPosition = startPositions[this.startColumn];
160
+ if (this.startPosition === undefined) {
161
+ this.startPosition = null;
162
+ }
163
+
164
+ // If totalColumns exceeded its total columns size set endColumn to the latest item
165
+ if (totalColumns < this.endColumn) {
166
+ this.endColumn = totalColumns - 1;
167
+ }
168
+ if (this.startColumn !== null) {
169
+ this.count = this.endColumn - this.startColumn + 1;
170
+ }
76
171
  }
77
172
 
78
173
  /**
79
- * Gets the column width at the specified column index.
80
- *
81
- * @param {number} column Column index.
174
+ * @param {number} column The visual column index.
82
175
  * @returns {number}
176
+ * @private
83
177
  */
84
- getColumnWidth(column) {
85
- const width = this.columnWidthFn(column);
178
+ _getColumnWidth(column) {
179
+ let width = _classPrivateFieldGet(_options, this).columnWidthFn(column);
86
180
  if (isNaN(width)) {
87
- return DEFAULT_WIDTH;
181
+ width = ViewportColumnsCalculator.DEFAULT_WIDTH;
88
182
  }
89
183
  return width;
90
184
  }
@@ -2,63 +2,86 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  require("core-js/modules/es.error.cause.js");
5
+ require("core-js/modules/es.array.at.js");
5
6
  require("core-js/modules/es.array.push.js");
6
- var _viewportBase = require("./viewportBase");
7
+ var _constants = require("./constants");
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"); }
7
10
  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; }
8
11
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
9
12
  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); }
10
- const DEFAULT_HEIGHT = exports.DEFAULT_HEIGHT = 23;
11
-
13
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
14
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
15
+ 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"); }
12
16
  /**
13
17
  * @typedef {object} ViewportRowsCalculatorOptions
14
- * @property {Map<string, ViewportBaseCalculator>} calculationTypes The calculation types to be performed.
15
18
  * @property {number} viewportHeight Height of the viewport.
16
19
  * @property {number} scrollOffset Current vertical scroll position of the viewport.
17
20
  * @property {number} totalRows Total number of rows.
18
21
  * @property {Function} rowHeightFn Function that returns the height of the row at a given index (in px).
19
- * @property {Function} overrideFn Function that allows to adjust the `startRow` and `endRow` parameters.
22
+ * @property {Function} overrideFn Function that changes calculated this.startRow, this.endRow (used by MergeCells plugin).
23
+ * @property {string} calculationType String which describes types of calculation which will be performed.
20
24
  * @property {number} horizontalScrollbarHeight The scrollbar height.
21
25
  */
22
26
  /**
23
- * Calculates indexes of rows to render OR rows that are visible OR partially visible in the viewport.
27
+ * Calculates indexes of rows to render OR rows that are visible.
28
+ * To redo the calculation, you need to create a new calculator.
24
29
  *
25
30
  * @class ViewportRowsCalculator
26
31
  */
27
- class ViewportRowsCalculator extends _viewportBase.ViewportBaseCalculator {
32
+ var _options = /*#__PURE__*/new WeakMap();
33
+ class ViewportRowsCalculator {
34
+ /**
35
+ * Default row height.
36
+ *
37
+ * @type {number}
38
+ */
39
+ static get DEFAULT_HEIGHT() {
40
+ return 23;
41
+ }
42
+
43
+ /**
44
+ * Number of rendered/visible rows.
45
+ *
46
+ * @type {number}
47
+ */
48
+
28
49
  /**
29
50
  * @param {ViewportRowsCalculatorOptions} options Object with all options specified for row viewport calculation.
30
51
  */
31
- constructor(_ref) {
32
- let {
33
- calculationTypes,
34
- viewportHeight,
35
- scrollOffset,
36
- totalRows,
37
- rowHeightFn,
38
- overrideFn,
39
- horizontalScrollbarHeight
40
- } = _ref;
41
- super(calculationTypes);
42
- _defineProperty(this, "viewportHeight", 0);
43
- _defineProperty(this, "scrollOffset", 0);
44
- _defineProperty(this, "zeroBasedScrollOffset", 0);
45
- _defineProperty(this, "totalRows", 0);
46
- _defineProperty(this, "rowHeightFn", null);
47
- _defineProperty(this, "rowHeight", 0);
48
- _defineProperty(this, "overrideFn", null);
49
- _defineProperty(this, "horizontalScrollbarHeight", 0);
50
- _defineProperty(this, "innerViewportHeight", 0);
51
- _defineProperty(this, "totalCalculatedHeight", 0);
52
- _defineProperty(this, "startPositions", []);
53
- _defineProperty(this, "needReverse", true);
54
- this.viewportHeight = viewportHeight;
55
- this.scrollOffset = scrollOffset;
56
- this.zeroBasedScrollOffset = Math.max(scrollOffset, 0);
57
- this.totalRows = totalRows;
58
- this.rowHeightFn = rowHeightFn;
59
- this.overrideFn = overrideFn;
60
- this.horizontalScrollbarHeight = horizontalScrollbarHeight !== null && horizontalScrollbarHeight !== void 0 ? horizontalScrollbarHeight : 0;
61
- this.innerViewportHeight = this.zeroBasedScrollOffset + this.viewportHeight - this.horizontalScrollbarHeight;
52
+ constructor(options) {
53
+ _defineProperty(this, "count", 0);
54
+ /**
55
+ * Index of the first rendered/visible row (can be overwritten using overrideFn).
56
+ *
57
+ * @type {number|null}
58
+ */
59
+ _defineProperty(this, "startRow", null);
60
+ /**
61
+ * Index of the last rendered/visible row (can be overwritten using overrideFn).
62
+ *
63
+ * @type {null}
64
+ */
65
+ _defineProperty(this, "endRow", null);
66
+ /**
67
+ * Position of the first rendered/visible row (in px).
68
+ *
69
+ * @type {number|null}
70
+ */
71
+ _defineProperty(this, "startPosition", null);
72
+ /**
73
+ * Determines if the viewport is visible in the trimming container.
74
+ *
75
+ * @type {boolean}
76
+ */
77
+ _defineProperty(this, "isVisibleInTrimmingContainer", false);
78
+ /**
79
+ * The calculator options.
80
+ *
81
+ * @type {ViewportRowsCalculatorOptions}
82
+ */
83
+ _classPrivateFieldInitSpec(this, _options, void 0);
84
+ _classPrivateFieldSet(_options, this, options);
62
85
  this.calculate();
63
86
  }
64
87
 
@@ -66,32 +89,91 @@ class ViewportRowsCalculator extends _viewportBase.ViewportBaseCalculator {
66
89
  * Calculates viewport.
67
90
  */
68
91
  calculate() {
69
- this._initialize(this);
70
- for (let row = 0; row < this.totalRows; row++) {
71
- this.rowHeight = this.getRowHeight(row);
72
- this._process(row, this);
73
- this.startPositions.push(this.totalCalculatedHeight);
74
- this.totalCalculatedHeight += this.rowHeight;
75
- if (this.totalCalculatedHeight >= this.innerViewportHeight) {
76
- this.needReverse = false;
92
+ const {
93
+ calculationType,
94
+ overrideFn,
95
+ rowHeightFn,
96
+ scrollOffset,
97
+ totalRows,
98
+ viewportHeight
99
+ } = _classPrivateFieldGet(_options, this);
100
+ const zeroBasedScrollOffset = Math.max(_classPrivateFieldGet(_options, this).scrollOffset, 0);
101
+ const horizontalScrollbarHeight = _classPrivateFieldGet(_options, this).horizontalScrollbarHeight || 0;
102
+ const innerViewportHeight = zeroBasedScrollOffset + viewportHeight - horizontalScrollbarHeight;
103
+ let sum = 0;
104
+ let needReverse = true;
105
+ const startPositions = [];
106
+ let rowHeight;
107
+ let firstVisibleRowHeight = 0;
108
+ let lastVisibleRowHeight = 0;
109
+
110
+ // Calculate the number (start and end index) of rows needed
111
+ for (let i = 0; i < totalRows; i++) {
112
+ rowHeight = rowHeightFn(i);
113
+ if (isNaN(rowHeight)) {
114
+ rowHeight = ViewportRowsCalculator.DEFAULT_HEIGHT;
115
+ }
116
+ if (sum <= zeroBasedScrollOffset && calculationType !== _constants.FULLY_VISIBLE_TYPE) {
117
+ this.startRow = i;
118
+ firstVisibleRowHeight = rowHeight;
119
+ }
120
+ if (sum >= zeroBasedScrollOffset && sum + (calculationType === _constants.FULLY_VISIBLE_TYPE ? rowHeight : 0) <= innerViewportHeight) {
121
+ if (this.startRow === null) {
122
+ this.startRow = i;
123
+ firstVisibleRowHeight = rowHeight;
124
+ }
125
+ this.endRow = i;
126
+ }
127
+ startPositions.push(sum);
128
+ sum += rowHeight;
129
+ lastVisibleRowHeight = rowHeight;
130
+ if (calculationType !== _constants.FULLY_VISIBLE_TYPE) {
131
+ this.endRow = i;
132
+ }
133
+ if (sum >= innerViewportHeight) {
134
+ needReverse = false;
77
135
  break;
78
136
  }
79
137
  }
80
- this._finalize(this);
81
- }
138
+ const mostBottomScrollOffset = scrollOffset + viewportHeight - horizontalScrollbarHeight;
139
+ const topRowOffset = calculationType === _constants.FULLY_VISIBLE_TYPE ? firstVisibleRowHeight : 0;
140
+ const bottomRowOffset = calculationType === _constants.FULLY_VISIBLE_TYPE ? 0 : lastVisibleRowHeight;
141
+ if (mostBottomScrollOffset < topRowOffset || scrollOffset > startPositions.at(-1) + bottomRowOffset) {
142
+ this.isVisibleInTrimmingContainer = false;
143
+ } else {
144
+ this.isVisibleInTrimmingContainer = true;
145
+ }
82
146
 
83
- /**
84
- * Gets the row height at the specified row index.
85
- *
86
- * @param {number} row Row index.
87
- * @returns {number}
88
- */
89
- getRowHeight(row) {
90
- const rowHeight = this.rowHeightFn(row);
91
- if (isNaN(rowHeight)) {
92
- return DEFAULT_HEIGHT;
147
+ // If the estimation has reached the last row and there is still some space available in the viewport,
148
+ // we need to render in reverse in order to fill the whole viewport with rows
149
+ if (this.endRow === totalRows - 1 && needReverse) {
150
+ this.startRow = this.endRow;
151
+ while (this.startRow > 0) {
152
+ // rowHeight is the height of the last row
153
+ const viewportSum = startPositions[this.endRow] + rowHeight - startPositions[this.startRow - 1];
154
+ if (viewportSum <= viewportHeight - horizontalScrollbarHeight || calculationType !== _constants.FULLY_VISIBLE_TYPE) {
155
+ this.startRow -= 1;
156
+ }
157
+ if (viewportSum >= viewportHeight - horizontalScrollbarHeight) {
158
+ break;
159
+ }
160
+ }
161
+ }
162
+ if (calculationType === _constants.RENDER_TYPE && this.startRow !== null && overrideFn) {
163
+ overrideFn(this);
164
+ }
165
+ this.startPosition = startPositions[this.startRow];
166
+ if (this.startPosition === undefined) {
167
+ this.startPosition = null;
168
+ }
169
+
170
+ // If totalRows exceeded its total rows size set endRow to the latest item
171
+ if (totalRows < this.endRow) {
172
+ this.endRow = totalRows - 1;
173
+ }
174
+ if (this.startRow !== null) {
175
+ this.count = this.endRow - this.startRow + 1;
93
176
  }
94
- return rowHeight;
95
177
  }
96
178
  }
97
179
  exports.ViewportRowsCalculator = ViewportRowsCalculator;