@univerjs/sheets-filter 0.4.2 → 0.5.0-beta.0

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