@univerjs/sheets-filter 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,22 @@
1
- import { ICommand, IMutationInfo, IRange, Nullable } from '@univerjs/core';
2
- import { ISheetCommandSharedParams } from '@univerjs/sheets';
3
- import { IAutoFilter, IFilterColumn } from '../../models/types';
4
- import { ISetSheetsFilterCriteriaMutationParams } from '../mutations/sheets-filter.mutation';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { ICommand, IMutationInfo, IRange, Nullable } from '@univerjs/core';
17
+ import type { ISheetCommandSharedParams } from '@univerjs/sheets';
18
+ import type { IAutoFilter, IFilterColumn } from '../../models/types';
19
+ import type { ISetSheetsFilterCriteriaMutationParams } from '../mutations/sheets-filter.mutation';
5
20
  /**
6
21
  * Parameters of command {@link SetSheetFilterRangeCommand}.
7
22
  * @property {IRange} range - the range to be set as filter range.
@@ -1,6 +1,21 @@
1
- import { IMutation, IRange, Nullable } from '@univerjs/core';
2
- import { ISheetCommandSharedParams } from '@univerjs/sheets';
3
- import { IFilterColumn } from '../../models/types';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { IMutation, IRange, Nullable } from '@univerjs/core';
17
+ import type { ISheetCommandSharedParams } from '@univerjs/sheets';
18
+ import type { IFilterColumn } from '../../models/types';
4
19
  /**
5
20
  * Parameters of mutation {@link SetSheetsFilterRangeMutation}.
6
21
  * @property range - the range to be set as filter range.
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { Disposable, ICommandService, IConfigService } from '@univerjs/core';
2
17
  import { SheetsFilterController } from './sheets-filter.controller';
3
18
  export declare class SheetsFilterSyncController extends Disposable {
@@ -6,10 +21,10 @@ export declare class SheetsFilterSyncController extends Disposable {
6
21
  private readonly _configService;
7
22
  private _d;
8
23
  private readonly _visible$;
9
- readonly visible$: import('rxjs').Observable<boolean>;
24
+ readonly visible$: import("rxjs").Observable<boolean>;
10
25
  get visible(): boolean;
11
26
  private readonly _enabled$;
12
- readonly enabled$: import('rxjs').Observable<boolean>;
27
+ readonly enabled$: import("rxjs").Observable<boolean>;
13
28
  get enabled(): boolean;
14
29
  constructor(_sheetsFilterController: SheetsFilterController, _commandService: ICommandService, _configService: IConfigService);
15
30
  setEnabled(enabled: boolean): void;
@@ -1,4 +1,20 @@
1
- import { IMutationInfo, IRange, Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { IMutationInfo, IRange } from '@univerjs/core';
17
+ import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
2
18
  import { DataSyncPrimaryController } from '@univerjs/rpc';
3
19
  import { RefRangeService, SheetInterceptorService, ZebraCrossingCacheController } from '@univerjs/sheets';
4
20
  import { SheetsFilterService } from '../services/sheet-filter.service';
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { CustomFilterOperator } from '@univerjs/sheets-filter';
2
17
  /**
3
18
  * @ignore
@@ -1,6 +1,22 @@
1
- import { IEventBase, FEventName } from '@univerjs/core/facade';
2
- import { ISetSheetsFilterCriteriaCommandParams } from '@univerjs/sheets-filter';
3
- import { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { IEventBase } from '@univerjs/core/facade';
17
+ import type { ISetSheetsFilterCriteriaCommandParams } from '@univerjs/sheets-filter';
18
+ import type { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
19
+ import { FEventName } from '@univerjs/core/facade';
4
20
  /**
5
21
  * @ignore
6
22
  */
@@ -1,5 +1,21 @@
1
- import { Nullable, Workbook, Worksheet, ICommandService, Injector } from '@univerjs/core';
2
- import { FilterModel, IFilterColumn, ISetSheetsFilterCriteriaCommandParams } from '@univerjs/sheets-filter';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { Nullable, Workbook, Worksheet } from '@univerjs/core';
17
+ import type { FilterModel, IFilterColumn, ISetSheetsFilterCriteriaCommandParams } from '@univerjs/sheets-filter';
18
+ import { ICommandService, Injector } from '@univerjs/core';
3
19
  import { FRange } from '@univerjs/sheets/facade';
4
20
  /**
5
21
  * This interface class provides methods to modify the filter settings of a worksheet.
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { FRange } from '@univerjs/sheets/facade';
2
17
  import { FFilter } from './f-filter';
3
18
  /**
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { FWorksheet } from '@univerjs/sheets/facade';
2
17
  import { FFilter } from './f-filter';
3
18
  /**
@@ -1,4 +1,19 @@
1
- import { CellValue, Nullable } from '@univerjs/core';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { CellValue, Nullable } from '@univerjs/core';
2
17
  import { CustomFilterOperator } from './types';
3
18
  export interface IFilterFn<P extends unknown[]> {
4
19
  label?: string;
@@ -1,6 +1,23 @@
1
- import { CellValue, IRange, IStyleData, Nullable, Worksheet, Disposable } from '@univerjs/core';
2
- import { Observable } from 'rxjs';
3
- import { IAutoFilter, IFilterColumn, FilterBy } from './types';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { CellValue, IRange, IStyleData, Nullable, Worksheet } from '@univerjs/core';
17
+ import type { Observable } from 'rxjs';
18
+ import type { IAutoFilter, IFilterColumn } from './types';
19
+ import { Disposable } from '@univerjs/core';
20
+ import { FilterBy } from './types';
4
21
  /**
5
22
  * This is the in-memory model of filter.
6
23
  */
@@ -1,4 +1,19 @@
1
- import { BooleanNumber, IRange } from '@univerjs/core';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { BooleanNumber, IRange } from '@univerjs/core';
2
17
  /**
3
18
  * The filter types.
4
19
  */
