@univerjs/sheets-filter 0.5.1 → 0.5.2-nightly.202412281605
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 +149 -145
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
"use strict";var fe=Object.defineProperty;var ge=(i,n,e)=>n in i?fe(i,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[n]=e;var w=(i,n,e)=>ge(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"),Ce="sheets-filter.config",Q={},K="sheet.mutation.set-filter-range",X="sheet.mutation.set-filter-criteria",Z="sheet.mutation.remove-filter",k="sheet.mutation.re-calc-filter",ee=new Set([K,X,Z,k]);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 te={operator:T.GREATER_THAN,fn:(i,n)=>x(i)?i>n:!1},re={operator:T.GREATER_THAN_OR_EQUAL,fn:(i,n)=>x(i)?i>=n:!1},ne={operator:T.LESS_THAN,fn:(i,n)=>x(i)?i<n:!1},ie={operator:T.LESS_THAN_OR_EQUAL,fn:(i,n)=>x(i)?i<=n:!1},se={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=le(i);return e&&pe(n)?!ae(n).test(e):e!==n}return x(i)?i!==n:!0}},oe=new Map([]),_e=[te,re,ne,ie,se,D];_e.forEach(i=>{oe.set(i.operator,i)});function Re(i){return!!i}const Se={fn:(i,n)=>{const e=le(i);return e===null?n==="":ae(n).test(e)}};function z(i){return i?oe.get(i):Se}function x(i){return typeof i=="number"}function G(i){return!!(typeof i=="number"||typeof i=="string"&&u.isNumeric(i))}function le(i){return typeof i=="boolean"||i==null?null:typeof i=="string"?i:i.toString()}function pe(i){return typeof i=="number"?!1:i.indexOf("*")!==-1||i.indexOf("?")!==-1}function ae(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 ce(this.unitId,this.subUnitId,this._worksheet,t,{getAlreadyFilteredOutRows:()=>this._alreadyFilteredOutRows}),l.setRangeAndColumn(r,e),this._filterColumnByIndex.set(e,l)),l.setCriteria(t)}_removeCriteria(e){const t=this._filterColumnByIndex.get(e);t&&(t.dispose(),this._filterColumnByIndex.delete(e))}_emit(){this._filteredOutRows$.next(this._alreadyFilteredOutRows)}_emitHasCriteria(){this._hasCriteria$.next(this._filterColumnByIndex.size>0)}_rebuildAlreadyFilteredOutRowsWithCache(){const e=this._getAllFilterColumns().filter(t=>t.hasCache()).reduce((t,r)=>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 ce 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&&!G(n))return r=>D.fn(r,n);if(Re(i.operator)){if(!G(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?J(t):r?t.t===u.CellValueType.NUMBER&&typeof t.v=="string"?r.v:J(r):null}function J(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&&ee.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:K,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:X,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:Z,type:u.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(exports.SheetsFilterService).removeFilterModel(e,t)}},$={id:k,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}},me={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:me})}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},Y=(i,n)=>(e,t)=>n(e,t,i),b;exports.UniverSheetsFilterPlugin=(b=class extends u.Plugin{constructor(n=Q,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=u.merge({},Q,this._config);this._configService.setConfig(Ce,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([Y(1,u.Inject(u.Injector)),Y(2,u.IConfigService)],exports.UniverSheetsFilterPlugin);const de={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}},ue={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(ue.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(de.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=he(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),he(i,n,e).forEach(o=>t.push(o)),t}function he(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id:p.id,params:{unitId:i,subUnitId:n,col:s.colId,criteria:s}};t.push(o)}),t}function 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=ee;exports.FilterColumn=ce;exports.FilterModel=P;exports.ReCalcSheetsFilterCommand=De;exports.ReCalcSheetsFilterMutation=$;exports.RemoveSheetFilterCommand=ue;exports.RemoveSheetsFilterMutation=y;exports.SHEET_FILTER_SNAPSHOT_ID=V;exports.SetSheetFilterRangeCommand=de;exports.SetSheetsFilterCriteriaCommand=je;exports.SetSheetsFilterCriteriaMutation=p;exports.SetSheetsFilterRangeMutation=R;exports.SmartToggleSheetsFilterCommand=He;exports.equals=se;exports.getCustomFilterFn=z;exports.greaterThan=te;exports.greaterThanOrEqualTo=re;exports.lessThan=ne;exports.lessThanOrEqualTo=ie;exports.notEquals=D;
|
package/lib/es/index.js
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var w = (i, r, e) =>
|
|
4
|
-
import { isNumeric as
|
|
5
|
-
import { SheetInterceptorService as
|
|
6
|
-
import { BehaviorSubject as b, merge as
|
|
7
|
-
const
|
|
8
|
-
ae,
|
|
1
|
+
var Fe = Object.defineProperty;
|
|
2
|
+
var we = (i, r, e) => r in i ? Fe(i, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[r] = e;
|
|
3
|
+
var w = (i, r, e) => we(i, typeof r != "symbol" ? r + "" : r, e);
|
|
4
|
+
import { isNumeric as Se, Disposable as V, Rectangle as Y, mergeSets as Q, Tools as k, extractPureTextFromCell as ve, CellValueType as K, UniverInstanceType as U, fromCallback as Me, CommandType as E, IResourceManagerService as Ee, IUniverInstanceService as x, ICommandService as T, Inject as z, DisposableCollection as Oe, moveMatrixArray as ee, Plugin as ye, merge as Ae, Injector as Te, IConfigService as Ne, IUndoRedoService as j, ErrorService as xe, LocaleService as Ie, sequenceExecute as $e } from "@univerjs/core";
|
|
5
|
+
import { SheetInterceptorService as Pe, RefRangeService as Ue, SetWorksheetActiveOperation as be, CopySheetCommand as Le, RemoveSheetCommand as Be, INTERCEPTOR_POINT as ze, RemoveRowMutation as He, InsertRowMutation as De, SetRangeValuesMutation as We, expandToContinuousRange as ae, getSheetCommandTarget as L, MoveRowsCommand as Ve, MoveRangeCommand as je, EffectRefRangId as te, RemoveRowCommand as qe, RemoveColCommand as Qe, InsertColCommand as Ge, InsertRowCommand as Je, SheetsSelectionsService as Ye, isSingleCellSelection as Ke } from "@univerjs/sheets";
|
|
6
|
+
import { BehaviorSubject as b, merge as Xe, filter as Ze, switchMap as ke, of as et } from "rxjs";
|
|
7
|
+
const tt = "sheets-filter.config", re = {}, ce = "sheet.mutation.set-filter-range", de = "sheet.mutation.set-filter-criteria", ue = "sheet.mutation.remove-filter", he = "sheet.mutation.re-calc-filter", rt = /* @__PURE__ */ new Set([
|
|
9
8
|
ce,
|
|
10
9
|
de,
|
|
11
|
-
ue
|
|
10
|
+
ue,
|
|
11
|
+
he
|
|
12
12
|
]);
|
|
13
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
|
|
14
|
+
const nt = {
|
|
15
15
|
operator: N.GREATER_THAN,
|
|
16
16
|
fn: (i, r) => $(i) ? i > r : !1
|
|
17
|
-
},
|
|
17
|
+
}, it = {
|
|
18
18
|
operator: N.GREATER_THAN_OR_EQUAL,
|
|
19
19
|
fn: (i, r) => $(i) ? i >= r : !1
|
|
20
|
-
},
|
|
20
|
+
}, st = {
|
|
21
21
|
operator: N.LESS_THAN,
|
|
22
22
|
fn: (i, r) => $(i) ? i < r : !1
|
|
23
|
-
},
|
|
23
|
+
}, ot = {
|
|
24
24
|
operator: N.LESS_THAN_OR_EQUAL,
|
|
25
25
|
fn: (i, r) => $(i) ? i <= r : !1
|
|
26
|
-
},
|
|
26
|
+
}, lt = {
|
|
27
27
|
operator: N.EQUAL,
|
|
28
28
|
fn: (i, r) => $(i) ? i === r : !1
|
|
29
|
-
},
|
|
29
|
+
}, fe = {
|
|
30
30
|
operator: N.NOT_EQUALS,
|
|
31
31
|
fn: (i, r) => {
|
|
32
32
|
if (typeof r == "string") {
|
|
33
33
|
if (r === " ")
|
|
34
34
|
return i != null;
|
|
35
|
-
const e =
|
|
36
|
-
return e &&
|
|
35
|
+
const e = ge(i);
|
|
36
|
+
return e && ut(r) ? !_e(r).test(e) : e !== r;
|
|
37
37
|
}
|
|
38
38
|
return $(i) ? i !== r : !0;
|
|
39
39
|
}
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
}, me = /* @__PURE__ */ new Map([]), at = [nt, it, st, ot, lt, fe];
|
|
41
|
+
at.forEach((i) => {
|
|
42
|
+
me.set(i.operator, i);
|
|
43
43
|
});
|
|
44
|
-
function
|
|
44
|
+
function ct(i) {
|
|
45
45
|
return !!i;
|
|
46
46
|
}
|
|
47
|
-
const
|
|
47
|
+
const dt = {
|
|
48
48
|
fn: (i, r) => {
|
|
49
|
-
const e =
|
|
50
|
-
return e === null ? r === "" :
|
|
49
|
+
const e = ge(i);
|
|
50
|
+
return e === null ? r === "" : _e(r).test(e);
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
-
function
|
|
54
|
-
return i ?
|
|
53
|
+
function ne(i) {
|
|
54
|
+
return i ? me.get(i) : dt;
|
|
55
55
|
}
|
|
56
56
|
function $(i) {
|
|
57
57
|
return typeof i == "number";
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
return !!(typeof i == "number" || typeof i == "string" &&
|
|
59
|
+
function ie(i) {
|
|
60
|
+
return !!(typeof i == "number" || typeof i == "string" && Se(i));
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function ge(i) {
|
|
63
63
|
return typeof i == "boolean" || i == null ? null : typeof i == "string" ? i : i.toString();
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function ut(i) {
|
|
66
66
|
return typeof i == "number" ? !1 : i.indexOf("*") !== -1 || i.indexOf("?") !== -1;
|
|
67
67
|
}
|
|
68
|
-
function
|
|
68
|
+
function _e(i) {
|
|
69
69
|
const r = i.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("?", ".").replace(/[*]/g, ".$&");
|
|
70
70
|
return new RegExp(`^${r}$`);
|
|
71
71
|
}
|
|
@@ -188,7 +188,7 @@ class D extends V {
|
|
|
188
188
|
if (e > o || e < s)
|
|
189
189
|
throw new Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);
|
|
190
190
|
let l;
|
|
191
|
-
this._filterColumnByIndex.has(e) ? l = this._filterColumnByIndex.get(e) : (l = new
|
|
191
|
+
this._filterColumnByIndex.has(e) ? l = this._filterColumnByIndex.get(e) : (l = new ht(
|
|
192
192
|
this.unitId,
|
|
193
193
|
this.subUnitId,
|
|
194
194
|
this._worksheet,
|
|
@@ -218,7 +218,7 @@ class D extends V {
|
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
-
class
|
|
221
|
+
class ht extends V {
|
|
222
222
|
constructor(e, t, n, s, o) {
|
|
223
223
|
super();
|
|
224
224
|
w(this, "_filteredOutRows", null);
|
|
@@ -283,7 +283,7 @@ class ut extends V {
|
|
|
283
283
|
const { row: a, rowSpan: c, col: h } = l;
|
|
284
284
|
if (o.has(a) && (!c || c === 1))
|
|
285
285
|
continue;
|
|
286
|
-
const d = this._filterByValues ?
|
|
286
|
+
const d = this._filterByValues ? ve(this._worksheet.getCell(a, h)) : Ft(this._worksheet, a, h);
|
|
287
287
|
if (!this._filterFn(d) && (s.add(a), c))
|
|
288
288
|
for (let u = 1; u < c; u++)
|
|
289
289
|
s.add(a + u);
|
|
@@ -291,66 +291,66 @@ class ut extends V {
|
|
|
291
291
|
return s;
|
|
292
292
|
}
|
|
293
293
|
_generateFilterFn() {
|
|
294
|
-
this._criteria && (this._filterFn =
|
|
294
|
+
this._criteria && (this._filterFn = ft(this._criteria), this._filterByValues = !!this._criteria.filters);
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
|
-
function
|
|
297
|
+
function ft(i) {
|
|
298
298
|
if (i.filters)
|
|
299
|
-
return
|
|
299
|
+
return mt(i.filters);
|
|
300
300
|
if (i.customFilters)
|
|
301
|
-
return
|
|
301
|
+
return gt(i.customFilters);
|
|
302
302
|
throw new Error("[FilterModel]: other types of filters are not supported yet.");
|
|
303
303
|
}
|
|
304
|
-
function
|
|
304
|
+
function mt(i) {
|
|
305
305
|
const r = !!i.blank, e = new Set(i.filters);
|
|
306
306
|
return (t) => t === void 0 || t === "" ? r : e.has(typeof t == "string" ? t : `${t}`);
|
|
307
307
|
}
|
|
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];
|
|
311
|
-
}
|
|
312
308
|
function gt(i) {
|
|
309
|
+
const r = i.customFilters.map((e) => pt(e));
|
|
310
|
+
return Ct(r) ? i.and ? _t(r) : Rt(r) : r[0];
|
|
311
|
+
}
|
|
312
|
+
function _t(i) {
|
|
313
313
|
const [r, e] = i;
|
|
314
314
|
return (t) => r(t) && e(t);
|
|
315
315
|
}
|
|
316
|
-
function
|
|
316
|
+
function Rt(i) {
|
|
317
317
|
const [r, e] = i;
|
|
318
318
|
return (t) => r(t) || e(t);
|
|
319
319
|
}
|
|
320
|
-
function
|
|
320
|
+
function Ct(i) {
|
|
321
321
|
return i.length === 2;
|
|
322
322
|
}
|
|
323
|
-
function
|
|
323
|
+
function pt(i) {
|
|
324
324
|
const r = i.val;
|
|
325
|
-
if (i.operator === N.NOT_EQUALS && !
|
|
326
|
-
return (n) =>
|
|
327
|
-
if (
|
|
328
|
-
if (!
|
|
329
|
-
const n =
|
|
325
|
+
if (i.operator === N.NOT_EQUALS && !ie(r))
|
|
326
|
+
return (n) => fe.fn(n, r);
|
|
327
|
+
if (ct(i.operator)) {
|
|
328
|
+
if (!ie(r)) return () => !1;
|
|
329
|
+
const n = ne(i.operator), s = Number(r);
|
|
330
330
|
return (o) => n.fn(o, s);
|
|
331
331
|
}
|
|
332
|
-
const e =
|
|
332
|
+
const e = ne(i.operator);
|
|
333
333
|
return (t) => e.fn(t, r);
|
|
334
334
|
}
|
|
335
|
-
function
|
|
335
|
+
function Ft(i, r, e) {
|
|
336
336
|
const t = i.getCell(r, e);
|
|
337
337
|
if (!t) return null;
|
|
338
338
|
const n = i.getCellRaw(r, e);
|
|
339
|
-
return t && !n ?
|
|
339
|
+
return t && !n ? se(t) : n ? t.t === K.NUMBER && typeof t.v == "string" ? n.v : se(n) : null;
|
|
340
340
|
}
|
|
341
|
-
function
|
|
341
|
+
function se(i) {
|
|
342
342
|
var t, n;
|
|
343
343
|
const r = (n = (t = i.p) == null ? void 0 : t.body) == null ? void 0 : n.dataStream;
|
|
344
344
|
if (r) return r.trimEnd();
|
|
345
345
|
const e = i.v;
|
|
346
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" : "";
|
|
347
347
|
}
|
|
348
|
-
var
|
|
349
|
-
for (var n = t > 1 ? void 0 : t ?
|
|
348
|
+
var wt = Object.defineProperty, St = Object.getOwnPropertyDescriptor, vt = (i, r, e, t) => {
|
|
349
|
+
for (var n = t > 1 ? void 0 : t ? St(r, e) : r, s = i.length - 1, o; s >= 0; s--)
|
|
350
350
|
(o = i[s]) && (n = (t ? o(r, e, n) : o(n)) || n);
|
|
351
|
-
return t && n &&
|
|
351
|
+
return t && n && wt(r, e, n), n;
|
|
352
352
|
}, J = (i, r) => (e, t) => r(e, t, i);
|
|
353
|
-
const
|
|
353
|
+
const Re = "SHEET_FILTER_PLUGIN";
|
|
354
354
|
let M = class extends V {
|
|
355
355
|
constructor(r, e, t) {
|
|
356
356
|
super();
|
|
@@ -418,13 +418,13 @@ let M = class extends V {
|
|
|
418
418
|
}
|
|
419
419
|
_initActiveFilterModel() {
|
|
420
420
|
this.disposeWithMe(
|
|
421
|
-
|
|
421
|
+
Xe(
|
|
422
422
|
// source1: executing filter related mutations
|
|
423
|
-
|
|
423
|
+
Me(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(Ze(([r]) => r.type === E.MUTATION && rt.has(r.id))),
|
|
424
424
|
// source2: activate sheet changes
|
|
425
|
-
this._univerInstanceService.getCurrentTypeOfUnit$(U.UNIVER_SHEET).pipe(
|
|
425
|
+
this._univerInstanceService.getCurrentTypeOfUnit$(U.UNIVER_SHEET).pipe(ke((r) => {
|
|
426
426
|
var e;
|
|
427
|
-
return (e = r == null ? void 0 : r.activeSheet$) != null ? e :
|
|
427
|
+
return (e = r == null ? void 0 : r.activeSheet$) != null ? e : et(null);
|
|
428
428
|
}))
|
|
429
429
|
).subscribe(() => this._updateActiveFilterModel())
|
|
430
430
|
);
|
|
@@ -447,7 +447,7 @@ let M = class extends V {
|
|
|
447
447
|
}
|
|
448
448
|
_initModel() {
|
|
449
449
|
this._resourcesManagerService.registerPluginResource({
|
|
450
|
-
pluginName:
|
|
450
|
+
pluginName: Re,
|
|
451
451
|
businesses: [U.UNIVER_SHEET],
|
|
452
452
|
toJson: (r) => this._serializeAutoFiltersForUnit(r),
|
|
453
453
|
parseJson: (r) => JSON.parse(r),
|
|
@@ -464,41 +464,41 @@ let M = class extends V {
|
|
|
464
464
|
this._filterModels.has(r) || this._filterModels.set(r, /* @__PURE__ */ new Map()), this._filterModels.get(r).set(e, t);
|
|
465
465
|
}
|
|
466
466
|
};
|
|
467
|
-
M =
|
|
468
|
-
J(0,
|
|
467
|
+
M = vt([
|
|
468
|
+
J(0, Ee),
|
|
469
469
|
J(1, x),
|
|
470
470
|
J(2, T)
|
|
471
471
|
], M);
|
|
472
472
|
const R = {
|
|
473
|
-
id:
|
|
473
|
+
id: ce,
|
|
474
474
|
type: E.MUTATION,
|
|
475
475
|
handler: (i, r) => {
|
|
476
476
|
const { subUnitId: e, unitId: t, range: n } = r;
|
|
477
477
|
return i.get(M).ensureFilterModel(t, e).setRange(n), !0;
|
|
478
478
|
}
|
|
479
479
|
}, p = {
|
|
480
|
-
id:
|
|
480
|
+
id: de,
|
|
481
481
|
type: E.MUTATION,
|
|
482
482
|
handler: (i, r) => {
|
|
483
483
|
const { subUnitId: e, unitId: t, criteria: n, col: s, reCalc: o = !0 } = r, a = i.get(M).getFilterModel(t, e);
|
|
484
484
|
return a ? (a.setCriteria(s, n, o), !0) : !1;
|
|
485
485
|
}
|
|
486
486
|
}, O = {
|
|
487
|
-
id:
|
|
487
|
+
id: ue,
|
|
488
488
|
type: E.MUTATION,
|
|
489
489
|
handler: (i, r) => {
|
|
490
490
|
const { unitId: e, subUnitId: t } = r;
|
|
491
491
|
return i.get(M).removeFilterModel(e, t);
|
|
492
492
|
}
|
|
493
493
|
}, H = {
|
|
494
|
-
id:
|
|
494
|
+
id: he,
|
|
495
495
|
type: E.MUTATION,
|
|
496
496
|
handler: (i, r) => {
|
|
497
497
|
const { unitId: e, subUnitId: t } = r, s = i.get(M).getFilterModel(e, t);
|
|
498
498
|
return s ? (s.reCalc(), !0) : !1;
|
|
499
499
|
}
|
|
500
500
|
};
|
|
501
|
-
function
|
|
501
|
+
function Mt(i, r) {
|
|
502
502
|
for (let e = 0; e < i.length; e++) {
|
|
503
503
|
let t = e;
|
|
504
504
|
if (i[e])
|
|
@@ -508,17 +508,17 @@ function vt(i, r) {
|
|
|
508
508
|
return i.filter((e) => e !== null);
|
|
509
509
|
}
|
|
510
510
|
function I(i) {
|
|
511
|
-
return
|
|
511
|
+
return Mt(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);
|
|
512
512
|
}
|
|
513
|
-
var
|
|
514
|
-
for (var n = t > 1 ? void 0 : t ?
|
|
513
|
+
var Et = Object.defineProperty, Ot = Object.getOwnPropertyDescriptor, yt = (i, r, e, t) => {
|
|
514
|
+
for (var n = t > 1 ? void 0 : t ? Ot(r, e) : r, s = i.length - 1, o; s >= 0; s--)
|
|
515
515
|
(o = i[s]) && (n = (t ? o(r, e, n) : o(n)) || n);
|
|
516
|
-
return t && n &&
|
|
516
|
+
return t && n && Et(r, e, n), n;
|
|
517
517
|
}, P = (i, r) => (e, t) => r(e, t, i);
|
|
518
518
|
let W = class extends V {
|
|
519
519
|
constructor(r, e, t, n, s) {
|
|
520
520
|
super();
|
|
521
|
-
w(this, "_disposableCollection", new
|
|
521
|
+
w(this, "_disposableCollection", new Oe());
|
|
522
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();
|
|
523
523
|
}
|
|
524
524
|
_initCommands() {
|
|
@@ -533,7 +533,7 @@ let W = class extends V {
|
|
|
533
533
|
this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
|
|
534
534
|
getMutations: (r) => this._getUpdateFilter(r)
|
|
535
535
|
})), this.disposeWithMe(this._commandService.onCommandExecuted((r) => {
|
|
536
|
-
if (r.id ===
|
|
536
|
+
if (r.id === be.id) {
|
|
537
537
|
const e = r.params, t = e.subUnitId, n = e.unitId;
|
|
538
538
|
if (!t || !n)
|
|
539
539
|
return;
|
|
@@ -559,19 +559,19 @@ let W = class extends V {
|
|
|
559
559
|
if (!t || !n) return;
|
|
560
560
|
const s = (l = this._sheetsFilterService.getFilterModel(r, e)) == null ? void 0 : l.getRange(), o = (a) => {
|
|
561
561
|
switch (a.id) {
|
|
562
|
-
case
|
|
562
|
+
case Je.id: {
|
|
563
563
|
const c = a.params, h = c.unitId || r, d = c.subUnitId || e;
|
|
564
564
|
return this._handleInsertRowCommand(c, h, d);
|
|
565
565
|
}
|
|
566
|
-
case
|
|
566
|
+
case Ge.id: {
|
|
567
567
|
const c = a.params, h = c.unitId || r, d = c.subUnitId || e;
|
|
568
568
|
return this._handleInsertColCommand(c, h, d);
|
|
569
569
|
}
|
|
570
|
-
case
|
|
570
|
+
case Qe.id: {
|
|
571
571
|
const c = a.params;
|
|
572
572
|
return this._handleRemoveColCommand(c, r, e);
|
|
573
573
|
}
|
|
574
|
-
case
|
|
574
|
+
case qe.id: {
|
|
575
575
|
const c = a.params;
|
|
576
576
|
return this._handleRemoveRowCommand(c, r, e);
|
|
577
577
|
}
|
|
@@ -583,7 +583,7 @@ let W = class extends V {
|
|
|
583
583
|
const c = a.params;
|
|
584
584
|
return this._handleMoveRowsCommand(c, r, e);
|
|
585
585
|
}
|
|
586
|
-
case
|
|
586
|
+
case je.id: {
|
|
587
587
|
const c = a.params;
|
|
588
588
|
return this._handleMoveRangeCommand(c, r, e);
|
|
589
589
|
}
|
|
@@ -595,11 +595,11 @@ let W = class extends V {
|
|
|
595
595
|
_getUpdateFilter(r) {
|
|
596
596
|
const { id: e } = r;
|
|
597
597
|
switch (e) {
|
|
598
|
-
case
|
|
598
|
+
case Be.id: {
|
|
599
599
|
const t = r.params;
|
|
600
600
|
return this._handleRemoveSheetCommand(t, t.unitId, t.subUnitId);
|
|
601
601
|
}
|
|
602
|
-
case
|
|
602
|
+
case Le.id: {
|
|
603
603
|
const t = r.params, { targetSubUnitId: n, unitId: s, subUnitId: o } = t;
|
|
604
604
|
return !s || !o || !n ? this._handleNull() : this._handleCopySheetCommand(s, o, n);
|
|
605
605
|
}
|
|
@@ -798,13 +798,13 @@ let W = class extends V {
|
|
|
798
798
|
subUnitId: t,
|
|
799
799
|
col: A,
|
|
800
800
|
criteria: { ...y.serialize(), colId: A }
|
|
801
|
-
},
|
|
801
|
+
}, pe = {
|
|
802
802
|
unitId: e,
|
|
803
803
|
subUnitId: t,
|
|
804
804
|
col: A,
|
|
805
805
|
criteria: n.getFilterColumn(A) ? { ...(X = n.getFilterColumn(A)) == null ? void 0 : X.serialize(), colId: A } : null
|
|
806
806
|
};
|
|
807
|
-
h.push({ id: p.id, params: q }), d.push({ id: p.id, params:
|
|
807
|
+
h.push({ id: p.id, params: q }), d.push({ id: p.id, params: pe });
|
|
808
808
|
}
|
|
809
809
|
if (!((Z = u[v]) != null && Z.filter)) {
|
|
810
810
|
const q = {
|
|
@@ -942,7 +942,7 @@ let W = class extends V {
|
|
|
942
942
|
return { redos: [], undos: [] };
|
|
943
943
|
}
|
|
944
944
|
_initRowFilteredInterceptor() {
|
|
945
|
-
this.disposeWithMe(this._sheetInterceptorService.intercept(
|
|
945
|
+
this.disposeWithMe(this._sheetInterceptorService.intercept(ze.ROW_FILTERED, {
|
|
946
946
|
// sheet-interceptor.service.ts
|
|
947
947
|
handler: (r, e) => {
|
|
948
948
|
var t, n;
|
|
@@ -1011,7 +1011,7 @@ let W = class extends V {
|
|
|
1011
1011
|
if (!s) return;
|
|
1012
1012
|
const o = Array.from(s.filteredOutRows).sort((d, u) => d - u), l = [];
|
|
1013
1013
|
let a = !1;
|
|
1014
|
-
if (r.id ===
|
|
1014
|
+
if (r.id === He.id) {
|
|
1015
1015
|
const { startRow: d, endRow: u } = r.params.range, m = o.filter((g) => g >= d && g <= u);
|
|
1016
1016
|
o.forEach((g) => {
|
|
1017
1017
|
if (g < d)
|
|
@@ -1023,13 +1023,13 @@ let W = class extends V {
|
|
|
1023
1023
|
l.push(g - (u - d + 1 - m.length));
|
|
1024
1024
|
});
|
|
1025
1025
|
}
|
|
1026
|
-
if (r.id ===
|
|
1026
|
+
if (r.id === De.id) {
|
|
1027
1027
|
const { startRow: d, endRow: u } = r.params.range;
|
|
1028
1028
|
o.forEach((m) => {
|
|
1029
1029
|
m >= d ? (a = !0, l.push(m + (u - d + 1))) : l.push(m);
|
|
1030
1030
|
});
|
|
1031
1031
|
}
|
|
1032
|
-
if (a && (s.filteredOutRows = new Set(l)), r.id ===
|
|
1032
|
+
if (a && (s.filteredOutRows = new Set(l)), r.id === We.id && !(e != null && e.onlyLocal)) {
|
|
1033
1033
|
const d = this._getExtendRegion(t, n);
|
|
1034
1034
|
if (d) {
|
|
1035
1035
|
const u = r.params.cellValue;
|
|
@@ -1039,7 +1039,7 @@ let W = class extends V {
|
|
|
1039
1039
|
if (g && this._cellHasValue(g)) {
|
|
1040
1040
|
const C = (h = this._univerInstanceService.getUnit(t)) == null ? void 0 : h.getSheetBySheetId(n);
|
|
1041
1041
|
if (C) {
|
|
1042
|
-
const S =
|
|
1042
|
+
const S = ae(d, { down: !0 }, C), F = this._sheetsFilterService.getFilterModel(t, n), _ = F.getRange();
|
|
1043
1043
|
F.setRange({
|
|
1044
1044
|
..._,
|
|
1045
1045
|
endRow: S.endRow
|
|
@@ -1080,7 +1080,7 @@ let W = class extends V {
|
|
|
1080
1080
|
const { subUnitId: n, unitId: s } = t, o = this._sheetsFilterService.getFilterModel(s, n);
|
|
1081
1081
|
if (!o) return;
|
|
1082
1082
|
const l = o.getRange();
|
|
1083
|
-
if (r.id ===
|
|
1083
|
+
if (r.id === Ve.id && e.fromRange.startRow <= l.startRow && e.fromRange.endRow < l.endRow && e.fromRange.endRow >= l.startRow)
|
|
1084
1084
|
throw this._sheetsFilterService.setFilterErrorMsg("sheets-filter.msg.filter-header-forbidden"), new Error("[SheetsFilterController]: Cannot move header row of filter");
|
|
1085
1085
|
}));
|
|
1086
1086
|
}
|
|
@@ -1089,23 +1089,27 @@ let W = class extends V {
|
|
|
1089
1089
|
return !(e.length === 0 || e.every((t) => t == null));
|
|
1090
1090
|
}
|
|
1091
1091
|
};
|
|
1092
|
-
W =
|
|
1092
|
+
W = yt([
|
|
1093
1093
|
P(0, T),
|
|
1094
|
-
P(1, z(
|
|
1094
|
+
P(1, z(Pe)),
|
|
1095
1095
|
P(2, z(M)),
|
|
1096
1096
|
P(3, x),
|
|
1097
|
-
P(4, z(
|
|
1097
|
+
P(4, z(Ue))
|
|
1098
1098
|
], W);
|
|
1099
|
-
var
|
|
1100
|
-
for (var n = t > 1 ? void 0 : t ?
|
|
1099
|
+
var At = Object.defineProperty, Tt = Object.getOwnPropertyDescriptor, Nt = (i, r, e, t) => {
|
|
1100
|
+
for (var n = t > 1 ? void 0 : t ? Tt(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
|
-
},
|
|
1104
|
-
let
|
|
1105
|
-
constructor(i =
|
|
1102
|
+
return t && n && At(r, e, n), n;
|
|
1103
|
+
}, oe = (i, r) => (e, t) => r(e, t, i), B;
|
|
1104
|
+
let le = (B = class extends ye {
|
|
1105
|
+
constructor(i = re, r, e) {
|
|
1106
1106
|
super(), this._config = i, this._injector = r, this._configService = e;
|
|
1107
|
-
const { ...t } =
|
|
1108
|
-
|
|
1107
|
+
const { ...t } = Ae(
|
|
1108
|
+
{},
|
|
1109
|
+
re,
|
|
1110
|
+
this._config
|
|
1111
|
+
);
|
|
1112
|
+
this._configService.setConfig(tt, t);
|
|
1109
1113
|
}
|
|
1110
1114
|
onStarting() {
|
|
1111
1115
|
[
|
|
@@ -1116,19 +1120,19 @@ let oe = (B = class extends Oe {
|
|
|
1116
1120
|
onReady() {
|
|
1117
1121
|
this._injector.get(W);
|
|
1118
1122
|
}
|
|
1119
|
-
}, w(B, "type", U.UNIVER_SHEET), w(B, "pluginName",
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
],
|
|
1124
|
-
const
|
|
1123
|
+
}, w(B, "type", U.UNIVER_SHEET), w(B, "pluginName", Re), B);
|
|
1124
|
+
le = Nt([
|
|
1125
|
+
oe(1, z(Te)),
|
|
1126
|
+
oe(2, Ne)
|
|
1127
|
+
], le);
|
|
1128
|
+
const xt = {
|
|
1125
1129
|
id: "sheet.command.set-filter-range",
|
|
1126
1130
|
type: E.COMMAND,
|
|
1127
1131
|
handler: (i, r) => {
|
|
1128
1132
|
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
1133
|
if (!L(s, r) || e.getFilterModel(o, l)) return !1;
|
|
1130
1134
|
if (a.endRow === a.startRow) {
|
|
1131
|
-
const m = i.get(
|
|
1135
|
+
const m = i.get(xe), g = i.get(Ie);
|
|
1132
1136
|
return m.emit(g.t("sheets-filter.command.not-valid-filter-range")), !1;
|
|
1133
1137
|
}
|
|
1134
1138
|
const d = { id: R.id, params: { unitId: o, subUnitId: l, range: a } }, u = t.syncExecuteCommand(d.id, d.params);
|
|
@@ -1138,7 +1142,7 @@ const Nt = {
|
|
|
1138
1142
|
redoMutations: [d]
|
|
1139
1143
|
}), u;
|
|
1140
1144
|
}
|
|
1141
|
-
},
|
|
1145
|
+
}, It = {
|
|
1142
1146
|
id: "sheet.command.remove-sheet-filter",
|
|
1143
1147
|
type: E.COMMAND,
|
|
1144
1148
|
handler: (i, r) => {
|
|
@@ -1146,14 +1150,14 @@ const Nt = {
|
|
|
1146
1150
|
if (!o) return !1;
|
|
1147
1151
|
const { unitId: l, subUnitId: a } = o, c = t.getFilterModel(l, a);
|
|
1148
1152
|
if (!c) return !1;
|
|
1149
|
-
const h = c == null ? void 0 : c.serialize(), d =
|
|
1153
|
+
const h = c == null ? void 0 : c.serialize(), d = $t(l, a, h), u = n.syncExecuteCommand(O.id, { unitId: l, subUnitId: a });
|
|
1150
1154
|
return u && s.pushUndoRedo({
|
|
1151
1155
|
unitID: l,
|
|
1152
1156
|
undoMutations: d,
|
|
1153
1157
|
redoMutations: [{ id: O.id, params: { unitId: l, subUnitId: a } }]
|
|
1154
1158
|
}), u;
|
|
1155
1159
|
}
|
|
1156
|
-
},
|
|
1160
|
+
}, Ht = {
|
|
1157
1161
|
id: "sheet.command.smart-toggle-filter",
|
|
1158
1162
|
type: E.COMMAND,
|
|
1159
1163
|
handler: async (i) => {
|
|
@@ -1161,17 +1165,17 @@ const Nt = {
|
|
|
1161
1165
|
if (!s || !n) return !1;
|
|
1162
1166
|
const o = n.getUnitId(), l = s.getSheetId();
|
|
1163
1167
|
if (e.getFilterModel(o, l))
|
|
1164
|
-
return t.executeCommand(
|
|
1165
|
-
const h = i.get(
|
|
1168
|
+
return t.executeCommand(It.id, { unitId: o, subUnitId: l });
|
|
1169
|
+
const h = i.get(Ye).getCurrentLastSelection();
|
|
1166
1170
|
if (!h) return !1;
|
|
1167
|
-
const d = h.range, u =
|
|
1168
|
-
return t.executeCommand(
|
|
1171
|
+
const d = h.range, u = Ke(h) ? ae(d, { left: !0, right: !0, up: !0, down: !0 }, s) : d;
|
|
1172
|
+
return t.executeCommand(xt.id, {
|
|
1169
1173
|
unitId: o,
|
|
1170
1174
|
subUnitId: l,
|
|
1171
1175
|
range: u
|
|
1172
1176
|
});
|
|
1173
1177
|
}
|
|
1174
|
-
},
|
|
1178
|
+
}, Dt = {
|
|
1175
1179
|
id: "sheet.command.set-filter-criteria",
|
|
1176
1180
|
type: E.COMMAND,
|
|
1177
1181
|
handler: async (i, r) => {
|
|
@@ -1179,7 +1183,7 @@ const Nt = {
|
|
|
1179
1183
|
if (!c) return !1;
|
|
1180
1184
|
const h = c.getRange();
|
|
1181
1185
|
if (!h || l < h.startColumn || l > h.endColumn) return !1;
|
|
1182
|
-
const d = c.getFilterColumn(l), u =
|
|
1186
|
+
const d = c.getFilterColumn(l), u = Ut(s, o, l, d), m = {
|
|
1183
1187
|
id: p.id,
|
|
1184
1188
|
params: {
|
|
1185
1189
|
unitId: s,
|
|
@@ -1194,7 +1198,7 @@ const Nt = {
|
|
|
1194
1198
|
redoMutations: [m]
|
|
1195
1199
|
}), g;
|
|
1196
1200
|
}
|
|
1197
|
-
},
|
|
1201
|
+
}, Wt = {
|
|
1198
1202
|
id: "sheet.command.clear-filter-criteria",
|
|
1199
1203
|
type: E.COMMAND,
|
|
1200
1204
|
handler: (i, r) => {
|
|
@@ -1202,14 +1206,14 @@ const Nt = {
|
|
|
1202
1206
|
if (!o) return !1;
|
|
1203
1207
|
const { unitId: l, subUnitId: a } = o, c = e.getFilterModel(o.unitId, o.subUnitId);
|
|
1204
1208
|
if (!c) return !1;
|
|
1205
|
-
const h = c.serialize(), d =
|
|
1206
|
-
return
|
|
1209
|
+
const h = c.serialize(), d = Ce(l, a, h), u = Pt(l, a, h);
|
|
1210
|
+
return $e(u, n).result ? (t.pushUndoRedo({
|
|
1207
1211
|
unitID: l,
|
|
1208
1212
|
undoMutations: d,
|
|
1209
1213
|
redoMutations: u
|
|
1210
1214
|
}), !0) : !1;
|
|
1211
1215
|
}
|
|
1212
|
-
},
|
|
1216
|
+
}, Vt = {
|
|
1213
1217
|
id: "sheet.command.re-calc-filter",
|
|
1214
1218
|
type: E.COMMAND,
|
|
1215
1219
|
handler: (i, r) => {
|
|
@@ -1219,7 +1223,7 @@ const Nt = {
|
|
|
1219
1223
|
return e.getFilterModel(s.unitId, s.subUnitId) ? t.executeCommand(H.id, { unitId: o, subUnitId: l }) : !1;
|
|
1220
1224
|
}
|
|
1221
1225
|
};
|
|
1222
|
-
function
|
|
1226
|
+
function $t(i, r, e) {
|
|
1223
1227
|
const t = [], n = {
|
|
1224
1228
|
id: R.id,
|
|
1225
1229
|
params: {
|
|
@@ -1228,9 +1232,9 @@ function It(i, r, e) {
|
|
|
1228
1232
|
range: e.ref
|
|
1229
1233
|
}
|
|
1230
1234
|
};
|
|
1231
|
-
return t.push(n),
|
|
1235
|
+
return t.push(n), Ce(i, r, e).forEach((o) => t.push(o)), t;
|
|
1232
1236
|
}
|
|
1233
|
-
function
|
|
1237
|
+
function Ce(i, r, e) {
|
|
1234
1238
|
var n;
|
|
1235
1239
|
const t = [];
|
|
1236
1240
|
return (n = e.filterColumns) == null || n.forEach((s) => {
|
|
@@ -1246,7 +1250,7 @@ function Re(i, r, e) {
|
|
|
1246
1250
|
t.push(o);
|
|
1247
1251
|
}), t;
|
|
1248
1252
|
}
|
|
1249
|
-
function
|
|
1253
|
+
function Pt(i, r, e) {
|
|
1250
1254
|
var n;
|
|
1251
1255
|
const t = [];
|
|
1252
1256
|
return (n = e.filterColumns) == null || n.forEach((s) => {
|
|
@@ -1262,7 +1266,7 @@ function $t(i, r, e) {
|
|
|
1262
1266
|
t.push(o);
|
|
1263
1267
|
}), t;
|
|
1264
1268
|
}
|
|
1265
|
-
function
|
|
1269
|
+
function Ut(i, r, e, t) {
|
|
1266
1270
|
if (!t)
|
|
1267
1271
|
return {
|
|
1268
1272
|
id: p.id,
|
|
@@ -1285,28 +1289,28 @@ function Pt(i, r, e, t) {
|
|
|
1285
1289
|
};
|
|
1286
1290
|
}
|
|
1287
1291
|
export {
|
|
1288
|
-
|
|
1292
|
+
Wt as ClearSheetsFilterCriteriaCommand,
|
|
1289
1293
|
N as CustomFilterOperator,
|
|
1290
|
-
|
|
1291
|
-
|
|
1294
|
+
rt as FILTER_MUTATIONS,
|
|
1295
|
+
ht as FilterColumn,
|
|
1292
1296
|
D as FilterModel,
|
|
1293
|
-
|
|
1297
|
+
Vt as ReCalcSheetsFilterCommand,
|
|
1294
1298
|
H as ReCalcSheetsFilterMutation,
|
|
1295
|
-
|
|
1299
|
+
It as RemoveSheetFilterCommand,
|
|
1296
1300
|
O as RemoveSheetsFilterMutation,
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1301
|
+
Re as SHEET_FILTER_SNAPSHOT_ID,
|
|
1302
|
+
xt as SetSheetFilterRangeCommand,
|
|
1303
|
+
Dt as SetSheetsFilterCriteriaCommand,
|
|
1300
1304
|
p as SetSheetsFilterCriteriaMutation,
|
|
1301
1305
|
R as SetSheetsFilterRangeMutation,
|
|
1302
1306
|
M as SheetsFilterService,
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1307
|
+
Ht as SmartToggleSheetsFilterCommand,
|
|
1308
|
+
le as UniverSheetsFilterPlugin,
|
|
1309
|
+
lt as equals,
|
|
1310
|
+
ne as getCustomFilterFn,
|
|
1311
|
+
nt as greaterThan,
|
|
1312
|
+
it as greaterThanOrEqualTo,
|
|
1313
|
+
st as lessThan,
|
|
1314
|
+
ot as lessThanOrEqualTo,
|
|
1315
|
+
fe as notEquals
|
|
1312
1316
|
};
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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"})});
|
|
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 fe="sheets-filter.config",q={},Q="sheet.mutation.set-filter-range",G="sheet.mutation.set-filter-criteria",J="sheet.mutation.remove-filter",Y="sheet.mutation.re-calc-filter",K=new Set([Q,G,J,Y]);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 X={operator:I.GREATER_THAN,fn:(i,n)=>U(i)?i>n:!1},Z={operator:I.GREATER_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i>=n:!1},k={operator:I.LESS_THAN,fn:(i,n)=>U(i)?i<n:!1},ee={operator:I.LESS_THAN_OR_EQUAL,fn:(i,n)=>U(i)?i<=n:!1},te={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=ie(i);return e&&_e(n)?!se(n).test(e):e!==n}return U(i)?i!==n:!0}},re=new Map([]);[X,Z,k,ee,te,H].forEach(i=>{re.set(i.operator,i)});function ge(i){return!!i}const Ce={fn:(i,n)=>{const e=ie(i);return e===null?n==="":se(n).test(e)}};function z(i){return i?re.get(i):Ce}function U(i){return typeof i=="number"}function ne(i){return!!(typeof i=="number"||typeof i=="string"&&u.isNumeric(i))}function ie(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 se(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 oe(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 oe 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&&!ne(n))return r=>H.fn(r,n);if(ge(i.operator)){if(!ne(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?le(t):r?t.t===u.CellValueType.NUMBER&&typeof t.v=="string"?r.v:le(r):null}function le(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&&K.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:G,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:J,type:u.CommandType.MUTATION,handler:(i,n)=>{const{unitId:e,subUnitId:t}=n;return i.get(g.SheetsFilterService).removeFilterModel(e,t)}},b={id:Y,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 he,me;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)?{...(he=r.getFilterColumn(N))==null?void 0:he.serialize(),colId:N}:null};m.push({id:p.id,params:W}),c.push({id:p.id,params:Ve})}if(!((me=h[y])!=null&&me.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},ae=(i,n)=>(e,t)=>n(e,t,i);g.UniverSheetsFilterPlugin=(x=class extends u.Plugin{constructor(n=q,e,t){super(),this._config=n,this._injector=e,this._configService=t;const{...r}=u.merge({},q,this._config);this._configService.setConfig(fe,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([ae(1,u.Inject(u.Injector)),ae(2,u.IConfigService)],g.UniverSheetsFilterPlugin);const de={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}},ue={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(ue.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(de.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=ce(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),ce(i,n,e).forEach(o=>t.push(o)),t}function ce(i,n,e){var r;const t=[];return(r=e.filterColumns)==null||r.forEach(s=>{const o={id: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=K,g.FilterColumn=oe,g.FilterModel=P,g.ReCalcSheetsFilterCommand=He,g.ReCalcSheetsFilterMutation=b,g.RemoveSheetFilterCommand=ue,g.RemoveSheetsFilterMutation=O,g.SHEET_FILTER_SNAPSHOT_ID=V,g.SetSheetFilterRangeCommand=de,g.SetSheetsFilterCriteriaCommand=Be,g.SetSheetsFilterCriteriaMutation=p,g.SetSheetsFilterRangeMutation=F,g.SmartToggleSheetsFilterCommand=Le,g.equals=te,g.getCustomFilterFn=z,g.greaterThan=X,g.greaterThanOrEqualTo=Z,g.lessThan=k,g.lessThanOrEqualTo=ee,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.2-nightly.202412281605",
|
|
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.2-nightly.202412281605",
|
|
55
|
+
"@univerjs/sheets": "0.5.2-nightly.202412281605"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"rxjs": "^7.8.1",
|
|
59
59
|
"typescript": "^5.7.2",
|
|
60
|
-
"vite": "^6.0.
|
|
61
|
-
"vitest": "^2.1.
|
|
62
|
-
"@univerjs-infra/shared": "0.5.
|
|
60
|
+
"vite": "^6.0.3",
|
|
61
|
+
"vitest": "^2.1.8",
|
|
62
|
+
"@univerjs-infra/shared": "0.5.2"
|
|
63
63
|
},
|
|
64
64
|
"space": {
|
|
65
65
|
".": {
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|