@univerjs/sheets-filter-ui 0.19.0 → 0.20.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.
package/lib/cjs/index.js CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/sheets-filter`),n=require(`@univerjs/sheets-ui`),r=require(`@univerjs/ui`),i=require(`@univerjs/engine-render`),a=require(`@univerjs/sheets`),o=require(`rxjs`),s=require(`@univerjs/rpc`),c=require(`@univerjs/design`),l=require(`@univerjs/icons`),u=require(`react`),d=require(`react/jsx-runtime`),f=function(e){return e[e.FIRST=0]=`FIRST`,e[e.SECOND=1]=`SECOND`,e}({}),p=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}({}),m;(function(n){let r=n.NONE={label:`sheets-filter.conditions.none`,operator:p.NONE,order:f.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.NONE]: should not have initial form params!`)},testMappingParams:e=>e.operator1===p.NONE,mapToFilterColumn:()=>null,testMappingFilterColumn:e=>!e.customFilters&&!e.filters?{}:!1},i=n.ALL_CONDITIONS=[r,n.EMPTY={label:`sheets-filter.conditions.empty`,operator:p.EMPTY,order:f.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.EMPTY]: should not have initial form params!`)},testMappingParams:({operator1:e})=>e===p.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:p.EMPTY}:!1}},n.NOT_EMPTY={label:`sheets-filter.conditions.not-empty`,operator:p.NOT_EMPTY,order:f.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.NOT_EMPTY]: should not have initial form params!`)},testMappingParams:({operator1:e})=>e===p.NOT_EMPTY,mapToFilterColumn:()=>({customFilters:{customFilters:[{val:``,operator:t.CustomFilterOperator.NOT_EQUALS}]}}),testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.val===` `&&r.operator===t.CustomFilterOperator.NOT_EQUALS?{operator1:p.NOT_EMPTY}:!1}},n.TEXT_CONTAINS={label:`sheets-filter.conditions.text-contains`,operator:p.CONTAINS,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.CONTAINS,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.CONTAINS,val1:r.slice(1,-1)}:!1}},n.DOES_NOT_CONTAIN={label:`sheets-filter.conditions.does-not-contain`,operator:p.DOES_NOT_CONTAIN,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.DOES_NOT_CONTAIN,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`*${e.val1}*`,operator:t.CustomFilterOperator.NOT_EQUALS}]}}),testMappingParams:e=>{let[t]=h(e);return t===p.DOES_NOT_CONTAIN},testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0],i=r.val.toString();return r.operator===t.CustomFilterOperator.NOT_EQUALS&&i.startsWith(`*`)&&i.endsWith(`*`)?{operator1:p.DOES_NOT_CONTAIN,val1:i.slice(1,-1)}:!1}},n.STARTS_WITH={label:`sheets-filter.conditions.starts-with`,operator:p.STARTS_WITH,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.STARTS_WITH,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`${e.val1}*`}]}}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.STARTS_WITH,val1:r.slice(0,-1)}:!1}},n.ENDS_WITH={label:`sheets-filter.conditions.ends-with`,operator:p.ENDS_WITH,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.ENDS_WITH,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`*${e.val1}`}]}}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.ENDS_WITH,val1:r.slice(1)}:!1}},n.EQUALS={label:`sheets-filter.conditions.equals`,operator:p.EQUALS,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.EQUALS,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.EQUALS,val1:``}:((n=e.customFilters)==null?void 0:n.customFilters.length)===1&&!e.customFilters.customFilters[0].operator?{operator1:p.EQUALS,val1:e.customFilters.customFilters[0].val.toString()}:!1}},n.GREATER_THAN={label:`sheets-filter.conditions.greater-than`,operator:t.CustomFilterOperator.GREATER_THAN,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:t.CustomFilterOperator.GREATER_THAN,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:t.CustomFilterOperator.GREATER_THAN}]}}),testMappingParams:e=>{let[n]=h(e);return n===t.CustomFilterOperator.GREATER_THAN},testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===t.CustomFilterOperator.GREATER_THAN?{operator1:t.CustomFilterOperator.GREATER_THAN,val1:r.val.toString()}:!1}},n.GREATER_THAN_OR_EQUAL={label:`sheets-filter.conditions.greater-than-or-equal`,operator:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:``}),testMappingParams:e=>{let[n]=h(e);return n===t.CustomFilterOperator.GREATER_THAN_OR_EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL}]}}),testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===t.CustomFilterOperator.GREATER_THAN_OR_EQUAL?{operator1:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:r.val.toString()}:!1}},n.LESS_THAN={label:`sheets-filter.conditions.less-than`,operator:t.CustomFilterOperator.LESS_THAN,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:t.CustomFilterOperator.LESS_THAN,val1:``}),testMappingParams:e=>{let[n]=h(e);return n===t.CustomFilterOperator.LESS_THAN},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:t.CustomFilterOperator.LESS_THAN}]}}),testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===t.CustomFilterOperator.LESS_THAN?{operator1:t.CustomFilterOperator.LESS_THAN,val1:r.val.toString()}:!1}},n.LESS_THAN_OR_EQUAL={label:`sheets-filter.conditions.less-than-or-equal`,operator:t.CustomFilterOperator.LESS_THAN_OR_EQUAL,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:t.CustomFilterOperator.LESS_THAN_OR_EQUAL,val1:``}),testMappingParams:e=>{let[n]=h(e);return n===t.CustomFilterOperator.LESS_THAN_OR_EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:t.CustomFilterOperator.LESS_THAN_OR_EQUAL}]}}),testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===t.CustomFilterOperator.LESS_THAN_OR_EQUAL?{operator1:t.CustomFilterOperator.LESS_THAN_OR_EQUAL,val1:r.val.toString()}:!1}},n.EQUAL={label:`sheets-filter.conditions.equal`,operator:t.CustomFilterOperator.EQUAL,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:t.CustomFilterOperator.EQUAL,val1:``}),testMappingParams:e=>{let[n]=h(e);return n===t.CustomFilterOperator.EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:t.CustomFilterOperator.EQUAL}]}}),testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===t.CustomFilterOperator.EQUAL?{operator1:t.CustomFilterOperator.EQUAL,val1:r.val.toString()}:!1}},n.NOT_EQUAL={label:`sheets-filter.conditions.not-equal`,operator:t.CustomFilterOperator.NOT_EQUALS,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:t.CustomFilterOperator.NOT_EQUALS,val1:``}),testMappingParams:e=>{let[n]=h(e);return n===t.CustomFilterOperator.NOT_EQUALS},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:t.CustomFilterOperator.NOT_EQUALS}]}}),testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===t.CustomFilterOperator.NOT_EQUALS?{operator1:t.CustomFilterOperator.NOT_EQUALS,val1:r.val.toString()}:!1}},n.BETWEEN={label:`sheets-filter.conditions.between`,operator:p.BETWEEN,order:f.SECOND,numOfParameters:2,getDefaultFormParams:()=>({and:!0,operator1:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:``,operator2:t.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:``}),testMappingParams:e=>{let{and:n,operator1:r,operator2:i}=e;if(!n)return!1;let a=[r,i];return a.includes(t.CustomFilterOperator.GREATER_THAN_OR_EQUAL)&&a.includes(t.CustomFilterOperator.LESS_THAN_OR_EQUAL)},mapToFilterColumn:n=>{let{val1:r,val2:i,operator1:a}=n,o=a===t.CustomFilterOperator.GREATER_THAN_OR_EQUAL;return{customFilters:{and:e.BooleanNumber.TRUE,customFilters:[{val:o?r:i,operator:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL},{val:o?i:r,operator:t.CustomFilterOperator.LESS_THAN_OR_EQUAL}]}}},testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==2)return!1;let[r,i]=e.customFilters.customFilters;return r.operator===t.CustomFilterOperator.GREATER_THAN_OR_EQUAL&&i.operator===t.CustomFilterOperator.LESS_THAN_OR_EQUAL&&e.customFilters.and?{and:!0,operator1:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:r.val.toString(),operator2:t.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:i.val.toString()}:i.operator===t.CustomFilterOperator.GREATER_THAN_OR_EQUAL&&r.operator===t.CustomFilterOperator.LESS_THAN_OR_EQUAL&&e.customFilters.and?{and:!0,operator1:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:i.val.toString(),operator2:t.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:r.val.toLocaleString()}:!1}},n.NOT_BETWEEN={label:`sheets-filter.conditions.not-between`,operator:p.NOT_BETWEEN,order:f.SECOND,numOfParameters:2,getDefaultFormParams:()=>({operator1:t.CustomFilterOperator.LESS_THAN,val1:``,operator2:t.CustomFilterOperator.GREATER_THAN,val2:``}),testMappingParams:e=>{let{and:n,operator1:r,operator2:i}=e;if(n)return!1;let a=[r,i];return a.includes(t.CustomFilterOperator.GREATER_THAN)&&a.includes(t.CustomFilterOperator.LESS_THAN)},mapToFilterColumn:e=>{let{val1:n,val2:r,operator1:i}=e,a=i===t.CustomFilterOperator.GREATER_THAN;return{customFilters:{customFilters:[{val:a?n:r,operator:t.CustomFilterOperator.GREATER_THAN},{val:a?r:n,operator:t.CustomFilterOperator.LESS_THAN}]}}},testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==2)return!1;let[r,i]=e.customFilters.customFilters;return r.operator===t.CustomFilterOperator.LESS_THAN&&i.operator===t.CustomFilterOperator.GREATER_THAN&&!e.customFilters.and?{operator1:t.CustomFilterOperator.LESS_THAN,val1:r.val.toString(),operator2:t.CustomFilterOperator.GREATER_THAN,val2:i.val.toString()}:i.operator===t.CustomFilterOperator.LESS_THAN&&r.operator===t.CustomFilterOperator.GREATER_THAN&&!e.customFilters.and?{operator1:t.CustomFilterOperator.GREATER_THAN,val1:i.val.toString(),operator2:t.CustomFilterOperator.LESS_THAN,val2:r.val.toLocaleString()}:!1}},n.CUSTOM={label:`sheets-filter.conditions.custom`,operator:p.CUSTOM,order:f.SECOND,numOfParameters:2,getDefaultFormParams:()=>({operator1:p.NONE,val1:``,operator2:p.NONE,val2:``}),testMappingParams:()=>!0,mapToFilterColumn:t=>{let{and:n,val1:a,val2:o,operator1:s,operator2:c}=t;function l(e,t){for(let n of i)if(n.operator===e)return n.mapToFilterColumn({val1:t,operator1:e})}let u=!s||s===m.NONE.operator,d=!c||c===m.NONE.operator;if(u&&d)return r.mapToFilterColumn({});if(u)return l(c,o);if(d)return l(s,a);let f=l(s,a),p=l(c,o),h={customFilters:[f.customFilters.customFilters[0],p.customFilters.customFilters[0]]};return n&&(h.and=e.BooleanNumber.TRUE),{customFilters:h}},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==2)return!1;let n=e.customFilters.customFilters.map(e=>l({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 a(e){let t=i.find(t=>t.operator===e);if(!t)throw Error(`[SheetsFilter]: no condition item found for operator: ${e}`);return t}n.getItemByOperator=a;function o(e,t){for(let n of i.filter(e=>e.numOfParameters===t))if(n.numOfParameters!==0&&n.testMappingParams(e))return n;for(let t of i)if(t.testMappingParams(e))return t;throw Error(`[SheetsFilter]: no condition item can be mapped from the filter map params!`)}n.testMappingParams=o;function s(e){let t=i.find(t=>t.operator===e);return(t==null?void 0:t.numOfParameters)===0?{operator1:t.operator}:t.getDefaultFormParams()}n.getInitialFormParams=s;function c(e,t){return e.mapToFilterColumn(t)}n.mapToFilterColumn=c;function l(e){if(!e)return[r,{}];for(let t of i){let n=t.testMappingFilterColumn(e);if(n)return[t,n]}return[r,{}]}n.testMappingFilterColumn=l})(m||(m={}));function h(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 g(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 _(e,t){return function(n,r){t(n,r,e)}}function v(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 y=`sheets-filter.generate-filter-values.service`,b=(0,e.createIdentifier)(y);let x=class extends e.Disposable{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}),S(o,this._localeService,c,d,new Set(i),a,new Set(l.map(String)),s,u.getStyles()))}};x=v([_(0,(0,e.Inject)(e.LocaleService)),_(1,e.IUniverInstanceService),_(2,e.ILogService)],x);function S(n,r,i,a,o,s,c,l,u){var d;let f=new Map,p=new Map,m=`empty`,h=!n&&((s==null?void 0:s.filterBy)===t.FilterBy.COLORS||(s==null?void 0:s.filterBy)===t.FilterBy.CONDITIONS)&&((d=s.filteredOutRows)==null?void 0:d.size),g=0;for(let t of a.iterateByColumn(i,!1,!1)){let{row:n,rowSpan:i=1}=t,s=0;for(;s<i;){var _,v,y;let d=n+s;if(o.has(d)){s++;continue}let m=t!=null&&t.value?(0,e.extractPureTextFromCell)(t.value):``;if(!m){g+=1,s+=i;continue}let C=(_=t.value)!=null&&_.v&&!t.value.p?(v=u.get((y=t.value)==null?void 0:y.s))==null||(v=v.n)==null?void 0:v.pattern:``,E=C&&e.numfmt.getFormatInfo(C).isDate,D=!1;if(E){let{year:t,month:n,day:r}=e.numfmt.getFormatDateInfo(C);D=t||n||r}if(C&&E&&D){var b,x,S;let n=(b=a.getCellRaw(t.row,t.col))==null?void 0:b.v;if(!n){s++;continue}let[i,o,u]=e.numfmt.format(`yyyy-mm-dd`,Number(n)).split(`-`).map(Number),d=f.get(`${i}`);d||(d={title:`${i}`,key:`${i}`,children:[],count:0,leaf:!1,checked:!1},f.set(`${i}`,d),p.set(`${i}`,[`${i}`]));let g=(x=d.children)==null?void 0:x.find(e=>e.key===`${i}-${o}`);if(!g){var w;g={title:r.t(`sheets-filter.date.${o}`),key:`${i}-${o}`,children:[],count:0,leaf:!1,checked:!1},(w=d.children)==null||w.push(g),p.set(`${i}-${o}`,[`${i}`,`${i}-${o}`])}let _=g==null||(S=g.children)==null?void 0:S.find(e=>e.key===`${i}-${o}-${u}`);if(_)_.originValues.add(m),_.count++,g.count++,d.count++;else{var T;(T=g.children)==null||T.push({title:`${u}`,key:`${i}-${o}-${u}`,count:1,originValues:new Set([m]),leaf:!0,checked:h?!1:c.size?c.has(m):!l}),g.count++,d.count++,p.set(`${i}-${o}-${u}`,[`${i}`,`${i}-${o}`,`${i}-${o}-${u}`])}}else{let e=m,t=f.get(e);t?t.count++:(t={title:m,leaf:!0,checked:h?!1:c.size?c.has(m):!l,key:e,count:1},f.set(e,t),p.set(e,[e]))}s++}}let E=h?!1:n?l:!0;if(g>0){let e={title:r.t(`sheets-filter.panel.empty`),count:g,leaf:!0,checked:E,key:m};f.set(`empty`,e),p.set(`empty`,[m])}return{filterTreeItems:C(Array.from(f.values())),filterTreeMapCache:p}}function C(e){return Array.from(e).sort((e,t)=>e.children&&!t.children?-1:!e.children&&t.children?1:T(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 w=e=>!Number.isNaN(Number(e))&&!Number.isNaN(Number.parseFloat(e));function T(e,t){let n=w(e),r=w(t);return n&&r?Number.parseFloat(e)-Number.parseFloat(t):n&&!r?-1:!n&&r?1:e.localeCompare(t)}function E(e,t){for(let n of e){if(n.key===t)return n;if(n.children){let e=E(n.children,t);if(e)return e}}return null}function D(e){return e.leaf?e.checked:e.children?e.children.every(e=>D(e)):!0}function O(e,t){e.leaf&&(t===void 0?e.checked=!e.checked:e.checked=t),e.children&&e.children.forEach(e=>O(e,t))}function ee(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=ee(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 k(e){"@babel/helpers - typeof";return k=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},k(e)}function te(e,t){if(k(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(k(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function ne(e){var t=te(e,`string`);return k(t)==`symbol`?t:t+``}function A(e,t,n){return(t=ne(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var j,M,N;(0,e.createIdentifier)(`sheets-filter-ui.sheets-filter-panel.service`);let P=class extends e.Disposable{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,n){super(),this._injector=e,this._refRangeService=n,A(this,`_filterBy$`,new o.BehaviorSubject(t.FilterBy.VALUES)),A(this,`filterBy$`,this._filterBy$.asObservable()),A(this,`_filterByModel$`,new o.ReplaySubject(1)),A(this,`filterByModel$`,this._filterByModel$.asObservable()),A(this,`_filterByModel`,null),A(this,`_hasCriteria$`,new o.BehaviorSubject(!1)),A(this,`hasCriteria$`,this._hasCriteria$.asObservable()),A(this,`_filterModel`,null),A(this,`_col$`,new o.BehaviorSubject(-1)),A(this,`col$`,this._col$.asObservable()),A(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 t.FilterBy.VALUES:this._setupByValues(this._filterModel,this.col);break;case t.FilterBy.COLORS:this._setupByColors(this._filterModel,this.col);break;case t.FilterBy.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,n){this._disposePreviousModel();let r=e.getRange();return r.startRow===r.endRow?!1:(this.filterByModel=await I.fromFilterColumn(this._injector,e,n),this._filterBy$.next(t.FilterBy.VALUES),this._listenToFilterHeaderChange(e,n),!0)}async _setupByColors(e,n){this._disposePreviousModel();let r=e.getRange();return r.startRow===r.endRow?!1:(this.filterByModel=await L.fromFilterColumn(this._injector,e,n),this._filterBy$.next(t.FilterBy.COLORS),this._listenToFilterHeaderChange(e,n),!0)}_setupByConditions(e,n){this._disposePreviousModel();let r=e.getRange();return r.startRow===r.endRow?!1:(this.filterByModel=F.fromFilterColumn(this._injector,e,n,e.getFilterColumn(n)),this._filterBy$.next(t.FilterBy.CONDITIONS),this._listenToFilterHeaderChange(e,n),!0)}_disposePreviousModel(){var e;(e=this._filterByModel)==null||e.dispose(),this.filterByModel=null}};P=v([_(0,(0,e.Inject)(e.Injector)),_(1,(0,e.Inject)(a.RefRangeService))],P);let F=j=class extends e.Disposable{static fromFilterColumn(e,t,n,r){let[i,a]=m.testMappingFilterColumn(r==null?void 0:r.getColumnData());return e.createInstance(j,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,A(this,`canApply$`,(0,o.of)(!0)),A(this,`_conditionItem$`,void 0),A(this,`conditionItem$`,void 0),A(this,`_filterConditionFormParams$`,void 0),A(this,`filterConditionFormParams$`,void 0),this._conditionItem$=new o.BehaviorSubject(n),this.conditionItem$=this._conditionItem$.asObservable(),this._filterConditionFormParams$=new o.BehaviorSubject(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(t.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}async apply(){if(this._disposed)return!1;let e=m.mapToFilterColumn(this.conditionItem,this.filterConditionFormParams);return this._commandService.executeCommand(t.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:e})}onPrimaryConditionChange(e){let t=m.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(m.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=m.testMappingParams(t,this.conditionItem.numOfParameters);this._conditionItem$.next(e)}this._filterConditionFormParams$.next(t)}};F=j=v([_(4,e.ICommandService)],F);let I=M=class extends e.Disposable{static async fromFilterColumn(t,n,r){let i=t.get(e.IUniverInstanceService),a=t.get(e.LocaleService),o=t.get(b,e.Quantity.OPTIONAL),{unitId:s,subUnitId:c}=n,l=i.getUniverSheetInstance(s);if(!l)throw Error(`[ByValuesModel]: Workbook not found for filter model with unitId: ${s}!`);let u=l==null?void 0:l.getSheetBySheetId(c);if(!u)throw Error(`[ByValuesModel]: Worksheet not found for filter model with unitId: ${s} and subUnitId: ${c}!`);let d=n.getRange(),f=r,p=n.getFilterColumn(r),m=p==null?void 0:p.getColumnData().filters,h=new Set(m==null?void 0:m.filters),g=!!(m&&m.blank),_=n.getFilteredOutRowsExceptCol(r),v={...d,startRow:d.startRow+1,startColumn:f,endColumn:f},y,x;if(o){let e=await o.getFilterValues({unitId:s,subUnitId:c,filteredOutRowsByOtherColumns:Array.from(_),filterColumn:p,filters:!!m,blankChecked:g,iterateRange:v,alreadyChecked:Array.from(h)});y=e.filterTreeItems,x=e.filterTreeMapCache}else{let e=S(!!m,a,v,u,_,p,h,g,l.getStyles());y=e.filterTreeItems,x=e.filterTreeMapCache}return t.createInstance(M,n,r,y,x)}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,A(this,`_rawFilterItems$`,void 0),A(this,`rawFilterItems$`,void 0),A(this,`filterItems$`,void 0),A(this,`_filterItems`,[]),A(this,`_treeMapCache`,void 0),A(this,`canApply$`,void 0),A(this,`_manuallyUpdateFilterItems$`,void 0),A(this,`_searchString$`,void 0),A(this,`searchString$`,void 0),this._treeMapCache=r,this._searchString$=new o.BehaviorSubject(``),this.searchString$=this._searchString$.asObservable(),this._rawFilterItems$=new o.BehaviorSubject(n),this.rawFilterItems$=this._rawFilterItems$.asObservable(),this._manuallyUpdateFilterItems$=new o.Subject,this.filterItems$=(0,o.merge)((0,o.combineLatest)([this._searchString$.pipe((0,o.throttleTime)(500,void 0,{leading:!0,trailing:!0}),(0,o.startWith)(void 0)),this._rawFilterItems$]).pipe((0,o.map)(([e,t])=>e?ee(t,e.toLowerCase().split(/\s+/).filter(e=>!!e)):t)),this._manuallyUpdateFilterItems$).pipe((0,o.shareReplay)(1)),this.canApply$=this.filterItems$.pipe((0,o.map)(e=>g(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(t){let n=e.Tools.deepClone(this._filterItems);n.forEach(e=>O(e,t)),this._manuallyUpdateFilterItems(n)}onFilterCheckToggled(t){let n=e.Tools.deepClone(this._filterItems),r=E(n,t.key);r&&(O(r,!D(r)),this._manuallyUpdateFilterItems(n))}onFilterOnly(t){let n=e.Tools.deepClone(this._filterItems);n.forEach(e=>O(e,!1)),t.forEach(e=>{let t=E(n,e);t&&O(t,!0)}),this._manuallyUpdateFilterItems(n)}_manuallyUpdateFilterItems(e){this._manuallyUpdateFilterItems$.next(e)}clear(){return this._disposed?Promise.resolve(!1):this._commandService.executeCommand(t.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}async apply(){if(this._disposed)return!1;let e=g(this._filterItems),{checked:n,checkedItems:r}=e,i=this.rawFilterItems,a=0;for(let e of i)a+=e.count;let o=n===0,s=e.checked===a,c={colId:this.col};if(o)throw Error(`[ByValuesModel]: no checked items!`);if(s)return this._commandService.executeCommand(t.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null});{c.filters={};let e=r.filter(e=>e.key!==`empty`);e.length>0&&(c.filters={filters:e.flatMap(e=>e.originValues?Array.from(e.originValues):[e.title])}),e.length!==r.length&&(c.filters.blank=!0)}return this._commandService.executeCommand(t.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:c})}};I=M=v([_(4,e.ICommandService)],I);let L=N=class extends e.Disposable{static async fromFilterColumn(t,n,r){var a,o,s;let c=t.get(e.IUniverInstanceService),{unitId:l,subUnitId:u}=n,d=c.getUniverSheetInstance(l);if(!d)throw Error(`[ByColorsModel]: Workbook not found for filter model with unitId: ${l}!`);let f=d==null?void 0:d.getSheetBySheetId(u);if(!f)throw Error(`[ByColorsModel]: Worksheet not found for filter model with unitId: ${l} and subUnitId: ${u}!`);let p=n.getRange(),m=r,h=(a=n.getFilterColumn(r))==null?void 0:a.getColumnData().colorFilters,g=n.getFilteredOutRowsExceptCol(r),_={...p,startRow:p.startRow+1,startColumn:m,endColumn:m},v=new Map,y=new Set((o=h==null?void 0:h.cellFillColors)==null?[]:o),b=new Map,x=new Set((s=h==null?void 0:h.cellTextColors)==null?[]:s);for(let t of f.iterateByColumn(_,!1,!0)){let{row:n,col:r,value:a}=t;if(g.has(n))continue;let o=f.getComposedCellStyleByCellData(n,r,a);if(o.bg&&o.bg.rgb){let t=new e.ColorKit(o.bg.rgb).toRgbString();v.has(t)||v.set(t,{color:t,checked:y.has(t)})}else v.set(`default-fill-color`,{color:null,checked:y.has(null)});if(o.cl&&o.cl.rgb){let t=new e.ColorKit(o.cl.rgb).toRgbString();b.has(t)||b.set(t,{color:t,checked:x.has(t)})}else b.set(`default-font-color`,{color:i.COLOR_BLACK_RGB,checked:x.has(i.COLOR_BLACK_RGB)})}return t.createInstance(N,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,A(this,`canApply$`,(0,o.of)(!0)),A(this,`_cellFillColors$`,void 0),A(this,`cellFillColors$`,void 0),A(this,`_cellTextColors$`,void 0),A(this,`cellTextColors$`,void 0),this._cellFillColors$=new o.BehaviorSubject(Array.from(n.values())),this.cellFillColors$=this._cellFillColors$.asObservable(),this._cellTextColors$=new o.BehaviorSubject(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(t.SetSheetsFilterCriteriaCommand.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),n=this.cellTextColors.filter(e=>e.checked).map(e=>e.color);if(e.length===0&&n.length===0)return this._commandService.executeCommand(t.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null});let r={colId:this.col};return e.length>0?r.colorFilters={cellFillColors:e}:n.length>0&&(r.colorFilters={cellTextColors:n}),this._commandService.executeCommand(t.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:r})}};L=N=v([_(4,e.ICommandService)],L);const R=`FILTER_PANEL_OPENED`,z={id:`sheet.operation.open-filter-panel`,type:e.CommandType.OPERATION,handler:(r,i)=>{let a=r.get(e.IContextService),o=r.get(t.SheetsFilterService),s=r.get(P),c=r.get(e.ICommandService),l=r.has(n.IEditorBridgeService)?r.get(n.IEditorBridgeService):null;l!=null&&l.isVisible().visible&&c.syncExecuteCommand(n.SetCellEditVisibleOperation.id,{visible:!1});let{unitId:u,subUnitId:d,col:f}=i,p=o.getFilterModel(u,d);return p?(s.setupCol(p,f),a.getContextValue(`FILTER_PANEL_OPENED`)||a.setContextValue(R,!0),!0):!1}},B={id:`sheet.operation.close-filter-panel`,type:e.CommandType.OPERATION,handler:t=>{let n=t.get(e.IContextService),i=t.get(P),a=t.get(r.ILayoutService,e.Quantity.OPTIONAL);return n.getContextValue(`FILTER_PANEL_OPENED`)?(n.setContextValue(R,!1),a==null||a.focus(),i.terminate()):!1}},V={id:`sheet.operation.apply-filter`,type:e.CommandType.OPERATION,handler:(e,t)=>{let{filterBy:n}=t;return e.get(P).changeFilterBy(n)}};var H=`@univerjs/sheets-filter-ui`,U=`0.19.0`;const W=`sheets-filter-ui.config`;Symbol(W);const G={};let K=class extends e.Disposable{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(n=>{if(n.id===t.SmartToggleSheetsFilterCommand.id){var r;let t=(0,a.getSheetCommandTarget)(this._injector.get(e.IUniverInstanceService));if(!t)return;let{unitId:n,subUnitId:o,worksheet:s}=t,c=(r=this._sheetsFilterService.getFilterModel(n,o))==null?void 0:r.getRange(),l;if(c)l=this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[a.RangeProtectionPermissionViewPoint],worksheetTypes:[a.WorksheetFilterPermission,a.WorksheetViewPermission]},[c],n,o);else{var i;let e=(i=this._sheetsSelectionService.getCurrentLastSelection())==null?void 0:i.range;if(e){let t={...e};t=e.startColumn===e.endColumn&&e.startRow===e.endRow?(0,a.expandToContinuousRange)(t,{left:!0,right:!0,up:!0,down:!0},s):t,l=this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[a.RangeProtectionPermissionViewPoint],worksheetTypes:[a.WorksheetViewPermission,a.WorksheetFilterPermission]},[t],n,o)}else l=this._sheetPermissionCheckPermission.permissionCheckWithoutRange({rangeTypes:[a.RangeProtectionPermissionViewPoint],worksheetTypes:[a.WorksheetViewPermission,a.WorksheetFilterPermission]})}l||this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.filterErr`))}if(n.id===z.id){var o;let t=n.params,{unitId:r,subUnitId:i}=t,s=(o=this._sheetsFilterService.getFilterModel(r,i))==null?void 0:o.getRange(),c=e.Tools.deepClone(s);c&&(c.startColumn=t.col,c.endColumn=t.col,this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[a.RangeProtectionPermissionViewPoint],worksheetTypes:[a.WorksheetFilterPermission,a.WorksheetViewPermission]},[c],r,i)||this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.filterErr`)))}}))}};K=v([_(0,(0,e.Inject)(t.SheetsFilterService)),_(1,(0,e.Inject)(e.LocaleService)),_(2,e.ICommandService),_(3,(0,e.Inject)(a.SheetPermissionCheckController)),_(4,(0,e.Inject)(e.Injector)),_(5,(0,e.Inject)(a.SheetsSelectionsService))],K);const re=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 ie=class{static drawNoCriteria(e,t,n,r){e.save(),i.Rect.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(),i.Rect.drawWith(e,{radius:2,width:16,height:16,fill:r}),e.scale(t/16,t/16),e.fillStyle=n,e.fill(re),e.restore()}};let q=class extends i.Shape{constructor(e,t,n,r,i){super(e,t),this._contextService=n,this._commandService=r,this._themeService=i,A(this,`_cellWidth`,0),A(this,`_cellHeight`,0),A(this,`_filterParams`,void 0),A(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?ie.drawHasCriteria(e,16,s,c):ie.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(z.id)||setTimeout(()=>{this._commandService.executeCommand(z.id,{unitId:n,subUnitId:r,col:t})},200)}onPointerEnter(){this._hovered=!0,this.makeDirty(!0)}onPointerLeave(){this._hovered=!1,this.makeDirty(!0)}};q=v([_(2,e.IContextService),_(3,e.ICommandService),_(4,(0,e.Inject)(e.ThemeService))],q);function ae(t,n,r,i){switch(i){case e.VerticalAlign.TOP:return t+1;case e.VerticalAlign.MIDDLE:return t+Math.max(0,(r-16)/2);case e.VerticalAlign.BOTTOM:default:return n-16-1}}let J=class extends e.RxDisposable{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,A(this,`_currentRenderParams`,null),A(this,`_filterRangeShape`,null),A(this,`_buttonRenderDisposable`,null),A(this,`_filterButtonShapes`,[]),this._initRenderer()}dispose(){super.dispose(),this._disposeRendering()}_initRenderer(){this.disposeWithMe(this._themeService.currentTheme$.subscribe(()=>{this._refreshRendering(this._currentRenderParams)})),this._sheetSkeletonManagerService.currentSkeleton$.pipe((0,o.switchMap)(n=>{var r,i;if(!n)return(0,o.of)(null);let{unit:s,unitId:c}=this._context,l=((r=s.getActiveSheet())==null?void 0:r.getSheetId())||``,u=(i=this._sheetsFilterService.getFilterModel(c,l))==null?void 0:i,d=()=>({unitId:c,worksheetId:l,filterModel:u,range:u==null?void 0:u.getRange(),skeleton:n.skeleton});return(0,e.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([n])=>{var r;return n.type===e.CommandType.MUTATION&&((r=n.params)==null?void 0:r.unitId)===s.getUnitId()&&(t.FILTER_MUTATIONS.has(n.id)||n.id===a.SetRangeValuesMutation.id)}),(0,o.throttleTime)(20,void 0,{leading:!1,trailing:!0}),(0,o.map)(d),(0,o.startWith)(d()))}),(0,o.takeUntil)(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:r}=this._context,{rowHeaderWidth:i,columnHeaderHeight:a}=t,o=this._filterRangeShape=new n.SelectionControl(r,1e3,this._themeService,{rowHeaderWidth:i,columnHeaderHeight:a,enableAutoFill:!1,highlightHeader:!1}),s=(0,n.attachSelectionWithCoord)({range:e,primary:null,style:{fill:`rgba(0, 0, 0, 0.0)`}},t);o.updateRangeBySelectionWithCoord(s),o.setEvent(!1),r.makeDirty(!0)}_renderButtons(t){let{range:r,filterModel:i,unitId:a,skeleton:o,worksheetId:s}=t,{unit:c,scene:l}=this._context,u=c.getSheetBySheetId(s);if(!u)return;this._interceptCellContent(a,s,t.range);let{startColumn:d,endColumn:f,startRow:p}=r;for(let t=d;t<=f;t++){let r=`sheets-filter-button-${t}`,c=(0,n.getCoordByCell)(p,t,l,o),d=u.getComposedCellStyle(p,t),f=(d==null?void 0:d.vt)||e.VerticalAlign.BOTTOM,{startX:m,startY:h,endX:g,endY:_}=c,v=g-m,y=_-h;if(y<=1||v<=1)continue;let b=!!i.getFilterColumn(t),x={left:g-16-1,top:ae(h,_,y,f),height:16,width:16,zIndex:5e3,cellHeight:y,cellWidth:v,filterParams:{unitId:a,subUnitId:s,col:t,hasCriteria:b}},S=this._injector.createInstance(q,r,x);this._filterButtonShapes.push(S)}l.addObjects(this._filterButtonShapes),l.makeDirty()}_interceptCellContent(t,n,r){let{startRow:i,startColumn:o,endColumn:s}=r;this._buttonRenderDisposable=this._sheetInterceptorService.intercept(a.INTERCEPTOR_POINT.CELL_CONTENT,{effect:e.InterceptorEffectEnum.Style,handler:(e,r,a)=>{let{row:c,col:l,unitId:u,subUnitId:d}=r;return u!==t||d!==n||c!==i||l<o||l>s?a(e):((!e||e===r.rawData)&&(e={...r.rawData}),e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,rightOffset:16},a(e))},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=[]}};J=v([_(1,(0,e.Inject)(e.Injector)),_(2,(0,e.Inject)(n.SheetSkeletonManagerService)),_(3,(0,e.Inject)(t.SheetsFilterService)),_(4,(0,e.Inject)(e.ThemeService)),_(5,(0,e.Inject)(a.SheetInterceptorService)),_(6,e.ICommandService),_(7,n.ISheetSelectionRenderService)],J);let Y=class extends e.RxDisposable{constructor(n,r){super(),this._renderManagerService=n,this._sheetsRenderService=r,[t.SetSheetsFilterRangeMutation,t.SetSheetsFilterCriteriaMutation,t.RemoveSheetsFilterMutation,t.ReCalcSheetsFilterMutation].forEach(e=>this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(e.id))),this.disposeWithMe(this._renderManagerService.registerRenderModule(e.UniverInstanceType.UNIVER_SHEET,[J]))}};Y=v([_(0,i.IRenderManagerService),_(1,(0,e.Inject)(n.SheetsRenderService))],Y);let X=class extends e.Plugin{constructor(t=G,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{menu:i,...a}=(0,e.merge)({},G,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(W,a)}onStarting(){[[K],[Y]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(K)}onRendered(){this._injector.get(Y)}};A(X,`type`,e.UniverInstanceType.UNIVER_SHEET),A(X,`pluginName`,`SHEET_FILTER_UI_PLUGIN`),A(X,`packageName`,H),A(X,`version`,U),X=v([(0,e.DependentOn)(t.UniverSheetsFilterPlugin),_(1,(0,e.Inject)(e.Injector)),_(2,e.IConfigService)],X);function oe(i){let s=i.get(t.SheetsFilterService);return{id:t.SmartToggleSheetsFilterCommand.id,type:r.MenuItemType.BUTTON_SELECTOR,icon:`FilterIcon`,tooltip:`sheets-filter.toolbar.smart-toggle-filter-tooltip`,hidden$:(0,r.getMenuHiddenObservable)(i,e.UniverInstanceType.UNIVER_SHEET),activated$:s.activeFilterModel$.pipe((0,o.map)(e=>!!e)),disabled$:(0,n.getObservableWithExclusiveRange$)(i,(0,n.getCurrentRangeDisable$)(i,{worksheetTypes:[a.WorksheetFilterPermission,a.WorksheetViewPermission],rangeTypes:[a.RangeProtectionPermissionViewPoint]}))}}function se(n){let i=n.get(t.SheetsFilterService);return{id:t.ClearSheetsFilterCriteriaCommand.id,type:r.MenuItemType.BUTTON,title:`sheets-filter.toolbar.clear-filter-criteria`,hidden$:(0,r.getMenuHiddenObservable)(n,e.UniverInstanceType.UNIVER_SHEET),disabled$:i.activeFilterModel$.pipe((0,o.switchMap)(e=>{var t;return(t=e==null?void 0:e.hasCriteria$.pipe((0,o.map)(e=>!e)))==null?(0,o.of)(!0):t}))}}function ce(n){let i=n.get(t.SheetsFilterService);return{id:t.ReCalcSheetsFilterCommand.id,type:r.MenuItemType.BUTTON,title:`sheets-filter.toolbar.re-calc-filter-conditions`,hidden$:(0,r.getMenuHiddenObservable)(n,e.UniverInstanceType.UNIVER_SHEET),disabled$:i.activeFilterModel$.pipe((0,o.switchMap)(e=>{var t;return(t=e==null?void 0:e.hasCriteria$.pipe((0,o.map)(e=>!e)))==null?(0,o.of)(!0):t}))}}const le={[r.RibbonDataGroup.ORGANIZATION]:{[t.SmartToggleSheetsFilterCommand.id]:{order:2,menuItemFactory:oe,[t.ClearSheetsFilterCriteriaCommand.id]:{order:0,menuItemFactory:se},[t.ReCalcSheetsFilterCommand.id]:{order:1,menuItemFactory:ce}}}};function ue(t){let{model:n}=t,i=(0,r.useDependency)(e.LocaleService),a=(0,r.useObservable)(n.cellFillColors$,[],!0),o=(0,r.useObservable)(n.cellTextColors$,[],!0),s=(0,u.useCallback)(e=>{n.onFilterCheckToggled(e)},[n]),f=(0,u.useCallback)(e=>{n.onFilterCheckToggled(e,!1)},[n]);return(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-colors-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel`,className:(0,c.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`,c.borderClassName),children:[a.length>1&&(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white`,children:i.t(`sheets-filter.panel.filter-by-cell-fill-color`)}),(0,d.jsx)(`div`,{className:`univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2`,children:a.map((e,t)=>(0,d.jsxs)(`div`,{className:`univer-relative univer-size-6`,onClick:()=>s(e),children:[e.color?(0,d.jsx)(`button`,{type:`button`,className:(0,c.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`),style:{backgroundColor:e.color}}):(0,d.jsx)(l.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`}),e.checked&&(0,d.jsx)(de,{})]},`sheets-filter-cell-fill-color-${t}`))})]}),o.length>1&&(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white`,children:i.t(`sheets-filter.panel.filter-by-cell-text-color`)}),(0,d.jsx)(`div`,{className:`univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2`,children:o.map((e,t)=>(0,d.jsxs)(`div`,{className:`univer-relative univer-size-6`,onClick:()=>f(e),children:[(0,d.jsx)(`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:(0,d.jsx)(l.AIcon,{style:{color:e.color}})}),e.checked&&(0,d.jsx)(de,{})]},`sheets-filter-cell-text-color-${t}`))})]}),a.length<=1&&o.length<=1&&(0,d.jsx)(`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:i.t(`sheets-filter.panel.filter-by-color-none`)})]})})}function de(){return(0,d.jsx)(`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:(0,d.jsx)(l.SuccessIcon,{className:`univer-size-full univer-font-bold univer-text-[#418F1F]`})})}function fe(t){var n,i;let{model:a}=t,o=(0,r.useDependency)(e.LocaleService),s=(0,r.useObservable)(a.conditionItem$,void 0),l=(0,r.useObservable)(a.filterConditionFormParams$,void 0),f=l!=null&&l.and?`AND`:`OR`,p=(0,u.useCallback)(e=>{a.onConditionFormChange({and:e===`AND`})},[a]),h=pe(o),g=(0,u.useCallback)(e=>{a.onPrimaryConditionChange(e)},[a]),_=me(o),v=(0,u.useCallback)(e=>{a.onConditionFormChange(e)},[a]),y=o.t(`sheets-filter.panel.input-values-placeholder`);function b(e,t,n){let r=m.getItemByOperator(e).numOfParameters===1;return(0,d.jsxs)(d.Fragment,{children:[n===`operator2`&&(0,d.jsxs)(c.RadioGroup,{value:f,onChange:p,children:[(0,d.jsx)(c.Radio,{value:`AND`,children:o.t(`sheets-filter.panel.and`)}),(0,d.jsx)(c.Radio,{value:`OR`,children:o.t(`sheets-filter.panel.or`)})]}),(0,d.jsx)(c.Select,{value:e,options:_,onChange:e=>v({[n]:e})}),r&&(0,d.jsx)(`div`,{children:(0,d.jsx)(c.Input,{className:`univer-mt-2`,value:t,placeholder:y,onChange:e=>v({[n===`operator1`?`val1`:`val2`]:e})})})]})}return(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-conditions-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:s&&l&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(c.Select,{value:s.operator,options:h,onChange:g}),m.getItemByOperator(s.operator).numOfParameters===0?null:(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel-conditions-container-inner`,className:(0,c.clsx)(`univer-mt-2 univer-flex-grow univer-overflow-hidden univer-rounded-md univer-p-2`,c.borderClassName),children:[s.numOfParameters>=1&&b(l.operator1,(n=l.val1)==null?``:n,`operator1`),s.numOfParameters>=2&&b(l.operator2,(i=l.val2)==null?``:i,`operator2`),(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel-conditions-desc`,className:`univer-mt-2 univer-text-xs univer-text-gray-500`,children:[o.t(`sheets-filter.panel.?`),(0,d.jsx)(`br`,{}),o.t(`sheets-filter.panel.*`)]})]})]})})}function pe(e){return(0,u.useMemo)(()=>[{options:[{label:e.t(m.NONE.label),value:m.NONE.operator}]},{options:[{label:e.t(m.EMPTY.label),value:m.EMPTY.operator},{label:e.t(m.NOT_EMPTY.label),value:m.NOT_EMPTY.operator}]},{options:[{label:e.t(m.TEXT_CONTAINS.label),value:m.TEXT_CONTAINS.operator},{label:e.t(m.DOES_NOT_CONTAIN.label),value:m.DOES_NOT_CONTAIN.operator},{label:e.t(m.STARTS_WITH.label),value:m.STARTS_WITH.operator},{label:e.t(m.ENDS_WITH.label),value:m.ENDS_WITH.operator},{label:e.t(m.EQUALS.label),value:m.EQUALS.operator}]},{options:[{label:e.t(m.GREATER_THAN.label),value:m.GREATER_THAN.operator},{label:e.t(m.GREATER_THAN_OR_EQUAL.label),value:m.GREATER_THAN_OR_EQUAL.operator},{label:e.t(m.LESS_THAN.label),value:m.LESS_THAN.operator},{label:e.t(m.LESS_THAN_OR_EQUAL.label),value:m.LESS_THAN_OR_EQUAL.operator},{label:e.t(m.EQUAL.label),value:m.EQUAL.operator},{label:e.t(m.NOT_EQUAL.label),value:m.NOT_EQUAL.operator},{label:e.t(m.BETWEEN.label),value:m.BETWEEN.operator},{label:e.t(m.NOT_BETWEEN.label),value:m.NOT_BETWEEN.operator}]},{options:[{label:e.t(m.CUSTOM.label),value:m.CUSTOM.operator}]}],[e.getCurrentLocale(),e])}function me(e){return(0,u.useMemo)(()=>m.ALL_CONDITIONS.filter(e=>e.numOfParameters!==2).map(t=>({label:e.t(t.label),value:t.operator})),[e.getCurrentLocale(),e])}function he(t){let{model:n}=t,i=(0,r.useDependency)(e.LocaleService),a=(0,r.useObservable)(n.searchString$,``,!0),o=(0,r.useObservable)(n.filterItems$,void 0,!0),s=i.t(`sheets-filter.panel.filter-only`),l=g(o),f=l.checked>0&&l.unchecked===0,p=l.checked>0&&l.unchecked>0,m=n.treeMapCache,h=(0,u.useCallback)(()=>{n.onCheckAllToggled(!f)},[n,f]),_=(0,u.useCallback)(e=>{n.setSearchString(e)},[n]);function v(e){let t=[];return e.forEach(e=>{e.checked&&t.push(e.key),e.children&&(t=t.concat(v(e.children)))}),t}return(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel-values-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:[(0,d.jsx)(c.Input,{autoFocus:!0,value:a,placeholder:i.t(`sheets-filter.panel.search-placeholder`),onChange:_}),(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel`,className:(0,c.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`,c.borderClassName),children:[(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-values-item`,className:`univer-box-border univer-h-8 univer-w-full univer-py-0.5`,children:(0,d.jsxs)(`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:[(0,d.jsx)(c.Checkbox,{indeterminate:p,disabled:o.length===0,checked:f,onChange:h}),(0,d.jsx)(`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:`${i.t(`sheets-filter.panel.select-all`)}`}),(0,d.jsx)(`span`,{"data-u-comp":`sheets-filter-panel-values-item-count`,className:`univer-text-gray-400 dark:!univer-text-gray-500`,children:`(${l.checked}/${l.checked+l.unchecked})`})]})}),(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-values-virtual`,className:`univer-flex-grow`,children:(0,d.jsx)(c.Tree,{data:o,defaultExpandAll:!1,valueGroup:v(o),onChange:e=>{n.onFilterCheckToggled(e)},defaultCache:m,itemHeight:28,treeNodeClassName:`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/sheets-filter`),n=require(`@univerjs/sheets-ui`),r=require(`@univerjs/ui`),i=require(`@univerjs/engine-render`),a=require(`@univerjs/sheets`),o=require(`rxjs`),s=require(`@univerjs/rpc`),c=require(`@univerjs/design`),l=require(`@univerjs/icons`),u=require(`react`),d=require(`react/jsx-runtime`),f=function(e){return e[e.FIRST=0]=`FIRST`,e[e.SECOND=1]=`SECOND`,e}({}),p=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}({}),m;(function(n){let r=n.NONE={label:`sheets-filter.conditions.none`,operator:p.NONE,order:f.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.NONE]: should not have initial form params!`)},testMappingParams:e=>e.operator1===p.NONE,mapToFilterColumn:()=>null,testMappingFilterColumn:e=>!e.customFilters&&!e.filters?{}:!1},i=n.ALL_CONDITIONS=[r,n.EMPTY={label:`sheets-filter.conditions.empty`,operator:p.EMPTY,order:f.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.EMPTY]: should not have initial form params!`)},testMappingParams:({operator1:e})=>e===p.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:p.EMPTY}:!1}},n.NOT_EMPTY={label:`sheets-filter.conditions.not-empty`,operator:p.NOT_EMPTY,order:f.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.NOT_EMPTY]: should not have initial form params!`)},testMappingParams:({operator1:e})=>e===p.NOT_EMPTY,mapToFilterColumn:()=>({customFilters:{customFilters:[{val:``,operator:t.CustomFilterOperator.NOT_EQUALS}]}}),testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.val===` `&&r.operator===t.CustomFilterOperator.NOT_EQUALS?{operator1:p.NOT_EMPTY}:!1}},n.TEXT_CONTAINS={label:`sheets-filter.conditions.text-contains`,operator:p.CONTAINS,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.CONTAINS,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.CONTAINS,val1:r.slice(1,-1)}:!1}},n.DOES_NOT_CONTAIN={label:`sheets-filter.conditions.does-not-contain`,operator:p.DOES_NOT_CONTAIN,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.DOES_NOT_CONTAIN,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`*${e.val1}*`,operator:t.CustomFilterOperator.NOT_EQUALS}]}}),testMappingParams:e=>{let[t]=h(e);return t===p.DOES_NOT_CONTAIN},testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0],i=r.val.toString();return r.operator===t.CustomFilterOperator.NOT_EQUALS&&i.startsWith(`*`)&&i.endsWith(`*`)?{operator1:p.DOES_NOT_CONTAIN,val1:i.slice(1,-1)}:!1}},n.STARTS_WITH={label:`sheets-filter.conditions.starts-with`,operator:p.STARTS_WITH,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.STARTS_WITH,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`${e.val1}*`}]}}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.STARTS_WITH,val1:r.slice(0,-1)}:!1}},n.ENDS_WITH={label:`sheets-filter.conditions.ends-with`,operator:p.ENDS_WITH,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.ENDS_WITH,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`*${e.val1}`}]}}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.ENDS_WITH,val1:r.slice(1)}:!1}},n.EQUALS={label:`sheets-filter.conditions.equals`,operator:p.EQUALS,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.EQUALS,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.EQUALS,val1:``}:((n=e.customFilters)==null?void 0:n.customFilters.length)===1&&!e.customFilters.customFilters[0].operator?{operator1:p.EQUALS,val1:e.customFilters.customFilters[0].val.toString()}:!1}},n.GREATER_THAN={label:`sheets-filter.conditions.greater-than`,operator:t.CustomFilterOperator.GREATER_THAN,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:t.CustomFilterOperator.GREATER_THAN,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:t.CustomFilterOperator.GREATER_THAN}]}}),testMappingParams:e=>{let[n]=h(e);return n===t.CustomFilterOperator.GREATER_THAN},testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===t.CustomFilterOperator.GREATER_THAN?{operator1:t.CustomFilterOperator.GREATER_THAN,val1:r.val.toString()}:!1}},n.GREATER_THAN_OR_EQUAL={label:`sheets-filter.conditions.greater-than-or-equal`,operator:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:``}),testMappingParams:e=>{let[n]=h(e);return n===t.CustomFilterOperator.GREATER_THAN_OR_EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL}]}}),testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===t.CustomFilterOperator.GREATER_THAN_OR_EQUAL?{operator1:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:r.val.toString()}:!1}},n.LESS_THAN={label:`sheets-filter.conditions.less-than`,operator:t.CustomFilterOperator.LESS_THAN,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:t.CustomFilterOperator.LESS_THAN,val1:``}),testMappingParams:e=>{let[n]=h(e);return n===t.CustomFilterOperator.LESS_THAN},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:t.CustomFilterOperator.LESS_THAN}]}}),testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===t.CustomFilterOperator.LESS_THAN?{operator1:t.CustomFilterOperator.LESS_THAN,val1:r.val.toString()}:!1}},n.LESS_THAN_OR_EQUAL={label:`sheets-filter.conditions.less-than-or-equal`,operator:t.CustomFilterOperator.LESS_THAN_OR_EQUAL,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:t.CustomFilterOperator.LESS_THAN_OR_EQUAL,val1:``}),testMappingParams:e=>{let[n]=h(e);return n===t.CustomFilterOperator.LESS_THAN_OR_EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:t.CustomFilterOperator.LESS_THAN_OR_EQUAL}]}}),testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===t.CustomFilterOperator.LESS_THAN_OR_EQUAL?{operator1:t.CustomFilterOperator.LESS_THAN_OR_EQUAL,val1:r.val.toString()}:!1}},n.EQUAL={label:`sheets-filter.conditions.equal`,operator:t.CustomFilterOperator.EQUAL,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:t.CustomFilterOperator.EQUAL,val1:``}),testMappingParams:e=>{let[n]=h(e);return n===t.CustomFilterOperator.EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:t.CustomFilterOperator.EQUAL}]}}),testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===t.CustomFilterOperator.EQUAL?{operator1:t.CustomFilterOperator.EQUAL,val1:r.val.toString()}:!1}},n.NOT_EQUAL={label:`sheets-filter.conditions.not-equal`,operator:t.CustomFilterOperator.NOT_EQUALS,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:t.CustomFilterOperator.NOT_EQUALS,val1:``}),testMappingParams:e=>{let[n]=h(e);return n===t.CustomFilterOperator.NOT_EQUALS},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:t.CustomFilterOperator.NOT_EQUALS}]}}),testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===t.CustomFilterOperator.NOT_EQUALS?{operator1:t.CustomFilterOperator.NOT_EQUALS,val1:r.val.toString()}:!1}},n.BETWEEN={label:`sheets-filter.conditions.between`,operator:p.BETWEEN,order:f.SECOND,numOfParameters:2,getDefaultFormParams:()=>({and:!0,operator1:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:``,operator2:t.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:``}),testMappingParams:e=>{let{and:n,operator1:r,operator2:i}=e;if(!n)return!1;let a=[r,i];return a.includes(t.CustomFilterOperator.GREATER_THAN_OR_EQUAL)&&a.includes(t.CustomFilterOperator.LESS_THAN_OR_EQUAL)},mapToFilterColumn:n=>{let{val1:r,val2:i,operator1:a}=n,o=a===t.CustomFilterOperator.GREATER_THAN_OR_EQUAL;return{customFilters:{and:e.BooleanNumber.TRUE,customFilters:[{val:o?r:i,operator:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL},{val:o?i:r,operator:t.CustomFilterOperator.LESS_THAN_OR_EQUAL}]}}},testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==2)return!1;let[r,i]=e.customFilters.customFilters;return r.operator===t.CustomFilterOperator.GREATER_THAN_OR_EQUAL&&i.operator===t.CustomFilterOperator.LESS_THAN_OR_EQUAL&&e.customFilters.and?{and:!0,operator1:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:r.val.toString(),operator2:t.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:i.val.toString()}:i.operator===t.CustomFilterOperator.GREATER_THAN_OR_EQUAL&&r.operator===t.CustomFilterOperator.LESS_THAN_OR_EQUAL&&e.customFilters.and?{and:!0,operator1:t.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:i.val.toString(),operator2:t.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:r.val.toLocaleString()}:!1}},n.NOT_BETWEEN={label:`sheets-filter.conditions.not-between`,operator:p.NOT_BETWEEN,order:f.SECOND,numOfParameters:2,getDefaultFormParams:()=>({operator1:t.CustomFilterOperator.LESS_THAN,val1:``,operator2:t.CustomFilterOperator.GREATER_THAN,val2:``}),testMappingParams:e=>{let{and:n,operator1:r,operator2:i}=e;if(n)return!1;let a=[r,i];return a.includes(t.CustomFilterOperator.GREATER_THAN)&&a.includes(t.CustomFilterOperator.LESS_THAN)},mapToFilterColumn:e=>{let{val1:n,val2:r,operator1:i}=e,a=i===t.CustomFilterOperator.GREATER_THAN;return{customFilters:{customFilters:[{val:a?n:r,operator:t.CustomFilterOperator.GREATER_THAN},{val:a?r:n,operator:t.CustomFilterOperator.LESS_THAN}]}}},testMappingFilterColumn:e=>{var n;if(((n=e.customFilters)==null?void 0:n.customFilters.length)!==2)return!1;let[r,i]=e.customFilters.customFilters;return r.operator===t.CustomFilterOperator.LESS_THAN&&i.operator===t.CustomFilterOperator.GREATER_THAN&&!e.customFilters.and?{operator1:t.CustomFilterOperator.LESS_THAN,val1:r.val.toString(),operator2:t.CustomFilterOperator.GREATER_THAN,val2:i.val.toString()}:i.operator===t.CustomFilterOperator.LESS_THAN&&r.operator===t.CustomFilterOperator.GREATER_THAN&&!e.customFilters.and?{operator1:t.CustomFilterOperator.GREATER_THAN,val1:i.val.toString(),operator2:t.CustomFilterOperator.LESS_THAN,val2:r.val.toLocaleString()}:!1}},n.CUSTOM={label:`sheets-filter.conditions.custom`,operator:p.CUSTOM,order:f.SECOND,numOfParameters:2,getDefaultFormParams:()=>({operator1:p.NONE,val1:``,operator2:p.NONE,val2:``}),testMappingParams:()=>!0,mapToFilterColumn:t=>{let{and:n,val1:a,val2:o,operator1:s,operator2:c}=t;function l(e,t){for(let n of i)if(n.operator===e)return n.mapToFilterColumn({val1:t,operator1:e})}let u=!s||s===m.NONE.operator,d=!c||c===m.NONE.operator;if(u&&d)return r.mapToFilterColumn({});if(u)return l(c,o);if(d)return l(s,a);let f=l(s,a),p=l(c,o),h={customFilters:[f.customFilters.customFilters[0],p.customFilters.customFilters[0]]};return n&&(h.and=e.BooleanNumber.TRUE),{customFilters:h}},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==2)return!1;let n=e.customFilters.customFilters.map(e=>l({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 a(e){let t=i.find(t=>t.operator===e);if(!t)throw Error(`[SheetsFilter]: no condition item found for operator: ${e}`);return t}n.getItemByOperator=a;function o(e,t){for(let n of i.filter(e=>e.numOfParameters===t))if(n.numOfParameters!==0&&n.testMappingParams(e))return n;for(let t of i)if(t.testMappingParams(e))return t;throw Error(`[SheetsFilter]: no condition item can be mapped from the filter map params!`)}n.testMappingParams=o;function s(e){let t=i.find(t=>t.operator===e);return(t==null?void 0:t.numOfParameters)===0?{operator1:t.operator}:t.getDefaultFormParams()}n.getInitialFormParams=s;function c(e,t){return e.mapToFilterColumn(t)}n.mapToFilterColumn=c;function l(e){if(!e)return[r,{}];for(let t of i){let n=t.testMappingFilterColumn(e);if(n)return[t,n]}return[r,{}]}n.testMappingFilterColumn=l})(m||(m={}));function h(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 g(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 _(e,t){return function(n,r){t(n,r,e)}}function v(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 y=`sheets-filter.generate-filter-values.service`,b=(0,e.createIdentifier)(y);let x=class extends e.Disposable{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}),S(o,this._localeService,c,d,new Set(i),a,new Set(l.map(String)),s,u.getStyles()))}};x=v([_(0,(0,e.Inject)(e.LocaleService)),_(1,e.IUniverInstanceService),_(2,e.ILogService)],x);function S(n,r,i,a,o,s,c,l,u){var d;let f=new Map,p=new Map,m=`empty`,h=!n&&((s==null?void 0:s.filterBy)===t.FilterBy.COLORS||(s==null?void 0:s.filterBy)===t.FilterBy.CONDITIONS)&&((d=s.filteredOutRows)==null?void 0:d.size),g=0;for(let t of a.iterateByColumn(i,!1,!1)){let{row:n,rowSpan:i=1}=t,s=0;for(;s<i;){var _,v,y;let d=n+s;if(o.has(d)){s++;continue}let m=t!=null&&t.value?(0,e.extractPureTextFromCell)(t.value):``;if(!m){g+=1,s+=i;continue}let C=(_=t.value)!=null&&_.v&&!t.value.p?(v=u.get((y=t.value)==null?void 0:y.s))==null||(v=v.n)==null?void 0:v.pattern:``,E=C&&e.numfmt.getFormatInfo(C).isDate,D=!1;if(E){let{year:t,month:n,day:r}=e.numfmt.getFormatDateInfo(C);D=t||n||r}if(C&&E&&D){var b,x,S;let n=(b=a.getCellRaw(t.row,t.col))==null?void 0:b.v;if(!n){s++;continue}let[i,o,u]=e.numfmt.format(`yyyy-mm-dd`,Number(n)).split(`-`).map(Number),d=f.get(`${i}`);d||(d={title:`${i}`,key:`${i}`,children:[],count:0,leaf:!1,checked:!1},f.set(`${i}`,d),p.set(`${i}`,[`${i}`]));let g=(x=d.children)==null?void 0:x.find(e=>e.key===`${i}-${o}`);if(!g){var w;g={title:r.t(`sheets-filter.date.${o}`),key:`${i}-${o}`,children:[],count:0,leaf:!1,checked:!1},(w=d.children)==null||w.push(g),p.set(`${i}-${o}`,[`${i}`,`${i}-${o}`])}let _=g==null||(S=g.children)==null?void 0:S.find(e=>e.key===`${i}-${o}-${u}`);if(_)_.originValues.add(m),_.count++,g.count++,d.count++;else{var T;(T=g.children)==null||T.push({title:`${u}`,key:`${i}-${o}-${u}`,count:1,originValues:new Set([m]),leaf:!0,checked:h?!1:c.size?c.has(m):!l}),g.count++,d.count++,p.set(`${i}-${o}-${u}`,[`${i}`,`${i}-${o}`,`${i}-${o}-${u}`])}}else{let e=m,t=f.get(e);t?t.count++:(t={title:m,leaf:!0,checked:h?!1:c.size?c.has(m):!l,key:e,count:1},f.set(e,t),p.set(e,[e]))}s++}}let E=h?!1:n?l:!0;if(g>0){let e={title:r.t(`sheets-filter.panel.empty`),count:g,leaf:!0,checked:E,key:m};f.set(`empty`,e),p.set(`empty`,[m])}return{filterTreeItems:C(Array.from(f.values())),filterTreeMapCache:p}}function C(e){return Array.from(e).sort((e,t)=>e.children&&!t.children?-1:!e.children&&t.children?1:T(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 w=e=>!Number.isNaN(Number(e))&&!Number.isNaN(Number.parseFloat(e));function T(e,t){let n=w(e),r=w(t);return n&&r?Number.parseFloat(e)-Number.parseFloat(t):n&&!r?-1:!n&&r?1:e.localeCompare(t)}function E(e,t){for(let n of e){if(n.key===t)return n;if(n.children){let e=E(n.children,t);if(e)return e}}return null}function D(e){return e.leaf?e.checked:e.children?e.children.every(e=>D(e)):!0}function O(e,t){e.leaf&&(t===void 0?e.checked=!e.checked:e.checked=t),e.children&&e.children.forEach(e=>O(e,t))}function ee(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=ee(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 k(e){"@babel/helpers - typeof";return k=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},k(e)}function te(e,t){if(k(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(k(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function ne(e){var t=te(e,`string`);return k(t)==`symbol`?t:t+``}function A(e,t,n){return(t=ne(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var j,M,N;(0,e.createIdentifier)(`sheets-filter-ui.sheets-filter-panel.service`);let P=class extends e.Disposable{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,n){super(),this._injector=e,this._refRangeService=n,A(this,`_filterBy$`,new o.BehaviorSubject(t.FilterBy.VALUES)),A(this,`filterBy$`,this._filterBy$.asObservable()),A(this,`_filterByModel$`,new o.ReplaySubject(1)),A(this,`filterByModel$`,this._filterByModel$.asObservable()),A(this,`_filterByModel`,null),A(this,`_hasCriteria$`,new o.BehaviorSubject(!1)),A(this,`hasCriteria$`,this._hasCriteria$.asObservable()),A(this,`_filterModel`,null),A(this,`_col$`,new o.BehaviorSubject(-1)),A(this,`col$`,this._col$.asObservable()),A(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 t.FilterBy.VALUES:this._setupByValues(this._filterModel,this.col);break;case t.FilterBy.COLORS:this._setupByColors(this._filterModel,this.col);break;case t.FilterBy.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,n){this._disposePreviousModel();let r=e.getRange();return r.startRow===r.endRow?!1:(this.filterByModel=await I.fromFilterColumn(this._injector,e,n),this._filterBy$.next(t.FilterBy.VALUES),this._listenToFilterHeaderChange(e,n),!0)}async _setupByColors(e,n){this._disposePreviousModel();let r=e.getRange();return r.startRow===r.endRow?!1:(this.filterByModel=await L.fromFilterColumn(this._injector,e,n),this._filterBy$.next(t.FilterBy.COLORS),this._listenToFilterHeaderChange(e,n),!0)}_setupByConditions(e,n){this._disposePreviousModel();let r=e.getRange();return r.startRow===r.endRow?!1:(this.filterByModel=F.fromFilterColumn(this._injector,e,n,e.getFilterColumn(n)),this._filterBy$.next(t.FilterBy.CONDITIONS),this._listenToFilterHeaderChange(e,n),!0)}_disposePreviousModel(){var e;(e=this._filterByModel)==null||e.dispose(),this.filterByModel=null}};P=v([_(0,(0,e.Inject)(e.Injector)),_(1,(0,e.Inject)(a.RefRangeService))],P);let F=j=class extends e.Disposable{static fromFilterColumn(e,t,n,r){let[i,a]=m.testMappingFilterColumn(r==null?void 0:r.getColumnData());return e.createInstance(j,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,A(this,`canApply$`,(0,o.of)(!0)),A(this,`_conditionItem$`,void 0),A(this,`conditionItem$`,void 0),A(this,`_filterConditionFormParams$`,void 0),A(this,`filterConditionFormParams$`,void 0),this._conditionItem$=new o.BehaviorSubject(n),this.conditionItem$=this._conditionItem$.asObservable(),this._filterConditionFormParams$=new o.BehaviorSubject(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(t.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}async apply(){if(this._disposed)return!1;let e=m.mapToFilterColumn(this.conditionItem,this.filterConditionFormParams);return this._commandService.executeCommand(t.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:e})}onPrimaryConditionChange(e){let t=m.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(m.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=m.testMappingParams(t,this.conditionItem.numOfParameters);this._conditionItem$.next(e)}this._filterConditionFormParams$.next(t)}};F=j=v([_(4,e.ICommandService)],F);let I=M=class extends e.Disposable{static async fromFilterColumn(t,n,r){let i=t.get(e.IUniverInstanceService),a=t.get(e.LocaleService),o=t.get(b,e.Quantity.OPTIONAL),{unitId:s,subUnitId:c}=n,l=i.getUniverSheetInstance(s);if(!l)throw Error(`[ByValuesModel]: Workbook not found for filter model with unitId: ${s}!`);let u=l==null?void 0:l.getSheetBySheetId(c);if(!u)throw Error(`[ByValuesModel]: Worksheet not found for filter model with unitId: ${s} and subUnitId: ${c}!`);let d=n.getRange(),f=r,p=n.getFilterColumn(r),m=p==null?void 0:p.getColumnData().filters,h=new Set(m==null?void 0:m.filters),g=!!(m&&m.blank),_=n.getFilteredOutRowsExceptCol(r),v={...d,startRow:d.startRow+1,startColumn:f,endColumn:f},y,x;if(o){let e=await o.getFilterValues({unitId:s,subUnitId:c,filteredOutRowsByOtherColumns:Array.from(_),filterColumn:p,filters:!!m,blankChecked:g,iterateRange:v,alreadyChecked:Array.from(h)});y=e.filterTreeItems,x=e.filterTreeMapCache}else{let e=S(!!m,a,v,u,_,p,h,g,l.getStyles());y=e.filterTreeItems,x=e.filterTreeMapCache}return t.createInstance(M,n,r,y,x)}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,A(this,`_rawFilterItems$`,void 0),A(this,`rawFilterItems$`,void 0),A(this,`filterItems$`,void 0),A(this,`_filterItems`,[]),A(this,`_treeMapCache`,void 0),A(this,`canApply$`,void 0),A(this,`_manuallyUpdateFilterItems$`,void 0),A(this,`_searchString$`,void 0),A(this,`searchString$`,void 0),this._treeMapCache=r,this._searchString$=new o.BehaviorSubject(``),this.searchString$=this._searchString$.asObservable(),this._rawFilterItems$=new o.BehaviorSubject(n),this.rawFilterItems$=this._rawFilterItems$.asObservable(),this._manuallyUpdateFilterItems$=new o.Subject,this.filterItems$=(0,o.merge)((0,o.combineLatest)([this._searchString$.pipe((0,o.throttleTime)(500,void 0,{leading:!0,trailing:!0}),(0,o.startWith)(void 0)),this._rawFilterItems$]).pipe((0,o.map)(([e,t])=>e?ee(t,e.toLowerCase().split(/\s+/).filter(e=>!!e)):t)),this._manuallyUpdateFilterItems$).pipe((0,o.shareReplay)(1)),this.canApply$=this.filterItems$.pipe((0,o.map)(e=>g(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(t){let n=e.Tools.deepClone(this._filterItems);n.forEach(e=>O(e,t)),this._manuallyUpdateFilterItems(n)}onFilterCheckToggled(t){let n=e.Tools.deepClone(this._filterItems),r=E(n,t.key);r&&(O(r,!D(r)),this._manuallyUpdateFilterItems(n))}onFilterOnly(t){let n=e.Tools.deepClone(this._filterItems);n.forEach(e=>O(e,!1)),t.forEach(e=>{let t=E(n,e);t&&O(t,!0)}),this._manuallyUpdateFilterItems(n)}_manuallyUpdateFilterItems(e){this._manuallyUpdateFilterItems$.next(e)}clear(){return this._disposed?Promise.resolve(!1):this._commandService.executeCommand(t.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}async apply(){if(this._disposed)return!1;let e=g(this._filterItems),{checked:n,checkedItems:r}=e,i=this.rawFilterItems,a=0;for(let e of i)a+=e.count;let o=n===0,s=e.checked===a,c={colId:this.col};if(o)throw Error(`[ByValuesModel]: no checked items!`);if(s)return this._commandService.executeCommand(t.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null});{c.filters={};let e=r.filter(e=>e.key!==`empty`);e.length>0&&(c.filters={filters:e.flatMap(e=>e.originValues?Array.from(e.originValues):[e.title])}),e.length!==r.length&&(c.filters.blank=!0)}return this._commandService.executeCommand(t.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:c})}};I=M=v([_(4,e.ICommandService)],I);let L=N=class extends e.Disposable{static async fromFilterColumn(t,n,r){var a,o,s;let c=t.get(e.IUniverInstanceService),{unitId:l,subUnitId:u}=n,d=c.getUniverSheetInstance(l);if(!d)throw Error(`[ByColorsModel]: Workbook not found for filter model with unitId: ${l}!`);let f=d==null?void 0:d.getSheetBySheetId(u);if(!f)throw Error(`[ByColorsModel]: Worksheet not found for filter model with unitId: ${l} and subUnitId: ${u}!`);let p=n.getRange(),m=r,h=(a=n.getFilterColumn(r))==null?void 0:a.getColumnData().colorFilters,g=n.getFilteredOutRowsExceptCol(r),_={...p,startRow:p.startRow+1,startColumn:m,endColumn:m},v=new Map,y=new Set((o=h==null?void 0:h.cellFillColors)==null?[]:o),b=new Map,x=new Set((s=h==null?void 0:h.cellTextColors)==null?[]:s);for(let t of f.iterateByColumn(_,!1,!0)){let{row:n,col:r,value:a}=t;if(g.has(n))continue;let o=f.getComposedCellStyleByCellData(n,r,a);if(o.bg&&o.bg.rgb){let t=new e.ColorKit(o.bg.rgb).toRgbString();v.has(t)||v.set(t,{color:t,checked:y.has(t)})}else v.set(`default-fill-color`,{color:null,checked:y.has(null)});if(o.cl&&o.cl.rgb){let t=new e.ColorKit(o.cl.rgb).toRgbString();b.has(t)||b.set(t,{color:t,checked:x.has(t)})}else b.set(`default-font-color`,{color:i.COLOR_BLACK_RGB,checked:x.has(i.COLOR_BLACK_RGB)})}return t.createInstance(N,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,A(this,`canApply$`,(0,o.of)(!0)),A(this,`_cellFillColors$`,void 0),A(this,`cellFillColors$`,void 0),A(this,`_cellTextColors$`,void 0),A(this,`cellTextColors$`,void 0),this._cellFillColors$=new o.BehaviorSubject(Array.from(n.values())),this.cellFillColors$=this._cellFillColors$.asObservable(),this._cellTextColors$=new o.BehaviorSubject(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(t.SetSheetsFilterCriteriaCommand.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),n=this.cellTextColors.filter(e=>e.checked).map(e=>e.color);if(e.length===0&&n.length===0)return this._commandService.executeCommand(t.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null});let r={colId:this.col};return e.length>0?r.colorFilters={cellFillColors:e}:n.length>0&&(r.colorFilters={cellTextColors:n}),this._commandService.executeCommand(t.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:r})}};L=N=v([_(4,e.ICommandService)],L);const R=`FILTER_PANEL_OPENED`,z={id:`sheet.operation.open-filter-panel`,type:e.CommandType.OPERATION,handler:(r,i)=>{let a=r.get(e.IContextService),o=r.get(t.SheetsFilterService),s=r.get(P),c=r.get(e.ICommandService),l=r.has(n.IEditorBridgeService)?r.get(n.IEditorBridgeService):null;l!=null&&l.isVisible().visible&&c.syncExecuteCommand(n.SetCellEditVisibleOperation.id,{visible:!1});let{unitId:u,subUnitId:d,col:f}=i,p=o.getFilterModel(u,d);return p?(s.setupCol(p,f),a.getContextValue(`FILTER_PANEL_OPENED`)||a.setContextValue(R,!0),!0):!1}},B={id:`sheet.operation.close-filter-panel`,type:e.CommandType.OPERATION,handler:t=>{let n=t.get(e.IContextService),i=t.get(P),a=t.get(r.ILayoutService,e.Quantity.OPTIONAL);return n.getContextValue(`FILTER_PANEL_OPENED`)?(n.setContextValue(R,!1),a==null||a.focus(),i.terminate()):!1}},V={id:`sheet.operation.apply-filter`,type:e.CommandType.OPERATION,handler:(e,t)=>{let{filterBy:n}=t;return e.get(P).changeFilterBy(n)}};var H=`@univerjs/sheets-filter-ui`,U=`0.20.0`;const W=`sheets-filter-ui.config`;Symbol(W);const G={};let K=class extends e.Disposable{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(n=>{if(n.id===t.SmartToggleSheetsFilterCommand.id){var r;let t=(0,a.getSheetCommandTarget)(this._injector.get(e.IUniverInstanceService));if(!t)return;let{unitId:n,subUnitId:o,worksheet:s}=t,c=(r=this._sheetsFilterService.getFilterModel(n,o))==null?void 0:r.getRange(),l;if(c)l=this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[a.RangeProtectionPermissionViewPoint],worksheetTypes:[a.WorksheetFilterPermission,a.WorksheetViewPermission]},[c],n,o);else{var i;let e=(i=this._sheetsSelectionService.getCurrentLastSelection())==null?void 0:i.range;if(e){let t={...e};t=e.startColumn===e.endColumn&&e.startRow===e.endRow?(0,a.expandToContinuousRange)(t,{left:!0,right:!0,up:!0,down:!0},s):t,l=this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[a.RangeProtectionPermissionViewPoint],worksheetTypes:[a.WorksheetViewPermission,a.WorksheetFilterPermission]},[t],n,o)}else l=this._sheetPermissionCheckPermission.permissionCheckWithoutRange({rangeTypes:[a.RangeProtectionPermissionViewPoint],worksheetTypes:[a.WorksheetViewPermission,a.WorksheetFilterPermission]})}l||this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.filterErr`))}if(n.id===z.id){var o;let t=n.params,{unitId:r,subUnitId:i}=t,s=(o=this._sheetsFilterService.getFilterModel(r,i))==null?void 0:o.getRange(),c=e.Tools.deepClone(s);c&&(c.startColumn=t.col,c.endColumn=t.col,this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[a.RangeProtectionPermissionViewPoint],worksheetTypes:[a.WorksheetFilterPermission,a.WorksheetViewPermission]},[c],r,i)||this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.filterErr`)))}}))}};K=v([_(0,(0,e.Inject)(t.SheetsFilterService)),_(1,(0,e.Inject)(e.LocaleService)),_(2,e.ICommandService),_(3,(0,e.Inject)(a.SheetPermissionCheckController)),_(4,(0,e.Inject)(e.Injector)),_(5,(0,e.Inject)(a.SheetsSelectionsService))],K);const re=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 ie=class{static drawNoCriteria(e,t,n,r){e.save(),i.Rect.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(),i.Rect.drawWith(e,{radius:2,width:16,height:16,fill:r}),e.scale(t/16,t/16),e.fillStyle=n,e.fill(re),e.restore()}};let q=class extends i.Shape{constructor(e,t,n,r,i){super(e,t),this._contextService=n,this._commandService=r,this._themeService=i,A(this,`_cellWidth`,0),A(this,`_cellHeight`,0),A(this,`_filterParams`,void 0),A(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?ie.drawHasCriteria(e,16,s,c):ie.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(z.id)||setTimeout(()=>{this._commandService.executeCommand(z.id,{unitId:n,subUnitId:r,col:t})},200)}onPointerEnter(){this._hovered=!0,this.makeDirty(!0)}onPointerLeave(){this._hovered=!1,this.makeDirty(!0)}};q=v([_(2,e.IContextService),_(3,e.ICommandService),_(4,(0,e.Inject)(e.ThemeService))],q);function ae(t,n,r,i){switch(i){case e.VerticalAlign.TOP:return t+1;case e.VerticalAlign.MIDDLE:return t+Math.max(0,(r-16)/2);case e.VerticalAlign.BOTTOM:default:return n-16-1}}let J=class extends e.RxDisposable{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,A(this,`_currentRenderParams`,null),A(this,`_filterRangeShape`,null),A(this,`_buttonRenderDisposable`,null),A(this,`_filterButtonShapes`,[]),this._initRenderer()}dispose(){super.dispose(),this._disposeRendering()}_initRenderer(){this.disposeWithMe(this._themeService.currentTheme$.subscribe(()=>{this._refreshRendering(this._currentRenderParams)})),this._sheetSkeletonManagerService.currentSkeleton$.pipe((0,o.switchMap)(n=>{var r,i;if(!n)return(0,o.of)(null);let{unit:s,unitId:c}=this._context,l=((r=s.getActiveSheet())==null?void 0:r.getSheetId())||``,u=(i=this._sheetsFilterService.getFilterModel(c,l))==null?void 0:i,d=()=>({unitId:c,worksheetId:l,filterModel:u,range:u==null?void 0:u.getRange(),skeleton:n.skeleton});return(0,e.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([n])=>{var r;return n.type===e.CommandType.MUTATION&&((r=n.params)==null?void 0:r.unitId)===s.getUnitId()&&(t.FILTER_MUTATIONS.has(n.id)||n.id===a.SetRangeValuesMutation.id)}),(0,o.throttleTime)(20,void 0,{leading:!1,trailing:!0}),(0,o.map)(d),(0,o.startWith)(d()))}),(0,o.takeUntil)(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:r}=this._context,{rowHeaderWidth:i,columnHeaderHeight:o}=t,s=this._filterRangeShape=new n.SelectionControl(r,1e3,this._themeService,{rowHeaderWidth:i,columnHeaderHeight:o,enableAutoFill:!1,highlightHeader:!1}),c=(0,a.attachSelectionWithCoord)({range:e,primary:null,style:{fill:`rgba(0, 0, 0, 0.0)`}},t);s.updateRangeBySelectionWithCoord(c),s.setEvent(!1),r.makeDirty(!0)}_renderButtons(t){let{range:r,filterModel:i,unitId:a,skeleton:o,worksheetId:s}=t,{unit:c,scene:l}=this._context,u=c.getSheetBySheetId(s);if(!u)return;this._interceptCellContent(a,s,t.range);let{startColumn:d,endColumn:f,startRow:p}=r;for(let t=d;t<=f;t++){let r=`sheets-filter-button-${t}`,c=(0,n.getCoordByCell)(p,t,l,o),d=u.getComposedCellStyle(p,t),f=(d==null?void 0:d.vt)||e.VerticalAlign.BOTTOM,{startX:m,startY:h,endX:g,endY:_}=c,v=g-m,y=_-h;if(y<=1||v<=1)continue;let b=!!i.getFilterColumn(t),x={left:g-16-1,top:ae(h,_,y,f),height:16,width:16,zIndex:5e3,cellHeight:y,cellWidth:v,filterParams:{unitId:a,subUnitId:s,col:t,hasCriteria:b}},S=this._injector.createInstance(q,r,x);this._filterButtonShapes.push(S)}l.addObjects(this._filterButtonShapes),l.makeDirty()}_interceptCellContent(t,n,r){let{startRow:i,startColumn:o,endColumn:s}=r;this._buttonRenderDisposable=this._sheetInterceptorService.intercept(a.INTERCEPTOR_POINT.CELL_CONTENT,{effect:e.InterceptorEffectEnum.Style,handler:(e,r,a)=>{let{row:c,col:l,unitId:u,subUnitId:d}=r;return u!==t||d!==n||c!==i||l<o||l>s?a(e):((!e||e===r.rawData)&&(e={...r.rawData}),e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,rightOffset:16},a(e))},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=[]}};J=v([_(1,(0,e.Inject)(e.Injector)),_(2,(0,e.Inject)(n.SheetSkeletonManagerService)),_(3,(0,e.Inject)(t.SheetsFilterService)),_(4,(0,e.Inject)(e.ThemeService)),_(5,(0,e.Inject)(a.SheetInterceptorService)),_(6,e.ICommandService),_(7,n.ISheetSelectionRenderService)],J);let Y=class extends e.RxDisposable{constructor(n,r){super(),this._renderManagerService=n,this._sheetsRenderService=r,[t.SetSheetsFilterRangeMutation,t.SetSheetsFilterCriteriaMutation,t.RemoveSheetsFilterMutation,t.ReCalcSheetsFilterMutation].forEach(e=>this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(e.id))),this.disposeWithMe(this._renderManagerService.registerRenderModule(e.UniverInstanceType.UNIVER_SHEET,[J]))}};Y=v([_(0,i.IRenderManagerService),_(1,(0,e.Inject)(n.SheetsRenderService))],Y);let X=class extends e.Plugin{constructor(t=G,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{menu:i,...a}=(0,e.merge)({},G,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(W,a)}onStarting(){[[K],[Y]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(K)}onRendered(){this._injector.get(Y)}};A(X,`type`,e.UniverInstanceType.UNIVER_SHEET),A(X,`pluginName`,`SHEET_FILTER_UI_PLUGIN`),A(X,`packageName`,H),A(X,`version`,U),X=v([(0,e.DependentOn)(t.UniverSheetsFilterPlugin),_(1,(0,e.Inject)(e.Injector)),_(2,e.IConfigService)],X);function oe(i){let s=i.get(t.SheetsFilterService);return{id:t.SmartToggleSheetsFilterCommand.id,type:r.MenuItemType.BUTTON_SELECTOR,icon:`FilterIcon`,tooltip:`sheets-filter.toolbar.smart-toggle-filter-tooltip`,hidden$:(0,r.getMenuHiddenObservable)(i,e.UniverInstanceType.UNIVER_SHEET),activated$:s.activeFilterModel$.pipe((0,o.map)(e=>!!e)),disabled$:(0,n.getObservableWithExclusiveRange$)(i,(0,n.getCurrentRangeDisable$)(i,{worksheetTypes:[a.WorksheetFilterPermission,a.WorksheetViewPermission],rangeTypes:[a.RangeProtectionPermissionViewPoint]}))}}function se(n){let i=n.get(t.SheetsFilterService);return{id:t.ClearSheetsFilterCriteriaCommand.id,type:r.MenuItemType.BUTTON,title:`sheets-filter.toolbar.clear-filter-criteria`,hidden$:(0,r.getMenuHiddenObservable)(n,e.UniverInstanceType.UNIVER_SHEET),disabled$:i.activeFilterModel$.pipe((0,o.switchMap)(e=>{var t;return(t=e==null?void 0:e.hasCriteria$.pipe((0,o.map)(e=>!e)))==null?(0,o.of)(!0):t}))}}function ce(n){let i=n.get(t.SheetsFilterService);return{id:t.ReCalcSheetsFilterCommand.id,type:r.MenuItemType.BUTTON,title:`sheets-filter.toolbar.re-calc-filter-conditions`,hidden$:(0,r.getMenuHiddenObservable)(n,e.UniverInstanceType.UNIVER_SHEET),disabled$:i.activeFilterModel$.pipe((0,o.switchMap)(e=>{var t;return(t=e==null?void 0:e.hasCriteria$.pipe((0,o.map)(e=>!e)))==null?(0,o.of)(!0):t}))}}const le={[r.RibbonDataGroup.ORGANIZATION]:{[t.SmartToggleSheetsFilterCommand.id]:{order:2,menuItemFactory:oe,[t.ClearSheetsFilterCriteriaCommand.id]:{order:0,menuItemFactory:se},[t.ReCalcSheetsFilterCommand.id]:{order:1,menuItemFactory:ce}}}};function ue(t){let{model:n}=t,i=(0,r.useDependency)(e.LocaleService),a=(0,r.useObservable)(n.cellFillColors$,[],!0),o=(0,r.useObservable)(n.cellTextColors$,[],!0),s=(0,u.useCallback)(e=>{n.onFilterCheckToggled(e)},[n]),f=(0,u.useCallback)(e=>{n.onFilterCheckToggled(e,!1)},[n]);return(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-colors-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel`,className:(0,c.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`,c.borderClassName),children:[a.length>1&&(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white`,children:i.t(`sheets-filter.panel.filter-by-cell-fill-color`)}),(0,d.jsx)(`div`,{className:`univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2`,children:a.map((e,t)=>(0,d.jsxs)(`div`,{className:`univer-relative univer-size-6`,onClick:()=>s(e),children:[e.color?(0,d.jsx)(`button`,{type:`button`,className:(0,c.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`),style:{backgroundColor:e.color}}):(0,d.jsx)(l.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`}),e.checked&&(0,d.jsx)(de,{})]},`sheets-filter-cell-fill-color-${t}`))})]}),o.length>1&&(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white`,children:i.t(`sheets-filter.panel.filter-by-cell-text-color`)}),(0,d.jsx)(`div`,{className:`univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2`,children:o.map((e,t)=>(0,d.jsxs)(`div`,{className:`univer-relative univer-size-6`,onClick:()=>f(e),children:[(0,d.jsx)(`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:(0,d.jsx)(l.AIcon,{style:{color:e.color}})}),e.checked&&(0,d.jsx)(de,{})]},`sheets-filter-cell-text-color-${t}`))})]}),a.length<=1&&o.length<=1&&(0,d.jsx)(`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:i.t(`sheets-filter.panel.filter-by-color-none`)})]})})}function de(){return(0,d.jsx)(`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:(0,d.jsx)(l.SuccessIcon,{className:`univer-size-full univer-font-bold univer-text-[#418F1F]`})})}function fe(t){var n,i;let{model:a}=t,o=(0,r.useDependency)(e.LocaleService),s=(0,r.useObservable)(a.conditionItem$,void 0),l=(0,r.useObservable)(a.filterConditionFormParams$,void 0),f=l!=null&&l.and?`AND`:`OR`,p=(0,u.useCallback)(e=>{a.onConditionFormChange({and:e===`AND`})},[a]),h=pe(o),g=(0,u.useCallback)(e=>{a.onPrimaryConditionChange(e)},[a]),_=me(o),v=(0,u.useCallback)(e=>{a.onConditionFormChange(e)},[a]),y=o.t(`sheets-filter.panel.input-values-placeholder`);function b(e,t,n){let r=m.getItemByOperator(e).numOfParameters===1;return(0,d.jsxs)(d.Fragment,{children:[n===`operator2`&&(0,d.jsxs)(c.RadioGroup,{value:f,onChange:p,children:[(0,d.jsx)(c.Radio,{value:`AND`,children:o.t(`sheets-filter.panel.and`)}),(0,d.jsx)(c.Radio,{value:`OR`,children:o.t(`sheets-filter.panel.or`)})]}),(0,d.jsx)(c.Select,{value:e,options:_,onChange:e=>v({[n]:e})}),r&&(0,d.jsx)(`div`,{children:(0,d.jsx)(c.Input,{className:`univer-mt-2`,value:t,placeholder:y,onChange:e=>v({[n===`operator1`?`val1`:`val2`]:e})})})]})}return(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-conditions-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:s&&l&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(c.Select,{value:s.operator,options:h,onChange:g}),m.getItemByOperator(s.operator).numOfParameters===0?null:(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel-conditions-container-inner`,className:(0,c.clsx)(`univer-mt-2 univer-flex-grow univer-overflow-hidden univer-rounded-md univer-p-2`,c.borderClassName),children:[s.numOfParameters>=1&&b(l.operator1,(n=l.val1)==null?``:n,`operator1`),s.numOfParameters>=2&&b(l.operator2,(i=l.val2)==null?``:i,`operator2`),(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel-conditions-desc`,className:`univer-mt-2 univer-text-xs univer-text-gray-500`,children:[o.t(`sheets-filter.panel.?`),(0,d.jsx)(`br`,{}),o.t(`sheets-filter.panel.*`)]})]})]})})}function pe(e){return(0,u.useMemo)(()=>[{options:[{label:e.t(m.NONE.label),value:m.NONE.operator}]},{options:[{label:e.t(m.EMPTY.label),value:m.EMPTY.operator},{label:e.t(m.NOT_EMPTY.label),value:m.NOT_EMPTY.operator}]},{options:[{label:e.t(m.TEXT_CONTAINS.label),value:m.TEXT_CONTAINS.operator},{label:e.t(m.DOES_NOT_CONTAIN.label),value:m.DOES_NOT_CONTAIN.operator},{label:e.t(m.STARTS_WITH.label),value:m.STARTS_WITH.operator},{label:e.t(m.ENDS_WITH.label),value:m.ENDS_WITH.operator},{label:e.t(m.EQUALS.label),value:m.EQUALS.operator}]},{options:[{label:e.t(m.GREATER_THAN.label),value:m.GREATER_THAN.operator},{label:e.t(m.GREATER_THAN_OR_EQUAL.label),value:m.GREATER_THAN_OR_EQUAL.operator},{label:e.t(m.LESS_THAN.label),value:m.LESS_THAN.operator},{label:e.t(m.LESS_THAN_OR_EQUAL.label),value:m.LESS_THAN_OR_EQUAL.operator},{label:e.t(m.EQUAL.label),value:m.EQUAL.operator},{label:e.t(m.NOT_EQUAL.label),value:m.NOT_EQUAL.operator},{label:e.t(m.BETWEEN.label),value:m.BETWEEN.operator},{label:e.t(m.NOT_BETWEEN.label),value:m.NOT_BETWEEN.operator}]},{options:[{label:e.t(m.CUSTOM.label),value:m.CUSTOM.operator}]}],[e.getCurrentLocale(),e])}function me(e){return(0,u.useMemo)(()=>m.ALL_CONDITIONS.filter(e=>e.numOfParameters!==2).map(t=>({label:e.t(t.label),value:t.operator})),[e.getCurrentLocale(),e])}function he(t){let{model:n}=t,i=(0,r.useDependency)(e.LocaleService),a=(0,r.useObservable)(n.searchString$,``,!0),o=(0,r.useObservable)(n.filterItems$,void 0,!0),s=i.t(`sheets-filter.panel.filter-only`),l=g(o),f=l.checked>0&&l.unchecked===0,p=l.checked>0&&l.unchecked>0,m=n.treeMapCache,h=(0,u.useCallback)(()=>{n.onCheckAllToggled(!f)},[n,f]),_=(0,u.useCallback)(e=>{n.setSearchString(e)},[n]);function v(e){let t=[];return e.forEach(e=>{e.checked&&t.push(e.key),e.children&&(t=t.concat(v(e.children)))}),t}return(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel-values-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:[(0,d.jsx)(c.Input,{autoFocus:!0,value:a,placeholder:i.t(`sheets-filter.panel.search-placeholder`),onChange:_}),(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel`,className:(0,c.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`,c.borderClassName),children:[(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-values-item`,className:`univer-box-border univer-h-8 univer-w-full univer-py-0.5`,children:(0,d.jsxs)(`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:[(0,d.jsx)(c.Checkbox,{indeterminate:p,disabled:o.length===0,checked:f,onChange:h}),(0,d.jsx)(`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:`${i.t(`sheets-filter.panel.select-all`)}`}),(0,d.jsx)(`span`,{"data-u-comp":`sheets-filter-panel-values-item-count`,className:`univer-text-gray-400 dark:!univer-text-gray-500`,children:`(${l.checked}/${l.checked+l.unchecked})`})]})}),(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-values-virtual`,className:`univer-flex-grow`,children:(0,d.jsx)(c.Tree,{data:o,defaultExpandAll:!1,valueGroup:v(o),onChange:e=>{n.onFilterCheckToggled(e)},defaultCache:m,itemHeight:28,treeNodeClassName:`
2
2
  univer-pr-2 univer-border-box univer-rounded-md
3
3
  [&:hover_a]:univer-inline-block
4
4
  hover:univer-bg-gray-50 univer-h-full
package/lib/es/index.js CHANGED
@@ -1,7 +1,7 @@
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,attachSelectionWithCoord as we,getCoordByCell as Te,getCurrentRangeDisable$ as Ee,getObservableWithExclusiveRange$ as De,whenSheetEditorFocused as Oe}from"@univerjs/sheets-ui";import{ComponentContainer as ke,ComponentManager as Ae,ILayoutService as je,IMenuManagerService as Me,IMessageService as Ne,IShortcutService as Pe,KeyCode as Fe,MenuItemType as Ie,MetaKeys as Le,RibbonDataGroup as Re,getMenuHiddenObservable as ze,useComponentsOfPart as Be,useDependency as k,useObservable as A}from"@univerjs/ui";import{COLOR_BLACK_RGB as Ve,IRenderManagerService as He,Rect as Ue,Shape as We}from"@univerjs/engine-render";import{INTERCEPTOR_POINT as Ge,RangeProtectionPermissionViewPoint as j,RefRangeService as Ke,SetRangeValuesMutation as qe,SheetInterceptorService as Je,SheetPermissionCheckController as Ye,SheetsSelectionsService as Xe,WorksheetFilterPermission as M,WorksheetViewPermission as N,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(Ke))],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:Ve,checked:x.has(Ve)})}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(je,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.19.0`;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(Ye)),W(4,u(d)),W(5,u(Xe))],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(),Ue.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(),Ue.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 We{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===qe.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=we({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=Te(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(Ge.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(Je)),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,He),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:Ie.BUTTON_SELECTOR,icon:`FilterIcon`,tooltip:`sheets-filter.toolbar.smart-toggle-filter-tooltip`,hidden$:ze(e,b.UNIVER_SHEET),activated$:t.activeFilterModel$.pipe(F(e=>!!e)),disabled$:De(e,Ee(e,{worksheetTypes:[M,N],rangeTypes:[j]}))}}function mn(e){let t=e.get(O);return{id:ie.id,type:Ie.BUTTON,title:`sheets-filter.toolbar.clear-filter-criteria`,hidden$:ze(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:Ie.BUTTON,title:`sheets-filter.toolbar.re-calc-filter-conditions`,hidden$:ze(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={[Re.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 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.0`;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:`
2
2
  univer-pr-2 univer-border-box univer-rounded-md
3
3
  [&:hover_a]:univer-inline-block
4
4
  hover:univer-bg-gray-50 univer-h-full
5
5
  univer-text-gray-900 dark:hover:!univer-bg-gray-900
6
6
  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(Ne),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,_=Be(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(ke,{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:Fe.L|Le.CTRL_COMMAND|Le.SHIFT,description:`sheets-filter.shortcut.smart-toggle-filter`,preconditions:Oe,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(Ae)),W(2,u(J)),W(3,u(be)),W(4,u(O)),W(5,u(p)),W(6,Pe),W(7,a),W(8,Me),W(9,s),W(10,Ne),W(11,u(Se)),W(12,He)],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};
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};
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
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,attachSelectionWithCoord as we,getCoordByCell as Te,getCurrentRangeDisable$ as Ee,getObservableWithExclusiveRange$ as De,whenSheetEditorFocused as Oe}from"@univerjs/sheets-ui";import{ComponentContainer as ke,ComponentManager as Ae,ILayoutService as je,IMenuManagerService as Me,IMessageService as Ne,IShortcutService as Pe,KeyCode as Fe,MenuItemType as Ie,MetaKeys as Le,RibbonDataGroup as Re,getMenuHiddenObservable as ze,useComponentsOfPart as Be,useDependency as k,useObservable as A}from"@univerjs/ui";import{COLOR_BLACK_RGB as Ve,IRenderManagerService as He,Rect as Ue,Shape as We}from"@univerjs/engine-render";import{INTERCEPTOR_POINT as Ge,RangeProtectionPermissionViewPoint as j,RefRangeService as Ke,SetRangeValuesMutation as qe,SheetInterceptorService as Je,SheetPermissionCheckController as Ye,SheetsSelectionsService as Xe,WorksheetFilterPermission as M,WorksheetViewPermission as N,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(Ke))],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:Ve,checked:x.has(Ve)})}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(je,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.19.0`;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(Ye)),W(4,u(d)),W(5,u(Xe))],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(),Ue.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(),Ue.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 We{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===qe.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=we({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=Te(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(Ge.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(Je)),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,He),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:Ie.BUTTON_SELECTOR,icon:`FilterIcon`,tooltip:`sheets-filter.toolbar.smart-toggle-filter-tooltip`,hidden$:ze(e,b.UNIVER_SHEET),activated$:t.activeFilterModel$.pipe(F(e=>!!e)),disabled$:De(e,Ee(e,{worksheetTypes:[M,N],rangeTypes:[j]}))}}function mn(e){let t=e.get(O);return{id:ie.id,type:Ie.BUTTON,title:`sheets-filter.toolbar.clear-filter-criteria`,hidden$:ze(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:Ie.BUTTON,title:`sheets-filter.toolbar.re-calc-filter-conditions`,hidden$:ze(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={[Re.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 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.0`;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:`
2
2
  univer-pr-2 univer-border-box univer-rounded-md
3
3
  [&:hover_a]:univer-inline-block
4
4
  hover:univer-bg-gray-50 univer-h-full
5
5
  univer-text-gray-900 dark:hover:!univer-bg-gray-900
6
6
  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(Ne),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,_=Be(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(ke,{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:Fe.L|Le.CTRL_COMMAND|Le.SHIFT,description:`sheets-filter.shortcut.smart-toggle-filter`,preconditions:Oe,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(Ae)),W(2,u(J)),W(3,u(be)),W(4,u(O)),W(5,u(p)),W(6,Pe),W(7,a),W(8,Me),W(9,s),W(10,Ne),W(11,u(Se)),W(12,He)],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};
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};
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets-filter`),require(`@univerjs/sheets-ui`),require(`@univerjs/ui`),require(`@univerjs/engine-render`),require(`@univerjs/sheets`),require(`rxjs`),require(`@univerjs/rpc`),require(`@univerjs/design`),require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-filter`,`@univerjs/sheets-ui`,`@univerjs/ui`,`@univerjs/engine-render`,`@univerjs/sheets`,`rxjs`,`@univerjs/rpc`,`@univerjs/design`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFilterUi={},e.UniverCore,e.UniverSheetsFilter,e.UniverSheetsUi,e.UniverUi,e.UniverEngineRender,e.UniverSheets,e.rxjs,e.UniverRpc,e.UniverDesign,e.React,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let f=function(e){return e[e.FIRST=0]=`FIRST`,e[e.SECOND=1]=`SECOND`,e}({}),p=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}({}),m;(function(e){let r=e.NONE={label:`sheets-filter.conditions.none`,operator:p.NONE,order:f.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.NONE]: should not have initial form params!`)},testMappingParams:e=>e.operator1===p.NONE,mapToFilterColumn:()=>null,testMappingFilterColumn:e=>!e.customFilters&&!e.filters?{}:!1},i=e.ALL_CONDITIONS=[r,e.EMPTY={label:`sheets-filter.conditions.empty`,operator:p.EMPTY,order:f.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.EMPTY]: should not have initial form params!`)},testMappingParams:({operator1:e})=>e===p.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:p.EMPTY}:!1}},e.NOT_EMPTY={label:`sheets-filter.conditions.not-empty`,operator:p.NOT_EMPTY,order:f.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.NOT_EMPTY]: should not have initial form params!`)},testMappingParams:({operator1:e})=>e===p.NOT_EMPTY,mapToFilterColumn:()=>({customFilters:{customFilters:[{val:``,operator:n.CustomFilterOperator.NOT_EQUALS}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.val===` `&&r.operator===n.CustomFilterOperator.NOT_EQUALS?{operator1:p.NOT_EMPTY}:!1}},e.TEXT_CONTAINS={label:`sheets-filter.conditions.text-contains`,operator:p.CONTAINS,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.CONTAINS,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.CONTAINS,val1:r.slice(1,-1)}:!1}},e.DOES_NOT_CONTAIN={label:`sheets-filter.conditions.does-not-contain`,operator:p.DOES_NOT_CONTAIN,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.DOES_NOT_CONTAIN,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`*${e.val1}*`,operator:n.CustomFilterOperator.NOT_EQUALS}]}}),testMappingParams:e=>{let[t]=h(e);return t===p.DOES_NOT_CONTAIN},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0],i=r.val.toString();return r.operator===n.CustomFilterOperator.NOT_EQUALS&&i.startsWith(`*`)&&i.endsWith(`*`)?{operator1:p.DOES_NOT_CONTAIN,val1:i.slice(1,-1)}:!1}},e.STARTS_WITH={label:`sheets-filter.conditions.starts-with`,operator:p.STARTS_WITH,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.STARTS_WITH,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`${e.val1}*`}]}}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.STARTS_WITH,val1:r.slice(0,-1)}:!1}},e.ENDS_WITH={label:`sheets-filter.conditions.ends-with`,operator:p.ENDS_WITH,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.ENDS_WITH,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`*${e.val1}`}]}}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.ENDS_WITH,val1:r.slice(1)}:!1}},e.EQUALS={label:`sheets-filter.conditions.equals`,operator:p.EQUALS,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.EQUALS,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.EQUALS,val1:``}:((n=e.customFilters)==null?void 0:n.customFilters.length)===1&&!e.customFilters.customFilters[0].operator?{operator1:p.EQUALS,val1:e.customFilters.customFilters[0].val.toString()}:!1}},e.GREATER_THAN={label:`sheets-filter.conditions.greater-than`,operator:n.CustomFilterOperator.GREATER_THAN,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:n.CustomFilterOperator.GREATER_THAN,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:n.CustomFilterOperator.GREATER_THAN}]}}),testMappingParams:e=>{let[t]=h(e);return t===n.CustomFilterOperator.GREATER_THAN},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===n.CustomFilterOperator.GREATER_THAN?{operator1:n.CustomFilterOperator.GREATER_THAN,val1:r.val.toString()}:!1}},e.GREATER_THAN_OR_EQUAL={label:`sheets-filter.conditions.greater-than-or-equal`,operator:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===n.CustomFilterOperator.GREATER_THAN_OR_EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===n.CustomFilterOperator.GREATER_THAN_OR_EQUAL?{operator1:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:r.val.toString()}:!1}},e.LESS_THAN={label:`sheets-filter.conditions.less-than`,operator:n.CustomFilterOperator.LESS_THAN,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:n.CustomFilterOperator.LESS_THAN,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===n.CustomFilterOperator.LESS_THAN},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:n.CustomFilterOperator.LESS_THAN}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===n.CustomFilterOperator.LESS_THAN?{operator1:n.CustomFilterOperator.LESS_THAN,val1:r.val.toString()}:!1}},e.LESS_THAN_OR_EQUAL={label:`sheets-filter.conditions.less-than-or-equal`,operator:n.CustomFilterOperator.LESS_THAN_OR_EQUAL,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:n.CustomFilterOperator.LESS_THAN_OR_EQUAL,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===n.CustomFilterOperator.LESS_THAN_OR_EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:n.CustomFilterOperator.LESS_THAN_OR_EQUAL}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===n.CustomFilterOperator.LESS_THAN_OR_EQUAL?{operator1:n.CustomFilterOperator.LESS_THAN_OR_EQUAL,val1:r.val.toString()}:!1}},e.EQUAL={label:`sheets-filter.conditions.equal`,operator:n.CustomFilterOperator.EQUAL,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:n.CustomFilterOperator.EQUAL,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===n.CustomFilterOperator.EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:n.CustomFilterOperator.EQUAL}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===n.CustomFilterOperator.EQUAL?{operator1:n.CustomFilterOperator.EQUAL,val1:r.val.toString()}:!1}},e.NOT_EQUAL={label:`sheets-filter.conditions.not-equal`,operator:n.CustomFilterOperator.NOT_EQUALS,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:n.CustomFilterOperator.NOT_EQUALS,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===n.CustomFilterOperator.NOT_EQUALS},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:n.CustomFilterOperator.NOT_EQUALS}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===n.CustomFilterOperator.NOT_EQUALS?{operator1:n.CustomFilterOperator.NOT_EQUALS,val1:r.val.toString()}:!1}},e.BETWEEN={label:`sheets-filter.conditions.between`,operator:p.BETWEEN,order:f.SECOND,numOfParameters:2,getDefaultFormParams:()=>({and:!0,operator1:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:``,operator2:n.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:``}),testMappingParams:e=>{let{and:t,operator1:r,operator2:i}=e;if(!t)return!1;let a=[r,i];return a.includes(n.CustomFilterOperator.GREATER_THAN_OR_EQUAL)&&a.includes(n.CustomFilterOperator.LESS_THAN_OR_EQUAL)},mapToFilterColumn:e=>{let{val1:r,val2:i,operator1:a}=e,o=a===n.CustomFilterOperator.GREATER_THAN_OR_EQUAL;return{customFilters:{and:t.BooleanNumber.TRUE,customFilters:[{val:o?r:i,operator:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL},{val:o?i:r,operator:n.CustomFilterOperator.LESS_THAN_OR_EQUAL}]}}},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==2)return!1;let[r,i]=e.customFilters.customFilters;return r.operator===n.CustomFilterOperator.GREATER_THAN_OR_EQUAL&&i.operator===n.CustomFilterOperator.LESS_THAN_OR_EQUAL&&e.customFilters.and?{and:!0,operator1:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:r.val.toString(),operator2:n.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:i.val.toString()}:i.operator===n.CustomFilterOperator.GREATER_THAN_OR_EQUAL&&r.operator===n.CustomFilterOperator.LESS_THAN_OR_EQUAL&&e.customFilters.and?{and:!0,operator1:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:i.val.toString(),operator2:n.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:r.val.toLocaleString()}:!1}},e.NOT_BETWEEN={label:`sheets-filter.conditions.not-between`,operator:p.NOT_BETWEEN,order:f.SECOND,numOfParameters:2,getDefaultFormParams:()=>({operator1:n.CustomFilterOperator.LESS_THAN,val1:``,operator2:n.CustomFilterOperator.GREATER_THAN,val2:``}),testMappingParams:e=>{let{and:t,operator1:r,operator2:i}=e;if(t)return!1;let a=[r,i];return a.includes(n.CustomFilterOperator.GREATER_THAN)&&a.includes(n.CustomFilterOperator.LESS_THAN)},mapToFilterColumn:e=>{let{val1:t,val2:r,operator1:i}=e,a=i===n.CustomFilterOperator.GREATER_THAN;return{customFilters:{customFilters:[{val:a?t:r,operator:n.CustomFilterOperator.GREATER_THAN},{val:a?r:t,operator:n.CustomFilterOperator.LESS_THAN}]}}},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==2)return!1;let[r,i]=e.customFilters.customFilters;return r.operator===n.CustomFilterOperator.LESS_THAN&&i.operator===n.CustomFilterOperator.GREATER_THAN&&!e.customFilters.and?{operator1:n.CustomFilterOperator.LESS_THAN,val1:r.val.toString(),operator2:n.CustomFilterOperator.GREATER_THAN,val2:i.val.toString()}:i.operator===n.CustomFilterOperator.LESS_THAN&&r.operator===n.CustomFilterOperator.GREATER_THAN&&!e.customFilters.and?{operator1:n.CustomFilterOperator.GREATER_THAN,val1:i.val.toString(),operator2:n.CustomFilterOperator.LESS_THAN,val2:r.val.toLocaleString()}:!1}},e.CUSTOM={label:`sheets-filter.conditions.custom`,operator:p.CUSTOM,order:f.SECOND,numOfParameters:2,getDefaultFormParams:()=>({operator1:p.NONE,val1:``,operator2:p.NONE,val2:``}),testMappingParams:()=>!0,mapToFilterColumn:e=>{let{and:n,val1:a,val2:o,operator1:s,operator2:c}=e;function l(e,t){for(let n of i)if(n.operator===e)return n.mapToFilterColumn({val1:t,operator1:e})}let u=!s||s===m.NONE.operator,d=!c||c===m.NONE.operator;if(u&&d)return r.mapToFilterColumn({});if(u)return l(c,o);if(d)return l(s,a);let f=l(s,a),p=l(c,o),h={customFilters:[f.customFilters.customFilters[0],p.customFilters.customFilters[0]]};return n&&(h.and=t.BooleanNumber.TRUE),{customFilters:h}},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==2)return!1;let n=e.customFilters.customFilters.map(e=>l({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 a(e){let t=i.find(t=>t.operator===e);if(!t)throw Error(`[SheetsFilter]: no condition item found for operator: ${e}`);return t}e.getItemByOperator=a;function o(e,t){for(let n of i.filter(e=>e.numOfParameters===t))if(n.numOfParameters!==0&&n.testMappingParams(e))return n;for(let t of i)if(t.testMappingParams(e))return t;throw Error(`[SheetsFilter]: no condition item can be mapped from the filter map params!`)}e.testMappingParams=o;function s(e){let t=i.find(t=>t.operator===e);return(t==null?void 0:t.numOfParameters)===0?{operator1:t.operator}:t.getDefaultFormParams()}e.getInitialFormParams=s;function c(e,t){return e.mapToFilterColumn(t)}e.mapToFilterColumn=c;function l(e){if(!e)return[r,{}];for(let t of i){let n=t.testMappingFilterColumn(e);if(n)return[t,n]}return[r,{}]}e.testMappingFilterColumn=l})(m||(m={}));function h(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 g(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 _(e,t){return function(n,r){t(n,r,e)}}function v(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let y=`sheets-filter.generate-filter-values.service`,b=(0,t.createIdentifier)(y),x=class extends t.Disposable{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}),S(o,this._localeService,c,d,new Set(i),a,new Set(l.map(String)),s,u.getStyles()))}};x=v([_(0,(0,t.Inject)(t.LocaleService)),_(1,t.IUniverInstanceService),_(2,t.ILogService)],x);function S(e,r,i,a,o,s,c,l,u){var d;let f=new Map,p=new Map,m=`empty`,h=!e&&((s==null?void 0:s.filterBy)===n.FilterBy.COLORS||(s==null?void 0:s.filterBy)===n.FilterBy.CONDITIONS)&&((d=s.filteredOutRows)==null?void 0:d.size),g=0;for(let e of a.iterateByColumn(i,!1,!1)){let{row:n,rowSpan:i=1}=e,s=0;for(;s<i;){var _,v,y;let d=n+s;if(o.has(d)){s++;continue}let m=e!=null&&e.value?(0,t.extractPureTextFromCell)(e.value):``;if(!m){g+=1,s+=i;continue}let C=(_=e.value)!=null&&_.v&&!e.value.p?(v=u.get((y=e.value)==null?void 0:y.s))==null||(v=v.n)==null?void 0:v.pattern:``,E=C&&t.numfmt.getFormatInfo(C).isDate,D=!1;if(E){let{year:e,month:n,day:r}=t.numfmt.getFormatDateInfo(C);D=e||n||r}if(C&&E&&D){var b,x,S;let n=(b=a.getCellRaw(e.row,e.col))==null?void 0:b.v;if(!n){s++;continue}let[i,o,u]=t.numfmt.format(`yyyy-mm-dd`,Number(n)).split(`-`).map(Number),d=f.get(`${i}`);d||(d={title:`${i}`,key:`${i}`,children:[],count:0,leaf:!1,checked:!1},f.set(`${i}`,d),p.set(`${i}`,[`${i}`]));let g=(x=d.children)==null?void 0:x.find(e=>e.key===`${i}-${o}`);if(!g){var w;g={title:r.t(`sheets-filter.date.${o}`),key:`${i}-${o}`,children:[],count:0,leaf:!1,checked:!1},(w=d.children)==null||w.push(g),p.set(`${i}-${o}`,[`${i}`,`${i}-${o}`])}let _=g==null||(S=g.children)==null?void 0:S.find(e=>e.key===`${i}-${o}-${u}`);if(_)_.originValues.add(m),_.count++,g.count++,d.count++;else{var T;(T=g.children)==null||T.push({title:`${u}`,key:`${i}-${o}-${u}`,count:1,originValues:new Set([m]),leaf:!0,checked:h?!1:c.size?c.has(m):!l}),g.count++,d.count++,p.set(`${i}-${o}-${u}`,[`${i}`,`${i}-${o}`,`${i}-${o}-${u}`])}}else{let e=m,t=f.get(e);t?t.count++:(t={title:m,leaf:!0,checked:h?!1:c.size?c.has(m):!l,key:e,count:1},f.set(e,t),p.set(e,[e]))}s++}}let E=h?!1:e?l:!0;if(g>0){let e={title:r.t(`sheets-filter.panel.empty`),count:g,leaf:!0,checked:E,key:m};f.set(`empty`,e),p.set(`empty`,[m])}return{filterTreeItems:C(Array.from(f.values())),filterTreeMapCache:p}}function C(e){return Array.from(e).sort((e,t)=>e.children&&!t.children?-1:!e.children&&t.children?1:T(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))}let w=e=>!Number.isNaN(Number(e))&&!Number.isNaN(Number.parseFloat(e));function T(e,t){let n=w(e),r=w(t);return n&&r?Number.parseFloat(e)-Number.parseFloat(t):n&&!r?-1:!n&&r?1:e.localeCompare(t)}function E(e,t){for(let n of e){if(n.key===t)return n;if(n.children){let e=E(n.children,t);if(e)return e}}return null}function D(e){return e.leaf?e.checked:e.children?e.children.every(e=>D(e)):!0}function O(e,t){e.leaf&&(t===void 0?e.checked=!e.checked:e.checked=t),e.children&&e.children.forEach(e=>O(e,t))}function ee(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=ee(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 k(e){"@babel/helpers - typeof";return k=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},k(e)}function te(e,t){if(k(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(k(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function ne(e){var t=te(e,`string`);return k(t)==`symbol`?t:t+``}function A(e,t,n){return(t=ne(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var j,M,N;(0,t.createIdentifier)(`sheets-filter-ui.sheets-filter-panel.service`);let P=class extends t.Disposable{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,A(this,`_filterBy$`,new s.BehaviorSubject(n.FilterBy.VALUES)),A(this,`filterBy$`,this._filterBy$.asObservable()),A(this,`_filterByModel$`,new s.ReplaySubject(1)),A(this,`filterByModel$`,this._filterByModel$.asObservable()),A(this,`_filterByModel`,null),A(this,`_hasCriteria$`,new s.BehaviorSubject(!1)),A(this,`hasCriteria$`,this._hasCriteria$.asObservable()),A(this,`_filterModel`,null),A(this,`_col$`,new s.BehaviorSubject(-1)),A(this,`col$`,this._col$.asObservable()),A(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 n.FilterBy.VALUES:this._setupByValues(this._filterModel,this.col);break;case n.FilterBy.COLORS:this._setupByColors(this._filterModel,this.col);break;case n.FilterBy.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 r=e.getRange();return r.startRow===r.endRow?!1:(this.filterByModel=await I.fromFilterColumn(this._injector,e,t),this._filterBy$.next(n.FilterBy.VALUES),this._listenToFilterHeaderChange(e,t),!0)}async _setupByColors(e,t){this._disposePreviousModel();let r=e.getRange();return r.startRow===r.endRow?!1:(this.filterByModel=await re.fromFilterColumn(this._injector,e,t),this._filterBy$.next(n.FilterBy.COLORS),this._listenToFilterHeaderChange(e,t),!0)}_setupByConditions(e,t){this._disposePreviousModel();let r=e.getRange();return r.startRow===r.endRow?!1:(this.filterByModel=F.fromFilterColumn(this._injector,e,t,e.getFilterColumn(t)),this._filterBy$.next(n.FilterBy.CONDITIONS),this._listenToFilterHeaderChange(e,t),!0)}_disposePreviousModel(){var e;(e=this._filterByModel)==null||e.dispose(),this.filterByModel=null}};P=v([_(0,(0,t.Inject)(t.Injector)),_(1,(0,t.Inject)(o.RefRangeService))],P);let F=j=class extends t.Disposable{static fromFilterColumn(e,t,n,r){let[i,a]=m.testMappingFilterColumn(r==null?void 0:r.getColumnData());return e.createInstance(j,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,A(this,`canApply$`,(0,s.of)(!0)),A(this,`_conditionItem$`,void 0),A(this,`conditionItem$`,void 0),A(this,`_filterConditionFormParams$`,void 0),A(this,`filterConditionFormParams$`,void 0),this._conditionItem$=new s.BehaviorSubject(n),this.conditionItem$=this._conditionItem$.asObservable(),this._filterConditionFormParams$=new s.BehaviorSubject(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(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}async apply(){if(this._disposed)return!1;let e=m.mapToFilterColumn(this.conditionItem,this.filterConditionFormParams);return this._commandService.executeCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:e})}onPrimaryConditionChange(e){let t=m.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(m.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=m.testMappingParams(t,this.conditionItem.numOfParameters);this._conditionItem$.next(e)}this._filterConditionFormParams$.next(t)}};F=j=v([_(4,t.ICommandService)],F);let I=M=class extends t.Disposable{static async fromFilterColumn(e,n,r){let i=e.get(t.IUniverInstanceService),a=e.get(t.LocaleService),o=e.get(b,t.Quantity.OPTIONAL),{unitId:s,subUnitId:c}=n,l=i.getUniverSheetInstance(s);if(!l)throw Error(`[ByValuesModel]: Workbook not found for filter model with unitId: ${s}!`);let u=l==null?void 0:l.getSheetBySheetId(c);if(!u)throw Error(`[ByValuesModel]: Worksheet not found for filter model with unitId: ${s} and subUnitId: ${c}!`);let d=n.getRange(),f=r,p=n.getFilterColumn(r),m=p==null?void 0:p.getColumnData().filters,h=new Set(m==null?void 0:m.filters),g=!!(m&&m.blank),_=n.getFilteredOutRowsExceptCol(r),v={...d,startRow:d.startRow+1,startColumn:f,endColumn:f},y,x;if(o){let e=await o.getFilterValues({unitId:s,subUnitId:c,filteredOutRowsByOtherColumns:Array.from(_),filterColumn:p,filters:!!m,blankChecked:g,iterateRange:v,alreadyChecked:Array.from(h)});y=e.filterTreeItems,x=e.filterTreeMapCache}else{let e=S(!!m,a,v,u,_,p,h,g,l.getStyles());y=e.filterTreeItems,x=e.filterTreeMapCache}return e.createInstance(M,n,r,y,x)}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,A(this,`_rawFilterItems$`,void 0),A(this,`rawFilterItems$`,void 0),A(this,`filterItems$`,void 0),A(this,`_filterItems`,[]),A(this,`_treeMapCache`,void 0),A(this,`canApply$`,void 0),A(this,`_manuallyUpdateFilterItems$`,void 0),A(this,`_searchString$`,void 0),A(this,`searchString$`,void 0),this._treeMapCache=r,this._searchString$=new s.BehaviorSubject(``),this.searchString$=this._searchString$.asObservable(),this._rawFilterItems$=new s.BehaviorSubject(n),this.rawFilterItems$=this._rawFilterItems$.asObservable(),this._manuallyUpdateFilterItems$=new s.Subject,this.filterItems$=(0,s.merge)((0,s.combineLatest)([this._searchString$.pipe((0,s.throttleTime)(500,void 0,{leading:!0,trailing:!0}),(0,s.startWith)(void 0)),this._rawFilterItems$]).pipe((0,s.map)(([e,t])=>e?ee(t,e.toLowerCase().split(/\s+/).filter(e=>!!e)):t)),this._manuallyUpdateFilterItems$).pipe((0,s.shareReplay)(1)),this.canApply$=this.filterItems$.pipe((0,s.map)(e=>g(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 n=t.Tools.deepClone(this._filterItems);n.forEach(t=>O(t,e)),this._manuallyUpdateFilterItems(n)}onFilterCheckToggled(e){let n=t.Tools.deepClone(this._filterItems),r=E(n,e.key);r&&(O(r,!D(r)),this._manuallyUpdateFilterItems(n))}onFilterOnly(e){let n=t.Tools.deepClone(this._filterItems);n.forEach(e=>O(e,!1)),e.forEach(e=>{let t=E(n,e);t&&O(t,!0)}),this._manuallyUpdateFilterItems(n)}_manuallyUpdateFilterItems(e){this._manuallyUpdateFilterItems$.next(e)}clear(){return this._disposed?Promise.resolve(!1):this._commandService.executeCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}async apply(){if(this._disposed)return!1;let e=g(this._filterItems),{checked:t,checkedItems:r}=e,i=this.rawFilterItems,a=0;for(let e of i)a+=e.count;let o=t===0,s=e.checked===a,c={colId:this.col};if(o)throw Error(`[ByValuesModel]: no checked items!`);if(s)return this._commandService.executeCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null});{c.filters={};let e=r.filter(e=>e.key!==`empty`);e.length>0&&(c.filters={filters:e.flatMap(e=>e.originValues?Array.from(e.originValues):[e.title])}),e.length!==r.length&&(c.filters.blank=!0)}return this._commandService.executeCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:c})}};I=M=v([_(4,t.ICommandService)],I);let re=N=class extends t.Disposable{static async fromFilterColumn(e,n,r){var i,o,s;let c=e.get(t.IUniverInstanceService),{unitId:l,subUnitId:u}=n,d=c.getUniverSheetInstance(l);if(!d)throw Error(`[ByColorsModel]: Workbook not found for filter model with unitId: ${l}!`);let f=d==null?void 0:d.getSheetBySheetId(u);if(!f)throw Error(`[ByColorsModel]: Worksheet not found for filter model with unitId: ${l} 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((o=h==null?void 0:h.cellFillColors)==null?[]:o),b=new Map,x=new Set((s=h==null?void 0:h.cellTextColors)==null?[]:s);for(let e of f.iterateByColumn(_,!1,!0)){let{row:n,col:r,value:i}=e;if(g.has(n))continue;let o=f.getComposedCellStyleByCellData(n,r,i);if(o.bg&&o.bg.rgb){let e=new t.ColorKit(o.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(o.cl&&o.cl.rgb){let e=new t.ColorKit(o.cl.rgb).toRgbString();b.has(e)||b.set(e,{color:e,checked:x.has(e)})}else b.set(`default-font-color`,{color:a.COLOR_BLACK_RGB,checked:x.has(a.COLOR_BLACK_RGB)})}return e.createInstance(N,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,A(this,`canApply$`,(0,s.of)(!0)),A(this,`_cellFillColors$`,void 0),A(this,`cellFillColors$`,void 0),A(this,`_cellTextColors$`,void 0),A(this,`cellTextColors$`,void 0),this._cellFillColors$=new s.BehaviorSubject(Array.from(n.values())),this.cellFillColors$=this._cellFillColors$.asObservable(),this._cellTextColors$=new s.BehaviorSubject(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(n.SetSheetsFilterCriteriaCommand.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(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null});let r={colId:this.col};return e.length>0?r.colorFilters={cellFillColors:e}:t.length>0&&(r.colorFilters={cellTextColors:t}),this._commandService.executeCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:r})}};re=N=v([_(4,t.ICommandService)],re);let L=`FILTER_PANEL_OPENED`,R={id:`sheet.operation.open-filter-panel`,type:t.CommandType.OPERATION,handler:(e,i)=>{let a=e.get(t.IContextService),o=e.get(n.SheetsFilterService),s=e.get(P),c=e.get(t.ICommandService),l=e.has(r.IEditorBridgeService)?e.get(r.IEditorBridgeService):null;l!=null&&l.isVisible().visible&&c.syncExecuteCommand(r.SetCellEditVisibleOperation.id,{visible:!1});let{unitId:u,subUnitId:d,col:f}=i,p=o.getFilterModel(u,d);return p?(s.setupCol(p,f),a.getContextValue(`FILTER_PANEL_OPENED`)||a.setContextValue(L,!0),!0):!1}},z={id:`sheet.operation.close-filter-panel`,type:t.CommandType.OPERATION,handler:e=>{let n=e.get(t.IContextService),r=e.get(P),a=e.get(i.ILayoutService,t.Quantity.OPTIONAL);return n.getContextValue(`FILTER_PANEL_OPENED`)?(n.setContextValue(L,!1),a==null||a.focus(),r.terminate()):!1}},B={id:`sheet.operation.apply-filter`,type:t.CommandType.OPERATION,handler:(e,t)=>{let{filterBy:n}=t;return e.get(P).changeFilterBy(n)}};var V=`@univerjs/sheets-filter-ui`,H=`0.19.0`;let U=`sheets-filter-ui.config`;Symbol(U);let W={},G=class extends t.Disposable{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===n.SmartToggleSheetsFilterCommand.id){var r;let e=(0,o.getSheetCommandTarget)(this._injector.get(t.IUniverInstanceService));if(!e)return;let{unitId:n,subUnitId:a,worksheet:s}=e,c=(r=this._sheetsFilterService.getFilterModel(n,a))==null?void 0:r.getRange(),l;if(c)l=this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[o.RangeProtectionPermissionViewPoint],worksheetTypes:[o.WorksheetFilterPermission,o.WorksheetViewPermission]},[c],n,a);else{var i;let e=(i=this._sheetsSelectionService.getCurrentLastSelection())==null?void 0:i.range;if(e){let t={...e};t=e.startColumn===e.endColumn&&e.startRow===e.endRow?(0,o.expandToContinuousRange)(t,{left:!0,right:!0,up:!0,down:!0},s):t,l=this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[o.RangeProtectionPermissionViewPoint],worksheetTypes:[o.WorksheetViewPermission,o.WorksheetFilterPermission]},[t],n,a)}else l=this._sheetPermissionCheckPermission.permissionCheckWithoutRange({rangeTypes:[o.RangeProtectionPermissionViewPoint],worksheetTypes:[o.WorksheetViewPermission,o.WorksheetFilterPermission]})}l||this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.filterErr`))}if(e.id===R.id){var a;let n=e.params,{unitId:r,subUnitId:i}=n,s=(a=this._sheetsFilterService.getFilterModel(r,i))==null?void 0:a.getRange(),c=t.Tools.deepClone(s);c&&(c.startColumn=n.col,c.endColumn=n.col,this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[o.RangeProtectionPermissionViewPoint],worksheetTypes:[o.WorksheetFilterPermission,o.WorksheetViewPermission]},[c],r,i)||this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.filterErr`)))}}))}};G=v([_(0,(0,t.Inject)(n.SheetsFilterService)),_(1,(0,t.Inject)(t.LocaleService)),_(2,t.ICommandService),_(3,(0,t.Inject)(o.SheetPermissionCheckController)),_(4,(0,t.Inject)(t.Injector)),_(5,(0,t.Inject)(o.SheetsSelectionsService))],G);let ie=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 ae=class{static drawNoCriteria(e,t,n,r){e.save(),a.Rect.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(),a.Rect.drawWith(e,{radius:2,width:16,height:16,fill:r}),e.scale(t/16,t/16),e.fillStyle=n,e.fill(ie),e.restore()}};let K=class extends a.Shape{constructor(e,t,n,r,i){super(e,t),this._contextService=n,this._commandService=r,this._themeService=i,A(this,`_cellWidth`,0),A(this,`_cellHeight`,0),A(this,`_filterParams`,void 0),A(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?ae.drawHasCriteria(e,16,s,c):ae.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(R.id)||setTimeout(()=>{this._commandService.executeCommand(R.id,{unitId:n,subUnitId:r,col:t})},200)}onPointerEnter(){this._hovered=!0,this.makeDirty(!0)}onPointerLeave(){this._hovered=!1,this.makeDirty(!0)}};K=v([_(2,t.IContextService),_(3,t.ICommandService),_(4,(0,t.Inject)(t.ThemeService))],K);function oe(e,n,r,i){switch(i){case t.VerticalAlign.TOP:return e+1;case t.VerticalAlign.MIDDLE:return e+Math.max(0,(r-16)/2);case t.VerticalAlign.BOTTOM:default:return n-16-1}}let q=class extends t.RxDisposable{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,A(this,`_currentRenderParams`,null),A(this,`_filterRangeShape`,null),A(this,`_buttonRenderDisposable`,null),A(this,`_filterButtonShapes`,[]),this._initRenderer()}dispose(){super.dispose(),this._disposeRendering()}_initRenderer(){this.disposeWithMe(this._themeService.currentTheme$.subscribe(()=>{this._refreshRendering(this._currentRenderParams)})),this._sheetSkeletonManagerService.currentSkeleton$.pipe((0,s.switchMap)(e=>{var r,i;if(!e)return(0,s.of)(null);let{unit:a,unitId:c}=this._context,l=((r=a.getActiveSheet())==null?void 0:r.getSheetId())||``,u=(i=this._sheetsFilterService.getFilterModel(c,l))==null?void 0:i,d=()=>({unitId:c,worksheetId:l,filterModel:u,range:u==null?void 0:u.getRange(),skeleton:e.skeleton});return(0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,s.filter)(([e])=>{var r;return e.type===t.CommandType.MUTATION&&((r=e.params)==null?void 0:r.unitId)===a.getUnitId()&&(n.FILTER_MUTATIONS.has(e.id)||e.id===o.SetRangeValuesMutation.id)}),(0,s.throttleTime)(20,void 0,{leading:!1,trailing:!0}),(0,s.map)(d),(0,s.startWith)(d()))}),(0,s.takeUntil)(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:i,columnHeaderHeight:a}=t,o=this._filterRangeShape=new r.SelectionControl(n,1e3,this._themeService,{rowHeaderWidth:i,columnHeaderHeight:a,enableAutoFill:!1,highlightHeader:!1}),s=(0,r.attachSelectionWithCoord)({range:e,primary:null,style:{fill:`rgba(0, 0, 0, 0.0)`}},t);o.updateRangeBySelectionWithCoord(s),o.setEvent(!1),n.makeDirty(!0)}_renderButtons(e){let{range:n,filterModel:i,unitId:a,skeleton:o,worksheetId:s}=e,{unit:c,scene:l}=this._context,u=c.getSheetBySheetId(s);if(!u)return;this._interceptCellContent(a,s,e.range);let{startColumn:d,endColumn:f,startRow:p}=n;for(let e=d;e<=f;e++){let n=`sheets-filter-button-${e}`,c=(0,r.getCoordByCell)(p,e,l,o),d=u.getComposedCellStyle(p,e),f=(d==null?void 0:d.vt)||t.VerticalAlign.BOTTOM,{startX:m,startY:h,endX:g,endY:_}=c,v=g-m,y=_-h;if(y<=1||v<=1)continue;let b=!!i.getFilterColumn(e),x={left:g-16-1,top:oe(h,_,y,f),height:16,width:16,zIndex:5e3,cellHeight:y,cellWidth:v,filterParams:{unitId:a,subUnitId:s,col:e,hasCriteria:b}},S=this._injector.createInstance(K,n,x);this._filterButtonShapes.push(S)}l.addObjects(this._filterButtonShapes),l.makeDirty()}_interceptCellContent(e,n,r){let{startRow:i,startColumn:a,endColumn:s}=r;this._buttonRenderDisposable=this._sheetInterceptorService.intercept(o.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,handler:(t,r,o)=>{let{row:c,col:l,unitId:u,subUnitId:d}=r;return u!==e||d!==n||c!==i||l<a||l>s?o(t):((!t||t===r.rawData)&&(t={...r.rawData}),t.fontRenderExtension={...t==null?void 0:t.fontRenderExtension,rightOffset:16},o(t))},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=[]}};q=v([_(1,(0,t.Inject)(t.Injector)),_(2,(0,t.Inject)(r.SheetSkeletonManagerService)),_(3,(0,t.Inject)(n.SheetsFilterService)),_(4,(0,t.Inject)(t.ThemeService)),_(5,(0,t.Inject)(o.SheetInterceptorService)),_(6,t.ICommandService),_(7,r.ISheetSelectionRenderService)],q);let J=class extends t.RxDisposable{constructor(e,r){super(),this._renderManagerService=e,this._sheetsRenderService=r,[n.SetSheetsFilterRangeMutation,n.SetSheetsFilterCriteriaMutation,n.RemoveSheetsFilterMutation,n.ReCalcSheetsFilterMutation].forEach(e=>this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(e.id))),this.disposeWithMe(this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,[q]))}};J=v([_(0,a.IRenderManagerService),_(1,(0,t.Inject)(r.SheetsRenderService))],J);let Y=class extends t.Plugin{constructor(e=W,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},W,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(U,a)}onStarting(){[[G],[J]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(G)}onRendered(){this._injector.get(J)}};A(Y,`type`,t.UniverInstanceType.UNIVER_SHEET),A(Y,`pluginName`,`SHEET_FILTER_UI_PLUGIN`),A(Y,`packageName`,V),A(Y,`version`,H),Y=v([(0,t.DependentOn)(n.UniverSheetsFilterPlugin),_(1,(0,t.Inject)(t.Injector)),_(2,t.IConfigService)],Y);function X({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),c=(0,u.useRef)(`_${ue()}`);return se(n,`${r}`,{defIds:n.defIds,idSuffix:c.current},{ref:e,className:s,...o},a)}function se(e,t,n,r,i){return(0,u.createElement)(e.tag,{key:t,...ce(e,n,i),...r},(le(e,n).children||[]).map((r,a)=>se(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function ce(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function le(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function ue(){return Math.random().toString(36).substring(2,8)}X.displayName=`UniverIcon`;let de={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 20 20`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M10 1.05957C10.356 1.05957 10.6816 1.26162 10.8408 1.58008L18.8408 17.5801L18.8799 17.668C19.0486 18.1134 18.8551 18.6232 18.4199 18.8408C17.9557 19.0727 17.3913 18.8841 17.1592 18.4199L10 4.10156L2.84082 18.4199C2.60871 18.8841 2.04434 19.0727 1.58008 18.8408C1.11587 18.6087 0.92731 18.0443 1.15918 17.5801L9.15918 1.58008C9.31841 1.26162 9.64395 1.05957 10 1.05957Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M15.3337 11.7261L15.4294 11.731C15.9035 11.779 16.2732 12.1798 16.2732 12.6665C16.2732 13.1532 15.9035 13.554 15.4294 13.602L15.3337 13.6069H4.66675C4.1476 13.6069 3.72632 13.1856 3.72632 12.6665C3.72632 12.1474 4.1476 11.7261 4.66675 11.7261H15.3337Z`}}]},fe=(0,u.forwardRef)(function(e,t){return(0,u.createElement)(X,Object.assign({},e,{id:`a-icon`,ref:t,icon:de}))});fe.displayName=`AIcon`;let pe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 20 20`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M17.0596 10C17.0596 6.10087 13.8992 2.94043 10 2.94043C6.10087 2.94043 2.94043 6.10087 2.94043 10C2.94043 13.8992 6.10087 17.0596 10 17.0596C13.8992 17.0596 17.0596 13.8992 17.0596 10ZM18.9404 10C18.9404 14.9374 14.9374 18.9404 10 18.9404C5.06257 18.9404 1.05957 14.9374 1.05957 10C1.05957 5.06257 5.06257 1.05957 10 1.05957C14.9374 1.05957 18.9404 5.06257 18.9404 10Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.29492 4.13476C4.63911 3.79057 5.1845 3.76906 5.55371 4.07031L5.625 4.13476L16.0244 14.5352L16.0889 14.6064C16.3902 14.9757 16.3686 15.52 16.0244 15.8643C15.6573 16.2313 15.0624 16.2313 14.6953 15.8643L4.29492 5.46484L4.23047 5.39355C3.92922 5.02434 3.95073 4.47895 4.29492 4.13476Z`}}]},me=(0,u.forwardRef)(function(e,t){return(0,u.createElement)(X,Object.assign({},e,{id:`ban-icon`,ref:t,icon:pe}))});me.displayName=`BanIcon`;let he={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M3.32182 2.60967C2.98161 2.60967 2.79671 3.0074 3.01601 3.2675L6.85819 7.8246C6.94943 7.93282 6.99947 8.06981 6.99947 8.21136V12.7338C6.99947 12.898 7.0998 13.0455 7.2525 13.1058L8.73833 13.6928C9.00085 13.7965 9.28531 13.6031 9.28531 13.3208V8.21136C9.28531 8.06981 9.33535 7.93282 9.42659 7.8246L13.2688 3.2675C13.4881 3.0074 13.3032 2.60967 12.963 2.60967H3.32182ZM2.09858 4.04101C1.22139 3.0006 1.96097 1.40967 3.32182 1.40967H12.963C14.3238 1.40967 15.0634 3.0006 14.1862 4.04101L10.4853 8.43054V13.3208C10.4853 14.4498 9.34747 15.2237 8.29742 14.8089L6.81158 14.2219C6.20078 13.9806 5.79947 13.3905 5.79947 12.7338V8.43054L2.09858 4.04101Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},ge=(0,u.forwardRef)(function(e,t){return(0,u.createElement)(X,Object.assign({},e,{id:`filter-icon`,ref:t,icon:he}))});ge.displayName=`FilterIcon`;let _e={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M8.00016 1.33203C6.68162 1.33203 5.39269 1.72302 4.29636 2.45557C3.20004 3.18811 2.34555 4.2293 1.84097 5.44747C1.33638 6.66565 1.20436 8.00609 1.4616 9.2993C1.71883 10.5925 2.35377 11.7804 3.28612 12.7127C4.21847 13.6451 5.40636 14.28 6.69956 14.5373C7.99277 14.7945 9.33321 14.6625 10.5514 14.1579C11.7696 13.6533 12.8108 12.7988 13.5433 11.7025C14.2758 10.6062 14.6668 9.31724 14.6668 7.9987C14.6649 6.23118 13.9619 4.53662 12.7121 3.2868C11.4622 2.03697 9.76768 1.33397 8.00016 1.33203ZM7.66683 3.9987C7.86461 3.9987 8.05795 4.05735 8.2224 4.16723C8.38685 4.27711 8.51502 4.43329 8.59071 4.61601C8.6664 4.79874 8.6862 4.99981 8.64762 5.19379C8.60903 5.38777 8.51379 5.56595 8.37394 5.7058C8.23409 5.84566 8.0559 5.9409 7.86192 5.97948C7.66794 6.01807 7.46687 5.99826 7.28415 5.92258C7.10142 5.84689 6.94524 5.71872 6.83536 5.55427C6.72548 5.38982 6.66683 5.19648 6.66683 4.9987C6.66683 4.73348 6.77219 4.47913 6.95972 4.29159C7.14726 4.10405 7.40162 3.9987 7.66683 3.9987ZM9.3335 11.332H6.66683C6.49002 11.332 6.32045 11.2618 6.19543 11.1368C6.0704 11.0117 6.00016 10.8422 6.00016 10.6654C6.00016 10.4886 6.0704 10.319 6.19543 10.194C6.32045 10.0689 6.49002 9.9987 6.66683 9.9987H7.3335V7.9987H6.66683C6.49002 7.9987 6.32045 7.92846 6.19543 7.80343C6.0704 7.67841 6.00016 7.50884 6.00016 7.33203C6.00016 7.15522 6.0704 6.98565 6.19543 6.86063C6.32045 6.7356 6.49002 6.66536 6.66683 6.66536H8.00016C8.17698 6.66536 8.34655 6.7356 8.47157 6.86063C8.59659 6.98565 8.66683 7.15522 8.66683 7.33203V9.9987H9.3335C9.51031 9.9987 9.67988 10.0689 9.8049 10.194C9.92993 10.319 10.0002 10.4886 10.0002 10.6654C10.0002 10.8422 9.92993 11.0117 9.8049 11.1368C9.67988 11.2618 9.51031 11.332 9.3335 11.332Z`}}]},ve=(0,u.forwardRef)(function(e,t){return(0,u.createElement)(X,Object.assign({},e,{id:`info-icon`,ref:t,icon:_e}))});ve.displayName=`InfoIcon`;let ye={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M8 15C11.866 15 15 11.866 15 8C15 4.13401 11.866 1 8 1C4.13401 1 1 4.13401 1 8C1 11.866 4.13401 15 8 15ZM11.7245 6.42417C11.9588 6.18985 11.9588 5.80995 11.7245 5.57564C11.4901 5.34132 11.1102 5.34132 10.8759 5.57564L7.3002 9.15137L5.72446 7.57564C5.49014 7.34132 5.11025 7.34132 4.87593 7.57564C4.64162 7.80995 4.64162 8.18985 4.87593 8.42417L6.87593 10.4242C7.11025 10.6585 7.49014 10.6585 7.72446 10.4242L11.7245 6.42417Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},be=(0,u.forwardRef)(function(e,t){return(0,u.createElement)(X,Object.assign({},e,{id:`success-icon`,ref:t,icon:ye}))});be.displayName=`SuccessIcon`;function xe(e){let a=e.get(n.SheetsFilterService);return{id:n.SmartToggleSheetsFilterCommand.id,type:i.MenuItemType.BUTTON_SELECTOR,icon:`FilterIcon`,tooltip:`sheets-filter.toolbar.smart-toggle-filter-tooltip`,hidden$:(0,i.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),activated$:a.activeFilterModel$.pipe((0,s.map)(e=>!!e)),disabled$:(0,r.getObservableWithExclusiveRange$)(e,(0,r.getCurrentRangeDisable$)(e,{worksheetTypes:[o.WorksheetFilterPermission,o.WorksheetViewPermission],rangeTypes:[o.RangeProtectionPermissionViewPoint]}))}}function Se(e){let r=e.get(n.SheetsFilterService);return{id:n.ClearSheetsFilterCriteriaCommand.id,type:i.MenuItemType.BUTTON,title:`sheets-filter.toolbar.clear-filter-criteria`,hidden$:(0,i.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:r.activeFilterModel$.pipe((0,s.switchMap)(e=>{var t;return(t=e==null?void 0:e.hasCriteria$.pipe((0,s.map)(e=>!e)))==null?(0,s.of)(!0):t}))}}function Ce(e){let r=e.get(n.SheetsFilterService);return{id:n.ReCalcSheetsFilterCommand.id,type:i.MenuItemType.BUTTON,title:`sheets-filter.toolbar.re-calc-filter-conditions`,hidden$:(0,i.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:r.activeFilterModel$.pipe((0,s.switchMap)(e=>{var t;return(t=e==null?void 0:e.hasCriteria$.pipe((0,s.map)(e=>!e)))==null?(0,s.of)(!0):t}))}}let we={[i.RibbonDataGroup.ORGANIZATION]:{[n.SmartToggleSheetsFilterCommand.id]:{order:2,menuItemFactory:xe,[n.ClearSheetsFilterCriteriaCommand.id]:{order:0,menuItemFactory:Se},[n.ReCalcSheetsFilterCommand.id]:{order:1,menuItemFactory:Ce}}}};function Te(e){let{model:n}=e,r=(0,i.useDependency)(t.LocaleService),a=(0,i.useObservable)(n.cellFillColors$,[],!0),o=(0,i.useObservable)(n.cellTextColors$,[],!0),s=(0,u.useCallback)(e=>{n.onFilterCheckToggled(e)},[n]),c=(0,u.useCallback)(e=>{n.onFilterCheckToggled(e,!1)},[n]);return(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-colors-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel`,className:(0,l.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`,l.borderClassName),children:[a.length>1&&(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white`,children:r.t(`sheets-filter.panel.filter-by-cell-fill-color`)}),(0,d.jsx)(`div`,{className:`univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2`,children:a.map((e,t)=>(0,d.jsxs)(`div`,{className:`univer-relative univer-size-6`,onClick:()=>s(e),children:[e.color?(0,d.jsx)(`button`,{type:`button`,className:(0,l.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`),style:{backgroundColor:e.color}}):(0,d.jsx)(me,{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&&(0,d.jsx)(Ee,{})]},`sheets-filter-cell-fill-color-${t}`))})]}),o.length>1&&(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white`,children:r.t(`sheets-filter.panel.filter-by-cell-text-color`)}),(0,d.jsx)(`div`,{className:`univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2`,children:o.map((e,t)=>(0,d.jsxs)(`div`,{className:`univer-relative univer-size-6`,onClick:()=>c(e),children:[(0,d.jsx)(`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:(0,d.jsx)(fe,{style:{color:e.color}})}),e.checked&&(0,d.jsx)(Ee,{})]},`sheets-filter-cell-text-color-${t}`))})]}),a.length<=1&&o.length<=1&&(0,d.jsx)(`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:r.t(`sheets-filter.panel.filter-by-color-none`)})]})})}function Ee(){return(0,d.jsx)(`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:(0,d.jsx)(be,{className:`univer-size-full univer-font-bold univer-text-[#418F1F]`})})}function De(e){var n,r;let{model:a}=e,o=(0,i.useDependency)(t.LocaleService),s=(0,i.useObservable)(a.conditionItem$,void 0),c=(0,i.useObservable)(a.filterConditionFormParams$,void 0),f=c!=null&&c.and?`AND`:`OR`,p=(0,u.useCallback)(e=>{a.onConditionFormChange({and:e===`AND`})},[a]),h=Oe(o),g=(0,u.useCallback)(e=>{a.onPrimaryConditionChange(e)},[a]),_=ke(o),v=(0,u.useCallback)(e=>{a.onConditionFormChange(e)},[a]),y=o.t(`sheets-filter.panel.input-values-placeholder`);function b(e,t,n){let r=m.getItemByOperator(e).numOfParameters===1;return(0,d.jsxs)(d.Fragment,{children:[n===`operator2`&&(0,d.jsxs)(l.RadioGroup,{value:f,onChange:p,children:[(0,d.jsx)(l.Radio,{value:`AND`,children:o.t(`sheets-filter.panel.and`)}),(0,d.jsx)(l.Radio,{value:`OR`,children:o.t(`sheets-filter.panel.or`)})]}),(0,d.jsx)(l.Select,{value:e,options:_,onChange:e=>v({[n]:e})}),r&&(0,d.jsx)(`div`,{children:(0,d.jsx)(l.Input,{className:`univer-mt-2`,value:t,placeholder:y,onChange:e=>v({[n===`operator1`?`val1`:`val2`]:e})})})]})}return(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-conditions-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:s&&c&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(l.Select,{value:s.operator,options:h,onChange:g}),m.getItemByOperator(s.operator).numOfParameters===0?null:(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel-conditions-container-inner`,className:(0,l.clsx)(`univer-mt-2 univer-flex-grow univer-overflow-hidden univer-rounded-md univer-p-2`,l.borderClassName),children:[s.numOfParameters>=1&&b(c.operator1,(n=c.val1)==null?``:n,`operator1`),s.numOfParameters>=2&&b(c.operator2,(r=c.val2)==null?``:r,`operator2`),(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel-conditions-desc`,className:`univer-mt-2 univer-text-xs univer-text-gray-500`,children:[o.t(`sheets-filter.panel.?`),(0,d.jsx)(`br`,{}),o.t(`sheets-filter.panel.*`)]})]})]})})}function Oe(e){return(0,u.useMemo)(()=>[{options:[{label:e.t(m.NONE.label),value:m.NONE.operator}]},{options:[{label:e.t(m.EMPTY.label),value:m.EMPTY.operator},{label:e.t(m.NOT_EMPTY.label),value:m.NOT_EMPTY.operator}]},{options:[{label:e.t(m.TEXT_CONTAINS.label),value:m.TEXT_CONTAINS.operator},{label:e.t(m.DOES_NOT_CONTAIN.label),value:m.DOES_NOT_CONTAIN.operator},{label:e.t(m.STARTS_WITH.label),value:m.STARTS_WITH.operator},{label:e.t(m.ENDS_WITH.label),value:m.ENDS_WITH.operator},{label:e.t(m.EQUALS.label),value:m.EQUALS.operator}]},{options:[{label:e.t(m.GREATER_THAN.label),value:m.GREATER_THAN.operator},{label:e.t(m.GREATER_THAN_OR_EQUAL.label),value:m.GREATER_THAN_OR_EQUAL.operator},{label:e.t(m.LESS_THAN.label),value:m.LESS_THAN.operator},{label:e.t(m.LESS_THAN_OR_EQUAL.label),value:m.LESS_THAN_OR_EQUAL.operator},{label:e.t(m.EQUAL.label),value:m.EQUAL.operator},{label:e.t(m.NOT_EQUAL.label),value:m.NOT_EQUAL.operator},{label:e.t(m.BETWEEN.label),value:m.BETWEEN.operator},{label:e.t(m.NOT_BETWEEN.label),value:m.NOT_BETWEEN.operator}]},{options:[{label:e.t(m.CUSTOM.label),value:m.CUSTOM.operator}]}],[e.getCurrentLocale(),e])}function ke(e){return(0,u.useMemo)(()=>m.ALL_CONDITIONS.filter(e=>e.numOfParameters!==2).map(t=>({label:e.t(t.label),value:t.operator})),[e.getCurrentLocale(),e])}function Ae(e){let{model:n}=e,r=(0,i.useDependency)(t.LocaleService),a=(0,i.useObservable)(n.searchString$,``,!0),o=(0,i.useObservable)(n.filterItems$,void 0,!0),s=r.t(`sheets-filter.panel.filter-only`),c=g(o),f=c.checked>0&&c.unchecked===0,p=c.checked>0&&c.unchecked>0,m=n.treeMapCache,h=(0,u.useCallback)(()=>{n.onCheckAllToggled(!f)},[n,f]),_=(0,u.useCallback)(e=>{n.setSearchString(e)},[n]);function v(e){let t=[];return e.forEach(e=>{e.checked&&t.push(e.key),e.children&&(t=t.concat(v(e.children)))}),t}return(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel-values-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:[(0,d.jsx)(l.Input,{autoFocus:!0,value:a,placeholder:r.t(`sheets-filter.panel.search-placeholder`),onChange:_}),(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel`,className:(0,l.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`,l.borderClassName),children:[(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-values-item`,className:`univer-box-border univer-h-8 univer-w-full univer-py-0.5`,children:(0,d.jsxs)(`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:[(0,d.jsx)(l.Checkbox,{indeterminate:p,disabled:o.length===0,checked:f,onChange:h}),(0,d.jsx)(`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:`${r.t(`sheets-filter.panel.select-all`)}`}),(0,d.jsx)(`span`,{"data-u-comp":`sheets-filter-panel-values-item-count`,className:`univer-text-gray-400 dark:!univer-text-gray-500`,children:`(${c.checked}/${c.checked+c.unchecked})`})]})}),(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-values-virtual`,className:`univer-flex-grow`,children:(0,d.jsx)(l.Tree,{data:o,defaultExpandAll:!1,valueGroup:v(o),onChange:e=>{n.onFilterCheckToggled(e)},defaultCache:m,itemHeight:28,treeNodeClassName:`
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets-filter`),require(`@univerjs/sheets-ui`),require(`@univerjs/ui`),require(`@univerjs/engine-render`),require(`@univerjs/sheets`),require(`rxjs`),require(`@univerjs/rpc`),require(`@univerjs/design`),require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-filter`,`@univerjs/sheets-ui`,`@univerjs/ui`,`@univerjs/engine-render`,`@univerjs/sheets`,`rxjs`,`@univerjs/rpc`,`@univerjs/design`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFilterUi={},e.UniverCore,e.UniverSheetsFilter,e.UniverSheetsUi,e.UniverUi,e.UniverEngineRender,e.UniverSheets,e.rxjs,e.UniverRpc,e.UniverDesign,e.React,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let f=function(e){return e[e.FIRST=0]=`FIRST`,e[e.SECOND=1]=`SECOND`,e}({}),p=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}({}),m;(function(e){let r=e.NONE={label:`sheets-filter.conditions.none`,operator:p.NONE,order:f.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.NONE]: should not have initial form params!`)},testMappingParams:e=>e.operator1===p.NONE,mapToFilterColumn:()=>null,testMappingFilterColumn:e=>!e.customFilters&&!e.filters?{}:!1},i=e.ALL_CONDITIONS=[r,e.EMPTY={label:`sheets-filter.conditions.empty`,operator:p.EMPTY,order:f.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.EMPTY]: should not have initial form params!`)},testMappingParams:({operator1:e})=>e===p.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:p.EMPTY}:!1}},e.NOT_EMPTY={label:`sheets-filter.conditions.not-empty`,operator:p.NOT_EMPTY,order:f.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw Error(`[FilterConditionItems.NOT_EMPTY]: should not have initial form params!`)},testMappingParams:({operator1:e})=>e===p.NOT_EMPTY,mapToFilterColumn:()=>({customFilters:{customFilters:[{val:``,operator:n.CustomFilterOperator.NOT_EQUALS}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.val===` `&&r.operator===n.CustomFilterOperator.NOT_EQUALS?{operator1:p.NOT_EMPTY}:!1}},e.TEXT_CONTAINS={label:`sheets-filter.conditions.text-contains`,operator:p.CONTAINS,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.CONTAINS,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.CONTAINS,val1:r.slice(1,-1)}:!1}},e.DOES_NOT_CONTAIN={label:`sheets-filter.conditions.does-not-contain`,operator:p.DOES_NOT_CONTAIN,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.DOES_NOT_CONTAIN,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`*${e.val1}*`,operator:n.CustomFilterOperator.NOT_EQUALS}]}}),testMappingParams:e=>{let[t]=h(e);return t===p.DOES_NOT_CONTAIN},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0],i=r.val.toString();return r.operator===n.CustomFilterOperator.NOT_EQUALS&&i.startsWith(`*`)&&i.endsWith(`*`)?{operator1:p.DOES_NOT_CONTAIN,val1:i.slice(1,-1)}:!1}},e.STARTS_WITH={label:`sheets-filter.conditions.starts-with`,operator:p.STARTS_WITH,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.STARTS_WITH,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`${e.val1}*`}]}}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.STARTS_WITH,val1:r.slice(0,-1)}:!1}},e.ENDS_WITH={label:`sheets-filter.conditions.ends-with`,operator:p.ENDS_WITH,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.ENDS_WITH,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:`*${e.val1}`}]}}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.ENDS_WITH,val1:r.slice(1)}:!1}},e.EQUALS={label:`sheets-filter.conditions.equals`,operator:p.EQUALS,order:f.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:p.EQUALS,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===p.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:p.EQUALS,val1:``}:((n=e.customFilters)==null?void 0:n.customFilters.length)===1&&!e.customFilters.customFilters[0].operator?{operator1:p.EQUALS,val1:e.customFilters.customFilters[0].val.toString()}:!1}},e.GREATER_THAN={label:`sheets-filter.conditions.greater-than`,operator:n.CustomFilterOperator.GREATER_THAN,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:n.CustomFilterOperator.GREATER_THAN,val1:``}),mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:n.CustomFilterOperator.GREATER_THAN}]}}),testMappingParams:e=>{let[t]=h(e);return t===n.CustomFilterOperator.GREATER_THAN},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===n.CustomFilterOperator.GREATER_THAN?{operator1:n.CustomFilterOperator.GREATER_THAN,val1:r.val.toString()}:!1}},e.GREATER_THAN_OR_EQUAL={label:`sheets-filter.conditions.greater-than-or-equal`,operator:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===n.CustomFilterOperator.GREATER_THAN_OR_EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===n.CustomFilterOperator.GREATER_THAN_OR_EQUAL?{operator1:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:r.val.toString()}:!1}},e.LESS_THAN={label:`sheets-filter.conditions.less-than`,operator:n.CustomFilterOperator.LESS_THAN,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:n.CustomFilterOperator.LESS_THAN,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===n.CustomFilterOperator.LESS_THAN},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:n.CustomFilterOperator.LESS_THAN}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===n.CustomFilterOperator.LESS_THAN?{operator1:n.CustomFilterOperator.LESS_THAN,val1:r.val.toString()}:!1}},e.LESS_THAN_OR_EQUAL={label:`sheets-filter.conditions.less-than-or-equal`,operator:n.CustomFilterOperator.LESS_THAN_OR_EQUAL,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:n.CustomFilterOperator.LESS_THAN_OR_EQUAL,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===n.CustomFilterOperator.LESS_THAN_OR_EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:n.CustomFilterOperator.LESS_THAN_OR_EQUAL}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===n.CustomFilterOperator.LESS_THAN_OR_EQUAL?{operator1:n.CustomFilterOperator.LESS_THAN_OR_EQUAL,val1:r.val.toString()}:!1}},e.EQUAL={label:`sheets-filter.conditions.equal`,operator:n.CustomFilterOperator.EQUAL,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:n.CustomFilterOperator.EQUAL,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===n.CustomFilterOperator.EQUAL},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:n.CustomFilterOperator.EQUAL}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===n.CustomFilterOperator.EQUAL?{operator1:n.CustomFilterOperator.EQUAL,val1:r.val.toString()}:!1}},e.NOT_EQUAL={label:`sheets-filter.conditions.not-equal`,operator:n.CustomFilterOperator.NOT_EQUALS,numOfParameters:1,order:f.FIRST,getDefaultFormParams:()=>({operator1:n.CustomFilterOperator.NOT_EQUALS,val1:``}),testMappingParams:e=>{let[t]=h(e);return t===n.CustomFilterOperator.NOT_EQUALS},mapToFilterColumn:e=>({customFilters:{customFilters:[{val:e.val1,operator:n.CustomFilterOperator.NOT_EQUALS}]}}),testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==1)return!1;let r=e.customFilters.customFilters[0];return r.operator===n.CustomFilterOperator.NOT_EQUALS?{operator1:n.CustomFilterOperator.NOT_EQUALS,val1:r.val.toString()}:!1}},e.BETWEEN={label:`sheets-filter.conditions.between`,operator:p.BETWEEN,order:f.SECOND,numOfParameters:2,getDefaultFormParams:()=>({and:!0,operator1:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:``,operator2:n.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:``}),testMappingParams:e=>{let{and:t,operator1:r,operator2:i}=e;if(!t)return!1;let a=[r,i];return a.includes(n.CustomFilterOperator.GREATER_THAN_OR_EQUAL)&&a.includes(n.CustomFilterOperator.LESS_THAN_OR_EQUAL)},mapToFilterColumn:e=>{let{val1:r,val2:i,operator1:a}=e,o=a===n.CustomFilterOperator.GREATER_THAN_OR_EQUAL;return{customFilters:{and:t.BooleanNumber.TRUE,customFilters:[{val:o?r:i,operator:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL},{val:o?i:r,operator:n.CustomFilterOperator.LESS_THAN_OR_EQUAL}]}}},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==2)return!1;let[r,i]=e.customFilters.customFilters;return r.operator===n.CustomFilterOperator.GREATER_THAN_OR_EQUAL&&i.operator===n.CustomFilterOperator.LESS_THAN_OR_EQUAL&&e.customFilters.and?{and:!0,operator1:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:r.val.toString(),operator2:n.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:i.val.toString()}:i.operator===n.CustomFilterOperator.GREATER_THAN_OR_EQUAL&&r.operator===n.CustomFilterOperator.LESS_THAN_OR_EQUAL&&e.customFilters.and?{and:!0,operator1:n.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:i.val.toString(),operator2:n.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:r.val.toLocaleString()}:!1}},e.NOT_BETWEEN={label:`sheets-filter.conditions.not-between`,operator:p.NOT_BETWEEN,order:f.SECOND,numOfParameters:2,getDefaultFormParams:()=>({operator1:n.CustomFilterOperator.LESS_THAN,val1:``,operator2:n.CustomFilterOperator.GREATER_THAN,val2:``}),testMappingParams:e=>{let{and:t,operator1:r,operator2:i}=e;if(t)return!1;let a=[r,i];return a.includes(n.CustomFilterOperator.GREATER_THAN)&&a.includes(n.CustomFilterOperator.LESS_THAN)},mapToFilterColumn:e=>{let{val1:t,val2:r,operator1:i}=e,a=i===n.CustomFilterOperator.GREATER_THAN;return{customFilters:{customFilters:[{val:a?t:r,operator:n.CustomFilterOperator.GREATER_THAN},{val:a?r:t,operator:n.CustomFilterOperator.LESS_THAN}]}}},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==2)return!1;let[r,i]=e.customFilters.customFilters;return r.operator===n.CustomFilterOperator.LESS_THAN&&i.operator===n.CustomFilterOperator.GREATER_THAN&&!e.customFilters.and?{operator1:n.CustomFilterOperator.LESS_THAN,val1:r.val.toString(),operator2:n.CustomFilterOperator.GREATER_THAN,val2:i.val.toString()}:i.operator===n.CustomFilterOperator.LESS_THAN&&r.operator===n.CustomFilterOperator.GREATER_THAN&&!e.customFilters.and?{operator1:n.CustomFilterOperator.GREATER_THAN,val1:i.val.toString(),operator2:n.CustomFilterOperator.LESS_THAN,val2:r.val.toLocaleString()}:!1}},e.CUSTOM={label:`sheets-filter.conditions.custom`,operator:p.CUSTOM,order:f.SECOND,numOfParameters:2,getDefaultFormParams:()=>({operator1:p.NONE,val1:``,operator2:p.NONE,val2:``}),testMappingParams:()=>!0,mapToFilterColumn:e=>{let{and:n,val1:a,val2:o,operator1:s,operator2:c}=e;function l(e,t){for(let n of i)if(n.operator===e)return n.mapToFilterColumn({val1:t,operator1:e})}let u=!s||s===m.NONE.operator,d=!c||c===m.NONE.operator;if(u&&d)return r.mapToFilterColumn({});if(u)return l(c,o);if(d)return l(s,a);let f=l(s,a),p=l(c,o),h={customFilters:[f.customFilters.customFilters[0],p.customFilters.customFilters[0]]};return n&&(h.and=t.BooleanNumber.TRUE),{customFilters:h}},testMappingFilterColumn:e=>{var t;if(((t=e.customFilters)==null?void 0:t.customFilters.length)!==2)return!1;let n=e.customFilters.customFilters.map(e=>l({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 a(e){let t=i.find(t=>t.operator===e);if(!t)throw Error(`[SheetsFilter]: no condition item found for operator: ${e}`);return t}e.getItemByOperator=a;function o(e,t){for(let n of i.filter(e=>e.numOfParameters===t))if(n.numOfParameters!==0&&n.testMappingParams(e))return n;for(let t of i)if(t.testMappingParams(e))return t;throw Error(`[SheetsFilter]: no condition item can be mapped from the filter map params!`)}e.testMappingParams=o;function s(e){let t=i.find(t=>t.operator===e);return(t==null?void 0:t.numOfParameters)===0?{operator1:t.operator}:t.getDefaultFormParams()}e.getInitialFormParams=s;function c(e,t){return e.mapToFilterColumn(t)}e.mapToFilterColumn=c;function l(e){if(!e)return[r,{}];for(let t of i){let n=t.testMappingFilterColumn(e);if(n)return[t,n]}return[r,{}]}e.testMappingFilterColumn=l})(m||(m={}));function h(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 g(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 _(e,t){return function(n,r){t(n,r,e)}}function v(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let y=`sheets-filter.generate-filter-values.service`,b=(0,t.createIdentifier)(y),x=class extends t.Disposable{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}),S(o,this._localeService,c,d,new Set(i),a,new Set(l.map(String)),s,u.getStyles()))}};x=v([_(0,(0,t.Inject)(t.LocaleService)),_(1,t.IUniverInstanceService),_(2,t.ILogService)],x);function S(e,r,i,a,o,s,c,l,u){var d;let f=new Map,p=new Map,m=`empty`,h=!e&&((s==null?void 0:s.filterBy)===n.FilterBy.COLORS||(s==null?void 0:s.filterBy)===n.FilterBy.CONDITIONS)&&((d=s.filteredOutRows)==null?void 0:d.size),g=0;for(let e of a.iterateByColumn(i,!1,!1)){let{row:n,rowSpan:i=1}=e,s=0;for(;s<i;){var _,v,y;let d=n+s;if(o.has(d)){s++;continue}let m=e!=null&&e.value?(0,t.extractPureTextFromCell)(e.value):``;if(!m){g+=1,s+=i;continue}let C=(_=e.value)!=null&&_.v&&!e.value.p?(v=u.get((y=e.value)==null?void 0:y.s))==null||(v=v.n)==null?void 0:v.pattern:``,E=C&&t.numfmt.getFormatInfo(C).isDate,D=!1;if(E){let{year:e,month:n,day:r}=t.numfmt.getFormatDateInfo(C);D=e||n||r}if(C&&E&&D){var b,x,S;let n=(b=a.getCellRaw(e.row,e.col))==null?void 0:b.v;if(!n){s++;continue}let[i,o,u]=t.numfmt.format(`yyyy-mm-dd`,Number(n)).split(`-`).map(Number),d=f.get(`${i}`);d||(d={title:`${i}`,key:`${i}`,children:[],count:0,leaf:!1,checked:!1},f.set(`${i}`,d),p.set(`${i}`,[`${i}`]));let g=(x=d.children)==null?void 0:x.find(e=>e.key===`${i}-${o}`);if(!g){var w;g={title:r.t(`sheets-filter.date.${o}`),key:`${i}-${o}`,children:[],count:0,leaf:!1,checked:!1},(w=d.children)==null||w.push(g),p.set(`${i}-${o}`,[`${i}`,`${i}-${o}`])}let _=g==null||(S=g.children)==null?void 0:S.find(e=>e.key===`${i}-${o}-${u}`);if(_)_.originValues.add(m),_.count++,g.count++,d.count++;else{var T;(T=g.children)==null||T.push({title:`${u}`,key:`${i}-${o}-${u}`,count:1,originValues:new Set([m]),leaf:!0,checked:h?!1:c.size?c.has(m):!l}),g.count++,d.count++,p.set(`${i}-${o}-${u}`,[`${i}`,`${i}-${o}`,`${i}-${o}-${u}`])}}else{let e=m,t=f.get(e);t?t.count++:(t={title:m,leaf:!0,checked:h?!1:c.size?c.has(m):!l,key:e,count:1},f.set(e,t),p.set(e,[e]))}s++}}let E=h?!1:e?l:!0;if(g>0){let e={title:r.t(`sheets-filter.panel.empty`),count:g,leaf:!0,checked:E,key:m};f.set(`empty`,e),p.set(`empty`,[m])}return{filterTreeItems:C(Array.from(f.values())),filterTreeMapCache:p}}function C(e){return Array.from(e).sort((e,t)=>e.children&&!t.children?-1:!e.children&&t.children?1:T(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))}let w=e=>!Number.isNaN(Number(e))&&!Number.isNaN(Number.parseFloat(e));function T(e,t){let n=w(e),r=w(t);return n&&r?Number.parseFloat(e)-Number.parseFloat(t):n&&!r?-1:!n&&r?1:e.localeCompare(t)}function E(e,t){for(let n of e){if(n.key===t)return n;if(n.children){let e=E(n.children,t);if(e)return e}}return null}function D(e){return e.leaf?e.checked:e.children?e.children.every(e=>D(e)):!0}function O(e,t){e.leaf&&(t===void 0?e.checked=!e.checked:e.checked=t),e.children&&e.children.forEach(e=>O(e,t))}function ee(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=ee(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 k(e){"@babel/helpers - typeof";return k=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},k(e)}function te(e,t){if(k(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(k(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function ne(e){var t=te(e,`string`);return k(t)==`symbol`?t:t+``}function A(e,t,n){return(t=ne(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var j,M,N;(0,t.createIdentifier)(`sheets-filter-ui.sheets-filter-panel.service`);let P=class extends t.Disposable{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,A(this,`_filterBy$`,new s.BehaviorSubject(n.FilterBy.VALUES)),A(this,`filterBy$`,this._filterBy$.asObservable()),A(this,`_filterByModel$`,new s.ReplaySubject(1)),A(this,`filterByModel$`,this._filterByModel$.asObservable()),A(this,`_filterByModel`,null),A(this,`_hasCriteria$`,new s.BehaviorSubject(!1)),A(this,`hasCriteria$`,this._hasCriteria$.asObservable()),A(this,`_filterModel`,null),A(this,`_col$`,new s.BehaviorSubject(-1)),A(this,`col$`,this._col$.asObservable()),A(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 n.FilterBy.VALUES:this._setupByValues(this._filterModel,this.col);break;case n.FilterBy.COLORS:this._setupByColors(this._filterModel,this.col);break;case n.FilterBy.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 r=e.getRange();return r.startRow===r.endRow?!1:(this.filterByModel=await I.fromFilterColumn(this._injector,e,t),this._filterBy$.next(n.FilterBy.VALUES),this._listenToFilterHeaderChange(e,t),!0)}async _setupByColors(e,t){this._disposePreviousModel();let r=e.getRange();return r.startRow===r.endRow?!1:(this.filterByModel=await re.fromFilterColumn(this._injector,e,t),this._filterBy$.next(n.FilterBy.COLORS),this._listenToFilterHeaderChange(e,t),!0)}_setupByConditions(e,t){this._disposePreviousModel();let r=e.getRange();return r.startRow===r.endRow?!1:(this.filterByModel=F.fromFilterColumn(this._injector,e,t,e.getFilterColumn(t)),this._filterBy$.next(n.FilterBy.CONDITIONS),this._listenToFilterHeaderChange(e,t),!0)}_disposePreviousModel(){var e;(e=this._filterByModel)==null||e.dispose(),this.filterByModel=null}};P=v([_(0,(0,t.Inject)(t.Injector)),_(1,(0,t.Inject)(o.RefRangeService))],P);let F=j=class extends t.Disposable{static fromFilterColumn(e,t,n,r){let[i,a]=m.testMappingFilterColumn(r==null?void 0:r.getColumnData());return e.createInstance(j,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,A(this,`canApply$`,(0,s.of)(!0)),A(this,`_conditionItem$`,void 0),A(this,`conditionItem$`,void 0),A(this,`_filterConditionFormParams$`,void 0),A(this,`filterConditionFormParams$`,void 0),this._conditionItem$=new s.BehaviorSubject(n),this.conditionItem$=this._conditionItem$.asObservable(),this._filterConditionFormParams$=new s.BehaviorSubject(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(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}async apply(){if(this._disposed)return!1;let e=m.mapToFilterColumn(this.conditionItem,this.filterConditionFormParams);return this._commandService.executeCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:e})}onPrimaryConditionChange(e){let t=m.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(m.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=m.testMappingParams(t,this.conditionItem.numOfParameters);this._conditionItem$.next(e)}this._filterConditionFormParams$.next(t)}};F=j=v([_(4,t.ICommandService)],F);let I=M=class extends t.Disposable{static async fromFilterColumn(e,n,r){let i=e.get(t.IUniverInstanceService),a=e.get(t.LocaleService),o=e.get(b,t.Quantity.OPTIONAL),{unitId:s,subUnitId:c}=n,l=i.getUniverSheetInstance(s);if(!l)throw Error(`[ByValuesModel]: Workbook not found for filter model with unitId: ${s}!`);let u=l==null?void 0:l.getSheetBySheetId(c);if(!u)throw Error(`[ByValuesModel]: Worksheet not found for filter model with unitId: ${s} and subUnitId: ${c}!`);let d=n.getRange(),f=r,p=n.getFilterColumn(r),m=p==null?void 0:p.getColumnData().filters,h=new Set(m==null?void 0:m.filters),g=!!(m&&m.blank),_=n.getFilteredOutRowsExceptCol(r),v={...d,startRow:d.startRow+1,startColumn:f,endColumn:f},y,x;if(o){let e=await o.getFilterValues({unitId:s,subUnitId:c,filteredOutRowsByOtherColumns:Array.from(_),filterColumn:p,filters:!!m,blankChecked:g,iterateRange:v,alreadyChecked:Array.from(h)});y=e.filterTreeItems,x=e.filterTreeMapCache}else{let e=S(!!m,a,v,u,_,p,h,g,l.getStyles());y=e.filterTreeItems,x=e.filterTreeMapCache}return e.createInstance(M,n,r,y,x)}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,A(this,`_rawFilterItems$`,void 0),A(this,`rawFilterItems$`,void 0),A(this,`filterItems$`,void 0),A(this,`_filterItems`,[]),A(this,`_treeMapCache`,void 0),A(this,`canApply$`,void 0),A(this,`_manuallyUpdateFilterItems$`,void 0),A(this,`_searchString$`,void 0),A(this,`searchString$`,void 0),this._treeMapCache=r,this._searchString$=new s.BehaviorSubject(``),this.searchString$=this._searchString$.asObservable(),this._rawFilterItems$=new s.BehaviorSubject(n),this.rawFilterItems$=this._rawFilterItems$.asObservable(),this._manuallyUpdateFilterItems$=new s.Subject,this.filterItems$=(0,s.merge)((0,s.combineLatest)([this._searchString$.pipe((0,s.throttleTime)(500,void 0,{leading:!0,trailing:!0}),(0,s.startWith)(void 0)),this._rawFilterItems$]).pipe((0,s.map)(([e,t])=>e?ee(t,e.toLowerCase().split(/\s+/).filter(e=>!!e)):t)),this._manuallyUpdateFilterItems$).pipe((0,s.shareReplay)(1)),this.canApply$=this.filterItems$.pipe((0,s.map)(e=>g(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 n=t.Tools.deepClone(this._filterItems);n.forEach(t=>O(t,e)),this._manuallyUpdateFilterItems(n)}onFilterCheckToggled(e){let n=t.Tools.deepClone(this._filterItems),r=E(n,e.key);r&&(O(r,!D(r)),this._manuallyUpdateFilterItems(n))}onFilterOnly(e){let n=t.Tools.deepClone(this._filterItems);n.forEach(e=>O(e,!1)),e.forEach(e=>{let t=E(n,e);t&&O(t,!0)}),this._manuallyUpdateFilterItems(n)}_manuallyUpdateFilterItems(e){this._manuallyUpdateFilterItems$.next(e)}clear(){return this._disposed?Promise.resolve(!1):this._commandService.executeCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}async apply(){if(this._disposed)return!1;let e=g(this._filterItems),{checked:t,checkedItems:r}=e,i=this.rawFilterItems,a=0;for(let e of i)a+=e.count;let o=t===0,s=e.checked===a,c={colId:this.col};if(o)throw Error(`[ByValuesModel]: no checked items!`);if(s)return this._commandService.executeCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null});{c.filters={};let e=r.filter(e=>e.key!==`empty`);e.length>0&&(c.filters={filters:e.flatMap(e=>e.originValues?Array.from(e.originValues):[e.title])}),e.length!==r.length&&(c.filters.blank=!0)}return this._commandService.executeCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:c})}};I=M=v([_(4,t.ICommandService)],I);let re=N=class extends t.Disposable{static async fromFilterColumn(e,n,r){var i,o,s;let c=e.get(t.IUniverInstanceService),{unitId:l,subUnitId:u}=n,d=c.getUniverSheetInstance(l);if(!d)throw Error(`[ByColorsModel]: Workbook not found for filter model with unitId: ${l}!`);let f=d==null?void 0:d.getSheetBySheetId(u);if(!f)throw Error(`[ByColorsModel]: Worksheet not found for filter model with unitId: ${l} 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((o=h==null?void 0:h.cellFillColors)==null?[]:o),b=new Map,x=new Set((s=h==null?void 0:h.cellTextColors)==null?[]:s);for(let e of f.iterateByColumn(_,!1,!0)){let{row:n,col:r,value:i}=e;if(g.has(n))continue;let o=f.getComposedCellStyleByCellData(n,r,i);if(o.bg&&o.bg.rgb){let e=new t.ColorKit(o.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(o.cl&&o.cl.rgb){let e=new t.ColorKit(o.cl.rgb).toRgbString();b.has(e)||b.set(e,{color:e,checked:x.has(e)})}else b.set(`default-font-color`,{color:a.COLOR_BLACK_RGB,checked:x.has(a.COLOR_BLACK_RGB)})}return e.createInstance(N,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,A(this,`canApply$`,(0,s.of)(!0)),A(this,`_cellFillColors$`,void 0),A(this,`cellFillColors$`,void 0),A(this,`_cellTextColors$`,void 0),A(this,`cellTextColors$`,void 0),this._cellFillColors$=new s.BehaviorSubject(Array.from(n.values())),this.cellFillColors$=this._cellFillColors$.asObservable(),this._cellTextColors$=new s.BehaviorSubject(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(n.SetSheetsFilterCriteriaCommand.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(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null});let r={colId:this.col};return e.length>0?r.colorFilters={cellFillColors:e}:t.length>0&&(r.colorFilters={cellTextColors:t}),this._commandService.executeCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:r})}};re=N=v([_(4,t.ICommandService)],re);let L=`FILTER_PANEL_OPENED`,R={id:`sheet.operation.open-filter-panel`,type:t.CommandType.OPERATION,handler:(e,i)=>{let a=e.get(t.IContextService),o=e.get(n.SheetsFilterService),s=e.get(P),c=e.get(t.ICommandService),l=e.has(r.IEditorBridgeService)?e.get(r.IEditorBridgeService):null;l!=null&&l.isVisible().visible&&c.syncExecuteCommand(r.SetCellEditVisibleOperation.id,{visible:!1});let{unitId:u,subUnitId:d,col:f}=i,p=o.getFilterModel(u,d);return p?(s.setupCol(p,f),a.getContextValue(`FILTER_PANEL_OPENED`)||a.setContextValue(L,!0),!0):!1}},z={id:`sheet.operation.close-filter-panel`,type:t.CommandType.OPERATION,handler:e=>{let n=e.get(t.IContextService),r=e.get(P),a=e.get(i.ILayoutService,t.Quantity.OPTIONAL);return n.getContextValue(`FILTER_PANEL_OPENED`)?(n.setContextValue(L,!1),a==null||a.focus(),r.terminate()):!1}},B={id:`sheet.operation.apply-filter`,type:t.CommandType.OPERATION,handler:(e,t)=>{let{filterBy:n}=t;return e.get(P).changeFilterBy(n)}};var V=`@univerjs/sheets-filter-ui`,H=`0.20.0`;let U=`sheets-filter-ui.config`;Symbol(U);let W={},G=class extends t.Disposable{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===n.SmartToggleSheetsFilterCommand.id){var r;let e=(0,o.getSheetCommandTarget)(this._injector.get(t.IUniverInstanceService));if(!e)return;let{unitId:n,subUnitId:a,worksheet:s}=e,c=(r=this._sheetsFilterService.getFilterModel(n,a))==null?void 0:r.getRange(),l;if(c)l=this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[o.RangeProtectionPermissionViewPoint],worksheetTypes:[o.WorksheetFilterPermission,o.WorksheetViewPermission]},[c],n,a);else{var i;let e=(i=this._sheetsSelectionService.getCurrentLastSelection())==null?void 0:i.range;if(e){let t={...e};t=e.startColumn===e.endColumn&&e.startRow===e.endRow?(0,o.expandToContinuousRange)(t,{left:!0,right:!0,up:!0,down:!0},s):t,l=this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[o.RangeProtectionPermissionViewPoint],worksheetTypes:[o.WorksheetViewPermission,o.WorksheetFilterPermission]},[t],n,a)}else l=this._sheetPermissionCheckPermission.permissionCheckWithoutRange({rangeTypes:[o.RangeProtectionPermissionViewPoint],worksheetTypes:[o.WorksheetViewPermission,o.WorksheetFilterPermission]})}l||this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.filterErr`))}if(e.id===R.id){var a;let n=e.params,{unitId:r,subUnitId:i}=n,s=(a=this._sheetsFilterService.getFilterModel(r,i))==null?void 0:a.getRange(),c=t.Tools.deepClone(s);c&&(c.startColumn=n.col,c.endColumn=n.col,this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[o.RangeProtectionPermissionViewPoint],worksheetTypes:[o.WorksheetFilterPermission,o.WorksheetViewPermission]},[c],r,i)||this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.filterErr`)))}}))}};G=v([_(0,(0,t.Inject)(n.SheetsFilterService)),_(1,(0,t.Inject)(t.LocaleService)),_(2,t.ICommandService),_(3,(0,t.Inject)(o.SheetPermissionCheckController)),_(4,(0,t.Inject)(t.Injector)),_(5,(0,t.Inject)(o.SheetsSelectionsService))],G);let ie=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 ae=class{static drawNoCriteria(e,t,n,r){e.save(),a.Rect.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(),a.Rect.drawWith(e,{radius:2,width:16,height:16,fill:r}),e.scale(t/16,t/16),e.fillStyle=n,e.fill(ie),e.restore()}};let K=class extends a.Shape{constructor(e,t,n,r,i){super(e,t),this._contextService=n,this._commandService=r,this._themeService=i,A(this,`_cellWidth`,0),A(this,`_cellHeight`,0),A(this,`_filterParams`,void 0),A(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?ae.drawHasCriteria(e,16,s,c):ae.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(R.id)||setTimeout(()=>{this._commandService.executeCommand(R.id,{unitId:n,subUnitId:r,col:t})},200)}onPointerEnter(){this._hovered=!0,this.makeDirty(!0)}onPointerLeave(){this._hovered=!1,this.makeDirty(!0)}};K=v([_(2,t.IContextService),_(3,t.ICommandService),_(4,(0,t.Inject)(t.ThemeService))],K);function oe(e,n,r,i){switch(i){case t.VerticalAlign.TOP:return e+1;case t.VerticalAlign.MIDDLE:return e+Math.max(0,(r-16)/2);case t.VerticalAlign.BOTTOM:default:return n-16-1}}let q=class extends t.RxDisposable{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,A(this,`_currentRenderParams`,null),A(this,`_filterRangeShape`,null),A(this,`_buttonRenderDisposable`,null),A(this,`_filterButtonShapes`,[]),this._initRenderer()}dispose(){super.dispose(),this._disposeRendering()}_initRenderer(){this.disposeWithMe(this._themeService.currentTheme$.subscribe(()=>{this._refreshRendering(this._currentRenderParams)})),this._sheetSkeletonManagerService.currentSkeleton$.pipe((0,s.switchMap)(e=>{var r,i;if(!e)return(0,s.of)(null);let{unit:a,unitId:c}=this._context,l=((r=a.getActiveSheet())==null?void 0:r.getSheetId())||``,u=(i=this._sheetsFilterService.getFilterModel(c,l))==null?void 0:i,d=()=>({unitId:c,worksheetId:l,filterModel:u,range:u==null?void 0:u.getRange(),skeleton:e.skeleton});return(0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,s.filter)(([e])=>{var r;return e.type===t.CommandType.MUTATION&&((r=e.params)==null?void 0:r.unitId)===a.getUnitId()&&(n.FILTER_MUTATIONS.has(e.id)||e.id===o.SetRangeValuesMutation.id)}),(0,s.throttleTime)(20,void 0,{leading:!1,trailing:!0}),(0,s.map)(d),(0,s.startWith)(d()))}),(0,s.takeUntil)(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:i,columnHeaderHeight:a}=t,s=this._filterRangeShape=new r.SelectionControl(n,1e3,this._themeService,{rowHeaderWidth:i,columnHeaderHeight:a,enableAutoFill:!1,highlightHeader:!1}),c=(0,o.attachSelectionWithCoord)({range:e,primary:null,style:{fill:`rgba(0, 0, 0, 0.0)`}},t);s.updateRangeBySelectionWithCoord(c),s.setEvent(!1),n.makeDirty(!0)}_renderButtons(e){let{range:n,filterModel:i,unitId:a,skeleton:o,worksheetId:s}=e,{unit:c,scene:l}=this._context,u=c.getSheetBySheetId(s);if(!u)return;this._interceptCellContent(a,s,e.range);let{startColumn:d,endColumn:f,startRow:p}=n;for(let e=d;e<=f;e++){let n=`sheets-filter-button-${e}`,c=(0,r.getCoordByCell)(p,e,l,o),d=u.getComposedCellStyle(p,e),f=(d==null?void 0:d.vt)||t.VerticalAlign.BOTTOM,{startX:m,startY:h,endX:g,endY:_}=c,v=g-m,y=_-h;if(y<=1||v<=1)continue;let b=!!i.getFilterColumn(e),x={left:g-16-1,top:oe(h,_,y,f),height:16,width:16,zIndex:5e3,cellHeight:y,cellWidth:v,filterParams:{unitId:a,subUnitId:s,col:e,hasCriteria:b}},S=this._injector.createInstance(K,n,x);this._filterButtonShapes.push(S)}l.addObjects(this._filterButtonShapes),l.makeDirty()}_interceptCellContent(e,n,r){let{startRow:i,startColumn:a,endColumn:s}=r;this._buttonRenderDisposable=this._sheetInterceptorService.intercept(o.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,handler:(t,r,o)=>{let{row:c,col:l,unitId:u,subUnitId:d}=r;return u!==e||d!==n||c!==i||l<a||l>s?o(t):((!t||t===r.rawData)&&(t={...r.rawData}),t.fontRenderExtension={...t==null?void 0:t.fontRenderExtension,rightOffset:16},o(t))},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=[]}};q=v([_(1,(0,t.Inject)(t.Injector)),_(2,(0,t.Inject)(r.SheetSkeletonManagerService)),_(3,(0,t.Inject)(n.SheetsFilterService)),_(4,(0,t.Inject)(t.ThemeService)),_(5,(0,t.Inject)(o.SheetInterceptorService)),_(6,t.ICommandService),_(7,r.ISheetSelectionRenderService)],q);let J=class extends t.RxDisposable{constructor(e,r){super(),this._renderManagerService=e,this._sheetsRenderService=r,[n.SetSheetsFilterRangeMutation,n.SetSheetsFilterCriteriaMutation,n.RemoveSheetsFilterMutation,n.ReCalcSheetsFilterMutation].forEach(e=>this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(e.id))),this.disposeWithMe(this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,[q]))}};J=v([_(0,a.IRenderManagerService),_(1,(0,t.Inject)(r.SheetsRenderService))],J);let Y=class extends t.Plugin{constructor(e=W,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},W,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(U,a)}onStarting(){[[G],[J]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(G)}onRendered(){this._injector.get(J)}};A(Y,`type`,t.UniverInstanceType.UNIVER_SHEET),A(Y,`pluginName`,`SHEET_FILTER_UI_PLUGIN`),A(Y,`packageName`,V),A(Y,`version`,H),Y=v([(0,t.DependentOn)(n.UniverSheetsFilterPlugin),_(1,(0,t.Inject)(t.Injector)),_(2,t.IConfigService)],Y);function X({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),c=(0,u.useRef)(`_${ue()}`);return se(n,`${r}`,{defIds:n.defIds,idSuffix:c.current},{ref:e,className:s,...o},a)}function se(e,t,n,r,i){return(0,u.createElement)(e.tag,{key:t,...ce(e,n,i),...r},(le(e,n).children||[]).map((r,a)=>se(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function ce(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function le(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function ue(){return Math.random().toString(36).substring(2,8)}X.displayName=`UniverIcon`;let de={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 20 20`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M10 1.05957C10.356 1.05957 10.6816 1.26162 10.8408 1.58008L18.8408 17.5801L18.8799 17.668C19.0486 18.1134 18.8551 18.6232 18.4199 18.8408C17.9557 19.0727 17.3913 18.8841 17.1592 18.4199L10 4.10156L2.84082 18.4199C2.60871 18.8841 2.04434 19.0727 1.58008 18.8408C1.11587 18.6087 0.92731 18.0443 1.15918 17.5801L9.15918 1.58008C9.31841 1.26162 9.64395 1.05957 10 1.05957Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M15.3337 11.7261L15.4294 11.731C15.9035 11.779 16.2732 12.1798 16.2732 12.6665C16.2732 13.1532 15.9035 13.554 15.4294 13.602L15.3337 13.6069H4.66675C4.1476 13.6069 3.72632 13.1856 3.72632 12.6665C3.72632 12.1474 4.1476 11.7261 4.66675 11.7261H15.3337Z`}}]},fe=(0,u.forwardRef)(function(e,t){return(0,u.createElement)(X,Object.assign({},e,{id:`a-icon`,ref:t,icon:de}))});fe.displayName=`AIcon`;let pe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 20 20`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M17.0596 10C17.0596 6.10087 13.8992 2.94043 10 2.94043C6.10087 2.94043 2.94043 6.10087 2.94043 10C2.94043 13.8992 6.10087 17.0596 10 17.0596C13.8992 17.0596 17.0596 13.8992 17.0596 10ZM18.9404 10C18.9404 14.9374 14.9374 18.9404 10 18.9404C5.06257 18.9404 1.05957 14.9374 1.05957 10C1.05957 5.06257 5.06257 1.05957 10 1.05957C14.9374 1.05957 18.9404 5.06257 18.9404 10Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.29492 4.13476C4.63911 3.79057 5.1845 3.76906 5.55371 4.07031L5.625 4.13476L16.0244 14.5352L16.0889 14.6064C16.3902 14.9757 16.3686 15.52 16.0244 15.8643C15.6573 16.2313 15.0624 16.2313 14.6953 15.8643L4.29492 5.46484L4.23047 5.39355C3.92922 5.02434 3.95073 4.47895 4.29492 4.13476Z`}}]},me=(0,u.forwardRef)(function(e,t){return(0,u.createElement)(X,Object.assign({},e,{id:`ban-icon`,ref:t,icon:pe}))});me.displayName=`BanIcon`;let he={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M3.32182 2.60967C2.98161 2.60967 2.79671 3.0074 3.01601 3.2675L6.85819 7.8246C6.94943 7.93282 6.99947 8.06981 6.99947 8.21136V12.7338C6.99947 12.898 7.0998 13.0455 7.2525 13.1058L8.73833 13.6928C9.00085 13.7965 9.28531 13.6031 9.28531 13.3208V8.21136C9.28531 8.06981 9.33535 7.93282 9.42659 7.8246L13.2688 3.2675C13.4881 3.0074 13.3032 2.60967 12.963 2.60967H3.32182ZM2.09858 4.04101C1.22139 3.0006 1.96097 1.40967 3.32182 1.40967H12.963C14.3238 1.40967 15.0634 3.0006 14.1862 4.04101L10.4853 8.43054V13.3208C10.4853 14.4498 9.34747 15.2237 8.29742 14.8089L6.81158 14.2219C6.20078 13.9806 5.79947 13.3905 5.79947 12.7338V8.43054L2.09858 4.04101Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},ge=(0,u.forwardRef)(function(e,t){return(0,u.createElement)(X,Object.assign({},e,{id:`filter-icon`,ref:t,icon:he}))});ge.displayName=`FilterIcon`;let _e={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M8.00016 1.33203C6.68162 1.33203 5.39269 1.72302 4.29636 2.45557C3.20004 3.18811 2.34555 4.2293 1.84097 5.44747C1.33638 6.66565 1.20436 8.00609 1.4616 9.2993C1.71883 10.5925 2.35377 11.7804 3.28612 12.7127C4.21847 13.6451 5.40636 14.28 6.69956 14.5373C7.99277 14.7945 9.33321 14.6625 10.5514 14.1579C11.7696 13.6533 12.8108 12.7988 13.5433 11.7025C14.2758 10.6062 14.6668 9.31724 14.6668 7.9987C14.6649 6.23118 13.9619 4.53662 12.7121 3.2868C11.4622 2.03697 9.76768 1.33397 8.00016 1.33203ZM7.66683 3.9987C7.86461 3.9987 8.05795 4.05735 8.2224 4.16723C8.38685 4.27711 8.51502 4.43329 8.59071 4.61601C8.6664 4.79874 8.6862 4.99981 8.64762 5.19379C8.60903 5.38777 8.51379 5.56595 8.37394 5.7058C8.23409 5.84566 8.0559 5.9409 7.86192 5.97948C7.66794 6.01807 7.46687 5.99826 7.28415 5.92258C7.10142 5.84689 6.94524 5.71872 6.83536 5.55427C6.72548 5.38982 6.66683 5.19648 6.66683 4.9987C6.66683 4.73348 6.77219 4.47913 6.95972 4.29159C7.14726 4.10405 7.40162 3.9987 7.66683 3.9987ZM9.3335 11.332H6.66683C6.49002 11.332 6.32045 11.2618 6.19543 11.1368C6.0704 11.0117 6.00016 10.8422 6.00016 10.6654C6.00016 10.4886 6.0704 10.319 6.19543 10.194C6.32045 10.0689 6.49002 9.9987 6.66683 9.9987H7.3335V7.9987H6.66683C6.49002 7.9987 6.32045 7.92846 6.19543 7.80343C6.0704 7.67841 6.00016 7.50884 6.00016 7.33203C6.00016 7.15522 6.0704 6.98565 6.19543 6.86063C6.32045 6.7356 6.49002 6.66536 6.66683 6.66536H8.00016C8.17698 6.66536 8.34655 6.7356 8.47157 6.86063C8.59659 6.98565 8.66683 7.15522 8.66683 7.33203V9.9987H9.3335C9.51031 9.9987 9.67988 10.0689 9.8049 10.194C9.92993 10.319 10.0002 10.4886 10.0002 10.6654C10.0002 10.8422 9.92993 11.0117 9.8049 11.1368C9.67988 11.2618 9.51031 11.332 9.3335 11.332Z`}}]},ve=(0,u.forwardRef)(function(e,t){return(0,u.createElement)(X,Object.assign({},e,{id:`info-icon`,ref:t,icon:_e}))});ve.displayName=`InfoIcon`;let ye={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M8 15C11.866 15 15 11.866 15 8C15 4.13401 11.866 1 8 1C4.13401 1 1 4.13401 1 8C1 11.866 4.13401 15 8 15ZM11.7245 6.42417C11.9588 6.18985 11.9588 5.80995 11.7245 5.57564C11.4901 5.34132 11.1102 5.34132 10.8759 5.57564L7.3002 9.15137L5.72446 7.57564C5.49014 7.34132 5.11025 7.34132 4.87593 7.57564C4.64162 7.80995 4.64162 8.18985 4.87593 8.42417L6.87593 10.4242C7.11025 10.6585 7.49014 10.6585 7.72446 10.4242L11.7245 6.42417Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},be=(0,u.forwardRef)(function(e,t){return(0,u.createElement)(X,Object.assign({},e,{id:`success-icon`,ref:t,icon:ye}))});be.displayName=`SuccessIcon`;function xe(e){let a=e.get(n.SheetsFilterService);return{id:n.SmartToggleSheetsFilterCommand.id,type:i.MenuItemType.BUTTON_SELECTOR,icon:`FilterIcon`,tooltip:`sheets-filter.toolbar.smart-toggle-filter-tooltip`,hidden$:(0,i.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),activated$:a.activeFilterModel$.pipe((0,s.map)(e=>!!e)),disabled$:(0,r.getObservableWithExclusiveRange$)(e,(0,r.getCurrentRangeDisable$)(e,{worksheetTypes:[o.WorksheetFilterPermission,o.WorksheetViewPermission],rangeTypes:[o.RangeProtectionPermissionViewPoint]}))}}function Se(e){let r=e.get(n.SheetsFilterService);return{id:n.ClearSheetsFilterCriteriaCommand.id,type:i.MenuItemType.BUTTON,title:`sheets-filter.toolbar.clear-filter-criteria`,hidden$:(0,i.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:r.activeFilterModel$.pipe((0,s.switchMap)(e=>{var t;return(t=e==null?void 0:e.hasCriteria$.pipe((0,s.map)(e=>!e)))==null?(0,s.of)(!0):t}))}}function Ce(e){let r=e.get(n.SheetsFilterService);return{id:n.ReCalcSheetsFilterCommand.id,type:i.MenuItemType.BUTTON,title:`sheets-filter.toolbar.re-calc-filter-conditions`,hidden$:(0,i.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:r.activeFilterModel$.pipe((0,s.switchMap)(e=>{var t;return(t=e==null?void 0:e.hasCriteria$.pipe((0,s.map)(e=>!e)))==null?(0,s.of)(!0):t}))}}let we={[i.RibbonDataGroup.ORGANIZATION]:{[n.SmartToggleSheetsFilterCommand.id]:{order:2,menuItemFactory:xe,[n.ClearSheetsFilterCriteriaCommand.id]:{order:0,menuItemFactory:Se},[n.ReCalcSheetsFilterCommand.id]:{order:1,menuItemFactory:Ce}}}};function Te(e){let{model:n}=e,r=(0,i.useDependency)(t.LocaleService),a=(0,i.useObservable)(n.cellFillColors$,[],!0),o=(0,i.useObservable)(n.cellTextColors$,[],!0),s=(0,u.useCallback)(e=>{n.onFilterCheckToggled(e)},[n]),c=(0,u.useCallback)(e=>{n.onFilterCheckToggled(e,!1)},[n]);return(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-colors-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel`,className:(0,l.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`,l.borderClassName),children:[a.length>1&&(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white`,children:r.t(`sheets-filter.panel.filter-by-cell-fill-color`)}),(0,d.jsx)(`div`,{className:`univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2`,children:a.map((e,t)=>(0,d.jsxs)(`div`,{className:`univer-relative univer-size-6`,onClick:()=>s(e),children:[e.color?(0,d.jsx)(`button`,{type:`button`,className:(0,l.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`),style:{backgroundColor:e.color}}):(0,d.jsx)(me,{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&&(0,d.jsx)(Ee,{})]},`sheets-filter-cell-fill-color-${t}`))})]}),o.length>1&&(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white`,children:r.t(`sheets-filter.panel.filter-by-cell-text-color`)}),(0,d.jsx)(`div`,{className:`univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2`,children:o.map((e,t)=>(0,d.jsxs)(`div`,{className:`univer-relative univer-size-6`,onClick:()=>c(e),children:[(0,d.jsx)(`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:(0,d.jsx)(fe,{style:{color:e.color}})}),e.checked&&(0,d.jsx)(Ee,{})]},`sheets-filter-cell-text-color-${t}`))})]}),a.length<=1&&o.length<=1&&(0,d.jsx)(`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:r.t(`sheets-filter.panel.filter-by-color-none`)})]})})}function Ee(){return(0,d.jsx)(`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:(0,d.jsx)(be,{className:`univer-size-full univer-font-bold univer-text-[#418F1F]`})})}function De(e){var n,r;let{model:a}=e,o=(0,i.useDependency)(t.LocaleService),s=(0,i.useObservable)(a.conditionItem$,void 0),c=(0,i.useObservable)(a.filterConditionFormParams$,void 0),f=c!=null&&c.and?`AND`:`OR`,p=(0,u.useCallback)(e=>{a.onConditionFormChange({and:e===`AND`})},[a]),h=Oe(o),g=(0,u.useCallback)(e=>{a.onPrimaryConditionChange(e)},[a]),_=ke(o),v=(0,u.useCallback)(e=>{a.onConditionFormChange(e)},[a]),y=o.t(`sheets-filter.panel.input-values-placeholder`);function b(e,t,n){let r=m.getItemByOperator(e).numOfParameters===1;return(0,d.jsxs)(d.Fragment,{children:[n===`operator2`&&(0,d.jsxs)(l.RadioGroup,{value:f,onChange:p,children:[(0,d.jsx)(l.Radio,{value:`AND`,children:o.t(`sheets-filter.panel.and`)}),(0,d.jsx)(l.Radio,{value:`OR`,children:o.t(`sheets-filter.panel.or`)})]}),(0,d.jsx)(l.Select,{value:e,options:_,onChange:e=>v({[n]:e})}),r&&(0,d.jsx)(`div`,{children:(0,d.jsx)(l.Input,{className:`univer-mt-2`,value:t,placeholder:y,onChange:e=>v({[n===`operator1`?`val1`:`val2`]:e})})})]})}return(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-conditions-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:s&&c&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(l.Select,{value:s.operator,options:h,onChange:g}),m.getItemByOperator(s.operator).numOfParameters===0?null:(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel-conditions-container-inner`,className:(0,l.clsx)(`univer-mt-2 univer-flex-grow univer-overflow-hidden univer-rounded-md univer-p-2`,l.borderClassName),children:[s.numOfParameters>=1&&b(c.operator1,(n=c.val1)==null?``:n,`operator1`),s.numOfParameters>=2&&b(c.operator2,(r=c.val2)==null?``:r,`operator2`),(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel-conditions-desc`,className:`univer-mt-2 univer-text-xs univer-text-gray-500`,children:[o.t(`sheets-filter.panel.?`),(0,d.jsx)(`br`,{}),o.t(`sheets-filter.panel.*`)]})]})]})})}function Oe(e){return(0,u.useMemo)(()=>[{options:[{label:e.t(m.NONE.label),value:m.NONE.operator}]},{options:[{label:e.t(m.EMPTY.label),value:m.EMPTY.operator},{label:e.t(m.NOT_EMPTY.label),value:m.NOT_EMPTY.operator}]},{options:[{label:e.t(m.TEXT_CONTAINS.label),value:m.TEXT_CONTAINS.operator},{label:e.t(m.DOES_NOT_CONTAIN.label),value:m.DOES_NOT_CONTAIN.operator},{label:e.t(m.STARTS_WITH.label),value:m.STARTS_WITH.operator},{label:e.t(m.ENDS_WITH.label),value:m.ENDS_WITH.operator},{label:e.t(m.EQUALS.label),value:m.EQUALS.operator}]},{options:[{label:e.t(m.GREATER_THAN.label),value:m.GREATER_THAN.operator},{label:e.t(m.GREATER_THAN_OR_EQUAL.label),value:m.GREATER_THAN_OR_EQUAL.operator},{label:e.t(m.LESS_THAN.label),value:m.LESS_THAN.operator},{label:e.t(m.LESS_THAN_OR_EQUAL.label),value:m.LESS_THAN_OR_EQUAL.operator},{label:e.t(m.EQUAL.label),value:m.EQUAL.operator},{label:e.t(m.NOT_EQUAL.label),value:m.NOT_EQUAL.operator},{label:e.t(m.BETWEEN.label),value:m.BETWEEN.operator},{label:e.t(m.NOT_BETWEEN.label),value:m.NOT_BETWEEN.operator}]},{options:[{label:e.t(m.CUSTOM.label),value:m.CUSTOM.operator}]}],[e.getCurrentLocale(),e])}function ke(e){return(0,u.useMemo)(()=>m.ALL_CONDITIONS.filter(e=>e.numOfParameters!==2).map(t=>({label:e.t(t.label),value:t.operator})),[e.getCurrentLocale(),e])}function Ae(e){let{model:n}=e,r=(0,i.useDependency)(t.LocaleService),a=(0,i.useObservable)(n.searchString$,``,!0),o=(0,i.useObservable)(n.filterItems$,void 0,!0),s=r.t(`sheets-filter.panel.filter-only`),c=g(o),f=c.checked>0&&c.unchecked===0,p=c.checked>0&&c.unchecked>0,m=n.treeMapCache,h=(0,u.useCallback)(()=>{n.onCheckAllToggled(!f)},[n,f]),_=(0,u.useCallback)(e=>{n.setSearchString(e)},[n]);function v(e){let t=[];return e.forEach(e=>{e.checked&&t.push(e.key),e.children&&(t=t.concat(v(e.children)))}),t}return(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel-values-container`,className:`univer-flex univer-h-full univer-min-h-[300px] univer-flex-col`,children:[(0,d.jsx)(l.Input,{autoFocus:!0,value:a,placeholder:r.t(`sheets-filter.panel.search-placeholder`),onChange:_}),(0,d.jsxs)(`div`,{"data-u-comp":`sheets-filter-panel`,className:(0,l.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`,l.borderClassName),children:[(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-values-item`,className:`univer-box-border univer-h-8 univer-w-full univer-py-0.5`,children:(0,d.jsxs)(`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:[(0,d.jsx)(l.Checkbox,{indeterminate:p,disabled:o.length===0,checked:f,onChange:h}),(0,d.jsx)(`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:`${r.t(`sheets-filter.panel.select-all`)}`}),(0,d.jsx)(`span`,{"data-u-comp":`sheets-filter-panel-values-item-count`,className:`univer-text-gray-400 dark:!univer-text-gray-500`,children:`(${c.checked}/${c.checked+c.unchecked})`})]})}),(0,d.jsx)(`div`,{"data-u-comp":`sheets-filter-panel-values-virtual`,className:`univer-flex-grow`,children:(0,d.jsx)(l.Tree,{data:o,defaultExpandAll:!1,valueGroup:v(o),onChange:e=>{n.onFilterCheckToggled(e)},defaultCache:m,itemHeight:28,treeNodeClassName:`
2
2
  univer-pr-2 univer-border-box univer-rounded-md
3
3
  [&:hover_a]:univer-inline-block
4
4
  hover:univer-bg-gray-50 univer-h-full
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-filter-ui",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "private": false,
5
5
  "description": "Univer Sheets Filter UI",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -53,14 +53,14 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@univerjs/icons": "^1.1.1",
56
- "@univerjs/core": "0.19.0",
57
- "@univerjs/design": "0.19.0",
58
- "@univerjs/engine-render": "0.19.0",
59
- "@univerjs/rpc": "0.19.0",
60
- "@univerjs/sheets": "0.19.0",
61
- "@univerjs/sheets-ui": "0.19.0",
62
- "@univerjs/ui": "0.19.0",
63
- "@univerjs/sheets-filter": "0.19.0"
56
+ "@univerjs/core": "0.20.0",
57
+ "@univerjs/design": "0.20.0",
58
+ "@univerjs/engine-render": "0.20.0",
59
+ "@univerjs/rpc": "0.20.0",
60
+ "@univerjs/sheets": "0.20.0",
61
+ "@univerjs/sheets-filter": "0.20.0",
62
+ "@univerjs/sheets-ui": "0.20.0",
63
+ "@univerjs/ui": "0.20.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "postcss": "^8.5.8",
@@ -69,8 +69,8 @@
69
69
  "tailwindcss": "3.4.18",
70
70
  "typescript": "^6.0.2",
71
71
  "vitest": "^4.1.1",
72
- "@univerjs-infra/shared": "0.19.0",
73
- "@univerjs/engine-formula": "0.19.0"
72
+ "@univerjs-infra/shared": "0.20.0",
73
+ "@univerjs/engine-formula": "0.20.0"
74
74
  },
75
75
  "scripts": {
76
76
  "test": "vitest run",