@univerjs/sheets-sort 0.2.2 → 0.2.4-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # @univerjs/sheets-sort
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@univerjs/sheets-sort)](https://npmjs.org/packages/@univerjs/sheets-sort)
4
- [![license](https://img.shields.io/npm/l/@univerjs/sheets-sort)](https://img.shields.io/npm/l/@univerjs/sheets-sort)
3
+ ## Package Overview
4
+
5
+ | Package Name | UMD Namespace | Version | License | Downloads | Contains CSS | Contains i18n locales |
6
+ | --- | --- | --- | --- | --- | :---: | :---: |
7
+ | `@univerjs/sheets-sort` | `UniverSheetsSort` | [![][npm-version-shield]][npm-version-link] | ![][npm-license-shield] | ![][npm-downloads-shield] | ❌ | ⭕️ |
5
8
 
6
9
  ## Introduction
7
10
 
@@ -20,3 +23,9 @@ npm install @univerjs/sheets-sort
20
23
  # Using pnpm
21
24
  pnpm add @univerjs/sheets-sort
22
25
  ```
26
+
27
+ <!-- Links -->
28
+ [npm-version-shield]: https://img.shields.io/npm/v/@univerjs/sheets-sort?style=flat-square
29
+ [npm-version-link]: https://npmjs.com/package/@univerjs/sheets-sort
30
+ [npm-license-shield]: https://img.shields.io/npm/l/@univerjs/sheets-sort?style=flat-square
31
+ [npm-downloads-shield]: https://img.shields.io/npm/dm/@univerjs/sheets-sort?style=flat-square
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var j=(e,r,t)=>r in e?M(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var d=(e,r,t)=>j(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),C=require("@wendellhu/redi"),I=require("@univerjs/sheets"),$=require("@univerjs/engine-formula");var f=(e=>(e.DESC="desc",e.ASC="asc",e))(f||{});const A=e=>e.replace(/-/gi,"").replace(/'/gi,""),V=(e,r)=>{const t=e===null||e==="",o=r===null||r==="";return t&&o?0:t?1:o?-1:null},x=(e,r,t)=>{const o=typeof e=="number",n=typeof r=="number";return o&&n?e<r?t===f.ASC?-1:1:e>r?t===f.ASC?1:-1:0:o?t===f.ASC?1:-1:n?t===f.ASC?-1:1:null},L=(e,r,t)=>{const o=typeof e=="string",n=typeof r=="string";if(o&&(e=A(e.toLocaleLowerCase())),n&&(r=A(r.toLocaleLowerCase())),!o&&!n)return null;if(o&&n){const s=e,i=r;return s<i?t===f.ASC?-1:1:s>i?t===f.ASC?1:-1:0}return o?t===f.ASC?1:-1:n?t===f.ASC?-1:1:null},F=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;var q=Object.defineProperty,B=Object.getOwnPropertyDescriptor,G=(e,r,t,o)=>{for(var n=o>1?void 0:o?B(r,t):r,s=e.length-1,i;s>=0;s--)(i=e[s])&&(n=(o?i(r,t,n):i(n))||n);return o&&n&&q(r,t,n),n},R=(e,r)=>(t,o)=>r(t,o,e);exports.SheetsSortService=class extends c.Disposable{constructor(t,o,n){super();d(this,"_compareFns",[]);this._univerInstanceService=t,this._commandService=o,this._formulaDataModel=n}mergeCheck(t){var u;const{unitId:o,subUnitId:n,range:s}=t,i=(u=this._univerInstanceService.getUnit(o))==null?void 0:u.getSheetBySheetId(n);if(!i)return!1;const l=i.getMergeData().filter(a=>c.Rectangle.contains(s,a));return l.length===0?!0:H(s,l)}emptyCheck(t){var l;const{unitId:o,subUnitId:n,range:s}=t,i=(l=this._univerInstanceService.getUnit(o))==null?void 0:l.getSheetBySheetId(n);if(!i)return!1;for(let u=s.startRow;u<=s.endRow;u++)for(let a=s.startColumn;a<=s.endColumn;a++)if(!F(i.getCellRaw(u,a)))return!0;return!1}singleCheck(t){return t.range.startRow!==t.range.endRow}formulaCheck(t){var l,u;const{unitId:o,subUnitId:n,range:s}=t,i=(u=(l=this._formulaDataModel.getArrayFormulaRange())==null?void 0:l[o])==null?void 0:u[n];for(const a in i){const S=i[Number(a)];for(const p in S){const g=S[Number(p)];if(g&&c.Rectangle.intersects(s,g))return!1}}return!0}registerCompareFn(t){this._compareFns.unshift(t)}getAllCompareFns(){return this._compareFns}applySort(t,o,n){var l;const{unitId:s,subUnitId:i}=I.getSheetCommandTarget(this._univerInstanceService)||{};this._commandService.executeCommand(w.id,{orderRules:t.orderRules,range:t.range,hasTitle:(l=t.hasTitle)!=null?l:!1,unitId:o||s,subUnitId:n||i})}};exports.SheetsSortService=G([c.OnLifecycle(c.LifecycleStages.Ready,exports.SheetsSortService),R(0,c.IUniverInstanceService),R(1,c.ICommandService),R(2,C.Inject($.FormulaDataModel))],exports.SheetsSortService);function H(e,r){const t=e.endRow-e.startRow+1,o=e.endColumn-e.startColumn+1;let n=null,s=null;const i=t*o;let l=0;for(const u of r)if(u.startRow>=e.startRow&&u.endRow<=e.endRow&&u.startColumn>=e.startColumn&&u.endColumn<=e.endColumn){const a=u.endRow-u.startRow+1,S=u.endColumn-u.startColumn+1;if(n===null&&s===null)n=a,s=S;else if(a!==n||S!==s)return!1;l+=a*S}return l===i}const w={id:"sheet.command.sort-range",type:c.CommandType.COMMAND,handler:(e,r)=>{const{range:t,orderRules:o,hasTitle:n,unitId:s,subUnitId:i}=r,l=e.get(exports.SheetsSortService),u=e.get(c.IUniverInstanceService),{worksheet:a}=I.getSheetCommandTarget(u,r)||{};if(!a)return!1;const S=a.getMergeData().filter(m=>c.Rectangle.contains(t,m)),p=S.map(m=>m.startRow),{startRow:g,endRow:P}=t,N=n?g+1:g,_=[],b=[];for(let m=N;m<=P;m++)a.getRowFiltered(m)||a.getRowRawVisible(m)!==!1&&(S.length&&!p.includes(m)||(_.push({index:m,value:W(a,m,o)}),b.push(m)));const O=l.getAllCompareFns();_.sort(J(o,z(O)));const y={};_.forEach(({index:m,value:ne},E)=>{y[b[E]]=m});const U={id:I.ReorderRangeCommand.id,params:{unitId:s,subUnitId:i,range:t,order:y}},T=e.get(c.ICommandService);return c.sequenceExecute([U],T).result}};function W(e,r,t){const o=[];return t.forEach(({colIndex:n})=>{o.push(e.getCellRaw(r,n))}),o}function z(e){return(r,t,o)=>{for(let n=0;n<e.length;n++){const s=e[n](r,t,o);if(s!=null)return s}return 0}}function J(e,r){return function(t,o){let n=null;for(let s=0;s<e.length;s++){const i=t.value[s],l=o.value[s];if(n=r(e[s].type,i,l),n!==0&&n!==null&&n!==void 0)return n}return 0}}var K=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,X=(e,r,t,o)=>{for(var n=o>1?void 0:o?Q(r,t):r,s=e.length-1,i;s>=0;s--)(i=e[s])&&(n=(o?i(r,t,n):i(n))||n);return o&&n&&K(r,t,n),n},D=(e,r)=>(t,o)=>r(t,o,e);let h=class extends c.Disposable{constructor(e,r){super(),this._commandService=e,this._sortService=r,this._initCommands(),this._registerCompareFns()}_initCommands(){[w].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){const e=(r,t,o)=>{const n=this._getCommonValue(t),s=this._getCommonValue(o),i=[V,L,x];for(let l=0;l<i.length;l++){const u=i[l](n,s,r);if(u!==null)return u}return null};this._sortService.registerCompareFn(e)}_getCommonValue(e){var t,o;if(F(e))return null;const r=(o=(t=e==null?void 0:e.p)==null?void 0:t.body)==null?void 0:o.dataStream;return r||((e==null?void 0:e.t)===c.CellValueType.NUMBER?Number.parseFloat(`${e.v}`):(e==null?void 0:e.t)===c.CellValueType.STRING?typeof e.v=="number"?e.v:`${e.v}`:(e==null?void 0:e.t)===c.CellValueType.BOOLEAN?`${e.v}`:(e==null?void 0:e.t)===c.CellValueType.FORCE_STRING?Number.parseFloat(`${e.v}`):`${e==null?void 0:e.v}`)}};h=X([c.OnLifecycle(c.LifecycleStages.Ready,h),D(0,c.ICommandService),D(1,C.Inject(exports.SheetsSortService))],h);var Y=Object.defineProperty,Z=Object.getOwnPropertyDescriptor,k=(e,r,t,o)=>{for(var n=o>1?void 0:o?Z(r,t):r,s=e.length-1,i;s>=0;s--)(i=e[s])&&(n=(o?i(r,t,n):i(n))||n);return o&&n&&Y(r,t,n),n},ee=(e,r)=>(t,o)=>r(t,o,e);const te="UNIVER_SHEETS_SORT_PLUGIN";var v;exports.UniverSheetsSortPlugin=(v=class extends c.Plugin{constructor(r,t){super(),this._injector=t}onStarting(r){[[h],[exports.SheetsSortService]].forEach(t=>r.add(t))}},d(v,"type",c.UniverInstanceType.UNIVER_SHEET),d(v,"pluginName",te),v);exports.UniverSheetsSortPlugin=k([ee(1,C.Inject(C.Injector))],exports.UniverSheetsSortPlugin);exports.SortRangeCommand=w;exports.SortType=f;
1
+ "use strict";var E=Object.defineProperty;var M=(e,r,t)=>r in e?E(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var d=(e,r,t)=>M(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@univerjs/core"),R=require("@univerjs/sheets"),j=require("@univerjs/engine-formula");var f=(e=>(e.DESC="desc",e.ASC="asc",e))(f||{});const y=e=>e.replace(/-/gi,"").replace(/'/gi,""),$=(e,r)=>{const t=e===null||e==="",o=r===null||r==="";return t&&o?0:t?1:o?-1:null},V=(e,r,t)=>{const o=typeof e=="number",n=typeof r=="number";return o&&n?e<r?t===f.ASC?-1:1:e>r?t===f.ASC?1:-1:0:o?t===f.ASC?1:-1:n?t===f.ASC?-1:1:null},x=(e,r,t)=>{const o=typeof e=="string",n=typeof r=="string";if(o&&(e=y(e.toLocaleLowerCase())),n&&(r=y(r.toLocaleLowerCase())),!o&&!n)return null;if(o&&n){const s=e,i=r;return s<i?t===f.ASC?-1:1:s>i?t===f.ASC?1:-1:0}return o?t===f.ASC?1:-1:n?t===f.ASC?-1:1:null},D=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;var L=Object.defineProperty,q=Object.getOwnPropertyDescriptor,B=(e,r,t,o)=>{for(var n=o>1?void 0:o?q(r,t):r,s=e.length-1,i;s>=0;s--)(i=e[s])&&(n=(o?i(r,t,n):i(n))||n);return o&&n&&L(r,t,n),n},_=(e,r)=>(t,o)=>r(t,o,e);exports.SheetsSortService=class extends u.Disposable{constructor(t,o,n){super();d(this,"_compareFns",[]);this._univerInstanceService=t,this._commandService=o,this._formulaDataModel=n}mergeCheck(t){var l;const{unitId:o,subUnitId:n,range:s}=t,i=(l=this._univerInstanceService.getUnit(o))==null?void 0:l.getSheetBySheetId(n);if(!i)return!1;const c=i.getMergeData().filter(a=>u.Rectangle.contains(s,a));return c.length===0?!0:G(s,c)}emptyCheck(t){var c;const{unitId:o,subUnitId:n,range:s}=t,i=(c=this._univerInstanceService.getUnit(o))==null?void 0:c.getSheetBySheetId(n);if(!i)return!1;for(let l=s.startRow;l<=s.endRow;l++)for(let a=s.startColumn;a<=s.endColumn;a++)if(!D(i.getCellRaw(l,a)))return!0;return!1}singleCheck(t){return t.range.startRow!==t.range.endRow}formulaCheck(t){var c,l;const{unitId:o,subUnitId:n,range:s}=t,i=(l=(c=this._formulaDataModel.getArrayFormulaRange())==null?void 0:c[o])==null?void 0:l[n];for(const a in i){const S=i[Number(a)];for(const C in S){const g=S[Number(C)];if(g&&u.Rectangle.intersects(s,g))return!1}}return!0}registerCompareFn(t){this._compareFns.unshift(t)}getAllCompareFns(){return this._compareFns}applySort(t,o,n){var c;const{unitId:s,subUnitId:i}=R.getSheetCommandTarget(this._univerInstanceService)||{};this._commandService.executeCommand(I.id,{orderRules:t.orderRules,range:t.range,hasTitle:(c=t.hasTitle)!=null?c:!1,unitId:o||s,subUnitId:n||i})}};exports.SheetsSortService=B([u.OnLifecycle(u.LifecycleStages.Ready,exports.SheetsSortService),_(0,u.IUniverInstanceService),_(1,u.ICommandService),_(2,u.Inject(j.FormulaDataModel))],exports.SheetsSortService);function G(e,r){const t=e.endRow-e.startRow+1,o=e.endColumn-e.startColumn+1;let n=null,s=null;const i=t*o;let c=0;for(const l of r)if(l.startRow>=e.startRow&&l.endRow<=e.endRow&&l.startColumn>=e.startColumn&&l.endColumn<=e.endColumn){const a=l.endRow-l.startRow+1,S=l.endColumn-l.startColumn+1;if(n===null&&s===null)n=a,s=S;else if(a!==n||S!==s)return!1;c+=a*S}return c===i}const I={id:"sheet.command.sort-range",type:u.CommandType.COMMAND,handler:(e,r)=>{const{range:t,orderRules:o,hasTitle:n,unitId:s,subUnitId:i}=r,c=e.get(exports.SheetsSortService),l=e.get(u.IUniverInstanceService),{worksheet:a}=R.getSheetCommandTarget(l,r)||{};if(!a)return!1;const S=a.getMergeData().filter(m=>u.Rectangle.contains(t,m)),C=S.map(m=>m.startRow),{startRow:g,endRow:F}=t,P=n?g+1:g,p=[],w=[];for(let m=P;m<=F;m++)a.getRowFiltered(m)||a.getRowRawVisible(m)!==!1&&(S.length&&!C.includes(m)||(p.push({index:m,value:H(a,m,o)}),w.push(m)));const N=c.getAllCompareFns();p.sort(z(o,W(N)));const b={};p.forEach(({index:m,value:re},T)=>{b[w[T]]=m});const O={id:R.ReorderRangeCommand.id,params:{unitId:s,subUnitId:i,range:t,order:b}},U=e.get(u.ICommandService);return u.sequenceExecute([O],U).result}};function H(e,r,t){const o=[];return t.forEach(({colIndex:n})=>{o.push(e.getCellRaw(r,n))}),o}function W(e){return(r,t,o)=>{for(let n=0;n<e.length;n++){const s=e[n](r,t,o);if(s!=null)return s}return 0}}function z(e,r){return function(t,o){let n=null;for(let s=0;s<e.length;s++){const i=t.value[s],c=o.value[s];if(n=r(e[s].type,i,c),n!==0&&n!==null&&n!==void 0)return n}return 0}}var J=Object.defineProperty,K=Object.getOwnPropertyDescriptor,Q=(e,r,t,o)=>{for(var n=o>1?void 0:o?K(r,t):r,s=e.length-1,i;s>=0;s--)(i=e[s])&&(n=(o?i(r,t,n):i(n))||n);return o&&n&&J(r,t,n),n},A=(e,r)=>(t,o)=>r(t,o,e);let h=class extends u.Disposable{constructor(e,r){super(),this._commandService=e,this._sortService=r,this._initCommands(),this._registerCompareFns()}_initCommands(){[I].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){const e=(r,t,o)=>{const n=this._getCommonValue(t),s=this._getCommonValue(o),i=[$,x,V];for(let c=0;c<i.length;c++){const l=i[c](n,s,r);if(l!==null)return l}return null};this._sortService.registerCompareFn(e)}_getCommonValue(e){var t,o;if(D(e))return null;const r=(o=(t=e==null?void 0:e.p)==null?void 0:t.body)==null?void 0:o.dataStream;return r||((e==null?void 0:e.t)===u.CellValueType.NUMBER?Number.parseFloat(`${e.v}`):(e==null?void 0:e.t)===u.CellValueType.STRING?typeof e.v=="number"?e.v:`${e.v}`:(e==null?void 0:e.t)===u.CellValueType.BOOLEAN?`${e.v}`:(e==null?void 0:e.t)===u.CellValueType.FORCE_STRING?Number.parseFloat(`${e.v}`):`${e==null?void 0:e.v}`)}};h=Q([u.OnLifecycle(u.LifecycleStages.Ready,h),A(0,u.ICommandService),A(1,u.Inject(exports.SheetsSortService))],h);var X=Object.defineProperty,Y=Object.getOwnPropertyDescriptor,Z=(e,r,t,o)=>{for(var n=o>1?void 0:o?Y(r,t):r,s=e.length-1,i;s>=0;s--)(i=e[s])&&(n=(o?i(r,t,n):i(n))||n);return o&&n&&X(r,t,n),n},k=(e,r)=>(t,o)=>r(t,o,e);const ee="UNIVER_SHEETS_SORT_PLUGIN";var v;exports.UniverSheetsSortPlugin=(v=class extends u.Plugin{constructor(r,t){super(),this._injector=t}onStarting(r){[[h],[exports.SheetsSortService]].forEach(t=>r.add(t))}},d(v,"type",u.UniverInstanceType.UNIVER_SHEET),d(v,"pluginName",ee),v);exports.UniverSheetsSortPlugin=Z([k(1,u.Inject(u.Injector))],exports.UniverSheetsSortPlugin);exports.SortRangeCommand=I;exports.SortType=f;
package/lib/es/index.js CHANGED
@@ -1,87 +1,86 @@
1
1
  var q = Object.defineProperty;
2
- var H = (e, r, n) => r in e ? q(e, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[r] = n;
3
- var v = (e, r, n) => H(e, typeof r != "symbol" ? r + "" : r, n);
4
- import { OnLifecycle as O, LifecycleStages as P, Disposable as E, Rectangle as R, IUniverInstanceService as U, ICommandService as w, CommandType as W, sequenceExecute as z, CellValueType as C, Plugin as J, UniverInstanceType as K } from "@univerjs/core";
5
- import { Inject as I, Injector as Q } from "@wendellhu/redi";
2
+ var H = (e, t, n) => t in e ? q(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var v = (e, t, n) => H(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { OnLifecycle as O, LifecycleStages as P, Inject as w, Disposable as E, Rectangle as R, IUniverInstanceService as U, ICommandService as I, CommandType as W, sequenceExecute as z, CellValueType as C, Plugin as J, UniverInstanceType as K, Injector as Q } from "@univerjs/core";
6
5
  import { getSheetCommandTarget as M, ReorderRangeCommand as X } from "@univerjs/sheets";
7
6
  import { FormulaDataModel as Y } from "@univerjs/engine-formula";
8
7
  var m = /* @__PURE__ */ ((e) => (e.DESC = "desc", e.ASC = "asc", e))(m || {});
9
- const F = (e) => e.replace(/-/gi, "").replace(/'/gi, ""), Z = (e, r) => {
10
- const n = e === null || e === "", o = r === null || r === "";
8
+ const F = (e) => e.replace(/-/gi, "").replace(/'/gi, ""), Z = (e, t) => {
9
+ const n = e === null || e === "", o = t === null || t === "";
11
10
  return n && o ? 0 : n ? 1 : o ? -1 : null;
12
- }, k = (e, r, n) => {
13
- const o = typeof e == "number", t = typeof r == "number";
14
- return o && t ? e < r ? n === m.ASC ? -1 : 1 : e > r ? n === m.ASC ? 1 : -1 : 0 : o ? n === m.ASC ? 1 : -1 : t ? n === m.ASC ? -1 : 1 : null;
15
- }, ee = (e, r, n) => {
16
- const o = typeof e == "string", t = typeof r == "string";
17
- if (o && (e = F(e.toLocaleLowerCase())), t && (r = F(r.toLocaleLowerCase())), !o && !t)
11
+ }, k = (e, t, n) => {
12
+ const o = typeof e == "number", r = typeof t == "number";
13
+ return o && r ? e < t ? n === m.ASC ? -1 : 1 : e > t ? n === m.ASC ? 1 : -1 : 0 : o ? n === m.ASC ? 1 : -1 : r ? n === m.ASC ? -1 : 1 : null;
14
+ }, ee = (e, t, n) => {
15
+ const o = typeof e == "string", r = typeof t == "string";
16
+ if (o && (e = F(e.toLocaleLowerCase())), r && (t = F(t.toLocaleLowerCase())), !o && !r)
18
17
  return null;
19
- if (o && t) {
20
- const s = e, u = r;
18
+ if (o && r) {
19
+ const s = e, u = t;
21
20
  return s < u ? n === m.ASC ? -1 : 1 : s > u ? n === m.ASC ? 1 : -1 : 0;
22
21
  }
23
- return o ? n === m.ASC ? 1 : -1 : t ? n === m.ASC ? -1 : 1 : null;
22
+ return o ? n === m.ASC ? 1 : -1 : r ? n === m.ASC ? -1 : 1 : null;
24
23
  }, T = (e) => !e || Object.keys(e).length === 0 || (e == null ? void 0 : e.v) == null && (e == null ? void 0 : e.p) == null;
25
- var re = Object.defineProperty, te = Object.getOwnPropertyDescriptor, ne = (e, r, n, o) => {
26
- for (var t = o > 1 ? void 0 : o ? te(r, n) : r, s = e.length - 1, u; s >= 0; s--)
27
- (u = e[s]) && (t = (o ? u(r, n, t) : u(t)) || t);
28
- return o && t && re(r, n, t), t;
29
- }, _ = (e, r) => (n, o) => r(n, o, e);
24
+ var te = Object.defineProperty, re = Object.getOwnPropertyDescriptor, ne = (e, t, n, o) => {
25
+ for (var r = o > 1 ? void 0 : o ? re(t, n) : t, s = e.length - 1, u; s >= 0; s--)
26
+ (u = e[s]) && (r = (o ? u(t, n, r) : u(r)) || r);
27
+ return o && r && te(t, n, r), r;
28
+ }, _ = (e, t) => (n, o) => t(n, o, e);
30
29
  let d = class extends E {
31
- constructor(r, n, o) {
30
+ constructor(t, n, o) {
32
31
  super();
33
32
  v(this, "_compareFns", []);
34
- this._univerInstanceService = r, this._commandService = n, this._formulaDataModel = o;
33
+ this._univerInstanceService = t, this._commandService = n, this._formulaDataModel = o;
35
34
  }
36
- mergeCheck(r) {
35
+ mergeCheck(t) {
37
36
  var l;
38
- const { unitId: n, subUnitId: o, range: t } = r, s = (l = this._univerInstanceService.getUnit(n)) == null ? void 0 : l.getSheetBySheetId(o);
37
+ const { unitId: n, subUnitId: o, range: r } = t, s = (l = this._univerInstanceService.getUnit(n)) == null ? void 0 : l.getSheetBySheetId(o);
39
38
  if (!s)
40
39
  return !1;
41
- const u = s.getMergeData().filter((i) => R.contains(t, i));
42
- return u.length === 0 ? !0 : oe(t, u);
40
+ const u = s.getMergeData().filter((i) => R.contains(r, i));
41
+ return u.length === 0 ? !0 : oe(r, u);
43
42
  }
44
- emptyCheck(r) {
43
+ emptyCheck(t) {
45
44
  var u;
46
- const { unitId: n, subUnitId: o, range: t } = r, s = (u = this._univerInstanceService.getUnit(n)) == null ? void 0 : u.getSheetBySheetId(o);
45
+ const { unitId: n, subUnitId: o, range: r } = t, s = (u = this._univerInstanceService.getUnit(n)) == null ? void 0 : u.getSheetBySheetId(o);
47
46
  if (!s)
48
47
  return !1;
49
- for (let l = t.startRow; l <= t.endRow; l++)
50
- for (let i = t.startColumn; i <= t.endColumn; i++)
48
+ for (let l = r.startRow; l <= r.endRow; l++)
49
+ for (let i = r.startColumn; i <= r.endColumn; i++)
51
50
  if (!T(s.getCellRaw(l, i)))
52
51
  return !0;
53
52
  return !1;
54
53
  }
55
- singleCheck(r) {
56
- return r.range.startRow !== r.range.endRow;
54
+ singleCheck(t) {
55
+ return t.range.startRow !== t.range.endRow;
57
56
  }
58
- formulaCheck(r) {
57
+ formulaCheck(t) {
59
58
  var u, l;
60
- const { unitId: n, subUnitId: o, range: t } = r, s = (l = (u = this._formulaDataModel.getArrayFormulaRange()) == null ? void 0 : u[n]) == null ? void 0 : l[o];
59
+ const { unitId: n, subUnitId: o, range: r } = t, s = (l = (u = this._formulaDataModel.getArrayFormulaRange()) == null ? void 0 : u[n]) == null ? void 0 : l[o];
61
60
  for (const i in s) {
62
61
  const a = s[Number(i)];
63
62
  for (const f in a) {
64
63
  const g = a[Number(f)];
65
- if (g && R.intersects(t, g))
64
+ if (g && R.intersects(r, g))
66
65
  return !1;
67
66
  }
68
67
  }
69
68
  return !0;
70
69
  }
71
- registerCompareFn(r) {
72
- this._compareFns.unshift(r);
70
+ registerCompareFn(t) {
71
+ this._compareFns.unshift(t);
73
72
  }
74
73
  getAllCompareFns() {
75
74
  return this._compareFns;
76
75
  }
77
- applySort(r, n, o) {
76
+ applySort(t, n, o) {
78
77
  var u;
79
- const { unitId: t, subUnitId: s } = M(this._univerInstanceService) || {};
78
+ const { unitId: r, subUnitId: s } = M(this._univerInstanceService) || {};
80
79
  this._commandService.executeCommand($.id, {
81
- orderRules: r.orderRules,
82
- range: r.range,
83
- hasTitle: (u = r.hasTitle) != null ? u : !1,
84
- unitId: n || t,
80
+ orderRules: t.orderRules,
81
+ range: t.range,
82
+ hasTitle: (u = t.hasTitle) != null ? u : !1,
83
+ unitId: n || r,
85
84
  subUnitId: o || s
86
85
  });
87
86
  }
@@ -89,20 +88,20 @@ let d = class extends E {
89
88
  d = ne([
90
89
  O(P.Ready, d),
91
90
  _(0, U),
92
- _(1, w),
93
- _(2, I(Y))
91
+ _(1, I),
92
+ _(2, w(Y))
94
93
  ], d);
95
- function oe(e, r) {
94
+ function oe(e, t) {
96
95
  const n = e.endRow - e.startRow + 1, o = e.endColumn - e.startColumn + 1;
97
- let t = null, s = null;
96
+ let r = null, s = null;
98
97
  const u = n * o;
99
98
  let l = 0;
100
- for (const i of r)
99
+ for (const i of t)
101
100
  if (i.startRow >= e.startRow && i.endRow <= e.endRow && i.startColumn >= e.startColumn && i.endColumn <= e.endColumn) {
102
101
  const a = i.endRow - i.startRow + 1, f = i.endColumn - i.startColumn + 1;
103
- if (t === null && s === null)
104
- t = a, s = f;
105
- else if (a !== t || f !== s)
102
+ if (r === null && s === null)
103
+ r = a, s = f;
104
+ else if (a !== r || f !== s)
106
105
  return !1;
107
106
  l += a * f;
108
107
  }
@@ -111,11 +110,11 @@ function oe(e, r) {
111
110
  const $ = {
112
111
  id: "sheet.command.sort-range",
113
112
  type: W.COMMAND,
114
- handler: (e, r) => {
115
- const { range: n, orderRules: o, hasTitle: t, unitId: s, subUnitId: u } = r, l = e.get(d), i = e.get(U), { worksheet: a } = M(i, r) || {};
113
+ handler: (e, t) => {
114
+ const { range: n, orderRules: o, hasTitle: r, unitId: s, subUnitId: u } = t, l = e.get(d), i = e.get(U), { worksheet: a } = M(i, t) || {};
116
115
  if (!a)
117
116
  return !1;
118
- const f = a.getMergeData().filter((c) => R.contains(n, c)), g = f.map((c) => c.startRow), { startRow: b, endRow: x } = n, j = t ? b + 1 : b, S = [], A = [];
117
+ const f = a.getMergeData().filter((c) => R.contains(n, c)), g = f.map((c) => c.startRow), { startRow: b, endRow: x } = n, j = r ? b + 1 : b, S = [], A = [];
119
118
  for (let c = j; c <= x; c++)
120
119
  a.getRowFiltered(c) || a.getRowRawVisible(c) !== !1 && (f.length && !g.includes(c) || (S.push({
121
120
  index: c,
@@ -135,45 +134,45 @@ const $ = {
135
134
  range: n,
136
135
  order: D
137
136
  }
138
- }, B = e.get(w);
137
+ }, B = e.get(I);
139
138
  return z([L], B).result;
140
139
  }
141
140
  };
142
- function se(e, r, n) {
141
+ function se(e, t, n) {
143
142
  const o = [];
144
- return n.forEach(({ colIndex: t }) => {
145
- o.push(e.getCellRaw(r, t));
143
+ return n.forEach(({ colIndex: r }) => {
144
+ o.push(e.getCellRaw(t, r));
146
145
  }), o;
147
146
  }
148
147
  function ue(e) {
149
- return (r, n, o) => {
150
- for (let t = 0; t < e.length; t++) {
151
- const s = e[t](r, n, o);
148
+ return (t, n, o) => {
149
+ for (let r = 0; r < e.length; r++) {
150
+ const s = e[r](t, n, o);
152
151
  if (s != null)
153
152
  return s;
154
153
  }
155
154
  return 0;
156
155
  };
157
156
  }
158
- function ie(e, r) {
157
+ function ie(e, t) {
159
158
  return function(n, o) {
160
- let t = null;
159
+ let r = null;
161
160
  for (let s = 0; s < e.length; s++) {
162
161
  const u = n.value[s], l = o.value[s];
163
- if (t = r(e[s].type, u, l), t !== 0 && t !== null && t !== void 0)
164
- return t;
162
+ if (r = t(e[s].type, u, l), r !== 0 && r !== null && r !== void 0)
163
+ return r;
165
164
  }
166
165
  return 0;
167
166
  };
168
167
  }
169
- var le = Object.defineProperty, ce = Object.getOwnPropertyDescriptor, ae = (e, r, n, o) => {
170
- for (var t = o > 1 ? void 0 : o ? ce(r, n) : r, s = e.length - 1, u; s >= 0; s--)
171
- (u = e[s]) && (t = (o ? u(r, n, t) : u(t)) || t);
172
- return o && t && le(r, n, t), t;
173
- }, N = (e, r) => (n, o) => r(n, o, e);
168
+ var le = Object.defineProperty, ce = Object.getOwnPropertyDescriptor, ae = (e, t, n, o) => {
169
+ for (var r = o > 1 ? void 0 : o ? ce(t, n) : t, s = e.length - 1, u; s >= 0; s--)
170
+ (u = e[s]) && (r = (o ? u(t, n, r) : u(r)) || r);
171
+ return o && r && le(t, n, r), r;
172
+ }, N = (e, t) => (n, o) => t(n, o, e);
174
173
  let p = class extends E {
175
- constructor(e, r) {
176
- super(), this._commandService = e, this._sortService = r, this._initCommands(), this._registerCompareFns();
174
+ constructor(e, t) {
175
+ super(), this._commandService = e, this._sortService = t, this._initCommands(), this._registerCompareFns();
177
176
  }
178
177
  _initCommands() {
179
178
  [
@@ -181,14 +180,14 @@ let p = class extends E {
181
180
  ].forEach((e) => this.disposeWithMe(this._commandService.registerCommand(e)));
182
181
  }
183
182
  _registerCompareFns() {
184
- const e = (r, n, o) => {
185
- const t = this._getCommonValue(n), s = this._getCommonValue(o), u = [
183
+ const e = (t, n, o) => {
184
+ const r = this._getCommonValue(n), s = this._getCommonValue(o), u = [
186
185
  Z,
187
186
  ee,
188
187
  k
189
188
  ];
190
189
  for (let l = 0; l < u.length; l++) {
191
- const i = u[l](t, s, r);
190
+ const i = u[l](r, s, t);
192
191
  if (i !== null)
193
192
  return i;
194
193
  }
@@ -200,35 +199,35 @@ let p = class extends E {
200
199
  var n, o;
201
200
  if (T(e))
202
201
  return null;
203
- const r = (o = (n = e == null ? void 0 : e.p) == null ? void 0 : n.body) == null ? void 0 : o.dataStream;
204
- return r || ((e == null ? void 0 : e.t) === C.NUMBER ? Number.parseFloat(`${e.v}`) : (e == null ? void 0 : e.t) === C.STRING ? typeof e.v == "number" ? e.v : `${e.v}` : (e == null ? void 0 : e.t) === C.BOOLEAN ? `${e.v}` : (e == null ? void 0 : e.t) === C.FORCE_STRING ? Number.parseFloat(`${e.v}`) : `${e == null ? void 0 : e.v}`);
202
+ const t = (o = (n = e == null ? void 0 : e.p) == null ? void 0 : n.body) == null ? void 0 : o.dataStream;
203
+ return t || ((e == null ? void 0 : e.t) === C.NUMBER ? Number.parseFloat(`${e.v}`) : (e == null ? void 0 : e.t) === C.STRING ? typeof e.v == "number" ? e.v : `${e.v}` : (e == null ? void 0 : e.t) === C.BOOLEAN ? `${e.v}` : (e == null ? void 0 : e.t) === C.FORCE_STRING ? Number.parseFloat(`${e.v}`) : `${e == null ? void 0 : e.v}`);
205
204
  }
206
205
  };
207
206
  p = ae([
208
207
  O(P.Ready, p),
209
- N(0, w),
210
- N(1, I(d))
208
+ N(0, I),
209
+ N(1, w(d))
211
210
  ], p);
212
- var me = Object.defineProperty, fe = Object.getOwnPropertyDescriptor, de = (e, r, n, o) => {
213
- for (var t = o > 1 ? void 0 : o ? fe(r, n) : r, s = e.length - 1, u; s >= 0; s--)
214
- (u = e[s]) && (t = (o ? u(r, n, t) : u(t)) || t);
215
- return o && t && me(r, n, t), t;
216
- }, ge = (e, r) => (n, o) => r(n, o, e);
211
+ var me = Object.defineProperty, fe = Object.getOwnPropertyDescriptor, de = (e, t, n, o) => {
212
+ for (var r = o > 1 ? void 0 : o ? fe(t, n) : t, s = e.length - 1, u; s >= 0; s--)
213
+ (u = e[s]) && (r = (o ? u(t, n, r) : u(r)) || r);
214
+ return o && r && me(t, n, r), r;
215
+ }, ge = (e, t) => (n, o) => t(n, o, e);
217
216
  const ve = "UNIVER_SHEETS_SORT_PLUGIN";
218
217
  var h;
219
218
  let y = (h = class extends J {
220
- constructor(e, r) {
221
- super(), this._injector = r;
219
+ constructor(e, t) {
220
+ super(), this._injector = t;
222
221
  }
223
222
  onStarting(e) {
224
223
  [
225
224
  [p],
226
225
  [d]
227
- ].forEach((r) => e.add(r));
226
+ ].forEach((t) => e.add(t));
228
227
  }
229
228
  }, v(h, "type", K.UNIVER_SHEET), v(h, "pluginName", ve), h);
230
229
  y = de([
231
- ge(1, I(Q))
230
+ ge(1, w(Q))
232
231
  ], y);
233
232
  export {
234
233
  d as SheetsSortService,
@@ -0,0 +1,15 @@
1
+ {
2
+ "sheetsSort": {
3
+ "title": "Sort",
4
+ "toolbar": {
5
+ "sort-asc": "ascending order",
6
+ "sort-desc": "descending order",
7
+ "sort-custom": "custom order"
8
+ },
9
+ "context-menu": {
10
+ "sort-asc": "ascending order",
11
+ "sort-desc": "descending order",
12
+ "sort-custom": "custom order"
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "sheetsSort": {
3
+ "title": "Sắp xếp",
4
+ "toolbar": {
5
+ "sort-asc": "Tăng dần",
6
+ "sort-desc": "Giảm dần",
7
+ "sort-custom": "Sắp xếp tùy chỉnh"
8
+ },
9
+ "context-menu": {
10
+ "sort-asc": "Tăng dần",
11
+ "sort-desc": "Giảm dần",
12
+ "sort-custom": "Sắp xếp tùy chỉnh"
13
+ }
14
+ }
15
+ }
@@ -1,5 +1,4 @@
1
- import { IWorkbookData, Univer, Workbook } from '@univerjs/core';
2
- import { Dependency, Injector } from '@wendellhu/redi';
1
+ import { Dependency, IWorkbookData, Workbook, Injector, Univer } from '@univerjs/core';
3
2
 
4
3
  export interface ITestBed {
5
4
  univer: Univer;
@@ -0,0 +1,4 @@
1
+ import { default as zhCN } from './zh-CN';
2
+
3
+ declare const locale: typeof zhCN;
4
+ export default locale;
@@ -0,0 +1,4 @@
1
+ import { default as zhCN } from './zh-CN';
2
+
3
+ declare const locale: typeof zhCN;
4
+ export default locale;
@@ -1,5 +1,4 @@
1
- import { Plugin, UniverInstanceType } from '@univerjs/core';
2
- import { Injector } from '@wendellhu/redi';
1
+ import { Injector, Plugin, UniverInstanceType } from '@univerjs/core';
3
2
 
4
3
  export declare class UniverSheetsSortPlugin extends Plugin {
5
4
  protected readonly _injector: Injector;
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(l,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/sheets"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/sheets","@univerjs/engine-formula"],i):(l=typeof globalThis<"u"?globalThis:l||self,i(l.UniverSheetsSort={},l.UniverCore,l["@wendellhu/redi"],l.UniverSheets,l.UniverEngineFormula))})(this,function(l,i,S,p,P){"use strict";var te=Object.defineProperty;var re=(l,i,S)=>i in l?te(l,i,{enumerable:!0,configurable:!0,writable:!0,value:S}):l[i]=S;var _=(l,i,S)=>re(l,typeof i!="symbol"?i+"":i,S);var C;var d=(e=>(e.DESC="desc",e.ASC="asc",e))(d||{});const b=e=>e.replace(/-/gi,"").replace(/'/gi,""),N=(e,s)=>{const t=e===null||e==="",n=s===null||s==="";return t&&n?0:t?1:n?-1:null},O=(e,s,t)=>{const n=typeof e=="number",r=typeof s=="number";return n&&r?e<s?t===d.ASC?-1:1:e>s?t===d.ASC?1:-1:0:n?t===d.ASC?1:-1:r?t===d.ASC?-1:1:null},T=(e,s,t)=>{const n=typeof e=="string",r=typeof s=="string";if(n&&(e=b(e.toLocaleLowerCase())),r&&(s=b(s.toLocaleLowerCase())),!n&&!r)return null;if(n&&r){const o=e,u=s;return o<u?t===d.ASC?-1:1:o>u?t===d.ASC?1:-1:0}return n?t===d.ASC?1:-1:r?t===d.ASC?-1:1:null},A=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;var j=Object.defineProperty,E=Object.getOwnPropertyDescriptor,M=(e,s,t,n)=>{for(var r=n>1?void 0:n?E(s,t):s,o=e.length-1,u;o>=0;o--)(u=e[o])&&(r=(n?u(s,t,r):u(r))||r);return n&&r&&j(s,t,r),r},R=(e,s)=>(t,n)=>s(t,n,e);l.SheetsSortService=class extends i.Disposable{constructor(t,n,r){super();_(this,"_compareFns",[]);this._univerInstanceService=t,this._commandService=n,this._formulaDataModel=r}mergeCheck(t){var a;const{unitId:n,subUnitId:r,range:o}=t,u=(a=this._univerInstanceService.getUnit(n))==null?void 0:a.getSheetBySheetId(r);if(!u)return!1;const c=u.getMergeData().filter(f=>i.Rectangle.contains(o,f));return c.length===0?!0:$(o,c)}emptyCheck(t){var c;const{unitId:n,subUnitId:r,range:o}=t,u=(c=this._univerInstanceService.getUnit(n))==null?void 0:c.getSheetBySheetId(r);if(!u)return!1;for(let a=o.startRow;a<=o.endRow;a++)for(let f=o.startColumn;f<=o.endColumn;f++)if(!A(u.getCellRaw(a,f)))return!0;return!1}singleCheck(t){return t.range.startRow!==t.range.endRow}formulaCheck(t){var c,a;const{unitId:n,subUnitId:r,range:o}=t,u=(a=(c=this._formulaDataModel.getArrayFormulaRange())==null?void 0:c[n])==null?void 0:a[r];for(const f in u){const v=u[Number(f)];for(const I in v){const g=v[Number(I)];if(g&&i.Rectangle.intersects(o,g))return!1}}return!0}registerCompareFn(t){this._compareFns.unshift(t)}getAllCompareFns(){return this._compareFns}applySort(t,n,r){var c;const{unitId:o,subUnitId:u}=p.getSheetCommandTarget(this._univerInstanceService)||{};this._commandService.executeCommand(w.id,{orderRules:t.orderRules,range:t.range,hasTitle:(c=t.hasTitle)!=null?c:!1,unitId:n||o,subUnitId:r||u})}},l.SheetsSortService=M([i.OnLifecycle(i.LifecycleStages.Ready,l.SheetsSortService),R(0,i.IUniverInstanceService),R(1,i.ICommandService),R(2,S.Inject(P.FormulaDataModel))],l.SheetsSortService);function $(e,s){const t=e.endRow-e.startRow+1,n=e.endColumn-e.startColumn+1;let r=null,o=null;const u=t*n;let c=0;for(const a of s)if(a.startRow>=e.startRow&&a.endRow<=e.endRow&&a.startColumn>=e.startColumn&&a.endColumn<=e.endColumn){const f=a.endRow-a.startRow+1,v=a.endColumn-a.startColumn+1;if(r===null&&o===null)r=f,o=v;else if(f!==r||v!==o)return!1;c+=f*v}return c===u}const w={id:"sheet.command.sort-range",type:i.CommandType.COMMAND,handler:(e,s)=>{const{range:t,orderRules:n,hasTitle:r,unitId:o,subUnitId:u}=s,c=e.get(l.SheetsSortService),a=e.get(i.IUniverInstanceService),{worksheet:f}=p.getSheetCommandTarget(a,s)||{};if(!f)return!1;const v=f.getMergeData().filter(m=>i.Rectangle.contains(t,m)),I=v.map(m=>m.startRow),{startRow:g,endRow:Q}=t,X=r?g+1:g,y=[],D=[];for(let m=X;m<=Q;m++)f.getRowFiltered(m)||f.getRowRawVisible(m)!==!1&&(v.length&&!I.includes(m)||(y.push({index:m,value:V(f,m,n)}),D.push(m)));const Y=c.getAllCompareFns();y.sort(q(n,L(Y)));const F={};y.forEach(({index:m,value:se},ee)=>{F[D[ee]]=m});const Z={id:p.ReorderRangeCommand.id,params:{unitId:o,subUnitId:u,range:t,order:F}},k=e.get(i.ICommandService);return i.sequenceExecute([Z],k).result}};function V(e,s,t){const n=[];return t.forEach(({colIndex:r})=>{n.push(e.getCellRaw(s,r))}),n}function L(e){return(s,t,n)=>{for(let r=0;r<e.length;r++){const o=e[r](s,t,n);if(o!=null)return o}return 0}}function q(e,s){return function(t,n){let r=null;for(let o=0;o<e.length;o++){const u=t.value[o],c=n.value[o];if(r=s(e[o].type,u,c),r!==0&&r!==null&&r!==void 0)return r}return 0}}var B=Object.defineProperty,G=Object.getOwnPropertyDescriptor,H=(e,s,t,n)=>{for(var r=n>1?void 0:n?G(s,t):s,o=e.length-1,u;o>=0;o--)(u=e[o])&&(r=(n?u(s,t,r):u(r))||r);return n&&r&&B(s,t,r),r},U=(e,s)=>(t,n)=>s(t,n,e);let h=class extends i.Disposable{constructor(e,s){super(),this._commandService=e,this._sortService=s,this._initCommands(),this._registerCompareFns()}_initCommands(){[w].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){const e=(s,t,n)=>{const r=this._getCommonValue(t),o=this._getCommonValue(n),u=[N,T,O];for(let c=0;c<u.length;c++){const a=u[c](r,o,s);if(a!==null)return a}return null};this._sortService.registerCompareFn(e)}_getCommonValue(e){var t,n;if(A(e))return null;const s=(n=(t=e==null?void 0:e.p)==null?void 0:t.body)==null?void 0:n.dataStream;return s||((e==null?void 0:e.t)===i.CellValueType.NUMBER?Number.parseFloat(`${e.v}`):(e==null?void 0:e.t)===i.CellValueType.STRING?typeof e.v=="number"?e.v:`${e.v}`:(e==null?void 0:e.t)===i.CellValueType.BOOLEAN?`${e.v}`:(e==null?void 0:e.t)===i.CellValueType.FORCE_STRING?Number.parseFloat(`${e.v}`):`${e==null?void 0:e.v}`)}};h=H([i.OnLifecycle(i.LifecycleStages.Ready,h),U(0,i.ICommandService),U(1,S.Inject(l.SheetsSortService))],h);var x=Object.defineProperty,W=Object.getOwnPropertyDescriptor,z=(e,s,t,n)=>{for(var r=n>1?void 0:n?W(s,t):s,o=e.length-1,u;o>=0;o--)(u=e[o])&&(r=(n?u(s,t,r):u(r))||r);return n&&r&&x(s,t,r),r},J=(e,s)=>(t,n)=>s(t,n,e);const K="UNIVER_SHEETS_SORT_PLUGIN";l.UniverSheetsSortPlugin=(C=class extends i.Plugin{constructor(s,t){super(),this._injector=t}onStarting(s){[[h],[l.SheetsSortService]].forEach(t=>s.add(t))}},_(C,"type",i.UniverInstanceType.UNIVER_SHEET),_(C,"pluginName",K),C),l.UniverSheetsSortPlugin=z([J(1,S.Inject(S.Injector))],l.UniverSheetsSortPlugin),l.SortRangeCommand=w,l.SortType=d,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
1
+ (function(l,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-formula"],i):(l=typeof globalThis<"u"?globalThis:l||self,i(l.UniverSheetsSort={},l.UniverCore,l.UniverSheets,l.UniverEngineFormula))})(this,function(l,i,v,F){"use strict";var ee=Object.defineProperty;var te=(l,i,v)=>i in l?ee(l,i,{enumerable:!0,configurable:!0,writable:!0,value:v}):l[i]=v;var _=(l,i,v)=>te(l,typeof i!="symbol"?i+"":i,v);var C;var S=(e=>(e.DESC="desc",e.ASC="asc",e))(S||{});const y=e=>e.replace(/-/gi,"").replace(/'/gi,""),P=(e,s)=>{const t=e===null||e==="",n=s===null||s==="";return t&&n?0:t?1:n?-1:null},N=(e,s,t)=>{const n=typeof e=="number",r=typeof s=="number";return n&&r?e<s?t===S.ASC?-1:1:e>s?t===S.ASC?1:-1:0:n?t===S.ASC?1:-1:r?t===S.ASC?-1:1:null},O=(e,s,t)=>{const n=typeof e=="string",r=typeof s=="string";if(n&&(e=y(e.toLocaleLowerCase())),r&&(s=y(s.toLocaleLowerCase())),!n&&!r)return null;if(n&&r){const o=e,u=s;return o<u?t===S.ASC?-1:1:o>u?t===S.ASC?1:-1:0}return n?t===S.ASC?1:-1:r?t===S.ASC?-1:1:null},b=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;var T=Object.defineProperty,j=Object.getOwnPropertyDescriptor,E=(e,s,t,n)=>{for(var r=n>1?void 0:n?j(s,t):s,o=e.length-1,u;o>=0;o--)(u=e[o])&&(r=(n?u(s,t,r):u(r))||r);return n&&r&&T(s,t,r),r},p=(e,s)=>(t,n)=>s(t,n,e);l.SheetsSortService=class extends i.Disposable{constructor(t,n,r){super();_(this,"_compareFns",[]);this._univerInstanceService=t,this._commandService=n,this._formulaDataModel=r}mergeCheck(t){var a;const{unitId:n,subUnitId:r,range:o}=t,u=(a=this._univerInstanceService.getUnit(n))==null?void 0:a.getSheetBySheetId(r);if(!u)return!1;const c=u.getMergeData().filter(f=>i.Rectangle.contains(o,f));return c.length===0?!0:M(o,c)}emptyCheck(t){var c;const{unitId:n,subUnitId:r,range:o}=t,u=(c=this._univerInstanceService.getUnit(n))==null?void 0:c.getSheetBySheetId(r);if(!u)return!1;for(let a=o.startRow;a<=o.endRow;a++)for(let f=o.startColumn;f<=o.endColumn;f++)if(!b(u.getCellRaw(a,f)))return!0;return!1}singleCheck(t){return t.range.startRow!==t.range.endRow}formulaCheck(t){var c,a;const{unitId:n,subUnitId:r,range:o}=t,u=(a=(c=this._formulaDataModel.getArrayFormulaRange())==null?void 0:c[n])==null?void 0:a[r];for(const f in u){const d=u[Number(f)];for(const I in d){const g=d[Number(I)];if(g&&i.Rectangle.intersects(o,g))return!1}}return!0}registerCompareFn(t){this._compareFns.unshift(t)}getAllCompareFns(){return this._compareFns}applySort(t,n,r){var c;const{unitId:o,subUnitId:u}=v.getSheetCommandTarget(this._univerInstanceService)||{};this._commandService.executeCommand(R.id,{orderRules:t.orderRules,range:t.range,hasTitle:(c=t.hasTitle)!=null?c:!1,unitId:n||o,subUnitId:r||u})}},l.SheetsSortService=E([i.OnLifecycle(i.LifecycleStages.Ready,l.SheetsSortService),p(0,i.IUniverInstanceService),p(1,i.ICommandService),p(2,i.Inject(F.FormulaDataModel))],l.SheetsSortService);function M(e,s){const t=e.endRow-e.startRow+1,n=e.endColumn-e.startColumn+1;let r=null,o=null;const u=t*n;let c=0;for(const a of s)if(a.startRow>=e.startRow&&a.endRow<=e.endRow&&a.startColumn>=e.startColumn&&a.endColumn<=e.endColumn){const f=a.endRow-a.startRow+1,d=a.endColumn-a.startColumn+1;if(r===null&&o===null)r=f,o=d;else if(f!==r||d!==o)return!1;c+=f*d}return c===u}const R={id:"sheet.command.sort-range",type:i.CommandType.COMMAND,handler:(e,s)=>{const{range:t,orderRules:n,hasTitle:r,unitId:o,subUnitId:u}=s,c=e.get(l.SheetsSortService),a=e.get(i.IUniverInstanceService),{worksheet:f}=v.getSheetCommandTarget(a,s)||{};if(!f)return!1;const d=f.getMergeData().filter(m=>i.Rectangle.contains(t,m)),I=d.map(m=>m.startRow),{startRow:g,endRow:K}=t,Q=r?g+1:g,w=[],U=[];for(let m=Q;m<=K;m++)f.getRowFiltered(m)||f.getRowRawVisible(m)!==!1&&(d.length&&!I.includes(m)||(w.push({index:m,value:$(f,m,n)}),U.push(m)));const X=c.getAllCompareFns();w.sort(L(n,V(X)));const D={};w.forEach(({index:m,value:ne},k)=>{D[U[k]]=m});const Y={id:v.ReorderRangeCommand.id,params:{unitId:o,subUnitId:u,range:t,order:D}},Z=e.get(i.ICommandService);return i.sequenceExecute([Y],Z).result}};function $(e,s,t){const n=[];return t.forEach(({colIndex:r})=>{n.push(e.getCellRaw(s,r))}),n}function V(e){return(s,t,n)=>{for(let r=0;r<e.length;r++){const o=e[r](s,t,n);if(o!=null)return o}return 0}}function L(e,s){return function(t,n){let r=null;for(let o=0;o<e.length;o++){const u=t.value[o],c=n.value[o];if(r=s(e[o].type,u,c),r!==0&&r!==null&&r!==void 0)return r}return 0}}var q=Object.defineProperty,B=Object.getOwnPropertyDescriptor,G=(e,s,t,n)=>{for(var r=n>1?void 0:n?B(s,t):s,o=e.length-1,u;o>=0;o--)(u=e[o])&&(r=(n?u(s,t,r):u(r))||r);return n&&r&&q(s,t,r),r},A=(e,s)=>(t,n)=>s(t,n,e);let h=class extends i.Disposable{constructor(e,s){super(),this._commandService=e,this._sortService=s,this._initCommands(),this._registerCompareFns()}_initCommands(){[R].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){const e=(s,t,n)=>{const r=this._getCommonValue(t),o=this._getCommonValue(n),u=[P,O,N];for(let c=0;c<u.length;c++){const a=u[c](r,o,s);if(a!==null)return a}return null};this._sortService.registerCompareFn(e)}_getCommonValue(e){var t,n;if(b(e))return null;const s=(n=(t=e==null?void 0:e.p)==null?void 0:t.body)==null?void 0:n.dataStream;return s||((e==null?void 0:e.t)===i.CellValueType.NUMBER?Number.parseFloat(`${e.v}`):(e==null?void 0:e.t)===i.CellValueType.STRING?typeof e.v=="number"?e.v:`${e.v}`:(e==null?void 0:e.t)===i.CellValueType.BOOLEAN?`${e.v}`:(e==null?void 0:e.t)===i.CellValueType.FORCE_STRING?Number.parseFloat(`${e.v}`):`${e==null?void 0:e.v}`)}};h=G([i.OnLifecycle(i.LifecycleStages.Ready,h),A(0,i.ICommandService),A(1,i.Inject(l.SheetsSortService))],h);var H=Object.defineProperty,x=Object.getOwnPropertyDescriptor,W=(e,s,t,n)=>{for(var r=n>1?void 0:n?x(s,t):s,o=e.length-1,u;o>=0;o--)(u=e[o])&&(r=(n?u(s,t,r):u(r))||r);return n&&r&&H(s,t,r),r},z=(e,s)=>(t,n)=>s(t,n,e);const J="UNIVER_SHEETS_SORT_PLUGIN";l.UniverSheetsSortPlugin=(C=class extends i.Plugin{constructor(s,t){super(),this._injector=t}onStarting(s){[[h],[l.SheetsSortService]].forEach(t=>s.add(t))}},_(C,"type",i.UniverInstanceType.UNIVER_SHEET),_(C,"pluginName",J),C),l.UniverSheetsSortPlugin=W([z(1,i.Inject(i.Injector))],l.UniverSheetsSortPlugin),l.SortRangeCommand=R,l.SortType=S,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-sort",
3
- "version": "0.2.2",
3
+ "version": "0.2.4-alpha.0",
4
4
  "private": false,
5
5
  "description": "A library for sorting data in Univer Sheet",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -45,21 +45,19 @@
45
45
  "lib"
46
46
  ],
47
47
  "peerDependencies": {
48
- "@wendellhu/redi": "0.15.5",
49
- "@univerjs/core": "0.2.2",
50
- "@univerjs/sheets": "0.2.2",
51
- "@univerjs/engine-formula": "0.2.2"
48
+ "@univerjs/core": "0.2.4-alpha.0",
49
+ "@univerjs/engine-formula": "0.2.4-alpha.0",
50
+ "@univerjs/sheets": "0.2.4-alpha.0"
52
51
  },
53
52
  "devDependencies": {
54
- "@wendellhu/redi": "0.15.5",
55
53
  "rxjs": "^7.8.1",
56
54
  "typescript": "^5.5.3",
57
- "vite": "^5.3.3",
58
- "vitest": "^1.6.0",
59
- "@univerjs/core": "0.2.2",
60
- "@univerjs/engine-formula": "0.2.2",
61
- "@univerjs/shared": "0.2.2",
62
- "@univerjs/sheets": "0.2.2"
55
+ "vite": "^5.3.4",
56
+ "vitest": "^2.0.3",
57
+ "@univerjs/core": "0.2.4-alpha.0",
58
+ "@univerjs/engine-formula": "0.2.4-alpha.0",
59
+ "@univerjs/shared": "0.2.4-alpha.0",
60
+ "@univerjs/sheets": "0.2.4-alpha.0"
63
61
  },
64
62
  "univerSpace": {
65
63
  ".": {