@univerjs/sheets-table 1.3.0 → 1.4.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 (82) hide show
  1. package/README.md +23 -0
  2. package/lib/cjs/facade.js +3 -7
  3. package/lib/cjs/index.js +45 -4960
  4. package/lib/cjs/locale/ar-SA.js +1 -2
  5. package/lib/cjs/locale/ca-ES.js +1 -2
  6. package/lib/cjs/locale/de-DE.js +1 -2
  7. package/lib/cjs/locale/en-US.js +1 -2
  8. package/lib/cjs/locale/es-ES.js +1 -2
  9. package/lib/cjs/locale/fa-IR.js +1 -2
  10. package/lib/cjs/locale/fr-FR.js +1 -2
  11. package/lib/cjs/locale/id-ID.js +1 -2
  12. package/lib/cjs/locale/it-IT.js +1 -2
  13. package/lib/cjs/locale/ja-JP.js +1 -2
  14. package/lib/cjs/locale/ko-KR.js +1 -2
  15. package/lib/cjs/locale/pl-PL.js +1 -2
  16. package/lib/cjs/locale/pt-BR.js +1 -2
  17. package/lib/cjs/locale/ru-RU.js +1 -2
  18. package/lib/cjs/locale/sk-SK.js +1 -2
  19. package/lib/cjs/locale/vi-VN.js +1 -2
  20. package/lib/cjs/locale/zh-CN.js +1 -2
  21. package/lib/cjs/locale/zh-HK.js +1 -2
  22. package/lib/cjs/locale/zh-TW.js +1 -2
  23. package/lib/cjs/plugin-D9zM3t0a.js +5296 -0
  24. package/lib/cjs/worker.js +9 -0
  25. package/lib/es/facade.js +3 -6
  26. package/lib/es/index.js +1 -4916
  27. package/lib/es/locale/ar-SA.js +1 -2
  28. package/lib/es/locale/ca-ES.js +1 -2
  29. package/lib/es/locale/de-DE.js +1 -2
  30. package/lib/es/locale/en-US.js +1 -2
  31. package/lib/es/locale/es-ES.js +1 -2
  32. package/lib/es/locale/fa-IR.js +1 -2
  33. package/lib/es/locale/fr-FR.js +1 -2
  34. package/lib/es/locale/id-ID.js +1 -2
  35. package/lib/es/locale/it-IT.js +1 -2
  36. package/lib/es/locale/ja-JP.js +1 -2
  37. package/lib/es/locale/ko-KR.js +1 -2
  38. package/lib/es/locale/pl-PL.js +1 -2
  39. package/lib/es/locale/pt-BR.js +1 -2
  40. package/lib/es/locale/ru-RU.js +1 -2
  41. package/lib/es/locale/sk-SK.js +1 -2
  42. package/lib/es/locale/vi-VN.js +1 -2
  43. package/lib/es/locale/zh-CN.js +1 -2
  44. package/lib/es/locale/zh-HK.js +1 -2
  45. package/lib/es/locale/zh-TW.js +1 -2
  46. package/lib/es/plugin-D3R6dh5q.js +5039 -0
  47. package/lib/es/worker.js +3 -0
  48. package/lib/facade.js +3 -6
  49. package/lib/index.js +1 -4916
  50. package/lib/locale/ar-SA.js +1 -2
  51. package/lib/locale/ca-ES.js +1 -2
  52. package/lib/locale/de-DE.js +1 -2
  53. package/lib/locale/en-US.js +1 -2
  54. package/lib/locale/es-ES.js +1 -2
  55. package/lib/locale/fa-IR.js +1 -2
  56. package/lib/locale/fr-FR.js +1 -2
  57. package/lib/locale/id-ID.js +1 -2
  58. package/lib/locale/it-IT.js +1 -2
  59. package/lib/locale/ja-JP.js +1 -2
  60. package/lib/locale/ko-KR.js +1 -2
  61. package/lib/locale/pl-PL.js +1 -2
  62. package/lib/locale/pt-BR.js +1 -2
  63. package/lib/locale/ru-RU.js +1 -2
  64. package/lib/locale/sk-SK.js +1 -2
  65. package/lib/locale/vi-VN.js +1 -2
  66. package/lib/locale/zh-CN.js +1 -2
  67. package/lib/locale/zh-HK.js +1 -2
  68. package/lib/locale/zh-TW.js +1 -2
  69. package/lib/plugin-D3R6dh5q.js +5039 -0
  70. package/lib/types/commands/mutations/add-sheet-table.mutation.d.ts +2 -1
  71. package/lib/types/controllers/sheets-table.controller.d.ts +1 -0
  72. package/lib/types/controllers/table-theme.factory.d.ts +25 -25
  73. package/lib/types/models/filter-util/condition.d.ts +1 -1
  74. package/lib/types/models/filter-util/date-filter-util.d.ts +1 -1
  75. package/lib/types/models/table-dxf.d.ts +25 -0
  76. package/lib/types/models/table-manager.d.ts +2 -2
  77. package/lib/types/models/table.d.ts +4 -4
  78. package/lib/types/services/table.service.d.ts +2 -2
  79. package/lib/types/worker.d.ts +16 -0
  80. package/lib/umd/index.js +1 -1
  81. package/lib/worker.js +3 -0
  82. package/package.json +16 -11
