import { SortType as r, SortRangeCommand as c } from "@univerjs/sheets-sort"; import { FRange as S, FWorksheet as l, FSheetEventName as R } from "@univerjs/sheets/facade"; import { RANGE_TYPE as k, FEventName as w, FUniver as C, ICommandService as p } from "@univerjs/core"; class f extends S { sort(o) { const e = this._range.startColumn, s = (Array.isArray(o) ? o : [o]).map((n) => typeof n == "number" ? { colIndex: n + e, type: r.ASC } : { colIndex: n.column + e, type: n.ascending ? r.ASC : r.DESC }); return this._commandService.syncExecuteCommand(c.id, { orderRules: s, range: this._range, hasTitle: !1, unitId: this._workbook.getUnitId(), subUnitId: this._worksheet.getSheetId() }), this; } } S.extend(f); class v extends l { sort(o, e = !0) { const t = [{ // real column index should be colIndex - 1. colIndex: o, type: e ? r.ASC : r.DESC }], s = { startRow: 0, startColumn: 0, endRow: this._worksheet.getRowCount() - 1, endColumn: this._worksheet.getColumnCount() - 1, rangeType: k.ALL }; return this._commandService.syncExecuteCommand(c.id, { orderRules: t, range: s, hasTitle: !1, unitId: this._workbook.getUnitId(), subUnitId: this._worksheet.getSheetId() }), this; } } l.extend(v); w.extend(R); class E extends C { _initialize(o) { const e = o.get(p); this.disposeWithMe(e.beforeCommandExecuted((t) => { switch (t.id) { case c.id: this._beforeRangeSort(t); break; } })), this.disposeWithMe(e.onCommandExecuted((t) => { switch (t.id) { case c.id: this._onRangeSorted(t); break; } })); } _beforeRangeSort(o) { const e = o.params, t = this.getUniverSheet(e.unitId), s = t.getSheetBySheetId(e.subUnitId), { startColumn: n, endColumn: h, startRow: a, endRow: m } = e.range, g = s.getRange(a, n, m - a + 1, h - n + 1), i = { workbook: t, worksheet: s, range: g, sortColumn: e.orderRules.map((d) => ({ column: d.colIndex - n, ascending: d.type === r.ASC })) }; if (this.fireEvent(this.Event.SheetBeforeRangeSort, i), i.cancel) throw new Error("SortRangeCommand canceled."); } _onRangeSorted(o) { const e = o.params, t = this.getUniverSheet(e.unitId), s = t.getSheetBySheetId(e.subUnitId), { startColumn: n, endColumn: h, startRow: a, endRow: m } = e.range, g = s.getRange(a, n, m - a + 1, h - n + 1), i = { workbook: t, worksheet: s, range: g, sortColumn: e.orderRules.map((d) => ({ column: d.colIndex - n, ascending: d.type === r.ASC })) }; if (this.fireEvent(this.Event.SheetRangeSorted, i), i.cancel) throw new Error("SortRangeCommand canceled."); } } C.extend(E);