@visactor/vtable-plugins 1.23.3-alpha.0 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/cjs/auto-fill/index.d.ts +3 -2
  2. package/cjs/auto-fill/index.js.map +1 -1
  3. package/cjs/auto-fill/series-converters.d.ts +3 -3
  4. package/cjs/auto-fill/series-converters.js.map +1 -1
  5. package/cjs/contextmenu/handle-menu-helper.js +1 -2
  6. package/cjs/contextmenu/index.js +2 -1
  7. package/cjs/excel-edit-cell-keyboard.d.ts +4 -2
  8. package/cjs/excel-edit-cell-keyboard.js.map +1 -1
  9. package/cjs/filter/filter-engine.js +5 -1
  10. package/cjs/filter/filter-engine.js.map +1 -1
  11. package/cjs/filter/filter-state-manager.d.ts +6 -1
  12. package/cjs/filter/filter-state-manager.js +81 -0
  13. package/cjs/filter/filter-state-manager.js.map +1 -1
  14. package/cjs/filter/filter-toolbar.d.ts +2 -0
  15. package/cjs/filter/filter-toolbar.js +23 -3
  16. package/cjs/filter/filter-toolbar.js.map +1 -1
  17. package/cjs/filter/filter.d.ts +4 -2
  18. package/cjs/filter/filter.js +32 -10
  19. package/cjs/filter/filter.js.map +1 -1
  20. package/cjs/filter/index.js +2 -1
  21. package/cjs/filter/types.d.ts +3 -0
  22. package/cjs/filter/types.js.map +1 -1
  23. package/cjs/filter/value-filter.js +11 -41
  24. package/cjs/filter/value-filter.js.map +1 -1
  25. package/cjs/filter/value-filter.syncSingleStateFromTableData.backup.d.ts +46 -0
  26. package/cjs/filter/value-filter.syncSingleStateFromTableData.backup.js +247 -0
  27. package/cjs/filter/value-filter.syncSingleStateFromTableData.backup.js.map +1 -0
  28. package/cjs/history/formula.d.ts +40 -0
  29. package/cjs/history/formula.js +112 -0
  30. package/cjs/history/formula.js.map +1 -0
  31. package/cjs/history/history-plugin.d.ts +88 -0
  32. package/cjs/history/history-plugin.js +699 -0
  33. package/cjs/history/history-plugin.js.map +1 -0
  34. package/cjs/history/index.d.ts +3 -0
  35. package/cjs/history/index.js +24 -0
  36. package/cjs/history/index.js.map +1 -0
  37. package/cjs/history/replay.d.ts +9 -0
  38. package/cjs/history/replay.js +268 -0
  39. package/cjs/history/replay.js.map +1 -0
  40. package/cjs/history/sheet-key.d.ts +9 -0
  41. package/cjs/history/sheet-key.js +44 -0
  42. package/cjs/history/sheet-key.js.map +1 -0
  43. package/cjs/history/snapshot.d.ts +15 -0
  44. package/cjs/history/snapshot.js +78 -0
  45. package/cjs/history/snapshot.js.map +1 -0
  46. package/cjs/history/types.d.ts +105 -0
  47. package/cjs/history/types.js +6 -0
  48. package/cjs/history/types.js.map +1 -0
  49. package/cjs/history-plugin.d.ts +1 -0
  50. package/cjs/history-plugin.js +21 -0
  51. package/cjs/history-plugin.js.map +1 -0
  52. package/cjs/index.d.ts +1 -0
  53. package/cjs/index.js +2 -1
  54. package/cjs/index.js.map +1 -1
  55. package/cjs/master-detail-plugin/checkbox.js +1 -1
  56. package/cjs/master-detail-plugin/config.js +1 -1
  57. package/cjs/master-detail-plugin/core.js +1 -1
  58. package/cjs/master-detail-plugin/events.js +1 -1
  59. package/cjs/master-detail-plugin/types.d.ts +1 -1
  60. package/cjs/master-detail-plugin/types.js.map +1 -1
  61. package/cjs/rotate-table.d.ts +7 -6
  62. package/cjs/rotate-table.js +12 -13
  63. package/cjs/rotate-table.js.map +1 -1
  64. package/cjs/row-series.js +2 -1
  65. package/cjs/table-export/util/pagination.js.map +1 -1
  66. package/cjs/wps-fill-handle.d.ts +4 -2
  67. package/cjs/wps-fill-handle.js.map +1 -1
  68. package/dist/vtable-plugins.js +1903 -81
  69. package/dist/vtable-plugins.min.js +3 -3
  70. package/es/auto-fill/index.d.ts +3 -2
  71. package/es/auto-fill/index.js.map +1 -1
  72. package/es/auto-fill/series-converters.d.ts +3 -3
  73. package/es/auto-fill/series-converters.js.map +1 -1
  74. package/es/contextmenu/handle-menu-helper.js +1 -2
  75. package/es/contextmenu/index.js +2 -1
  76. package/es/excel-edit-cell-keyboard.d.ts +4 -2
  77. package/es/excel-edit-cell-keyboard.js.map +1 -1
  78. package/es/filter/filter-engine.js +5 -1
  79. package/es/filter/filter-engine.js.map +1 -1
  80. package/es/filter/filter-state-manager.d.ts +6 -1
  81. package/es/filter/filter-state-manager.js +81 -0
  82. package/es/filter/filter-state-manager.js.map +1 -1
  83. package/es/filter/filter-toolbar.d.ts +2 -0
  84. package/es/filter/filter-toolbar.js +23 -3
  85. package/es/filter/filter-toolbar.js.map +1 -1
  86. package/es/filter/filter.d.ts +4 -2
  87. package/es/filter/filter.js +32 -10
  88. package/es/filter/filter.js.map +1 -1
  89. package/es/filter/index.js +2 -1
  90. package/es/filter/types.d.ts +3 -0
  91. package/es/filter/types.js.map +1 -1
  92. package/es/filter/value-filter.js +12 -41
  93. package/es/filter/value-filter.js.map +1 -1
  94. package/es/filter/value-filter.syncSingleStateFromTableData.backup.d.ts +46 -0
  95. package/es/filter/value-filter.syncSingleStateFromTableData.backup.js +242 -0
  96. package/es/filter/value-filter.syncSingleStateFromTableData.backup.js.map +1 -0
  97. package/es/history/formula.d.ts +40 -0
  98. package/es/history/formula.js +103 -0
  99. package/es/history/formula.js.map +1 -0
  100. package/es/history/history-plugin.d.ts +88 -0
  101. package/es/history/history-plugin.js +698 -0
  102. package/es/history/history-plugin.js.map +1 -0
  103. package/es/history/index.d.ts +3 -0
  104. package/es/history/index.js +4 -0
  105. package/es/history/index.js.map +1 -0
  106. package/es/history/replay.d.ts +9 -0
  107. package/es/history/replay.js +260 -0
  108. package/es/history/replay.js.map +1 -0
  109. package/es/history/sheet-key.d.ts +9 -0
  110. package/es/history/sheet-key.js +38 -0
  111. package/es/history/sheet-key.js.map +1 -0
  112. package/es/history/snapshot.d.ts +15 -0
  113. package/es/history/snapshot.js +71 -0
  114. package/es/history/snapshot.js.map +1 -0
  115. package/es/history/types.d.ts +105 -0
  116. package/es/history/types.js +2 -0
  117. package/es/history/types.js.map +1 -0
  118. package/es/history-plugin.d.ts +1 -0
  119. package/es/history-plugin.js +2 -0
  120. package/es/history-plugin.js.map +1 -0
  121. package/es/index.d.ts +1 -0
  122. package/es/index.js +2 -0
  123. package/es/index.js.map +1 -1
  124. package/es/master-detail-plugin/checkbox.js +1 -1
  125. package/es/master-detail-plugin/config.js +1 -1
  126. package/es/master-detail-plugin/core.js +1 -1
  127. package/es/master-detail-plugin/events.js +1 -1
  128. package/es/master-detail-plugin/types.d.ts +1 -1
  129. package/es/master-detail-plugin/types.js.map +1 -1
  130. package/es/rotate-table.d.ts +7 -6
  131. package/es/rotate-table.js +2 -3
  132. package/es/rotate-table.js.map +1 -1
  133. package/es/row-series.js +2 -1
  134. package/es/table-export/util/pagination.js.map +1 -1
  135. package/es/wps-fill-handle.d.ts +4 -2
  136. package/es/wps-fill-handle.js.map +1 -1
  137. package/package.json +10 -8
  138. package/cjs/auto-fill/__tests__/formula-integration.test.d.ts +0 -23
  139. package/cjs/auto-fill/__tests__/formula-integration.test.js +0 -61
  140. package/cjs/auto-fill/__tests__/formula-integration.test.js.map +0 -1
  141. package/es/auto-fill/__tests__/formula-integration.test.d.ts +0 -23
  142. package/es/auto-fill/__tests__/formula-integration.test.js +0 -54
  143. package/es/auto-fill/__tests__/formula-integration.test.js.map +0 -1
