@univerjs/sheets-filter-ui 1.3.1 → 1.5.0

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.
Files changed (74) hide show
  1. package/README.md +18 -7
  2. package/lib/cjs/config-BF97qkoE.js +309 -0
  3. package/lib/cjs/index.js +217 -465
  4. package/lib/cjs/locale/ar-SA.js +1 -2
  5. package/lib/cjs/locale/ca-ES.js +1 -2
  6. package/lib/cjs/locale/de-DE.js +1 -2
  7. package/lib/cjs/locale/en-US.js +1 -2
  8. package/lib/cjs/locale/es-ES.js +1 -2
  9. package/lib/cjs/locale/fa-IR.js +1 -2
  10. package/lib/cjs/locale/fr-FR.js +1 -2
  11. package/lib/cjs/locale/id-ID.js +1 -2
  12. package/lib/cjs/locale/it-IT.js +1 -2
  13. package/lib/cjs/locale/ja-JP.js +1 -2
  14. package/lib/cjs/locale/ko-KR.js +1 -2
  15. package/lib/cjs/locale/pl-PL.js +1 -2
  16. package/lib/cjs/locale/pt-BR.js +1 -2
  17. package/lib/cjs/locale/ru-RU.js +1 -2
  18. package/lib/cjs/locale/sk-SK.js +1 -2
  19. package/lib/cjs/locale/vi-VN.js +1 -2
  20. package/lib/cjs/locale/zh-CN.js +1 -2
  21. package/lib/cjs/locale/zh-HK.js +1 -2
  22. package/lib/cjs/locale/zh-TW.js +1 -2
  23. package/lib/cjs/worker.js +39 -0
  24. package/lib/config-CbqvVwlO.js +244 -0
  25. package/lib/es/config-CbqvVwlO.js +244 -0
  26. package/lib/es/index.js +110 -352
  27. package/lib/es/locale/ar-SA.js +1 -2
  28. package/lib/es/locale/ca-ES.js +1 -2
  29. package/lib/es/locale/de-DE.js +1 -2
  30. package/lib/es/locale/en-US.js +1 -2
  31. package/lib/es/locale/es-ES.js +1 -2
  32. package/lib/es/locale/fa-IR.js +1 -2
  33. package/lib/es/locale/fr-FR.js +1 -2
  34. package/lib/es/locale/id-ID.js +1 -2
  35. package/lib/es/locale/it-IT.js +1 -2
  36. package/lib/es/locale/ja-JP.js +1 -2
  37. package/lib/es/locale/ko-KR.js +1 -2
  38. package/lib/es/locale/pl-PL.js +1 -2
  39. package/lib/es/locale/pt-BR.js +1 -2
  40. package/lib/es/locale/ru-RU.js +1 -2
  41. package/lib/es/locale/sk-SK.js +1 -2
  42. package/lib/es/locale/vi-VN.js +1 -2
  43. package/lib/es/locale/zh-CN.js +1 -2
  44. package/lib/es/locale/zh-HK.js +1 -2
  45. package/lib/es/locale/zh-TW.js +1 -2
  46. package/lib/es/worker.js +33 -0
  47. package/lib/index.js +110 -352
  48. package/lib/locale/ar-SA.js +1 -2
  49. package/lib/locale/ca-ES.js +1 -2
  50. package/lib/locale/de-DE.js +1 -2
  51. package/lib/locale/en-US.js +1 -2
  52. package/lib/locale/es-ES.js +1 -2
  53. package/lib/locale/fa-IR.js +1 -2
  54. package/lib/locale/fr-FR.js +1 -2
  55. package/lib/locale/id-ID.js +1 -2
  56. package/lib/locale/it-IT.js +1 -2
  57. package/lib/locale/ja-JP.js +1 -2
  58. package/lib/locale/ko-KR.js +1 -2
  59. package/lib/locale/pl-PL.js +1 -2
  60. package/lib/locale/pt-BR.js +1 -2
  61. package/lib/locale/ru-RU.js +1 -2
  62. package/lib/locale/sk-SK.js +1 -2
  63. package/lib/locale/vi-VN.js +1 -2
  64. package/lib/locale/zh-CN.js +1 -2
  65. package/lib/locale/zh-HK.js +1 -2
  66. package/lib/locale/zh-TW.js +1 -2
  67. package/lib/types/__tests__/data.d.ts +2 -2
  68. package/lib/types/index.d.ts +0 -1
  69. package/lib/types/services/sheets-filter-panel.service.d.ts +1 -1
  70. package/lib/types/worker/generate-filter-values.service.d.ts +1 -1
  71. package/lib/types/worker.d.ts +16 -0
  72. package/lib/umd/index.js +5 -5
  73. package/lib/worker.js +33 -0
  74. package/package.json +21 -16
