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