@univerjs/sheets-sort 0.16.1 → 0.17.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/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"),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;
1
+ "use strict";var $=Object.defineProperty;var x=(e,r,t)=>r in e?$(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var b=(e,r,t)=>x(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@univerjs/core"),d=require("@univerjs/sheets"),F=require("@univerjs/engine-formula");var g=(e=>(e.DESC="desc",e.ASC="asc",e))(g||{});const P=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=P(e.toLocaleLowerCase())),o&&(r=P(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},D=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},p=(e,r)=>(t,n)=>r(t,n,e);exports.SheetsSortService=class extends u.Disposable{constructor(t,n,o){super();b(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(!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: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 C in f){const S=f[Number(C)];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(R.id,{orderRules:t.orderRules,range:t.range,hasTitle:(c=t.hasTitle)!=null?c:!1,unitId:n||s,subUnitId:o||i})}};exports.SheetsSortService=H([p(0,u.IUniverInstanceService),p(1,u.ICommandService),p(2,u.Inject(F.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 R={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)),C=f.map(m=>m.startRow),{startRow:S,endRow:T}=t,O=o?S+1:S,_=[],I=[];for(let m=O;m<=T;m++)a.getRowFiltered(m)||a.getRowRawVisible(m)!==!1&&(f.length&&!C.includes(m)||(_.push({index:m,value:K(a,m,n)}),I.push(m)));const E=c.getAllCompareFns();_.sort(Y(n,W(E)));const w={};_.forEach(({index:m,value:se},V)=>{w[I[V]]=m});const M={id:d.ReorderRangeCommand.id,params:{unitId:s,subUnitId:i,range:t,order:w}},j=e.get(u.ICommandService);return u.sequenceExecute([M],j).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="@univerjs/sheets-sort",J="0.17.0",N={name:z,version:J},Q="sheets-sort.config",A={};var X=Object.getOwnPropertyDescriptor,Z=(e,r,t,n)=>{for(var o=n>1?void 0:n?X(r,t):r,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(o)||o);return o},U=(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(){[R].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(D(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=Z([U(0,u.ICommandService),U(1,u.Inject(exports.SheetsSortService))],v);var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,re=(e,r,t)=>r in e?ee(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,ne=(e,r,t,n)=>{for(var o=n>1?void 0:n?te(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),h=(e,r,t)=>re(e,typeof r!="symbol"?r+"":r,t);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(Q,o)}onStarting(){[[v],[exports.SheetsSortService]].forEach(r=>this._injector.add(r))}onReady(){this._injector.get(v)}};h(exports.UniverSheetsSortPlugin,"type",u.UniverInstanceType.UNIVER_SHEET);h(exports.UniverSheetsSortPlugin,"pluginName","SHEET_SORT_PLUGIN");h(exports.UniverSheetsSortPlugin,"packageName",N.name);h(exports.UniverSheetsSortPlugin,"version",N.version);exports.UniverSheetsSortPlugin=ne([u.DependentOn(d.UniverSheetsPlugin,F.UniverFormulaEnginePlugin),y(1,u.Inject(u.Injector)),y(2,u.IConfigService)],exports.UniverSheetsSortPlugin);exports.SortRangeCommand=R;exports.SortType=g;
package/lib/es/index.js CHANGED
@@ -1,35 +1,35 @@
1
- var H = Object.defineProperty;
2
- var q = (e, t, r) => t in e ? H(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var F = (e, t, r) => q(e, typeof t != "symbol" ? t + "" : t, r);
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 { getSheetCommandTarget as U, ReorderRangeCommand as k, UniverSheetsPlugin as ee } from "@univerjs/sheets";
6
- import { FormulaDataModel as te, UniverFormulaEnginePlugin as re } from "@univerjs/engine-formula";
1
+ var q = Object.defineProperty;
2
+ var k = (e, t, r) => t in e ? q(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var N = (e, t, r) => k(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { IUniverInstanceService as P, ICommandService as w, Inject as I, Disposable as U, Rectangle as R, 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 { getSheetCommandTarget as T, ReorderRangeCommand as ee, UniverSheetsPlugin as te } from "@univerjs/sheets";
6
+ import { FormulaDataModel as re, UniverFormulaEnginePlugin as ne } from "@univerjs/engine-formula";
7
7
  var m = /* @__PURE__ */ ((e) => (e.DESC = "desc", e.ASC = "asc", e))(m || {});
8
- const N = (e) => e.replace(/-/gi, "").replace(/'/gi, ""), ne = (e, t) => {
8
+ const D = (e) => e.replace(/-/gi, "").replace(/'/gi, ""), oe = (e, t) => {
9
9
  const r = e === null || e === "", n = t === null || t === "";
10
10
  return r && n ? 0 : r ? 1 : n ? -1 : null;
11
- }, oe = (e, t, r) => {
11
+ }, se = (e, t, r) => {
12
12
  const n = typeof e == "number", o = typeof t == "number";
13
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;
14
- }, se = (e, t, r) => {
14
+ }, ie = (e, t, r) => {
15
15
  const n = typeof e == "string", o = typeof t == "string";
16
- if (n && (e = N(e.toLocaleLowerCase())), o && (t = N(t.toLocaleLowerCase())), !n && !o)
16
+ if (n && (e = D(e.toLocaleLowerCase())), o && (t = D(t.toLocaleLowerCase())), !n && !o)
17
17
  return null;
18
18
  if (n && o) {
19
19
  const s = e, i = t;
20
20
  return s < i ? r === m.ASC ? -1 : 1 : s > i ? r === m.ASC ? 1 : -1 : 0;
21
21
  }
22
22
  return n ? r === m.ASC ? 1 : -1 : o ? r === m.ASC ? -1 : 1 : null;
23
- }, T = (e) => !e || Object.keys(e).length === 0 || (e == null ? void 0 : e.v) == null && (e == null ? void 0 : e.p) == null;
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--)
23
+ }, M = (e) => !e || Object.keys(e).length === 0 || (e == null ? void 0 : e.v) == null && (e == null ? void 0 : e.p) == null;
24
+ var ue = Object.getOwnPropertyDescriptor, le = (e, t, r, n) => {
25
+ for (var o = n > 1 ? void 0 : n ? ue(t, r) : t, s = e.length - 1, i; s >= 0; s--)
26
26
  (i = e[s]) && (o = i(o) || o);
27
27
  return o;
28
- }, S = (e, t) => (r, n) => t(r, n, e);
29
- let g = class extends P {
28
+ }, p = (e, t) => (r, n) => t(r, n, e);
29
+ let d = class extends U {
30
30
  constructor(t, r, n) {
31
31
  super();
32
- F(this, "_compareFns", []);
32
+ N(this, "_compareFns", []);
33
33
  this._univerInstanceService = t, this._commandService = r, this._formulaDataModel = n;
34
34
  }
35
35
  mergeCheck(t) {
@@ -37,8 +37,8 @@ let g = class extends P {
37
37
  const { unitId: r, subUnitId: n, range: o } = t, s = (l = this._univerInstanceService.getUnit(r)) == null ? void 0 : l.getSheetBySheetId(n);
38
38
  if (!s)
39
39
  return !1;
40
- const i = s.getMergeData().filter((u) => p.contains(o, u));
41
- return i.length === 0 ? !0 : le(o, i);
40
+ const i = s.getMergeData().filter((u) => R.contains(o, u));
41
+ return i.length === 0 ? !0 : ce(o, i);
42
42
  }
43
43
  emptyCheck(t) {
44
44
  var i;
@@ -47,7 +47,7 @@ let g = class extends P {
47
47
  return !1;
48
48
  for (let l = o.startRow; l <= o.endRow; l++)
49
49
  for (let u = o.startColumn; u <= o.endColumn; u++)
50
- if (!T(s.getCellRaw(l, u)))
50
+ if (!M(s.getCellRaw(l, u)))
51
51
  return !0;
52
52
  return !1;
53
53
  }
@@ -60,8 +60,8 @@ let g = class extends P {
60
60
  for (const u in s) {
61
61
  const a = s[Number(u)];
62
62
  for (const f in a) {
63
- const d = a[Number(f)];
64
- if (d && p.intersects(o, d))
63
+ const v = a[Number(f)];
64
+ if (v && R.intersects(o, v))
65
65
  return !1;
66
66
  }
67
67
  }
@@ -75,8 +75,8 @@ let g = class extends P {
75
75
  }
76
76
  applySort(t, r, n) {
77
77
  var i;
78
- const { unitId: o, subUnitId: s } = U(this._univerInstanceService) || {};
79
- this._commandService.executeCommand(M.id, {
78
+ const { unitId: o, subUnitId: s } = T(this._univerInstanceService) || {};
79
+ this._commandService.executeCommand(x.id, {
80
80
  orderRules: t.orderRules,
81
81
  range: t.range,
82
82
  hasTitle: (i = t.hasTitle) != null ? i : !1,
@@ -85,12 +85,12 @@ let g = class extends P {
85
85
  });
86
86
  }
87
87
  };
88
- g = ue([
89
- S(0, O),
90
- S(1, R),
91
- S(2, w(te))
92
- ], g);
93
- function le(e, t) {
88
+ d = le([
89
+ p(0, P),
90
+ p(1, w),
91
+ p(2, I(re))
92
+ ], d);
93
+ function ce(e, t) {
94
94
  const r = e.endRow - e.startRow + 1, n = e.endColumn - e.startColumn + 1;
95
95
  let o = null, s = null;
96
96
  const i = r * n;
@@ -106,44 +106,44 @@ function le(e, t) {
106
106
  }
107
107
  return l === i;
108
108
  }
109
- const M = {
109
+ const x = {
110
110
  id: "sheet.command.sort-range",
111
111
  type: K.COMMAND,
112
112
  handler: (e, t) => {
113
- const { range: r, orderRules: n, hasTitle: o, unitId: s, subUnitId: i } = t, l = e.get(g), u = e.get(O), { worksheet: a } = U(u, t) || {};
113
+ const { range: r, orderRules: n, hasTitle: o, unitId: s, subUnitId: i } = t, l = e.get(d), u = e.get(P), { worksheet: a } = T(u, t) || {};
114
114
  if (!a)
115
115
  return !1;
116
- const f = a.getMergeData().filter((c) => p.contains(r, c)), d = f.map((c) => c.startRow), { startRow: I, endRow: $ } = r, j = o ? I + 1 : I, _ = [], b = [];
117
- for (let c = j; c <= $; c++)
118
- a.getRowFiltered(c) || a.getRowRawVisible(c) !== !1 && (f.length && !d.includes(c) || (_.push({
116
+ const f = a.getMergeData().filter((c) => R.contains(r, c)), v = f.map((c) => c.startRow), { startRow: b, endRow: j } = r, V = o ? b + 1 : b, S = [], A = [];
117
+ for (let c = V; c <= j; c++)
118
+ a.getRowFiltered(c) || a.getRowRawVisible(c) !== !1 && (f.length && !v.includes(c) || (S.push({
119
119
  index: c,
120
- value: ce(a, c, n)
121
- }), b.push(c)));
122
- const V = l.getAllCompareFns();
123
- _.sort(me(n, ae(V)));
124
- const A = {};
125
- _.forEach(({ index: c, value: Re }, B) => {
126
- A[b[B]] = c;
120
+ value: ae(a, c, n)
121
+ }), A.push(c)));
122
+ const L = l.getAllCompareFns();
123
+ S.sort(fe(n, me(L)));
124
+ const F = {};
125
+ S.forEach(({ index: c, value: Ie }, H) => {
126
+ F[A[H]] = c;
127
127
  });
128
- const L = {
129
- id: k.id,
128
+ const G = {
129
+ id: ee.id,
130
130
  params: {
131
131
  unitId: s,
132
132
  subUnitId: i,
133
133
  range: r,
134
- order: A
134
+ order: F
135
135
  }
136
- }, G = e.get(R);
137
- return W([L], G).result;
136
+ }, B = e.get(w);
137
+ return W([G], B).result;
138
138
  }
139
139
  };
140
- function ce(e, t, r) {
140
+ function ae(e, t, r) {
141
141
  const n = [];
142
142
  return r.forEach(({ colIndex: o }) => {
143
143
  n.push(e.getCellRaw(t, o));
144
144
  }), n;
145
145
  }
146
- function ae(e) {
146
+ function me(e) {
147
147
  return (t, r, n) => {
148
148
  for (let o = 0; o < e.length; o++) {
149
149
  const s = e[o](t, r, n);
@@ -153,7 +153,7 @@ function ae(e) {
153
153
  return 0;
154
154
  };
155
155
  }
156
- function me(e, t) {
156
+ function fe(e, t) {
157
157
  return function(r, n) {
158
158
  let o = null;
159
159
  for (let s = 0; s < e.length; s++) {
@@ -164,27 +164,30 @@ function me(e, t) {
164
164
  return 0;
165
165
  };
166
166
  }
167
- const fe = "sheets-sort.config", D = {};
168
- var ge = Object.getOwnPropertyDescriptor, de = (e, t, r, n) => {
169
- for (var o = n > 1 ? void 0 : n ? ge(t, r) : t, s = e.length - 1, i; s >= 0; s--)
167
+ const ge = "@univerjs/sheets-sort", de = "0.17.0", $ = {
168
+ name: ge,
169
+ version: de
170
+ }, ve = "sheets-sort.config", y = {};
171
+ var he = Object.getOwnPropertyDescriptor, Ce = (e, t, r, n) => {
172
+ for (var o = n > 1 ? void 0 : n ? he(t, r) : t, s = e.length - 1, i; s >= 0; s--)
170
173
  (i = e[s]) && (o = i(o) || o);
171
174
  return o;
172
175
  }, E = (e, t) => (r, n) => t(r, n, e);
173
- let v = class extends P {
176
+ let C = class extends U {
174
177
  constructor(e, t) {
175
178
  super(), this._commandService = e, this._sortService = t, this._initCommands(), this._registerCompareFns();
176
179
  }
177
180
  _initCommands() {
178
181
  [
179
- M
182
+ x
180
183
  ].forEach((e) => this.disposeWithMe(this._commandService.registerCommand(e)));
181
184
  }
182
185
  _registerCompareFns() {
183
186
  const e = (t, r, n) => {
184
187
  const o = this._getCommonValue(r), s = this._getCommonValue(n), i = [
185
- ne,
186
- se,
187
- oe
188
+ oe,
189
+ ie,
190
+ se
188
191
  ];
189
192
  for (let l = 0; l < i.length; l++) {
190
193
  const u = i[l](o, s, t);
@@ -197,52 +200,53 @@ let v = class extends P {
197
200
  }
198
201
  _getCommonValue(e) {
199
202
  var r, n;
200
- if (T(e))
203
+ if (M(e))
201
204
  return null;
202
205
  const t = (n = (r = e == null ? void 0 : e.p) == null ? void 0 : r.body) == null ? void 0 : n.dataStream;
203
206
  return t || ((e == null ? void 0 : e.t) === h.NUMBER ? Number.parseFloat(`${e.v}`) : (e == null ? void 0 : e.t) === h.STRING ? typeof e.v == "number" ? e.v : `${e.v}` : (e == null ? void 0 : e.t) === h.BOOLEAN ? `${e.v}` : (e == null ? void 0 : e.t) === h.FORCE_STRING ? Number.parseFloat(`${e.v}`) : `${e == null ? void 0 : e.v}`);
204
207
  }
205
208
  };
206
- v = de([
207
- E(0, R),
208
- E(1, w(g))
209
- ], v);
210
- var he = Object.defineProperty, ve = Object.getOwnPropertyDescriptor, Ce = (e, t, r) => t in e ? he(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, _e = (e, t, r, n) => {
211
- for (var o = n > 1 ? void 0 : n ? ve(t, r) : t, s = e.length - 1, i; s >= 0; s--)
209
+ C = Ce([
210
+ E(0, w),
211
+ E(1, I(d))
212
+ ], C);
213
+ var _e = Object.defineProperty, Se = Object.getOwnPropertyDescriptor, pe = (e, t, r) => t in e ? _e(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, Re = (e, t, r, n) => {
214
+ for (var o = n > 1 ? void 0 : n ? Se(t, r) : t, s = e.length - 1, i; s >= 0; s--)
212
215
  (i = e[s]) && (o = i(o) || o);
213
216
  return o;
214
- }, y = (e, t) => (r, n) => t(r, n, e), x = (e, t, r) => Ce(e, typeof t != "symbol" ? t + "" : t, r);
215
- const Se = "SHEET_SORT_PLUGIN";
216
- let C = class extends X {
217
- constructor(e = D, t, r) {
217
+ }, O = (e, t) => (r, n) => t(r, n, e), _ = (e, t, r) => pe(e, typeof t != "symbol" ? t + "" : t, r);
218
+ let g = class extends X {
219
+ constructor(e = y, t, r) {
218
220
  super(), this._config = e, this._injector = t, this._configService = r;
219
221
  const { ...n } = Z(
220
222
  {},
221
- D,
223
+ y,
222
224
  this._config
223
225
  );
224
- this._configService.setConfig(fe, n);
226
+ this._configService.setConfig(ve, n);
225
227
  }
226
228
  onStarting() {
227
229
  [
228
- [v],
229
- [g]
230
+ [C],
231
+ [d]
230
232
  ].forEach((e) => this._injector.add(e));
231
233
  }
232
234
  onReady() {
233
- this._injector.get(v);
235
+ this._injector.get(C);
234
236
  }
235
237
  };
236
- x(C, "type", Y.UNIVER_SHEET);
237
- x(C, "pluginName", Se);
238
- C = _e([
239
- z(ee, re),
240
- y(1, w(J)),
241
- y(2, Q)
242
- ], C);
238
+ _(g, "type", Y.UNIVER_SHEET);
239
+ _(g, "pluginName", "SHEET_SORT_PLUGIN");
240
+ _(g, "packageName", $.name);
241
+ _(g, "version", $.version);
242
+ g = Re([
243
+ z(te, ne),
244
+ O(1, I(J)),
245
+ O(2, Q)
246
+ ], g);
243
247
  export {
244
- g as SheetsSortService,
245
- M as SortRangeCommand,
248
+ d as SheetsSortService,
249
+ x as SortRangeCommand,
246
250
  m as SortType,
247
- C as UniverSheetsSortPlugin
251
+ g as UniverSheetsSortPlugin
248
252
  };
package/lib/index.js CHANGED
@@ -1,35 +1,35 @@
1
- var H = Object.defineProperty;
2
- var q = (e, t, r) => t in e ? H(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var F = (e, t, r) => q(e, typeof t != "symbol" ? t + "" : t, r);
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 { getSheetCommandTarget as U, ReorderRangeCommand as k, UniverSheetsPlugin as ee } from "@univerjs/sheets";
6
- import { FormulaDataModel as te, UniverFormulaEnginePlugin as re } from "@univerjs/engine-formula";
1
+ var q = Object.defineProperty;
2
+ var k = (e, t, r) => t in e ? q(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var N = (e, t, r) => k(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { IUniverInstanceService as P, ICommandService as w, Inject as I, Disposable as U, Rectangle as R, 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 { getSheetCommandTarget as T, ReorderRangeCommand as ee, UniverSheetsPlugin as te } from "@univerjs/sheets";
6
+ import { FormulaDataModel as re, UniverFormulaEnginePlugin as ne } from "@univerjs/engine-formula";
7
7
  var m = /* @__PURE__ */ ((e) => (e.DESC = "desc", e.ASC = "asc", e))(m || {});
8
- const N = (e) => e.replace(/-/gi, "").replace(/'/gi, ""), ne = (e, t) => {
8
+ const D = (e) => e.replace(/-/gi, "").replace(/'/gi, ""), oe = (e, t) => {
9
9
  const r = e === null || e === "", n = t === null || t === "";
10
10
  return r && n ? 0 : r ? 1 : n ? -1 : null;
11
- }, oe = (e, t, r) => {
11
+ }, se = (e, t, r) => {
12
12
  const n = typeof e == "number", o = typeof t == "number";
13
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;
14
- }, se = (e, t, r) => {
14
+ }, ie = (e, t, r) => {
15
15
  const n = typeof e == "string", o = typeof t == "string";
16
- if (n && (e = N(e.toLocaleLowerCase())), o && (t = N(t.toLocaleLowerCase())), !n && !o)
16
+ if (n && (e = D(e.toLocaleLowerCase())), o && (t = D(t.toLocaleLowerCase())), !n && !o)
17
17
  return null;
18
18
  if (n && o) {
19
19
  const s = e, i = t;
20
20
  return s < i ? r === m.ASC ? -1 : 1 : s > i ? r === m.ASC ? 1 : -1 : 0;
21
21
  }
22
22
  return n ? r === m.ASC ? 1 : -1 : o ? r === m.ASC ? -1 : 1 : null;
23
- }, T = (e) => !e || Object.keys(e).length === 0 || (e == null ? void 0 : e.v) == null && (e == null ? void 0 : e.p) == null;
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--)
23
+ }, M = (e) => !e || Object.keys(e).length === 0 || (e == null ? void 0 : e.v) == null && (e == null ? void 0 : e.p) == null;
24
+ var ue = Object.getOwnPropertyDescriptor, le = (e, t, r, n) => {
25
+ for (var o = n > 1 ? void 0 : n ? ue(t, r) : t, s = e.length - 1, i; s >= 0; s--)
26
26
  (i = e[s]) && (o = i(o) || o);
27
27
  return o;
28
- }, S = (e, t) => (r, n) => t(r, n, e);
29
- let g = class extends P {
28
+ }, p = (e, t) => (r, n) => t(r, n, e);
29
+ let d = class extends U {
30
30
  constructor(t, r, n) {
31
31
  super();
32
- F(this, "_compareFns", []);
32
+ N(this, "_compareFns", []);
33
33
  this._univerInstanceService = t, this._commandService = r, this._formulaDataModel = n;
34
34
  }
35
35
  mergeCheck(t) {
@@ -37,8 +37,8 @@ let g = class extends P {
37
37
  const { unitId: r, subUnitId: n, range: o } = t, s = (l = this._univerInstanceService.getUnit(r)) == null ? void 0 : l.getSheetBySheetId(n);
38
38
  if (!s)
39
39
  return !1;
40
- const i = s.getMergeData().filter((u) => p.contains(o, u));
41
- return i.length === 0 ? !0 : le(o, i);
40
+ const i = s.getMergeData().filter((u) => R.contains(o, u));
41
+ return i.length === 0 ? !0 : ce(o, i);
42
42
  }
43
43
  emptyCheck(t) {
44
44
  var i;
@@ -47,7 +47,7 @@ let g = class extends P {
47
47
  return !1;
48
48
  for (let l = o.startRow; l <= o.endRow; l++)
49
49
  for (let u = o.startColumn; u <= o.endColumn; u++)
50
- if (!T(s.getCellRaw(l, u)))
50
+ if (!M(s.getCellRaw(l, u)))
51
51
  return !0;
52
52
  return !1;
53
53
  }
@@ -60,8 +60,8 @@ let g = class extends P {
60
60
  for (const u in s) {
61
61
  const a = s[Number(u)];
62
62
  for (const f in a) {
63
- const d = a[Number(f)];
64
- if (d && p.intersects(o, d))
63
+ const v = a[Number(f)];
64
+ if (v && R.intersects(o, v))
65
65
  return !1;
66
66
  }
67
67
  }
@@ -75,8 +75,8 @@ let g = class extends P {
75
75
  }
76
76
  applySort(t, r, n) {
77
77
  var i;
78
- const { unitId: o, subUnitId: s } = U(this._univerInstanceService) || {};
79
- this._commandService.executeCommand(M.id, {
78
+ const { unitId: o, subUnitId: s } = T(this._univerInstanceService) || {};
79
+ this._commandService.executeCommand(x.id, {
80
80
  orderRules: t.orderRules,
81
81
  range: t.range,
82
82
  hasTitle: (i = t.hasTitle) != null ? i : !1,
@@ -85,12 +85,12 @@ let g = class extends P {
85
85
  });
86
86
  }
87
87
  };
88
- g = ue([
89
- S(0, O),
90
- S(1, R),
91
- S(2, w(te))
92
- ], g);
93
- function le(e, t) {
88
+ d = le([
89
+ p(0, P),
90
+ p(1, w),
91
+ p(2, I(re))
92
+ ], d);
93
+ function ce(e, t) {
94
94
  const r = e.endRow - e.startRow + 1, n = e.endColumn - e.startColumn + 1;
95
95
  let o = null, s = null;
96
96
  const i = r * n;
@@ -106,44 +106,44 @@ function le(e, t) {
106
106
  }
107
107
  return l === i;
108
108
  }
109
- const M = {
109
+ const x = {
110
110
  id: "sheet.command.sort-range",
111
111
  type: K.COMMAND,
112
112
  handler: (e, t) => {
113
- const { range: r, orderRules: n, hasTitle: o, unitId: s, subUnitId: i } = t, l = e.get(g), u = e.get(O), { worksheet: a } = U(u, t) || {};
113
+ const { range: r, orderRules: n, hasTitle: o, unitId: s, subUnitId: i } = t, l = e.get(d), u = e.get(P), { worksheet: a } = T(u, t) || {};
114
114
  if (!a)
115
115
  return !1;
116
- const f = a.getMergeData().filter((c) => p.contains(r, c)), d = f.map((c) => c.startRow), { startRow: I, endRow: $ } = r, j = o ? I + 1 : I, _ = [], b = [];
117
- for (let c = j; c <= $; c++)
118
- a.getRowFiltered(c) || a.getRowRawVisible(c) !== !1 && (f.length && !d.includes(c) || (_.push({
116
+ const f = a.getMergeData().filter((c) => R.contains(r, c)), v = f.map((c) => c.startRow), { startRow: b, endRow: j } = r, V = o ? b + 1 : b, S = [], A = [];
117
+ for (let c = V; c <= j; c++)
118
+ a.getRowFiltered(c) || a.getRowRawVisible(c) !== !1 && (f.length && !v.includes(c) || (S.push({
119
119
  index: c,
120
- value: ce(a, c, n)
121
- }), b.push(c)));
122
- const V = l.getAllCompareFns();
123
- _.sort(me(n, ae(V)));
124
- const A = {};
125
- _.forEach(({ index: c, value: Re }, B) => {
126
- A[b[B]] = c;
120
+ value: ae(a, c, n)
121
+ }), A.push(c)));
122
+ const L = l.getAllCompareFns();
123
+ S.sort(fe(n, me(L)));
124
+ const F = {};
125
+ S.forEach(({ index: c, value: Ie }, H) => {
126
+ F[A[H]] = c;
127
127
  });
128
- const L = {
129
- id: k.id,
128
+ const G = {
129
+ id: ee.id,
130
130
  params: {
131
131
  unitId: s,
132
132
  subUnitId: i,
133
133
  range: r,
134
- order: A
134
+ order: F
135
135
  }
136
- }, G = e.get(R);
137
- return W([L], G).result;
136
+ }, B = e.get(w);
137
+ return W([G], B).result;
138
138
  }
139
139
  };
140
- function ce(e, t, r) {
140
+ function ae(e, t, r) {
141
141
  const n = [];
142
142
  return r.forEach(({ colIndex: o }) => {
143
143
  n.push(e.getCellRaw(t, o));
144
144
  }), n;
145
145
  }
146
- function ae(e) {
146
+ function me(e) {
147
147
  return (t, r, n) => {
148
148
  for (let o = 0; o < e.length; o++) {
149
149
  const s = e[o](t, r, n);
@@ -153,7 +153,7 @@ function ae(e) {
153
153
  return 0;
154
154
  };
155
155
  }
156
- function me(e, t) {
156
+ function fe(e, t) {
157
157
  return function(r, n) {
158
158
  let o = null;
159
159
  for (let s = 0; s < e.length; s++) {
@@ -164,27 +164,30 @@ function me(e, t) {
164
164
  return 0;
165
165
  };
166
166
  }
167
- const fe = "sheets-sort.config", D = {};
168
- var ge = Object.getOwnPropertyDescriptor, de = (e, t, r, n) => {
169
- for (var o = n > 1 ? void 0 : n ? ge(t, r) : t, s = e.length - 1, i; s >= 0; s--)
167
+ const ge = "@univerjs/sheets-sort", de = "0.17.0", $ = {
168
+ name: ge,
169
+ version: de
170
+ }, ve = "sheets-sort.config", y = {};
171
+ var he = Object.getOwnPropertyDescriptor, Ce = (e, t, r, n) => {
172
+ for (var o = n > 1 ? void 0 : n ? he(t, r) : t, s = e.length - 1, i; s >= 0; s--)
170
173
  (i = e[s]) && (o = i(o) || o);
171
174
  return o;
172
175
  }, E = (e, t) => (r, n) => t(r, n, e);
173
- let v = class extends P {
176
+ let C = class extends U {
174
177
  constructor(e, t) {
175
178
  super(), this._commandService = e, this._sortService = t, this._initCommands(), this._registerCompareFns();
176
179
  }
177
180
  _initCommands() {
178
181
  [
179
- M
182
+ x
180
183
  ].forEach((e) => this.disposeWithMe(this._commandService.registerCommand(e)));
181
184
  }
182
185
  _registerCompareFns() {
183
186
  const e = (t, r, n) => {
184
187
  const o = this._getCommonValue(r), s = this._getCommonValue(n), i = [
185
- ne,
186
- se,
187
- oe
188
+ oe,
189
+ ie,
190
+ se
188
191
  ];
189
192
  for (let l = 0; l < i.length; l++) {
190
193
  const u = i[l](o, s, t);
@@ -197,52 +200,53 @@ let v = class extends P {
197
200
  }
198
201
  _getCommonValue(e) {
199
202
  var r, n;
200
- if (T(e))
203
+ if (M(e))
201
204
  return null;
202
205
  const t = (n = (r = e == null ? void 0 : e.p) == null ? void 0 : r.body) == null ? void 0 : n.dataStream;
203
206
  return t || ((e == null ? void 0 : e.t) === h.NUMBER ? Number.parseFloat(`${e.v}`) : (e == null ? void 0 : e.t) === h.STRING ? typeof e.v == "number" ? e.v : `${e.v}` : (e == null ? void 0 : e.t) === h.BOOLEAN ? `${e.v}` : (e == null ? void 0 : e.t) === h.FORCE_STRING ? Number.parseFloat(`${e.v}`) : `${e == null ? void 0 : e.v}`);
204
207
  }
205
208
  };
206
- v = de([
207
- E(0, R),
208
- E(1, w(g))
209
- ], v);
210
- var he = Object.defineProperty, ve = Object.getOwnPropertyDescriptor, Ce = (e, t, r) => t in e ? he(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, _e = (e, t, r, n) => {
211
- for (var o = n > 1 ? void 0 : n ? ve(t, r) : t, s = e.length - 1, i; s >= 0; s--)
209
+ C = Ce([
210
+ E(0, w),
211
+ E(1, I(d))
212
+ ], C);
213
+ var _e = Object.defineProperty, Se = Object.getOwnPropertyDescriptor, pe = (e, t, r) => t in e ? _e(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, Re = (e, t, r, n) => {
214
+ for (var o = n > 1 ? void 0 : n ? Se(t, r) : t, s = e.length - 1, i; s >= 0; s--)
212
215
  (i = e[s]) && (o = i(o) || o);
213
216
  return o;
214
- }, y = (e, t) => (r, n) => t(r, n, e), x = (e, t, r) => Ce(e, typeof t != "symbol" ? t + "" : t, r);
215
- const Se = "SHEET_SORT_PLUGIN";
216
- let C = class extends X {
217
- constructor(e = D, t, r) {
217
+ }, O = (e, t) => (r, n) => t(r, n, e), _ = (e, t, r) => pe(e, typeof t != "symbol" ? t + "" : t, r);
218
+ let g = class extends X {
219
+ constructor(e = y, t, r) {
218
220
  super(), this._config = e, this._injector = t, this._configService = r;
219
221
  const { ...n } = Z(
220
222
  {},
221
- D,
223
+ y,
222
224
  this._config
223
225
  );
224
- this._configService.setConfig(fe, n);
226
+ this._configService.setConfig(ve, n);
225
227
  }
226
228
  onStarting() {
227
229
  [
228
- [v],
229
- [g]
230
+ [C],
231
+ [d]
230
232
  ].forEach((e) => this._injector.add(e));
231
233
  }
232
234
  onReady() {
233
- this._injector.get(v);
235
+ this._injector.get(C);
234
236
  }
235
237
  };
236
- x(C, "type", Y.UNIVER_SHEET);
237
- x(C, "pluginName", Se);
238
- C = _e([
239
- z(ee, re),
240
- y(1, w(J)),
241
- y(2, Q)
242
- ], C);
238
+ _(g, "type", Y.UNIVER_SHEET);
239
+ _(g, "pluginName", "SHEET_SORT_PLUGIN");
240
+ _(g, "packageName", $.name);
241
+ _(g, "version", $.version);
242
+ g = Re([
243
+ z(te, ne),
244
+ O(1, I(J)),
245
+ O(2, Q)
246
+ ], g);
243
247
  export {
244
- g as SheetsSortService,
245
- M as SortRangeCommand,
248
+ d as SheetsSortService,
249
+ x as SortRangeCommand,
246
250
  m as SortType,
247
- C as UniverSheetsSortPlugin
251
+ g as UniverSheetsSortPlugin
248
252
  };
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export { type ISortRangeCommandParams, SortRangeCommand } from './commands/commands/sheets-sort.command';
17
- export type { IUniverSheetsSortConfig } from './controllers/config.schema';
17
+ export type { IUniverSheetsSortConfig } from './config/config';
18
18
  export { UniverSheetsSortPlugin } from './plugin';
19
19
  export { type IOrderRule, type ISortOption, SortType } from './services/interface';
20
20
  export { SheetsSortService } from './services/sheets-sort.service';
@@ -1,4 +1,4 @@
1
- import { IUniverSheetsSortConfig } from './controllers/config.schema';
1
+ import { IUniverSheetsSortConfig } from './config/config';
2
2
  import { IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
3
3
  export declare class UniverSheetsSortPlugin extends Plugin {
4
4
  private readonly _config;
@@ -6,6 +6,8 @@ export declare class UniverSheetsSortPlugin extends Plugin {
6
6
  private readonly _configService;
7
7
  static type: UniverInstanceType;
8
8
  static pluginName: string;
9
+ static packageName: string;
10
+ static version: string;
9
11
  constructor(_config: Partial<IUniverSheetsSortConfig> | undefined, _injector: Injector, _configService: IConfigService);
10
12
  onStarting(): void;
11
13
  onReady(): void;
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/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"})}));
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,S,w){"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 T=(l,o,S)=>ne(l,typeof o!="symbol"?o+"":o,S);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();T(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(m=>o.Rectangle.contains(i,m));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 m=i.startColumn;m<=i.endColumn;m++)if(!U(u.getCellRaw(a,m)))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 m in u){const d=u[Number(m)];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}=S.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(w.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 m=a.endRow-a.startRow+1,d=a.endColumn-a.startColumn+1;if(s===null&&i===null)s=m,i=d;else if(m!==s||d!==i)return!1;c+=m*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:m}=S.getSheetCommandTarget(a,n)||{};if(!m)return!1;const d=m.getMergeData().filter(f=>o.Rectangle.contains(t,f)),R=d.map(f=>f.startRow),{startRow:v,endRow:J}=t,Q=s?v+1:v,I=[],D=[];for(let f=Q;f<=J;f++)m.getRowFiltered(f)||m.getRowRawVisible(f)!==!1&&(d.length&&!R.includes(f)||(I.push({index:f,value:L(m,f,r)}),D.push(f)));const X=c.getAllCompareFns();I.sort(q(r,G(X)));const N={};I.forEach(({index:f,value:oe},ee)=>{N[D[ee]]=f});const Z={id:S.ReorderRangeCommand.id,params:{unitId:i,subUnitId:u,range:t,order:N}},x=e.get(o.ICommandService);return o.sequenceExecute([Z],x).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}}const y={name:"@univerjs/sheets-sort",version:"0.17.0"},B="sheets-sort.config",P={};var H=Object.getOwnPropertyDescriptor,k=(e,n,t,r)=>{for(var s=r>1?void 0:r?H(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);let h=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}`)}};h=k([A(0,o.ICommandService),A(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,z=(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},F=(e,n)=>(t,r)=>n(t,r,e),C=(e,n,t)=>Y(e,typeof n!="symbol"?n+"":n,t);l.UniverSheetsSortPlugin=class extends o.Plugin{constructor(n=P,t,r){super(),this._config=n,this._injector=t,this._configService=r;const{...s}=o.merge({},P,this._config);this._configService.setConfig(B,s)}onStarting(){[[h],[l.SheetsSortService]].forEach(n=>this._injector.add(n))}onReady(){this._injector.get(h)}},C(l.UniverSheetsSortPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),C(l.UniverSheetsSortPlugin,"pluginName","SHEET_SORT_PLUGIN"),C(l.UniverSheetsSortPlugin,"packageName",y.name),C(l.UniverSheetsSortPlugin,"version",y.version),l.UniverSheetsSortPlugin=z([o.DependentOn(S.UniverSheetsPlugin,w.UniverFormulaEnginePlugin),F(1,o.Inject(o.Injector)),F(2,o.IConfigService)],l.UniverSheetsSortPlugin),l.SortRangeCommand=p,l.SortType=g,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.16.1",
3
+ "version": "0.17.0",
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.16.1",
62
- "@univerjs/sheets": "0.16.1",
63
- "@univerjs/engine-formula": "0.16.1"
61
+ "@univerjs/core": "0.17.0",
62
+ "@univerjs/sheets": "0.17.0",
63
+ "@univerjs/engine-formula": "0.17.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "typescript": "^5.9.3",
67
67
  "vite": "^7.3.1",
68
68
  "vitest": "^4.0.18",
69
- "@univerjs-infra/shared": "0.16.1"
69
+ "@univerjs-infra/shared": "0.17.0"
70
70
  },
71
71
  "scripts": {
72
72
  "test": "vitest run",