@univerjs/sheets-filter 0.4.1 → 0.4.2-nightly.202410301606
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/es/facade.js +133 -0
- package/lib/es/index.js +77 -583
- package/lib/sheets-filter.command-CL_iGKJ6.mjs +713 -0
- package/lib/types/commands/commands/sheets-filter.command.d.ts +57 -0
- package/lib/types/facade/f-filter.d.ts +54 -0
- package/lib/types/facade/f-range.d.ts +25 -0
- package/lib/types/facade/f-worksheet.d.ts +9 -0
- package/lib/types/facade/index.d.ts +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/models/filter-model.d.ts +1 -1
- package/lib/umd/facade.js +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +10 -13
- package/LICENSE +0 -176
- package/lib/cjs/index.js +0 -1
package/lib/es/facade.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
3
|
+
import { Inject, Injector, ICommandService } from "@univerjs/core";
|
|
4
|
+
import { FRange, FWorksheet } from "@univerjs/sheets/facade";
|
|
5
|
+
import { r as SetSheetsFilterCriteriaCommand, m as ClearSheetsFilterCriteriaCommand, p as RemoveSheetFilterCommand, q as SetSheetFilterRangeCommand, a as SheetsFilterService } from "../sheets-filter.command-CL_iGKJ6.mjs";
|
|
6
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
7
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
8
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
9
|
+
return kind && result && __defProp2(target, key, result), result;
|
|
10
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a;
|
|
11
|
+
let FFilter = (_a = class {
|
|
12
|
+
constructor(_workbook, _worksheet, _filterModel, _injector, _commandSrv) {
|
|
13
|
+
this._workbook = _workbook, this._worksheet = _worksheet, this._filterModel = _filterModel, this._injector = _injector, this._commandSrv = _commandSrv;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get the filtered out rows by this filter.
|
|
17
|
+
* @returns {number[]} Filtered out rows by this filter.
|
|
18
|
+
*/
|
|
19
|
+
getFilteredOutRows() {
|
|
20
|
+
return Array.from(this._filterModel.filteredOutRows).sort();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the filter criteria of a column.
|
|
24
|
+
* @param {number} col The column number.
|
|
25
|
+
* @returns {Nullable<IFilterColumn>} The filter criteria of the column.
|
|
26
|
+
*/
|
|
27
|
+
getColumnFilterCriteria(col) {
|
|
28
|
+
var _a2;
|
|
29
|
+
return (_a2 = this._filterModel.getFilterColumn(col)) == null ? void 0 : _a2.getColumnData();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Clear the filter criteria of a column.
|
|
33
|
+
* @param {number} col The column number.
|
|
34
|
+
* @returns {Promise<boolean>} If the filter criteria is cleared.
|
|
35
|
+
*/
|
|
36
|
+
removeColumnFilterCriteria(col) {
|
|
37
|
+
return this._commandSrv.executeCommand(SetSheetsFilterCriteriaCommand.id, {
|
|
38
|
+
unitId: this._workbook.getUnitId(),
|
|
39
|
+
subUnitId: this._worksheet.getSheetId(),
|
|
40
|
+
col,
|
|
41
|
+
criteria: null
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Set the filter criteria of a column.
|
|
46
|
+
* @param {number} col The column number.
|
|
47
|
+
* @param {ISetSheetsFilterCriteriaCommandParams['criteria']} criteria The new filter criteria.
|
|
48
|
+
* @returns {Promise<boolean>} If the filter criteria is set.
|
|
49
|
+
*/
|
|
50
|
+
setColumnFilterCriteria(col, criteria) {
|
|
51
|
+
return this._commandSrv.executeCommand(SetSheetsFilterCriteriaCommand.id, {
|
|
52
|
+
unitId: this._workbook.getUnitId(),
|
|
53
|
+
subUnitId: this._worksheet.getSheetId(),
|
|
54
|
+
col,
|
|
55
|
+
criteria
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get the range of the filter.
|
|
60
|
+
* @returns {FRange} The range of the filter.
|
|
61
|
+
*/
|
|
62
|
+
getRange() {
|
|
63
|
+
const range = this._filterModel.getRange();
|
|
64
|
+
return this._injector.createInstance(FRange, this._workbook, this._worksheet, range);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Remove the filter criteria of all columns.
|
|
68
|
+
* @returns {Promise<boolean>} If the filter criteria is removed.
|
|
69
|
+
*/
|
|
70
|
+
removeFilterCriteria() {
|
|
71
|
+
return this._commandSrv.executeCommand(ClearSheetsFilterCriteriaCommand.id);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Remove the filter from the worksheet.
|
|
75
|
+
* @returns {Promise<boolean>} If the filter is removed.
|
|
76
|
+
*/
|
|
77
|
+
remove() {
|
|
78
|
+
return this._commandSrv.executeCommand(RemoveSheetFilterCommand.id, {
|
|
79
|
+
unitId: this._workbook.getUnitId(),
|
|
80
|
+
subUnitId: this._worksheet.getSheetId()
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}, __name(_a, "FFilter"), _a);
|
|
84
|
+
FFilter = __decorateClass([
|
|
85
|
+
__decorateParam(3, Inject(Injector)),
|
|
86
|
+
__decorateParam(4, ICommandService)
|
|
87
|
+
], FFilter);
|
|
88
|
+
const _FRangeFilter = class _FRangeFilter extends FRange {
|
|
89
|
+
async createFilter() {
|
|
90
|
+
return this._getFilterModel() || !await this._commandService.executeCommand(SetSheetFilterRangeCommand.id, {
|
|
91
|
+
unitId: this._workbook.getUnitId(),
|
|
92
|
+
subUnitId: this._worksheet.getSheetId(),
|
|
93
|
+
range: this._range
|
|
94
|
+
}) ? null : this.getFilter();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get the filter for the current range's worksheet.
|
|
98
|
+
*
|
|
99
|
+
* @return {FFilter | null} The interface class to handle the filter. If the worksheet does not have a filter,
|
|
100
|
+
* this method would return `null`.
|
|
101
|
+
*/
|
|
102
|
+
getFilter() {
|
|
103
|
+
const filterModel = this._getFilterModel();
|
|
104
|
+
return filterModel ? this._injector.createInstance(FFilter, this._workbook, this._worksheet, filterModel) : null;
|
|
105
|
+
}
|
|
106
|
+
_getFilterModel() {
|
|
107
|
+
return this._injector.get(SheetsFilterService).getFilterModel(
|
|
108
|
+
this._workbook.getUnitId(),
|
|
109
|
+
this._worksheet.getSheetId()
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
__name(_FRangeFilter, "FRangeFilter");
|
|
114
|
+
let FRangeFilter = _FRangeFilter;
|
|
115
|
+
FRange.extend(FRangeFilter);
|
|
116
|
+
const _FWorksheetFilter = class _FWorksheetFilter extends FWorksheet {
|
|
117
|
+
getFilter() {
|
|
118
|
+
const filterModel = this._getFilterModel();
|
|
119
|
+
return filterModel ? this._injector.createInstance(FFilter, this._workbook, this._worksheet, filterModel) : null;
|
|
120
|
+
}
|
|
121
|
+
_getFilterModel() {
|
|
122
|
+
return this._injector.get(SheetsFilterService).getFilterModel(
|
|
123
|
+
this._workbook.getUnitId(),
|
|
124
|
+
this._worksheet.getSheetId()
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
__name(_FWorksheetFilter, "FWorksheetFilter");
|
|
129
|
+
let FWorksheetFilter = _FWorksheetFilter;
|
|
130
|
+
FWorksheet.extend(FWorksheetFilter);
|
|
131
|
+
export {
|
|
132
|
+
FFilter
|
|
133
|
+
};
|