package/README.md CHANGED
@@ -8,9 +8,9 @@
8
8
 
9
9
  ## Package Overview
10
10
 
11
- | Package | UMD global | CSS | Locales | Facade entry |
12
- | --- | --- | :---: | :---: | :---: |
13
- | `@univerjs/sheets-filter-ui` | `UniverSheetsFilterUi` | Yes | Yes | No |
11
+ | Package | UMD global | CSS | Locales | Facade entry | Worker entry |
12
+ | --- | --- | :---: | :---: | :---: | :---: |
13
+ | `@univerjs/sheets-filter-ui` | `UniverSheetsFilterUi` | Yes | Yes | No | Yes |
14
14
 
15
15
  ## Installation
16
16
 
@@ -20,10 +20,10 @@ pnpm add @univerjs/sheets-filter-ui
20
20
  npm install @univerjs/sheets-filter-ui
21
21
  ```
22
22
 
23
- Keep all `@univerjs/*` packages on the same version.
24
-
25
23
  ## Usage
26
24
 
25
+ Start with the [integration setup](https://docs.univer.ai/) for your document type, including its required plugins, styles, and locale resources. The snippet below assumes that setup is complete.
26
+
27
27
  ```ts
28
28
  import '@univerjs/sheets-filter-ui/lib/index.css';
29
29
  import EnUS from '@univerjs/sheets-filter-ui/locale/en-US';
@@ -34,11 +34,22 @@ univer.registerPlugin(UniverSheetsFilterUIPlugin);
34
34
  // Merge EnUS into your Univer locale map when this package contributes UI text.
35
35
  ```
36
36
 
37
- Exported plugin classes:
37
+ Main-thread plugin classes:
38
38
 
39
39
  - `UniverSheetsFilterUIPlugin`
40
40
  - `UniverSheetsFilterMobileUIPlugin`
41
- - `UniverSheetsFilterUIWorkerPlugin`
41
+
42
+ ### Worker usage
43
+
44
+ On the main thread, import `UniverSheetsFilterUIPlugin` from `@univerjs/sheets-filter-ui`.
45
+
46
+ In the worker entry, import `UniverSheetsFilterUIWorkerPlugin` from `@univerjs/sheets-filter-ui/worker`:
47
+
48
+ ```ts
49
+ import { UniverSheetsFilterUIWorkerPlugin } from '@univerjs/sheets-filter-ui/worker';
50
+
51
+ univer.registerPlugin(UniverSheetsFilterUIWorkerPlugin);
52
+ ```
42
53
 
43
54
  ## Resources
44
55
 
@@ -0,0 +1,309 @@
1
+ let _univerjs_core = require("@univerjs/core");
2
+ let _univerjs_sheets_filter = require("@univerjs/sheets-filter");
3
+
4
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
5
+ function __decorateParam(paramIndex, decorator) {
6
+ return function(target, key) {
7
+ decorator(target, key, paramIndex);
8
+ };
9
+ }
10
+
11
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
12
+ function __decorate(decorators, target, key, desc) {
13
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
15
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
16
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
17
+ }
18
+
19
+ // src/worker/generate-filter-values.service.ts
20
+ const SHEETS_GENERATE_FILTER_VALUES_SERVICE_NAME = "sheets-filter.generate-filter-values.service";
21
+ const ISheetsGenerateFilterValuesService = (0, _univerjs_core.createIdentifier)(SHEETS_GENERATE_FILTER_VALUES_SERVICE_NAME);
22
+ let SheetsGenerateFilterValuesService = class SheetsGenerateFilterValuesService extends _univerjs_core.Disposable {
23
+ constructor(_localeService, _univerInstanceService, _logService) {
24
+ super();
25
+ this._localeService = _localeService;
26
+ this._univerInstanceService = _univerInstanceService;
27
+ this._logService = _logService;
28
+ }
29
+ async getFilterValues(params) {
30
+ var _this$_univerInstance;
31
+ const { unitId, subUnitId, filteredOutRowsByOtherColumns, filterColumn, filters, blankChecked, iterateRange, alreadyChecked } = params;
32
+ const workbook = this._univerInstanceService.getUnit(unitId);
33
+ const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
34
+ if (!workbook || !worksheet) return [];
35
+ this._logService.debug("[SheetsGenerateFilterValuesService]", "getFilterValues for", {
36
+ unitId,
37
+ subUnitId
38
+ });
39
+ return getFilterTreeByValueItems(filters, this._localeService, iterateRange, worksheet, new Set(filteredOutRowsByOtherColumns), filterColumn, new Set(alreadyChecked.map(String)), blankChecked, workbook.getStyles());
40
+ }
41
+ };
42
+ SheetsGenerateFilterValuesService = __decorate([
43
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
44
+ __decorateParam(1, _univerjs_core.IUniverInstanceService),
45
+ __decorateParam(2, _univerjs_core.ILogService)
46
+ ], SheetsGenerateFilterValuesService);
47
+ function getFilterTreeByValueItems(filters, localeService, iterateRange, worksheet, filteredOutRowsByOtherColumns, filterColumn, alreadyChecked, blankChecked, styles) {
48
+ var _filterColumn$filtere;
49
+ const items = /* @__PURE__ */ new Map();
50
+ const treeMap = /* @__PURE__ */ new Map();
51
+ const DefaultPattern = "yyyy-mm-dd";
52
+ const EmptyKey = "empty";
53
+ const isNeedClearCheckedStatus = !filters && ((filterColumn === null || filterColumn === void 0 ? void 0 : filterColumn.filterBy) === _univerjs_sheets_filter.FilterBy.COLORS || (filterColumn === null || filterColumn === void 0 ? void 0 : filterColumn.filterBy) === _univerjs_sheets_filter.FilterBy.CONDITIONS) && ((_filterColumn$filtere = filterColumn.filteredOutRows) === null || _filterColumn$filtere === void 0 ? void 0 : _filterColumn$filtere.size);
54
+ let emptyCount = 0;
55
+ for (const cell of worksheet.iterateByColumn(iterateRange, false, false)) {
56
+ const { row, rowSpan = 1 } = cell;
57
+ let rowIndex = 0;
58
+ while (rowIndex < rowSpan) {
59
+ var _cell$value, _styles$get, _cell$value2;
60
+ const targetRow = row + rowIndex;
61
+ if (filteredOutRowsByOtherColumns.has(targetRow)) {
62
+ rowIndex++;
63
+ continue;
64
+ }
65
+ const value = (cell === null || cell === void 0 ? void 0 : cell.value) ? (0, _univerjs_core.extractPureTextFromCell)(cell.value) : "";
66
+ if (!value) {
67
+ emptyCount += 1;
68
+ rowIndex += rowSpan;
69
+ continue;
70
+ }
71
+ const fmtStr = ((_cell$value = cell.value) === null || _cell$value === void 0 ? void 0 : _cell$value.v) && !cell.value.p ? (_styles$get = styles.get((_cell$value2 = cell.value) === null || _cell$value2 === void 0 ? void 0 : _cell$value2.s)) === null || _styles$get === void 0 || (_styles$get = _styles$get.n) === null || _styles$get === void 0 ? void 0 : _styles$get.pattern : "";
72
+ const isDateValue = fmtStr && _univerjs_core.numfmt.getFormatInfo(fmtStr).isDate;
73
+ let isIncludeDatePart = false;
74
+ if (isDateValue) {
75
+ const { year, month, day } = _univerjs_core.numfmt.getFormatDateInfo(fmtStr);
76
+ isIncludeDatePart = year || month || day;
77
+ }
78
+ if (fmtStr && isDateValue && isIncludeDatePart) {
79
+ var _worksheet$getCellRaw, _yearItem$children, _monthItem$children;
80
+ const originValue = (_worksheet$getCellRaw = worksheet.getCellRaw(cell.row, cell.col)) === null || _worksheet$getCellRaw === void 0 ? void 0 : _worksheet$getCellRaw.v;
81
+ if (!originValue) {
82
+ rowIndex++;
83
+ continue;
84
+ }
85
+ const [year, month, day] = _univerjs_core.numfmt.format(DefaultPattern, Number(originValue)).split("-").map(Number);
86
+ let yearItem = items.get(`${year}`);
87
+ if (!yearItem) {
88
+ yearItem = {
89
+ title: `${year}`,
90
+ key: `${year}`,
91
+ children: [],
92
+ count: 0,
93
+ leaf: false,
94
+ checked: false
95
+ };
96
+ items.set(`${year}`, yearItem);
97
+ treeMap.set(`${year}`, [`${year}`]);
98
+ }
99
+ let monthItem = (_yearItem$children = yearItem.children) === null || _yearItem$children === void 0 ? void 0 : _yearItem$children.find((item) => item.key === `${year}-${month}`);
100
+ if (!monthItem) {
101
+ var _yearItem$children2;
102
+ monthItem = {
103
+ title: localeService.t(`sheets-filter-ui.date.${month}`),
104
+ key: `${year}-${month}`,
105
+ children: [],
106
+ count: 0,
107
+ leaf: false,
108
+ checked: false
109
+ };
110
+ (_yearItem$children2 = yearItem.children) === null || _yearItem$children2 === void 0 || _yearItem$children2.push(monthItem);
111
+ treeMap.set(`${year}-${month}`, [`${year}`, `${year}-${month}`]);
112
+ }
113
+ const dayItem = monthItem === null || monthItem === void 0 || (_monthItem$children = monthItem.children) === null || _monthItem$children === void 0 ? void 0 : _monthItem$children.find((item) => item.key === `${year}-${month}-${day}`);
114
+ if (!dayItem) {
115
+ var _monthItem$children2;
116
+ (_monthItem$children2 = monthItem.children) === null || _monthItem$children2 === void 0 || _monthItem$children2.push({
117
+ title: `${day}`,
118
+ key: `${year}-${month}-${day}`,
119
+ count: 1,
120
+ originValues: /* @__PURE__ */ new Set([value]),
121
+ leaf: true,
122
+ checked: isNeedClearCheckedStatus ? false : alreadyChecked.size ? alreadyChecked.has(value) : !blankChecked
123
+ });
124
+ monthItem.count++;
125
+ yearItem.count++;
126
+ treeMap.set(`${year}-${month}-${day}`, [
127
+ `${year}`,
128
+ `${year}-${month}`,
129
+ `${year}-${month}-${day}`
130
+ ]);
131
+ } else {
132
+ dayItem.originValues.add(value);
133
+ dayItem.count++;
134
+ monthItem.count++;
135
+ yearItem.count++;
136
+ }
137
+ } else {
138
+ const key = value;
139
+ let item = items.get(key);
140
+ if (!item) {
141
+ item = {
142
+ title: value,
143
+ leaf: true,
144
+ checked: isNeedClearCheckedStatus ? false : alreadyChecked.size ? alreadyChecked.has(value) : !blankChecked,
145
+ key,
146
+ count: 1
147
+ };
148
+ items.set(key, item);
149
+ treeMap.set(key, [key]);
150
+ } else item.count++;
151
+ }
152
+ rowIndex++;
153
+ }
154
+ }
155
+ const initialBlankChecked = isNeedClearCheckedStatus ? false : filters ? blankChecked : true;
156
+ if (emptyCount > 0) {
157
+ const item = {
158
+ title: localeService.t("sheets-filter-ui.panel.empty"),
159
+ count: emptyCount,
160
+ leaf: true,
161
+ checked: initialBlankChecked,
162
+ key: EmptyKey
163
+ };
164
+ items.set("empty", item);
165
+ treeMap.set("empty", [EmptyKey]);
166
+ }
167
+ return {
168
+ filterTreeItems: generateFilterTreeBySort(Array.from(items.values())),
169
+ filterTreeMapCache: treeMap
170
+ };
171
+ }
172
+ function generateFilterTreeBySort(tree) {
173
+ return Array.from(tree).sort((a, b) => {
174
+ if (a.children && !b.children) return -1;
175
+ if (!a.children && b.children) return 1;
176
+ return compare(a.title, b.title);
177
+ }).map((yearItem) => {
178
+ if (yearItem.children) yearItem.children.sort((a, b) => {
179
+ return Number.parseInt(a.key.split("-")[1], 10) - Number.parseInt(b.key.split("-")[1], 10);
180
+ }).forEach((monthItem) => {
181
+ if (monthItem.children) monthItem.children.sort((a, b) => {
182
+ return Number.parseInt(a.key.split("-")[2], 10) - Number.parseInt(b.key.split("-")[2], 10);
183
+ });
184
+ });
185
+ return yearItem;
186
+ });
187
+ }
188
+ function compare(strA, strB) {
189
+ const aIsNumeric = (0, _univerjs_core.isNumeric)(strA);
190
+ const bIsNumeric = (0, _univerjs_core.isNumeric)(strB);
191
+ if (aIsNumeric && bIsNumeric) return Number.parseFloat(strA) - Number.parseFloat(strB);
192
+ else if (aIsNumeric && !bIsNumeric) return -1;
193
+ else if (!aIsNumeric && bIsNumeric) return 1;
194
+ else return strA.localeCompare(strB);
195
+ }
196
+
197
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
198
+ function _typeof(o) {
199
+ "@babel/helpers - typeof";
200
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
201
+ return typeof o;
202
+ } : function(o) {
203
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
204
+ }, _typeof(o);
205
+ }
206
+
207
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
208
+ function toPrimitive(t, e) {
209
+ if ("object" != _typeof(t) || !t) return t;
210
+ var r;
211
+ if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
212
+ var i = r.call(t, e || "default");
213
+ if ("object" != _typeof(i)) return i;
214
+ throw new TypeError("@@toPrimitive must return a primitive value.");
215
+ }
216
+ return ("string" === e ? String : Number)(t);
217
+ }
218
+
219
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
220
+ function toPropertyKey(t) {
221
+ var i = toPrimitive(t, "string");
222
+ return "symbol" == _typeof(i) ? i : i + "";
223
+ }
224
+
225
+ // \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
226
+ function _defineProperty(e, r, t) {
227
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
228
+ value: t,
229
+ enumerable: !0,
230
+ configurable: !0,
231
+ writable: !0
232
+ }) : e[r] = t, e;
233
+ }
234
+
235
+ // package.json
236
+ var name = "@univerjs/sheets-filter-ui";
237
+ var version = "1.5.0";
238
+
239
+ // src/config/config.ts
240
+ const SHEETS_FILTER_UI_PLUGIN_CONFIG_KEY = "sheets-filter-ui.config";
241
+ const configSymbol = Symbol(SHEETS_FILTER_UI_PLUGIN_CONFIG_KEY);
242
+ const defaultPluginConfig = {};
243
+
244
+ Object.defineProperty(exports, "ISheetsGenerateFilterValuesService", {
245
+ enumerable: true,
246
+ get: function () {
247
+ return ISheetsGenerateFilterValuesService;
248
+ }
249
+ });
250
+ Object.defineProperty(exports, "SHEETS_FILTER_UI_PLUGIN_CONFIG_KEY", {
251
+ enumerable: true,
252
+ get: function () {
253
+ return SHEETS_FILTER_UI_PLUGIN_CONFIG_KEY;
254
+ }
255
+ });
256
+ Object.defineProperty(exports, "SHEETS_GENERATE_FILTER_VALUES_SERVICE_NAME", {
257
+ enumerable: true,
258
+ get: function () {
259
+ return SHEETS_GENERATE_FILTER_VALUES_SERVICE_NAME;
260
+ }
261
+ });
262
+ Object.defineProperty(exports, "SheetsGenerateFilterValuesService", {
263
+ enumerable: true,
264
+ get: function () {
265
+ return SheetsGenerateFilterValuesService;
266
+ }
267
+ });
268
+ Object.defineProperty(exports, "__decorate", {
269
+ enumerable: true,
270
+ get: function () {
271
+ return __decorate;
272
+ }
273
+ });
274
+ Object.defineProperty(exports, "__decorateParam", {
275
+ enumerable: true,
276
+ get: function () {
277
+ return __decorateParam;
278
+ }
279
+ });
280
+ Object.defineProperty(exports, "_defineProperty", {
281
+ enumerable: true,
282
+ get: function () {
283
+ return _defineProperty;
284
+ }
285
+ });
286
+ Object.defineProperty(exports, "defaultPluginConfig", {
287
+ enumerable: true,
288
+ get: function () {
289
+ return defaultPluginConfig;
290
+ }
291
+ });
292
+ Object.defineProperty(exports, "getFilterTreeByValueItems", {
293
+ enumerable: true,
294
+ get: function () {
295
+ return getFilterTreeByValueItems;
296
+ }
297
+ });
298
+ Object.defineProperty(exports, "name", {
299
+ enumerable: true,
300
+ get: function () {
301
+ return name;
302
+ }
303
+ });
304
+ Object.defineProperty(exports, "version", {
305
+ enumerable: true,
306
+ get: function () {
307
+ return version;
308
+ }
309
+ });