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