handsontable 0.0.0-next-1af4e47-20241125 → 0.0.0-next-fcb9b77-20241126

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.

@@ -171,47 +171,43 @@ class CoreAbstract {
171
171
  * Scrolls the viewport to a cell (rerenders if needed).
172
172
  *
173
173
  * @param {CellCoords} coords The cell coordinates to scroll to.
174
- * @param {boolean} [snapToTop] If `true`, viewport is scrolled to show the cell on the top of the table.
175
- * @param {boolean} [snapToRight] If `true`, viewport is scrolled to show the cell on the right of the table.
176
- * @param {boolean} [snapToBottom] If `true`, viewport is scrolled to show the cell on the bottom of the table.
177
- * @param {boolean} [snapToLeft] If `true`, viewport is scrolled to show the cell on the left of the table.
174
+ * @param {'auto' | 'start' | 'end'} [horizontalSnap='auto'] If `'start'`, viewport is scrolled to show
175
+ * the cell on the left of the table. If `'end'`, viewport is scrolled to show the cell on the right of
176
+ * the table. When `'auto'`, the viewport is scrolled only when the column is outside of the viewport.
177
+ * @param {'auto' | 'top' | 'bottom'} [verticalSnap='auto'] If `'top'`, viewport is scrolled to show
178
+ * the cell on the top of the table. If `'bottom'`, viewport is scrolled to show the cell on the bottom of
179
+ * the table. When `'auto'`, the viewport is scrolled only when the row is outside of the viewport.
178
180
  * @returns {boolean}
179
181
  */
180
- scrollViewport(coords, snapToTop, snapToRight, snapToBottom, snapToLeft) {
181
- if (coords.col < 0 || coords.row < 0) {
182
- return false;
183
- }
184
- return this.wtScroll.scrollViewport(coords, snapToTop, snapToRight, snapToBottom, snapToLeft);
182
+ scrollViewport(coords, horizontalSnap, verticalSnap) {
183
+ return this.wtScroll.scrollViewport(coords, horizontalSnap, verticalSnap);
185
184
  }
186
185
 
187
186
  /**
188
187
  * Scrolls the viewport to a column (rerenders if needed).
189
188
  *
190
189
  * @param {number} column Visual column index.
191
- * @param {boolean} [snapToRight] If `true`, viewport is scrolled to show the cell on the right of the table.
192
- * @param {boolean} [snapToLeft] If `true`, viewport is scrolled to show the cell on the left of the table.
190
+ * @param {'auto' | 'start' | 'end'} [snapping='auto'] If `'start'`, viewport is scrolled to show
191
+ * the cell on the left of the table. If `'end'`, viewport is scrolled to show the cell on the right of
192
+ * the table. When `'auto'`, the viewport is scrolled only when the column is outside of the viewport.
193
193
  * @returns {boolean}
194
194
  */
195
- scrollViewportHorizontally(column, snapToRight, snapToLeft) {
196
- if (column < 0) {
197
- return false;
198
- }
199
- return this.wtScroll.scrollViewportHorizontally(column, snapToRight, snapToLeft);
195
+ scrollViewportHorizontally(column, snapping) {
196
+ return this.wtScroll.scrollViewportHorizontally(column, snapping);
200
197
  }
201
198
 
202
199
  /**
203
200
  * Scrolls the viewport to a row (rerenders if needed).
204
201
  *
205
202
  * @param {number} row Visual row index.
206
- * @param {boolean} [snapToTop] If `true`, viewport is scrolled to show the cell on the top of the table.
207
- * @param {boolean} [snapToBottom] If `true`, viewport is scrolled to show the cell on the bottom of the table.
203
+ * @param {'auto' | 'top' | 'bottom'} [snapping='auto'] If `'top'`, viewport is scrolled to show
204
+ * the cell on the top of the table. If `'bottom'`, viewport is scrolled to show the cell on
205
+ * the bottom of the table. When `'auto'`, the viewport is scrolled only when the row is outside of
206
+ * the viewport.
208
207
  * @returns {boolean}
209
208
  */
210
- scrollViewportVertically(row, snapToTop, snapToBottom) {
211
- if (row < 0) {
212
- return false;
213
- }
214
- return this.wtScroll.scrollViewportVertically(row, snapToTop, snapToBottom);
209
+ scrollViewportVertically(row, snapping) {
210
+ return this.wtScroll.scrollViewportVertically(row, snapping);
215
211
  }
216
212
 
217
213
  /**
@@ -167,47 +167,43 @@ export default class CoreAbstract {
167
167
  * Scrolls the viewport to a cell (rerenders if needed).
168
168
  *
169
169
  * @param {CellCoords} coords The cell coordinates to scroll to.
170
- * @param {boolean} [snapToTop] If `true`, viewport is scrolled to show the cell on the top of the table.
171
- * @param {boolean} [snapToRight] If `true`, viewport is scrolled to show the cell on the right of the table.
172
- * @param {boolean} [snapToBottom] If `true`, viewport is scrolled to show the cell on the bottom of the table.
173
- * @param {boolean} [snapToLeft] If `true`, viewport is scrolled to show the cell on the left of the table.
170
+ * @param {'auto' | 'start' | 'end'} [horizontalSnap='auto'] If `'start'`, viewport is scrolled to show
171
+ * the cell on the left of the table. If `'end'`, viewport is scrolled to show the cell on the right of
172
+ * the table. When `'auto'`, the viewport is scrolled only when the column is outside of the viewport.
173
+ * @param {'auto' | 'top' | 'bottom'} [verticalSnap='auto'] If `'top'`, viewport is scrolled to show
174
+ * the cell on the top of the table. If `'bottom'`, viewport is scrolled to show the cell on the bottom of
175
+ * the table. When `'auto'`, the viewport is scrolled only when the row is outside of the viewport.
174
176
  * @returns {boolean}
175
177
  */
176
- scrollViewport(coords, snapToTop, snapToRight, snapToBottom, snapToLeft) {
177
- if (coords.col < 0 || coords.row < 0) {
178
- return false;
179
- }
180
- return this.wtScroll.scrollViewport(coords, snapToTop, snapToRight, snapToBottom, snapToLeft);
178
+ scrollViewport(coords, horizontalSnap, verticalSnap) {
179
+ return this.wtScroll.scrollViewport(coords, horizontalSnap, verticalSnap);
181
180
  }
182
181
 
183
182
  /**
184
183
  * Scrolls the viewport to a column (rerenders if needed).
185
184
  *
186
185
  * @param {number} column Visual column index.
187
- * @param {boolean} [snapToRight] If `true`, viewport is scrolled to show the cell on the right of the table.
188
- * @param {boolean} [snapToLeft] If `true`, viewport is scrolled to show the cell on the left of the table.
186
+ * @param {'auto' | 'start' | 'end'} [snapping='auto'] If `'start'`, viewport is scrolled to show
187
+ * the cell on the left of the table. If `'end'`, viewport is scrolled to show the cell on the right of
188
+ * the table. When `'auto'`, the viewport is scrolled only when the column is outside of the viewport.
189
189
  * @returns {boolean}
190
190
  */
191
- scrollViewportHorizontally(column, snapToRight, snapToLeft) {
192
- if (column < 0) {
193
- return false;
194
- }
195
- return this.wtScroll.scrollViewportHorizontally(column, snapToRight, snapToLeft);
191
+ scrollViewportHorizontally(column, snapping) {
192
+ return this.wtScroll.scrollViewportHorizontally(column, snapping);
196
193
  }
197
194
 
198
195
  /**
199
196
  * Scrolls the viewport to a row (rerenders if needed).
200
197
  *
201
198
  * @param {number} row Visual row index.
202
- * @param {boolean} [snapToTop] If `true`, viewport is scrolled to show the cell on the top of the table.
203
- * @param {boolean} [snapToBottom] If `true`, viewport is scrolled to show the cell on the bottom of the table.
199
+ * @param {'auto' | 'top' | 'bottom'} [snapping='auto'] If `'top'`, viewport is scrolled to show
200
+ * the cell on the top of the table. If `'bottom'`, viewport is scrolled to show the cell on
201
+ * the bottom of the table. When `'auto'`, the viewport is scrolled only when the row is outside of
202
+ * the viewport.
204
203
  * @returns {boolean}
205
204
  */
206
- scrollViewportVertically(row, snapToTop, snapToBottom) {
207
- if (row < 0) {
208
- return false;
209
- }
210
- return this.wtScroll.scrollViewportVertically(row, snapToTop, snapToBottom);
205
+ scrollViewportVertically(row, snapping) {
206
+ return this.wtScroll.scrollViewportVertically(row, snapping);
211
207
  }
212
208
 
213
209
  /**
@@ -125,14 +125,14 @@ class WalkontableFacade {
125
125
  let topmost = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
126
126
  return this._wot.getCell(coords, topmost);
127
127
  }
128
- scrollViewport(coords, snapToTop, snapToRight, snapToBottom, snapToLeft) {
129
- return this._wot.scrollViewport(coords, snapToTop, snapToRight, snapToBottom, snapToLeft);
128
+ scrollViewport(coords, horizontalSnap, verticalSnap) {
129
+ return this._wot.scrollViewport(coords, horizontalSnap, verticalSnap);
130
130
  }
131
- scrollViewportHorizontally(column, snapToRight, snapToLeft) {
132
- return this._wot.scrollViewportHorizontally(column, snapToRight, snapToLeft);
131
+ scrollViewportHorizontally(column, snapping) {
132
+ return this._wot.scrollViewportHorizontally(column, snapping);
133
133
  }
134
- scrollViewportVertically(row, snapToTop, snapToBottom) {
135
- return this._wot.scrollViewportVertically(row, snapToTop, snapToBottom);
134
+ scrollViewportVertically(row, snapping) {
135
+ return this._wot.scrollViewportVertically(row, snapping);
136
136
  }
137
137
  getViewport() {
138
138
  return this._wot.getViewport();
@@ -121,14 +121,14 @@ export default class WalkontableFacade {
121
121
  let topmost = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
122
122
  return this._wot.getCell(coords, topmost);
123
123
  }
124
- scrollViewport(coords, snapToTop, snapToRight, snapToBottom, snapToLeft) {
125
- return this._wot.scrollViewport(coords, snapToTop, snapToRight, snapToBottom, snapToLeft);
124
+ scrollViewport(coords, horizontalSnap, verticalSnap) {
125
+ return this._wot.scrollViewport(coords, horizontalSnap, verticalSnap);
126
126
  }
127
- scrollViewportHorizontally(column, snapToRight, snapToLeft) {
128
- return this._wot.scrollViewportHorizontally(column, snapToRight, snapToLeft);
127
+ scrollViewportHorizontally(column, snapping) {
128
+ return this._wot.scrollViewportHorizontally(column, snapping);
129
129
  }
130
- scrollViewportVertically(row, snapToTop, snapToBottom) {
131
- return this._wot.scrollViewportVertically(row, snapToTop, snapToBottom);
130
+ scrollViewportVertically(row, snapping) {
131
+ return this._wot.scrollViewportVertically(row, snapping);
132
132
  }
133
133
  getViewport() {
134
134
  return this._wot.getViewport();
@@ -3,6 +3,7 @@
3
3
  exports.__esModule = true;
4
4
  require("core-js/modules/es.error.cause.js");
5
5
  var _element = require("../../../helpers/dom/element");
6
+ var _object = require("../../../helpers/object");
6
7
  function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
7
8
  function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
8
9
  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; }
@@ -39,15 +40,20 @@ class Scroll {
39
40
  * Scrolls viewport to a cell.
40
41
  *
41
42
  * @param {CellCoords} coords The cell coordinates.
42
- * @param {boolean} [snapToTop] If `true`, viewport is scrolled to show the cell on the top of the table.
43
- * @param {boolean} [snapToRight] If `true`, viewport is scrolled to show the cell on the right of the table.
44
- * @param {boolean} [snapToBottom] If `true`, viewport is scrolled to show the cell on the bottom of the table.
45
- * @param {boolean} [snapToLeft] If `true`, viewport is scrolled to show the cell on the left of the table.
43
+ * @param {'auto' | 'start' | 'end'} [horizontalSnap='auto'] If `'start'`, viewport is scrolled to show
44
+ * the cell on the left of the table. If `'end'`, viewport is scrolled to show the cell on the right of
45
+ * the table. When `'auto'`, the viewport is scrolled only when the column is outside of the viewport.
46
+ * @param {'auto' | 'top' | 'bottom'} [verticalSnap='auto'] If `'top'`, viewport is scrolled to show
47
+ * the cell on the top of the table. If `'bottom'`, viewport is scrolled to show the cell on the bottom of
48
+ * the table. When `'auto'`, the viewport is scrolled only when the row is outside of the viewport.
46
49
  * @returns {boolean}
47
50
  */
48
- scrollViewport(coords, snapToTop, snapToRight, snapToBottom, snapToLeft) {
49
- const scrolledHorizontally = this.scrollViewportHorizontally(coords.col, snapToRight, snapToLeft);
50
- const scrolledVertically = this.scrollViewportVertically(coords.row, snapToTop, snapToBottom);
51
+ scrollViewport(coords, horizontalSnap, verticalSnap) {
52
+ if (coords.col < 0 || coords.row < 0) {
53
+ return false;
54
+ }
55
+ const scrolledHorizontally = this.scrollViewportHorizontally(coords.col, horizontalSnap);
56
+ const scrolledVertically = this.scrollViewportVertically(coords.row, verticalSnap);
51
57
  return scrolledHorizontally || scrolledVertically;
52
58
  }
53
59
 
@@ -55,42 +61,43 @@ class Scroll {
55
61
  * Scrolls viewport to a column.
56
62
  *
57
63
  * @param {number} column Visual column index.
58
- * @param {boolean} [snapToRight] If `true`, viewport is scrolled to show the cell on the right of the table.
59
- * @param {boolean} [snapToLeft] If `true`, viewport is scrolled to show the cell on the left of the table.
64
+ * @param {'auto' | 'start' | 'end'} [snapping='auto'] If `'start'`, viewport is scrolled to show
65
+ * the cell on the left of the table. If `'end'`, viewport is scrolled to show the cell on the right of
66
+ * the table. When `'auto'`, the viewport is scrolled only when the column is outside of the viewport.
60
67
  * @returns {boolean}
61
68
  */
62
- scrollViewportHorizontally(column, snapToRight, snapToLeft) {
69
+ scrollViewportHorizontally(column) {
70
+ let snapping = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'auto';
63
71
  const {
64
72
  drawn,
65
73
  totalColumns
66
74
  } = this.dataAccessObject;
67
-
68
- // do not scroll the viewport when the column points to a range outside of the dataset
69
- if (!drawn || !Number.isInteger(column) || column < 0 || column > totalColumns) {
75
+ if (!drawn) {
76
+ return false;
77
+ }
78
+ const snappingObject = (0, _object.createObjectPropListener)(snapping);
79
+ column = this.dataAccessObject.wtSettings.getSetting('onBeforeViewportScrollHorizontally', column, snappingObject);
80
+ if (!Number.isInteger(column) || column < 0 || column > totalColumns) {
70
81
  return false;
71
82
  }
72
- const autoSnapping = snapToRight === undefined && snapToLeft === undefined;
83
+ snapping = snappingObject.value;
73
84
  const {
74
85
  fixedColumnsStart,
75
86
  inlineStartOverlay
76
87
  } = this.dataAccessObject;
88
+ const autoSnapping = snapping === 'auto';
77
89
 
78
- // for auto-snapping (both snap* arguments are undefined) do not scroll the viewport
79
- // when the columns points to the overlays
90
+ // for auto-snapping do not scroll the viewport when the columns points to the overlays
80
91
  if (autoSnapping && column < fixedColumnsStart) {
81
92
  return false;
82
93
  }
83
- column = this.dataAccessObject.wtSettings.getSetting('onBeforeViewportScrollHorizontally', column);
84
- if (!Number.isInteger(column) || column < 0 || column > totalColumns) {
85
- return false;
86
- }
87
94
  const firstColumn = this.getFirstVisibleColumn();
88
95
  const lastColumn = this.getLastVisibleColumn();
89
96
  let result = false;
90
97
  if (autoSnapping && (column < firstColumn || column > lastColumn) || !autoSnapping) {
91
98
  // if there is at least one fully visible column determine the snapping direction based on
92
- // that columns or by snapToRight/snapToLeft flags, if provided.
93
- result = inlineStartOverlay.scrollTo(column, autoSnapping ? column >= this.getLastPartiallyVisibleColumn() : snapToRight);
99
+ // that columns or by snapping flag, if provided.
100
+ result = inlineStartOverlay.scrollTo(column, autoSnapping ? column >= this.getLastPartiallyVisibleColumn() : snapping === 'end');
94
101
  }
95
102
  return result;
96
103
  }
@@ -99,43 +106,45 @@ class Scroll {
99
106
  * Scrolls viewport to a row.
100
107
  *
101
108
  * @param {number} row Visual row index.
102
- * @param {boolean} [snapToTop] If `true`, viewport is scrolled to show the cell on the top of the table.
103
- * @param {boolean} [snapToBottom] If `true`, viewport is scrolled to show the cell on the bottom of the table.
109
+ * @param {'auto' | 'top' | 'bottom'} [snapping='auto'] If `'top'`, viewport is scrolled to show
110
+ * the cell on the top of the table. If `'bottom'`, viewport is scrolled to show the cell on
111
+ * the bottom of the table. When `'auto'`, the viewport is scrolled only when the row is outside of
112
+ * the viewport.
104
113
  * @returns {boolean}
105
114
  */
106
- scrollViewportVertically(row, snapToTop, snapToBottom) {
115
+ scrollViewportVertically(row) {
116
+ let snapping = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'auto';
107
117
  const {
108
118
  drawn,
109
119
  totalRows
110
120
  } = this.dataAccessObject;
111
-
112
- // do not scroll the viewport when the row points to a range outside of the dataset
113
- if (!drawn || !Number.isInteger(row) || row < 0 || row > totalRows) {
121
+ if (!drawn) {
122
+ return false;
123
+ }
124
+ const snappingObject = (0, _object.createObjectPropListener)(snapping);
125
+ row = this.dataAccessObject.wtSettings.getSetting('onBeforeViewportScrollVertically', row, snappingObject);
126
+ if (!Number.isInteger(row) || row < 0 || row > totalRows) {
114
127
  return false;
115
128
  }
116
- const autoSnapping = snapToTop === undefined && snapToBottom === undefined;
129
+ snapping = snappingObject.value;
117
130
  const {
118
131
  fixedRowsBottom,
119
132
  fixedRowsTop,
120
133
  topOverlay
121
134
  } = this.dataAccessObject;
135
+ const autoSnapping = snapping === 'auto';
122
136
 
123
- // for auto-snapping (both snap* arguments are undefined) do not scroll the viewport
124
- // when the rows points to the overlays
137
+ // for auto-snapping do not scroll the viewport when the rows points to the overlays
125
138
  if (autoSnapping && (row < fixedRowsTop || row > totalRows - fixedRowsBottom - 1)) {
126
139
  return false;
127
140
  }
128
- row = this.dataAccessObject.wtSettings.getSetting('onBeforeViewportScrollVertically', row);
129
- if (!Number.isInteger(row) || row < 0 || row > totalRows) {
130
- return false;
131
- }
132
141
  const firstRow = this.getFirstVisibleRow();
133
142
  const lastRow = this.getLastVisibleRow();
134
143
  let result = false;
135
144
  if (autoSnapping && (row < firstRow || row > lastRow) || !autoSnapping) {
136
145
  // if there is at least one fully visible row determine the snapping direction based on
137
- // that rows or by snapToTop/snapToBottom flags, if provided.
138
- result = topOverlay.scrollTo(row, autoSnapping ? row >= this.getLastPartiallyVisibleRow() : snapToBottom);
146
+ // that rows or by snapping flag, if provided.
147
+ result = topOverlay.scrollTo(row, autoSnapping ? row >= this.getLastPartiallyVisibleRow() : snapping === 'bottom');
139
148
  }
140
149
  return result;
141
150
  }
@@ -6,6 +6,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
6
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
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
8
  import { innerHeight, innerWidth, getScrollLeft, getScrollTop, offset } from "../../../helpers/dom/element.mjs";
9
+ import { createObjectPropListener } from "../../../helpers/object.mjs";
9
10
  /**
10
11
  * @class Scroll
11
12
  */
@@ -36,15 +37,20 @@ class Scroll {
36
37
  * Scrolls viewport to a cell.
37
38
  *
38
39
  * @param {CellCoords} coords The cell coordinates.
39
- * @param {boolean} [snapToTop] If `true`, viewport is scrolled to show the cell on the top of the table.
40
- * @param {boolean} [snapToRight] If `true`, viewport is scrolled to show the cell on the right of the table.
41
- * @param {boolean} [snapToBottom] If `true`, viewport is scrolled to show the cell on the bottom of the table.
42
- * @param {boolean} [snapToLeft] If `true`, viewport is scrolled to show the cell on the left of the table.
40
+ * @param {'auto' | 'start' | 'end'} [horizontalSnap='auto'] If `'start'`, viewport is scrolled to show
41
+ * the cell on the left of the table. If `'end'`, viewport is scrolled to show the cell on the right of
42
+ * the table. When `'auto'`, the viewport is scrolled only when the column is outside of the viewport.
43
+ * @param {'auto' | 'top' | 'bottom'} [verticalSnap='auto'] If `'top'`, viewport is scrolled to show
44
+ * the cell on the top of the table. If `'bottom'`, viewport is scrolled to show the cell on the bottom of
45
+ * the table. When `'auto'`, the viewport is scrolled only when the row is outside of the viewport.
43
46
  * @returns {boolean}
44
47
  */
45
- scrollViewport(coords, snapToTop, snapToRight, snapToBottom, snapToLeft) {
46
- const scrolledHorizontally = this.scrollViewportHorizontally(coords.col, snapToRight, snapToLeft);
47
- const scrolledVertically = this.scrollViewportVertically(coords.row, snapToTop, snapToBottom);
48
+ scrollViewport(coords, horizontalSnap, verticalSnap) {
49
+ if (coords.col < 0 || coords.row < 0) {
50
+ return false;
51
+ }
52
+ const scrolledHorizontally = this.scrollViewportHorizontally(coords.col, horizontalSnap);
53
+ const scrolledVertically = this.scrollViewportVertically(coords.row, verticalSnap);
48
54
  return scrolledHorizontally || scrolledVertically;
49
55
  }
50
56
 
@@ -52,42 +58,43 @@ class Scroll {
52
58
  * Scrolls viewport to a column.
53
59
  *
54
60
  * @param {number} column Visual column index.
55
- * @param {boolean} [snapToRight] If `true`, viewport is scrolled to show the cell on the right of the table.
56
- * @param {boolean} [snapToLeft] If `true`, viewport is scrolled to show the cell on the left of the table.
61
+ * @param {'auto' | 'start' | 'end'} [snapping='auto'] If `'start'`, viewport is scrolled to show
62
+ * the cell on the left of the table. If `'end'`, viewport is scrolled to show the cell on the right of
63
+ * the table. When `'auto'`, the viewport is scrolled only when the column is outside of the viewport.
57
64
  * @returns {boolean}
58
65
  */
59
- scrollViewportHorizontally(column, snapToRight, snapToLeft) {
66
+ scrollViewportHorizontally(column) {
67
+ let snapping = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'auto';
60
68
  const {
61
69
  drawn,
62
70
  totalColumns
63
71
  } = this.dataAccessObject;
64
-
65
- // do not scroll the viewport when the column points to a range outside of the dataset
66
- if (!drawn || !Number.isInteger(column) || column < 0 || column > totalColumns) {
72
+ if (!drawn) {
73
+ return false;
74
+ }
75
+ const snappingObject = createObjectPropListener(snapping);
76
+ column = this.dataAccessObject.wtSettings.getSetting('onBeforeViewportScrollHorizontally', column, snappingObject);
77
+ if (!Number.isInteger(column) || column < 0 || column > totalColumns) {
67
78
  return false;
68
79
  }
69
- const autoSnapping = snapToRight === undefined && snapToLeft === undefined;
80
+ snapping = snappingObject.value;
70
81
  const {
71
82
  fixedColumnsStart,
72
83
  inlineStartOverlay
73
84
  } = this.dataAccessObject;
85
+ const autoSnapping = snapping === 'auto';
74
86
 
75
- // for auto-snapping (both snap* arguments are undefined) do not scroll the viewport
76
- // when the columns points to the overlays
87
+ // for auto-snapping do not scroll the viewport when the columns points to the overlays
77
88
  if (autoSnapping && column < fixedColumnsStart) {
78
89
  return false;
79
90
  }
80
- column = this.dataAccessObject.wtSettings.getSetting('onBeforeViewportScrollHorizontally', column);
81
- if (!Number.isInteger(column) || column < 0 || column > totalColumns) {
82
- return false;
83
- }
84
91
  const firstColumn = this.getFirstVisibleColumn();
85
92
  const lastColumn = this.getLastVisibleColumn();
86
93
  let result = false;
87
94
  if (autoSnapping && (column < firstColumn || column > lastColumn) || !autoSnapping) {
88
95
  // if there is at least one fully visible column determine the snapping direction based on
89
- // that columns or by snapToRight/snapToLeft flags, if provided.
90
- result = inlineStartOverlay.scrollTo(column, autoSnapping ? column >= this.getLastPartiallyVisibleColumn() : snapToRight);
96
+ // that columns or by snapping flag, if provided.
97
+ result = inlineStartOverlay.scrollTo(column, autoSnapping ? column >= this.getLastPartiallyVisibleColumn() : snapping === 'end');
91
98
  }
92
99
  return result;
93
100
  }
@@ -96,43 +103,45 @@ class Scroll {
96
103
  * Scrolls viewport to a row.
97
104
  *
98
105
  * @param {number} row Visual row index.
99
- * @param {boolean} [snapToTop] If `true`, viewport is scrolled to show the cell on the top of the table.
100
- * @param {boolean} [snapToBottom] If `true`, viewport is scrolled to show the cell on the bottom of the table.
106
+ * @param {'auto' | 'top' | 'bottom'} [snapping='auto'] If `'top'`, viewport is scrolled to show
107
+ * the cell on the top of the table. If `'bottom'`, viewport is scrolled to show the cell on
108
+ * the bottom of the table. When `'auto'`, the viewport is scrolled only when the row is outside of
109
+ * the viewport.
101
110
  * @returns {boolean}
102
111
  */
103
- scrollViewportVertically(row, snapToTop, snapToBottom) {
112
+ scrollViewportVertically(row) {
113
+ let snapping = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'auto';
104
114
  const {
105
115
  drawn,
106
116
  totalRows
107
117
  } = this.dataAccessObject;
108
-
109
- // do not scroll the viewport when the row points to a range outside of the dataset
110
- if (!drawn || !Number.isInteger(row) || row < 0 || row > totalRows) {
118
+ if (!drawn) {
119
+ return false;
120
+ }
121
+ const snappingObject = createObjectPropListener(snapping);
122
+ row = this.dataAccessObject.wtSettings.getSetting('onBeforeViewportScrollVertically', row, snappingObject);
123
+ if (!Number.isInteger(row) || row < 0 || row > totalRows) {
111
124
  return false;
112
125
  }
113
- const autoSnapping = snapToTop === undefined && snapToBottom === undefined;
126
+ snapping = snappingObject.value;
114
127
  const {
115
128
  fixedRowsBottom,
116
129
  fixedRowsTop,
117
130
  topOverlay
118
131
  } = this.dataAccessObject;
132
+ const autoSnapping = snapping === 'auto';
119
133
 
120
- // for auto-snapping (both snap* arguments are undefined) do not scroll the viewport
121
- // when the rows points to the overlays
134
+ // for auto-snapping do not scroll the viewport when the rows points to the overlays
122
135
  if (autoSnapping && (row < fixedRowsTop || row > totalRows - fixedRowsBottom - 1)) {
123
136
  return false;
124
137
  }
125
- row = this.dataAccessObject.wtSettings.getSetting('onBeforeViewportScrollVertically', row);
126
- if (!Number.isInteger(row) || row < 0 || row > totalRows) {
127
- return false;
128
- }
129
138
  const firstRow = this.getFirstVisibleRow();
130
139
  const lastRow = this.getLastVisibleRow();
131
140
  let result = false;
132
141
  if (autoSnapping && (row < firstRow || row > lastRow) || !autoSnapping) {
133
142
  // if there is at least one fully visible row determine the snapping direction based on
134
- // that rows or by snapToTop/snapToBottom flags, if provided.
135
- result = topOverlay.scrollTo(row, autoSnapping ? row >= this.getLastPartiallyVisibleRow() : snapToBottom);
143
+ // that rows or by snapping flag, if provided.
144
+ result = topOverlay.scrollTo(row, autoSnapping ? row >= this.getLastPartiallyVisibleRow() : snapping === 'bottom');
136
145
  }
137
146
  return result;
138
147
  }
package/base.js CHANGED
@@ -45,8 +45,8 @@ Handsontable.hooks = _hooks.Hooks.getSingleton();
45
45
  Handsontable.CellCoords = _src.CellCoords;
46
46
  Handsontable.CellRange = _src.CellRange;
47
47
  Handsontable.packageName = 'handsontable';
48
- Handsontable.buildDate = "25/11/2024 11:12:47";
49
- Handsontable.version = "0.0.0-next-1af4e47-20241125";
48
+ Handsontable.buildDate = "26/11/2024 09:17:14";
49
+ Handsontable.version = "0.0.0-next-fcb9b77-20241126";
50
50
  Handsontable.languages = {
51
51
  dictionaryKeys: _registry.dictionaryKeys,
52
52
  getLanguageDictionary: _registry.getLanguageDictionary,
package/base.mjs CHANGED
@@ -35,8 +35,8 @@ Handsontable.hooks = Hooks.getSingleton();
35
35
  Handsontable.CellCoords = CellCoords;
36
36
  Handsontable.CellRange = CellRange;
37
37
  Handsontable.packageName = 'handsontable';
38
- Handsontable.buildDate = "25/11/2024 11:12:53";
39
- Handsontable.version = "0.0.0-next-1af4e47-20241125";
38
+ Handsontable.buildDate = "26/11/2024 09:17:20";
39
+ Handsontable.version = "0.0.0-next-fcb9b77-20241126";
40
40
  Handsontable.languages = {
41
41
  dictionaryKeys,
42
42
  getLanguageDictionary,
@@ -543,6 +543,10 @@ const REGISTERED_HOOKS = exports.REGISTERED_HOOKS = [/* eslint-disable jsdoc/req
543
543
  * @since 14.0.0
544
544
  * @event Hooks#beforeViewportScrollVertically
545
545
  * @param {number} visualRow Visual row index.
546
+ * @param {'auto' | 'top' | 'bottom'} [snapping='auto'] If `'top'`, viewport is scrolled to show
547
+ * the cell on the top of the table. If `'bottom'`, viewport is scrolled to show the cell on
548
+ * the bottom of the table. When `'auto'`, the viewport is scrolled only when the row is outside of
549
+ * the viewport.
546
550
  * @returns {number | boolean} Returns modified row index (or the same as passed in the method argument) to which
547
551
  * the viewport will be scrolled. If the returned value is `false`, the scrolling will be canceled.
548
552
  */
@@ -554,6 +558,9 @@ const REGISTERED_HOOKS = exports.REGISTERED_HOOKS = [/* eslint-disable jsdoc/req
554
558
  * @since 14.0.0
555
559
  * @event Hooks#beforeViewportScrollHorizontally
556
560
  * @param {number} visualColumn Visual column index.
561
+ * @param {'auto' | 'start' | 'end'} [snapping='auto'] If `'start'`, viewport is scrolled to show
562
+ * the cell on the left of the table. If `'end'`, viewport is scrolled to show the cell on the right of
563
+ * the table. When `'auto'`, the viewport is scrolled only when the column is outside of the viewport.
557
564
  * @returns {number | boolean} Returns modified column index (or the same as passed in the method argument) to which
558
565
  * the viewport will be scrolled. If the returned value is `false`, the scrolling will be canceled.
559
566
  */
@@ -540,6 +540,10 @@ export const REGISTERED_HOOKS = [/* eslint-disable jsdoc/require-description-com
540
540
  * @since 14.0.0
541
541
  * @event Hooks#beforeViewportScrollVertically
542
542
  * @param {number} visualRow Visual row index.
543
+ * @param {'auto' | 'top' | 'bottom'} [snapping='auto'] If `'top'`, viewport is scrolled to show
544
+ * the cell on the top of the table. If `'bottom'`, viewport is scrolled to show the cell on
545
+ * the bottom of the table. When `'auto'`, the viewport is scrolled only when the row is outside of
546
+ * the viewport.
543
547
  * @returns {number | boolean} Returns modified row index (or the same as passed in the method argument) to which
544
548
  * the viewport will be scrolled. If the returned value is `false`, the scrolling will be canceled.
545
549
  */
@@ -551,6 +555,9 @@ export const REGISTERED_HOOKS = [/* eslint-disable jsdoc/require-description-com
551
555
  * @since 14.0.0
552
556
  * @event Hooks#beforeViewportScrollHorizontally
553
557
  * @param {number} visualColumn Visual column index.
558
+ * @param {'auto' | 'start' | 'end'} [snapping='auto'] If `'start'`, viewport is scrolled to show
559
+ * the cell on the left of the table. If `'end'`, viewport is scrolled to show the cell on the right of
560
+ * the table. When `'auto'`, the viewport is scrolled only when the column is outside of the viewport.
554
561
  * @returns {number | boolean} Returns modified column index (or the same as passed in the method argument) to which
555
562
  * the viewport will be scrolled. If the returned value is `false`, the scrolling will be canceled.
556
563
  */
@@ -226,8 +226,8 @@ export interface Events {
226
226
  beforeUpdateData?: (sourceData: CellValue[], initialLoad: boolean, source: string | undefined) => void;
227
227
  beforeValidate?: (value: CellValue, row: number, prop: string | number, source?: ChangeSource) => void;
228
228
  beforeValueRender?: (value: CellValue, cellProperties: CellProperties) => void;
229
- beforeViewportScrollVertically?: (visualRow: number) => number | boolean;
230
- beforeViewportScrollHorizontally?: (visualColumn: number) => number | boolean;
229
+ beforeViewportScrollVertically?: (visualRow: number, snapping: 'auto' | 'top' | 'bottom') => number | boolean | null;
230
+ beforeViewportScrollHorizontally?: (visualColumn: number, snapping: 'auto' | 'start' | 'end') => number | boolean | null;
231
231
  beforeViewportScroll?: () => void;
232
232
  beforeViewRender?: (isForced: boolean, skipRender: { skipRender?: boolean }) => void;
233
233
  construct?: () => void;
package/core.js CHANGED
@@ -4083,22 +4083,8 @@ function Core(rootElement, userSettings) {
4083
4083
  const {
4084
4084
  row,
4085
4085
  col,
4086
- verticalSnap,
4087
- horizontalSnap,
4088
4086
  considerHiddenIndexes
4089
4087
  } = (_options = options) !== null && _options !== void 0 ? _options : {};
4090
- let snapToTop;
4091
- let snapToBottom;
4092
- let snapToInlineStart;
4093
- let snapToInlineEnd;
4094
- if (verticalSnap !== undefined) {
4095
- snapToTop = verticalSnap === 'top';
4096
- snapToBottom = !snapToTop;
4097
- }
4098
- if (horizontalSnap !== undefined) {
4099
- snapToInlineStart = horizontalSnap === 'start';
4100
- snapToInlineEnd = !snapToInlineStart;
4101
- }
4102
4088
  let renderableRow = row;
4103
4089
  let renderableColumn = col;
4104
4090
  if (considerHiddenIndexes === undefined || considerHiddenIndexes) {
@@ -4115,13 +4101,13 @@ function Core(rootElement, userSettings) {
4115
4101
  const isRowInteger = Number.isInteger(renderableRow);
4116
4102
  const isColumnInteger = Number.isInteger(renderableColumn);
4117
4103
  if (isRowInteger && renderableRow >= 0 && isColumnInteger && renderableColumn >= 0) {
4118
- return instance.view.scrollViewport(instance._createCellCoords(renderableRow, renderableColumn), snapToTop, snapToInlineEnd, snapToBottom, snapToInlineStart);
4104
+ return instance.view.scrollViewport(instance._createCellCoords(renderableRow, renderableColumn), options.horizontalSnap, options.verticalSnap);
4119
4105
  }
4120
4106
  if (isRowInteger && renderableRow >= 0 && (isColumnInteger && renderableColumn < 0 || !isColumnInteger)) {
4121
- return instance.view.scrollViewportVertically(renderableRow, snapToTop, snapToBottom);
4107
+ return instance.view.scrollViewportVertically(renderableRow, options.verticalSnap);
4122
4108
  }
4123
4109
  if (isColumnInteger && renderableColumn >= 0 && (isRowInteger && renderableRow < 0 || !isRowInteger)) {
4124
- return instance.view.scrollViewportHorizontally(renderableColumn, snapToInlineEnd, snapToInlineStart);
4110
+ return instance.view.scrollViewportHorizontally(renderableColumn, options.horizontalSnap);
4125
4111
  }
4126
4112
  return false;
4127
4113
  };