import { N, uo } from "./chunk-BW43Z7N3.js"; import { Pr } from "./chunk-QRYBFJ3R.js"; import { Fe, Ot, Pt, Ra, SE, _n, ar, dn, en, mu, nt, nu, ot } from "./chunk-23V3HWTR.js"; // node_modules/.pnpm/@univerjs+sheets-sort@0.5.5_@grpc+grpc-js@1.13.4_react@18.3.1_rxjs@7.8.1/node_modules/@univerjs/sheets-sort/lib/es/index.js var H = Object.defineProperty; var q = (e, t, r) => t in e ? H(e, t, { enumerable: true, configurable: true, writable: true, value: r }) : e[t] = r; var h = (e, t, r) => q(e, typeof t != "symbol" ? t + "" : t, r); var ee = "sheets-sort.config"; var N2 = {}; var f = ((e) => (e.DESC = "desc", e.ASC = "asc", e))(f || {}); var D = (e) => e.replace(/-/gi, "").replace(/'/gi, ""); var te = (e, t) => { const r = e === null || e === "", o = t === null || t === ""; return r && o ? 0 : r ? 1 : o ? -1 : null; }; var re = (e, t, r) => { const o = typeof e == "number", n = typeof t == "number"; return o && n ? e < t ? r === f.ASC ? -1 : 1 : e > t ? r === f.ASC ? 1 : -1 : 0 : o ? r === f.ASC ? 1 : -1 : n ? r === f.ASC ? -1 : 1 : null; }; var ne = (e, t, r) => { const o = typeof e == "string", n = typeof t == "string"; if (o && (e = D(e.toLocaleLowerCase())), n && (t = D(t.toLocaleLowerCase())), !o && !n) return null; if (o && n) { const s = e, i = t; return s < i ? r === f.ASC ? -1 : 1 : s > i ? r === f.ASC ? 1 : -1 : 0; } return o ? r === f.ASC ? 1 : -1 : n ? r === f.ASC ? -1 : 1 : null; }; var M = (e) => !e || Object.keys(e).length === 0 || (e == null ? void 0 : e.v) == null && (e == null ? void 0 : e.p) == null; var oe = Object.defineProperty; var se = Object.getOwnPropertyDescriptor; var ie = (e, t, r, o) => { for (var n = o > 1 ? void 0 : o ? se(t, r) : t, s = e.length - 1, i; s >= 0; s--) (i = e[s]) && (n = (o ? i(t, r, n) : i(n)) || n); return o && n && oe(t, r, n), n; }; var p = (e, t) => (r, o) => t(r, o, e); var g = class extends nt { constructor(t, r, o) { super(); h(this, "_compareFns", []); this._univerInstanceService = t, this._commandService = r, this._formulaDataModel = o; } mergeCheck(t) { var c; const { unitId: r, subUnitId: o, range: n } = t, s = (c = this._univerInstanceService.getUnit(r)) == null ? void 0 : c.getSheetBySheetId(o); if (!s) return false; const i = s.getMergeData().filter((u) => en.contains(n, u)); return i.length === 0 ? true : ue(n, i); } emptyCheck(t) { var i; const { unitId: r, subUnitId: o, range: n } = t, s = (i = this._univerInstanceService.getUnit(r)) == null ? void 0 : i.getSheetBySheetId(o); if (!s) return false; for (let c = n.startRow; c <= n.endRow; c++) for (let u = n.startColumn; u <= n.endColumn; u++) if (!M(s.getCellRaw(c, u))) return true; return false; } singleCheck(t) { return t.range.startRow !== t.range.endRow; } formulaCheck(t) { var i, c; const { unitId: r, subUnitId: o, range: n } = t, s = (c = (i = this._formulaDataModel.getArrayFormulaRange()) == null ? void 0 : i[r]) == null ? void 0 : c[o]; for (const u in s) { const a = s[Number(u)]; for (const m in a) { const d = a[Number(m)]; if (d && en.intersects(n, d)) return false; } } return true; } registerCompareFn(t) { this._compareFns.unshift(t); } getAllCompareFns() { return this._compareFns; } applySort(t, r, o) { var i; const { unitId: n, subUnitId: s } = N(this._univerInstanceService) || {}; this._commandService.executeCommand($.id, { orderRules: t.orderRules, range: t.range, hasTitle: (i = t.hasTitle) != null ? i : false, unitId: r || n, subUnitId: o || s }); } }; g = ie([ p(0, _n), p(1, Pt), p(2, ot(Pr)) ], g); function ue(e, t) { const r = e.endRow - e.startRow + 1, o = e.endColumn - e.startColumn + 1; let n = null, s = null; const i = r * o; let c = 0; for (const u of t) if (u.startRow >= e.startRow && u.endRow <= e.endRow && u.startColumn >= e.startColumn && u.endColumn <= e.endColumn) { const a = u.endRow - u.startRow + 1, m = u.endColumn - u.startColumn + 1; if (n === null && s === null) n = a, s = m; else if (a !== n || m !== s) return false; c += a * m; } return c === i; } var $ = { id: "sheet.command.sort-range", type: ar.COMMAND, handler: (e, t) => { const { range: r, orderRules: o, hasTitle: n, unitId: s, subUnitId: i } = t, c = e.get(g), u = e.get(_n), { worksheet: a } = N(u, t) || {}; if (!a) return false; const m = a.getMergeData().filter((l) => en.contains(r, l)), d = m.map((l) => l.startRow), { startRow: b, endRow: j } = r, x = n ? b + 1 : b, S = [], A = []; for (let l = x; l <= j; l++) a.getRowFiltered(l) || a.getRowRawVisible(l) !== false && (m.length && !d.includes(l) || (S.push({ index: l, value: ce(a, l, o) }), A.push(l))); const V = c.getAllCompareFns(); S.sort(ae(o, le(V))); const F = {}; S.forEach(({ index: l, value: Se }, B) => { F[A[B]] = l; }); const L = { id: uo.id, params: { unitId: s, subUnitId: i, range: r, order: F } }, G = e.get(Pt); return mu([L], G).result; } }; function ce(e, t, r) { const o = []; return r.forEach(({ colIndex: n }) => { o.push(e.getCellRaw(t, n)); }), o; } function le(e) { return (t, r, o) => { for (let n = 0; n < e.length; n++) { const s = e[n](t, r, o); if (s != null) return s; } return 0; }; } function ae(e, t) { return function(r, o) { let n = null; for (let s = 0; s < e.length; s++) { const i = r.value[s], c = o.value[s]; if (n = t(e[s].type, i, c), n !== 0 && n !== null && n !== void 0) return n; } return 0; }; } var fe = Object.defineProperty; var me = Object.getOwnPropertyDescriptor; var ge = (e, t, r, o) => { for (var n = o > 1 ? void 0 : o ? me(t, r) : t, s = e.length - 1, i; s >= 0; s--) (i = e[s]) && (n = (o ? i(t, r, n) : i(n)) || n); return o && n && fe(t, r, n), n; }; var O = (e, t) => (r, o) => t(r, o, e); var v = class extends nt { constructor(e, t) { super(), this._commandService = e, this._sortService = t, this._initCommands(), this._registerCompareFns(); } _initCommands() { [ $ ].forEach((e) => this.disposeWithMe(this._commandService.registerCommand(e))); } _registerCompareFns() { const e = (t, r, o) => { const n = this._getCommonValue(r), s = this._getCommonValue(o), i = [ te, ne, re ]; for (let c = 0; c < i.length; c++) { const u = i[c](n, s, t); if (u !== null) return u; } return null; }; this._sortService.registerCompareFn(e); } _getCommonValue(e) { var r, o; if (M(e)) return null; const t = (o = (r = e == null ? void 0 : e.p) == null ? void 0 : r.body) == null ? void 0 : o.dataStream; return t || ((e == null ? void 0 : e.t) === dn.NUMBER ? Number.parseFloat(`${e.v}`) : (e == null ? void 0 : e.t) === dn.STRING ? typeof e.v == "number" ? e.v : `${e.v}` : (e == null ? void 0 : e.t) === dn.BOOLEAN ? `${e.v}` : (e == null ? void 0 : e.t) === dn.FORCE_STRING ? Number.parseFloat(`${e.v}`) : `${e == null ? void 0 : e.v}`); } }; v = ge([ O(0, Pt), O(1, ot(g)) ], v); var de = Object.defineProperty; var he = Object.getOwnPropertyDescriptor; var Ce = (e, t, r, o) => { for (var n = o > 1 ? void 0 : o ? he(t, r) : t, s = e.length - 1, i; s >= 0; s--) (i = e[s]) && (n = (o ? i(t, r, n) : i(n)) || n); return o && n && de(t, r, n), n; }; var P = (e, t) => (r, o) => t(r, o, e); var _e = "SHEET_SORT_PLUGIN"; var _; var E = (_ = class extends Ra { constructor(e = N2, t, r) { super(), this._config = e, this._injector = t, this._configService = r; const { ...o } = nu( {}, N2, this._config ); this._configService.setConfig(ee, o); } onStarting() { [ [v], [g] ].forEach((e) => this._injector.add(e)); } onReady() { this._injector.get(v); } }, h(_, "type", Fe.UNIVER_SHEET), h(_, "pluginName", _e), _); E = Ce([ P(1, ot(Ot)), P(2, SE) ], E); export { f, g, $, E }; //# sourceMappingURL=chunk-5XPMH3SW.js.map