@univerjs/sheets-filter-ui 0.20.1 → 0.21.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 (41) hide show
  1. package/lib/cjs/index.js +2749 -2
  2. package/lib/cjs/locale/ca-ES.js +79 -1
  3. package/lib/cjs/locale/en-US.js +94 -1
  4. package/lib/cjs/locale/es-ES.js +79 -1
  5. package/lib/cjs/locale/fa-IR.js +79 -1
  6. package/lib/cjs/locale/fr-FR.js +79 -1
  7. package/lib/cjs/locale/ja-JP.js +79 -1
  8. package/lib/cjs/locale/ko-KR.js +79 -1
  9. package/lib/cjs/locale/ru-RU.js +79 -1
  10. package/lib/cjs/locale/sk-SK.js +79 -1
  11. package/lib/cjs/locale/vi-VN.js +79 -1
  12. package/lib/cjs/locale/zh-CN.js +79 -1
  13. package/lib/cjs/locale/zh-TW.js +79 -1
  14. package/lib/es/index.js +2728 -2
  15. package/lib/es/locale/ca-ES.js +78 -1
  16. package/lib/es/locale/en-US.js +93 -1
  17. package/lib/es/locale/es-ES.js +78 -1
  18. package/lib/es/locale/fa-IR.js +78 -1
  19. package/lib/es/locale/fr-FR.js +78 -1
  20. package/lib/es/locale/ja-JP.js +78 -1
  21. package/lib/es/locale/ko-KR.js +78 -1
  22. package/lib/es/locale/ru-RU.js +78 -1
  23. package/lib/es/locale/sk-SK.js +78 -1
  24. package/lib/es/locale/vi-VN.js +78 -1
  25. package/lib/es/locale/zh-CN.js +78 -1
  26. package/lib/es/locale/zh-TW.js +78 -1
  27. package/lib/index.js +2728 -2
  28. package/lib/locale/ca-ES.js +78 -1
  29. package/lib/locale/en-US.js +93 -1
  30. package/lib/locale/es-ES.js +78 -1
  31. package/lib/locale/fa-IR.js +78 -1
  32. package/lib/locale/fr-FR.js +78 -1
  33. package/lib/locale/ja-JP.js +78 -1
  34. package/lib/locale/ko-KR.js +78 -1
  35. package/lib/locale/ru-RU.js +78 -1
  36. package/lib/locale/sk-SK.js +78 -1
  37. package/lib/locale/vi-VN.js +78 -1
  38. package/lib/locale/zh-CN.js +78 -1
  39. package/lib/locale/zh-TW.js +78 -1
  40. package/lib/umd/index.js +2 -2
  41. package/package.json +13 -13