package/lib/index.js CHANGED
@@ -1,4918 +1,3 @@
1
- import { BooleanNumber, BorderStyleTypes, CellValueType, ColorKit, CommandType, DEFAULT_STYLES, DateSystem, DependentOn, Disposable, ErrorService, FilterSelectionMode, FormulaType, ICommandService, IConfigService, ILogService, IPermissionService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, Plugin, RTree, RecordValueType, Rectangle, Tools, UniverInstanceType, customNameCharacterCheck, excelSerialToDateTime, generateRandomId, getColorStyle, getRecordValueKey, merge, numfmt, regexp, registerDependencies, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
2
- import { IActiveDirtyManagerService, IDefinedNamesService, ISheetRowFilteredService, LexerTreeBuilder, RemoveSuperTableMutation, SetSuperTableMutation, extractFormulaError, serializeRange } from "@univerjs/engine-formula";
3
- import { AddRangeThemeMutation, CopySheetCommand, IExclusiveRangeService, INTERCEPTOR_POINT, InsertColCommand, InsertColMutation, InsertRowCommand, InsertRowMutation, MoveRangeCommand, RangeThemeStyle, RefRangeService, RemoveColCommand, RemoveColMutation, RemoveRangeThemeMutation, RemoveRowCommand, RemoveRowMutation, RemoveSheetCommand, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SheetInterceptorService, SheetRangeThemeModel, SheetRangeThemeService, SheetsSelectionsService, UniverSheetsPlugin, WorkbookEditablePermission, ZebraCrossingCacheController, checkRangesEditablePermission, getMoveRangeCommandMutations, getMoveRangeUndoRedoMutations, getSheetCommandTarget } from "@univerjs/sheets";
4
- import { BehaviorSubject, Subject, filter, switchMap } from "rxjs";
1
+ import { A as processStyleWithBorderStyle, B as TableConditionTypeEnum, C as SheetTableService, D as SHEET_TABLE_CUSTOM_THEME_PREFIX, E as getTableRecordValue, F as isRecordTableFilter, H as TableNumberCompareTypeEnum, I as SheetsTableButtonStateEnum, L as SheetsTableSortStateEnum, M as isColorTableFilter, N as isConditionFilter, O as TABLE_FILTER_EMPTY_VALUE, P as isManualTableFilter, R as TableColumnDataTypeEnum, S as AddSheetTableMutation, T as compileTableRecordFilter, U as TableStringCompareTypeEnum, V as TableDateCompareTypeEnum, _ as SetSheetTableFilterMutation, a as SheetTableInsertRowAtCommand, b as AddSheetTableCommand, c as SheetTableRemoveColumnAtCommand, d as SetSheetTableSortStateCommand, f as SetSheetTableFilterCommand, g as DeleteSheetTableCommand, h as RemoveTableThemeCommand, i as SheetTableInsertColumnAtCommand, j as getExistingNamesSet, k as customEmptyThemeWithBorderStyle, l as SheetTableRemoveRowCommand, m as validateSheetTableName, n as SheetsTableThemeController, o as SheetTableInsertRowCommand, p as SetSheetTableCommand, r as SheetTableInsertColCommand, s as SheetTableRemoveColCommand, t as UniverSheetsTablePlugin, u as SheetsTableController, v as AddTableThemeCommand, w as TableManager, x as DeleteSheetTableMutation, y as SetSheetTableMutation, z as TableColumnFilterTypeEnum } from "./plugin-D3R6dh5q.js";
5
2
 
6
- //#region src/types/enum.ts
7
- /**
8
- * Copyright 2023-present DreamNum Co., Ltd.
9
- *
10
- * Licensed under the Apache License, Version 2.0 (the "License");
11
- * you may not use this file except in compliance with the License.
12
- * You may obtain a copy of the License at
13
- *
14
- * http://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- let TableColumnDataTypeEnum = /* @__PURE__ */ function(TableColumnDataTypeEnum) {
23
- TableColumnDataTypeEnum["None"] = "none";
24
- TableColumnDataTypeEnum["String"] = "string";
25
- TableColumnDataTypeEnum["Number"] = "number";
26
- TableColumnDataTypeEnum["Date"] = "date";
27
- TableColumnDataTypeEnum["Bool"] = "bool";
28
- TableColumnDataTypeEnum["Checkbox"] = "checkbox";
29
- TableColumnDataTypeEnum["List"] = "list";
30
- return TableColumnDataTypeEnum;
31
- }({});
32
- let TableColumnFilterTypeEnum = /* @__PURE__ */ function(TableColumnFilterTypeEnum) {
33
- TableColumnFilterTypeEnum["manual"] = "manual";
34
- TableColumnFilterTypeEnum["condition"] = "condition";
35
- TableColumnFilterTypeEnum["color"] = "color";
36
- TableColumnFilterTypeEnum["record"] = "record";
37
- return TableColumnFilterTypeEnum;
38
- }({});
39
- let TableConditionTypeEnum = /* @__PURE__ */ function(TableConditionTypeEnum) {
40
- TableConditionTypeEnum["Date"] = "date";
41
- TableConditionTypeEnum["Number"] = "number";
42
- TableConditionTypeEnum["String"] = "string";
43
- TableConditionTypeEnum["Logic"] = "logic";
44
- return TableConditionTypeEnum;
45
- }({});
46
- let TableNumberCompareTypeEnum = /* @__PURE__ */ function(TableNumberCompareTypeEnum) {
47
- TableNumberCompareTypeEnum["Equal"] = "equal";
48
- TableNumberCompareTypeEnum["NotEqual"] = "notEqual";
49
- TableNumberCompareTypeEnum["GreaterThan"] = "greaterThan";
50
- TableNumberCompareTypeEnum["GreaterThanOrEqual"] = "greaterThanOrEqual";
51
- TableNumberCompareTypeEnum["LessThan"] = "lessThan";
52
- TableNumberCompareTypeEnum["LessThanOrEqual"] = "lessThanOrEqual";
53
- TableNumberCompareTypeEnum["Between"] = "between";
54
- TableNumberCompareTypeEnum["NotBetween"] = "notBetween";
55
- TableNumberCompareTypeEnum["Above"] = "above";
56
- TableNumberCompareTypeEnum["Below"] = "below";
57
- TableNumberCompareTypeEnum["TopN"] = "topN";
58
- return TableNumberCompareTypeEnum;
59
- }({});
60
- let TableStringCompareTypeEnum = /* @__PURE__ */ function(TableStringCompareTypeEnum) {
61
- TableStringCompareTypeEnum["Equal"] = "equal";
62
- TableStringCompareTypeEnum["NotEqual"] = "notEqual";
63
- TableStringCompareTypeEnum["Contains"] = "contains";
64
- TableStringCompareTypeEnum["NotContains"] = "notContains";
65
- TableStringCompareTypeEnum["StartsWith"] = "startsWith";
66
- TableStringCompareTypeEnum["EndsWith"] = "endsWith";
67
- return TableStringCompareTypeEnum;
68
- }({});
69
- let TableDateCompareTypeEnum = /* @__PURE__ */ function(TableDateCompareTypeEnum) {
70
- TableDateCompareTypeEnum["Equal"] = "equal";
71
- TableDateCompareTypeEnum["NotEqual"] = "notEqual";
72
- TableDateCompareTypeEnum["After"] = "after";
73
- TableDateCompareTypeEnum["AfterOrEqual"] = "afterOrEqual";
74
- TableDateCompareTypeEnum["Before"] = "before";
75
- TableDateCompareTypeEnum["BeforeOrEqual"] = "beforeOrEqual";
76
- TableDateCompareTypeEnum["Between"] = "between";
77
- TableDateCompareTypeEnum["NotBetween"] = "notBetween";
78
- TableDateCompareTypeEnum["Today"] = "today";
79
- TableDateCompareTypeEnum["Yesterday"] = "yesterday";
80
- TableDateCompareTypeEnum["Tomorrow"] = "tomorrow";
81
- TableDateCompareTypeEnum["ThisWeek"] = "thisWeek";
82
- TableDateCompareTypeEnum["LastWeek"] = "lastWeek";
83
- TableDateCompareTypeEnum["NextWeek"] = "nextWeek";
84
- TableDateCompareTypeEnum["ThisMonth"] = "thisMonth";
85
- TableDateCompareTypeEnum["LastMonth"] = "lastMonth";
86
- TableDateCompareTypeEnum["NextMonth"] = "nextMonth";
87
- TableDateCompareTypeEnum["ThisQuarter"] = "thisQuarter";
88
- TableDateCompareTypeEnum["LastQuarter"] = "lastQuarter";
89
- TableDateCompareTypeEnum["NextQuarter"] = "nextQuarter";
90
- TableDateCompareTypeEnum["ThisYear"] = "thisYear";
91
- TableDateCompareTypeEnum["LastYear"] = "lastYear";
92
- TableDateCompareTypeEnum["NextYear"] = "nextYear";
93
- TableDateCompareTypeEnum["YearToDate"] = "yearToDate";
94
- TableDateCompareTypeEnum["Quarter"] = "quarter";
95
- TableDateCompareTypeEnum["Month"] = "month";
96
- TableDateCompareTypeEnum["M1"] = "m1";
97
- TableDateCompareTypeEnum["M2"] = "m2";
98
- TableDateCompareTypeEnum["M3"] = "m3";
99
- TableDateCompareTypeEnum["M4"] = "m4";
100
- TableDateCompareTypeEnum["M5"] = "m5";
101
- TableDateCompareTypeEnum["M6"] = "m6";
102
- TableDateCompareTypeEnum["M7"] = "m7";
103
- TableDateCompareTypeEnum["M8"] = "m8";
104
- TableDateCompareTypeEnum["M9"] = "m9";
105
- TableDateCompareTypeEnum["M10"] = "m10";
106
- TableDateCompareTypeEnum["M11"] = "m11";
107
- TableDateCompareTypeEnum["M12"] = "m12";
108
- TableDateCompareTypeEnum["Q1"] = "q1";
109
- TableDateCompareTypeEnum["Q2"] = "q2";
110
- TableDateCompareTypeEnum["Q3"] = "q3";
111
- TableDateCompareTypeEnum["Q4"] = "q4";
112
- return TableDateCompareTypeEnum;
113
- }({});
114
- /**
115
- * Represents the pivot cell style type enum
116
- */
117
- let SheetsTableButtonStateEnum = /* @__PURE__ */ function(SheetsTableButtonStateEnum) {
118
- SheetsTableButtonStateEnum[SheetsTableButtonStateEnum["FilteredSortNone"] = 1] = "FilteredSortNone";
119
- SheetsTableButtonStateEnum[SheetsTableButtonStateEnum["FilteredSortAsc"] = 2] = "FilteredSortAsc";
120
- SheetsTableButtonStateEnum[SheetsTableButtonStateEnum["FilteredSortDesc"] = 3] = "FilteredSortDesc";
121
- SheetsTableButtonStateEnum[SheetsTableButtonStateEnum["FilterNoneSortNone"] = 4] = "FilterNoneSortNone";
122
- SheetsTableButtonStateEnum[SheetsTableButtonStateEnum["FilterNoneSortAsc"] = 5] = "FilterNoneSortAsc";
123
- SheetsTableButtonStateEnum[SheetsTableButtonStateEnum["FilterNoneSortDesc"] = 6] = "FilterNoneSortDesc";
124
- return SheetsTableButtonStateEnum;
125
- }({});
126
- let SheetsTableSortStateEnum = /* @__PURE__ */ function(SheetsTableSortStateEnum) {
127
- SheetsTableSortStateEnum["Asc"] = "asc";
128
- SheetsTableSortStateEnum["Desc"] = "desc";
129
- SheetsTableSortStateEnum["None"] = "none";
130
- return SheetsTableSortStateEnum;
131
- }({});
132
-
133
- //#endregion
134
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
135
- function _typeof(o) {
136
- "@babel/helpers - typeof";
137
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
138
- return typeof o;
139
- } : function(o) {
140
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
141
- }, _typeof(o);
142
- }
143
-
144
- //#endregion
145
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
146
- function toPrimitive(t, r) {
147
- if ("object" != _typeof(t) || !t) return t;
148
- var e = t[Symbol.toPrimitive];
149
- if (void 0 !== e) {
150
- var i = e.call(t, r || "default");
151
- if ("object" != _typeof(i)) return i;
152
- throw new TypeError("@@toPrimitive must return a primitive value.");
153
- }
154
- return ("string" === r ? String : Number)(t);
155
- }
156
-
157
- //#endregion
158
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
159
- function toPropertyKey(t) {
160
- var i = toPrimitive(t, "string");
161
- return "symbol" == _typeof(i) ? i : i + "";
162
- }
163
-
164
- //#endregion
165
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
166
- function _defineProperty(e, r, t) {
167
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
168
- value: t,
169
- enumerable: !0,
170
- configurable: !0,
171
- writable: !0
172
- }) : e[r] = t, e;
173
- }
174
-
175
- //#endregion
176
- //#region src/models/table-column.ts
177
- var TableColumn = class {
178
- constructor(id, name) {
179
- _defineProperty(this, "dataType", void 0);
180
- _defineProperty(this, "id", void 0);
181
- _defineProperty(this, "displayName", void 0);
182
- _defineProperty(this, "formula", void 0);
183
- _defineProperty(this, "formulaIsArray", void 0);
184
- _defineProperty(this, "totalsRowLabel", void 0);
185
- _defineProperty(this, "totalsRowFunction", void 0);
186
- _defineProperty(this, "totalsRowFormula", void 0);
187
- _defineProperty(this, "showFilterButton", void 0);
188
- _defineProperty(this, "meta", void 0);
189
- _defineProperty(this, "style", void 0);
190
- this.id = id;
191
- this.displayName = name;
192
- this.dataType = "string";
193
- this.formula = "";
194
- this.showFilterButton = true;
195
- this.meta = {};
196
- this.style = {};
197
- }
198
- getMeta() {
199
- return this.meta;
200
- }
201
- setMeta(meta) {
202
- this.meta = meta;
203
- }
204
- getDisplayName() {
205
- return this.displayName;
206
- }
207
- toJSON() {
208
- return {
209
- id: this.id,
210
- displayName: this.displayName,
211
- dataType: this.dataType,
212
- formula: this.formula,
213
- formulaIsArray: this.formulaIsArray,
214
- totalsRowLabel: this.totalsRowLabel,
215
- totalsRowFunction: this.totalsRowFunction,
216
- totalsRowFormula: this.totalsRowFormula,
217
- showFilterButton: this.showFilterButton,
218
- meta: this.meta,
219
- style: this.style
220
- };
221
- }
222
- fromJSON(json) {
223
- this.id = json.id;
224
- this.displayName = json.displayName;
225
- this.dataType = json.dataType;
226
- this.formula = json.formula;
227
- this.formulaIsArray = json.formulaIsArray;
228
- this.totalsRowLabel = json.totalsRowLabel;
229
- this.totalsRowFunction = json.totalsRowFunction;
230
- this.totalsRowFormula = json.totalsRowFormula;
231
- this.showFilterButton = json.showFilterButton ?? true;
232
- this.meta = json.meta;
233
- this.style = json.style;
234
- }
235
- isShowFilterButton() {
236
- return this.showFilterButton;
237
- }
238
- };
239
-
240
- //#endregion
241
- //#region src/util.ts
242
- function getColumnName(columnIndex, columnText) {
243
- return `${columnText} ${columnIndex}`;
244
- }
245
- const BooleanTrue = "TRUE";
246
- const BooleanFalse = "FALSE";
247
- const getStringFromDataStream$1 = (data) => {
248
- var _data$body;
249
- return ((_data$body = data.body) === null || _data$body === void 0 ? void 0 : _data$body.dataStream.replace(/\r\n$/, "")) || "";
250
- };
251
- /**
252
- * transform cell data to dimension name
253
- * @param cellData the sheet cell data
254
- * @param styles workBook styles collection
255
- * @param patternInfoRecord The cache record for pattern info
256
- * @returns {string} The dimension name
257
- */
258
- function convertCellDataToString(cellData) {
259
- if (cellData) {
260
- const { v, t, p } = cellData;
261
- if (p) return getStringFromDataStream$1(p);
262
- if ((t === CellValueType.FORCE_STRING || t === CellValueType.STRING) && v !== void 0 && v !== null) return String(v);
263
- else if (t === CellValueType.BOOLEAN) return v ? BooleanTrue : BooleanFalse;
264
- else if (t === CellValueType.NUMBER) return String(v);
265
- else {
266
- if (typeof v === "boolean") return v ? BooleanTrue : BooleanFalse;
267
- return v === void 0 || v === null ? "" : String(v);
268
- }
269
- }
270
- return "";
271
- }
272
- function getTableFilterState(tableFilter, sortState) {
273
- if (tableFilter !== void 0 && tableFilter !== null) switch (sortState) {
274
- case "asc": return 2;
275
- case "desc": return 3;
276
- default: return 1;
277
- }
278
- else switch (sortState) {
279
- case "asc": return 5;
280
- case "desc": return 6;
281
- default: return 4;
282
- }
283
- }
284
- function isConditionFilter(filter) {
285
- if (!filter) return false;
286
- return filter.filterType === "condition";
287
- }
288
- function isManualTableFilter(filter) {
289
- if (!filter) return false;
290
- return filter.filterType === "manual";
291
- }
292
- function isColorTableFilter(filter) {
293
- if (!filter) return false;
294
- return filter.filterType === "color";
295
- }
296
- function isRecordTableFilter(filter) {
297
- if (!filter) return false;
298
- return filter.filterType === "record";
299
- }
300
- /**
301
- * Get existing names including sheet names, table names and defined names to check for duplicates table name.
302
- */
303
- function getExistingNamesSet(unitId, options) {
304
- const { univerInstanceService, tableManager, definedNamesService } = options;
305
- const existingNamesSet = /* @__PURE__ */ new Set();
306
- const workbook = univerInstanceService === null || univerInstanceService === void 0 ? void 0 : univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
307
- if (workbook) workbook.getSheets().forEach((sheet) => {
308
- existingNamesSet.add(sheet.getName().toLowerCase());
309
- });
310
- const tableList = tableManager === null || tableManager === void 0 ? void 0 : tableManager.getTableList(unitId);
311
- if (tableList && tableList.length > 0) tableList.forEach((tableItem) => {
312
- existingNamesSet.add(tableItem.name.toLowerCase());
313
- });
314
- const definedNames = definedNamesService === null || definedNamesService === void 0 ? void 0 : definedNamesService.getDefinedNameMap(unitId);
315
- if (definedNames) Object.values(definedNames).forEach((definedName) => {
316
- existingNamesSet.add(definedName.name.toLowerCase());
317
- });
318
- return existingNamesSet;
319
- }
320
-
321
- //#endregion
322
- //#region src/config/config.ts
323
- const tableDefaultBorderStyle = {
324
- s: BorderStyleTypes.THIN,
325
- cl: { rgb: "rgb(95, 101, 116)" }
326
- };
327
- const SHEETS_TABLE_PLUGIN_CONFIG_KEY = "sheets-table.config";
328
- const configSymbol = Symbol(SHEETS_TABLE_PLUGIN_CONFIG_KEY);
329
- const defaultPluginConfig = {};
330
-
331
- //#endregion
332
- //#region src/controllers/table-theme.factory.ts
333
- const customEmptyThemeWithBorderStyle = {
334
- headerRowStyle: { bd: { t: tableDefaultBorderStyle } },
335
- headerColumnStyle: { bd: { l: tableDefaultBorderStyle } },
336
- lastColumnStyle: { bd: { r: tableDefaultBorderStyle } },
337
- lastRowStyle: { bd: { b: tableDefaultBorderStyle } }
338
- };
339
- const processStyleWithBorderStyle = (key, style) => {
340
- if (key === "headerRowStyle") {
341
- if (!style.bd) return {
342
- ...style,
343
- bd: { t: tableDefaultBorderStyle }
344
- };
345
- } else if (key === "lastRowStyle") {
346
- if (!style.bd) return {
347
- ...style,
348
- bd: { b: tableDefaultBorderStyle }
349
- };
350
- } else if (key === "lastColumnStyle") {
351
- if (!style.bd) return {
352
- ...style,
353
- bd: { r: tableDefaultBorderStyle }
354
- };
355
- } else if (key === "headerColumnStyle") {
356
- if (!style.bd) return {
357
- ...style,
358
- bd: { l: tableDefaultBorderStyle }
359
- };
360
- }
361
- return style;
362
- };
363
- const tableDefaultThemeStyleArr = [
364
- [[
365
- "#6280F9",
366
- "#FFFFFF",
367
- "#EEF2FF",
368
- "#DCE4FF"
369
- ], ["#fff"]],
370
- [[
371
- "#16BDCA",
372
- "#FFFFFF",
373
- "#EDFAFA",
374
- "#AFECEF"
375
- ], ["#000"]],
376
- [[
377
- "#31C48D",
378
- "#FFFFFF",
379
- "#F3FAF7",
380
- "#BCF0DA"
381
- ], ["#fff"]],
382
- [[
383
- "#AC94FA",
384
- "#FFFFFF",
385
- "#F6F5FF",
386
- "#EDEBFE"
387
- ], ["#fff"]],
388
- [[
389
- "#F17EBB",
390
- "#FFFFFF",
391
- "#FDF2F8",
392
- "#FCE8F3"
393
- ], ["#fff"]],
394
- [[
395
- "#F98080",
396
- "#FFFFFF",
397
- "#FDF2F2",
398
- "#FDE8E8"
399
- ], ["#fff"]]
400
- ];
401
- const tableThemeConfig = tableDefaultThemeStyleArr.map((item, index) => {
402
- const [backgroundArr, colorArr] = item;
403
- const [headerRowBg, firstRowBg, secondRowBg, lastRowBg] = backgroundArr;
404
- const [headerCl] = colorArr;
405
- return {
406
- name: `table-default-${index}`,
407
- style: {
408
- headerRowStyle: {
409
- bg: { rgb: headerRowBg },
410
- cl: { rgb: headerCl },
411
- bd: { t: tableDefaultBorderStyle }
412
- },
413
- headerColumnStyle: { bd: { l: tableDefaultBorderStyle } },
414
- firstRowStyle: { bg: { rgb: firstRowBg } },
415
- secondRowStyle: { bg: { rgb: secondRowBg } },
416
- lastRowStyle: {
417
- bg: { rgb: lastRowBg },
418
- bd: { b: tableDefaultBorderStyle }
419
- },
420
- lastColumnStyle: { bd: { r: tableDefaultBorderStyle } }
421
- }
422
- };
423
- });
424
-
425
- //#endregion
426
- //#region src/const.ts
427
- /**
428
- * Copyright 2023-present DreamNum Co., Ltd.
429
- *
430
- * Licensed under the Apache License, Version 2.0 (the "License");
431
- * you may not use this file except in compliance with the License.
432
- * You may obtain a copy of the License at
433
- *
434
- * http://www.apache.org/licenses/LICENSE-2.0
435
- *
436
- * Unless required by applicable law or agreed to in writing, software
437
- * distributed under the License is distributed on an "AS IS" BASIS,
438
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
439
- * See the License for the specific language governing permissions and
440
- * limitations under the License.
441
- */
442
- const PLUGIN_NAME = "SHEET_TABLE_PLUGIN";
443
- const FEATURE_TABLE_ID = "SHEET_TABLE";
444
- const SHEET_TABLE_CUSTOM_THEME_PREFIX = "table-custom";
445
- const TABLE_FILTER_EMPTY_VALUE = "__UNIVER_TABLE_FILTER_EMPTY__";
446
-
447
- //#endregion
448
- //#region src/models/filter-util/date-filter-util.ts
449
- /**
450
- * The provided date is a date in Q1 of the year.
451
- * @param {Date} date - The date to compare.
452
- * @returns {boolean} return the date is match
453
- */
454
- const dateQ1 = (date) => {
455
- return date.getMonth() <= 2;
456
- };
457
- /**
458
- * The provided date is a date in Q2 of the year.
459
- * @param {Date} date - The date to compare.
460
- * @returns {boolean} return the date is match
461
- */
462
- const dateQ2 = (date) => {
463
- const month = date.getMonth();
464
- return month > 2 && month <= 5;
465
- };
466
- /**
467
- * The provided date is a date in Q3 of the year.
468
- * @param {Date} date - The date to compare.
469
- * @returns {boolean} return the date is match
470
- */
471
- const dateQ3 = (date) => {
472
- const month = date.getMonth();
473
- return month > 5 && month <= 8;
474
- };
475
- /**
476
- * The provided date is a date in Q4 of the year.
477
- * @param {Date} date - The date to compare.
478
- * @returns {boolean} return the date is match
479
- */
480
- const dateQ4 = (date) => {
481
- const month = date.getMonth();
482
- return month > 8 && month <= 11;
483
- };
484
- /**
485
- * The provided date is a date in January.
486
- * @param {Date} date - The date to compare.
487
- * @returns {boolean} return the date is match
488
- */
489
- const dateM1 = (date) => {
490
- return date.getMonth() === 0;
491
- };
492
- /**
493
- * The provided date is a date in February.
494
- * @param {Date} date - The date to compare.
495
- * @returns {boolean} return the date is match
496
- */
497
- const dateM2 = (date) => {
498
- return date.getMonth() === 1;
499
- };
500
- /**
501
- * The provided date is a date in March.
502
- * @param {Date} date - The date to compare.
503
- * @returns {boolean} return the date is match
504
- */
505
- const dateM3 = (date) => {
506
- return date.getMonth() === 2;
507
- };
508
- /**
509
- * The provided date is a date in April.
510
- * @param {Date} date - The date to compare.
511
- * @returns {boolean} return the date is match
512
- */
513
- const dateM4 = (date) => {
514
- return date.getMonth() === 3;
515
- };
516
- /**
517
- * The provided date is a date in May.
518
- * @param {Date} date - The date to compare.
519
- * @returns {boolean} return the date is match
520
- */
521
- const dateM5 = (date) => {
522
- return date.getMonth() === 4;
523
- };
524
- /**
525
- * The provided date is a date in June.
526
- * @param {Date} date - The date to compare.
527
- * @returns {boolean} return the date is match
528
- */
529
- const dateM6 = (date) => {
530
- return date.getMonth() === 5;
531
- };
532
- /**
533
- * The provided date is a date in July.
534
- * @param {Date} date - The date to compare.
535
- * @returns {boolean} return the date is match
536
- */
537
- const dateM7 = (date) => {
538
- return date.getMonth() === 6;
539
- };
540
- /**
541
- * The provided date is a date in August.
542
- * @param {Date} date - The date to compare.
543
- * @returns {boolean} return the date is match
544
- */
545
- const dateM8 = (date) => {
546
- return date.getMonth() === 7;
547
- };
548
- /**
549
- * The provided date is a date in September.
550
- * @param {Date} date - The date to compare.
551
- * @returns {boolean} return the date is match
552
- */
553
- const dateM9 = (date) => {
554
- return date.getMonth() === 8;
555
- };
556
- /**
557
- * The provided date is a date in October.
558
- * @param {Date} date - The date to compare.
559
- * @returns {boolean} return the date is match
560
- */
561
- const dateM10 = (date) => {
562
- return date.getMonth() === 9;
563
- };
564
- /**
565
- * The provided date is a date in November.
566
- * @param {Date} date - The date to compare.
567
- * @returns {boolean} return the date is match
568
- */
569
- const dateM11 = (date) => {
570
- return date.getMonth() === 10;
571
- };
572
- /**
573
- * The provided date is a date in December.
574
- * @param {Date} date - The date to compare.
575
- * @returns {boolean} return the date is match
576
- */
577
- const dateM12 = (date) => {
578
- return date.getMonth() === 11;
579
- };
580
- /**
581
- * The provided date is today.
582
- * @param {Date} expectedDate - The date to compare.
583
- * @param {Date} [anchorTime] - The reference date.
584
- * @returns {boolean} return the date is match
585
- */
586
- const today = (expectedDate, anchorTime = /* @__PURE__ */ new Date()) => {
587
- return expectedDate.toDateString() === anchorTime.toDateString();
588
- };
589
- /**
590
- * The provided date is tomorrow.
591
- * @param {Date} date - The date to compare.
592
- * @param {Date} [anchorTime] - The reference date.
593
- * @returns {boolean} return the date is match
594
- */
595
- const tomorrow = (date, anchorTime = /* @__PURE__ */ new Date()) => {
596
- const tomorrow = new Date(anchorTime);
597
- tomorrow.setDate(tomorrow.getDate() + 1);
598
- return date.toDateString() === tomorrow.toDateString();
599
- };
600
- /**
601
- * The provided date is yesterday.
602
- * @param {Date} date - The date to compare.
603
- * @param {Date} [anchorTime] - The reference date.
604
- * @returns {boolean} return the date is match
605
- */
606
- const yesterday = (date, anchorTime = /* @__PURE__ */ new Date()) => {
607
- const yesterday = new Date(anchorTime);
608
- yesterday.setDate(yesterday.getDate() - 1);
609
- return date.toDateString() === yesterday.toDateString();
610
- };
611
- /**
612
- * Get the start date of the week for the provided date.
613
- * @param {Date} date - The date to get the week start.
614
- * @returns {Date} The start date of the week.
615
- */
616
- const getWeekStart = (date) => {
617
- const day = date.getDay();
618
- const diff = date.getDate() - day + (day === 0 ? -6 : 1);
619
- const weekStart = new Date(date);
620
- weekStart.setDate(diff);
621
- return weekStart;
622
- };
623
- /**
624
- * The provided date is in the current week.
625
- * @param {Date} date - The date to compare.
626
- * @param {Date} [anchorTime] - The reference date.
627
- * @returns {boolean} return the date is match
628
- */
629
- const thisWeek = (date, anchorTime = /* @__PURE__ */ new Date()) => {
630
- const weekStart = getWeekStart(date);
631
- const anchorTimeWeekStart = getWeekStart(anchorTime);
632
- return weekStart.toDateString() === anchorTimeWeekStart.toDateString();
633
- };
634
- /**
635
- * The provided date is in the next week.
636
- * @param {Date} date - The date to compare.
637
- * @param {Date} [anchorTime] - The reference date.
638
- * @returns {boolean} return the date is match
639
- */
640
- const nextWeek = (date, anchorTime = /* @__PURE__ */ new Date()) => {
641
- const weekStart = getWeekStart(date);
642
- const anchorTimeNextWeekStart = getWeekStart(anchorTime);
643
- anchorTimeNextWeekStart.setDate(anchorTimeNextWeekStart.getDate() + 7);
644
- return weekStart.toDateString() === anchorTimeNextWeekStart.toDateString();
645
- };
646
- /**
647
- * The provided date is in the last week.
648
- * @param {Date} date - The date to compare.
649
- * @param {Date} [anchorTime] - The reference date.
650
- * @returns {boolean} return the date is match
651
- */
652
- const lastWeek = (date, anchorTime = /* @__PURE__ */ new Date()) => {
653
- const weekStart = getWeekStart(date);
654
- const anchorTimeLastWeekStart = getWeekStart(anchorTime);
655
- anchorTimeLastWeekStart.setDate(anchorTimeLastWeekStart.getDate() - 7);
656
- return weekStart.toDateString() === anchorTimeLastWeekStart.toDateString();
657
- };
658
- /**
659
- * The provided date is in the current month.
660
- * @param {Date} date - The date to compare.
661
- * @param {Date} [anchorTime] - The reference date.
662
- * @returns {boolean} return the date is match
663
- */
664
- const thisMonth = (date, anchorTime = /* @__PURE__ */ new Date()) => {
665
- return date.getFullYear() === anchorTime.getFullYear() && date.getMonth() === anchorTime.getMonth();
666
- };
667
- /**
668
- * Get the start date of the month for the provided date.
669
- * @param {Date} date - The date to get the month start.
670
- * @returns {Date} The start date of the month.
671
- */
672
- const getMonthStart = (date) => {
673
- const monthStart = new Date(date);
674
- monthStart.setHours(0, 0, 0, 0);
675
- monthStart.setDate(1);
676
- return monthStart;
677
- };
678
- /**
679
- * The provided date is in the next month.
680
- * @param {Date} date - The date to compare.
681
- * @param {Date} [anchorTime] - The reference date.
682
- * @returns {boolean} return the date is match
683
- */
684
- const nextMonth = (date, anchorTime = /* @__PURE__ */ new Date()) => {
685
- const nextMonthStart = new Date(anchorTime);
686
- nextMonthStart.setHours(0, 0, 0, 0);
687
- nextMonthStart.setMonth(nextMonthStart.getMonth() + 1, 1);
688
- const monthEnd = new Date(nextMonthStart);
689
- monthEnd.setMonth(monthEnd.getMonth() + 1);
690
- const dateTime = date.getTime();
691
- return dateTime >= nextMonthStart.getTime() && dateTime < monthEnd.getTime();
692
- };
693
- /**
694
- * The provided date is in the last month.
695
- * @param {Date} date - The date to compare.
696
- * @param {Date} [anchorTime] - The reference date.
697
- * @returns {boolean} return the date is match
698
- */
699
- const lastMonth = (date, anchorTime = /* @__PURE__ */ new Date()) => {
700
- const monthEnd = getMonthStart(anchorTime);
701
- const lastMonthStart = new Date(monthEnd);
702
- lastMonthStart.setMonth(lastMonthStart.getMonth() - 1);
703
- const dateTime = date.getTime();
704
- return dateTime >= lastMonthStart.getTime() && dateTime < monthEnd.getTime();
705
- };
706
- /**
707
- * Get the start date of the quarter for the provided date.
708
- * @param {Date} date - The date to get the quarter start.
709
- * @returns {Date} The start date of the quarter.
710
- */
711
- const getQuarterStart = (date) => {
712
- const quarterStart = new Date(date);
713
- quarterStart.setHours(0, 0, 0, 0);
714
- quarterStart.setDate(1);
715
- const month = quarterStart.getMonth();
716
- quarterStart.setMonth(month - month % 3);
717
- return quarterStart;
718
- };
719
- /**
720
- * The provided date is in the current quarter.
721
- * @param {Date} date - The date to compare.
722
- * @param {Date} [anchorTime] - The reference date.
723
- * @returns {boolean} return the date is match
724
- */
725
- const thisQuarter = (date, anchorTime = /* @__PURE__ */ new Date()) => {
726
- const quarterStart = getQuarterStart(anchorTime);
727
- const nextQuarterStart = new Date(quarterStart);
728
- nextQuarterStart.setMonth(nextQuarterStart.getMonth() + 3);
729
- const dateTime = date.getTime();
730
- return dateTime >= quarterStart.getTime() && dateTime < nextQuarterStart.getTime();
731
- };
732
- /**
733
- * The provided date is in the next quarter.
734
- * @param {Date} date - The date to compare.
735
- * @param {Date} [anchorTime] - The reference date.
736
- * @returns {boolean} return the date is match
737
- */
738
- const nextQuarter = (date, anchorTime = /* @__PURE__ */ new Date()) => {
739
- const quarterStart = getQuarterStart(anchorTime);
740
- const nextQuarterStart = new Date(quarterStart);
741
- nextQuarterStart.setMonth(nextQuarterStart.getMonth() + 3);
742
- const nextQuarterEnd = new Date(nextQuarterStart);
743
- nextQuarterEnd.setMonth(nextQuarterEnd.getMonth() + 3);
744
- const dateTime = date.getTime();
745
- return dateTime >= nextQuarterStart.getTime() && dateTime < nextQuarterEnd.getTime();
746
- };
747
- /**
748
- * The provided date is in the last quarter.
749
- * @param {Date} date - The date to compare.
750
- * @param {Date} [anchorTime] - The reference date.
751
- * @returns {boolean} return the date is match
752
- */
753
- const lastQuarter = (date, anchorTime = /* @__PURE__ */ new Date()) => {
754
- const quarterStart = getQuarterStart(anchorTime);
755
- const lastQuarterStart = new Date(quarterStart);
756
- lastQuarterStart.setMonth(lastQuarterStart.getMonth() - 3);
757
- const dateTime = date.getTime();
758
- return dateTime >= lastQuarterStart.getTime() && dateTime < quarterStart.getTime();
759
- };
760
- /**
761
- * The provided date is in the current year.
762
- * @param {Date} date - The date to compare.
763
- * @param {Date} [anchorTime] - The reference date.
764
- * @returns {boolean} return the date is match
765
- */
766
- const thisYear = (date, anchorTime = /* @__PURE__ */ new Date()) => {
767
- return date.getFullYear() === anchorTime.getFullYear();
768
- };
769
- /**
770
- * The provided date is in the next year.
771
- * @param {Date} date - The date to compare.
772
- * @param {Date} [anchorTime] - The reference date.
773
- * @returns {boolean} return the date is match
774
- */
775
- const nextYear = (date, anchorTime = /* @__PURE__ */ new Date()) => {
776
- return date.getFullYear() === anchorTime.getFullYear() + 1;
777
- };
778
- /**
779
- * The provided date is in the last year.
780
- * @param {Date} date - The date to compare.
781
- * @param {Date} [anchorTime] - The reference date.
782
- * @returns {boolean} return the date is match
783
- */
784
- const lastYear = (date, anchorTime = /* @__PURE__ */ new Date()) => {
785
- return date.getFullYear() === anchorTime.getFullYear() - 1;
786
- };
787
- /**
788
- * The provided date is in the year to date.
789
- * @param {Date} date - The date to compare.
790
- * @param {Date} [anchorTime] - The reference date.
791
- * @returns {boolean} return the date is match
792
- */
793
- const yearToDate = (date, anchorTime = /* @__PURE__ */ new Date()) => {
794
- const yearStart = new Date(anchorTime);
795
- yearStart.setHours(0, 0, 0, 0);
796
- yearStart.setMonth(0, 1);
797
- const dateTime = date.getTime();
798
- return dateTime >= yearStart.getTime() && dateTime < anchorTime.getTime();
799
- };
800
- function getDateFilterExecuteFunc(filterInfo) {
801
- switch (filterInfo.compareType) {
802
- case "equal": {
803
- const expected = new Date(filterInfo.expectedValue);
804
- return (date) => date.getTime() === expected.getTime();
805
- }
806
- case "notEqual": {
807
- const expected = new Date(filterInfo.expectedValue);
808
- return (date) => date.getTime() !== expected.getTime();
809
- }
810
- case "after": {
811
- const expected = new Date(filterInfo.expectedValue);
812
- return (date) => date.getTime() > expected.getTime();
813
- }
814
- case "before": {
815
- const expected = new Date(filterInfo.expectedValue);
816
- return (date) => date.getTime() < expected.getTime();
817
- }
818
- case "afterOrEqual": {
819
- const expected = new Date(filterInfo.expectedValue);
820
- return (date) => date.getTime() >= expected.getTime();
821
- }
822
- case "beforeOrEqual": {
823
- const expected = new Date(filterInfo.expectedValue);
824
- return (date) => date.getTime() <= expected.getTime();
825
- }
826
- case "between": return (date) => {
827
- const [start, end] = filterInfo.expectedValue;
828
- return date.getTime() >= new Date(start).getTime() && date.getTime() <= new Date(end).getTime();
829
- };
830
- case "notBetween": return (date) => {
831
- const [start, end] = filterInfo.expectedValue;
832
- return date.getTime() < new Date(start).getTime() || date.getTime() > new Date(end).getTime();
833
- };
834
- case "today": {
835
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
836
- return (date) => today(date, anchorTime);
837
- }
838
- case "yesterday": {
839
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
840
- return (date) => yesterday(date, anchorTime);
841
- }
842
- case "tomorrow": {
843
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
844
- return (date) => tomorrow(date, anchorTime);
845
- }
846
- case "thisWeek": {
847
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
848
- return (date) => thisWeek(date, anchorTime);
849
- }
850
- case "lastWeek": {
851
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
852
- return (date) => lastWeek(date, anchorTime);
853
- }
854
- case "nextWeek": {
855
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
856
- return (date) => nextWeek(date, anchorTime);
857
- }
858
- case "thisMonth": {
859
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
860
- return (date) => thisMonth(date, anchorTime);
861
- }
862
- case "lastMonth": {
863
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
864
- return (date) => lastMonth(date, anchorTime);
865
- }
866
- case "nextMonth": {
867
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
868
- return (date) => nextMonth(date, anchorTime);
869
- }
870
- case "thisQuarter": {
871
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
872
- return (date) => thisQuarter(date, anchorTime);
873
- }
874
- case "lastQuarter": {
875
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
876
- return (date) => lastQuarter(date, anchorTime);
877
- }
878
- case "nextQuarter": {
879
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
880
- return (date) => nextQuarter(date, anchorTime);
881
- }
882
- case "thisYear": {
883
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
884
- return (date) => thisYear(date, anchorTime);
885
- }
886
- case "lastYear": {
887
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
888
- return (date) => lastYear(date, anchorTime);
889
- }
890
- case "nextYear": {
891
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
892
- return (date) => nextYear(date, anchorTime);
893
- }
894
- case "yearToDate": {
895
- const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
896
- return (date) => yearToDate(date, anchorTime);
897
- }
898
- case "m1": return dateM1;
899
- case "m2": return dateM2;
900
- case "m3": return dateM3;
901
- case "m4": return dateM4;
902
- case "m5": return dateM5;
903
- case "m6": return dateM6;
904
- case "m7": return dateM7;
905
- case "m8": return dateM8;
906
- case "m9": return dateM9;
907
- case "m10": return dateM10;
908
- case "m11": return dateM11;
909
- case "m12": return dateM12;
910
- case "q1": return dateQ1;
911
- case "q2": return dateQ2;
912
- case "q3": return dateQ3;
913
- case "q4": return dateQ4;
914
- default: throw new Error("Unsupported compare type");
915
- }
916
- }
917
-
918
- //#endregion
919
- //#region src/models/filter-util/top-n.ts
920
- /**
921
- * Copyright 2023-present DreamNum Co., Ltd.
922
- *
923
- * Licensed under the Apache License, Version 2.0 (the "License");
924
- * you may not use this file except in compliance with the License.
925
- * You may obtain a copy of the License at
926
- *
927
- * http://www.apache.org/licenses/LICENSE-2.0
928
- *
929
- * Unless required by applicable law or agreed to in writing, software
930
- * distributed under the License is distributed on an "AS IS" BASIS,
931
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
932
- * See the License for the specific language governing permissions and
933
- * limitations under the License.
934
- */
935
- /**
936
- * @description Represents a heap data structure.
937
- * A heap is a complete binary tree that satisfies the heap property.
938
- * The heap property states that the parent node is always smaller or bigger than its children.
939
- * The root node is the smallest or biggest element in the heap.
940
- * The heap is used to find the kth largest or smallest element in a list.
941
- * A array can be used to represent a heap.
942
- * The root node is at index 0, and the left child of a node at index i is at index 2i + 1.
943
- * The right child of a node at index i is at index 2i + 2.
944
- * The parent node of a node at index i is at index (i - 1) / 2.
945
- * @example
946
- * const maxHeap = [5, 3, 4, 1, 2];
947
- * // const minHeap = [6, 8, 7, 10, 9];
948
- * // the root node in maxHeap is 5
949
- * // the root child is 3, 4, then the child of 3 is 1, 2
950
- */
951
- var Heap = class {
952
- /**
953
- * Initializes a new instance of the Heap class.
954
- */
955
- constructor() {
956
- _defineProperty(this, "heap", void 0);
957
- this.heap = [];
958
- }
959
- /**
960
- * Swaps the elements at the given indices in the heap.
961
- * @param index1 The index of the first element.
962
- * @param index2 The index of the second element.
963
- */
964
- swap(index1, index2) {
965
- const temp = this.heap[index1];
966
- this.heap[index1] = this.heap[index2];
967
- this.heap[index2] = temp;
968
- }
969
- /**
970
- * Returns the index of the parent node for the given index.
971
- * @param index The index of the node.
972
- * @returns The index of the parent node.
973
- */
974
- getParentIndex(index) {
975
- return Math.floor((index - 1) / 2);
976
- }
977
- /**
978
- * Returns the index of the left child node for the given index.
979
- * @param index The index of the node.
980
- * @returns The index of the left child node.
981
- */
982
- getLeftIndex(index) {
983
- return index * 2 + 1;
984
- }
985
- /**
986
- * Returns the index of the right child node for the given index.
987
- * @param index The index of the node.
988
- * @returns The index of the right child node.
989
- */
990
- getRightIndex(index) {
991
- return index * 2 + 2;
992
- }
993
- /**
994
- * Returns the number of elements in the heap.
995
- * @returns The number of elements in the heap.
996
- */
997
- size() {
998
- return this.heap.length;
999
- }
1000
- /**
1001
- * Returns the minimum value in the heap without removing it.
1002
- * @returns The minimum value in the heap.
1003
- */
1004
- peek() {
1005
- return this.heap[0];
1006
- }
1007
- /**
1008
- * @description Returns whether the heap includes the given value.
1009
- * @param {number} value The value to be checked.
1010
- * @returns {boolean} return true if the heap includes the given value
1011
- */
1012
- include(value) {
1013
- return this.heap.includes(value);
1014
- }
1015
- };
1016
- /**
1017
- * @description Represents a min heap data structure.
1018
- * in MinHeap, the parent node is always smaller than its children.
1019
- * The root node is the smallest element in the heap.
1020
- * The min heap is used to find the kth largest element in a list.
1021
- */
1022
- var MinHeap = class extends Heap {
1023
- /**
1024
- * Initializes a new instance of the MinHeap class.
1025
- */
1026
- constructor() {
1027
- super();
1028
- }
1029
- /**
1030
- * Moves the element at the given index up the heap until it satisfies the min heap property.
1031
- * @param index The index of the element to be shifted up.
1032
- */
1033
- shiftUp(index) {
1034
- if (index === 0) return;
1035
- const parentIndex = this.getParentIndex(index);
1036
- if (this.heap[parentIndex] > this.heap[index]) {
1037
- this.swap(parentIndex, index);
1038
- this.shiftUp(parentIndex);
1039
- }
1040
- }
1041
- /**
1042
- * Moves the element at the given index down the heap until it satisfies the min heap property.
1043
- * @param index The index of the element to be shifted down.
1044
- */
1045
- shiftDown(index) {
1046
- const leftIndex = this.getLeftIndex(index);
1047
- const rightIndex = this.getRightIndex(index);
1048
- if (this.heap[leftIndex] < this.heap[index]) {
1049
- this.swap(leftIndex, index);
1050
- this.shiftDown(leftIndex);
1051
- }
1052
- if (this.heap[rightIndex] < this.heap[index]) {
1053
- this.swap(rightIndex, index);
1054
- this.shiftDown(rightIndex);
1055
- }
1056
- }
1057
- /**
1058
- * Inserts a new value into the min heap.
1059
- * @param value The value to be inserted.
1060
- */
1061
- insert(value) {
1062
- this.heap.push(value);
1063
- this.shiftUp(this.heap.length - 1);
1064
- }
1065
- /**
1066
- * Removes and returns the minimum value from the min heap.
1067
- */
1068
- pop() {
1069
- this.heap[0] = this.heap.pop();
1070
- this.shiftDown(0);
1071
- }
1072
- };
1073
- /**
1074
- * Returns the kth largest element from the given list using a min heap.
1075
- * @param {number[]} list The list of numbers.
1076
- * @param {number} k The value of k.
1077
- * @returns The kth largest element.
1078
- */
1079
- const getLargestK = (list, k) => {
1080
- const minHeap = new MinHeap();
1081
- for (const item of list) {
1082
- minHeap.insert(item);
1083
- if (minHeap.size() > k) minHeap.pop();
1084
- }
1085
- return minHeap.heap;
1086
- };
1087
-
1088
- //#endregion
1089
- //#region src/models/filter-util/number-filter-util.ts
1090
- /**
1091
- * @description Checks if a value is above the average.
1092
- * @param {number} value - The value to check.
1093
- * @param {number} average - The average value.
1094
- * @returns {boolean} A boolean value indicating whether the value is above the average.
1095
- */
1096
- const above = (value, average) => {
1097
- return value > average;
1098
- };
1099
- /**
1100
- * @description Checks if a value is below the average.
1101
- * @param {number} value - The value to check.
1102
- * @param {number} average - The average value.
1103
- * @returns {boolean} A boolean value indicating whether the value is below the average.
1104
- */
1105
- const below = (value, average) => {
1106
- return value < average;
1107
- };
1108
- /**
1109
- * @description Gets the largest N values from a list and checks if the expected value is included.
1110
- * @param {number[]} list - The list of numbers.
1111
- * @param {number} top - The number of top values to retrieve.
1112
- * @param {number} expectedValue - The expected value to check for inclusion.
1113
- * @returns {boolean} A boolean value indicating whether the expected value is included in the top N values.
1114
- */
1115
- const getTopN = (list, top, expectedValue) => {
1116
- return getLargestK(list, top).includes(expectedValue);
1117
- };
1118
- function getNumberFilterExecuteFunc(filter, calculatedOptions) {
1119
- switch (filter.compareType) {
1120
- case "equal": {
1121
- const expectedValue = Number(filter.expectedValue);
1122
- return (value) => value === expectedValue;
1123
- }
1124
- case "notEqual": {
1125
- const expectedValue = Number(filter.expectedValue);
1126
- return (value) => value !== expectedValue;
1127
- }
1128
- case "greaterThan": {
1129
- const expectedValue = Number(filter.expectedValue);
1130
- return (value) => value > expectedValue;
1131
- }
1132
- case "greaterThanOrEqual": {
1133
- const expectedValue = Number(filter.expectedValue);
1134
- return (value) => value >= expectedValue;
1135
- }
1136
- case "lessThan": {
1137
- const expectedValue = Number(filter.expectedValue);
1138
- return (value) => value < expectedValue;
1139
- }
1140
- case "lessThanOrEqual": {
1141
- const expectedValue = Number(filter.expectedValue);
1142
- return (value) => value <= expectedValue;
1143
- }
1144
- case "between": {
1145
- const [min, max] = filter.expectedValue;
1146
- const minValue = Number(min);
1147
- const maxValue = Number(max);
1148
- if (minValue > maxValue) return (value) => value >= maxValue && value <= minValue;
1149
- return (value) => value >= minValue && value <= maxValue;
1150
- }
1151
- case "notBetween": {
1152
- const [min, max] = filter.expectedValue;
1153
- const minValue = Number(min);
1154
- const maxValue = Number(max);
1155
- if (minValue > maxValue) return (value) => value < maxValue || value > minValue;
1156
- return (value) => value < minValue || value > maxValue;
1157
- }
1158
- case "above": {
1159
- const average = calculatedOptions.average;
1160
- return (value) => above(value, average);
1161
- }
1162
- case "below": {
1163
- const average = calculatedOptions.average;
1164
- return (value) => below(value, average);
1165
- }
1166
- case "topN": {
1167
- const list = calculatedOptions.list;
1168
- const top = Number(filter.expectedValue);
1169
- return (value) => getTopN(list, top, value);
1170
- }
1171
- }
1172
- }
1173
-
1174
- //#endregion
1175
- //#region src/models/filter-util/text-filter-util.ts
1176
- const textEqual = (compareValue, expectedValue) => {
1177
- return regexp.createFromWildcard(expectedValue).test(compareValue);
1178
- };
1179
- const textNotEqual = (compareValue, expectedValue) => {
1180
- return !regexp.createFromWildcard(expectedValue).test(compareValue);
1181
- };
1182
- const textContain = (compareValue, expectedValue) => {
1183
- return regexp.createFromWildcard(`*${expectedValue}*`).test(compareValue);
1184
- };
1185
- const textNotContain = (compareValue, expectedValue) => {
1186
- return !regexp.createFromWildcard(`*${expectedValue}*`).test(compareValue);
1187
- };
1188
- const textStartWith = (compareValue, expectedValue) => {
1189
- return regexp.createFromWildcard(`${expectedValue}*`).test(compareValue);
1190
- };
1191
- const textEndWith = (compareValue, expectedValue) => {
1192
- return regexp.createFromWildcard(`*${expectedValue}`).test(compareValue);
1193
- };
1194
- function getTextFilterExecuteFunc(filter) {
1195
- switch (filter.compareType) {
1196
- case "equal": return (value) => textEqual(value, filter.expectedValue);
1197
- case "notEqual": return (value) => textNotEqual(value, filter.expectedValue);
1198
- case "contains": return (value) => textContain(value, filter.expectedValue);
1199
- case "notContains": return (value) => textNotContain(value, filter.expectedValue);
1200
- case "startsWith": return (value) => textStartWith(value, filter.expectedValue);
1201
- case "endsWith": return (value) => textEndWith(value, filter.expectedValue);
1202
- default:
1203
- console.error(`Unknown filter operator: ${filter.compareType}`);
1204
- return (value) => true;
1205
- }
1206
- }
1207
-
1208
- //#endregion
1209
- //#region src/models/filter-util/condition.ts
1210
- const NumberDynamicFilterCompareTypeSet = /* @__PURE__ */ new Set([
1211
- "above",
1212
- "below",
1213
- "topN"
1214
- ]);
1215
- const DateDynamicFilterCompareTypeSet = /* @__PURE__ */ new Set([
1216
- "today",
1217
- "yesterday",
1218
- "tomorrow",
1219
- "thisWeek",
1220
- "lastWeek",
1221
- "nextWeek",
1222
- "thisMonth",
1223
- "lastMonth",
1224
- "nextMonth",
1225
- "thisQuarter",
1226
- "lastQuarter",
1227
- "nextQuarter",
1228
- "nextYear",
1229
- "thisYear",
1230
- "lastYear",
1231
- "yearToDate"
1232
- ]);
1233
- function isNumberDynamicFilter(compareType) {
1234
- return NumberDynamicFilterCompareTypeSet.has(compareType);
1235
- }
1236
- function getConditionExecuteFunc(filter, calculatedOptions) {
1237
- if (isNumberDynamicFilter(filter.filterInfo.compareType)) return (value) => true;
1238
- else switch (filter.filterInfo.conditionType) {
1239
- case "date": return getDateFilterExecuteFunc(filter.filterInfo);
1240
- case "number": return getNumberFilterExecuteFunc(filter.filterInfo, calculatedOptions);
1241
- case "string": return getTextFilterExecuteFunc(filter.filterInfo);
1242
- case "logic":
1243
- default: return (value) => true;
1244
- }
1245
- }
1246
- function getCellValueWithConditionType(sheet, row, col, conditionType, dateSystem = DateSystem.Date1900) {
1247
- switch (conditionType) {
1248
- case "date": {
1249
- const dateNumber = getNumberCellValue$1(sheet, row, col);
1250
- return dateNumber == null ? null : excelSerialToDateTimeLocal(dateNumber, dateSystem);
1251
- }
1252
- case "number": return getNumberCellValue$1(sheet, row, col);
1253
- case "string":
1254
- default: return getStringCellValue(sheet, row, col);
1255
- }
1256
- }
1257
- const getStringFromDataStream = (data) => {
1258
- var _data$body;
1259
- return ((_data$body = data.body) === null || _data$body === void 0 ? void 0 : _data$body.dataStream.replace(/\r\n$/, "")) || "";
1260
- };
1261
- function getStringCellValue(sheet, row, col) {
1262
- const cellData = sheet.getCell(row, col);
1263
- if (!cellData) return null;
1264
- const { v, t, p } = cellData;
1265
- if (p) return getStringFromDataStream(p);
1266
- if (typeof v === "string") {
1267
- if (t === CellValueType.BOOLEAN) return v.toUpperCase();
1268
- return v;
1269
- }
1270
- if (typeof v === "number") {
1271
- if (t === CellValueType.BOOLEAN) return v ? "TRUE" : "FALSE";
1272
- return v;
1273
- }
1274
- if (typeof v === "boolean") return v ? "TRUE" : "FALSE";
1275
- if (v === void 0) return;
1276
- return String(v);
1277
- }
1278
- function getNumberCellValue$1(sheet, row, col) {
1279
- const cellData = sheet.getCell(row, col);
1280
- if (!cellData) return null;
1281
- const { v, t, p } = cellData;
1282
- if (p) return null;
1283
- if (typeof v === "string" && t === CellValueType.NUMBER) return Number(sheet.getCellRaw(row, col).v);
1284
- return Number(v);
1285
- }
1286
- function excelSerialToDateTimeLocal(serial, dateSystem = DateSystem.Date1900) {
1287
- const utcDate = excelSerialToDateTime(serial, dateSystem);
1288
- if (Number.isNaN(utcDate.getTime())) return utcDate;
1289
- return new Date(utcDate.getUTCFullYear(), utcDate.getUTCMonth(), utcDate.getUTCDate(), utcDate.getUTCHours(), utcDate.getUTCMinutes(), utcDate.getUTCSeconds(), utcDate.getUTCMilliseconds());
1290
- }
1291
-
1292
- //#endregion
1293
- //#region src/models/filter-util/record-filter.ts
1294
- /**
1295
- * Formula errors are recognized when the cell retains formula, shared-formula, or intercepted array-formula context.
1296
- */
1297
- function getTableRecordValue(sheet, row, column) {
1298
- const cell = sheet.getCell(row, column);
1299
- const error = extractFormulaError(cell, (cell === null || cell === void 0 ? void 0 : cell.isInArrayFormulaRange) === true);
1300
- if (error !== null) return {
1301
- type: RecordValueType.Error,
1302
- value: error
1303
- };
1304
- if (!cell) return { type: RecordValueType.Blank };
1305
- if (cell.p) return {
1306
- type: RecordValueType.String,
1307
- value: convertCellDataToString(cell)
1308
- };
1309
- const value = cell.v;
1310
- if (value === null || value === void 0) return { type: RecordValueType.Blank };
1311
- if (cell.t === CellValueType.STRING || cell.t === CellValueType.FORCE_STRING) return {
1312
- type: RecordValueType.String,
1313
- value: String(value)
1314
- };
1315
- if (cell.t === CellValueType.BOOLEAN) return {
1316
- type: RecordValueType.Boolean,
1317
- value: getBooleanValue(value)
1318
- };
1319
- if (cell.t === CellValueType.NUMBER || typeof value === "number") {
1320
- var _sheet$getComposedCel;
1321
- const numberValue = getFiniteNumberValue(getNumberCellValue(sheet, row, column, value, cell.t === CellValueType.NUMBER, cell.isInArrayFormulaRange === true));
1322
- const pattern = (_sheet$getComposedCel = sheet.getComposedCellStyleByCellData(row, column, cell).n) === null || _sheet$getComposedCel === void 0 ? void 0 : _sheet$getComposedCel.pattern;
1323
- return pattern && numfmt.getFormatInfo(pattern).isDate ? {
1324
- type: RecordValueType.Date,
1325
- value: numberValue
1326
- } : {
1327
- type: RecordValueType.Number,
1328
- value: numberValue
1329
- };
1330
- }
1331
- if (typeof value === "boolean") return {
1332
- type: RecordValueType.Boolean,
1333
- value
1334
- };
1335
- if (typeof value === "string") return {
1336
- type: RecordValueType.String,
1337
- value
1338
- };
1339
- throw new TypeError("Invalid table record cell value.");
1340
- }
1341
- function compileTableRecordFilter(_filter) {
1342
- const filter = _filter;
1343
- if (!isRecord(filter) || filter.filterType !== "record") throw new TypeError("Invalid table record filter.");
1344
- if (filter.mode !== FilterSelectionMode.Include && filter.mode !== FilterSelectionMode.Exclude || !Array.isArray(filter.values)) throw new TypeError("Invalid table record filter.");
1345
- const keys = new Set(filter.values.map((value) => getRecordValueKey(value)));
1346
- if (filter.mode === FilterSelectionMode.Include) return (value) => keys.has(getRecordValueKey(value));
1347
- return (value) => !keys.has(getRecordValueKey(value));
1348
- }
1349
- function cloneTableRecordFilter(filter) {
1350
- compileTableRecordFilter(filter);
1351
- return {
1352
- filterType: "record",
1353
- mode: filter.mode,
1354
- values: filter.values.map((value) => value.type === RecordValueType.Blank ? { type: RecordValueType.Blank } : { ...value })
1355
- };
1356
- }
1357
- function getBooleanValue(value) {
1358
- if (value === true || value === 1 || typeof value === "string" && value.toUpperCase() === "TRUE") return true;
1359
- if (value === false || value === 0 || typeof value === "string" && value.toUpperCase() === "FALSE") return false;
1360
- throw new TypeError("Invalid table record boolean value.");
1361
- }
1362
- function getFiniteNumberValue(value) {
1363
- const numberValue = typeof value === "number" ? value : Number(value);
1364
- if (!Number.isFinite(numberValue)) throw new RangeError("Table record numeric values must be finite.");
1365
- return numberValue;
1366
- }
1367
- function getNumberCellValue(sheet, row, column, value, isNumberCell, isArrayFormulaCell) {
1368
- var _sheet$getCellRaw;
1369
- if (!isNumberCell || isArrayFormulaCell) return value;
1370
- return ((_sheet$getCellRaw = sheet.getCellRaw(row, column)) === null || _sheet$getCellRaw === void 0 ? void 0 : _sheet$getCellRaw.v) ?? value;
1371
- }
1372
- function isRecord(value) {
1373
- return typeof value === "object" && value !== null && !Array.isArray(value);
1374
- }
1375
-
1376
- //#endregion
1377
- //#region src/models/table-filter.ts
1378
- var TableFilters = class {
1379
- constructor() {
1380
- _defineProperty(this, "_tableColumnFilterList", void 0);
1381
- _defineProperty(this, "_tableSortInfo", void 0);
1382
- _defineProperty(this, "_filterOutRows", /* @__PURE__ */ new Set());
1383
- this._tableColumnFilterList = [];
1384
- }
1385
- setColumnFilter(columnIndex, filter) {
1386
- if (!filter) this._tableColumnFilterList[columnIndex] = void 0;
1387
- else if (filter.filterType === "record") this._tableColumnFilterList[columnIndex] = cloneTableRecordFilter(filter);
1388
- else this._tableColumnFilterList[columnIndex] = filter;
1389
- }
1390
- setSortState(columnIndex, sortState) {
1391
- this._tableSortInfo = {
1392
- columnIndex,
1393
- sortState
1394
- };
1395
- }
1396
- setSortInfo(sortInfo) {
1397
- this._tableSortInfo = sortInfo;
1398
- }
1399
- getColumnFilter(columnIndex) {
1400
- const filter = this._tableColumnFilterList[columnIndex];
1401
- return (filter === null || filter === void 0 ? void 0 : filter.filterType) === "record" ? cloneTableRecordFilter(filter) : filter;
1402
- }
1403
- getFilterState(columnIndex) {
1404
- var _this$_tableSortInfo;
1405
- const sortState = ((_this$_tableSortInfo = this._tableSortInfo) === null || _this$_tableSortInfo === void 0 ? void 0 : _this$_tableSortInfo.columnIndex) === columnIndex ? this._tableSortInfo.sortState : "none";
1406
- return getTableFilterState(this._tableColumnFilterList[columnIndex], sortState);
1407
- }
1408
- getSortState() {
1409
- return this._tableSortInfo ?? {};
1410
- }
1411
- getFilterStates(range) {
1412
- const states = [];
1413
- const { startColumn, endColumn } = range;
1414
- for (let i = startColumn; i <= endColumn; i++) states.push(this.getFilterState(i - startColumn));
1415
- return states;
1416
- }
1417
- getFilterOutRows() {
1418
- return this._filterOutRows;
1419
- }
1420
- setFilterOutRows(rows) {
1421
- this._filterOutRows = new Set(rows);
1422
- }
1423
- doFilter(sheet, range, dateSystem = DateSystem.Date1900) {
1424
- const filterOutRows = /* @__PURE__ */ new Set();
1425
- const tableColumnFilterList = this._tableColumnFilterList;
1426
- for (let i = 0; i < tableColumnFilterList.length; i++) if (tableColumnFilterList[i]) this.doColumnFilter(sheet, range, i, filterOutRows, dateSystem);
1427
- this._filterOutRows = filterOutRows;
1428
- return filterOutRows;
1429
- }
1430
- doColumnFilter(sheet, range, columnIndex, filterOutRows, dateSystem = DateSystem.Date1900) {
1431
- const filter = this._tableColumnFilterList[columnIndex];
1432
- if (filter && sheet) {
1433
- const { startRow, endRow, startColumn } = range;
1434
- const column = startColumn + columnIndex;
1435
- if (filter.filterType === "record") {
1436
- const executeRecordFilter = compileTableRecordFilter(filter);
1437
- for (let row = startRow; row <= endRow; row++) if (!executeRecordFilter(getTableRecordValue(sheet, row, column))) filterOutRows.add(row);
1438
- return;
1439
- }
1440
- const executeFunc = this.getExecuteFunc(sheet, range, columnIndex, filter);
1441
- for (let row = startRow; row <= endRow; row++) {
1442
- if (isColorTableFilter(filter)) {
1443
- const cellData = sheet.getCell(row, column);
1444
- if (!executeFunc(sheet.getComposedCellStyleByCellData(row, column, cellData))) filterOutRows.add(row);
1445
- continue;
1446
- }
1447
- const conditionType = isConditionFilter(filter) ? filter.filterInfo.conditionType : "string";
1448
- const cellValue = getCellValueWithConditionType(sheet, row, column, conditionType, dateSystem);
1449
- if (cellValue === null && !executeFunc(cellValue)) filterOutRows.add(row);
1450
- else if (!executeFunc(getCellValueWithConditionType(sheet, row, column, conditionType, dateSystem))) filterOutRows.add(row);
1451
- }
1452
- }
1453
- }
1454
- _getNumberCalculatedOptions(sheet, range, columnIndex) {
1455
- const { startRow, endRow, startColumn } = range;
1456
- const column = startColumn + columnIndex;
1457
- const list = [];
1458
- let count = 0;
1459
- let sum = 0;
1460
- for (let row = startRow; row <= endRow; row++) {
1461
- const val = getCellValueWithConditionType(sheet, row, column, "number");
1462
- if (val !== null) {
1463
- list.push(val);
1464
- count++;
1465
- sum += val;
1466
- }
1467
- }
1468
- return {
1469
- list,
1470
- average: count > 0 ? sum / count : 0
1471
- };
1472
- }
1473
- getExecuteFunc(sheet, range, columnIndex, filter) {
1474
- if (filter.filterType === "manual") {
1475
- const valuesSet = new Set(filter.values.map(String));
1476
- return (value) => {
1477
- if (value == null) return valuesSet.has(TABLE_FILTER_EMPTY_VALUE);
1478
- return valuesSet.has(String(value));
1479
- };
1480
- } else if (filter.filterType === "record") return compileTableRecordFilter(filter);
1481
- else if (filter.filterType === "condition") {
1482
- const calculatedOptions = isNumberDynamicFilter(filter.filterInfo.compareType) ? this._getNumberCalculatedOptions(sheet, range, columnIndex) : void 0;
1483
- return getConditionExecuteFunc(filter, calculatedOptions);
1484
- } else if (filter.filterType === "color") {
1485
- const normalizeColor = (color) => color ? new ColorKit(color).toRgbString() : null;
1486
- if (filter.cellFillColors) {
1487
- const colors = new Set(filter.cellFillColors.map(normalizeColor));
1488
- return (style) => colors.has(normalizeColor(getColorStyle(style === null || style === void 0 ? void 0 : style.bg)));
1489
- }
1490
- if (filter.cellTextColors) {
1491
- const colors = new Set(filter.cellTextColors.map(normalizeColor));
1492
- return (style) => colors.has(normalizeColor(getColorStyle(style === null || style === void 0 ? void 0 : style.cl) ?? getColorStyle(DEFAULT_STYLES.cl)));
1493
- }
1494
- } else return (_value) => {
1495
- return true;
1496
- };
1497
- return () => true;
1498
- }
1499
- toJSON() {
1500
- return {
1501
- tableColumnFilterList: this._tableColumnFilterList.some((filter) => (filter === null || filter === void 0 ? void 0 : filter.filterType) === "record") ? this._tableColumnFilterList.map((filter) => (filter === null || filter === void 0 ? void 0 : filter.filterType) === "record" ? cloneTableRecordFilter(filter) : filter) : this._tableColumnFilterList,
1502
- tableSortInfo: this._tableSortInfo
1503
- };
1504
- }
1505
- fromJSON(json) {
1506
- const filters = json.tableColumnFilterList ?? [];
1507
- if (filters.some((filter) => (filter === null || filter === void 0 ? void 0 : filter.filterType) === "record")) {
1508
- this._tableColumnFilterList = [];
1509
- filters.forEach((filter, index) => this.setColumnFilter(index, filter));
1510
- } else this._tableColumnFilterList = filters;
1511
- if (json.tableSortInfo) this._tableSortInfo = json.tableSortInfo;
1512
- }
1513
- dispose() {
1514
- this._tableColumnFilterList = [];
1515
- this._filterOutRows = /* @__PURE__ */ new Set();
1516
- }
1517
- };
1518
-
1519
- //#endregion
1520
- //#region src/models/table.ts
1521
- var Table = class {
1522
- constructor(id, name, range, header, options = {}) {
1523
- _defineProperty(this, "_id", void 0);
1524
- _defineProperty(this, "_name", void 0);
1525
- _defineProperty(this, "_tableStyleId", void 0);
1526
- _defineProperty(this, "_showHeader", void 0);
1527
- _defineProperty(this, "_showFooter", void 0);
1528
- _defineProperty(this, "_showAutoFilter", void 0);
1529
- _defineProperty(this, "_range", void 0);
1530
- _defineProperty(this, "_columns", /* @__PURE__ */ new Map());
1531
- _defineProperty(this, "_columnOrder", []);
1532
- _defineProperty(this, "tableMeta", void 0);
1533
- _defineProperty(this, "_tableFilters", void 0);
1534
- _defineProperty(this, "_subUnitId", void 0);
1535
- this._id = id;
1536
- this._range = range;
1537
- this._name = name;
1538
- this._tableFilters = new TableFilters();
1539
- this._init(header, options);
1540
- }
1541
- _init(header, options) {
1542
- this._tableStyleId = options === null || options === void 0 ? void 0 : options.tableStyleId;
1543
- this._showHeader = (options === null || options === void 0 ? void 0 : options.showHeader) ?? true;
1544
- this._showFooter = (options === null || options === void 0 ? void 0 : options.showFooter) ?? false;
1545
- this._showAutoFilter = (options === null || options === void 0 ? void 0 : options.showAutoFilter) ?? true;
1546
- const range = this.getRange();
1547
- const startColumn = range.startColumn;
1548
- const endColumn = range.endColumn;
1549
- for (let i = startColumn; i <= endColumn; i++) {
1550
- var _options$columns;
1551
- const index = i - startColumn;
1552
- let id;
1553
- let columnName;
1554
- if ((_options$columns = options.columns) === null || _options$columns === void 0 ? void 0 : _options$columns[index]) {
1555
- id = options.columns[index].id;
1556
- columnName = options.columns[index].displayName;
1557
- } else {
1558
- id = generateRandomId();
1559
- columnName = header[i - startColumn];
1560
- }
1561
- const column = new TableColumn(id, columnName);
1562
- this._columns.set(id, column);
1563
- this._columnOrder.push(id);
1564
- }
1565
- if (options.filters) options.filters.forEach((filter, index) => {
1566
- if (filter) this._tableFilters.setColumnFilter(index, filter);
1567
- });
1568
- }
1569
- setTableFilterColumn(columnIndex, filter) {
1570
- this._tableFilters.setColumnFilter(columnIndex, filter);
1571
- }
1572
- getTableFilterColumn(columnIndex) {
1573
- return this._tableFilters.getColumnFilter(columnIndex);
1574
- }
1575
- getTableFilters() {
1576
- return this._tableFilters;
1577
- }
1578
- getTableFilterRange() {
1579
- const tableRange = this.getRange();
1580
- const showHeader = this.isShowHeader();
1581
- const isShowFooter = this.isShowFooter();
1582
- const { startRow, startColumn, endRow, endColumn } = tableRange;
1583
- return {
1584
- startRow: showHeader ? startRow + 1 : startRow,
1585
- startColumn,
1586
- endRow: isShowFooter ? endRow - 1 : endRow,
1587
- endColumn
1588
- };
1589
- }
1590
- setColumns(columns) {
1591
- this._columns.clear();
1592
- this._columnOrder = [];
1593
- columns.forEach((columnJson) => {
1594
- const column = new TableColumn(columnJson.id, columnJson.displayName);
1595
- column.fromJSON(columnJson);
1596
- this._columns.set(columnJson.id, column);
1597
- this._columnOrder.push(columnJson.id);
1598
- });
1599
- }
1600
- getColumnsCount() {
1601
- return this._columnOrder.length;
1602
- }
1603
- insertColumn(index, column) {
1604
- const columnId = column.id;
1605
- this._columns.set(columnId, column);
1606
- this._columnOrder.splice(index, 0, columnId);
1607
- }
1608
- removeColumn(index) {
1609
- const columnId = this._columnOrder[index];
1610
- this._columns.delete(columnId);
1611
- this._columnOrder.splice(index, 1);
1612
- }
1613
- setTableMeta(meta) {
1614
- this.tableMeta = meta;
1615
- }
1616
- getTableMeta() {
1617
- return this.tableMeta;
1618
- }
1619
- getColumn(columnId) {
1620
- return this._columns.get(columnId);
1621
- }
1622
- getTableColumnByIndex(index) {
1623
- const id = this._columnOrder[index];
1624
- return this.getColumn(id);
1625
- }
1626
- getColumnNameByIndex(index) {
1627
- var _this$getColumn;
1628
- const id = this._columnOrder[index];
1629
- return ((_this$getColumn = this.getColumn(id)) === null || _this$getColumn === void 0 ? void 0 : _this$getColumn.getDisplayName()) || "";
1630
- }
1631
- getId() {
1632
- return this._id;
1633
- }
1634
- getRangeInfo() {
1635
- return { ...this._range };
1636
- }
1637
- getRange() {
1638
- return { ...this._range };
1639
- }
1640
- setRange(range) {
1641
- this._range = range;
1642
- }
1643
- setDisplayName(name) {
1644
- this._name = name;
1645
- }
1646
- getDisplayName() {
1647
- return this._name;
1648
- }
1649
- getSubunitId() {
1650
- return this._subUnitId;
1651
- }
1652
- setSubunitId(subUnitId) {
1653
- this._subUnitId = subUnitId;
1654
- }
1655
- getTableStyleId() {
1656
- return this._tableStyleId ?? tableThemeConfig[0].name;
1657
- }
1658
- setTableStyleId(tableStyleId) {
1659
- this._tableStyleId = tableStyleId;
1660
- }
1661
- isShowHeader() {
1662
- return this._showHeader ?? true;
1663
- }
1664
- setShowHeader(showHeader) {
1665
- this._showHeader = showHeader;
1666
- }
1667
- isShowFooter() {
1668
- return this._showFooter ?? false;
1669
- }
1670
- isShowAutoFilter() {
1671
- return this._showAutoFilter ?? true;
1672
- }
1673
- setShowAutoFilter(showAutoFilter) {
1674
- this._showAutoFilter = showAutoFilter;
1675
- }
1676
- getTableInfo() {
1677
- return {
1678
- id: this._id,
1679
- subUnitId: this._subUnitId,
1680
- name: this._name,
1681
- range: this.getRangeInfo(),
1682
- meta: this.tableMeta,
1683
- showHeader: this._showHeader,
1684
- showAutoFilter: this._showAutoFilter,
1685
- columns: this._columnOrder.map((columnId) => this._columns.get(columnId).toJSON())
1686
- };
1687
- }
1688
- getTableConfig() {
1689
- return {
1690
- name: this.getDisplayName(),
1691
- range: this.getRangeInfo(),
1692
- options: {
1693
- showHeader: this._showHeader,
1694
- showFooter: this._showFooter,
1695
- showAutoFilter: this._showAutoFilter
1696
- },
1697
- tableStyleId: this._tableStyleId
1698
- };
1699
- }
1700
- getFilterStates(range) {
1701
- return this._tableFilters.getFilterStates(range);
1702
- }
1703
- toJSON() {
1704
- const columns = this._columnOrder.map((columnId) => this._columns.get(columnId).toJSON());
1705
- return {
1706
- id: this._id,
1707
- name: this._name,
1708
- range: this.getRangeInfo(),
1709
- options: {
1710
- showHeader: this._showHeader,
1711
- showFooter: this._showFooter,
1712
- showAutoFilter: this._showAutoFilter,
1713
- tableStyleId: this._tableStyleId
1714
- },
1715
- filters: this._tableFilters.toJSON(),
1716
- columns,
1717
- meta: this.tableMeta
1718
- };
1719
- }
1720
- fromJSON(json) {
1721
- this._id = json.id;
1722
- this._name = json.name;
1723
- this._range = json.range;
1724
- this.tableMeta = json.meta;
1725
- this._tableStyleId = json.options.tableStyleId || "";
1726
- this._showHeader = json.options.showHeader ?? true;
1727
- this._showFooter = json.options.showFooter ?? true;
1728
- this._showAutoFilter = json.options.showAutoFilter ?? true;
1729
- this._columns.clear();
1730
- this._columnOrder = [];
1731
- json.columns.forEach((column) => {
1732
- const tableColumn = new TableColumn(column.id, column.displayName);
1733
- tableColumn.fromJSON(column);
1734
- this._columns.set(column.id, tableColumn);
1735
- this._columnOrder.push(column.id);
1736
- });
1737
- this._tableFilters = new TableFilters();
1738
- this._tableFilters.fromJSON(json.filters);
1739
- }
1740
- dispose() {
1741
- this._id = "";
1742
- this._name = "";
1743
- this._tableStyleId = "";
1744
- this._showHeader = true;
1745
- this._showFooter = true;
1746
- this._showAutoFilter = true;
1747
- delete this._range;
1748
- this._columns.clear();
1749
- this._columnOrder = [];
1750
- }
1751
- };
1752
-
1753
- //#endregion
1754
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
1755
- function __decorateParam(paramIndex, decorator) {
1756
- return function(target, key) {
1757
- decorator(target, key, paramIndex);
1758
- };
1759
- }
1760
-
1761
- //#endregion
1762
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
1763
- function __decorate(decorators, target, key, desc) {
1764
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1765
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1766
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1767
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1768
- }
1769
-
1770
- //#endregion
1771
- //#region src/models/table-manager.ts
1772
- let TableManager = class TableManager extends Disposable {
1773
- constructor(_univerInstanceService, _localeService) {
1774
- super();
1775
- this._univerInstanceService = _univerInstanceService;
1776
- this._localeService = _localeService;
1777
- _defineProperty(this, "_tableMap", void 0);
1778
- _defineProperty(this, "_tableAdd$", new Subject());
1779
- _defineProperty(this, "tableAdd$", this._tableAdd$.asObservable());
1780
- _defineProperty(this, "_tableDelete$", new Subject());
1781
- _defineProperty(this, "tableDelete$", this._tableDelete$.asObservable());
1782
- _defineProperty(this, "_tableNameChanged$", new Subject());
1783
- _defineProperty(this, "tableNameChanged$", this._tableNameChanged$.asObservable());
1784
- _defineProperty(this, "_tableRangeChanged$", new Subject());
1785
- _defineProperty(this, "tableRangeChanged$", this._tableRangeChanged$.asObservable());
1786
- _defineProperty(this, "_tableThemeChanged$", new Subject());
1787
- _defineProperty(this, "tableThemeChanged$", this._tableThemeChanged$.asObservable());
1788
- _defineProperty(this, "_tableFilterChanged$", new Subject());
1789
- _defineProperty(this, "tableFilterChanged$", this._tableFilterChanged$.asObservable());
1790
- _defineProperty(this, "_tableInitStatus", new BehaviorSubject(false));
1791
- _defineProperty(this, "tableInitStatus$", this._tableInitStatus.asObservable());
1792
- this._tableMap = /* @__PURE__ */ new Map();
1793
- }
1794
- _ensureUnit(unitId) {
1795
- if (!this._tableMap.has(unitId)) this._tableMap.set(unitId, /* @__PURE__ */ new Map());
1796
- return this._tableMap.get(unitId);
1797
- }
1798
- getColumnHeader(unitId, subUnitId, range, prefixText) {
1799
- var _this$_univerInstance;
1800
- const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
1801
- const { startRow, startColumn, endColumn } = range;
1802
- const header = [];
1803
- const columnText = prefixText ?? "Column";
1804
- for (let i = startColumn; i <= endColumn; i++) header.push(convertCellDataToString(worksheet === null || worksheet === void 0 ? void 0 : worksheet.getCell(startRow, i)) || getColumnName(i - startColumn + 1, columnText));
1805
- return header;
1806
- }
1807
- /**
1808
- * Add a table to univer.
1809
- * @param {string} unitId The unit id of the table.
1810
- * @param {string} subUnitId The subunit id of the table.
1811
- * @param {string} name The table name, it should be unique in the unit or it will be appended with a number.
1812
- * @param {ITableRange} range The range of the table, it contains the unit id and subunit id.
1813
- * @param {string[]} [header] The header of the table, if not provided, it will be generated based on the range.
1814
- * @param {string} [initId] The initial id of the table, if not provided, a random id will be generated.
1815
- * @param {ITableOptions} [options] Other options of the table.
1816
- * @returns {string} The table id.
1817
- */
1818
- addTable(unitId, subUnitId, name, range, header, initId, options) {
1819
- const id = initId ?? generateRandomId();
1820
- const tableHeader = header || this.getColumnHeader(unitId, subUnitId, range);
1821
- const table = new Table(id, name, range, tableHeader, options);
1822
- table.setSubunitId(subUnitId);
1823
- this._ensureUnit(unitId).set(id, table);
1824
- this._tableAdd$.next({
1825
- unitId,
1826
- subUnitId,
1827
- range,
1828
- tableName: name,
1829
- tableId: id,
1830
- tableStyleId: options === null || options === void 0 ? void 0 : options.tableStyleId
1831
- });
1832
- if (options === null || options === void 0 ? void 0 : options.filters) {
1833
- const workbook = this._univerInstanceService.getUnit(unitId);
1834
- const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
1835
- table.getTableFilters().doFilter(worksheet, range, workbook === null || workbook === void 0 ? void 0 : workbook.getDateSystem());
1836
- this._tableFilterChanged$.next({
1837
- unitId,
1838
- subUnitId,
1839
- tableId: id
1840
- });
1841
- }
1842
- return id;
1843
- }
1844
- addFilter(unitId, tableId, column, filter) {
1845
- const table = this.getTable(unitId, tableId);
1846
- if (table) {
1847
- table.getTableFilters().setColumnFilter(column, filter);
1848
- const subUnitId = table.getSubunitId();
1849
- this._tableFilterChanged$.next({
1850
- unitId,
1851
- subUnitId,
1852
- tableId
1853
- });
1854
- }
1855
- }
1856
- getFilterRanges(unitId, subUnitId) {
1857
- const unitMap = this._tableMap.get(unitId);
1858
- if (!unitMap) return [];
1859
- const filterRanges = [];
1860
- unitMap.forEach((table) => {
1861
- if (table.getSubunitId() === subUnitId && table.isShowHeader()) filterRanges.push(table.getRange());
1862
- });
1863
- return filterRanges;
1864
- }
1865
- getSheetFilterRangeWithState(unitId, subUnitId) {
1866
- const unitMap = this._tableMap.get(unitId);
1867
- if (!unitMap) return [];
1868
- const filterRanges = [];
1869
- unitMap.forEach((table) => {
1870
- if (table.getSubunitId() === subUnitId && table.isShowHeader() && table.isShowAutoFilter()) filterRanges.push({
1871
- tableId: table.getId(),
1872
- range: table.getRange(),
1873
- states: table.getFilterStates(table.getRange())
1874
- });
1875
- });
1876
- return filterRanges;
1877
- }
1878
- getTable(unitId, tableId) {
1879
- const unitMap = this._tableMap.get(unitId);
1880
- if (!unitMap) return;
1881
- return unitMap.get(tableId);
1882
- }
1883
- /**
1884
- * Get the unique table name, in excel, the table name should be unique because it is used as a reference.
1885
- * @param {string} unitId The unit id of the table.
1886
- * @param {string} baseName The base name of the table.
1887
- * @returns {string} The unique table name
1888
- */
1889
- getUniqueTableName(unitId, baseName) {
1890
- const unitMap = this._tableMap.get(unitId);
1891
- if (!unitMap) return baseName;
1892
- const tableNamesSet = new Set(Array.from(unitMap.values()).map((table) => table.getDisplayName()));
1893
- let newName = baseName;
1894
- let count = 1;
1895
- while (tableNamesSet.has(newName)) {
1896
- newName = `${baseName}-${count}`;
1897
- count++;
1898
- }
1899
- return newName;
1900
- }
1901
- /**
1902
- * Get table by unit id and table id.
1903
- * @param {string} unitId The unit id of the table.
1904
- * @param {string} tableId The table id.
1905
- * @returns {Table} The table.
1906
- */
1907
- getTableById(unitId, tableId) {
1908
- return this.getTable(unitId, tableId);
1909
- }
1910
- getTableList(unitId) {
1911
- const unitMap = this._tableMap.get(unitId);
1912
- if (!unitMap) return [];
1913
- return Array.from(unitMap.values()).map((table) => {
1914
- return {
1915
- ...table.getTableInfo(),
1916
- unitId
1917
- };
1918
- });
1919
- }
1920
- /**
1921
- * Get the table list by unit id and subunit id.
1922
- * @param {string} unitId The unit id of the table.
1923
- * @param {string} subUnitId The subunit id of the table.
1924
- * @returns {Table[]} The table list.
1925
- */
1926
- getTablesBySubunitId(unitId, subUnitId) {
1927
- const unitMap = this._tableMap.get(unitId);
1928
- if (!unitMap) return [];
1929
- return Array.from(unitMap.values()).filter((table) => table.getSubunitId() === subUnitId);
1930
- }
1931
- getTablesInfoBySubunitId(unitId, subUnitId) {
1932
- return this.getTablesBySubunitId(unitId, subUnitId).map((table) => {
1933
- return {
1934
- id: table.getId(),
1935
- name: table.getDisplayName(),
1936
- range: table.getRange()
1937
- };
1938
- });
1939
- }
1940
- deleteTable(unitId, tableId) {
1941
- const unitMap = this._tableMap.get(unitId);
1942
- const table = unitMap === null || unitMap === void 0 ? void 0 : unitMap.get(tableId);
1943
- if (table) {
1944
- const tableInfo = table.getTableInfo();
1945
- const tableStyleId = table.getTableStyleId();
1946
- unitMap === null || unitMap === void 0 || unitMap.delete(tableId);
1947
- const { subUnitId, range, name } = tableInfo;
1948
- this._tableDelete$.next({
1949
- unitId,
1950
- subUnitId,
1951
- tableId,
1952
- range,
1953
- tableName: name,
1954
- tableStyleId
1955
- });
1956
- }
1957
- }
1958
- operationTableRowCol(unitId, tableId, config) {
1959
- const table = this.getTableById(unitId, tableId);
1960
- if (!table) return;
1961
- const { operationType, rowColType, index, count, columnsJson } = config;
1962
- const oldRange = table.getRange();
1963
- const newRange = { ...oldRange };
1964
- if (operationType === "insert") {
1965
- if (rowColType === "row") newRange.endRow += count;
1966
- else if (rowColType === "column") {
1967
- newRange.endColumn += count;
1968
- for (let i = 0; i < count; i++) {
1969
- const columnPrefix = this._localeService.t("sheets-table.columnPrefix");
1970
- const column = new TableColumn(generateRandomId(), getColumnName(table.getColumnsCount() + 1 + i, columnPrefix));
1971
- if (columnsJson === null || columnsJson === void 0 ? void 0 : columnsJson[i]) column.fromJSON(columnsJson[i]);
1972
- const columnIndex = index + i - oldRange.startColumn;
1973
- table.insertColumn(columnIndex, column);
1974
- }
1975
- }
1976
- } else if (rowColType === "row") newRange.endRow -= count;
1977
- else if (rowColType === "column") {
1978
- newRange.endColumn -= count;
1979
- for (let i = count - 1; i >= 0; i--) {
1980
- const columnIndex = index + i - oldRange.startColumn;
1981
- table.removeColumn(columnIndex);
1982
- }
1983
- }
1984
- table.setRange(newRange);
1985
- this._tableRangeChanged$.next({
1986
- unitId,
1987
- subUnitId: table.getSubunitId(),
1988
- tableId,
1989
- range: newRange,
1990
- oldRange
1991
- });
1992
- }
1993
- updateTableRange(unitId, tableId, config) {
1994
- const table = this.getTableById(unitId, tableId);
1995
- if (!table) return;
1996
- const oldRange = table.getRange();
1997
- const newRange = config.newRange;
1998
- if (newRange.startColumn < oldRange.startColumn) {
1999
- const diff = oldRange.startColumn - newRange.startColumn;
2000
- const columnPrefix = this._localeService.t("sheets-table.columnPrefix");
2001
- for (let i = 0; i < diff; i++) table.insertColumn(oldRange.startColumn, new TableColumn(generateRandomId(), getColumnName(table.getColumnsCount() + 1, columnPrefix)));
2002
- } else if (newRange.startColumn > oldRange.startColumn) {
2003
- const diff = newRange.startColumn - oldRange.startColumn;
2004
- for (let i = diff - 1; i >= 0; i--) {
2005
- const columnIndex = newRange.startColumn + i - oldRange.startColumn;
2006
- table.removeColumn(columnIndex);
2007
- }
2008
- }
2009
- if (newRange.endColumn < oldRange.endColumn) {
2010
- const diff = oldRange.endColumn - newRange.endColumn;
2011
- for (let i = diff - 1; i >= 0; i--) {
2012
- const columnIndex = newRange.endColumn + i - oldRange.startColumn;
2013
- table.removeColumn(columnIndex);
2014
- }
2015
- } else if (newRange.endColumn > oldRange.endColumn) {
2016
- const diff = newRange.endColumn - oldRange.endColumn;
2017
- const columnPrefix = this._localeService.t("sheets-table.columnPrefix");
2018
- for (let i = 0; i < diff; i++) table.insertColumn(oldRange.endColumn, new TableColumn(generateRandomId(), getColumnName(table.getColumnsCount() + 1, columnPrefix)));
2019
- }
2020
- table.setRange(newRange);
2021
- this._tableRangeChanged$.next({
2022
- unitId,
2023
- subUnitId: table.getSubunitId(),
2024
- tableId,
2025
- range: newRange,
2026
- oldRange
2027
- });
2028
- }
2029
- moveTable(unitId, tableId, subUnitId, range) {
2030
- const table = this.getTableById(unitId, tableId);
2031
- if (!table) return;
2032
- const oldRange = table.getRange();
2033
- const oldSubUnitId = table.getSubunitId();
2034
- table.setSubunitId(subUnitId);
2035
- table.setRange({ ...range });
2036
- this._tableRangeChanged$.next({
2037
- unitId,
2038
- subUnitId,
2039
- oldSubUnitId,
2040
- tableId,
2041
- range: { ...range },
2042
- oldRange
2043
- });
2044
- this._tableFilterChanged$.next({
2045
- unitId,
2046
- subUnitId,
2047
- oldSubUnitId,
2048
- tableId
2049
- });
2050
- }
2051
- setTableByConfig(unitId, tableId, config) {
2052
- const unitMap = this._tableMap.get(unitId);
2053
- const table = unitMap === null || unitMap === void 0 ? void 0 : unitMap.get(tableId);
2054
- if (!table) return;
2055
- const subUnitId = table.getSubunitId();
2056
- const { name, updateRange, rowColOperation, theme, sortInfo, options, filterButtons } = config;
2057
- if (config.calculatedColumn) {
2058
- const column = table.getColumn(config.calculatedColumn.columnId);
2059
- if (column) {
2060
- column.formula = config.calculatedColumn.formula;
2061
- column.formulaIsArray = config.calculatedColumn.formulaIsArray;
2062
- }
2063
- }
2064
- if (filterButtons) {
2065
- if (filterButtons.showAutoFilter !== void 0) table.setShowAutoFilter(filterButtons.showAutoFilter);
2066
- for (const [columnId, visible] of Object.entries(filterButtons.columns ?? {})) {
2067
- const column = table.getColumn(columnId);
2068
- if (column) column.showFilterButton = visible;
2069
- }
2070
- }
2071
- if (name) {
2072
- const oldTableName = table.getDisplayName();
2073
- table.setDisplayName(name);
2074
- this._tableNameChanged$.next({
2075
- unitId,
2076
- subUnitId,
2077
- tableId,
2078
- tableName: name,
2079
- oldTableName
2080
- });
2081
- }
2082
- if (rowColOperation) this.operationTableRowCol(unitId, tableId, rowColOperation);
2083
- if (updateRange) this.updateTableRange(unitId, tableId, updateRange);
2084
- if (theme) {
2085
- const oldTheme = table.getTableStyleId() ?? "default";
2086
- table.setTableStyleId(theme);
2087
- this._tableThemeChanged$.next({
2088
- unitId,
2089
- subUnitId,
2090
- tableId,
2091
- theme,
2092
- oldTheme
2093
- });
2094
- }
2095
- if ("sortInfo" in config) table.getTableFilters().setSortInfo(sortInfo);
2096
- if (options) {
2097
- if (options.showHeader !== void 0) table.setShowHeader(options.showHeader);
2098
- }
2099
- }
2100
- toJSON(unitId) {
2101
- const result = {};
2102
- const unitMap = this._tableMap.get(unitId);
2103
- if (unitMap) unitMap.forEach((table) => {
2104
- const subUnitId = table.getSubunitId();
2105
- if (!result[subUnitId]) {
2106
- const tableFilteredOutRows = /* @__PURE__ */ new Set();
2107
- this.getTablesBySubunitId(unitId, subUnitId).forEach((table) => {
2108
- const tableFilteredRows = table.getTableFilters().getFilterOutRows();
2109
- if (!tableFilteredRows) return;
2110
- for (const row of tableFilteredRows) tableFilteredOutRows.add(row);
2111
- });
2112
- result[subUnitId] = {
2113
- tables: [],
2114
- tableFilteredOutRows: Array.from(tableFilteredOutRows)
2115
- };
2116
- }
2117
- result[subUnitId].tables.push(table.toJSON());
2118
- });
2119
- return result;
2120
- }
2121
- fromJSON(unitId, data) {
2122
- const unitMap = this._ensureUnit(unitId);
2123
- Object.keys(data).forEach((subUnitId) => {
2124
- const target = getSheetCommandTarget(this._univerInstanceService, {
2125
- unitId,
2126
- subUnitId
2127
- });
2128
- if (!target) return;
2129
- const sheet = target.worksheet;
2130
- let tables;
2131
- if (data[subUnitId].tables) tables = data[subUnitId].tables;
2132
- else if (Array.isArray(data[subUnitId])) tables = data[subUnitId];
2133
- if (!tables) return;
2134
- const cachedFilteredOutRows = data[subUnitId].tableFilteredOutRows;
2135
- tables.forEach((table) => {
2136
- var _table$options;
2137
- const header = this.getColumnHeader(unitId, subUnitId, table.range);
2138
- const tableInstance = new Table(table.id, table.name, table.range, header, table.options);
2139
- tableInstance.setTableMeta(table.meta);
2140
- if (table.columns.length) tableInstance.setColumns(table.columns);
2141
- if (table.filters) {
2142
- const tableFilter = tableInstance.getTableFilters();
2143
- tableFilter.fromJSON(table.filters);
2144
- if (Array.isArray(cachedFilteredOutRows)) {
2145
- const { startRow, endRow } = tableInstance.getTableFilterRange();
2146
- tableFilter.setFilterOutRows(cachedFilteredOutRows.filter((row) => row >= startRow && row <= endRow));
2147
- } else tableFilter.doFilter(sheet, tableInstance.getTableFilterRange(), target.workbook.getDateSystem());
2148
- }
2149
- tableInstance.setSubunitId(subUnitId);
2150
- unitMap.set(table.id, tableInstance);
2151
- this._tableAdd$.next({
2152
- unitId,
2153
- subUnitId,
2154
- range: table.range,
2155
- tableName: table.name,
2156
- tableId: table.id,
2157
- tableStyleId: (_table$options = table.options) === null || _table$options === void 0 ? void 0 : _table$options.tableStyleId
2158
- });
2159
- });
2160
- });
2161
- this._tableInitStatus.next(true);
2162
- }
2163
- deleteUnitId(unitId) {
2164
- const unitMap = this._tableMap.get(unitId);
2165
- if (unitMap) unitMap.forEach((table) => table.dispose());
2166
- this._tableMap.delete(unitId);
2167
- }
2168
- dispose() {
2169
- super.dispose();
2170
- this._tableAdd$.complete();
2171
- this._tableDelete$.complete();
2172
- this._tableNameChanged$.complete();
2173
- this._tableRangeChanged$.complete();
2174
- this._tableThemeChanged$.complete();
2175
- this._tableFilterChanged$.complete();
2176
- this._tableInitStatus.complete();
2177
- this._tableMap.forEach((unitMap) => {
2178
- unitMap.forEach((table) => table.dispose());
2179
- unitMap.clear();
2180
- });
2181
- this._tableMap.clear();
2182
- }
2183
- };
2184
- TableManager = __decorate([__decorateParam(0, IUniverInstanceService), __decorateParam(1, Inject(LocaleService))], TableManager);
2185
-
2186
- //#endregion
2187
- //#region src/services/table.service.ts
2188
- let SheetTableService = class SheetTableService extends Disposable {
2189
- constructor(_tableManager) {
2190
- super();
2191
- this._tableManager = _tableManager;
2192
- }
2193
- getTableInfo(unitId, tableId) {
2194
- const table = this._tableManager.getTable(unitId, tableId);
2195
- if (!table) return;
2196
- return {
2197
- unitId,
2198
- ...table.getTableInfo()
2199
- };
2200
- }
2201
- getTableList(unitId) {
2202
- return this._tableManager.getTableList(unitId);
2203
- }
2204
- addTable(unitId, subUnitId, tableName, rangeInfo, tableHeader, tableId, options) {
2205
- return this._tableManager.addTable(unitId, subUnitId, tableName, rangeInfo, tableHeader, tableId, options);
2206
- }
2207
- deleteTable(unitId, subUnitId, tableId) {
2208
- this._tableManager.deleteTable(unitId, tableId);
2209
- }
2210
- getTableMeta(unitId, tableId) {
2211
- var _this$_tableManager$g;
2212
- return (_this$_tableManager$g = this._tableManager.getTable(unitId, tableId)) === null || _this$_tableManager$g === void 0 ? void 0 : _this$_tableManager$g.getTableMeta();
2213
- }
2214
- setTableMeta(unitId, tableId, meta) {
2215
- var _this$_tableManager$g2;
2216
- (_this$_tableManager$g2 = this._tableManager.getTable(unitId, tableId)) === null || _this$_tableManager$g2 === void 0 || _this$_tableManager$g2.setTableMeta(meta);
2217
- }
2218
- getTableColumnMeta(unitId, tableId, index) {
2219
- var _this$_tableManager$g3;
2220
- return (_this$_tableManager$g3 = this._tableManager.getTable(unitId, tableId)) === null || _this$_tableManager$g3 === void 0 || (_this$_tableManager$g3 = _this$_tableManager$g3.getTableColumnByIndex(index)) === null || _this$_tableManager$g3 === void 0 ? void 0 : _this$_tableManager$g3.getMeta();
2221
- }
2222
- selTableColumnMeta(unitId, tableId, index, meta) {
2223
- var _this$_tableManager$g4;
2224
- (_this$_tableManager$g4 = this._tableManager.getTable(unitId, tableId)) === null || _this$_tableManager$g4 === void 0 || (_this$_tableManager$g4 = _this$_tableManager$g4.getTableColumnByIndex(index)) === null || _this$_tableManager$g4 === void 0 || _this$_tableManager$g4.setMeta(meta);
2225
- }
2226
- addFilter(unitId, tableId, column, filter) {
2227
- this._tableManager.addFilter(unitId, tableId, column, filter);
2228
- }
2229
- getCellValueWithConditionType(sheet, row, col, conditionType = "string") {
2230
- return getCellValueWithConditionType(sheet, row, col, conditionType);
2231
- }
2232
- };
2233
- SheetTableService = __decorate([__decorateParam(0, Inject(TableManager))], SheetTableService);
2234
-
2235
- //#endregion
2236
- //#region src/commands/mutations/add-sheet-table.mutation.ts
2237
- const AddSheetTableMutation = {
2238
- id: "sheet.mutation.add-table",
2239
- type: CommandType.MUTATION,
2240
- handler: (accessor, params) => {
2241
- const { tableId, unitId, subUnitId, name, range, header, options } = params;
2242
- accessor.get(SheetTableService).addTable(unitId, subUnitId, name, range, header, tableId, options);
2243
- return true;
2244
- }
2245
- };
2246
-
2247
- //#endregion
2248
- //#region src/commands/mutations/delete-sheet-table.mutation.ts
2249
- const DeleteSheetTableMutation = {
2250
- id: "sheet.mutation.delete-table",
2251
- type: CommandType.MUTATION,
2252
- handler: (accessor, params) => {
2253
- const { unitId, subUnitId, tableId } = params;
2254
- accessor.get(SheetTableService).deleteTable(unitId, subUnitId, tableId);
2255
- return true;
2256
- }
2257
- };
2258
-
2259
- //#endregion
2260
- //#region src/commands/commands/add-sheet-table.command.ts
2261
- const AddSheetTableCommand = {
2262
- id: "sheet.command.add-table",
2263
- type: CommandType.COMMAND,
2264
- handler: (accessor, params) => {
2265
- if (!params) return false;
2266
- const undoRedoService = accessor.get(IUndoRedoService);
2267
- const commandService = accessor.get(ICommandService);
2268
- const localeService = accessor.get(LocaleService);
2269
- const tableManager = accessor.get(TableManager);
2270
- const tableId = params.id ?? generateRandomId();
2271
- const existingNamesSet = getExistingNamesSet(params.unitId, {
2272
- univerInstanceService: accessor.get(IUniverInstanceService),
2273
- tableManager,
2274
- definedNamesService: accessor.get(IDefinedNamesService)
2275
- });
2276
- let tableName = params.name;
2277
- if (!tableName || !customNameCharacterCheck(tableName.toLowerCase(), existingNamesSet)) {
2278
- const prefix = localeService.t("sheets-table.tablePrefix");
2279
- let index = tableManager.getTableList(params.unitId).length + 1;
2280
- for (const name of existingNamesSet) if (name.startsWith(prefix.toLowerCase())) {
2281
- const n = Number(name.slice(prefix.length));
2282
- if (Number.isInteger(n) && n >= index) index = n + 1;
2283
- }
2284
- tableName = `${prefix}${index}`;
2285
- }
2286
- const redos = [];
2287
- const undos = [];
2288
- const { unitId, subUnitId, range } = params;
2289
- const header = tableManager.getColumnHeader(unitId, subUnitId, range, localeService.t("sheets-table.columnPrefix"));
2290
- const options = Tools.deepClone(params.options ?? {});
2291
- options.columns = header.map((name, index) => {
2292
- var _options$columns;
2293
- return ((_options$columns = options.columns) === null || _options$columns === void 0 ? void 0 : _options$columns[index]) ?? new TableColumn(generateRandomId(), name).toJSON();
2294
- });
2295
- redos.push({
2296
- id: AddSheetTableMutation.id,
2297
- params: {
2298
- ...params,
2299
- tableId,
2300
- name: tableName,
2301
- header,
2302
- options
2303
- }
2304
- });
2305
- undos.push({
2306
- id: DeleteSheetTableMutation.id,
2307
- params: {
2308
- tableId,
2309
- unitId: params.unitId
2310
- }
2311
- });
2312
- if (sequenceExecute(redos, commandService).result) {
2313
- undoRedoService.pushUndoRedo({
2314
- unitID: params.unitId,
2315
- undoMutations: undos,
2316
- redoMutations: redos
2317
- });
2318
- return true;
2319
- }
2320
- return false;
2321
- }
2322
- };
2323
-
2324
- //#endregion
2325
- //#region src/commands/mutations/set-sheet-table.mutation.ts
2326
- const SetSheetTableMutation = {
2327
- id: "sheet.mutation.set-sheet-table",
2328
- type: CommandType.MUTATION,
2329
- handler: (accessor, params) => {
2330
- if (!params) return false;
2331
- const { unitId, tableId, config } = params;
2332
- accessor.get(TableManager).setTableByConfig(unitId, tableId, config);
2333
- return true;
2334
- }
2335
- };
2336
-
2337
- //#endregion
2338
- //#region src/commands/commands/add-table-theme.command.ts
2339
- const AddTableThemeCommand = {
2340
- id: "sheet.command.add-table-theme",
2341
- type: CommandType.COMMAND,
2342
- handler: (accessor, params) => {
2343
- if (!params) return false;
2344
- const tableManager = accessor.get(TableManager);
2345
- const { unitId, tableId, themeStyle } = params;
2346
- const redos = [];
2347
- const undos = [];
2348
- const table = tableManager.getTableById(unitId, tableId);
2349
- if (!table) return false;
2350
- const subUnitId = table.getSubunitId();
2351
- redos.push({
2352
- id: AddRangeThemeMutation.id,
2353
- params: {
2354
- unitId,
2355
- subUnitId,
2356
- styleJSON: themeStyle.toJson()
2357
- }
2358
- });
2359
- redos.push({
2360
- id: SetSheetTableMutation.id,
2361
- params: {
2362
- unitId,
2363
- subUnitId,
2364
- tableId,
2365
- config: { theme: themeStyle.getName() }
2366
- }
2367
- });
2368
- undos.push({
2369
- id: SetSheetTableMutation.id,
2370
- params: {
2371
- unitId,
2372
- subUnitId,
2373
- tableId,
2374
- config: { themeStyle: table.getTableStyleId() }
2375
- }
2376
- });
2377
- undos.push({
2378
- id: RemoveRangeThemeMutation.id,
2379
- params: {
2380
- unitId,
2381
- subUnitId,
2382
- styleName: themeStyle.getName()
2383
- }
2384
- });
2385
- const commandService = accessor.get(ICommandService);
2386
- if (sequenceExecute(redos, commandService).result) {
2387
- accessor.get(IUndoRedoService).pushUndoRedo({
2388
- unitID: unitId,
2389
- undoMutations: undos,
2390
- redoMutations: redos
2391
- });
2392
- return true;
2393
- }
2394
- return false;
2395
- }
2396
- };
2397
-
2398
- //#endregion
2399
- //#region src/commands/mutations/set-table-filter.mutation.ts
2400
- const SetSheetTableFilterMutation = {
2401
- id: "sheet.mutation.set-table-filter",
2402
- type: CommandType.MUTATION,
2403
- handler: (accessor, params) => {
2404
- const { tableId, unitId, column, tableFilter } = params;
2405
- const tableManager = accessor.get(TableManager);
2406
- const table = tableManager.getTable(unitId, tableId);
2407
- tableManager.addFilter(unitId, tableId, column, tableFilter);
2408
- if (table) {
2409
- var _tableManager$toJSON$;
2410
- const tableFilters = table.getTableFilters();
2411
- if (params.filterOutRows) tableFilters.setFilterOutRows(params.filterOutRows);
2412
- else params.filterOutRows = [...tableFilters.getFilterOutRows()];
2413
- params.subUnitId = table.getSubunitId();
2414
- params.tableFilteredOutRows = ((_tableManager$toJSON$ = tableManager.toJSON(unitId)[params.subUnitId]) === null || _tableManager$toJSON$ === void 0 ? void 0 : _tableManager$toJSON$.tableFilteredOutRows) ?? [];
2415
- }
2416
- return true;
2417
- }
2418
- };
2419
-
2420
- //#endregion
2421
- //#region src/commands/commands/delete-sheet-table.command.ts
2422
- const DeleteSheetTableCommand = {
2423
- id: "sheet.command.delete-table",
2424
- type: CommandType.COMMAND,
2425
- handler: (accessor, params) => {
2426
- var _tableConfig$filters$;
2427
- if (!params) return false;
2428
- const undoRedoService = accessor.get(IUndoRedoService);
2429
- const commandService = accessor.get(ICommandService);
2430
- const sheetTableManager = accessor.get(TableManager);
2431
- const logService = accessor.get(ILogService);
2432
- const redos = [];
2433
- const undos = [];
2434
- const tableInstance = sheetTableManager.getTable(params.unitId, params.tableId);
2435
- const tableConfig = tableInstance === null || tableInstance === void 0 ? void 0 : tableInstance.toJSON();
2436
- if (!tableConfig) {
2437
- logService.error("[TableManager]: Table not found");
2438
- return false;
2439
- }
2440
- const interceptorCommands = accessor.get(SheetInterceptorService).onCommandExecute({
2441
- id: DeleteSheetTableCommand.id,
2442
- params: {
2443
- ...params,
2444
- tableName: tableConfig.name
2445
- }
2446
- });
2447
- redos.push(...interceptorCommands.preRedos ?? []);
2448
- redos.push({
2449
- id: DeleteSheetTableMutation.id,
2450
- params: { ...params }
2451
- });
2452
- redos.push(...interceptorCommands.redos);
2453
- undos.push(...interceptorCommands.preUndos ?? []);
2454
- undos.push({
2455
- id: AddSheetTableMutation.id,
2456
- params: {
2457
- unitId: params.unitId,
2458
- subUnitId: params.subUnitId,
2459
- tableId: params.tableId,
2460
- name: tableConfig.name,
2461
- range: tableConfig.range,
2462
- options: tableConfig.options
2463
- }
2464
- });
2465
- (_tableConfig$filters$ = tableConfig.filters.tableColumnFilterList) === null || _tableConfig$filters$ === void 0 || _tableConfig$filters$.forEach((tableFilter, column) => {
2466
- if (tableFilter) undos.push({
2467
- id: SetSheetTableFilterMutation.id,
2468
- params: {
2469
- unitId: params.unitId,
2470
- tableId: params.tableId,
2471
- column,
2472
- tableFilter
2473
- }
2474
- });
2475
- });
2476
- undos.push(...interceptorCommands.undos);
2477
- if (sequenceExecute(redos, commandService).result) {
2478
- undoRedoService.pushUndoRedo({
2479
- unitID: params.unitId,
2480
- undoMutations: undos,
2481
- redoMutations: redos
2482
- });
2483
- return true;
2484
- }
2485
- return false;
2486
- }
2487
- };
2488
-
2489
- //#endregion
2490
- //#region src/commands/commands/remove-table-theme.command.ts
2491
- const RemoveTableThemeCommand = {
2492
- id: "sheet.command.remove-table-theme",
2493
- type: CommandType.COMMAND,
2494
- handler: (accessor, params) => {
2495
- if (!params) return false;
2496
- const { unitId, tableId, themeName } = params;
2497
- const tableManager = accessor.get(TableManager);
2498
- const rangeThemeModel = accessor.get(SheetRangeThemeModel);
2499
- const table = tableManager.getTableById(unitId, tableId);
2500
- if (!table) return false;
2501
- const subUnitId = table.getSubunitId();
2502
- const redos = [];
2503
- const undos = [];
2504
- const defaultRangeThemes = rangeThemeModel.getRegisteredRangeThemes().filter((item) => item === null || item === void 0 ? void 0 : item.startsWith("table-default"));
2505
- let shouldBeSelectedTheme = rangeThemeModel.getRegisteredRangeThemes().filter((item) => item === null || item === void 0 ? void 0 : item.startsWith(SHEET_TABLE_CUSTOM_THEME_PREFIX)).find((item) => item !== themeName);
2506
- if (!shouldBeSelectedTheme) shouldBeSelectedTheme = defaultRangeThemes[0];
2507
- redos.push({
2508
- id: SetSheetTableMutation.id,
2509
- params: {
2510
- unitId,
2511
- subUnitId,
2512
- tableId,
2513
- config: { theme: shouldBeSelectedTheme }
2514
- }
2515
- });
2516
- redos.push({
2517
- id: RemoveRangeThemeMutation.id,
2518
- params: {
2519
- unitId,
2520
- subUnitId,
2521
- styleName: themeName
2522
- }
2523
- });
2524
- const themeStyle = rangeThemeModel.getDefaultRangeThemeStyle(themeName);
2525
- if (themeStyle) {
2526
- undos.push({
2527
- id: AddRangeThemeMutation.id,
2528
- params: {
2529
- unitId,
2530
- subUnitId,
2531
- styleJSON: themeStyle.toJson()
2532
- }
2533
- });
2534
- undos.push({
2535
- id: SetSheetTableMutation.id,
2536
- params: {
2537
- unitId,
2538
- subUnitId,
2539
- tableId,
2540
- config: { theme: themeName }
2541
- }
2542
- });
2543
- }
2544
- const commandService = accessor.get(ICommandService);
2545
- if (sequenceExecute(redos, commandService).result) {
2546
- accessor.get(IUndoRedoService).pushUndoRedo({
2547
- unitID: unitId,
2548
- redoMutations: redos,
2549
- undoMutations: undos
2550
- });
2551
- return true;
2552
- }
2553
- return false;
2554
- }
2555
- };
2556
-
2557
- //#endregion
2558
- //#region src/util/table-name.ts
2559
- /**
2560
- * Copyright 2023-present DreamNum Co., Ltd.
2561
- *
2562
- * Licensed under the Apache License, Version 2.0 (the "License");
2563
- * you may not use this file except in compliance with the License.
2564
- * You may obtain a copy of the License at
2565
- *
2566
- * http://www.apache.org/licenses/LICENSE-2.0
2567
- *
2568
- * Unless required by applicable law or agreed to in writing, software
2569
- * distributed under the License is distributed on an "AS IS" BASIS,
2570
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2571
- * See the License for the specific language governing permissions and
2572
- * limitations under the License.
2573
- */
2574
- function validateSheetTableName(name, existingNamesSet) {
2575
- const trimmedName = name.trim();
2576
- if (!trimmedName) return {
2577
- valid: false,
2578
- reason: "empty"
2579
- };
2580
- const normalizedExistingNames = new Set(Array.from(existingNamesSet, (item) => item.toLowerCase()));
2581
- if (!customNameCharacterCheck(trimmedName.toLowerCase(), normalizedExistingNames)) return {
2582
- valid: false,
2583
- reason: "invalid"
2584
- };
2585
- return { valid: true };
2586
- }
2587
-
2588
- //#endregion
2589
- //#region src/commands/utils/calculated-column.ts
2590
- function getCalculatedColumnFillMutation(table, unitId, subUnitId, startRow, endRow, getLexerTreeBuilder, config) {
2591
- var _table$getTableInfo;
2592
- const tableInfo = (_table$getTableInfo = table.getTableInfo) === null || _table$getTableInfo === void 0 ? void 0 : _table$getTableInfo.call(table);
2593
- if (!tableInfo) return;
2594
- const firstDataRow = tableInfo.range.startRow + (tableInfo.showHeader ? 1 : 0);
2595
- const cellValue = {};
2596
- let lexerTreeBuilder;
2597
- tableInfo.columns.forEach((column, columnIndex) => {
2598
- var _ref;
2599
- if (config && column.id !== config.columnId) return;
2600
- const formula = (_ref = (config === null || config === void 0 ? void 0 : config.formula) ?? column.formula) === null || _ref === void 0 ? void 0 : _ref.trim();
2601
- const formulaIsArray = (config === null || config === void 0 ? void 0 : config.formulaIsArray) ?? column.formulaIsArray;
2602
- if (!formula) return;
2603
- const baseFormula = normalizeCalculatedColumnFormula(formula.startsWith("=") ? formula : `=${formula}`, tableInfo.name);
2604
- const sheetColumn = tableInfo.range.startColumn + columnIndex;
2605
- lexerTreeBuilder ??= getLexerTreeBuilder();
2606
- for (let row = startRow; row <= endRow; row++) {
2607
- cellValue[row] ??= {};
2608
- const cell = {
2609
- f: lexerTreeBuilder.moveFormulaRefOffset(baseFormula, 0, row - firstDataRow),
2610
- si: null,
2611
- ref: null,
2612
- ft: formulaIsArray ? FormulaType.ARRAY : null,
2613
- fd: formulaIsArray ? BooleanNumber.FALSE : null,
2614
- v: null,
2615
- p: null,
2616
- t: null
2617
- };
2618
- if (formulaIsArray) cell.ref = serializeRange({
2619
- startRow: row,
2620
- endRow: row,
2621
- startColumn: sheetColumn,
2622
- endColumn: sheetColumn
2623
- });
2624
- cellValue[row][sheetColumn] = cell;
2625
- }
2626
- });
2627
- if (!Object.keys(cellValue).length) return;
2628
- return {
2629
- id: SetRangeValuesMutation.id,
2630
- params: {
2631
- unitId,
2632
- subUnitId,
2633
- cellValue
2634
- }
2635
- };
2636
- }
2637
- function normalizeCalculatedColumnFormula(formula, tableName) {
2638
- let result = "";
2639
- for (let index = 0; index < formula.length; index++) {
2640
- const start = index;
2641
- const char = formula[index];
2642
- if (char === "\"" || char === "'") {
2643
- while (++index < formula.length) if (formula[index] === char) {
2644
- if (formula[index + 1] !== char) break;
2645
- index++;
2646
- }
2647
- } else if (char === "[") {
2648
- let depth = 1;
2649
- while (++index < formula.length && depth > 0) {
2650
- if (formula[index] === "'") index++;
2651
- else if (formula[index] === "[") depth++;
2652
- else if (formula[index] === "]") depth--;
2653
- if (depth === 0) break;
2654
- }
2655
- if (depth === 0) {
2656
- const body = formula.slice(start + 1, index);
2657
- const previous = formula.slice(0, start).trimEnd().slice(-1);
2658
- const unqualified = !previous || /[=+\-*/^&(<>,;:{]/.test(previous);
2659
- const next = formula.slice(index + 1).trimStart();
2660
- if (!/^[^+\-*/^&=<>%),;}:\s]/.test(next)) {
2661
- const prefix = unqualified ? tableName : "";
2662
- const columns = body.slice(1);
2663
- result += body.startsWith("@") ? `${prefix}[[#This Row],${columns.startsWith("[") ? columns : `[${columns}]`}]` : `${prefix}[${body}]`;
2664
- continue;
2665
- }
2666
- }
2667
- }
2668
- result += formula.slice(start, index + 1);
2669
- }
2670
- return result;
2671
- }
2672
-
2673
- //#endregion
2674
- //#region src/commands/commands/set-sheet-table.command.ts
2675
- const SetSheetTableCommand = {
2676
- id: "sheet.command.set-table-config",
2677
- type: CommandType.COMMAND,
2678
- handler: (accessor, params) => {
2679
- if (!params) return false;
2680
- const { unitId, tableId, name, updateRange, rowColOperation, theme, filterButtons } = params;
2681
- const tableManager = accessor.get(TableManager);
2682
- const table = tableManager.getTableById(unitId, tableId);
2683
- if (!table) return false;
2684
- const cellRedos = [];
2685
- const cellUndos = [];
2686
- const oldTableConfig = {};
2687
- const newTableConfig = {};
2688
- if (params.calculatedColumn) {
2689
- const { columnId, formula, formulaIsArray } = params.calculatedColumn;
2690
- const column = table.getColumn(columnId);
2691
- if (!column || typeof formula !== "string" || formulaIsArray !== void 0 && typeof formulaIsArray !== "boolean") return false;
2692
- if (updateRange || rowColOperation) return false;
2693
- const range = table.getTableFilterRange();
2694
- const columnIndex = table.getTableInfo().columns.findIndex((item) => item.id === columnId);
2695
- const sheetColumn = range.startColumn + columnIndex;
2696
- const editRange = {
2697
- ...range,
2698
- startColumn: sheetColumn,
2699
- endColumn: sheetColumn
2700
- };
2701
- if (!checkRangesEditablePermission(accessor, unitId, table.getSubunitId(), [editRange])) return false;
2702
- const normalized = formula.trim();
2703
- if (normalized === "=") return false;
2704
- oldTableConfig.calculatedColumn = {
2705
- columnId,
2706
- formula: column.formula,
2707
- formulaIsArray: column.formulaIsArray
2708
- };
2709
- newTableConfig.calculatedColumn = {
2710
- columnId,
2711
- formula: normalized && !normalized.startsWith("=") ? `=${normalized}` : normalized,
2712
- formulaIsArray: normalized ? formulaIsArray ?? column.formulaIsArray : void 0
2713
- };
2714
- const fill = getCalculatedColumnFillMutation(table, unitId, table.getSubunitId(), range.startRow, range.endRow, () => accessor.get(LexerTreeBuilder), newTableConfig.calculatedColumn);
2715
- if (fill) {
2716
- cellRedos.push(fill);
2717
- cellUndos.push({
2718
- id: SetRangeValuesMutation.id,
2719
- params: SetRangeValuesUndoMutationFactory(accessor, fill.params)
2720
- });
2721
- }
2722
- }
2723
- if (filterButtons) {
2724
- var _accessor$get$getPerm;
2725
- if (((_accessor$get$getPerm = accessor.get(IPermissionService).getPermissionPoint(new WorkbookEditablePermission(unitId).id)) === null || _accessor$get$getPerm === void 0 ? void 0 : _accessor$get$getPerm.value) === false) return false;
2726
- const { showAutoFilter, columns } = filterButtons;
2727
- if (showAutoFilter !== void 0 && typeof showAutoFilter !== "boolean") return false;
2728
- const entries = Object.entries(columns ?? {});
2729
- if (entries.some(([id, visible]) => !table.getColumn(id) || typeof visible !== "boolean")) return false;
2730
- oldTableConfig.filterButtons = {
2731
- ...showAutoFilter === void 0 ? {} : { showAutoFilter: table.isShowAutoFilter() },
2732
- columns: Object.fromEntries(entries.map(([id]) => [id, table.getColumn(id).isShowFilterButton()]))
2733
- };
2734
- newTableConfig.filterButtons = {
2735
- ...showAutoFilter === void 0 ? {} : { showAutoFilter },
2736
- columns: Object.fromEntries(entries)
2737
- };
2738
- }
2739
- const localeService = accessor.get(LocaleService);
2740
- const existingNamesSet = getExistingNamesSet(unitId, {
2741
- univerInstanceService: accessor.get(IUniverInstanceService),
2742
- tableManager,
2743
- definedNamesService: accessor.get(IDefinedNamesService)
2744
- });
2745
- if (name) {
2746
- if (!validateSheetTableName(name, existingNamesSet).valid) {
2747
- accessor.get(ILogService).warn(localeService.t("sheets-table.tableNameError"));
2748
- return false;
2749
- }
2750
- oldTableConfig.name = table.getDisplayName();
2751
- newTableConfig.name = name;
2752
- }
2753
- if (rowColOperation) {
2754
- oldTableConfig.rowColOperation = {
2755
- operationType: rowColOperation.operationType === "insert" ? "delete" : "insert",
2756
- rowColType: rowColOperation.rowColType,
2757
- index: rowColOperation.index,
2758
- count: rowColOperation.count
2759
- };
2760
- newTableConfig.rowColOperation = rowColOperation;
2761
- }
2762
- if (updateRange) {
2763
- oldTableConfig.updateRange = { newRange: table.getRange() };
2764
- newTableConfig.updateRange = updateRange;
2765
- }
2766
- if (theme) {
2767
- oldTableConfig.theme = table.getTableStyleId();
2768
- newTableConfig.theme = theme;
2769
- }
2770
- const redoParams = {
2771
- unitId,
2772
- subUnitId: table.getSubunitId(),
2773
- tableId,
2774
- config: newTableConfig
2775
- };
2776
- const undoParams = {
2777
- unitId,
2778
- subUnitId: table.getSubunitId(),
2779
- tableId,
2780
- config: oldTableConfig
2781
- };
2782
- const interceptorCommands = accessor.get(SheetInterceptorService).onCommandExecute({
2783
- id: SetSheetTableCommand.id,
2784
- params: {
2785
- ...params,
2786
- oldTableName: oldTableConfig.name
2787
- }
2788
- });
2789
- const redos = [
2790
- ...interceptorCommands.preRedos ?? [],
2791
- {
2792
- id: SetSheetTableMutation.id,
2793
- params: redoParams
2794
- },
2795
- ...cellRedos,
2796
- ...interceptorCommands.redos
2797
- ];
2798
- const undos = [
2799
- ...interceptorCommands.preUndos ?? [],
2800
- {
2801
- id: SetSheetTableMutation.id,
2802
- params: undoParams
2803
- },
2804
- ...cellUndos,
2805
- ...interceptorCommands.undos
2806
- ];
2807
- const commandService = accessor.get(ICommandService);
2808
- if (!sequenceExecute(redos, commandService).result) return false;
2809
- accessor.get(IUndoRedoService).pushUndoRedo({
2810
- unitID: unitId,
2811
- undoMutations: undos,
2812
- redoMutations: redos
2813
- });
2814
- return true;
2815
- }
2816
- };
2817
-
2818
- //#endregion
2819
- //#region src/commands/commands/set-table-filter.command.ts
2820
- const SetSheetTableFilterCommand = {
2821
- id: "sheet.command.set-table-filter",
2822
- type: CommandType.COMMAND,
2823
- handler: (accessor, params) => {
2824
- var _tableManager$getTabl, _params$tableFilter;
2825
- if (!params) return false;
2826
- const undoRedoService = accessor.get(IUndoRedoService);
2827
- const commandService = accessor.get(ICommandService);
2828
- const tableManager = accessor.get(TableManager);
2829
- const tableId = params.tableId || generateRandomId();
2830
- const tableFilters = (_tableManager$getTabl = tableManager.getTable(params.unitId, tableId)) === null || _tableManager$getTabl === void 0 ? void 0 : _tableManager$getTabl.getTableFilters();
2831
- const previousFilter = tableFilters === null || tableFilters === void 0 ? void 0 : tableFilters.getColumnFilter(params.column);
2832
- const previousFilterOutRows = [...(tableFilters === null || tableFilters === void 0 ? void 0 : tableFilters.getFilterOutRows()) ?? []];
2833
- const tableFilter = ((_params$tableFilter = params.tableFilter) === null || _params$tableFilter === void 0 ? void 0 : _params$tableFilter.filterType) === "record" ? cloneTableRecordFilter(params.tableFilter) : params.tableFilter;
2834
- const redos = [];
2835
- const undos = [];
2836
- redos.push({
2837
- id: SetSheetTableFilterMutation.id,
2838
- params: {
2839
- ...params,
2840
- tableId,
2841
- tableFilter
2842
- }
2843
- });
2844
- undos.push({
2845
- id: SetSheetTableFilterMutation.id,
2846
- params: {
2847
- ...params,
2848
- tableId,
2849
- tableFilter: previousFilter,
2850
- filterOutRows: previousFilterOutRows
2851
- }
2852
- });
2853
- if (sequenceExecute(redos, commandService).result) {
2854
- undoRedoService.pushUndoRedo({
2855
- unitID: params.unitId,
2856
- undoMutations: undos,
2857
- redoMutations: redos
2858
- });
2859
- return true;
2860
- }
2861
- return false;
2862
- }
2863
- };
2864
-
2865
- //#endregion
2866
- //#region src/commands/commands/set-table-sort-state.command.ts
2867
- const SetSheetTableSortStateCommand = {
2868
- id: "sheet.command.set-table-sort-state",
2869
- type: CommandType.COMMAND,
2870
- handler: (accessor, params) => {
2871
- if (!params) return false;
2872
- const table = accessor.get(TableManager).getTable(params.unitId, params.tableId);
2873
- if (!table) return false;
2874
- const previousSortInfo = table.getTableFilters().toJSON().tableSortInfo;
2875
- const commandService = accessor.get(ICommandService);
2876
- const mutationParams = {
2877
- unitId: params.unitId,
2878
- subUnitId: table.getSubunitId(),
2879
- tableId: params.tableId,
2880
- config: { sortInfo: params.sortInfo }
2881
- };
2882
- if (!commandService.syncExecuteCommand(SetSheetTableMutation.id, mutationParams)) return false;
2883
- accessor.get(IUndoRedoService).pushUndoRedo({
2884
- unitID: params.unitId,
2885
- undoMutations: [{
2886
- id: SetSheetTableMutation.id,
2887
- params: {
2888
- ...mutationParams,
2889
- config: { sortInfo: previousSortInfo }
2890
- }
2891
- }],
2892
- redoMutations: [{
2893
- id: SetSheetTableMutation.id,
2894
- params: mutationParams
2895
- }]
2896
- });
2897
- return true;
2898
- }
2899
- };
2900
-
2901
- //#endregion
2902
- //#region src/controllers/sheets-table.controller.ts
2903
- let SheetsTableController = class SheetsTableController extends Disposable {
2904
- constructor(_univerInstanceService, _sheetInterceptorService, _tableManager, _resourceManagerService) {
2905
- super();
2906
- this._univerInstanceService = _univerInstanceService;
2907
- this._sheetInterceptorService = _sheetInterceptorService;
2908
- this._tableManager = _tableManager;
2909
- this._resourceManagerService = _resourceManagerService;
2910
- _defineProperty(this, "_tableRangeRTree", /* @__PURE__ */ new Map());
2911
- this.registerTableChangeEvent();
2912
- this._initSnapshot();
2913
- this._initSheetChange();
2914
- this.registerTableHeaderInterceptor();
2915
- }
2916
- getContainerTableWithRange(unitId, subUnitId, range) {
2917
- const rTree = this._ensureTableRangeRTree(unitId);
2918
- const wrapperTableId = Array.from(rTree.bulkSearch([{
2919
- unitId,
2920
- sheetId: subUnitId,
2921
- range
2922
- }])).find((id) => {
2923
- const table = this._tableManager.getTable(unitId, String(id));
2924
- if (table) return Rectangle.contains(table.getRange(), range);
2925
- return false;
2926
- });
2927
- if (wrapperTableId) return this._tableManager.getTable(unitId, String(wrapperTableId));
2928
- }
2929
- _ensureTableRangeRTree(unitId) {
2930
- if (!this._tableRangeRTree.has(unitId)) this._tableRangeRTree.set(unitId, new RTree());
2931
- return this._tableRangeRTree.get(unitId);
2932
- }
2933
- registerTableChangeEvent() {
2934
- this.disposeWithMe(this._tableManager.tableAdd$.subscribe((event) => {
2935
- const { range, tableId, unitId, subUnitId } = event;
2936
- this._ensureTableRangeRTree(unitId).insert({
2937
- unitId,
2938
- sheetId: subUnitId,
2939
- id: tableId,
2940
- range: { ...range }
2941
- });
2942
- }));
2943
- this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe((event) => {
2944
- const { range, tableId, unitId, subUnitId, oldRange, oldSubUnitId = subUnitId } = event;
2945
- const rTree = this._ensureTableRangeRTree(unitId);
2946
- rTree.remove({
2947
- unitId,
2948
- sheetId: oldSubUnitId,
2949
- id: tableId,
2950
- range: { ...oldRange }
2951
- });
2952
- rTree.insert({
2953
- unitId,
2954
- sheetId: subUnitId,
2955
- id: tableId,
2956
- range: { ...range }
2957
- });
2958
- }));
2959
- this.disposeWithMe(this._tableManager.tableDelete$.subscribe((event) => {
2960
- const { tableId, unitId, subUnitId, range } = event;
2961
- this._ensureTableRangeRTree(unitId).remove({
2962
- unitId,
2963
- sheetId: subUnitId,
2964
- id: tableId,
2965
- range: { ...range }
2966
- });
2967
- }));
2968
- }
2969
- registerTableHeaderInterceptor() {
2970
- this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
2971
- effect: InterceptorEffectEnum.Value,
2972
- handler: (cell, context, next) => {
2973
- const { row, col, unitId, subUnitId } = context;
2974
- const rTree = this._ensureTableRangeRTree(unitId);
2975
- if ((cell === null || cell === void 0 ? void 0 : cell.v) === void 0 && rTree) {
2976
- const ids = Array.from(rTree.bulkSearch([{
2977
- unitId,
2978
- sheetId: subUnitId,
2979
- range: {
2980
- startColumn: col,
2981
- endColumn: col,
2982
- startRow: row,
2983
- endRow: row
2984
- }
2985
- }]));
2986
- if (ids.length > 0) {
2987
- const table = this._tableManager.getTable(unitId, ids[0]);
2988
- if (table) {
2989
- const tableRange = table.getRange();
2990
- const index = col - tableRange.startColumn;
2991
- if (tableRange.startRow === row) {
2992
- const columnName = table.getColumnNameByIndex(index);
2993
- if (!cell || cell === context.rawData) cell = { ...context.rawData };
2994
- cell.v = columnName;
2995
- return next(cell);
2996
- }
2997
- }
2998
- }
2999
- }
3000
- return next(cell);
3001
- }
3002
- }));
3003
- }
3004
- _toJson(unitId) {
3005
- return this._tableManager.toJSON(unitId);
3006
- }
3007
- _fromJSON(unitId, resources) {
3008
- return this._tableManager.fromJSON(unitId, resources);
3009
- }
3010
- _deleteUnitId(unitId) {
3011
- this._tableManager.deleteUnitId(unitId);
3012
- }
3013
- _initSnapshot() {
3014
- this.disposeWithMe(this._resourceManagerService.registerPluginResource({
3015
- toJson: (unitId) => {
3016
- return JSON.stringify(this._toJson(unitId));
3017
- },
3018
- parseJson: (json) => {
3019
- if (!json) return {};
3020
- try {
3021
- return JSON.parse(json);
3022
- } catch (error) {
3023
- return {};
3024
- }
3025
- },
3026
- businesses: [UniverInstanceType.UNIVER_SHEET],
3027
- pluginName: PLUGIN_NAME,
3028
- onLoad: (unitId, resources) => {
3029
- this._fromJSON(unitId, resources);
3030
- },
3031
- onUnLoad: (unitId) => {
3032
- this._deleteUnitId(unitId);
3033
- }
3034
- }));
3035
- }
3036
- _initSheetChange() {
3037
- this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (commandInfo) => {
3038
- if (commandInfo.id === RemoveSheetCommand.id) {
3039
- var _getActiveSheet;
3040
- const params = commandInfo.params;
3041
- const unitId = params.unitId || this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET).getUnitId();
3042
- const subUnitId = params.subUnitId || ((_getActiveSheet = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET).getActiveSheet()) === null || _getActiveSheet === void 0 ? void 0 : _getActiveSheet.getSheetId());
3043
- if (!unitId || !subUnitId) return {
3044
- redos: [],
3045
- undos: []
3046
- };
3047
- const tables = this._tableManager.getTablesBySubunitId(unitId, subUnitId);
3048
- if (tables.length === 0) return {
3049
- redos: [],
3050
- undos: []
3051
- };
3052
- const redos = [];
3053
- const undos = [];
3054
- tables.forEach((table) => {
3055
- const tableJson = table.toJSON();
3056
- redos.push({
3057
- id: DeleteSheetTableMutation.id,
3058
- params: {
3059
- unitId,
3060
- subUnitId,
3061
- tableId: tableJson.id
3062
- }
3063
- });
3064
- undos.push({
3065
- id: AddSheetTableMutation.id,
3066
- params: {
3067
- unitId,
3068
- subUnitId,
3069
- name: tableJson.name,
3070
- range: tableJson.range,
3071
- tableId: tableJson.id,
3072
- options: {
3073
- ...tableJson.options,
3074
- columns: tableJson.columns,
3075
- filters: tableJson.filters.tableColumnFilterList
3076
- }
3077
- }
3078
- });
3079
- });
3080
- return {
3081
- redos,
3082
- undos
3083
- };
3084
- } else if (commandInfo.id === CopySheetCommand.id) {
3085
- const { unitId, subUnitId, targetSubUnitId } = commandInfo.params;
3086
- if (!unitId || !subUnitId || !targetSubUnitId) return {
3087
- redos: [],
3088
- undos: []
3089
- };
3090
- const tables = this._tableManager.getTablesBySubunitId(unitId, subUnitId);
3091
- if (tables.length === 0) return {
3092
- redos: [],
3093
- undos: []
3094
- };
3095
- const redos = [];
3096
- const undos = [];
3097
- tables.forEach((table) => {
3098
- const tableJson = table.toJSON();
3099
- const tableId = generateRandomId();
3100
- redos.push({
3101
- id: AddSheetTableMutation.id,
3102
- params: {
3103
- unitId,
3104
- subUnitId: targetSubUnitId,
3105
- name: tableJson.name,
3106
- range: {
3107
- ...tableJson.range,
3108
- sheetId: targetSubUnitId
3109
- },
3110
- tableId,
3111
- options: {
3112
- ...tableJson.options,
3113
- columns: tableJson.columns,
3114
- filters: tableJson.filters.tableColumnFilterList
3115
- }
3116
- }
3117
- });
3118
- undos.push({
3119
- id: DeleteSheetTableMutation.id,
3120
- params: {
3121
- unitId,
3122
- subUnitId: targetSubUnitId,
3123
- tableId
3124
- }
3125
- });
3126
- });
3127
- return {
3128
- redos,
3129
- undos
3130
- };
3131
- }
3132
- return {
3133
- redos: [],
3134
- undos: []
3135
- };
3136
- } }));
3137
- }
3138
- dispose() {
3139
- super.dispose();
3140
- this._tableRangeRTree.clear();
3141
- }
3142
- };
3143
- SheetsTableController = __decorate([
3144
- __decorateParam(0, Inject(IUniverInstanceService)),
3145
- __decorateParam(1, Inject(SheetInterceptorService)),
3146
- __decorateParam(2, Inject(TableManager)),
3147
- __decorateParam(3, Inject(IResourceManagerService))
3148
- ], SheetsTableController);
3149
-
3150
- //#endregion
3151
- //#region src/commands/commands/sheet-table-row-col.command.ts
3152
- function executeTableMutationSequence(accessor, unitId, redos, undos) {
3153
- const commandService = accessor.get(ICommandService);
3154
- if (sequenceExecute(redos, commandService).result) {
3155
- accessor.get(IUndoRedoService).pushUndoRedo({
3156
- unitID: unitId,
3157
- undoMutations: undos,
3158
- redoMutations: redos
3159
- });
3160
- return true;
3161
- }
3162
- return false;
3163
- }
3164
- const SheetTableInsertRowCommand = {
3165
- id: "sheet.command.table-insert-row",
3166
- type: CommandType.COMMAND,
3167
- handler: (accessor) => {
3168
- const univerInstanceService = accessor.get(IUniverInstanceService);
3169
- const target = getSheetCommandTarget(univerInstanceService);
3170
- if (!target) return false;
3171
- const { worksheet, unitId, subUnitId } = target;
3172
- const selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
3173
- if (!selections.length || selections.length > 1) return false;
3174
- const range = selections[0].range;
3175
- const table = accessor.get(SheetsTableController).getContainerTableWithRange(unitId, subUnitId, range);
3176
- if (!table) return false;
3177
- const insertRowCount = range.endRow - range.startRow + 1;
3178
- const worksheetLastRowIndex = worksheet.getRowCount() - 1;
3179
- const rowContentIndex = worksheet.getCellMatrix().getDataRange().endRow;
3180
- const redos = [];
3181
- const undos = [];
3182
- if (worksheetLastRowIndex - rowContentIndex < insertRowCount) {
3183
- redos.push({
3184
- id: InsertRowMutation.id,
3185
- params: {
3186
- unitId,
3187
- subUnitId,
3188
- range: { ...range }
3189
- }
3190
- });
3191
- redos.push({
3192
- id: SetSheetTableMutation.id,
3193
- params: {
3194
- unitId,
3195
- subUnitId,
3196
- tableId: table.getId(),
3197
- config: { updateRange: { newRange: {
3198
- ...table.getRange(),
3199
- endRow: table.getRange().endRow + insertRowCount
3200
- } } }
3201
- }
3202
- });
3203
- undos.push({
3204
- id: SetSheetTableMutation.id,
3205
- params: {
3206
- unitId,
3207
- subUnitId,
3208
- tableId: table.getId(),
3209
- config: { updateRange: { newRange: table.getRange() } }
3210
- }
3211
- });
3212
- undos.push({
3213
- id: RemoveRowMutation.id,
3214
- params: {
3215
- unitId,
3216
- subUnitId,
3217
- range: { ...range }
3218
- }
3219
- });
3220
- } else {
3221
- const oldRange = { ...table.getRange() };
3222
- redos.push({
3223
- id: SetSheetTableMutation.id,
3224
- params: {
3225
- unitId,
3226
- subUnitId,
3227
- tableId: table.getId(),
3228
- config: { updateRange: { newRange: {
3229
- ...oldRange,
3230
- endRow: oldRange.endRow + insertRowCount
3231
- } } }
3232
- }
3233
- });
3234
- undos.push({
3235
- id: SetSheetTableMutation.id,
3236
- params: {
3237
- unitId,
3238
- subUnitId,
3239
- tableId: table.getId(),
3240
- config: { updateRange: { newRange: { ...oldRange } } }
3241
- }
3242
- });
3243
- const moveRangeMutations = getMoveRangeCommandMutations(accessor, {
3244
- fromUnitId: unitId,
3245
- fromSubUnitId: subUnitId,
3246
- toSubUnitId: subUnitId,
3247
- fromRange: {
3248
- startRow: range.startRow,
3249
- endRow: rowContentIndex,
3250
- startColumn: oldRange.startColumn,
3251
- endColumn: oldRange.endColumn
3252
- },
3253
- toRange: {
3254
- startRow: range.startRow + insertRowCount,
3255
- endRow: rowContentIndex + insertRowCount,
3256
- startColumn: oldRange.startColumn,
3257
- endColumn: oldRange.endColumn
3258
- }
3259
- }, {
3260
- includeSelection: false,
3261
- includeAutoHeight: false
3262
- });
3263
- if (moveRangeMutations) {
3264
- redos.push(...moveRangeMutations.redos);
3265
- undos.push(...moveRangeMutations.undos);
3266
- }
3267
- }
3268
- const formulaMutation = getCalculatedColumnFillMutation(table, unitId, subUnitId, range.startRow, range.endRow, () => accessor.get(LexerTreeBuilder));
3269
- if (formulaMutation) {
3270
- redos.push(formulaMutation);
3271
- undos.push({
3272
- id: SetRangeValuesMutation.id,
3273
- params: SetRangeValuesUndoMutationFactory(accessor, formulaMutation.params)
3274
- });
3275
- }
3276
- const commandService = accessor.get(ICommandService);
3277
- if (sequenceExecute(redos, commandService).result) {
3278
- accessor.get(IUndoRedoService).pushUndoRedo({
3279
- unitID: unitId,
3280
- undoMutations: undos,
3281
- redoMutations: redos
3282
- });
3283
- return true;
3284
- }
3285
- return false;
3286
- }
3287
- };
3288
- const SheetTableInsertRowAtCommand = {
3289
- id: "sheet.command.table-insert-row-at",
3290
- type: CommandType.COMMAND,
3291
- handler: (accessor, params) => {
3292
- if (!params) return false;
3293
- const { unitId, subUnitId, tableId, index, count = 1 } = params;
3294
- if (count <= 0) return false;
3295
- const univerInstanceService = accessor.get(IUniverInstanceService);
3296
- const target = getSheetCommandTarget(univerInstanceService, {
3297
- unitId,
3298
- subUnitId
3299
- });
3300
- if (!target) return false;
3301
- const table = accessor.get(TableManager).getTableById(unitId, tableId);
3302
- if (!table || table.getSubunitId() !== subUnitId) return false;
3303
- const oldRange = table.getRange();
3304
- if (index <= oldRange.startRow || index > oldRange.endRow + 1) return false;
3305
- const redos = [{
3306
- id: SetSheetTableMutation.id,
3307
- params: {
3308
- unitId,
3309
- subUnitId,
3310
- tableId,
3311
- config: { updateRange: { newRange: {
3312
- ...oldRange,
3313
- endRow: oldRange.endRow + count
3314
- } } }
3315
- }
3316
- }];
3317
- const undos = [{
3318
- id: SetSheetTableMutation.id,
3319
- params: {
3320
- unitId,
3321
- subUnitId,
3322
- tableId,
3323
- config: { updateRange: { newRange: { ...oldRange } } }
3324
- }
3325
- }];
3326
- const rowContentIndex = target.worksheet.getCellMatrix().getDataRange().endRow;
3327
- const moveRangeMutations = index <= rowContentIndex ? getMoveRangeCommandMutations(accessor, {
3328
- fromUnitId: unitId,
3329
- fromSubUnitId: subUnitId,
3330
- toSubUnitId: subUnitId,
3331
- fromRange: {
3332
- startRow: index,
3333
- endRow: rowContentIndex,
3334
- startColumn: oldRange.startColumn,
3335
- endColumn: oldRange.endColumn
3336
- },
3337
- toRange: {
3338
- startRow: index + count,
3339
- endRow: rowContentIndex + count,
3340
- startColumn: oldRange.startColumn,
3341
- endColumn: oldRange.endColumn
3342
- }
3343
- }, {
3344
- includeSelection: false,
3345
- includeAutoHeight: false
3346
- }) : null;
3347
- if (moveRangeMutations) {
3348
- redos.push(...moveRangeMutations.redos);
3349
- undos.push(...moveRangeMutations.undos);
3350
- }
3351
- const formulaMutation = getCalculatedColumnFillMutation(table, unitId, subUnitId, index, index + count - 1, () => accessor.get(LexerTreeBuilder));
3352
- if (formulaMutation) {
3353
- redos.push(formulaMutation);
3354
- undos.push({
3355
- id: SetRangeValuesMutation.id,
3356
- params: SetRangeValuesUndoMutationFactory(accessor, formulaMutation.params)
3357
- });
3358
- }
3359
- return executeTableMutationSequence(accessor, unitId, redos, undos);
3360
- }
3361
- };
3362
- const SheetTableInsertColCommand = {
3363
- id: "sheet.command.table-insert-col",
3364
- type: CommandType.COMMAND,
3365
- handler: (accessor) => {
3366
- const univerInstanceService = accessor.get(IUniverInstanceService);
3367
- const target = getSheetCommandTarget(univerInstanceService);
3368
- if (!target) return false;
3369
- const { worksheet, unitId, subUnitId } = target;
3370
- const selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
3371
- if (!selections.length || selections.length > 1) return false;
3372
- const range = selections[0].range;
3373
- const table = accessor.get(SheetsTableController).getContainerTableWithRange(unitId, subUnitId, range);
3374
- if (!table) return false;
3375
- const insertColCount = range.endColumn - range.startColumn + 1;
3376
- const worksheetLastColIndex = worksheet.getColumnCount() - 1;
3377
- const colContentIndex = worksheet.getCellMatrix().getDataRange().endColumn;
3378
- const redos = [];
3379
- const undos = [];
3380
- if (worksheetLastColIndex - colContentIndex < insertColCount) {
3381
- redos.push({
3382
- id: InsertColMutation.id,
3383
- params: {
3384
- unitId,
3385
- subUnitId,
3386
- range: { ...range }
3387
- }
3388
- });
3389
- redos.push({
3390
- id: SetSheetTableMutation.id,
3391
- params: {
3392
- unitId,
3393
- subUnitId,
3394
- tableId: table.getId(),
3395
- config: { rowColOperation: {
3396
- operationType: "insert",
3397
- rowColType: "column",
3398
- index: range.startColumn,
3399
- count: insertColCount
3400
- } }
3401
- }
3402
- });
3403
- undos.push({
3404
- id: SetSheetTableMutation.id,
3405
- params: {
3406
- unitId,
3407
- subUnitId,
3408
- tableId: table.getId(),
3409
- config: { rowColOperation: {
3410
- operationType: "delete",
3411
- rowColType: "column",
3412
- index: range.startColumn,
3413
- count: insertColCount
3414
- } }
3415
- }
3416
- });
3417
- undos.push({
3418
- id: RemoveColMutation.id,
3419
- params: {
3420
- unitId,
3421
- subUnitId,
3422
- range: { ...range }
3423
- }
3424
- });
3425
- } else {
3426
- const oldRange = table.getRange();
3427
- redos.push({
3428
- id: SetSheetTableMutation.id,
3429
- params: {
3430
- unitId,
3431
- subUnitId,
3432
- tableId: table.getId(),
3433
- config: { rowColOperation: {
3434
- operationType: "insert",
3435
- rowColType: "column",
3436
- index: range.startColumn,
3437
- count: insertColCount
3438
- } }
3439
- }
3440
- });
3441
- undos.push({
3442
- id: SetSheetTableMutation.id,
3443
- params: {
3444
- unitId,
3445
- subUnitId,
3446
- tableId: table.getId(),
3447
- config: { rowColOperation: {
3448
- operationType: "delete",
3449
- rowColType: "column",
3450
- index: range.startColumn,
3451
- count: insertColCount
3452
- } }
3453
- }
3454
- });
3455
- const moveRangeMutations = getMoveRangeUndoRedoMutations(accessor, {
3456
- unitId,
3457
- subUnitId,
3458
- range: {
3459
- startRow: oldRange.startRow,
3460
- endRow: oldRange.endRow,
3461
- startColumn: range.startColumn,
3462
- endColumn: colContentIndex
3463
- }
3464
- }, {
3465
- unitId,
3466
- subUnitId,
3467
- range: {
3468
- startRow: oldRange.startRow,
3469
- endRow: oldRange.endRow,
3470
- startColumn: range.startColumn + insertColCount,
3471
- endColumn: colContentIndex + insertColCount
3472
- }
3473
- });
3474
- if (moveRangeMutations) {
3475
- redos.push(...moveRangeMutations.redos);
3476
- undos.push(...moveRangeMutations.undos);
3477
- }
3478
- }
3479
- const commandService = accessor.get(ICommandService);
3480
- if (sequenceExecute(redos, commandService).result) {
3481
- accessor.get(IUndoRedoService).pushUndoRedo({
3482
- unitID: unitId,
3483
- undoMutations: undos,
3484
- redoMutations: redos
3485
- });
3486
- return true;
3487
- }
3488
- return false;
3489
- }
3490
- };
3491
- const SheetTableInsertColumnAtCommand = {
3492
- id: "sheet.command.table-insert-column-at",
3493
- type: CommandType.COMMAND,
3494
- handler: (accessor, params) => {
3495
- if (!params) return false;
3496
- const { unitId, subUnitId, tableId, index, count = 1 } = params;
3497
- if (count <= 0) return false;
3498
- const univerInstanceService = accessor.get(IUniverInstanceService);
3499
- const target = getSheetCommandTarget(univerInstanceService, {
3500
- unitId,
3501
- subUnitId
3502
- });
3503
- if (!target) return false;
3504
- const table = accessor.get(TableManager).getTableById(unitId, tableId);
3505
- if (!table || table.getSubunitId() !== subUnitId) return false;
3506
- const oldRange = table.getRange();
3507
- if (index < oldRange.startColumn || index > oldRange.endColumn + 1) return false;
3508
- const redos = [{
3509
- id: SetSheetTableMutation.id,
3510
- params: {
3511
- unitId,
3512
- subUnitId,
3513
- tableId,
3514
- config: { rowColOperation: {
3515
- operationType: "insert",
3516
- rowColType: "column",
3517
- index,
3518
- count
3519
- } }
3520
- }
3521
- }];
3522
- const undos = [{
3523
- id: SetSheetTableMutation.id,
3524
- params: {
3525
- unitId,
3526
- subUnitId,
3527
- tableId,
3528
- config: { rowColOperation: {
3529
- operationType: "delete",
3530
- rowColType: "column",
3531
- index,
3532
- count
3533
- } }
3534
- }
3535
- }];
3536
- const colContentIndex = target.worksheet.getCellMatrix().getDataRange().endColumn;
3537
- if (index <= colContentIndex) {
3538
- const moveRangeMutations = getMoveRangeUndoRedoMutations(accessor, {
3539
- unitId,
3540
- subUnitId,
3541
- range: {
3542
- startRow: oldRange.startRow,
3543
- endRow: oldRange.endRow,
3544
- startColumn: index,
3545
- endColumn: colContentIndex
3546
- }
3547
- }, {
3548
- unitId,
3549
- subUnitId,
3550
- range: {
3551
- startRow: oldRange.startRow,
3552
- endRow: oldRange.endRow,
3553
- startColumn: index + count,
3554
- endColumn: colContentIndex + count
3555
- }
3556
- });
3557
- if (moveRangeMutations) {
3558
- redos.push(...moveRangeMutations.redos);
3559
- undos.push(...moveRangeMutations.undos);
3560
- }
3561
- }
3562
- return executeTableMutationSequence(accessor, unitId, redos, undos);
3563
- }
3564
- };
3565
- const SheetTableRemoveColumnAtCommand = {
3566
- id: "sheet.command.table-remove-column-at",
3567
- type: CommandType.COMMAND,
3568
- handler: (accessor, params) => {
3569
- if (!params) return false;
3570
- const { unitId, subUnitId, tableId, index, count = 1 } = params;
3571
- if (count <= 0) return false;
3572
- const univerInstanceService = accessor.get(IUniverInstanceService);
3573
- const target = getSheetCommandTarget(univerInstanceService, {
3574
- unitId,
3575
- subUnitId
3576
- });
3577
- if (!target) return false;
3578
- const table = accessor.get(TableManager).getTableById(unitId, tableId);
3579
- if (!table || table.getSubunitId() !== subUnitId) return false;
3580
- const oldRange = table.getRange();
3581
- if (index < oldRange.startColumn || index + count - 1 > oldRange.endColumn || count >= oldRange.endColumn - oldRange.startColumn + 1) return false;
3582
- const tableInfo = table.getTableInfo();
3583
- const columns = [];
3584
- const gap = index - oldRange.startColumn;
3585
- for (let i = 0; i < count; i++) {
3586
- const column = tableInfo.columns[gap + i];
3587
- if (column) columns.push(column);
3588
- }
3589
- const interceptorCommands = accessor.get(SheetInterceptorService).onCommandExecute({
3590
- id: SheetTableRemoveColumnAtCommand.id,
3591
- params: {
3592
- ...params,
3593
- tableName: tableInfo.name,
3594
- removedColumnNames: columns.map((column) => column.displayName)
3595
- }
3596
- });
3597
- const redos = [
3598
- ...interceptorCommands.preRedos ?? [],
3599
- {
3600
- id: SetSheetTableMutation.id,
3601
- params: {
3602
- unitId,
3603
- subUnitId,
3604
- tableId,
3605
- config: { rowColOperation: {
3606
- operationType: "delete",
3607
- rowColType: "column",
3608
- index,
3609
- count
3610
- } }
3611
- }
3612
- },
3613
- ...interceptorCommands.redos
3614
- ];
3615
- const undos = [
3616
- ...interceptorCommands.preUndos ?? [],
3617
- {
3618
- id: SetSheetTableMutation.id,
3619
- params: {
3620
- unitId,
3621
- subUnitId,
3622
- tableId,
3623
- config: { rowColOperation: {
3624
- operationType: "insert",
3625
- rowColType: "column",
3626
- index,
3627
- count,
3628
- columnsJson: columns
3629
- } }
3630
- }
3631
- },
3632
- ...interceptorCommands.undos
3633
- ];
3634
- const colContentIndex = target.worksheet.getCellMatrix().getDataRange().endColumn;
3635
- if (index + count <= colContentIndex) {
3636
- const moveRangeMutations = getMoveRangeUndoRedoMutations(accessor, {
3637
- unitId,
3638
- subUnitId,
3639
- range: {
3640
- startRow: oldRange.startRow,
3641
- endRow: oldRange.endRow,
3642
- startColumn: index + count,
3643
- endColumn: colContentIndex
3644
- }
3645
- }, {
3646
- unitId,
3647
- subUnitId,
3648
- range: {
3649
- startRow: oldRange.startRow,
3650
- endRow: oldRange.endRow,
3651
- startColumn: index,
3652
- endColumn: colContentIndex - count
3653
- }
3654
- });
3655
- if (moveRangeMutations) {
3656
- redos.push(...moveRangeMutations.redos);
3657
- undos.push(...moveRangeMutations.undos);
3658
- }
3659
- }
3660
- return executeTableMutationSequence(accessor, unitId, redos, undos);
3661
- }
3662
- };
3663
- const SheetTableRemoveRowCommand = {
3664
- id: "sheet.command.table-remove-row",
3665
- type: CommandType.COMMAND,
3666
- handler: (accessor, params) => {
3667
- if (!params) return false;
3668
- const univerInstanceService = accessor.get(IUniverInstanceService);
3669
- const target = getSheetCommandTarget(univerInstanceService, params);
3670
- if (!target) return false;
3671
- const { unitId, subUnitId } = target;
3672
- const selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
3673
- if (!selections.length || selections.length > 1) return false;
3674
- const range = selections[0].range;
3675
- const table = accessor.get(SheetsTableController).getContainerTableWithRange(unitId, subUnitId, range);
3676
- if (!table) return false;
3677
- const removeRowCount = range.endRow - range.startRow + 1;
3678
- const redos = [];
3679
- const undos = [];
3680
- const oldRange = table.getRange();
3681
- redos.push({
3682
- id: SetSheetTableMutation.id,
3683
- params: {
3684
- unitId,
3685
- subUnitId,
3686
- tableId: table.getId(),
3687
- config: { updateRange: { newRange: {
3688
- ...oldRange,
3689
- endRow: oldRange.endRow - removeRowCount
3690
- } } }
3691
- }
3692
- });
3693
- undos.push({
3694
- id: SetSheetTableMutation.id,
3695
- params: {
3696
- unitId,
3697
- subUnitId,
3698
- tableId: table.getId(),
3699
- config: { updateRange: { newRange: { ...oldRange } } }
3700
- }
3701
- });
3702
- const rowContentIndex = target.worksheet.getCellMatrix().getDataRange().endRow;
3703
- const moveRangeMutations = getMoveRangeUndoRedoMutations(accessor, {
3704
- unitId,
3705
- subUnitId,
3706
- range: {
3707
- startRow: range.endRow + 1,
3708
- endRow: rowContentIndex,
3709
- startColumn: oldRange.startColumn,
3710
- endColumn: oldRange.endColumn
3711
- }
3712
- }, {
3713
- unitId,
3714
- subUnitId,
3715
- range: {
3716
- startRow: range.startRow,
3717
- endRow: rowContentIndex - removeRowCount,
3718
- startColumn: oldRange.startColumn,
3719
- endColumn: oldRange.endColumn
3720
- }
3721
- });
3722
- if (moveRangeMutations) {
3723
- redos.push(...moveRangeMutations.redos);
3724
- undos.push(...moveRangeMutations.undos);
3725
- }
3726
- const commandService = accessor.get(ICommandService);
3727
- if (sequenceExecute(redos, commandService).result) {
3728
- accessor.get(IUndoRedoService).pushUndoRedo({
3729
- unitID: unitId,
3730
- undoMutations: undos,
3731
- redoMutations: redos
3732
- });
3733
- return true;
3734
- }
3735
- return false;
3736
- }
3737
- };
3738
- const SheetTableRemoveColCommand = {
3739
- id: "sheet.command.table-remove-col",
3740
- type: CommandType.COMMAND,
3741
- handler: (accessor, params) => {
3742
- if (!params) return false;
3743
- const univerInstanceService = accessor.get(IUniverInstanceService);
3744
- const target = getSheetCommandTarget(univerInstanceService, params);
3745
- if (!target) return false;
3746
- const { workbook, unitId, subUnitId } = target;
3747
- accessor.get(TableManager);
3748
- const selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
3749
- if (!selections.length || selections.length > 1) return false;
3750
- const range = selections[0].range;
3751
- const table = accessor.get(SheetsTableController).getContainerTableWithRange(unitId, subUnitId, range);
3752
- if (!table) return false;
3753
- const removeColCount = range.endColumn - range.startColumn + 1;
3754
- const redos = [];
3755
- const undos = [];
3756
- const oldRange = table.getRange();
3757
- redos.push({
3758
- id: SetSheetTableMutation.id,
3759
- params: {
3760
- unitId,
3761
- subUnitId,
3762
- tableId: table.getId(),
3763
- config: { rowColOperation: {
3764
- operationType: "delete",
3765
- rowColType: "column",
3766
- index: range.startColumn,
3767
- count: removeColCount
3768
- } }
3769
- }
3770
- });
3771
- const tableInfo = table.getTableInfo();
3772
- const columns = [];
3773
- const gap = range.startColumn - oldRange.startColumn;
3774
- for (let i = 0; i < removeColCount; i++) {
3775
- const column = tableInfo.columns[gap + i];
3776
- if (column) columns.push(column);
3777
- }
3778
- const interceptorCommands = accessor.get(SheetInterceptorService).onCommandExecute({
3779
- id: SheetTableRemoveColCommand.id,
3780
- params: {
3781
- ...params,
3782
- tableName: tableInfo.name,
3783
- removedColumnNames: columns.map((column) => column.displayName)
3784
- }
3785
- });
3786
- redos.unshift(...interceptorCommands.preRedos ?? []);
3787
- redos.push(...interceptorCommands.redos);
3788
- undos.unshift(...interceptorCommands.preUndos ?? []);
3789
- undos.push({
3790
- id: SetSheetTableMutation.id,
3791
- params: {
3792
- unitId,
3793
- subUnitId,
3794
- tableId: table.getId(),
3795
- config: { rowColOperation: {
3796
- operationType: "insert",
3797
- rowColType: "column",
3798
- index: range.startColumn,
3799
- count: removeColCount,
3800
- columnsJson: columns
3801
- } }
3802
- }
3803
- });
3804
- undos.push(...interceptorCommands.undos);
3805
- const colContentIndex = target.worksheet.getCellMatrix().getDataRange().endColumn;
3806
- const moveRangeMutations = getMoveRangeUndoRedoMutations(accessor, {
3807
- unitId,
3808
- subUnitId,
3809
- range: {
3810
- startRow: oldRange.startRow,
3811
- endRow: oldRange.endRow,
3812
- startColumn: range.endColumn + 1,
3813
- endColumn: colContentIndex
3814
- }
3815
- }, {
3816
- unitId,
3817
- subUnitId,
3818
- range: {
3819
- startRow: oldRange.startRow,
3820
- endRow: oldRange.endRow,
3821
- startColumn: range.startColumn,
3822
- endColumn: colContentIndex - removeColCount
3823
- }
3824
- });
3825
- if (moveRangeMutations) {
3826
- redos.push(...moveRangeMutations.redos);
3827
- undos.push(...moveRangeMutations.undos);
3828
- }
3829
- const commandService = accessor.get(ICommandService);
3830
- if (sequenceExecute(redos, commandService).result) {
3831
- accessor.get(IUndoRedoService).pushUndoRedo({
3832
- unitID: unitId,
3833
- undoMutations: undos,
3834
- redoMutations: redos
3835
- });
3836
- return true;
3837
- }
3838
- return false;
3839
- }
3840
- };
3841
-
3842
- //#endregion
3843
- //#region src/controllers/sheet-table-theme.controller.ts
3844
- let SheetsTableThemeController = class SheetsTableThemeController extends Disposable {
3845
- constructor(_tableManager, _sheetRangeThemeService, _sheetRangeThemeModel, _configService) {
3846
- super();
3847
- this._tableManager = _tableManager;
3848
- this._sheetRangeThemeService = _sheetRangeThemeService;
3849
- this._sheetRangeThemeModel = _sheetRangeThemeModel;
3850
- this._configService = _configService;
3851
- _defineProperty(this, "_defaultThemeIndex", 0);
3852
- _defineProperty(this, "_allThemes", []);
3853
- this._initUserTableTheme();
3854
- this.registerTableChangeEvent();
3855
- this._initDefaultTableTheme();
3856
- }
3857
- registerTableChangeEvent() {
3858
- this.disposeWithMe(this._tableManager.tableAdd$.subscribe((event) => {
3859
- const { range, tableId, unitId, subUnitId, tableStyleId } = event;
3860
- const table = this._tableManager.getTable(unitId, tableId);
3861
- const _tableStyleId = tableStyleId || this._allThemes[this._defaultThemeIndex].name;
3862
- table.setTableStyleId(_tableStyleId);
3863
- this._sheetRangeThemeService.registerRangeThemeStyle(_tableStyleId, {
3864
- unitId,
3865
- subUnitId,
3866
- range: { ...range }
3867
- });
3868
- }));
3869
- this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe((event) => {
3870
- const { range, oldRange, tableId, unitId, subUnitId, oldSubUnitId = subUnitId } = event;
3871
- const table = this._tableManager.getTable(unitId, tableId);
3872
- let tableStyleId = table.getTableStyleId();
3873
- if (!tableStyleId) {
3874
- tableStyleId = this._allThemes[this._defaultThemeIndex].name;
3875
- table.setTableStyleId(tableStyleId);
3876
- }
3877
- this._sheetRangeThemeService.removeRangeThemeRule(tableStyleId, {
3878
- unitId,
3879
- subUnitId: oldSubUnitId,
3880
- range: { ...oldRange }
3881
- });
3882
- this._sheetRangeThemeService.registerRangeThemeStyle(tableStyleId, {
3883
- unitId,
3884
- subUnitId,
3885
- range: { ...range }
3886
- });
3887
- }));
3888
- this.disposeWithMe(this._tableManager.tableThemeChanged$.subscribe((event) => {
3889
- const { theme, oldTheme, tableId, unitId, subUnitId } = event;
3890
- const range = this._tableManager.getTable(unitId, tableId).getRange();
3891
- this._sheetRangeThemeService.removeRangeThemeRule(oldTheme, {
3892
- unitId,
3893
- subUnitId,
3894
- range: { ...range }
3895
- });
3896
- this._sheetRangeThemeService.registerRangeThemeStyle(theme, {
3897
- unitId,
3898
- subUnitId,
3899
- range: { ...range }
3900
- });
3901
- }));
3902
- this.disposeWithMe(this._tableManager.tableDelete$.subscribe((event) => {
3903
- const { range, unitId, subUnitId, tableStyleId = this._allThemes[this._defaultThemeIndex].name } = event;
3904
- this._sheetRangeThemeService.removeRangeThemeRule(tableStyleId, {
3905
- unitId,
3906
- subUnitId,
3907
- range: { ...range }
3908
- });
3909
- }));
3910
- }
3911
- _initUserTableTheme() {
3912
- const tableConfig = this._configService.getConfig("sheets-table.config") || {};
3913
- const defaultThemeIndex = tableConfig.defaultThemeIndex || 0;
3914
- const userThemes = tableConfig.userThemes || [];
3915
- this._defaultThemeIndex = defaultThemeIndex;
3916
- this._allThemes = userThemes.concat(tableThemeConfig);
3917
- }
3918
- _initDefaultTableTheme() {
3919
- for (let i = 0; i < this._allThemes.length; i++) {
3920
- const { name, style } = this._allThemes[i];
3921
- const rangeThemeStyle = new RangeThemeStyle(name, style);
3922
- this._sheetRangeThemeModel.registerDefaultRangeTheme(rangeThemeStyle);
3923
- }
3924
- }
3925
- dispose() {
3926
- super.dispose();
3927
- this._allThemes = [];
3928
- this._defaultThemeIndex = 0;
3929
- }
3930
- };
3931
- SheetsTableThemeController = __decorate([
3932
- __decorateParam(0, Inject(TableManager)),
3933
- __decorateParam(1, Inject(SheetRangeThemeService)),
3934
- __decorateParam(2, Inject(SheetRangeThemeModel)),
3935
- __decorateParam(3, IConfigService)
3936
- ], SheetsTableThemeController);
3937
-
3938
- //#endregion
3939
- //#region package.json
3940
- var name = "@univerjs/sheets-table";
3941
- var version = "1.3.0";
3942
-
3943
- //#endregion
3944
- //#region src/commands/mutations/move-sheet-table.mutation.ts
3945
- const MoveSheetTableMutation = {
3946
- id: "sheet.mutation.move-table",
3947
- type: CommandType.MUTATION,
3948
- handler: (accessor, params) => {
3949
- if (!params) return false;
3950
- const { unitId, tableId, subUnitId, range, calculatedColumns } = params;
3951
- const manager = accessor.get(TableManager);
3952
- const table = manager.getTableById(unitId, tableId);
3953
- const workbook = accessor.get(IUniverInstanceService).getUnit(unitId);
3954
- const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
3955
- if (!table || !worksheet) return false;
3956
- const columns = calculatedColumns ?? table.getTableInfo().columns.map((column, columnIndex) => {
3957
- var _worksheet$getCellRaw;
3958
- const row = range.startRow + (table.isShowHeader() ? 1 : 0);
3959
- const endRow = range.endRow - (table.isShowFooter() ? 1 : 0);
3960
- const formula = column.formula && row <= endRow ? (_worksheet$getCellRaw = worksheet.getCellRaw(row, range.startColumn + columnIndex)) === null || _worksheet$getCellRaw === void 0 ? void 0 : _worksheet$getCellRaw.f : void 0;
3961
- return {
3962
- columnId: column.id,
3963
- formula: formula || column.formula,
3964
- formulaIsArray: column.formulaIsArray
3965
- };
3966
- }).filter((column) => column.formula);
3967
- for (const config of columns) {
3968
- const column = table.getColumn(config.columnId);
3969
- if (column) {
3970
- column.formula = config.formula;
3971
- column.formulaIsArray = config.formulaIsArray;
3972
- }
3973
- }
3974
- manager.moveTable(unitId, tableId, subUnitId, range);
3975
- return true;
3976
- }
3977
- };
3978
-
3979
- //#endregion
3980
- //#region src/controllers/sheet-table-formula.controller.ts
3981
- let SheetTableFormulaController = class SheetTableFormulaController extends Disposable {
3982
- constructor(_tableManager, _commandService, _activeDirtyManagerService) {
3983
- super();
3984
- this._tableManager = _tableManager;
3985
- this._commandService = _commandService;
3986
- this._activeDirtyManagerService = _activeDirtyManagerService;
3987
- this._initRangeListener();
3988
- this._initFilterDirtyRange();
3989
- }
3990
- _initFilterDirtyRange() {
3991
- this._activeDirtyManagerService.register(SetSheetTableFilterMutation.id, {
3992
- commandId: SetSheetTableFilterMutation.id,
3993
- getDirtyData: (command) => {
3994
- const params = command.params;
3995
- const table = this._tableManager.getTableById(params.unitId, params.tableId);
3996
- if (!table) return {};
3997
- const { subUnitId, range } = table.getTableInfo();
3998
- return {
3999
- dirtyRanges: [{
4000
- unitId: params.unitId,
4001
- sheetId: subUnitId,
4002
- range
4003
- }],
4004
- clearDependencyTreeCache: { [params.unitId]: { [subUnitId]: "1" } }
4005
- };
4006
- }
4007
- });
4008
- this.disposeWithMe(toDisposable(() => {
4009
- this._activeDirtyManagerService.remove(SetSheetTableFilterMutation.id);
4010
- }));
4011
- }
4012
- _initRangeListener() {
4013
- this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe((event) => {
4014
- const { tableId, unitId } = event;
4015
- const table = this._tableManager.getTableById(unitId, tableId);
4016
- if (!table) return;
4017
- this._updateSuperTable(unitId, table);
4018
- }));
4019
- this.disposeWithMe(this._tableManager.tableAdd$.subscribe((event) => {
4020
- const { tableId, unitId } = event;
4021
- const table = this._tableManager.getTableById(unitId, tableId);
4022
- if (!table) return;
4023
- this._updateSuperTable(unitId, table);
4024
- }));
4025
- this.disposeWithMe(this._tableManager.tableDelete$.subscribe((event) => {
4026
- const { unitId, subUnitId, tableName, range } = event;
4027
- this._commandService.executeCommand(RemoveSuperTableMutation.id, {
4028
- unitId,
4029
- tableName,
4030
- reference: {
4031
- sheetId: subUnitId,
4032
- range
4033
- }
4034
- }, { onlyLocal: true });
4035
- }));
4036
- this.disposeWithMe(this._tableManager.tableNameChanged$.subscribe((event) => {
4037
- const { tableId, unitId, oldTableName } = event;
4038
- this._commandService.executeCommand(RemoveSuperTableMutation.id, {
4039
- unitId,
4040
- tableName: oldTableName
4041
- }, { onlyLocal: true });
4042
- const table = this._tableManager.getTableById(unitId, tableId);
4043
- if (!table) return;
4044
- this._updateSuperTable(unitId, table, oldTableName);
4045
- }));
4046
- }
4047
- _updateSuperTable(unitId, table, oldTableName) {
4048
- const tableInfo = table.getTableInfo();
4049
- const name = tableInfo.name;
4050
- const columns = tableInfo.columns;
4051
- const titleMap = /* @__PURE__ */ new Map();
4052
- columns.forEach((column, index) => {
4053
- titleMap.set(column.displayName, index);
4054
- });
4055
- this._commandService.executeCommand(SetSuperTableMutation.id, {
4056
- unitId,
4057
- tableName: name,
4058
- oldTableName,
4059
- reference: {
4060
- range: tableInfo.range,
4061
- sheetId: tableInfo.subUnitId,
4062
- titleMap
4063
- }
4064
- }, { onlyLocal: true });
4065
- }
4066
- };
4067
- SheetTableFormulaController = __decorate([
4068
- __decorateParam(0, Inject(TableManager)),
4069
- __decorateParam(1, ICommandService),
4070
- __decorateParam(2, IActiveDirtyManagerService)
4071
- ], SheetTableFormulaController);
4072
-
4073
- //#endregion
4074
- //#region src/controllers/sheet-table-move.controller.ts
4075
- let SheetTableMoveController = class SheetTableMoveController extends Disposable {
4076
- constructor(_tableManager, _sheetInterceptorService, _univerInstanceService, _injector, _localeService, _errorService) {
4077
- super();
4078
- this._tableManager = _tableManager;
4079
- this._sheetInterceptorService = _sheetInterceptorService;
4080
- this._univerInstanceService = _univerInstanceService;
4081
- this._injector = _injector;
4082
- this._localeService = _localeService;
4083
- this._errorService = _errorService;
4084
- this.disposeWithMe(this._sheetInterceptorService.interceptBeforeCommand({ performCheck: async (command) => command.id !== MoveRangeCommand.id || this._checkMove(command.params) }));
4085
- this.disposeWithMe(this._sheetInterceptorService.interceptAfterCommand({ getMutations: (command) => command.id === MoveRangeCommand.id ? this._getMoveMutations(command.params) : {
4086
- redos: [],
4087
- undos: []
4088
- } }));
4089
- }
4090
- _getTargets(params) {
4091
- const source = getSheetCommandTarget(this._univerInstanceService, {
4092
- unitId: params.fromUnitId ?? params.toUnitId,
4093
- subUnitId: params.fromSubUnitId
4094
- });
4095
- return {
4096
- source,
4097
- target: getSheetCommandTarget(this._univerInstanceService, {
4098
- unitId: params.toUnitId ?? (source === null || source === void 0 ? void 0 : source.unitId),
4099
- subUnitId: params.toSubUnitId ?? (source === null || source === void 0 ? void 0 : source.subUnitId)
4100
- })
4101
- };
4102
- }
4103
- _checkMove(params) {
4104
- const { source, target } = this._getTargets(params);
4105
- if (!source || !target || source.unitId !== target.unitId) return false;
4106
- const movingTables = this._tableManager.getTablesBySubunitId(source.unitId, source.subUnitId).filter((table) => Rectangle.contains(params.fromRange, table.getRange()));
4107
- if (!movingTables.length) return true;
4108
- const targetTables = this._tableManager.getTablesBySubunitId(target.unitId, target.subUnitId);
4109
- for (const table of targetTables) {
4110
- if (movingTables.includes(table) || !Rectangle.intersects(params.toRange, table.getRange())) continue;
4111
- this._errorService.emit(this._localeService.t("sheets-table.moveTableOverlapError"));
4112
- return false;
4113
- }
4114
- const { fromRange, toRange } = params;
4115
- if (!this._isValidMoveRange(params, target.worksheet)) return false;
4116
- return checkRangesEditablePermission(this._injector, source.unitId, source.subUnitId, [fromRange]) && checkRangesEditablePermission(this._injector, target.unitId, target.subUnitId, [toRange]);
4117
- }
4118
- _isValidMoveRange(params, worksheet) {
4119
- const { fromRange, toRange } = params;
4120
- if (fromRange.endRow - fromRange.startRow !== toRange.endRow - toRange.startRow || fromRange.endColumn - fromRange.startColumn !== toRange.endColumn - toRange.startColumn || toRange.startRow < 0 || toRange.startColumn < 0 || toRange.endRow >= worksheet.getRowCount() || toRange.endColumn >= worksheet.getColumnCount()) return false;
4121
- return true;
4122
- }
4123
- _getMoveMutations(params) {
4124
- const redos = [];
4125
- const undos = [];
4126
- const { source, target } = this._getTargets(params);
4127
- if (!source || !target || source.unitId !== target.unitId) return {
4128
- redos,
4129
- undos
4130
- };
4131
- const rowOffset = params.toRange.startRow - params.fromRange.startRow;
4132
- const columnOffset = params.toRange.startColumn - params.fromRange.startColumn;
4133
- const tables = this._tableManager.getTablesBySubunitId(source.unitId, source.subUnitId);
4134
- for (const table of tables) {
4135
- const range = table.getRange();
4136
- if (!Rectangle.contains(params.fromRange, range)) continue;
4137
- redos.push({
4138
- id: MoveSheetTableMutation.id,
4139
- params: {
4140
- unitId: source.unitId,
4141
- tableId: table.getId(),
4142
- subUnitId: target.subUnitId,
4143
- range: {
4144
- startRow: range.startRow + rowOffset,
4145
- endRow: range.endRow + rowOffset,
4146
- startColumn: range.startColumn + columnOffset,
4147
- endColumn: range.endColumn + columnOffset
4148
- }
4149
- }
4150
- });
4151
- undos.push({
4152
- id: MoveSheetTableMutation.id,
4153
- params: {
4154
- unitId: source.unitId,
4155
- tableId: table.getId(),
4156
- subUnitId: source.subUnitId,
4157
- range,
4158
- calculatedColumns: table.getTableInfo().columns.filter((column) => column.formula).map((column) => ({
4159
- columnId: column.id,
4160
- formula: column.formula,
4161
- formulaIsArray: column.formulaIsArray
4162
- }))
4163
- }
4164
- });
4165
- }
4166
- return {
4167
- redos,
4168
- undos
4169
- };
4170
- }
4171
- };
4172
- SheetTableMoveController = __decorate([
4173
- __decorateParam(0, Inject(TableManager)),
4174
- __decorateParam(1, Inject(SheetInterceptorService)),
4175
- __decorateParam(2, IUniverInstanceService),
4176
- __decorateParam(3, Inject(Injector)),
4177
- __decorateParam(4, Inject(LocaleService)),
4178
- __decorateParam(5, Inject(ErrorService))
4179
- ], SheetTableMoveController);
4180
-
4181
- //#endregion
4182
- //#region src/controllers/sheet-table-range.controller.ts
4183
- /**
4184
- * Copyright 2023-present DreamNum Co., Ltd.
4185
- *
4186
- * Licensed under the Apache License, Version 2.0 (the "License");
4187
- * you may not use this file except in compliance with the License.
4188
- * You may obtain a copy of the License at
4189
- *
4190
- * http://www.apache.org/licenses/LICENSE-2.0
4191
- *
4192
- * Unless required by applicable law or agreed to in writing, software
4193
- * distributed under the License is distributed on an "AS IS" BASIS,
4194
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4195
- * See the License for the specific language governing permissions and
4196
- * limitations under the License.
4197
- */
4198
- let SheetTableRangeController = class SheetTableRangeController extends Disposable {
4199
- constructor(_tableManager, _exclusiveRangeService) {
4200
- super();
4201
- this._tableManager = _tableManager;
4202
- this._exclusiveRangeService = _exclusiveRangeService;
4203
- this._initRangeListener();
4204
- }
4205
- _initRangeListener() {
4206
- this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe((event) => {
4207
- const { range, tableId, unitId, subUnitId, oldSubUnitId = subUnitId } = event;
4208
- this._exclusiveRangeService.clearExclusiveRangesByGroupId(unitId, oldSubUnitId, FEATURE_TABLE_ID, tableId);
4209
- this._exclusiveRangeService.addExclusiveRange(unitId, subUnitId, FEATURE_TABLE_ID, [{
4210
- range: { ...range },
4211
- groupId: tableId
4212
- }]);
4213
- }));
4214
- this.disposeWithMe(this._tableManager.tableAdd$.subscribe((event) => {
4215
- const { tableId, unitId, subUnitId, range } = event;
4216
- this._exclusiveRangeService.addExclusiveRange(unitId, subUnitId, FEATURE_TABLE_ID, [{
4217
- range: { ...range },
4218
- groupId: tableId
4219
- }]);
4220
- }));
4221
- this.disposeWithMe(this._tableManager.tableDelete$.subscribe((event) => {
4222
- const { tableId, unitId, subUnitId } = event;
4223
- this._exclusiveRangeService.clearExclusiveRangesByGroupId(unitId, subUnitId, FEATURE_TABLE_ID, tableId);
4224
- }));
4225
- }
4226
- };
4227
- SheetTableRangeController = __decorate([__decorateParam(0, Inject(TableManager)), __decorateParam(1, Inject(IExclusiveRangeService))], SheetTableRangeController);
4228
-
4229
- //#endregion
4230
- //#region src/controllers/sheet-table-ref-range.controller.ts
4231
- const SHEET_TABLE_REMOVE_COL_COMMAND_ID = "sheet.command.table-remove-col";
4232
- const DELETE_SHEET_TABLE_COMMAND_ID = "sheet.command.delete-table";
4233
- let SheetTableRefRangeController = class SheetTableRefRangeController extends Disposable {
4234
- constructor(_commandService, _refRangeService, _univerInstanceService, _injector, _sheetInterceptorService, _tableManager, _localeService) {
4235
- super();
4236
- this._commandService = _commandService;
4237
- this._refRangeService = _refRangeService;
4238
- this._univerInstanceService = _univerInstanceService;
4239
- this._injector = _injector;
4240
- this._sheetInterceptorService = _sheetInterceptorService;
4241
- this._tableManager = _tableManager;
4242
- this._localeService = _localeService;
4243
- this._initCommandInterceptor();
4244
- this._initCommandListener();
4245
- }
4246
- _initCommandInterceptor() {
4247
- const self = this;
4248
- this._sheetInterceptorService.interceptCommand({
4249
- priority: -1,
4250
- getMutations(commandInfo) {
4251
- const defaultReturn = {
4252
- redos: [],
4253
- undos: []
4254
- };
4255
- const { id, params } = commandInfo;
4256
- switch (id) {
4257
- case InsertRowCommand.id: return self._generateTableMutationWithInsertRow(params);
4258
- case InsertColCommand.id: return self._generateTableMutationWithInsertCol(params);
4259
- case RemoveRowCommand.id: return self._generateTableMutationWithRemoveRow(params);
4260
- case RemoveColCommand.id: return self._generateTableMutationWithRemoveCol(params);
4261
- }
4262
- return defaultReturn;
4263
- }
4264
- });
4265
- }
4266
- _generateTableMutationWithInsertRow(insertParams) {
4267
- const undos = [];
4268
- const redos = [];
4269
- const target = getSheetCommandTarget(this._univerInstanceService, insertParams);
4270
- if (!target) return {
4271
- undos,
4272
- redos
4273
- };
4274
- const { unitId, subUnitId } = target;
4275
- const allSubUnitTables = this._tableManager.getTablesBySubunitId(unitId, subUnitId);
4276
- if (!allSubUnitTables.length) return {
4277
- undos,
4278
- redos
4279
- };
4280
- const { range } = insertParams;
4281
- allSubUnitTables.forEach((table) => {
4282
- const tableRange = table.getRange();
4283
- if (range.startRow > tableRange.startRow && range.startRow <= tableRange.endRow) {
4284
- const insertRowCount = range.endRow - range.startRow + 1;
4285
- redos.push({
4286
- id: SetSheetTableMutation.id,
4287
- params: {
4288
- unitId,
4289
- subUnitId,
4290
- tableId: table.getId(),
4291
- config: { updateRange: { newRange: {
4292
- ...tableRange,
4293
- endRow: tableRange.endRow + insertRowCount
4294
- } } }
4295
- }
4296
- });
4297
- const formulaMutation = getCalculatedColumnFillMutation(table, unitId, subUnitId, range.startRow, range.endRow, () => this._injector.get(LexerTreeBuilder));
4298
- if (formulaMutation) redos.push(formulaMutation);
4299
- undos.push({
4300
- id: SetSheetTableMutation.id,
4301
- params: {
4302
- unitId,
4303
- subUnitId,
4304
- tableId: table.getId(),
4305
- config: { updateRange: { newRange: { ...tableRange } } }
4306
- }
4307
- });
4308
- }
4309
- });
4310
- return {
4311
- undos,
4312
- redos
4313
- };
4314
- }
4315
- _generateTableMutationWithInsertCol(insertParams) {
4316
- const undos = [];
4317
- const redos = [];
4318
- const target = getSheetCommandTarget(this._univerInstanceService, insertParams);
4319
- if (!target) return {
4320
- undos,
4321
- redos
4322
- };
4323
- const { unitId, subUnitId } = target;
4324
- const allSubUnitTables = this._tableManager.getTablesBySubunitId(unitId, subUnitId);
4325
- if (!allSubUnitTables.length) return {
4326
- undos,
4327
- redos
4328
- };
4329
- const { range } = insertParams;
4330
- allSubUnitTables.forEach((table) => {
4331
- const tableRange = table.getRange();
4332
- if (range.startColumn > tableRange.startColumn && range.startColumn <= tableRange.endColumn) {
4333
- const insertColCount = range.endColumn - range.startColumn + 1;
4334
- redos.push({
4335
- id: SetSheetTableMutation.id,
4336
- params: {
4337
- unitId,
4338
- subUnitId,
4339
- tableId: table.getId(),
4340
- config: { rowColOperation: {
4341
- operationType: "insert",
4342
- rowColType: "column",
4343
- index: range.startColumn,
4344
- count: insertColCount
4345
- } }
4346
- }
4347
- });
4348
- undos.push({
4349
- id: SetSheetTableMutation.id,
4350
- params: {
4351
- unitId,
4352
- subUnitId,
4353
- tableId: table.getId(),
4354
- config: { rowColOperation: {
4355
- operationType: "delete",
4356
- rowColType: "column",
4357
- index: range.startColumn,
4358
- count: insertColCount
4359
- } }
4360
- }
4361
- });
4362
- }
4363
- });
4364
- return {
4365
- undos,
4366
- redos
4367
- };
4368
- }
4369
- _generateTableMutationWithRemoveRow(removeParams) {
4370
- const undos = [];
4371
- const redos = [];
4372
- const preRedos = [];
4373
- const preUndos = [];
4374
- const target = getSheetCommandTarget(this._univerInstanceService);
4375
- if (!target) return {
4376
- undos,
4377
- redos,
4378
- preRedos,
4379
- preUndos
4380
- };
4381
- const { unitId, subUnitId } = target;
4382
- const allSubUnitTables = this._tableManager.getTablesBySubunitId(unitId, subUnitId);
4383
- if (!allSubUnitTables.length) return {
4384
- undos,
4385
- redos,
4386
- preRedos,
4387
- preUndos
4388
- };
4389
- const { range } = removeParams;
4390
- const removeRowCount = range.endRow - range.startRow + 1;
4391
- allSubUnitTables.forEach((table) => {
4392
- const tableRange = table.getRange();
4393
- if (Rectangle.intersects(tableRange, range)) {
4394
- if (range.startRow <= tableRange.startRow && range.endRow >= tableRange.startRow) {
4395
- preRedos.push({
4396
- id: DeleteSheetTableMutation.id,
4397
- params: {
4398
- unitId,
4399
- subUnitId,
4400
- tableId: table.getId()
4401
- }
4402
- });
4403
- const tableJson = table.toJSON();
4404
- undos.push({
4405
- id: AddSheetTableMutation.id,
4406
- params: {
4407
- unitId,
4408
- subUnitId,
4409
- tableId: tableJson.id,
4410
- name: tableJson.name,
4411
- range: tableJson.range,
4412
- options: tableJson.options
4413
- }
4414
- });
4415
- } else if (range.startRow > tableRange.startRow && range.startRow <= tableRange.endRow) {
4416
- redos.push({
4417
- id: SetSheetTableMutation.id,
4418
- params: {
4419
- unitId,
4420
- subUnitId,
4421
- tableId: table.getId(),
4422
- config: { updateRange: { newRange: {
4423
- ...tableRange,
4424
- endRow: tableRange.endRow - removeRowCount
4425
- } } }
4426
- }
4427
- });
4428
- undos.push({
4429
- id: SetSheetTableMutation.id,
4430
- params: {
4431
- unitId,
4432
- subUnitId,
4433
- tableId: table.getId(),
4434
- config: { updateRange: { newRange: { ...tableRange } } }
4435
- }
4436
- });
4437
- } else if (range.startRow < tableRange.endRow && range.endRow >= tableRange.endRow) {
4438
- redos.push({
4439
- id: SetSheetTableMutation.id,
4440
- params: {
4441
- unitId,
4442
- subUnitId,
4443
- tableId: table.getId(),
4444
- config: { updateRange: { newRange: {
4445
- ...tableRange,
4446
- endRow: range.startRow - 1
4447
- } } }
4448
- }
4449
- });
4450
- undos.push({
4451
- id: SetSheetTableMutation.id,
4452
- params: {
4453
- unitId,
4454
- subUnitId,
4455
- tableId: table.getId(),
4456
- config: { updateRange: { newRange: { ...tableRange } } }
4457
- }
4458
- });
4459
- }
4460
- }
4461
- });
4462
- return {
4463
- undos,
4464
- redos,
4465
- preRedos,
4466
- preUndos
4467
- };
4468
- }
4469
- _generateTableMutationWithRemoveCol(removeParams) {
4470
- const undos = [];
4471
- const redos = [];
4472
- const preRedos = [];
4473
- const preUndos = [];
4474
- const target = getSheetCommandTarget(this._univerInstanceService);
4475
- if (!target) return {
4476
- undos,
4477
- redos,
4478
- preRedos,
4479
- preUndos
4480
- };
4481
- const { unitId, subUnitId } = target;
4482
- const allSubUnitTables = this._tableManager.getTablesBySubunitId(unitId, subUnitId);
4483
- if (!allSubUnitTables.length) return {
4484
- undos,
4485
- redos,
4486
- preRedos,
4487
- preUndos
4488
- };
4489
- const { range } = removeParams;
4490
- const removeColCount = range.endColumn - range.startColumn + 1;
4491
- allSubUnitTables.forEach((table) => {
4492
- const tableRange = table.getRange();
4493
- if (Rectangle.intersects(tableRange, range)) {
4494
- if (range.startColumn <= tableRange.startColumn && range.endColumn >= tableRange.endColumn) {
4495
- const tableInfo = table.getTableInfo();
4496
- const formulaMutations = this._sheetInterceptorService.onCommandExecute({
4497
- id: DELETE_SHEET_TABLE_COMMAND_ID,
4498
- params: {
4499
- unitId,
4500
- subUnitId,
4501
- tableId: table.getId(),
4502
- tableName: tableInfo.name
4503
- }
4504
- });
4505
- preRedos.push(...formulaMutations.preRedos ?? [], ...formulaMutations.redos);
4506
- preRedos.push({
4507
- id: DeleteSheetTableMutation.id,
4508
- params: {
4509
- unitId,
4510
- subUnitId,
4511
- tableId: table.getId()
4512
- }
4513
- });
4514
- const tableJson = table.toJSON();
4515
- const { startRow, startColumn, endColumn } = tableJson.range;
4516
- const workbook = this._univerInstanceService.getUnit(unitId);
4517
- const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
4518
- if (!worksheet) return {
4519
- undos,
4520
- redos,
4521
- preRedos,
4522
- preUndos
4523
- };
4524
- const header = [];
4525
- for (let i = startColumn; i <= endColumn; i++) header.push(convertCellDataToString(worksheet === null || worksheet === void 0 ? void 0 : worksheet.getCell(startRow, i)) || getColumnName(i - startColumn + 1, this._localeService.t("sheets-table.columnPrefix")));
4526
- undos.push({
4527
- id: AddSheetTableMutation.id,
4528
- params: {
4529
- unitId,
4530
- subUnitId,
4531
- tableId: tableJson.id,
4532
- name: tableJson.name,
4533
- header,
4534
- range: tableJson.range,
4535
- options: tableJson.options
4536
- }
4537
- });
4538
- undos.push(...formulaMutations.preUndos ?? [], ...formulaMutations.undos);
4539
- } else if (range.startColumn <= tableRange.startColumn && range.endColumn >= tableRange.startColumn) {
4540
- const tableJson = table.toJSON();
4541
- const removeColumnCount = range.endColumn - tableRange.startColumn + 1;
4542
- redos.push({
4543
- id: SetSheetTableMutation.id,
4544
- params: {
4545
- unitId,
4546
- subUnitId,
4547
- tableId: table.getId(),
4548
- config: { rowColOperation: {
4549
- operationType: "delete",
4550
- rowColType: "column",
4551
- index: tableRange.startColumn,
4552
- count: removeColumnCount
4553
- } }
4554
- }
4555
- });
4556
- const columns = [];
4557
- for (let i = 0; i < removeColumnCount; i++) {
4558
- const column = table.getTableColumnByIndex(i);
4559
- if (column) columns.push(column.toJSON());
4560
- }
4561
- preUndos.push(this._getDeleteTableMutation(unitId, subUnitId, table.getId()));
4562
- undos.push(this._getAddTableMutation(unitId, subUnitId, tableJson));
4563
- this._appendTableColumnFormulaMutations(redos, undos, {
4564
- unitId,
4565
- subUnitId,
4566
- tableId: table.getId(),
4567
- tableName: table.getTableInfo().name,
4568
- range,
4569
- columns
4570
- });
4571
- } else if (range.startColumn > tableRange.startColumn && range.endColumn > tableRange.endColumn) {
4572
- const tableJson = table.toJSON();
4573
- const removeColumnCount = tableRange.endColumn - range.startColumn + 1;
4574
- redos.push({
4575
- id: SetSheetTableMutation.id,
4576
- params: {
4577
- unitId,
4578
- subUnitId,
4579
- tableId: table.getId(),
4580
- config: { rowColOperation: {
4581
- operationType: "delete",
4582
- rowColType: "column",
4583
- index: range.startColumn,
4584
- count: removeColumnCount
4585
- } }
4586
- }
4587
- });
4588
- const columns = [];
4589
- const gap = range.startColumn - tableRange.startColumn;
4590
- for (let i = 0; i < removeColumnCount; i++) {
4591
- const column = table.getTableColumnByIndex(i + gap);
4592
- if (column) columns.push(column.toJSON());
4593
- }
4594
- preUndos.push(this._getDeleteTableMutation(unitId, subUnitId, table.getId()));
4595
- undos.push(this._getAddTableMutation(unitId, subUnitId, tableJson));
4596
- this._appendTableColumnFormulaMutations(redos, undos, {
4597
- unitId,
4598
- subUnitId,
4599
- tableId: table.getId(),
4600
- tableName: table.getTableInfo().name,
4601
- range,
4602
- columns
4603
- });
4604
- } else if (range.startColumn > tableRange.startColumn && range.endColumn <= tableRange.endColumn) {
4605
- const tableJson = table.toJSON();
4606
- redos.push({
4607
- id: SetSheetTableMutation.id,
4608
- params: {
4609
- unitId,
4610
- subUnitId,
4611
- tableId: table.getId(),
4612
- config: { rowColOperation: {
4613
- operationType: "delete",
4614
- rowColType: "column",
4615
- index: range.startColumn,
4616
- count: removeColCount
4617
- } }
4618
- }
4619
- });
4620
- const columns = [];
4621
- const gap = range.startColumn - tableRange.startColumn;
4622
- for (let i = 0; i < removeColCount; i++) {
4623
- const column = table.getTableColumnByIndex(i + gap);
4624
- if (column) columns.push(column.toJSON());
4625
- }
4626
- preUndos.push(this._getDeleteTableMutation(unitId, subUnitId, table.getId()));
4627
- undos.push(this._getAddTableMutation(unitId, subUnitId, tableJson));
4628
- this._appendTableColumnFormulaMutations(redos, undos, {
4629
- unitId,
4630
- subUnitId,
4631
- tableId: table.getId(),
4632
- tableName: table.getTableInfo().name,
4633
- range,
4634
- columns
4635
- });
4636
- }
4637
- }
4638
- });
4639
- return {
4640
- undos,
4641
- redos,
4642
- preRedos,
4643
- preUndos
4644
- };
4645
- }
4646
- _getDeleteTableMutation(unitId, subUnitId, tableId) {
4647
- return {
4648
- id: DeleteSheetTableMutation.id,
4649
- params: {
4650
- unitId,
4651
- subUnitId,
4652
- tableId
4653
- }
4654
- };
4655
- }
4656
- _getAddTableMutation(unitId, subUnitId, tableJson) {
4657
- const header = tableJson.columns.map((column) => column.displayName);
4658
- return {
4659
- id: AddSheetTableMutation.id,
4660
- params: {
4661
- unitId,
4662
- subUnitId,
4663
- tableId: tableJson.id,
4664
- name: tableJson.name,
4665
- header,
4666
- range: tableJson.range,
4667
- options: {
4668
- ...tableJson.options,
4669
- columns: tableJson.columns,
4670
- filters: tableJson.filters.tableColumnFilterList
4671
- }
4672
- }
4673
- };
4674
- }
4675
- _appendTableColumnFormulaMutations(redos, undos, info) {
4676
- const removedColumnNames = info.columns.map((column) => column.displayName);
4677
- if (!removedColumnNames.length) return;
4678
- const formulaMutations = this._sheetInterceptorService.onCommandExecute({
4679
- id: SHEET_TABLE_REMOVE_COL_COMMAND_ID,
4680
- params: {
4681
- unitId: info.unitId,
4682
- subUnitId: info.subUnitId,
4683
- tableId: info.tableId,
4684
- tableName: info.tableName,
4685
- range: info.range,
4686
- removedColumnNames
4687
- }
4688
- });
4689
- redos.splice(Math.max(redos.length - 1, 0), 0, ...formulaMutations.preRedos ?? [], ...formulaMutations.redos);
4690
- undos.push(...formulaMutations.preUndos ?? [], ...formulaMutations.undos);
4691
- }
4692
- _initCommandListener() {
4693
- this._commandService.onCommandExecuted((commandInfo) => {
4694
- if (commandInfo.id === InsertRowMutation.id) {
4695
- const { unitId, subUnitId, range } = commandInfo.params;
4696
- const insertCount = range.endRow - range.startRow + 1;
4697
- this._tableManager.getTablesBySubunitId(unitId, subUnitId).forEach((table) => {
4698
- const tableRange = table.getRange();
4699
- if (range.startRow <= tableRange.startRow) this._tableManager.updateTableRange(unitId, table.getId(), { newRange: {
4700
- ...tableRange,
4701
- startRow: tableRange.startRow + insertCount,
4702
- endRow: tableRange.endRow + insertCount
4703
- } });
4704
- });
4705
- } else if (commandInfo.id === InsertColMutation.id) {
4706
- const { unitId, subUnitId, range } = commandInfo.params;
4707
- const insertCount = range.endColumn - range.startColumn + 1;
4708
- this._tableManager.getTablesBySubunitId(unitId, subUnitId).forEach((table) => {
4709
- const tableRange = table.getRange();
4710
- if (range.startColumn <= tableRange.startColumn) this._tableManager.updateTableRange(unitId, table.getId(), { newRange: {
4711
- ...tableRange,
4712
- startColumn: tableRange.startColumn + insertCount,
4713
- endColumn: tableRange.endColumn + insertCount
4714
- } });
4715
- });
4716
- } else if (commandInfo.id === RemoveRowMutation.id) {
4717
- const { unitId, subUnitId, range } = commandInfo.params;
4718
- const removeCount = range.endRow - range.startRow + 1;
4719
- this._tableManager.getTablesBySubunitId(unitId, subUnitId).forEach((table) => {
4720
- const tableRange = table.getRange();
4721
- if (range.startRow < tableRange.startRow) this._tableManager.updateTableRange(unitId, table.getId(), { newRange: {
4722
- ...tableRange,
4723
- startRow: tableRange.startRow - removeCount,
4724
- endRow: tableRange.endRow - removeCount
4725
- } });
4726
- });
4727
- } else if (commandInfo.id === RemoveColMutation.id) {
4728
- const { unitId, subUnitId, range } = commandInfo.params;
4729
- const removeCount = range.endColumn - range.startColumn + 1;
4730
- this._tableManager.getTablesBySubunitId(unitId, subUnitId).forEach((table) => {
4731
- const tableRange = table.getRange();
4732
- if (range.startColumn < tableRange.startColumn) this._tableManager.updateTableRange(unitId, table.getId(), { newRange: {
4733
- ...tableRange,
4734
- startColumn: tableRange.startColumn - removeCount,
4735
- endColumn: tableRange.endColumn - removeCount
4736
- } });
4737
- });
4738
- }
4739
- });
4740
- }
4741
- };
4742
- SheetTableRefRangeController = __decorate([
4743
- __decorateParam(0, Inject(ICommandService)),
4744
- __decorateParam(1, Inject(RefRangeService)),
4745
- __decorateParam(2, Inject(IUniverInstanceService)),
4746
- __decorateParam(3, Inject(Injector)),
4747
- __decorateParam(4, Inject(SheetInterceptorService)),
4748
- __decorateParam(5, Inject(TableManager)),
4749
- __decorateParam(6, Inject(LocaleService))
4750
- ], SheetTableRefRangeController);
4751
-
4752
- //#endregion
4753
- //#region src/controllers/table-filter.controller.ts
4754
- let TableFilterController = class TableFilterController extends Disposable {
4755
- constructor(_tableManager, _sheetInterceptorService, _univerInstanceService, _sheetRowFilteredService, _zebraCrossingCacheController) {
4756
- super();
4757
- this._tableManager = _tableManager;
4758
- this._sheetInterceptorService = _sheetInterceptorService;
4759
- this._univerInstanceService = _univerInstanceService;
4760
- this._sheetRowFilteredService = _sheetRowFilteredService;
4761
- this._zebraCrossingCacheController = _zebraCrossingCacheController;
4762
- _defineProperty(this, "_tableFilteredOutRows", /* @__PURE__ */ new Map());
4763
- this.registerFilterChangeEvent();
4764
- this.initTableHiddenRowIntercept();
4765
- this._registerFormulaRowFiltered();
4766
- this._initFilteredOutRows();
4767
- }
4768
- _registerFormulaRowFiltered() {
4769
- this.disposeWithMe(this._sheetRowFilteredService.register((unitId, subUnitId, row) => {
4770
- return this._getTableFilteredOutRows(unitId, subUnitId).has(row);
4771
- }));
4772
- }
4773
- initTableHiddenRowIntercept() {
4774
- this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.ROW_FILTERED, {
4775
- priority: 100,
4776
- handler: (filtered, rowLocation, next) => {
4777
- if (filtered) return true;
4778
- const isTableFiltered = this._getTableFilteredOutRows(rowLocation.unitId, rowLocation.subUnitId).has(rowLocation.row);
4779
- return isTableFiltered ? true : next(isTableFiltered);
4780
- }
4781
- }));
4782
- }
4783
- _initFilteredOutRows() {
4784
- this.disposeWithMe(this._tableManager.tableInitStatus$.pipe(filter((initialized) => initialized), switchMap(() => {
4785
- return this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET);
4786
- }), filter((workbook) => workbook !== null && workbook !== void 0), switchMap((workbook) => workbook.activeSheet$), filter((sheet) => sheet !== null && sheet !== void 0)).subscribe(() => {
4787
- const target = getSheetCommandTarget(this._univerInstanceService);
4788
- if (!target) return;
4789
- const { unitId, subUnitId } = target;
4790
- this._refreshTableFilteredOutRows(unitId, subUnitId);
4791
- }));
4792
- }
4793
- registerFilterChangeEvent() {
4794
- this.disposeWithMe(this._tableManager.tableDelete$.subscribe(({ unitId, subUnitId }) => {
4795
- this._refreshTableFilteredOutRows(unitId, subUnitId);
4796
- this._zebraCrossingCacheController.updateZebraCrossingCache(unitId, subUnitId);
4797
- }));
4798
- this.disposeWithMe(this._tableManager.tableFilterChanged$.subscribe((event) => {
4799
- const { unitId, subUnitId, tableId, oldSubUnitId } = event;
4800
- const workbook = this._univerInstanceService.getUnit(unitId);
4801
- const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
4802
- const table = this._tableManager.getTable(unitId, tableId);
4803
- if (!worksheet || !table) return;
4804
- table.getTableFilters().doFilter(worksheet, table.getTableFilterRange(), workbook === null || workbook === void 0 ? void 0 : workbook.getDateSystem());
4805
- this._refreshTableFilteredOutRows(unitId, subUnitId);
4806
- this._zebraCrossingCacheController.updateZebraCrossingCache(unitId, subUnitId);
4807
- if (oldSubUnitId && oldSubUnitId !== subUnitId) {
4808
- this._refreshTableFilteredOutRows(unitId, oldSubUnitId);
4809
- this._zebraCrossingCacheController.updateZebraCrossingCache(unitId, oldSubUnitId);
4810
- }
4811
- }));
4812
- }
4813
- _refreshTableFilteredOutRows(unitId, subUnitId) {
4814
- const filteredOutRows = /* @__PURE__ */ new Set();
4815
- this._tableManager.getTablesBySubunitId(unitId, subUnitId).forEach((table) => {
4816
- const tableFilteredRows = table.getTableFilters().getFilterOutRows();
4817
- if (!tableFilteredRows) return;
4818
- for (const row of tableFilteredRows) filteredOutRows.add(row);
4819
- });
4820
- this._tableFilteredOutRows.set(this._getSheetKey(unitId, subUnitId), filteredOutRows);
4821
- }
4822
- _getTableFilteredOutRows(unitId, subUnitId) {
4823
- const key = this._getSheetKey(unitId, subUnitId);
4824
- if (!this._tableFilteredOutRows.has(key)) this._refreshTableFilteredOutRows(unitId, subUnitId);
4825
- return this._tableFilteredOutRows.get(key) ?? /* @__PURE__ */ new Set();
4826
- }
4827
- _getSheetKey(unitId, subUnitId) {
4828
- return `${unitId}|${subUnitId}`;
4829
- }
4830
- dispose() {
4831
- super.dispose();
4832
- this._tableFilteredOutRows.clear();
4833
- }
4834
- };
4835
- TableFilterController = __decorate([
4836
- __decorateParam(0, Inject(TableManager)),
4837
- __decorateParam(1, Inject(SheetInterceptorService)),
4838
- __decorateParam(2, Inject(IUniverInstanceService)),
4839
- __decorateParam(3, Inject(ISheetRowFilteredService)),
4840
- __decorateParam(4, Inject(ZebraCrossingCacheController))
4841
- ], TableFilterController);
4842
-
4843
- //#endregion
4844
- //#region src/plugin.ts
4845
- let UniverSheetsTablePlugin = class UniverSheetsTablePlugin extends Plugin {
4846
- constructor(_config = defaultPluginConfig, _injector, _configService, _commandService) {
4847
- super();
4848
- this._config = _config;
4849
- this._injector = _injector;
4850
- this._configService = _configService;
4851
- this._commandService = _commandService;
4852
- const { ...rest } = merge({}, defaultPluginConfig, this._config);
4853
- this._configService.setConfig(SHEETS_TABLE_PLUGIN_CONFIG_KEY, rest);
4854
- this._initRegisterCommand();
4855
- }
4856
- onStarting() {
4857
- registerDependencies(this._injector, [
4858
- [TableManager],
4859
- [SheetsTableThemeController],
4860
- [SheetsTableController],
4861
- [SheetTableService],
4862
- [TableFilterController],
4863
- [SheetTableRangeController],
4864
- [SheetTableRefRangeController],
4865
- [SheetTableMoveController],
4866
- [SheetTableFormulaController]
4867
- ]);
4868
- }
4869
- onReady() {
4870
- touchDependencies(this._injector, [
4871
- [SheetTableFormulaController],
4872
- [SheetTableRangeController],
4873
- [SheetTableRefRangeController],
4874
- [SheetTableMoveController],
4875
- [SheetsTableThemeController],
4876
- [SheetsTableController],
4877
- [SheetTableService],
4878
- [TableFilterController]
4879
- ]);
4880
- touchDependencies(this._injector, [[TableManager]]);
4881
- }
4882
- _initRegisterCommand() {
4883
- [
4884
- AddSheetTableCommand,
4885
- AddSheetTableMutation,
4886
- DeleteSheetTableCommand,
4887
- DeleteSheetTableMutation,
4888
- MoveSheetTableMutation,
4889
- SetSheetTableFilterMutation,
4890
- SetSheetTableFilterCommand,
4891
- SetSheetTableSortStateCommand,
4892
- SetSheetTableCommand,
4893
- SetSheetTableMutation,
4894
- AddTableThemeCommand,
4895
- RemoveTableThemeCommand,
4896
- SheetTableInsertRowCommand,
4897
- SheetTableInsertColCommand,
4898
- SheetTableInsertRowAtCommand,
4899
- SheetTableInsertColumnAtCommand,
4900
- SheetTableRemoveRowCommand,
4901
- SheetTableRemoveColCommand,
4902
- SheetTableRemoveColumnAtCommand
4903
- ].forEach((m) => this._commandService.registerCommand(m));
4904
- }
4905
- };
4906
- _defineProperty(UniverSheetsTablePlugin, "pluginName", PLUGIN_NAME);
4907
- _defineProperty(UniverSheetsTablePlugin, "packageName", name);
4908
- _defineProperty(UniverSheetsTablePlugin, "version", version);
4909
- _defineProperty(UniverSheetsTablePlugin, "type", UniverInstanceType.UNIVER_SHEET);
4910
- UniverSheetsTablePlugin = __decorate([
4911
- DependentOn(UniverSheetsPlugin),
4912
- __decorateParam(1, Inject(Injector)),
4913
- __decorateParam(2, IConfigService),
4914
- __decorateParam(3, Inject(ICommandService))
4915
- ], UniverSheetsTablePlugin);
4916
-
4917
- //#endregion
4918
3
  export { AddSheetTableCommand, AddSheetTableMutation, AddTableThemeCommand, DeleteSheetTableCommand, DeleteSheetTableMutation, RemoveTableThemeCommand, SHEET_TABLE_CUSTOM_THEME_PREFIX, SetSheetTableCommand, SetSheetTableFilterCommand, SetSheetTableFilterMutation, SetSheetTableMutation, SetSheetTableSortStateCommand, SheetTableInsertColCommand, SheetTableInsertColumnAtCommand, SheetTableInsertRowAtCommand, SheetTableInsertRowCommand, SheetTableRemoveColCommand, SheetTableRemoveColumnAtCommand, SheetTableRemoveRowCommand, SheetTableService, SheetsTableButtonStateEnum, SheetsTableController, SheetsTableSortStateEnum, SheetsTableThemeController, TABLE_FILTER_EMPTY_VALUE, TableColumnDataTypeEnum, TableColumnFilterTypeEnum, TableConditionTypeEnum, TableDateCompareTypeEnum, TableManager, TableNumberCompareTypeEnum, TableStringCompareTypeEnum, UniverSheetsTablePlugin, compileTableRecordFilter, customEmptyThemeWithBorderStyle, getExistingNamesSet, getTableRecordValue, isColorTableFilter, isConditionFilter, isManualTableFilter, isRecordTableFilter, processStyleWithBorderStyle, validateSheetTableName };