@univerjs/sheets-sort-ui 0.20.1 → 0.21.0

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.
Files changed (41) hide show
  1. package/lib/cjs/index.js +990 -1
  2. package/lib/cjs/locale/ca-ES.js +33 -1
  3. package/lib/cjs/locale/en-US.js +48 -1
  4. package/lib/cjs/locale/es-ES.js +33 -1
  5. package/lib/cjs/locale/fa-IR.js +33 -1
  6. package/lib/cjs/locale/fr-FR.js +33 -1
  7. package/lib/cjs/locale/ja-JP.js +33 -1
  8. package/lib/cjs/locale/ko-KR.js +33 -1
  9. package/lib/cjs/locale/ru-RU.js +33 -1
  10. package/lib/cjs/locale/sk-SK.js +33 -1
  11. package/lib/cjs/locale/vi-VN.js +33 -1
  12. package/lib/cjs/locale/zh-CN.js +33 -1
  13. package/lib/cjs/locale/zh-TW.js +33 -1
  14. package/lib/es/index.js +974 -1
  15. package/lib/es/locale/ca-ES.js +32 -1
  16. package/lib/es/locale/en-US.js +47 -1
  17. package/lib/es/locale/es-ES.js +32 -1
  18. package/lib/es/locale/fa-IR.js +32 -1
  19. package/lib/es/locale/fr-FR.js +32 -1
  20. package/lib/es/locale/ja-JP.js +32 -1
  21. package/lib/es/locale/ko-KR.js +32 -1
  22. package/lib/es/locale/ru-RU.js +32 -1
  23. package/lib/es/locale/sk-SK.js +32 -1
  24. package/lib/es/locale/vi-VN.js +32 -1
  25. package/lib/es/locale/zh-CN.js +32 -1
  26. package/lib/es/locale/zh-TW.js +32 -1
  27. package/lib/index.js +974 -1
  28. package/lib/locale/ca-ES.js +32 -1
  29. package/lib/locale/en-US.js +47 -1
  30. package/lib/locale/es-ES.js +32 -1
  31. package/lib/locale/fa-IR.js +32 -1
  32. package/lib/locale/fr-FR.js +32 -1
  33. package/lib/locale/ja-JP.js +32 -1
  34. package/lib/locale/ko-KR.js +32 -1
  35. package/lib/locale/ru-RU.js +32 -1
  36. package/lib/locale/sk-SK.js +32 -1
  37. package/lib/locale/vi-VN.js +32 -1
  38. package/lib/locale/zh-CN.js +32 -1
  39. package/lib/locale/zh-TW.js +32 -1
  40. package/lib/umd/index.js +1 -1
  41. package/package.json +12 -12