package/lib/index.js CHANGED
@@ -1,7 +1,2733 @@
1
- import{BooleanNumber as e,ColorKit as t,CommandType as n,DependentOn as r,Disposable as i,ICommandService as a,IConfigService as o,IContextService as s,ILogService as c,IUniverInstanceService as l,Inject as u,Injector as d,InterceptorEffectEnum as f,LocaleService as p,Optional as m,Plugin as h,Quantity as g,RxDisposable as _,ThemeService as v,Tools as y,UniverInstanceType as b,VerticalAlign as x,createIdentifier as S,extractPureTextFromCell as ee,fromCallback as C,merge as w,numfmt as te,registerDependencies as ne,touchDependencies as re}from"@univerjs/core";import{ClearSheetsFilterCriteriaCommand as ie,CustomFilterOperator as T,FILTER_MUTATIONS as ae,FilterBy as E,ReCalcSheetsFilterCommand as oe,ReCalcSheetsFilterMutation as se,RemoveSheetFilterCommand as ce,RemoveSheetsFilterMutation as le,SetSheetFilterRangeCommand as ue,SetSheetsFilterCriteriaCommand as D,SetSheetsFilterCriteriaMutation as de,SetSheetsFilterRangeMutation as fe,SheetsFilterService as O,SheetsFilterSyncController as pe,SmartToggleSheetsFilterCommand as me,UniverSheetsFilterPlugin as he}from"@univerjs/sheets-filter";import{IEditorBridgeService as ge,ISheetSelectionRenderService as _e,SelectionControl as ve,SetCellEditVisibleOperation as ye,SheetCanvasPopManagerService as be,SheetSkeletonManagerService as xe,SheetsRenderService as Se,SheetsUIPart as Ce,getCoordByCell as we,getCurrentRangeDisable$ as Te,getObservableWithExclusiveRange$ as Ee,whenSheetEditorFocused as De}from"@univerjs/sheets-ui";import{ComponentContainer as Oe,ComponentManager as ke,ILayoutService as Ae,IMenuManagerService as je,IMessageService as Me,IShortcutService as Ne,KeyCode as Pe,MenuItemType as Fe,MetaKeys as Ie,RibbonDataGroup as Le,getMenuHiddenObservable as Re,useComponentsOfPart as ze,useDependency as k,useObservable as A}from"@univerjs/ui";import{COLOR_BLACK_RGB as Be,IRenderManagerService as Ve,Rect as He,Shape as Ue}from"@univerjs/engine-render";import{INTERCEPTOR_POINT as We,RangeProtectionPermissionViewPoint as j,RefRangeService as Ge,SetRangeValuesMutation as Ke,SheetInterceptorService as qe,SheetPermissionCheckController as Je,SheetsSelectionsService as Ye,WorksheetFilterPermission as M,WorksheetViewPermission as N,attachSelectionWithCoord as Xe,expandToContinuousRange as Ze,getSheetCommandTarget as Qe}from"@univerjs/sheets";import{BehaviorSubject as P,ReplaySubject as $e,Subject as et,combineLatest as tt,distinctUntilChanged as nt,filter as rt,map as F,merge as it,of as I,shareReplay as at,startWith as ot,switchMap as st,takeUntil as ct,throttleTime as lt}from"rxjs";import{IRPCChannelService as ut,fromModule as dt,toModule as ft}from"@univerjs/rpc";import{Button as pt,Checkbox as mt,Input as ht,MessageType as gt,Radio as _t,RadioGroup as vt,Segmented as yt,Select as bt,Switch as xt,Tooltip as St,Tree as Ct,borderClassName as wt,clsx as Tt}from"@univerjs/design";import{AIcon as Et,BanIcon as Dt,FilterIcon as Ot,InfoIcon as kt,SuccessIcon as At}from"@univerjs/icons";import{useCallback as L,useMemo as jt}from"react";import{Fragment as Mt,jsx as R,jsxs as z}from"react/jsx-runtime";let B=function(e){return e[e.FIRST=0]=`FIRST`,e[e.SECOND=1]=`SECOND`,e}({}),V=function(e){return e.NONE=`none`,e.STARTS_WITH=`startsWith`,e.DOES_NOT_START_WITH=`doesNotStartWith`,e.ENDS_WITH=`endsWith`,e.DOES_NOT_END_WITH=`doesNotEndWith`,e.CONTAINS=`contains`,e.DOES_NOT_CONTAIN=`doesNotContain`,e.EQUALS=`equals`,e.NOT_EQUALS=`notEquals`,e.EMPTY=`empty`,e.NOT_EMPTY=`notEmpty`,e.BETWEEN=`between`,e.NOT_BETWEEN=`notBetween`,e.CUSTOM=`custom`,e}({}),H;(function(t){let n=t.NONE={label:`sheets-filter.conditions.none`,operator:V.NONE,order:B.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.NONE]: should not have initial form params!`)},testMappingParams:e=>e.operator1===V.NONE,mapToFilterColumn:()=>null,testMappingFilterColumn:e=>!e.customFilters&&!e.filters?{}:!1},r=t.ALL_CONDITIONS=[n,t.EMPTY={label:`sheets-filter.conditions.empty`,operator:V.EMPTY,order:B.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.EMPTY]: should not have initial form params!`)},testMappingParams:({operator1:e})=>e===V.EMPTY,mapToFilterColumn:()=>({customFilters:{customFilters:[{val:``}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let n=e.customFilters.customFilters[0];return n.val===``&&n.operator===void 0?{operator1:V.EMPTY}:!1}},t.NOT_EMPTY={label:`sheets-filter.conditions.not-empty`,operator:V.NOT_EMPTY,order:B.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.NOT_EMPTY]: should not have initial form params!`)},testMappingParams:({operator1:e})=>e===V.NOT_EMPTY,mapToFilterColumn:()=>({customFilters:{customFilters:[{val:``,operator:T.NOT_EQUALS}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let n=e.customFilters.customFilters[0];return n.val===` `&&n.operator===T.NOT_EQUALS?{operator1:V.NOT_EMPTY}:!1}},t.TEXT_CONTAINS={label:`sheets-filter.conditions.text-contains`,operator:V.CONTAINS,order:B.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:V.CONTAINS,val1:``}),testMappingParams:e=>{let[t]=U(e);return t===V.CONTAINS},mapToFilterColumn:e=>{let{val1:t}=e;return t===``?null:{customFilters:{customFilters:[{val:`*${t}*`}]}}},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let n=e.customFilters.customFilters[0],r=n.val.toString();return!n.operator&&r.startsWith(`*`)&&r.endsWith(`*`)?{operator1:V.CONTAINS,val1:r.slice(1,-1)}:!1}},t.DOES_NOT_CONTAIN={label:`sheets-filter.conditions.does-not-contain`,operator:V.DOES_NOT_CONTAIN,order:B.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:V.DOES_NOT_CONTAIN,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`*${e.val1}*`,operator:T.NOT_EQUALS}]}}),testMappingParams:e=>{let[t]=U(e);return t===V.DOES_NOT_CONTAIN},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let n=e.customFilters.customFilters[0],r=n.val.toString();return n.operator===T.NOT_EQUALS&&r.startsWith(`*`)&&r.endsWith(`*`)?{operator1:V.DOES_NOT_CONTAIN,val1:r.slice(1,-1)}:!1}},t.STARTS_WITH={label:`sheets-filter.conditions.starts-with`,operator:V.STARTS_WITH,order:B.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:V.STARTS_WITH,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`${e.val1}*`}]}}),testMappingParams:e=>{let[t]=U(e);return t===V.STARTS_WITH},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let n=e.customFilters.customFilters[0],r=n.val.toString();return!n.operator&&r.endsWith(`*`)&&!r.startsWith(`*`)?{operator1:V.STARTS_WITH,val1:r.slice(0,-1)}:!1}},t.ENDS_WITH={label:`sheets-filter.conditions.ends-with`,operator:V.ENDS_WITH,order:B.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:V.ENDS_WITH,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`*${e.val1}`}]}}),testMappingParams:e=>{let[t]=U(e);return t===V.ENDS_WITH},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let n=e.customFilters.customFilters[0],r=n.val.toString();return!n.operator&&r.startsWith(`*`)&&!r.endsWith(`*`)?{operator1:V.ENDS_WITH,val1:r.slice(1)}:!1}},t.EQUALS={label:`sheets-filter.conditions.equals`,operator:V.EQUALS,order:B.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:V.EQUALS,val1:``}),testMappingParams:e=>{let[t]=U(e);return t===V.EQUALS},mapToFilterColumn:e=>{let{val1:t}=e;return t===``?null:{customFilters:{customFilters:[{val:t}]}}},testMappingFilterColumn:e=>{var t,n;return((t=e.filters)==null||(t=t.filters)==null?void 0:t.length)===1?{operator1:V.EQUALS,val1:``}:((n=e.customFilters)==null?void 0:n.customFilters.length)===1&&!e.customFilters.customFilters[0].operator?{operator1:V.EQUALS,val1:e.customFilters.customFilters[0].val.toString()}:!1}},t.GREATER_THAN={label:`sheets-filter.conditions.greater-than`,operator:T.GREATER_THAN,numOfParameters:1,order:B.FIRST,getDefaultFormParams:()=>({operator1:T.GREATER_THAN,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:T.GREATER_THAN}]}}),testMappingParams:e=>{let[t]=U(e);return t===T.GREATER_THAN},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let n=e.customFilters.customFilters[0];return n.operator===T.GREATER_THAN?{operator1:T.GREATER_THAN,val1:n.val.toString()}:!1}},t.GREATER_THAN_OR_EQUAL={label:`sheets-filter.conditions.greater-than-or-equal`,operator:T.GREATER_THAN_OR_EQUAL,numOfParameters:1,order:B.FIRST,getDefaultFormParams:()=>({operator1:T.GREATER_THAN_OR_EQUAL,val1:``}),testMappingParams:e=>{let[t]=U(e);return t===T.GREATER_THAN_OR_EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:T.GREATER_THAN_OR_EQUAL}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let n=e.customFilters.customFilters[0];return n.operator===T.GREATER_THAN_OR_EQUAL?{operator1:T.GREATER_THAN_OR_EQUAL,val1:n.val.toString()}:!1}},t.LESS_THAN={label:`sheets-filter.conditions.less-than`,operator:T.LESS_THAN,numOfParameters:1,order:B.FIRST,getDefaultFormParams:()=>({operator1:T.LESS_THAN,val1:``}),testMappingParams:e=>{let[t]=U(e);return t===T.LESS_THAN},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:T.LESS_THAN}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let n=e.customFilters.customFilters[0];return n.operator===T.LESS_THAN?{operator1:T.LESS_THAN,val1:n.val.toString()}:!1}},t.LESS_THAN_OR_EQUAL={label:`sheets-filter.conditions.less-than-or-equal`,operator:T.LESS_THAN_OR_EQUAL,numOfParameters:1,order:B.FIRST,getDefaultFormParams:()=>({operator1:T.LESS_THAN_OR_EQUAL,val1:``}),testMappingParams:e=>{let[t]=U(e);return t===T.LESS_THAN_OR_EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:T.LESS_THAN_OR_EQUAL}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let n=e.customFilters.customFilters[0];return n.operator===T.LESS_THAN_OR_EQUAL?{operator1:T.LESS_THAN_OR_EQUAL,val1:n.val.toString()}:!1}},t.EQUAL={label:`sheets-filter.conditions.equal`,operator:T.EQUAL,numOfParameters:1,order:B.FIRST,getDefaultFormParams:()=>({operator1:T.EQUAL,val1:``}),testMappingParams:e=>{let[t]=U(e);return t===T.EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:T.EQUAL}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let n=e.customFilters.customFilters[0];return n.operator===T.EQUAL?{operator1:T.EQUAL,val1:n.val.toString()}:!1}},t.NOT_EQUAL={label:`sheets-filter.conditions.not-equal`,operator:T.NOT_EQUALS,numOfParameters:1,order:B.FIRST,getDefaultFormParams:()=>({operator1:T.NOT_EQUALS,val1:``}),testMappingParams:e=>{let[t]=U(e);return t===T.NOT_EQUALS},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:T.NOT_EQUALS}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let n=e.customFilters.customFilters[0];return n.operator===T.NOT_EQUALS?{operator1:T.NOT_EQUALS,val1:n.val.toString()}:!1}},t.BETWEEN={label:`sheets-filter.conditions.between`,operator:V.BETWEEN,order:B.SECOND,numOfParameters:2,getDefaultFormParams:()=>({and:!0,operator1:T.GREATER_THAN_OR_EQUAL,val1:``,operator2:T.LESS_THAN_OR_EQUAL,val2:``}),testMappingParams:e=>{let{and:t,operator1:n,operator2:r}=e;if(!t)return!1;let i=[n,r];return i.includes(T.GREATER_THAN_OR_EQUAL)&&i.includes(T.LESS_THAN_OR_EQUAL)},mapToFilterColumn:t=>{let{val1:n,val2:r,operator1:i}=t,a=i===T.GREATER_THAN_OR_EQUAL;return{customFilters:{and:e.TRUE,customFilters:[{val:a?n:r,operator:T.GREATER_THAN_OR_EQUAL},{val:a?r:n,operator:T.LESS_THAN_OR_EQUAL}]}}},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==2)return!1;let[n,r]=e.customFilters.customFilters;return n.operator===T.GREATER_THAN_OR_EQUAL&&r.operator===T.LESS_THAN_OR_EQUAL&&e.customFilters.and?{and:!0,operator1:T.GREATER_THAN_OR_EQUAL,val1:n.val.toString(),operator2:T.LESS_THAN_OR_EQUAL,val2:r.val.toString()}:r.operator===T.GREATER_THAN_OR_EQUAL&&n.operator===T.LESS_THAN_OR_EQUAL&&e.customFilters.and?{and:!0,operator1:T.GREATER_THAN_OR_EQUAL,val1:r.val.toString(),operator2:T.LESS_THAN_OR_EQUAL,val2:n.val.toLocaleString()}:!1}},t.NOT_BETWEEN={label:`sheets-filter.conditions.not-between`,operator:V.NOT_BETWEEN,order:B.SECOND,numOfParameters:2,getDefaultFormParams:()=>({operator1:T.LESS_THAN,val1:``,operator2:T.GREATER_THAN,val2:``}),testMappingParams:e=>{let{and:t,operator1:n,operator2:r}=e;if(t)return!1;let i=[n,r];return i.includes(T.GREATER_THAN)&&i.includes(T.LESS_THAN)},mapToFilterColumn:e=>{let{val1:t,val2:n,operator1:r}=e,i=r===T.GREATER_THAN;return{customFilters:{customFilters:[{val:i?t:n,operator:T.GREATER_THAN},{val:i?n:t,operator:T.LESS_THAN}]}}},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==2)return!1;let[n,r]=e.customFilters.customFilters;return n.operator===T.LESS_THAN&&r.operator===T.GREATER_THAN&&!e.customFilters.and?{operator1:T.LESS_THAN,val1:n.val.toString(),operator2:T.GREATER_THAN,val2:r.val.toString()}:r.operator===T.LESS_THAN&&n.operator===T.GREATER_THAN&&!e.customFilters.and?{operator1:T.GREATER_THAN,val1:r.val.toString(),operator2:T.LESS_THAN,val2:n.val.toLocaleString()}:!1}},t.CUSTOM={label:`sheets-filter.conditions.custom`,operator:V.CUSTOM,order:B.SECOND,numOfParameters:2,getDefaultFormParams:()=>({operator1:V.NONE,val1:``,operator2:V.NONE,val2:``}),testMappingParams:()=>!0,mapToFilterColumn:t=>{let{and:i,val1:a,val2:o,operator1:s,operator2:c}=t;function l(e,t){for(let n of r)if(n.operator===e)return n.mapToFilterColumn({val1:t,operator1:e})}let u=!s||s===H.NONE.operator,d=!c||c===H.NONE.operator;if(u&&d)return n.mapToFilterColumn({});if(u)return l(c,o);if(d)return l(s,a);let f=l(s,a),p=l(c,o),m={customFilters:[f.customFilters.customFilters[0],p.customFilters.customFilters[0]]};return i&&(m.and=e.TRUE),{customFilters:m}},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==2)return!1;let n=e.customFilters.customFilters.map(e=>c({customFilters:{customFilters:[e]}})),r={operator1:n[0][0].operator,val1:n[0][1].val1,operator2:n[1][0].operator,val2:n[1][1].val1};return e.customFilters.and&&(r.and=!0),r}}];function i(e){let t=r.find(t=>t.operator===e);if(!t)throw Error(`[SheetsFilter]: no condition item found for operator: ${e}`);return t}t.getItemByOperator=i;function a(e,t){for(let n of r.filter(e=>e.numOfParameters===t))if(n.numOfParameters!==0&&n.testMappingParams(e))return n;for(let t of r)if(t.testMappingParams(e))return t;throw Error(`[SheetsFilter]: no condition item can be mapped from the filter map params!`)}t.testMappingParams=a;function o(e){let t=r.find(t=>t.operator===e);return(t==null?void 0:t.numOfParameters)===0?{operator1:t.operator}:t.getDefaultFormParams()}t.getInitialFormParams=o;function s(e,t){return e.mapToFilterColumn(t)}t.mapToFilterColumn=s;function c(e){if(!e)return[n,{}];for(let t of r){let n=t.testMappingFilterColumn(e);if(n)return[t,n]}return[n,{}]}t.testMappingFilterColumn=c})(H||(H={}));function U(e){let{operator1:t,operator2:n,val1:r,val2:i}=e;if(t&&n)throw Error(`Both operator1 and operator2 are set!`);if(!t&&!n)throw Error(`Neither operator1 and operator2 and both not set!`);return t?[t,r]:[n,i]}function Nt(e){let t=[],n=[],r=0,i=0;function a(e){e.leaf&&(e.checked?(t.push(e),r+=e.count):(n.push(e),i+=e.count)),e.children&&e.children.forEach(a)}return e.forEach(a),{checkedItems:t,uncheckedItems:n,checked:r,unchecked:i}}function W(e,t){return function(n,r){t(n,r,e)}}function G(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}const Pt=`sheets-filter.generate-filter-values.service`,Ft=S(Pt);let It=class extends i{constructor(e,t,n){super(),this._localeService=e,this._univerInstanceService=t,this._logService=n}async getFilterValues(e){var t;let{unitId:n,subUnitId:r,filteredOutRowsByOtherColumns:i,filterColumn:a,filters:o,blankChecked:s,iterateRange:c,alreadyChecked:l}=e,u=this._univerInstanceService.getUnit(n),d=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);return!u||!d?[]:(this._logService.debug(`[SheetsGenerateFilterValuesService]`,`getFilterValues for`,{unitId:n,subUnitId:r}),Lt(o,this._localeService,c,d,new Set(i),a,new Set(l.map(String)),s,u.getStyles()))}};It=G([W(0,u(p)),W(1,l),W(2,c)],It);function Lt(e,t,n,r,i,a,o,s,c){var l;let u=new Map,d=new Map,f=`empty`,p=!e&&((a==null?void 0:a.filterBy)===E.COLORS||(a==null?void 0:a.filterBy)===E.CONDITIONS)&&((l=a.filteredOutRows)==null?void 0:l.size),m=0;for(let e of r.iterateByColumn(n,!1,!1)){let{row:n,rowSpan:a=1}=e,l=0;for(;l<a;){var h,g,_;let f=n+l;if(i.has(f)){l++;continue}let C=e!=null&&e.value?ee(e.value):``;if(!C){m+=1,l+=a;continue}let w=(h=e.value)!=null&&h.v&&!e.value.p?(g=c.get((_=e.value)==null?void 0:_.s))==null||(g=g.n)==null?void 0:g.pattern:``,ne=w&&te.getFormatInfo(w).isDate,re=!1;if(ne){let{year:e,month:t,day:n}=te.getFormatDateInfo(w);re=e||t||n}if(w&&ne&&re){var v,y,b;let n=(v=r.getCellRaw(e.row,e.col))==null?void 0:v.v;if(!n){l++;continue}let[i,a,c]=te.format(`yyyy-mm-dd`,Number(n)).split(`-`).map(Number),f=u.get(`${i}`);f||(f={title:`${i}`,key:`${i}`,children:[],count:0,leaf:!1,checked:!1},u.set(`${i}`,f),d.set(`${i}`,[`${i}`]));let m=(y=f.children)==null?void 0:y.find(e=>e.key===`${i}-${a}`);if(!m){var x;m={title:t.t(`sheets-filter.date.${a}`),key:`${i}-${a}`,children:[],count:0,leaf:!1,checked:!1},(x=f.children)==null||x.push(m),d.set(`${i}-${a}`,[`${i}`,`${i}-${a}`])}let h=m==null||(b=m.children)==null?void 0:b.find(e=>e.key===`${i}-${a}-${c}`);if(h)h.originValues.add(C),h.count++,m.count++,f.count++;else{var S;(S=m.children)==null||S.push({title:`${c}`,key:`${i}-${a}-${c}`,count:1,originValues:new Set([C]),leaf:!0,checked:p?!1:o.size?o.has(C):!s}),m.count++,f.count++,d.set(`${i}-${a}-${c}`,[`${i}`,`${i}-${a}`,`${i}-${a}-${c}`])}}else{let e=C,t=u.get(e);t?t.count++:(t={title:C,leaf:!0,checked:p?!1:o.size?o.has(C):!s,key:e,count:1},u.set(e,t),d.set(e,[e]))}l++}}let C=p?!1:e?s:!0;if(m>0){let e={title:t.t(`sheets-filter.panel.empty`),count:m,leaf:!0,checked:C,key:f};u.set(`empty`,e),d.set(`empty`,[f])}return{filterTreeItems:Rt(Array.from(u.values())),filterTreeMapCache:d}}function Rt(e){return Array.from(e).sort((e,t)=>e.children&&!t.children?-1:!e.children&&t.children?1:Bt(e.title,t.title)).map(e=>(e.children&&e.children.sort((e,t)=>Number.parseInt(e.key.split(`-`)[1],10)-Number.parseInt(t.key.split(`-`)[1],10)).forEach(e=>{e.children&&e.children.sort((e,t)=>Number.parseInt(e.key.split(`-`)[2],10)-Number.parseInt(t.key.split(`-`)[2],10))}),e))}const zt=e=>!Number.isNaN(Number(e))&&!Number.isNaN(Number.parseFloat(e));function Bt(e,t){let n=zt(e),r=zt(t);return n&&r?Number.parseFloat(e)-Number.parseFloat(t):n&&!r?-1:!n&&r?1:e.localeCompare(t)}function Vt(e,t){for(let n of e){if(n.key===t)return n;if(n.children){let e=Vt(n.children,t);if(e)return e}}return null}function Ht(e){return e.leaf?e.checked:e.children?e.children.every(e=>Ht(e)):!0}function K(e,t){e.leaf&&(t===void 0?e.checked=!e.checked:e.checked=t),e.children&&e.children.forEach(e=>K(e,t))}function Ut(e,t){let n=[];return e.forEach(e=>{let r=e.originValues?t.some(t=>Array.from(e.originValues).some(e=>e.toLowerCase().includes(t.toLowerCase()))):!1,i=!r&&t.some(t=>e.title.toLowerCase().includes(t.toLowerCase()));if(r||i)n.push({...e});else if(e.children){let r=Ut(e.children,t);if(r.length>0){let t=r.reduce((e,t)=>e+t.count,0);n.push({...e,count:t,children:r})}}}),n}function Wt(e){"@babel/helpers - typeof";return Wt=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},Wt(e)}function Gt(e,t){if(Wt(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(Wt(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Kt(e){var t=Gt(e,`string`);return Wt(t)==`symbol`?t:t+``}function q(e,t,n){return(t=Kt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var qt,Jt,Yt;S(`sheets-filter-ui.sheets-filter-panel.service`);let J=class extends i{get filterBy(){return this._filterBy$.getValue()}get filterByModel(){return this._filterByModel}set filterByModel(e){this._filterByModel=e,this._filterByModel$.next(e)}get filterModel(){return this._filterModel}get col(){return this._col$.getValue()}constructor(e,t){super(),this._injector=e,this._refRangeService=t,q(this,`_filterBy$`,new P(E.VALUES)),q(this,`filterBy$`,this._filterBy$.asObservable()),q(this,`_filterByModel$`,new $e(1)),q(this,`filterByModel$`,this._filterByModel$.asObservable()),q(this,`_filterByModel`,null),q(this,`_hasCriteria$`,new P(!1)),q(this,`hasCriteria$`,this._hasCriteria$.asObservable()),q(this,`_filterModel`,null),q(this,`_col$`,new P(-1)),q(this,`col$`,this._col$.asObservable()),q(this,`_filterHeaderListener`,null)}dispose(){this._filterBy$.complete(),this._filterByModel$.complete(),this._hasCriteria$.complete()}setupCol(e,t){this.terminate(),this._filterModel=e,this._col$.next(t);let n=e.getFilterColumn(t);if(n){let r=n.getColumnData();if(r.customFilters){this._hasCriteria$.next(!0),this._setupByConditions(e,t);return}if(r.colorFilters){this._hasCriteria$.next(!0),this._setupByColors(e,t);return}if(r.filters){this._hasCriteria$.next(!0),this._setupByValues(e,t);return}this._hasCriteria$.next(!1),this._setupByValues(e,t);return}this._hasCriteria$.next(!1),this._setupByValues(e,t)}changeFilterBy(e){if(!this._filterModel||this.col===-1)return!1;switch(e){case E.VALUES:this._setupByValues(this._filterModel,this.col);break;case E.COLORS:this._setupByColors(this._filterModel,this.col);break;case E.CONDITIONS:this._setupByConditions(this._filterModel,this.col);break}return!0}terminate(){return this._filterModel=null,this._col$.next(-1),this._disposeFilterHeaderChangeListener(),!0}_disposeFilterHeaderChangeListener(){var e;(e=this._filterHeaderListener)==null||e.dispose(),this._filterHeaderListener=null}_listenToFilterHeaderChange(e,t){this._disposeFilterHeaderChangeListener();let n=e.unitId,r=e.subUnitId,i=e.getRange(),a={startColumn:t,startRow:i.startRow,endRow:i.startRow,endColumn:t};this._filterHeaderListener=this._refRangeService.watchRange(n,r,a,(e,t)=>{if(!t)this.terminate();else{let n=t.startColumn-e.startColumn;n!==0&&this._filterByModel.deltaCol(n)}})}async _setupByValues(e,t){this._disposePreviousModel();let n=e.getRange();return n.startRow===n.endRow?!1:(this.filterByModel=await Zt.fromFilterColumn(this._injector,e,t),this._filterBy$.next(E.VALUES),this._listenToFilterHeaderChange(e,t),!0)}async _setupByColors(e,t){this._disposePreviousModel();let n=e.getRange();return n.startRow===n.endRow?!1:(this.filterByModel=await Qt.fromFilterColumn(this._injector,e,t),this._filterBy$.next(E.COLORS),this._listenToFilterHeaderChange(e,t),!0)}_setupByConditions(e,t){this._disposePreviousModel();let n=e.getRange();return n.startRow===n.endRow?!1:(this.filterByModel=Xt.fromFilterColumn(this._injector,e,t,e.getFilterColumn(t)),this._filterBy$.next(E.CONDITIONS),this._listenToFilterHeaderChange(e,t),!0)}_disposePreviousModel(){var e;(e=this._filterByModel)==null||e.dispose(),this.filterByModel=null}};J=G([W(0,u(d)),W(1,u(Ge))],J);let Xt=qt=class extends i{static fromFilterColumn(e,t,n,r){let[i,a]=H.testMappingFilterColumn(r==null?void 0:r.getColumnData());return e.createInstance(qt,t,n,i,a)}get conditionItem(){return this._conditionItem$.getValue()}get filterConditionFormParams(){return this._filterConditionFormParams$.getValue()}constructor(e,t,n,r,i){super(),this._filterModel=e,this.col=t,this._commandService=i,q(this,`canApply$`,I(!0)),q(this,`_conditionItem$`,void 0),q(this,`conditionItem$`,void 0),q(this,`_filterConditionFormParams$`,void 0),q(this,`filterConditionFormParams$`,void 0),this._conditionItem$=new P(n),this.conditionItem$=this._conditionItem$.asObservable(),this._filterConditionFormParams$=new P(r),this.filterConditionFormParams$=this._filterConditionFormParams$.asObservable()}dispose(){super.dispose(),this._conditionItem$.complete(),this._filterConditionFormParams$.complete()}deltaCol(e){this.col+=e}clear(){return this._disposed?Promise.resolve(!1):this._commandService.executeCommand(D.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}async apply(){if(this._disposed)return!1;let e=H.mapToFilterColumn(this.conditionItem,this.filterConditionFormParams);return this._commandService.executeCommand(D.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:e})}onPrimaryConditionChange(e){let t=H.ALL_CONDITIONS.find(t=>t.operator===e);if(!t)throw Error(`[ByConditionsModel]: condition item not found for operator: ${e}!`);this._conditionItem$.next(t),this._filterConditionFormParams$.next(H.getInitialFormParams(e))}onConditionFormChange(e){let t={...this.filterConditionFormParams,...e};if(t.and!==!0&&delete t.and,e.and!==void 0||e.operator1!==void 0||e.operator2!==void 0){let e=H.testMappingParams(t,this.conditionItem.numOfParameters);this._conditionItem$.next(e)}this._filterConditionFormParams$.next(t)}};Xt=qt=G([W(4,a)],Xt);let Zt=Jt=class extends i{static async fromFilterColumn(e,t,n){let r=e.get(l),i=e.get(p),a=e.get(Ft,g.OPTIONAL),{unitId:o,subUnitId:s}=t,c=r.getUniverSheetInstance(o);if(!c)throw Error(`[ByValuesModel]: Workbook not found for filter model with unitId: ${o}!`);let u=c==null?void 0:c.getSheetBySheetId(s);if(!u)throw Error(`[ByValuesModel]: Worksheet not found for filter model with unitId: ${o} and subUnitId: ${s}!`);let d=t.getRange(),f=n,m=t.getFilterColumn(n),h=m==null?void 0:m.getColumnData().filters,_=new Set(h==null?void 0:h.filters),v=!!(h&&h.blank),y=t.getFilteredOutRowsExceptCol(n),b={...d,startRow:d.startRow+1,startColumn:f,endColumn:f},x,S;if(a){let e=await a.getFilterValues({unitId:o,subUnitId:s,filteredOutRowsByOtherColumns:Array.from(y),filterColumn:m,filters:!!h,blankChecked:v,iterateRange:b,alreadyChecked:Array.from(_)});x=e.filterTreeItems,S=e.filterTreeMapCache}else{let e=Lt(!!h,i,b,u,y,m,_,v,c.getStyles());x=e.filterTreeItems,S=e.filterTreeMapCache}return e.createInstance(Jt,t,n,x,S)}get rawFilterItems(){return this._rawFilterItems$.getValue()}get filterItems(){return this._filterItems}get treeMapCache(){return this._treeMapCache}constructor(e,t,n,r,i){super(),this._filterModel=e,this.col=t,this._commandService=i,q(this,`_rawFilterItems$`,void 0),q(this,`rawFilterItems$`,void 0),q(this,`filterItems$`,void 0),q(this,`_filterItems`,[]),q(this,`_treeMapCache`,void 0),q(this,`canApply$`,void 0),q(this,`_manuallyUpdateFilterItems$`,void 0),q(this,`_searchString$`,void 0),q(this,`searchString$`,void 0),this._treeMapCache=r,this._searchString$=new P(``),this.searchString$=this._searchString$.asObservable(),this._rawFilterItems$=new P(n),this.rawFilterItems$=this._rawFilterItems$.asObservable(),this._manuallyUpdateFilterItems$=new et,this.filterItems$=it(tt([this._searchString$.pipe(lt(500,void 0,{leading:!0,trailing:!0}),ot(void 0)),this._rawFilterItems$]).pipe(F(([e,t])=>e?Ut(t,e.toLowerCase().split(/\s+/).filter(e=>!!e)):t)),this._manuallyUpdateFilterItems$).pipe(at(1)),this.canApply$=this.filterItems$.pipe(F(e=>Nt(e).checked>0)),this.disposeWithMe(this.filterItems$.subscribe(e=>this._filterItems=e))}dispose(){this._rawFilterItems$.complete(),this._searchString$.complete()}deltaCol(e){this.col+=e}setSearchString(e){this._searchString$.next(e)}onCheckAllToggled(e){let t=y.deepClone(this._filterItems);t.forEach(t=>K(t,e)),this._manuallyUpdateFilterItems(t)}onFilterCheckToggled(e){let t=y.deepClone(this._filterItems),n=Vt(t,e.key);n&&(K(n,!Ht(n)),this._manuallyUpdateFilterItems(t))}onFilterOnly(e){let t=y.deepClone(this._filterItems);t.forEach(e=>K(e,!1)),e.forEach(e=>{let n=Vt(t,e);n&&K(n,!0)}),this._manuallyUpdateFilterItems(t)}_manuallyUpdateFilterItems(e){this._manuallyUpdateFilterItems$.next(e)}clear(){return this._disposed?Promise.resolve(!1):this._commandService.executeCommand(D.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}async apply(){if(this._disposed)return!1;let e=Nt(this._filterItems),{checked:t,checkedItems:n}=e,r=this.rawFilterItems,i=0;for(let e of r)i+=e.count;let a=t===0,o=e.checked===i,s={colId:this.col};if(a)throw Error(`[ByValuesModel]: no checked items!`);if(o)return this._commandService.executeCommand(D.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null});{s.filters={};let e=n.filter(e=>e.key!==`empty`);e.length>0&&(s.filters={filters:e.flatMap(e=>e.originValues?Array.from(e.originValues):[e.title])}),e.length!==n.length&&(s.filters.blank=!0)}return this._commandService.executeCommand(D.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:s})}};Zt=Jt=G([W(4,a)],Zt);let Qt=Yt=class extends i{static async fromFilterColumn(e,n,r){var i,a,o;let s=e.get(l),{unitId:c,subUnitId:u}=n,d=s.getUniverSheetInstance(c);if(!d)throw Error(`[ByColorsModel]: Workbook not found for filter model with unitId: ${c}!`);let f=d==null?void 0:d.getSheetBySheetId(u);if(!f)throw Error(`[ByColorsModel]: Worksheet not found for filter model with unitId: ${c} and subUnitId: ${u}!`);let p=n.getRange(),m=r,h=(i=n.getFilterColumn(r))==null?void 0:i.getColumnData().colorFilters,g=n.getFilteredOutRowsExceptCol(r),_={...p,startRow:p.startRow+1,startColumn:m,endColumn:m},v=new Map,y=new Set((a=h==null?void 0:h.cellFillColors)==null?[]:a),b=new Map,x=new Set((o=h==null?void 0:h.cellTextColors)==null?[]:o);for(let e of f.iterateByColumn(_,!1,!0)){let{row:n,col:r,value:i}=e;if(g.has(n))continue;let a=f.getComposedCellStyleByCellData(n,r,i);if(a.bg&&a.bg.rgb){let e=new t(a.bg.rgb).toRgbString();v.has(e)||v.set(e,{color:e,checked:y.has(e)})}else v.set(`default-fill-color`,{color:null,checked:y.has(null)});if(a.cl&&a.cl.rgb){let e=new t(a.cl.rgb).toRgbString();b.has(e)||b.set(e,{color:e,checked:x.has(e)})}else b.set(`default-font-color`,{color:Be,checked:x.has(Be)})}return e.createInstance(Yt,n,r,v,b)}get cellFillColors(){return this._cellFillColors$.getValue()}get cellTextColors(){return this._cellTextColors$.getValue()}constructor(e,t,n,r,i){super(),this._filterModel=e,this.col=t,this._commandService=i,q(this,`canApply$`,I(!0)),q(this,`_cellFillColors$`,void 0),q(this,`cellFillColors$`,void 0),q(this,`_cellTextColors$`,void 0),q(this,`cellTextColors$`,void 0),this._cellFillColors$=new P(Array.from(n.values())),this.cellFillColors$=this._cellFillColors$.asObservable(),this._cellTextColors$=new P(Array.from(r.values())),this.cellTextColors$=this._cellTextColors$.asObservable()}dispose(){super.dispose(),this._cellFillColors$.complete()}deltaCol(e){this.col+=e}clear(){return this._disposed?Promise.resolve(!1):this._commandService.executeCommand(D.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}onFilterCheckToggled(e,t=!0){let n=t?this.cellFillColors:this.cellTextColors,r=[],i=!1;for(let t=0;t<n.length;t++){let a=n[t];if(a.color===e.color){i=!0,r.push({color:a.color,checked:!a.checked});continue}r.push({color:a.color,checked:a.checked})}i&&(this._resetColorsCheckedStatus(!t),t?this._cellFillColors$.next([...r]):this._cellTextColors$.next([...r]))}_resetColorsCheckedStatus(e=!0){let t=e?this.cellFillColors:this.cellTextColors,n=[];for(let e=0;e<t.length;e++)n.push({color:t[e].color,checked:!1});e?this._cellFillColors$.next([...n]):this._cellTextColors$.next([...n])}async apply(){if(this._disposed)return!1;let e=this.cellFillColors.filter(e=>e.checked).map(e=>e.color),t=this.cellTextColors.filter(e=>e.checked).map(e=>e.color);if(e.length===0&&t.length===0)return this._commandService.executeCommand(D.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null});let n={colId:this.col};return e.length>0?n.colorFilters={cellFillColors:e}:t.length>0&&(n.colorFilters={cellTextColors:t}),this._commandService.executeCommand(D.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:n})}};Qt=Yt=G([W(4,a)],Qt);const $t=`FILTER_PANEL_OPENED`,en={id:`sheet.operation.open-filter-panel`,type:n.OPERATION,handler:(e,t)=>{let n=e.get(s),r=e.get(O),i=e.get(J),o=e.get(a),c=e.has(ge)?e.get(ge):null;c!=null&&c.isVisible().visible&&o.syncExecuteCommand(ye.id,{visible:!1});let{unitId:l,subUnitId:u,col:d}=t,f=r.getFilterModel(l,u);return f?(i.setupCol(f,d),n.getContextValue(`FILTER_PANEL_OPENED`)||n.setContextValue($t,!0),!0):!1}},Y={id:`sheet.operation.close-filter-panel`,type:n.OPERATION,handler:e=>{let t=e.get(s),n=e.get(J),r=e.get(Ae,g.OPTIONAL);return t.getContextValue(`FILTER_PANEL_OPENED`)?(t.setContextValue($t,!1),r==null||r.focus(),n.terminate()):!1}},tn={id:`sheet.operation.apply-filter`,type:n.OPERATION,handler:(e,t)=>{let{filterBy:n}=t;return e.get(J).changeFilterBy(n)}};var nn=`@univerjs/sheets-filter-ui`,rn=`0.20.1`;const an=`sheets-filter-ui.config`;Symbol(an);const on={};let X=class extends i{constructor(e,t,n,r,i,a){super(),this._sheetsFilterService=e,this._localeService=t,this._commandService=n,this._sheetPermissionCheckPermission=r,this._injector=i,this._sheetsSelectionService=a,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===me.id){var t;let e=Qe(this._injector.get(l));if(!e)return;let{unitId:r,subUnitId:i,worksheet:a}=e,o=(t=this._sheetsFilterService.getFilterModel(r,i))==null?void 0:t.getRange(),s;if(o)s=this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[j],worksheetTypes:[M,N]},[o],r,i);else{var n;let e=(n=this._sheetsSelectionService.getCurrentLastSelection())==null?void 0:n.range;if(e){let t={...e};t=e.startColumn===e.endColumn&&e.startRow===e.endRow?Ze(t,{left:!0,right:!0,up:!0,down:!0},a):t,s=this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[j],worksheetTypes:[N,M]},[t],r,i)}else s=this._sheetPermissionCheckPermission.permissionCheckWithoutRange({rangeTypes:[j],worksheetTypes:[N,M]})}s||this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.filterErr`))}if(e.id===en.id){var r;let t=e.params,{unitId:n,subUnitId:i}=t,a=(r=this._sheetsFilterService.getFilterModel(n,i))==null?void 0:r.getRange(),o=y.deepClone(a);o&&(o.startColumn=t.col,o.endColumn=t.col,this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[j],worksheetTypes:[M,N]},[o],n,i)||this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.filterErr`)))}}))}};X=G([W(0,u(O)),W(1,u(p)),W(2,a),W(3,u(Je)),W(4,u(d)),W(5,u(Ye))],X);const sn=new Path2D(`M3.30363 3C2.79117 3 2.51457 3.60097 2.84788 3.99024L6.8 8.60593V12.5662C6.8 12.7184 6.8864 12.8575 7.02289 12.9249L8.76717 13.7863C8.96655 13.8847 9.2 13.7396 9.2 13.5173V8.60593L13.1521 3.99024C13.4854 3.60097 13.2088 3 12.6964 3H3.30363Z`);var cn=class{static drawNoCriteria(e,t,n,r){e.save(),He.drawWith(e,{radius:2,width:16,height:16,fill:r}),e.lineCap=`square`,e.strokeStyle=n,e.scale(t/16,t/16),e.beginPath(),e.lineWidth=1,e.lineCap=`round`,e.moveTo(3,4),e.lineTo(13,4),e.moveTo(4.5,8),e.lineTo(11.5,8),e.moveTo(6,12),e.lineTo(10,12),e.stroke(),e.restore()}static drawHasCriteria(e,t,n,r){e.save(),He.drawWith(e,{radius:2,width:16,height:16,fill:r}),e.scale(t/16,t/16),e.fillStyle=n,e.fill(sn),e.restore()}};let ln=class extends Ue{constructor(e,t,n,r,i){super(e,t),this._contextService=n,this._commandService=r,this._themeService=i,q(this,`_cellWidth`,0),q(this,`_cellHeight`,0),q(this,`_filterParams`,void 0),q(this,`_hovered`,!1),this.setShapeProps(t),this.onPointerDown$.subscribeEvent(e=>this.onPointerDown(e)),this.onPointerEnter$.subscribeEvent(()=>this.onPointerEnter()),this.onPointerLeave$.subscribeEvent(()=>this.onPointerLeave())}setShapeProps(e){e.cellHeight!==void 0&&(this._cellHeight=e.cellHeight),e.cellWidth!==void 0&&(this._cellWidth=e.cellWidth),e.filterParams!==void 0&&(this._filterParams=e.filterParams),this.transformByState({width:e.width,height:e.height})}_draw(e){let t=this._cellHeight,n=this._cellWidth,r=16-n,i=16-t;e.save();let a=new Path2D;a.rect(r,i,n,t),e.clip(a);let{hasCriteria:o}=this._filterParams,s=this._themeService.getColorFromTheme(`primary.600`),c=this._hovered?this._themeService.getColorFromTheme(`gray.50`):`rgba(255, 255, 255, 1.0)`;o?cn.drawHasCriteria(e,16,s,c):cn.drawNoCriteria(e,16,s,c),e.restore()}onPointerDown(e){if(e.button===2)return;let{col:t,unitId:n,subUnitId:r}=this._filterParams;this._contextService.getContextValue(`FILTER_PANEL_OPENED`)||!this._commandService.hasCommand(en.id)||setTimeout(()=>{this._commandService.executeCommand(en.id,{unitId:n,subUnitId:r,col:t})},200)}onPointerEnter(){this._hovered=!0,this.makeDirty(!0)}onPointerLeave(){this._hovered=!1,this.makeDirty(!0)}};ln=G([W(2,s),W(3,a),W(4,u(v))],ln);function un(e,t,n,r){switch(r){case x.TOP:return e+1;case x.MIDDLE:return e+Math.max(0,(n-16)/2);case x.BOTTOM:default:return t-16-1}}let dn=class extends _{constructor(e,t,n,r,i,a,o,s){super(),this._context=e,this._injector=t,this._sheetSkeletonManagerService=n,this._sheetsFilterService=r,this._themeService=i,this._sheetInterceptorService=a,this._commandService=o,this._selectionRenderService=s,q(this,`_currentRenderParams`,null),q(this,`_filterRangeShape`,null),q(this,`_buttonRenderDisposable`,null),q(this,`_filterButtonShapes`,[]),this._initRenderer()}dispose(){super.dispose(),this._disposeRendering()}_initRenderer(){this.disposeWithMe(this._themeService.currentTheme$.subscribe(()=>{this._refreshRendering(this._currentRenderParams)})),this._sheetSkeletonManagerService.currentSkeleton$.pipe(st(e=>{var t,r;if(!e)return I(null);let{unit:i,unitId:a}=this._context,o=((t=i.getActiveSheet())==null?void 0:t.getSheetId())||``,s=(r=this._sheetsFilterService.getFilterModel(a,o))==null?void 0:r,c=()=>({unitId:a,worksheetId:o,filterModel:s,range:s==null?void 0:s.getRange(),skeleton:e.skeleton});return C(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(rt(([e])=>{var t;return e.type===n.MUTATION&&((t=e.params)==null?void 0:t.unitId)===i.getUnitId()&&(ae.has(e.id)||e.id===Ke.id)}),lt(20,void 0,{leading:!1,trailing:!0}),F(c),ot(c()))}),ct(this.dispose$)).subscribe(e=>{this._currentRenderParams=e,this._refreshRendering(e)})}_refreshRendering(e){this._disposeRendering(),!(!e||!e.range)&&(this._renderRange(e.range,e.skeleton),this._renderButtons(e))}_renderRange(e,t){let{scene:n}=this._context,{rowHeaderWidth:r,columnHeaderHeight:i}=t,a=this._filterRangeShape=new ve(n,1e3,this._themeService,{rowHeaderWidth:r,columnHeaderHeight:i,enableAutoFill:!1,highlightHeader:!1}),o=Xe({range:e,primary:null,style:{fill:`rgba(0, 0, 0, 0.0)`}},t);a.updateRangeBySelectionWithCoord(o),a.setEvent(!1),n.makeDirty(!0)}_renderButtons(e){let{range:t,filterModel:n,unitId:r,skeleton:i,worksheetId:a}=e,{unit:o,scene:s}=this._context,c=o.getSheetBySheetId(a);if(!c)return;this._interceptCellContent(r,a,e.range);let{startColumn:l,endColumn:u,startRow:d}=t;for(let e=l;e<=u;e++){let t=`sheets-filter-button-${e}`,o=we(d,e,s,i),l=c.getComposedCellStyle(d,e),u=(l==null?void 0:l.vt)||x.BOTTOM,{startX:f,startY:p,endX:m,endY:h}=o,g=m-f,_=h-p;if(_<=1||g<=1)continue;let v=!!n.getFilterColumn(e),y={left:m-16-1,top:un(p,h,_,u),height:16,width:16,zIndex:5e3,cellHeight:_,cellWidth:g,filterParams:{unitId:r,subUnitId:a,col:e,hasCriteria:v}},b=this._injector.createInstance(ln,t,y);this._filterButtonShapes.push(b)}s.addObjects(this._filterButtonShapes),s.makeDirty()}_interceptCellContent(e,t,n){let{startRow:r,startColumn:i,endColumn:a}=n;this._buttonRenderDisposable=this._sheetInterceptorService.intercept(We.CELL_CONTENT,{effect:f.Style,handler:(n,o,s)=>{let{row:c,col:l,unitId:u,subUnitId:d}=o;return u!==e||d!==t||c!==r||l<i||l>a?s(n):((!n||n===o.rawData)&&(n={...o.rawData}),n.fontRenderExtension={...n==null?void 0:n.fontRenderExtension,rightOffset:16},s(n))},priority:10})}_disposeRendering(){var e,t;(e=this._filterRangeShape)==null||e.dispose(),this._filterButtonShapes.forEach(e=>e.dispose()),(t=this._buttonRenderDisposable)==null||t.dispose(),this._filterRangeShape=null,this._buttonRenderDisposable=null,this._filterButtonShapes=[]}};dn=G([W(1,u(d)),W(2,u(xe)),W(3,u(O)),W(4,u(v)),W(5,u(qe)),W(6,a),W(7,_e)],dn);let fn=class extends _{constructor(e,t){super(),this._renderManagerService=e,this._sheetsRenderService=t,[fe,de,le,se].forEach(e=>this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(e.id))),this.disposeWithMe(this._renderManagerService.registerRenderModule(b.UNIVER_SHEET,[dn]))}};fn=G([W(0,Ve),W(1,u(Se))],fn);let Z=class extends h{constructor(e=on,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=w({},on,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(an,i)}onStarting(){[[X],[fn]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(X)}onRendered(){this._injector.get(fn)}};q(Z,`type`,b.UNIVER_SHEET),q(Z,`pluginName`,`SHEET_FILTER_UI_PLUGIN`),q(Z,`packageName`,nn),q(Z,`version`,rn),Z=G([r(he),W(1,u(d)),W(2,o)],Z);function pn(e){let t=e.get(O);return{id:me.id,type:Fe.BUTTON_SELECTOR,icon:`FilterIcon`,tooltip:`sheets-filter.toolbar.smart-toggle-filter-tooltip`,hidden$:Re(e,b.UNIVER_SHEET),activated$:t.activeFilterModel$.pipe(F(e=>!!e)),disabled$:Ee(e,Te(e,{worksheetTypes:[M,N],rangeTypes:[j]}))}}function mn(e){let t=e.get(O);return{id:ie.id,type:Fe.BUTTON,title:`sheets-filter.toolbar.clear-filter-criteria`,hidden$:Re(e,b.UNIVER_SHEET),disabled$:t.activeFilterModel$.pipe(st(e=>{var t;return(t=e==null?void 0:e.hasCriteria$.pipe(F(e=>!e)))==null?I(!0):t}))}}function hn(e){let t=e.get(O);return{id:oe.id,type:Fe.BUTTON,title:`sheets-filter.toolbar.re-calc-filter-conditions`,hidden$:Re(e,b.UNIVER_SHEET),disabled$:t.activeFilterModel$.pipe(st(e=>{var t;return(t=e==null?void 0:e.hasCriteria$.pipe(F(e=>!e)))==null?I(!0):t}))}}const gn={[Le.ORGANIZATION]:{[me.id]:{order:2,menuItemFactory:pn,[ie.id]:{order:0,menuItemFactory:mn},[oe.id]:{order:1,menuItemFactory:hn}}}};function _n(e){let{model:t}=e,n=k(p),r=A(t.cellFillColors$,[],!0),i=A(t.cellTextColors$,[],!0),a=L(e=>{t.onFilterCheckToggled(e)},[t]),o=L(e=>{t.onFilterCheckToggled(e,!1)},[t]);return R(`div`,{"data-u-comp":`sheets-filter-panel-colors-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:z(`div`,{"data-u-comp":`sheets-filter-panel`,className:Tt(`univer-mt-2 univer-box-border univer-flex univer-h-[300px] univer-flex-grow univer-flex-col univer-gap-4 univer-overflow-auto univer-rounded-md univer-px-2 univer-py-2.5`,wt),children:[r.length>1&&z(`div`,{children:[R(`div`,{className:`univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white`,children:n.t(`sheets-filter.panel.filter-by-cell-fill-color`)}),R(`div`,{className:`univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2`,children:r.map((e,t)=>z(`div`,{className:`univer-relative univer-size-6`,onClick:()=>a(e),children:[e.color?R(`button`,{type:`button`,className:Tt(`univer-box-border univer-size-6 univer-cursor-pointer univer-rounded-full univer-border univer-border-solid univer-border-transparent univer-bg-gray-300 univer-transition-shadow hover:univer-ring-2 hover:univer-ring-offset-2 hover:univer-ring-offset-white`),style:{backgroundColor:e.color}}):R(Dt,{className:`univer-size-6 univer-cursor-pointer univer-rounded-full hover:univer-ring-2 hover:univer-ring-offset-2 hover:univer-ring-offset-white`}),e.checked&&R(vn,{})]},`sheets-filter-cell-fill-color-${t}`))})]}),i.length>1&&z(`div`,{children:[R(`div`,{className:`univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white`,children:n.t(`sheets-filter.panel.filter-by-cell-text-color`)}),R(`div`,{className:`univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2`,children:i.map((e,t)=>z(`div`,{className:`univer-relative univer-size-6`,onClick:()=>o(e),children:[R(`div`,{className:`univer-box-border univer-flex univer-size-full univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-full univer-border univer-border-solid univer-border-[rgba(13,13,13,0.06)] univer-p-0.5 hover:univer-ring-2 hover:univer-ring-offset-2 hover:univer-ring-offset-white dark:!univer-border-[rgba(255,255,255,0.06)]`,children:R(Et,{style:{color:e.color}})}),e.checked&&R(vn,{})]},`sheets-filter-cell-text-color-${t}`))})]}),r.length<=1&&i.length<=1&&R(`div`,{className:`univer-flex univer-size-full univer-items-center univer-justify-center univer-text-sm univer-text-gray-900 dark:!univer-text-gray-200`,children:n.t(`sheets-filter.panel.filter-by-color-none`)})]})})}function vn(){return R(`div`,{className:`univer-absolute -univer-bottom-0.5 -univer-right-0.5 univer-flex univer-size-3 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-full univer-bg-white`,children:R(At,{className:`univer-size-full univer-font-bold univer-text-[#418F1F]`})})}function yn(e){var t,n;let{model:r}=e,i=k(p),a=A(r.conditionItem$,void 0),o=A(r.filterConditionFormParams$,void 0),s=o!=null&&o.and?`AND`:`OR`,c=L(e=>{r.onConditionFormChange({and:e===`AND`})},[r]),l=bn(i),u=L(e=>{r.onPrimaryConditionChange(e)},[r]),d=xn(i),f=L(e=>{r.onConditionFormChange(e)},[r]),m=i.t(`sheets-filter.panel.input-values-placeholder`);function h(e,t,n){let r=H.getItemByOperator(e).numOfParameters===1;return z(Mt,{children:[n===`operator2`&&z(vt,{value:s,onChange:c,children:[R(_t,{value:`AND`,children:i.t(`sheets-filter.panel.and`)}),R(_t,{value:`OR`,children:i.t(`sheets-filter.panel.or`)})]}),R(bt,{value:e,options:d,onChange:e=>f({[n]:e})}),r&&R(`div`,{children:R(ht,{className:`univer-mt-2`,value:t,placeholder:m,onChange:e=>f({[n===`operator1`?`val1`:`val2`]:e})})})]})}return R(`div`,{"data-u-comp":`sheets-filter-panel-conditions-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:a&&o&&z(Mt,{children:[R(bt,{value:a.operator,options:l,onChange:u}),H.getItemByOperator(a.operator).numOfParameters===0?null:z(`div`,{"data-u-comp":`sheets-filter-panel-conditions-container-inner`,className:Tt(`univer-mt-2 univer-flex-grow univer-overflow-hidden univer-rounded-md univer-p-2`,wt),children:[a.numOfParameters>=1&&h(o.operator1,(t=o.val1)==null?``:t,`operator1`),a.numOfParameters>=2&&h(o.operator2,(n=o.val2)==null?``:n,`operator2`),z(`div`,{"data-u-comp":`sheets-filter-panel-conditions-desc`,className:`univer-mt-2 univer-text-xs univer-text-gray-500`,children:[i.t(`sheets-filter.panel.?`),R(`br`,{}),i.t(`sheets-filter.panel.*`)]})]})]})})}function bn(e){return jt(()=>[{options:[{label:e.t(H.NONE.label),value:H.NONE.operator}]},{options:[{label:e.t(H.EMPTY.label),value:H.EMPTY.operator},{label:e.t(H.NOT_EMPTY.label),value:H.NOT_EMPTY.operator}]},{options:[{label:e.t(H.TEXT_CONTAINS.label),value:H.TEXT_CONTAINS.operator},{label:e.t(H.DOES_NOT_CONTAIN.label),value:H.DOES_NOT_CONTAIN.operator},{label:e.t(H.STARTS_WITH.label),value:H.STARTS_WITH.operator},{label:e.t(H.ENDS_WITH.label),value:H.ENDS_WITH.operator},{label:e.t(H.EQUALS.label),value:H.EQUALS.operator}]},{options:[{label:e.t(H.GREATER_THAN.label),value:H.GREATER_THAN.operator},{label:e.t(H.GREATER_THAN_OR_EQUAL.label),value:H.GREATER_THAN_OR_EQUAL.operator},{label:e.t(H.LESS_THAN.label),value:H.LESS_THAN.operator},{label:e.t(H.LESS_THAN_OR_EQUAL.label),value:H.LESS_THAN_OR_EQUAL.operator},{label:e.t(H.EQUAL.label),value:H.EQUAL.operator},{label:e.t(H.NOT_EQUAL.label),value:H.NOT_EQUAL.operator},{label:e.t(H.BETWEEN.label),value:H.BETWEEN.operator},{label:e.t(H.NOT_BETWEEN.label),value:H.NOT_BETWEEN.operator}]},{options:[{label:e.t(H.CUSTOM.label),value:H.CUSTOM.operator}]}],[e.getCurrentLocale(),e])}function xn(e){return jt(()=>H.ALL_CONDITIONS.filter(e=>e.numOfParameters!==2).map(t=>({label:e.t(t.label),value:t.operator})),[e.getCurrentLocale(),e])}function Sn(e){let{model:t}=e,n=k(p),r=A(t.searchString$,``,!0),i=A(t.filterItems$,void 0,!0),a=n.t(`sheets-filter.panel.filter-only`),o=Nt(i),s=o.checked>0&&o.unchecked===0,c=o.checked>0&&o.unchecked>0,l=t.treeMapCache,u=L(()=>{t.onCheckAllToggled(!s)},[t,s]),d=L(e=>{t.setSearchString(e)},[t]);function f(e){let t=[];return e.forEach(e=>{e.checked&&t.push(e.key),e.children&&(t=t.concat(f(e.children)))}),t}return z(`div`,{"data-u-comp":`sheets-filter-panel-values-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:[R(ht,{autoFocus:!0,value:r,placeholder:n.t(`sheets-filter.panel.search-placeholder`),onChange:d}),z(`div`,{"data-u-comp":`sheets-filter-panel`,className:Tt(`univer-mt-2 univer-box-border univer-flex univer-flex-grow univer-flex-col univer-overflow-hidden univer-rounded-md univer-px-2 univer-py-2.5`,wt),children:[R(`div`,{"data-u-comp":`sheets-filter-panel-values-item`,className:`univer-box-border univer-h-8 univer-w-full univer-py-0.5`,children:z(`div`,{"data-u-comp":`sheets-filter-panel-values-item-inner`,className:`univer-box-border univer-flex univer-h-7 univer-items-center univer-rounded-md univer-py-0 univer-pl-5 univer-pr-0.5 univer-text-sm`,children:[R(mt,{indeterminate:c,disabled:i.length===0,checked:s,onChange:u}),R(`span`,{"data-u-comp":`sheets-filter-panel-values-item-text`,className:`univer-mx-1 univer-inline-block univer-flex-shrink univer-truncate univer-text-gray-900 dark:!univer-text-white`,children:`${n.t(`sheets-filter.panel.select-all`)}`}),R(`span`,{"data-u-comp":`sheets-filter-panel-values-item-count`,className:`univer-text-gray-400 dark:!univer-text-gray-500`,children:`(${o.checked}/${o.checked+o.unchecked})`})]})}),R(`div`,{"data-u-comp":`sheets-filter-panel-values-virtual`,className:`univer-flex-grow`,children:R(Ct,{data:i,defaultExpandAll:!1,valueGroup:f(i),onChange:e=>{t.onFilterCheckToggled(e)},defaultCache:l,itemHeight:28,treeNodeClassName:`
1
+ import { BooleanNumber, ColorKit, CommandType, DependentOn, Disposable, ICommandService, IConfigService, IContextService, ILogService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, Optional, Plugin, Quantity, RxDisposable, ThemeService, Tools, UniverInstanceType, VerticalAlign, createIdentifier, extractPureTextFromCell, fromCallback, merge, numfmt, registerDependencies, touchDependencies } from "@univerjs/core";
2
+ import { ClearSheetsFilterCriteriaCommand, CustomFilterOperator, FILTER_MUTATIONS, FilterBy, ReCalcSheetsFilterCommand, ReCalcSheetsFilterMutation, RemoveSheetFilterCommand, RemoveSheetsFilterMutation, SetSheetFilterRangeCommand, SetSheetsFilterCriteriaCommand, SetSheetsFilterCriteriaMutation, SetSheetsFilterRangeMutation, SheetsFilterService, SheetsFilterSyncController, SmartToggleSheetsFilterCommand, UniverSheetsFilterPlugin } from "@univerjs/sheets-filter";
3
+ import { IEditorBridgeService, ISheetSelectionRenderService, SelectionControl, SetCellEditVisibleOperation, SheetCanvasPopManagerService, SheetSkeletonManagerService, SheetsRenderService, SheetsUIPart, getCoordByCell, getCurrentRangeDisable$, getObservableWithExclusiveRange$, whenSheetEditorFocused } from "@univerjs/sheets-ui";
4
+ import { ComponentContainer, ComponentManager, ILayoutService, IMenuManagerService, IMessageService, IShortcutService, KeyCode, MenuItemType, MetaKeys, RibbonDataGroup, getMenuHiddenObservable, useComponentsOfPart, useDependency, useObservable } from "@univerjs/ui";
5
+ import { COLOR_BLACK_RGB, IRenderManagerService, Rect, Shape } from "@univerjs/engine-render";
6
+ import { INTERCEPTOR_POINT, RangeProtectionPermissionViewPoint, RefRangeService, SetRangeValuesMutation, SheetInterceptorService, SheetPermissionCheckController, SheetsSelectionsService, WorksheetFilterPermission, WorksheetViewPermission, attachSelectionWithCoord, expandToContinuousRange, getSheetCommandTarget } from "@univerjs/sheets";
7
+ import { BehaviorSubject, ReplaySubject, Subject, combineLatest, distinctUntilChanged, filter, map, merge as merge$1, of, shareReplay, startWith, switchMap, takeUntil, throttleTime } from "rxjs";
8
+ import { IRPCChannelService, fromModule, toModule } from "@univerjs/rpc";
9
+ import { Button, Checkbox, Input, MessageType, Radio, RadioGroup, Segmented, Select, Switch, Tooltip, Tree, borderClassName, clsx } from "@univerjs/design";
10
+ import { AIcon, BanIcon, FilterIcon, InfoIcon, SuccessIcon } from "@univerjs/icons";
11
+ import { useCallback, useMemo } from "react";
12
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
13
+
14
+ //#region src/models/extended-operators.ts
15
+ /**
16
+ * Copyright 2023-present DreamNum Co., Ltd.
17
+ *
18
+ * Licensed under the Apache License, Version 2.0 (the "License");
19
+ * you may not use this file except in compliance with the License.
20
+ * You may obtain a copy of the License at
21
+ *
22
+ * http://www.apache.org/licenses/LICENSE-2.0
23
+ *
24
+ * Unless required by applicable law or agreed to in writing, software
25
+ * distributed under the License is distributed on an "AS IS" BASIS,
26
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
+ * See the License for the specific language governing permissions and
28
+ * limitations under the License.
29
+ */
30
+ let OperatorOrder = /* @__PURE__ */ function(OperatorOrder) {
31
+ OperatorOrder[OperatorOrder["FIRST"] = 0] = "FIRST";
32
+ OperatorOrder[OperatorOrder["SECOND"] = 1] = "SECOND";
33
+ return OperatorOrder;
34
+ }({});
35
+ /**
36
+ * Extended custom filter operators.
37
+ *
38
+ * These operators are not defined in OOXML,
39
+ * so when exporting these operators we need to fallback to `CustomFilterOperator` and
40
+ * other possible filter types.
41
+ */
42
+ let ExtendCustomFilterOperator = /* @__PURE__ */ function(ExtendCustomFilterOperator) {
43
+ ExtendCustomFilterOperator["NONE"] = "none";
44
+ /** Fallback to `<customFilter val="123*" />` */
45
+ ExtendCustomFilterOperator["STARTS_WITH"] = "startsWith";
46
+ /** Fallback to `<customFilter operator="notEqual" val="123*" />` */
47
+ ExtendCustomFilterOperator["DOES_NOT_START_WITH"] = "doesNotStartWith";
48
+ /** Fallback to `<customFilter val="*123" />` */
49
+ ExtendCustomFilterOperator["ENDS_WITH"] = "endsWith";
50
+ /** Fallback to `<customFilter operator="notEqual" val="*123" />` */
51
+ ExtendCustomFilterOperator["DOES_NOT_END_WITH"] = "doesNotEndWith";
52
+ /** Fallback to `<customFilter val="*123*" />` */
53
+ ExtendCustomFilterOperator["CONTAINS"] = "contains";
54
+ /** Fallback to `<customFilter operator="notEqual" val="*123*" />` */
55
+ ExtendCustomFilterOperator["DOES_NOT_CONTAIN"] = "doesNotContain";
56
+ /**
57
+ * Text equals. It is not same as CustomFilterOperator.EQUAL.
58
+ *
59
+ * When equals empty, it will be mapped to.
60
+ *
61
+ * <autoFilter>
62
+ * <filterColumn colId="0">
63
+ * <filters blank="1"/>
64
+ * </filterColumn>
65
+ * </autoFilter>
66
+ */
67
+ ExtendCustomFilterOperator["EQUALS"] = "equals";
68
+ /** Fallback to `<customFilter operator="notEqual" val="" />` */
69
+ ExtendCustomFilterOperator["NOT_EQUALS"] = "notEquals";
70
+ /**
71
+ * Fallback to `<filter blank="1" />`.
72
+ *
73
+ * It can also fallback to `<customFilter val="" />`, when with another custom filter.
74
+ */
75
+ ExtendCustomFilterOperator["EMPTY"] = "empty";
76
+ /** Fallback to `<customFilter operator="notEqual" val=" " />` */
77
+ ExtendCustomFilterOperator["NOT_EMPTY"] = "notEmpty";
78
+ /**
79
+ * Falls back to the following XML:
80
+ *
81
+ * ```xml
82
+ * <customFilters and="1">
83
+ * <customFilter operator="greaterThanOrEqual" val="123"/>
84
+ * <customFilter operator="lessThanOrEqual" val="456"/>
85
+ * </customFilters>
86
+ * ```
87
+ *
88
+ * Actually in Microsoft Excel, `NOT_BETWEEN` is still `BETWEEN`, as long as the two operators
89
+ * are `greaterThanOrEqual` and `lessThanOrEqual`.
90
+ */
91
+ ExtendCustomFilterOperator["BETWEEN"] = "between";
92
+ /**
93
+ * Falls back to the following XML:
94
+ *
95
+ * ```xml
96
+ * <customFilters> <!-- no `and="1"` means `OR` -->
97
+ * <customFilter operator="lessThan" val="456"/>
98
+ * <customFilter operator="greaterThan" val="123"/>
99
+ * </customFilters>
100
+ * ```
101
+ */
102
+ ExtendCustomFilterOperator["NOT_BETWEEN"] = "notBetween";
103
+ ExtendCustomFilterOperator["CUSTOM"] = "custom";
104
+ return ExtendCustomFilterOperator;
105
+ }({});
106
+
107
+ //#endregion
108
+ //#region src/models/conditions.ts
109
+ let FilterConditionItems;
110
+ (function(_FilterConditionItems) {
111
+ const NONE = _FilterConditionItems.NONE = {
112
+ label: "sheets-filter.conditions.none",
113
+ operator: ExtendCustomFilterOperator.NONE,
114
+ order: OperatorOrder.SECOND,
115
+ numOfParameters: 0,
116
+ getDefaultFormParams: () => {
117
+ throw new Error("[FilterConditionItems.NONE]: should not have initial form params!");
118
+ },
119
+ testMappingParams: (params) => {
120
+ return params.operator1 === ExtendCustomFilterOperator.NONE;
121
+ },
122
+ mapToFilterColumn: () => null,
123
+ testMappingFilterColumn: (filterColumn) => {
124
+ if (!filterColumn.customFilters && !filterColumn.filters) return {};
125
+ return false;
126
+ }
127
+ };
128
+ const ALL_CONDITIONS = _FilterConditionItems.ALL_CONDITIONS = [
129
+ NONE,
130
+ _FilterConditionItems.EMPTY = {
131
+ label: "sheets-filter.conditions.empty",
132
+ operator: ExtendCustomFilterOperator.EMPTY,
133
+ order: OperatorOrder.SECOND,
134
+ numOfParameters: 0,
135
+ getDefaultFormParams: () => {
136
+ throw new Error("[FilterConditionItems.EMPTY]: should not have initial form params!");
137
+ },
138
+ testMappingParams: ({ operator1 }) => operator1 === ExtendCustomFilterOperator.EMPTY,
139
+ mapToFilterColumn: () => ({ customFilters: { customFilters: [{ val: "" }] } }),
140
+ testMappingFilterColumn: (filterColumn) => {
141
+ var _filterColumn$customF;
142
+ if (((_filterColumn$customF = filterColumn.customFilters) === null || _filterColumn$customF === void 0 ? void 0 : _filterColumn$customF.customFilters.length) !== 1) return false;
143
+ const firstCustomFilter = filterColumn.customFilters.customFilters[0];
144
+ if (!(firstCustomFilter.val === "" && firstCustomFilter.operator === void 0)) return false;
145
+ return { operator1: ExtendCustomFilterOperator.EMPTY };
146
+ }
147
+ },
148
+ _FilterConditionItems.NOT_EMPTY = {
149
+ label: "sheets-filter.conditions.not-empty",
150
+ operator: ExtendCustomFilterOperator.NOT_EMPTY,
151
+ order: OperatorOrder.SECOND,
152
+ numOfParameters: 0,
153
+ getDefaultFormParams: () => {
154
+ throw new Error("[FilterConditionItems.NOT_EMPTY]: should not have initial form params!");
155
+ },
156
+ testMappingParams: ({ operator1 }) => operator1 === ExtendCustomFilterOperator.NOT_EMPTY,
157
+ mapToFilterColumn: () => ({ customFilters: { customFilters: [{
158
+ val: "",
159
+ operator: CustomFilterOperator.NOT_EQUALS
160
+ }] } }),
161
+ testMappingFilterColumn: (filterColumn) => {
162
+ var _filterColumn$customF2;
163
+ if (((_filterColumn$customF2 = filterColumn.customFilters) === null || _filterColumn$customF2 === void 0 ? void 0 : _filterColumn$customF2.customFilters.length) !== 1) return false;
164
+ const firstCustomFilter = filterColumn.customFilters.customFilters[0];
165
+ if (!(firstCustomFilter.val === " " && firstCustomFilter.operator === CustomFilterOperator.NOT_EQUALS)) return false;
166
+ return { operator1: ExtendCustomFilterOperator.NOT_EMPTY };
167
+ }
168
+ },
169
+ _FilterConditionItems.TEXT_CONTAINS = {
170
+ label: "sheets-filter.conditions.text-contains",
171
+ operator: ExtendCustomFilterOperator.CONTAINS,
172
+ order: OperatorOrder.FIRST,
173
+ numOfParameters: 1,
174
+ getDefaultFormParams: () => ({
175
+ operator1: ExtendCustomFilterOperator.CONTAINS,
176
+ val1: ""
177
+ }),
178
+ testMappingParams: (params) => {
179
+ const [op] = getOnlyOperatorAndVal(params);
180
+ return op === ExtendCustomFilterOperator.CONTAINS;
181
+ },
182
+ mapToFilterColumn: (mapParams) => {
183
+ const { val1 } = mapParams;
184
+ if (val1 === "") return null;
185
+ return { customFilters: { customFilters: [{ val: `*${val1}*` }] } };
186
+ },
187
+ testMappingFilterColumn: (filterColumn) => {
188
+ var _filterColumn$customF3;
189
+ if (((_filterColumn$customF3 = filterColumn.customFilters) === null || _filterColumn$customF3 === void 0 ? void 0 : _filterColumn$customF3.customFilters.length) !== 1) return false;
190
+ const firstCustomFilter = filterColumn.customFilters.customFilters[0];
191
+ const valAsString = firstCustomFilter.val.toString();
192
+ if (!firstCustomFilter.operator && valAsString.startsWith("*") && valAsString.endsWith("*")) return {
193
+ operator1: ExtendCustomFilterOperator.CONTAINS,
194
+ val1: valAsString.slice(1, -1)
195
+ };
196
+ return false;
197
+ }
198
+ },
199
+ _FilterConditionItems.DOES_NOT_CONTAIN = {
200
+ label: "sheets-filter.conditions.does-not-contain",
201
+ operator: ExtendCustomFilterOperator.DOES_NOT_CONTAIN,
202
+ order: OperatorOrder.FIRST,
203
+ numOfParameters: 1,
204
+ getDefaultFormParams: () => ({
205
+ operator1: ExtendCustomFilterOperator.DOES_NOT_CONTAIN,
206
+ val1: ""
207
+ }),
208
+ mapToFilterColumn: (mapParams) => ({ customFilters: { customFilters: [{
209
+ val: `*${mapParams.val1}*`,
210
+ operator: CustomFilterOperator.NOT_EQUALS
211
+ }] } }),
212
+ testMappingParams: (params) => {
213
+ const [op] = getOnlyOperatorAndVal(params);
214
+ return op === ExtendCustomFilterOperator.DOES_NOT_CONTAIN;
215
+ },
216
+ testMappingFilterColumn: (filterColumn) => {
217
+ var _filterColumn$customF4;
218
+ if (((_filterColumn$customF4 = filterColumn.customFilters) === null || _filterColumn$customF4 === void 0 ? void 0 : _filterColumn$customF4.customFilters.length) !== 1) return false;
219
+ const firstCustomFilter = filterColumn.customFilters.customFilters[0];
220
+ const valAsString = firstCustomFilter.val.toString();
221
+ if (firstCustomFilter.operator === CustomFilterOperator.NOT_EQUALS && valAsString.startsWith("*") && valAsString.endsWith("*")) return {
222
+ operator1: ExtendCustomFilterOperator.DOES_NOT_CONTAIN,
223
+ val1: valAsString.slice(1, -1)
224
+ };
225
+ return false;
226
+ }
227
+ },
228
+ _FilterConditionItems.STARTS_WITH = {
229
+ label: "sheets-filter.conditions.starts-with",
230
+ operator: ExtendCustomFilterOperator.STARTS_WITH,
231
+ order: OperatorOrder.FIRST,
232
+ numOfParameters: 1,
233
+ getDefaultFormParams: () => ({
234
+ operator1: ExtendCustomFilterOperator.STARTS_WITH,
235
+ val1: ""
236
+ }),
237
+ mapToFilterColumn: (mapParams) => ({ customFilters: { customFilters: [{ val: `${mapParams.val1}*` }] } }),
238
+ testMappingParams: (params) => {
239
+ const [op] = getOnlyOperatorAndVal(params);
240
+ return op === ExtendCustomFilterOperator.STARTS_WITH;
241
+ },
242
+ testMappingFilterColumn: (filterColumn) => {
243
+ var _filterColumn$customF5;
244
+ if (((_filterColumn$customF5 = filterColumn.customFilters) === null || _filterColumn$customF5 === void 0 ? void 0 : _filterColumn$customF5.customFilters.length) !== 1) return false;
245
+ const firstCustomFilter = filterColumn.customFilters.customFilters[0];
246
+ const valAsString = firstCustomFilter.val.toString();
247
+ if (!firstCustomFilter.operator && valAsString.endsWith("*") && !valAsString.startsWith("*")) return {
248
+ operator1: ExtendCustomFilterOperator.STARTS_WITH,
249
+ val1: valAsString.slice(0, -1)
250
+ };
251
+ return false;
252
+ }
253
+ },
254
+ _FilterConditionItems.ENDS_WITH = {
255
+ label: "sheets-filter.conditions.ends-with",
256
+ operator: ExtendCustomFilterOperator.ENDS_WITH,
257
+ order: OperatorOrder.FIRST,
258
+ numOfParameters: 1,
259
+ getDefaultFormParams: () => ({
260
+ operator1: ExtendCustomFilterOperator.ENDS_WITH,
261
+ val1: ""
262
+ }),
263
+ mapToFilterColumn: (mapParams) => ({ customFilters: { customFilters: [{ val: `*${mapParams.val1}` }] } }),
264
+ testMappingParams: (params) => {
265
+ const [op] = getOnlyOperatorAndVal(params);
266
+ return op === ExtendCustomFilterOperator.ENDS_WITH;
267
+ },
268
+ testMappingFilterColumn: (filterColumn) => {
269
+ var _filterColumn$customF6;
270
+ if (((_filterColumn$customF6 = filterColumn.customFilters) === null || _filterColumn$customF6 === void 0 ? void 0 : _filterColumn$customF6.customFilters.length) !== 1) return false;
271
+ const firstCustomFilter = filterColumn.customFilters.customFilters[0];
272
+ const valAsString = firstCustomFilter.val.toString();
273
+ if (!firstCustomFilter.operator && valAsString.startsWith("*") && !valAsString.endsWith("*")) return {
274
+ operator1: ExtendCustomFilterOperator.ENDS_WITH,
275
+ val1: valAsString.slice(1)
276
+ };
277
+ return false;
278
+ }
279
+ },
280
+ _FilterConditionItems.EQUALS = {
281
+ label: "sheets-filter.conditions.equals",
282
+ operator: ExtendCustomFilterOperator.EQUALS,
283
+ order: OperatorOrder.FIRST,
284
+ numOfParameters: 1,
285
+ getDefaultFormParams: () => ({
286
+ operator1: ExtendCustomFilterOperator.EQUALS,
287
+ val1: ""
288
+ }),
289
+ testMappingParams: (params) => {
290
+ const [op] = getOnlyOperatorAndVal(params);
291
+ return op === ExtendCustomFilterOperator.EQUALS;
292
+ },
293
+ mapToFilterColumn: (mapParams) => {
294
+ const { val1 } = mapParams;
295
+ if (val1 === "") return null;
296
+ return { customFilters: { customFilters: [{ val: val1 }] } };
297
+ },
298
+ testMappingFilterColumn: (filterColumn) => {
299
+ var _filterColumn$filters, _filterColumn$customF7;
300
+ if (((_filterColumn$filters = filterColumn.filters) === null || _filterColumn$filters === void 0 || (_filterColumn$filters = _filterColumn$filters.filters) === null || _filterColumn$filters === void 0 ? void 0 : _filterColumn$filters.length) === 1) return {
301
+ operator1: ExtendCustomFilterOperator.EQUALS,
302
+ val1: ""
303
+ };
304
+ if (((_filterColumn$customF7 = filterColumn.customFilters) === null || _filterColumn$customF7 === void 0 ? void 0 : _filterColumn$customF7.customFilters.length) === 1 && !filterColumn.customFilters.customFilters[0].operator) return {
305
+ operator1: ExtendCustomFilterOperator.EQUALS,
306
+ val1: filterColumn.customFilters.customFilters[0].val.toString()
307
+ };
308
+ return false;
309
+ }
310
+ },
311
+ _FilterConditionItems.GREATER_THAN = {
312
+ label: "sheets-filter.conditions.greater-than",
313
+ operator: CustomFilterOperator.GREATER_THAN,
314
+ numOfParameters: 1,
315
+ order: OperatorOrder.FIRST,
316
+ getDefaultFormParams: () => ({
317
+ operator1: CustomFilterOperator.GREATER_THAN,
318
+ val1: ""
319
+ }),
320
+ mapToFilterColumn: (mapParams) => ({ customFilters: { customFilters: [{
321
+ val: mapParams.val1,
322
+ operator: CustomFilterOperator.GREATER_THAN
323
+ }] } }),
324
+ testMappingParams: (params) => {
325
+ const [op] = getOnlyOperatorAndVal(params);
326
+ return op === CustomFilterOperator.GREATER_THAN;
327
+ },
328
+ testMappingFilterColumn: (filterColumn) => {
329
+ var _filterColumn$customF8;
330
+ if (((_filterColumn$customF8 = filterColumn.customFilters) === null || _filterColumn$customF8 === void 0 ? void 0 : _filterColumn$customF8.customFilters.length) !== 1) return false;
331
+ const firstCustomFilter = filterColumn.customFilters.customFilters[0];
332
+ if (firstCustomFilter.operator !== CustomFilterOperator.GREATER_THAN) return false;
333
+ return {
334
+ operator1: CustomFilterOperator.GREATER_THAN,
335
+ val1: firstCustomFilter.val.toString()
336
+ };
337
+ }
338
+ },
339
+ _FilterConditionItems.GREATER_THAN_OR_EQUAL = {
340
+ label: "sheets-filter.conditions.greater-than-or-equal",
341
+ operator: CustomFilterOperator.GREATER_THAN_OR_EQUAL,
342
+ numOfParameters: 1,
343
+ order: OperatorOrder.FIRST,
344
+ getDefaultFormParams: () => ({
345
+ operator1: CustomFilterOperator.GREATER_THAN_OR_EQUAL,
346
+ val1: ""
347
+ }),
348
+ testMappingParams: (params) => {
349
+ const [op] = getOnlyOperatorAndVal(params);
350
+ return op === CustomFilterOperator.GREATER_THAN_OR_EQUAL;
351
+ },
352
+ mapToFilterColumn: (mapParams) => ({ customFilters: { customFilters: [{
353
+ val: mapParams.val1,
354
+ operator: CustomFilterOperator.GREATER_THAN_OR_EQUAL
355
+ }] } }),
356
+ testMappingFilterColumn: (filterColumn) => {
357
+ var _filterColumn$customF9;
358
+ if (((_filterColumn$customF9 = filterColumn.customFilters) === null || _filterColumn$customF9 === void 0 ? void 0 : _filterColumn$customF9.customFilters.length) !== 1) return false;
359
+ const firstCustomFilter = filterColumn.customFilters.customFilters[0];
360
+ if (firstCustomFilter.operator !== CustomFilterOperator.GREATER_THAN_OR_EQUAL) return false;
361
+ return {
362
+ operator1: CustomFilterOperator.GREATER_THAN_OR_EQUAL,
363
+ val1: firstCustomFilter.val.toString()
364
+ };
365
+ }
366
+ },
367
+ _FilterConditionItems.LESS_THAN = {
368
+ label: "sheets-filter.conditions.less-than",
369
+ operator: CustomFilterOperator.LESS_THAN,
370
+ numOfParameters: 1,
371
+ order: OperatorOrder.FIRST,
372
+ getDefaultFormParams: () => ({
373
+ operator1: CustomFilterOperator.LESS_THAN,
374
+ val1: ""
375
+ }),
376
+ testMappingParams: (params) => {
377
+ const [op] = getOnlyOperatorAndVal(params);
378
+ return op === CustomFilterOperator.LESS_THAN;
379
+ },
380
+ mapToFilterColumn: (mapParams) => ({ customFilters: { customFilters: [{
381
+ val: mapParams.val1,
382
+ operator: CustomFilterOperator.LESS_THAN
383
+ }] } }),
384
+ testMappingFilterColumn: (filterColumn) => {
385
+ var _filterColumn$customF10;
386
+ if (((_filterColumn$customF10 = filterColumn.customFilters) === null || _filterColumn$customF10 === void 0 ? void 0 : _filterColumn$customF10.customFilters.length) !== 1) return false;
387
+ const firstCustomFilter = filterColumn.customFilters.customFilters[0];
388
+ if (firstCustomFilter.operator !== CustomFilterOperator.LESS_THAN) return false;
389
+ return {
390
+ operator1: CustomFilterOperator.LESS_THAN,
391
+ val1: firstCustomFilter.val.toString()
392
+ };
393
+ }
394
+ },
395
+ _FilterConditionItems.LESS_THAN_OR_EQUAL = {
396
+ label: "sheets-filter.conditions.less-than-or-equal",
397
+ operator: CustomFilterOperator.LESS_THAN_OR_EQUAL,
398
+ numOfParameters: 1,
399
+ order: OperatorOrder.FIRST,
400
+ getDefaultFormParams: () => ({
401
+ operator1: CustomFilterOperator.LESS_THAN_OR_EQUAL,
402
+ val1: ""
403
+ }),
404
+ testMappingParams: (params) => {
405
+ const [op] = getOnlyOperatorAndVal(params);
406
+ return op === CustomFilterOperator.LESS_THAN_OR_EQUAL;
407
+ },
408
+ mapToFilterColumn: (mapParams) => ({ customFilters: { customFilters: [{
409
+ val: mapParams.val1,
410
+ operator: CustomFilterOperator.LESS_THAN_OR_EQUAL
411
+ }] } }),
412
+ testMappingFilterColumn: (filterColumn) => {
413
+ var _filterColumn$customF11;
414
+ if (((_filterColumn$customF11 = filterColumn.customFilters) === null || _filterColumn$customF11 === void 0 ? void 0 : _filterColumn$customF11.customFilters.length) !== 1) return false;
415
+ const firstCustomFilter = filterColumn.customFilters.customFilters[0];
416
+ if (firstCustomFilter.operator !== CustomFilterOperator.LESS_THAN_OR_EQUAL) return false;
417
+ return {
418
+ operator1: CustomFilterOperator.LESS_THAN_OR_EQUAL,
419
+ val1: firstCustomFilter.val.toString()
420
+ };
421
+ }
422
+ },
423
+ _FilterConditionItems.EQUAL = {
424
+ label: "sheets-filter.conditions.equal",
425
+ operator: CustomFilterOperator.EQUAL,
426
+ numOfParameters: 1,
427
+ order: OperatorOrder.FIRST,
428
+ getDefaultFormParams: () => ({
429
+ operator1: CustomFilterOperator.EQUAL,
430
+ val1: ""
431
+ }),
432
+ testMappingParams: (params) => {
433
+ const [op] = getOnlyOperatorAndVal(params);
434
+ return op === CustomFilterOperator.EQUAL;
435
+ },
436
+ mapToFilterColumn: (mapParams) => ({ customFilters: { customFilters: [{
437
+ val: mapParams.val1,
438
+ operator: CustomFilterOperator.EQUAL
439
+ }] } }),
440
+ testMappingFilterColumn: (filterColumn) => {
441
+ var _filterColumn$customF12;
442
+ if (((_filterColumn$customF12 = filterColumn.customFilters) === null || _filterColumn$customF12 === void 0 ? void 0 : _filterColumn$customF12.customFilters.length) !== 1) return false;
443
+ const firstCustomFilter = filterColumn.customFilters.customFilters[0];
444
+ if (firstCustomFilter.operator !== CustomFilterOperator.EQUAL) return false;
445
+ return {
446
+ operator1: CustomFilterOperator.EQUAL,
447
+ val1: firstCustomFilter.val.toString()
448
+ };
449
+ }
450
+ },
451
+ _FilterConditionItems.NOT_EQUAL = {
452
+ label: "sheets-filter.conditions.not-equal",
453
+ operator: CustomFilterOperator.NOT_EQUALS,
454
+ numOfParameters: 1,
455
+ order: OperatorOrder.FIRST,
456
+ getDefaultFormParams: () => ({
457
+ operator1: CustomFilterOperator.NOT_EQUALS,
458
+ val1: ""
459
+ }),
460
+ testMappingParams: (params) => {
461
+ const [op] = getOnlyOperatorAndVal(params);
462
+ return op === CustomFilterOperator.NOT_EQUALS;
463
+ },
464
+ mapToFilterColumn: (mapParams) => ({ customFilters: { customFilters: [{
465
+ val: mapParams.val1,
466
+ operator: CustomFilterOperator.NOT_EQUALS
467
+ }] } }),
468
+ testMappingFilterColumn: (filterColumn) => {
469
+ var _filterColumn$customF13;
470
+ if (((_filterColumn$customF13 = filterColumn.customFilters) === null || _filterColumn$customF13 === void 0 ? void 0 : _filterColumn$customF13.customFilters.length) !== 1) return false;
471
+ const firstCustomFilter = filterColumn.customFilters.customFilters[0];
472
+ if (firstCustomFilter.operator !== CustomFilterOperator.NOT_EQUALS) return false;
473
+ return {
474
+ operator1: CustomFilterOperator.NOT_EQUALS,
475
+ val1: firstCustomFilter.val.toString()
476
+ };
477
+ }
478
+ },
479
+ _FilterConditionItems.BETWEEN = {
480
+ label: "sheets-filter.conditions.between",
481
+ operator: ExtendCustomFilterOperator.BETWEEN,
482
+ order: OperatorOrder.SECOND,
483
+ numOfParameters: 2,
484
+ getDefaultFormParams: () => ({
485
+ and: true,
486
+ operator1: CustomFilterOperator.GREATER_THAN_OR_EQUAL,
487
+ val1: "",
488
+ operator2: CustomFilterOperator.LESS_THAN_OR_EQUAL,
489
+ val2: ""
490
+ }),
491
+ testMappingParams: (params) => {
492
+ const { and, operator1, operator2 } = params;
493
+ if (!and) return false;
494
+ const operators = [operator1, operator2];
495
+ return operators.includes(CustomFilterOperator.GREATER_THAN_OR_EQUAL) && operators.includes(CustomFilterOperator.LESS_THAN_OR_EQUAL);
496
+ },
497
+ mapToFilterColumn: (mapParams) => {
498
+ const { val1, val2, operator1 } = mapParams;
499
+ const operator1IsGreater = operator1 === CustomFilterOperator.GREATER_THAN_OR_EQUAL;
500
+ return { customFilters: {
501
+ and: BooleanNumber.TRUE,
502
+ customFilters: [{
503
+ val: operator1IsGreater ? val1 : val2,
504
+ operator: CustomFilterOperator.GREATER_THAN_OR_EQUAL
505
+ }, {
506
+ val: operator1IsGreater ? val2 : val1,
507
+ operator: CustomFilterOperator.LESS_THAN_OR_EQUAL
508
+ }]
509
+ } };
510
+ },
511
+ testMappingFilterColumn: (filterColumn) => {
512
+ var _filterColumn$customF14;
513
+ if (((_filterColumn$customF14 = filterColumn.customFilters) === null || _filterColumn$customF14 === void 0 ? void 0 : _filterColumn$customF14.customFilters.length) !== 2) return false;
514
+ const [firstCustomFilter, secondCustomFilter] = filterColumn.customFilters.customFilters;
515
+ if (firstCustomFilter.operator === CustomFilterOperator.GREATER_THAN_OR_EQUAL && secondCustomFilter.operator === CustomFilterOperator.LESS_THAN_OR_EQUAL && filterColumn.customFilters.and) return {
516
+ and: true,
517
+ operator1: CustomFilterOperator.GREATER_THAN_OR_EQUAL,
518
+ val1: firstCustomFilter.val.toString(),
519
+ operator2: CustomFilterOperator.LESS_THAN_OR_EQUAL,
520
+ val2: secondCustomFilter.val.toString()
521
+ };
522
+ if (secondCustomFilter.operator === CustomFilterOperator.GREATER_THAN_OR_EQUAL && firstCustomFilter.operator === CustomFilterOperator.LESS_THAN_OR_EQUAL && filterColumn.customFilters.and) return {
523
+ and: true,
524
+ operator1: CustomFilterOperator.GREATER_THAN_OR_EQUAL,
525
+ val1: secondCustomFilter.val.toString(),
526
+ operator2: CustomFilterOperator.LESS_THAN_OR_EQUAL,
527
+ val2: firstCustomFilter.val.toLocaleString()
528
+ };
529
+ return false;
530
+ }
531
+ },
532
+ _FilterConditionItems.NOT_BETWEEN = {
533
+ label: "sheets-filter.conditions.not-between",
534
+ operator: ExtendCustomFilterOperator.NOT_BETWEEN,
535
+ order: OperatorOrder.SECOND,
536
+ numOfParameters: 2,
537
+ getDefaultFormParams: () => ({
538
+ operator1: CustomFilterOperator.LESS_THAN,
539
+ val1: "",
540
+ operator2: CustomFilterOperator.GREATER_THAN,
541
+ val2: ""
542
+ }),
543
+ testMappingParams: (params) => {
544
+ const { and, operator1, operator2 } = params;
545
+ if (and) return false;
546
+ const operators = [operator1, operator2];
547
+ return operators.includes(CustomFilterOperator.GREATER_THAN) && operators.includes(CustomFilterOperator.LESS_THAN);
548
+ },
549
+ mapToFilterColumn: (mapParams) => {
550
+ const { val1, val2, operator1 } = mapParams;
551
+ const operator1IsGreater = operator1 === CustomFilterOperator.GREATER_THAN;
552
+ return { customFilters: { customFilters: [{
553
+ val: operator1IsGreater ? val1 : val2,
554
+ operator: CustomFilterOperator.GREATER_THAN
555
+ }, {
556
+ val: operator1IsGreater ? val2 : val1,
557
+ operator: CustomFilterOperator.LESS_THAN
558
+ }] } };
559
+ },
560
+ testMappingFilterColumn: (filterColumn) => {
561
+ var _filterColumn$customF15;
562
+ if (((_filterColumn$customF15 = filterColumn.customFilters) === null || _filterColumn$customF15 === void 0 ? void 0 : _filterColumn$customF15.customFilters.length) !== 2) return false;
563
+ const [firstCustomFilter, secondCustomFilter] = filterColumn.customFilters.customFilters;
564
+ if (firstCustomFilter.operator === CustomFilterOperator.LESS_THAN && secondCustomFilter.operator === CustomFilterOperator.GREATER_THAN && !filterColumn.customFilters.and) return {
565
+ operator1: CustomFilterOperator.LESS_THAN,
566
+ val1: firstCustomFilter.val.toString(),
567
+ operator2: CustomFilterOperator.GREATER_THAN,
568
+ val2: secondCustomFilter.val.toString()
569
+ };
570
+ if (secondCustomFilter.operator === CustomFilterOperator.LESS_THAN && firstCustomFilter.operator === CustomFilterOperator.GREATER_THAN && !filterColumn.customFilters.and) return {
571
+ operator1: CustomFilterOperator.GREATER_THAN,
572
+ val1: secondCustomFilter.val.toString(),
573
+ operator2: CustomFilterOperator.LESS_THAN,
574
+ val2: firstCustomFilter.val.toLocaleString()
575
+ };
576
+ return false;
577
+ }
578
+ },
579
+ _FilterConditionItems.CUSTOM = {
580
+ label: "sheets-filter.conditions.custom",
581
+ operator: ExtendCustomFilterOperator.CUSTOM,
582
+ order: OperatorOrder.SECOND,
583
+ numOfParameters: 2,
584
+ getDefaultFormParams: () => {
585
+ return {
586
+ operator1: ExtendCustomFilterOperator.NONE,
587
+ val1: "",
588
+ operator2: ExtendCustomFilterOperator.NONE,
589
+ val2: ""
590
+ };
591
+ },
592
+ testMappingParams: () => true,
593
+ mapToFilterColumn: (mapParams) => {
594
+ const { and, val1, val2, operator1, operator2 } = mapParams;
595
+ function mapOperator(operator, val) {
596
+ for (const condition of ALL_CONDITIONS) if (condition.operator === operator) return condition.mapToFilterColumn({
597
+ val1: val,
598
+ operator1: operator
599
+ });
600
+ }
601
+ const operator1IsNone = !operator1 || operator1 === FilterConditionItems.NONE.operator;
602
+ const operator2IsNone = !operator2 || operator2 === FilterConditionItems.NONE.operator;
603
+ if (operator1IsNone && operator2IsNone) return NONE.mapToFilterColumn({});
604
+ if (operator1IsNone) return mapOperator(operator2, val2);
605
+ if (operator2IsNone) return mapOperator(operator1, val1);
606
+ const mappedCustomFilter1 = mapOperator(operator1, val1);
607
+ const mappedCustomFilter2 = mapOperator(operator2, val2);
608
+ const customFilters = { customFilters: [mappedCustomFilter1.customFilters.customFilters[0], mappedCustomFilter2.customFilters.customFilters[0]] };
609
+ if (and) customFilters.and = BooleanNumber.TRUE;
610
+ return { customFilters };
611
+ },
612
+ testMappingFilterColumn: (filterColumn) => {
613
+ var _filterColumn$customF16;
614
+ if (((_filterColumn$customF16 = filterColumn.customFilters) === null || _filterColumn$customF16 === void 0 ? void 0 : _filterColumn$customF16.customFilters.length) !== 2) return false;
615
+ const params = filterColumn.customFilters.customFilters.map((customFilter) => {
616
+ return testMappingFilterColumn({ customFilters: { customFilters: [customFilter] } });
617
+ });
618
+ const result = {
619
+ operator1: params[0][0].operator,
620
+ val1: params[0][1].val1,
621
+ operator2: params[1][0].operator,
622
+ val2: params[1][1].val1
623
+ };
624
+ if (filterColumn.customFilters.and) result.and = true;
625
+ return result;
626
+ }
627
+ }
628
+ ];
629
+ function getItemByOperator(operator) {
630
+ const item = ALL_CONDITIONS.find((condition) => condition.operator === operator);
631
+ if (!item) throw new Error(`[SheetsFilter]: no condition item found for operator: ${operator}`);
632
+ return item;
633
+ }
634
+ _FilterConditionItems.getItemByOperator = getItemByOperator;
635
+ function testMappingParams(mapParams, numOfParameters) {
636
+ for (const condition of ALL_CONDITIONS.filter((condition) => condition.numOfParameters === numOfParameters)) if (condition.numOfParameters !== 0 && condition.testMappingParams(mapParams)) return condition;
637
+ for (const condition of ALL_CONDITIONS) if (condition.testMappingParams(mapParams)) return condition;
638
+ throw new Error("[SheetsFilter]: no condition item can be mapped from the filter map params!");
639
+ }
640
+ _FilterConditionItems.testMappingParams = testMappingParams;
641
+ function getInitialFormParams(operator) {
642
+ const condition = ALL_CONDITIONS.find((condition) => condition.operator === operator);
643
+ if ((condition === null || condition === void 0 ? void 0 : condition.numOfParameters) === 0) return { operator1: condition.operator };
644
+ return condition.getDefaultFormParams();
645
+ }
646
+ _FilterConditionItems.getInitialFormParams = getInitialFormParams;
647
+ function mapToFilterColumn(condition, mapParams) {
648
+ return condition.mapToFilterColumn(mapParams);
649
+ }
650
+ _FilterConditionItems.mapToFilterColumn = mapToFilterColumn;
651
+ function testMappingFilterColumn(filterColumn) {
652
+ if (!filterColumn) return [NONE, {}];
653
+ for (const condition of ALL_CONDITIONS) {
654
+ const mapParams = condition.testMappingFilterColumn(filterColumn);
655
+ if (mapParams) return [condition, mapParams];
656
+ }
657
+ return [NONE, {}];
658
+ }
659
+ _FilterConditionItems.testMappingFilterColumn = testMappingFilterColumn;
660
+ })(FilterConditionItems || (FilterConditionItems = {}));
661
+ function getOnlyOperatorAndVal(mapParams) {
662
+ const { operator1, operator2, val1, val2 } = mapParams;
663
+ if (operator1 && operator2) throw new Error("Both operator1 and operator2 are set!");
664
+ if (!operator1 && !operator2) throw new Error("Neither operator1 and operator2 and both not set!");
665
+ return operator1 ? [operator1, val1] : [operator2, val2];
666
+ }
667
+
668
+ //#endregion
669
+ //#region src/models/utils.ts
670
+ function statisticFilterByValueItems(items) {
671
+ const checkedItems = [];
672
+ const uncheckedItems = [];
673
+ let checked = 0;
674
+ let unchecked = 0;
675
+ function traverse(node) {
676
+ if (node.leaf) if (node.checked) {
677
+ checkedItems.push(node);
678
+ checked += node.count;
679
+ } else {
680
+ uncheckedItems.push(node);
681
+ unchecked += node.count;
682
+ }
683
+ if (node.children) node.children.forEach(traverse);
684
+ }
685
+ items.forEach(traverse);
686
+ return {
687
+ checkedItems,
688
+ uncheckedItems,
689
+ checked,
690
+ unchecked
691
+ };
692
+ }
693
+
694
+ //#endregion
695
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
696
+ function __decorateParam(paramIndex, decorator) {
697
+ return function(target, key) {
698
+ decorator(target, key, paramIndex);
699
+ };
700
+ }
701
+
702
+ //#endregion
703
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
704
+ function __decorate(decorators, target, key, desc) {
705
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
706
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
707
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
708
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
709
+ }
710
+
711
+ //#endregion
712
+ //#region src/worker/generate-filter-values.service.ts
713
+ const SHEETS_GENERATE_FILTER_VALUES_SERVICE_NAME = "sheets-filter.generate-filter-values.service";
714
+ const ISheetsGenerateFilterValuesService = createIdentifier(SHEETS_GENERATE_FILTER_VALUES_SERVICE_NAME);
715
+ let SheetsGenerateFilterValuesService = class SheetsGenerateFilterValuesService extends Disposable {
716
+ constructor(_localeService, _univerInstanceService, _logService) {
717
+ super();
718
+ this._localeService = _localeService;
719
+ this._univerInstanceService = _univerInstanceService;
720
+ this._logService = _logService;
721
+ }
722
+ async getFilterValues(params) {
723
+ var _this$_univerInstance;
724
+ const { unitId, subUnitId, filteredOutRowsByOtherColumns, filterColumn, filters, blankChecked, iterateRange, alreadyChecked } = params;
725
+ const workbook = this._univerInstanceService.getUnit(unitId);
726
+ const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
727
+ if (!workbook || !worksheet) return [];
728
+ this._logService.debug("[SheetsGenerateFilterValuesService]", "getFilterValues for", {
729
+ unitId,
730
+ subUnitId
731
+ });
732
+ return getFilterTreeByValueItems(filters, this._localeService, iterateRange, worksheet, new Set(filteredOutRowsByOtherColumns), filterColumn, new Set(alreadyChecked.map(String)), blankChecked, workbook.getStyles());
733
+ }
734
+ };
735
+ SheetsGenerateFilterValuesService = __decorate([
736
+ __decorateParam(0, Inject(LocaleService)),
737
+ __decorateParam(1, IUniverInstanceService),
738
+ __decorateParam(2, ILogService)
739
+ ], SheetsGenerateFilterValuesService);
740
+ function getFilterTreeByValueItems(filters, localeService, iterateRange, worksheet, filteredOutRowsByOtherColumns, filterColumn, alreadyChecked, blankChecked, styles) {
741
+ var _filterColumn$filtere;
742
+ const items = /* @__PURE__ */ new Map();
743
+ const treeMap = /* @__PURE__ */ new Map();
744
+ const DefaultPattern = "yyyy-mm-dd";
745
+ const EmptyKey = "empty";
746
+ const isNeedClearCheckedStatus = !filters && ((filterColumn === null || filterColumn === void 0 ? void 0 : filterColumn.filterBy) === FilterBy.COLORS || (filterColumn === null || filterColumn === void 0 ? void 0 : filterColumn.filterBy) === FilterBy.CONDITIONS) && ((_filterColumn$filtere = filterColumn.filteredOutRows) === null || _filterColumn$filtere === void 0 ? void 0 : _filterColumn$filtere.size);
747
+ let emptyCount = 0;
748
+ for (const cell of worksheet.iterateByColumn(iterateRange, false, false)) {
749
+ const { row, rowSpan = 1 } = cell;
750
+ let rowIndex = 0;
751
+ while (rowIndex < rowSpan) {
752
+ var _cell$value, _styles$get, _cell$value2;
753
+ const targetRow = row + rowIndex;
754
+ if (filteredOutRowsByOtherColumns.has(targetRow)) {
755
+ rowIndex++;
756
+ continue;
757
+ }
758
+ const value = (cell === null || cell === void 0 ? void 0 : cell.value) ? extractPureTextFromCell(cell.value) : "";
759
+ if (!value) {
760
+ emptyCount += 1;
761
+ rowIndex += rowSpan;
762
+ continue;
763
+ }
764
+ const fmtStr = ((_cell$value = cell.value) === null || _cell$value === void 0 ? void 0 : _cell$value.v) && !cell.value.p ? (_styles$get = styles.get((_cell$value2 = cell.value) === null || _cell$value2 === void 0 ? void 0 : _cell$value2.s)) === null || _styles$get === void 0 || (_styles$get = _styles$get.n) === null || _styles$get === void 0 ? void 0 : _styles$get.pattern : "";
765
+ const isDateValue = fmtStr && numfmt.getFormatInfo(fmtStr).isDate;
766
+ let isIncludeDatePart = false;
767
+ if (isDateValue) {
768
+ const { year, month, day } = numfmt.getFormatDateInfo(fmtStr);
769
+ isIncludeDatePart = year || month || day;
770
+ }
771
+ if (fmtStr && isDateValue && isIncludeDatePart) {
772
+ var _worksheet$getCellRaw, _yearItem$children, _monthItem$children;
773
+ const originValue = (_worksheet$getCellRaw = worksheet.getCellRaw(cell.row, cell.col)) === null || _worksheet$getCellRaw === void 0 ? void 0 : _worksheet$getCellRaw.v;
774
+ if (!originValue) {
775
+ rowIndex++;
776
+ continue;
777
+ }
778
+ const [year, month, day] = numfmt.format(DefaultPattern, Number(originValue)).split("-").map(Number);
779
+ let yearItem = items.get(`${year}`);
780
+ if (!yearItem) {
781
+ yearItem = {
782
+ title: `${year}`,
783
+ key: `${year}`,
784
+ children: [],
785
+ count: 0,
786
+ leaf: false,
787
+ checked: false
788
+ };
789
+ items.set(`${year}`, yearItem);
790
+ treeMap.set(`${year}`, [`${year}`]);
791
+ }
792
+ let monthItem = (_yearItem$children = yearItem.children) === null || _yearItem$children === void 0 ? void 0 : _yearItem$children.find((item) => item.key === `${year}-${month}`);
793
+ if (!monthItem) {
794
+ var _yearItem$children2;
795
+ monthItem = {
796
+ title: localeService.t(`sheets-filter.date.${month}`),
797
+ key: `${year}-${month}`,
798
+ children: [],
799
+ count: 0,
800
+ leaf: false,
801
+ checked: false
802
+ };
803
+ (_yearItem$children2 = yearItem.children) === null || _yearItem$children2 === void 0 || _yearItem$children2.push(monthItem);
804
+ treeMap.set(`${year}-${month}`, [`${year}`, `${year}-${month}`]);
805
+ }
806
+ const dayItem = monthItem === null || monthItem === void 0 || (_monthItem$children = monthItem.children) === null || _monthItem$children === void 0 ? void 0 : _monthItem$children.find((item) => item.key === `${year}-${month}-${day}`);
807
+ if (!dayItem) {
808
+ var _monthItem$children2;
809
+ (_monthItem$children2 = monthItem.children) === null || _monthItem$children2 === void 0 || _monthItem$children2.push({
810
+ title: `${day}`,
811
+ key: `${year}-${month}-${day}`,
812
+ count: 1,
813
+ originValues: new Set([value]),
814
+ leaf: true,
815
+ checked: isNeedClearCheckedStatus ? false : alreadyChecked.size ? alreadyChecked.has(value) : !blankChecked
816
+ });
817
+ monthItem.count++;
818
+ yearItem.count++;
819
+ treeMap.set(`${year}-${month}-${day}`, [
820
+ `${year}`,
821
+ `${year}-${month}`,
822
+ `${year}-${month}-${day}`
823
+ ]);
824
+ } else {
825
+ dayItem.originValues.add(value);
826
+ dayItem.count++;
827
+ monthItem.count++;
828
+ yearItem.count++;
829
+ }
830
+ } else {
831
+ const key = value;
832
+ let item = items.get(key);
833
+ if (!item) {
834
+ item = {
835
+ title: value,
836
+ leaf: true,
837
+ checked: isNeedClearCheckedStatus ? false : alreadyChecked.size ? alreadyChecked.has(value) : !blankChecked,
838
+ key,
839
+ count: 1
840
+ };
841
+ items.set(key, item);
842
+ treeMap.set(key, [key]);
843
+ } else item.count++;
844
+ }
845
+ rowIndex++;
846
+ }
847
+ }
848
+ const initialBlankChecked = isNeedClearCheckedStatus ? false : filters ? blankChecked : true;
849
+ if (emptyCount > 0) {
850
+ const item = {
851
+ title: localeService.t("sheets-filter.panel.empty"),
852
+ count: emptyCount,
853
+ leaf: true,
854
+ checked: initialBlankChecked,
855
+ key: EmptyKey
856
+ };
857
+ items.set("empty", item);
858
+ treeMap.set("empty", [EmptyKey]);
859
+ }
860
+ return {
861
+ filterTreeItems: generateFilterTreeBySort(Array.from(items.values())),
862
+ filterTreeMapCache: treeMap
863
+ };
864
+ }
865
+ function generateFilterTreeBySort(tree) {
866
+ return Array.from(tree).sort((a, b) => {
867
+ if (a.children && !b.children) return -1;
868
+ if (!a.children && b.children) return 1;
869
+ return compare(a.title, b.title);
870
+ }).map((yearItem) => {
871
+ if (yearItem.children) yearItem.children.sort((a, b) => {
872
+ return Number.parseInt(a.key.split("-")[1], 10) - Number.parseInt(b.key.split("-")[1], 10);
873
+ }).forEach((monthItem) => {
874
+ if (monthItem.children) monthItem.children.sort((a, b) => {
875
+ return Number.parseInt(a.key.split("-")[2], 10) - Number.parseInt(b.key.split("-")[2], 10);
876
+ });
877
+ });
878
+ return yearItem;
879
+ });
880
+ }
881
+ const isNumeric = (str) => !Number.isNaN(Number(str)) && !Number.isNaN(Number.parseFloat(str));
882
+ function compare(strA, strB) {
883
+ const aIsNumeric = isNumeric(strA);
884
+ const bIsNumeric = isNumeric(strB);
885
+ if (aIsNumeric && bIsNumeric) return Number.parseFloat(strA) - Number.parseFloat(strB);
886
+ else if (aIsNumeric && !bIsNumeric) return -1;
887
+ else if (!aIsNumeric && bIsNumeric) return 1;
888
+ else return strA.localeCompare(strB);
889
+ }
890
+
891
+ //#endregion
892
+ //#region src/services/util.ts
893
+ function findObjectByKey(data, targetKey) {
894
+ for (const node of data) {
895
+ if (node.key === targetKey) return node;
896
+ if (node.children) {
897
+ const result = findObjectByKey(node.children, targetKey);
898
+ if (result) return result;
899
+ }
900
+ }
901
+ return null;
902
+ }
903
+ function areAllLeafNodesChecked(node) {
904
+ if (node.leaf) return node.checked;
905
+ return node.children ? node.children.every((child) => areAllLeafNodesChecked(child)) : true;
906
+ }
907
+ function updateLeafNodesCheckedStatus(node, status) {
908
+ if (node.leaf) if (status !== void 0) node.checked = status;
909
+ else node.checked = !node.checked;
910
+ if (node.children) node.children.forEach((child) => updateLeafNodesCheckedStatus(child, status));
911
+ }
912
+ function searchTree(items, searchKeywords) {
913
+ const result = [];
914
+ items.forEach((item) => {
915
+ const originMatches = item.originValues ? searchKeywords.some((keyword) => Array.from(item.originValues).some((value) => value.toLowerCase().includes(keyword.toLowerCase()))) : false;
916
+ const titleMatches = !originMatches && searchKeywords.some((keyword) => item.title.toLowerCase().includes(keyword.toLowerCase()));
917
+ if (originMatches || titleMatches) result.push({ ...item });
918
+ else if (item.children) {
919
+ const filteredChildren = searchTree(item.children, searchKeywords);
920
+ if (filteredChildren.length > 0) {
921
+ const aggregatedCount = filteredChildren.reduce((sum, child) => sum + child.count, 0);
922
+ result.push({
923
+ ...item,
924
+ count: aggregatedCount,
925
+ children: filteredChildren
926
+ });
927
+ }
928
+ }
929
+ });
930
+ return result;
931
+ }
932
+
933
+ //#endregion
934
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
935
+ function _typeof(o) {
936
+ "@babel/helpers - typeof";
937
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
938
+ return typeof o;
939
+ } : function(o) {
940
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
941
+ }, _typeof(o);
942
+ }
943
+
944
+ //#endregion
945
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
946
+ function toPrimitive(t, r) {
947
+ if ("object" != _typeof(t) || !t) return t;
948
+ var e = t[Symbol.toPrimitive];
949
+ if (void 0 !== e) {
950
+ var i = e.call(t, r || "default");
951
+ if ("object" != _typeof(i)) return i;
952
+ throw new TypeError("@@toPrimitive must return a primitive value.");
953
+ }
954
+ return ("string" === r ? String : Number)(t);
955
+ }
956
+
957
+ //#endregion
958
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
959
+ function toPropertyKey(t) {
960
+ var i = toPrimitive(t, "string");
961
+ return "symbol" == _typeof(i) ? i : i + "";
962
+ }
963
+
964
+ //#endregion
965
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
966
+ function _defineProperty(e, r, t) {
967
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
968
+ value: t,
969
+ enumerable: !0,
970
+ configurable: !0,
971
+ writable: !0
972
+ }) : e[r] = t, e;
973
+ }
974
+
975
+ //#endregion
976
+ //#region src/services/sheets-filter-panel.service.ts
977
+ var _ByConditionsModel, _ByValuesModel, _ByColorsModel;
978
+ const ISheetsFilterPanelService = createIdentifier("sheets-filter-ui.sheets-filter-panel.service");
979
+ let SheetsFilterPanelService = class SheetsFilterPanelService extends Disposable {
980
+ get filterBy() {
981
+ return this._filterBy$.getValue();
982
+ }
983
+ get filterByModel() {
984
+ return this._filterByModel;
985
+ }
986
+ set filterByModel(model) {
987
+ this._filterByModel = model;
988
+ this._filterByModel$.next(model);
989
+ }
990
+ get filterModel() {
991
+ return this._filterModel;
992
+ }
993
+ get col() {
994
+ return this._col$.getValue();
995
+ }
996
+ constructor(_injector, _refRangeService) {
997
+ super();
998
+ this._injector = _injector;
999
+ this._refRangeService = _refRangeService;
1000
+ _defineProperty(this, "_filterBy$", new BehaviorSubject(FilterBy.VALUES));
1001
+ _defineProperty(this, "filterBy$", this._filterBy$.asObservable());
1002
+ _defineProperty(this, "_filterByModel$", new ReplaySubject(1));
1003
+ _defineProperty(this, "filterByModel$", this._filterByModel$.asObservable());
1004
+ _defineProperty(this, "_filterByModel", null);
1005
+ _defineProperty(this, "_hasCriteria$", new BehaviorSubject(false));
1006
+ _defineProperty(this, "hasCriteria$", this._hasCriteria$.asObservable());
1007
+ _defineProperty(this, "_filterModel", null);
1008
+ _defineProperty(this, "_col$", new BehaviorSubject(-1));
1009
+ _defineProperty(this, "col$", this._col$.asObservable());
1010
+ _defineProperty(this, "_filterHeaderListener", null);
1011
+ }
1012
+ dispose() {
1013
+ this._filterBy$.complete();
1014
+ this._filterByModel$.complete();
1015
+ this._hasCriteria$.complete();
1016
+ }
1017
+ setupCol(filterModel, col) {
1018
+ this.terminate();
1019
+ this._filterModel = filterModel;
1020
+ this._col$.next(col);
1021
+ const filterColumn = filterModel.getFilterColumn(col);
1022
+ if (filterColumn) {
1023
+ const info = filterColumn.getColumnData();
1024
+ if (info.customFilters) {
1025
+ this._hasCriteria$.next(true);
1026
+ this._setupByConditions(filterModel, col);
1027
+ return;
1028
+ }
1029
+ if (info.colorFilters) {
1030
+ this._hasCriteria$.next(true);
1031
+ this._setupByColors(filterModel, col);
1032
+ return;
1033
+ }
1034
+ if (info.filters) {
1035
+ this._hasCriteria$.next(true);
1036
+ this._setupByValues(filterModel, col);
1037
+ return;
1038
+ }
1039
+ this._hasCriteria$.next(false);
1040
+ this._setupByValues(filterModel, col);
1041
+ return;
1042
+ }
1043
+ this._hasCriteria$.next(false);
1044
+ this._setupByValues(filterModel, col);
1045
+ }
1046
+ changeFilterBy(filterBy) {
1047
+ if (!this._filterModel || this.col === -1) return false;
1048
+ switch (filterBy) {
1049
+ case FilterBy.VALUES:
1050
+ this._setupByValues(this._filterModel, this.col);
1051
+ break;
1052
+ case FilterBy.COLORS:
1053
+ this._setupByColors(this._filterModel, this.col);
1054
+ break;
1055
+ case FilterBy.CONDITIONS:
1056
+ this._setupByConditions(this._filterModel, this.col);
1057
+ break;
1058
+ }
1059
+ return true;
1060
+ }
1061
+ terminate() {
1062
+ this._filterModel = null;
1063
+ this._col$.next(-1);
1064
+ this._disposeFilterHeaderChangeListener();
1065
+ return true;
1066
+ }
1067
+ _disposeFilterHeaderChangeListener() {
1068
+ var _this$_filterHeaderLi;
1069
+ (_this$_filterHeaderLi = this._filterHeaderListener) === null || _this$_filterHeaderLi === void 0 || _this$_filterHeaderLi.dispose();
1070
+ this._filterHeaderListener = null;
1071
+ }
1072
+ _listenToFilterHeaderChange(filterModel, col) {
1073
+ this._disposeFilterHeaderChangeListener();
1074
+ const unitId = filterModel.unitId;
1075
+ const subUnitId = filterModel.subUnitId;
1076
+ const filterRange = filterModel.getRange();
1077
+ const columnHeaderRange = {
1078
+ startColumn: col,
1079
+ startRow: filterRange.startRow,
1080
+ endRow: filterRange.startRow,
1081
+ endColumn: col
1082
+ };
1083
+ this._filterHeaderListener = this._refRangeService.watchRange(unitId, subUnitId, columnHeaderRange, (before, after) => {
1084
+ if (!after) this.terminate();
1085
+ else {
1086
+ const offset = after.startColumn - before.startColumn;
1087
+ if (offset !== 0) this._filterByModel.deltaCol(offset);
1088
+ }
1089
+ });
1090
+ }
1091
+ async _setupByValues(filterModel, col) {
1092
+ this._disposePreviousModel();
1093
+ const range = filterModel.getRange();
1094
+ if (range.startRow === range.endRow) return false;
1095
+ this.filterByModel = await ByValuesModel.fromFilterColumn(this._injector, filterModel, col);
1096
+ this._filterBy$.next(FilterBy.VALUES);
1097
+ this._listenToFilterHeaderChange(filterModel, col);
1098
+ return true;
1099
+ }
1100
+ async _setupByColors(filterModel, col) {
1101
+ this._disposePreviousModel();
1102
+ const range = filterModel.getRange();
1103
+ if (range.startRow === range.endRow) return false;
1104
+ this.filterByModel = await ByColorsModel.fromFilterColumn(this._injector, filterModel, col);
1105
+ this._filterBy$.next(FilterBy.COLORS);
1106
+ this._listenToFilterHeaderChange(filterModel, col);
1107
+ return true;
1108
+ }
1109
+ _setupByConditions(filterModel, col) {
1110
+ this._disposePreviousModel();
1111
+ const range = filterModel.getRange();
1112
+ if (range.startRow === range.endRow) return false;
1113
+ this.filterByModel = ByConditionsModel.fromFilterColumn(this._injector, filterModel, col, filterModel.getFilterColumn(col));
1114
+ this._filterBy$.next(FilterBy.CONDITIONS);
1115
+ this._listenToFilterHeaderChange(filterModel, col);
1116
+ return true;
1117
+ }
1118
+ _disposePreviousModel() {
1119
+ var _this$_filterByModel;
1120
+ (_this$_filterByModel = this._filterByModel) === null || _this$_filterByModel === void 0 || _this$_filterByModel.dispose();
1121
+ this.filterByModel = null;
1122
+ }
1123
+ };
1124
+ SheetsFilterPanelService = __decorate([__decorateParam(0, Inject(Injector)), __decorateParam(1, Inject(RefRangeService))], SheetsFilterPanelService);
1125
+ let ByConditionsModel = _ByConditionsModel = class ByConditionsModel extends Disposable {
1126
+ /**
1127
+ * Create a model with targeting filter column. If there is not a filter column, the model would be created with
1128
+ * default values.
1129
+ *
1130
+ * @param injector
1131
+ * @param filterModel
1132
+ * @param col
1133
+ * @param filterColumn
1134
+ *
1135
+ * @returns the model to control the panel's state
1136
+ */
1137
+ static fromFilterColumn(injector, filterModel, col, filterColumn) {
1138
+ const [conditionItem, conditionParams] = FilterConditionItems.testMappingFilterColumn(filterColumn === null || filterColumn === void 0 ? void 0 : filterColumn.getColumnData());
1139
+ return injector.createInstance(_ByConditionsModel, filterModel, col, conditionItem, conditionParams);
1140
+ }
1141
+ get conditionItem() {
1142
+ return this._conditionItem$.getValue();
1143
+ }
1144
+ get filterConditionFormParams() {
1145
+ return this._filterConditionFormParams$.getValue();
1146
+ }
1147
+ constructor(_filterModel, col, conditionItem, conditionParams, _commandService) {
1148
+ super();
1149
+ this._filterModel = _filterModel;
1150
+ this.col = col;
1151
+ this._commandService = _commandService;
1152
+ _defineProperty(this, "canApply$", of(true));
1153
+ _defineProperty(this, "_conditionItem$", void 0);
1154
+ _defineProperty(this, "conditionItem$", void 0);
1155
+ _defineProperty(this, "_filterConditionFormParams$", void 0);
1156
+ _defineProperty(this, "filterConditionFormParams$", void 0);
1157
+ this._conditionItem$ = new BehaviorSubject(conditionItem);
1158
+ this.conditionItem$ = this._conditionItem$.asObservable();
1159
+ this._filterConditionFormParams$ = new BehaviorSubject(conditionParams);
1160
+ this.filterConditionFormParams$ = this._filterConditionFormParams$.asObservable();
1161
+ }
1162
+ dispose() {
1163
+ super.dispose();
1164
+ this._conditionItem$.complete();
1165
+ this._filterConditionFormParams$.complete();
1166
+ }
1167
+ deltaCol(offset) {
1168
+ this.col += offset;
1169
+ }
1170
+ clear() {
1171
+ if (this._disposed) return Promise.resolve(false);
1172
+ return this._commandService.executeCommand(SetSheetsFilterCriteriaCommand.id, {
1173
+ unitId: this._filterModel.unitId,
1174
+ subUnitId: this._filterModel.subUnitId,
1175
+ col: this.col,
1176
+ criteria: null
1177
+ });
1178
+ }
1179
+ /**
1180
+ * Apply the filter condition to the target filter column.
1181
+ */
1182
+ async apply() {
1183
+ if (this._disposed) return false;
1184
+ const filterColumn = FilterConditionItems.mapToFilterColumn(this.conditionItem, this.filterConditionFormParams);
1185
+ return this._commandService.executeCommand(SetSheetsFilterCriteriaCommand.id, {
1186
+ unitId: this._filterModel.unitId,
1187
+ subUnitId: this._filterModel.subUnitId,
1188
+ col: this.col,
1189
+ criteria: filterColumn
1190
+ });
1191
+ }
1192
+ /**
1193
+ * This method would be called when user changes the primary condition. The model would load the corresponding
1194
+ * `IFilterConditionFormParams` and load default condition form params.
1195
+ */
1196
+ onPrimaryConditionChange(operator) {
1197
+ const conditionItem = FilterConditionItems.ALL_CONDITIONS.find((item) => item.operator === operator);
1198
+ if (!conditionItem) throw new Error(`[ByConditionsModel]: condition item not found for operator: ${operator}!`);
1199
+ this._conditionItem$.next(conditionItem);
1200
+ this._filterConditionFormParams$.next(FilterConditionItems.getInitialFormParams(operator));
1201
+ }
1202
+ /**
1203
+ * This method would be called when user changes the primary conditions, the input values or "AND" "OR" ratio.
1204
+ * If the primary conditions or the ratio is changed, the method would load the corresponding `IFilterCondition`.
1205
+ *
1206
+ * When the panel call this method, it only has to pass the changed keys.
1207
+ *
1208
+ * @param params
1209
+ */
1210
+ onConditionFormChange(params) {
1211
+ const newParams = {
1212
+ ...this.filterConditionFormParams,
1213
+ ...params
1214
+ };
1215
+ if (newParams.and !== true) delete newParams.and;
1216
+ if (typeof params.and !== "undefined" || typeof params.operator1 !== "undefined" || typeof params.operator2 !== "undefined") {
1217
+ const conditionItem = FilterConditionItems.testMappingParams(newParams, this.conditionItem.numOfParameters);
1218
+ this._conditionItem$.next(conditionItem);
1219
+ }
1220
+ this._filterConditionFormParams$.next(newParams);
1221
+ }
1222
+ };
1223
+ ByConditionsModel = _ByConditionsModel = __decorate([__decorateParam(4, ICommandService)], ByConditionsModel);
1224
+ let ByValuesModel = _ByValuesModel = class ByValuesModel extends Disposable {
1225
+ /**
1226
+ * Create a model with targeting filter column. If there is not a filter column, the model would be created with
1227
+ * default values.
1228
+ *
1229
+ * @param injector
1230
+ * @param filterModel
1231
+ * @param col
1232
+ *
1233
+ * @returns the model to control the panel's state
1234
+ */
1235
+ static async fromFilterColumn(injector, filterModel, col) {
1236
+ const univerInstanceService = injector.get(IUniverInstanceService);
1237
+ const localeService = injector.get(LocaleService);
1238
+ const generateFilterValuesService = injector.get(ISheetsGenerateFilterValuesService, Quantity.OPTIONAL);
1239
+ const { unitId, subUnitId } = filterModel;
1240
+ const workbook = univerInstanceService.getUniverSheetInstance(unitId);
1241
+ if (!workbook) throw new Error(`[ByValuesModel]: Workbook not found for filter model with unitId: ${unitId}!`);
1242
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
1243
+ if (!worksheet) throw new Error(`[ByValuesModel]: Worksheet not found for filter model with unitId: ${unitId} and subUnitId: ${subUnitId}!`);
1244
+ const range = filterModel.getRange();
1245
+ const column = col;
1246
+ const filterColumn = filterModel.getFilterColumn(col);
1247
+ const filters = filterColumn === null || filterColumn === void 0 ? void 0 : filterColumn.getColumnData().filters;
1248
+ const alreadyChecked = new Set(filters === null || filters === void 0 ? void 0 : filters.filters);
1249
+ const blankChecked = !!(filters && filters.blank);
1250
+ const filteredOutRowsByOtherColumns = filterModel.getFilteredOutRowsExceptCol(col);
1251
+ const iterateRange = {
1252
+ ...range,
1253
+ startRow: range.startRow + 1,
1254
+ startColumn: column,
1255
+ endColumn: column
1256
+ };
1257
+ let items;
1258
+ let cache;
1259
+ if (generateFilterValuesService) {
1260
+ const res = await generateFilterValuesService.getFilterValues({
1261
+ unitId,
1262
+ subUnitId,
1263
+ filteredOutRowsByOtherColumns: Array.from(filteredOutRowsByOtherColumns),
1264
+ filterColumn,
1265
+ filters: !!filters,
1266
+ blankChecked,
1267
+ iterateRange,
1268
+ alreadyChecked: Array.from(alreadyChecked)
1269
+ });
1270
+ items = res.filterTreeItems;
1271
+ cache = res.filterTreeMapCache;
1272
+ } else {
1273
+ const res = getFilterTreeByValueItems(!!filters, localeService, iterateRange, worksheet, filteredOutRowsByOtherColumns, filterColumn, alreadyChecked, blankChecked, workbook.getStyles());
1274
+ items = res.filterTreeItems;
1275
+ cache = res.filterTreeMapCache;
1276
+ }
1277
+ return injector.createInstance(_ByValuesModel, filterModel, col, items, cache);
1278
+ }
1279
+ get rawFilterItems() {
1280
+ return this._rawFilterItems$.getValue();
1281
+ }
1282
+ get filterItems() {
1283
+ return this._filterItems;
1284
+ }
1285
+ get treeMapCache() {
1286
+ return this._treeMapCache;
1287
+ }
1288
+ constructor(_filterModel, col, items, cache, _commandService) {
1289
+ super();
1290
+ this._filterModel = _filterModel;
1291
+ this.col = col;
1292
+ this._commandService = _commandService;
1293
+ _defineProperty(this, "_rawFilterItems$", void 0);
1294
+ _defineProperty(this, "rawFilterItems$", void 0);
1295
+ _defineProperty(this, "filterItems$", void 0);
1296
+ _defineProperty(this, "_filterItems", []);
1297
+ _defineProperty(this, "_treeMapCache", void 0);
1298
+ _defineProperty(this, "canApply$", void 0);
1299
+ _defineProperty(this, "_manuallyUpdateFilterItems$", void 0);
1300
+ _defineProperty(this, "_searchString$", void 0);
1301
+ _defineProperty(this, "searchString$", void 0);
1302
+ this._treeMapCache = cache;
1303
+ this._searchString$ = new BehaviorSubject("");
1304
+ this.searchString$ = this._searchString$.asObservable();
1305
+ this._rawFilterItems$ = new BehaviorSubject(items);
1306
+ this.rawFilterItems$ = this._rawFilterItems$.asObservable();
1307
+ this._manuallyUpdateFilterItems$ = new Subject();
1308
+ this.filterItems$ = merge$1(combineLatest([this._searchString$.pipe(throttleTime(500, void 0, {
1309
+ leading: true,
1310
+ trailing: true
1311
+ }), startWith(void 0)), this._rawFilterItems$]).pipe(map(([searchString, items]) => {
1312
+ if (!searchString) return items;
1313
+ return searchTree(items, searchString.toLowerCase().split(/\s+/).filter((s) => !!s));
1314
+ })), this._manuallyUpdateFilterItems$).pipe(shareReplay(1));
1315
+ this.canApply$ = this.filterItems$.pipe(map((items) => {
1316
+ return statisticFilterByValueItems(items).checked > 0;
1317
+ }));
1318
+ this.disposeWithMe(this.filterItems$.subscribe((items) => this._filterItems = items));
1319
+ }
1320
+ dispose() {
1321
+ this._rawFilterItems$.complete();
1322
+ this._searchString$.complete();
1323
+ }
1324
+ deltaCol(offset) {
1325
+ this.col += offset;
1326
+ }
1327
+ setSearchString(str) {
1328
+ this._searchString$.next(str);
1329
+ }
1330
+ onCheckAllToggled(checked) {
1331
+ const items = Tools.deepClone(this._filterItems);
1332
+ items.forEach((item) => updateLeafNodesCheckedStatus(item, checked));
1333
+ this._manuallyUpdateFilterItems(items);
1334
+ }
1335
+ /**
1336
+ * Toggle a filter item.
1337
+ */
1338
+ onFilterCheckToggled(item) {
1339
+ const items = Tools.deepClone(this._filterItems);
1340
+ const changedItem = findObjectByKey(items, item.key);
1341
+ if (!changedItem) return;
1342
+ updateLeafNodesCheckedStatus(changedItem, !areAllLeafNodesChecked(changedItem));
1343
+ this._manuallyUpdateFilterItems(items);
1344
+ }
1345
+ onFilterOnly(itemKeys) {
1346
+ const items = Tools.deepClone(this._filterItems);
1347
+ items.forEach((item) => updateLeafNodesCheckedStatus(item, false));
1348
+ itemKeys.forEach((key) => {
1349
+ const changedItem = findObjectByKey(items, key);
1350
+ if (changedItem) updateLeafNodesCheckedStatus(changedItem, true);
1351
+ });
1352
+ this._manuallyUpdateFilterItems(items);
1353
+ }
1354
+ _manuallyUpdateFilterItems(items) {
1355
+ this._manuallyUpdateFilterItems$.next(items);
1356
+ }
1357
+ clear() {
1358
+ if (this._disposed) return Promise.resolve(false);
1359
+ return this._commandService.executeCommand(SetSheetsFilterCriteriaCommand.id, {
1360
+ unitId: this._filterModel.unitId,
1361
+ subUnitId: this._filterModel.subUnitId,
1362
+ col: this.col,
1363
+ criteria: null
1364
+ });
1365
+ }
1366
+ /**
1367
+ * Apply the filter condition to the target filter column.
1368
+ */
1369
+ async apply() {
1370
+ if (this._disposed) return false;
1371
+ const statistics = statisticFilterByValueItems(this._filterItems);
1372
+ const { checked, checkedItems } = statistics;
1373
+ const rawFilterItems = this.rawFilterItems;
1374
+ let rawFilterCount = 0;
1375
+ for (const item of rawFilterItems) rawFilterCount += item.count;
1376
+ const noChecked = checked === 0;
1377
+ const allChecked = statistics.checked === rawFilterCount;
1378
+ const criteria = { colId: this.col };
1379
+ if (noChecked) throw new Error("[ByValuesModel]: no checked items!");
1380
+ else if (allChecked) return this._commandService.executeCommand(SetSheetsFilterCriteriaCommand.id, {
1381
+ unitId: this._filterModel.unitId,
1382
+ subUnitId: this._filterModel.subUnitId,
1383
+ col: this.col,
1384
+ criteria: null
1385
+ });
1386
+ else {
1387
+ criteria.filters = {};
1388
+ const nonEmptyItems = checkedItems.filter((item) => item.key !== "empty");
1389
+ if (nonEmptyItems.length > 0) criteria.filters = { filters: nonEmptyItems.flatMap((item) => item.originValues ? Array.from(item.originValues) : [item.title]) };
1390
+ if (nonEmptyItems.length !== checkedItems.length) criteria.filters.blank = true;
1391
+ }
1392
+ return this._commandService.executeCommand(SetSheetsFilterCriteriaCommand.id, {
1393
+ unitId: this._filterModel.unitId,
1394
+ subUnitId: this._filterModel.subUnitId,
1395
+ col: this.col,
1396
+ criteria
1397
+ });
1398
+ }
1399
+ };
1400
+ ByValuesModel = _ByValuesModel = __decorate([__decorateParam(4, ICommandService)], ByValuesModel);
1401
+ let ByColorsModel = _ByColorsModel = class ByColorsModel extends Disposable {
1402
+ /**
1403
+ * Create a model with targeting filter column. If there is not a filter column, the model would be created with
1404
+ * default values.
1405
+ *
1406
+ * @param injector
1407
+ * @param filterModel
1408
+ * @param col
1409
+ *
1410
+ * @returns the model to control the panel's state
1411
+ */
1412
+ static async fromFilterColumn(injector, filterModel, col) {
1413
+ var _filterModel$getFilte, _colorFilters$cellFil, _colorFilters$cellTex;
1414
+ const univerInstanceService = injector.get(IUniverInstanceService);
1415
+ const { unitId, subUnitId } = filterModel;
1416
+ const workbook = univerInstanceService.getUniverSheetInstance(unitId);
1417
+ if (!workbook) throw new Error(`[ByColorsModel]: Workbook not found for filter model with unitId: ${unitId}!`);
1418
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
1419
+ if (!worksheet) throw new Error(`[ByColorsModel]: Worksheet not found for filter model with unitId: ${unitId} and subUnitId: ${subUnitId}!`);
1420
+ const range = filterModel.getRange();
1421
+ const column = col;
1422
+ const colorFilters = (_filterModel$getFilte = filterModel.getFilterColumn(col)) === null || _filterModel$getFilte === void 0 ? void 0 : _filterModel$getFilte.getColumnData().colorFilters;
1423
+ const filteredOutRowsByOtherColumns = filterModel.getFilteredOutRowsExceptCol(col);
1424
+ const iterateRange = {
1425
+ ...range,
1426
+ startRow: range.startRow + 1,
1427
+ startColumn: column,
1428
+ endColumn: column
1429
+ };
1430
+ const cellFillColors = /* @__PURE__ */ new Map();
1431
+ const cellFillColorsChecked = new Set((_colorFilters$cellFil = colorFilters === null || colorFilters === void 0 ? void 0 : colorFilters.cellFillColors) !== null && _colorFilters$cellFil !== void 0 ? _colorFilters$cellFil : []);
1432
+ const cellTextColors = /* @__PURE__ */ new Map();
1433
+ const cellTextColorsChecked = new Set((_colorFilters$cellTex = colorFilters === null || colorFilters === void 0 ? void 0 : colorFilters.cellTextColors) !== null && _colorFilters$cellTex !== void 0 ? _colorFilters$cellTex : []);
1434
+ for (const cell of worksheet.iterateByColumn(iterateRange, false, true)) {
1435
+ const { row, col, value } = cell;
1436
+ if (filteredOutRowsByOtherColumns.has(row)) continue;
1437
+ const style = worksheet.getComposedCellStyleByCellData(row, col, value);
1438
+ if (style.bg && style.bg.rgb) {
1439
+ const bg = new ColorKit(style.bg.rgb).toRgbString();
1440
+ if (!cellFillColors.has(bg)) cellFillColors.set(bg, {
1441
+ color: bg,
1442
+ checked: cellFillColorsChecked.has(bg)
1443
+ });
1444
+ } else cellFillColors.set("default-fill-color", {
1445
+ color: null,
1446
+ checked: cellFillColorsChecked.has(null)
1447
+ });
1448
+ if (style.cl && style.cl.rgb) {
1449
+ const cl = new ColorKit(style.cl.rgb).toRgbString();
1450
+ if (!cellTextColors.has(cl)) cellTextColors.set(cl, {
1451
+ color: cl,
1452
+ checked: cellTextColorsChecked.has(cl)
1453
+ });
1454
+ } else cellTextColors.set("default-font-color", {
1455
+ color: COLOR_BLACK_RGB,
1456
+ checked: cellTextColorsChecked.has(COLOR_BLACK_RGB)
1457
+ });
1458
+ }
1459
+ return injector.createInstance(_ByColorsModel, filterModel, col, cellFillColors, cellTextColors);
1460
+ }
1461
+ get cellFillColors() {
1462
+ return this._cellFillColors$.getValue();
1463
+ }
1464
+ get cellTextColors() {
1465
+ return this._cellTextColors$.getValue();
1466
+ }
1467
+ constructor(_filterModel, col, cellFillColors, cellTextColors, _commandService) {
1468
+ super();
1469
+ this._filterModel = _filterModel;
1470
+ this.col = col;
1471
+ this._commandService = _commandService;
1472
+ _defineProperty(this, "canApply$", of(true));
1473
+ _defineProperty(this, "_cellFillColors$", void 0);
1474
+ _defineProperty(this, "cellFillColors$", void 0);
1475
+ _defineProperty(this, "_cellTextColors$", void 0);
1476
+ _defineProperty(this, "cellTextColors$", void 0);
1477
+ this._cellFillColors$ = new BehaviorSubject(Array.from(cellFillColors.values()));
1478
+ this.cellFillColors$ = this._cellFillColors$.asObservable();
1479
+ this._cellTextColors$ = new BehaviorSubject(Array.from(cellTextColors.values()));
1480
+ this.cellTextColors$ = this._cellTextColors$.asObservable();
1481
+ }
1482
+ dispose() {
1483
+ super.dispose();
1484
+ this._cellFillColors$.complete();
1485
+ }
1486
+ deltaCol(offset) {
1487
+ this.col += offset;
1488
+ }
1489
+ clear() {
1490
+ if (this._disposed) return Promise.resolve(false);
1491
+ return this._commandService.executeCommand(SetSheetsFilterCriteriaCommand.id, {
1492
+ unitId: this._filterModel.unitId,
1493
+ subUnitId: this._filterModel.subUnitId,
1494
+ col: this.col,
1495
+ criteria: null
1496
+ });
1497
+ }
1498
+ onFilterCheckToggled(item, isFillColor = true) {
1499
+ const colors = isFillColor ? this.cellFillColors : this.cellTextColors;
1500
+ const items = [];
1501
+ let found = false;
1502
+ for (let i = 0; i < colors.length; i++) {
1503
+ const colorItem = colors[i];
1504
+ if (colorItem.color === item.color) {
1505
+ found = true;
1506
+ items.push({
1507
+ color: colorItem.color,
1508
+ checked: !colorItem.checked
1509
+ });
1510
+ continue;
1511
+ }
1512
+ items.push({
1513
+ color: colorItem.color,
1514
+ checked: colorItem.checked
1515
+ });
1516
+ }
1517
+ if (!found) return;
1518
+ this._resetColorsCheckedStatus(!isFillColor);
1519
+ if (isFillColor) this._cellFillColors$.next([...items]);
1520
+ else this._cellTextColors$.next([...items]);
1521
+ }
1522
+ _resetColorsCheckedStatus(isFillColor = true) {
1523
+ const colors = isFillColor ? this.cellFillColors : this.cellTextColors;
1524
+ const items = [];
1525
+ for (let i = 0; i < colors.length; i++) items.push({
1526
+ color: colors[i].color,
1527
+ checked: false
1528
+ });
1529
+ if (isFillColor) this._cellFillColors$.next([...items]);
1530
+ else this._cellTextColors$.next([...items]);
1531
+ }
1532
+ /**
1533
+ * Apply the filter condition to the target filter column.
1534
+ */
1535
+ async apply() {
1536
+ if (this._disposed) return false;
1537
+ const cellFillColorsChecked = this.cellFillColors.filter((item) => item.checked).map((item) => item.color);
1538
+ const cellTextColorsChecked = this.cellTextColors.filter((item) => item.checked).map((item) => item.color);
1539
+ if (cellFillColorsChecked.length === 0 && cellTextColorsChecked.length === 0) return this._commandService.executeCommand(SetSheetsFilterCriteriaCommand.id, {
1540
+ unitId: this._filterModel.unitId,
1541
+ subUnitId: this._filterModel.subUnitId,
1542
+ col: this.col,
1543
+ criteria: null
1544
+ });
1545
+ const criteria = { colId: this.col };
1546
+ if (cellFillColorsChecked.length > 0) criteria.colorFilters = { cellFillColors: cellFillColorsChecked };
1547
+ else if (cellTextColorsChecked.length > 0) criteria.colorFilters = { cellTextColors: cellTextColorsChecked };
1548
+ return this._commandService.executeCommand(SetSheetsFilterCriteriaCommand.id, {
1549
+ unitId: this._filterModel.unitId,
1550
+ subUnitId: this._filterModel.subUnitId,
1551
+ col: this.col,
1552
+ criteria
1553
+ });
1554
+ }
1555
+ };
1556
+ ByColorsModel = _ByColorsModel = __decorate([__decorateParam(4, ICommandService)], ByColorsModel);
1557
+
1558
+ //#endregion
1559
+ //#region src/commands/operations/sheets-filter.operation.ts
1560
+ const FILTER_PANEL_OPENED_KEY = "FILTER_PANEL_OPENED";
1561
+ /**
1562
+ * The operation to open the filter panel and prepare for changing the filter conditions on a given column.
1563
+ */
1564
+ const OpenFilterPanelOperation = {
1565
+ id: "sheet.operation.open-filter-panel",
1566
+ type: CommandType.OPERATION,
1567
+ handler: (accessor, params) => {
1568
+ const contextService = accessor.get(IContextService);
1569
+ const sheetsFilterService = accessor.get(SheetsFilterService);
1570
+ const sheetsFilterPanelService = accessor.get(SheetsFilterPanelService);
1571
+ const commandService = accessor.get(ICommandService);
1572
+ const editorBridgeService = accessor.has(IEditorBridgeService) ? accessor.get(IEditorBridgeService) : null;
1573
+ if (editorBridgeService === null || editorBridgeService === void 0 ? void 0 : editorBridgeService.isVisible().visible) commandService.syncExecuteCommand(SetCellEditVisibleOperation.id, { visible: false });
1574
+ const { unitId, subUnitId, col } = params;
1575
+ const filterModel = sheetsFilterService.getFilterModel(unitId, subUnitId);
1576
+ if (!filterModel) return false;
1577
+ sheetsFilterPanelService.setupCol(filterModel, col);
1578
+ if (!contextService.getContextValue("FILTER_PANEL_OPENED")) contextService.setContextValue(FILTER_PANEL_OPENED_KEY, true);
1579
+ return true;
1580
+ }
1581
+ };
1582
+ const CloseFilterPanelOperation = {
1583
+ id: "sheet.operation.close-filter-panel",
1584
+ type: CommandType.OPERATION,
1585
+ handler: (accessor) => {
1586
+ const contextService = accessor.get(IContextService);
1587
+ const sheetsFilterPanelService = accessor.get(SheetsFilterPanelService);
1588
+ const layoutService = accessor.get(ILayoutService, Quantity.OPTIONAL);
1589
+ if (contextService.getContextValue("FILTER_PANEL_OPENED")) {
1590
+ contextService.setContextValue(FILTER_PANEL_OPENED_KEY, false);
1591
+ layoutService === null || layoutService === void 0 || layoutService.focus();
1592
+ return sheetsFilterPanelService.terminate();
1593
+ }
1594
+ return false;
1595
+ }
1596
+ };
1597
+ const ChangeFilterByOperation = {
1598
+ id: "sheet.operation.apply-filter",
1599
+ type: CommandType.OPERATION,
1600
+ handler: (accessor, params) => {
1601
+ const { filterBy } = params;
1602
+ return accessor.get(SheetsFilterPanelService).changeFilterBy(filterBy);
1603
+ }
1604
+ };
1605
+
1606
+ //#endregion
1607
+ //#region package.json
1608
+ var name = "@univerjs/sheets-filter-ui";
1609
+ var version = "0.21.0";
1610
+
1611
+ //#endregion
1612
+ //#region src/config/config.ts
1613
+ const SHEETS_FILTER_UI_PLUGIN_CONFIG_KEY = "sheets-filter-ui.config";
1614
+ const configSymbol = Symbol(SHEETS_FILTER_UI_PLUGIN_CONFIG_KEY);
1615
+ const defaultPluginConfig = {};
1616
+
1617
+ //#endregion
1618
+ //#region src/controllers/sheets-filter-permission.controller.ts
1619
+ let SheetsFilterPermissionController = class SheetsFilterPermissionController extends Disposable {
1620
+ constructor(_sheetsFilterService, _localeService, _commandService, _sheetPermissionCheckPermission, _injector, _sheetsSelectionService) {
1621
+ super();
1622
+ this._sheetsFilterService = _sheetsFilterService;
1623
+ this._localeService = _localeService;
1624
+ this._commandService = _commandService;
1625
+ this._sheetPermissionCheckPermission = _sheetPermissionCheckPermission;
1626
+ this._injector = _injector;
1627
+ this._sheetsSelectionService = _sheetsSelectionService;
1628
+ this._commandExecutedListener();
1629
+ }
1630
+ _commandExecutedListener() {
1631
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
1632
+ if (command.id === SmartToggleSheetsFilterCommand.id) {
1633
+ var _this$_sheetsFilterSe;
1634
+ const target = getSheetCommandTarget(this._injector.get(IUniverInstanceService));
1635
+ if (!target) return;
1636
+ const { unitId, subUnitId, worksheet } = target;
1637
+ const filterRange = (_this$_sheetsFilterSe = this._sheetsFilterService.getFilterModel(unitId, subUnitId)) === null || _this$_sheetsFilterSe === void 0 ? void 0 : _this$_sheetsFilterSe.getRange();
1638
+ let permission;
1639
+ if (filterRange) permission = this._sheetPermissionCheckPermission.permissionCheckWithRanges({
1640
+ rangeTypes: [RangeProtectionPermissionViewPoint],
1641
+ worksheetTypes: [WorksheetFilterPermission, WorksheetViewPermission]
1642
+ }, [filterRange], unitId, subUnitId);
1643
+ else {
1644
+ var _this$_sheetsSelectio;
1645
+ const range = (_this$_sheetsSelectio = this._sheetsSelectionService.getCurrentLastSelection()) === null || _this$_sheetsSelectio === void 0 ? void 0 : _this$_sheetsSelectio.range;
1646
+ if (range) {
1647
+ let newRange = { ...range };
1648
+ newRange = range.startColumn === range.endColumn && range.startRow === range.endRow ? expandToContinuousRange(newRange, {
1649
+ left: true,
1650
+ right: true,
1651
+ up: true,
1652
+ down: true
1653
+ }, worksheet) : newRange;
1654
+ permission = this._sheetPermissionCheckPermission.permissionCheckWithRanges({
1655
+ rangeTypes: [RangeProtectionPermissionViewPoint],
1656
+ worksheetTypes: [WorksheetViewPermission, WorksheetFilterPermission]
1657
+ }, [newRange], unitId, subUnitId);
1658
+ } else permission = this._sheetPermissionCheckPermission.permissionCheckWithoutRange({
1659
+ rangeTypes: [RangeProtectionPermissionViewPoint],
1660
+ worksheetTypes: [WorksheetViewPermission, WorksheetFilterPermission]
1661
+ });
1662
+ }
1663
+ if (!permission) this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.filterErr"));
1664
+ }
1665
+ if (command.id === OpenFilterPanelOperation.id) {
1666
+ var _this$_sheetsFilterSe2;
1667
+ const params = command.params;
1668
+ const { unitId, subUnitId } = params;
1669
+ const filterRange = (_this$_sheetsFilterSe2 = this._sheetsFilterService.getFilterModel(unitId, subUnitId)) === null || _this$_sheetsFilterSe2 === void 0 ? void 0 : _this$_sheetsFilterSe2.getRange();
1670
+ const colRange = Tools.deepClone(filterRange);
1671
+ if (colRange) {
1672
+ colRange.startColumn = params.col;
1673
+ colRange.endColumn = params.col;
1674
+ if (!this._sheetPermissionCheckPermission.permissionCheckWithRanges({
1675
+ rangeTypes: [RangeProtectionPermissionViewPoint],
1676
+ worksheetTypes: [WorksheetFilterPermission, WorksheetViewPermission]
1677
+ }, [colRange], unitId, subUnitId)) this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.filterErr"));
1678
+ }
1679
+ }
1680
+ }));
1681
+ }
1682
+ };
1683
+ SheetsFilterPermissionController = __decorate([
1684
+ __decorateParam(0, Inject(SheetsFilterService)),
1685
+ __decorateParam(1, Inject(LocaleService)),
1686
+ __decorateParam(2, ICommandService),
1687
+ __decorateParam(3, Inject(SheetPermissionCheckController)),
1688
+ __decorateParam(4, Inject(Injector)),
1689
+ __decorateParam(5, Inject(SheetsSelectionsService))
1690
+ ], SheetsFilterPermissionController);
1691
+
1692
+ //#endregion
1693
+ //#region src/views/widgets/drawings.ts
1694
+ const BUTTON_VIEWPORT = 16;
1695
+ const FILTER_BUTTON_EMPTY = new Path2D("M3.30363 3C2.79117 3 2.51457 3.60097 2.84788 3.99024L6.8 8.60593V12.5662C6.8 12.7184 6.8864 12.8575 7.02289 12.9249L8.76717 13.7863C8.96655 13.8847 9.2 13.7396 9.2 13.5173V8.60593L13.1521 3.99024C13.4854 3.60097 13.2088 3 12.6964 3H3.30363Z");
1696
+ var FilterButton = class {
1697
+ static drawNoCriteria(ctx, size, fgColor, bgColor) {
1698
+ ctx.save();
1699
+ Rect.drawWith(ctx, {
1700
+ radius: 2,
1701
+ width: BUTTON_VIEWPORT,
1702
+ height: BUTTON_VIEWPORT,
1703
+ fill: bgColor
1704
+ });
1705
+ ctx.lineCap = "square";
1706
+ ctx.strokeStyle = fgColor;
1707
+ ctx.scale(size / BUTTON_VIEWPORT, size / BUTTON_VIEWPORT);
1708
+ ctx.beginPath();
1709
+ ctx.lineWidth = 1;
1710
+ ctx.lineCap = "round";
1711
+ ctx.moveTo(3, 4);
1712
+ ctx.lineTo(13, 4);
1713
+ ctx.moveTo(4.5, 8);
1714
+ ctx.lineTo(11.5, 8);
1715
+ ctx.moveTo(6, 12);
1716
+ ctx.lineTo(10, 12);
1717
+ ctx.stroke();
1718
+ ctx.restore();
1719
+ }
1720
+ static drawHasCriteria(ctx, size, fgColor, bgColor) {
1721
+ ctx.save();
1722
+ Rect.drawWith(ctx, {
1723
+ radius: 2,
1724
+ width: BUTTON_VIEWPORT,
1725
+ height: BUTTON_VIEWPORT,
1726
+ fill: bgColor
1727
+ });
1728
+ ctx.scale(size / BUTTON_VIEWPORT, size / BUTTON_VIEWPORT);
1729
+ ctx.fillStyle = fgColor;
1730
+ ctx.fill(FILTER_BUTTON_EMPTY);
1731
+ ctx.restore();
1732
+ }
1733
+ };
1734
+
1735
+ //#endregion
1736
+ //#region src/views/widgets/filter-button.shape.ts
1737
+ const FILTER_ICON_SIZE = 16;
1738
+ let SheetsFilterButtonShape = class SheetsFilterButtonShape extends Shape {
1739
+ constructor(key, props, _contextService, _commandService, _themeService) {
1740
+ super(key, props);
1741
+ this._contextService = _contextService;
1742
+ this._commandService = _commandService;
1743
+ this._themeService = _themeService;
1744
+ _defineProperty(this, "_cellWidth", 0);
1745
+ _defineProperty(this, "_cellHeight", 0);
1746
+ _defineProperty(this, "_filterParams", void 0);
1747
+ _defineProperty(this, "_hovered", false);
1748
+ this.setShapeProps(props);
1749
+ this.onPointerDown$.subscribeEvent((evt) => this.onPointerDown(evt));
1750
+ this.onPointerEnter$.subscribeEvent(() => this.onPointerEnter());
1751
+ this.onPointerLeave$.subscribeEvent(() => this.onPointerLeave());
1752
+ }
1753
+ setShapeProps(props) {
1754
+ if (typeof props.cellHeight !== "undefined") this._cellHeight = props.cellHeight;
1755
+ if (typeof props.cellWidth !== "undefined") this._cellWidth = props.cellWidth;
1756
+ if (typeof props.filterParams !== "undefined") this._filterParams = props.filterParams;
1757
+ this.transformByState({
1758
+ width: props.width,
1759
+ height: props.height
1760
+ });
1761
+ }
1762
+ _draw(ctx) {
1763
+ const cellHeight = this._cellHeight;
1764
+ const cellWidth = this._cellWidth;
1765
+ const left = 16 - cellWidth;
1766
+ const top = 16 - cellHeight;
1767
+ ctx.save();
1768
+ const cellRegion = new Path2D();
1769
+ cellRegion.rect(left, top, cellWidth, cellHeight);
1770
+ ctx.clip(cellRegion);
1771
+ const { hasCriteria } = this._filterParams;
1772
+ const fgColor = this._themeService.getColorFromTheme("primary.600");
1773
+ const bgColor = this._hovered ? this._themeService.getColorFromTheme("gray.50") : "rgba(255, 255, 255, 1.0)";
1774
+ if (hasCriteria) FilterButton.drawHasCriteria(ctx, 16, fgColor, bgColor);
1775
+ else FilterButton.drawNoCriteria(ctx, 16, fgColor, bgColor);
1776
+ ctx.restore();
1777
+ }
1778
+ onPointerDown(evt) {
1779
+ if (evt.button === 2) return;
1780
+ const { col, unitId, subUnitId } = this._filterParams;
1781
+ if (this._contextService.getContextValue("FILTER_PANEL_OPENED") || !this._commandService.hasCommand(OpenFilterPanelOperation.id)) return;
1782
+ setTimeout(() => {
1783
+ this._commandService.executeCommand(OpenFilterPanelOperation.id, {
1784
+ unitId,
1785
+ subUnitId,
1786
+ col
1787
+ });
1788
+ }, 200);
1789
+ }
1790
+ onPointerEnter() {
1791
+ this._hovered = true;
1792
+ this.makeDirty(true);
1793
+ }
1794
+ onPointerLeave() {
1795
+ this._hovered = false;
1796
+ this.makeDirty(true);
1797
+ }
1798
+ };
1799
+ SheetsFilterButtonShape = __decorate([
1800
+ __decorateParam(2, IContextService),
1801
+ __decorateParam(3, ICommandService),
1802
+ __decorateParam(4, Inject(ThemeService))
1803
+ ], SheetsFilterButtonShape);
1804
+
1805
+ //#endregion
1806
+ //#region src/views/render-modules/sheets-filter.render-controller.ts
1807
+ const DEFAULT_Z_INDEX = 1e3;
1808
+ const SHEETS_FILTER_BUTTON_Z_INDEX = 5e3;
1809
+ function computeIconTop(startY, endY, cellHeight, verticalAlign) {
1810
+ switch (verticalAlign) {
1811
+ case VerticalAlign.TOP: return startY + 1;
1812
+ case VerticalAlign.MIDDLE: return startY + Math.max(0, (cellHeight - 16) / 2);
1813
+ case VerticalAlign.BOTTOM:
1814
+ default: return endY - 16 - 1;
1815
+ }
1816
+ }
1817
+ let SheetsFilterRenderController = class SheetsFilterRenderController extends RxDisposable {
1818
+ constructor(_context, _injector, _sheetSkeletonManagerService, _sheetsFilterService, _themeService, _sheetInterceptorService, _commandService, _selectionRenderService) {
1819
+ super();
1820
+ this._context = _context;
1821
+ this._injector = _injector;
1822
+ this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
1823
+ this._sheetsFilterService = _sheetsFilterService;
1824
+ this._themeService = _themeService;
1825
+ this._sheetInterceptorService = _sheetInterceptorService;
1826
+ this._commandService = _commandService;
1827
+ this._selectionRenderService = _selectionRenderService;
1828
+ _defineProperty(this, "_currentRenderParams", null);
1829
+ _defineProperty(this, "_filterRangeShape", null);
1830
+ _defineProperty(this, "_buttonRenderDisposable", null);
1831
+ _defineProperty(this, "_filterButtonShapes", []);
1832
+ this._initRenderer();
1833
+ }
1834
+ dispose() {
1835
+ super.dispose();
1836
+ this._disposeRendering();
1837
+ }
1838
+ _initRenderer() {
1839
+ this.disposeWithMe(this._themeService.currentTheme$.subscribe(() => {
1840
+ this._refreshRendering(this._currentRenderParams);
1841
+ }));
1842
+ this._sheetSkeletonManagerService.currentSkeleton$.pipe(switchMap((skeletonParams) => {
1843
+ var _workbook$getActiveSh, _this$_sheetsFilterSe;
1844
+ if (!skeletonParams) return of(null);
1845
+ const { unit: workbook, unitId } = this._context;
1846
+ const worksheetId = ((_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId()) || "";
1847
+ const filterModel = (_this$_sheetsFilterSe = this._sheetsFilterService.getFilterModel(unitId, worksheetId)) !== null && _this$_sheetsFilterSe !== void 0 ? _this$_sheetsFilterSe : void 0;
1848
+ const getParams = () => ({
1849
+ unitId,
1850
+ worksheetId,
1851
+ filterModel,
1852
+ range: filterModel === null || filterModel === void 0 ? void 0 : filterModel.getRange(),
1853
+ skeleton: skeletonParams.skeleton
1854
+ });
1855
+ return fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(filter(([command]) => {
1856
+ var _command$params;
1857
+ return command.type === CommandType.MUTATION && ((_command$params = command.params) === null || _command$params === void 0 ? void 0 : _command$params.unitId) === workbook.getUnitId() && (FILTER_MUTATIONS.has(command.id) || command.id === SetRangeValuesMutation.id);
1858
+ }), throttleTime(20, void 0, {
1859
+ leading: false,
1860
+ trailing: true
1861
+ }), map(getParams), startWith(getParams()));
1862
+ }), takeUntil(this.dispose$)).subscribe((renderParams) => {
1863
+ this._currentRenderParams = renderParams;
1864
+ this._refreshRendering(renderParams);
1865
+ });
1866
+ }
1867
+ _refreshRendering(renderParams) {
1868
+ this._disposeRendering();
1869
+ if (!renderParams || !renderParams.range) return;
1870
+ this._renderRange(renderParams.range, renderParams.skeleton);
1871
+ this._renderButtons(renderParams);
1872
+ }
1873
+ _renderRange(range, skeleton) {
1874
+ const { scene } = this._context;
1875
+ const { rowHeaderWidth, columnHeaderHeight } = skeleton;
1876
+ const filterRangeShape = this._filterRangeShape = new SelectionControl(scene, DEFAULT_Z_INDEX, this._themeService, {
1877
+ rowHeaderWidth,
1878
+ columnHeaderHeight,
1879
+ enableAutoFill: false,
1880
+ highlightHeader: false
1881
+ });
1882
+ const selectionWithCoord = attachSelectionWithCoord({
1883
+ range,
1884
+ primary: null,
1885
+ style: { fill: "rgba(0, 0, 0, 0.0)" }
1886
+ }, skeleton);
1887
+ filterRangeShape.updateRangeBySelectionWithCoord(selectionWithCoord);
1888
+ filterRangeShape.setEvent(false);
1889
+ scene.makeDirty(true);
1890
+ }
1891
+ _renderButtons(params) {
1892
+ const { range, filterModel, unitId, skeleton, worksheetId } = params;
1893
+ const { unit: workbook, scene } = this._context;
1894
+ const worksheet = workbook.getSheetBySheetId(worksheetId);
1895
+ if (!worksheet) return;
1896
+ this._interceptCellContent(unitId, worksheetId, params.range);
1897
+ const { startColumn, endColumn, startRow } = range;
1898
+ for (let col = startColumn; col <= endColumn; col++) {
1899
+ const key = `sheets-filter-button-${col}`;
1900
+ const startPosition = getCoordByCell(startRow, col, scene, skeleton);
1901
+ const cellStyle = worksheet.getComposedCellStyle(startRow, col);
1902
+ const verticalAlign = (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.vt) || VerticalAlign.BOTTOM;
1903
+ const { startX, startY, endX, endY } = startPosition;
1904
+ const cellWidth = endX - startX;
1905
+ const cellHeight = endY - startY;
1906
+ if (cellHeight <= 1 || cellWidth <= 1) continue;
1907
+ const hasCriteria = !!filterModel.getFilterColumn(col);
1908
+ const props = {
1909
+ left: endX - 16 - 1,
1910
+ top: computeIconTop(startY, endY, cellHeight, verticalAlign),
1911
+ height: 16,
1912
+ width: 16,
1913
+ zIndex: SHEETS_FILTER_BUTTON_Z_INDEX,
1914
+ cellHeight,
1915
+ cellWidth,
1916
+ filterParams: {
1917
+ unitId,
1918
+ subUnitId: worksheetId,
1919
+ col,
1920
+ hasCriteria
1921
+ }
1922
+ };
1923
+ const buttonShape = this._injector.createInstance(SheetsFilterButtonShape, key, props);
1924
+ this._filterButtonShapes.push(buttonShape);
1925
+ }
1926
+ scene.addObjects(this._filterButtonShapes);
1927
+ scene.makeDirty();
1928
+ }
1929
+ _interceptCellContent(workbookId, worksheetId, range) {
1930
+ const { startRow, startColumn, endColumn } = range;
1931
+ this._buttonRenderDisposable = this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
1932
+ effect: InterceptorEffectEnum.Style,
1933
+ handler: (cell, pos, next) => {
1934
+ const { row, col, unitId, subUnitId } = pos;
1935
+ if (unitId !== workbookId || subUnitId !== worksheetId || row !== startRow || col < startColumn || col > endColumn) return next(cell);
1936
+ if (!cell || cell === pos.rawData) cell = { ...pos.rawData };
1937
+ cell.fontRenderExtension = {
1938
+ ...cell === null || cell === void 0 ? void 0 : cell.fontRenderExtension,
1939
+ rightOffset: 16
1940
+ };
1941
+ return next(cell);
1942
+ },
1943
+ priority: 10
1944
+ });
1945
+ }
1946
+ _disposeRendering() {
1947
+ var _this$_filterRangeSha, _this$_buttonRenderDi;
1948
+ (_this$_filterRangeSha = this._filterRangeShape) === null || _this$_filterRangeSha === void 0 || _this$_filterRangeSha.dispose();
1949
+ this._filterButtonShapes.forEach((s) => s.dispose());
1950
+ (_this$_buttonRenderDi = this._buttonRenderDisposable) === null || _this$_buttonRenderDi === void 0 || _this$_buttonRenderDi.dispose();
1951
+ this._filterRangeShape = null;
1952
+ this._buttonRenderDisposable = null;
1953
+ this._filterButtonShapes = [];
1954
+ }
1955
+ };
1956
+ SheetsFilterRenderController = __decorate([
1957
+ __decorateParam(1, Inject(Injector)),
1958
+ __decorateParam(2, Inject(SheetSkeletonManagerService)),
1959
+ __decorateParam(3, Inject(SheetsFilterService)),
1960
+ __decorateParam(4, Inject(ThemeService)),
1961
+ __decorateParam(5, Inject(SheetInterceptorService)),
1962
+ __decorateParam(6, ICommandService),
1963
+ __decorateParam(7, ISheetSelectionRenderService)
1964
+ ], SheetsFilterRenderController);
1965
+
1966
+ //#endregion
1967
+ //#region src/controllers/sheets-filter-ui-mobile.controller.ts
1968
+ let SheetsFilterUIMobileController = class SheetsFilterUIMobileController extends RxDisposable {
1969
+ constructor(_renderManagerService, _sheetsRenderService) {
1970
+ super();
1971
+ this._renderManagerService = _renderManagerService;
1972
+ this._sheetsRenderService = _sheetsRenderService;
1973
+ [
1974
+ SetSheetsFilterRangeMutation,
1975
+ SetSheetsFilterCriteriaMutation,
1976
+ RemoveSheetsFilterMutation,
1977
+ ReCalcSheetsFilterMutation
1978
+ ].forEach((m) => this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(m.id)));
1979
+ this.disposeWithMe(this._renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SHEET, [SheetsFilterRenderController]));
1980
+ }
1981
+ };
1982
+ SheetsFilterUIMobileController = __decorate([__decorateParam(0, IRenderManagerService), __decorateParam(1, Inject(SheetsRenderService))], SheetsFilterUIMobileController);
1983
+
1984
+ //#endregion
1985
+ //#region src/mobile-plugin.ts
1986
+ let UniverSheetsFilterMobileUIPlugin = class UniverSheetsFilterMobileUIPlugin extends Plugin {
1987
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
1988
+ super();
1989
+ this._config = _config;
1990
+ this._injector = _injector;
1991
+ this._configService = _configService;
1992
+ const { menu, ...rest } = merge({}, defaultPluginConfig, this._config);
1993
+ if (menu) this._configService.setConfig("menu", menu, { merge: true });
1994
+ this._configService.setConfig(SHEETS_FILTER_UI_PLUGIN_CONFIG_KEY, rest);
1995
+ }
1996
+ onStarting() {
1997
+ [[SheetsFilterPermissionController], [SheetsFilterUIMobileController]].forEach((d) => this._injector.add(d));
1998
+ }
1999
+ onReady() {
2000
+ this._injector.get(SheetsFilterPermissionController);
2001
+ }
2002
+ onRendered() {
2003
+ this._injector.get(SheetsFilterUIMobileController);
2004
+ }
2005
+ };
2006
+ _defineProperty(UniverSheetsFilterMobileUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
2007
+ _defineProperty(UniverSheetsFilterMobileUIPlugin, "pluginName", "SHEET_FILTER_UI_PLUGIN");
2008
+ _defineProperty(UniverSheetsFilterMobileUIPlugin, "packageName", name);
2009
+ _defineProperty(UniverSheetsFilterMobileUIPlugin, "version", version);
2010
+ UniverSheetsFilterMobileUIPlugin = __decorate([
2011
+ DependentOn(UniverSheetsFilterPlugin),
2012
+ __decorateParam(1, Inject(Injector)),
2013
+ __decorateParam(2, IConfigService)
2014
+ ], UniverSheetsFilterMobileUIPlugin);
2015
+
2016
+ //#endregion
2017
+ //#region src/menu/sheets-filter.menu.ts
2018
+ function SmartToggleFilterMenuItemFactory(accessor) {
2019
+ const sheetsFilterService = accessor.get(SheetsFilterService);
2020
+ return {
2021
+ id: SmartToggleSheetsFilterCommand.id,
2022
+ type: MenuItemType.BUTTON_SELECTOR,
2023
+ icon: "FilterIcon",
2024
+ tooltip: "sheets-filter.toolbar.smart-toggle-filter-tooltip",
2025
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
2026
+ activated$: sheetsFilterService.activeFilterModel$.pipe(map((model) => !!model)),
2027
+ disabled$: getObservableWithExclusiveRange$(accessor, getCurrentRangeDisable$(accessor, {
2028
+ worksheetTypes: [WorksheetFilterPermission, WorksheetViewPermission],
2029
+ rangeTypes: [RangeProtectionPermissionViewPoint]
2030
+ }))
2031
+ };
2032
+ }
2033
+ function ClearFilterCriteriaMenuItemFactory(accessor) {
2034
+ const sheetsFilterService = accessor.get(SheetsFilterService);
2035
+ return {
2036
+ id: ClearSheetsFilterCriteriaCommand.id,
2037
+ type: MenuItemType.BUTTON,
2038
+ title: "sheets-filter.toolbar.clear-filter-criteria",
2039
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
2040
+ disabled$: sheetsFilterService.activeFilterModel$.pipe(switchMap((model) => {
2041
+ var _model$hasCriteria$$p;
2042
+ return (_model$hasCriteria$$p = model === null || model === void 0 ? void 0 : model.hasCriteria$.pipe(map((m) => !m))) !== null && _model$hasCriteria$$p !== void 0 ? _model$hasCriteria$$p : of(true);
2043
+ }))
2044
+ };
2045
+ }
2046
+ function ReCalcFilterMenuItemFactory(accessor) {
2047
+ const sheetsFilterService = accessor.get(SheetsFilterService);
2048
+ return {
2049
+ id: ReCalcSheetsFilterCommand.id,
2050
+ type: MenuItemType.BUTTON,
2051
+ title: "sheets-filter.toolbar.re-calc-filter-conditions",
2052
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
2053
+ disabled$: sheetsFilterService.activeFilterModel$.pipe(switchMap((model) => {
2054
+ var _model$hasCriteria$$p2;
2055
+ return (_model$hasCriteria$$p2 = model === null || model === void 0 ? void 0 : model.hasCriteria$.pipe(map((m) => !m))) !== null && _model$hasCriteria$$p2 !== void 0 ? _model$hasCriteria$$p2 : of(true);
2056
+ }))
2057
+ };
2058
+ }
2059
+
2060
+ //#endregion
2061
+ //#region src/menu/schema.ts
2062
+ const menuSchema = { [RibbonDataGroup.ORGANIZATION]: { [SmartToggleSheetsFilterCommand.id]: {
2063
+ order: 2,
2064
+ menuItemFactory: SmartToggleFilterMenuItemFactory,
2065
+ [ClearSheetsFilterCriteriaCommand.id]: {
2066
+ order: 0,
2067
+ menuItemFactory: ClearFilterCriteriaMenuItemFactory
2068
+ },
2069
+ [ReCalcSheetsFilterCommand.id]: {
2070
+ order: 1,
2071
+ menuItemFactory: ReCalcFilterMenuItemFactory
2072
+ }
2073
+ } } };
2074
+
2075
+ //#endregion
2076
+ //#region src/views/components/SheetsFilterByColorsPanel.tsx
2077
+ /**
2078
+ * Filter by colors.
2079
+ */
2080
+ function FilterByColor(props) {
2081
+ const { model } = props;
2082
+ const localeService = useDependency(LocaleService);
2083
+ const cellFillColors = useObservable(model.cellFillColors$, [], true);
2084
+ const cellTextColors = useObservable(model.cellTextColors$, [], true);
2085
+ const handleSelectCellFillColor = useCallback((color) => {
2086
+ model.onFilterCheckToggled(color);
2087
+ }, [model]);
2088
+ const handleSelectCellTextColor = useCallback((color) => {
2089
+ model.onFilterCheckToggled(color, false);
2090
+ }, [model]);
2091
+ return /* @__PURE__ */ jsx("div", {
2092
+ "data-u-comp": "sheets-filter-panel-colors-container",
2093
+ className: "univer-flex univer-h-full univer-min-h-[300px] univer-flex-col",
2094
+ children: /* @__PURE__ */ jsxs("div", {
2095
+ "data-u-comp": "sheets-filter-panel",
2096
+ className: clsx("univer-mt-2 univer-box-border univer-flex univer-h-[300px] univer-flex-grow univer-flex-col univer-gap-4 univer-overflow-auto univer-rounded-md univer-px-2 univer-py-2.5", borderClassName),
2097
+ children: [
2098
+ cellFillColors.length > 1 && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
2099
+ className: "univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white",
2100
+ children: localeService.t("sheets-filter.panel.filter-by-cell-fill-color")
2101
+ }), /* @__PURE__ */ jsx("div", {
2102
+ className: "univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2",
2103
+ children: cellFillColors.map((color, index) => /* @__PURE__ */ jsxs("div", {
2104
+ className: "univer-relative univer-size-6",
2105
+ onClick: () => handleSelectCellFillColor(color),
2106
+ children: [!color.color ? /* @__PURE__ */ jsx(BanIcon, { className: "univer-size-6 univer-cursor-pointer univer-rounded-full hover:univer-ring-2 hover:univer-ring-offset-2 hover:univer-ring-offset-white" }) : /* @__PURE__ */ jsx("button", {
2107
+ type: "button",
2108
+ className: clsx("univer-box-border univer-size-6 univer-cursor-pointer univer-rounded-full univer-border univer-border-solid univer-border-transparent univer-bg-gray-300 univer-transition-shadow hover:univer-ring-2 hover:univer-ring-offset-2 hover:univer-ring-offset-white"),
2109
+ style: { backgroundColor: color.color }
2110
+ }), color.checked && /* @__PURE__ */ jsx(CheckedIcon, {})]
2111
+ }, `sheets-filter-cell-fill-color-${index}`))
2112
+ })] }),
2113
+ cellTextColors.length > 1 && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
2114
+ className: "univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white",
2115
+ children: localeService.t("sheets-filter.panel.filter-by-cell-text-color")
2116
+ }), /* @__PURE__ */ jsx("div", {
2117
+ className: "univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2",
2118
+ children: cellTextColors.map((color, index) => /* @__PURE__ */ jsxs("div", {
2119
+ className: "univer-relative univer-size-6",
2120
+ onClick: () => handleSelectCellTextColor(color),
2121
+ children: [/* @__PURE__ */ jsx("div", {
2122
+ className: "univer-box-border univer-flex univer-size-full univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-full univer-border univer-border-solid univer-border-[rgba(13,13,13,0.06)] univer-p-0.5 hover:univer-ring-2 hover:univer-ring-offset-2 hover:univer-ring-offset-white dark:!univer-border-[rgba(255,255,255,0.06)]",
2123
+ children: /* @__PURE__ */ jsx(AIcon, { style: { color: color.color } })
2124
+ }), color.checked && /* @__PURE__ */ jsx(CheckedIcon, {})]
2125
+ }, `sheets-filter-cell-text-color-${index}`))
2126
+ })] }),
2127
+ cellFillColors.length <= 1 && cellTextColors.length <= 1 && /* @__PURE__ */ jsx("div", {
2128
+ className: "univer-flex univer-size-full univer-items-center univer-justify-center univer-text-sm univer-text-gray-900 dark:!univer-text-gray-200",
2129
+ children: localeService.t("sheets-filter.panel.filter-by-color-none")
2130
+ })
2131
+ ]
2132
+ })
2133
+ });
2134
+ }
2135
+ function CheckedIcon() {
2136
+ return /* @__PURE__ */ jsx("div", {
2137
+ className: "univer-absolute -univer-bottom-0.5 -univer-right-0.5 univer-flex univer-size-3 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-full univer-bg-white",
2138
+ children: /* @__PURE__ */ jsx(SuccessIcon, { className: "univer-size-full univer-font-bold univer-text-[#418F1F]" })
2139
+ });
2140
+ }
2141
+
2142
+ //#endregion
2143
+ //#region src/views/components/SheetsFilterByConditionsPanel.tsx
2144
+ /**
2145
+ * Filter by conditions.
2146
+ */
2147
+ function FilterByCondition(props) {
2148
+ var _formParams$val, _formParams$val2;
2149
+ const { model } = props;
2150
+ const localeService = useDependency(LocaleService);
2151
+ const condition = useObservable(model.conditionItem$, void 0);
2152
+ const formParams = useObservable(model.filterConditionFormParams$, void 0);
2153
+ const radioValue = (formParams === null || formParams === void 0 ? void 0 : formParams.and) ? "AND" : "OR";
2154
+ const onRadioChange = useCallback((key) => {
2155
+ model.onConditionFormChange({ and: key === "AND" });
2156
+ }, [model]);
2157
+ const primaryOptions = usePrimaryOptions(localeService);
2158
+ const onPrimaryConditionChange = useCallback((value) => {
2159
+ model.onPrimaryConditionChange(value);
2160
+ }, [model]);
2161
+ const secondaryOptions = useSecondaryOptions(localeService);
2162
+ const onFormParamsChange = useCallback((diffParams) => {
2163
+ model.onConditionFormChange(diffParams);
2164
+ }, [model]);
2165
+ const placeholder = localeService.t("sheets-filter.panel.input-values-placeholder");
2166
+ function renderSecondaryCondition(operator, val, name) {
2167
+ const shouldRenderInput = FilterConditionItems.getItemByOperator(operator).numOfParameters === 1;
2168
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2169
+ name === "operator2" && /* @__PURE__ */ jsxs(RadioGroup, {
2170
+ value: radioValue,
2171
+ onChange: onRadioChange,
2172
+ children: [/* @__PURE__ */ jsx(Radio, {
2173
+ value: "AND",
2174
+ children: localeService.t("sheets-filter.panel.and")
2175
+ }), /* @__PURE__ */ jsx(Radio, {
2176
+ value: "OR",
2177
+ children: localeService.t("sheets-filter.panel.or")
2178
+ })]
2179
+ }),
2180
+ /* @__PURE__ */ jsx(Select, {
2181
+ value: operator,
2182
+ options: secondaryOptions,
2183
+ onChange: (operator) => onFormParamsChange({ [name]: operator })
2184
+ }),
2185
+ shouldRenderInput && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Input, {
2186
+ className: "univer-mt-2",
2187
+ value: val,
2188
+ placeholder,
2189
+ onChange: (value) => onFormParamsChange({ [name === "operator1" ? "val1" : "val2"]: value })
2190
+ }) })
2191
+ ] });
2192
+ }
2193
+ return /* @__PURE__ */ jsx("div", {
2194
+ "data-u-comp": "sheets-filter-panel-conditions-container",
2195
+ className: "univer-flex univer-h-full univer-min-h-[300px] univer-flex-col",
2196
+ children: condition && formParams && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Select, {
2197
+ value: condition.operator,
2198
+ options: primaryOptions,
2199
+ onChange: onPrimaryConditionChange
2200
+ }), FilterConditionItems.getItemByOperator(condition.operator).numOfParameters !== 0 ? /* @__PURE__ */ jsxs("div", {
2201
+ "data-u-comp": "sheets-filter-panel-conditions-container-inner",
2202
+ className: clsx("univer-mt-2 univer-flex-grow univer-overflow-hidden univer-rounded-md univer-p-2", borderClassName),
2203
+ children: [
2204
+ condition.numOfParameters >= 1 && renderSecondaryCondition(formParams.operator1, (_formParams$val = formParams.val1) !== null && _formParams$val !== void 0 ? _formParams$val : "", "operator1"),
2205
+ condition.numOfParameters >= 2 && renderSecondaryCondition(formParams.operator2, (_formParams$val2 = formParams.val2) !== null && _formParams$val2 !== void 0 ? _formParams$val2 : "", "operator2"),
2206
+ /* @__PURE__ */ jsxs("div", {
2207
+ "data-u-comp": "sheets-filter-panel-conditions-desc",
2208
+ className: "univer-mt-2 univer-text-xs univer-text-gray-500",
2209
+ children: [
2210
+ localeService.t("sheets-filter.panel.?"),
2211
+ /* @__PURE__ */ jsx("br", {}),
2212
+ localeService.t("sheets-filter.panel.*")
2213
+ ]
2214
+ })
2215
+ ]
2216
+ }) : null] })
2217
+ });
2218
+ }
2219
+ function usePrimaryOptions(localeService) {
2220
+ return useMemo(() => [
2221
+ { options: [{
2222
+ label: localeService.t(FilterConditionItems.NONE.label),
2223
+ value: FilterConditionItems.NONE.operator
2224
+ }] },
2225
+ { options: [{
2226
+ label: localeService.t(FilterConditionItems.EMPTY.label),
2227
+ value: FilterConditionItems.EMPTY.operator
2228
+ }, {
2229
+ label: localeService.t(FilterConditionItems.NOT_EMPTY.label),
2230
+ value: FilterConditionItems.NOT_EMPTY.operator
2231
+ }] },
2232
+ { options: [
2233
+ {
2234
+ label: localeService.t(FilterConditionItems.TEXT_CONTAINS.label),
2235
+ value: FilterConditionItems.TEXT_CONTAINS.operator
2236
+ },
2237
+ {
2238
+ label: localeService.t(FilterConditionItems.DOES_NOT_CONTAIN.label),
2239
+ value: FilterConditionItems.DOES_NOT_CONTAIN.operator
2240
+ },
2241
+ {
2242
+ label: localeService.t(FilterConditionItems.STARTS_WITH.label),
2243
+ value: FilterConditionItems.STARTS_WITH.operator
2244
+ },
2245
+ {
2246
+ label: localeService.t(FilterConditionItems.ENDS_WITH.label),
2247
+ value: FilterConditionItems.ENDS_WITH.operator
2248
+ },
2249
+ {
2250
+ label: localeService.t(FilterConditionItems.EQUALS.label),
2251
+ value: FilterConditionItems.EQUALS.operator
2252
+ }
2253
+ ] },
2254
+ { options: [
2255
+ {
2256
+ label: localeService.t(FilterConditionItems.GREATER_THAN.label),
2257
+ value: FilterConditionItems.GREATER_THAN.operator
2258
+ },
2259
+ {
2260
+ label: localeService.t(FilterConditionItems.GREATER_THAN_OR_EQUAL.label),
2261
+ value: FilterConditionItems.GREATER_THAN_OR_EQUAL.operator
2262
+ },
2263
+ {
2264
+ label: localeService.t(FilterConditionItems.LESS_THAN.label),
2265
+ value: FilterConditionItems.LESS_THAN.operator
2266
+ },
2267
+ {
2268
+ label: localeService.t(FilterConditionItems.LESS_THAN_OR_EQUAL.label),
2269
+ value: FilterConditionItems.LESS_THAN_OR_EQUAL.operator
2270
+ },
2271
+ {
2272
+ label: localeService.t(FilterConditionItems.EQUAL.label),
2273
+ value: FilterConditionItems.EQUAL.operator
2274
+ },
2275
+ {
2276
+ label: localeService.t(FilterConditionItems.NOT_EQUAL.label),
2277
+ value: FilterConditionItems.NOT_EQUAL.operator
2278
+ },
2279
+ {
2280
+ label: localeService.t(FilterConditionItems.BETWEEN.label),
2281
+ value: FilterConditionItems.BETWEEN.operator
2282
+ },
2283
+ {
2284
+ label: localeService.t(FilterConditionItems.NOT_BETWEEN.label),
2285
+ value: FilterConditionItems.NOT_BETWEEN.operator
2286
+ }
2287
+ ] },
2288
+ { options: [{
2289
+ label: localeService.t(FilterConditionItems.CUSTOM.label),
2290
+ value: FilterConditionItems.CUSTOM.operator
2291
+ }] }
2292
+ ], [localeService.getCurrentLocale(), localeService]);
2293
+ }
2294
+ function useSecondaryOptions(localeService) {
2295
+ return useMemo(() => FilterConditionItems.ALL_CONDITIONS.filter((c) => c.numOfParameters !== 2).map((c) => ({
2296
+ label: localeService.t(c.label),
2297
+ value: c.operator
2298
+ })), [localeService.getCurrentLocale(), localeService]);
2299
+ }
2300
+
2301
+ //#endregion
2302
+ //#region src/views/components/SheetsFilterByValuesPanel.tsx
2303
+ /**
2304
+ * Filter by values.
2305
+ */
2306
+ function FilterByValue(props) {
2307
+ const { model } = props;
2308
+ const localeService = useDependency(LocaleService);
2309
+ const searchText = useObservable(model.searchString$, "", true);
2310
+ const items = useObservable(model.filterItems$, void 0, true);
2311
+ const filterOnly = localeService.t("sheets-filter.panel.filter-only");
2312
+ const stat = statisticFilterByValueItems(items);
2313
+ const allChecked = stat.checked > 0 && stat.unchecked === 0;
2314
+ const indeterminate = stat.checked > 0 && stat.unchecked > 0;
2315
+ const treeMap = model.treeMapCache;
2316
+ const onCheckAllToggled = useCallback(() => {
2317
+ model.onCheckAllToggled(!allChecked);
2318
+ }, [model, allChecked]);
2319
+ const onSearchValueChange = useCallback((str) => {
2320
+ model.setSearchString(str);
2321
+ }, [model]);
2322
+ function extractCheckedKeys(items) {
2323
+ let checkedKeys = [];
2324
+ items.forEach((item) => {
2325
+ if (item.checked) checkedKeys.push(item.key);
2326
+ if (item.children) checkedKeys = checkedKeys.concat(extractCheckedKeys(item.children));
2327
+ });
2328
+ return checkedKeys;
2329
+ }
2330
+ return /* @__PURE__ */ jsxs("div", {
2331
+ "data-u-comp": "sheets-filter-panel-values-container",
2332
+ className: "univer-flex univer-h-full univer-min-h-[300px] univer-flex-col",
2333
+ children: [/* @__PURE__ */ jsx(Input, {
2334
+ autoFocus: true,
2335
+ value: searchText,
2336
+ placeholder: localeService.t("sheets-filter.panel.search-placeholder"),
2337
+ onChange: onSearchValueChange
2338
+ }), /* @__PURE__ */ jsxs("div", {
2339
+ "data-u-comp": "sheets-filter-panel",
2340
+ className: clsx("univer-mt-2 univer-box-border univer-flex univer-flex-grow univer-flex-col univer-overflow-hidden univer-rounded-md univer-px-2 univer-py-2.5", borderClassName),
2341
+ children: [/* @__PURE__ */ jsx("div", {
2342
+ "data-u-comp": "sheets-filter-panel-values-item",
2343
+ className: "univer-box-border univer-h-8 univer-w-full univer-py-0.5",
2344
+ children: /* @__PURE__ */ jsxs("div", {
2345
+ "data-u-comp": "sheets-filter-panel-values-item-inner",
2346
+ className: "univer-box-border univer-flex univer-h-7 univer-items-center univer-rounded-md univer-py-0 univer-pl-5 univer-pr-0.5 univer-text-sm",
2347
+ children: [
2348
+ /* @__PURE__ */ jsx(Checkbox, {
2349
+ indeterminate,
2350
+ disabled: items.length === 0,
2351
+ checked: allChecked,
2352
+ onChange: onCheckAllToggled
2353
+ }),
2354
+ /* @__PURE__ */ jsx("span", {
2355
+ "data-u-comp": "sheets-filter-panel-values-item-text",
2356
+ className: "univer-mx-1 univer-inline-block univer-flex-shrink univer-truncate univer-text-gray-900 dark:!univer-text-white",
2357
+ children: `${localeService.t("sheets-filter.panel.select-all")}`
2358
+ }),
2359
+ /* @__PURE__ */ jsx("span", {
2360
+ "data-u-comp": "sheets-filter-panel-values-item-count",
2361
+ className: "univer-text-gray-400 dark:!univer-text-gray-500",
2362
+ children: `(${stat.checked}/${stat.checked + stat.unchecked})`
2363
+ })
2364
+ ]
2365
+ })
2366
+ }), /* @__PURE__ */ jsx("div", {
2367
+ "data-u-comp": "sheets-filter-panel-values-virtual",
2368
+ className: "univer-flex-grow",
2369
+ children: /* @__PURE__ */ jsx(Tree, {
2370
+ data: items,
2371
+ defaultExpandAll: false,
2372
+ valueGroup: extractCheckedKeys(items),
2373
+ onChange: (node) => {
2374
+ model.onFilterCheckToggled(node);
2375
+ },
2376
+ defaultCache: treeMap,
2377
+ itemHeight: 28,
2378
+ treeNodeClassName: `
2
2379
  univer-pr-2 univer-border-box univer-rounded-md
3
2380
  [&:hover_a]:univer-inline-block
4
2381
  hover:univer-bg-gray-50 univer-h-full
5
2382
  univer-text-gray-900 dark:hover:!univer-bg-gray-900
6
2383
  dark:!univer-text-white
7
- `,attachRender:e=>z(`div`,{className:`univer-ml-1 univer-flex univer-h-5 univer-flex-1 univer-cursor-pointer univer-items-center univer-justify-between univer-text-sm univer-text-primary-500`,children:[R(`span`,{"data-u-comp":`sheets-filter-panel-values-item-count`,className:`univer-text-gray-400 dark:!univer-text-gray-500`,children:`(${e.count})`}),R(`a`,{className:`univer-box-border univer-hidden univer-h-4 univer-whitespace-nowrap univer-px-1.5`,onClick:()=>{let n=[];e.children?e.children.forEach(e=>{e.children?e.children.forEach(e=>{n.push(e.key)}):n.push(e.key)}):n.push(e.key),t.onFilterOnly(n)},children:a})]})})})]})]})}function Cn(){let e=k(pe);if(!A(e.visible$,void 0,!0))return null;let t=k(p),n=k(Me),r=A(e.enabled$,void 0,!0);return z(`div`,{className:`univer-mt-2 univer-flex univer-items-center univer-justify-between univer-text-sm univer-text-gray-900 dark:!univer-text-gray-200`,children:[z(`div`,{className:`univer-flex univer-items-center univer-gap-1`,children:[R(`span`,{children:t.t(`sheets-filter.sync.title`)}),R(St,{title:r?t.t(`sheets-filter.sync.statusTips.off`):t.t(`sheets-filter.sync.statusTips.on`),asChild:!0,children:R(kt,{className:`univer-block`})})]}),R(xt,{defaultChecked:r,onChange:r=>{let i=r?t.t(`sheets-filter.sync.switchTips.on`):t.t(`sheets-filter.sync.switchTips.off`);e.setEnabled(r),n.show({content:i,type:gt.Success,duration:2e3})}})]})}function wn(){var e;let t=k(J),n=k(p),r=k(a),i=A(t.filterBy$,void 0,!0),o=A(t.filterByModel$,void 0,!1),s=A(()=>(o==null?void 0:o.canApply$)||I(!1),void 0,!1,[o]),c=Tn(n),l=!A(t.hasCriteria$),u=L(e=>{r.executeCommand(tn.id,{filterBy:e})},[r]),d=L(async()=>{await(o==null?void 0:o.clear()),r.executeCommand(Y.id)},[o,r]),f=L(()=>{r.executeCommand(Y.id)},[r]),m=L(async()=>{await(o==null?void 0:o.apply()),r.executeCommand(Y.id)},[o,r]),h=(e=k(O).activeFilterModel)==null?void 0:e.getRange(),g=t.col,_=ze(Ce.FILTER_PANEL_EMBED_POINT);return z(`div`,{"data-u-comp":`sheets-filter-panel`,className:`univer-box-border univer-flex univer-max-h-[500px] univer-w-[400px] univer-flex-col univer-rounded-lg univer-bg-white univer-p-4 univer-shadow-lg dark:!univer-border-gray-600 dark:!univer-bg-gray-700`,children:[R(Oe,{components:_,sharedProps:{range:h,colIndex:g,onClose:f}}),R(`div`,{className:`univer-mb-1 univer-flex-shrink-0 univer-flex-grow-0`,children:R(yt,{value:i,items:c,onChange:e=>u(e)})}),o?R(`div`,{"data-u-comp":`sheets-filter-panel-content`,className:`univer-flex-shrink univer-flex-grow univer-pt-2`,children:i===E.VALUES?R(Sn,{model:o}):i===E.COLORS?R(_n,{model:o}):R(yn,{model:o})}):R(`div`,{className:`univer-flex-1`}),R(Cn,{}),z(`div`,{"data-u-comp":`sheets-filter-panel-footer`,className:`univer-mt-4 univer-inline-flex univer-flex-shrink-0 univer-flex-grow-0 univer-flex-nowrap univer-justify-between univer-overflow-hidden`,children:[R(pt,{variant:`link`,onClick:d,disabled:l,children:n.t(`sheets-filter.panel.clear-filter`)}),z(`span`,{className:`univer-flex univer-gap-2`,children:[R(pt,{variant:`default`,onClick:f,children:n.t(`sheets-filter.panel.cancel`)}),R(pt,{disabled:!s,variant:`primary`,onClick:m,children:n.t(`sheets-filter.panel.confirm`)})]})]})]})}function Tn(e){return jt(()=>[{label:e.t(`sheets-filter.panel.by-values`),value:E.VALUES},{label:e.t(`sheets-filter.panel.by-colors`),value:E.COLORS},{label:e.t(`sheets-filter.panel.by-conditions`),value:E.CONDITIONS}],[e.getCurrentLocale(),e])}const En={id:me.id,binding:Pe.L|Ie.CTRL_COMMAND|Ie.SHIFT,description:`sheets-filter.shortcut.smart-toggle-filter`,preconditions:De,group:`4_sheet-edit`},Dn=`FILTER_PANEL_POPUP`;let On=class extends fn{constructor(e,t,n,r,i,a,o,s,c,l,u,d,f){super(f,d),this._injector=e,this._componentManager=t,this._sheetsFilterPanelService=n,this._sheetCanvasPopupService=r,this._sheetsFilterService=i,this._localeService=a,this._shortcutService=o,this._commandService=s,this._menuManagerService=c,this._contextService=l,this._messageService=u,q(this,`_popupDisposable`,void 0),this._initCommands(),this._initShortcuts(),this._initMenuItems(),this._initUI()}dispose(){super.dispose(),this._closeFilterPopup()}_initShortcuts(){[En].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_initCommands(){[me,ce,ue,D,ie,oe,tn,en,Y].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenuItems(){this._menuManagerService.mergeMenu(gn)}_initUI(){[[Dn,wn],[`FilterIcon`,Ot]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))}),this.disposeWithMe(this._contextService.subscribeContextValue$($t).pipe(nt()).subscribe(e=>{e?this._openFilterPopup():this._closeFilterPopup()})),this.disposeWithMe(this._sheetsFilterService.errorMsg$.subscribe(e=>{e&&this._messageService.show({type:gt.Error,content:this._localeService.t(e)})}))}_openFilterPopup(){let e=this._sheetsFilterPanelService.filterModel;if(!e)throw Error(`[SheetsFilterUIController]: no filter model when opening filter popup!`);let t=e.getRange(),n=this._sheetsFilterPanelService.col,{startRow:r}=t;this._popupDisposable=this._sheetCanvasPopupService.attachPopupToCell(r,n,{componentKey:Dn,direction:`horizontal`,onClickOutside:()=>this._commandService.syncExecuteCommand(Y.id),offset:[5,0]})}_closeFilterPopup(){var e;(e=this._popupDisposable)==null||e.dispose(),this._popupDisposable=null}};On=G([W(0,u(d)),W(1,u(ke)),W(2,u(J)),W(3,u(be)),W(4,u(O)),W(5,u(p)),W(6,Ne),W(7,a),W(8,je),W(9,s),W(10,Me),W(11,u(Se)),W(12,Ve)],On);let Q=class extends h{constructor(e=on,t,n,r){super(),this._config=e,this._injector=t,this._configService=n,this._rpcChannelService=r;let{menu:i,...a}=w({},on,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(an,a)}onStarting(){ne(this._injector,[[J],[X],[On]]),this._config.useRemoteFilterValuesGenerator&&this._rpcChannelService&&this._injector.add([Ft,{useFactory:()=>ft(this._rpcChannelService.requestChannel(Pt))}])}onReady(){re(this._injector,[[X]])}onRendered(){re(this._injector,[[On]])}};q(Q,`type`,b.UNIVER_SHEET),q(Q,`pluginName`,`SHEET_FILTER_UI_PLUGIN`),q(Q,`packageName`,nn),q(Q,`version`,rn),Q=G([r(he),W(1,u(d)),W(2,o),W(3,m(ut))],Q);let $=class extends h{constructor(e,t,n){super(),this._config=e,this._injector=t,this._rpcChannelService=n}onStarting(){[[Ft,{useClass:It}]].forEach(e=>this._injector.add(e))}onReady(){this._rpcChannelService.registerChannel(Pt,dt(this._injector.get(Ft)))}};q($,`type`,b.UNIVER_SHEET),q($,`pluginName`,`SHEET_FILTER_UI_WORKER_PLUGIN`),q($,`packageName`,nn),q($,`version`,rn),$=G([W(1,u(d)),W(2,ut)],$);export{tn as ChangeFilterByOperation,Y as CloseFilterPanelOperation,en as OpenFilterPanelOperation,Z as UniverSheetsFilterMobileUIPlugin,Q as UniverSheetsFilterUIPlugin,$ as UniverSheetsFilterUIWorkerPlugin};
2384
+ `,
2385
+ attachRender: (item) => /* @__PURE__ */ jsxs("div", {
2386
+ className: "univer-ml-1 univer-flex univer-h-5 univer-flex-1 univer-cursor-pointer univer-items-center univer-justify-between univer-text-sm univer-text-primary-500",
2387
+ children: [/* @__PURE__ */ jsx("span", {
2388
+ "data-u-comp": "sheets-filter-panel-values-item-count",
2389
+ className: "univer-text-gray-400 dark:!univer-text-gray-500",
2390
+ children: `(${item.count})`
2391
+ }), /* @__PURE__ */ jsx("a", {
2392
+ className: "univer-box-border univer-hidden univer-h-4 univer-whitespace-nowrap univer-px-1.5",
2393
+ onClick: () => {
2394
+ const filterValues = [];
2395
+ if (item.children) item.children.forEach((child) => {
2396
+ if (child.children) child.children.forEach((subChild) => {
2397
+ filterValues.push(subChild.key);
2398
+ });
2399
+ else filterValues.push(child.key);
2400
+ });
2401
+ else filterValues.push(item.key);
2402
+ model.onFilterOnly(filterValues);
2403
+ },
2404
+ children: filterOnly
2405
+ })]
2406
+ })
2407
+ })
2408
+ })]
2409
+ })]
2410
+ });
2411
+ }
2412
+
2413
+ //#endregion
2414
+ //#region src/views/components/SheetsFilterSyncSwitch.tsx
2415
+ /**
2416
+ * Copyright 2023-present DreamNum Co., Ltd.
2417
+ *
2418
+ * Licensed under the Apache License, Version 2.0 (the "License");
2419
+ * you may not use this file except in compliance with the License.
2420
+ * You may obtain a copy of the License at
2421
+ *
2422
+ * http://www.apache.org/licenses/LICENSE-2.0
2423
+ *
2424
+ * Unless required by applicable law or agreed to in writing, software
2425
+ * distributed under the License is distributed on an "AS IS" BASIS,
2426
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2427
+ * See the License for the specific language governing permissions and
2428
+ * limitations under the License.
2429
+ */
2430
+ function FilterSyncSwitch() {
2431
+ const sheetsFilterSyncController = useDependency(SheetsFilterSyncController);
2432
+ if (!useObservable(sheetsFilterSyncController.visible$, void 0, true)) return null;
2433
+ const localeService = useDependency(LocaleService);
2434
+ const messageService = useDependency(IMessageService);
2435
+ const enabled = useObservable(sheetsFilterSyncController.enabled$, void 0, true);
2436
+ return /* @__PURE__ */ jsxs("div", {
2437
+ className: "univer-mt-2 univer-flex univer-items-center univer-justify-between univer-text-sm univer-text-gray-900 dark:!univer-text-gray-200",
2438
+ children: [/* @__PURE__ */ jsxs("div", {
2439
+ className: "univer-flex univer-items-center univer-gap-1",
2440
+ children: [/* @__PURE__ */ jsx("span", { children: localeService.t("sheets-filter.sync.title") }), /* @__PURE__ */ jsx(Tooltip, {
2441
+ title: enabled ? localeService.t("sheets-filter.sync.statusTips.off") : localeService.t("sheets-filter.sync.statusTips.on"),
2442
+ asChild: true,
2443
+ children: /* @__PURE__ */ jsx(InfoIcon, { className: "univer-block" })
2444
+ })]
2445
+ }), /* @__PURE__ */ jsx(Switch, {
2446
+ defaultChecked: enabled,
2447
+ onChange: (checked) => {
2448
+ const message = checked ? localeService.t("sheets-filter.sync.switchTips.on") : localeService.t("sheets-filter.sync.switchTips.off");
2449
+ sheetsFilterSyncController.setEnabled(checked);
2450
+ messageService.show({
2451
+ content: message,
2452
+ type: MessageType.Success,
2453
+ duration: 2e3
2454
+ });
2455
+ }
2456
+ })]
2457
+ });
2458
+ }
2459
+
2460
+ //#endregion
2461
+ //#region src/views/components/SheetsFilterPanel.tsx
2462
+ /**
2463
+ * This Filter Panel component is used to filter the data in the sheet.
2464
+ *
2465
+ * @returns React element
2466
+ */
2467
+ function FilterPanel() {
2468
+ var _filterService$active;
2469
+ const sheetsFilterPanelService = useDependency(SheetsFilterPanelService);
2470
+ const localeService = useDependency(LocaleService);
2471
+ const commandService = useDependency(ICommandService);
2472
+ const filterBy = useObservable(sheetsFilterPanelService.filterBy$, void 0, true);
2473
+ const filterByModel = useObservable(sheetsFilterPanelService.filterByModel$, void 0, false);
2474
+ const canApply = useObservable(() => (filterByModel === null || filterByModel === void 0 ? void 0 : filterByModel.canApply$) || of(false), void 0, false, [filterByModel]);
2475
+ const items = useFilterByOptions(localeService);
2476
+ const clearFilterDisabled = !useObservable(sheetsFilterPanelService.hasCriteria$);
2477
+ const onFilterByTypeChange = useCallback((value) => {
2478
+ commandService.executeCommand(ChangeFilterByOperation.id, { filterBy: value });
2479
+ }, [commandService]);
2480
+ const onClearCriteria = useCallback(async () => {
2481
+ await (filterByModel === null || filterByModel === void 0 ? void 0 : filterByModel.clear());
2482
+ commandService.executeCommand(CloseFilterPanelOperation.id);
2483
+ }, [filterByModel, commandService]);
2484
+ const onCancel = useCallback(() => {
2485
+ commandService.executeCommand(CloseFilterPanelOperation.id);
2486
+ }, [commandService]);
2487
+ const onApply = useCallback(async () => {
2488
+ await (filterByModel === null || filterByModel === void 0 ? void 0 : filterByModel.apply());
2489
+ commandService.executeCommand(CloseFilterPanelOperation.id);
2490
+ }, [filterByModel, commandService]);
2491
+ const range = (_filterService$active = useDependency(SheetsFilterService).activeFilterModel) === null || _filterService$active === void 0 ? void 0 : _filterService$active.getRange();
2492
+ const colIndex = sheetsFilterPanelService.col;
2493
+ return /* @__PURE__ */ jsxs("div", {
2494
+ "data-u-comp": "sheets-filter-panel",
2495
+ className: "univer-box-border univer-flex univer-max-h-[500px] univer-w-[400px] univer-flex-col univer-rounded-lg univer-bg-white univer-p-4 univer-shadow-lg dark:!univer-border-gray-600 dark:!univer-bg-gray-700",
2496
+ children: [
2497
+ /* @__PURE__ */ jsx(ComponentContainer, {
2498
+ components: useComponentsOfPart(SheetsUIPart.FILTER_PANEL_EMBED_POINT),
2499
+ sharedProps: {
2500
+ range,
2501
+ colIndex,
2502
+ onClose: onCancel
2503
+ }
2504
+ }),
2505
+ /* @__PURE__ */ jsx("div", {
2506
+ className: "univer-mb-1 univer-flex-shrink-0 univer-flex-grow-0",
2507
+ children: /* @__PURE__ */ jsx(Segmented, {
2508
+ value: filterBy,
2509
+ items,
2510
+ onChange: (value) => onFilterByTypeChange(value)
2511
+ })
2512
+ }),
2513
+ filterByModel ? /* @__PURE__ */ jsx("div", {
2514
+ "data-u-comp": "sheets-filter-panel-content",
2515
+ className: "univer-flex-shrink univer-flex-grow univer-pt-2",
2516
+ children: filterBy === FilterBy.VALUES ? /* @__PURE__ */ jsx(FilterByValue, { model: filterByModel }) : filterBy === FilterBy.COLORS ? /* @__PURE__ */ jsx(FilterByColor, { model: filterByModel }) : /* @__PURE__ */ jsx(FilterByCondition, { model: filterByModel })
2517
+ }) : /* @__PURE__ */ jsx("div", { className: "univer-flex-1" }),
2518
+ /* @__PURE__ */ jsx(FilterSyncSwitch, {}),
2519
+ /* @__PURE__ */ jsxs("div", {
2520
+ "data-u-comp": "sheets-filter-panel-footer",
2521
+ className: "univer-mt-4 univer-inline-flex univer-flex-shrink-0 univer-flex-grow-0 univer-flex-nowrap univer-justify-between univer-overflow-hidden",
2522
+ children: [/* @__PURE__ */ jsx(Button, {
2523
+ variant: "link",
2524
+ onClick: onClearCriteria,
2525
+ disabled: clearFilterDisabled,
2526
+ children: localeService.t("sheets-filter.panel.clear-filter")
2527
+ }), /* @__PURE__ */ jsxs("span", {
2528
+ className: "univer-flex univer-gap-2",
2529
+ children: [/* @__PURE__ */ jsx(Button, {
2530
+ variant: "default",
2531
+ onClick: onCancel,
2532
+ children: localeService.t("sheets-filter.panel.cancel")
2533
+ }), /* @__PURE__ */ jsx(Button, {
2534
+ disabled: !canApply,
2535
+ variant: "primary",
2536
+ onClick: onApply,
2537
+ children: localeService.t("sheets-filter.panel.confirm")
2538
+ })]
2539
+ })]
2540
+ })
2541
+ ]
2542
+ });
2543
+ }
2544
+ function useFilterByOptions(localeService) {
2545
+ return useMemo(() => [
2546
+ {
2547
+ label: localeService.t("sheets-filter.panel.by-values"),
2548
+ value: FilterBy.VALUES
2549
+ },
2550
+ {
2551
+ label: localeService.t("sheets-filter.panel.by-colors"),
2552
+ value: FilterBy.COLORS
2553
+ },
2554
+ {
2555
+ label: localeService.t("sheets-filter.panel.by-conditions"),
2556
+ value: FilterBy.CONDITIONS
2557
+ }
2558
+ ], [localeService.getCurrentLocale(), localeService]);
2559
+ }
2560
+
2561
+ //#endregion
2562
+ //#region src/controllers/sheets-filter.shortcut.ts
2563
+ const SmartToggleFilterShortcut = {
2564
+ id: SmartToggleSheetsFilterCommand.id,
2565
+ binding: KeyCode.L | MetaKeys.CTRL_COMMAND | MetaKeys.SHIFT,
2566
+ description: "sheets-filter.shortcut.smart-toggle-filter",
2567
+ preconditions: whenSheetEditorFocused,
2568
+ group: "4_sheet-edit"
2569
+ };
2570
+
2571
+ //#endregion
2572
+ //#region src/controllers/sheets-filter-ui-desktop.controller.ts
2573
+ const FILTER_PANEL_POPUP_KEY = "FILTER_PANEL_POPUP";
2574
+ let SheetsFilterUIDesktopController = class SheetsFilterUIDesktopController extends SheetsFilterUIMobileController {
2575
+ constructor(_injector, _componentManager, _sheetsFilterPanelService, _sheetCanvasPopupService, _sheetsFilterService, _localeService, _shortcutService, _commandService, _menuManagerService, _contextService, _messageService, sheetsRenderService, renderManagerService) {
2576
+ super(renderManagerService, sheetsRenderService);
2577
+ this._injector = _injector;
2578
+ this._componentManager = _componentManager;
2579
+ this._sheetsFilterPanelService = _sheetsFilterPanelService;
2580
+ this._sheetCanvasPopupService = _sheetCanvasPopupService;
2581
+ this._sheetsFilterService = _sheetsFilterService;
2582
+ this._localeService = _localeService;
2583
+ this._shortcutService = _shortcutService;
2584
+ this._commandService = _commandService;
2585
+ this._menuManagerService = _menuManagerService;
2586
+ this._contextService = _contextService;
2587
+ this._messageService = _messageService;
2588
+ _defineProperty(this, "_popupDisposable", void 0);
2589
+ this._initCommands();
2590
+ this._initShortcuts();
2591
+ this._initMenuItems();
2592
+ this._initUI();
2593
+ }
2594
+ dispose() {
2595
+ super.dispose();
2596
+ this._closeFilterPopup();
2597
+ }
2598
+ _initShortcuts() {
2599
+ [SmartToggleFilterShortcut].forEach((shortcut) => {
2600
+ this.disposeWithMe(this._shortcutService.registerShortcut(shortcut));
2601
+ });
2602
+ }
2603
+ _initCommands() {
2604
+ [
2605
+ SmartToggleSheetsFilterCommand,
2606
+ RemoveSheetFilterCommand,
2607
+ SetSheetFilterRangeCommand,
2608
+ SetSheetsFilterCriteriaCommand,
2609
+ ClearSheetsFilterCriteriaCommand,
2610
+ ReCalcSheetsFilterCommand,
2611
+ ChangeFilterByOperation,
2612
+ OpenFilterPanelOperation,
2613
+ CloseFilterPanelOperation
2614
+ ].forEach((c) => {
2615
+ this.disposeWithMe(this._commandService.registerCommand(c));
2616
+ });
2617
+ }
2618
+ _initMenuItems() {
2619
+ this._menuManagerService.mergeMenu(menuSchema);
2620
+ }
2621
+ _initUI() {
2622
+ [[FILTER_PANEL_POPUP_KEY, FilterPanel], ["FilterIcon", FilterIcon]].forEach(([key, comp]) => {
2623
+ this.disposeWithMe(this._componentManager.register(key, comp));
2624
+ });
2625
+ this.disposeWithMe(this._contextService.subscribeContextValue$(FILTER_PANEL_OPENED_KEY).pipe(distinctUntilChanged()).subscribe((open) => {
2626
+ if (open) this._openFilterPopup();
2627
+ else this._closeFilterPopup();
2628
+ }));
2629
+ this.disposeWithMe(this._sheetsFilterService.errorMsg$.subscribe((content) => {
2630
+ if (content) this._messageService.show({
2631
+ type: MessageType.Error,
2632
+ content: this._localeService.t(content)
2633
+ });
2634
+ }));
2635
+ }
2636
+ _openFilterPopup() {
2637
+ const currentFilterModel = this._sheetsFilterPanelService.filterModel;
2638
+ if (!currentFilterModel) throw new Error("[SheetsFilterUIController]: no filter model when opening filter popup!");
2639
+ const range = currentFilterModel.getRange();
2640
+ const col = this._sheetsFilterPanelService.col;
2641
+ const { startRow } = range;
2642
+ this._popupDisposable = this._sheetCanvasPopupService.attachPopupToCell(startRow, col, {
2643
+ componentKey: FILTER_PANEL_POPUP_KEY,
2644
+ direction: "horizontal",
2645
+ onClickOutside: () => this._commandService.syncExecuteCommand(CloseFilterPanelOperation.id),
2646
+ offset: [5, 0]
2647
+ });
2648
+ }
2649
+ _closeFilterPopup() {
2650
+ var _this$_popupDisposabl;
2651
+ (_this$_popupDisposabl = this._popupDisposable) === null || _this$_popupDisposabl === void 0 || _this$_popupDisposabl.dispose();
2652
+ this._popupDisposable = null;
2653
+ }
2654
+ };
2655
+ SheetsFilterUIDesktopController = __decorate([
2656
+ __decorateParam(0, Inject(Injector)),
2657
+ __decorateParam(1, Inject(ComponentManager)),
2658
+ __decorateParam(2, Inject(SheetsFilterPanelService)),
2659
+ __decorateParam(3, Inject(SheetCanvasPopManagerService)),
2660
+ __decorateParam(4, Inject(SheetsFilterService)),
2661
+ __decorateParam(5, Inject(LocaleService)),
2662
+ __decorateParam(6, IShortcutService),
2663
+ __decorateParam(7, ICommandService),
2664
+ __decorateParam(8, IMenuManagerService),
2665
+ __decorateParam(9, IContextService),
2666
+ __decorateParam(10, IMessageService),
2667
+ __decorateParam(11, Inject(SheetsRenderService)),
2668
+ __decorateParam(12, IRenderManagerService)
2669
+ ], SheetsFilterUIDesktopController);
2670
+
2671
+ //#endregion
2672
+ //#region src/plugin.ts
2673
+ let UniverSheetsFilterUIPlugin = class UniverSheetsFilterUIPlugin extends Plugin {
2674
+ constructor(_config = defaultPluginConfig, _injector, _configService, _rpcChannelService) {
2675
+ super();
2676
+ this._config = _config;
2677
+ this._injector = _injector;
2678
+ this._configService = _configService;
2679
+ this._rpcChannelService = _rpcChannelService;
2680
+ const { menu, ...rest } = merge({}, defaultPluginConfig, this._config);
2681
+ if (menu) this._configService.setConfig("menu", menu, { merge: true });
2682
+ this._configService.setConfig(SHEETS_FILTER_UI_PLUGIN_CONFIG_KEY, rest);
2683
+ }
2684
+ onStarting() {
2685
+ registerDependencies(this._injector, [
2686
+ [SheetsFilterPanelService],
2687
+ [SheetsFilterPermissionController],
2688
+ [SheetsFilterUIDesktopController]
2689
+ ]);
2690
+ if (this._config.useRemoteFilterValuesGenerator && this._rpcChannelService) this._injector.add([ISheetsGenerateFilterValuesService, { useFactory: () => toModule(this._rpcChannelService.requestChannel(SHEETS_GENERATE_FILTER_VALUES_SERVICE_NAME)) }]);
2691
+ }
2692
+ onReady() {
2693
+ touchDependencies(this._injector, [[SheetsFilterPermissionController]]);
2694
+ }
2695
+ onRendered() {
2696
+ touchDependencies(this._injector, [[SheetsFilterUIDesktopController]]);
2697
+ }
2698
+ };
2699
+ _defineProperty(UniverSheetsFilterUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
2700
+ _defineProperty(UniverSheetsFilterUIPlugin, "pluginName", "SHEET_FILTER_UI_PLUGIN");
2701
+ _defineProperty(UniverSheetsFilterUIPlugin, "packageName", name);
2702
+ _defineProperty(UniverSheetsFilterUIPlugin, "version", version);
2703
+ UniverSheetsFilterUIPlugin = __decorate([
2704
+ DependentOn(UniverSheetsFilterPlugin),
2705
+ __decorateParam(1, Inject(Injector)),
2706
+ __decorateParam(2, IConfigService),
2707
+ __decorateParam(3, Optional(IRPCChannelService))
2708
+ ], UniverSheetsFilterUIPlugin);
2709
+
2710
+ //#endregion
2711
+ //#region src/worker/plugin.ts
2712
+ let UniverSheetsFilterUIWorkerPlugin = class UniverSheetsFilterUIWorkerPlugin extends Plugin {
2713
+ constructor(_config, _injector, _rpcChannelService) {
2714
+ super();
2715
+ this._config = _config;
2716
+ this._injector = _injector;
2717
+ this._rpcChannelService = _rpcChannelService;
2718
+ }
2719
+ onStarting() {
2720
+ [[ISheetsGenerateFilterValuesService, { useClass: SheetsGenerateFilterValuesService }]].forEach((d) => this._injector.add(d));
2721
+ }
2722
+ onReady() {
2723
+ this._rpcChannelService.registerChannel(SHEETS_GENERATE_FILTER_VALUES_SERVICE_NAME, fromModule(this._injector.get(ISheetsGenerateFilterValuesService)));
2724
+ }
2725
+ };
2726
+ _defineProperty(UniverSheetsFilterUIWorkerPlugin, "type", UniverInstanceType.UNIVER_SHEET);
2727
+ _defineProperty(UniverSheetsFilterUIWorkerPlugin, "pluginName", "SHEET_FILTER_UI_WORKER_PLUGIN");
2728
+ _defineProperty(UniverSheetsFilterUIWorkerPlugin, "packageName", name);
2729
+ _defineProperty(UniverSheetsFilterUIWorkerPlugin, "version", version);
2730
+ UniverSheetsFilterUIWorkerPlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IRPCChannelService)], UniverSheetsFilterUIWorkerPlugin);
2731
+
2732
+ //#endregion
2733
+ export { ChangeFilterByOperation, CloseFilterPanelOperation, OpenFilterPanelOperation, UniverSheetsFilterMobileUIPlugin, UniverSheetsFilterUIPlugin, UniverSheetsFilterUIWorkerPlugin };