@univerjs/sheets-filter 0.5.4 → 0.5.5-experimental.20250123-34738ff

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
@@ -1,94 +1,101 @@
1
- var Fe = Object.defineProperty;
2
- var we = (i, r, e) => r in i ? Fe(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e;
3
- var w = (i, r, e) => we(i, typeof r != "symbol" ? r + "" : r, e);
4
- import { isNumeric as Se, Disposable as V, Rectangle as Y, mergeSets as Q, Tools as k, extractPureTextFromCell as ve, CellValueType as K, UniverInstanceType as U, fromCallback as Me, CommandType as E, IResourceManagerService as Ee, IUniverInstanceService as x, ICommandService as T, Inject as z, DisposableCollection as Oe, moveMatrixArray as ee, Plugin as ye, merge as Ae, Injector as Te, IConfigService as Ne, IUndoRedoService as j, ErrorService as xe, LocaleService as Ie, sequenceExecute as $e } from "@univerjs/core";
5
- import { SheetInterceptorService as Pe, RefRangeService as Ue, SetWorksheetActiveOperation as be, CopySheetCommand as Le, RemoveSheetCommand as Be, INTERCEPTOR_POINT as ze, RemoveRowMutation as He, InsertRowMutation as De, SetRangeValuesMutation as We, expandToContinuousRange as ae, getSheetCommandTarget as L, MoveRowsCommand as Ve, MoveRangeCommand as je, EffectRefRangId as te, RemoveRowCommand as qe, RemoveColCommand as Qe, InsertColCommand as Ge, InsertRowCommand as Je, SheetsSelectionsService as Ye, isSingleCellSelection as Ke } from "@univerjs/sheets";
6
- import { BehaviorSubject as b, merge as Xe, filter as Ze, switchMap as ke, of as et } from "rxjs";
7
- const tt = "sheets-filter.config", re = {}, ce = "sheet.mutation.set-filter-range", de = "sheet.mutation.set-filter-criteria", ue = "sheet.mutation.remove-filter", he = "sheet.mutation.re-calc-filter", rt = /* @__PURE__ */ new Set([
8
- ce,
9
- de,
10
- ue,
11
- he
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
+ import { isNumeric, Disposable, Rectangle, mergeSets, Tools, extractPureTextFromCell, CellValueType, UniverInstanceType, fromCallback, CommandType, IResourceManagerService, IUniverInstanceService, ICommandService, Inject, DisposableCollection, moveMatrixArray, Plugin, merge as merge$1, Injector, IConfigService, IUndoRedoService, ErrorService, LocaleService, sequenceExecute } from "@univerjs/core";
6
+ import { SheetInterceptorService, RefRangeService, SetWorksheetActiveOperation, CopySheetCommand, RemoveSheetCommand, INTERCEPTOR_POINT, RemoveRowMutation, InsertRowMutation, SetRangeValuesMutation, expandToContinuousRange, getSheetCommandTarget, MoveRowsCommand, MoveRangeCommand, EffectRefRangId, RemoveRowCommand, RemoveColCommand, InsertColCommand, InsertRowCommand, SheetsSelectionsService, isSingleCellSelection } from "@univerjs/sheets";
7
+ import { BehaviorSubject, merge, filter, switchMap, of } from "rxjs";
8
+ const SHEETS_FILTER_PLUGIN_CONFIG_KEY = "sheets-filter.config", defaultPluginConfig = {}, SetSheetsFilterRangeMutationId = "sheet.mutation.set-filter-range", SetSheetsFilterCriteriaMutationId = "sheet.mutation.set-filter-criteria", RemoveSheetsFilterMutationId = "sheet.mutation.remove-filter", ReCalcSheetsFilterMutationId = "sheet.mutation.re-calc-filter", FILTER_MUTATIONS = /* @__PURE__ */ new Set([
9
+ SetSheetsFilterRangeMutationId,
10
+ SetSheetsFilterCriteriaMutationId,
11
+ RemoveSheetsFilterMutationId,
12
+ ReCalcSheetsFilterMutationId
12
13
  ]);
13
- var N = /* @__PURE__ */ ((i) => (i.EQUAL = "equal", i.GREATER_THAN = "greaterThan", i.GREATER_THAN_OR_EQUAL = "greaterThanOrEqual", i.LESS_THAN = "lessThan", i.LESS_THAN_OR_EQUAL = "lessThanOrEqual", i.NOT_EQUALS = "notEqual", i))(N || {});
14
- const nt = {
15
- operator: N.GREATER_THAN,
16
- fn: (i, r) => $(i) ? i > r : !1
17
- }, it = {
18
- operator: N.GREATER_THAN_OR_EQUAL,
19
- fn: (i, r) => $(i) ? i >= r : !1
20
- }, st = {
21
- operator: N.LESS_THAN,
22
- fn: (i, r) => $(i) ? i < r : !1
23
- }, ot = {
24
- operator: N.LESS_THAN_OR_EQUAL,
25
- fn: (i, r) => $(i) ? i <= r : !1
26
- }, lt = {
27
- operator: N.EQUAL,
28
- fn: (i, r) => $(i) ? i === r : !1
29
- }, fe = {
30
- operator: N.NOT_EQUALS,
31
- fn: (i, r) => {
32
- if (typeof r == "string") {
33
- if (r === " ")
34
- return i != null;
35
- const e = ge(i);
36
- return e && ut(r) ? !_e(r).test(e) : e !== r;
14
+ 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 || {});
15
+ const greaterThan = {
16
+ operator: CustomFilterOperator.GREATER_THAN,
17
+ fn: /* @__PURE__ */ __name((value, compare) => ensureNumber(value) ? value > compare : !1, "fn")
18
+ }, greaterThanOrEqualTo = {
19
+ operator: CustomFilterOperator.GREATER_THAN_OR_EQUAL,
20
+ fn: /* @__PURE__ */ __name((value, compare) => ensureNumber(value) ? value >= compare : !1, "fn")
21
+ }, lessThan = {
22
+ operator: CustomFilterOperator.LESS_THAN,
23
+ fn: /* @__PURE__ */ __name((value, compare) => ensureNumber(value) ? value < compare : !1, "fn")
24
+ }, lessThanOrEqualTo = {
25
+ operator: CustomFilterOperator.LESS_THAN_OR_EQUAL,
26
+ fn: /* @__PURE__ */ __name((value, compare) => ensureNumber(value) ? value <= compare : !1, "fn")
27
+ }, equals = {
28
+ operator: CustomFilterOperator.EQUAL,
29
+ fn: /* @__PURE__ */ __name((value, compare) => ensureNumber(value) ? value === compare : !1, "fn")
30
+ }, notEquals = {
31
+ operator: CustomFilterOperator.NOT_EQUALS,
32
+ fn: /* @__PURE__ */ __name((value, compare) => {
33
+ if (typeof compare == "string") {
34
+ if (compare === " ")
35
+ return value != null;
36
+ const ensuredString = ensureString(value);
37
+ return ensuredString && isWildCardString(compare) ? !createREGEXFromWildChar(compare).test(ensuredString) : ensuredString !== compare;
37
38
  }
38
- return $(i) ? i !== r : !0;
39
- }
40
- }, me = /* @__PURE__ */ new Map([]), at = [nt, it, st, ot, lt, fe];
41
- at.forEach((i) => {
42
- me.set(i.operator, i);
39
+ return ensureNumber(value) ? value !== compare : !0;
40
+ }, "fn")
41
+ }, CustomFilterFnRegistry = /* @__PURE__ */ new Map([]), ALL_CUSTOM_FILTER_FUNCTIONS = [greaterThan, greaterThanOrEqualTo, lessThan, lessThanOrEqualTo, equals, notEquals];
42
+ ALL_CUSTOM_FILTER_FUNCTIONS.forEach((fn) => {
43
+ CustomFilterFnRegistry.set(fn.operator, fn);
43
44
  });
44
- function ct(i) {
45
- return !!i;
45
+ function isNumericFilterFn(operator) {
46
+ return !!operator;
46
47
  }
47
- const dt = {
48
- fn: (i, r) => {
49
- const e = ge(i);
50
- return e === null ? r === "" : _e(r).test(e);
51
- }
48
+ __name(isNumericFilterFn, "isNumericFilterFn");
49
+ const textMatch = {
50
+ fn: /* @__PURE__ */ __name((value, compare) => {
51
+ const ensured = ensureString(value);
52
+ return ensured === null ? compare === "" : createREGEXFromWildChar(compare).test(ensured);
53
+ }, "fn")
52
54
  };
53
- function ne(i) {
54
- return i ? me.get(i) : dt;
55
+ function getCustomFilterFn(operator) {
56
+ return operator ? CustomFilterFnRegistry.get(operator) : textMatch;
55
57
  }
56
- function $(i) {
57
- return typeof i == "number";
58
+ __name(getCustomFilterFn, "getCustomFilterFn");
59
+ function ensureNumber(value) {
60
+ return typeof value == "number";
58
61
  }
59
- function ie(i) {
60
- return !!(typeof i == "number" || typeof i == "string" && Se(i));
62
+ __name(ensureNumber, "ensureNumber");
63
+ function ensureNumeric(value) {
64
+ return !!(typeof value == "number" || typeof value == "string" && isNumeric(value));
61
65
  }
62
- function ge(i) {
63
- return typeof i == "boolean" || i == null ? null : typeof i == "string" ? i : i.toString();
66
+ __name(ensureNumeric, "ensureNumeric");
67
+ function ensureString(value) {
68
+ return typeof value == "boolean" || value == null ? null : typeof value == "string" ? value : value.toString();
64
69
  }
65
- function ut(i) {
66
- return typeof i == "number" ? !1 : i.indexOf("*") !== -1 || i.indexOf("?") !== -1;
70
+ __name(ensureString, "ensureString");
71
+ function isWildCardString(str) {
72
+ return typeof str == "number" ? !1 : str.indexOf("*") !== -1 || str.indexOf("?") !== -1;
67
73
  }
68
- function _e(i) {
69
- const r = i.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("?", ".").replace(/[*]/g, ".$&");
70
- return new RegExp(`^${r}$`);
74
+ __name(isWildCardString, "isWildCardString");
75
+ function createREGEXFromWildChar(wildChar) {
76
+ const regexpStr = wildChar.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("?", ".").replace(/[*]/g, ".$&");
77
+ return new RegExp(`^${regexpStr}$`);
71
78
  }
72
- const G = () => /* @__PURE__ */ new Set();
73
- class D extends V {
74
- constructor(e, t, n) {
79
+ __name(createREGEXFromWildChar, "createREGEXFromWildChar");
80
+ const EMPTY = /* @__PURE__ */ __name(() => /* @__PURE__ */ new Set(), "EMPTY"), _FilterModel = class _FilterModel extends Disposable {
81
+ constructor(unitId, subUnitId, _worksheet) {
75
82
  super();
76
- w(this, "_filteredOutRows$", new b(G()));
83
+ __publicField(this, "_filteredOutRows$", new BehaviorSubject(EMPTY()));
77
84
  /** An observable value. A set of filtered out rows. */
78
- w(this, "filteredOutRows$", this._filteredOutRows$.asObservable());
85
+ __publicField(this, "filteredOutRows$", this._filteredOutRows$.asObservable());
79
86
  // TODO: we may need to update which cols have criteria rather than simple boolean
80
- w(this, "_hasCriteria$", new b(!1));
81
- w(this, "hasCriteria$", this._hasCriteria$.asObservable());
82
- w(this, "_filterColumnByIndex", /* @__PURE__ */ new Map());
83
- w(this, "_alreadyFilteredOutRows", G());
84
- w(this, "_range");
85
- this.unitId = e, this.subUnitId = t, this._worksheet = n;
87
+ __publicField(this, "_hasCriteria$", new BehaviorSubject(!1));
88
+ __publicField(this, "hasCriteria$", this._hasCriteria$.asObservable());
89
+ __publicField(this, "_filterColumnByIndex", /* @__PURE__ */ new Map());
90
+ __publicField(this, "_alreadyFilteredOutRows", EMPTY());
91
+ __publicField(this, "_range");
92
+ this.unitId = unitId, this.subUnitId = subUnitId, this._worksheet = _worksheet;
86
93
  }
87
94
  get filteredOutRows() {
88
95
  return this._filteredOutRows$.getValue();
89
96
  }
90
- set filteredOutRows(e) {
91
- this._alreadyFilteredOutRows = e, this._filteredOutRows$.next(e);
97
+ set filteredOutRows(rows) {
98
+ this._alreadyFilteredOutRows = rows, this._filteredOutRows$.next(rows);
92
99
  }
93
100
  dispose() {
94
101
  super.dispose(), this._filteredOutRows$.complete(), this._hasCriteria$.complete();
@@ -97,11 +104,11 @@ class D extends V {
97
104
  * Serialize this filter model to the JSON format representation.
98
105
  */
99
106
  serialize() {
100
- const e = {
101
- ref: Y.clone(this._range),
102
- filterColumns: this._getAllFilterColumns(!0).sort(([t], [n]) => t - n).map(([t, n]) => n.serialize())
107
+ const result = {
108
+ ref: Rectangle.clone(this._range),
109
+ filterColumns: this._getAllFilterColumns(!0).sort(([offset1], [offset2]) => offset1 - offset2).map(([_, filterColumn]) => filterColumn.serialize())
103
110
  };
104
- return this._alreadyFilteredOutRows && (e.cachedFilteredOut = Array.from(this._alreadyFilteredOutRows).sort()), e;
111
+ return this._alreadyFilteredOutRows && (result.cachedFilteredOut = Array.from(this._alreadyFilteredOutRows).sort()), result;
105
112
  }
106
113
  /**
107
114
  * Deserialize auto filter info to construct a `FilterModel` object.
@@ -110,16 +117,16 @@ class D extends V {
110
117
  * @param worksheet the Worksheet object
111
118
  * @param autoFilter auto filter data
112
119
  */
113
- static deserialize(e, t, n, s) {
114
- const o = new D(e, t, n);
115
- return o._dump(s), o;
120
+ static deserialize(unitId, subUnitId, worksheet, autoFilter) {
121
+ const filterModel = new _FilterModel(unitId, subUnitId, worksheet);
122
+ return filterModel._dump(autoFilter), filterModel;
116
123
  }
117
- _dump(e) {
118
- var t;
119
- this.setRange(e.ref), (t = e.filterColumns) == null || t.forEach((n) => this._setCriteriaWithoutReCalc(n.colId, n)), e.cachedFilteredOut && (this._alreadyFilteredOutRows = new Set(e.cachedFilteredOut), this._emit()), this._emitHasCriteria();
124
+ _dump(autoFilter) {
125
+ var _a4;
126
+ 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();
120
127
  }
121
- isRowFiltered(e) {
122
- return this._alreadyFilteredOutRows.has(e);
128
+ isRowFiltered(row) {
129
+ return this._alreadyFilteredOutRows.has(row);
123
130
  }
124
131
  getRange() {
125
132
  if (!this._range)
@@ -131,74 +138,74 @@ class D extends V {
131
138
  * another word it would not change `filteredOutRows` on `FilterModel` nor `FilterColumn`.
132
139
  * @param col
133
140
  */
134
- getFilteredOutRowsExceptCol(e) {
135
- return this._getAllFilterColumns(!0).filter(([t]) => t !== e).reduce((t, [, n]) => {
136
- const s = n.calc({ getAlreadyFilteredOutRows: () => t });
137
- return s ? Q(t, s) : t;
141
+ getFilteredOutRowsExceptCol(col) {
142
+ return this._getAllFilterColumns(!0).filter(([colOffset]) => colOffset !== col).reduce((acc, [, filterColumn]) => {
143
+ const newResult = filterColumn.calc({ getAlreadyFilteredOutRows: /* @__PURE__ */ __name(() => acc, "getAlreadyFilteredOutRows") });
144
+ return newResult ? mergeSets(acc, newResult) : acc;
138
145
  }, /* @__PURE__ */ new Set());
139
146
  }
140
147
  /**
141
148
  * Set range of the filter model, this would remove some `IFilterColumn`
142
149
  * if the new range not overlaps the old range.
143
150
  */
144
- setRange(e) {
145
- this._range = e, this._getAllFilterColumns(!0).forEach(([t, n]) => {
146
- n.setRangeAndColumn({
147
- startRow: e.startRow,
148
- endRow: e.endRow,
149
- startColumn: t,
150
- endColumn: t
151
- }, t);
151
+ setRange(range) {
152
+ this._range = range, this._getAllFilterColumns(!0).forEach(([col, filterColumn]) => {
153
+ filterColumn.setRangeAndColumn({
154
+ startRow: range.startRow,
155
+ endRow: range.endRow,
156
+ startColumn: col,
157
+ endColumn: col
158
+ }, col);
152
159
  });
153
160
  }
154
161
  /**
155
162
  * Set or remove filter criteria on a specific row.
156
163
  */
157
- setCriteria(e, t, n = !1) {
164
+ setCriteria(col, criteria, reCalc = !1) {
158
165
  if (!this._range)
159
166
  throw new Error("[FilterModel] could not set criteria before a range is set!");
160
- if (!t) {
161
- this._removeCriteria(e), this._rebuildAlreadyFilteredOutRowsWithCache(), n && this._reCalcAllColumns(), this._emit(), this._emitHasCriteria();
167
+ if (!criteria) {
168
+ this._removeCriteria(col), this._rebuildAlreadyFilteredOutRowsWithCache(), reCalc && this._reCalcAllColumns(), this._emit(), this._emitHasCriteria();
162
169
  return;
163
170
  }
164
- this._setCriteriaWithoutReCalc(e, t), n && (this._rebuildAlreadyFilteredOutRowsWithCache(), this._reCalcWithNoCacheColumns(), this._emit(), this._emitHasCriteria());
171
+ this._setCriteriaWithoutReCalc(col, criteria), reCalc && (this._rebuildAlreadyFilteredOutRowsWithCache(), this._reCalcWithNoCacheColumns(), this._emit(), this._emitHasCriteria());
165
172
  }
166
173
  getAllFilterColumns() {
167
174
  return this._getAllFilterColumns(!0);
168
175
  }
169
- getFilterColumn(e) {
170
- var t;
171
- return (t = this._filterColumnByIndex.get(e)) != null ? t : null;
176
+ getFilterColumn(index) {
177
+ var _a4;
178
+ return (_a4 = this._filterColumnByIndex.get(index)) != null ? _a4 : null;
172
179
  }
173
180
  reCalc() {
174
181
  this._reCalcAllColumns(), this._emit();
175
182
  }
176
- _getAllFilterColumns(e = !1) {
177
- const t = Array.from(this._filterColumnByIndex.entries());
178
- return e ? t : t.map(([n, s]) => s);
183
+ _getAllFilterColumns(withCol = !1) {
184
+ const columns = Array.from(this._filterColumnByIndex.entries());
185
+ return withCol ? columns : columns.map(([_, filterColumn]) => filterColumn);
179
186
  }
180
187
  _reCalcAllColumns() {
181
- this._alreadyFilteredOutRows = G(), this._getAllFilterColumns().forEach((e) => e.__clearCache()), this._reCalcWithNoCacheColumns();
188
+ this._alreadyFilteredOutRows = EMPTY(), this._getAllFilterColumns().forEach((filterColumn) => filterColumn.__clearCache()), this._reCalcWithNoCacheColumns();
182
189
  }
183
- _setCriteriaWithoutReCalc(e, t) {
184
- const n = this._range;
185
- if (!n)
190
+ _setCriteriaWithoutReCalc(col, criteria) {
191
+ const range = this._range;
192
+ if (!range)
186
193
  throw new Error("[FilterModel] could not set criteria before a range is set!");
187
- const { startColumn: s, endColumn: o } = n;
188
- if (e > o || e < s)
189
- throw new Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);
190
- let l;
191
- this._filterColumnByIndex.has(e) ? l = this._filterColumnByIndex.get(e) : (l = new ht(
194
+ const { startColumn, endColumn } = range;
195
+ if (col > endColumn || col < startColumn)
196
+ throw new Error(`[FilterModel] could not set criteria on column ${col} which is out of range!`);
197
+ let filterColumn;
198
+ this._filterColumnByIndex.has(col) ? filterColumn = this._filterColumnByIndex.get(col) : (filterColumn = new FilterColumn(
192
199
  this.unitId,
193
200
  this.subUnitId,
194
201
  this._worksheet,
195
- t,
196
- { getAlreadyFilteredOutRows: () => this._alreadyFilteredOutRows }
197
- ), l.setRangeAndColumn(n, e), this._filterColumnByIndex.set(e, l)), l.setCriteria(t);
202
+ criteria,
203
+ { getAlreadyFilteredOutRows: /* @__PURE__ */ __name(() => this._alreadyFilteredOutRows, "getAlreadyFilteredOutRows") }
204
+ ), filterColumn.setRangeAndColumn(range, col), this._filterColumnByIndex.set(col, filterColumn)), filterColumn.setCriteria(criteria);
198
205
  }
199
- _removeCriteria(e) {
200
- const t = this._filterColumnByIndex.get(e);
201
- t && (t.dispose(), this._filterColumnByIndex.delete(e));
206
+ _removeCriteria(col) {
207
+ const filterColumn = this._filterColumnByIndex.get(col);
208
+ filterColumn && (filterColumn.dispose(), this._filterColumnByIndex.delete(col));
202
209
  }
203
210
  _emit() {
204
211
  this._filteredOutRows$.next(this._alreadyFilteredOutRows);
@@ -207,27 +214,29 @@ class D extends V {
207
214
  this._hasCriteria$.next(this._filterColumnByIndex.size > 0);
208
215
  }
209
216
  _rebuildAlreadyFilteredOutRowsWithCache() {
210
- const e = this._getAllFilterColumns().filter((t) => t.hasCache()).reduce((t, n) => Q(t, n.filteredOutRows), /* @__PURE__ */ new Set());
211
- this._alreadyFilteredOutRows = e;
217
+ const newFilteredOutRows = this._getAllFilterColumns().filter((filterColumn) => filterColumn.hasCache()).reduce((acc, filterColumn) => mergeSets(acc, filterColumn.filteredOutRows), /* @__PURE__ */ new Set());
218
+ this._alreadyFilteredOutRows = newFilteredOutRows;
212
219
  }
213
220
  _reCalcWithNoCacheColumns() {
214
- const e = this._getAllFilterColumns().filter((t) => !t.hasCache());
215
- for (const t of e) {
216
- const n = t.reCalc();
217
- n && (this._alreadyFilteredOutRows = Q(this._alreadyFilteredOutRows, n));
221
+ const noCacheFilteredOutRows = this._getAllFilterColumns().filter((filterColumn) => !filterColumn.hasCache());
222
+ for (const filterColumn of noCacheFilteredOutRows) {
223
+ const filteredRows = filterColumn.reCalc();
224
+ filteredRows && (this._alreadyFilteredOutRows = mergeSets(this._alreadyFilteredOutRows, filteredRows));
218
225
  }
219
226
  }
220
- }
221
- class ht extends V {
222
- constructor(e, t, n, s, o) {
227
+ };
228
+ __name(_FilterModel, "FilterModel");
229
+ let FilterModel = _FilterModel;
230
+ const _FilterColumn = class _FilterColumn extends Disposable {
231
+ constructor(unitId, subUnitId, _worksheet, _criteria, _filterColumnContext) {
223
232
  super();
224
- w(this, "_filteredOutRows", null);
233
+ __publicField(this, "_filteredOutRows", null);
225
234
  /** Cache the filter function. */
226
- w(this, "_filterFn", null);
227
- w(this, "_range", null);
228
- w(this, "_column", 0);
229
- w(this, "_filterByValues", !1);
230
- this.unitId = e, this.subUnitId = t, this._worksheet = n, this._criteria = s, this._filterColumnContext = o;
235
+ __publicField(this, "_filterFn", null);
236
+ __publicField(this, "_range", null);
237
+ __publicField(this, "_column", 0);
238
+ __publicField(this, "_filterByValues", !1);
239
+ this.unitId = unitId, this.subUnitId = subUnitId, this._worksheet = _worksheet, this._criteria = _criteria, this._filterColumnContext = _filterColumnContext;
231
240
  }
232
241
  get filteredOutRows() {
233
242
  return this._filteredOutRows;
@@ -244,7 +253,7 @@ class ht extends V {
244
253
  serialize() {
245
254
  if (!this._criteria)
246
255
  throw new Error("[FilterColumn]: could not serialize without a filter column!");
247
- return k.deepClone({
256
+ return Tools.deepClone({
248
257
  ...this._criteria,
249
258
  colId: this._column
250
259
  });
@@ -253,14 +262,14 @@ class ht extends V {
253
262
  return this._filteredOutRows !== null;
254
263
  }
255
264
  // The first row should be omitted!
256
- setRangeAndColumn(e, t) {
257
- this._range = e, this._column = t;
265
+ setRangeAndColumn(range, column) {
266
+ this._range = range, this._column = column;
258
267
  }
259
- setCriteria(e) {
260
- this._criteria = e, this._generateFilterFn(), this._filteredOutRows = null;
268
+ setCriteria(criteria) {
269
+ this._criteria = criteria, this._generateFilterFn(), this._filteredOutRows = null;
261
270
  }
262
271
  getColumnData() {
263
- return k.deepClone(this._criteria);
272
+ return Tools.deepClone(this._criteria);
264
273
  }
265
274
  /**
266
275
  * Trigger new calculation on this `FilterModel` instance.
@@ -271,98 +280,110 @@ class ht extends V {
271
280
  reCalc() {
272
281
  return this._filteredOutRows = this.calc(this._filterColumnContext), this._filteredOutRows;
273
282
  }
274
- calc(e) {
283
+ calc(context) {
275
284
  if (!this._filterFn)
276
285
  throw new Error("[FilterColumn] cannot calculate without a filter fn!");
277
286
  if (!this._range)
278
287
  throw new Error("[FilterColumn] cannot calculate without a range!");
279
288
  if (typeof this._column != "number")
280
289
  throw new TypeError("[FilterColumn] cannot calculate without a column offset!");
281
- const t = this._column, n = { startColumn: t, endColumn: t, startRow: this._range.startRow + 1, endRow: this._range.endRow }, s = /* @__PURE__ */ new Set(), o = e.getAlreadyFilteredOutRows();
282
- for (const l of this._worksheet.iterateByColumn(n, !1, !1)) {
283
- const { row: a, rowSpan: c, col: h } = l;
284
- if (o.has(a) && (!c || c === 1))
290
+ 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();
291
+ for (const range of this._worksheet.iterateByColumn(iterateRange, !1, !1)) {
292
+ const { row, rowSpan, col } = range;
293
+ if (filteredOutByOthers.has(row) && (!rowSpan || rowSpan === 1))
285
294
  continue;
286
- const d = this._filterByValues ? ve(this._worksheet.getCell(a, h)) : Ft(this._worksheet, a, h);
287
- if (!this._filterFn(d) && (s.add(a), c))
288
- for (let u = 1; u < c; u++)
289
- s.add(a + u);
295
+ const value = this._filterByValues ? extractPureTextFromCell(this._worksheet.getCell(row, col)) : getFilterValueForConditionalFiltering(this._worksheet, row, col);
296
+ if (!this._filterFn(value) && (filteredOutRows.add(row), rowSpan))
297
+ for (let i = 1; i < rowSpan; i++)
298
+ filteredOutRows.add(row + i);
290
299
  }
291
- return s;
300
+ return filteredOutRows;
292
301
  }
293
302
  _generateFilterFn() {
294
- this._criteria && (this._filterFn = ft(this._criteria), this._filterByValues = !!this._criteria.filters);
303
+ this._criteria && (this._filterFn = generateFilterFn(this._criteria), this._filterByValues = !!this._criteria.filters);
295
304
  }
296
- }
297
- function ft(i) {
298
- if (i.filters)
299
- return mt(i.filters);
300
- if (i.customFilters)
301
- return gt(i.customFilters);
305
+ };
306
+ __name(_FilterColumn, "FilterColumn");
307
+ let FilterColumn = _FilterColumn;
308
+ function generateFilterFn(column) {
309
+ if (column.filters)
310
+ return filterByValuesFnFactory(column.filters);
311
+ if (column.customFilters)
312
+ return customFilterFnFactory(column.customFilters);
302
313
  throw new Error("[FilterModel]: other types of filters are not supported yet.");
303
314
  }
304
- function mt(i) {
305
- const r = !!i.blank, e = new Set(i.filters);
306
- return (t) => t === void 0 || t === "" ? r : e.has(typeof t == "string" ? t : `${t}`);
315
+ __name(generateFilterFn, "generateFilterFn");
316
+ function filterByValuesFnFactory(values) {
317
+ const includeBlank = !!values.blank, valuesSet = new Set(values.filters);
318
+ return (value) => value === void 0 || value === "" ? includeBlank : valuesSet.has(typeof value == "string" ? value : `${value}`);
307
319
  }
308
- function gt(i) {
309
- const r = i.customFilters.map((e) => pt(e));
310
- return Ct(r) ? i.and ? _t(r) : Rt(r) : r[0];
320
+ __name(filterByValuesFnFactory, "filterByValuesFnFactory");
321
+ function customFilterFnFactory(customFilters) {
322
+ const customFilterFns = customFilters.customFilters.map((filter2) => generateCustomFilterFn(filter2));
323
+ return isCompoundCustomFilter(customFilterFns) ? customFilters.and ? AND(customFilterFns) : OR(customFilterFns) : customFilterFns[0];
311
324
  }
312
- function _t(i) {
313
- const [r, e] = i;
314
- return (t) => r(t) && e(t);
325
+ __name(customFilterFnFactory, "customFilterFnFactory");
326
+ function AND(filterFns) {
327
+ const [fn1, fn2] = filterFns;
328
+ return (value) => fn1(value) && fn2(value);
315
329
  }
316
- function Rt(i) {
317
- const [r, e] = i;
318
- return (t) => r(t) || e(t);
330
+ __name(AND, "AND");
331
+ function OR(filterFns) {
332
+ const [fn1, fn2] = filterFns;
333
+ return (value) => fn1(value) || fn2(value);
319
334
  }
320
- function Ct(i) {
321
- return i.length === 2;
335
+ __name(OR, "OR");
336
+ function isCompoundCustomFilter(filter2) {
337
+ return filter2.length === 2;
322
338
  }
323
- function pt(i) {
324
- const r = i.val;
325
- if (i.operator === N.NOT_EQUALS && !ie(r))
326
- return (n) => fe.fn(n, r);
327
- if (ct(i.operator)) {
328
- if (!ie(r)) return () => !1;
329
- const n = ne(i.operator), s = Number(r);
330
- return (o) => n.fn(o, s);
331
- }
332
- const e = ne(i.operator);
333
- return (t) => e.fn(t, r);
339
+ __name(isCompoundCustomFilter, "isCompoundCustomFilter");
340
+ function generateCustomFilterFn(filter2) {
341
+ const compare = filter2.val;
342
+ if (filter2.operator === CustomFilterOperator.NOT_EQUALS && !ensureNumeric(compare))
343
+ return (value) => notEquals.fn(value, compare);
344
+ if (isNumericFilterFn(filter2.operator)) {
345
+ if (!ensureNumeric(compare)) return () => !1;
346
+ const customFilterFn2 = getCustomFilterFn(filter2.operator), ensuredNumber = Number(compare);
347
+ return (value) => customFilterFn2.fn(value, ensuredNumber);
348
+ }
349
+ const customFilterFn = getCustomFilterFn(filter2.operator);
350
+ return (value) => customFilterFn.fn(value, compare);
334
351
  }
335
- function Ft(i, r, e) {
336
- const t = i.getCell(r, e);
337
- if (!t) return null;
338
- const n = i.getCellRaw(r, e);
339
- return t && !n ? se(t) : n ? t.t === K.NUMBER && typeof t.v == "string" ? n.v : se(n) : null;
352
+ __name(generateCustomFilterFn, "generateCustomFilterFn");
353
+ function getFilterValueForConditionalFiltering(worksheet, row, col) {
354
+ const interceptedCell = worksheet.getCell(row, col);
355
+ if (!interceptedCell) return null;
356
+ const rawCell = worksheet.getCellRaw(row, col);
357
+ return interceptedCell && !rawCell ? extractFilterValueFromCell(interceptedCell) : rawCell ? interceptedCell.t === CellValueType.NUMBER && typeof interceptedCell.v == "string" ? rawCell.v : extractFilterValueFromCell(rawCell) : null;
340
358
  }
341
- function se(i) {
342
- var t, n;
343
- const r = (n = (t = i.p) == null ? void 0 : t.body) == null ? void 0 : n.dataStream;
344
- if (r) return r.trimEnd();
345
- const e = i.v;
346
- return typeof e == "string" ? i.t === K.BOOLEAN ? e.toUpperCase() : e : typeof e == "number" ? i.t === K.BOOLEAN ? e ? "TRUE" : "FALSE" : e : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : "";
359
+ __name(getFilterValueForConditionalFiltering, "getFilterValueForConditionalFiltering");
360
+ function extractFilterValueFromCell(cell) {
361
+ var _a4, _b;
362
+ const richTextValue = (_b = (_a4 = cell.p) == null ? void 0 : _a4.body) == null ? void 0 : _b.dataStream;
363
+ if (richTextValue) return richTextValue.trimEnd();
364
+ const rawValue = cell.v;
365
+ 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" : "";
347
366
  }
348
- var wt = Object.defineProperty, St = Object.getOwnPropertyDescriptor, vt = (i, r, e, t) => {
349
- for (var n = t > 1 ? void 0 : t ? St(r, e) : r, s = i.length - 1, o; s >= 0; s--)
350
- (o = i[s]) && (n = (t ? o(r, e, n) : o(n)) || n);
351
- return t && n && wt(r, e, n), n;
352
- }, J = (i, r) => (e, t) => r(e, t, i);
353
- const Re = "SHEET_FILTER_PLUGIN";
354
- let M = class extends V {
355
- constructor(r, e, t) {
367
+ __name(extractFilterValueFromCell, "extractFilterValueFromCell");
368
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
369
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
370
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
371
+ return kind && result && __defProp$2(target, key, result), result;
372
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2");
373
+ const SHEET_FILTER_SNAPSHOT_ID = "SHEET_FILTER_PLUGIN";
374
+ var _a;
375
+ let SheetsFilterService = (_a = class extends Disposable {
376
+ constructor(_resourcesManagerService, _univerInstanceService, _commandService) {
356
377
  super();
357
- w(this, "_filterModels", /* @__PURE__ */ new Map());
358
- w(this, "_loadedUnitId$", new b(null));
359
- w(this, "loadedUnitId$", this._loadedUnitId$.asObservable());
360
- w(this, "_errorMsg$", new b(null));
361
- w(this, "errorMsg$", this._errorMsg$.asObservable());
362
- w(this, "_activeFilterModel$", new b(null));
378
+ __publicField(this, "_filterModels", /* @__PURE__ */ new Map());
379
+ __publicField(this, "_loadedUnitId$", new BehaviorSubject(null));
380
+ __publicField(this, "loadedUnitId$", this._loadedUnitId$.asObservable());
381
+ __publicField(this, "_errorMsg$", new BehaviorSubject(null));
382
+ __publicField(this, "errorMsg$", this._errorMsg$.asObservable());
383
+ __publicField(this, "_activeFilterModel$", new BehaviorSubject(null));
363
384
  /** An observable value emitting the current Workbook's active Worksheet's filter model (if there is one). */
364
- w(this, "activeFilterModel$", this._activeFilterModel$.asObservable());
365
- this._resourcesManagerService = r, this._univerInstanceService = e, this._commandService = t, this._initModel(), this._initActiveFilterModel();
385
+ __publicField(this, "activeFilterModel$", this._activeFilterModel$.asObservable());
386
+ this._resourcesManagerService = _resourcesManagerService, this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this._initModel(), this._initActiveFilterModel();
366
387
  }
367
388
  /** The current Workbook's active Worksheet's filter model (if there is one). */
368
389
  get activeFilterModel() {
@@ -373,235 +394,237 @@ let M = class extends V {
373
394
  * @param unitId
374
395
  * @param subUnitId
375
396
  */
376
- ensureFilterModel(r, e) {
377
- const t = this.getFilterModel(r, e);
378
- if (t)
379
- return t;
380
- const n = this._univerInstanceService.getUniverSheetInstance(r);
381
- if (!n)
382
- throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${r}!`);
383
- const s = n.getSheetBySheetId(e);
384
- if (!s)
385
- throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${e}!`);
386
- const o = new D(r, e, s);
387
- return this._cacheFilterModel(r, e, o), o;
388
- }
389
- getFilterModel(r, e) {
390
- var t, n;
391
- return (n = (t = this._filterModels.get(r)) == null ? void 0 : t.get(e)) != null ? n : null;
392
- }
393
- removeFilterModel(r, e) {
394
- const t = this.getFilterModel(r, e);
395
- return t ? (t.dispose(), this._filterModels.get(r).delete(e), !0) : !1;
396
- }
397
- setFilterErrorMsg(r) {
398
- this._errorMsg$.next(r);
397
+ ensureFilterModel(unitId, subUnitId) {
398
+ const already = this.getFilterModel(unitId, subUnitId);
399
+ if (already)
400
+ return already;
401
+ const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
402
+ if (!workbook)
403
+ throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${unitId}!`);
404
+ const worksheet = workbook.getSheetBySheetId(subUnitId);
405
+ if (!worksheet)
406
+ throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${subUnitId}!`);
407
+ const filterModel = new FilterModel(unitId, subUnitId, worksheet);
408
+ return this._cacheFilterModel(unitId, subUnitId, filterModel), filterModel;
409
+ }
410
+ getFilterModel(unitId, subUnitId) {
411
+ var _a4, _b;
412
+ return (_b = (_a4 = this._filterModels.get(unitId)) == null ? void 0 : _a4.get(subUnitId)) != null ? _b : null;
413
+ }
414
+ removeFilterModel(unitId, subUnitId) {
415
+ const already = this.getFilterModel(unitId, subUnitId);
416
+ return already ? (already.dispose(), this._filterModels.get(unitId).delete(subUnitId), !0) : !1;
417
+ }
418
+ setFilterErrorMsg(content) {
419
+ this._errorMsg$.next(content);
399
420
  }
400
421
  _updateActiveFilterModel() {
401
- let r;
422
+ let workbook;
402
423
  try {
403
- if (r = this._univerInstanceService.getCurrentUnitForType(U.UNIVER_SHEET), !r) {
424
+ if (workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), !workbook) {
404
425
  this._activeFilterModel$.next(null);
405
426
  return;
406
427
  }
407
- } catch (o) {
408
- console.error("[SheetsFilterService]: could not get active workbook!", o);
428
+ } catch (err) {
429
+ console.error("[SheetsFilterService]: could not get active workbook!", err);
409
430
  return;
410
431
  }
411
- const e = r.getActiveSheet(!0);
412
- if (!e) {
432
+ const activeSheet = workbook.getActiveSheet(!0);
433
+ if (!activeSheet) {
413
434
  this._activeFilterModel$.next(null);
414
435
  return;
415
436
  }
416
- const t = e.getUnitId(), n = e.getSheetId(), s = this.getFilterModel(t, n);
417
- this._activeFilterModel$.next(s);
437
+ const unitId = activeSheet.getUnitId(), subUnitId = activeSheet.getSheetId(), filterModel = this.getFilterModel(unitId, subUnitId);
438
+ this._activeFilterModel$.next(filterModel);
418
439
  }
419
440
  _initActiveFilterModel() {
420
441
  this.disposeWithMe(
421
- Xe(
442
+ merge(
422
443
  // source1: executing filter related mutations
423
- Me(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(Ze(([r]) => r.type === E.MUTATION && rt.has(r.id))),
444
+ fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(filter(([command]) => command.type === CommandType.MUTATION && FILTER_MUTATIONS.has(command.id))),
424
445
  // source2: activate sheet changes
425
- this._univerInstanceService.getCurrentTypeOfUnit$(U.UNIVER_SHEET).pipe(ke((r) => {
426
- var e;
427
- return (e = r == null ? void 0 : r.activeSheet$) != null ? e : et(null);
446
+ this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(switchMap((workbook) => {
447
+ var _a4;
448
+ return (_a4 = workbook == null ? void 0 : workbook.activeSheet$) != null ? _a4 : of(null);
428
449
  }))
429
450
  ).subscribe(() => this._updateActiveFilterModel())
430
451
  );
431
452
  }
432
- _serializeAutoFiltersForUnit(r) {
433
- const e = this._filterModels.get(r);
434
- if (!e)
453
+ _serializeAutoFiltersForUnit(unitId) {
454
+ const allFilterModels = this._filterModels.get(unitId);
455
+ if (!allFilterModels)
435
456
  return "{}";
436
- const t = {};
437
- return e.forEach((n, s) => {
438
- t[s] = n.serialize();
439
- }), JSON.stringify(t);
440
- }
441
- _deserializeAutoFiltersForUnit(r, e) {
442
- const t = this._univerInstanceService.getUniverSheetInstance(r);
443
- Object.keys(e).forEach((n) => {
444
- const s = e[n], o = D.deserialize(r, n, t.getSheetBySheetId(n), s);
445
- this._cacheFilterModel(r, n, o);
457
+ const json = {};
458
+ return allFilterModels.forEach((model, worksheetId) => {
459
+ json[worksheetId] = model.serialize();
460
+ }), JSON.stringify(json);
461
+ }
462
+ _deserializeAutoFiltersForUnit(unitId, json) {
463
+ const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
464
+ Object.keys(json).forEach((worksheetId) => {
465
+ const autoFilter = json[worksheetId], filterModel = FilterModel.deserialize(unitId, worksheetId, workbook.getSheetBySheetId(worksheetId), autoFilter);
466
+ this._cacheFilterModel(unitId, worksheetId, filterModel);
446
467
  });
447
468
  }
448
469
  _initModel() {
449
470
  this._resourcesManagerService.registerPluginResource({
450
- pluginName: Re,
451
- businesses: [U.UNIVER_SHEET],
452
- toJson: (r) => this._serializeAutoFiltersForUnit(r),
453
- parseJson: (r) => JSON.parse(r),
454
- onLoad: (r, e) => {
455
- this._deserializeAutoFiltersForUnit(r, e), this._loadedUnitId$.next(r), this._updateActiveFilterModel();
456
- },
457
- onUnLoad: (r) => {
458
- const e = this._filterModels.get(r);
459
- e && (e.forEach((t) => t.dispose()), this._filterModels.delete(r));
460
- }
471
+ pluginName: SHEET_FILTER_SNAPSHOT_ID,
472
+ businesses: [UniverInstanceType.UNIVER_SHEET],
473
+ toJson: /* @__PURE__ */ __name((id) => this._serializeAutoFiltersForUnit(id), "toJson"),
474
+ parseJson: /* @__PURE__ */ __name((json) => JSON.parse(json), "parseJson"),
475
+ onLoad: /* @__PURE__ */ __name((unitId, value) => {
476
+ this._deserializeAutoFiltersForUnit(unitId, value), this._loadedUnitId$.next(unitId), this._updateActiveFilterModel();
477
+ }, "onLoad"),
478
+ onUnLoad: /* @__PURE__ */ __name((unitId) => {
479
+ const allFilterModels = this._filterModels.get(unitId);
480
+ allFilterModels && (allFilterModels.forEach((model) => model.dispose()), this._filterModels.delete(unitId));
481
+ }, "onUnLoad")
461
482
  });
462
483
  }
463
- _cacheFilterModel(r, e, t) {
464
- this._filterModels.has(r) || this._filterModels.set(r, /* @__PURE__ */ new Map()), this._filterModels.get(r).set(e, t);
465
- }
484
+ _cacheFilterModel(unitId, subUnitId, filterModel) {
485
+ this._filterModels.has(unitId) || this._filterModels.set(unitId, /* @__PURE__ */ new Map()), this._filterModels.get(unitId).set(subUnitId, filterModel);
486
+ }
487
+ }, __name(_a, "SheetsFilterService"), _a);
488
+ SheetsFilterService = __decorateClass$2([
489
+ __decorateParam$2(0, IResourceManagerService),
490
+ __decorateParam$2(1, IUniverInstanceService),
491
+ __decorateParam$2(2, ICommandService)
492
+ ], SheetsFilterService);
493
+ const SetSheetsFilterRangeMutation = {
494
+ id: SetSheetsFilterRangeMutationId,
495
+ type: CommandType.MUTATION,
496
+ handler: /* @__PURE__ */ __name((accessor, params) => {
497
+ const { subUnitId, unitId, range } = params;
498
+ return accessor.get(SheetsFilterService).ensureFilterModel(unitId, subUnitId).setRange(range), !0;
499
+ }, "handler")
500
+ }, SetSheetsFilterCriteriaMutation = {
501
+ id: SetSheetsFilterCriteriaMutationId,
502
+ type: CommandType.MUTATION,
503
+ handler: /* @__PURE__ */ __name((accessor, params) => {
504
+ const { subUnitId, unitId, criteria, col, reCalc = !0 } = params, filterModel = accessor.get(SheetsFilterService).getFilterModel(unitId, subUnitId);
505
+ return filterModel ? (filterModel.setCriteria(col, criteria, reCalc), !0) : !1;
506
+ }, "handler")
507
+ }, RemoveSheetsFilterMutation = {
508
+ id: RemoveSheetsFilterMutationId,
509
+ type: CommandType.MUTATION,
510
+ handler: /* @__PURE__ */ __name((accessor, params) => {
511
+ const { unitId, subUnitId } = params;
512
+ return accessor.get(SheetsFilterService).removeFilterModel(unitId, subUnitId);
513
+ }, "handler")
514
+ }, ReCalcSheetsFilterMutation = {
515
+ id: ReCalcSheetsFilterMutationId,
516
+ type: CommandType.MUTATION,
517
+ handler: /* @__PURE__ */ __name((accessor, params) => {
518
+ const { unitId, subUnitId } = params, filterModel = accessor.get(SheetsFilterService).getFilterModel(unitId, subUnitId);
519
+ return filterModel ? (filterModel.reCalc(), !0) : !1;
520
+ }, "handler")
466
521
  };
467
- M = vt([
468
- J(0, Ee),
469
- J(1, x),
470
- J(2, T)
471
- ], M);
472
- const R = {
473
- id: ce,
474
- type: E.MUTATION,
475
- handler: (i, r) => {
476
- const { subUnitId: e, unitId: t, range: n } = r;
477
- return i.get(M).ensureFilterModel(t, e).setRange(n), !0;
478
- }
479
- }, p = {
480
- id: de,
481
- type: E.MUTATION,
482
- handler: (i, r) => {
483
- const { subUnitId: e, unitId: t, criteria: n, col: s, reCalc: o = !0 } = r, a = i.get(M).getFilterModel(t, e);
484
- return a ? (a.setCriteria(s, n, o), !0) : !1;
485
- }
486
- }, O = {
487
- id: ue,
488
- type: E.MUTATION,
489
- handler: (i, r) => {
490
- const { unitId: e, subUnitId: t } = r;
491
- return i.get(M).removeFilterModel(e, t);
492
- }
493
- }, H = {
494
- id: he,
495
- type: E.MUTATION,
496
- handler: (i, r) => {
497
- const { unitId: e, subUnitId: t } = r, s = i.get(M).getFilterModel(e, t);
498
- return s ? (s.reCalc(), !0) : !1;
499
- }
500
- };
501
- function Mt(i, r) {
502
- for (let e = 0; e < i.length; e++) {
503
- let t = e;
504
- if (i[e])
505
- for (let n = e + 1; n < i.length; n++)
506
- i[t] && i[n] && r(i[t], i[n]) && (i[t] = null, t = n);
507
- }
508
- return i.filter((e) => e !== null);
522
+ function objectsShaker(target, isEqual) {
523
+ for (let i = 0; i < target.length; i++) {
524
+ let cur = i;
525
+ if (target[i])
526
+ for (let j = i + 1; j < target.length; j++)
527
+ target[cur] && target[j] && isEqual(target[cur], target[j]) && (target[cur] = null, cur = j);
528
+ }
529
+ return target.filter((o) => o !== null);
509
530
  }
510
- function I(i) {
511
- return Mt(i, (r, e) => r.id === p.id && e.id === p.id && r.params.unitId === e.params.unitId && r.params.subUnitId === e.params.subUnitId && r.params.col === e.params.col);
531
+ __name(objectsShaker, "objectsShaker");
532
+ function mergeSetFilterCriteria(mutations) {
533
+ return objectsShaker(mutations, (o1, o2) => o1.id === SetSheetsFilterCriteriaMutation.id && o2.id === SetSheetsFilterCriteriaMutation.id && o1.params.unitId === o2.params.unitId && o1.params.subUnitId === o2.params.subUnitId && o1.params.col === o2.params.col);
512
534
  }
513
- var Et = Object.defineProperty, Ot = Object.getOwnPropertyDescriptor, yt = (i, r, e, t) => {
514
- for (var n = t > 1 ? void 0 : t ? Ot(r, e) : r, s = i.length - 1, o; s >= 0; s--)
515
- (o = i[s]) && (n = (t ? o(r, e, n) : o(n)) || n);
516
- return t && n && Et(r, e, n), n;
517
- }, P = (i, r) => (e, t) => r(e, t, i);
518
- let W = class extends V {
519
- constructor(r, e, t, n, s) {
535
+ __name(mergeSetFilterCriteria, "mergeSetFilterCriteria");
536
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
537
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
538
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
539
+ return kind && result && __defProp$1(target, key, result), result;
540
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a2;
541
+ let SheetsFilterController = (_a2 = class extends Disposable {
542
+ constructor(_commandService, _sheetInterceptorService, _sheetsFilterService, _univerInstanceService, _refRangeService) {
520
543
  super();
521
- w(this, "_disposableCollection", new Oe());
522
- this._commandService = r, this._sheetInterceptorService = e, this._sheetsFilterService = t, this._univerInstanceService = n, this._refRangeService = s, this._initCommands(), this._initRowFilteredInterceptor(), this._initInterceptors(), this._commandExecutedListener(), this._initErrorHandling();
544
+ __publicField(this, "_disposableCollection", new DisposableCollection());
545
+ this._commandService = _commandService, this._sheetInterceptorService = _sheetInterceptorService, this._sheetsFilterService = _sheetsFilterService, this._univerInstanceService = _univerInstanceService, this._refRangeService = _refRangeService, this._initCommands(), this._initRowFilteredInterceptor(), this._initInterceptors(), this._commandExecutedListener(), this._initErrorHandling();
523
546
  }
524
547
  _initCommands() {
525
548
  [
526
- p,
527
- R,
528
- H,
529
- O
530
- ].forEach((r) => this.disposeWithMe(this._commandService.registerCommand(r)));
549
+ SetSheetsFilterCriteriaMutation,
550
+ SetSheetsFilterRangeMutation,
551
+ ReCalcSheetsFilterMutation,
552
+ RemoveSheetsFilterMutation
553
+ ].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
531
554
  }
532
555
  _initInterceptors() {
533
556
  this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
534
- getMutations: (r) => this._getUpdateFilter(r)
535
- })), this.disposeWithMe(this._commandService.onCommandExecuted((r) => {
536
- if (r.id === be.id) {
537
- const e = r.params, t = e.subUnitId, n = e.unitId;
538
- if (!t || !n)
557
+ getMutations: /* @__PURE__ */ __name((command) => this._getUpdateFilter(command), "getMutations")
558
+ })), this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
559
+ if (commandInfo.id === SetWorksheetActiveOperation.id) {
560
+ const params = commandInfo.params, sheetId = params.subUnitId, unitId = params.unitId;
561
+ if (!sheetId || !unitId)
539
562
  return;
540
- this._registerRefRange(n, t);
563
+ this._registerRefRange(unitId, sheetId);
541
564
  }
542
- if (r.id === R.id) {
543
- const e = r.params, t = e.subUnitId, n = e.unitId;
544
- if (!t || !n)
565
+ if (commandInfo.id === SetSheetsFilterRangeMutation.id) {
566
+ const params = commandInfo.params, sheetId = params.subUnitId, unitId = params.unitId;
567
+ if (!sheetId || !unitId)
545
568
  return;
546
- this._registerRefRange(e.unitId, e.subUnitId);
569
+ this._registerRefRange(params.unitId, params.subUnitId);
547
570
  }
548
- })), this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe((r) => {
549
- if (r) {
550
- const e = this._univerInstanceService.getUniverSheetInstance(r), t = e == null ? void 0 : e.getActiveSheet();
551
- t && this._registerRefRange(r, t.getSheetId());
571
+ })), this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe((unitId) => {
572
+ if (unitId) {
573
+ const workbook = this._univerInstanceService.getUniverSheetInstance(unitId), sheet = workbook == null ? void 0 : workbook.getActiveSheet();
574
+ sheet && this._registerRefRange(unitId, sheet.getSheetId());
552
575
  }
553
576
  }));
554
577
  }
555
- _registerRefRange(r, e) {
556
- var l;
578
+ _registerRefRange(unitId, subUnitId) {
579
+ var _a4;
557
580
  this._disposableCollection.dispose();
558
- const t = this._univerInstanceService.getUniverSheetInstance(r), n = t == null ? void 0 : t.getSheetBySheetId(e);
559
- if (!t || !n) return;
560
- const s = (l = this._sheetsFilterService.getFilterModel(r, e)) == null ? void 0 : l.getRange(), o = (a) => {
561
- switch (a.id) {
562
- case Je.id: {
563
- const c = a.params, h = c.unitId || r, d = c.subUnitId || e;
564
- return this._handleInsertRowCommand(c, h, d);
581
+ const workbook = this._univerInstanceService.getUniverSheetInstance(unitId), workSheet = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId);
582
+ if (!workbook || !workSheet) return;
583
+ const range = (_a4 = this._sheetsFilterService.getFilterModel(unitId, subUnitId)) == null ? void 0 : _a4.getRange(), handler = /* @__PURE__ */ __name((config) => {
584
+ switch (config.id) {
585
+ case InsertRowCommand.id: {
586
+ const params = config.params, _unitId = params.unitId || unitId, _subUnitId = params.subUnitId || subUnitId;
587
+ return this._handleInsertRowCommand(params, _unitId, _subUnitId);
565
588
  }
566
- case Ge.id: {
567
- const c = a.params, h = c.unitId || r, d = c.subUnitId || e;
568
- return this._handleInsertColCommand(c, h, d);
589
+ case InsertColCommand.id: {
590
+ const params = config.params, _unitId = params.unitId || unitId, _subUnitId = params.subUnitId || subUnitId;
591
+ return this._handleInsertColCommand(params, _unitId, _subUnitId);
569
592
  }
570
- case Qe.id: {
571
- const c = a.params;
572
- return this._handleRemoveColCommand(c, r, e);
593
+ case RemoveColCommand.id: {
594
+ const params = config.params;
595
+ return this._handleRemoveColCommand(params, unitId, subUnitId);
573
596
  }
574
- case qe.id: {
575
- const c = a.params;
576
- return this._handleRemoveRowCommand(c, r, e);
597
+ case RemoveRowCommand.id: {
598
+ const params = config.params;
599
+ return this._handleRemoveRowCommand(params, unitId, subUnitId);
577
600
  }
578
- case te.MoveColsCommandId: {
579
- const c = a.params;
580
- return this._handleMoveColsCommand(c, r, e);
601
+ case EffectRefRangId.MoveColsCommandId: {
602
+ const params = config.params;
603
+ return this._handleMoveColsCommand(params, unitId, subUnitId);
581
604
  }
582
- case te.MoveRowsCommandId: {
583
- const c = a.params;
584
- return this._handleMoveRowsCommand(c, r, e);
605
+ case EffectRefRangId.MoveRowsCommandId: {
606
+ const params = config.params;
607
+ return this._handleMoveRowsCommand(params, unitId, subUnitId);
585
608
  }
586
- case je.id: {
587
- const c = a.params;
588
- return this._handleMoveRangeCommand(c, r, e);
609
+ case MoveRangeCommand.id: {
610
+ const params = config.params;
611
+ return this._handleMoveRangeCommand(params, unitId, subUnitId);
589
612
  }
590
613
  }
591
614
  return { redos: [], undos: [] };
592
- };
593
- s && this._disposableCollection.add(this._refRangeService.registerRefRange(s, o, r, e));
594
- }
595
- _getUpdateFilter(r) {
596
- const { id: e } = r;
597
- switch (e) {
598
- case Be.id: {
599
- const t = r.params;
600
- return this._handleRemoveSheetCommand(t, t.unitId, t.subUnitId);
615
+ }, "handler");
616
+ range && this._disposableCollection.add(this._refRangeService.registerRefRange(range, handler, unitId, subUnitId));
617
+ }
618
+ _getUpdateFilter(command) {
619
+ const { id } = command;
620
+ switch (id) {
621
+ case RemoveSheetCommand.id: {
622
+ const params = command.params;
623
+ return this._handleRemoveSheetCommand(params, params.unitId, params.subUnitId);
601
624
  }
602
- case Le.id: {
603
- const t = r.params, { targetSubUnitId: n, unitId: s, subUnitId: o } = t;
604
- return !s || !o || !n ? this._handleNull() : this._handleCopySheetCommand(s, o, n);
625
+ case CopySheetCommand.id: {
626
+ const params = command.params, { targetSubUnitId, unitId, subUnitId } = params;
627
+ return !unitId || !subUnitId || !targetSubUnitId ? this._handleNull() : this._handleCopySheetCommand(unitId, subUnitId, targetSubUnitId);
605
628
  }
606
629
  }
607
630
  return {
@@ -609,441 +632,441 @@ let W = class extends V {
609
632
  undos: []
610
633
  };
611
634
  }
612
- _handleInsertColCommand(r, e, t) {
613
- var _;
614
- const n = this._sheetsFilterService.getFilterModel(e, t), s = (_ = n == null ? void 0 : n.getRange()) != null ? _ : null;
615
- if (!n || !s)
635
+ _handleInsertColCommand(config, unitId, subUnitId) {
636
+ var _a4;
637
+ const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a4 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a4 : null;
638
+ if (!filterModel || !filterRange)
616
639
  return this._handleNull();
617
- const { startColumn: o, endColumn: l } = s, { startColumn: a, endColumn: c } = r.range, h = c - a + 1;
618
- if (c > l)
640
+ const { startColumn, endColumn } = filterRange, { startColumn: insertStartColumn, endColumn: insertEndColumn } = config.range, count = insertEndColumn - insertStartColumn + 1;
641
+ if (insertEndColumn > endColumn)
619
642
  return this._handleNull();
620
- const d = [], u = [], m = a, g = {
621
- unitId: e,
622
- subUnitId: t,
643
+ const redos = [], undos = [], anchor = insertStartColumn, setFilterRangeMutationParams = {
644
+ unitId,
645
+ subUnitId,
623
646
  range: {
624
- ...s,
625
- startColumn: a <= o ? o + h : o,
626
- endColumn: l + h
647
+ ...filterRange,
648
+ startColumn: insertStartColumn <= startColumn ? startColumn + count : startColumn,
649
+ endColumn: endColumn + count
627
650
  }
628
- }, C = {
629
- unitId: e,
630
- subUnitId: t,
631
- range: s
651
+ }, undoSetFilterRangeMutationParams = {
652
+ unitId,
653
+ subUnitId,
654
+ range: filterRange
632
655
  };
633
- d.push({ id: R.id, params: g }), u.push({ id: R.id, params: C });
634
- const F = n.getAllFilterColumns().filter((f) => f[0] >= m);
635
- if (F.length !== 0) {
636
- const { newRange: f, oldRange: v } = this.moveCriteria(e, t, F, h);
637
- d.push(...f.redos, ...v.redos), u.push(...f.undos, ...v.undos);
656
+ redos.push({ id: SetSheetsFilterRangeMutation.id, params: setFilterRangeMutationParams }), undos.push({ id: SetSheetsFilterRangeMutation.id, params: undoSetFilterRangeMutationParams });
657
+ const effected = filterModel.getAllFilterColumns().filter((column) => column[0] >= anchor);
658
+ if (effected.length !== 0) {
659
+ const { newRange, oldRange } = this.moveCriteria(unitId, subUnitId, effected, count);
660
+ redos.push(...newRange.redos, ...oldRange.redos), undos.push(...newRange.undos, ...oldRange.undos);
638
661
  }
639
- return { redos: I(d), undos: I(u) };
662
+ return { redos: mergeSetFilterCriteria(redos), undos: mergeSetFilterCriteria(undos) };
640
663
  }
641
- _handleInsertRowCommand(r, e, t) {
642
- var C;
643
- const n = this._sheetsFilterService.getFilterModel(e, t), s = (C = n == null ? void 0 : n.getRange()) != null ? C : null;
644
- if (!n || !s)
664
+ _handleInsertRowCommand(config, unitId, subUnitId) {
665
+ var _a4;
666
+ const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a4 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a4 : null;
667
+ if (!filterModel || !filterRange)
645
668
  return this._handleNull();
646
- const { startRow: o, endRow: l } = s, { startRow: a, endRow: c } = r.range, h = c - a + 1;
647
- if (c > l)
669
+ const { startRow, endRow } = filterRange, { startRow: insertStartRow, endRow: insertEndRow } = config.range, rowCount = insertEndRow - insertStartRow + 1;
670
+ if (insertEndRow > endRow)
648
671
  return this._handleNull();
649
- const d = [], u = [], m = {
650
- unitId: e,
651
- subUnitId: t,
672
+ const redos = [], undos = [], setFilterRangeParams = {
673
+ unitId,
674
+ subUnitId,
652
675
  range: {
653
- ...s,
654
- startRow: a <= o ? o + h : o,
655
- endRow: l + h
676
+ ...filterRange,
677
+ startRow: insertStartRow <= startRow ? startRow + rowCount : startRow,
678
+ endRow: endRow + rowCount
656
679
  }
657
- }, g = {
658
- unitId: e,
659
- subUnitId: t,
660
- range: s
680
+ }, undoSetFilterRangeMutationParams = {
681
+ unitId,
682
+ subUnitId,
683
+ range: filterRange
661
684
  };
662
- return d.push({ id: R.id, params: m }), u.push({ id: R.id, params: g }), {
663
- redos: I(d),
664
- undos: I(u)
685
+ return redos.push({ id: SetSheetsFilterRangeMutation.id, params: setFilterRangeParams }), undos.push({ id: SetSheetsFilterRangeMutation.id, params: undoSetFilterRangeMutationParams }), {
686
+ redos: mergeSetFilterCriteria(redos),
687
+ undos: mergeSetFilterCriteria(undos)
665
688
  };
666
689
  }
667
- _handleRemoveColCommand(r, e, t) {
668
- var F;
669
- const n = this._sheetsFilterService.getFilterModel(e, t), s = (F = n == null ? void 0 : n.getRange()) != null ? F : null;
670
- if (!n || !s)
690
+ _handleRemoveColCommand(config, unitId, subUnitId) {
691
+ var _a4;
692
+ const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a4 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a4 : null;
693
+ if (!filterModel || !filterRange)
671
694
  return this._handleNull();
672
- const { startColumn: o, endColumn: l } = s, { startColumn: a, endColumn: c } = r.range;
673
- if (a > l)
695
+ const { startColumn, endColumn } = filterRange, { startColumn: removeStartColumn, endColumn: removeEndColumn } = config.range;
696
+ if (removeStartColumn > endColumn)
674
697
  return this._handleNull();
675
- const h = [], d = [], u = c < o ? 0 : Math.min(c, l) - Math.max(a, o) + 1, m = c - a + 1, g = n.getAllFilterColumns();
676
- g.forEach((_) => {
677
- const [f, v] = _;
678
- f <= c && f >= a && (h.push({ id: p.id, params: { unitId: e, subUnitId: t, col: f, criteria: null } }), d.push({ id: p.id, params: { unitId: e, subUnitId: t, col: f, criteria: { ...v.serialize(), colId: f } } }));
698
+ const redos = [], undos = [], rangeRemoveCount = removeEndColumn < startColumn ? 0 : Math.min(removeEndColumn, endColumn) - Math.max(removeStartColumn, startColumn) + 1, removeCount = removeEndColumn - removeStartColumn + 1, filterColumn = filterModel.getAllFilterColumns();
699
+ filterColumn.forEach((column) => {
700
+ const [col, filter2] = column;
701
+ 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 } } }));
679
702
  });
680
- const C = g.filter((_) => {
681
- const [f, v] = _;
682
- return f > c;
703
+ const shifted = filterColumn.filter((column) => {
704
+ const [col, _] = column;
705
+ return col > removeEndColumn;
683
706
  });
684
- let S = { undos: [], redos: [] };
685
- if (C.length > 0) {
686
- const { oldRange: _, newRange: f } = this.moveCriteria(e, t, C, -m);
687
- S = f, h.push(..._.redos), d.unshift(..._.undos);
707
+ let newRangeCriteria = { undos: [], redos: [] };
708
+ if (shifted.length > 0) {
709
+ const { oldRange, newRange } = this.moveCriteria(unitId, subUnitId, shifted, -removeCount);
710
+ newRangeCriteria = newRange, redos.push(...oldRange.redos), undos.unshift(...oldRange.undos);
688
711
  }
689
- if (u === l - o + 1) {
690
- const _ = {
691
- unitId: e,
692
- subUnitId: t
712
+ if (rangeRemoveCount === endColumn - startColumn + 1) {
713
+ const removeFilterRangeMutationParams = {
714
+ unitId,
715
+ subUnitId
693
716
  };
694
- h.push({ id: O.id, params: _ }), d.unshift({ id: R.id, params: { range: s, unitId: e, subUnitId: t } });
717
+ redos.push({ id: RemoveSheetsFilterMutation.id, params: removeFilterRangeMutationParams }), undos.unshift({ id: SetSheetsFilterRangeMutation.id, params: { range: filterRange, unitId, subUnitId } });
695
718
  } else {
696
- const _ = o <= a ? o : u === 0 ? o - m : a, f = o <= a ? l - u : l - m, v = {
697
- unitId: e,
698
- subUnitId: t,
699
- range: { ...s, startColumn: _, endColumn: f }
719
+ const newStartColumn = startColumn <= removeStartColumn ? startColumn : rangeRemoveCount === 0 ? startColumn - removeCount : removeStartColumn, newEndColumn = startColumn <= removeStartColumn ? endColumn - rangeRemoveCount : endColumn - removeCount, setFilterRangeMutationParams = {
720
+ unitId,
721
+ subUnitId,
722
+ range: { ...filterRange, startColumn: newStartColumn, endColumn: newEndColumn }
700
723
  };
701
- h.push({ id: R.id, params: v }), d.unshift({ id: R.id, params: { range: s, unitId: e, subUnitId: t } }), h.push(...S.redos), d.unshift(...S.undos);
724
+ redos.push({ id: SetSheetsFilterRangeMutation.id, params: setFilterRangeMutationParams }), undos.unshift({ id: SetSheetsFilterRangeMutation.id, params: { range: filterRange, unitId, subUnitId } }), redos.push(...newRangeCriteria.redos), undos.unshift(...newRangeCriteria.undos);
702
725
  }
703
726
  return {
704
- undos: d,
705
- redos: h
727
+ undos,
728
+ redos
706
729
  };
707
730
  }
708
- _handleRemoveRowCommand(r, e, t) {
709
- var C;
710
- const n = this._sheetsFilterService.getFilterModel(e, t);
711
- if (!n)
731
+ _handleRemoveRowCommand(config, unitId, subUnitId) {
732
+ var _a4;
733
+ const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId);
734
+ if (!filterModel)
712
735
  return this._handleNull();
713
- const s = n.getRange(), { startRow: o, endRow: l } = s, { startRow: a, endRow: c } = r.range;
714
- if (a > l)
736
+ const filterRange = filterModel.getRange(), { startRow, endRow } = filterRange, { startRow: removeStartRow, endRow: removeEndRow } = config.range;
737
+ if (removeStartRow > endRow)
715
738
  return this._handleNull();
716
- if (c < o)
739
+ if (removeEndRow < startRow)
717
740
  return {
718
- undos: [{ id: R.id, params: { range: s, unitId: e, subUnitId: t } }],
741
+ undos: [{ id: SetSheetsFilterRangeMutation.id, params: { range: filterRange, unitId, subUnitId } }],
719
742
  redos: [{
720
- id: R.id,
743
+ id: SetSheetsFilterRangeMutation.id,
721
744
  params: {
722
745
  range: {
723
- ...s,
724
- startRow: o - (c - a + 1),
725
- endRow: l - (c - a + 1)
746
+ ...filterRange,
747
+ startRow: startRow - (removeEndRow - removeStartRow + 1),
748
+ endRow: endRow - (removeEndRow - removeStartRow + 1)
726
749
  },
727
- unitId: e,
728
- subUnitId: t
750
+ unitId,
751
+ subUnitId
729
752
  }
730
753
  }]
731
754
  };
732
- const h = [], d = [], u = n.getAllFilterColumns(), m = o <= c && o >= a;
733
- d.push({ id: R.id, params: { range: s, unitId: e, subUnitId: t } });
734
- const g = Math.min(c, l) - Math.max(a, o) + 1;
735
- if (g === l - o + 1 || m) {
736
- const S = {
737
- unitId: e,
738
- subUnitId: t
755
+ const redos = [], undos = [], filterColumn = filterModel.getAllFilterColumns(), filterHeaderIsRemoved = startRow <= removeEndRow && startRow >= removeStartRow;
756
+ undos.push({ id: SetSheetsFilterRangeMutation.id, params: { range: filterRange, unitId, subUnitId } });
757
+ const count = Math.min(removeEndRow, endRow) - Math.max(removeStartRow, startRow) + 1;
758
+ if (count === endRow - startRow + 1 || filterHeaderIsRemoved) {
759
+ const removeFilterRangeMutationParams = {
760
+ unitId,
761
+ subUnitId
739
762
  };
740
- h.push({ id: O.id, params: S }), u.forEach((F) => {
741
- const [_, f] = F, v = {
742
- unitId: e,
743
- subUnitId: t,
744
- col: _,
745
- criteria: { ...f.serialize(), colId: _ }
763
+ redos.push({ id: RemoveSheetsFilterMutation.id, params: removeFilterRangeMutationParams }), filterColumn.forEach((column) => {
764
+ const [offset, filter2] = column, setCriteriaMutationParams = {
765
+ unitId,
766
+ subUnitId,
767
+ col: offset,
768
+ criteria: { ...filter2.serialize(), colId: offset }
746
769
  };
747
- d.push({ id: p.id, params: v });
770
+ undos.push({ id: SetSheetsFilterCriteriaMutation.id, params: setCriteriaMutationParams });
748
771
  });
749
772
  } else {
750
- const S = (C = this._univerInstanceService.getUniverSheetInstance(e)) == null ? void 0 : C.getSheetBySheetId(t);
751
- if (!S)
773
+ const worksheet = (_a4 = this._univerInstanceService.getUniverSheetInstance(unitId)) == null ? void 0 : _a4.getSheetBySheetId(subUnitId);
774
+ if (!worksheet)
752
775
  return this._handleNull();
753
- const F = [];
754
- for (let y = a; y <= c; y++)
755
- S.getRowFiltered(y) && F.push(y);
756
- const _ = Math.min(o, a), f = _ + (l - o) - g + F.length, v = {
757
- unitId: e,
758
- subUnitId: t,
776
+ const hiddenRows = [];
777
+ for (let r = removeStartRow; r <= removeEndRow; r++)
778
+ worksheet.getRowFiltered(r) && hiddenRows.push(r);
779
+ const afterStartRow = Math.min(startRow, removeStartRow), afterEndRow = afterStartRow + (endRow - startRow) - count + hiddenRows.length, setFilterRangeMutationParams = {
780
+ unitId,
781
+ subUnitId,
759
782
  range: {
760
- ...s,
761
- startRow: _,
762
- endRow: f
783
+ ...filterRange,
784
+ startRow: afterStartRow,
785
+ endRow: afterEndRow
763
786
  }
764
787
  };
765
- h.push({ id: R.id, params: v });
788
+ redos.push({ id: SetSheetsFilterRangeMutation.id, params: setFilterRangeMutationParams });
766
789
  }
767
790
  return {
768
- undos: I(d),
769
- redos: I(h)
791
+ undos: mergeSetFilterCriteria(undos),
792
+ redos: mergeSetFilterCriteria(redos)
770
793
  };
771
794
  }
772
795
  // eslint-disable-next-line max-lines-per-function
773
- _handleMoveColsCommand(r, e, t) {
774
- var _;
775
- const n = this._sheetsFilterService.getFilterModel(e, t), s = (_ = n == null ? void 0 : n.getRange()) != null ? _ : null;
776
- if (!n || !s)
796
+ _handleMoveColsCommand(config, unitId, subUnitId) {
797
+ var _a4;
798
+ const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a4 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a4 : null;
799
+ if (!filterModel || !filterRange)
777
800
  return this._handleNull();
778
- const { startColumn: o, endColumn: l } = s, { fromRange: a, toRange: c } = r;
779
- if (a.endColumn < o && c.startColumn <= o || a.startColumn > l && c.endColumn > l)
801
+ const { startColumn, endColumn } = filterRange, { fromRange, toRange } = config;
802
+ if (fromRange.endColumn < startColumn && toRange.startColumn <= startColumn || fromRange.startColumn > endColumn && toRange.endColumn > endColumn)
780
803
  return this._handleNull();
781
- const h = [], d = [], u = {};
782
- for (let f = o; f <= l; f++)
783
- u[f] = {
784
- colIndex: f,
785
- filter: n.getFilterColumn(f)
804
+ const redos = [], undos = [], filterCol = {};
805
+ for (let col = startColumn; col <= endColumn; col++)
806
+ filterCol[col] = {
807
+ colIndex: col,
808
+ filter: filterModel.getFilterColumn(col)
786
809
  };
787
- ee(a.startColumn, a.endColumn - a.startColumn + 1, c.startColumn, u);
788
- let m = s.startColumn, g = s.endColumn;
789
- o >= a.startColumn && o <= a.endColumn && c.startColumn > a.startColumn && a.endColumn < l && (m = a.endColumn + 1), l >= a.startColumn && l <= a.endColumn && c.startColumn < a.startColumn && a.startColumn > o && (g = a.startColumn - 1);
790
- const C = Object.keys(u).map((f) => Number(f)), S = C.find((f) => u[f].colIndex === g), F = C.find((f) => u[f].colIndex === m);
791
- if (C.forEach((f) => {
792
- var X, Z;
793
- const { colIndex: v, filter: y } = u[f], A = f;
794
- if (y) {
795
- if (A >= F && A <= S) {
796
- const q = {
797
- unitId: e,
798
- subUnitId: t,
799
- col: A,
800
- criteria: { ...y.serialize(), colId: A }
801
- }, pe = {
802
- unitId: e,
803
- subUnitId: t,
804
- col: A,
805
- criteria: n.getFilterColumn(A) ? { ...(X = n.getFilterColumn(A)) == null ? void 0 : X.serialize(), colId: A } : null
810
+ moveMatrixArray(fromRange.startColumn, fromRange.endColumn - fromRange.startColumn + 1, toRange.startColumn, filterCol);
811
+ let startBorder = filterRange.startColumn, endBorder = filterRange.endColumn;
812
+ 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);
813
+ 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);
814
+ if (numberCols.forEach((col) => {
815
+ var _a5, _b;
816
+ const { colIndex: oldColIndex, filter: filter2 } = filterCol[col], newColIndex = col;
817
+ if (filter2) {
818
+ if (newColIndex >= newStart && newColIndex <= newEnd) {
819
+ const setCriteriaMutationParams = {
820
+ unitId,
821
+ subUnitId,
822
+ col: newColIndex,
823
+ criteria: { ...filter2.serialize(), colId: newColIndex }
824
+ }, undoSetCriteriaMutationParams = {
825
+ unitId,
826
+ subUnitId,
827
+ col: newColIndex,
828
+ criteria: filterModel.getFilterColumn(newColIndex) ? { ...(_a5 = filterModel.getFilterColumn(newColIndex)) == null ? void 0 : _a5.serialize(), colId: newColIndex } : null
806
829
  };
807
- h.push({ id: p.id, params: q }), d.push({ id: p.id, params: pe });
830
+ redos.push({ id: SetSheetsFilterCriteriaMutation.id, params: setCriteriaMutationParams }), undos.push({ id: SetSheetsFilterCriteriaMutation.id, params: undoSetCriteriaMutationParams });
808
831
  }
809
- if (!((Z = u[v]) != null && Z.filter)) {
810
- const q = {
811
- unitId: e,
812
- subUnitId: t,
813
- col: v,
832
+ if (!((_b = filterCol[oldColIndex]) != null && _b.filter)) {
833
+ const setCriteriaMutationParams = {
834
+ unitId,
835
+ subUnitId,
836
+ col: oldColIndex,
814
837
  criteria: null
815
838
  };
816
- h.push({ id: p.id, params: q }), d.push({ id: p.id, params: { unitId: e, subUnitId: t, col: v, criteria: { ...y.serialize(), colId: v } } });
839
+ redos.push({ id: SetSheetsFilterCriteriaMutation.id, params: setCriteriaMutationParams }), undos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId, col: oldColIndex, criteria: { ...filter2.serialize(), colId: oldColIndex } } });
817
840
  }
818
841
  }
819
- }), o !== F || l !== S) {
820
- const f = {
821
- unitId: e,
822
- subUnitId: t,
842
+ }), startColumn !== newStart || endColumn !== newEnd) {
843
+ const setFilterRangeMutationParams = {
844
+ unitId,
845
+ subUnitId,
823
846
  range: {
824
- ...s,
825
- startColumn: F,
826
- endColumn: S
847
+ ...filterRange,
848
+ startColumn: newStart,
849
+ endColumn: newEnd
827
850
  }
828
851
  };
829
- h.unshift({ id: R.id, params: f }), d.unshift({ id: R.id, params: { range: s, unitId: e, subUnitId: t } });
852
+ redos.unshift({ id: SetSheetsFilterRangeMutation.id, params: setFilterRangeMutationParams }), undos.unshift({ id: SetSheetsFilterRangeMutation.id, params: { range: filterRange, unitId, subUnitId } });
830
853
  }
831
854
  return {
832
- undos: d,
833
- redos: h
855
+ undos,
856
+ redos
834
857
  };
835
858
  }
836
- _handleMoveRowsCommand(r, e, t) {
837
- var _;
838
- const n = this._sheetsFilterService.getFilterModel(e, t), s = (_ = n == null ? void 0 : n.getRange()) != null ? _ : null;
839
- if (!n || !s)
859
+ _handleMoveRowsCommand(config, unitId, subUnitId) {
860
+ var _a4;
861
+ const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = (_a4 = filterModel == null ? void 0 : filterModel.getRange()) != null ? _a4 : null;
862
+ if (!filterModel || !filterRange)
840
863
  return this._handleNull();
841
- const { startRow: o, endRow: l } = s, { fromRange: a, toRange: c } = r;
842
- if (a.endRow < o && c.startRow <= o || a.startRow > l && c.endRow > l)
864
+ const { startRow, endRow } = filterRange, { fromRange, toRange } = config;
865
+ if (fromRange.endRow < startRow && toRange.startRow <= startRow || fromRange.startRow > endRow && toRange.endRow > endRow)
843
866
  return this._handleNull();
844
- const h = [], d = [], u = {};
845
- for (let f = o; f <= l; f++)
846
- u[f] = {
847
- oldIndex: f
867
+ const redos = [], undos = [], filterRow = {};
868
+ for (let row = startRow; row <= endRow; row++)
869
+ filterRow[row] = {
870
+ oldIndex: row
848
871
  };
849
- const m = o;
850
- let g = l;
851
- l >= a.startRow && l <= a.endRow && c.startRow < a.startRow && a.startRow > o && (g = a.startRow - 1), ee(a.startRow, a.endRow - a.startRow + 1, c.startRow, u);
852
- const C = Object.keys(u).map((f) => Number(f)), S = C.find((f) => u[f].oldIndex === g), F = C.find((f) => u[f].oldIndex === m);
853
- if (o !== F || l !== S) {
854
- const f = {
855
- unitId: e,
856
- subUnitId: t,
872
+ const startBorder = startRow;
873
+ let endBorder = endRow;
874
+ endRow >= fromRange.startRow && endRow <= fromRange.endRow && toRange.startRow < fromRange.startRow && fromRange.startRow > startRow && (endBorder = fromRange.startRow - 1), moveMatrixArray(fromRange.startRow, fromRange.endRow - fromRange.startRow + 1, toRange.startRow, filterRow);
875
+ const numberRows = Object.keys(filterRow).map((row) => Number(row)), newEnd = numberRows.find((row) => filterRow[row].oldIndex === endBorder), newStart = numberRows.find((row) => filterRow[row].oldIndex === startBorder);
876
+ if (startRow !== newStart || endRow !== newEnd) {
877
+ const setFilterRangeMutationParams = {
878
+ unitId,
879
+ subUnitId,
857
880
  range: {
858
- ...s,
859
- startRow: F,
860
- endRow: S
881
+ ...filterRange,
882
+ startRow: newStart,
883
+ endRow: newEnd
861
884
  }
862
885
  };
863
- h.push({ id: R.id, params: f }, { id: H.id, params: { unitId: e, subUnitId: t } }), d.push({ id: R.id, params: { range: s, unitId: e, subUnitId: t } }, { id: H.id, params: { unitId: e, subUnitId: t } });
886
+ redos.push({ id: SetSheetsFilterRangeMutation.id, params: setFilterRangeMutationParams }, { id: ReCalcSheetsFilterMutation.id, params: { unitId, subUnitId } }), undos.push({ id: SetSheetsFilterRangeMutation.id, params: { range: filterRange, unitId, subUnitId } }, { id: ReCalcSheetsFilterMutation.id, params: { unitId, subUnitId } });
864
887
  }
865
888
  return {
866
- redos: h,
867
- undos: d
889
+ redos,
890
+ undos
868
891
  };
869
892
  }
870
- _handleMoveRangeCommand(r, e, t) {
871
- const { fromRange: n, toRange: s } = r, o = this._sheetsFilterService.getFilterModel(e, t);
872
- if (!o)
893
+ _handleMoveRangeCommand(config, unitId, subUnitId) {
894
+ const { fromRange, toRange } = config, filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId);
895
+ if (!filterModel)
873
896
  return this._handleNull();
874
- const l = o.getRange();
875
- if (!l)
897
+ const filterRange = filterModel.getRange();
898
+ if (!filterRange)
876
899
  return this._handleNull();
877
- const a = [], c = [];
878
- if (Y.contains(n, l)) {
879
- const h = l.startRow - n.startRow, d = l.startColumn - n.startColumn, u = {
880
- startRow: s.startRow + h,
881
- startColumn: s.startColumn + d,
882
- endRow: s.startRow + h + (l.endRow - l.startRow),
883
- endColumn: s.startColumn + d + (l.endColumn - l.startColumn)
884
- }, m = {
885
- id: O.id,
900
+ const redos = [], undos = [];
901
+ if (Rectangle.contains(fromRange, filterRange)) {
902
+ const rowOffset = filterRange.startRow - fromRange.startRow, colOffset = filterRange.startColumn - fromRange.startColumn, newFilterRange = {
903
+ startRow: toRange.startRow + rowOffset,
904
+ startColumn: toRange.startColumn + colOffset,
905
+ endRow: toRange.startRow + rowOffset + (filterRange.endRow - filterRange.startRow),
906
+ endColumn: toRange.startColumn + colOffset + (filterRange.endColumn - filterRange.startColumn)
907
+ }, removeFilter = {
908
+ id: RemoveSheetsFilterMutation.id,
886
909
  params: {
887
- unitId: e,
888
- subUnitId: t
910
+ unitId,
911
+ subUnitId
889
912
  }
890
- }, g = { id: R.id, params: { unitId: e, subUnitId: t, range: u } }, C = { id: R.id, params: { unitId: e, subUnitId: t, range: l } };
891
- a.push(m, g), c.push(m, C);
892
- const S = o.getAllFilterColumns(), F = s.startColumn - n.startColumn;
893
- S.forEach((_) => {
894
- const [f, v] = _;
895
- v && (a.push({ id: p.id, params: { unitId: e, subUnitId: t, col: f + F, criteria: { ...v.serialize(), colId: f + F } } }), c.push({ id: p.id, params: { unitId: e, subUnitId: t, col: f, criteria: { ...v.serialize(), colId: f } } }));
913
+ }, setNewFilterRange = { id: SetSheetsFilterRangeMutation.id, params: { unitId, subUnitId, range: newFilterRange } }, setOldFilterRange = { id: SetSheetsFilterRangeMutation.id, params: { unitId, subUnitId, range: filterRange } };
914
+ redos.push(removeFilter, setNewFilterRange), undos.push(removeFilter, setOldFilterRange);
915
+ const filterColumn = filterModel.getAllFilterColumns(), moveColDelta = toRange.startColumn - fromRange.startColumn;
916
+ filterColumn.forEach((column) => {
917
+ const [col, criteria] = column;
918
+ criteria && (redos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId, col: col + moveColDelta, criteria: { ...criteria.serialize(), colId: col + moveColDelta } } }), undos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId, col, criteria: { ...criteria.serialize(), colId: col } } }));
896
919
  });
897
- } else if (Y.intersects(s, l)) {
898
- const h = {
899
- ...l,
900
- endRow: Math.max(l.endRow, s.endRow)
920
+ } else if (Rectangle.intersects(toRange, filterRange)) {
921
+ const newFilterRange = {
922
+ ...filterRange,
923
+ endRow: Math.max(filterRange.endRow, toRange.endRow)
901
924
  };
902
- a.push({ id: R.id, params: { unitId: e, subUnitId: t, range: h } }), c.push({ id: R.id, params: { unitId: e, subUnitId: t, range: l } });
925
+ redos.push({ id: SetSheetsFilterRangeMutation.id, params: { unitId, subUnitId, range: newFilterRange } }), undos.push({ id: SetSheetsFilterRangeMutation.id, params: { unitId, subUnitId, range: filterRange } });
903
926
  }
904
927
  return {
905
- redos: a,
906
- undos: c
928
+ redos,
929
+ undos
907
930
  };
908
931
  }
909
- _handleRemoveSheetCommand(r, e, t) {
910
- const n = this._sheetsFilterService.getFilterModel(e, t);
911
- if (!n)
932
+ _handleRemoveSheetCommand(config, unitId, subUnitId) {
933
+ const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId);
934
+ if (!filterModel)
912
935
  return this._handleNull();
913
- const s = n.getRange();
914
- if (!s)
936
+ const filterRange = filterModel.getRange();
937
+ if (!filterRange)
915
938
  return this._handleNull();
916
- const o = [], l = [];
917
- return n.getAllFilterColumns().forEach(([c, h]) => {
918
- l.push({ id: p.id, params: { unitId: e, subUnitId: t, col: c, criteria: { ...h.serialize(), colId: c } } });
919
- }), o.push({ id: O.id, params: { unitId: e, subUnitId: t, range: s } }), l.unshift({ id: R.id, params: { range: s, unitId: e, subUnitId: t } }), {
920
- undos: l,
921
- redos: o
939
+ const redos = [], undos = [];
940
+ return filterModel.getAllFilterColumns().forEach(([col, filter2]) => {
941
+ undos.push({ id: SetSheetsFilterCriteriaMutation.id, params: { unitId, subUnitId, col, criteria: { ...filter2.serialize(), colId: col } } });
942
+ }), redos.push({ id: RemoveSheetsFilterMutation.id, params: { unitId, subUnitId, range: filterRange } }), undos.unshift({ id: SetSheetsFilterRangeMutation.id, params: { range: filterRange, unitId, subUnitId } }), {
943
+ undos,
944
+ redos
922
945
  };
923
946
  }
924
- _handleCopySheetCommand(r, e, t) {
925
- const n = this._sheetsFilterService.getFilterModel(r, e);
926
- if (!n)
947
+ _handleCopySheetCommand(unitId, subUnitId, targetSubUnitId) {
948
+ const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId);
949
+ if (!filterModel)
927
950
  return this._handleNull();
928
- const s = n.getRange();
929
- if (!s)
951
+ const filterRange = filterModel.getRange();
952
+ if (!filterRange)
930
953
  return this._handleNull();
931
- const o = [], l = [], a = [], c = [];
932
- return n.getAllFilterColumns().forEach(([d, u]) => {
933
- o.push({ id: p.id, params: { unitId: r, subUnitId: t, col: d, criteria: { ...u.serialize(), colId: d } } }), a.push({ id: p.id, params: { unitId: r, subUnitId: t, col: d, criteria: null } });
934
- }), a.push({ id: O.id, params: { unitId: r, subUnitId: t, range: s } }), o.unshift({ id: R.id, params: { range: s, unitId: r, subUnitId: t } }), {
935
- undos: l,
936
- redos: o,
937
- preUndos: a,
938
- preRedos: c
954
+ const redos = [], undos = [], preUndos = [], preRedos = [];
955
+ return filterModel.getAllFilterColumns().forEach(([col, filter2]) => {
956
+ 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 } });
957
+ }), preUndos.push({ id: RemoveSheetsFilterMutation.id, params: { unitId, subUnitId: targetSubUnitId, range: filterRange } }), redos.unshift({ id: SetSheetsFilterRangeMutation.id, params: { range: filterRange, unitId, subUnitId: targetSubUnitId } }), {
958
+ undos,
959
+ redos,
960
+ preUndos,
961
+ preRedos
939
962
  };
940
963
  }
941
964
  _handleNull() {
942
965
  return { redos: [], undos: [] };
943
966
  }
944
967
  _initRowFilteredInterceptor() {
945
- this.disposeWithMe(this._sheetInterceptorService.intercept(ze.ROW_FILTERED, {
968
+ this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.ROW_FILTERED, {
946
969
  // sheet-interceptor.service.ts
947
- handler: (r, e) => {
948
- var t, n;
949
- return r ? !0 : (n = (t = this._sheetsFilterService.getFilterModel(
950
- e.unitId,
951
- e.subUnitId
952
- )) == null ? void 0 : t.isRowFiltered(e.row)) != null ? n : !1;
953
- }
970
+ handler: /* @__PURE__ */ __name((filtered, rowLocation) => {
971
+ var _a4, _b;
972
+ return filtered ? !0 : (_b = (_a4 = this._sheetsFilterService.getFilterModel(
973
+ rowLocation.unitId,
974
+ rowLocation.subUnitId
975
+ )) == null ? void 0 : _a4.isRowFiltered(rowLocation.row)) != null ? _b : !1;
976
+ }, "handler")
954
977
  }));
955
978
  }
956
- moveCriteria(r, e, t, n) {
957
- const s = {
958
- unitId: r,
959
- subUnitId: e,
979
+ moveCriteria(unitId, subUnitId, target, step) {
980
+ const defaultSetCriteriaMutationParams = {
981
+ unitId,
982
+ subUnitId,
960
983
  criteria: null,
961
984
  col: -1
962
- }, o = [], l = [], a = [], c = [];
963
- return t.forEach((h) => {
964
- const [d, u] = h;
965
- l.push({
966
- id: p.id,
985
+ }, oldUndos = [], oldRedos = [], newUndos = [], newRedos = [];
986
+ return target.forEach((column) => {
987
+ const [offset, filter2] = column;
988
+ oldRedos.push({
989
+ id: SetSheetsFilterCriteriaMutation.id,
967
990
  params: {
968
- ...s,
969
- col: d
991
+ ...defaultSetCriteriaMutationParams,
992
+ col: offset
970
993
  }
971
- }), o.push({
972
- id: p.id,
994
+ }), oldUndos.push({
995
+ id: SetSheetsFilterCriteriaMutation.id,
973
996
  params: {
974
- ...s,
975
- col: d,
976
- criteria: { ...u.serialize(), colId: d }
997
+ ...defaultSetCriteriaMutationParams,
998
+ col: offset,
999
+ criteria: { ...filter2.serialize(), colId: offset }
977
1000
  }
978
1001
  });
979
- }), t.forEach((h) => {
980
- const [d, u] = h;
981
- c.push({
982
- id: p.id,
1002
+ }), target.forEach((column) => {
1003
+ const [offset, filter2] = column;
1004
+ newRedos.push({
1005
+ id: SetSheetsFilterCriteriaMutation.id,
983
1006
  params: {
984
- ...s,
985
- col: d + n,
986
- criteria: { ...u.serialize(), colId: d + n }
1007
+ ...defaultSetCriteriaMutationParams,
1008
+ col: offset + step,
1009
+ criteria: { ...filter2.serialize(), colId: offset + step }
987
1010
  }
988
- }), a.push({
989
- id: p.id,
1011
+ }), newUndos.push({
1012
+ id: SetSheetsFilterCriteriaMutation.id,
990
1013
  params: {
991
- ...s,
992
- col: d + n,
1014
+ ...defaultSetCriteriaMutationParams,
1015
+ col: offset + step,
993
1016
  criteria: null
994
1017
  }
995
1018
  });
996
1019
  }), {
997
1020
  newRange: {
998
- redos: c,
999
- undos: a
1021
+ redos: newRedos,
1022
+ undos: newUndos
1000
1023
  },
1001
1024
  oldRange: {
1002
- redos: l,
1003
- undos: o
1025
+ redos: oldRedos,
1026
+ undos: oldUndos
1004
1027
  }
1005
1028
  };
1006
1029
  }
1007
1030
  _commandExecutedListener() {
1008
- this.disposeWithMe(this._commandService.onCommandExecuted((r, e) => {
1009
- var c, h;
1010
- const { unitId: t, subUnitId: n } = r.params || {}, s = this._sheetsFilterService.getFilterModel(t, n);
1011
- if (!s) return;
1012
- const o = Array.from(s.filteredOutRows).sort((d, u) => d - u), l = [];
1013
- let a = !1;
1014
- if (r.id === He.id) {
1015
- const { startRow: d, endRow: u } = r.params.range, m = o.filter((g) => g >= d && g <= u);
1016
- o.forEach((g) => {
1017
- if (g < d)
1018
- l.push(g);
1019
- else if (a = !0, g <= u) {
1020
- const C = Math.max(d, l.length ? l[l.length - 1] + 1 : d);
1021
- l.push(C);
1031
+ this.disposeWithMe(this._commandService.onCommandExecuted((command, options) => {
1032
+ var _a4, _b;
1033
+ const { unitId, subUnitId } = command.params || {}, filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId);
1034
+ if (!filterModel) return;
1035
+ const filteredOutRows = Array.from(filterModel.filteredOutRows).sort((a, b) => a - b), newFilteredOutRows = [];
1036
+ let changed = !1;
1037
+ if (command.id === RemoveRowMutation.id) {
1038
+ const { startRow, endRow } = command.params.range, filterOutInRemove = filteredOutRows.filter((row) => row >= startRow && row <= endRow);
1039
+ filteredOutRows.forEach((row) => {
1040
+ if (row < startRow)
1041
+ newFilteredOutRows.push(row);
1042
+ else if (changed = !0, row <= endRow) {
1043
+ const newIndex = Math.max(startRow, newFilteredOutRows.length ? newFilteredOutRows[newFilteredOutRows.length - 1] + 1 : startRow);
1044
+ newFilteredOutRows.push(newIndex);
1022
1045
  } else
1023
- l.push(g - (u - d + 1 - m.length));
1046
+ newFilteredOutRows.push(row - (endRow - startRow + 1 - filterOutInRemove.length));
1024
1047
  });
1025
1048
  }
1026
- if (r.id === De.id) {
1027
- const { startRow: d, endRow: u } = r.params.range;
1028
- o.forEach((m) => {
1029
- m >= d ? (a = !0, l.push(m + (u - d + 1))) : l.push(m);
1049
+ if (command.id === InsertRowMutation.id) {
1050
+ const { startRow, endRow } = command.params.range;
1051
+ filteredOutRows.forEach((row) => {
1052
+ row >= startRow ? (changed = !0, newFilteredOutRows.push(row + (endRow - startRow + 1))) : newFilteredOutRows.push(row);
1030
1053
  });
1031
1054
  }
1032
- if (a && (s.filteredOutRows = new Set(l)), r.id === We.id && !(e != null && e.onlyLocal)) {
1033
- const d = this._getExtendRegion(t, n);
1034
- if (d) {
1035
- const u = r.params.cellValue;
1036
- if (u)
1037
- for (let m = d.startColumn; m <= d.endColumn; m++) {
1038
- const g = (c = u == null ? void 0 : u[d.startRow]) == null ? void 0 : c[m];
1039
- if (g && this._cellHasValue(g)) {
1040
- const C = (h = this._univerInstanceService.getUnit(t)) == null ? void 0 : h.getSheetBySheetId(n);
1041
- if (C) {
1042
- const S = ae(d, { down: !0 }, C), F = this._sheetsFilterService.getFilterModel(t, n), _ = F.getRange();
1043
- F.setRange({
1044
- ..._,
1045
- endRow: S.endRow
1046
- }), this._registerRefRange(t, n);
1055
+ if (changed && (filterModel.filteredOutRows = new Set(newFilteredOutRows)), command.id === SetRangeValuesMutation.id && !(options != null && options.onlyLocal)) {
1056
+ const extendRegion = this._getExtendRegion(unitId, subUnitId);
1057
+ if (extendRegion) {
1058
+ const cellValue = command.params.cellValue;
1059
+ if (cellValue)
1060
+ for (let col = extendRegion.startColumn; col <= extendRegion.endColumn; col++) {
1061
+ const cell = (_a4 = cellValue == null ? void 0 : cellValue[extendRegion.startRow]) == null ? void 0 : _a4[col];
1062
+ if (cell && this._cellHasValue(cell)) {
1063
+ const worksheet = (_b = this._univerInstanceService.getUnit(unitId)) == null ? void 0 : _b.getSheetBySheetId(subUnitId);
1064
+ if (worksheet) {
1065
+ const extendedRange = expandToContinuousRange(extendRegion, { down: !0 }, worksheet), filterModel2 = this._sheetsFilterService.getFilterModel(unitId, subUnitId), filterRange = filterModel2.getRange();
1066
+ filterModel2.setRange({
1067
+ ...filterRange,
1068
+ endRow: extendedRange.endRow
1069
+ }), this._registerRefRange(unitId, subUnitId);
1047
1070
  }
1048
1071
  }
1049
1072
  }
@@ -1051,266 +1074,270 @@ let W = class extends V {
1051
1074
  }
1052
1075
  }));
1053
1076
  }
1054
- _getExtendRegion(r, e) {
1055
- var a;
1056
- const t = this._sheetsFilterService.getFilterModel(r, e);
1057
- if (!t)
1077
+ _getExtendRegion(unitId, subUnitId) {
1078
+ var _a4;
1079
+ const filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId);
1080
+ if (!filterModel)
1058
1081
  return null;
1059
- const n = (a = this._univerInstanceService.getUnit(r)) == null ? void 0 : a.getSheetBySheetId(e);
1060
- if (!n)
1082
+ const worksheet = (_a4 = this._univerInstanceService.getUnit(unitId)) == null ? void 0 : _a4.getSheetBySheetId(subUnitId);
1083
+ if (!worksheet)
1061
1084
  return null;
1062
- const s = t.getRange();
1063
- if (!s)
1085
+ const filterRange = filterModel.getRange();
1086
+ if (!filterRange)
1064
1087
  return null;
1065
- const o = n.getRowCount() - 1, l = n.getRowManager();
1066
- for (let c = s.endRow + 1; c <= o; c++)
1067
- if (l.getRowRawVisible(c))
1088
+ const maxRowIndex = worksheet.getRowCount() - 1, rowManager = worksheet.getRowManager();
1089
+ for (let row = filterRange.endRow + 1; row <= maxRowIndex; row++)
1090
+ if (rowManager.getRowRawVisible(row))
1068
1091
  return {
1069
- startRow: c,
1070
- endRow: c,
1071
- startColumn: s.startColumn,
1072
- endColumn: s.endColumn
1092
+ startRow: row,
1093
+ endRow: row,
1094
+ startColumn: filterRange.startColumn,
1095
+ endColumn: filterRange.endColumn
1073
1096
  };
1074
1097
  return null;
1075
1098
  }
1076
1099
  _initErrorHandling() {
1077
- this.disposeWithMe(this._commandService.beforeCommandExecuted((r) => {
1078
- const e = r.params, t = L(this._univerInstanceService);
1079
- if (!t) return;
1080
- const { subUnitId: n, unitId: s } = t, o = this._sheetsFilterService.getFilterModel(s, n);
1081
- if (!o) return;
1082
- const l = o.getRange();
1083
- if (r.id === Ve.id && e.fromRange.startRow <= l.startRow && e.fromRange.endRow < l.endRow && e.fromRange.endRow >= l.startRow)
1100
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
1101
+ const params = command.params, target = getSheetCommandTarget(this._univerInstanceService);
1102
+ if (!target) return;
1103
+ const { subUnitId, unitId } = target, filterModel = this._sheetsFilterService.getFilterModel(unitId, subUnitId);
1104
+ if (!filterModel) return;
1105
+ const filterRange = filterModel.getRange();
1106
+ if (command.id === MoveRowsCommand.id && params.fromRange.startRow <= filterRange.startRow && params.fromRange.endRow < filterRange.endRow && params.fromRange.endRow >= filterRange.startRow)
1084
1107
  throw this._sheetsFilterService.setFilterErrorMsg("sheets-filter.msg.filter-header-forbidden"), new Error("[SheetsFilterController]: Cannot move header row of filter");
1085
1108
  }));
1086
1109
  }
1087
- _cellHasValue(r) {
1088
- const e = Object.values(r);
1089
- return !(e.length === 0 || e.every((t) => t == null));
1090
- }
1091
- };
1092
- W = yt([
1093
- P(0, T),
1094
- P(1, z(Pe)),
1095
- P(2, z(M)),
1096
- P(3, x),
1097
- P(4, z(Ue))
1098
- ], W);
1099
- var At = Object.defineProperty, Tt = Object.getOwnPropertyDescriptor, Nt = (i, r, e, t) => {
1100
- for (var n = t > 1 ? void 0 : t ? Tt(r, e) : r, s = i.length - 1, o; s >= 0; s--)
1101
- (o = i[s]) && (n = (t ? o(r, e, n) : o(n)) || n);
1102
- return t && n && At(r, e, n), n;
1103
- }, oe = (i, r) => (e, t) => r(e, t, i), B;
1104
- let le = (B = class extends ye {
1105
- constructor(i = re, r, e) {
1106
- super(), this._config = i, this._injector = r, this._configService = e;
1107
- const { ...t } = Ae(
1110
+ _cellHasValue(cell) {
1111
+ const values = Object.values(cell);
1112
+ return !(values.length === 0 || values.every((v) => v == null));
1113
+ }
1114
+ }, __name(_a2, "SheetsFilterController"), _a2);
1115
+ SheetsFilterController = __decorateClass$1([
1116
+ __decorateParam$1(0, ICommandService),
1117
+ __decorateParam$1(1, Inject(SheetInterceptorService)),
1118
+ __decorateParam$1(2, Inject(SheetsFilterService)),
1119
+ __decorateParam$1(3, IUniverInstanceService),
1120
+ __decorateParam$1(4, Inject(RefRangeService))
1121
+ ], SheetsFilterController);
1122
+ 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);
1125
+ 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 {
1128
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
1129
+ super(), this._config = _config, this._injector = _injector, this._configService = _configService;
1130
+ const { ...rest } = merge$1(
1108
1131
  {},
1109
- re,
1132
+ defaultPluginConfig,
1110
1133
  this._config
1111
1134
  );
1112
- this._configService.setConfig(tt, t);
1135
+ this._configService.setConfig(SHEETS_FILTER_PLUGIN_CONFIG_KEY, rest);
1113
1136
  }
1114
1137
  onStarting() {
1115
1138
  [
1116
- [M],
1117
- [W]
1118
- ].forEach((i) => this._injector.add(i));
1139
+ [SheetsFilterService],
1140
+ [SheetsFilterController]
1141
+ ].forEach((d) => this._injector.add(d));
1119
1142
  }
1120
1143
  onReady() {
1121
- this._injector.get(W);
1122
- }
1123
- }, w(B, "type", U.UNIVER_SHEET), w(B, "pluginName", Re), B);
1124
- le = Nt([
1125
- oe(1, z(Te)),
1126
- oe(2, Ne)
1127
- ], le);
1128
- const xt = {
1144
+ this._injector.get(SheetsFilterController);
1145
+ }
1146
+ }, __name(_a3, "UniverSheetsFilterPlugin"), __publicField(_a3, "type", UniverInstanceType.UNIVER_SHEET), __publicField(_a3, "pluginName", SHEET_FILTER_SNAPSHOT_ID), _a3);
1147
+ UniverSheetsFilterPlugin = __decorateClass([
1148
+ __decorateParam(1, Inject(Injector)),
1149
+ __decorateParam(2, IConfigService)
1150
+ ], UniverSheetsFilterPlugin);
1151
+ const SetSheetFilterRangeCommand = {
1129
1152
  id: "sheet.command.set-filter-range",
1130
- type: E.COMMAND,
1131
- handler: (i, r) => {
1132
- const e = i.get(M), t = i.get(T), n = i.get(j), s = i.get(x), { unitId: o, subUnitId: l, range: a } = r;
1133
- if (!L(s, r) || e.getFilterModel(o, l)) return !1;
1134
- if (a.endRow === a.startRow) {
1135
- const m = i.get(xe), g = i.get(Ie);
1136
- return m.emit(g.t("sheets-filter.command.not-valid-filter-range")), !1;
1153
+ type: CommandType.COMMAND,
1154
+ handler: /* @__PURE__ */ __name((accessor, params) => {
1155
+ const sheetsFilterService = accessor.get(SheetsFilterService), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), instanceSrv = accessor.get(IUniverInstanceService), { unitId, subUnitId, range } = params;
1156
+ if (!getSheetCommandTarget(instanceSrv, params) || sheetsFilterService.getFilterModel(unitId, subUnitId)) return !1;
1157
+ if (range.endRow === range.startRow) {
1158
+ const errorService = accessor.get(ErrorService), localeService = accessor.get(LocaleService);
1159
+ return errorService.emit(localeService.t("sheets-filter.command.not-valid-filter-range")), !1;
1137
1160
  }
1138
- const d = { id: R.id, params: { unitId: o, subUnitId: l, range: a } }, u = t.syncExecuteCommand(d.id, d.params);
1139
- return u && n.pushUndoRedo({
1140
- unitID: o,
1141
- undoMutations: [{ id: O.id, params: { unitId: o, subUnitId: l } }],
1142
- redoMutations: [d]
1143
- }), u;
1144
- }
1145
- }, It = {
1161
+ const redoMutation = { id: SetSheetsFilterRangeMutation.id, params: { unitId, subUnitId, range } }, result = commandService.syncExecuteCommand(redoMutation.id, redoMutation.params);
1162
+ return result && undoRedoService.pushUndoRedo({
1163
+ unitID: unitId,
1164
+ undoMutations: [{ id: RemoveSheetsFilterMutation.id, params: { unitId, subUnitId } }],
1165
+ redoMutations: [redoMutation]
1166
+ }), result;
1167
+ }, "handler")
1168
+ }, RemoveSheetFilterCommand = {
1146
1169
  id: "sheet.command.remove-sheet-filter",
1147
- type: E.COMMAND,
1148
- handler: (i, r) => {
1149
- const e = i.get(x), t = i.get(M), n = i.get(T), s = i.get(j), o = L(e, r);
1150
- if (!o) return !1;
1151
- const { unitId: l, subUnitId: a } = o, c = t.getFilterModel(l, a);
1152
- if (!c) return !1;
1153
- const h = c == null ? void 0 : c.serialize(), d = $t(l, a, h), u = n.syncExecuteCommand(O.id, { unitId: l, subUnitId: a });
1154
- return u && s.pushUndoRedo({
1155
- unitID: l,
1156
- undoMutations: d,
1157
- redoMutations: [{ id: O.id, params: { unitId: l, subUnitId: a } }]
1158
- }), u;
1159
- }
1160
- }, Ht = {
1170
+ type: CommandType.COMMAND,
1171
+ handler: /* @__PURE__ */ __name((accessor, params) => {
1172
+ const univerInstanceService = accessor.get(IUniverInstanceService), sheetsFilterService = accessor.get(SheetsFilterService), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), commandTarget = getSheetCommandTarget(univerInstanceService, params);
1173
+ if (!commandTarget) return !1;
1174
+ const { unitId, subUnitId } = commandTarget, filterModel = sheetsFilterService.getFilterModel(unitId, subUnitId);
1175
+ if (!filterModel) return !1;
1176
+ const autoFilter = filterModel == null ? void 0 : filterModel.serialize(), undoMutations = destructFilterModel(unitId, subUnitId, autoFilter), result = commandService.syncExecuteCommand(RemoveSheetsFilterMutation.id, { unitId, subUnitId });
1177
+ return result && undoRedoService.pushUndoRedo({
1178
+ unitID: unitId,
1179
+ undoMutations,
1180
+ redoMutations: [{ id: RemoveSheetsFilterMutation.id, params: { unitId, subUnitId } }]
1181
+ }), result;
1182
+ }, "handler")
1183
+ }, SmartToggleSheetsFilterCommand = {
1161
1184
  id: "sheet.command.smart-toggle-filter",
1162
- type: E.COMMAND,
1163
- handler: async (i) => {
1164
- const r = i.get(x), e = i.get(M), t = i.get(T), n = r.getCurrentUnitForType(U.UNIVER_SHEET), s = n == null ? void 0 : n.getActiveSheet();
1165
- if (!s || !n) return !1;
1166
- const o = n.getUnitId(), l = s.getSheetId();
1167
- if (e.getFilterModel(o, l))
1168
- return t.executeCommand(It.id, { unitId: o, subUnitId: l });
1169
- const h = i.get(Ye).getCurrentLastSelection();
1170
- if (!h) return !1;
1171
- const d = h.range, u = Ke(h) ? ae(d, { left: !0, right: !0, up: !0, down: !0 }, s) : d;
1172
- return t.executeCommand(xt.id, {
1173
- unitId: o,
1174
- subUnitId: l,
1175
- range: u
1185
+ type: CommandType.COMMAND,
1186
+ handler: /* @__PURE__ */ __name(async (accessor) => {
1187
+ const univerInstanceService = accessor.get(IUniverInstanceService), sheetsFilterService = accessor.get(SheetsFilterService), commandService = accessor.get(ICommandService), currentWorkbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), currentWorksheet = currentWorkbook == null ? void 0 : currentWorkbook.getActiveSheet();
1188
+ if (!currentWorksheet || !currentWorkbook) return !1;
1189
+ const unitId = currentWorkbook.getUnitId(), subUnitId = currentWorksheet.getSheetId();
1190
+ if (sheetsFilterService.getFilterModel(unitId, subUnitId))
1191
+ return commandService.executeCommand(RemoveSheetFilterCommand.id, { unitId, subUnitId });
1192
+ const lastSelection = accessor.get(SheetsSelectionsService).getCurrentLastSelection();
1193
+ if (!lastSelection) return !1;
1194
+ const startRange = lastSelection.range, targetFilterRange = isSingleCellSelection(lastSelection) ? expandToContinuousRange(startRange, { left: !0, right: !0, up: !0, down: !0 }, currentWorksheet) : startRange;
1195
+ return commandService.executeCommand(SetSheetFilterRangeCommand.id, {
1196
+ unitId,
1197
+ subUnitId,
1198
+ range: targetFilterRange
1176
1199
  });
1177
- }
1178
- }, Dt = {
1200
+ }, "handler")
1201
+ }, SetSheetsFilterCriteriaCommand = {
1179
1202
  id: "sheet.command.set-filter-criteria",
1180
- type: E.COMMAND,
1181
- handler: (i, r) => {
1182
- const e = i.get(M), t = i.get(T), n = i.get(j), { unitId: s, subUnitId: o, col: l, criteria: a } = r, c = e.getFilterModel(s, o);
1183
- if (!c) return !1;
1184
- const h = c.getRange();
1185
- if (!h || l < h.startColumn || l > h.endColumn) return !1;
1186
- const d = c.getFilterColumn(l), u = Ut(s, o, l, d), m = {
1187
- id: p.id,
1203
+ type: CommandType.COMMAND,
1204
+ handler: /* @__PURE__ */ __name((accessor, params) => {
1205
+ const sheetsFilterService = accessor.get(SheetsFilterService), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), { unitId, subUnitId, col, criteria } = params, filterModel = sheetsFilterService.getFilterModel(unitId, subUnitId);
1206
+ if (!filterModel) return !1;
1207
+ const range = filterModel.getRange();
1208
+ if (!range || col < range.startColumn || col > range.endColumn) return !1;
1209
+ const filterColumn = filterModel.getFilterColumn(col), undoMutation = destructFilterColumn(unitId, subUnitId, col, filterColumn), redoMutation = {
1210
+ id: SetSheetsFilterCriteriaMutation.id,
1188
1211
  params: {
1189
- unitId: s,
1190
- subUnitId: o,
1191
- col: l,
1192
- criteria: a
1212
+ unitId,
1213
+ subUnitId,
1214
+ col,
1215
+ criteria
1193
1216
  }
1194
- }, g = t.syncExecuteCommand(m.id, m.params);
1195
- return g && n.pushUndoRedo({
1196
- unitID: s,
1197
- undoMutations: [u],
1198
- redoMutations: [m]
1199
- }), g;
1200
- }
1201
- }, Wt = {
1217
+ }, result = commandService.syncExecuteCommand(redoMutation.id, redoMutation.params);
1218
+ return result && undoRedoService.pushUndoRedo({
1219
+ unitID: unitId,
1220
+ undoMutations: [undoMutation],
1221
+ redoMutations: [redoMutation]
1222
+ }), result;
1223
+ }, "handler")
1224
+ }, ClearSheetsFilterCriteriaCommand = {
1202
1225
  id: "sheet.command.clear-filter-criteria",
1203
- type: E.COMMAND,
1204
- handler: (i, r) => {
1205
- const e = i.get(M), t = i.get(j), n = i.get(T), s = i.get(x), o = L(s, r);
1206
- if (!o) return !1;
1207
- const { unitId: l, subUnitId: a } = o, c = e.getFilterModel(o.unitId, o.subUnitId);
1208
- if (!c) return !1;
1209
- const h = c.serialize(), d = Ce(l, a, h), u = Pt(l, a, h);
1210
- return $e(u, n).result ? (t.pushUndoRedo({
1211
- unitID: l,
1212
- undoMutations: d,
1213
- redoMutations: u
1226
+ type: CommandType.COMMAND,
1227
+ handler: /* @__PURE__ */ __name((accessor, params) => {
1228
+ const sheetsFilterService = accessor.get(SheetsFilterService), undoRedoService = accessor.get(IUndoRedoService), commandService = accessor.get(ICommandService), instanceSrv = accessor.get(IUniverInstanceService), commandTarget = getSheetCommandTarget(instanceSrv, params);
1229
+ if (!commandTarget) return !1;
1230
+ const { unitId, subUnitId } = commandTarget, filterModel = sheetsFilterService.getFilterModel(commandTarget.unitId, commandTarget.subUnitId);
1231
+ if (!filterModel) return !1;
1232
+ const autoFilter = filterModel.serialize(), undoMutations = destructFilterCriteria(unitId, subUnitId, autoFilter), redoMutations = generateRemoveCriteriaMutations(unitId, subUnitId, autoFilter);
1233
+ return sequenceExecute(redoMutations, commandService).result ? (undoRedoService.pushUndoRedo({
1234
+ unitID: unitId,
1235
+ undoMutations,
1236
+ redoMutations
1214
1237
  }), !0) : !1;
1215
- }
1216
- }, Vt = {
1238
+ }, "handler")
1239
+ }, ReCalcSheetsFilterCommand = {
1217
1240
  id: "sheet.command.re-calc-filter",
1218
- type: E.COMMAND,
1219
- handler: (i, r) => {
1220
- const e = i.get(M), t = i.get(T), n = i.get(x), s = L(n, r);
1221
- if (!s) return !1;
1222
- const { unitId: o, subUnitId: l } = s;
1223
- return e.getFilterModel(s.unitId, s.subUnitId) ? t.executeCommand(H.id, { unitId: o, subUnitId: l }) : !1;
1224
- }
1241
+ type: CommandType.COMMAND,
1242
+ handler: /* @__PURE__ */ __name((accessor, params) => {
1243
+ const sheetsFilterService = accessor.get(SheetsFilterService), commandService = accessor.get(ICommandService), instanceSrv = accessor.get(IUniverInstanceService), commandTarget = getSheetCommandTarget(instanceSrv, params);
1244
+ if (!commandTarget) return !1;
1245
+ const { unitId, subUnitId } = commandTarget;
1246
+ return sheetsFilterService.getFilterModel(commandTarget.unitId, commandTarget.subUnitId) ? commandService.executeCommand(ReCalcSheetsFilterMutation.id, { unitId, subUnitId }) : !1;
1247
+ }, "handler")
1225
1248
  };
1226
- function $t(i, r, e) {
1227
- const t = [], n = {
1228
- id: R.id,
1249
+ function destructFilterModel(unitId, subUnitId, autoFilter) {
1250
+ const mutations = [], setFilterMutation = {
1251
+ id: SetSheetsFilterRangeMutation.id,
1229
1252
  params: {
1230
- unitId: i,
1231
- subUnitId: r,
1232
- range: e.ref
1253
+ unitId,
1254
+ subUnitId,
1255
+ range: autoFilter.ref
1233
1256
  }
1234
1257
  };
1235
- return t.push(n), Ce(i, r, e).forEach((o) => t.push(o)), t;
1258
+ return mutations.push(setFilterMutation), destructFilterCriteria(unitId, subUnitId, autoFilter).forEach((m) => mutations.push(m)), mutations;
1236
1259
  }
1237
- function Ce(i, r, e) {
1238
- var n;
1239
- const t = [];
1240
- return (n = e.filterColumns) == null || n.forEach((s) => {
1241
- const o = {
1242
- id: p.id,
1260
+ __name(destructFilterModel, "destructFilterModel");
1261
+ function destructFilterCriteria(unitId, subUnitId, autoFilter) {
1262
+ var _a4;
1263
+ const mutations = [];
1264
+ return (_a4 = autoFilter.filterColumns) == null || _a4.forEach((filterColumn) => {
1265
+ const setFilterCriteriaMutation = {
1266
+ id: SetSheetsFilterCriteriaMutation.id,
1243
1267
  params: {
1244
- unitId: i,
1245
- subUnitId: r,
1246
- col: s.colId,
1247
- criteria: s
1268
+ unitId,
1269
+ subUnitId,
1270
+ col: filterColumn.colId,
1271
+ criteria: filterColumn
1248
1272
  }
1249
1273
  };
1250
- t.push(o);
1251
- }), t;
1274
+ mutations.push(setFilterCriteriaMutation);
1275
+ }), mutations;
1252
1276
  }
1253
- function Pt(i, r, e) {
1254
- var n;
1255
- const t = [];
1256
- return (n = e.filterColumns) == null || n.forEach((s) => {
1257
- const o = {
1258
- id: p.id,
1277
+ __name(destructFilterCriteria, "destructFilterCriteria");
1278
+ function generateRemoveCriteriaMutations(unitId, subUnitId, autoFilter) {
1279
+ var _a4;
1280
+ const mutations = [];
1281
+ return (_a4 = autoFilter.filterColumns) == null || _a4.forEach((filterColumn) => {
1282
+ const removeFilterCriteriaMutation = {
1283
+ id: SetSheetsFilterCriteriaMutation.id,
1259
1284
  params: {
1260
- unitId: i,
1261
- subUnitId: r,
1262
- col: s.colId,
1285
+ unitId,
1286
+ subUnitId,
1287
+ col: filterColumn.colId,
1263
1288
  criteria: null
1264
1289
  }
1265
1290
  };
1266
- t.push(o);
1267
- }), t;
1291
+ mutations.push(removeFilterCriteriaMutation);
1292
+ }), mutations;
1268
1293
  }
1269
- function Ut(i, r, e, t) {
1270
- if (!t)
1294
+ __name(generateRemoveCriteriaMutations, "generateRemoveCriteriaMutations");
1295
+ function destructFilterColumn(unitId, subUnitId, colId, filterColumn) {
1296
+ if (!filterColumn)
1271
1297
  return {
1272
- id: p.id,
1298
+ id: SetSheetsFilterCriteriaMutation.id,
1273
1299
  params: {
1274
- unitId: i,
1275
- subUnitId: r,
1276
- col: e,
1300
+ unitId,
1301
+ subUnitId,
1302
+ col: colId,
1277
1303
  criteria: null
1278
1304
  }
1279
1305
  };
1280
- const n = t.serialize();
1306
+ const serialize = filterColumn.serialize();
1281
1307
  return {
1282
- id: p.id,
1308
+ id: SetSheetsFilterCriteriaMutation.id,
1283
1309
  params: {
1284
- unitId: i,
1285
- subUnitId: r,
1286
- col: e,
1287
- criteria: n
1310
+ unitId,
1311
+ subUnitId,
1312
+ col: colId,
1313
+ criteria: serialize
1288
1314
  }
1289
1315
  };
1290
1316
  }
1317
+ __name(destructFilterColumn, "destructFilterColumn");
1291
1318
  export {
1292
- Wt as ClearSheetsFilterCriteriaCommand,
1293
- N as CustomFilterOperator,
1294
- rt as FILTER_MUTATIONS,
1295
- ht as FilterColumn,
1296
- D as FilterModel,
1297
- Vt as ReCalcSheetsFilterCommand,
1298
- H as ReCalcSheetsFilterMutation,
1299
- It as RemoveSheetFilterCommand,
1300
- O as RemoveSheetsFilterMutation,
1301
- Re as SHEET_FILTER_SNAPSHOT_ID,
1302
- xt as SetSheetFilterRangeCommand,
1303
- Dt as SetSheetsFilterCriteriaCommand,
1304
- p as SetSheetsFilterCriteriaMutation,
1305
- R as SetSheetsFilterRangeMutation,
1306
- M as SheetsFilterService,
1307
- Ht as SmartToggleSheetsFilterCommand,
1308
- le as UniverSheetsFilterPlugin,
1309
- lt as equals,
1310
- ne as getCustomFilterFn,
1311
- nt as greaterThan,
1312
- it as greaterThanOrEqualTo,
1313
- st as lessThan,
1314
- ot as lessThanOrEqualTo,
1315
- fe as notEquals
1319
+ ClearSheetsFilterCriteriaCommand,
1320
+ CustomFilterOperator,
1321
+ FILTER_MUTATIONS,
1322
+ FilterColumn,
1323
+ FilterModel,
1324
+ ReCalcSheetsFilterCommand,
1325
+ ReCalcSheetsFilterMutation,
1326
+ RemoveSheetFilterCommand,
1327
+ RemoveSheetsFilterMutation,
1328
+ SHEET_FILTER_SNAPSHOT_ID,
1329
+ SetSheetFilterRangeCommand,
1330
+ SetSheetsFilterCriteriaCommand,
1331
+ SetSheetsFilterCriteriaMutation,
1332
+ SetSheetsFilterRangeMutation,
1333
+ SheetsFilterService,
1334
+ SmartToggleSheetsFilterCommand,
1335
+ UniverSheetsFilterPlugin,
1336
+ equals,
1337
+ getCustomFilterFn,
1338
+ greaterThan,
1339
+ greaterThanOrEqualTo,
1340
+ lessThan,
1341
+ lessThanOrEqualTo,
1342
+ notEquals
1316
1343
  };