package/lib/es/index.js CHANGED
@@ -1 +1,974 @@
1
- import{CommandType as e,DependentOn as t,Disposable as n,ICommandService as r,IConfigService as i,IConfirmService as a,IUniverInstanceService as o,Inject as s,Injector as c,LocaleService as l,LocaleType as u,Plugin as d,RxDisposable as f,Tools as p,UniverInstanceType as m,merge as h,throttle as ee}from"@univerjs/core";import{RangeProtectionPermissionEditPoint as g,SetSelectionsOperation as te,SheetsSelectionsService as ne,WorkbookEditablePermission as _,WorksheetEditPermission as v,WorksheetSortPermission as y,expandToContinuousRange as b,getPrimaryForRange as re,getSheetCommandTarget as ie}from"@univerjs/sheets";import{SheetsSortService as ae,SortRangeCommand as oe,SortType as x,UniverSheetsSortPlugin as se}from"@univerjs/sheets-sort";import{BehaviorSubject as ce,takeUntil as le}from"rxjs";import{Button as S,ButtonGroup as ue,Checkbox as de,DraggableList as fe,Dropdown as pe,Radio as C,RadioGroup as me,clsx as he,scrollbarClassName as ge}from"@univerjs/design";import{ComponentManager as _e,ContextMenuGroup as ve,ContextMenuPosition as ye,IDialogService as be,ILayoutService as xe,IMenuManagerService as Se,IUIPartsService as Ce,MenuItemType as w,RibbonDataGroup as we,connectInjector as Te,getMenuHiddenObservable as Ee,useDependency as T,useObservable as De}from"@univerjs/ui";import{useCallback as E,useEffect as Oe,useRef as ke,useState as D}from"react";import{jsx as O,jsxs as k}from"react/jsx-runtime";import{serializeRange as Ae}from"@univerjs/engine-formula";import{AscendingIcon as je,CheckMarkIcon as Me,CustomSortIcon as Ne,DeleteEmptyIcon as Pe,DescendingIcon as Fe,ExpandAscendingIcon as Ie,ExpandDescendingIcon as Le,IncreaseIcon as Re,MoreDownIcon as ze,SequenceIcon as Be}from"@univerjs/icons";import{SheetsRenderService as Ve,SheetsUIPart as He,getCurrentExclusiveRangeInterest$ as Ue,getCurrentRangeDisable$ as A}from"@univerjs/sheets-ui";const We=e=>{let[t,n]=D(`0`),r=T(l);return k(`div`,{className:`univer-text-sm`,children:[O(`div`,{className:`extend-confirm-desc`,children:r.t(`sheets-sort.dialog.sort-reminder-desc`)}),k(me,{className:`univer-mt-4`,value:t,direction:`vertical`,onChange:t=>{n(t),e.onChange(t)},children:[O(C,{value:`0`,children:r.t(`sheets-sort.dialog.sort-reminder-no`)}),O(C,{value:`1`,children:r.t(`sheets-sort.dialog.sort-reminder-ext`)})]})]})};function j(e){"@babel/helpers - typeof";return j=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},j(e)}function Ge(e,t){if(j(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(j(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ke(e){var t=Ge(e,`string`);return j(t)==`symbol`?t:t+``}function M(e,t,n){return(t=Ke(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function N(e,t){return function(n,r){t(n,r,e)}}function P(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let F=function(e){return e.KEEP=`keep`,e.EXTEND=`extend`,e.CANCEL=`cancel`,e}({});const I={MERGE_ERROR:`sheets-sort.error.merge-size`,EMPTY_ERROR:`sheets-sort.error.empty`,SINGLE_ERROR:`sheets-sort.error.single`,FORMULA_ARRAY:`sheets-sort.error.formula-array`};let L=class extends n{constructor(e,t,n,r,i,a){super(),this._univerInstanceService=e,this._confirmService=t,this._selectionManagerService=n,this._sheetsSortService=r,this._localeService=i,this._commandService=a,M(this,`_customSortState$`,new ce(null)),M(this,`customSortState$`,this._customSortState$.asObservable())}async triggerSortDirectly(e,t,n){let r=n||await this._detectSortLocation(t);if(!r||!this._check(r))return!1;let i={orderRules:[{type:e?x.ASC:x.DESC,colIndex:r.colIndex}],range:r.range};return this._sheetsSortService.applySort(i,r.unitId,r.subUnitId),!0}async triggerSortCustomize(){let e=await this._detectSortLocation();return!e||!this._check(e)?!1:(this.showCustomSortPanel(e),!0)}customSortState(){return this._customSortState$.getValue()}getTitles(e){var t,n;let r=(t=this.customSortState())==null?void 0:t.location;if(!r)return[];let{unitId:i,subUnitId:a,range:o}=r,s=(n=this._univerInstanceService.getUnit(i))==null?void 0:n.getSheetBySheetId(a);if(!s)return[];let c=qe(this._localeService);return Array.from({length:o.endColumn-o.startColumn+1},(t,n)=>{var r;let i=(r=s.getCell(o.startRow,n+o.startColumn))==null?void 0:r.v;return{index:n+o.startColumn,label:e?`${i==null?c(n+o.startColumn):i}`:c(n+o.startColumn)}})}setSelection(e,t,n){var r;let i=(r=this._univerInstanceService.getUnit(e))==null?void 0:r.getSheetBySheetId(t);if(!i)return;let a={unitId:e,subUnitId:t,selections:[{range:n,primary:re(n,i),style:null}]};this._commandService.executeCommand(te.id,a)}async showCheckError(e){return await this._confirmService.confirm({id:`sort-range-check-error`,title:{title:this._localeService.t(`info.tooltip`)},children:{title:O(`div`,{children:this._localeService.t(e)})},cancelText:this._localeService.t(`sheets-sort.dialog.cancel`),confirmText:this._localeService.t(`sheets-sort.dialog.confirm`)})}async showExtendConfirm(){let e=!1;return await this._confirmService.confirm({id:`extend-sort-range-dialog`,title:{title:this._localeService.t(`sheets-sort.dialog.sort-reminder`)},children:{title:O(We,{onChange:t=>{e=t===`1`}})},width:400,cancelText:this._localeService.t(`sheets-sort.dialog.cancel`),confirmText:this._localeService.t(`sheets-sort.dialog.confirm`)})?e?F.EXTEND:F.KEEP:F.CANCEL}showCustomSortPanel(e){this._customSortState$.next({location:e,show:!0})}closeCustomSortPanel(){this._customSortState$.next({show:!1})}_check(e){return this._sheetsSortService.singleCheck(e)?this._sheetsSortService.mergeCheck(e)?this._sheetsSortService.formulaCheck(e)?this._sheetsSortService.emptyCheck(e)?!0:(this.showCheckError(I.EMPTY_ERROR),!1):(this.showCheckError(I.FORMULA_ARRAY),!1):(this.showCheckError(I.MERGE_ERROR),!1):(this.showCheckError(I.SINGLE_ERROR),!1)}async _detectSortLocation(e){let t=this._univerInstanceService.getCurrentUnitForType(m.UNIVER_SHEET),n=t.getActiveSheet(),r=t.getUnitId(),i=n.getSheetId(),a=this._selectionManagerService.getCurrentLastSelection();if(!a)return null;let o;if(e===!0)o=b(a.range,{up:!0,down:!0,left:!0,right:!0},n),this.setSelection(r,i,o);else if(e===!1)o=a.range;else{let e=await this.showExtendConfirm();if(e===F.CANCEL)return null;e===F.KEEP?o=a.range:(o=b(a.range,{up:!0,down:!0,left:!0,right:!0},n),this.setSelection(r,i,o))}return{range:o,unitId:r,subUnitId:i,colIndex:a.primary.actualColumn}}};L=P([N(0,o),N(1,a),N(2,s(ne)),N(3,s(ae)),N(4,s(l)),N(5,r)],L);function qe(e){return t=>{let n=p.chatAtABC(t);switch(e.getCurrentLocale()){case u.ZH_CN:return`"${n}"列`;case u.EN_US:return`Column "${n}"`;default:return`Column "${n}"`}}}const R={id:`sheet.command.sort-range-asc`,type:e.COMMAND,handler:async e=>await e.get(L).triggerSortDirectly(!0,!1)},z={id:`sheet.command.sort-range-asc-ext`,type:e.COMMAND,handler:async e=>await e.get(L).triggerSortDirectly(!0,!0)},B={id:`sheet.command.sort-range-desc`,type:e.COMMAND,handler:async e=>await e.get(L).triggerSortDirectly(!1,!1)},V={id:`sheet.command.sort-range-desc-ext`,type:e.COMMAND,handler:async e=>await e.get(L).triggerSortDirectly(!1,!0)},H={id:`sheet.command.sort-range-custom`,type:e.COMMAND,handler:async e=>await e.get(L).triggerSortCustomize()},U={id:`sheet.command.sort-range-asc-ctx`,type:e.COMMAND,handler:async e=>await e.get(L).triggerSortDirectly(!0,!1)},W={id:`sheet.command.sort-range-asc-ext-ctx`,type:e.COMMAND,handler:async e=>await e.get(L).triggerSortDirectly(!0,!0)},G={id:`sheet.command.sort-range-desc-ctx`,type:e.COMMAND,handler:async e=>await e.get(L).triggerSortDirectly(!1,!1)},K={id:`sheet.command.sort-range-desc-ext-ctx`,type:e.COMMAND,handler:async e=>await e.get(L).triggerSortDirectly(!1,!0)},q={id:`sheet.command.sort-range-custom-ctx`,type:e.COMMAND,handler:async e=>await e.get(L).triggerSortCustomize()};var Je=`@univerjs/sheets-sort-ui`,Ye=`0.20.1`;const Xe=`sheets-sort-ui.config`;Symbol(Xe);const Ze={},Qe=`sheet.menu.sheets-sort`,$e=`sheet.menu.sheets-sort-ctx`,J=`AscendingIcon`,Y=`ExpandAscendingIcon`,X=`DescendingIcon`,Z=`ExpandDescendingIcon`,et=`CustomSortIcon`;function tt(e){return{id:Qe,type:w.SUBITEMS,icon:J,tooltip:`sheets-sort.general.sort`,hidden$:Ee(e,m.UNIVER_SHEET),disabled$:A(e,{workbookTypes:[_],worksheetTypes:[y,v],rangeTypes:[g]})}}function nt(e){return{id:R.id,icon:J,title:`sheets-sort.general.sort-asc-cur`,type:w.BUTTON,hidden$:Ue(e)}}function rt(e){return{id:z.id,title:`sheets-sort.general.sort-asc-ext`,icon:Y,type:w.BUTTON}}function it(e){return{id:B.id,title:`sheets-sort.general.sort-desc-cur`,icon:X,type:w.BUTTON}}function at(e){return{id:V.id,title:`sheets-sort.general.sort-desc-ext`,icon:Z,type:w.BUTTON}}function ot(e){return{id:H.id,title:`sheets-sort.general.sort-custom`,type:w.BUTTON,icon:et}}function st(e){return{id:$e,title:`sheets-sort.general.sort`,type:w.SUBITEMS,icon:J,hidden$:Ee(e,m.UNIVER_SHEET),disabled$:A(e,{workbookTypes:[_],worksheetTypes:[y,v],rangeTypes:[g]})}}function ct(e){return{id:U.id,title:`sheets-sort.general.sort-asc-cur`,type:w.BUTTON,icon:J,disabled$:A(e,{workbookTypes:[_],worksheetTypes:[y,v],rangeTypes:[g]})}}function lt(e){return{id:W.id,title:`sheets-sort.general.sort-asc-ext`,type:w.BUTTON,icon:Y,disabled$:A(e,{workbookTypes:[_],worksheetTypes:[y,v],rangeTypes:[g]})}}function ut(e){return{id:G.id,title:`sheets-sort.general.sort-desc-cur`,type:w.BUTTON,icon:X,disabled$:A(e,{workbookTypes:[_],worksheetTypes:[y,v],rangeTypes:[g]})}}function dt(e){return{id:K.id,title:`sheets-sort.general.sort-desc-ext`,type:w.BUTTON,icon:Z,disabled$:A(e,{workbookTypes:[_],worksheetTypes:[y,v],rangeTypes:[g]})}}function ft(e){return{id:q.id,title:`sheets-sort.general.sort-custom`,type:w.BUTTON,icon:et,disabled$:A(e,{workbookTypes:[_],worksheetTypes:[y,v],rangeTypes:[g]})}}const pt={[we.ORGANIZATION]:{[Qe]:{order:3,menuItemFactory:tt,[R.id]:{order:0,menuItemFactory:nt},[z.id]:{order:1,menuItemFactory:rt},[B.id]:{order:2,menuItemFactory:it},[V.id]:{order:3,menuItemFactory:at},[H.id]:{order:4,menuItemFactory:ot}}},[ye.MAIN_AREA]:{[ve.DATA]:{[$e]:{order:0,menuItemFactory:st,[U.id]:{order:0,menuItemFactory:ct},[W.id]:{order:1,menuItemFactory:lt},[G.id]:{order:2,menuItemFactory:ut},[K.id]:{order:3,menuItemFactory:dt},[q.id]:{order:4,menuItemFactory:ft}}}}};function mt(){let e=De(T(L).customSortState$);return!e||!e.location?null:O(ht,{state:e})}function ht({state:e}){let t=T(ae),n=T(l),r=T(L),[i,a]=D(!1),[o,s]=D(0),c=ke(null),{range:u,unitId:d,subUnitId:f}=e.location,p=r.getTitles(i),[m,h]=D([{type:x.ASC,colIndex:u.startColumn}]),g=E((e,t)=>{let n=[...m];t===null?n.splice(e,1):n[e]=t,h(n)},[m]),te=E(ee(()=>{let e=[...m],t=_t(u,m);t!==null&&(e.push({type:x.ASC,colIndex:t}),h(e))},200),[m,u]),ne=E((e,n)=>{t.applySort({range:u,orderRules:e,hasTitle:n}),r.closeCustomSortPanel()},[t,r,u]),_=E(()=>{r.closeCustomSortPanel()},[r]),v=E(e=>{a(e),e?r.setSelection(d,f,{...u,startRow:u.startRow+1}):r.setSelection(d,f,u)},[r,u,f,d]);Oe(()=>{c.current&&m.length>5&&(c.current.scrollTop=c.current.scrollHeight)},[m]);let y=m.length<p.length,b=m.map(e=>({...e,id:`${e.colIndex}`}));return k(`div`,{children:[k(`div`,{onMouseDown:e=>{e.stopPropagation()},children:[k(`div`,{className:`univer-mb-2 univer-flex univer-items-center univer-justify-between`,children:[O(de,{checked:i,onChange:e=>v(!!e),children:n.t(`sheets-sort.dialog.first-row-check`)}),y?k(`div`,{className:`univer-flex univer-cursor-pointer univer-select-none univer-items-center univer-text-base`,onClick:te,children:[O(Re,{}),O(`span`,{className:`univer-ml-1.5`,children:n.t(`sheets-sort.dialog.add-condition`)})]}):k(`div`,{className:`univer-flex univer-cursor-pointer univer-select-none univer-items-center univer-text-base univer-text-primary-500 disabled:univer-cursor-not-allowed disabled:univer-divide-opacity-30 disabled:univer-text-gray-800`,children:[O(Re,{}),O(`span`,{className:`univer-ml-1.5 univer-text-xs`,children:n.t(`sheets-sort.dialog.add-condition`)})]})]}),O(`div`,{ref:c,className:he(`univer-max-h-[310px] univer-overflow-y-auto univer-overflow-x-hidden`,ge),onScroll:e=>{let t=e.currentTarget.scrollTop;s(t)},children:O(fe,{list:b,onListChange:h,idKey:`id`,draggableHandle:`[data-u-comp=sort-panel-item-handler]`,itemRender:e=>O(gt,{titles:p,list:b,item:e,onChange:(e,t)=>g(t,e),scrollPosition:o}),rowHeight:32,margin:[0,12]})})]}),k(`div`,{className:`univer-mt-5 univer-flex univer-justify-end`,children:[O(S,{className:`univer-ml-3`,onClick:()=>_(),children:n.t(`sheets-sort.dialog.cancel`)}),O(S,{className:`univer-ml-3`,variant:`primary`,onClick:()=>ne(m,i),children:n.t(`sheets-sort.dialog.confirm`)})]})]})}function gt(e){var t;let{list:n,item:r,titles:i,onChange:a,scrollPosition:o}=e,s=T(l),c=i.filter(e=>!n.some(t=>t.colIndex===e.index)||e.index===r.colIndex),u=n.findIndex(e=>e.colIndex===r.colIndex),d=E(e=>{a({...r,colIndex:e.index},u),p(!1)},[u,r,a]),[f,p]=D(!1),m=e=>{p(e)};Oe(()=>{p(!1)},[o]);let h=n.length>1,ee=(t=i.find(e=>e.index===r.colIndex))==null?void 0:t.label;return k(`div`,{className:`univer-grid univer-grid-flow-col univer-grid-cols-2 univer-items-center univer-gap-2`,children:[k(`div`,{className:`univer-flex univer-items-center`,children:[O(`div`,{"data-u-comp":`sort-panel-item-handler`,className:`univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-text-base univer-text-gray-700`,children:O(Be,{})}),O(pe,{overlay:O(`ul`,{className:he(`univer-my-0 univer-box-border univer-grid univer-max-h-[310px] univer-w-[--radix-popper-anchor-width] univer-items-center univer-gap-1 univer-overflow-y-auto univer-overflow-x-hidden univer-rounded-lg univer-border univer-bg-white univer-p-1 univer-text-base univer-shadow-lg`,ge),children:c.map(e=>k(`li`,{onClick:()=>d(e),className:`univer-relative univer-box-border univer-flex univer-h-7 univer-cursor-pointer univer-list-none univer-items-center univer-justify-between univer-rounded univer-px-2 univer-text-sm univer-transition-all hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700`,children:[O(`span`,{className:`univer-max-w-[220px] univer-truncate`,children:e.label}),O(`span`,{children:e.index===r.colIndex&&O(Me,{})})]},e.index))}),open:f,onOpenChange:m,children:k(`div`,{className:he(`univer-ml-2 univer-flex univer-w-full univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-md univer-py-1.5 univer-text-sm univer-text-gray-900 dark:!univer-text-white`),children:[O(`span`,{className:`univer-max-w-[220px] univer-truncate`,children:ee}),O(ze,{})]})})]}),k(`div`,{className:`univer-flex univer-items-center univer-justify-end univer-gap-2`,children:[k(me,{value:r.type,onChange:e=>{a({...r,type:e},u)},children:[O(C,{value:x.ASC,children:s.t(`sheets-sort.general.sort-asc`)}),O(C,{value:x.DESC,children:s.t(`sheets-sort.general.sort-desc`)})]}),O(`a`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-transition-colors hover:univer-text-red-500`,onClick:()=>a(null,u),children:!h&&O(Pe,{})})]})]})}function _t(e,t){let{startColumn:n,endColumn:r}=e,i=new Set(t.map(e=>e==null?void 0:e.colIndex));for(let e=n;e<=r;e++)if(!i.has(e))return e;return null}function vt(e){let{range:t,colIndex:n,onClose:r}=e,i=T(L),a=T(o),s=T(l),c=E(e=>{let{unitId:o,subUnitId:s}=ie(a)||{};if(t&&o&&s){let r={...t,startRow:t.startRow+1};i.triggerSortDirectly(e,!1,{unitId:o,subUnitId:s,range:r,colIndex:n})}else throw Error(`Cannot find the target to sort. unitId: ${o}, subUnitId: ${s}, range: ${t}, colIndex: ${n}`);r()},[t,n,i,a,r]);return k(ue,{className:`univer-mb-3 univer-w-full univer-grid-cols-2`,children:[k(S,{onClick:()=>c(!0),children:[O(je,{}),s.t(`sheets-sort.general.sort-asc`)]}),k(S,{onClick:()=>c(!1),children:[O(Fe,{}),s.t(`sheets-sort.general.sort-desc`)]})]})}const yt=`custom-sort-dialog`;let Q=class extends f{constructor(e,t,n,r,i,a,o,s,c,l){super(),this._commandService=e,this._menuManagerService=t,this._dialogService=n,this._layoutService=r,this._uiPartsService=i,this._sheetRenderService=a,this._localeService=o,this._sheetsSortUIService=s,this._injector=c,this._componentManager=l,this._initCommands(),this._initMenu(),this._initUI()}_initMenu(){this._menuManagerService.mergeMenu(pt)}_initCommands(){[R,z,B,V,H,U,W,G,K,q].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e))),this.disposeWithMe(this._sheetRenderService.registerSkeletonChangingMutations(oe.id))}_initUI(){this.disposeWithMe(this._uiPartsService.registerComponent(He.FILTER_PANEL_EMBED_POINT,()=>Te(vt,this._injector))),[[`CustomSortPanel`,mt],[J,je],[Y,Ie],[X,Fe],[Z,Le],[et,Ne]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))}),this._sheetsSortUIService.customSortState$.pipe(le(this.dispose$)).subscribe(e=>{e&&e.show&&e.location?this._openCustomSortPanel(e.location):e&&!(e!=null&&e.show)&&this._closePanel()})}_openCustomSortPanel(e){this._dialogService.open({id:yt,draggable:!0,width:560,title:{title:`${this._localeService.t(`sheets-sort.general.sort-custom`)}: ${Ae(e.range)}`},children:{label:`CustomSortPanel`},destroyOnClose:!0,defaultPosition:bt(),preservePositionOnDestroy:!1,onClose:()=>this._closePanel(),mask:!0})}_closePanel(){this._dialogService.close(yt),queueMicrotask(()=>this._layoutService.focus())}};Q=P([N(0,r),N(1,Se),N(2,be),N(3,xe),N(4,Ce),N(5,s(Ve)),N(6,s(l)),N(7,s(L)),N(8,s(c)),N(9,s(_e))],Q);function bt(){return{x:(window.innerWidth-560)/2,y:128}}let $=class extends d{constructor(e=Ze,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=h({},Ze,this._config);this._configService.setConfig(Xe,r)}onStarting(){[[L],[Q]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(Q)}};M($,`type`,m.UNIVER_SHEET),M($,`pluginName`,`SHEET_SORT_UI_PLUGIN`),M($,`packageName`,Je),M($,`version`,Ye),$=P([t(se),N(1,s(c)),N(2,i)],$);export{R as SortRangeAscCommand,z as SortRangeAscExtCommand,W as SortRangeAscExtInCtxMenuCommand,U as SortRangeAscInCtxMenuCommand,H as SortRangeCustomCommand,q as SortRangeCustomInCtxMenuCommand,B as SortRangeDescCommand,V as SortRangeDescExtCommand,K as SortRangeDescExtInCtxMenuCommand,G as SortRangeDescInCtxMenuCommand,$ as UniverSheetsSortUIPlugin};
1
+ import { CommandType, DependentOn, Disposable, ICommandService, IConfigService, IConfirmService, IUniverInstanceService, Inject, Injector, LocaleService, LocaleType, Plugin, RxDisposable, Tools, UniverInstanceType, merge, throttle } from "@univerjs/core";
2
+ import { RangeProtectionPermissionEditPoint, SetSelectionsOperation, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSortPermission, expandToContinuousRange, getPrimaryForRange, getSheetCommandTarget } from "@univerjs/sheets";
3
+ import { SheetsSortService, SortRangeCommand, SortType, UniverSheetsSortPlugin } from "@univerjs/sheets-sort";
4
+ import { BehaviorSubject, takeUntil } from "rxjs";
5
+ import { Button, ButtonGroup, Checkbox, DraggableList, Dropdown, Radio, RadioGroup, clsx, scrollbarClassName } from "@univerjs/design";
6
+ import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IDialogService, ILayoutService, IMenuManagerService, IUIPartsService, MenuItemType, RibbonDataGroup, connectInjector, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
7
+ import { useCallback, useEffect, useRef, useState } from "react";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ import { serializeRange } from "@univerjs/engine-formula";
10
+ import { AscendingIcon, CheckMarkIcon, CustomSortIcon, DeleteEmptyIcon, DescendingIcon, ExpandAscendingIcon, ExpandDescendingIcon, IncreaseIcon, MoreDownIcon, SequenceIcon } from "@univerjs/icons";
11
+ import { SheetsRenderService, SheetsUIPart, getCurrentExclusiveRangeInterest$, getCurrentRangeDisable$ } from "@univerjs/sheets-ui";
12
+
13
+ //#region src/views/ExtendConfirm.tsx
14
+ /**
15
+ * Copyright 2023-present DreamNum Co., Ltd.
16
+ *
17
+ * Licensed under the Apache License, Version 2.0 (the "License");
18
+ * you may not use this file except in compliance with the License.
19
+ * You may obtain a copy of the License at
20
+ *
21
+ * http://www.apache.org/licenses/LICENSE-2.0
22
+ *
23
+ * Unless required by applicable law or agreed to in writing, software
24
+ * distributed under the License is distributed on an "AS IS" BASIS,
25
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26
+ * See the License for the specific language governing permissions and
27
+ * limitations under the License.
28
+ */
29
+ const ExtendConfirm = (props) => {
30
+ const [extend, setExtend] = useState("0");
31
+ const localeService = useDependency(LocaleService);
32
+ return /* @__PURE__ */ jsxs("div", {
33
+ className: "univer-text-sm",
34
+ children: [/* @__PURE__ */ jsx("div", {
35
+ className: "extend-confirm-desc",
36
+ children: localeService.t("sheets-sort.dialog.sort-reminder-desc")
37
+ }), /* @__PURE__ */ jsxs(RadioGroup, {
38
+ className: "univer-mt-4",
39
+ value: extend,
40
+ direction: "vertical",
41
+ onChange: (value) => {
42
+ setExtend(value);
43
+ props.onChange(value);
44
+ },
45
+ children: [/* @__PURE__ */ jsx(Radio, {
46
+ value: "0",
47
+ children: localeService.t("sheets-sort.dialog.sort-reminder-no")
48
+ }), /* @__PURE__ */ jsx(Radio, {
49
+ value: "1",
50
+ children: localeService.t("sheets-sort.dialog.sort-reminder-ext")
51
+ })]
52
+ })]
53
+ });
54
+ };
55
+
56
+ //#endregion
57
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
58
+ function _typeof(o) {
59
+ "@babel/helpers - typeof";
60
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
61
+ return typeof o;
62
+ } : function(o) {
63
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
64
+ }, _typeof(o);
65
+ }
66
+
67
+ //#endregion
68
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
69
+ function toPrimitive(t, r) {
70
+ if ("object" != _typeof(t) || !t) return t;
71
+ var e = t[Symbol.toPrimitive];
72
+ if (void 0 !== e) {
73
+ var i = e.call(t, r || "default");
74
+ if ("object" != _typeof(i)) return i;
75
+ throw new TypeError("@@toPrimitive must return a primitive value.");
76
+ }
77
+ return ("string" === r ? String : Number)(t);
78
+ }
79
+
80
+ //#endregion
81
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
82
+ function toPropertyKey(t) {
83
+ var i = toPrimitive(t, "string");
84
+ return "symbol" == _typeof(i) ? i : i + "";
85
+ }
86
+
87
+ //#endregion
88
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
89
+ function _defineProperty(e, r, t) {
90
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
91
+ value: t,
92
+ enumerable: !0,
93
+ configurable: !0,
94
+ writable: !0
95
+ }) : e[r] = t, e;
96
+ }
97
+
98
+ //#endregion
99
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
100
+ function __decorateParam(paramIndex, decorator) {
101
+ return function(target, key) {
102
+ decorator(target, key, paramIndex);
103
+ };
104
+ }
105
+
106
+ //#endregion
107
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
108
+ function __decorate(decorators, target, key, desc) {
109
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
110
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
111
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
112
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
113
+ }
114
+
115
+ //#endregion
116
+ //#region src/services/sheets-sort-ui.service.tsx
117
+ let EXTEND_TYPE = /* @__PURE__ */ function(EXTEND_TYPE) {
118
+ EXTEND_TYPE["KEEP"] = "keep";
119
+ EXTEND_TYPE["EXTEND"] = "extend";
120
+ EXTEND_TYPE["CANCEL"] = "cancel";
121
+ return EXTEND_TYPE;
122
+ }({});
123
+ const SORT_ERROR_MESSAGE = {
124
+ MERGE_ERROR: "sheets-sort.error.merge-size",
125
+ EMPTY_ERROR: "sheets-sort.error.empty",
126
+ SINGLE_ERROR: "sheets-sort.error.single",
127
+ FORMULA_ARRAY: "sheets-sort.error.formula-array"
128
+ };
129
+ let SheetsSortUIService = class SheetsSortUIService extends Disposable {
130
+ constructor(_univerInstanceService, _confirmService, _selectionManagerService, _sheetsSortService, _localeService, _commandService) {
131
+ super();
132
+ this._univerInstanceService = _univerInstanceService;
133
+ this._confirmService = _confirmService;
134
+ this._selectionManagerService = _selectionManagerService;
135
+ this._sheetsSortService = _sheetsSortService;
136
+ this._localeService = _localeService;
137
+ this._commandService = _commandService;
138
+ _defineProperty(this, "_customSortState$", new BehaviorSubject(null));
139
+ _defineProperty(this, "customSortState$", this._customSortState$.asObservable());
140
+ }
141
+ async triggerSortDirectly(asc, extend, sheetRangeLocation) {
142
+ const location = sheetRangeLocation || await this._detectSortLocation(extend);
143
+ if (!location) return false;
144
+ if (!this._check(location)) return false;
145
+ const sortOption = {
146
+ orderRules: [{
147
+ type: asc ? SortType.ASC : SortType.DESC,
148
+ colIndex: location.colIndex
149
+ }],
150
+ range: location.range
151
+ };
152
+ this._sheetsSortService.applySort(sortOption, location.unitId, location.subUnitId);
153
+ return true;
154
+ }
155
+ async triggerSortCustomize() {
156
+ const location = await this._detectSortLocation();
157
+ if (!location) return false;
158
+ if (!this._check(location)) return false;
159
+ this.showCustomSortPanel(location);
160
+ return true;
161
+ }
162
+ customSortState() {
163
+ return this._customSortState$.getValue();
164
+ }
165
+ getTitles(hasTitle) {
166
+ var _this$customSortState, _this$_univerInstance;
167
+ const location = (_this$customSortState = this.customSortState()) === null || _this$customSortState === void 0 ? void 0 : _this$customSortState.location;
168
+ if (!location) return [];
169
+ const { unitId, subUnitId, range } = location;
170
+ const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
171
+ if (!worksheet) return [];
172
+ const colTranslator = colIndexTranslator(this._localeService);
173
+ return Array.from({ length: range.endColumn - range.startColumn + 1 }, (_, i) => {
174
+ var _worksheet$getCell;
175
+ const cellValue = (_worksheet$getCell = worksheet.getCell(range.startRow, i + range.startColumn)) === null || _worksheet$getCell === void 0 ? void 0 : _worksheet$getCell.v;
176
+ return {
177
+ index: i + range.startColumn,
178
+ label: hasTitle ? `${cellValue !== null && cellValue !== void 0 ? cellValue : colTranslator(i + range.startColumn)}` : colTranslator(i + range.startColumn)
179
+ };
180
+ });
181
+ }
182
+ setSelection(unitId, subUnitId, range) {
183
+ var _this$_univerInstance2;
184
+ const worksheet = (_this$_univerInstance2 = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance2 === void 0 ? void 0 : _this$_univerInstance2.getSheetBySheetId(subUnitId);
185
+ if (!worksheet) return;
186
+ const setSelectionsOperationParams = {
187
+ unitId,
188
+ subUnitId,
189
+ selections: [{
190
+ range,
191
+ primary: getPrimaryForRange(range, worksheet),
192
+ style: null
193
+ }]
194
+ };
195
+ this._commandService.executeCommand(SetSelectionsOperation.id, setSelectionsOperationParams);
196
+ }
197
+ async showCheckError(content) {
198
+ return await this._confirmService.confirm({
199
+ id: "sort-range-check-error",
200
+ title: { title: this._localeService.t("info.tooltip") },
201
+ children: { title: /* @__PURE__ */ jsx("div", { children: this._localeService.t(content) }) },
202
+ cancelText: this._localeService.t("sheets-sort.dialog.cancel"),
203
+ confirmText: this._localeService.t("sheets-sort.dialog.confirm")
204
+ });
205
+ }
206
+ async showExtendConfirm() {
207
+ let shouldExtend = false;
208
+ if (await this._confirmService.confirm({
209
+ id: "extend-sort-range-dialog",
210
+ title: { title: this._localeService.t("sheets-sort.dialog.sort-reminder") },
211
+ children: { title: /* @__PURE__ */ jsx(ExtendConfirm, { onChange: (value) => {
212
+ shouldExtend = value === "1";
213
+ } }) },
214
+ width: 400,
215
+ cancelText: this._localeService.t("sheets-sort.dialog.cancel"),
216
+ confirmText: this._localeService.t("sheets-sort.dialog.confirm")
217
+ })) return shouldExtend ? EXTEND_TYPE.EXTEND : EXTEND_TYPE.KEEP;
218
+ return EXTEND_TYPE.CANCEL;
219
+ }
220
+ showCustomSortPanel(location) {
221
+ this._customSortState$.next({
222
+ location,
223
+ show: true
224
+ });
225
+ }
226
+ closeCustomSortPanel() {
227
+ this._customSortState$.next({ show: false });
228
+ }
229
+ _check(location) {
230
+ if (!this._sheetsSortService.singleCheck(location)) {
231
+ this.showCheckError(SORT_ERROR_MESSAGE.SINGLE_ERROR);
232
+ return false;
233
+ }
234
+ if (!this._sheetsSortService.mergeCheck(location)) {
235
+ this.showCheckError(SORT_ERROR_MESSAGE.MERGE_ERROR);
236
+ return false;
237
+ }
238
+ if (!this._sheetsSortService.formulaCheck(location)) {
239
+ this.showCheckError(SORT_ERROR_MESSAGE.FORMULA_ARRAY);
240
+ return false;
241
+ }
242
+ if (!this._sheetsSortService.emptyCheck(location)) {
243
+ this.showCheckError(SORT_ERROR_MESSAGE.EMPTY_ERROR);
244
+ return false;
245
+ }
246
+ return true;
247
+ }
248
+ async _detectSortLocation(extend) {
249
+ const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
250
+ const worksheet = workbook.getActiveSheet();
251
+ const unitId = workbook.getUnitId();
252
+ const subUnitId = worksheet.getSheetId();
253
+ const selection = this._selectionManagerService.getCurrentLastSelection();
254
+ if (!selection) return null;
255
+ let range;
256
+ if (extend === true) {
257
+ range = expandToContinuousRange(selection.range, {
258
+ up: true,
259
+ down: true,
260
+ left: true,
261
+ right: true
262
+ }, worksheet);
263
+ this.setSelection(unitId, subUnitId, range);
264
+ } else if (extend === false) range = selection.range;
265
+ else {
266
+ const confirmRes = await this.showExtendConfirm();
267
+ if (confirmRes === EXTEND_TYPE.CANCEL) return null;
268
+ if (confirmRes === EXTEND_TYPE.KEEP) range = selection.range;
269
+ else {
270
+ range = expandToContinuousRange(selection.range, {
271
+ up: true,
272
+ down: true,
273
+ left: true,
274
+ right: true
275
+ }, worksheet);
276
+ this.setSelection(unitId, subUnitId, range);
277
+ }
278
+ }
279
+ return {
280
+ range,
281
+ unitId,
282
+ subUnitId,
283
+ colIndex: selection.primary.actualColumn
284
+ };
285
+ }
286
+ };
287
+ SheetsSortUIService = __decorate([
288
+ __decorateParam(0, IUniverInstanceService),
289
+ __decorateParam(1, IConfirmService),
290
+ __decorateParam(2, Inject(SheetsSelectionsService)),
291
+ __decorateParam(3, Inject(SheetsSortService)),
292
+ __decorateParam(4, Inject(LocaleService)),
293
+ __decorateParam(5, ICommandService)
294
+ ], SheetsSortUIService);
295
+ function colIndexTranslator(localeService) {
296
+ return (colIndex) => {
297
+ const colName = Tools.chatAtABC(colIndex);
298
+ switch (localeService.getCurrentLocale()) {
299
+ case LocaleType.ZH_CN: return `"${colName}"列`;
300
+ case LocaleType.EN_US: return `Column "${colName}"`;
301
+ default: return `Column "${colName}"`;
302
+ }
303
+ };
304
+ }
305
+
306
+ //#endregion
307
+ //#region src/commands/commands/sheets-sort.command.ts
308
+ const SortRangeAscCommand = {
309
+ id: "sheet.command.sort-range-asc",
310
+ type: CommandType.COMMAND,
311
+ handler: async (accessor) => {
312
+ return await accessor.get(SheetsSortUIService).triggerSortDirectly(true, false);
313
+ }
314
+ };
315
+ const SortRangeAscExtCommand = {
316
+ id: "sheet.command.sort-range-asc-ext",
317
+ type: CommandType.COMMAND,
318
+ handler: async (accessor) => {
319
+ return await accessor.get(SheetsSortUIService).triggerSortDirectly(true, true);
320
+ }
321
+ };
322
+ const SortRangeDescCommand = {
323
+ id: "sheet.command.sort-range-desc",
324
+ type: CommandType.COMMAND,
325
+ handler: async (accessor) => {
326
+ return await accessor.get(SheetsSortUIService).triggerSortDirectly(false, false);
327
+ }
328
+ };
329
+ const SortRangeDescExtCommand = {
330
+ id: "sheet.command.sort-range-desc-ext",
331
+ type: CommandType.COMMAND,
332
+ handler: async (accessor) => {
333
+ return await accessor.get(SheetsSortUIService).triggerSortDirectly(false, true);
334
+ }
335
+ };
336
+ const SortRangeCustomCommand = {
337
+ id: "sheet.command.sort-range-custom",
338
+ type: CommandType.COMMAND,
339
+ handler: async (accessor) => {
340
+ return await accessor.get(SheetsSortUIService).triggerSortCustomize();
341
+ }
342
+ };
343
+ const SortRangeAscInCtxMenuCommand = {
344
+ id: "sheet.command.sort-range-asc-ctx",
345
+ type: CommandType.COMMAND,
346
+ handler: async (accessor) => {
347
+ return await accessor.get(SheetsSortUIService).triggerSortDirectly(true, false);
348
+ }
349
+ };
350
+ const SortRangeAscExtInCtxMenuCommand = {
351
+ id: "sheet.command.sort-range-asc-ext-ctx",
352
+ type: CommandType.COMMAND,
353
+ handler: async (accessor) => {
354
+ return await accessor.get(SheetsSortUIService).triggerSortDirectly(true, true);
355
+ }
356
+ };
357
+ const SortRangeDescInCtxMenuCommand = {
358
+ id: "sheet.command.sort-range-desc-ctx",
359
+ type: CommandType.COMMAND,
360
+ handler: async (accessor) => {
361
+ return await accessor.get(SheetsSortUIService).triggerSortDirectly(false, false);
362
+ }
363
+ };
364
+ const SortRangeDescExtInCtxMenuCommand = {
365
+ id: "sheet.command.sort-range-desc-ext-ctx",
366
+ type: CommandType.COMMAND,
367
+ handler: async (accessor) => {
368
+ return await accessor.get(SheetsSortUIService).triggerSortDirectly(false, true);
369
+ }
370
+ };
371
+ const SortRangeCustomInCtxMenuCommand = {
372
+ id: "sheet.command.sort-range-custom-ctx",
373
+ type: CommandType.COMMAND,
374
+ handler: async (accessor) => {
375
+ return await accessor.get(SheetsSortUIService).triggerSortCustomize();
376
+ }
377
+ };
378
+
379
+ //#endregion
380
+ //#region package.json
381
+ var name = "@univerjs/sheets-sort-ui";
382
+ var version = "0.21.0";
383
+
384
+ //#endregion
385
+ //#region src/config/config.ts
386
+ const SHEETS_SORT_UI_PLUGIN_CONFIG_KEY = "sheets-sort-ui.config";
387
+ const configSymbol = Symbol(SHEETS_SORT_UI_PLUGIN_CONFIG_KEY);
388
+ const defaultPluginConfig = {};
389
+
390
+ //#endregion
391
+ //#region src/menu/sheets-sort.menu.ts
392
+ const SHEETS_SORT_MENU_ID = "sheet.menu.sheets-sort";
393
+ const SHEETS_SORT_CTX_MENU_ID = "sheet.menu.sheets-sort-ctx";
394
+ const SHEETS_SORT_ASC_ICON = "AscendingIcon";
395
+ const SHEETS_SORT_ASC_EXT_ICON = "ExpandAscendingIcon";
396
+ const SHEETS_SORT_DESC_ICON = "DescendingIcon";
397
+ const SHEETS_SORT_DESC_EXT_ICON = "ExpandDescendingIcon";
398
+ const SHEETS_SORT_CUSTOM_ICON = "CustomSortIcon";
399
+ function sortRangeMenuFactory(accessor) {
400
+ return {
401
+ id: SHEETS_SORT_MENU_ID,
402
+ type: MenuItemType.SUBITEMS,
403
+ icon: SHEETS_SORT_ASC_ICON,
404
+ tooltip: "sheets-sort.general.sort",
405
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
406
+ disabled$: getCurrentRangeDisable$(accessor, {
407
+ workbookTypes: [WorkbookEditablePermission],
408
+ worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission],
409
+ rangeTypes: [RangeProtectionPermissionEditPoint]
410
+ })
411
+ };
412
+ }
413
+ function sortRangeAscMenuFactory(_accessor) {
414
+ return {
415
+ id: SortRangeAscCommand.id,
416
+ icon: SHEETS_SORT_ASC_ICON,
417
+ title: "sheets-sort.general.sort-asc-cur",
418
+ type: MenuItemType.BUTTON,
419
+ hidden$: getCurrentExclusiveRangeInterest$(_accessor)
420
+ };
421
+ }
422
+ function sortRangeAscExtMenuFactory(_accessor) {
423
+ return {
424
+ id: SortRangeAscExtCommand.id,
425
+ title: "sheets-sort.general.sort-asc-ext",
426
+ icon: SHEETS_SORT_ASC_EXT_ICON,
427
+ type: MenuItemType.BUTTON
428
+ };
429
+ }
430
+ function sortRangeDescMenuFactory(_accessor) {
431
+ return {
432
+ id: SortRangeDescCommand.id,
433
+ title: "sheets-sort.general.sort-desc-cur",
434
+ icon: SHEETS_SORT_DESC_ICON,
435
+ type: MenuItemType.BUTTON
436
+ };
437
+ }
438
+ function sortRangeDescExtMenuFactory(_accessor) {
439
+ return {
440
+ id: SortRangeDescExtCommand.id,
441
+ title: "sheets-sort.general.sort-desc-ext",
442
+ icon: SHEETS_SORT_DESC_EXT_ICON,
443
+ type: MenuItemType.BUTTON
444
+ };
445
+ }
446
+ function sortRangeCustomMenuFactory(_accessor) {
447
+ return {
448
+ id: SortRangeCustomCommand.id,
449
+ title: "sheets-sort.general.sort-custom",
450
+ type: MenuItemType.BUTTON,
451
+ icon: SHEETS_SORT_CUSTOM_ICON
452
+ };
453
+ }
454
+ function sortRangeCtxMenuFactory(accessor) {
455
+ return {
456
+ id: SHEETS_SORT_CTX_MENU_ID,
457
+ title: "sheets-sort.general.sort",
458
+ type: MenuItemType.SUBITEMS,
459
+ icon: SHEETS_SORT_ASC_ICON,
460
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
461
+ disabled$: getCurrentRangeDisable$(accessor, {
462
+ workbookTypes: [WorkbookEditablePermission],
463
+ worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission],
464
+ rangeTypes: [RangeProtectionPermissionEditPoint]
465
+ })
466
+ };
467
+ }
468
+ function sortRangeAscCtxMenuFactory(_accessor) {
469
+ return {
470
+ id: SortRangeAscInCtxMenuCommand.id,
471
+ title: "sheets-sort.general.sort-asc-cur",
472
+ type: MenuItemType.BUTTON,
473
+ icon: SHEETS_SORT_ASC_ICON,
474
+ disabled$: getCurrentRangeDisable$(_accessor, {
475
+ workbookTypes: [WorkbookEditablePermission],
476
+ worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission],
477
+ rangeTypes: [RangeProtectionPermissionEditPoint]
478
+ })
479
+ };
480
+ }
481
+ function sortRangeAscExtCtxMenuFactory(_accessor) {
482
+ return {
483
+ id: SortRangeAscExtInCtxMenuCommand.id,
484
+ title: "sheets-sort.general.sort-asc-ext",
485
+ type: MenuItemType.BUTTON,
486
+ icon: SHEETS_SORT_ASC_EXT_ICON,
487
+ disabled$: getCurrentRangeDisable$(_accessor, {
488
+ workbookTypes: [WorkbookEditablePermission],
489
+ worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission],
490
+ rangeTypes: [RangeProtectionPermissionEditPoint]
491
+ })
492
+ };
493
+ }
494
+ function sortRangeDescCtxMenuFactory(_accessor) {
495
+ return {
496
+ id: SortRangeDescInCtxMenuCommand.id,
497
+ title: "sheets-sort.general.sort-desc-cur",
498
+ type: MenuItemType.BUTTON,
499
+ icon: SHEETS_SORT_DESC_ICON,
500
+ disabled$: getCurrentRangeDisable$(_accessor, {
501
+ workbookTypes: [WorkbookEditablePermission],
502
+ worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission],
503
+ rangeTypes: [RangeProtectionPermissionEditPoint]
504
+ })
505
+ };
506
+ }
507
+ function sortRangeDescExtCtxMenuFactory(_accessor) {
508
+ return {
509
+ id: SortRangeDescExtInCtxMenuCommand.id,
510
+ title: "sheets-sort.general.sort-desc-ext",
511
+ type: MenuItemType.BUTTON,
512
+ icon: SHEETS_SORT_DESC_EXT_ICON,
513
+ disabled$: getCurrentRangeDisable$(_accessor, {
514
+ workbookTypes: [WorkbookEditablePermission],
515
+ worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission],
516
+ rangeTypes: [RangeProtectionPermissionEditPoint]
517
+ })
518
+ };
519
+ }
520
+ function sortRangeCustomCtxMenuFactory(_accessor) {
521
+ return {
522
+ id: SortRangeCustomInCtxMenuCommand.id,
523
+ title: "sheets-sort.general.sort-custom",
524
+ type: MenuItemType.BUTTON,
525
+ icon: SHEETS_SORT_CUSTOM_ICON,
526
+ disabled$: getCurrentRangeDisable$(_accessor, {
527
+ workbookTypes: [WorkbookEditablePermission],
528
+ worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission],
529
+ rangeTypes: [RangeProtectionPermissionEditPoint]
530
+ })
531
+ };
532
+ }
533
+
534
+ //#endregion
535
+ //#region src/menu/schema.ts
536
+ const menuSchema = {
537
+ [RibbonDataGroup.ORGANIZATION]: { [SHEETS_SORT_MENU_ID]: {
538
+ order: 3,
539
+ menuItemFactory: sortRangeMenuFactory,
540
+ [SortRangeAscCommand.id]: {
541
+ order: 0,
542
+ menuItemFactory: sortRangeAscMenuFactory
543
+ },
544
+ [SortRangeAscExtCommand.id]: {
545
+ order: 1,
546
+ menuItemFactory: sortRangeAscExtMenuFactory
547
+ },
548
+ [SortRangeDescCommand.id]: {
549
+ order: 2,
550
+ menuItemFactory: sortRangeDescMenuFactory
551
+ },
552
+ [SortRangeDescExtCommand.id]: {
553
+ order: 3,
554
+ menuItemFactory: sortRangeDescExtMenuFactory
555
+ },
556
+ [SortRangeCustomCommand.id]: {
557
+ order: 4,
558
+ menuItemFactory: sortRangeCustomMenuFactory
559
+ }
560
+ } },
561
+ [ContextMenuPosition.MAIN_AREA]: { [ContextMenuGroup.DATA]: { [SHEETS_SORT_CTX_MENU_ID]: {
562
+ order: 0,
563
+ menuItemFactory: sortRangeCtxMenuFactory,
564
+ [SortRangeAscInCtxMenuCommand.id]: {
565
+ order: 0,
566
+ menuItemFactory: sortRangeAscCtxMenuFactory
567
+ },
568
+ [SortRangeAscExtInCtxMenuCommand.id]: {
569
+ order: 1,
570
+ menuItemFactory: sortRangeAscExtCtxMenuFactory
571
+ },
572
+ [SortRangeDescInCtxMenuCommand.id]: {
573
+ order: 2,
574
+ menuItemFactory: sortRangeDescCtxMenuFactory
575
+ },
576
+ [SortRangeDescExtInCtxMenuCommand.id]: {
577
+ order: 3,
578
+ menuItemFactory: sortRangeDescExtCtxMenuFactory
579
+ },
580
+ [SortRangeCustomInCtxMenuCommand.id]: {
581
+ order: 4,
582
+ menuItemFactory: sortRangeCustomCtxMenuFactory
583
+ }
584
+ } } }
585
+ };
586
+
587
+ //#endregion
588
+ //#region src/views/CustomSortPanel.tsx
589
+ function CustomSortPanel() {
590
+ const state = useObservable(useDependency(SheetsSortUIService).customSortState$);
591
+ if (!state || !state.location) return null;
592
+ return /* @__PURE__ */ jsx(CustomSortPanelImpl, { state });
593
+ }
594
+ function CustomSortPanelImpl({ state }) {
595
+ const sheetsSortService = useDependency(SheetsSortService);
596
+ const localeService = useDependency(LocaleService);
597
+ const sheetsSortUIService = useDependency(SheetsSortUIService);
598
+ const [hasTitle, setHasTitle] = useState(false);
599
+ const [scrollPosition, setScrollPosition] = useState(0);
600
+ const listEndRef = useRef(null);
601
+ const { range, unitId, subUnitId } = state.location;
602
+ const titles = sheetsSortUIService.getTitles(hasTitle);
603
+ const [list, setList] = useState([{
604
+ type: SortType.ASC,
605
+ colIndex: range.startColumn
606
+ }]);
607
+ const onItemChange = useCallback((index, value) => {
608
+ const newList = [...list];
609
+ if (value === null) newList.splice(index, 1);
610
+ else newList[index] = value;
611
+ setList(newList);
612
+ }, [list]);
613
+ const newItem = useCallback(throttle(() => {
614
+ const newList = [...list];
615
+ const nextColIndex = findNextColIndex(range, list);
616
+ if (nextColIndex !== null) {
617
+ newList.push({
618
+ type: SortType.ASC,
619
+ colIndex: nextColIndex
620
+ });
621
+ setList(newList);
622
+ }
623
+ }, 200), [list, range]);
624
+ const apply = useCallback((orderRules, hasTitle) => {
625
+ sheetsSortService.applySort({
626
+ range,
627
+ orderRules,
628
+ hasTitle
629
+ });
630
+ sheetsSortUIService.closeCustomSortPanel();
631
+ }, [
632
+ sheetsSortService,
633
+ sheetsSortUIService,
634
+ range
635
+ ]);
636
+ const cancel = useCallback(() => {
637
+ sheetsSortUIService.closeCustomSortPanel();
638
+ }, [sheetsSortUIService]);
639
+ const setTitle = useCallback((value) => {
640
+ setHasTitle(value);
641
+ if (value) sheetsSortUIService.setSelection(unitId, subUnitId, {
642
+ ...range,
643
+ startRow: range.startRow + 1
644
+ });
645
+ else sheetsSortUIService.setSelection(unitId, subUnitId, range);
646
+ }, [
647
+ sheetsSortUIService,
648
+ range,
649
+ subUnitId,
650
+ unitId
651
+ ]);
652
+ useEffect(() => {
653
+ if (listEndRef.current && list.length > 5) listEndRef.current.scrollTop = listEndRef.current.scrollHeight;
654
+ }, [list]);
655
+ const canNew = list.length < titles.length;
656
+ const dragList = list.map((item) => ({
657
+ ...item,
658
+ id: `${item.colIndex}`
659
+ }));
660
+ return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
661
+ onMouseDown: (e) => {
662
+ e.stopPropagation();
663
+ },
664
+ children: [/* @__PURE__ */ jsxs("div", {
665
+ className: "univer-mb-2 univer-flex univer-items-center univer-justify-between",
666
+ children: [/* @__PURE__ */ jsx(Checkbox, {
667
+ checked: hasTitle,
668
+ onChange: (value) => setTitle(!!value),
669
+ children: localeService.t("sheets-sort.dialog.first-row-check")
670
+ }), canNew ? /* @__PURE__ */ jsxs("div", {
671
+ className: "univer-flex univer-cursor-pointer univer-select-none univer-items-center univer-text-base",
672
+ onClick: newItem,
673
+ children: [/* @__PURE__ */ jsx(IncreaseIcon, {}), /* @__PURE__ */ jsx("span", {
674
+ className: "univer-ml-1.5",
675
+ children: localeService.t("sheets-sort.dialog.add-condition")
676
+ })]
677
+ }) : /* @__PURE__ */ jsxs("div", {
678
+ className: "univer-flex univer-cursor-pointer univer-select-none univer-items-center univer-text-base univer-text-primary-500 disabled:univer-cursor-not-allowed disabled:univer-divide-opacity-30 disabled:univer-text-gray-800",
679
+ children: [/* @__PURE__ */ jsx(IncreaseIcon, {}), /* @__PURE__ */ jsx("span", {
680
+ className: "univer-ml-1.5 univer-text-xs",
681
+ children: localeService.t("sheets-sort.dialog.add-condition")
682
+ })]
683
+ })]
684
+ }), /* @__PURE__ */ jsx("div", {
685
+ ref: listEndRef,
686
+ className: clsx("univer-max-h-[310px] univer-overflow-y-auto univer-overflow-x-hidden", scrollbarClassName),
687
+ onScroll: (e) => {
688
+ const position = e.currentTarget.scrollTop;
689
+ setScrollPosition(position);
690
+ },
691
+ children: /* @__PURE__ */ jsx(DraggableList, {
692
+ list: dragList,
693
+ onListChange: setList,
694
+ idKey: "id",
695
+ draggableHandle: "[data-u-comp=sort-panel-item-handler]",
696
+ itemRender: (item) => /* @__PURE__ */ jsx(SortOptionItem, {
697
+ titles,
698
+ list: dragList,
699
+ item,
700
+ onChange: (value, index) => onItemChange(index, value),
701
+ scrollPosition
702
+ }),
703
+ rowHeight: 32,
704
+ margin: [0, 12]
705
+ })
706
+ })]
707
+ }), /* @__PURE__ */ jsxs("div", {
708
+ className: "univer-mt-5 univer-flex univer-justify-end",
709
+ children: [/* @__PURE__ */ jsx(Button, {
710
+ className: "univer-ml-3",
711
+ onClick: () => cancel(),
712
+ children: localeService.t("sheets-sort.dialog.cancel")
713
+ }), /* @__PURE__ */ jsx(Button, {
714
+ className: "univer-ml-3",
715
+ variant: "primary",
716
+ onClick: () => apply(list, hasTitle),
717
+ children: localeService.t("sheets-sort.dialog.confirm")
718
+ })]
719
+ })] });
720
+ }
721
+ function SortOptionItem(props) {
722
+ var _titles$find;
723
+ const { list, item, titles, onChange, scrollPosition } = props;
724
+ const localeService = useDependency(LocaleService);
725
+ const availableMenu = titles.filter((title) => !list.some((item) => item.colIndex === title.index) || title.index === item.colIndex);
726
+ const currentIndex = list.findIndex((listItem) => listItem.colIndex === item.colIndex);
727
+ const handleChangeColIndex = useCallback((menuItem) => {
728
+ onChange({
729
+ ...item,
730
+ colIndex: menuItem.index
731
+ }, currentIndex);
732
+ setVisible(false);
733
+ }, [
734
+ currentIndex,
735
+ item,
736
+ onChange
737
+ ]);
738
+ const [visible, setVisible] = useState(false);
739
+ const onVisibleChange = (visible) => {
740
+ setVisible(visible);
741
+ };
742
+ useEffect(() => {
743
+ setVisible(false);
744
+ }, [scrollPosition]);
745
+ const showDelete = list.length > 1;
746
+ const itemLabel = (_titles$find = titles.find((title) => title.index === item.colIndex)) === null || _titles$find === void 0 ? void 0 : _titles$find.label;
747
+ return /* @__PURE__ */ jsxs("div", {
748
+ className: "univer-grid univer-grid-flow-col univer-grid-cols-2 univer-items-center univer-gap-2",
749
+ children: [/* @__PURE__ */ jsxs("div", {
750
+ className: "univer-flex univer-items-center",
751
+ children: [/* @__PURE__ */ jsx("div", {
752
+ "data-u-comp": "sort-panel-item-handler",
753
+ className: "univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-text-base univer-text-gray-700",
754
+ children: /* @__PURE__ */ jsx(SequenceIcon, {})
755
+ }), /* @__PURE__ */ jsx(Dropdown, {
756
+ overlay: /* @__PURE__ */ jsx("ul", {
757
+ className: clsx("univer-my-0 univer-box-border univer-grid univer-max-h-[310px] univer-w-[--radix-popper-anchor-width] univer-items-center univer-gap-1 univer-overflow-y-auto univer-overflow-x-hidden univer-rounded-lg univer-border univer-bg-white univer-p-1 univer-text-base univer-shadow-lg", scrollbarClassName),
758
+ children: availableMenu.map((menuItem) => /* @__PURE__ */ jsxs("li", {
759
+ onClick: () => handleChangeColIndex(menuItem),
760
+ className: "univer-relative univer-box-border univer-flex univer-h-7 univer-cursor-pointer univer-list-none univer-items-center univer-justify-between univer-rounded univer-px-2 univer-text-sm univer-transition-all hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",
761
+ children: [/* @__PURE__ */ jsx("span", {
762
+ className: "univer-max-w-[220px] univer-truncate",
763
+ children: menuItem.label
764
+ }), /* @__PURE__ */ jsx("span", { children: menuItem.index === item.colIndex && /* @__PURE__ */ jsx(CheckMarkIcon, {}) })]
765
+ }, menuItem.index))
766
+ }),
767
+ open: visible,
768
+ onOpenChange: onVisibleChange,
769
+ children: /* @__PURE__ */ jsxs("div", {
770
+ className: clsx("univer-ml-2 univer-flex univer-w-full univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-md univer-py-1.5 univer-text-sm univer-text-gray-900 dark:!univer-text-white"),
771
+ children: [/* @__PURE__ */ jsx("span", {
772
+ className: "univer-max-w-[220px] univer-truncate",
773
+ children: itemLabel
774
+ }), /* @__PURE__ */ jsx(MoreDownIcon, {})]
775
+ })
776
+ })]
777
+ }), /* @__PURE__ */ jsxs("div", {
778
+ className: "univer-flex univer-items-center univer-justify-end univer-gap-2",
779
+ children: [/* @__PURE__ */ jsxs(RadioGroup, {
780
+ value: item.type,
781
+ onChange: (value) => {
782
+ onChange({
783
+ ...item,
784
+ type: value
785
+ }, currentIndex);
786
+ },
787
+ children: [/* @__PURE__ */ jsx(Radio, {
788
+ value: SortType.ASC,
789
+ children: localeService.t("sheets-sort.general.sort-asc")
790
+ }), /* @__PURE__ */ jsx(Radio, {
791
+ value: SortType.DESC,
792
+ children: localeService.t("sheets-sort.general.sort-desc")
793
+ })]
794
+ }), /* @__PURE__ */ jsx("a", {
795
+ className: "univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-transition-colors hover:univer-text-red-500",
796
+ onClick: () => onChange(null, currentIndex),
797
+ children: !showDelete && /* @__PURE__ */ jsx(DeleteEmptyIcon, {})
798
+ })]
799
+ })]
800
+ });
801
+ }
802
+ function findNextColIndex(range, list) {
803
+ const { startColumn, endColumn } = range;
804
+ const used = new Set(list.map((item) => item === null || item === void 0 ? void 0 : item.colIndex));
805
+ for (let i = startColumn; i <= endColumn; i++) if (!used.has(i)) return i;
806
+ return null;
807
+ }
808
+
809
+ //#endregion
810
+ //#region src/views/EmbedSortBtn.tsx
811
+ function EmbedSortBtn(props) {
812
+ const { range, colIndex, onClose } = props;
813
+ const sheetsSortUIService = useDependency(SheetsSortUIService);
814
+ const univerInstanceService = useDependency(IUniverInstanceService);
815
+ const localeService = useDependency(LocaleService);
816
+ const apply = useCallback((asc) => {
817
+ const { unitId, subUnitId } = getSheetCommandTarget(univerInstanceService) || {};
818
+ if (range && unitId && subUnitId) {
819
+ const noTitleRange = {
820
+ ...range,
821
+ startRow: range.startRow + 1
822
+ };
823
+ sheetsSortUIService.triggerSortDirectly(asc, false, {
824
+ unitId,
825
+ subUnitId,
826
+ range: noTitleRange,
827
+ colIndex
828
+ });
829
+ } else throw new Error(`Cannot find the target to sort. unitId: ${unitId}, subUnitId: ${subUnitId}, range: ${range}, colIndex: ${colIndex}`);
830
+ onClose();
831
+ }, [
832
+ range,
833
+ colIndex,
834
+ sheetsSortUIService,
835
+ univerInstanceService,
836
+ onClose
837
+ ]);
838
+ return /* @__PURE__ */ jsxs(ButtonGroup, {
839
+ className: "univer-mb-3 univer-w-full univer-grid-cols-2",
840
+ children: [/* @__PURE__ */ jsxs(Button, {
841
+ onClick: () => apply(true),
842
+ children: [/* @__PURE__ */ jsx(AscendingIcon, {}), localeService.t("sheets-sort.general.sort-asc")]
843
+ }), /* @__PURE__ */ jsxs(Button, {
844
+ onClick: () => apply(false),
845
+ children: [/* @__PURE__ */ jsx(DescendingIcon, {}), localeService.t("sheets-sort.general.sort-desc")]
846
+ })]
847
+ });
848
+ }
849
+
850
+ //#endregion
851
+ //#region src/controllers/sheets-sort-ui.controller.ts
852
+ const CUSTOM_SORT_DIALOG_ID = "custom-sort-dialog";
853
+ const CUSTOM_SORT_PANEL_WIDTH = 560;
854
+ const CUSTOM_SORT_PANEL_TOP = 128;
855
+ let SheetsSortUIController = class SheetsSortUIController extends RxDisposable {
856
+ constructor(_commandService, _menuManagerService, _dialogService, _layoutService, _uiPartsService, _sheetRenderService, _localeService, _sheetsSortUIService, _injector, _componentManager) {
857
+ super();
858
+ this._commandService = _commandService;
859
+ this._menuManagerService = _menuManagerService;
860
+ this._dialogService = _dialogService;
861
+ this._layoutService = _layoutService;
862
+ this._uiPartsService = _uiPartsService;
863
+ this._sheetRenderService = _sheetRenderService;
864
+ this._localeService = _localeService;
865
+ this._sheetsSortUIService = _sheetsSortUIService;
866
+ this._injector = _injector;
867
+ this._componentManager = _componentManager;
868
+ this._initCommands();
869
+ this._initMenu();
870
+ this._initUI();
871
+ }
872
+ _initMenu() {
873
+ this._menuManagerService.mergeMenu(menuSchema);
874
+ }
875
+ _initCommands() {
876
+ [
877
+ SortRangeAscCommand,
878
+ SortRangeAscExtCommand,
879
+ SortRangeDescCommand,
880
+ SortRangeDescExtCommand,
881
+ SortRangeCustomCommand,
882
+ SortRangeAscInCtxMenuCommand,
883
+ SortRangeAscExtInCtxMenuCommand,
884
+ SortRangeDescInCtxMenuCommand,
885
+ SortRangeDescExtInCtxMenuCommand,
886
+ SortRangeCustomInCtxMenuCommand
887
+ ].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
888
+ this.disposeWithMe(this._sheetRenderService.registerSkeletonChangingMutations(SortRangeCommand.id));
889
+ }
890
+ _initUI() {
891
+ this.disposeWithMe(this._uiPartsService.registerComponent(SheetsUIPart.FILTER_PANEL_EMBED_POINT, () => connectInjector(EmbedSortBtn, this._injector)));
892
+ [
893
+ ["CustomSortPanel", CustomSortPanel],
894
+ [SHEETS_SORT_ASC_ICON, AscendingIcon],
895
+ [SHEETS_SORT_ASC_EXT_ICON, ExpandAscendingIcon],
896
+ [SHEETS_SORT_DESC_ICON, DescendingIcon],
897
+ [SHEETS_SORT_DESC_EXT_ICON, ExpandDescendingIcon],
898
+ [SHEETS_SORT_CUSTOM_ICON, CustomSortIcon]
899
+ ].forEach(([key, comp]) => {
900
+ this.disposeWithMe(this._componentManager.register(key, comp));
901
+ });
902
+ this._sheetsSortUIService.customSortState$.pipe(takeUntil(this.dispose$)).subscribe((newState) => {
903
+ if (newState && newState.show && newState.location) this._openCustomSortPanel(newState.location);
904
+ else if (newState && !(newState === null || newState === void 0 ? void 0 : newState.show)) this._closePanel();
905
+ });
906
+ }
907
+ _openCustomSortPanel(location) {
908
+ this._dialogService.open({
909
+ id: CUSTOM_SORT_DIALOG_ID,
910
+ draggable: true,
911
+ width: CUSTOM_SORT_PANEL_WIDTH,
912
+ title: { title: `${this._localeService.t("sheets-sort.general.sort-custom")}: ${serializeRange(location.range)}` },
913
+ children: { label: "CustomSortPanel" },
914
+ destroyOnClose: true,
915
+ defaultPosition: getCustomSortDialogDefaultPosition(),
916
+ preservePositionOnDestroy: false,
917
+ onClose: () => this._closePanel(),
918
+ mask: true
919
+ });
920
+ }
921
+ _closePanel() {
922
+ this._dialogService.close(CUSTOM_SORT_DIALOG_ID);
923
+ queueMicrotask(() => this._layoutService.focus());
924
+ }
925
+ };
926
+ SheetsSortUIController = __decorate([
927
+ __decorateParam(0, ICommandService),
928
+ __decorateParam(1, IMenuManagerService),
929
+ __decorateParam(2, IDialogService),
930
+ __decorateParam(3, ILayoutService),
931
+ __decorateParam(4, IUIPartsService),
932
+ __decorateParam(5, Inject(SheetsRenderService)),
933
+ __decorateParam(6, Inject(LocaleService)),
934
+ __decorateParam(7, Inject(SheetsSortUIService)),
935
+ __decorateParam(8, Inject(Injector)),
936
+ __decorateParam(9, Inject(ComponentManager))
937
+ ], SheetsSortUIController);
938
+ function getCustomSortDialogDefaultPosition() {
939
+ return {
940
+ x: (window.innerWidth - CUSTOM_SORT_PANEL_WIDTH) / 2,
941
+ y: CUSTOM_SORT_PANEL_TOP
942
+ };
943
+ }
944
+
945
+ //#endregion
946
+ //#region src/plugin.ts
947
+ let UniverSheetsSortUIPlugin = class UniverSheetsSortUIPlugin extends Plugin {
948
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
949
+ super();
950
+ this._config = _config;
951
+ this._injector = _injector;
952
+ this._configService = _configService;
953
+ const { ...rest } = merge({}, defaultPluginConfig, this._config);
954
+ this._configService.setConfig(SHEETS_SORT_UI_PLUGIN_CONFIG_KEY, rest);
955
+ }
956
+ onStarting() {
957
+ [[SheetsSortUIService], [SheetsSortUIController]].forEach((d) => this._injector.add(d));
958
+ }
959
+ onRendered() {
960
+ this._injector.get(SheetsSortUIController);
961
+ }
962
+ };
963
+ _defineProperty(UniverSheetsSortUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
964
+ _defineProperty(UniverSheetsSortUIPlugin, "pluginName", "SHEET_SORT_UI_PLUGIN");
965
+ _defineProperty(UniverSheetsSortUIPlugin, "packageName", name);
966
+ _defineProperty(UniverSheetsSortUIPlugin, "version", version);
967
+ UniverSheetsSortUIPlugin = __decorate([
968
+ DependentOn(UniverSheetsSortPlugin),
969
+ __decorateParam(1, Inject(Injector)),
970
+ __decorateParam(2, IConfigService)
971
+ ], UniverSheetsSortUIPlugin);
972
+
973
+ //#endregion
974
+ export { SortRangeAscCommand, SortRangeAscExtCommand, SortRangeAscExtInCtxMenuCommand, SortRangeAscInCtxMenuCommand, SortRangeCustomCommand, SortRangeCustomInCtxMenuCommand, SortRangeDescCommand, SortRangeDescExtCommand, SortRangeDescExtInCtxMenuCommand, SortRangeDescInCtxMenuCommand, UniverSheetsSortUIPlugin };