handsontable 0.0.0-next-4a0d0f1-20240131 → 0.0.0-next-95bb75e-20240131

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.

package/helpers/mixed.js CHANGED
@@ -134,7 +134,7 @@ const domMessages = {
134
134
  function _injectProductInfo(key, element) {
135
135
  const hasValidType = !isEmpty(key);
136
136
  const isNonCommercial = typeof key === 'string' && key.toLowerCase() === 'non-commercial-and-evaluation';
137
- const hotVersion = "0.0.0-next-4a0d0f1-20240131";
137
+ const hotVersion = "0.0.0-next-95bb75e-20240131";
138
138
  let keyValidityDate;
139
139
  let consoleMessageState = 'invalid';
140
140
  let domMessageState = 'invalid';
package/helpers/mixed.mjs CHANGED
@@ -124,7 +124,7 @@ const domMessages = {
124
124
  export function _injectProductInfo(key, element) {
125
125
  const hasValidType = !isEmpty(key);
126
126
  const isNonCommercial = typeof key === 'string' && key.toLowerCase() === 'non-commercial-and-evaluation';
127
- const hotVersion = "0.0.0-next-4a0d0f1-20240131";
127
+ const hotVersion = "0.0.0-next-95bb75e-20240131";
128
128
  let keyValidityDate;
129
129
  let consoleMessageState = 'invalid';
130
130
  let domMessageState = 'invalid';
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.getMoves = getMoves;
5
+ require("core-js/modules/es.array.push.js");
6
+ /**
7
+ * Gets first position where to move element (respecting the fact that some element will be sooner or later
8
+ * taken out of the dataset in order to move them).
9
+ *
10
+ * @param {Array<number>} movedIndexes Sequence of moved indexes for certain axis.
11
+ * @param {number} finalIndex Final place where to move rows.
12
+ * @param {number} numberOfIndexes Number of indexes in a dataset.
13
+ * @returns {number} Index informing where to move the first element.
14
+ */
15
+ function getMoveLine(movedIndexes, finalIndex, numberOfIndexes) {
16
+ const notMovedElements = Array.from(Array(numberOfIndexes).keys()).filter(index => movedIndexes.includes(index) === false);
17
+ if (finalIndex === 0) {
18
+ var _notMovedElements$fin;
19
+ return (_notMovedElements$fin = notMovedElements[finalIndex]) !== null && _notMovedElements$fin !== void 0 ? _notMovedElements$fin : 0; // Moving before the first dataset's element.
20
+ }
21
+ return notMovedElements[finalIndex - 1] + 1; // Moving before another element.
22
+ }
23
+
24
+ /**
25
+ * Gets initially calculated move positions.
26
+ *
27
+ * @param {Array<number>} movedIndexes Sequence of moved indexes for certain axis.
28
+ * @param {number} moveLine Final place where to move rows.
29
+ * @returns {Array<{from: number, to: number}>} Initially calculated move positions.
30
+ */
31
+ function getInitiallyCalculatedMoves(movedIndexes, moveLine) {
32
+ const moves = [];
33
+ movedIndexes.forEach(movedIndex => {
34
+ const move = {
35
+ from: movedIndex,
36
+ to: moveLine
37
+ };
38
+ moves.forEach(previouslyMovedIndex => {
39
+ const isMovingFromEndToStart = previouslyMovedIndex.from > previouslyMovedIndex.to;
40
+ const isMovingElementBefore = previouslyMovedIndex.to <= move.from;
41
+ const isMovingAfterElement = previouslyMovedIndex.from > move.from;
42
+ if (isMovingAfterElement && isMovingElementBefore && isMovingFromEndToStart) {
43
+ move.from += 1;
44
+ }
45
+ });
46
+
47
+ // Moved element from right to left (or bottom to top).
48
+ if (move.from >= moveLine) {
49
+ moveLine += 1;
50
+ }
51
+ moves.push(move);
52
+ });
53
+ return moves;
54
+ }
55
+
56
+ /**
57
+ * Gets finally calculated move positions (after adjusting).
58
+ *
59
+ * @param {Array<{from: number, to: number}>} moves Initially calculated move positions.
60
+ * @returns {Array<{from: number, to: number}>} Finally calculated move positions (after adjusting).
61
+ */
62
+ function adjustedCalculatedMoves(moves) {
63
+ moves.forEach((move, index) => {
64
+ const nextMoved = moves.slice(index + 1);
65
+ nextMoved.forEach(nextMovedIndex => {
66
+ const isMovingFromStartToEnd = nextMovedIndex.from < nextMovedIndex.to;
67
+ if (nextMovedIndex.from > move.from && isMovingFromStartToEnd) {
68
+ nextMovedIndex.from -= 1;
69
+ }
70
+ });
71
+ });
72
+ return moves;
73
+ }
74
+
75
+ /**
76
+ * Get list of move positions.
77
+ *
78
+ * @param {Array<number>} movedIndexes Sequence of moved indexes for certain axis.
79
+ * @param {number} finalIndex Final place where to move rows.
80
+ * @param {number} numberOfIndexes Number of indexes in a dataset.
81
+ * @returns {Array<{from: number, to: number}>}
82
+ */
83
+ function getMoves(movedIndexes, finalIndex, numberOfIndexes) {
84
+ const moves = getInitiallyCalculatedMoves(movedIndexes, getMoveLine(movedIndexes, finalIndex, numberOfIndexes));
85
+ return adjustedCalculatedMoves(moves);
86
+ }
@@ -0,0 +1,82 @@
1
+ import "core-js/modules/es.array.push.js";
2
+ /**
3
+ * Gets first position where to move element (respecting the fact that some element will be sooner or later
4
+ * taken out of the dataset in order to move them).
5
+ *
6
+ * @param {Array<number>} movedIndexes Sequence of moved indexes for certain axis.
7
+ * @param {number} finalIndex Final place where to move rows.
8
+ * @param {number} numberOfIndexes Number of indexes in a dataset.
9
+ * @returns {number} Index informing where to move the first element.
10
+ */
11
+ function getMoveLine(movedIndexes, finalIndex, numberOfIndexes) {
12
+ const notMovedElements = Array.from(Array(numberOfIndexes).keys()).filter(index => movedIndexes.includes(index) === false);
13
+ if (finalIndex === 0) {
14
+ var _notMovedElements$fin;
15
+ return (_notMovedElements$fin = notMovedElements[finalIndex]) !== null && _notMovedElements$fin !== void 0 ? _notMovedElements$fin : 0; // Moving before the first dataset's element.
16
+ }
17
+ return notMovedElements[finalIndex - 1] + 1; // Moving before another element.
18
+ }
19
+
20
+ /**
21
+ * Gets initially calculated move positions.
22
+ *
23
+ * @param {Array<number>} movedIndexes Sequence of moved indexes for certain axis.
24
+ * @param {number} moveLine Final place where to move rows.
25
+ * @returns {Array<{from: number, to: number}>} Initially calculated move positions.
26
+ */
27
+ function getInitiallyCalculatedMoves(movedIndexes, moveLine) {
28
+ const moves = [];
29
+ movedIndexes.forEach(movedIndex => {
30
+ const move = {
31
+ from: movedIndex,
32
+ to: moveLine
33
+ };
34
+ moves.forEach(previouslyMovedIndex => {
35
+ const isMovingFromEndToStart = previouslyMovedIndex.from > previouslyMovedIndex.to;
36
+ const isMovingElementBefore = previouslyMovedIndex.to <= move.from;
37
+ const isMovingAfterElement = previouslyMovedIndex.from > move.from;
38
+ if (isMovingAfterElement && isMovingElementBefore && isMovingFromEndToStart) {
39
+ move.from += 1;
40
+ }
41
+ });
42
+
43
+ // Moved element from right to left (or bottom to top).
44
+ if (move.from >= moveLine) {
45
+ moveLine += 1;
46
+ }
47
+ moves.push(move);
48
+ });
49
+ return moves;
50
+ }
51
+
52
+ /**
53
+ * Gets finally calculated move positions (after adjusting).
54
+ *
55
+ * @param {Array<{from: number, to: number}>} moves Initially calculated move positions.
56
+ * @returns {Array<{from: number, to: number}>} Finally calculated move positions (after adjusting).
57
+ */
58
+ function adjustedCalculatedMoves(moves) {
59
+ moves.forEach((move, index) => {
60
+ const nextMoved = moves.slice(index + 1);
61
+ nextMoved.forEach(nextMovedIndex => {
62
+ const isMovingFromStartToEnd = nextMovedIndex.from < nextMovedIndex.to;
63
+ if (nextMovedIndex.from > move.from && isMovingFromStartToEnd) {
64
+ nextMovedIndex.from -= 1;
65
+ }
66
+ });
67
+ });
68
+ return moves;
69
+ }
70
+
71
+ /**
72
+ * Get list of move positions.
73
+ *
74
+ * @param {Array<number>} movedIndexes Sequence of moved indexes for certain axis.
75
+ * @param {number} finalIndex Final place where to move rows.
76
+ * @param {number} numberOfIndexes Number of indexes in a dataset.
77
+ * @returns {Array<{from: number, to: number}>}
78
+ */
79
+ export function getMoves(movedIndexes, finalIndex, numberOfIndexes) {
80
+ const moves = getInitiallyCalculatedMoves(movedIndexes, getMoveLine(movedIndexes, finalIndex, numberOfIndexes));
81
+ return adjustedCalculatedMoves(moves);
82
+ }
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "url": "https://github.com/handsontable/handsontable/issues"
11
11
  },
12
12
  "author": "Handsoncode <hello@handsontable.com>",
13
- "version": "0.0.0-next-4a0d0f1-20240131",
13
+ "version": "0.0.0-next-95bb75e-20240131",
14
14
  "main": "index",
15
15
  "module": "index.mjs",
16
16
  "jsnext:main": "index.mjs",
@@ -4,6 +4,7 @@ exports.__esModule = true;
4
4
  require("core-js/modules/es.array.push.js");
5
5
  require("core-js/modules/es.error.cause.js");
6
6
  var _string = require("../../../helpers/string");
7
+ var _moves = require("../../../helpers/moves");
7
8
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
8
9
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
9
10
  function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
@@ -176,79 +177,6 @@ class AxisSyncer {
176
177
  _classPrivateFieldSet(this, _finalIndex, this.getHfIndexFromVisualIndex(visualFinalIndex));
177
178
  }
178
179
 
179
- /**
180
- * Gets first position where to move element (respecting the fact that some element will be sooner or later
181
- * taken out of the dataset in order to move them).
182
- *
183
- * @param {Array<number>} movedHfIndexes Sequence of moved HF indexes for certain axis.
184
- * @param {number} finalHfIndex Final HF place where to move rows.
185
- * @returns {number} HF's index informing where to move the first element.
186
- * @private
187
- */
188
- getMoveLine(movedHfIndexes, finalHfIndex) {
189
- const numberOfElements = _classPrivateFieldGet(this, _indexMapper).getNumberOfIndexes();
190
- const notMovedElements = Array.from(Array(numberOfElements).keys()).filter(index => movedHfIndexes.includes(index) === false);
191
- if (finalHfIndex === 0) {
192
- var _notMovedElements$fin;
193
- return (_notMovedElements$fin = notMovedElements[finalHfIndex]) !== null && _notMovedElements$fin !== void 0 ? _notMovedElements$fin : 0; // Moving before the first dataset's element.
194
- }
195
- return notMovedElements[finalHfIndex - 1] + 1; // Moving before another element.
196
- }
197
-
198
- /**
199
- * Gets initially calculated HF's move positions.
200
- *
201
- * @private
202
- * @param {Array<number>} movedHfIndexes Sequence of moved HF indexes for certain axis.
203
- * @param {number} finalHfIndex Final HF place where to move rows.
204
- * @returns {Array<{from: number, to: number}>} Initially calculated HF's move positions.
205
- */
206
- getInitiallyCalculatedMoves(movedHfIndexes, finalHfIndex) {
207
- let moveLine = this.getMoveLine(movedHfIndexes, finalHfIndex);
208
- const moves = [];
209
- movedHfIndexes.forEach(movedHfIndex => {
210
- const move = {
211
- from: movedHfIndex,
212
- to: moveLine
213
- };
214
- moves.forEach(previouslyMovedIndex => {
215
- const isMovingFromEndToStart = previouslyMovedIndex.from > previouslyMovedIndex.to;
216
- const isMovingElementBefore = previouslyMovedIndex.to <= move.from;
217
- const isMovingAfterElement = previouslyMovedIndex.from > move.from;
218
- if (isMovingAfterElement && isMovingElementBefore && isMovingFromEndToStart) {
219
- move.from += 1;
220
- }
221
- });
222
-
223
- // Moved element from right to left (or bottom to top).
224
- if (move.from >= moveLine) {
225
- moveLine += 1;
226
- }
227
- moves.push(move);
228
- });
229
- return moves;
230
- }
231
-
232
- /**
233
- * Gets finally calculated HF's move positions (after adjusting).
234
- *
235
- * @private
236
- * @param {Array<{from: number, to: number}>} moves Initially calculated HF's move positions.
237
- * @returns {Array<{from: number, to: number}>} Finally calculated HF's move positions (after adjusting).
238
- */
239
- adjustedCalculatedMoves(moves) {
240
- moves.forEach((move, index) => {
241
- const nextMoved = moves.slice(index + 1);
242
- nextMoved.forEach(nextMovedIndex => {
243
- const isMovingFromStartToEnd = nextMovedIndex.from < nextMovedIndex.to;
244
- if (nextMovedIndex.from > move.from && isMovingFromStartToEnd) {
245
- nextMovedIndex.from -= 1;
246
- }
247
- });
248
- });
249
- return moves;
250
- }
251
-
252
180
  /**
253
181
  * Calculating where to move HF elements and performing already calculated moves.
254
182
  *
@@ -262,7 +190,7 @@ class AxisSyncer {
262
190
  if (movePossible === false || orderChanged === false) {
263
191
  return;
264
192
  }
265
- const calculatedMoves = this.adjustedCalculatedMoves(this.getInitiallyCalculatedMoves(_classPrivateFieldGet(this, _movedIndexes), _classPrivateFieldGet(this, _finalIndex)));
193
+ const calculatedMoves = (0, _moves.getMoves)(_classPrivateFieldGet(this, _movedIndexes), _classPrivateFieldGet(this, _finalIndex), _classPrivateFieldGet(this, _indexMapper).getNumberOfIndexes());
266
194
  if (_classPrivateFieldGet(this, _indexSyncer).getSheetId() === null) {
267
195
  _classPrivateFieldGet(this, _indexSyncer).getPostponeAction(() => this.syncMoves(calculatedMoves));
268
196
  } else {
@@ -8,6 +8,7 @@ function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _
8
8
  function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
9
9
  function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
10
10
  import { toUpperCaseFirst } from "../../../helpers/string.mjs";
11
+ import { getMoves } from "../../../helpers/moves.mjs";
11
12
  /**
12
13
  * @private
13
14
  * @class IndexSyncer
@@ -173,79 +174,6 @@ class AxisSyncer {
173
174
  _classPrivateFieldSet(this, _finalIndex, this.getHfIndexFromVisualIndex(visualFinalIndex));
174
175
  }
175
176
 
176
- /**
177
- * Gets first position where to move element (respecting the fact that some element will be sooner or later
178
- * taken out of the dataset in order to move them).
179
- *
180
- * @param {Array<number>} movedHfIndexes Sequence of moved HF indexes for certain axis.
181
- * @param {number} finalHfIndex Final HF place where to move rows.
182
- * @returns {number} HF's index informing where to move the first element.
183
- * @private
184
- */
185
- getMoveLine(movedHfIndexes, finalHfIndex) {
186
- const numberOfElements = _classPrivateFieldGet(this, _indexMapper).getNumberOfIndexes();
187
- const notMovedElements = Array.from(Array(numberOfElements).keys()).filter(index => movedHfIndexes.includes(index) === false);
188
- if (finalHfIndex === 0) {
189
- var _notMovedElements$fin;
190
- return (_notMovedElements$fin = notMovedElements[finalHfIndex]) !== null && _notMovedElements$fin !== void 0 ? _notMovedElements$fin : 0; // Moving before the first dataset's element.
191
- }
192
- return notMovedElements[finalHfIndex - 1] + 1; // Moving before another element.
193
- }
194
-
195
- /**
196
- * Gets initially calculated HF's move positions.
197
- *
198
- * @private
199
- * @param {Array<number>} movedHfIndexes Sequence of moved HF indexes for certain axis.
200
- * @param {number} finalHfIndex Final HF place where to move rows.
201
- * @returns {Array<{from: number, to: number}>} Initially calculated HF's move positions.
202
- */
203
- getInitiallyCalculatedMoves(movedHfIndexes, finalHfIndex) {
204
- let moveLine = this.getMoveLine(movedHfIndexes, finalHfIndex);
205
- const moves = [];
206
- movedHfIndexes.forEach(movedHfIndex => {
207
- const move = {
208
- from: movedHfIndex,
209
- to: moveLine
210
- };
211
- moves.forEach(previouslyMovedIndex => {
212
- const isMovingFromEndToStart = previouslyMovedIndex.from > previouslyMovedIndex.to;
213
- const isMovingElementBefore = previouslyMovedIndex.to <= move.from;
214
- const isMovingAfterElement = previouslyMovedIndex.from > move.from;
215
- if (isMovingAfterElement && isMovingElementBefore && isMovingFromEndToStart) {
216
- move.from += 1;
217
- }
218
- });
219
-
220
- // Moved element from right to left (or bottom to top).
221
- if (move.from >= moveLine) {
222
- moveLine += 1;
223
- }
224
- moves.push(move);
225
- });
226
- return moves;
227
- }
228
-
229
- /**
230
- * Gets finally calculated HF's move positions (after adjusting).
231
- *
232
- * @private
233
- * @param {Array<{from: number, to: number}>} moves Initially calculated HF's move positions.
234
- * @returns {Array<{from: number, to: number}>} Finally calculated HF's move positions (after adjusting).
235
- */
236
- adjustedCalculatedMoves(moves) {
237
- moves.forEach((move, index) => {
238
- const nextMoved = moves.slice(index + 1);
239
- nextMoved.forEach(nextMovedIndex => {
240
- const isMovingFromStartToEnd = nextMovedIndex.from < nextMovedIndex.to;
241
- if (nextMovedIndex.from > move.from && isMovingFromStartToEnd) {
242
- nextMovedIndex.from -= 1;
243
- }
244
- });
245
- });
246
- return moves;
247
- }
248
-
249
177
  /**
250
178
  * Calculating where to move HF elements and performing already calculated moves.
251
179
  *
@@ -259,7 +187,7 @@ class AxisSyncer {
259
187
  if (movePossible === false || orderChanged === false) {
260
188
  return;
261
189
  }
262
- const calculatedMoves = this.adjustedCalculatedMoves(this.getInitiallyCalculatedMoves(_classPrivateFieldGet(this, _movedIndexes), _classPrivateFieldGet(this, _finalIndex)));
190
+ const calculatedMoves = getMoves(_classPrivateFieldGet(this, _movedIndexes), _classPrivateFieldGet(this, _finalIndex), _classPrivateFieldGet(this, _indexMapper).getNumberOfIndexes());
263
191
  if (_classPrivateFieldGet(this, _indexSyncer).getSheetId() === null) {
264
192
  _classPrivateFieldGet(this, _indexSyncer).getPostponeAction(() => this.syncMoves(calculatedMoves));
265
193
  } else {
@@ -8,6 +8,7 @@ var _array = require("../../helpers/array");
8
8
  var _number = require("../../helpers/number");
9
9
  var _object = require("../../helpers/object");
10
10
  var _utils = require("../contextMenu/utils");
11
+ var _moves = require("../../helpers/moves");
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
13
  const SHORTCUTS_GROUP = 'undoRedo';
13
14
  const PLUGIN_KEY = exports.PLUGIN_KEY = 'undoRedo';
@@ -132,6 +133,12 @@ function UndoRedo(instance) {
132
133
  }
133
134
  plugin.done(() => new UndoRedo.RowMoveAction(rows, finalIndex));
134
135
  });
136
+ instance.addHook('beforeColumnMove', (columns, finalIndex) => {
137
+ if (columns === false) {
138
+ return;
139
+ }
140
+ plugin.done(() => new UndoRedo.ColumnMoveAction(columns, finalIndex));
141
+ });
135
142
  instance.addHook('beforeMergeCells', (cellRange, auto) => {
136
143
  if (auto) {
137
144
  return;
@@ -714,24 +721,24 @@ UndoRedo.UnmergeCellsAction = UnmergeCellsAction;
714
721
  */
715
722
  UndoRedo.RowMoveAction = function (rows, finalIndex) {
716
723
  this.rows = rows.slice();
717
- this.finalIndex = finalIndex;
724
+ this.finalRowIndex = finalIndex;
718
725
  this.actionType = 'row_move';
719
726
  };
720
727
  (0, _object.inherit)(UndoRedo.RowMoveAction, UndoRedo.Action);
721
728
  UndoRedo.RowMoveAction.prototype.undo = function (instance, undoneCallback) {
722
729
  const manualRowMove = instance.getPlugin('manualRowMove');
723
- const copyOfRows = [].concat(this.rows);
724
- const rowsMovedUp = copyOfRows.filter(a => a > this.finalIndex);
725
- const rowsMovedDown = copyOfRows.filter(a => a <= this.finalIndex);
726
- const allMovedRows = rowsMovedUp.sort((a, b) => b - a).concat(rowsMovedDown.sort((a, b) => a - b));
727
730
  instance.addHookOnce('afterViewRender', undoneCallback);
728
-
729
- // Moving rows from those with higher indexes to those with lower indexes when action was performed from bottom to top
730
- // Moving rows from those with lower indexes to those with higher indexes when action was performed from top to bottom
731
- for (let i = 0; i < allMovedRows.length; i += 1) {
732
- const newPhysicalRow = instance.toVisualRow(allMovedRows[i]);
733
- manualRowMove.moveRow(newPhysicalRow, allMovedRows[i]);
734
- }
731
+ const rowMoves = (0, _moves.getMoves)(this.rows, this.finalRowIndex, instance.rowIndexMapper.getNumberOfIndexes());
732
+ rowMoves.reverse().forEach(_ref4 => {
733
+ let {
734
+ from,
735
+ to
736
+ } = _ref4;
737
+ if (from < to) {
738
+ to -= 1;
739
+ }
740
+ manualRowMove.moveRow(to, from);
741
+ });
735
742
  instance.render();
736
743
  instance.deselectCell();
737
744
  instance.selectRows(this.rows[0], this.rows[0] + this.rows.length - 1);
@@ -739,10 +746,50 @@ UndoRedo.RowMoveAction.prototype.undo = function (instance, undoneCallback) {
739
746
  UndoRedo.RowMoveAction.prototype.redo = function (instance, redoneCallback) {
740
747
  const manualRowMove = instance.getPlugin('manualRowMove');
741
748
  instance.addHookOnce('afterViewRender', redoneCallback);
742
- manualRowMove.moveRows(this.rows.slice(), this.finalIndex);
749
+ manualRowMove.moveRows(this.rows.slice(), this.finalRowIndex);
750
+ instance.render();
751
+ instance.deselectCell();
752
+ instance.selectRows(this.finalRowIndex, this.finalRowIndex + this.rows.length - 1);
753
+ };
754
+
755
+ /**
756
+ * ManualColumnMove action.
757
+ *
758
+ * @private
759
+ * @param {number[]} columns An array with moved columns.
760
+ * @param {number} finalIndex The destination index.
761
+ */
762
+ UndoRedo.ColumnMoveAction = function (columns, finalIndex) {
763
+ this.columns = columns.slice();
764
+ this.finalColumnIndex = finalIndex;
765
+ this.actionType = 'col_move';
766
+ };
767
+ (0, _object.inherit)(UndoRedo.ColumnMoveAction, UndoRedo.Action);
768
+ UndoRedo.ColumnMoveAction.prototype.undo = function (instance, undoneCallback) {
769
+ const manualColumnMove = instance.getPlugin('manualColumnMove');
770
+ instance.addHookOnce('afterViewRender', undoneCallback);
771
+ const columnMoves = (0, _moves.getMoves)(this.columns, this.finalColumnIndex, instance.columnIndexMapper.getNumberOfIndexes());
772
+ columnMoves.reverse().forEach(_ref5 => {
773
+ let {
774
+ from,
775
+ to
776
+ } = _ref5;
777
+ if (from < to) {
778
+ to -= 1;
779
+ }
780
+ manualColumnMove.moveColumn(to, from);
781
+ });
782
+ instance.render();
783
+ instance.deselectCell();
784
+ instance.selectColumns(this.columns[0], this.columns[0] + this.columns.length - 1);
785
+ };
786
+ UndoRedo.ColumnMoveAction.prototype.redo = function (instance, redoneCallback) {
787
+ const manualColumnMove = instance.getPlugin('manualColumnMove');
788
+ instance.addHookOnce('afterViewRender', redoneCallback);
789
+ manualColumnMove.moveColumns(this.columns.slice(), this.finalColumnIndex);
743
790
  instance.render();
744
791
  instance.deselectCell();
745
- instance.selectRows(this.finalIndex, this.finalIndex + this.rows.length - 1);
792
+ instance.selectColumns(this.finalColumnIndex, this.finalColumnIndex + this.columns.length - 1);
746
793
  };
747
794
 
748
795
  /**
@@ -5,6 +5,7 @@ import { arrayMap, arrayEach } from "../../helpers/array.mjs";
5
5
  import { rangeEach } from "../../helpers/number.mjs";
6
6
  import { inherit, deepClone } from "../../helpers/object.mjs";
7
7
  import { align } from "../contextMenu/utils.mjs";
8
+ import { getMoves } from "../../helpers/moves.mjs";
8
9
  const SHORTCUTS_GROUP = 'undoRedo';
9
10
  export const PLUGIN_KEY = 'undoRedo';
10
11
 
@@ -128,6 +129,12 @@ function UndoRedo(instance) {
128
129
  }
129
130
  plugin.done(() => new UndoRedo.RowMoveAction(rows, finalIndex));
130
131
  });
132
+ instance.addHook('beforeColumnMove', (columns, finalIndex) => {
133
+ if (columns === false) {
134
+ return;
135
+ }
136
+ plugin.done(() => new UndoRedo.ColumnMoveAction(columns, finalIndex));
137
+ });
131
138
  instance.addHook('beforeMergeCells', (cellRange, auto) => {
132
139
  if (auto) {
133
140
  return;
@@ -710,24 +717,24 @@ UndoRedo.UnmergeCellsAction = UnmergeCellsAction;
710
717
  */
711
718
  UndoRedo.RowMoveAction = function (rows, finalIndex) {
712
719
  this.rows = rows.slice();
713
- this.finalIndex = finalIndex;
720
+ this.finalRowIndex = finalIndex;
714
721
  this.actionType = 'row_move';
715
722
  };
716
723
  inherit(UndoRedo.RowMoveAction, UndoRedo.Action);
717
724
  UndoRedo.RowMoveAction.prototype.undo = function (instance, undoneCallback) {
718
725
  const manualRowMove = instance.getPlugin('manualRowMove');
719
- const copyOfRows = [].concat(this.rows);
720
- const rowsMovedUp = copyOfRows.filter(a => a > this.finalIndex);
721
- const rowsMovedDown = copyOfRows.filter(a => a <= this.finalIndex);
722
- const allMovedRows = rowsMovedUp.sort((a, b) => b - a).concat(rowsMovedDown.sort((a, b) => a - b));
723
726
  instance.addHookOnce('afterViewRender', undoneCallback);
724
-
725
- // Moving rows from those with higher indexes to those with lower indexes when action was performed from bottom to top
726
- // Moving rows from those with lower indexes to those with higher indexes when action was performed from top to bottom
727
- for (let i = 0; i < allMovedRows.length; i += 1) {
728
- const newPhysicalRow = instance.toVisualRow(allMovedRows[i]);
729
- manualRowMove.moveRow(newPhysicalRow, allMovedRows[i]);
730
- }
727
+ const rowMoves = getMoves(this.rows, this.finalRowIndex, instance.rowIndexMapper.getNumberOfIndexes());
728
+ rowMoves.reverse().forEach(_ref4 => {
729
+ let {
730
+ from,
731
+ to
732
+ } = _ref4;
733
+ if (from < to) {
734
+ to -= 1;
735
+ }
736
+ manualRowMove.moveRow(to, from);
737
+ });
731
738
  instance.render();
732
739
  instance.deselectCell();
733
740
  instance.selectRows(this.rows[0], this.rows[0] + this.rows.length - 1);
@@ -735,10 +742,50 @@ UndoRedo.RowMoveAction.prototype.undo = function (instance, undoneCallback) {
735
742
  UndoRedo.RowMoveAction.prototype.redo = function (instance, redoneCallback) {
736
743
  const manualRowMove = instance.getPlugin('manualRowMove');
737
744
  instance.addHookOnce('afterViewRender', redoneCallback);
738
- manualRowMove.moveRows(this.rows.slice(), this.finalIndex);
745
+ manualRowMove.moveRows(this.rows.slice(), this.finalRowIndex);
746
+ instance.render();
747
+ instance.deselectCell();
748
+ instance.selectRows(this.finalRowIndex, this.finalRowIndex + this.rows.length - 1);
749
+ };
750
+
751
+ /**
752
+ * ManualColumnMove action.
753
+ *
754
+ * @private
755
+ * @param {number[]} columns An array with moved columns.
756
+ * @param {number} finalIndex The destination index.
757
+ */
758
+ UndoRedo.ColumnMoveAction = function (columns, finalIndex) {
759
+ this.columns = columns.slice();
760
+ this.finalColumnIndex = finalIndex;
761
+ this.actionType = 'col_move';
762
+ };
763
+ inherit(UndoRedo.ColumnMoveAction, UndoRedo.Action);
764
+ UndoRedo.ColumnMoveAction.prototype.undo = function (instance, undoneCallback) {
765
+ const manualColumnMove = instance.getPlugin('manualColumnMove');
766
+ instance.addHookOnce('afterViewRender', undoneCallback);
767
+ const columnMoves = getMoves(this.columns, this.finalColumnIndex, instance.columnIndexMapper.getNumberOfIndexes());
768
+ columnMoves.reverse().forEach(_ref5 => {
769
+ let {
770
+ from,
771
+ to
772
+ } = _ref5;
773
+ if (from < to) {
774
+ to -= 1;
775
+ }
776
+ manualColumnMove.moveColumn(to, from);
777
+ });
778
+ instance.render();
779
+ instance.deselectCell();
780
+ instance.selectColumns(this.columns[0], this.columns[0] + this.columns.length - 1);
781
+ };
782
+ UndoRedo.ColumnMoveAction.prototype.redo = function (instance, redoneCallback) {
783
+ const manualColumnMove = instance.getPlugin('manualColumnMove');
784
+ instance.addHookOnce('afterViewRender', redoneCallback);
785
+ manualColumnMove.moveColumns(this.columns.slice(), this.finalColumnIndex);
739
786
  instance.render();
740
787
  instance.deselectCell();
741
- instance.selectRows(this.finalIndex, this.finalIndex + this.rows.length - 1);
788
+ instance.selectColumns(this.finalColumnIndex, this.finalColumnIndex + this.columns.length - 1);
742
789
  };
743
790
 
744
791
  /**