@univerjs/sheets-sort 0.8.2 → 0.8.3-nightly.202507010644

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var V=Object.defineProperty;var $=(e,r,t)=>r in e?V(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var w=(e,r,t)=>$(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@univerjs/core"),P=require("@univerjs/engine-formula"),d=require("@univerjs/sheets"),x="sheets-sort.config",b={};var g=(e=>(e.DESC="desc",e.ASC="asc",e))(g||{});const A=e=>e.replace(/-/gi,"").replace(/'/gi,""),L=(e,r)=>{const t=e===null||e==="",n=r===null||r==="";return t&&n?0:t?1:n?-1:null},G=(e,r,t)=>{const n=typeof e=="number",o=typeof r=="number";return n&&o?e<r?t===g.ASC?-1:1:e>r?t===g.ASC?1:-1:0:n?t===g.ASC?1:-1:o?t===g.ASC?-1:1:null},q=(e,r,t)=>{const n=typeof e=="string",o=typeof r=="string";if(n&&(e=A(e.toLocaleLowerCase())),o&&(r=A(r.toLocaleLowerCase())),!n&&!o)return null;if(n&&o){const s=e,i=r;return s<i?t===g.ASC?-1:1:s>i?t===g.ASC?1:-1:0}return n?t===g.ASC?1:-1:o?t===g.ASC?-1:1:null},U=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;var B=Object.getOwnPropertyDescriptor,H=(e,r,t,n)=>{for(var o=n>1?void 0:n?B(r,t):r,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(o)||o);return o},_=(e,r)=>(t,n)=>r(t,n,e);exports.SheetsSortService=class extends u.Disposable{constructor(t,n,o){super();w(this,"_compareFns",[]);this._univerInstanceService=t,this._commandService=n,this._formulaDataModel=o}mergeCheck(t){var l;const{unitId:n,subUnitId:o,range:s}=t,i=(l=this._univerInstanceService.getUnit(n))==null?void 0:l.getSheetBySheetId(o);if(!i)return!1;const c=i.getMergeData().filter(a=>u.Rectangle.contains(s,a));return c.length===0?!0:K(s,c)}emptyCheck(t){var c;const{unitId:n,subUnitId:o,range:s}=t,i=(c=this._univerInstanceService.getUnit(n))==null?void 0:c.getSheetBySheetId(o);if(!i)return!1;for(let l=s.startRow;l<=s.endRow;l++)for(let a=s.startColumn;a<=s.endColumn;a++)if(!U(i.getCellRaw(l,a)))return!0;return!1}singleCheck(t){return t.range.startRow!==t.range.endRow}formulaCheck(t){var c,l;const{unitId:n,subUnitId:o,range:s}=t,i=(l=(c=this._formulaDataModel.getArrayFormulaRange())==null?void 0:c[n])==null?void 0:l[o];for(const a in i){const f=i[Number(a)];for(const h in f){const S=f[Number(h)];if(S&&u.Rectangle.intersects(s,S))return!1}}return!0}registerCompareFn(t){this._compareFns.unshift(t)}getAllCompareFns(){return this._compareFns}applySort(t,n,o){var c;const{unitId:s,subUnitId:i}=d.getSheetCommandTarget(this._univerInstanceService)||{};this._commandService.executeCommand(p.id,{orderRules:t.orderRules,range:t.range,hasTitle:(c=t.hasTitle)!=null?c:!1,unitId:n||s,subUnitId:o||i})}};exports.SheetsSortService=H([_(0,u.IUniverInstanceService),_(1,u.ICommandService),_(2,u.Inject(P.FormulaDataModel))],exports.SheetsSortService);function K(e,r){const t=e.endRow-e.startRow+1,n=e.endColumn-e.startColumn+1;let o=null,s=null;const i=t*n;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,f=l.endColumn-l.startColumn+1;if(o===null&&s===null)o=a,s=f;else if(a!==o||f!==s)return!1;c+=a*f}return c===i}const p={id:"sheet.command.sort-range",type:u.CommandType.COMMAND,handler:(e,r)=>{const{range:t,orderRules:n,hasTitle:o,unitId:s,subUnitId:i}=r,c=e.get(exports.SheetsSortService),l=e.get(u.IUniverInstanceService),{worksheet:a}=d.getSheetCommandTarget(l,r)||{};if(!a)return!1;const f=a.getMergeData().filter(m=>u.Rectangle.contains(t,m)),h=f.map(m=>m.startRow),{startRow:S,endRow:N}=t,T=o?S+1:S,C=[],R=[];for(let m=T;m<=N;m++)a.getRowFiltered(m)||a.getRowRawVisible(m)!==!1&&(f.length&&!h.includes(m)||(C.push({index:m,value:W(a,m,n)}),R.push(m)));const E=c.getAllCompareFns();C.sort(z(n,Y(E)));const I={};C.forEach(({index:m,value:ne},j)=>{I[R[j]]=m});const O={id:d.ReorderRangeCommand.id,params:{unitId:s,subUnitId:i,range:t,order:I}},M=e.get(u.ICommandService);return u.sequenceExecute([O],M).result}};function W(e,r,t){const n=[];return t.forEach(({colIndex:o})=>{n.push(e.getCellRaw(r,o))}),n}function Y(e){return(r,t,n)=>{for(let o=0;o<e.length;o++){const s=e[o](r,t,n);if(s!=null)return s}return 0}}function z(e,r){return function(t,n){let o=null;for(let s=0;s<e.length;s++){const i=t.value[s],c=n.value[s];if(o=r(e[s].type,i,c),o!==0&&o!==null&&o!==void 0)return o}return 0}}var J=Object.getOwnPropertyDescriptor,Q=(e,r,t,n)=>{for(var o=n>1?void 0:n?J(r,t):r,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(o)||o);return o},y=(e,r)=>(t,n)=>r(t,n,e);let v=class extends u.Disposable{constructor(e,r){super(),this._commandService=e,this._sortService=r,this._initCommands(),this._registerCompareFns()}_initCommands(){[p].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){const e=(r,t,n)=>{const o=this._getCommonValue(t),s=this._getCommonValue(n),i=[L,q,G];for(let c=0;c<i.length;c++){const l=i[c](o,s,r);if(l!==null)return l}return null};this._sortService.registerCompareFn(e)}_getCommonValue(e){var t,n;if(U(e))return null;const r=(n=(t=e==null?void 0:e.p)==null?void 0:t.body)==null?void 0:n.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}`)}};v=Q([y(0,u.ICommandService),y(1,u.Inject(exports.SheetsSortService))],v);var X=Object.defineProperty,Z=Object.getOwnPropertyDescriptor,k=(e,r,t)=>r in e?X(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,ee=(e,r,t,n)=>{for(var o=n>1?void 0:n?Z(r,t):r,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(o)||o);return o},F=(e,r)=>(t,n)=>r(t,n,e),D=(e,r,t)=>k(e,typeof r!="symbol"?r+"":r,t);const te="SHEET_SORT_PLUGIN";exports.UniverSheetsSortPlugin=class extends u.Plugin{constructor(r=b,t,n){super(),this._config=r,this._injector=t,this._configService=n;const{...o}=u.merge({},b,this._config);this._configService.setConfig(x,o)}onStarting(){[[v],[exports.SheetsSortService]].forEach(r=>this._injector.add(r))}onReady(){this._injector.get(v)}};D(exports.UniverSheetsSortPlugin,"type",u.UniverInstanceType.UNIVER_SHEET);D(exports.UniverSheetsSortPlugin,"pluginName",te);exports.UniverSheetsSortPlugin=ee([u.DependentOn(d.UniverSheetsPlugin,P.UniverFormulaEnginePlugin),F(1,u.Inject(u.Injector)),F(2,u.IConfigService)],exports.UniverSheetsSortPlugin);exports.SortRangeCommand=p;exports.SortType=g;
1
+ "use strict";var V=Object.defineProperty;var $=(e,r,t)=>r in e?V(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var w=(e,r,t)=>$(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@univerjs/core"),d=require("@univerjs/sheets"),P=require("@univerjs/engine-formula");var g=(e=>(e.DESC="desc",e.ASC="asc",e))(g||{});const b=e=>e.replace(/-/gi,"").replace(/'/gi,""),x=(e,r)=>{const t=e===null||e==="",n=r===null||r==="";return t&&n?0:t?1:n?-1:null},L=(e,r,t)=>{const n=typeof e=="number",o=typeof r=="number";return n&&o?e<r?t===g.ASC?-1:1:e>r?t===g.ASC?1:-1:0:n?t===g.ASC?1:-1:o?t===g.ASC?-1:1:null},G=(e,r,t)=>{const n=typeof e=="string",o=typeof r=="string";if(n&&(e=b(e.toLocaleLowerCase())),o&&(r=b(r.toLocaleLowerCase())),!n&&!o)return null;if(n&&o){const s=e,i=r;return s<i?t===g.ASC?-1:1:s>i?t===g.ASC?1:-1:0}return n?t===g.ASC?1:-1:o?t===g.ASC?-1:1:null},U=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;var q=Object.getOwnPropertyDescriptor,B=(e,r,t,n)=>{for(var o=n>1?void 0:n?q(r,t):r,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(o)||o);return o},_=(e,r)=>(t,n)=>r(t,n,e);exports.SheetsSortService=class extends u.Disposable{constructor(t,n,o){super();w(this,"_compareFns",[]);this._univerInstanceService=t,this._commandService=n,this._formulaDataModel=o}mergeCheck(t){var l;const{unitId:n,subUnitId:o,range:s}=t,i=(l=this._univerInstanceService.getUnit(n))==null?void 0:l.getSheetBySheetId(o);if(!i)return!1;const c=i.getMergeData().filter(a=>u.Rectangle.contains(s,a));return c.length===0?!0:H(s,c)}emptyCheck(t){var c;const{unitId:n,subUnitId:o,range:s}=t,i=(c=this._univerInstanceService.getUnit(n))==null?void 0:c.getSheetBySheetId(o);if(!i)return!1;for(let l=s.startRow;l<=s.endRow;l++)for(let a=s.startColumn;a<=s.endColumn;a++)if(!U(i.getCellRaw(l,a)))return!0;return!1}singleCheck(t){return t.range.startRow!==t.range.endRow}formulaCheck(t){var c,l;const{unitId:n,subUnitId:o,range:s}=t,i=(l=(c=this._formulaDataModel.getArrayFormulaRange())==null?void 0:c[n])==null?void 0:l[o];for(const a in i){const f=i[Number(a)];for(const h in f){const S=f[Number(h)];if(S&&u.Rectangle.intersects(s,S))return!1}}return!0}registerCompareFn(t){this._compareFns.unshift(t)}getAllCompareFns(){return this._compareFns}applySort(t,n,o){var c;const{unitId:s,subUnitId:i}=d.getSheetCommandTarget(this._univerInstanceService)||{};this._commandService.executeCommand(p.id,{orderRules:t.orderRules,range:t.range,hasTitle:(c=t.hasTitle)!=null?c:!1,unitId:n||s,subUnitId:o||i})}};exports.SheetsSortService=B([_(0,u.IUniverInstanceService),_(1,u.ICommandService),_(2,u.Inject(P.FormulaDataModel))],exports.SheetsSortService);function H(e,r){const t=e.endRow-e.startRow+1,n=e.endColumn-e.startColumn+1;let o=null,s=null;const i=t*n;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,f=l.endColumn-l.startColumn+1;if(o===null&&s===null)o=a,s=f;else if(a!==o||f!==s)return!1;c+=a*f}return c===i}const p={id:"sheet.command.sort-range",type:u.CommandType.COMMAND,handler:(e,r)=>{const{range:t,orderRules:n,hasTitle:o,unitId:s,subUnitId:i}=r,c=e.get(exports.SheetsSortService),l=e.get(u.IUniverInstanceService),{worksheet:a}=d.getSheetCommandTarget(l,r)||{};if(!a)return!1;const f=a.getMergeData().filter(m=>u.Rectangle.contains(t,m)),h=f.map(m=>m.startRow),{startRow:S,endRow:N}=t,T=o?S+1:S,C=[],R=[];for(let m=T;m<=N;m++)a.getRowFiltered(m)||a.getRowRawVisible(m)!==!1&&(f.length&&!h.includes(m)||(C.push({index:m,value:K(a,m,n)}),R.push(m)));const E=c.getAllCompareFns();C.sort(Y(n,W(E)));const I={};C.forEach(({index:m,value:ne},j)=>{I[R[j]]=m});const O={id:d.ReorderRangeCommand.id,params:{unitId:s,subUnitId:i,range:t,order:I}},M=e.get(u.ICommandService);return u.sequenceExecute([O],M).result}};function K(e,r,t){const n=[];return t.forEach(({colIndex:o})=>{n.push(e.getCellRaw(r,o))}),n}function W(e){return(r,t,n)=>{for(let o=0;o<e.length;o++){const s=e[o](r,t,n);if(s!=null)return s}return 0}}function Y(e,r){return function(t,n){let o=null;for(let s=0;s<e.length;s++){const i=t.value[s],c=n.value[s];if(o=r(e[s].type,i,c),o!==0&&o!==null&&o!==void 0)return o}return 0}}const z="sheets-sort.config",A={};var J=Object.getOwnPropertyDescriptor,Q=(e,r,t,n)=>{for(var o=n>1?void 0:n?J(r,t):r,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(o)||o);return o},y=(e,r)=>(t,n)=>r(t,n,e);let v=class extends u.Disposable{constructor(e,r){super(),this._commandService=e,this._sortService=r,this._initCommands(),this._registerCompareFns()}_initCommands(){[p].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){const e=(r,t,n)=>{const o=this._getCommonValue(t),s=this._getCommonValue(n),i=[x,G,L];for(let c=0;c<i.length;c++){const l=i[c](o,s,r);if(l!==null)return l}return null};this._sortService.registerCompareFn(e)}_getCommonValue(e){var t,n;if(U(e))return null;const r=(n=(t=e==null?void 0:e.p)==null?void 0:t.body)==null?void 0:n.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}`)}};v=Q([y(0,u.ICommandService),y(1,u.Inject(exports.SheetsSortService))],v);var X=Object.defineProperty,Z=Object.getOwnPropertyDescriptor,k=(e,r,t)=>r in e?X(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,ee=(e,r,t,n)=>{for(var o=n>1?void 0:n?Z(r,t):r,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(o)||o);return o},F=(e,r)=>(t,n)=>r(t,n,e),D=(e,r,t)=>k(e,typeof r!="symbol"?r+"":r,t);const te="SHEET_SORT_PLUGIN";exports.UniverSheetsSortPlugin=class extends u.Plugin{constructor(r=A,t,n){super(),this._config=r,this._injector=t,this._configService=n;const{...o}=u.merge({},A,this._config);this._configService.setConfig(z,o)}onStarting(){[[v],[exports.SheetsSortService]].forEach(r=>this._injector.add(r))}onReady(){this._injector.get(v)}};D(exports.UniverSheetsSortPlugin,"type",u.UniverInstanceType.UNIVER_SHEET);D(exports.UniverSheetsSortPlugin,"pluginName",te);exports.UniverSheetsSortPlugin=ee([u.DependentOn(d.UniverSheetsPlugin,P.UniverFormulaEnginePlugin),F(1,u.Inject(u.Injector)),F(2,u.IConfigService)],exports.UniverSheetsSortPlugin);exports.SortRangeCommand=p;exports.SortType=g;
@@ -0,0 +1 @@
1
+ "use strict";const t={sheetsSort:{title:"정렬",toolbar:{"sort-asc":"오름차순","sort-desc":"내림차순","sort-custom":"사용자 정의 순서"},"context-menu":{"sort-asc":"오름차순","sort-desc":"내림차순","sort-custom":"사용자 정의 순서"}}};module.exports=t;
package/lib/es/index.js CHANGED
@@ -2,19 +2,18 @@ var H = Object.defineProperty;
2
2
  var q = (e, t, r) => t in e ? H(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
3
  var F = (e, t, r) => q(e, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { IUniverInstanceService as O, ICommandService as R, Inject as w, Disposable as P, Rectangle as p, CommandType as K, sequenceExecute as W, CellValueType as h, UniverInstanceType as Y, DependentOn as z, Injector as J, IConfigService as Q, Plugin as X, merge as Z } from "@univerjs/core";
5
- import { FormulaDataModel as k, UniverFormulaEnginePlugin as ee } from "@univerjs/engine-formula";
6
- import { getSheetCommandTarget as U, ReorderRangeCommand as te, UniverSheetsPlugin as re } from "@univerjs/sheets";
7
- const ne = "sheets-sort.config", N = {};
5
+ import { getSheetCommandTarget as U, ReorderRangeCommand as k, UniverSheetsPlugin as ee } from "@univerjs/sheets";
6
+ import { FormulaDataModel as te, UniverFormulaEnginePlugin as re } from "@univerjs/engine-formula";
8
7
  var m = /* @__PURE__ */ ((e) => (e.DESC = "desc", e.ASC = "asc", e))(m || {});
9
- const D = (e) => e.replace(/-/gi, "").replace(/'/gi, ""), oe = (e, t) => {
8
+ const N = (e) => e.replace(/-/gi, "").replace(/'/gi, ""), ne = (e, t) => {
10
9
  const r = e === null || e === "", n = t === null || t === "";
11
10
  return r && n ? 0 : r ? 1 : n ? -1 : null;
12
- }, se = (e, t, r) => {
11
+ }, oe = (e, t, r) => {
13
12
  const n = typeof e == "number", o = typeof t == "number";
14
13
  return n && o ? e < t ? r === m.ASC ? -1 : 1 : e > t ? r === m.ASC ? 1 : -1 : 0 : n ? r === m.ASC ? 1 : -1 : o ? r === m.ASC ? -1 : 1 : null;
15
- }, ie = (e, t, r) => {
14
+ }, se = (e, t, r) => {
16
15
  const n = typeof e == "string", o = typeof t == "string";
17
- if (n && (e = D(e.toLocaleLowerCase())), o && (t = D(t.toLocaleLowerCase())), !n && !o)
16
+ if (n && (e = N(e.toLocaleLowerCase())), o && (t = N(t.toLocaleLowerCase())), !n && !o)
18
17
  return null;
19
18
  if (n && o) {
20
19
  const s = e, i = t;
@@ -22,8 +21,8 @@ const D = (e) => e.replace(/-/gi, "").replace(/'/gi, ""), oe = (e, t) => {
22
21
  }
23
22
  return n ? r === m.ASC ? 1 : -1 : o ? r === 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 ue = Object.getOwnPropertyDescriptor, le = (e, t, r, n) => {
26
- for (var o = n > 1 ? void 0 : n ? ue(t, r) : t, s = e.length - 1, i; s >= 0; s--)
24
+ var ie = Object.getOwnPropertyDescriptor, ue = (e, t, r, n) => {
25
+ for (var o = n > 1 ? void 0 : n ? ie(t, r) : t, s = e.length - 1, i; s >= 0; s--)
27
26
  (i = e[s]) && (o = i(o) || o);
28
27
  return o;
29
28
  }, S = (e, t) => (r, n) => t(r, n, e);
@@ -39,7 +38,7 @@ let g = class extends P {
39
38
  if (!s)
40
39
  return !1;
41
40
  const i = s.getMergeData().filter((u) => p.contains(o, u));
42
- return i.length === 0 ? !0 : ce(o, i);
41
+ return i.length === 0 ? !0 : le(o, i);
43
42
  }
44
43
  emptyCheck(t) {
45
44
  var i;
@@ -86,12 +85,12 @@ let g = class extends P {
86
85
  });
87
86
  }
88
87
  };
89
- g = le([
88
+ g = ue([
90
89
  S(0, O),
91
90
  S(1, R),
92
- S(2, w(k))
91
+ S(2, w(te))
93
92
  ], g);
94
- function ce(e, t) {
93
+ function le(e, t) {
95
94
  const r = e.endRow - e.startRow + 1, n = e.endColumn - e.startColumn + 1;
96
95
  let o = null, s = null;
97
96
  const i = r * n;
@@ -118,16 +117,16 @@ const M = {
118
117
  for (let c = j; c <= $; c++)
119
118
  a.getRowFiltered(c) || a.getRowRawVisible(c) !== !1 && (f.length && !d.includes(c) || (_.push({
120
119
  index: c,
121
- value: ae(a, c, n)
120
+ value: ce(a, c, n)
122
121
  }), b.push(c)));
123
122
  const V = l.getAllCompareFns();
124
- _.sort(fe(n, me(V)));
123
+ _.sort(me(n, ae(V)));
125
124
  const A = {};
126
125
  _.forEach(({ index: c, value: Re }, B) => {
127
126
  A[b[B]] = c;
128
127
  });
129
128
  const L = {
130
- id: te.id,
129
+ id: k.id,
131
130
  params: {
132
131
  unitId: s,
133
132
  subUnitId: i,
@@ -138,13 +137,13 @@ const M = {
138
137
  return W([L], G).result;
139
138
  }
140
139
  };
141
- function ae(e, t, r) {
140
+ function ce(e, t, r) {
142
141
  const n = [];
143
142
  return r.forEach(({ colIndex: o }) => {
144
143
  n.push(e.getCellRaw(t, o));
145
144
  }), n;
146
145
  }
147
- function me(e) {
146
+ function ae(e) {
148
147
  return (t, r, n) => {
149
148
  for (let o = 0; o < e.length; o++) {
150
149
  const s = e[o](t, r, n);
@@ -154,7 +153,7 @@ function me(e) {
154
153
  return 0;
155
154
  };
156
155
  }
157
- function fe(e, t) {
156
+ function me(e, t) {
158
157
  return function(r, n) {
159
158
  let o = null;
160
159
  for (let s = 0; s < e.length; s++) {
@@ -165,6 +164,7 @@ function fe(e, t) {
165
164
  return 0;
166
165
  };
167
166
  }
167
+ const fe = "sheets-sort.config", D = {};
168
168
  var ge = Object.getOwnPropertyDescriptor, de = (e, t, r, n) => {
169
169
  for (var o = n > 1 ? void 0 : n ? ge(t, r) : t, s = e.length - 1, i; s >= 0; s--)
170
170
  (i = e[s]) && (o = i(o) || o);
@@ -182,9 +182,9 @@ let v = class extends P {
182
182
  _registerCompareFns() {
183
183
  const e = (t, r, n) => {
184
184
  const o = this._getCommonValue(r), s = this._getCommonValue(n), i = [
185
- oe,
186
- ie,
187
- se
185
+ ne,
186
+ se,
187
+ oe
188
188
  ];
189
189
  for (let l = 0; l < i.length; l++) {
190
190
  const u = i[l](o, s, t);
@@ -214,14 +214,14 @@ var he = Object.defineProperty, ve = Object.getOwnPropertyDescriptor, Ce = (e, t
214
214
  }, y = (e, t) => (r, n) => t(r, n, e), x = (e, t, r) => Ce(e, typeof t != "symbol" ? t + "" : t, r);
215
215
  const Se = "SHEET_SORT_PLUGIN";
216
216
  let C = class extends X {
217
- constructor(e = N, t, r) {
217
+ constructor(e = D, t, r) {
218
218
  super(), this._config = e, this._injector = t, this._configService = r;
219
219
  const { ...n } = Z(
220
220
  {},
221
- N,
221
+ D,
222
222
  this._config
223
223
  );
224
- this._configService.setConfig(ne, n);
224
+ this._configService.setConfig(fe, n);
225
225
  }
226
226
  onStarting() {
227
227
  [
@@ -236,7 +236,7 @@ let C = class extends X {
236
236
  x(C, "type", Y.UNIVER_SHEET);
237
237
  x(C, "pluginName", Se);
238
238
  C = _e([
239
- z(re, ee),
239
+ z(ee, re),
240
240
  y(1, w(J)),
241
241
  y(2, Q)
242
242
  ], C);
@@ -0,0 +1,18 @@
1
+ const t = {
2
+ sheetsSort: {
3
+ title: "정렬",
4
+ toolbar: {
5
+ "sort-asc": "오름차순",
6
+ "sort-desc": "내림차순",
7
+ "sort-custom": "사용자 정의 순서"
8
+ },
9
+ "context-menu": {
10
+ "sort-asc": "오름차순",
11
+ "sort-desc": "내림차순",
12
+ "sort-custom": "사용자 정의 순서"
13
+ }
14
+ }
15
+ };
16
+ export {
17
+ t as default
18
+ };
package/lib/index.js CHANGED
@@ -2,19 +2,18 @@ var H = Object.defineProperty;
2
2
  var q = (e, t, r) => t in e ? H(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
3
  var F = (e, t, r) => q(e, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { IUniverInstanceService as O, ICommandService as R, Inject as w, Disposable as P, Rectangle as p, CommandType as K, sequenceExecute as W, CellValueType as h, UniverInstanceType as Y, DependentOn as z, Injector as J, IConfigService as Q, Plugin as X, merge as Z } from "@univerjs/core";
5
- import { FormulaDataModel as k, UniverFormulaEnginePlugin as ee } from "@univerjs/engine-formula";
6
- import { getSheetCommandTarget as U, ReorderRangeCommand as te, UniverSheetsPlugin as re } from "@univerjs/sheets";
7
- const ne = "sheets-sort.config", N = {};
5
+ import { getSheetCommandTarget as U, ReorderRangeCommand as k, UniverSheetsPlugin as ee } from "@univerjs/sheets";
6
+ import { FormulaDataModel as te, UniverFormulaEnginePlugin as re } from "@univerjs/engine-formula";
8
7
  var m = /* @__PURE__ */ ((e) => (e.DESC = "desc", e.ASC = "asc", e))(m || {});
9
- const D = (e) => e.replace(/-/gi, "").replace(/'/gi, ""), oe = (e, t) => {
8
+ const N = (e) => e.replace(/-/gi, "").replace(/'/gi, ""), ne = (e, t) => {
10
9
  const r = e === null || e === "", n = t === null || t === "";
11
10
  return r && n ? 0 : r ? 1 : n ? -1 : null;
12
- }, se = (e, t, r) => {
11
+ }, oe = (e, t, r) => {
13
12
  const n = typeof e == "number", o = typeof t == "number";
14
13
  return n && o ? e < t ? r === m.ASC ? -1 : 1 : e > t ? r === m.ASC ? 1 : -1 : 0 : n ? r === m.ASC ? 1 : -1 : o ? r === m.ASC ? -1 : 1 : null;
15
- }, ie = (e, t, r) => {
14
+ }, se = (e, t, r) => {
16
15
  const n = typeof e == "string", o = typeof t == "string";
17
- if (n && (e = D(e.toLocaleLowerCase())), o && (t = D(t.toLocaleLowerCase())), !n && !o)
16
+ if (n && (e = N(e.toLocaleLowerCase())), o && (t = N(t.toLocaleLowerCase())), !n && !o)
18
17
  return null;
19
18
  if (n && o) {
20
19
  const s = e, i = t;
@@ -22,8 +21,8 @@ const D = (e) => e.replace(/-/gi, "").replace(/'/gi, ""), oe = (e, t) => {
22
21
  }
23
22
  return n ? r === m.ASC ? 1 : -1 : o ? r === 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 ue = Object.getOwnPropertyDescriptor, le = (e, t, r, n) => {
26
- for (var o = n > 1 ? void 0 : n ? ue(t, r) : t, s = e.length - 1, i; s >= 0; s--)
24
+ var ie = Object.getOwnPropertyDescriptor, ue = (e, t, r, n) => {
25
+ for (var o = n > 1 ? void 0 : n ? ie(t, r) : t, s = e.length - 1, i; s >= 0; s--)
27
26
  (i = e[s]) && (o = i(o) || o);
28
27
  return o;
29
28
  }, S = (e, t) => (r, n) => t(r, n, e);
@@ -39,7 +38,7 @@ let g = class extends P {
39
38
  if (!s)
40
39
  return !1;
41
40
  const i = s.getMergeData().filter((u) => p.contains(o, u));
42
- return i.length === 0 ? !0 : ce(o, i);
41
+ return i.length === 0 ? !0 : le(o, i);
43
42
  }
44
43
  emptyCheck(t) {
45
44
  var i;
@@ -86,12 +85,12 @@ let g = class extends P {
86
85
  });
87
86
  }
88
87
  };
89
- g = le([
88
+ g = ue([
90
89
  S(0, O),
91
90
  S(1, R),
92
- S(2, w(k))
91
+ S(2, w(te))
93
92
  ], g);
94
- function ce(e, t) {
93
+ function le(e, t) {
95
94
  const r = e.endRow - e.startRow + 1, n = e.endColumn - e.startColumn + 1;
96
95
  let o = null, s = null;
97
96
  const i = r * n;
@@ -118,16 +117,16 @@ const M = {
118
117
  for (let c = j; c <= $; c++)
119
118
  a.getRowFiltered(c) || a.getRowRawVisible(c) !== !1 && (f.length && !d.includes(c) || (_.push({
120
119
  index: c,
121
- value: ae(a, c, n)
120
+ value: ce(a, c, n)
122
121
  }), b.push(c)));
123
122
  const V = l.getAllCompareFns();
124
- _.sort(fe(n, me(V)));
123
+ _.sort(me(n, ae(V)));
125
124
  const A = {};
126
125
  _.forEach(({ index: c, value: Re }, B) => {
127
126
  A[b[B]] = c;
128
127
  });
129
128
  const L = {
130
- id: te.id,
129
+ id: k.id,
131
130
  params: {
132
131
  unitId: s,
133
132
  subUnitId: i,
@@ -138,13 +137,13 @@ const M = {
138
137
  return W([L], G).result;
139
138
  }
140
139
  };
141
- function ae(e, t, r) {
140
+ function ce(e, t, r) {
142
141
  const n = [];
143
142
  return r.forEach(({ colIndex: o }) => {
144
143
  n.push(e.getCellRaw(t, o));
145
144
  }), n;
146
145
  }
147
- function me(e) {
146
+ function ae(e) {
148
147
  return (t, r, n) => {
149
148
  for (let o = 0; o < e.length; o++) {
150
149
  const s = e[o](t, r, n);
@@ -154,7 +153,7 @@ function me(e) {
154
153
  return 0;
155
154
  };
156
155
  }
157
- function fe(e, t) {
156
+ function me(e, t) {
158
157
  return function(r, n) {
159
158
  let o = null;
160
159
  for (let s = 0; s < e.length; s++) {
@@ -165,6 +164,7 @@ function fe(e, t) {
165
164
  return 0;
166
165
  };
167
166
  }
167
+ const fe = "sheets-sort.config", D = {};
168
168
  var ge = Object.getOwnPropertyDescriptor, de = (e, t, r, n) => {
169
169
  for (var o = n > 1 ? void 0 : n ? ge(t, r) : t, s = e.length - 1, i; s >= 0; s--)
170
170
  (i = e[s]) && (o = i(o) || o);
@@ -182,9 +182,9 @@ let v = class extends P {
182
182
  _registerCompareFns() {
183
183
  const e = (t, r, n) => {
184
184
  const o = this._getCommonValue(r), s = this._getCommonValue(n), i = [
185
- oe,
186
- ie,
187
- se
185
+ ne,
186
+ se,
187
+ oe
188
188
  ];
189
189
  for (let l = 0; l < i.length; l++) {
190
190
  const u = i[l](o, s, t);
@@ -214,14 +214,14 @@ var he = Object.defineProperty, ve = Object.getOwnPropertyDescriptor, Ce = (e, t
214
214
  }, y = (e, t) => (r, n) => t(r, n, e), x = (e, t, r) => Ce(e, typeof t != "symbol" ? t + "" : t, r);
215
215
  const Se = "SHEET_SORT_PLUGIN";
216
216
  let C = class extends X {
217
- constructor(e = N, t, r) {
217
+ constructor(e = D, t, r) {
218
218
  super(), this._config = e, this._injector = t, this._configService = r;
219
219
  const { ...n } = Z(
220
220
  {},
221
- N,
221
+ D,
222
222
  this._config
223
223
  );
224
- this._configService.setConfig(ne, n);
224
+ this._configService.setConfig(fe, n);
225
225
  }
226
226
  onStarting() {
227
227
  [
@@ -236,7 +236,7 @@ let C = class extends X {
236
236
  x(C, "type", Y.UNIVER_SHEET);
237
237
  x(C, "pluginName", Se);
238
238
  C = _e([
239
- z(re, ee),
239
+ z(ee, re),
240
240
  y(1, w(J)),
241
241
  y(2, Q)
242
242
  ], C);
@@ -0,0 +1,18 @@
1
+ const t = {
2
+ sheetsSort: {
3
+ title: "정렬",
4
+ toolbar: {
5
+ "sort-asc": "오름차순",
6
+ "sort-desc": "내림차순",
7
+ "sort-custom": "사용자 정의 순서"
8
+ },
9
+ "context-menu": {
10
+ "sort-asc": "오름차순",
11
+ "sort-desc": "내림차순",
12
+ "sort-custom": "사용자 정의 순서"
13
+ }
14
+ }
15
+ };
16
+ export {
17
+ t as default
18
+ };
@@ -13,7 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ export { type ISortRangeCommandParams, SortRangeCommand } from './commands/commands/sheets-sort.command';
17
+ export type { IUniverSheetsSortConfig } from './controllers/config.schema';
16
18
  export { UniverSheetsSortPlugin } from './plugin';
17
- export { SheetsSortService } from './services/sheets-sort.service';
18
19
  export { type IOrderRule, type ISortOption, SortType } from './services/interface';
19
- export { type ISortRangeCommandParams, SortRangeCommand, } from './commands/commands/sheets-sort.command';
20
+ export { SheetsSortService } from './services/sheets-sort.service';
@@ -0,0 +1,3 @@
1
+ import { default as enUS } from './en-US';
2
+ declare const locale: typeof enUS;
3
+ export default locale;
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(l,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/engine-formula"),require("@univerjs/sheets")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-formula","@univerjs/sheets"],o):(l=typeof globalThis<"u"?globalThis:l||self,o(l.UniverSheetsSort={},l.UniverCore,l.UniverEngineFormula,l.UniverSheets))})(this,function(l,o,S,h){"use strict";var te=Object.defineProperty;var ne=(l,o,S)=>o in l?te(l,o,{enumerable:!0,configurable:!0,writable:!0,value:S}):l[o]=S;var N=(l,o,S)=>ne(l,typeof o!="symbol"?o+"":o,S);const T="sheets-sort.config",w={};var g=(e=>(e.DESC="desc",e.ASC="asc",e))(g||{});const b=e=>e.replace(/-/gi,"").replace(/'/gi,""),E=(e,n)=>{const t=e===null||e==="",r=n===null||n==="";return t&&r?0:t?1:r?-1:null},O=(e,n,t)=>{const r=typeof e=="number",s=typeof n=="number";return r&&s?e<n?t===g.ASC?-1:1:e>n?t===g.ASC?1:-1:0:r?t===g.ASC?1:-1:s?t===g.ASC?-1:1:null},j=(e,n,t)=>{const r=typeof e=="string",s=typeof n=="string";if(r&&(e=b(e.toLocaleLowerCase())),s&&(n=b(n.toLocaleLowerCase())),!r&&!s)return null;if(r&&s){const i=e,u=n;return i<u?t===g.ASC?-1:1:i>u?t===g.ASC?1:-1:0}return r?t===g.ASC?1:-1:s?t===g.ASC?-1:1:null},U=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;var M=Object.getOwnPropertyDescriptor,V=(e,n,t,r)=>{for(var s=r>1?void 0:r?M(n,t):n,i=e.length-1,u;i>=0;i--)(u=e[i])&&(s=u(s)||s);return s},_=(e,n)=>(t,r)=>n(t,r,e);l.SheetsSortService=class extends o.Disposable{constructor(t,r,s){super();N(this,"_compareFns",[]);this._univerInstanceService=t,this._commandService=r,this._formulaDataModel=s}mergeCheck(t){var a;const{unitId:r,subUnitId:s,range:i}=t,u=(a=this._univerInstanceService.getUnit(r))==null?void 0:a.getSheetBySheetId(s);if(!u)return!1;const c=u.getMergeData().filter(f=>o.Rectangle.contains(i,f));return c.length===0?!0:$(i,c)}emptyCheck(t){var c;const{unitId:r,subUnitId:s,range:i}=t,u=(c=this._univerInstanceService.getUnit(r))==null?void 0:c.getSheetBySheetId(s);if(!u)return!1;for(let a=i.startRow;a<=i.endRow;a++)for(let f=i.startColumn;f<=i.endColumn;f++)if(!U(u.getCellRaw(a,f)))return!0;return!1}singleCheck(t){return t.range.startRow!==t.range.endRow}formulaCheck(t){var c,a;const{unitId:r,subUnitId:s,range:i}=t,u=(a=(c=this._formulaDataModel.getArrayFormulaRange())==null?void 0:c[r])==null?void 0:a[s];for(const f in u){const d=u[Number(f)];for(const R in d){const v=d[Number(R)];if(v&&o.Rectangle.intersects(i,v))return!1}}return!0}registerCompareFn(t){this._compareFns.unshift(t)}getAllCompareFns(){return this._compareFns}applySort(t,r,s){var c;const{unitId:i,subUnitId:u}=h.getSheetCommandTarget(this._univerInstanceService)||{};this._commandService.executeCommand(p.id,{orderRules:t.orderRules,range:t.range,hasTitle:(c=t.hasTitle)!=null?c:!1,unitId:r||i,subUnitId:s||u})}},l.SheetsSortService=V([_(0,o.IUniverInstanceService),_(1,o.ICommandService),_(2,o.Inject(S.FormulaDataModel))],l.SheetsSortService);function $(e,n){const t=e.endRow-e.startRow+1,r=e.endColumn-e.startColumn+1;let s=null,i=null;const u=t*r;let c=0;for(const a of n)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(s===null&&i===null)s=f,i=d;else if(f!==s||d!==i)return!1;c+=f*d}return c===u}const p={id:"sheet.command.sort-range",type:o.CommandType.COMMAND,handler:(e,n)=>{const{range:t,orderRules:r,hasTitle:s,unitId:i,subUnitId:u}=n,c=e.get(l.SheetsSortService),a=e.get(o.IUniverInstanceService),{worksheet:f}=h.getSheetCommandTarget(a,n)||{};if(!f)return!1;const d=f.getMergeData().filter(m=>o.Rectangle.contains(t,m)),R=d.map(m=>m.startRow),{startRow:v,endRow:J}=t,Q=s?v+1:v,I=[],F=[];for(let m=Q;m<=J;m++)f.getRowFiltered(m)||f.getRowRawVisible(m)!==!1&&(d.length&&!R.includes(m)||(I.push({index:m,value:L(f,m,r)}),F.push(m)));const X=c.getAllCompareFns();I.sort(q(r,G(X)));const D={};I.forEach(({index:m,value:se},ee)=>{D[F[ee]]=m});const Z={id:h.ReorderRangeCommand.id,params:{unitId:i,subUnitId:u,range:t,order:D}},k=e.get(o.ICommandService);return o.sequenceExecute([Z],k).result}};function L(e,n,t){const r=[];return t.forEach(({colIndex:s})=>{r.push(e.getCellRaw(n,s))}),r}function G(e){return(n,t,r)=>{for(let s=0;s<e.length;s++){const i=e[s](n,t,r);if(i!=null)return i}return 0}}function q(e,n){return function(t,r){let s=null;for(let i=0;i<e.length;i++){const u=t.value[i],c=r.value[i];if(s=n(e[i].type,u,c),s!==0&&s!==null&&s!==void 0)return s}return 0}}var B=Object.getOwnPropertyDescriptor,H=(e,n,t,r)=>{for(var s=r>1?void 0:r?B(n,t):n,i=e.length-1,u;i>=0;i--)(u=e[i])&&(s=u(s)||s);return s},y=(e,n)=>(t,r)=>n(t,r,e);let C=class extends o.Disposable{constructor(e,n){super(),this._commandService=e,this._sortService=n,this._initCommands(),this._registerCompareFns()}_initCommands(){[p].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){const e=(n,t,r)=>{const s=this._getCommonValue(t),i=this._getCommonValue(r),u=[E,j,O];for(let c=0;c<u.length;c++){const a=u[c](s,i,n);if(a!==null)return a}return null};this._sortService.registerCompareFn(e)}_getCommonValue(e){var t,r;if(U(e))return null;const n=(r=(t=e==null?void 0:e.p)==null?void 0:t.body)==null?void 0:r.dataStream;return n||((e==null?void 0:e.t)===o.CellValueType.NUMBER?Number.parseFloat(`${e.v}`):(e==null?void 0:e.t)===o.CellValueType.STRING?typeof e.v=="number"?e.v:`${e.v}`:(e==null?void 0:e.t)===o.CellValueType.BOOLEAN?`${e.v}`:(e==null?void 0:e.t)===o.CellValueType.FORCE_STRING?Number.parseFloat(`${e.v}`):`${e==null?void 0:e.v}`)}};C=H([y(0,o.ICommandService),y(1,o.Inject(l.SheetsSortService))],C);var K=Object.defineProperty,W=Object.getOwnPropertyDescriptor,Y=(e,n,t)=>n in e?K(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,x=(e,n,t,r)=>{for(var s=r>1?void 0:r?W(n,t):n,i=e.length-1,u;i>=0;i--)(u=e[i])&&(s=u(s)||s);return s},A=(e,n)=>(t,r)=>n(t,r,e),P=(e,n,t)=>Y(e,typeof n!="symbol"?n+"":n,t);const z="SHEET_SORT_PLUGIN";l.UniverSheetsSortPlugin=class extends o.Plugin{constructor(n=w,t,r){super(),this._config=n,this._injector=t,this._configService=r;const{...s}=o.merge({},w,this._config);this._configService.setConfig(T,s)}onStarting(){[[C],[l.SheetsSortService]].forEach(n=>this._injector.add(n))}onReady(){this._injector.get(C)}},P(l.UniverSheetsSortPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),P(l.UniverSheetsSortPlugin,"pluginName",z),l.UniverSheetsSortPlugin=x([o.DependentOn(h.UniverSheetsPlugin,S.UniverFormulaEnginePlugin),A(1,o.Inject(o.Injector)),A(2,o.IConfigService)],l.UniverSheetsSortPlugin),l.SortRangeCommand=p,l.SortType=g,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
1
+ (function(l,o){typeof exports=="object"&&typeof module<"u"?o(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"],o):(l=typeof globalThis<"u"?globalThis:l||self,o(l.UniverSheetsSort={},l.UniverCore,l.UniverSheets,l.UniverEngineFormula))})(this,function(l,o,d,I){"use strict";var te=Object.defineProperty;var ne=(l,o,d)=>o in l?te(l,o,{enumerable:!0,configurable:!0,writable:!0,value:d}):l[o]=d;var N=(l,o,d)=>ne(l,typeof o!="symbol"?o+"":o,d);var g=(e=>(e.DESC="desc",e.ASC="asc",e))(g||{});const w=e=>e.replace(/-/gi,"").replace(/'/gi,""),T=(e,n)=>{const t=e===null||e==="",r=n===null||n==="";return t&&r?0:t?1:r?-1:null},E=(e,n,t)=>{const r=typeof e=="number",s=typeof n=="number";return r&&s?e<n?t===g.ASC?-1:1:e>n?t===g.ASC?1:-1:0:r?t===g.ASC?1:-1:s?t===g.ASC?-1:1:null},O=(e,n,t)=>{const r=typeof e=="string",s=typeof n=="string";if(r&&(e=w(e.toLocaleLowerCase())),s&&(n=w(n.toLocaleLowerCase())),!r&&!s)return null;if(r&&s){const i=e,u=n;return i<u?t===g.ASC?-1:1:i>u?t===g.ASC?1:-1:0}return r?t===g.ASC?1:-1:s?t===g.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 j=Object.getOwnPropertyDescriptor,M=(e,n,t,r)=>{for(var s=r>1?void 0:r?j(n,t):n,i=e.length-1,u;i>=0;i--)(u=e[i])&&(s=u(s)||s);return s},C=(e,n)=>(t,r)=>n(t,r,e);l.SheetsSortService=class extends o.Disposable{constructor(t,r,s){super();N(this,"_compareFns",[]);this._univerInstanceService=t,this._commandService=r,this._formulaDataModel=s}mergeCheck(t){var a;const{unitId:r,subUnitId:s,range:i}=t,u=(a=this._univerInstanceService.getUnit(r))==null?void 0:a.getSheetBySheetId(s);if(!u)return!1;const c=u.getMergeData().filter(f=>o.Rectangle.contains(i,f));return c.length===0?!0:V(i,c)}emptyCheck(t){var c;const{unitId:r,subUnitId:s,range:i}=t,u=(c=this._univerInstanceService.getUnit(r))==null?void 0:c.getSheetBySheetId(s);if(!u)return!1;for(let a=i.startRow;a<=i.endRow;a++)for(let f=i.startColumn;f<=i.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:r,subUnitId:s,range:i}=t,u=(a=(c=this._formulaDataModel.getArrayFormulaRange())==null?void 0:c[r])==null?void 0:a[s];for(const f in u){const S=u[Number(f)];for(const p in S){const v=S[Number(p)];if(v&&o.Rectangle.intersects(i,v))return!1}}return!0}registerCompareFn(t){this._compareFns.unshift(t)}getAllCompareFns(){return this._compareFns}applySort(t,r,s){var c;const{unitId:i,subUnitId:u}=d.getSheetCommandTarget(this._univerInstanceService)||{};this._commandService.executeCommand(_.id,{orderRules:t.orderRules,range:t.range,hasTitle:(c=t.hasTitle)!=null?c:!1,unitId:r||i,subUnitId:s||u})}},l.SheetsSortService=M([C(0,o.IUniverInstanceService),C(1,o.ICommandService),C(2,o.Inject(I.FormulaDataModel))],l.SheetsSortService);function V(e,n){const t=e.endRow-e.startRow+1,r=e.endColumn-e.startColumn+1;let s=null,i=null;const u=t*r;let c=0;for(const a of n)if(a.startRow>=e.startRow&&a.endRow<=e.endRow&&a.startColumn>=e.startColumn&&a.endColumn<=e.endColumn){const f=a.endRow-a.startRow+1,S=a.endColumn-a.startColumn+1;if(s===null&&i===null)s=f,i=S;else if(f!==s||S!==i)return!1;c+=f*S}return c===u}const _={id:"sheet.command.sort-range",type:o.CommandType.COMMAND,handler:(e,n)=>{const{range:t,orderRules:r,hasTitle:s,unitId:i,subUnitId:u}=n,c=e.get(l.SheetsSortService),a=e.get(o.IUniverInstanceService),{worksheet:f}=d.getSheetCommandTarget(a,n)||{};if(!f)return!1;const S=f.getMergeData().filter(m=>o.Rectangle.contains(t,m)),p=S.map(m=>m.startRow),{startRow:v,endRow:J}=t,Q=s?v+1:v,R=[],F=[];for(let m=Q;m<=J;m++)f.getRowFiltered(m)||f.getRowRawVisible(m)!==!1&&(S.length&&!p.includes(m)||(R.push({index:m,value:$(f,m,r)}),F.push(m)));const X=c.getAllCompareFns();R.sort(G(r,L(X)));const D={};R.forEach(({index:m,value:se},ee)=>{D[F[ee]]=m});const Z={id:d.ReorderRangeCommand.id,params:{unitId:i,subUnitId:u,range:t,order:D}},k=e.get(o.ICommandService);return o.sequenceExecute([Z],k).result}};function $(e,n,t){const r=[];return t.forEach(({colIndex:s})=>{r.push(e.getCellRaw(n,s))}),r}function L(e){return(n,t,r)=>{for(let s=0;s<e.length;s++){const i=e[s](n,t,r);if(i!=null)return i}return 0}}function G(e,n){return function(t,r){let s=null;for(let i=0;i<e.length;i++){const u=t.value[i],c=r.value[i];if(s=n(e[i].type,u,c),s!==0&&s!==null&&s!==void 0)return s}return 0}}const q="sheets-sort.config",U={};var B=Object.getOwnPropertyDescriptor,H=(e,n,t,r)=>{for(var s=r>1?void 0:r?B(n,t):n,i=e.length-1,u;i>=0;i--)(u=e[i])&&(s=u(s)||s);return s},y=(e,n)=>(t,r)=>n(t,r,e);let h=class extends o.Disposable{constructor(e,n){super(),this._commandService=e,this._sortService=n,this._initCommands(),this._registerCompareFns()}_initCommands(){[_].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){const e=(n,t,r)=>{const s=this._getCommonValue(t),i=this._getCommonValue(r),u=[T,O,E];for(let c=0;c<u.length;c++){const a=u[c](s,i,n);if(a!==null)return a}return null};this._sortService.registerCompareFn(e)}_getCommonValue(e){var t,r;if(b(e))return null;const n=(r=(t=e==null?void 0:e.p)==null?void 0:t.body)==null?void 0:r.dataStream;return n||((e==null?void 0:e.t)===o.CellValueType.NUMBER?Number.parseFloat(`${e.v}`):(e==null?void 0:e.t)===o.CellValueType.STRING?typeof e.v=="number"?e.v:`${e.v}`:(e==null?void 0:e.t)===o.CellValueType.BOOLEAN?`${e.v}`:(e==null?void 0:e.t)===o.CellValueType.FORCE_STRING?Number.parseFloat(`${e.v}`):`${e==null?void 0:e.v}`)}};h=H([y(0,o.ICommandService),y(1,o.Inject(l.SheetsSortService))],h);var K=Object.defineProperty,W=Object.getOwnPropertyDescriptor,Y=(e,n,t)=>n in e?K(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,x=(e,n,t,r)=>{for(var s=r>1?void 0:r?W(n,t):n,i=e.length-1,u;i>=0;i--)(u=e[i])&&(s=u(s)||s);return s},A=(e,n)=>(t,r)=>n(t,r,e),P=(e,n,t)=>Y(e,typeof n!="symbol"?n+"":n,t);const z="SHEET_SORT_PLUGIN";l.UniverSheetsSortPlugin=class extends o.Plugin{constructor(n=U,t,r){super(),this._config=n,this._injector=t,this._configService=r;const{...s}=o.merge({},U,this._config);this._configService.setConfig(q,s)}onStarting(){[[h],[l.SheetsSortService]].forEach(n=>this._injector.add(n))}onReady(){this._injector.get(h)}},P(l.UniverSheetsSortPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),P(l.UniverSheetsSortPlugin,"pluginName",z),l.UniverSheetsSortPlugin=x([o.DependentOn(d.UniverSheetsPlugin,I.UniverFormulaEnginePlugin),A(1,o.Inject(o.Injector)),A(2,o.IConfigService)],l.UniverSheetsSortPlugin),l.SortRangeCommand=_,l.SortType=g,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports=="object"&&typeof module<"u"?module.exports=t():typeof define=="function"&&define.amd?define(t):(e=typeof globalThis<"u"?globalThis:e||self,e.UniverSheetsSortKoKR=t())})(this,function(){"use strict";return{sheetsSort:{title:"정렬",toolbar:{"sort-asc":"오름차순","sort-desc":"내림차순","sort-custom":"사용자 정의 순서"},"context-menu":{"sort-asc":"오름차순","sort-desc":"내림차순","sort-custom":"사용자 정의 순서"}}}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-sort",
3
- "version": "0.8.2",
3
+ "version": "0.8.3-nightly.202507010644",
4
4
  "private": false,
5
5
  "description": "A library for sorting data in Univer Sheet",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -58,15 +58,15 @@
58
58
  "lib"
59
59
  ],
60
60
  "dependencies": {
61
- "@univerjs/core": "0.8.2",
62
- "@univerjs/sheets": "0.8.2",
63
- "@univerjs/engine-formula": "0.8.2"
61
+ "@univerjs/core": "0.8.3-nightly.202507010644",
62
+ "@univerjs/engine-formula": "0.8.3-nightly.202507010644",
63
+ "@univerjs/sheets": "0.8.3-nightly.202507010644"
64
64
  },
65
65
  "devDependencies": {
66
66
  "typescript": "^5.8.3",
67
67
  "vite": "^6.3.5",
68
- "vitest": "^3.1.4",
69
- "@univerjs-infra/shared": "0.8.2"
68
+ "vitest": "^3.2.4",
69
+ "@univerjs-infra/shared": "0.8.3"
70
70
  },
71
71
  "scripts": {
72
72
  "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