@univerjs/sheets-filter-ui 0.8.1 → 0.8.2-nightly.202506201607

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -4,4 +4,4 @@
4
4
  hover:univer-bg-gray-50 univer-h-full
5
5
  univer-text-gray-900 dark:hover:!univer-bg-gray-900
6
6
  dark:!univer-text-white
7
- `,attachRender:_=>d.jsxs("div",{className:"univer-ml-1 univer-flex univer-h-5 univer-flex-1 univer-cursor-pointer univer-items-center univer-justify-between univer-text-sm univer-text-primary-500",children:[d.jsx("span",{"data-u-comp":"sheets-filter-panel-values-item-count",className:"univer-text-gray-400 dark:!univer-text-gray-500",children:`(${_.count})`}),d.jsx("a",{className:"univer-box-border univer-hidden univer-h-4 univer-whitespace-nowrap univer-px-1.5",onClick:()=>{const E=[];_.children?_.children.forEach(F=>{F.children?F.children.forEach(R=>{E.push(R.key)}):E.push(F.key)}):E.push(_.key),e.onFilterOnly(E)},children:l})]})})})]})]})}function _t(){var R;const t=C.useDependency(Q),e=C.useDependency(u.LocaleService),r=C.useDependency(u.ICommandService),s=C.useObservable(t.filterBy$,void 0,!0),n=C.useObservable(t.filterByModel$,void 0,!1),l=C.useObservable(()=>(n==null?void 0:n.canApply$)||S.of(!1),void 0,!1,[n]),i=vt(e),o=!C.useObservable(t.hasCriteria$),a=b.useCallback(I=>{r.executeCommand(Ae.id,{filterBy:I})},[r]),h=b.useCallback(async()=>{await(n==null?void 0:n.clear()),r.executeCommand(z.id)},[n,r]),m=b.useCallback(()=>{r.executeCommand(z.id)},[r]),f=b.useCallback(async()=>{await(n==null?void 0:n.apply()),r.executeCommand(z.id)},[n,r]),_=(R=C.useDependency(c.SheetsFilterService).activeFilterModel)==null?void 0:R.getRange(),E=t.col,F=C.useComponentsOfPart(U.SheetsUIPart.FILTER_PANEL_EMBED_POINT);return d.jsxs("div",{"data-u-comp":"sheets-filter-panel",className:"univer-box-border univer-flex univer-h-[442px] univer-w-[312px] univer-flex-col univer-rounded-lg univer-bg-white univer-p-4 univer-shadow-lg dark:!univer-border-gray-600 dark:!univer-bg-gray-700",children:[d.jsx(C.ComponentContainer,{components:F,sharedProps:{range:_,colIndex:E,onClose:m}}),d.jsx("div",{className:"univer-mb-1 univer-flex-shrink-0 univer-flex-grow-0",children:d.jsx(y.Segmented,{value:s,items:i,onChange:I=>a(I)})}),n?d.jsx("div",{"data-u-comp":"sheets-filter-panel-content",className:"univer-flex-shrink univer-flex-grow univer-pt-2",children:s===de.VALUES?d.jsx(ft,{model:n}):d.jsx(mt,{model:n})}):d.jsx("div",{className:"univer-flex-1"}),d.jsxs("div",{"data-u-comp":"sheets-filter-panel-footer",className:"univer-mt-4 univer-inline-flex univer-flex-shrink-0 univer-flex-grow-0 univer-flex-nowrap univer-justify-between univer-overflow-hidden",children:[d.jsx(y.Button,{variant:"link",onClick:h,disabled:o,children:e.t("sheets-filter.panel.clear-filter")}),d.jsxs("span",{className:"univer-flex univer-gap-2",children:[d.jsx(y.Button,{variant:"default",onClick:m,children:e.t("sheets-filter.panel.cancel")}),d.jsx(y.Button,{disabled:!l,variant:"primary",onClick:f,children:e.t("sheets-filter.panel.confirm")})]})]})]})}function vt(t){const e=t.getCurrentLocale();return b.useMemo(()=>[{label:t.t("sheets-filter.panel.by-values"),value:de.VALUES},{label:t.t("sheets-filter.panel.by-conditions"),value:de.CONDITIONS}],[e,t])}function gt(t){const e=t.get(c.SheetsFilterService);return{id:c.SmartToggleSheetsFilterCommand.id,type:C.MenuItemType.BUTTON_SELECTOR,icon:"FilterIcon",tooltip:"sheets-filter.toolbar.smart-toggle-filter-tooltip",hidden$:C.getMenuHiddenObservable(t,u.UniverInstanceType.UNIVER_SHEET),activated$:e.activeFilterModel$.pipe(S.map(r=>!!r)),disabled$:U.getObservableWithExclusiveRange$(t,U.getCurrentRangeDisable$(t,{worksheetTypes:[O.WorksheetFilterPermission,O.WorksheetViewPermission],rangeTypes:[O.RangeProtectionPermissionViewPoint]}))}}function St(t){const e=t.get(c.SheetsFilterService);return{id:c.ClearSheetsFilterCriteriaCommand.id,type:C.MenuItemType.BUTTON,title:"sheets-filter.toolbar.clear-filter-criteria",hidden$:C.getMenuHiddenObservable(t,u.UniverInstanceType.UNIVER_SHEET),disabled$:e.activeFilterModel$.pipe(S.switchMap(r=>{var s;return(s=r==null?void 0:r.hasCriteria$.pipe(S.map(n=>!n)))!=null?s:S.of(!0)}))}}function Ct(t){const e=t.get(c.SheetsFilterService);return{id:c.ReCalcSheetsFilterCommand.id,type:C.MenuItemType.BUTTON,title:"sheets-filter.toolbar.re-calc-filter-conditions",hidden$:C.getMenuHiddenObservable(t,u.UniverInstanceType.UNIVER_SHEET),disabled$:e.activeFilterModel$.pipe(S.switchMap(r=>{var s;return(s=r==null?void 0:r.hasCriteria$.pipe(S.map(n=>!n)))!=null?s:S.of(!0)}))}}const Ft={[C.RibbonDataGroup.ORGANIZATION]:{[c.SmartToggleSheetsFilterCommand.id]:{order:2,menuItemFactory:gt,[c.ClearSheetsFilterCriteriaCommand.id]:{order:0,menuItemFactory:St},[c.ReCalcSheetsFilterCommand.id]:{order:1,menuItemFactory:Ct}}}},V=16,Tt=new Path2D("M3.30363 3C2.79117 3 2.51457 3.60097 2.84788 3.99024L6.8 8.60593V12.5662C6.8 12.7184 6.8864 12.8575 7.02289 12.9249L8.76717 13.7863C8.96655 13.8847 9.2 13.7396 9.2 13.5173V8.60593L13.1521 3.99024C13.4854 3.60097 13.2088 3 12.6964 3H3.30363Z");class Le{static drawNoCriteria(e,r,s,n){e.save(),ie.Rect.drawWith(e,{radius:2,width:V,height:V,fill:n}),e.lineCap="square",e.strokeStyle=s,e.scale(r/V,r/V),e.beginPath(),e.lineWidth=1,e.lineCap="round",e.moveTo(3,4),e.lineTo(13,4),e.moveTo(4.5,8),e.lineTo(11.5,8),e.moveTo(6,12),e.lineTo(10,12),e.stroke(),e.restore()}static drawHasCriteria(e,r,s,n){e.save(),ie.Rect.drawWith(e,{radius:2,width:V,height:V,fill:n}),e.scale(r/V,r/V),e.fillStyle=s,e.fill(Tt),e.restore()}}var Et=Object.getOwnPropertyDescriptor,Ot=(t,e,r,s)=>{for(var n=s>1?void 0:s?Et(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(n=i(n)||n);return n},Te=(t,e)=>(r,s)=>e(r,s,t);const B=16,ce=1;let ye=class extends ie.Shape{constructor(e,r,s,n,l){super(e,r);v(this,"_cellWidth",0);v(this,"_cellHeight",0);v(this,"_filterParams");v(this,"_hovered",!1);this._contextService=s,this._commandService=n,this._themeService=l,this.setShapeProps(r),this.onPointerDown$.subscribeEvent(i=>this.onPointerDown(i)),this.onPointerEnter$.subscribeEvent(()=>this.onPointerEnter()),this.onPointerLeave$.subscribeEvent(()=>this.onPointerLeave())}setShapeProps(e){typeof e.cellHeight<"u"&&(this._cellHeight=e.cellHeight),typeof e.cellWidth<"u"&&(this._cellWidth=e.cellWidth),typeof e.filterParams<"u"&&(this._filterParams=e.filterParams),this.transformByState({width:e.width,height:e.height})}_draw(e){const r=this._cellHeight,s=this._cellWidth,n=B-s,l=B-r;e.save();const i=new Path2D;i.rect(n,l,s,r),e.clip(i);const{hasCriteria:o}=this._filterParams,a=this._themeService.getColorFromTheme("primary.600"),h=this._hovered?this._themeService.getColorFromTheme("gray.50"):"rgba(255, 255, 255, 1.0)";o?Le.drawHasCriteria(e,B,a,h):Le.drawNoCriteria(e,B,a,h),e.restore()}onPointerDown(e){if(e.button===2)return;const{col:r,unitId:s,subUnitId:n}=this._filterParams;this._contextService.getContextValue(J)||!this._commandService.hasCommand(se.id)||setTimeout(()=>{this._commandService.executeCommand(se.id,{unitId:s,subUnitId:n,col:r})},200)}onPointerEnter(){this._hovered=!0,this.makeDirty(!0)}onPointerLeave(){this._hovered=!1,this.makeDirty(!0)}};ye=Ot([Te(2,u.IContextService),Te(3,u.ICommandService),Te(4,u.Inject(u.ThemeService))],ye);var It=Object.getOwnPropertyDescriptor,Nt=(t,e,r,s)=>{for(var n=s>1?void 0:s?It(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(n=i(n)||n);return n},q=(t,e)=>(r,s)=>e(r,s,t);const yt=1e3,Rt=5e3;let Re=class extends u.RxDisposable{constructor(e,r,s,n,l,i,o,a){super();v(this,"_filterRangeShape",null);v(this,"_buttonRenderDisposable",null);v(this,"_filterButtonShapes",[]);this._context=e,this._injector=r,this._sheetSkeletonManagerService=s,this._sheetsFilterService=n,this._themeService=l,this._sheetInterceptorService=i,this._commandService=o,this._selectionRenderService=a,this._initRenderer()}dispose(){super.dispose(),this._disposeRendering()}_initRenderer(){this._sheetSkeletonManagerService.currentSkeleton$.pipe(S.switchMap(e=>{var o,a;if(!e)return S.of(null);const{unit:r,unitId:s}=this._context,n=((o=r.getActiveSheet())==null?void 0:o.getSheetId())||"",l=(a=this._sheetsFilterService.getFilterModel(s,n))!=null?a:void 0,i=()=>({unitId:s,worksheetId:n,filterModel:l,range:l==null?void 0:l.getRange(),skeleton:e.skeleton});return u.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(S.filter(([h])=>{var m;return h.type===u.CommandType.MUTATION&&((m=h.params)==null?void 0:m.unitId)===r.getUnitId()&&(c.FILTER_MUTATIONS.has(h.id)||h.id===O.SetRangeValuesMutation.id)}),S.throttleTime(20,void 0,{leading:!1,trailing:!0}),S.map(i),S.startWith(i()))}),S.takeUntil(this.dispose$)).subscribe(e=>{this._disposeRendering(),!(!e||!e.range)&&(this._renderRange(e.range,e.skeleton),this._renderButtons(e))})}_renderRange(e,r){const{scene:s}=this._context,{rowHeaderWidth:n,columnHeaderHeight:l}=r,i=this._filterRangeShape=new U.SelectionControl(s,yt,this._themeService,{rowHeaderWidth:n,columnHeaderHeight:l,enableAutoFill:!1,highlightHeader:!1}),o={range:e,primary:null,style:{fill:"rgba(0, 0, 0, 0.0)"}},a=U.attachSelectionWithCoord(o,r);i.updateRangeBySelectionWithCoord(a),i.setEvent(!1),s.makeDirty(!0)}_renderButtons(e){const{range:r,filterModel:s,unitId:n,skeleton:l,worksheetId:i}=e,{scene:o}=this._context;this._interceptCellContent(n,i,e.range);const{startColumn:a,endColumn:h,startRow:m}=r;for(let f=a;f<=h;f++){const T=`sheets-filter-button-${f}`,_=U.getCoordByCell(m,f,o,l),{startX:E,startY:F,endX:R,endY:I}=_,M=R-E,A=I-F;if(A<=ce||M<=ce)continue;const k=!!s.getFilterColumn(f),D=R-B-ce,oe=I-B-ce,ae={left:D,top:oe,height:B,width:B,zIndex:Rt,cellHeight:A,cellWidth:M,filterParams:{unitId:n,subUnitId:i,col:f,hasCriteria:k}},w=this._injector.createInstance(ye,T,ae);this._filterButtonShapes.push(w)}o.addObjects(this._filterButtonShapes),o.makeDirty()}_interceptCellContent(e,r,s){const{startRow:n,startColumn:l,endColumn:i}=s;this._buttonRenderDisposable=this._sheetInterceptorService.intercept(O.INTERCEPTOR_POINT.CELL_CONTENT,{effect:u.InterceptorEffectEnum.Style,handler:(o,a,h)=>{const{row:m,col:f,unitId:T,subUnitId:_}=a;return T!==e||_!==r||m!==n||f<l||f>i||((!o||o===a.rawData)&&(o={...a.rawData}),o.fontRenderExtension={...o==null?void 0:o.fontRenderExtension,rightOffset:B}),h(o)},priority:10})}_disposeRendering(){var e,r;(e=this._filterRangeShape)==null||e.dispose(),this._filterButtonShapes.forEach(s=>s.dispose()),(r=this._buttonRenderDisposable)==null||r.dispose(),this._filterRangeShape=null,this._buttonRenderDisposable=null,this._filterButtonShapes=[]}};Re=Nt([q(1,u.Inject(u.Injector)),q(2,u.Inject(U.SheetSkeletonManagerService)),q(3,u.Inject(c.SheetsFilterService)),q(4,u.Inject(u.ThemeService)),q(5,u.Inject(O.SheetInterceptorService)),q(6,u.ICommandService),q(7,U.ISheetSelectionRenderService)],Re);var Pt=Object.getOwnPropertyDescriptor,bt=(t,e,r,s)=>{for(var n=s>1?void 0:s?Pt(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(n=i(n)||n);return n},Ue=(t,e)=>(r,s)=>e(r,s,t);let ne=class extends u.RxDisposable{constructor(t,e){super(),this._renderManagerService=t,this._sheetsRenderService=e,[c.SetSheetsFilterRangeMutation,c.SetSheetsFilterCriteriaMutation,c.RemoveSheetsFilterMutation,c.ReCalcSheetsFilterMutation].forEach(r=>this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(r.id))),this.disposeWithMe(this._renderManagerService.registerRenderModule(u.UniverInstanceType.UNIVER_SHEET,[Re]))}};ne=bt([Ue(0,ie.IRenderManagerService),Ue(1,u.Inject(U.SheetsRenderService))],ne);const At={id:c.SmartToggleSheetsFilterCommand.id,binding:C.KeyCode.L|C.MetaKeys.CTRL_COMMAND|C.MetaKeys.SHIFT,description:"sheets-filter.shortcut.smart-toggle-filter",preconditions:U.whenSheetEditorFocused,group:"4_sheet-edit"};var Mt=Object.getOwnPropertyDescriptor,wt=(t,e,r,s)=>{for(var n=s>1?void 0:s?Mt(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(n=i(n)||n);return n},L=(t,e)=>(r,s)=>e(r,s,t);const $e="FILTER_PANEL_POPUP";let ve=class extends ne{constructor(e,r,s,n,l,i,o,a,h,m,f,T,_){super(_,T);v(this,"_popupDisposable");this._injector=e,this._componentManager=r,this._sheetsFilterPanelService=s,this._sheetCanvasPopupService=n,this._sheetsFilterService=l,this._localeService=i,this._shortcutService=o,this._commandService=a,this._menuManagerService=h,this._contextService=m,this._messageService=f,this._initCommands(),this._initShortcuts(),this._initMenuItems(),this._initUI()}dispose(){super.dispose(),this._closeFilterPopup()}_initShortcuts(){[At].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_initCommands(){[c.SmartToggleSheetsFilterCommand,c.RemoveSheetFilterCommand,c.SetSheetFilterRangeCommand,c.SetSheetsFilterCriteriaCommand,c.ClearSheetsFilterCriteriaCommand,c.ReCalcSheetsFilterCommand,Ae,se,z].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenuItems(){this._menuManagerService.mergeMenu(Ft)}_initUI(){[[$e,_t],["FilterIcon",Qe]].forEach(([e,r])=>{this.disposeWithMe(this._componentManager.register(e,r))}),this.disposeWithMe(this._contextService.subscribeContextValue$(J).pipe(S.distinctUntilChanged()).subscribe(e=>{e?this._openFilterPopup():this._closeFilterPopup()})),this.disposeWithMe(this._sheetsFilterService.errorMsg$.subscribe(e=>{e&&this._messageService.show({type:y.MessageType.Error,content:this._localeService.t(e)})}))}_openFilterPopup(){const e=this._sheetsFilterPanelService.filterModel;if(!e)throw new Error("[SheetsFilterUIController]: no filter model when opening filter popup!");const r=e.getRange(),s=this._sheetsFilterPanelService.col,{startRow:n}=r;this._popupDisposable=this._sheetCanvasPopupService.attachPopupToCell(n,s,{componentKey:$e,direction:"horizontal",onClickOutside:()=>this._commandService.syncExecuteCommand(z.id),offset:[5,0]})}_closeFilterPopup(){var e;(e=this._popupDisposable)==null||e.dispose(),this._popupDisposable=null}};ve=wt([L(0,u.Inject(u.Injector)),L(1,u.Inject(C.ComponentManager)),L(2,u.Inject(Q)),L(3,u.Inject(U.SheetCanvasPopManagerService)),L(4,u.Inject(c.SheetsFilterService)),L(5,u.Inject(u.LocaleService)),L(6,C.IShortcutService),L(7,u.ICommandService),L(8,C.IMenuManagerService),L(9,u.IContextService),L(10,C.IMessageService),L(11,u.Inject(U.SheetsRenderService)),L(12,ie.IRenderManagerService)],ve);var Lt=Object.defineProperty,Ut=Object.getOwnPropertyDescriptor,$t=(t,e,r)=>e in t?Lt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xt=(t,e,r,s)=>{for(var n=s>1?void 0:s?Ut(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(n=i(n)||n);return n},Ee=(t,e)=>(r,s)=>e(r,s,t),Ge=(t,e,r)=>$t(t,typeof e!="symbol"?e+"":e,r);const kt="SHEET_FILTER_UI_PLUGIN";exports.UniverSheetsFilterUIPlugin=class extends u.Plugin{constructor(e=he,r,s,n){super(),this._config=e,this._injector=r,this._configService=s,this._rpcChannelService=n;const{menu:l,...i}=u.merge({},he,this._config);l&&this._configService.setConfig("menu",l,{merge:!0}),this._configService.setConfig(De,i)}onStarting(){[[Q],[ee],[ve]].forEach(e=>this._injector.add(e)),this._config.useRemoteFilterValuesGenerator&&this._rpcChannelService&&this._injector.add([me,{useFactory:()=>ge.toModule(this._rpcChannelService.requestChannel(Pe))}])}onReady(){this._injector.get(ee)}onRendered(){this._injector.get(ve)}};Ge(exports.UniverSheetsFilterUIPlugin,"type",u.UniverInstanceType.UNIVER_SHEET);Ge(exports.UniverSheetsFilterUIPlugin,"pluginName",kt);exports.UniverSheetsFilterUIPlugin=xt([u.DependentOn(c.UniverSheetsFilterPlugin),Ee(1,u.Inject(u.Injector)),Ee(2,u.IConfigService),Ee(3,u.Optional(ge.IRPCChannelService))],exports.UniverSheetsFilterUIPlugin);var Dt=Object.defineProperty,Ht=Object.getOwnPropertyDescriptor,jt=(t,e,r)=>e in t?Dt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Bt=(t,e,r,s)=>{for(var n=s>1?void 0:s?Ht(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(n=i(n)||n);return n},xe=(t,e)=>(r,s)=>e(r,s,t),Ye=(t,e,r)=>jt(t,typeof e!="symbol"?e+"":e,r);const Wt="SHEET_FILTER_UI_PLUGIN";exports.UniverSheetsFilterMobileUIPlugin=class extends u.Plugin{constructor(e=he,r,s){super(),this._config=e,this._injector=r,this._configService=s;const{menu:n,...l}=u.merge({},he,this._config);n&&this._configService.setConfig("menu",n,{merge:!0}),this._configService.setConfig(De,l)}onStarting(){[[ee],[ne]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(ee)}onRendered(){this._injector.get(ne)}};Ye(exports.UniverSheetsFilterMobileUIPlugin,"type",u.UniverInstanceType.UNIVER_SHEET);Ye(exports.UniverSheetsFilterMobileUIPlugin,"pluginName",Wt);exports.UniverSheetsFilterMobileUIPlugin=Bt([u.DependentOn(c.UniverSheetsFilterPlugin),xe(1,u.Inject(u.Injector)),xe(2,u.IConfigService)],exports.UniverSheetsFilterMobileUIPlugin);var Vt=Object.getOwnPropertyDescriptor,Qt=(t,e,r,s)=>{for(var n=s>1?void 0:s?Vt(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(n=i(n)||n);return n},ke=(t,e)=>(r,s)=>e(r,s,t),ue;exports.UniverSheetsFilterUIWorkerPlugin=(ue=class extends u.Plugin{constructor(e,r,s){super(),this._config=e,this._injector=r,this._rpcChannelService=s}onStarting(){[[me,{useClass:Ie}]].forEach(e=>this._injector.add(e))}onReady(){this._rpcChannelService.registerChannel(Pe,ge.fromModule(this._injector.get(me)))}},v(ue,"type",u.UniverInstanceType.UNIVER_SHEET),v(ue,"pluginName","SHEET_FILTER_UI_WORKER_PLUGIN"),ue);exports.UniverSheetsFilterUIWorkerPlugin=Qt([ke(1,u.Inject(u.Injector)),ke(2,ge.IRPCChannelService)],exports.UniverSheetsFilterUIWorkerPlugin);exports.ChangeFilterByOperation=Ae;exports.CloseFilterPanelOperation=z;exports.OpenFilterPanelOperation=se;
7
+ `,attachRender:_=>d.jsxs("div",{className:"univer-ml-1 univer-flex univer-h-5 univer-flex-1 univer-cursor-pointer univer-items-center univer-justify-between univer-text-sm univer-text-primary-500",children:[d.jsx("span",{"data-u-comp":"sheets-filter-panel-values-item-count",className:"univer-text-gray-400 dark:!univer-text-gray-500",children:`(${_.count})`}),d.jsx("a",{className:"univer-box-border univer-hidden univer-h-4 univer-whitespace-nowrap univer-px-1.5",onClick:()=>{const E=[];_.children?_.children.forEach(F=>{F.children?F.children.forEach(R=>{E.push(R.key)}):E.push(F.key)}):E.push(_.key),e.onFilterOnly(E)},children:l})]})})})]})]})}function _t(){var R;const t=C.useDependency(Q),e=C.useDependency(u.LocaleService),r=C.useDependency(u.ICommandService),s=C.useObservable(t.filterBy$,void 0,!0),n=C.useObservable(t.filterByModel$,void 0,!1),l=C.useObservable(()=>(n==null?void 0:n.canApply$)||S.of(!1),void 0,!1,[n]),i=vt(e),o=!C.useObservable(t.hasCriteria$),a=b.useCallback(I=>{r.executeCommand(Ae.id,{filterBy:I})},[r]),h=b.useCallback(async()=>{await(n==null?void 0:n.clear()),r.executeCommand(z.id)},[n,r]),m=b.useCallback(()=>{r.executeCommand(z.id)},[r]),f=b.useCallback(async()=>{await(n==null?void 0:n.apply()),r.executeCommand(z.id)},[n,r]),_=(R=C.useDependency(c.SheetsFilterService).activeFilterModel)==null?void 0:R.getRange(),E=t.col,F=C.useComponentsOfPart(U.SheetsUIPart.FILTER_PANEL_EMBED_POINT);return d.jsxs("div",{"data-u-comp":"sheets-filter-panel",className:"univer-box-border univer-flex univer-h-[442px] univer-w-[312px] univer-flex-col univer-rounded-lg univer-bg-white univer-p-4 univer-shadow-lg dark:!univer-border-gray-600 dark:!univer-bg-gray-700",children:[d.jsx(C.ComponentContainer,{components:F,sharedProps:{range:_,colIndex:E,onClose:m}}),d.jsx("div",{className:"univer-mb-1 univer-flex-shrink-0 univer-flex-grow-0",children:d.jsx(y.Segmented,{value:s,items:i,onChange:I=>a(I)})}),n?d.jsx("div",{"data-u-comp":"sheets-filter-panel-content",className:"univer-flex-shrink univer-flex-grow univer-pt-2",children:s===de.VALUES?d.jsx(ft,{model:n}):d.jsx(mt,{model:n})}):d.jsx("div",{className:"univer-flex-1"}),d.jsxs("div",{"data-u-comp":"sheets-filter-panel-footer",className:"univer-mt-4 univer-inline-flex univer-flex-shrink-0 univer-flex-grow-0 univer-flex-nowrap univer-justify-between univer-overflow-hidden",children:[d.jsx(y.Button,{variant:"link",onClick:h,disabled:o,children:e.t("sheets-filter.panel.clear-filter")}),d.jsxs("span",{className:"univer-flex univer-gap-2",children:[d.jsx(y.Button,{variant:"default",onClick:m,children:e.t("sheets-filter.panel.cancel")}),d.jsx(y.Button,{disabled:!l,variant:"primary",onClick:f,children:e.t("sheets-filter.panel.confirm")})]})]})]})}function vt(t){const e=t.getCurrentLocale();return b.useMemo(()=>[{label:t.t("sheets-filter.panel.by-values"),value:de.VALUES},{label:t.t("sheets-filter.panel.by-conditions"),value:de.CONDITIONS}],[e,t])}function gt(t){const e=t.get(c.SheetsFilterService);return{id:c.SmartToggleSheetsFilterCommand.id,type:C.MenuItemType.BUTTON_SELECTOR,icon:"FilterIcon",tooltip:"sheets-filter.toolbar.smart-toggle-filter-tooltip",hidden$:C.getMenuHiddenObservable(t,u.UniverInstanceType.UNIVER_SHEET),activated$:e.activeFilterModel$.pipe(S.map(r=>!!r)),disabled$:U.getObservableWithExclusiveRange$(t,U.getCurrentRangeDisable$(t,{worksheetTypes:[O.WorksheetFilterPermission,O.WorksheetViewPermission],rangeTypes:[O.RangeProtectionPermissionViewPoint]}))}}function St(t){const e=t.get(c.SheetsFilterService);return{id:c.ClearSheetsFilterCriteriaCommand.id,type:C.MenuItemType.BUTTON,title:"sheets-filter.toolbar.clear-filter-criteria",hidden$:C.getMenuHiddenObservable(t,u.UniverInstanceType.UNIVER_SHEET),disabled$:e.activeFilterModel$.pipe(S.switchMap(r=>{var s;return(s=r==null?void 0:r.hasCriteria$.pipe(S.map(n=>!n)))!=null?s:S.of(!0)}))}}function Ct(t){const e=t.get(c.SheetsFilterService);return{id:c.ReCalcSheetsFilterCommand.id,type:C.MenuItemType.BUTTON,title:"sheets-filter.toolbar.re-calc-filter-conditions",hidden$:C.getMenuHiddenObservable(t,u.UniverInstanceType.UNIVER_SHEET),disabled$:e.activeFilterModel$.pipe(S.switchMap(r=>{var s;return(s=r==null?void 0:r.hasCriteria$.pipe(S.map(n=>!n)))!=null?s:S.of(!0)}))}}const Ft={[C.RibbonDataGroup.ORGANIZATION]:{[c.SmartToggleSheetsFilterCommand.id]:{order:2,menuItemFactory:gt,[c.ClearSheetsFilterCriteriaCommand.id]:{order:0,menuItemFactory:St},[c.ReCalcSheetsFilterCommand.id]:{order:1,menuItemFactory:Ct}}}},V=16,Tt=new Path2D("M3.30363 3C2.79117 3 2.51457 3.60097 2.84788 3.99024L6.8 8.60593V12.5662C6.8 12.7184 6.8864 12.8575 7.02289 12.9249L8.76717 13.7863C8.96655 13.8847 9.2 13.7396 9.2 13.5173V8.60593L13.1521 3.99024C13.4854 3.60097 13.2088 3 12.6964 3H3.30363Z");class Le{static drawNoCriteria(e,r,s,n){e.save(),ie.Rect.drawWith(e,{radius:2,width:V,height:V,fill:n}),e.lineCap="square",e.strokeStyle=s,e.scale(r/V,r/V),e.beginPath(),e.lineWidth=1,e.lineCap="round",e.moveTo(3,4),e.lineTo(13,4),e.moveTo(4.5,8),e.lineTo(11.5,8),e.moveTo(6,12),e.lineTo(10,12),e.stroke(),e.restore()}static drawHasCriteria(e,r,s,n){e.save(),ie.Rect.drawWith(e,{radius:2,width:V,height:V,fill:n}),e.scale(r/V,r/V),e.fillStyle=s,e.fill(Tt),e.restore()}}var Et=Object.getOwnPropertyDescriptor,Ot=(t,e,r,s)=>{for(var n=s>1?void 0:s?Et(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(n=i(n)||n);return n},Te=(t,e)=>(r,s)=>e(r,s,t);const B=16,ce=1;let ye=class extends ie.Shape{constructor(e,r,s,n,l){super(e,r);v(this,"_cellWidth",0);v(this,"_cellHeight",0);v(this,"_filterParams");v(this,"_hovered",!1);this._contextService=s,this._commandService=n,this._themeService=l,this.setShapeProps(r),this.onPointerDown$.subscribeEvent(i=>this.onPointerDown(i)),this.onPointerEnter$.subscribeEvent(()=>this.onPointerEnter()),this.onPointerLeave$.subscribeEvent(()=>this.onPointerLeave())}setShapeProps(e){typeof e.cellHeight<"u"&&(this._cellHeight=e.cellHeight),typeof e.cellWidth<"u"&&(this._cellWidth=e.cellWidth),typeof e.filterParams<"u"&&(this._filterParams=e.filterParams),this.transformByState({width:e.width,height:e.height})}_draw(e){const r=this._cellHeight,s=this._cellWidth,n=B-s,l=B-r;e.save();const i=new Path2D;i.rect(n,l,s,r),e.clip(i);const{hasCriteria:o}=this._filterParams,a=this._themeService.getColorFromTheme("primary.600"),h=this._hovered?this._themeService.getColorFromTheme("gray.50"):"rgba(255, 255, 255, 1.0)";o?Le.drawHasCriteria(e,B,a,h):Le.drawNoCriteria(e,B,a,h),e.restore()}onPointerDown(e){if(e.button===2)return;const{col:r,unitId:s,subUnitId:n}=this._filterParams;this._contextService.getContextValue(J)||!this._commandService.hasCommand(se.id)||setTimeout(()=>{this._commandService.executeCommand(se.id,{unitId:s,subUnitId:n,col:r})},200)}onPointerEnter(){this._hovered=!0,this.makeDirty(!0)}onPointerLeave(){this._hovered=!1,this.makeDirty(!0)}};ye=Ot([Te(2,u.IContextService),Te(3,u.ICommandService),Te(4,u.Inject(u.ThemeService))],ye);var It=Object.getOwnPropertyDescriptor,Nt=(t,e,r,s)=>{for(var n=s>1?void 0:s?It(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(n=i(n)||n);return n},q=(t,e)=>(r,s)=>e(r,s,t);const yt=1e3,Rt=5e3;let Re=class extends u.RxDisposable{constructor(e,r,s,n,l,i,o,a){super();v(this,"_filterRangeShape",null);v(this,"_buttonRenderDisposable",null);v(this,"_filterButtonShapes",[]);this._context=e,this._injector=r,this._sheetSkeletonManagerService=s,this._sheetsFilterService=n,this._themeService=l,this._sheetInterceptorService=i,this._commandService=o,this._selectionRenderService=a,this._initRenderer()}dispose(){super.dispose(),this._disposeRendering()}_initRenderer(){this._sheetSkeletonManagerService.currentSkeleton$.pipe(S.switchMap(e=>{var o,a;if(!e)return S.of(null);const{unit:r,unitId:s}=this._context,n=((o=r.getActiveSheet())==null?void 0:o.getSheetId())||"",l=(a=this._sheetsFilterService.getFilterModel(s,n))!=null?a:void 0,i=()=>({unitId:s,worksheetId:n,filterModel:l,range:l==null?void 0:l.getRange(),skeleton:e.skeleton});return u.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(S.filter(([h])=>{var m;return h.type===u.CommandType.MUTATION&&((m=h.params)==null?void 0:m.unitId)===r.getUnitId()&&(c.FILTER_MUTATIONS.has(h.id)||h.id===O.SetRangeValuesMutation.id)}),S.throttleTime(20,void 0,{leading:!1,trailing:!0}),S.map(i),S.startWith(i()))}),S.takeUntil(this.dispose$)).subscribe(e=>{this._disposeRendering(),!(!e||!e.range)&&(this._renderRange(e.range,e.skeleton),this._renderButtons(e))})}_renderRange(e,r){const{scene:s}=this._context,{rowHeaderWidth:n,columnHeaderHeight:l}=r,i=this._filterRangeShape=new U.SelectionControl(s,yt,this._themeService,{rowHeaderWidth:n,columnHeaderHeight:l,enableAutoFill:!1,highlightHeader:!1}),o={range:e,primary:null,style:{fill:"rgba(0, 0, 0, 0.0)"}},a=U.attachSelectionWithCoord(o,r);i.updateRangeBySelectionWithCoord(a),i.setEvent(!1),s.makeDirty(!0)}_renderButtons(e){const{range:r,filterModel:s,unitId:n,skeleton:l,worksheetId:i}=e,{scene:o}=this._context;this._interceptCellContent(n,i,e.range);const{startColumn:a,endColumn:h,startRow:m}=r;for(let f=a;f<=h;f++){const T=`sheets-filter-button-${f}`,_=U.getCoordByCell(m,f,o,l),{startX:E,startY:F,endX:R,endY:I}=_,M=R-E,A=I-F;if(A<=ce||M<=ce)continue;const k=!!s.getFilterColumn(f),D=R-B-ce,oe=I-B-ce,ae={left:D,top:oe,height:B,width:B,zIndex:Rt,cellHeight:A,cellWidth:M,filterParams:{unitId:n,subUnitId:i,col:f,hasCriteria:k}},w=this._injector.createInstance(ye,T,ae);this._filterButtonShapes.push(w)}o.addObjects(this._filterButtonShapes),o.makeDirty()}_interceptCellContent(e,r,s){const{startRow:n,startColumn:l,endColumn:i}=s;this._buttonRenderDisposable=this._sheetInterceptorService.intercept(O.INTERCEPTOR_POINT.CELL_CONTENT,{effect:u.InterceptorEffectEnum.Style,handler:(o,a,h)=>{const{row:m,col:f,unitId:T,subUnitId:_}=a;return T!==e||_!==r||m!==n||f<l||f>i||((!o||o===a.rawData)&&(o={...a.rawData}),o.fontRenderExtension={...o==null?void 0:o.fontRenderExtension,rightOffset:B}),h(o)},priority:10})}_disposeRendering(){var e,r;(e=this._filterRangeShape)==null||e.dispose(),this._filterButtonShapes.forEach(s=>s.dispose()),(r=this._buttonRenderDisposable)==null||r.dispose(),this._filterRangeShape=null,this._buttonRenderDisposable=null,this._filterButtonShapes=[]}};Re=Nt([q(1,u.Inject(u.Injector)),q(2,u.Inject(U.SheetSkeletonManagerService)),q(3,u.Inject(c.SheetsFilterService)),q(4,u.Inject(u.ThemeService)),q(5,u.Inject(O.SheetInterceptorService)),q(6,u.ICommandService),q(7,U.ISheetSelectionRenderService)],Re);var Pt=Object.getOwnPropertyDescriptor,bt=(t,e,r,s)=>{for(var n=s>1?void 0:s?Pt(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(n=i(n)||n);return n},Ue=(t,e)=>(r,s)=>e(r,s,t);let ne=class extends u.RxDisposable{constructor(t,e){super(),this._renderManagerService=t,this._sheetsRenderService=e,[c.SetSheetsFilterRangeMutation,c.SetSheetsFilterCriteriaMutation,c.RemoveSheetsFilterMutation,c.ReCalcSheetsFilterMutation].forEach(r=>this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(r.id))),this.disposeWithMe(this._renderManagerService.registerRenderModule(u.UniverInstanceType.UNIVER_SHEET,[Re]))}};ne=bt([Ue(0,ie.IRenderManagerService),Ue(1,u.Inject(U.SheetsRenderService))],ne);const At={id:c.SmartToggleSheetsFilterCommand.id,binding:C.KeyCode.L|C.MetaKeys.CTRL_COMMAND|C.MetaKeys.SHIFT,description:"sheets-filter.shortcut.smart-toggle-filter",preconditions:U.whenSheetEditorFocused,group:"4_sheet-edit"};var Mt=Object.getOwnPropertyDescriptor,wt=(t,e,r,s)=>{for(var n=s>1?void 0:s?Mt(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(n=i(n)||n);return n},L=(t,e)=>(r,s)=>e(r,s,t);const $e="FILTER_PANEL_POPUP";let ve=class extends ne{constructor(e,r,s,n,l,i,o,a,h,m,f,T,_){super(_,T);v(this,"_popupDisposable");this._injector=e,this._componentManager=r,this._sheetsFilterPanelService=s,this._sheetCanvasPopupService=n,this._sheetsFilterService=l,this._localeService=i,this._shortcutService=o,this._commandService=a,this._menuManagerService=h,this._contextService=m,this._messageService=f,this._initCommands(),this._initShortcuts(),this._initMenuItems(),this._initUI()}dispose(){super.dispose(),this._closeFilterPopup()}_initShortcuts(){[At].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_initCommands(){[c.SmartToggleSheetsFilterCommand,c.RemoveSheetFilterCommand,c.SetSheetFilterRangeCommand,c.SetSheetsFilterCriteriaCommand,c.ClearSheetsFilterCriteriaCommand,c.ReCalcSheetsFilterCommand,Ae,se,z].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initMenuItems(){this._menuManagerService.mergeMenu(Ft)}_initUI(){[[$e,_t],["FilterIcon",Qe]].forEach(([e,r])=>{this.disposeWithMe(this._componentManager.register(e,r))}),this.disposeWithMe(this._contextService.subscribeContextValue$(J).pipe(S.distinctUntilChanged()).subscribe(e=>{e?this._openFilterPopup():this._closeFilterPopup()})),this.disposeWithMe(this._sheetsFilterService.errorMsg$.subscribe(e=>{e&&this._messageService.show({type:y.MessageType.Error,content:this._localeService.t(e)})}))}_openFilterPopup(){const e=this._sheetsFilterPanelService.filterModel;if(!e)throw new Error("[SheetsFilterUIController]: no filter model when opening filter popup!");const r=e.getRange(),s=this._sheetsFilterPanelService.col,{startRow:n}=r;this._popupDisposable=this._sheetCanvasPopupService.attachPopupToCell(n,s,{componentKey:$e,direction:"horizontal",onClickOutside:()=>this._commandService.syncExecuteCommand(z.id),offset:[5,0]})}_closeFilterPopup(){var e;(e=this._popupDisposable)==null||e.dispose(),this._popupDisposable=null}};ve=wt([L(0,u.Inject(u.Injector)),L(1,u.Inject(C.ComponentManager)),L(2,u.Inject(Q)),L(3,u.Inject(U.SheetCanvasPopManagerService)),L(4,u.Inject(c.SheetsFilterService)),L(5,u.Inject(u.LocaleService)),L(6,C.IShortcutService),L(7,u.ICommandService),L(8,C.IMenuManagerService),L(9,u.IContextService),L(10,C.IMessageService),L(11,u.Inject(U.SheetsRenderService)),L(12,ie.IRenderManagerService)],ve);var Lt=Object.defineProperty,Ut=Object.getOwnPropertyDescriptor,$t=(t,e,r)=>e in t?Lt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xt=(t,e,r,s)=>{for(var n=s>1?void 0:s?Ut(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(n=i(n)||n);return n},Ee=(t,e)=>(r,s)=>e(r,s,t),Ge=(t,e,r)=>$t(t,typeof e!="symbol"?e+"":e,r);const kt="SHEET_FILTER_UI_PLUGIN";exports.UniverSheetsFilterUIPlugin=class extends u.Plugin{constructor(e=he,r,s,n){super(),this._config=e,this._injector=r,this._configService=s,this._rpcChannelService=n;const{menu:l,...i}=u.merge({},he,this._config);l&&this._configService.setConfig("menu",l,{merge:!0}),this._configService.setConfig(De,i)}onStarting(){u.registerDependencies(this._injector,[[Q],[ee],[ve]]),this._config.useRemoteFilterValuesGenerator&&this._rpcChannelService&&this._injector.add([me,{useFactory:()=>ge.toModule(this._rpcChannelService.requestChannel(Pe))}])}onReady(){u.touchDependencies(this._injector,[[ee]])}onRendered(){u.touchDependencies(this._injector,[[ve]])}};Ge(exports.UniverSheetsFilterUIPlugin,"type",u.UniverInstanceType.UNIVER_SHEET);Ge(exports.UniverSheetsFilterUIPlugin,"pluginName",kt);exports.UniverSheetsFilterUIPlugin=xt([u.DependentOn(c.UniverSheetsFilterPlugin),Ee(1,u.Inject(u.Injector)),Ee(2,u.IConfigService),Ee(3,u.Optional(ge.IRPCChannelService))],exports.UniverSheetsFilterUIPlugin);var Dt=Object.defineProperty,Ht=Object.getOwnPropertyDescriptor,jt=(t,e,r)=>e in t?Dt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Bt=(t,e,r,s)=>{for(var n=s>1?void 0:s?Ht(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(n=i(n)||n);return n},xe=(t,e)=>(r,s)=>e(r,s,t),Ye=(t,e,r)=>jt(t,typeof e!="symbol"?e+"":e,r);const Wt="SHEET_FILTER_UI_PLUGIN";exports.UniverSheetsFilterMobileUIPlugin=class extends u.Plugin{constructor(e=he,r,s){super(),this._config=e,this._injector=r,this._configService=s;const{menu:n,...l}=u.merge({},he,this._config);n&&this._configService.setConfig("menu",n,{merge:!0}),this._configService.setConfig(De,l)}onStarting(){[[ee],[ne]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(ee)}onRendered(){this._injector.get(ne)}};Ye(exports.UniverSheetsFilterMobileUIPlugin,"type",u.UniverInstanceType.UNIVER_SHEET);Ye(exports.UniverSheetsFilterMobileUIPlugin,"pluginName",Wt);exports.UniverSheetsFilterMobileUIPlugin=Bt([u.DependentOn(c.UniverSheetsFilterPlugin),xe(1,u.Inject(u.Injector)),xe(2,u.IConfigService)],exports.UniverSheetsFilterMobileUIPlugin);var Vt=Object.getOwnPropertyDescriptor,Qt=(t,e,r,s)=>{for(var n=s>1?void 0:s?Vt(e,r):e,l=t.length-1,i;l>=0;l--)(i=t[l])&&(n=i(n)||n);return n},ke=(t,e)=>(r,s)=>e(r,s,t),ue;exports.UniverSheetsFilterUIWorkerPlugin=(ue=class extends u.Plugin{constructor(e,r,s){super(),this._config=e,this._injector=r,this._rpcChannelService=s}onStarting(){[[me,{useClass:Ie}]].forEach(e=>this._injector.add(e))}onReady(){this._rpcChannelService.registerChannel(Pe,ge.fromModule(this._injector.get(me)))}},v(ue,"type",u.UniverInstanceType.UNIVER_SHEET),v(ue,"pluginName","SHEET_FILTER_UI_WORKER_PLUGIN"),ue);exports.UniverSheetsFilterUIWorkerPlugin=Qt([ke(1,u.Inject(u.Injector)),ke(2,ge.IRPCChannelService)],exports.UniverSheetsFilterUIWorkerPlugin);exports.ChangeFilterByOperation=Ae;exports.CloseFilterPanelOperation=z;exports.OpenFilterPanelOperation=se;