@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.
Files changed (44) hide show
  1. package/lib/cjs/facade.js +125 -1
  2. package/lib/cjs/index.js +406 -1
  3. package/lib/cjs/locale/ca-ES.js +18 -1
  4. package/lib/cjs/locale/en-US.js +33 -1
  5. package/lib/cjs/locale/es-ES.js +18 -1
  6. package/lib/cjs/locale/fa-IR.js +18 -1
  7. package/lib/cjs/locale/fr-FR.js +18 -1
  8. package/lib/cjs/locale/ja-JP.js +18 -1
  9. package/lib/cjs/locale/ko-KR.js +18 -1
  10. package/lib/cjs/locale/ru-RU.js +18 -1
  11. package/lib/cjs/locale/sk-SK.js +18 -1
  12. package/lib/cjs/locale/vi-VN.js +18 -1
  13. package/lib/cjs/locale/zh-CN.js +18 -1
  14. package/lib/cjs/locale/zh-TW.js +18 -1
  15. package/lib/es/facade.js +126 -1
  16. package/lib/es/index.js +392 -1
  17. package/lib/es/locale/ca-ES.js +17 -1
  18. package/lib/es/locale/en-US.js +32 -1
  19. package/lib/es/locale/es-ES.js +17 -1
  20. package/lib/es/locale/fa-IR.js +17 -1
  21. package/lib/es/locale/fr-FR.js +17 -1
  22. package/lib/es/locale/ja-JP.js +17 -1
  23. package/lib/es/locale/ko-KR.js +17 -1
  24. package/lib/es/locale/ru-RU.js +17 -1
  25. package/lib/es/locale/sk-SK.js +17 -1
  26. package/lib/es/locale/vi-VN.js +17 -1
  27. package/lib/es/locale/zh-CN.js +17 -1
  28. package/lib/es/locale/zh-TW.js +17 -1
  29. package/lib/facade.js +126 -1
  30. package/lib/index.js +392 -1
  31. package/lib/locale/ca-ES.js +17 -1
  32. package/lib/locale/en-US.js +32 -1
  33. package/lib/locale/es-ES.js +17 -1
  34. package/lib/locale/fa-IR.js +17 -1
  35. package/lib/locale/fr-FR.js +17 -1
  36. package/lib/locale/ja-JP.js +17 -1
  37. package/lib/locale/ko-KR.js +17 -1
  38. package/lib/locale/ru-RU.js +17 -1
  39. package/lib/locale/sk-SK.js +17 -1
  40. package/lib/locale/vi-VN.js +17 -1
  41. package/lib/locale/zh-CN.js +17 -1
  42. package/lib/locale/zh-TW.js +17 -1
  43. package/lib/umd/index.js +1 -1
  44. package/package.json +6 -6
