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