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