@univerjs/sheets-filter 0.24.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/lib/cjs/facade.js +16 -9
  2. package/lib/cjs/index.js +23 -10
  3. package/lib/cjs/locale/ar-SA.js +9 -0
  4. package/lib/cjs/locale/ca-ES.js +9 -0
  5. package/lib/cjs/locale/de-DE.js +9 -0
  6. package/lib/cjs/locale/en-US.js +24 -0
  7. package/lib/cjs/locale/es-ES.js +9 -0
  8. package/lib/cjs/locale/fa-IR.js +9 -0
  9. package/lib/cjs/locale/fr-FR.js +9 -0
  10. package/lib/cjs/locale/id-ID.js +9 -0
  11. package/lib/cjs/locale/it-IT.js +9 -0
  12. package/lib/cjs/locale/ja-JP.js +9 -0
  13. package/lib/cjs/locale/ko-KR.js +9 -0
  14. package/lib/cjs/locale/pl-PL.js +9 -0
  15. package/lib/cjs/locale/pt-BR.js +9 -0
  16. package/lib/cjs/locale/ru-RU.js +9 -0
  17. package/lib/cjs/locale/sk-SK.js +9 -0
  18. package/lib/cjs/locale/vi-VN.js +9 -0
  19. package/lib/cjs/locale/zh-CN.js +9 -0
  20. package/lib/cjs/locale/zh-HK.js +9 -0
  21. package/lib/cjs/locale/zh-TW.js +9 -0
  22. package/lib/es/facade.js +16 -9
  23. package/lib/es/index.js +23 -10
  24. package/lib/es/locale/ar-SA.js +8 -0
  25. package/lib/es/locale/ca-ES.js +8 -0
  26. package/lib/es/locale/de-DE.js +8 -0
  27. package/lib/es/locale/en-US.js +23 -0
  28. package/lib/es/locale/es-ES.js +8 -0
  29. package/lib/es/locale/fa-IR.js +8 -0
  30. package/lib/es/locale/fr-FR.js +8 -0
  31. package/lib/es/locale/id-ID.js +8 -0
  32. package/lib/es/locale/it-IT.js +8 -0
  33. package/lib/es/locale/ja-JP.js +8 -0
  34. package/lib/es/locale/ko-KR.js +8 -0
  35. package/lib/es/locale/pl-PL.js +8 -0
  36. package/lib/es/locale/pt-BR.js +8 -0
  37. package/lib/es/locale/ru-RU.js +8 -0
  38. package/lib/es/locale/sk-SK.js +8 -0
  39. package/lib/es/locale/vi-VN.js +8 -0
  40. package/lib/es/locale/zh-CN.js +8 -0
  41. package/lib/es/locale/zh-HK.js +8 -0
  42. package/lib/es/locale/zh-TW.js +8 -0
  43. package/lib/facade.js +16 -9
  44. package/lib/index.js +23 -10
  45. package/lib/locale/ar-SA.js +8 -0
  46. package/lib/locale/ca-ES.js +8 -0
  47. package/lib/locale/de-DE.js +8 -0
  48. package/lib/locale/en-US.js +23 -0
  49. package/lib/locale/es-ES.js +8 -0
  50. package/lib/locale/fa-IR.js +8 -0
  51. package/lib/locale/fr-FR.js +8 -0
  52. package/lib/locale/id-ID.js +8 -0
  53. package/lib/locale/it-IT.js +8 -0
  54. package/lib/locale/ja-JP.js +8 -0
  55. package/lib/locale/ko-KR.js +8 -0
  56. package/lib/locale/pl-PL.js +8 -0
  57. package/lib/locale/pt-BR.js +8 -0
  58. package/lib/locale/ru-RU.js +8 -0
  59. package/lib/locale/sk-SK.js +8 -0
  60. package/lib/locale/vi-VN.js +8 -0
  61. package/lib/locale/zh-CN.js +8 -0
  62. package/lib/locale/zh-HK.js +8 -0
  63. package/lib/locale/zh-TW.js +8 -0
  64. package/lib/types/controllers/sheets-filter.controller.d.ts +1 -0
  65. package/lib/types/facade/f-filter.d.ts +14 -7
  66. package/lib/types/facade/f-range.d.ts +4 -2
  67. package/lib/types/facade/f-worksheet.d.ts +2 -1
  68. package/lib/types/locale/ar-SA.d.ts +18 -0
  69. package/lib/types/locale/ca-ES.d.ts +18 -0
  70. package/lib/types/locale/de-DE.d.ts +18 -0
  71. package/lib/types/locale/en-US.d.ts +26 -0
  72. package/lib/types/locale/es-ES.d.ts +18 -0
  73. package/lib/types/locale/fa-IR.d.ts +18 -0
  74. package/lib/types/locale/fr-FR.d.ts +18 -0
  75. package/lib/types/locale/id-ID.d.ts +18 -0
  76. package/lib/types/locale/it-IT.d.ts +18 -0
  77. package/lib/types/locale/ja-JP.d.ts +18 -0
  78. package/lib/types/locale/ko-KR.d.ts +18 -0
  79. package/lib/types/locale/pl-PL.d.ts +18 -0
  80. package/lib/types/locale/pt-BR.d.ts +18 -0
  81. package/lib/types/locale/ru-RU.d.ts +18 -0
  82. package/lib/types/locale/sk-SK.d.ts +18 -0
  83. package/lib/types/locale/vi-VN.d.ts +18 -0
  84. package/lib/types/locale/zh-CN.d.ts +18 -0
  85. package/lib/types/locale/zh-HK.d.ts +18 -0
  86. package/lib/types/locale/zh-TW.d.ts +18 -0
  87. package/lib/umd/facade.js +1 -1
  88. package/lib/umd/index.js +1 -1
  89. package/lib/umd/locale/ar-SA.js +1 -0
  90. package/lib/umd/locale/ca-ES.js +1 -0
  91. package/lib/umd/locale/de-DE.js +1 -0
  92. package/lib/umd/locale/en-US.js +1 -0
  93. package/lib/umd/locale/es-ES.js +1 -0
  94. package/lib/umd/locale/fa-IR.js +1 -0
  95. package/lib/umd/locale/fr-FR.js +1 -0
  96. package/lib/umd/locale/id-ID.js +1 -0
  97. package/lib/umd/locale/it-IT.js +1 -0
  98. package/lib/umd/locale/ja-JP.js +1 -0
  99. package/lib/umd/locale/ko-KR.js +1 -0
  100. package/lib/umd/locale/pl-PL.js +1 -0
  101. package/lib/umd/locale/pt-BR.js +1 -0
  102. package/lib/umd/locale/ru-RU.js +1 -0
  103. package/lib/umd/locale/sk-SK.js +1 -0
  104. package/lib/umd/locale/vi-VN.js +1 -0
  105. package/lib/umd/locale/zh-CN.js +1 -0
  106. package/lib/umd/locale/zh-HK.js +1 -0
  107. package/lib/umd/locale/zh-TW.js +1 -0
  108. package/package.json +13 -8
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +1,26 @@
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
+ declare const locale: {
17
+ 'sheets-filter': {
18
+ command: {
19
+ 'not-valid-filter-range': string;
20
+ };
21
+ msg: {
22
+ 'filter-header-forbidden': string;
23
+ };
24
+ };
25
+ };
26
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
@@ -0,0 +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
+ */
16
+ import type enUS from './en-US';
17
+ declare const locale: typeof enUS;
18
+ export default locale;
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/core/facade`),require(`@univerjs/sheets-filter`),require(`@univerjs/sheets/facade`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/core/facade`,`@univerjs/sheets-filter`,`@univerjs/sheets/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFilterFacade={},e.UniverCore,e.UniverCoreFacade,e.UniverSheetsFilter,e.UniverSheetsFacade))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=class extends n.FUniver{_initialize(e){let n=e.get(t.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetBeforeRangeFilter,()=>n.beforeCommandExecuted(e=>{e.id===r.SetSheetsFilterCriteriaCommand.id&&this._beforeRangeFilter(e)}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetBeforeRangeFilterClear,()=>n.beforeCommandExecuted(e=>{e.id===r.ClearSheetsFilterCriteriaCommand.id&&this._beforeRangeFilterClear()}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetRangeFiltered,()=>n.onCommandExecuted(e=>{e.id===r.SetSheetsFilterCriteriaCommand.id&&this._onRangeFiltered(e)}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetRangeFilterCleared,()=>n.onCommandExecuted(e=>{e.id===r.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)}};n.FUniver.extend(a);function o(e,t){return function(n,r){t(n,r,e)}}function s(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 c=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(r.SetSheetsFilterCriteriaCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),col:e,criteria:null}),this}setColumnFilterCriteria(e,t){return this._commandSrv.syncExecuteCommand(r.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(i.FRange,this._workbook,this._worksheet,e)}removeFilterCriteria(){return this._commandSrv.syncExecuteCommand(r.ClearSheetsFilterCriteriaCommand.id),this}remove(){return this._commandSrv.syncExecuteCommand(r.RemoveSheetFilterCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()})}};c=s([o(3,(0,t.Inject)(t.Injector)),o(4,t.ICommandService)],c);var l=class extends i.FRange{createFilter(){return this._getFilterModel()||!this._commandService.syncExecuteCommand(r.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(c,this._workbook,this._worksheet,e):null}_getFilterModel(){return this._injector.get(r.SheetsFilterService).getFilterModel(this._workbook.getUnitId(),this._worksheet.getSheetId())}};i.FRange.extend(l);var u=class extends i.FWorksheet{getFilter(){let e=this._getFilterModel();return e?this._injector.createInstance(c,this._workbook,this._worksheet,e):null}_getFilterModel(){return this._injector.get(r.SheetsFilterService).getFilterModel(this._workbook.getUnitId(),this._worksheet.getSheetId())}};i.FWorksheet.extend(u);var d=class extends n.FEnum{get CustomFilterOperator(){return r.CustomFilterOperator}};n.FEnum.extend(d);var f=class extends n.FEventName{get SheetBeforeRangeFilter(){return`SheetBeforeRangeFilter`}get SheetRangeFiltered(){return`SheetRangeFiltered`}get SheetRangeFilterCleared(){return`SheetRangeFilterCleared`}get SheetBeforeRangeFilterClear(){return`SheetBeforeRangeFilterClear`}};n.FEventName.extend(f),Object.defineProperty(e,`FFilter`,{enumerable:!0,get:function(){return c}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/core/facade"),require("@univerjs/sheets-filter"),require("@univerjs/sheets/facade")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/core/facade`,`@univerjs/sheets-filter`,`@univerjs/sheets/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFilterFacade={},e.UniverCore,e.UniverCoreFacade,e.UniverSheetsFilter,e.UniverSheetsFacade))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=class extends n.FUniver{_initialize(e){let n=e.get(t.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetBeforeRangeFilter,()=>n.beforeCommandExecuted(e=>{e.id===r.SetSheetsFilterCriteriaCommand.id&&this._beforeRangeFilter(e)}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetBeforeRangeFilterClear,()=>n.beforeCommandExecuted(e=>{e.id===r.ClearSheetsFilterCriteriaCommand.id&&this._beforeRangeFilterClear()}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetRangeFiltered,()=>n.onCommandExecuted(e=>{e.id===r.SetSheetsFilterCriteriaCommand.id&&this._onRangeFiltered(e)}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetRangeFilterCleared,()=>n.onCommandExecuted(e=>{e.id===r.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)}};n.FUniver.extend(a);function o(e,t){return function(n,r){t(n,r,e)}}function s(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 c=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(r.SetSheetsFilterCriteriaCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),col:e,criteria:null}),this}setColumnFilterCriteria(e,t){return this._commandSrv.syncExecuteCommand(r.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(i.FRange,this._workbook,this._worksheet,e)}removeFilterCriteria(){return this._commandSrv.syncExecuteCommand(r.ClearSheetsFilterCriteriaCommand.id),this}remove(){return this._commandSrv.syncExecuteCommand(r.RemoveSheetFilterCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()})}};c=s([o(3,(0,t.Inject)(t.Injector)),o(4,t.ICommandService)],c);var l=class extends i.FRange{createFilter(){return this._getFilterModel()||!this._commandService.syncExecuteCommand(r.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(c,this._workbook,this._worksheet,e):null}_getFilterModel(){return this._injector.get(r.SheetsFilterService).getFilterModel(this._workbook.getUnitId(),this._worksheet.getSheetId())}};i.FRange.extend(l);var u=class extends i.FWorksheet{getFilter(){let e=this._getFilterModel();return e?this._injector.createInstance(c,this._workbook,this._worksheet,e):null}_getFilterModel(){return this._injector.get(r.SheetsFilterService).getFilterModel(this._workbook.getUnitId(),this._worksheet.getSheetId())}};i.FWorksheet.extend(u);var d=class extends n.FEnum{get CustomFilterOperator(){return r.CustomFilterOperator}};n.FEnum.extend(d);var f=class extends n.FEventName{get SheetBeforeRangeFilter(){return`SheetBeforeRangeFilter`}get SheetRangeFiltered(){return`SheetRangeFiltered`}get SheetRangeFilterCleared(){return`SheetRangeFilterCleared`}get SheetBeforeRangeFilterClear(){return`SheetBeforeRangeFilterClear`}};n.FEventName.extend(f),Object.defineProperty(e,"FFilter",{enumerable:!0,get:function(){return c}})});
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`rxjs`),require(`@univerjs/engine-render`),require(`@univerjs/rpc`),require(`@univerjs/engine-formula`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`rxjs`,`@univerjs/engine-render`,`@univerjs/rpc`,`@univerjs/engine-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFilter={},e.UniverCore,e.UniverSheets,e.rxjs,e.UniverEngineRender,e.UniverRpc,e.UniverEngineFormula))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let s=`sheet.mutation.set-filter-range`,c=`sheet.mutation.set-filter-criteria`,l=`sheet.mutation.remove-filter`,u=`sheet.mutation.re-calc-filter`,d=new Set([s,c,l,u]),f=function(e){return e[e.VALUES=0]=`VALUES`,e[e.COLORS=1]=`COLORS`,e[e.CONDITIONS=2]=`CONDITIONS`,e}({}),p=function(e){return e.EQUAL=`equal`,e.GREATER_THAN=`greaterThan`,e.GREATER_THAN_OR_EQUAL=`greaterThanOrEqual`,e.LESS_THAN=`lessThan`,e.LESS_THAN_OR_EQUAL=`lessThanOrEqual`,e.NOT_EQUALS=`notEqual`,e}({}),m={operator:`greaterThan`,fn:(e,t)=>C(e)?e>t:!1},h={operator:`greaterThanOrEqual`,fn:(e,t)=>C(e)?e>=t:!1},g={operator:`lessThan`,fn:(e,t)=>C(e)?e<t:!1},_={operator:`lessThanOrEqual`,fn:(e,t)=>C(e)?e<=t:!1},v={operator:`equal`,fn:(e,t)=>C(e)?e===t:!1},y={operator:`notEqual`,fn:(e,n)=>{if(typeof n==`string`){if(n===` `)return e!=null;let r=T(e);return r&&te(n)?!(0,t.createREGEXFromWildChar)(n).test(r):r!==n}return C(e)?e!==n:!0}},b=new Map([]);[m,h,g,_,v,y].forEach(e=>{b.set(e.operator,e)});function ee(e){return!!e}let x={fn:(e,n)=>{let r=T(e);return r===null?n===``:(0,t.createREGEXFromWildChar)(n).test(r)}};function S(e){return e?b.get(e):x}function C(e){return typeof e==`number`}function w(e){return!!(typeof e==`number`||typeof e==`string`&&(0,t.isNumeric)(e))}function T(e){return typeof e==`boolean`||e==null?null:typeof e==`string`?e:e.toString()}function te(e){return typeof e==`number`?!1:e.indexOf(`*`)!==-1||e.indexOf(`?`)!==-1}function E(e){"@babel/helpers - typeof";return E=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},E(e)}function ne(e,t){if(E(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(E(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function D(e){var t=ne(e,`string`);return E(t)==`symbol`?t:t+``}function O(e,t,n){return(t=D(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let k=()=>new Set;var A=class e extends t.Disposable{get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}constructor(e,t,n){super(),this.unitId=e,this.subUnitId=t,this._worksheet=n,O(this,`_filteredOutRows$`,new r.BehaviorSubject(k())),O(this,`filteredOutRows$`,this._filteredOutRows$.asObservable()),O(this,`_hasCriteria$`,new r.BehaviorSubject(!1)),O(this,`hasCriteria$`,this._hasCriteria$.asObservable()),O(this,`_filterColumnByIndex`,new Map),O(this,`_alreadyFilteredOutRows`,k()),O(this,`_range`,void 0)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete(),this._worksheet=null}serialize(){let e={ref:t.Rectangle.clone(this._range),filterColumns:this._getAllFilterColumns(!0).sort(([e],[t])=>e-t).map(([e,t])=>t.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(t,n,r,i){let a=new e(t,n,r);return a._dump(i),a}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.filter(e=>!(!e.filters&&!e.colorFilters&&!e.customFilters)).forEach(e=>this._setCriteriaWithoutReCalc(e.colId,e)),e.cachedFilteredOut?(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()):e.filterColumns&&e.filterColumns.length>0&&(this._reCalcAllColumns(),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw Error(`[FilterModel] could not get range before a range is set!`);return this._range}getFilteredOutRowsExceptCol(e){return this._getAllFilterColumns(!0).filter(([t])=>t!==e).reduce((e,[,n])=>{let r=n.calc({getAlreadyFilteredOutRows:()=>e});return r?(0,t.mergeSets)(e,r):e},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,n])=>{n.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,n=!1){if(!this._range)throw Error(`[FilterModel] could not set criteria before a range is set!`);if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),n&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),n&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))==null?null:t}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){let t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([e,t])=>t)}_reCalcAllColumns(){this._alreadyFilteredOutRows=k(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns()}_setCriteriaWithoutReCalc(e,t){let n=this._range;if(!n)throw Error(`[FilterModel] could not set criteria before a range is set!`);let{startColumn:r,endColumn:i}=n;if(e>i||e<r)throw Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);let a;this._filterColumnByIndex.has(e)?a=this._filterColumnByIndex.get(e):(a=new j(this.unitId,this.subUnitId,this._worksheet,t,{getAlreadyFilteredOutRows:()=>this._alreadyFilteredOutRows}),a.setRangeAndColumn(n,e),this._filterColumnByIndex.set(e,a)),a.setCriteria(t)}_removeCriteria(e){let t=this._filterColumnByIndex.get(e);t&&(t.dispose(),this._filterColumnByIndex.delete(e))}_emit(){this._filteredOutRows$.next(this._alreadyFilteredOutRows)}_emitHasCriteria(){this._hasCriteria$.next(this._filterColumnByIndex.size>0)}_rebuildAlreadyFilteredOutRowsWithCache(){let e=this._getAllFilterColumns().filter(e=>e.hasCache()).reduce((e,n)=>(0,t.mergeSets)(e,n.filteredOutRows),new Set);this._alreadyFilteredOutRows=e}_reCalcWithNoCacheColumns(){let e=this._getAllFilterColumns().filter(e=>!e.hasCache());for(let n of e){let e=n.reCalc();e&&(this._alreadyFilteredOutRows=(0,t.mergeSets)(this._alreadyFilteredOutRows,e))}}},j=class extends t.Disposable{get filteredOutRows(){return this._filteredOutRows}get filterBy(){return this._filterBy}constructor(e,t,n,r,i){super(),this.unitId=e,this.subUnitId=t,this._worksheet=n,this._criteria=r,this._filterColumnContext=i,O(this,`_filteredOutRows`,null),O(this,`_filterFn`,null),O(this,`_range`,null),O(this,`_column`,0),O(this,`_filterBy`,0)}dispose(){super.dispose(),this._filteredOutRows=null}__clearCache(){this._filteredOutRows=null}serialize(){if(!this._criteria)throw Error(`[FilterColumn]: could not serialize without a filter column!`);return t.Tools.deepClone({...this._criteria,colId:this._column})}hasCache(){return this._filteredOutRows!==null}setRangeAndColumn(e,t){this._range=e,this._column=t}setCriteria(e){this._criteria=e,this._generateFilterFn(),this._filteredOutRows=null}getColumnData(){return t.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw Error(`[FilterColumn] cannot calculate without a filter fn!`);if(!this._range)throw Error(`[FilterColumn] cannot calculate without a range!`);if(typeof this._column!=`number`)throw TypeError(`[FilterColumn] cannot calculate without a column offset!`);let n=this._column,r={startColumn:n,endColumn:n,startRow:this._range.startRow+1,endRow:this._range.endRow},i=new Set,a=e.getAlreadyFilteredOutRows();for(let e of this._worksheet.iterateByColumn(r,!1,!1)){let{row:n,rowSpan:r,col:o}=e;if(!(a.has(n)&&(!r||r===1))&&!(this._filterBy===0?this._filterFn((0,t.extractPureTextFromCell)(this._worksheet.getCell(n,o))):this._filterBy===1?this._filterFn(this._worksheet.getComposedCellStyle(n,o)):this._filterFn(ce(this._worksheet,n,o)))&&(i.add(n),r))for(let e=1;e<r;e++)i.add(n+e)}return i}_generateFilterFn(){this._criteria&&(this._filterFn=re(this._criteria),this._filterBy=this._criteria.filters?0:this._criteria.colorFilters?1:2)}};function re(e){if(e.filters)return ie(e.filters);if(e.colorFilters)return ae(e.colorFilters);if(e.customFilters)return oe(e.customFilters);throw Error(`[FilterModel]: other types of filters are not supported yet.`)}function ie(e){let t=!!e.blank,n=new Set(e.filters);return e=>e===void 0||e===``?t:n.has(typeof e==`string`?e:`${e}`)}function ae(e){if(e.cellFillColors){let n=new Set(e.cellFillColors);return e=>{var r;if(!e||!((r=e.bg)!=null&&r.rgb))return!!n.has(null);let i=new t.ColorKit(e.bg.rgb).toRgbString();return n.has(i)}}if(e.cellTextColors){let n=new Set(e.cellTextColors);return e=>{var r;if(!e||!((r=e.cl)!=null&&r.rgb))return!!n.has(i.COLOR_BLACK_RGB);let a=new t.ColorKit(e.cl.rgb).toRgbString();return n.has(a)}}throw Error(`[FilterModel]: color filters are not supported yet.`)}function oe(e){let t=e.customFilters.map(e=>P(e));return N(t)?e.and?se(t):M(t):t[0]}function se(e){let[t,n]=e;return e=>t(e)&&n(e)}function M(e){let[t,n]=e;return e=>t(e)||n(e)}function N(e){return e.length===2}function P(e){let t=e.val;if(e.operator===`notEqual`&&!w(t))return e=>y.fn(e,t);if(ee(e.operator)){if(!w(t))return()=>!1;let n=S(e.operator),r=Number(t);return e=>n.fn(e,r)}let n=S(e.operator);return e=>n.fn(e,t)}function ce(e,n,r){let i=e.getCell(n,r);if(!i)return null;let a=e.getCellRaw(n,r);return i&&!a?F(i):a?i.t===t.CellValueType.NUMBER&&typeof i.v==`string`?a.v:i.t===t.CellValueType.NUMBER?Number(a.v):F(a):null}function F(e){var n;let r=(n=e.p)==null||(n=n.body)==null?void 0:n.dataStream;if(r)return r.trimEnd();let i=e.v;return typeof i==`string`?e.t===t.CellValueType.BOOLEAN?i.toUpperCase():i:typeof i==`number`?e.t===t.CellValueType.BOOLEAN?i?`TRUE`:`FALSE`:i:typeof i==`boolean`?i?`TRUE`:`FALSE`:``}function I(e,t){return function(n,r){t(n,r,e)}}function L(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let R=`SHEET_FILTER_PLUGIN`,z=class extends t.Disposable{get activeFilterModel(){return this._activeFilterModel$.getValue()}constructor(e,t,n){super(),this._resourcesManagerService=e,this._univerInstanceService=t,this._commandService=n,O(this,`_filterModels`,new Map),O(this,`_loadedUnitId$`,new r.BehaviorSubject(null)),O(this,`loadedUnitId$`,this._loadedUnitId$.asObservable()),O(this,`_errorMsg$`,new r.BehaviorSubject(null)),O(this,`errorMsg$`,this._errorMsg$.asObservable()),O(this,`_activeFilterModel$`,new r.BehaviorSubject(null)),O(this,`activeFilterModel$`,this._activeFilterModel$.asObservable()),this._initModel(),this._initActiveFilterModel()}ensureFilterModel(e,t){let n=this.getFilterModel(e,t);if(n)return n;let r=this._univerInstanceService.getUniverSheetInstance(e);if(!r)throw Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${e}!`);let i=r.getSheetBySheetId(t);if(!i)throw Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${t}!`);let a=new A(e,t,i);return this._cacheFilterModel(e,t,a),a}getFilterModel(e,t){var n,r;return(n=(r=this._filterModels.get(e))==null?void 0:r.get(t))==null?null:n}removeFilterModel(e,t){let n=this.getFilterModel(e,t);return n?(n.dispose(),this._filterModels.get(e).delete(t),!0):!1}setFilterErrorMsg(e){this._errorMsg$.next(e)}_updateActiveFilterModel(){let e;try{if(e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),!e){this._activeFilterModel$.next(null);return}}catch(e){console.error(`[SheetsFilterService]: could not get active workbook!`,e);return}let n=e.getActiveSheet(!0);if(!n){this._activeFilterModel$.next(null);return}let r=n.getUnitId(),i=n.getSheetId(),a=this.getFilterModel(r,i);this._activeFilterModel$.next(a)}_initActiveFilterModel(){this.disposeWithMe((0,r.merge)((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,r.filter)(([e])=>e.type===t.CommandType.MUTATION&&d.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,r.switchMap)(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?(0,r.of)(null):t}))).subscribe(()=>this._updateActiveFilterModel()))}_serializeAutoFiltersForUnit(e){let t=this._filterModels.get(e);if(!t)return`{}`;let n={};return t.forEach((e,t)=>{n[t]=e.serialize()}),JSON.stringify(n)}_deserializeAutoFiltersForUnit(e,t){let n=this._univerInstanceService.getUniverSheetInstance(e);Object.keys(t).forEach(r=>{let i=t[r],a=A.deserialize(e,r,n.getSheetBySheetId(r),i);this._cacheFilterModel(e,r,a)})}dispose(){super.dispose(),this._loadedUnitId$.complete(),this._errorMsg$.complete(),this._activeFilterModel$.complete(),this._filterModels.forEach(e=>{e.forEach(e=>e.dispose()),e.clear()}),this._filterModels.clear()}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:R,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:e=>this._serializeAutoFiltersForUnit(e),parseJson:e=>JSON.parse(e),onLoad:(e,t)=>{this._deserializeAutoFiltersForUnit(e,t),this._loadedUnitId$.next(e),this._updateActiveFilterModel()},onUnLoad:e=>{let t=this._filterModels.get(e);t&&(t.forEach(e=>e.dispose()),this._filterModels.delete(e))}})}_cacheFilterModel(e,t,n){this._filterModels.has(e)||this._filterModels.set(e,new Map),this._filterModels.get(e).set(t,n)}};z=L([I(0,t.IResourceManagerService),I(1,t.IUniverInstanceService),I(2,t.ICommandService)],z);let B={id:s,type:t.CommandType.MUTATION,handler:(e,t)=>{let{subUnitId:n,unitId:r,range:i}=t;return e.get(z).ensureFilterModel(r,n).setRange(i),!0}},V={id:c,type:t.CommandType.MUTATION,handler:(e,t)=>{let{subUnitId:n,unitId:r,criteria:i,col:a,reCalc:o=!0}=t,s=e.get(z).getFilterModel(r,n);return s?(s.setCriteria(a,i,o),!0):!1}},H={id:l,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,subUnitId:r}=t;return e.get(z).removeFilterModel(n,r)}},U={id:u,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,subUnitId:r}=t,i=e.get(z).getFilterModel(n,r);return i?(i.reCalc(),!0):!1}},W={id:`sheet.command.set-filter-range`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(z),a=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(t.IUniverInstanceService),{unitId:c,subUnitId:l,range:u}=r;if(!(0,n.getSheetCommandTarget)(s,r)||i.getFilterModel(c,l))return!1;if(u.endRow===u.startRow){let n=e.get(t.ErrorService),r=e.get(t.LocaleService);return n.emit(r.t(`sheets-filter.command.not-valid-filter-range`)),!1}let d={id:B.id,params:{unitId:c,subUnitId:l,range:u}},f=a.syncExecuteCommand(d.id,d.params);return f&&o.pushUndoRedo({unitID:c,undoMutations:[{id:H.id,params:{unitId:c,subUnitId:l}}],redoMutations:[d]}),f}},G={id:`sheet.command.remove-sheet-filter`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(z),{unitId:o,subUnitId:s}=i,c=a.getFilterModel(o,s);if(!c)return!1;let l=c.getRange();if(!l)return!1;let u=e.get(t.ICommandService),d=e.get(t.IUndoRedoService),f=pe(o,s,c.serialize()),p=u.syncExecuteCommand(H.id,{unitId:o,subUnitId:s});return p&&(d.pushUndoRedo({unitID:o,undoMutations:f,redoMutations:[{id:H.id,params:{unitId:o,subUnitId:s}}]}),u.executeCommand(n.MarkDirtyFilterChangeMutation.id,{unitId:o,subUnitId:s,filterRange:l})),p}},le={id:`sheet.command.smart-toggle-filter`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.IUniverInstanceService),i=e.get(z),a=e.get(t.ICommandService),o=r.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),s=o==null?void 0:o.getActiveSheet();if(!s||!o)return!1;let c=o.getUnitId(),l=s.getSheetId();if(i.getFilterModel(c,l))return a.executeCommand(G.id,{unitId:c,subUnitId:l});let u=e.get(n.SheetsSelectionsService).getCurrentLastSelection();if(!u)return!1;let d=u.range,f=(0,n.isSingleCellSelection)(u)?(0,n.expandToContinuousRange)(d,{left:!0,right:!0,up:!0,down:!0},s):d.startRow===d.endRow?(0,n.expandToContinuousRange)(d,{down:!0},s):d;return a.executeCommand(W.id,{unitId:c,subUnitId:l,range:f})}},ue={id:`sheet.command.set-filter-criteria`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(z),{unitId:o,subUnitId:s}=i,c=a.getFilterModel(o,s);if(!c)return!1;let{col:l,criteria:u}=r,d=c.getRange();if(!d||l<d.startColumn||l>d.endColumn)return!1;let f=e.get(t.ICommandService),p=e.get(t.IUndoRedoService),m=he(o,s,l,c.getFilterColumn(l)),h={id:V.id,params:{unitId:o,subUnitId:s,col:l,criteria:u}},g=f.syncExecuteCommand(h.id,h.params);return g&&(p.pushUndoRedo({unitID:o,undoMutations:[m],redoMutations:[h]}),f.executeCommand(n.MarkDirtyFilterChangeMutation.id,{unitId:o,subUnitId:s,filterRange:d})),g}},de={id:`sheet.command.clear-filter-criteria`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(z),{unitId:o,subUnitId:s}=i,c=a.getFilterModel(o,s);if(!c)return!1;let l=c.getRange();if(!l)return!1;let u=e.get(t.IUndoRedoService),d=e.get(t.ICommandService),f=c.serialize(),p=K(o,s,f),m=me(o,s,f);return(0,t.sequenceExecute)(m,d).result?(u.pushUndoRedo({unitID:o,undoMutations:p,redoMutations:m}),d.executeCommand(n.MarkDirtyFilterChangeMutation.id,{unitId:o,subUnitId:s,filterRange:l}),!0):!1}},fe={id:`sheet.command.re-calc-filter`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(z),a=e.get(t.ICommandService),o=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!o)return!1;let{unitId:s,subUnitId:c}=o;return i.getFilterModel(o.unitId,o.subUnitId)?a.executeCommand(U.id,{unitId:s,subUnitId:c}):!1}};function pe(e,t,n){let r=[],i={id:B.id,params:{unitId:e,subUnitId:t,range:n.ref}};return r.push(i),K(e,t,n).forEach(e=>r.push(e)),r}function K(e,t,n){var r;let i=[];return(r=n.filterColumns)==null||r.forEach(n=>{let r={id:V.id,params:{unitId:e,subUnitId:t,col:n.colId,criteria:n}};i.push(r)}),i}function me(e,t,n){var r;let i=[];return(r=n.filterColumns)==null||r.forEach(n=>{let r={id:V.id,params:{unitId:e,subUnitId:t,col:n.colId,criteria:null}};i.push(r)}),i}function he(e,t,n,r){if(!r)return{id:V.id,params:{unitId:e,subUnitId:t,col:n,criteria:null}};let i=r.serialize();return{id:V.id,params:{unitId:e,subUnitId:t,col:n,criteria:i}}}let q=`sheets-filter.config`;Symbol(q);let J={};function ge(e,t){for(let n=0;n<e.length;n++){let r=n;if(e[n])for(let i=n+1;i<e.length;i++)e[r]&&e[i]&&t(e[r],e[i])&&(e[r]=null,r=i)}return e.filter(e=>e!==null)}function Y(e){return ge(e,(e,t)=>e.id===V.id&&t.id===V.id&&e.params.unitId===t.params.unitId&&e.params.subUnitId===t.params.subUnitId&&e.params.col===t.params.col)}let X=class extends t.Disposable{constructor(e,n,r,i,a,o,s){super(),this._commandService=e,this._sheetInterceptorService=n,this._sheetsFilterService=r,this._univerInstanceService=i,this._refRangeService=a,this._dataSyncPrimaryController=o,this._zebraCrossingCacheController=s,O(this,`_disposableCollection`,new t.DisposableCollection),this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener(),this._initErrorHandling(),this._initZebraCrossingCacheListener()}_initZebraCrossingCacheListener(){this.disposeWithMe(this._sheetsFilterService.activeFilterModel$.subscribe(e=>{e&&this.disposeWithMe(e.filteredOutRows$.subscribe(()=>{this._zebraCrossingCacheController.updateZebraCrossingCache(e.unitId,e.subUnitId)}))}))}_initCommands(){[V,B,U,H].forEach(e=>{var t;this.disposeWithMe(this._commandService.registerCommand(e)),(t=this._dataSyncPrimaryController)==null||t.registerSyncingMutations(e)})}_initInterceptors(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>this._getUpdateFilter(e)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===n.SetWorksheetActiveOperation.id){let t=e.params,n=t.subUnitId,r=t.unitId;if(!n||!r)return;this._registerRefRange(r,n)}if(e.id===B.id){let t=e.params,n=t.subUnitId,r=t.unitId;if(!n||!r)return;this._registerRefRange(t.unitId,t.subUnitId)}})),this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe(e=>{if(e){let t=this._univerInstanceService.getUniverSheetInstance(e),n=t==null?void 0:t.getActiveSheet();n&&this._registerRefRange(e,n.getSheetId())}}))}_registerRefRange(e,t){var r;this._disposableCollection.dispose();let i=this._univerInstanceService.getUniverSheetInstance(e),a=i==null?void 0:i.getSheetBySheetId(t);if(!i||!a)return;let o=(r=this._sheetsFilterService.getFilterModel(e,t))==null?void 0:r.getRange();o&&this._disposableCollection.add(this._refRangeService.registerRefRange(o,r=>{switch(r.id){case n.InsertRowCommand.id:{let n=r.params,i=n.unitId||e,a=n.subUnitId||t;return this._handleInsertRowCommand(n,i,a)}case n.InsertColCommand.id:{let n=r.params,i=n.unitId||e,a=n.subUnitId||t;return this.handleInsertColCommand(n.range,i,a)}case n.RemoveColCommand.id:{let n=r.params;return this.handleRemoveColCommand(n.range,e,t)}case n.RemoveRowCommand.id:{let n=r.params;return this._handleRemoveRowCommand(n,e,t)}case n.EffectRefRangId.MoveColsCommandId:{let n=r.params;return this.handleMoveColsCommand({fromRange:n.fromRange,toRange:n.toRange},e,t)}case n.EffectRefRangId.MoveRowsCommandId:{let n=r.params;return this._handleMoveRowsCommand(n,e,t)}case n.MoveRangeCommand.id:{let n=r.params;return this._handleMoveRangeCommand(n,e,t)}}return{redos:[],undos:[]}},e,t))}_getUpdateFilter(e){let{id:t}=e;switch(t){case n.RemoveSheetCommand.id:{let t=e.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case n.CopySheetCommand.id:{let{targetSubUnitId:t,unitId:n,subUnitId:r}=e.params;return!n||!r||!t?this._handleNull():this._handleCopySheetCommand(n,r,t)}}return{redos:[],undos:[]}}handleInsertColCommand(e,t,n){var r;let i=this._sheetsFilterService.getFilterModel(t,n),a=(r=i==null?void 0:i.getRange())==null?null:r;if(!i||!a)return this._handleNull();let{startColumn:o,endColumn:s}=a,{startColumn:c,endColumn:l}=e,u=l-c+1;if(l>s)return this._handleNull();let d=[],f=[],p=c,m={unitId:t,subUnitId:n,range:{...a,startColumn:c<=o?o+u:o,endColumn:s+u}},h={unitId:t,subUnitId:n,range:a};d.push({id:B.id,params:m}),f.push({id:B.id,params:h});let g=i.getAllFilterColumns().filter(e=>e[0]>=p);if(g.length!==0){let{newRange:e,oldRange:r}=this._moveCriteria(t,n,g,u);d.push(...r.redos,...e.redos),f.push(...e.undos,...r.undos)}return{redos:Y(d),undos:Y(f)}}_handleInsertRowCommand(e,t,n){var r;let i=this._sheetsFilterService.getFilterModel(t,n),a=(r=i==null?void 0:i.getRange())==null?null:r;if(!i||!a)return this._handleNull();let{startRow:o,endRow:s}=a,{startRow:c,endRow:l}=e.range,u=l-c+1;if(l>s)return this._handleNull();let d=[],f=[],p={unitId:t,subUnitId:n,range:{...a,startRow:c<=o?o+u:o,endRow:s+u}},m={unitId:t,subUnitId:n,range:a};return d.push({id:B.id,params:p}),f.push({id:B.id,params:m}),{redos:Y(d),undos:Y(f)}}handleRemoveColCommand(e,t,n){var r;let i=this._sheetsFilterService.getFilterModel(t,n),a=(r=i==null?void 0:i.getRange())==null?null:r;if(!i||!a)return this._handleNull();let{startColumn:o,endColumn:s}=a,{startColumn:c,endColumn:l}=e;if(c>s)return this._handleNull();let u=[],d=[],f=l<o?0:Math.min(l,s)-Math.max(c,o)+1,p=l-c+1,m=i.getAllFilterColumns();m.forEach(e=>{let[r,i]=e;r<=l&&r>=c&&(u.push({id:V.id,params:{unitId:t,subUnitId:n,col:r,criteria:null}}),d.push({id:V.id,params:{unitId:t,subUnitId:n,col:r,criteria:{...i.serialize(),colId:r}}}))});let h=m.filter(e=>{let[t,n]=e;return t>l}),g={undos:[],redos:[]};if(h.length>0){let{oldRange:e,newRange:r}=this._moveCriteria(t,n,h,-p);g=r,u.push(...e.redos),d.unshift(...e.undos)}if(f===s-o+1){let e={unitId:t,subUnitId:n};u.push({id:H.id,params:e}),d.unshift({id:B.id,params:{range:a,unitId:t,subUnitId:n}})}else{let e=o<=c?o:f===0?o-p:c,r=o<=c?s-f:s-p,i={unitId:t,subUnitId:n,range:{...a,startColumn:e,endColumn:r}};u.push({id:B.id,params:i}),d.unshift({id:B.id,params:{range:a,unitId:t,subUnitId:n}}),u.push(...g.redos),d.unshift(...g.undos)}return{undos:d,redos:u}}_handleRemoveRowCommand(e,t,n){let r=this._sheetsFilterService.getFilterModel(t,n);if(!r)return this._handleNull();let i=r.getRange(),{startRow:a,endRow:o}=i,{startRow:s,endRow:c}=e.range;if(s>o)return this._handleNull();if(c<a)return{undos:[{id:B.id,params:{range:i,unitId:t,subUnitId:n}}],redos:[{id:B.id,params:{range:{...i,startRow:a-(c-s+1),endRow:o-(c-s+1)},unitId:t,subUnitId:n}}]};let l=[],u=[],d=r.getAllFilterColumns(),f=a<=c&&a>=s;u.push({id:B.id,params:{range:i,unitId:t,subUnitId:n}});let p=Math.min(c,o)-Math.max(s,a)+1;if(p===o-a+1||f){let e={unitId:t,subUnitId:n};l.push({id:H.id,params:e}),d.forEach(e=>{let[r,i]=e,a={unitId:t,subUnitId:n,col:r,criteria:{...i.serialize(),colId:r}};u.push({id:V.id,params:a})})}else{var m;let e=(m=this._univerInstanceService.getUniverSheetInstance(t))==null?void 0:m.getSheetBySheetId(n);if(!e)return this._handleNull();let r=[];for(let t=s;t<=c;t++)e.getRowFiltered(t)&&r.push(t);let u=Math.min(a,s),d=u+(o-a)-p+r.length,f={unitId:t,subUnitId:n,range:{...i,startRow:u,endRow:d}};l.push({id:B.id,params:f})}return{undos:Y(u),redos:Y(l)}}handleMoveColsCommand({fromRange:e,toRange:n},r,i){var a;let o=this._sheetsFilterService.getFilterModel(r,i),s=(a=o==null?void 0:o.getRange())==null?null:a;if(!o||!s)return this._handleNull();let{startColumn:c,endColumn:l}=s;if(e.endColumn<c&&n.startColumn<=c||e.startColumn>l&&n.endColumn>l)return this._handleNull();let u=[],d=[],f={};for(let e=c;e<=l;e++)f[e]={colIndex:e,filter:o.getFilterColumn(e)};(0,t.moveMatrixArray)(e.startColumn,e.endColumn-e.startColumn+1,n.startColumn,f);let p=s.startColumn,m=s.endColumn;c>=e.startColumn&&c<=e.endColumn&&n.startColumn>e.startColumn&&e.endColumn<l&&(p=e.endColumn+1),l>=e.startColumn&&l<=e.endColumn&&n.startColumn<e.startColumn&&e.startColumn>c&&(m=e.startColumn-1);let h=Object.keys(f).map(e=>Number(e)),g=h.find(e=>f[e].colIndex===m),_=h.find(e=>f[e].colIndex===p);if(h.forEach(e=>{let{colIndex:t,filter:n}=f[e],a=e;if(n){var s;if(a>=_&&a<=g){var c;let e={unitId:r,subUnitId:i,col:a,criteria:{...n.serialize(),colId:a}},t={unitId:r,subUnitId:i,col:a,criteria:o.getFilterColumn(a)?{...(c=o.getFilterColumn(a))==null?void 0:c.serialize(),colId:a}:null};u.push({id:V.id,params:e}),d.push({id:V.id,params:t})}if(!((s=f[t])!=null&&s.filter)){let e={unitId:r,subUnitId:i,col:t,criteria:null};u.push({id:V.id,params:e}),d.push({id:V.id,params:{unitId:r,subUnitId:i,col:t,criteria:{...n.serialize(),colId:t}}})}}}),c!==_||l!==g){let e={unitId:r,subUnitId:i,range:{...s,startColumn:_,endColumn:g}};u.unshift({id:B.id,params:e}),d.unshift({id:B.id,params:{range:s,unitId:r,subUnitId:i}})}return{undos:d,redos:u}}_handleMoveRowsCommand(e,n,r){var i;let a=this._sheetsFilterService.getFilterModel(n,r),o=(i=a==null?void 0:a.getRange())==null?null:i;if(!a||!o)return this._handleNull();let{startRow:s,endRow:c}=o,{fromRange:l,toRange:u}=e;if(l.endRow<s&&u.startRow<=s||l.startRow>c&&u.endRow>c)return this._handleNull();let d=[],f=[],p={};for(let e=s;e<=c;e++)p[e]={oldIndex:e};let m=s,h=c;c>=l.startRow&&c<=l.endRow&&u.startRow<l.startRow&&l.startRow>s&&(h=l.startRow-1),(0,t.moveMatrixArray)(l.startRow,l.endRow-l.startRow+1,u.startRow,p);let g=Object.keys(p).map(e=>Number(e)),_=g.find(e=>p[e].oldIndex===h),v=g.find(e=>p[e].oldIndex===m);if(s!==v||c!==_){let e={unitId:n,subUnitId:r,range:{...o,startRow:v,endRow:_}};d.push({id:B.id,params:e},{id:U.id,params:{unitId:n,subUnitId:r}}),f.push({id:B.id,params:{range:o,unitId:n,subUnitId:r}},{id:U.id,params:{unitId:n,subUnitId:r}})}return{redos:d,undos:f}}_handleMoveRangeCommand(e,n,r){let{fromRange:i,toRange:a}=e,o=this._sheetsFilterService.getFilterModel(n,r);if(!o)return this._handleNull();let s=o.getRange();if(!s)return this._handleNull();let c=[],l=[];if(t.Rectangle.contains(i,s)){let e=s.startRow-i.startRow,t=s.startColumn-i.startColumn,u={startRow:a.startRow+e,startColumn:a.startColumn+t,endRow:a.startRow+e+(s.endRow-s.startRow),endColumn:a.startColumn+t+(s.endColumn-s.startColumn)},d={id:H.id,params:{unitId:n,subUnitId:r}},f={id:B.id,params:{unitId:n,subUnitId:r,range:u}},p={id:B.id,params:{unitId:n,subUnitId:r,range:s}};c.push(d,f),l.push(d,p);let m=o.getAllFilterColumns(),h=a.startColumn-i.startColumn;m.forEach(e=>{let[t,i]=e;i&&(c.push({id:V.id,params:{unitId:n,subUnitId:r,col:t+h,criteria:{...i.serialize(),colId:t+h}}}),l.push({id:V.id,params:{unitId:n,subUnitId:r,col:t,criteria:{...i.serialize(),colId:t}}}))})}else if(t.Rectangle.intersects(a,s)){let e={...s,endRow:Math.max(s.endRow,a.endRow)};c.push({id:B.id,params:{unitId:n,subUnitId:r,range:e}}),l.push({id:B.id,params:{unitId:n,subUnitId:r,range:s}})}return{redos:c,undos:l}}_handleRemoveSheetCommand(e,t,n){let r=this._sheetsFilterService.getFilterModel(t,n);if(!r)return this._handleNull();let i=r.getRange();if(!i)return this._handleNull();let a=[],o=[];return r.getAllFilterColumns().forEach(([e,r])=>{o.push({id:V.id,params:{unitId:t,subUnitId:n,col:e,criteria:{...r.serialize(),colId:e}}})}),a.push({id:H.id,params:{unitId:t,subUnitId:n,range:i}}),o.unshift({id:B.id,params:{range:i,unitId:t,subUnitId:n}}),{undos:o,redos:a}}_handleCopySheetCommand(e,t,n){let r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();let i=r.getRange();if(!i)return this._handleNull();let a=[],o=[],s=[];return r.getAllFilterColumns().forEach(([t,r])=>{a.push({id:V.id,params:{unitId:e,subUnitId:n,col:t,criteria:{...r.serialize(),colId:t}}}),s.push({id:V.id,params:{unitId:e,subUnitId:n,col:t,criteria:null}})}),s.push({id:H.id,params:{unitId:e,subUnitId:n,range:i}}),a.unshift({id:B.id,params:{range:i,unitId:e,subUnitId:n}}),{undos:o,redos:a,preUndos:s,preRedos:[]}}_handleNull(){return{redos:[],undos:[]}}_initRowFilteredInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(n.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(e,t)=>{var n,r;return e?!0:(n=(r=this._sheetsFilterService.getFilterModel(t.unitId,t.subUnitId))==null?void 0:r.isRowFiltered(t.row))==null?!1:n}}))}_moveCriteria(e,t,n,r){let i={unitId:e,subUnitId:t,criteria:null,col:-1},a=[],o=[],s=[],c=[];return n.forEach(e=>{let[t,n]=e;o.push({id:V.id,params:{...i,col:t}}),a.push({id:V.id,params:{...i,col:t,criteria:{...n.serialize(),colId:t}}})}),n.forEach(e=>{let[t,n]=e;c.push({id:V.id,params:{...i,col:t+r,criteria:{...n.serialize(),colId:t+r}}}),s.push({id:V.id,params:{...i,col:t+r,criteria:null}})}),{newRange:{redos:c,undos:s},oldRange:{redos:o,undos:a}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((e,t)=>{let{unitId:r,subUnitId:i}=e.params||{},a=this._sheetsFilterService.getFilterModel(r,i);if(!a)return;let o=Array.from(a.filteredOutRows).sort((e,t)=>e-t),s=[],c=!1;if(e.id===n.RemoveRowMutation.id){let{startRow:t,endRow:n}=e.params.range,r=o.filter(e=>e>=t&&e<=n);o.forEach(e=>{if(e<t)s.push(e);else if(c=!0,e<=n){let e=Math.max(t,s.length?s[s.length-1]+1:t);s.push(e)}else s.push(e-(n-t+1-r.length))})}if(e.id===n.InsertRowMutation.id){let{startRow:t,endRow:n}=e.params.range;o.forEach(e=>{e>=t?(c=!0,s.push(e+(n-t+1))):s.push(e)})}if(c&&(a.filteredOutRows=new Set(s)),e.id===n.SetRangeValuesMutation.id&&!(t!=null&&t.onlyLocal)){let t=this._getExtendRegion(r,i);if(t){let a=e.params.cellValue;if(a)for(let e=t.startColumn;e<=t.endColumn;e++){var l;let o=a==null||(l=a[t.startRow])==null?void 0:l[e];if(o&&this._cellHasValue(o)){var u;let e=(u=this._univerInstanceService.getUnit(r))==null?void 0:u.getSheetBySheetId(i);if(e){let a=(0,n.expandToContinuousRange)(t,{down:!0},e),o=this._sheetsFilterService.getFilterModel(r,i),s=o.getRange();o.setRange({...s,endRow:a.endRow}),this._registerRefRange(r,i)}}}}}}))}_getExtendRegion(e,t){var n;let r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return null;let i=(n=this._univerInstanceService.getUnit(e))==null?void 0:n.getSheetBySheetId(t);if(!i)return null;let a=r.getRange();if(!a)return null;let o=i.getRowCount()-1,s=i.getRowManager();for(let e=a.endRow+1;e<=o;e++)if(s.getRowRawVisible(e))return{startRow:e,endRow:e,startColumn:a.startColumn,endColumn:a.endColumn};return null}_initErrorHandling(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let t=e.params,r=(0,n.getSheetCommandTarget)(this._univerInstanceService,t);if(!r)return;let{subUnitId:i,unitId:a}=r,o=this._sheetsFilterService.getFilterModel(a,i);if(!o)return;let s=o.getRange();if(e.id===n.MoveRowsCommand.id&&t.fromRange.startRow<=s.startRow&&t.fromRange.endRow<s.endRow&&t.fromRange.endRow>=s.startRow)throw this._sheetsFilterService.setFilterErrorMsg(`sheets-filter.msg.filter-header-forbidden`),Error(`[SheetsFilterController]: Cannot move header row of filter`)}))}_cellHasValue(e){let t=Object.values(e);return!(t.length===0||t.every(e=>e==null))}};X=L([I(0,t.ICommandService),I(1,(0,t.Inject)(n.SheetInterceptorService)),I(2,(0,t.Inject)(z)),I(3,t.IUniverInstanceService),I(4,(0,t.Inject)(n.RefRangeService)),I(5,(0,t.Optional)(a.DataSyncPrimaryController)),I(6,(0,t.Inject)(n.ZebraCrossingCacheController))],X);let _e=[V.id,U.id],ve=[n.InsertColMutation.id,n.RemoveColMutation.id,n.MoveColsMutation.id],Z=class extends t.Disposable{get visible(){return this._visible$.getValue()}get enabled(){return this._enabled$.getValue()}constructor(e,n,i){super(),this._sheetsFilterController=e,this._commandService=n,this._configService=i,O(this,`_d`,new t.DisposableCollection),O(this,`_visible$`,new r.BehaviorSubject(!1)),O(this,`visible$`,this._visible$.asObservable()),O(this,`_enabled$`,new r.BehaviorSubject(!0)),O(this,`enabled$`,this._enabled$.asObservable());let a=this._configService.getConfig(q);if(a!=null&&a.enableSyncSwitch&&(this._visible$.next(!0),typeof a.enableSyncSwitch==`object`)){var o;this.setEnabled((o=a.enableSyncSwitch.defaultValue)==null?!0:o)}}setEnabled(e){this._enabled$.next(e),e?this._d.dispose():this._initOnlyLocalListener()}_initOnlyLocalListener(){this._d.add(this._commandService.beforeCommandExecuted((e,t)=>{_e.includes(e.id)&&(t||(t={}),t.onlyLocal=!0)})),this._d.add(this._commandService.onCommandExecuted((e,r)=>{if(ve.includes(e.id)&&r!=null&&r.fromCollab){if(e.id===n.InsertColMutation.id){let{range:n,unitId:i,subUnitId:a}=e.params,{redos:o}=this._sheetsFilterController.handleInsertColCommand(n,i,a);(0,t.sequenceExecute)(o,this._commandService,r)}else if(e.id===n.RemoveColMutation.id){let{range:n,unitId:i,subUnitId:a}=e.params,{redos:o}=this._sheetsFilterController.handleRemoveColCommand(n,i,a);(0,t.sequenceExecute)(o,this._commandService,r)}else if(e.id===n.MoveColsMutation.id){let{sourceRange:n,targetRange:i,unitId:a,subUnitId:o}=e.params,{redos:s}=this._sheetsFilterController.handleMoveColsCommand({fromRange:n,toRange:i},a,o);(0,t.sequenceExecute)(s,this._commandService,r)}}}))}};Z=L([I(0,(0,t.Inject)(X)),I(1,t.ICommandService),I(2,t.IConfigService)],Z);var ye=`@univerjs/sheets-filter`,be=`0.24.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});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-render"),require("@univerjs/rpc"),require("@univerjs/engine-formula")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`rxjs`,`@univerjs/engine-render`,`@univerjs/rpc`,`@univerjs/engine-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFilter={},e.UniverCore,e.UniverSheets,e.rxjs,e.UniverEngineRender,e.UniverRpc,e.UniverEngineFormula))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let s=`sheet.mutation.set-filter-range`,c=`sheet.mutation.set-filter-criteria`,l=`sheet.mutation.remove-filter`,u=`sheet.mutation.re-calc-filter`,d=new Set([s,c,l,u]),f=function(e){return e[e.VALUES=0]=`VALUES`,e[e.COLORS=1]=`COLORS`,e[e.CONDITIONS=2]=`CONDITIONS`,e}({}),p=function(e){return e.EQUAL=`equal`,e.GREATER_THAN=`greaterThan`,e.GREATER_THAN_OR_EQUAL=`greaterThanOrEqual`,e.LESS_THAN=`lessThan`,e.LESS_THAN_OR_EQUAL=`lessThanOrEqual`,e.NOT_EQUALS=`notEqual`,e}({}),m={operator:`greaterThan`,fn:(e,t)=>C(e)?e>t:!1},h={operator:`greaterThanOrEqual`,fn:(e,t)=>C(e)?e>=t:!1},g={operator:`lessThan`,fn:(e,t)=>C(e)?e<t:!1},_={operator:`lessThanOrEqual`,fn:(e,t)=>C(e)?e<=t:!1},v={operator:`equal`,fn:(e,t)=>C(e)?e===t:!1},y={operator:`notEqual`,fn:(e,n)=>{if(typeof n==`string`){if(n===` `)return e!=null;let r=T(e);return r&&te(n)?!(0,t.createREGEXFromWildChar)(n).test(r):r!==n}return C(e)?e!==n:!0}},b=new Map([]);[m,h,g,_,v,y].forEach(e=>{b.set(e.operator,e)});function ee(e){return!!e}let x={fn:(e,n)=>{let r=T(e);return r===null?n===``:(0,t.createREGEXFromWildChar)(n).test(r)}};function S(e){return e?b.get(e):x}function C(e){return typeof e==`number`}function w(e){return!!(typeof e==`number`||typeof e==`string`&&(0,t.isNumeric)(e))}function T(e){return typeof e==`boolean`||e==null?null:typeof e==`string`?e:e.toString()}function te(e){return typeof e==`number`?!1:e.indexOf(`*`)!==-1||e.indexOf(`?`)!==-1}function E(e){"@babel/helpers - typeof";return E=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},E(e)}function ne(e,t){if(E(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(E(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function D(e){var t=ne(e,`string`);return E(t)==`symbol`?t:t+``}function O(e,t,n){return(t=D(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let k=()=>new Set;var A=class e extends t.Disposable{get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}constructor(e,t,n){super(),this.unitId=e,this.subUnitId=t,this._worksheet=n,O(this,`_filteredOutRows$`,new r.BehaviorSubject(k())),O(this,`filteredOutRows$`,this._filteredOutRows$.asObservable()),O(this,`_hasCriteria$`,new r.BehaviorSubject(!1)),O(this,`hasCriteria$`,this._hasCriteria$.asObservable()),O(this,`_filterColumnByIndex`,new Map),O(this,`_alreadyFilteredOutRows`,k()),O(this,`_range`,void 0)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete(),this._worksheet=null}serialize(){let e={ref:t.Rectangle.clone(this._range),filterColumns:this._getAllFilterColumns(!0).sort(([e],[t])=>e-t).map(([e,t])=>t.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(t,n,r,i){let a=new e(t,n,r);return a._dump(i),a}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.filter(e=>!(!e.filters&&!e.colorFilters&&!e.customFilters)).forEach(e=>this._setCriteriaWithoutReCalc(e.colId,e)),e.cachedFilteredOut?(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()):e.filterColumns&&e.filterColumns.length>0&&(this._reCalcAllColumns(),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw Error(`[FilterModel] could not get range before a range is set!`);return this._range}getFilteredOutRowsExceptCol(e){return this._getAllFilterColumns(!0).filter(([t])=>t!==e).reduce((e,[,n])=>{let r=n.calc({getAlreadyFilteredOutRows:()=>e});return r?(0,t.mergeSets)(e,r):e},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,n])=>{n.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,n=!1){if(!this._range)throw Error(`[FilterModel] could not set criteria before a range is set!`);if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),n&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),n&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))==null?null:t}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){let t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([e,t])=>t)}_reCalcAllColumns(){this._alreadyFilteredOutRows=k(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns()}_setCriteriaWithoutReCalc(e,t){let n=this._range;if(!n)throw Error(`[FilterModel] could not set criteria before a range is set!`);let{startColumn:r,endColumn:i}=n;if(e>i||e<r)throw Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);let a;this._filterColumnByIndex.has(e)?a=this._filterColumnByIndex.get(e):(a=new j(this.unitId,this.subUnitId,this._worksheet,t,{getAlreadyFilteredOutRows:()=>this._alreadyFilteredOutRows}),a.setRangeAndColumn(n,e),this._filterColumnByIndex.set(e,a)),a.setCriteria(t)}_removeCriteria(e){let t=this._filterColumnByIndex.get(e);t&&(t.dispose(),this._filterColumnByIndex.delete(e))}_emit(){this._filteredOutRows$.next(this._alreadyFilteredOutRows)}_emitHasCriteria(){this._hasCriteria$.next(this._filterColumnByIndex.size>0)}_rebuildAlreadyFilteredOutRowsWithCache(){let e=this._getAllFilterColumns().filter(e=>e.hasCache()).reduce((e,n)=>(0,t.mergeSets)(e,n.filteredOutRows),new Set);this._alreadyFilteredOutRows=e}_reCalcWithNoCacheColumns(){let e=this._getAllFilterColumns().filter(e=>!e.hasCache());for(let n of e){let e=n.reCalc();e&&(this._alreadyFilteredOutRows=(0,t.mergeSets)(this._alreadyFilteredOutRows,e))}}},j=class extends t.Disposable{get filteredOutRows(){return this._filteredOutRows}get filterBy(){return this._filterBy}constructor(e,t,n,r,i){super(),this.unitId=e,this.subUnitId=t,this._worksheet=n,this._criteria=r,this._filterColumnContext=i,O(this,`_filteredOutRows`,null),O(this,`_filterFn`,null),O(this,`_range`,null),O(this,`_column`,0),O(this,`_filterBy`,0)}dispose(){super.dispose(),this._filteredOutRows=null}__clearCache(){this._filteredOutRows=null}serialize(){if(!this._criteria)throw Error(`[FilterColumn]: could not serialize without a filter column!`);return t.Tools.deepClone({...this._criteria,colId:this._column})}hasCache(){return this._filteredOutRows!==null}setRangeAndColumn(e,t){this._range=e,this._column=t}setCriteria(e){this._criteria=e,this._generateFilterFn(),this._filteredOutRows=null}getColumnData(){return t.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw Error(`[FilterColumn] cannot calculate without a filter fn!`);if(!this._range)throw Error(`[FilterColumn] cannot calculate without a range!`);if(typeof this._column!=`number`)throw TypeError(`[FilterColumn] cannot calculate without a column offset!`);let n=this._column,r={startColumn:n,endColumn:n,startRow:this._range.startRow+1,endRow:this._range.endRow},i=new Set,a=e.getAlreadyFilteredOutRows();for(let e of this._worksheet.iterateByColumn(r,!1,!1)){let{row:n,rowSpan:r,col:o}=e;if(!(a.has(n)&&(!r||r===1))&&!(this._filterBy===0?this._filterFn((0,t.extractPureTextFromCell)(this._worksheet.getCell(n,o))):this._filterBy===1?this._filterFn(this._worksheet.getComposedCellStyle(n,o)):this._filterFn(de(this._worksheet,n,o)))&&(i.add(n),r))for(let e=1;e<r;e++)i.add(n+e)}return i}_generateFilterFn(){this._criteria&&(this._filterFn=re(this._criteria),this._filterBy=this._criteria.filters?0:this._criteria.colorFilters?1:2)}};function re(e){if(e.filters)return ie(e.filters);if(e.colorFilters)return ae(e.colorFilters);if(e.customFilters)return oe(e.customFilters);throw Error(`[FilterModel]: other types of filters are not supported yet.`)}function ie(e){let t=!!e.blank,n=new Set(e.filters);return e=>e===void 0||e===``?t:n.has(typeof e==`string`?e:`${e}`)}function ae(e){if(e.cellFillColors){let n=new Set(e.cellFillColors);return e=>{var r;if(!e||!((r=e.bg)!=null&&r.rgb))return!!n.has(null);let i=new t.ColorKit(e.bg.rgb).toRgbString();return n.has(i)}}if(e.cellTextColors){let n=new Set(e.cellTextColors);return e=>{var r;if(!e||!((r=e.cl)!=null&&r.rgb))return!!n.has(i.COLOR_BLACK_RGB);let a=new t.ColorKit(e.cl.rgb).toRgbString();return n.has(a)}}throw Error(`[FilterModel]: color filters are not supported yet.`)}function oe(e){let t=e.customFilters.map(e=>ue(e));return le(t)?e.and?se(t):ce(t):t[0]}function se(e){let[t,n]=e;return e=>t(e)&&n(e)}function ce(e){let[t,n]=e;return e=>t(e)||n(e)}function le(e){return e.length===2}function ue(e){let t=e.val;if(e.operator===`notEqual`&&!w(t))return e=>y.fn(e,t);if(ee(e.operator)){if(!w(t))return()=>!1;let n=S(e.operator),r=Number(t);return e=>n.fn(e,r)}let n=S(e.operator);return e=>n.fn(e,t)}function de(e,n,r){let i=e.getCell(n,r);if(!i)return null;let a=e.getCellRaw(n,r);return i&&!a?M(i):a?i.t===t.CellValueType.NUMBER&&typeof i.v==`string`?a.v:i.t===t.CellValueType.NUMBER?Number(a.v):M(a):null}function M(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 N(e,t){return function(n,r){t(n,r,e)}}function P(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 F=`SHEET_FILTER_PLUGIN`,I=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.getCurrentUnitOfType(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:F,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)}};I=P([N(0,t.IResourceManagerService),N(1,t.IUniverInstanceService),N(2,t.ICommandService)],I);let L={id:s,type:t.CommandType.MUTATION,handler:(e,t)=>{let{subUnitId:n,unitId:r,range:i}=t;return e.get(I).ensureFilterModel(r,n).setRange(i),!0}},R={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(I).getFilterModel(r,n);return s?(s.setCriteria(a,i,o),!0):!1}},z={id:l,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,subUnitId:r}=t;return e.get(I).removeFilterModel(n,r)}},B={id:u,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,subUnitId:r}=t,i=e.get(I).getFilterModel(n,r);return i?(i.reCalc(),!0):!1}},V={id:`sheet.command.set-filter-range`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(I),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:L.id,params:{unitId:c,subUnitId:l,range:u}},f=a.syncExecuteCommand(d.id,d.params);return f&&o.pushUndoRedo({unitID:c,undoMutations:[{id:z.id,params:{unitId:c,subUnitId:l}}],redoMutations:[d]}),f}},H={id:`sheet.command.remove-sheet-filter`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(I),{unitId:o,subUnitId:s}=i,c=a.getFilterModel(o,s);if(!c)return!1;let l=c.getRange();if(!l)return!1;let u=e.get(t.ICommandService),d=e.get(t.IUndoRedoService),f=pe(o,s,c.serialize()),p=u.syncExecuteCommand(z.id,{unitId:o,subUnitId:s});return p&&(d.pushUndoRedo({unitID:o,undoMutations:f,redoMutations:[{id:z.id,params:{unitId:o,subUnitId:s}}]}),u.executeCommand(n.MarkDirtyFilterChangeMutation.id,{unitId:o,subUnitId:s,filterRange:l})),p}},fe={id:`sheet.command.smart-toggle-filter`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.IUniverInstanceService),i=e.get(I),a=e.get(t.ICommandService),o=r.getCurrentUnitOfType(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(H.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(V.id,{unitId:c,subUnitId:l,range:f})}},U={id:`sheet.command.set-filter-criteria`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(I),{unitId:o,subUnitId:s}=i,c=a.getFilterModel(o,s);if(!c)return!1;let{col:l,criteria:u}=r,d=c.getRange();if(!d||l<d.startColumn||l>d.endColumn)return!1;let f=e.get(t.ICommandService),p=e.get(t.IUndoRedoService),m=he(o,s,l,c.getFilterColumn(l)),h={id:R.id,params:{unitId:o,subUnitId:s,col:l,criteria:u}},g=f.syncExecuteCommand(h.id,h.params);return g&&(p.pushUndoRedo({unitID:o,undoMutations:[m],redoMutations:[h]}),f.executeCommand(n.MarkDirtyFilterChangeMutation.id,{unitId:o,subUnitId:s,filterRange:d})),g}},W={id:`sheet.command.clear-filter-criteria`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(I),{unitId:o,subUnitId:s}=i,c=a.getFilterModel(o,s);if(!c)return!1;let l=c.getRange();if(!l)return!1;let u=e.get(t.IUndoRedoService),d=e.get(t.ICommandService),f=c.serialize(),p=K(o,s,f),m=me(o,s,f);return(0,t.sequenceExecute)(m,d).result?(u.pushUndoRedo({unitID:o,undoMutations:p,redoMutations:m}),d.executeCommand(n.MarkDirtyFilterChangeMutation.id,{unitId:o,subUnitId:s,filterRange:l}),!0):!1}},G={id:`sheet.command.re-calc-filter`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(I),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(B.id,{unitId:s,subUnitId:c}):!1}};function pe(e,t,n){let r=[],i={id:L.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:R.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:R.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:R.id,params:{unitId:e,subUnitId:t,col:n,criteria:null}};let i=r.serialize();return{id:R.id,params:{unitId:e,subUnitId:t,col:n,criteria:i}}}let q=`sheets-filter.config`,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===R.id&&t.id===R.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,H,U,W,G].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))}),[R,L,B,z].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===L.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:L.id,params:m}),f.push({id:L.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:L.id,params:p}),f.push({id:L.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:R.id,params:{unitId:t,subUnitId:n,col:r,criteria:null}}),d.push({id:R.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:z.id,params:e}),d.unshift({id:L.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:L.id,params:i}),d.unshift({id:L.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:L.id,params:{range:i,unitId:t,subUnitId:n}}],redos:[{id:L.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:L.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:z.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:R.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=this._getFilteredRowCount(e,s,c),u=Math.min(a,s),d=u+(o-a)-p+r,f={unitId:t,subUnitId:n,range:{...i,startRow:u,endRow:d}};l.push({id:L.id,params:f})}return{undos:Y(u),redos:Y(l)}}_getFilteredRowCount(e,t,n){let r=0;for(let i=t;i<=n;i++)e.getRowFiltered(i)&&r++;return r}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:R.id,params:e}),d.push({id:R.id,params:t})}if(!((s=f[t])!=null&&s.filter)){let e={unitId:r,subUnitId:i,col:t,criteria:null};u.push({id:R.id,params:e}),d.push({id:R.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:L.id,params:e}),d.unshift({id:L.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:L.id,params:e},{id:B.id,params:{unitId:n,subUnitId:r}}),f.push({id:L.id,params:{range:o,unitId:n,subUnitId:r}},{id:B.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:z.id,params:{unitId:n,subUnitId:r}},f={id:L.id,params:{unitId:n,subUnitId:r,range:u}},p={id:L.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:R.id,params:{unitId:n,subUnitId:r,col:t+h,criteria:{...i.serialize(),colId:t+h}}}),l.push({id:R.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:L.id,params:{unitId:n,subUnitId:r,range:e}}),l.push({id:L.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:R.id,params:{unitId:t,subUnitId:n,col:e,criteria:{...r.serialize(),colId:e}}})}),a.push({id:z.id,params:{unitId:t,subUnitId:n,range:i}}),o.unshift({id:L.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:R.id,params:{unitId:e,subUnitId:n,col:t,criteria:{...r.serialize(),colId:t}}}),s.push({id:R.id,params:{unitId:e,subUnitId:n,col:t,criteria:null}})}),s.push({id:z.id,params:{unitId:e,subUnitId:n,range:i}}),a.unshift({id:L.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:R.id,params:{...i,col:t}}),a.push({id:R.id,params:{...i,col:t,criteria:{...n.serialize(),colId:t}}})}),n.forEach(e=>{let[t,n]=e;c.push({id:R.id,params:{...i,col:t+r,criteria:{...n.serialize(),colId:t+r}}}),s.push({id:R.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=P([N(0,t.ICommandService),N(1,(0,t.Inject)(n.SheetInterceptorService)),N(2,(0,t.Inject)(I)),N(3,t.IUniverInstanceService),N(4,(0,t.Inject)(n.RefRangeService)),N(5,(0,t.Optional)(a.DataSyncPrimaryController)),N(6,(0,t.Inject)(n.ZebraCrossingCacheController))],X);let _e=[R.id,B.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=P([N(0,(0,t.Inject)(X)),N(1,t.ICommandService),N(2,t.IConfigService)],Z);var ye=`@univerjs/sheets-filter`,be=`0.25.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=P([N(0,(0,t.Inject)(o.IActiveDirtyManagerService)),N(1,(0,t.Inject)(o.ISheetRowFilteredService)),N(2,(0,t.Inject)(I)),N(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],[I],[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`,F),O($,`packageName`,ye),O($,`version`,be),$=P([N(1,(0,t.Inject)(t.Injector)),N(2,t.IConfigService)],$),e.ClearSheetsFilterCriteriaCommand=W,e.CustomFilterOperator=p,e.FILTER_MUTATIONS=d,e.FilterBy=f,e.FilterColumn=j,e.FilterModel=A,e.ReCalcSheetsFilterCommand=G,e.ReCalcSheetsFilterMutation=B,e.RemoveSheetFilterCommand=H,e.RemoveSheetsFilterMutation=z,e.SHEET_FILTER_SNAPSHOT_ID=F,e.SetSheetFilterRangeCommand=V,e.SetSheetsFilterCriteriaCommand=U,e.SetSheetsFilterCriteriaMutation=R,e.SetSheetsFilterRangeMutation=L,Object.defineProperty(e,"SheetsFilterService",{enumerable:!0,get:function(){return I}}),Object.defineProperty(e,"SheetsFilterSyncController",{enumerable:!0,get:function(){return Z}}),e.SmartToggleSheetsFilterCommand=fe,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});
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFilterArSA=t())})(this,function(){return{"sheets-filter":{command:{"not-valid-filter-range":`يحتوي النطاق المحدد على صف واحد فقط وهو غير صالح للتصفية.`},msg:{"filter-header-forbidden":`لا يمكنك نقل صف الرأس الخاص بالتصفية.`}}}});
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFilterCaES=t())})(this,function(){return{"sheets-filter":{command:{"not-valid-filter-range":`L'interval seleccionat només té una fila i no és vàlid per filtrar.`},msg:{"filter-header-forbidden":`No pots moure la fila de capçalera d'un filtre.`}}}});
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFilterDeDE=t())})(this,function(){return{"sheets-filter":{command:{"not-valid-filter-range":`Der ausgewählte Bereich hat nur eine Zeile und ist für den Filter ungültig.`},msg:{"filter-header-forbidden":`Die Kopfzeile eines Filters kann nicht verschoben werden.`}}}});
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFilterEnUS=t())})(this,function(){return{"sheets-filter":{command:{"not-valid-filter-range":`The selected range only has one row and not valid for filter.`},msg:{"filter-header-forbidden":`You can't move the header row of a filter.`}}}});
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFilterEsES=t())})(this,function(){return{"sheets-filter":{command:{"not-valid-filter-range":`El rango seleccionado solo tiene una fila y no es válido para filtrar.`},msg:{"filter-header-forbidden":`No puedes mover la fila de encabezado de un filtro.`}}}});
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFilterFaIR=t())})(this,function(){return{"sheets-filter":{command:{"not-valid-filter-range":`محدوده انتخاب شده فقط یک ردیف دارد و برای فیلتر معتبر نیست.`},msg:{"filter-header-forbidden":`شما نمی‌توانید ردیف هدر یک فیلتر را جابه‌جا کنید.`}}}});
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFilterFrFR=t())})(this,function(){return{"sheets-filter":{command:{"not-valid-filter-range":`La plage sélectionnée n'a qu'une seule ligne et n'est pas valide pour le filtre.`},msg:{"filter-header-forbidden":`Vous ne pouvez pas déplacer la ligne d'en-tête d'un filtre.`}}}});
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFilterIdID=t())})(this,function(){return{"sheets-filter":{command:{"not-valid-filter-range":`Rentang yang dipilih hanya memiliki satu baris dan tidak valid untuk filter.`},msg:{"filter-header-forbidden":`Anda tidak dapat memindahkan baris header filter.`}}}});