@univerjs/sheets-filter 0.5.2 → 0.5.3-experimental.20250106-4af1f4e
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/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +125 -38
- package/lib/es/index.js +1 -1
- package/lib/types/facade/f-enum.d.ts +13 -0
- package/lib/types/facade/f-event.d.ts +104 -0
- package/lib/types/facade/f-filter.d.ts +7 -7
- package/lib/types/facade/f-range.d.ts +17 -5
- package/lib/types/facade/f-worksheet.d.ts +13 -0
- package/lib/types/facade/index.d.ts +4 -0
- package/lib/types/models/types.d.ts +9 -3
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +5 -23
- package/LICENSE +0 -176
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),n=require("@univerjs/sheets-filter"),a=require("@univerjs/sheets/facade");var d=Object.defineProperty,F=Object.getOwnPropertyDescriptor,m=(s,e,t,r)=>{for(var i=r>1?void 0:r?F(e,t):e,l=s.length-1,h;l>=0;l--)(h=s[l])&&(i=(r?h(e,t,i):h(i))||i);return r&&i&&d(e,t,i),i},c=(s,e)=>(t,r)=>e(t,r,s);exports.FFilter=class{constructor(e,t,r,i,l){this._workbook=e,this._worksheet=t,this._filterModel=r,this._injector=i,this._commandSrv=l}getFilteredOutRows(){return Array.from(this._filterModel.filteredOutRows).sort()}getColumnFilterCriteria(e){var t;return(t=this._filterModel.getFilterColumn(e))==null?void 0:t.getColumnData()}removeColumnFilterCriteria(e){return this._commandSrv.syncExecuteCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),col:e,criteria:null}),this}setColumnFilterCriteria(e,t){return this._commandSrv.syncExecuteCommand(n.SetSheetsFilterCriteriaCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),col:e,criteria:t}),this}getRange(){const e=this._filterModel.getRange();return this._injector.createInstance(a.FRange,this._workbook,this._worksheet,e)}removeFilterCriteria(){return this._commandSrv.syncExecuteCommand(n.ClearSheetsFilterCriteriaCommand.id),this}remove(){return this._commandSrv.syncExecuteCommand(n.RemoveSheetFilterCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()})}};exports.FFilter=m([c(3,o.Inject(o.Injector)),c(4,o.ICommandService)],exports.FFilter);class g extends a.FRange{createFilter(){return this._getFilterModel()||!this._commandService.syncExecuteCommand(n.SetSheetFilterRangeCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range})?null:this.getFilter()}getFilter(){const e=this._getFilterModel();return e?this._injector.createInstance(exports.FFilter,this._workbook,this._worksheet,e):null}_getFilterModel(){return this._injector.get(n.SheetsFilterService).getFilterModel(this._workbook.getUnitId(),this._worksheet.getSheetId())}}a.FRange.extend(g);class u extends a.FWorksheet{getFilter(){const e=this._getFilterModel();return e?this._injector.createInstance(exports.FFilter,this._workbook,this._worksheet,e):null}_getFilterModel(){return this._injector.get(n.SheetsFilterService).getFilterModel(this._workbook.getUnitId(),this._worksheet.getSheetId())}}a.FWorksheet.extend(u);class S extends o.FEnum{get CustomFilterOperation(){return n.CustomFilterOperator}}o.FEnum.extend(S);class _ extends o.FEventName{get SheetBeforeRangeFilter(){return"SheetBeforeRangeFilter"}get SheetRangeFiltered(){return"SheetRangeFiltered"}get SheetRangeFilterCleared(){return"SheetRangeFilterCleared"}get SheetBeforeRangeFilterClear(){return"SheetBeforeRangeFilterClear"}}o.FEventName.extend(_);o.FEventName.extend(a.FSheetEventName);class C extends o.FUniver{_initialize(e){const t=e.get(o.ICommandService);this.disposeWithMe(t.beforeCommandExecuted(r=>{switch(r.id){case n.SetSheetsFilterCriteriaCommand.id:this._beforeRangeFilter(r);break;case n.ClearSheetsFilterCriteriaCommand.id:this._beforeRangeFilterClear();break}})),this.disposeWithMe(t.onCommandExecuted(r=>{switch(r.id){case n.SetSheetsFilterCriteriaCommand.id:this._onRangeFiltered(r);break;case n.ClearSheetsFilterCriteriaCommand.id:this._onRangeFilterCleared();break}}))}_beforeRangeFilter(e){const t=e.params,r=this.getUniverSheet(t.unitId),i={workbook:r,worksheet:r.getSheetBySheetId(t.subUnitId),col:t.col,criteria:t.criteria};if(this.fireEvent(this.Event.SheetBeforeRangeFilter,i),i.cancel)throw new Error("SetSheetsFilterCriteriaCommand canceled.")}_onRangeFiltered(e){const t=e.params,r=this.getUniverSheet(t.unitId),i={workbook:r,worksheet:r.getSheetBySheetId(t.subUnitId),col:t.col,criteria:t.criteria};if(this.fireEvent(this.Event.SheetRangeFiltered,i),i.cancel)throw new Error("SetSheetsFilterCriteriaCommand canceled.")}_beforeRangeFilterClear(){const e=this.getActiveWorkbook();if(!e)return;const t={workbook:e,worksheet:e.getActiveSheet()};if(this.fireEvent(this.Event.SheetBeforeRangeFilterClear,t),t.cancel)throw new Error("SetSheetsFilterCriteriaCommand canceled.")}_onRangeFilterCleared(){const e=this.getActiveWorkbook();if(!e)return;const t={workbook:e,worksheet:e.getActiveSheet()};if(this.fireEvent(this.Event.SheetRangeFilterCleared,t),t.cancel)throw new Error("SetSheetsFilterCriteriaCommand canceled.")}}o.FUniver.extend(C);
|
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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:(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/facade.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Inject as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
var
|
|
5
|
-
for (var
|
|
6
|
-
(
|
|
7
|
-
return
|
|
8
|
-
},
|
|
1
|
+
import { Inject as S, Injector as C, ICommandService as g, FEnum as F, FEventName as c, FUniver as u } from "@univerjs/core";
|
|
2
|
+
import { SetSheetsFilterCriteriaCommand as o, ClearSheetsFilterCriteriaCommand as l, RemoveSheetFilterCommand as v, SetSheetFilterRangeCommand as f, SheetsFilterService as _, CustomFilterOperator as w } from "@univerjs/sheets-filter";
|
|
3
|
+
import { FRange as d, FWorksheet as k, FSheetEventName as b } from "@univerjs/sheets/facade";
|
|
4
|
+
var I = Object.defineProperty, R = Object.getOwnPropertyDescriptor, E = (i, e, t, r) => {
|
|
5
|
+
for (var n = r > 1 ? void 0 : r ? R(e, t) : e, a = i.length - 1, h; a >= 0; a--)
|
|
6
|
+
(h = i[a]) && (n = (r ? h(e, t, n) : h(n)) || n);
|
|
7
|
+
return r && n && I(e, t, n), n;
|
|
8
|
+
}, m = (i, e) => (t, r) => e(t, r, i);
|
|
9
9
|
let s = class {
|
|
10
|
-
constructor(
|
|
11
|
-
this._workbook =
|
|
10
|
+
constructor(i, e, t, r, n) {
|
|
11
|
+
this._workbook = i, this._worksheet = e, this._filterModel = t, this._injector = r, this._commandSrv = n;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Get the filtered out rows by this filter.
|
|
@@ -22,70 +22,70 @@ let s = class {
|
|
|
22
22
|
* @param {number} col The column number.
|
|
23
23
|
* @returns {Nullable<IFilterColumn>} The filter criteria of the column.
|
|
24
24
|
*/
|
|
25
|
-
getColumnFilterCriteria(
|
|
25
|
+
getColumnFilterCriteria(i) {
|
|
26
26
|
var e;
|
|
27
|
-
return (e = this._filterModel.getFilterColumn(
|
|
27
|
+
return (e = this._filterModel.getFilterColumn(i)) == null ? void 0 : e.getColumnData();
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Clear the filter criteria of a column.
|
|
31
31
|
* @param {number} col The column number.
|
|
32
|
-
* @returns {
|
|
32
|
+
* @returns {FFilter} The interface class to handle the filter.
|
|
33
33
|
*/
|
|
34
|
-
removeColumnFilterCriteria(
|
|
35
|
-
return this._commandSrv.
|
|
34
|
+
removeColumnFilterCriteria(i) {
|
|
35
|
+
return this._commandSrv.syncExecuteCommand(o.id, {
|
|
36
36
|
unitId: this._workbook.getUnitId(),
|
|
37
37
|
subUnitId: this._worksheet.getSheetId(),
|
|
38
|
-
col:
|
|
38
|
+
col: i,
|
|
39
39
|
criteria: null
|
|
40
|
-
});
|
|
40
|
+
}), this;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Set the filter criteria of a column.
|
|
44
44
|
* @param {number} col The column number.
|
|
45
45
|
* @param {ISetSheetsFilterCriteriaCommandParams['criteria']} criteria The new filter criteria.
|
|
46
|
-
* @returns {
|
|
46
|
+
* @returns {FFilter} The interface class to handle the filter.
|
|
47
47
|
*/
|
|
48
|
-
setColumnFilterCriteria(
|
|
49
|
-
return this._commandSrv.
|
|
48
|
+
setColumnFilterCriteria(i, e) {
|
|
49
|
+
return this._commandSrv.syncExecuteCommand(o.id, {
|
|
50
50
|
unitId: this._workbook.getUnitId(),
|
|
51
51
|
subUnitId: this._worksheet.getSheetId(),
|
|
52
|
-
col:
|
|
52
|
+
col: i,
|
|
53
53
|
criteria: e
|
|
54
|
-
});
|
|
54
|
+
}), this;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Get the range of the filter.
|
|
58
58
|
* @returns {FRange} The range of the filter.
|
|
59
59
|
*/
|
|
60
60
|
getRange() {
|
|
61
|
-
const
|
|
62
|
-
return this._injector.createInstance(
|
|
61
|
+
const i = this._filterModel.getRange();
|
|
62
|
+
return this._injector.createInstance(d, this._workbook, this._worksheet, i);
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* Remove the filter criteria of all columns.
|
|
66
66
|
* @returns {Promise<boolean>} If the filter criteria is removed.
|
|
67
67
|
*/
|
|
68
68
|
removeFilterCriteria() {
|
|
69
|
-
return this._commandSrv.
|
|
69
|
+
return this._commandSrv.syncExecuteCommand(l.id), this;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Remove the filter from the worksheet.
|
|
73
|
-
* @returns {
|
|
73
|
+
* @returns {boolean} If the filter is removed.
|
|
74
74
|
*/
|
|
75
75
|
remove() {
|
|
76
|
-
return this._commandSrv.
|
|
76
|
+
return this._commandSrv.syncExecuteCommand(v.id, {
|
|
77
77
|
unitId: this._workbook.getUnitId(),
|
|
78
78
|
subUnitId: this._worksheet.getSheetId()
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
|
-
s =
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
s = E([
|
|
83
|
+
m(3, S(C)),
|
|
84
|
+
m(4, g)
|
|
85
85
|
], s);
|
|
86
|
-
class
|
|
87
|
-
|
|
88
|
-
return this._getFilterModel() || !
|
|
86
|
+
class x extends d {
|
|
87
|
+
createFilter() {
|
|
88
|
+
return this._getFilterModel() || !this._commandService.syncExecuteCommand(f.id, {
|
|
89
89
|
unitId: this._workbook.getUnitId(),
|
|
90
90
|
subUnitId: this._worksheet.getSheetId(),
|
|
91
91
|
range: this._range
|
|
@@ -102,26 +102,113 @@ class f extends h {
|
|
|
102
102
|
return e ? this._injector.createInstance(s, this._workbook, this._worksheet, e) : null;
|
|
103
103
|
}
|
|
104
104
|
_getFilterModel() {
|
|
105
|
-
return this._injector.get(
|
|
105
|
+
return this._injector.get(_).getFilterModel(
|
|
106
106
|
this._workbook.getUnitId(),
|
|
107
107
|
this._worksheet.getSheetId()
|
|
108
108
|
);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
|
|
112
|
-
class
|
|
111
|
+
d.extend(x);
|
|
112
|
+
class p extends k {
|
|
113
113
|
getFilter() {
|
|
114
114
|
const e = this._getFilterModel();
|
|
115
115
|
return e ? this._injector.createInstance(s, this._workbook, this._worksheet, e) : null;
|
|
116
116
|
}
|
|
117
117
|
_getFilterModel() {
|
|
118
|
-
return this._injector.get(
|
|
118
|
+
return this._injector.get(_).getFilterModel(
|
|
119
119
|
this._workbook.getUnitId(),
|
|
120
120
|
this._worksheet.getSheetId()
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
|
|
124
|
+
k.extend(p);
|
|
125
|
+
class M extends F {
|
|
126
|
+
get CustomFilterOperation() {
|
|
127
|
+
return w;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
F.extend(M);
|
|
131
|
+
class U extends c {
|
|
132
|
+
get SheetBeforeRangeFilter() {
|
|
133
|
+
return "SheetBeforeRangeFilter";
|
|
134
|
+
}
|
|
135
|
+
get SheetRangeFiltered() {
|
|
136
|
+
return "SheetRangeFiltered";
|
|
137
|
+
}
|
|
138
|
+
get SheetRangeFilterCleared() {
|
|
139
|
+
return "SheetRangeFilterCleared";
|
|
140
|
+
}
|
|
141
|
+
get SheetBeforeRangeFilterClear() {
|
|
142
|
+
return "SheetBeforeRangeFilterClear";
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
c.extend(U);
|
|
146
|
+
c.extend(b);
|
|
147
|
+
class j extends u {
|
|
148
|
+
_initialize(e) {
|
|
149
|
+
const t = e.get(g);
|
|
150
|
+
this.disposeWithMe(t.beforeCommandExecuted((r) => {
|
|
151
|
+
switch (r.id) {
|
|
152
|
+
case o.id:
|
|
153
|
+
this._beforeRangeFilter(r);
|
|
154
|
+
break;
|
|
155
|
+
case l.id:
|
|
156
|
+
this._beforeRangeFilterClear();
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
})), this.disposeWithMe(t.onCommandExecuted((r) => {
|
|
160
|
+
switch (r.id) {
|
|
161
|
+
case o.id:
|
|
162
|
+
this._onRangeFiltered(r);
|
|
163
|
+
break;
|
|
164
|
+
case l.id:
|
|
165
|
+
this._onRangeFilterCleared();
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
_beforeRangeFilter(e) {
|
|
171
|
+
const t = e.params, r = this.getUniverSheet(t.unitId), n = {
|
|
172
|
+
workbook: r,
|
|
173
|
+
worksheet: r.getSheetBySheetId(t.subUnitId),
|
|
174
|
+
col: t.col,
|
|
175
|
+
criteria: t.criteria
|
|
176
|
+
};
|
|
177
|
+
if (this.fireEvent(this.Event.SheetBeforeRangeFilter, n), n.cancel)
|
|
178
|
+
throw new Error("SetSheetsFilterCriteriaCommand canceled.");
|
|
179
|
+
}
|
|
180
|
+
_onRangeFiltered(e) {
|
|
181
|
+
const t = e.params, r = this.getUniverSheet(t.unitId), n = {
|
|
182
|
+
workbook: r,
|
|
183
|
+
worksheet: r.getSheetBySheetId(t.subUnitId),
|
|
184
|
+
col: t.col,
|
|
185
|
+
criteria: t.criteria
|
|
186
|
+
};
|
|
187
|
+
if (this.fireEvent(this.Event.SheetRangeFiltered, n), n.cancel)
|
|
188
|
+
throw new Error("SetSheetsFilterCriteriaCommand canceled.");
|
|
189
|
+
}
|
|
190
|
+
_beforeRangeFilterClear() {
|
|
191
|
+
const e = this.getActiveWorkbook();
|
|
192
|
+
if (!e) return;
|
|
193
|
+
const t = {
|
|
194
|
+
workbook: e,
|
|
195
|
+
worksheet: e.getActiveSheet()
|
|
196
|
+
};
|
|
197
|
+
if (this.fireEvent(this.Event.SheetBeforeRangeFilterClear, t), t.cancel)
|
|
198
|
+
throw new Error("SetSheetsFilterCriteriaCommand canceled.");
|
|
199
|
+
}
|
|
200
|
+
_onRangeFilterCleared() {
|
|
201
|
+
const e = this.getActiveWorkbook();
|
|
202
|
+
if (!e) return;
|
|
203
|
+
const t = {
|
|
204
|
+
workbook: e,
|
|
205
|
+
worksheet: e.getActiveSheet()
|
|
206
|
+
};
|
|
207
|
+
if (this.fireEvent(this.Event.SheetRangeFilterCleared, t), t.cancel)
|
|
208
|
+
throw new Error("SetSheetsFilterCriteriaCommand canceled.");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
u.extend(j);
|
|
125
212
|
export {
|
|
126
213
|
s as FFilter
|
|
127
214
|
};
|
package/lib/es/index.js
CHANGED
|
@@ -1178,7 +1178,7 @@ const xt = {
|
|
|
1178
1178
|
}, Dt = {
|
|
1179
1179
|
id: "sheet.command.set-filter-criteria",
|
|
1180
1180
|
type: E.COMMAND,
|
|
1181
|
-
handler:
|
|
1181
|
+
handler: (i, r) => {
|
|
1182
1182
|
const e = i.get(M), t = i.get(T), n = i.get(j), { unitId: s, subUnitId: o, col: l, criteria: a } = r, c = e.getFilterModel(s, o);
|
|
1183
1183
|
if (!c) return !1;
|
|
1184
1184
|
const h = c.getRange();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FEnum } from '@univerjs/core';
|
|
2
|
+
import { CustomFilterOperator } from '@univerjs/sheets-filter';
|
|
3
|
+
export interface IFSheetsFilterEnumMixin {
|
|
4
|
+
/** Please refer to {@link CustomFilterOperation}. */
|
|
5
|
+
CustomFilterOperator: CustomFilterOperator;
|
|
6
|
+
}
|
|
7
|
+
export declare class FSheetsFilterEnumMixin extends FEnum {
|
|
8
|
+
get CustomFilterOperation(): typeof CustomFilterOperator;
|
|
9
|
+
}
|
|
10
|
+
declare module '@univerjs/core' {
|
|
11
|
+
interface FEnum extends IFSheetsFilterEnumMixin {
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { IEventBase, FEventName } from '@univerjs/core';
|
|
2
|
+
import { ISetSheetsFilterCriteriaCommandParams } from '@univerjs/sheets-filter';
|
|
3
|
+
import { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
|
|
4
|
+
export interface IFSheetFilterEventMixin {
|
|
5
|
+
/**
|
|
6
|
+
* This event will be emitted when the filter criteria on a column is changed.
|
|
7
|
+
* Type of the event is {@link ISheetRangeFilteredParams}.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const callbackDisposable = univerAPI.addEvent(univerAPI.Event.SheetRangeFiltered, (params) => {
|
|
12
|
+
* const { workbook, worksheet, col, criteria } = params;
|
|
13
|
+
*
|
|
14
|
+
* // your custom logic
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
readonly SheetRangeFiltered: 'SheetRangeFiltered';
|
|
19
|
+
/**
|
|
20
|
+
* This event will be emitted before the filter criteria on a column is changed.
|
|
21
|
+
* Type of the event is {@link ISheetRangeFilteredParams}.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const callbackDisposable = univerAPI.addEvent(univerAPI.Event.SheetBeforeRangeFilter, (params) => {
|
|
26
|
+
* const { workbook, worksheet, col, criteria } = params;
|
|
27
|
+
*
|
|
28
|
+
* // your custom logic
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
readonly SheetBeforeRangeFilter: 'SheetBeforeRangeFilter';
|
|
33
|
+
/**
|
|
34
|
+
* This event will be emitted when the filter on a worksheet is cleared.
|
|
35
|
+
* Type of the event is {@link ISheetRangeFilterClearedEventParams}.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const callbackDisposable = univerAPI.addEvent(univerAPI.Event.SheetRangeFilterCleared, (params) => {
|
|
40
|
+
* const { workbook, worksheet } = params;
|
|
41
|
+
*
|
|
42
|
+
* // your custom logic
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
readonly SheetRangeFilterCleared: 'SheetRangeFilterCleared';
|
|
47
|
+
/**
|
|
48
|
+
* This event will be emitted after the filter on a worksheet is cleared.
|
|
49
|
+
* Type of the event is {@link ISheetRangeFilterClearedEventParams}.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const callbackDisposable = univerAPI.addEvent(univerAPI.Event.SheetBeforeRangeFilterClear, (params) => {
|
|
54
|
+
* const { workbook, worksheet } = params;
|
|
55
|
+
*
|
|
56
|
+
* // your custom logic
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
readonly SheetBeforeRangeFilterClear: 'SheetBeforeRangeFilterClear';
|
|
61
|
+
}
|
|
62
|
+
export declare class FSheetFilterEventName extends FEventName implements IFSheetFilterEventMixin {
|
|
63
|
+
get SheetBeforeRangeFilter(): 'SheetBeforeRangeFilter';
|
|
64
|
+
get SheetRangeFiltered(): 'SheetRangeFiltered';
|
|
65
|
+
get SheetRangeFilterCleared(): 'SheetRangeFilterCleared';
|
|
66
|
+
get SheetBeforeRangeFilterClear(): 'SheetBeforeRangeFilterClear';
|
|
67
|
+
}
|
|
68
|
+
declare module '@univerjs/core' {
|
|
69
|
+
interface FEventName extends IFSheetFilterEventMixin {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The params of SheetRangeFiltered and SheetBeforeRangeFilter events.
|
|
74
|
+
* @param workbook - The corresponding workbook wrapped in {@link FWorkbook}.
|
|
75
|
+
* @param worksheet - The corresponding worksheet wrapped in {@link FWorksheet}.
|
|
76
|
+
* @param col - The column on which the filter criteria is changed.
|
|
77
|
+
* @param criteria - Raw filter criteria.
|
|
78
|
+
*/
|
|
79
|
+
export interface ISheetRangeFilteredParams extends IEventBase, Pick<ISetSheetsFilterCriteriaCommandParams, 'criteria' | 'col'> {
|
|
80
|
+
workbook: FWorkbook;
|
|
81
|
+
worksheet: FWorksheet;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The params of SheetRangeFilterCleared and SheetBeforeRangeFilterClear events.
|
|
85
|
+
* @param workbook - The corresponding workbook wrapped in {@link FWorkbook}.
|
|
86
|
+
* @param worksheet - The corresponding worksheet wrapped in {@link FWorksheet}.
|
|
87
|
+
*/
|
|
88
|
+
export interface ISheetRangeFilterClearedEventParams extends IEventBase {
|
|
89
|
+
workbook: FWorkbook;
|
|
90
|
+
worksheet: FWorksheet;
|
|
91
|
+
}
|
|
92
|
+
interface ISheetRangeFilterEventParamConfig {
|
|
93
|
+
SheetBeforeRangeFilter: ISheetRangeFilteredParams;
|
|
94
|
+
SheetRangeFiltered: ISheetRangeFilteredParams;
|
|
95
|
+
SheetBeforeRangeFilterClear: ISheetRangeFilterClearedEventParams;
|
|
96
|
+
SheetRangeFilterCleared: ISheetRangeFilterClearedEventParams;
|
|
97
|
+
}
|
|
98
|
+
declare module '@univerjs/core' {
|
|
99
|
+
interface FEventName extends IFSheetFilterEventMixin {
|
|
100
|
+
}
|
|
101
|
+
interface IEventParamConfig extends ISheetRangeFilterEventParamConfig {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export {};
|
|
@@ -25,16 +25,16 @@ export declare class FFilter {
|
|
|
25
25
|
/**
|
|
26
26
|
* Clear the filter criteria of a column.
|
|
27
27
|
* @param {number} col The column number.
|
|
28
|
-
* @returns {
|
|
28
|
+
* @returns {FFilter} The interface class to handle the filter.
|
|
29
29
|
*/
|
|
30
|
-
removeColumnFilterCriteria(col: number):
|
|
30
|
+
removeColumnFilterCriteria(col: number): FFilter;
|
|
31
31
|
/**
|
|
32
32
|
* Set the filter criteria of a column.
|
|
33
33
|
* @param {number} col The column number.
|
|
34
34
|
* @param {ISetSheetsFilterCriteriaCommandParams['criteria']} criteria The new filter criteria.
|
|
35
|
-
* @returns {
|
|
35
|
+
* @returns {FFilter} The interface class to handle the filter.
|
|
36
36
|
*/
|
|
37
|
-
setColumnFilterCriteria(col: number, criteria: ISetSheetsFilterCriteriaCommandParams['criteria']):
|
|
37
|
+
setColumnFilterCriteria(col: number, criteria: ISetSheetsFilterCriteriaCommandParams['criteria']): FFilter;
|
|
38
38
|
/**
|
|
39
39
|
* Get the range of the filter.
|
|
40
40
|
* @returns {FRange} The range of the filter.
|
|
@@ -44,10 +44,10 @@ export declare class FFilter {
|
|
|
44
44
|
* Remove the filter criteria of all columns.
|
|
45
45
|
* @returns {Promise<boolean>} If the filter criteria is removed.
|
|
46
46
|
*/
|
|
47
|
-
removeFilterCriteria():
|
|
47
|
+
removeFilterCriteria(): FFilter;
|
|
48
48
|
/**
|
|
49
49
|
* Remove the filter from the worksheet.
|
|
50
|
-
* @returns {
|
|
50
|
+
* @returns {boolean} If the filter is removed.
|
|
51
51
|
*/
|
|
52
|
-
remove():
|
|
52
|
+
remove(): boolean;
|
|
53
53
|
}
|
|
@@ -4,22 +4,34 @@ export interface IFRangeFilter {
|
|
|
4
4
|
/**
|
|
5
5
|
* Create a filter for the current range. If the worksheet already has a filter, this method would return `null`.
|
|
6
6
|
*
|
|
7
|
-
* @async
|
|
8
|
-
*
|
|
9
7
|
* @return The interface class to handle the filter. If the worksheet already has a filter,
|
|
10
8
|
* this method would return `null`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const workbook = univerAPI.getActiveWorkbook();
|
|
13
|
+
* const worksheet = workbook.getActiveSheet();
|
|
14
|
+
* const filter = worksheet.getRange('A1:D14').createFilter();
|
|
15
|
+
* ```
|
|
11
16
|
*/
|
|
12
|
-
createFilter(this: FRange):
|
|
17
|
+
createFilter(this: FRange): FFilter | null;
|
|
13
18
|
/**
|
|
14
|
-
* Get the filter for the current range's worksheet.
|
|
19
|
+
* Get the filter for the current range's worksheet. Normally, you can directly call `getFilter` on {@link FWorksheet}.
|
|
15
20
|
*
|
|
16
21
|
* @return {FFilter | null} The interface class to handle the filter. If the worksheet does not have a filter,
|
|
17
22
|
* this method would return `null`.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const workbook = univerAPI.getActiveWorkbook();
|
|
27
|
+
* const worksheet = workbook.getActiveSheet();
|
|
28
|
+
* const filter = worksheet.getRange('A1:D14').getFilter();
|
|
29
|
+
* ````
|
|
18
30
|
*/
|
|
19
31
|
getFilter(): FFilter | null;
|
|
20
32
|
}
|
|
21
33
|
export declare class FRangeFilter extends FRange implements IFRangeFilter {
|
|
22
|
-
createFilter():
|
|
34
|
+
createFilter(): FFilter | null;
|
|
23
35
|
/**
|
|
24
36
|
* Get the filter for the current range's worksheet.
|
|
25
37
|
*
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { FWorksheet } from '@univerjs/sheets/facade';
|
|
2
2
|
import { FFilter } from './f-filter';
|
|
3
3
|
export interface IFWorksheetFilter {
|
|
4
|
+
/**
|
|
5
|
+
* Get the filter for the current worksheet.
|
|
6
|
+
*
|
|
7
|
+
* @return {FFilter | null} The interface class to handle the filter. If the worksheet does not have a filter,
|
|
8
|
+
* this method would return `null`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const workbook = univerAPI.getActiveWorkbook();
|
|
13
|
+
* const worksheet = workbook.getActiveSheet();
|
|
14
|
+
* const filter = worksheet.getFilter();
|
|
15
|
+
* ````
|
|
16
|
+
*/
|
|
4
17
|
getFilter(): FFilter | null;
|
|
5
18
|
}
|
|
6
19
|
export declare class FWorksheetFilter extends FWorksheet implements IFWorksheetFilter {
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
import './f-filter';
|
|
17
17
|
import './f-range';
|
|
18
18
|
import './f-worksheet';
|
|
19
|
+
import './f-enum';
|
|
20
|
+
import './f-event';
|
|
21
|
+
export type * from './f-enum';
|
|
22
|
+
export type * from './f-event';
|
|
19
23
|
export { FFilter } from './f-filter';
|
|
20
24
|
export type * from './f-filter';
|
|
21
25
|
export type * from './f-range';
|
|
@@ -58,17 +58,23 @@ export interface ICustomFilter {
|
|
|
58
58
|
operator?: CustomFilterOperator;
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* Basic custom filter operators.
|
|
62
62
|
*
|
|
63
|
-
*
|
|
64
|
-
* They are represented by regex-like values.
|
|
63
|
+
* @internal
|
|
64
|
+
* doesNotContain, isBlank, isNotBlank are not defined in OOXML. They are represented by regex-like values.
|
|
65
65
|
*/
|
|
66
66
|
export declare enum CustomFilterOperator {
|
|
67
|
+
/** "EQUAL" operator. */
|
|
67
68
|
EQUAL = "equal",
|
|
69
|
+
/** "GREATER_THAN" operator. */
|
|
68
70
|
GREATER_THAN = "greaterThan",
|
|
71
|
+
/** "GREATER_THAN_OR_EQUAL" operator. */
|
|
69
72
|
GREATER_THAN_OR_EQUAL = "greaterThanOrEqual",
|
|
73
|
+
/** "LESS_THAN" operator. */
|
|
70
74
|
LESS_THAN = "lessThan",
|
|
75
|
+
/** "LESS_THAN_OR_EQUAL" operator. */
|
|
71
76
|
LESS_THAN_OR_EQUAL = "lessThanOrEqual",
|
|
77
|
+
/** "NOT_EQUALS" operator. */
|
|
72
78
|
NOT_EQUALS = "notEqual"
|
|
73
79
|
}
|
|
74
80
|
export interface IDynamicFilter {
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(o,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/core"),require("@univerjs/sheets-filter"),require("@univerjs/sheets/facade")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-filter","@univerjs/sheets/facade"],i):(o=typeof globalThis<"u"?globalThis:o||self,i(o.UniverSheetsFilterFacade={},o.UniverCore,o.UniverSheetsFilter,o.UniverSheetsFacade))})(this,function(o,i,s,h){"use strict";var m=Object.defineProperty,u=Object.getOwnPropertyDescriptor,F=(a,e,t,r)=>{for(var n=r>1?void 0:r?u(e,t):e,l=a.length-1,d;l>=0;l--)(d=a[l])&&(n=(r?d(e,t,n):d(n))||n);return r&&n&&m(e,t,n),n},c=(a,e)=>(t,r)=>e(t,r,a);o.FFilter=class{constructor(e,t,r,n,l){this._workbook=e,this._worksheet=t,this._filterModel=r,this._injector=n,this._commandSrv=l}getFilteredOutRows(){return Array.from(this._filterModel.filteredOutRows).sort()}getColumnFilterCriteria(e){var t;return(t=this._filterModel.getFilterColumn(e))==null?void 0:t.getColumnData()}removeColumnFilterCriteria(e){return this._commandSrv.syncExecuteCommand(s.SetSheetsFilterCriteriaCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),col:e,criteria:null}),this}setColumnFilterCriteria(e,t){return this._commandSrv.syncExecuteCommand(s.SetSheetsFilterCriteriaCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),col:e,criteria:t}),this}getRange(){const e=this._filterModel.getRange();return this._injector.createInstance(h.FRange,this._workbook,this._worksheet,e)}removeFilterCriteria(){return this._commandSrv.syncExecuteCommand(s.ClearSheetsFilterCriteriaCommand.id),this}remove(){return this._commandSrv.syncExecuteCommand(s.RemoveSheetFilterCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()})}},o.FFilter=F([c(3,i.Inject(i.Injector)),c(4,i.ICommandService)],o.FFilter);class g extends h.FRange{createFilter(){return this._getFilterModel()||!this._commandService.syncExecuteCommand(s.SetSheetFilterRangeCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range})?null:this.getFilter()}getFilter(){const e=this._getFilterModel();return e?this._injector.createInstance(o.FFilter,this._workbook,this._worksheet,e):null}_getFilterModel(){return this._injector.get(s.SheetsFilterService).getFilterModel(this._workbook.getUnitId(),this._worksheet.getSheetId())}}h.FRange.extend(g);class S extends h.FWorksheet{getFilter(){const e=this._getFilterModel();return e?this._injector.createInstance(o.FFilter,this._workbook,this._worksheet,e):null}_getFilterModel(){return this._injector.get(s.SheetsFilterService).getFilterModel(this._workbook.getUnitId(),this._worksheet.getSheetId())}}h.FWorksheet.extend(S);class v extends i.FEnum{get CustomFilterOperation(){return s.CustomFilterOperator}}i.FEnum.extend(v);class C extends i.FEventName{get SheetBeforeRangeFilter(){return"SheetBeforeRangeFilter"}get SheetRangeFiltered(){return"SheetRangeFiltered"}get SheetRangeFilterCleared(){return"SheetRangeFilterCleared"}get SheetBeforeRangeFilterClear(){return"SheetBeforeRangeFilterClear"}}i.FEventName.extend(C),i.FEventName.extend(h.FSheetEventName);class _ extends i.FUniver{_initialize(e){const t=e.get(i.ICommandService);this.disposeWithMe(t.beforeCommandExecuted(r=>{switch(r.id){case s.SetSheetsFilterCriteriaCommand.id:this._beforeRangeFilter(r);break;case s.ClearSheetsFilterCriteriaCommand.id:this._beforeRangeFilterClear();break}})),this.disposeWithMe(t.onCommandExecuted(r=>{switch(r.id){case s.SetSheetsFilterCriteriaCommand.id:this._onRangeFiltered(r);break;case s.ClearSheetsFilterCriteriaCommand.id:this._onRangeFilterCleared();break}}))}_beforeRangeFilter(e){const t=e.params,r=this.getUniverSheet(t.unitId),n={workbook:r,worksheet:r.getSheetBySheetId(t.subUnitId),col:t.col,criteria:t.criteria};if(this.fireEvent(this.Event.SheetBeforeRangeFilter,n),n.cancel)throw new Error("SetSheetsFilterCriteriaCommand canceled.")}_onRangeFiltered(e){const t=e.params,r=this.getUniverSheet(t.unitId),n={workbook:r,worksheet:r.getSheetBySheetId(t.subUnitId),col:t.col,criteria:t.criteria};if(this.fireEvent(this.Event.SheetRangeFiltered,n),n.cancel)throw new Error("SetSheetsFilterCriteriaCommand canceled.")}_beforeRangeFilterClear(){const e=this.getActiveWorkbook();if(!e)return;const t={workbook:e,worksheet:e.getActiveSheet()};if(this.fireEvent(this.Event.SheetBeforeRangeFilterClear,t),t.cancel)throw new Error("SetSheetsFilterCriteriaCommand canceled.")}_onRangeFilterCleared(){const e=this.getActiveWorkbook();if(!e)return;const t={workbook:e,worksheet:e.getActiveSheet()};if(this.fireEvent(this.Event.SheetRangeFilterCleared,t),t.cancel)throw new Error("SetSheetsFilterCriteriaCommand canceled.")}}i.FUniver.extend(_),Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
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 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"})});
|
|
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:(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.3-experimental.20250106-4af1f4e",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A library for filtering data in Univer Sheet",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -51,33 +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.3-experimental.20250106-4af1f4e",
|
|
55
|
+
"@univerjs/sheets": "0.5.3-experimental.20250106-4af1f4e"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"rxjs": "^7.8.1",
|
|
59
59
|
"typescript": "^5.7.2",
|
|
60
|
-
"vite": "^6.0.
|
|
60
|
+
"vite": "^6.0.6",
|
|
61
61
|
"vitest": "^2.1.8",
|
|
62
|
-
"@univerjs-infra/shared": "0.5.
|
|
63
|
-
},
|
|
64
|
-
"space": {
|
|
65
|
-
".": {
|
|
66
|
-
"import": "./lib/es/index.js",
|
|
67
|
-
"require": "./lib/cjs/index.js",
|
|
68
|
-
"types": "./lib/types/index.d.ts"
|
|
69
|
-
},
|
|
70
|
-
"./*": {
|
|
71
|
-
"import": "./lib/es/*",
|
|
72
|
-
"require": "./lib/cjs/*",
|
|
73
|
-
"types": "./lib/types/index.d.ts"
|
|
74
|
-
},
|
|
75
|
-
"./facade": {
|
|
76
|
-
"import": "./lib/es/facade.js",
|
|
77
|
-
"require": "./lib/cjs/facade.js",
|
|
78
|
-
"types": "./lib/types/facade/index.d.ts"
|
|
79
|
-
},
|
|
80
|
-
"./lib/*": "./lib/*"
|
|
62
|
+
"@univerjs-infra/shared": "0.5.3"
|
|
81
63
|
},
|
|
82
64
|
"scripts": {
|
|
83
65
|
"test": "vitest run",
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|