@univerjs/sheets-filter 0.5.0 → 0.5.1
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 +205 -205
- package/lib/types/common/const.d.ts +20 -0
- package/lib/types/controllers/config.schema.d.ts +1 -1
- package/lib/types/index.d.ts +2 -1
- package/lib/types/plugin.d.ts +1 -1
- package/lib/types/services/sheet-filter.service.d.ts +0 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ce=Object.defineProperty;var de=(i,n,e)=>n in i?ce(i,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[n]=e;var w=(i,n,e)=>de(i,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@univerjs/core"),O=require("rxjs"),S=require("@univerjs/sheets"),R={id:"sheet.mutation.set-filter-range",type:u.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,range:r}=n;return i.get(exports.SheetsFilterService).ensureFilterModel(t,e).setRange(r),!0}},p={id:"sheet.mutation.set-filter-criteria",type:u.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}},y={id:"sheet.mutation.remove-filter",type:u.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(exports.SheetsFilterService).removeFilterModel(e,t)}},x={id:"sheet.mutation.re-calc-filter",type:u.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}};var 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 Y={operator:T.GREATER_THAN,fn:(i,n)=>U(i)?i>n:!1},K={operator:T.GREATER_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i>=n:!1},X={operator:T.LESS_THAN,fn:(i,n)=>U(i)?i<n:!1},Z={operator:T.LESS_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i<=n:!1},k={operator:T.EQUAL,fn:(i,n)=>U(i)?i===n:!1},H={operator:T.NOT_EQUALS,fn:(i,n)=>{if(typeof n=="string"){if(n===" ")return i!=null;const e=te(i);return e&&fe(n)?!re(n).test(e):e!==n}return U(i)?i!==n:!0}},ee=new Map([]),ue=[Y,K,X,Z,k,H];ue.forEach(i=>{ee.set(i.operator,i)});function he(i){return!!i}const me={fn:(i,n)=>{const e=te(i);return e===null?n==="":re(n).test(e)}};function D(i){return i?ee.get(i):me}function U(i){return typeof i=="number"}function Q(i){return!!(typeof i=="number"||typeof i=="string"&&u.isNumeric(i))}function te(i){return typeof i=="boolean"||i==null?null:typeof i=="string"?i:i.toString()}function fe(i){return typeof i=="number"?!1:i.indexOf("*")!==-1||i.indexOf("?")!==-1}function re(i){const n=i.replace(/[.+^${}()|[\]\\]/g,"\\$&").replaceAll("?",".").replace(/[*]/g,".$&");return new RegExp(`^${n}$`)}const j=()=>new Set;class P extends u.Disposable{constructor(e,t,r){super();w(this,"_filteredOutRows$",new O.BehaviorSubject(j()));w(this,"filteredOutRows$",this._filteredOutRows$.asObservable());w(this,"_hasCriteria$",new O.BehaviorSubject(!1));w(this,"hasCriteria$",this._hasCriteria$.asObservable());w(this,"_filterColumnByIndex",new Map);w(this,"_alreadyFilteredOutRows",j());w(this,"_range");this.unitId=e,this.subUnitId=t,this._worksheet=r}get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete()}serialize(){const e={ref:u.Rectangle.clone(this._range),filterColumns:this._getAllFilterColumns(!0).sort(([t],[r])=>t-r).map(([t,r])=>r.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(e,t,r,s){const o=new P(e,t,r);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.forEach(r=>this._setCriteriaWithoutReCalc(r.colId,r)),e.cachedFilteredOut&&(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw new Error("[FilterModel] could not get range before a range is set!");return this._range}getFilteredOutRowsExceptCol(e){return this._getAllFilterColumns(!0).filter(([t])=>t!==e).reduce((t,[,r])=>{const s=r.calc({getAlreadyFilteredOutRows:()=>t});return s?u.mergeSets(t,s):t},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,r])=>{r.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,r=!1){if(!this._range)throw new Error("[FilterModel] could not set criteria before a range is set!");if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),r&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),r&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))!=null?t:null}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){const t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([r,s])=>s)}_reCalcAllColumns(){this._alreadyFilteredOutRows=j(),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 ne(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)=>u.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=u.mergeSets(this._alreadyFilteredOutRows,r))}}}class ne extends u.Disposable{constructor(e,t,r,s,o){super();w(this,"_filteredOutRows",null);w(this,"_filterFn",null);w(this,"_range",null);w(this,"_column",0);w(this,"_filterByValues",!1);this.unitId=e,this.subUnitId=t,this._worksheet=r,this._criteria=s,this._filterColumnContext=o}get filteredOutRows(){return this._filteredOutRows}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 u.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 u.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw new Error("[FilterColumn] cannot calculate without a filter fn!");if(!this._range)throw new Error("[FilterColumn] cannot calculate without a range!");if(typeof this._column!="number")throw new TypeError("[FilterColumn] cannot calculate without a column offset!");const t=this._column,r={startColumn:t,endColumn:t,startRow:this._range.startRow+1,endRow:this._range.endRow},s=new Set,o=e.getAlreadyFilteredOutRows();for(const l of this._worksheet.iterateByColumn(r,!1,!1)){const{row:a,rowSpan:c,col:m}=l;if(o.has(a)&&(!c||c===1))continue;const d=this._filterByValues?u.extractPureTextFromCell(this._worksheet.getCell(a,m)):ve(this._worksheet,a,m);if(!this._filterFn(d)&&(s.add(a),c))for(let h=1;h<c;h++)s.add(a+h)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=ge(this._criteria),this._filterByValues=!!this._criteria.filters)}}function ge(i){if(i.filters)return Ce(i.filters);if(i.customFilters)return _e(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function Ce(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 _e(i){const n=i.customFilters.map(e=>Fe(e));return pe(n)?i.and?Re(n):Se(n):n[0]}function Re(i){const[n,e]=i;return t=>n(t)&&e(t)}function Se(i){const[n,e]=i;return t=>n(t)||e(t)}function pe(i){return i.length===2}function Fe(i){const n=i.val;if(i.operator===T.NOT_EQUALS&&!Q(n))return r=>H.fn(r,n);if(he(i.operator)){if(!Q(n))return()=>!1;const r=D(i.operator),s=Number(n);return o=>r.fn(o,s)}const e=D(i.operator);return t=>e.fn(t,n)}function ve(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?G(t):r?t.t===u.CellValueType.NUMBER&&typeof t.v=="string"?r.v:G(r):null}function G(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===u.CellValueType.BOOLEAN?e.toUpperCase():e:typeof e=="number"?i.t===u.CellValueType.BOOLEAN?e?"TRUE":"FALSE":e:typeof e=="boolean"?e?"TRUE":"FALSE":""}var we=Object.defineProperty,Me=Object.getOwnPropertyDescriptor,Ee=(i,n,e,t)=>{for(var r=t>1?void 0:t?Me(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&we(n,e,r),r},z=(i,n)=>(e,t)=>n(e,t,i);const ie=new Set([R.id,p.id,y.id,x.id]),V="SHEET_FILTER_PLUGIN";exports.SheetsFilterService=class extends u.Disposable{constructor(e,t,r){super();w(this,"_filterModels",new Map);w(this,"_loadedUnitId$",new O.BehaviorSubject(null));w(this,"loadedUnitId$",this._loadedUnitId$.asObservable());w(this,"_errorMsg$",new O.BehaviorSubject(null));w(this,"errorMsg$",this._errorMsg$.asObservable());w(this,"_activeFilterModel$",new O.BehaviorSubject(null));w(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(u.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(u.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(O.filter(([e])=>e.type===u.CommandType.MUTATION&&ie.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(u.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=P.deserialize(e,s,r.getSheetBySheetId(s),o);this._cacheFilterModel(e,s,l)})}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:V,businesses:[u.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=Ee([z(0,u.IResourceManagerService),z(1,u.IUniverInstanceService),z(2,u.ICommandService)],exports.SheetsFilterService);function ye(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 ye(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 Oe=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,Ie=(i,n,e,t)=>{for(var r=t>1?void 0:t?Te(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&Oe(n,e,r),r},$=(i,n)=>(e,t)=>n(e,t,i);let B=class extends u.Disposable{constructor(n,e,t,r,s){super();w(this,"_disposableCollection",new u.DisposableCollection);this._commandService=n,this._sheetInterceptorService=e,this._sheetsFilterService=t,this._univerInstanceService=r,this._refRangeService=s,this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener(),this._initErrorHandling()}_initCommands(){[p,R,x,y].forEach(n=>this.disposeWithMe(this._commandService.registerCommand(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===R.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(e.unitId,e.subUnitId)}})),this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe(n=>{if(n){const e=this._univerInstanceService.getUniverSheetInstance(n),t=e==null?void 0:e.getActiveSheet();t&&this._registerRefRange(n,t.getSheetId())}}))}_registerRefRange(n,e){var l;this._disposableCollection.dispose();const t=this._univerInstanceService.getUniverSheetInstance(n),r=t==null?void 0:t.getSheetBySheetId(e);if(!t||!r)return;const s=(l=this._sheetsFilterService.getFilterModel(n,e))==null?void 0:l.getRange(),o=a=>{switch(a.id){case S.InsertRowCommand.id:{const c=a.params,m=c.unitId||n,d=c.subUnitId||e;return this._handleInsertRowCommand(c,m,d)}case S.InsertColCommand.id:{const c=a.params,m=c.unitId||n,d=c.subUnitId||e;return this._handleInsertColCommand(c,m,d)}case S.RemoveColCommand.id:{const c=a.params;return this._handleRemoveColCommand(c,n,e)}case S.RemoveRowCommand.id:{const c=a.params;return this._handleRemoveRowCommand(c,n,e)}case S.EffectRefRangId.MoveColsCommandId:{const c=a.params;return this._handleMoveColsCommand(c,n,e)}case S.EffectRefRangId.MoveRowsCommandId:{const c=a.params;return this._handleMoveRowsCommand(c,n,e)}case S.MoveRangeCommand.id:{const c=a.params;return this._handleMoveRangeCommand(c,n,e)}}return{redos:[],undos:[]}};s&&this._disposableCollection.add(this._refRangeService.registerRefRange(s,o,n,e))}_getUpdateFilter(n){const{id:e}=n;switch(e){case S.RemoveSheetCommand.id:{const t=n.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case S.CopySheetCommand.id:{const t=n.params,{targetSubUnitId:r,unitId:s,subUnitId:o}=t;return!s||!o||!r?this._handleNull():this._handleCopySheetCommand(s,o,r)}}return{redos:[],undos:[]}}_handleInsertColCommand(n,e,t){var _;const r=this._sheetsFilterService.getFilterModel(e,t),s=(_=r==null?void 0:r.getRange())!=null?_:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:a,endColumn:c}=n.range,m=c-a+1;if(c>l)return this._handleNull();const d=[],h=[],g=a,C={unitId:e,subUnitId:t,range:{...s,startColumn:a<=o?o+m:o,endColumn:l+m}},F={unitId:e,subUnitId:t,range:s};d.push({id:R.id,params:C}),h.push({id:R.id,params:F});const v=r.getAllFilterColumns().filter(f=>f[0]>=g);if(v.length!==0){const{newRange:f,oldRange:E}=this.moveCriteria(e,t,v,m);d.push(...f.redos,...E.redos),h.push(...f.undos,...E.undos)}return{redos:N(d),undos:N(h)}}_handleInsertRowCommand(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,{startRow:a,endRow:c}=n.range,m=c-a+1;if(c>l)return this._handleNull();const d=[],h=[],g={unitId:e,subUnitId:t,range:{...s,startRow:a<=o?o+m:o,endRow:l+m}},C={unitId:e,subUnitId:t,range:s};return d.push({id:R.id,params:g}),h.push({id:R.id,params:C}),{redos:N(d),undos:N(h)}}_handleRemoveColCommand(n,e,t){var v;const r=this._sheetsFilterService.getFilterModel(e,t),s=(v=r==null?void 0:r.getRange())!=null?v:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:a,endColumn:c}=n.range;if(a>l)return this._handleNull();const m=[],d=[],h=c<o?0:Math.min(c,l)-Math.max(a,o)+1,g=c-a+1,C=r.getAllFilterColumns();C.forEach(_=>{const[f,E]=_;f<=c&&f>=a&&(m.push({id:p.id,params:{unitId:e,subUnitId:t,col:f,criteria:null}}),d.push({id:p.id,params:{unitId:e,subUnitId:t,col:f,criteria:{...E.serialize(),colId:f}}}))});const F=C.filter(_=>{const[f,E]=_;return f>c});let M={undos:[],redos:[]};if(F.length>0){const{oldRange:_,newRange:f}=this.moveCriteria(e,t,F,-g);M=f,m.push(..._.redos),d.unshift(..._.undos)}if(h===l-o+1){const _={unitId:e,subUnitId:t};m.push({id:y.id,params:_}),d.unshift({id:R.id,params:{range:s,unitId:e,subUnitId:t}})}else{const _=o<=a?o:h===0?o-g:a,f=o<=a?l-h:l-g,E={unitId:e,subUnitId:t,range:{...s,startColumn:_,endColumn:f}};m.push({id:R.id,params:E}),d.unshift({id:R.id,params:{range:s,unitId:e,subUnitId:t}}),m.push(...M.redos),d.unshift(...M.undos)}return{undos:d,redos:m}}_handleRemoveRowCommand(n,e,t){var F;const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange(),{startRow:o,endRow:l}=s,{startRow:a,endRow:c}=n.range;if(a>l)return this._handleNull();if(c<o)return{undos:[{id:R.id,params:{range:s,unitId:e,subUnitId:t}}],redos:[{id:R.id,params:{range:{...s,startRow:o-(c-a+1),endRow:l-(c-a+1)},unitId:e,subUnitId:t}}]};const m=[],d=[],h=r.getAllFilterColumns(),g=o<=c&&o>=a;d.push({id:R.id,params:{range:s,unitId:e,subUnitId:t}});const C=Math.min(c,l)-Math.max(a,o)+1;if(C===l-o+1||g){const M={unitId:e,subUnitId:t};m.push({id:y.id,params:M}),h.forEach(v=>{const[_,f]=v,E={unitId:e,subUnitId:t,col:_,criteria:{...f.serialize(),colId:_}};d.push({id:p.id,params:E})})}else{const M=(F=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:F.getSheetBySheetId(t);if(!M)return this._handleNull();const v=[];for(let I=a;I<=c;I++)M.getRowFiltered(I)&&v.push(I);const _=Math.min(o,a),f=_+(l-o)-C+v.length,E={unitId:e,subUnitId:t,range:{...s,startRow:_,endRow:f}};m.push({id:R.id,params:E})}return{undos:N(d),redos:N(m)}}_handleMoveColsCommand(n,e,t){var _;const r=this._sheetsFilterService.getFilterModel(e,t),s=(_=r==null?void 0:r.getRange())!=null?_:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{fromRange:a,toRange:c}=n;if(a.endColumn<o&&c.startColumn<=o||a.startColumn>l&&c.endColumn>l)return this._handleNull();const m=[],d=[],h={};for(let f=o;f<=l;f++)h[f]={colIndex:f,filter:r.getFilterColumn(f)};u.moveMatrixArray(a.startColumn,a.endColumn-a.startColumn+1,c.startColumn,h);let g=s.startColumn,C=s.endColumn;o>=a.startColumn&&o<=a.endColumn&&c.startColumn>a.startColumn&&a.endColumn<l&&(g=a.endColumn+1),l>=a.startColumn&&l<=a.endColumn&&c.startColumn<a.startColumn&&a.startColumn>o&&(C=a.startColumn-1);const F=Object.keys(h).map(f=>Number(f)),M=F.find(f=>h[f].colIndex===C),v=F.find(f=>h[f].colIndex===g);if(F.forEach(f=>{var W,q;const{colIndex:E,filter:I}=h[f],A=f;if(I){if(A>=v&&A<=M){const L={unitId:e,subUnitId:t,col:A,criteria:{...I.serialize(),colId:A}},ae={unitId:e,subUnitId:t,col:A,criteria:r.getFilterColumn(A)?{...(W=r.getFilterColumn(A))==null?void 0:W.serialize(),colId:A}:null};m.push({id:p.id,params:L}),d.push({id:p.id,params:ae})}if(!((q=h[E])!=null&&q.filter)){const L={unitId:e,subUnitId:t,col:E,criteria:null};m.push({id:p.id,params:L}),d.push({id:p.id,params:{unitId:e,subUnitId:t,col:E,criteria:{...I.serialize(),colId:E}}})}}}),o!==v||l!==M){const f={unitId:e,subUnitId:t,range:{...s,startColumn:v,endColumn:M}};m.unshift({id:R.id,params:f}),d.unshift({id:R.id,params:{range:s,unitId:e,subUnitId:t}})}return{undos:d,redos:m}}_handleMoveRowsCommand(n,e,t){var _;const r=this._sheetsFilterService.getFilterModel(e,t),s=(_=r==null?void 0:r.getRange())!=null?_:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{fromRange:a,toRange:c}=n;if(a.endRow<o&&c.startRow<=o||a.startRow>l&&c.endRow>l)return this._handleNull();const m=[],d=[],h={};for(let f=o;f<=l;f++)h[f]={oldIndex:f};const g=o;let C=l;l>=a.startRow&&l<=a.endRow&&c.startRow<a.startRow&&a.startRow>o&&(C=a.startRow-1),u.moveMatrixArray(a.startRow,a.endRow-a.startRow+1,c.startRow,h);const F=Object.keys(h).map(f=>Number(f)),M=F.find(f=>h[f].oldIndex===C),v=F.find(f=>h[f].oldIndex===g);if(o!==v||l!==M){const f={unitId:e,subUnitId:t,range:{...s,startRow:v,endRow:M}};m.push({id:R.id,params:f},{id:x.id,params:{unitId:e,subUnitId:t}}),d.push({id:R.id,params:{range:s,unitId:e,subUnitId:t}},{id:x.id,params:{unitId:e,subUnitId:t}})}return{redos:m,undos:d}}_handleMoveRangeCommand(n,e,t){const{fromRange:r,toRange:s}=n,o=this._sheetsFilterService.getFilterModel(e,t);if(!o)return this._handleNull();const l=o.getRange();if(!l)return this._handleNull();const a=[],c=[];if(u.Rectangle.contains(r,l)){const m=l.startRow-r.startRow,d=l.startColumn-r.startColumn,h={startRow:s.startRow+m,startColumn:s.startColumn+d,endRow:s.startRow+m+(l.endRow-l.startRow),endColumn:s.startColumn+d+(l.endColumn-l.startColumn)},g={id:y.id,params:{unitId:e,subUnitId:t}},C={id:R.id,params:{unitId:e,subUnitId:t,range:h}},F={id:R.id,params:{unitId:e,subUnitId:t,range:l}};a.push(g,C),c.push(g,F);const M=o.getAllFilterColumns(),v=s.startColumn-r.startColumn;M.forEach(_=>{const[f,E]=_;E&&(a.push({id:p.id,params:{unitId:e,subUnitId:t,col:f+v,criteria:{...E.serialize(),colId:f+v}}}),c.push({id:p.id,params:{unitId:e,subUnitId:t,col:f,criteria:{...E.serialize(),colId:f}}}))})}else if(u.Rectangle.intersects(s,l)){const m={...l,endRow:Math.max(l.endRow,s.endRow)};a.push({id:R.id,params:{unitId:e,subUnitId:t,range:m}}),c.push({id:R.id,params:{unitId:e,subUnitId:t,range:l}})}return{redos:a,undos:c}}_handleRemoveSheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[];return r.getAllFilterColumns().forEach(([c,m])=>{l.push({id:p.id,params:{unitId:e,subUnitId:t,col:c,criteria:{...m.serialize(),colId:c}}})}),o.push({id:y.id,params:{unitId:e,subUnitId:t,range:s}}),l.unshift({id:R.id,params:{range:s,unitId:e,subUnitId:t}}),{undos:l,redos:o}}_handleCopySheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(n,e);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[],a=[],c=[];return r.getAllFilterColumns().forEach(([d,h])=>{o.push({id:p.id,params:{unitId:n,subUnitId:t,col:d,criteria:{...h.serialize(),colId:d}}}),a.push({id:p.id,params:{unitId:n,subUnitId:t,col:d,criteria:null}})}),a.push({id:y.id,params:{unitId:n,subUnitId:t,range:s}}),o.unshift({id:R.id,params:{range:s,unitId:n,subUnitId:t}}),{undos:l,redos:o,preUndos:a,preRedos:c}}_handleNull(){return{redos:[],undos:[]}}_initRowFilteredInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(S.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(n,e)=>{var t,r;return n?!0:(r=(t=this._sheetsFilterService.getFilterModel(e.unitId,e.subUnitId))==null?void 0:t.isRowFiltered(e.row))!=null?r:!1}}))}moveCriteria(n,e,t,r){const s={unitId:n,subUnitId:e,criteria:null,col:-1},o=[],l=[],a=[],c=[];return t.forEach(m=>{const[d,h]=m;l.push({id:p.id,params:{...s,col:d}}),o.push({id:p.id,params:{...s,col:d,criteria:{...h.serialize(),colId:d}}})}),t.forEach(m=>{const[d,h]=m;c.push({id:p.id,params:{...s,col:d+r,criteria:{...h.serialize(),colId:d+r}}}),a.push({id:p.id,params:{...s,col:d+r,criteria:null}})}),{newRange:{redos:c,undos:a},oldRange:{redos:l,undos:o}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{var c,m;const{unitId:t,subUnitId:r}=n.params||{},s=this._sheetsFilterService.getFilterModel(t,r);if(!s)return;const o=Array.from(s.filteredOutRows).sort((d,h)=>d-h),l=[];let a=!1;if(n.id===S.RemoveRowMutation.id){const{startRow:d,endRow:h}=n.params.range,g=o.filter(C=>C>=d&&C<=h);o.forEach(C=>{if(C<d)l.push(C);else if(a=!0,C<=h){const F=Math.max(d,l.length?l[l.length-1]+1:d);l.push(F)}else l.push(C-(h-d+1-g.length))})}if(n.id===S.InsertRowMutation.id){const{startRow:d,endRow:h}=n.params.range;o.forEach(g=>{g>=d?(a=!0,l.push(g+(h-d+1))):l.push(g)})}if(a&&(s.filteredOutRows=new Set(l)),n.id===S.SetRangeValuesMutation.id&&!(e!=null&&e.onlyLocal)){const d=this._getExtendRegion(t,r);if(d){const h=n.params.cellValue;if(h)for(let g=d.startColumn;g<=d.endColumn;g++){const C=(c=h==null?void 0:h[d.startRow])==null?void 0:c[g];if(C&&this._cellHasValue(C)){const F=(m=this._univerInstanceService.getUnit(t))==null?void 0:m.getSheetBySheetId(r);if(F){const M=S.expandToContinuousRange(d,{down:!0},F),v=this._sheetsFilterService.getFilterModel(t,r),_=v.getRange();v.setRange({..._,endRow:M.endRow}),this._registerRefRange(t,r)}}}}}}))}_getExtendRegion(n,e){var a;const t=this._sheetsFilterService.getFilterModel(n,e);if(!t)return null;const r=(a=this._univerInstanceService.getUnit(n))==null?void 0:a.getSheetBySheetId(e);if(!r)return null;const s=t.getRange();if(!s)return null;const o=r.getRowCount()-1,l=r.getRowManager();for(let c=s.endRow+1;c<=o;c++)if(l.getRowRawVisible(c))return{startRow:c,endRow:c,startColumn:s.startColumn,endColumn:s.endColumn};return null}_initErrorHandling(){this.disposeWithMe(this._commandService.beforeCommandExecuted(n=>{const e=n.params,t=S.getSheetCommandTarget(this._univerInstanceService);if(!t)return;const{subUnitId:r,unitId:s}=t,o=this._sheetsFilterService.getFilterModel(s,r);if(!o)return;const l=o.getRange();if(n.id===S.MoveRowsCommand.id&&e.fromRange.startRow<=l.startRow&&e.fromRange.endRow<l.endRow&&e.fromRange.endRow>=l.startRow)throw this._sheetsFilterService.setFilterErrorMsg("sheets-filter.msg.filter-header-forbidden"),new Error("[SheetsFilterController]: Cannot move header row of filter")}))}_cellHasValue(n){const e=Object.values(n);return!(e.length===0||e.every(t=>t==null))}};B=Ie([$(0,u.ICommandService),$(1,u.Inject(S.SheetInterceptorService)),$(2,u.Inject(exports.SheetsFilterService)),$(3,u.IUniverInstanceService),$(4,u.Inject(S.RefRangeService))],B);const Ae="sheets-filter.config",Ne={};var xe=Object.defineProperty,Ue=Object.getOwnPropertyDescriptor,$e=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ue(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&xe(n,e,r),r},J=(i,n)=>(e,t)=>n(e,t,i),b;exports.UniverSheetsFilterPlugin=(b=class extends u.Plugin{constructor(n=Ne,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=this._config;this._configService.setConfig(Ae,r)}onStarting(){[[exports.SheetsFilterService],[B]].forEach(n=>this._injector.add(n))}onReady(){this._injector.get(B)}},w(b,"type",u.UniverInstanceType.UNIVER_SHEET),w(b,"pluginName",V),b);exports.UniverSheetsFilterPlugin=$e([J(1,u.Inject(u.Injector)),J(2,u.IConfigService)],exports.UniverSheetsFilterPlugin);const se={id:"sheet.command.set-filter-range",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(u.ICommandService),r=i.get(u.IUndoRedoService),s=i.get(u.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 g=i.get(u.ErrorService),C=i.get(u.LocaleService);return g.emit(C.t("sheets-filter.command.not-valid-filter-range")),!1}const d={id:R.id,params:{unitId:o,subUnitId:l,range:a}},h=t.syncExecuteCommand(d.id,d.params);return h&&r.pushUndoRedo({unitID:o,undoMutations:[{id:y.id,params:{unitId:o,subUnitId:l}}],redoMutations:[d]}),h}},oe={id:"sheet.command.remove-sheet-filter",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(u.IUniverInstanceService),t=i.get(exports.SheetsFilterService),r=i.get(u.ICommandService),s=i.get(u.IUndoRedoService),o=S.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,c=t.getFilterModel(l,a);if(!c)return!1;const m=c==null?void 0:c.serialize(),d=je(l,a,m),h=r.syncExecuteCommand(y.id,{unitId:l,subUnitId:a});return h&&s.pushUndoRedo({unitID:l,undoMutations:d,redoMutations:[{id:y.id,params:{unitId:l,subUnitId:a}}]}),h}},Pe={id:"sheet.command.smart-toggle-filter",type:u.CommandType.COMMAND,handler:async i=>{const n=i.get(u.IUniverInstanceService),e=i.get(exports.SheetsFilterService),t=i.get(u.ICommandService),r=n.getCurrentUnitForType(u.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(oe.id,{unitId:o,subUnitId:l});const m=i.get(S.SheetsSelectionsService).getCurrentLastSelection();if(!m)return!1;const d=m.range,h=S.isSingleCellSelection(m)?S.expandToContinuousRange(d,{left:!0,right:!0,up:!0,down:!0},s):d;return t.executeCommand(se.id,{unitId:o,subUnitId:l,range:h})}},be={id:"sheet.command.set-filter-criteria",type:u.CommandType.COMMAND,handler:async(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(u.ICommandService),r=i.get(u.IUndoRedoService),{unitId:s,subUnitId:o,col:l,criteria:a}=n,c=e.getFilterModel(s,o);if(!c)return!1;const m=c.getRange();if(!m||l<m.startColumn||l>m.endColumn)return!1;const d=c.getFilterColumn(l),h=De(s,o,l,d),g={id:p.id,params:{unitId:s,subUnitId:o,col:l,criteria:a}},C=t.syncExecuteCommand(g.id,g.params);return C&&r.pushUndoRedo({unitID:s,undoMutations:[h],redoMutations:[g]}),C}},Be={id:"sheet.command.clear-filter-criteria",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(u.IUndoRedoService),r=i.get(u.ICommandService),s=i.get(u.IUniverInstanceService),o=S.getSheetCommandTarget(s,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,c=e.getFilterModel(o.unitId,o.subUnitId);if(!c)return!1;const m=c.serialize(),d=le(l,a,m),h=ze(l,a,m);return u.sequenceExecute(h,r).result?(t.pushUndoRedo({unitID:l,undoMutations:d,redoMutations:h}),!0):!1}},Le={id:"sheet.command.re-calc-filter",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(u.ICommandService),r=i.get(u.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 je(i,n,e){const t=[],r={id:R.id,params:{unitId:i,subUnitId:n,range:e.ref}};return t.push(r),le(i,n,e).forEach(o=>t.push(o)),t}function le(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 ze(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 De(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}}}exports.ClearSheetsFilterCriteriaCommand=Be;exports.CustomFilterOperator=T;exports.FILTER_MUTATIONS=ie;exports.FilterColumn=ne;exports.FilterModel=P;exports.ReCalcSheetsFilterCommand=Le;exports.ReCalcSheetsFilterMutation=x;exports.RemoveSheetFilterCommand=oe;exports.RemoveSheetsFilterMutation=y;exports.SHEET_FILTER_SNAPSHOT_ID=V;exports.SetSheetFilterRangeCommand=se;exports.SetSheetsFilterCriteriaCommand=be;exports.SetSheetsFilterCriteriaMutation=p;exports.SetSheetsFilterRangeMutation=R;exports.SmartToggleSheetsFilterCommand=Pe;exports.equals=k;exports.getCustomFilterFn=D;exports.greaterThan=Y;exports.greaterThanOrEqualTo=K;exports.lessThan=X;exports.lessThanOrEqualTo=Z;exports.notEquals=H;
|
|
1
|
+
"use strict";var me=Object.defineProperty;var fe=(i,n,e)=>n in i?me(i,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[n]=e;var w=(i,n,e)=>fe(i,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@univerjs/core"),S=require("@univerjs/sheets"),O=require("rxjs"),ge="sheets-filter.config",Ce={},Y="sheet.mutation.set-filter-range",K="sheet.mutation.set-filter-criteria",X="sheet.mutation.remove-filter",Z="sheet.mutation.re-calc-filter",k=new Set([Y,K,X,Z]);var 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 ee={operator:T.GREATER_THAN,fn:(i,n)=>x(i)?i>n:!1},te={operator:T.GREATER_THAN_OR_EQUAL,fn:(i,n)=>x(i)?i>=n:!1},re={operator:T.LESS_THAN,fn:(i,n)=>x(i)?i<n:!1},ne={operator:T.LESS_THAN_OR_EQUAL,fn:(i,n)=>x(i)?i<=n:!1},ie={operator:T.EQUAL,fn:(i,n)=>x(i)?i===n:!1},D={operator:T.NOT_EQUALS,fn:(i,n)=>{if(typeof n=="string"){if(n===" ")return i!=null;const e=oe(i);return e&&pe(n)?!le(n).test(e):e!==n}return x(i)?i!==n:!0}},se=new Map([]),_e=[ee,te,re,ne,ie,D];_e.forEach(i=>{se.set(i.operator,i)});function Re(i){return!!i}const Se={fn:(i,n)=>{const e=oe(i);return e===null?n==="":le(n).test(e)}};function z(i){return i?se.get(i):Se}function x(i){return typeof i=="number"}function Q(i){return!!(typeof i=="number"||typeof i=="string"&&u.isNumeric(i))}function oe(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}function le(i){const n=i.replace(/[.+^${}()|[\]\\]/g,"\\$&").replaceAll("?",".").replace(/[*]/g,".$&");return new RegExp(`^${n}$`)}const H=()=>new Set;class P extends u.Disposable{constructor(e,t,r){super();w(this,"_filteredOutRows$",new O.BehaviorSubject(H()));w(this,"filteredOutRows$",this._filteredOutRows$.asObservable());w(this,"_hasCriteria$",new O.BehaviorSubject(!1));w(this,"hasCriteria$",this._hasCriteria$.asObservable());w(this,"_filterColumnByIndex",new Map);w(this,"_alreadyFilteredOutRows",H());w(this,"_range");this.unitId=e,this.subUnitId=t,this._worksheet=r}get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete()}serialize(){const e={ref:u.Rectangle.clone(this._range),filterColumns:this._getAllFilterColumns(!0).sort(([t],[r])=>t-r).map(([t,r])=>r.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(e,t,r,s){const o=new P(e,t,r);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.forEach(r=>this._setCriteriaWithoutReCalc(r.colId,r)),e.cachedFilteredOut&&(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw new Error("[FilterModel] could not get range before a range is set!");return this._range}getFilteredOutRowsExceptCol(e){return this._getAllFilterColumns(!0).filter(([t])=>t!==e).reduce((t,[,r])=>{const s=r.calc({getAlreadyFilteredOutRows:()=>t});return s?u.mergeSets(t,s):t},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,r])=>{r.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,r=!1){if(!this._range)throw new Error("[FilterModel] could not set criteria before a range is set!");if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),r&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),r&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))!=null?t:null}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){const t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([r,s])=>s)}_reCalcAllColumns(){this._alreadyFilteredOutRows=H(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns()}_setCriteriaWithoutReCalc(e,t){const r=this._range;if(!r)throw new Error("[FilterModel] could not set criteria before a range is set!");const{startColumn:s,endColumn:o}=r;if(e>o||e<s)throw new Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);let l;this._filterColumnByIndex.has(e)?l=this._filterColumnByIndex.get(e):(l=new 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)=>u.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=u.mergeSets(this._alreadyFilteredOutRows,r))}}}class ae extends u.Disposable{constructor(e,t,r,s,o){super();w(this,"_filteredOutRows",null);w(this,"_filterFn",null);w(this,"_range",null);w(this,"_column",0);w(this,"_filterByValues",!1);this.unitId=e,this.subUnitId=t,this._worksheet=r,this._criteria=s,this._filterColumnContext=o}get filteredOutRows(){return this._filteredOutRows}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 u.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 u.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw new Error("[FilterColumn] cannot calculate without a filter fn!");if(!this._range)throw new Error("[FilterColumn] cannot calculate without a range!");if(typeof this._column!="number")throw new TypeError("[FilterColumn] cannot calculate without a column offset!");const t=this._column,r={startColumn:t,endColumn:t,startRow:this._range.startRow+1,endRow:this._range.endRow},s=new Set,o=e.getAlreadyFilteredOutRows();for(const l of this._worksheet.iterateByColumn(r,!1,!1)){const{row:a,rowSpan:c,col:m}=l;if(o.has(a)&&(!c||c===1))continue;const d=this._filterByValues?u.extractPureTextFromCell(this._worksheet.getCell(a,m)):Te(this._worksheet,a,m);if(!this._filterFn(d)&&(s.add(a),c))for(let h=1;h<c;h++)s.add(a+h)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=Fe(this._criteria),this._filterByValues=!!this._criteria.filters)}}function Fe(i){if(i.filters)return ve(i.filters);if(i.customFilters)return we(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function ve(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 we(i){const n=i.customFilters.map(e=>Oe(e));return ye(n)?i.and?Me(n):Ee(n):n[0]}function Me(i){const[n,e]=i;return t=>n(t)&&e(t)}function Ee(i){const[n,e]=i;return t=>n(t)||e(t)}function ye(i){return i.length===2}function Oe(i){const n=i.val;if(i.operator===T.NOT_EQUALS&&!Q(n))return r=>D.fn(r,n);if(Re(i.operator)){if(!Q(n))return()=>!1;const r=z(i.operator),s=Number(n);return o=>r.fn(o,s)}const e=z(i.operator);return t=>e.fn(t,n)}function Te(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?G(t):r?t.t===u.CellValueType.NUMBER&&typeof t.v=="string"?r.v:G(r):null}function G(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===u.CellValueType.BOOLEAN?e.toUpperCase():e:typeof e=="number"?i.t===u.CellValueType.BOOLEAN?e?"TRUE":"FALSE":e:typeof e=="boolean"?e?"TRUE":"FALSE":""}var Ie=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,Ne=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ae(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&Ie(n,e,r),r},j=(i,n)=>(e,t)=>n(e,t,i);const V="SHEET_FILTER_PLUGIN";exports.SheetsFilterService=class extends u.Disposable{constructor(e,t,r){super();w(this,"_filterModels",new Map);w(this,"_loadedUnitId$",new O.BehaviorSubject(null));w(this,"loadedUnitId$",this._loadedUnitId$.asObservable());w(this,"_errorMsg$",new O.BehaviorSubject(null));w(this,"errorMsg$",this._errorMsg$.asObservable());w(this,"_activeFilterModel$",new O.BehaviorSubject(null));w(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(u.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(u.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(O.filter(([e])=>e.type===u.CommandType.MUTATION&&k.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(u.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=P.deserialize(e,s,r.getSheetBySheetId(s),o);this._cacheFilterModel(e,s,l)})}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:V,businesses:[u.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=Ne([j(0,u.IResourceManagerService),j(1,u.IUniverInstanceService),j(2,u.ICommandService)],exports.SheetsFilterService);const R={id:Y,type:u.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,range:r}=n;return i.get(exports.SheetsFilterService).ensureFilterModel(t,e).setRange(r),!0}},p={id:K,type:u.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}},y={id:X,type:u.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(exports.SheetsFilterService).removeFilterModel(e,t)}},$={id:Z,type:u.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}};function xe(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 xe(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 Ue=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,Pe=(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=(t?o(n,e,r):o(r))||r);return t&&r&&Ue(n,e,r),r},U=(i,n)=>(e,t)=>n(e,t,i);let B=class extends u.Disposable{constructor(n,e,t,r,s){super();w(this,"_disposableCollection",new u.DisposableCollection);this._commandService=n,this._sheetInterceptorService=e,this._sheetsFilterService=t,this._univerInstanceService=r,this._refRangeService=s,this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener(),this._initErrorHandling()}_initCommands(){[p,R,$,y].forEach(n=>this.disposeWithMe(this._commandService.registerCommand(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===R.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(e.unitId,e.subUnitId)}})),this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe(n=>{if(n){const e=this._univerInstanceService.getUniverSheetInstance(n),t=e==null?void 0:e.getActiveSheet();t&&this._registerRefRange(n,t.getSheetId())}}))}_registerRefRange(n,e){var l;this._disposableCollection.dispose();const t=this._univerInstanceService.getUniverSheetInstance(n),r=t==null?void 0:t.getSheetBySheetId(e);if(!t||!r)return;const s=(l=this._sheetsFilterService.getFilterModel(n,e))==null?void 0:l.getRange(),o=a=>{switch(a.id){case S.InsertRowCommand.id:{const c=a.params,m=c.unitId||n,d=c.subUnitId||e;return this._handleInsertRowCommand(c,m,d)}case S.InsertColCommand.id:{const c=a.params,m=c.unitId||n,d=c.subUnitId||e;return this._handleInsertColCommand(c,m,d)}case S.RemoveColCommand.id:{const c=a.params;return this._handleRemoveColCommand(c,n,e)}case S.RemoveRowCommand.id:{const c=a.params;return this._handleRemoveRowCommand(c,n,e)}case S.EffectRefRangId.MoveColsCommandId:{const c=a.params;return this._handleMoveColsCommand(c,n,e)}case S.EffectRefRangId.MoveRowsCommandId:{const c=a.params;return this._handleMoveRowsCommand(c,n,e)}case S.MoveRangeCommand.id:{const c=a.params;return this._handleMoveRangeCommand(c,n,e)}}return{redos:[],undos:[]}};s&&this._disposableCollection.add(this._refRangeService.registerRefRange(s,o,n,e))}_getUpdateFilter(n){const{id:e}=n;switch(e){case S.RemoveSheetCommand.id:{const t=n.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case S.CopySheetCommand.id:{const t=n.params,{targetSubUnitId:r,unitId:s,subUnitId:o}=t;return!s||!o||!r?this._handleNull():this._handleCopySheetCommand(s,o,r)}}return{redos:[],undos:[]}}_handleInsertColCommand(n,e,t){var _;const r=this._sheetsFilterService.getFilterModel(e,t),s=(_=r==null?void 0:r.getRange())!=null?_:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:a,endColumn:c}=n.range,m=c-a+1;if(c>l)return this._handleNull();const d=[],h=[],g=a,C={unitId:e,subUnitId:t,range:{...s,startColumn:a<=o?o+m:o,endColumn:l+m}},F={unitId:e,subUnitId:t,range:s};d.push({id:R.id,params:C}),h.push({id:R.id,params:F});const v=r.getAllFilterColumns().filter(f=>f[0]>=g);if(v.length!==0){const{newRange:f,oldRange:E}=this.moveCriteria(e,t,v,m);d.push(...f.redos,...E.redos),h.push(...f.undos,...E.undos)}return{redos:N(d),undos:N(h)}}_handleInsertRowCommand(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,{startRow:a,endRow:c}=n.range,m=c-a+1;if(c>l)return this._handleNull();const d=[],h=[],g={unitId:e,subUnitId:t,range:{...s,startRow:a<=o?o+m:o,endRow:l+m}},C={unitId:e,subUnitId:t,range:s};return d.push({id:R.id,params:g}),h.push({id:R.id,params:C}),{redos:N(d),undos:N(h)}}_handleRemoveColCommand(n,e,t){var v;const r=this._sheetsFilterService.getFilterModel(e,t),s=(v=r==null?void 0:r.getRange())!=null?v:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:a,endColumn:c}=n.range;if(a>l)return this._handleNull();const m=[],d=[],h=c<o?0:Math.min(c,l)-Math.max(a,o)+1,g=c-a+1,C=r.getAllFilterColumns();C.forEach(_=>{const[f,E]=_;f<=c&&f>=a&&(m.push({id:p.id,params:{unitId:e,subUnitId:t,col:f,criteria:null}}),d.push({id:p.id,params:{unitId:e,subUnitId:t,col:f,criteria:{...E.serialize(),colId:f}}}))});const F=C.filter(_=>{const[f,E]=_;return f>c});let M={undos:[],redos:[]};if(F.length>0){const{oldRange:_,newRange:f}=this.moveCriteria(e,t,F,-g);M=f,m.push(..._.redos),d.unshift(..._.undos)}if(h===l-o+1){const _={unitId:e,subUnitId:t};m.push({id:y.id,params:_}),d.unshift({id:R.id,params:{range:s,unitId:e,subUnitId:t}})}else{const _=o<=a?o:h===0?o-g:a,f=o<=a?l-h:l-g,E={unitId:e,subUnitId:t,range:{...s,startColumn:_,endColumn:f}};m.push({id:R.id,params:E}),d.unshift({id:R.id,params:{range:s,unitId:e,subUnitId:t}}),m.push(...M.redos),d.unshift(...M.undos)}return{undos:d,redos:m}}_handleRemoveRowCommand(n,e,t){var F;const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange(),{startRow:o,endRow:l}=s,{startRow:a,endRow:c}=n.range;if(a>l)return this._handleNull();if(c<o)return{undos:[{id:R.id,params:{range:s,unitId:e,subUnitId:t}}],redos:[{id:R.id,params:{range:{...s,startRow:o-(c-a+1),endRow:l-(c-a+1)},unitId:e,subUnitId:t}}]};const m=[],d=[],h=r.getAllFilterColumns(),g=o<=c&&o>=a;d.push({id:R.id,params:{range:s,unitId:e,subUnitId:t}});const C=Math.min(c,l)-Math.max(a,o)+1;if(C===l-o+1||g){const M={unitId:e,subUnitId:t};m.push({id:y.id,params:M}),h.forEach(v=>{const[_,f]=v,E={unitId:e,subUnitId:t,col:_,criteria:{...f.serialize(),colId:_}};d.push({id:p.id,params:E})})}else{const M=(F=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:F.getSheetBySheetId(t);if(!M)return this._handleNull();const v=[];for(let I=a;I<=c;I++)M.getRowFiltered(I)&&v.push(I);const _=Math.min(o,a),f=_+(l-o)-C+v.length,E={unitId:e,subUnitId:t,range:{...s,startRow:_,endRow:f}};m.push({id:R.id,params:E})}return{undos:N(d),redos:N(m)}}_handleMoveColsCommand(n,e,t){var _;const r=this._sheetsFilterService.getFilterModel(e,t),s=(_=r==null?void 0:r.getRange())!=null?_:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{fromRange:a,toRange:c}=n;if(a.endColumn<o&&c.startColumn<=o||a.startColumn>l&&c.endColumn>l)return this._handleNull();const m=[],d=[],h={};for(let f=o;f<=l;f++)h[f]={colIndex:f,filter:r.getFilterColumn(f)};u.moveMatrixArray(a.startColumn,a.endColumn-a.startColumn+1,c.startColumn,h);let g=s.startColumn,C=s.endColumn;o>=a.startColumn&&o<=a.endColumn&&c.startColumn>a.startColumn&&a.endColumn<l&&(g=a.endColumn+1),l>=a.startColumn&&l<=a.endColumn&&c.startColumn<a.startColumn&&a.startColumn>o&&(C=a.startColumn-1);const F=Object.keys(h).map(f=>Number(f)),M=F.find(f=>h[f].colIndex===C),v=F.find(f=>h[f].colIndex===g);if(F.forEach(f=>{var W,q;const{colIndex:E,filter:I}=h[f],A=f;if(I){if(A>=v&&A<=M){const L={unitId:e,subUnitId:t,col:A,criteria:{...I.serialize(),colId:A}},he={unitId:e,subUnitId:t,col:A,criteria:r.getFilterColumn(A)?{...(W=r.getFilterColumn(A))==null?void 0:W.serialize(),colId:A}:null};m.push({id:p.id,params:L}),d.push({id:p.id,params:he})}if(!((q=h[E])!=null&&q.filter)){const L={unitId:e,subUnitId:t,col:E,criteria:null};m.push({id:p.id,params:L}),d.push({id:p.id,params:{unitId:e,subUnitId:t,col:E,criteria:{...I.serialize(),colId:E}}})}}}),o!==v||l!==M){const f={unitId:e,subUnitId:t,range:{...s,startColumn:v,endColumn:M}};m.unshift({id:R.id,params:f}),d.unshift({id:R.id,params:{range:s,unitId:e,subUnitId:t}})}return{undos:d,redos:m}}_handleMoveRowsCommand(n,e,t){var _;const r=this._sheetsFilterService.getFilterModel(e,t),s=(_=r==null?void 0:r.getRange())!=null?_:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{fromRange:a,toRange:c}=n;if(a.endRow<o&&c.startRow<=o||a.startRow>l&&c.endRow>l)return this._handleNull();const m=[],d=[],h={};for(let f=o;f<=l;f++)h[f]={oldIndex:f};const g=o;let C=l;l>=a.startRow&&l<=a.endRow&&c.startRow<a.startRow&&a.startRow>o&&(C=a.startRow-1),u.moveMatrixArray(a.startRow,a.endRow-a.startRow+1,c.startRow,h);const F=Object.keys(h).map(f=>Number(f)),M=F.find(f=>h[f].oldIndex===C),v=F.find(f=>h[f].oldIndex===g);if(o!==v||l!==M){const f={unitId:e,subUnitId:t,range:{...s,startRow:v,endRow:M}};m.push({id:R.id,params:f},{id:$.id,params:{unitId:e,subUnitId:t}}),d.push({id:R.id,params:{range:s,unitId:e,subUnitId:t}},{id:$.id,params:{unitId:e,subUnitId:t}})}return{redos:m,undos:d}}_handleMoveRangeCommand(n,e,t){const{fromRange:r,toRange:s}=n,o=this._sheetsFilterService.getFilterModel(e,t);if(!o)return this._handleNull();const l=o.getRange();if(!l)return this._handleNull();const a=[],c=[];if(u.Rectangle.contains(r,l)){const m=l.startRow-r.startRow,d=l.startColumn-r.startColumn,h={startRow:s.startRow+m,startColumn:s.startColumn+d,endRow:s.startRow+m+(l.endRow-l.startRow),endColumn:s.startColumn+d+(l.endColumn-l.startColumn)},g={id:y.id,params:{unitId:e,subUnitId:t}},C={id:R.id,params:{unitId:e,subUnitId:t,range:h}},F={id:R.id,params:{unitId:e,subUnitId:t,range:l}};a.push(g,C),c.push(g,F);const M=o.getAllFilterColumns(),v=s.startColumn-r.startColumn;M.forEach(_=>{const[f,E]=_;E&&(a.push({id:p.id,params:{unitId:e,subUnitId:t,col:f+v,criteria:{...E.serialize(),colId:f+v}}}),c.push({id:p.id,params:{unitId:e,subUnitId:t,col:f,criteria:{...E.serialize(),colId:f}}}))})}else if(u.Rectangle.intersects(s,l)){const m={...l,endRow:Math.max(l.endRow,s.endRow)};a.push({id:R.id,params:{unitId:e,subUnitId:t,range:m}}),c.push({id:R.id,params:{unitId:e,subUnitId:t,range:l}})}return{redos:a,undos:c}}_handleRemoveSheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[];return r.getAllFilterColumns().forEach(([c,m])=>{l.push({id:p.id,params:{unitId:e,subUnitId:t,col:c,criteria:{...m.serialize(),colId:c}}})}),o.push({id:y.id,params:{unitId:e,subUnitId:t,range:s}}),l.unshift({id:R.id,params:{range:s,unitId:e,subUnitId:t}}),{undos:l,redos:o}}_handleCopySheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(n,e);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[],a=[],c=[];return r.getAllFilterColumns().forEach(([d,h])=>{o.push({id:p.id,params:{unitId:n,subUnitId:t,col:d,criteria:{...h.serialize(),colId:d}}}),a.push({id:p.id,params:{unitId:n,subUnitId:t,col:d,criteria:null}})}),a.push({id:y.id,params:{unitId:n,subUnitId:t,range:s}}),o.unshift({id:R.id,params:{range:s,unitId:n,subUnitId:t}}),{undos:l,redos:o,preUndos:a,preRedos:c}}_handleNull(){return{redos:[],undos:[]}}_initRowFilteredInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(S.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(n,e)=>{var t,r;return n?!0:(r=(t=this._sheetsFilterService.getFilterModel(e.unitId,e.subUnitId))==null?void 0:t.isRowFiltered(e.row))!=null?r:!1}}))}moveCriteria(n,e,t,r){const s={unitId:n,subUnitId:e,criteria:null,col:-1},o=[],l=[],a=[],c=[];return t.forEach(m=>{const[d,h]=m;l.push({id:p.id,params:{...s,col:d}}),o.push({id:p.id,params:{...s,col:d,criteria:{...h.serialize(),colId:d}}})}),t.forEach(m=>{const[d,h]=m;c.push({id:p.id,params:{...s,col:d+r,criteria:{...h.serialize(),colId:d+r}}}),a.push({id:p.id,params:{...s,col:d+r,criteria:null}})}),{newRange:{redos:c,undos:a},oldRange:{redos:l,undos:o}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{var c,m;const{unitId:t,subUnitId:r}=n.params||{},s=this._sheetsFilterService.getFilterModel(t,r);if(!s)return;const o=Array.from(s.filteredOutRows).sort((d,h)=>d-h),l=[];let a=!1;if(n.id===S.RemoveRowMutation.id){const{startRow:d,endRow:h}=n.params.range,g=o.filter(C=>C>=d&&C<=h);o.forEach(C=>{if(C<d)l.push(C);else if(a=!0,C<=h){const F=Math.max(d,l.length?l[l.length-1]+1:d);l.push(F)}else l.push(C-(h-d+1-g.length))})}if(n.id===S.InsertRowMutation.id){const{startRow:d,endRow:h}=n.params.range;o.forEach(g=>{g>=d?(a=!0,l.push(g+(h-d+1))):l.push(g)})}if(a&&(s.filteredOutRows=new Set(l)),n.id===S.SetRangeValuesMutation.id&&!(e!=null&&e.onlyLocal)){const d=this._getExtendRegion(t,r);if(d){const h=n.params.cellValue;if(h)for(let g=d.startColumn;g<=d.endColumn;g++){const C=(c=h==null?void 0:h[d.startRow])==null?void 0:c[g];if(C&&this._cellHasValue(C)){const F=(m=this._univerInstanceService.getUnit(t))==null?void 0:m.getSheetBySheetId(r);if(F){const M=S.expandToContinuousRange(d,{down:!0},F),v=this._sheetsFilterService.getFilterModel(t,r),_=v.getRange();v.setRange({..._,endRow:M.endRow}),this._registerRefRange(t,r)}}}}}}))}_getExtendRegion(n,e){var a;const t=this._sheetsFilterService.getFilterModel(n,e);if(!t)return null;const r=(a=this._univerInstanceService.getUnit(n))==null?void 0:a.getSheetBySheetId(e);if(!r)return null;const s=t.getRange();if(!s)return null;const o=r.getRowCount()-1,l=r.getRowManager();for(let c=s.endRow+1;c<=o;c++)if(l.getRowRawVisible(c))return{startRow:c,endRow:c,startColumn:s.startColumn,endColumn:s.endColumn};return null}_initErrorHandling(){this.disposeWithMe(this._commandService.beforeCommandExecuted(n=>{const e=n.params,t=S.getSheetCommandTarget(this._univerInstanceService);if(!t)return;const{subUnitId:r,unitId:s}=t,o=this._sheetsFilterService.getFilterModel(s,r);if(!o)return;const l=o.getRange();if(n.id===S.MoveRowsCommand.id&&e.fromRange.startRow<=l.startRow&&e.fromRange.endRow<l.endRow&&e.fromRange.endRow>=l.startRow)throw this._sheetsFilterService.setFilterErrorMsg("sheets-filter.msg.filter-header-forbidden"),new Error("[SheetsFilterController]: Cannot move header row of filter")}))}_cellHasValue(n){const e=Object.values(n);return!(e.length===0||e.every(t=>t==null))}};B=Pe([U(0,u.ICommandService),U(1,u.Inject(S.SheetInterceptorService)),U(2,u.Inject(exports.SheetsFilterService)),U(3,u.IUniverInstanceService),U(4,u.Inject(S.RefRangeService))],B);var be=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Le=(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=(t?o(n,e,r):o(r))||r);return t&&r&&be(n,e,r),r},J=(i,n)=>(e,t)=>n(e,t,i),b;exports.UniverSheetsFilterPlugin=(b=class extends u.Plugin{constructor(n=Ce,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=this._config;this._configService.setConfig(ge,r)}onStarting(){[[exports.SheetsFilterService],[B]].forEach(n=>this._injector.add(n))}onReady(){this._injector.get(B)}},w(b,"type",u.UniverInstanceType.UNIVER_SHEET),w(b,"pluginName",V),b);exports.UniverSheetsFilterPlugin=Le([J(1,u.Inject(u.Injector)),J(2,u.IConfigService)],exports.UniverSheetsFilterPlugin);const ce={id:"sheet.command.set-filter-range",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(u.ICommandService),r=i.get(u.IUndoRedoService),s=i.get(u.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 g=i.get(u.ErrorService),C=i.get(u.LocaleService);return g.emit(C.t("sheets-filter.command.not-valid-filter-range")),!1}const d={id:R.id,params:{unitId:o,subUnitId:l,range:a}},h=t.syncExecuteCommand(d.id,d.params);return h&&r.pushUndoRedo({unitID:o,undoMutations:[{id:y.id,params:{unitId:o,subUnitId:l}}],redoMutations:[d]}),h}},de={id:"sheet.command.remove-sheet-filter",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(u.IUniverInstanceService),t=i.get(exports.SheetsFilterService),r=i.get(u.ICommandService),s=i.get(u.IUndoRedoService),o=S.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,c=t.getFilterModel(l,a);if(!c)return!1;const m=c==null?void 0:c.serialize(),d=Ve(l,a,m),h=r.syncExecuteCommand(y.id,{unitId:l,subUnitId:a});return h&&s.pushUndoRedo({unitID:l,undoMutations:d,redoMutations:[{id:y.id,params:{unitId:l,subUnitId:a}}]}),h}},He={id:"sheet.command.smart-toggle-filter",type:u.CommandType.COMMAND,handler:async i=>{const n=i.get(u.IUniverInstanceService),e=i.get(exports.SheetsFilterService),t=i.get(u.ICommandService),r=n.getCurrentUnitForType(u.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(de.id,{unitId:o,subUnitId:l});const m=i.get(S.SheetsSelectionsService).getCurrentLastSelection();if(!m)return!1;const d=m.range,h=S.isSingleCellSelection(m)?S.expandToContinuousRange(d,{left:!0,right:!0,up:!0,down:!0},s):d;return t.executeCommand(ce.id,{unitId:o,subUnitId:l,range:h})}},je={id:"sheet.command.set-filter-criteria",type:u.CommandType.COMMAND,handler:async(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(u.ICommandService),r=i.get(u.IUndoRedoService),{unitId:s,subUnitId:o,col:l,criteria:a}=n,c=e.getFilterModel(s,o);if(!c)return!1;const m=c.getRange();if(!m||l<m.startColumn||l>m.endColumn)return!1;const d=c.getFilterColumn(l),h=qe(s,o,l,d),g={id:p.id,params:{unitId:s,subUnitId:o,col:l,criteria:a}},C=t.syncExecuteCommand(g.id,g.params);return C&&r.pushUndoRedo({unitID:s,undoMutations:[h],redoMutations:[g]}),C}},ze={id:"sheet.command.clear-filter-criteria",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(u.IUndoRedoService),r=i.get(u.ICommandService),s=i.get(u.IUniverInstanceService),o=S.getSheetCommandTarget(s,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,c=e.getFilterModel(o.unitId,o.subUnitId);if(!c)return!1;const m=c.serialize(),d=ue(l,a,m),h=We(l,a,m);return u.sequenceExecute(h,r).result?(t.pushUndoRedo({unitID:l,undoMutations:d,redoMutations:h}),!0):!1}},De={id:"sheet.command.re-calc-filter",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(exports.SheetsFilterService),t=i.get(u.ICommandService),r=i.get(u.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($.id,{unitId:o,subUnitId:l}):!1}};function Ve(i,n,e){const t=[],r={id:R.id,params:{unitId:i,subUnitId:n,range:e.ref}};return t.push(r),ue(i,n,e).forEach(o=>t.push(o)),t}function ue(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 We(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 qe(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}}}exports.ClearSheetsFilterCriteriaCommand=ze;exports.CustomFilterOperator=T;exports.FILTER_MUTATIONS=k;exports.FilterColumn=ae;exports.FilterModel=P;exports.ReCalcSheetsFilterCommand=De;exports.ReCalcSheetsFilterMutation=$;exports.RemoveSheetFilterCommand=de;exports.RemoveSheetsFilterMutation=y;exports.SHEET_FILTER_SNAPSHOT_ID=V;exports.SetSheetFilterRangeCommand=ce;exports.SetSheetsFilterCriteriaCommand=je;exports.SetSheetsFilterCriteriaMutation=p;exports.SetSheetsFilterRangeMutation=R;exports.SmartToggleSheetsFilterCommand=He;exports.equals=ie;exports.getCustomFilterFn=z;exports.greaterThan=ee;exports.greaterThanOrEqualTo=te;exports.lessThan=re;exports.lessThanOrEqualTo=ne;exports.notEquals=D;
|
package/lib/es/index.js
CHANGED
|
@@ -1,94 +1,71 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var w = (i, r, e) =>
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type: E.MUTATION,
|
|
17
|
-
handler: (i, r) => {
|
|
18
|
-
const { subUnitId: e, unitId: t, criteria: n, col: s, reCalc: o = !0 } = r, a = i.get(M).getFilterModel(t, e);
|
|
19
|
-
return a ? (a.setCriteria(s, n, o), !0) : !1;
|
|
20
|
-
}
|
|
21
|
-
}, O = {
|
|
22
|
-
id: "sheet.mutation.remove-filter",
|
|
23
|
-
type: E.MUTATION,
|
|
24
|
-
handler: (i, r) => {
|
|
25
|
-
const { unitId: e, subUnitId: t } = r;
|
|
26
|
-
return i.get(M).removeFilterModel(e, t);
|
|
27
|
-
}
|
|
28
|
-
}, L = {
|
|
29
|
-
id: "sheet.mutation.re-calc-filter",
|
|
30
|
-
type: E.MUTATION,
|
|
31
|
-
handler: (i, r) => {
|
|
32
|
-
const { unitId: e, subUnitId: t } = r, s = i.get(M).getFilterModel(e, t);
|
|
33
|
-
return s ? (s.reCalc(), !0) : !1;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var T = /* @__PURE__ */ ((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 || {});
|
|
37
|
-
const Ye = {
|
|
38
|
-
operator: T.GREATER_THAN,
|
|
1
|
+
var pe = Object.defineProperty;
|
|
2
|
+
var Fe = (i, r, e) => r in i ? pe(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e;
|
|
3
|
+
var w = (i, r, e) => Fe(i, typeof r != "symbol" ? r + "" : r, e);
|
|
4
|
+
import { isNumeric as we, Disposable as V, Rectangle as Y, mergeSets as Q, Tools as k, extractPureTextFromCell as Se, CellValueType as K, UniverInstanceType as U, fromCallback as ve, CommandType as E, IResourceManagerService as Me, IUniverInstanceService as x, ICommandService as T, Inject as z, DisposableCollection as Ee, moveMatrixArray as ee, Plugin as Oe, Injector as ye, IConfigService as Ae, IUndoRedoService as j, ErrorService as Te, LocaleService as Ne, sequenceExecute as xe } from "@univerjs/core";
|
|
5
|
+
import { SheetInterceptorService as Ie, RefRangeService as $e, SetWorksheetActiveOperation as Pe, CopySheetCommand as Ue, RemoveSheetCommand as be, INTERCEPTOR_POINT as Le, RemoveRowMutation as Be, InsertRowMutation as ze, SetRangeValuesMutation as He, expandToContinuousRange as le, getSheetCommandTarget as L, MoveRowsCommand as De, MoveRangeCommand as We, EffectRefRangId as te, RemoveRowCommand as Ve, RemoveColCommand as je, InsertColCommand as qe, InsertRowCommand as Qe, SheetsSelectionsService as Ge, isSingleCellSelection as Je } from "@univerjs/sheets";
|
|
6
|
+
import { BehaviorSubject as b, merge as Ye, filter as Ke, switchMap as Xe, of as Ze } from "rxjs";
|
|
7
|
+
const ke = "sheets-filter.config", et = {}, ae = "sheet.mutation.set-filter-range", ce = "sheet.mutation.set-filter-criteria", de = "sheet.mutation.remove-filter", ue = "sheet.mutation.re-calc-filter", tt = /* @__PURE__ */ new Set([
|
|
8
|
+
ae,
|
|
9
|
+
ce,
|
|
10
|
+
de,
|
|
11
|
+
ue
|
|
12
|
+
]);
|
|
13
|
+
var N = /* @__PURE__ */ ((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))(N || {});
|
|
14
|
+
const rt = {
|
|
15
|
+
operator: N.GREATER_THAN,
|
|
39
16
|
fn: (i, r) => $(i) ? i > r : !1
|
|
40
|
-
},
|
|
41
|
-
operator:
|
|
17
|
+
}, nt = {
|
|
18
|
+
operator: N.GREATER_THAN_OR_EQUAL,
|
|
42
19
|
fn: (i, r) => $(i) ? i >= r : !1
|
|
43
|
-
},
|
|
44
|
-
operator:
|
|
20
|
+
}, it = {
|
|
21
|
+
operator: N.LESS_THAN,
|
|
45
22
|
fn: (i, r) => $(i) ? i < r : !1
|
|
46
|
-
},
|
|
47
|
-
operator:
|
|
23
|
+
}, st = {
|
|
24
|
+
operator: N.LESS_THAN_OR_EQUAL,
|
|
48
25
|
fn: (i, r) => $(i) ? i <= r : !1
|
|
49
|
-
},
|
|
50
|
-
operator:
|
|
26
|
+
}, ot = {
|
|
27
|
+
operator: N.EQUAL,
|
|
51
28
|
fn: (i, r) => $(i) ? i === r : !1
|
|
52
|
-
},
|
|
53
|
-
operator:
|
|
29
|
+
}, he = {
|
|
30
|
+
operator: N.NOT_EQUALS,
|
|
54
31
|
fn: (i, r) => {
|
|
55
32
|
if (typeof r == "string") {
|
|
56
33
|
if (r === " ")
|
|
57
34
|
return i != null;
|
|
58
|
-
const e =
|
|
59
|
-
return e &&
|
|
35
|
+
const e = me(i);
|
|
36
|
+
return e && dt(r) ? !ge(r).test(e) : e !== r;
|
|
60
37
|
}
|
|
61
38
|
return $(i) ? i !== r : !0;
|
|
62
39
|
}
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
|
|
40
|
+
}, fe = /* @__PURE__ */ new Map([]), lt = [rt, nt, it, st, ot, he];
|
|
41
|
+
lt.forEach((i) => {
|
|
42
|
+
fe.set(i.operator, i);
|
|
66
43
|
});
|
|
67
|
-
function
|
|
44
|
+
function at(i) {
|
|
68
45
|
return !!i;
|
|
69
46
|
}
|
|
70
|
-
const
|
|
47
|
+
const ct = {
|
|
71
48
|
fn: (i, r) => {
|
|
72
|
-
const e =
|
|
73
|
-
return e === null ? r === "" :
|
|
49
|
+
const e = me(i);
|
|
50
|
+
return e === null ? r === "" : ge(r).test(e);
|
|
74
51
|
}
|
|
75
52
|
};
|
|
76
53
|
function re(i) {
|
|
77
|
-
return i ?
|
|
54
|
+
return i ? fe.get(i) : ct;
|
|
78
55
|
}
|
|
79
56
|
function $(i) {
|
|
80
57
|
return typeof i == "number";
|
|
81
58
|
}
|
|
82
59
|
function ne(i) {
|
|
83
|
-
return !!(typeof i == "number" || typeof i == "string" &&
|
|
60
|
+
return !!(typeof i == "number" || typeof i == "string" && we(i));
|
|
84
61
|
}
|
|
85
|
-
function
|
|
62
|
+
function me(i) {
|
|
86
63
|
return typeof i == "boolean" || i == null ? null : typeof i == "string" ? i : i.toString();
|
|
87
64
|
}
|
|
88
|
-
function
|
|
65
|
+
function dt(i) {
|
|
89
66
|
return typeof i == "number" ? !1 : i.indexOf("*") !== -1 || i.indexOf("?") !== -1;
|
|
90
67
|
}
|
|
91
|
-
function
|
|
68
|
+
function ge(i) {
|
|
92
69
|
const r = i.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("?", ".").replace(/[*]/g, ".$&");
|
|
93
70
|
return new RegExp(`^${r}$`);
|
|
94
71
|
}
|
|
@@ -211,7 +188,7 @@ class D extends V {
|
|
|
211
188
|
if (e > o || e < s)
|
|
212
189
|
throw new Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);
|
|
213
190
|
let l;
|
|
214
|
-
this._filterColumnByIndex.has(e) ? l = this._filterColumnByIndex.get(e) : (l = new
|
|
191
|
+
this._filterColumnByIndex.has(e) ? l = this._filterColumnByIndex.get(e) : (l = new ut(
|
|
215
192
|
this.unitId,
|
|
216
193
|
this.subUnitId,
|
|
217
194
|
this._worksheet,
|
|
@@ -241,7 +218,7 @@ class D extends V {
|
|
|
241
218
|
}
|
|
242
219
|
}
|
|
243
220
|
}
|
|
244
|
-
class
|
|
221
|
+
class ut extends V {
|
|
245
222
|
constructor(e, t, n, s, o) {
|
|
246
223
|
super();
|
|
247
224
|
w(this, "_filteredOutRows", null);
|
|
@@ -306,7 +283,7 @@ class it extends V {
|
|
|
306
283
|
const { row: a, rowSpan: c, col: h } = l;
|
|
307
284
|
if (o.has(a) && (!c || c === 1))
|
|
308
285
|
continue;
|
|
309
|
-
const d = this._filterByValues ?
|
|
286
|
+
const d = this._filterByValues ? Se(this._worksheet.getCell(a, h)) : pt(this._worksheet, a, h);
|
|
310
287
|
if (!this._filterFn(d) && (s.add(a), c))
|
|
311
288
|
for (let u = 1; u < c; u++)
|
|
312
289
|
s.add(a + u);
|
|
@@ -314,40 +291,40 @@ class it extends V {
|
|
|
314
291
|
return s;
|
|
315
292
|
}
|
|
316
293
|
_generateFilterFn() {
|
|
317
|
-
this._criteria && (this._filterFn =
|
|
294
|
+
this._criteria && (this._filterFn = ht(this._criteria), this._filterByValues = !!this._criteria.filters);
|
|
318
295
|
}
|
|
319
296
|
}
|
|
320
|
-
function
|
|
297
|
+
function ht(i) {
|
|
321
298
|
if (i.filters)
|
|
322
|
-
return
|
|
299
|
+
return ft(i.filters);
|
|
323
300
|
if (i.customFilters)
|
|
324
|
-
return
|
|
301
|
+
return mt(i.customFilters);
|
|
325
302
|
throw new Error("[FilterModel]: other types of filters are not supported yet.");
|
|
326
303
|
}
|
|
327
|
-
function
|
|
304
|
+
function ft(i) {
|
|
328
305
|
const r = !!i.blank, e = new Set(i.filters);
|
|
329
306
|
return (t) => t === void 0 || t === "" ? r : e.has(typeof t == "string" ? t : `${t}`);
|
|
330
307
|
}
|
|
331
|
-
function
|
|
332
|
-
const r = i.customFilters.map((e) =>
|
|
333
|
-
return
|
|
308
|
+
function mt(i) {
|
|
309
|
+
const r = i.customFilters.map((e) => Ct(e));
|
|
310
|
+
return Rt(r) ? i.and ? gt(r) : _t(r) : r[0];
|
|
334
311
|
}
|
|
335
|
-
function
|
|
312
|
+
function gt(i) {
|
|
336
313
|
const [r, e] = i;
|
|
337
314
|
return (t) => r(t) && e(t);
|
|
338
315
|
}
|
|
339
|
-
function
|
|
316
|
+
function _t(i) {
|
|
340
317
|
const [r, e] = i;
|
|
341
318
|
return (t) => r(t) || e(t);
|
|
342
319
|
}
|
|
343
|
-
function
|
|
320
|
+
function Rt(i) {
|
|
344
321
|
return i.length === 2;
|
|
345
322
|
}
|
|
346
|
-
function
|
|
323
|
+
function Ct(i) {
|
|
347
324
|
const r = i.val;
|
|
348
|
-
if (i.operator ===
|
|
349
|
-
return (n) =>
|
|
350
|
-
if (
|
|
325
|
+
if (i.operator === N.NOT_EQUALS && !ne(r))
|
|
326
|
+
return (n) => he.fn(n, r);
|
|
327
|
+
if (at(i.operator)) {
|
|
351
328
|
if (!ne(r)) return () => !1;
|
|
352
329
|
const n = re(i.operator), s = Number(r);
|
|
353
330
|
return (o) => n.fn(o, s);
|
|
@@ -355,7 +332,7 @@ function ut(i) {
|
|
|
355
332
|
const e = re(i.operator);
|
|
356
333
|
return (t) => e.fn(t, r);
|
|
357
334
|
}
|
|
358
|
-
function
|
|
335
|
+
function pt(i, r, e) {
|
|
359
336
|
const t = i.getCell(r, e);
|
|
360
337
|
if (!t) return null;
|
|
361
338
|
const n = i.getCellRaw(r, e);
|
|
@@ -368,17 +345,12 @@ function ie(i) {
|
|
|
368
345
|
const e = i.v;
|
|
369
346
|
return typeof e == "string" ? i.t === K.BOOLEAN ? e.toUpperCase() : e : typeof e == "number" ? i.t === K.BOOLEAN ? e ? "TRUE" : "FALSE" : e : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : "";
|
|
370
347
|
}
|
|
371
|
-
var
|
|
372
|
-
for (var n = t > 1 ? void 0 : t ?
|
|
348
|
+
var Ft = Object.defineProperty, wt = Object.getOwnPropertyDescriptor, St = (i, r, e, t) => {
|
|
349
|
+
for (var n = t > 1 ? void 0 : t ? wt(r, e) : r, s = i.length - 1, o; s >= 0; s--)
|
|
373
350
|
(o = i[s]) && (n = (t ? o(r, e, n) : o(n)) || n);
|
|
374
|
-
return t && n &&
|
|
351
|
+
return t && n && Ft(r, e, n), n;
|
|
375
352
|
}, J = (i, r) => (e, t) => r(e, t, i);
|
|
376
|
-
const
|
|
377
|
-
R.id,
|
|
378
|
-
C.id,
|
|
379
|
-
O.id,
|
|
380
|
-
L.id
|
|
381
|
-
]), he = "SHEET_FILTER_PLUGIN";
|
|
353
|
+
const _e = "SHEET_FILTER_PLUGIN";
|
|
382
354
|
let M = class extends V {
|
|
383
355
|
constructor(r, e, t) {
|
|
384
356
|
super();
|
|
@@ -446,13 +418,13 @@ let M = class extends V {
|
|
|
446
418
|
}
|
|
447
419
|
_initActiveFilterModel() {
|
|
448
420
|
this.disposeWithMe(
|
|
449
|
-
|
|
421
|
+
Ye(
|
|
450
422
|
// source1: executing filter related mutations
|
|
451
|
-
|
|
423
|
+
ve(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(Ke(([r]) => r.type === E.MUTATION && tt.has(r.id))),
|
|
452
424
|
// source2: activate sheet changes
|
|
453
|
-
this._univerInstanceService.getCurrentTypeOfUnit$(U.UNIVER_SHEET).pipe(
|
|
425
|
+
this._univerInstanceService.getCurrentTypeOfUnit$(U.UNIVER_SHEET).pipe(Xe((r) => {
|
|
454
426
|
var e;
|
|
455
|
-
return (e = r == null ? void 0 : r.activeSheet$) != null ? e :
|
|
427
|
+
return (e = r == null ? void 0 : r.activeSheet$) != null ? e : Ze(null);
|
|
456
428
|
}))
|
|
457
429
|
).subscribe(() => this._updateActiveFilterModel())
|
|
458
430
|
);
|
|
@@ -475,7 +447,7 @@ let M = class extends V {
|
|
|
475
447
|
}
|
|
476
448
|
_initModel() {
|
|
477
449
|
this._resourcesManagerService.registerPluginResource({
|
|
478
|
-
pluginName:
|
|
450
|
+
pluginName: _e,
|
|
479
451
|
businesses: [U.UNIVER_SHEET],
|
|
480
452
|
toJson: (r) => this._serializeAutoFiltersForUnit(r),
|
|
481
453
|
parseJson: (r) => JSON.parse(r),
|
|
@@ -492,12 +464,41 @@ let M = class extends V {
|
|
|
492
464
|
this._filterModels.has(r) || this._filterModels.set(r, /* @__PURE__ */ new Map()), this._filterModels.get(r).set(e, t);
|
|
493
465
|
}
|
|
494
466
|
};
|
|
495
|
-
M =
|
|
496
|
-
J(0,
|
|
467
|
+
M = St([
|
|
468
|
+
J(0, Me),
|
|
497
469
|
J(1, x),
|
|
498
|
-
J(2,
|
|
470
|
+
J(2, T)
|
|
499
471
|
], M);
|
|
500
|
-
|
|
472
|
+
const R = {
|
|
473
|
+
id: ae,
|
|
474
|
+
type: E.MUTATION,
|
|
475
|
+
handler: (i, r) => {
|
|
476
|
+
const { subUnitId: e, unitId: t, range: n } = r;
|
|
477
|
+
return i.get(M).ensureFilterModel(t, e).setRange(n), !0;
|
|
478
|
+
}
|
|
479
|
+
}, p = {
|
|
480
|
+
id: ce,
|
|
481
|
+
type: E.MUTATION,
|
|
482
|
+
handler: (i, r) => {
|
|
483
|
+
const { subUnitId: e, unitId: t, criteria: n, col: s, reCalc: o = !0 } = r, a = i.get(M).getFilterModel(t, e);
|
|
484
|
+
return a ? (a.setCriteria(s, n, o), !0) : !1;
|
|
485
|
+
}
|
|
486
|
+
}, O = {
|
|
487
|
+
id: de,
|
|
488
|
+
type: E.MUTATION,
|
|
489
|
+
handler: (i, r) => {
|
|
490
|
+
const { unitId: e, subUnitId: t } = r;
|
|
491
|
+
return i.get(M).removeFilterModel(e, t);
|
|
492
|
+
}
|
|
493
|
+
}, H = {
|
|
494
|
+
id: ue,
|
|
495
|
+
type: E.MUTATION,
|
|
496
|
+
handler: (i, r) => {
|
|
497
|
+
const { unitId: e, subUnitId: t } = r, s = i.get(M).getFilterModel(e, t);
|
|
498
|
+
return s ? (s.reCalc(), !0) : !1;
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
function vt(i, r) {
|
|
501
502
|
for (let e = 0; e < i.length; e++) {
|
|
502
503
|
let t = e;
|
|
503
504
|
if (i[e])
|
|
@@ -507,24 +508,24 @@ function Rt(i, r) {
|
|
|
507
508
|
return i.filter((e) => e !== null);
|
|
508
509
|
}
|
|
509
510
|
function I(i) {
|
|
510
|
-
return
|
|
511
|
+
return vt(i, (r, e) => r.id === p.id && e.id === p.id && r.params.unitId === e.params.unitId && r.params.subUnitId === e.params.subUnitId && r.params.col === e.params.col);
|
|
511
512
|
}
|
|
512
|
-
var
|
|
513
|
-
for (var n = t > 1 ? void 0 : t ?
|
|
513
|
+
var Mt = Object.defineProperty, Et = Object.getOwnPropertyDescriptor, Ot = (i, r, e, t) => {
|
|
514
|
+
for (var n = t > 1 ? void 0 : t ? Et(r, e) : r, s = i.length - 1, o; s >= 0; s--)
|
|
514
515
|
(o = i[s]) && (n = (t ? o(r, e, n) : o(n)) || n);
|
|
515
|
-
return t && n &&
|
|
516
|
+
return t && n && Mt(r, e, n), n;
|
|
516
517
|
}, P = (i, r) => (e, t) => r(e, t, i);
|
|
517
518
|
let W = class extends V {
|
|
518
519
|
constructor(r, e, t, n, s) {
|
|
519
520
|
super();
|
|
520
|
-
w(this, "_disposableCollection", new
|
|
521
|
+
w(this, "_disposableCollection", new Ee());
|
|
521
522
|
this._commandService = r, this._sheetInterceptorService = e, this._sheetsFilterService = t, this._univerInstanceService = n, this._refRangeService = s, this._initCommands(), this._initRowFilteredInterceptor(), this._initInterceptors(), this._commandExecutedListener(), this._initErrorHandling();
|
|
522
523
|
}
|
|
523
524
|
_initCommands() {
|
|
524
525
|
[
|
|
525
|
-
|
|
526
|
+
p,
|
|
526
527
|
R,
|
|
527
|
-
|
|
528
|
+
H,
|
|
528
529
|
O
|
|
529
530
|
].forEach((r) => this.disposeWithMe(this._commandService.registerCommand(r)));
|
|
530
531
|
}
|
|
@@ -624,12 +625,12 @@ let W = class extends V {
|
|
|
624
625
|
startColumn: a <= o ? o + h : o,
|
|
625
626
|
endColumn: l + h
|
|
626
627
|
}
|
|
627
|
-
},
|
|
628
|
+
}, C = {
|
|
628
629
|
unitId: e,
|
|
629
630
|
subUnitId: t,
|
|
630
631
|
range: s
|
|
631
632
|
};
|
|
632
|
-
d.push({ id: R.id, params: g }), u.push({ id: R.id, params:
|
|
633
|
+
d.push({ id: R.id, params: g }), u.push({ id: R.id, params: C });
|
|
633
634
|
const F = n.getAllFilterColumns().filter((f) => f[0] >= m);
|
|
634
635
|
if (F.length !== 0) {
|
|
635
636
|
const { newRange: f, oldRange: v } = this.moveCriteria(e, t, F, h);
|
|
@@ -638,8 +639,8 @@ let W = class extends V {
|
|
|
638
639
|
return { redos: I(d), undos: I(u) };
|
|
639
640
|
}
|
|
640
641
|
_handleInsertRowCommand(r, e, t) {
|
|
641
|
-
var
|
|
642
|
-
const n = this._sheetsFilterService.getFilterModel(e, t), s = (
|
|
642
|
+
var C;
|
|
643
|
+
const n = this._sheetsFilterService.getFilterModel(e, t), s = (C = n == null ? void 0 : n.getRange()) != null ? C : null;
|
|
643
644
|
if (!n || !s)
|
|
644
645
|
return this._handleNull();
|
|
645
646
|
const { startRow: o, endRow: l } = s, { startRow: a, endRow: c } = r.range, h = c - a + 1;
|
|
@@ -674,15 +675,15 @@ let W = class extends V {
|
|
|
674
675
|
const h = [], d = [], u = c < o ? 0 : Math.min(c, l) - Math.max(a, o) + 1, m = c - a + 1, g = n.getAllFilterColumns();
|
|
675
676
|
g.forEach((_) => {
|
|
676
677
|
const [f, v] = _;
|
|
677
|
-
f <= c && f >= a && (h.push({ id:
|
|
678
|
+
f <= c && f >= a && (h.push({ id: p.id, params: { unitId: e, subUnitId: t, col: f, criteria: null } }), d.push({ id: p.id, params: { unitId: e, subUnitId: t, col: f, criteria: { ...v.serialize(), colId: f } } }));
|
|
678
679
|
});
|
|
679
|
-
const
|
|
680
|
+
const C = g.filter((_) => {
|
|
680
681
|
const [f, v] = _;
|
|
681
682
|
return f > c;
|
|
682
683
|
});
|
|
683
684
|
let S = { undos: [], redos: [] };
|
|
684
|
-
if (
|
|
685
|
-
const { oldRange: _, newRange: f } = this.moveCriteria(e, t,
|
|
685
|
+
if (C.length > 0) {
|
|
686
|
+
const { oldRange: _, newRange: f } = this.moveCriteria(e, t, C, -m);
|
|
686
687
|
S = f, h.push(..._.redos), d.unshift(..._.undos);
|
|
687
688
|
}
|
|
688
689
|
if (u === l - o + 1) {
|
|
@@ -705,7 +706,7 @@ let W = class extends V {
|
|
|
705
706
|
};
|
|
706
707
|
}
|
|
707
708
|
_handleRemoveRowCommand(r, e, t) {
|
|
708
|
-
var
|
|
709
|
+
var C;
|
|
709
710
|
const n = this._sheetsFilterService.getFilterModel(e, t);
|
|
710
711
|
if (!n)
|
|
711
712
|
return this._handleNull();
|
|
@@ -743,10 +744,10 @@ let W = class extends V {
|
|
|
743
744
|
col: _,
|
|
744
745
|
criteria: { ...f.serialize(), colId: _ }
|
|
745
746
|
};
|
|
746
|
-
d.push({ id:
|
|
747
|
+
d.push({ id: p.id, params: v });
|
|
747
748
|
});
|
|
748
749
|
} else {
|
|
749
|
-
const S = (
|
|
750
|
+
const S = (C = this._univerInstanceService.getUniverSheetInstance(e)) == null ? void 0 : C.getSheetBySheetId(t);
|
|
750
751
|
if (!S)
|
|
751
752
|
return this._handleNull();
|
|
752
753
|
const F = [];
|
|
@@ -786,8 +787,8 @@ let W = class extends V {
|
|
|
786
787
|
ee(a.startColumn, a.endColumn - a.startColumn + 1, c.startColumn, u);
|
|
787
788
|
let m = s.startColumn, g = s.endColumn;
|
|
788
789
|
o >= a.startColumn && o <= a.endColumn && c.startColumn > a.startColumn && a.endColumn < l && (m = a.endColumn + 1), l >= a.startColumn && l <= a.endColumn && c.startColumn < a.startColumn && a.startColumn > o && (g = a.startColumn - 1);
|
|
789
|
-
const
|
|
790
|
-
if (
|
|
790
|
+
const C = Object.keys(u).map((f) => Number(f)), S = C.find((f) => u[f].colIndex === g), F = C.find((f) => u[f].colIndex === m);
|
|
791
|
+
if (C.forEach((f) => {
|
|
791
792
|
var X, Z;
|
|
792
793
|
const { colIndex: v, filter: y } = u[f], A = f;
|
|
793
794
|
if (y) {
|
|
@@ -797,13 +798,13 @@ let W = class extends V {
|
|
|
797
798
|
subUnitId: t,
|
|
798
799
|
col: A,
|
|
799
800
|
criteria: { ...y.serialize(), colId: A }
|
|
800
|
-
},
|
|
801
|
+
}, Ce = {
|
|
801
802
|
unitId: e,
|
|
802
803
|
subUnitId: t,
|
|
803
804
|
col: A,
|
|
804
805
|
criteria: n.getFilterColumn(A) ? { ...(X = n.getFilterColumn(A)) == null ? void 0 : X.serialize(), colId: A } : null
|
|
805
806
|
};
|
|
806
|
-
h.push({ id:
|
|
807
|
+
h.push({ id: p.id, params: q }), d.push({ id: p.id, params: Ce });
|
|
807
808
|
}
|
|
808
809
|
if (!((Z = u[v]) != null && Z.filter)) {
|
|
809
810
|
const q = {
|
|
@@ -812,7 +813,7 @@ let W = class extends V {
|
|
|
812
813
|
col: v,
|
|
813
814
|
criteria: null
|
|
814
815
|
};
|
|
815
|
-
h.push({ id:
|
|
816
|
+
h.push({ id: p.id, params: q }), d.push({ id: p.id, params: { unitId: e, subUnitId: t, col: v, criteria: { ...y.serialize(), colId: v } } });
|
|
816
817
|
}
|
|
817
818
|
}
|
|
818
819
|
}), o !== F || l !== S) {
|
|
@@ -848,7 +849,7 @@ let W = class extends V {
|
|
|
848
849
|
const m = o;
|
|
849
850
|
let g = l;
|
|
850
851
|
l >= a.startRow && l <= a.endRow && c.startRow < a.startRow && a.startRow > o && (g = a.startRow - 1), ee(a.startRow, a.endRow - a.startRow + 1, c.startRow, u);
|
|
851
|
-
const
|
|
852
|
+
const C = Object.keys(u).map((f) => Number(f)), S = C.find((f) => u[f].oldIndex === g), F = C.find((f) => u[f].oldIndex === m);
|
|
852
853
|
if (o !== F || l !== S) {
|
|
853
854
|
const f = {
|
|
854
855
|
unitId: e,
|
|
@@ -859,7 +860,7 @@ let W = class extends V {
|
|
|
859
860
|
endRow: S
|
|
860
861
|
}
|
|
861
862
|
};
|
|
862
|
-
h.push({ id: R.id, params: f }, { id:
|
|
863
|
+
h.push({ id: R.id, params: f }, { id: H.id, params: { unitId: e, subUnitId: t } }), d.push({ id: R.id, params: { range: s, unitId: e, subUnitId: t } }, { id: H.id, params: { unitId: e, subUnitId: t } });
|
|
863
864
|
}
|
|
864
865
|
return {
|
|
865
866
|
redos: h,
|
|
@@ -886,12 +887,12 @@ let W = class extends V {
|
|
|
886
887
|
unitId: e,
|
|
887
888
|
subUnitId: t
|
|
888
889
|
}
|
|
889
|
-
}, g = { id: R.id, params: { unitId: e, subUnitId: t, range: u } },
|
|
890
|
-
a.push(m, g), c.push(m,
|
|
890
|
+
}, g = { id: R.id, params: { unitId: e, subUnitId: t, range: u } }, C = { id: R.id, params: { unitId: e, subUnitId: t, range: l } };
|
|
891
|
+
a.push(m, g), c.push(m, C);
|
|
891
892
|
const S = o.getAllFilterColumns(), F = s.startColumn - n.startColumn;
|
|
892
893
|
S.forEach((_) => {
|
|
893
894
|
const [f, v] = _;
|
|
894
|
-
v && (a.push({ id:
|
|
895
|
+
v && (a.push({ id: p.id, params: { unitId: e, subUnitId: t, col: f + F, criteria: { ...v.serialize(), colId: f + F } } }), c.push({ id: p.id, params: { unitId: e, subUnitId: t, col: f, criteria: { ...v.serialize(), colId: f } } }));
|
|
895
896
|
});
|
|
896
897
|
} else if (Y.intersects(s, l)) {
|
|
897
898
|
const h = {
|
|
@@ -914,7 +915,7 @@ let W = class extends V {
|
|
|
914
915
|
return this._handleNull();
|
|
915
916
|
const o = [], l = [];
|
|
916
917
|
return n.getAllFilterColumns().forEach(([c, h]) => {
|
|
917
|
-
l.push({ id:
|
|
918
|
+
l.push({ id: p.id, params: { unitId: e, subUnitId: t, col: c, criteria: { ...h.serialize(), colId: c } } });
|
|
918
919
|
}), o.push({ id: O.id, params: { unitId: e, subUnitId: t, range: s } }), l.unshift({ id: R.id, params: { range: s, unitId: e, subUnitId: t } }), {
|
|
919
920
|
undos: l,
|
|
920
921
|
redos: o
|
|
@@ -929,7 +930,7 @@ let W = class extends V {
|
|
|
929
930
|
return this._handleNull();
|
|
930
931
|
const o = [], l = [], a = [], c = [];
|
|
931
932
|
return n.getAllFilterColumns().forEach(([d, u]) => {
|
|
932
|
-
o.push({ id:
|
|
933
|
+
o.push({ id: p.id, params: { unitId: r, subUnitId: t, col: d, criteria: { ...u.serialize(), colId: d } } }), a.push({ id: p.id, params: { unitId: r, subUnitId: t, col: d, criteria: null } });
|
|
933
934
|
}), a.push({ id: O.id, params: { unitId: r, subUnitId: t, range: s } }), o.unshift({ id: R.id, params: { range: s, unitId: r, subUnitId: t } }), {
|
|
934
935
|
undos: l,
|
|
935
936
|
redos: o,
|
|
@@ -962,13 +963,13 @@ let W = class extends V {
|
|
|
962
963
|
return t.forEach((h) => {
|
|
963
964
|
const [d, u] = h;
|
|
964
965
|
l.push({
|
|
965
|
-
id:
|
|
966
|
+
id: p.id,
|
|
966
967
|
params: {
|
|
967
968
|
...s,
|
|
968
969
|
col: d
|
|
969
970
|
}
|
|
970
971
|
}), o.push({
|
|
971
|
-
id:
|
|
972
|
+
id: p.id,
|
|
972
973
|
params: {
|
|
973
974
|
...s,
|
|
974
975
|
col: d,
|
|
@@ -978,14 +979,14 @@ let W = class extends V {
|
|
|
978
979
|
}), t.forEach((h) => {
|
|
979
980
|
const [d, u] = h;
|
|
980
981
|
c.push({
|
|
981
|
-
id:
|
|
982
|
+
id: p.id,
|
|
982
983
|
params: {
|
|
983
984
|
...s,
|
|
984
985
|
col: d + n,
|
|
985
986
|
criteria: { ...u.serialize(), colId: d + n }
|
|
986
987
|
}
|
|
987
988
|
}), a.push({
|
|
988
|
-
id:
|
|
989
|
+
id: p.id,
|
|
989
990
|
params: {
|
|
990
991
|
...s,
|
|
991
992
|
col: d + n,
|
|
@@ -1016,8 +1017,8 @@ let W = class extends V {
|
|
|
1016
1017
|
if (g < d)
|
|
1017
1018
|
l.push(g);
|
|
1018
1019
|
else if (a = !0, g <= u) {
|
|
1019
|
-
const
|
|
1020
|
-
l.push(
|
|
1020
|
+
const C = Math.max(d, l.length ? l[l.length - 1] + 1 : d);
|
|
1021
|
+
l.push(C);
|
|
1021
1022
|
} else
|
|
1022
1023
|
l.push(g - (u - d + 1 - m.length));
|
|
1023
1024
|
});
|
|
@@ -1036,9 +1037,9 @@ let W = class extends V {
|
|
|
1036
1037
|
for (let m = d.startColumn; m <= d.endColumn; m++) {
|
|
1037
1038
|
const g = (c = u == null ? void 0 : u[d.startRow]) == null ? void 0 : c[m];
|
|
1038
1039
|
if (g && this._cellHasValue(g)) {
|
|
1039
|
-
const
|
|
1040
|
-
if (
|
|
1041
|
-
const S = le(d, { down: !0 },
|
|
1040
|
+
const C = (h = this._univerInstanceService.getUnit(t)) == null ? void 0 : h.getSheetBySheetId(n);
|
|
1041
|
+
if (C) {
|
|
1042
|
+
const S = le(d, { down: !0 }, C), F = this._sheetsFilterService.getFilterModel(t, n), _ = F.getRange();
|
|
1042
1043
|
F.setRange({
|
|
1043
1044
|
..._,
|
|
1044
1045
|
endRow: S.endRow
|
|
@@ -1074,7 +1075,7 @@ let W = class extends V {
|
|
|
1074
1075
|
}
|
|
1075
1076
|
_initErrorHandling() {
|
|
1076
1077
|
this.disposeWithMe(this._commandService.beforeCommandExecuted((r) => {
|
|
1077
|
-
const e = r.params, t =
|
|
1078
|
+
const e = r.params, t = L(this._univerInstanceService);
|
|
1078
1079
|
if (!t) return;
|
|
1079
1080
|
const { subUnitId: n, unitId: s } = t, o = this._sheetsFilterService.getFilterModel(s, n);
|
|
1080
1081
|
if (!o) return;
|
|
@@ -1088,24 +1089,23 @@ let W = class extends V {
|
|
|
1088
1089
|
return !(e.length === 0 || e.every((t) => t == null));
|
|
1089
1090
|
}
|
|
1090
1091
|
};
|
|
1091
|
-
W =
|
|
1092
|
-
P(0,
|
|
1093
|
-
P(1,
|
|
1094
|
-
P(2,
|
|
1092
|
+
W = Ot([
|
|
1093
|
+
P(0, T),
|
|
1094
|
+
P(1, z(Ie)),
|
|
1095
|
+
P(2, z(M)),
|
|
1095
1096
|
P(3, x),
|
|
1096
|
-
P(4,
|
|
1097
|
+
P(4, z($e))
|
|
1097
1098
|
], W);
|
|
1098
|
-
|
|
1099
|
-
var
|
|
1100
|
-
for (var n = t > 1 ? void 0 : t ? Mt(r, e) : r, s = i.length - 1, o; s >= 0; s--)
|
|
1099
|
+
var yt = Object.defineProperty, At = Object.getOwnPropertyDescriptor, Tt = (i, r, e, t) => {
|
|
1100
|
+
for (var n = t > 1 ? void 0 : t ? At(r, e) : r, s = i.length - 1, o; s >= 0; s--)
|
|
1101
1101
|
(o = i[s]) && (n = (t ? o(r, e, n) : o(n)) || n);
|
|
1102
|
-
return t && n &&
|
|
1103
|
-
}, se = (i, r) => (e, t) => r(e, t, i),
|
|
1104
|
-
let oe = (
|
|
1105
|
-
constructor(i =
|
|
1102
|
+
return t && n && yt(r, e, n), n;
|
|
1103
|
+
}, se = (i, r) => (e, t) => r(e, t, i), B;
|
|
1104
|
+
let oe = (B = class extends Oe {
|
|
1105
|
+
constructor(i = et, r, e) {
|
|
1106
1106
|
super(), this._config = i, this._injector = r, this._configService = e;
|
|
1107
1107
|
const { ...t } = this._config;
|
|
1108
|
-
this._configService.setConfig(
|
|
1108
|
+
this._configService.setConfig(ke, t);
|
|
1109
1109
|
}
|
|
1110
1110
|
onStarting() {
|
|
1111
1111
|
[
|
|
@@ -1116,19 +1116,19 @@ let oe = (z = class extends Se {
|
|
|
1116
1116
|
onReady() {
|
|
1117
1117
|
this._injector.get(W);
|
|
1118
1118
|
}
|
|
1119
|
-
}, w(
|
|
1120
|
-
oe =
|
|
1121
|
-
se(1,
|
|
1122
|
-
se(2,
|
|
1119
|
+
}, w(B, "type", U.UNIVER_SHEET), w(B, "pluginName", _e), B);
|
|
1120
|
+
oe = Tt([
|
|
1121
|
+
se(1, z(ye)),
|
|
1122
|
+
se(2, Ae)
|
|
1123
1123
|
], oe);
|
|
1124
|
-
const
|
|
1124
|
+
const Nt = {
|
|
1125
1125
|
id: "sheet.command.set-filter-range",
|
|
1126
1126
|
type: E.COMMAND,
|
|
1127
1127
|
handler: (i, r) => {
|
|
1128
|
-
const e = i.get(M), t = i.get(
|
|
1129
|
-
if (!
|
|
1128
|
+
const e = i.get(M), t = i.get(T), n = i.get(j), s = i.get(x), { unitId: o, subUnitId: l, range: a } = r;
|
|
1129
|
+
if (!L(s, r) || e.getFilterModel(o, l)) return !1;
|
|
1130
1130
|
if (a.endRow === a.startRow) {
|
|
1131
|
-
const m = i.get(
|
|
1131
|
+
const m = i.get(Te), g = i.get(Ne);
|
|
1132
1132
|
return m.emit(g.t("sheets-filter.command.not-valid-filter-range")), !1;
|
|
1133
1133
|
}
|
|
1134
1134
|
const d = { id: R.id, params: { unitId: o, subUnitId: l, range: a } }, u = t.syncExecuteCommand(d.id, d.params);
|
|
@@ -1138,49 +1138,49 @@ const Ot = {
|
|
|
1138
1138
|
redoMutations: [d]
|
|
1139
1139
|
}), u;
|
|
1140
1140
|
}
|
|
1141
|
-
},
|
|
1141
|
+
}, xt = {
|
|
1142
1142
|
id: "sheet.command.remove-sheet-filter",
|
|
1143
1143
|
type: E.COMMAND,
|
|
1144
1144
|
handler: (i, r) => {
|
|
1145
|
-
const e = i.get(x), t = i.get(M), n = i.get(
|
|
1145
|
+
const e = i.get(x), t = i.get(M), n = i.get(T), s = i.get(j), o = L(e, r);
|
|
1146
1146
|
if (!o) return !1;
|
|
1147
1147
|
const { unitId: l, subUnitId: a } = o, c = t.getFilterModel(l, a);
|
|
1148
1148
|
if (!c) return !1;
|
|
1149
|
-
const h = c == null ? void 0 : c.serialize(), d =
|
|
1149
|
+
const h = c == null ? void 0 : c.serialize(), d = It(l, a, h), u = n.syncExecuteCommand(O.id, { unitId: l, subUnitId: a });
|
|
1150
1150
|
return u && s.pushUndoRedo({
|
|
1151
1151
|
unitID: l,
|
|
1152
1152
|
undoMutations: d,
|
|
1153
1153
|
redoMutations: [{ id: O.id, params: { unitId: l, subUnitId: a } }]
|
|
1154
1154
|
}), u;
|
|
1155
1155
|
}
|
|
1156
|
-
},
|
|
1156
|
+
}, zt = {
|
|
1157
1157
|
id: "sheet.command.smart-toggle-filter",
|
|
1158
1158
|
type: E.COMMAND,
|
|
1159
1159
|
handler: async (i) => {
|
|
1160
|
-
const r = i.get(x), e = i.get(M), t = i.get(
|
|
1160
|
+
const r = i.get(x), e = i.get(M), t = i.get(T), n = r.getCurrentUnitForType(U.UNIVER_SHEET), s = n == null ? void 0 : n.getActiveSheet();
|
|
1161
1161
|
if (!s || !n) return !1;
|
|
1162
1162
|
const o = n.getUnitId(), l = s.getSheetId();
|
|
1163
1163
|
if (e.getFilterModel(o, l))
|
|
1164
|
-
return t.executeCommand(
|
|
1164
|
+
return t.executeCommand(xt.id, { unitId: o, subUnitId: l });
|
|
1165
1165
|
const h = i.get(Ge).getCurrentLastSelection();
|
|
1166
1166
|
if (!h) return !1;
|
|
1167
1167
|
const d = h.range, u = Je(h) ? le(d, { left: !0, right: !0, up: !0, down: !0 }, s) : d;
|
|
1168
|
-
return t.executeCommand(
|
|
1168
|
+
return t.executeCommand(Nt.id, {
|
|
1169
1169
|
unitId: o,
|
|
1170
1170
|
subUnitId: l,
|
|
1171
1171
|
range: u
|
|
1172
1172
|
});
|
|
1173
1173
|
}
|
|
1174
|
-
},
|
|
1174
|
+
}, Ht = {
|
|
1175
1175
|
id: "sheet.command.set-filter-criteria",
|
|
1176
1176
|
type: E.COMMAND,
|
|
1177
1177
|
handler: async (i, r) => {
|
|
1178
|
-
const e = i.get(M), t = i.get(
|
|
1178
|
+
const e = i.get(M), t = i.get(T), n = i.get(j), { unitId: s, subUnitId: o, col: l, criteria: a } = r, c = e.getFilterModel(s, o);
|
|
1179
1179
|
if (!c) return !1;
|
|
1180
1180
|
const h = c.getRange();
|
|
1181
1181
|
if (!h || l < h.startColumn || l > h.endColumn) return !1;
|
|
1182
|
-
const d = c.getFilterColumn(l), u =
|
|
1183
|
-
id:
|
|
1182
|
+
const d = c.getFilterColumn(l), u = Pt(s, o, l, d), m = {
|
|
1183
|
+
id: p.id,
|
|
1184
1184
|
params: {
|
|
1185
1185
|
unitId: s,
|
|
1186
1186
|
subUnitId: o,
|
|
@@ -1194,32 +1194,32 @@ const Ot = {
|
|
|
1194
1194
|
redoMutations: [m]
|
|
1195
1195
|
}), g;
|
|
1196
1196
|
}
|
|
1197
|
-
},
|
|
1197
|
+
}, Dt = {
|
|
1198
1198
|
id: "sheet.command.clear-filter-criteria",
|
|
1199
1199
|
type: E.COMMAND,
|
|
1200
1200
|
handler: (i, r) => {
|
|
1201
|
-
const e = i.get(M), t = i.get(j), n = i.get(
|
|
1201
|
+
const e = i.get(M), t = i.get(j), n = i.get(T), s = i.get(x), o = L(s, r);
|
|
1202
1202
|
if (!o) return !1;
|
|
1203
1203
|
const { unitId: l, subUnitId: a } = o, c = e.getFilterModel(o.unitId, o.subUnitId);
|
|
1204
1204
|
if (!c) return !1;
|
|
1205
|
-
const h = c.serialize(), d =
|
|
1206
|
-
return
|
|
1205
|
+
const h = c.serialize(), d = Re(l, a, h), u = $t(l, a, h);
|
|
1206
|
+
return xe(u, n).result ? (t.pushUndoRedo({
|
|
1207
1207
|
unitID: l,
|
|
1208
1208
|
undoMutations: d,
|
|
1209
1209
|
redoMutations: u
|
|
1210
1210
|
}), !0) : !1;
|
|
1211
1211
|
}
|
|
1212
|
-
},
|
|
1212
|
+
}, Wt = {
|
|
1213
1213
|
id: "sheet.command.re-calc-filter",
|
|
1214
1214
|
type: E.COMMAND,
|
|
1215
1215
|
handler: (i, r) => {
|
|
1216
|
-
const e = i.get(M), t = i.get(
|
|
1216
|
+
const e = i.get(M), t = i.get(T), n = i.get(x), s = L(n, r);
|
|
1217
1217
|
if (!s) return !1;
|
|
1218
1218
|
const { unitId: o, subUnitId: l } = s;
|
|
1219
|
-
return e.getFilterModel(s.unitId, s.subUnitId) ? t.executeCommand(
|
|
1219
|
+
return e.getFilterModel(s.unitId, s.subUnitId) ? t.executeCommand(H.id, { unitId: o, subUnitId: l }) : !1;
|
|
1220
1220
|
}
|
|
1221
1221
|
};
|
|
1222
|
-
function
|
|
1222
|
+
function It(i, r, e) {
|
|
1223
1223
|
const t = [], n = {
|
|
1224
1224
|
id: R.id,
|
|
1225
1225
|
params: {
|
|
@@ -1228,14 +1228,14 @@ function At(i, r, e) {
|
|
|
1228
1228
|
range: e.ref
|
|
1229
1229
|
}
|
|
1230
1230
|
};
|
|
1231
|
-
return t.push(n),
|
|
1231
|
+
return t.push(n), Re(i, r, e).forEach((o) => t.push(o)), t;
|
|
1232
1232
|
}
|
|
1233
|
-
function
|
|
1233
|
+
function Re(i, r, e) {
|
|
1234
1234
|
var n;
|
|
1235
1235
|
const t = [];
|
|
1236
1236
|
return (n = e.filterColumns) == null || n.forEach((s) => {
|
|
1237
1237
|
const o = {
|
|
1238
|
-
id:
|
|
1238
|
+
id: p.id,
|
|
1239
1239
|
params: {
|
|
1240
1240
|
unitId: i,
|
|
1241
1241
|
subUnitId: r,
|
|
@@ -1246,12 +1246,12 @@ function fe(i, r, e) {
|
|
|
1246
1246
|
t.push(o);
|
|
1247
1247
|
}), t;
|
|
1248
1248
|
}
|
|
1249
|
-
function
|
|
1249
|
+
function $t(i, r, e) {
|
|
1250
1250
|
var n;
|
|
1251
1251
|
const t = [];
|
|
1252
1252
|
return (n = e.filterColumns) == null || n.forEach((s) => {
|
|
1253
1253
|
const o = {
|
|
1254
|
-
id:
|
|
1254
|
+
id: p.id,
|
|
1255
1255
|
params: {
|
|
1256
1256
|
unitId: i,
|
|
1257
1257
|
subUnitId: r,
|
|
@@ -1262,10 +1262,10 @@ function Nt(i, r, e) {
|
|
|
1262
1262
|
t.push(o);
|
|
1263
1263
|
}), t;
|
|
1264
1264
|
}
|
|
1265
|
-
function
|
|
1265
|
+
function Pt(i, r, e, t) {
|
|
1266
1266
|
if (!t)
|
|
1267
1267
|
return {
|
|
1268
|
-
id:
|
|
1268
|
+
id: p.id,
|
|
1269
1269
|
params: {
|
|
1270
1270
|
unitId: i,
|
|
1271
1271
|
subUnitId: r,
|
|
@@ -1275,7 +1275,7 @@ function Tt(i, r, e, t) {
|
|
|
1275
1275
|
};
|
|
1276
1276
|
const n = t.serialize();
|
|
1277
1277
|
return {
|
|
1278
|
-
id:
|
|
1278
|
+
id: p.id,
|
|
1279
1279
|
params: {
|
|
1280
1280
|
unitId: i,
|
|
1281
1281
|
subUnitId: r,
|
|
@@ -1285,28 +1285,28 @@ function Tt(i, r, e, t) {
|
|
|
1285
1285
|
};
|
|
1286
1286
|
}
|
|
1287
1287
|
export {
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1288
|
+
Dt as ClearSheetsFilterCriteriaCommand,
|
|
1289
|
+
N as CustomFilterOperator,
|
|
1290
|
+
tt as FILTER_MUTATIONS,
|
|
1291
|
+
ut as FilterColumn,
|
|
1292
1292
|
D as FilterModel,
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1293
|
+
Wt as ReCalcSheetsFilterCommand,
|
|
1294
|
+
H as ReCalcSheetsFilterMutation,
|
|
1295
|
+
xt as RemoveSheetFilterCommand,
|
|
1296
1296
|
O as RemoveSheetsFilterMutation,
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1297
|
+
_e as SHEET_FILTER_SNAPSHOT_ID,
|
|
1298
|
+
Nt as SetSheetFilterRangeCommand,
|
|
1299
|
+
Ht as SetSheetsFilterCriteriaCommand,
|
|
1300
|
+
p as SetSheetsFilterCriteriaMutation,
|
|
1301
1301
|
R as SetSheetsFilterRangeMutation,
|
|
1302
1302
|
M as SheetsFilterService,
|
|
1303
|
-
|
|
1303
|
+
zt as SmartToggleSheetsFilterCommand,
|
|
1304
1304
|
oe as UniverSheetsFilterPlugin,
|
|
1305
|
-
|
|
1305
|
+
ot as equals,
|
|
1306
1306
|
re as getCustomFilterFn,
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1307
|
+
rt as greaterThan,
|
|
1308
|
+
nt as greaterThanOrEqualTo,
|
|
1309
|
+
it as lessThan,
|
|
1310
|
+
st as lessThanOrEqualTo,
|
|
1311
|
+
he as notEquals
|
|
1312
1312
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export declare const SetSheetsFilterRangeMutationId = "sheet.mutation.set-filter-range";
|
|
17
|
+
export declare const SetSheetsFilterCriteriaMutationId = "sheet.mutation.set-filter-criteria";
|
|
18
|
+
export declare const RemoveSheetsFilterMutationId = "sheet.mutation.remove-filter";
|
|
19
|
+
export declare const ReCalcSheetsFilterMutationId = "sheet.mutation.re-calc-filter";
|
|
20
|
+
export declare const FILTER_MUTATIONS: Set<string>;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export declare const
|
|
16
|
+
export declare const SHEETS_FILTER_PLUGIN_CONFIG_KEY = "sheets-filter.config";
|
|
17
17
|
export declare const configSymbol: unique symbol;
|
|
18
18
|
export interface IUniverSheetsFilterConfig {
|
|
19
19
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
export { UniverSheetsFilterPlugin } from './plugin';
|
|
17
17
|
export { FilterColumn, FilterModel } from './models/filter-model';
|
|
18
18
|
export { equals, getCustomFilterFn, greaterThan, greaterThanOrEqualTo, lessThan, lessThanOrEqualTo, notEquals, } from './models/custom-filters';
|
|
19
|
-
export {
|
|
19
|
+
export { SHEET_FILTER_SNAPSHOT_ID, SheetsFilterService } from './services/sheet-filter.service';
|
|
20
20
|
export type { IAutoFilter, ICustomFilter, ICustomFilters, IFilterColumn, IFilters } from './models/types';
|
|
21
21
|
export { CustomFilterOperator } from './models/types';
|
|
22
|
+
export { FILTER_MUTATIONS } from './common/const';
|
|
22
23
|
export { type ISetSheetsFilterCriteriaMutationParams, type ISetSheetsFilterRangeMutationParams, ReCalcSheetsFilterMutation, RemoveSheetsFilterMutation, SetSheetsFilterCriteriaMutation, SetSheetsFilterRangeMutation, } from './commands/mutations/sheets-filter.mutation';
|
|
23
24
|
export { ClearSheetsFilterCriteriaCommand, type ISetSheetFilterRangeCommandParams, type ISetSheetsFilterCriteriaCommandParams, ReCalcSheetsFilterCommand, RemoveSheetFilterCommand, SetSheetFilterRangeCommand, SetSheetsFilterCriteriaCommand, SmartToggleSheetsFilterCommand, } from './commands/commands/sheets-filter.command';
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
|
|
2
1
|
import { IUniverSheetsFilterConfig } from './controllers/config.schema';
|
|
2
|
+
import { IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
|
|
3
3
|
export declare class UniverSheetsFilterPlugin extends Plugin {
|
|
4
4
|
private readonly _config;
|
|
5
5
|
protected readonly _injector: Injector;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Nullable, Disposable, ICommandService, IResourceManagerService, IUniverInstanceService } from '@univerjs/core';
|
|
2
2
|
import { IAutoFilter } from '../models/types';
|
|
3
3
|
import { FilterModel } from '../models/filter-model';
|
|
4
|
-
export declare const FILTER_MUTATIONS: Set<string>;
|
|
5
4
|
type WorksheetID = string;
|
|
6
5
|
export interface ISheetsFilterResource {
|
|
7
6
|
[key: WorksheetID]: IAutoFilter;
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(g,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets"],u):(g=typeof globalThis<"u"?globalThis:g||self,u(g.UniverSheetsFilter={},g.UniverCore,g.rxjs,g.UniverSheets))})(this,function(g,u,O,F){"use strict";var De=Object.defineProperty;var He=(g,u,O)=>u in g?De(g,u,{enumerable:!0,configurable:!0,writable:!0,value:O}):g[u]=O;var M=(g,u,O)=>He(g,typeof u!="symbol"?u+"":u,O);var x;const S={id:"sheet.mutation.set-filter-range",type:u.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,range:r}=n;return i.get(g.SheetsFilterService).ensureFilterModel(t,e).setRange(r),!0}},p={id:"sheet.mutation.set-filter-criteria",type:u.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,criteria:r,col:s,reCalc:o=!0}=n,a=i.get(g.SheetsFilterService).getFilterModel(t,e);return a?(a.setCriteria(s,r,o),!0):!1}},T={id:"sheet.mutation.remove-filter",type:u.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(g.SheetsFilterService).removeFilterModel(e,t)}},U={id:"sheet.mutation.re-calc-filter",type:u.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n,s=i.get(g.SheetsFilterService).getFilterModel(e,t);return s?(s.reCalc(),!0):!1}};var I=(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))(I||{});const q={operator:I.GREATER_THAN,fn:(i,n)=>$(i)?i>n:!1},Q={operator:I.GREATER_THAN_OR_EQUAL,fn:(i,n)=>$(i)?i>=n:!1},G={operator:I.LESS_THAN,fn:(i,n)=>$(i)?i<n:!1},J={operator:I.LESS_THAN_OR_EQUAL,fn:(i,n)=>$(i)?i<=n:!1},Y={operator:I.EQUAL,fn:(i,n)=>$(i)?i===n:!1},z={operator:I.NOT_EQUALS,fn:(i,n)=>{if(typeof n=="string"){if(n===" ")return i!=null;const e=Z(i);return e&&ce(n)?!k(n).test(e):e!==n}return $(i)?i!==n:!0}},K=new Map([]);[q,Q,G,J,Y,z].forEach(i=>{K.set(i.operator,i)});function de(i){return!!i}const ue={fn:(i,n)=>{const e=Z(i);return e===null?n==="":k(n).test(e)}};function D(i){return i?K.get(i):ue}function $(i){return typeof i=="number"}function X(i){return!!(typeof i=="number"||typeof i=="string"&&u.isNumeric(i))}function Z(i){return typeof i=="boolean"||i==null?null:typeof i=="string"?i:i.toString()}function ce(i){return typeof i=="number"?!1:i.indexOf("*")!==-1||i.indexOf("?")!==-1}function k(i){const n=i.replace(/[.+^${}()|[\]\\]/g,"\\$&").replaceAll("?",".").replace(/[*]/g,".$&");return new RegExp(`^${n}$`)}const H=()=>new Set;class b extends u.Disposable{constructor(e,t,r){super();M(this,"_filteredOutRows$",new O.BehaviorSubject(H()));M(this,"filteredOutRows$",this._filteredOutRows$.asObservable());M(this,"_hasCriteria$",new O.BehaviorSubject(!1));M(this,"hasCriteria$",this._hasCriteria$.asObservable());M(this,"_filterColumnByIndex",new Map);M(this,"_alreadyFilteredOutRows",H());M(this,"_range");this.unitId=e,this.subUnitId=t,this._worksheet=r}get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete()}serialize(){const e={ref:u.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 b(e,t,r);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.forEach(r=>this._setCriteriaWithoutReCalc(r.colId,r)),e.cachedFilteredOut&&(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw new Error("[FilterModel] could not get range before a range is set!");return this._range}getFilteredOutRowsExceptCol(e){return this._getAllFilterColumns(!0).filter(([t])=>t!==e).reduce((t,[,r])=>{const s=r.calc({getAlreadyFilteredOutRows:()=>t});return s?u.mergeSets(t,s):t},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,r])=>{r.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,r=!1){if(!this._range)throw new Error("[FilterModel] could not set criteria before a range is set!");if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),r&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),r&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))!=null?t:null}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){const t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([r,s])=>s)}_reCalcAllColumns(){this._alreadyFilteredOutRows=H(),this._getAllFilterColumns().forEach(e=>e.__clearCache()),this._reCalcWithNoCacheColumns()}_setCriteriaWithoutReCalc(e,t){const r=this._range;if(!r)throw new Error("[FilterModel] could not set criteria before a range is set!");const{startColumn:s,endColumn:o}=r;if(e>o||e<s)throw new Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);let l;this._filterColumnByIndex.has(e)?l=this._filterColumnByIndex.get(e):(l=new ee(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)=>u.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=u.mergeSets(this._alreadyFilteredOutRows,r))}}}class ee extends u.Disposable{constructor(e,t,r,s,o){super();M(this,"_filteredOutRows",null);M(this,"_filterFn",null);M(this,"_range",null);M(this,"_column",0);M(this,"_filterByValues",!1);this.unitId=e,this.subUnitId=t,this._worksheet=r,this._criteria=s,this._filterColumnContext=o}get filteredOutRows(){return this._filteredOutRows}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 u.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 u.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw new Error("[FilterColumn] cannot calculate without a filter fn!");if(!this._range)throw new Error("[FilterColumn] cannot calculate without a range!");if(typeof this._column!="number")throw new TypeError("[FilterColumn] cannot calculate without a column offset!");const t=this._column,r={startColumn:t,endColumn:t,startRow:this._range.startRow+1,endRow:this._range.endRow},s=new Set,o=e.getAlreadyFilteredOutRows();for(const l of this._worksheet.iterateByColumn(r,!1,!1)){const{row:a,rowSpan:d,col:m}=l;if(o.has(a)&&(!d||d===1))continue;const c=this._filterByValues?u.extractPureTextFromCell(this._worksheet.getCell(a,m)):Se(this._worksheet,a,m);if(!this._filterFn(c)&&(s.add(a),d))for(let h=1;h<d;h++)s.add(a+h)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=he(this._criteria),this._filterByValues=!!this._criteria.filters)}}function he(i){if(i.filters)return me(i.filters);if(i.customFilters)return fe(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 fe(i){const n=i.customFilters.map(e=>Re(e));return _e(n)?i.and?ge(n):Ce(n):n[0]}function ge(i){const[n,e]=i;return t=>n(t)&&e(t)}function Ce(i){const[n,e]=i;return t=>n(t)||e(t)}function _e(i){return i.length===2}function Re(i){const n=i.val;if(i.operator===I.NOT_EQUALS&&!X(n))return r=>z.fn(r,n);if(de(i.operator)){if(!X(n))return()=>!1;const r=D(i.operator),s=Number(n);return o=>r.fn(o,s)}const e=D(i.operator);return t=>e.fn(t,n)}function Se(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?te(t):r?t.t===u.CellValueType.NUMBER&&typeof t.v=="string"?r.v:te(r):null}function te(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===u.CellValueType.BOOLEAN?e.toUpperCase():e:typeof e=="number"?i.t===u.CellValueType.BOOLEAN?e?"TRUE":"FALSE":e:typeof e=="boolean"?e?"TRUE":"FALSE":""}var Fe=Object.defineProperty,pe=Object.getOwnPropertyDescriptor,ve=(i,n,e,t)=>{for(var r=t>1?void 0:t?pe(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&Fe(n,e,r),r},j=(i,n)=>(e,t)=>n(e,t,i);const re=new Set([S.id,p.id,T.id,U.id]),V="SHEET_FILTER_PLUGIN";g.SheetsFilterService=class extends u.Disposable{constructor(e,t,r){super();M(this,"_filterModels",new Map);M(this,"_loadedUnitId$",new O.BehaviorSubject(null));M(this,"loadedUnitId$",this._loadedUnitId$.asObservable());M(this,"_errorMsg$",new O.BehaviorSubject(null));M(this,"errorMsg$",this._errorMsg$.asObservable());M(this,"_activeFilterModel$",new O.BehaviorSubject(null));M(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 b(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(u.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(u.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(O.filter(([e])=>e.type===u.CommandType.MUTATION&&re.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(u.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=b.deserialize(e,s,r.getSheetBySheetId(s),o);this._cacheFilterModel(e,s,l)})}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:V,businesses:[u.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)}},g.SheetsFilterService=ve([j(0,u.IResourceManagerService),j(1,u.IUniverInstanceService),j(2,u.ICommandService)],g.SheetsFilterService);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 P(i){return we(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 Me=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,ye=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ee(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&Me(n,e,r),r},L=(i,n)=>(e,t)=>n(e,t,i);let B=class extends u.Disposable{constructor(n,e,t,r,s){super();M(this,"_disposableCollection",new u.DisposableCollection);this._commandService=n,this._sheetInterceptorService=e,this._sheetsFilterService=t,this._univerInstanceService=r,this._refRangeService=s,this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener(),this._initErrorHandling()}_initCommands(){[p,S,U,T].forEach(n=>this.disposeWithMe(this._commandService.registerCommand(n)))}_initInterceptors(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>this._getUpdateFilter(n)})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===F.SetWorksheetActiveOperation.id){const e=n.params,t=e.subUnitId,r=e.unitId;if(!t||!r)return;this._registerRefRange(r,t)}if(n.id===S.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 F.InsertRowCommand.id:{const d=a.params,m=d.unitId||n,c=d.subUnitId||e;return this._handleInsertRowCommand(d,m,c)}case F.InsertColCommand.id:{const d=a.params,m=d.unitId||n,c=d.subUnitId||e;return this._handleInsertColCommand(d,m,c)}case F.RemoveColCommand.id:{const d=a.params;return this._handleRemoveColCommand(d,n,e)}case F.RemoveRowCommand.id:{const d=a.params;return this._handleRemoveRowCommand(d,n,e)}case F.EffectRefRangId.MoveColsCommandId:{const d=a.params;return this._handleMoveColsCommand(d,n,e)}case F.EffectRefRangId.MoveRowsCommandId:{const d=a.params;return this._handleMoveRowsCommand(d,n,e)}case F.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 F.RemoveSheetCommand.id:{const t=n.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case F.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 R;const r=this._sheetsFilterService.getFilterModel(e,t),s=(R=r==null?void 0:r.getRange())!=null?R:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:a,endColumn:d}=n.range,m=d-a+1;if(d>l)return this._handleNull();const c=[],h=[],C=a,_={unitId:e,subUnitId:t,range:{...s,startColumn:a<=o?o+m:o,endColumn:l+m}},v={unitId:e,subUnitId:t,range:s};c.push({id:S.id,params:_}),h.push({id:S.id,params:v});const w=r.getAllFilterColumns().filter(f=>f[0]>=C);if(w.length!==0){const{newRange:f,oldRange:y}=this.moveCriteria(e,t,w,m);c.push(...f.redos,...y.redos),h.push(...f.undos,...y.undos)}return{redos:P(c),undos:P(h)}}_handleInsertRowCommand(n,e,t){var v;const r=this._sheetsFilterService.getFilterModel(e,t),s=(v=r==null?void 0:r.getRange())!=null?v:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{startRow:a,endRow:d}=n.range,m=d-a+1;if(d>l)return this._handleNull();const c=[],h=[],C={unitId:e,subUnitId:t,range:{...s,startRow:a<=o?o+m:o,endRow:l+m}},_={unitId:e,subUnitId:t,range:s};return c.push({id:S.id,params:C}),h.push({id:S.id,params:_}),{redos:P(c),undos:P(h)}}_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.range;if(a>l)return this._handleNull();const m=[],c=[],h=d<o?0:Math.min(d,l)-Math.max(a,o)+1,C=d-a+1,_=r.getAllFilterColumns();_.forEach(R=>{const[f,y]=R;f<=d&&f>=a&&(m.push({id:p.id,params:{unitId:e,subUnitId:t,col:f,criteria:null}}),c.push({id:p.id,params:{unitId:e,subUnitId:t,col:f,criteria:{...y.serialize(),colId:f}}}))});const v=_.filter(R=>{const[f,y]=R;return f>d});let E={undos:[],redos:[]};if(v.length>0){const{oldRange:R,newRange:f}=this.moveCriteria(e,t,v,-C);E=f,m.push(...R.redos),c.unshift(...R.undos)}if(h===l-o+1){const R={unitId:e,subUnitId:t};m.push({id:T.id,params:R}),c.unshift({id:S.id,params:{range:s,unitId:e,subUnitId:t}})}else{const R=o<=a?o:h===0?o-C:a,f=o<=a?l-h:l-C,y={unitId:e,subUnitId:t,range:{...s,startColumn:R,endColumn:f}};m.push({id:S.id,params:y}),c.unshift({id:S.id,params:{range:s,unitId:e,subUnitId:t}}),m.push(...E.redos),c.unshift(...E.undos)}return{undos:c,redos:m}}_handleRemoveRowCommand(n,e,t){var v;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:S.id,params:{range:s,unitId:e,subUnitId:t}}],redos:[{id:S.id,params:{range:{...s,startRow:o-(d-a+1),endRow:l-(d-a+1)},unitId:e,subUnitId:t}}]};const m=[],c=[],h=r.getAllFilterColumns(),C=o<=d&&o>=a;c.push({id:S.id,params:{range:s,unitId:e,subUnitId:t}});const _=Math.min(d,l)-Math.max(a,o)+1;if(_===l-o+1||C){const E={unitId:e,subUnitId:t};m.push({id:T.id,params:E}),h.forEach(w=>{const[R,f]=w,y={unitId:e,subUnitId:t,col:R,criteria:{...f.serialize(),colId:R}};c.push({id:p.id,params:y})})}else{const E=(v=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:v.getSheetBySheetId(t);if(!E)return this._handleNull();const w=[];for(let A=a;A<=d;A++)E.getRowFiltered(A)&&w.push(A);const R=Math.min(o,a),f=R+(l-o)-_+w.length,y={unitId:e,subUnitId:t,range:{...s,startRow:R,endRow:f}};m.push({id:S.id,params:y})}return{undos:P(c),redos:P(m)}}_handleMoveColsCommand(n,e,t){var R;const r=this._sheetsFilterService.getFilterModel(e,t),s=(R=r==null?void 0:r.getRange())!=null?R:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{fromRange:a,toRange:d}=n;if(a.endColumn<o&&d.startColumn<=o||a.startColumn>l&&d.endColumn>l)return this._handleNull();const m=[],c=[],h={};for(let f=o;f<=l;f++)h[f]={colIndex:f,filter:r.getFilterColumn(f)};u.moveMatrixArray(a.startColumn,a.endColumn-a.startColumn+1,d.startColumn,h);let C=s.startColumn,_=s.endColumn;o>=a.startColumn&&o<=a.endColumn&&d.startColumn>a.startColumn&&a.endColumn<l&&(C=a.endColumn+1),l>=a.startColumn&&l<=a.endColumn&&d.startColumn<a.startColumn&&a.startColumn>o&&(_=a.startColumn-1);const v=Object.keys(h).map(f=>Number(f)),E=v.find(f=>h[f].colIndex===_),w=v.find(f=>h[f].colIndex===C);if(v.forEach(f=>{var le,ae;const{colIndex:y,filter:A}=h[f],N=f;if(A){if(N>=w&&N<=E){const W={unitId:e,subUnitId:t,col:N,criteria:{...A.serialize(),colId:N}},ze={unitId:e,subUnitId:t,col:N,criteria:r.getFilterColumn(N)?{...(le=r.getFilterColumn(N))==null?void 0:le.serialize(),colId:N}:null};m.push({id:p.id,params:W}),c.push({id:p.id,params:ze})}if(!((ae=h[y])!=null&&ae.filter)){const W={unitId:e,subUnitId:t,col:y,criteria:null};m.push({id:p.id,params:W}),c.push({id:p.id,params:{unitId:e,subUnitId:t,col:y,criteria:{...A.serialize(),colId:y}}})}}}),o!==w||l!==E){const f={unitId:e,subUnitId:t,range:{...s,startColumn:w,endColumn:E}};m.unshift({id:S.id,params:f}),c.unshift({id:S.id,params:{range:s,unitId:e,subUnitId:t}})}return{undos:c,redos:m}}_handleMoveRowsCommand(n,e,t){var R;const r=this._sheetsFilterService.getFilterModel(e,t),s=(R=r==null?void 0:r.getRange())!=null?R:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{fromRange:a,toRange:d}=n;if(a.endRow<o&&d.startRow<=o||a.startRow>l&&d.endRow>l)return this._handleNull();const m=[],c=[],h={};for(let f=o;f<=l;f++)h[f]={oldIndex:f};const C=o;let _=l;l>=a.startRow&&l<=a.endRow&&d.startRow<a.startRow&&a.startRow>o&&(_=a.startRow-1),u.moveMatrixArray(a.startRow,a.endRow-a.startRow+1,d.startRow,h);const v=Object.keys(h).map(f=>Number(f)),E=v.find(f=>h[f].oldIndex===_),w=v.find(f=>h[f].oldIndex===C);if(o!==w||l!==E){const f={unitId:e,subUnitId:t,range:{...s,startRow:w,endRow:E}};m.push({id:S.id,params:f},{id:U.id,params:{unitId:e,subUnitId:t}}),c.push({id:S.id,params:{range:s,unitId:e,subUnitId:t}},{id:U.id,params:{unitId:e,subUnitId:t}})}return{redos:m,undos:c}}_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(u.Rectangle.contains(r,l)){const m=l.startRow-r.startRow,c=l.startColumn-r.startColumn,h={startRow:s.startRow+m,startColumn:s.startColumn+c,endRow:s.startRow+m+(l.endRow-l.startRow),endColumn:s.startColumn+c+(l.endColumn-l.startColumn)},C={id:T.id,params:{unitId:e,subUnitId:t}},_={id:S.id,params:{unitId:e,subUnitId:t,range:h}},v={id:S.id,params:{unitId:e,subUnitId:t,range:l}};a.push(C,_),d.push(C,v);const E=o.getAllFilterColumns(),w=s.startColumn-r.startColumn;E.forEach(R=>{const[f,y]=R;y&&(a.push({id:p.id,params:{unitId:e,subUnitId:t,col:f+w,criteria:{...y.serialize(),colId:f+w}}}),d.push({id:p.id,params:{unitId:e,subUnitId:t,col:f,criteria:{...y.serialize(),colId:f}}}))})}else if(u.Rectangle.intersects(s,l)){const m={...l,endRow:Math.max(l.endRow,s.endRow)};a.push({id:S.id,params:{unitId:e,subUnitId:t,range:m}}),d.push({id:S.id,params:{unitId:e,subUnitId:t,range:l}})}return{redos:a,undos:d}}_handleRemoveSheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[];return r.getAllFilterColumns().forEach(([d,m])=>{l.push({id:p.id,params:{unitId:e,subUnitId:t,col:d,criteria:{...m.serialize(),colId:d}}})}),o.push({id:T.id,params:{unitId:e,subUnitId:t,range:s}}),l.unshift({id:S.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(([c,h])=>{o.push({id:p.id,params:{unitId:n,subUnitId:t,col:c,criteria:{...h.serialize(),colId:c}}}),a.push({id:p.id,params:{unitId:n,subUnitId:t,col:c,criteria:null}})}),a.push({id:T.id,params:{unitId:n,subUnitId:t,range:s}}),o.unshift({id:S.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(F.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(n,e)=>{var t,r;return n?!0:(r=(t=this._sheetsFilterService.getFilterModel(e.unitId,e.subUnitId))==null?void 0:t.isRowFiltered(e.row))!=null?r:!1}}))}moveCriteria(n,e,t,r){const s={unitId:n,subUnitId:e,criteria:null,col:-1},o=[],l=[],a=[],d=[];return t.forEach(m=>{const[c,h]=m;l.push({id:p.id,params:{...s,col:c}}),o.push({id:p.id,params:{...s,col:c,criteria:{...h.serialize(),colId:c}}})}),t.forEach(m=>{const[c,h]=m;d.push({id:p.id,params:{...s,col:c+r,criteria:{...h.serialize(),colId:c+r}}}),a.push({id:p.id,params:{...s,col:c+r,criteria:null}})}),{newRange:{redos:d,undos:a},oldRange:{redos:l,undos:o}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{var d,m;const{unitId:t,subUnitId:r}=n.params||{},s=this._sheetsFilterService.getFilterModel(t,r);if(!s)return;const o=Array.from(s.filteredOutRows).sort((c,h)=>c-h),l=[];let a=!1;if(n.id===F.RemoveRowMutation.id){const{startRow:c,endRow:h}=n.params.range,C=o.filter(_=>_>=c&&_<=h);o.forEach(_=>{if(_<c)l.push(_);else if(a=!0,_<=h){const v=Math.max(c,l.length?l[l.length-1]+1:c);l.push(v)}else l.push(_-(h-c+1-C.length))})}if(n.id===F.InsertRowMutation.id){const{startRow:c,endRow:h}=n.params.range;o.forEach(C=>{C>=c?(a=!0,l.push(C+(h-c+1))):l.push(C)})}if(a&&(s.filteredOutRows=new Set(l)),n.id===F.SetRangeValuesMutation.id&&!(e!=null&&e.onlyLocal)){const c=this._getExtendRegion(t,r);if(c){const h=n.params.cellValue;if(h)for(let C=c.startColumn;C<=c.endColumn;C++){const _=(d=h==null?void 0:h[c.startRow])==null?void 0:d[C];if(_&&this._cellHasValue(_)){const v=(m=this._univerInstanceService.getUnit(t))==null?void 0:m.getSheetBySheetId(r);if(v){const E=F.expandToContinuousRange(c,{down:!0},v),w=this._sheetsFilterService.getFilterModel(t,r),R=w.getRange();w.setRange({...R,endRow:E.endRow}),this._registerRefRange(t,r)}}}}}}))}_getExtendRegion(n,e){var a;const t=this._sheetsFilterService.getFilterModel(n,e);if(!t)return null;const r=(a=this._univerInstanceService.getUnit(n))==null?void 0:a.getSheetBySheetId(e);if(!r)return null;const s=t.getRange();if(!s)return null;const o=r.getRowCount()-1,l=r.getRowManager();for(let d=s.endRow+1;d<=o;d++)if(l.getRowRawVisible(d))return{startRow:d,endRow:d,startColumn:s.startColumn,endColumn:s.endColumn};return null}_initErrorHandling(){this.disposeWithMe(this._commandService.beforeCommandExecuted(n=>{const e=n.params,t=F.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===F.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))}};B=ye([L(0,u.ICommandService),L(1,u.Inject(F.SheetInterceptorService)),L(2,u.Inject(g.SheetsFilterService)),L(3,u.IUniverInstanceService),L(4,u.Inject(F.RefRangeService))],B);const Oe="sheets-filter.config",Te={};var Ie=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,Ne=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ae(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&Ie(n,e,r),r},ne=(i,n)=>(e,t)=>n(e,t,i);g.UniverSheetsFilterPlugin=(x=class extends u.Plugin{constructor(n=Te,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=this._config;this._configService.setConfig(Oe,r)}onStarting(){[[g.SheetsFilterService],[B]].forEach(n=>this._injector.add(n))}onReady(){this._injector.get(B)}},M(x,"type",u.UniverInstanceType.UNIVER_SHEET),M(x,"pluginName",V),x),g.UniverSheetsFilterPlugin=Ne([ne(1,u.Inject(u.Injector)),ne(2,u.IConfigService)],g.UniverSheetsFilterPlugin);const ie={id:"sheet.command.set-filter-range",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(g.SheetsFilterService),t=i.get(u.ICommandService),r=i.get(u.IUndoRedoService),s=i.get(u.IUniverInstanceService),{unitId:o,subUnitId:l,range:a}=n;if(!F.getSheetCommandTarget(s,n)||e.getFilterModel(o,l))return!1;if(a.endRow===a.startRow){const C=i.get(u.ErrorService),_=i.get(u.LocaleService);return C.emit(_.t("sheets-filter.command.not-valid-filter-range")),!1}const c={id:S.id,params:{unitId:o,subUnitId:l,range:a}},h=t.syncExecuteCommand(c.id,c.params);return h&&r.pushUndoRedo({unitID:o,undoMutations:[{id:T.id,params:{unitId:o,subUnitId:l}}],redoMutations:[c]}),h}},se={id:"sheet.command.remove-sheet-filter",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(u.IUniverInstanceService),t=i.get(g.SheetsFilterService),r=i.get(u.ICommandService),s=i.get(u.IUndoRedoService),o=F.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,d=t.getFilterModel(l,a);if(!d)return!1;const m=d==null?void 0:d.serialize(),c=Le(l,a,m),h=r.syncExecuteCommand(T.id,{unitId:l,subUnitId:a});return h&&s.pushUndoRedo({unitID:l,undoMutations:c,redoMutations:[{id:T.id,params:{unitId:l,subUnitId:a}}]}),h}},Ue={id:"sheet.command.smart-toggle-filter",type:u.CommandType.COMMAND,handler:async i=>{const n=i.get(u.IUniverInstanceService),e=i.get(g.SheetsFilterService),t=i.get(u.ICommandService),r=n.getCurrentUnitForType(u.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(se.id,{unitId:o,subUnitId:l});const m=i.get(F.SheetsSelectionsService).getCurrentLastSelection();if(!m)return!1;const c=m.range,h=F.isSingleCellSelection(m)?F.expandToContinuousRange(c,{left:!0,right:!0,up:!0,down:!0},s):c;return t.executeCommand(ie.id,{unitId:o,subUnitId:l,range:h})}},$e={id:"sheet.command.set-filter-criteria",type:u.CommandType.COMMAND,handler:async(i,n)=>{const e=i.get(g.SheetsFilterService),t=i.get(u.ICommandService),r=i.get(u.IUndoRedoService),{unitId:s,subUnitId:o,col:l,criteria:a}=n,d=e.getFilterModel(s,o);if(!d)return!1;const m=d.getRange();if(!m||l<m.startColumn||l>m.endColumn)return!1;const c=d.getFilterColumn(l),h=xe(s,o,l,c),C={id:p.id,params:{unitId:s,subUnitId:o,col:l,criteria:a}},_=t.syncExecuteCommand(C.id,C.params);return _&&r.pushUndoRedo({unitID:s,undoMutations:[h],redoMutations:[C]}),_}},Pe={id:"sheet.command.clear-filter-criteria",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(g.SheetsFilterService),t=i.get(u.IUndoRedoService),r=i.get(u.ICommandService),s=i.get(u.IUniverInstanceService),o=F.getSheetCommandTarget(s,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,d=e.getFilterModel(o.unitId,o.subUnitId);if(!d)return!1;const m=d.serialize(),c=oe(l,a,m),h=Be(l,a,m);return u.sequenceExecute(h,r).result?(t.pushUndoRedo({unitID:l,undoMutations:c,redoMutations:h}),!0):!1}},be={id:"sheet.command.re-calc-filter",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(g.SheetsFilterService),t=i.get(u.ICommandService),r=i.get(u.IUniverInstanceService),s=F.getSheetCommandTarget(r,n);if(!s)return!1;const{unitId:o,subUnitId:l}=s;return e.getFilterModel(s.unitId,s.subUnitId)?t.executeCommand(U.id,{unitId:o,subUnitId:l}):!1}};function Le(i,n,e){const t=[],r={id:S.id,params:{unitId:i,subUnitId:n,range:e.ref}};return t.push(r),oe(i,n,e).forEach(o=>t.push(o)),t}function oe(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 Be(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}}}g.ClearSheetsFilterCriteriaCommand=Pe,g.CustomFilterOperator=I,g.FILTER_MUTATIONS=re,g.FilterColumn=ee,g.FilterModel=b,g.ReCalcSheetsFilterCommand=be,g.ReCalcSheetsFilterMutation=U,g.RemoveSheetFilterCommand=se,g.RemoveSheetsFilterMutation=T,g.SHEET_FILTER_SNAPSHOT_ID=V,g.SetSheetFilterRangeCommand=ie,g.SetSheetsFilterCriteriaCommand=$e,g.SetSheetsFilterCriteriaMutation=p,g.SetSheetsFilterRangeMutation=S,g.SmartToggleSheetsFilterCommand=Ue,g.equals=Y,g.getCustomFilterFn=D,g.greaterThan=q,g.greaterThanOrEqualTo=Q,g.lessThan=G,g.lessThanOrEqualTo=J,g.notEquals=z,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(g,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs"],u):(g=typeof globalThis<"u"?globalThis:g||self,u(g.UniverSheetsFilter={},g.UniverCore,g.UniverSheets,g.rxjs))})(this,function(g,u,R,T){"use strict";var We=Object.defineProperty;var qe=(g,u,R)=>u in g?We(g,u,{enumerable:!0,configurable:!0,writable:!0,value:R}):g[u]=R;var M=(g,u,R)=>qe(g,typeof u!="symbol"?u+"":u,R);var x;const me="sheets-filter.config",fe={},q="sheet.mutation.set-filter-range",Q="sheet.mutation.set-filter-criteria",G="sheet.mutation.remove-filter",J="sheet.mutation.re-calc-filter",Y=new Set([q,Q,G,J]);var I=(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))(I||{});const K={operator:I.GREATER_THAN,fn:(i,n)=>U(i)?i>n:!1},X={operator:I.GREATER_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i>=n:!1},Z={operator:I.LESS_THAN,fn:(i,n)=>U(i)?i<n:!1},k={operator:I.LESS_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i<=n:!1},ee={operator:I.EQUAL,fn:(i,n)=>U(i)?i===n:!1},H={operator:I.NOT_EQUALS,fn:(i,n)=>{if(typeof n=="string"){if(n===" ")return i!=null;const e=ne(i);return e&&_e(n)?!ie(n).test(e):e!==n}return U(i)?i!==n:!0}},te=new Map([]);[K,X,Z,k,ee,H].forEach(i=>{te.set(i.operator,i)});function ge(i){return!!i}const Ce={fn:(i,n)=>{const e=ne(i);return e===null?n==="":ie(n).test(e)}};function z(i){return i?te.get(i):Ce}function U(i){return typeof i=="number"}function re(i){return!!(typeof i=="number"||typeof i=="string"&&u.isNumeric(i))}function ne(i){return typeof i=="boolean"||i==null?null:typeof i=="string"?i:i.toString()}function _e(i){return typeof i=="number"?!1:i.indexOf("*")!==-1||i.indexOf("?")!==-1}function ie(i){const n=i.replace(/[.+^${}()|[\]\\]/g,"\\$&").replaceAll("?",".").replace(/[*]/g,".$&");return new RegExp(`^${n}$`)}const D=()=>new Set;class P extends u.Disposable{constructor(e,t,r){super();M(this,"_filteredOutRows$",new T.BehaviorSubject(D()));M(this,"filteredOutRows$",this._filteredOutRows$.asObservable());M(this,"_hasCriteria$",new T.BehaviorSubject(!1));M(this,"hasCriteria$",this._hasCriteria$.asObservable());M(this,"_filterColumnByIndex",new Map);M(this,"_alreadyFilteredOutRows",D());M(this,"_range");this.unitId=e,this.subUnitId=t,this._worksheet=r}get filteredOutRows(){return this._filteredOutRows$.getValue()}set filteredOutRows(e){this._alreadyFilteredOutRows=e,this._filteredOutRows$.next(e)}dispose(){super.dispose(),this._filteredOutRows$.complete(),this._hasCriteria$.complete()}serialize(){const e={ref:u.Rectangle.clone(this._range),filterColumns:this._getAllFilterColumns(!0).sort(([t],[r])=>t-r).map(([t,r])=>r.serialize())};return this._alreadyFilteredOutRows&&(e.cachedFilteredOut=Array.from(this._alreadyFilteredOutRows).sort()),e}static deserialize(e,t,r,s){const o=new P(e,t,r);return o._dump(s),o}_dump(e){var t;this.setRange(e.ref),(t=e.filterColumns)==null||t.forEach(r=>this._setCriteriaWithoutReCalc(r.colId,r)),e.cachedFilteredOut&&(this._alreadyFilteredOutRows=new Set(e.cachedFilteredOut),this._emit()),this._emitHasCriteria()}isRowFiltered(e){return this._alreadyFilteredOutRows.has(e)}getRange(){if(!this._range)throw new Error("[FilterModel] could not get range before a range is set!");return this._range}getFilteredOutRowsExceptCol(e){return this._getAllFilterColumns(!0).filter(([t])=>t!==e).reduce((t,[,r])=>{const s=r.calc({getAlreadyFilteredOutRows:()=>t});return s?u.mergeSets(t,s):t},new Set)}setRange(e){this._range=e,this._getAllFilterColumns(!0).forEach(([t,r])=>{r.setRangeAndColumn({startRow:e.startRow,endRow:e.endRow,startColumn:t,endColumn:t},t)})}setCriteria(e,t,r=!1){if(!this._range)throw new Error("[FilterModel] could not set criteria before a range is set!");if(!t){this._removeCriteria(e),this._rebuildAlreadyFilteredOutRowsWithCache(),r&&this._reCalcAllColumns(),this._emit(),this._emitHasCriteria();return}this._setCriteriaWithoutReCalc(e,t),r&&(this._rebuildAlreadyFilteredOutRowsWithCache(),this._reCalcWithNoCacheColumns(),this._emit(),this._emitHasCriteria())}getAllFilterColumns(){return this._getAllFilterColumns(!0)}getFilterColumn(e){var t;return(t=this._filterColumnByIndex.get(e))!=null?t:null}reCalc(){this._reCalcAllColumns(),this._emit()}_getAllFilterColumns(e=!1){const t=Array.from(this._filterColumnByIndex.entries());return e?t:t.map(([r,s])=>s)}_reCalcAllColumns(){this._alreadyFilteredOutRows=D(),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 se(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)=>u.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=u.mergeSets(this._alreadyFilteredOutRows,r))}}}class se extends u.Disposable{constructor(e,t,r,s,o){super();M(this,"_filteredOutRows",null);M(this,"_filterFn",null);M(this,"_range",null);M(this,"_column",0);M(this,"_filterByValues",!1);this.unitId=e,this.subUnitId=t,this._worksheet=r,this._criteria=s,this._filterColumnContext=o}get filteredOutRows(){return this._filteredOutRows}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 u.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 u.Tools.deepClone(this._criteria)}reCalc(){return this._filteredOutRows=this.calc(this._filterColumnContext),this._filteredOutRows}calc(e){if(!this._filterFn)throw new Error("[FilterColumn] cannot calculate without a filter fn!");if(!this._range)throw new Error("[FilterColumn] cannot calculate without a range!");if(typeof this._column!="number")throw new TypeError("[FilterColumn] cannot calculate without a column offset!");const t=this._column,r={startColumn:t,endColumn:t,startRow:this._range.startRow+1,endRow:this._range.endRow},s=new Set,o=e.getAlreadyFilteredOutRows();for(const l of this._worksheet.iterateByColumn(r,!1,!1)){const{row:a,rowSpan:d,col:m}=l;if(o.has(a)&&(!d||d===1))continue;const c=this._filterByValues?u.extractPureTextFromCell(this._worksheet.getCell(a,m)):Ee(this._worksheet,a,m);if(!this._filterFn(c)&&(s.add(a),d))for(let h=1;h<d;h++)s.add(a+h)}return s}_generateFilterFn(){this._criteria&&(this._filterFn=Re(this._criteria),this._filterByValues=!!this._criteria.filters)}}function Re(i){if(i.filters)return Se(i.filters);if(i.customFilters)return Fe(i.customFilters);throw new Error("[FilterModel]: other types of filters are not supported yet.")}function Se(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 Fe(i){const n=i.customFilters.map(e=>Me(e));return we(n)?i.and?pe(n):ve(n):n[0]}function pe(i){const[n,e]=i;return t=>n(t)&&e(t)}function ve(i){const[n,e]=i;return t=>n(t)||e(t)}function we(i){return i.length===2}function Me(i){const n=i.val;if(i.operator===I.NOT_EQUALS&&!re(n))return r=>H.fn(r,n);if(ge(i.operator)){if(!re(n))return()=>!1;const r=z(i.operator),s=Number(n);return o=>r.fn(o,s)}const e=z(i.operator);return t=>e.fn(t,n)}function Ee(i,n,e){const t=i.getCell(n,e);if(!t)return null;const r=i.getCellRaw(n,e);return t&&!r?oe(t):r?t.t===u.CellValueType.NUMBER&&typeof t.v=="string"?r.v:oe(r):null}function oe(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===u.CellValueType.BOOLEAN?e.toUpperCase():e:typeof e=="number"?i.t===u.CellValueType.BOOLEAN?e?"TRUE":"FALSE":e:typeof e=="boolean"?e?"TRUE":"FALSE":""}var ye=Object.defineProperty,Oe=Object.getOwnPropertyDescriptor,Te=(i,n,e,t)=>{for(var r=t>1?void 0:t?Oe(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&ye(n,e,r),r},j=(i,n)=>(e,t)=>n(e,t,i);const V="SHEET_FILTER_PLUGIN";g.SheetsFilterService=class extends u.Disposable{constructor(e,t,r){super();M(this,"_filterModels",new Map);M(this,"_loadedUnitId$",new T.BehaviorSubject(null));M(this,"loadedUnitId$",this._loadedUnitId$.asObservable());M(this,"_errorMsg$",new T.BehaviorSubject(null));M(this,"errorMsg$",this._errorMsg$.asObservable());M(this,"_activeFilterModel$",new T.BehaviorSubject(null));M(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(u.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(T.merge(u.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(T.filter(([e])=>e.type===u.CommandType.MUTATION&&Y.has(e.id))),this._univerInstanceService.getCurrentTypeOfUnit$(u.UniverInstanceType.UNIVER_SHEET).pipe(T.switchMap(e=>{var t;return(t=e==null?void 0:e.activeSheet$)!=null?t:T.of(null)}))).subscribe(()=>this._updateActiveFilterModel()))}_serializeAutoFiltersForUnit(e){const t=this._filterModels.get(e);if(!t)return"{}";const r={};return t.forEach((s,o)=>{r[o]=s.serialize()}),JSON.stringify(r)}_deserializeAutoFiltersForUnit(e,t){const r=this._univerInstanceService.getUniverSheetInstance(e);Object.keys(t).forEach(s=>{const o=t[s],l=P.deserialize(e,s,r.getSheetBySheetId(s),o);this._cacheFilterModel(e,s,l)})}_initModel(){this._resourcesManagerService.registerPluginResource({pluginName:V,businesses:[u.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)}},g.SheetsFilterService=Te([j(0,u.IResourceManagerService),j(1,u.IUniverInstanceService),j(2,u.ICommandService)],g.SheetsFilterService);const F={id:q,type:u.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,range:r}=n;return i.get(g.SheetsFilterService).ensureFilterModel(t,e).setRange(r),!0}},p={id:Q,type:u.CommandType.MUTATION,handler:(i,n)=>{const{subUnitId:e,unitId:t,criteria:r,col:s,reCalc:o=!0}=n,a=i.get(g.SheetsFilterService).getFilterModel(t,e);return a?(a.setCriteria(s,r,o),!0):!1}},O={id:G,type:u.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(g.SheetsFilterService).removeFilterModel(e,t)}},b={id:J,type:u.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n,s=i.get(g.SheetsFilterService).getFilterModel(e,t);return s?(s.reCalc(),!0):!1}};function Ie(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 $(i){return Ie(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 Ae=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,Ue=(i,n,e,t)=>{for(var r=t>1?void 0:t?Ne(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&Ae(n,e,r),r},L=(i,n)=>(e,t)=>n(e,t,i);let B=class extends u.Disposable{constructor(n,e,t,r,s){super();M(this,"_disposableCollection",new u.DisposableCollection);this._commandService=n,this._sheetInterceptorService=e,this._sheetsFilterService=t,this._univerInstanceService=r,this._refRangeService=s,this._initCommands(),this._initRowFilteredInterceptor(),this._initInterceptors(),this._commandExecutedListener(),this._initErrorHandling()}_initCommands(){[p,F,b,O].forEach(n=>this.disposeWithMe(this._commandService.registerCommand(n)))}_initInterceptors(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:n=>this._getUpdateFilter(n)})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===R.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 R.InsertRowCommand.id:{const d=a.params,m=d.unitId||n,c=d.subUnitId||e;return this._handleInsertRowCommand(d,m,c)}case R.InsertColCommand.id:{const d=a.params,m=d.unitId||n,c=d.subUnitId||e;return this._handleInsertColCommand(d,m,c)}case R.RemoveColCommand.id:{const d=a.params;return this._handleRemoveColCommand(d,n,e)}case R.RemoveRowCommand.id:{const d=a.params;return this._handleRemoveRowCommand(d,n,e)}case R.EffectRefRangId.MoveColsCommandId:{const d=a.params;return this._handleMoveColsCommand(d,n,e)}case R.EffectRefRangId.MoveRowsCommandId:{const d=a.params;return this._handleMoveRowsCommand(d,n,e)}case R.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 R.RemoveSheetCommand.id:{const t=n.params;return this._handleRemoveSheetCommand(t,t.unitId,t.subUnitId)}case R.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 S;const r=this._sheetsFilterService.getFilterModel(e,t),s=(S=r==null?void 0:r.getRange())!=null?S:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{startColumn:a,endColumn:d}=n.range,m=d-a+1;if(d>l)return this._handleNull();const c=[],h=[],C=a,_={unitId:e,subUnitId:t,range:{...s,startColumn:a<=o?o+m:o,endColumn:l+m}},v={unitId:e,subUnitId:t,range:s};c.push({id:F.id,params:_}),h.push({id:F.id,params:v});const w=r.getAllFilterColumns().filter(f=>f[0]>=C);if(w.length!==0){const{newRange:f,oldRange:y}=this.moveCriteria(e,t,w,m);c.push(...f.redos,...y.redos),h.push(...f.undos,...y.undos)}return{redos:$(c),undos:$(h)}}_handleInsertRowCommand(n,e,t){var v;const r=this._sheetsFilterService.getFilterModel(e,t),s=(v=r==null?void 0:r.getRange())!=null?v:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{startRow:a,endRow:d}=n.range,m=d-a+1;if(d>l)return this._handleNull();const c=[],h=[],C={unitId:e,subUnitId:t,range:{...s,startRow:a<=o?o+m:o,endRow:l+m}},_={unitId:e,subUnitId:t,range:s};return c.push({id:F.id,params:C}),h.push({id:F.id,params:_}),{redos:$(c),undos:$(h)}}_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.range;if(a>l)return this._handleNull();const m=[],c=[],h=d<o?0:Math.min(d,l)-Math.max(a,o)+1,C=d-a+1,_=r.getAllFilterColumns();_.forEach(S=>{const[f,y]=S;f<=d&&f>=a&&(m.push({id:p.id,params:{unitId:e,subUnitId:t,col:f,criteria:null}}),c.push({id:p.id,params:{unitId:e,subUnitId:t,col:f,criteria:{...y.serialize(),colId:f}}}))});const v=_.filter(S=>{const[f,y]=S;return f>d});let E={undos:[],redos:[]};if(v.length>0){const{oldRange:S,newRange:f}=this.moveCriteria(e,t,v,-C);E=f,m.push(...S.redos),c.unshift(...S.undos)}if(h===l-o+1){const S={unitId:e,subUnitId:t};m.push({id:O.id,params:S}),c.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}})}else{const S=o<=a?o:h===0?o-C:a,f=o<=a?l-h:l-C,y={unitId:e,subUnitId:t,range:{...s,startColumn:S,endColumn:f}};m.push({id:F.id,params:y}),c.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}}),m.push(...E.redos),c.unshift(...E.undos)}return{undos:c,redos:m}}_handleRemoveRowCommand(n,e,t){var v;const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange(),{startRow:o,endRow:l}=s,{startRow:a,endRow:d}=n.range;if(a>l)return this._handleNull();if(d<o)return{undos:[{id:F.id,params:{range:s,unitId:e,subUnitId:t}}],redos:[{id:F.id,params:{range:{...s,startRow:o-(d-a+1),endRow:l-(d-a+1)},unitId:e,subUnitId:t}}]};const m=[],c=[],h=r.getAllFilterColumns(),C=o<=d&&o>=a;c.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 E={unitId:e,subUnitId:t};m.push({id:O.id,params:E}),h.forEach(w=>{const[S,f]=w,y={unitId:e,subUnitId:t,col:S,criteria:{...f.serialize(),colId:S}};c.push({id:p.id,params:y})})}else{const E=(v=this._univerInstanceService.getUniverSheetInstance(e))==null?void 0:v.getSheetBySheetId(t);if(!E)return this._handleNull();const w=[];for(let A=a;A<=d;A++)E.getRowFiltered(A)&&w.push(A);const S=Math.min(o,a),f=S+(l-o)-_+w.length,y={unitId:e,subUnitId:t,range:{...s,startRow:S,endRow:f}};m.push({id:F.id,params:y})}return{undos:$(c),redos:$(m)}}_handleMoveColsCommand(n,e,t){var S;const r=this._sheetsFilterService.getFilterModel(e,t),s=(S=r==null?void 0:r.getRange())!=null?S:null;if(!r||!s)return this._handleNull();const{startColumn:o,endColumn:l}=s,{fromRange:a,toRange:d}=n;if(a.endColumn<o&&d.startColumn<=o||a.startColumn>l&&d.endColumn>l)return this._handleNull();const m=[],c=[],h={};for(let f=o;f<=l;f++)h[f]={colIndex:f,filter:r.getFilterColumn(f)};u.moveMatrixArray(a.startColumn,a.endColumn-a.startColumn+1,d.startColumn,h);let C=s.startColumn,_=s.endColumn;o>=a.startColumn&&o<=a.endColumn&&d.startColumn>a.startColumn&&a.endColumn<l&&(C=a.endColumn+1),l>=a.startColumn&&l<=a.endColumn&&d.startColumn<a.startColumn&&a.startColumn>o&&(_=a.startColumn-1);const v=Object.keys(h).map(f=>Number(f)),E=v.find(f=>h[f].colIndex===_),w=v.find(f=>h[f].colIndex===C);if(v.forEach(f=>{var ce,he;const{colIndex:y,filter:A}=h[f],N=f;if(A){if(N>=w&&N<=E){const W={unitId:e,subUnitId:t,col:N,criteria:{...A.serialize(),colId:N}},Ve={unitId:e,subUnitId:t,col:N,criteria:r.getFilterColumn(N)?{...(ce=r.getFilterColumn(N))==null?void 0:ce.serialize(),colId:N}:null};m.push({id:p.id,params:W}),c.push({id:p.id,params:Ve})}if(!((he=h[y])!=null&&he.filter)){const W={unitId:e,subUnitId:t,col:y,criteria:null};m.push({id:p.id,params:W}),c.push({id:p.id,params:{unitId:e,subUnitId:t,col:y,criteria:{...A.serialize(),colId:y}}})}}}),o!==w||l!==E){const f={unitId:e,subUnitId:t,range:{...s,startColumn:w,endColumn:E}};m.unshift({id:F.id,params:f}),c.unshift({id:F.id,params:{range:s,unitId:e,subUnitId:t}})}return{undos:c,redos:m}}_handleMoveRowsCommand(n,e,t){var S;const r=this._sheetsFilterService.getFilterModel(e,t),s=(S=r==null?void 0:r.getRange())!=null?S:null;if(!r||!s)return this._handleNull();const{startRow:o,endRow:l}=s,{fromRange:a,toRange:d}=n;if(a.endRow<o&&d.startRow<=o||a.startRow>l&&d.endRow>l)return this._handleNull();const m=[],c=[],h={};for(let f=o;f<=l;f++)h[f]={oldIndex:f};const C=o;let _=l;l>=a.startRow&&l<=a.endRow&&d.startRow<a.startRow&&a.startRow>o&&(_=a.startRow-1),u.moveMatrixArray(a.startRow,a.endRow-a.startRow+1,d.startRow,h);const v=Object.keys(h).map(f=>Number(f)),E=v.find(f=>h[f].oldIndex===_),w=v.find(f=>h[f].oldIndex===C);if(o!==w||l!==E){const f={unitId:e,subUnitId:t,range:{...s,startRow:w,endRow:E}};m.push({id:F.id,params:f},{id:b.id,params:{unitId:e,subUnitId:t}}),c.push({id:F.id,params:{range:s,unitId:e,subUnitId:t}},{id:b.id,params:{unitId:e,subUnitId:t}})}return{redos:m,undos:c}}_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(u.Rectangle.contains(r,l)){const m=l.startRow-r.startRow,c=l.startColumn-r.startColumn,h={startRow:s.startRow+m,startColumn:s.startColumn+c,endRow:s.startRow+m+(l.endRow-l.startRow),endColumn:s.startColumn+c+(l.endColumn-l.startColumn)},C={id:O.id,params:{unitId:e,subUnitId:t}},_={id:F.id,params:{unitId:e,subUnitId:t,range:h}},v={id:F.id,params:{unitId:e,subUnitId:t,range:l}};a.push(C,_),d.push(C,v);const E=o.getAllFilterColumns(),w=s.startColumn-r.startColumn;E.forEach(S=>{const[f,y]=S;y&&(a.push({id:p.id,params:{unitId:e,subUnitId:t,col:f+w,criteria:{...y.serialize(),colId:f+w}}}),d.push({id:p.id,params:{unitId:e,subUnitId:t,col:f,criteria:{...y.serialize(),colId:f}}}))})}else if(u.Rectangle.intersects(s,l)){const m={...l,endRow:Math.max(l.endRow,s.endRow)};a.push({id:F.id,params:{unitId:e,subUnitId:t,range:m}}),d.push({id:F.id,params:{unitId:e,subUnitId:t,range:l}})}return{redos:a,undos:d}}_handleRemoveSheetCommand(n,e,t){const r=this._sheetsFilterService.getFilterModel(e,t);if(!r)return this._handleNull();const s=r.getRange();if(!s)return this._handleNull();const o=[],l=[];return r.getAllFilterColumns().forEach(([d,m])=>{l.push({id:p.id,params:{unitId:e,subUnitId:t,col:d,criteria:{...m.serialize(),colId:d}}})}),o.push({id:O.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(([c,h])=>{o.push({id:p.id,params:{unitId:n,subUnitId:t,col:c,criteria:{...h.serialize(),colId:c}}}),a.push({id:p.id,params:{unitId:n,subUnitId:t,col:c,criteria:null}})}),a.push({id:O.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(R.INTERCEPTOR_POINT.ROW_FILTERED,{handler:(n,e)=>{var t,r;return n?!0:(r=(t=this._sheetsFilterService.getFilterModel(e.unitId,e.subUnitId))==null?void 0:t.isRowFiltered(e.row))!=null?r:!1}}))}moveCriteria(n,e,t,r){const s={unitId:n,subUnitId:e,criteria:null,col:-1},o=[],l=[],a=[],d=[];return t.forEach(m=>{const[c,h]=m;l.push({id:p.id,params:{...s,col:c}}),o.push({id:p.id,params:{...s,col:c,criteria:{...h.serialize(),colId:c}}})}),t.forEach(m=>{const[c,h]=m;d.push({id:p.id,params:{...s,col:c+r,criteria:{...h.serialize(),colId:c+r}}}),a.push({id:p.id,params:{...s,col:c+r,criteria:null}})}),{newRange:{redos:d,undos:a},oldRange:{redos:l,undos:o}}}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,e)=>{var d,m;const{unitId:t,subUnitId:r}=n.params||{},s=this._sheetsFilterService.getFilterModel(t,r);if(!s)return;const o=Array.from(s.filteredOutRows).sort((c,h)=>c-h),l=[];let a=!1;if(n.id===R.RemoveRowMutation.id){const{startRow:c,endRow:h}=n.params.range,C=o.filter(_=>_>=c&&_<=h);o.forEach(_=>{if(_<c)l.push(_);else if(a=!0,_<=h){const v=Math.max(c,l.length?l[l.length-1]+1:c);l.push(v)}else l.push(_-(h-c+1-C.length))})}if(n.id===R.InsertRowMutation.id){const{startRow:c,endRow:h}=n.params.range;o.forEach(C=>{C>=c?(a=!0,l.push(C+(h-c+1))):l.push(C)})}if(a&&(s.filteredOutRows=new Set(l)),n.id===R.SetRangeValuesMutation.id&&!(e!=null&&e.onlyLocal)){const c=this._getExtendRegion(t,r);if(c){const h=n.params.cellValue;if(h)for(let C=c.startColumn;C<=c.endColumn;C++){const _=(d=h==null?void 0:h[c.startRow])==null?void 0:d[C];if(_&&this._cellHasValue(_)){const v=(m=this._univerInstanceService.getUnit(t))==null?void 0:m.getSheetBySheetId(r);if(v){const E=R.expandToContinuousRange(c,{down:!0},v),w=this._sheetsFilterService.getFilterModel(t,r),S=w.getRange();w.setRange({...S,endRow:E.endRow}),this._registerRefRange(t,r)}}}}}}))}_getExtendRegion(n,e){var a;const t=this._sheetsFilterService.getFilterModel(n,e);if(!t)return null;const r=(a=this._univerInstanceService.getUnit(n))==null?void 0:a.getSheetBySheetId(e);if(!r)return null;const s=t.getRange();if(!s)return null;const o=r.getRowCount()-1,l=r.getRowManager();for(let d=s.endRow+1;d<=o;d++)if(l.getRowRawVisible(d))return{startRow:d,endRow:d,startColumn:s.startColumn,endColumn:s.endColumn};return null}_initErrorHandling(){this.disposeWithMe(this._commandService.beforeCommandExecuted(n=>{const e=n.params,t=R.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===R.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))}};B=Ue([L(0,u.ICommandService),L(1,u.Inject(R.SheetInterceptorService)),L(2,u.Inject(g.SheetsFilterService)),L(3,u.IUniverInstanceService),L(4,u.Inject(R.RefRangeService))],B);var $e=Object.defineProperty,Pe=Object.getOwnPropertyDescriptor,be=(i,n,e,t)=>{for(var r=t>1?void 0:t?Pe(n,e):n,s=i.length-1,o;s>=0;s--)(o=i[s])&&(r=(t?o(n,e,r):o(r))||r);return t&&r&&$e(n,e,r),r},le=(i,n)=>(e,t)=>n(e,t,i);g.UniverSheetsFilterPlugin=(x=class extends u.Plugin{constructor(n=fe,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=this._config;this._configService.setConfig(me,r)}onStarting(){[[g.SheetsFilterService],[B]].forEach(n=>this._injector.add(n))}onReady(){this._injector.get(B)}},M(x,"type",u.UniverInstanceType.UNIVER_SHEET),M(x,"pluginName",V),x),g.UniverSheetsFilterPlugin=be([le(1,u.Inject(u.Injector)),le(2,u.IConfigService)],g.UniverSheetsFilterPlugin);const ae={id:"sheet.command.set-filter-range",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(g.SheetsFilterService),t=i.get(u.ICommandService),r=i.get(u.IUndoRedoService),s=i.get(u.IUniverInstanceService),{unitId:o,subUnitId:l,range:a}=n;if(!R.getSheetCommandTarget(s,n)||e.getFilterModel(o,l))return!1;if(a.endRow===a.startRow){const C=i.get(u.ErrorService),_=i.get(u.LocaleService);return C.emit(_.t("sheets-filter.command.not-valid-filter-range")),!1}const c={id:F.id,params:{unitId:o,subUnitId:l,range:a}},h=t.syncExecuteCommand(c.id,c.params);return h&&r.pushUndoRedo({unitID:o,undoMutations:[{id:O.id,params:{unitId:o,subUnitId:l}}],redoMutations:[c]}),h}},de={id:"sheet.command.remove-sheet-filter",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(u.IUniverInstanceService),t=i.get(g.SheetsFilterService),r=i.get(u.ICommandService),s=i.get(u.IUndoRedoService),o=R.getSheetCommandTarget(e,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,d=t.getFilterModel(l,a);if(!d)return!1;const m=d==null?void 0:d.serialize(),c=ze(l,a,m),h=r.syncExecuteCommand(O.id,{unitId:l,subUnitId:a});return h&&s.pushUndoRedo({unitID:l,undoMutations:c,redoMutations:[{id:O.id,params:{unitId:l,subUnitId:a}}]}),h}},Le={id:"sheet.command.smart-toggle-filter",type:u.CommandType.COMMAND,handler:async i=>{const n=i.get(u.IUniverInstanceService),e=i.get(g.SheetsFilterService),t=i.get(u.ICommandService),r=n.getCurrentUnitForType(u.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(de.id,{unitId:o,subUnitId:l});const m=i.get(R.SheetsSelectionsService).getCurrentLastSelection();if(!m)return!1;const c=m.range,h=R.isSingleCellSelection(m)?R.expandToContinuousRange(c,{left:!0,right:!0,up:!0,down:!0},s):c;return t.executeCommand(ae.id,{unitId:o,subUnitId:l,range:h})}},Be={id:"sheet.command.set-filter-criteria",type:u.CommandType.COMMAND,handler:async(i,n)=>{const e=i.get(g.SheetsFilterService),t=i.get(u.ICommandService),r=i.get(u.IUndoRedoService),{unitId:s,subUnitId:o,col:l,criteria:a}=n,d=e.getFilterModel(s,o);if(!d)return!1;const m=d.getRange();if(!m||l<m.startColumn||l>m.endColumn)return!1;const c=d.getFilterColumn(l),h=je(s,o,l,c),C={id:p.id,params:{unitId:s,subUnitId:o,col:l,criteria:a}},_=t.syncExecuteCommand(C.id,C.params);return _&&r.pushUndoRedo({unitID:s,undoMutations:[h],redoMutations:[C]}),_}},xe={id:"sheet.command.clear-filter-criteria",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(g.SheetsFilterService),t=i.get(u.IUndoRedoService),r=i.get(u.ICommandService),s=i.get(u.IUniverInstanceService),o=R.getSheetCommandTarget(s,n);if(!o)return!1;const{unitId:l,subUnitId:a}=o,d=e.getFilterModel(o.unitId,o.subUnitId);if(!d)return!1;const m=d.serialize(),c=ue(l,a,m),h=De(l,a,m);return u.sequenceExecute(h,r).result?(t.pushUndoRedo({unitID:l,undoMutations:c,redoMutations:h}),!0):!1}},He={id:"sheet.command.re-calc-filter",type:u.CommandType.COMMAND,handler:(i,n)=>{const e=i.get(g.SheetsFilterService),t=i.get(u.ICommandService),r=i.get(u.IUniverInstanceService),s=R.getSheetCommandTarget(r,n);if(!s)return!1;const{unitId:o,subUnitId:l}=s;return e.getFilterModel(s.unitId,s.subUnitId)?t.executeCommand(b.id,{unitId:o,subUnitId:l}):!1}};function ze(i,n,e){const t=[],r={id:F.id,params:{unitId:i,subUnitId:n,range:e.ref}};return t.push(r),ue(i,n,e).forEach(o=>t.push(o)),t}function ue(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 De(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 je(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}}}g.ClearSheetsFilterCriteriaCommand=xe,g.CustomFilterOperator=I,g.FILTER_MUTATIONS=Y,g.FilterColumn=se,g.FilterModel=P,g.ReCalcSheetsFilterCommand=He,g.ReCalcSheetsFilterMutation=b,g.RemoveSheetFilterCommand=de,g.RemoveSheetsFilterMutation=O,g.SHEET_FILTER_SNAPSHOT_ID=V,g.SetSheetFilterRangeCommand=ae,g.SetSheetsFilterCriteriaCommand=Be,g.SetSheetsFilterCriteriaMutation=p,g.SetSheetsFilterRangeMutation=F,g.SmartToggleSheetsFilterCommand=Le,g.equals=ee,g.getCustomFilterFn=z,g.greaterThan=K,g.greaterThanOrEqualTo=X,g.lessThan=Z,g.lessThanOrEqualTo=k,g.notEquals=H,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-filter",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A library for filtering data in Univer Sheet",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -51,15 +51,15 @@
|
|
|
51
51
|
"rxjs": ">=7.0.0"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@univerjs/core": "0.5.
|
|
55
|
-
"@univerjs/sheets": "0.5.
|
|
54
|
+
"@univerjs/core": "0.5.1",
|
|
55
|
+
"@univerjs/sheets": "0.5.1"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"rxjs": "^7.8.1",
|
|
59
|
-
"typescript": "^5.
|
|
60
|
-
"vite": "^
|
|
61
|
-
"vitest": "^2.1.
|
|
62
|
-
"@univerjs-infra/shared": "0.5.
|
|
59
|
+
"typescript": "^5.7.2",
|
|
60
|
+
"vite": "^6.0.1",
|
|
61
|
+
"vitest": "^2.1.6",
|
|
62
|
+
"@univerjs-infra/shared": "0.5.1"
|
|
63
63
|
},
|
|
64
64
|
"space": {
|
|
65
65
|
".": {
|