@univerjs/sheets-filter 0.10.7-nightly.202509130703 → 0.10.8-nightly.202509200616

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Re=Object.defineProperty;var Fe=(i,r,e)=>r in i?Re(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e;var R=(i,r,e)=>Fe(i,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),S=require("@univerjs/sheets"),O=require("rxjs"),ve=require("@univerjs/engine-render"),pe=require("@univerjs/rpc"),K=require("@univerjs/engine-formula"),te="sheet.mutation.set-filter-range",re="sheet.mutation.set-filter-criteria",ne="sheet.mutation.remove-filter",ie="sheet.mutation.re-calc-filter",q=new Set([te,re,ne,ie]);var A=(i=>(i[i.VALUES=0]="VALUES",i[i.COLORS=1]="COLORS",i[i.CONDITIONS=2]="CONDITIONS",i))(A||{}),T=(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))(T||{});const se={operator:T.GREATER_THAN,fn:(i,r)=>U(i)?i>r:!1},oe={operator:T.GREATER_THAN_OR_EQUAL,fn:(i,r)=>U(i)?i>=r:!1},le={operator:T.LESS_THAN,fn:(i,r)=>U(i)?i<r:!1},ae={operator:T.LESS_THAN_OR_EQUAL,fn:(i,r)=>U(i)?i<=r:!1},ce={operator:T.EQUAL,fn:(i,r)=>U(i)?i===r:!1},k={operator:T.NOT_EQUALS,fn:(i,r)=>{if(typeof r=="string"){if(r===" ")return i!=null;const e=ue(i);return e&&Ee(r)?!he(r).test(e):e!==r}return U(i)?i!==r:!0}},de=new Map([]),we=[se,oe,le,ae,ce,k];we.forEach(i=>{de.set(i.operator,i)});function Me(i){return!!i}const ye={fn:(i,r)=>{const e=ue(i);return e===null?r==="":he(r).test(e)}};function W(i){return i?de.get(i):ye}function U(i){return typeof i=="number"}function Z(i){return!!(typeof i=="number"||typeof i=="string"&&d.isNumeric(i))}function ue(i){return typeof i=="boolean"||i==null?null:typeof i=="string"?i:i.toString()}function Ee(i){return typeof i=="number"?!1:i.indexOf("*")!==-1||i.indexOf("?")!==-1}function he(i){const r=i.replace(/[.+^${}()|[\]\\]/g,"\\$&").replaceAll("?",".").replace(/[*]/g,".$&");return new RegExp(`^${r}$`)}const H=()=>new Set;class $ extends d.Disposable{constructor(e,t,n){super();R(this,"_filteredOutRows$",new O.BehaviorSubject(H()));R(this,"filteredOutRows$",this._filteredOutRows$.asObservable());R(this,"_hasCriteria$",new O.BehaviorSubject(!1));R(this,"hasCriteria$",this._hasCriteria$.asObservable());R(this,"_filterColumnByIndex",new Map);R(this,"_alreadyFilteredOutRows",H());R(this,"_range");this.unitId=e,this.subUnitId=t,this._worksheet=n}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],[n])=>t-n).map(([t,n])=>n.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(e,t,n,s){const o=new $(e,t,n);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.forEach(n=>this._setCriteriaWithoutReCalc(n.colId,n)),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,[,n])=>{const s=n.calc({getAlreadyFilteredOutRows:()=>t});return s?d.mergeSets(t,s):t},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,n])=>{n.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,n=!1){if(!this._range)throw new Error("[FilterModel] could not set criteria before a range is set!");if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),n&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),n&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._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(([n,s])=>s)}_reCalcAllColumns(){this._alreadyFilteredOutRows=H(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns()}_setCriteriaWithoutReCalc(e,t){const n=this._range;if(!n)throw new Error("[FilterModel] could not set criteria before a range is set!");const{startColumn:s,endColumn:o}=n;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 me(this.unitId,this.subUnitId,this._worksheet,t,{getAlreadyFilteredOutRows:()=>this._alreadyFilteredOutRows}),l.setRangeAndColumn(n,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,n)=>d.mergeSets(t,n.filteredOutRows),new Set);this._alreadyFilteredOutRows=e}_reCalcWithNoCacheColumns(){const e=this._getAllFilterColumns().filter(t=>!t.hasCache());for(const t of e){const n=t.reCalc();n&&(this._alreadyFilteredOutRows=d.mergeSets(this._alreadyFilteredOutRows,n))}}}class me extends d.Disposable{constructor(e,t,n,s,o){super();R(this,"_filteredOutRows",null);R(this,"_filterFn",null);R(this,"_range",null);R(this,"_column",0);R(this,"_filterBy",A.VALUES);this.unitId=e,this.subUnitId=t,this._worksheet=n,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,n={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(n,!1,!1)){const{row:a,rowSpan:c,col:h}=l;if(o.has(a)&&(!c||c===1))continue;if(!(this._filterBy===A.VALUES?this._filterFn(d.extractPureTextFromCell(this._worksheet.getCell(a,h))):this._filterBy===A.COLORS?this._filterFn(this._worksheet.getComposedCellStyle(a,h)):this._filterFn($e(this._worksheet,a,h)))&&(s.add(a),c))for(let m=1;m<c;m++)s.add(a+m)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=Oe(this._criteria),this._filterBy=this._criteria.filters?A.VALUES:this._criteria.colorFilters?A.COLORS:A.CONDITIONS)}}function Oe(i){if(i.filters)return Ie(i.filters);if(i.colorFilters)return Te(i.colorFilters);if(i.customFilters)return Ae(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function Ie(i){const r=!!i.blank,e=new Set(i.filters);return t=>t===void 0||t===""?r:e.has(typeof t=="string"?t:`${t}`)}function Te(i){if(i.cellFillColors){const r=new Set(i.cellFillColors);return e=>{var n;if(!e||!((n=e.bg)!=null&&n.rgb))return!!r.has(null);const t=new d.ColorKit(e.bg.rgb).toRgbString();return r.has(t)}}if(i.cellTextColors){const r=new Set(i.cellTextColors);return e=>{var n;if(!e||!((n=e.cl)!=null&&n.rgb))return!!r.has(ve.COLOR_BLACK_RGB);const t=new d.ColorKit(e.cl.rgb).toRgbString();return r.has(t)}}throw new Error("[FilterModel]: color filters are not supported yet.")}function Ae(i){const r=i.customFilters.map(e=>Ue(e));return Ne(r)?i.and?be(r):xe(r):r[0]}function be(i){const[r,e]=i;return t=>r(t)&&e(t)}function xe(i){const[r,e]=i;return t=>r(t)||e(t)}function Ne(i){return i.length===2}function Ue(i){const r=i.val;if(i.operator===T.NOT_EQUALS&&!Z(r))return n=>k.fn(n,r);if(Me(i.operator)){if(!Z(r))return()=>!1;const n=W(i.operator),s=Number(r);return o=>n.fn(o,s)}const e=W(i.operator);return t=>e.fn(t,r)}function $e(i,r,e){const t=i.getCell(r,e);if(!t)return null;const n=i.getCellRaw(r,e);return t&&!n?Y(t):n?t.t===d.CellValueType.NUMBER&&typeof t.v=="string"?n.v:Y(n):null}function Y(i){var t,n;const r=(n=(t=i.p)==null?void 0:t.body)==null?void 0:n.dataStream;if(r)return r.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 Le=Object.getOwnPropertyDescriptor,Pe=(i,r,e,t)=>{for(var n=t>1?void 0:t?Le(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},z=(i,r)=>(e,t)=>r(e,t,i);const G="SHEET_FILTER_PLUGIN";exports.SheetsFilterService=class extends d.Disposable{constructor(e,t,n){super();R(this,"_filterModels",new Map);R(this,"_loadedUnitId$",new O.BehaviorSubject(null));R(this,"loadedUnitId$",this._loadedUnitId$.asObservable());R(this,"_errorMsg$",new O.BehaviorSubject(null));R(this,"errorMsg$",this._errorMsg$.asObservable());R(this,"_activeFilterModel$",new O.BehaviorSubject(null));R(this,"activeFilterModel$",this._activeFilterModel$.asObservable());this._resourcesManagerService=e,this._univerInstanceService=t,this._commandService=n,this._initModel(),this._initActiveFilterModel()}get activeFilterModel(){return this._activeFilterModel$.getValue()}ensureFilterModel(e,t){const n=this.getFilterModel(e,t);if(n)return n;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 $(e,t,o);return this._cacheFilterModel(e,t,l),l}getFilterModel(e,t){var n,s;return(s=(n=this._filterModels.get(e))==null?void 0:n.get(t))!=null?s:null}removeFilterModel(e,t){const n=this.getFilterModel(e,t);return n?(n.dispose(),this._filterModels.get(e).delete(t),!0):!1}setFilterErrorMsg(e){this._errorMsg$.next(e)}_updateActiveFilterModel(){let e;try{if(e=this._univerInstanceService.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 n=t.getUnitId(),s=t.getSheetId(),o=this.getFilterModel(n,s);this._activeFilterModel$.next(o)}_initActiveFilterModel(){this.disposeWithMe(O.merge(d.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(O.filter(([e])=>e.type===d.CommandType.MUTATION&&q.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(O.switchMap(e=>{var t;return(t=e==null?void 0:e.activeSheet$)!=null?t:O.of(null)}))).subscribe(()=>this._updateActiveFilterModel()))}_serializeAutoFiltersForUnit(e){const t=this._filterModels.get(e);if(!t)return"{}";const n={};return t.forEach((s,o)=>{n[o]=s.serialize()}),JSON.stringify(n)}_deserializeAutoFiltersForUnit(e,t){const n=this._univerInstanceService.getUniverSheetInstance(e);Object.keys(t).forEach(s=>{const o=t[s],l=$.deserialize(e,s,n.getSheetBySheetId(s),o);this._cacheFilterModel(e,s,l)})}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:G,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(n=>n.dispose()),this._filterModels.delete(e))}})}_cacheFilterModel(e,t,n){this._filterModels.has(e)||this._filterModels.set(e,new Map),this._filterModels.get(e).set(t,n)}};exports.SheetsFilterService=Pe([z(0,d.IResourceManagerService),z(1,d.IUniverInstanceService),z(2,d.ICommandService)],exports.SheetsFilterService);const F={id:te,type:d.CommandType.MUTATION,handler:(i,r)=>{const{subUnitId:e,unitId:t,range:n}=r;return i.get(exports.SheetsFilterService).ensureFilterModel(t,e).setRange(n),!0}},v={id:re,type:d.CommandType.MUTATION,handler:(i,r)=>{const{subUnitId:e,unitId:t,criteria:n,col:s,reCalc:o=!0}=r,a=i.get(exports.SheetsFilterService).getFilterModel(t,e);return a?(a.setCriteria(s,n,o),!0):!1}},I={id:ne,type:d.CommandType.MUTATION,handler:(i,r)=>{const{unitId:e,subUnitId:t}=r;return i.get(exports.SheetsFilterService).removeFilterModel(e,t)}},N={id:ie,type:d.CommandType.MUTATION,handler:(i,r)=>{const{unitId:e,subUnitId:t}=r,s=i.get(exports.SheetsFilterService).getFilterModel(e,t);return s?(s.reCalc(),!0):!1}},fe={id:"sheet.command.set-filter-range",type:d.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(exports.SheetsFilterService),t=i.get(d.ICommandService),n=i.get(d.IUndoRedoService),s=i.get(d.IUniverInstanceService),{unitId:o,subUnitId:l,range:a}=r;if(!S.getSheetCommandTarget(s,r)||e.getFilterModel(o,l))return!1;if(a.endRow===a.startRow){const C=i.get(d.ErrorService),_=i.get(d.LocaleService);return C.emit(_.t("sheets-filter.command.not-valid-filter-range")),!1}const u={id:F.id,params:{unitId:o,subUnitId:l,range:a}},m=t.syncExecuteCommand(u.id,u.params);return m&&n.pushUndoRedo({unitID:o,undoMutations:[{id:I.id,params:{unitId:o,subUnitId:l}}],redoMutations:[u]}),m}},ge={id:"sheet.command.remove-sheet-filter",type:d.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(d.IUniverInstanceService),t=i.get(exports.SheetsFilterService),n=i.get(d.ICommandService),s=i.get(d.IUndoRedoService),o=S.getSheetCommandTarget(e,r);if(!o)return!1;const{unitId:l,subUnitId:a}=o,c=t.getFilterModel(l,a);if(!c)return!1;const h=c==null?void 0:c.serialize(),u=ze(l,a,h),m=n.syncExecuteCommand(I.id,{unitId:l,subUnitId:a});return m&&s.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:[{id:I.id,params:{unitId:l,subUnitId:a}}]}),m}},De={id:"sheet.command.smart-toggle-filter",type:d.CommandType.COMMAND,handler:async i=>{const r=i.get(d.IUniverInstanceService),e=i.get(exports.SheetsFilterService),t=i.get(d.ICommandService),n=r.getCurrentUnitForType(d.UniverInstanceType.UNIVER_SHEET),s=n==null?void 0:n.getActiveSheet();if(!s||!n)return!1;const o=n.getUnitId(),l=s.getSheetId();if(e.getFilterModel(o,l))return t.executeCommand(ge.id,{unitId:o,subUnitId:l});const h=i.get(S.SheetsSelectionsService).getCurrentLastSelection();if(!h)return!1;const u=h.range,m=S.isSingleCellSelection(h)?S.expandToContinuousRange(u,{left:!0,right:!0,up:!0,down:!0},s):u;return t.executeCommand(fe.id,{unitId:o,subUnitId:l,range:m})}},Be={id:"sheet.command.set-filter-criteria",type:d.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(exports.SheetsFilterService),t=i.get(d.ICommandService),n=i.get(d.IUndoRedoService),{unitId:s,subUnitId:o,col:l,criteria:a}=r,c=e.getFilterModel(s,o);if(!c)return!1;const h=c.getRange();if(!h||l<h.startColumn||l>h.endColumn)return!1;const u=c.getFilterColumn(l),m=We(s,o,l,u),C={id:v.id,params:{unitId:s,subUnitId:o,col:l,criteria:a}},_=t.syncExecuteCommand(C.id,C.params);return _&&n.pushUndoRedo({unitID:s,undoMutations:[m],redoMutations:[C]}),_}},je={id:"sheet.command.clear-filter-criteria",type:d.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(exports.SheetsFilterService),t=i.get(d.IUndoRedoService),n=i.get(d.ICommandService),s=i.get(d.IUniverInstanceService),o=S.getSheetCommandTarget(s,r);if(!o)return!1;const{unitId:l,subUnitId:a}=o,c=e.getFilterModel(o.unitId,o.subUnitId);if(!c)return!1;const h=c.serialize(),u=Ce(l,a,h),m=Ve(l,a,h);return d.sequenceExecute(m,n).result?(t.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:m}),!0):!1}},He={id:"sheet.command.re-calc-filter",type:d.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(exports.SheetsFilterService),t=i.get(d.ICommandService),n=i.get(d.IUniverInstanceService),s=S.getSheetCommandTarget(n,r);if(!s)return!1;const{unitId:o,subUnitId:l}=s;return e.getFilterModel(s.unitId,s.subUnitId)?t.executeCommand(N.id,{unitId:o,subUnitId:l}):!1}};function ze(i,r,e){const t=[],n={id:F.id,params:{unitId:i,subUnitId:r,range:e.ref}};return t.push(n),Ce(i,r,e).forEach(o=>t.push(o)),t}function Ce(i,r,e){var n;const t=[];return(n=e.filterColumns)==null||n.forEach(s=>{const o={id:v.id,params:{unitId:i,subUnitId:r,col:s.colId,criteria:s}};t.push(o)}),t}function Ve(i,r,e){var n;const t=[];return(n=e.filterColumns)==null||n.forEach(s=>{const o={id:v.id,params:{unitId:i,subUnitId:r,col:s.colId,criteria:null}};t.push(o)}),t}function We(i,r,e,t){if(!t)return{id:v.id,params:{unitId:i,subUnitId:r,col:e,criteria:null}};const n=t.serialize();return{id:v.id,params:{unitId:i,subUnitId:r,col:e,criteria:n}}}const _e="sheets-filter.config",X={};function qe(i,r){for(let e=0;e<i.length;e++){let t=e;if(i[e])for(let n=e+1;n<i.length;n++)i[t]&&i[n]&&r(i[t],i[n])&&(i[t]=null,t=n)}return i.filter(e=>e!==null)}function x(i){return qe(i,(r,e)=>r.id===v.id&&e.id===v.id&&r.params.unitId===e.params.unitId&&r.params.subUnitId===e.params.subUnitId&&r.params.col===e.params.col)}var ke=Object.getOwnPropertyDescriptor,Ge=(i,r,e,t)=>{for(var n=t>1?void 0:t?ke(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},b=(i,r)=>(e,t)=>r(e,t,i);let L=class extends d.Disposable{constructor(r,e,t,n,s,o,l){super();R(this,"_disposableCollection",new d.DisposableCollection);this._commandService=r,this._sheetInterceptorService=e,this._sheetsFilterService=t,this._univerInstanceService=n,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(r=>{r&&this.disposeWithMe(r.filteredOutRows$.subscribe(()=>{this._zebraCrossingCacheController.updateZebraCrossingCache(r.unitId,r.subUnitId)}))}))}_initCommands(){[v,F,N,I].forEach(r=>{var e;this.disposeWithMe(this._commandService.registerCommand(r)),(e=this._dataSyncPrimaryController)==null||e.registerSyncingMutations(r)})}_initInterceptors(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>this._getUpdateFilter(r)})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===S.SetWorksheetActiveOperation.id){const e=r.params,t=e.subUnitId,n=e.unitId;if(!t||!n)return;this._registerRefRange(n,t)}if(r.id===F.id){const e=r.params,t=e.subUnitId,n=e.unitId;if(!t||!n)return;this._registerRefRange(e.unitId,e.subUnitId)}})),this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe(r=>{if(r){const e=this._univerInstanceService.getUniverSheetInstance(r),t=e==null?void 0:e.getActiveSheet();t&&this._registerRefRange(r,t.getSheetId())}}))}_registerRefRange(r,e){var l;this._disposableCollection.dispose();const t=this._univerInstanceService.getUniverSheetInstance(r),n=t==null?void 0:t.getSheetBySheetId(e);if(!t||!n)return;const s=(l=this._sheetsFilterService.getFilterModel(r,e))==null?void 0:l.getRange(),o=a=>{switch(a.id){case S.InsertRowCommand.id:{const c=a.params,h=c.unitId||r,u=c.subUnitId||e;return this._handleInsertRowCommand(c,h,u)}case S.InsertColCommand.id:{const c=a.params,h=c.unitId||r,u=c.subUnitId||e;return this.handleInsertColCommand(c.range,h,u)}case S.RemoveColCommand.id:{const c=a.params;return this.handleRemoveColCommand(c.range,r,e)}case S.RemoveRowCommand.id:{const c=a.params;return this._handleRemoveRowCommand(c,r,e)}case S.EffectRefRangId.MoveColsCommandId:{const c=a.params;return this.handleMoveColsCommand({fromRange:c.fromRange,toRange:c.toRange},r,e)}case S.EffectRefRangId.MoveRowsCommandId:{const c=a.params;return this._handleMoveRowsCommand(c,r,e)}case S.MoveRangeCommand.id:{const c=a.params;return this._handleMoveRangeCommand(c,r,e)}}return{redos:[],undos:[]}};s&&this._disposableCollection.add(this._refRangeService.registerRefRange(s,o,r,e))}_getUpdateFilter(r){const{id:e}=r;switch(e){case S.RemoveSheetCommand.id:{const t=r.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case S.CopySheetCommand.id:{const t=r.params,{targetSubUnitId:n,unitId:s,subUnitId:o}=t;return!s||!o||!n?this._handleNull():this._handleCopySheetCommand(s,o,n)}}return{redos:[],undos:[]}}handleInsertColCommand(r,e,t){var f;const n=this._sheetsFilterService.getFilterModel(e,t),s=(f=n==null?void 0:n.getRange())!=null?f:null;if(!n||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:a,endColumn:c}=r,h=c-a+1;if(c>l)return this._handleNull();const u=[],m=[],C=a,_={unitId:e,subUnitId:t,range:{...s,startColumn:a<=o?o+h:o,endColumn:l+h}},p={unitId:e,subUnitId:t,range:s};u.push({id:F.id,params:_}),m.push({id:F.id,params:p});const w=n.getAllFilterColumns().filter(g=>g[0]>=C);if(w.length!==0){const{newRange:g,oldRange:y}=this._moveCriteria(e,t,w,h);u.push(...y.redos,...g.redos),m.push(...g.undos,...y.undos)}return{redos:x(u),undos:x(m)}}_handleInsertRowCommand(r,e,t){var p;const n=this._sheetsFilterService.getFilterModel(e,t),s=(p=n==null?void 0:n.getRange())!=null?p:null;if(!n||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{startRow:a,endRow:c}=r.range,h=c-a+1;if(c>l)return this._handleNull();const u=[],m=[],C={unitId:e,subUnitId:t,range:{...s,startRow:a<=o?o+h:o,endRow:l+h}},_={unitId:e,subUnitId:t,range:s};return u.push({id:F.id,params:C}),m.push({id:F.id,params:_}),{redos:x(u),undos:x(m)}}handleRemoveColCommand(r,e,t){var w;const n=this._sheetsFilterService.getFilterModel(e,t),s=(w=n==null?void 0:n.getRange())!=null?w:null;if(!n||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:a,endColumn:c}=r;if(a>l)return this._handleNull();const h=[],u=[],m=c<o?0:Math.min(c,l)-Math.max(a,o)+1,C=c-a+1,_=n.getAllFilterColumns();_.forEach(f=>{const[g,y]=f;g<=c&&g>=a&&(h.push({id:v.id,params:{unitId:e,subUnitId:t,col:g,criteria:null}}),u.push({id:v.id,params:{unitId:e,subUnitId:t,col:g,criteria:{...y.serialize(),colId:g}}}))});const p=_.filter(f=>{const[g,y]=f;return g>c});let M={undos:[],redos:[]};if(p.length>0){const{oldRange:f,newRange:g}=this._moveCriteria(e,t,p,-C);M=g,h.push(...f.redos),u.unshift(...f.undos)}if(m===l-o+1){const f={unitId:e,subUnitId:t};h.push({id:I.id,params:f}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}})}else{const f=o<=a?o:m===0?o-C:a,g=o<=a?l-m:l-C,y={unitId:e,subUnitId:t,range:{...s,startColumn:f,endColumn:g}};h.push({id:F.id,params:y}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),h.push(...M.redos),u.unshift(...M.undos)}return{undos:u,redos:h}}_handleRemoveRowCommand(r,e,t){var p;const n=this._sheetsFilterService.getFilterModel(e,t);if(!n)return this._handleNull();const s=n.getRange(),{startRow:o,endRow:l}=s,{startRow:a,endRow:c}=r.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 h=[],u=[],m=n.getAllFilterColumns(),C=o<=c&&o>=a;u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}});const _=Math.min(c,l)-Math.max(a,o)+1;if(_===l-o+1||C){const M={unitId:e,subUnitId:t};h.push({id:I.id,params:M}),m.forEach(w=>{const[f,g]=w,y={unitId:e,subUnitId:t,col:f,criteria:{...g.serialize(),colId:f}};u.push({id:v.id,params:y})})}else{const M=(p=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:p.getSheetBySheetId(t);if(!M)return this._handleNull();const w=[];for(let E=a;E<=c;E++)M.getRowFiltered(E)&&w.push(E);const f=Math.min(o,a),g=f+(l-o)-_+w.length,y={unitId:e,subUnitId:t,range:{...s,startRow:f,endRow:g}};h.push({id:F.id,params:y})}return{undos:x(u),redos:x(h)}}handleMoveColsCommand({fromRange:r,toRange:e},t,n){var w;const s=this._sheetsFilterService.getFilterModel(t,n),o=(w=s==null?void 0:s.getRange())!=null?w:null;if(!s||!o)return this._handleNull();const{startColumn:l,endColumn:a}=o;if(r.endColumn<l&&e.startColumn<=l||r.startColumn>a&&e.endColumn>a)return this._handleNull();const c=[],h=[],u={};for(let f=l;f<=a;f++)u[f]={colIndex:f,filter:s.getFilterColumn(f)};d.moveMatrixArray(r.startColumn,r.endColumn-r.startColumn+1,e.startColumn,u);let m=o.startColumn,C=o.endColumn;l>=r.startColumn&&l<=r.endColumn&&e.startColumn>r.startColumn&&r.endColumn<a&&(m=r.endColumn+1),a>=r.startColumn&&a<=r.endColumn&&e.startColumn<r.startColumn&&r.startColumn>l&&(C=r.startColumn-1);const _=Object.keys(u).map(f=>Number(f)),p=_.find(f=>u[f].colIndex===C),M=_.find(f=>u[f].colIndex===m);if(_.forEach(f=>{var Q,J;const{colIndex:g,filter:y}=u[f],E=f;if(y){if(E>=M&&E<=p){const j={unitId:t,subUnitId:n,col:E,criteria:{...y.serialize(),colId:E}},Se={unitId:t,subUnitId:n,col:E,criteria:s.getFilterColumn(E)?{...(Q=s.getFilterColumn(E))==null?void 0:Q.serialize(),colId:E}:null};c.push({id:v.id,params:j}),h.push({id:v.id,params:Se})}if(!((J=u[g])!=null&&J.filter)){const j={unitId:t,subUnitId:n,col:g,criteria:null};c.push({id:v.id,params:j}),h.push({id:v.id,params:{unitId:t,subUnitId:n,col:g,criteria:{...y.serialize(),colId:g}}})}}}),l!==M||a!==p){const f={unitId:t,subUnitId:n,range:{...o,startColumn:M,endColumn:p}};c.unshift({id:F.id,params:f}),h.unshift({id:F.id,params:{range:o,unitId:t,subUnitId:n}})}return{undos:h,redos:c}}_handleMoveRowsCommand(r,e,t){var f;const n=this._sheetsFilterService.getFilterModel(e,t),s=(f=n==null?void 0:n.getRange())!=null?f:null;if(!n||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{fromRange:a,toRange:c}=r;if(a.endRow<o&&c.startRow<=o||a.startRow>l&&c.endRow>l)return this._handleNull();const h=[],u=[],m={};for(let g=o;g<=l;g++)m[g]={oldIndex:g};const C=o;let _=l;l>=a.startRow&&l<=a.endRow&&c.startRow<a.startRow&&a.startRow>o&&(_=a.startRow-1),d.moveMatrixArray(a.startRow,a.endRow-a.startRow+1,c.startRow,m);const p=Object.keys(m).map(g=>Number(g)),M=p.find(g=>m[g].oldIndex===_),w=p.find(g=>m[g].oldIndex===C);if(o!==w||l!==M){const g={unitId:e,subUnitId:t,range:{...s,startRow:w,endRow:M}};h.push({id:F.id,params:g},{id:N.id,params:{unitId:e,subUnitId:t}}),u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}},{id:N.id,params:{unitId:e,subUnitId:t}})}return{redos:h,undos:u}}_handleMoveRangeCommand(r,e,t){const{fromRange:n,toRange:s}=r,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(n,l)){const h=l.startRow-n.startRow,u=l.startColumn-n.startColumn,m={startRow:s.startRow+h,startColumn:s.startColumn+u,endRow:s.startRow+h+(l.endRow-l.startRow),endColumn:s.startColumn+u+(l.endColumn-l.startColumn)},C={id:I.id,params:{unitId:e,subUnitId:t}},_={id:F.id,params:{unitId:e,subUnitId:t,range:m}},p={id:F.id,params:{unitId:e,subUnitId:t,range:l}};a.push(C,_),c.push(C,p);const M=o.getAllFilterColumns(),w=s.startColumn-n.startColumn;M.forEach(f=>{const[g,y]=f;y&&(a.push({id:v.id,params:{unitId:e,subUnitId:t,col:g+w,criteria:{...y.serialize(),colId:g+w}}}),c.push({id:v.id,params:{unitId:e,subUnitId:t,col:g,criteria:{...y.serialize(),colId:g}}}))})}else if(d.Rectangle.intersects(s,l)){const h={...l,endRow:Math.max(l.endRow,s.endRow)};a.push({id:F.id,params:{unitId:e,subUnitId:t,range:h}}),c.push({id:F.id,params:{unitId:e,subUnitId:t,range:l}})}return{redos:a,undos:c}}_handleRemoveSheetCommand(r,e,t){const n=this._sheetsFilterService.getFilterModel(e,t);if(!n)return this._handleNull();const s=n.getRange();if(!s)return this._handleNull();const o=[],l=[];return n.getAllFilterColumns().forEach(([c,h])=>{l.push({id:v.id,params:{unitId:e,subUnitId:t,col:c,criteria:{...h.serialize(),colId:c}}})}),o.push({id:I.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(r,e,t){const n=this._sheetsFilterService.getFilterModel(r,e);if(!n)return this._handleNull();const s=n.getRange();if(!s)return this._handleNull();const o=[],l=[],a=[],c=[];return n.getAllFilterColumns().forEach(([u,m])=>{o.push({id:v.id,params:{unitId:r,subUnitId:t,col:u,criteria:{...m.serialize(),colId:u}}}),a.push({id:v.id,params:{unitId:r,subUnitId:t,col:u,criteria:null}})}),a.push({id:I.id,params:{unitId:r,subUnitId:t,range:s}}),o.unshift({id:F.id,params:{range:s,unitId:r,subUnitId:t}}),{undos:l,redos:o,preUndos:a,preRedos:c}}_handleNull(){return{redos:[],undos:[]}}_initRowFilteredInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(S.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(r,e)=>{var t,n;return r?!0:(n=(t=this._sheetsFilterService.getFilterModel(e.unitId,e.subUnitId))==null?void 0:t.isRowFiltered(e.row))!=null?n:!1}}))}_moveCriteria(r,e,t,n){const s={unitId:r,subUnitId:e,criteria:null,col:-1},o=[],l=[],a=[],c=[];return t.forEach(h=>{const[u,m]=h;l.push({id:v.id,params:{...s,col:u}}),o.push({id:v.id,params:{...s,col:u,criteria:{...m.serialize(),colId:u}}})}),t.forEach(h=>{const[u,m]=h;c.push({id:v.id,params:{...s,col:u+n,criteria:{...m.serialize(),colId:u+n}}}),a.push({id:v.id,params:{...s,col:u+n,criteria:null}})}),{newRange:{redos:c,undos:a},oldRange:{redos:l,undos:o}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((r,e)=>{var c,h;const{unitId:t,subUnitId:n}=r.params||{},s=this._sheetsFilterService.getFilterModel(t,n);if(!s)return;const o=Array.from(s.filteredOutRows).sort((u,m)=>u-m),l=[];let a=!1;if(r.id===S.RemoveRowMutation.id){const{startRow:u,endRow:m}=r.params.range,C=o.filter(_=>_>=u&&_<=m);o.forEach(_=>{if(_<u)l.push(_);else if(a=!0,_<=m){const p=Math.max(u,l.length?l[l.length-1]+1:u);l.push(p)}else l.push(_-(m-u+1-C.length))})}if(r.id===S.InsertRowMutation.id){const{startRow:u,endRow:m}=r.params.range;o.forEach(C=>{C>=u?(a=!0,l.push(C+(m-u+1))):l.push(C)})}if(a&&(s.filteredOutRows=new Set(l)),r.id===S.SetRangeValuesMutation.id&&!(e!=null&&e.onlyLocal)){const u=this._getExtendRegion(t,n);if(u){const m=r.params.cellValue;if(m)for(let C=u.startColumn;C<=u.endColumn;C++){const _=(c=m==null?void 0:m[u.startRow])==null?void 0:c[C];if(_&&this._cellHasValue(_)){const p=(h=this._univerInstanceService.getUnit(t))==null?void 0:h.getSheetBySheetId(n);if(p){const M=S.expandToContinuousRange(u,{down:!0},p),w=this._sheetsFilterService.getFilterModel(t,n),f=w.getRange();w.setRange({...f,endRow:M.endRow}),this._registerRefRange(t,n)}}}}}}))}_getExtendRegion(r,e){var a;const t=this._sheetsFilterService.getFilterModel(r,e);if(!t)return null;const n=(a=this._univerInstanceService.getUnit(r))==null?void 0:a.getSheetBySheetId(e);if(!n)return null;const s=t.getRange();if(!s)return null;const o=n.getRowCount()-1,l=n.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(r=>{const e=r.params,t=S.getSheetCommandTarget(this._univerInstanceService);if(!t)return;const{subUnitId:n,unitId:s}=t,o=this._sheetsFilterService.getFilterModel(s,n);if(!o)return;const l=o.getRange();if(r.id===S.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(r){const e=Object.values(r);return!(e.length===0||e.every(t=>t==null))}};L=Ge([b(0,d.ICommandService),b(1,d.Inject(S.SheetInterceptorService)),b(2,d.Inject(exports.SheetsFilterService)),b(3,d.IUniverInstanceService),b(4,d.Inject(S.RefRangeService)),b(5,d.Optional(pe.DataSyncPrimaryController)),b(6,d.Inject(S.ZebraCrossingCacheController))],L);var Qe=Object.getOwnPropertyDescriptor,Je=(i,r,e,t)=>{for(var n=t>1?void 0:t?Qe(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},V=(i,r)=>(e,t)=>r(e,t,i);const Ke=[v.id,N.id],Ze=[S.InsertColMutation.id,S.RemoveColMutation.id,S.MoveColsMutation.id];exports.SheetsFilterSyncController=class extends d.Disposable{constructor(e,t,n){super();R(this,"_d",new d.DisposableCollection);R(this,"_visible$",new O.BehaviorSubject(!1));R(this,"visible$",this._visible$.asObservable());R(this,"_enabled$",new O.BehaviorSubject(!0));R(this,"enabled$",this._enabled$.asObservable());this._sheetsFilterController=e,this._commandService=t,this._configService=n;const s=this._configService.getConfig(_e);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(Ze.includes(e.id)&&(t!=null&&t.fromCollab)){if(e.id===S.InsertColMutation.id){const{range:n,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleInsertColCommand(n,s,o);d.sequenceExecute(l,this._commandService,t)}else if(e.id===S.RemoveColMutation.id){const{range:n,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleRemoveColCommand(n,s,o);d.sequenceExecute(l,this._commandService,t)}else if(e.id===S.MoveColsMutation.id){const{sourceRange:n,targetRange:s,unitId:o,subUnitId:l}=e.params,{redos:a}=this._sheetsFilterController.handleMoveColsCommand({fromRange:n,toRange:s},o,l);d.sequenceExecute(a,this._commandService,t)}}}))}};exports.SheetsFilterSyncController=Je([V(0,d.Inject(L)),V(1,d.ICommandService),V(2,d.IConfigService)],exports.SheetsFilterSyncController);var Ye=Object.getOwnPropertyDescriptor,Xe=(i,r,e,t)=>{for(var n=t>1?void 0:t?Ye(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},P=(i,r)=>(e,t)=>r(e,t,i);let B=class extends d.Disposable{constructor(i,r,e,t){super(),this._activeDirtyManagerService=i,this._sheetRowFilteredService=r,this._sheetsFilterService=e,this._univerInstanceService=t,this._initFormulaDirtyRange(),this._registerSheetRowFiltered()}_initFormulaDirtyRange(){q.forEach(i=>{this._activeDirtyManagerService.register(i,{commandId:i,getDirtyData:r=>{const e=r.params,{unitId:t,subUnitId:n}=e;return{dirtyRanges:this._getHideRowMutation(t,n),clearDependencyTreeCache:{[t]:{[n]:"1"}}}}})})}_getHideRowMutation(i,r){var l,a;const e=(l=this._sheetsFilterService.getFilterModel(i,r))==null?void 0:l.getRange(),t=(a=this._univerInstanceService.getUnit(i))==null?void 0:a.getSheetBySheetId(r);if(e==null||t==null)return[];const{startRow:n,endRow:s}=e;return[{unitId:i,sheetId:r,range:{startRow:n,startColumn:0,endRow:s,endColumn:t.getColumnCount()-1}}]}_registerSheetRowFiltered(){this._sheetRowFilteredService.register((i,r,e)=>{var t,n;return(n=(t=this._sheetsFilterService.getFilterModel(i,r))==null?void 0:t.isRowFiltered(e))!=null?n:!1})}};B=Xe([P(0,d.Inject(K.IActiveDirtyManagerService)),P(1,d.Inject(K.ISheetRowFilteredService)),P(2,d.Inject(exports.SheetsFilterService)),P(3,d.IUniverInstanceService)],B);var et=Object.getOwnPropertyDescriptor,tt=(i,r,e,t)=>{for(var n=t>1?void 0:t?et(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},ee=(i,r)=>(e,t)=>r(e,t,i),D;exports.UniverSheetsFilterPlugin=(D=class extends d.Plugin{constructor(r=X,e,t){super(),this._config=r,this._injector=e,this._configService=t;const{...n}=d.merge({},X,this._config);this._configService.setConfig(_e,n)}onStarting(){[[B],[exports.SheetsFilterService],[L],[exports.SheetsFilterSyncController]].forEach(r=>this._injector.add(r))}onReady(){d.touchDependencies(this._injector,[[B],[L],[exports.SheetsFilterSyncController]])}},R(D,"type",d.UniverInstanceType.UNIVER_SHEET),R(D,"pluginName",G),D);exports.UniverSheetsFilterPlugin=tt([ee(1,d.Inject(d.Injector)),ee(2,d.IConfigService)],exports.UniverSheetsFilterPlugin);exports.ClearSheetsFilterCriteriaCommand=je;exports.CustomFilterOperator=T;exports.FILTER_MUTATIONS=q;exports.FilterBy=A;exports.FilterColumn=me;exports.FilterModel=$;exports.ReCalcSheetsFilterCommand=He;exports.ReCalcSheetsFilterMutation=N;exports.RemoveSheetFilterCommand=ge;exports.RemoveSheetsFilterMutation=I;exports.SHEET_FILTER_SNAPSHOT_ID=G;exports.SetSheetFilterRangeCommand=fe;exports.SetSheetsFilterCriteriaCommand=Be;exports.SetSheetsFilterCriteriaMutation=v;exports.SetSheetsFilterRangeMutation=F;exports.SmartToggleSheetsFilterCommand=De;exports.equals=ce;exports.getCustomFilterFn=W;exports.greaterThan=se;exports.greaterThanOrEqualTo=oe;exports.lessThan=le;exports.lessThanOrEqualTo=ae;exports.notEquals=k;
1
+ "use strict";var Re=Object.defineProperty;var Fe=(i,n,e)=>n in i?Re(i,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[n]=e;var R=(i,n,e)=>Fe(i,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),S=require("@univerjs/sheets"),O=require("rxjs"),ve=require("@univerjs/engine-render"),pe=require("@univerjs/rpc"),K=require("@univerjs/engine-formula"),te="sheet.mutation.set-filter-range",re="sheet.mutation.set-filter-criteria",ne="sheet.mutation.remove-filter",ie="sheet.mutation.re-calc-filter",q=new Set([te,re,ne,ie]);var A=(i=>(i[i.VALUES=0]="VALUES",i[i.COLORS=1]="COLORS",i[i.CONDITIONS=2]="CONDITIONS",i))(A||{}),T=(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))(T||{});const se={operator:T.GREATER_THAN,fn:(i,n)=>U(i)?i>n:!1},oe={operator:T.GREATER_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i>=n:!1},le={operator:T.LESS_THAN,fn:(i,n)=>U(i)?i<n:!1},ae={operator:T.LESS_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i<=n:!1},ce={operator:T.EQUAL,fn:(i,n)=>U(i)?i===n:!1},k={operator:T.NOT_EQUALS,fn:(i,n)=>{if(typeof n=="string"){if(n===" ")return i!=null;const e=ue(i);return e&&Ee(n)?!he(n).test(e):e!==n}return U(i)?i!==n:!0}},de=new Map([]),we=[se,oe,le,ae,ce,k];we.forEach(i=>{de.set(i.operator,i)});function Me(i){return!!i}const ye={fn:(i,n)=>{const e=ue(i);return e===null?n==="":he(n).test(e)}};function W(i){return i?de.get(i):ye}function U(i){return typeof i=="number"}function Z(i){return!!(typeof i=="number"||typeof i=="string"&&d.isNumeric(i))}function ue(i){return typeof i=="boolean"||i==null?null:typeof i=="string"?i:i.toString()}function Ee(i){return typeof i=="number"?!1:i.indexOf("*")!==-1||i.indexOf("?")!==-1}function he(i){const n=i.replace(/[.+^${}()|[\]\\]/g,"\\$&").replaceAll("?",".").replace(/[*]/g,".$&");return new RegExp(`^${n}$`)}const H=()=>new Set;class $ extends d.Disposable{constructor(e,t,r){super();R(this,"_filteredOutRows$",new O.BehaviorSubject(H()));R(this,"filteredOutRows$",this._filteredOutRows$.asObservable());R(this,"_hasCriteria$",new O.BehaviorSubject(!1));R(this,"hasCriteria$",this._hasCriteria$.asObservable());R(this,"_filterColumnByIndex",new Map);R(this,"_alreadyFilteredOutRows",H());R(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 $(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=H(),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 me(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 me extends d.Disposable{constructor(e,t,r,s,o){super();R(this,"_filteredOutRows",null);R(this,"_filterFn",null);R(this,"_range",null);R(this,"_column",0);R(this,"_filterBy",A.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:h}=l;if(o.has(a)&&(!c||c===1))continue;if(!(this._filterBy===A.VALUES?this._filterFn(d.extractPureTextFromCell(this._worksheet.getCell(a,h))):this._filterBy===A.COLORS?this._filterFn(this._worksheet.getComposedCellStyle(a,h)):this._filterFn($e(this._worksheet,a,h)))&&(s.add(a),c))for(let m=1;m<c;m++)s.add(a+m)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=Oe(this._criteria),this._filterBy=this._criteria.filters?A.VALUES:this._criteria.colorFilters?A.COLORS:A.CONDITIONS)}}function Oe(i){if(i.filters)return Ie(i.filters);if(i.colorFilters)return Te(i.colorFilters);if(i.customFilters)return Ae(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function Ie(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 Te(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(ve.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 Ae(i){const n=i.customFilters.map(e=>Ue(e));return xe(n)?i.and?be(n):Ne(n):n[0]}function be(i){const[n,e]=i;return t=>n(t)&&e(t)}function Ne(i){const[n,e]=i;return t=>n(t)||e(t)}function xe(i){return i.length===2}function Ue(i){const n=i.val;if(i.operator===T.NOT_EQUALS&&!Z(n))return r=>k.fn(r,n);if(Me(i.operator)){if(!Z(n))return()=>!1;const r=W(i.operator),s=Number(n);return o=>r.fn(o,s)}const e=W(i.operator);return t=>e.fn(t,n)}function $e(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?Y(t):r?t.t===d.CellValueType.NUMBER&&typeof t.v=="string"?r.v:t.t===d.CellValueType.NUMBER?Number(r.v):Y(r):null}function Y(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 Le=Object.getOwnPropertyDescriptor,Pe=(i,n,e,t)=>{for(var r=t>1?void 0:t?Le(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},z=(i,n)=>(e,t)=>n(e,t,i);const G="SHEET_FILTER_PLUGIN";exports.SheetsFilterService=class extends d.Disposable{constructor(e,t,r){super();R(this,"_filterModels",new Map);R(this,"_loadedUnitId$",new O.BehaviorSubject(null));R(this,"loadedUnitId$",this._loadedUnitId$.asObservable());R(this,"_errorMsg$",new O.BehaviorSubject(null));R(this,"errorMsg$",this._errorMsg$.asObservable());R(this,"_activeFilterModel$",new O.BehaviorSubject(null));R(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 $(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(O.merge(d.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(O.filter(([e])=>e.type===d.CommandType.MUTATION&&q.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(O.switchMap(e=>{var t;return(t=e==null?void 0:e.activeSheet$)!=null?t:O.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=$.deserialize(e,s,r.getSheetBySheetId(s),o);this._cacheFilterModel(e,s,l)})}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:G,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)}};exports.SheetsFilterService=Pe([z(0,d.IResourceManagerService),z(1,d.IUniverInstanceService),z(2,d.ICommandService)],exports.SheetsFilterService);const F={id:te,type:d.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,range:r}=n;return i.get(exports.SheetsFilterService).ensureFilterModel(t,e).setRange(r),!0}},v={id:re,type:d.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,criteria:r,col:s,reCalc:o=!0}=n,a=i.get(exports.SheetsFilterService).getFilterModel(t,e);return a?(a.setCriteria(s,r,o),!0):!1}},I={id:ne,type:d.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(exports.SheetsFilterService).removeFilterModel(e,t)}},x={id:ie,type:d.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n,s=i.get(exports.SheetsFilterService).getFilterModel(e,t);return s?(s.reCalc(),!0):!1}},fe={id:"sheet.command.set-filter-range",type:d.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(d.ICommandService),r=i.get(d.IUndoRedoService),s=i.get(d.IUniverInstanceService),{unitId:o,subUnitId:l,range:a}=n;if(!S.getSheetCommandTarget(s,n)||e.getFilterModel(o,l))return!1;if(a.endRow===a.startRow){const C=i.get(d.ErrorService),_=i.get(d.LocaleService);return C.emit(_.t("sheets-filter.command.not-valid-filter-range")),!1}const u={id:F.id,params:{unitId:o,subUnitId:l,range:a}},m=t.syncExecuteCommand(u.id,u.params);return m&&r.pushUndoRedo({unitID:o,undoMutations:[{id:I.id,params:{unitId:o,subUnitId:l}}],redoMutations:[u]}),m}},ge={id:"sheet.command.remove-sheet-filter",type:d.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(d.IUniverInstanceService),t=i.get(exports.SheetsFilterService),r=i.get(d.ICommandService),s=i.get(d.IUndoRedoService),o=S.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,c=t.getFilterModel(l,a);if(!c)return!1;const h=c==null?void 0:c.serialize(),u=ze(l,a,h),m=r.syncExecuteCommand(I.id,{unitId:l,subUnitId:a});return m&&s.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:[{id:I.id,params:{unitId:l,subUnitId:a}}]}),m}},De={id:"sheet.command.smart-toggle-filter",type:d.CommandType.COMMAND,handler:async i=>{const n=i.get(d.IUniverInstanceService),e=i.get(exports.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(ge.id,{unitId:o,subUnitId:l});const h=i.get(S.SheetsSelectionsService).getCurrentLastSelection();if(!h)return!1;const u=h.range,m=S.isSingleCellSelection(h)?S.expandToContinuousRange(u,{left:!0,right:!0,up:!0,down:!0},s):u;return t.executeCommand(fe.id,{unitId:o,subUnitId:l,range:m})}},Be={id:"sheet.command.set-filter-criteria",type:d.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.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 h=c.getRange();if(!h||l<h.startColumn||l>h.endColumn)return!1;const u=c.getFilterColumn(l),m=We(s,o,l,u),C={id:v.id,params:{unitId:s,subUnitId:o,col:l,criteria:a}},_=t.syncExecuteCommand(C.id,C.params);return _&&r.pushUndoRedo({unitID:s,undoMutations:[m],redoMutations:[C]}),_}},je={id:"sheet.command.clear-filter-criteria",type:d.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(d.IUndoRedoService),r=i.get(d.ICommandService),s=i.get(d.IUniverInstanceService),o=S.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 h=c.serialize(),u=Ce(l,a,h),m=Ve(l,a,h);return d.sequenceExecute(m,r).result?(t.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:m}),!0):!1}},He={id:"sheet.command.re-calc-filter",type:d.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(d.ICommandService),r=i.get(d.IUniverInstanceService),s=S.getSheetCommandTarget(r,n);if(!s)return!1;const{unitId:o,subUnitId:l}=s;return e.getFilterModel(s.unitId,s.subUnitId)?t.executeCommand(x.id,{unitId:o,subUnitId:l}):!1}};function ze(i,n,e){const t=[],r={id:F.id,params:{unitId:i,subUnitId:n,range:e.ref}};return t.push(r),Ce(i,n,e).forEach(o=>t.push(o)),t}function Ce(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:v.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:s}};t.push(o)}),t}function Ve(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:v.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:null}};t.push(o)}),t}function We(i,n,e,t){if(!t)return{id:v.id,params:{unitId:i,subUnitId:n,col:e,criteria:null}};const r=t.serialize();return{id:v.id,params:{unitId:i,subUnitId:n,col:e,criteria:r}}}const _e="sheets-filter.config",X={};function qe(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 N(i){return qe(i,(n,e)=>n.id===v.id&&e.id===v.id&&n.params.unitId===e.params.unitId&&n.params.subUnitId===e.params.subUnitId&&n.params.col===e.params.col)}var ke=Object.getOwnPropertyDescriptor,Ge=(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},b=(i,n)=>(e,t)=>n(e,t,i);let L=class extends d.Disposable{constructor(n,e,t,r,s,o,l){super();R(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(){[v,F,x,I].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===S.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 S.InsertRowCommand.id:{const c=a.params,h=c.unitId||n,u=c.subUnitId||e;return this._handleInsertRowCommand(c,h,u)}case S.InsertColCommand.id:{const c=a.params,h=c.unitId||n,u=c.subUnitId||e;return this.handleInsertColCommand(c.range,h,u)}case S.RemoveColCommand.id:{const c=a.params;return this.handleRemoveColCommand(c.range,n,e)}case S.RemoveRowCommand.id:{const c=a.params;return this._handleRemoveRowCommand(c,n,e)}case S.EffectRefRangId.MoveColsCommandId:{const c=a.params;return this.handleMoveColsCommand({fromRange:c.fromRange,toRange:c.toRange},n,e)}case S.EffectRefRangId.MoveRowsCommandId:{const c=a.params;return this._handleMoveRowsCommand(c,n,e)}case S.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 S.RemoveSheetCommand.id:{const t=n.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case S.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 f;const r=this._sheetsFilterService.getFilterModel(e,t),s=(f=r==null?void 0:r.getRange())!=null?f:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:a,endColumn:c}=n,h=c-a+1;if(c>l)return this._handleNull();const u=[],m=[],C=a,_={unitId:e,subUnitId:t,range:{...s,startColumn:a<=o?o+h:o,endColumn:l+h}},p={unitId:e,subUnitId:t,range:s};u.push({id:F.id,params:_}),m.push({id:F.id,params:p});const w=r.getAllFilterColumns().filter(g=>g[0]>=C);if(w.length!==0){const{newRange:g,oldRange:y}=this._moveCriteria(e,t,w,h);u.push(...y.redos,...g.redos),m.push(...g.undos,...y.undos)}return{redos:N(u),undos:N(m)}}_handleInsertRowCommand(n,e,t){var p;const r=this._sheetsFilterService.getFilterModel(e,t),s=(p=r==null?void 0:r.getRange())!=null?p:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{startRow:a,endRow:c}=n.range,h=c-a+1;if(c>l)return this._handleNull();const u=[],m=[],C={unitId:e,subUnitId:t,range:{...s,startRow:a<=o?o+h:o,endRow:l+h}},_={unitId:e,subUnitId:t,range:s};return u.push({id:F.id,params:C}),m.push({id:F.id,params:_}),{redos:N(u),undos:N(m)}}handleRemoveColCommand(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{startColumn:o,endColumn:l}=s,{startColumn:a,endColumn:c}=n;if(a>l)return this._handleNull();const h=[],u=[],m=c<o?0:Math.min(c,l)-Math.max(a,o)+1,C=c-a+1,_=r.getAllFilterColumns();_.forEach(f=>{const[g,y]=f;g<=c&&g>=a&&(h.push({id:v.id,params:{unitId:e,subUnitId:t,col:g,criteria:null}}),u.push({id:v.id,params:{unitId:e,subUnitId:t,col:g,criteria:{...y.serialize(),colId:g}}}))});const p=_.filter(f=>{const[g,y]=f;return g>c});let M={undos:[],redos:[]};if(p.length>0){const{oldRange:f,newRange:g}=this._moveCriteria(e,t,p,-C);M=g,h.push(...f.redos),u.unshift(...f.undos)}if(m===l-o+1){const f={unitId:e,subUnitId:t};h.push({id:I.id,params:f}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}})}else{const f=o<=a?o:m===0?o-C:a,g=o<=a?l-m:l-C,y={unitId:e,subUnitId:t,range:{...s,startColumn:f,endColumn:g}};h.push({id:F.id,params:y}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),h.push(...M.redos),u.unshift(...M.undos)}return{undos:u,redos:h}}_handleRemoveRowCommand(n,e,t){var p;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 h=[],u=[],m=r.getAllFilterColumns(),C=o<=c&&o>=a;u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}});const _=Math.min(c,l)-Math.max(a,o)+1;if(_===l-o+1||C){const M={unitId:e,subUnitId:t};h.push({id:I.id,params:M}),m.forEach(w=>{const[f,g]=w,y={unitId:e,subUnitId:t,col:f,criteria:{...g.serialize(),colId:f}};u.push({id:v.id,params:y})})}else{const M=(p=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:p.getSheetBySheetId(t);if(!M)return this._handleNull();const w=[];for(let E=a;E<=c;E++)M.getRowFiltered(E)&&w.push(E);const f=Math.min(o,a),g=f+(l-o)-_+w.length,y={unitId:e,subUnitId:t,range:{...s,startRow:f,endRow:g}};h.push({id:F.id,params:y})}return{undos:N(u),redos:N(h)}}handleMoveColsCommand({fromRange:n,toRange:e},t,r){var w;const s=this._sheetsFilterService.getFilterModel(t,r),o=(w=s==null?void 0:s.getRange())!=null?w: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=[],h=[],u={};for(let f=l;f<=a;f++)u[f]={colIndex:f,filter:s.getFilterColumn(f)};d.moveMatrixArray(n.startColumn,n.endColumn-n.startColumn+1,e.startColumn,u);let m=o.startColumn,C=o.endColumn;l>=n.startColumn&&l<=n.endColumn&&e.startColumn>n.startColumn&&n.endColumn<a&&(m=n.endColumn+1),a>=n.startColumn&&a<=n.endColumn&&e.startColumn<n.startColumn&&n.startColumn>l&&(C=n.startColumn-1);const _=Object.keys(u).map(f=>Number(f)),p=_.find(f=>u[f].colIndex===C),M=_.find(f=>u[f].colIndex===m);if(_.forEach(f=>{var Q,J;const{colIndex:g,filter:y}=u[f],E=f;if(y){if(E>=M&&E<=p){const j={unitId:t,subUnitId:r,col:E,criteria:{...y.serialize(),colId:E}},Se={unitId:t,subUnitId:r,col:E,criteria:s.getFilterColumn(E)?{...(Q=s.getFilterColumn(E))==null?void 0:Q.serialize(),colId:E}:null};c.push({id:v.id,params:j}),h.push({id:v.id,params:Se})}if(!((J=u[g])!=null&&J.filter)){const j={unitId:t,subUnitId:r,col:g,criteria:null};c.push({id:v.id,params:j}),h.push({id:v.id,params:{unitId:t,subUnitId:r,col:g,criteria:{...y.serialize(),colId:g}}})}}}),l!==M||a!==p){const f={unitId:t,subUnitId:r,range:{...o,startColumn:M,endColumn:p}};c.unshift({id:F.id,params:f}),h.unshift({id:F.id,params:{range:o,unitId:t,subUnitId:r}})}return{undos:h,redos:c}}_handleMoveRowsCommand(n,e,t){var f;const r=this._sheetsFilterService.getFilterModel(e,t),s=(f=r==null?void 0:r.getRange())!=null?f: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 h=[],u=[],m={};for(let g=o;g<=l;g++)m[g]={oldIndex:g};const C=o;let _=l;l>=a.startRow&&l<=a.endRow&&c.startRow<a.startRow&&a.startRow>o&&(_=a.startRow-1),d.moveMatrixArray(a.startRow,a.endRow-a.startRow+1,c.startRow,m);const p=Object.keys(m).map(g=>Number(g)),M=p.find(g=>m[g].oldIndex===_),w=p.find(g=>m[g].oldIndex===C);if(o!==w||l!==M){const g={unitId:e,subUnitId:t,range:{...s,startRow:w,endRow:M}};h.push({id:F.id,params:g},{id:x.id,params:{unitId:e,subUnitId:t}}),u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}},{id:x.id,params:{unitId:e,subUnitId:t}})}return{redos:h,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 h=l.startRow-r.startRow,u=l.startColumn-r.startColumn,m={startRow:s.startRow+h,startColumn:s.startColumn+u,endRow:s.startRow+h+(l.endRow-l.startRow),endColumn:s.startColumn+u+(l.endColumn-l.startColumn)},C={id:I.id,params:{unitId:e,subUnitId:t}},_={id:F.id,params:{unitId:e,subUnitId:t,range:m}},p={id:F.id,params:{unitId:e,subUnitId:t,range:l}};a.push(C,_),c.push(C,p);const M=o.getAllFilterColumns(),w=s.startColumn-r.startColumn;M.forEach(f=>{const[g,y]=f;y&&(a.push({id:v.id,params:{unitId:e,subUnitId:t,col:g+w,criteria:{...y.serialize(),colId:g+w}}}),c.push({id:v.id,params:{unitId:e,subUnitId:t,col:g,criteria:{...y.serialize(),colId:g}}}))})}else if(d.Rectangle.intersects(s,l)){const h={...l,endRow:Math.max(l.endRow,s.endRow)};a.push({id:F.id,params:{unitId:e,subUnitId:t,range:h}}),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,h])=>{l.push({id:v.id,params:{unitId:e,subUnitId:t,col:c,criteria:{...h.serialize(),colId:c}}})}),o.push({id:I.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,m])=>{o.push({id:v.id,params:{unitId:n,subUnitId:t,col:u,criteria:{...m.serialize(),colId:u}}}),a.push({id:v.id,params:{unitId:n,subUnitId:t,col:u,criteria:null}})}),a.push({id:I.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(S.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(h=>{const[u,m]=h;l.push({id:v.id,params:{...s,col:u}}),o.push({id:v.id,params:{...s,col:u,criteria:{...m.serialize(),colId:u}}})}),t.forEach(h=>{const[u,m]=h;c.push({id:v.id,params:{...s,col:u+r,criteria:{...m.serialize(),colId:u+r}}}),a.push({id:v.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,h;const{unitId:t,subUnitId:r}=n.params||{},s=this._sheetsFilterService.getFilterModel(t,r);if(!s)return;const o=Array.from(s.filteredOutRows).sort((u,m)=>u-m),l=[];let a=!1;if(n.id===S.RemoveRowMutation.id){const{startRow:u,endRow:m}=n.params.range,C=o.filter(_=>_>=u&&_<=m);o.forEach(_=>{if(_<u)l.push(_);else if(a=!0,_<=m){const p=Math.max(u,l.length?l[l.length-1]+1:u);l.push(p)}else l.push(_-(m-u+1-C.length))})}if(n.id===S.InsertRowMutation.id){const{startRow:u,endRow:m}=n.params.range;o.forEach(C=>{C>=u?(a=!0,l.push(C+(m-u+1))):l.push(C)})}if(a&&(s.filteredOutRows=new Set(l)),n.id===S.SetRangeValuesMutation.id&&!(e!=null&&e.onlyLocal)){const u=this._getExtendRegion(t,r);if(u){const m=n.params.cellValue;if(m)for(let C=u.startColumn;C<=u.endColumn;C++){const _=(c=m==null?void 0:m[u.startRow])==null?void 0:c[C];if(_&&this._cellHasValue(_)){const p=(h=this._univerInstanceService.getUnit(t))==null?void 0:h.getSheetBySheetId(r);if(p){const M=S.expandToContinuousRange(u,{down:!0},p),w=this._sheetsFilterService.getFilterModel(t,r),f=w.getRange();w.setRange({...f,endRow:M.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=S.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===S.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))}};L=Ge([b(0,d.ICommandService),b(1,d.Inject(S.SheetInterceptorService)),b(2,d.Inject(exports.SheetsFilterService)),b(3,d.IUniverInstanceService),b(4,d.Inject(S.RefRangeService)),b(5,d.Optional(pe.DataSyncPrimaryController)),b(6,d.Inject(S.ZebraCrossingCacheController))],L);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},V=(i,n)=>(e,t)=>n(e,t,i);const Ke=[v.id,x.id],Ze=[S.InsertColMutation.id,S.RemoveColMutation.id,S.MoveColsMutation.id];exports.SheetsFilterSyncController=class extends d.Disposable{constructor(e,t,r){super();R(this,"_d",new d.DisposableCollection);R(this,"_visible$",new O.BehaviorSubject(!1));R(this,"visible$",this._visible$.asObservable());R(this,"_enabled$",new O.BehaviorSubject(!0));R(this,"enabled$",this._enabled$.asObservable());this._sheetsFilterController=e,this._commandService=t,this._configService=r;const s=this._configService.getConfig(_e);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(Ze.includes(e.id)&&(t!=null&&t.fromCollab)){if(e.id===S.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===S.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===S.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)}}}))}};exports.SheetsFilterSyncController=Je([V(0,d.Inject(L)),V(1,d.ICommandService),V(2,d.IConfigService)],exports.SheetsFilterSyncController);var Ye=Object.getOwnPropertyDescriptor,Xe=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ye(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},P=(i,n)=>(e,t)=>n(e,t,i);let B=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(){q.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})}};B=Xe([P(0,d.Inject(K.IActiveDirtyManagerService)),P(1,d.Inject(K.ISheetRowFilteredService)),P(2,d.Inject(exports.SheetsFilterService)),P(3,d.IUniverInstanceService)],B);var et=Object.getOwnPropertyDescriptor,tt=(i,n,e,t)=>{for(var r=t>1?void 0:t?et(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},ee=(i,n)=>(e,t)=>n(e,t,i),D;exports.UniverSheetsFilterPlugin=(D=class extends d.Plugin{constructor(n=X,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=d.merge({},X,this._config);this._configService.setConfig(_e,r)}onStarting(){[[B],[exports.SheetsFilterService],[L],[exports.SheetsFilterSyncController]].forEach(n=>this._injector.add(n))}onReady(){d.touchDependencies(this._injector,[[B],[L],[exports.SheetsFilterSyncController]])}},R(D,"type",d.UniverInstanceType.UNIVER_SHEET),R(D,"pluginName",G),D);exports.UniverSheetsFilterPlugin=tt([ee(1,d.Inject(d.Injector)),ee(2,d.IConfigService)],exports.UniverSheetsFilterPlugin);exports.ClearSheetsFilterCriteriaCommand=je;exports.CustomFilterOperator=T;exports.FILTER_MUTATIONS=q;exports.FilterBy=A;exports.FilterColumn=me;exports.FilterModel=$;exports.ReCalcSheetsFilterCommand=He;exports.ReCalcSheetsFilterMutation=x;exports.RemoveSheetFilterCommand=ge;exports.RemoveSheetsFilterMutation=I;exports.SHEET_FILTER_SNAPSHOT_ID=G;exports.SetSheetFilterRangeCommand=fe;exports.SetSheetsFilterCriteriaCommand=Be;exports.SetSheetsFilterCriteriaMutation=v;exports.SetSheetsFilterRangeMutation=F;exports.SmartToggleSheetsFilterCommand=De;exports.equals=ce;exports.getCustomFilterFn=W;exports.greaterThan=se;exports.greaterThanOrEqualTo=oe;exports.lessThan=le;exports.lessThanOrEqualTo=ae;exports.notEquals=k;
package/lib/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var be = Object.defineProperty;
2
2
  var $e = (i, t, e) => t in i ? be(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
3
  var C = (i, t, e) => $e(i, typeof t != "symbol" ? t + "" : t, e);
4
- import { isNumeric as Le, Disposable as U, Rectangle as ee, mergeSets as Z, Tools as ie, extractPureTextFromCell as Ue, CellValueType as te, ColorKit as se, UniverInstanceType as D, fromCallback as Pe, CommandType as O, IResourceManagerService as De, IUniverInstanceService as N, ICommandService as T, IUndoRedoService as Q, sequenceExecute as j, ErrorService as Be, LocaleService as ze, Inject as A, Optional as He, DisposableCollection as me, moveMatrixArray as oe, IConfigService as ge, Plugin as Ve, merge as We, touchDependencies as je, Injector as ke } from "@univerjs/core";
4
+ import { isNumeric as Le, Disposable as U, Rectangle as te, mergeSets as K, Tools as ie, extractPureTextFromCell as Ue, CellValueType as k, ColorKit as se, UniverInstanceType as D, fromCallback as Pe, CommandType as O, IResourceManagerService as De, IUniverInstanceService as T, ICommandService as N, IUndoRedoService as J, sequenceExecute as j, ErrorService as Be, LocaleService as ze, Inject as A, Optional as He, DisposableCollection as me, moveMatrixArray as oe, IConfigService as ge, Plugin as Ve, merge as We, touchDependencies as je, Injector as ke } from "@univerjs/core";
5
5
  import { getSheetCommandTarget as H, SheetsSelectionsService as qe, isSingleCellSelection as Ge, expandToContinuousRange as _e, SheetInterceptorService as Qe, RefRangeService as Je, ZebraCrossingCacheController as Ze, SetWorksheetActiveOperation as Ke, CopySheetCommand as Ye, RemoveSheetCommand as Xe, INTERCEPTOR_POINT as et, RemoveRowMutation as tt, InsertRowMutation as rt, SetRangeValuesMutation as nt, MoveRowsCommand as it, MoveRangeCommand as st, EffectRefRangId as le, RemoveRowCommand as ot, RemoveColCommand as lt, InsertColCommand as at, InsertRowCommand as ct, InsertColMutation as Ce, RemoveColMutation as Re, MoveColsMutation as pe } from "@univerjs/sheets";
6
6
  import { BehaviorSubject as $, merge as dt, filter as ut, switchMap as ht, of as ft } from "rxjs";
7
7
  import { COLOR_BLACK_RGB as mt } from "@univerjs/engine-render";
@@ -72,18 +72,18 @@ function Ae(i) {
72
72
  const t = i.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("?", ".").replace(/[*]/g, ".$&");
73
73
  return new RegExp(`^${t}$`);
74
74
  }
75
- const K = () => /* @__PURE__ */ new Set();
76
- class k extends U {
75
+ const Y = () => /* @__PURE__ */ new Set();
76
+ class q extends U {
77
77
  constructor(e, r, n) {
78
78
  super();
79
- C(this, "_filteredOutRows$", new $(K()));
79
+ C(this, "_filteredOutRows$", new $(Y()));
80
80
  /** An observable value. A set of filtered out rows. */
81
81
  C(this, "filteredOutRows$", this._filteredOutRows$.asObservable());
82
82
  // TODO: we may need to update which cols have criteria rather than simple boolean
83
83
  C(this, "_hasCriteria$", new $(!1));
84
84
  C(this, "hasCriteria$", this._hasCriteria$.asObservable());
85
85
  C(this, "_filterColumnByIndex", /* @__PURE__ */ new Map());
86
- C(this, "_alreadyFilteredOutRows", K());
86
+ C(this, "_alreadyFilteredOutRows", Y());
87
87
  C(this, "_range");
88
88
  this.unitId = e, this.subUnitId = r, this._worksheet = n;
89
89
  }
@@ -101,7 +101,7 @@ class k extends U {
101
101
  */
102
102
  serialize() {
103
103
  const e = {
104
- ref: ee.clone(this._range),
104
+ ref: te.clone(this._range),
105
105
  filterColumns: this._getAllFilterColumns(!0).sort(([r], [n]) => r - n).map(([r, n]) => n.serialize())
106
106
  };
107
107
  return this._alreadyFilteredOutRows && (e.cachedFilteredOut = Array.from(this._alreadyFilteredOutRows).sort()), e;
@@ -114,7 +114,7 @@ class k extends U {
114
114
  * @param autoFilter auto filter data
115
115
  */
116
116
  static deserialize(e, r, n, s) {
117
- const o = new k(e, r, n);
117
+ const o = new q(e, r, n);
118
118
  return o._dump(s), o;
119
119
  }
120
120
  _dump(e) {
@@ -137,7 +137,7 @@ class k extends U {
137
137
  getFilteredOutRowsExceptCol(e) {
138
138
  return this._getAllFilterColumns(!0).filter(([r]) => r !== e).reduce((r, [, n]) => {
139
139
  const s = n.calc({ getAlreadyFilteredOutRows: () => r });
140
- return s ? Z(r, s) : r;
140
+ return s ? K(r, s) : r;
141
141
  }, /* @__PURE__ */ new Set());
142
142
  }
143
143
  /**
@@ -181,7 +181,7 @@ class k extends U {
181
181
  return e ? r : r.map(([n, s]) => s);
182
182
  }
183
183
  _reCalcAllColumns() {
184
- this._alreadyFilteredOutRows = K(), this._getAllFilterColumns().forEach((e) => e.__clearCache()), this._reCalcWithNoCacheColumns();
184
+ this._alreadyFilteredOutRows = Y(), this._getAllFilterColumns().forEach((e) => e.__clearCache()), this._reCalcWithNoCacheColumns();
185
185
  }
186
186
  _setCriteriaWithoutReCalc(e, r) {
187
187
  const n = this._range;
@@ -210,14 +210,14 @@ class k extends U {
210
210
  this._hasCriteria$.next(this._filterColumnByIndex.size > 0);
211
211
  }
212
212
  _rebuildAlreadyFilteredOutRowsWithCache() {
213
- const e = this._getAllFilterColumns().filter((r) => r.hasCache()).reduce((r, n) => Z(r, n.filteredOutRows), /* @__PURE__ */ new Set());
213
+ const e = this._getAllFilterColumns().filter((r) => r.hasCache()).reduce((r, n) => K(r, n.filteredOutRows), /* @__PURE__ */ new Set());
214
214
  this._alreadyFilteredOutRows = e;
215
215
  }
216
216
  _reCalcWithNoCacheColumns() {
217
217
  const e = this._getAllFilterColumns().filter((r) => !r.hasCache());
218
218
  for (const r of e) {
219
219
  const n = r.reCalc();
220
- n && (this._alreadyFilteredOutRows = Z(this._alreadyFilteredOutRows, n));
220
+ n && (this._alreadyFilteredOutRows = K(this._alreadyFilteredOutRows, n));
221
221
  }
222
222
  }
223
223
  }
@@ -301,18 +301,18 @@ class yt extends U {
301
301
  }
302
302
  function At(i) {
303
303
  if (i.filters)
304
- return Tt(i.filters);
304
+ return Nt(i.filters);
305
305
  if (i.colorFilters)
306
- return Nt(i.colorFilters);
306
+ return Tt(i.colorFilters);
307
307
  if (i.customFilters)
308
308
  return xt(i.customFilters);
309
309
  throw new Error("[FilterModel]: other types of filters are not supported yet.");
310
310
  }
311
- function Tt(i) {
311
+ function Nt(i) {
312
312
  const t = !!i.blank, e = new Set(i.filters);
313
313
  return (r) => r === void 0 || r === "" ? t : e.has(typeof r == "string" ? r : `${r}`);
314
314
  }
315
- function Nt(i) {
315
+ function Tt(i) {
316
316
  if (i.cellFillColors) {
317
317
  const t = new Set(i.cellFillColors);
318
318
  return (e) => {
@@ -366,21 +366,21 @@ function Ut(i, t, e) {
366
366
  const r = i.getCell(t, e);
367
367
  if (!r) return null;
368
368
  const n = i.getCellRaw(t, e);
369
- return r && !n ? de(r) : n ? r.t === te.NUMBER && typeof r.v == "string" ? n.v : de(n) : null;
369
+ return r && !n ? de(r) : n ? r.t === k.NUMBER && typeof r.v == "string" ? n.v : r.t === k.NUMBER ? Number(n.v) : de(n) : null;
370
370
  }
371
371
  function de(i) {
372
372
  var r, n;
373
373
  const t = (n = (r = i.p) == null ? void 0 : r.body) == null ? void 0 : n.dataStream;
374
374
  if (t) return t.trimEnd();
375
375
  const e = i.v;
376
- return typeof e == "string" ? i.t === te.BOOLEAN ? e.toUpperCase() : e : typeof e == "number" ? i.t === te.BOOLEAN ? e ? "TRUE" : "FALSE" : e : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : "";
376
+ return typeof e == "string" ? i.t === k.BOOLEAN ? e.toUpperCase() : e : typeof e == "number" ? i.t === k.BOOLEAN ? e ? "TRUE" : "FALSE" : e : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : "";
377
377
  }
378
378
  var Pt = Object.getOwnPropertyDescriptor, Dt = (i, t, e, r) => {
379
379
  for (var n = r > 1 ? void 0 : r ? Pt(t, e) : t, s = i.length - 1, o; s >= 0; s--)
380
380
  (o = i[s]) && (n = o(n) || n);
381
381
  return n;
382
- }, Y = (i, t) => (e, r) => t(e, r, i);
383
- const Te = "SHEET_FILTER_PLUGIN";
382
+ }, X = (i, t) => (e, r) => t(e, r, i);
383
+ const Ne = "SHEET_FILTER_PLUGIN";
384
384
  let M = class extends U {
385
385
  constructor(t, e, r) {
386
386
  super();
@@ -413,7 +413,7 @@ let M = class extends U {
413
413
  const s = n.getSheetBySheetId(e);
414
414
  if (!s)
415
415
  throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${e}!`);
416
- const o = new k(t, e, s);
416
+ const o = new q(t, e, s);
417
417
  return this._cacheFilterModel(t, e, o), o;
418
418
  }
419
419
  getFilterModel(t, e) {
@@ -471,13 +471,13 @@ let M = class extends U {
471
471
  _deserializeAutoFiltersForUnit(t, e) {
472
472
  const r = this._univerInstanceService.getUniverSheetInstance(t);
473
473
  Object.keys(e).forEach((n) => {
474
- const s = e[n], o = k.deserialize(t, n, r.getSheetBySheetId(n), s);
474
+ const s = e[n], o = q.deserialize(t, n, r.getSheetBySheetId(n), s);
475
475
  this._cacheFilterModel(t, n, o);
476
476
  });
477
477
  }
478
478
  _initModel() {
479
479
  this._resourcesManagerService.registerPluginResource({
480
- pluginName: Te,
480
+ pluginName: Ne,
481
481
  businesses: [D.UNIVER_SHEET],
482
482
  toJson: (t) => this._serializeAutoFiltersForUnit(t),
483
483
  parseJson: (t) => JSON.parse(t),
@@ -495,9 +495,9 @@ let M = class extends U {
495
495
  }
496
496
  };
497
497
  M = Dt([
498
- Y(0, De),
499
- Y(1, N),
500
- Y(2, T)
498
+ X(0, De),
499
+ X(1, T),
500
+ X(2, N)
501
501
  ], M);
502
502
  const R = {
503
503
  id: Se,
@@ -531,7 +531,7 @@ const R = {
531
531
  id: "sheet.command.set-filter-range",
532
532
  type: O.COMMAND,
533
533
  handler: (i, t) => {
534
- const e = i.get(M), r = i.get(T), n = i.get(Q), s = i.get(N), { unitId: o, subUnitId: l, range: a } = t;
534
+ const e = i.get(M), r = i.get(N), n = i.get(J), s = i.get(T), { unitId: o, subUnitId: l, range: a } = t;
535
535
  if (!H(s, t) || e.getFilterModel(o, l)) return !1;
536
536
  if (a.endRow === a.startRow) {
537
537
  const g = i.get(Be), _ = i.get(ze);
@@ -548,7 +548,7 @@ const R = {
548
548
  id: "sheet.command.remove-sheet-filter",
549
549
  type: O.COMMAND,
550
550
  handler: (i, t) => {
551
- const e = i.get(N), r = i.get(M), n = i.get(T), s = i.get(Q), o = H(e, t);
551
+ const e = i.get(T), r = i.get(M), n = i.get(N), s = i.get(J), o = H(e, t);
552
552
  if (!o) return !1;
553
553
  const { unitId: l, subUnitId: a } = o, c = r.getFilterModel(l, a);
554
554
  if (!c) return !1;
@@ -563,7 +563,7 @@ const R = {
563
563
  id: "sheet.command.smart-toggle-filter",
564
564
  type: O.COMMAND,
565
565
  handler: async (i) => {
566
- const t = i.get(N), e = i.get(M), r = i.get(T), n = t.getCurrentUnitForType(D.UNIVER_SHEET), s = n == null ? void 0 : n.getActiveSheet();
566
+ const t = i.get(T), e = i.get(M), r = i.get(N), n = t.getCurrentUnitForType(D.UNIVER_SHEET), s = n == null ? void 0 : n.getActiveSheet();
567
567
  if (!s || !n) return !1;
568
568
  const o = n.getUnitId(), l = s.getSheetId();
569
569
  if (e.getFilterModel(o, l))
@@ -581,7 +581,7 @@ const R = {
581
581
  id: "sheet.command.set-filter-criteria",
582
582
  type: O.COMMAND,
583
583
  handler: (i, t) => {
584
- const e = i.get(M), r = i.get(T), n = i.get(Q), { unitId: s, subUnitId: o, col: l, criteria: a } = t, c = e.getFilterModel(s, o);
584
+ const e = i.get(M), r = i.get(N), n = i.get(J), { unitId: s, subUnitId: o, col: l, criteria: a } = t, c = e.getFilterModel(s, o);
585
585
  if (!c) return !1;
586
586
  const u = c.getRange();
587
587
  if (!u || l < u.startColumn || l > u.endColumn) return !1;
@@ -604,11 +604,11 @@ const R = {
604
604
  id: "sheet.command.clear-filter-criteria",
605
605
  type: O.COMMAND,
606
606
  handler: (i, t) => {
607
- const e = i.get(M), r = i.get(Q), n = i.get(T), s = i.get(N), o = H(s, t);
607
+ const e = i.get(M), r = i.get(J), n = i.get(N), s = i.get(T), o = H(s, t);
608
608
  if (!o) return !1;
609
609
  const { unitId: l, subUnitId: a } = o, c = e.getFilterModel(o.unitId, o.subUnitId);
610
610
  if (!c) return !1;
611
- const u = c.serialize(), d = Ne(l, a, u), h = Vt(l, a, u);
611
+ const u = c.serialize(), d = Te(l, a, u), h = Vt(l, a, u);
612
612
  return j(h, n).result ? (r.pushUndoRedo({
613
613
  unitID: l,
614
614
  undoMutations: d,
@@ -619,7 +619,7 @@ const R = {
619
619
  id: "sheet.command.re-calc-filter",
620
620
  type: O.COMMAND,
621
621
  handler: (i, t) => {
622
- const e = i.get(M), r = i.get(T), n = i.get(N), s = H(n, t);
622
+ const e = i.get(M), r = i.get(N), n = i.get(T), s = H(n, t);
623
623
  if (!s) return !1;
624
624
  const { unitId: o, subUnitId: l } = s;
625
625
  return e.getFilterModel(s.unitId, s.subUnitId) ? r.executeCommand(B.id, { unitId: o, subUnitId: l }) : !1;
@@ -634,9 +634,9 @@ function Ht(i, t, e) {
634
634
  range: e.ref
635
635
  }
636
636
  };
637
- return r.push(n), Ne(i, t, e).forEach((o) => r.push(o)), r;
637
+ return r.push(n), Te(i, t, e).forEach((o) => r.push(o)), r;
638
638
  }
639
- function Ne(i, t, e) {
639
+ function Te(i, t, e) {
640
640
  var n;
641
641
  const r = [];
642
642
  return (n = e.filterColumns) == null || n.forEach((s) => {
@@ -1003,7 +1003,7 @@ let z = class extends U {
1003
1003
  const { colIndex: m, filter: v } = d[f], E = f;
1004
1004
  if (v) {
1005
1005
  if (E >= w && E <= S) {
1006
- const J = {
1006
+ const Z = {
1007
1007
  unitId: r,
1008
1008
  subUnitId: n,
1009
1009
  col: E,
@@ -1014,16 +1014,16 @@ let z = class extends U {
1014
1014
  col: E,
1015
1015
  criteria: s.getFilterColumn(E) ? { ...(re = s.getFilterColumn(E)) == null ? void 0 : re.serialize(), colId: E } : null
1016
1016
  };
1017
- c.push({ id: p.id, params: J }), u.push({ id: p.id, params: Ie });
1017
+ c.push({ id: p.id, params: Z }), u.push({ id: p.id, params: Ie });
1018
1018
  }
1019
1019
  if (!((ne = d[m]) != null && ne.filter)) {
1020
- const J = {
1020
+ const Z = {
1021
1021
  unitId: r,
1022
1022
  subUnitId: n,
1023
1023
  col: m,
1024
1024
  criteria: null
1025
1025
  };
1026
- c.push({ id: p.id, params: J }), u.push({ id: p.id, params: { unitId: r, subUnitId: n, col: m, criteria: { ...v.serialize(), colId: m } } });
1026
+ c.push({ id: p.id, params: Z }), u.push({ id: p.id, params: { unitId: r, subUnitId: n, col: m, criteria: { ...v.serialize(), colId: m } } });
1027
1027
  }
1028
1028
  }
1029
1029
  }), l !== w || a !== S) {
@@ -1085,7 +1085,7 @@ let z = class extends U {
1085
1085
  if (!l)
1086
1086
  return this._handleNull();
1087
1087
  const a = [], c = [];
1088
- if (ee.contains(n, l)) {
1088
+ if (te.contains(n, l)) {
1089
1089
  const u = l.startRow - n.startRow, d = l.startColumn - n.startColumn, h = {
1090
1090
  startRow: s.startRow + u,
1091
1091
  startColumn: s.startColumn + d,
@@ -1104,7 +1104,7 @@ let z = class extends U {
1104
1104
  const [m, v] = f;
1105
1105
  v && (a.push({ id: p.id, params: { unitId: e, subUnitId: r, col: m + F, criteria: { ...v.serialize(), colId: m + F } } }), c.push({ id: p.id, params: { unitId: e, subUnitId: r, col: m, criteria: { ...v.serialize(), colId: m } } }));
1106
1106
  });
1107
- } else if (ee.intersects(s, l)) {
1107
+ } else if (te.intersects(s, l)) {
1108
1108
  const u = {
1109
1109
  ...l,
1110
1110
  endRow: Math.max(l.endRow, s.endRow)
@@ -1300,10 +1300,10 @@ let z = class extends U {
1300
1300
  }
1301
1301
  };
1302
1302
  z = qt([
1303
- I(0, T),
1303
+ I(0, N),
1304
1304
  I(1, A(Qe)),
1305
1305
  I(2, A(M)),
1306
- I(3, N),
1306
+ I(3, T),
1307
1307
  I(4, A(Je)),
1308
1308
  I(5, He(gt)),
1309
1309
  I(6, A(Ze))
@@ -1312,7 +1312,7 @@ var Gt = Object.getOwnPropertyDescriptor, Qt = (i, t, e, r) => {
1312
1312
  for (var n = r > 1 ? void 0 : r ? Gt(t, e) : t, s = i.length - 1, o; s >= 0; s--)
1313
1313
  (o = i[s]) && (n = o(n) || n);
1314
1314
  return n;
1315
- }, X = (i, t) => (e, r) => t(e, r, i);
1315
+ }, ee = (i, t) => (e, r) => t(e, r, i);
1316
1316
  const Jt = [
1317
1317
  p.id,
1318
1318
  B.id
@@ -1321,7 +1321,7 @@ const Jt = [
1321
1321
  Re.id,
1322
1322
  pe.id
1323
1323
  ];
1324
- let q = class extends U {
1324
+ let G = class extends U {
1325
1325
  constructor(t, e, r) {
1326
1326
  super();
1327
1327
  C(this, "_d", new me());
@@ -1365,17 +1365,17 @@ let q = class extends U {
1365
1365
  );
1366
1366
  }
1367
1367
  };
1368
- q = Qt([
1369
- X(0, A(z)),
1370
- X(1, T),
1371
- X(2, ge)
1372
- ], q);
1368
+ G = Qt([
1369
+ ee(0, A(z)),
1370
+ ee(1, N),
1371
+ ee(2, ge)
1372
+ ], G);
1373
1373
  var Kt = Object.getOwnPropertyDescriptor, Yt = (i, t, e, r) => {
1374
1374
  for (var n = r > 1 ? void 0 : r ? Kt(t, e) : t, s = i.length - 1, o; s >= 0; s--)
1375
1375
  (o = i[s]) && (n = o(n) || n);
1376
1376
  return n;
1377
1377
  }, V = (i, t) => (e, r) => t(e, r, i);
1378
- let G = class extends U {
1378
+ let Q = class extends U {
1379
1379
  constructor(i, t, e, r) {
1380
1380
  super(), this._activeDirtyManagerService = i, this._sheetRowFilteredService = t, this._sheetsFilterService = e, this._univerInstanceService = r, this._initFormulaDirtyRange(), this._registerSheetRowFiltered();
1381
1381
  }
@@ -1424,12 +1424,12 @@ let G = class extends U {
1424
1424
  });
1425
1425
  }
1426
1426
  };
1427
- G = Yt([
1427
+ Q = Yt([
1428
1428
  V(0, A(_t)),
1429
1429
  V(1, A(Ct)),
1430
1430
  V(2, A(M)),
1431
- V(3, N)
1432
- ], G);
1431
+ V(3, T)
1432
+ ], Q);
1433
1433
  var Xt = Object.getOwnPropertyDescriptor, er = (i, t, e, r) => {
1434
1434
  for (var n = r > 1 ? void 0 : r ? Xt(t, e) : t, s = i.length - 1, o; s >= 0; s--)
1435
1435
  (o = i[s]) && (n = o(n) || n);
@@ -1447,20 +1447,20 @@ let fe = (W = class extends Ve {
1447
1447
  }
1448
1448
  onStarting() {
1449
1449
  [
1450
- [G],
1450
+ [Q],
1451
1451
  [M],
1452
1452
  [z],
1453
- [q]
1453
+ [G]
1454
1454
  ].forEach((i) => this._injector.add(i));
1455
1455
  }
1456
1456
  onReady() {
1457
1457
  je(this._injector, [
1458
- [G],
1458
+ [Q],
1459
1459
  [z],
1460
- [q]
1460
+ [G]
1461
1461
  ]);
1462
1462
  }
1463
- }, C(W, "type", D.UNIVER_SHEET), C(W, "pluginName", Te), W);
1463
+ }, C(W, "type", D.UNIVER_SHEET), C(W, "pluginName", Ne), W);
1464
1464
  fe = er([
1465
1465
  he(1, A(ke)),
1466
1466
  he(2, ge)
@@ -1471,18 +1471,18 @@ export {
1471
1471
  Me as FILTER_MUTATIONS,
1472
1472
  b as FilterBy,
1473
1473
  yt as FilterColumn,
1474
- k as FilterModel,
1474
+ q as FilterModel,
1475
1475
  ur as ReCalcSheetsFilterCommand,
1476
1476
  B as ReCalcSheetsFilterMutation,
1477
1477
  zt as RemoveSheetFilterCommand,
1478
1478
  y as RemoveSheetsFilterMutation,
1479
- Te as SHEET_FILTER_SNAPSHOT_ID,
1479
+ Ne as SHEET_FILTER_SNAPSHOT_ID,
1480
1480
  Bt as SetSheetFilterRangeCommand,
1481
1481
  cr as SetSheetsFilterCriteriaCommand,
1482
1482
  p as SetSheetsFilterCriteriaMutation,
1483
1483
  R as SetSheetsFilterRangeMutation,
1484
1484
  M as SheetsFilterService,
1485
- q as SheetsFilterSyncController,
1485
+ G as SheetsFilterSyncController,
1486
1486
  ar as SmartToggleSheetsFilterCommand,
1487
1487
  fe as UniverSheetsFilterPlugin,
1488
1488
  wt as equals,
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var be = Object.defineProperty;
2
2
  var $e = (i, t, e) => t in i ? be(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
3
  var C = (i, t, e) => $e(i, typeof t != "symbol" ? t + "" : t, e);
4
- import { isNumeric as Le, Disposable as U, Rectangle as ee, mergeSets as Z, Tools as ie, extractPureTextFromCell as Ue, CellValueType as te, ColorKit as se, UniverInstanceType as D, fromCallback as Pe, CommandType as O, IResourceManagerService as De, IUniverInstanceService as N, ICommandService as T, IUndoRedoService as Q, sequenceExecute as j, ErrorService as Be, LocaleService as ze, Inject as A, Optional as He, DisposableCollection as me, moveMatrixArray as oe, IConfigService as ge, Plugin as Ve, merge as We, touchDependencies as je, Injector as ke } from "@univerjs/core";
4
+ import { isNumeric as Le, Disposable as U, Rectangle as te, mergeSets as K, Tools as ie, extractPureTextFromCell as Ue, CellValueType as k, ColorKit as se, UniverInstanceType as D, fromCallback as Pe, CommandType as O, IResourceManagerService as De, IUniverInstanceService as T, ICommandService as N, IUndoRedoService as J, sequenceExecute as j, ErrorService as Be, LocaleService as ze, Inject as A, Optional as He, DisposableCollection as me, moveMatrixArray as oe, IConfigService as ge, Plugin as Ve, merge as We, touchDependencies as je, Injector as ke } from "@univerjs/core";
5
5
  import { getSheetCommandTarget as H, SheetsSelectionsService as qe, isSingleCellSelection as Ge, expandToContinuousRange as _e, SheetInterceptorService as Qe, RefRangeService as Je, ZebraCrossingCacheController as Ze, SetWorksheetActiveOperation as Ke, CopySheetCommand as Ye, RemoveSheetCommand as Xe, INTERCEPTOR_POINT as et, RemoveRowMutation as tt, InsertRowMutation as rt, SetRangeValuesMutation as nt, MoveRowsCommand as it, MoveRangeCommand as st, EffectRefRangId as le, RemoveRowCommand as ot, RemoveColCommand as lt, InsertColCommand as at, InsertRowCommand as ct, InsertColMutation as Ce, RemoveColMutation as Re, MoveColsMutation as pe } from "@univerjs/sheets";
6
6
  import { BehaviorSubject as $, merge as dt, filter as ut, switchMap as ht, of as ft } from "rxjs";
7
7
  import { COLOR_BLACK_RGB as mt } from "@univerjs/engine-render";
@@ -72,18 +72,18 @@ function Ae(i) {
72
72
  const t = i.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("?", ".").replace(/[*]/g, ".$&");
73
73
  return new RegExp(`^${t}$`);
74
74
  }
75
- const K = () => /* @__PURE__ */ new Set();
76
- class k extends U {
75
+ const Y = () => /* @__PURE__ */ new Set();
76
+ class q extends U {
77
77
  constructor(e, r, n) {
78
78
  super();
79
- C(this, "_filteredOutRows$", new $(K()));
79
+ C(this, "_filteredOutRows$", new $(Y()));
80
80
  /** An observable value. A set of filtered out rows. */
81
81
  C(this, "filteredOutRows$", this._filteredOutRows$.asObservable());
82
82
  // TODO: we may need to update which cols have criteria rather than simple boolean
83
83
  C(this, "_hasCriteria$", new $(!1));
84
84
  C(this, "hasCriteria$", this._hasCriteria$.asObservable());
85
85
  C(this, "_filterColumnByIndex", /* @__PURE__ */ new Map());
86
- C(this, "_alreadyFilteredOutRows", K());
86
+ C(this, "_alreadyFilteredOutRows", Y());
87
87
  C(this, "_range");
88
88
  this.unitId = e, this.subUnitId = r, this._worksheet = n;
89
89
  }
@@ -101,7 +101,7 @@ class k extends U {
101
101
  */
102
102
  serialize() {
103
103
  const e = {
104
- ref: ee.clone(this._range),
104
+ ref: te.clone(this._range),
105
105
  filterColumns: this._getAllFilterColumns(!0).sort(([r], [n]) => r - n).map(([r, n]) => n.serialize())
106
106
  };
107
107
  return this._alreadyFilteredOutRows && (e.cachedFilteredOut = Array.from(this._alreadyFilteredOutRows).sort()), e;
@@ -114,7 +114,7 @@ class k extends U {
114
114
  * @param autoFilter auto filter data
115
115
  */
116
116
  static deserialize(e, r, n, s) {
117
- const o = new k(e, r, n);
117
+ const o = new q(e, r, n);
118
118
  return o._dump(s), o;
119
119
  }
120
120
  _dump(e) {
@@ -137,7 +137,7 @@ class k extends U {
137
137
  getFilteredOutRowsExceptCol(e) {
138
138
  return this._getAllFilterColumns(!0).filter(([r]) => r !== e).reduce((r, [, n]) => {
139
139
  const s = n.calc({ getAlreadyFilteredOutRows: () => r });
140
- return s ? Z(r, s) : r;
140
+ return s ? K(r, s) : r;
141
141
  }, /* @__PURE__ */ new Set());
142
142
  }
143
143
  /**
@@ -181,7 +181,7 @@ class k extends U {
181
181
  return e ? r : r.map(([n, s]) => s);
182
182
  }
183
183
  _reCalcAllColumns() {
184
- this._alreadyFilteredOutRows = K(), this._getAllFilterColumns().forEach((e) => e.__clearCache()), this._reCalcWithNoCacheColumns();
184
+ this._alreadyFilteredOutRows = Y(), this._getAllFilterColumns().forEach((e) => e.__clearCache()), this._reCalcWithNoCacheColumns();
185
185
  }
186
186
  _setCriteriaWithoutReCalc(e, r) {
187
187
  const n = this._range;
@@ -210,14 +210,14 @@ class k extends U {
210
210
  this._hasCriteria$.next(this._filterColumnByIndex.size > 0);
211
211
  }
212
212
  _rebuildAlreadyFilteredOutRowsWithCache() {
213
- const e = this._getAllFilterColumns().filter((r) => r.hasCache()).reduce((r, n) => Z(r, n.filteredOutRows), /* @__PURE__ */ new Set());
213
+ const e = this._getAllFilterColumns().filter((r) => r.hasCache()).reduce((r, n) => K(r, n.filteredOutRows), /* @__PURE__ */ new Set());
214
214
  this._alreadyFilteredOutRows = e;
215
215
  }
216
216
  _reCalcWithNoCacheColumns() {
217
217
  const e = this._getAllFilterColumns().filter((r) => !r.hasCache());
218
218
  for (const r of e) {
219
219
  const n = r.reCalc();
220
- n && (this._alreadyFilteredOutRows = Z(this._alreadyFilteredOutRows, n));
220
+ n && (this._alreadyFilteredOutRows = K(this._alreadyFilteredOutRows, n));
221
221
  }
222
222
  }
223
223
  }
@@ -301,18 +301,18 @@ class yt extends U {
301
301
  }
302
302
  function At(i) {
303
303
  if (i.filters)
304
- return Tt(i.filters);
304
+ return Nt(i.filters);
305
305
  if (i.colorFilters)
306
- return Nt(i.colorFilters);
306
+ return Tt(i.colorFilters);
307
307
  if (i.customFilters)
308
308
  return xt(i.customFilters);
309
309
  throw new Error("[FilterModel]: other types of filters are not supported yet.");
310
310
  }
311
- function Tt(i) {
311
+ function Nt(i) {
312
312
  const t = !!i.blank, e = new Set(i.filters);
313
313
  return (r) => r === void 0 || r === "" ? t : e.has(typeof r == "string" ? r : `${r}`);
314
314
  }
315
- function Nt(i) {
315
+ function Tt(i) {
316
316
  if (i.cellFillColors) {
317
317
  const t = new Set(i.cellFillColors);
318
318
  return (e) => {
@@ -366,21 +366,21 @@ function Ut(i, t, e) {
366
366
  const r = i.getCell(t, e);
367
367
  if (!r) return null;
368
368
  const n = i.getCellRaw(t, e);
369
- return r && !n ? de(r) : n ? r.t === te.NUMBER && typeof r.v == "string" ? n.v : de(n) : null;
369
+ return r && !n ? de(r) : n ? r.t === k.NUMBER && typeof r.v == "string" ? n.v : r.t === k.NUMBER ? Number(n.v) : de(n) : null;
370
370
  }
371
371
  function de(i) {
372
372
  var r, n;
373
373
  const t = (n = (r = i.p) == null ? void 0 : r.body) == null ? void 0 : n.dataStream;
374
374
  if (t) return t.trimEnd();
375
375
  const e = i.v;
376
- return typeof e == "string" ? i.t === te.BOOLEAN ? e.toUpperCase() : e : typeof e == "number" ? i.t === te.BOOLEAN ? e ? "TRUE" : "FALSE" : e : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : "";
376
+ return typeof e == "string" ? i.t === k.BOOLEAN ? e.toUpperCase() : e : typeof e == "number" ? i.t === k.BOOLEAN ? e ? "TRUE" : "FALSE" : e : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : "";
377
377
  }
378
378
  var Pt = Object.getOwnPropertyDescriptor, Dt = (i, t, e, r) => {
379
379
  for (var n = r > 1 ? void 0 : r ? Pt(t, e) : t, s = i.length - 1, o; s >= 0; s--)
380
380
  (o = i[s]) && (n = o(n) || n);
381
381
  return n;
382
- }, Y = (i, t) => (e, r) => t(e, r, i);
383
- const Te = "SHEET_FILTER_PLUGIN";
382
+ }, X = (i, t) => (e, r) => t(e, r, i);
383
+ const Ne = "SHEET_FILTER_PLUGIN";
384
384
  let M = class extends U {
385
385
  constructor(t, e, r) {
386
386
  super();
@@ -413,7 +413,7 @@ let M = class extends U {
413
413
  const s = n.getSheetBySheetId(e);
414
414
  if (!s)
415
415
  throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${e}!`);
416
- const o = new k(t, e, s);
416
+ const o = new q(t, e, s);
417
417
  return this._cacheFilterModel(t, e, o), o;
418
418
  }
419
419
  getFilterModel(t, e) {
@@ -471,13 +471,13 @@ let M = class extends U {
471
471
  _deserializeAutoFiltersForUnit(t, e) {
472
472
  const r = this._univerInstanceService.getUniverSheetInstance(t);
473
473
  Object.keys(e).forEach((n) => {
474
- const s = e[n], o = k.deserialize(t, n, r.getSheetBySheetId(n), s);
474
+ const s = e[n], o = q.deserialize(t, n, r.getSheetBySheetId(n), s);
475
475
  this._cacheFilterModel(t, n, o);
476
476
  });
477
477
  }
478
478
  _initModel() {
479
479
  this._resourcesManagerService.registerPluginResource({
480
- pluginName: Te,
480
+ pluginName: Ne,
481
481
  businesses: [D.UNIVER_SHEET],
482
482
  toJson: (t) => this._serializeAutoFiltersForUnit(t),
483
483
  parseJson: (t) => JSON.parse(t),
@@ -495,9 +495,9 @@ let M = class extends U {
495
495
  }
496
496
  };
497
497
  M = Dt([
498
- Y(0, De),
499
- Y(1, N),
500
- Y(2, T)
498
+ X(0, De),
499
+ X(1, T),
500
+ X(2, N)
501
501
  ], M);
502
502
  const R = {
503
503
  id: Se,
@@ -531,7 +531,7 @@ const R = {
531
531
  id: "sheet.command.set-filter-range",
532
532
  type: O.COMMAND,
533
533
  handler: (i, t) => {
534
- const e = i.get(M), r = i.get(T), n = i.get(Q), s = i.get(N), { unitId: o, subUnitId: l, range: a } = t;
534
+ const e = i.get(M), r = i.get(N), n = i.get(J), s = i.get(T), { unitId: o, subUnitId: l, range: a } = t;
535
535
  if (!H(s, t) || e.getFilterModel(o, l)) return !1;
536
536
  if (a.endRow === a.startRow) {
537
537
  const g = i.get(Be), _ = i.get(ze);
@@ -548,7 +548,7 @@ const R = {
548
548
  id: "sheet.command.remove-sheet-filter",
549
549
  type: O.COMMAND,
550
550
  handler: (i, t) => {
551
- const e = i.get(N), r = i.get(M), n = i.get(T), s = i.get(Q), o = H(e, t);
551
+ const e = i.get(T), r = i.get(M), n = i.get(N), s = i.get(J), o = H(e, t);
552
552
  if (!o) return !1;
553
553
  const { unitId: l, subUnitId: a } = o, c = r.getFilterModel(l, a);
554
554
  if (!c) return !1;
@@ -563,7 +563,7 @@ const R = {
563
563
  id: "sheet.command.smart-toggle-filter",
564
564
  type: O.COMMAND,
565
565
  handler: async (i) => {
566
- const t = i.get(N), e = i.get(M), r = i.get(T), n = t.getCurrentUnitForType(D.UNIVER_SHEET), s = n == null ? void 0 : n.getActiveSheet();
566
+ const t = i.get(T), e = i.get(M), r = i.get(N), n = t.getCurrentUnitForType(D.UNIVER_SHEET), s = n == null ? void 0 : n.getActiveSheet();
567
567
  if (!s || !n) return !1;
568
568
  const o = n.getUnitId(), l = s.getSheetId();
569
569
  if (e.getFilterModel(o, l))
@@ -581,7 +581,7 @@ const R = {
581
581
  id: "sheet.command.set-filter-criteria",
582
582
  type: O.COMMAND,
583
583
  handler: (i, t) => {
584
- const e = i.get(M), r = i.get(T), n = i.get(Q), { unitId: s, subUnitId: o, col: l, criteria: a } = t, c = e.getFilterModel(s, o);
584
+ const e = i.get(M), r = i.get(N), n = i.get(J), { unitId: s, subUnitId: o, col: l, criteria: a } = t, c = e.getFilterModel(s, o);
585
585
  if (!c) return !1;
586
586
  const u = c.getRange();
587
587
  if (!u || l < u.startColumn || l > u.endColumn) return !1;
@@ -604,11 +604,11 @@ const R = {
604
604
  id: "sheet.command.clear-filter-criteria",
605
605
  type: O.COMMAND,
606
606
  handler: (i, t) => {
607
- const e = i.get(M), r = i.get(Q), n = i.get(T), s = i.get(N), o = H(s, t);
607
+ const e = i.get(M), r = i.get(J), n = i.get(N), s = i.get(T), o = H(s, t);
608
608
  if (!o) return !1;
609
609
  const { unitId: l, subUnitId: a } = o, c = e.getFilterModel(o.unitId, o.subUnitId);
610
610
  if (!c) return !1;
611
- const u = c.serialize(), d = Ne(l, a, u), h = Vt(l, a, u);
611
+ const u = c.serialize(), d = Te(l, a, u), h = Vt(l, a, u);
612
612
  return j(h, n).result ? (r.pushUndoRedo({
613
613
  unitID: l,
614
614
  undoMutations: d,
@@ -619,7 +619,7 @@ const R = {
619
619
  id: "sheet.command.re-calc-filter",
620
620
  type: O.COMMAND,
621
621
  handler: (i, t) => {
622
- const e = i.get(M), r = i.get(T), n = i.get(N), s = H(n, t);
622
+ const e = i.get(M), r = i.get(N), n = i.get(T), s = H(n, t);
623
623
  if (!s) return !1;
624
624
  const { unitId: o, subUnitId: l } = s;
625
625
  return e.getFilterModel(s.unitId, s.subUnitId) ? r.executeCommand(B.id, { unitId: o, subUnitId: l }) : !1;
@@ -634,9 +634,9 @@ function Ht(i, t, e) {
634
634
  range: e.ref
635
635
  }
636
636
  };
637
- return r.push(n), Ne(i, t, e).forEach((o) => r.push(o)), r;
637
+ return r.push(n), Te(i, t, e).forEach((o) => r.push(o)), r;
638
638
  }
639
- function Ne(i, t, e) {
639
+ function Te(i, t, e) {
640
640
  var n;
641
641
  const r = [];
642
642
  return (n = e.filterColumns) == null || n.forEach((s) => {
@@ -1003,7 +1003,7 @@ let z = class extends U {
1003
1003
  const { colIndex: m, filter: v } = d[f], E = f;
1004
1004
  if (v) {
1005
1005
  if (E >= w && E <= S) {
1006
- const J = {
1006
+ const Z = {
1007
1007
  unitId: r,
1008
1008
  subUnitId: n,
1009
1009
  col: E,
@@ -1014,16 +1014,16 @@ let z = class extends U {
1014
1014
  col: E,
1015
1015
  criteria: s.getFilterColumn(E) ? { ...(re = s.getFilterColumn(E)) == null ? void 0 : re.serialize(), colId: E } : null
1016
1016
  };
1017
- c.push({ id: p.id, params: J }), u.push({ id: p.id, params: Ie });
1017
+ c.push({ id: p.id, params: Z }), u.push({ id: p.id, params: Ie });
1018
1018
  }
1019
1019
  if (!((ne = d[m]) != null && ne.filter)) {
1020
- const J = {
1020
+ const Z = {
1021
1021
  unitId: r,
1022
1022
  subUnitId: n,
1023
1023
  col: m,
1024
1024
  criteria: null
1025
1025
  };
1026
- c.push({ id: p.id, params: J }), u.push({ id: p.id, params: { unitId: r, subUnitId: n, col: m, criteria: { ...v.serialize(), colId: m } } });
1026
+ c.push({ id: p.id, params: Z }), u.push({ id: p.id, params: { unitId: r, subUnitId: n, col: m, criteria: { ...v.serialize(), colId: m } } });
1027
1027
  }
1028
1028
  }
1029
1029
  }), l !== w || a !== S) {
@@ -1085,7 +1085,7 @@ let z = class extends U {
1085
1085
  if (!l)
1086
1086
  return this._handleNull();
1087
1087
  const a = [], c = [];
1088
- if (ee.contains(n, l)) {
1088
+ if (te.contains(n, l)) {
1089
1089
  const u = l.startRow - n.startRow, d = l.startColumn - n.startColumn, h = {
1090
1090
  startRow: s.startRow + u,
1091
1091
  startColumn: s.startColumn + d,
@@ -1104,7 +1104,7 @@ let z = class extends U {
1104
1104
  const [m, v] = f;
1105
1105
  v && (a.push({ id: p.id, params: { unitId: e, subUnitId: r, col: m + F, criteria: { ...v.serialize(), colId: m + F } } }), c.push({ id: p.id, params: { unitId: e, subUnitId: r, col: m, criteria: { ...v.serialize(), colId: m } } }));
1106
1106
  });
1107
- } else if (ee.intersects(s, l)) {
1107
+ } else if (te.intersects(s, l)) {
1108
1108
  const u = {
1109
1109
  ...l,
1110
1110
  endRow: Math.max(l.endRow, s.endRow)
@@ -1300,10 +1300,10 @@ let z = class extends U {
1300
1300
  }
1301
1301
  };
1302
1302
  z = qt([
1303
- I(0, T),
1303
+ I(0, N),
1304
1304
  I(1, A(Qe)),
1305
1305
  I(2, A(M)),
1306
- I(3, N),
1306
+ I(3, T),
1307
1307
  I(4, A(Je)),
1308
1308
  I(5, He(gt)),
1309
1309
  I(6, A(Ze))
@@ -1312,7 +1312,7 @@ var Gt = Object.getOwnPropertyDescriptor, Qt = (i, t, e, r) => {
1312
1312
  for (var n = r > 1 ? void 0 : r ? Gt(t, e) : t, s = i.length - 1, o; s >= 0; s--)
1313
1313
  (o = i[s]) && (n = o(n) || n);
1314
1314
  return n;
1315
- }, X = (i, t) => (e, r) => t(e, r, i);
1315
+ }, ee = (i, t) => (e, r) => t(e, r, i);
1316
1316
  const Jt = [
1317
1317
  p.id,
1318
1318
  B.id
@@ -1321,7 +1321,7 @@ const Jt = [
1321
1321
  Re.id,
1322
1322
  pe.id
1323
1323
  ];
1324
- let q = class extends U {
1324
+ let G = class extends U {
1325
1325
  constructor(t, e, r) {
1326
1326
  super();
1327
1327
  C(this, "_d", new me());
@@ -1365,17 +1365,17 @@ let q = class extends U {
1365
1365
  );
1366
1366
  }
1367
1367
  };
1368
- q = Qt([
1369
- X(0, A(z)),
1370
- X(1, T),
1371
- X(2, ge)
1372
- ], q);
1368
+ G = Qt([
1369
+ ee(0, A(z)),
1370
+ ee(1, N),
1371
+ ee(2, ge)
1372
+ ], G);
1373
1373
  var Kt = Object.getOwnPropertyDescriptor, Yt = (i, t, e, r) => {
1374
1374
  for (var n = r > 1 ? void 0 : r ? Kt(t, e) : t, s = i.length - 1, o; s >= 0; s--)
1375
1375
  (o = i[s]) && (n = o(n) || n);
1376
1376
  return n;
1377
1377
  }, V = (i, t) => (e, r) => t(e, r, i);
1378
- let G = class extends U {
1378
+ let Q = class extends U {
1379
1379
  constructor(i, t, e, r) {
1380
1380
  super(), this._activeDirtyManagerService = i, this._sheetRowFilteredService = t, this._sheetsFilterService = e, this._univerInstanceService = r, this._initFormulaDirtyRange(), this._registerSheetRowFiltered();
1381
1381
  }
@@ -1424,12 +1424,12 @@ let G = class extends U {
1424
1424
  });
1425
1425
  }
1426
1426
  };
1427
- G = Yt([
1427
+ Q = Yt([
1428
1428
  V(0, A(_t)),
1429
1429
  V(1, A(Ct)),
1430
1430
  V(2, A(M)),
1431
- V(3, N)
1432
- ], G);
1431
+ V(3, T)
1432
+ ], Q);
1433
1433
  var Xt = Object.getOwnPropertyDescriptor, er = (i, t, e, r) => {
1434
1434
  for (var n = r > 1 ? void 0 : r ? Xt(t, e) : t, s = i.length - 1, o; s >= 0; s--)
1435
1435
  (o = i[s]) && (n = o(n) || n);
@@ -1447,20 +1447,20 @@ let fe = (W = class extends Ve {
1447
1447
  }
1448
1448
  onStarting() {
1449
1449
  [
1450
- [G],
1450
+ [Q],
1451
1451
  [M],
1452
1452
  [z],
1453
- [q]
1453
+ [G]
1454
1454
  ].forEach((i) => this._injector.add(i));
1455
1455
  }
1456
1456
  onReady() {
1457
1457
  je(this._injector, [
1458
- [G],
1458
+ [Q],
1459
1459
  [z],
1460
- [q]
1460
+ [G]
1461
1461
  ]);
1462
1462
  }
1463
- }, C(W, "type", D.UNIVER_SHEET), C(W, "pluginName", Te), W);
1463
+ }, C(W, "type", D.UNIVER_SHEET), C(W, "pluginName", Ne), W);
1464
1464
  fe = er([
1465
1465
  he(1, A(ke)),
1466
1466
  he(2, ge)
@@ -1471,18 +1471,18 @@ export {
1471
1471
  Me as FILTER_MUTATIONS,
1472
1472
  b as FilterBy,
1473
1473
  yt as FilterColumn,
1474
- k as FilterModel,
1474
+ q as FilterModel,
1475
1475
  ur as ReCalcSheetsFilterCommand,
1476
1476
  B as ReCalcSheetsFilterMutation,
1477
1477
  zt as RemoveSheetFilterCommand,
1478
1478
  y as RemoveSheetsFilterMutation,
1479
- Te as SHEET_FILTER_SNAPSHOT_ID,
1479
+ Ne as SHEET_FILTER_SNAPSHOT_ID,
1480
1480
  Bt as SetSheetFilterRangeCommand,
1481
1481
  cr as SetSheetsFilterCriteriaCommand,
1482
1482
  p as SetSheetsFilterCriteriaMutation,
1483
1483
  R as SetSheetsFilterRangeMutation,
1484
1484
  M as SheetsFilterService,
1485
- q as SheetsFilterSyncController,
1485
+ G as SheetsFilterSyncController,
1486
1486
  ar as SmartToggleSheetsFilterCommand,
1487
1487
  fe as UniverSheetsFilterPlugin,
1488
1488
  wt as equals,
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(h,c){typeof exports=="object"&&typeof module<"u"?c(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"],c):(h=typeof globalThis<"u"?globalThis:h||self,c(h.UniverSheetsFilter={},h.UniverCore,h.UniverSheets,h.rxjs,h.UniverEngineRender,h.UniverRpc,h.UniverEngineFormula))})(this,(function(h,c,_,I,Re,ve,J){"use strict";var et=Object.defineProperty;var tt=(h,c,_)=>c in h?et(h,c,{enumerable:!0,configurable:!0,writable:!0,value:_}):h[c]=_;var v=(h,c,_)=>tt(h,typeof c!="symbol"?c+"":c,_);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"&&c.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 c.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:c.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?c.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 ce(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)=>c.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=c.mergeSets(this._alreadyFilteredOutRows,r))}}}class ce extends c.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 c.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 c.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:d,col:m}=l;if(o.has(a)&&(!d||d===1))continue;if(!(this._filterBy===N.VALUES?this._filterFn(c.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),d))for(let f=1;f<d;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 c.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 c.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?de(t):r?t.t===c.CellValueType.NUMBER&&typeof t.v=="string"?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===c.CellValueType.BOOLEAN?e.toUpperCase():e:typeof e=="number"?i.t===c.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 c.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(c.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(c.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([e])=>e.type===c.CommandType.MUTATION&&H.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(c.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:[c.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,c.IResourceManagerService),q(1,c.IUniverInstanceService),q(2,c.ICommandService)],h.SheetsFilterService);const F={id:K,type:c.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:c.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:c.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(h.SheetsFilterService).removeFilterModel(e,t)}},$={id:X,type:c.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:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(c.ICommandService),r=i.get(c.IUndoRedoService),s=i.get(c.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(c.ErrorService),R=i.get(c.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:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(c.IUniverInstanceService),t=i.get(h.SheetsFilterService),r=i.get(c.ICommandService),s=i.get(c.IUndoRedoService),o=_.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,d=t.getFilterModel(l,a);if(!d)return!1;const m=d==null?void 0:d.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:c.CommandType.COMMAND,handler:async i=>{const n=i.get(c.IUniverInstanceService),e=i.get(h.SheetsFilterService),t=i.get(c.ICommandService),r=n.getCurrentUnitForType(c.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:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(c.ICommandService),r=i.get(c.IUndoRedoService),{unitId:s,subUnitId:o,col:l,criteria:a}=n,d=e.getFilterModel(s,o);if(!d)return!1;const m=d.getRange();if(!m||l<m.startColumn||l>m.endColumn)return!1;const u=d.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:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(c.IUndoRedoService),r=i.get(c.ICommandService),s=i.get(c.IUniverInstanceService),o=_.getSheetCommandTarget(s,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,d=e.getFilterModel(o.unitId,o.subUnitId);if(!d)return!1;const m=d.serialize(),u=me(l,a,m),f=xe(l,a,m);return c.sequenceExecute(f,r).result?(t.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:f}),!0):!1}},Be={id:"sheet.command.re-calc-filter",type:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(c.ICommandService),r=i.get(c.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 c.Disposable{constructor(n,e,t,r,s,o,l){super();v(this,"_disposableCollection",new c.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 d=a.params,m=d.unitId||n,u=d.subUnitId||e;return this._handleInsertRowCommand(d,m,u)}case _.InsertColCommand.id:{const d=a.params,m=d.unitId||n,u=d.subUnitId||e;return this.handleInsertColCommand(d.range,m,u)}case _.RemoveColCommand.id:{const d=a.params;return this.handleRemoveColCommand(d.range,n,e)}case _.RemoveRowCommand.id:{const d=a.params;return this._handleRemoveRowCommand(d,n,e)}case _.EffectRefRangId.MoveColsCommandId:{const d=a.params;return this.handleMoveColsCommand({fromRange:d.fromRange,toRange:d.toRange},n,e)}case _.EffectRefRangId.MoveRowsCommandId:{const d=a.params;return this._handleMoveRowsCommand(d,n,e)}case _.MoveRangeCommand.id:{const d=a.params;return this._handleMoveRangeCommand(d,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:d}=n,m=d-a+1;if(d>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:d}=n.range,m=d-a+1;if(d>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:d}=n;if(a>l)return this._handleNull();const m=[],u=[],f=d<o?0:Math.min(d,l)-Math.max(a,o)+1,S=d-a+1,R=r.getAllFilterColumns();R.forEach(g=>{const[C,y]=g;C<=d&&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>d});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:d}=n.range;if(a>l)return this._handleNull();if(d<o)return{undos:[{id:F.id,params:{range:s,unitId:e,subUnitId:t}}],redos:[{id:F.id,params:{range:{...s,startRow:o-(d-a+1),endRow:l-(d-a+1)},unitId:e,subUnitId:t}}]};const m=[],u=[],f=r.getAllFilterColumns(),S=o<=d&&o>=a;u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}});const R=Math.min(d,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<=d;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 d=[],m=[],u={};for(let g=l;g<=a;g++)u[g]={colIndex:g,filter:s.getFilterColumn(g)};c.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};d.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};d.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}};d.unshift({id:F.id,params:g}),m.unshift({id:F.id,params:{range:o,unitId:t,subUnitId:r}})}return{undos:m,redos:d}}_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:d}=n;if(a.endRow<o&&d.startRow<=o||a.startRow>l&&d.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&&d.startRow<a.startRow&&a.startRow>o&&(R=a.startRow-1),c.moveMatrixArray(a.startRow,a.endRow-a.startRow+1,d.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=[],d=[];if(c.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),d.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}}}),d.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:{...y.serialize(),colId:C}}}))})}else if(c.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}}),d.push({id:F.id,params:{unitId:e,subUnitId:t,range:l}})}return{redos:a,undos:d}}_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(([d,m])=>{l.push({id:p.id,params:{unitId:e,subUnitId:t,col:d,criteria:{...m.serialize(),colId:d}}})}),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=[],d=[];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:d}}_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=[],d=[];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;d.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:d,undos:a},oldRange:{redos:l,undos:o}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{var d,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=(d=f==null?void 0:f[u.startRow])==null?void 0:d[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 d=s.endRow+1;d<=o;d++)if(l.getRowRawVisible(d))return{startRow:d,endRow:d,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,c.ICommandService),b(1,c.Inject(_.SheetInterceptorService)),b(2,c.Inject(h.SheetsFilterService)),b(3,c.IUniverInstanceService),b(4,c.Inject(_.RefRangeService)),b(5,c.Optional(ve.DataSyncPrimaryController)),b(6,c.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 c.Disposable{constructor(e,t,r){super();v(this,"_d",new c.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);c.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);c.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);c.sequenceExecute(a,this._commandService,t)}}}))}},h.SheetsFilterSyncController=ke([G(0,c.Inject(D)),G(1,c.ICommandService),G(2,c.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 c.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,c.Inject(J.IActiveDirtyManagerService)),B(1,c.Inject(J.ISheetRowFilteredService)),B(2,c.Inject(h.SheetsFilterService)),B(3,c.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 c.Plugin{constructor(n=ge,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=c.merge({},ge,this._config);this._configService.setConfig(fe,r)}onStarting(){[[j],[h.SheetsFilterService],[D],[h.SheetsFilterSyncController]].forEach(n=>this._injector.add(n))}onReady(){c.touchDependencies(this._injector,[[j],[D],[h.SheetsFilterSyncController]])}},v(x,"type",c.UniverInstanceType.UNIVER_SHEET),v(x,"pluginName",k),x),h.UniverSheetsFilterPlugin=Ye([Ce(1,c.Inject(c.Injector)),Ce(2,c.IConfigService)],h.UniverSheetsFilterPlugin),h.ClearSheetsFilterCriteriaCommand=De,h.CustomFilterOperator=A,h.FILTER_MUTATIONS=H,h.FilterBy=N,h.FilterColumn=ce,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"})}));
1
+ (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"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-filter",
3
- "version": "0.10.7-nightly.202509130703",
3
+ "version": "0.10.8-nightly.202509200616",
4
4
  "private": false,
5
5
  "description": "A library for filtering data in Univer Sheet",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -56,18 +56,18 @@
56
56
  "rxjs": ">=7.0.0"
57
57
  },
58
58
  "dependencies": {
59
- "@univerjs/core": "0.10.7-nightly.202509130703",
60
- "@univerjs/engine-formula": "0.10.7-nightly.202509130703",
61
- "@univerjs/engine-render": "0.10.7-nightly.202509130703",
62
- "@univerjs/rpc": "0.10.7-nightly.202509130703",
63
- "@univerjs/sheets": "0.10.7-nightly.202509130703"
59
+ "@univerjs/core": "0.10.8-nightly.202509200616",
60
+ "@univerjs/engine-formula": "0.10.8-nightly.202509200616",
61
+ "@univerjs/rpc": "0.10.8-nightly.202509200616",
62
+ "@univerjs/sheets": "0.10.8-nightly.202509200616",
63
+ "@univerjs/engine-render": "0.10.8-nightly.202509200616"
64
64
  },
65
65
  "devDependencies": {
66
66
  "rxjs": "^7.8.2",
67
67
  "typescript": "^5.9.2",
68
68
  "vite": "^7.1.4",
69
69
  "vitest": "^3.2.4",
70
- "@univerjs-infra/shared": "0.10.7"
70
+ "@univerjs-infra/shared": "0.10.8"
71
71
  },
72
72
  "scripts": {
73
73
  "test": "vitest run",