1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414 |
- import {
- $,
- Be,
- F,
- Fn,
- Gn,
- Jd,
- Mh,
- N,
- Q,
- V,
- _t,
- an,
- et,
- gt,
- ko,
- mt,
- pt,
- qe,
- xs,
- zn
- } from "./chunk-BW43Z7N3.js";
- import {
- AR,
- BehaviorSubject,
- Bi,
- Fe,
- Gf,
- Ko,
- Mi,
- NE,
- Ot,
- Pt,
- Ra,
- SE,
- Vr,
- _n,
- ar,
- cn,
- d0,
- dn,
- en,
- filter,
- merge,
- mu,
- nt,
- nu,
- of,
- ot,
- re,
- switchMap,
- tE
- } from "./chunk-23V3HWTR.js";
- // node_modules/.pnpm/@univerjs+sheets-filter@0.5.5_@grpc+grpc-js@1.13.4_react@18.3.1_rxjs@7.8.1/node_modules/@univerjs/sheets-filter/lib/es/index.js
- var Fe2 = Object.defineProperty;
- var we = (i, r, e) => r in i ? Fe2(i, r, { enumerable: true, configurable: true, writable: true, value: e }) : i[r] = e;
- var w = (i, r, e) => we(i, typeof r != "symbol" ? r + "" : r, e);
- var tt = "sheets-filter.config";
- var re2 = {};
- var ce = "sheet.mutation.set-filter-range";
- var de = "sheet.mutation.set-filter-criteria";
- var ue = "sheet.mutation.remove-filter";
- var he = "sheet.mutation.re-calc-filter";
- var rt = /* @__PURE__ */ new Set([
- ce,
- de,
- ue,
- he
- ]);
- var N2 = ((i) => (i.EQUAL = "equal", i.GREATER_THAN = "greaterThan", i.GREATER_THAN_OR_EQUAL = "greaterThanOrEqual", i.LESS_THAN = "lessThan", i.LESS_THAN_OR_EQUAL = "lessThanOrEqual", i.NOT_EQUALS = "notEqual", i))(N2 || {});
- var nt2 = {
- operator: N2.GREATER_THAN,
- fn: (i, r) => $2(i) ? i > r : false
- };
- var it = {
- operator: N2.GREATER_THAN_OR_EQUAL,
- fn: (i, r) => $2(i) ? i >= r : false
- };
- var st = {
- operator: N2.LESS_THAN,
- fn: (i, r) => $2(i) ? i < r : false
- };
- var ot2 = {
- operator: N2.LESS_THAN_OR_EQUAL,
- fn: (i, r) => $2(i) ? i <= r : false
- };
- var lt = {
- operator: N2.EQUAL,
- fn: (i, r) => $2(i) ? i === r : false
- };
- var fe = {
- operator: N2.NOT_EQUALS,
- fn: (i, r) => {
- if (typeof r == "string") {
- if (r === " ")
- return i != null;
- const e = ge(i);
- return e && ut(r) ? !_e(r).test(e) : e !== r;
- }
- return $2(i) ? i !== r : true;
- }
- };
- var me = /* @__PURE__ */ new Map([]);
- var at = [nt2, it, st, ot2, lt, fe];
- at.forEach((i) => {
- me.set(i.operator, i);
- });
- function ct(i) {
- return !!i;
- }
- var dt = {
- fn: (i, r) => {
- const e = ge(i);
- return e === null ? r === "" : _e(r).test(e);
- }
- };
- function ne(i) {
- return i ? me.get(i) : dt;
- }
- function $2(i) {
- return typeof i == "number";
- }
- function ie(i) {
- return !!(typeof i == "number" || typeof i == "string" && d0(i));
- }
- function ge(i) {
- return typeof i == "boolean" || i == null ? null : typeof i == "string" ? i : i.toString();
- }
- function ut(i) {
- return typeof i == "number" ? false : i.indexOf("*") !== -1 || i.indexOf("?") !== -1;
- }
- function _e(i) {
- const r = i.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("?", ".").replace(/[*]/g, ".$&");
- return new RegExp(`^${r}$`);
- }
- var G = () => /* @__PURE__ */ new Set();
- var D = class _D extends nt {
- constructor(e, t, n) {
- super();
- w(this, "_filteredOutRows$", new BehaviorSubject(G()));
- w(this, "filteredOutRows$", this._filteredOutRows$.asObservable());
- w(this, "_hasCriteria$", new BehaviorSubject(false));
- w(this, "hasCriteria$", this._hasCriteria$.asObservable());
- w(this, "_filterColumnByIndex", /* @__PURE__ */ new Map());
- w(this, "_alreadyFilteredOutRows", G());
- w(this, "_range");
- this.unitId = e, this.subUnitId = t, this._worksheet = n;
- }
- get filteredOutRows() {
- return this._filteredOutRows$.getValue();
- }
- set filteredOutRows(e) {
- this._alreadyFilteredOutRows = e, this._filteredOutRows$.next(e);
- }
- dispose() {
- super.dispose(), this._filteredOutRows$.complete(), this._hasCriteria$.complete();
- }
- /**
- * Serialize this filter model to the JSON format representation.
- */
- serialize() {
- const e = {
- ref: en.clone(this._range),
- filterColumns: this._getAllFilterColumns(true).sort(([t], [n]) => t - n).map(([t, n]) => n.serialize())
- };
- return this._alreadyFilteredOutRows && (e.cachedFilteredOut = Array.from(this._alreadyFilteredOutRows).sort()), e;
- }
- /**
- * Deserialize auto filter info to construct a `FilterModel` object.
- * @param unitId workbook id
- * @param subUnitId worksheet id
- * @param worksheet the Worksheet object
- * @param autoFilter auto filter data
- */
- static deserialize(e, t, n, s) {
- const o = new _D(e, t, n);
- return o._dump(s), o;
- }
- _dump(e) {
- var t;
- this.setRange(e.ref), (t = e.filterColumns) == null || t.forEach((n) => this._setCriteriaWithoutReCalc(n.colId, n)), e.cachedFilteredOut && (this._alreadyFilteredOutRows = new Set(e.cachedFilteredOut), this._emit()), this._emitHasCriteria();
- }
- isRowFiltered(e) {
- return this._alreadyFilteredOutRows.has(e);
- }
- getRange() {
- if (!this._range)
- throw new Error("[FilterModel] could not get range before a range is set!");
- return this._range;
- }
- /**
- * Get filtered out rows except the specific column. This method is considered as "pure". In
- * another word it would not change `filteredOutRows` on `FilterModel` nor `FilterColumn`.
- * @param col
- */
- getFilteredOutRowsExceptCol(e) {
- return this._getAllFilterColumns(true).filter(([t]) => t !== e).reduce((t, [, n]) => {
- const s = n.calc({ getAlreadyFilteredOutRows: () => t });
- return s ? AR(t, s) : t;
- }, /* @__PURE__ */ new Set());
- }
- /**
- * Set range of the filter model, this would remove some `IFilterColumn`
- * if the new range not overlaps the old range.
- */
- setRange(e) {
- this._range = e, this._getAllFilterColumns(true).forEach(([t, n]) => {
- n.setRangeAndColumn({
- startRow: e.startRow,
- endRow: e.endRow,
- startColumn: t,
- endColumn: t
- }, t);
- });
- }
- /**
- * Set or remove filter criteria on a specific row.
- */
- setCriteria(e, t, n = false) {
- if (!this._range)
- throw new Error("[FilterModel] could not set criteria before a range is set!");
- if (!t) {
- this._removeCriteria(e), this._rebuildAlreadyFilteredOutRowsWithCache(), n && this._reCalcAllColumns(), this._emit(), this._emitHasCriteria();
- return;
- }
- this._setCriteriaWithoutReCalc(e, t), n && (this._rebuildAlreadyFilteredOutRowsWithCache(), this._reCalcWithNoCacheColumns(), this._emit(), this._emitHasCriteria());
- }
- getAllFilterColumns() {
- return this._getAllFilterColumns(true);
- }
- getFilterColumn(e) {
- var t;
- return (t = this._filterColumnByIndex.get(e)) != null ? t : null;
- }
- reCalc() {
- this._reCalcAllColumns(), this._emit();
- }
- _getAllFilterColumns(e = false) {
- const t = Array.from(this._filterColumnByIndex.entries());
- return e ? t : t.map(([n, s]) => s);
- }
- _reCalcAllColumns() {
- this._alreadyFilteredOutRows = G(), this._getAllFilterColumns().forEach((e) => e.__clearCache()), this._reCalcWithNoCacheColumns();
- }
- _setCriteriaWithoutReCalc(e, t) {
- const n = this._range;
- if (!n)
- throw new Error("[FilterModel] could not set criteria before a range is set!");
- const { startColumn: s, endColumn: o } = n;
- if (e > o || e < s)
- throw new Error(`[FilterModel] could not set criteria on column ${e} which is out of range!`);
- let l;
- this._filterColumnByIndex.has(e) ? l = this._filterColumnByIndex.get(e) : (l = new ht(
- this.unitId,
- this.subUnitId,
- this._worksheet,
- t,
- { getAlreadyFilteredOutRows: () => this._alreadyFilteredOutRows }
- ), l.setRangeAndColumn(n, e), this._filterColumnByIndex.set(e, l)), l.setCriteria(t);
- }
- _removeCriteria(e) {
- const t = this._filterColumnByIndex.get(e);
- t && (t.dispose(), this._filterColumnByIndex.delete(e));
- }
- _emit() {
- this._filteredOutRows$.next(this._alreadyFilteredOutRows);
- }
- _emitHasCriteria() {
- this._hasCriteria$.next(this._filterColumnByIndex.size > 0);
- }
- _rebuildAlreadyFilteredOutRowsWithCache() {
- const e = this._getAllFilterColumns().filter((t) => t.hasCache()).reduce((t, n) => AR(t, n.filteredOutRows), /* @__PURE__ */ new Set());
- this._alreadyFilteredOutRows = e;
- }
- _reCalcWithNoCacheColumns() {
- const e = this._getAllFilterColumns().filter((t) => !t.hasCache());
- for (const t of e) {
- const n = t.reCalc();
- n && (this._alreadyFilteredOutRows = AR(this._alreadyFilteredOutRows, n));
- }
- }
- };
- var ht = class extends nt {
- constructor(e, t, n, s, o) {
- super();
- w(this, "_filteredOutRows", null);
- w(this, "_filterFn", null);
- w(this, "_range", null);
- w(this, "_column", 0);
- w(this, "_filterByValues", false);
- this.unitId = e, this.subUnitId = t, this._worksheet = n, this._criteria = s, this._filterColumnContext = o;
- }
- get filteredOutRows() {
- return this._filteredOutRows;
- }
- dispose() {
- super.dispose(), this._filteredOutRows = null;
- }
- /**
- * @internal
- */
- __clearCache() {
- this._filteredOutRows = null;
- }
- serialize() {
- if (!this._criteria)
- throw new Error("[FilterColumn]: could not serialize without a filter column!");
- return re.deepClone({
- ...this._criteria,
- colId: this._column
- });
- }
- hasCache() {
- return this._filteredOutRows !== null;
- }
- // The first row should be omitted!
- setRangeAndColumn(e, t) {
- this._range = e, this._column = t;
- }
- setCriteria(e) {
- this._criteria = e, this._generateFilterFn(), this._filteredOutRows = null;
- }
- getColumnData() {
- return re.deepClone(this._criteria);
- }
- /**
- * Trigger new calculation on this `FilterModel` instance.
- *
- * @external DO NOT EVER call this method from `FilterColumn` itself. The whole process heavily relies on
- * `filteredOutByOthers`, and it is more comprehensible if we let `FilterModel` take full control over the process.
- */
- reCalc() {
- return this._filteredOutRows = this.calc(this._filterColumnContext), this._filteredOutRows;
- }
- calc(e) {
- if (!this._filterFn)
- throw new Error("[FilterColumn] cannot calculate without a filter fn!");
- if (!this._range)
- throw new Error("[FilterColumn] cannot calculate without a range!");
- if (typeof this._column != "number")
- throw new TypeError("[FilterColumn] cannot calculate without a column offset!");
- const t = this._column, n = { startColumn: t, endColumn: t, startRow: this._range.startRow + 1, endRow: this._range.endRow }, s = /* @__PURE__ */ new Set(), o = e.getAlreadyFilteredOutRows();
- for (const l of this._worksheet.iterateByColumn(n, false, false)) {
- const { row: a, rowSpan: c, col: h } = l;
- if (o.has(a) && (!c || c === 1))
- continue;
- const d = this._filterByValues ? tE(this._worksheet.getCell(a, h)) : Ft(this._worksheet, a, h);
- if (!this._filterFn(d) && (s.add(a), c))
- for (let u = 1; u < c; u++)
- s.add(a + u);
- }
- return s;
- }
- _generateFilterFn() {
- this._criteria && (this._filterFn = ft(this._criteria), this._filterByValues = !!this._criteria.filters);
- }
- };
- function ft(i) {
- if (i.filters)
- return mt2(i.filters);
- if (i.customFilters)
- return gt2(i.customFilters);
- throw new Error("[FilterModel]: other types of filters are not supported yet.");
- }
- function mt2(i) {
- const r = !!i.blank, e = new Set(i.filters);
- return (t) => t === void 0 || t === "" ? r : e.has(typeof t == "string" ? t : `${t}`);
- }
- function gt2(i) {
- const r = i.customFilters.map((e) => pt2(e));
- return Ct(r) ? i.and ? _t2(r) : Rt(r) : r[0];
- }
- function _t2(i) {
- const [r, e] = i;
- return (t) => r(t) && e(t);
- }
- function Rt(i) {
- const [r, e] = i;
- return (t) => r(t) || e(t);
- }
- function Ct(i) {
- return i.length === 2;
- }
- function pt2(i) {
- const r = i.val;
- if (i.operator === N2.NOT_EQUALS && !ie(r))
- return (n) => fe.fn(n, r);
- if (ct(i.operator)) {
- if (!ie(r))
- return () => false;
- const n = ne(i.operator), s = Number(r);
- return (o) => n.fn(o, s);
- }
- const e = ne(i.operator);
- return (t) => e.fn(t, r);
- }
- function Ft(i, r, e) {
- const t = i.getCell(r, e);
- if (!t)
- return null;
- const n = i.getCellRaw(r, e);
- return t && !n ? se(t) : n ? t.t === dn.NUMBER && typeof t.v == "string" ? n.v : se(n) : null;
- }
- function se(i) {
- var t, n;
- const r = (n = (t = i.p) == null ? void 0 : t.body) == null ? void 0 : n.dataStream;
- if (r)
- return r.trimEnd();
- const e = i.v;
- return typeof e == "string" ? i.t === dn.BOOLEAN ? e.toUpperCase() : e : typeof e == "number" ? i.t === dn.BOOLEAN ? e ? "TRUE" : "FALSE" : e : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : "";
- }
- var wt = Object.defineProperty;
- var St = Object.getOwnPropertyDescriptor;
- var vt = (i, r, e, t) => {
- for (var n = t > 1 ? void 0 : t ? St(r, e) : r, s = i.length - 1, o; s >= 0; s--)
- (o = i[s]) && (n = (t ? o(r, e, n) : o(n)) || n);
- return t && n && wt(r, e, n), n;
- };
- var J = (i, r) => (e, t) => r(e, t, i);
- var Re = "SHEET_FILTER_PLUGIN";
- var M = class extends nt {
- constructor(r, e, t) {
- super();
- w(this, "_filterModels", /* @__PURE__ */ new Map());
- w(this, "_loadedUnitId$", new BehaviorSubject(null));
- w(this, "loadedUnitId$", this._loadedUnitId$.asObservable());
- w(this, "_errorMsg$", new BehaviorSubject(null));
- w(this, "errorMsg$", this._errorMsg$.asObservable());
- w(this, "_activeFilterModel$", new BehaviorSubject(null));
- w(this, "activeFilterModel$", this._activeFilterModel$.asObservable());
- this._resourcesManagerService = r, this._univerInstanceService = e, this._commandService = t, this._initModel(), this._initActiveFilterModel();
- }
- /** The current Workbook's active Worksheet's filter model (if there is one). */
- get activeFilterModel() {
- return this._activeFilterModel$.getValue();
- }
- /**
- *
- * @param unitId
- * @param subUnitId
- */
- ensureFilterModel(r, e) {
- const t = this.getFilterModel(r, e);
- if (t)
- return t;
- const n = this._univerInstanceService.getUniverSheetInstance(r);
- if (!n)
- throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${r}!`);
- const s = n.getSheetBySheetId(e);
- if (!s)
- throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing worksheet ${e}!`);
- const o = new D(r, e, s);
- return this._cacheFilterModel(r, e, o), o;
- }
- getFilterModel(r, e) {
- var t, n;
- return (n = (t = this._filterModels.get(r)) == null ? void 0 : t.get(e)) != null ? n : null;
- }
- removeFilterModel(r, e) {
- const t = this.getFilterModel(r, e);
- return t ? (t.dispose(), this._filterModels.get(r).delete(e), true) : false;
- }
- setFilterErrorMsg(r) {
- this._errorMsg$.next(r);
- }
- _updateActiveFilterModel() {
- let r;
- try {
- if (r = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET), !r) {
- this._activeFilterModel$.next(null);
- return;
- }
- } catch (o) {
- console.error("[SheetsFilterService]: could not get active workbook!", o);
- return;
- }
- const e = r.getActiveSheet(true);
- if (!e) {
- this._activeFilterModel$.next(null);
- return;
- }
- const t = e.getUnitId(), n = e.getSheetId(), s = this.getFilterModel(t, n);
- this._activeFilterModel$.next(s);
- }
- _initActiveFilterModel() {
- this.disposeWithMe(
- merge(
- // source1: executing filter related mutations
- Gf(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(filter(([r]) => r.type === ar.MUTATION && rt.has(r.id))),
- // source2: activate sheet changes
- this._univerInstanceService.getCurrentTypeOfUnit$(Fe.UNIVER_SHEET).pipe(switchMap((r) => {
- var e;
- return (e = r == null ? void 0 : r.activeSheet$) != null ? e : of(null);
- }))
- ).subscribe(() => this._updateActiveFilterModel())
- );
- }
- _serializeAutoFiltersForUnit(r) {
- const e = this._filterModels.get(r);
- if (!e)
- return "{}";
- const t = {};
- return e.forEach((n, s) => {
- t[s] = n.serialize();
- }), JSON.stringify(t);
- }
- _deserializeAutoFiltersForUnit(r, e) {
- const t = this._univerInstanceService.getUniverSheetInstance(r);
- Object.keys(e).forEach((n) => {
- const s = e[n], o = D.deserialize(r, n, t.getSheetBySheetId(n), s);
- this._cacheFilterModel(r, n, o);
- });
- }
- _initModel() {
- this._resourcesManagerService.registerPluginResource({
- pluginName: Re,
- businesses: [Fe.UNIVER_SHEET],
- toJson: (r) => this._serializeAutoFiltersForUnit(r),
- parseJson: (r) => JSON.parse(r),
- onLoad: (r, e) => {
- this._deserializeAutoFiltersForUnit(r, e), this._loadedUnitId$.next(r), this._updateActiveFilterModel();
- },
- onUnLoad: (r) => {
- const e = this._filterModels.get(r);
- e && (e.forEach((t) => t.dispose()), this._filterModels.delete(r));
- }
- });
- }
- _cacheFilterModel(r, e, t) {
- this._filterModels.has(r) || this._filterModels.set(r, /* @__PURE__ */ new Map()), this._filterModels.get(r).set(e, t);
- }
- };
- M = vt([
- J(0, Bi),
- J(1, _n),
- J(2, Pt)
- ], M);
- var R = {
- id: ce,
- type: ar.MUTATION,
- handler: (i, r) => {
- const { subUnitId: e, unitId: t, range: n } = r;
- return i.get(M).ensureFilterModel(t, e).setRange(n), true;
- }
- };
- var p = {
- id: de,
- type: ar.MUTATION,
- handler: (i, r) => {
- const { subUnitId: e, unitId: t, criteria: n, col: s, reCalc: o = true } = r, a = i.get(M).getFilterModel(t, e);
- return a ? (a.setCriteria(s, n, o), true) : false;
- }
- };
- var O = {
- id: ue,
- type: ar.MUTATION,
- handler: (i, r) => {
- const { unitId: e, subUnitId: t } = r;
- return i.get(M).removeFilterModel(e, t);
- }
- };
- var H = {
- id: he,
- type: ar.MUTATION,
- handler: (i, r) => {
- const { unitId: e, subUnitId: t } = r, s = i.get(M).getFilterModel(e, t);
- return s ? (s.reCalc(), true) : false;
- }
- };
- function Mt(i, r) {
- for (let e = 0; e < i.length; e++) {
- let t = e;
- if (i[e])
- for (let n = e + 1; n < i.length; n++)
- i[t] && i[n] && r(i[t], i[n]) && (i[t] = null, t = n);
- }
- return i.filter((e) => e !== null);
- }
- function I(i) {
- return Mt(i, (r, e) => r.id === p.id && e.id === p.id && r.params.unitId === e.params.unitId && r.params.subUnitId === e.params.subUnitId && r.params.col === e.params.col);
- }
- var Et = Object.defineProperty;
- var Ot2 = Object.getOwnPropertyDescriptor;
- var yt = (i, r, e, t) => {
- for (var n = t > 1 ? void 0 : t ? Ot2(r, e) : r, s = i.length - 1, o; s >= 0; s--)
- (o = i[s]) && (n = (t ? o(r, e, n) : o(n)) || n);
- return t && n && Et(r, e, n), n;
- };
- var P = (i, r) => (e, t) => r(e, t, i);
- var W = class extends nt {
- constructor(r, e, t, n, s) {
- super();
- w(this, "_disposableCollection", new Mi());
- this._commandService = r, this._sheetInterceptorService = e, this._sheetsFilterService = t, this._univerInstanceService = n, this._refRangeService = s, this._initCommands(), this._initRowFilteredInterceptor(), this._initInterceptors(), this._commandExecutedListener(), this._initErrorHandling();
- }
- _initCommands() {
- [
- p,
- R,
- H,
- O
- ].forEach((r) => this.disposeWithMe(this._commandService.registerCommand(r)));
- }
- _initInterceptors() {
- this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
- getMutations: (r) => this._getUpdateFilter(r)
- })), this.disposeWithMe(this._commandService.onCommandExecuted((r) => {
- if (r.id === an.id) {
- const e = r.params, t = e.subUnitId, n = e.unitId;
- if (!t || !n)
- return;
- this._registerRefRange(n, t);
- }
- if (r.id === R.id) {
- const e = r.params, t = e.subUnitId, n = e.unitId;
- if (!t || !n)
- return;
- this._registerRefRange(e.unitId, e.subUnitId);
- }
- })), this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe((r) => {
- if (r) {
- const e = this._univerInstanceService.getUniverSheetInstance(r), t = e == null ? void 0 : e.getActiveSheet();
- t && this._registerRefRange(r, t.getSheetId());
- }
- }));
- }
- _registerRefRange(r, e) {
- var l;
- this._disposableCollection.dispose();
- const t = this._univerInstanceService.getUniverSheetInstance(r), n = t == null ? void 0 : t.getSheetBySheetId(e);
- if (!t || !n)
- return;
- const s = (l = this._sheetsFilterService.getFilterModel(r, e)) == null ? void 0 : l.getRange(), o = (a) => {
- switch (a.id) {
- case mt.id: {
- const c = a.params, h = c.unitId || r, d = c.subUnitId || e;
- return this._handleInsertRowCommand(c, h, d);
- }
- case gt.id: {
- const c = a.params, h = c.unitId || r, d = c.subUnitId || e;
- return this._handleInsertColCommand(c, h, d);
- }
- case zn.id: {
- const c = a.params;
- return this._handleRemoveColCommand(c, r, e);
- }
- case Gn.id: {
- const c = a.params;
- return this._handleRemoveRowCommand(c, r, e);
- }
- case $.MoveColsCommandId: {
- const c = a.params;
- return this._handleMoveColsCommand(c, r, e);
- }
- case $.MoveRowsCommandId: {
- const c = a.params;
- return this._handleMoveRowsCommand(c, r, e);
- }
- case pt.id: {
- const c = a.params;
- return this._handleMoveRangeCommand(c, r, e);
- }
- }
- return { redos: [], undos: [] };
- };
- s && this._disposableCollection.add(this._refRangeService.registerRefRange(s, o, r, e));
- }
- _getUpdateFilter(r) {
- const { id: e } = r;
- switch (e) {
- case ko.id: {
- const t = r.params;
- return this._handleRemoveSheetCommand(t, t.unitId, t.subUnitId);
- }
- case xs.id: {
- const t = r.params, { targetSubUnitId: n, unitId: s, subUnitId: o } = t;
- return !s || !o || !n ? this._handleNull() : this._handleCopySheetCommand(s, o, n);
- }
- }
- return {
- redos: [],
- undos: []
- };
- }
- _handleInsertColCommand(r, e, t) {
- var _;
- const n = this._sheetsFilterService.getFilterModel(e, t), s = (_ = n == null ? void 0 : n.getRange()) != null ? _ : null;
- if (!n || !s)
- return this._handleNull();
- const { startColumn: o, endColumn: l } = s, { startColumn: a, endColumn: c } = r.range, h = c - a + 1;
- if (c > l)
- return this._handleNull();
- const d = [], u = [], m = a, g = {
- unitId: e,
- subUnitId: t,
- range: {
- ...s,
- startColumn: a <= o ? o + h : o,
- endColumn: l + h
- }
- }, C = {
- unitId: e,
- subUnitId: t,
- range: s
- };
- d.push({ id: R.id, params: g }), u.push({ id: R.id, params: C });
- const F2 = n.getAllFilterColumns().filter((f) => f[0] >= m);
- if (F2.length !== 0) {
- const { newRange: f, oldRange: v } = this.moveCriteria(e, t, F2, h);
- d.push(...f.redos, ...v.redos), u.push(...f.undos, ...v.undos);
- }
- return { redos: I(d), undos: I(u) };
- }
- _handleInsertRowCommand(r, e, t) {
- var C;
- const n = this._sheetsFilterService.getFilterModel(e, t), s = (C = n == null ? void 0 : n.getRange()) != null ? C : null;
- if (!n || !s)
- return this._handleNull();
- const { startRow: o, endRow: l } = s, { startRow: a, endRow: c } = r.range, h = c - a + 1;
- if (c > l)
- return this._handleNull();
- const d = [], u = [], m = {
- unitId: e,
- subUnitId: t,
- range: {
- ...s,
- startRow: a <= o ? o + h : o,
- endRow: l + h
- }
- }, g = {
- unitId: e,
- subUnitId: t,
- range: s
- };
- return d.push({ id: R.id, params: m }), u.push({ id: R.id, params: g }), {
- redos: I(d),
- undos: I(u)
- };
- }
- _handleRemoveColCommand(r, e, t) {
- var F2;
- const n = this._sheetsFilterService.getFilterModel(e, t), s = (F2 = n == null ? void 0 : n.getRange()) != null ? F2 : null;
- if (!n || !s)
- return this._handleNull();
- const { startColumn: o, endColumn: l } = s, { startColumn: a, endColumn: c } = r.range;
- if (a > l)
- return this._handleNull();
- const h = [], d = [], u = c < o ? 0 : Math.min(c, l) - Math.max(a, o) + 1, m = c - a + 1, g = n.getAllFilterColumns();
- g.forEach((_) => {
- const [f, v] = _;
- f <= c && f >= a && (h.push({ id: p.id, params: { unitId: e, subUnitId: t, col: f, criteria: null } }), d.push({ id: p.id, params: { unitId: e, subUnitId: t, col: f, criteria: { ...v.serialize(), colId: f } } }));
- });
- const C = g.filter((_) => {
- const [f, v] = _;
- return f > c;
- });
- let S = { undos: [], redos: [] };
- if (C.length > 0) {
- const { oldRange: _, newRange: f } = this.moveCriteria(e, t, C, -m);
- S = f, h.push(..._.redos), d.unshift(..._.undos);
- }
- if (u === l - o + 1) {
- const _ = {
- unitId: e,
- subUnitId: t
- };
- h.push({ id: O.id, params: _ }), d.unshift({ id: R.id, params: { range: s, unitId: e, subUnitId: t } });
- } else {
- const _ = o <= a ? o : u === 0 ? o - m : a, f = o <= a ? l - u : l - m, v = {
- unitId: e,
- subUnitId: t,
- range: { ...s, startColumn: _, endColumn: f }
- };
- h.push({ id: R.id, params: v }), d.unshift({ id: R.id, params: { range: s, unitId: e, subUnitId: t } }), h.push(...S.redos), d.unshift(...S.undos);
- }
- return {
- undos: d,
- redos: h
- };
- }
- _handleRemoveRowCommand(r, e, t) {
- var C;
- const n = this._sheetsFilterService.getFilterModel(e, t);
- if (!n)
- return this._handleNull();
- const s = n.getRange(), { startRow: o, endRow: l } = s, { startRow: a, endRow: c } = r.range;
- if (a > l)
- return this._handleNull();
- if (c < o)
- return {
- undos: [{ id: R.id, params: { range: s, unitId: e, subUnitId: t } }],
- redos: [{
- id: R.id,
- params: {
- range: {
- ...s,
- startRow: o - (c - a + 1),
- endRow: l - (c - a + 1)
- },
- unitId: e,
- subUnitId: t
- }
- }]
- };
- const h = [], d = [], u = n.getAllFilterColumns(), m = o <= c && o >= a;
- d.push({ id: R.id, params: { range: s, unitId: e, subUnitId: t } });
- const g = Math.min(c, l) - Math.max(a, o) + 1;
- if (g === l - o + 1 || m) {
- const S = {
- unitId: e,
- subUnitId: t
- };
- h.push({ id: O.id, params: S }), u.forEach((F2) => {
- const [_, f] = F2, v = {
- unitId: e,
- subUnitId: t,
- col: _,
- criteria: { ...f.serialize(), colId: _ }
- };
- d.push({ id: p.id, params: v });
- });
- } else {
- const S = (C = this._univerInstanceService.getUniverSheetInstance(e)) == null ? void 0 : C.getSheetBySheetId(t);
- if (!S)
- return this._handleNull();
- const F2 = [];
- for (let y = a; y <= c; y++)
- S.getRowFiltered(y) && F2.push(y);
- const _ = Math.min(o, a), f = _ + (l - o) - g + F2.length, v = {
- unitId: e,
- subUnitId: t,
- range: {
- ...s,
- startRow: _,
- endRow: f
- }
- };
- h.push({ id: R.id, params: v });
- }
- return {
- undos: I(d),
- redos: I(h)
- };
- }
- // eslint-disable-next-line max-lines-per-function
- _handleMoveColsCommand(r, e, t) {
- var _;
- const n = this._sheetsFilterService.getFilterModel(e, t), s = (_ = n == null ? void 0 : n.getRange()) != null ? _ : null;
- if (!n || !s)
- return this._handleNull();
- const { startColumn: o, endColumn: l } = s, { fromRange: a, toRange: c } = r;
- if (a.endColumn < o && c.startColumn <= o || a.startColumn > l && c.endColumn > l)
- return this._handleNull();
- const h = [], d = [], u = {};
- for (let f = o; f <= l; f++)
- u[f] = {
- colIndex: f,
- filter: n.getFilterColumn(f)
- };
- Ko(a.startColumn, a.endColumn - a.startColumn + 1, c.startColumn, u);
- let m = s.startColumn, g = s.endColumn;
- o >= a.startColumn && o <= a.endColumn && c.startColumn > a.startColumn && a.endColumn < l && (m = a.endColumn + 1), l >= a.startColumn && l <= a.endColumn && c.startColumn < a.startColumn && a.startColumn > o && (g = a.startColumn - 1);
- const C = Object.keys(u).map((f) => Number(f)), S = C.find((f) => u[f].colIndex === g), F2 = C.find((f) => u[f].colIndex === m);
- if (C.forEach((f) => {
- var X, Z;
- const { colIndex: v, filter: y } = u[f], A = f;
- if (y) {
- if (A >= F2 && A <= S) {
- const q = {
- unitId: e,
- subUnitId: t,
- col: A,
- criteria: { ...y.serialize(), colId: A }
- }, pe = {
- unitId: e,
- subUnitId: t,
- col: A,
- criteria: n.getFilterColumn(A) ? { ...(X = n.getFilterColumn(A)) == null ? void 0 : X.serialize(), colId: A } : null
- };
- h.push({ id: p.id, params: q }), d.push({ id: p.id, params: pe });
- }
- if (!((Z = u[v]) != null && Z.filter)) {
- const q = {
- unitId: e,
- subUnitId: t,
- col: v,
- criteria: null
- };
- h.push({ id: p.id, params: q }), d.push({ id: p.id, params: { unitId: e, subUnitId: t, col: v, criteria: { ...y.serialize(), colId: v } } });
- }
- }
- }), o !== F2 || l !== S) {
- const f = {
- unitId: e,
- subUnitId: t,
- range: {
- ...s,
- startColumn: F2,
- endColumn: S
- }
- };
- h.unshift({ id: R.id, params: f }), d.unshift({ id: R.id, params: { range: s, unitId: e, subUnitId: t } });
- }
- return {
- undos: d,
- redos: h
- };
- }
- _handleMoveRowsCommand(r, e, t) {
- var _;
- const n = this._sheetsFilterService.getFilterModel(e, t), s = (_ = n == null ? void 0 : n.getRange()) != null ? _ : null;
- if (!n || !s)
- return this._handleNull();
- const { startRow: o, endRow: l } = s, { fromRange: a, toRange: c } = r;
- if (a.endRow < o && c.startRow <= o || a.startRow > l && c.endRow > l)
- return this._handleNull();
- const h = [], d = [], u = {};
- for (let f = o; f <= l; f++)
- u[f] = {
- oldIndex: f
- };
- const m = o;
- let g = l;
- l >= a.startRow && l <= a.endRow && c.startRow < a.startRow && a.startRow > o && (g = a.startRow - 1), Ko(a.startRow, a.endRow - a.startRow + 1, c.startRow, u);
- const C = Object.keys(u).map((f) => Number(f)), S = C.find((f) => u[f].oldIndex === g), F2 = C.find((f) => u[f].oldIndex === m);
- if (o !== F2 || l !== S) {
- const f = {
- unitId: e,
- subUnitId: t,
- range: {
- ...s,
- startRow: F2,
- endRow: S
- }
- };
- h.push({ id: R.id, params: f }, { id: H.id, params: { unitId: e, subUnitId: t } }), d.push({ id: R.id, params: { range: s, unitId: e, subUnitId: t } }, { id: H.id, params: { unitId: e, subUnitId: t } });
- }
- return {
- redos: h,
- undos: d
- };
- }
- _handleMoveRangeCommand(r, e, t) {
- const { fromRange: n, toRange: s } = r, o = this._sheetsFilterService.getFilterModel(e, t);
- if (!o)
- return this._handleNull();
- const l = o.getRange();
- if (!l)
- return this._handleNull();
- const a = [], c = [];
- if (en.contains(n, l)) {
- const h = l.startRow - n.startRow, d = l.startColumn - n.startColumn, u = {
- startRow: s.startRow + h,
- startColumn: s.startColumn + d,
- endRow: s.startRow + h + (l.endRow - l.startRow),
- endColumn: s.startColumn + d + (l.endColumn - l.startColumn)
- }, m = {
- id: O.id,
- params: {
- unitId: e,
- subUnitId: t
- }
- }, g = { id: R.id, params: { unitId: e, subUnitId: t, range: u } }, C = { id: R.id, params: { unitId: e, subUnitId: t, range: l } };
- a.push(m, g), c.push(m, C);
- const S = o.getAllFilterColumns(), F2 = s.startColumn - n.startColumn;
- S.forEach((_) => {
- const [f, v] = _;
- v && (a.push({ id: p.id, params: { unitId: e, subUnitId: t, col: f + F2, criteria: { ...v.serialize(), colId: f + F2 } } }), c.push({ id: p.id, params: { unitId: e, subUnitId: t, col: f, criteria: { ...v.serialize(), colId: f } } }));
- });
- } else if (en.intersects(s, l)) {
- const h = {
- ...l,
- endRow: Math.max(l.endRow, s.endRow)
- };
- a.push({ id: R.id, params: { unitId: e, subUnitId: t, range: h } }), c.push({ id: R.id, params: { unitId: e, subUnitId: t, range: l } });
- }
- return {
- redos: a,
- undos: c
- };
- }
- _handleRemoveSheetCommand(r, e, t) {
- const n = this._sheetsFilterService.getFilterModel(e, t);
- if (!n)
- return this._handleNull();
- const s = n.getRange();
- if (!s)
- return this._handleNull();
- const o = [], l = [];
- return n.getAllFilterColumns().forEach(([c, h]) => {
- l.push({ id: p.id, params: { unitId: e, subUnitId: t, col: c, criteria: { ...h.serialize(), colId: c } } });
- }), o.push({ id: O.id, params: { unitId: e, subUnitId: t, range: s } }), l.unshift({ id: R.id, params: { range: s, unitId: e, subUnitId: t } }), {
- undos: l,
- redos: o
- };
- }
- _handleCopySheetCommand(r, e, t) {
- const n = this._sheetsFilterService.getFilterModel(r, e);
- if (!n)
- return this._handleNull();
- const s = n.getRange();
- if (!s)
- return this._handleNull();
- const o = [], l = [], a = [], c = [];
- return n.getAllFilterColumns().forEach(([d, u]) => {
- o.push({ id: p.id, params: { unitId: r, subUnitId: t, col: d, criteria: { ...u.serialize(), colId: d } } }), a.push({ id: p.id, params: { unitId: r, subUnitId: t, col: d, criteria: null } });
- }), a.push({ id: O.id, params: { unitId: r, subUnitId: t, range: s } }), o.unshift({ id: R.id, params: { range: s, unitId: r, subUnitId: t } }), {
- undos: l,
- redos: o,
- preUndos: a,
- preRedos: c
- };
- }
- _handleNull() {
- return { redos: [], undos: [] };
- }
- _initRowFilteredInterceptor() {
- this.disposeWithMe(this._sheetInterceptorService.intercept(et.ROW_FILTERED, {
- // sheet-interceptor.service.ts
- handler: (r, e) => {
- var t, n;
- return r ? true : (n = (t = this._sheetsFilterService.getFilterModel(
- e.unitId,
- e.subUnitId
- )) == null ? void 0 : t.isRowFiltered(e.row)) != null ? n : false;
- }
- }));
- }
- moveCriteria(r, e, t, n) {
- const s = {
- unitId: r,
- subUnitId: e,
- criteria: null,
- col: -1
- }, o = [], l = [], a = [], c = [];
- return t.forEach((h) => {
- const [d, u] = h;
- l.push({
- id: p.id,
- params: {
- ...s,
- col: d
- }
- }), o.push({
- id: p.id,
- params: {
- ...s,
- col: d,
- criteria: { ...u.serialize(), colId: d }
- }
- });
- }), t.forEach((h) => {
- const [d, u] = h;
- c.push({
- id: p.id,
- params: {
- ...s,
- col: d + n,
- criteria: { ...u.serialize(), colId: d + n }
- }
- }), a.push({
- id: p.id,
- params: {
- ...s,
- col: d + n,
- criteria: null
- }
- });
- }), {
- newRange: {
- redos: c,
- undos: a
- },
- oldRange: {
- redos: l,
- undos: o
- }
- };
- }
- _commandExecutedListener() {
- this.disposeWithMe(this._commandService.onCommandExecuted((r, e) => {
- var c, h;
- const { unitId: t, subUnitId: n } = r.params || {}, s = this._sheetsFilterService.getFilterModel(t, n);
- if (!s)
- return;
- const o = Array.from(s.filteredOutRows).sort((d, u) => d - u), l = [];
- let a = false;
- if (r.id === Be.id) {
- const { startRow: d, endRow: u } = r.params.range, m = o.filter((g) => g >= d && g <= u);
- o.forEach((g) => {
- if (g < d)
- l.push(g);
- else if (a = true, g <= u) {
- const C = Math.max(d, l.length ? l[l.length - 1] + 1 : d);
- l.push(C);
- } else
- l.push(g - (u - d + 1 - m.length));
- });
- }
- if (r.id === qe.id) {
- const { startRow: d, endRow: u } = r.params.range;
- o.forEach((m) => {
- m >= d ? (a = true, l.push(m + (u - d + 1))) : l.push(m);
- });
- }
- if (a && (s.filteredOutRows = new Set(l)), r.id === Q.id && !(e != null && e.onlyLocal)) {
- const d = this._getExtendRegion(t, n);
- if (d) {
- const u = r.params.cellValue;
- if (u)
- for (let m = d.startColumn; m <= d.endColumn; m++) {
- const g = (c = u == null ? void 0 : u[d.startRow]) == null ? void 0 : c[m];
- if (g && this._cellHasValue(g)) {
- const C = (h = this._univerInstanceService.getUnit(t)) == null ? void 0 : h.getSheetBySheetId(n);
- if (C) {
- const S = Mh(d, { down: true }, C), F2 = this._sheetsFilterService.getFilterModel(t, n), _ = F2.getRange();
- F2.setRange({
- ..._,
- endRow: S.endRow
- }), this._registerRefRange(t, n);
- }
- }
- }
- }
- }
- }));
- }
- _getExtendRegion(r, e) {
- var a;
- const t = this._sheetsFilterService.getFilterModel(r, e);
- if (!t)
- return null;
- const n = (a = this._univerInstanceService.getUnit(r)) == null ? void 0 : a.getSheetBySheetId(e);
- if (!n)
- return null;
- const s = t.getRange();
- if (!s)
- return null;
- const o = n.getRowCount() - 1, l = n.getRowManager();
- for (let c = s.endRow + 1; c <= o; c++)
- if (l.getRowRawVisible(c))
- return {
- startRow: c,
- endRow: c,
- startColumn: s.startColumn,
- endColumn: s.endColumn
- };
- return null;
- }
- _initErrorHandling() {
- this.disposeWithMe(this._commandService.beforeCommandExecuted((r) => {
- const e = r.params, t = N(this._univerInstanceService);
- if (!t)
- return;
- const { subUnitId: n, unitId: s } = t, o = this._sheetsFilterService.getFilterModel(s, n);
- if (!o)
- return;
- const l = o.getRange();
- if (r.id === Fn.id && e.fromRange.startRow <= l.startRow && e.fromRange.endRow < l.endRow && e.fromRange.endRow >= l.startRow)
- throw this._sheetsFilterService.setFilterErrorMsg("sheets-filter.msg.filter-header-forbidden"), new Error("[SheetsFilterController]: Cannot move header row of filter");
- }));
- }
- _cellHasValue(r) {
- const e = Object.values(r);
- return !(e.length === 0 || e.every((t) => t == null));
- }
- };
- W = yt([
- P(0, Pt),
- P(1, ot(V)),
- P(2, ot(M)),
- P(3, _n),
- P(4, ot(_t))
- ], W);
- var At = Object.defineProperty;
- var Tt = Object.getOwnPropertyDescriptor;
- var Nt = (i, r, e, t) => {
- for (var n = t > 1 ? void 0 : t ? Tt(r, e) : r, s = i.length - 1, o; s >= 0; s--)
- (o = i[s]) && (n = (t ? o(r, e, n) : o(n)) || n);
- return t && n && At(r, e, n), n;
- };
- var oe = (i, r) => (e, t) => r(e, t, i);
- var B;
- var le = (B = class extends Ra {
- constructor(i = re2, r, e) {
- super(), this._config = i, this._injector = r, this._configService = e;
- const { ...t } = nu(
- {},
- re2,
- this._config
- );
- this._configService.setConfig(tt, t);
- }
- onStarting() {
- [
- [M],
- [W]
- ].forEach((i) => this._injector.add(i));
- }
- onReady() {
- this._injector.get(W);
- }
- }, w(B, "type", Fe.UNIVER_SHEET), w(B, "pluginName", Re), B);
- le = Nt([
- oe(1, ot(Ot)),
- oe(2, SE)
- ], le);
- var xt = {
- id: "sheet.command.set-filter-range",
- type: ar.COMMAND,
- handler: (i, r) => {
- const e = i.get(M), t = i.get(Pt), n = i.get(cn), s = i.get(_n), { unitId: o, subUnitId: l, range: a } = r;
- if (!N(s, r) || e.getFilterModel(o, l))
- return false;
- if (a.endRow === a.startRow) {
- const m = i.get(NE), g = i.get(Vr);
- return m.emit(g.t("sheets-filter.command.not-valid-filter-range")), false;
- }
- const d = { id: R.id, params: { unitId: o, subUnitId: l, range: a } }, u = t.syncExecuteCommand(d.id, d.params);
- return u && n.pushUndoRedo({
- unitID: o,
- undoMutations: [{ id: O.id, params: { unitId: o, subUnitId: l } }],
- redoMutations: [d]
- }), u;
- }
- };
- var It = {
- id: "sheet.command.remove-sheet-filter",
- type: ar.COMMAND,
- handler: (i, r) => {
- const e = i.get(_n), t = i.get(M), n = i.get(Pt), s = i.get(cn), o = N(e, r);
- if (!o)
- return false;
- const { unitId: l, subUnitId: a } = o, c = t.getFilterModel(l, a);
- if (!c)
- return false;
- const h = c == null ? void 0 : c.serialize(), d = $t(l, a, h), u = n.syncExecuteCommand(O.id, { unitId: l, subUnitId: a });
- return u && s.pushUndoRedo({
- unitID: l,
- undoMutations: d,
- redoMutations: [{ id: O.id, params: { unitId: l, subUnitId: a } }]
- }), u;
- }
- };
- var Ht = {
- id: "sheet.command.smart-toggle-filter",
- type: ar.COMMAND,
- handler: async (i) => {
- const r = i.get(_n), e = i.get(M), t = i.get(Pt), n = r.getCurrentUnitForType(Fe.UNIVER_SHEET), s = n == null ? void 0 : n.getActiveSheet();
- if (!s || !n)
- return false;
- const o = n.getUnitId(), l = s.getSheetId();
- if (e.getFilterModel(o, l))
- return t.executeCommand(It.id, { unitId: o, subUnitId: l });
- const h = i.get(F).getCurrentLastSelection();
- if (!h)
- return false;
- const d = h.range, u = Jd(h) ? Mh(d, { left: true, right: true, up: true, down: true }, s) : d;
- return t.executeCommand(xt.id, {
- unitId: o,
- subUnitId: l,
- range: u
- });
- }
- };
- var Dt = {
- id: "sheet.command.set-filter-criteria",
- type: ar.COMMAND,
- handler: (i, r) => {
- const e = i.get(M), t = i.get(Pt), n = i.get(cn), { unitId: s, subUnitId: o, col: l, criteria: a } = r, c = e.getFilterModel(s, o);
- if (!c)
- return false;
- const h = c.getRange();
- if (!h || l < h.startColumn || l > h.endColumn)
- return false;
- const d = c.getFilterColumn(l), u = Ut(s, o, l, d), m = {
- id: p.id,
- params: {
- unitId: s,
- subUnitId: o,
- col: l,
- criteria: a
- }
- }, g = t.syncExecuteCommand(m.id, m.params);
- return g && n.pushUndoRedo({
- unitID: s,
- undoMutations: [u],
- redoMutations: [m]
- }), g;
- }
- };
- var Wt = {
- id: "sheet.command.clear-filter-criteria",
- type: ar.COMMAND,
- handler: (i, r) => {
- const e = i.get(M), t = i.get(cn), n = i.get(Pt), s = i.get(_n), o = N(s, r);
- if (!o)
- return false;
- const { unitId: l, subUnitId: a } = o, c = e.getFilterModel(o.unitId, o.subUnitId);
- if (!c)
- return false;
- const h = c.serialize(), d = Ce(l, a, h), u = Pt2(l, a, h);
- return mu(u, n).result ? (t.pushUndoRedo({
- unitID: l,
- undoMutations: d,
- redoMutations: u
- }), true) : false;
- }
- };
- var Vt = {
- id: "sheet.command.re-calc-filter",
- type: ar.COMMAND,
- handler: (i, r) => {
- const e = i.get(M), t = i.get(Pt), n = i.get(_n), s = N(n, r);
- if (!s)
- return false;
- const { unitId: o, subUnitId: l } = s;
- return e.getFilterModel(s.unitId, s.subUnitId) ? t.executeCommand(H.id, { unitId: o, subUnitId: l }) : false;
- }
- };
- function $t(i, r, e) {
- const t = [], n = {
- id: R.id,
- params: {
- unitId: i,
- subUnitId: r,
- range: e.ref
- }
- };
- return t.push(n), Ce(i, r, e).forEach((o) => t.push(o)), t;
- }
- function Ce(i, r, e) {
- var n;
- const t = [];
- return (n = e.filterColumns) == null || n.forEach((s) => {
- const o = {
- id: p.id,
- params: {
- unitId: i,
- subUnitId: r,
- col: s.colId,
- criteria: s
- }
- };
- t.push(o);
- }), t;
- }
- function Pt2(i, r, e) {
- var n;
- const t = [];
- return (n = e.filterColumns) == null || n.forEach((s) => {
- const o = {
- id: p.id,
- params: {
- unitId: i,
- subUnitId: r,
- col: s.colId,
- criteria: null
- }
- };
- t.push(o);
- }), t;
- }
- function Ut(i, r, e, t) {
- if (!t)
- return {
- id: p.id,
- params: {
- unitId: i,
- subUnitId: r,
- col: e,
- criteria: null
- }
- };
- const n = t.serialize();
- return {
- id: p.id,
- params: {
- unitId: i,
- subUnitId: r,
- col: e,
- criteria: n
- }
- };
- }
- export {
- rt,
- N2 as N,
- nt2 as nt,
- it,
- st,
- ot2 as ot,
- lt,
- fe,
- ne,
- D,
- ht,
- Re,
- M,
- R,
- p,
- O,
- H,
- le,
- xt,
- It,
- Ht,
- Dt,
- Wt,
- Vt
- };
- //# sourceMappingURL=chunk-KSOBIBXF.js.map
|