@univerjs/sheets-filter 0.21.1 → 0.22.0-insiders.20260513-09bbeca

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/README.md CHANGED
@@ -1,31 +1,42 @@
1
1
  # @univerjs/sheets-filter
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@univerjs/sheets-filter?style=flat-square)](https://npmjs.com/package/@univerjs/sheets-filter)
4
+ [![license](https://img.shields.io/npm/l/@univerjs/sheets-filter?style=flat-square)](https://npmjs.com/package/@univerjs/sheets-filter)
5
+ [![downloads](https://img.shields.io/npm/dm/@univerjs/sheets-filter?style=flat-square)](https://npmjs.com/package/@univerjs/sheets-filter)
6
+
7
+ `@univerjs/sheets-filter` adds the core filtering model, commands, and services for Univer Sheets.
8
+
3
9
  ## Package Overview
4
10
 
5
- | Package Name | UMD Namespace | Version | License | Downloads | Contains CSS | Contains i18n locales |
6
- | --- | --- | --- | --- | --- | :---: | :---: |
7
- | `@univerjs/sheets-filter` | `UniverSheetsFilter` | [![][npm-version-shield]][npm-version-link] | ![][npm-license-shield] | ![][npm-downloads-shield] | ❌ | ❌ |
11
+ | Package | UMD global | CSS | Locales | Facade entry |
12
+ | --- | --- | :---: | :---: | :---: |
13
+ | `@univerjs/sheets-filter` | `UniverSheetsFilter` | No | No | Yes |
14
+
15
+ ## Installation
8
16
 
9
- ## Introduction
17
+ ```sh
18
+ pnpm add @univerjs/sheets-filter
19
+ # or
20
+ npm install @univerjs/sheets-filter
21
+ ```
10
22
 
11
- `@univerjs/sheets-filter` is a filter plugin for Univer Sheet.
23
+ Keep all `@univerjs/*` packages on the same version.
12
24
 
13
25
  ## Usage
14
26
 
15
- You should use this plugin with the `@univerjs/sheets-filter-ui` package.
27
+ ```ts
28
+ import { UniverSheetsFilterPlugin } from '@univerjs/sheets-filter';
16
29
 
17
- ### Installation
30
+ univer.registerPlugin(UniverSheetsFilterPlugin);
31
+ ```
18
32
 
19
- ```shell
20
- # Using npm
21
- npm install @univerjs/sheets-filter
33
+ ## Integration Notes
22
34
 
23
- # Using pnpm
24
- pnpm add @univerjs/sheets-filter
25
- ```
35
+ Use this package with `@univerjs/sheets-filter-ui` when users need filter menus and panels.
36
+
37
+ ## Resources
38
+
39
+ - [Documentation](https://docs.univer.ai)
40
+ - [NPM package](https://npmjs.com/package/@univerjs/sheets-filter)
41
+ - [GitHub repository](https://github.com/dream-num/univer)
26
42
 
27
- <!-- Links -->
28
- [npm-version-shield]: https://img.shields.io/npm/v/@univerjs/sheets-filter?style=flat-square
29
- [npm-version-link]: https://npmjs.com/package/@univerjs/sheets-filter
30
- [npm-license-shield]: https://img.shields.io/npm/l/@univerjs/sheets-filter?style=flat-square
31
- [npm-downloads-shield]: https://img.shields.io/npm/dm/@univerjs/sheets-filter?style=flat-square
package/lib/cjs/facade.js CHANGED
@@ -70,7 +70,7 @@ var FUniverSheetsFilterMixin = class extends _univerjs_core_facade.FUniver {
70
70
  _univerjs_core_facade.FUniver.extend(FUniverSheetsFilterMixin);
71
71
 
72
72
  //#endregion
73
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
73
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
74
74
  function __decorateParam(paramIndex, decorator) {
75
75
  return function(target, key) {
76
76
  decorator(target, key, paramIndex);
@@ -78,7 +78,7 @@ function __decorateParam(paramIndex, decorator) {
78
78
  }
79
79
 
80
80
  //#endregion
81
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
81
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
82
82
  function __decorate(decorators, target, key, desc) {
83
83
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
84
84
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
package/lib/cjs/index.js CHANGED
@@ -69,42 +69,42 @@ let CustomFilterOperator = /* @__PURE__ */ function(CustomFilterOperator) {
69
69
  //#endregion
70
70
  //#region src/models/custom-filters.ts
71
71
  const greaterThan = {
72
- operator: CustomFilterOperator.GREATER_THAN,
72
+ operator: "greaterThan",
73
73
  fn: (value, compare) => {
74
74
  if (!ensureNumber(value)) return false;
75
75
  return value > compare;
76
76
  }
77
77
  };
78
78
  const greaterThanOrEqualTo = {
79
- operator: CustomFilterOperator.GREATER_THAN_OR_EQUAL,
79
+ operator: "greaterThanOrEqual",
80
80
  fn: (value, compare) => {
81
81
  if (!ensureNumber(value)) return false;
82
82
  return value >= compare;
83
83
  }
84
84
  };
85
85
  const lessThan = {
86
- operator: CustomFilterOperator.LESS_THAN,
86
+ operator: "lessThan",
87
87
  fn: (value, compare) => {
88
88
  if (!ensureNumber(value)) return false;
89
89
  return value < compare;
90
90
  }
91
91
  };
92
92
  const lessThanOrEqualTo = {
93
- operator: CustomFilterOperator.LESS_THAN_OR_EQUAL,
93
+ operator: "lessThanOrEqual",
94
94
  fn: (value, compare) => {
95
95
  if (!ensureNumber(value)) return false;
96
96
  return value <= compare;
97
97
  }
98
98
  };
99
99
  const equals = {
100
- operator: CustomFilterOperator.EQUAL,
100
+ operator: "equal",
101
101
  fn: (value, compare) => {
102
102
  if (!ensureNumber(value)) return false;
103
103
  return value === compare;
104
104
  }
105
105
  };
106
106
  const notEquals = {
107
- operator: CustomFilterOperator.NOT_EQUALS,
107
+ operator: "notEqual",
108
108
  fn: (value, compare) => {
109
109
  if (typeof compare === "string") {
110
110
  if (compare === " ") {
@@ -164,7 +164,7 @@ function isWildCardString(str) {
164
164
  }
165
165
 
166
166
  //#endregion
167
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
167
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
168
168
  function _typeof(o) {
169
169
  "@babel/helpers - typeof";
170
170
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -175,7 +175,7 @@ function _typeof(o) {
175
175
  }
176
176
 
177
177
  //#endregion
178
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
178
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
179
179
  function toPrimitive(t, r) {
180
180
  if ("object" != _typeof(t) || !t) return t;
181
181
  var e = t[Symbol.toPrimitive];
@@ -188,14 +188,14 @@ function toPrimitive(t, r) {
188
188
  }
189
189
 
190
190
  //#endregion
191
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
191
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
192
192
  function toPropertyKey(t) {
193
193
  var i = toPrimitive(t, "string");
194
194
  return "symbol" == _typeof(i) ? i : i + "";
195
195
  }
196
196
 
197
197
  //#endregion
198
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
198
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
199
199
  function _defineProperty(e, r, t) {
200
200
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
201
201
  value: t,
@@ -382,9 +382,10 @@ var FilterModel = class FilterModel extends _univerjs_core.Disposable {
382
382
  this._hasCriteria$.next(this._filterColumnByIndex.size > 0);
383
383
  }
384
384
  _rebuildAlreadyFilteredOutRowsWithCache() {
385
- this._alreadyFilteredOutRows = this._getAllFilterColumns().filter((filterColumn) => filterColumn.hasCache()).reduce((acc, filterColumn) => {
385
+ const newFilteredOutRows = this._getAllFilterColumns().filter((filterColumn) => filterColumn.hasCache()).reduce((acc, filterColumn) => {
386
386
  return (0, _univerjs_core.mergeSets)(acc, filterColumn.filteredOutRows);
387
387
  }, /* @__PURE__ */ new Set());
388
+ this._alreadyFilteredOutRows = newFilteredOutRows;
388
389
  }
389
390
  _reCalcWithNoCacheColumns() {
390
391
  const noCacheFilteredOutRows = this._getAllFilterColumns().filter((filterColumn) => !filterColumn.hasCache());
@@ -415,7 +416,7 @@ var FilterColumn = class extends _univerjs_core.Disposable {
415
416
  _defineProperty(this, "_filterFn", null);
416
417
  _defineProperty(this, "_range", null);
417
418
  _defineProperty(this, "_column", 0);
418
- _defineProperty(this, "_filterBy", FilterBy.VALUES);
419
+ _defineProperty(this, "_filterBy", 0);
419
420
  }
420
421
  dispose() {
421
422
  super.dispose();
@@ -475,7 +476,7 @@ var FilterColumn = class extends _univerjs_core.Disposable {
475
476
  for (const range of this._worksheet.iterateByColumn(iterateRange, false, false)) {
476
477
  const { row, rowSpan, col } = range;
477
478
  if (filteredOutByOthers.has(row) && (!rowSpan || rowSpan === 1)) continue;
478
- if (!(this._filterBy === FilterBy.VALUES ? this._filterFn((0, _univerjs_core.extractPureTextFromCell)(this._worksheet.getCell(row, col))) : this._filterBy === FilterBy.COLORS ? this._filterFn(this._worksheet.getComposedCellStyle(row, col)) : this._filterFn(getFilterValueForConditionalFiltering(this._worksheet, row, col)))) {
479
+ if (!(this._filterBy === 0 ? this._filterFn((0, _univerjs_core.extractPureTextFromCell)(this._worksheet.getCell(row, col))) : this._filterBy === 1 ? this._filterFn(this._worksheet.getComposedCellStyle(row, col)) : this._filterFn(getFilterValueForConditionalFiltering(this._worksheet, row, col)))) {
479
480
  filteredOutRows.add(row);
480
481
  if (rowSpan) for (let i = 1; i < rowSpan; i++) filteredOutRows.add(row + i);
481
482
  }
@@ -485,7 +486,7 @@ var FilterColumn = class extends _univerjs_core.Disposable {
485
486
  _generateFilterFn() {
486
487
  if (!this._criteria) return;
487
488
  this._filterFn = generateFilterFn(this._criteria);
488
- this._filterBy = this._criteria.filters ? FilterBy.VALUES : this._criteria.colorFilters ? FilterBy.COLORS : FilterBy.CONDITIONS;
489
+ this._filterBy = this._criteria.filters ? 0 : this._criteria.colorFilters ? 1 : 2;
489
490
  }
490
491
  };
491
492
  /**
@@ -555,7 +556,7 @@ function isCompoundCustomFilter(filter) {
555
556
  }
556
557
  function generateCustomFilterFn(filter) {
557
558
  const compare = filter.val;
558
- if (filter.operator === CustomFilterOperator.NOT_EQUALS) {
559
+ if (filter.operator === "notEqual") {
559
560
  if (!ensureNumeric(compare)) return (value) => notEquals.fn(value, compare);
560
561
  }
561
562
  if (isNumericFilterFn(filter.operator)) {
@@ -595,7 +596,7 @@ function extractFilterValueFromCell(cell) {
595
596
  }
596
597
 
597
598
  //#endregion
598
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
599
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
599
600
  function __decorateParam(paramIndex, decorator) {
600
601
  return function(target, key) {
601
602
  decorator(target, key, paramIndex);
@@ -603,7 +604,7 @@ function __decorateParam(paramIndex, decorator) {
603
604
  }
604
605
 
605
606
  //#endregion
606
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
607
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
607
608
  function __decorate(decorators, target, key, desc) {
608
609
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
609
610
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -2215,7 +2216,7 @@ SheetsFilterSyncController = __decorate([
2215
2216
  //#endregion
2216
2217
  //#region package.json
2217
2218
  var name = "@univerjs/sheets-filter";
2218
- var version = "0.21.1";
2219
+ var version = "0.22.0-insiders.20260513-09bbeca";
2219
2220
 
2220
2221
  //#endregion
2221
2222
  //#region src/services/sheet-filter-formula.service.ts
package/lib/es/facade.js CHANGED
@@ -69,7 +69,7 @@ var FUniverSheetsFilterMixin = class extends FUniver {
69
69
  FUniver.extend(FUniverSheetsFilterMixin);
70
70
 
71
71
  //#endregion
72
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
72
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
73
73
  function __decorateParam(paramIndex, decorator) {
74
74
  return function(target, key) {
75
75
  decorator(target, key, paramIndex);
@@ -77,7 +77,7 @@ function __decorateParam(paramIndex, decorator) {
77
77
  }
78
78
 
79
79
  //#endregion
80
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
80
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
81
81
  function __decorate(decorators, target, key, desc) {
82
82
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
83
83
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
package/lib/es/index.js CHANGED
@@ -68,42 +68,42 @@ let CustomFilterOperator = /* @__PURE__ */ function(CustomFilterOperator) {
68
68
  //#endregion
69
69
  //#region src/models/custom-filters.ts
70
70
  const greaterThan = {
71
- operator: CustomFilterOperator.GREATER_THAN,
71
+ operator: "greaterThan",
72
72
  fn: (value, compare) => {
73
73
  if (!ensureNumber(value)) return false;
74
74
  return value > compare;
75
75
  }
76
76
  };
77
77
  const greaterThanOrEqualTo = {
78
- operator: CustomFilterOperator.GREATER_THAN_OR_EQUAL,
78
+ operator: "greaterThanOrEqual",
79
79
  fn: (value, compare) => {
80
80
  if (!ensureNumber(value)) return false;
81
81
  return value >= compare;
82
82
  }
83
83
  };
84
84
  const lessThan = {
85
- operator: CustomFilterOperator.LESS_THAN,
85
+ operator: "lessThan",
86
86
  fn: (value, compare) => {
87
87
  if (!ensureNumber(value)) return false;
88
88
  return value < compare;
89
89
  }
90
90
  };
91
91
  const lessThanOrEqualTo = {
92
- operator: CustomFilterOperator.LESS_THAN_OR_EQUAL,
92
+ operator: "lessThanOrEqual",
93
93
  fn: (value, compare) => {
94
94
  if (!ensureNumber(value)) return false;
95
95
  return value <= compare;
96
96
  }
97
97
  };
98
98
  const equals = {
99
- operator: CustomFilterOperator.EQUAL,
99
+ operator: "equal",
100
100
  fn: (value, compare) => {
101
101
  if (!ensureNumber(value)) return false;
102
102
  return value === compare;
103
103
  }
104
104
  };
105
105
  const notEquals = {
106
- operator: CustomFilterOperator.NOT_EQUALS,
106
+ operator: "notEqual",
107
107
  fn: (value, compare) => {
108
108
  if (typeof compare === "string") {
109
109
  if (compare === " ") {
@@ -163,7 +163,7 @@ function isWildCardString(str) {
163
163
  }
164
164
 
165
165
  //#endregion
166
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
166
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
167
167
  function _typeof(o) {
168
168
  "@babel/helpers - typeof";
169
169
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -174,7 +174,7 @@ function _typeof(o) {
174
174
  }
175
175
 
176
176
  //#endregion
177
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
177
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
178
178
  function toPrimitive(t, r) {
179
179
  if ("object" != _typeof(t) || !t) return t;
180
180
  var e = t[Symbol.toPrimitive];
@@ -187,14 +187,14 @@ function toPrimitive(t, r) {
187
187
  }
188
188
 
189
189
  //#endregion
190
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
190
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
191
191
  function toPropertyKey(t) {
192
192
  var i = toPrimitive(t, "string");
193
193
  return "symbol" == _typeof(i) ? i : i + "";
194
194
  }
195
195
 
196
196
  //#endregion
197
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
197
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
198
198
  function _defineProperty(e, r, t) {
199
199
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
200
200
  value: t,
@@ -381,9 +381,10 @@ var FilterModel = class FilterModel extends Disposable {
381
381
  this._hasCriteria$.next(this._filterColumnByIndex.size > 0);
382
382
  }
383
383
  _rebuildAlreadyFilteredOutRowsWithCache() {
384
- this._alreadyFilteredOutRows = this._getAllFilterColumns().filter((filterColumn) => filterColumn.hasCache()).reduce((acc, filterColumn) => {
384
+ const newFilteredOutRows = this._getAllFilterColumns().filter((filterColumn) => filterColumn.hasCache()).reduce((acc, filterColumn) => {
385
385
  return mergeSets(acc, filterColumn.filteredOutRows);
386
386
  }, /* @__PURE__ */ new Set());
387
+ this._alreadyFilteredOutRows = newFilteredOutRows;
387
388
  }
388
389
  _reCalcWithNoCacheColumns() {
389
390
  const noCacheFilteredOutRows = this._getAllFilterColumns().filter((filterColumn) => !filterColumn.hasCache());
@@ -414,7 +415,7 @@ var FilterColumn = class extends Disposable {
414
415
  _defineProperty(this, "_filterFn", null);
415
416
  _defineProperty(this, "_range", null);
416
417
  _defineProperty(this, "_column", 0);
417
- _defineProperty(this, "_filterBy", FilterBy.VALUES);
418
+ _defineProperty(this, "_filterBy", 0);
418
419
  }
419
420
  dispose() {
420
421
  super.dispose();
@@ -474,7 +475,7 @@ var FilterColumn = class extends Disposable {
474
475
  for (const range of this._worksheet.iterateByColumn(iterateRange, false, false)) {
475
476
  const { row, rowSpan, col } = range;
476
477
  if (filteredOutByOthers.has(row) && (!rowSpan || rowSpan === 1)) continue;
477
- if (!(this._filterBy === FilterBy.VALUES ? this._filterFn(extractPureTextFromCell(this._worksheet.getCell(row, col))) : this._filterBy === FilterBy.COLORS ? this._filterFn(this._worksheet.getComposedCellStyle(row, col)) : this._filterFn(getFilterValueForConditionalFiltering(this._worksheet, row, col)))) {
478
+ if (!(this._filterBy === 0 ? this._filterFn(extractPureTextFromCell(this._worksheet.getCell(row, col))) : this._filterBy === 1 ? this._filterFn(this._worksheet.getComposedCellStyle(row, col)) : this._filterFn(getFilterValueForConditionalFiltering(this._worksheet, row, col)))) {
478
479
  filteredOutRows.add(row);
479
480
  if (rowSpan) for (let i = 1; i < rowSpan; i++) filteredOutRows.add(row + i);
480
481
  }
@@ -484,7 +485,7 @@ var FilterColumn = class extends Disposable {
484
485
  _generateFilterFn() {
485
486
  if (!this._criteria) return;
486
487
  this._filterFn = generateFilterFn(this._criteria);
487
- this._filterBy = this._criteria.filters ? FilterBy.VALUES : this._criteria.colorFilters ? FilterBy.COLORS : FilterBy.CONDITIONS;
488
+ this._filterBy = this._criteria.filters ? 0 : this._criteria.colorFilters ? 1 : 2;
488
489
  }
489
490
  };
490
491
  /**
@@ -554,7 +555,7 @@ function isCompoundCustomFilter(filter) {
554
555
  }
555
556
  function generateCustomFilterFn(filter) {
556
557
  const compare = filter.val;
557
- if (filter.operator === CustomFilterOperator.NOT_EQUALS) {
558
+ if (filter.operator === "notEqual") {
558
559
  if (!ensureNumeric(compare)) return (value) => notEquals.fn(value, compare);
559
560
  }
560
561
  if (isNumericFilterFn(filter.operator)) {
@@ -594,7 +595,7 @@ function extractFilterValueFromCell(cell) {
594
595
  }
595
596
 
596
597
  //#endregion
597
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
598
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
598
599
  function __decorateParam(paramIndex, decorator) {
599
600
  return function(target, key) {
600
601
  decorator(target, key, paramIndex);
@@ -602,7 +603,7 @@ function __decorateParam(paramIndex, decorator) {
602
603
  }
603
604
 
604
605
  //#endregion
605
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
606
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
606
607
  function __decorate(decorators, target, key, desc) {
607
608
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
608
609
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -2214,7 +2215,7 @@ SheetsFilterSyncController = __decorate([
2214
2215
  //#endregion
2215
2216
  //#region package.json
2216
2217
  var name = "@univerjs/sheets-filter";
2217
- var version = "0.21.1";
2218
+ var version = "0.22.0-insiders.20260513-09bbeca";
2218
2219
 
2219
2220
  //#endregion
2220
2221
  //#region src/services/sheet-filter-formula.service.ts
package/lib/facade.js CHANGED
@@ -69,7 +69,7 @@ var FUniverSheetsFilterMixin = class extends FUniver {
69
69
  FUniver.extend(FUniverSheetsFilterMixin);
70
70
 
71
71
  //#endregion
72
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
72
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
73
73
  function __decorateParam(paramIndex, decorator) {
74
74
  return function(target, key) {
75
75
  decorator(target, key, paramIndex);
@@ -77,7 +77,7 @@ function __decorateParam(paramIndex, decorator) {
77
77
  }
78
78
 
79
79
  //#endregion
80
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
80
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
81
81
  function __decorate(decorators, target, key, desc) {
82
82
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
83
83
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
package/lib/index.js CHANGED
@@ -68,42 +68,42 @@ let CustomFilterOperator = /* @__PURE__ */ function(CustomFilterOperator) {
68
68
  //#endregion
69
69
  //#region src/models/custom-filters.ts
70
70
  const greaterThan = {
71
- operator: CustomFilterOperator.GREATER_THAN,
71
+ operator: "greaterThan",
72
72
  fn: (value, compare) => {
73
73
  if (!ensureNumber(value)) return false;
74
74
  return value > compare;
75
75
  }
76
76
  };
77
77
  const greaterThanOrEqualTo = {
78
- operator: CustomFilterOperator.GREATER_THAN_OR_EQUAL,
78
+ operator: "greaterThanOrEqual",
79
79
  fn: (value, compare) => {
80
80
  if (!ensureNumber(value)) return false;
81
81
  return value >= compare;
82
82
  }
83
83
  };
84
84
  const lessThan = {
85
- operator: CustomFilterOperator.LESS_THAN,
85
+ operator: "lessThan",
86
86
  fn: (value, compare) => {
87
87
  if (!ensureNumber(value)) return false;
88
88
  return value < compare;
89
89
  }
90
90
  };
91
91
  const lessThanOrEqualTo = {
92
- operator: CustomFilterOperator.LESS_THAN_OR_EQUAL,
92
+ operator: "lessThanOrEqual",
93
93
  fn: (value, compare) => {
94
94
  if (!ensureNumber(value)) return false;
95
95
  return value <= compare;
96
96
  }
97
97
  };
98
98
  const equals = {
99
- operator: CustomFilterOperator.EQUAL,
99
+ operator: "equal",
100
100
  fn: (value, compare) => {
101
101
  if (!ensureNumber(value)) return false;
102
102
  return value === compare;
103
103
  }
104
104
  };
105
105
  const notEquals = {
106
- operator: CustomFilterOperator.NOT_EQUALS,
106
+ operator: "notEqual",
107
107
  fn: (value, compare) => {
108
108
  if (typeof compare === "string") {
109
109
  if (compare === " ") {
@@ -163,7 +163,7 @@ function isWildCardString(str) {
163
163
  }
164
164
 
165
165
  //#endregion
166
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
166
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
167
167
  function _typeof(o) {
168
168
  "@babel/helpers - typeof";
169
169
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -174,7 +174,7 @@ function _typeof(o) {
174
174
  }
175
175
 
176
176
  //#endregion
177
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
177
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
178
178
  function toPrimitive(t, r) {
179
179
  if ("object" != _typeof(t) || !t) return t;
180
180
  var e = t[Symbol.toPrimitive];
@@ -187,14 +187,14 @@ function toPrimitive(t, r) {
187
187
  }
188
188
 
189
189
  //#endregion
190
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
190
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
191
191
  function toPropertyKey(t) {
192
192
  var i = toPrimitive(t, "string");
193
193
  return "symbol" == _typeof(i) ? i : i + "";
194
194
  }
195
195
 
196
196
  //#endregion
197
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
197
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
198
198
  function _defineProperty(e, r, t) {
199
199
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
200
200
  value: t,
@@ -381,9 +381,10 @@ var FilterModel = class FilterModel extends Disposable {
381
381
  this._hasCriteria$.next(this._filterColumnByIndex.size > 0);
382
382
  }
383
383
  _rebuildAlreadyFilteredOutRowsWithCache() {
384
- this._alreadyFilteredOutRows = this._getAllFilterColumns().filter((filterColumn) => filterColumn.hasCache()).reduce((acc, filterColumn) => {
384
+ const newFilteredOutRows = this._getAllFilterColumns().filter((filterColumn) => filterColumn.hasCache()).reduce((acc, filterColumn) => {
385
385
  return mergeSets(acc, filterColumn.filteredOutRows);
386
386
  }, /* @__PURE__ */ new Set());
387
+ this._alreadyFilteredOutRows = newFilteredOutRows;
387
388
  }
388
389
  _reCalcWithNoCacheColumns() {
389
390
  const noCacheFilteredOutRows = this._getAllFilterColumns().filter((filterColumn) => !filterColumn.hasCache());
@@ -414,7 +415,7 @@ var FilterColumn = class extends Disposable {
414
415
  _defineProperty(this, "_filterFn", null);
415
416
  _defineProperty(this, "_range", null);
416
417
  _defineProperty(this, "_column", 0);
417
- _defineProperty(this, "_filterBy", FilterBy.VALUES);
418
+ _defineProperty(this, "_filterBy", 0);
418
419
  }
419
420
  dispose() {
420
421
  super.dispose();
@@ -474,7 +475,7 @@ var FilterColumn = class extends Disposable {
474
475
  for (const range of this._worksheet.iterateByColumn(iterateRange, false, false)) {
475
476
  const { row, rowSpan, col } = range;
476
477
  if (filteredOutByOthers.has(row) && (!rowSpan || rowSpan === 1)) continue;
477
- if (!(this._filterBy === FilterBy.VALUES ? this._filterFn(extractPureTextFromCell(this._worksheet.getCell(row, col))) : this._filterBy === FilterBy.COLORS ? this._filterFn(this._worksheet.getComposedCellStyle(row, col)) : this._filterFn(getFilterValueForConditionalFiltering(this._worksheet, row, col)))) {
478
+ if (!(this._filterBy === 0 ? this._filterFn(extractPureTextFromCell(this._worksheet.getCell(row, col))) : this._filterBy === 1 ? this._filterFn(this._worksheet.getComposedCellStyle(row, col)) : this._filterFn(getFilterValueForConditionalFiltering(this._worksheet, row, col)))) {
478
479
  filteredOutRows.add(row);
479
480
  if (rowSpan) for (let i = 1; i < rowSpan; i++) filteredOutRows.add(row + i);
480
481
  }
@@ -484,7 +485,7 @@ var FilterColumn = class extends Disposable {
484
485
  _generateFilterFn() {
485
486
  if (!this._criteria) return;
486
487
  this._filterFn = generateFilterFn(this._criteria);
487
- this._filterBy = this._criteria.filters ? FilterBy.VALUES : this._criteria.colorFilters ? FilterBy.COLORS : FilterBy.CONDITIONS;
488
+ this._filterBy = this._criteria.filters ? 0 : this._criteria.colorFilters ? 1 : 2;
488
489
  }
489
490
  };
490
491
  /**
@@ -554,7 +555,7 @@ function isCompoundCustomFilter(filter) {
554
555
  }
555
556
  function generateCustomFilterFn(filter) {
556
557
  const compare = filter.val;
557
- if (filter.operator === CustomFilterOperator.NOT_EQUALS) {
558
+ if (filter.operator === "notEqual") {
558
559
  if (!ensureNumeric(compare)) return (value) => notEquals.fn(value, compare);
559
560
  }
560
561
  if (isNumericFilterFn(filter.operator)) {
@@ -594,7 +595,7 @@ function extractFilterValueFromCell(cell) {
594
595
  }
595
596
 
596
597
  //#endregion
597
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
598
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
598
599
  function __decorateParam(paramIndex, decorator) {
599
600
  return function(target, key) {
600
601
  decorator(target, key, paramIndex);
@@ -602,7 +603,7 @@ function __decorateParam(paramIndex, decorator) {
602
603
  }
603
604
 
604
605
  //#endregion
605
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
606
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
606
607
  function __decorate(decorators, target, key, desc) {
607
608
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
608
609
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -2214,7 +2215,7 @@ SheetsFilterSyncController = __decorate([
2214
2215
  //#endregion
2215
2216
  //#region package.json
2216
2217
  var name = "@univerjs/sheets-filter";
2217
- var version = "0.21.1";
2218
+ var version = "0.22.0-insiders.20260513-09bbeca";
2218
2219
 
2219
2220
  //#endregion
2220
2221
  //#region src/services/sheet-filter-formula.service.ts
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`rxjs`),require(`@univerjs/engine-render`),require(`@univerjs/rpc`),require(`@univerjs/engine-formula`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`rxjs`,`@univerjs/engine-render`,`@univerjs/rpc`,`@univerjs/engine-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFilter={},e.UniverCore,e.UniverSheets,e.rxjs,e.UniverEngineRender,e.UniverRpc,e.UniverEngineFormula))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let s=`sheet.mutation.set-filter-range`,c=`sheet.mutation.set-filter-criteria`,l=`sheet.mutation.remove-filter`,u=`sheet.mutation.re-calc-filter`,d=new Set([s,c,l,u]),f=function(e){return e[e.VALUES=0]=`VALUES`,e[e.COLORS=1]=`COLORS`,e[e.CONDITIONS=2]=`CONDITIONS`,e}({}),p=function(e){return e.EQUAL=`equal`,e.GREATER_THAN=`greaterThan`,e.GREATER_THAN_OR_EQUAL=`greaterThanOrEqual`,e.LESS_THAN=`lessThan`,e.LESS_THAN_OR_EQUAL=`lessThanOrEqual`,e.NOT_EQUALS=`notEqual`,e}({}),m={operator:p.GREATER_THAN,fn:(e,t)=>C(e)?e>t:!1},h={operator:p.GREATER_THAN_OR_EQUAL,fn:(e,t)=>C(e)?e>=t:!1},g={operator:p.LESS_THAN,fn:(e,t)=>C(e)?e<t:!1},_={operator:p.LESS_THAN_OR_EQUAL,fn:(e,t)=>C(e)?e<=t:!1},v={operator:p.EQUAL,fn:(e,t)=>C(e)?e===t:!1},y={operator:p.NOT_EQUALS,fn:(e,n)=>{if(typeof n==`string`){if(n===` `)return e!=null;let r=T(e);return r&&te(n)?!(0,t.createREGEXFromWildChar)(n).test(r):r!==n}return C(e)?e!==n:!0}},b=new Map([]);[m,h,g,_,v,y].forEach(e=>{b.set(e.operator,e)});function ee(e){return!!e}let x={fn:(e,n)=>{let r=T(e);return r===null?n===``:(0,t.createREGEXFromWildChar)(n).test(r)}};function S(e){return e?b.get(e):x}function C(e){return typeof e==`number`}function w(e){return!!(typeof e==`number`||typeof e==`string`&&(0,t.isNumeric)(e))}function T(e){return typeof e==`boolean`||e==null?null:typeof e==`string`?e:e.toString()}function te(e){return typeof e==`number`?!1:e.indexOf(`*`)!==-1||e.indexOf(`?`)!==-1}function E(e){"@babel/helpers - typeof";return E=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},E(e)}function ne(e,t){if(E(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(E(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function D(e){var t=ne(e,`string`);return E(t)==`symbol`?t:t+``}function O(e,t,n){return(t=D(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let k=()=>new Set;var A=class e extends t.Disposable{get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}constructor(e,t,n){super(),this.unitId=e,this.subUnitId=t,this._worksheet=n,O(this,`_filteredOutRows$`,new r.BehaviorSubject(k())),O(this,`filteredOutRows$`,this._filteredOutRows$.asObservable()),O(this,`_hasCriteria$`,new r.BehaviorSubject(!1)),O(this,`hasCriteria$`,this._hasCriteria$.asObservable()),O(this,`_filterColumnByIndex`,new Map),O(this,`_alreadyFilteredOutRows`,k()),O(this,`_range`,void 0)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete(),this._worksheet=null}serialize(){let e={ref:t.Rectangle.clone(this._range),filterColumns:this._getAllFilterColumns(!0).sort(([e],[t])=>e-t).map(([e,t])=>t.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(t,n,r,i){let a=new e(t,n,r);return a._dump(i),a}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.filter(e=>!(!e.filters&&!e.colorFilters&&!e.customFilters)).forEach(e=>this._setCriteriaWithoutReCalc(e.colId,e)),e.cachedFilteredOut?(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()):e.filterColumns&&e.filterColumns.length>0&&(this._reCalcAllColumns(),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw Error(`[FilterModel] could not get range before a range is set!`);return this._range}getFilteredOutRowsExceptCol(e){return this._getAllFilterColumns(!0).filter(([t])=>t!==e).reduce((e,[,n])=>{let r=n.calc({getAlreadyFilteredOutRows:()=>e});return r?(0,t.mergeSets)(e,r):e},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,n])=>{n.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,n=!1){if(!this._range)throw Error(`[FilterModel] could not set criteria before a range is set!`);if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),n&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),n&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))==null?null:t}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){let t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([e,t])=>t)}_reCalcAllColumns(){this._alreadyFilteredOutRows=k(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns()}_setCriteriaWithoutReCalc(e,t){let n=this._range;if(!n)throw Error(`[FilterModel] could not set criteria before a range is set!`);let{startColumn:r,endColumn:i}=n;if(e>i||e<r)throw Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);let a;this._filterColumnByIndex.has(e)?a=this._filterColumnByIndex.get(e):(a=new j(this.unitId,this.subUnitId,this._worksheet,t,{getAlreadyFilteredOutRows:()=>this._alreadyFilteredOutRows}),a.setRangeAndColumn(n,e),this._filterColumnByIndex.set(e,a)),a.setCriteria(t)}_removeCriteria(e){let t=this._filterColumnByIndex.get(e);t&&(t.dispose(),this._filterColumnByIndex.delete(e))}_emit(){this._filteredOutRows$.next(this._alreadyFilteredOutRows)}_emitHasCriteria(){this._hasCriteria$.next(this._filterColumnByIndex.size>0)}_rebuildAlreadyFilteredOutRowsWithCache(){this._alreadyFilteredOutRows=this._getAllFilterColumns().filter(e=>e.hasCache()).reduce((e,n)=>(0,t.mergeSets)(e,n.filteredOutRows),new Set)}_reCalcWithNoCacheColumns(){let e=this._getAllFilterColumns().filter(e=>!e.hasCache());for(let n of e){let e=n.reCalc();e&&(this._alreadyFilteredOutRows=(0,t.mergeSets)(this._alreadyFilteredOutRows,e))}}},j=class extends t.Disposable{get filteredOutRows(){return this._filteredOutRows}get filterBy(){return this._filterBy}constructor(e,t,n,r,i){super(),this.unitId=e,this.subUnitId=t,this._worksheet=n,this._criteria=r,this._filterColumnContext=i,O(this,`_filteredOutRows`,null),O(this,`_filterFn`,null),O(this,`_range`,null),O(this,`_column`,0),O(this,`_filterBy`,f.VALUES)}dispose(){super.dispose(),this._filteredOutRows=null}__clearCache(){this._filteredOutRows=null}serialize(){if(!this._criteria)throw Error(`[FilterColumn]: could not serialize without a filter column!`);return t.Tools.deepClone({...this._criteria,colId:this._column})}hasCache(){return this._filteredOutRows!==null}setRangeAndColumn(e,t){this._range=e,this._column=t}setCriteria(e){this._criteria=e,this._generateFilterFn(),this._filteredOutRows=null}getColumnData(){return t.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw Error(`[FilterColumn] cannot calculate without a filter fn!`);if(!this._range)throw Error(`[FilterColumn] cannot calculate without a range!`);if(typeof this._column!=`number`)throw TypeError(`[FilterColumn] cannot calculate without a column offset!`);let n=this._column,r={startColumn:n,endColumn:n,startRow:this._range.startRow+1,endRow:this._range.endRow},i=new Set,a=e.getAlreadyFilteredOutRows();for(let e of this._worksheet.iterateByColumn(r,!1,!1)){let{row:n,rowSpan:r,col:o}=e;if(!(a.has(n)&&(!r||r===1))&&!(this._filterBy===f.VALUES?this._filterFn((0,t.extractPureTextFromCell)(this._worksheet.getCell(n,o))):this._filterBy===f.COLORS?this._filterFn(this._worksheet.getComposedCellStyle(n,o)):this._filterFn(ce(this._worksheet,n,o)))&&(i.add(n),r))for(let e=1;e<r;e++)i.add(n+e)}return i}_generateFilterFn(){this._criteria&&(this._filterFn=re(this._criteria),this._filterBy=this._criteria.filters?f.VALUES:this._criteria.colorFilters?f.COLORS:f.CONDITIONS)}};function re(e){if(e.filters)return ie(e.filters);if(e.colorFilters)return ae(e.colorFilters);if(e.customFilters)return oe(e.customFilters);throw Error(`[FilterModel]: other types of filters are not supported yet.`)}function ie(e){let t=!!e.blank,n=new Set(e.filters);return e=>e===void 0||e===``?t:n.has(typeof e==`string`?e:`${e}`)}function ae(e){if(e.cellFillColors){let n=new Set(e.cellFillColors);return e=>{var r;if(!e||!((r=e.bg)!=null&&r.rgb))return!!n.has(null);let i=new t.ColorKit(e.bg.rgb).toRgbString();return n.has(i)}}if(e.cellTextColors){let n=new Set(e.cellTextColors);return e=>{var r;if(!e||!((r=e.cl)!=null&&r.rgb))return!!n.has(i.COLOR_BLACK_RGB);let a=new t.ColorKit(e.cl.rgb).toRgbString();return n.has(a)}}throw Error(`[FilterModel]: color filters are not supported yet.`)}function oe(e){let t=e.customFilters.map(e=>P(e));return N(t)?e.and?se(t):M(t):t[0]}function se(e){let[t,n]=e;return e=>t(e)&&n(e)}function M(e){let[t,n]=e;return e=>t(e)||n(e)}function N(e){return e.length===2}function P(e){let t=e.val;if(e.operator===p.NOT_EQUALS&&!w(t))return e=>y.fn(e,t);if(ee(e.operator)){if(!w(t))return()=>!1;let n=S(e.operator),r=Number(t);return e=>n.fn(e,r)}let n=S(e.operator);return e=>n.fn(e,t)}function ce(e,n,r){let i=e.getCell(n,r);if(!i)return null;let a=e.getCellRaw(n,r);return i&&!a?F(i):a?i.t===t.CellValueType.NUMBER&&typeof i.v==`string`?a.v:i.t===t.CellValueType.NUMBER?Number(a.v):F(a):null}function F(e){var n;let r=(n=e.p)==null||(n=n.body)==null?void 0:n.dataStream;if(r)return r.trimEnd();let i=e.v;return typeof i==`string`?e.t===t.CellValueType.BOOLEAN?i.toUpperCase():i:typeof i==`number`?e.t===t.CellValueType.BOOLEAN?i?`TRUE`:`FALSE`:i:typeof i==`boolean`?i?`TRUE`:`FALSE`:``}function I(e,t){return function(n,r){t(n,r,e)}}function L(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let R=`SHEET_FILTER_PLUGIN`,z=class extends t.Disposable{get activeFilterModel(){return this._activeFilterModel$.getValue()}constructor(e,t,n){super(),this._resourcesManagerService=e,this._univerInstanceService=t,this._commandService=n,O(this,`_filterModels`,new Map),O(this,`_loadedUnitId$`,new r.BehaviorSubject(null)),O(this,`loadedUnitId$`,this._loadedUnitId$.asObservable()),O(this,`_errorMsg$`,new r.BehaviorSubject(null)),O(this,`errorMsg$`,this._errorMsg$.asObservable()),O(this,`_activeFilterModel$`,new r.BehaviorSubject(null)),O(this,`activeFilterModel$`,this._activeFilterModel$.asObservable()),this._initModel(),this._initActiveFilterModel()}ensureFilterModel(e,t){let n=this.getFilterModel(e,t);if(n)return n;let r=this._univerInstanceService.getUniverSheetInstance(e);if(!r)throw Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${e}!`);let i=r.getSheetBySheetId(t);if(!i)throw Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${t}!`);let a=new A(e,t,i);return this._cacheFilterModel(e,t,a),a}getFilterModel(e,t){var n,r;return(n=(r=this._filterModels.get(e))==null?void 0:r.get(t))==null?null:n}removeFilterModel(e,t){let n=this.getFilterModel(e,t);return n?(n.dispose(),this._filterModels.get(e).delete(t),!0):!1}setFilterErrorMsg(e){this._errorMsg$.next(e)}_updateActiveFilterModel(){let e;try{if(e=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),!e){this._activeFilterModel$.next(null);return}}catch(e){console.error(`[SheetsFilterService]: could not get active workbook!`,e);return}let n=e.getActiveSheet(!0);if(!n){this._activeFilterModel$.next(null);return}let r=n.getUnitId(),i=n.getSheetId(),a=this.getFilterModel(r,i);this._activeFilterModel$.next(a)}_initActiveFilterModel(){this.disposeWithMe((0,r.merge)((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,r.filter)(([e])=>e.type===t.CommandType.MUTATION&&d.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,r.switchMap)(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?(0,r.of)(null):t}))).subscribe(()=>this._updateActiveFilterModel()))}_serializeAutoFiltersForUnit(e){let t=this._filterModels.get(e);if(!t)return`{}`;let n={};return t.forEach((e,t)=>{n[t]=e.serialize()}),JSON.stringify(n)}_deserializeAutoFiltersForUnit(e,t){let n=this._univerInstanceService.getUniverSheetInstance(e);Object.keys(t).forEach(r=>{let i=t[r],a=A.deserialize(e,r,n.getSheetBySheetId(r),i);this._cacheFilterModel(e,r,a)})}dispose(){super.dispose(),this._loadedUnitId$.complete(),this._errorMsg$.complete(),this._activeFilterModel$.complete(),this._filterModels.forEach(e=>{e.forEach(e=>e.dispose()),e.clear()}),this._filterModels.clear()}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:R,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:e=>this._serializeAutoFiltersForUnit(e),parseJson:e=>JSON.parse(e),onLoad:(e,t)=>{this._deserializeAutoFiltersForUnit(e,t),this._loadedUnitId$.next(e),this._updateActiveFilterModel()},onUnLoad:e=>{let t=this._filterModels.get(e);t&&(t.forEach(e=>e.dispose()),this._filterModels.delete(e))}})}_cacheFilterModel(e,t,n){this._filterModels.has(e)||this._filterModels.set(e,new Map),this._filterModels.get(e).set(t,n)}};z=L([I(0,t.IResourceManagerService),I(1,t.IUniverInstanceService),I(2,t.ICommandService)],z);let B={id:s,type:t.CommandType.MUTATION,handler:(e,t)=>{let{subUnitId:n,unitId:r,range:i}=t;return e.get(z).ensureFilterModel(r,n).setRange(i),!0}},V={id:c,type:t.CommandType.MUTATION,handler:(e,t)=>{let{subUnitId:n,unitId:r,criteria:i,col:a,reCalc:o=!0}=t,s=e.get(z).getFilterModel(r,n);return s?(s.setCriteria(a,i,o),!0):!1}},H={id:l,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,subUnitId:r}=t;return e.get(z).removeFilterModel(n,r)}},U={id:u,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,subUnitId:r}=t,i=e.get(z).getFilterModel(n,r);return i?(i.reCalc(),!0):!1}},W={id:`sheet.command.set-filter-range`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(z),a=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(t.IUniverInstanceService),{unitId:c,subUnitId:l,range:u}=r;if(!(0,n.getSheetCommandTarget)(s,r)||i.getFilterModel(c,l))return!1;if(u.endRow===u.startRow){let n=e.get(t.ErrorService),r=e.get(t.LocaleService);return n.emit(r.t(`sheets-filter.command.not-valid-filter-range`)),!1}let d={id:B.id,params:{unitId:c,subUnitId:l,range:u}},f=a.syncExecuteCommand(d.id,d.params);return f&&o.pushUndoRedo({unitID:c,undoMutations:[{id:H.id,params:{unitId:c,subUnitId:l}}],redoMutations:[d]}),f}},G={id:`sheet.command.remove-sheet-filter`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(z),{unitId:o,subUnitId:s}=i,c=a.getFilterModel(o,s);if(!c)return!1;let l=c.getRange();if(!l)return!1;let u=e.get(t.ICommandService),d=e.get(t.IUndoRedoService),f=pe(o,s,c.serialize()),p=u.syncExecuteCommand(H.id,{unitId:o,subUnitId:s});return p&&(d.pushUndoRedo({unitID:o,undoMutations:f,redoMutations:[{id:H.id,params:{unitId:o,subUnitId:s}}]}),u.executeCommand(n.MarkDirtyFilterChangeMutation.id,{unitId:o,subUnitId:s,filterRange:l})),p}},le={id:`sheet.command.smart-toggle-filter`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.IUniverInstanceService),i=e.get(z),a=e.get(t.ICommandService),o=r.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),s=o==null?void 0:o.getActiveSheet();if(!s||!o)return!1;let c=o.getUnitId(),l=s.getSheetId();if(i.getFilterModel(c,l))return a.executeCommand(G.id,{unitId:c,subUnitId:l});let u=e.get(n.SheetsSelectionsService).getCurrentLastSelection();if(!u)return!1;let d=u.range,f=(0,n.isSingleCellSelection)(u)?(0,n.expandToContinuousRange)(d,{left:!0,right:!0,up:!0,down:!0},s):d.startRow===d.endRow?(0,n.expandToContinuousRange)(d,{down:!0},s):d;return a.executeCommand(W.id,{unitId:c,subUnitId:l,range:f})}},ue={id:`sheet.command.set-filter-criteria`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(z),{unitId:o,subUnitId:s}=i,c=a.getFilterModel(o,s);if(!c)return!1;let{col:l,criteria:u}=r,d=c.getRange();if(!d||l<d.startColumn||l>d.endColumn)return!1;let f=e.get(t.ICommandService),p=e.get(t.IUndoRedoService),m=he(o,s,l,c.getFilterColumn(l)),h={id:V.id,params:{unitId:o,subUnitId:s,col:l,criteria:u}},g=f.syncExecuteCommand(h.id,h.params);return g&&(p.pushUndoRedo({unitID:o,undoMutations:[m],redoMutations:[h]}),f.executeCommand(n.MarkDirtyFilterChangeMutation.id,{unitId:o,subUnitId:s,filterRange:d})),g}},de={id:`sheet.command.clear-filter-criteria`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(z),{unitId:o,subUnitId:s}=i,c=a.getFilterModel(o,s);if(!c)return!1;let l=c.getRange();if(!l)return!1;let u=e.get(t.IUndoRedoService),d=e.get(t.ICommandService),f=c.serialize(),p=K(o,s,f),m=me(o,s,f);return(0,t.sequenceExecute)(m,d).result?(u.pushUndoRedo({unitID:o,undoMutations:p,redoMutations:m}),d.executeCommand(n.MarkDirtyFilterChangeMutation.id,{unitId:o,subUnitId:s,filterRange:l}),!0):!1}},fe={id:`sheet.command.re-calc-filter`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(z),a=e.get(t.ICommandService),o=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!o)return!1;let{unitId:s,subUnitId:c}=o;return i.getFilterModel(o.unitId,o.subUnitId)?a.executeCommand(U.id,{unitId:s,subUnitId:c}):!1}};function pe(e,t,n){let r=[],i={id:B.id,params:{unitId:e,subUnitId:t,range:n.ref}};return r.push(i),K(e,t,n).forEach(e=>r.push(e)),r}function K(e,t,n){var r;let i=[];return(r=n.filterColumns)==null||r.forEach(n=>{let r={id:V.id,params:{unitId:e,subUnitId:t,col:n.colId,criteria:n}};i.push(r)}),i}function me(e,t,n){var r;let i=[];return(r=n.filterColumns)==null||r.forEach(n=>{let r={id:V.id,params:{unitId:e,subUnitId:t,col:n.colId,criteria:null}};i.push(r)}),i}function he(e,t,n,r){if(!r)return{id:V.id,params:{unitId:e,subUnitId:t,col:n,criteria:null}};let i=r.serialize();return{id:V.id,params:{unitId:e,subUnitId:t,col:n,criteria:i}}}let q=`sheets-filter.config`;Symbol(q);let J={};function ge(e,t){for(let n=0;n<e.length;n++){let r=n;if(e[n])for(let i=n+1;i<e.length;i++)e[r]&&e[i]&&t(e[r],e[i])&&(e[r]=null,r=i)}return e.filter(e=>e!==null)}function Y(e){return ge(e,(e,t)=>e.id===V.id&&t.id===V.id&&e.params.unitId===t.params.unitId&&e.params.subUnitId===t.params.subUnitId&&e.params.col===t.params.col)}let X=class extends t.Disposable{constructor(e,n,r,i,a,o,s){super(),this._commandService=e,this._sheetInterceptorService=n,this._sheetsFilterService=r,this._univerInstanceService=i,this._refRangeService=a,this._dataSyncPrimaryController=o,this._zebraCrossingCacheController=s,O(this,`_disposableCollection`,new t.DisposableCollection),this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener(),this._initErrorHandling(),this._initZebraCrossingCacheListener()}_initZebraCrossingCacheListener(){this.disposeWithMe(this._sheetsFilterService.activeFilterModel$.subscribe(e=>{e&&this.disposeWithMe(e.filteredOutRows$.subscribe(()=>{this._zebraCrossingCacheController.updateZebraCrossingCache(e.unitId,e.subUnitId)}))}))}_initCommands(){[V,B,U,H].forEach(e=>{var t;this.disposeWithMe(this._commandService.registerCommand(e)),(t=this._dataSyncPrimaryController)==null||t.registerSyncingMutations(e)})}_initInterceptors(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>this._getUpdateFilter(e)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===n.SetWorksheetActiveOperation.id){let t=e.params,n=t.subUnitId,r=t.unitId;if(!n||!r)return;this._registerRefRange(r,n)}if(e.id===B.id){let t=e.params,n=t.subUnitId,r=t.unitId;if(!n||!r)return;this._registerRefRange(t.unitId,t.subUnitId)}})),this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe(e=>{if(e){let t=this._univerInstanceService.getUniverSheetInstance(e),n=t==null?void 0:t.getActiveSheet();n&&this._registerRefRange(e,n.getSheetId())}}))}_registerRefRange(e,t){var r;this._disposableCollection.dispose();let i=this._univerInstanceService.getUniverSheetInstance(e),a=i==null?void 0:i.getSheetBySheetId(t);if(!i||!a)return;let o=(r=this._sheetsFilterService.getFilterModel(e,t))==null?void 0:r.getRange();o&&this._disposableCollection.add(this._refRangeService.registerRefRange(o,r=>{switch(r.id){case n.InsertRowCommand.id:{let n=r.params,i=n.unitId||e,a=n.subUnitId||t;return this._handleInsertRowCommand(n,i,a)}case n.InsertColCommand.id:{let n=r.params,i=n.unitId||e,a=n.subUnitId||t;return this.handleInsertColCommand(n.range,i,a)}case n.RemoveColCommand.id:{let n=r.params;return this.handleRemoveColCommand(n.range,e,t)}case n.RemoveRowCommand.id:{let n=r.params;return this._handleRemoveRowCommand(n,e,t)}case n.EffectRefRangId.MoveColsCommandId:{let n=r.params;return this.handleMoveColsCommand({fromRange:n.fromRange,toRange:n.toRange},e,t)}case n.EffectRefRangId.MoveRowsCommandId:{let n=r.params;return this._handleMoveRowsCommand(n,e,t)}case n.MoveRangeCommand.id:{let n=r.params;return this._handleMoveRangeCommand(n,e,t)}}return{redos:[],undos:[]}},e,t))}_getUpdateFilter(e){let{id:t}=e;switch(t){case n.RemoveSheetCommand.id:{let t=e.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case n.CopySheetCommand.id:{let{targetSubUnitId:t,unitId:n,subUnitId:r}=e.params;return!n||!r||!t?this._handleNull():this._handleCopySheetCommand(n,r,t)}}return{redos:[],undos:[]}}handleInsertColCommand(e,t,n){var r;let i=this._sheetsFilterService.getFilterModel(t,n),a=(r=i==null?void 0:i.getRange())==null?null:r;if(!i||!a)return this._handleNull();let{startColumn:o,endColumn:s}=a,{startColumn:c,endColumn:l}=e,u=l-c+1;if(l>s)return this._handleNull();let d=[],f=[],p=c,m={unitId:t,subUnitId:n,range:{...a,startColumn:c<=o?o+u:o,endColumn:s+u}},h={unitId:t,subUnitId:n,range:a};d.push({id:B.id,params:m}),f.push({id:B.id,params:h});let g=i.getAllFilterColumns().filter(e=>e[0]>=p);if(g.length!==0){let{newRange:e,oldRange:r}=this._moveCriteria(t,n,g,u);d.push(...r.redos,...e.redos),f.push(...e.undos,...r.undos)}return{redos:Y(d),undos:Y(f)}}_handleInsertRowCommand(e,t,n){var r;let i=this._sheetsFilterService.getFilterModel(t,n),a=(r=i==null?void 0:i.getRange())==null?null:r;if(!i||!a)return this._handleNull();let{startRow:o,endRow:s}=a,{startRow:c,endRow:l}=e.range,u=l-c+1;if(l>s)return this._handleNull();let d=[],f=[],p={unitId:t,subUnitId:n,range:{...a,startRow:c<=o?o+u:o,endRow:s+u}},m={unitId:t,subUnitId:n,range:a};return d.push({id:B.id,params:p}),f.push({id:B.id,params:m}),{redos:Y(d),undos:Y(f)}}handleRemoveColCommand(e,t,n){var r;let i=this._sheetsFilterService.getFilterModel(t,n),a=(r=i==null?void 0:i.getRange())==null?null:r;if(!i||!a)return this._handleNull();let{startColumn:o,endColumn:s}=a,{startColumn:c,endColumn:l}=e;if(c>s)return this._handleNull();let u=[],d=[],f=l<o?0:Math.min(l,s)-Math.max(c,o)+1,p=l-c+1,m=i.getAllFilterColumns();m.forEach(e=>{let[r,i]=e;r<=l&&r>=c&&(u.push({id:V.id,params:{unitId:t,subUnitId:n,col:r,criteria:null}}),d.push({id:V.id,params:{unitId:t,subUnitId:n,col:r,criteria:{...i.serialize(),colId:r}}}))});let h=m.filter(e=>{let[t,n]=e;return t>l}),g={undos:[],redos:[]};if(h.length>0){let{oldRange:e,newRange:r}=this._moveCriteria(t,n,h,-p);g=r,u.push(...e.redos),d.unshift(...e.undos)}if(f===s-o+1){let e={unitId:t,subUnitId:n};u.push({id:H.id,params:e}),d.unshift({id:B.id,params:{range:a,unitId:t,subUnitId:n}})}else{let e=o<=c?o:f===0?o-p:c,r=o<=c?s-f:s-p,i={unitId:t,subUnitId:n,range:{...a,startColumn:e,endColumn:r}};u.push({id:B.id,params:i}),d.unshift({id:B.id,params:{range:a,unitId:t,subUnitId:n}}),u.push(...g.redos),d.unshift(...g.undos)}return{undos:d,redos:u}}_handleRemoveRowCommand(e,t,n){let r=this._sheetsFilterService.getFilterModel(t,n);if(!r)return this._handleNull();let i=r.getRange(),{startRow:a,endRow:o}=i,{startRow:s,endRow:c}=e.range;if(s>o)return this._handleNull();if(c<a)return{undos:[{id:B.id,params:{range:i,unitId:t,subUnitId:n}}],redos:[{id:B.id,params:{range:{...i,startRow:a-(c-s+1),endRow:o-(c-s+1)},unitId:t,subUnitId:n}}]};let l=[],u=[],d=r.getAllFilterColumns(),f=a<=c&&a>=s;u.push({id:B.id,params:{range:i,unitId:t,subUnitId:n}});let p=Math.min(c,o)-Math.max(s,a)+1;if(p===o-a+1||f){let e={unitId:t,subUnitId:n};l.push({id:H.id,params:e}),d.forEach(e=>{let[r,i]=e,a={unitId:t,subUnitId:n,col:r,criteria:{...i.serialize(),colId:r}};u.push({id:V.id,params:a})})}else{var m;let e=(m=this._univerInstanceService.getUniverSheetInstance(t))==null?void 0:m.getSheetBySheetId(n);if(!e)return this._handleNull();let r=[];for(let t=s;t<=c;t++)e.getRowFiltered(t)&&r.push(t);let u=Math.min(a,s),d=u+(o-a)-p+r.length,f={unitId:t,subUnitId:n,range:{...i,startRow:u,endRow:d}};l.push({id:B.id,params:f})}return{undos:Y(u),redos:Y(l)}}handleMoveColsCommand({fromRange:e,toRange:n},r,i){var a;let o=this._sheetsFilterService.getFilterModel(r,i),s=(a=o==null?void 0:o.getRange())==null?null:a;if(!o||!s)return this._handleNull();let{startColumn:c,endColumn:l}=s;if(e.endColumn<c&&n.startColumn<=c||e.startColumn>l&&n.endColumn>l)return this._handleNull();let u=[],d=[],f={};for(let e=c;e<=l;e++)f[e]={colIndex:e,filter:o.getFilterColumn(e)};(0,t.moveMatrixArray)(e.startColumn,e.endColumn-e.startColumn+1,n.startColumn,f);let p=s.startColumn,m=s.endColumn;c>=e.startColumn&&c<=e.endColumn&&n.startColumn>e.startColumn&&e.endColumn<l&&(p=e.endColumn+1),l>=e.startColumn&&l<=e.endColumn&&n.startColumn<e.startColumn&&e.startColumn>c&&(m=e.startColumn-1);let h=Object.keys(f).map(e=>Number(e)),g=h.find(e=>f[e].colIndex===m),_=h.find(e=>f[e].colIndex===p);if(h.forEach(e=>{let{colIndex:t,filter:n}=f[e],a=e;if(n){var s;if(a>=_&&a<=g){var c;let e={unitId:r,subUnitId:i,col:a,criteria:{...n.serialize(),colId:a}},t={unitId:r,subUnitId:i,col:a,criteria:o.getFilterColumn(a)?{...(c=o.getFilterColumn(a))==null?void 0:c.serialize(),colId:a}:null};u.push({id:V.id,params:e}),d.push({id:V.id,params:t})}if(!((s=f[t])!=null&&s.filter)){let e={unitId:r,subUnitId:i,col:t,criteria:null};u.push({id:V.id,params:e}),d.push({id:V.id,params:{unitId:r,subUnitId:i,col:t,criteria:{...n.serialize(),colId:t}}})}}}),c!==_||l!==g){let e={unitId:r,subUnitId:i,range:{...s,startColumn:_,endColumn:g}};u.unshift({id:B.id,params:e}),d.unshift({id:B.id,params:{range:s,unitId:r,subUnitId:i}})}return{undos:d,redos:u}}_handleMoveRowsCommand(e,n,r){var i;let a=this._sheetsFilterService.getFilterModel(n,r),o=(i=a==null?void 0:a.getRange())==null?null:i;if(!a||!o)return this._handleNull();let{startRow:s,endRow:c}=o,{fromRange:l,toRange:u}=e;if(l.endRow<s&&u.startRow<=s||l.startRow>c&&u.endRow>c)return this._handleNull();let d=[],f=[],p={};for(let e=s;e<=c;e++)p[e]={oldIndex:e};let m=s,h=c;c>=l.startRow&&c<=l.endRow&&u.startRow<l.startRow&&l.startRow>s&&(h=l.startRow-1),(0,t.moveMatrixArray)(l.startRow,l.endRow-l.startRow+1,u.startRow,p);let g=Object.keys(p).map(e=>Number(e)),_=g.find(e=>p[e].oldIndex===h),v=g.find(e=>p[e].oldIndex===m);if(s!==v||c!==_){let e={unitId:n,subUnitId:r,range:{...o,startRow:v,endRow:_}};d.push({id:B.id,params:e},{id:U.id,params:{unitId:n,subUnitId:r}}),f.push({id:B.id,params:{range:o,unitId:n,subUnitId:r}},{id:U.id,params:{unitId:n,subUnitId:r}})}return{redos:d,undos:f}}_handleMoveRangeCommand(e,n,r){let{fromRange:i,toRange:a}=e,o=this._sheetsFilterService.getFilterModel(n,r);if(!o)return this._handleNull();let s=o.getRange();if(!s)return this._handleNull();let c=[],l=[];if(t.Rectangle.contains(i,s)){let e=s.startRow-i.startRow,t=s.startColumn-i.startColumn,u={startRow:a.startRow+e,startColumn:a.startColumn+t,endRow:a.startRow+e+(s.endRow-s.startRow),endColumn:a.startColumn+t+(s.endColumn-s.startColumn)},d={id:H.id,params:{unitId:n,subUnitId:r}},f={id:B.id,params:{unitId:n,subUnitId:r,range:u}},p={id:B.id,params:{unitId:n,subUnitId:r,range:s}};c.push(d,f),l.push(d,p);let m=o.getAllFilterColumns(),h=a.startColumn-i.startColumn;m.forEach(e=>{let[t,i]=e;i&&(c.push({id:V.id,params:{unitId:n,subUnitId:r,col:t+h,criteria:{...i.serialize(),colId:t+h}}}),l.push({id:V.id,params:{unitId:n,subUnitId:r,col:t,criteria:{...i.serialize(),colId:t}}}))})}else if(t.Rectangle.intersects(a,s)){let e={...s,endRow:Math.max(s.endRow,a.endRow)};c.push({id:B.id,params:{unitId:n,subUnitId:r,range:e}}),l.push({id:B.id,params:{unitId:n,subUnitId:r,range:s}})}return{redos:c,undos:l}}_handleRemoveSheetCommand(e,t,n){let r=this._sheetsFilterService.getFilterModel(t,n);if(!r)return this._handleNull();let i=r.getRange();if(!i)return this._handleNull();let a=[],o=[];return r.getAllFilterColumns().forEach(([e,r])=>{o.push({id:V.id,params:{unitId:t,subUnitId:n,col:e,criteria:{...r.serialize(),colId:e}}})}),a.push({id:H.id,params:{unitId:t,subUnitId:n,range:i}}),o.unshift({id:B.id,params:{range:i,unitId:t,subUnitId:n}}),{undos:o,redos:a}}_handleCopySheetCommand(e,t,n){let r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();let i=r.getRange();if(!i)return this._handleNull();let a=[],o=[],s=[];return r.getAllFilterColumns().forEach(([t,r])=>{a.push({id:V.id,params:{unitId:e,subUnitId:n,col:t,criteria:{...r.serialize(),colId:t}}}),s.push({id:V.id,params:{unitId:e,subUnitId:n,col:t,criteria:null}})}),s.push({id:H.id,params:{unitId:e,subUnitId:n,range:i}}),a.unshift({id:B.id,params:{range:i,unitId:e,subUnitId:n}}),{undos:o,redos:a,preUndos:s,preRedos:[]}}_handleNull(){return{redos:[],undos:[]}}_initRowFilteredInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(n.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(e,t)=>{var n,r;return e?!0:(n=(r=this._sheetsFilterService.getFilterModel(t.unitId,t.subUnitId))==null?void 0:r.isRowFiltered(t.row))==null?!1:n}}))}_moveCriteria(e,t,n,r){let i={unitId:e,subUnitId:t,criteria:null,col:-1},a=[],o=[],s=[],c=[];return n.forEach(e=>{let[t,n]=e;o.push({id:V.id,params:{...i,col:t}}),a.push({id:V.id,params:{...i,col:t,criteria:{...n.serialize(),colId:t}}})}),n.forEach(e=>{let[t,n]=e;c.push({id:V.id,params:{...i,col:t+r,criteria:{...n.serialize(),colId:t+r}}}),s.push({id:V.id,params:{...i,col:t+r,criteria:null}})}),{newRange:{redos:c,undos:s},oldRange:{redos:o,undos:a}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((e,t)=>{let{unitId:r,subUnitId:i}=e.params||{},a=this._sheetsFilterService.getFilterModel(r,i);if(!a)return;let o=Array.from(a.filteredOutRows).sort((e,t)=>e-t),s=[],c=!1;if(e.id===n.RemoveRowMutation.id){let{startRow:t,endRow:n}=e.params.range,r=o.filter(e=>e>=t&&e<=n);o.forEach(e=>{if(e<t)s.push(e);else if(c=!0,e<=n){let e=Math.max(t,s.length?s[s.length-1]+1:t);s.push(e)}else s.push(e-(n-t+1-r.length))})}if(e.id===n.InsertRowMutation.id){let{startRow:t,endRow:n}=e.params.range;o.forEach(e=>{e>=t?(c=!0,s.push(e+(n-t+1))):s.push(e)})}if(c&&(a.filteredOutRows=new Set(s)),e.id===n.SetRangeValuesMutation.id&&!(t!=null&&t.onlyLocal)){let t=this._getExtendRegion(r,i);if(t){let a=e.params.cellValue;if(a)for(let e=t.startColumn;e<=t.endColumn;e++){var l;let o=a==null||(l=a[t.startRow])==null?void 0:l[e];if(o&&this._cellHasValue(o)){var u;let e=(u=this._univerInstanceService.getUnit(r))==null?void 0:u.getSheetBySheetId(i);if(e){let a=(0,n.expandToContinuousRange)(t,{down:!0},e),o=this._sheetsFilterService.getFilterModel(r,i),s=o.getRange();o.setRange({...s,endRow:a.endRow}),this._registerRefRange(r,i)}}}}}}))}_getExtendRegion(e,t){var n;let r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return null;let i=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);if(!i)return null;let a=r.getRange();if(!a)return null;let o=i.getRowCount()-1,s=i.getRowManager();for(let e=a.endRow+1;e<=o;e++)if(s.getRowRawVisible(e))return{startRow:e,endRow:e,startColumn:a.startColumn,endColumn:a.endColumn};return null}_initErrorHandling(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let t=e.params,r=(0,n.getSheetCommandTarget)(this._univerInstanceService,t);if(!r)return;let{subUnitId:i,unitId:a}=r,o=this._sheetsFilterService.getFilterModel(a,i);if(!o)return;let s=o.getRange();if(e.id===n.MoveRowsCommand.id&&t.fromRange.startRow<=s.startRow&&t.fromRange.endRow<s.endRow&&t.fromRange.endRow>=s.startRow)throw this._sheetsFilterService.setFilterErrorMsg(`sheets-filter.msg.filter-header-forbidden`),Error(`[SheetsFilterController]: Cannot move header row of filter`)}))}_cellHasValue(e){let t=Object.values(e);return!(t.length===0||t.every(e=>e==null))}};X=L([I(0,t.ICommandService),I(1,(0,t.Inject)(n.SheetInterceptorService)),I(2,(0,t.Inject)(z)),I(3,t.IUniverInstanceService),I(4,(0,t.Inject)(n.RefRangeService)),I(5,(0,t.Optional)(a.DataSyncPrimaryController)),I(6,(0,t.Inject)(n.ZebraCrossingCacheController))],X);let _e=[V.id,U.id],ve=[n.InsertColMutation.id,n.RemoveColMutation.id,n.MoveColsMutation.id],Z=class extends t.Disposable{get visible(){return this._visible$.getValue()}get enabled(){return this._enabled$.getValue()}constructor(e,n,i){super(),this._sheetsFilterController=e,this._commandService=n,this._configService=i,O(this,`_d`,new t.DisposableCollection),O(this,`_visible$`,new r.BehaviorSubject(!1)),O(this,`visible$`,this._visible$.asObservable()),O(this,`_enabled$`,new r.BehaviorSubject(!0)),O(this,`enabled$`,this._enabled$.asObservable());let a=this._configService.getConfig(q);if(a!=null&&a.enableSyncSwitch&&(this._visible$.next(!0),typeof a.enableSyncSwitch==`object`)){var o;this.setEnabled((o=a.enableSyncSwitch.defaultValue)==null?!0:o)}}setEnabled(e){this._enabled$.next(e),e?this._d.dispose():this._initOnlyLocalListener()}_initOnlyLocalListener(){this._d.add(this._commandService.beforeCommandExecuted((e,t)=>{_e.includes(e.id)&&(t||(t={}),t.onlyLocal=!0)})),this._d.add(this._commandService.onCommandExecuted((e,r)=>{if(ve.includes(e.id)&&r!=null&&r.fromCollab){if(e.id===n.InsertColMutation.id){let{range:n,unitId:i,subUnitId:a}=e.params,{redos:o}=this._sheetsFilterController.handleInsertColCommand(n,i,a);(0,t.sequenceExecute)(o,this._commandService,r)}else if(e.id===n.RemoveColMutation.id){let{range:n,unitId:i,subUnitId:a}=e.params,{redos:o}=this._sheetsFilterController.handleRemoveColCommand(n,i,a);(0,t.sequenceExecute)(o,this._commandService,r)}else if(e.id===n.MoveColsMutation.id){let{sourceRange:n,targetRange:i,unitId:a,subUnitId:o}=e.params,{redos:s}=this._sheetsFilterController.handleMoveColsCommand({fromRange:n,toRange:i},a,o);(0,t.sequenceExecute)(s,this._commandService,r)}}}))}};Z=L([I(0,(0,t.Inject)(X)),I(1,t.ICommandService),I(2,t.IConfigService)],Z);var ye=`@univerjs/sheets-filter`,be=`0.21.1`;let Q=class extends t.Disposable{constructor(e,t,n,r){super(),this._activeDirtyManagerService=e,this._sheetRowFilteredService=t,this._sheetsFilterService=n,this._univerInstanceService=r,this._initFormulaDirtyRange(),this._registerSheetRowFiltered()}_initFormulaDirtyRange(){d.forEach(e=>{this._activeDirtyManagerService.register(e,{commandId:e,getDirtyData:e=>{let{unitId:t,subUnitId:n}=e.params;return{dirtyRanges:this._getHideRowMutation(t,n),clearDependencyTreeCache:{[t]:{[n]:`1`}}}}})})}_getHideRowMutation(e,t){var n,r;let i=(n=this._sheetsFilterService.getFilterModel(e,t))==null?void 0:n.getRange(),a=(r=this._univerInstanceService.getUnit(e))==null?void 0:r.getSheetBySheetId(t);if(i==null||a==null)return[];let{startRow:o,endRow:s}=i;return[{unitId:e,sheetId:t,range:{startRow:o,startColumn:0,endRow:s,endColumn:a.getColumnCount()-1}}]}_registerSheetRowFiltered(){this._sheetRowFilteredService.register((e,t,n)=>{var r,i;return(r=(i=this._sheetsFilterService.getFilterModel(e,t))==null?void 0:i.isRowFiltered(n))==null?!1:r})}};Q=L([I(0,(0,t.Inject)(o.IActiveDirtyManagerService)),I(1,(0,t.Inject)(o.ISheetRowFilteredService)),I(2,(0,t.Inject)(z)),I(3,t.IUniverInstanceService)],Q);let $=class extends t.Plugin{constructor(e=J,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},J,this._config);this._configService.setConfig(q,i)}onStarting(){[[Q],[z],[X],[Z]].forEach(e=>this._injector.add(e))}onReady(){(0,t.touchDependencies)(this._injector,[[Q],[X],[Z]])}};O($,`type`,t.UniverInstanceType.UNIVER_SHEET),O($,`pluginName`,R),O($,`packageName`,ye),O($,`version`,be),$=L([I(1,(0,t.Inject)(t.Injector)),I(2,t.IConfigService)],$),e.ClearSheetsFilterCriteriaCommand=de,e.CustomFilterOperator=p,e.FILTER_MUTATIONS=d,e.FilterBy=f,e.FilterColumn=j,e.FilterModel=A,e.ReCalcSheetsFilterCommand=fe,e.ReCalcSheetsFilterMutation=U,e.RemoveSheetFilterCommand=G,e.RemoveSheetsFilterMutation=H,e.SHEET_FILTER_SNAPSHOT_ID=R,e.SetSheetFilterRangeCommand=W,e.SetSheetsFilterCriteriaCommand=ue,e.SetSheetsFilterCriteriaMutation=V,e.SetSheetsFilterRangeMutation=B,Object.defineProperty(e,`SheetsFilterService`,{enumerable:!0,get:function(){return z}}),Object.defineProperty(e,`SheetsFilterSyncController`,{enumerable:!0,get:function(){return Z}}),e.SmartToggleSheetsFilterCommand=le,Object.defineProperty(e,`UniverSheetsFilterPlugin`,{enumerable:!0,get:function(){return $}}),e.equals=v,e.getCustomFilterFn=S,e.greaterThan=m,e.greaterThanOrEqualTo=h,e.lessThan=g,e.lessThanOrEqualTo=_,e.notEquals=y});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`rxjs`),require(`@univerjs/engine-render`),require(`@univerjs/rpc`),require(`@univerjs/engine-formula`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`rxjs`,`@univerjs/engine-render`,`@univerjs/rpc`,`@univerjs/engine-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFilter={},e.UniverCore,e.UniverSheets,e.rxjs,e.UniverEngineRender,e.UniverRpc,e.UniverEngineFormula))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let s=`sheet.mutation.set-filter-range`,c=`sheet.mutation.set-filter-criteria`,l=`sheet.mutation.remove-filter`,u=`sheet.mutation.re-calc-filter`,d=new Set([s,c,l,u]),f=function(e){return e[e.VALUES=0]=`VALUES`,e[e.COLORS=1]=`COLORS`,e[e.CONDITIONS=2]=`CONDITIONS`,e}({}),p=function(e){return e.EQUAL=`equal`,e.GREATER_THAN=`greaterThan`,e.GREATER_THAN_OR_EQUAL=`greaterThanOrEqual`,e.LESS_THAN=`lessThan`,e.LESS_THAN_OR_EQUAL=`lessThanOrEqual`,e.NOT_EQUALS=`notEqual`,e}({}),m={operator:`greaterThan`,fn:(e,t)=>C(e)?e>t:!1},h={operator:`greaterThanOrEqual`,fn:(e,t)=>C(e)?e>=t:!1},g={operator:`lessThan`,fn:(e,t)=>C(e)?e<t:!1},_={operator:`lessThanOrEqual`,fn:(e,t)=>C(e)?e<=t:!1},v={operator:`equal`,fn:(e,t)=>C(e)?e===t:!1},y={operator:`notEqual`,fn:(e,n)=>{if(typeof n==`string`){if(n===` `)return e!=null;let r=T(e);return r&&te(n)?!(0,t.createREGEXFromWildChar)(n).test(r):r!==n}return C(e)?e!==n:!0}},b=new Map([]);[m,h,g,_,v,y].forEach(e=>{b.set(e.operator,e)});function ee(e){return!!e}let x={fn:(e,n)=>{let r=T(e);return r===null?n===``:(0,t.createREGEXFromWildChar)(n).test(r)}};function S(e){return e?b.get(e):x}function C(e){return typeof e==`number`}function w(e){return!!(typeof e==`number`||typeof e==`string`&&(0,t.isNumeric)(e))}function T(e){return typeof e==`boolean`||e==null?null:typeof e==`string`?e:e.toString()}function te(e){return typeof e==`number`?!1:e.indexOf(`*`)!==-1||e.indexOf(`?`)!==-1}function E(e){"@babel/helpers - typeof";return E=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},E(e)}function ne(e,t){if(E(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(E(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function D(e){var t=ne(e,`string`);return E(t)==`symbol`?t:t+``}function O(e,t,n){return(t=D(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let k=()=>new Set;var A=class e extends t.Disposable{get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}constructor(e,t,n){super(),this.unitId=e,this.subUnitId=t,this._worksheet=n,O(this,`_filteredOutRows$`,new r.BehaviorSubject(k())),O(this,`filteredOutRows$`,this._filteredOutRows$.asObservable()),O(this,`_hasCriteria$`,new r.BehaviorSubject(!1)),O(this,`hasCriteria$`,this._hasCriteria$.asObservable()),O(this,`_filterColumnByIndex`,new Map),O(this,`_alreadyFilteredOutRows`,k()),O(this,`_range`,void 0)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete(),this._worksheet=null}serialize(){let e={ref:t.Rectangle.clone(this._range),filterColumns:this._getAllFilterColumns(!0).sort(([e],[t])=>e-t).map(([e,t])=>t.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(t,n,r,i){let a=new e(t,n,r);return a._dump(i),a}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.filter(e=>!(!e.filters&&!e.colorFilters&&!e.customFilters)).forEach(e=>this._setCriteriaWithoutReCalc(e.colId,e)),e.cachedFilteredOut?(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()):e.filterColumns&&e.filterColumns.length>0&&(this._reCalcAllColumns(),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw Error(`[FilterModel] could not get range before a range is set!`);return this._range}getFilteredOutRowsExceptCol(e){return this._getAllFilterColumns(!0).filter(([t])=>t!==e).reduce((e,[,n])=>{let r=n.calc({getAlreadyFilteredOutRows:()=>e});return r?(0,t.mergeSets)(e,r):e},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,n])=>{n.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,n=!1){if(!this._range)throw Error(`[FilterModel] could not set criteria before a range is set!`);if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),n&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),n&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))==null?null:t}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){let t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([e,t])=>t)}_reCalcAllColumns(){this._alreadyFilteredOutRows=k(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns()}_setCriteriaWithoutReCalc(e,t){let n=this._range;if(!n)throw Error(`[FilterModel] could not set criteria before a range is set!`);let{startColumn:r,endColumn:i}=n;if(e>i||e<r)throw Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);let a;this._filterColumnByIndex.has(e)?a=this._filterColumnByIndex.get(e):(a=new j(this.unitId,this.subUnitId,this._worksheet,t,{getAlreadyFilteredOutRows:()=>this._alreadyFilteredOutRows}),a.setRangeAndColumn(n,e),this._filterColumnByIndex.set(e,a)),a.setCriteria(t)}_removeCriteria(e){let t=this._filterColumnByIndex.get(e);t&&(t.dispose(),this._filterColumnByIndex.delete(e))}_emit(){this._filteredOutRows$.next(this._alreadyFilteredOutRows)}_emitHasCriteria(){this._hasCriteria$.next(this._filterColumnByIndex.size>0)}_rebuildAlreadyFilteredOutRowsWithCache(){let e=this._getAllFilterColumns().filter(e=>e.hasCache()).reduce((e,n)=>(0,t.mergeSets)(e,n.filteredOutRows),new Set);this._alreadyFilteredOutRows=e}_reCalcWithNoCacheColumns(){let e=this._getAllFilterColumns().filter(e=>!e.hasCache());for(let n of e){let e=n.reCalc();e&&(this._alreadyFilteredOutRows=(0,t.mergeSets)(this._alreadyFilteredOutRows,e))}}},j=class extends t.Disposable{get filteredOutRows(){return this._filteredOutRows}get filterBy(){return this._filterBy}constructor(e,t,n,r,i){super(),this.unitId=e,this.subUnitId=t,this._worksheet=n,this._criteria=r,this._filterColumnContext=i,O(this,`_filteredOutRows`,null),O(this,`_filterFn`,null),O(this,`_range`,null),O(this,`_column`,0),O(this,`_filterBy`,0)}dispose(){super.dispose(),this._filteredOutRows=null}__clearCache(){this._filteredOutRows=null}serialize(){if(!this._criteria)throw Error(`[FilterColumn]: could not serialize without a filter column!`);return t.Tools.deepClone({...this._criteria,colId:this._column})}hasCache(){return this._filteredOutRows!==null}setRangeAndColumn(e,t){this._range=e,this._column=t}setCriteria(e){this._criteria=e,this._generateFilterFn(),this._filteredOutRows=null}getColumnData(){return t.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw Error(`[FilterColumn] cannot calculate without a filter fn!`);if(!this._range)throw Error(`[FilterColumn] cannot calculate without a range!`);if(typeof this._column!=`number`)throw TypeError(`[FilterColumn] cannot calculate without a column offset!`);let n=this._column,r={startColumn:n,endColumn:n,startRow:this._range.startRow+1,endRow:this._range.endRow},i=new Set,a=e.getAlreadyFilteredOutRows();for(let e of this._worksheet.iterateByColumn(r,!1,!1)){let{row:n,rowSpan:r,col:o}=e;if(!(a.has(n)&&(!r||r===1))&&!(this._filterBy===0?this._filterFn((0,t.extractPureTextFromCell)(this._worksheet.getCell(n,o))):this._filterBy===1?this._filterFn(this._worksheet.getComposedCellStyle(n,o)):this._filterFn(ce(this._worksheet,n,o)))&&(i.add(n),r))for(let e=1;e<r;e++)i.add(n+e)}return i}_generateFilterFn(){this._criteria&&(this._filterFn=re(this._criteria),this._filterBy=this._criteria.filters?0:this._criteria.colorFilters?1:2)}};function re(e){if(e.filters)return ie(e.filters);if(e.colorFilters)return ae(e.colorFilters);if(e.customFilters)return oe(e.customFilters);throw Error(`[FilterModel]: other types of filters are not supported yet.`)}function ie(e){let t=!!e.blank,n=new Set(e.filters);return e=>e===void 0||e===``?t:n.has(typeof e==`string`?e:`${e}`)}function ae(e){if(e.cellFillColors){let n=new Set(e.cellFillColors);return e=>{var r;if(!e||!((r=e.bg)!=null&&r.rgb))return!!n.has(null);let i=new t.ColorKit(e.bg.rgb).toRgbString();return n.has(i)}}if(e.cellTextColors){let n=new Set(e.cellTextColors);return e=>{var r;if(!e||!((r=e.cl)!=null&&r.rgb))return!!n.has(i.COLOR_BLACK_RGB);let a=new t.ColorKit(e.cl.rgb).toRgbString();return n.has(a)}}throw Error(`[FilterModel]: color filters are not supported yet.`)}function oe(e){let t=e.customFilters.map(e=>P(e));return N(t)?e.and?se(t):M(t):t[0]}function se(e){let[t,n]=e;return e=>t(e)&&n(e)}function M(e){let[t,n]=e;return e=>t(e)||n(e)}function N(e){return e.length===2}function P(e){let t=e.val;if(e.operator===`notEqual`&&!w(t))return e=>y.fn(e,t);if(ee(e.operator)){if(!w(t))return()=>!1;let n=S(e.operator),r=Number(t);return e=>n.fn(e,r)}let n=S(e.operator);return e=>n.fn(e,t)}function ce(e,n,r){let i=e.getCell(n,r);if(!i)return null;let a=e.getCellRaw(n,r);return i&&!a?F(i):a?i.t===t.CellValueType.NUMBER&&typeof i.v==`string`?a.v:i.t===t.CellValueType.NUMBER?Number(a.v):F(a):null}function F(e){var n;let r=(n=e.p)==null||(n=n.body)==null?void 0:n.dataStream;if(r)return r.trimEnd();let i=e.v;return typeof i==`string`?e.t===t.CellValueType.BOOLEAN?i.toUpperCase():i:typeof i==`number`?e.t===t.CellValueType.BOOLEAN?i?`TRUE`:`FALSE`:i:typeof i==`boolean`?i?`TRUE`:`FALSE`:``}function I(e,t){return function(n,r){t(n,r,e)}}function L(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let R=`SHEET_FILTER_PLUGIN`,z=class extends t.Disposable{get activeFilterModel(){return this._activeFilterModel$.getValue()}constructor(e,t,n){super(),this._resourcesManagerService=e,this._univerInstanceService=t,this._commandService=n,O(this,`_filterModels`,new Map),O(this,`_loadedUnitId$`,new r.BehaviorSubject(null)),O(this,`loadedUnitId$`,this._loadedUnitId$.asObservable()),O(this,`_errorMsg$`,new r.BehaviorSubject(null)),O(this,`errorMsg$`,this._errorMsg$.asObservable()),O(this,`_activeFilterModel$`,new r.BehaviorSubject(null)),O(this,`activeFilterModel$`,this._activeFilterModel$.asObservable()),this._initModel(),this._initActiveFilterModel()}ensureFilterModel(e,t){let n=this.getFilterModel(e,t);if(n)return n;let r=this._univerInstanceService.getUniverSheetInstance(e);if(!r)throw Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${e}!`);let i=r.getSheetBySheetId(t);if(!i)throw Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${t}!`);let a=new A(e,t,i);return this._cacheFilterModel(e,t,a),a}getFilterModel(e,t){var n,r;return(n=(r=this._filterModels.get(e))==null?void 0:r.get(t))==null?null:n}removeFilterModel(e,t){let n=this.getFilterModel(e,t);return n?(n.dispose(),this._filterModels.get(e).delete(t),!0):!1}setFilterErrorMsg(e){this._errorMsg$.next(e)}_updateActiveFilterModel(){let e;try{if(e=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),!e){this._activeFilterModel$.next(null);return}}catch(e){console.error(`[SheetsFilterService]: could not get active workbook!`,e);return}let n=e.getActiveSheet(!0);if(!n){this._activeFilterModel$.next(null);return}let r=n.getUnitId(),i=n.getSheetId(),a=this.getFilterModel(r,i);this._activeFilterModel$.next(a)}_initActiveFilterModel(){this.disposeWithMe((0,r.merge)((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,r.filter)(([e])=>e.type===t.CommandType.MUTATION&&d.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,r.switchMap)(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?(0,r.of)(null):t}))).subscribe(()=>this._updateActiveFilterModel()))}_serializeAutoFiltersForUnit(e){let t=this._filterModels.get(e);if(!t)return`{}`;let n={};return t.forEach((e,t)=>{n[t]=e.serialize()}),JSON.stringify(n)}_deserializeAutoFiltersForUnit(e,t){let n=this._univerInstanceService.getUniverSheetInstance(e);Object.keys(t).forEach(r=>{let i=t[r],a=A.deserialize(e,r,n.getSheetBySheetId(r),i);this._cacheFilterModel(e,r,a)})}dispose(){super.dispose(),this._loadedUnitId$.complete(),this._errorMsg$.complete(),this._activeFilterModel$.complete(),this._filterModels.forEach(e=>{e.forEach(e=>e.dispose()),e.clear()}),this._filterModels.clear()}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:R,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:e=>this._serializeAutoFiltersForUnit(e),parseJson:e=>JSON.parse(e),onLoad:(e,t)=>{this._deserializeAutoFiltersForUnit(e,t),this._loadedUnitId$.next(e),this._updateActiveFilterModel()},onUnLoad:e=>{let t=this._filterModels.get(e);t&&(t.forEach(e=>e.dispose()),this._filterModels.delete(e))}})}_cacheFilterModel(e,t,n){this._filterModels.has(e)||this._filterModels.set(e,new Map),this._filterModels.get(e).set(t,n)}};z=L([I(0,t.IResourceManagerService),I(1,t.IUniverInstanceService),I(2,t.ICommandService)],z);let B={id:s,type:t.CommandType.MUTATION,handler:(e,t)=>{let{subUnitId:n,unitId:r,range:i}=t;return e.get(z).ensureFilterModel(r,n).setRange(i),!0}},V={id:c,type:t.CommandType.MUTATION,handler:(e,t)=>{let{subUnitId:n,unitId:r,criteria:i,col:a,reCalc:o=!0}=t,s=e.get(z).getFilterModel(r,n);return s?(s.setCriteria(a,i,o),!0):!1}},H={id:l,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,subUnitId:r}=t;return e.get(z).removeFilterModel(n,r)}},U={id:u,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,subUnitId:r}=t,i=e.get(z).getFilterModel(n,r);return i?(i.reCalc(),!0):!1}},W={id:`sheet.command.set-filter-range`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(z),a=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(t.IUniverInstanceService),{unitId:c,subUnitId:l,range:u}=r;if(!(0,n.getSheetCommandTarget)(s,r)||i.getFilterModel(c,l))return!1;if(u.endRow===u.startRow){let n=e.get(t.ErrorService),r=e.get(t.LocaleService);return n.emit(r.t(`sheets-filter.command.not-valid-filter-range`)),!1}let d={id:B.id,params:{unitId:c,subUnitId:l,range:u}},f=a.syncExecuteCommand(d.id,d.params);return f&&o.pushUndoRedo({unitID:c,undoMutations:[{id:H.id,params:{unitId:c,subUnitId:l}}],redoMutations:[d]}),f}},G={id:`sheet.command.remove-sheet-filter`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(z),{unitId:o,subUnitId:s}=i,c=a.getFilterModel(o,s);if(!c)return!1;let l=c.getRange();if(!l)return!1;let u=e.get(t.ICommandService),d=e.get(t.IUndoRedoService),f=pe(o,s,c.serialize()),p=u.syncExecuteCommand(H.id,{unitId:o,subUnitId:s});return p&&(d.pushUndoRedo({unitID:o,undoMutations:f,redoMutations:[{id:H.id,params:{unitId:o,subUnitId:s}}]}),u.executeCommand(n.MarkDirtyFilterChangeMutation.id,{unitId:o,subUnitId:s,filterRange:l})),p}},le={id:`sheet.command.smart-toggle-filter`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.IUniverInstanceService),i=e.get(z),a=e.get(t.ICommandService),o=r.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),s=o==null?void 0:o.getActiveSheet();if(!s||!o)return!1;let c=o.getUnitId(),l=s.getSheetId();if(i.getFilterModel(c,l))return a.executeCommand(G.id,{unitId:c,subUnitId:l});let u=e.get(n.SheetsSelectionsService).getCurrentLastSelection();if(!u)return!1;let d=u.range,f=(0,n.isSingleCellSelection)(u)?(0,n.expandToContinuousRange)(d,{left:!0,right:!0,up:!0,down:!0},s):d.startRow===d.endRow?(0,n.expandToContinuousRange)(d,{down:!0},s):d;return a.executeCommand(W.id,{unitId:c,subUnitId:l,range:f})}},ue={id:`sheet.command.set-filter-criteria`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(z),{unitId:o,subUnitId:s}=i,c=a.getFilterModel(o,s);if(!c)return!1;let{col:l,criteria:u}=r,d=c.getRange();if(!d||l<d.startColumn||l>d.endColumn)return!1;let f=e.get(t.ICommandService),p=e.get(t.IUndoRedoService),m=he(o,s,l,c.getFilterColumn(l)),h={id:V.id,params:{unitId:o,subUnitId:s,col:l,criteria:u}},g=f.syncExecuteCommand(h.id,h.params);return g&&(p.pushUndoRedo({unitID:o,undoMutations:[m],redoMutations:[h]}),f.executeCommand(n.MarkDirtyFilterChangeMutation.id,{unitId:o,subUnitId:s,filterRange:d})),g}},de={id:`sheet.command.clear-filter-criteria`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(z),{unitId:o,subUnitId:s}=i,c=a.getFilterModel(o,s);if(!c)return!1;let l=c.getRange();if(!l)return!1;let u=e.get(t.IUndoRedoService),d=e.get(t.ICommandService),f=c.serialize(),p=K(o,s,f),m=me(o,s,f);return(0,t.sequenceExecute)(m,d).result?(u.pushUndoRedo({unitID:o,undoMutations:p,redoMutations:m}),d.executeCommand(n.MarkDirtyFilterChangeMutation.id,{unitId:o,subUnitId:s,filterRange:l}),!0):!1}},fe={id:`sheet.command.re-calc-filter`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(z),a=e.get(t.ICommandService),o=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!o)return!1;let{unitId:s,subUnitId:c}=o;return i.getFilterModel(o.unitId,o.subUnitId)?a.executeCommand(U.id,{unitId:s,subUnitId:c}):!1}};function pe(e,t,n){let r=[],i={id:B.id,params:{unitId:e,subUnitId:t,range:n.ref}};return r.push(i),K(e,t,n).forEach(e=>r.push(e)),r}function K(e,t,n){var r;let i=[];return(r=n.filterColumns)==null||r.forEach(n=>{let r={id:V.id,params:{unitId:e,subUnitId:t,col:n.colId,criteria:n}};i.push(r)}),i}function me(e,t,n){var r;let i=[];return(r=n.filterColumns)==null||r.forEach(n=>{let r={id:V.id,params:{unitId:e,subUnitId:t,col:n.colId,criteria:null}};i.push(r)}),i}function he(e,t,n,r){if(!r)return{id:V.id,params:{unitId:e,subUnitId:t,col:n,criteria:null}};let i=r.serialize();return{id:V.id,params:{unitId:e,subUnitId:t,col:n,criteria:i}}}let q=`sheets-filter.config`;Symbol(q);let J={};function ge(e,t){for(let n=0;n<e.length;n++){let r=n;if(e[n])for(let i=n+1;i<e.length;i++)e[r]&&e[i]&&t(e[r],e[i])&&(e[r]=null,r=i)}return e.filter(e=>e!==null)}function Y(e){return ge(e,(e,t)=>e.id===V.id&&t.id===V.id&&e.params.unitId===t.params.unitId&&e.params.subUnitId===t.params.subUnitId&&e.params.col===t.params.col)}let X=class extends t.Disposable{constructor(e,n,r,i,a,o,s){super(),this._commandService=e,this._sheetInterceptorService=n,this._sheetsFilterService=r,this._univerInstanceService=i,this._refRangeService=a,this._dataSyncPrimaryController=o,this._zebraCrossingCacheController=s,O(this,`_disposableCollection`,new t.DisposableCollection),this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener(),this._initErrorHandling(),this._initZebraCrossingCacheListener()}_initZebraCrossingCacheListener(){this.disposeWithMe(this._sheetsFilterService.activeFilterModel$.subscribe(e=>{e&&this.disposeWithMe(e.filteredOutRows$.subscribe(()=>{this._zebraCrossingCacheController.updateZebraCrossingCache(e.unitId,e.subUnitId)}))}))}_initCommands(){[V,B,U,H].forEach(e=>{var t;this.disposeWithMe(this._commandService.registerCommand(e)),(t=this._dataSyncPrimaryController)==null||t.registerSyncingMutations(e)})}_initInterceptors(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>this._getUpdateFilter(e)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===n.SetWorksheetActiveOperation.id){let t=e.params,n=t.subUnitId,r=t.unitId;if(!n||!r)return;this._registerRefRange(r,n)}if(e.id===B.id){let t=e.params,n=t.subUnitId,r=t.unitId;if(!n||!r)return;this._registerRefRange(t.unitId,t.subUnitId)}})),this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe(e=>{if(e){let t=this._univerInstanceService.getUniverSheetInstance(e),n=t==null?void 0:t.getActiveSheet();n&&this._registerRefRange(e,n.getSheetId())}}))}_registerRefRange(e,t){var r;this._disposableCollection.dispose();let i=this._univerInstanceService.getUniverSheetInstance(e),a=i==null?void 0:i.getSheetBySheetId(t);if(!i||!a)return;let o=(r=this._sheetsFilterService.getFilterModel(e,t))==null?void 0:r.getRange();o&&this._disposableCollection.add(this._refRangeService.registerRefRange(o,r=>{switch(r.id){case n.InsertRowCommand.id:{let n=r.params,i=n.unitId||e,a=n.subUnitId||t;return this._handleInsertRowCommand(n,i,a)}case n.InsertColCommand.id:{let n=r.params,i=n.unitId||e,a=n.subUnitId||t;return this.handleInsertColCommand(n.range,i,a)}case n.RemoveColCommand.id:{let n=r.params;return this.handleRemoveColCommand(n.range,e,t)}case n.RemoveRowCommand.id:{let n=r.params;return this._handleRemoveRowCommand(n,e,t)}case n.EffectRefRangId.MoveColsCommandId:{let n=r.params;return this.handleMoveColsCommand({fromRange:n.fromRange,toRange:n.toRange},e,t)}case n.EffectRefRangId.MoveRowsCommandId:{let n=r.params;return this._handleMoveRowsCommand(n,e,t)}case n.MoveRangeCommand.id:{let n=r.params;return this._handleMoveRangeCommand(n,e,t)}}return{redos:[],undos:[]}},e,t))}_getUpdateFilter(e){let{id:t}=e;switch(t){case n.RemoveSheetCommand.id:{let t=e.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case n.CopySheetCommand.id:{let{targetSubUnitId:t,unitId:n,subUnitId:r}=e.params;return!n||!r||!t?this._handleNull():this._handleCopySheetCommand(n,r,t)}}return{redos:[],undos:[]}}handleInsertColCommand(e,t,n){var r;let i=this._sheetsFilterService.getFilterModel(t,n),a=(r=i==null?void 0:i.getRange())==null?null:r;if(!i||!a)return this._handleNull();let{startColumn:o,endColumn:s}=a,{startColumn:c,endColumn:l}=e,u=l-c+1;if(l>s)return this._handleNull();let d=[],f=[],p=c,m={unitId:t,subUnitId:n,range:{...a,startColumn:c<=o?o+u:o,endColumn:s+u}},h={unitId:t,subUnitId:n,range:a};d.push({id:B.id,params:m}),f.push({id:B.id,params:h});let g=i.getAllFilterColumns().filter(e=>e[0]>=p);if(g.length!==0){let{newRange:e,oldRange:r}=this._moveCriteria(t,n,g,u);d.push(...r.redos,...e.redos),f.push(...e.undos,...r.undos)}return{redos:Y(d),undos:Y(f)}}_handleInsertRowCommand(e,t,n){var r;let i=this._sheetsFilterService.getFilterModel(t,n),a=(r=i==null?void 0:i.getRange())==null?null:r;if(!i||!a)return this._handleNull();let{startRow:o,endRow:s}=a,{startRow:c,endRow:l}=e.range,u=l-c+1;if(l>s)return this._handleNull();let d=[],f=[],p={unitId:t,subUnitId:n,range:{...a,startRow:c<=o?o+u:o,endRow:s+u}},m={unitId:t,subUnitId:n,range:a};return d.push({id:B.id,params:p}),f.push({id:B.id,params:m}),{redos:Y(d),undos:Y(f)}}handleRemoveColCommand(e,t,n){var r;let i=this._sheetsFilterService.getFilterModel(t,n),a=(r=i==null?void 0:i.getRange())==null?null:r;if(!i||!a)return this._handleNull();let{startColumn:o,endColumn:s}=a,{startColumn:c,endColumn:l}=e;if(c>s)return this._handleNull();let u=[],d=[],f=l<o?0:Math.min(l,s)-Math.max(c,o)+1,p=l-c+1,m=i.getAllFilterColumns();m.forEach(e=>{let[r,i]=e;r<=l&&r>=c&&(u.push({id:V.id,params:{unitId:t,subUnitId:n,col:r,criteria:null}}),d.push({id:V.id,params:{unitId:t,subUnitId:n,col:r,criteria:{...i.serialize(),colId:r}}}))});let h=m.filter(e=>{let[t,n]=e;return t>l}),g={undos:[],redos:[]};if(h.length>0){let{oldRange:e,newRange:r}=this._moveCriteria(t,n,h,-p);g=r,u.push(...e.redos),d.unshift(...e.undos)}if(f===s-o+1){let e={unitId:t,subUnitId:n};u.push({id:H.id,params:e}),d.unshift({id:B.id,params:{range:a,unitId:t,subUnitId:n}})}else{let e=o<=c?o:f===0?o-p:c,r=o<=c?s-f:s-p,i={unitId:t,subUnitId:n,range:{...a,startColumn:e,endColumn:r}};u.push({id:B.id,params:i}),d.unshift({id:B.id,params:{range:a,unitId:t,subUnitId:n}}),u.push(...g.redos),d.unshift(...g.undos)}return{undos:d,redos:u}}_handleRemoveRowCommand(e,t,n){let r=this._sheetsFilterService.getFilterModel(t,n);if(!r)return this._handleNull();let i=r.getRange(),{startRow:a,endRow:o}=i,{startRow:s,endRow:c}=e.range;if(s>o)return this._handleNull();if(c<a)return{undos:[{id:B.id,params:{range:i,unitId:t,subUnitId:n}}],redos:[{id:B.id,params:{range:{...i,startRow:a-(c-s+1),endRow:o-(c-s+1)},unitId:t,subUnitId:n}}]};let l=[],u=[],d=r.getAllFilterColumns(),f=a<=c&&a>=s;u.push({id:B.id,params:{range:i,unitId:t,subUnitId:n}});let p=Math.min(c,o)-Math.max(s,a)+1;if(p===o-a+1||f){let e={unitId:t,subUnitId:n};l.push({id:H.id,params:e}),d.forEach(e=>{let[r,i]=e,a={unitId:t,subUnitId:n,col:r,criteria:{...i.serialize(),colId:r}};u.push({id:V.id,params:a})})}else{var m;let e=(m=this._univerInstanceService.getUniverSheetInstance(t))==null?void 0:m.getSheetBySheetId(n);if(!e)return this._handleNull();let r=[];for(let t=s;t<=c;t++)e.getRowFiltered(t)&&r.push(t);let u=Math.min(a,s),d=u+(o-a)-p+r.length,f={unitId:t,subUnitId:n,range:{...i,startRow:u,endRow:d}};l.push({id:B.id,params:f})}return{undos:Y(u),redos:Y(l)}}handleMoveColsCommand({fromRange:e,toRange:n},r,i){var a;let o=this._sheetsFilterService.getFilterModel(r,i),s=(a=o==null?void 0:o.getRange())==null?null:a;if(!o||!s)return this._handleNull();let{startColumn:c,endColumn:l}=s;if(e.endColumn<c&&n.startColumn<=c||e.startColumn>l&&n.endColumn>l)return this._handleNull();let u=[],d=[],f={};for(let e=c;e<=l;e++)f[e]={colIndex:e,filter:o.getFilterColumn(e)};(0,t.moveMatrixArray)(e.startColumn,e.endColumn-e.startColumn+1,n.startColumn,f);let p=s.startColumn,m=s.endColumn;c>=e.startColumn&&c<=e.endColumn&&n.startColumn>e.startColumn&&e.endColumn<l&&(p=e.endColumn+1),l>=e.startColumn&&l<=e.endColumn&&n.startColumn<e.startColumn&&e.startColumn>c&&(m=e.startColumn-1);let h=Object.keys(f).map(e=>Number(e)),g=h.find(e=>f[e].colIndex===m),_=h.find(e=>f[e].colIndex===p);if(h.forEach(e=>{let{colIndex:t,filter:n}=f[e],a=e;if(n){var s;if(a>=_&&a<=g){var c;let e={unitId:r,subUnitId:i,col:a,criteria:{...n.serialize(),colId:a}},t={unitId:r,subUnitId:i,col:a,criteria:o.getFilterColumn(a)?{...(c=o.getFilterColumn(a))==null?void 0:c.serialize(),colId:a}:null};u.push({id:V.id,params:e}),d.push({id:V.id,params:t})}if(!((s=f[t])!=null&&s.filter)){let e={unitId:r,subUnitId:i,col:t,criteria:null};u.push({id:V.id,params:e}),d.push({id:V.id,params:{unitId:r,subUnitId:i,col:t,criteria:{...n.serialize(),colId:t}}})}}}),c!==_||l!==g){let e={unitId:r,subUnitId:i,range:{...s,startColumn:_,endColumn:g}};u.unshift({id:B.id,params:e}),d.unshift({id:B.id,params:{range:s,unitId:r,subUnitId:i}})}return{undos:d,redos:u}}_handleMoveRowsCommand(e,n,r){var i;let a=this._sheetsFilterService.getFilterModel(n,r),o=(i=a==null?void 0:a.getRange())==null?null:i;if(!a||!o)return this._handleNull();let{startRow:s,endRow:c}=o,{fromRange:l,toRange:u}=e;if(l.endRow<s&&u.startRow<=s||l.startRow>c&&u.endRow>c)return this._handleNull();let d=[],f=[],p={};for(let e=s;e<=c;e++)p[e]={oldIndex:e};let m=s,h=c;c>=l.startRow&&c<=l.endRow&&u.startRow<l.startRow&&l.startRow>s&&(h=l.startRow-1),(0,t.moveMatrixArray)(l.startRow,l.endRow-l.startRow+1,u.startRow,p);let g=Object.keys(p).map(e=>Number(e)),_=g.find(e=>p[e].oldIndex===h),v=g.find(e=>p[e].oldIndex===m);if(s!==v||c!==_){let e={unitId:n,subUnitId:r,range:{...o,startRow:v,endRow:_}};d.push({id:B.id,params:e},{id:U.id,params:{unitId:n,subUnitId:r}}),f.push({id:B.id,params:{range:o,unitId:n,subUnitId:r}},{id:U.id,params:{unitId:n,subUnitId:r}})}return{redos:d,undos:f}}_handleMoveRangeCommand(e,n,r){let{fromRange:i,toRange:a}=e,o=this._sheetsFilterService.getFilterModel(n,r);if(!o)return this._handleNull();let s=o.getRange();if(!s)return this._handleNull();let c=[],l=[];if(t.Rectangle.contains(i,s)){let e=s.startRow-i.startRow,t=s.startColumn-i.startColumn,u={startRow:a.startRow+e,startColumn:a.startColumn+t,endRow:a.startRow+e+(s.endRow-s.startRow),endColumn:a.startColumn+t+(s.endColumn-s.startColumn)},d={id:H.id,params:{unitId:n,subUnitId:r}},f={id:B.id,params:{unitId:n,subUnitId:r,range:u}},p={id:B.id,params:{unitId:n,subUnitId:r,range:s}};c.push(d,f),l.push(d,p);let m=o.getAllFilterColumns(),h=a.startColumn-i.startColumn;m.forEach(e=>{let[t,i]=e;i&&(c.push({id:V.id,params:{unitId:n,subUnitId:r,col:t+h,criteria:{...i.serialize(),colId:t+h}}}),l.push({id:V.id,params:{unitId:n,subUnitId:r,col:t,criteria:{...i.serialize(),colId:t}}}))})}else if(t.Rectangle.intersects(a,s)){let e={...s,endRow:Math.max(s.endRow,a.endRow)};c.push({id:B.id,params:{unitId:n,subUnitId:r,range:e}}),l.push({id:B.id,params:{unitId:n,subUnitId:r,range:s}})}return{redos:c,undos:l}}_handleRemoveSheetCommand(e,t,n){let r=this._sheetsFilterService.getFilterModel(t,n);if(!r)return this._handleNull();let i=r.getRange();if(!i)return this._handleNull();let a=[],o=[];return r.getAllFilterColumns().forEach(([e,r])=>{o.push({id:V.id,params:{unitId:t,subUnitId:n,col:e,criteria:{...r.serialize(),colId:e}}})}),a.push({id:H.id,params:{unitId:t,subUnitId:n,range:i}}),o.unshift({id:B.id,params:{range:i,unitId:t,subUnitId:n}}),{undos:o,redos:a}}_handleCopySheetCommand(e,t,n){let r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();let i=r.getRange();if(!i)return this._handleNull();let a=[],o=[],s=[];return r.getAllFilterColumns().forEach(([t,r])=>{a.push({id:V.id,params:{unitId:e,subUnitId:n,col:t,criteria:{...r.serialize(),colId:t}}}),s.push({id:V.id,params:{unitId:e,subUnitId:n,col:t,criteria:null}})}),s.push({id:H.id,params:{unitId:e,subUnitId:n,range:i}}),a.unshift({id:B.id,params:{range:i,unitId:e,subUnitId:n}}),{undos:o,redos:a,preUndos:s,preRedos:[]}}_handleNull(){return{redos:[],undos:[]}}_initRowFilteredInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(n.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(e,t)=>{var n,r;return e?!0:(n=(r=this._sheetsFilterService.getFilterModel(t.unitId,t.subUnitId))==null?void 0:r.isRowFiltered(t.row))==null?!1:n}}))}_moveCriteria(e,t,n,r){let i={unitId:e,subUnitId:t,criteria:null,col:-1},a=[],o=[],s=[],c=[];return n.forEach(e=>{let[t,n]=e;o.push({id:V.id,params:{...i,col:t}}),a.push({id:V.id,params:{...i,col:t,criteria:{...n.serialize(),colId:t}}})}),n.forEach(e=>{let[t,n]=e;c.push({id:V.id,params:{...i,col:t+r,criteria:{...n.serialize(),colId:t+r}}}),s.push({id:V.id,params:{...i,col:t+r,criteria:null}})}),{newRange:{redos:c,undos:s},oldRange:{redos:o,undos:a}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((e,t)=>{let{unitId:r,subUnitId:i}=e.params||{},a=this._sheetsFilterService.getFilterModel(r,i);if(!a)return;let o=Array.from(a.filteredOutRows).sort((e,t)=>e-t),s=[],c=!1;if(e.id===n.RemoveRowMutation.id){let{startRow:t,endRow:n}=e.params.range,r=o.filter(e=>e>=t&&e<=n);o.forEach(e=>{if(e<t)s.push(e);else if(c=!0,e<=n){let e=Math.max(t,s.length?s[s.length-1]+1:t);s.push(e)}else s.push(e-(n-t+1-r.length))})}if(e.id===n.InsertRowMutation.id){let{startRow:t,endRow:n}=e.params.range;o.forEach(e=>{e>=t?(c=!0,s.push(e+(n-t+1))):s.push(e)})}if(c&&(a.filteredOutRows=new Set(s)),e.id===n.SetRangeValuesMutation.id&&!(t!=null&&t.onlyLocal)){let t=this._getExtendRegion(r,i);if(t){let a=e.params.cellValue;if(a)for(let e=t.startColumn;e<=t.endColumn;e++){var l;let o=a==null||(l=a[t.startRow])==null?void 0:l[e];if(o&&this._cellHasValue(o)){var u;let e=(u=this._univerInstanceService.getUnit(r))==null?void 0:u.getSheetBySheetId(i);if(e){let a=(0,n.expandToContinuousRange)(t,{down:!0},e),o=this._sheetsFilterService.getFilterModel(r,i),s=o.getRange();o.setRange({...s,endRow:a.endRow}),this._registerRefRange(r,i)}}}}}}))}_getExtendRegion(e,t){var n;let r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return null;let i=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);if(!i)return null;let a=r.getRange();if(!a)return null;let o=i.getRowCount()-1,s=i.getRowManager();for(let e=a.endRow+1;e<=o;e++)if(s.getRowRawVisible(e))return{startRow:e,endRow:e,startColumn:a.startColumn,endColumn:a.endColumn};return null}_initErrorHandling(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let t=e.params,r=(0,n.getSheetCommandTarget)(this._univerInstanceService,t);if(!r)return;let{subUnitId:i,unitId:a}=r,o=this._sheetsFilterService.getFilterModel(a,i);if(!o)return;let s=o.getRange();if(e.id===n.MoveRowsCommand.id&&t.fromRange.startRow<=s.startRow&&t.fromRange.endRow<s.endRow&&t.fromRange.endRow>=s.startRow)throw this._sheetsFilterService.setFilterErrorMsg(`sheets-filter.msg.filter-header-forbidden`),Error(`[SheetsFilterController]: Cannot move header row of filter`)}))}_cellHasValue(e){let t=Object.values(e);return!(t.length===0||t.every(e=>e==null))}};X=L([I(0,t.ICommandService),I(1,(0,t.Inject)(n.SheetInterceptorService)),I(2,(0,t.Inject)(z)),I(3,t.IUniverInstanceService),I(4,(0,t.Inject)(n.RefRangeService)),I(5,(0,t.Optional)(a.DataSyncPrimaryController)),I(6,(0,t.Inject)(n.ZebraCrossingCacheController))],X);let _e=[V.id,U.id],ve=[n.InsertColMutation.id,n.RemoveColMutation.id,n.MoveColsMutation.id],Z=class extends t.Disposable{get visible(){return this._visible$.getValue()}get enabled(){return this._enabled$.getValue()}constructor(e,n,i){super(),this._sheetsFilterController=e,this._commandService=n,this._configService=i,O(this,`_d`,new t.DisposableCollection),O(this,`_visible$`,new r.BehaviorSubject(!1)),O(this,`visible$`,this._visible$.asObservable()),O(this,`_enabled$`,new r.BehaviorSubject(!0)),O(this,`enabled$`,this._enabled$.asObservable());let a=this._configService.getConfig(q);if(a!=null&&a.enableSyncSwitch&&(this._visible$.next(!0),typeof a.enableSyncSwitch==`object`)){var o;this.setEnabled((o=a.enableSyncSwitch.defaultValue)==null?!0:o)}}setEnabled(e){this._enabled$.next(e),e?this._d.dispose():this._initOnlyLocalListener()}_initOnlyLocalListener(){this._d.add(this._commandService.beforeCommandExecuted((e,t)=>{_e.includes(e.id)&&(t||(t={}),t.onlyLocal=!0)})),this._d.add(this._commandService.onCommandExecuted((e,r)=>{if(ve.includes(e.id)&&r!=null&&r.fromCollab){if(e.id===n.InsertColMutation.id){let{range:n,unitId:i,subUnitId:a}=e.params,{redos:o}=this._sheetsFilterController.handleInsertColCommand(n,i,a);(0,t.sequenceExecute)(o,this._commandService,r)}else if(e.id===n.RemoveColMutation.id){let{range:n,unitId:i,subUnitId:a}=e.params,{redos:o}=this._sheetsFilterController.handleRemoveColCommand(n,i,a);(0,t.sequenceExecute)(o,this._commandService,r)}else if(e.id===n.MoveColsMutation.id){let{sourceRange:n,targetRange:i,unitId:a,subUnitId:o}=e.params,{redos:s}=this._sheetsFilterController.handleMoveColsCommand({fromRange:n,toRange:i},a,o);(0,t.sequenceExecute)(s,this._commandService,r)}}}))}};Z=L([I(0,(0,t.Inject)(X)),I(1,t.ICommandService),I(2,t.IConfigService)],Z);var ye=`@univerjs/sheets-filter`,be=`0.22.0-insiders.20260513-09bbeca`;let Q=class extends t.Disposable{constructor(e,t,n,r){super(),this._activeDirtyManagerService=e,this._sheetRowFilteredService=t,this._sheetsFilterService=n,this._univerInstanceService=r,this._initFormulaDirtyRange(),this._registerSheetRowFiltered()}_initFormulaDirtyRange(){d.forEach(e=>{this._activeDirtyManagerService.register(e,{commandId:e,getDirtyData:e=>{let{unitId:t,subUnitId:n}=e.params;return{dirtyRanges:this._getHideRowMutation(t,n),clearDependencyTreeCache:{[t]:{[n]:`1`}}}}})})}_getHideRowMutation(e,t){var n,r;let i=(n=this._sheetsFilterService.getFilterModel(e,t))==null?void 0:n.getRange(),a=(r=this._univerInstanceService.getUnit(e))==null?void 0:r.getSheetBySheetId(t);if(i==null||a==null)return[];let{startRow:o,endRow:s}=i;return[{unitId:e,sheetId:t,range:{startRow:o,startColumn:0,endRow:s,endColumn:a.getColumnCount()-1}}]}_registerSheetRowFiltered(){this._sheetRowFilteredService.register((e,t,n)=>{var r,i;return(r=(i=this._sheetsFilterService.getFilterModel(e,t))==null?void 0:i.isRowFiltered(n))==null?!1:r})}};Q=L([I(0,(0,t.Inject)(o.IActiveDirtyManagerService)),I(1,(0,t.Inject)(o.ISheetRowFilteredService)),I(2,(0,t.Inject)(z)),I(3,t.IUniverInstanceService)],Q);let $=class extends t.Plugin{constructor(e=J,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},J,this._config);this._configService.setConfig(q,i)}onStarting(){[[Q],[z],[X],[Z]].forEach(e=>this._injector.add(e))}onReady(){(0,t.touchDependencies)(this._injector,[[Q],[X],[Z]])}};O($,`type`,t.UniverInstanceType.UNIVER_SHEET),O($,`pluginName`,R),O($,`packageName`,ye),O($,`version`,be),$=L([I(1,(0,t.Inject)(t.Injector)),I(2,t.IConfigService)],$),e.ClearSheetsFilterCriteriaCommand=de,e.CustomFilterOperator=p,e.FILTER_MUTATIONS=d,e.FilterBy=f,e.FilterColumn=j,e.FilterModel=A,e.ReCalcSheetsFilterCommand=fe,e.ReCalcSheetsFilterMutation=U,e.RemoveSheetFilterCommand=G,e.RemoveSheetsFilterMutation=H,e.SHEET_FILTER_SNAPSHOT_ID=R,e.SetSheetFilterRangeCommand=W,e.SetSheetsFilterCriteriaCommand=ue,e.SetSheetsFilterCriteriaMutation=V,e.SetSheetsFilterRangeMutation=B,Object.defineProperty(e,`SheetsFilterService`,{enumerable:!0,get:function(){return z}}),Object.defineProperty(e,`SheetsFilterSyncController`,{enumerable:!0,get:function(){return Z}}),e.SmartToggleSheetsFilterCommand=le,Object.defineProperty(e,`UniverSheetsFilterPlugin`,{enumerable:!0,get:function(){return $}}),e.equals=v,e.getCustomFilterFn=S,e.greaterThan=m,e.greaterThanOrEqualTo=h,e.lessThan=g,e.lessThanOrEqualTo=_,e.notEquals=y});
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-filter",
3
- "version": "0.21.1",
3
+ "version": "0.22.0-insiders.20260513-09bbeca",
4
4
  "private": false,
5
- "description": "A library for filtering data in Univer Sheet",
6
- "author": "DreamNum <developer@univer.ai>",
5
+ "description": "Filtering model, commands, and services for Univer Sheets.",
6
+ "author": "DreamNum Co., Ltd. <developer@univer.ai>",
7
7
  "license": "Apache-2.0",
8
8
  "funding": {
9
9
  "type": "opencollective",
@@ -17,7 +17,13 @@
17
17
  "bugs": {
18
18
  "url": "https://github.com/dream-num/univer/issues"
19
19
  },
20
- "keywords": [],
20
+ "keywords": [
21
+ "univer",
22
+ "sheets",
23
+ "filter",
24
+ "spreadsheet",
25
+ "plugin"
26
+ ],
21
27
  "exports": {
22
28
  ".": {
23
29
  "import": "./lib/es/index.js",
@@ -56,17 +62,17 @@
56
62
  "rxjs": ">=7.0.0"
57
63
  },
58
64
  "dependencies": {
59
- "@univerjs/engine-formula": "0.21.1",
60
- "@univerjs/engine-render": "0.21.1",
61
- "@univerjs/rpc": "0.21.1",
62
- "@univerjs/core": "0.21.1",
63
- "@univerjs/sheets": "0.21.1"
65
+ "@univerjs/core": "0.22.0-insiders.20260513-09bbeca",
66
+ "@univerjs/engine-formula": "0.22.0-insiders.20260513-09bbeca",
67
+ "@univerjs/rpc": "0.22.0-insiders.20260513-09bbeca",
68
+ "@univerjs/sheets": "0.22.0-insiders.20260513-09bbeca",
69
+ "@univerjs/engine-render": "0.22.0-insiders.20260513-09bbeca"
64
70
  },
65
71
  "devDependencies": {
66
72
  "rxjs": "^7.8.2",
67
- "typescript": "^6.0.2",
68
- "vitest": "^4.1.4",
69
- "@univerjs-infra/shared": "0.21.1"
73
+ "typescript": "^6.0.3",
74
+ "vitest": "^4.1.5",
75
+ "@univerjs-infra/shared": "0.22.0"
70
76
  },
71
77
  "scripts": {
72
78
  "test": "vitest run",
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS