@univerjs/sheets-filter 0.12.3 → 0.12.4-experimental.20251210-8d33c6e
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 +1 -1
- package/lib/es/index.js +42 -39
- package/lib/index.js +42 -39
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Se=Object.defineProperty;var Re=(i,n,e)=>n in i?Se(i,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[n]=e;var R=(i,n,e)=>Re(i,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),S=require("@univerjs/sheets"),O=require("rxjs"),Fe=require("@univerjs/engine-render"),ve=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)?!c.createREGEXFromWildChar(n).test(e):e!==n}return U(i)?i!==n:!0}},de=new Map([]),pe=[se,oe,le,ae,ce,k];pe.forEach(i=>{de.set(i.operator,i)});function we(i){return!!i}const Me={fn:(i,n)=>{const e=ue(i);return e===null?n==="":c.createREGEXFromWildChar(n).test(e)}};function W(i){return i?de.get(i):Me}function U(i){return typeof i=="number"}function Z(i){return!!(typeof i=="number"||typeof i=="string"&&c.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}const H=()=>new Set;class $ extends c.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(),this._worksheet=null}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 $(e,t,r);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.filter(r=>!(!r.filters&&!r.colorFilters&&!r.customFilters)).forEach(r=>this._setCriteriaWithoutReCalc(r.colId,r)),e.cachedFilteredOut?(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()):e.filterColumns&&e.filterColumns.length>0&&(this._reCalcAllColumns(),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._getAllFilterColumns().forEach(s=>s.__clearCache()),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 he(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 he extends c.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 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:h}=l;if(o.has(a)&&(!d||d===1))continue;if(!(this._filterBy===A.VALUES?this._filterFn(c.extractPureTextFromCell(this._worksheet.getCell(a,h))):this._filterBy===A.COLORS?this._filterFn(this._worksheet.getComposedCellStyle(a,h)):this._filterFn(Ue(this._worksheet,a,h)))&&(s.add(a),d))for(let m=1;m<d;m++)s.add(a+m)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=ye(this._criteria),this._filterBy=this._criteria.filters?A.VALUES:this._criteria.colorFilters?A.COLORS:A.CONDITIONS)}}function ye(i){if(i.filters)return Oe(i.filters);if(i.colorFilters)return Ie(i.colorFilters);if(i.customFilters)return Te(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function Oe(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 Ie(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(Fe.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 Te(i){const n=i.customFilters.map(e=>xe(e));return Ne(n)?i.and?Ae(n):be(n):n[0]}function Ae(i){const[n,e]=i;return t=>n(t)&&e(t)}function be(i){const[n,e]=i;return t=>n(t)||e(t)}function Ne(i){return i.length===2}function xe(i){const n=i.val;if(i.operator===T.NOT_EQUALS&&!Z(n))return r=>k.fn(r,n);if(we(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 Ue(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?X(t):r?t.t===c.CellValueType.NUMBER&&typeof t.v=="string"?r.v:t.t===c.CellValueType.NUMBER?Number(r.v):X(r):null}function X(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 $e=Object.getOwnPropertyDescriptor,Le=(i,n,e,t)=>{for(var r=t>1?void 0:t?$e(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 c.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(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(O.merge(c.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(O.filter(([e])=>e.type===c.CommandType.MUTATION&&q.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(c.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)})}dispose(){super.dispose(),this._loadedUnitId$.complete(),this._errorMsg$.complete(),this._activeFilterModel$.complete(),this._filterModels.forEach(e=>{e.forEach(t=>t.dispose()),e.clear()}),this._filterModels.clear()}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:G,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)}};exports.SheetsFilterService=Le([z(0,c.IResourceManagerService),z(1,c.IUniverInstanceService),z(2,c.ICommandService)],exports.SheetsFilterService);const F={id:te,type:c.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:c.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:c.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(exports.SheetsFilterService).removeFilterModel(e,t)}},x={id:ie,type:c.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}},me={id:"sheet.command.set-filter-range",type:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(c.ICommandService),r=i.get(c.IUndoRedoService),s=i.get(c.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(c.ErrorService),_=i.get(c.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}},fe={id:"sheet.command.remove-sheet-filter",type:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(c.IUniverInstanceService),t=i.get(exports.SheetsFilterService),r=i.get(c.ICommandService),s=i.get(c.IUndoRedoService),o=S.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,d=t.getFilterModel(l,a);if(!d)return!1;const h=d==null?void 0:d.serialize(),u=He(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}},Pe={id:"sheet.command.smart-toggle-filter",type:c.CommandType.COMMAND,handler:async i=>{const n=i.get(c.IUniverInstanceService),e=i.get(exports.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(fe.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(me.id,{unitId:o,subUnitId:l,range:m})}},De={id:"sheet.command.set-filter-criteria",type:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.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 h=d.getRange();if(!h||l<h.startColumn||l>h.endColumn)return!1;const u=d.getFilterColumn(l),m=Ve(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]}),_}},Be={id:"sheet.command.clear-filter-criteria",type:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(c.IUndoRedoService),r=i.get(c.ICommandService),s=i.get(c.IUniverInstanceService),o=S.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 h=d.serialize(),u=ge(l,a,h),m=ze(l,a,h);return c.sequenceExecute(m,r).result?(t.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:m}),!0):!1}},je={id:"sheet.command.re-calc-filter",type:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(c.ICommandService),r=i.get(c.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 He(i,n,e){const t=[],r={id:F.id,params:{unitId:i,subUnitId:n,range:e.ref}};return t.push(r),ge(i,n,e).forEach(o=>t.push(o)),t}function ge(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 ze(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 Ve(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 Ce="sheets-filter.config",Y={};function We(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 We(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 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},b=(i,n)=>(e,t)=>n(e,t,i);let L=class extends c.Disposable{constructor(n,e,t,r,s,o,l){super();R(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(){[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 d=a.params,h=d.unitId||n,u=d.subUnitId||e;return this._handleInsertRowCommand(d,h,u)}case S.InsertColCommand.id:{const d=a.params,h=d.unitId||n,u=d.subUnitId||e;return this.handleInsertColCommand(d.range,h,u)}case S.RemoveColCommand.id:{const d=a.params;return this.handleRemoveColCommand(d.range,n,e)}case S.RemoveRowCommand.id:{const d=a.params;return this._handleRemoveRowCommand(d,n,e)}case S.EffectRefRangId.MoveColsCommandId:{const d=a.params;return this.handleMoveColsCommand({fromRange:d.fromRange,toRange:d.toRange},n,e)}case S.EffectRefRangId.MoveRowsCommandId:{const d=a.params;return this._handleMoveRowsCommand(d,n,e)}case S.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 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:d}=n,h=d-a+1;if(d>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:E}=this._moveCriteria(e,t,w,h);u.push(...E.redos,...g.redos),m.push(...g.undos,...E.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:d}=n.range,h=d-a+1;if(d>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:d}=n;if(a>l)return this._handleNull();const h=[],u=[],m=d<o?0:Math.min(d,l)-Math.max(a,o)+1,C=d-a+1,_=r.getAllFilterColumns();_.forEach(f=>{const[g,E]=f;g<=d&&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:{...E.serialize(),colId:g}}}))});const p=_.filter(f=>{const[g,E]=f;return g>d});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,E={unitId:e,subUnitId:t,range:{...s,startColumn:f,endColumn:g}};h.push({id:F.id,params:E}),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: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 h=[],u=[],m=r.getAllFilterColumns(),C=o<=d&&o>=a;u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}});const _=Math.min(d,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,E={unitId:e,subUnitId:t,col:f,criteria:{...g.serialize(),colId:f}};u.push({id:v.id,params:E})})}else{const M=(p=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:p.getSheetBySheetId(t);if(!M)return this._handleNull();const w=[];for(let y=a;y<=d;y++)M.getRowFiltered(y)&&w.push(y);const f=Math.min(o,a),g=f+(l-o)-_+w.length,E={unitId:e,subUnitId:t,range:{...s,startRow:f,endRow:g}};h.push({id:F.id,params:E})}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 d=[],h=[],u={};for(let f=l;f<=a;f++)u[f]={colIndex:f,filter:s.getFilterColumn(f)};c.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:E}=u[f],y=f;if(E){if(y>=M&&y<=p){const j={unitId:t,subUnitId:r,col:y,criteria:{...E.serialize(),colId:y}},_e={unitId:t,subUnitId:r,col:y,criteria:s.getFilterColumn(y)?{...(Q=s.getFilterColumn(y))==null?void 0:Q.serialize(),colId:y}:null};d.push({id:v.id,params:j}),h.push({id:v.id,params:_e})}if(!((J=u[g])!=null&&J.filter)){const j={unitId:t,subUnitId:r,col:g,criteria:null};d.push({id:v.id,params:j}),h.push({id:v.id,params:{unitId:t,subUnitId:r,col:g,criteria:{...E.serialize(),colId:g}}})}}}),l!==M||a!==p){const f={unitId:t,subUnitId:r,range:{...o,startColumn:M,endColumn:p}};d.unshift({id:F.id,params:f}),h.unshift({id:F.id,params:{range:o,unitId:t,subUnitId:r}})}return{undos:h,redos:d}}_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:d}=n;if(a.endRow<o&&d.startRow<=o||a.startRow>l&&d.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&&d.startRow<a.startRow&&a.startRow>o&&(_=a.startRow-1),c.moveMatrixArray(a.startRow,a.endRow-a.startRow+1,d.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=[],d=[];if(c.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,_),d.push(C,p);const M=o.getAllFilterColumns(),w=s.startColumn-r.startColumn;M.forEach(f=>{const[g,E]=f;E&&(a.push({id:v.id,params:{unitId:e,subUnitId:t,col:g+w,criteria:{...E.serialize(),colId:g+w}}}),d.push({id:v.id,params:{unitId:e,subUnitId:t,col:g,criteria:{...E.serialize(),colId:g}}}))})}else if(c.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}}),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,h])=>{l.push({id:v.id,params:{unitId:e,subUnitId:t,col:d,criteria:{...h.serialize(),colId:d}}})}),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=[],d=[];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:d}}_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=[],d=[];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;d.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:d,undos:a},oldRange:{redos:l,undos:o}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{var d,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 _=(d=m==null?void 0:m[u.startRow])==null?void 0:d[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 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=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=ke([b(0,c.ICommandService),b(1,c.Inject(S.SheetInterceptorService)),b(2,c.Inject(exports.SheetsFilterService)),b(3,c.IUniverInstanceService),b(4,c.Inject(S.RefRangeService)),b(5,c.Optional(ve.DataSyncPrimaryController)),b(6,c.Inject(S.ZebraCrossingCacheController))],L);var Ge=Object.getOwnPropertyDescriptor,Qe=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ge(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 Je=[v.id,x.id],Ke=[S.InsertColMutation.id,S.RemoveColMutation.id,S.MoveColsMutation.id];exports.SheetsFilterSyncController=class extends c.Disposable{constructor(e,t,r){var o;super();R(this,"_d",new c.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(Ce);s!=null&&s.enableSyncSwitch&&(this._visible$.next(!0),typeof s.enableSyncSwitch=="object"&&this.setEnabled((o=s.enableSyncSwitch.defaultValue)!=null?o:!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)=>{Je.includes(e.id)&&(t||(t={}),t.onlyLocal=!0)})),this._d.add(this._commandService.onCommandExecuted((e,t)=>{if(Ke.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);c.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);c.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);c.sequenceExecute(a,this._commandService,t)}}}))}};exports.SheetsFilterSyncController=Qe([V(0,c.Inject(L)),V(1,c.ICommandService),V(2,c.IConfigService)],exports.SheetsFilterSyncController);var Ze=Object.getOwnPropertyDescriptor,Xe=(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},P=(i,n)=>(e,t)=>n(e,t,i);let B=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(){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,c.Inject(K.IActiveDirtyManagerService)),P(1,c.Inject(K.ISheetRowFilteredService)),P(2,c.Inject(exports.SheetsFilterService)),P(3,c.IUniverInstanceService)],B);var Ye=Object.getOwnPropertyDescriptor,et=(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},ee=(i,n)=>(e,t)=>n(e,t,i),D;exports.UniverSheetsFilterPlugin=(D=class extends c.Plugin{constructor(n=Y,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=c.merge({},Y,this._config);this._configService.setConfig(Ce,r)}onStarting(){[[B],[exports.SheetsFilterService],[L],[exports.SheetsFilterSyncController]].forEach(n=>this._injector.add(n))}onReady(){c.touchDependencies(this._injector,[[B],[L],[exports.SheetsFilterSyncController]])}},R(D,"type",c.UniverInstanceType.UNIVER_SHEET),R(D,"pluginName",G),D);exports.UniverSheetsFilterPlugin=et([ee(1,c.Inject(c.Injector)),ee(2,c.IConfigService)],exports.UniverSheetsFilterPlugin);exports.ClearSheetsFilterCriteriaCommand=Be;exports.CustomFilterOperator=T;exports.FILTER_MUTATIONS=q;exports.FilterBy=A;exports.FilterColumn=he;exports.FilterModel=$;exports.ReCalcSheetsFilterCommand=je;exports.ReCalcSheetsFilterMutation=x;exports.RemoveSheetFilterCommand=fe;exports.RemoveSheetsFilterMutation=I;exports.SHEET_FILTER_SNAPSHOT_ID=G;exports.SetSheetFilterRangeCommand=me;exports.SetSheetsFilterCriteriaCommand=De;exports.SetSheetsFilterCriteriaMutation=v;exports.SetSheetsFilterRangeMutation=F;exports.SmartToggleSheetsFilterCommand=Pe;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 Se=Object.defineProperty;var Re=(i,n,e)=>n in i?Se(i,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[n]=e;var R=(i,n,e)=>Re(i,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),S=require("@univerjs/sheets"),O=require("rxjs"),Fe=require("@univerjs/engine-render"),ve=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)?!c.createREGEXFromWildChar(n).test(e):e!==n}return U(i)?i!==n:!0}},de=new Map([]),pe=[se,oe,le,ae,ce,k];pe.forEach(i=>{de.set(i.operator,i)});function we(i){return!!i}const Me={fn:(i,n)=>{const e=ue(i);return e===null?n==="":c.createREGEXFromWildChar(n).test(e)}};function W(i){return i?de.get(i):Me}function U(i){return typeof i=="number"}function Z(i){return!!(typeof i=="number"||typeof i=="string"&&c.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}const H=()=>new Set;class $ extends c.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(),this._worksheet=null}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 $(e,t,r);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.filter(r=>!(!r.filters&&!r.colorFilters&&!r.customFilters)).forEach(r=>this._setCriteriaWithoutReCalc(r.colId,r)),e.cachedFilteredOut?(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()):e.filterColumns&&e.filterColumns.length>0&&(this._reCalcAllColumns(),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._getAllFilterColumns().forEach(s=>s.__clearCache()),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 he(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 he extends c.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 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:h}=l;if(o.has(a)&&(!d||d===1))continue;if(!(this._filterBy===A.VALUES?this._filterFn(c.extractPureTextFromCell(this._worksheet.getCell(a,h))):this._filterBy===A.COLORS?this._filterFn(this._worksheet.getComposedCellStyle(a,h)):this._filterFn(Ue(this._worksheet,a,h)))&&(s.add(a),d))for(let m=1;m<d;m++)s.add(a+m)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=ye(this._criteria),this._filterBy=this._criteria.filters?A.VALUES:this._criteria.colorFilters?A.COLORS:A.CONDITIONS)}}function ye(i){if(i.filters)return Oe(i.filters);if(i.colorFilters)return Ie(i.colorFilters);if(i.customFilters)return Te(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function Oe(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 Ie(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(Fe.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 Te(i){const n=i.customFilters.map(e=>xe(e));return Ne(n)?i.and?Ae(n):be(n):n[0]}function Ae(i){const[n,e]=i;return t=>n(t)&&e(t)}function be(i){const[n,e]=i;return t=>n(t)||e(t)}function Ne(i){return i.length===2}function xe(i){const n=i.val;if(i.operator===T.NOT_EQUALS&&!Z(n))return r=>k.fn(r,n);if(we(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 Ue(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?X(t):r?t.t===c.CellValueType.NUMBER&&typeof t.v=="string"?r.v:t.t===c.CellValueType.NUMBER?Number(r.v):X(r):null}function X(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 $e=Object.getOwnPropertyDescriptor,Le=(i,n,e,t)=>{for(var r=t>1?void 0:t?$e(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 c.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(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(O.merge(c.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(O.filter(([e])=>e.type===c.CommandType.MUTATION&&q.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(c.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)})}dispose(){super.dispose(),this._loadedUnitId$.complete(),this._errorMsg$.complete(),this._activeFilterModel$.complete(),this._filterModels.forEach(e=>{e.forEach(t=>t.dispose()),e.clear()}),this._filterModels.clear()}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:G,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)}};exports.SheetsFilterService=Le([z(0,c.IResourceManagerService),z(1,c.IUniverInstanceService),z(2,c.ICommandService)],exports.SheetsFilterService);const F={id:te,type:c.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:c.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:c.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(exports.SheetsFilterService).removeFilterModel(e,t)}},x={id:ie,type:c.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}},me={id:"sheet.command.set-filter-range",type:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(c.ICommandService),r=i.get(c.IUndoRedoService),s=i.get(c.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(c.ErrorService),_=i.get(c.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}},fe={id:"sheet.command.remove-sheet-filter",type:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(c.IUniverInstanceService),t=i.get(exports.SheetsFilterService),r=i.get(c.ICommandService),s=i.get(c.IUndoRedoService),o=S.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,d=t.getFilterModel(l,a);if(!d)return!1;const h=d==null?void 0:d.serialize(),u=He(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}},Pe={id:"sheet.command.smart-toggle-filter",type:c.CommandType.COMMAND,handler:async i=>{const n=i.get(c.IUniverInstanceService),e=i.get(exports.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(fe.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.startRow===u.endRow?S.expandToContinuousRange(u,{down:!0},s):u;return t.executeCommand(me.id,{unitId:o,subUnitId:l,range:m})}},De={id:"sheet.command.set-filter-criteria",type:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.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 h=d.getRange();if(!h||l<h.startColumn||l>h.endColumn)return!1;const u=d.getFilterColumn(l),m=Ve(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]}),_}},Be={id:"sheet.command.clear-filter-criteria",type:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(c.IUndoRedoService),r=i.get(c.ICommandService),s=i.get(c.IUniverInstanceService),o=S.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 h=d.serialize(),u=ge(l,a,h),m=ze(l,a,h);return c.sequenceExecute(m,r).result?(t.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:m}),!0):!1}},je={id:"sheet.command.re-calc-filter",type:c.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(c.ICommandService),r=i.get(c.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 He(i,n,e){const t=[],r={id:F.id,params:{unitId:i,subUnitId:n,range:e.ref}};return t.push(r),ge(i,n,e).forEach(o=>t.push(o)),t}function ge(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 ze(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 Ve(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 Ce="sheets-filter.config",Y={};function We(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 We(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 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},b=(i,n)=>(e,t)=>n(e,t,i);let L=class extends c.Disposable{constructor(n,e,t,r,s,o,l){super();R(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(){[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 d=a.params,h=d.unitId||n,u=d.subUnitId||e;return this._handleInsertRowCommand(d,h,u)}case S.InsertColCommand.id:{const d=a.params,h=d.unitId||n,u=d.subUnitId||e;return this.handleInsertColCommand(d.range,h,u)}case S.RemoveColCommand.id:{const d=a.params;return this.handleRemoveColCommand(d.range,n,e)}case S.RemoveRowCommand.id:{const d=a.params;return this._handleRemoveRowCommand(d,n,e)}case S.EffectRefRangId.MoveColsCommandId:{const d=a.params;return this.handleMoveColsCommand({fromRange:d.fromRange,toRange:d.toRange},n,e)}case S.EffectRefRangId.MoveRowsCommandId:{const d=a.params;return this._handleMoveRowsCommand(d,n,e)}case S.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 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:d}=n,h=d-a+1;if(d>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:E}=this._moveCriteria(e,t,w,h);u.push(...E.redos,...g.redos),m.push(...g.undos,...E.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:d}=n.range,h=d-a+1;if(d>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:d}=n;if(a>l)return this._handleNull();const h=[],u=[],m=d<o?0:Math.min(d,l)-Math.max(a,o)+1,C=d-a+1,_=r.getAllFilterColumns();_.forEach(f=>{const[g,E]=f;g<=d&&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:{...E.serialize(),colId:g}}}))});const p=_.filter(f=>{const[g,E]=f;return g>d});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,E={unitId:e,subUnitId:t,range:{...s,startColumn:f,endColumn:g}};h.push({id:F.id,params:E}),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: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 h=[],u=[],m=r.getAllFilterColumns(),C=o<=d&&o>=a;u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}});const _=Math.min(d,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,E={unitId:e,subUnitId:t,col:f,criteria:{...g.serialize(),colId:f}};u.push({id:v.id,params:E})})}else{const M=(p=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:p.getSheetBySheetId(t);if(!M)return this._handleNull();const w=[];for(let y=a;y<=d;y++)M.getRowFiltered(y)&&w.push(y);const f=Math.min(o,a),g=f+(l-o)-_+w.length,E={unitId:e,subUnitId:t,range:{...s,startRow:f,endRow:g}};h.push({id:F.id,params:E})}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 d=[],h=[],u={};for(let f=l;f<=a;f++)u[f]={colIndex:f,filter:s.getFilterColumn(f)};c.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:E}=u[f],y=f;if(E){if(y>=M&&y<=p){const j={unitId:t,subUnitId:r,col:y,criteria:{...E.serialize(),colId:y}},_e={unitId:t,subUnitId:r,col:y,criteria:s.getFilterColumn(y)?{...(Q=s.getFilterColumn(y))==null?void 0:Q.serialize(),colId:y}:null};d.push({id:v.id,params:j}),h.push({id:v.id,params:_e})}if(!((J=u[g])!=null&&J.filter)){const j={unitId:t,subUnitId:r,col:g,criteria:null};d.push({id:v.id,params:j}),h.push({id:v.id,params:{unitId:t,subUnitId:r,col:g,criteria:{...E.serialize(),colId:g}}})}}}),l!==M||a!==p){const f={unitId:t,subUnitId:r,range:{...o,startColumn:M,endColumn:p}};d.unshift({id:F.id,params:f}),h.unshift({id:F.id,params:{range:o,unitId:t,subUnitId:r}})}return{undos:h,redos:d}}_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:d}=n;if(a.endRow<o&&d.startRow<=o||a.startRow>l&&d.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&&d.startRow<a.startRow&&a.startRow>o&&(_=a.startRow-1),c.moveMatrixArray(a.startRow,a.endRow-a.startRow+1,d.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=[],d=[];if(c.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,_),d.push(C,p);const M=o.getAllFilterColumns(),w=s.startColumn-r.startColumn;M.forEach(f=>{const[g,E]=f;E&&(a.push({id:v.id,params:{unitId:e,subUnitId:t,col:g+w,criteria:{...E.serialize(),colId:g+w}}}),d.push({id:v.id,params:{unitId:e,subUnitId:t,col:g,criteria:{...E.serialize(),colId:g}}}))})}else if(c.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}}),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,h])=>{l.push({id:v.id,params:{unitId:e,subUnitId:t,col:d,criteria:{...h.serialize(),colId:d}}})}),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=[],d=[];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:d}}_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=[],d=[];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;d.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:d,undos:a},oldRange:{redos:l,undos:o}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{var d,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 _=(d=m==null?void 0:m[u.startRow])==null?void 0:d[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 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=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=ke([b(0,c.ICommandService),b(1,c.Inject(S.SheetInterceptorService)),b(2,c.Inject(exports.SheetsFilterService)),b(3,c.IUniverInstanceService),b(4,c.Inject(S.RefRangeService)),b(5,c.Optional(ve.DataSyncPrimaryController)),b(6,c.Inject(S.ZebraCrossingCacheController))],L);var Ge=Object.getOwnPropertyDescriptor,Qe=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ge(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 Je=[v.id,x.id],Ke=[S.InsertColMutation.id,S.RemoveColMutation.id,S.MoveColsMutation.id];exports.SheetsFilterSyncController=class extends c.Disposable{constructor(e,t,r){var o;super();R(this,"_d",new c.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(Ce);s!=null&&s.enableSyncSwitch&&(this._visible$.next(!0),typeof s.enableSyncSwitch=="object"&&this.setEnabled((o=s.enableSyncSwitch.defaultValue)!=null?o:!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)=>{Je.includes(e.id)&&(t||(t={}),t.onlyLocal=!0)})),this._d.add(this._commandService.onCommandExecuted((e,t)=>{if(Ke.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);c.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);c.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);c.sequenceExecute(a,this._commandService,t)}}}))}};exports.SheetsFilterSyncController=Qe([V(0,c.Inject(L)),V(1,c.ICommandService),V(2,c.IConfigService)],exports.SheetsFilterSyncController);var Ze=Object.getOwnPropertyDescriptor,Xe=(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},P=(i,n)=>(e,t)=>n(e,t,i);let B=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(){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,c.Inject(K.IActiveDirtyManagerService)),P(1,c.Inject(K.ISheetRowFilteredService)),P(2,c.Inject(exports.SheetsFilterService)),P(3,c.IUniverInstanceService)],B);var Ye=Object.getOwnPropertyDescriptor,et=(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},ee=(i,n)=>(e,t)=>n(e,t,i),D;exports.UniverSheetsFilterPlugin=(D=class extends c.Plugin{constructor(n=Y,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=c.merge({},Y,this._config);this._configService.setConfig(Ce,r)}onStarting(){[[B],[exports.SheetsFilterService],[L],[exports.SheetsFilterSyncController]].forEach(n=>this._injector.add(n))}onReady(){c.touchDependencies(this._injector,[[B],[L],[exports.SheetsFilterSyncController]])}},R(D,"type",c.UniverInstanceType.UNIVER_SHEET),R(D,"pluginName",G),D);exports.UniverSheetsFilterPlugin=et([ee(1,c.Inject(c.Injector)),ee(2,c.IConfigService)],exports.UniverSheetsFilterPlugin);exports.ClearSheetsFilterCriteriaCommand=Be;exports.CustomFilterOperator=T;exports.FILTER_MUTATIONS=q;exports.FilterBy=A;exports.FilterColumn=he;exports.FilterModel=$;exports.ReCalcSheetsFilterCommand=je;exports.ReCalcSheetsFilterMutation=x;exports.RemoveSheetFilterCommand=fe;exports.RemoveSheetsFilterMutation=I;exports.SHEET_FILTER_SNAPSHOT_ID=G;exports.SetSheetFilterRangeCommand=me;exports.SetSheetsFilterCriteriaCommand=De;exports.SetSheetsFilterCriteriaMutation=v;exports.SetSheetsFilterRangeMutation=F;exports.SmartToggleSheetsFilterCommand=Pe;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,8 +1,8 @@
|
|
|
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 { createREGEXFromWildChar as
|
|
5
|
-
import { getSheetCommandTarget as H, SheetsSelectionsService as qe, isSingleCellSelection as Ge, expandToContinuousRange as
|
|
4
|
+
import { createREGEXFromWildChar as ge, isNumeric as Le, Disposable as U, Rectangle as te, mergeSets as K, Tools as se, extractPureTextFromCell as Ue, CellValueType as k, ColorKit as oe, 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 _e, moveMatrixArray as le, IConfigService as Ce, Plugin as Ve, merge as We, touchDependencies as je, Injector as ke } from "@univerjs/core";
|
|
5
|
+
import { getSheetCommandTarget as H, SheetsSelectionsService as qe, isSingleCellSelection as Ge, expandToContinuousRange as re, 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 ae, RemoveRowCommand as ot, RemoveColCommand as lt, InsertColCommand as at, InsertRowCommand as ct, InsertColMutation as Re, RemoveColMutation as pe, MoveColsMutation as Se } 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";
|
|
8
8
|
import { DataSyncPrimaryController as gt } from "@univerjs/rpc";
|
|
@@ -36,7 +36,7 @@ const Rt = {
|
|
|
36
36
|
if (t === " ")
|
|
37
37
|
return i != null;
|
|
38
38
|
const e = Ae(i);
|
|
39
|
-
return e && Ot(t) ? !
|
|
39
|
+
return e && Ot(t) ? !ge(t).test(e) : e !== t;
|
|
40
40
|
}
|
|
41
41
|
return P(i) ? i !== t : !0;
|
|
42
42
|
}
|
|
@@ -50,16 +50,16 @@ function Mt(i) {
|
|
|
50
50
|
const Et = {
|
|
51
51
|
fn: (i, t) => {
|
|
52
52
|
const e = Ae(i);
|
|
53
|
-
return e === null ? t === "" :
|
|
53
|
+
return e === null ? t === "" : ge(t).test(e);
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
-
function
|
|
56
|
+
function ce(i) {
|
|
57
57
|
return i ? ye.get(i) : Et;
|
|
58
58
|
}
|
|
59
59
|
function P(i) {
|
|
60
60
|
return typeof i == "number";
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function de(i) {
|
|
63
63
|
return !!(typeof i == "number" || typeof i == "string" && Le(i));
|
|
64
64
|
}
|
|
65
65
|
function Ae(i) {
|
|
@@ -246,7 +246,7 @@ class yt extends U {
|
|
|
246
246
|
serialize() {
|
|
247
247
|
if (!this._criteria)
|
|
248
248
|
throw new Error("[FilterColumn]: could not serialize without a filter column!");
|
|
249
|
-
return
|
|
249
|
+
return se.deepClone({
|
|
250
250
|
...this._criteria,
|
|
251
251
|
colId: this._column
|
|
252
252
|
});
|
|
@@ -262,7 +262,7 @@ class yt extends U {
|
|
|
262
262
|
this._criteria = e, this._generateFilterFn(), this._filteredOutRows = null;
|
|
263
263
|
}
|
|
264
264
|
getColumnData() {
|
|
265
|
-
return
|
|
265
|
+
return se.deepClone(this._criteria);
|
|
266
266
|
}
|
|
267
267
|
/**
|
|
268
268
|
* Trigger new calculation on this `FilterModel` instance.
|
|
@@ -315,7 +315,7 @@ function Tt(i) {
|
|
|
315
315
|
var n;
|
|
316
316
|
if (!e || !((n = e.bg) != null && n.rgb))
|
|
317
317
|
return !!t.has(null);
|
|
318
|
-
const r = new
|
|
318
|
+
const r = new oe(e.bg.rgb).toRgbString();
|
|
319
319
|
return t.has(r);
|
|
320
320
|
};
|
|
321
321
|
}
|
|
@@ -325,7 +325,7 @@ function Tt(i) {
|
|
|
325
325
|
var n;
|
|
326
326
|
if (!e || !((n = e.cl) != null && n.rgb))
|
|
327
327
|
return !!t.has(mt);
|
|
328
|
-
const r = new
|
|
328
|
+
const r = new oe(e.cl.rgb).toRgbString();
|
|
329
329
|
return t.has(r);
|
|
330
330
|
};
|
|
331
331
|
}
|
|
@@ -348,23 +348,23 @@ function $t(i) {
|
|
|
348
348
|
}
|
|
349
349
|
function Lt(i) {
|
|
350
350
|
const t = i.val;
|
|
351
|
-
if (i.operator === I.NOT_EQUALS && !
|
|
351
|
+
if (i.operator === I.NOT_EQUALS && !de(t))
|
|
352
352
|
return (n) => Oe.fn(n, t);
|
|
353
353
|
if (Mt(i.operator)) {
|
|
354
|
-
if (!
|
|
355
|
-
const n =
|
|
354
|
+
if (!de(t)) return () => !1;
|
|
355
|
+
const n = ce(i.operator), s = Number(t);
|
|
356
356
|
return (o) => n.fn(o, s);
|
|
357
357
|
}
|
|
358
|
-
const e =
|
|
358
|
+
const e = ce(i.operator);
|
|
359
359
|
return (r) => e.fn(r, t);
|
|
360
360
|
}
|
|
361
361
|
function Ut(i, t, e) {
|
|
362
362
|
const r = i.getCell(t, e);
|
|
363
363
|
if (!r) return null;
|
|
364
364
|
const n = i.getCellRaw(t, e);
|
|
365
|
-
return r && !n ?
|
|
365
|
+
return r && !n ? ue(r) : n ? r.t === k.NUMBER && typeof r.v == "string" ? n.v : r.t === k.NUMBER ? Number(n.v) : ue(n) : null;
|
|
366
366
|
}
|
|
367
|
-
function
|
|
367
|
+
function ue(i) {
|
|
368
368
|
var r, n;
|
|
369
369
|
const t = (n = (r = i.p) == null ? void 0 : r.body) == null ? void 0 : n.dataStream;
|
|
370
370
|
if (t) return t.trimEnd();
|
|
@@ -571,7 +571,10 @@ const R = {
|
|
|
571
571
|
return r.executeCommand(zt.id, { unitId: o, subUnitId: l });
|
|
572
572
|
const u = i.get(qe).getCurrentLastSelection();
|
|
573
573
|
if (!u) return !1;
|
|
574
|
-
const d = u.range, h =
|
|
574
|
+
const d = u.range, h = (
|
|
575
|
+
// If the selection is a single cell, we should expand it to a continuous range in all directions.
|
|
576
|
+
Ge(u) ? re(d, { left: !0, right: !0, up: !0, down: !0 }, s) : d.startRow === d.endRow ? re(d, { down: !0 }, s) : d
|
|
577
|
+
);
|
|
575
578
|
return r.executeCommand(Bt.id, {
|
|
576
579
|
unitId: o,
|
|
577
580
|
subUnitId: l,
|
|
@@ -691,7 +694,7 @@ function Wt(i, t, e, r) {
|
|
|
691
694
|
}
|
|
692
695
|
};
|
|
693
696
|
}
|
|
694
|
-
const Ie = "sheets-filter.config",
|
|
697
|
+
const Ie = "sheets-filter.config", he = {};
|
|
695
698
|
function jt(i, t) {
|
|
696
699
|
for (let e = 0; e < i.length; e++) {
|
|
697
700
|
let r = e;
|
|
@@ -712,7 +715,7 @@ var kt = Object.getOwnPropertyDescriptor, qt = (i, t, e, r) => {
|
|
|
712
715
|
let z = class extends U {
|
|
713
716
|
constructor(t, e, r, n, s, o, l) {
|
|
714
717
|
super();
|
|
715
|
-
C(this, "_disposableCollection", new
|
|
718
|
+
C(this, "_disposableCollection", new _e());
|
|
716
719
|
this._commandService = t, this._sheetInterceptorService = e, this._sheetsFilterService = r, this._univerInstanceService = n, this._refRangeService = s, this._dataSyncPrimaryController = o, this._zebraCrossingCacheController = l, this._initCommands(), this._initRowFilteredInterceptor(), this._initInterceptors(), this._commandExecutedListener(), this._initErrorHandling(), this._initZebraCrossingCacheListener();
|
|
717
720
|
}
|
|
718
721
|
_initZebraCrossingCacheListener() {
|
|
@@ -783,14 +786,14 @@ let z = class extends U {
|
|
|
783
786
|
const c = a.params;
|
|
784
787
|
return this._handleRemoveRowCommand(c, t, e);
|
|
785
788
|
}
|
|
786
|
-
case
|
|
789
|
+
case ae.MoveColsCommandId: {
|
|
787
790
|
const c = a.params;
|
|
788
791
|
return this.handleMoveColsCommand({
|
|
789
792
|
fromRange: c.fromRange,
|
|
790
793
|
toRange: c.toRange
|
|
791
794
|
}, t, e);
|
|
792
795
|
}
|
|
793
|
-
case
|
|
796
|
+
case ae.MoveRowsCommandId: {
|
|
794
797
|
const c = a.params;
|
|
795
798
|
return this._handleMoveRowsCommand(c, t, e);
|
|
796
799
|
}
|
|
@@ -995,12 +998,12 @@ let z = class extends U {
|
|
|
995
998
|
colIndex: f,
|
|
996
999
|
filter: s.getFilterColumn(f)
|
|
997
1000
|
};
|
|
998
|
-
|
|
1001
|
+
le(t.startColumn, t.endColumn - t.startColumn + 1, e.startColumn, d);
|
|
999
1002
|
let h = o.startColumn, g = o.endColumn;
|
|
1000
1003
|
l >= t.startColumn && l <= t.endColumn && e.startColumn > t.startColumn && t.endColumn < a && (h = t.endColumn + 1), a >= t.startColumn && a <= t.endColumn && e.startColumn < t.startColumn && t.startColumn > l && (g = t.startColumn - 1);
|
|
1001
1004
|
const _ = Object.keys(d).map((f) => Number(f)), S = _.find((f) => d[f].colIndex === g), w = _.find((f) => d[f].colIndex === h);
|
|
1002
1005
|
if (_.forEach((f) => {
|
|
1003
|
-
var
|
|
1006
|
+
var ne, ie;
|
|
1004
1007
|
const { colIndex: m, filter: v } = d[f], E = f;
|
|
1005
1008
|
if (v) {
|
|
1006
1009
|
if (E >= w && E <= S) {
|
|
@@ -1013,11 +1016,11 @@ let z = class extends U {
|
|
|
1013
1016
|
unitId: r,
|
|
1014
1017
|
subUnitId: n,
|
|
1015
1018
|
col: E,
|
|
1016
|
-
criteria: s.getFilterColumn(E) ? { ...(
|
|
1019
|
+
criteria: s.getFilterColumn(E) ? { ...(ne = s.getFilterColumn(E)) == null ? void 0 : ne.serialize(), colId: E } : null
|
|
1017
1020
|
};
|
|
1018
1021
|
c.push({ id: p.id, params: Z }), u.push({ id: p.id, params: xe });
|
|
1019
1022
|
}
|
|
1020
|
-
if (!((
|
|
1023
|
+
if (!((ie = d[m]) != null && ie.filter)) {
|
|
1021
1024
|
const Z = {
|
|
1022
1025
|
unitId: r,
|
|
1023
1026
|
subUnitId: n,
|
|
@@ -1059,7 +1062,7 @@ let z = class extends U {
|
|
|
1059
1062
|
};
|
|
1060
1063
|
const g = o;
|
|
1061
1064
|
let _ = l;
|
|
1062
|
-
l >= a.startRow && l <= a.endRow && c.startRow < a.startRow && a.startRow > o && (_ = a.startRow - 1),
|
|
1065
|
+
l >= a.startRow && l <= a.endRow && c.startRow < a.startRow && a.startRow > o && (_ = a.startRow - 1), le(a.startRow, a.endRow - a.startRow + 1, c.startRow, h);
|
|
1063
1066
|
const S = Object.keys(h).map((m) => Number(m)), w = S.find((m) => h[m].oldIndex === _), F = S.find((m) => h[m].oldIndex === g);
|
|
1064
1067
|
if (o !== F || l !== w) {
|
|
1065
1068
|
const m = {
|
|
@@ -1250,7 +1253,7 @@ let z = class extends U {
|
|
|
1250
1253
|
if (_ && this._cellHasValue(_)) {
|
|
1251
1254
|
const S = (u = this._univerInstanceService.getUnit(r)) == null ? void 0 : u.getSheetBySheetId(n);
|
|
1252
1255
|
if (S) {
|
|
1253
|
-
const w =
|
|
1256
|
+
const w = re(d, { down: !0 }, S), F = this._sheetsFilterService.getFilterModel(r, n), f = F.getRange();
|
|
1254
1257
|
F.setRange({
|
|
1255
1258
|
...f,
|
|
1256
1259
|
endRow: w.endRow
|
|
@@ -1326,7 +1329,7 @@ let G = class extends U {
|
|
|
1326
1329
|
constructor(t, e, r) {
|
|
1327
1330
|
var s;
|
|
1328
1331
|
super();
|
|
1329
|
-
C(this, "_d", new
|
|
1332
|
+
C(this, "_d", new _e());
|
|
1330
1333
|
C(this, "_visible$", new $(!1));
|
|
1331
1334
|
C(this, "visible$", this._visible$.asObservable());
|
|
1332
1335
|
C(this, "_enabled$", new $(!0));
|
|
@@ -1370,7 +1373,7 @@ let G = class extends U {
|
|
|
1370
1373
|
G = Qt([
|
|
1371
1374
|
ee(0, A(z)),
|
|
1372
1375
|
ee(1, N),
|
|
1373
|
-
ee(2,
|
|
1376
|
+
ee(2, Ce)
|
|
1374
1377
|
], G);
|
|
1375
1378
|
var Kt = Object.getOwnPropertyDescriptor, Yt = (i, t, e, r) => {
|
|
1376
1379
|
for (var n = r > 1 ? void 0 : r ? Kt(t, e) : t, s = i.length - 1, o; s >= 0; s--)
|
|
@@ -1436,13 +1439,13 @@ var Xt = Object.getOwnPropertyDescriptor, er = (i, t, e, r) => {
|
|
|
1436
1439
|
for (var n = r > 1 ? void 0 : r ? Xt(t, e) : t, s = i.length - 1, o; s >= 0; s--)
|
|
1437
1440
|
(o = i[s]) && (n = o(n) || n);
|
|
1438
1441
|
return n;
|
|
1439
|
-
},
|
|
1440
|
-
let
|
|
1441
|
-
constructor(i =
|
|
1442
|
+
}, fe = (i, t) => (e, r) => t(e, r, i), W;
|
|
1443
|
+
let me = (W = class extends Ve {
|
|
1444
|
+
constructor(i = he, t, e) {
|
|
1442
1445
|
super(), this._config = i, this._injector = t, this._configService = e;
|
|
1443
1446
|
const { ...r } = We(
|
|
1444
1447
|
{},
|
|
1445
|
-
|
|
1448
|
+
he,
|
|
1446
1449
|
this._config
|
|
1447
1450
|
);
|
|
1448
1451
|
this._configService.setConfig(Ie, r);
|
|
@@ -1463,10 +1466,10 @@ let fe = (W = class extends Ve {
|
|
|
1463
1466
|
]);
|
|
1464
1467
|
}
|
|
1465
1468
|
}, C(W, "type", D.UNIVER_SHEET), C(W, "pluginName", Ne), W);
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
],
|
|
1469
|
+
me = er([
|
|
1470
|
+
fe(1, A(ke)),
|
|
1471
|
+
fe(2, Ce)
|
|
1472
|
+
], me);
|
|
1470
1473
|
export {
|
|
1471
1474
|
dr as ClearSheetsFilterCriteriaCommand,
|
|
1472
1475
|
I as CustomFilterOperator,
|
|
@@ -1486,9 +1489,9 @@ export {
|
|
|
1486
1489
|
M as SheetsFilterService,
|
|
1487
1490
|
G as SheetsFilterSyncController,
|
|
1488
1491
|
ar as SmartToggleSheetsFilterCommand,
|
|
1489
|
-
|
|
1492
|
+
me as UniverSheetsFilterPlugin,
|
|
1490
1493
|
wt as equals,
|
|
1491
|
-
|
|
1494
|
+
ce as getCustomFilterFn,
|
|
1492
1495
|
Rt as greaterThan,
|
|
1493
1496
|
pt as greaterThanOrEqualTo,
|
|
1494
1497
|
St as lessThan,
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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 { createREGEXFromWildChar as
|
|
5
|
-
import { getSheetCommandTarget as H, SheetsSelectionsService as qe, isSingleCellSelection as Ge, expandToContinuousRange as
|
|
4
|
+
import { createREGEXFromWildChar as ge, isNumeric as Le, Disposable as U, Rectangle as te, mergeSets as K, Tools as se, extractPureTextFromCell as Ue, CellValueType as k, ColorKit as oe, 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 _e, moveMatrixArray as le, IConfigService as Ce, Plugin as Ve, merge as We, touchDependencies as je, Injector as ke } from "@univerjs/core";
|
|
5
|
+
import { getSheetCommandTarget as H, SheetsSelectionsService as qe, isSingleCellSelection as Ge, expandToContinuousRange as re, 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 ae, RemoveRowCommand as ot, RemoveColCommand as lt, InsertColCommand as at, InsertRowCommand as ct, InsertColMutation as Re, RemoveColMutation as pe, MoveColsMutation as Se } 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";
|
|
8
8
|
import { DataSyncPrimaryController as gt } from "@univerjs/rpc";
|
|
@@ -36,7 +36,7 @@ const Rt = {
|
|
|
36
36
|
if (t === " ")
|
|
37
37
|
return i != null;
|
|
38
38
|
const e = Ae(i);
|
|
39
|
-
return e && Ot(t) ? !
|
|
39
|
+
return e && Ot(t) ? !ge(t).test(e) : e !== t;
|
|
40
40
|
}
|
|
41
41
|
return P(i) ? i !== t : !0;
|
|
42
42
|
}
|
|
@@ -50,16 +50,16 @@ function Mt(i) {
|
|
|
50
50
|
const Et = {
|
|
51
51
|
fn: (i, t) => {
|
|
52
52
|
const e = Ae(i);
|
|
53
|
-
return e === null ? t === "" :
|
|
53
|
+
return e === null ? t === "" : ge(t).test(e);
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
-
function
|
|
56
|
+
function ce(i) {
|
|
57
57
|
return i ? ye.get(i) : Et;
|
|
58
58
|
}
|
|
59
59
|
function P(i) {
|
|
60
60
|
return typeof i == "number";
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function de(i) {
|
|
63
63
|
return !!(typeof i == "number" || typeof i == "string" && Le(i));
|
|
64
64
|
}
|
|
65
65
|
function Ae(i) {
|
|
@@ -246,7 +246,7 @@ class yt extends U {
|
|
|
246
246
|
serialize() {
|
|
247
247
|
if (!this._criteria)
|
|
248
248
|
throw new Error("[FilterColumn]: could not serialize without a filter column!");
|
|
249
|
-
return
|
|
249
|
+
return se.deepClone({
|
|
250
250
|
...this._criteria,
|
|
251
251
|
colId: this._column
|
|
252
252
|
});
|
|
@@ -262,7 +262,7 @@ class yt extends U {
|
|
|
262
262
|
this._criteria = e, this._generateFilterFn(), this._filteredOutRows = null;
|
|
263
263
|
}
|
|
264
264
|
getColumnData() {
|
|
265
|
-
return
|
|
265
|
+
return se.deepClone(this._criteria);
|
|
266
266
|
}
|
|
267
267
|
/**
|
|
268
268
|
* Trigger new calculation on this `FilterModel` instance.
|
|
@@ -315,7 +315,7 @@ function Tt(i) {
|
|
|
315
315
|
var n;
|
|
316
316
|
if (!e || !((n = e.bg) != null && n.rgb))
|
|
317
317
|
return !!t.has(null);
|
|
318
|
-
const r = new
|
|
318
|
+
const r = new oe(e.bg.rgb).toRgbString();
|
|
319
319
|
return t.has(r);
|
|
320
320
|
};
|
|
321
321
|
}
|
|
@@ -325,7 +325,7 @@ function Tt(i) {
|
|
|
325
325
|
var n;
|
|
326
326
|
if (!e || !((n = e.cl) != null && n.rgb))
|
|
327
327
|
return !!t.has(mt);
|
|
328
|
-
const r = new
|
|
328
|
+
const r = new oe(e.cl.rgb).toRgbString();
|
|
329
329
|
return t.has(r);
|
|
330
330
|
};
|
|
331
331
|
}
|
|
@@ -348,23 +348,23 @@ function $t(i) {
|
|
|
348
348
|
}
|
|
349
349
|
function Lt(i) {
|
|
350
350
|
const t = i.val;
|
|
351
|
-
if (i.operator === I.NOT_EQUALS && !
|
|
351
|
+
if (i.operator === I.NOT_EQUALS && !de(t))
|
|
352
352
|
return (n) => Oe.fn(n, t);
|
|
353
353
|
if (Mt(i.operator)) {
|
|
354
|
-
if (!
|
|
355
|
-
const n =
|
|
354
|
+
if (!de(t)) return () => !1;
|
|
355
|
+
const n = ce(i.operator), s = Number(t);
|
|
356
356
|
return (o) => n.fn(o, s);
|
|
357
357
|
}
|
|
358
|
-
const e =
|
|
358
|
+
const e = ce(i.operator);
|
|
359
359
|
return (r) => e.fn(r, t);
|
|
360
360
|
}
|
|
361
361
|
function Ut(i, t, e) {
|
|
362
362
|
const r = i.getCell(t, e);
|
|
363
363
|
if (!r) return null;
|
|
364
364
|
const n = i.getCellRaw(t, e);
|
|
365
|
-
return r && !n ?
|
|
365
|
+
return r && !n ? ue(r) : n ? r.t === k.NUMBER && typeof r.v == "string" ? n.v : r.t === k.NUMBER ? Number(n.v) : ue(n) : null;
|
|
366
366
|
}
|
|
367
|
-
function
|
|
367
|
+
function ue(i) {
|
|
368
368
|
var r, n;
|
|
369
369
|
const t = (n = (r = i.p) == null ? void 0 : r.body) == null ? void 0 : n.dataStream;
|
|
370
370
|
if (t) return t.trimEnd();
|
|
@@ -571,7 +571,10 @@ const R = {
|
|
|
571
571
|
return r.executeCommand(zt.id, { unitId: o, subUnitId: l });
|
|
572
572
|
const u = i.get(qe).getCurrentLastSelection();
|
|
573
573
|
if (!u) return !1;
|
|
574
|
-
const d = u.range, h =
|
|
574
|
+
const d = u.range, h = (
|
|
575
|
+
// If the selection is a single cell, we should expand it to a continuous range in all directions.
|
|
576
|
+
Ge(u) ? re(d, { left: !0, right: !0, up: !0, down: !0 }, s) : d.startRow === d.endRow ? re(d, { down: !0 }, s) : d
|
|
577
|
+
);
|
|
575
578
|
return r.executeCommand(Bt.id, {
|
|
576
579
|
unitId: o,
|
|
577
580
|
subUnitId: l,
|
|
@@ -691,7 +694,7 @@ function Wt(i, t, e, r) {
|
|
|
691
694
|
}
|
|
692
695
|
};
|
|
693
696
|
}
|
|
694
|
-
const Ie = "sheets-filter.config",
|
|
697
|
+
const Ie = "sheets-filter.config", he = {};
|
|
695
698
|
function jt(i, t) {
|
|
696
699
|
for (let e = 0; e < i.length; e++) {
|
|
697
700
|
let r = e;
|
|
@@ -712,7 +715,7 @@ var kt = Object.getOwnPropertyDescriptor, qt = (i, t, e, r) => {
|
|
|
712
715
|
let z = class extends U {
|
|
713
716
|
constructor(t, e, r, n, s, o, l) {
|
|
714
717
|
super();
|
|
715
|
-
C(this, "_disposableCollection", new
|
|
718
|
+
C(this, "_disposableCollection", new _e());
|
|
716
719
|
this._commandService = t, this._sheetInterceptorService = e, this._sheetsFilterService = r, this._univerInstanceService = n, this._refRangeService = s, this._dataSyncPrimaryController = o, this._zebraCrossingCacheController = l, this._initCommands(), this._initRowFilteredInterceptor(), this._initInterceptors(), this._commandExecutedListener(), this._initErrorHandling(), this._initZebraCrossingCacheListener();
|
|
717
720
|
}
|
|
718
721
|
_initZebraCrossingCacheListener() {
|
|
@@ -783,14 +786,14 @@ let z = class extends U {
|
|
|
783
786
|
const c = a.params;
|
|
784
787
|
return this._handleRemoveRowCommand(c, t, e);
|
|
785
788
|
}
|
|
786
|
-
case
|
|
789
|
+
case ae.MoveColsCommandId: {
|
|
787
790
|
const c = a.params;
|
|
788
791
|
return this.handleMoveColsCommand({
|
|
789
792
|
fromRange: c.fromRange,
|
|
790
793
|
toRange: c.toRange
|
|
791
794
|
}, t, e);
|
|
792
795
|
}
|
|
793
|
-
case
|
|
796
|
+
case ae.MoveRowsCommandId: {
|
|
794
797
|
const c = a.params;
|
|
795
798
|
return this._handleMoveRowsCommand(c, t, e);
|
|
796
799
|
}
|
|
@@ -995,12 +998,12 @@ let z = class extends U {
|
|
|
995
998
|
colIndex: f,
|
|
996
999
|
filter: s.getFilterColumn(f)
|
|
997
1000
|
};
|
|
998
|
-
|
|
1001
|
+
le(t.startColumn, t.endColumn - t.startColumn + 1, e.startColumn, d);
|
|
999
1002
|
let h = o.startColumn, g = o.endColumn;
|
|
1000
1003
|
l >= t.startColumn && l <= t.endColumn && e.startColumn > t.startColumn && t.endColumn < a && (h = t.endColumn + 1), a >= t.startColumn && a <= t.endColumn && e.startColumn < t.startColumn && t.startColumn > l && (g = t.startColumn - 1);
|
|
1001
1004
|
const _ = Object.keys(d).map((f) => Number(f)), S = _.find((f) => d[f].colIndex === g), w = _.find((f) => d[f].colIndex === h);
|
|
1002
1005
|
if (_.forEach((f) => {
|
|
1003
|
-
var
|
|
1006
|
+
var ne, ie;
|
|
1004
1007
|
const { colIndex: m, filter: v } = d[f], E = f;
|
|
1005
1008
|
if (v) {
|
|
1006
1009
|
if (E >= w && E <= S) {
|
|
@@ -1013,11 +1016,11 @@ let z = class extends U {
|
|
|
1013
1016
|
unitId: r,
|
|
1014
1017
|
subUnitId: n,
|
|
1015
1018
|
col: E,
|
|
1016
|
-
criteria: s.getFilterColumn(E) ? { ...(
|
|
1019
|
+
criteria: s.getFilterColumn(E) ? { ...(ne = s.getFilterColumn(E)) == null ? void 0 : ne.serialize(), colId: E } : null
|
|
1017
1020
|
};
|
|
1018
1021
|
c.push({ id: p.id, params: Z }), u.push({ id: p.id, params: xe });
|
|
1019
1022
|
}
|
|
1020
|
-
if (!((
|
|
1023
|
+
if (!((ie = d[m]) != null && ie.filter)) {
|
|
1021
1024
|
const Z = {
|
|
1022
1025
|
unitId: r,
|
|
1023
1026
|
subUnitId: n,
|
|
@@ -1059,7 +1062,7 @@ let z = class extends U {
|
|
|
1059
1062
|
};
|
|
1060
1063
|
const g = o;
|
|
1061
1064
|
let _ = l;
|
|
1062
|
-
l >= a.startRow && l <= a.endRow && c.startRow < a.startRow && a.startRow > o && (_ = a.startRow - 1),
|
|
1065
|
+
l >= a.startRow && l <= a.endRow && c.startRow < a.startRow && a.startRow > o && (_ = a.startRow - 1), le(a.startRow, a.endRow - a.startRow + 1, c.startRow, h);
|
|
1063
1066
|
const S = Object.keys(h).map((m) => Number(m)), w = S.find((m) => h[m].oldIndex === _), F = S.find((m) => h[m].oldIndex === g);
|
|
1064
1067
|
if (o !== F || l !== w) {
|
|
1065
1068
|
const m = {
|
|
@@ -1250,7 +1253,7 @@ let z = class extends U {
|
|
|
1250
1253
|
if (_ && this._cellHasValue(_)) {
|
|
1251
1254
|
const S = (u = this._univerInstanceService.getUnit(r)) == null ? void 0 : u.getSheetBySheetId(n);
|
|
1252
1255
|
if (S) {
|
|
1253
|
-
const w =
|
|
1256
|
+
const w = re(d, { down: !0 }, S), F = this._sheetsFilterService.getFilterModel(r, n), f = F.getRange();
|
|
1254
1257
|
F.setRange({
|
|
1255
1258
|
...f,
|
|
1256
1259
|
endRow: w.endRow
|
|
@@ -1326,7 +1329,7 @@ let G = class extends U {
|
|
|
1326
1329
|
constructor(t, e, r) {
|
|
1327
1330
|
var s;
|
|
1328
1331
|
super();
|
|
1329
|
-
C(this, "_d", new
|
|
1332
|
+
C(this, "_d", new _e());
|
|
1330
1333
|
C(this, "_visible$", new $(!1));
|
|
1331
1334
|
C(this, "visible$", this._visible$.asObservable());
|
|
1332
1335
|
C(this, "_enabled$", new $(!0));
|
|
@@ -1370,7 +1373,7 @@ let G = class extends U {
|
|
|
1370
1373
|
G = Qt([
|
|
1371
1374
|
ee(0, A(z)),
|
|
1372
1375
|
ee(1, N),
|
|
1373
|
-
ee(2,
|
|
1376
|
+
ee(2, Ce)
|
|
1374
1377
|
], G);
|
|
1375
1378
|
var Kt = Object.getOwnPropertyDescriptor, Yt = (i, t, e, r) => {
|
|
1376
1379
|
for (var n = r > 1 ? void 0 : r ? Kt(t, e) : t, s = i.length - 1, o; s >= 0; s--)
|
|
@@ -1436,13 +1439,13 @@ var Xt = Object.getOwnPropertyDescriptor, er = (i, t, e, r) => {
|
|
|
1436
1439
|
for (var n = r > 1 ? void 0 : r ? Xt(t, e) : t, s = i.length - 1, o; s >= 0; s--)
|
|
1437
1440
|
(o = i[s]) && (n = o(n) || n);
|
|
1438
1441
|
return n;
|
|
1439
|
-
},
|
|
1440
|
-
let
|
|
1441
|
-
constructor(i =
|
|
1442
|
+
}, fe = (i, t) => (e, r) => t(e, r, i), W;
|
|
1443
|
+
let me = (W = class extends Ve {
|
|
1444
|
+
constructor(i = he, t, e) {
|
|
1442
1445
|
super(), this._config = i, this._injector = t, this._configService = e;
|
|
1443
1446
|
const { ...r } = We(
|
|
1444
1447
|
{},
|
|
1445
|
-
|
|
1448
|
+
he,
|
|
1446
1449
|
this._config
|
|
1447
1450
|
);
|
|
1448
1451
|
this._configService.setConfig(Ie, r);
|
|
@@ -1463,10 +1466,10 @@ let fe = (W = class extends Ve {
|
|
|
1463
1466
|
]);
|
|
1464
1467
|
}
|
|
1465
1468
|
}, C(W, "type", D.UNIVER_SHEET), C(W, "pluginName", Ne), W);
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
],
|
|
1469
|
+
me = er([
|
|
1470
|
+
fe(1, A(ke)),
|
|
1471
|
+
fe(2, Ce)
|
|
1472
|
+
], me);
|
|
1470
1473
|
export {
|
|
1471
1474
|
dr as ClearSheetsFilterCriteriaCommand,
|
|
1472
1475
|
I as CustomFilterOperator,
|
|
@@ -1486,9 +1489,9 @@ export {
|
|
|
1486
1489
|
M as SheetsFilterService,
|
|
1487
1490
|
G as SheetsFilterSyncController,
|
|
1488
1491
|
ar as SmartToggleSheetsFilterCommand,
|
|
1489
|
-
|
|
1492
|
+
me as UniverSheetsFilterPlugin,
|
|
1490
1493
|
wt as equals,
|
|
1491
|
-
|
|
1494
|
+
ce as getCustomFilterFn,
|
|
1492
1495
|
Rt as greaterThan,
|
|
1493
1496
|
pt as greaterThanOrEqualTo,
|
|
1494
1497
|
St as lessThan,
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(h,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-render"),require("@univerjs/rpc"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-render","@univerjs/rpc","@univerjs/engine-formula"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.UniverSheetsFilter={},h.UniverCore,h.UniverSheets,h.rxjs,h.UniverEngineRender,h.UniverRpc,h.UniverEngineFormula))})(this,(function(h,a,_,I,Se,Re,J){"use strict";var Ye=Object.defineProperty;var et=(h,a,_)=>a in h?Ye(h,a,{enumerable:!0,configurable:!0,writable:!0,value:_}):h[a]=_;var v=(h,a,_)=>et(h,typeof a!="symbol"?a+"":a,_);var x;const K="sheet.mutation.set-filter-range",Z="sheet.mutation.set-filter-criteria",X="sheet.mutation.remove-filter",Y="sheet.mutation.re-calc-filter",H=new Set([K,Z,X,Y]);var N=(i=>(i[i.VALUES=0]="VALUES",i[i.COLORS=1]="COLORS",i[i.CONDITIONS=2]="CONDITIONS",i))(N||{}),A=(i=>(i.EQUAL="equal",i.GREATER_THAN="greaterThan",i.GREATER_THAN_OR_EQUAL="greaterThanOrEqual",i.LESS_THAN="lessThan",i.LESS_THAN_OR_EQUAL="lessThanOrEqual",i.NOT_EQUALS="notEqual",i))(A||{});const ee={operator:A.GREATER_THAN,fn:(i,n)=>U(i)?i>n:!1},te={operator:A.GREATER_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i>=n:!1},re={operator:A.LESS_THAN,fn:(i,n)=>U(i)?i<n:!1},ne={operator:A.LESS_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i<=n:!1},ie={operator:A.EQUAL,fn:(i,n)=>U(i)?i===n:!1},z={operator:A.NOT_EQUALS,fn:(i,n)=>{if(typeof n=="string"){if(n===" ")return i!=null;const e=le(i);return e&&pe(n)?!a.createREGEXFromWildChar(n).test(e):e!==n}return U(i)?i!==n:!0}},se=new Map([]);[ee,te,re,ne,ie,z].forEach(i=>{se.set(i.operator,i)});function ve(i){return!!i}const Fe={fn:(i,n)=>{const e=le(i);return e===null?n==="":a.createREGEXFromWildChar(n).test(e)}};function V(i){return i?se.get(i):Fe}function U(i){return typeof i=="number"}function oe(i){return!!(typeof i=="number"||typeof i=="string"&&a.isNumeric(i))}function le(i){return typeof i=="boolean"||i==null?null:typeof i=="string"?i:i.toString()}function pe(i){return typeof i=="number"?!1:i.indexOf("*")!==-1||i.indexOf("?")!==-1}const W=()=>new Set;class P extends a.Disposable{constructor(e,t,r){super();v(this,"_filteredOutRows$",new I.BehaviorSubject(W()));v(this,"filteredOutRows$",this._filteredOutRows$.asObservable());v(this,"_hasCriteria$",new I.BehaviorSubject(!1));v(this,"hasCriteria$",this._hasCriteria$.asObservable());v(this,"_filterColumnByIndex",new Map);v(this,"_alreadyFilteredOutRows",W());v(this,"_range");this.unitId=e,this.subUnitId=t,this._worksheet=r}get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete(),this._worksheet=null}serialize(){const e={ref:a.Rectangle.clone(this._range),filterColumns:this._getAllFilterColumns(!0).sort(([t],[r])=>t-r).map(([t,r])=>r.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(e,t,r,s){const o=new P(e,t,r);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.filter(r=>!(!r.filters&&!r.colorFilters&&!r.customFilters)).forEach(r=>this._setCriteriaWithoutReCalc(r.colId,r)),e.cachedFilteredOut?(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()):e.filterColumns&&e.filterColumns.length>0&&(this._reCalcAllColumns(),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw new Error("[FilterModel] could not get range before a range is set!");return this._range}getFilteredOutRowsExceptCol(e){return this._getAllFilterColumns(!0).filter(([t])=>t!==e).reduce((t,[,r])=>{const s=r.calc({getAlreadyFilteredOutRows:()=>t});return s?a.mergeSets(t,s):t},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,r])=>{r.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,r=!1){if(!this._range)throw new Error("[FilterModel] could not set criteria before a range is set!");if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),r&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),r&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._getAllFilterColumns().forEach(s=>s.__clearCache()),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))!=null?t:null}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){const t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([r,s])=>s)}_reCalcAllColumns(){this._alreadyFilteredOutRows=W(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns()}_setCriteriaWithoutReCalc(e,t){const r=this._range;if(!r)throw new Error("[FilterModel] could not set criteria before a range is set!");const{startColumn:s,endColumn:o}=r;if(e>o||e<s)throw new Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);let l;this._filterColumnByIndex.has(e)?l=this._filterColumnByIndex.get(e):(l=new ae(this.unitId,this.subUnitId,this._worksheet,t,{getAlreadyFilteredOutRows:()=>this._alreadyFilteredOutRows}),l.setRangeAndColumn(r,e),this._filterColumnByIndex.set(e,l)),l.setCriteria(t)}_removeCriteria(e){const t=this._filterColumnByIndex.get(e);t&&(t.dispose(),this._filterColumnByIndex.delete(e))}_emit(){this._filteredOutRows$.next(this._alreadyFilteredOutRows)}_emitHasCriteria(){this._hasCriteria$.next(this._filterColumnByIndex.size>0)}_rebuildAlreadyFilteredOutRowsWithCache(){const e=this._getAllFilterColumns().filter(t=>t.hasCache()).reduce((t,r)=>a.mergeSets(t,r.filteredOutRows),new Set);this._alreadyFilteredOutRows=e}_reCalcWithNoCacheColumns(){const e=this._getAllFilterColumns().filter(t=>!t.hasCache());for(const t of e){const r=t.reCalc();r&&(this._alreadyFilteredOutRows=a.mergeSets(this._alreadyFilteredOutRows,r))}}}class ae extends a.Disposable{constructor(e,t,r,s,o){super();v(this,"_filteredOutRows",null);v(this,"_filterFn",null);v(this,"_range",null);v(this,"_column",0);v(this,"_filterBy",N.VALUES);this.unitId=e,this.subUnitId=t,this._worksheet=r,this._criteria=s,this._filterColumnContext=o}get filteredOutRows(){return this._filteredOutRows}get filterBy(){return this._filterBy}dispose(){super.dispose(),this._filteredOutRows=null}__clearCache(){this._filteredOutRows=null}serialize(){if(!this._criteria)throw new Error("[FilterColumn]: could not serialize without a filter column!");return a.Tools.deepClone({...this._criteria,colId:this._column})}hasCache(){return this._filteredOutRows!==null}setRangeAndColumn(e,t){this._range=e,this._column=t}setCriteria(e){this._criteria=e,this._generateFilterFn(),this._filteredOutRows=null}getColumnData(){return a.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw new Error("[FilterColumn] cannot calculate without a filter fn!");if(!this._range)throw new Error("[FilterColumn] cannot calculate without a range!");if(typeof this._column!="number")throw new TypeError("[FilterColumn] cannot calculate without a column offset!");const t=this._column,r={startColumn:t,endColumn:t,startRow:this._range.startRow+1,endRow:this._range.endRow},s=new Set,o=e.getAlreadyFilteredOutRows();for(const l of this._worksheet.iterateByColumn(r,!1,!1)){const{row:c,rowSpan:d,col:m}=l;if(o.has(c)&&(!d||d===1))continue;if(!(this._filterBy===N.VALUES?this._filterFn(a.extractPureTextFromCell(this._worksheet.getCell(c,m))):this._filterBy===N.COLORS?this._filterFn(this._worksheet.getComposedCellStyle(c,m)):this._filterFn(Ne(this._worksheet,c,m)))&&(s.add(c),d))for(let f=1;f<d;f++)s.add(c+f)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=we(this._criteria),this._filterBy=this._criteria.filters?N.VALUES:this._criteria.colorFilters?N.COLORS:N.CONDITIONS)}}function we(i){if(i.filters)return Me(i.filters);if(i.colorFilters)return Ee(i.colorFilters);if(i.customFilters)return ye(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function Me(i){const n=!!i.blank,e=new Set(i.filters);return t=>t===void 0||t===""?n:e.has(typeof t=="string"?t:`${t}`)}function Ee(i){if(i.cellFillColors){const n=new Set(i.cellFillColors);return e=>{var r;if(!e||!((r=e.bg)!=null&&r.rgb))return!!n.has(null);const t=new a.ColorKit(e.bg.rgb).toRgbString();return n.has(t)}}if(i.cellTextColors){const n=new Set(i.cellTextColors);return e=>{var r;if(!e||!((r=e.cl)!=null&&r.rgb))return!!n.has(Se.COLOR_BLACK_RGB);const t=new a.ColorKit(e.cl.rgb).toRgbString();return n.has(t)}}throw new Error("[FilterModel]: color filters are not supported yet.")}function ye(i){const n=i.customFilters.map(e=>Ae(e));return Te(n)?i.and?Oe(n):Ie(n):n[0]}function Oe(i){const[n,e]=i;return t=>n(t)&&e(t)}function Ie(i){const[n,e]=i;return t=>n(t)||e(t)}function Te(i){return i.length===2}function Ae(i){const n=i.val;if(i.operator===A.NOT_EQUALS&&!oe(n))return r=>z.fn(r,n);if(ve(i.operator)){if(!oe(n))return()=>!1;const r=V(i.operator),s=Number(n);return o=>r.fn(o,s)}const e=V(i.operator);return t=>e.fn(t,n)}function Ne(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?ce(t):r?t.t===a.CellValueType.NUMBER&&typeof t.v=="string"?r.v:t.t===a.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===a.CellValueType.BOOLEAN?e.toUpperCase():e:typeof e=="number"?i.t===a.CellValueType.BOOLEAN?e?"TRUE":"FALSE":e:typeof e=="boolean"?e?"TRUE":"FALSE":""}var be=Object.getOwnPropertyDescriptor,Ue=(i,n,e,t)=>{for(var r=t>1?void 0:t?be(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},q=(i,n)=>(e,t)=>n(e,t,i);const k="SHEET_FILTER_PLUGIN";h.SheetsFilterService=class extends a.Disposable{constructor(e,t,r){super();v(this,"_filterModels",new Map);v(this,"_loadedUnitId$",new I.BehaviorSubject(null));v(this,"loadedUnitId$",this._loadedUnitId$.asObservable());v(this,"_errorMsg$",new I.BehaviorSubject(null));v(this,"errorMsg$",this._errorMsg$.asObservable());v(this,"_activeFilterModel$",new I.BehaviorSubject(null));v(this,"activeFilterModel$",this._activeFilterModel$.asObservable());this._resourcesManagerService=e,this._univerInstanceService=t,this._commandService=r,this._initModel(),this._initActiveFilterModel()}get activeFilterModel(){return this._activeFilterModel$.getValue()}ensureFilterModel(e,t){const r=this.getFilterModel(e,t);if(r)return r;const s=this._univerInstanceService.getUniverSheetInstance(e);if(!s)throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${e}!`);const o=s.getSheetBySheetId(t);if(!o)throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${t}!`);const l=new P(e,t,o);return this._cacheFilterModel(e,t,l),l}getFilterModel(e,t){var r,s;return(s=(r=this._filterModels.get(e))==null?void 0:r.get(t))!=null?s:null}removeFilterModel(e,t){const r=this.getFilterModel(e,t);return r?(r.dispose(),this._filterModels.get(e).delete(t),!0):!1}setFilterErrorMsg(e){this._errorMsg$.next(e)}_updateActiveFilterModel(){let e;try{if(e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),!e){this._activeFilterModel$.next(null);return}}catch(l){console.error("[SheetsFilterService]: could not get active workbook!",l);return}const t=e.getActiveSheet(!0);if(!t){this._activeFilterModel$.next(null);return}const r=t.getUnitId(),s=t.getSheetId(),o=this.getFilterModel(r,s);this._activeFilterModel$.next(o)}_initActiveFilterModel(){this.disposeWithMe(I.merge(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([e])=>e.type===a.CommandType.MUTATION&&H.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(e=>{var t;return(t=e==null?void 0:e.activeSheet$)!=null?t:I.of(null)}))).subscribe(()=>this._updateActiveFilterModel()))}_serializeAutoFiltersForUnit(e){const t=this._filterModels.get(e);if(!t)return"{}";const r={};return t.forEach((s,o)=>{r[o]=s.serialize()}),JSON.stringify(r)}_deserializeAutoFiltersForUnit(e,t){const r=this._univerInstanceService.getUniverSheetInstance(e);Object.keys(t).forEach(s=>{const o=t[s],l=P.deserialize(e,s,r.getSheetBySheetId(s),o);this._cacheFilterModel(e,s,l)})}dispose(){super.dispose(),this._loadedUnitId$.complete(),this._errorMsg$.complete(),this._activeFilterModel$.complete(),this._filterModels.forEach(e=>{e.forEach(t=>t.dispose()),e.clear()}),this._filterModels.clear()}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:k,businesses:[a.UniverInstanceType.UNIVER_SHEET],toJson:e=>this._serializeAutoFiltersForUnit(e),parseJson:e=>JSON.parse(e),onLoad:(e,t)=>{this._deserializeAutoFiltersForUnit(e,t),this._loadedUnitId$.next(e),this._updateActiveFilterModel()},onUnLoad:e=>{const t=this._filterModels.get(e);t&&(t.forEach(r=>r.dispose()),this._filterModels.delete(e))}})}_cacheFilterModel(e,t,r){this._filterModels.has(e)||this._filterModels.set(e,new Map),this._filterModels.get(e).set(t,r)}},h.SheetsFilterService=Ue([q(0,a.IResourceManagerService),q(1,a.IUniverInstanceService),q(2,a.ICommandService)],h.SheetsFilterService);const F={id:K,type:a.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,range:r}=n;return i.get(h.SheetsFilterService).ensureFilterModel(t,e).setRange(r),!0}},p={id:Z,type:a.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,criteria:r,col:s,reCalc:o=!0}=n,c=i.get(h.SheetsFilterService).getFilterModel(t,e);return c?(c.setCriteria(s,r,o),!0):!1}},T={id:X,type:a.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(h.SheetsFilterService).removeFilterModel(e,t)}},$={id:Y,type:a.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n,s=i.get(h.SheetsFilterService).getFilterModel(e,t);return s?(s.reCalc(),!0):!1}},de={id:"sheet.command.set-filter-range",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUndoRedoService),s=i.get(a.IUniverInstanceService),{unitId:o,subUnitId:l,range:c}=n;if(!_.getSheetCommandTarget(s,n)||e.getFilterModel(o,l))return!1;if(c.endRow===c.startRow){const S=i.get(a.ErrorService),R=i.get(a.LocaleService);return S.emit(R.t("sheets-filter.command.not-valid-filter-range")),!1}const u={id:F.id,params:{unitId:o,subUnitId:l,range:c}},f=t.syncExecuteCommand(u.id,u.params);return f&&r.pushUndoRedo({unitID:o,undoMutations:[{id:T.id,params:{unitId:o,subUnitId:l}}],redoMutations:[u]}),f}},ue={id:"sheet.command.remove-sheet-filter",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(a.IUniverInstanceService),t=i.get(h.SheetsFilterService),r=i.get(a.ICommandService),s=i.get(a.IUndoRedoService),o=_.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:c}=o,d=t.getFilterModel(l,c);if(!d)return!1;const m=d==null?void 0:d.serialize(),u=Be(l,c,m),f=r.syncExecuteCommand(T.id,{unitId:l,subUnitId:c});return f&&s.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:[{id:T.id,params:{unitId:l,subUnitId:c}}]}),f}},$e={id:"sheet.command.smart-toggle-filter",type:a.CommandType.COMMAND,handler:async i=>{const n=i.get(a.IUniverInstanceService),e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=r==null?void 0:r.getActiveSheet();if(!s||!r)return!1;const o=r.getUnitId(),l=s.getSheetId();if(e.getFilterModel(o,l))return t.executeCommand(ue.id,{unitId:o,subUnitId:l});const m=i.get(_.SheetsSelectionsService).getCurrentLastSelection();if(!m)return!1;const u=m.range,f=_.isSingleCellSelection(m)?_.expandToContinuousRange(u,{left:!0,right:!0,up:!0,down:!0},s):u;return t.executeCommand(de.id,{unitId:o,subUnitId:l,range:f})}},Le={id:"sheet.command.set-filter-criteria",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUndoRedoService),{unitId:s,subUnitId:o,col:l,criteria:c}=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=xe(s,o,l,u),S={id:p.id,params:{unitId:s,subUnitId:o,col:l,criteria:c}},R=t.syncExecuteCommand(S.id,S.params);return R&&r.pushUndoRedo({unitID:s,undoMutations:[f],redoMutations:[S]}),R}},Pe={id:"sheet.command.clear-filter-criteria",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.IUndoRedoService),r=i.get(a.ICommandService),s=i.get(a.IUniverInstanceService),o=_.getSheetCommandTarget(s,n);if(!o)return!1;const{unitId:l,subUnitId:c}=o,d=e.getFilterModel(o.unitId,o.subUnitId);if(!d)return!1;const m=d.serialize(),u=he(l,c,m),f=je(l,c,m);return a.sequenceExecute(f,r).result?(t.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:f}),!0):!1}},De={id:"sheet.command.re-calc-filter",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUniverInstanceService),s=_.getSheetCommandTarget(r,n);if(!s)return!1;const{unitId:o,subUnitId:l}=s;return e.getFilterModel(s.unitId,s.subUnitId)?t.executeCommand($.id,{unitId:o,subUnitId:l}):!1}};function Be(i,n,e){const t=[],r={id:F.id,params:{unitId:i,subUnitId:n,range:e.ref}};return t.push(r),he(i,n,e).forEach(o=>t.push(o)),t}function he(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:s}};t.push(o)}),t}function je(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:null}};t.push(o)}),t}function xe(i,n,e,t){if(!t)return{id:p.id,params:{unitId:i,subUnitId:n,col:e,criteria:null}};const r=t.serialize();return{id:p.id,params:{unitId:i,subUnitId:n,col:e,criteria:r}}}const me="sheets-filter.config",fe={};function He(i,n){for(let e=0;e<i.length;e++){let t=e;if(i[e])for(let r=e+1;r<i.length;r++)i[t]&&i[r]&&n(i[t],i[r])&&(i[t]=null,t=r)}return i.filter(e=>e!==null)}function L(i){return He(i,(n,e)=>n.id===p.id&&e.id===p.id&&n.params.unitId===e.params.unitId&&n.params.subUnitId===e.params.subUnitId&&n.params.col===e.params.col)}var ze=Object.getOwnPropertyDescriptor,Ve=(i,n,e,t)=>{for(var r=t>1?void 0:t?ze(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},b=(i,n)=>(e,t)=>n(e,t,i);let D=class extends a.Disposable{constructor(n,e,t,r,s,o,l){super();v(this,"_disposableCollection",new a.DisposableCollection);this._commandService=n,this._sheetInterceptorService=e,this._sheetsFilterService=t,this._univerInstanceService=r,this._refRangeService=s,this._dataSyncPrimaryController=o,this._zebraCrossingCacheController=l,this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener(),this._initErrorHandling(),this._initZebraCrossingCacheListener()}_initZebraCrossingCacheListener(){this.disposeWithMe(this._sheetsFilterService.activeFilterModel$.subscribe(n=>{n&&this.disposeWithMe(n.filteredOutRows$.subscribe(()=>{this._zebraCrossingCacheController.updateZebraCrossingCache(n.unitId,n.subUnitId)}))}))}_initCommands(){[p,F,$,T].forEach(n=>{var e;this.disposeWithMe(this._commandService.registerCommand(n)),(e=this._dataSyncPrimaryController)==null||e.registerSyncingMutations(n)})}_initInterceptors(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>this._getUpdateFilter(n)})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===_.SetWorksheetActiveOperation.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(r,t)}if(n.id===F.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(e.unitId,e.subUnitId)}})),this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe(n=>{if(n){const e=this._univerInstanceService.getUniverSheetInstance(n),t=e==null?void 0:e.getActiveSheet();t&&this._registerRefRange(n,t.getSheetId())}}))}_registerRefRange(n,e){var l;this._disposableCollection.dispose();const t=this._univerInstanceService.getUniverSheetInstance(n),r=t==null?void 0:t.getSheetBySheetId(e);if(!t||!r)return;const s=(l=this._sheetsFilterService.getFilterModel(n,e))==null?void 0:l.getRange(),o=c=>{switch(c.id){case _.InsertRowCommand.id:{const d=c.params,m=d.unitId||n,u=d.subUnitId||e;return this._handleInsertRowCommand(d,m,u)}case _.InsertColCommand.id:{const d=c.params,m=d.unitId||n,u=d.subUnitId||e;return this.handleInsertColCommand(d.range,m,u)}case _.RemoveColCommand.id:{const d=c.params;return this.handleRemoveColCommand(d.range,n,e)}case _.RemoveRowCommand.id:{const d=c.params;return this._handleRemoveRowCommand(d,n,e)}case _.EffectRefRangId.MoveColsCommandId:{const d=c.params;return this.handleMoveColsCommand({fromRange:d.fromRange,toRange:d.toRange},n,e)}case _.EffectRefRangId.MoveRowsCommandId:{const d=c.params;return this._handleMoveRowsCommand(d,n,e)}case _.MoveRangeCommand.id:{const d=c.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:c,endColumn:d}=n,m=d-c+1;if(d>l)return this._handleNull();const u=[],f=[],S=c,R={unitId:e,subUnitId:t,range:{...s,startColumn:c<=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:c,endRow:d}=n.range,m=d-c+1;if(d>l)return this._handleNull();const u=[],f=[],S={unitId:e,subUnitId:t,range:{...s,startRow:c<=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:c,endColumn:d}=n;if(c>l)return this._handleNull();const m=[],u=[],f=d<o?0:Math.min(d,l)-Math.max(c,o)+1,S=d-c+1,R=r.getAllFilterColumns();R.forEach(g=>{const[C,y]=g;C<=d&&C>=c&&(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<=c?o:f===0?o-S:c,C=o<=c?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:c,endRow:d}=n.range;if(c>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-c+1),endRow:l-(d-c+1)},unitId:e,subUnitId:t}}]};const m=[],u=[],f=r.getAllFilterColumns(),S=o<=d&&o>=c;u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}});const R=Math.min(d,l)-Math.max(c,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=c;O<=d;O++)E.getRowFiltered(O)&&M.push(O);const g=Math.min(o,c),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:c}=o;if(n.endColumn<l&&e.startColumn<=l||n.startColumn>c&&e.endColumn>c)return this._handleNull();const d=[],m=[],u={};for(let g=l;g<=c;g++)u[g]={colIndex:g,filter:s.getFilterColumn(g)};a.moveMatrixArray(n.startColumn,n.endColumn-n.startColumn+1,e.startColumn,u);let f=o.startColumn,S=o.endColumn;l>=n.startColumn&&l<=n.endColumn&&e.startColumn>n.startColumn&&n.endColumn<c&&(f=n.endColumn+1),c>=n.startColumn&&c<=n.endColumn&&e.startColumn<n.startColumn&&n.startColumn>l&&(S=n.startColumn-1);const R=Object.keys(u).map(g=>Number(g)),w=R.find(g=>u[g].colIndex===S),E=R.find(g=>u[g].colIndex===f);if(R.forEach(g=>{var Ce,_e;const{colIndex:C,filter:y}=u[g],O=g;if(y){if(O>=E&&O<=w){const Q={unitId:t,subUnitId:r,col:O,criteria:{...y.serialize(),colId:O}},Xe={unitId:t,subUnitId:r,col:O,criteria:s.getFilterColumn(O)?{...(Ce=s.getFilterColumn(O))==null?void 0:Ce.serialize(),colId:O}:null};d.push({id:p.id,params:Q}),m.push({id:p.id,params:Xe})}if(!((_e=u[C])!=null&&_e.filter)){const Q={unitId:t,subUnitId:r,col:C,criteria:null};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||c!==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:c,toRange:d}=n;if(c.endRow<o&&d.startRow<=o||c.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>=c.startRow&&l<=c.endRow&&d.startRow<c.startRow&&c.startRow>o&&(R=c.startRow-1),a.moveMatrixArray(c.startRow,c.endRow-c.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 c=[],d=[];if(a.Rectangle.contains(r,l)){const m=l.startRow-r.startRow,u=l.startColumn-r.startColumn,f={startRow:s.startRow+m,startColumn:s.startColumn+u,endRow:s.startRow+m+(l.endRow-l.startRow),endColumn:s.startColumn+u+(l.endColumn-l.startColumn)},S={id:T.id,params:{unitId:e,subUnitId:t}},R={id:F.id,params:{unitId:e,subUnitId:t,range:f}},w={id:F.id,params:{unitId:e,subUnitId:t,range:l}};c.push(S,R),d.push(S,w);const E=o.getAllFilterColumns(),M=s.startColumn-r.startColumn;E.forEach(g=>{const[C,y]=g;y&&(c.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(a.Rectangle.intersects(s,l)){const m={...l,endRow:Math.max(l.endRow,s.endRow)};c.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:c,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=[],c=[],d=[];return r.getAllFilterColumns().forEach(([u,f])=>{o.push({id:p.id,params:{unitId:n,subUnitId:t,col:u,criteria:{...f.serialize(),colId:u}}}),c.push({id:p.id,params:{unitId:n,subUnitId:t,col:u,criteria:null}})}),c.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:c,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=[],c=[],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}}}),c.push({id:p.id,params:{...s,col:u+r,criteria:null}})}),{newRange:{redos:d,undos:c},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 c=!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(c=!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?(c=!0,l.push(S+(f-u+1))):l.push(S)})}if(c&&(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 c;const t=this._sheetsFilterService.getFilterModel(n,e);if(!t)return null;const r=(c=this._univerInstanceService.getUnit(n))==null?void 0:c.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=Ve([b(0,a.ICommandService),b(1,a.Inject(_.SheetInterceptorService)),b(2,a.Inject(h.SheetsFilterService)),b(3,a.IUniverInstanceService),b(4,a.Inject(_.RefRangeService)),b(5,a.Optional(Re.DataSyncPrimaryController)),b(6,a.Inject(_.ZebraCrossingCacheController))],D);var We=Object.getOwnPropertyDescriptor,qe=(i,n,e,t)=>{for(var r=t>1?void 0:t?We(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},G=(i,n)=>(e,t)=>n(e,t,i);const ke=[p.id,$.id],Ge=[_.InsertColMutation.id,_.RemoveColMutation.id,_.MoveColsMutation.id];h.SheetsFilterSyncController=class extends a.Disposable{constructor(e,t,r){var o;super();v(this,"_d",new a.DisposableCollection);v(this,"_visible$",new I.BehaviorSubject(!1));v(this,"visible$",this._visible$.asObservable());v(this,"_enabled$",new I.BehaviorSubject(!0));v(this,"enabled$",this._enabled$.asObservable());this._sheetsFilterController=e,this._commandService=t,this._configService=r;const s=this._configService.getConfig(me);s!=null&&s.enableSyncSwitch&&(this._visible$.next(!0),typeof s.enableSyncSwitch=="object"&&this.setEnabled((o=s.enableSyncSwitch.defaultValue)!=null?o:!0))}get visible(){return this._visible$.getValue()}get enabled(){return this._enabled$.getValue()}setEnabled(e){this._enabled$.next(e),e?this._d.dispose():this._initOnlyLocalListener()}_initOnlyLocalListener(){this._d.add(this._commandService.beforeCommandExecuted((e,t)=>{ke.includes(e.id)&&(t||(t={}),t.onlyLocal=!0)})),this._d.add(this._commandService.onCommandExecuted((e,t)=>{if(Ge.includes(e.id)&&(t!=null&&t.fromCollab)){if(e.id===_.InsertColMutation.id){const{range:r,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleInsertColCommand(r,s,o);a.sequenceExecute(l,this._commandService,t)}else if(e.id===_.RemoveColMutation.id){const{range:r,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleRemoveColCommand(r,s,o);a.sequenceExecute(l,this._commandService,t)}else if(e.id===_.MoveColsMutation.id){const{sourceRange:r,targetRange:s,unitId:o,subUnitId:l}=e.params,{redos:c}=this._sheetsFilterController.handleMoveColsCommand({fromRange:r,toRange:s},o,l);a.sequenceExecute(c,this._commandService,t)}}}))}},h.SheetsFilterSyncController=qe([G(0,a.Inject(D)),G(1,a.ICommandService),G(2,a.IConfigService)],h.SheetsFilterSyncController);var Qe=Object.getOwnPropertyDescriptor,Je=(i,n,e,t)=>{for(var r=t>1?void 0:t?Qe(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},B=(i,n)=>(e,t)=>n(e,t,i);let j=class extends a.Disposable{constructor(i,n,e,t){super(),this._activeDirtyManagerService=i,this._sheetRowFilteredService=n,this._sheetsFilterService=e,this._univerInstanceService=t,this._initFormulaDirtyRange(),this._registerSheetRowFiltered()}_initFormulaDirtyRange(){H.forEach(i=>{this._activeDirtyManagerService.register(i,{commandId:i,getDirtyData:n=>{const e=n.params,{unitId:t,subUnitId:r}=e;return{dirtyRanges:this._getHideRowMutation(t,r),clearDependencyTreeCache:{[t]:{[r]:"1"}}}}})})}_getHideRowMutation(i,n){var l,c;const e=(l=this._sheetsFilterService.getFilterModel(i,n))==null?void 0:l.getRange(),t=(c=this._univerInstanceService.getUnit(i))==null?void 0:c.getSheetBySheetId(n);if(e==null||t==null)return[];const{startRow:r,endRow:s}=e;return[{unitId:i,sheetId:n,range:{startRow:r,startColumn:0,endRow:s,endColumn:t.getColumnCount()-1}}]}_registerSheetRowFiltered(){this._sheetRowFilteredService.register((i,n,e)=>{var t,r;return(r=(t=this._sheetsFilterService.getFilterModel(i,n))==null?void 0:t.isRowFiltered(e))!=null?r:!1})}};j=Je([B(0,a.Inject(J.IActiveDirtyManagerService)),B(1,a.Inject(J.ISheetRowFilteredService)),B(2,a.Inject(h.SheetsFilterService)),B(3,a.IUniverInstanceService)],j);var Ke=Object.getOwnPropertyDescriptor,Ze=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ke(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},ge=(i,n)=>(e,t)=>n(e,t,i);h.UniverSheetsFilterPlugin=(x=class extends a.Plugin{constructor(n=fe,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=a.merge({},fe,this._config);this._configService.setConfig(me,r)}onStarting(){[[j],[h.SheetsFilterService],[D],[h.SheetsFilterSyncController]].forEach(n=>this._injector.add(n))}onReady(){a.touchDependencies(this._injector,[[j],[D],[h.SheetsFilterSyncController]])}},v(x,"type",a.UniverInstanceType.UNIVER_SHEET),v(x,"pluginName",k),x),h.UniverSheetsFilterPlugin=Ze([ge(1,a.Inject(a.Injector)),ge(2,a.IConfigService)],h.UniverSheetsFilterPlugin),h.ClearSheetsFilterCriteriaCommand=Pe,h.CustomFilterOperator=A,h.FILTER_MUTATIONS=H,h.FilterBy=N,h.FilterColumn=ae,h.FilterModel=P,h.ReCalcSheetsFilterCommand=De,h.ReCalcSheetsFilterMutation=$,h.RemoveSheetFilterCommand=ue,h.RemoveSheetsFilterMutation=T,h.SHEET_FILTER_SNAPSHOT_ID=k,h.SetSheetFilterRangeCommand=de,h.SetSheetsFilterCriteriaCommand=Le,h.SetSheetsFilterCriteriaMutation=p,h.SetSheetsFilterRangeMutation=F,h.SmartToggleSheetsFilterCommand=$e,h.equals=ie,h.getCustomFilterFn=V,h.greaterThan=ee,h.greaterThanOrEqualTo=te,h.lessThan=re,h.lessThanOrEqualTo=ne,h.notEquals=z,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(h,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-render"),require("@univerjs/rpc"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@univerjs/engine-render","@univerjs/rpc","@univerjs/engine-formula"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.UniverSheetsFilter={},h.UniverCore,h.UniverSheets,h.rxjs,h.UniverEngineRender,h.UniverRpc,h.UniverEngineFormula))})(this,(function(h,a,_,I,Se,Re,J){"use strict";var Ye=Object.defineProperty;var et=(h,a,_)=>a in h?Ye(h,a,{enumerable:!0,configurable:!0,writable:!0,value:_}):h[a]=_;var v=(h,a,_)=>et(h,typeof a!="symbol"?a+"":a,_);var x;const K="sheet.mutation.set-filter-range",Z="sheet.mutation.set-filter-criteria",X="sheet.mutation.remove-filter",Y="sheet.mutation.re-calc-filter",H=new Set([K,Z,X,Y]);var N=(i=>(i[i.VALUES=0]="VALUES",i[i.COLORS=1]="COLORS",i[i.CONDITIONS=2]="CONDITIONS",i))(N||{}),A=(i=>(i.EQUAL="equal",i.GREATER_THAN="greaterThan",i.GREATER_THAN_OR_EQUAL="greaterThanOrEqual",i.LESS_THAN="lessThan",i.LESS_THAN_OR_EQUAL="lessThanOrEqual",i.NOT_EQUALS="notEqual",i))(A||{});const ee={operator:A.GREATER_THAN,fn:(i,n)=>U(i)?i>n:!1},te={operator:A.GREATER_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i>=n:!1},re={operator:A.LESS_THAN,fn:(i,n)=>U(i)?i<n:!1},ne={operator:A.LESS_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i<=n:!1},ie={operator:A.EQUAL,fn:(i,n)=>U(i)?i===n:!1},z={operator:A.NOT_EQUALS,fn:(i,n)=>{if(typeof n=="string"){if(n===" ")return i!=null;const e=le(i);return e&&pe(n)?!a.createREGEXFromWildChar(n).test(e):e!==n}return U(i)?i!==n:!0}},se=new Map([]);[ee,te,re,ne,ie,z].forEach(i=>{se.set(i.operator,i)});function ve(i){return!!i}const Fe={fn:(i,n)=>{const e=le(i);return e===null?n==="":a.createREGEXFromWildChar(n).test(e)}};function V(i){return i?se.get(i):Fe}function U(i){return typeof i=="number"}function oe(i){return!!(typeof i=="number"||typeof i=="string"&&a.isNumeric(i))}function le(i){return typeof i=="boolean"||i==null?null:typeof i=="string"?i:i.toString()}function pe(i){return typeof i=="number"?!1:i.indexOf("*")!==-1||i.indexOf("?")!==-1}const W=()=>new Set;class P extends a.Disposable{constructor(e,t,r){super();v(this,"_filteredOutRows$",new I.BehaviorSubject(W()));v(this,"filteredOutRows$",this._filteredOutRows$.asObservable());v(this,"_hasCriteria$",new I.BehaviorSubject(!1));v(this,"hasCriteria$",this._hasCriteria$.asObservable());v(this,"_filterColumnByIndex",new Map);v(this,"_alreadyFilteredOutRows",W());v(this,"_range");this.unitId=e,this.subUnitId=t,this._worksheet=r}get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete(),this._worksheet=null}serialize(){const e={ref:a.Rectangle.clone(this._range),filterColumns:this._getAllFilterColumns(!0).sort(([t],[r])=>t-r).map(([t,r])=>r.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(e,t,r,s){const o=new P(e,t,r);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.filter(r=>!(!r.filters&&!r.colorFilters&&!r.customFilters)).forEach(r=>this._setCriteriaWithoutReCalc(r.colId,r)),e.cachedFilteredOut?(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()):e.filterColumns&&e.filterColumns.length>0&&(this._reCalcAllColumns(),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw new Error("[FilterModel] could not get range before a range is set!");return this._range}getFilteredOutRowsExceptCol(e){return this._getAllFilterColumns(!0).filter(([t])=>t!==e).reduce((t,[,r])=>{const s=r.calc({getAlreadyFilteredOutRows:()=>t});return s?a.mergeSets(t,s):t},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,r])=>{r.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,r=!1){if(!this._range)throw new Error("[FilterModel] could not set criteria before a range is set!");if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),r&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),r&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._getAllFilterColumns().forEach(s=>s.__clearCache()),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))!=null?t:null}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){const t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([r,s])=>s)}_reCalcAllColumns(){this._alreadyFilteredOutRows=W(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns()}_setCriteriaWithoutReCalc(e,t){const r=this._range;if(!r)throw new Error("[FilterModel] could not set criteria before a range is set!");const{startColumn:s,endColumn:o}=r;if(e>o||e<s)throw new Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);let l;this._filterColumnByIndex.has(e)?l=this._filterColumnByIndex.get(e):(l=new ae(this.unitId,this.subUnitId,this._worksheet,t,{getAlreadyFilteredOutRows:()=>this._alreadyFilteredOutRows}),l.setRangeAndColumn(r,e),this._filterColumnByIndex.set(e,l)),l.setCriteria(t)}_removeCriteria(e){const t=this._filterColumnByIndex.get(e);t&&(t.dispose(),this._filterColumnByIndex.delete(e))}_emit(){this._filteredOutRows$.next(this._alreadyFilteredOutRows)}_emitHasCriteria(){this._hasCriteria$.next(this._filterColumnByIndex.size>0)}_rebuildAlreadyFilteredOutRowsWithCache(){const e=this._getAllFilterColumns().filter(t=>t.hasCache()).reduce((t,r)=>a.mergeSets(t,r.filteredOutRows),new Set);this._alreadyFilteredOutRows=e}_reCalcWithNoCacheColumns(){const e=this._getAllFilterColumns().filter(t=>!t.hasCache());for(const t of e){const r=t.reCalc();r&&(this._alreadyFilteredOutRows=a.mergeSets(this._alreadyFilteredOutRows,r))}}}class ae extends a.Disposable{constructor(e,t,r,s,o){super();v(this,"_filteredOutRows",null);v(this,"_filterFn",null);v(this,"_range",null);v(this,"_column",0);v(this,"_filterBy",N.VALUES);this.unitId=e,this.subUnitId=t,this._worksheet=r,this._criteria=s,this._filterColumnContext=o}get filteredOutRows(){return this._filteredOutRows}get filterBy(){return this._filterBy}dispose(){super.dispose(),this._filteredOutRows=null}__clearCache(){this._filteredOutRows=null}serialize(){if(!this._criteria)throw new Error("[FilterColumn]: could not serialize without a filter column!");return a.Tools.deepClone({...this._criteria,colId:this._column})}hasCache(){return this._filteredOutRows!==null}setRangeAndColumn(e,t){this._range=e,this._column=t}setCriteria(e){this._criteria=e,this._generateFilterFn(),this._filteredOutRows=null}getColumnData(){return a.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw new Error("[FilterColumn] cannot calculate without a filter fn!");if(!this._range)throw new Error("[FilterColumn] cannot calculate without a range!");if(typeof this._column!="number")throw new TypeError("[FilterColumn] cannot calculate without a column offset!");const t=this._column,r={startColumn:t,endColumn:t,startRow:this._range.startRow+1,endRow:this._range.endRow},s=new Set,o=e.getAlreadyFilteredOutRows();for(const l of this._worksheet.iterateByColumn(r,!1,!1)){const{row:d,rowSpan:c,col:m}=l;if(o.has(d)&&(!c||c===1))continue;if(!(this._filterBy===N.VALUES?this._filterFn(a.extractPureTextFromCell(this._worksheet.getCell(d,m))):this._filterBy===N.COLORS?this._filterFn(this._worksheet.getComposedCellStyle(d,m)):this._filterFn(Ne(this._worksheet,d,m)))&&(s.add(d),c))for(let f=1;f<c;f++)s.add(d+f)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=we(this._criteria),this._filterBy=this._criteria.filters?N.VALUES:this._criteria.colorFilters?N.COLORS:N.CONDITIONS)}}function we(i){if(i.filters)return Me(i.filters);if(i.colorFilters)return Ee(i.colorFilters);if(i.customFilters)return ye(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function Me(i){const n=!!i.blank,e=new Set(i.filters);return t=>t===void 0||t===""?n:e.has(typeof t=="string"?t:`${t}`)}function Ee(i){if(i.cellFillColors){const n=new Set(i.cellFillColors);return e=>{var r;if(!e||!((r=e.bg)!=null&&r.rgb))return!!n.has(null);const t=new a.ColorKit(e.bg.rgb).toRgbString();return n.has(t)}}if(i.cellTextColors){const n=new Set(i.cellTextColors);return e=>{var r;if(!e||!((r=e.cl)!=null&&r.rgb))return!!n.has(Se.COLOR_BLACK_RGB);const t=new a.ColorKit(e.cl.rgb).toRgbString();return n.has(t)}}throw new Error("[FilterModel]: color filters are not supported yet.")}function ye(i){const n=i.customFilters.map(e=>Ae(e));return Te(n)?i.and?Oe(n):Ie(n):n[0]}function Oe(i){const[n,e]=i;return t=>n(t)&&e(t)}function Ie(i){const[n,e]=i;return t=>n(t)||e(t)}function Te(i){return i.length===2}function Ae(i){const n=i.val;if(i.operator===A.NOT_EQUALS&&!oe(n))return r=>z.fn(r,n);if(ve(i.operator)){if(!oe(n))return()=>!1;const r=V(i.operator),s=Number(n);return o=>r.fn(o,s)}const e=V(i.operator);return t=>e.fn(t,n)}function Ne(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?de(t):r?t.t===a.CellValueType.NUMBER&&typeof t.v=="string"?r.v:t.t===a.CellValueType.NUMBER?Number(r.v):de(r):null}function de(i){var t,r;const n=(r=(t=i.p)==null?void 0:t.body)==null?void 0:r.dataStream;if(n)return n.trimEnd();const e=i.v;return typeof e=="string"?i.t===a.CellValueType.BOOLEAN?e.toUpperCase():e:typeof e=="number"?i.t===a.CellValueType.BOOLEAN?e?"TRUE":"FALSE":e:typeof e=="boolean"?e?"TRUE":"FALSE":""}var be=Object.getOwnPropertyDescriptor,Ue=(i,n,e,t)=>{for(var r=t>1?void 0:t?be(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},q=(i,n)=>(e,t)=>n(e,t,i);const k="SHEET_FILTER_PLUGIN";h.SheetsFilterService=class extends a.Disposable{constructor(e,t,r){super();v(this,"_filterModels",new Map);v(this,"_loadedUnitId$",new I.BehaviorSubject(null));v(this,"loadedUnitId$",this._loadedUnitId$.asObservable());v(this,"_errorMsg$",new I.BehaviorSubject(null));v(this,"errorMsg$",this._errorMsg$.asObservable());v(this,"_activeFilterModel$",new I.BehaviorSubject(null));v(this,"activeFilterModel$",this._activeFilterModel$.asObservable());this._resourcesManagerService=e,this._univerInstanceService=t,this._commandService=r,this._initModel(),this._initActiveFilterModel()}get activeFilterModel(){return this._activeFilterModel$.getValue()}ensureFilterModel(e,t){const r=this.getFilterModel(e,t);if(r)return r;const s=this._univerInstanceService.getUniverSheetInstance(e);if(!s)throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${e}!`);const o=s.getSheetBySheetId(t);if(!o)throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${t}!`);const l=new P(e,t,o);return this._cacheFilterModel(e,t,l),l}getFilterModel(e,t){var r,s;return(s=(r=this._filterModels.get(e))==null?void 0:r.get(t))!=null?s:null}removeFilterModel(e,t){const r=this.getFilterModel(e,t);return r?(r.dispose(),this._filterModels.get(e).delete(t),!0):!1}setFilterErrorMsg(e){this._errorMsg$.next(e)}_updateActiveFilterModel(){let e;try{if(e=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),!e){this._activeFilterModel$.next(null);return}}catch(l){console.error("[SheetsFilterService]: could not get active workbook!",l);return}const t=e.getActiveSheet(!0);if(!t){this._activeFilterModel$.next(null);return}const r=t.getUnitId(),s=t.getSheetId(),o=this.getFilterModel(r,s);this._activeFilterModel$.next(o)}_initActiveFilterModel(){this.disposeWithMe(I.merge(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([e])=>e.type===a.CommandType.MUTATION&&H.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(e=>{var t;return(t=e==null?void 0:e.activeSheet$)!=null?t:I.of(null)}))).subscribe(()=>this._updateActiveFilterModel()))}_serializeAutoFiltersForUnit(e){const t=this._filterModels.get(e);if(!t)return"{}";const r={};return t.forEach((s,o)=>{r[o]=s.serialize()}),JSON.stringify(r)}_deserializeAutoFiltersForUnit(e,t){const r=this._univerInstanceService.getUniverSheetInstance(e);Object.keys(t).forEach(s=>{const o=t[s],l=P.deserialize(e,s,r.getSheetBySheetId(s),o);this._cacheFilterModel(e,s,l)})}dispose(){super.dispose(),this._loadedUnitId$.complete(),this._errorMsg$.complete(),this._activeFilterModel$.complete(),this._filterModels.forEach(e=>{e.forEach(t=>t.dispose()),e.clear()}),this._filterModels.clear()}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:k,businesses:[a.UniverInstanceType.UNIVER_SHEET],toJson:e=>this._serializeAutoFiltersForUnit(e),parseJson:e=>JSON.parse(e),onLoad:(e,t)=>{this._deserializeAutoFiltersForUnit(e,t),this._loadedUnitId$.next(e),this._updateActiveFilterModel()},onUnLoad:e=>{const t=this._filterModels.get(e);t&&(t.forEach(r=>r.dispose()),this._filterModels.delete(e))}})}_cacheFilterModel(e,t,r){this._filterModels.has(e)||this._filterModels.set(e,new Map),this._filterModels.get(e).set(t,r)}},h.SheetsFilterService=Ue([q(0,a.IResourceManagerService),q(1,a.IUniverInstanceService),q(2,a.ICommandService)],h.SheetsFilterService);const F={id:K,type:a.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,range:r}=n;return i.get(h.SheetsFilterService).ensureFilterModel(t,e).setRange(r),!0}},p={id:Z,type:a.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,criteria:r,col:s,reCalc:o=!0}=n,d=i.get(h.SheetsFilterService).getFilterModel(t,e);return d?(d.setCriteria(s,r,o),!0):!1}},T={id:X,type:a.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(h.SheetsFilterService).removeFilterModel(e,t)}},$={id:Y,type:a.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n,s=i.get(h.SheetsFilterService).getFilterModel(e,t);return s?(s.reCalc(),!0):!1}},ce={id:"sheet.command.set-filter-range",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUndoRedoService),s=i.get(a.IUniverInstanceService),{unitId:o,subUnitId:l,range:d}=n;if(!_.getSheetCommandTarget(s,n)||e.getFilterModel(o,l))return!1;if(d.endRow===d.startRow){const S=i.get(a.ErrorService),R=i.get(a.LocaleService);return S.emit(R.t("sheets-filter.command.not-valid-filter-range")),!1}const u={id:F.id,params:{unitId:o,subUnitId:l,range:d}},f=t.syncExecuteCommand(u.id,u.params);return f&&r.pushUndoRedo({unitID:o,undoMutations:[{id:T.id,params:{unitId:o,subUnitId:l}}],redoMutations:[u]}),f}},ue={id:"sheet.command.remove-sheet-filter",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(a.IUniverInstanceService),t=i.get(h.SheetsFilterService),r=i.get(a.ICommandService),s=i.get(a.IUndoRedoService),o=_.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:d}=o,c=t.getFilterModel(l,d);if(!c)return!1;const m=c==null?void 0:c.serialize(),u=Be(l,d,m),f=r.syncExecuteCommand(T.id,{unitId:l,subUnitId:d});return f&&s.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:[{id:T.id,params:{unitId:l,subUnitId:d}}]}),f}},$e={id:"sheet.command.smart-toggle-filter",type:a.CommandType.COMMAND,handler:async i=>{const n=i.get(a.IUniverInstanceService),e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=r==null?void 0:r.getActiveSheet();if(!s||!r)return!1;const o=r.getUnitId(),l=s.getSheetId();if(e.getFilterModel(o,l))return t.executeCommand(ue.id,{unitId:o,subUnitId:l});const m=i.get(_.SheetsSelectionsService).getCurrentLastSelection();if(!m)return!1;const u=m.range,f=_.isSingleCellSelection(m)?_.expandToContinuousRange(u,{left:!0,right:!0,up:!0,down:!0},s):u.startRow===u.endRow?_.expandToContinuousRange(u,{down:!0},s):u;return t.executeCommand(ce.id,{unitId:o,subUnitId:l,range:f})}},Le={id:"sheet.command.set-filter-criteria",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUndoRedoService),{unitId:s,subUnitId:o,col:l,criteria:d}=n,c=e.getFilterModel(s,o);if(!c)return!1;const m=c.getRange();if(!m||l<m.startColumn||l>m.endColumn)return!1;const u=c.getFilterColumn(l),f=xe(s,o,l,u),S={id:p.id,params:{unitId:s,subUnitId:o,col:l,criteria:d}},R=t.syncExecuteCommand(S.id,S.params);return R&&r.pushUndoRedo({unitID:s,undoMutations:[f],redoMutations:[S]}),R}},Pe={id:"sheet.command.clear-filter-criteria",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.IUndoRedoService),r=i.get(a.ICommandService),s=i.get(a.IUniverInstanceService),o=_.getSheetCommandTarget(s,n);if(!o)return!1;const{unitId:l,subUnitId:d}=o,c=e.getFilterModel(o.unitId,o.subUnitId);if(!c)return!1;const m=c.serialize(),u=he(l,d,m),f=je(l,d,m);return a.sequenceExecute(f,r).result?(t.pushUndoRedo({unitID:l,undoMutations:u,redoMutations:f}),!0):!1}},De={id:"sheet.command.re-calc-filter",type:a.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(h.SheetsFilterService),t=i.get(a.ICommandService),r=i.get(a.IUniverInstanceService),s=_.getSheetCommandTarget(r,n);if(!s)return!1;const{unitId:o,subUnitId:l}=s;return e.getFilterModel(s.unitId,s.subUnitId)?t.executeCommand($.id,{unitId:o,subUnitId:l}):!1}};function Be(i,n,e){const t=[],r={id:F.id,params:{unitId:i,subUnitId:n,range:e.ref}};return t.push(r),he(i,n,e).forEach(o=>t.push(o)),t}function he(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:s}};t.push(o)}),t}function je(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:null}};t.push(o)}),t}function xe(i,n,e,t){if(!t)return{id:p.id,params:{unitId:i,subUnitId:n,col:e,criteria:null}};const r=t.serialize();return{id:p.id,params:{unitId:i,subUnitId:n,col:e,criteria:r}}}const me="sheets-filter.config",fe={};function He(i,n){for(let e=0;e<i.length;e++){let t=e;if(i[e])for(let r=e+1;r<i.length;r++)i[t]&&i[r]&&n(i[t],i[r])&&(i[t]=null,t=r)}return i.filter(e=>e!==null)}function L(i){return He(i,(n,e)=>n.id===p.id&&e.id===p.id&&n.params.unitId===e.params.unitId&&n.params.subUnitId===e.params.subUnitId&&n.params.col===e.params.col)}var ze=Object.getOwnPropertyDescriptor,Ve=(i,n,e,t)=>{for(var r=t>1?void 0:t?ze(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},b=(i,n)=>(e,t)=>n(e,t,i);let D=class extends a.Disposable{constructor(n,e,t,r,s,o,l){super();v(this,"_disposableCollection",new a.DisposableCollection);this._commandService=n,this._sheetInterceptorService=e,this._sheetsFilterService=t,this._univerInstanceService=r,this._refRangeService=s,this._dataSyncPrimaryController=o,this._zebraCrossingCacheController=l,this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener(),this._initErrorHandling(),this._initZebraCrossingCacheListener()}_initZebraCrossingCacheListener(){this.disposeWithMe(this._sheetsFilterService.activeFilterModel$.subscribe(n=>{n&&this.disposeWithMe(n.filteredOutRows$.subscribe(()=>{this._zebraCrossingCacheController.updateZebraCrossingCache(n.unitId,n.subUnitId)}))}))}_initCommands(){[p,F,$,T].forEach(n=>{var e;this.disposeWithMe(this._commandService.registerCommand(n)),(e=this._dataSyncPrimaryController)==null||e.registerSyncingMutations(n)})}_initInterceptors(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>this._getUpdateFilter(n)})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===_.SetWorksheetActiveOperation.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(r,t)}if(n.id===F.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(e.unitId,e.subUnitId)}})),this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe(n=>{if(n){const e=this._univerInstanceService.getUniverSheetInstance(n),t=e==null?void 0:e.getActiveSheet();t&&this._registerRefRange(n,t.getSheetId())}}))}_registerRefRange(n,e){var l;this._disposableCollection.dispose();const t=this._univerInstanceService.getUniverSheetInstance(n),r=t==null?void 0:t.getSheetBySheetId(e);if(!t||!r)return;const s=(l=this._sheetsFilterService.getFilterModel(n,e))==null?void 0:l.getRange(),o=d=>{switch(d.id){case _.InsertRowCommand.id:{const c=d.params,m=c.unitId||n,u=c.subUnitId||e;return this._handleInsertRowCommand(c,m,u)}case _.InsertColCommand.id:{const c=d.params,m=c.unitId||n,u=c.subUnitId||e;return this.handleInsertColCommand(c.range,m,u)}case _.RemoveColCommand.id:{const c=d.params;return this.handleRemoveColCommand(c.range,n,e)}case _.RemoveRowCommand.id:{const c=d.params;return this._handleRemoveRowCommand(c,n,e)}case _.EffectRefRangId.MoveColsCommandId:{const c=d.params;return this.handleMoveColsCommand({fromRange:c.fromRange,toRange:c.toRange},n,e)}case _.EffectRefRangId.MoveRowsCommandId:{const c=d.params;return this._handleMoveRowsCommand(c,n,e)}case _.MoveRangeCommand.id:{const c=d.params;return this._handleMoveRangeCommand(c,n,e)}}return{redos:[],undos:[]}};s&&this._disposableCollection.add(this._refRangeService.registerRefRange(s,o,n,e))}_getUpdateFilter(n){const{id:e}=n;switch(e){case _.RemoveSheetCommand.id:{const t=n.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case _.CopySheetCommand.id:{const t=n.params,{targetSubUnitId:r,unitId:s,subUnitId:o}=t;return!s||!o||!r?this._handleNull():this._handleCopySheetCommand(s,o,r)}}return{redos:[],undos:[]}}handleInsertColCommand(n,e,t){var g;const r=this._sheetsFilterService.getFilterModel(e,t),s=(g=r==null?void 0:r.getRange())!=null?g:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:d,endColumn:c}=n,m=c-d+1;if(c>l)return this._handleNull();const u=[],f=[],S=d,R={unitId:e,subUnitId:t,range:{...s,startColumn:d<=o?o+m:o,endColumn:l+m}},w={unitId:e,subUnitId:t,range:s};u.push({id:F.id,params:R}),f.push({id:F.id,params:w});const M=r.getAllFilterColumns().filter(C=>C[0]>=S);if(M.length!==0){const{newRange:C,oldRange:y}=this._moveCriteria(e,t,M,m);u.push(...y.redos,...C.redos),f.push(...C.undos,...y.undos)}return{redos:L(u),undos:L(f)}}_handleInsertRowCommand(n,e,t){var w;const r=this._sheetsFilterService.getFilterModel(e,t),s=(w=r==null?void 0:r.getRange())!=null?w:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{startRow:d,endRow:c}=n.range,m=c-d+1;if(c>l)return this._handleNull();const u=[],f=[],S={unitId:e,subUnitId:t,range:{...s,startRow:d<=o?o+m:o,endRow:l+m}},R={unitId:e,subUnitId:t,range:s};return u.push({id:F.id,params:S}),f.push({id:F.id,params:R}),{redos:L(u),undos:L(f)}}handleRemoveColCommand(n,e,t){var M;const r=this._sheetsFilterService.getFilterModel(e,t),s=(M=r==null?void 0:r.getRange())!=null?M:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:d,endColumn:c}=n;if(d>l)return this._handleNull();const m=[],u=[],f=c<o?0:Math.min(c,l)-Math.max(d,o)+1,S=c-d+1,R=r.getAllFilterColumns();R.forEach(g=>{const[C,y]=g;C<=c&&C>=d&&(m.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:null}}),u.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:{...y.serialize(),colId:C}}}))});const w=R.filter(g=>{const[C,y]=g;return C>c});let E={undos:[],redos:[]};if(w.length>0){const{oldRange:g,newRange:C}=this._moveCriteria(e,t,w,-S);E=C,m.push(...g.redos),u.unshift(...g.undos)}if(f===l-o+1){const g={unitId:e,subUnitId:t};m.push({id:T.id,params:g}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}})}else{const g=o<=d?o:f===0?o-S:d,C=o<=d?l-f:l-S,y={unitId:e,subUnitId:t,range:{...s,startColumn:g,endColumn:C}};m.push({id:F.id,params:y}),u.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),m.push(...E.redos),u.unshift(...E.undos)}return{undos:u,redos:m}}_handleRemoveRowCommand(n,e,t){var w;const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange(),{startRow:o,endRow:l}=s,{startRow:d,endRow:c}=n.range;if(d>l)return this._handleNull();if(c<o)return{undos:[{id:F.id,params:{range:s,unitId:e,subUnitId:t}}],redos:[{id:F.id,params:{range:{...s,startRow:o-(c-d+1),endRow:l-(c-d+1)},unitId:e,subUnitId:t}}]};const m=[],u=[],f=r.getAllFilterColumns(),S=o<=c&&o>=d;u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}});const R=Math.min(c,l)-Math.max(d,o)+1;if(R===l-o+1||S){const E={unitId:e,subUnitId:t};m.push({id:T.id,params:E}),f.forEach(M=>{const[g,C]=M,y={unitId:e,subUnitId:t,col:g,criteria:{...C.serialize(),colId:g}};u.push({id:p.id,params:y})})}else{const E=(w=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:w.getSheetBySheetId(t);if(!E)return this._handleNull();const M=[];for(let O=d;O<=c;O++)E.getRowFiltered(O)&&M.push(O);const g=Math.min(o,d),C=g+(l-o)-R+M.length,y={unitId:e,subUnitId:t,range:{...s,startRow:g,endRow:C}};m.push({id:F.id,params:y})}return{undos:L(u),redos:L(m)}}handleMoveColsCommand({fromRange:n,toRange:e},t,r){var M;const s=this._sheetsFilterService.getFilterModel(t,r),o=(M=s==null?void 0:s.getRange())!=null?M:null;if(!s||!o)return this._handleNull();const{startColumn:l,endColumn:d}=o;if(n.endColumn<l&&e.startColumn<=l||n.startColumn>d&&e.endColumn>d)return this._handleNull();const c=[],m=[],u={};for(let g=l;g<=d;g++)u[g]={colIndex:g,filter:s.getFilterColumn(g)};a.moveMatrixArray(n.startColumn,n.endColumn-n.startColumn+1,e.startColumn,u);let f=o.startColumn,S=o.endColumn;l>=n.startColumn&&l<=n.endColumn&&e.startColumn>n.startColumn&&n.endColumn<d&&(f=n.endColumn+1),d>=n.startColumn&&d<=n.endColumn&&e.startColumn<n.startColumn&&n.startColumn>l&&(S=n.startColumn-1);const R=Object.keys(u).map(g=>Number(g)),w=R.find(g=>u[g].colIndex===S),E=R.find(g=>u[g].colIndex===f);if(R.forEach(g=>{var Ce,_e;const{colIndex:C,filter:y}=u[g],O=g;if(y){if(O>=E&&O<=w){const Q={unitId:t,subUnitId:r,col:O,criteria:{...y.serialize(),colId:O}},Xe={unitId:t,subUnitId:r,col:O,criteria:s.getFilterColumn(O)?{...(Ce=s.getFilterColumn(O))==null?void 0:Ce.serialize(),colId:O}:null};c.push({id:p.id,params:Q}),m.push({id:p.id,params:Xe})}if(!((_e=u[C])!=null&&_e.filter)){const Q={unitId:t,subUnitId:r,col:C,criteria:null};c.push({id:p.id,params:Q}),m.push({id:p.id,params:{unitId:t,subUnitId:r,col:C,criteria:{...y.serialize(),colId:C}}})}}}),l!==E||d!==w){const g={unitId:t,subUnitId:r,range:{...o,startColumn:E,endColumn:w}};c.unshift({id:F.id,params:g}),m.unshift({id:F.id,params:{range:o,unitId:t,subUnitId:r}})}return{undos:m,redos:c}}_handleMoveRowsCommand(n,e,t){var g;const r=this._sheetsFilterService.getFilterModel(e,t),s=(g=r==null?void 0:r.getRange())!=null?g:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{fromRange:d,toRange:c}=n;if(d.endRow<o&&c.startRow<=o||d.startRow>l&&c.endRow>l)return this._handleNull();const m=[],u=[],f={};for(let C=o;C<=l;C++)f[C]={oldIndex:C};const S=o;let R=l;l>=d.startRow&&l<=d.endRow&&c.startRow<d.startRow&&d.startRow>o&&(R=d.startRow-1),a.moveMatrixArray(d.startRow,d.endRow-d.startRow+1,c.startRow,f);const w=Object.keys(f).map(C=>Number(C)),E=w.find(C=>f[C].oldIndex===R),M=w.find(C=>f[C].oldIndex===S);if(o!==M||l!==E){const C={unitId:e,subUnitId:t,range:{...s,startRow:M,endRow:E}};m.push({id:F.id,params:C},{id:$.id,params:{unitId:e,subUnitId:t}}),u.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}},{id:$.id,params:{unitId:e,subUnitId:t}})}return{redos:m,undos:u}}_handleMoveRangeCommand(n,e,t){const{fromRange:r,toRange:s}=n,o=this._sheetsFilterService.getFilterModel(e,t);if(!o)return this._handleNull();const l=o.getRange();if(!l)return this._handleNull();const d=[],c=[];if(a.Rectangle.contains(r,l)){const m=l.startRow-r.startRow,u=l.startColumn-r.startColumn,f={startRow:s.startRow+m,startColumn:s.startColumn+u,endRow:s.startRow+m+(l.endRow-l.startRow),endColumn:s.startColumn+u+(l.endColumn-l.startColumn)},S={id:T.id,params:{unitId:e,subUnitId:t}},R={id:F.id,params:{unitId:e,subUnitId:t,range:f}},w={id:F.id,params:{unitId:e,subUnitId:t,range:l}};d.push(S,R),c.push(S,w);const E=o.getAllFilterColumns(),M=s.startColumn-r.startColumn;E.forEach(g=>{const[C,y]=g;y&&(d.push({id:p.id,params:{unitId:e,subUnitId:t,col:C+M,criteria:{...y.serialize(),colId:C+M}}}),c.push({id:p.id,params:{unitId:e,subUnitId:t,col:C,criteria:{...y.serialize(),colId:C}}}))})}else if(a.Rectangle.intersects(s,l)){const m={...l,endRow:Math.max(l.endRow,s.endRow)};d.push({id:F.id,params:{unitId:e,subUnitId:t,range:m}}),c.push({id:F.id,params:{unitId:e,subUnitId:t,range:l}})}return{redos:d,undos:c}}_handleRemoveSheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[];return r.getAllFilterColumns().forEach(([c,m])=>{l.push({id:p.id,params:{unitId:e,subUnitId:t,col:c,criteria:{...m.serialize(),colId:c}}})}),o.push({id:T.id,params:{unitId:e,subUnitId:t,range:s}}),l.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),{undos:l,redos:o}}_handleCopySheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(n,e);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[],d=[],c=[];return r.getAllFilterColumns().forEach(([u,f])=>{o.push({id:p.id,params:{unitId:n,subUnitId:t,col:u,criteria:{...f.serialize(),colId:u}}}),d.push({id:p.id,params:{unitId:n,subUnitId:t,col:u,criteria:null}})}),d.push({id:T.id,params:{unitId:n,subUnitId:t,range:s}}),o.unshift({id:F.id,params:{range:s,unitId:n,subUnitId:t}}),{undos:l,redos:o,preUndos:d,preRedos:c}}_handleNull(){return{redos:[],undos:[]}}_initRowFilteredInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(n,e)=>{var t,r;return n?!0:(r=(t=this._sheetsFilterService.getFilterModel(e.unitId,e.subUnitId))==null?void 0:t.isRowFiltered(e.row))!=null?r:!1}}))}_moveCriteria(n,e,t,r){const s={unitId:n,subUnitId:e,criteria:null,col:-1},o=[],l=[],d=[],c=[];return t.forEach(m=>{const[u,f]=m;l.push({id:p.id,params:{...s,col:u}}),o.push({id:p.id,params:{...s,col:u,criteria:{...f.serialize(),colId:u}}})}),t.forEach(m=>{const[u,f]=m;c.push({id:p.id,params:{...s,col:u+r,criteria:{...f.serialize(),colId:u+r}}}),d.push({id:p.id,params:{...s,col:u+r,criteria:null}})}),{newRange:{redos:c,undos:d},oldRange:{redos:l,undos:o}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{var c,m;const{unitId:t,subUnitId:r}=n.params||{},s=this._sheetsFilterService.getFilterModel(t,r);if(!s)return;const o=Array.from(s.filteredOutRows).sort((u,f)=>u-f),l=[];let d=!1;if(n.id===_.RemoveRowMutation.id){const{startRow:u,endRow:f}=n.params.range,S=o.filter(R=>R>=u&&R<=f);o.forEach(R=>{if(R<u)l.push(R);else if(d=!0,R<=f){const w=Math.max(u,l.length?l[l.length-1]+1:u);l.push(w)}else l.push(R-(f-u+1-S.length))})}if(n.id===_.InsertRowMutation.id){const{startRow:u,endRow:f}=n.params.range;o.forEach(S=>{S>=u?(d=!0,l.push(S+(f-u+1))):l.push(S)})}if(d&&(s.filteredOutRows=new Set(l)),n.id===_.SetRangeValuesMutation.id&&!(e!=null&&e.onlyLocal)){const u=this._getExtendRegion(t,r);if(u){const f=n.params.cellValue;if(f)for(let S=u.startColumn;S<=u.endColumn;S++){const R=(c=f==null?void 0:f[u.startRow])==null?void 0:c[S];if(R&&this._cellHasValue(R)){const w=(m=this._univerInstanceService.getUnit(t))==null?void 0:m.getSheetBySheetId(r);if(w){const E=_.expandToContinuousRange(u,{down:!0},w),M=this._sheetsFilterService.getFilterModel(t,r),g=M.getRange();M.setRange({...g,endRow:E.endRow}),this._registerRefRange(t,r)}}}}}}))}_getExtendRegion(n,e){var d;const t=this._sheetsFilterService.getFilterModel(n,e);if(!t)return null;const r=(d=this._univerInstanceService.getUnit(n))==null?void 0:d.getSheetBySheetId(e);if(!r)return null;const s=t.getRange();if(!s)return null;const o=r.getRowCount()-1,l=r.getRowManager();for(let c=s.endRow+1;c<=o;c++)if(l.getRowRawVisible(c))return{startRow:c,endRow:c,startColumn:s.startColumn,endColumn:s.endColumn};return null}_initErrorHandling(){this.disposeWithMe(this._commandService.beforeCommandExecuted(n=>{const e=n.params,t=_.getSheetCommandTarget(this._univerInstanceService);if(!t)return;const{subUnitId:r,unitId:s}=t,o=this._sheetsFilterService.getFilterModel(s,r);if(!o)return;const l=o.getRange();if(n.id===_.MoveRowsCommand.id&&e.fromRange.startRow<=l.startRow&&e.fromRange.endRow<l.endRow&&e.fromRange.endRow>=l.startRow)throw this._sheetsFilterService.setFilterErrorMsg("sheets-filter.msg.filter-header-forbidden"),new Error("[SheetsFilterController]: Cannot move header row of filter")}))}_cellHasValue(n){const e=Object.values(n);return!(e.length===0||e.every(t=>t==null))}};D=Ve([b(0,a.ICommandService),b(1,a.Inject(_.SheetInterceptorService)),b(2,a.Inject(h.SheetsFilterService)),b(3,a.IUniverInstanceService),b(4,a.Inject(_.RefRangeService)),b(5,a.Optional(Re.DataSyncPrimaryController)),b(6,a.Inject(_.ZebraCrossingCacheController))],D);var We=Object.getOwnPropertyDescriptor,qe=(i,n,e,t)=>{for(var r=t>1?void 0:t?We(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},G=(i,n)=>(e,t)=>n(e,t,i);const ke=[p.id,$.id],Ge=[_.InsertColMutation.id,_.RemoveColMutation.id,_.MoveColsMutation.id];h.SheetsFilterSyncController=class extends a.Disposable{constructor(e,t,r){var o;super();v(this,"_d",new a.DisposableCollection);v(this,"_visible$",new I.BehaviorSubject(!1));v(this,"visible$",this._visible$.asObservable());v(this,"_enabled$",new I.BehaviorSubject(!0));v(this,"enabled$",this._enabled$.asObservable());this._sheetsFilterController=e,this._commandService=t,this._configService=r;const s=this._configService.getConfig(me);s!=null&&s.enableSyncSwitch&&(this._visible$.next(!0),typeof s.enableSyncSwitch=="object"&&this.setEnabled((o=s.enableSyncSwitch.defaultValue)!=null?o:!0))}get visible(){return this._visible$.getValue()}get enabled(){return this._enabled$.getValue()}setEnabled(e){this._enabled$.next(e),e?this._d.dispose():this._initOnlyLocalListener()}_initOnlyLocalListener(){this._d.add(this._commandService.beforeCommandExecuted((e,t)=>{ke.includes(e.id)&&(t||(t={}),t.onlyLocal=!0)})),this._d.add(this._commandService.onCommandExecuted((e,t)=>{if(Ge.includes(e.id)&&(t!=null&&t.fromCollab)){if(e.id===_.InsertColMutation.id){const{range:r,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleInsertColCommand(r,s,o);a.sequenceExecute(l,this._commandService,t)}else if(e.id===_.RemoveColMutation.id){const{range:r,unitId:s,subUnitId:o}=e.params,{redos:l}=this._sheetsFilterController.handleRemoveColCommand(r,s,o);a.sequenceExecute(l,this._commandService,t)}else if(e.id===_.MoveColsMutation.id){const{sourceRange:r,targetRange:s,unitId:o,subUnitId:l}=e.params,{redos:d}=this._sheetsFilterController.handleMoveColsCommand({fromRange:r,toRange:s},o,l);a.sequenceExecute(d,this._commandService,t)}}}))}},h.SheetsFilterSyncController=qe([G(0,a.Inject(D)),G(1,a.ICommandService),G(2,a.IConfigService)],h.SheetsFilterSyncController);var Qe=Object.getOwnPropertyDescriptor,Je=(i,n,e,t)=>{for(var r=t>1?void 0:t?Qe(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},B=(i,n)=>(e,t)=>n(e,t,i);let j=class extends a.Disposable{constructor(i,n,e,t){super(),this._activeDirtyManagerService=i,this._sheetRowFilteredService=n,this._sheetsFilterService=e,this._univerInstanceService=t,this._initFormulaDirtyRange(),this._registerSheetRowFiltered()}_initFormulaDirtyRange(){H.forEach(i=>{this._activeDirtyManagerService.register(i,{commandId:i,getDirtyData:n=>{const e=n.params,{unitId:t,subUnitId:r}=e;return{dirtyRanges:this._getHideRowMutation(t,r),clearDependencyTreeCache:{[t]:{[r]:"1"}}}}})})}_getHideRowMutation(i,n){var l,d;const e=(l=this._sheetsFilterService.getFilterModel(i,n))==null?void 0:l.getRange(),t=(d=this._univerInstanceService.getUnit(i))==null?void 0:d.getSheetBySheetId(n);if(e==null||t==null)return[];const{startRow:r,endRow:s}=e;return[{unitId:i,sheetId:n,range:{startRow:r,startColumn:0,endRow:s,endColumn:t.getColumnCount()-1}}]}_registerSheetRowFiltered(){this._sheetRowFilteredService.register((i,n,e)=>{var t,r;return(r=(t=this._sheetsFilterService.getFilterModel(i,n))==null?void 0:t.isRowFiltered(e))!=null?r:!1})}};j=Je([B(0,a.Inject(J.IActiveDirtyManagerService)),B(1,a.Inject(J.ISheetRowFilteredService)),B(2,a.Inject(h.SheetsFilterService)),B(3,a.IUniverInstanceService)],j);var Ke=Object.getOwnPropertyDescriptor,Ze=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ke(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=o(r)||r);return r},ge=(i,n)=>(e,t)=>n(e,t,i);h.UniverSheetsFilterPlugin=(x=class extends a.Plugin{constructor(n=fe,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=a.merge({},fe,this._config);this._configService.setConfig(me,r)}onStarting(){[[j],[h.SheetsFilterService],[D],[h.SheetsFilterSyncController]].forEach(n=>this._injector.add(n))}onReady(){a.touchDependencies(this._injector,[[j],[D],[h.SheetsFilterSyncController]])}},v(x,"type",a.UniverInstanceType.UNIVER_SHEET),v(x,"pluginName",k),x),h.UniverSheetsFilterPlugin=Ze([ge(1,a.Inject(a.Injector)),ge(2,a.IConfigService)],h.UniverSheetsFilterPlugin),h.ClearSheetsFilterCriteriaCommand=Pe,h.CustomFilterOperator=A,h.FILTER_MUTATIONS=H,h.FilterBy=N,h.FilterColumn=ae,h.FilterModel=P,h.ReCalcSheetsFilterCommand=De,h.ReCalcSheetsFilterMutation=$,h.RemoveSheetFilterCommand=ue,h.RemoveSheetsFilterMutation=T,h.SHEET_FILTER_SNAPSHOT_ID=k,h.SetSheetFilterRangeCommand=ce,h.SetSheetsFilterCriteriaCommand=Le,h.SetSheetsFilterCriteriaMutation=p,h.SetSheetsFilterRangeMutation=F,h.SmartToggleSheetsFilterCommand=$e,h.equals=ie,h.getCustomFilterFn=V,h.greaterThan=ee,h.greaterThanOrEqualTo=te,h.lessThan=re,h.lessThanOrEqualTo=ne,h.notEquals=z,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-filter",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.4-experimental.20251210-8d33c6e",
|
|
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/
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/engine-render": "0.12.
|
|
62
|
-
"@univerjs/rpc": "0.12.
|
|
63
|
-
"@univerjs/sheets": "0.12.
|
|
59
|
+
"@univerjs/core": "0.12.4-experimental.20251210-8d33c6e",
|
|
60
|
+
"@univerjs/engine-formula": "0.12.4-experimental.20251210-8d33c6e",
|
|
61
|
+
"@univerjs/engine-render": "0.12.4-experimental.20251210-8d33c6e",
|
|
62
|
+
"@univerjs/rpc": "0.12.4-experimental.20251210-8d33c6e",
|
|
63
|
+
"@univerjs/sheets": "0.12.4-experimental.20251210-8d33c6e"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"rxjs": "^7.8.2",
|
|
67
67
|
"typescript": "^5.9.3",
|
|
68
|
-
"vite": "^7.2.
|
|
69
|
-
"vitest": "^4.0.
|
|
70
|
-
"@univerjs-infra/shared": "0.12.
|
|
68
|
+
"vite": "^7.2.6",
|
|
69
|
+
"vitest": "^4.0.15",
|
|
70
|
+
"@univerjs-infra/shared": "0.12.4"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"test": "vitest run",
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|