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