| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- var H = Object.defineProperty;
- var q = (e, t, r) => t in e ? H(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
- var h = (e, t, r) => q(e, typeof t != "symbol" ? t + "" : t, r);
- import { Inject as w, Disposable as y, Rectangle as R, IUniverInstanceService as U, ICommandService as I, CommandType as K, sequenceExecute as W, CellValueType as C, Plugin as Y, merge as z, UniverInstanceType as J, Injector as Q, IConfigService as X } from "@univerjs/core";
- import { getSheetCommandTarget as T, ReorderRangeCommand as Z } from "@univerjs/sheets";
- import { FormulaDataModel as k } from "@univerjs/engine-formula";
- const ee = "sheets-sort.config", N = {};
- var f = /* @__PURE__ */ ((e) => (e.DESC = "desc", e.ASC = "asc", e))(f || {});
- const D = (e) => e.replace(/-/gi, "").replace(/'/gi, ""), te = (e, t) => {
- const r = e === null || e === "", o = t === null || t === "";
- return r && o ? 0 : r ? 1 : o ? -1 : null;
- }, 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;
- }, 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;
- }, 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, se = Object.getOwnPropertyDescriptor, 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;
- }, p = (e, t) => (r, o) => t(r, o, e);
- let g = class extends y {
- 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 !1;
- const i = s.getMergeData().filter((u) => R.contains(n, u));
- return i.length === 0 ? !0 : 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 !1;
- 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 !0;
- return !1;
- }
- 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 && R.intersects(n, d))
- return !1;
- }
- }
- return !0;
- }
- registerCompareFn(t) {
- this._compareFns.unshift(t);
- }
- getAllCompareFns() {
- return this._compareFns;
- }
- applySort(t, r, o) {
- var i;
- const { unitId: n, subUnitId: s } = T(this._univerInstanceService) || {};
- this._commandService.executeCommand($.id, {
- orderRules: t.orderRules,
- range: t.range,
- hasTitle: (i = t.hasTitle) != null ? i : !1,
- unitId: r || n,
- subUnitId: o || s
- });
- }
- };
- g = ie([
- p(0, U),
- p(1, I),
- p(2, w(k))
- ], 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 !1;
- c += a * m;
- }
- return c === i;
- }
- const $ = {
- id: "sheet.command.sort-range",
- type: K.COMMAND,
- handler: (e, t) => {
- const { range: r, orderRules: o, hasTitle: n, unitId: s, subUnitId: i } = t, c = e.get(g), u = e.get(U), { worksheet: a } = T(u, t) || {};
- if (!a)
- return !1;
- const m = a.getMergeData().filter((l) => R.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) !== !1 && (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: Z.id,
- params: {
- unitId: s,
- subUnitId: i,
- range: r,
- order: F
- }
- }, G = e.get(I);
- return W([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, me = Object.getOwnPropertyDescriptor, 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;
- }, O = (e, t) => (r, o) => t(r, o, e);
- let v = class extends y {
- 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) === C.NUMBER ? Number.parseFloat(`${e.v}`) : (e == null ? void 0 : e.t) === C.STRING ? typeof e.v == "number" ? e.v : `${e.v}` : (e == null ? void 0 : e.t) === C.BOOLEAN ? `${e.v}` : (e == null ? void 0 : e.t) === C.FORCE_STRING ? Number.parseFloat(`${e.v}`) : `${e == null ? void 0 : e.v}`);
- }
- };
- v = ge([
- O(0, I),
- O(1, w(g))
- ], v);
- var de = Object.defineProperty, he = Object.getOwnPropertyDescriptor, 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;
- }, P = (e, t) => (r, o) => t(r, o, e);
- const _e = "SHEET_SORT_PLUGIN";
- var _;
- let E = (_ = class extends Y {
- constructor(e = N, t, r) {
- super(), this._config = e, this._injector = t, this._configService = r;
- const { ...o } = z(
- {},
- N,
- this._config
- );
- this._configService.setConfig(ee, o);
- }
- onStarting() {
- [
- [v],
- [g]
- ].forEach((e) => this._injector.add(e));
- }
- onReady() {
- this._injector.get(v);
- }
- }, h(_, "type", J.UNIVER_SHEET), h(_, "pluginName", _e), _);
- E = Ce([
- P(1, w(Q)),
- P(2, X)
- ], E);
- export {
- g as SheetsSortService,
- $ as SortRangeCommand,
- f as SortType,
- E as UniverSheetsSortPlugin
- };
|