handsontable 0.0.0-next-442b0cf-20241209 → 0.0.0-next-aa821c7-20241209

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 (61) hide show
  1. package/base.js +2 -2
  2. package/base.mjs +2 -2
  3. package/core.js +1 -7
  4. package/core.mjs +1 -7
  5. package/dataMap/metaManager/metaSchema.js +2 -3
  6. package/dataMap/metaManager/metaSchema.mjs +2 -3
  7. package/dist/handsontable.css +12 -2
  8. package/dist/handsontable.full.css +12 -2
  9. package/dist/handsontable.full.js +1438 -864
  10. package/dist/handsontable.full.min.css +3 -3
  11. package/dist/handsontable.full.min.js +9 -7
  12. package/dist/handsontable.js +1437 -863
  13. package/dist/handsontable.min.css +3 -3
  14. package/dist/handsontable.min.js +35 -33
  15. package/helpers/mixed.js +1 -1
  16. package/helpers/mixed.mjs +1 -1
  17. package/package.json +1 -1
  18. package/plugins/base/base.js +0 -7
  19. package/plugins/base/base.mjs +0 -7
  20. package/plugins/undoRedo/actions/_base.js +19 -0
  21. package/plugins/undoRedo/actions/_base.mjs +15 -0
  22. package/plugins/undoRedo/actions/cellAlignment.js +85 -0
  23. package/plugins/undoRedo/actions/cellAlignment.mjs +81 -0
  24. package/plugins/undoRedo/actions/columnMove.js +84 -0
  25. package/plugins/undoRedo/actions/columnMove.mjs +80 -0
  26. package/plugins/undoRedo/actions/columnSort.js +73 -0
  27. package/plugins/undoRedo/actions/columnSort.mjs +69 -0
  28. package/plugins/undoRedo/actions/createColumn.js +60 -0
  29. package/plugins/undoRedo/actions/createColumn.mjs +56 -0
  30. package/plugins/undoRedo/actions/createRow.js +65 -0
  31. package/plugins/undoRedo/actions/createRow.mjs +61 -0
  32. package/plugins/undoRedo/actions/dataChange.js +114 -0
  33. package/plugins/undoRedo/actions/dataChange.mjs +110 -0
  34. package/plugins/undoRedo/actions/filters.js +68 -0
  35. package/plugins/undoRedo/actions/filters.mjs +64 -0
  36. package/plugins/undoRedo/actions/index.js +27 -0
  37. package/plugins/undoRedo/actions/index.mjs +23 -0
  38. package/plugins/undoRedo/actions/mergeCells.js +63 -0
  39. package/plugins/undoRedo/actions/mergeCells.mjs +59 -0
  40. package/plugins/undoRedo/actions/removeColumn.js +176 -0
  41. package/plugins/undoRedo/actions/removeColumn.mjs +172 -0
  42. package/plugins/undoRedo/actions/removeRow.js +119 -0
  43. package/plugins/undoRedo/actions/removeRow.mjs +115 -0
  44. package/plugins/undoRedo/actions/rowMove.js +84 -0
  45. package/plugins/undoRedo/actions/rowMove.mjs +80 -0
  46. package/plugins/undoRedo/actions/unmergeCells.js +56 -0
  47. package/plugins/undoRedo/actions/unmergeCells.mjs +52 -0
  48. package/plugins/undoRedo/index.js +3 -4
  49. package/plugins/undoRedo/index.mjs +1 -2
  50. package/plugins/undoRedo/undoRedo.js +277 -879
  51. package/plugins/undoRedo/undoRedo.mjs +277 -880
  52. package/plugins/undoRedo/utils.js +37 -0
  53. package/plugins/undoRedo/utils.mjs +33 -0
  54. package/styles/handsontable.css +9 -2
  55. package/styles/handsontable.min.css +3 -3
  56. package/styles/ht-theme-horizon.css +2 -2
  57. package/styles/ht-theme-horizon.min.css +2 -2
  58. package/styles/ht-theme-main.css +2 -2
  59. package/styles/ht-theme-main.min.css +2 -2
  60. package/utils/ghostTable.js +1 -5
  61. package/utils/ghostTable.mjs +1 -5
