@univerjs/sheets-filter 0.4.1 → 0.4.2-nightly.202410301606

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/es/index.js CHANGED
@@ -2,530 +2,18 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { CommandType, isNumeric, Disposable, Rectangle, mergeSets, Tools, extractPureTextFromCell, CellValueType, UniverInstanceType, fromCallback, IResourceManagerService, IUniverInstanceService, ICommandService, Inject, DisposableCollection, moveMatrixArray, Plugin, Injector, IConfigService } from "@univerjs/core";
6
- import { BehaviorSubject, merge, filter, switchMap, of } from "rxjs";
5
+ import { Inject, Disposable, DisposableCollection, moveMatrixArray, Rectangle, ICommandService, IUniverInstanceService, Plugin, UniverInstanceType, Injector, IConfigService } from "@univerjs/core";
6
+ import { S as SetSheetsFilterCriteriaMutation, a as SheetsFilterService, b as SetSheetsFilterRangeMutation, R as ReCalcSheetsFilterMutation, c as RemoveSheetsFilterMutation, d as SHEET_FILTER_SNAPSHOT_ID } from "../sheets-filter.command-CL_iGKJ6.mjs";
7
+ import { m, C, k, F, e, o, p, q, r, s, f, g, h, i, l, j, n } from "../sheets-filter.command-CL_iGKJ6.mjs";
7
8
  import { SheetInterceptorService, RefRangeService, SetWorksheetActiveOperation, CopySheetCommand, RemoveSheetCommand, INTERCEPTOR_POINT, RemoveRowMutation, InsertRowMutation, SetRangeValuesMutation, expandToContinuousRange, getSheetCommandTarget, MoveRowsCommand, MoveRangeCommand, EffectRefRangId, RemoveRowCommand, RemoveColCommand, InsertColCommand, InsertRowCommand } from "@univerjs/sheets";
