@univerjs/sheets-sort 0.21.1 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,31 +1,45 @@
1
1
  # @univerjs/sheets-sort
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@univerjs/sheets-sort?style=flat-square)](https://npmjs.com/package/@univerjs/sheets-sort)
4
+ [![license](https://img.shields.io/npm/l/@univerjs/sheets-sort?style=flat-square)](https://npmjs.com/package/@univerjs/sheets-sort)
5
+ [![downloads](https://img.shields.io/npm/dm/@univerjs/sheets-sort?style=flat-square)](https://npmjs.com/package/@univerjs/sheets-sort)
6
+
7
+ `@univerjs/sheets-sort` adds the core sorting model, commands, and services for Univer Sheets.
8
+
3
9
  ## Package Overview
4
10
 
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] | ❌ | ⭕️ |
11
+ | Package | UMD global | CSS | Locales | Facade entry |
12
+ | --- | --- | :---: | :---: | :---: |
13
+ | `@univerjs/sheets-sort` | `UniverSheetsSort` | No | Yes | Yes |
8
14
 
9
- ## Introduction
15
+ ## Installation
10
16
 
11
- `@univerjs/sheets-sort` is a sort plugin for Univer Sheet.
17
+ ```sh
18
+ pnpm add @univerjs/sheets-sort
19
+ # or
20
+ npm install @univerjs/sheets-sort
21
+ ```
22
+
23
+ Keep all `@univerjs/*` packages on the same version.
12
24
 
13
25
  ## Usage
14
26
 
15
- You should use this plugin with the `@univerjs/sheets-sort-ui` package.
27
+ ```ts
28
+ import EnUS from '@univerjs/sheets-sort/locale/en-US';
29
+ import { UniverSheetsSortPlugin } from '@univerjs/sheets-sort';
16
30
 
17
- ### Installation
31
+ univer.registerPlugin(UniverSheetsSortPlugin);
18
32
 
19
- ```shell
20
- # Using npm
21
- npm install @univerjs/sheets-sort
22
-
23
- # Using pnpm
24
- pnpm add @univerjs/sheets-sort
33
+ // Merge EnUS into your Univer locale map when this package contributes UI text.
25
34
  ```
26
35
 
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
36
+ ## Integration Notes
37
+
38
+ Use this package with `@univerjs/sheets-sort-ui` when users need sorting menus and panels.
39
+
40
+ ## Resources
41
+
42
+ - [Documentation](https://docs.univer.ai)
43
+ - [NPM package](https://npmjs.com/package/@univerjs/sheets-sort)
44
+ - [GitHub repository](https://github.com/dream-num/univer)
45
+
package/lib/cjs/index.js CHANGED
@@ -12,33 +12,27 @@ let SortType = /* @__PURE__ */ function(SortType) {
12
12
 
13
13
  //#endregion
14
14
  //#region src/controllers/utils.ts
15
- let ORDER = /* @__PURE__ */ function(ORDER) {
16
- ORDER[ORDER["POSITIVE"] = 1] = "POSITIVE";
17
- ORDER[ORDER["NEGATIVE"] = -1] = "NEGATIVE";
18
- ORDER[ORDER["ZERO"] = 0] = "ZERO";
19
- return ORDER;
20
- }({});
21
15
  const removeStringSymbol = (str) => {
22
16
  return str.replace(/-/gi, "").replace(/'/gi, "");
23
17
  };
24
18
  const compareNull = (a1, a2) => {
25
19
  const isA1Null = a1 === null || a1 === "";
26
20
  const isA2Null = a2 === null || a2 === "";
27
- if (isA1Null && isA2Null) return ORDER.ZERO;
28
- if (isA1Null) return ORDER.POSITIVE;
29
- if (isA2Null) return ORDER.NEGATIVE;
21
+ if (isA1Null && isA2Null) return 0;
22
+ if (isA1Null) return 1;
23
+ if (isA2Null) return -1;
30
24
  return null;
31
25
  };
32
26
  const compareNumber = (a1, a2, type) => {
33
27
  const isA1Num = typeof a1 === "number";
34
28
  const isA2Num = typeof a2 === "number";
35
29
  if (isA1Num && isA2Num) {
36
- if (a1 < a2) return type === SortType.ASC ? ORDER.NEGATIVE : ORDER.POSITIVE;
37
- if (a1 > a2) return type === SortType.ASC ? ORDER.POSITIVE : ORDER.NEGATIVE;
38
- return ORDER.ZERO;
30
+ if (a1 < a2) return type === "asc" ? -1 : 1;
31
+ if (a1 > a2) return type === "asc" ? 1 : -1;
32
+ return 0;
39
33
  }
40
- if (isA1Num) return type === SortType.ASC ? ORDER.POSITIVE : ORDER.NEGATIVE;
41
- if (isA2Num) return type === SortType.ASC ? ORDER.NEGATIVE : ORDER.POSITIVE;
34
+ if (isA1Num) return type === "asc" ? 1 : -1;
35
+ if (isA2Num) return type === "asc" ? -1 : 1;
42
36
  return null;
43
37
  };
44
38
  const compareString = (a1, a2, type) => {
@@ -50,12 +44,12 @@ const compareString = (a1, a2, type) => {
50
44
  if (isA1Str && isA2Str) {
51
45
  const a1AsString = a1;
52
46
  const a2AsString = a2;
53
- if (a1AsString < a2AsString) return type === SortType.ASC ? ORDER.NEGATIVE : ORDER.POSITIVE;
54
- if (a1AsString > a2AsString) return type === SortType.ASC ? ORDER.POSITIVE : ORDER.NEGATIVE;
55
- return ORDER.ZERO;
47
+ if (a1AsString < a2AsString) return type === "asc" ? -1 : 1;
48
+ if (a1AsString > a2AsString) return type === "asc" ? 1 : -1;
49
+ return 0;
56
50
  }
57
- if (isA1Str) return type === SortType.ASC ? ORDER.POSITIVE : ORDER.NEGATIVE;
58
- if (isA2Str) return type === SortType.ASC ? ORDER.NEGATIVE : ORDER.POSITIVE;
51
+ if (isA1Str) return type === "asc" ? 1 : -1;
52
+ if (isA2Str) return type === "asc" ? -1 : 1;
59
53
  return null;
60
54
  };
61
55
  const isNullValue = (cell) => {
@@ -66,7 +60,7 @@ const isNullValue = (cell) => {
66
60
  };
67
61
 
68
62
  //#endregion
69
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
63
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
70
64
  function _typeof(o) {
71
65
  "@babel/helpers - typeof";
72
66
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -77,7 +71,7 @@ function _typeof(o) {
77
71
  }
78
72
 
79
73
  //#endregion
80
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
74
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
81
75
  function toPrimitive(t, r) {
82
76
  if ("object" != _typeof(t) || !t) return t;
83
77
  var e = t[Symbol.toPrimitive];
@@ -90,14 +84,14 @@ function toPrimitive(t, r) {
90
84
  }
91
85
 
92
86
  //#endregion
93
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
87
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
94
88
  function toPropertyKey(t) {
95
89
  var i = toPrimitive(t, "string");
96
90
  return "symbol" == _typeof(i) ? i : i + "";
97
91
  }
98
92
 
99
93
  //#endregion
100
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
94
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
101
95
  function _defineProperty(e, r, t) {
102
96
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
103
97
  value: t,
@@ -108,7 +102,7 @@ function _defineProperty(e, r, t) {
108
102
  }
109
103
 
110
104
  //#endregion
111
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
105
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
112
106
  function __decorateParam(paramIndex, decorator) {
113
107
  return function(target, key) {
114
108
  decorator(target, key, paramIndex);
@@ -116,7 +110,7 @@ function __decorateParam(paramIndex, decorator) {
116
110
  }
117
111
 
118
112
  //#endregion
119
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
113
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
120
114
  function __decorate(decorators, target, key, desc) {
121
115
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
122
116
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -291,7 +285,7 @@ function reorderFnGenerator(orderRules, valueCompare) {
291
285
  //#endregion
292
286
  //#region package.json
293
287
  var name = "@univerjs/sheets-sort";
294
- var version = "0.21.1";
288
+ var version = "0.22.0";
295
289
 
296
290
  //#endregion
297
291
  //#region src/config/config.ts
package/lib/es/index.js CHANGED
@@ -11,33 +11,27 @@ let SortType = /* @__PURE__ */ function(SortType) {
11
11
 
12
12
  //#endregion
13
13
  //#region src/controllers/utils.ts
14
- let ORDER = /* @__PURE__ */ function(ORDER) {
15
- ORDER[ORDER["POSITIVE"] = 1] = "POSITIVE";
16
- ORDER[ORDER["NEGATIVE"] = -1] = "NEGATIVE";
17
- ORDER[ORDER["ZERO"] = 0] = "ZERO";
18
- return ORDER;
19
- }({});
20
14
  const removeStringSymbol = (str) => {
21
15
  return str.replace(/-/gi, "").replace(/'/gi, "");
22
16
  };
23
17
  const compareNull = (a1, a2) => {
24
18
  const isA1Null = a1 === null || a1 === "";
25
19
  const isA2Null = a2 === null || a2 === "";
26
- if (isA1Null && isA2Null) return ORDER.ZERO;
27
- if (isA1Null) return ORDER.POSITIVE;
28
- if (isA2Null) return ORDER.NEGATIVE;
20
+ if (isA1Null && isA2Null) return 0;
21
+ if (isA1Null) return 1;
22
+ if (isA2Null) return -1;
29
23
  return null;
30
24
  };
31
25
  const compareNumber = (a1, a2, type) => {
32
26
  const isA1Num = typeof a1 === "number";
33
27
  const isA2Num = typeof a2 === "number";
34
28
  if (isA1Num && isA2Num) {
35
- if (a1 < a2) return type === SortType.ASC ? ORDER.NEGATIVE : ORDER.POSITIVE;
36
- if (a1 > a2) return type === SortType.ASC ? ORDER.POSITIVE : ORDER.NEGATIVE;
37
- return ORDER.ZERO;
29
+ if (a1 < a2) return type === "asc" ? -1 : 1;
30
+ if (a1 > a2) return type === "asc" ? 1 : -1;
31
+ return 0;
38
32
  }
39
- if (isA1Num) return type === SortType.ASC ? ORDER.POSITIVE : ORDER.NEGATIVE;
40
- if (isA2Num) return type === SortType.ASC ? ORDER.NEGATIVE : ORDER.POSITIVE;
33
+ if (isA1Num) return type === "asc" ? 1 : -1;
34
+ if (isA2Num) return type === "asc" ? -1 : 1;
41
35
  return null;
42
36
  };
43
37
  const compareString = (a1, a2, type) => {
@@ -49,12 +43,12 @@ const compareString = (a1, a2, type) => {
49
43
  if (isA1Str && isA2Str) {
50
44
  const a1AsString = a1;
51
45
  const a2AsString = a2;
52
- if (a1AsString < a2AsString) return type === SortType.ASC ? ORDER.NEGATIVE : ORDER.POSITIVE;
53
- if (a1AsString > a2AsString) return type === SortType.ASC ? ORDER.POSITIVE : ORDER.NEGATIVE;
54
- return ORDER.ZERO;
46
+ if (a1AsString < a2AsString) return type === "asc" ? -1 : 1;
47
+ if (a1AsString > a2AsString) return type === "asc" ? 1 : -1;
48
+ return 0;
55
49
  }
56
- if (isA1Str) return type === SortType.ASC ? ORDER.POSITIVE : ORDER.NEGATIVE;
57
- if (isA2Str) return type === SortType.ASC ? ORDER.NEGATIVE : ORDER.POSITIVE;
50
+ if (isA1Str) return type === "asc" ? 1 : -1;
51
+ if (isA2Str) return type === "asc" ? -1 : 1;
58
52
  return null;
59
53
  };
60
54
  const isNullValue = (cell) => {
@@ -65,7 +59,7 @@ const isNullValue = (cell) => {
65
59
  };
66
60
 
67
61
  //#endregion
68
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
62
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
69
63
  function _typeof(o) {
70
64
  "@babel/helpers - typeof";
71
65
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -76,7 +70,7 @@ function _typeof(o) {
76
70
  }
77
71
 
78
72
  //#endregion
79
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
73
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
80
74
  function toPrimitive(t, r) {
81
75
  if ("object" != _typeof(t) || !t) return t;
82
76
  var e = t[Symbol.toPrimitive];
@@ -89,14 +83,14 @@ function toPrimitive(t, r) {
89
83
  }
90
84
 
91
85
  //#endregion
92
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
86
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
93
87
  function toPropertyKey(t) {
94
88
  var i = toPrimitive(t, "string");
95
89
  return "symbol" == _typeof(i) ? i : i + "";
96
90
  }
97
91
 
98
92
  //#endregion
99
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
93
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
100
94
  function _defineProperty(e, r, t) {
101
95
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
102
96
  value: t,
@@ -107,7 +101,7 @@ function _defineProperty(e, r, t) {
107
101
  }
108
102
 
109
103
  //#endregion
110
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
104
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
111
105
  function __decorateParam(paramIndex, decorator) {
112
106
  return function(target, key) {
113
107
  decorator(target, key, paramIndex);
@@ -115,7 +109,7 @@ function __decorateParam(paramIndex, decorator) {
115
109
  }
116
110
 
117
111
  //#endregion
118
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
112
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
119
113
  function __decorate(decorators, target, key, desc) {
120
114
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
121
115
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -290,7 +284,7 @@ function reorderFnGenerator(orderRules, valueCompare) {
290
284
  //#endregion
291
285
  //#region package.json
292
286
  var name = "@univerjs/sheets-sort";
293
- var version = "0.21.1";
287
+ var version = "0.22.0";
294
288
 
295
289
  //#endregion
296
290
  //#region src/config/config.ts
package/lib/index.js CHANGED
@@ -11,33 +11,27 @@ let SortType = /* @__PURE__ */ function(SortType) {
11
11
 
12
12
  //#endregion
13
13
  //#region src/controllers/utils.ts
14
- let ORDER = /* @__PURE__ */ function(ORDER) {
15
- ORDER[ORDER["POSITIVE"] = 1] = "POSITIVE";
16
- ORDER[ORDER["NEGATIVE"] = -1] = "NEGATIVE";
17
- ORDER[ORDER["ZERO"] = 0] = "ZERO";
18
- return ORDER;
19
- }({});
20
14
  const removeStringSymbol = (str) => {
21
15
  return str.replace(/-/gi, "").replace(/'/gi, "");
22
16
  };
23
17
  const compareNull = (a1, a2) => {
24
18
  const isA1Null = a1 === null || a1 === "";
25
19
  const isA2Null = a2 === null || a2 === "";
26
- if (isA1Null && isA2Null) return ORDER.ZERO;
27
- if (isA1Null) return ORDER.POSITIVE;
28
- if (isA2Null) return ORDER.NEGATIVE;
20
+ if (isA1Null && isA2Null) return 0;
21
+ if (isA1Null) return 1;
22
+ if (isA2Null) return -1;
29
23
  return null;
30
24
  };
31
25
  const compareNumber = (a1, a2, type) => {
32
26
  const isA1Num = typeof a1 === "number";
33
27
  const isA2Num = typeof a2 === "number";
34
28
  if (isA1Num && isA2Num) {
35
- if (a1 < a2) return type === SortType.ASC ? ORDER.NEGATIVE : ORDER.POSITIVE;
36
- if (a1 > a2) return type === SortType.ASC ? ORDER.POSITIVE : ORDER.NEGATIVE;
37
- return ORDER.ZERO;
29
+ if (a1 < a2) return type === "asc" ? -1 : 1;
30
+ if (a1 > a2) return type === "asc" ? 1 : -1;
31
+ return 0;
38
32
  }
39
- if (isA1Num) return type === SortType.ASC ? ORDER.POSITIVE : ORDER.NEGATIVE;
40
- if (isA2Num) return type === SortType.ASC ? ORDER.NEGATIVE : ORDER.POSITIVE;
33
+ if (isA1Num) return type === "asc" ? 1 : -1;
34
+ if (isA2Num) return type === "asc" ? -1 : 1;
41
35
  return null;
42
36
  };
43
37
  const compareString = (a1, a2, type) => {
@@ -49,12 +43,12 @@ const compareString = (a1, a2, type) => {
49
43
  if (isA1Str && isA2Str) {
50
44
  const a1AsString = a1;
51
45
  const a2AsString = a2;
52
- if (a1AsString < a2AsString) return type === SortType.ASC ? ORDER.NEGATIVE : ORDER.POSITIVE;
53
- if (a1AsString > a2AsString) return type === SortType.ASC ? ORDER.POSITIVE : ORDER.NEGATIVE;
54
- return ORDER.ZERO;
46
+ if (a1AsString < a2AsString) return type === "asc" ? -1 : 1;
47
+ if (a1AsString > a2AsString) return type === "asc" ? 1 : -1;
48
+ return 0;
55
49
  }
56
- if (isA1Str) return type === SortType.ASC ? ORDER.POSITIVE : ORDER.NEGATIVE;
57
- if (isA2Str) return type === SortType.ASC ? ORDER.NEGATIVE : ORDER.POSITIVE;
50
+ if (isA1Str) return type === "asc" ? 1 : -1;
51
+ if (isA2Str) return type === "asc" ? -1 : 1;
58
52
  return null;
59
53
  };
60
54
  const isNullValue = (cell) => {
@@ -65,7 +59,7 @@ const isNullValue = (cell) => {
65
59
  };
66
60
 
67
61
  //#endregion
68
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
62
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
69
63
  function _typeof(o) {
70
64
  "@babel/helpers - typeof";
71
65
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -76,7 +70,7 @@ function _typeof(o) {
76
70
  }
77
71
 
78
72
  //#endregion
79
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
73
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
80
74
  function toPrimitive(t, r) {
81
75
  if ("object" != _typeof(t) || !t) return t;
82
76
  var e = t[Symbol.toPrimitive];
@@ -89,14 +83,14 @@ function toPrimitive(t, r) {
89
83
  }
90
84
 
91
85
  //#endregion
92
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
86
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
93
87
  function toPropertyKey(t) {
94
88
  var i = toPrimitive(t, "string");
95
89
  return "symbol" == _typeof(i) ? i : i + "";
96
90
  }
97
91
 
98
92
  //#endregion
99
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
93
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
100
94
  function _defineProperty(e, r, t) {
101
95
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
102
96
  value: t,
@@ -107,7 +101,7 @@ function _defineProperty(e, r, t) {
107
101
  }
108
102
 
109
103
  //#endregion
110
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
104
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
111
105
  function __decorateParam(paramIndex, decorator) {
112
106
  return function(target, key) {
113
107
  decorator(target, key, paramIndex);
@@ -115,7 +109,7 @@ function __decorateParam(paramIndex, decorator) {
115
109
  }
116
110
 
117
111
  //#endregion
118
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
112
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
119
113
  function __decorate(decorators, target, key, desc) {
120
114
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
121
115
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -290,7 +284,7 @@ function reorderFnGenerator(orderRules, valueCompare) {
290
284
  //#endregion
291
285
  //#region package.json
292
286
  var name = "@univerjs/sheets-sort";
293
- var version = "0.21.1";
287
+ var version = "0.22.0";
294
288
 
295
289
  //#endregion
296
290
  //#region src/config/config.ts
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(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`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsSort={},e.UniverCore,e.UniverSheets,e.UniverEngineFormula))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let i=function(e){return e.DESC=`desc`,e.ASC=`asc`,e}({}),a=function(e){return e[e.POSITIVE=1]=`POSITIVE`,e[e.NEGATIVE=-1]=`NEGATIVE`,e[e.ZERO=0]=`ZERO`,e}({}),o=e=>e.replace(/-/gi,``).replace(/'/gi,``),s=(e,t)=>{let n=e===null||e===``,r=t===null||t===``;return n&&r?a.ZERO:n?a.POSITIVE:r?a.NEGATIVE:null},c=(e,t,n)=>{let r=typeof e==`number`,o=typeof t==`number`;return r&&o?e<t?n===i.ASC?a.NEGATIVE:a.POSITIVE:e>t?n===i.ASC?a.POSITIVE:a.NEGATIVE:a.ZERO:r?n===i.ASC?a.POSITIVE:a.NEGATIVE:o?n===i.ASC?a.NEGATIVE:a.POSITIVE:null},l=(e,t,n)=>{let r=typeof e==`string`,s=typeof t==`string`;if(r&&(e=o(e.toLocaleLowerCase())),s&&(t=o(t.toLocaleLowerCase())),!r&&!s)return null;if(r&&s){let r=e,o=t;return r<o?n===i.ASC?a.NEGATIVE:a.POSITIVE:r>o?n===i.ASC?a.POSITIVE:a.NEGATIVE:a.ZERO}return r?n===i.ASC?a.POSITIVE:a.NEGATIVE:s?n===i.ASC?a.NEGATIVE:a.POSITIVE:null},u=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;function d(e){"@babel/helpers - typeof";return d=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},d(e)}function f(e,t){if(d(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(d(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function p(e){var t=f(e,`string`);return d(t)==`symbol`?t:t+``}function m(e,t,n){return(t=p(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(e,t){return function(n,r){t(n,r,e)}}function g(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let _=class extends t.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._commandService=t,this._formulaDataModel=n,m(this,`_compareFns`,[])}mergeCheck(e){var n;let{unitId:r,subUnitId:i,range:a}=e,o=(n=this._univerInstanceService.getUnit(r))==null?void 0:n.getSheetBySheetId(i);if(!o)return!1;let s=o.getMergeData().filter(e=>t.Rectangle.contains(a,e));return s.length===0?!0:v(a,s)}emptyCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);if(!a)return!1;for(let e=i.startRow;e<=i.endRow;e++)for(let t=i.startColumn;t<=i.endColumn;t++)if(!u(a.getCellRaw(e,t)))return!0;return!1}singleCheck(e){return e.range.startRow!==e.range.endRow}formulaCheck(e){var n;let{unitId:r,subUnitId:i,range:a}=e,o=(n=this._formulaDataModel.getArrayFormulaRange())==null||(n=n[r])==null?void 0:n[i];for(let e in o){let n=o[Number(e)];for(let e in n){let r=n[Number(e)];if(r&&t.Rectangle.intersects(a,r))return!1}}return!0}registerCompareFn(e){this._compareFns.unshift(e)}getAllCompareFns(){return this._compareFns}applySort(e,t,r){var i;let{unitId:a,subUnitId:o}=(0,n.getSheetCommandTarget)(this._univerInstanceService)||{};this._commandService.executeCommand(y.id,{orderRules:e.orderRules,range:e.range,hasTitle:(i=e.hasTitle)==null?!1:i,unitId:t||a,subUnitId:r||o})}};_=g([h(0,t.IUniverInstanceService),h(1,t.ICommandService),h(2,(0,t.Inject)(r.FormulaDataModel))],_);function v(e,t){let n=e.endRow-e.startRow+1,r=e.endColumn-e.startColumn+1,i=null,a=null,o=n*r,s=0;for(let n of t)if(n.startRow>=e.startRow&&n.endRow<=e.endRow&&n.startColumn>=e.startColumn&&n.endColumn<=e.endColumn){let e=n.endRow-n.startRow+1,t=n.endColumn-n.startColumn+1;if(i===null&&a===null)i=e,a=t;else if(e!==i||t!==a)return!1;s+=e*t}return s===o}let y={id:`sheet.command.sort-range`,type:t.CommandType.COMMAND,handler:(e,r)=>{let{range:i,orderRules:a,hasTitle:o,unitId:s,subUnitId:c}=r,l=e.get(_),{worksheet:u}=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r)||{};if(!u)return!1;let d=u.getMergeData().filter(e=>t.Rectangle.contains(i,e)),f=d.map(e=>e.startRow),{startRow:p,endRow:m}=i,h=o?p+1:p,g=[],v=[];for(let e=h;e<=m;e++)u.getRowFiltered(e)||u.getRowRawVisible(e)!==!1&&(d.length&&!f.includes(e)||(g.push({index:e,value:b(u,e,a)}),v.push(e)));let y=l.getAllCompareFns();g.sort(S(a,x(y)));let C={};g.forEach(({index:e,value:t},n)=>{C[v[n]]=e});let w={id:n.ReorderRangeCommand.id,params:{unitId:s,subUnitId:c,range:i,order:C}},T=e.get(t.ICommandService);return(0,t.sequenceExecute)([w],T).result}};function b(e,t,n){let r=[];return n.forEach(({colIndex:n})=>{r.push(e.getCellRaw(t,n))}),r}function x(e){return(t,n,r)=>{for(let i=0;i<e.length;i++){let a=e[i](t,n,r);if(a!=null)return a}return 0}}function S(e,t){return function(n,r){let i=null;for(let a=0;a<e.length;a++){let o=n.value[a],s=r.value[a];if(i=t(e[a].type,o,s),i!==0&&i!=null)return i}return 0}}var C=`@univerjs/sheets-sort`,w=`0.21.1`;let T=`sheets-sort.config`;Symbol(T);let E={},D=class extends t.Disposable{constructor(e,t){super(),this._commandService=e,this._sortService=t,this._initCommands(),this._registerCompareFns()}_initCommands(){[y].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){this._sortService.registerCompareFn((e,t,n)=>{let r=this._getCommonValue(t),i=this._getCommonValue(n),a=[s,l,c];for(let t=0;t<a.length;t++){let n=a[t](r,i,e);if(n!==null)return n}return null})}_getCommonValue(e){var n;return u(e)?null:(e==null||(n=e.p)==null||(n=n.body)==null?void 0:n.dataStream)||((e==null?void 0:e.t)===t.CellValueType.NUMBER?Number.parseFloat(`${e.v}`):(e==null?void 0:e.t)===t.CellValueType.STRING?typeof e.v==`number`?e.v:`${e.v}`:(e==null?void 0:e.t)===t.CellValueType.BOOLEAN?`${e.v}`:(e==null?void 0:e.t)===t.CellValueType.FORCE_STRING?Number.parseFloat(`${e.v}`):`${e==null?void 0:e.v}`)}};D=g([h(0,t.ICommandService),h(1,(0,t.Inject)(_))],D);let O=class extends t.Plugin{constructor(e=E,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},E,this._config);this._configService.setConfig(T,i)}onStarting(){[[D],[_]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(D)}};m(O,`type`,t.UniverInstanceType.UNIVER_SHEET),m(O,`pluginName`,`SHEET_SORT_PLUGIN`),m(O,`packageName`,C),m(O,`version`,w),O=g([(0,t.DependentOn)(n.UniverSheetsPlugin,r.UniverFormulaEnginePlugin),h(1,(0,t.Inject)(t.Injector)),h(2,t.IConfigService)],O),Object.defineProperty(e,`SheetsSortService`,{enumerable:!0,get:function(){return _}}),e.SortRangeCommand=y,e.SortType=i,Object.defineProperty(e,`UniverSheetsSortPlugin`,{enumerable:!0,get:function(){return O}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(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`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsSort={},e.UniverCore,e.UniverSheets,e.UniverEngineFormula))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let i=function(e){return e.DESC=`desc`,e.ASC=`asc`,e}({}),a=e=>e.replace(/-/gi,``).replace(/'/gi,``),o=(e,t)=>{let n=e===null||e===``,r=t===null||t===``;return n&&r?0:n?1:r?-1:null},s=(e,t,n)=>{let r=typeof e==`number`,i=typeof t==`number`;return r&&i?e<t?n===`asc`?-1:1:e>t?n===`asc`?1:-1:0:r?n===`asc`?1:-1:i?n===`asc`?-1:1:null},c=(e,t,n)=>{let r=typeof e==`string`,i=typeof t==`string`;if(r&&(e=a(e.toLocaleLowerCase())),i&&(t=a(t.toLocaleLowerCase())),!r&&!i)return null;if(r&&i){let r=e,i=t;return r<i?n===`asc`?-1:1:r>i?n===`asc`?1:-1:0}return r?n===`asc`?1:-1:i?n===`asc`?-1:1:null},l=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;function u(e){"@babel/helpers - typeof";return u=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},u(e)}function d(e,t){if(u(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(u(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function f(e){var t=d(e,`string`);return u(t)==`symbol`?t:t+``}function p(e,t,n){return(t=f(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function m(e,t){return function(n,r){t(n,r,e)}}function h(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let g=class extends t.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._commandService=t,this._formulaDataModel=n,p(this,`_compareFns`,[])}mergeCheck(e){var n;let{unitId:r,subUnitId:i,range:a}=e,o=(n=this._univerInstanceService.getUnit(r))==null?void 0:n.getSheetBySheetId(i);if(!o)return!1;let s=o.getMergeData().filter(e=>t.Rectangle.contains(a,e));return s.length===0?!0:_(a,s)}emptyCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);if(!a)return!1;for(let e=i.startRow;e<=i.endRow;e++)for(let t=i.startColumn;t<=i.endColumn;t++)if(!l(a.getCellRaw(e,t)))return!0;return!1}singleCheck(e){return e.range.startRow!==e.range.endRow}formulaCheck(e){var n;let{unitId:r,subUnitId:i,range:a}=e,o=(n=this._formulaDataModel.getArrayFormulaRange())==null||(n=n[r])==null?void 0:n[i];for(let e in o){let n=o[Number(e)];for(let e in n){let r=n[Number(e)];if(r&&t.Rectangle.intersects(a,r))return!1}}return!0}registerCompareFn(e){this._compareFns.unshift(e)}getAllCompareFns(){return this._compareFns}applySort(e,t,r){var i;let{unitId:a,subUnitId:o}=(0,n.getSheetCommandTarget)(this._univerInstanceService)||{};this._commandService.executeCommand(v.id,{orderRules:e.orderRules,range:e.range,hasTitle:(i=e.hasTitle)==null?!1:i,unitId:t||a,subUnitId:r||o})}};g=h([m(0,t.IUniverInstanceService),m(1,t.ICommandService),m(2,(0,t.Inject)(r.FormulaDataModel))],g);function _(e,t){let n=e.endRow-e.startRow+1,r=e.endColumn-e.startColumn+1,i=null,a=null,o=n*r,s=0;for(let n of t)if(n.startRow>=e.startRow&&n.endRow<=e.endRow&&n.startColumn>=e.startColumn&&n.endColumn<=e.endColumn){let e=n.endRow-n.startRow+1,t=n.endColumn-n.startColumn+1;if(i===null&&a===null)i=e,a=t;else if(e!==i||t!==a)return!1;s+=e*t}return s===o}let v={id:`sheet.command.sort-range`,type:t.CommandType.COMMAND,handler:(e,r)=>{let{range:i,orderRules:a,hasTitle:o,unitId:s,subUnitId:c}=r,l=e.get(g),{worksheet:u}=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r)||{};if(!u)return!1;let d=u.getMergeData().filter(e=>t.Rectangle.contains(i,e)),f=d.map(e=>e.startRow),{startRow:p,endRow:m}=i,h=o?p+1:p,_=[],v=[];for(let e=h;e<=m;e++)u.getRowFiltered(e)||u.getRowRawVisible(e)!==!1&&(d.length&&!f.includes(e)||(_.push({index:e,value:y(u,e,a)}),v.push(e)));let S=l.getAllCompareFns();_.sort(x(a,b(S)));let C={};_.forEach(({index:e,value:t},n)=>{C[v[n]]=e});let w={id:n.ReorderRangeCommand.id,params:{unitId:s,subUnitId:c,range:i,order:C}},T=e.get(t.ICommandService);return(0,t.sequenceExecute)([w],T).result}};function y(e,t,n){let r=[];return n.forEach(({colIndex:n})=>{r.push(e.getCellRaw(t,n))}),r}function b(e){return(t,n,r)=>{for(let i=0;i<e.length;i++){let a=e[i](t,n,r);if(a!=null)return a}return 0}}function x(e,t){return function(n,r){let i=null;for(let a=0;a<e.length;a++){let o=n.value[a],s=r.value[a];if(i=t(e[a].type,o,s),i!==0&&i!=null)return i}return 0}}var S=`@univerjs/sheets-sort`,C=`0.22.0`;let w=`sheets-sort.config`;Symbol(w);let T={},E=class extends t.Disposable{constructor(e,t){super(),this._commandService=e,this._sortService=t,this._initCommands(),this._registerCompareFns()}_initCommands(){[v].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){this._sortService.registerCompareFn((e,t,n)=>{let r=this._getCommonValue(t),i=this._getCommonValue(n),a=[o,c,s];for(let t=0;t<a.length;t++){let n=a[t](r,i,e);if(n!==null)return n}return null})}_getCommonValue(e){var n;return l(e)?null:(e==null||(n=e.p)==null||(n=n.body)==null?void 0:n.dataStream)||((e==null?void 0:e.t)===t.CellValueType.NUMBER?Number.parseFloat(`${e.v}`):(e==null?void 0:e.t)===t.CellValueType.STRING?typeof e.v==`number`?e.v:`${e.v}`:(e==null?void 0:e.t)===t.CellValueType.BOOLEAN?`${e.v}`:(e==null?void 0:e.t)===t.CellValueType.FORCE_STRING?Number.parseFloat(`${e.v}`):`${e==null?void 0:e.v}`)}};E=h([m(0,t.ICommandService),m(1,(0,t.Inject)(g))],E);let D=class extends t.Plugin{constructor(e=T,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},T,this._config);this._configService.setConfig(w,i)}onStarting(){[[E],[g]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(E)}};p(D,`type`,t.UniverInstanceType.UNIVER_SHEET),p(D,`pluginName`,`SHEET_SORT_PLUGIN`),p(D,`packageName`,S),p(D,`version`,C),D=h([(0,t.DependentOn)(n.UniverSheetsPlugin,r.UniverFormulaEnginePlugin),m(1,(0,t.Inject)(t.Injector)),m(2,t.IConfigService)],D),Object.defineProperty(e,`SheetsSortService`,{enumerable:!0,get:function(){return g}}),e.SortRangeCommand=v,e.SortType=i,Object.defineProperty(e,`UniverSheetsSortPlugin`,{enumerable:!0,get:function(){return D}})});
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-sort",
3
- "version": "0.21.1",
3
+ "version": "0.22.0",
4
4
  "private": false,
5
- "description": "A library for sorting data in Univer Sheet",
6
- "author": "DreamNum <developer@univer.ai>",
5
+ "description": "Sorting model, commands, and services for Univer Sheets.",
6
+ "author": "DreamNum Co., Ltd. <developer@univer.ai>",
7
7
  "license": "Apache-2.0",
8
8
  "funding": {
9
9
  "type": "opencollective",
@@ -17,7 +17,13 @@
17
17
  "bugs": {
18
18
  "url": "https://github.com/dream-num/univer/issues"
19
19
  },
20
- "keywords": [],
20
+ "keywords": [
21
+ "univer",
22
+ "sheets",
23
+ "sort",
24
+ "spreadsheet",
25
+ "plugin"
26
+ ],
21
27
  "exports": {
22
28
  ".": {
23
29
  "import": "./lib/es/index.js",
@@ -58,14 +64,14 @@
58
64
  "lib"
59
65
  ],
60
66
  "dependencies": {
61
- "@univerjs/engine-formula": "0.21.1",
62
- "@univerjs/sheets": "0.21.1",
63
- "@univerjs/core": "0.21.1"
67
+ "@univerjs/core": "0.22.0",
68
+ "@univerjs/engine-formula": "0.22.0",
69
+ "@univerjs/sheets": "0.22.0"
64
70
  },
65
71
  "devDependencies": {
66
- "typescript": "^6.0.2",
67
- "vitest": "^4.1.4",
68
- "@univerjs-infra/shared": "0.21.1"
72
+ "typescript": "^6.0.3",
73
+ "vitest": "^4.1.5",
74
+ "@univerjs-infra/shared": "0.22.0"
69
75
  },
70
76
  "scripts": {
71
77
  "test": "vitest run",