@univerjs/sheets-sort 0.20.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +125 -1
- package/lib/cjs/index.js +406 -1
- package/lib/cjs/locale/ca-ES.js +18 -1
- package/lib/cjs/locale/en-US.js +33 -1
- package/lib/cjs/locale/es-ES.js +18 -1
- package/lib/cjs/locale/fa-IR.js +18 -1
- package/lib/cjs/locale/fr-FR.js +18 -1
- package/lib/cjs/locale/ja-JP.js +18 -1
- package/lib/cjs/locale/ko-KR.js +18 -1
- package/lib/cjs/locale/ru-RU.js +18 -1
- package/lib/cjs/locale/sk-SK.js +18 -1
- package/lib/cjs/locale/vi-VN.js +18 -1
- package/lib/cjs/locale/zh-CN.js +18 -1
- package/lib/cjs/locale/zh-TW.js +18 -1
- package/lib/es/facade.js +126 -1
- package/lib/es/index.js +392 -1
- package/lib/es/locale/ca-ES.js +17 -1
- package/lib/es/locale/en-US.js +32 -1
- package/lib/es/locale/es-ES.js +17 -1
- package/lib/es/locale/fa-IR.js +17 -1
- package/lib/es/locale/fr-FR.js +17 -1
- package/lib/es/locale/ja-JP.js +17 -1
- package/lib/es/locale/ko-KR.js +17 -1
- package/lib/es/locale/ru-RU.js +17 -1
- package/lib/es/locale/sk-SK.js +17 -1
- package/lib/es/locale/vi-VN.js +17 -1
- package/lib/es/locale/zh-CN.js +17 -1
- package/lib/es/locale/zh-TW.js +17 -1
- package/lib/facade.js +126 -1
- package/lib/index.js +392 -1
- package/lib/locale/ca-ES.js +17 -1
- package/lib/locale/en-US.js +32 -1
- package/lib/locale/es-ES.js +17 -1
- package/lib/locale/fa-IR.js +17 -1
- package/lib/locale/fr-FR.js +17 -1
- package/lib/locale/ja-JP.js +17 -1
- package/lib/locale/ko-KR.js +17 -1
- package/lib/locale/ru-RU.js +17 -1
- package/lib/locale/sk-SK.js +17 -1
- package/lib/locale/vi-VN.js +17 -1
- package/lib/locale/zh-CN.js +17 -1
- package/lib/locale/zh-TW.js +17 -1
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
package/lib/cjs/locale/ja-JP.js
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/locale/ja-JP.ts
|
|
3
|
+
const locale = { sheetsSort: {
|
|
4
|
+
title: "並べ替え",
|
|
5
|
+
toolbar: {
|
|
6
|
+
"sort-asc": "昇順",
|
|
7
|
+
"sort-desc": "降順",
|
|
8
|
+
"sort-custom": "カスタム順序"
|
|
9
|
+
},
|
|
10
|
+
"context-menu": {
|
|
11
|
+
"sort-asc": "昇順",
|
|
12
|
+
"sort-desc": "降順",
|
|
13
|
+
"sort-custom": "カスタム順序"
|
|
14
|
+
}
|
|
15
|
+
} };
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
module.exports = locale;
|
package/lib/cjs/locale/ko-KR.js
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/locale/ko-KR.ts
|
|
3
|
+
const locale = { sheetsSort: {
|
|
4
|
+
title: "정렬",
|
|
5
|
+
toolbar: {
|
|
6
|
+
"sort-asc": "오름차순",
|
|
7
|
+
"sort-desc": "내림차순",
|
|
8
|
+
"sort-custom": "사용자 정의 순서"
|
|
9
|
+
},
|
|
10
|
+
"context-menu": {
|
|
11
|
+
"sort-asc": "오름차순",
|
|
12
|
+
"sort-desc": "내림차순",
|
|
13
|
+
"sort-custom": "사용자 정의 순서"
|
|
14
|
+
}
|
|
15
|
+
} };
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
module.exports = locale;
|
package/lib/cjs/locale/ru-RU.js
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/locale/ru-RU.ts
|
|
3
|
+
const locale = { sheetsSort: {
|
|
4
|
+
title: "Sort",
|
|
5
|
+
toolbar: {
|
|
6
|
+
"sort-asc": "по возрастанию",
|
|
7
|
+
"sort-desc": "по убыванию",
|
|
8
|
+
"sort-custom": "пользовательский выбор"
|
|
9
|
+
},
|
|
10
|
+
"context-menu": {
|
|
11
|
+
"sort-asc": "по возрастанию",
|
|
12
|
+
"sort-desc": "по убыванию",
|
|
13
|
+
"sort-custom": "пользовательский выбор"
|
|
14
|
+
}
|
|
15
|
+
} };
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
module.exports = locale;
|
package/lib/cjs/locale/sk-SK.js
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/locale/sk-SK.ts
|
|
3
|
+
const locale = { sheetsSort: {
|
|
4
|
+
title: "Triedenie",
|
|
5
|
+
toolbar: {
|
|
6
|
+
"sort-asc": "vzostupné poradie",
|
|
7
|
+
"sort-desc": "zostupné poradie",
|
|
8
|
+
"sort-custom": "vlastné poradie"
|
|
9
|
+
},
|
|
10
|
+
"context-menu": {
|
|
11
|
+
"sort-asc": "vzostupné poradie",
|
|
12
|
+
"sort-desc": "zostupné poradie",
|
|
13
|
+
"sort-custom": "vlastné poradie"
|
|
14
|
+
}
|
|
15
|
+
} };
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
module.exports = locale;
|
package/lib/cjs/locale/vi-VN.js
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/locale/vi-VN.ts
|
|
3
|
+
const locale = { sheetsSort: {
|
|
4
|
+
title: "Sort",
|
|
5
|
+
toolbar: {
|
|
6
|
+
"sort-asc": "ascending order",
|
|
7
|
+
"sort-desc": "descending order",
|
|
8
|
+
"sort-custom": "custom order"
|
|
9
|
+
},
|
|
10
|
+
"context-menu": {
|
|
11
|
+
"sort-asc": "ascending order",
|
|
12
|
+
"sort-desc": "descending order",
|
|
13
|
+
"sort-custom": "custom order"
|
|
14
|
+
}
|
|
15
|
+
} };
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
module.exports = locale;
|
package/lib/cjs/locale/zh-CN.js
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/locale/zh-CN.ts
|
|
3
|
+
const locale = { sheetsSort: {
|
|
4
|
+
title: "排序",
|
|
5
|
+
toolbar: {
|
|
6
|
+
"sort-asc": "升序",
|
|
7
|
+
"sort-desc": "降序",
|
|
8
|
+
"sort-custom": "自定义排序"
|
|
9
|
+
},
|
|
10
|
+
"context-menu": {
|
|
11
|
+
"sort-asc": "升序",
|
|
12
|
+
"sort-desc": "降序",
|
|
13
|
+
"sort-custom": "自定义排序"
|
|
14
|
+
}
|
|
15
|
+
} };
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
module.exports = locale;
|
package/lib/cjs/locale/zh-TW.js
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/locale/zh-TW.ts
|
|
3
|
+
const locale = { sheetsSort: {
|
|
4
|
+
title: "Sắp xếp",
|
|
5
|
+
toolbar: {
|
|
6
|
+
"sort-asc": "Tăng dần",
|
|
7
|
+
"sort-desc": "Giảm dần",
|
|
8
|
+
"sort-custom": "Sắp xếp tùy chỉnh"
|
|
9
|
+
},
|
|
10
|
+
"context-menu": {
|
|
11
|
+
"sort-asc": "Tăng dần",
|
|
12
|
+
"sort-desc": "Giảm dần",
|
|
13
|
+
"sort-custom": "Sắp xếp tùy chỉnh"
|
|
14
|
+
}
|
|
15
|
+
} };
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
module.exports = locale;
|
package/lib/es/facade.js
CHANGED
|
@@ -1 +1,126 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ICommandService, RANGE_TYPE } from "@univerjs/core";
|
|
2
|
+
import { FEventName, FUniver } from "@univerjs/core/facade";
|
|
3
|
+
import { SortRangeCommand, SortType } from "@univerjs/sheets-sort";
|
|
4
|
+
import { FRange, FWorksheet } from "@univerjs/sheets/facade";
|
|
5
|
+
|
|
6
|
+
//#region src/facade/f-univer.ts
|
|
7
|
+
var FUniverSheetsSortMixin = class extends FUniver {
|
|
8
|
+
/**
|
|
9
|
+
* @ignore
|
|
10
|
+
*/
|
|
11
|
+
_initialize(injector) {
|
|
12
|
+
const commandService = injector.get(ICommandService);
|
|
13
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.SheetBeforeRangeSort, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
14
|
+
if (commandInfo.id !== SortRangeCommand.id) return;
|
|
15
|
+
this._beforeRangeSort(commandInfo);
|
|
16
|
+
})));
|
|
17
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.SheetRangeSorted, () => commandService.onCommandExecuted((commandInfo) => {
|
|
18
|
+
if (commandInfo.id !== SortRangeCommand.id) return;
|
|
19
|
+
this._onRangeSorted(commandInfo);
|
|
20
|
+
})));
|
|
21
|
+
}
|
|
22
|
+
_beforeRangeSort(commandInfo) {
|
|
23
|
+
const params = commandInfo.params;
|
|
24
|
+
const fWorkbook = this.getUniverSheet(params.unitId);
|
|
25
|
+
const fWorksheet = fWorkbook.getSheetBySheetId(params.subUnitId);
|
|
26
|
+
const { startColumn, endColumn, startRow, endRow } = params.range;
|
|
27
|
+
const eventParams = {
|
|
28
|
+
workbook: fWorkbook,
|
|
29
|
+
worksheet: fWorksheet,
|
|
30
|
+
range: fWorksheet.getRange(startRow, startColumn, endRow - startRow + 1, endColumn - startColumn + 1),
|
|
31
|
+
sortColumn: params.orderRules.map((rule) => ({
|
|
32
|
+
column: rule.colIndex - startColumn,
|
|
33
|
+
ascending: rule.type === SortType.ASC
|
|
34
|
+
}))
|
|
35
|
+
};
|
|
36
|
+
this.fireEvent(this.Event.SheetBeforeRangeSort, eventParams);
|
|
37
|
+
if (eventParams.cancel) throw new Error("SortRangeCommand canceled.");
|
|
38
|
+
}
|
|
39
|
+
_onRangeSorted(commandInfo) {
|
|
40
|
+
const params = commandInfo.params;
|
|
41
|
+
const fWorkbook = this.getUniverSheet(params.unitId);
|
|
42
|
+
const fWorksheet = fWorkbook.getSheetBySheetId(params.subUnitId);
|
|
43
|
+
const { startColumn, endColumn, startRow, endRow } = params.range;
|
|
44
|
+
const eventParams = {
|
|
45
|
+
workbook: fWorkbook,
|
|
46
|
+
worksheet: fWorksheet,
|
|
47
|
+
range: fWorksheet.getRange(startRow, startColumn, endRow - startRow + 1, endColumn - startColumn + 1),
|
|
48
|
+
sortColumn: params.orderRules.map((rule) => ({
|
|
49
|
+
column: rule.colIndex - startColumn,
|
|
50
|
+
ascending: rule.type === SortType.ASC
|
|
51
|
+
}))
|
|
52
|
+
};
|
|
53
|
+
this.fireEvent(this.Event.SheetRangeSorted, eventParams);
|
|
54
|
+
if (eventParams.cancel) throw new Error("SortRangeCommand canceled.");
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
FUniver.extend(FUniverSheetsSortMixin);
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/facade/f-range.ts
|
|
61
|
+
var FRangeSheetsSortMixin = class extends FRange {
|
|
62
|
+
sort(column) {
|
|
63
|
+
const columnBase = this._range.startColumn;
|
|
64
|
+
const orderRules = (Array.isArray(column) ? column : [column]).map((c) => {
|
|
65
|
+
if (typeof c === "number") return {
|
|
66
|
+
colIndex: c + columnBase,
|
|
67
|
+
type: SortType.ASC
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
colIndex: c.column + columnBase,
|
|
71
|
+
type: c.ascending ? SortType.ASC : SortType.DESC
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
this._commandService.syncExecuteCommand(SortRangeCommand.id, {
|
|
75
|
+
orderRules,
|
|
76
|
+
range: this._range,
|
|
77
|
+
hasTitle: false,
|
|
78
|
+
unitId: this._workbook.getUnitId(),
|
|
79
|
+
subUnitId: this._worksheet.getSheetId()
|
|
80
|
+
});
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
FRange.extend(FRangeSheetsSortMixin);
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/facade/f-worksheet.ts
|
|
88
|
+
var FWorksheetSortMixin = class extends FWorksheet {
|
|
89
|
+
sort(colIndex, asc = true) {
|
|
90
|
+
const orderRules = [{
|
|
91
|
+
colIndex,
|
|
92
|
+
type: asc ? SortType.ASC : SortType.DESC
|
|
93
|
+
}];
|
|
94
|
+
const range = {
|
|
95
|
+
startRow: 0,
|
|
96
|
+
startColumn: 0,
|
|
97
|
+
endRow: this._worksheet.getRowCount() - 1,
|
|
98
|
+
endColumn: this._worksheet.getColumnCount() - 1,
|
|
99
|
+
rangeType: RANGE_TYPE.ALL
|
|
100
|
+
};
|
|
101
|
+
this._commandService.syncExecuteCommand(SortRangeCommand.id, {
|
|
102
|
+
orderRules,
|
|
103
|
+
range,
|
|
104
|
+
hasTitle: false,
|
|
105
|
+
unitId: this._workbook.getUnitId(),
|
|
106
|
+
subUnitId: this._worksheet.getSheetId()
|
|
107
|
+
});
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
FWorksheet.extend(FWorksheetSortMixin);
|
|
112
|
+
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/facade/f-event.ts
|
|
115
|
+
var FSheetsSortEventNameMixin = class {
|
|
116
|
+
get SheetRangeSorted() {
|
|
117
|
+
return "SheetRangeSorted";
|
|
118
|
+
}
|
|
119
|
+
get SheetBeforeRangeSort() {
|
|
120
|
+
return "SheetBeforeRangeSort";
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
FEventName.extend(FSheetsSortEventNameMixin);
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
export { };
|
package/lib/es/index.js
CHANGED
|
@@ -1 +1,392 @@
|
|
|
1
|
-
import{CellValueType
|
|
1
|
+
import { CellValueType, CommandType, DependentOn, Disposable, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, Plugin, Rectangle, UniverInstanceType, merge, sequenceExecute } from "@univerjs/core";
|
|
2
|
+
import { ReorderRangeCommand, UniverSheetsPlugin, getSheetCommandTarget } from "@univerjs/sheets";
|
|
3
|
+
import { FormulaDataModel, UniverFormulaEnginePlugin } from "@univerjs/engine-formula";
|
|
4
|
+
|
|
5
|
+
//#region src/services/interface.ts
|
|
6
|
+
let SortType = /* @__PURE__ */ function(SortType) {
|
|
7
|
+
SortType["DESC"] = "desc";
|
|
8
|
+
SortType["ASC"] = "asc";
|
|
9
|
+
return SortType;
|
|
10
|
+
}({});
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
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
|
+
const removeStringSymbol = (str) => {
|
|
21
|
+
return str.replace(/-/gi, "").replace(/'/gi, "");
|
|
22
|
+
};
|
|
23
|
+
const compareNull = (a1, a2) => {
|
|
24
|
+
const isA1Null = a1 === null || a1 === "";
|
|
25
|
+
const isA2Null = a2 === null || a2 === "";
|
|
26
|
+
if (isA1Null && isA2Null) return ORDER.ZERO;
|
|
27
|
+
if (isA1Null) return ORDER.POSITIVE;
|
|
28
|
+
if (isA2Null) return ORDER.NEGATIVE;
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
const compareNumber = (a1, a2, type) => {
|
|
32
|
+
const isA1Num = typeof a1 === "number";
|
|
33
|
+
const isA2Num = typeof a2 === "number";
|
|
34
|
+
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;
|
|
38
|
+
}
|
|
39
|
+
if (isA1Num) return type === SortType.ASC ? ORDER.POSITIVE : ORDER.NEGATIVE;
|
|
40
|
+
if (isA2Num) return type === SortType.ASC ? ORDER.NEGATIVE : ORDER.POSITIVE;
|
|
41
|
+
return null;
|
|
42
|
+
};
|
|
43
|
+
const compareString = (a1, a2, type) => {
|
|
44
|
+
const isA1Str = typeof a1 === "string";
|
|
45
|
+
const isA2Str = typeof a2 === "string";
|
|
46
|
+
if (isA1Str) a1 = removeStringSymbol(a1.toLocaleLowerCase());
|
|
47
|
+
if (isA2Str) a2 = removeStringSymbol(a2.toLocaleLowerCase());
|
|
48
|
+
if (!isA1Str && !isA2Str) return null;
|
|
49
|
+
if (isA1Str && isA2Str) {
|
|
50
|
+
const a1AsString = a1;
|
|
51
|
+
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;
|
|
55
|
+
}
|
|
56
|
+
if (isA1Str) return type === SortType.ASC ? ORDER.POSITIVE : ORDER.NEGATIVE;
|
|
57
|
+
if (isA2Str) return type === SortType.ASC ? ORDER.NEGATIVE : ORDER.POSITIVE;
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
const isNullValue = (cell) => {
|
|
61
|
+
if (!cell) return true;
|
|
62
|
+
if (Object.keys(cell).length === 0) return true;
|
|
63
|
+
if ((cell === null || cell === void 0 ? void 0 : cell.v) == null && (cell === null || cell === void 0 ? void 0 : cell.p) == null) return true;
|
|
64
|
+
return false;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
69
|
+
function _typeof(o) {
|
|
70
|
+
"@babel/helpers - typeof";
|
|
71
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
72
|
+
return typeof o;
|
|
73
|
+
} : function(o) {
|
|
74
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
75
|
+
}, _typeof(o);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
80
|
+
function toPrimitive(t, r) {
|
|
81
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
82
|
+
var e = t[Symbol.toPrimitive];
|
|
83
|
+
if (void 0 !== e) {
|
|
84
|
+
var i = e.call(t, r || "default");
|
|
85
|
+
if ("object" != _typeof(i)) return i;
|
|
86
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
87
|
+
}
|
|
88
|
+
return ("string" === r ? String : Number)(t);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
93
|
+
function toPropertyKey(t) {
|
|
94
|
+
var i = toPrimitive(t, "string");
|
|
95
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
100
|
+
function _defineProperty(e, r, t) {
|
|
101
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
102
|
+
value: t,
|
|
103
|
+
enumerable: !0,
|
|
104
|
+
configurable: !0,
|
|
105
|
+
writable: !0
|
|
106
|
+
}) : e[r] = t, e;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
111
|
+
function __decorateParam(paramIndex, decorator) {
|
|
112
|
+
return function(target, key) {
|
|
113
|
+
decorator(target, key, paramIndex);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
119
|
+
function __decorate(decorators, target, key, desc) {
|
|
120
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
121
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
122
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
123
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/services/sheets-sort.service.ts
|
|
128
|
+
let SheetsSortService = class SheetsSortService extends Disposable {
|
|
129
|
+
constructor(_univerInstanceService, _commandService, _formulaDataModel) {
|
|
130
|
+
super();
|
|
131
|
+
this._univerInstanceService = _univerInstanceService;
|
|
132
|
+
this._commandService = _commandService;
|
|
133
|
+
this._formulaDataModel = _formulaDataModel;
|
|
134
|
+
_defineProperty(this, "_compareFns", []);
|
|
135
|
+
}
|
|
136
|
+
mergeCheck(location) {
|
|
137
|
+
var _this$_univerInstance;
|
|
138
|
+
const { unitId, subUnitId, range } = location;
|
|
139
|
+
const sheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
|
|
140
|
+
if (!sheet) return false;
|
|
141
|
+
const mergeDataInRange = sheet.getMergeData().filter((merge) => Rectangle.contains(range, merge));
|
|
142
|
+
if (mergeDataInRange.length === 0) return true;
|
|
143
|
+
return isRangeDividedEqually(range, mergeDataInRange);
|
|
144
|
+
}
|
|
145
|
+
emptyCheck(location) {
|
|
146
|
+
var _this$_univerInstance2;
|
|
147
|
+
const { unitId, subUnitId, range } = location;
|
|
148
|
+
const sheet = (_this$_univerInstance2 = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance2 === void 0 ? void 0 : _this$_univerInstance2.getSheetBySheetId(subUnitId);
|
|
149
|
+
if (!sheet) return false;
|
|
150
|
+
for (let row = range.startRow; row <= range.endRow; row++) for (let col = range.startColumn; col <= range.endColumn; col++) if (!isNullValue(sheet.getCellRaw(row, col))) return true;
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
singleCheck(location) {
|
|
154
|
+
if (location.range.startRow === location.range.endRow) return false;
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
formulaCheck(location) {
|
|
158
|
+
var _this$_formulaDataMod;
|
|
159
|
+
const { unitId, subUnitId, range } = location;
|
|
160
|
+
const arrayFormulaRange = (_this$_formulaDataMod = this._formulaDataModel.getArrayFormulaRange()) === null || _this$_formulaDataMod === void 0 || (_this$_formulaDataMod = _this$_formulaDataMod[unitId]) === null || _this$_formulaDataMod === void 0 ? void 0 : _this$_formulaDataMod[subUnitId];
|
|
161
|
+
for (const row in arrayFormulaRange) {
|
|
162
|
+
const rowData = arrayFormulaRange[Number(row)];
|
|
163
|
+
for (const col in rowData) {
|
|
164
|
+
const arrayFormula = rowData[Number(col)];
|
|
165
|
+
if (arrayFormula && Rectangle.intersects(range, arrayFormula)) return false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
registerCompareFn(fn) {
|
|
171
|
+
this._compareFns.unshift(fn);
|
|
172
|
+
}
|
|
173
|
+
getAllCompareFns() {
|
|
174
|
+
return this._compareFns;
|
|
175
|
+
}
|
|
176
|
+
applySort(sortOption, unitId, subUnitId) {
|
|
177
|
+
var _sortOption$hasTitle;
|
|
178
|
+
const { unitId: _unitId, subUnitId: _subUnitId } = getSheetCommandTarget(this._univerInstanceService) || {};
|
|
179
|
+
this._commandService.executeCommand(SortRangeCommand.id, {
|
|
180
|
+
orderRules: sortOption.orderRules,
|
|
181
|
+
range: sortOption.range,
|
|
182
|
+
hasTitle: (_sortOption$hasTitle = sortOption.hasTitle) !== null && _sortOption$hasTitle !== void 0 ? _sortOption$hasTitle : false,
|
|
183
|
+
unitId: unitId || _unitId,
|
|
184
|
+
subUnitId: subUnitId || _subUnitId
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
SheetsSortService = __decorate([
|
|
189
|
+
__decorateParam(0, IUniverInstanceService),
|
|
190
|
+
__decorateParam(1, ICommandService),
|
|
191
|
+
__decorateParam(2, Inject(FormulaDataModel))
|
|
192
|
+
], SheetsSortService);
|
|
193
|
+
function isRangeDividedEqually(range, merges) {
|
|
194
|
+
const rangeRows = range.endRow - range.startRow + 1;
|
|
195
|
+
const rangeCols = range.endColumn - range.startColumn + 1;
|
|
196
|
+
let mergeRows = null;
|
|
197
|
+
let mergeCols = null;
|
|
198
|
+
const totalArea = rangeRows * rangeCols;
|
|
199
|
+
let totalMergeArea = 0;
|
|
200
|
+
for (const merge of merges) if (merge.startRow >= range.startRow && merge.endRow <= range.endRow && merge.startColumn >= range.startColumn && merge.endColumn <= range.endColumn) {
|
|
201
|
+
const currentMergeRows = merge.endRow - merge.startRow + 1;
|
|
202
|
+
const currentMergeCols = merge.endColumn - merge.startColumn + 1;
|
|
203
|
+
if (mergeRows === null && mergeCols === null) {
|
|
204
|
+
mergeRows = currentMergeRows;
|
|
205
|
+
mergeCols = currentMergeCols;
|
|
206
|
+
} else if (currentMergeRows !== mergeRows || currentMergeCols !== mergeCols) return false;
|
|
207
|
+
totalMergeArea += currentMergeRows * currentMergeCols;
|
|
208
|
+
}
|
|
209
|
+
return totalMergeArea === totalArea;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/commands/commands/sheets-sort.command.ts
|
|
214
|
+
const SortRangeCommand = {
|
|
215
|
+
id: "sheet.command.sort-range",
|
|
216
|
+
type: CommandType.COMMAND,
|
|
217
|
+
handler: (accessor, params) => {
|
|
218
|
+
const { range, orderRules, hasTitle, unitId, subUnitId } = params;
|
|
219
|
+
const sortService = accessor.get(SheetsSortService);
|
|
220
|
+
const { worksheet } = getSheetCommandTarget(accessor.get(IUniverInstanceService), params) || {};
|
|
221
|
+
if (!worksheet) return false;
|
|
222
|
+
const mergeDataInRange = worksheet.getMergeData().filter((mergeData) => {
|
|
223
|
+
return Rectangle.contains(range, mergeData);
|
|
224
|
+
});
|
|
225
|
+
const mergeMainRowIndexes = mergeDataInRange.map((mergeData) => {
|
|
226
|
+
return mergeData.startRow;
|
|
227
|
+
});
|
|
228
|
+
const { startRow: rangeStartRow, endRow } = range;
|
|
229
|
+
const startRow = hasTitle ? rangeStartRow + 1 : rangeStartRow;
|
|
230
|
+
const toReorder = [];
|
|
231
|
+
const oldOrder = [];
|
|
232
|
+
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
|
|
233
|
+
if (worksheet.getRowFiltered(rowIndex)) continue;
|
|
234
|
+
if (worksheet.getRowRawVisible(rowIndex) === false) continue;
|
|
235
|
+
if (mergeDataInRange.length && !mergeMainRowIndexes.includes(rowIndex)) continue;
|
|
236
|
+
toReorder.push({
|
|
237
|
+
index: rowIndex,
|
|
238
|
+
value: getRowCellData(worksheet, rowIndex, orderRules)
|
|
239
|
+
});
|
|
240
|
+
oldOrder.push(rowIndex);
|
|
241
|
+
}
|
|
242
|
+
const compareFns = sortService.getAllCompareFns();
|
|
243
|
+
toReorder.sort(reorderFnGenerator(orderRules, combineCompareFnsAsOne(compareFns)));
|
|
244
|
+
const order = {};
|
|
245
|
+
toReorder.forEach(({ index, value }, oldIndex) => {
|
|
246
|
+
order[oldOrder[oldIndex]] = index;
|
|
247
|
+
});
|
|
248
|
+
const reorderRangeCommand = {
|
|
249
|
+
id: ReorderRangeCommand.id,
|
|
250
|
+
params: {
|
|
251
|
+
unitId,
|
|
252
|
+
subUnitId,
|
|
253
|
+
range,
|
|
254
|
+
order
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
const commandService = accessor.get(ICommandService);
|
|
258
|
+
return sequenceExecute([reorderRangeCommand], commandService).result;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
function getRowCellData(worksheet, rowIndex, orderRules) {
|
|
262
|
+
const result = [];
|
|
263
|
+
orderRules.forEach(({ colIndex }) => {
|
|
264
|
+
result.push(worksheet.getCellRaw(rowIndex, colIndex));
|
|
265
|
+
});
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
function combineCompareFnsAsOne(compareFns) {
|
|
269
|
+
return (type, a, b) => {
|
|
270
|
+
for (let i = 0; i < compareFns.length; i++) {
|
|
271
|
+
const res = compareFns[i](type, a, b);
|
|
272
|
+
if (res != null) return res;
|
|
273
|
+
}
|
|
274
|
+
return 0;
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function reorderFnGenerator(orderRules, valueCompare) {
|
|
278
|
+
return function(a, b) {
|
|
279
|
+
let ret = null;
|
|
280
|
+
for (let index = 0; index < orderRules.length; index++) {
|
|
281
|
+
const aCellData = a.value[index];
|
|
282
|
+
const bCellData = b.value[index];
|
|
283
|
+
ret = valueCompare(orderRules[index].type, aCellData, bCellData);
|
|
284
|
+
if (ret !== 0 && ret !== null && ret !== void 0) return ret;
|
|
285
|
+
}
|
|
286
|
+
return 0;
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
//#endregion
|
|
291
|
+
//#region package.json
|
|
292
|
+
var name = "@univerjs/sheets-sort";
|
|
293
|
+
var version = "0.21.0";
|
|
294
|
+
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/config/config.ts
|
|
297
|
+
/**
|
|
298
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
299
|
+
*
|
|
300
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
301
|
+
* you may not use this file except in compliance with the License.
|
|
302
|
+
* You may obtain a copy of the License at
|
|
303
|
+
*
|
|
304
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
305
|
+
*
|
|
306
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
307
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
308
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
309
|
+
* See the License for the specific language governing permissions and
|
|
310
|
+
* limitations under the License.
|
|
311
|
+
*/
|
|
312
|
+
const SHEETS_SORT_PLUGIN_CONFIG_KEY = "sheets-sort.config";
|
|
313
|
+
const configSymbol = Symbol(SHEETS_SORT_PLUGIN_CONFIG_KEY);
|
|
314
|
+
const defaultPluginConfig = {};
|
|
315
|
+
|
|
316
|
+
//#endregion
|
|
317
|
+
//#region src/controllers/sheets-sort.controller.ts
|
|
318
|
+
let SheetsSortController = class SheetsSortController extends Disposable {
|
|
319
|
+
constructor(_commandService, _sortService) {
|
|
320
|
+
super();
|
|
321
|
+
this._commandService = _commandService;
|
|
322
|
+
this._sortService = _sortService;
|
|
323
|
+
this._initCommands();
|
|
324
|
+
this._registerCompareFns();
|
|
325
|
+
}
|
|
326
|
+
_initCommands() {
|
|
327
|
+
[SortRangeCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
|
|
328
|
+
}
|
|
329
|
+
_registerCompareFns() {
|
|
330
|
+
const commonFn = (type, a, b) => {
|
|
331
|
+
const valueA = this._getCommonValue(a);
|
|
332
|
+
const valueB = this._getCommonValue(b);
|
|
333
|
+
const compareTypeFns = [
|
|
334
|
+
compareNull,
|
|
335
|
+
compareString,
|
|
336
|
+
compareNumber
|
|
337
|
+
];
|
|
338
|
+
for (let i = 0; i < compareTypeFns.length; i++) {
|
|
339
|
+
const res = compareTypeFns[i](valueA, valueB, type);
|
|
340
|
+
if (res !== null) return res;
|
|
341
|
+
}
|
|
342
|
+
return null;
|
|
343
|
+
};
|
|
344
|
+
this._sortService.registerCompareFn(commonFn);
|
|
345
|
+
}
|
|
346
|
+
_getCommonValue(a) {
|
|
347
|
+
var _a$p;
|
|
348
|
+
if (isNullValue(a)) return null;
|
|
349
|
+
const richTextValue = a === null || a === void 0 || (_a$p = a.p) === null || _a$p === void 0 || (_a$p = _a$p.body) === null || _a$p === void 0 ? void 0 : _a$p.dataStream;
|
|
350
|
+
if (richTextValue) return richTextValue;
|
|
351
|
+
if ((a === null || a === void 0 ? void 0 : a.t) === CellValueType.NUMBER) return Number.parseFloat(`${a.v}`);
|
|
352
|
+
if ((a === null || a === void 0 ? void 0 : a.t) === CellValueType.STRING) {
|
|
353
|
+
if (typeof a.v === "number") return a.v;
|
|
354
|
+
return `${a.v}`;
|
|
355
|
+
}
|
|
356
|
+
if ((a === null || a === void 0 ? void 0 : a.t) === CellValueType.BOOLEAN) return `${a.v}`;
|
|
357
|
+
if ((a === null || a === void 0 ? void 0 : a.t) === CellValueType.FORCE_STRING) return Number.parseFloat(`${a.v}`);
|
|
358
|
+
return `${a === null || a === void 0 ? void 0 : a.v}`;
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
SheetsSortController = __decorate([__decorateParam(0, ICommandService), __decorateParam(1, Inject(SheetsSortService))], SheetsSortController);
|
|
362
|
+
|
|
363
|
+
//#endregion
|
|
364
|
+
//#region src/plugin.ts
|
|
365
|
+
let UniverSheetsSortPlugin = class UniverSheetsSortPlugin extends Plugin {
|
|
366
|
+
constructor(_config = defaultPluginConfig, _injector, _configService) {
|
|
367
|
+
super();
|
|
368
|
+
this._config = _config;
|
|
369
|
+
this._injector = _injector;
|
|
370
|
+
this._configService = _configService;
|
|
371
|
+
const { ...rest } = merge({}, defaultPluginConfig, this._config);
|
|
372
|
+
this._configService.setConfig(SHEETS_SORT_PLUGIN_CONFIG_KEY, rest);
|
|
373
|
+
}
|
|
374
|
+
onStarting() {
|
|
375
|
+
[[SheetsSortController], [SheetsSortService]].forEach((d) => this._injector.add(d));
|
|
376
|
+
}
|
|
377
|
+
onReady() {
|
|
378
|
+
this._injector.get(SheetsSortController);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
_defineProperty(UniverSheetsSortPlugin, "type", UniverInstanceType.UNIVER_SHEET);
|
|
382
|
+
_defineProperty(UniverSheetsSortPlugin, "pluginName", "SHEET_SORT_PLUGIN");
|
|
383
|
+
_defineProperty(UniverSheetsSortPlugin, "packageName", name);
|
|
384
|
+
_defineProperty(UniverSheetsSortPlugin, "version", version);
|
|
385
|
+
UniverSheetsSortPlugin = __decorate([
|
|
386
|
+
DependentOn(UniverSheetsPlugin, UniverFormulaEnginePlugin),
|
|
387
|
+
__decorateParam(1, Inject(Injector)),
|
|
388
|
+
__decorateParam(2, IConfigService)
|
|
389
|
+
], UniverSheetsSortPlugin);
|
|
390
|
+
|
|
391
|
+
//#endregion
|
|
392
|
+
export { SheetsSortService, SortRangeCommand, SortType, UniverSheetsSortPlugin };
|