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