@@ -0,0 +1,59 @@
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
+ import { BaseAction } from "./_base.mjs";
6
+ /**
7
+ * Action that tracks changes in merged cells.
8
+ *
9
+ * @class MergeCellsAction
10
+ * @private
11
+ */
12
+ export class MergeCellsAction extends BaseAction {
13
+ constructor(_ref) {
14
+ let {
15
+ data,
16
+ cellRange
17
+ } = _ref;
18
+ super();
19
+ _defineProperty(this, "cellRange", void 0);
20
+ this.cellRange = cellRange;
21
+ this.data = data;
22
+ }
23
+ static startRegisteringEvents(hot, undoRedoPlugin) {
24
+ hot.addHook('beforeMergeCells', (cellRange, auto) => {
25
+ if (auto) {
26
+ return;
27
+ }
28
+ const topStartCorner = cellRange.getTopStartCorner();
29
+ const bottomEndCorner = cellRange.getBottomEndCorner();
30
+ const data = hot.getData(topStartCorner.row, topStartCorner.col, bottomEndCorner.row, bottomEndCorner.col);
31
+ undoRedoPlugin.done(() => new MergeCellsAction({
32
+ data,
33
+ cellRange
34
+ }));
35
+ });
36
+ }
37
+
38
+ /**
39
+ * @param {Core} hot The Handsontable instance.
40
+ * @param {function(): void} undoneCallback The callback to be called after the action is undone.
41
+ */
42
+ undo(hot, undoneCallback) {
43
+ const mergeCellsPlugin = hot.getPlugin('mergeCells');
44
+ hot.addHookOnce('afterViewRender', undoneCallback);
45
+ mergeCellsPlugin.unmergeRange(this.cellRange, true);
46
+ const topStartCorner = this.cellRange.getTopStartCorner();
47
+ hot.populateFromArray(topStartCorner.row, topStartCorner.col, this.data, undefined, undefined, 'MergeCells');
48
+ }
49
+
50
+ /**
51
+ * @param {Core} hot The Handsontable instance.
52
+ * @param {function(): void} redoneCallback The callback to be called after the action is redone.
53
+ */
54
+ redo(hot, redoneCallback) {
55
+ const mergeCellsPlugin = hot.getPlugin('mergeCells');
56
+ hot.addHookOnce('afterViewRender', redoneCallback);
57
+ mergeCellsPlugin.mergeRange(this.cellRange);
58
+ }
59
+ }
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ require("core-js/modules/es.error.cause.js");
5
+ require("core-js/modules/es.array.push.js");
6
+ require("core-js/modules/esnext.iterator.constructor.js");
7
+ require("core-js/modules/esnext.iterator.for-each.js");
8
+ var _base = require("./_base");
9
+ var _utils = require("../utils");
10
+ var _number = require("../../../helpers/number");
11
+ var _array = require("../../../helpers/array");
12
+ 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; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
14
+ 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); }
15
+ /**
16
+ * Action that tracks changes in column removal.
17
+ *
18
+ * @class RemoveColumnAction
19
+ * @private
20
+ */
21
+ class RemoveColumnAction extends _base.BaseAction {
22
+ constructor(_ref) {
23
+ let {
24
+ index,
25
+ indexes,
26
+ data,
27
+ headers,
28
+ columnPositions,
29
+ rowPositions,
30
+ fixedColumnsStart,
31
+ removedCellMetas
32
+ } = _ref;
33
+ super();
34
+ /**
35
+ * @param {number} index The visual column index.
36
+ */
37
+ _defineProperty(this, "index", void 0);
38
+ /**
39
+ * @param {number[]} indexes The visual column indexes.
40
+ */
41
+ _defineProperty(this, "indexes", void 0);
42
+ /**
43
+ * @param {Array} data The removed data.
44
+ */
45
+ _defineProperty(this, "data", void 0);
46
+ /**
47
+ * @param {number} amount The number of removed columns.
48
+ */
49
+ _defineProperty(this, "amount", void 0);
50
+ /**
51
+ * @param {Array} headers The header values.
52
+ */
53
+ _defineProperty(this, "headers", void 0);
54
+ /**
55
+ * @param {number[]} columnPositions The column position.
56
+ */
57
+ _defineProperty(this, "columnPositions", void 0);
58
+ /**
59
+ * @param {number[]} rowPositions The row position.
60
+ */
61
+ _defineProperty(this, "rowPositions", void 0);
62
+ /**
63
+ * @param {number} fixedColumnsStart Number of fixed columns on the left. Remove column action change it sometimes.
64
+ */
65
+ _defineProperty(this, "fixedColumnsStart", void 0);
66
+ /**
67
+ * @param {Array} removedCellMetas List of removed cell metas.
68
+ */
69
+ _defineProperty(this, "removedCellMetas", void 0);
70
+ this.index = index;
71
+ this.indexes = indexes;
72
+ this.data = data;
73
+ this.amount = this.data[0].length;
74
+ this.headers = headers;
75
+ this.columnPositions = columnPositions.slice(0);
76
+ this.rowPositions = rowPositions.slice(0);
77
+ this.fixedColumnsStart = fixedColumnsStart;
78
+ this.removedCellMetas = removedCellMetas;
79
+ }
80
+ static startRegisteringEvents(hot, undoRedoPlugin) {
81
+ hot.addHook('beforeRemoveCol', (index, amount, logicColumns, source) => {
82
+ const wrappedAction = () => {
83
+ const originalData = hot.getSourceDataArray();
84
+ const columnIndex = (hot.countCols() + index) % hot.countCols();
85
+ const lastColumnIndex = columnIndex + amount - 1;
86
+ const removedData = [];
87
+ const headers = [];
88
+ const indexes = [];
89
+ (0, _number.rangeEach)(originalData.length - 1, i => {
90
+ const column = [];
91
+ const origRow = originalData[i];
92
+ (0, _number.rangeEach)(columnIndex, lastColumnIndex, j => {
93
+ column.push(origRow[hot.toPhysicalColumn(j)]);
94
+ });
95
+ removedData.push(column);
96
+ });
97
+ (0, _number.rangeEach)(amount - 1, i => {
98
+ indexes.push(hot.toPhysicalColumn(columnIndex + i));
99
+ });
100
+ if (Array.isArray(hot.getSettings().colHeaders)) {
101
+ (0, _number.rangeEach)(amount - 1, i => {
102
+ headers.push(hot.getSettings().colHeaders[hot.toPhysicalColumn(columnIndex + i)] || null);
103
+ });
104
+ }
105
+ const columnsMap = hot.columnIndexMapper.getIndexesSequence();
106
+ const rowsMap = hot.rowIndexMapper.getIndexesSequence();
107
+ return new RemoveColumnAction({
108
+ index: columnIndex,
109
+ indexes,
110
+ data: removedData,
111
+ headers,
112
+ columnPositions: columnsMap,
113
+ rowPositions: rowsMap,
114
+ fixedColumnsStart: hot.getSettings().fixedColumnsStart,
115
+ removedCellMetas: (0, _utils.getCellMetas)(hot, 0, hot.countRows(), columnIndex, lastColumnIndex)
116
+ });
117
+ };
118
+ undoRedoPlugin.done(wrappedAction, source);
119
+ });
120
+ }
121
+
122
+ /**
123
+ * @param {Core} hot The Handsontable instance.
124
+ * @param {function(): void} undoneCallback The callback to be called after the action is undone.
125
+ */
126
+ undo(hot, undoneCallback) {
127
+ const settings = hot.getSettings();
128
+
129
+ // Changing by the reference as `updateSettings` doesn't work the best.
130
+ settings.fixedColumnsStart = this.fixedColumnsStart;
131
+ const ascendingIndexes = this.indexes.slice(0).sort();
132
+ const sortByIndexes = (elem, j, arr) => arr[this.indexes.indexOf(ascendingIndexes[j])];
133
+ const removedDataLength = this.data.length;
134
+ const sortedData = [];
135
+ for (let rowIndex = 0; rowIndex < removedDataLength; rowIndex++) {
136
+ sortedData.push((0, _array.arrayMap)(this.data[rowIndex], sortByIndexes));
137
+ }
138
+ const sortedHeaders = (0, _array.arrayMap)(this.headers, sortByIndexes);
139
+ const changes = [];
140
+ hot.alter('insert_col_start', this.indexes[0], this.indexes.length, 'UndoRedo.undo');
141
+ (0, _array.arrayEach)(hot.getSourceDataArray(), (rowData, rowIndex) => {
142
+ (0, _array.arrayEach)(ascendingIndexes, (changedIndex, contiquesIndex) => {
143
+ rowData[changedIndex] = sortedData[rowIndex][contiquesIndex];
144
+ changes.push([rowIndex, changedIndex, rowData[changedIndex]]);
145
+ });
146
+ });
147
+ hot.setSourceDataAtCell(changes, undefined, undefined, 'UndoRedo.undo');
148
+ if (typeof this.headers !== 'undefined') {
149
+ (0, _array.arrayEach)(sortedHeaders, (headerData, columnIndex) => {
150
+ hot.getSettings().colHeaders[ascendingIndexes[columnIndex]] = headerData;
151
+ });
152
+ }
153
+ this.removedCellMetas.forEach(_ref2 => {
154
+ let [rowIndex, columnIndex, cellMeta] = _ref2;
155
+ hot.setCellMetaObject(rowIndex, columnIndex, cellMeta);
156
+ });
157
+ hot.batchExecution(() => {
158
+ // Restore row sequence in a case when all columns are removed. the original
159
+ // row sequence is lost in that case.
160
+ hot.rowIndexMapper.setIndexesSequence(this.rowPositions);
161
+ hot.columnIndexMapper.setIndexesSequence(this.columnPositions);
162
+ }, true);
163
+ hot.addHookOnce('afterViewRender', undoneCallback);
164
+ hot.render();
165
+ }
166
+
167
+ /**
168
+ * @param {Core} hot The Handsontable instance.
169
+ * @param {function(): void} redoneCallback The callback to be called after the action is redone.
170
+ */
171
+ redo(hot, redoneCallback) {
172
+ hot.addHookOnce('afterRemoveCol', redoneCallback);
173
+ hot.alter('remove_col', this.index, this.amount, 'UndoRedo.redo');
174
+ }
175
+ }
176
+ exports.RemoveColumnAction = RemoveColumnAction;
@@ -0,0 +1,172 @@
1
+ import "core-js/modules/es.error.cause.js";
2
+ import "core-js/modules/es.array.push.js";
3
+ import "core-js/modules/esnext.iterator.constructor.js";
4
+ import "core-js/modules/esnext.iterator.for-each.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
+ import { BaseAction } from "./_base.mjs";
9
+ import { getCellMetas } from "../utils.mjs";
10
+ import { rangeEach } from "../../../helpers/number.mjs";
11
+ import { arrayMap, arrayEach } from "../../../helpers/array.mjs";
12
+ /**
13
+ * Action that tracks changes in column removal.
14
+ *
15
+ * @class RemoveColumnAction
16
+ * @private
17
+ */
18
+ export class RemoveColumnAction extends BaseAction {
19
+ constructor(_ref) {
20
+ let {
21
+ index,
22
+ indexes,
23
+ data,
24
+ headers,
25
+ columnPositions,
26
+ rowPositions,
27
+ fixedColumnsStart,
28
+ removedCellMetas
29
+ } = _ref;
30
+ super();
31
+ /**
32
+ * @param {number} index The visual column index.
33
+ */
34
+ _defineProperty(this, "index", void 0);
35
+ /**
36
+ * @param {number[]} indexes The visual column indexes.
37
+ */
38
+ _defineProperty(this, "indexes", void 0);
39
+ /**
40
+ * @param {Array} data The removed data.
41
+ */
42
+ _defineProperty(this, "data", void 0);
43
+ /**
44
+ * @param {number} amount The number of removed columns.
45
+ */
46
+ _defineProperty(this, "amount", void 0);
47
+ /**
48
+ * @param {Array} headers The header values.
49
+ */
50
+ _defineProperty(this, "headers", void 0);
51
+ /**
52
+ * @param {number[]} columnPositions The column position.
53
+ */
54
+ _defineProperty(this, "columnPositions", void 0);
55
+ /**
56
+ * @param {number[]} rowPositions The row position.
57
+ */
58
+ _defineProperty(this, "rowPositions", void 0);
59
+ /**
60
+ * @param {number} fixedColumnsStart Number of fixed columns on the left. Remove column action change it sometimes.
61
+ */
62
+ _defineProperty(this, "fixedColumnsStart", void 0);
63
+ /**
64
+ * @param {Array} removedCellMetas List of removed cell metas.
65
+ */
66
+ _defineProperty(this, "removedCellMetas", void 0);
67
+ this.index = index;
68
+ this.indexes = indexes;
69
+ this.data = data;
70
+ this.amount = this.data[0].length;
71
+ this.headers = headers;
72
+ this.columnPositions = columnPositions.slice(0);
73
+ this.rowPositions = rowPositions.slice(0);
74
+ this.fixedColumnsStart = fixedColumnsStart;
75
+ this.removedCellMetas = removedCellMetas;
76
+ }
77
+ static startRegisteringEvents(hot, undoRedoPlugin) {
78
+ hot.addHook('beforeRemoveCol', (index, amount, logicColumns, source) => {
79
+ const wrappedAction = () => {
80
+ const originalData = hot.getSourceDataArray();
81
+ const columnIndex = (hot.countCols() + index) % hot.countCols();
82
+ const lastColumnIndex = columnIndex + amount - 1;
83
+ const removedData = [];
84
+ const headers = [];
85
+ const indexes = [];
86
+ rangeEach(originalData.length - 1, i => {
87
+ const column = [];
88
+ const origRow = originalData[i];
89
+ rangeEach(columnIndex, lastColumnIndex, j => {
90
+ column.push(origRow[hot.toPhysicalColumn(j)]);
91
+ });
92
+ removedData.push(column);
93
+ });
94
+ rangeEach(amount - 1, i => {
95
+ indexes.push(hot.toPhysicalColumn(columnIndex + i));
96
+ });
97
+ if (Array.isArray(hot.getSettings().colHeaders)) {
98
+ rangeEach(amount - 1, i => {
99
+ headers.push(hot.getSettings().colHeaders[hot.toPhysicalColumn(columnIndex + i)] || null);
100
+ });
101
+ }
102
+ const columnsMap = hot.columnIndexMapper.getIndexesSequence();
103
+ const rowsMap = hot.rowIndexMapper.getIndexesSequence();
104
+ return new RemoveColumnAction({
105
+ index: columnIndex,
106
+ indexes,
107
+ data: removedData,
108
+ headers,
109
+ columnPositions: columnsMap,
110
+ rowPositions: rowsMap,
111
+ fixedColumnsStart: hot.getSettings().fixedColumnsStart,
112
+ removedCellMetas: getCellMetas(hot, 0, hot.countRows(), columnIndex, lastColumnIndex)
113
+ });
114
+ };
115
+ undoRedoPlugin.done(wrappedAction, source);
116
+ });
117
+ }
118
+
119
+ /**
120
+ * @param {Core} hot The Handsontable instance.
121
+ * @param {function(): void} undoneCallback The callback to be called after the action is undone.
122
+ */
123
+ undo(hot, undoneCallback) {
124
+ const settings = hot.getSettings();
125
+
126
+ // Changing by the reference as `updateSettings` doesn't work the best.
127
+ settings.fixedColumnsStart = this.fixedColumnsStart;
128
+ const ascendingIndexes = this.indexes.slice(0).sort();
129
+ const sortByIndexes = (elem, j, arr) => arr[this.indexes.indexOf(ascendingIndexes[j])];
130
+ const removedDataLength = this.data.length;
131
+ const sortedData = [];
132
+ for (let rowIndex = 0; rowIndex < removedDataLength; rowIndex++) {
133
+ sortedData.push(arrayMap(this.data[rowIndex], sortByIndexes));
134
+ }
135
+ const sortedHeaders = arrayMap(this.headers, sortByIndexes);
136
+ const changes = [];
137
+ hot.alter('insert_col_start', this.indexes[0], this.indexes.length, 'UndoRedo.undo');
138
+ arrayEach(hot.getSourceDataArray(), (rowData, rowIndex) => {
139
+ arrayEach(ascendingIndexes, (changedIndex, contiquesIndex) => {
140
+ rowData[changedIndex] = sortedData[rowIndex][contiquesIndex];
141
+ changes.push([rowIndex, changedIndex, rowData[changedIndex]]);
142
+ });
143
+ });
144
+ hot.setSourceDataAtCell(changes, undefined, undefined, 'UndoRedo.undo');
145
+ if (typeof this.headers !== 'undefined') {
146
+ arrayEach(sortedHeaders, (headerData, columnIndex) => {
147
+ hot.getSettings().colHeaders[ascendingIndexes[columnIndex]] = headerData;
148
+ });
149
+ }
150
+ this.removedCellMetas.forEach(_ref2 => {
151
+ let [rowIndex, columnIndex, cellMeta] = _ref2;
152
+ hot.setCellMetaObject(rowIndex, columnIndex, cellMeta);
153
+ });
154
+ hot.batchExecution(() => {
155
+ // Restore row sequence in a case when all columns are removed. the original
156
+ // row sequence is lost in that case.
157
+ hot.rowIndexMapper.setIndexesSequence(this.rowPositions);
158
+ hot.columnIndexMapper.setIndexesSequence(this.columnPositions);
159
+ }, true);
160
+ hot.addHookOnce('afterViewRender', undoneCallback);
161
+ hot.render();
162
+ }
163
+
164
+ /**
165
+ * @param {Core} hot The Handsontable instance.
166
+ * @param {function(): void} redoneCallback The callback to be called after the action is redone.
167
+ */
168
+ redo(hot, redoneCallback) {
169
+ hot.addHookOnce('afterRemoveCol', redoneCallback);
170
+ hot.alter('remove_col', this.index, this.amount, 'UndoRedo.redo');
171
+ }
172
+ }
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ require("core-js/modules/es.error.cause.js");
5
+ require("core-js/modules/es.array.push.js");
6
+ require("core-js/modules/esnext.iterator.constructor.js");
7
+ require("core-js/modules/esnext.iterator.for-each.js");
8
+ var _base = require("./_base");
9
+ var _utils = require("../utils");
10
+ var _object = require("../../../helpers/object");
11
+ 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; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
13
+ 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); }
14
+ /**
15
+ * Action that tracks changes in row removal.
16
+ *
17
+ * @class RemoveRowAction
18
+ * @private
19
+ */
20
+ class RemoveRowAction extends _base.BaseAction {
21
+ constructor(_ref) {
22
+ let {
23
+ index,
24
+ data,
25
+ fixedRowsBottom,
26
+ fixedRowsTop,
27
+ rowIndexesSequence,
28
+ removedCellMetas
29
+ } = _ref;
30
+ super();
31
+ /**
32
+ * @param {number} index The visual row index.
33
+ */
34
+ _defineProperty(this, "index", void 0);
35
+ /**
36
+ * @param {Array} data The removed data.
37
+ */
38
+ _defineProperty(this, "data", void 0);
39
+ /**
40
+ * @param {number} fixedRowsBottom Number of fixed rows on the bottom. Remove row action change it sometimes.
41
+ */
42
+ _defineProperty(this, "fixedRowsBottom", void 0);
43
+ /**
44
+ * @param {number} fixedRowsTop Number of fixed rows on the top. Remove row action change it sometimes.
45
+ */
46
+ _defineProperty(this, "fixedRowsTop", void 0);
47
+ /**
48
+ * @param {Array} rowIndexesSequence Row index sequence taken from the row index mapper.
49
+ */
50
+ _defineProperty(this, "rowIndexesSequence", void 0);
51
+ /**
52
+ * @param {Array} removedCellMetas List of removed cell metas.
53
+ */
54
+ _defineProperty(this, "removedCellMetas", void 0);
55
+ this.index = index;
56
+ this.data = data;
57
+ this.fixedRowsBottom = fixedRowsBottom;
58
+ this.fixedRowsTop = fixedRowsTop;
59
+ this.rowIndexesSequence = rowIndexesSequence;
60
+ this.removedCellMetas = removedCellMetas;
61
+ }
62
+ static startRegisteringEvents(hot, undoRedoPlugin) {
63
+ hot.addHook('beforeRemoveRow', (index, amount, logicRows, source) => {
64
+ const wrappedAction = () => {
65
+ const physicalRowIndex = hot.toPhysicalRow(index);
66
+ const lastRowIndex = physicalRowIndex + amount - 1;
67
+ const removedData = (0, _object.deepClone)(hot.getSourceData(physicalRowIndex, 0, physicalRowIndex + amount - 1, hot.countSourceCols() - 1));
68
+ return new RemoveRowAction({
69
+ index: physicalRowIndex,
70
+ data: removedData,
71
+ fixedRowsBottom: hot.getSettings().fixedRowsBottom,
72
+ fixedRowsTop: hot.getSettings().fixedRowsTop,
73
+ rowIndexesSequence: hot.rowIndexMapper.getIndexesSequence(),
74
+ removedCellMetas: (0, _utils.getCellMetas)(hot, physicalRowIndex, lastRowIndex, 0, hot.countCols() - 1)
75
+ });
76
+ };
77
+ undoRedoPlugin.done(wrappedAction, source);
78
+ });
79
+ }
80
+
81
+ /**
82
+ * @param {Core} hot The Handsontable instance.
83
+ * @param {function(): void} undoneCallback The callback to be called after the action is undone.
84
+ */
85
+ undo(hot, undoneCallback) {
86
+ const settings = hot.getSettings();
87
+ const changes = [];
88
+
89
+ // Changing by the reference as `updateSettings` doesn't work the best.
90
+ settings.fixedRowsBottom = this.fixedRowsBottom;
91
+ settings.fixedRowsTop = this.fixedRowsTop;
92
+
93
+ // Prepare the change list to fill the source data.
94
+ this.data.forEach((dataRow, rowIndexDelta) => {
95
+ Object.keys(dataRow).forEach(columnProp => {
96
+ const columnIndex = parseInt(columnProp, 10);
97
+ changes.push([this.index + rowIndexDelta, isNaN(columnIndex) ? columnProp : columnIndex, dataRow[columnProp]]);
98
+ });
99
+ });
100
+ hot.alter('insert_row_above', this.index, this.data.length, 'UndoRedo.undo');
101
+ this.removedCellMetas.forEach(_ref2 => {
102
+ let [rowIndex, columnIndex, cellMeta] = _ref2;
103
+ hot.setCellMetaObject(rowIndex, columnIndex, cellMeta);
104
+ });
105
+ hot.addHookOnce('afterViewRender', undoneCallback);
106
+ hot.setSourceDataAtCell(changes, null, null, 'UndoRedo.undo');
107
+ hot.rowIndexMapper.setIndexesSequence(this.rowIndexesSequence);
108
+ }
109
+
110
+ /**
111
+ * @param {Core} hot The Handsontable instance.
112
+ * @param {function(): void} redoneCallback The callback to be called after the action is redone.
113
+ */
114
+ redo(hot, redoneCallback) {
115
+ hot.addHookOnce('afterRemoveRow', redoneCallback);
116
+ hot.alter('remove_row', this.index, this.data.length, 'UndoRedo.redo');
117
+ }
118
+ }
119
+ exports.RemoveRowAction = RemoveRowAction;
@@ -0,0 +1,115 @@
1
+ import "core-js/modules/es.error.cause.js";
2
+ import "core-js/modules/es.array.push.js";
3
+ import "core-js/modules/esnext.iterator.constructor.js";
4
+ import "core-js/modules/esnext.iterator.for-each.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
+ import { BaseAction } from "./_base.mjs";
9
+ import { getCellMetas } from "../utils.mjs";
10
+ import { deepClone } from "../../../helpers/object.mjs";
11
+ /**
12
+ * Action that tracks changes in row removal.
13
+ *
14
+ * @class RemoveRowAction
15
+ * @private
16
+ */
17
+ export class RemoveRowAction extends BaseAction {
18
+ constructor(_ref) {
19
+ let {
20
+ index,
21
+ data,
22
+ fixedRowsBottom,
23
+ fixedRowsTop,
24
+ rowIndexesSequence,
25
+ removedCellMetas
26
+ } = _ref;
27
+ super();
28
+ /**
29
+ * @param {number} index The visual row index.
30
+ */
31
+ _defineProperty(this, "index", void 0);
32
+ /**
33
+ * @param {Array} data The removed data.
34
+ */
35
+ _defineProperty(this, "data", void 0);
36
+ /**
37
+ * @param {number} fixedRowsBottom Number of fixed rows on the bottom. Remove row action change it sometimes.
38
+ */
39
+ _defineProperty(this, "fixedRowsBottom", void 0);
40
+ /**
41
+ * @param {number} fixedRowsTop Number of fixed rows on the top. Remove row action change it sometimes.
42
+ */
43
+ _defineProperty(this, "fixedRowsTop", void 0);
44
+ /**
45
+ * @param {Array} rowIndexesSequence Row index sequence taken from the row index mapper.
46
+ */
47
+ _defineProperty(this, "rowIndexesSequence", void 0);
48
+ /**
49
+ * @param {Array} removedCellMetas List of removed cell metas.
50
+ */
51
+ _defineProperty(this, "removedCellMetas", void 0);
52
+ this.index = index;
53
+ this.data = data;
54
+ this.fixedRowsBottom = fixedRowsBottom;
55
+ this.fixedRowsTop = fixedRowsTop;
56
+ this.rowIndexesSequence = rowIndexesSequence;
57
+ this.removedCellMetas = removedCellMetas;
58
+ }
59
+ static startRegisteringEvents(hot, undoRedoPlugin) {
60
+ hot.addHook('beforeRemoveRow', (index, amount, logicRows, source) => {
61
+ const wrappedAction = () => {
62
+ const physicalRowIndex = hot.toPhysicalRow(index);
63
+ const lastRowIndex = physicalRowIndex + amount - 1;
64
+ const removedData = deepClone(hot.getSourceData(physicalRowIndex, 0, physicalRowIndex + amount - 1, hot.countSourceCols() - 1));
65
+ return new RemoveRowAction({
66
+ index: physicalRowIndex,
67
+ data: removedData,
68
+ fixedRowsBottom: hot.getSettings().fixedRowsBottom,
69
+ fixedRowsTop: hot.getSettings().fixedRowsTop,
70
+ rowIndexesSequence: hot.rowIndexMapper.getIndexesSequence(),
71
+ removedCellMetas: getCellMetas(hot, physicalRowIndex, lastRowIndex, 0, hot.countCols() - 1)
72
+ });
73
+ };
74
+ undoRedoPlugin.done(wrappedAction, source);
75
+ });
76
+ }
77
+
78
+ /**
79
+ * @param {Core} hot The Handsontable instance.
80
+ * @param {function(): void} undoneCallback The callback to be called after the action is undone.
81
+ */
82
+ undo(hot, undoneCallback) {
83
+ const settings = hot.getSettings();
84
+ const changes = [];
85
+
86
+ // Changing by the reference as `updateSettings` doesn't work the best.
87
+ settings.fixedRowsBottom = this.fixedRowsBottom;
88
+ settings.fixedRowsTop = this.fixedRowsTop;
89
+
90
+ // Prepare the change list to fill the source data.
91
+ this.data.forEach((dataRow, rowIndexDelta) => {
92
+ Object.keys(dataRow).forEach(columnProp => {
93
+ const columnIndex = parseInt(columnProp, 10);
94
+ changes.push([this.index + rowIndexDelta, isNaN(columnIndex) ? columnProp : columnIndex, dataRow[columnProp]]);
95
+ });
96
+ });
97
+ hot.alter('insert_row_above', this.index, this.data.length, 'UndoRedo.undo');
98
+ this.removedCellMetas.forEach(_ref2 => {
99
+ let [rowIndex, columnIndex, cellMeta] = _ref2;
100
+ hot.setCellMetaObject(rowIndex, columnIndex, cellMeta);
101
+ });
102
+ hot.addHookOnce('afterViewRender', undoneCallback);
103
+ hot.setSourceDataAtCell(changes, null, null, 'UndoRedo.undo');
104
+ hot.rowIndexMapper.setIndexesSequence(this.rowIndexesSequence);
105
+ }
106
+
107
+ /**
108
+ * @param {Core} hot The Handsontable instance.
109
+ * @param {function(): void} redoneCallback The callback to be called after the action is redone.
110
+ */
111
+ redo(hot, redoneCallback) {
112
+ hot.addHookOnce('afterRemoveRow', redoneCallback);
113
+ hot.alter('remove_row', this.index, this.data.length, 'UndoRedo.redo');
114
+ }
115
+ }