@univerjs/preset-sheets-filter 0.10.10 → 0.10.11
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/index.css +1 -1
- package/lib/umd/index.js +3 -3
- package/package.json +7 -7
package/lib/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.univer-absolute{position:absolute}.univer-relative{position:relative}.-univer-bottom-0\.5{bottom:-.125rem}.-univer-right-0\.5{right:-.125rem}.univer-mx-1{margin-left:.25rem;margin-right:.25rem}.univer-mb-1{margin-bottom:.25rem}.univer-mb-2{margin-bottom:.5rem}.univer-ml-1{margin-left:.25rem}.univer-mt-2{margin-top:.5rem}.univer-mt-4{margin-top:1rem}.univer-box-border{box-sizing:border-box}.univer-block{display:block}.univer-inline-block{display:inline-block}.univer-flex{display:flex}.univer-inline-flex{display:inline-flex}.univer-grid{display:grid}.univer-hidden{display:none}.univer-h-3{height:.75rem}.univer-h-4{height:1rem}.univer-h-5{height:1.25rem}.univer-h-6{height:1.5rem}.univer-h-7{height:1.75rem}.univer-h-8{height:2rem}.univer-h-\[300px\]{height:300px}.univer-h-full{height:100%}.univer-max-h-\[500px\]{max-height:500px}.univer-min-h-\[300px\]{min-height:300px}.univer-w-3{width:.75rem}.univer-w-6{width:1.5rem}.univer-w-\[400px\]{width:400px}.univer-w-full{width:100%}.univer-flex-1{flex:1 1 0%}.univer-flex-shrink{flex-shrink:1}.univer-flex-shrink-0{flex-shrink:0}.univer-flex-grow{flex-grow:1}.univer-flex-grow-0{flex-grow:0}.univer-cursor-pointer{cursor:pointer}.univer-grid-cols-8{grid-template-columns:repeat(8,minmax(0,1fr))}.univer-flex-col{flex-direction:column}.univer-flex-nowrap{flex-wrap:nowrap}.univer-items-center{align-items:center}.univer-justify-start{justify-content:flex-start}.univer-justify-center{justify-content:center}.univer-justify-between{justify-content:space-between}.univer-gap-1{gap:.25rem}.univer-gap-2{gap:.5rem}.univer-gap-4{gap:1rem}.univer-overflow-auto{overflow:auto}.univer-overflow-hidden{overflow:hidden}.univer-text-ellipsis{text-overflow:ellipsis}.univer-whitespace-nowrap{white-space:nowrap}.univer-rounded-full{border-radius:9999px}.univer-rounded-lg{border-radius:.5rem}.univer-rounded-md{border-radius:.375rem}.univer-border{border-width:1px}.univer-border-solid{border-style:solid}.univer-border-\[rgba\(13\,13\,13\,0\.06\)\]{border-color:#0d0d0d0f}.univer-border-transparent{border-color:transparent}.univer-bg-gray-300{background-color:var(--univer-gray-300)}.univer-bg-white{background-color:var(--univer-white)}.univer-p-0\.5{padding:.125rem}.univer-p-2{padding:.5rem}.univer-p-4{padding:1rem}.univer-px-1\.5{padding-left:.375rem;padding-right:.375rem}.univer-px-2{padding-left:.5rem;padding-right:.5rem}.univer-py-0\.5{padding-top:.125rem;padding-bottom:.125rem}.univer-py-2\.5{padding-top:.625rem;padding-bottom:.625rem}.univer-pb-0{padding-bottom:0}.univer-pl-5{padding-left:1.25rem}.univer-pr-0\.5{padding-right:.125rem}.univer-pr-2{padding-right:.5rem}.univer-pt-0{padding-top:0}.univer-pt-2{padding-top:.5rem}.univer-text-sm{font-size:.875rem;line-height:1.25rem}.univer-text-xs{font-size:.75rem;line-height:1rem}.univer-font-bold{font-weight:700}.univer-text-\[\#418F1F\]{--univer-tw-text-opacity: 1;color:#418f1f;color:rgba(65,143,31,var(--univer-tw-text-opacity, 1))}.univer-text-gray-400{color:var(--univer-gray-400)}.univer-text-gray-500{color:var(--univer-gray-500)}.univer-text-gray-900{color:var(--univer-gray-900)}.univer-text-primary-500{color:var(--univer-primary-500)}.univer-shadow-lg{--univer-tw-shadow: 0px 4px 6px 0px rgba(30, 40, 77, .05), 0px 10px 15px -3px rgba(30, 40, 77, .1);--univer-tw-shadow-colored: 0px 4px 6px 0px var(--univer-tw-shadow-color), 0px 10px 15px -3px var(--univer-tw-shadow-color);box-shadow:0 0 #0000,0 0 #0000,0 4px 6px #1e284d0d,0 10px 15px -3px #1e284d1a;box-shadow:var(--univer-tw-ring-offset-shadow, 0 0 rgba(0,0,0,0)),var(--univer-tw-ring-shadow, 0 0 rgba(0,0,0,0)),var(--univer-tw-shadow)}.univer-transition-shadow{transition-property:box-shadow;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.hover\:univer-bg-gray-50:hover{background-color:var(--univer-gray-50)}.hover\:univer-ring-2:hover{--univer-tw-ring-offset-shadow: var(--univer-tw-ring-inset) 0 0 0 var(--univer-tw-ring-offset-width) var(--univer-tw-ring-offset-color);--univer-tw-ring-shadow: var(--univer-tw-ring-inset) 0 0 0 calc(2px + var(--univer-tw-ring-offset-width)) var(--univer-tw-ring-color);box-shadow:var(--univer-tw-ring-offset-shadow),var(--univer-tw-ring-shadow),0 0 #0000;box-shadow:var(--univer-tw-ring-offset-shadow),var(--univer-tw-ring-shadow),var(--univer-tw-shadow, 0 0 rgba(0,0,0,0))}.hover\:univer-ring-offset-2:hover{--univer-tw-ring-offset-width: 2px }.hover\:univer-ring-offset-white:hover{--univer-tw-ring-offset-color: var(--univer-white) }.dark\:\!univer-border-\[rgba\(255\,255\,255\,0\.06\)\]:where(.univer-dark,.univer-dark *){border-color:#ffffff0f!important}.dark\:\!univer-border-gray-600:where(.univer-dark,.univer-dark *){border-color:var(--univer-gray-600)!important}.dark\:\!univer-bg-gray-700:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-700)!important}.dark\:\!univer-text-gray-200:where(.univer-dark,.univer-dark *){color:var(--univer-gray-200)!important}.dark\:\!univer-text-gray-500:where(.univer-dark,.univer-dark *){color:var(--univer-gray-500)!important}.dark\:\!univer-text-white:where(.univer-dark,.univer-dark *){color:var(--univer-white)!important}.dark\:
|
|
1
|
+
.univer-absolute{position:absolute}.univer-relative{position:relative}.-univer-bottom-0\.5{bottom:-.125rem}.-univer-right-0\.5{right:-.125rem}.univer-mx-1{margin-left:.25rem;margin-right:.25rem}.univer-mb-1{margin-bottom:.25rem}.univer-mb-2{margin-bottom:.5rem}.univer-ml-1{margin-left:.25rem}.univer-mt-2{margin-top:.5rem}.univer-mt-4{margin-top:1rem}.univer-box-border{box-sizing:border-box}.univer-block{display:block}.univer-inline-block{display:inline-block}.univer-flex{display:flex}.univer-inline-flex{display:inline-flex}.univer-grid{display:grid}.univer-hidden{display:none}.univer-h-3{height:.75rem}.univer-h-4{height:1rem}.univer-h-5{height:1.25rem}.univer-h-6{height:1.5rem}.univer-h-7{height:1.75rem}.univer-h-8{height:2rem}.univer-h-\[300px\]{height:300px}.univer-h-full{height:100%}.univer-max-h-\[500px\]{max-height:500px}.univer-min-h-\[300px\]{min-height:300px}.univer-w-3{width:.75rem}.univer-w-6{width:1.5rem}.univer-w-\[400px\]{width:400px}.univer-w-full{width:100%}.univer-flex-1{flex:1 1 0%}.univer-flex-shrink{flex-shrink:1}.univer-flex-shrink-0{flex-shrink:0}.univer-flex-grow{flex-grow:1}.univer-flex-grow-0{flex-grow:0}.univer-cursor-pointer{cursor:pointer}.univer-grid-cols-8{grid-template-columns:repeat(8,minmax(0,1fr))}.univer-flex-col{flex-direction:column}.univer-flex-nowrap{flex-wrap:nowrap}.univer-items-center{align-items:center}.univer-justify-start{justify-content:flex-start}.univer-justify-center{justify-content:center}.univer-justify-between{justify-content:space-between}.univer-gap-1{gap:.25rem}.univer-gap-2{gap:.5rem}.univer-gap-4{gap:1rem}.univer-overflow-auto{overflow:auto}.univer-overflow-hidden{overflow:hidden}.univer-text-ellipsis{text-overflow:ellipsis}.univer-whitespace-nowrap{white-space:nowrap}.univer-rounded-full{border-radius:9999px}.univer-rounded-lg{border-radius:.5rem}.univer-rounded-md{border-radius:.375rem}.univer-border{border-width:1px}.univer-border-solid{border-style:solid}.univer-border-\[rgba\(13\,13\,13\,0\.06\)\]{border-color:#0d0d0d0f}.univer-border-transparent{border-color:transparent}.univer-bg-gray-300{background-color:var(--univer-gray-300)}.univer-bg-white{background-color:var(--univer-white)}.univer-p-0\.5{padding:.125rem}.univer-p-2{padding:.5rem}.univer-p-4{padding:1rem}.univer-px-1\.5{padding-left:.375rem;padding-right:.375rem}.univer-px-2{padding-left:.5rem;padding-right:.5rem}.univer-py-0\.5{padding-top:.125rem;padding-bottom:.125rem}.univer-py-2\.5{padding-top:.625rem;padding-bottom:.625rem}.univer-pb-0{padding-bottom:0}.univer-pl-5{padding-left:1.25rem}.univer-pr-0\.5{padding-right:.125rem}.univer-pr-2{padding-right:.5rem}.univer-pt-0{padding-top:0}.univer-pt-2{padding-top:.5rem}.univer-text-sm{font-size:.875rem;line-height:1.25rem}.univer-text-xs{font-size:.75rem;line-height:1rem}.univer-font-bold{font-weight:700}.univer-text-\[\#418F1F\]{--univer-tw-text-opacity: 1;color:#418f1f;color:rgba(65,143,31,var(--univer-tw-text-opacity, 1))}.univer-text-gray-400{color:var(--univer-gray-400)}.univer-text-gray-500{color:var(--univer-gray-500)}.univer-text-gray-900{color:var(--univer-gray-900)}.univer-text-primary-500{color:var(--univer-primary-500)}.univer-shadow-lg{--univer-tw-shadow: 0px 4px 6px 0px rgba(30, 40, 77, .05), 0px 10px 15px -3px rgba(30, 40, 77, .1);--univer-tw-shadow-colored: 0px 4px 6px 0px var(--univer-tw-shadow-color), 0px 10px 15px -3px var(--univer-tw-shadow-color);box-shadow:0 0 #0000,0 0 #0000,0 4px 6px #1e284d0d,0 10px 15px -3px #1e284d1a;box-shadow:var(--univer-tw-ring-offset-shadow, 0 0 rgba(0,0,0,0)),var(--univer-tw-ring-shadow, 0 0 rgba(0,0,0,0)),var(--univer-tw-shadow)}.univer-transition-shadow{transition-property:box-shadow;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.hover\:univer-bg-gray-50:hover{background-color:var(--univer-gray-50)}.hover\:univer-ring-2:hover{--univer-tw-ring-offset-shadow: var(--univer-tw-ring-inset) 0 0 0 var(--univer-tw-ring-offset-width) var(--univer-tw-ring-offset-color);--univer-tw-ring-shadow: var(--univer-tw-ring-inset) 0 0 0 calc(2px + var(--univer-tw-ring-offset-width)) var(--univer-tw-ring-color);box-shadow:var(--univer-tw-ring-offset-shadow),var(--univer-tw-ring-shadow),0 0 #0000;box-shadow:var(--univer-tw-ring-offset-shadow),var(--univer-tw-ring-shadow),var(--univer-tw-shadow, 0 0 rgba(0,0,0,0))}.hover\:univer-ring-offset-2:hover{--univer-tw-ring-offset-width: 2px }.hover\:univer-ring-offset-white:hover{--univer-tw-ring-offset-color: var(--univer-white) }.dark\:\!univer-border-\[rgba\(255\,255\,255\,0\.06\)\]:where(.univer-dark,.univer-dark *){border-color:#ffffff0f!important}.dark\:\!univer-border-gray-600:where(.univer-dark,.univer-dark *){border-color:var(--univer-gray-600)!important}.dark\:\!univer-bg-gray-700:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-700)!important}.dark\:\!univer-text-gray-200:where(.univer-dark,.univer-dark *){color:var(--univer-gray-200)!important}.dark\:\!univer-text-gray-500:where(.univer-dark,.univer-dark *){color:var(--univer-gray-500)!important}.dark\:\!univer-text-white:where(.univer-dark,.univer-dark *){color:var(--univer-white)!important}.dark\:hover\:\!univer-bg-gray-900:hover:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-900)!important}.\[\&\:hover_a\]\:univer-inline-block:hover a{display:inline-block}
|
package/lib/umd/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @univerjs/sheets-filter/index
|
|
2
|
-
(function(h,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-render"),require("@univerjs/rpc"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-render","@univerjs/rpc","@univerjs/engine-formula"],d):(h=typeof globalThis<"u"?globalThis:h||self,d(h.UniverSheetsFilter={},h.UniverCore,h.UniverSheets,h.rxjs,h.UniverEngineRender,h.UniverRpc,h.UniverEngineFormula))})(this,(function(h,d,_,I,Re,ve,J){"use strict";var et=Object.defineProperty;var tt=(h,d,_)=>d in h?et(h,d,{enumerable:!0,configurable:!0,writable:!0,value:_}):h[d]=_;var v=(h,d,_)=>tt(h,typeof d!="symbol"?d+"":d,_);var x;const K="sheet.mutation.set-filter-range",Z="sheet.mutation.set-filter-criteria",Y="sheet.mutation.remove-filter",X="sheet.mutation.re-calc-filter",H=new Set([K,Z,Y,X]);var N=(i=>(i[i.VALUES=0]="VALUES",i[i.COLORS=1]="COLORS",i[i.CONDITIONS=2]="CONDITIONS",i))(N||{}),A=(i=>(i.EQUAL="equal",i.GREATER_THAN="greaterThan",i.GREATER_THAN_OR_EQUAL="greaterThanOrEqual",i.LESS_THAN="lessThan",i.LESS_THAN_OR_EQUAL="lessThanOrEqual",i.NOT_EQUALS="notEqual",i))(A||{});const ee={operator:A.GREATER_THAN,fn:(i,n)=>U(i)?i>n:!1},te={operator:A.GREATER_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i>=n:!1},re={operator:A.LESS_THAN,fn:(i,n)=>U(i)?i<n:!1},ne={operator:A.LESS_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i<=n:!1},ie={operator:A.EQUAL,fn:(i,n)=>U(i)?i===n:!1},z={operator:A.NOT_EQUALS,fn:(i,n)=>{if(typeof n=="string"){if(n===" ")return i!=null;const e=le(i);return e&&we(n)?!ae(n).test(e):e!==n}return U(i)?i!==n:!0}},se=new Map([]);[ee,te,re,ne,ie,z].forEach(i=>{se.set(i.operator,i)});function Fe(i){return!!i}const pe={fn:(i,n)=>{const e=le(i);return e===null?n==="":ae(n).test(e)}};function V(i){return i?se.get(i):pe}function U(i){return typeof i=="number"}function oe(i){return!!(typeof i=="number"||typeof i=="string"&&d.isNumeric(i))}function le(i){return typeof i=="boolean"||i==null?null:typeof i=="string"?i:i.toString()}function we(i){return typeof i=="number"?!1:i.indexOf("*")!==-1||i.indexOf("?")!==-1}function ae(i){const n=i.replace(/[.+^${}()|[\]\\]/g,"\\$&").replaceAll("?",".").replace(/[*]/g,".$&");return new RegExp(`^${n}$`)}const W=()=>new Set;class P extends d.Disposable{constructor(e,t,r){super();v(this,"_filteredOutRows$",new I.BehaviorSubject(W()));v(this,"filteredOutRows$",this._filteredOutRows$.asObservable());v(this,"_hasCriteria$",new I.BehaviorSubject(!1));v(this,"hasCriteria$",this._hasCriteria$.asObservable());v(this,"_filterColumnByIndex",new Map);v(this,"_alreadyFilteredOutRows",W());v(this,"_range");this.unitId=e,this.subUnitId=t,this._worksheet=r}get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete()}serialize(){const e={ref:d.Rectangle.clone(this._range),filterColumns:this._getAllFilterColumns(!0).sort(([t],[r])=>t-r).map(([t,r])=>r.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(e,t,r,s){const o=new P(e,t,r);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.forEach(r=>this._setCriteriaWithoutReCalc(r.colId,r)),e.cachedFilteredOut&&(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw new Error("[FilterModel] could not get range before a range is set!");return this._range}getFilteredOutRowsExceptCol(e){return this._getAllFilterColumns(!0).filter(([t])=>t!==e).reduce((t,[,r])=>{const s=r.calc({getAlreadyFilteredOutRows:()=>t});return s?d.mergeSets(t,s):t},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,r])=>{r.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,r=!1){if(!this._range)throw new Error("[FilterModel] could not set criteria before a range is set!");if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),r&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),r&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))!=null?t:null}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){const t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([r,s])=>s)}_reCalcAllColumns(){this._alreadyFilteredOutRows=W(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns()}_setCriteriaWithoutReCalc(e,t){const r=this._range;if(!r)throw new Error("[FilterModel] could not set criteria before a range is set!");const{startColumn:s,endColumn:o}=r;if(e>o||e<s)throw new Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);let l;this._filterColumnByIndex.has(e)?l=this._filterColumnByIndex.get(e):(l=new de(this.unitId,this.subUnitId,this._worksheet,t,{getAlreadyFilteredOutRows:()=>this._alreadyFilteredOutRows}),l.setRangeAndColumn(r,e),this._filterColumnByIndex.set(e,l)),l.setCriteria(t)}_removeCriteria(e){const t=this._filterColumnByIndex.get(e);t&&(t.dispose(),this._filterColumnByIndex.delete(e))}_emit(){this._filteredOutRows$.next(this._alreadyFilteredOutRows)}_emitHasCriteria(){this._hasCriteria$.next(this._filterColumnByIndex.size>0)}_rebuildAlreadyFilteredOutRowsWithCache(){const e=this._getAllFilterColumns().filter(t=>t.hasCache()).reduce((t,r)=>d.mergeSets(t,r.filteredOutRows),new Set);this._alreadyFilteredOutRows=e}_reCalcWithNoCacheColumns(){const e=this._getAllFilterColumns().filter(t=>!t.hasCache());for(const t of e){const r=t.reCalc();r&&(this._alreadyFilteredOutRows=d.mergeSets(this._alreadyFilteredOutRows,r))}}}class de extends d.Disposable{constructor(e,t,r,s,o){super();v(this,"_filteredOutRows",null);v(this,"_filterFn",null);v(this,"_range",null);v(this,"_column",0);v(this,"_filterBy",N.VALUES);this.unitId=e,this.subUnitId=t,this._worksheet=r,this._criteria=s,this._filterColumnContext=o}get filteredOutRows(){return this._filteredOutRows}get filterBy(){return this._filterBy}dispose(){super.dispose(),this._filteredOutRows=null}__clearCache(){this._filteredOutRows=null}serialize(){if(!this._criteria)throw new Error("[FilterColumn]: could not serialize without a filter column!");return d.Tools.deepClone({...this._criteria,colId:this._column})}hasCache(){return this._filteredOutRows!==null}setRangeAndColumn(e,t){this._range=e,this._column=t}setCriteria(e){this._criteria=e,this._generateFilterFn(),this._filteredOutRows=null}getColumnData(){return d.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw new Error("[FilterColumn] cannot calculate without a filter fn!");if(!this._range)throw new Error("[FilterColumn] cannot calculate without a range!");if(typeof this._column!="number")throw new TypeError("[FilterColumn] cannot calculate without a column offset!");const t=this._column,r={startColumn:t,endColumn:t,startRow:this._range.startRow+1,endRow:this._range.endRow},s=new Set,o=e.getAlreadyFilteredOutRows();for(const l of this._worksheet.iterateByColumn(r,!1,!1)){const{row:a,rowSpan:c,col:m}=l;if(o.has(a)&&(!c||c===1))continue;if(!(this._filterBy===N.VALUES?this._filterFn(d.extractPureTextFromCell(this._worksheet.getCell(a,m))):this._filterBy===N.COLORS?this._filterFn(this._worksheet.getComposedCellStyle(a,m)):this._filterFn(be(this._worksheet,a,m)))&&(s.add(a),c))for(let f=1;f<c;f++)s.add(a+f)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=Me(this._criteria),this._filterBy=this._criteria.filters?N.VALUES:this._criteria.colorFilters?N.COLORS:N.CONDITIONS)}}function Me(i){if(i.filters)return Ee(i.filters);if(i.colorFilters)return ye(i.colorFilters);if(i.customFilters)return Oe(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function Ee(i){const n=!!i.blank,e=new Set(i.filters);return t=>t===void 0||t===""?n:e.has(typeof t=="string"?t:`${t}`)}function ye(i){if(i.cellFillColors){const n=new Set(i.cellFillColors);return e=>{var r;if(!e||!((r=e.bg)!=null&&r.rgb))return!!n.has(null);const t=new d.ColorKit(e.bg.rgb).toRgbString();return n.has(t)}}if(i.cellTextColors){const n=new Set(i.cellTextColors);return e=>{var r;if(!e||!((r=e.cl)!=null&&r.rgb))return!!n.has(Re.COLOR_BLACK_RGB);const t=new d.ColorKit(e.cl.rgb).toRgbString();return n.has(t)}}throw new Error("[FilterModel]: color filters are not supported yet.")}function Oe(i){const n=i.customFilters.map(e=>Ne(e));return Ae(n)?i.and?Ie(n):Te(n):n[0]}function Ie(i){const[n,e]=i;return t=>n(t)&&e(t)}function Te(i){const[n,e]=i;return t=>n(t)||e(t)}function Ae(i){return i.length===2}function Ne(i){const n=i.val;if(i.operator===A.NOT_EQUALS&&!oe(n))return r=>z.fn(r,n);if(Fe(i.operator)){if(!oe(n))return()=>!1;const r=V(i.operator),s=Number(n);return o=>r.fn(o,s)}const e=V(i.operator);return t=>e.fn(t,n)}function be(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?ce(t):r?t.t===d.CellValueType.NUMBER&&typeof t.v=="string"?r.v:t.t===d.CellValueType.NUMBER?Number(r.v):ce(r):null}function ce(i){var t,r;const n=(r=(t=i.p)==null?void 0:t.body)==null?void 0:r.dataStream;if(n)return n.trimEnd();const e=i.v;return typeof e=="string"?i.t===d.CellValueType.BOOLEAN?e.toUpperCase():e:typeof e=="number"?i.t===d.CellValueType.BOOLEAN?e?"TRUE":"FALSE":e:typeof e=="boolean"?e?"TRUE":"FALSE":""}var Ue=Object.getOwnPropertyDescriptor,$e=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ue(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},q=(i,n)=>(e,t)=>n(e,t,i);const k="SHEET_FILTER_PLUGIN";h.SheetsFilterService=class extends d.Disposable{constructor(e,t,r){super();v(this,"_filterModels",new Map);v(this,"_loadedUnitId$",new I.BehaviorSubject(null));v(this,"loadedUnitId$",this._loadedUnitId$.asObservable());v(this,"_errorMsg$",new I.BehaviorSubject(null));v(this,"errorMsg$",this._errorMsg$.asObservable());v(this,"_activeFilterModel$",new I.BehaviorSubject(null));v(this,"activeFilterModel$",this._activeFilterModel$.asObservable());this._resourcesManagerService=e,this._univerInstanceService=t,this._commandService=r,this._initModel(),this._initActiveFilterModel()}get activeFilterModel(){return this._activeFilterModel$.getValue()}ensureFilterModel(e,t){const r=this.getFilterModel(e,t);if(r)return r;const s=this._univerInstanceService.getUniverSheetInstance(e);if(!s)throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${e}!`);const o=s.getSheetBySheetId(t);if(!o)throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${t}!`);const l=new P(e,t,o);return this._cacheFilterModel(e,t,l),l}getFilterModel(e,t){var r,s;return(s=(r=this._filterModels.get(e))==null?void 0:r.get(t))!=null?s:null}removeFilterModel(e,t){const r=this.getFilterModel(e,t);return r?(r.dispose(),this._filterModels.get(e).delete(t),!0):!1}setFilterErrorMsg(e){this._errorMsg$.next(e)}_updateActiveFilterModel(){let e;try{if(e=this._univerInstanceService.getCurrentUnitForType(d.UniverInstanceType.UNIVER_SHEET),!e){this._activeFilterModel$.next(null);return}}catch(l){console.error("[SheetsFilterService]: could not get active workbook!",l);return}const t=e.getActiveSheet(!0);if(!t){this._activeFilterModel$.next(null);return}const r=t.getUnitId(),s=t.getSheetId(),o=this.getFilterModel(r,s);this._activeFilterModel$.next(o)}_initActiveFilterModel(){this.disposeWithMe(I.merge(d.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([e])=>e.type===d.CommandType.MUTATION&&H.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(e=>{var t;return(t=e==null?void 0:e.activeSheet$)!=null?t:I.of(null)}))).subscribe(()=>this._updateActiveFilterModel()))}_serializeAutoFiltersForUnit(e){const t=this._filterModels.get(e);if(!t)return"{}";const r={};return t.forEach((s,o)=>{r[o]=s.serialize()}),JSON.stringify(r)}_deserializeAutoFiltersForUnit(e,t){const r=this._univerInstanceService.getUniverSheetInstance(e);Object.keys(t).forEach(s=>{const o=t[s],l=P.deserialize(e,s,r.getSheetBySheetId(s),o);this._cacheFilterModel(e,s,l)})}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:k,businesses:[d.UniverInstanceType.UNIVER_SHEET],toJson:e=>this._serializeAutoFiltersForUnit(e),parseJson:e=>JSON.parse(e),onLoad:(e,t)=>{this._deserializeAutoFiltersForUnit(e,t),this._loadedUnitId$.next(e),this._updateActiveFilterModel()},onUnLoad:e=>{const t=this._filterModels.get(e);t&&(t.forEach(r=>r.dispose()),this._filterModels.delete(e))}})}_cacheFilterModel(e,t,r){this._filterModels.has(e)||this._filterModels.set(e,new Map),this._filterModels.get(e).set(t,r)}},h.SheetsFilterService=$e([q(0,d.IResourceManagerService),q(1,d.IUniverInstanceService),q(2,d.ICommandService)],h.SheetsFilterService);const F={id:K,type:d.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,range:r}=n;return i.get(h.SheetsFilterService).ensureFilterModel(t,e).setRange(r),!0}},p={id:Z,type:d.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,criteria:r,col:s,reCalc:o=!0}=n,a=i.get(h.SheetsFilterService).getFilterModel(t,e);return a?(a.setCriteria(s,r,o),!0):!1}},T={id:Y,type:d.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(h.SheetsFilterService).removeFilterModel(e,t)}},$={id:X,type:d.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n,s=i.get(h.SheetsFilterService).getFilterModel(e,t);return s?(s.reCalc(),!0):!1}},ue={id:"sheet.command.set-filter-range",type:d.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(d.ICommandService),r=i.get(d.IUndoRedoService),s=i.get(d.IUniverInstanceService),{unitId:o,subUnitId:l,range:a}=n;if(!_.getSheetCommandTarget(s,n)||e.getFilterModel(o,l))return!1;if(a.endRow===a.startRow){const S=i.get(d.ErrorService),R=i.get(d.LocaleService);return S.emit(R.t("sheets-filter.command.not-valid-filter-range")),!1}const u={id:F.id,params:{unitId:o,subUnitId:l,range:a}},f=t.syncExecuteCommand(u.id,u.params);return f&&r.pushUndoRedo({unitID:o,undoMutations:[{id:T.id,params:{unitId:o,subUnitId:l}}],redoMutations:[u]}),f}},he={id:"sheet.command.remove-sheet-filter",type:d.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(d.IUniverInstanceService),t=i.get(h.SheetsFilterService),r=i.get(d.ICommandService),s=i.get(d.IUndoRedoService),o=_.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,c=t.getFilterModel(l,a);if(!c)return!1;const m=c==null?void 0:c.serialize(),u=je(l,a,m),f=r.syncExecuteCommand(T.id,{unitId:l,subUnitId:a});return f&&s.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:[{id:T.id,params:{unitId:l,subUnitId:a}}]}),f}},Le={id:"sheet.command.smart-toggle-filter",type:d.CommandType.COMMAND,handler:async i=>{const n=i.get(d.IUniverInstanceService),e=i.get(h.SheetsFilterService),t=i.get(d.ICommandService),r=n.getCurrentUnitForType(d.UniverInstanceType.UNIVER_SHEET),s=r==null?void 0:r.getActiveSheet();if(!s||!r)return!1;const o=r.getUnitId(),l=s.getSheetId();if(e.getFilterModel(o,l))return t.executeCommand(he.id,{unitId:o,subUnitId:l});const m=i.get(_.SheetsSelectionsService).getCurrentLastSelection();if(!m)return!1;const u=m.range,f=_.isSingleCellSelection(m)?_.expandToContinuousRange(u,{left:!0,right:!0,up:!0,down:!0},s):u;return t.executeCommand(ue.id,{unitId:o,subUnitId:l,range:f})}},Pe={id:"sheet.command.set-filter-criteria",type:d.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(d.ICommandService),r=i.get(d.IUndoRedoService),{unitId:s,subUnitId:o,col:l,criteria:a}=n,c=e.getFilterModel(s,o);if(!c)return!1;const m=c.getRange();if(!m||l<m.startColumn||l>m.endColumn)return!1;const u=c.getFilterColumn(l),f=He(s,o,l,u),S={id:p.id,params:{unitId:s,subUnitId:o,col:l,criteria:a}},R=t.syncExecuteCommand(S.id,S.params);return R&&r.pushUndoRedo({unitID:s,undoMutations:[f],redoMutations:[S]}),R}},De={id:"sheet.command.clear-filter-criteria",type:d.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(d.IUndoRedoService),r=i.get(d.ICommandService),s=i.get(d.IUniverInstanceService),o=_.getSheetCommandTarget(s,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,c=e.getFilterModel(o.unitId,o.subUnitId);if(!c)return!1;const m=c.serialize(),u=me(l,a,m),f=xe(l,a,m);return d.sequenceExecute(f,r).result?(t.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:f}),!0):!1}},Be={id:"sheet.command.re-calc-filter",type:d.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(d.ICommandService),r=i.get(d.IUniverInstanceService),s=_.getSheetCommandTarget(r,n);if(!s)return!1;const{unitId:o,subUnitId:l}=s;return e.getFilterModel(s.unitId,s.subUnitId)?t.executeCommand($.id,{unitId:o,subUnitId:l}):!1}};function je(i,n,e){const t=[],r={id:F.id,params:{unitId:i,subUnitId:n,range:e.ref}};return t.push(r),me(i,n,e).forEach(o=>t.push(o)),t}function me(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:s}};t.push(o)}),t}function xe(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:null}};t.push(o)}),t}function He(i,n,e,t){if(!t)return{id:p.id,params:{unitId:i,subUnitId:n,col:e,criteria:null}};const r=t.serialize();return{id:p.id,params:{unitId:i,subUnitId:n,col:e,criteria:r}}}const fe="sheets-filter.config",ge={};function ze(i,n){for(let e=0;e<i.length;e++){let t=e;if(i[e])for(let r=e+1;r<i.length;r++)i[t]&&i[r]&&n(i[t],i[r])&&(i[t]=null,t=r)}return i.filter(e=>e!==null)}function L(i){return ze(i,(n,e)=>n.id===p.id&&e.id===p.id&&n.params.unitId===e.params.unitId&&n.params.subUnitId===e.params.subUnitId&&n.params.col===e.params.col)}var Ve=Object.getOwnPropertyDescriptor,We=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ve(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},b=(i,n)=>(e,t)=>n(e,t,i);let D=class extends d.Disposable{constructor(n,e,t,r,s,o,l){super();v(this,"_disposableCollection",new d.DisposableCollection);this._commandService=n,this._sheetInterceptorService=e,this._sheetsFilterService=t,this._univerInstanceService=r,this._refRangeService=s,this._dataSyncPrimaryController=o,this._zebraCrossingCacheController=l,this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener(),this._initErrorHandling(),this._initZebraCrossingCacheListener()}_initZebraCrossingCacheListener(){this.disposeWithMe(this._sheetsFilterService.activeFilterModel$.subscribe(n=>{n&&this.disposeWithMe(n.filteredOutRows$.subscribe(()=>{this._zebraCrossingCacheController.updateZebraCrossingCache(n.unitId,n.subUnitId)}))}))}_initCommands(){[p,F,$,T].forEach(n=>{var e;this.disposeWithMe(this._commandService.registerCommand(n)),(e=this._dataSyncPrimaryController)==null||e.registerSyncingMutations(n)})}_initInterceptors(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>this._getUpdateFilter(n)})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===_.SetWorksheetActiveOperation.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(r,t)}if(n.id===F.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(e.unitId,e.subUnitId)}})),this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe(n=>{if(n){const e=this._univerInstanceService.getUniverSheetInstance(n),t=e==null?void 0:e.getActiveSheet();t&&this._registerRefRange(n,t.getSheetId())}}))}_registerRefRange(n,e){var l;this._disposableCollection.dispose();const t=this._univerInstanceService.getUniverSheetInstance(n),r=t==null?void 0:t.getSheetBySheetId(e);if(!t||!r)return;const s=(l=this._sheetsFilterService.getFilterModel(n,e))==null?void 0:l.getRange(),o=a=>{switch(a.id){case _.InsertRowCommand.id:{const c=a.params,m=c.unitId||n,u=c.subUnitId||e;return this._handleInsertRowCommand(c,m,u)}case _.InsertColCommand.id:{const c=a.params,m=c.unitId||n,u=c.subUnitId||e;return this.handleInsertColCommand(c.range,m,u)}case _.RemoveColCommand.id:{const c=a.params;return this.handleRemoveColCommand(c.range,n,e)}case _.RemoveRowCommand.id:{const c=a.params;return this._handleRemoveRowCommand(c,n,e)}case _.EffectRefRangId.MoveColsCommandId:{const c=a.params;return this.handleMoveColsCommand({fromRange:c.fromRange,toRange:c.toRange},n,e)}case _.EffectRefRangId.MoveRowsCommandId:{const c=a.params;return this._handleMoveRowsCommand(c,n,e)}case _.MoveRangeCommand.id:{const c=a.params;return this._handleMoveRangeCommand(c,n,e)}}return{redos:[],undos:[]}};s&&this._disposableCollection.add(this._refRangeService.registerRefRange(s,o,n,e))}_getUpdateFilter(n){const{id:e}=n;switch(e){case _.RemoveSheetCommand.id:{const t=n.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case _.CopySheetCommand.id:{const t=n.params,{targetSubUnitId:r,unitId:s,subUnitId:o}=t;return!s||!o||!r?this._handleNull():this._handleCopySheetCommand(s,o,r)}}return{redos:[],undos:[]}}handleInsertColCommand(n,e,t){var g;const r=this._sheetsFilterService.getFilterModel(e,t),s=(g=r==null?void 0:r.getRange())!=null?g:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:a,endColumn:c}=n,m=c-a+1;if(c>l)return this._handleNull();const u=[],f=[],S=a,R={unitId:e,subUnitId:t,range:{...s,startColumn:a<=o?o+m:o,endColumn:l+m}},w={unitId:e,subUnitId:t,range:s};u.push({id:F.id,params:R}),f.push({id:F.id,params:w});const M=r.getAllFilterColumns().filter(C=>C[0]>=S);if(M.length!==0){const{newRange:C,oldRange:y}=this._moveCriteria(e,t,M,m);u.push(...y.redos,...C.redos),f.push(...C.undos,...y.undos)}return{redos:L(u),undos:L(f)}}_handleInsertRowCommand(n,e,t){var w;const r=this._sheetsFilterService.getFilterModel(e,t),s=(w=r==null?void 0:r.getRange())!=null?w:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{startRow:a,endRow:c}=n.range,m=c-a+1;if(c>l)return this._handleNull();const u=[],f=[],S={unitId:e,subUnitId:t,range:{...s,startRow:a<=o?o+m:o,endRow:l+m}},R={unitId:e,subUnitId:t,range:s};return u.push({id:F.id,params:S}),f.push({id:F.id,params:R}),{redos:L(u),undos:L(f)}}handleRemoveColCommand(n,e,t){var M;const r=this._sheetsFilterService.getFilterModel(e,t),s=(M=r==null?void 0:r.getRange())!=null?M:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:a,endColumn:c}=n;if(a>l)return this._handleNull();const m=[],u=[],f=c<o?0:Math.min(c,l)-Math.max(a,o)+1,S=c-a+1,R=r.getAllFilterColumns();R.forEach(g=>{const[C,y]=g;C<=c&&C>=a&&(m.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:null}}),u.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:{...y.serialize(),colId:C}}}))});const w=R.filter(g=>{const[C,y]=g;return C>c});let E={undos:[],redos:[]};if(w.length>0){const{oldRange:g,newRange:C}=this._moveCriteria(e,t,w,-S);E=C,m.push(...g.redos),u.unshift(...g.undos)}if(f===l-o+1){const g={unitId:e,subUnitId:t};m.push({id:T.id,params:g}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}})}else{const g=o<=a?o:f===0?o-S:a,C=o<=a?l-f:l-S,y={unitId:e,subUnitId:t,range:{...s,startColumn:g,endColumn:C}};m.push({id:F.id,params:y}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),m.push(...E.redos),u.unshift(...E.undos)}return{undos:u,redos:m}}_handleRemoveRowCommand(n,e,t){var w;const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange(),{startRow:o,endRow:l}=s,{startRow:a,endRow:c}=n.range;if(a>l)return this._handleNull();if(c<o)return{undos:[{id:F.id,params:{range:s,unitId:e,subUnitId:t}}],redos:[{id:F.id,params:{range:{...s,startRow:o-(c-a+1),endRow:l-(c-a+1)},unitId:e,subUnitId:t}}]};const m=[],u=[],f=r.getAllFilterColumns(),S=o<=c&&o>=a;u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}});const R=Math.min(c,l)-Math.max(a,o)+1;if(R===l-o+1||S){const E={unitId:e,subUnitId:t};m.push({id:T.id,params:E}),f.forEach(M=>{const[g,C]=M,y={unitId:e,subUnitId:t,col:g,criteria:{...C.serialize(),colId:g}};u.push({id:p.id,params:y})})}else{const E=(w=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:w.getSheetBySheetId(t);if(!E)return this._handleNull();const M=[];for(let O=a;O<=c;O++)E.getRowFiltered(O)&&M.push(O);const g=Math.min(o,a),C=g+(l-o)-R+M.length,y={unitId:e,subUnitId:t,range:{...s,startRow:g,endRow:C}};m.push({id:F.id,params:y})}return{undos:L(u),redos:L(m)}}handleMoveColsCommand({fromRange:n,toRange:e},t,r){var M;const s=this._sheetsFilterService.getFilterModel(t,r),o=(M=s==null?void 0:s.getRange())!=null?M:null;if(!s||!o)return this._handleNull();const{startColumn:l,endColumn:a}=o;if(n.endColumn<l&&e.startColumn<=l||n.startColumn>a&&e.endColumn>a)return this._handleNull();const c=[],m=[],u={};for(let g=l;g<=a;g++)u[g]={colIndex:g,filter:s.getFilterColumn(g)};d.moveMatrixArray(n.startColumn,n.endColumn-n.startColumn+1,e.startColumn,u);let f=o.startColumn,S=o.endColumn;l>=n.startColumn&&l<=n.endColumn&&e.startColumn>n.startColumn&&n.endColumn<a&&(f=n.endColumn+1),a>=n.startColumn&&a<=n.endColumn&&e.startColumn<n.startColumn&&n.startColumn>l&&(S=n.startColumn-1);const R=Object.keys(u).map(g=>Number(g)),w=R.find(g=>u[g].colIndex===S),E=R.find(g=>u[g].colIndex===f);if(R.forEach(g=>{var _e,Se;const{colIndex:C,filter:y}=u[g],O=g;if(y){if(O>=E&&O<=w){const Q={unitId:t,subUnitId:r,col:O,criteria:{...y.serialize(),colId:O}},Xe={unitId:t,subUnitId:r,col:O,criteria:s.getFilterColumn(O)?{...(_e=s.getFilterColumn(O))==null?void 0:_e.serialize(),colId:O}:null};c.push({id:p.id,params:Q}),m.push({id:p.id,params:Xe})}if(!((Se=u[C])!=null&&Se.filter)){const Q={unitId:t,subUnitId:r,col:C,criteria:null};c.push({id:p.id,params:Q}),m.push({id:p.id,params:{unitId:t,subUnitId:r,col:C,criteria:{...y.serialize(),colId:C}}})}}}),l!==E||a!==w){const g={unitId:t,subUnitId:r,range:{...o,startColumn:E,endColumn:w}};c.unshift({id:F.id,params:g}),m.unshift({id:F.id,params:{range:o,unitId:t,subUnitId:r}})}return{undos:m,redos:c}}_handleMoveRowsCommand(n,e,t){var g;const r=this._sheetsFilterService.getFilterModel(e,t),s=(g=r==null?void 0:r.getRange())!=null?g:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{fromRange:a,toRange:c}=n;if(a.endRow<o&&c.startRow<=o||a.startRow>l&&c.endRow>l)return this._handleNull();const m=[],u=[],f={};for(let C=o;C<=l;C++)f[C]={oldIndex:C};const S=o;let R=l;l>=a.startRow&&l<=a.endRow&&c.startRow<a.startRow&&a.startRow>o&&(R=a.startRow-1),d.moveMatrixArray(a.startRow,a.endRow-a.startRow+1,c.startRow,f);const w=Object.keys(f).map(C=>Number(C)),E=w.find(C=>f[C].oldIndex===R),M=w.find(C=>f[C].oldIndex===S);if(o!==M||l!==E){const C={unitId:e,subUnitId:t,range:{...s,startRow:M,endRow:E}};m.push({id:F.id,params:C},{id:$.id,params:{unitId:e,subUnitId:t}}),u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}},{id:$.id,params:{unitId:e,subUnitId:t}})}return{redos:m,undos:u}}_handleMoveRangeCommand(n,e,t){const{fromRange:r,toRange:s}=n,o=this._sheetsFilterService.getFilterModel(e,t);if(!o)return this._handleNull();const l=o.getRange();if(!l)return this._handleNull();const a=[],c=[];if(d.Rectangle.contains(r,l)){const m=l.startRow-r.startRow,u=l.startColumn-r.startColumn,f={startRow:s.startRow+m,startColumn:s.startColumn+u,endRow:s.startRow+m+(l.endRow-l.startRow),endColumn:s.startColumn+u+(l.endColumn-l.startColumn)},S={id:T.id,params:{unitId:e,subUnitId:t}},R={id:F.id,params:{unitId:e,subUnitId:t,range:f}},w={id:F.id,params:{unitId:e,subUnitId:t,range:l}};a.push(S,R),c.push(S,w);const E=o.getAllFilterColumns(),M=s.startColumn-r.startColumn;E.forEach(g=>{const[C,y]=g;y&&(a.push({id:p.id,params:{unitId:e,subUnitId:t,col:C+M,criteria:{...y.serialize(),colId:C+M}}}),c.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:{...y.serialize(),colId:C}}}))})}else if(d.Rectangle.intersects(s,l)){const m={...l,endRow:Math.max(l.endRow,s.endRow)};a.push({id:F.id,params:{unitId:e,subUnitId:t,range:m}}),c.push({id:F.id,params:{unitId:e,subUnitId:t,range:l}})}return{redos:a,undos:c}}_handleRemoveSheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[];return r.getAllFilterColumns().forEach(([c,m])=>{l.push({id:p.id,params:{unitId:e,subUnitId:t,col:c,criteria:{...m.serialize(),colId:c}}})}),o.push({id:T.id,params:{unitId:e,subUnitId:t,range:s}}),l.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),{undos:l,redos:o}}_handleCopySheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(n,e);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[],a=[],c=[];return r.getAllFilterColumns().forEach(([u,f])=>{o.push({id:p.id,params:{unitId:n,subUnitId:t,col:u,criteria:{...f.serialize(),colId:u}}}),a.push({id:p.id,params:{unitId:n,subUnitId:t,col:u,criteria:null}})}),a.push({id:T.id,params:{unitId:n,subUnitId:t,range:s}}),o.unshift({id:F.id,params:{range:s,unitId:n,subUnitId:t}}),{undos:l,redos:o,preUndos:a,preRedos:c}}_handleNull(){return{redos:[],undos:[]}}_initRowFilteredInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(n,e)=>{var t,r;return n?!0:(r=(t=this._sheetsFilterService.getFilterModel(e.unitId,e.subUnitId))==null?void 0:t.isRowFiltered(e.row))!=null?r:!1}}))}_moveCriteria(n,e,t,r){const s={unitId:n,subUnitId:e,criteria:null,col:-1},o=[],l=[],a=[],c=[];return t.forEach(m=>{const[u,f]=m;l.push({id:p.id,params:{...s,col:u}}),o.push({id:p.id,params:{...s,col:u,criteria:{...f.serialize(),colId:u}}})}),t.forEach(m=>{const[u,f]=m;c.push({id:p.id,params:{...s,col:u+r,criteria:{...f.serialize(),colId:u+r}}}),a.push({id:p.id,params:{...s,col:u+r,criteria:null}})}),{newRange:{redos:c,undos:a},oldRange:{redos:l,undos:o}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{var c,m;const{unitId:t,subUnitId:r}=n.params||{},s=this._sheetsFilterService.getFilterModel(t,r);if(!s)return;const o=Array.from(s.filteredOutRows).sort((u,f)=>u-f),l=[];let a=!1;if(n.id===_.RemoveRowMutation.id){const{startRow:u,endRow:f}=n.params.range,S=o.filter(R=>R>=u&&R<=f);o.forEach(R=>{if(R<u)l.push(R);else if(a=!0,R<=f){const w=Math.max(u,l.length?l[l.length-1]+1:u);l.push(w)}else l.push(R-(f-u+1-S.length))})}if(n.id===_.InsertRowMutation.id){const{startRow:u,endRow:f}=n.params.range;o.forEach(S=>{S>=u?(a=!0,l.push(S+(f-u+1))):l.push(S)})}if(a&&(s.filteredOutRows=new Set(l)),n.id===_.SetRangeValuesMutation.id&&!(e!=null&&e.onlyLocal)){const u=this._getExtendRegion(t,r);if(u){const f=n.params.cellValue;if(f)for(let S=u.startColumn;S<=u.endColumn;S++){const R=(c=f==null?void 0:f[u.startRow])==null?void 0:c[S];if(R&&this._cellHasValue(R)){const w=(m=this._univerInstanceService.getUnit(t))==null?void 0:m.getSheetBySheetId(r);if(w){const E=_.expandToContinuousRange(u,{down:!0},w),M=this._sheetsFilterService.getFilterModel(t,r),g=M.getRange();M.setRange({...g,endRow:E.endRow}),this._registerRefRange(t,r)}}}}}}))}_getExtendRegion(n,e){var a;const t=this._sheetsFilterService.getFilterModel(n,e);if(!t)return null;const r=(a=this._univerInstanceService.getUnit(n))==null?void 0:a.getSheetBySheetId(e);if(!r)return null;const s=t.getRange();if(!s)return null;const o=r.getRowCount()-1,l=r.getRowManager();for(let c=s.endRow+1;c<=o;c++)if(l.getRowRawVisible(c))return{startRow:c,endRow:c,startColumn:s.startColumn,endColumn:s.endColumn};return null}_initErrorHandling(){this.disposeWithMe(this._commandService.beforeCommandExecuted(n=>{const e=n.params,t=_.getSheetCommandTarget(this._univerInstanceService);if(!t)return;const{subUnitId:r,unitId:s}=t,o=this._sheetsFilterService.getFilterModel(s,r);if(!o)return;const l=o.getRange();if(n.id===_.MoveRowsCommand.id&&e.fromRange.startRow<=l.startRow&&e.fromRange.endRow<l.endRow&&e.fromRange.endRow>=l.startRow)throw this._sheetsFilterService.setFilterErrorMsg("sheets-filter.msg.filter-header-forbidden"),new Error("[SheetsFilterController]: Cannot move header row of filter")}))}_cellHasValue(n){const e=Object.values(n);return!(e.length===0||e.every(t=>t==null))}};D=We([b(0,d.ICommandService),b(1,d.Inject(_.SheetInterceptorService)),b(2,d.Inject(h.SheetsFilterService)),b(3,d.IUniverInstanceService),b(4,d.Inject(_.RefRangeService)),b(5,d.Optional(ve.DataSyncPrimaryController)),b(6,d.Inject(_.ZebraCrossingCacheController))],D);var qe=Object.getOwnPropertyDescriptor,ke=(i,n,e,t)=>{for(var r=t>1?void 0:t?qe(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},G=(i,n)=>(e,t)=>n(e,t,i);const Ge=[p.id,$.id],Qe=[_.InsertColMutation.id,_.RemoveColMutation.id,_.MoveColsMutation.id];h.SheetsFilterSyncController=class extends d.Disposable{constructor(e,t,r){super();v(this,"_d",new d.DisposableCollection);v(this,"_visible$",new I.BehaviorSubject(!1));v(this,"visible$",this._visible$.asObservable());v(this,"_enabled$",new I.BehaviorSubject(!0));v(this,"enabled$",this._enabled$.asObservable());this._sheetsFilterController=e,this._commandService=t,this._configService=r;const s=this._configService.getConfig(fe);s!=null&&s.enableSyncSwitch&&this._visible$.next(!0)}get visible(){return this._visible$.getValue()}get enabled(){return this._enabled$.getValue()}setEnabled(e){this._enabled$.next(e),e?this._d.dispose():this._initOnlyLocalListener()}_initOnlyLocalListener(){this._d.add(this._commandService.beforeCommandExecuted((e,t)=>{Ge.includes(e.id)&&(t||(t={}),t.onlyLocal=!0)})),this._d.add(this._commandService.onCommandExecuted((e,t)=>{if(Qe.includes(e.id)&&(t!=null&&t.fromCollab)){if(e.id===_.InsertColMutation.id){const{range:r,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleInsertColCommand(r,s,o);d.sequenceExecute(l,this._commandService,t)}else if(e.id===_.RemoveColMutation.id){const{range:r,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleRemoveColCommand(r,s,o);d.sequenceExecute(l,this._commandService,t)}else if(e.id===_.MoveColsMutation.id){const{sourceRange:r,targetRange:s,unitId:o,subUnitId:l}=e.params,{redos:a}=this._sheetsFilterController.handleMoveColsCommand({fromRange:r,toRange:s},o,l);d.sequenceExecute(a,this._commandService,t)}}}))}},h.SheetsFilterSyncController=ke([G(0,d.Inject(D)),G(1,d.ICommandService),G(2,d.IConfigService)],h.SheetsFilterSyncController);var Je=Object.getOwnPropertyDescriptor,Ke=(i,n,e,t)=>{for(var r=t>1?void 0:t?Je(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},B=(i,n)=>(e,t)=>n(e,t,i);let j=class extends d.Disposable{constructor(i,n,e,t){super(),this._activeDirtyManagerService=i,this._sheetRowFilteredService=n,this._sheetsFilterService=e,this._univerInstanceService=t,this._initFormulaDirtyRange(),this._registerSheetRowFiltered()}_initFormulaDirtyRange(){H.forEach(i=>{this._activeDirtyManagerService.register(i,{commandId:i,getDirtyData:n=>{const e=n.params,{unitId:t,subUnitId:r}=e;return{dirtyRanges:this._getHideRowMutation(t,r),clearDependencyTreeCache:{[t]:{[r]:"1"}}}}})})}_getHideRowMutation(i,n){var l,a;const e=(l=this._sheetsFilterService.getFilterModel(i,n))==null?void 0:l.getRange(),t=(a=this._univerInstanceService.getUnit(i))==null?void 0:a.getSheetBySheetId(n);if(e==null||t==null)return[];const{startRow:r,endRow:s}=e;return[{unitId:i,sheetId:n,range:{startRow:r,startColumn:0,endRow:s,endColumn:t.getColumnCount()-1}}]}_registerSheetRowFiltered(){this._sheetRowFilteredService.register((i,n,e)=>{var t,r;return(r=(t=this._sheetsFilterService.getFilterModel(i,n))==null?void 0:t.isRowFiltered(e))!=null?r:!1})}};j=Ke([B(0,d.Inject(J.IActiveDirtyManagerService)),B(1,d.Inject(J.ISheetRowFilteredService)),B(2,d.Inject(h.SheetsFilterService)),B(3,d.IUniverInstanceService)],j);var Ze=Object.getOwnPropertyDescriptor,Ye=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ze(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},Ce=(i,n)=>(e,t)=>n(e,t,i);h.UniverSheetsFilterPlugin=(x=class extends d.Plugin{constructor(n=ge,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=d.merge({},ge,this._config);this._configService.setConfig(fe,r)}onStarting(){[[j],[h.SheetsFilterService],[D],[h.SheetsFilterSyncController]].forEach(n=>this._injector.add(n))}onReady(){d.touchDependencies(this._injector,[[j],[D],[h.SheetsFilterSyncController]])}},v(x,"type",d.UniverInstanceType.UNIVER_SHEET),v(x,"pluginName",k),x),h.UniverSheetsFilterPlugin=Ye([Ce(1,d.Inject(d.Injector)),Ce(2,d.IConfigService)],h.UniverSheetsFilterPlugin),h.ClearSheetsFilterCriteriaCommand=De,h.CustomFilterOperator=A,h.FILTER_MUTATIONS=H,h.FilterBy=N,h.FilterColumn=de,h.FilterModel=P,h.ReCalcSheetsFilterCommand=Be,h.ReCalcSheetsFilterMutation=$,h.RemoveSheetFilterCommand=he,h.RemoveSheetsFilterMutation=T,h.SHEET_FILTER_SNAPSHOT_ID=k,h.SetSheetFilterRangeCommand=ue,h.SetSheetsFilterCriteriaCommand=Pe,h.SetSheetsFilterCriteriaMutation=p,h.SetSheetsFilterRangeMutation=F,h.SmartToggleSheetsFilterCommand=Le,h.equals=ie,h.getCustomFilterFn=V,h.greaterThan=ee,h.greaterThanOrEqualTo=te,h.lessThan=re,h.lessThanOrEqualTo=ne,h.notEquals=z,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
|
|
2
|
+
(function(h,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-render"),require("@univerjs/rpc"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-render","@univerjs/rpc","@univerjs/engine-formula"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.UniverSheetsFilter={},h.UniverCore,h.UniverSheets,h.rxjs,h.UniverEngineRender,h.UniverRpc,h.UniverEngineFormula))})(this,(function(h,a,_,I,Se,Re,J){"use strict";var Ye=Object.defineProperty;var et=(h,a,_)=>a in h?Ye(h,a,{enumerable:!0,configurable:!0,writable:!0,value:_}):h[a]=_;var v=(h,a,_)=>et(h,typeof a!="symbol"?a+"":a,_);var x;const K="sheet.mutation.set-filter-range",Z="sheet.mutation.set-filter-criteria",X="sheet.mutation.remove-filter",Y="sheet.mutation.re-calc-filter",H=new Set([K,Z,X,Y]);var N=(i=>(i[i.VALUES=0]="VALUES",i[i.COLORS=1]="COLORS",i[i.CONDITIONS=2]="CONDITIONS",i))(N||{}),A=(i=>(i.EQUAL="equal",i.GREATER_THAN="greaterThan",i.GREATER_THAN_OR_EQUAL="greaterThanOrEqual",i.LESS_THAN="lessThan",i.LESS_THAN_OR_EQUAL="lessThanOrEqual",i.NOT_EQUALS="notEqual",i))(A||{});const ee={operator:A.GREATER_THAN,fn:(i,n)=>U(i)?i>n:!1},te={operator:A.GREATER_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i>=n:!1},re={operator:A.LESS_THAN,fn:(i,n)=>U(i)?i<n:!1},ne={operator:A.LESS_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i<=n:!1},ie={operator:A.EQUAL,fn:(i,n)=>U(i)?i===n:!1},z={operator:A.NOT_EQUALS,fn:(i,n)=>{if(typeof n=="string"){if(n===" ")return i!=null;const e=le(i);return e&&pe(n)?!a.createREGEXFromWildChar(n).test(e):e!==n}return U(i)?i!==n:!0}},se=new Map([]);[ee,te,re,ne,ie,z].forEach(i=>{se.set(i.operator,i)});function ve(i){return!!i}const Fe={fn:(i,n)=>{const e=le(i);return e===null?n==="":a.createREGEXFromWildChar(n).test(e)}};function V(i){return i?se.get(i):Fe}function U(i){return typeof i=="number"}function oe(i){return!!(typeof i=="number"||typeof i=="string"&&a.isNumeric(i))}function le(i){return typeof i=="boolean"||i==null?null:typeof i=="string"?i:i.toString()}function pe(i){return typeof i=="number"?!1:i.indexOf("*")!==-1||i.indexOf("?")!==-1}const W=()=>new Set;class P extends a.Disposable{constructor(e,t,r){super();v(this,"_filteredOutRows$",new I.BehaviorSubject(W()));v(this,"filteredOutRows$",this._filteredOutRows$.asObservable());v(this,"_hasCriteria$",new I.BehaviorSubject(!1));v(this,"hasCriteria$",this._hasCriteria$.asObservable());v(this,"_filterColumnByIndex",new Map);v(this,"_alreadyFilteredOutRows",W());v(this,"_range");this.unitId=e,this.subUnitId=t,this._worksheet=r}get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete(),this._worksheet=null}serialize(){const e={ref:a.Rectangle.clone(this._range),filterColumns:this._getAllFilterColumns(!0).sort(([t],[r])=>t-r).map(([t,r])=>r.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(e,t,r,s){const o=new P(e,t,r);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.forEach(r=>this._setCriteriaWithoutReCalc(r.colId,r)),e.cachedFilteredOut&&(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw new Error("[FilterModel] could not get range before a range is set!");return this._range}getFilteredOutRowsExceptCol(e){return this._getAllFilterColumns(!0).filter(([t])=>t!==e).reduce((t,[,r])=>{const s=r.calc({getAlreadyFilteredOutRows:()=>t});return s?a.mergeSets(t,s):t},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,r])=>{r.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,r=!1){if(!this._range)throw new Error("[FilterModel] could not set criteria before a range is set!");if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),r&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),r&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))!=null?t:null}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){const t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([r,s])=>s)}_reCalcAllColumns(){this._alreadyFilteredOutRows=W(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns()}_setCriteriaWithoutReCalc(e,t){const r=this._range;if(!r)throw new Error("[FilterModel] could not set criteria before a range is set!");const{startColumn:s,endColumn:o}=r;if(e>o||e<s)throw new Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);let l;this._filterColumnByIndex.has(e)?l=this._filterColumnByIndex.get(e):(l=new ae(this.unitId,this.subUnitId,this._worksheet,t,{getAlreadyFilteredOutRows:()=>this._alreadyFilteredOutRows}),l.setRangeAndColumn(r,e),this._filterColumnByIndex.set(e,l)),l.setCriteria(t)}_removeCriteria(e){const t=this._filterColumnByIndex.get(e);t&&(t.dispose(),this._filterColumnByIndex.delete(e))}_emit(){this._filteredOutRows$.next(this._alreadyFilteredOutRows)}_emitHasCriteria(){this._hasCriteria$.next(this._filterColumnByIndex.size>0)}_rebuildAlreadyFilteredOutRowsWithCache(){const e=this._getAllFilterColumns().filter(t=>t.hasCache()).reduce((t,r)=>a.mergeSets(t,r.filteredOutRows),new Set);this._alreadyFilteredOutRows=e}_reCalcWithNoCacheColumns(){const e=this._getAllFilterColumns().filter(t=>!t.hasCache());for(const t of e){const r=t.reCalc();r&&(this._alreadyFilteredOutRows=a.mergeSets(this._alreadyFilteredOutRows,r))}}}class ae extends a.Disposable{constructor(e,t,r,s,o){super();v(this,"_filteredOutRows",null);v(this,"_filterFn",null);v(this,"_range",null);v(this,"_column",0);v(this,"_filterBy",N.VALUES);this.unitId=e,this.subUnitId=t,this._worksheet=r,this._criteria=s,this._filterColumnContext=o}get filteredOutRows(){return this._filteredOutRows}get filterBy(){return this._filterBy}dispose(){super.dispose(),this._filteredOutRows=null}__clearCache(){this._filteredOutRows=null}serialize(){if(!this._criteria)throw new Error("[FilterColumn]: could not serialize without a filter column!");return a.Tools.deepClone({...this._criteria,colId:this._column})}hasCache(){return this._filteredOutRows!==null}setRangeAndColumn(e,t){this._range=e,this._column=t}setCriteria(e){this._criteria=e,this._generateFilterFn(),this._filteredOutRows=null}getColumnData(){return a.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw new Error("[FilterColumn] cannot calculate without a filter fn!");if(!this._range)throw new Error("[FilterColumn] cannot calculate without a range!");if(typeof this._column!="number")throw new TypeError("[FilterColumn] cannot calculate without a column offset!");const t=this._column,r={startColumn:t,endColumn:t,startRow:this._range.startRow+1,endRow:this._range.endRow},s=new Set,o=e.getAlreadyFilteredOutRows();for(const l of this._worksheet.iterateByColumn(r,!1,!1)){const{row:d,rowSpan:c,col:m}=l;if(o.has(d)&&(!c||c===1))continue;if(!(this._filterBy===N.VALUES?this._filterFn(a.extractPureTextFromCell(this._worksheet.getCell(d,m))):this._filterBy===N.COLORS?this._filterFn(this._worksheet.getComposedCellStyle(d,m)):this._filterFn(Ne(this._worksheet,d,m)))&&(s.add(d),c))for(let f=1;f<c;f++)s.add(d+f)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=we(this._criteria),this._filterBy=this._criteria.filters?N.VALUES:this._criteria.colorFilters?N.COLORS:N.CONDITIONS)}}function we(i){if(i.filters)return Me(i.filters);if(i.colorFilters)return Ee(i.colorFilters);if(i.customFilters)return ye(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function Me(i){const n=!!i.blank,e=new Set(i.filters);return t=>t===void 0||t===""?n:e.has(typeof t=="string"?t:`${t}`)}function Ee(i){if(i.cellFillColors){const n=new Set(i.cellFillColors);return e=>{var r;if(!e||!((r=e.bg)!=null&&r.rgb))return!!n.has(null);const t=new a.ColorKit(e.bg.rgb).toRgbString();return n.has(t)}}if(i.cellTextColors){const n=new Set(i.cellTextColors);return e=>{var r;if(!e||!((r=e.cl)!=null&&r.rgb))return!!n.has(Se.COLOR_BLACK_RGB);const t=new a.ColorKit(e.cl.rgb).toRgbString();return n.has(t)}}throw new Error("[FilterModel]: color filters are not supported yet.")}function ye(i){const n=i.customFilters.map(e=>Ae(e));return Te(n)?i.and?Oe(n):Ie(n):n[0]}function Oe(i){const[n,e]=i;return t=>n(t)&&e(t)}function Ie(i){const[n,e]=i;return t=>n(t)||e(t)}function Te(i){return i.length===2}function Ae(i){const n=i.val;if(i.operator===A.NOT_EQUALS&&!oe(n))return r=>z.fn(r,n);if(ve(i.operator)){if(!oe(n))return()=>!1;const r=V(i.operator),s=Number(n);return o=>r.fn(o,s)}const e=V(i.operator);return t=>e.fn(t,n)}function Ne(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?de(t):r?t.t===a.CellValueType.NUMBER&&typeof t.v=="string"?r.v:t.t===a.CellValueType.NUMBER?Number(r.v):de(r):null}function de(i){var t,r;const n=(r=(t=i.p)==null?void 0:t.body)==null?void 0:r.dataStream;if(n)return n.trimEnd();const e=i.v;return typeof e=="string"?i.t===a.CellValueType.BOOLEAN?e.toUpperCase():e:typeof e=="number"?i.t===a.CellValueType.BOOLEAN?e?"TRUE":"FALSE":e:typeof e=="boolean"?e?"TRUE":"FALSE":""}var be=Object.getOwnPropertyDescriptor,Ue=(i,n,e,t)=>{for(var r=t>1?void 0:t?be(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},q=(i,n)=>(e,t)=>n(e,t,i);const k="SHEET_FILTER_PLUGIN";h.SheetsFilterService=class extends a.Disposable{constructor(e,t,r){super();v(this,"_filterModels",new Map);v(this,"_loadedUnitId$",new I.BehaviorSubject(null));v(this,"loadedUnitId$",this._loadedUnitId$.asObservable());v(this,"_errorMsg$",new I.BehaviorSubject(null));v(this,"errorMsg$",this._errorMsg$.asObservable());v(this,"_activeFilterModel$",new I.BehaviorSubject(null));v(this,"activeFilterModel$",this._activeFilterModel$.asObservable());this._resourcesManagerService=e,this._univerInstanceService=t,this._commandService=r,this._initModel(),this._initActiveFilterModel()}get activeFilterModel(){return this._activeFilterModel$.getValue()}ensureFilterModel(e,t){const r=this.getFilterModel(e,t);if(r)return r;const s=this._univerInstanceService.getUniverSheetInstance(e);if(!s)throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${e}!`);const o=s.getSheetBySheetId(t);if(!o)throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${t}!`);const l=new P(e,t,o);return this._cacheFilterModel(e,t,l),l}getFilterModel(e,t){var r,s;return(s=(r=this._filterModels.get(e))==null?void 0:r.get(t))!=null?s:null}removeFilterModel(e,t){const r=this.getFilterModel(e,t);return r?(r.dispose(),this._filterModels.get(e).delete(t),!0):!1}setFilterErrorMsg(e){this._errorMsg$.next(e)}_updateActiveFilterModel(){let e;try{if(e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),!e){this._activeFilterModel$.next(null);return}}catch(l){console.error("[SheetsFilterService]: could not get active workbook!",l);return}const t=e.getActiveSheet(!0);if(!t){this._activeFilterModel$.next(null);return}const r=t.getUnitId(),s=t.getSheetId(),o=this.getFilterModel(r,s);this._activeFilterModel$.next(o)}_initActiveFilterModel(){this.disposeWithMe(I.merge(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([e])=>e.type===a.CommandType.MUTATION&&H.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(e=>{var t;return(t=e==null?void 0:e.activeSheet$)!=null?t:I.of(null)}))).subscribe(()=>this._updateActiveFilterModel()))}_serializeAutoFiltersForUnit(e){const t=this._filterModels.get(e);if(!t)return"{}";const r={};return t.forEach((s,o)=>{r[o]=s.serialize()}),JSON.stringify(r)}_deserializeAutoFiltersForUnit(e,t){const r=this._univerInstanceService.getUniverSheetInstance(e);Object.keys(t).forEach(s=>{const o=t[s],l=P.deserialize(e,s,r.getSheetBySheetId(s),o);this._cacheFilterModel(e,s,l)})}dispose(){super.dispose(),this._loadedUnitId$.complete(),this._errorMsg$.complete(),this._activeFilterModel$.complete(),this._filterModels.forEach(e=>{e.forEach(t=>t.dispose()),e.clear()}),this._filterModels.clear()}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:k,businesses:[a.UniverInstanceType.UNIVER_SHEET],toJson:e=>this._serializeAutoFiltersForUnit(e),parseJson:e=>JSON.parse(e),onLoad:(e,t)=>{this._deserializeAutoFiltersForUnit(e,t),this._loadedUnitId$.next(e),this._updateActiveFilterModel()},onUnLoad:e=>{const t=this._filterModels.get(e);t&&(t.forEach(r=>r.dispose()),this._filterModels.delete(e))}})}_cacheFilterModel(e,t,r){this._filterModels.has(e)||this._filterModels.set(e,new Map),this._filterModels.get(e).set(t,r)}},h.SheetsFilterService=Ue([q(0,a.IResourceManagerService),q(1,a.IUniverInstanceService),q(2,a.ICommandService)],h.SheetsFilterService);const F={id:K,type:a.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,range:r}=n;return i.get(h.SheetsFilterService).ensureFilterModel(t,e).setRange(r),!0}},p={id:Z,type:a.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,criteria:r,col:s,reCalc:o=!0}=n,d=i.get(h.SheetsFilterService).getFilterModel(t,e);return d?(d.setCriteria(s,r,o),!0):!1}},T={id:X,type:a.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(h.SheetsFilterService).removeFilterModel(e,t)}},$={id:Y,type:a.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n,s=i.get(h.SheetsFilterService).getFilterModel(e,t);return s?(s.reCalc(),!0):!1}},ce={id:"sheet.command.set-filter-range",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUndoRedoService),s=i.get(a.IUniverInstanceService),{unitId:o,subUnitId:l,range:d}=n;if(!_.getSheetCommandTarget(s,n)||e.getFilterModel(o,l))return!1;if(d.endRow===d.startRow){const S=i.get(a.ErrorService),R=i.get(a.LocaleService);return S.emit(R.t("sheets-filter.command.not-valid-filter-range")),!1}const u={id:F.id,params:{unitId:o,subUnitId:l,range:d}},f=t.syncExecuteCommand(u.id,u.params);return f&&r.pushUndoRedo({unitID:o,undoMutations:[{id:T.id,params:{unitId:o,subUnitId:l}}],redoMutations:[u]}),f}},ue={id:"sheet.command.remove-sheet-filter",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(a.IUniverInstanceService),t=i.get(h.SheetsFilterService),r=i.get(a.ICommandService),s=i.get(a.IUndoRedoService),o=_.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:d}=o,c=t.getFilterModel(l,d);if(!c)return!1;const m=c==null?void 0:c.serialize(),u=Be(l,d,m),f=r.syncExecuteCommand(T.id,{unitId:l,subUnitId:d});return f&&s.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:[{id:T.id,params:{unitId:l,subUnitId:d}}]}),f}},$e={id:"sheet.command.smart-toggle-filter",type:a.CommandType.COMMAND,handler:async i=>{const n=i.get(a.IUniverInstanceService),e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=r==null?void 0:r.getActiveSheet();if(!s||!r)return!1;const o=r.getUnitId(),l=s.getSheetId();if(e.getFilterModel(o,l))return t.executeCommand(ue.id,{unitId:o,subUnitId:l});const m=i.get(_.SheetsSelectionsService).getCurrentLastSelection();if(!m)return!1;const u=m.range,f=_.isSingleCellSelection(m)?_.expandToContinuousRange(u,{left:!0,right:!0,up:!0,down:!0},s):u;return t.executeCommand(ce.id,{unitId:o,subUnitId:l,range:f})}},Le={id:"sheet.command.set-filter-criteria",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUndoRedoService),{unitId:s,subUnitId:o,col:l,criteria:d}=n,c=e.getFilterModel(s,o);if(!c)return!1;const m=c.getRange();if(!m||l<m.startColumn||l>m.endColumn)return!1;const u=c.getFilterColumn(l),f=xe(s,o,l,u),S={id:p.id,params:{unitId:s,subUnitId:o,col:l,criteria:d}},R=t.syncExecuteCommand(S.id,S.params);return R&&r.pushUndoRedo({unitID:s,undoMutations:[f],redoMutations:[S]}),R}},Pe={id:"sheet.command.clear-filter-criteria",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.IUndoRedoService),r=i.get(a.ICommandService),s=i.get(a.IUniverInstanceService),o=_.getSheetCommandTarget(s,n);if(!o)return!1;const{unitId:l,subUnitId:d}=o,c=e.getFilterModel(o.unitId,o.subUnitId);if(!c)return!1;const m=c.serialize(),u=he(l,d,m),f=je(l,d,m);return a.sequenceExecute(f,r).result?(t.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:f}),!0):!1}},De={id:"sheet.command.re-calc-filter",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUniverInstanceService),s=_.getSheetCommandTarget(r,n);if(!s)return!1;const{unitId:o,subUnitId:l}=s;return e.getFilterModel(s.unitId,s.subUnitId)?t.executeCommand($.id,{unitId:o,subUnitId:l}):!1}};function Be(i,n,e){const t=[],r={id:F.id,params:{unitId:i,subUnitId:n,range:e.ref}};return t.push(r),he(i,n,e).forEach(o=>t.push(o)),t}function he(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:s}};t.push(o)}),t}function je(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:null}};t.push(o)}),t}function xe(i,n,e,t){if(!t)return{id:p.id,params:{unitId:i,subUnitId:n,col:e,criteria:null}};const r=t.serialize();return{id:p.id,params:{unitId:i,subUnitId:n,col:e,criteria:r}}}const me="sheets-filter.config",fe={};function He(i,n){for(let e=0;e<i.length;e++){let t=e;if(i[e])for(let r=e+1;r<i.length;r++)i[t]&&i[r]&&n(i[t],i[r])&&(i[t]=null,t=r)}return i.filter(e=>e!==null)}function L(i){return He(i,(n,e)=>n.id===p.id&&e.id===p.id&&n.params.unitId===e.params.unitId&&n.params.subUnitId===e.params.subUnitId&&n.params.col===e.params.col)}var ze=Object.getOwnPropertyDescriptor,Ve=(i,n,e,t)=>{for(var r=t>1?void 0:t?ze(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},b=(i,n)=>(e,t)=>n(e,t,i);let D=class extends a.Disposable{constructor(n,e,t,r,s,o,l){super();v(this,"_disposableCollection",new a.DisposableCollection);this._commandService=n,this._sheetInterceptorService=e,this._sheetsFilterService=t,this._univerInstanceService=r,this._refRangeService=s,this._dataSyncPrimaryController=o,this._zebraCrossingCacheController=l,this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener(),this._initErrorHandling(),this._initZebraCrossingCacheListener()}_initZebraCrossingCacheListener(){this.disposeWithMe(this._sheetsFilterService.activeFilterModel$.subscribe(n=>{n&&this.disposeWithMe(n.filteredOutRows$.subscribe(()=>{this._zebraCrossingCacheController.updateZebraCrossingCache(n.unitId,n.subUnitId)}))}))}_initCommands(){[p,F,$,T].forEach(n=>{var e;this.disposeWithMe(this._commandService.registerCommand(n)),(e=this._dataSyncPrimaryController)==null||e.registerSyncingMutations(n)})}_initInterceptors(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>this._getUpdateFilter(n)})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===_.SetWorksheetActiveOperation.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(r,t)}if(n.id===F.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(e.unitId,e.subUnitId)}})),this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe(n=>{if(n){const e=this._univerInstanceService.getUniverSheetInstance(n),t=e==null?void 0:e.getActiveSheet();t&&this._registerRefRange(n,t.getSheetId())}}))}_registerRefRange(n,e){var l;this._disposableCollection.dispose();const t=this._univerInstanceService.getUniverSheetInstance(n),r=t==null?void 0:t.getSheetBySheetId(e);if(!t||!r)return;const s=(l=this._sheetsFilterService.getFilterModel(n,e))==null?void 0:l.getRange(),o=d=>{switch(d.id){case _.InsertRowCommand.id:{const c=d.params,m=c.unitId||n,u=c.subUnitId||e;return this._handleInsertRowCommand(c,m,u)}case _.InsertColCommand.id:{const c=d.params,m=c.unitId||n,u=c.subUnitId||e;return this.handleInsertColCommand(c.range,m,u)}case _.RemoveColCommand.id:{const c=d.params;return this.handleRemoveColCommand(c.range,n,e)}case _.RemoveRowCommand.id:{const c=d.params;return this._handleRemoveRowCommand(c,n,e)}case _.EffectRefRangId.MoveColsCommandId:{const c=d.params;return this.handleMoveColsCommand({fromRange:c.fromRange,toRange:c.toRange},n,e)}case _.EffectRefRangId.MoveRowsCommandId:{const c=d.params;return this._handleMoveRowsCommand(c,n,e)}case _.MoveRangeCommand.id:{const c=d.params;return this._handleMoveRangeCommand(c,n,e)}}return{redos:[],undos:[]}};s&&this._disposableCollection.add(this._refRangeService.registerRefRange(s,o,n,e))}_getUpdateFilter(n){const{id:e}=n;switch(e){case _.RemoveSheetCommand.id:{const t=n.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case _.CopySheetCommand.id:{const t=n.params,{targetSubUnitId:r,unitId:s,subUnitId:o}=t;return!s||!o||!r?this._handleNull():this._handleCopySheetCommand(s,o,r)}}return{redos:[],undos:[]}}handleInsertColCommand(n,e,t){var g;const r=this._sheetsFilterService.getFilterModel(e,t),s=(g=r==null?void 0:r.getRange())!=null?g:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:d,endColumn:c}=n,m=c-d+1;if(c>l)return this._handleNull();const u=[],f=[],S=d,R={unitId:e,subUnitId:t,range:{...s,startColumn:d<=o?o+m:o,endColumn:l+m}},w={unitId:e,subUnitId:t,range:s};u.push({id:F.id,params:R}),f.push({id:F.id,params:w});const M=r.getAllFilterColumns().filter(C=>C[0]>=S);if(M.length!==0){const{newRange:C,oldRange:y}=this._moveCriteria(e,t,M,m);u.push(...y.redos,...C.redos),f.push(...C.undos,...y.undos)}return{redos:L(u),undos:L(f)}}_handleInsertRowCommand(n,e,t){var w;const r=this._sheetsFilterService.getFilterModel(e,t),s=(w=r==null?void 0:r.getRange())!=null?w:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{startRow:d,endRow:c}=n.range,m=c-d+1;if(c>l)return this._handleNull();const u=[],f=[],S={unitId:e,subUnitId:t,range:{...s,startRow:d<=o?o+m:o,endRow:l+m}},R={unitId:e,subUnitId:t,range:s};return u.push({id:F.id,params:S}),f.push({id:F.id,params:R}),{redos:L(u),undos:L(f)}}handleRemoveColCommand(n,e,t){var M;const r=this._sheetsFilterService.getFilterModel(e,t),s=(M=r==null?void 0:r.getRange())!=null?M:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:d,endColumn:c}=n;if(d>l)return this._handleNull();const m=[],u=[],f=c<o?0:Math.min(c,l)-Math.max(d,o)+1,S=c-d+1,R=r.getAllFilterColumns();R.forEach(g=>{const[C,y]=g;C<=c&&C>=d&&(m.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:null}}),u.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:{...y.serialize(),colId:C}}}))});const w=R.filter(g=>{const[C,y]=g;return C>c});let E={undos:[],redos:[]};if(w.length>0){const{oldRange:g,newRange:C}=this._moveCriteria(e,t,w,-S);E=C,m.push(...g.redos),u.unshift(...g.undos)}if(f===l-o+1){const g={unitId:e,subUnitId:t};m.push({id:T.id,params:g}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}})}else{const g=o<=d?o:f===0?o-S:d,C=o<=d?l-f:l-S,y={unitId:e,subUnitId:t,range:{...s,startColumn:g,endColumn:C}};m.push({id:F.id,params:y}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),m.push(...E.redos),u.unshift(...E.undos)}return{undos:u,redos:m}}_handleRemoveRowCommand(n,e,t){var w;const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange(),{startRow:o,endRow:l}=s,{startRow:d,endRow:c}=n.range;if(d>l)return this._handleNull();if(c<o)return{undos:[{id:F.id,params:{range:s,unitId:e,subUnitId:t}}],redos:[{id:F.id,params:{range:{...s,startRow:o-(c-d+1),endRow:l-(c-d+1)},unitId:e,subUnitId:t}}]};const m=[],u=[],f=r.getAllFilterColumns(),S=o<=c&&o>=d;u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}});const R=Math.min(c,l)-Math.max(d,o)+1;if(R===l-o+1||S){const E={unitId:e,subUnitId:t};m.push({id:T.id,params:E}),f.forEach(M=>{const[g,C]=M,y={unitId:e,subUnitId:t,col:g,criteria:{...C.serialize(),colId:g}};u.push({id:p.id,params:y})})}else{const E=(w=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:w.getSheetBySheetId(t);if(!E)return this._handleNull();const M=[];for(let O=d;O<=c;O++)E.getRowFiltered(O)&&M.push(O);const g=Math.min(o,d),C=g+(l-o)-R+M.length,y={unitId:e,subUnitId:t,range:{...s,startRow:g,endRow:C}};m.push({id:F.id,params:y})}return{undos:L(u),redos:L(m)}}handleMoveColsCommand({fromRange:n,toRange:e},t,r){var M;const s=this._sheetsFilterService.getFilterModel(t,r),o=(M=s==null?void 0:s.getRange())!=null?M:null;if(!s||!o)return this._handleNull();const{startColumn:l,endColumn:d}=o;if(n.endColumn<l&&e.startColumn<=l||n.startColumn>d&&e.endColumn>d)return this._handleNull();const c=[],m=[],u={};for(let g=l;g<=d;g++)u[g]={colIndex:g,filter:s.getFilterColumn(g)};a.moveMatrixArray(n.startColumn,n.endColumn-n.startColumn+1,e.startColumn,u);let f=o.startColumn,S=o.endColumn;l>=n.startColumn&&l<=n.endColumn&&e.startColumn>n.startColumn&&n.endColumn<d&&(f=n.endColumn+1),d>=n.startColumn&&d<=n.endColumn&&e.startColumn<n.startColumn&&n.startColumn>l&&(S=n.startColumn-1);const R=Object.keys(u).map(g=>Number(g)),w=R.find(g=>u[g].colIndex===S),E=R.find(g=>u[g].colIndex===f);if(R.forEach(g=>{var Ce,_e;const{colIndex:C,filter:y}=u[g],O=g;if(y){if(O>=E&&O<=w){const Q={unitId:t,subUnitId:r,col:O,criteria:{...y.serialize(),colId:O}},Xe={unitId:t,subUnitId:r,col:O,criteria:s.getFilterColumn(O)?{...(Ce=s.getFilterColumn(O))==null?void 0:Ce.serialize(),colId:O}:null};c.push({id:p.id,params:Q}),m.push({id:p.id,params:Xe})}if(!((_e=u[C])!=null&&_e.filter)){const Q={unitId:t,subUnitId:r,col:C,criteria:null};c.push({id:p.id,params:Q}),m.push({id:p.id,params:{unitId:t,subUnitId:r,col:C,criteria:{...y.serialize(),colId:C}}})}}}),l!==E||d!==w){const g={unitId:t,subUnitId:r,range:{...o,startColumn:E,endColumn:w}};c.unshift({id:F.id,params:g}),m.unshift({id:F.id,params:{range:o,unitId:t,subUnitId:r}})}return{undos:m,redos:c}}_handleMoveRowsCommand(n,e,t){var g;const r=this._sheetsFilterService.getFilterModel(e,t),s=(g=r==null?void 0:r.getRange())!=null?g:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{fromRange:d,toRange:c}=n;if(d.endRow<o&&c.startRow<=o||d.startRow>l&&c.endRow>l)return this._handleNull();const m=[],u=[],f={};for(let C=o;C<=l;C++)f[C]={oldIndex:C};const S=o;let R=l;l>=d.startRow&&l<=d.endRow&&c.startRow<d.startRow&&d.startRow>o&&(R=d.startRow-1),a.moveMatrixArray(d.startRow,d.endRow-d.startRow+1,c.startRow,f);const w=Object.keys(f).map(C=>Number(C)),E=w.find(C=>f[C].oldIndex===R),M=w.find(C=>f[C].oldIndex===S);if(o!==M||l!==E){const C={unitId:e,subUnitId:t,range:{...s,startRow:M,endRow:E}};m.push({id:F.id,params:C},{id:$.id,params:{unitId:e,subUnitId:t}}),u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}},{id:$.id,params:{unitId:e,subUnitId:t}})}return{redos:m,undos:u}}_handleMoveRangeCommand(n,e,t){const{fromRange:r,toRange:s}=n,o=this._sheetsFilterService.getFilterModel(e,t);if(!o)return this._handleNull();const l=o.getRange();if(!l)return this._handleNull();const d=[],c=[];if(a.Rectangle.contains(r,l)){const m=l.startRow-r.startRow,u=l.startColumn-r.startColumn,f={startRow:s.startRow+m,startColumn:s.startColumn+u,endRow:s.startRow+m+(l.endRow-l.startRow),endColumn:s.startColumn+u+(l.endColumn-l.startColumn)},S={id:T.id,params:{unitId:e,subUnitId:t}},R={id:F.id,params:{unitId:e,subUnitId:t,range:f}},w={id:F.id,params:{unitId:e,subUnitId:t,range:l}};d.push(S,R),c.push(S,w);const E=o.getAllFilterColumns(),M=s.startColumn-r.startColumn;E.forEach(g=>{const[C,y]=g;y&&(d.push({id:p.id,params:{unitId:e,subUnitId:t,col:C+M,criteria:{...y.serialize(),colId:C+M}}}),c.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:{...y.serialize(),colId:C}}}))})}else if(a.Rectangle.intersects(s,l)){const m={...l,endRow:Math.max(l.endRow,s.endRow)};d.push({id:F.id,params:{unitId:e,subUnitId:t,range:m}}),c.push({id:F.id,params:{unitId:e,subUnitId:t,range:l}})}return{redos:d,undos:c}}_handleRemoveSheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[];return r.getAllFilterColumns().forEach(([c,m])=>{l.push({id:p.id,params:{unitId:e,subUnitId:t,col:c,criteria:{...m.serialize(),colId:c}}})}),o.push({id:T.id,params:{unitId:e,subUnitId:t,range:s}}),l.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),{undos:l,redos:o}}_handleCopySheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(n,e);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[],d=[],c=[];return r.getAllFilterColumns().forEach(([u,f])=>{o.push({id:p.id,params:{unitId:n,subUnitId:t,col:u,criteria:{...f.serialize(),colId:u}}}),d.push({id:p.id,params:{unitId:n,subUnitId:t,col:u,criteria:null}})}),d.push({id:T.id,params:{unitId:n,subUnitId:t,range:s}}),o.unshift({id:F.id,params:{range:s,unitId:n,subUnitId:t}}),{undos:l,redos:o,preUndos:d,preRedos:c}}_handleNull(){return{redos:[],undos:[]}}_initRowFilteredInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(n,e)=>{var t,r;return n?!0:(r=(t=this._sheetsFilterService.getFilterModel(e.unitId,e.subUnitId))==null?void 0:t.isRowFiltered(e.row))!=null?r:!1}}))}_moveCriteria(n,e,t,r){const s={unitId:n,subUnitId:e,criteria:null,col:-1},o=[],l=[],d=[],c=[];return t.forEach(m=>{const[u,f]=m;l.push({id:p.id,params:{...s,col:u}}),o.push({id:p.id,params:{...s,col:u,criteria:{...f.serialize(),colId:u}}})}),t.forEach(m=>{const[u,f]=m;c.push({id:p.id,params:{...s,col:u+r,criteria:{...f.serialize(),colId:u+r}}}),d.push({id:p.id,params:{...s,col:u+r,criteria:null}})}),{newRange:{redos:c,undos:d},oldRange:{redos:l,undos:o}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{var c,m;const{unitId:t,subUnitId:r}=n.params||{},s=this._sheetsFilterService.getFilterModel(t,r);if(!s)return;const o=Array.from(s.filteredOutRows).sort((u,f)=>u-f),l=[];let d=!1;if(n.id===_.RemoveRowMutation.id){const{startRow:u,endRow:f}=n.params.range,S=o.filter(R=>R>=u&&R<=f);o.forEach(R=>{if(R<u)l.push(R);else if(d=!0,R<=f){const w=Math.max(u,l.length?l[l.length-1]+1:u);l.push(w)}else l.push(R-(f-u+1-S.length))})}if(n.id===_.InsertRowMutation.id){const{startRow:u,endRow:f}=n.params.range;o.forEach(S=>{S>=u?(d=!0,l.push(S+(f-u+1))):l.push(S)})}if(d&&(s.filteredOutRows=new Set(l)),n.id===_.SetRangeValuesMutation.id&&!(e!=null&&e.onlyLocal)){const u=this._getExtendRegion(t,r);if(u){const f=n.params.cellValue;if(f)for(let S=u.startColumn;S<=u.endColumn;S++){const R=(c=f==null?void 0:f[u.startRow])==null?void 0:c[S];if(R&&this._cellHasValue(R)){const w=(m=this._univerInstanceService.getUnit(t))==null?void 0:m.getSheetBySheetId(r);if(w){const E=_.expandToContinuousRange(u,{down:!0},w),M=this._sheetsFilterService.getFilterModel(t,r),g=M.getRange();M.setRange({...g,endRow:E.endRow}),this._registerRefRange(t,r)}}}}}}))}_getExtendRegion(n,e){var d;const t=this._sheetsFilterService.getFilterModel(n,e);if(!t)return null;const r=(d=this._univerInstanceService.getUnit(n))==null?void 0:d.getSheetBySheetId(e);if(!r)return null;const s=t.getRange();if(!s)return null;const o=r.getRowCount()-1,l=r.getRowManager();for(let c=s.endRow+1;c<=o;c++)if(l.getRowRawVisible(c))return{startRow:c,endRow:c,startColumn:s.startColumn,endColumn:s.endColumn};return null}_initErrorHandling(){this.disposeWithMe(this._commandService.beforeCommandExecuted(n=>{const e=n.params,t=_.getSheetCommandTarget(this._univerInstanceService);if(!t)return;const{subUnitId:r,unitId:s}=t,o=this._sheetsFilterService.getFilterModel(s,r);if(!o)return;const l=o.getRange();if(n.id===_.MoveRowsCommand.id&&e.fromRange.startRow<=l.startRow&&e.fromRange.endRow<l.endRow&&e.fromRange.endRow>=l.startRow)throw this._sheetsFilterService.setFilterErrorMsg("sheets-filter.msg.filter-header-forbidden"),new Error("[SheetsFilterController]: Cannot move header row of filter")}))}_cellHasValue(n){const e=Object.values(n);return!(e.length===0||e.every(t=>t==null))}};D=Ve([b(0,a.ICommandService),b(1,a.Inject(_.SheetInterceptorService)),b(2,a.Inject(h.SheetsFilterService)),b(3,a.IUniverInstanceService),b(4,a.Inject(_.RefRangeService)),b(5,a.Optional(Re.DataSyncPrimaryController)),b(6,a.Inject(_.ZebraCrossingCacheController))],D);var We=Object.getOwnPropertyDescriptor,qe=(i,n,e,t)=>{for(var r=t>1?void 0:t?We(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},G=(i,n)=>(e,t)=>n(e,t,i);const ke=[p.id,$.id],Ge=[_.InsertColMutation.id,_.RemoveColMutation.id,_.MoveColsMutation.id];h.SheetsFilterSyncController=class extends a.Disposable{constructor(e,t,r){super();v(this,"_d",new a.DisposableCollection);v(this,"_visible$",new I.BehaviorSubject(!1));v(this,"visible$",this._visible$.asObservable());v(this,"_enabled$",new I.BehaviorSubject(!0));v(this,"enabled$",this._enabled$.asObservable());this._sheetsFilterController=e,this._commandService=t,this._configService=r;const s=this._configService.getConfig(me);s!=null&&s.enableSyncSwitch&&this._visible$.next(!0)}get visible(){return this._visible$.getValue()}get enabled(){return this._enabled$.getValue()}setEnabled(e){this._enabled$.next(e),e?this._d.dispose():this._initOnlyLocalListener()}_initOnlyLocalListener(){this._d.add(this._commandService.beforeCommandExecuted((e,t)=>{ke.includes(e.id)&&(t||(t={}),t.onlyLocal=!0)})),this._d.add(this._commandService.onCommandExecuted((e,t)=>{if(Ge.includes(e.id)&&(t!=null&&t.fromCollab)){if(e.id===_.InsertColMutation.id){const{range:r,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleInsertColCommand(r,s,o);a.sequenceExecute(l,this._commandService,t)}else if(e.id===_.RemoveColMutation.id){const{range:r,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleRemoveColCommand(r,s,o);a.sequenceExecute(l,this._commandService,t)}else if(e.id===_.MoveColsMutation.id){const{sourceRange:r,targetRange:s,unitId:o,subUnitId:l}=e.params,{redos:d}=this._sheetsFilterController.handleMoveColsCommand({fromRange:r,toRange:s},o,l);a.sequenceExecute(d,this._commandService,t)}}}))}},h.SheetsFilterSyncController=qe([G(0,a.Inject(D)),G(1,a.ICommandService),G(2,a.IConfigService)],h.SheetsFilterSyncController);var Qe=Object.getOwnPropertyDescriptor,Je=(i,n,e,t)=>{for(var r=t>1?void 0:t?Qe(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},B=(i,n)=>(e,t)=>n(e,t,i);let j=class extends a.Disposable{constructor(i,n,e,t){super(),this._activeDirtyManagerService=i,this._sheetRowFilteredService=n,this._sheetsFilterService=e,this._univerInstanceService=t,this._initFormulaDirtyRange(),this._registerSheetRowFiltered()}_initFormulaDirtyRange(){H.forEach(i=>{this._activeDirtyManagerService.register(i,{commandId:i,getDirtyData:n=>{const e=n.params,{unitId:t,subUnitId:r}=e;return{dirtyRanges:this._getHideRowMutation(t,r),clearDependencyTreeCache:{[t]:{[r]:"1"}}}}})})}_getHideRowMutation(i,n){var l,d;const e=(l=this._sheetsFilterService.getFilterModel(i,n))==null?void 0:l.getRange(),t=(d=this._univerInstanceService.getUnit(i))==null?void 0:d.getSheetBySheetId(n);if(e==null||t==null)return[];const{startRow:r,endRow:s}=e;return[{unitId:i,sheetId:n,range:{startRow:r,startColumn:0,endRow:s,endColumn:t.getColumnCount()-1}}]}_registerSheetRowFiltered(){this._sheetRowFilteredService.register((i,n,e)=>{var t,r;return(r=(t=this._sheetsFilterService.getFilterModel(i,n))==null?void 0:t.isRowFiltered(e))!=null?r:!1})}};j=Je([B(0,a.Inject(J.IActiveDirtyManagerService)),B(1,a.Inject(J.ISheetRowFilteredService)),B(2,a.Inject(h.SheetsFilterService)),B(3,a.IUniverInstanceService)],j);var Ke=Object.getOwnPropertyDescriptor,Ze=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ke(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},ge=(i,n)=>(e,t)=>n(e,t,i);h.UniverSheetsFilterPlugin=(x=class extends a.Plugin{constructor(n=fe,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=a.merge({},fe,this._config);this._configService.setConfig(me,r)}onStarting(){[[j],[h.SheetsFilterService],[D],[h.SheetsFilterSyncController]].forEach(n=>this._injector.add(n))}onReady(){a.touchDependencies(this._injector,[[j],[D],[h.SheetsFilterSyncController]])}},v(x,"type",a.UniverInstanceType.UNIVER_SHEET),v(x,"pluginName",k),x),h.UniverSheetsFilterPlugin=Ze([ge(1,a.Inject(a.Injector)),ge(2,a.IConfigService)],h.UniverSheetsFilterPlugin),h.ClearSheetsFilterCriteriaCommand=Pe,h.CustomFilterOperator=A,h.FILTER_MUTATIONS=H,h.FilterBy=N,h.FilterColumn=ae,h.FilterModel=P,h.ReCalcSheetsFilterCommand=De,h.ReCalcSheetsFilterMutation=$,h.RemoveSheetFilterCommand=ue,h.RemoveSheetsFilterMutation=T,h.SHEET_FILTER_SNAPSHOT_ID=k,h.SetSheetFilterRangeCommand=ce,h.SetSheetsFilterCriteriaCommand=Le,h.SetSheetsFilterCriteriaMutation=p,h.SetSheetsFilterRangeMutation=F,h.SmartToggleSheetsFilterCommand=$e,h.equals=ie,h.getCustomFilterFn=V,h.greaterThan=ee,h.greaterThanOrEqualTo=te,h.lessThan=re,h.lessThanOrEqualTo=ne,h.notEquals=z,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
// @univerjs/sheets-filter/facade
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
// @univerjs/sheets-filter-ui/index
|
|
10
|
-
(function(C,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@univerjs/core"),require("@univerjs/sheets-filter"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/rpc"),require("@univerjs/design"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-filter","@univerjs/sheets-ui","@univerjs/ui","@univerjs/engine-render","@univerjs/sheets","rxjs","@univerjs/rpc","@univerjs/design","react/jsx-runtime","react"],u):(C=typeof globalThis<"u"?globalThis:C||self,u(C.UniverSheetsFilterUi={},C.UniverCore,C.UniverSheetsFilter,C.UniverSheetsUi,C.UniverUi,C.UniverEngineRender,C.UniverSheets,C.rxjs,C.UniverRpc,C.UniverDesign,C.React,C.React))})(this,(function(C,u,c,k,g,X,N,S,fe,F,d,I){"use strict";var sr=Object.defineProperty;var ar=(C,u,c)=>u in C?sr(C,u,{enumerable:!0,configurable:!0,writable:!0,value:c}):C[u]=c;var _=(C,u,c)=>ar(C,typeof u!="symbol"?u+"":u,c);var Oe;var A=(t=>(t[t.FIRST=0]="FIRST",t[t.SECOND=1]="SECOND",t))(A||{}),E=(t=>(t.NONE="none",t.STARTS_WITH="startsWith",t.DOES_NOT_START_WITH="doesNotStartWith",t.ENDS_WITH="endsWith",t.DOES_NOT_END_WITH="doesNotEndWith",t.CONTAINS="contains",t.DOES_NOT_CONTAIN="doesNotContain",t.EQUALS="equals",t.NOT_EQUALS="notEquals",t.EMPTY="empty",t.NOT_EMPTY="notEmpty",t.BETWEEN="between",t.NOT_BETWEEN="notBetween",t.CUSTOM="custom",t))(E||{}),f;(t=>{t.NONE={label:"sheets-filter.conditions.none",operator:E.NONE,order:A.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw new Error("[FilterConditionItems.NONE]: should not have initial form params!")},testMappingParams:i=>i.operator1===E.NONE,mapToFilterColumn:()=>null,testMappingFilterColumn:i=>!i.customFilters&&!i.filters?{}:!1},t.EMPTY={label:"sheets-filter.conditions.empty",operator:E.EMPTY,order:A.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw new Error("[FilterConditionItems.EMPTY]: should not have initial form params!")},testMappingParams:({operator1:i})=>i===E.EMPTY,mapToFilterColumn:()=>({customFilters:{customFilters:[{val:""}]}}),testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.val===""&&s.operator===void 0?{operator1:E.EMPTY}:!1}},t.NOT_EMPTY={label:"sheets-filter.conditions.not-empty",operator:E.NOT_EMPTY,order:A.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw new Error("[FilterConditionItems.NOT_EMPTY]: should not have initial form params!")},testMappingParams:({operator1:i})=>i===E.NOT_EMPTY,mapToFilterColumn:()=>({customFilters:{customFilters:[{val:"",operator:c.CustomFilterOperator.NOT_EQUALS}]}}),testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.val===" "&&s.operator===c.CustomFilterOperator.NOT_EQUALS?{operator1:E.NOT_EMPTY}:!1}},t.TEXT_CONTAINS={label:"sheets-filter.conditions.text-contains",operator:E.CONTAINS,order:A.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:E.CONTAINS,val1:""}),testMappingParams:i=>{const[s]=H(i);return s===E.CONTAINS},mapToFilterColumn:i=>{const{val1:s}=i;return s===""?null:{customFilters:{customFilters:[{val:`*${s}*`}]}}},testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0],a=s.val.toString();return!s.operator&&a.startsWith("*")&&a.endsWith("*")?{operator1:E.CONTAINS,val1:a.slice(1,-1)}:!1}},t.DOES_NOT_CONTAIN={label:"sheets-filter.conditions.does-not-contain",operator:E.DOES_NOT_CONTAIN,order:A.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:E.DOES_NOT_CONTAIN,val1:""}),mapToFilterColumn:i=>({customFilters:{customFilters:[{val:`*${i.val1}*`,operator:c.CustomFilterOperator.NOT_EQUALS}]}}),testMappingParams:i=>{const[s]=H(i);return s===E.DOES_NOT_CONTAIN},testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0],a=s.val.toString();return s.operator===c.CustomFilterOperator.NOT_EQUALS&&a.startsWith("*")&&a.endsWith("*")?{operator1:E.DOES_NOT_CONTAIN,val1:a.slice(1,-1)}:!1}},t.STARTS_WITH={label:"sheets-filter.conditions.starts-with",operator:E.STARTS_WITH,order:A.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:E.STARTS_WITH,val1:""}),mapToFilterColumn:i=>({customFilters:{customFilters:[{val:`${i.val1}*`}]}}),testMappingParams:i=>{const[s]=H(i);return s===E.STARTS_WITH},testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0],a=s.val.toString();return!s.operator&&a.endsWith("*")&&!a.startsWith("*")?{operator1:E.STARTS_WITH,val1:a.slice(0,-1)}:!1}},t.ENDS_WITH={label:"sheets-filter.conditions.ends-with",operator:E.ENDS_WITH,order:A.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:E.ENDS_WITH,val1:""}),mapToFilterColumn:i=>({customFilters:{customFilters:[{val:`*${i.val1}`}]}}),testMappingParams:i=>{const[s]=H(i);return s===E.ENDS_WITH},testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0],a=s.val.toString();return!s.operator&&a.startsWith("*")&&!a.endsWith("*")?{operator1:E.ENDS_WITH,val1:a.slice(1)}:!1}},t.EQUALS={label:"sheets-filter.conditions.equals",operator:E.EQUALS,order:A.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:E.EQUALS,val1:""}),testMappingParams:i=>{const[s]=H(i);return s===E.EQUALS},mapToFilterColumn:i=>{const{val1:s}=i;return s===""?null:{customFilters:{customFilters:[{val:s}]}}},testMappingFilterColumn:i=>{var s,a,h;return((a=(s=i.filters)==null?void 0:s.filters)==null?void 0:a.length)===1?{operator1:E.EQUALS,val1:""}:((h=i.customFilters)==null?void 0:h.customFilters.length)===1&&!i.customFilters.customFilters[0].operator?{operator1:E.EQUALS,val1:i.customFilters.customFilters[0].val.toString()}:!1}},t.GREATER_THAN={label:"sheets-filter.conditions.greater-than",operator:c.CustomFilterOperator.GREATER_THAN,numOfParameters:1,order:A.FIRST,getDefaultFormParams:()=>({operator1:c.CustomFilterOperator.GREATER_THAN,val1:""}),mapToFilterColumn:i=>({customFilters:{customFilters:[{val:i.val1,operator:c.CustomFilterOperator.GREATER_THAN}]}}),testMappingParams:i=>{const[s]=H(i);return s===c.CustomFilterOperator.GREATER_THAN},testMappingFilterColumn:i=>{var a;if(((a=i.customFilters)==null?void 0:a.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.operator!==c.CustomFilterOperator.GREATER_THAN?!1:{operator1:c.CustomFilterOperator.GREATER_THAN,val1:s.val.toString()}}},t.GREATER_THAN_OR_EQUAL={label:"sheets-filter.conditions.greater-than-or-equal",operator:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL,numOfParameters:1,order:A.FIRST,getDefaultFormParams:()=>({operator1:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:""}),testMappingParams:i=>{const[s]=H(i);return s===c.CustomFilterOperator.GREATER_THAN_OR_EQUAL},mapToFilterColumn:i=>({customFilters:{customFilters:[{val:i.val1,operator:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL}]}}),testMappingFilterColumn:i=>{var a;if(((a=i.customFilters)==null?void 0:a.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.operator!==c.CustomFilterOperator.GREATER_THAN_OR_EQUAL?!1:{operator1:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:s.val.toString()}}},t.LESS_THAN={label:"sheets-filter.conditions.less-than",operator:c.CustomFilterOperator.LESS_THAN,numOfParameters:1,order:A.FIRST,getDefaultFormParams:()=>({operator1:c.CustomFilterOperator.LESS_THAN,val1:""}),testMappingParams:i=>{const[s]=H(i);return s===c.CustomFilterOperator.LESS_THAN},mapToFilterColumn:i=>({customFilters:{customFilters:[{val:i.val1,operator:c.CustomFilterOperator.LESS_THAN}]}}),testMappingFilterColumn:i=>{var a;if(((a=i.customFilters)==null?void 0:a.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.operator!==c.CustomFilterOperator.LESS_THAN?!1:{operator1:c.CustomFilterOperator.LESS_THAN,val1:s.val.toString()}}},t.LESS_THAN_OR_EQUAL={label:"sheets-filter.conditions.less-than-or-equal",operator:c.CustomFilterOperator.LESS_THAN_OR_EQUAL,numOfParameters:1,order:A.FIRST,getDefaultFormParams:()=>({operator1:c.CustomFilterOperator.LESS_THAN_OR_EQUAL,val1:""}),testMappingParams:i=>{const[s]=H(i);return s===c.CustomFilterOperator.LESS_THAN_OR_EQUAL},mapToFilterColumn:i=>({customFilters:{customFilters:[{val:i.val1,operator:c.CustomFilterOperator.LESS_THAN_OR_EQUAL}]}}),testMappingFilterColumn:i=>{var a;if(((a=i.customFilters)==null?void 0:a.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.operator!==c.CustomFilterOperator.LESS_THAN_OR_EQUAL?!1:{operator1:c.CustomFilterOperator.LESS_THAN_OR_EQUAL,val1:s.val.toString()}}},t.EQUAL={label:"sheets-filter.conditions.equal",operator:c.CustomFilterOperator.EQUAL,numOfParameters:1,order:A.FIRST,getDefaultFormParams:()=>({operator1:c.CustomFilterOperator.EQUAL,val1:""}),testMappingParams:i=>{const[s]=H(i);return s===c.CustomFilterOperator.EQUAL},mapToFilterColumn:i=>({customFilters:{customFilters:[{val:i.val1,operator:c.CustomFilterOperator.EQUAL}]}}),testMappingFilterColumn:i=>{var a;if(((a=i.customFilters)==null?void 0:a.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.operator!==c.CustomFilterOperator.EQUAL?!1:{operator1:c.CustomFilterOperator.EQUAL,val1:s.val.toString()}}},t.NOT_EQUAL={label:"sheets-filter.conditions.not-equal",operator:c.CustomFilterOperator.NOT_EQUALS,numOfParameters:1,order:A.FIRST,getDefaultFormParams:()=>({operator1:c.CustomFilterOperator.NOT_EQUALS,val1:""}),testMappingParams:i=>{const[s]=H(i);return s===c.CustomFilterOperator.NOT_EQUALS},mapToFilterColumn:i=>({customFilters:{customFilters:[{val:i.val1,operator:c.CustomFilterOperator.NOT_EQUALS}]}}),testMappingFilterColumn:i=>{var a;if(((a=i.customFilters)==null?void 0:a.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.operator!==c.CustomFilterOperator.NOT_EQUALS?!1:{operator1:c.CustomFilterOperator.NOT_EQUALS,val1:s.val.toString()}}},t.BETWEEN={label:"sheets-filter.conditions.between",operator:E.BETWEEN,order:A.SECOND,numOfParameters:2,getDefaultFormParams:()=>({and:!0,operator1:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:"",operator2:c.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:""}),testMappingParams:i=>{const{and:s,operator1:a,operator2:h}=i;if(!s)return!1;const m=[a,h];return m.includes(c.CustomFilterOperator.GREATER_THAN_OR_EQUAL)&&m.includes(c.CustomFilterOperator.LESS_THAN_OR_EQUAL)},mapToFilterColumn:i=>{const{val1:s,val2:a,operator1:h}=i,m=h===c.CustomFilterOperator.GREATER_THAN_OR_EQUAL;return{customFilters:{and:u.BooleanNumber.TRUE,customFilters:[{val:m?s:a,operator:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL},{val:m?a:s,operator:c.CustomFilterOperator.LESS_THAN_OR_EQUAL}]}}},testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==2)return!1;const[s,a]=i.customFilters.customFilters;return s.operator===c.CustomFilterOperator.GREATER_THAN_OR_EQUAL&&a.operator===c.CustomFilterOperator.LESS_THAN_OR_EQUAL&&i.customFilters.and?{and:!0,operator1:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:s.val.toString(),operator2:c.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:a.val.toString()}:a.operator===c.CustomFilterOperator.GREATER_THAN_OR_EQUAL&&s.operator===c.CustomFilterOperator.LESS_THAN_OR_EQUAL&&i.customFilters.and?{and:!0,operator1:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:a.val.toString(),operator2:c.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:s.val.toLocaleString()}:!1}},t.NOT_BETWEEN={label:"sheets-filter.conditions.not-between",operator:E.NOT_BETWEEN,order:A.SECOND,numOfParameters:2,getDefaultFormParams:()=>({operator1:c.CustomFilterOperator.LESS_THAN,val1:"",operator2:c.CustomFilterOperator.GREATER_THAN,val2:""}),testMappingParams:i=>{const{and:s,operator1:a,operator2:h}=i;if(s)return!1;const m=[a,h];return m.includes(c.CustomFilterOperator.GREATER_THAN)&&m.includes(c.CustomFilterOperator.LESS_THAN)},mapToFilterColumn:i=>{const{val1:s,val2:a,operator1:h}=i,m=h===c.CustomFilterOperator.GREATER_THAN;return{customFilters:{customFilters:[{val:m?s:a,operator:c.CustomFilterOperator.GREATER_THAN},{val:m?a:s,operator:c.CustomFilterOperator.LESS_THAN}]}}},testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==2)return!1;const[s,a]=i.customFilters.customFilters;return s.operator===c.CustomFilterOperator.LESS_THAN&&a.operator===c.CustomFilterOperator.GREATER_THAN&&!i.customFilters.and?{operator1:c.CustomFilterOperator.LESS_THAN,val1:s.val.toString(),operator2:c.CustomFilterOperator.GREATER_THAN,val2:a.val.toString()}:a.operator===c.CustomFilterOperator.LESS_THAN&&s.operator===c.CustomFilterOperator.GREATER_THAN&&!i.customFilters.and?{operator1:c.CustomFilterOperator.GREATER_THAN,val1:a.val.toString(),operator2:c.CustomFilterOperator.LESS_THAN,val2:s.val.toLocaleString()}:!1}},t.CUSTOM={label:"sheets-filter.conditions.custom",operator:E.CUSTOM,order:A.SECOND,numOfParameters:2,getDefaultFormParams:()=>({operator1:E.NONE,val1:"",operator2:E.NONE,val2:""}),testMappingParams:()=>!0,mapToFilterColumn:i=>{const{and:s,val1:a,val2:h,operator1:m,operator2:p}=i;function y(M,w){for(const L of t.ALL_CONDITIONS)if(L.operator===M)return L.mapToFilterColumn({val1:w,operator1:M})}const v=!m||m===t.NONE.operator,T=!p||p===t.NONE.operator;if(v&&T)return t.NONE.mapToFilterColumn({});if(v)return y(p,h);if(T)return y(m,a);const O=y(m,a),b=y(p,h),P={customFilters:[O.customFilters.customFilters[0],b.customFilters.customFilters[0]]};return s&&(P.and=u.BooleanNumber.TRUE),{customFilters:P}},testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==2)return!1;const s=i.customFilters.customFilters.map(m=>l({customFilters:{customFilters:[m]}})),a={operator1:s[0][0].operator,val1:s[0][1].val1,operator2:s[1][0].operator,val2:s[1][1].val1};return i.customFilters.and&&(a.and=!0),a}},t.ALL_CONDITIONS=[t.NONE,t.EMPTY,t.NOT_EMPTY,t.TEXT_CONTAINS,t.DOES_NOT_CONTAIN,t.STARTS_WITH,t.ENDS_WITH,t.EQUALS,t.GREATER_THAN,t.GREATER_THAN_OR_EQUAL,t.LESS_THAN,t.LESS_THAN_OR_EQUAL,t.EQUAL,t.NOT_EQUAL,t.BETWEEN,t.NOT_BETWEEN,t.CUSTOM];function e(i){const s=t.ALL_CONDITIONS.find(a=>a.operator===i);if(!s)throw new Error(`[SheetsFilter]: no condition item found for operator: ${i}`);return s}t.getItemByOperator=e;function r(i,s){for(const a of t.ALL_CONDITIONS.filter(h=>h.numOfParameters===s))if(a.numOfParameters!==0&&a.testMappingParams(i))return a;for(const a of t.ALL_CONDITIONS)if(a.testMappingParams(i))return a;throw new Error("[SheetsFilter]: no condition item can be mapped from the filter map params!")}t.testMappingParams=r;function n(i){const s=t.ALL_CONDITIONS.find(a=>a.operator===i);return(s==null?void 0:s.numOfParameters)===0?{operator1:s.operator}:s.getDefaultFormParams()}t.getInitialFormParams=n;function o(i,s){return i.mapToFilterColumn(s)}t.mapToFilterColumn=o;function l(i){if(!i)return[t.NONE,{}];for(const s of t.ALL_CONDITIONS){const a=s.testMappingFilterColumn(i);if(a)return[s,a]}return[t.NONE,{}]}t.testMappingFilterColumn=l})(f||(f={}));function H(t){const{operator1:e,operator2:r,val1:n,val2:o}=t;if(e&&r)throw new Error("Both operator1 and operator2 are set!");if(!e&&!r)throw new Error("Neither operator1 and operator2 and both not set!");return e?[e,n]:[r,o]}function Ie(t){const e=[],r=[];let n=0,o=0;function l(i){i.leaf&&(i.checked?(e.push(i),n+=i.count):(r.push(i),o+=i.count)),i.children&&i.children.forEach(l)}return t.forEach(l),{checkedItems:e,uncheckedItems:r,checked:n,unchecked:o}}var nt=Object.getOwnPropertyDescriptor,ot=(t,e,r,n)=>{for(var o=n>1?void 0:n?nt(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},Fe=(t,e)=>(r,n)=>e(r,n,t);const Ne="sheets-filter.generate-filter-values.service",ve=u.createIdentifier(Ne),st=["yyyy-mm-dd","yyyy-mm-dd;@","yyyy/mm/dd;@","yyyy/mm/dd hh:mm","yyyy-m-d am/pm h:mm","yyyy-MM-dd","yyyy/MM/dd","yyyy/mm/dd",'yyyy"年"MM"月"dd"日"',"MM-dd",'M"月"d"日"',"MM-dd A/P hh:mm"];let be=class extends u.Disposable{constructor(t,e,r){super(),this._localeService=t,this._univerInstanceService=e,this._logService=r}async getFilterValues(t){var p;const{unitId:e,subUnitId:r,filteredOutRowsByOtherColumns:n,filterColumn:o,filters:l,blankChecked:i,iterateRange:s,alreadyChecked:a}=t,h=this._univerInstanceService.getUnit(e),m=(p=this._univerInstanceService.getUnit(e))==null?void 0:p.getSheetBySheetId(r);return!h||!m?[]:(this._logService.debug("[SheetsGenerateFilterValuesService]","getFilterValues for",{unitId:e,subUnitId:r}),Be(l,this._localeService,s,m,new Set(n),o,new Set(a.map(String)),i,h.getStyles()))}};be=ot([Fe(0,u.Inject(u.LocaleService)),Fe(1,u.IUniverInstanceService),Fe(2,u.ILogService)],be);function Be(t,e,r,n,o,l,i,s,a){var P,M,w,L,D,q,Z,se,W,$;const h=new Map,m=new Map,p="yyyy-mm-dd",y=new Set(st),v="empty",T=!t&&((l==null?void 0:l.filterBy)===c.FilterBy.COLORS||(l==null?void 0:l.filterBy)===c.FilterBy.CONDITIONS)&&((P=l.filteredOutRows)==null?void 0:P.size);let O=0;for(const U of n.iterateByColumn(r,!1,!1)){const{row:$e,rowSpan:it=1}=U;let ae=0;for(;ae<it;){const nr=$e+ae;if(o.has(nr)){ae++;continue}const J=U!=null&&U.value?u.extractPureTextFromCell(U.value):"";if(!J){O+=1,ae+=it;continue}const ye=(M=U.value)!=null&&M.v&&!U.value.p?(D=(L=a.get((w=U.value)==null?void 0:w.s))==null?void 0:L.n)==null?void 0:D.pattern:"",or=ye&&u.numfmt.getFormatInfo(ye).isDate;if(ye&&or&&y.has(ye)){const K=(q=n.getCellRaw(U.row,U.col))==null?void 0:q.v;if(!K){ae++;continue}const le=u.numfmt.format(p,K),[R,j,pe]=le.split("-").map(Number);let ee=h.get(`${R}`);ee||(ee={title:`${R}`,key:`${R}`,children:[],count:0,leaf:!1,checked:!1},h.set(`${R}`,ee),m.set(`${R}`,[`${R}`]));let Q=(Z=ee.children)==null?void 0:Z.find(ke=>ke.key===`${R}-${j}`);Q||(Q={title:e.t(`sheets-filter.date.${j}`),key:`${R}-${j}`,children:[],count:0,leaf:!1,checked:!1},(se=ee.children)==null||se.push(Q),m.set(`${R}-${j}`,[`${R}`,`${R}-${j}`]));const Ue=(W=Q==null?void 0:Q.children)==null?void 0:W.find(ke=>ke.key===`${R}-${j}-${pe}`);Ue?(Ue.originValues.add(J),Ue.count++,Q.count++,ee.count++):(($=Q.children)==null||$.push({title:`${pe}`,key:`${R}-${j}-${pe}`,count:1,originValues:new Set([J]),leaf:!0,checked:T?!1:i.size?i.has(J):!s}),Q.count++,ee.count++,m.set(`${R}-${j}-${pe}`,[`${R}`,`${R}-${j}`,`${R}-${j}-${pe}`]))}else{const K=J;let le=h.get(K);le?le.count++:(le={title:J,leaf:!0,checked:T?!1:i.size?i.has(J):!s,key:K,count:1},h.set(K,le),m.set(K,[K]))}ae++}}const b=T?!1:t?s:!0;if(O>0){const U={title:e.t("sheets-filter.panel.empty"),count:O,leaf:!0,checked:b,key:v};h.set("empty",U),m.set("empty",[v])}return{filterTreeItems:at(Array.from(h.values())),filterTreeMapCache:m}}function at(t){return Array.from(t).sort((e,r)=>e.children&&!r.children?-1:!e.children&&r.children?1:lt(e.title,r.title)).map(e=>(e.children&&e.children.sort((r,n)=>{const o=Number.parseInt(r.key.split("-")[1],10),l=Number.parseInt(n.key.split("-")[1],10);return o-l}).forEach(r=>{r.children&&r.children.sort((n,o)=>{const l=Number.parseInt(n.key.split("-")[2],10),i=Number.parseInt(o.key.split("-")[2],10);return l-i})}),e))}const De=t=>!Number.isNaN(Number(t))&&!Number.isNaN(Number.parseFloat(t));function lt(t,e){const r=De(t),n=De(e);return r&&n?Number.parseFloat(t)-Number.parseFloat(e):r&&!n?-1:!r&&n?1:t.localeCompare(e)}function Pe(t,e){for(const r of t){if(r.key===e)return r;if(r.children){const n=Pe(r.children,e);if(n)return n}}return null}function xe(t){return t.leaf?t.checked:t.children?t.children.every(e=>xe(e)):!0}function ce(t,e){t.leaf&&(e!==void 0?t.checked=e:t.checked=!t.checked),t.children&&t.children.forEach(r=>ce(r,e))}function He(t,e){const r=[];return t.forEach(n=>{const o=n.originValues?e.some(s=>Array.from(n.originValues).some(a=>a.toLowerCase().includes(s.toLowerCase()))):!1,l=!o&&e.some(s=>n.title.toLowerCase().includes(s.toLowerCase()));if(o||l)r.push({...n});else if(n.children){const s=He(n.children,e);if(s.length>0){const a=s.reduce((h,m)=>h+m.count,0);r.push({...n,count:a,children:s})}}}),r}var ct=Object.getOwnPropertyDescriptor,_e=(t,e,r,n)=>{for(var o=n>1?void 0:n?ct(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},ue=(t,e)=>(r,n)=>e(r,n,t);u.createIdentifier("sheets-filter-ui.sheets-filter-panel.service");let G=class extends u.Disposable{constructor(e,r){super();_(this,"_filterBy$",new S.BehaviorSubject(c.FilterBy.VALUES));_(this,"filterBy$",this._filterBy$.asObservable());_(this,"_filterByModel$",new S.ReplaySubject(1));_(this,"filterByModel$",this._filterByModel$.asObservable());_(this,"_filterByModel",null);_(this,"_hasCriteria$",new S.BehaviorSubject(!1));_(this,"hasCriteria$",this._hasCriteria$.asObservable());_(this,"_filterModel",null);_(this,"_col$",new S.BehaviorSubject(-1));_(this,"col$",this._col$.asObservable());_(this,"_filterHeaderListener",null);this._injector=e,this._refRangeService=r}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()}dispose(){this._filterBy$.complete(),this._filterByModel$.complete(),this._hasCriteria$.complete()}setupCol(e,r){this.terminate(),this._filterModel=e,this._col$.next(r);const n=e.getFilterColumn(r);if(n){const o=n.getColumnData();if(o.customFilters){this._hasCriteria$.next(!0),this._setupByConditions(e,r);return}if(o.colorFilters){this._hasCriteria$.next(!0),this._setupByColors(e,r);return}if(o.filters){this._hasCriteria$.next(!0),this._setupByValues(e,r);return}this._hasCriteria$.next(!1),this._setupByValues(e,r);return}this._hasCriteria$.next(!1),this._setupByValues(e,r)}changeFilterBy(e){if(!this._filterModel||this.col===-1)return!1;switch(e){case c.FilterBy.VALUES:this._setupByValues(this._filterModel,this.col);break;case c.FilterBy.COLORS:this._setupByColors(this._filterModel,this.col);break;case c.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,r){this._disposeFilterHeaderChangeListener();const n=e.unitId,o=e.subUnitId,l=e.getRange(),i={startColumn:r,startRow:l.startRow,endRow:l.startRow,endColumn:r};this._filterHeaderListener=this._refRangeService.watchRange(n,o,i,(s,a)=>{if(!a)this.terminate();else{const h=a.startColumn-s.startColumn;h!==0&&this._filterByModel.deltaCol(h)}})}async _setupByValues(e,r){this._disposePreviousModel();const n=e.getRange();if(n.startRow===n.endRow)return!1;const o=await Ce.fromFilterColumn(this._injector,e,r);return this.filterByModel=o,this._filterBy$.next(c.FilterBy.VALUES),this._listenToFilterHeaderChange(e,r),!0}async _setupByColors(e,r){this._disposePreviousModel();const n=e.getRange();if(n.startRow===n.endRow)return!1;const o=await Se.fromFilterColumn(this._injector,e,r);return this.filterByModel=o,this._filterBy$.next(c.FilterBy.COLORS),this._listenToFilterHeaderChange(e,r),!0}_setupByConditions(e,r){this._disposePreviousModel();const n=e.getRange();if(n.startRow===n.endRow)return!1;const o=ge.fromFilterColumn(this._injector,e,r,e.getFilterColumn(r));return this.filterByModel=o,this._filterBy$.next(c.FilterBy.CONDITIONS),this._listenToFilterHeaderChange(e,r),!0}_disposePreviousModel(){var e;(e=this._filterByModel)==null||e.dispose(),this.filterByModel=null}};G=_e([ue(0,u.Inject(u.Injector)),ue(1,u.Inject(N.RefRangeService))],G);let ge=class extends u.Disposable{constructor(e,r,n,o,l){super();_(this,"canApply$",S.of(!0));_(this,"_conditionItem$");_(this,"conditionItem$");_(this,"_filterConditionFormParams$");_(this,"filterConditionFormParams$");this._filterModel=e,this.col=r,this._commandService=l,this._conditionItem$=new S.BehaviorSubject(n),this.conditionItem$=this._conditionItem$.asObservable(),this._filterConditionFormParams$=new S.BehaviorSubject(o),this.filterConditionFormParams$=this._filterConditionFormParams$.asObservable()}static fromFilterColumn(e,r,n,o){const[l,i]=f.testMappingFilterColumn(o==null?void 0:o.getColumnData());return e.createInstance(ge,r,n,l,i)}get conditionItem(){return this._conditionItem$.getValue()}get filterConditionFormParams(){return this._filterConditionFormParams$.getValue()}dispose(){super.dispose(),this._conditionItem$.complete(),this._filterConditionFormParams$.complete()}deltaCol(e){this.col+=e}clear(){return this._disposed?Promise.resolve(!1):this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}async apply(){if(this._disposed)return!1;const e=f.mapToFilterColumn(this.conditionItem,this.filterConditionFormParams);return this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:e})}onPrimaryConditionChange(e){const r=f.ALL_CONDITIONS.find(n=>n.operator===e);if(!r)throw new Error(`[ByConditionsModel]: condition item not found for operator: ${e}!`);this._conditionItem$.next(r),this._filterConditionFormParams$.next(f.getInitialFormParams(e))}onConditionFormChange(e){const r={...this.filterConditionFormParams,...e};if(r.and!==!0&&delete r.and,typeof e.and<"u"||typeof e.operator1<"u"||typeof e.operator2<"u"){const n=f.testMappingParams(r,this.conditionItem.numOfParameters);this._conditionItem$.next(n)}this._filterConditionFormParams$.next(r)}};ge=_e([ue(4,u.ICommandService)],ge);let Ce=class extends u.Disposable{constructor(e,r,n,o,l){super();_(this,"_rawFilterItems$");_(this,"rawFilterItems$");_(this,"filterItems$");_(this,"_filterItems",[]);_(this,"_treeMapCache");_(this,"canApply$");_(this,"_manuallyUpdateFilterItems$");_(this,"_searchString$");_(this,"searchString$");this._filterModel=e,this.col=r,this._commandService=l,this._treeMapCache=o,this._searchString$=new S.BehaviorSubject(""),this.searchString$=this._searchString$.asObservable(),this._rawFilterItems$=new S.BehaviorSubject(n),this.rawFilterItems$=this._rawFilterItems$.asObservable(),this._manuallyUpdateFilterItems$=new S.Subject,this.filterItems$=S.merge(S.combineLatest([this._searchString$.pipe(S.throttleTime(500,void 0,{leading:!0,trailing:!0}),S.startWith(void 0)),this._rawFilterItems$]).pipe(S.map(([i,s])=>{if(!i)return s;const h=i.toLowerCase().split(/\s+/).filter(m=>!!m);return He(s,h)})),this._manuallyUpdateFilterItems$).pipe(S.shareReplay(1)),this.canApply$=this.filterItems$.pipe(S.map(i=>Ie(i).checked>0)),this.disposeWithMe(this.filterItems$.subscribe(i=>this._filterItems=i))}static async fromFilterColumn(e,r,n){const o=e.get(u.IUniverInstanceService),l=e.get(u.LocaleService),i=e.get(ve,u.Quantity.OPTIONAL),{unitId:s,subUnitId:a}=r,h=o.getUniverSheetInstance(s);if(!h)throw new Error(`[ByValuesModel]: Workbook not found for filter model with unitId: ${s}!`);const m=h==null?void 0:h.getSheetBySheetId(a);if(!m)throw new Error(`[ByValuesModel]: Worksheet not found for filter model with unitId: ${s} and subUnitId: ${a}!`);const p=r.getRange(),y=n,v=r.getFilterColumn(n),T=v==null?void 0:v.getColumnData().filters,O=new Set(T==null?void 0:T.filters),b=!!(T&&T.blank),P=r.getFilteredOutRowsExceptCol(n),M={...p,startRow:p.startRow+1,startColumn:y,endColumn:y};let w,L;if(i){const D=await i.getFilterValues({unitId:s,subUnitId:a,filteredOutRowsByOtherColumns:Array.from(P),filterColumn:v,filters:!!T,blankChecked:b,iterateRange:M,alreadyChecked:Array.from(O)});w=D.filterTreeItems,L=D.filterTreeMapCache}else{const D=Be(!!T,l,M,m,P,v,O,b,h.getStyles());w=D.filterTreeItems,L=D.filterTreeMapCache}return e.createInstance(Ce,r,n,w,L)}get rawFilterItems(){return this._rawFilterItems$.getValue()}get filterItems(){return this._filterItems}get treeMapCache(){return this._treeMapCache}dispose(){this._rawFilterItems$.complete(),this._searchString$.complete()}deltaCol(e){this.col+=e}setSearchString(e){this._searchString$.next(e)}onCheckAllToggled(e){const r=u.Tools.deepClone(this._filterItems);r.forEach(n=>ce(n,e)),this._manuallyUpdateFilterItems(r)}onFilterCheckToggled(e){const r=u.Tools.deepClone(this._filterItems),n=Pe(r,e.key);if(!n)return;const o=xe(n);ce(n,!o),this._manuallyUpdateFilterItems(r)}onFilterOnly(e){const r=u.Tools.deepClone(this._filterItems);r.forEach(n=>ce(n,!1)),e.forEach(n=>{const o=Pe(r,n);o&&ce(o,!0)}),this._manuallyUpdateFilterItems(r)}_manuallyUpdateFilterItems(e){this._manuallyUpdateFilterItems$.next(e)}clear(){return this._disposed?Promise.resolve(!1):this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}async apply(){if(this._disposed)return!1;const e=Ie(this._filterItems),{checked:r,checkedItems:n}=e,o=this.rawFilterItems;let l=0;for(const h of o)l+=h.count;const i=r===0,s=e.checked===l,a={colId:this.col};if(i)throw new Error("[ByValuesModel]: no checked items!");if(s)return this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null});{a.filters={};const h=n.filter(p=>p.key!=="empty");h.length>0&&(a.filters={filters:h.flatMap(p=>p.originValues?Array.from(p.originValues):[p.title])}),h.length!==n.length&&(a.filters.blank=!0)}return this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:a})}};Ce=_e([ue(4,u.ICommandService)],Ce);let Se=class extends u.Disposable{constructor(e,r,n,o,l){super();_(this,"canApply$",S.of(!0));_(this,"_cellFillColors$");_(this,"cellFillColors$");_(this,"_cellTextColors$");_(this,"cellTextColors$");this._filterModel=e,this.col=r,this._commandService=l,this._cellFillColors$=new S.BehaviorSubject(Array.from(n.values())),this.cellFillColors$=this._cellFillColors$.asObservable(),this._cellTextColors$=new S.BehaviorSubject(Array.from(o.values())),this.cellTextColors$=this._cellTextColors$.asObservable()}static async fromFilterColumn(e,r,n){var M,w,L;const o=e.get(u.IUniverInstanceService),{unitId:l,subUnitId:i}=r,s=o.getUniverSheetInstance(l);if(!s)throw new Error(`[ByColorsModel]: Workbook not found for filter model with unitId: ${l}!`);const a=s==null?void 0:s.getSheetBySheetId(i);if(!a)throw new Error(`[ByColorsModel]: Worksheet not found for filter model with unitId: ${l} and subUnitId: ${i}!`);const h=r.getRange(),m=n,p=(M=r.getFilterColumn(n))==null?void 0:M.getColumnData().colorFilters,y=r.getFilteredOutRowsExceptCol(n),v={...h,startRow:h.startRow+1,startColumn:m,endColumn:m},T=new Map,O=new Set((w=p==null?void 0:p.cellFillColors)!=null?w:[]),b=new Map,P=new Set((L=p==null?void 0:p.cellTextColors)!=null?L:[]);for(const D of a.iterateByColumn(v,!1,!0)){const{row:q,col:Z,value:se}=D;if(y.has(q))continue;const W=a.getComposedCellStyleByCellData(q,Z,se);if(W.bg&&W.bg.rgb){const $=new u.ColorKit(W.bg.rgb).toRgbString();T.has($)||T.set($,{color:$,checked:O.has($)})}else T.set("default-fill-color",{color:null,checked:O.has(null)});if(W.cl&&W.cl.rgb){const $=new u.ColorKit(W.cl.rgb).toRgbString();b.has($)||b.set($,{color:$,checked:P.has($)})}else b.set("default-font-color",{color:X.COLOR_BLACK_RGB,checked:P.has(X.COLOR_BLACK_RGB)})}return e.createInstance(Se,r,n,T,b)}get cellFillColors(){return this._cellFillColors$.getValue()}get cellTextColors(){return this._cellTextColors$.getValue()}dispose(){super.dispose(),this._cellFillColors$.complete()}deltaCol(e){this.col+=e}clear(){return this._disposed?Promise.resolve(!1):this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}onFilterCheckToggled(e,r=!0){const n=r?this.cellFillColors:this.cellTextColors,o=[];let l=!1;for(let i=0;i<n.length;i++){const s=n[i];if(s.color===e.color){l=!0,o.push({color:s.color,checked:!s.checked});continue}o.push({color:s.color,checked:s.checked})}l&&(this._resetColorsCheckedStatus(!r),r?this._cellFillColors$.next([...o]):this._cellTextColors$.next([...o]))}_resetColorsCheckedStatus(e=!0){const r=e?this.cellFillColors:this.cellTextColors,n=[];for(let o=0;o<r.length;o++)n.push({color:r[o].color,checked:!1});e?this._cellFillColors$.next([...n]):this._cellTextColors$.next([...n])}async apply(){if(this._disposed)return!1;const e=this.cellFillColors.filter(o=>o.checked).map(o=>o.color),r=this.cellTextColors.filter(o=>o.checked).map(o=>o.color);if(e.length===0&&r.length===0)return this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null});const n={colId:this.col};return e.length>0?n.colorFilters={cellFillColors:e}:r.length>0&&(n.colorFilters={cellTextColors:r}),this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:n})}};Se=_e([ue(4,u.ICommandService)],Se);const te="FILTER_PANEL_OPENED",he={id:"sheet.operation.open-filter-panel",type:u.CommandType.OPERATION,handler:(t,e)=>{const r=t.get(u.IContextService),n=t.get(c.SheetsFilterService),o=t.get(G);t.get(u.ICommandService).syncExecuteCommand(k.SetCellEditVisibleOperation.id,{visible:!1});const{unitId:i,subUnitId:s,col:a}=e,h=n.getFilterModel(i,s);return h?(o.setupCol(h,a),r.getContextValue(te)||r.setContextValue(te,!0),!0):!1}},re={id:"sheet.operation.close-filter-panel",type:u.CommandType.OPERATION,handler:t=>{const e=t.get(u.IContextService),r=t.get(G),n=t.get(g.ILayoutService,u.Quantity.OPTIONAL);return e.getContextValue(te)?(e.setContextValue(te,!1),n==null||n.focus(),r.terminate()):!1}},Ae={id:"sheet.operation.apply-filter",type:u.CommandType.OPERATION,handler:(t,e)=>{const{filterBy:r}=e;return t.get(G).changeFilterBy(r)}},We="sheets-filter-ui.config",Te={};var ut=Object.getOwnPropertyDescriptor,ht=(t,e,r,n)=>{for(var o=n>1?void 0:n?ut(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},ie=(t,e)=>(r,n)=>e(r,n,t);let ne=class extends u.Disposable{constructor(t,e,r,n,o,l){super(),this._sheetsFilterService=t,this._localeService=e,this._commandService=r,this._sheetPermissionCheckPermission=n,this._injector=o,this._sheetsSelectionService=l,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{var e,r,n;if(t.id===c.SmartToggleSheetsFilterCommand.id){const o=this._injector.get(u.IUniverInstanceService),l=N.getSheetCommandTarget(o);if(!l)return;const{unitId:i,subUnitId:s,worksheet:a}=l,h=(e=this._sheetsFilterService.getFilterModel(i,s))==null?void 0:e.getRange();let m;if(h)m=this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[N.RangeProtectionPermissionViewPoint],worksheetTypes:[N.WorksheetFilterPermission,N.WorksheetViewPermission]},[h]);else{const p=(r=this._sheetsSelectionService.getCurrentLastSelection())==null?void 0:r.range;if(p){let y={...p};y=p.startColumn===p.endColumn&&p.startRow===p.endRow?N.expandToContinuousRange(y,{left:!0,right:!0,up:!0,down:!0},a):y,m=this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[N.RangeProtectionPermissionViewPoint],worksheetTypes:[N.WorksheetViewPermission,N.WorksheetFilterPermission]},[y],i,s)}else m=this._sheetPermissionCheckPermission.permissionCheckWithoutRange({rangeTypes:[N.RangeProtectionPermissionViewPoint],worksheetTypes:[N.WorksheetViewPermission,N.WorksheetFilterPermission]})}m||this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.filterErr"))}if(t.id===he.id){const o=t.params,{unitId:l,subUnitId:i}=o,s=(n=this._sheetsFilterService.getFilterModel(l,i))==null?void 0:n.getRange(),a=u.Tools.deepClone(s);a&&(a.startColumn=o.col,a.endColumn=o.col,this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[N.RangeProtectionPermissionViewPoint],worksheetTypes:[N.WorksheetFilterPermission,N.WorksheetViewPermission]},[a])||this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.filterErr")))}}))}};ne=ht([ie(0,u.Inject(c.SheetsFilterService)),ie(1,u.Inject(u.LocaleService)),ie(2,u.ICommandService),ie(3,u.Inject(N.SheetPermissionCheckController)),ie(4,u.Inject(u.Injector)),ie(5,u.Inject(N.SheetsSelectionsService))],ne);const Y=16,dt=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");class Ve{static drawNoCriteria(e,r,n,o){e.save(),X.Rect.drawWith(e,{radius:2,width:Y,height:Y,fill:o}),e.lineCap="square",e.strokeStyle=n,e.scale(r/Y,r/Y),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,r,n,o){e.save(),X.Rect.drawWith(e,{radius:2,width:Y,height:Y,fill:o}),e.scale(r/Y,r/Y),e.fillStyle=n,e.fill(dt),e.restore()}}var mt=Object.getOwnPropertyDescriptor,pt=(t,e,r,n)=>{for(var o=n>1?void 0:n?mt(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},we=(t,e)=>(r,n)=>e(r,n,t);const V=16,de=1;let Re=class extends X.Shape{constructor(e,r,n,o,l){super(e,r);_(this,"_cellWidth",0);_(this,"_cellHeight",0);_(this,"_filterParams");_(this,"_hovered",!1);this._contextService=n,this._commandService=o,this._themeService=l,this.setShapeProps(r),this.onPointerDown$.subscribeEvent(i=>this.onPointerDown(i)),this.onPointerEnter$.subscribeEvent(()=>this.onPointerEnter()),this.onPointerLeave$.subscribeEvent(()=>this.onPointerLeave())}setShapeProps(e){typeof e.cellHeight<"u"&&(this._cellHeight=e.cellHeight),typeof e.cellWidth<"u"&&(this._cellWidth=e.cellWidth),typeof e.filterParams<"u"&&(this._filterParams=e.filterParams),this.transformByState({width:e.width,height:e.height})}_draw(e){const r=this._cellHeight,n=this._cellWidth,o=V-n,l=V-r;e.save();const i=new Path2D;i.rect(o,l,n,r),e.clip(i);const{hasCriteria:s}=this._filterParams,a=this._themeService.getColorFromTheme("primary.600"),h=this._hovered?this._themeService.getColorFromTheme("gray.50"):"rgba(255, 255, 255, 1.0)";s?Ve.drawHasCriteria(e,V,a,h):Ve.drawNoCriteria(e,V,a,h),e.restore()}onPointerDown(e){if(e.button===2)return;const{col:r,unitId:n,subUnitId:o}=this._filterParams;this._contextService.getContextValue(te)||!this._commandService.hasCommand(he.id)||setTimeout(()=>{this._commandService.executeCommand(he.id,{unitId:n,subUnitId:o,col:r})},200)}onPointerEnter(){this._hovered=!0,this.makeDirty(!0)}onPointerLeave(){this._hovered=!1,this.makeDirty(!0)}};Re=pt([we(2,u.IContextService),we(3,u.ICommandService),we(4,u.Inject(u.ThemeService))],Re);var ft=Object.getOwnPropertyDescriptor,vt=(t,e,r,n)=>{for(var o=n>1?void 0:n?ft(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},z=(t,e)=>(r,n)=>e(r,n,t);const _t=1e3,gt=5e3;function Ct(t,e,r,n){switch(n){case u.VerticalAlign.TOP:return t+de;case u.VerticalAlign.MIDDLE:return t+Math.max(0,(r-V)/2);case u.VerticalAlign.BOTTOM:default:return e-V-de}}let Me=class extends u.RxDisposable{constructor(e,r,n,o,l,i,s,a){super();_(this,"_filterRangeShape",null);_(this,"_buttonRenderDisposable",null);_(this,"_filterButtonShapes",[]);this._context=e,this._injector=r,this._sheetSkeletonManagerService=n,this._sheetsFilterService=o,this._themeService=l,this._sheetInterceptorService=i,this._commandService=s,this._selectionRenderService=a,this._initRenderer()}dispose(){super.dispose(),this._disposeRendering()}_initRenderer(){this._sheetSkeletonManagerService.currentSkeleton$.pipe(S.switchMap(e=>{var s,a;if(!e)return S.of(null);const{unit:r,unitId:n}=this._context,o=((s=r.getActiveSheet())==null?void 0:s.getSheetId())||"",l=(a=this._sheetsFilterService.getFilterModel(n,o))!=null?a:void 0,i=()=>({unitId:n,worksheetId:o,filterModel:l,range:l==null?void 0:l.getRange(),skeleton:e.skeleton});return u.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(S.filter(([h])=>{var m;return h.type===u.CommandType.MUTATION&&((m=h.params)==null?void 0:m.unitId)===r.getUnitId()&&(c.FILTER_MUTATIONS.has(h.id)||h.id===N.SetRangeValuesMutation.id)}),S.throttleTime(20,void 0,{leading:!1,trailing:!0}),S.map(i),S.startWith(i()))}),S.takeUntil(this.dispose$)).subscribe(e=>{this._disposeRendering(),!(!e||!e.range)&&(this._renderRange(e.range,e.skeleton),this._renderButtons(e))})}_renderRange(e,r){const{scene:n}=this._context,{rowHeaderWidth:o,columnHeaderHeight:l}=r,i=this._filterRangeShape=new k.SelectionControl(n,_t,this._themeService,{rowHeaderWidth:o,columnHeaderHeight:l,enableAutoFill:!1,highlightHeader:!1}),s={range:e,primary:null,style:{fill:"rgba(0, 0, 0, 0.0)"}},a=k.attachSelectionWithCoord(s,r);i.updateRangeBySelectionWithCoord(a),i.setEvent(!1),n.makeDirty(!0)}_renderButtons(e){const{range:r,filterModel:n,unitId:o,skeleton:l,worksheetId:i}=e,{unit:s,scene:a}=this._context,h=s.getSheetBySheetId(i);if(!h)return;this._interceptCellContent(o,i,e.range);const{startColumn:m,endColumn:p,startRow:y}=r;for(let v=m;v<=p;v++){const T=`sheets-filter-button-${v}`,O=k.getCoordByCell(y,v,a,l),b=h.getComposedCellStyle(y,v),P=(b==null?void 0:b.vt)||u.VerticalAlign.BOTTOM,{startX:M,startY:w,endX:L,endY:D}=O,q=L-M,Z=D-w;if(Z<=de||q<=de)continue;const se=!!n.getFilterColumn(v),W=L-V-de,$=Ct(w,D,Z,P),U={left:W,top:$,height:V,width:V,zIndex:gt,cellHeight:Z,cellWidth:q,filterParams:{unitId:o,subUnitId:i,col:v,hasCriteria:se}},$e=this._injector.createInstance(Re,T,U);this._filterButtonShapes.push($e)}a.addObjects(this._filterButtonShapes),a.makeDirty()}_interceptCellContent(e,r,n){const{startRow:o,startColumn:l,endColumn:i}=n;this._buttonRenderDisposable=this._sheetInterceptorService.intercept(N.INTERCEPTOR_POINT.CELL_CONTENT,{effect:u.InterceptorEffectEnum.Style,handler:(s,a,h)=>{const{row:m,col:p,unitId:y,subUnitId:v}=a;return y!==e||v!==r||m!==o||p<l||p>i||((!s||s===a.rawData)&&(s={...a.rawData}),s.fontRenderExtension={...s==null?void 0:s.fontRenderExtension,rightOffset:V}),h(s)},priority:10})}_disposeRendering(){var e,r;(e=this._filterRangeShape)==null||e.dispose(),this._filterButtonShapes.forEach(n=>n.dispose()),(r=this._buttonRenderDisposable)==null||r.dispose(),this._filterRangeShape=null,this._buttonRenderDisposable=null,this._filterButtonShapes=[]}};Me=vt([z(1,u.Inject(u.Injector)),z(2,u.Inject(k.SheetSkeletonManagerService)),z(3,u.Inject(c.SheetsFilterService)),z(4,u.Inject(u.ThemeService)),z(5,u.Inject(N.SheetInterceptorService)),z(6,u.ICommandService),z(7,k.ISheetSelectionRenderService)],Me);var St=Object.getOwnPropertyDescriptor,Tt=(t,e,r,n)=>{for(var o=n>1?void 0:n?St(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},je=(t,e)=>(r,n)=>e(r,n,t);let me=class extends u.RxDisposable{constructor(t,e){super(),this._renderManagerService=t,this._sheetsRenderService=e,[c.SetSheetsFilterRangeMutation,c.SetSheetsFilterCriteriaMutation,c.RemoveSheetsFilterMutation,c.ReCalcSheetsFilterMutation].forEach(r=>this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(r.id))),this.disposeWithMe(this._renderManagerService.registerRenderModule(u.UniverInstanceType.UNIVER_SHEET,[Me]))}};me=Tt([je(0,X.IRenderManagerService),je(1,u.Inject(k.SheetsRenderService))],me);var Et=Object.defineProperty,Ot=Object.getOwnPropertyDescriptor,yt=(t,e,r)=>e in t?Et(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,It=(t,e,r,n)=>{for(var o=n>1?void 0:n?Ot(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},Qe=(t,e)=>(r,n)=>e(r,n,t),Ge=(t,e,r)=>yt(t,typeof e!="symbol"?e+"":e,r);const Ft="SHEET_FILTER_UI_PLUGIN";C.UniverSheetsFilterMobileUIPlugin=class extends u.Plugin{constructor(e=Te,r,n){super(),this._config=e,this._injector=r,this._configService=n;const{menu:o,...l}=u.merge({},Te,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(We,l)}onStarting(){[[ne],[me]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(ne)}onRendered(){this._injector.get(me)}},Ge(C.UniverSheetsFilterMobileUIPlugin,"type",u.UniverInstanceType.UNIVER_SHEET),Ge(C.UniverSheetsFilterMobileUIPlugin,"pluginName",Ft),C.UniverSheetsFilterMobileUIPlugin=It([u.DependentOn(c.UniverSheetsFilterPlugin),Qe(1,u.Inject(u.Injector)),Qe(2,u.IConfigService)],C.UniverSheetsFilterMobileUIPlugin);var x=function(){return x=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++){e=arguments[r];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t},x.apply(this,arguments)},Nt=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]]);return r},oe=I.forwardRef(function(t,e){var r=t.icon,n=t.id,o=t.className,l=t.extend,i=Nt(t,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(n," ").concat(o||"").trim(),a=I.useRef("_".concat(At()));return Ye(r,"".concat(n),{defIds:r.defIds,idSuffix:a.current},x({ref:e,className:s},i),l)});function Ye(t,e,r,n,o){return I.createElement(t.tag,x(x({key:e},bt(t,r,o)),n),(Pt(t,r).children||[]).map(function(l,i){return Ye(l,"".concat(e,"-").concat(t.tag,"-").concat(i),r,void 0,o)}))}function bt(t,e,r){var n=x({},t.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1),t.tag==="mask"&&n.id&&(n.id=n.id+e.idSuffix),Object.entries(n).forEach(function(l){var i=l[0],s=l[1];i==="mask"&&typeof s=="string"&&(n[i]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))});var o=e.defIds;return!o||o.length===0||(t.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(function(l){var i=l[0],s=l[1];typeof s=="string"&&(n[i]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),n}function Pt(t,e){var r,n=e.defIds;return!n||n.length===0?t:t.tag==="defs"&&(!((r=t.children)===null||r===void 0)&&r.length)?x(x({},t),{children:t.children.map(function(o){return typeof o.attrs.id=="string"&&n&&n.includes(o.attrs.id)?x(x({},o),{attrs:x(x({},o.attrs),{id:o.attrs.id+e.idSuffix})}):o})}):t}function At(){return Math.random().toString(36).substring(2,8)}oe.displayName="UniverIcon";var wt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 20 20",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M10 1.05957C10.356 1.05957 10.6816 1.26162 10.8408 1.58008L18.8408 17.5801L18.8799 17.668C19.0486 18.1134 18.8551 18.6232 18.4199 18.8408C17.9557 19.0727 17.3913 18.8841 17.1592 18.4199L10 4.10156L2.84082 18.4199C2.60871 18.8841 2.04434 19.0727 1.58008 18.8408C1.11587 18.6087 0.92731 18.0443 1.15918 17.5801L9.15918 1.58008C9.31841 1.26162 9.64395 1.05957 10 1.05957Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M15.3337 11.7261L15.4294 11.731C15.9035 11.779 16.2732 12.1798 16.2732 12.6665C16.2732 13.1532 15.9035 13.554 15.4294 13.602L15.3337 13.6069H4.66675C4.1476 13.6069 3.72632 13.1856 3.72632 12.6665C3.72632 12.1474 4.1476 11.7261 4.66675 11.7261H15.3337Z"}}]},qe=I.forwardRef(function(t,e){return I.createElement(oe,Object.assign({},t,{id:"a-icon",ref:e,icon:wt}))});qe.displayName="AIcon";var Rt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 20 20",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M17.0596 10C17.0596 6.10087 13.8992 2.94043 10 2.94043C6.10087 2.94043 2.94043 6.10087 2.94043 10C2.94043 13.8992 6.10087 17.0596 10 17.0596C13.8992 17.0596 17.0596 13.8992 17.0596 10ZM18.9404 10C18.9404 14.9374 14.9374 18.9404 10 18.9404C5.06257 18.9404 1.05957 14.9374 1.05957 10C1.05957 5.06257 5.06257 1.05957 10 1.05957C14.9374 1.05957 18.9404 5.06257 18.9404 10Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.29492 4.13476C4.63911 3.79057 5.1845 3.76906 5.55371 4.07031L5.625 4.13476L16.0244 14.5352L16.0889 14.6064C16.3902 14.9757 16.3686 15.52 16.0244 15.8643C15.6573 16.2313 15.0624 16.2313 14.6953 15.8643L4.29492 5.46484L4.23047 5.39355C3.92922 5.02434 3.95073 4.47895 4.29492 4.13476Z"}}]},Ze=I.forwardRef(function(t,e){return I.createElement(oe,Object.assign({},t,{id:"ban-icon",ref:e,icon:Rt}))});Ze.displayName="BanIcon";var Mt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.32182 2.60967C2.98161 2.60967 2.79671 3.0074 3.01601 3.2675L6.85819 7.8246C6.94943 7.93282 6.99947 8.06981 6.99947 8.21136V12.7338C6.99947 12.898 7.0998 13.0455 7.2525 13.1058L8.73833 13.6928C9.00085 13.7965 9.28531 13.6031 9.28531 13.3208V8.21136C9.28531 8.06981 9.33535 7.93282 9.42659 7.8246L13.2688 3.2675C13.4881 3.0074 13.3032 2.60967 12.963 2.60967H3.32182ZM2.09858 4.04101C1.22139 3.0006 1.96097 1.40967 3.32182 1.40967H12.963C14.3238 1.40967 15.0634 3.0006 14.1862 4.04101L10.4853 8.43054V13.3208C10.4853 14.4498 9.34747 15.2237 8.29742 14.8089L6.81158 14.2219C6.20078 13.9806 5.79947 13.3905 5.79947 12.7338V8.43054L2.09858 4.04101Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ke=I.forwardRef(function(t,e){return I.createElement(oe,Object.assign({},t,{id:"filter-icon",ref:e,icon:Mt}))});Ke.displayName="FilterIcon";var Lt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.00016 1.33203C6.68162 1.33203 5.39269 1.72302 4.29636 2.45557C3.20004 3.18811 2.34555 4.2293 1.84097 5.44747C1.33638 6.66565 1.20436 8.00609 1.4616 9.2993C1.71883 10.5925 2.35377 11.7804 3.28612 12.7127C4.21847 13.6451 5.40636 14.28 6.69956 14.5373C7.99277 14.7945 9.33321 14.6625 10.5514 14.1579C11.7696 13.6533 12.8108 12.7988 13.5433 11.7025C14.2758 10.6062 14.6668 9.31724 14.6668 7.9987C14.6649 6.23118 13.9619 4.53662 12.7121 3.2868C11.4622 2.03697 9.76768 1.33397 8.00016 1.33203ZM7.66683 3.9987C7.86461 3.9987 8.05795 4.05735 8.2224 4.16723C8.38685 4.27711 8.51502 4.43329 8.59071 4.61601C8.6664 4.79874 8.6862 4.99981 8.64762 5.19379C8.60903 5.38777 8.51379 5.56595 8.37394 5.7058C8.23409 5.84566 8.0559 5.9409 7.86192 5.97948C7.66794 6.01807 7.46687 5.99826 7.28415 5.92258C7.10142 5.84689 6.94524 5.71872 6.83536 5.55427C6.72548 5.38982 6.66683 5.19648 6.66683 4.9987C6.66683 4.73348 6.77219 4.47913 6.95972 4.29159C7.14726 4.10405 7.40162 3.9987 7.66683 3.9987ZM9.3335 11.332H6.66683C6.49002 11.332 6.32045 11.2618 6.19543 11.1368C6.0704 11.0117 6.00016 10.8422 6.00016 10.6654C6.00016 10.4886 6.0704 10.319 6.19543 10.194C6.32045 10.0689 6.49002 9.9987 6.66683 9.9987H7.3335V7.9987H6.66683C6.49002 7.9987 6.32045 7.92846 6.19543 7.80343C6.0704 7.67841 6.00016 7.50884 6.00016 7.33203C6.00016 7.15522 6.0704 6.98565 6.19543 6.86063C6.32045 6.7356 6.49002 6.66536 6.66683 6.66536H8.00016C8.17698 6.66536 8.34655 6.7356 8.47157 6.86063C8.59659 6.98565 8.66683 7.15522 8.66683 7.33203V9.9987H9.3335C9.51031 9.9987 9.67988 10.0689 9.8049 10.194C9.92993 10.319 10.0002 10.4886 10.0002 10.6654C10.0002 10.8422 9.92993 11.0117 9.8049 11.1368C9.67988 11.2618 9.51031 11.332 9.3335 11.332Z"}}]},Xe=I.forwardRef(function(t,e){return I.createElement(oe,Object.assign({},t,{id:"info-icon",ref:e,icon:Lt}))});Xe.displayName="InfoIcon";var $t={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8 15C11.866 15 15 11.866 15 8C15 4.13401 11.866 1 8 1C4.13401 1 1 4.13401 1 8C1 11.866 4.13401 15 8 15ZM11.7245 6.42417C11.9588 6.18985 11.9588 5.80995 11.7245 5.57564C11.4901 5.34132 11.1102 5.34132 10.8759 5.57564L7.3002 9.15137L5.72446 7.57564C5.49014 7.34132 5.11025 7.34132 4.87593 7.57564C4.64162 7.80995 4.64162 8.18985 4.87593 8.42417L6.87593 10.4242C7.11025 10.6585 7.49014 10.6585 7.72446 10.4242L11.7245 6.42417Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ze=I.forwardRef(function(t,e){return I.createElement(oe,Object.assign({},t,{id:"success-icon",ref:e,icon:$t}))});ze.displayName="SuccessIcon";function Ut(t){const{model:e}=t,r=g.useDependency(u.LocaleService),n=g.useObservable(e.cellFillColors$,[],!0),o=g.useObservable(e.cellTextColors$,[],!0),l=I.useCallback(s=>{e.onFilterCheckToggled(s)},[e]),i=I.useCallback(s=>{e.onFilterCheckToggled(s,!1)},[e]);return 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:d.jsxs("div",{"data-u-comp":"sheets-filter-panel",className:F.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",F.borderClassName),children:[n.length>1&&d.jsxs("div",{children:[d.jsx("div",{className:"univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white",children:r.t("sheets-filter.panel.filter-by-cell-fill-color")}),d.jsx("div",{className:"univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2",children:n.map((s,a)=>d.jsxs("div",{className:"univer-relative univer-h-6 univer-w-6",onClick:()=>l(s),children:[s.color?d.jsx("button",{type:"button",className:F.clsx("univer-box-border univer-h-6 univer-w-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:s.color}}):d.jsx(Ze,{className:"univer-h-6 univer-w-6 univer-cursor-pointer univer-rounded-full hover:univer-ring-2 hover:univer-ring-offset-2 hover:univer-ring-offset-white"}),s.checked&&d.jsx(Je,{})]},`sheets-filter-cell-fill-color-${a}`))})]}),o.length>1&&d.jsxs("div",{children:[d.jsx("div",{className:"univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white",children:r.t("sheets-filter.panel.filter-by-cell-text-color")}),d.jsx("div",{className:"univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2",children:o.map((s,a)=>d.jsxs("div",{className:"univer-relative univer-h-6 univer-w-6",onClick:()=>i(s),children:[d.jsx("div",{className:"univer-box-border univer-flex univer-h-full univer-w-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:d.jsx(qe,{style:{color:s.color}})}),s.checked&&d.jsx(Je,{})]},`sheets-filter-cell-text-color-${a}`))})]}),n.length<=1&&o.length<=1&&d.jsx("div",{className:"univer-flex univer-h-full univer-w-full univer-items-center univer-justify-center univer-text-sm univer-text-gray-900 dark:!univer-text-gray-200",children:r.t("sheets-filter.panel.filter-by-color-none")})]})})}function Je(){return d.jsx("div",{className:"univer-absolute -univer-bottom-0.5 -univer-right-0.5 univer-flex univer-h-3 univer-w-3 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-full univer-bg-white",children:d.jsx(ze,{className:"univer-h-full univer-w-full univer-font-bold univer-text-[#418F1F]"})})}function kt(t){var v,T;const{model:e}=t,r=g.useDependency(u.LocaleService),n=g.useObservable(e.conditionItem$,void 0),o=g.useObservable(e.filterConditionFormParams$,void 0),l=o!=null&&o.and?"AND":"OR",i=I.useCallback(O=>{e.onConditionFormChange({and:O==="AND"})},[e]),s=Bt(r),a=I.useCallback(O=>{e.onPrimaryConditionChange(O)},[e]),h=Dt(r),m=I.useCallback(O=>{e.onConditionFormChange(O)},[e]),p=r.t("sheets-filter.panel.input-values-placeholder");function y(O,b,P){const M=f.getItemByOperator(O).numOfParameters===1;return d.jsxs(d.Fragment,{children:[P==="operator2"&&d.jsxs(F.RadioGroup,{value:l,onChange:i,children:[d.jsx(F.Radio,{value:"AND",children:r.t("sheets-filter.panel.and")}),d.jsx(F.Radio,{value:"OR",children:r.t("sheets-filter.panel.or")})]}),d.jsx(F.Select,{value:O,options:h,onChange:w=>m({[P]:w})}),M&&d.jsx("div",{children:d.jsx(F.Input,{className:"univer-mt-2",value:b,placeholder:p,onChange:w=>m({[P==="operator1"?"val1":"val2"]:w})})})]})}return 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:n&&o&&d.jsxs(d.Fragment,{children:[d.jsx(F.Select,{value:n.operator,options:s,onChange:a}),f.getItemByOperator(n.operator).numOfParameters!==0?d.jsxs("div",{"data-u-comp":"sheets-filter-panel-conditions-container-inner",className:F.clsx("univer-mt-2 univer-flex-grow univer-overflow-hidden univer-rounded-md univer-p-2",F.borderClassName),children:[n.numOfParameters>=1&&y(o.operator1,(v=o.val1)!=null?v:"","operator1"),n.numOfParameters>=2&&y(o.operator2,(T=o.val2)!=null?T:"","operator2"),d.jsxs("div",{"data-u-comp":"sheets-filter-panel-conditions-desc",className:"univer-mt-2 univer-text-xs univer-text-gray-500",children:[r.t("sheets-filter.panel.?"),d.jsx("br",{}),r.t("sheets-filter.panel.*")]})]}):null]})})}function Bt(t){const e=t.getCurrentLocale();return I.useMemo(()=>[{options:[{label:t.t(f.NONE.label),value:f.NONE.operator}]},{options:[{label:t.t(f.EMPTY.label),value:f.EMPTY.operator},{label:t.t(f.NOT_EMPTY.label),value:f.NOT_EMPTY.operator}]},{options:[{label:t.t(f.TEXT_CONTAINS.label),value:f.TEXT_CONTAINS.operator},{label:t.t(f.DOES_NOT_CONTAIN.label),value:f.DOES_NOT_CONTAIN.operator},{label:t.t(f.STARTS_WITH.label),value:f.STARTS_WITH.operator},{label:t.t(f.ENDS_WITH.label),value:f.ENDS_WITH.operator},{label:t.t(f.EQUALS.label),value:f.EQUALS.operator}]},{options:[{label:t.t(f.GREATER_THAN.label),value:f.GREATER_THAN.operator},{label:t.t(f.GREATER_THAN_OR_EQUAL.label),value:f.GREATER_THAN_OR_EQUAL.operator},{label:t.t(f.LESS_THAN.label),value:f.LESS_THAN.operator},{label:t.t(f.LESS_THAN_OR_EQUAL.label),value:f.LESS_THAN_OR_EQUAL.operator},{label:t.t(f.EQUAL.label),value:f.EQUAL.operator},{label:t.t(f.NOT_EQUAL.label),value:f.NOT_EQUAL.operator},{label:t.t(f.BETWEEN.label),value:f.BETWEEN.operator},{label:t.t(f.NOT_BETWEEN.label),value:f.NOT_BETWEEN.operator}]},{options:[{label:t.t(f.CUSTOM.label),value:f.CUSTOM.operator}]}],[e,t])}function Dt(t){const e=t.getCurrentLocale();return I.useMemo(()=>f.ALL_CONDITIONS.filter(r=>r.numOfParameters!==2).map(r=>({label:t.t(r.label),value:r.operator})),[e,t])}function xt(t){const{model:e}=t,r=g.useDependency(u.LocaleService),n=g.useObservable(e.searchString$,"",!0),o=g.useObservable(e.filterItems$,void 0,!0),l=r.t("sheets-filter.panel.filter-only"),i=Ie(o),s=i.checked>0&&i.unchecked===0,a=i.checked>0&&i.unchecked>0,h=e.treeMapCache,m=I.useCallback(()=>{e.onCheckAllToggled(!s)},[e,s]),p=I.useCallback(v=>{e.setSearchString(v)},[e]);function y(v){let T=[];return v.forEach(O=>{O.checked&&T.push(O.key),O.children&&(T=T.concat(y(O.children)))}),T}return 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:[d.jsx(F.Input,{autoFocus:!0,value:n,placeholder:r.t("sheets-filter.panel.search-placeholder"),onChange:p}),d.jsxs("div",{"data-u-comp":"sheets-filter-panel",className:F.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",F.borderClassName),children:[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: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-pb-0 univer-pl-5 univer-pr-0.5 univer-pt-0 univer-text-sm",children:[d.jsx(F.Checkbox,{indeterminate:a,disabled:o.length===0,checked:s,onChange:m}),d.jsx("span",{"data-u-comp":"sheets-filter-panel-values-item-text",className:"univer-mx-1 univer-inline-block univer-flex-shrink univer-overflow-hidden univer-text-ellipsis univer-whitespace-nowrap univer-text-gray-900 dark:!univer-text-white",children:`${r.t("sheets-filter.panel.select-all")}`}),d.jsx("span",{"data-u-comp":"sheets-filter-panel-values-item-count",className:"univer-text-gray-400 dark:!univer-text-gray-500",children:`(${i.checked}/${i.checked+i.unchecked})`})]})}),d.jsx("div",{"data-u-comp":"sheets-filter-panel-values-virtual",className:"univer-flex-grow",children:d.jsx(F.Tree,{data:o,defaultExpandAll:!1,valueGroup:y(o),onChange:v=>{e.onFilterCheckToggled(v)},defaultCache:h,itemHeight:28,treeNodeClassName:`
|
|
10
|
+
(function(C,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@univerjs/core"),require("@univerjs/sheets-filter"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/rpc"),require("@univerjs/design"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-filter","@univerjs/sheets-ui","@univerjs/ui","@univerjs/engine-render","@univerjs/sheets","rxjs","@univerjs/rpc","@univerjs/design","react/jsx-runtime","react"],u):(C=typeof globalThis<"u"?globalThis:C||self,u(C.UniverSheetsFilterUi={},C.UniverCore,C.UniverSheetsFilter,C.UniverSheetsUi,C.UniverUi,C.UniverEngineRender,C.UniverSheets,C.rxjs,C.UniverRpc,C.UniverDesign,C.React,C.React))})(this,(function(C,u,c,M,g,X,N,S,fe,F,d,I){"use strict";var sr=Object.defineProperty;var ar=(C,u,c)=>u in C?sr(C,u,{enumerable:!0,configurable:!0,writable:!0,value:c}):C[u]=c;var _=(C,u,c)=>ar(C,typeof u!="symbol"?u+"":u,c);var Oe;var A=(t=>(t[t.FIRST=0]="FIRST",t[t.SECOND=1]="SECOND",t))(A||{}),E=(t=>(t.NONE="none",t.STARTS_WITH="startsWith",t.DOES_NOT_START_WITH="doesNotStartWith",t.ENDS_WITH="endsWith",t.DOES_NOT_END_WITH="doesNotEndWith",t.CONTAINS="contains",t.DOES_NOT_CONTAIN="doesNotContain",t.EQUALS="equals",t.NOT_EQUALS="notEquals",t.EMPTY="empty",t.NOT_EMPTY="notEmpty",t.BETWEEN="between",t.NOT_BETWEEN="notBetween",t.CUSTOM="custom",t))(E||{}),f;(t=>{t.NONE={label:"sheets-filter.conditions.none",operator:E.NONE,order:A.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw new Error("[FilterConditionItems.NONE]: should not have initial form params!")},testMappingParams:i=>i.operator1===E.NONE,mapToFilterColumn:()=>null,testMappingFilterColumn:i=>!i.customFilters&&!i.filters?{}:!1},t.EMPTY={label:"sheets-filter.conditions.empty",operator:E.EMPTY,order:A.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw new Error("[FilterConditionItems.EMPTY]: should not have initial form params!")},testMappingParams:({operator1:i})=>i===E.EMPTY,mapToFilterColumn:()=>({customFilters:{customFilters:[{val:""}]}}),testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.val===""&&s.operator===void 0?{operator1:E.EMPTY}:!1}},t.NOT_EMPTY={label:"sheets-filter.conditions.not-empty",operator:E.NOT_EMPTY,order:A.SECOND,numOfParameters:0,getDefaultFormParams:()=>{throw new Error("[FilterConditionItems.NOT_EMPTY]: should not have initial form params!")},testMappingParams:({operator1:i})=>i===E.NOT_EMPTY,mapToFilterColumn:()=>({customFilters:{customFilters:[{val:"",operator:c.CustomFilterOperator.NOT_EQUALS}]}}),testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.val===" "&&s.operator===c.CustomFilterOperator.NOT_EQUALS?{operator1:E.NOT_EMPTY}:!1}},t.TEXT_CONTAINS={label:"sheets-filter.conditions.text-contains",operator:E.CONTAINS,order:A.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:E.CONTAINS,val1:""}),testMappingParams:i=>{const[s]=H(i);return s===E.CONTAINS},mapToFilterColumn:i=>{const{val1:s}=i;return s===""?null:{customFilters:{customFilters:[{val:`*${s}*`}]}}},testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0],a=s.val.toString();return!s.operator&&a.startsWith("*")&&a.endsWith("*")?{operator1:E.CONTAINS,val1:a.slice(1,-1)}:!1}},t.DOES_NOT_CONTAIN={label:"sheets-filter.conditions.does-not-contain",operator:E.DOES_NOT_CONTAIN,order:A.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:E.DOES_NOT_CONTAIN,val1:""}),mapToFilterColumn:i=>({customFilters:{customFilters:[{val:`*${i.val1}*`,operator:c.CustomFilterOperator.NOT_EQUALS}]}}),testMappingParams:i=>{const[s]=H(i);return s===E.DOES_NOT_CONTAIN},testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0],a=s.val.toString();return s.operator===c.CustomFilterOperator.NOT_EQUALS&&a.startsWith("*")&&a.endsWith("*")?{operator1:E.DOES_NOT_CONTAIN,val1:a.slice(1,-1)}:!1}},t.STARTS_WITH={label:"sheets-filter.conditions.starts-with",operator:E.STARTS_WITH,order:A.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:E.STARTS_WITH,val1:""}),mapToFilterColumn:i=>({customFilters:{customFilters:[{val:`${i.val1}*`}]}}),testMappingParams:i=>{const[s]=H(i);return s===E.STARTS_WITH},testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0],a=s.val.toString();return!s.operator&&a.endsWith("*")&&!a.startsWith("*")?{operator1:E.STARTS_WITH,val1:a.slice(0,-1)}:!1}},t.ENDS_WITH={label:"sheets-filter.conditions.ends-with",operator:E.ENDS_WITH,order:A.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:E.ENDS_WITH,val1:""}),mapToFilterColumn:i=>({customFilters:{customFilters:[{val:`*${i.val1}`}]}}),testMappingParams:i=>{const[s]=H(i);return s===E.ENDS_WITH},testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0],a=s.val.toString();return!s.operator&&a.startsWith("*")&&!a.endsWith("*")?{operator1:E.ENDS_WITH,val1:a.slice(1)}:!1}},t.EQUALS={label:"sheets-filter.conditions.equals",operator:E.EQUALS,order:A.FIRST,numOfParameters:1,getDefaultFormParams:()=>({operator1:E.EQUALS,val1:""}),testMappingParams:i=>{const[s]=H(i);return s===E.EQUALS},mapToFilterColumn:i=>{const{val1:s}=i;return s===""?null:{customFilters:{customFilters:[{val:s}]}}},testMappingFilterColumn:i=>{var s,a,h;return((a=(s=i.filters)==null?void 0:s.filters)==null?void 0:a.length)===1?{operator1:E.EQUALS,val1:""}:((h=i.customFilters)==null?void 0:h.customFilters.length)===1&&!i.customFilters.customFilters[0].operator?{operator1:E.EQUALS,val1:i.customFilters.customFilters[0].val.toString()}:!1}},t.GREATER_THAN={label:"sheets-filter.conditions.greater-than",operator:c.CustomFilterOperator.GREATER_THAN,numOfParameters:1,order:A.FIRST,getDefaultFormParams:()=>({operator1:c.CustomFilterOperator.GREATER_THAN,val1:""}),mapToFilterColumn:i=>({customFilters:{customFilters:[{val:i.val1,operator:c.CustomFilterOperator.GREATER_THAN}]}}),testMappingParams:i=>{const[s]=H(i);return s===c.CustomFilterOperator.GREATER_THAN},testMappingFilterColumn:i=>{var a;if(((a=i.customFilters)==null?void 0:a.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.operator!==c.CustomFilterOperator.GREATER_THAN?!1:{operator1:c.CustomFilterOperator.GREATER_THAN,val1:s.val.toString()}}},t.GREATER_THAN_OR_EQUAL={label:"sheets-filter.conditions.greater-than-or-equal",operator:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL,numOfParameters:1,order:A.FIRST,getDefaultFormParams:()=>({operator1:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:""}),testMappingParams:i=>{const[s]=H(i);return s===c.CustomFilterOperator.GREATER_THAN_OR_EQUAL},mapToFilterColumn:i=>({customFilters:{customFilters:[{val:i.val1,operator:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL}]}}),testMappingFilterColumn:i=>{var a;if(((a=i.customFilters)==null?void 0:a.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.operator!==c.CustomFilterOperator.GREATER_THAN_OR_EQUAL?!1:{operator1:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:s.val.toString()}}},t.LESS_THAN={label:"sheets-filter.conditions.less-than",operator:c.CustomFilterOperator.LESS_THAN,numOfParameters:1,order:A.FIRST,getDefaultFormParams:()=>({operator1:c.CustomFilterOperator.LESS_THAN,val1:""}),testMappingParams:i=>{const[s]=H(i);return s===c.CustomFilterOperator.LESS_THAN},mapToFilterColumn:i=>({customFilters:{customFilters:[{val:i.val1,operator:c.CustomFilterOperator.LESS_THAN}]}}),testMappingFilterColumn:i=>{var a;if(((a=i.customFilters)==null?void 0:a.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.operator!==c.CustomFilterOperator.LESS_THAN?!1:{operator1:c.CustomFilterOperator.LESS_THAN,val1:s.val.toString()}}},t.LESS_THAN_OR_EQUAL={label:"sheets-filter.conditions.less-than-or-equal",operator:c.CustomFilterOperator.LESS_THAN_OR_EQUAL,numOfParameters:1,order:A.FIRST,getDefaultFormParams:()=>({operator1:c.CustomFilterOperator.LESS_THAN_OR_EQUAL,val1:""}),testMappingParams:i=>{const[s]=H(i);return s===c.CustomFilterOperator.LESS_THAN_OR_EQUAL},mapToFilterColumn:i=>({customFilters:{customFilters:[{val:i.val1,operator:c.CustomFilterOperator.LESS_THAN_OR_EQUAL}]}}),testMappingFilterColumn:i=>{var a;if(((a=i.customFilters)==null?void 0:a.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.operator!==c.CustomFilterOperator.LESS_THAN_OR_EQUAL?!1:{operator1:c.CustomFilterOperator.LESS_THAN_OR_EQUAL,val1:s.val.toString()}}},t.EQUAL={label:"sheets-filter.conditions.equal",operator:c.CustomFilterOperator.EQUAL,numOfParameters:1,order:A.FIRST,getDefaultFormParams:()=>({operator1:c.CustomFilterOperator.EQUAL,val1:""}),testMappingParams:i=>{const[s]=H(i);return s===c.CustomFilterOperator.EQUAL},mapToFilterColumn:i=>({customFilters:{customFilters:[{val:i.val1,operator:c.CustomFilterOperator.EQUAL}]}}),testMappingFilterColumn:i=>{var a;if(((a=i.customFilters)==null?void 0:a.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.operator!==c.CustomFilterOperator.EQUAL?!1:{operator1:c.CustomFilterOperator.EQUAL,val1:s.val.toString()}}},t.NOT_EQUAL={label:"sheets-filter.conditions.not-equal",operator:c.CustomFilterOperator.NOT_EQUALS,numOfParameters:1,order:A.FIRST,getDefaultFormParams:()=>({operator1:c.CustomFilterOperator.NOT_EQUALS,val1:""}),testMappingParams:i=>{const[s]=H(i);return s===c.CustomFilterOperator.NOT_EQUALS},mapToFilterColumn:i=>({customFilters:{customFilters:[{val:i.val1,operator:c.CustomFilterOperator.NOT_EQUALS}]}}),testMappingFilterColumn:i=>{var a;if(((a=i.customFilters)==null?void 0:a.customFilters.length)!==1)return!1;const s=i.customFilters.customFilters[0];return s.operator!==c.CustomFilterOperator.NOT_EQUALS?!1:{operator1:c.CustomFilterOperator.NOT_EQUALS,val1:s.val.toString()}}},t.BETWEEN={label:"sheets-filter.conditions.between",operator:E.BETWEEN,order:A.SECOND,numOfParameters:2,getDefaultFormParams:()=>({and:!0,operator1:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:"",operator2:c.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:""}),testMappingParams:i=>{const{and:s,operator1:a,operator2:h}=i;if(!s)return!1;const m=[a,h];return m.includes(c.CustomFilterOperator.GREATER_THAN_OR_EQUAL)&&m.includes(c.CustomFilterOperator.LESS_THAN_OR_EQUAL)},mapToFilterColumn:i=>{const{val1:s,val2:a,operator1:h}=i,m=h===c.CustomFilterOperator.GREATER_THAN_OR_EQUAL;return{customFilters:{and:u.BooleanNumber.TRUE,customFilters:[{val:m?s:a,operator:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL},{val:m?a:s,operator:c.CustomFilterOperator.LESS_THAN_OR_EQUAL}]}}},testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==2)return!1;const[s,a]=i.customFilters.customFilters;return s.operator===c.CustomFilterOperator.GREATER_THAN_OR_EQUAL&&a.operator===c.CustomFilterOperator.LESS_THAN_OR_EQUAL&&i.customFilters.and?{and:!0,operator1:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:s.val.toString(),operator2:c.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:a.val.toString()}:a.operator===c.CustomFilterOperator.GREATER_THAN_OR_EQUAL&&s.operator===c.CustomFilterOperator.LESS_THAN_OR_EQUAL&&i.customFilters.and?{and:!0,operator1:c.CustomFilterOperator.GREATER_THAN_OR_EQUAL,val1:a.val.toString(),operator2:c.CustomFilterOperator.LESS_THAN_OR_EQUAL,val2:s.val.toLocaleString()}:!1}},t.NOT_BETWEEN={label:"sheets-filter.conditions.not-between",operator:E.NOT_BETWEEN,order:A.SECOND,numOfParameters:2,getDefaultFormParams:()=>({operator1:c.CustomFilterOperator.LESS_THAN,val1:"",operator2:c.CustomFilterOperator.GREATER_THAN,val2:""}),testMappingParams:i=>{const{and:s,operator1:a,operator2:h}=i;if(s)return!1;const m=[a,h];return m.includes(c.CustomFilterOperator.GREATER_THAN)&&m.includes(c.CustomFilterOperator.LESS_THAN)},mapToFilterColumn:i=>{const{val1:s,val2:a,operator1:h}=i,m=h===c.CustomFilterOperator.GREATER_THAN;return{customFilters:{customFilters:[{val:m?s:a,operator:c.CustomFilterOperator.GREATER_THAN},{val:m?a:s,operator:c.CustomFilterOperator.LESS_THAN}]}}},testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==2)return!1;const[s,a]=i.customFilters.customFilters;return s.operator===c.CustomFilterOperator.LESS_THAN&&a.operator===c.CustomFilterOperator.GREATER_THAN&&!i.customFilters.and?{operator1:c.CustomFilterOperator.LESS_THAN,val1:s.val.toString(),operator2:c.CustomFilterOperator.GREATER_THAN,val2:a.val.toString()}:a.operator===c.CustomFilterOperator.LESS_THAN&&s.operator===c.CustomFilterOperator.GREATER_THAN&&!i.customFilters.and?{operator1:c.CustomFilterOperator.GREATER_THAN,val1:a.val.toString(),operator2:c.CustomFilterOperator.LESS_THAN,val2:s.val.toLocaleString()}:!1}},t.CUSTOM={label:"sheets-filter.conditions.custom",operator:E.CUSTOM,order:A.SECOND,numOfParameters:2,getDefaultFormParams:()=>({operator1:E.NONE,val1:"",operator2:E.NONE,val2:""}),testMappingParams:()=>!0,mapToFilterColumn:i=>{const{and:s,val1:a,val2:h,operator1:m,operator2:p}=i;function y(L,w){for(const $ of t.ALL_CONDITIONS)if($.operator===L)return $.mapToFilterColumn({val1:w,operator1:L})}const v=!m||m===t.NONE.operator,T=!p||p===t.NONE.operator;if(v&&T)return t.NONE.mapToFilterColumn({});if(v)return y(p,h);if(T)return y(m,a);const O=y(m,a),b=y(p,h),P={customFilters:[O.customFilters.customFilters[0],b.customFilters.customFilters[0]]};return s&&(P.and=u.BooleanNumber.TRUE),{customFilters:P}},testMappingFilterColumn:i=>{var h;if(((h=i.customFilters)==null?void 0:h.customFilters.length)!==2)return!1;const s=i.customFilters.customFilters.map(m=>l({customFilters:{customFilters:[m]}})),a={operator1:s[0][0].operator,val1:s[0][1].val1,operator2:s[1][0].operator,val2:s[1][1].val1};return i.customFilters.and&&(a.and=!0),a}},t.ALL_CONDITIONS=[t.NONE,t.EMPTY,t.NOT_EMPTY,t.TEXT_CONTAINS,t.DOES_NOT_CONTAIN,t.STARTS_WITH,t.ENDS_WITH,t.EQUALS,t.GREATER_THAN,t.GREATER_THAN_OR_EQUAL,t.LESS_THAN,t.LESS_THAN_OR_EQUAL,t.EQUAL,t.NOT_EQUAL,t.BETWEEN,t.NOT_BETWEEN,t.CUSTOM];function e(i){const s=t.ALL_CONDITIONS.find(a=>a.operator===i);if(!s)throw new Error(`[SheetsFilter]: no condition item found for operator: ${i}`);return s}t.getItemByOperator=e;function r(i,s){for(const a of t.ALL_CONDITIONS.filter(h=>h.numOfParameters===s))if(a.numOfParameters!==0&&a.testMappingParams(i))return a;for(const a of t.ALL_CONDITIONS)if(a.testMappingParams(i))return a;throw new Error("[SheetsFilter]: no condition item can be mapped from the filter map params!")}t.testMappingParams=r;function n(i){const s=t.ALL_CONDITIONS.find(a=>a.operator===i);return(s==null?void 0:s.numOfParameters)===0?{operator1:s.operator}:s.getDefaultFormParams()}t.getInitialFormParams=n;function o(i,s){return i.mapToFilterColumn(s)}t.mapToFilterColumn=o;function l(i){if(!i)return[t.NONE,{}];for(const s of t.ALL_CONDITIONS){const a=s.testMappingFilterColumn(i);if(a)return[s,a]}return[t.NONE,{}]}t.testMappingFilterColumn=l})(f||(f={}));function H(t){const{operator1:e,operator2:r,val1:n,val2:o}=t;if(e&&r)throw new Error("Both operator1 and operator2 are set!");if(!e&&!r)throw new Error("Neither operator1 and operator2 and both not set!");return e?[e,n]:[r,o]}function Ie(t){const e=[],r=[];let n=0,o=0;function l(i){i.leaf&&(i.checked?(e.push(i),n+=i.count):(r.push(i),o+=i.count)),i.children&&i.children.forEach(l)}return t.forEach(l),{checkedItems:e,uncheckedItems:r,checked:n,unchecked:o}}var nt=Object.getOwnPropertyDescriptor,ot=(t,e,r,n)=>{for(var o=n>1?void 0:n?nt(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},Fe=(t,e)=>(r,n)=>e(r,n,t);const Ne="sheets-filter.generate-filter-values.service",ve=u.createIdentifier(Ne),st=["yyyy-mm-dd","yyyy-mm-dd;@","yyyy/mm/dd;@","yyyy/mm/dd hh:mm","yyyy-m-d am/pm h:mm","yyyy-MM-dd","yyyy/MM/dd","yyyy/mm/dd",'yyyy"年"MM"月"dd"日"',"MM-dd",'M"月"d"日"',"MM-dd A/P hh:mm"];let be=class extends u.Disposable{constructor(t,e,r){super(),this._localeService=t,this._univerInstanceService=e,this._logService=r}async getFilterValues(t){var p;const{unitId:e,subUnitId:r,filteredOutRowsByOtherColumns:n,filterColumn:o,filters:l,blankChecked:i,iterateRange:s,alreadyChecked:a}=t,h=this._univerInstanceService.getUnit(e),m=(p=this._univerInstanceService.getUnit(e))==null?void 0:p.getSheetBySheetId(r);return!h||!m?[]:(this._logService.debug("[SheetsGenerateFilterValuesService]","getFilterValues for",{unitId:e,subUnitId:r}),Be(l,this._localeService,s,m,new Set(n),o,new Set(a.map(String)),i,h.getStyles()))}};be=ot([Fe(0,u.Inject(u.LocaleService)),Fe(1,u.IUniverInstanceService),Fe(2,u.ILogService)],be);function Be(t,e,r,n,o,l,i,s,a){var P,L,w,$,D,q,Z,se,W,U;const h=new Map,m=new Map,p="yyyy-mm-dd",y=new Set(st),v="empty",T=!t&&((l==null?void 0:l.filterBy)===c.FilterBy.COLORS||(l==null?void 0:l.filterBy)===c.FilterBy.CONDITIONS)&&((P=l.filteredOutRows)==null?void 0:P.size);let O=0;for(const k of n.iterateByColumn(r,!1,!1)){const{row:$e,rowSpan:it=1}=k;let ae=0;for(;ae<it;){const nr=$e+ae;if(o.has(nr)){ae++;continue}const J=k!=null&&k.value?u.extractPureTextFromCell(k.value):"";if(!J){O+=1,ae+=it;continue}const ye=(L=k.value)!=null&&L.v&&!k.value.p?(D=($=a.get((w=k.value)==null?void 0:w.s))==null?void 0:$.n)==null?void 0:D.pattern:"",or=ye&&u.numfmt.getFormatInfo(ye).isDate;if(ye&&or&&y.has(ye)){const K=(q=n.getCellRaw(k.row,k.col))==null?void 0:q.v;if(!K){ae++;continue}const le=u.numfmt.format(p,K),[R,j,pe]=le.split("-").map(Number);let ee=h.get(`${R}`);ee||(ee={title:`${R}`,key:`${R}`,children:[],count:0,leaf:!1,checked:!1},h.set(`${R}`,ee),m.set(`${R}`,[`${R}`]));let Q=(Z=ee.children)==null?void 0:Z.find(ke=>ke.key===`${R}-${j}`);Q||(Q={title:e.t(`sheets-filter.date.${j}`),key:`${R}-${j}`,children:[],count:0,leaf:!1,checked:!1},(se=ee.children)==null||se.push(Q),m.set(`${R}-${j}`,[`${R}`,`${R}-${j}`]));const Ue=(W=Q==null?void 0:Q.children)==null?void 0:W.find(ke=>ke.key===`${R}-${j}-${pe}`);Ue?(Ue.originValues.add(J),Ue.count++,Q.count++,ee.count++):((U=Q.children)==null||U.push({title:`${pe}`,key:`${R}-${j}-${pe}`,count:1,originValues:new Set([J]),leaf:!0,checked:T?!1:i.size?i.has(J):!s}),Q.count++,ee.count++,m.set(`${R}-${j}-${pe}`,[`${R}`,`${R}-${j}`,`${R}-${j}-${pe}`]))}else{const K=J;let le=h.get(K);le?le.count++:(le={title:J,leaf:!0,checked:T?!1:i.size?i.has(J):!s,key:K,count:1},h.set(K,le),m.set(K,[K]))}ae++}}const b=T?!1:t?s:!0;if(O>0){const k={title:e.t("sheets-filter.panel.empty"),count:O,leaf:!0,checked:b,key:v};h.set("empty",k),m.set("empty",[v])}return{filterTreeItems:at(Array.from(h.values())),filterTreeMapCache:m}}function at(t){return Array.from(t).sort((e,r)=>e.children&&!r.children?-1:!e.children&&r.children?1:lt(e.title,r.title)).map(e=>(e.children&&e.children.sort((r,n)=>{const o=Number.parseInt(r.key.split("-")[1],10),l=Number.parseInt(n.key.split("-")[1],10);return o-l}).forEach(r=>{r.children&&r.children.sort((n,o)=>{const l=Number.parseInt(n.key.split("-")[2],10),i=Number.parseInt(o.key.split("-")[2],10);return l-i})}),e))}const De=t=>!Number.isNaN(Number(t))&&!Number.isNaN(Number.parseFloat(t));function lt(t,e){const r=De(t),n=De(e);return r&&n?Number.parseFloat(t)-Number.parseFloat(e):r&&!n?-1:!r&&n?1:t.localeCompare(e)}function Pe(t,e){for(const r of t){if(r.key===e)return r;if(r.children){const n=Pe(r.children,e);if(n)return n}}return null}function xe(t){return t.leaf?t.checked:t.children?t.children.every(e=>xe(e)):!0}function ce(t,e){t.leaf&&(e!==void 0?t.checked=e:t.checked=!t.checked),t.children&&t.children.forEach(r=>ce(r,e))}function He(t,e){const r=[];return t.forEach(n=>{const o=n.originValues?e.some(s=>Array.from(n.originValues).some(a=>a.toLowerCase().includes(s.toLowerCase()))):!1,l=!o&&e.some(s=>n.title.toLowerCase().includes(s.toLowerCase()));if(o||l)r.push({...n});else if(n.children){const s=He(n.children,e);if(s.length>0){const a=s.reduce((h,m)=>h+m.count,0);r.push({...n,count:a,children:s})}}}),r}var ct=Object.getOwnPropertyDescriptor,_e=(t,e,r,n)=>{for(var o=n>1?void 0:n?ct(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},ue=(t,e)=>(r,n)=>e(r,n,t);u.createIdentifier("sheets-filter-ui.sheets-filter-panel.service");let G=class extends u.Disposable{constructor(e,r){super();_(this,"_filterBy$",new S.BehaviorSubject(c.FilterBy.VALUES));_(this,"filterBy$",this._filterBy$.asObservable());_(this,"_filterByModel$",new S.ReplaySubject(1));_(this,"filterByModel$",this._filterByModel$.asObservable());_(this,"_filterByModel",null);_(this,"_hasCriteria$",new S.BehaviorSubject(!1));_(this,"hasCriteria$",this._hasCriteria$.asObservable());_(this,"_filterModel",null);_(this,"_col$",new S.BehaviorSubject(-1));_(this,"col$",this._col$.asObservable());_(this,"_filterHeaderListener",null);this._injector=e,this._refRangeService=r}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()}dispose(){this._filterBy$.complete(),this._filterByModel$.complete(),this._hasCriteria$.complete()}setupCol(e,r){this.terminate(),this._filterModel=e,this._col$.next(r);const n=e.getFilterColumn(r);if(n){const o=n.getColumnData();if(o.customFilters){this._hasCriteria$.next(!0),this._setupByConditions(e,r);return}if(o.colorFilters){this._hasCriteria$.next(!0),this._setupByColors(e,r);return}if(o.filters){this._hasCriteria$.next(!0),this._setupByValues(e,r);return}this._hasCriteria$.next(!1),this._setupByValues(e,r);return}this._hasCriteria$.next(!1),this._setupByValues(e,r)}changeFilterBy(e){if(!this._filterModel||this.col===-1)return!1;switch(e){case c.FilterBy.VALUES:this._setupByValues(this._filterModel,this.col);break;case c.FilterBy.COLORS:this._setupByColors(this._filterModel,this.col);break;case c.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,r){this._disposeFilterHeaderChangeListener();const n=e.unitId,o=e.subUnitId,l=e.getRange(),i={startColumn:r,startRow:l.startRow,endRow:l.startRow,endColumn:r};this._filterHeaderListener=this._refRangeService.watchRange(n,o,i,(s,a)=>{if(!a)this.terminate();else{const h=a.startColumn-s.startColumn;h!==0&&this._filterByModel.deltaCol(h)}})}async _setupByValues(e,r){this._disposePreviousModel();const n=e.getRange();if(n.startRow===n.endRow)return!1;const o=await Ce.fromFilterColumn(this._injector,e,r);return this.filterByModel=o,this._filterBy$.next(c.FilterBy.VALUES),this._listenToFilterHeaderChange(e,r),!0}async _setupByColors(e,r){this._disposePreviousModel();const n=e.getRange();if(n.startRow===n.endRow)return!1;const o=await Se.fromFilterColumn(this._injector,e,r);return this.filterByModel=o,this._filterBy$.next(c.FilterBy.COLORS),this._listenToFilterHeaderChange(e,r),!0}_setupByConditions(e,r){this._disposePreviousModel();const n=e.getRange();if(n.startRow===n.endRow)return!1;const o=ge.fromFilterColumn(this._injector,e,r,e.getFilterColumn(r));return this.filterByModel=o,this._filterBy$.next(c.FilterBy.CONDITIONS),this._listenToFilterHeaderChange(e,r),!0}_disposePreviousModel(){var e;(e=this._filterByModel)==null||e.dispose(),this.filterByModel=null}};G=_e([ue(0,u.Inject(u.Injector)),ue(1,u.Inject(N.RefRangeService))],G);let ge=class extends u.Disposable{constructor(e,r,n,o,l){super();_(this,"canApply$",S.of(!0));_(this,"_conditionItem$");_(this,"conditionItem$");_(this,"_filterConditionFormParams$");_(this,"filterConditionFormParams$");this._filterModel=e,this.col=r,this._commandService=l,this._conditionItem$=new S.BehaviorSubject(n),this.conditionItem$=this._conditionItem$.asObservable(),this._filterConditionFormParams$=new S.BehaviorSubject(o),this.filterConditionFormParams$=this._filterConditionFormParams$.asObservable()}static fromFilterColumn(e,r,n,o){const[l,i]=f.testMappingFilterColumn(o==null?void 0:o.getColumnData());return e.createInstance(ge,r,n,l,i)}get conditionItem(){return this._conditionItem$.getValue()}get filterConditionFormParams(){return this._filterConditionFormParams$.getValue()}dispose(){super.dispose(),this._conditionItem$.complete(),this._filterConditionFormParams$.complete()}deltaCol(e){this.col+=e}clear(){return this._disposed?Promise.resolve(!1):this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}async apply(){if(this._disposed)return!1;const e=f.mapToFilterColumn(this.conditionItem,this.filterConditionFormParams);return this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:e})}onPrimaryConditionChange(e){const r=f.ALL_CONDITIONS.find(n=>n.operator===e);if(!r)throw new Error(`[ByConditionsModel]: condition item not found for operator: ${e}!`);this._conditionItem$.next(r),this._filterConditionFormParams$.next(f.getInitialFormParams(e))}onConditionFormChange(e){const r={...this.filterConditionFormParams,...e};if(r.and!==!0&&delete r.and,typeof e.and<"u"||typeof e.operator1<"u"||typeof e.operator2<"u"){const n=f.testMappingParams(r,this.conditionItem.numOfParameters);this._conditionItem$.next(n)}this._filterConditionFormParams$.next(r)}};ge=_e([ue(4,u.ICommandService)],ge);let Ce=class extends u.Disposable{constructor(e,r,n,o,l){super();_(this,"_rawFilterItems$");_(this,"rawFilterItems$");_(this,"filterItems$");_(this,"_filterItems",[]);_(this,"_treeMapCache");_(this,"canApply$");_(this,"_manuallyUpdateFilterItems$");_(this,"_searchString$");_(this,"searchString$");this._filterModel=e,this.col=r,this._commandService=l,this._treeMapCache=o,this._searchString$=new S.BehaviorSubject(""),this.searchString$=this._searchString$.asObservable(),this._rawFilterItems$=new S.BehaviorSubject(n),this.rawFilterItems$=this._rawFilterItems$.asObservable(),this._manuallyUpdateFilterItems$=new S.Subject,this.filterItems$=S.merge(S.combineLatest([this._searchString$.pipe(S.throttleTime(500,void 0,{leading:!0,trailing:!0}),S.startWith(void 0)),this._rawFilterItems$]).pipe(S.map(([i,s])=>{if(!i)return s;const h=i.toLowerCase().split(/\s+/).filter(m=>!!m);return He(s,h)})),this._manuallyUpdateFilterItems$).pipe(S.shareReplay(1)),this.canApply$=this.filterItems$.pipe(S.map(i=>Ie(i).checked>0)),this.disposeWithMe(this.filterItems$.subscribe(i=>this._filterItems=i))}static async fromFilterColumn(e,r,n){const o=e.get(u.IUniverInstanceService),l=e.get(u.LocaleService),i=e.get(ve,u.Quantity.OPTIONAL),{unitId:s,subUnitId:a}=r,h=o.getUniverSheetInstance(s);if(!h)throw new Error(`[ByValuesModel]: Workbook not found for filter model with unitId: ${s}!`);const m=h==null?void 0:h.getSheetBySheetId(a);if(!m)throw new Error(`[ByValuesModel]: Worksheet not found for filter model with unitId: ${s} and subUnitId: ${a}!`);const p=r.getRange(),y=n,v=r.getFilterColumn(n),T=v==null?void 0:v.getColumnData().filters,O=new Set(T==null?void 0:T.filters),b=!!(T&&T.blank),P=r.getFilteredOutRowsExceptCol(n),L={...p,startRow:p.startRow+1,startColumn:y,endColumn:y};let w,$;if(i){const D=await i.getFilterValues({unitId:s,subUnitId:a,filteredOutRowsByOtherColumns:Array.from(P),filterColumn:v,filters:!!T,blankChecked:b,iterateRange:L,alreadyChecked:Array.from(O)});w=D.filterTreeItems,$=D.filterTreeMapCache}else{const D=Be(!!T,l,L,m,P,v,O,b,h.getStyles());w=D.filterTreeItems,$=D.filterTreeMapCache}return e.createInstance(Ce,r,n,w,$)}get rawFilterItems(){return this._rawFilterItems$.getValue()}get filterItems(){return this._filterItems}get treeMapCache(){return this._treeMapCache}dispose(){this._rawFilterItems$.complete(),this._searchString$.complete()}deltaCol(e){this.col+=e}setSearchString(e){this._searchString$.next(e)}onCheckAllToggled(e){const r=u.Tools.deepClone(this._filterItems);r.forEach(n=>ce(n,e)),this._manuallyUpdateFilterItems(r)}onFilterCheckToggled(e){const r=u.Tools.deepClone(this._filterItems),n=Pe(r,e.key);if(!n)return;const o=xe(n);ce(n,!o),this._manuallyUpdateFilterItems(r)}onFilterOnly(e){const r=u.Tools.deepClone(this._filterItems);r.forEach(n=>ce(n,!1)),e.forEach(n=>{const o=Pe(r,n);o&&ce(o,!0)}),this._manuallyUpdateFilterItems(r)}_manuallyUpdateFilterItems(e){this._manuallyUpdateFilterItems$.next(e)}clear(){return this._disposed?Promise.resolve(!1):this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}async apply(){if(this._disposed)return!1;const e=Ie(this._filterItems),{checked:r,checkedItems:n}=e,o=this.rawFilterItems;let l=0;for(const h of o)l+=h.count;const i=r===0,s=e.checked===l,a={colId:this.col};if(i)throw new Error("[ByValuesModel]: no checked items!");if(s)return this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null});{a.filters={};const h=n.filter(p=>p.key!=="empty");h.length>0&&(a.filters={filters:h.flatMap(p=>p.originValues?Array.from(p.originValues):[p.title])}),h.length!==n.length&&(a.filters.blank=!0)}return this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:a})}};Ce=_e([ue(4,u.ICommandService)],Ce);let Se=class extends u.Disposable{constructor(e,r,n,o,l){super();_(this,"canApply$",S.of(!0));_(this,"_cellFillColors$");_(this,"cellFillColors$");_(this,"_cellTextColors$");_(this,"cellTextColors$");this._filterModel=e,this.col=r,this._commandService=l,this._cellFillColors$=new S.BehaviorSubject(Array.from(n.values())),this.cellFillColors$=this._cellFillColors$.asObservable(),this._cellTextColors$=new S.BehaviorSubject(Array.from(o.values())),this.cellTextColors$=this._cellTextColors$.asObservable()}static async fromFilterColumn(e,r,n){var L,w,$;const o=e.get(u.IUniverInstanceService),{unitId:l,subUnitId:i}=r,s=o.getUniverSheetInstance(l);if(!s)throw new Error(`[ByColorsModel]: Workbook not found for filter model with unitId: ${l}!`);const a=s==null?void 0:s.getSheetBySheetId(i);if(!a)throw new Error(`[ByColorsModel]: Worksheet not found for filter model with unitId: ${l} and subUnitId: ${i}!`);const h=r.getRange(),m=n,p=(L=r.getFilterColumn(n))==null?void 0:L.getColumnData().colorFilters,y=r.getFilteredOutRowsExceptCol(n),v={...h,startRow:h.startRow+1,startColumn:m,endColumn:m},T=new Map,O=new Set((w=p==null?void 0:p.cellFillColors)!=null?w:[]),b=new Map,P=new Set(($=p==null?void 0:p.cellTextColors)!=null?$:[]);for(const D of a.iterateByColumn(v,!1,!0)){const{row:q,col:Z,value:se}=D;if(y.has(q))continue;const W=a.getComposedCellStyleByCellData(q,Z,se);if(W.bg&&W.bg.rgb){const U=new u.ColorKit(W.bg.rgb).toRgbString();T.has(U)||T.set(U,{color:U,checked:O.has(U)})}else T.set("default-fill-color",{color:null,checked:O.has(null)});if(W.cl&&W.cl.rgb){const U=new u.ColorKit(W.cl.rgb).toRgbString();b.has(U)||b.set(U,{color:U,checked:P.has(U)})}else b.set("default-font-color",{color:X.COLOR_BLACK_RGB,checked:P.has(X.COLOR_BLACK_RGB)})}return e.createInstance(Se,r,n,T,b)}get cellFillColors(){return this._cellFillColors$.getValue()}get cellTextColors(){return this._cellTextColors$.getValue()}dispose(){super.dispose(),this._cellFillColors$.complete()}deltaCol(e){this.col+=e}clear(){return this._disposed?Promise.resolve(!1):this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null})}onFilterCheckToggled(e,r=!0){const n=r?this.cellFillColors:this.cellTextColors,o=[];let l=!1;for(let i=0;i<n.length;i++){const s=n[i];if(s.color===e.color){l=!0,o.push({color:s.color,checked:!s.checked});continue}o.push({color:s.color,checked:s.checked})}l&&(this._resetColorsCheckedStatus(!r),r?this._cellFillColors$.next([...o]):this._cellTextColors$.next([...o]))}_resetColorsCheckedStatus(e=!0){const r=e?this.cellFillColors:this.cellTextColors,n=[];for(let o=0;o<r.length;o++)n.push({color:r[o].color,checked:!1});e?this._cellFillColors$.next([...n]):this._cellTextColors$.next([...n])}async apply(){if(this._disposed)return!1;const e=this.cellFillColors.filter(o=>o.checked).map(o=>o.color),r=this.cellTextColors.filter(o=>o.checked).map(o=>o.color);if(e.length===0&&r.length===0)return this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:null});const n={colId:this.col};return e.length>0?n.colorFilters={cellFillColors:e}:r.length>0&&(n.colorFilters={cellTextColors:r}),this._commandService.executeCommand(c.SetSheetsFilterCriteriaCommand.id,{unitId:this._filterModel.unitId,subUnitId:this._filterModel.subUnitId,col:this.col,criteria:n})}};Se=_e([ue(4,u.ICommandService)],Se);const te="FILTER_PANEL_OPENED",he={id:"sheet.operation.open-filter-panel",type:u.CommandType.OPERATION,handler:(t,e)=>{const r=t.get(u.IContextService),n=t.get(c.SheetsFilterService),o=t.get(G),l=t.get(u.ICommandService),i=t.has(M.IEditorBridgeService)?t.get(M.IEditorBridgeService):null;i!=null&&i.isVisible().visible&&l.syncExecuteCommand(M.SetCellEditVisibleOperation.id,{visible:!1});const{unitId:s,subUnitId:a,col:h}=e,m=n.getFilterModel(s,a);return m?(o.setupCol(m,h),r.getContextValue(te)||r.setContextValue(te,!0),!0):!1}},re={id:"sheet.operation.close-filter-panel",type:u.CommandType.OPERATION,handler:t=>{const e=t.get(u.IContextService),r=t.get(G),n=t.get(g.ILayoutService,u.Quantity.OPTIONAL);return e.getContextValue(te)?(e.setContextValue(te,!1),n==null||n.focus(),r.terminate()):!1}},Ae={id:"sheet.operation.apply-filter",type:u.CommandType.OPERATION,handler:(t,e)=>{const{filterBy:r}=e;return t.get(G).changeFilterBy(r)}},We="sheets-filter-ui.config",Te={};var ut=Object.getOwnPropertyDescriptor,ht=(t,e,r,n)=>{for(var o=n>1?void 0:n?ut(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},ie=(t,e)=>(r,n)=>e(r,n,t);let ne=class extends u.Disposable{constructor(t,e,r,n,o,l){super(),this._sheetsFilterService=t,this._localeService=e,this._commandService=r,this._sheetPermissionCheckPermission=n,this._injector=o,this._sheetsSelectionService=l,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(t=>{var e,r,n;if(t.id===c.SmartToggleSheetsFilterCommand.id){const o=this._injector.get(u.IUniverInstanceService),l=N.getSheetCommandTarget(o);if(!l)return;const{unitId:i,subUnitId:s,worksheet:a}=l,h=(e=this._sheetsFilterService.getFilterModel(i,s))==null?void 0:e.getRange();let m;if(h)m=this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[N.RangeProtectionPermissionViewPoint],worksheetTypes:[N.WorksheetFilterPermission,N.WorksheetViewPermission]},[h]);else{const p=(r=this._sheetsSelectionService.getCurrentLastSelection())==null?void 0:r.range;if(p){let y={...p};y=p.startColumn===p.endColumn&&p.startRow===p.endRow?N.expandToContinuousRange(y,{left:!0,right:!0,up:!0,down:!0},a):y,m=this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[N.RangeProtectionPermissionViewPoint],worksheetTypes:[N.WorksheetViewPermission,N.WorksheetFilterPermission]},[y],i,s)}else m=this._sheetPermissionCheckPermission.permissionCheckWithoutRange({rangeTypes:[N.RangeProtectionPermissionViewPoint],worksheetTypes:[N.WorksheetViewPermission,N.WorksheetFilterPermission]})}m||this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.filterErr"))}if(t.id===he.id){const o=t.params,{unitId:l,subUnitId:i}=o,s=(n=this._sheetsFilterService.getFilterModel(l,i))==null?void 0:n.getRange(),a=u.Tools.deepClone(s);a&&(a.startColumn=o.col,a.endColumn=o.col,this._sheetPermissionCheckPermission.permissionCheckWithRanges({rangeTypes:[N.RangeProtectionPermissionViewPoint],worksheetTypes:[N.WorksheetFilterPermission,N.WorksheetViewPermission]},[a])||this._sheetPermissionCheckPermission.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.filterErr")))}}))}};ne=ht([ie(0,u.Inject(c.SheetsFilterService)),ie(1,u.Inject(u.LocaleService)),ie(2,u.ICommandService),ie(3,u.Inject(N.SheetPermissionCheckController)),ie(4,u.Inject(u.Injector)),ie(5,u.Inject(N.SheetsSelectionsService))],ne);const Y=16,dt=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");class Ve{static drawNoCriteria(e,r,n,o){e.save(),X.Rect.drawWith(e,{radius:2,width:Y,height:Y,fill:o}),e.lineCap="square",e.strokeStyle=n,e.scale(r/Y,r/Y),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,r,n,o){e.save(),X.Rect.drawWith(e,{radius:2,width:Y,height:Y,fill:o}),e.scale(r/Y,r/Y),e.fillStyle=n,e.fill(dt),e.restore()}}var mt=Object.getOwnPropertyDescriptor,pt=(t,e,r,n)=>{for(var o=n>1?void 0:n?mt(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},we=(t,e)=>(r,n)=>e(r,n,t);const V=16,de=1;let Re=class extends X.Shape{constructor(e,r,n,o,l){super(e,r);_(this,"_cellWidth",0);_(this,"_cellHeight",0);_(this,"_filterParams");_(this,"_hovered",!1);this._contextService=n,this._commandService=o,this._themeService=l,this.setShapeProps(r),this.onPointerDown$.subscribeEvent(i=>this.onPointerDown(i)),this.onPointerEnter$.subscribeEvent(()=>this.onPointerEnter()),this.onPointerLeave$.subscribeEvent(()=>this.onPointerLeave())}setShapeProps(e){typeof e.cellHeight<"u"&&(this._cellHeight=e.cellHeight),typeof e.cellWidth<"u"&&(this._cellWidth=e.cellWidth),typeof e.filterParams<"u"&&(this._filterParams=e.filterParams),this.transformByState({width:e.width,height:e.height})}_draw(e){const r=this._cellHeight,n=this._cellWidth,o=V-n,l=V-r;e.save();const i=new Path2D;i.rect(o,l,n,r),e.clip(i);const{hasCriteria:s}=this._filterParams,a=this._themeService.getColorFromTheme("primary.600"),h=this._hovered?this._themeService.getColorFromTheme("gray.50"):"rgba(255, 255, 255, 1.0)";s?Ve.drawHasCriteria(e,V,a,h):Ve.drawNoCriteria(e,V,a,h),e.restore()}onPointerDown(e){if(e.button===2)return;const{col:r,unitId:n,subUnitId:o}=this._filterParams;this._contextService.getContextValue(te)||!this._commandService.hasCommand(he.id)||setTimeout(()=>{this._commandService.executeCommand(he.id,{unitId:n,subUnitId:o,col:r})},200)}onPointerEnter(){this._hovered=!0,this.makeDirty(!0)}onPointerLeave(){this._hovered=!1,this.makeDirty(!0)}};Re=pt([we(2,u.IContextService),we(3,u.ICommandService),we(4,u.Inject(u.ThemeService))],Re);var ft=Object.getOwnPropertyDescriptor,vt=(t,e,r,n)=>{for(var o=n>1?void 0:n?ft(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},z=(t,e)=>(r,n)=>e(r,n,t);const _t=1e3,gt=5e3;function Ct(t,e,r,n){switch(n){case u.VerticalAlign.TOP:return t+de;case u.VerticalAlign.MIDDLE:return t+Math.max(0,(r-V)/2);case u.VerticalAlign.BOTTOM:default:return e-V-de}}let Me=class extends u.RxDisposable{constructor(e,r,n,o,l,i,s,a){super();_(this,"_filterRangeShape",null);_(this,"_buttonRenderDisposable",null);_(this,"_filterButtonShapes",[]);this._context=e,this._injector=r,this._sheetSkeletonManagerService=n,this._sheetsFilterService=o,this._themeService=l,this._sheetInterceptorService=i,this._commandService=s,this._selectionRenderService=a,this._initRenderer()}dispose(){super.dispose(),this._disposeRendering()}_initRenderer(){this._sheetSkeletonManagerService.currentSkeleton$.pipe(S.switchMap(e=>{var s,a;if(!e)return S.of(null);const{unit:r,unitId:n}=this._context,o=((s=r.getActiveSheet())==null?void 0:s.getSheetId())||"",l=(a=this._sheetsFilterService.getFilterModel(n,o))!=null?a:void 0,i=()=>({unitId:n,worksheetId:o,filterModel:l,range:l==null?void 0:l.getRange(),skeleton:e.skeleton});return u.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(S.filter(([h])=>{var m;return h.type===u.CommandType.MUTATION&&((m=h.params)==null?void 0:m.unitId)===r.getUnitId()&&(c.FILTER_MUTATIONS.has(h.id)||h.id===N.SetRangeValuesMutation.id)}),S.throttleTime(20,void 0,{leading:!1,trailing:!0}),S.map(i),S.startWith(i()))}),S.takeUntil(this.dispose$)).subscribe(e=>{this._disposeRendering(),!(!e||!e.range)&&(this._renderRange(e.range,e.skeleton),this._renderButtons(e))})}_renderRange(e,r){const{scene:n}=this._context,{rowHeaderWidth:o,columnHeaderHeight:l}=r,i=this._filterRangeShape=new M.SelectionControl(n,_t,this._themeService,{rowHeaderWidth:o,columnHeaderHeight:l,enableAutoFill:!1,highlightHeader:!1}),s={range:e,primary:null,style:{fill:"rgba(0, 0, 0, 0.0)"}},a=M.attachSelectionWithCoord(s,r);i.updateRangeBySelectionWithCoord(a),i.setEvent(!1),n.makeDirty(!0)}_renderButtons(e){const{range:r,filterModel:n,unitId:o,skeleton:l,worksheetId:i}=e,{unit:s,scene:a}=this._context,h=s.getSheetBySheetId(i);if(!h)return;this._interceptCellContent(o,i,e.range);const{startColumn:m,endColumn:p,startRow:y}=r;for(let v=m;v<=p;v++){const T=`sheets-filter-button-${v}`,O=M.getCoordByCell(y,v,a,l),b=h.getComposedCellStyle(y,v),P=(b==null?void 0:b.vt)||u.VerticalAlign.BOTTOM,{startX:L,startY:w,endX:$,endY:D}=O,q=$-L,Z=D-w;if(Z<=de||q<=de)continue;const se=!!n.getFilterColumn(v),W=$-V-de,U=Ct(w,D,Z,P),k={left:W,top:U,height:V,width:V,zIndex:gt,cellHeight:Z,cellWidth:q,filterParams:{unitId:o,subUnitId:i,col:v,hasCriteria:se}},$e=this._injector.createInstance(Re,T,k);this._filterButtonShapes.push($e)}a.addObjects(this._filterButtonShapes),a.makeDirty()}_interceptCellContent(e,r,n){const{startRow:o,startColumn:l,endColumn:i}=n;this._buttonRenderDisposable=this._sheetInterceptorService.intercept(N.INTERCEPTOR_POINT.CELL_CONTENT,{effect:u.InterceptorEffectEnum.Style,handler:(s,a,h)=>{const{row:m,col:p,unitId:y,subUnitId:v}=a;return y!==e||v!==r||m!==o||p<l||p>i||((!s||s===a.rawData)&&(s={...a.rawData}),s.fontRenderExtension={...s==null?void 0:s.fontRenderExtension,rightOffset:V}),h(s)},priority:10})}_disposeRendering(){var e,r;(e=this._filterRangeShape)==null||e.dispose(),this._filterButtonShapes.forEach(n=>n.dispose()),(r=this._buttonRenderDisposable)==null||r.dispose(),this._filterRangeShape=null,this._buttonRenderDisposable=null,this._filterButtonShapes=[]}};Me=vt([z(1,u.Inject(u.Injector)),z(2,u.Inject(M.SheetSkeletonManagerService)),z(3,u.Inject(c.SheetsFilterService)),z(4,u.Inject(u.ThemeService)),z(5,u.Inject(N.SheetInterceptorService)),z(6,u.ICommandService),z(7,M.ISheetSelectionRenderService)],Me);var St=Object.getOwnPropertyDescriptor,Tt=(t,e,r,n)=>{for(var o=n>1?void 0:n?St(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},je=(t,e)=>(r,n)=>e(r,n,t);let me=class extends u.RxDisposable{constructor(t,e){super(),this._renderManagerService=t,this._sheetsRenderService=e,[c.SetSheetsFilterRangeMutation,c.SetSheetsFilterCriteriaMutation,c.RemoveSheetsFilterMutation,c.ReCalcSheetsFilterMutation].forEach(r=>this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(r.id))),this.disposeWithMe(this._renderManagerService.registerRenderModule(u.UniverInstanceType.UNIVER_SHEET,[Me]))}};me=Tt([je(0,X.IRenderManagerService),je(1,u.Inject(M.SheetsRenderService))],me);var Et=Object.defineProperty,Ot=Object.getOwnPropertyDescriptor,yt=(t,e,r)=>e in t?Et(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,It=(t,e,r,n)=>{for(var o=n>1?void 0:n?Ot(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},Qe=(t,e)=>(r,n)=>e(r,n,t),Ge=(t,e,r)=>yt(t,typeof e!="symbol"?e+"":e,r);const Ft="SHEET_FILTER_UI_PLUGIN";C.UniverSheetsFilterMobileUIPlugin=class extends u.Plugin{constructor(e=Te,r,n){super(),this._config=e,this._injector=r,this._configService=n;const{menu:o,...l}=u.merge({},Te,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(We,l)}onStarting(){[[ne],[me]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(ne)}onRendered(){this._injector.get(me)}},Ge(C.UniverSheetsFilterMobileUIPlugin,"type",u.UniverInstanceType.UNIVER_SHEET),Ge(C.UniverSheetsFilterMobileUIPlugin,"pluginName",Ft),C.UniverSheetsFilterMobileUIPlugin=It([u.DependentOn(c.UniverSheetsFilterPlugin),Qe(1,u.Inject(u.Injector)),Qe(2,u.IConfigService)],C.UniverSheetsFilterMobileUIPlugin);var x=function(){return x=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++){e=arguments[r];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t},x.apply(this,arguments)},Nt=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]]);return r},oe=I.forwardRef(function(t,e){var r=t.icon,n=t.id,o=t.className,l=t.extend,i=Nt(t,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(n," ").concat(o||"").trim(),a=I.useRef("_".concat(At()));return Ye(r,"".concat(n),{defIds:r.defIds,idSuffix:a.current},x({ref:e,className:s},i),l)});function Ye(t,e,r,n,o){return I.createElement(t.tag,x(x({key:e},bt(t,r,o)),n),(Pt(t,r).children||[]).map(function(l,i){return Ye(l,"".concat(e,"-").concat(t.tag,"-").concat(i),r,void 0,o)}))}function bt(t,e,r){var n=x({},t.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1),t.tag==="mask"&&n.id&&(n.id=n.id+e.idSuffix),Object.entries(n).forEach(function(l){var i=l[0],s=l[1];i==="mask"&&typeof s=="string"&&(n[i]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))});var o=e.defIds;return!o||o.length===0||(t.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(function(l){var i=l[0],s=l[1];typeof s=="string"&&(n[i]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),n}function Pt(t,e){var r,n=e.defIds;return!n||n.length===0?t:t.tag==="defs"&&(!((r=t.children)===null||r===void 0)&&r.length)?x(x({},t),{children:t.children.map(function(o){return typeof o.attrs.id=="string"&&n&&n.includes(o.attrs.id)?x(x({},o),{attrs:x(x({},o.attrs),{id:o.attrs.id+e.idSuffix})}):o})}):t}function At(){return Math.random().toString(36).substring(2,8)}oe.displayName="UniverIcon";var wt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 20 20",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M10 1.05957C10.356 1.05957 10.6816 1.26162 10.8408 1.58008L18.8408 17.5801L18.8799 17.668C19.0486 18.1134 18.8551 18.6232 18.4199 18.8408C17.9557 19.0727 17.3913 18.8841 17.1592 18.4199L10 4.10156L2.84082 18.4199C2.60871 18.8841 2.04434 19.0727 1.58008 18.8408C1.11587 18.6087 0.92731 18.0443 1.15918 17.5801L9.15918 1.58008C9.31841 1.26162 9.64395 1.05957 10 1.05957Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M15.3337 11.7261L15.4294 11.731C15.9035 11.779 16.2732 12.1798 16.2732 12.6665C16.2732 13.1532 15.9035 13.554 15.4294 13.602L15.3337 13.6069H4.66675C4.1476 13.6069 3.72632 13.1856 3.72632 12.6665C3.72632 12.1474 4.1476 11.7261 4.66675 11.7261H15.3337Z"}}]},qe=I.forwardRef(function(t,e){return I.createElement(oe,Object.assign({},t,{id:"a-icon",ref:e,icon:wt}))});qe.displayName="AIcon";var Rt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 20 20",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M17.0596 10C17.0596 6.10087 13.8992 2.94043 10 2.94043C6.10087 2.94043 2.94043 6.10087 2.94043 10C2.94043 13.8992 6.10087 17.0596 10 17.0596C13.8992 17.0596 17.0596 13.8992 17.0596 10ZM18.9404 10C18.9404 14.9374 14.9374 18.9404 10 18.9404C5.06257 18.9404 1.05957 14.9374 1.05957 10C1.05957 5.06257 5.06257 1.05957 10 1.05957C14.9374 1.05957 18.9404 5.06257 18.9404 10Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.29492 4.13476C4.63911 3.79057 5.1845 3.76906 5.55371 4.07031L5.625 4.13476L16.0244 14.5352L16.0889 14.6064C16.3902 14.9757 16.3686 15.52 16.0244 15.8643C15.6573 16.2313 15.0624 16.2313 14.6953 15.8643L4.29492 5.46484L4.23047 5.39355C3.92922 5.02434 3.95073 4.47895 4.29492 4.13476Z"}}]},Ze=I.forwardRef(function(t,e){return I.createElement(oe,Object.assign({},t,{id:"ban-icon",ref:e,icon:Rt}))});Ze.displayName="BanIcon";var Mt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.32182 2.60967C2.98161 2.60967 2.79671 3.0074 3.01601 3.2675L6.85819 7.8246C6.94943 7.93282 6.99947 8.06981 6.99947 8.21136V12.7338C6.99947 12.898 7.0998 13.0455 7.2525 13.1058L8.73833 13.6928C9.00085 13.7965 9.28531 13.6031 9.28531 13.3208V8.21136C9.28531 8.06981 9.33535 7.93282 9.42659 7.8246L13.2688 3.2675C13.4881 3.0074 13.3032 2.60967 12.963 2.60967H3.32182ZM2.09858 4.04101C1.22139 3.0006 1.96097 1.40967 3.32182 1.40967H12.963C14.3238 1.40967 15.0634 3.0006 14.1862 4.04101L10.4853 8.43054V13.3208C10.4853 14.4498 9.34747 15.2237 8.29742 14.8089L6.81158 14.2219C6.20078 13.9806 5.79947 13.3905 5.79947 12.7338V8.43054L2.09858 4.04101Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ke=I.forwardRef(function(t,e){return I.createElement(oe,Object.assign({},t,{id:"filter-icon",ref:e,icon:Mt}))});Ke.displayName="FilterIcon";var Lt={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.00016 1.33203C6.68162 1.33203 5.39269 1.72302 4.29636 2.45557C3.20004 3.18811 2.34555 4.2293 1.84097 5.44747C1.33638 6.66565 1.20436 8.00609 1.4616 9.2993C1.71883 10.5925 2.35377 11.7804 3.28612 12.7127C4.21847 13.6451 5.40636 14.28 6.69956 14.5373C7.99277 14.7945 9.33321 14.6625 10.5514 14.1579C11.7696 13.6533 12.8108 12.7988 13.5433 11.7025C14.2758 10.6062 14.6668 9.31724 14.6668 7.9987C14.6649 6.23118 13.9619 4.53662 12.7121 3.2868C11.4622 2.03697 9.76768 1.33397 8.00016 1.33203ZM7.66683 3.9987C7.86461 3.9987 8.05795 4.05735 8.2224 4.16723C8.38685 4.27711 8.51502 4.43329 8.59071 4.61601C8.6664 4.79874 8.6862 4.99981 8.64762 5.19379C8.60903 5.38777 8.51379 5.56595 8.37394 5.7058C8.23409 5.84566 8.0559 5.9409 7.86192 5.97948C7.66794 6.01807 7.46687 5.99826 7.28415 5.92258C7.10142 5.84689 6.94524 5.71872 6.83536 5.55427C6.72548 5.38982 6.66683 5.19648 6.66683 4.9987C6.66683 4.73348 6.77219 4.47913 6.95972 4.29159C7.14726 4.10405 7.40162 3.9987 7.66683 3.9987ZM9.3335 11.332H6.66683C6.49002 11.332 6.32045 11.2618 6.19543 11.1368C6.0704 11.0117 6.00016 10.8422 6.00016 10.6654C6.00016 10.4886 6.0704 10.319 6.19543 10.194C6.32045 10.0689 6.49002 9.9987 6.66683 9.9987H7.3335V7.9987H6.66683C6.49002 7.9987 6.32045 7.92846 6.19543 7.80343C6.0704 7.67841 6.00016 7.50884 6.00016 7.33203C6.00016 7.15522 6.0704 6.98565 6.19543 6.86063C6.32045 6.7356 6.49002 6.66536 6.66683 6.66536H8.00016C8.17698 6.66536 8.34655 6.7356 8.47157 6.86063C8.59659 6.98565 8.66683 7.15522 8.66683 7.33203V9.9987H9.3335C9.51031 9.9987 9.67988 10.0689 9.8049 10.194C9.92993 10.319 10.0002 10.4886 10.0002 10.6654C10.0002 10.8422 9.92993 11.0117 9.8049 11.1368C9.67988 11.2618 9.51031 11.332 9.3335 11.332Z"}}]},Xe=I.forwardRef(function(t,e){return I.createElement(oe,Object.assign({},t,{id:"info-icon",ref:e,icon:Lt}))});Xe.displayName="InfoIcon";var $t={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8 15C11.866 15 15 11.866 15 8C15 4.13401 11.866 1 8 1C4.13401 1 1 4.13401 1 8C1 11.866 4.13401 15 8 15ZM11.7245 6.42417C11.9588 6.18985 11.9588 5.80995 11.7245 5.57564C11.4901 5.34132 11.1102 5.34132 10.8759 5.57564L7.3002 9.15137L5.72446 7.57564C5.49014 7.34132 5.11025 7.34132 4.87593 7.57564C4.64162 7.80995 4.64162 8.18985 4.87593 8.42417L6.87593 10.4242C7.11025 10.6585 7.49014 10.6585 7.72446 10.4242L11.7245 6.42417Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ze=I.forwardRef(function(t,e){return I.createElement(oe,Object.assign({},t,{id:"success-icon",ref:e,icon:$t}))});ze.displayName="SuccessIcon";function Ut(t){const{model:e}=t,r=g.useDependency(u.LocaleService),n=g.useObservable(e.cellFillColors$,[],!0),o=g.useObservable(e.cellTextColors$,[],!0),l=I.useCallback(s=>{e.onFilterCheckToggled(s)},[e]),i=I.useCallback(s=>{e.onFilterCheckToggled(s,!1)},[e]);return 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:d.jsxs("div",{"data-u-comp":"sheets-filter-panel",className:F.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",F.borderClassName),children:[n.length>1&&d.jsxs("div",{children:[d.jsx("div",{className:"univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white",children:r.t("sheets-filter.panel.filter-by-cell-fill-color")}),d.jsx("div",{className:"univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2",children:n.map((s,a)=>d.jsxs("div",{className:"univer-relative univer-h-6 univer-w-6",onClick:()=>l(s),children:[s.color?d.jsx("button",{type:"button",className:F.clsx("univer-box-border univer-h-6 univer-w-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:s.color}}):d.jsx(Ze,{className:"univer-h-6 univer-w-6 univer-cursor-pointer univer-rounded-full hover:univer-ring-2 hover:univer-ring-offset-2 hover:univer-ring-offset-white"}),s.checked&&d.jsx(Je,{})]},`sheets-filter-cell-fill-color-${a}`))})]}),o.length>1&&d.jsxs("div",{children:[d.jsx("div",{className:"univer-mb-2 univer-text-sm univer-text-gray-900 dark:!univer-text-white",children:r.t("sheets-filter.panel.filter-by-cell-text-color")}),d.jsx("div",{className:"univer-grid univer-grid-cols-8 univer-items-center univer-justify-start univer-gap-2",children:o.map((s,a)=>d.jsxs("div",{className:"univer-relative univer-h-6 univer-w-6",onClick:()=>i(s),children:[d.jsx("div",{className:"univer-box-border univer-flex univer-h-full univer-w-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:d.jsx(qe,{style:{color:s.color}})}),s.checked&&d.jsx(Je,{})]},`sheets-filter-cell-text-color-${a}`))})]}),n.length<=1&&o.length<=1&&d.jsx("div",{className:"univer-flex univer-h-full univer-w-full univer-items-center univer-justify-center univer-text-sm univer-text-gray-900 dark:!univer-text-gray-200",children:r.t("sheets-filter.panel.filter-by-color-none")})]})})}function Je(){return d.jsx("div",{className:"univer-absolute -univer-bottom-0.5 -univer-right-0.5 univer-flex univer-h-3 univer-w-3 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-full univer-bg-white",children:d.jsx(ze,{className:"univer-h-full univer-w-full univer-font-bold univer-text-[#418F1F]"})})}function kt(t){var v,T;const{model:e}=t,r=g.useDependency(u.LocaleService),n=g.useObservable(e.conditionItem$,void 0),o=g.useObservable(e.filterConditionFormParams$,void 0),l=o!=null&&o.and?"AND":"OR",i=I.useCallback(O=>{e.onConditionFormChange({and:O==="AND"})},[e]),s=Bt(r),a=I.useCallback(O=>{e.onPrimaryConditionChange(O)},[e]),h=Dt(r),m=I.useCallback(O=>{e.onConditionFormChange(O)},[e]),p=r.t("sheets-filter.panel.input-values-placeholder");function y(O,b,P){const L=f.getItemByOperator(O).numOfParameters===1;return d.jsxs(d.Fragment,{children:[P==="operator2"&&d.jsxs(F.RadioGroup,{value:l,onChange:i,children:[d.jsx(F.Radio,{value:"AND",children:r.t("sheets-filter.panel.and")}),d.jsx(F.Radio,{value:"OR",children:r.t("sheets-filter.panel.or")})]}),d.jsx(F.Select,{value:O,options:h,onChange:w=>m({[P]:w})}),L&&d.jsx("div",{children:d.jsx(F.Input,{className:"univer-mt-2",value:b,placeholder:p,onChange:w=>m({[P==="operator1"?"val1":"val2"]:w})})})]})}return 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:n&&o&&d.jsxs(d.Fragment,{children:[d.jsx(F.Select,{value:n.operator,options:s,onChange:a}),f.getItemByOperator(n.operator).numOfParameters!==0?d.jsxs("div",{"data-u-comp":"sheets-filter-panel-conditions-container-inner",className:F.clsx("univer-mt-2 univer-flex-grow univer-overflow-hidden univer-rounded-md univer-p-2",F.borderClassName),children:[n.numOfParameters>=1&&y(o.operator1,(v=o.val1)!=null?v:"","operator1"),n.numOfParameters>=2&&y(o.operator2,(T=o.val2)!=null?T:"","operator2"),d.jsxs("div",{"data-u-comp":"sheets-filter-panel-conditions-desc",className:"univer-mt-2 univer-text-xs univer-text-gray-500",children:[r.t("sheets-filter.panel.?"),d.jsx("br",{}),r.t("sheets-filter.panel.*")]})]}):null]})})}function Bt(t){const e=t.getCurrentLocale();return I.useMemo(()=>[{options:[{label:t.t(f.NONE.label),value:f.NONE.operator}]},{options:[{label:t.t(f.EMPTY.label),value:f.EMPTY.operator},{label:t.t(f.NOT_EMPTY.label),value:f.NOT_EMPTY.operator}]},{options:[{label:t.t(f.TEXT_CONTAINS.label),value:f.TEXT_CONTAINS.operator},{label:t.t(f.DOES_NOT_CONTAIN.label),value:f.DOES_NOT_CONTAIN.operator},{label:t.t(f.STARTS_WITH.label),value:f.STARTS_WITH.operator},{label:t.t(f.ENDS_WITH.label),value:f.ENDS_WITH.operator},{label:t.t(f.EQUALS.label),value:f.EQUALS.operator}]},{options:[{label:t.t(f.GREATER_THAN.label),value:f.GREATER_THAN.operator},{label:t.t(f.GREATER_THAN_OR_EQUAL.label),value:f.GREATER_THAN_OR_EQUAL.operator},{label:t.t(f.LESS_THAN.label),value:f.LESS_THAN.operator},{label:t.t(f.LESS_THAN_OR_EQUAL.label),value:f.LESS_THAN_OR_EQUAL.operator},{label:t.t(f.EQUAL.label),value:f.EQUAL.operator},{label:t.t(f.NOT_EQUAL.label),value:f.NOT_EQUAL.operator},{label:t.t(f.BETWEEN.label),value:f.BETWEEN.operator},{label:t.t(f.NOT_BETWEEN.label),value:f.NOT_BETWEEN.operator}]},{options:[{label:t.t(f.CUSTOM.label),value:f.CUSTOM.operator}]}],[e,t])}function Dt(t){const e=t.getCurrentLocale();return I.useMemo(()=>f.ALL_CONDITIONS.filter(r=>r.numOfParameters!==2).map(r=>({label:t.t(r.label),value:r.operator})),[e,t])}function xt(t){const{model:e}=t,r=g.useDependency(u.LocaleService),n=g.useObservable(e.searchString$,"",!0),o=g.useObservable(e.filterItems$,void 0,!0),l=r.t("sheets-filter.panel.filter-only"),i=Ie(o),s=i.checked>0&&i.unchecked===0,a=i.checked>0&&i.unchecked>0,h=e.treeMapCache,m=I.useCallback(()=>{e.onCheckAllToggled(!s)},[e,s]),p=I.useCallback(v=>{e.setSearchString(v)},[e]);function y(v){let T=[];return v.forEach(O=>{O.checked&&T.push(O.key),O.children&&(T=T.concat(y(O.children)))}),T}return 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:[d.jsx(F.Input,{autoFocus:!0,value:n,placeholder:r.t("sheets-filter.panel.search-placeholder"),onChange:p}),d.jsxs("div",{"data-u-comp":"sheets-filter-panel",className:F.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",F.borderClassName),children:[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: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-pb-0 univer-pl-5 univer-pr-0.5 univer-pt-0 univer-text-sm",children:[d.jsx(F.Checkbox,{indeterminate:a,disabled:o.length===0,checked:s,onChange:m}),d.jsx("span",{"data-u-comp":"sheets-filter-panel-values-item-text",className:"univer-mx-1 univer-inline-block univer-flex-shrink univer-overflow-hidden univer-text-ellipsis univer-whitespace-nowrap univer-text-gray-900 dark:!univer-text-white",children:`${r.t("sheets-filter.panel.select-all")}`}),d.jsx("span",{"data-u-comp":"sheets-filter-panel-values-item-count",className:"univer-text-gray-400 dark:!univer-text-gray-500",children:`(${i.checked}/${i.checked+i.unchecked})`})]})}),d.jsx("div",{"data-u-comp":"sheets-filter-panel-values-virtual",className:"univer-flex-grow",children:d.jsx(F.Tree,{data:o,defaultExpandAll:!1,valueGroup:y(o),onChange:v=>{e.onFilterCheckToggled(v)},defaultCache:h,itemHeight:28,treeNodeClassName:`
|
|
11
11
|
univer-pr-2 univer-border-box univer-rounded-md
|
|
12
12
|
[&:hover_a]:univer-inline-block
|
|
13
13
|
hover:univer-bg-gray-50 univer-h-full
|
|
14
14
|
univer-text-gray-900 dark:hover:!univer-bg-gray-900
|
|
15
15
|
dark:!univer-text-white
|
|
16
|
-
`,attachRender:v=>d.jsxs("div",{className:"univer-ml-1 univer-flex univer-h-5 univer-flex-1 univer-cursor-pointer univer-items-center univer-justify-between univer-text-sm univer-text-primary-500",children:[d.jsx("span",{"data-u-comp":"sheets-filter-panel-values-item-count",className:"univer-text-gray-400 dark:!univer-text-gray-500",children:`(${v.count})`}),d.jsx("a",{className:"univer-box-border univer-hidden univer-h-4 univer-whitespace-nowrap univer-px-1.5",onClick:()=>{const T=[];v.children?v.children.forEach(O=>{O.children?O.children.forEach(b=>{T.push(b.key)}):T.push(O.key)}):T.push(v.key),e.onFilterOnly(T)},children:l})]})})})]})]})}function Ht(){const t=g.useDependency(c.SheetsFilterSyncController);if(!g.useObservable(t.visible$,void 0,!0))return null;const r=g.useDependency(u.LocaleService),n=g.useDependency(g.IMessageService),o=g.useObservable(t.enabled$,void 0,!0);return d.jsxs("div",{className:"univer-mt-2 univer-flex univer-items-center univer-justify-between univer-text-sm univer-text-gray-900 dark:univer-text-gray-200",children:[d.jsxs("div",{className:"univer-flex univer-items-center univer-gap-1",children:[d.jsx("span",{children:r.t("sheets-filter.sync.title")}),d.jsx(F.Tooltip,{title:o?r.t("sheets-filter.sync.statusTips.off"):r.t("sheets-filter.sync.statusTips.on"),asChild:!0,children:d.jsx(Xe,{className:"univer-block"})})]}),d.jsx(F.Switch,{defaultChecked:o,onChange:l=>{const i=l?r.t("sheets-filter.sync.switchTips.on"):r.t("sheets-filter.sync.switchTips.off");t.setEnabled(l),n.show({content:i,type:F.MessageType.Success,duration:2e3})}})]})}function Wt(){var b;const t=g.useDependency(G),e=g.useDependency(u.LocaleService),r=g.useDependency(u.ICommandService),n=g.useObservable(t.filterBy$,void 0,!0),o=g.useObservable(t.filterByModel$,void 0,!1),l=g.useObservable(()=>(o==null?void 0:o.canApply$)||S.of(!1),void 0,!1,[o]),i=Vt(e),s=!g.useObservable(t.hasCriteria$),a=I.useCallback(P=>{r.executeCommand(Ae.id,{filterBy:P})},[r]),h=I.useCallback(async()=>{await(o==null?void 0:o.clear()),r.executeCommand(re.id)},[o,r]),m=I.useCallback(()=>{r.executeCommand(re.id)},[r]),p=I.useCallback(async()=>{await(o==null?void 0:o.apply()),r.executeCommand(re.id)},[o,r]),v=(b=g.useDependency(c.SheetsFilterService).activeFilterModel)==null?void 0:b.getRange(),T=t.col,O=g.useComponentsOfPart(k.SheetsUIPart.FILTER_PANEL_EMBED_POINT);return d.jsxs("div",{"data-u-comp":"sheets-filter-panel",className:"univer-box-border univer-flex univer-max-h-[500px] univer-w-[400px] univer-flex-col univer-rounded-lg univer-bg-white univer-p-4 univer-shadow-lg dark:!univer-border-gray-600 dark:!univer-bg-gray-700",children:[d.jsx(g.ComponentContainer,{components:O,sharedProps:{range:v,colIndex:T,onClose:m}}),d.jsx("div",{className:"univer-mb-1 univer-flex-shrink-0 univer-flex-grow-0",children:d.jsx(F.Segmented,{value:n,items:i,onChange:P=>a(P)})}),o?d.jsx("div",{"data-u-comp":"sheets-filter-panel-content",className:"univer-flex-shrink univer-flex-grow univer-pt-2",children:n===c.FilterBy.VALUES?d.jsx(xt,{model:o}):n===c.FilterBy.COLORS?d.jsx(Ut,{model:o}):d.jsx(kt,{model:o})}):d.jsx("div",{className:"univer-flex-1"}),d.jsx(Ht,{}),d.jsxs("div",{"data-u-comp":"sheets-filter-panel-footer",className:"univer-mt-4 univer-inline-flex univer-flex-shrink-0 univer-flex-grow-0 univer-flex-nowrap univer-justify-between univer-overflow-hidden",children:[d.jsx(F.Button,{variant:"link",onClick:h,disabled:s,children:e.t("sheets-filter.panel.clear-filter")}),d.jsxs("span",{className:"univer-flex univer-gap-2",children:[d.jsx(F.Button,{variant:"default",onClick:m,children:e.t("sheets-filter.panel.cancel")}),d.jsx(F.Button,{disabled:!l,variant:"primary",onClick:p,children:e.t("sheets-filter.panel.confirm")})]})]})]})}function Vt(t){const e=t.getCurrentLocale();return I.useMemo(()=>[{label:t.t("sheets-filter.panel.by-values"),value:c.FilterBy.VALUES},{label:t.t("sheets-filter.panel.by-colors"),value:c.FilterBy.COLORS},{label:t.t("sheets-filter.panel.by-conditions"),value:c.FilterBy.CONDITIONS}],[e,t])}function jt(t){const e=t.get(c.SheetsFilterService);return{id:c.SmartToggleSheetsFilterCommand.id,type:g.MenuItemType.BUTTON_SELECTOR,icon:"FilterIcon",tooltip:"sheets-filter.toolbar.smart-toggle-filter-tooltip",hidden$:g.getMenuHiddenObservable(t,u.UniverInstanceType.UNIVER_SHEET),activated$:e.activeFilterModel$.pipe(S.map(r=>!!r)),disabled$:k.getObservableWithExclusiveRange$(t,k.getCurrentRangeDisable$(t,{worksheetTypes:[N.WorksheetFilterPermission,N.WorksheetViewPermission],rangeTypes:[N.RangeProtectionPermissionViewPoint]}))}}function Qt(t){const e=t.get(c.SheetsFilterService);return{id:c.ClearSheetsFilterCriteriaCommand.id,type:g.MenuItemType.BUTTON,title:"sheets-filter.toolbar.clear-filter-criteria",hidden$:g.getMenuHiddenObservable(t,u.UniverInstanceType.UNIVER_SHEET),disabled$:e.activeFilterModel$.pipe(S.switchMap(r=>{var n;return(n=r==null?void 0:r.hasCriteria$.pipe(S.map(o=>!o)))!=null?n:S.of(!0)}))}}function Gt(t){const e=t.get(c.SheetsFilterService);return{id:c.ReCalcSheetsFilterCommand.id,type:g.MenuItemType.BUTTON,title:"sheets-filter.toolbar.re-calc-filter-conditions",hidden$:g.getMenuHiddenObservable(t,u.UniverInstanceType.UNIVER_SHEET),disabled$:e.activeFilterModel$.pipe(S.switchMap(r=>{var n;return(n=r==null?void 0:r.hasCriteria$.pipe(S.map(o=>!o)))!=null?n:S.of(!0)}))}}const Yt={[g.RibbonDataGroup.ORGANIZATION]:{[c.SmartToggleSheetsFilterCommand.id]:{order:2,menuItemFactory:jt,[c.ClearSheetsFilterCriteriaCommand.id]:{order:0,menuItemFactory:Qt},[c.ReCalcSheetsFilterCommand.id]:{order:1,menuItemFactory:Gt}}}},qt={id:c.SmartToggleSheetsFilterCommand.id,binding:g.KeyCode.L|g.MetaKeys.CTRL_COMMAND|g.MetaKeys.SHIFT,description:"sheets-filter.shortcut.smart-toggle-filter",preconditions:k.whenSheetEditorFocused,group:"4_sheet-edit"};var Zt=Object.getOwnPropertyDescriptor,Kt=(t,e,r,n)=>{for(var o=n>1?void 0:n?Zt(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},B=(t,e)=>(r,n)=>e(r,n,t);const et="FILTER_PANEL_POPUP";let Ee=class extends me{constructor(e,r,n,o,l,i,s,a,h,m,p,y,v){super(v,y);_(this,"_popupDisposable");this._injector=e,this._componentManager=r,this._sheetsFilterPanelService=n,this._sheetCanvasPopupService=o,this._sheetsFilterService=l,this._localeService=i,this._shortcutService=s,this._commandService=a,this._menuManagerService=h,this._contextService=m,this._messageService=p,this._initCommands(),this._initShortcuts(),this._initMenuItems(),this._initUI()}dispose(){super.dispose(),this._closeFilterPopup()}_initShortcuts(){[qt].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_initCommands(){[c.SmartToggleSheetsFilterCommand,c.RemoveSheetFilterCommand,c.SetSheetFilterRangeCommand,c.SetSheetsFilterCriteriaCommand,c.ClearSheetsFilterCriteriaCommand,c.ReCalcSheetsFilterCommand,Ae,he,re].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenuItems(){this._menuManagerService.mergeMenu(Yt)}_initUI(){[[et,Wt],["FilterIcon",Ke]].forEach(([e,r])=>{this.disposeWithMe(this._componentManager.register(e,r))}),this.disposeWithMe(this._contextService.subscribeContextValue$(te).pipe(S.distinctUntilChanged()).subscribe(e=>{e?this._openFilterPopup():this._closeFilterPopup()})),this.disposeWithMe(this._sheetsFilterService.errorMsg$.subscribe(e=>{e&&this._messageService.show({type:F.MessageType.Error,content:this._localeService.t(e)})}))}_openFilterPopup(){const e=this._sheetsFilterPanelService.filterModel;if(!e)throw new Error("[SheetsFilterUIController]: no filter model when opening filter popup!");const r=e.getRange(),n=this._sheetsFilterPanelService.col,{startRow:o}=r;this._popupDisposable=this._sheetCanvasPopupService.attachPopupToCell(o,n,{componentKey:et,direction:"horizontal",onClickOutside:()=>this._commandService.syncExecuteCommand(re.id),offset:[5,0]})}_closeFilterPopup(){var e;(e=this._popupDisposable)==null||e.dispose(),this._popupDisposable=null}};Ee=Kt([B(0,u.Inject(u.Injector)),B(1,u.Inject(g.ComponentManager)),B(2,u.Inject(G)),B(3,u.Inject(k.SheetCanvasPopManagerService)),B(4,u.Inject(c.SheetsFilterService)),B(5,u.Inject(u.LocaleService)),B(6,g.IShortcutService),B(7,u.ICommandService),B(8,g.IMenuManagerService),B(9,u.IContextService),B(10,g.IMessageService),B(11,u.Inject(k.SheetsRenderService)),B(12,X.IRenderManagerService)],Ee);var Xt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Jt=(t,e,r)=>e in t?Xt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,er=(t,e,r,n)=>{for(var o=n>1?void 0:n?zt(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},Le=(t,e)=>(r,n)=>e(r,n,t),tt=(t,e,r)=>Jt(t,typeof e!="symbol"?e+"":e,r);const tr="SHEET_FILTER_UI_PLUGIN";C.UniverSheetsFilterUIPlugin=class extends u.Plugin{constructor(e=Te,r,n,o){super(),this._config=e,this._injector=r,this._configService=n,this._rpcChannelService=o;const{menu:l,...i}=u.merge({},Te,this._config);l&&this._configService.setConfig("menu",l,{merge:!0}),this._configService.setConfig(We,i)}onStarting(){u.registerDependencies(this._injector,[[G],[ne],[Ee]]),this._config.useRemoteFilterValuesGenerator&&this._rpcChannelService&&this._injector.add([ve,{useFactory:()=>fe.toModule(this._rpcChannelService.requestChannel(Ne))}])}onReady(){u.touchDependencies(this._injector,[[ne]])}onRendered(){u.touchDependencies(this._injector,[[Ee]])}},tt(C.UniverSheetsFilterUIPlugin,"type",u.UniverInstanceType.UNIVER_SHEET),tt(C.UniverSheetsFilterUIPlugin,"pluginName",tr),C.UniverSheetsFilterUIPlugin=er([u.DependentOn(c.UniverSheetsFilterPlugin),Le(1,u.Inject(u.Injector)),Le(2,u.IConfigService),Le(3,u.Optional(fe.IRPCChannelService))],C.UniverSheetsFilterUIPlugin);var rr=Object.getOwnPropertyDescriptor,ir=(t,e,r,n)=>{for(var o=n>1?void 0:n?rr(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},rt=(t,e)=>(r,n)=>e(r,n,t);C.UniverSheetsFilterUIWorkerPlugin=(Oe=class extends u.Plugin{constructor(e,r,n){super(),this._config=e,this._injector=r,this._rpcChannelService=n}onStarting(){[[ve,{useClass:be}]].forEach(e=>this._injector.add(e))}onReady(){this._rpcChannelService.registerChannel(Ne,fe.fromModule(this._injector.get(ve)))}},_(Oe,"type",u.UniverInstanceType.UNIVER_SHEET),_(Oe,"pluginName","SHEET_FILTER_UI_WORKER_PLUGIN"),Oe),C.UniverSheetsFilterUIWorkerPlugin=ir([rt(1,u.Inject(u.Injector)),rt(2,fe.IRPCChannelService)],C.UniverSheetsFilterUIWorkerPlugin),C.ChangeFilterByOperation=Ae,C.CloseFilterPanelOperation=re,C.OpenFilterPanelOperation=he,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
|
|
16
|
+
`,attachRender:v=>d.jsxs("div",{className:"univer-ml-1 univer-flex univer-h-5 univer-flex-1 univer-cursor-pointer univer-items-center univer-justify-between univer-text-sm univer-text-primary-500",children:[d.jsx("span",{"data-u-comp":"sheets-filter-panel-values-item-count",className:"univer-text-gray-400 dark:!univer-text-gray-500",children:`(${v.count})`}),d.jsx("a",{className:"univer-box-border univer-hidden univer-h-4 univer-whitespace-nowrap univer-px-1.5",onClick:()=>{const T=[];v.children?v.children.forEach(O=>{O.children?O.children.forEach(b=>{T.push(b.key)}):T.push(O.key)}):T.push(v.key),e.onFilterOnly(T)},children:l})]})})})]})]})}function Ht(){const t=g.useDependency(c.SheetsFilterSyncController);if(!g.useObservable(t.visible$,void 0,!0))return null;const r=g.useDependency(u.LocaleService),n=g.useDependency(g.IMessageService),o=g.useObservable(t.enabled$,void 0,!0);return d.jsxs("div",{className:"univer-mt-2 univer-flex univer-items-center univer-justify-between univer-text-sm univer-text-gray-900 dark:!univer-text-gray-200",children:[d.jsxs("div",{className:"univer-flex univer-items-center univer-gap-1",children:[d.jsx("span",{children:r.t("sheets-filter.sync.title")}),d.jsx(F.Tooltip,{title:o?r.t("sheets-filter.sync.statusTips.off"):r.t("sheets-filter.sync.statusTips.on"),asChild:!0,children:d.jsx(Xe,{className:"univer-block"})})]}),d.jsx(F.Switch,{defaultChecked:o,onChange:l=>{const i=l?r.t("sheets-filter.sync.switchTips.on"):r.t("sheets-filter.sync.switchTips.off");t.setEnabled(l),n.show({content:i,type:F.MessageType.Success,duration:2e3})}})]})}function Wt(){var b;const t=g.useDependency(G),e=g.useDependency(u.LocaleService),r=g.useDependency(u.ICommandService),n=g.useObservable(t.filterBy$,void 0,!0),o=g.useObservable(t.filterByModel$,void 0,!1),l=g.useObservable(()=>(o==null?void 0:o.canApply$)||S.of(!1),void 0,!1,[o]),i=Vt(e),s=!g.useObservable(t.hasCriteria$),a=I.useCallback(P=>{r.executeCommand(Ae.id,{filterBy:P})},[r]),h=I.useCallback(async()=>{await(o==null?void 0:o.clear()),r.executeCommand(re.id)},[o,r]),m=I.useCallback(()=>{r.executeCommand(re.id)},[r]),p=I.useCallback(async()=>{await(o==null?void 0:o.apply()),r.executeCommand(re.id)},[o,r]),v=(b=g.useDependency(c.SheetsFilterService).activeFilterModel)==null?void 0:b.getRange(),T=t.col,O=g.useComponentsOfPart(M.SheetsUIPart.FILTER_PANEL_EMBED_POINT);return d.jsxs("div",{"data-u-comp":"sheets-filter-panel",className:"univer-box-border univer-flex univer-max-h-[500px] univer-w-[400px] univer-flex-col univer-rounded-lg univer-bg-white univer-p-4 univer-shadow-lg dark:!univer-border-gray-600 dark:!univer-bg-gray-700",children:[d.jsx(g.ComponentContainer,{components:O,sharedProps:{range:v,colIndex:T,onClose:m}}),d.jsx("div",{className:"univer-mb-1 univer-flex-shrink-0 univer-flex-grow-0",children:d.jsx(F.Segmented,{value:n,items:i,onChange:P=>a(P)})}),o?d.jsx("div",{"data-u-comp":"sheets-filter-panel-content",className:"univer-flex-shrink univer-flex-grow univer-pt-2",children:n===c.FilterBy.VALUES?d.jsx(xt,{model:o}):n===c.FilterBy.COLORS?d.jsx(Ut,{model:o}):d.jsx(kt,{model:o})}):d.jsx("div",{className:"univer-flex-1"}),d.jsx(Ht,{}),d.jsxs("div",{"data-u-comp":"sheets-filter-panel-footer",className:"univer-mt-4 univer-inline-flex univer-flex-shrink-0 univer-flex-grow-0 univer-flex-nowrap univer-justify-between univer-overflow-hidden",children:[d.jsx(F.Button,{variant:"link",onClick:h,disabled:s,children:e.t("sheets-filter.panel.clear-filter")}),d.jsxs("span",{className:"univer-flex univer-gap-2",children:[d.jsx(F.Button,{variant:"default",onClick:m,children:e.t("sheets-filter.panel.cancel")}),d.jsx(F.Button,{disabled:!l,variant:"primary",onClick:p,children:e.t("sheets-filter.panel.confirm")})]})]})]})}function Vt(t){const e=t.getCurrentLocale();return I.useMemo(()=>[{label:t.t("sheets-filter.panel.by-values"),value:c.FilterBy.VALUES},{label:t.t("sheets-filter.panel.by-colors"),value:c.FilterBy.COLORS},{label:t.t("sheets-filter.panel.by-conditions"),value:c.FilterBy.CONDITIONS}],[e,t])}function jt(t){const e=t.get(c.SheetsFilterService);return{id:c.SmartToggleSheetsFilterCommand.id,type:g.MenuItemType.BUTTON_SELECTOR,icon:"FilterIcon",tooltip:"sheets-filter.toolbar.smart-toggle-filter-tooltip",hidden$:g.getMenuHiddenObservable(t,u.UniverInstanceType.UNIVER_SHEET),activated$:e.activeFilterModel$.pipe(S.map(r=>!!r)),disabled$:M.getObservableWithExclusiveRange$(t,M.getCurrentRangeDisable$(t,{worksheetTypes:[N.WorksheetFilterPermission,N.WorksheetViewPermission],rangeTypes:[N.RangeProtectionPermissionViewPoint]}))}}function Qt(t){const e=t.get(c.SheetsFilterService);return{id:c.ClearSheetsFilterCriteriaCommand.id,type:g.MenuItemType.BUTTON,title:"sheets-filter.toolbar.clear-filter-criteria",hidden$:g.getMenuHiddenObservable(t,u.UniverInstanceType.UNIVER_SHEET),disabled$:e.activeFilterModel$.pipe(S.switchMap(r=>{var n;return(n=r==null?void 0:r.hasCriteria$.pipe(S.map(o=>!o)))!=null?n:S.of(!0)}))}}function Gt(t){const e=t.get(c.SheetsFilterService);return{id:c.ReCalcSheetsFilterCommand.id,type:g.MenuItemType.BUTTON,title:"sheets-filter.toolbar.re-calc-filter-conditions",hidden$:g.getMenuHiddenObservable(t,u.UniverInstanceType.UNIVER_SHEET),disabled$:e.activeFilterModel$.pipe(S.switchMap(r=>{var n;return(n=r==null?void 0:r.hasCriteria$.pipe(S.map(o=>!o)))!=null?n:S.of(!0)}))}}const Yt={[g.RibbonDataGroup.ORGANIZATION]:{[c.SmartToggleSheetsFilterCommand.id]:{order:2,menuItemFactory:jt,[c.ClearSheetsFilterCriteriaCommand.id]:{order:0,menuItemFactory:Qt},[c.ReCalcSheetsFilterCommand.id]:{order:1,menuItemFactory:Gt}}}},qt={id:c.SmartToggleSheetsFilterCommand.id,binding:g.KeyCode.L|g.MetaKeys.CTRL_COMMAND|g.MetaKeys.SHIFT,description:"sheets-filter.shortcut.smart-toggle-filter",preconditions:M.whenSheetEditorFocused,group:"4_sheet-edit"};var Zt=Object.getOwnPropertyDescriptor,Kt=(t,e,r,n)=>{for(var o=n>1?void 0:n?Zt(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},B=(t,e)=>(r,n)=>e(r,n,t);const et="FILTER_PANEL_POPUP";let Ee=class extends me{constructor(e,r,n,o,l,i,s,a,h,m,p,y,v){super(v,y);_(this,"_popupDisposable");this._injector=e,this._componentManager=r,this._sheetsFilterPanelService=n,this._sheetCanvasPopupService=o,this._sheetsFilterService=l,this._localeService=i,this._shortcutService=s,this._commandService=a,this._menuManagerService=h,this._contextService=m,this._messageService=p,this._initCommands(),this._initShortcuts(),this._initMenuItems(),this._initUI()}dispose(){super.dispose(),this._closeFilterPopup()}_initShortcuts(){[qt].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_initCommands(){[c.SmartToggleSheetsFilterCommand,c.RemoveSheetFilterCommand,c.SetSheetFilterRangeCommand,c.SetSheetsFilterCriteriaCommand,c.ClearSheetsFilterCriteriaCommand,c.ReCalcSheetsFilterCommand,Ae,he,re].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenuItems(){this._menuManagerService.mergeMenu(Yt)}_initUI(){[[et,Wt],["FilterIcon",Ke]].forEach(([e,r])=>{this.disposeWithMe(this._componentManager.register(e,r))}),this.disposeWithMe(this._contextService.subscribeContextValue$(te).pipe(S.distinctUntilChanged()).subscribe(e=>{e?this._openFilterPopup():this._closeFilterPopup()})),this.disposeWithMe(this._sheetsFilterService.errorMsg$.subscribe(e=>{e&&this._messageService.show({type:F.MessageType.Error,content:this._localeService.t(e)})}))}_openFilterPopup(){const e=this._sheetsFilterPanelService.filterModel;if(!e)throw new Error("[SheetsFilterUIController]: no filter model when opening filter popup!");const r=e.getRange(),n=this._sheetsFilterPanelService.col,{startRow:o}=r;this._popupDisposable=this._sheetCanvasPopupService.attachPopupToCell(o,n,{componentKey:et,direction:"horizontal",onClickOutside:()=>this._commandService.syncExecuteCommand(re.id),offset:[5,0]})}_closeFilterPopup(){var e;(e=this._popupDisposable)==null||e.dispose(),this._popupDisposable=null}};Ee=Kt([B(0,u.Inject(u.Injector)),B(1,u.Inject(g.ComponentManager)),B(2,u.Inject(G)),B(3,u.Inject(M.SheetCanvasPopManagerService)),B(4,u.Inject(c.SheetsFilterService)),B(5,u.Inject(u.LocaleService)),B(6,g.IShortcutService),B(7,u.ICommandService),B(8,g.IMenuManagerService),B(9,u.IContextService),B(10,g.IMessageService),B(11,u.Inject(M.SheetsRenderService)),B(12,X.IRenderManagerService)],Ee);var Xt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Jt=(t,e,r)=>e in t?Xt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,er=(t,e,r,n)=>{for(var o=n>1?void 0:n?zt(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},Le=(t,e)=>(r,n)=>e(r,n,t),tt=(t,e,r)=>Jt(t,typeof e!="symbol"?e+"":e,r);const tr="SHEET_FILTER_UI_PLUGIN";C.UniverSheetsFilterUIPlugin=class extends u.Plugin{constructor(e=Te,r,n,o){super(),this._config=e,this._injector=r,this._configService=n,this._rpcChannelService=o;const{menu:l,...i}=u.merge({},Te,this._config);l&&this._configService.setConfig("menu",l,{merge:!0}),this._configService.setConfig(We,i)}onStarting(){u.registerDependencies(this._injector,[[G],[ne],[Ee]]),this._config.useRemoteFilterValuesGenerator&&this._rpcChannelService&&this._injector.add([ve,{useFactory:()=>fe.toModule(this._rpcChannelService.requestChannel(Ne))}])}onReady(){u.touchDependencies(this._injector,[[ne]])}onRendered(){u.touchDependencies(this._injector,[[Ee]])}},tt(C.UniverSheetsFilterUIPlugin,"type",u.UniverInstanceType.UNIVER_SHEET),tt(C.UniverSheetsFilterUIPlugin,"pluginName",tr),C.UniverSheetsFilterUIPlugin=er([u.DependentOn(c.UniverSheetsFilterPlugin),Le(1,u.Inject(u.Injector)),Le(2,u.IConfigService),Le(3,u.Optional(fe.IRPCChannelService))],C.UniverSheetsFilterUIPlugin);var rr=Object.getOwnPropertyDescriptor,ir=(t,e,r,n)=>{for(var o=n>1?void 0:n?rr(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(o=i(o)||o);return o},rt=(t,e)=>(r,n)=>e(r,n,t);C.UniverSheetsFilterUIWorkerPlugin=(Oe=class extends u.Plugin{constructor(e,r,n){super(),this._config=e,this._injector=r,this._rpcChannelService=n}onStarting(){[[ve,{useClass:be}]].forEach(e=>this._injector.add(e))}onReady(){this._rpcChannelService.registerChannel(Ne,fe.fromModule(this._injector.get(ve)))}},_(Oe,"type",u.UniverInstanceType.UNIVER_SHEET),_(Oe,"pluginName","SHEET_FILTER_UI_WORKER_PLUGIN"),Oe),C.UniverSheetsFilterUIWorkerPlugin=ir([rt(1,u.Inject(u.Injector)),rt(2,fe.IRPCChannelService)],C.UniverSheetsFilterUIWorkerPlugin),C.ChangeFilterByOperation=Ae,C.CloseFilterPanelOperation=re,C.OpenFilterPanelOperation=he,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
// index
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/preset-sheets-filter",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.11",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -63,21 +63,21 @@
|
|
|
63
63
|
"rxjs": ">=7.0.0"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@univerjs/sheets-filter": "0.10.
|
|
67
|
-
"@univerjs/sheets-filter-ui": "0.10.
|
|
66
|
+
"@univerjs/sheets-filter": "0.10.11",
|
|
67
|
+
"@univerjs/sheets-filter-ui": "0.10.11"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@univerjs/core": "0.10.
|
|
70
|
+
"@univerjs/core": "0.10.11",
|
|
71
71
|
"react": "18.3.1",
|
|
72
72
|
"react-dom": "18.3.1",
|
|
73
73
|
"rxjs": "7.8.2",
|
|
74
|
-
"typescript": "^5.9.
|
|
75
|
-
"@univerjs-infra/shared": "0.10.
|
|
74
|
+
"typescript": "^5.9.3",
|
|
75
|
+
"@univerjs-infra/shared": "0.10.11"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"prebuild:preset": "tsx prepare.ts",
|
|
79
79
|
"build:preset": "tsx build.ts",
|
|
80
|
-
"
|
|
80
|
+
"typecheck": "tsc --noEmit"
|
|
81
81
|
},
|
|
82
82
|
"module": "./lib/es/index.js"
|
|
83
83
|
}
|