@@ -0,0 +1,699 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.HistoryPlugin = void 0;
6
+
7
+ const vtable_1 = require("@visactor/vtable"), formula_1 = require("./formula"), replay_1 = require("./replay"), snapshot_1 = require("./snapshot"), sheet_key_1 = require("./sheet-key"), types_1 = require("../filter/types");
8
+
9
+ class HistoryPlugin {
10
+ constructor(options) {
11
+ var _a, _b, _c;
12
+ this.id = "history-plugin", this.name = "History", this.runTime = [ vtable_1.TABLE_EVENT_TYPE.BEFORE_INIT, vtable_1.TABLE_EVENT_TYPE.INITIALIZED, vtable_1.TABLE_EVENT_TYPE.BEFORE_KEYDOWN, vtable_1.TABLE_EVENT_TYPE.CHANGE_CELL_VALUE, vtable_1.TABLE_EVENT_TYPE.CHANGE_CELL_VALUES, vtable_1.TABLE_EVENT_TYPE.PASTED_DATA, vtable_1.TABLE_EVENT_TYPE.MERGE_CELLS, vtable_1.TABLE_EVENT_TYPE.UNMERGE_CELLS, vtable_1.TABLE_EVENT_TYPE.ADD_RECORD, vtable_1.TABLE_EVENT_TYPE.DELETE_RECORD, vtable_1.TABLE_EVENT_TYPE.UPDATE_RECORD, vtable_1.TABLE_EVENT_TYPE.ADD_COLUMN, vtable_1.TABLE_EVENT_TYPE.DELETE_COLUMN, vtable_1.TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION, vtable_1.TABLE_EVENT_TYPE.SORT_CLICK, vtable_1.TABLE_EVENT_TYPE.RESIZE_ROW, vtable_1.TABLE_EVENT_TYPE.RESIZE_ROW_END, vtable_1.TABLE_EVENT_TYPE.RESIZE_COLUMN, vtable_1.TABLE_EVENT_TYPE.RESIZE_COLUMN_END ],
13
+ this.table = null, this.undoStack = [], this.redoStack = [], this.currentTransaction = null,
14
+ this.isReplaying = !1, this.prevColumnsSnapshot = null, this.prevRecordsSnapshot = null,
15
+ this.prevFormulasSnapshot = null, this.prevResizedRowHeightsSnapshot = null, this.prevResizedColWidthsSnapshot = null,
16
+ this.lastKnownSortState = null, this.sortStartSnapshot = null, this.sortPending = !1,
17
+ this.sortEventBound = !1, this.cellPreChangeContent = new Map, this.formulaCache = new Map,
18
+ this.formulaEventBound = !1, this.resizeRowStartHeight = new Map, this.resizeColStartWidth = new Map,
19
+ this.filterEventBound = !1, this.filterUnsubscribe = null, this.filterApplyingSnapshot = !1,
20
+ this.id = null !== (_a = null == options ? void 0 : options.id) && void 0 !== _a ? _a : this.id,
21
+ this.maxHistory = null !== (_b = null == options ? void 0 : options.maxHistory) && void 0 !== _b ? _b : 100,
22
+ this.enableCompression = null !== (_c = null == options ? void 0 : options.enableCompression) && void 0 !== _c && _c,
23
+ this.onTransactionPushed = null == options ? void 0 : options.onTransactionPushed;
24
+ }
25
+ run(...args) {
26
+ var _a, _b, _c, _d, _e, _f;
27
+ const eventArgs = args[0], runtime = args[1], table = args[2];
28
+ if (!table) return;
29
+ if (this.table) this.vtableSheet || (this.vtableSheet = table.__vtableSheet); else if (this.table = table,
30
+ this.vtableSheet = table.__vtableSheet, runtime !== vtable_1.TABLE_EVENT_TYPE.BEFORE_INIT && (null === (_a = table.internalProps) || void 0 === _a ? void 0 : _a.dataSource)) {
31
+ const state = this.getSnapshotState(), sheetKey = this.getSheetKey();
32
+ (0, snapshot_1.captureSnapshot)(table, state, {
33
+ formulaManager: null === (_b = this.vtableSheet) || void 0 === _b ? void 0 : _b.formulaManager,
34
+ sheetKey: sheetKey
35
+ }), this.setSnapshotState(state), this.lastKnownSortState = this.normalizeSortState(null === (_c = table.internalProps) || void 0 === _c ? void 0 : _c.sortState);
36
+ }
37
+ if (this.ensureFilterEventBindings(), runtime === vtable_1.TABLE_EVENT_TYPE.BEFORE_INIT) return;
38
+ this.ensureFormulaEventBindings(), this.ensureSortEventBindings();
39
+ const workbookReplaying = null === (_e = null === (_d = this.table) || void 0 === _d ? void 0 : _d.__vtableSheet) || void 0 === _e ? void 0 : _e.__workbookHistoryReplaying;
40
+ if (!this.isReplaying && !workbookReplaying) {
41
+ switch (runtime) {
42
+ case vtable_1.TABLE_EVENT_TYPE.INITIALIZED:
43
+ break;
44
+
45
+ case vtable_1.TABLE_EVENT_TYPE.BEFORE_KEYDOWN:
46
+ this.handleBeforeKeydown(eventArgs);
47
+ break;
48
+
49
+ case vtable_1.TABLE_EVENT_TYPE.CHANGE_CELL_VALUE:
50
+ this.handleChangeCellValue(eventArgs);
51
+ break;
52
+
53
+ case vtable_1.TABLE_EVENT_TYPE.CHANGE_CELL_VALUES:
54
+ this.handleChangeCellValues(eventArgs);
55
+ break;
56
+
57
+ case vtable_1.TABLE_EVENT_TYPE.PASTED_DATA:
58
+ break;
59
+
60
+ case vtable_1.TABLE_EVENT_TYPE.MERGE_CELLS:
61
+ this.handleMergeCells(eventArgs);
62
+ break;
63
+
64
+ case vtable_1.TABLE_EVENT_TYPE.UNMERGE_CELLS:
65
+ this.handleUnmergeCells(eventArgs);
66
+ break;
67
+
68
+ case vtable_1.TABLE_EVENT_TYPE.ADD_RECORD:
69
+ this.handleAddRecord(eventArgs);
70
+ break;
71
+
72
+ case vtable_1.TABLE_EVENT_TYPE.DELETE_RECORD:
73
+ this.handleDeleteRecord(eventArgs);
74
+ break;
75
+
76
+ case vtable_1.TABLE_EVENT_TYPE.UPDATE_RECORD:
77
+ this.handleUpdateRecord(eventArgs);
78
+ break;
79
+
80
+ case vtable_1.TABLE_EVENT_TYPE.ADD_COLUMN:
81
+ this.handleAddColumn(eventArgs);
82
+ break;
83
+
84
+ case vtable_1.TABLE_EVENT_TYPE.DELETE_COLUMN:
85
+ this.handleDeleteColumn(eventArgs);
86
+ break;
87
+
88
+ case vtable_1.TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION:
89
+ this.handleChangeHeaderPosition(eventArgs);
90
+ break;
91
+
92
+ case vtable_1.TABLE_EVENT_TYPE.SORT_CLICK:
93
+ this.handleSortClick(eventArgs);
94
+ break;
95
+
96
+ case vtable_1.TABLE_EVENT_TYPE.RESIZE_ROW:
97
+ this.handleResizeRow(eventArgs);
98
+ break;
99
+
100
+ case vtable_1.TABLE_EVENT_TYPE.RESIZE_ROW_END:
101
+ this.handleResizeRowEnd(eventArgs);
102
+ break;
103
+
104
+ case vtable_1.TABLE_EVENT_TYPE.RESIZE_COLUMN:
105
+ this.handleResizeColumn(eventArgs);
106
+ break;
107
+
108
+ case vtable_1.TABLE_EVENT_TYPE.RESIZE_COLUMN_END:
109
+ this.handleResizeColumnEnd(eventArgs);
110
+ }
111
+ if (this.table) {
112
+ const state = this.getSnapshotState(), sheetKey = this.getSheetKey();
113
+ (0, snapshot_1.captureSnapshot)(this.table, state, {
114
+ formulaManager: null === (_f = this.vtableSheet) || void 0 === _f ? void 0 : _f.formulaManager,
115
+ sheetKey: sheetKey
116
+ }), this.setSnapshotState(state);
117
+ }
118
+ }
119
+ }
120
+ startTransaction() {
121
+ this.currentTransaction || (this.currentTransaction = {
122
+ commands: []
123
+ });
124
+ }
125
+ endTransaction() {
126
+ this.currentTransaction && 0 !== this.currentTransaction.commands.length ? (this.pushTransaction(this.currentTransaction),
127
+ this.currentTransaction = null) : this.currentTransaction = null;
128
+ }
129
+ undo() {
130
+ var _a;
131
+ if (!this.table || 0 === this.undoStack.length) return;
132
+ const transaction = this.undoStack.pop();
133
+ this.isReplaying = !0;
134
+ try {
135
+ for (let i = transaction.commands.length - 1; i >= 0; i--) this.applyCommand(transaction.commands[i], "undo");
136
+ } finally {
137
+ this.isReplaying = !1;
138
+ }
139
+ if (this.redoStack.push(transaction), this.table) {
140
+ const state = this.getSnapshotState(), sheetKey = this.getSheetKey();
141
+ (0, snapshot_1.captureSnapshot)(this.table, state, {
142
+ formulaManager: null === (_a = this.vtableSheet) || void 0 === _a ? void 0 : _a.formulaManager,
143
+ sheetKey: sheetKey
144
+ }), this.setSnapshotState(state);
145
+ }
146
+ }
147
+ redo() {
148
+ var _a;
149
+ if (!this.table || 0 === this.redoStack.length) return;
150
+ const transaction = this.redoStack.pop();
151
+ this.isReplaying = !0;
152
+ try {
153
+ for (const cmd of transaction.commands) this.applyCommand(cmd, "redo");
154
+ } finally {
155
+ this.isReplaying = !1;
156
+ }
157
+ if (this.undoStack.push(transaction), this.table) {
158
+ const state = this.getSnapshotState(), sheetKey = this.getSheetKey();
159
+ (0, snapshot_1.captureSnapshot)(this.table, state, {
160
+ formulaManager: null === (_a = this.vtableSheet) || void 0 === _a ? void 0 : _a.formulaManager,
161
+ sheetKey: sheetKey
162
+ }), this.setSnapshotState(state);
163
+ }
164
+ }
165
+ clear() {
166
+ this.undoStack = [], this.redoStack = [], this.currentTransaction = null;
167
+ }
168
+ updateOptions(options) {
169
+ null != options.maxHistory && (this.maxHistory = options.maxHistory, this.trimHistory()),
170
+ null != options.enableCompression && (this.enableCompression = options.enableCompression),
171
+ options.onTransactionPushed && (this.onTransactionPushed = options.onTransactionPushed);
172
+ }
173
+ release() {
174
+ this.clear(), this.unbindFormulaEvents(), this.unbindSortEvents(), this.unbindFilterEvents(),
175
+ this.table = null, this.vtableSheet = null, this.resolvedSheetKey = void 0, this.prevColumnsSnapshot = null,
176
+ this.prevMergeSnapshot = void 0, this.prevRecordsSnapshot = null, this.prevFormulasSnapshot = null,
177
+ this.prevResizedRowHeightsSnapshot = null, this.prevResizedColWidthsSnapshot = null,
178
+ this.lastKnownSortState = null, this.sortStartSnapshot = null, this.sortPending = !1,
179
+ this.sortEventBound = !1, this.sortChangeOrderListenerId = void 0, this.cellPreChangeContent.clear(),
180
+ this.formulaCache.clear(), this.resizeRowStartHeight.clear(), this.resizeColStartWidth.clear(),
181
+ this.filterEventBound = !1, this.filterUnsubscribe = null, this.filterSnapshotCache = void 0,
182
+ this.filterPluginId = void 0;
183
+ }
184
+ ensureFilterEventBindings() {
185
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
186
+ if (!this.table) return;
187
+ const pm = this.table.pluginManager, filterPlugin = null !== (_f = null !== (_d = null !== (_b = null === (_a = null == pm ? void 0 : pm.getPlugin) || void 0 === _a ? void 0 : _a.call(pm, "filter")) && void 0 !== _b ? _b : null === (_c = null == pm ? void 0 : pm.getPluginByName) || void 0 === _c ? void 0 : _c.call(pm, "Filter")) && void 0 !== _d ? _d : null === (_e = null == pm ? void 0 : pm.getPlugin) || void 0 === _e ? void 0 : _e.call(pm, "filter-plugin")) && void 0 !== _f ? _f : null === (_g = null == pm ? void 0 : pm.getPluginByName) || void 0 === _g ? void 0 : _g.call(pm, "filter-plugin");
188
+ if (!(null == filterPlugin ? void 0 : filterPlugin.getFilterSnapshot) || !(null == filterPlugin ? void 0 : filterPlugin.applyFilterSnapshot)) return;
189
+ this.filterEventBound || (this.filterEventBound = !0, this.filterPluginRef = filterPlugin,
190
+ this.filterPluginId = null !== (_h = filterPlugin.id) && void 0 !== _h ? _h : "filter",
191
+ this.filterSnapshotCache = (0, snapshot_1.cloneDeep)(filterPlugin.getFilterSnapshot())),
192
+ this.filterApplySnapshotOriginal || (this.filterApplySnapshotOriginal = null === (_j = filterPlugin.applyFilterSnapshot) || void 0 === _j ? void 0 : _j.bind(filterPlugin),
193
+ this.filterApplySnapshotOriginal && (filterPlugin.applyFilterSnapshot = snapshot => {
194
+ var _a, _b;
195
+ if (this.isReplaying) return this.filterApplySnapshotOriginal(snapshot);
196
+ const oldSnapshot = null !== (_a = this.filterSnapshotCache) && void 0 !== _a ? _a : filterPlugin.getFilterSnapshot();
197
+ this.filterApplyingSnapshot = !0;
198
+ try {
199
+ return this.filterApplySnapshotOriginal(snapshot);
200
+ } finally {
201
+ this.filterApplyingSnapshot = !1;
202
+ const newSnapshot = filterPlugin.getFilterSnapshot();
203
+ if (JSON.stringify(oldSnapshot) !== JSON.stringify(newSnapshot)) {
204
+ const cmd = {
205
+ type: "filter",
206
+ sheetKey: this.getSheetKey(),
207
+ pluginId: null !== (_b = this.filterPluginId) && void 0 !== _b ? _b : "filter",
208
+ oldSnapshot: oldSnapshot,
209
+ newSnapshot: newSnapshot
210
+ };
211
+ this.pushCommand(cmd), this.filterSnapshotCache = (0, snapshot_1.cloneDeep)(newSnapshot);
212
+ } else this.filterSnapshotCache = (0, snapshot_1.cloneDeep)(newSnapshot);
213
+ }
214
+ }));
215
+ const stateManager = null == filterPlugin ? void 0 : filterPlugin.filterStateManager;
216
+ !this.filterUnsubscribe && (null == stateManager ? void 0 : stateManager.subscribe) && (this.filterUnsubscribe = stateManager.subscribe(((_state, action) => {
217
+ var _a, _b;
218
+ if (this.isReplaying) return;
219
+ if (this.filterApplyingSnapshot) return void (this.filterSnapshotCache = (0, snapshot_1.cloneDeep)(filterPlugin.getFilterSnapshot()));
220
+ const t = null == action ? void 0 : action.type;
221
+ if (t !== types_1.FilterActionType.APPLY_FILTERS && t !== types_1.FilterActionType.CLEAR_ALL_FILTERS && t !== types_1.FilterActionType.REMOVE_FILTER && t !== types_1.FilterActionType.DISABLE_FILTER) return;
222
+ const oldSnapshot = null !== (_a = this.filterSnapshotCache) && void 0 !== _a ? _a : filterPlugin.getFilterSnapshot(), newSnapshot = filterPlugin.getFilterSnapshot();
223
+ if (JSON.stringify(oldSnapshot) === JSON.stringify(newSnapshot)) return;
224
+ const cmd = {
225
+ type: "filter",
226
+ sheetKey: this.getSheetKey(),
227
+ pluginId: null !== (_b = this.filterPluginId) && void 0 !== _b ? _b : "filter",
228
+ oldSnapshot: oldSnapshot,
229
+ newSnapshot: newSnapshot
230
+ };
231
+ this.pushCommand(cmd), this.filterSnapshotCache = (0, snapshot_1.cloneDeep)(newSnapshot);
232
+ })));
233
+ }
234
+ unbindFilterEvents() {
235
+ var _a;
236
+ null === (_a = this.filterUnsubscribe) || void 0 === _a || _a.call(this), this.filterUnsubscribe = null,
237
+ this.filterEventBound = !1, this.filterPluginRef && this.filterApplySnapshotOriginal && (this.filterPluginRef.applyFilterSnapshot = this.filterApplySnapshotOriginal),
238
+ this.filterPluginRef = null, this.filterApplySnapshotOriginal = null, this.filterApplyingSnapshot = !1;
239
+ }
240
+ getSheetKey() {
241
+ const resolved = (0, sheet_key_1.resolveSheetKey)({
242
+ vtableSheet: this.vtableSheet,
243
+ table: this.table,
244
+ cached: this.resolvedSheetKey
245
+ });
246
+ return this.resolvedSheetKey = resolved.cached, resolved.sheetKey;
247
+ }
248
+ getSnapshotState() {
249
+ return {
250
+ prevColumnsSnapshot: this.prevColumnsSnapshot,
251
+ prevMergeSnapshot: this.prevMergeSnapshot,
252
+ prevRecordsSnapshot: this.prevRecordsSnapshot,
253
+ prevFormulasSnapshot: this.prevFormulasSnapshot,
254
+ prevResizedRowHeightsSnapshot: this.prevResizedRowHeightsSnapshot,
255
+ prevResizedColWidthsSnapshot: this.prevResizedColWidthsSnapshot
256
+ };
257
+ }
258
+ setSnapshotState(next) {
259
+ var _a, _b, _c;
260
+ this.prevColumnsSnapshot = next.prevColumnsSnapshot, this.prevMergeSnapshot = next.prevMergeSnapshot,
261
+ this.prevRecordsSnapshot = next.prevRecordsSnapshot, this.prevFormulasSnapshot = null !== (_a = next.prevFormulasSnapshot) && void 0 !== _a ? _a : null,
262
+ this.prevResizedRowHeightsSnapshot = null !== (_b = next.prevResizedRowHeightsSnapshot) && void 0 !== _b ? _b : null,
263
+ this.prevResizedColWidthsSnapshot = null !== (_c = next.prevResizedColWidthsSnapshot) && void 0 !== _c ? _c : null;
264
+ }
265
+ pushTransaction(tx) {
266
+ var _a, _b, _c;
267
+ if (0 !== tx.commands.length && (this.undoStack.push(tx), this.redoStack = [], this.trimHistory(),
268
+ this.onTransactionPushed && !this.isReplaying)) {
269
+ (null === (_b = null === (_a = this.table) || void 0 === _a ? void 0 : _a.__vtableSheet) || void 0 === _b ? void 0 : _b.__workbookHistoryReplaying) || this.onTransactionPushed({
270
+ tx: tx,
271
+ sheetKey: this.getSheetKey(),
272
+ table: null !== (_c = this.table) && void 0 !== _c ? _c : void 0
273
+ });
274
+ }
275
+ }
276
+ trimHistory() {
277
+ this.undoStack.length > this.maxHistory && this.undoStack.splice(0, this.undoStack.length - this.maxHistory);
278
+ }
279
+ pushCommand(cmd) {
280
+ this.currentTransaction ? this.currentTransaction.commands.push(cmd) : this.pushTransaction({
281
+ commands: [ cmd ]
282
+ });
283
+ }
284
+ recordExternalCommand(cmd) {
285
+ this.isReplaying || this.pushCommand(cmd);
286
+ }
287
+ tryCompressCellChange(change, sheetKey) {
288
+ if (!this.enableCompression) return !1;
289
+ const targetTx = this.currentTransaction || this.undoStack[this.undoStack.length - 1];
290
+ if (!targetTx || 0 === targetTx.commands.length) return !1;
291
+ const last = targetTx.commands[targetTx.commands.length - 1];
292
+ if (("cell" === last.type || "cells" === last.type) && last.sheetKey === sheetKey) {
293
+ const cells = last.cells;
294
+ if (1 === cells.length && cells[0].row === change.row && cells[0].col === change.col) return cells[0].newContent = change.newContent,
295
+ !0;
296
+ }
297
+ return !1;
298
+ }
299
+ handleBeforeKeydown(eventArgs) {
300
+ var _a, _b, _c, _d, _e, _f;
301
+ const e = eventArgs.event;
302
+ if (!e || !this.table) return;
303
+ if (!(e.ctrlKey || e.metaKey)) return;
304
+ const formulaManager = null === (_a = this.vtableSheet) || void 0 === _a ? void 0 : _a.formulaManager;
305
+ if (null == formulaManager ? void 0 : formulaManager.formulaWorkingOnCell) return;
306
+ if (null === (_b = this.table.editorManager) || void 0 === _b ? void 0 : _b.editingEditor) return;
307
+ const key = e.key.toLowerCase();
308
+ if ("z" === key) {
309
+ const workbookHistory = null === (_d = null === (_c = this.vtableSheet) || void 0 === _c ? void 0 : _c.getWorkbookHistoryManager) || void 0 === _d ? void 0 : _d.call(_c);
310
+ e.shiftKey ? workbookHistory ? workbookHistory.redo() : this.redo() : workbookHistory ? workbookHistory.undo() : this.undo(),
311
+ e.preventDefault(), e.stopPropagation();
312
+ } else if ("y" === key) {
313
+ const workbookHistory = null === (_f = null === (_e = this.vtableSheet) || void 0 === _e ? void 0 : _e.getWorkbookHistoryManager) || void 0 === _f ? void 0 : _f.call(_e);
314
+ workbookHistory ? workbookHistory.redo() : this.redo(), e.preventDefault(), e.stopPropagation();
315
+ }
316
+ }
317
+ handleChangeCellValue(eventArgs) {
318
+ var _a;
319
+ (0, formula_1.captureCellPreChangeContent)({
320
+ sheetKey: this.getSheetKey(),
321
+ row: eventArgs.row,
322
+ col: eventArgs.col,
323
+ currentValue: eventArgs.currentValue,
324
+ formulaManager: null === (_a = this.vtableSheet) || void 0 === _a ? void 0 : _a.formulaManager,
325
+ store: this.cellPreChangeContent
326
+ });
327
+ }
328
+ handleChangeCellValues(eventArgs) {
329
+ var _a;
330
+ if (!this.table) return;
331
+ const sheetKey = this.getSheetKey(), formulaManager = null === (_a = this.vtableSheet) || void 0 === _a ? void 0 : _a.formulaManager, cells = eventArgs.values.map((v => {
332
+ const oldContent = (0, formula_1.popCellPreChangeContent)({
333
+ sheetKey: sheetKey,
334
+ row: v.row,
335
+ col: v.col,
336
+ fallbackOldContent: v.currentValue,
337
+ store: this.cellPreChangeContent
338
+ }), normalizedOld = null == oldContent ? "" : oldContent, normalizedNew = null == v.changedValue ? "" : v.changedValue;
339
+ return {
340
+ row: v.row,
341
+ col: v.col,
342
+ oldContent: normalizedOld,
343
+ newContent: normalizedNew
344
+ };
345
+ })).filter((c => {
346
+ if (c.oldContent === c.newContent) return !1;
347
+ if (!sheetKey || !(null == formulaManager ? void 0 : formulaManager.getCellFormula) || !(null == formulaManager ? void 0 : formulaManager.getCellValue)) return !0;
348
+ if ("string" == typeof c.newContent && c.newContent.startsWith("=")) return !1;
349
+ if (!formulaManager.getCellFormula({
350
+ sheet: sheetKey,
351
+ row: c.row,
352
+ col: c.col
353
+ })) return !0;
354
+ const result = formulaManager.getCellValue({
355
+ sheet: sheetKey,
356
+ row: c.row,
357
+ col: c.col
358
+ }), display = (null == result ? void 0 : result.error) ? "#ERROR!" : null == result ? void 0 : result.value;
359
+ return display !== c.newContent && (null == display || null == c.newContent || String(display) !== String(c.newContent));
360
+ }));
361
+ if (!cells.length) return;
362
+ if (sheetKey && 1 === cells.length && this.tryCompressCellChange(cells[0], sheetKey)) return;
363
+ const cmd = {
364
+ type: "cells",
365
+ sheetKey: sheetKey,
366
+ cells: cells
367
+ };
368
+ this.pushCommand(cmd);
369
+ }
370
+ ensureFormulaEventBindings() {
371
+ var _a, _b, _c, _d, _e;
372
+ if (!this.table || !this.vtableSheet || this.formulaEventBound) return;
373
+ const sheetKey = this.getSheetKey();
374
+ if (!sheetKey) return;
375
+ const worksheet = null !== (_c = null === (_b = (_a = this.vtableSheet).getWorkSheetByKey) || void 0 === _b ? void 0 : _b.call(_a, sheetKey)) && void 0 !== _c ? _c : null === (_e = null === (_d = this.vtableSheet.workSheetInstances) || void 0 === _d ? void 0 : _d.get) || void 0 === _e ? void 0 : _e.call(_d, sheetKey), eventManager = null == worksheet ? void 0 : worksheet.eventManager;
376
+ (null == eventManager ? void 0 : eventManager.on) && (null == eventManager ? void 0 : eventManager.off) && (this.formulaEventBound = !0,
377
+ this.formulaEventManager = eventManager, this.onFormulaAddedHandler = event => {
378
+ if (this.isReplaying) return;
379
+ const cell = null == event ? void 0 : event.cell, formula = null == event ? void 0 : event.formula;
380
+ if (!cell || "number" != typeof cell.row || "number" != typeof cell.col) return;
381
+ if ("string" != typeof formula || !formula.length) return;
382
+ const normalized = formula.startsWith("=") ? formula : `=${formula}`, key = `${sheetKey}:${cell.row}:${cell.col}`, prev = this.formulaCache.get(key), oldContent = (0,
383
+ formula_1.popCellPreChangeContent)({
384
+ sheetKey: sheetKey,
385
+ row: cell.row,
386
+ col: cell.col,
387
+ fallbackOldContent: void 0 !== prev ? prev : "",
388
+ store: this.cellPreChangeContent
389
+ });
390
+ if (oldContent === normalized) return void this.formulaCache.set(key, normalized);
391
+ const cmd = {
392
+ type: "cells",
393
+ sheetKey: sheetKey,
394
+ cells: [ {
395
+ row: cell.row,
396
+ col: cell.col,
397
+ oldContent: oldContent,
398
+ newContent: normalized
399
+ } ]
400
+ };
401
+ this.pushCommand(cmd), this.formulaCache.set(key, normalized);
402
+ }, eventManager.on("formula_added", this.onFormulaAddedHandler));
403
+ }
404
+ ensureSortEventBindings() {
405
+ var _a;
406
+ if (!this.table || this.sortEventBound) return;
407
+ const ds = null === (_a = this.table.internalProps) || void 0 === _a ? void 0 : _a.dataSource;
408
+ (null == ds ? void 0 : ds.on) && (null == ds ? void 0 : ds.off) && (this.sortEventBound = !0,
409
+ this.sortChangeOrderListenerId = ds.on("change_order", (() => {
410
+ var _a;
411
+ if (this.isReplaying || !this.table || !this.sortPending) return;
412
+ const sheetKey = this.getSheetKey(), oldSortState = this.sortStartSnapshot;
413
+ this.sortStartSnapshot = null, this.sortPending = !1;
414
+ const newSortState = this.normalizeSortState(null === (_a = this.table.internalProps) || void 0 === _a ? void 0 : _a.sortState);
415
+ if (JSON.stringify(oldSortState) === JSON.stringify(newSortState)) return void (this.lastKnownSortState = newSortState);
416
+ const cmd = {
417
+ type: "sort",
418
+ sheetKey: sheetKey,
419
+ oldSortState: oldSortState,
420
+ newSortState: newSortState
421
+ };
422
+ this.pushCommand(cmd), this.lastKnownSortState = newSortState;
423
+ })));
424
+ }
425
+ unbindSortEvents() {
426
+ var _a, _b;
427
+ if (!this.sortEventBound) return;
428
+ const ds = null === (_b = null === (_a = this.table) || void 0 === _a ? void 0 : _a.internalProps) || void 0 === _b ? void 0 : _b.dataSource;
429
+ try {
430
+ (null == ds ? void 0 : ds.off) && this.sortChangeOrderListenerId && ds.off(this.sortChangeOrderListenerId);
431
+ } catch (_c) {} finally {
432
+ this.sortEventBound = !1, this.sortChangeOrderListenerId = void 0, this.sortPending = !1,
433
+ this.sortStartSnapshot = null;
434
+ }
435
+ }
436
+ unbindFormulaEvents() {
437
+ if (this.formulaEventBound && this.formulaEventManager) try {
438
+ this.onFormulaAddedHandler && this.formulaEventManager.off("formula_added", this.onFormulaAddedHandler);
439
+ } catch (_a) {} finally {
440
+ this.formulaEventBound = !1, this.formulaEventManager = void 0, this.onFormulaAddedHandler = void 0;
441
+ }
442
+ }
443
+ cloneMergeConfig(input) {
444
+ return Array.isArray(input) ? input.map((i => (0, snapshot_1.cloneDeep)(i))) : input;
445
+ }
446
+ isSameMergeConfig(a, b) {
447
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
448
+ const normalize = v => null == v ? [] : (Array.isArray(v), v), aa = normalize(a), bb = normalize(b);
449
+ if (aa === bb) return !0;
450
+ if (Array.isArray(aa) && Array.isArray(bb)) {
451
+ if (aa.length !== bb.length) return !1;
452
+ for (let i = 0; i < aa.length; i++) {
453
+ const ra = null === (_a = aa[i]) || void 0 === _a ? void 0 : _a.range, rb = null === (_b = bb[i]) || void 0 === _b ? void 0 : _b.range;
454
+ if (!ra || !rb || (null === (_c = ra.start) || void 0 === _c ? void 0 : _c.col) !== (null === (_d = rb.start) || void 0 === _d ? void 0 : _d.col) || (null === (_e = ra.start) || void 0 === _e ? void 0 : _e.row) !== (null === (_f = rb.start) || void 0 === _f ? void 0 : _f.row) || (null === (_g = ra.end) || void 0 === _g ? void 0 : _g.col) !== (null === (_h = rb.end) || void 0 === _h ? void 0 : _h.col) || (null === (_j = ra.end) || void 0 === _j ? void 0 : _j.row) !== (null === (_k = rb.end) || void 0 === _k ? void 0 : _k.row) || (null === (_l = aa[i]) || void 0 === _l ? void 0 : _l.text) !== (null === (_m = bb[i]) || void 0 === _m ? void 0 : _m.text)) return !1;
455
+ }
456
+ return !0;
457
+ }
458
+ return !1;
459
+ }
460
+ handleMergeCells(eventArgs) {
461
+ this.handleMergeConfigChanged(eventArgs);
462
+ }
463
+ handleUnmergeCells(eventArgs) {
464
+ this.handleMergeConfigChanged(eventArgs);
465
+ }
466
+ handleMergeConfigChanged(eventArgs) {
467
+ var _a;
468
+ if (!this.table) return;
469
+ const {startCol: startCol, startRow: startRow, endCol: endCol, endRow: endRow} = eventArgs, before = this.cloneMergeConfig(this.prevMergeSnapshot), after = this.cloneMergeConfig(null === (_a = this.table.options) || void 0 === _a ? void 0 : _a.customMergeCell);
470
+ if (this.isSameMergeConfig(before, after)) return;
471
+ const cmd = {
472
+ type: "merge_cells",
473
+ sheetKey: this.getSheetKey(),
474
+ startCol: startCol,
475
+ startRow: startRow,
476
+ endCol: endCol,
477
+ endRow: endRow,
478
+ oldCustomMergeCell: before,
479
+ newCustomMergeCell: after
480
+ };
481
+ this.pushCommand(cmd);
482
+ }
483
+ handleAddRecord(eventArgs) {
484
+ var _a, _b, _c, _d;
485
+ const cmd = {
486
+ type: "add_record",
487
+ sheetKey: this.getSheetKey(),
488
+ records: Array.isArray(eventArgs.records) ? eventArgs.records.slice() : [],
489
+ recordIndex: eventArgs.recordIndex,
490
+ recordCount: null !== (_a = eventArgs.recordCount) && void 0 !== _a ? _a : Array.isArray(eventArgs.records) ? eventArgs.records.length : 0
491
+ };
492
+ if (this.table && "number" == typeof eventArgs.recordIndex) {
493
+ const start = eventArgs.recordIndex, count = cmd.recordCount, ds = null === (_c = null === (_b = this.table) || void 0 === _b ? void 0 : _b.internalProps) || void 0 === _c ? void 0 : _c.dataSource, rawRecords = null === (_d = null == ds ? void 0 : ds.dataSourceObj) || void 0 === _d ? void 0 : _d.records, viewRecords = this.table.records;
494
+ if (Array.isArray(viewRecords) && viewRecords.length && (cmd.anchorBefore = start > 0 ? viewRecords[start - 1] : void 0,
495
+ cmd.anchorAfter = viewRecords[start + count]), Array.isArray(rawRecords) && Array.isArray(viewRecords)) {
496
+ let rawInsertIndex = rawRecords.length;
497
+ if (0 === viewRecords.length) rawInsertIndex = rawRecords.length; else if (start <= 0) {
498
+ const first = viewRecords[0], idx = rawRecords.indexOf(first);
499
+ rawInsertIndex = idx >= 0 ? idx : 0;
500
+ } else if (start >= viewRecords.length) {
501
+ const last = viewRecords[viewRecords.length - 1], idx = rawRecords.indexOf(last);
502
+ rawInsertIndex = idx >= 0 ? idx + 1 : rawRecords.length;
503
+ } else {
504
+ const prev = viewRecords[start - 1], idx = rawRecords.indexOf(prev);
505
+ rawInsertIndex = idx >= 0 ? idx + 1 : rawRecords.length;
506
+ }
507
+ cmd.rawInsertIndex = rawInsertIndex;
508
+ }
509
+ }
510
+ this.pushCommand(cmd);
511
+ }
512
+ handleDeleteRecord(eventArgs) {
513
+ var _a, _b;
514
+ const sheetKey = this.getSheetKey(), recordIndexs = Array.isArray(eventArgs.recordIndexs) ? eventArgs.recordIndexs.slice() : [ eventArgs.recordIndexs ];
515
+ let deletedRowHeights;
516
+ if (this.table && this.prevResizedRowHeightsSnapshot) {
517
+ const headerCount = this.table.transpose ? this.table.rowHeaderLevelCount : this.table.columnHeaderLevelCount;
518
+ recordIndexs.forEach((idx => {
519
+ var _a;
520
+ if ("number" != typeof idx) return;
521
+ const rowIndex = idx + (null != headerCount ? headerCount : 0), height = null === (_a = this.prevResizedRowHeightsSnapshot) || void 0 === _a ? void 0 : _a[rowIndex];
522
+ "number" == typeof height && (deletedRowHeights || (deletedRowHeights = {}), deletedRowHeights[idx] = height);
523
+ }));
524
+ }
525
+ const oldCustomMergeCell = this.cloneMergeConfig(this.prevMergeSnapshot), newCustomMergeCell = this.cloneMergeConfig(null === (_b = null === (_a = this.table) || void 0 === _a ? void 0 : _a.options) || void 0 === _b ? void 0 : _b.customMergeCell), cmd = {
526
+ type: "delete_record",
527
+ sheetKey: sheetKey,
528
+ records: Array.isArray(eventArgs.records) ? eventArgs.records.slice() : [],
529
+ recordIndexs: recordIndexs,
530
+ deletedRowHeights: deletedRowHeights,
531
+ oldCustomMergeCell: oldCustomMergeCell,
532
+ newCustomMergeCell: newCustomMergeCell
533
+ };
534
+ this.pushCommand(cmd);
535
+ }
536
+ handleUpdateRecord(eventArgs) {
537
+ if (!this.table) return;
538
+ const sheetKey = this.getSheetKey(), recordIndexs = eventArgs.recordIndexs || [], newRecords = Array.isArray(eventArgs.records) ? eventArgs.records.slice() : [];
539
+ if (!this.prevRecordsSnapshot || !Array.isArray(this.prevRecordsSnapshot) || !recordIndexs.length) return;
540
+ const oldRecords = [];
541
+ recordIndexs.forEach((idx => {
542
+ if ("number" == typeof idx) {
543
+ const rec = this.prevRecordsSnapshot[idx];
544
+ oldRecords.push(void 0 !== rec ? (0, snapshot_1.cloneRecord)(rec) : void 0);
545
+ } else oldRecords.push(void 0);
546
+ }));
547
+ const cmd = {
548
+ type: "update_record",
549
+ sheetKey: sheetKey,
550
+ oldRecords: oldRecords,
551
+ newRecords: newRecords,
552
+ recordIndexs: recordIndexs
553
+ };
554
+ this.pushCommand(cmd);
555
+ }
556
+ handleAddColumn(eventArgs) {
557
+ if (!this.table) return;
558
+ const sheetKey = this.getSheetKey(), {columnIndex: columnIndex, columnCount: columnCount, columns: columns} = eventArgs, cmd = {
559
+ type: "add_column",
560
+ sheetKey: sheetKey,
561
+ columnIndex: columnIndex,
562
+ columnCount: columnCount,
563
+ columns: columns.slice(columnIndex, columnIndex + columnCount).map((c => (0, snapshot_1.cloneDeep)(c)))
564
+ };
565
+ this.pushCommand(cmd);
566
+ }
567
+ handleDeleteColumn(eventArgs) {
568
+ if (!this.table) return;
569
+ const sheetKey = this.getSheetKey(), deleteColIndexs = (eventArgs.deleteColIndexs || []).slice(), deletedColumnsFromEvent = eventArgs.deletedColumns, prevColumns = this.prevColumnsSnapshot || [], deletedColumns = Array.isArray(deletedColumnsFromEvent) ? deletedColumnsFromEvent.map((c => (0,
570
+ snapshot_1.cloneDeep)(c))) : [];
571
+ deletedColumns.length || deleteColIndexs.forEach((idx => {
572
+ idx >= 0 && idx < prevColumns.length && deletedColumns.push((0, snapshot_1.cloneDeep)(prevColumns[idx]));
573
+ }));
574
+ let deletedFormulas, deletedColWidths, deletedRecordValues = eventArgs.deletedRecordValues;
575
+ if (Array.isArray(deletedRecordValues) && deletedRecordValues.length || (deletedRecordValues = void 0,
576
+ Array.isArray(this.prevRecordsSnapshot) && this.prevRecordsSnapshot.length && (deletedRecordValues = this.prevRecordsSnapshot.map((rec => Array.isArray(rec) ? deleteColIndexs.map((idx => rec[idx])) : [])),
577
+ deletedRecordValues.every((v => 0 === v.length)) && (deletedRecordValues = void 0))),
578
+ this.prevFormulasSnapshot && deleteColIndexs.length) {
579
+ Object.entries(this.prevFormulasSnapshot).forEach((([cellRef, formula]) => {
580
+ const parsed = (0, formula_1.parseA1Notation)(cellRef);
581
+ parsed && deleteColIndexs.includes(parsed.col) && (deletedFormulas || (deletedFormulas = {}),
582
+ deletedFormulas[cellRef] = formula);
583
+ }));
584
+ }
585
+ this.prevResizedColWidthsSnapshot && deleteColIndexs.length && deleteColIndexs.forEach((idx => {
586
+ var _a;
587
+ const w = null === (_a = this.prevResizedColWidthsSnapshot) || void 0 === _a ? void 0 : _a[idx];
588
+ "number" == typeof w && (deletedColWidths || (deletedColWidths = {}), deletedColWidths[idx] = w);
589
+ }));
590
+ const cmd = {
591
+ type: "delete_column",
592
+ sheetKey: sheetKey,
593
+ deleteColIndexs: deleteColIndexs,
594
+ columns: deletedColumns,
595
+ deletedRecordValues: deletedRecordValues,
596
+ deletedFormulas: deletedFormulas,
597
+ deletedColWidths: deletedColWidths
598
+ };
599
+ this.pushCommand(cmd);
600
+ }
601
+ handleChangeHeaderPosition(eventArgs) {
602
+ var _a;
603
+ const sheetKey = this.getSheetKey(), moving = null !== (_a = eventArgs.movingColumnOrRow) && void 0 !== _a ? _a : "column", cmd = {
604
+ type: "change_header_position",
605
+ sheetKey: sheetKey,
606
+ moving: moving,
607
+ sourceIndex: "column" === moving ? eventArgs.source.col : eventArgs.source.row,
608
+ targetIndex: "column" === moving ? eventArgs.target.col : eventArgs.target.row
609
+ };
610
+ this.pushCommand(cmd);
611
+ }
612
+ normalizeSortState(input) {
613
+ if (!input) return null;
614
+ if (Array.isArray(input)) {
615
+ const list = input.filter(Boolean).map((s => ({
616
+ field: s.field,
617
+ order: s.order
618
+ }))).filter((s => void 0 !== s.field && s.order && "normal" !== s.order));
619
+ return list.length ? list : null;
620
+ }
621
+ const s = input;
622
+ return void 0 !== s.field && s.order && "normal" !== s.order ? {
623
+ field: s.field,
624
+ order: s.order
625
+ } : null;
626
+ }
627
+ handleSortClick(_eventArgs) {
628
+ this.table && (this.sortStartSnapshot = this.lastKnownSortState, this.sortPending = !0,
629
+ setTimeout((() => {
630
+ this.sortPending && (this.sortPending = !1, this.sortStartSnapshot = null);
631
+ }), 0));
632
+ }
633
+ handleResizeRow(eventArgs) {
634
+ var _a, _b;
635
+ if (!this.table) return;
636
+ const row = eventArgs.row;
637
+ if (!this.resizeRowStartHeight.has(row)) {
638
+ const oldHeight = null === (_b = (_a = this.table).getRowHeight) || void 0 === _b ? void 0 : _b.call(_a, row);
639
+ "number" == typeof oldHeight && this.resizeRowStartHeight.set(row, oldHeight);
640
+ }
641
+ }
642
+ handleResizeRowEnd(eventArgs) {
643
+ var _a;
644
+ if (!this.table) return;
645
+ const sheetKey = this.getSheetKey(), row = eventArgs.row, newHeight = eventArgs.rowHeight, oldHeight = null !== (_a = this.resizeRowStartHeight.get(row)) && void 0 !== _a ? _a : newHeight;
646
+ if (this.resizeRowStartHeight.delete(row), "number" == typeof oldHeight && "number" == typeof newHeight && oldHeight === newHeight) return;
647
+ const cmd = {
648
+ type: "resize_row",
649
+ sheetKey: sheetKey,
650
+ row: row,
651
+ oldHeight: oldHeight,
652
+ newHeight: newHeight
653
+ };
654
+ this.pushCommand(cmd);
655
+ }
656
+ handleResizeColumn(eventArgs) {
657
+ var _a, _b;
658
+ if (!this.table) return;
659
+ const col = eventArgs.col;
660
+ if (!this.resizeColStartWidth.has(col)) {
661
+ const oldWidth = null === (_b = (_a = this.table).getColWidth) || void 0 === _b ? void 0 : _b.call(_a, col);
662
+ "number" == typeof oldWidth && this.resizeColStartWidth.set(col, oldWidth);
663
+ }
664
+ }
665
+ handleResizeColumnEnd(eventArgs) {
666
+ var _a, _b, _c, _d;
667
+ if (!this.table) return;
668
+ const sheetKey = this.getSheetKey(), col = eventArgs.col, newWidth = null !== (_a = (eventArgs.colWidths || [])[col]) && void 0 !== _a ? _a : null === (_c = (_b = this.table).getColWidth) || void 0 === _c ? void 0 : _c.call(_b, col), oldWidth = null !== (_d = this.resizeColStartWidth.get(col)) && void 0 !== _d ? _d : newWidth;
669
+ if (this.resizeColStartWidth.delete(col), "number" == typeof oldWidth && "number" == typeof newWidth && oldWidth === newWidth) return;
670
+ const cmd = {
671
+ type: "resize_column",
672
+ sheetKey: sheetKey,
673
+ col: col,
674
+ oldWidth: oldWidth,
675
+ newWidth: newWidth
676
+ };
677
+ this.pushCommand(cmd);
678
+ }
679
+ applyCommand(cmd, direction) {
680
+ this.table && (0, replay_1.replayCommand)({
681
+ table: this.table,
682
+ vtableSheet: this.vtableSheet,
683
+ cmd: cmd,
684
+ direction: direction,
685
+ deleteRecordsByReference: records => this.deleteRecordsByReference(records)
686
+ });
687
+ }
688
+ deleteRecordsByReference(records) {
689
+ if (!this.table || !(null == records ? void 0 : records.length)) return;
690
+ const tableRecords = this.table.records || [], indexs = [];
691
+ records.forEach((rec => {
692
+ const idx = tableRecords.indexOf(rec);
693
+ idx >= 0 && indexs.push(idx);
694
+ })), indexs.length && this.table.deleteRecords && this.table.deleteRecords(indexs);
695
+ }
696
+ }
697
+
698
+ exports.HistoryPlugin = HistoryPlugin;
699
+ //# sourceMappingURL=history-plugin.js.map