@univerjs/sheets-filter 0.2.5 → 0.2.7

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