@univerjs/sheets-sort-ui 0.18.0 → 0.19.0-insiders.20260403-3e0e122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -30
- package/lib/es/index.js +1 -30
- package/lib/index.js +1 -30
- package/lib/umd/index.js +1 -30
- package/package.json +12 -12
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1,30 +1 @@
|
|
|
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.18.0`;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:`
|
|
2
|
-
univer-flex univer-cursor-pointer univer-select-none univer-items-center
|
|
3
|
-
univer-text-base
|
|
4
|
-
`,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:`
|
|
5
|
-
univer-flex univer-cursor-pointer univer-select-none univer-items-center
|
|
6
|
-
univer-text-base univer-text-primary-500
|
|
7
|
-
disabled:univer-cursor-not-allowed disabled:univer-divide-opacity-30
|
|
8
|
-
disabled:univer-text-gray-800
|
|
9
|
-
`,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:`
|
|
10
|
-
univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-text-base
|
|
11
|
-
univer-text-gray-700
|
|
12
|
-
`,children:(0,s.jsx)(l.SequenceIcon,{})}),(0,s.jsx)(i.Dropdown,{overlay:(0,s.jsx)(`ul`,{className:(0,i.clsx)(`
|
|
13
|
-
univer-my-0 univer-box-border univer-grid univer-max-h-[310px]
|
|
14
|
-
univer-w-[--radix-popper-anchor-width] univer-items-center univer-gap-1
|
|
15
|
-
univer-overflow-y-auto univer-overflow-x-hidden univer-rounded-lg univer-border
|
|
16
|
-
univer-bg-white univer-p-1 univer-text-base univer-shadow-lg
|
|
17
|
-
`,i.scrollbarClassName),children:h.map(e=>(0,s.jsxs)(`li`,{onClick:()=>_(e),className:`
|
|
18
|
-
univer-relative univer-box-border univer-flex univer-h-7 univer-cursor-pointer
|
|
19
|
-
univer-list-none univer-items-center univer-justify-between univer-rounded
|
|
20
|
-
univer-px-2 univer-text-sm univer-transition-all
|
|
21
|
-
hover:univer-bg-gray-100
|
|
22
|
-
dark:hover:!univer-bg-gray-700
|
|
23
|
-
`,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)(`
|
|
24
|
-
univer-ml-2 univer-flex univer-w-full univer-items-center univer-justify-between
|
|
25
|
-
univer-overflow-hidden univer-rounded-md univer-py-1.5 univer-text-sm univer-text-gray-900
|
|
26
|
-
dark:!univer-text-white
|
|
27
|
-
`),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:`
|
|
28
|
-
univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-transition-colors
|
|
29
|
-
hover:univer-text-red-500
|
|
30
|
-
`,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`});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.19.0-insiders.20260403-3e0e122`;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 $}});
|
package/lib/es/index.js
CHANGED
|
@@ -1,30 +1 @@
|
|
|
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.18.0`;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:`
|
|
2
|
-
univer-flex univer-cursor-pointer univer-select-none univer-items-center
|
|
3
|
-
univer-text-base
|
|
4
|
-
`,onClick:te,children:[O(Re,{}),O(`span`,{className:`univer-ml-1.5`,children:n.t(`sheets-sort.dialog.add-condition`)})]}):k(`div`,{className:`
|
|
5
|
-
univer-flex univer-cursor-pointer univer-select-none univer-items-center
|
|
6
|
-
univer-text-base univer-text-primary-500
|
|
7
|
-
disabled:univer-cursor-not-allowed disabled:univer-divide-opacity-30
|
|
8
|
-
disabled:univer-text-gray-800
|
|
9
|
-
`,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:`
|
|
10
|
-
univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-text-base
|
|
11
|
-
univer-text-gray-700
|
|
12
|
-
`,children:O(Be,{})}),O(pe,{overlay:O(`ul`,{className:he(`
|
|
13
|
-
univer-my-0 univer-box-border univer-grid univer-max-h-[310px]
|
|
14
|
-
univer-w-[--radix-popper-anchor-width] univer-items-center univer-gap-1
|
|
15
|
-
univer-overflow-y-auto univer-overflow-x-hidden univer-rounded-lg univer-border
|
|
16
|
-
univer-bg-white univer-p-1 univer-text-base univer-shadow-lg
|
|
17
|
-
`,ge),children:c.map(e=>k(`li`,{onClick:()=>d(e),className:`
|
|
18
|
-
univer-relative univer-box-border univer-flex univer-h-7 univer-cursor-pointer
|
|
19
|
-
univer-list-none univer-items-center univer-justify-between univer-rounded
|
|
20
|
-
univer-px-2 univer-text-sm univer-transition-all
|
|
21
|
-
hover:univer-bg-gray-100
|
|
22
|
-
dark:hover:!univer-bg-gray-700
|
|
23
|
-
`,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(`
|
|
24
|
-
univer-ml-2 univer-flex univer-w-full univer-items-center univer-justify-between
|
|
25
|
-
univer-overflow-hidden univer-rounded-md univer-py-1.5 univer-text-sm univer-text-gray-900
|
|
26
|
-
dark:!univer-text-white
|
|
27
|
-
`),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:`
|
|
28
|
-
univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-transition-colors
|
|
29
|
-
hover:univer-text-red-500
|
|
30
|
-
`,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 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.19.0-insiders.20260403-3e0e122`;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};
|
package/lib/index.js
CHANGED
|
@@ -1,30 +1 @@
|
|
|
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.18.0`;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:`
|
|
2
|
-
univer-flex univer-cursor-pointer univer-select-none univer-items-center
|
|
3
|
-
univer-text-base
|
|
4
|
-
`,onClick:te,children:[O(Re,{}),O(`span`,{className:`univer-ml-1.5`,children:n.t(`sheets-sort.dialog.add-condition`)})]}):k(`div`,{className:`
|
|
5
|
-
univer-flex univer-cursor-pointer univer-select-none univer-items-center
|
|
6
|
-
univer-text-base univer-text-primary-500
|
|
7
|
-
disabled:univer-cursor-not-allowed disabled:univer-divide-opacity-30
|
|
8
|
-
disabled:univer-text-gray-800
|
|
9
|
-
`,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:`
|
|
10
|
-
univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-text-base
|
|
11
|
-
univer-text-gray-700
|
|
12
|
-
`,children:O(Be,{})}),O(pe,{overlay:O(`ul`,{className:he(`
|
|
13
|
-
univer-my-0 univer-box-border univer-grid univer-max-h-[310px]
|
|
14
|
-
univer-w-[--radix-popper-anchor-width] univer-items-center univer-gap-1
|
|
15
|
-
univer-overflow-y-auto univer-overflow-x-hidden univer-rounded-lg univer-border
|
|
16
|
-
univer-bg-white univer-p-1 univer-text-base univer-shadow-lg
|
|
17
|
-
`,ge),children:c.map(e=>k(`li`,{onClick:()=>d(e),className:`
|
|
18
|
-
univer-relative univer-box-border univer-flex univer-h-7 univer-cursor-pointer
|
|
19
|
-
univer-list-none univer-items-center univer-justify-between univer-rounded
|
|
20
|
-
univer-px-2 univer-text-sm univer-transition-all
|
|
21
|
-
hover:univer-bg-gray-100
|
|
22
|
-
dark:hover:!univer-bg-gray-700
|
|
23
|
-
`,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(`
|
|
24
|
-
univer-ml-2 univer-flex univer-w-full univer-items-center univer-justify-between
|
|
25
|
-
univer-overflow-hidden univer-rounded-md univer-py-1.5 univer-text-sm univer-text-gray-900
|
|
26
|
-
dark:!univer-text-white
|
|
27
|
-
`),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:`
|
|
28
|
-
univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-transition-colors
|
|
29
|
-
hover:univer-text-red-500
|
|
30
|
-
`,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 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.19.0-insiders.20260403-3e0e122`;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};
|
package/lib/umd/index.js
CHANGED
|
@@ -1,30 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`@univerjs/sheets-sort`),require(`rxjs`),require(`@univerjs/design`),require(`@univerjs/ui`),require(`react`),require(`react/jsx-runtime`),require(`@univerjs/engine-formula`),require(`@univerjs/sheets-ui`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/sheets-sort`,`rxjs`,`@univerjs/design`,`@univerjs/ui`,`react`,`react/jsx-runtime`,`@univerjs/engine-formula`,`@univerjs/sheets-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsSortUi={},e.UniverCore,e.UniverSheets,e.UniverSheetsSort,e.rxjs,e.UniverDesign,e.UniverUi,e.React,e.React,e.UniverEngineFormula,e.UniverSheetsUi))})(this,function(e,t,n,r,i,a,o,s,c,l,u){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let d=e=>{let[n,r]=(0,s.useState)(`0`),i=(0,o.useDependency)(t.LocaleService);return(0,c.jsxs)(`div`,{className:`univer-text-sm`,children:[(0,c.jsx)(`div`,{className:`extend-confirm-desc`,children:i.t(`sheets-sort.dialog.sort-reminder-desc`)}),(0,c.jsxs)(a.RadioGroup,{className:`univer-mt-4`,value:n,direction:`vertical`,onChange:t=>{r(t),e.onChange(t)},children:[(0,c.jsx)(a.Radio,{value:`0`,children:i.t(`sheets-sort.dialog.sort-reminder-no`)}),(0,c.jsx)(a.Radio,{value:`1`,children:i.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}({}),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`},b=class extends t.Disposable{constructor(e,t,n,r,a,o){super(),this._univerInstanceService=e,this._confirmService=t,this._selectionManagerService=n,this._sheetsSortService=r,this._localeService=a,this._commandService=o,h(this,`_customSortState$`,new i.BehaviorSubject(null)),h(this,`customSortState$`,this._customSortState$.asObservable())}async triggerSortDirectly(e,t,n){let i=n||await this._detectSortLocation(t);if(!i||!this._check(i))return!1;let a={orderRules:[{type:e?r.SortType.ASC:r.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,t,r){var i;let a=(i=this._univerInstanceService.getUnit(e))==null?void 0:i.getSheetBySheetId(t);if(!a)return;let o={unitId:e,subUnitId:t,selections:[{range:r,primary:(0,n.getPrimaryForRange)(r,a),style:null}]};this._commandService.executeCommand(n.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,c.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,c.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(e){let r=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),i=r.getActiveSheet(),a=r.getUnitId(),o=i.getSheetId(),s=this._selectionManagerService.getCurrentLastSelection();if(!s)return null;let c;if(e===!0)c=(0,n.expandToContinuousRange)(s.range,{up:!0,down:!0,left:!0,right:!0},i),this.setSelection(a,o,c);else if(e===!1)c=s.range;else{let e=await this.showExtendConfirm();if(e===v.CANCEL)return null;e===v.KEEP?c=s.range:(c=(0,n.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,t.IUniverInstanceService),g(1,t.IConfirmService),g(2,(0,t.Inject)(n.SheetsSelectionsService)),g(3,(0,t.Inject)(r.SheetsSortService)),g(4,(0,t.Inject)(t.LocaleService)),g(5,t.ICommandService)],b);function x(e){return n=>{let r=t.Tools.chatAtABC(n);switch(e.getCurrentLocale()){case t.LocaleType.ZH_CN:return`"${r}"列`;case t.LocaleType.EN_US:return`Column "${r}"`;default:return`Column "${r}"`}}}let S={id:`sheet.command.sort-range-asc`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!0,!1)},C={id:`sheet.command.sort-range-asc-ext`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!0,!0)},w={id:`sheet.command.sort-range-desc`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!1,!1)},T={id:`sheet.command.sort-range-desc-ext`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!1,!0)},E={id:`sheet.command.sort-range-custom`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortCustomize()},D={id:`sheet.command.sort-range-asc-ctx`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!0,!1)},O={id:`sheet.command.sort-range-asc-ext-ctx`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!0,!0)},k={id:`sheet.command.sort-range-desc-ctx`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!1,!1)},A={id:`sheet.command.sort-range-desc-ext-ctx`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!1,!0)},j={id:`sheet.command.sort-range-custom-ctx`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortCustomize()};var ee=`@univerjs/sheets-sort-ui`,te=`0.18.0`;let ne=`sheets-sort-ui.config`;Symbol(ne);let M={};function N({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,c=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),l=(0,s.useRef)(`_${oe()}`);return re(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...o},a)}function re(e,t,n,r,i){return(0,s.createElement)(e.tag,{key:t,...ie(e,n,i),...r},(ae(e,n).children||[]).map((r,a)=>re(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function ie(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function ae(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function oe(){return Math.random().toString(36).substring(2,8)}N.displayName=`UniverIcon`;let se={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.4208 14.4667C12.4208 14.798 12.1522 15.0667 11.8208 15.0667C11.4895 15.0667 11.2208 14.798 11.2208 14.4667V2.98193L9.97861 4.22417C9.7443 4.45848 9.3644 4.45848 9.13008 4.22417C8.89577 3.98985 8.89577 3.60995 9.13008 3.37564L11.3967 1.10897C11.6311 0.874657 12.011 0.874657 12.2453 1.10897L14.5119 3.37564C14.7463 3.60995 14.7463 3.98985 14.5119 4.22417C14.2776 4.45848 13.8977 4.45848 13.6634 4.22417L12.4208 2.9816V14.4667Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.98967 10.2798C1.6583 10.2798 1.38967 10.0112 1.38967 9.67983C1.38967 9.34846 1.6583 9.07983 1.98967 9.07983H6.50138C6.74406 9.07983 6.96284 9.22602 7.05571 9.45022C7.14858 9.67443 7.09725 9.9325 6.92565 10.1041L3.43819 13.5916H6.50138C6.83276 13.5916 7.10138 13.8602 7.10138 14.1916C7.10138 14.5229 6.83276 14.7916 6.50138 14.7916H1.98967C1.74699 14.7916 1.52821 14.6454 1.43534 14.4212C1.34247 14.197 1.3938 13.9389 1.5654 13.7673L5.05286 10.2798H1.98967Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.1846 1.86439C4.8641 0.989866 3.62725 0.989866 3.30674 1.86439L1.34882 7.20672C1.23479 7.51786 1.39458 7.86252 1.70571 7.97655C2.01684 8.09058 2.3615 7.93079 2.47553 7.61966L3.06159 6.02055L3.06338 6.02056H5.42975L6.01581 7.61966C6.12984 7.93079 6.4745 8.09058 6.78563 7.97655C7.09677 7.86252 7.25655 7.51786 7.14252 7.20672L5.1846 1.86439ZM4.98996 4.82056L4.24567 2.78971L3.50138 4.82056H4.98996Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},P=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`ascending-icon`,ref:t,icon:se}))});P.displayName=`AscendingIcon`;let ce={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},F=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`check-mark-icon`,ref:t,icon:ce}))});F.displayName=`CheckMarkIcon`;let le={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M9.77445 9.24306L9.77457 11.9573C9.77458 12.2887 9.50597 12.5574 9.17459 12.5574C8.84322 12.5574 8.57458 12.2888 8.57457 11.9574L8.57439 7.79509C8.57438 7.46372 8.84299 7.19508 9.17436 7.19507C9.3281 7.19493 9.48196 7.25351 9.59925 7.3708L11.3465 9.11808C11.5808 9.3524 11.5808 9.7323 11.3465 9.96661C11.1122 10.2009 10.7323 10.2009 10.498 9.96661L9.77445 9.24306Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.22584 10.5094L6.22572 7.79514C6.22571 7.46377 6.49433 7.19513 6.8257 7.19512C7.15707 7.1951 7.42571 7.46372 7.42572 7.79509L7.4259 11.9574C7.42592 12.2888 7.1573 12.5574 6.82593 12.5574C6.67228 12.5575 6.51828 12.4989 6.40104 12.3817L4.65376 10.6344C4.41945 10.4001 4.41945 10.0202 4.65376 9.78588C4.88808 9.55156 5.26798 9.55156 5.50229 9.78588L6.22584 10.5094Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.14014 3.73989C1.14014 2.30396 2.3042 1.13989 3.74014 1.13989H12.2601C13.6961 1.13989 14.8601 2.30395 14.8601 3.73989V12.2599C14.8601 13.6958 13.6961 14.8599 12.2601 14.8599H3.74014C2.3042 14.8599 1.14014 13.6958 1.14014 12.2599V3.73989ZM2.34014 5.86724V12.2599C2.34014 13.0331 2.96694 13.6599 3.74014 13.6599H12.2601C13.0333 13.6599 13.6601 13.0331 13.6601 12.2599V5.86724H2.34014ZM13.6601 4.66724H2.34014V3.73989C2.34014 2.9667 2.96694 2.33989 3.74014 2.33989H12.2601C13.0333 2.33989 13.6601 2.96669 13.6601 3.73989V4.66724Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},I=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`custom-sort-icon`,ref:t,icon:le}))});I.displayName=`CustomSortIcon`;let ue={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V13.1332C3.15332 14.2377 4.04875 15.1332 5.15332 15.1332H10.8465C11.9511 15.1332 12.8465 14.2377 12.8465 13.1331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V13.1331C11.6465 13.575 11.2884 13.9331 10.8465 13.9331H5.15332C4.71149 13.9331 4.35332 13.575 4.35332 13.1332V6.82217Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},L=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`delete-empty-icon`,ref:t,icon:ue}))});L.displayName=`DeleteEmptyIcon`;let de={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.4208 1.53335C12.4208 1.20198 12.1522 0.93335 11.8208 0.93335C11.4895 0.93335 11.2208 1.20198 11.2208 1.53335V13.0181L9.97861 11.7758C9.7443 11.5415 9.3644 11.5415 9.13008 11.7758C8.89577 12.0101 8.89577 12.39 9.13008 12.6244L11.3967 14.891C11.6311 15.1253 12.011 15.1253 12.2453 14.891L14.5119 12.6244C14.7463 12.39 14.7463 12.0101 14.5119 11.7758C14.2776 11.5415 13.8977 11.5415 13.6634 11.7758L12.4208 13.0184V1.53335Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.98967 10.2798C1.6583 10.2798 1.38967 10.0112 1.38967 9.67983C1.38967 9.34846 1.6583 9.07983 1.98967 9.07983H6.50138C6.74406 9.07983 6.96284 9.22602 7.05571 9.45022C7.14858 9.67443 7.09725 9.9325 6.92565 10.1041L3.43819 13.5916H6.50138C6.83276 13.5916 7.10138 13.8602 7.10138 14.1916C7.10138 14.5229 6.83276 14.7916 6.50138 14.7916H1.98967C1.74699 14.7916 1.52821 14.6454 1.43534 14.4212C1.34247 14.197 1.3938 13.9389 1.5654 13.7673L5.05286 10.2798H1.98967Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.1846 1.86439C4.8641 0.989866 3.62725 0.989866 3.30674 1.86439L1.34882 7.20672C1.23479 7.51786 1.39458 7.86252 1.70571 7.97655C2.01684 8.09058 2.3615 7.93079 2.47553 7.61966L3.06159 6.02055L3.06338 6.02056H5.42975L6.01581 7.61966C6.12984 7.93079 6.4745 8.09058 6.78563 7.97655C7.09677 7.86252 7.25655 7.51786 7.14252 7.20672L5.1846 1.86439ZM4.98996 4.82056L4.24567 2.78971L3.50138 4.82056H4.98996Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},R=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`descending-icon`,ref:t,icon:de}))});R.displayName=`DescendingIcon`;let fe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.9064 3.20024C1.57503 3.20024 1.3064 2.93161 1.3064 2.60024C1.3064 2.26887 1.57503 2.00024 1.9064 2.00024H4.57306C4.90443 2.00024 5.17306 2.26887 5.17306 2.60024C5.17306 2.93161 4.90443 3.20024 4.57306 3.20024H1.9064ZM1.3064 6.19985C1.3064 6.53122 1.57503 6.79985 1.9064 6.79985H5.9064C6.23777 6.79985 6.5064 6.53122 6.5064 6.19985C6.5064 5.86848 6.23777 5.59985 5.9064 5.59985H1.9064C1.57503 5.59985 1.3064 5.86848 1.3064 6.19985ZM1.9064 10.3997C1.57503 10.3997 1.3064 10.1311 1.3064 9.79971C1.3064 9.46834 1.57503 9.19971 1.9064 9.19971H7.23973C7.5711 9.19971 7.83973 9.46834 7.83973 9.79971C7.83973 10.1311 7.5711 10.3997 7.23973 10.3997H1.9064ZM1.9064 13.9996C1.57503 13.9996 1.3064 13.7309 1.3064 13.3996C1.3064 13.0682 1.57503 12.7996 1.9064 12.7996H8.57306C8.90443 12.7996 9.17306 13.0682 9.17306 13.3996C9.17306 13.7309 8.90443 13.9996 8.57306 13.9996H1.9064Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M12.4267 14.2667C12.4267 14.5981 12.1581 14.8667 11.8267 14.8667C11.4953 14.8667 11.2267 14.5981 11.2267 14.2667V3.18198L9.98447 4.42422C9.75015 4.65853 9.37026 4.65853 9.13594 4.42422C8.90163 4.1899 8.90163 3.81 9.13594 3.57569L11.4026 1.30902C11.6369 1.07471 12.0168 1.07471 12.2511 1.30902L14.5178 3.57569C14.7521 3.81 14.7521 4.1899 14.5178 4.42422C14.2835 4.65853 13.9036 4.65853 13.6693 4.42422L12.4267 3.18165V14.2667Z`}}]},z=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`expand-ascending-icon`,ref:t,icon:fe}))});z.displayName=`ExpandAscendingIcon`;let pe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.9064 12.7998C1.57503 12.7998 1.3064 13.0684 1.3064 13.3998C1.3064 13.7311 1.57503 13.9998 1.9064 13.9998H4.57306C4.90443 13.9998 5.17306 13.7311 5.17306 13.3998C5.17306 13.0684 4.90443 12.7998 4.57306 12.7998H1.9064ZM1.3064 9.80015C1.3064 9.46878 1.57503 9.20015 1.9064 9.20015H5.9064C6.23777 9.20015 6.5064 9.46878 6.5064 9.80015C6.5064 10.1315 6.23777 10.4001 5.9064 10.4001H1.9064C1.57503 10.4001 1.3064 10.1315 1.3064 9.80015ZM1.9064 5.60029C1.57503 5.60029 1.3064 5.86892 1.3064 6.20029C1.3064 6.53166 1.57503 6.80029 1.9064 6.80029H7.23973C7.5711 6.80029 7.83973 6.53166 7.83973 6.20029C7.83973 5.86892 7.5711 5.60029 7.23973 5.60029H1.9064ZM1.9064 2.00044C1.57503 2.00044 1.3064 2.26907 1.3064 2.60044C1.3064 2.93181 1.57503 3.20044 1.9064 3.20044H8.57306C8.90443 3.20044 9.17306 2.93181 9.17306 2.60044C9.17306 2.26907 8.90443 2.00044 8.57306 2.00044H1.9064Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M12.4267 1.7333C12.4267 1.40193 12.1581 1.1333 11.8267 1.1333C11.4953 1.1333 11.2267 1.40193 11.2267 1.7333V12.818L9.98447 11.5758C9.75015 11.3415 9.37026 11.3415 9.13594 11.5758C8.90163 11.8101 8.90163 12.19 9.13594 12.4243L11.4026 14.691C11.6369 14.9253 12.0168 14.9253 12.2511 14.691L14.5178 12.4243C14.7521 12.19 14.7521 11.8101 14.5178 11.5758C14.2835 11.3415 13.9036 11.3415 13.6693 11.5758L12.4267 12.8183V1.7333Z`}}]},B=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`expand-descending-icon`,ref:t,icon:pe}))});B.displayName=`ExpandDescendingIcon`;let me={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z`}}]},V=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`increase-icon`,ref:t,icon:me}))});V.displayName=`IncreaseIcon`;let he={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},H=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`more-down-icon`,ref:t,icon:he}))});H.displayName=`MoreDownIcon`;let ge={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M6 5C6.55228 5 7 4.55228 7 4C7 3.44772 6.55228 3 6 3C5.44772 3 5 3.44772 5 4C5 4.55228 5.44772 5 6 5Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6 9C6.55228 9 7 8.55229 7 8C7 7.44772 6.55228 7 6 7C5.44772 7 5 7.44772 5 8C5 8.55229 5.44772 9 6 9Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M7 12C7 12.5523 6.55228 13 6 13C5.44772 13 5 12.5523 5 12C5 11.4477 5.44772 11 6 11C6.55228 11 7 11.4477 7 12Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10 5C10.5523 5 11 4.55228 11 4C11 3.44772 10.5523 3 10 3C9.44771 3 9 3.44772 9 4C9 4.55228 9.44771 5 10 5Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M11 8C11 8.55229 10.5523 9 10 9C9.44771 9 9 8.55229 9 8C9 7.44772 9.44771 7 10 7C10.5523 7 11 7.44772 11 8Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10 13C10.5523 13 11 12.5523 11 12C11 11.4477 10.5523 11 10 11C9.44771 11 9 11.4477 9 12C9 12.5523 9.44771 13 10 13Z`}}]},U=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`sequence-icon`,ref:t,icon:ge}))});U.displayName=`SequenceIcon`;let W=`sheet.menu.sheets-sort`,G=`sheet.menu.sheets-sort-ctx`,K=`AscendingIcon`,q=`ExpandAscendingIcon`,J=`DescendingIcon`,Y=`ExpandDescendingIcon`,X=`CustomSortIcon`;function _e(e){return{id:W,type:o.MenuItemType.SUBITEMS,icon:K,tooltip:`sheets-sort.general.sort`,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetSortPermission,n.WorksheetEditPermission],rangeTypes:[n.RangeProtectionPermissionEditPoint]})}}function ve(e){return{id:S.id,icon:K,title:`sheets-sort.general.sort-asc-cur`,type:o.MenuItemType.BUTTON,hidden$:(0,u.getCurrentExclusiveRangeInterest$)(e)}}function ye(e){return{id:C.id,title:`sheets-sort.general.sort-asc-ext`,icon:q,type:o.MenuItemType.BUTTON}}function be(e){return{id:w.id,title:`sheets-sort.general.sort-desc-cur`,icon:J,type:o.MenuItemType.BUTTON}}function xe(e){return{id:T.id,title:`sheets-sort.general.sort-desc-ext`,icon:Y,type:o.MenuItemType.BUTTON}}function Se(e){return{id:E.id,title:`sheets-sort.general.sort-custom`,type:o.MenuItemType.BUTTON,icon:X}}function Ce(e){return{id:G,title:`sheets-sort.general.sort`,type:o.MenuItemType.SUBITEMS,icon:K,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetSortPermission,n.WorksheetEditPermission],rangeTypes:[n.RangeProtectionPermissionEditPoint]})}}function we(e){return{id:D.id,title:`sheets-sort.general.sort-asc-cur`,type:o.MenuItemType.BUTTON,icon:K,disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetSortPermission,n.WorksheetEditPermission],rangeTypes:[n.RangeProtectionPermissionEditPoint]})}}function Te(e){return{id:O.id,title:`sheets-sort.general.sort-asc-ext`,type:o.MenuItemType.BUTTON,icon:q,disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetSortPermission,n.WorksheetEditPermission],rangeTypes:[n.RangeProtectionPermissionEditPoint]})}}function Ee(e){return{id:k.id,title:`sheets-sort.general.sort-desc-cur`,type:o.MenuItemType.BUTTON,icon:J,disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetSortPermission,n.WorksheetEditPermission],rangeTypes:[n.RangeProtectionPermissionEditPoint]})}}function De(e){return{id:A.id,title:`sheets-sort.general.sort-desc-ext`,type:o.MenuItemType.BUTTON,icon:Y,disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetSortPermission,n.WorksheetEditPermission],rangeTypes:[n.RangeProtectionPermissionEditPoint]})}}function Oe(e){return{id:j.id,title:`sheets-sort.general.sort-custom`,type:o.MenuItemType.BUTTON,icon:X,disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetSortPermission,n.WorksheetEditPermission],rangeTypes:[n.RangeProtectionPermissionEditPoint]})}}let ke={[o.RibbonDataGroup.ORGANIZATION]:{[W]:{order:3,menuItemFactory:_e,[S.id]:{order:0,menuItemFactory:ve},[C.id]:{order:1,menuItemFactory:ye},[w.id]:{order:2,menuItemFactory:be},[T.id]:{order:3,menuItemFactory:xe},[E.id]:{order:4,menuItemFactory:Se}}},[o.ContextMenuPosition.MAIN_AREA]:{[o.ContextMenuGroup.DATA]:{[G]:{order:0,menuItemFactory:Ce,[D.id]:{order:0,menuItemFactory:we},[O.id]:{order:1,menuItemFactory:Te},[k.id]:{order:2,menuItemFactory:Ee},[A.id]:{order:3,menuItemFactory:De},[j.id]:{order:4,menuItemFactory:Oe}}}}};function Ae(){let e=(0,o.useObservable)((0,o.useDependency)(b).customSortState$);return!e||!e.location?null:(0,c.jsx)(je,{state:e})}function je({state:e}){let n=(0,o.useDependency)(r.SheetsSortService),i=(0,o.useDependency)(t.LocaleService),l=(0,o.useDependency)(b),[u,d]=(0,s.useState)(!1),[f,p]=(0,s.useState)(0),m=(0,s.useRef)(null),{range:h,unitId:g,subUnitId:_}=e.location,v=l.getTitles(u),[y,x]=(0,s.useState)([{type:r.SortType.ASC,colIndex:h.startColumn}]),S=(0,s.useCallback)((e,t)=>{let n=[...y];t===null?n.splice(e,1):n[e]=t,x(n)},[y]),C=(0,s.useCallback)((0,t.throttle)(()=>{let e=[...y],t=Ne(h,y);t!==null&&(e.push({type:r.SortType.ASC,colIndex:t}),x(e))},200),[y,h]),w=(0,s.useCallback)((e,t)=>{n.applySort({range:h,orderRules:e,hasTitle:t}),l.closeCustomSortPanel()},[n,l,h]),T=(0,s.useCallback)(()=>{l.closeCustomSortPanel()},[l]),E=(0,s.useCallback)(e=>{d(e),e?l.setSelection(g,_,{...h,startRow:h.startRow+1}):l.setSelection(g,_,h)},[l,h,_,g]);(0,s.useEffect)(()=>{m.current&&y.length>5&&(m.current.scrollTop=m.current.scrollHeight)},[y]);let D=y.length<v.length,O=y.map(e=>({...e,id:`${e.colIndex}`}));return(0,c.jsxs)(`div`,{children:[(0,c.jsxs)(`div`,{onMouseDown:e=>{e.stopPropagation()},children:[(0,c.jsxs)(`div`,{className:`univer-mb-2 univer-flex univer-items-center univer-justify-between`,children:[(0,c.jsx)(a.Checkbox,{checked:u,onChange:e=>E(!!e),children:i.t(`sheets-sort.dialog.first-row-check`)}),D?(0,c.jsxs)(`div`,{className:`
|
|
2
|
-
univer-flex univer-cursor-pointer univer-select-none univer-items-center
|
|
3
|
-
univer-text-base
|
|
4
|
-
`,onClick:C,children:[(0,c.jsx)(V,{}),(0,c.jsx)(`span`,{className:`univer-ml-1.5`,children:i.t(`sheets-sort.dialog.add-condition`)})]}):(0,c.jsxs)(`div`,{className:`
|
|
5
|
-
univer-flex univer-cursor-pointer univer-select-none univer-items-center
|
|
6
|
-
univer-text-base univer-text-primary-500
|
|
7
|
-
disabled:univer-cursor-not-allowed disabled:univer-divide-opacity-30
|
|
8
|
-
disabled:univer-text-gray-800
|
|
9
|
-
`,children:[(0,c.jsx)(V,{}),(0,c.jsx)(`span`,{className:`univer-ml-1.5 univer-text-xs`,children:i.t(`sheets-sort.dialog.add-condition`)})]})]}),(0,c.jsx)(`div`,{ref:m,className:(0,a.clsx)(`univer-max-h-[310px] univer-overflow-y-auto univer-overflow-x-hidden`,a.scrollbarClassName),onScroll:e=>{let t=e.currentTarget.scrollTop;p(t)},children:(0,c.jsx)(a.DraggableList,{list:O,onListChange:x,idKey:`id`,draggableHandle:`[data-u-comp=sort-panel-item-handler]`,itemRender:e=>(0,c.jsx)(Me,{titles:v,list:O,item:e,onChange:(e,t)=>S(t,e),scrollPosition:f}),rowHeight:32,margin:[0,12]})})]}),(0,c.jsxs)(`div`,{className:`univer-mt-5 univer-flex univer-justify-end`,children:[(0,c.jsx)(a.Button,{className:`univer-ml-3`,onClick:()=>T(),children:i.t(`sheets-sort.dialog.cancel`)}),(0,c.jsx)(a.Button,{className:`univer-ml-3`,variant:`primary`,onClick:()=>w(y,u),children:i.t(`sheets-sort.dialog.confirm`)})]})]})}function Me(e){var n;let{list:i,item:l,titles:u,onChange:d,scrollPosition:f}=e,p=(0,o.useDependency)(t.LocaleService),m=u.filter(e=>!i.some(t=>t.colIndex===e.index)||e.index===l.colIndex),h=i.findIndex(e=>e.colIndex===l.colIndex),g=(0,s.useCallback)(e=>{d({...l,colIndex:e.index},h),v(!1)},[h,l,d]),[_,v]=(0,s.useState)(!1),y=e=>{v(e)};(0,s.useEffect)(()=>{v(!1)},[f]);let b=i.length>1,x=(n=u.find(e=>e.index===l.colIndex))==null?void 0:n.label;return(0,c.jsxs)(`div`,{className:`univer-grid univer-grid-flow-col univer-grid-cols-2 univer-items-center univer-gap-2`,children:[(0,c.jsxs)(`div`,{className:`univer-flex univer-items-center`,children:[(0,c.jsx)(`div`,{"data-u-comp":`sort-panel-item-handler`,className:`
|
|
10
|
-
univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-text-base
|
|
11
|
-
univer-text-gray-700
|
|
12
|
-
`,children:(0,c.jsx)(U,{})}),(0,c.jsx)(a.Dropdown,{overlay:(0,c.jsx)(`ul`,{className:(0,a.clsx)(`
|
|
13
|
-
univer-my-0 univer-box-border univer-grid univer-max-h-[310px]
|
|
14
|
-
univer-w-[--radix-popper-anchor-width] univer-items-center univer-gap-1
|
|
15
|
-
univer-overflow-y-auto univer-overflow-x-hidden univer-rounded-lg univer-border
|
|
16
|
-
univer-bg-white univer-p-1 univer-text-base univer-shadow-lg
|
|
17
|
-
`,a.scrollbarClassName),children:m.map(e=>(0,c.jsxs)(`li`,{onClick:()=>g(e),className:`
|
|
18
|
-
univer-relative univer-box-border univer-flex univer-h-7 univer-cursor-pointer
|
|
19
|
-
univer-list-none univer-items-center univer-justify-between univer-rounded
|
|
20
|
-
univer-px-2 univer-text-sm univer-transition-all
|
|
21
|
-
hover:univer-bg-gray-100
|
|
22
|
-
dark:hover:!univer-bg-gray-700
|
|
23
|
-
`,children:[(0,c.jsx)(`span`,{className:`univer-max-w-[220px] univer-truncate`,children:e.label}),(0,c.jsx)(`span`,{children:e.index===l.colIndex&&(0,c.jsx)(F,{})})]},e.index))}),open:_,onOpenChange:y,children:(0,c.jsxs)(`div`,{className:(0,a.clsx)(`
|
|
24
|
-
univer-ml-2 univer-flex univer-w-full univer-items-center univer-justify-between
|
|
25
|
-
univer-overflow-hidden univer-rounded-md univer-py-1.5 univer-text-sm univer-text-gray-900
|
|
26
|
-
dark:!univer-text-white
|
|
27
|
-
`),children:[(0,c.jsx)(`span`,{className:`univer-max-w-[220px] univer-truncate`,children:x}),(0,c.jsx)(H,{})]})})]}),(0,c.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-end univer-gap-2`,children:[(0,c.jsxs)(a.RadioGroup,{value:l.type,onChange:e=>{d({...l,type:e},h)},children:[(0,c.jsx)(a.Radio,{value:r.SortType.ASC,children:p.t(`sheets-sort.general.sort-asc`)}),(0,c.jsx)(a.Radio,{value:r.SortType.DESC,children:p.t(`sheets-sort.general.sort-desc`)})]}),(0,c.jsx)(`a`,{className:`
|
|
28
|
-
univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-transition-colors
|
|
29
|
-
hover:univer-text-red-500
|
|
30
|
-
`,onClick:()=>d(null,h),children:!b&&(0,c.jsx)(L,{})})]})]})}function Ne(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 Pe(e){let{range:r,colIndex:i,onClose:l}=e,u=(0,o.useDependency)(b),d=(0,o.useDependency)(t.IUniverInstanceService),f=(0,o.useDependency)(t.LocaleService),p=(0,s.useCallback)(e=>{let{unitId:t,subUnitId:a}=(0,n.getSheetCommandTarget)(d)||{};if(r&&t&&a){let n={...r,startRow:r.startRow+1};u.triggerSortDirectly(e,!1,{unitId:t,subUnitId:a,range:n,colIndex:i})}else throw Error(`Cannot find the target to sort. unitId: ${t}, subUnitId: ${a}, range: ${r}, colIndex: ${i}`);l()},[r,i,u,d,l]);return(0,c.jsxs)(a.ButtonGroup,{className:`univer-mb-3 univer-w-full univer-grid-cols-2`,children:[(0,c.jsxs)(a.Button,{onClick:()=>p(!0),children:[(0,c.jsx)(P,{}),f.t(`sheets-sort.general.sort-asc`)]}),(0,c.jsxs)(a.Button,{onClick:()=>p(!1),children:[(0,c.jsx)(R,{}),f.t(`sheets-sort.general.sort-desc`)]})]})}let Z=`custom-sort-dialog`,Q=class extends t.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(ke)}_initCommands(){[S,C,w,T,E,D,O,k,A,j].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e))),this.disposeWithMe(this._sheetRenderService.registerSkeletonChangingMutations(r.SortRangeCommand.id))}_initUI(){this.disposeWithMe(this._uiPartsService.registerComponent(u.SheetsUIPart.FILTER_PANEL_EMBED_POINT,()=>(0,o.connectInjector)(Pe,this._injector))),[[`CustomSortPanel`,Ae],[K,P],[q,z],[J,R],[Y,B],[X,I]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))}),this._sheetsSortUIService.customSortState$.pipe((0,i.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,l.serializeRange)(e.range)}`},children:{label:`CustomSortPanel`},destroyOnClose:!0,defaultPosition:Fe(),preservePositionOnDestroy:!1,onClose:()=>this._closePanel(),mask:!0})}_closePanel(){this._dialogService.close(Z),queueMicrotask(()=>this._layoutService.focus())}};Q=_([g(0,t.ICommandService),g(1,o.IMenuManagerService),g(2,o.IDialogService),g(3,o.ILayoutService),g(4,o.IUIPartsService),g(5,(0,t.Inject)(u.SheetsRenderService)),g(6,(0,t.Inject)(t.LocaleService)),g(7,(0,t.Inject)(b)),g(8,(0,t.Inject)(t.Injector)),g(9,(0,t.Inject)(o.ComponentManager))],Q);function Fe(){return{x:(window.innerWidth-560)/2,y:128}}let $=class extends t.Plugin{constructor(e=M,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},M,this._config);this._configService.setConfig(ne,i)}onStarting(){[[b],[Q]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(Q)}};h($,`type`,t.UniverInstanceType.UNIVER_SHEET),h($,`pluginName`,`SHEET_SORT_UI_PLUGIN`),h($,`packageName`,ee),h($,`version`,te),$=_([(0,t.DependentOn)(r.UniverSheetsSortPlugin),g(1,(0,t.Inject)(t.Injector)),g(2,t.IConfigService)],$),e.SortRangeAscCommand=S,e.SortRangeAscExtCommand=C,e.SortRangeAscExtInCtxMenuCommand=O,e.SortRangeAscInCtxMenuCommand=D,e.SortRangeCustomCommand=E,e.SortRangeCustomInCtxMenuCommand=j,e.SortRangeDescCommand=w,e.SortRangeDescExtCommand=T,e.SortRangeDescExtInCtxMenuCommand=A,e.SortRangeDescInCtxMenuCommand=k,Object.defineProperty(e,`UniverSheetsSortUIPlugin`,{enumerable:!0,get:function(){return $}})});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`@univerjs/sheets-sort`),require(`rxjs`),require(`@univerjs/design`),require(`@univerjs/ui`),require(`react`),require(`react/jsx-runtime`),require(`@univerjs/engine-formula`),require(`@univerjs/sheets-ui`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/sheets-sort`,`rxjs`,`@univerjs/design`,`@univerjs/ui`,`react`,`react/jsx-runtime`,`@univerjs/engine-formula`,`@univerjs/sheets-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsSortUi={},e.UniverCore,e.UniverSheets,e.UniverSheetsSort,e.rxjs,e.UniverDesign,e.UniverUi,e.React,e.React,e.UniverEngineFormula,e.UniverSheetsUi))})(this,function(e,t,n,r,i,a,o,s,c,l,u){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let d=e=>{let[n,r]=(0,s.useState)(`0`),i=(0,o.useDependency)(t.LocaleService);return(0,c.jsxs)(`div`,{className:`univer-text-sm`,children:[(0,c.jsx)(`div`,{className:`extend-confirm-desc`,children:i.t(`sheets-sort.dialog.sort-reminder-desc`)}),(0,c.jsxs)(a.RadioGroup,{className:`univer-mt-4`,value:n,direction:`vertical`,onChange:t=>{r(t),e.onChange(t)},children:[(0,c.jsx)(a.Radio,{value:`0`,children:i.t(`sheets-sort.dialog.sort-reminder-no`)}),(0,c.jsx)(a.Radio,{value:`1`,children:i.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}({}),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`},b=class extends t.Disposable{constructor(e,t,n,r,a,o){super(),this._univerInstanceService=e,this._confirmService=t,this._selectionManagerService=n,this._sheetsSortService=r,this._localeService=a,this._commandService=o,h(this,`_customSortState$`,new i.BehaviorSubject(null)),h(this,`customSortState$`,this._customSortState$.asObservable())}async triggerSortDirectly(e,t,n){let i=n||await this._detectSortLocation(t);if(!i||!this._check(i))return!1;let a={orderRules:[{type:e?r.SortType.ASC:r.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,t,r){var i;let a=(i=this._univerInstanceService.getUnit(e))==null?void 0:i.getSheetBySheetId(t);if(!a)return;let o={unitId:e,subUnitId:t,selections:[{range:r,primary:(0,n.getPrimaryForRange)(r,a),style:null}]};this._commandService.executeCommand(n.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,c.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,c.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(e){let r=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),i=r.getActiveSheet(),a=r.getUnitId(),o=i.getSheetId(),s=this._selectionManagerService.getCurrentLastSelection();if(!s)return null;let c;if(e===!0)c=(0,n.expandToContinuousRange)(s.range,{up:!0,down:!0,left:!0,right:!0},i),this.setSelection(a,o,c);else if(e===!1)c=s.range;else{let e=await this.showExtendConfirm();if(e===v.CANCEL)return null;e===v.KEEP?c=s.range:(c=(0,n.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,t.IUniverInstanceService),g(1,t.IConfirmService),g(2,(0,t.Inject)(n.SheetsSelectionsService)),g(3,(0,t.Inject)(r.SheetsSortService)),g(4,(0,t.Inject)(t.LocaleService)),g(5,t.ICommandService)],b);function x(e){return n=>{let r=t.Tools.chatAtABC(n);switch(e.getCurrentLocale()){case t.LocaleType.ZH_CN:return`"${r}"列`;case t.LocaleType.EN_US:return`Column "${r}"`;default:return`Column "${r}"`}}}let S={id:`sheet.command.sort-range-asc`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!0,!1)},C={id:`sheet.command.sort-range-asc-ext`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!0,!0)},w={id:`sheet.command.sort-range-desc`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!1,!1)},T={id:`sheet.command.sort-range-desc-ext`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!1,!0)},E={id:`sheet.command.sort-range-custom`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortCustomize()},D={id:`sheet.command.sort-range-asc-ctx`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!0,!1)},O={id:`sheet.command.sort-range-asc-ext-ctx`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!0,!0)},k={id:`sheet.command.sort-range-desc-ctx`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!1,!1)},A={id:`sheet.command.sort-range-desc-ext-ctx`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortDirectly(!1,!0)},j={id:`sheet.command.sort-range-custom-ctx`,type:t.CommandType.COMMAND,handler:async e=>await e.get(b).triggerSortCustomize()};var ee=`@univerjs/sheets-sort-ui`,te=`0.19.0-insiders.20260403-3e0e122`;let ne=`sheets-sort-ui.config`;Symbol(ne);let M={};function N({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,c=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),l=(0,s.useRef)(`_${oe()}`);return re(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...o},a)}function re(e,t,n,r,i){return(0,s.createElement)(e.tag,{key:t,...ie(e,n,i),...r},(ae(e,n).children||[]).map((r,a)=>re(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function ie(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function ae(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function oe(){return Math.random().toString(36).substring(2,8)}N.displayName=`UniverIcon`;let se={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.4208 14.4667C12.4208 14.798 12.1522 15.0667 11.8208 15.0667C11.4895 15.0667 11.2208 14.798 11.2208 14.4667V2.98193L9.97861 4.22417C9.7443 4.45848 9.3644 4.45848 9.13008 4.22417C8.89577 3.98985 8.89577 3.60995 9.13008 3.37564L11.3967 1.10897C11.6311 0.874657 12.011 0.874657 12.2453 1.10897L14.5119 3.37564C14.7463 3.60995 14.7463 3.98985 14.5119 4.22417C14.2776 4.45848 13.8977 4.45848 13.6634 4.22417L12.4208 2.9816V14.4667Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.98967 10.2798C1.6583 10.2798 1.38967 10.0112 1.38967 9.67983C1.38967 9.34846 1.6583 9.07983 1.98967 9.07983H6.50138C6.74406 9.07983 6.96284 9.22602 7.05571 9.45022C7.14858 9.67443 7.09725 9.9325 6.92565 10.1041L3.43819 13.5916H6.50138C6.83276 13.5916 7.10138 13.8602 7.10138 14.1916C7.10138 14.5229 6.83276 14.7916 6.50138 14.7916H1.98967C1.74699 14.7916 1.52821 14.6454 1.43534 14.4212C1.34247 14.197 1.3938 13.9389 1.5654 13.7673L5.05286 10.2798H1.98967Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.1846 1.86439C4.8641 0.989866 3.62725 0.989866 3.30674 1.86439L1.34882 7.20672C1.23479 7.51786 1.39458 7.86252 1.70571 7.97655C2.01684 8.09058 2.3615 7.93079 2.47553 7.61966L3.06159 6.02055L3.06338 6.02056H5.42975L6.01581 7.61966C6.12984 7.93079 6.4745 8.09058 6.78563 7.97655C7.09677 7.86252 7.25655 7.51786 7.14252 7.20672L5.1846 1.86439ZM4.98996 4.82056L4.24567 2.78971L3.50138 4.82056H4.98996Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},P=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`ascending-icon`,ref:t,icon:se}))});P.displayName=`AscendingIcon`;let ce={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},F=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`check-mark-icon`,ref:t,icon:ce}))});F.displayName=`CheckMarkIcon`;let le={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M9.77445 9.24306L9.77457 11.9573C9.77458 12.2887 9.50597 12.5574 9.17459 12.5574C8.84322 12.5574 8.57458 12.2888 8.57457 11.9574L8.57439 7.79509C8.57438 7.46372 8.84299 7.19508 9.17436 7.19507C9.3281 7.19493 9.48196 7.25351 9.59925 7.3708L11.3465 9.11808C11.5808 9.3524 11.5808 9.7323 11.3465 9.96661C11.1122 10.2009 10.7323 10.2009 10.498 9.96661L9.77445 9.24306Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.22584 10.5094L6.22572 7.79514C6.22571 7.46377 6.49433 7.19513 6.8257 7.19512C7.15707 7.1951 7.42571 7.46372 7.42572 7.79509L7.4259 11.9574C7.42592 12.2888 7.1573 12.5574 6.82593 12.5574C6.67228 12.5575 6.51828 12.4989 6.40104 12.3817L4.65376 10.6344C4.41945 10.4001 4.41945 10.0202 4.65376 9.78588C4.88808 9.55156 5.26798 9.55156 5.50229 9.78588L6.22584 10.5094Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.14014 3.73989C1.14014 2.30396 2.3042 1.13989 3.74014 1.13989H12.2601C13.6961 1.13989 14.8601 2.30395 14.8601 3.73989V12.2599C14.8601 13.6958 13.6961 14.8599 12.2601 14.8599H3.74014C2.3042 14.8599 1.14014 13.6958 1.14014 12.2599V3.73989ZM2.34014 5.86724V12.2599C2.34014 13.0331 2.96694 13.6599 3.74014 13.6599H12.2601C13.0333 13.6599 13.6601 13.0331 13.6601 12.2599V5.86724H2.34014ZM13.6601 4.66724H2.34014V3.73989C2.34014 2.9667 2.96694 2.33989 3.74014 2.33989H12.2601C13.0333 2.33989 13.6601 2.96669 13.6601 3.73989V4.66724Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},I=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`custom-sort-icon`,ref:t,icon:le}))});I.displayName=`CustomSortIcon`;let ue={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V13.1332C3.15332 14.2377 4.04875 15.1332 5.15332 15.1332H10.8465C11.9511 15.1332 12.8465 14.2377 12.8465 13.1331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V13.1331C11.6465 13.575 11.2884 13.9331 10.8465 13.9331H5.15332C4.71149 13.9331 4.35332 13.575 4.35332 13.1332V6.82217Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},L=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`delete-empty-icon`,ref:t,icon:ue}))});L.displayName=`DeleteEmptyIcon`;let de={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.4208 1.53335C12.4208 1.20198 12.1522 0.93335 11.8208 0.93335C11.4895 0.93335 11.2208 1.20198 11.2208 1.53335V13.0181L9.97861 11.7758C9.7443 11.5415 9.3644 11.5415 9.13008 11.7758C8.89577 12.0101 8.89577 12.39 9.13008 12.6244L11.3967 14.891C11.6311 15.1253 12.011 15.1253 12.2453 14.891L14.5119 12.6244C14.7463 12.39 14.7463 12.0101 14.5119 11.7758C14.2776 11.5415 13.8977 11.5415 13.6634 11.7758L12.4208 13.0184V1.53335Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.98967 10.2798C1.6583 10.2798 1.38967 10.0112 1.38967 9.67983C1.38967 9.34846 1.6583 9.07983 1.98967 9.07983H6.50138C6.74406 9.07983 6.96284 9.22602 7.05571 9.45022C7.14858 9.67443 7.09725 9.9325 6.92565 10.1041L3.43819 13.5916H6.50138C6.83276 13.5916 7.10138 13.8602 7.10138 14.1916C7.10138 14.5229 6.83276 14.7916 6.50138 14.7916H1.98967C1.74699 14.7916 1.52821 14.6454 1.43534 14.4212C1.34247 14.197 1.3938 13.9389 1.5654 13.7673L5.05286 10.2798H1.98967Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.1846 1.86439C4.8641 0.989866 3.62725 0.989866 3.30674 1.86439L1.34882 7.20672C1.23479 7.51786 1.39458 7.86252 1.70571 7.97655C2.01684 8.09058 2.3615 7.93079 2.47553 7.61966L3.06159 6.02055L3.06338 6.02056H5.42975L6.01581 7.61966C6.12984 7.93079 6.4745 8.09058 6.78563 7.97655C7.09677 7.86252 7.25655 7.51786 7.14252 7.20672L5.1846 1.86439ZM4.98996 4.82056L4.24567 2.78971L3.50138 4.82056H4.98996Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},R=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`descending-icon`,ref:t,icon:de}))});R.displayName=`DescendingIcon`;let fe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.9064 3.20024C1.57503 3.20024 1.3064 2.93161 1.3064 2.60024C1.3064 2.26887 1.57503 2.00024 1.9064 2.00024H4.57306C4.90443 2.00024 5.17306 2.26887 5.17306 2.60024C5.17306 2.93161 4.90443 3.20024 4.57306 3.20024H1.9064ZM1.3064 6.19985C1.3064 6.53122 1.57503 6.79985 1.9064 6.79985H5.9064C6.23777 6.79985 6.5064 6.53122 6.5064 6.19985C6.5064 5.86848 6.23777 5.59985 5.9064 5.59985H1.9064C1.57503 5.59985 1.3064 5.86848 1.3064 6.19985ZM1.9064 10.3997C1.57503 10.3997 1.3064 10.1311 1.3064 9.79971C1.3064 9.46834 1.57503 9.19971 1.9064 9.19971H7.23973C7.5711 9.19971 7.83973 9.46834 7.83973 9.79971C7.83973 10.1311 7.5711 10.3997 7.23973 10.3997H1.9064ZM1.9064 13.9996C1.57503 13.9996 1.3064 13.7309 1.3064 13.3996C1.3064 13.0682 1.57503 12.7996 1.9064 12.7996H8.57306C8.90443 12.7996 9.17306 13.0682 9.17306 13.3996C9.17306 13.7309 8.90443 13.9996 8.57306 13.9996H1.9064Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M12.4267 14.2667C12.4267 14.5981 12.1581 14.8667 11.8267 14.8667C11.4953 14.8667 11.2267 14.5981 11.2267 14.2667V3.18198L9.98447 4.42422C9.75015 4.65853 9.37026 4.65853 9.13594 4.42422C8.90163 4.1899 8.90163 3.81 9.13594 3.57569L11.4026 1.30902C11.6369 1.07471 12.0168 1.07471 12.2511 1.30902L14.5178 3.57569C14.7521 3.81 14.7521 4.1899 14.5178 4.42422C14.2835 4.65853 13.9036 4.65853 13.6693 4.42422L12.4267 3.18165V14.2667Z`}}]},z=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`expand-ascending-icon`,ref:t,icon:fe}))});z.displayName=`ExpandAscendingIcon`;let pe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.9064 12.7998C1.57503 12.7998 1.3064 13.0684 1.3064 13.3998C1.3064 13.7311 1.57503 13.9998 1.9064 13.9998H4.57306C4.90443 13.9998 5.17306 13.7311 5.17306 13.3998C5.17306 13.0684 4.90443 12.7998 4.57306 12.7998H1.9064ZM1.3064 9.80015C1.3064 9.46878 1.57503 9.20015 1.9064 9.20015H5.9064C6.23777 9.20015 6.5064 9.46878 6.5064 9.80015C6.5064 10.1315 6.23777 10.4001 5.9064 10.4001H1.9064C1.57503 10.4001 1.3064 10.1315 1.3064 9.80015ZM1.9064 5.60029C1.57503 5.60029 1.3064 5.86892 1.3064 6.20029C1.3064 6.53166 1.57503 6.80029 1.9064 6.80029H7.23973C7.5711 6.80029 7.83973 6.53166 7.83973 6.20029C7.83973 5.86892 7.5711 5.60029 7.23973 5.60029H1.9064ZM1.9064 2.00044C1.57503 2.00044 1.3064 2.26907 1.3064 2.60044C1.3064 2.93181 1.57503 3.20044 1.9064 3.20044H8.57306C8.90443 3.20044 9.17306 2.93181 9.17306 2.60044C9.17306 2.26907 8.90443 2.00044 8.57306 2.00044H1.9064Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M12.4267 1.7333C12.4267 1.40193 12.1581 1.1333 11.8267 1.1333C11.4953 1.1333 11.2267 1.40193 11.2267 1.7333V12.818L9.98447 11.5758C9.75015 11.3415 9.37026 11.3415 9.13594 11.5758C8.90163 11.8101 8.90163 12.19 9.13594 12.4243L11.4026 14.691C11.6369 14.9253 12.0168 14.9253 12.2511 14.691L14.5178 12.4243C14.7521 12.19 14.7521 11.8101 14.5178 11.5758C14.2835 11.3415 13.9036 11.3415 13.6693 11.5758L12.4267 12.8183V1.7333Z`}}]},B=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`expand-descending-icon`,ref:t,icon:pe}))});B.displayName=`ExpandDescendingIcon`;let me={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z`}}]},V=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`increase-icon`,ref:t,icon:me}))});V.displayName=`IncreaseIcon`;let he={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},H=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`more-down-icon`,ref:t,icon:he}))});H.displayName=`MoreDownIcon`;let ge={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M6 5C6.55228 5 7 4.55228 7 4C7 3.44772 6.55228 3 6 3C5.44772 3 5 3.44772 5 4C5 4.55228 5.44772 5 6 5Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6 9C6.55228 9 7 8.55229 7 8C7 7.44772 6.55228 7 6 7C5.44772 7 5 7.44772 5 8C5 8.55229 5.44772 9 6 9Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M7 12C7 12.5523 6.55228 13 6 13C5.44772 13 5 12.5523 5 12C5 11.4477 5.44772 11 6 11C6.55228 11 7 11.4477 7 12Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10 5C10.5523 5 11 4.55228 11 4C11 3.44772 10.5523 3 10 3C9.44771 3 9 3.44772 9 4C9 4.55228 9.44771 5 10 5Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M11 8C11 8.55229 10.5523 9 10 9C9.44771 9 9 8.55229 9 8C9 7.44772 9.44771 7 10 7C10.5523 7 11 7.44772 11 8Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10 13C10.5523 13 11 12.5523 11 12C11 11.4477 10.5523 11 10 11C9.44771 11 9 11.4477 9 12C9 12.5523 9.44771 13 10 13Z`}}]},U=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(N,Object.assign({},e,{id:`sequence-icon`,ref:t,icon:ge}))});U.displayName=`SequenceIcon`;let W=`sheet.menu.sheets-sort`,G=`sheet.menu.sheets-sort-ctx`,K=`AscendingIcon`,q=`ExpandAscendingIcon`,J=`DescendingIcon`,Y=`ExpandDescendingIcon`,X=`CustomSortIcon`;function _e(e){return{id:W,type:o.MenuItemType.SUBITEMS,icon:K,tooltip:`sheets-sort.general.sort`,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetSortPermission,n.WorksheetEditPermission],rangeTypes:[n.RangeProtectionPermissionEditPoint]})}}function ve(e){return{id:S.id,icon:K,title:`sheets-sort.general.sort-asc-cur`,type:o.MenuItemType.BUTTON,hidden$:(0,u.getCurrentExclusiveRangeInterest$)(e)}}function ye(e){return{id:C.id,title:`sheets-sort.general.sort-asc-ext`,icon:q,type:o.MenuItemType.BUTTON}}function be(e){return{id:w.id,title:`sheets-sort.general.sort-desc-cur`,icon:J,type:o.MenuItemType.BUTTON}}function xe(e){return{id:T.id,title:`sheets-sort.general.sort-desc-ext`,icon:Y,type:o.MenuItemType.BUTTON}}function Se(e){return{id:E.id,title:`sheets-sort.general.sort-custom`,type:o.MenuItemType.BUTTON,icon:X}}function Ce(e){return{id:G,title:`sheets-sort.general.sort`,type:o.MenuItemType.SUBITEMS,icon:K,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetSortPermission,n.WorksheetEditPermission],rangeTypes:[n.RangeProtectionPermissionEditPoint]})}}function we(e){return{id:D.id,title:`sheets-sort.general.sort-asc-cur`,type:o.MenuItemType.BUTTON,icon:K,disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetSortPermission,n.WorksheetEditPermission],rangeTypes:[n.RangeProtectionPermissionEditPoint]})}}function Te(e){return{id:O.id,title:`sheets-sort.general.sort-asc-ext`,type:o.MenuItemType.BUTTON,icon:q,disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetSortPermission,n.WorksheetEditPermission],rangeTypes:[n.RangeProtectionPermissionEditPoint]})}}function Ee(e){return{id:k.id,title:`sheets-sort.general.sort-desc-cur`,type:o.MenuItemType.BUTTON,icon:J,disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetSortPermission,n.WorksheetEditPermission],rangeTypes:[n.RangeProtectionPermissionEditPoint]})}}function De(e){return{id:A.id,title:`sheets-sort.general.sort-desc-ext`,type:o.MenuItemType.BUTTON,icon:Y,disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetSortPermission,n.WorksheetEditPermission],rangeTypes:[n.RangeProtectionPermissionEditPoint]})}}function Oe(e){return{id:j.id,title:`sheets-sort.general.sort-custom`,type:o.MenuItemType.BUTTON,icon:X,disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetSortPermission,n.WorksheetEditPermission],rangeTypes:[n.RangeProtectionPermissionEditPoint]})}}let ke={[o.RibbonDataGroup.ORGANIZATION]:{[W]:{order:3,menuItemFactory:_e,[S.id]:{order:0,menuItemFactory:ve},[C.id]:{order:1,menuItemFactory:ye},[w.id]:{order:2,menuItemFactory:be},[T.id]:{order:3,menuItemFactory:xe},[E.id]:{order:4,menuItemFactory:Se}}},[o.ContextMenuPosition.MAIN_AREA]:{[o.ContextMenuGroup.DATA]:{[G]:{order:0,menuItemFactory:Ce,[D.id]:{order:0,menuItemFactory:we},[O.id]:{order:1,menuItemFactory:Te},[k.id]:{order:2,menuItemFactory:Ee},[A.id]:{order:3,menuItemFactory:De},[j.id]:{order:4,menuItemFactory:Oe}}}}};function Ae(){let e=(0,o.useObservable)((0,o.useDependency)(b).customSortState$);return!e||!e.location?null:(0,c.jsx)(je,{state:e})}function je({state:e}){let n=(0,o.useDependency)(r.SheetsSortService),i=(0,o.useDependency)(t.LocaleService),l=(0,o.useDependency)(b),[u,d]=(0,s.useState)(!1),[f,p]=(0,s.useState)(0),m=(0,s.useRef)(null),{range:h,unitId:g,subUnitId:_}=e.location,v=l.getTitles(u),[y,x]=(0,s.useState)([{type:r.SortType.ASC,colIndex:h.startColumn}]),S=(0,s.useCallback)((e,t)=>{let n=[...y];t===null?n.splice(e,1):n[e]=t,x(n)},[y]),C=(0,s.useCallback)((0,t.throttle)(()=>{let e=[...y],t=Ne(h,y);t!==null&&(e.push({type:r.SortType.ASC,colIndex:t}),x(e))},200),[y,h]),w=(0,s.useCallback)((e,t)=>{n.applySort({range:h,orderRules:e,hasTitle:t}),l.closeCustomSortPanel()},[n,l,h]),T=(0,s.useCallback)(()=>{l.closeCustomSortPanel()},[l]),E=(0,s.useCallback)(e=>{d(e),e?l.setSelection(g,_,{...h,startRow:h.startRow+1}):l.setSelection(g,_,h)},[l,h,_,g]);(0,s.useEffect)(()=>{m.current&&y.length>5&&(m.current.scrollTop=m.current.scrollHeight)},[y]);let D=y.length<v.length,O=y.map(e=>({...e,id:`${e.colIndex}`}));return(0,c.jsxs)(`div`,{children:[(0,c.jsxs)(`div`,{onMouseDown:e=>{e.stopPropagation()},children:[(0,c.jsxs)(`div`,{className:`univer-mb-2 univer-flex univer-items-center univer-justify-between`,children:[(0,c.jsx)(a.Checkbox,{checked:u,onChange:e=>E(!!e),children:i.t(`sheets-sort.dialog.first-row-check`)}),D?(0,c.jsxs)(`div`,{className:`univer-flex univer-cursor-pointer univer-select-none univer-items-center univer-text-base`,onClick:C,children:[(0,c.jsx)(V,{}),(0,c.jsx)(`span`,{className:`univer-ml-1.5`,children:i.t(`sheets-sort.dialog.add-condition`)})]}):(0,c.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,c.jsx)(V,{}),(0,c.jsx)(`span`,{className:`univer-ml-1.5 univer-text-xs`,children:i.t(`sheets-sort.dialog.add-condition`)})]})]}),(0,c.jsx)(`div`,{ref:m,className:(0,a.clsx)(`univer-max-h-[310px] univer-overflow-y-auto univer-overflow-x-hidden`,a.scrollbarClassName),onScroll:e=>{let t=e.currentTarget.scrollTop;p(t)},children:(0,c.jsx)(a.DraggableList,{list:O,onListChange:x,idKey:`id`,draggableHandle:`[data-u-comp=sort-panel-item-handler]`,itemRender:e=>(0,c.jsx)(Me,{titles:v,list:O,item:e,onChange:(e,t)=>S(t,e),scrollPosition:f}),rowHeight:32,margin:[0,12]})})]}),(0,c.jsxs)(`div`,{className:`univer-mt-5 univer-flex univer-justify-end`,children:[(0,c.jsx)(a.Button,{className:`univer-ml-3`,onClick:()=>T(),children:i.t(`sheets-sort.dialog.cancel`)}),(0,c.jsx)(a.Button,{className:`univer-ml-3`,variant:`primary`,onClick:()=>w(y,u),children:i.t(`sheets-sort.dialog.confirm`)})]})]})}function Me(e){var n;let{list:i,item:l,titles:u,onChange:d,scrollPosition:f}=e,p=(0,o.useDependency)(t.LocaleService),m=u.filter(e=>!i.some(t=>t.colIndex===e.index)||e.index===l.colIndex),h=i.findIndex(e=>e.colIndex===l.colIndex),g=(0,s.useCallback)(e=>{d({...l,colIndex:e.index},h),v(!1)},[h,l,d]),[_,v]=(0,s.useState)(!1),y=e=>{v(e)};(0,s.useEffect)(()=>{v(!1)},[f]);let b=i.length>1,x=(n=u.find(e=>e.index===l.colIndex))==null?void 0:n.label;return(0,c.jsxs)(`div`,{className:`univer-grid univer-grid-flow-col univer-grid-cols-2 univer-items-center univer-gap-2`,children:[(0,c.jsxs)(`div`,{className:`univer-flex univer-items-center`,children:[(0,c.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,c.jsx)(U,{})}),(0,c.jsx)(a.Dropdown,{overlay:(0,c.jsx)(`ul`,{className:(0,a.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`,a.scrollbarClassName),children:m.map(e=>(0,c.jsxs)(`li`,{onClick:()=>g(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,c.jsx)(`span`,{className:`univer-max-w-[220px] univer-truncate`,children:e.label}),(0,c.jsx)(`span`,{children:e.index===l.colIndex&&(0,c.jsx)(F,{})})]},e.index))}),open:_,onOpenChange:y,children:(0,c.jsxs)(`div`,{className:(0,a.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,c.jsx)(`span`,{className:`univer-max-w-[220px] univer-truncate`,children:x}),(0,c.jsx)(H,{})]})})]}),(0,c.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-end univer-gap-2`,children:[(0,c.jsxs)(a.RadioGroup,{value:l.type,onChange:e=>{d({...l,type:e},h)},children:[(0,c.jsx)(a.Radio,{value:r.SortType.ASC,children:p.t(`sheets-sort.general.sort-asc`)}),(0,c.jsx)(a.Radio,{value:r.SortType.DESC,children:p.t(`sheets-sort.general.sort-desc`)})]}),(0,c.jsx)(`a`,{className:`univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-transition-colors hover:univer-text-red-500`,onClick:()=>d(null,h),children:!b&&(0,c.jsx)(L,{})})]})]})}function Ne(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 Pe(e){let{range:r,colIndex:i,onClose:l}=e,u=(0,o.useDependency)(b),d=(0,o.useDependency)(t.IUniverInstanceService),f=(0,o.useDependency)(t.LocaleService),p=(0,s.useCallback)(e=>{let{unitId:t,subUnitId:a}=(0,n.getSheetCommandTarget)(d)||{};if(r&&t&&a){let n={...r,startRow:r.startRow+1};u.triggerSortDirectly(e,!1,{unitId:t,subUnitId:a,range:n,colIndex:i})}else throw Error(`Cannot find the target to sort. unitId: ${t}, subUnitId: ${a}, range: ${r}, colIndex: ${i}`);l()},[r,i,u,d,l]);return(0,c.jsxs)(a.ButtonGroup,{className:`univer-mb-3 univer-w-full univer-grid-cols-2`,children:[(0,c.jsxs)(a.Button,{onClick:()=>p(!0),children:[(0,c.jsx)(P,{}),f.t(`sheets-sort.general.sort-asc`)]}),(0,c.jsxs)(a.Button,{onClick:()=>p(!1),children:[(0,c.jsx)(R,{}),f.t(`sheets-sort.general.sort-desc`)]})]})}let Z=`custom-sort-dialog`,Q=class extends t.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(ke)}_initCommands(){[S,C,w,T,E,D,O,k,A,j].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e))),this.disposeWithMe(this._sheetRenderService.registerSkeletonChangingMutations(r.SortRangeCommand.id))}_initUI(){this.disposeWithMe(this._uiPartsService.registerComponent(u.SheetsUIPart.FILTER_PANEL_EMBED_POINT,()=>(0,o.connectInjector)(Pe,this._injector))),[[`CustomSortPanel`,Ae],[K,P],[q,z],[J,R],[Y,B],[X,I]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))}),this._sheetsSortUIService.customSortState$.pipe((0,i.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,l.serializeRange)(e.range)}`},children:{label:`CustomSortPanel`},destroyOnClose:!0,defaultPosition:Fe(),preservePositionOnDestroy:!1,onClose:()=>this._closePanel(),mask:!0})}_closePanel(){this._dialogService.close(Z),queueMicrotask(()=>this._layoutService.focus())}};Q=_([g(0,t.ICommandService),g(1,o.IMenuManagerService),g(2,o.IDialogService),g(3,o.ILayoutService),g(4,o.IUIPartsService),g(5,(0,t.Inject)(u.SheetsRenderService)),g(6,(0,t.Inject)(t.LocaleService)),g(7,(0,t.Inject)(b)),g(8,(0,t.Inject)(t.Injector)),g(9,(0,t.Inject)(o.ComponentManager))],Q);function Fe(){return{x:(window.innerWidth-560)/2,y:128}}let $=class extends t.Plugin{constructor(e=M,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},M,this._config);this._configService.setConfig(ne,i)}onStarting(){[[b],[Q]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(Q)}};h($,`type`,t.UniverInstanceType.UNIVER_SHEET),h($,`pluginName`,`SHEET_SORT_UI_PLUGIN`),h($,`packageName`,ee),h($,`version`,te),$=_([(0,t.DependentOn)(r.UniverSheetsSortPlugin),g(1,(0,t.Inject)(t.Injector)),g(2,t.IConfigService)],$),e.SortRangeAscCommand=S,e.SortRangeAscExtCommand=C,e.SortRangeAscExtInCtxMenuCommand=O,e.SortRangeAscInCtxMenuCommand=D,e.SortRangeCustomCommand=E,e.SortRangeCustomInCtxMenuCommand=j,e.SortRangeDescCommand=w,e.SortRangeDescExtCommand=T,e.SortRangeDescExtInCtxMenuCommand=A,e.SortRangeDescInCtxMenuCommand=k,Object.defineProperty(e,`UniverSheetsSortUIPlugin`,{enumerable:!0,get:function(){return $}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-sort-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0-insiders.20260403-3e0e122",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer Sheets Sort UI",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -53,23 +53,23 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@univerjs/icons": "^1.1.1",
|
|
56
|
-
"@univerjs/core": "0.
|
|
57
|
-
"@univerjs/design": "0.
|
|
58
|
-
"@univerjs/engine-formula": "0.
|
|
59
|
-
"@univerjs/sheets": "0.
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/sheets-ui": "0.
|
|
62
|
-
"@univerjs/
|
|
56
|
+
"@univerjs/core": "0.19.0-insiders.20260403-3e0e122",
|
|
57
|
+
"@univerjs/design": "0.19.0-insiders.20260403-3e0e122",
|
|
58
|
+
"@univerjs/engine-formula": "0.19.0-insiders.20260403-3e0e122",
|
|
59
|
+
"@univerjs/sheets": "0.19.0-insiders.20260403-3e0e122",
|
|
60
|
+
"@univerjs/ui": "0.19.0-insiders.20260403-3e0e122",
|
|
61
|
+
"@univerjs/sheets-ui": "0.19.0-insiders.20260403-3e0e122",
|
|
62
|
+
"@univerjs/sheets-sort": "0.19.0-insiders.20260403-3e0e122"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"postcss": "^8.5.8",
|
|
66
66
|
"react": "18.3.1",
|
|
67
67
|
"rxjs": "^7.8.2",
|
|
68
68
|
"tailwindcss": "3.4.18",
|
|
69
|
-
"typescript": "^
|
|
70
|
-
"vitest": "^4.1.
|
|
71
|
-
"@univerjs-infra/shared": "0.
|
|
72
|
-
"@univerjs/sheets-formula-ui": "0.
|
|
69
|
+
"typescript": "^6.0.2",
|
|
70
|
+
"vitest": "^4.1.1",
|
|
71
|
+
"@univerjs-infra/shared": "0.19.0",
|
|
72
|
+
"@univerjs/sheets-formula-ui": "0.19.0-insiders.20260403-3e0e122"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
75
|
"test": "vitest run",
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|