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