@univerjs/sheets-sort 0.8.2-nightly.202506261607 → 0.8.3-nightly.202506271607
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +26 -26
- package/lib/index.js +26 -26
- package/lib/types/index.d.ts +3 -2
- package/lib/umd/index.js +1 -1
- package/package.json +5 -5
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"),
|
|
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;
|
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 {
|
|
6
|
-
import {
|
|
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
|
|
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
|
-
},
|
|
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
|
-
},
|
|
14
|
+
}, se = (e, t, r) => {
|
|
16
15
|
const n = typeof e == "string", o = typeof t == "string";
|
|
17
|
-
if (n && (e =
|
|
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
|
|
26
|
-
for (var o = n > 1 ? void 0 : n ?
|
|
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 :
|
|
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 =
|
|
88
|
+
g = ue([
|
|
90
89
|
S(0, O),
|
|
91
90
|
S(1, R),
|
|
92
|
-
S(2, w(
|
|
91
|
+
S(2, w(te))
|
|
93
92
|
], g);
|
|
94
|
-
function
|
|
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:
|
|
120
|
+
value: ce(a, c, n)
|
|
122
121
|
}), b.push(c)));
|
|
123
122
|
const V = l.getAllCompareFns();
|
|
124
|
-
_.sort(
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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 =
|
|
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
|
-
|
|
221
|
+
D,
|
|
222
222
|
this._config
|
|
223
223
|
);
|
|
224
|
-
this._configService.setConfig(
|
|
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(
|
|
239
|
+
z(ee, re),
|
|
240
240
|
y(1, w(J)),
|
|
241
241
|
y(2, Q)
|
|
242
242
|
], C);
|
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 {
|
|
6
|
-
import {
|
|
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
|
|
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
|
-
},
|
|
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
|
-
},
|
|
14
|
+
}, se = (e, t, r) => {
|
|
16
15
|
const n = typeof e == "string", o = typeof t == "string";
|
|
17
|
-
if (n && (e =
|
|
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
|
|
26
|
-
for (var o = n > 1 ? void 0 : n ?
|
|
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 :
|
|
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 =
|
|
88
|
+
g = ue([
|
|
90
89
|
S(0, O),
|
|
91
90
|
S(1, R),
|
|
92
|
-
S(2, w(
|
|
91
|
+
S(2, w(te))
|
|
93
92
|
], g);
|
|
94
|
-
function
|
|
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:
|
|
120
|
+
value: ce(a, c, n)
|
|
122
121
|
}), b.push(c)));
|
|
123
122
|
const V = l.getAllCompareFns();
|
|
124
|
-
_.sort(
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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 =
|
|
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
|
-
|
|
221
|
+
D,
|
|
222
222
|
this._config
|
|
223
223
|
);
|
|
224
|
-
this._configService.setConfig(
|
|
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(
|
|
239
|
+
z(ee, re),
|
|
240
240
|
y(1, w(J)),
|
|
241
241
|
y(2, Q)
|
|
242
242
|
], C);
|
package/lib/types/index.d.ts
CHANGED
|
@@ -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 {
|
|
20
|
+
export { SheetsSortService } from './services/sheets-sort.service';
|
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/
|
|
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"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-sort",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3-nightly.202506271607",
|
|
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.
|
|
62
|
-
"@univerjs/engine-formula": "0.8.
|
|
63
|
-
"@univerjs/sheets": "0.8.
|
|
61
|
+
"@univerjs/core": "0.8.3-nightly.202506271607",
|
|
62
|
+
"@univerjs/engine-formula": "0.8.3-nightly.202506271607",
|
|
63
|
+
"@univerjs/sheets": "0.8.3-nightly.202506271607"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"typescript": "^5.8.3",
|
|
67
67
|
"vite": "^6.3.5",
|
|
68
68
|
"vitest": "^3.2.4",
|
|
69
|
-
"@univerjs-infra/shared": "0.8.
|
|
69
|
+
"@univerjs-infra/shared": "0.8.3"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"test": "vitest run",
|