package/lib/index.js CHANGED
@@ -1 +1,392 @@
1
- import{CellValueType as e,CommandType as t,DependentOn as n,Disposable as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,Plugin as l,Rectangle as u,UniverInstanceType as d,merge as f,sequenceExecute as p}from"@univerjs/core";import{ReorderRangeCommand as m,UniverSheetsPlugin as h,getSheetCommandTarget as g}from"@univerjs/sheets";import{FormulaDataModel as _,UniverFormulaEnginePlugin as v}from"@univerjs/engine-formula";let y=function(e){return e.DESC=`desc`,e.ASC=`asc`,e}({}),b=function(e){return e[e.POSITIVE=1]=`POSITIVE`,e[e.NEGATIVE=-1]=`NEGATIVE`,e[e.ZERO=0]=`ZERO`,e}({});const x=e=>e.replace(/-/gi,``).replace(/'/gi,``),S=(e,t)=>{let n=e===null||e===``,r=t===null||t===``;return n&&r?b.ZERO:n?b.POSITIVE:r?b.NEGATIVE:null},C=(e,t,n)=>{let r=typeof e==`number`,i=typeof t==`number`;return r&&i?e<t?n===y.ASC?b.NEGATIVE:b.POSITIVE:e>t?n===y.ASC?b.POSITIVE:b.NEGATIVE:b.ZERO:r?n===y.ASC?b.POSITIVE:b.NEGATIVE:i?n===y.ASC?b.NEGATIVE:b.POSITIVE:null},w=(e,t,n)=>{let r=typeof e==`string`,i=typeof t==`string`;if(r&&(e=x(e.toLocaleLowerCase())),i&&(t=x(t.toLocaleLowerCase())),!r&&!i)return null;if(r&&i){let r=e,i=t;return r<i?n===y.ASC?b.NEGATIVE:b.POSITIVE:r>i?n===y.ASC?b.POSITIVE:b.NEGATIVE:b.ZERO}return r?n===y.ASC?b.POSITIVE:b.NEGATIVE:i?n===y.ASC?b.NEGATIVE:b.POSITIVE:null},T=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;function E(e){"@babel/helpers - typeof";return E=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},E(e)}function D(e,t){if(E(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(E(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function O(e){var t=D(e,`string`);return E(t)==`symbol`?t:t+``}function k(e,t,n){return(t=O(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function A(e,t){return function(n,r){t(n,r,e)}}function j(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 M=class extends r{constructor(e,t,n){super(),this._univerInstanceService=e,this._commandService=t,this._formulaDataModel=n,k(this,`_compareFns`,[])}mergeCheck(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;let o=a.getMergeData().filter(e=>u.contains(i,e));return o.length===0?!0:N(i,o)}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(!T(a.getCellRaw(e,t)))return!0;return!1}singleCheck(e){return e.range.startRow!==e.range.endRow}formulaCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._formulaDataModel.getArrayFormulaRange())==null||(t=t[n])==null?void 0:t[r];for(let e in a){let t=a[Number(e)];for(let e in t){let n=t[Number(e)];if(n&&u.intersects(i,n))return!1}}return!0}registerCompareFn(e){this._compareFns.unshift(e)}getAllCompareFns(){return this._compareFns}applySort(e,t,n){var r;let{unitId:i,subUnitId:a}=g(this._univerInstanceService)||{};this._commandService.executeCommand(P.id,{orderRules:e.orderRules,range:e.range,hasTitle:(r=e.hasTitle)==null?!1:r,unitId:t||i,subUnitId:n||a})}};M=j([A(0,o),A(1,i),A(2,s(_))],M);function N(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}const P={id:`sheet.command.sort-range`,type:t.COMMAND,handler:(e,t)=>{let{range:n,orderRules:r,hasTitle:a,unitId:s,subUnitId:c}=t,l=e.get(M),{worksheet:d}=g(e.get(o),t)||{};if(!d)return!1;let f=d.getMergeData().filter(e=>u.contains(n,e)),h=f.map(e=>e.startRow),{startRow:_,endRow:v}=n,y=a?_+1:_,b=[],x=[];for(let e=y;e<=v;e++)d.getRowFiltered(e)||d.getRowRawVisible(e)!==!1&&(f.length&&!h.includes(e)||(b.push({index:e,value:F(d,e,r)}),x.push(e)));let S=l.getAllCompareFns();b.sort(L(r,I(S)));let C={};b.forEach(({index:e,value:t},n)=>{C[x[n]]=e});let w={id:m.id,params:{unitId:s,subUnitId:c,range:n,order:C}},T=e.get(i);return p([w],T).result}};function F(e,t,n){let r=[];return n.forEach(({colIndex:n})=>{r.push(e.getCellRaw(t,n))}),r}function I(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 L(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 R=`@univerjs/sheets-sort`,z=`0.20.1`;const B=`sheets-sort.config`;Symbol(B);const V={};let H=class extends r{constructor(e,t){super(),this._commandService=e,this._sortService=t,this._initCommands(),this._registerCompareFns()}_initCommands(){[P].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,w,C];for(let t=0;t<a.length;t++){let n=a[t](r,i,e);if(n!==null)return n}return null})}_getCommonValue(t){var n;return T(t)?null:(t==null||(n=t.p)==null||(n=n.body)==null?void 0:n.dataStream)||((t==null?void 0:t.t)===e.NUMBER?Number.parseFloat(`${t.v}`):(t==null?void 0:t.t)===e.STRING?typeof t.v==`number`?t.v:`${t.v}`:(t==null?void 0:t.t)===e.BOOLEAN?`${t.v}`:(t==null?void 0:t.t)===e.FORCE_STRING?Number.parseFloat(`${t.v}`):`${t==null?void 0:t.v}`)}};H=j([A(0,i),A(1,s(M))],H);let U=class extends l{constructor(e=V,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=f({},V,this._config);this._configService.setConfig(B,r)}onStarting(){[[H],[M]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(H)}};k(U,`type`,d.UNIVER_SHEET),k(U,`pluginName`,`SHEET_SORT_PLUGIN`),k(U,`packageName`,R),k(U,`version`,z),U=j([n(h,v),A(1,s(c)),A(2,a)],U);export{M as SheetsSortService,P as SortRangeCommand,y as SortType,U as UniverSheetsSortPlugin};
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 };
@@ -1 +1,17 @@
1
- const e={sheetsSort:{title:`Ordena`,toolbar:{"sort-asc":`ordre ascendent`,"sort-desc":`ordre descendent`,"sort-custom":`ordre personalitzat`},"context-menu":{"sort-asc":`ordre ascendent`,"sort-desc":`ordre descendent`,"sort-custom":`ordre personalitzat`}}};export{e as default};
1
+ //#region src/locale/ca-ES.ts
2
+ const locale = { sheetsSort: {
3
+ title: "Ordena",
4
+ toolbar: {
5
+ "sort-asc": "ordre ascendent",
6
+ "sort-desc": "ordre descendent",
7
+ "sort-custom": "ordre personalitzat"
8
+ },
9
+ "context-menu": {
10
+ "sort-asc": "ordre ascendent",
11
+ "sort-desc": "ordre descendent",
12
+ "sort-custom": "ordre personalitzat"
13
+ }
14
+ } };
15
+
16
+ //#endregion
17
+ export { locale as default };
@@ -1 +1,32 @@
1
- const e={sheetsSort:{title:`Sort`,toolbar:{"sort-asc":`ascending order`,"sort-desc":`descending order`,"sort-custom":`custom order`},"context-menu":{"sort-asc":`ascending order`,"sort-desc":`descending order`,"sort-custom":`custom order`}}};export{e as default};
1
+ //#region src/locale/en-US.ts
2
+ /**
3
+ * Copyright 2023-present DreamNum Co., Ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ const locale = { sheetsSort: {
18
+ title: "Sort",
19
+ toolbar: {
20
+ "sort-asc": "ascending order",
21
+ "sort-desc": "descending order",
22
+ "sort-custom": "custom order"
23
+ },
24
+ "context-menu": {
25
+ "sort-asc": "ascending order",
26
+ "sort-desc": "descending order",
27
+ "sort-custom": "custom order"
28
+ }
29
+ } };
30
+
31
+ //#endregion
32
+ export { locale as default };
@@ -1 +1,17 @@
1
- const e={sheetsSort:{title:`Ordenar`,toolbar:{"sort-asc":`orden ascendente`,"sort-desc":`orden descendente`,"sort-custom":`orden personalizado`},"context-menu":{"sort-asc":`orden ascendente`,"sort-desc":`orden descendente`,"sort-custom":`orden personalizado`}}};export{e as default};
1
+ //#region src/locale/es-ES.ts
2
+ const locale = { sheetsSort: {
3
+ title: "Ordenar",
4
+ toolbar: {
5
+ "sort-asc": "orden ascendente",
6
+ "sort-desc": "orden descendente",
7
+ "sort-custom": "orden personalizado"
8
+ },
9
+ "context-menu": {
10
+ "sort-asc": "orden ascendente",
11
+ "sort-desc": "orden descendente",
12
+ "sort-custom": "orden personalizado"
13
+ }
14
+ } };
15
+
16
+ //#endregion
17
+ export { locale as default };
@@ -1 +1,17 @@
1
- const e={sheetsSort:{title:`مرتب‌سازی`,toolbar:{"sort-asc":`ترتیب صعودی`,"sort-desc":`ترتیب نزولی`,"sort-custom":`ترتیب سفارشی`},"context-menu":{"sort-asc":`ترتیب صعودی`,"sort-desc":`ترتیب نزولی`,"sort-custom":`ترتیب سفارشی`}}};export{e as default};
1
+ //#region src/locale/fa-IR.ts
2
+ const locale = { sheetsSort: {
3
+ title: "مرتب‌سازی",
4
+ toolbar: {
5
+ "sort-asc": "ترتیب صعودی",
6
+ "sort-desc": "ترتیب نزولی",
7
+ "sort-custom": "ترتیب سفارشی"
8
+ },
9
+ "context-menu": {
10
+ "sort-asc": "ترتیب صعودی",
11
+ "sort-desc": "ترتیب نزولی",
12
+ "sort-custom": "ترتیب سفارشی"
13
+ }
14
+ } };
15
+
16
+ //#endregion
17
+ export { locale as default };
@@ -1 +1,17 @@
1
- const e={sheetsSort:{title:`Trier`,toolbar:{"sort-asc":`ordre croissant`,"sort-desc":`ordre décroissant`,"sort-custom":`ordre personnalisé`},"context-menu":{"sort-asc":`ordre croissant`,"sort-desc":`ordre décroissant`,"sort-custom":`ordre personnalisé`}}};export{e as default};
1
+ //#region src/locale/fr-FR.ts
2
+ const locale = { sheetsSort: {
3
+ title: "Trier",
4
+ toolbar: {
5
+ "sort-asc": "ordre croissant",
6
+ "sort-desc": "ordre décroissant",
7
+ "sort-custom": "ordre personnalisé"
8
+ },
9
+ "context-menu": {
10
+ "sort-asc": "ordre croissant",
11
+ "sort-desc": "ordre décroissant",
12
+ "sort-custom": "ordre personnalisé"
13
+ }
14
+ } };
15
+
16
+ //#endregion
17
+ export { locale as default };
@@ -1 +1,17 @@
1
- const e={sheetsSort:{title:`並べ替え`,toolbar:{"sort-asc":`昇順`,"sort-desc":`降順`,"sort-custom":`カスタム順序`},"context-menu":{"sort-asc":`昇順`,"sort-desc":`降順`,"sort-custom":`カスタム順序`}}};export{e as default};
1
+ //#region src/locale/ja-JP.ts
2
+ const locale = { sheetsSort: {
3
+ title: "並べ替え",
4
+ toolbar: {
5
+ "sort-asc": "昇順",
6
+ "sort-desc": "降順",
7
+ "sort-custom": "カスタム順序"
8
+ },
9
+ "context-menu": {
10
+ "sort-asc": "昇順",
11
+ "sort-desc": "降順",
12
+ "sort-custom": "カスタム順序"
13
+ }
14
+ } };
15
+
16
+ //#endregion
17
+ export { locale as default };
@@ -1 +1,17 @@
1
- const e={sheetsSort:{title:`정렬`,toolbar:{"sort-asc":`오름차순`,"sort-desc":`내림차순`,"sort-custom":`사용자 정의 순서`},"context-menu":{"sort-asc":`오름차순`,"sort-desc":`내림차순`,"sort-custom":`사용자 정의 순서`}}};export{e as default};
1
+ //#region src/locale/ko-KR.ts
2
+ const locale = { sheetsSort: {
3
+ title: "정렬",
4
+ toolbar: {
5
+ "sort-asc": "오름차순",
6
+ "sort-desc": "내림차순",
7
+ "sort-custom": "사용자 정의 순서"
8
+ },
9
+ "context-menu": {
10
+ "sort-asc": "오름차순",
11
+ "sort-desc": "내림차순",
12
+ "sort-custom": "사용자 정의 순서"
13
+ }
14
+ } };
15
+
16
+ //#endregion
17
+ export { locale as default };
@@ -1 +1,17 @@
1
- const e={sheetsSort:{title:`Sort`,toolbar:{"sort-asc":`по возрастанию`,"sort-desc":`по убыванию`,"sort-custom":`пользовательский выбор`},"context-menu":{"sort-asc":`по возрастанию`,"sort-desc":`по убыванию`,"sort-custom":`пользовательский выбор`}}};export{e as default};
1
+ //#region src/locale/ru-RU.ts
2
+ const locale = { sheetsSort: {
3
+ title: "Sort",
4
+ toolbar: {
5
+ "sort-asc": "по возрастанию",
6
+ "sort-desc": "по убыванию",
7
+ "sort-custom": "пользовательский выбор"
8
+ },
9
+ "context-menu": {
10
+ "sort-asc": "по возрастанию",
11
+ "sort-desc": "по убыванию",
12
+ "sort-custom": "пользовательский выбор"
13
+ }
14
+ } };
15
+
16
+ //#endregion
17
+ export { locale as default };
@@ -1 +1,17 @@
1
- const e={sheetsSort:{title:`Triedenie`,toolbar:{"sort-asc":`vzostupné poradie`,"sort-desc":`zostupné poradie`,"sort-custom":`vlastné poradie`},"context-menu":{"sort-asc":`vzostupné poradie`,"sort-desc":`zostupné poradie`,"sort-custom":`vlastné poradie`}}};export{e as default};
1
+ //#region src/locale/sk-SK.ts
2
+ const locale = { sheetsSort: {
3
+ title: "Triedenie",
4
+ toolbar: {
5
+ "sort-asc": "vzostupné poradie",
6
+ "sort-desc": "zostupné poradie",
7
+ "sort-custom": "vlastné poradie"
8
+ },
9
+ "context-menu": {
10
+ "sort-asc": "vzostupné poradie",
11
+ "sort-desc": "zostupné poradie",
12
+ "sort-custom": "vlastné poradie"
13
+ }
14
+ } };
15
+
16
+ //#endregion
17
+ export { locale as default };
@@ -1 +1,17 @@
1
- const e={sheetsSort:{title:`Sort`,toolbar:{"sort-asc":`ascending order`,"sort-desc":`descending order`,"sort-custom":`custom order`},"context-menu":{"sort-asc":`ascending order`,"sort-desc":`descending order`,"sort-custom":`custom order`}}};export{e as default};
1
+ //#region src/locale/vi-VN.ts
2
+ const locale = { 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
+
16
+ //#endregion
17
+ export { locale as default };
@@ -1 +1,17 @@
1
- const e={sheetsSort:{title:`排序`,toolbar:{"sort-asc":`升序`,"sort-desc":`降序`,"sort-custom":`自定义排序`},"context-menu":{"sort-asc":`升序`,"sort-desc":`降序`,"sort-custom":`自定义排序`}}};export{e as default};
1
+ //#region src/locale/zh-CN.ts
2
+ const locale = { sheetsSort: {
3
+ title: "排序",
4
+ toolbar: {
5
+ "sort-asc": "升序",
6
+ "sort-desc": "降序",
7
+ "sort-custom": "自定义排序"
8
+ },
9
+ "context-menu": {
10
+ "sort-asc": "升序",
11
+ "sort-desc": "降序",
12
+ "sort-custom": "自定义排序"
13
+ }
14
+ } };
15
+
16
+ //#endregion
17
+ export { locale as default };
@@ -1 +1,17 @@
1
- const e={sheetsSort:{title:`Sắp xếp`,toolbar:{"sort-asc":`Tăng dần`,"sort-desc":`Giảm dần`,"sort-custom":`Sắp xếp tùy chỉnh`},"context-menu":{"sort-asc":`Tăng dần`,"sort-desc":`Giảm dần`,"sort-custom":`Sắp xếp tùy chỉnh`}}};export{e as default};
1
+ //#region src/locale/zh-TW.ts
2
+ const locale = { 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
+
16
+ //#endregion
17
+ export { locale as default };