@univerjs/sheets-filter 0.1.8

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.
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
@@ -0,0 +1,37 @@
1
+ import { IFilterColumn } from '../models/types';
2
+ import { ISheetCommandSharedParams } from '@univerjs/sheets';
3
+ import { IMutation, IRange, Nullable } from '@univerjs/core';
4
+
5
+ export interface ISetSheetsFilterRangeMutationParams extends ISheetCommandSharedParams {
6
+ range: IRange;
7
+ }
8
+ /**
9
+ * Set filter range in a Worksheet. If the `FilterModel` does not exist, it will be created.
10
+ *
11
+ * Since there could only be a filter on a worksheet, when you want to update the range, you
12
+ * don't necessarily need to remove the filter first, you can just execute this mutation.
13
+ */
14
+ export declare const SetSheetsFilterRangeMutation: IMutation<ISetSheetsFilterRangeMutationParams>;
15
+ export interface ISetSheetsFilterCriteriaMutationParams extends ISheetCommandSharedParams {
16
+ col: number;
17
+ /**
18
+ * Filter criteria to set. If it is `null`, the criteria will be removed.
19
+ */
20
+ criteria: Nullable<IFilterColumn>;
21
+ /**
22
+ * If it should trigger calculation on this `FilterColumn`.
23
+ *
24
+ * @default true
25
+ */
26
+ reCalc?: boolean;
27
+ }
28
+ /**
29
+ * Set filter criteria of a Worksheet.
30
+ */
31
+ export declare const SetSheetsFilterCriteriaMutation: IMutation<ISetSheetsFilterCriteriaMutationParams>;
32
+ export interface IRemoveSheetsFilterMutationParams extends ISheetCommandSharedParams {
33
+ }
34
+ export declare const RemoveSheetsFilterMutation: IMutation<IRemoveSheetsFilterMutationParams>;
35
+ export interface IReCalcSheetsFilterMutationParams extends ISheetCommandSharedParams {
36
+ }
37
+ export declare const ReCalcSheetsFilterMutation: IMutation<IReCalcSheetsFilterMutationParams>;
@@ -0,0 +1,27 @@
1
+ import { SheetsFilterService } from '../services/sheet-filter.service';
2
+ import { RefRangeService, SheetInterceptorService } from '@univerjs/sheets';
3
+ import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
4
+
5
+ export declare class SheetsFilterController extends Disposable {
6
+ private readonly _commandService;
7
+ private readonly _sheetInterceptorService;
8
+ private readonly _sheetsFilterService;
9
+ private readonly _univerInstanceService;
10
+ private readonly _refRangeService;
11
+ constructor(_commandService: ICommandService, _sheetInterceptorService: SheetInterceptorService, _sheetsFilterService: SheetsFilterService, _univerInstanceService: IUniverInstanceService, _refRangeService: RefRangeService);
12
+ private _initCommands;
13
+ private _initInterceptors;
14
+ private _getUpdateFilter;
15
+ private _handleInsertColCommand;
16
+ private _handleInsertRowCommand;
17
+ private _handleRemoveColCommand;
18
+ private _handleRemoveRowCommand;
19
+ private _handleMoveColsCommand;
20
+ private _handleMoveRowsCommand;
21
+ private _handleMoveRangeCommand;
22
+ private _handleRemoveSheetCommand;
23
+ private _handleNull;
24
+ private _initRowFilteredInterceptor;
25
+ private moveCriteria;
26
+ private _commandExecutedListener;
27
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export { UniverSheetsFilterPlugin } from './plugin';
17
+ export { FilterColumn, FilterModel } from './models/filter-model';
18
+ export { equals, notEquals, getCustomFilterFn, greaterThan, greaterThanOrEqualTo, lessThan, lessThanOrEqualTo, } from './models/custom-filters';
19
+ export { SheetsFilterService, FILTER_MUTATIONS, SHEET_FILTER_SNAPSHOT_ID } from './services/sheet-filter.service';
20
+ export { type IReCalcSheetsFilterMutationParams, type IRemoveSheetsFilterMutationParams, type ISetSheetsFilterCriteriaMutationParams, type ISetSheetsFilterRangeMutationParams, SetSheetsFilterCriteriaMutation, SetSheetsFilterRangeMutation, ReCalcSheetsFilterMutation, RemoveSheetsFilterMutation, } from './commands/sheets-filter.mutation';
21
+ export type { IAutoFilter, IFilterColumn, IFilters, ICustomFilters, ICustomFilter } from './models/types';
22
+ export { CustomFilterOperator } from './models/types';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
@@ -0,0 +1,39 @@
1
+ import { CustomFilterOperator } from './types';
2
+ import { CellValue, Nullable } from '@univerjs/core';
3
+
4
+ export interface IFilterFn<P extends unknown[]> {
5
+ label?: string;
6
+ /**
7
+ * Description of this operator. Should be an i18n key.
8
+ */
9
+ description?: string;
10
+ fn: (...params: P) => boolean;
11
+ }
12
+ /**
13
+ * Custom filter functions normally used in "Filter by Conditions".
14
+ */
15
+ export interface ICustomFilterFn<P extends unknown[]> extends IFilterFn<P> {
16
+ /**
17
+ * Operator of the custom filter function.
18
+ */
19
+ operator?: CustomFilterOperator;
20
+ /**
21
+ * Group of the custom filter belongs to. It would be rendered in the panel by groups.
22
+ */
23
+ group?: string;
24
+ fn: (...params: P) => boolean;
25
+ }
26
+ type TwoParameters<C = string> = [value: Nullable<CellValue>, compare: C];
27
+ export declare const greaterThan: ICustomFilterFn<TwoParameters<number>>;
28
+ export declare const greaterThanOrEqualTo: ICustomFilterFn<TwoParameters<number>>;
29
+ export declare const lessThan: ICustomFilterFn<TwoParameters<number>>;
30
+ export declare const lessThanOrEqualTo: ICustomFilterFn<TwoParameters<number>>;
31
+ export declare const equals: ICustomFilterFn<TwoParameters<number>>;
32
+ export declare const notEquals: ICustomFilterFn<TwoParameters<number | string>>;
33
+ export declare const CustomFilterFnRegistry: Map<CustomFilterOperator, ICustomFilterFn<TwoParameters<number>>>;
34
+ export declare function isNumericFilterFn(operator?: CustomFilterOperator): boolean;
35
+ /** This operators matches texts. */
36
+ export declare const textMatch: ICustomFilterFn<TwoParameters<string>>;
37
+ export declare function getCustomFilterFn(operator?: CustomFilterOperator): ICustomFilterFn<TwoParameters<any>>;
38
+ export declare function ensureNumeric(value: Nullable<CellValue>): boolean;
39
+ export {};
@@ -0,0 +1,124 @@
1
+ import { IAutoFilter, IFilterColumn } from './types';
2
+ import { Observable } from 'rxjs';
3
+ import { Disposable, CellValue, IRange, Nullable, Worksheet } from '@univerjs/core';
4
+
5
+ /**
6
+ * This is the in-memory model of filter.
7
+ */
8
+ export declare class FilterModel extends Disposable {
9
+ readonly unitId: string;
10
+ readonly subUnitId: string;
11
+ private readonly _worksheet;
12
+ private readonly _filteredOutRows$;
13
+ /** An observable value. A set of filtered out rows. */
14
+ readonly filteredOutRows$: Observable<Readonly<Set<number>>>;
15
+ get filteredOutRows(): Set<number>;
16
+ set filteredOutRows(rows: Set<number>);
17
+ private readonly _hasCriteria$;
18
+ readonly hasCriteria$: Observable<boolean>;
19
+ private _filterColumnByIndex;
20
+ private _alreadyFilteredOutRows;
21
+ private _range;
22
+ constructor(unitId: string, subUnitId: string, _worksheet: Worksheet);
23
+ dispose(): void;
24
+ /**
25
+ * Serialize this filter model to the JSON format representation.
26
+ */
27
+ serialize(): IAutoFilter;
28
+ /**
29
+ * Deserialize auto filter info to construct a `FilterModel` object.
30
+ * @param unitId workbook id
31
+ * @param subUnitId worksheet id
32
+ * @param worksheet the Worksheet object
33
+ * @param autoFilter auto filter data
34
+ */
35
+ static deserialize(unitId: string, subUnitId: string, worksheet: Worksheet, autoFilter: IAutoFilter): FilterModel;
36
+ private _dump;
37
+ isRowFiltered(row: number): boolean;
38
+ getRange(): IRange;
39
+ /**
40
+ * Get filtered out rows except the specific column. This method is considered as "pure". In
41
+ * another word it would not change `filteredOutRows` on `FilterModel` nor `FilterColumn`.
42
+ * @param col
43
+ */
44
+ getFilteredOutRowsExceptCol(col: number): Set<number>;
45
+ /**
46
+ * Set range of the filter model, this would remove some `IFilterColumn`
47
+ * if the new range not overlaps the old range.
48
+ */
49
+ setRange(range: IRange): void;
50
+ /**
51
+ * Set or remove filter criteria on a specific row.
52
+ */
53
+ setCriteria(col: number, criteria: Nullable<IFilterColumn>, reCalc?: boolean): void;
54
+ getAllFilterColumns(): [number, FilterColumn][];
55
+ getFilterColumn(index: number): Nullable<FilterColumn>;
56
+ reCalc(): void;
57
+ private _getAllFilterColumns;
58
+ private _reCalcAllColumns;
59
+ private _setCriteriaWithoutReCalc;
60
+ private _removeCriteria;
61
+ private _emit;
62
+ private _emitHasCriteria;
63
+ private _rebuildAlreadyFilteredOutRowsWithCache;
64
+ private _reCalcWithNoCacheColumns;
65
+ }
66
+ interface IFilterColumnContext {
67
+ getAlreadyFilteredOutRows(): Set<number>;
68
+ }
69
+ /**
70
+ * This is the filter criteria on a specific column.
71
+ */
72
+ export declare class FilterColumn extends Disposable {
73
+ readonly unitId: string;
74
+ readonly subUnitId: string;
75
+ private readonly _worksheet;
76
+ /**
77
+ * A `FilterColumn` instance should not be created without a filter criteria.
78
+ */
79
+ private _criteria;
80
+ private readonly _filterColumnContext;
81
+ private _filteredOutRows;
82
+ get filteredOutRows(): Readonly<Nullable<Set<number>>>;
83
+ /** Cache the filter function. */
84
+ private _filterFn;
85
+ private _range;
86
+ private _column;
87
+ private _filterByValues;
88
+ constructor(unitId: string, subUnitId: string, _worksheet: Worksheet,
89
+ /**
90
+ * A `FilterColumn` instance should not be created without a filter criteria.
91
+ */
92
+ _criteria: IFilterColumn, _filterColumnContext: IFilterColumnContext);
93
+ dispose(): void;
94
+ /**
95
+ * @internal
96
+ */
97
+ __clearCache(): void;
98
+ serialize(): IFilterColumn;
99
+ hasCache(): boolean;
100
+ setRangeAndColumn(range: IRange, column: number): void;
101
+ setCriteria(criteria: IFilterColumn): void;
102
+ getColumnData(): Readonly<IFilterColumn>;
103
+ /**
104
+ * Trigger new calculation on this `FilterModel` instance.
105
+ *
106
+ * @external DO NOT EVER call this method from `FilterColumn` itself. The whole process heavily relies on
107
+ * `filteredOutByOthers`, and it is more comprehensible if we let `FilterModel` take full control over the process.
108
+ */
109
+ reCalc(): Readonly<Nullable<Set<number>>>;
110
+ calc(context: IFilterColumnContext): Readonly<Nullable<Set<number>>>;
111
+ private _generateFilterFn;
112
+ }
113
+ /**
114
+ * Filter function is a close function which received a cell's content and determine this value is considered as
115
+ * "matched" and the corresponding row would not be filtered out.
116
+ */
117
+ export type FilterFn = (value: Nullable<CellValue>) => boolean;
118
+ /**
119
+ * This functions take a `IFilterColumn` as input and return a function that can be used to filter rows.
120
+ * @param column
121
+ * @returns the filter function that takes the cell's value and return a boolean.
122
+ */
123
+ export declare function generateFilterFn(column: IFilterColumn): FilterFn;
124
+ export {};
@@ -0,0 +1,53 @@
1
+ import { BooleanNumber, IRange } from '@univerjs/core';
2
+
3
+ export interface IAutoFilter {
4
+ ref: IRange;
5
+ filterColumns?: IFilterColumn[];
6
+ cachedFilteredOut?: number[];
7
+ }
8
+ export interface IFilterColumn {
9
+ colId: number;
10
+ /**
11
+ * The filter value could be an empty string, which means <filters blank="1">.
12
+ */
13
+ filters?: IFilters;
14
+ customFilters?: ICustomFilters;
15
+ }
16
+ export interface IFilters {
17
+ blank?: true;
18
+ filters?: Array<string>;
19
+ }
20
+ export interface ICustomFilters {
21
+ and?: BooleanNumber.TRUE;
22
+ /** Max 2 capacity. */
23
+ customFilters: [ICustomFilter] | [ICustomFilter, ICustomFilter];
24
+ }
25
+ export interface IDynamicFilter {
26
+ val: string | number;
27
+ type: DynamicFilterOperator;
28
+ }
29
+ export interface ICustomFilter {
30
+ val: string | number;
31
+ /** This field may be empty. */
32
+ operator?: CustomFilterOperator;
33
+ }
34
+ /**
35
+ * These basic operators are defined in 18.18.31.
36
+ *
37
+ * Some comparison such as startsWith, endsWith, contains, doesNotContain, isBlank, isNotBlank are not defined in OOXML.
38
+ * They are represented by regex-like values.
39
+ */
40
+ export declare enum CustomFilterOperator {
41
+ EQUAL = "equal",
42
+ GREATER_THAN = "greaterThan",
43
+ GREATER_THAN_OR_EQUAL = "greaterThanOrEqual",
44
+ LESS_THAN = "lessThan",
45
+ LESS_THAN_OR_EQUAL = "lessThanOrEqual",
46
+ NOT_EQUALS = "notEqual"
47
+ }
48
+ /**
49
+ * Not used now. Would be used in the future.
50
+ */
51
+ export declare enum DynamicFilterOperator {
52
+ ABOVE_AVERAGE = "aboveAverage"
53
+ }
@@ -0,0 +1,10 @@
1
+ import { Injector } from '@wendellhu/redi';
2
+ import { Plugin, UniverInstanceType } from '@univerjs/core';
3
+
4
+ export declare class UniverSheetsFilterPlugin extends Plugin {
5
+ protected readonly _injector: Injector;
6
+ static type: UniverInstanceType;
7
+ static pluginName: string;
8
+ constructor(_config: unknown, _injector: Injector);
9
+ onStarting(injector: Injector): void;
10
+ }
@@ -0,0 +1,42 @@
1
+ import { IAutoFilter } from '../models/types';
2
+ import { FilterModel } from '../models/filter-model';
3
+ import { Nullable, Disposable, ICommandService, IResourceManagerService, IUniverInstanceService } from '@univerjs/core';
4
+
5
+ export declare const FILTER_MUTATIONS: Set<string>;
6
+ type WorksheetID = string;
7
+ export interface ISheetsFilterResource {
8
+ [key: WorksheetID]: IAutoFilter;
9
+ }
10
+ export declare const SHEET_FILTER_SNAPSHOT_ID = "SHEET_FILTER_PLUGIN";
11
+ /**
12
+ * This service is responsible for managing filter models, especially their lifecycle.
13
+ */
14
+ export declare class SheetsFilterService extends Disposable {
15
+ private readonly _resourcesManagerService;
16
+ private readonly _univerInstanceService;
17
+ private readonly _commandService;
18
+ private readonly _filterModels;
19
+ private readonly _loadedUnitId$;
20
+ readonly loadedUnitId$: import('rxjs').Observable<Nullable<string>>;
21
+ private readonly _activeFilterModel$;
22
+ /** An observable value emitting the current Workbook's active Worksheet's filter model (if there is one). */
23
+ readonly activeFilterModel$: import('rxjs').Observable<Nullable<FilterModel>>;
24
+ /** The current Workbook's active Worksheet's filter model (if there is one). */
25
+ get activeFilterModel(): Nullable<FilterModel>;
26
+ constructor(_resourcesManagerService: IResourceManagerService, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService);
27
+ /**
28
+ *
29
+ * @param unitId
30
+ * @param subUnitId
31
+ */
32
+ ensureFilterModel(unitId: string, subUnitId: string): FilterModel;
33
+ getFilterModel(unitId: string, subUnitId: string): Nullable<FilterModel>;
34
+ removeFilterModel(unitId: string, subUnitId: string): boolean;
35
+ private _updateActiveFilterModel;
36
+ private _initActiveFilterModel;
37
+ private _serializeAutoFiltersForUnit;
38
+ private _deserializeAutoFiltersForUnit;
39
+ private _initModel;
40
+ private _cacheFilterModel;
41
+ }
42
+ export {};
@@ -0,0 +1,11 @@
1
+ import { IMutationInfo, Nullable } from '@univerjs/core';
2
+
3
+ interface ILine {
4
+ start: number;
5
+ end: number;
6
+ }
7
+ export declare function lineIntersect(line1: ILine, line2: ILine): boolean;
8
+ export declare function lineContains(line1: ILine, line2: ILine): boolean;
9
+ export declare function objectsShaker<T>(target: Nullable<T>[], isEqual: (o1: T, o2: T) => boolean): T[];
10
+ export declare function mergeSetFilterCriteria(mutations: IMutationInfo[]): IMutationInfo<object>[];
11
+ export {};
@@ -0,0 +1 @@
1
+ (function(h,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("rxjs"),require("@univerjs/sheets")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","rxjs","@univerjs/sheets"],d):(h=typeof globalThis<"u"?globalThis:h||self,d(h.UniverSheetsFilter={},h.UniverCore,h["@wendellhu/redi"],h.rxjs,h.UniverSheets))})(this,function(h,d,O,T,E){"use strict";var ye=Object.defineProperty;var Te=(h,d,O)=>d in h?ye(h,d,{enumerable:!0,configurable:!0,writable:!0,value:O}):h[d]=O;var R=(h,d,O)=>(Te(h,typeof d!="symbol"?d+"":d,O),O);var B;var y=(i=>(i.EQUAL="equal",i.GREATER_THAN="greaterThan",i.GREATER_THAN_OR_EQUAL="greaterThanOrEqual",i.LESS_THAN="lessThan",i.LESS_THAN_OR_EQUAL="lessThanOrEqual",i.NOT_EQUALS="notEqual",i))(y||{});const W={operator:y.GREATER_THAN,fn:(i,n)=>P(i)?i>n:!1},D={operator:y.GREATER_THAN_OR_EQUAL,fn:(i,n)=>P(i)?i>=n:!1},V={operator:y.LESS_THAN,fn:(i,n)=>P(i)?i<n:!1},q={operator:y.LESS_THAN_OR_EQUAL,fn:(i,n)=>P(i)?i<=n:!1},Q={operator:y.EQUAL,fn:(i,n)=>P(i)?i===n:!1},b={operator:y.NOT_EQUALS,fn:(i,n)=>{if(typeof n=="string"){if(n===" ")return i!=null;const e=X(i);return e&&ne(n)?!Y(n).test(e):e!==n}return P(i)?i!==n:!0}},G=new Map([]);[W,D,V,q,Q,b].forEach(i=>{G.set(i.operator,i)});function re(i){return!!i}const ie={fn:(i,n)=>{const e=X(i);return e===null?n==="":Y(n).test(e)}};function j(i){return i?G.get(i):ie}function P(i){return typeof i=="number"}function J(i){return!!(typeof i=="number"||typeof i=="string"&&d.isNumeric(i))}function X(i){return typeof i=="boolean"||i==null?null:typeof i=="string"?i:i.toString()}function ne(i){return typeof i=="number"?!1:i.indexOf("*")!==-1||i.indexOf("?")!==-1}function Y(i){const n=i.replace(/[.+^${}()|[\]\\]/g,"\\$&").replaceAll("?",".").replace(/[*]/g,".$&");return new RegExp(`^${n}$`)}const x=()=>new Set;class $ extends d.Disposable{constructor(e,t,r){super();R(this,"_filteredOutRows$",new T.BehaviorSubject(x()));R(this,"filteredOutRows$",this._filteredOutRows$.asObservable());R(this,"_hasCriteria$",new T.BehaviorSubject(!1));R(this,"hasCriteria$",this._hasCriteria$.asObservable());R(this,"_filterColumnByIndex",new Map);R(this,"_alreadyFilteredOutRows",x());R(this,"_range");this.unitId=e,this.subUnitId=t,this._worksheet=r}get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete()}serialize(){const e={ref:d.Rectangle.clone(this._range),filterColumns:this._getAllFilterColumns(!0).sort(([t],[r])=>t-r).map(([t,r])=>r.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(e,t,r,s){const o=new $(e,t,r);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.forEach(r=>this._setCriteriaWithoutReCalc(r.colId,r)),e.cachedFilteredOut&&(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw new 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((t,[,r])=>{const s=r.calc({getAlreadyFilteredOutRows:()=>t});return s?d.mergeSets(t,s):t},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,r])=>{r.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,r=!1){if(!this._range)throw new Error("[FilterModel] could not set criteria before a range is set!");if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),r&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),r&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))!=null?t:null}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){const t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([r,s])=>s)}_reCalcAllColumns(){this._alreadyFilteredOutRows=x(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns()}_setCriteriaWithoutReCalc(e,t){const r=this._range;if(!r)throw new Error("[FilterModel] could not set criteria before a range is set!");const{startColumn:s,endColumn:o}=r;if(e>o||e<s)throw new Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);let l;this._filterColumnByIndex.has(e)?l=this._filterColumnByIndex.get(e):(l=new K(this.unitId,this.subUnitId,this._worksheet,t,{getAlreadyFilteredOutRows:()=>this._alreadyFilteredOutRows}),l.setRangeAndColumn(r,e),this._filterColumnByIndex.set(e,l)),l.setCriteria(t)}_removeCriteria(e){const 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(){const e=this._getAllFilterColumns().filter(t=>t.hasCache()).reduce((t,r)=>d.mergeSets(t,r.filteredOutRows),new Set);this._alreadyFilteredOutRows=e}_reCalcWithNoCacheColumns(){const e=this._getAllFilterColumns().filter(t=>!t.hasCache());for(const t of e){const r=t.reCalc();r&&(this._alreadyFilteredOutRows=d.mergeSets(this._alreadyFilteredOutRows,r))}}}class K extends d.Disposable{constructor(e,t,r,s,o){super();R(this,"_filteredOutRows",null);R(this,"_filterFn",null);R(this,"_range",null);R(this,"_column",0);R(this,"_filterByValues",!1);this.unitId=e,this.subUnitId=t,this._worksheet=r,this._criteria=s,this._filterColumnContext=o}get filteredOutRows(){return this._filteredOutRows}dispose(){super.dispose(),this._filteredOutRows=null}__clearCache(){this._filteredOutRows=null}serialize(){if(!this._criteria)throw new Error("[FilterColumn]: could not serialize without a filter column!");return d.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 d.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw new Error("[FilterColumn] cannot calculate without a filter fn!");if(!this._range)throw new Error("[FilterColumn] cannot calculate without a range!");if(typeof this._column!="number")throw new TypeError("[FilterColumn] cannot calculate without a column offset!");const t=this._column,r={startColumn:t,endColumn:t,startRow:this._range.startRow+1,endRow:this._range.endRow},s=new Set,o=e.getAlreadyFilteredOutRows();for(const l of this._worksheet.iterateByColumn(r,!1,!1)){const{row:a,rowSpan:c,col:u}=l;if(o.has(a)&&(!c||c===1))continue;const m=this._filterByValues?d.extractPureTextFromCell(this._worksheet.getCell(a,u)):he(this._worksheet,a,u);if(!this._filterFn(m)&&(s.add(a),c))for(let C=1;C<c;C++)s.add(a+C)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=se(this._criteria),this._filterByValues=!!this._criteria.filters)}}function se(i){if(i.filters)return oe(i.filters);if(i.customFilters)return le(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function oe(i){const n=!!i.blank,e=new Set(i.filters);return t=>t===void 0||t===""?n:e.has(typeof t=="string"?t:`${t}`)}function le(i){const n=i.customFilters.map(e=>de(e));return ce(n)?i.and?ae(n):ue(n):n[0]}function ae(i){const[n,e]=i;return t=>n(t)&&e(t)}function ue(i){const[n,e]=i;return t=>n(t)||e(t)}function ce(i){return i.length===2}function de(i){const n=i.val;if(i.operator===y.NOT_EQUALS&&!J(n))return r=>b.fn(r,n);if(re(i.operator)){if(!J(n))return()=>!1;const r=j(i.operator),s=Number(n);return o=>r.fn(o,s)}const e=j(i.operator);return t=>e.fn(t,n)}function he(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?Z(t):r?t.t===d.CellValueType.NUMBER&&typeof t.v=="string"?r.v:Z(r):null}function Z(i){var t,r;const n=(r=(t=i.p)==null?void 0:t.body)==null?void 0:r.dataStream;if(n)return n.trimEnd();const e=i.v;return typeof e=="string"?i.t===d.CellValueType.BOOLEAN?e.toUpperCase():e:typeof e=="number"?i.t===d.CellValueType.BOOLEAN?e?"TRUE":"FALSE":e:typeof e=="boolean"?e?"TRUE":"FALSE":""}const g={id:"sheet.mutation.set-filter-range",type:d.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,range:r}=n;return i.get(h.SheetsFilterService).ensureFilterModel(t,e).setRange(r),!0}},p={id:"sheet.mutation.set-filter-criteria",type:d.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,criteria:r,col:s,reCalc:o=!0}=n,a=i.get(h.SheetsFilterService).getFilterModel(t,e);return a?(a.setCriteria(s,r,o),!0):!1}},A={id:"sheet.mutation.remove-filter",type:d.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(h.SheetsFilterService).removeFilterModel(e,t)}},z={id:"sheet.mutation.re-calc-filter",type:d.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n,s=i.get(h.SheetsFilterService).getFilterModel(e,t);return s?(s.reCalc(),!0):!1}};var fe=Object.defineProperty,me=Object.getOwnPropertyDescriptor,_e=(i,n,e,t)=>{for(var r=t>1?void 0:t?me(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&fe(n,e,r),r},H=(i,n)=>(e,t)=>n(e,t,i);const k=new Set([g.id,p.id,A.id,z.id]),ee="SHEET_FILTER_PLUGIN";h.SheetsFilterService=class extends d.Disposable{constructor(e,t,r){super();R(this,"_filterModels",new Map);R(this,"_loadedUnitId$",new T.BehaviorSubject(null));R(this,"loadedUnitId$",this._loadedUnitId$.asObservable());R(this,"_activeFilterModel$",new T.BehaviorSubject(null));R(this,"activeFilterModel$",this._activeFilterModel$.asObservable());this._resourcesManagerService=e,this._univerInstanceService=t,this._commandService=r,this._initModel(),this._initActiveFilterModel()}get activeFilterModel(){return this._activeFilterModel$.getValue()}ensureFilterModel(e,t){const r=this.getFilterModel(e,t);if(r)return r;const s=this._univerInstanceService.getUniverSheetInstance(e);if(!s)throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${e}!`);const o=s.getSheetBySheetId(t);if(!o)throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${t}!`);const l=new $(e,t,o);return this._cacheFilterModel(e,t,l),l}getFilterModel(e,t){var r,s;return(s=(r=this._filterModels.get(e))==null?void 0:r.get(t))!=null?s:null}removeFilterModel(e,t){const r=this.getFilterModel(e,t);return r?(r.dispose(),this._filterModels.get(e).delete(t),!0):!1}_updateActiveFilterModel(){let e;try{if(e=this._univerInstanceService.getCurrentUnitForType(d.UniverInstanceType.UNIVER_SHEET),!e){this._activeFilterModel$.next(null);return}}catch{return}const t=e.getActiveSheet();if(!t){this._activeFilterModel$.next(null);return}const r=t.getUnitId(),s=t.getSheetId(),o=this.getFilterModel(r,s);this._activeFilterModel$.next(o)}_initActiveFilterModel(){this.disposeWithMe(T.merge(d.fromCallback(this._commandService.onCommandExecuted).pipe(T.filter(([e])=>e.type===d.CommandType.MUTATION&&k.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(T.switchMap(e=>{var t;return(t=e==null?void 0:e.activeSheet$)!=null?t:T.of(null)}))).subscribe(()=>this._updateActiveFilterModel()))}_serializeAutoFiltersForUnit(e){const t=this._filterModels.get(e);if(!t)return"{}";const r={};return t.forEach((s,o)=>{r[o]=s.serialize()}),JSON.stringify(r)}_deserializeAutoFiltersForUnit(e,t){const r=this._univerInstanceService.getUniverSheetInstance(e);Object.keys(t).forEach(s=>{const o=t[s],l=$.deserialize(e,s,r.getSheetBySheetId(s),o);this._cacheFilterModel(e,s,l)})}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:ee,businesses:[2],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=>{const t=this._filterModels.get(e);t&&(t.forEach(r=>r.dispose()),this._filterModels.delete(e))}})}_cacheFilterModel(e,t,r){this._filterModels.has(e)||this._filterModels.set(e,new Map),this._filterModels.get(e).set(t,r)}},h.SheetsFilterService=_e([d.OnLifecycle(d.LifecycleStages.Ready,h.SheetsFilterService),H(0,d.IResourceManagerService),H(1,d.IUniverInstanceService),H(2,d.ICommandService)],h.SheetsFilterService);function Ce(i,n){for(let e=0;e<i.length;e++){let t=e;if(i[e])for(let r=e+1;r<i.length;r++)i[t]&&i[r]&&n(i[t],i[r])&&(i[t]=null,t=r)}return i.filter(e=>e!==null)}function N(i){return Ce(i,(n,e)=>n.id===p.id&&e.id===p.id&&n.params.unitId===e.params.unitId&&n.params.subUnitId===e.params.subUnitId&&n.params.col===e.params.col)}var ge=Object.defineProperty,Re=Object.getOwnPropertyDescriptor,Fe=(i,n,e,t)=>{for(var r=t>1?void 0:t?Re(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&ge(n,e,r),r},L=(i,n)=>(e,t)=>n(e,t,i);let U=class extends d.Disposable{constructor(i,n,e,t,r){super(),this._commandService=i,this._sheetInterceptorService=n,this._sheetsFilterService=e,this._univerInstanceService=t,this._refRangeService=r,this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener()}_initCommands(){[p,g,z,A].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initInterceptors(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>this._getUpdateFilter(e)}));const i=new d.DisposableCollection,n=(e,t)=>{var a;const r=this._univerInstanceService.getUniverSheetInstance(e);if(!r||!(r==null?void 0:r.getSheetBySheetId(t)))return;i.dispose();const o=(a=this._sheetsFilterService.getFilterModel(e,t))==null?void 0:a.getRange(),l=c=>{switch(c.id){case E.InsertRowCommand.id:{const u=c.params,m=u.unitId||e,C=u.subUnitId||t;return this._handleInsertRowCommand(u,m,C)}case E.InsertColCommand.id:{const u=c.params,m=u.unitId||e,C=u.subUnitId||t;return this._handleInsertColCommand(u,m,C)}case E.RemoveColCommand.id:{const u=c.params;return this._handleRemoveColCommand(u,e,t)}case E.RemoveRowCommand.id:{const u=c.params;return this._handleRemoveRowCommand(u,e,t)}case E.EffectRefRangId.MoveColsCommandId:{const u=c.params;return this._handleMoveColsCommand(u,e,t)}case E.EffectRefRangId.MoveRowsCommandId:{const u=c.params;return this._handleMoveRowsCommand(u,e,t)}case E.MoveRangeCommand.id:{const u=c.params;return this._handleMoveRangeCommand(u,e,t)}}return{redos:[],undos:[]}};o&&i.add(this._refRangeService.registerRefRange(o,l,e,t))};this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===E.SetWorksheetActivateCommand.id){const t=e.params,r=t.subUnitId,s=t.unitId;if(!r||!s)return;n(s,r)}if(e.id===g.id){const t=e.params,r=t.subUnitId,s=t.unitId;if(!r||!s)return;n(t.unitId,t.subUnitId)}})),this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe(e=>{if(e){const t=this._univerInstanceService.getUniverSheetInstance(e),r=t==null?void 0:t.getActiveSheet();r&&n(e,r.getSheetId())}}))}_getUpdateFilter(i){const{id:n}=i;switch(n){case E.RemoveSheetCommand.id:{const e=i.params;return this._handleRemoveSheetCommand(e,e.unitId,e.subUnitId)}}return{redos:[],undos:[]}}_handleInsertColCommand(i,n,e){var _;const t=this._sheetsFilterService.getFilterModel(n,e),r=(_=t==null?void 0:t.getRange())!=null?_:null;if(!t||!r)return this._handleNull();const{startColumn:s,endColumn:o}=r,{startColumn:l,endColumn:a}=i.range,c=a-l+1;if(a>o)return this._handleNull();const u=[],m=[],C=l,w={unitId:n,subUnitId:e,range:{...r,startColumn:l<=s?s+c:s,endColumn:o+c}},S={unitId:n,subUnitId:e,range:r};u.push({id:g.id,params:w}),m.push({id:g.id,params:S});const f=t.getAllFilterColumns().filter(F=>F[0]>=C);if(f.length!==0){const{undos:F,redos:M}=this.moveCriteria(n,e,f,c);u.push(...M),m.push(...F)}return{redos:N(u),undos:N(m)}}_handleInsertRowCommand(i,n,e){var S;const t=this._sheetsFilterService.getFilterModel(n,e),r=(S=t==null?void 0:t.getRange())!=null?S:null;if(!t||!r)return this._handleNull();const{startRow:s,endRow:o}=r,{startRow:l,endRow:a}=i.range,c=a-l+1;if(a>o)return this._handleNull();const u=[],m=[],C={unitId:n,subUnitId:e,range:{...r,startRow:l<=s?s+c:s,endRow:o+c}},w={unitId:n,subUnitId:e,range:r};return u.push({id:g.id,params:C}),m.push({id:g.id,params:w}),{redos:N(u),undos:N(m)}}_handleRemoveColCommand(i,n,e){var v;const t=this._sheetsFilterService.getFilterModel(n,e),r=(v=t==null?void 0:t.getRange())!=null?v:null;if(!t||!r)return this._handleNull();const{startColumn:s,endColumn:o}=r,{startColumn:l,endColumn:a}=i.range;if(l>o)return this._handleNull();const c=[],u=[],m=a<s?0:Math.min(a,o)-Math.max(l,s)+1,C=a-l+1,w=t.getAllFilterColumns();w.forEach(f=>{const[_,F]=f;_<=a&&_>=l&&(c.push({id:p.id,params:{unitId:n,subUnitId:e,col:_,criteria:null}}),u.push({id:p.id,params:{unitId:n,subUnitId:e,col:_,criteria:{...F.serialize(),colId:_}}}))});const S=w.filter(f=>{const[_,F]=f;return _>a});if(S.length>0){const{undos:f,redos:_}=this.moveCriteria(n,e,S,-C);c.push(..._),u.push(...f)}if(m===o-s+1){const f={unitId:n,subUnitId:e};c.push({id:A.id,params:f})}else if(s<=l){const f=o-m,_={unitId:n,subUnitId:e,range:{...r,endColumn:f}};c.push({id:g.id,params:_})}else{const f={unitId:n,subUnitId:e,range:{...r,startColumn:l,endColumn:o-(a-l+1)}};c.push({id:g.id,params:f})}return u.push({id:g.id,params:{range:r,unitId:n,subUnitId:e}}),{undos:N(u),redos:N(c)}}_handleRemoveRowCommand(i,n,e){var S;const t=this._sheetsFilterService.getFilterModel(n,e);if(!t)return this._handleNull();const r=t.getRange(),{startRow:s,endRow:o}=r,{startRow:l,endRow:a}=i.range;if(l>o)return this._handleNull();const c=[],u=[],m=t.getAllFilterColumns(),C=s<=a&&s>=l;u.push({id:g.id,params:{range:r,unitId:n,subUnitId:e}});const w=Math.min(a,o)-Math.max(l,s)+1;if(w===o-s+1||C){const v={unitId:n,subUnitId:e};c.push({id:A.id,params:v}),m.forEach(f=>{const[_,F]=f,M={unitId:n,subUnitId:e,col:_,criteria:{...F.serialize(),colId:_}};u.push({id:p.id,params:M})})}else{const v=(S=this._univerInstanceService.getUniverSheetInstance(n))==null?void 0:S.getSheetBySheetId(e);if(!v)return this._handleNull();const f=[];for(let I=l;I<=a;I++)v.getRowFiltered(I)&&f.push(I);const _=Math.min(s,l),F=_+(o-s)-w+f.length,M={unitId:n,subUnitId:e,range:{...r,startRow:_,endRow:F}};c.push({id:g.id,params:M})}return{undos:N(u),redos:N(c)}}_handleMoveColsCommand(i,n,e){var v;const t=this._sheetsFilterService.getFilterModel(n,e),r=(v=t==null?void 0:t.getRange())!=null?v:null;if(!t||!r)return this._handleNull();const{startColumn:s,endColumn:o}=r,{fromRange:l,toRange:a}=i;if(l.endColumn<s&&a.startColumn<=s||l.startColumn>o&&a.endColumn>o)return this._handleNull();const c=[],u=[],m={};for(let f=s;f<=o;f++)m[f]={colIndex:f,filter:t.getFilterColumn(f)};d.moveMatrixArray(l.startColumn,l.endColumn-l.startColumn+1,a.startColumn,m);const C=Object.keys(m).map(f=>Number(f)),w=Math.max(...C),S=Math.min(...C);if(C.forEach(f=>{var I,te;const{colIndex:_,filter:F}=m[f],M=f;if(F){const Ee={unitId:n,subUnitId:e,col:M,criteria:{...F.serialize(),colId:M}};if(c.push({id:p.id,params:Ee}),u.push({id:A.id,params:{unitId:n,subUnitId:e,col:M,criteria:{...(I=t.getFilterColumn(M))==null?void 0:I.serialize(),colId:M}}}),!((te=m[_])!=null&&te.filter)){const Oe={unitId:n,subUnitId:e,col:_,criteria:null};c.push({id:p.id,params:Oe}),u.push({id:p.id,params:{unitId:n,subUnitId:e,col:_,criteria:{...F.serialize(),colId:_}}})}}}),s!==S||o!==w){const f={unitId:n,subUnitId:e,range:{...r,startColumn:S,endColumn:w}};c.unshift({id:g.id,params:f}),u.push({id:g.id,params:{range:r,unitId:n,subUnitId:e}})}return{undos:u,redos:c}}_handleMoveRowsCommand(i,n,e){var v;const t=this._sheetsFilterService.getFilterModel(n,e),r=(v=t==null?void 0:t.getRange())!=null?v:null;if(!t||!r)return this._handleNull();const{startRow:s,endRow:o}=r,{fromRange:l,toRange:a}=i;if(l.endRow<s&&a.startRow<=s||l.startRow>o&&a.endRow>o)return this._handleNull();const c=[],u=[],m={};for(let f=s;f<=o;f++)m[f]={offset:f-s};d.moveMatrixArray(l.startRow,l.endRow-l.startRow+1,a.startRow,m);const C=Object.keys(m).map(f=>Number(f)),w=Math.max(...C),S=Math.min(...C);if(s!==S||o!==w){const f={unitId:n,subUnitId:e,range:{...r,startRow:S,endRow:w}};c.unshift({id:g.id,params:f}),u.push({id:g.id,params:{range:r,unitId:n,subUnitId:e}})}return{redos:c,undos:u}}_handleMoveRangeCommand(i,n,e){const{fromRange:t,toRange:r}=i,s=this._sheetsFilterService.getFilterModel(n,e);if(!s)return this._handleNull();const o=s.getRange();if(!o)return this._handleNull();const l=[],a=[];if(d.Rectangle.contains(t,o)){const c=o.startRow-t.startRow,u=o.startColumn-t.startColumn,m={startRow:r.startRow+c,startColumn:r.startColumn+u,endRow:r.startRow+c+(o.endRow-o.startRow),endColumn:r.startColumn+u+(o.endColumn-o.startColumn)},C={id:A.id,params:{unitId:n,subUnitId:e}},w={id:g.id,params:{unitId:n,subUnitId:e,range:m}},S={id:g.id,params:{unitId:n,subUnitId:e,range:o}};l.push(C,w),a.push(C,S);const v=s.getAllFilterColumns(),f=r.startColumn-t.startColumn;v.forEach(_=>{const[F,M]=_;M&&(l.push({id:p.id,params:{unitId:n,subUnitId:e,col:F+f,criteria:{...M.serialize(),colId:F+f}}}),a.push({id:p.id,params:{unitId:n,subUnitId:e,col:F,criteria:{...M.serialize(),colId:F}}}))})}return{redos:l,undos:a}}_handleRemoveSheetCommand(i,n,e){const t=this._sheetsFilterService.getFilterModel(n,e);if(!t)return this._handleNull();const r=t.getRange();if(!r)return this._handleNull();const s=[],o=[];return t.getAllFilterColumns().forEach(a=>{const[c,u]=a;o.push({id:p.id,params:{unitId:n,subUnitId:e,col:a,criteria:{...u.serialize(),colId:a}}})}),s.push({id:A.id,params:{unitId:n,subUnitId:e,range:r}}),o.unshift({id:g.id,params:{range:r,unitId:n,subUnitId:e}}),{undos:o,redos:s}}_handleNull(){return{redos:[],undos:[]}}_initRowFilteredInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(E.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(i,n)=>{var e,t;return i?!0:(t=(e=this._sheetsFilterService.getFilterModel(n.unitId,n.subUnitId))==null?void 0:e.isRowFiltered(n.row))!=null?t:!1}}))}moveCriteria(i,n,e,t){const r={unitId:i,subUnitId:n,criteria:null,col:-1},s=[],o=[];return e.forEach(l=>{const[a,c]=l;o.push({id:p.id,params:{...r,col:a}}),s.push({id:p.id,params:{...r,col:a,criteria:{...c.serialize(),colId:a}}})}),e.forEach(l=>{const[a,c]=l;o.push({id:p.id,params:{...r,col:a+t,criteria:{...c.serialize(),colId:a+t}}}),s.push({id:p.id,params:{...r,col:a+t,criteria:null}})}),{redos:o,undos:s}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{const{unitId:n,subUnitId:e}=i.params||{},t=this._sheetsFilterService.getFilterModel(n,e);if(!t)return;const r=Array.from(t.filteredOutRows).sort((l,a)=>l-a),s=[];let o=!1;if(i.id===E.RemoveRowMutation.id){const{startRow:l,endRow:a}=i.params.range,c=r.filter(u=>u>=l&&u<=a);r.forEach(u=>{if(u<l)s.push(u);else if(o=!0,u<=a){const m=Math.max(l,s.length?s[s.length-1]+1:l);s.push(m)}else s.push(u-(a-l+1-c.length))})}if(i.id===E.InsertRowMutation.id){const{startRow:l,endRow:a}=i.params.range;r.forEach(c=>{c>=l?(o=!0,s.push(c+(a-l+1))):s.push(c)})}o&&(t.filteredOutRows=new Set(s))}))}};U=Fe([d.OnLifecycle(d.LifecycleStages.Ready,U),L(0,d.ICommandService),L(1,O.Inject(E.SheetInterceptorService)),L(2,O.Inject(h.SheetsFilterService)),L(3,d.IUniverInstanceService),L(4,O.Inject(E.RefRangeService))],U);var pe=Object.defineProperty,Se=Object.getOwnPropertyDescriptor,we=(i,n,e,t)=>{for(var r=t>1?void 0:t?Se(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&pe(n,e,r),r},ve=(i,n)=>(e,t)=>n(e,t,i);const Me="UNIVER_SHEETS_FILTER_PLUGIN";h.UniverSheetsFilterPlugin=(B=class extends d.Plugin{constructor(n,e){super(),this._injector=e}onStarting(n){[[h.SheetsFilterService],[U]].forEach(e=>n.add(e))}},R(B,"type",d.UniverInstanceType.UNIVER_SHEET),R(B,"pluginName",Me),B),h.UniverSheetsFilterPlugin=we([ve(1,O.Inject(O.Injector))],h.UniverSheetsFilterPlugin),h.CustomFilterOperator=y,h.FILTER_MUTATIONS=k,h.FilterColumn=K,h.FilterModel=$,h.ReCalcSheetsFilterMutation=z,h.RemoveSheetsFilterMutation=A,h.SHEET_FILTER_SNAPSHOT_ID=ee,h.SetSheetsFilterCriteriaMutation=p,h.SetSheetsFilterRangeMutation=g,h.equals=Q,h.getCustomFilterFn=j,h.greaterThan=W,h.greaterThanOrEqualTo=D,h.lessThan=V,h.lessThanOrEqualTo=q,h.notEquals=b,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@univerjs/sheets-filter",
3
+ "version": "0.1.8",
4
+ "private": false,
5
+ "description": "A library for filtering data in Univer Sheet",
6
+ "author": "DreamNum <developer@univer.ai>",
7
+ "license": "Apache-2.0",
8
+ "funding": {
9
+ "type": "opencollective",
10
+ "url": "https://opencollective.com/univer"
11
+ },
12
+ "homepage": "https://univer.ai",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/dream-num/univer"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/dream-num/univer/issues"
19
+ },
20
+ "keywords": [],
21
+ "exports": {
22
+ ".": {
23
+ "import": "./lib/es/index.js",
24
+ "require": "./lib/cjs/index.js",
25
+ "types": "./lib/types/index.d.ts"
26
+ },
27
+ "./*": {
28
+ "import": "./lib/es/*",
29
+ "require": "./lib/cjs/*",
30
+ "types": "./lib/types/index.d.ts"
31
+ },
32
+ "./lib/*": "./lib/*"
33
+ },
34
+ "main": "./lib/cjs/index.js",
35
+ "module": "./lib/es/index.js",
36
+ "types": "./lib/types/index.d.ts",
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "directories": {
41
+ "lib": "lib"
42
+ },
43
+ "files": [
44
+ "lib"
45
+ ],
46
+ "peerDependencies": {
47
+ "@wendellhu/redi": "^0.13.3",
48
+ "rxjs": ">=7.0.0",
49
+ "@univerjs/core": "0.1.8",
50
+ "@univerjs/sheets": "0.1.8"
51
+ },
52
+ "dependencies": {},
53
+ "devDependencies": {
54
+ "@wendellhu/redi": "^0.13.3",
55
+ "rxjs": "^7.8.1",
56
+ "typescript": "^5.4.5",
57
+ "vite": "^5.2.10",
58
+ "vitest": "^1.5.2",
59
+ "@univerjs/core": "0.1.8",
60
+ "@univerjs/shared": "0.1.8",
61
+ "@univerjs/sheets": "0.1.8"
62
+ },
63
+ "scripts": {
64
+ "test": "vitest run",
65
+ "test:watch": "vitest",
66
+ "coverage": "vitest run --coverage",
67
+ "lint:types": "tsc --noEmit",
68
+ "build": "tsc && vite build"
69
+ }
70
+ }