@@ -1,4 +1,19 @@
1
- import { IUniverSheetsFilterConfig } from './config/config';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { IUniverSheetsFilterConfig } from './config/config';
2
17
  import { IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
3
18
  export declare class UniverSheetsFilterPlugin extends Plugin {
4
19
  private readonly _config;
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ */
1
16
  import { Disposable, IUniverInstanceService } from '@univerjs/core';
2
17
  import { IActiveDirtyManagerService, ISheetRowFilteredService } from '@univerjs/engine-formula';
3
18
  import { SheetsFilterService } from './sheet-filter.service';
@@ -1,5 +1,21 @@
1
- import { Nullable, Disposable, ICommandService, IResourceManagerService, IUniverInstanceService } from '@univerjs/core';
2
- import { IAutoFilter } from '../models/types';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { Nullable } from '@univerjs/core';
17
+ import type { IAutoFilter } from '../models/types';
18
+ import { Disposable, ICommandService, IResourceManagerService, IUniverInstanceService } from '@univerjs/core';
3
19
  import { FilterModel } from '../models/filter-model';
4
20
  type WorksheetID = string;
5
21
  export interface ISheetsFilterResource {
@@ -15,12 +31,12 @@ export declare class SheetsFilterService extends Disposable {
15
31
  private readonly _commandService;
16
32
  private readonly _filterModels;
17
33
  private readonly _loadedUnitId$;
18
- readonly loadedUnitId$: import('rxjs').Observable<Nullable<string>>;
34
+ readonly loadedUnitId$: import("rxjs").Observable<Nullable<string>>;
19
35
  private readonly _errorMsg$;
20
- readonly errorMsg$: import('rxjs').Observable<Nullable<string>>;
36
+ readonly errorMsg$: import("rxjs").Observable<Nullable<string>>;
21
37
  private readonly _activeFilterModel$;
22
38
  /** 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>>;
39
+ readonly activeFilterModel$: import("rxjs").Observable<Nullable<FilterModel>>;
24
40
  /** The current Workbook's active Worksheet's filter model (if there is one). */
25
41
  get activeFilterModel(): Nullable<FilterModel>;
26
42
  constructor(_resourcesManagerService: IResourceManagerService, _univerInstanceService: IUniverInstanceService, _commandService: ICommandService);
@@ -1,4 +1,19 @@
1
- import { IMutationInfo, Nullable } from '@univerjs/core';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
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
+ import type { IMutationInfo, Nullable } from '@univerjs/core';
2
17
  interface ILine {
3
18
  start: number;
4
19
  end: number;
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(i,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@univerjs/core"),require("@univerjs/sheets-filter"),require("@univerjs/sheets/facade"),require("@univerjs/core/facade")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-filter","@univerjs/sheets/facade","@univerjs/core/facade"],h):(i=typeof globalThis<"u"?globalThis:i||self,h(i.UniverSheetsFilterFacade={},i.UniverCore,i.UniverSheetsFilter,i.UniverSheetsFacade,i.UniverCoreFacade))})(this,(function(i,h,n,a,l){"use strict";var m=Object.getOwnPropertyDescriptor,F=(s,e,t,r)=>{for(var o=r>1?void 0:r?m(e,t):e,d=s.length-1,u;d>=0;d--)(u=s[d])&&(o=u(o)||o);return o},c=(s,e)=>(t,r)=>e(t,r,s);i.FFilter=class{constructor(e,t,r,o,d){this._workbook=e,this._worksheet=t,this._filterModel=r,this._injector=o,this._commandSrv=d}getFilteredOutRows(){return Array.from(this._filterModel.filteredOutRows).sort()}getColumnFilterCriteria(e){var t;return(t=this._filterModel.getFilterColumn(e))==null?void 0:t.getColumnData()}removeColumnFilterCriteria(e){return this._commandSrv.syncExecuteCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),col:e,criteria:null}),this}setColumnFilterCriteria(e,t){return this._commandSrv.syncExecuteCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),col:e,criteria:t}),this}getRange(){const e=this._filterModel.getRange();return this._injector.createInstance(a.FRange,this._workbook,this._worksheet,e)}removeFilterCriteria(){return this._commandSrv.syncExecuteCommand(n.ClearSheetsFilterCriteriaCommand.id),this}remove(){return this._commandSrv.syncExecuteCommand(n.RemoveSheetFilterCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()})}},i.FFilter=F([c(3,h.Inject(h.Injector)),c(4,h.ICommandService)],i.FFilter);class g extends a.FRange{createFilter(){return this._getFilterModel()||!this._commandService.syncExecuteCommand(n.SetSheetFilterRangeCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range})?null:this.getFilter()}getFilter(){const e=this._getFilterModel();return e?this._injector.createInstance(i.FFilter,this._workbook,this._worksheet,e):null}_getFilterModel(){return this._injector.get(n.SheetsFilterService).getFilterModel(this._workbook.getUnitId(),this._worksheet.getSheetId())}}a.FRange.extend(g);class v extends a.FWorksheet{getFilter(){const e=this._getFilterModel();return e?this._injector.createInstance(i.FFilter,this._workbook,this._worksheet,e):null}_getFilterModel(){return this._injector.get(n.SheetsFilterService).getFilterModel(this._workbook.getUnitId(),this._worksheet.getSheetId())}}a.FWorksheet.extend(v);class S{get CustomFilterOperator(){return n.CustomFilterOperator}}l.FEnum.extend(S);class C extends l.FEventName{get SheetBeforeRangeFilter(){return"SheetBeforeRangeFilter"}get SheetRangeFiltered(){return"SheetRangeFiltered"}get SheetRangeFilterCleared(){return"SheetRangeFilterCleared"}get SheetBeforeRangeFilterClear(){return"SheetBeforeRangeFilterClear"}}l.FEventName.extend(C),l.FEventName.extend(a.FSheetEventName);class _ extends l.FUniver{_initialize(e){const t=e.get(h.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetBeforeRangeFilter,()=>t.beforeCommandExecuted(r=>{r.id===n.SetSheetsFilterCriteriaCommand.id&&this._beforeRangeFilter(r)}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetBeforeRangeFilterClear,()=>t.beforeCommandExecuted(r=>{r.id===n.ClearSheetsFilterCriteriaCommand.id&&this._beforeRangeFilterClear()}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetRangeFiltered,()=>t.onCommandExecuted(r=>{r.id===n.SetSheetsFilterCriteriaCommand.id&&this._onRangeFiltered(r)}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetRangeFilterCleared,()=>t.onCommandExecuted(r=>{r.id===n.ClearSheetsFilterCriteriaCommand.id&&this._onRangeFilterCleared()})))}_beforeRangeFilter(e){const t=e.params,r=this.getUniverSheet(t.unitId),o={workbook:r,worksheet:r.getSheetBySheetId(t.subUnitId),col:t.col,criteria:t.criteria};if(this.fireEvent(this.Event.SheetBeforeRangeFilter,o),o.cancel)throw new Error("SetSheetsFilterCriteriaCommand canceled.")}_onRangeFiltered(e){const t=e.params,r=this.getUniverSheet(t.unitId),o={workbook:r,worksheet:r.getSheetBySheetId(t.subUnitId),col:t.col,criteria:t.criteria};this.fireEvent(this.Event.SheetRangeFiltered,o)}_beforeRangeFilterClear(){const e=this.getActiveWorkbook();if(!e)return;const t={workbook:e,worksheet:e.getActiveSheet()};if(this.fireEvent(this.Event.SheetBeforeRangeFilterClear,t),t.cancel)throw new Error("SetSheetsFilterCriteriaCommand canceled.")}_onRangeFilterCleared(){const e=this.getActiveWorkbook();if(!e)return;const t={workbook:e,worksheet:e.getActiveSheet()};this.fireEvent(this.Event.SheetRangeFilterCleared,t)}}l.FUniver.extend(_),Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets-filter`),require(`@univerjs/sheets/facade`),require(`@univerjs/core/facade`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-filter`,`@univerjs/sheets/facade`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFilterFacade={},e.UniverCore,e.UniverSheetsFilter,e.UniverSheetsFacade,e.UniverCoreFacade))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function a(e,t){return function(n,r){t(n,r,e)}}function o(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 s=class{constructor(e,t,n,r,i){this._workbook=e,this._worksheet=t,this._filterModel=n,this._injector=r,this._commandSrv=i}getFilteredOutRows(){return Array.from(this._filterModel.filteredOutRows).sort()}getColumnFilterCriteria(e){var t;return(t=this._filterModel.getFilterColumn(e))==null?void 0:t.getColumnData()}removeColumnFilterCriteria(e){return this._commandSrv.syncExecuteCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),col:e,criteria:null}),this}setColumnFilterCriteria(e,t){return this._commandSrv.syncExecuteCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),col:e,criteria:t}),this}getRange(){let e=this._filterModel.getRange();return this._injector.createInstance(r.FRange,this._workbook,this._worksheet,e)}removeFilterCriteria(){return this._commandSrv.syncExecuteCommand(n.ClearSheetsFilterCriteriaCommand.id),this}remove(){return this._commandSrv.syncExecuteCommand(n.RemoveSheetFilterCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()})}};s=o([a(3,(0,t.Inject)(t.Injector)),a(4,t.ICommandService)],s);var c=class extends r.FRange{createFilter(){return this._getFilterModel()||!this._commandService.syncExecuteCommand(n.SetSheetFilterRangeCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range})?null:this.getFilter()}getFilter(){let e=this._getFilterModel();return e?this._injector.createInstance(s,this._workbook,this._worksheet,e):null}_getFilterModel(){return this._injector.get(n.SheetsFilterService).getFilterModel(this._workbook.getUnitId(),this._worksheet.getSheetId())}};r.FRange.extend(c);var l=class extends r.FWorksheet{getFilter(){let e=this._getFilterModel();return e?this._injector.createInstance(s,this._workbook,this._worksheet,e):null}_getFilterModel(){return this._injector.get(n.SheetsFilterService).getFilterModel(this._workbook.getUnitId(),this._worksheet.getSheetId())}};r.FWorksheet.extend(l);var u=class{get CustomFilterOperator(){return n.CustomFilterOperator}};i.FEnum.extend(u);var d=class extends i.FEventName{get SheetBeforeRangeFilter(){return`SheetBeforeRangeFilter`}get SheetRangeFiltered(){return`SheetRangeFiltered`}get SheetRangeFilterCleared(){return`SheetRangeFilterCleared`}get SheetBeforeRangeFilterClear(){return`SheetBeforeRangeFilterClear`}};i.FEventName.extend(d),i.FEventName.extend(r.FSheetEventName);var f=class extends i.FUniver{_initialize(e){let r=e.get(t.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetBeforeRangeFilter,()=>r.beforeCommandExecuted(e=>{e.id===n.SetSheetsFilterCriteriaCommand.id&&this._beforeRangeFilter(e)}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetBeforeRangeFilterClear,()=>r.beforeCommandExecuted(e=>{e.id===n.ClearSheetsFilterCriteriaCommand.id&&this._beforeRangeFilterClear()}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetRangeFiltered,()=>r.onCommandExecuted(e=>{e.id===n.SetSheetsFilterCriteriaCommand.id&&this._onRangeFiltered(e)}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetRangeFilterCleared,()=>r.onCommandExecuted(e=>{e.id===n.ClearSheetsFilterCriteriaCommand.id&&this._onRangeFilterCleared()})))}_beforeRangeFilter(e){let t=e.params,n=this.getUniverSheet(t.unitId),r={workbook:n,worksheet:n.getSheetBySheetId(t.subUnitId),col:t.col,criteria:t.criteria};if(this.fireEvent(this.Event.SheetBeforeRangeFilter,r),r.cancel)throw Error(`SetSheetsFilterCriteriaCommand canceled.`)}_onRangeFiltered(e){let t=e.params,n=this.getUniverSheet(t.unitId),r={workbook:n,worksheet:n.getSheetBySheetId(t.subUnitId),col:t.col,criteria:t.criteria};this.fireEvent(this.Event.SheetRangeFiltered,r)}_beforeRangeFilterClear(){let e=this.getActiveWorkbook();if(!e)return;let t={workbook:e,worksheet:e.getActiveSheet()};if(this.fireEvent(this.Event.SheetBeforeRangeFilterClear,t),t.cancel)throw Error(`SetSheetsFilterCriteriaCommand canceled.`)}_onRangeFilterCleared(){let e=this.getActiveWorkbook();if(!e)return;let t={workbook:e,worksheet:e.getActiveSheet()};this.fireEvent(this.Event.SheetRangeFilterCleared,t)}};i.FUniver.extend(f),Object.defineProperty(e,`FFilter`,{enumerable:!0,get:function(){return s}})});
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(h,a){typeof exports=="object"&&typeof module<"u"?a(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"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.UniverSheetsFilter={},h.UniverCore,h.UniverSheets,h.rxjs,h.UniverEngineRender,h.UniverRpc,h.UniverEngineFormula))})(this,(function(h,a,_,I,Re,ve,J){"use strict";var et=Object.defineProperty;var tt=(h,a,_)=>a in h?et(h,a,{enumerable:!0,configurable:!0,writable:!0,value:_}):h[a]=_;var v=(h,a,_)=>tt(h,typeof a!="symbol"?a+"":a,_);var P;const K="sheet.mutation.set-filter-range",Z="sheet.mutation.set-filter-criteria",X="sheet.mutation.remove-filter",Y="sheet.mutation.re-calc-filter",H=new Set([K,Z,X,Y]);var N=(i=>(i[i.VALUES=0]="VALUES",i[i.COLORS=1]="COLORS",i[i.CONDITIONS=2]="CONDITIONS",i))(N||{}),A=(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))(A||{});const ee={operator:A.GREATER_THAN,fn:(i,n)=>U(i)?i>n:!1},te={operator:A.GREATER_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i>=n:!1},re={operator:A.LESS_THAN,fn:(i,n)=>U(i)?i<n:!1},ne={operator:A.LESS_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i<=n:!1},ie={operator:A.EQUAL,fn:(i,n)=>U(i)?i===n:!1},z={operator:A.NOT_EQUALS,fn:(i,n)=>{if(typeof n=="string"){if(n===" ")return i!=null;const e=le(i);return e&&we(n)?!a.createREGEXFromWildChar(n).test(e):e!==n}return U(i)?i!==n:!0}},se=new Map([]);[ee,te,re,ne,ie,z].forEach(i=>{se.set(i.operator,i)});function Fe(i){return!!i}const pe={fn:(i,n)=>{const e=le(i);return e===null?n==="":a.createREGEXFromWildChar(n).test(e)}};function V(i){return i?se.get(i):pe}function U(i){return typeof i=="number"}function oe(i){return!!(typeof i=="number"||typeof i=="string"&&a.isNumeric(i))}function le(i){return typeof i=="boolean"||i==null?null:typeof i=="string"?i:i.toString()}function we(i){return typeof i=="number"?!1:i.indexOf("*")!==-1||i.indexOf("?")!==-1}const W=()=>new Set;class D extends a.Disposable{constructor(e,t,r){super();v(this,"_filteredOutRows$",new I.BehaviorSubject(W()));v(this,"filteredOutRows$",this._filteredOutRows$.asObservable());v(this,"_hasCriteria$",new I.BehaviorSubject(!1));v(this,"hasCriteria$",this._hasCriteria$.asObservable());v(this,"_filterColumnByIndex",new Map);v(this,"_alreadyFilteredOutRows",W());v(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(),this._worksheet=null}serialize(){const e={ref:a.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 D(e,t,r);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.filter(r=>!(!r.filters&&!r.colorFilters&&!r.customFilters)).forEach(r=>this._setCriteriaWithoutReCalc(r.colId,r)),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 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?a.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._getAllFilterColumns().forEach(s=>s.__clearCache()),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=W(),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 ae(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)=>a.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=a.mergeSets(this._alreadyFilteredOutRows,r))}}}class ae extends a.Disposable{constructor(e,t,r,s,o){super();v(this,"_filteredOutRows",null);v(this,"_filterFn",null);v(this,"_range",null);v(this,"_column",0);v(this,"_filterBy",N.VALUES);this.unitId=e,this.subUnitId=t,this._worksheet=r,this._criteria=s,this._filterColumnContext=o}get filteredOutRows(){return this._filteredOutRows}get filterBy(){return this._filterBy}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 a.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 a.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:c,rowSpan:d,col:m}=l;if(o.has(c)&&(!d||d===1))continue;if(!(this._filterBy===N.VALUES?this._filterFn(a.extractPureTextFromCell(this._worksheet.getCell(c,m))):this._filterBy===N.COLORS?this._filterFn(this._worksheet.getComposedCellStyle(c,m)):this._filterFn(be(this._worksheet,c,m)))&&(s.add(c),d))for(let f=1;f<d;f++)s.add(c+f)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=Me(this._criteria),this._filterBy=this._criteria.filters?N.VALUES:this._criteria.colorFilters?N.COLORS:N.CONDITIONS)}}function Me(i){if(i.filters)return Ee(i.filters);if(i.colorFilters)return ye(i.colorFilters);if(i.customFilters)return Oe(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function Ee(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 ye(i){if(i.cellFillColors){const n=new Set(i.cellFillColors);return e=>{var r;if(!e||!((r=e.bg)!=null&&r.rgb))return!!n.has(null);const t=new a.ColorKit(e.bg.rgb).toRgbString();return n.has(t)}}if(i.cellTextColors){const n=new Set(i.cellTextColors);return e=>{var r;if(!e||!((r=e.cl)!=null&&r.rgb))return!!n.has(Re.COLOR_BLACK_RGB);const t=new a.ColorKit(e.cl.rgb).toRgbString();return n.has(t)}}throw new Error("[FilterModel]: color filters are not supported yet.")}function Oe(i){const n=i.customFilters.map(e=>Ne(e));return Ae(n)?i.and?Ie(n):Te(n):n[0]}function Ie(i){const[n,e]=i;return t=>n(t)&&e(t)}function Te(i){const[n,e]=i;return t=>n(t)||e(t)}function Ae(i){return i.length===2}function Ne(i){const n=i.val;if(i.operator===A.NOT_EQUALS&&!oe(n))return r=>z.fn(r,n);if(Fe(i.operator)){if(!oe(n))return()=>!1;const r=V(i.operator),s=Number(n);return o=>r.fn(o,s)}const e=V(i.operator);return t=>e.fn(t,n)}function be(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?ce(t):r?t.t===a.CellValueType.NUMBER&&typeof t.v=="string"?r.v:t.t===a.CellValueType.NUMBER?Number(r.v):ce(r):null}function ce(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===a.CellValueType.BOOLEAN?e.toUpperCase():e:typeof e=="number"?i.t===a.CellValueType.BOOLEAN?e?"TRUE":"FALSE":e:typeof e=="boolean"?e?"TRUE":"FALSE":""}var Ue=Object.getOwnPropertyDescriptor,$e=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ue(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},q=(i,n)=>(e,t)=>n(e,t,i);const k="SHEET_FILTER_PLUGIN";h.SheetsFilterService=class extends a.Disposable{constructor(e,t,r){super();v(this,"_filterModels",new Map);v(this,"_loadedUnitId$",new I.BehaviorSubject(null));v(this,"loadedUnitId$",this._loadedUnitId$.asObservable());v(this,"_errorMsg$",new I.BehaviorSubject(null));v(this,"errorMsg$",this._errorMsg$.asObservable());v(this,"_activeFilterModel$",new I.BehaviorSubject(null));v(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 D(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}setFilterErrorMsg(e){this._errorMsg$.next(e)}_updateActiveFilterModel(){let e;try{if(e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),!e){this._activeFilterModel$.next(null);return}}catch(l){console.error("[SheetsFilterService]: could not get active workbook!",l);return}const t=e.getActiveSheet(!0);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(I.merge(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([e])=>e.type===a.CommandType.MUTATION&&H.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(e=>{var t;return(t=e==null?void 0:e.activeSheet$)!=null?t:I.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=D.deserialize(e,s,r.getSheetBySheetId(s),o);this._cacheFilterModel(e,s,l)})}dispose(){super.dispose(),this._loadedUnitId$.complete(),this._errorMsg$.complete(),this._activeFilterModel$.complete(),this._filterModels.forEach(e=>{e.forEach(t=>t.dispose()),e.clear()}),this._filterModels.clear()}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:k,businesses:[a.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=>{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([q(0,a.IResourceManagerService),q(1,a.IUniverInstanceService),q(2,a.ICommandService)],h.SheetsFilterService);const F={id:K,type:a.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:Z,type:a.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,criteria:r,col:s,reCalc:o=!0}=n,c=i.get(h.SheetsFilterService).getFilterModel(t,e);return c?(c.setCriteria(s,r,o),!0):!1}},T={id:X,type:a.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(h.SheetsFilterService).removeFilterModel(e,t)}},$={id:Y,type:a.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}},de={id:"sheet.command.set-filter-range",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUndoRedoService),s=i.get(a.IUniverInstanceService),{unitId:o,subUnitId:l,range:c}=n;if(!_.getSheetCommandTarget(s,n)||e.getFilterModel(o,l))return!1;if(c.endRow===c.startRow){const S=i.get(a.ErrorService),R=i.get(a.LocaleService);return S.emit(R.t("sheets-filter.command.not-valid-filter-range")),!1}const u={id:F.id,params:{unitId:o,subUnitId:l,range:c}},f=t.syncExecuteCommand(u.id,u.params);return f&&r.pushUndoRedo({unitID:o,undoMutations:[{id:T.id,params:{unitId:o,subUnitId:l}}],redoMutations:[u]}),f}},ue={id:"sheet.command.remove-sheet-filter",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(a.IUniverInstanceService),t=i.get(h.SheetsFilterService),r=i.get(a.ICommandService),s=i.get(a.IUndoRedoService),o=_.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:c}=o,d=t.getFilterModel(l,c);if(!d)return!1;const m=d==null?void 0:d.serialize(),u=je(l,c,m),f=r.syncExecuteCommand(T.id,{unitId:l,subUnitId:c});return f&&s.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:[{id:T.id,params:{unitId:l,subUnitId:c}}]}),f}},Le={id:"sheet.command.smart-toggle-filter",type:a.CommandType.COMMAND,handler:async i=>{const n=i.get(a.IUniverInstanceService),e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=r==null?void 0:r.getActiveSheet();if(!s||!r)return!1;const o=r.getUnitId(),l=s.getSheetId();if(e.getFilterModel(o,l))return t.executeCommand(ue.id,{unitId:o,subUnitId:l});const m=i.get(_.SheetsSelectionsService).getCurrentLastSelection();if(!m)return!1;const u=m.range,f=_.isSingleCellSelection(m)?_.expandToContinuousRange(u,{left:!0,right:!0,up:!0,down:!0},s):u.startRow===u.endRow?_.expandToContinuousRange(u,{down:!0},s):u;return t.executeCommand(de.id,{unitId:o,subUnitId:l,range:f})}},Pe={id:"sheet.command.set-filter-criteria",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUndoRedoService),{unitId:s,subUnitId:o,col:l,criteria:c}=n,d=e.getFilterModel(s,o);if(!d)return!1;const m=d.getRange();if(!m||l<m.startColumn||l>m.endColumn)return!1;const u=d.getFilterColumn(l),f=He(s,o,l,u),S={id:p.id,params:{unitId:s,subUnitId:o,col:l,criteria:c}},R=t.syncExecuteCommand(S.id,S.params);return R&&r.pushUndoRedo({unitID:s,undoMutations:[f],redoMutations:[S]}),R}},De={id:"sheet.command.clear-filter-criteria",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.IUndoRedoService),r=i.get(a.ICommandService),s=i.get(a.IUniverInstanceService),o=_.getSheetCommandTarget(s,n);if(!o)return!1;const{unitId:l,subUnitId:c}=o,d=e.getFilterModel(o.unitId,o.subUnitId);if(!d)return!1;const m=d.serialize(),u=he(l,c,m),f=xe(l,c,m);return a.sequenceExecute(f,r).result?(t.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:f}),!0):!1}},Be={id:"sheet.command.re-calc-filter",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUniverInstanceService),s=_.getSheetCommandTarget(r,n);if(!s)return!1;const{unitId:o,subUnitId:l}=s;return e.getFilterModel(s.unitId,s.subUnitId)?t.executeCommand($.id,{unitId:o,subUnitId:l}):!1}};function je(i,n,e){const t=[],r={id:F.id,params:{unitId:i,subUnitId:n,range:e.ref}};return t.push(r),he(i,n,e).forEach(o=>t.push(o)),t}function he(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:s}};t.push(o)}),t}function xe(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:null}};t.push(o)}),t}function He(i,n,e,t){if(!t)return{id:p.id,params:{unitId:i,subUnitId:n,col:e,criteria:null}};const r=t.serialize();return{id:p.id,params:{unitId:i,subUnitId:n,col:e,criteria:r}}}const me="sheets-filter.config",fe={};function ze(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 L(i){return ze(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 Ve=Object.getOwnPropertyDescriptor,We=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ve(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},b=(i,n)=>(e,t)=>n(e,t,i);let B=class extends a.Disposable{constructor(n,e,t,r,s,o,l){super();v(this,"_disposableCollection",new a.DisposableCollection);this._commandService=n,this._sheetInterceptorService=e,this._sheetsFilterService=t,this._univerInstanceService=r,this._refRangeService=s,this._dataSyncPrimaryController=o,this._zebraCrossingCacheController=l,this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener(),this._initErrorHandling(),this._initZebraCrossingCacheListener()}_initZebraCrossingCacheListener(){this.disposeWithMe(this._sheetsFilterService.activeFilterModel$.subscribe(n=>{n&&this.disposeWithMe(n.filteredOutRows$.subscribe(()=>{this._zebraCrossingCacheController.updateZebraCrossingCache(n.unitId,n.subUnitId)}))}))}_initCommands(){[p,F,$,T].forEach(n=>{var e;this.disposeWithMe(this._commandService.registerCommand(n)),(e=this._dataSyncPrimaryController)==null||e.registerSyncingMutations(n)})}_initInterceptors(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>this._getUpdateFilter(n)})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===_.SetWorksheetActiveOperation.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(r,t)}if(n.id===F.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(e.unitId,e.subUnitId)}})),this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe(n=>{if(n){const e=this._univerInstanceService.getUniverSheetInstance(n),t=e==null?void 0:e.getActiveSheet();t&&this._registerRefRange(n,t.getSheetId())}}))}_registerRefRange(n,e){var l;this._disposableCollection.dispose();const t=this._univerInstanceService.getUniverSheetInstance(n),r=t==null?void 0:t.getSheetBySheetId(e);if(!t||!r)return;const s=(l=this._sheetsFilterService.getFilterModel(n,e))==null?void 0:l.getRange(),o=c=>{switch(c.id){case _.InsertRowCommand.id:{const d=c.params,m=d.unitId||n,u=d.subUnitId||e;return this._handleInsertRowCommand(d,m,u)}case _.InsertColCommand.id:{const d=c.params,m=d.unitId||n,u=d.subUnitId||e;return this.handleInsertColCommand(d.range,m,u)}case _.RemoveColCommand.id:{const d=c.params;return this.handleRemoveColCommand(d.range,n,e)}case _.RemoveRowCommand.id:{const d=c.params;return this._handleRemoveRowCommand(d,n,e)}case _.EffectRefRangId.MoveColsCommandId:{const d=c.params;return this.handleMoveColsCommand({fromRange:d.fromRange,toRange:d.toRange},n,e)}case _.EffectRefRangId.MoveRowsCommandId:{const d=c.params;return this._handleMoveRowsCommand(d,n,e)}case _.MoveRangeCommand.id:{const d=c.params;return this._handleMoveRangeCommand(d,n,e)}}return{redos:[],undos:[]}};s&&this._disposableCollection.add(this._refRangeService.registerRefRange(s,o,n,e))}_getUpdateFilter(n){const{id:e}=n;switch(e){case _.RemoveSheetCommand.id:{const t=n.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case _.CopySheetCommand.id:{const t=n.params,{targetSubUnitId:r,unitId:s,subUnitId:o}=t;return!s||!o||!r?this._handleNull():this._handleCopySheetCommand(s,o,r)}}return{redos:[],undos:[]}}handleInsertColCommand(n,e,t){var g;const r=this._sheetsFilterService.getFilterModel(e,t),s=(g=r==null?void 0:r.getRange())!=null?g:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:c,endColumn:d}=n,m=d-c+1;if(d>l)return this._handleNull();const u=[],f=[],S=c,R={unitId:e,subUnitId:t,range:{...s,startColumn:c<=o?o+m:o,endColumn:l+m}},w={unitId:e,subUnitId:t,range:s};u.push({id:F.id,params:R}),f.push({id:F.id,params:w});const M=r.getAllFilterColumns().filter(C=>C[0]>=S);if(M.length!==0){const{newRange:C,oldRange:y}=this._moveCriteria(e,t,M,m);u.push(...y.redos,...C.redos),f.push(...C.undos,...y.undos)}return{redos:L(u),undos:L(f)}}_handleInsertRowCommand(n,e,t){var w;const r=this._sheetsFilterService.getFilterModel(e,t),s=(w=r==null?void 0:r.getRange())!=null?w:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{startRow:c,endRow:d}=n.range,m=d-c+1;if(d>l)return this._handleNull();const u=[],f=[],S={unitId:e,subUnitId:t,range:{...s,startRow:c<=o?o+m:o,endRow:l+m}},R={unitId:e,subUnitId:t,range:s};return u.push({id:F.id,params:S}),f.push({id:F.id,params:R}),{redos:L(u),undos:L(f)}}handleRemoveColCommand(n,e,t){var M;const r=this._sheetsFilterService.getFilterModel(e,t),s=(M=r==null?void 0:r.getRange())!=null?M:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:c,endColumn:d}=n;if(c>l)return this._handleNull();const m=[],u=[],f=d<o?0:Math.min(d,l)-Math.max(c,o)+1,S=d-c+1,R=r.getAllFilterColumns();R.forEach(g=>{const[C,y]=g;C<=d&&C>=c&&(m.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:null}}),u.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:{...y.serialize(),colId:C}}}))});const w=R.filter(g=>{const[C,y]=g;return C>d});let E={undos:[],redos:[]};if(w.length>0){const{oldRange:g,newRange:C}=this._moveCriteria(e,t,w,-S);E=C,m.push(...g.redos),u.unshift(...g.undos)}if(f===l-o+1){const g={unitId:e,subUnitId:t};m.push({id:T.id,params:g}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}})}else{const g=o<=c?o:f===0?o-S:c,C=o<=c?l-f:l-S,y={unitId:e,subUnitId:t,range:{...s,startColumn:g,endColumn:C}};m.push({id:F.id,params:y}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),m.push(...E.redos),u.unshift(...E.undos)}return{undos:u,redos:m}}_handleRemoveRowCommand(n,e,t){var w;const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange(),{startRow:o,endRow:l}=s,{startRow:c,endRow:d}=n.range;if(c>l)return this._handleNull();if(d<o)return{undos:[{id:F.id,params:{range:s,unitId:e,subUnitId:t}}],redos:[{id:F.id,params:{range:{...s,startRow:o-(d-c+1),endRow:l-(d-c+1)},unitId:e,subUnitId:t}}]};const m=[],u=[],f=r.getAllFilterColumns(),S=o<=d&&o>=c;u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}});const R=Math.min(d,l)-Math.max(c,o)+1;if(R===l-o+1||S){const E={unitId:e,subUnitId:t};m.push({id:T.id,params:E}),f.forEach(M=>{const[g,C]=M,y={unitId:e,subUnitId:t,col:g,criteria:{...C.serialize(),colId:g}};u.push({id:p.id,params:y})})}else{const E=(w=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:w.getSheetBySheetId(t);if(!E)return this._handleNull();const M=[];for(let O=c;O<=d;O++)E.getRowFiltered(O)&&M.push(O);const g=Math.min(o,c),C=g+(l-o)-R+M.length,y={unitId:e,subUnitId:t,range:{...s,startRow:g,endRow:C}};m.push({id:F.id,params:y})}return{undos:L(u),redos:L(m)}}handleMoveColsCommand({fromRange:n,toRange:e},t,r){var M;const s=this._sheetsFilterService.getFilterModel(t,r),o=(M=s==null?void 0:s.getRange())!=null?M:null;if(!s||!o)return this._handleNull();const{startColumn:l,endColumn:c}=o;if(n.endColumn<l&&e.startColumn<=l||n.startColumn>c&&e.endColumn>c)return this._handleNull();const d=[],m=[],u={};for(let g=l;g<=c;g++)u[g]={colIndex:g,filter:s.getFilterColumn(g)};a.moveMatrixArray(n.startColumn,n.endColumn-n.startColumn+1,e.startColumn,u);let f=o.startColumn,S=o.endColumn;l>=n.startColumn&&l<=n.endColumn&&e.startColumn>n.startColumn&&n.endColumn<c&&(f=n.endColumn+1),c>=n.startColumn&&c<=n.endColumn&&e.startColumn<n.startColumn&&n.startColumn>l&&(S=n.startColumn-1);const R=Object.keys(u).map(g=>Number(g)),w=R.find(g=>u[g].colIndex===S),E=R.find(g=>u[g].colIndex===f);if(R.forEach(g=>{var _e,Se;const{colIndex:C,filter:y}=u[g],O=g;if(y){if(O>=E&&O<=w){const Q={unitId:t,subUnitId:r,col:O,criteria:{...y.serialize(),colId:O}},Ye={unitId:t,subUnitId:r,col:O,criteria:s.getFilterColumn(O)?{...(_e=s.getFilterColumn(O))==null?void 0:_e.serialize(),colId:O}:null};d.push({id:p.id,params:Q}),m.push({id:p.id,params:Ye})}if(!((Se=u[C])!=null&&Se.filter)){const Q={unitId:t,subUnitId:r,col:C,criteria:null};d.push({id:p.id,params:Q}),m.push({id:p.id,params:{unitId:t,subUnitId:r,col:C,criteria:{...y.serialize(),colId:C}}})}}}),l!==E||c!==w){const g={unitId:t,subUnitId:r,range:{...o,startColumn:E,endColumn:w}};d.unshift({id:F.id,params:g}),m.unshift({id:F.id,params:{range:o,unitId:t,subUnitId:r}})}return{undos:m,redos:d}}_handleMoveRowsCommand(n,e,t){var g;const r=this._sheetsFilterService.getFilterModel(e,t),s=(g=r==null?void 0:r.getRange())!=null?g:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{fromRange:c,toRange:d}=n;if(c.endRow<o&&d.startRow<=o||c.startRow>l&&d.endRow>l)return this._handleNull();const m=[],u=[],f={};for(let C=o;C<=l;C++)f[C]={oldIndex:C};const S=o;let R=l;l>=c.startRow&&l<=c.endRow&&d.startRow<c.startRow&&c.startRow>o&&(R=c.startRow-1),a.moveMatrixArray(c.startRow,c.endRow-c.startRow+1,d.startRow,f);const w=Object.keys(f).map(C=>Number(C)),E=w.find(C=>f[C].oldIndex===R),M=w.find(C=>f[C].oldIndex===S);if(o!==M||l!==E){const C={unitId:e,subUnitId:t,range:{...s,startRow:M,endRow:E}};m.push({id:F.id,params:C},{id:$.id,params:{unitId:e,subUnitId:t}}),u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}},{id:$.id,params:{unitId:e,subUnitId:t}})}return{redos:m,undos:u}}_handleMoveRangeCommand(n,e,t){const{fromRange:r,toRange:s}=n,o=this._sheetsFilterService.getFilterModel(e,t);if(!o)return this._handleNull();const l=o.getRange();if(!l)return this._handleNull();const c=[],d=[];if(a.Rectangle.contains(r,l)){const m=l.startRow-r.startRow,u=l.startColumn-r.startColumn,f={startRow:s.startRow+m,startColumn:s.startColumn+u,endRow:s.startRow+m+(l.endRow-l.startRow),endColumn:s.startColumn+u+(l.endColumn-l.startColumn)},S={id:T.id,params:{unitId:e,subUnitId:t}},R={id:F.id,params:{unitId:e,subUnitId:t,range:f}},w={id:F.id,params:{unitId:e,subUnitId:t,range:l}};c.push(S,R),d.push(S,w);const E=o.getAllFilterColumns(),M=s.startColumn-r.startColumn;E.forEach(g=>{const[C,y]=g;y&&(c.push({id:p.id,params:{unitId:e,subUnitId:t,col:C+M,criteria:{...y.serialize(),colId:C+M}}}),d.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:{...y.serialize(),colId:C}}}))})}else if(a.Rectangle.intersects(s,l)){const m={...l,endRow:Math.max(l.endRow,s.endRow)};c.push({id:F.id,params:{unitId:e,subUnitId:t,range:m}}),d.push({id:F.id,params:{unitId:e,subUnitId:t,range:l}})}return{redos:c,undos:d}}_handleRemoveSheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[];return r.getAllFilterColumns().forEach(([d,m])=>{l.push({id:p.id,params:{unitId:e,subUnitId:t,col:d,criteria:{...m.serialize(),colId:d}}})}),o.push({id:T.id,params:{unitId:e,subUnitId:t,range:s}}),l.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),{undos:l,redos:o}}_handleCopySheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(n,e);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[],c=[],d=[];return r.getAllFilterColumns().forEach(([u,f])=>{o.push({id:p.id,params:{unitId:n,subUnitId:t,col:u,criteria:{...f.serialize(),colId:u}}}),c.push({id:p.id,params:{unitId:n,subUnitId:t,col:u,criteria:null}})}),c.push({id:T.id,params:{unitId:n,subUnitId:t,range:s}}),o.unshift({id:F.id,params:{range:s,unitId:n,subUnitId:t}}),{undos:l,redos:o,preUndos:c,preRedos:d}}_handleNull(){return{redos:[],undos:[]}}_initRowFilteredInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(n,e)=>{var t,r;return n?!0:(r=(t=this._sheetsFilterService.getFilterModel(e.unitId,e.subUnitId))==null?void 0:t.isRowFiltered(e.row))!=null?r:!1}}))}_moveCriteria(n,e,t,r){const s={unitId:n,subUnitId:e,criteria:null,col:-1},o=[],l=[],c=[],d=[];return t.forEach(m=>{const[u,f]=m;l.push({id:p.id,params:{...s,col:u}}),o.push({id:p.id,params:{...s,col:u,criteria:{...f.serialize(),colId:u}}})}),t.forEach(m=>{const[u,f]=m;d.push({id:p.id,params:{...s,col:u+r,criteria:{...f.serialize(),colId:u+r}}}),c.push({id:p.id,params:{...s,col:u+r,criteria:null}})}),{newRange:{redos:d,undos:c},oldRange:{redos:l,undos:o}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{var d,m;const{unitId:t,subUnitId:r}=n.params||{},s=this._sheetsFilterService.getFilterModel(t,r);if(!s)return;const o=Array.from(s.filteredOutRows).sort((u,f)=>u-f),l=[];let c=!1;if(n.id===_.RemoveRowMutation.id){const{startRow:u,endRow:f}=n.params.range,S=o.filter(R=>R>=u&&R<=f);o.forEach(R=>{if(R<u)l.push(R);else if(c=!0,R<=f){const w=Math.max(u,l.length?l[l.length-1]+1:u);l.push(w)}else l.push(R-(f-u+1-S.length))})}if(n.id===_.InsertRowMutation.id){const{startRow:u,endRow:f}=n.params.range;o.forEach(S=>{S>=u?(c=!0,l.push(S+(f-u+1))):l.push(S)})}if(c&&(s.filteredOutRows=new Set(l)),n.id===_.SetRangeValuesMutation.id&&!(e!=null&&e.onlyLocal)){const u=this._getExtendRegion(t,r);if(u){const f=n.params.cellValue;if(f)for(let S=u.startColumn;S<=u.endColumn;S++){const R=(d=f==null?void 0:f[u.startRow])==null?void 0:d[S];if(R&&this._cellHasValue(R)){const w=(m=this._univerInstanceService.getUnit(t))==null?void 0:m.getSheetBySheetId(r);if(w){const E=_.expandToContinuousRange(u,{down:!0},w),M=this._sheetsFilterService.getFilterModel(t,r),g=M.getRange();M.setRange({...g,endRow:E.endRow}),this._registerRefRange(t,r)}}}}}}))}_getExtendRegion(n,e){var c;const t=this._sheetsFilterService.getFilterModel(n,e);if(!t)return null;const r=(c=this._univerInstanceService.getUnit(n))==null?void 0:c.getSheetBySheetId(e);if(!r)return null;const s=t.getRange();if(!s)return null;const o=r.getRowCount()-1,l=r.getRowManager();for(let d=s.endRow+1;d<=o;d++)if(l.getRowRawVisible(d))return{startRow:d,endRow:d,startColumn:s.startColumn,endColumn:s.endColumn};return null}_initErrorHandling(){this.disposeWithMe(this._commandService.beforeCommandExecuted(n=>{const e=n.params,t=_.getSheetCommandTarget(this._univerInstanceService,e);if(!t)return;const{subUnitId:r,unitId:s}=t,o=this._sheetsFilterService.getFilterModel(s,r);if(!o)return;const l=o.getRange();if(n.id===_.MoveRowsCommand.id&&e.fromRange.startRow<=l.startRow&&e.fromRange.endRow<l.endRow&&e.fromRange.endRow>=l.startRow)throw this._sheetsFilterService.setFilterErrorMsg("sheets-filter.msg.filter-header-forbidden"),new Error("[SheetsFilterController]: Cannot move header row of filter")}))}_cellHasValue(n){const e=Object.values(n);return!(e.length===0||e.every(t=>t==null))}};B=We([b(0,a.ICommandService),b(1,a.Inject(_.SheetInterceptorService)),b(2,a.Inject(h.SheetsFilterService)),b(3,a.IUniverInstanceService),b(4,a.Inject(_.RefRangeService)),b(5,a.Optional(ve.DataSyncPrimaryController)),b(6,a.Inject(_.ZebraCrossingCacheController))],B);var qe=Object.getOwnPropertyDescriptor,ke=(i,n,e,t)=>{for(var r=t>1?void 0:t?qe(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},G=(i,n)=>(e,t)=>n(e,t,i);const Ge=[p.id,$.id],Qe=[_.InsertColMutation.id,_.RemoveColMutation.id,_.MoveColsMutation.id];h.SheetsFilterSyncController=class extends a.Disposable{constructor(e,t,r){var o;super();v(this,"_d",new a.DisposableCollection);v(this,"_visible$",new I.BehaviorSubject(!1));v(this,"visible$",this._visible$.asObservable());v(this,"_enabled$",new I.BehaviorSubject(!0));v(this,"enabled$",this._enabled$.asObservable());this._sheetsFilterController=e,this._commandService=t,this._configService=r;const s=this._configService.getConfig(me);s!=null&&s.enableSyncSwitch&&(this._visible$.next(!0),typeof s.enableSyncSwitch=="object"&&this.setEnabled((o=s.enableSyncSwitch.defaultValue)!=null?o:!0))}get visible(){return this._visible$.getValue()}get enabled(){return this._enabled$.getValue()}setEnabled(e){this._enabled$.next(e),e?this._d.dispose():this._initOnlyLocalListener()}_initOnlyLocalListener(){this._d.add(this._commandService.beforeCommandExecuted((e,t)=>{Ge.includes(e.id)&&(t||(t={}),t.onlyLocal=!0)})),this._d.add(this._commandService.onCommandExecuted((e,t)=>{if(Qe.includes(e.id)&&(t!=null&&t.fromCollab)){if(e.id===_.InsertColMutation.id){const{range:r,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleInsertColCommand(r,s,o);a.sequenceExecute(l,this._commandService,t)}else if(e.id===_.RemoveColMutation.id){const{range:r,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleRemoveColCommand(r,s,o);a.sequenceExecute(l,this._commandService,t)}else if(e.id===_.MoveColsMutation.id){const{sourceRange:r,targetRange:s,unitId:o,subUnitId:l}=e.params,{redos:c}=this._sheetsFilterController.handleMoveColsCommand({fromRange:r,toRange:s},o,l);a.sequenceExecute(c,this._commandService,t)}}}))}},h.SheetsFilterSyncController=ke([G(0,a.Inject(B)),G(1,a.ICommandService),G(2,a.IConfigService)],h.SheetsFilterSyncController);const ge={name:"@univerjs/sheets-filter",version:"0.17.0"};var Je=Object.getOwnPropertyDescriptor,Ke=(i,n,e,t)=>{for(var r=t>1?void 0:t?Je(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},j=(i,n)=>(e,t)=>n(e,t,i);let x=class extends a.Disposable{constructor(i,n,e,t){super(),this._activeDirtyManagerService=i,this._sheetRowFilteredService=n,this._sheetsFilterService=e,this._univerInstanceService=t,this._initFormulaDirtyRange(),this._registerSheetRowFiltered()}_initFormulaDirtyRange(){H.forEach(i=>{this._activeDirtyManagerService.register(i,{commandId:i,getDirtyData:n=>{const e=n.params,{unitId:t,subUnitId:r}=e;return{dirtyRanges:this._getHideRowMutation(t,r),clearDependencyTreeCache:{[t]:{[r]:"1"}}}}})})}_getHideRowMutation(i,n){var l,c;const e=(l=this._sheetsFilterService.getFilterModel(i,n))==null?void 0:l.getRange(),t=(c=this._univerInstanceService.getUnit(i))==null?void 0:c.getSheetBySheetId(n);if(e==null||t==null)return[];const{startRow:r,endRow:s}=e;return[{unitId:i,sheetId:n,range:{startRow:r,startColumn:0,endRow:s,endColumn:t.getColumnCount()-1}}]}_registerSheetRowFiltered(){this._sheetRowFilteredService.register((i,n,e)=>{var t,r;return(r=(t=this._sheetsFilterService.getFilterModel(i,n))==null?void 0:t.isRowFiltered(e))!=null?r:!1})}};x=Ke([j(0,a.Inject(J.IActiveDirtyManagerService)),j(1,a.Inject(J.ISheetRowFilteredService)),j(2,a.Inject(h.SheetsFilterService)),j(3,a.IUniverInstanceService)],x);var Ze=Object.getOwnPropertyDescriptor,Xe=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ze(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},Ce=(i,n)=>(e,t)=>n(e,t,i);h.UniverSheetsFilterPlugin=(P=class extends a.Plugin{constructor(n=fe,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=a.merge({},fe,this._config);this._configService.setConfig(me,r)}onStarting(){[[x],[h.SheetsFilterService],[B],[h.SheetsFilterSyncController]].forEach(n=>this._injector.add(n))}onReady(){a.touchDependencies(this._injector,[[x],[B],[h.SheetsFilterSyncController]])}},v(P,"type",a.UniverInstanceType.UNIVER_SHEET),v(P,"pluginName",k),v(P,"packageName",ge.name),v(P,"version",ge.version),P),h.UniverSheetsFilterPlugin=Xe([Ce(1,a.Inject(a.Injector)),Ce(2,a.IConfigService)],h.UniverSheetsFilterPlugin),h.ClearSheetsFilterCriteriaCommand=De,h.CustomFilterOperator=A,h.FILTER_MUTATIONS=H,h.FilterBy=N,h.FilterColumn=ae,h.FilterModel=D,h.ReCalcSheetsFilterCommand=Be,h.ReCalcSheetsFilterMutation=$,h.RemoveSheetFilterCommand=ue,h.RemoveSheetsFilterMutation=T,h.SHEET_FILTER_SNAPSHOT_ID=k,h.SetSheetFilterRangeCommand=de,h.SetSheetsFilterCriteriaCommand=Pe,h.SetSheetsFilterCriteriaMutation=p,h.SetSheetsFilterRangeMutation=F,h.SmartToggleSheetsFilterCommand=Le,h.equals=ie,h.getCustomFilterFn=V,h.greaterThan=ee,h.greaterThanOrEqualTo=te,h.lessThan=re,h.lessThanOrEqualTo=ne,h.notEquals=z,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
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=e.get(t.IUniverInstanceService),a=e.get(z),o=e.get(t.ICommandService),s=e.get(t.IUndoRedoService),c=(0,n.getSheetCommandTarget)(i,r);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=a.getFilterModel(l,u);if(!d)return!1;let f=pe(l,u,d==null?void 0:d.serialize()),p=o.syncExecuteCommand(H.id,{unitId:l,subUnitId:u});return p&&s.pushUndoRedo({unitID:l,undoMutations:f,redoMutations:[{id:H.id,params:{unitId:l,subUnitId:u}}]}),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,n)=>{let r=e.get(z),i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),{unitId:o,subUnitId:s,col:c,criteria:l}=n,u=r.getFilterModel(o,s);if(!u)return!1;let d=u.getRange();if(!d||c<d.startColumn||c>d.endColumn)return!1;let f=he(o,s,c,u.getFilterColumn(c)),p={id:V.id,params:{unitId:o,subUnitId:s,col:c,criteria:l}},m=i.syncExecuteCommand(p.id,p.params);return m&&a.pushUndoRedo({unitID:o,undoMutations:[f],redoMutations:[p]}),m}},de={id:`sheet.command.clear-filter-criteria`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(z),a=e.get(t.IUndoRedoService),o=e.get(t.ICommandService),s=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!s)return!1;let{unitId:c,subUnitId:l}=s,u=i.getFilterModel(s.unitId,s.subUnitId);if(!u)return!1;let d=u.serialize(),f=K(c,l,d),p=me(c,l,d);return(0,t.sequenceExecute)(p,o).result?(a.pushUndoRedo({unitID:c,undoMutations:f,redoMutations:p}),!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.18.0`;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});