8
- const SetSheetsFilterRangeMutation = {
9
- id: "sheet.mutation.set-filter-range",
10
- type: CommandType.MUTATION,
11
- handler: /* @__PURE__ */ __name((accessor, params) => {
12
- const { subUnitId, unitId, range } = params;
13
- return accessor.get(SheetsFilterService).ensureFilterModel(unitId, subUnitId).setRange(range), !0;
14
- }, "handler")
15
- }, SetSheetsFilterCriteriaMutation = {
16
- id: "sheet.mutation.set-filter-criteria",
17
- type: CommandType.MUTATION,
18
- handler: /* @__PURE__ */ __name((accessor, params) => {
19
- const { subUnitId, unitId, criteria, col, reCalc = !0 } = params, filterModel = accessor.get(SheetsFilterService).getFilterModel(unitId, subUnitId);
20
- return filterModel ? (filterModel.setCriteria(col, criteria, reCalc), !0) : !1;
21
- }, "handler")
22
- }, RemoveSheetsFilterMutation = {
23
- id: "sheet.mutation.remove-filter",
24
- type: CommandType.MUTATION,
25
- handler: /* @__PURE__ */ __name((accessor, params) => {
26
- const { unitId, subUnitId } = params;
27
- return accessor.get(SheetsFilterService).removeFilterModel(unitId, subUnitId);
28
- }, "handler")
29
- }, ReCalcSheetsFilterMutation = {
30
- id: "sheet.mutation.re-calc-filter",
31
- type: CommandType.MUTATION,
32
- handler: /* @__PURE__ */ __name((accessor, params) => {
33
- const { unitId, subUnitId } = params, filterModel = accessor.get(SheetsFilterService).getFilterModel(unitId, subUnitId);
34
- return filterModel ? (filterModel.reCalc(), !0) : !1;
35
- }, "handler")
36
- };
37
- var CustomFilterOperator = /* @__PURE__ */ ((CustomFilterOperator2) => (CustomFilterOperator2.EQUAL = "equal", CustomFilterOperator2.GREATER_THAN = "greaterThan", CustomFilterOperator2.GREATER_THAN_OR_EQUAL = "greaterThanOrEqual", CustomFilterOperator2.LESS_THAN = "lessThan", CustomFilterOperator2.LESS_THAN_OR_EQUAL = "lessThanOrEqual", CustomFilterOperator2.NOT_EQUALS = "notEqual", CustomFilterOperator2))(CustomFilterOperator || {});
38
- const greaterThan = {
39
- operator: CustomFilterOperator.GREATER_THAN,
40
- fn: /* @__PURE__ */ __name((value, compare) => ensureNumber(value) ? value > compare : !1, "fn")
41
- }, greaterThanOrEqualTo = {
42
- operator: CustomFilterOperator.GREATER_THAN_OR_EQUAL,
43
- fn: /* @__PURE__ */ __name((value, compare) => ensureNumber(value) ? value >= compare : !1, "fn")
44
- }, lessThan = {
45
- operator: CustomFilterOperator.LESS_THAN,
46
- fn: /* @__PURE__ */ __name((value, compare) => ensureNumber(value) ? value < compare : !1, "fn")
47
- }, lessThanOrEqualTo = {
48
- operator: CustomFilterOperator.LESS_THAN_OR_EQUAL,
49
- fn: /* @__PURE__ */ __name((value, compare) => ensureNumber(value) ? value <= compare : !1, "fn")
50
- }, equals = {
51
- operator: CustomFilterOperator.EQUAL,
52
- fn: /* @__PURE__ */ __name((value, compare) => ensureNumber(value) ? value === compare : !1, "fn")
53
- }, notEquals = {
54
- operator: CustomFilterOperator.NOT_EQUALS,
55
- fn: /* @__PURE__ */ __name((value, compare) => {
56
- if (typeof compare == "string") {
57
- if (compare === " ")
58
- return value != null;
59
- const ensuredString = ensureString(value);
60
- return ensuredString && isWildCardString(compare) ? !createREGEXFromWildChar(compare).test(ensuredString) : ensuredString !== compare;
61
- }
62
- return ensureNumber(value) ? value !== compare : !0;
63
- }, "fn")
64
- }, CustomFilterFnRegistry = /* @__PURE__ */ new Map([]), ALL_CUSTOM_FILTER_FUNCTIONS = [greaterThan, greaterThanOrEqualTo, lessThan, lessThanOrEqualTo, equals, notEquals];
65
- ALL_CUSTOM_FILTER_FUNCTIONS.forEach((fn) => {
66
- CustomFilterFnRegistry.set(fn.operator, fn);
67
- });
68
- function isNumericFilterFn(operator) {
69
- return !!operator;
70
- }
71
- __name(isNumericFilterFn, "isNumericFilterFn");
72
- const textMatch = {
73
- fn: /* @__PURE__ */ __name((value, compare) => {
74
- const ensured = ensureString(value);
75
- return ensured === null ? compare === "" : createREGEXFromWildChar(compare).test(ensured);
76
- }, "fn")
77
- };
78
- function getCustomFilterFn(operator) {
79
- return operator ? CustomFilterFnRegistry.get(operator) : textMatch;
80
- }
81
- __name(getCustomFilterFn, "getCustomFilterFn");
82
- function ensureNumber(value) {
83
- return typeof value == "number";
84
- }
85
- __name(ensureNumber, "ensureNumber");
86
- function ensureNumeric(value) {
87
- return !!(typeof value == "number" || typeof value == "string" && isNumeric(value));
88
- }
89
- __name(ensureNumeric, "ensureNumeric");
90
- function ensureString(value) {
91
- return typeof value == "boolean" || value == null ? null : typeof value == "string" ? value : value.toString();
92
- }
93
- __name(ensureString, "ensureString");
94
- function isWildCardString(str) {
95
- return typeof str == "number" ? !1 : str.indexOf("*") !== -1 || str.indexOf("?") !== -1;
96
- }
97
- __name(isWildCardString, "isWildCardString");
98
- function createREGEXFromWildChar(wildChar) {
99
- const regexpStr = wildChar.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("?", ".").replace(/[*]/g, ".$&");
100
- return new RegExp(`^${regexpStr}$`);
101
- }
102
- __name(createREGEXFromWildChar, "createREGEXFromWildChar");
103
- const EMPTY = /* @__PURE__ */ __name(() => /* @__PURE__ */ new Set(), "EMPTY"), _FilterModel = class _FilterModel extends Disposable {
104
- constructor(unitId, subUnitId, _worksheet) {
105
- super();
106
- __publicField(this, "_filteredOutRows$", new BehaviorSubject(EMPTY()));
107
- /** An observable value. A set of filtered out rows. */
108
- __publicField(this, "filteredOutRows$", this._filteredOutRows$.asObservable());
109
- // TODO: we may need to update which cols have criteria rather than simple boolean
110
- __publicField(this, "_hasCriteria$", new BehaviorSubject(!1));
111
- __publicField(this, "hasCriteria$", this._hasCriteria$.asObservable());
112
- __publicField(this, "_filterColumnByIndex", /* @__PURE__ */ new Map());
113
- __publicField(this, "_alreadyFilteredOutRows", EMPTY());
114
- __publicField(this, "_range");
115
- this.unitId = unitId, this.subUnitId = subUnitId, this._worksheet = _worksheet;
116
- }
117
- get filteredOutRows() {
118
- return this._filteredOutRows$.getValue();
119
- }
120
- set filteredOutRows(rows) {
121
- this._alreadyFilteredOutRows = rows, this._filteredOutRows$.next(rows);
122
- }
123
- dispose() {
124
- super.dispose(), this._filteredOutRows$.complete(), this._hasCriteria$.complete();
125
- }
126
- /**
127
- * Serialize this filter model to the JSON format representation.
128
- */
129
- serialize() {
130
- const result = {
131
- ref: Rectangle.clone(this._range),
132
- filterColumns: this._getAllFilterColumns(!0).sort(([offset1], [offset2]) => offset1 - offset2).map(([_, filterColumn]) => filterColumn.serialize())
133
- };
134
- return this._alreadyFilteredOutRows && (result.cachedFilteredOut = Array.from(this._alreadyFilteredOutRows).sort()), result;
135
- }
136
- /**
137
- * Deserialize auto filter info to construct a `FilterModel` object.
138
- * @param unitId workbook id
139
- * @param subUnitId worksheet id
140
- * @param worksheet the Worksheet object
141
- * @param autoFilter auto filter data
142
- */
143
- static deserialize(unitId, subUnitId, worksheet, autoFilter) {
144
- const filterModel = new _FilterModel(unitId, subUnitId, worksheet);
145
- return filterModel._dump(autoFilter), filterModel;
146
- }
147
- _dump(autoFilter) {
148
- var _a4;
149
- this.setRange(autoFilter.ref), (_a4 = autoFilter.filterColumns) == null || _a4.forEach((filterColumn) => this._setCriteriaWithoutReCalc(filterColumn.colId, filterColumn)), autoFilter.cachedFilteredOut && (this._alreadyFilteredOutRows = new Set(autoFilter.cachedFilteredOut), this._emit()), this._emitHasCriteria();
150
- }
151
- isRowFiltered(row) {
152
- return this._alreadyFilteredOutRows.has(row);
153
- }
154
- getRange() {
155
- if (!this._range)
156
- throw new Error("[FilterModel] could not get range before a range is set!");
157
- return this._range;
158
- }
159
- /**
160
- * Get filtered out rows except the specific column. This method is considered as "pure". In
161
- * another word it would not change `filteredOutRows` on `FilterModel` nor `FilterColumn`.
162
- * @param col
163
- */
164
- getFilteredOutRowsExceptCol(col) {
165
- return this._getAllFilterColumns(!0).filter(([colOffset]) => colOffset !== col).reduce((acc, [, filterColumn]) => {
166
- const newResult = filterColumn.calc({ getAlreadyFilteredOutRows: /* @__PURE__ */ __name(() => acc, "getAlreadyFilteredOutRows") });
167
- return newResult ? mergeSets(acc, newResult) : acc;
168
- }, /* @__PURE__ */ new Set());
169
- }
170
- /**
171
- * Set range of the filter model, this would remove some `IFilterColumn`
172
- * if the new range not overlaps the old range.
173
- */
174
- setRange(range) {
175
- this._range = range, this._getAllFilterColumns(!0).forEach(([col, filterColumn]) => {
176
- filterColumn.setRangeAndColumn({
177
- startRow: range.startRow,
178
- endRow: range.endRow,
179
- startColumn: col,
180
- endColumn: col
181
- }, col);
182
- });
183
- }
184
- /**
185
- * Set or remove filter criteria on a specific row.
186
- */
187
- setCriteria(col, criteria, reCalc = !1) {
188
- if (!this._range)
189
- throw new Error("[FilterModel] could not set criteria before a range is set!");
190
- if (!criteria) {
191
- this._removeCriteria(col), this._rebuildAlreadyFilteredOutRowsWithCache(), reCalc && this._reCalcAllColumns(), this._emit(), this._emitHasCriteria();
192
- return;
193
- }
194
- this._setCriteriaWithoutReCalc(col, criteria), reCalc && (this._rebuildAlreadyFilteredOutRowsWithCache(), this._reCalcWithNoCacheColumns(), this._emit(), this._emitHasCriteria());
195
- }
196
- getAllFilterColumns() {
197
- return this._getAllFilterColumns(!0);
198
- }
199
- getFilterColumn(index) {
200
- var _a4;
201
- return (_a4 = this._filterColumnByIndex.get(index)) != null ? _a4 : null;
202
- }
203
- reCalc() {
204
- this._reCalcAllColumns(), this._emit();
205
- }
206
- _getAllFilterColumns(withCol = !1) {
207
- const columns = Array.from(this._filterColumnByIndex.entries());
208
- return withCol ? columns : columns.map(([_, filterColumn]) => filterColumn);
209
- }
210
- _reCalcAllColumns() {
211
- this._alreadyFilteredOutRows = EMPTY(), this._getAllFilterColumns().forEach((filterColumn) => filterColumn.__clearCache()), this._reCalcWithNoCacheColumns();
212
- }
213
- _setCriteriaWithoutReCalc(col, criteria) {
214
- const range = this._range;
215
- if (!range)
216
- throw new Error("[FilterModel] could not set criteria before a range is set!");
217
- const { startColumn, endColumn } = range;
218
- if (col > endColumn || col < startColumn)
219
- throw new Error(`[FilterModel] could not set criteria on column ${col} which is out of range!`);
220
- let filterColumn;
221
- this._filterColumnByIndex.has(col) ? filterColumn = this._filterColumnByIndex.get(col) : (filterColumn = new FilterColumn(
222
- this.unitId,
223
- this.subUnitId,
224
- this._worksheet,
225
- criteria,
226
- { getAlreadyFilteredOutRows: /* @__PURE__ */ __name(() => this._alreadyFilteredOutRows, "getAlreadyFilteredOutRows") }
227
- ), filterColumn.setRangeAndColumn(range, col), this._filterColumnByIndex.set(col, filterColumn)), filterColumn.setCriteria(criteria);
228
- }
229
- _removeCriteria(col) {
230
- const filterColumn = this._filterColumnByIndex.get(col);
231
- filterColumn && (filterColumn.dispose(), this._filterColumnByIndex.delete(col));
232
- }
233
- _emit() {
234
- this._filteredOutRows$.next(this._alreadyFilteredOutRows);
235
- }
236
- _emitHasCriteria() {
237
- this._hasCriteria$.next(this._filterColumnByIndex.size > 0);
238
- }
239
- _rebuildAlreadyFilteredOutRowsWithCache() {
240
- const newFilteredOutRows = this._getAllFilterColumns().filter((filterColumn) => filterColumn.hasCache()).reduce((acc, filterColumn) => mergeSets(acc, filterColumn.filteredOutRows), /* @__PURE__ */ new Set());
241
- this._alreadyFilteredOutRows = newFilteredOutRows;
242
- }
243
- _reCalcWithNoCacheColumns() {
244
- const noCacheFilteredOutRows = this._getAllFilterColumns().filter((filterColumn) => !filterColumn.hasCache());
245
- for (const filterColumn of noCacheFilteredOutRows) {
246
- const filteredRows = filterColumn.reCalc();
247
- filteredRows && (this._alreadyFilteredOutRows = mergeSets(this._alreadyFilteredOutRows, filteredRows));
248
- }
249
- }
250
- };
251
- __name(_FilterModel, "FilterModel");
252
- let FilterModel = _FilterModel;
253
- const _FilterColumn = class _FilterColumn extends Disposable {
254
- constructor(unitId, subUnitId, _worksheet, _criteria, _filterColumnContext) {
255
- super();
256
- __publicField(this, "_filteredOutRows", null);
257
- /** Cache the filter function. */
258
- __publicField(this, "_filterFn", null);
259
- __publicField(this, "_range", null);
260
- __publicField(this, "_column", 0);
261
- __publicField(this, "_filterByValues", !1);
262
- this.unitId = unitId, this.subUnitId = subUnitId, this._worksheet = _worksheet, this._criteria = _criteria, this._filterColumnContext = _filterColumnContext;
263
- }
264
- get filteredOutRows() {
265
- return this._filteredOutRows;
266
- }
267
- dispose() {
268
- super.dispose(), this._filteredOutRows = null;
269
- }
270
- /**
271
- * @internal
272
- */
273
- __clearCache() {
274
- this._filteredOutRows = null;
275
- }
276
- serialize() {
277
- if (!this._criteria)
278
- throw new Error("[FilterColumn]: could not serialize without a filter column!");
279
- return Tools.deepClone({
280
- ...this._criteria,
281
- colId: this._column
282
- });
283
- }
284
- hasCache() {
285
- return this._filteredOutRows !== null;
286
- }
287
- // The first row should be omitted!
288
- setRangeAndColumn(range, column) {
289
- this._range = range, this._column = column;
290
- }
291
- setCriteria(criteria) {
292
- this._criteria = criteria, this._generateFilterFn(), this._filteredOutRows = null;
293
- }
294
- getColumnData() {
295
- return Tools.deepClone(this._criteria);
296
- }
297
- /**
298
- * Trigger new calculation on this `FilterModel` instance.
299
- *
300
- * @external DO NOT EVER call this method from `FilterColumn` itself. The whole process heavily relies on
301
- * `filteredOutByOthers`, and it is more comprehensible if we let `FilterModel` take full control over the process.
302
- */
303
- reCalc() {
304
- return this._filteredOutRows = this.calc(this._filterColumnContext), this._filteredOutRows;
305
- }
306
- calc(context) {
307
- if (!this._filterFn)
308
- throw new Error("[FilterColumn] cannot calculate without a filter fn!");
309
- if (!this._range)
310
- throw new Error("[FilterColumn] cannot calculate without a range!");
311
- if (typeof this._column != "number")
312
- throw new TypeError("[FilterColumn] cannot calculate without a column offset!");
313
- const column = this._column, iterateRange = { startColumn: column, endColumn: column, startRow: this._range.startRow + 1, endRow: this._range.endRow }, filteredOutRows = /* @__PURE__ */ new Set(), filteredOutByOthers = context.getAlreadyFilteredOutRows();
314
- for (const range of this._worksheet.iterateByColumn(iterateRange, !1, !1)) {
315
- const { row, rowSpan, col } = range;
316
- if (filteredOutByOthers.has(row) && (!rowSpan || rowSpan === 1))
317
- continue;
318
- const value = this._filterByValues ? extractPureTextFromCell(this._worksheet.getCell(row, col)) : getFilterValueForConditionalFiltering(this._worksheet, row, col);
319
- if (!this._filterFn(value) && (filteredOutRows.add(row), rowSpan))
320
- for (let i = 1; i < rowSpan; i++)
321
- filteredOutRows.add(row + i);
322
- }
323
- return filteredOutRows;
324
- }
325
- _generateFilterFn() {
326
- this._criteria && (this._filterFn = generateFilterFn(this._criteria), this._filterByValues = !!this._criteria.filters);
327
- }
328
- };
329
- __name(_FilterColumn, "FilterColumn");
330
- let FilterColumn = _FilterColumn;
331
- function generateFilterFn(column) {
332
- if (column.filters)
333
- return filterByValuesFnFactory(column.filters);
334
- if (column.customFilters)
335
- return customFilterFnFactory(column.customFilters);
336
- throw new Error("[FilterModel]: other types of filters are not supported yet.");
337
- }
338
- __name(generateFilterFn, "generateFilterFn");
339
- function filterByValuesFnFactory(values) {
340
- const includeBlank = !!values.blank, valuesSet = new Set(values.filters);
341
- return (value) => value === void 0 || value === "" ? includeBlank : valuesSet.has(typeof value == "string" ? value : `${value}`);
342
- }
343
- __name(filterByValuesFnFactory, "filterByValuesFnFactory");
344
- function customFilterFnFactory(customFilters) {
345
- const customFilterFns = customFilters.customFilters.map((filter2) => generateCustomFilterFn(filter2));
346
- return isCompoundCustomFilter(customFilterFns) ? customFilters.and ? AND(customFilterFns) : OR(customFilterFns) : customFilterFns[0];
347
- }
348
- __name(customFilterFnFactory, "customFilterFnFactory");
349
- function AND(filterFns) {
350
- const [fn1, fn2] = filterFns;
351
- return (value) => fn1(value) && fn2(value);
352
- }
353
- __name(AND, "AND");
354
- function OR(filterFns) {
355
- const [fn1, fn2] = filterFns;
356
- return (value) => fn1(value) || fn2(value);
357
- }
358
- __name(OR, "OR");
359
- function isCompoundCustomFilter(filter2) {
360
- return filter2.length === 2;
361
- }
362
- __name(isCompoundCustomFilter, "isCompoundCustomFilter");
363
- function generateCustomFilterFn(filter2) {
364
- const compare = filter2.val;
365
- if (filter2.operator === CustomFilterOperator.NOT_EQUALS && !ensureNumeric(compare))
366
- return (value) => notEquals.fn(value, compare);
367
- if (isNumericFilterFn(filter2.operator)) {
368
- if (!ensureNumeric(compare)) return () => !1;
369
- const customFilterFn2 = getCustomFilterFn(filter2.operator), ensuredNumber = Number(compare);
370
- return (value) => customFilterFn2.fn(value, ensuredNumber);
371
- }
372
- const customFilterFn = getCustomFilterFn(filter2.operator);
373
- return (value) => customFilterFn.fn(value, compare);
374
- }
375
- __name(generateCustomFilterFn, "generateCustomFilterFn");
376
- function getFilterValueForConditionalFiltering(worksheet, row, col) {
377
- const interceptedCell = worksheet.getCell(row, col);
378
- if (!interceptedCell) return null;
379
- const rawCell = worksheet.getCellRaw(row, col);
380
- return interceptedCell && !rawCell ? extractFilterValueFromCell(interceptedCell) : rawCell ? interceptedCell.t === CellValueType.NUMBER && typeof interceptedCell.v == "string" ? rawCell.v : extractFilterValueFromCell(rawCell) : null;
381
- }
382
- __name(getFilterValueForConditionalFiltering, "getFilterValueForConditionalFiltering");
383
- function extractFilterValueFromCell(cell) {
384
- var _a4, _b;
385
- const richTextValue = (_b = (_a4 = cell.p) == null ? void 0 : _a4.body) == null ? void 0 : _b.dataStream;
386
- if (richTextValue) return richTextValue.trimEnd();
387
- const rawValue = cell.v;
388
- return typeof rawValue == "string" ? cell.t === CellValueType.BOOLEAN ? rawValue.toUpperCase() : rawValue : typeof rawValue == "number" ? cell.t === CellValueType.BOOLEAN ? rawValue ? "TRUE" : "FALSE" : rawValue : typeof rawValue == "boolean" ? rawValue ? "TRUE" : "FALSE" : "";
389
- }
390
- __name(extractFilterValueFromCell, "extractFilterValueFromCell");
391
- var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
392
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
393
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
394
- return kind && result && __defProp$2(target, key, result), result;
395
- }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2");
396
- const FILTER_MUTATIONS = /* @__PURE__ */ new Set([
397
- SetSheetsFilterRangeMutation.id,
398
- SetSheetsFilterCriteriaMutation.id,
399
- RemoveSheetsFilterMutation.id,
400
- ReCalcSheetsFilterMutation.id
401
- ]), SHEET_FILTER_SNAPSHOT_ID = "SHEET_FILTER_PLUGIN";
402
- var _a;
403
- let SheetsFilterService = (_a = class extends Disposable {
404
- constructor(_resourcesManagerService, _univerInstanceService, _commandService) {
405
- super();
406
- __publicField(this, "_filterModels", /* @__PURE__ */ new Map());
407
- __publicField(this, "_loadedUnitId$", new BehaviorSubject(null));
408
- __publicField(this, "loadedUnitId$", this._loadedUnitId$.asObservable());
409
- __publicField(this, "_errorMsg$", new BehaviorSubject(null));
410
- __publicField(this, "errorMsg$", this._errorMsg$.asObservable());
411
- __publicField(this, "_activeFilterModel$", new BehaviorSubject(null));
412
- /** An observable value emitting the current Workbook's active Worksheet's filter model (if there is one). */
413
- __publicField(this, "activeFilterModel$", this._activeFilterModel$.asObservable());
414
- this._resourcesManagerService = _resourcesManagerService, this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this._initModel(), this._initActiveFilterModel();
415
- }
416
- /** The current Workbook's active Worksheet's filter model (if there is one). */
417
- get activeFilterModel() {
418
- return this._activeFilterModel$.getValue();
419
- }
420
- /**
421
- *
422
- * @param unitId
423
- * @param subUnitId
424
- */
425
- ensureFilterModel(unitId, subUnitId) {
426
- const already = this.getFilterModel(unitId, subUnitId);
427
- if (already)
428
- return already;
429
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
430
- if (!workbook)
431
- throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${unitId}!`);
432
- const worksheet = workbook.getSheetBySheetId(subUnitId);
433
- if (!worksheet)
434
- throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${subUnitId}!`);
435
- const filterModel = new FilterModel(unitId, subUnitId, worksheet);
436
- return this._cacheFilterModel(unitId, subUnitId, filterModel), filterModel;
437
- }
438
- getFilterModel(unitId, subUnitId) {
439
- var _a4, _b;
440
- return (_b = (_a4 = this._filterModels.get(unitId)) == null ? void 0 : _a4.get(subUnitId)) != null ? _b : null;
441
- }
442
- removeFilterModel(unitId, subUnitId) {
443
- const already = this.getFilterModel(unitId, subUnitId);
444
- return already ? (already.dispose(), this._filterModels.get(unitId).delete(subUnitId), !0) : !1;
445
- }
446
- setFilterErrorMsg(content) {
447
- this._errorMsg$.next(content);
448
- }
449
- _updateActiveFilterModel() {
450
- let workbook;
451
- try {
452
- if (workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), !workbook) {
453
- this._activeFilterModel$.next(null);
454
- return;
455
- }
456
- } catch (err) {
457
- console.error("[SheetsFilterService]: could not get active workbook!", err);
458
- return;
459
- }
460
- const activeSheet = workbook.getActiveSheet(!0);
461
- if (!activeSheet) {
462
- this._activeFilterModel$.next(null);
463
- return;
464
- }
465
- const unitId = activeSheet.getUnitId(), subUnitId = activeSheet.getSheetId(), filterModel = this.getFilterModel(unitId, subUnitId);
466
- this._activeFilterModel$.next(filterModel);
467
- }
468
- _initActiveFilterModel() {
469
- this.disposeWithMe(
470
- merge(
471
- // source1: executing filter related mutations
472
- fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(filter(([command]) => command.type === CommandType.MUTATION && FILTER_MUTATIONS.has(command.id))),
473
- // source2: activate sheet changes
474
- this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(switchMap((workbook) => {
475
- var _a4;
476
- return (_a4 = workbook == null ? void 0 : workbook.activeSheet$) != null ? _a4 : of(null);
477
- }))
478
- ).subscribe(() => this._updateActiveFilterModel())
479
- );
480
- }
481
- _serializeAutoFiltersForUnit(unitId) {
482
- const allFilterModels = this._filterModels.get(unitId);
483
- if (!allFilterModels)
484
- return "{}";
485
- const json = {};
486
- return allFilterModels.forEach((model, worksheetId) => {
487
- json[worksheetId] = model.serialize();
488
- }), JSON.stringify(json);
489
- }
490
- _deserializeAutoFiltersForUnit(unitId, json) {
491
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
492
- Object.keys(json).forEach((worksheetId) => {
493
- const autoFilter = json[worksheetId], filterModel = FilterModel.deserialize(unitId, worksheetId, workbook.getSheetBySheetId(worksheetId), autoFilter);
494
- this._cacheFilterModel(unitId, worksheetId, filterModel);
495
- });
496
- }
497
- _initModel() {
498
- this._resourcesManagerService.registerPluginResource({
499
- pluginName: SHEET_FILTER_SNAPSHOT_ID,
500
- businesses: [UniverInstanceType.UNIVER_SHEET],
501
- toJson: /* @__PURE__ */ __name((id) => this._serializeAutoFiltersForUnit(id), "toJson"),
502
- parseJson: /* @__PURE__ */ __name((json) => JSON.parse(json), "parseJson"),
503
- onLoad: /* @__PURE__ */ __name((unitId, value) => {
504
- this._deserializeAutoFiltersForUnit(unitId, value), this._loadedUnitId$.next(unitId), this._updateActiveFilterModel();
505
- }, "onLoad"),
506
- onUnLoad: /* @__PURE__ */ __name((unitId) => {
507
- const allFilterModels = this._filterModels.get(unitId);
508
- allFilterModels && (allFilterModels.forEach((model) => model.dispose()), this._filterModels.delete(unitId));
509
- }, "onUnLoad")
510
- });
511
- }
512
- _cacheFilterModel(unitId, subUnitId, filterModel) {
513
- this._filterModels.has(unitId) || this._filterModels.set(unitId, /* @__PURE__ */ new Map()), this._filterModels.get(unitId).set(subUnitId, filterModel);
514
- }
515
- }, __name(_a, "SheetsFilterService"), _a);
516
- SheetsFilterService = __decorateClass$2([
517
- __decorateParam$2(0, IResourceManagerService),
518
- __decorateParam$2(1, IUniverInstanceService),
519
- __decorateParam$2(2, ICommandService)
520
- ], SheetsFilterService);
521
9
  function objectsShaker(target, isEqual) {
522
- for (let i = 0; i < target.length; i++) {
523
- let cur = i;
524
- if (target[i])
525
- for (let j = i + 1; j < target.length; j++)
526
- target[cur] && target[j] && isEqual(target[cur], target[j]) && (target[cur] = null, cur = j);
10
+ for (let i2 = 0; i2 < target.length; i2++) {
11
+ let cur = i2;
12
+ if (target[i2])
13
+ for (let j2 = i2 + 1; j2 < target.length; j2++)
14
+ target[cur] && target[j2] && isEqual(target[cur], target[j2]) && (target[cur] = null, cur = j2);
527
15
  }
528
- return target.filter((o) => o !== null);
16
+ return target.filter((o2) => o2 !== null);
529
17
  }
530
18
  __name(objectsShaker, "objectsShaker");
531
19
  function mergeSetFilterCriteria(mutations) {
@@ -533,11 +21,11 @@ function mergeSetFilterCriteria(mutations) {
533
21
  }
534
22
  __name(mergeSetFilterCriteria, "mergeSetFilterCriteria");
535
23
  var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
536
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
537
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
24
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
25
+ (decorator = decorators[i2]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
538
26
  return kind && result && __defProp$1(target, key, result), result;
539
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a2;
540
- let SheetsFilterController = (_a2 = class extends Disposable {
27
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a;
28
+ let SheetsFilterController = (_a = class extends Disposable {
541
29
  constructor(_commandService, _sheetInterceptorService, _sheetsFilterService, _univerInstanceService, _refRangeService) {
542
30
  super();
543
31
  __publicField(this, "_disposableCollection", new DisposableCollection());
@@ -575,11 +63,11 @@ let SheetsFilterController = (_a2 = class extends Disposable {
575
63
  }));
576
64
  }
577
65
  _registerRefRange(unitId, subUnitId) {
578
- var _a4;
66
+ var _a3;
579
67
  this._disposableCollection.dispose();
580
68
  const workbook = this._univerInstanceService.getUniverSheetInstance(unitId), workSheet = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId);
581
69
  if (!workbook || !workSheet) return;
582
- const range = (_a4 = this._sheetsFilterService.getFilterModel(unitId, subUnitId)) == null ? void 0 : _a4.getRange(), handler = /* @__PURE__ */ __name((config) => {
70
+ const range = (_a3 = this._sheetsFilterService.getFilterModel(unitId, subUnitId)) == null ? void 0 : _a3.getRange(), handler = /* @__PURE__ */ __name((config) => {
583
71
  switch (config.id) {
584
72
  case InsertRowCommand.id: {
585
73
  const params = config.params, _unitId = params.unitId || unitId, _subUnitId = params.subUnitId || subUnitId;
@@ -632,8 +120,8 @@ let SheetsFilterController = (_a2 = class extends Disposable {
632
120
  };
633
121
  }
634
122
  _handleInsertColCommand(config, unitId, subUnitId) {
635
- var _a4;
636
- const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a4 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a4 : null;
123
+ var _a3;
124
+ const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a3 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a3 : null;
637
125
  if (!filterModel || !filterRange)
638
126
  return this._handleNull();
639
127
  const { startColumn, endColumn } = filterRange, { startColumn: insertStartColumn, endColumn: insertEndColumn } = config.range, count = insertEndColumn - insertStartColumn + 1;
@@ -661,8 +149,8 @@ let SheetsFilterController = (_a2 = class extends Disposable {
661
149
  return { redos: mergeSetFilterCriteria(redos), undos: mergeSetFilterCriteria(undos) };
662
150
  }
663
151
  _handleInsertRowCommand(config, unitId, subUnitId) {
664
- var _a4;
665
- const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a4 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a4 : null;
152
+ var _a3;
153
+ const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a3 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a3 : null;
666
154
  if (!filterModel || !filterRange)
667
155
  return this._handleNull();
668
156
  const { startRow, endRow } = filterRange, { startRow: insertStartRow, endRow: insertEndRow } = config.range, rowCount = insertEndRow - insertStartRow + 1;
@@ -687,8 +175,8 @@ let SheetsFilterController = (_a2 = class extends Disposable {
687
175
  };
688
176
  }
689
177
  _handleRemoveColCommand(config, unitId, subUnitId) {
690
- var _a4;
691
- const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a4 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a4 : null;
178
+ var _a3;
179
+ const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a3 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a3 : null;
692
180
  if (!filterModel || !filterRange)
693
181
  return this._handleNull();
694
182
  const { startColumn, endColumn } = filterRange, { startColumn: removeStartColumn, endColumn: removeEndColumn } = config.range;
@@ -696,8 +184,8 @@ let SheetsFilterController = (_a2 = class extends Disposable {
696
184
  return this._handleNull();
697
185
  const redos = [], undos = [], rangeRemoveCount = removeEndColumn < startColumn ? 0 : Math.min(removeEndColumn, endColumn) - Math.max(removeStartColumn, startColumn) + 1, removeCount = removeEndColumn - removeStartColumn + 1, filterColumn = filterModel.getAllFilterColumns();
698
186
  filterColumn.forEach((column) => {
699
- const [col, filter2] = column;
700
- col <= removeEndColumn && col >= removeStartColumn && (redos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId, col, criteria: null } }), undos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId, col, criteria: { ...filter2.serialize(), colId: col } } }));
187
+ const [col, filter] = column;
188
+ col <= removeEndColumn && col >= removeStartColumn && (redos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId, col, criteria: null } }), undos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId, col, criteria: { ...filter.serialize(), colId: col } } }));
701
189
  });
702
190
  const shifted = filterColumn.filter((column) => {
703
191
  const [col, _] = column;
@@ -728,7 +216,7 @@ let SheetsFilterController = (_a2 = class extends Disposable {
728
216
  };
729
217
  }
730
218
  _handleRemoveRowCommand(config, unitId, subUnitId) {
731
- var _a4;
219
+ var _a3;
732
220
  const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId);
733
221
  if (!filterModel)
734
222
  return this._handleNull();
@@ -760,21 +248,21 @@ let SheetsFilterController = (_a2 = class extends Disposable {
760
248
  subUnitId
761
249
  };
762
250
  redos.push({ id: RemoveSheetsFilterMutation.id, params: removeFilterRangeMutationParams }), filterColumn.forEach((column) => {
763
- const [offset, filter2] = column, setCriteriaMutationParams = {
251
+ const [offset, filter] = column, setCriteriaMutationParams = {
764
252
  unitId,
765
253
  subUnitId,
766
254
  col: offset,
767
- criteria: { ...filter2.serialize(), colId: offset }
255
+ criteria: { ...filter.serialize(), colId: offset }
768
256
  };
769
257
  undos.push({ id: SetSheetsFilterCriteriaMutation.id, params: setCriteriaMutationParams });
770
258
  });
771
259
  } else {
772
- const worksheet = (_a4 = this._univerInstanceService.getUniverSheetInstance(unitId)) == null ? void 0 : _a4.getSheetBySheetId(subUnitId);
260
+ const worksheet = (_a3 = this._univerInstanceService.getUniverSheetInstance(unitId)) == null ? void 0 : _a3.getSheetBySheetId(subUnitId);
773
261
  if (!worksheet)
774
262
  return this._handleNull();
775
263
  const hiddenRows = [];
776
- for (let r = removeStartRow; r <= removeEndRow; r++)
777
- worksheet.getRowFiltered(r) && hiddenRows.push(r);
264
+ for (let r2 = removeStartRow; r2 <= removeEndRow; r2++)
265
+ worksheet.getRowFiltered(r2) && hiddenRows.push(r2);
778
266
  const afterStartRow = Math.min(startRow, removeStartRow), afterEndRow = afterStartRow + (endRow - startRow) - count + hiddenRows.length, setFilterRangeMutationParams = {
779
267
  unitId,
780
268
  subUnitId,
@@ -793,8 +281,8 @@ let SheetsFilterController = (_a2 = class extends Disposable {
793
281
  }
794
282
  // eslint-disable-next-line max-lines-per-function
795
283
  _handleMoveColsCommand(config, unitId, subUnitId) {
796
- var _a4;
797
- const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a4 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a4 : null;
284
+ var _a3;
285
+ const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a3 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a3 : null;
798
286
  if (!filterModel || !filterRange)
799
287
  return this._handleNull();
800
288
  const { startColumn, endColumn } = filterRange, { fromRange, toRange } = config;
@@ -811,20 +299,20 @@ let SheetsFilterController = (_a2 = class extends Disposable {
811
299
  startColumn >= fromRange.startColumn && startColumn <= fromRange.endColumn && toRange.startColumn > fromRange.startColumn && fromRange.endColumn < endColumn && (startBorder = fromRange.endColumn + 1), endColumn >= fromRange.startColumn && endColumn <= fromRange.endColumn && toRange.startColumn < fromRange.startColumn && fromRange.startColumn > startColumn && (endBorder = fromRange.startColumn - 1);
812
300
  const numberCols = Object.keys(filterCol).map((col) => Number(col)), newEnd = numberCols.find((col) => filterCol[col].colIndex === endBorder), newStart = numberCols.find((col) => filterCol[col].colIndex === startBorder);
813
301
  if (numberCols.forEach((col) => {
814
- var _a5, _b;
815
- const { colIndex: oldColIndex, filter: filter2 } = filterCol[col], newColIndex = col;
816
- if (filter2) {
302
+ var _a4, _b;
303
+ const { colIndex: oldColIndex, filter } = filterCol[col], newColIndex = col;
304
+ if (filter) {
817
305
  if (newColIndex >= newStart && newColIndex <= newEnd) {
818
306
  const setCriteriaMutationParams = {
819
307
  unitId,
820
308
  subUnitId,
821
309
  col: newColIndex,
822
- criteria: { ...filter2.serialize(), colId: newColIndex }
310
+ criteria: { ...filter.serialize(), colId: newColIndex }
823
311
  }, undoSetCriteriaMutationParams = {
824
312
  unitId,
825
313
  subUnitId,
826
314
  col: newColIndex,
827
- criteria: filterModel.getFilterColumn(newColIndex) ? { ...(_a5 = filterModel.getFilterColumn(newColIndex)) == null ? void 0 : _a5.serialize(), colId: newColIndex } : null
315
+ criteria: filterModel.getFilterColumn(newColIndex) ? { ...(_a4 = filterModel.getFilterColumn(newColIndex)) == null ? void 0 : _a4.serialize(), colId: newColIndex } : null
828
316
  };
829
317
  redos.push({ id: SetSheetsFilterCriteriaMutation.id, params: setCriteriaMutationParams }), undos.push({ id: SetSheetsFilterCriteriaMutation.id, params: undoSetCriteriaMutationParams });
830
318
  }
@@ -835,7 +323,7 @@ let SheetsFilterController = (_a2 = class extends Disposable {
835
323
  col: oldColIndex,
836
324
  criteria: null
837
325
  };
838
- redos.push({ id: SetSheetsFilterCriteriaMutation.id, params: setCriteriaMutationParams }), undos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId, col: oldColIndex, criteria: { ...filter2.serialize(), colId: oldColIndex } } });
326
+ redos.push({ id: SetSheetsFilterCriteriaMutation.id, params: setCriteriaMutationParams }), undos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId, col: oldColIndex, criteria: { ...filter.serialize(), colId: oldColIndex } } });
839
327
  }
840
328
  }
841
329
  }), startColumn !== newStart || endColumn !== newEnd) {
@@ -856,8 +344,8 @@ let SheetsFilterController = (_a2 = class extends Disposable {
856
344
  };
857
345
  }
858
346
  _handleMoveRowsCommand(config, unitId, subUnitId) {
859
- var _a4;
860
- const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a4 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a4 : null;
347
+ var _a3;
348
+ const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a3 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a3 : null;
861
349
  if (!filterModel || !filterRange)
862
350
  return this._handleNull();
863
351
  const { startRow, endRow } = filterRange, { fromRange, toRange } = config;
@@ -936,8 +424,8 @@ let SheetsFilterController = (_a2 = class extends Disposable {
936
424
  if (!filterRange)
937
425
  return this._handleNull();
938
426
  const redos = [], undos = [];
939
- return filterModel.getAllFilterColumns().forEach(([col, filter2]) => {
940
- undos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId, col, criteria: { ...filter2.serialize(), colId: col } } });
427
+ return filterModel.getAllFilterColumns().forEach(([col, filter]) => {
428
+ undos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId, col, criteria: { ...filter.serialize(), colId: col } } });
941
429
  }), redos.push({ id: RemoveSheetsFilterMutation.id, params: { unitId, subUnitId, range: filterRange } }), undos.unshift({ id: SetSheetsFilterRangeMutation.id, params: { range: filterRange, unitId, subUnitId } }), {
942
430
  undos,
943
431
  redos
@@ -951,8 +439,8 @@ let SheetsFilterController = (_a2 = class extends Disposable {
951
439
  if (!filterRange)
952
440
  return this._handleNull();
953
441
  const redos = [], undos = [], preUndos = [], preRedos = [];
954
- return filterModel.getAllFilterColumns().forEach(([col, filter2]) => {
955
- redos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId: targetSubUnitId, col, criteria: { ...filter2.serialize(), colId: col } } }), preUndos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId: targetSubUnitId, col, criteria: null } });
442
+ return filterModel.getAllFilterColumns().forEach(([col, filter]) => {
443
+ redos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId: targetSubUnitId, col, criteria: { ...filter.serialize(), colId: col } } }), preUndos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId: targetSubUnitId, col, criteria: null } });
956
444
  }), preUndos.push({ id: RemoveSheetsFilterMutation.id, params: { unitId, subUnitId: targetSubUnitId, range: filterRange } }), redos.unshift({ id: SetSheetsFilterRangeMutation.id, params: { range: filterRange, unitId, subUnitId: targetSubUnitId } }), {
957
445
  undos,
958
446
  redos,
@@ -967,11 +455,11 @@ let SheetsFilterController = (_a2 = class extends Disposable {
967
455
  this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.ROW_FILTERED, {
968
456
  // sheet-interceptor.service.ts
969
457
  handler: /* @__PURE__ */ __name((filtered, rowLocation) => {
970
- var _a4, _b;
971
- return filtered ? !0 : (_b = (_a4 = this._sheetsFilterService.getFilterModel(
458
+ var _a3, _b;
459
+ return filtered ? !0 : (_b = (_a3 = this._sheetsFilterService.getFilterModel(
972
460
  rowLocation.unitId,
973
461
  rowLocation.subUnitId
974
- )) == null ? void 0 : _a4.isRowFiltered(rowLocation.row)) != null ? _b : !1;
462
+ )) == null ? void 0 : _a3.isRowFiltered(rowLocation.row)) != null ? _b : !1;
975
463
  }, "handler")
976
464
  }));
977
465
  }
@@ -983,7 +471,7 @@ let SheetsFilterController = (_a2 = class extends Disposable {
983
471
  col: -1
984
472
  }, oldUndos = [], oldRedos = [], newUndos = [], newRedos = [];
985
473
  return target.forEach((column) => {
986
- const [offset, filter2] = column;
474
+ const [offset, filter] = column;
987
475
  oldRedos.push({
988
476
  id: SetSheetsFilterCriteriaMutation.id,
989
477
  params: {
@@ -995,17 +483,17 @@ let SheetsFilterController = (_a2 = class extends Disposable {
995
483
  params: {
996
484
  ...defaultSetCriteriaMutationParams,
997
485
  col: offset,
998
- criteria: { ...filter2.serialize(), colId: offset }
486
+ criteria: { ...filter.serialize(), colId: offset }
999
487
  }
1000
488
  });
1001
489
  }), target.forEach((column) => {
1002
- const [offset, filter2] = column;
490
+ const [offset, filter] = column;
1003
491
  newRedos.push({
1004
492
  id: SetSheetsFilterCriteriaMutation.id,
1005
493
  params: {
1006
494
  ...defaultSetCriteriaMutationParams,
1007
495
  col: offset + step,
1008
- criteria: { ...filter2.serialize(), colId: offset + step }
496
+ criteria: { ...filter.serialize(), colId: offset + step }
1009
497
  }
1010
498
  }), newUndos.push({
1011
499
  id: SetSheetsFilterCriteriaMutation.id,
@@ -1028,7 +516,7 @@ let SheetsFilterController = (_a2 = class extends Disposable {
1028
516
  }
1029
517
  _commandExecutedListener() {
1030
518
  this.disposeWithMe(this._commandService.onCommandExecuted((command, options) => {
1031
- var _a4, _b;
519
+ var _a3, _b;
1032
520
  const { unitId, subUnitId } = command.params || {}, filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId);
1033
521
  if (!filterModel) return;
1034
522
  const filteredOutRows = Array.from(filterModel.filteredOutRows).sort((a, b) => a - b), newFilteredOutRows = [];
@@ -1057,7 +545,7 @@ let SheetsFilterController = (_a2 = class extends Disposable {
1057
545
  const cellValue = command.params.cellValue;
1058
546
  if (cellValue)
1059
547
  for (let col = extendRegion.startColumn; col <= extendRegion.endColumn; col++) {
1060
- const cell = (_a4 = cellValue == null ? void 0 : cellValue[extendRegion.startRow]) == null ? void 0 : _a4[col];
548
+ const cell = (_a3 = cellValue == null ? void 0 : cellValue[extendRegion.startRow]) == null ? void 0 : _a3[col];
1061
549
  if (cell && this._cellHasValue(cell)) {
1062
550
  const worksheet = (_b = this._univerInstanceService.getUnit(unitId)) == null ? void 0 : _b.getSheetBySheetId(subUnitId);
1063
551
  if (worksheet) {
@@ -1074,11 +562,11 @@ let SheetsFilterController = (_a2 = class extends Disposable {
1074
562
  }));
1075
563
  }
1076
564
  _getExtendRegion(unitId, subUnitId) {
1077
- var _a4;
565
+ var _a3;
1078
566
  const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId);
1079
567
  if (!filterModel)
1080
568
  return null;
1081
- const worksheet = (_a4 = this._univerInstanceService.getUnit(unitId)) == null ? void 0 : _a4.getSheetBySheetId(subUnitId);
569
+ const worksheet = (_a3 = this._univerInstanceService.getUnit(unitId)) == null ? void 0 : _a3.getSheetBySheetId(subUnitId);
1082
570
  if (!worksheet)
1083
571
  return null;
1084
572
  const filterRange = filterModel.getRange();
@@ -1110,7 +598,7 @@ let SheetsFilterController = (_a2 = class extends Disposable {
1110
598
  const values = Object.values(cell);
1111
599
  return !(values.length === 0 || values.every((v) => v == null));
1112
600
  }
1113
- }, __name(_a2, "SheetsFilterController"), _a2);
601
+ }, __name(_a, "SheetsFilterController"), _a);
1114
602
  SheetsFilterController = __decorateClass$1([
1115
603
  __decorateParam$1(0, ICommandService),
1116
604
  __decorateParam$1(1, Inject(SheetInterceptorService)),
@@ -1120,11 +608,11 @@ SheetsFilterController = __decorateClass$1([
1120
608
  ], SheetsFilterController);
1121
609
  const PLUGIN_CONFIG_KEY = "sheets-filter.config", defaultPluginConfig = {};
1122
610
  var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1123
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1124
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
611
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
612
+ (decorator = decorators[i2]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1125
613
  return kind && result && __defProp2(target, key, result), result;
1126
- }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a3;
1127
- let UniverSheetsFilterPlugin = (_a3 = class extends Plugin {
614
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a2;
615
+ let UniverSheetsFilterPlugin = (_a2 = class extends Plugin {
1128
616
  constructor(_config = defaultPluginConfig, _injector, _configService) {
1129
617
  super(), this._config = _config, this._injector = _injector, this._configService = _configService;
1130
618
  const { ...rest } = this._config;
@@ -1139,28 +627,34 @@ let UniverSheetsFilterPlugin = (_a3 = class extends Plugin {
1139
627
  onReady() {
1140
628
  this._injector.get(SheetsFilterController);
1141
629
  }
1142
- }, __name(_a3, "UniverSheetsFilterPlugin"), __publicField(_a3, "type", UniverInstanceType.UNIVER_SHEET), __publicField(_a3, "pluginName", SHEET_FILTER_SNAPSHOT_ID), _a3);
630
+ }, __name(_a2, "UniverSheetsFilterPlugin"), __publicField(_a2, "type", UniverInstanceType.UNIVER_SHEET), __publicField(_a2, "pluginName", SHEET_FILTER_SNAPSHOT_ID), _a2);
1143
631
  UniverSheetsFilterPlugin = __decorateClass([
1144
632
  __decorateParam(1, Inject(Injector)),
1145
633
  __decorateParam(2, IConfigService)
1146
634
  ], UniverSheetsFilterPlugin);
1147
635
  export {
1148
- CustomFilterOperator,
1149
- FILTER_MUTATIONS,
1150
- FilterColumn,
1151
- FilterModel,
636
+ m as ClearSheetsFilterCriteriaCommand,
637
+ C as CustomFilterOperator,
638
+ k as FILTER_MUTATIONS,
639
+ F as FilterColumn,
640
+ e as FilterModel,
641
+ o as ReCalcSheetsFilterCommand,
1152
642
  ReCalcSheetsFilterMutation,
643
+ p as RemoveSheetFilterCommand,
1153
644
  RemoveSheetsFilterMutation,
1154
645
  SHEET_FILTER_SNAPSHOT_ID,
646
+ q as SetSheetFilterRangeCommand,
647
+ r as SetSheetsFilterCriteriaCommand,
1155
648
  SetSheetsFilterCriteriaMutation,
1156
649
  SetSheetsFilterRangeMutation,
1157
650
  SheetsFilterService,
651
+ s as SmartToggleSheetsFilterCommand,
1158
652
  UniverSheetsFilterPlugin,
1159
- equals,
1160
- getCustomFilterFn,
1161
- greaterThan,
1162
- greaterThanOrEqualTo,
1163
- lessThan,
1164
- lessThanOrEqualTo,
1165
- notEquals
653
+ f as equals,
654
+ g as getCustomFilterFn,
655
+ h as greaterThan,
656
+ i as greaterThanOrEqualTo,
657
+ l as lessThan,
658
+ j as lessThanOrEqualTo,
659
+ n as notEquals
1166
660
  };