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