@univerjs/sheets-filter 0.1.14 → 0.1.16

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