@univerjs/sheets-filter 0.2.4 → 0.2.6

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