@univerjs/sheets-data-validation 0.5.4 → 0.5.5-experimental.20250122-3362a4a

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.
package/lib/es/index.js CHANGED
@@ -1,448 +1,455 @@
1
- var Rt = Object.defineProperty;
2
- var St = (s, a, e) => a in s ? Rt(s, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[a] = e;
3
- var f = (s, a, e) => St(s, typeof a != "symbol" ? a + "" : a, e);
4
- import { Inject as S, ICommandService as x, IUniverInstanceService as O, Disposable as $, ObjectMatrix as ve, UniverInstanceType as N, Range as b, isFormulaString as v, DataValidationType as T, getOriginCellValue as vt, RBush as Vt, debounce as Mt, Rectangle as I, Tools as V, DataValidationStatus as D, WrapStrategy as Se, DataValidationOperator as h, numfmt as Q, dayjs as at, DataValidationRenderMode as Be, CommandType as K, IUndoRedoService as z, sequenceExecute as Ie, isRangesEqual as rt, generateRandomId as yt, toDisposable as qe, IPermissionService as Et, Injector as Ge, CellValueType as Tt, RxDisposable as Ft, LifecycleService as Nt, LifecycleStages as ze, bufferDebounceTime as Ct, DependentOn as Ot, Plugin as wt, merge as It, IConfigService as At } from "@univerjs/core";
5
- import { DataValidationModel as ke, DataValidatorRegistryService as G, UpdateRuleType as y, BaseDataValidator as k, TextLengthErrorTitleMap as Dt, AddDataValidationMutation as L, RemoveDataValidationMutation as A, UpdateDataValidationMutation as E, getRuleSetting as bt, getRuleOptions as Lt, UniverDataValidationPlugin as xt } from "@univerjs/data-validation";
6
- import { SetRangeValuesMutation as oe, RemoveSheetMutation as it, getSheetCommandTarget as Ye, SetRangeValuesUndoMutationFactory as st, WorksheetViewPermission as Bt, RefRangeService as Ut, handleCommonDefaultRangeChangeWithEffectRefCommands as Pt, SheetInterceptorService as ot, RemoveSheetCommand as $t, SheetsSelectionsService as nt, ClearSelectionAllCommand as Ht } from "@univerjs/sheets";
7
- import { Subject as Qe, bufferWhen as Wt, filter as Ze } from "rxjs";
8
- import { RegisterOtherFormulaService as lt, FormulaRefRangeService as ut } from "@univerjs/sheets-formula";
9
- import { ERROR_TYPE_SET as jt, LexerTreeBuilder as Z, isReferenceString as dt, sequenceNodeType as Qt, deserializeRangeWithSheet as qt, deserializeRangeWithSheetWithCache as Gt } from "@univerjs/engine-formula";
10
- const kt = "SHEET_DATA_VALIDATION_PLUGIN";
11
- var Yt = Object.defineProperty, Xt = Object.getOwnPropertyDescriptor, Kt = (s, a, e, t) => {
12
- for (var r = t > 1 ? void 0 : t ? Xt(a, e) : a, i = s.length - 1, o; i >= 0; i--)
13
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
14
- return t && r && Yt(a, e, r), r;
15
- }, Je = (s, a) => (e, t) => a(e, t, s);
16
- let q = class extends $ {
17
- constructor(a, e) {
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
+ import { Inject, ICommandService, IUniverInstanceService, Disposable, ObjectMatrix, UniverInstanceType, Range, isFormulaString, DataValidationType, getOriginCellValue, RBush, debounce, Rectangle, Tools, DataValidationStatus, WrapStrategy, DataValidationOperator, numfmt, dayjs, DataValidationRenderMode, CommandType, IUndoRedoService, sequenceExecute, isRangesEqual, generateRandomId, toDisposable, IPermissionService, Injector, CellValueType, RxDisposable, LifecycleService, LifecycleStages, bufferDebounceTime, DependentOn, Plugin, merge, IConfigService } from "@univerjs/core";
6
+ import { DataValidationModel, DataValidatorRegistryService, UpdateRuleType, BaseDataValidator, TextLengthErrorTitleMap, AddDataValidationMutation, RemoveDataValidationMutation, UpdateDataValidationMutation, getRuleSetting, getRuleOptions, UniverDataValidationPlugin } from "@univerjs/data-validation";
7
+ import { SetRangeValuesMutation, RemoveSheetMutation, getSheetCommandTarget, SetRangeValuesUndoMutationFactory, WorksheetViewPermission, RefRangeService, handleCommonDefaultRangeChangeWithEffectRefCommands, SheetInterceptorService, RemoveSheetCommand, SheetsSelectionsService, ClearSelectionAllCommand } from "@univerjs/sheets";
8
+ import { Subject, bufferWhen, filter } from "rxjs";
9
+ import { RegisterOtherFormulaService, FormulaRefRangeService } from "@univerjs/sheets-formula";
10
+ import { ERROR_TYPE_SET, LexerTreeBuilder, isReferenceString, sequenceNodeType, deserializeRangeWithSheet, deserializeRangeWithSheetWithCache, operatorToken } from "@univerjs/engine-formula";
11
+ const DATA_VALIDATION_PLUGIN_NAME = "SHEET_DATA_VALIDATION_PLUGIN";
12
+ var __defProp$a = Object.defineProperty, __getOwnPropDesc$a = Object.getOwnPropertyDescriptor, __decorateClass$a = /* @__PURE__ */ __name((decorators, target, key, kind) => {
13
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
14
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
15
+ return kind && result && __defProp$a(target, key, result), result;
16
+ }, "__decorateClass$a"), __decorateParam$a = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$a"), _a;
17
+ let DataValidationCacheService = (_a = class extends Disposable {
18
+ constructor(_commandService, _univerInstanceService) {
18
19
  super();
19
- f(this, "_cacheMatrix", /* @__PURE__ */ new Map());
20
- f(this, "_dirtyRanges$", new Qe());
21
- f(this, "dirtyRanges$", this._dirtyRanges$.asObservable());
22
- this._commandService = a, this._univerInstanceService = e, this._initDirtyRanges(), this._initSheetRemove();
20
+ __publicField(this, "_cacheMatrix", /* @__PURE__ */ new Map());
21
+ __publicField(this, "_dirtyRanges$", new Subject());
22
+ __publicField(this, "dirtyRanges$", this._dirtyRanges$.asObservable());
23
+ this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._initDirtyRanges(), this._initSheetRemove();
23
24
  }
24
25
  _initDirtyRanges() {
25
- this.disposeWithMe(this._commandService.onCommandExecuted((a) => {
26
- if (a.id === oe.id) {
27
- const { cellValue: e, unitId: t, subUnitId: r } = a.params;
28
- if (e) {
29
- const i = new ve(e).getDataRange();
30
- if (i.endRow === -1) return;
31
- this.markRangeDirty(t, r, [i]);
26
+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
27
+ if (commandInfo.id === SetRangeValuesMutation.id) {
28
+ const { cellValue, unitId, subUnitId } = commandInfo.params;
29
+ if (cellValue) {
30
+ const range = new ObjectMatrix(cellValue).getDataRange();
31
+ if (range.endRow === -1) return;
32
+ this.markRangeDirty(unitId, subUnitId, [range]);
32
33
  }
33
34
  }
34
35
  }));
35
36
  }
36
37
  _initSheetRemove() {
37
- this.disposeWithMe(this._commandService.onCommandExecuted((a) => {
38
- var e;
39
- if (a.id === it.id) {
40
- const { unitId: t, subUnitId: r } = a.params;
41
- (e = this._cacheMatrix.get(t)) == null || e.delete(r);
38
+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
39
+ var _a12;
40
+ if (commandInfo.id === RemoveSheetMutation.id) {
41
+ const { unitId, subUnitId } = commandInfo.params;
42
+ (_a12 = this._cacheMatrix.get(unitId)) == null || _a12.delete(subUnitId);
42
43
  }
43
- })), this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((a) => {
44
- a.type === N.UNIVER_SHEET && this._cacheMatrix.delete(a.getUnitId());
44
+ })), this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((univerInstance) => {
45
+ univerInstance.type === UniverInstanceType.UNIVER_SHEET && this._cacheMatrix.delete(univerInstance.getUnitId());
45
46
  }));
46
47
  }
47
- _ensureCache(a, e) {
48
- let t = this._cacheMatrix.get(a);
49
- t || (t = /* @__PURE__ */ new Map(), this._cacheMatrix.set(a, t));
50
- let r = t.get(e);
51
- return r || (r = new ve(), t.set(e, r)), r;
48
+ _ensureCache(unitId, subUnitId) {
49
+ let unitMap = this._cacheMatrix.get(unitId);
50
+ unitMap || (unitMap = /* @__PURE__ */ new Map(), this._cacheMatrix.set(unitId, unitMap));
51
+ let cacheMatrix = unitMap.get(subUnitId);
52
+ return cacheMatrix || (cacheMatrix = new ObjectMatrix(), unitMap.set(subUnitId, cacheMatrix)), cacheMatrix;
52
53
  }
53
- ensureCache(a, e) {
54
- return this._ensureCache(a, e);
54
+ ensureCache(unitId, subUnitId) {
55
+ return this._ensureCache(unitId, subUnitId);
55
56
  }
56
- addRule(a, e, t) {
57
- this.markRangeDirty(a, e, t.ranges);
57
+ addRule(unitId, subUnitId, rule) {
58
+ this.markRangeDirty(unitId, subUnitId, rule.ranges);
58
59
  }
59
- removeRule(a, e, t) {
60
- this._deleteRange(a, e, t.ranges);
60
+ removeRule(unitId, subUnitId, rule) {
61
+ this._deleteRange(unitId, subUnitId, rule.ranges);
61
62
  }
62
- markRangeDirty(a, e, t) {
63
- const r = this._ensureCache(a, e);
64
- t.forEach((i) => {
65
- b.foreach(i, (o, n) => {
66
- r.setValue(o, n, void 0);
63
+ markRangeDirty(unitId, subUnitId, ranges) {
64
+ const cache = this._ensureCache(unitId, subUnitId);
65
+ ranges.forEach((range) => {
66
+ Range.foreach(range, (row, col) => {
67
+ cache.setValue(row, col, void 0);
67
68
  });
68
- }), this._dirtyRanges$.next({ unitId: a, subUnitId: e, ranges: t });
69
+ }), this._dirtyRanges$.next({ unitId, subUnitId, ranges });
69
70
  }
70
- _deleteRange(a, e, t) {
71
- const r = this._ensureCache(a, e);
72
- t.forEach((i) => {
73
- b.foreach(i, (o, n) => {
74
- r.realDeleteValue(o, n);
71
+ _deleteRange(unitId, subUnitId, ranges) {
72
+ const cache = this._ensureCache(unitId, subUnitId);
73
+ ranges.forEach((range) => {
74
+ Range.foreach(range, (row, col) => {
75
+ cache.realDeleteValue(row, col);
75
76
  });
76
- }), this._dirtyRanges$.next({ unitId: a, subUnitId: e, ranges: t });
77
- }
78
- getValue(a, e, t, r) {
79
- return this._ensureCache(a, e).getValue(t, r);
80
- }
81
- };
82
- q = Kt([
83
- Je(0, S(x)),
84
- Je(1, S(O))
85
- ], q);
86
- function se(s) {
87
- var a, e;
88
- return (e = (a = s == null ? void 0 : s[0]) == null ? void 0 : a[0]) == null ? void 0 : e.v;
77
+ }), this._dirtyRanges$.next({ unitId, subUnitId, ranges });
78
+ }
79
+ getValue(unitId, subUnitId, row, col) {
80
+ return this._ensureCache(unitId, subUnitId).getValue(row, col);
81
+ }
82
+ }, __name(_a, "DataValidationCacheService"), _a);
83
+ DataValidationCacheService = __decorateClass$a([
84
+ __decorateParam$a(0, Inject(ICommandService)),
85
+ __decorateParam$a(1, Inject(IUniverInstanceService))
86
+ ], DataValidationCacheService);
87
+ function getFormulaResult(result) {
88
+ var _a12, _b;
89
+ return (_b = (_a12 = result == null ? void 0 : result[0]) == null ? void 0 : _a12[0]) == null ? void 0 : _b.v;
89
90
  }
90
- function ge(s) {
91
- var a;
92
- return (a = s == null ? void 0 : s[0]) == null ? void 0 : a[0];
91
+ __name(getFormulaResult, "getFormulaResult");
92
+ function getFormulaCellData(result) {
93
+ var _a12;
94
+ return (_a12 = result == null ? void 0 : result[0]) == null ? void 0 : _a12[0];
93
95
  }
94
- function C(s) {
95
- return !jt.has(s);
96
+ __name(getFormulaCellData, "getFormulaCellData");
97
+ function isLegalFormulaResult(res) {
98
+ return !ERROR_TYPE_SET.has(res);
96
99
  }
97
- function de(s, a) {
98
- var t;
99
- const e = a.getValidatorItem(s);
100
- return (t = e == null ? void 0 : e.offsetFormulaByRange) != null ? t : !1;
100
+ __name(isLegalFormulaResult, "isLegalFormulaResult");
101
+ function shouldOffsetFormulaByRange(type, validatorRegistryService) {
102
+ var _a12;
103
+ const validator = validatorRegistryService.getValidatorItem(type);
104
+ return (_a12 = validator == null ? void 0 : validator.offsetFormulaByRange) != null ? _a12 : !1;
101
105
  }
102
- var zt = Object.defineProperty, Zt = Object.getOwnPropertyDescriptor, Jt = (s, a, e, t) => {
103
- for (var r = t > 1 ? void 0 : t ? Zt(a, e) : a, i = s.length - 1, o; i >= 0; i--)
104
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
105
- return t && r && zt(a, e, r), r;
106
- }, re = (s, a) => (e, t) => a(e, t, s);
107
- let P = class extends $ {
108
- constructor(a, e, t, r, i) {
106
+ __name(shouldOffsetFormulaByRange, "shouldOffsetFormulaByRange");
107
+ var __defProp$9 = Object.defineProperty, __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor, __decorateClass$9 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
108
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
109
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
110
+ return kind && result && __defProp$9(target, key, result), result;
111
+ }, "__decorateClass$9"), __decorateParam$9 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$9"), _a2;
112
+ let DataValidationCustomFormulaService = (_a2 = class extends Disposable {
113
+ constructor(_instanceSrv, _registerOtherFormulaService, _dataValidationModel, _dataValidationCacheService, _validatorRegistryService) {
109
114
  super();
110
115
  /**
111
116
  * Map of origin formula of rule
112
117
  */
113
- f(this, "_ruleFormulaMap", /* @__PURE__ */ new Map());
114
- f(this, "_ruleFormulaMap2", /* @__PURE__ */ new Map());
115
- this._instanceSrv = a, this._registerOtherFormulaService = e, this._dataValidationModel = t, this._dataValidationCacheService = r, this._validatorRegistryService = i, this._initFormulaResultHandler();
118
+ __publicField(this, "_ruleFormulaMap", /* @__PURE__ */ new Map());
119
+ __publicField(this, "_ruleFormulaMap2", /* @__PURE__ */ new Map());
120
+ this._instanceSrv = _instanceSrv, this._registerOtherFormulaService = _registerOtherFormulaService, this._dataValidationModel = _dataValidationModel, this._dataValidationCacheService = _dataValidationCacheService, this._validatorRegistryService = _validatorRegistryService, this._initFormulaResultHandler();
116
121
  }
117
122
  _initFormulaResultHandler() {
118
- this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((a) => {
119
- for (const e in a) {
120
- const t = a[e];
121
- if (this._instanceSrv.getUnitType(e) === N.UNIVER_SHEET)
122
- for (const i in t) {
123
- const o = t[i], { ruleFormulaMap: n } = this._ensureMaps(e, i);
124
- o.forEach((l) => {
125
- var c, m;
126
- const u = n.get((c = l.extra) == null ? void 0 : c.ruleId), d = this._dataValidationModel.getRuleById(e, i, (m = l.extra) == null ? void 0 : m.ruleId);
127
- d && u && this._dataValidationCacheService.markRangeDirty(e, i, d.ranges);
123
+ this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
124
+ for (const unitId in resultMap) {
125
+ const unitMap = resultMap[unitId];
126
+ if (this._instanceSrv.getUnitType(unitId) === UniverInstanceType.UNIVER_SHEET)
127
+ for (const subUnitId in unitMap) {
128
+ const results = unitMap[subUnitId], { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
129
+ results.forEach((result) => {
130
+ var _a12, _b;
131
+ const ruleInfo = ruleFormulaMap.get((_a12 = result.extra) == null ? void 0 : _a12.ruleId), rule = this._dataValidationModel.getRuleById(unitId, subUnitId, (_b = result.extra) == null ? void 0 : _b.ruleId);
132
+ rule && ruleInfo && this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
128
133
  });
129
134
  }
130
135
  }
131
136
  }));
132
137
  }
133
- _ensureMaps(a, e) {
134
- let t = this._ruleFormulaMap.get(a), r = this._ruleFormulaMap2.get(a);
135
- t || (t = /* @__PURE__ */ new Map(), this._ruleFormulaMap.set(a, t)), r || (r = /* @__PURE__ */ new Map(), this._ruleFormulaMap2.set(a, r));
136
- let i = t.get(e);
137
- i || (i = /* @__PURE__ */ new Map(), t.set(e, i));
138
- let o = r.get(e);
139
- return o || (o = /* @__PURE__ */ new Map(), r.set(e, o)), { ruleFormulaMap: i, ruleFormulaMap2: o };
138
+ _ensureMaps(unitId, subUnitId) {
139
+ let ruleFormulaUnitMap = this._ruleFormulaMap.get(unitId), ruleFormulaUnitMap2 = this._ruleFormulaMap2.get(unitId);
140
+ ruleFormulaUnitMap || (ruleFormulaUnitMap = /* @__PURE__ */ new Map(), this._ruleFormulaMap.set(unitId, ruleFormulaUnitMap)), ruleFormulaUnitMap2 || (ruleFormulaUnitMap2 = /* @__PURE__ */ new Map(), this._ruleFormulaMap2.set(unitId, ruleFormulaUnitMap2));
141
+ let ruleFormulaMap = ruleFormulaUnitMap.get(subUnitId);
142
+ ruleFormulaMap || (ruleFormulaMap = /* @__PURE__ */ new Map(), ruleFormulaUnitMap.set(subUnitId, ruleFormulaMap));
143
+ let ruleFormulaMap2 = ruleFormulaUnitMap2.get(subUnitId);
144
+ return ruleFormulaMap2 || (ruleFormulaMap2 = /* @__PURE__ */ new Map(), ruleFormulaUnitMap2.set(subUnitId, ruleFormulaMap2)), { ruleFormulaMap, ruleFormulaMap2 };
140
145
  }
141
- _registerFormula(a, e, t, r, i) {
142
- return this._registerOtherFormulaService.registerFormulaWithRange(a, e, r, i, { ruleId: t });
146
+ _registerFormula(unitId, subUnitId, ruleId, formulaString, ranges) {
147
+ return this._registerOtherFormulaService.registerFormulaWithRange(unitId, subUnitId, formulaString, ranges, { ruleId });
143
148
  }
144
- deleteByRuleId(a, e, t) {
145
- const { ruleFormulaMap: r, ruleFormulaMap2: i } = this._ensureMaps(a, e), o = this._dataValidationModel.getRuleById(a, e, t), n = r.get(t);
146
- if (!o || !n)
149
+ deleteByRuleId(unitId, subUnitId, ruleId) {
150
+ const { ruleFormulaMap, ruleFormulaMap2 } = this._ensureMaps(unitId, subUnitId), rule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId), formulaInfo = ruleFormulaMap.get(ruleId);
151
+ if (!rule || !formulaInfo)
147
152
  return;
148
- const l = r.get(t);
149
- l && (r.delete(t), this._registerOtherFormulaService.deleteFormula(a, e, [l.formulaId]));
150
- const u = i.get(t);
151
- u && (i.delete(t), this._registerOtherFormulaService.deleteFormula(a, e, [u.formulaId]));
152
- }
153
- _addFormulaByRange(a, e, t, r, i, o) {
154
- const { ruleFormulaMap: n, ruleFormulaMap2: l } = this._ensureMaps(a, e), u = o[0].startRow, d = o[0].startColumn;
155
- if (r && v(r)) {
156
- const c = this._registerFormula(a, e, t, r, o);
157
- n.set(t, {
158
- formula: r,
159
- originCol: d,
160
- originRow: u,
161
- formulaId: c
153
+ const current = ruleFormulaMap.get(ruleId);
154
+ current && (ruleFormulaMap.delete(ruleId), this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, [current.formulaId]));
155
+ const current2 = ruleFormulaMap2.get(ruleId);
156
+ current2 && (ruleFormulaMap2.delete(ruleId), this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, [current2.formulaId]));
157
+ }
158
+ _addFormulaByRange(unitId, subUnitId, ruleId, formula, formula2, ranges) {
159
+ const { ruleFormulaMap, ruleFormulaMap2 } = this._ensureMaps(unitId, subUnitId), originRow = ranges[0].startRow, originCol = ranges[0].startColumn;
160
+ if (formula && isFormulaString(formula)) {
161
+ const formulaId = this._registerFormula(unitId, subUnitId, ruleId, formula, ranges);
162
+ ruleFormulaMap.set(ruleId, {
163
+ formula,
164
+ originCol,
165
+ originRow,
166
+ formulaId
162
167
  });
163
168
  }
164
- if (i && v(i)) {
165
- const c = this._registerFormula(a, e, t, i, o);
166
- l.set(t, {
167
- formula: i,
168
- originCol: d,
169
- originRow: u,
170
- formulaId: c
169
+ if (formula2 && isFormulaString(formula2)) {
170
+ const formulaId2 = this._registerFormula(unitId, subUnitId, ruleId, formula2, ranges);
171
+ ruleFormulaMap2.set(ruleId, {
172
+ formula: formula2,
173
+ originCol,
174
+ originRow,
175
+ formulaId: formulaId2
171
176
  });
172
177
  }
173
178
  }
174
- addRule(a, e, t) {
175
- if (de(t.type, this._validatorRegistryService)) {
176
- const { ranges: r, formula1: i, formula2: o, uid: n } = t;
177
- this._addFormulaByRange(a, e, n, i, o, r);
179
+ addRule(unitId, subUnitId, rule) {
180
+ if (shouldOffsetFormulaByRange(rule.type, this._validatorRegistryService)) {
181
+ const { ranges, formula1, formula2, uid: ruleId } = rule;
182
+ this._addFormulaByRange(unitId, subUnitId, ruleId, formula1, formula2, ranges);
178
183
  }
179
184
  }
180
- async getCellFormulaValue(a, e, t, r, i) {
181
- var _, g;
182
- const { ruleFormulaMap: o } = this._ensureMaps(a, e), n = o.get(t);
183
- if (!n)
185
+ async getCellFormulaValue(unitId, subUnitId, ruleId, row, column) {
186
+ var _a12, _b;
187
+ const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId), current = ruleFormulaMap.get(ruleId);
188
+ if (!current)
184
189
  return Promise.resolve(void 0);
185
- const l = await this._registerOtherFormulaService.getFormulaValue(a, e, n.formulaId), { originRow: u, originCol: d } = n, c = r - u, m = i - d;
186
- return ge((g = (_ = l == null ? void 0 : l.result) == null ? void 0 : _[c]) == null ? void 0 : g[m]);
190
+ const result = await this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, current.formulaId), { originRow, originCol } = current, offsetRow = row - originRow, offsetCol = column - originCol;
191
+ return getFormulaCellData((_b = (_a12 = result == null ? void 0 : result.result) == null ? void 0 : _a12[offsetRow]) == null ? void 0 : _b[offsetCol]);
187
192
  }
188
- async getCellFormula2Value(a, e, t, r, i) {
189
- var _, g;
190
- const { ruleFormulaMap2: o } = this._ensureMaps(a, e), n = o.get(t);
191
- if (!n)
193
+ async getCellFormula2Value(unitId, subUnitId, ruleId, row, column) {
194
+ var _a12, _b;
195
+ const { ruleFormulaMap2 } = this._ensureMaps(unitId, subUnitId), current = ruleFormulaMap2.get(ruleId);
196
+ if (!current)
192
197
  return Promise.resolve(void 0);
193
- const l = await this._registerOtherFormulaService.getFormulaValue(a, e, n.formulaId), { originRow: u, originCol: d } = n, c = r - u, m = i - d;
194
- return ge((g = (_ = l == null ? void 0 : l.result) == null ? void 0 : _[c]) == null ? void 0 : g[m]);
198
+ const result = await this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, current.formulaId), { originRow, originCol } = current, offsetRow = row - originRow, offsetCol = column - originCol;
199
+ return getFormulaCellData((_b = (_a12 = result == null ? void 0 : result.result) == null ? void 0 : _a12[offsetRow]) == null ? void 0 : _b[offsetCol]);
195
200
  }
196
- getCellFormulaValueSync(a, e, t, r, i) {
197
- var _, g;
198
- const { ruleFormulaMap: o } = this._ensureMaps(a, e), n = o.get(t);
199
- if (!n)
201
+ getCellFormulaValueSync(unitId, subUnitId, ruleId, row, column) {
202
+ var _a12, _b;
203
+ const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId), current = ruleFormulaMap.get(ruleId);
204
+ if (!current)
200
205
  return;
201
- const l = this._registerOtherFormulaService.getFormulaValueSync(a, e, n.formulaId), { originRow: u, originCol: d } = n, c = r - u, m = i - d;
202
- return ge((g = (_ = l == null ? void 0 : l.result) == null ? void 0 : _[c]) == null ? void 0 : g[m]);
206
+ const result = this._registerOtherFormulaService.getFormulaValueSync(unitId, subUnitId, current.formulaId), { originRow, originCol } = current, offsetRow = row - originRow, offsetCol = column - originCol;
207
+ return getFormulaCellData((_b = (_a12 = result == null ? void 0 : result.result) == null ? void 0 : _a12[offsetRow]) == null ? void 0 : _b[offsetCol]);
203
208
  }
204
- getCellFormula2ValueSync(a, e, t, r, i) {
205
- var _, g;
206
- const { ruleFormulaMap2: o } = this._ensureMaps(a, e), n = o.get(t);
207
- if (!n)
209
+ getCellFormula2ValueSync(unitId, subUnitId, ruleId, row, column) {
210
+ var _a12, _b;
211
+ const { ruleFormulaMap2 } = this._ensureMaps(unitId, subUnitId), current = ruleFormulaMap2.get(ruleId);
212
+ if (!current)
208
213
  return;
209
- const l = this._registerOtherFormulaService.getFormulaValueSync(a, e, n.formulaId), { originRow: u, originCol: d } = n, c = r - u, m = i - d;
210
- return ge((g = (_ = l == null ? void 0 : l.result) == null ? void 0 : _[c]) == null ? void 0 : g[m]);
211
- }
212
- getRuleFormulaInfo(a, e, t) {
213
- const { ruleFormulaMap: r } = this._ensureMaps(a, e);
214
- return r.get(t);
215
- }
216
- };
217
- P = Jt([
218
- re(0, O),
219
- re(1, S(lt)),
220
- re(2, S(ke)),
221
- re(3, S(q)),
222
- re(4, S(G))
223
- ], P);
224
- var ea = Object.defineProperty, ta = Object.getOwnPropertyDescriptor, aa = (s, a, e, t) => {
225
- for (var r = t > 1 ? void 0 : t ? ta(a, e) : a, i = s.length - 1, o; i >= 0; i--)
226
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
227
- return t && r && ea(a, e, r), r;
228
- }, ie = (s, a) => (e, t) => a(e, t, s);
229
- let X = class extends $ {
230
- constructor(a, e, t, r, i) {
214
+ const result = this._registerOtherFormulaService.getFormulaValueSync(unitId, subUnitId, current.formulaId), { originRow, originCol } = current, offsetRow = row - originRow, offsetCol = column - originCol;
215
+ return getFormulaCellData((_b = (_a12 = result == null ? void 0 : result.result) == null ? void 0 : _a12[offsetRow]) == null ? void 0 : _b[offsetCol]);
216
+ }
217
+ getRuleFormulaInfo(unitId, subUnitId, ruleId) {
218
+ const { ruleFormulaMap } = this._ensureMaps(unitId, subUnitId);
219
+ return ruleFormulaMap.get(ruleId);
220
+ }
221
+ }, __name(_a2, "DataValidationCustomFormulaService"), _a2);
222
+ DataValidationCustomFormulaService = __decorateClass$9([
223
+ __decorateParam$9(0, IUniverInstanceService),
224
+ __decorateParam$9(1, Inject(RegisterOtherFormulaService)),
225
+ __decorateParam$9(2, Inject(DataValidationModel)),
226
+ __decorateParam$9(3, Inject(DataValidationCacheService)),
227
+ __decorateParam$9(4, Inject(DataValidatorRegistryService))
228
+ ], DataValidationCustomFormulaService);
229
+ var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor, __decorateClass$8 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
230
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
231
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
232
+ return kind && result && __defProp$8(target, key, result), result;
233
+ }, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$8"), _a3;
234
+ let DataValidationFormulaService = (_a3 = class extends Disposable {
235
+ constructor(_instanceService, _registerOtherFormulaService, _dataValidationCacheService, _dataValidationModel, _validatorRegistryService) {
231
236
  super();
232
- f(this, "_formulaRuleMap", /* @__PURE__ */ new Map());
233
- this._instanceService = a, this._registerOtherFormulaService = e, this._dataValidationCacheService = t, this._dataValidationModel = r, this._validatorRegistryService = i, this._initFormulaResultHandler();
237
+ __publicField(this, "_formulaRuleMap", /* @__PURE__ */ new Map());
238
+ this._instanceService = _instanceService, this._registerOtherFormulaService = _registerOtherFormulaService, this._dataValidationCacheService = _dataValidationCacheService, this._dataValidationModel = _dataValidationModel, this._validatorRegistryService = _validatorRegistryService, this._initFormulaResultHandler();
234
239
  }
235
240
  _initFormulaResultHandler() {
236
- this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((a) => {
237
- for (const e in a) {
238
- const t = a[e];
239
- if (this._instanceService.getUnitType(e) === N.UNIVER_SHEET)
240
- for (const i in t) {
241
- const o = t[i], n = this._ensureRuleFormulaMap(e, i);
242
- o.forEach((l) => {
243
- var u, d;
244
- if (n.get((u = l.extra) == null ? void 0 : u.ruleId)) {
245
- const c = this._dataValidationModel.getRuleById(e, i, (d = l.extra) == null ? void 0 : d.ruleId);
246
- c && this._dataValidationCacheService.markRangeDirty(e, i, c.ranges);
241
+ this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((resultMap) => {
242
+ for (const unitId in resultMap) {
243
+ const unitMap = resultMap[unitId];
244
+ if (this._instanceService.getUnitType(unitId) === UniverInstanceType.UNIVER_SHEET)
245
+ for (const subUnitId in unitMap) {
246
+ const results = unitMap[subUnitId], formulaMap = this._ensureRuleFormulaMap(unitId, subUnitId);
247
+ results.forEach((result) => {
248
+ var _a12, _b;
249
+ if (formulaMap.get((_a12 = result.extra) == null ? void 0 : _a12.ruleId)) {
250
+ const rule = this._dataValidationModel.getRuleById(unitId, subUnitId, (_b = result.extra) == null ? void 0 : _b.ruleId);
251
+ rule && this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
247
252
  }
248
253
  });
249
254
  }
250
255
  }
251
256
  }));
252
257
  }
253
- _ensureRuleFormulaMap(a, e) {
254
- let t = this._formulaRuleMap.get(a);
255
- t || (t = /* @__PURE__ */ new Map(), this._formulaRuleMap.set(a, t));
256
- let r = t.get(e);
257
- return r || (r = /* @__PURE__ */ new Map(), t.set(e, r)), r;
258
+ _ensureRuleFormulaMap(unitId, subUnitId) {
259
+ let unitMap = this._formulaRuleMap.get(unitId);
260
+ unitMap || (unitMap = /* @__PURE__ */ new Map(), this._formulaRuleMap.set(unitId, unitMap));
261
+ let subUnitMap = unitMap.get(subUnitId);
262
+ return subUnitMap || (subUnitMap = /* @__PURE__ */ new Map(), unitMap.set(subUnitId, subUnitMap)), subUnitMap;
258
263
  }
259
- _registerSingleFormula(a, e, t, r) {
260
- const i = [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }];
261
- return this._registerOtherFormulaService.registerFormulaWithRange(a, e, t, i, { ruleId: r });
264
+ _registerSingleFormula(unitId, subUnitId, formula, ruleId) {
265
+ const ranges = [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }];
266
+ return this._registerOtherFormulaService.registerFormulaWithRange(unitId, subUnitId, formula, ranges, { ruleId });
262
267
  }
263
- addRule(a, e, t) {
264
- if (!de(t.type, this._validatorRegistryService) && t.type !== T.CHECKBOX) {
265
- const { formula1: r, formula2: i, uid: o } = t, n = v(r), l = v(i);
266
- if (!n && !l)
268
+ addRule(unitId, subUnitId, rule) {
269
+ if (!shouldOffsetFormulaByRange(rule.type, this._validatorRegistryService) && rule.type !== DataValidationType.CHECKBOX) {
270
+ const { formula1, formula2, uid: ruleId } = rule, isFormula1Legal = isFormulaString(formula1), isFormula2Legal = isFormulaString(formula2);
271
+ if (!isFormula1Legal && !isFormula2Legal)
267
272
  return;
268
- const u = this._ensureRuleFormulaMap(a, e), d = [void 0, void 0];
269
- if (n) {
270
- const c = this._registerSingleFormula(a, e, r, o);
271
- d[0] = { id: c, text: r };
273
+ const formulaRuleMap = this._ensureRuleFormulaMap(unitId, subUnitId), item = [void 0, void 0];
274
+ if (isFormula1Legal) {
275
+ const id = this._registerSingleFormula(unitId, subUnitId, formula1, ruleId);
276
+ item[0] = { id, text: formula1 };
272
277
  }
273
- if (l) {
274
- const c = this._registerSingleFormula(a, e, i, o);
275
- d[1] = { id: c, text: i };
278
+ if (isFormula2Legal) {
279
+ const id = this._registerSingleFormula(unitId, subUnitId, formula2, ruleId);
280
+ item[1] = { id, text: formula2 };
276
281
  }
277
- u.set(o, d);
282
+ formulaRuleMap.set(ruleId, item);
278
283
  }
279
284
  }
280
- removeRule(a, e, t) {
281
- const i = this._ensureRuleFormulaMap(a, e).get(t);
282
- if (!i)
285
+ removeRule(unitId, subUnitId, ruleId) {
286
+ const item = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
287
+ if (!item)
283
288
  return;
284
- const [o, n] = i, l = [o == null ? void 0 : o.id, n == null ? void 0 : n.id].filter(Boolean);
285
- l.length && this._registerOtherFormulaService.deleteFormula(a, e, l);
289
+ const [formula1, formula2] = item, idList = [formula1 == null ? void 0 : formula1.id, formula2 == null ? void 0 : formula2.id].filter(Boolean);
290
+ idList.length && this._registerOtherFormulaService.deleteFormula(unitId, subUnitId, idList);
286
291
  }
287
- getRuleFormulaResult(a, e, t) {
288
- const i = this._ensureRuleFormulaMap(a, e).get(t);
289
- if (!i)
292
+ getRuleFormulaResult(unitId, subUnitId, ruleId) {
293
+ const formulaInfo = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
294
+ if (!formulaInfo)
290
295
  return Promise.resolve(null);
291
- const o = async (n) => n && this._registerOtherFormulaService.getFormulaValue(a, e, n.id);
296
+ const getResult = /* @__PURE__ */ __name(async (info) => info && this._registerOtherFormulaService.getFormulaValue(unitId, subUnitId, info.id), "getResult");
292
297
  return Promise.all([
293
- o(i[0]),
294
- o(i[1])
298
+ getResult(formulaInfo[0]),
299
+ getResult(formulaInfo[1])
295
300
  ]);
296
301
  }
297
- getRuleFormulaResultSync(a, e, t) {
298
- const i = this._ensureRuleFormulaMap(a, e).get(t);
299
- if (i)
300
- return i.map((o) => {
301
- if (o)
302
- return this._registerOtherFormulaService.getFormulaValueSync(a, e, o.id);
302
+ getRuleFormulaResultSync(unitId, subUnitId, ruleId) {
303
+ const formulaInfo = this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
304
+ if (formulaInfo)
305
+ return formulaInfo.map((i) => {
306
+ if (i)
307
+ return this._registerOtherFormulaService.getFormulaValueSync(unitId, subUnitId, i.id);
303
308
  });
304
309
  }
305
- getRuleFormulaInfo(a, e, t) {
306
- return this._ensureRuleFormulaMap(a, e).get(t);
307
- }
308
- };
309
- X = aa([
310
- ie(0, O),
311
- ie(1, S(lt)),
312
- ie(2, S(q)),
313
- ie(3, S(ke)),
314
- ie(4, S(G))
315
- ], X);
316
- function ne(s) {
317
- return vt(s);
310
+ getRuleFormulaInfo(unitId, subUnitId, ruleId) {
311
+ return this._ensureRuleFormulaMap(unitId, subUnitId).get(ruleId);
312
+ }
313
+ }, __name(_a3, "DataValidationFormulaService"), _a3);
314
+ DataValidationFormulaService = __decorateClass$8([
315
+ __decorateParam$8(0, IUniverInstanceService),
316
+ __decorateParam$8(1, Inject(RegisterOtherFormulaService)),
317
+ __decorateParam$8(2, Inject(DataValidationCacheService)),
318
+ __decorateParam$8(3, Inject(DataValidationModel)),
319
+ __decorateParam$8(4, Inject(DataValidatorRegistryService))
320
+ ], DataValidationFormulaService);
321
+ function getCellValueOrigin(cell) {
322
+ return getOriginCellValue(cell);
318
323
  }
319
- function ct(s) {
320
- var a;
321
- return String((a = ne(s)) != null ? a : "");
324
+ __name(getCellValueOrigin, "getCellValueOrigin");
325
+ function getStringCellValue(cell) {
326
+ var _a12;
327
+ return String((_a12 = getCellValueOrigin(cell)) != null ? _a12 : "");
322
328
  }
323
- class Xe {
324
- constructor(a, e, t, r, i = !1) {
325
- f(this, "_map");
326
- f(this, "_tree", new Vt());
327
- f(this, "_dirty", !0);
328
- f(this, "_buildTree", () => {
329
+ __name(getStringCellValue, "getStringCellValue");
330
+ const _RuleMatrix = class _RuleMatrix {
331
+ constructor(value, _unitId, _subUnitId, _univerInstanceService, _disableTree = !1) {
332
+ __publicField(this, "_map");
333
+ __publicField(this, "_tree", new RBush());
334
+ __publicField(this, "_dirty", !0);
335
+ __publicField(this, "_buildTree", /* @__PURE__ */ __name(() => {
329
336
  if (!this._dirty || this._disableTree)
330
337
  return;
331
338
  this._tree.clear();
332
- const a = [];
333
- this._map.forEach((e, t) => {
334
- e.forEach((r) => {
335
- a.push({
336
- minX: r.startRow,
337
- maxX: r.endRow,
338
- minY: r.startColumn,
339
- maxY: r.endColumn,
340
- ruleId: t
339
+ const items = [];
340
+ this._map.forEach((ranges, ruleId) => {
341
+ ranges.forEach((range) => {
342
+ items.push({
343
+ minX: range.startRow,
344
+ maxX: range.endRow,
345
+ minY: range.startColumn,
346
+ maxY: range.endColumn,
347
+ ruleId
341
348
  });
342
349
  });
343
- }), this._tree.load(a), this._dirty = !1;
344
- });
345
- f(this, "_debonceBuildTree", Mt(this._buildTree, 0));
346
- this._unitId = e, this._subUnitId = t, this._univerInstanceService = r, this._disableTree = i, this._map = a, this._buildTree();
350
+ }), this._tree.load(items), this._dirty = !1;
351
+ }, "_buildTree"));
352
+ __publicField(this, "_debonceBuildTree", debounce(this._buildTree, 0));
353
+ this._unitId = _unitId, this._subUnitId = _subUnitId, this._univerInstanceService = _univerInstanceService, this._disableTree = _disableTree, this._map = value, this._buildTree();
347
354
  }
348
355
  get _worksheet() {
349
- var a;
350
- return (a = this._univerInstanceService.getUnit(this._unitId, N.UNIVER_SHEET)) == null ? void 0 : a.getSheetBySheetId(this._subUnitId);
356
+ var _a12;
357
+ return (_a12 = this._univerInstanceService.getUnit(this._unitId, UniverInstanceType.UNIVER_SHEET)) == null ? void 0 : _a12.getSheetBySheetId(this._subUnitId);
351
358
  }
352
- _addRule(a, e) {
359
+ _addRule(ruleId, _ranges) {
353
360
  if (!this._worksheet)
354
361
  return;
355
- const t = I.mergeRanges(e.map((r) => b.transformRange(r, this._worksheet)));
356
- this._map.forEach((r, i) => {
357
- const o = I.subtractMulti(r, t);
358
- o.length === 0 ? this._map.delete(i) : this._map.set(i, o);
359
- }), this._dirty = !0, this._map.set(a, t), this._debonceBuildTree();
362
+ const ranges = Rectangle.mergeRanges(_ranges.map((range) => Range.transformRange(range, this._worksheet)));
363
+ this._map.forEach((value, key) => {
364
+ const newRanges = Rectangle.subtractMulti(value, ranges);
365
+ newRanges.length === 0 ? this._map.delete(key) : this._map.set(key, newRanges);
366
+ }), this._dirty = !0, this._map.set(ruleId, ranges), this._debonceBuildTree();
360
367
  }
361
- addRule(a) {
362
- this._addRule(a.uid, a.ranges);
368
+ addRule(rule) {
369
+ this._addRule(rule.uid, rule.ranges);
363
370
  }
364
- removeRange(a) {
371
+ removeRange(_ranges) {
365
372
  if (!this._worksheet)
366
373
  return;
367
- const e = a.map((t) => b.transformRange(t, this._worksheet));
368
- this._map.forEach((t, r) => {
369
- const i = I.subtractMulti(t, e);
370
- i.length === 0 ? this._map.delete(r) : this._map.set(r, i);
374
+ const ranges = _ranges.map((range) => Range.transformRange(range, this._worksheet));
375
+ this._map.forEach((value, key) => {
376
+ const newRanges = Rectangle.subtractMulti(value, ranges);
377
+ newRanges.length === 0 ? this._map.delete(key) : this._map.set(key, newRanges);
371
378
  }), this._dirty = !0, this._debonceBuildTree();
372
379
  }
373
- _removeRule(a) {
374
- this._map.delete(a), this._dirty = !0, this._debonceBuildTree();
380
+ _removeRule(ruleId) {
381
+ this._map.delete(ruleId), this._dirty = !0, this._debonceBuildTree();
375
382
  }
376
- removeRule(a) {
377
- this._removeRule(a.uid);
383
+ removeRule(rule) {
384
+ this._removeRule(rule.uid);
378
385
  }
379
- updateRange(a, e) {
380
- this._removeRule(a), this._addRule(a, e);
386
+ updateRange(ruleId, _newRanges) {
387
+ this._removeRule(ruleId), this._addRule(ruleId, _newRanges);
381
388
  }
382
- addRangeRules(a) {
383
- a.forEach(({ id: e, ranges: t }) => {
384
- if (!t.length)
389
+ addRangeRules(rules) {
390
+ rules.forEach(({ id: ruleId, ranges }) => {
391
+ if (!ranges.length)
385
392
  return;
386
- let r = this._map.get(e);
387
- r ? (this._map.set(e, I.mergeRanges([...r, ...t])), r = this._map.get(e)) : (r = t, this._map.set(e, r)), this._map.forEach((i, o) => {
388
- if (o === e)
393
+ let current = this._map.get(ruleId);
394
+ current ? (this._map.set(ruleId, Rectangle.mergeRanges([...current, ...ranges])), current = this._map.get(ruleId)) : (current = ranges, this._map.set(ruleId, current)), this._map.forEach((value, key) => {
395
+ if (key === ruleId)
389
396
  return;
390
- const n = I.subtractMulti(i, t);
391
- n.length === 0 ? this._map.delete(o) : this._map.set(o, n);
397
+ const newRanges = Rectangle.subtractMulti(value, ranges);
398
+ newRanges.length === 0 ? this._map.delete(key) : this._map.set(key, newRanges);
392
399
  });
393
400
  }), this._dirty = !0, this._debonceBuildTree();
394
401
  }
395
- diff(a) {
396
- const e = [];
397
- let t = 0;
398
- return a.forEach((r, i) => {
399
- var l;
400
- const o = (l = this._map.get(r.uid)) != null ? l : [], n = r.ranges;
401
- o.length !== 0 && (o.length !== n.length || o.some((u, d) => !I.equals(u, n[d]))) && e.push({
402
+ diff(rules) {
403
+ const mutations = [];
404
+ let deleteIndex = 0;
405
+ return rules.forEach((rule, index) => {
406
+ var _a12;
407
+ const newRanges = (_a12 = this._map.get(rule.uid)) != null ? _a12 : [], oldRanges = rule.ranges;
408
+ newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i]))) && mutations.push({
402
409
  type: "update",
403
- ruleId: r.uid,
404
- oldRanges: n,
405
- newRanges: I.sort(o),
406
- rule: r
407
- }), o.length === 0 && (e.push({
410
+ ruleId: rule.uid,
411
+ oldRanges,
412
+ newRanges: Rectangle.sort(newRanges),
413
+ rule
414
+ }), newRanges.length === 0 && (mutations.push({
408
415
  type: "delete",
409
- rule: r,
410
- index: i - t
411
- }), t++);
412
- }), e;
413
- }
414
- diffWithAddition(a, e) {
415
- const t = [];
416
- let r = 0;
417
- return a.forEach((i, o) => {
418
- var u;
419
- const n = (u = this._map.get(i.uid)) != null ? u : [], l = i.ranges;
420
- n.length !== 0 && (n.length !== l.length || n.some((d, c) => !I.equals(d, l[c]))) && t.push({
416
+ rule,
417
+ index: index - deleteIndex
418
+ }), deleteIndex++);
419
+ }), mutations;
420
+ }
421
+ diffWithAddition(rules, additionRules) {
422
+ const mutations = [];
423
+ let deleteIndex = 0;
424
+ return rules.forEach((rule, index) => {
425
+ var _a12;
426
+ const newRanges = (_a12 = this._map.get(rule.uid)) != null ? _a12 : [], oldRanges = rule.ranges;
427
+ newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i]))) && mutations.push({
421
428
  type: "update",
422
- ruleId: i.uid,
423
- oldRanges: l,
424
- newRanges: I.sort(n),
425
- rule: i
426
- }), n.length === 0 && (t.push({
429
+ ruleId: rule.uid,
430
+ oldRanges,
431
+ newRanges: Rectangle.sort(newRanges),
432
+ rule
433
+ }), newRanges.length === 0 && (mutations.push({
427
434
  type: "delete",
428
- rule: i,
429
- index: o - r
430
- }), r++);
431
- }), Array.from(e).forEach((i) => {
432
- var n;
433
- const o = (n = this._map.get(i.uid)) != null ? n : [];
434
- t.push({
435
+ rule,
436
+ index: index - deleteIndex
437
+ }), deleteIndex++);
438
+ }), Array.from(additionRules).forEach((rule) => {
439
+ var _a12;
440
+ const newRanges = (_a12 = this._map.get(rule.uid)) != null ? _a12 : [];
441
+ mutations.push({
435
442
  type: "add",
436
443
  rule: {
437
- ...i,
438
- ranges: I.sort(o)
444
+ ...rule,
445
+ ranges: Rectangle.sort(newRanges)
439
446
  }
440
447
  });
441
- }), t;
448
+ }), mutations;
442
449
  }
443
450
  clone() {
444
- return new Xe(
445
- new Map(V.deepClone(Array.from(this._map.entries()))),
451
+ return new _RuleMatrix(
452
+ new Map(Tools.deepClone(Array.from(this._map.entries()))),
446
453
  this._unitId,
447
454
  this._subUnitId,
448
455
  this._univerInstanceService,
@@ -450,591 +457,606 @@ class Xe {
450
457
  !0
451
458
  );
452
459
  }
453
- getValue(a, e) {
460
+ getValue(row, col) {
454
461
  this._dirty && this._buildTree();
455
- const t = this._tree.search({
456
- minX: a,
457
- maxX: a,
458
- minY: e,
459
- maxY: e
462
+ const result = this._tree.search({
463
+ minX: row,
464
+ maxX: row,
465
+ minY: col,
466
+ maxY: col
460
467
  });
461
- return t.length > 0 ? t[0].ruleId : void 0;
468
+ return result.length > 0 ? result[0].ruleId : void 0;
462
469
  }
463
- }
464
- var ra = Object.defineProperty, ia = Object.getOwnPropertyDescriptor, sa = (s, a, e, t) => {
465
- for (var r = t > 1 ? void 0 : t ? ia(a, e) : a, i = s.length - 1, o; i >= 0; i--)
466
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
467
- return t && r && ra(a, e, r), r;
468
- }, Y = (s, a) => (e, t) => a(e, t, s);
469
- let F = class extends $ {
470
- constructor(a, e, t, r, i, o, n) {
470
+ };
471
+ __name(_RuleMatrix, "RuleMatrix");
472
+ let RuleMatrix = _RuleMatrix;
473
+ var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
474
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
475
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
476
+ return kind && result && __defProp$7(target, key, result), result;
477
+ }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7"), _a4;
478
+ let SheetDataValidationModel = (_a4 = class extends Disposable {
479
+ constructor(_dataValidationModel, _univerInstanceService, _dataValidatorRegistryService, _dataValidationCacheService, _dataValidationFormulaService, _dataValidationCustomFormulaService, _commandService) {
471
480
  super();
472
- f(this, "_ruleMatrixMap", /* @__PURE__ */ new Map());
473
- f(this, "_validStatusChange$", new Qe());
474
- f(this, "_ruleChange$", new Qe());
475
- f(this, "ruleChange$", this._ruleChange$.asObservable());
476
- f(this, "validStatusChange$", this._validStatusChange$.asObservable());
477
- this._dataValidationModel = a, this._univerInstanceService = e, this._dataValidatorRegistryService = t, this._dataValidationCacheService = r, this._dataValidationFormulaService = i, this._dataValidationCustomFormulaService = o, this._commandService = n, this._initRuleUpdateListener(), this.disposeWithMe(() => {
481
+ __publicField(this, "_ruleMatrixMap", /* @__PURE__ */ new Map());
482
+ __publicField(this, "_validStatusChange$", new Subject());
483
+ __publicField(this, "_ruleChange$", new Subject());
484
+ __publicField(this, "ruleChange$", this._ruleChange$.asObservable());
485
+ __publicField(this, "validStatusChange$", this._validStatusChange$.asObservable());
486
+ this._dataValidationModel = _dataValidationModel, this._univerInstanceService = _univerInstanceService, this._dataValidatorRegistryService = _dataValidatorRegistryService, this._dataValidationCacheService = _dataValidationCacheService, this._dataValidationFormulaService = _dataValidationFormulaService, this._dataValidationCustomFormulaService = _dataValidationCustomFormulaService, this._commandService = _commandService, this._initRuleUpdateListener(), this.disposeWithMe(() => {
478
487
  this._ruleChange$.complete(), this._validStatusChange$.complete();
479
488
  }), this._initUniverInstanceListener();
480
489
  }
481
490
  _initUniverInstanceListener() {
482
491
  this.disposeWithMe(
483
- this._univerInstanceService.unitDisposed$.subscribe((a) => {
484
- this._ruleMatrixMap.delete(a.getUnitId());
492
+ this._univerInstanceService.unitDisposed$.subscribe((unit) => {
493
+ this._ruleMatrixMap.delete(unit.getUnitId());
485
494
  })
486
495
  ), this.disposeWithMe(
487
- this._commandService.onCommandExecuted((a) => {
488
- if (a.id === it.id) {
489
- const { unitId: e, subUnitId: t } = a.params, r = this._ruleMatrixMap.get(e);
490
- r && r.delete(t);
496
+ this._commandService.onCommandExecuted((command) => {
497
+ if (command.id === RemoveSheetMutation.id) {
498
+ const { unitId, subUnitId } = command.params, subUnitMap = this._ruleMatrixMap.get(unitId);
499
+ subUnitMap && subUnitMap.delete(subUnitId);
491
500
  }
492
501
  })
493
502
  );
494
503
  }
495
504
  _initRuleUpdateListener() {
496
- const a = this._dataValidationModel.getAll();
497
- for (const [e, t] of a)
498
- for (const [r, i] of t)
499
- for (const o of i)
500
- this._addRule(e, r, o), this._ruleChange$.next({
505
+ const allRules = this._dataValidationModel.getAll();
506
+ for (const [unitId, subUnitMap] of allRules)
507
+ for (const [subUnitId, rules] of subUnitMap)
508
+ for (const rule of rules)
509
+ this._addRule(unitId, subUnitId, rule), this._ruleChange$.next({
501
510
  type: "add",
502
- unitId: e,
503
- subUnitId: r,
504
- rule: o,
511
+ unitId,
512
+ subUnitId,
513
+ rule,
505
514
  source: "patched"
506
515
  });
507
516
  this.disposeWithMe(
508
- this._dataValidationModel.ruleChange$.subscribe((e) => {
509
- switch (e.type) {
517
+ this._dataValidationModel.ruleChange$.subscribe((ruleChange) => {
518
+ switch (ruleChange.type) {
510
519
  case "add":
511
- this._addRule(e.unitId, e.subUnitId, e.rule);
520
+ this._addRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
512
521
  break;
513
522
  case "update":
514
- this._updateRule(e.unitId, e.subUnitId, e.rule.uid, e.oldRule, e.updatePayload);
523
+ this._updateRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule.uid, ruleChange.oldRule, ruleChange.updatePayload);
515
524
  break;
516
525
  case "remove":
517
- this._removeRule(e.unitId, e.subUnitId, e.rule);
526
+ this._removeRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
518
527
  break;
519
528
  }
520
- this._ruleChange$.next(e);
529
+ this._ruleChange$.next(ruleChange);
521
530
  })
522
531
  );
523
532
  }
524
- _ensureRuleMatrix(a, e) {
525
- let t = this._ruleMatrixMap.get(a);
526
- t || (t = /* @__PURE__ */ new Map(), this._ruleMatrixMap.set(a, t));
527
- let r = t.get(e);
528
- return r || (r = new Xe(/* @__PURE__ */ new Map(), a, e, this._univerInstanceService), t.set(e, r)), r;
533
+ _ensureRuleMatrix(unitId, subUnitId) {
534
+ let unitMap = this._ruleMatrixMap.get(unitId);
535
+ unitMap || (unitMap = /* @__PURE__ */ new Map(), this._ruleMatrixMap.set(unitId, unitMap));
536
+ let matrix = unitMap.get(subUnitId);
537
+ return matrix || (matrix = new RuleMatrix(/* @__PURE__ */ new Map(), unitId, subUnitId, this._univerInstanceService), unitMap.set(subUnitId, matrix)), matrix;
529
538
  }
530
- _addRuleSideEffect(a, e, t) {
531
- this._ensureRuleMatrix(a, e).addRule(t), this._dataValidationCacheService.addRule(a, e, t), this._dataValidationFormulaService.addRule(a, e, t), this._dataValidationCustomFormulaService.addRule(a, e, t);
539
+ _addRuleSideEffect(unitId, subUnitId, rule) {
540
+ this._ensureRuleMatrix(unitId, subUnitId).addRule(rule), this._dataValidationCacheService.addRule(unitId, subUnitId, rule), this._dataValidationFormulaService.addRule(unitId, subUnitId, rule), this._dataValidationCustomFormulaService.addRule(unitId, subUnitId, rule);
532
541
  }
533
- _addRule(a, e, t) {
534
- (Array.isArray(t) ? t : [t]).forEach((i) => {
535
- this._addRuleSideEffect(a, e, i);
542
+ _addRule(unitId, subUnitId, rule) {
543
+ (Array.isArray(rule) ? rule : [rule]).forEach((item) => {
544
+ this._addRuleSideEffect(unitId, subUnitId, item);
536
545
  });
537
546
  }
538
- _updateRule(a, e, t, r, i) {
539
- const o = this._ensureRuleMatrix(a, e), n = {
540
- ...r,
541
- ...i.payload
547
+ _updateRule(unitId, subUnitId, ruleId, oldRule, payload) {
548
+ const ruleMatrix = this._ensureRuleMatrix(unitId, subUnitId), newRule = {
549
+ ...oldRule,
550
+ ...payload.payload
542
551
  };
543
- i.type === y.RANGE ? o.updateRange(t, i.payload) : i.type === y.ALL && o.updateRange(t, i.payload.ranges), this._dataValidationCacheService.removeRule(a, e, r), this._dataValidationCacheService.addRule(a, e, n), this._dataValidationFormulaService.removeRule(a, e, r.uid), this._dataValidationFormulaService.addRule(a, e, n), this._dataValidationCustomFormulaService.deleteByRuleId(a, e, t), this._dataValidationCustomFormulaService.addRule(a, e, n);
544
- }
545
- _removeRule(a, e, t) {
546
- this._ensureRuleMatrix(a, e).removeRule(t), this._dataValidationCacheService.removeRule(a, e, t), this._dataValidationCustomFormulaService.deleteByRuleId(a, e, t.uid);
547
- }
548
- getValidator(a) {
549
- return this._dataValidatorRegistryService.getValidatorItem(a);
550
- }
551
- getRuleIdByLocation(a, e, t, r) {
552
- return this._ensureRuleMatrix(a, e).getValue(t, r);
553
- }
554
- getRuleByLocation(a, e, t, r) {
555
- const i = this.getRuleIdByLocation(a, e, t, r);
556
- if (i)
557
- return this._dataValidationModel.getRuleById(a, e, i);
558
- }
559
- validator(a, e, t) {
560
- const { col: r, row: i, unitId: o, subUnitId: n, worksheet: l } = e, u = (g, R) => {
561
- t && t(g, R), R && this._validStatusChange$.next({
562
- unitId: o,
563
- subUnitId: n,
564
- ruleId: a.uid,
565
- status: g,
566
- row: i,
567
- col: r
552
+ payload.type === UpdateRuleType.RANGE ? ruleMatrix.updateRange(ruleId, payload.payload) : payload.type === UpdateRuleType.ALL && ruleMatrix.updateRange(ruleId, payload.payload.ranges), this._dataValidationCacheService.removeRule(unitId, subUnitId, oldRule), this._dataValidationCacheService.addRule(unitId, subUnitId, newRule), this._dataValidationFormulaService.removeRule(unitId, subUnitId, oldRule.uid), this._dataValidationFormulaService.addRule(unitId, subUnitId, newRule), this._dataValidationCustomFormulaService.deleteByRuleId(unitId, subUnitId, ruleId), this._dataValidationCustomFormulaService.addRule(unitId, subUnitId, newRule);
553
+ }
554
+ _removeRule(unitId, subUnitId, oldRule) {
555
+ this._ensureRuleMatrix(unitId, subUnitId).removeRule(oldRule), this._dataValidationCacheService.removeRule(unitId, subUnitId, oldRule), this._dataValidationCustomFormulaService.deleteByRuleId(unitId, subUnitId, oldRule.uid);
556
+ }
557
+ getValidator(type) {
558
+ return this._dataValidatorRegistryService.getValidatorItem(type);
559
+ }
560
+ getRuleIdByLocation(unitId, subUnitId, row, col) {
561
+ return this._ensureRuleMatrix(unitId, subUnitId).getValue(row, col);
562
+ }
563
+ getRuleByLocation(unitId, subUnitId, row, col) {
564
+ const ruleId = this.getRuleIdByLocation(unitId, subUnitId, row, col);
565
+ if (ruleId)
566
+ return this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
567
+ }
568
+ validator(rule, pos, _onCompete) {
569
+ const { col, row, unitId, subUnitId, worksheet } = pos, onCompete = /* @__PURE__ */ __name((status, changed) => {
570
+ _onCompete && _onCompete(status, changed), changed && this._validStatusChange$.next({
571
+ unitId,
572
+ subUnitId,
573
+ ruleId: rule.uid,
574
+ status,
575
+ row,
576
+ col
568
577
  });
569
- }, d = l.getCellValueOnly(i, r), c = this.getValidator(a.type), m = l.getCellRaw(i, r), _ = ne(m);
570
- if (c) {
571
- const g = this._dataValidationCacheService.ensureCache(o, n), R = g.getValue(i, r);
572
- return R == null ? (g.setValue(i, r, D.VALIDATING), c.validator(
578
+ }, "onCompete"), cell = worksheet.getCellValueOnly(row, col), validator = this.getValidator(rule.type), cellRaw = worksheet.getCellRaw(row, col), cellValue = getCellValueOrigin(cellRaw);
579
+ if (validator) {
580
+ const cache = this._dataValidationCacheService.ensureCache(unitId, subUnitId), current = cache.getValue(row, col);
581
+ return current == null ? (cache.setValue(row, col, DataValidationStatus.VALIDATING), validator.validator(
573
582
  {
574
- value: _,
575
- unitId: o,
576
- subUnitId: n,
577
- row: i,
578
- column: r,
579
- worksheet: e.worksheet,
580
- workbook: e.workbook,
581
- interceptValue: ne(d),
582
- t: m == null ? void 0 : m.t
583
+ value: cellValue,
584
+ unitId,
585
+ subUnitId,
586
+ row,
587
+ column: col,
588
+ worksheet: pos.worksheet,
589
+ workbook: pos.workbook,
590
+ interceptValue: getCellValueOrigin(cell),
591
+ t: cellRaw == null ? void 0 : cellRaw.t
583
592
  },
584
- a
585
- ).then((M) => {
586
- const p = M ? D.VALID : D.INVALID;
587
- p === D.VALID ? g.realDeleteValue(i, r) : g.setValue(i, r, p);
588
- const w = g.getValue(i, r);
589
- u(p, R !== w);
590
- }), D.VALIDATING) : (u(R != null ? R : D.VALID, !1), R != null ? R : D.VALID);
593
+ rule
594
+ ).then((status) => {
595
+ const realStatus = status ? DataValidationStatus.VALID : DataValidationStatus.INVALID;
596
+ realStatus === DataValidationStatus.VALID ? cache.realDeleteValue(row, col) : cache.setValue(row, col, realStatus);
597
+ const now = cache.getValue(row, col);
598
+ onCompete(realStatus, current !== now);
599
+ }), DataValidationStatus.VALIDATING) : (onCompete(current != null ? current : DataValidationStatus.VALID, !1), current != null ? current : DataValidationStatus.VALID);
591
600
  } else
592
- return u(D.VALID, !1), D.VALID;
601
+ return onCompete(DataValidationStatus.VALID, !1), DataValidationStatus.VALID;
593
602
  }
594
- getRuleObjectMatrix(a, e) {
595
- return this._ensureRuleMatrix(a, e);
603
+ getRuleObjectMatrix(unitId, subUnitId) {
604
+ return this._ensureRuleMatrix(unitId, subUnitId);
596
605
  }
597
- getRuleById(a, e, t) {
598
- return this._dataValidationModel.getRuleById(a, e, t);
606
+ getRuleById(unitId, subUnitId, ruleId) {
607
+ return this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
599
608
  }
600
- getRuleIndex(a, e, t) {
601
- return this._dataValidationModel.getRuleIndex(a, e, t);
609
+ getRuleIndex(unitId, subUnitId, ruleId) {
610
+ return this._dataValidationModel.getRuleIndex(unitId, subUnitId, ruleId);
602
611
  }
603
- getRules(a, e) {
604
- return [...this._dataValidationModel.getRules(a, e)];
612
+ getRules(unitId, subUnitId) {
613
+ return [...this._dataValidationModel.getRules(unitId, subUnitId)];
605
614
  }
606
- getUnitRules(a) {
607
- return this._dataValidationModel.getUnitRules(a);
615
+ getUnitRules(unitId) {
616
+ return this._dataValidationModel.getUnitRules(unitId);
608
617
  }
609
- deleteUnitRules(a) {
610
- return this._dataValidationModel.deleteUnitRules(a);
618
+ deleteUnitRules(unitId) {
619
+ return this._dataValidationModel.deleteUnitRules(unitId);
611
620
  }
612
- getSubUnitIds(a) {
613
- return this._dataValidationModel.getSubUnitIds(a);
621
+ getSubUnitIds(unitId) {
622
+ return this._dataValidationModel.getSubUnitIds(unitId);
614
623
  }
615
624
  getAll() {
616
625
  return this._dataValidationModel.getAll();
617
626
  }
618
- };
619
- F = sa([
620
- Y(0, S(ke)),
621
- Y(1, O),
622
- Y(2, S(G)),
623
- Y(3, S(q)),
624
- Y(4, S(X)),
625
- Y(5, S(P)),
626
- Y(6, x)
627
- ], F);
628
- const Ve = 1, Me = 0;
629
- function et(s, a) {
630
- return V.isBlank(s) ? a.t("dataValidation.validFail.value") : v(s) ? a.t("dataValidation.validFail.primitive") : "";
627
+ }, __name(_a4, "SheetDataValidationModel"), _a4);
628
+ SheetDataValidationModel = __decorateClass$7([
629
+ __decorateParam$7(0, Inject(DataValidationModel)),
630
+ __decorateParam$7(1, IUniverInstanceService),
631
+ __decorateParam$7(2, Inject(DataValidatorRegistryService)),
632
+ __decorateParam$7(3, Inject(DataValidationCacheService)),
633
+ __decorateParam$7(4, Inject(DataValidationFormulaService)),
634
+ __decorateParam$7(5, Inject(DataValidationCustomFormulaService)),
635
+ __decorateParam$7(6, ICommandService)
636
+ ], SheetDataValidationModel);
637
+ const CHECKBOX_FORMULA_1 = 1, CHECKBOX_FORMULA_2 = 0;
638
+ function getFailMessage(formula, localeService) {
639
+ return Tools.isBlank(formula) ? localeService.t("dataValidation.validFail.value") : isFormulaString(formula) ? localeService.t("dataValidation.validFail.primitive") : "";
631
640
  }
632
- const _e = (s) => V.isDefine(s) && String(s).toLowerCase() === "true" ? "1" : String(s).toLowerCase() === "false" ? "0" : s;
633
- class oa extends k {
641
+ __name(getFailMessage, "getFailMessage");
642
+ const transformCheckboxValue = /* @__PURE__ */ __name((value) => Tools.isDefine(value) && String(value).toLowerCase() === "true" ? "1" : String(value).toLowerCase() === "false" ? "0" : value, "transformCheckboxValue"), _CheckboxValidator = class _CheckboxValidator extends BaseDataValidator {
634
643
  constructor() {
635
644
  super(...arguments);
636
- f(this, "id", T.CHECKBOX);
637
- f(this, "title", "dataValidation.checkbox.title");
638
- f(this, "operators", []);
639
- f(this, "scopes", ["sheet"]);
640
- f(this, "offsetFormulaByRange", !1);
641
- f(this, "_formulaService", this.injector.get(X));
642
- f(this, "skipDefaultFontRender", (e, t, r) => {
643
- const { unitId: i, subUnitId: o } = r, { formula1: n, formula2: l } = this.parseFormulaSync(e, i, o), u = `${t != null ? t : ""}`;
644
- return !u || u === `${n}` || u === `${l}`;
645
- });
646
- }
647
- validatorFormula(e, t, r) {
648
- const { formula1: i, formula2: o } = e, n = i === o;
649
- if (V.isBlank(i) && V.isBlank(o))
645
+ __publicField(this, "id", DataValidationType.CHECKBOX);
646
+ __publicField(this, "title", "dataValidation.checkbox.title");
647
+ __publicField(this, "operators", []);
648
+ __publicField(this, "scopes", ["sheet"]);
649
+ __publicField(this, "offsetFormulaByRange", !1);
650
+ __publicField(this, "_formulaService", this.injector.get(DataValidationFormulaService));
651
+ __publicField(this, "skipDefaultFontRender", /* @__PURE__ */ __name((rule, cellValue, pos) => {
652
+ const { unitId, subUnitId } = pos, { formula1, formula2 } = this.parseFormulaSync(rule, unitId, subUnitId), valueStr = `${cellValue != null ? cellValue : ""}`;
653
+ return !valueStr || valueStr === `${formula1}` || valueStr === `${formula2}`;
654
+ }, "skipDefaultFontRender"));
655
+ }
656
+ validatorFormula(rule, unitId, subUnitId) {
657
+ const { formula1, formula2 } = rule, isEqual = formula1 === formula2;
658
+ if (Tools.isBlank(formula1) && Tools.isBlank(formula2))
650
659
  return {
651
660
  success: !0
652
661
  };
653
- if (n)
662
+ if (isEqual)
654
663
  return {
655
664
  success: !1,
656
665
  formula1: this.localeService.t("dataValidation.validFail.checkboxEqual"),
657
666
  formula2: this.localeService.t("dataValidation.validFail.checkboxEqual")
658
667
  };
659
- const l = et(i, this.localeService), u = et(o, this.localeService);
668
+ const error1 = getFailMessage(formula1, this.localeService), error2 = getFailMessage(formula2, this.localeService);
660
669
  return {
661
- success: !l && !u,
662
- formula1: l,
663
- formula2: u
670
+ success: !error1 && !error2,
671
+ formula1: error1,
672
+ formula2: error2
664
673
  };
665
674
  }
666
- async parseFormula(e, t, r) {
667
- var c, m, _, g;
668
- const { formula1: i = Ve, formula2: o = Me } = e, n = await this._formulaService.getRuleFormulaResult(t, r, e.uid), l = v(i) ? se((m = (c = n == null ? void 0 : n[0]) == null ? void 0 : c.result) == null ? void 0 : m[0][0]) : i, u = v(o) ? se((g = (_ = n == null ? void 0 : n[1]) == null ? void 0 : _.result) == null ? void 0 : g[0][0]) : o, d = C(String(l)) && C(String(u));
675
+ async parseFormula(rule, unitId, subUnitId) {
676
+ var _a12, _b, _c, _d;
677
+ const { formula1 = CHECKBOX_FORMULA_1, formula2 = CHECKBOX_FORMULA_2 } = rule, results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), originFormula1 = isFormulaString(formula1) ? getFormulaResult((_b = (_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result) == null ? void 0 : _b[0][0]) : formula1, originFormula2 = isFormulaString(formula2) ? getFormulaResult((_d = (_c = results == null ? void 0 : results[1]) == null ? void 0 : _c.result) == null ? void 0 : _d[0][0]) : formula2, isFormulaValid = isLegalFormulaResult(String(originFormula1)) && isLegalFormulaResult(String(originFormula2));
669
678
  return {
670
- formula1: _e(l),
671
- formula2: _e(u),
672
- originFormula1: l,
673
- originFormula2: u,
674
- isFormulaValid: d
679
+ formula1: transformCheckboxValue(originFormula1),
680
+ formula2: transformCheckboxValue(originFormula2),
681
+ originFormula1,
682
+ originFormula2,
683
+ isFormulaValid
675
684
  };
676
685
  }
677
- getExtraStyle(e, t) {
686
+ getExtraStyle(rule, value) {
678
687
  return {
679
- tb: Se.CLIP
688
+ tb: WrapStrategy.CLIP
680
689
  };
681
690
  }
682
- parseFormulaSync(e, t, r) {
683
- var c, m, _, g;
684
- const { formula1: i = Ve, formula2: o = Me } = e, n = this._formulaService.getRuleFormulaResultSync(t, r, e.uid), l = v(i) ? se((m = (c = n == null ? void 0 : n[0]) == null ? void 0 : c.result) == null ? void 0 : m[0][0]) : i, u = v(o) ? se((g = (_ = n == null ? void 0 : n[1]) == null ? void 0 : _.result) == null ? void 0 : g[0][0]) : o, d = C(String(l)) && C(String(u));
691
+ parseFormulaSync(rule, unitId, subUnitId) {
692
+ var _a12, _b, _c, _d;
693
+ const { formula1 = CHECKBOX_FORMULA_1, formula2 = CHECKBOX_FORMULA_2 } = rule, results = this._formulaService.getRuleFormulaResultSync(unitId, subUnitId, rule.uid), originFormula1 = isFormulaString(formula1) ? getFormulaResult((_b = (_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result) == null ? void 0 : _b[0][0]) : formula1, originFormula2 = isFormulaString(formula2) ? getFormulaResult((_d = (_c = results == null ? void 0 : results[1]) == null ? void 0 : _c.result) == null ? void 0 : _d[0][0]) : formula2, isFormulaValid = isLegalFormulaResult(String(originFormula1)) && isLegalFormulaResult(String(originFormula2));
685
694
  return {
686
- formula1: _e(l),
687
- formula2: _e(u),
688
- originFormula1: l,
689
- originFormula2: u,
690
- isFormulaValid: d
695
+ formula1: transformCheckboxValue(originFormula1),
696
+ formula2: transformCheckboxValue(originFormula2),
697
+ originFormula1,
698
+ originFormula2,
699
+ isFormulaValid
691
700
  };
692
701
  }
693
- async isValidType(e, t, r) {
694
- const { value: i, unitId: o, subUnitId: n } = e, { formula1: l, formula2: u, originFormula1: d, originFormula2: c } = await this.parseFormula(r, o, n);
695
- return !V.isDefine(l) || !V.isDefine(u) ? !0 : V.isDefine(i) && (String(i) === String(l) || String(i) === String(u) || String(i) === String(d != null ? d : "") || String(i) === String(c != null ? c : ""));
702
+ async isValidType(cellInfo, formula, rule) {
703
+ const { value, unitId, subUnitId } = cellInfo, { formula1, formula2, originFormula1, originFormula2 } = await this.parseFormula(rule, unitId, subUnitId);
704
+ return !Tools.isDefine(formula1) || !Tools.isDefine(formula2) ? !0 : Tools.isDefine(value) && (String(value) === String(formula1) || String(value) === String(formula2) || String(value) === String(originFormula1 != null ? originFormula1 : "") || String(value) === String(originFormula2 != null ? originFormula2 : ""));
696
705
  }
697
- generateRuleErrorMessage(e) {
706
+ generateRuleErrorMessage(rule) {
698
707
  return this.localeService.t("dataValidation.checkbox.error");
699
708
  }
700
- }
701
- const na = {
702
- [h.BETWEEN]: "dataValidation.date.operators.between",
703
- [h.EQUAL]: "dataValidation.date.operators.equal",
704
- [h.GREATER_THAN]: "dataValidation.date.operators.greaterThan",
705
- [h.GREATER_THAN_OR_EQUAL]: "dataValidation.date.operators.greaterThanOrEqual",
706
- [h.LESS_THAN]: "dataValidation.date.operators.lessThan",
707
- [h.LESS_THAN_OR_EQUAL]: "dataValidation.date.operators.lessThanOrEqual",
708
- [h.NOT_BETWEEN]: "dataValidation.date.operators.notBetween",
709
- [h.NOT_EQUAL]: "dataValidation.date.operators.notEqual"
710
709
  };
711
- h.BETWEEN + "", h.EQUAL + "", h.GREATER_THAN + "", h.GREATER_THAN_OR_EQUAL + "", h.LESS_THAN + "", h.LESS_THAN_OR_EQUAL + "", h.NOT_BETWEEN + "", h.NOT_EQUAL + "";
712
- const la = {
713
- [h.BETWEEN]: "dataValidation.date.ruleName.between",
714
- [h.EQUAL]: "dataValidation.date.ruleName.equal",
715
- [h.GREATER_THAN]: "dataValidation.date.ruleName.greaterThan",
716
- [h.GREATER_THAN_OR_EQUAL]: "dataValidation.date.ruleName.greaterThanOrEqual",
717
- [h.LESS_THAN]: "dataValidation.date.ruleName.lessThan",
718
- [h.LESS_THAN_OR_EQUAL]: "dataValidation.date.ruleName.lessThanOrEqual",
719
- [h.NOT_BETWEEN]: "dataValidation.date.ruleName.notBetween",
720
- [h.NOT_EQUAL]: "dataValidation.date.ruleName.notEqual"
721
- }, ua = {
722
- [h.BETWEEN]: "dataValidation.date.errorMsg.between",
723
- [h.EQUAL]: "dataValidation.date.errorMsg.equal",
724
- [h.GREATER_THAN]: "dataValidation.date.errorMsg.greaterThan",
725
- [h.GREATER_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.greaterThanOrEqual",
726
- [h.LESS_THAN]: "dataValidation.date.errorMsg.lessThan",
727
- [h.LESS_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.lessThanOrEqual",
728
- [h.NOT_BETWEEN]: "dataValidation.date.errorMsg.notBetween",
729
- [h.NOT_EQUAL]: "dataValidation.date.errorMsg.notEqual"
730
- }, Ae = [
731
- h.BETWEEN,
732
- h.NOT_BETWEEN
733
- ], le = "{FORMULA1}", ue = "{FORMULA2}";
734
- function rr(s) {
735
- return s.filter(Boolean).join(",");
710
+ __name(_CheckboxValidator, "CheckboxValidator");
711
+ let CheckboxValidator = _CheckboxValidator;
712
+ const DateOperatorNameMap = {
713
+ [DataValidationOperator.BETWEEN]: "dataValidation.date.operators.between",
714
+ [DataValidationOperator.EQUAL]: "dataValidation.date.operators.equal",
715
+ [DataValidationOperator.GREATER_THAN]: "dataValidation.date.operators.greaterThan",
716
+ [DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.operators.greaterThanOrEqual",
717
+ [DataValidationOperator.LESS_THAN]: "dataValidation.date.operators.lessThan",
718
+ [DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.operators.lessThanOrEqual",
719
+ [DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.operators.notBetween",
720
+ [DataValidationOperator.NOT_EQUAL]: "dataValidation.date.operators.notEqual"
721
+ };
722
+ DataValidationOperator.BETWEEN + "", DataValidationOperator.EQUAL + "", DataValidationOperator.GREATER_THAN + "", DataValidationOperator.GREATER_THAN_OR_EQUAL + "", DataValidationOperator.LESS_THAN + "", DataValidationOperator.LESS_THAN_OR_EQUAL + "", DataValidationOperator.NOT_BETWEEN + "", DataValidationOperator.NOT_EQUAL + "";
723
+ const DateOperatorTitleMap = {
724
+ [DataValidationOperator.BETWEEN]: "dataValidation.date.ruleName.between",
725
+ [DataValidationOperator.EQUAL]: "dataValidation.date.ruleName.equal",
726
+ [DataValidationOperator.GREATER_THAN]: "dataValidation.date.ruleName.greaterThan",
727
+ [DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.ruleName.greaterThanOrEqual",
728
+ [DataValidationOperator.LESS_THAN]: "dataValidation.date.ruleName.lessThan",
729
+ [DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.ruleName.lessThanOrEqual",
730
+ [DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.ruleName.notBetween",
731
+ [DataValidationOperator.NOT_EQUAL]: "dataValidation.date.ruleName.notEqual"
732
+ }, DateOperatorErrorTitleMap = {
733
+ [DataValidationOperator.BETWEEN]: "dataValidation.date.errorMsg.between",
734
+ [DataValidationOperator.EQUAL]: "dataValidation.date.errorMsg.equal",
735
+ [DataValidationOperator.GREATER_THAN]: "dataValidation.date.errorMsg.greaterThan",
736
+ [DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.greaterThanOrEqual",
737
+ [DataValidationOperator.LESS_THAN]: "dataValidation.date.errorMsg.lessThan",
738
+ [DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.date.errorMsg.lessThanOrEqual",
739
+ [DataValidationOperator.NOT_BETWEEN]: "dataValidation.date.errorMsg.notBetween",
740
+ [DataValidationOperator.NOT_EQUAL]: "dataValidation.date.errorMsg.notEqual"
741
+ }, TWO_FORMULA_OPERATOR_COUNT = [
742
+ DataValidationOperator.BETWEEN,
743
+ DataValidationOperator.NOT_BETWEEN
744
+ ], FORMULA1 = "{FORMULA1}", FORMULA2 = "{FORMULA2}";
745
+ function serializeListOptions(options) {
746
+ return options.filter(Boolean).join(",");
736
747
  }
737
- function pe(s) {
738
- return s.split(",").filter(Boolean);
748
+ __name(serializeListOptions, "serializeListOptions");
749
+ function deserializeListOptions(optionsStr) {
750
+ return optionsStr.split(",").filter(Boolean);
739
751
  }
740
- function ir(s) {
741
- const a = ne(s);
742
- return a == null ? "" : a.toString();
752
+ __name(deserializeListOptions, "deserializeListOptions");
753
+ function getDataValidationCellValue(cellData) {
754
+ const cellValue = getCellValueOrigin(cellData);
755
+ return cellValue == null ? "" : cellValue.toString();
743
756
  }
744
- function De(s, a, e) {
745
- const { formula1: t, formula2: r } = a, i = a.ranges[0].startRow, o = a.ranges[0].startColumn, n = e.row - i, l = e.col - o, u = v(t) ? s.moveFormulaRefOffset(t, l, n, !0) : t, d = v(r) ? s.moveFormulaRefOffset(r, l, n, !0) : r;
757
+ __name(getDataValidationCellValue, "getDataValidationCellValue");
758
+ function getTransformedFormula(lexerTreeBuilder, rule, position) {
759
+ const { formula1, formula2 } = rule, originStartRow = rule.ranges[0].startRow, originStartColumn = rule.ranges[0].startColumn, offsetRow = position.row - originStartRow, offsetColumn = position.col - originStartColumn, transformedFormula1 = isFormulaString(formula1) ? lexerTreeBuilder.moveFormulaRefOffset(formula1, offsetColumn, offsetRow, !0) : formula1, transformedFormula2 = isFormulaString(formula2) ? lexerTreeBuilder.moveFormulaRefOffset(formula2, offsetColumn, offsetRow, !0) : formula2;
746
760
  return {
747
- transformedFormula1: u,
748
- transformedFormula2: d
761
+ transformedFormula1,
762
+ transformedFormula2
749
763
  };
750
764
  }
751
- const Ue = (s) => {
752
- var e, t;
753
- if (s == null || typeof s == "boolean")
765
+ __name(getTransformedFormula, "getTransformedFormula");
766
+ const transformDate2SerialNumber = /* @__PURE__ */ __name((value) => {
767
+ var _a12, _b;
768
+ if (value == null || typeof value == "boolean")
754
769
  return;
755
- if (typeof s == "number" || !Number.isNaN(+s))
756
- return +s;
757
- const a = (e = Q.parseDate(s)) == null ? void 0 : e.v;
758
- return V.isDefine(a) ? a : (t = Q.parseDate(at(s).format("YYYY-MM-DD HH:mm:ss"))) == null ? void 0 : t.v;
759
- };
760
- class da extends k {
770
+ if (typeof value == "number" || !Number.isNaN(+value))
771
+ return +value;
772
+ const v = (_a12 = numfmt.parseDate(value)) == null ? void 0 : _a12.v;
773
+ return Tools.isDefine(v) ? v : (_b = numfmt.parseDate(dayjs(value).format("YYYY-MM-DD HH:mm:ss"))) == null ? void 0 : _b.v;
774
+ }, "transformDate2SerialNumber"), _DateValidator = class _DateValidator extends BaseDataValidator {
761
775
  constructor() {
762
776
  super(...arguments);
763
- f(this, "id", T.DATE);
764
- f(this, "title", "dataValidation.date.title");
765
- f(this, "operators", [
766
- h.BETWEEN,
767
- h.EQUAL,
768
- h.GREATER_THAN,
769
- h.GREATER_THAN_OR_EQUAL,
770
- h.LESS_THAN,
771
- h.LESS_THAN_OR_EQUAL,
772
- h.NOT_BETWEEN,
773
- h.NOT_EQUAL
777
+ __publicField(this, "id", DataValidationType.DATE);
778
+ __publicField(this, "title", "dataValidation.date.title");
779
+ __publicField(this, "operators", [
780
+ DataValidationOperator.BETWEEN,
781
+ DataValidationOperator.EQUAL,
782
+ DataValidationOperator.GREATER_THAN,
783
+ DataValidationOperator.GREATER_THAN_OR_EQUAL,
784
+ DataValidationOperator.LESS_THAN,
785
+ DataValidationOperator.LESS_THAN_OR_EQUAL,
786
+ DataValidationOperator.NOT_BETWEEN,
787
+ DataValidationOperator.NOT_EQUAL
774
788
  ]);
775
- f(this, "scopes", ["sheet"]);
776
- f(this, "_customFormulaService", this.injector.get(P));
777
- f(this, "_lexerTreeBuilder", this.injector.get(Z));
789
+ __publicField(this, "scopes", ["sheet"]);
790
+ __publicField(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
791
+ __publicField(this, "_lexerTreeBuilder", this.injector.get(LexerTreeBuilder));
778
792
  }
779
- async parseFormula(e, t, r, i, o) {
780
- const n = await this._customFormulaService.getCellFormulaValue(t, r, e.uid, i, o), l = await this._customFormulaService.getCellFormula2Value(t, r, e.uid, i, o), { formula1: u, formula2: d } = e, c = C(String(n == null ? void 0 : n.v)) && C(String(l == null ? void 0 : l.v));
793
+ async parseFormula(rule, unitId, subUnitId, row, column) {
794
+ const formulaResult1 = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, rule.uid, row, column), formulaResult2 = await this._customFormulaService.getCellFormula2Value(unitId, subUnitId, rule.uid, row, column), { formula1, formula2 } = rule, isFormulaValid = isLegalFormulaResult(String(formulaResult1 == null ? void 0 : formulaResult1.v)) && isLegalFormulaResult(String(formulaResult2 == null ? void 0 : formulaResult2.v));
781
795
  return {
782
- formula1: Ue(v(u) ? n == null ? void 0 : n.v : u),
783
- formula2: Ue(v(d) ? l == null ? void 0 : l.v : d),
784
- isFormulaValid: c
796
+ formula1: transformDate2SerialNumber(isFormulaString(formula1) ? formulaResult1 == null ? void 0 : formulaResult1.v : formula1),
797
+ formula2: transformDate2SerialNumber(isFormulaString(formula2) ? formulaResult2 == null ? void 0 : formulaResult2.v : formula2),
798
+ isFormulaValid
785
799
  };
786
800
  }
787
- async isValidType(e) {
788
- const { interceptValue: t, value: r } = e;
789
- return typeof r == "number" && typeof t == "string" ? !0 : typeof t == "string" ? !!Q.parseDate(t) : !1;
801
+ async isValidType(info) {
802
+ const { interceptValue, value } = info;
803
+ return typeof value == "number" && typeof interceptValue == "string" ? !0 : typeof interceptValue == "string" ? !!numfmt.parseDate(interceptValue) : !1;
790
804
  }
791
- _validatorSingleFormula(e) {
792
- return !V.isBlank(e) && (v(e) || !Number.isNaN(+e) || !!(e && Q.parseDate(e)));
805
+ _validatorSingleFormula(formula) {
806
+ return !Tools.isBlank(formula) && (isFormulaString(formula) || !Number.isNaN(+formula) || !!(formula && numfmt.parseDate(formula)));
793
807
  }
794
- validatorFormula(e, t, r) {
795
- const i = e.operator;
796
- if (!i)
808
+ validatorFormula(rule, unitId, subUnitId) {
809
+ const operator = rule.operator;
810
+ if (!operator)
797
811
  return {
798
812
  success: !1
799
813
  };
800
- const o = this._validatorSingleFormula(e.formula1), n = this.localeService.t("dataValidation.validFail.date");
801
- if (Ae.includes(i)) {
802
- const u = this._validatorSingleFormula(e.formula2);
814
+ const formula1Success = this._validatorSingleFormula(rule.formula1), errorMsg = this.localeService.t("dataValidation.validFail.date");
815
+ if (TWO_FORMULA_OPERATOR_COUNT.includes(operator)) {
816
+ const formula2Success = this._validatorSingleFormula(rule.formula2);
803
817
  return {
804
- success: o && u,
805
- formula1: o ? void 0 : n,
806
- formula2: u ? void 0 : n
818
+ success: formula1Success && formula2Success,
819
+ formula1: formula1Success ? void 0 : errorMsg,
820
+ formula2: formula2Success ? void 0 : errorMsg
807
821
  };
808
822
  }
809
823
  return {
810
- success: o,
811
- formula1: o ? void 0 : n
824
+ success: formula1Success,
825
+ formula1: formula1Success ? void 0 : errorMsg
812
826
  };
813
827
  }
814
- normalizeFormula(e, t, r) {
815
- const { formula1: i, formula2: o, bizInfo: n } = e, l = (u) => {
816
- var c;
817
- if (!u)
818
- return u;
819
- let d;
820
- if (!Number.isNaN(+u))
821
- d = Q.dateFromSerial(+u);
828
+ normalizeFormula(rule, _unitId, _subUnitId) {
829
+ const { formula1, formula2, bizInfo } = rule, normlizeSingleFormula = /* @__PURE__ */ __name((formula) => {
830
+ var _a12;
831
+ if (!formula)
832
+ return formula;
833
+ let date;
834
+ if (!Number.isNaN(+formula))
835
+ date = numfmt.dateFromSerial(+formula);
822
836
  else {
823
- const m = (c = Q.parseDate(u)) == null ? void 0 : c.v;
824
- if (m == null)
837
+ const res = (_a12 = numfmt.parseDate(formula)) == null ? void 0 : _a12.v;
838
+ if (res == null)
825
839
  return "";
826
- d = Q.dateFromSerial(m);
840
+ date = numfmt.dateFromSerial(res);
827
841
  }
828
- return at(`${d[0]}/${d[1]}/${d[2]} ${d[3]}:${d[4]}:${d[5]}`).format(n != null && n.showTime ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD");
829
- };
842
+ return dayjs(`${date[0]}/${date[1]}/${date[2]} ${date[3]}:${date[4]}:${date[5]}`).format(bizInfo != null && bizInfo.showTime ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD");
843
+ }, "normlizeSingleFormula");
830
844
  return {
831
- formula1: v(i) ? i : l(`${i}`),
832
- formula2: v(o) ? o : l(`${o}`)
845
+ formula1: isFormulaString(formula1) ? formula1 : normlizeSingleFormula(`${formula1}`),
846
+ formula2: isFormulaString(formula2) ? formula2 : normlizeSingleFormula(`${formula2}`)
833
847
  };
834
848
  }
835
- transform(e, t, r) {
836
- const { value: i } = e;
849
+ transform(cellInfo, _formula, _rule) {
850
+ const { value } = cellInfo;
837
851
  return {
838
- ...e,
839
- value: Ue(i)
852
+ ...cellInfo,
853
+ value: transformDate2SerialNumber(value)
840
854
  };
841
855
  }
842
856
  get operatorNames() {
843
- return this.operators.map((e) => this.localeService.t(na[e]));
857
+ return this.operators.map((operator) => this.localeService.t(DateOperatorNameMap[operator]));
844
858
  }
845
- generateRuleName(e) {
846
- var r, i;
847
- if (!e.operator)
859
+ generateRuleName(rule) {
860
+ var _a12, _b;
861
+ if (!rule.operator)
848
862
  return this.titleStr;
849
- const t = this.localeService.t(la[e.operator]).replace(le, (r = e.formula1) != null ? r : "").replace(ue, (i = e.formula2) != null ? i : "");
850
- return `${this.titleStr} ${t}`;
863
+ const ruleName = this.localeService.t(DateOperatorTitleMap[rule.operator]).replace(FORMULA1, (_a12 = rule.formula1) != null ? _a12 : "").replace(FORMULA2, (_b = rule.formula2) != null ? _b : "");
864
+ return `${this.titleStr} ${ruleName}`;
851
865
  }
852
- generateRuleErrorMessage(e, t) {
853
- if (!e.operator)
866
+ generateRuleErrorMessage(rule, pos) {
867
+ if (!rule.operator)
854
868
  return this.titleStr;
855
- const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
856
- return `${this.localeService.t(ua[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
869
+ const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, pos);
870
+ return `${this.localeService.t(DateOperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 != null ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 != null ? transformedFormula2 : "")}`;
857
871
  }
858
- }
859
- h.BETWEEN + "", h.EQUAL + "", h.GREATER_THAN + "", h.GREATER_THAN_OR_EQUAL + "", h.LESS_THAN + "", h.LESS_THAN_OR_EQUAL + "", h.NOT_BETWEEN + "", h.NOT_EQUAL + "";
860
- h.BETWEEN + "", h.EQUAL + "", h.GREATER_THAN + "", h.GREATER_THAN_OR_EQUAL + "", h.LESS_THAN + "", h.LESS_THAN_OR_EQUAL + "", h.NOT_BETWEEN + "", h.NOT_EQUAL + "";
861
- const ht = {
862
- [h.BETWEEN]: "dataValidation.errorMsg.between",
863
- [h.EQUAL]: "dataValidation.errorMsg.equal",
864
- [h.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
865
- [h.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual",
866
- [h.LESS_THAN]: "dataValidation.errorMsg.lessThan",
867
- [h.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
868
- [h.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
869
- [h.NOT_EQUAL]: "dataValidation.errorMsg.notEqual"
870
872
  };
871
- function ye(s) {
872
- let a = s;
873
- return typeof s == "string" ? ((s.startsWith("¥") || s.startsWith("$")) && (a = s.slice(1)), +a) : +s;
873
+ __name(_DateValidator, "DateValidator");
874
+ let DateValidator = _DateValidator;
875
+ DataValidationOperator.BETWEEN + "", DataValidationOperator.EQUAL + "", DataValidationOperator.GREATER_THAN + "", DataValidationOperator.GREATER_THAN_OR_EQUAL + "", DataValidationOperator.LESS_THAN + "", DataValidationOperator.LESS_THAN_OR_EQUAL + "", DataValidationOperator.NOT_BETWEEN + "", DataValidationOperator.NOT_EQUAL + "";
876
+ DataValidationOperator.BETWEEN + "", DataValidationOperator.EQUAL + "", DataValidationOperator.GREATER_THAN + "", DataValidationOperator.GREATER_THAN_OR_EQUAL + "", DataValidationOperator.LESS_THAN + "", DataValidationOperator.LESS_THAN_OR_EQUAL + "", DataValidationOperator.NOT_BETWEEN + "", DataValidationOperator.NOT_EQUAL + "";
877
+ const OperatorErrorTitleMap = {
878
+ [DataValidationOperator.BETWEEN]: "dataValidation.errorMsg.between",
879
+ [DataValidationOperator.EQUAL]: "dataValidation.errorMsg.equal",
880
+ [DataValidationOperator.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
881
+ [DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual",
882
+ [DataValidationOperator.LESS_THAN]: "dataValidation.errorMsg.lessThan",
883
+ [DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
884
+ [DataValidationOperator.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
885
+ [DataValidationOperator.NOT_EQUAL]: "dataValidation.errorMsg.notEqual"
886
+ };
887
+ function getCellValueNumber(cellValue) {
888
+ let str = cellValue;
889
+ return typeof cellValue == "string" ? ((cellValue.startsWith("¥") || cellValue.startsWith("$")) && (str = cellValue.slice(1)), +str) : +cellValue;
874
890
  }
875
- class ca extends k {
891
+ __name(getCellValueNumber, "getCellValueNumber");
892
+ const _DecimalValidator = class _DecimalValidator extends BaseDataValidator {
876
893
  constructor() {
877
894
  super(...arguments);
878
- f(this, "_customFormulaService", this.injector.get(P));
879
- f(this, "id", T.DECIMAL);
880
- f(this, "_lexerTreeBuilder", this.injector.get(Z));
881
- f(this, "title", "dataValidation.decimal.title");
882
- f(this, "operators", [
883
- h.BETWEEN,
884
- h.EQUAL,
885
- h.GREATER_THAN,
886
- h.GREATER_THAN_OR_EQUAL,
887
- h.LESS_THAN,
888
- h.LESS_THAN_OR_EQUAL,
889
- h.NOT_BETWEEN,
890
- h.NOT_EQUAL
895
+ __publicField(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
896
+ __publicField(this, "id", DataValidationType.DECIMAL);
897
+ __publicField(this, "_lexerTreeBuilder", this.injector.get(LexerTreeBuilder));
898
+ __publicField(this, "title", "dataValidation.decimal.title");
899
+ __publicField(this, "operators", [
900
+ DataValidationOperator.BETWEEN,
901
+ DataValidationOperator.EQUAL,
902
+ DataValidationOperator.GREATER_THAN,
903
+ DataValidationOperator.GREATER_THAN_OR_EQUAL,
904
+ DataValidationOperator.LESS_THAN,
905
+ DataValidationOperator.LESS_THAN_OR_EQUAL,
906
+ DataValidationOperator.NOT_BETWEEN,
907
+ DataValidationOperator.NOT_EQUAL
891
908
  ]);
892
- f(this, "scopes", ["sheet"]);
909
+ __publicField(this, "scopes", ["sheet"]);
893
910
  }
894
- _isFormulaOrNumber(e) {
895
- return !V.isBlank(e) && (v(e) || !Number.isNaN(+e));
911
+ _isFormulaOrNumber(formula) {
912
+ return !Tools.isBlank(formula) && (isFormulaString(formula) || !Number.isNaN(+formula));
896
913
  }
897
- async isValidType(e, t, r) {
898
- const { value: i } = e;
899
- return !Number.isNaN(ye(i));
914
+ async isValidType(cellInfo, formula, rule) {
915
+ const { value: cellValue } = cellInfo;
916
+ return !Number.isNaN(getCellValueNumber(cellValue));
900
917
  }
901
- transform(e, t, r) {
902
- const { value: i } = e;
918
+ transform(cellInfo, formula, rule) {
919
+ const { value: cellValue } = cellInfo;
903
920
  return {
904
- ...e,
905
- value: ye(i)
921
+ ...cellInfo,
922
+ value: getCellValueNumber(cellValue)
906
923
  };
907
924
  }
908
- _parseNumber(e) {
909
- return e == null ? Number.NaN : +e;
925
+ _parseNumber(formula) {
926
+ return formula == null ? Number.NaN : +formula;
910
927
  }
911
- async parseFormula(e, t, r, i, o) {
912
- const n = await this._customFormulaService.getCellFormulaValue(t, r, e.uid, i, o), l = await this._customFormulaService.getCellFormula2Value(t, r, e.uid, i, o), { formula1: u, formula2: d } = e, c = C(String(n == null ? void 0 : n.v)) && C(String(l == null ? void 0 : l.v));
928
+ async parseFormula(rule, unitId, subUnitId, row, column) {
929
+ const formulaResult1 = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, rule.uid, row, column), formulaResult2 = await this._customFormulaService.getCellFormula2Value(unitId, subUnitId, rule.uid, row, column), { formula1, formula2 } = rule, isFormulaValid = isLegalFormulaResult(String(formulaResult1 == null ? void 0 : formulaResult1.v)) && isLegalFormulaResult(String(formulaResult2 == null ? void 0 : formulaResult2.v));
913
930
  return {
914
- formula1: this._parseNumber(v(u) ? n == null ? void 0 : n.v : u),
915
- formula2: this._parseNumber(v(d) ? l == null ? void 0 : l.v : d),
916
- isFormulaValid: c
931
+ formula1: this._parseNumber(isFormulaString(formula1) ? formulaResult1 == null ? void 0 : formulaResult1.v : formula1),
932
+ formula2: this._parseNumber(isFormulaString(formula2) ? formulaResult2 == null ? void 0 : formulaResult2.v : formula2),
933
+ isFormulaValid
917
934
  };
918
935
  }
919
- validatorFormula(e, t, r) {
920
- const i = e.operator;
921
- if (!i)
936
+ validatorFormula(rule, unitId, subUnitId) {
937
+ const operator = rule.operator;
938
+ if (!operator)
922
939
  return {
923
940
  success: !1
924
941
  };
925
- const o = V.isDefine(e.formula1) && this._isFormulaOrNumber(e.formula1), n = V.isDefine(e.formula2) && this._isFormulaOrNumber(e.formula2), l = Ae.includes(i), u = this.localeService.t("dataValidation.validFail.number");
926
- return l ? {
927
- success: o && n,
928
- formula1: o ? void 0 : u,
929
- formula2: n ? void 0 : u
942
+ const formula1Success = Tools.isDefine(rule.formula1) && this._isFormulaOrNumber(rule.formula1), formula2Success = Tools.isDefine(rule.formula2) && this._isFormulaOrNumber(rule.formula2), isTwoFormula = TWO_FORMULA_OPERATOR_COUNT.includes(operator), errorMsg = this.localeService.t("dataValidation.validFail.number");
943
+ return isTwoFormula ? {
944
+ success: formula1Success && formula2Success,
945
+ formula1: formula1Success ? void 0 : errorMsg,
946
+ formula2: formula2Success ? void 0 : errorMsg
930
947
  } : {
931
- success: o,
932
- formula1: o ? "" : u
948
+ success: formula1Success,
949
+ formula1: formula1Success ? "" : errorMsg
933
950
  };
934
951
  }
935
- generateRuleErrorMessage(e, t) {
936
- if (!e.operator)
952
+ generateRuleErrorMessage(rule, position) {
953
+ if (!rule.operator)
937
954
  return this.titleStr;
938
- const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
939
- return `${this.localeService.t(ht[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
955
+ const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, position);
956
+ return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 != null ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 != null ? transformedFormula2 : "")}`;
940
957
  }
941
- }
942
- function Pe(s) {
943
- if (!s)
958
+ };
959
+ __name(_DecimalValidator, "DecimalValidator");
960
+ let DecimalValidator = _DecimalValidator;
961
+ function getRuleFormulaResultSet(result) {
962
+ if (!result)
944
963
  return [];
945
- const a = /* @__PURE__ */ new Set();
946
- return s.forEach(
947
- (e) => {
948
- e.forEach((t) => {
949
- var i, o;
950
- const r = ne(t);
951
- if (r != null) {
952
- if (typeof r != "string" && typeof (t == null ? void 0 : t.s) == "object" && ((o = (i = t.s) == null ? void 0 : i.n) != null && o.pattern)) {
953
- a.add(Q.format(t.s.n.pattern, r, { throws: !1 }));
964
+ const resultSet = /* @__PURE__ */ new Set();
965
+ return result.forEach(
966
+ (row) => {
967
+ row.forEach((cell) => {
968
+ var _a12, _b;
969
+ const value = getCellValueOrigin(cell);
970
+ if (value != null) {
971
+ if (typeof value != "string" && typeof (cell == null ? void 0 : cell.s) == "object" && ((_b = (_a12 = cell.s) == null ? void 0 : _a12.n) != null && _b.pattern)) {
972
+ resultSet.add(numfmt.format(cell.s.n.pattern, value, { throws: !1 }));
954
973
  return;
955
974
  }
956
- C(r.toString()) && a.add(r.toString());
975
+ isLegalFormulaResult(value.toString()) && resultSet.add(value.toString());
957
976
  }
958
977
  });
959
978
  }
960
- ), [...a];
979
+ ), [...resultSet];
961
980
  }
962
- const ha = [
981
+ __name(getRuleFormulaResultSet, "getRuleFormulaResultSet");
982
+ const supportedFormula = [
963
983
  "if",
964
984
  "indirect",
965
985
  "choose",
966
986
  "offset"
967
987
  ];
968
- function ma(s, a) {
969
- if (!v(s) || dt(s.slice(1)))
988
+ function isValidListFormula(formula, lexer) {
989
+ if (!isFormulaString(formula) || isReferenceString(formula.slice(1)))
970
990
  return !0;
971
- const t = a.sequenceNodesBuilder(s);
972
- return t && t.some((r) => typeof r == "object" && r.nodeType === Qt.FUNCTION && ha.indexOf(r.token.toLowerCase()) > -1);
991
+ const nodes = lexer.sequenceNodesBuilder(formula);
992
+ return nodes && nodes.some((node) => typeof node == "object" && node.nodeType === sequenceNodeType.FUNCTION && supportedFormula.indexOf(node.token.toLowerCase()) > -1);
973
993
  }
974
- function fa(s, a) {
975
- const { formula1: e = "", ranges: t } = s;
976
- if (dt(e.slice(1))) {
977
- const i = qt(e.slice(1));
978
- if ((!i.sheetName || i.sheetName === a) && t.some((o) => I.intersects(o, i.range)))
994
+ __name(isValidListFormula, "isValidListFormula");
995
+ function isRuleIntersects(rule, sheetName) {
996
+ const { formula1 = "", ranges } = rule;
997
+ if (isReferenceString(formula1.slice(1))) {
998
+ const refRange = deserializeRangeWithSheet(formula1.slice(1));
999
+ if ((!refRange.sheetName || refRange.sheetName === sheetName) && ranges.some((range) => Rectangle.intersects(range, refRange.range)))
979
1000
  return !0;
980
1001
  }
981
1002
  return !1;
982
1003
  }
983
- class mt extends k {
1004
+ __name(isRuleIntersects, "isRuleIntersects");
1005
+ const _ListValidator = class _ListValidator extends BaseDataValidator {
984
1006
  constructor() {
985
1007
  super(...arguments);
986
- f(this, "formulaService", this.injector.get(X));
987
- f(this, "_lexer", this.injector.get(Z));
988
- f(this, "_univerInstanceService", this.injector.get(O));
989
- f(this, "offsetFormulaByRange", !1);
990
- f(this, "id", T.LIST);
991
- f(this, "title", "dataValidation.list.title");
992
- f(this, "operators", []);
993
- f(this, "scopes", ["sheet"]);
994
- f(this, "skipDefaultFontRender", (e) => e.renderMode !== Be.TEXT);
995
- }
996
- validatorFormula(e, t, r) {
997
- var u, d, c;
998
- const i = !V.isBlank(e.formula1), o = ma((u = e.formula1) != null ? u : "", this._lexer), n = (c = (d = this._univerInstanceService.getUnit(t, N.UNIVER_SHEET)) == null ? void 0 : d.getSheetBySheetId(r)) == null ? void 0 : c.getName(), l = fa(e, n != null ? n : "");
1008
+ __publicField(this, "formulaService", this.injector.get(DataValidationFormulaService));
1009
+ __publicField(this, "_lexer", this.injector.get(LexerTreeBuilder));
1010
+ __publicField(this, "_univerInstanceService", this.injector.get(IUniverInstanceService));
1011
+ __publicField(this, "offsetFormulaByRange", !1);
1012
+ __publicField(this, "id", DataValidationType.LIST);
1013
+ __publicField(this, "title", "dataValidation.list.title");
1014
+ __publicField(this, "operators", []);
1015
+ __publicField(this, "scopes", ["sheet"]);
1016
+ __publicField(this, "skipDefaultFontRender", /* @__PURE__ */ __name((rule) => rule.renderMode !== DataValidationRenderMode.TEXT, "skipDefaultFontRender"));
1017
+ }
1018
+ validatorFormula(rule, unitId, subUnitId) {
1019
+ var _a12, _b, _c;
1020
+ const success = !Tools.isBlank(rule.formula1), valid = isValidListFormula((_a12 = rule.formula1) != null ? _a12 : "", this._lexer), sheetName = (_c = (_b = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) == null ? void 0 : _b.getSheetBySheetId(subUnitId)) == null ? void 0 : _c.getName(), isIntersects = isRuleIntersects(rule, sheetName != null ? sheetName : "");
999
1021
  return {
1000
- success: !!(i && o && !l),
1001
- formula1: i ? o ? l ? this.localeService.t("dataValidation.validFail.listIntersects") : void 0 : this.localeService.t("dataValidation.validFail.listInvalid") : this.localeService.t("dataValidation.validFail.list")
1022
+ success: !!(success && valid && !isIntersects),
1023
+ formula1: success ? valid ? isIntersects ? this.localeService.t("dataValidation.validFail.listIntersects") : void 0 : this.localeService.t("dataValidation.validFail.listInvalid") : this.localeService.t("dataValidation.validFail.list")
1002
1024
  };
1003
1025
  }
1004
- getExtraStyle(e, t, { style: r }) {
1005
- var o;
1006
- const i = (o = r.tb !== Se.OVERFLOW ? r.tb : Se.CLIP) != null ? o : Se.WRAP;
1007
- if (e.type === T.LIST && (e.renderMode === Be.ARROW || e.renderMode === Be.TEXT)) {
1008
- const n = this.getListWithColorMap(e), l = `${t != null ? t : ""}`, u = n[l];
1009
- if (u)
1026
+ getExtraStyle(rule, value, { style: defaultStyle }) {
1027
+ var _a12;
1028
+ const tb = (_a12 = defaultStyle.tb !== WrapStrategy.OVERFLOW ? defaultStyle.tb : WrapStrategy.CLIP) != null ? _a12 : WrapStrategy.WRAP;
1029
+ if (rule.type === DataValidationType.LIST && (rule.renderMode === DataValidationRenderMode.ARROW || rule.renderMode === DataValidationRenderMode.TEXT)) {
1030
+ const colorMap = this.getListWithColorMap(rule), valueStr = `${value != null ? value : ""}`, color = colorMap[valueStr];
1031
+ if (color)
1010
1032
  return {
1011
1033
  bg: {
1012
- rgb: u
1034
+ rgb: color
1013
1035
  },
1014
- tb: i
1036
+ tb
1015
1037
  };
1016
1038
  }
1017
1039
  return {
1018
- tb: i
1040
+ tb
1019
1041
  };
1020
1042
  }
1021
- parseCellValue(e) {
1022
- const t = e.toString();
1023
- return pe(t);
1043
+ parseCellValue(cellValue) {
1044
+ const cellString = cellValue.toString();
1045
+ return deserializeListOptions(cellString);
1024
1046
  }
1025
- async parseFormula(e, t, r) {
1026
- var l, u;
1027
- const i = await this.formulaService.getRuleFormulaResult(t, r, e.uid), o = se((u = (l = i == null ? void 0 : i[0]) == null ? void 0 : l.result) == null ? void 0 : u[0][0]);
1047
+ async parseFormula(rule, unitId, subUnitId) {
1048
+ var _a12, _b;
1049
+ const results = await this.formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), formulaResult1 = getFormulaResult((_b = (_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result) == null ? void 0 : _b[0][0]);
1028
1050
  return {
1029
1051
  formula1: void 0,
1030
1052
  formula2: void 0,
1031
- isFormulaValid: C(String(o))
1053
+ isFormulaValid: isLegalFormulaResult(String(formulaResult1))
1032
1054
  };
1033
1055
  }
1034
- async isValidType(e, t, r) {
1035
- var m, _;
1036
- const { value: i, unitId: o, subUnitId: n } = e, { formula1: l = "" } = r, u = await this.formulaService.getRuleFormulaResult(o, n, r.uid), d = v(l) ? Pe((_ = (m = u == null ? void 0 : u[0]) == null ? void 0 : m.result) == null ? void 0 : _[0][0]) : pe(l);
1037
- return this.parseCellValue(i).every((g) => d.includes(g));
1056
+ async isValidType(cellInfo, formula, rule) {
1057
+ var _a12, _b;
1058
+ const { value, unitId, subUnitId } = cellInfo, { formula1 = "" } = rule, results = await this.formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), formula1Result = isFormulaString(formula1) ? getRuleFormulaResultSet((_b = (_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result) == null ? void 0 : _b[0][0]) : deserializeListOptions(formula1);
1059
+ return this.parseCellValue(value).every((i) => formula1Result.includes(i));
1038
1060
  }
1039
1061
  generateRuleName() {
1040
1062
  return this.localeService.t("dataValidation.list.name");
@@ -1042,1366 +1064,1383 @@ class mt extends k {
1042
1064
  generateRuleErrorMessage() {
1043
1065
  return this.localeService.t("dataValidation.list.error");
1044
1066
  }
1045
- getList(e, t, r) {
1046
- var m, _, g, R;
1047
- const { formula1: i = "" } = e, o = this.injector.get(O), n = (m = t ? o.getUniverSheetInstance(t) : void 0) != null ? m : o.getCurrentUnitForType(N.UNIVER_SHEET);
1048
- if (!n) return [];
1049
- const l = (_ = r ? n.getSheetBySheetId(r) : void 0) != null ? _ : n.getActiveSheet();
1050
- if (!l) return [];
1051
- const u = n.getUnitId(), d = l.getSheetId(), c = this.formulaService.getRuleFormulaResultSync(u, d, e.uid);
1052
- return v(i) ? Pe((R = (g = c == null ? void 0 : c[0]) == null ? void 0 : g.result) == null ? void 0 : R[0][0]) : pe(i);
1053
- }
1054
- async getListAsync(e, t, r) {
1055
- var m, _, g, R;
1056
- const { formula1: i = "" } = e, o = this.injector.get(O), n = (m = t ? o.getUniverSheetInstance(t) : void 0) != null ? m : o.getCurrentUnitForType(N.UNIVER_SHEET);
1057
- if (!n) return [];
1058
- const l = (_ = r ? n.getSheetBySheetId(r) : void 0) != null ? _ : n.getActiveSheet();
1059
- if (!l) return [];
1060
- const u = n.getUnitId(), d = l.getSheetId(), c = await this.formulaService.getRuleFormulaResult(u, d, e.uid);
1061
- return v(i) ? Pe((R = (g = c == null ? void 0 : c[0]) == null ? void 0 : g.result) == null ? void 0 : R[0][0]) : pe(i);
1062
- }
1063
- getListWithColor(e, t, r) {
1064
- const i = this.getList(e, t, r), o = (e.formula2 || "").split(",");
1065
- return i.map((n, l) => ({ label: n, color: o[l] }));
1066
- }
1067
- getListWithColorMap(e, t, r) {
1068
- const i = this.getListWithColor(e, t, r), o = {};
1069
- return i.forEach((n) => {
1070
- n.color && (o[n.label] = n.color);
1071
- }), o;
1067
+ getList(rule, currentUnitId, currentSubUnitId) {
1068
+ var _a12, _b, _c, _d;
1069
+ const { formula1 = "" } = rule, univerInstanceService = this.injector.get(IUniverInstanceService), workbook = (_a12 = currentUnitId ? univerInstanceService.getUniverSheetInstance(currentUnitId) : void 0) != null ? _a12 : univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
1070
+ if (!workbook) return [];
1071
+ const worksheet = (_b = currentSubUnitId ? workbook.getSheetBySheetId(currentSubUnitId) : void 0) != null ? _b : workbook.getActiveSheet();
1072
+ if (!worksheet) return [];
1073
+ const unitId = workbook.getUnitId(), subUnitId = worksheet.getSheetId(), results = this.formulaService.getRuleFormulaResultSync(unitId, subUnitId, rule.uid);
1074
+ return isFormulaString(formula1) ? getRuleFormulaResultSet((_d = (_c = results == null ? void 0 : results[0]) == null ? void 0 : _c.result) == null ? void 0 : _d[0][0]) : deserializeListOptions(formula1);
1075
+ }
1076
+ async getListAsync(rule, currentUnitId, currentSubUnitId) {
1077
+ var _a12, _b, _c, _d;
1078
+ const { formula1 = "" } = rule, univerInstanceService = this.injector.get(IUniverInstanceService), workbook = (_a12 = currentUnitId ? univerInstanceService.getUniverSheetInstance(currentUnitId) : void 0) != null ? _a12 : univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
1079
+ if (!workbook) return [];
1080
+ const worksheet = (_b = currentSubUnitId ? workbook.getSheetBySheetId(currentSubUnitId) : void 0) != null ? _b : workbook.getActiveSheet();
1081
+ if (!worksheet) return [];
1082
+ const unitId = workbook.getUnitId(), subUnitId = worksheet.getSheetId(), results = await this.formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);
1083
+ return isFormulaString(formula1) ? getRuleFormulaResultSet((_d = (_c = results == null ? void 0 : results[0]) == null ? void 0 : _c.result) == null ? void 0 : _d[0][0]) : deserializeListOptions(formula1);
1084
+ }
1085
+ getListWithColor(rule, currentUnitId, currentSubUnitId) {
1086
+ const list = this.getList(rule, currentUnitId, currentSubUnitId), colorList = (rule.formula2 || "").split(",");
1087
+ return list.map((label, i) => ({ label, color: colorList[i] }));
1088
+ }
1089
+ getListWithColorMap(rule, currentUnitId, currentSubUnitId) {
1090
+ const list = this.getListWithColor(rule, currentUnitId, currentSubUnitId), map = {};
1091
+ return list.forEach((item) => {
1092
+ item.color && (map[item.label] = item.color);
1093
+ }), map;
1072
1094
  }
1073
- }
1074
- class ga extends k {
1095
+ };
1096
+ __name(_ListValidator, "ListValidator");
1097
+ let ListValidator = _ListValidator;
1098
+ const _TextLengthValidator = class _TextLengthValidator extends BaseDataValidator {
1075
1099
  constructor() {
1076
1100
  super(...arguments);
1077
- f(this, "id", T.TEXT_LENGTH);
1078
- f(this, "title", "dataValidation.textLength.title");
1079
- f(this, "_lexerTreeBuilder", this.injector.get(Z));
1080
- f(this, "operators", [
1081
- h.BETWEEN,
1082
- h.EQUAL,
1083
- h.GREATER_THAN,
1084
- h.GREATER_THAN_OR_EQUAL,
1085
- h.LESS_THAN,
1086
- h.LESS_THAN_OR_EQUAL,
1087
- h.NOT_BETWEEN,
1088
- h.NOT_EQUAL
1101
+ __publicField(this, "id", DataValidationType.TEXT_LENGTH);
1102
+ __publicField(this, "title", "dataValidation.textLength.title");
1103
+ __publicField(this, "_lexerTreeBuilder", this.injector.get(LexerTreeBuilder));
1104
+ __publicField(this, "operators", [
1105
+ DataValidationOperator.BETWEEN,
1106
+ DataValidationOperator.EQUAL,
1107
+ DataValidationOperator.GREATER_THAN,
1108
+ DataValidationOperator.GREATER_THAN_OR_EQUAL,
1109
+ DataValidationOperator.LESS_THAN,
1110
+ DataValidationOperator.LESS_THAN_OR_EQUAL,
1111
+ DataValidationOperator.NOT_BETWEEN,
1112
+ DataValidationOperator.NOT_EQUAL
1089
1113
  ]);
1090
- f(this, "scopes", ["sheet"]);
1091
- f(this, "_customFormulaService", this.injector.get(P));
1114
+ __publicField(this, "scopes", ["sheet"]);
1115
+ __publicField(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
1092
1116
  }
1093
- _isFormulaOrInt(e) {
1094
- return !V.isBlank(e) && (v(e) || !Number.isNaN(+e) && Number.isInteger(+e));
1117
+ _isFormulaOrInt(formula) {
1118
+ return !Tools.isBlank(formula) && (isFormulaString(formula) || !Number.isNaN(+formula) && Number.isInteger(+formula));
1095
1119
  }
1096
- validatorFormula(e, t, r) {
1097
- const i = e.operator;
1098
- if (!i)
1120
+ validatorFormula(rule, _unitId, _subUnitId) {
1121
+ const operator = rule.operator;
1122
+ if (!operator)
1099
1123
  return {
1100
1124
  success: !1
1101
1125
  };
1102
- const o = V.isDefine(e.formula1) && this._isFormulaOrInt(e.formula1), n = V.isDefine(e.formula2) && this._isFormulaOrInt(e.formula2), l = Ae.includes(i), u = this.localeService.t("dataValidation.validFail.number");
1103
- return l ? {
1104
- success: o && n,
1105
- formula1: o ? void 0 : u,
1106
- formula2: n ? void 0 : u
1126
+ const formula1Success = Tools.isDefine(rule.formula1) && this._isFormulaOrInt(rule.formula1), formula2Success = Tools.isDefine(rule.formula2) && this._isFormulaOrInt(rule.formula2), isTwoFormula = TWO_FORMULA_OPERATOR_COUNT.includes(operator), errorMsg = this.localeService.t("dataValidation.validFail.number");
1127
+ return isTwoFormula ? {
1128
+ success: formula1Success && formula2Success,
1129
+ formula1: formula1Success ? void 0 : errorMsg,
1130
+ formula2: formula2Success ? void 0 : errorMsg
1107
1131
  } : {
1108
- success: o,
1109
- formula1: u
1132
+ success: formula1Success,
1133
+ formula1: errorMsg
1110
1134
  };
1111
1135
  }
1112
- _parseNumber(e) {
1113
- return e == null ? Number.NaN : +e;
1136
+ _parseNumber(formula) {
1137
+ return formula == null ? Number.NaN : +formula;
1114
1138
  }
1115
- async parseFormula(e, t, r, i, o) {
1116
- const n = await this._customFormulaService.getCellFormulaValue(t, r, e.uid, i, o), l = await this._customFormulaService.getCellFormula2Value(t, r, e.uid, i, o), { formula1: u, formula2: d } = e, c = C(String(n == null ? void 0 : n.v)) && C(String(l == null ? void 0 : l.v));
1139
+ async parseFormula(rule, unitId, subUnitId, row, column) {
1140
+ const formulaResult1 = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, rule.uid, row, column), formulaResult2 = await this._customFormulaService.getCellFormula2Value(unitId, subUnitId, rule.uid, row, column), { formula1, formula2 } = rule, isFormulaValid = isLegalFormulaResult(String(formulaResult1 == null ? void 0 : formulaResult1.v)) && isLegalFormulaResult(String(formulaResult2 == null ? void 0 : formulaResult2.v));
1117
1141
  return {
1118
- formula1: this._parseNumber(v(u) ? n == null ? void 0 : n.v : u),
1119
- formula2: this._parseNumber(v(d) ? l == null ? void 0 : l.v : d),
1120
- isFormulaValid: c
1142
+ formula1: this._parseNumber(isFormulaString(formula1) ? formulaResult1 == null ? void 0 : formulaResult1.v : formula1),
1143
+ formula2: this._parseNumber(isFormulaString(formula2) ? formulaResult2 == null ? void 0 : formulaResult2.v : formula2),
1144
+ isFormulaValid
1121
1145
  };
1122
1146
  }
1123
- transform(e, t, r) {
1147
+ transform(cellInfo, _formula, _rule) {
1124
1148
  return {
1125
- ...e,
1126
- value: e.value.toString().length
1149
+ ...cellInfo,
1150
+ value: cellInfo.value.toString().length
1127
1151
  };
1128
1152
  }
1129
- async isValidType(e, t, r) {
1130
- const { value: i } = e;
1131
- return typeof i == "string" || typeof i == "number";
1153
+ async isValidType(cellInfo, _formula, _rule) {
1154
+ const { value: cellValue } = cellInfo;
1155
+ return typeof cellValue == "string" || typeof cellValue == "number";
1132
1156
  }
1133
- generateRuleErrorMessage(e, t) {
1134
- if (!e.operator)
1157
+ generateRuleErrorMessage(rule, pos) {
1158
+ if (!rule.operator)
1135
1159
  return this.titleStr;
1136
- const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
1137
- return `${this.localeService.t(Dt[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
1160
+ const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, pos);
1161
+ return `${this.localeService.t(TextLengthErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 != null ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 != null ? transformedFormula2 : "")}`;
1138
1162
  }
1163
+ };
1164
+ __name(_TextLengthValidator, "TextLengthValidator");
1165
+ let TextLengthValidator = _TextLengthValidator;
1166
+ function isBlankCell(cellData) {
1167
+ var _a12, _b;
1168
+ return cellData ? cellData.p ? !((_b = (_a12 = cellData.p.body) == null ? void 0 : _a12.dataStream) != null ? _b : "").slice(0, -2).trim() : Tools.isBlank(cellData.v) : !0;
1139
1169
  }
1140
- function ft(s) {
1141
- var e, t;
1142
- return s ? s.p ? !((t = (e = s.p.body) == null ? void 0 : e.dataStream) != null ? t : "").slice(0, -2).trim() : V.isBlank(s.v) : !0;
1143
- }
1144
- function be(s, a, e, t, r = "command", i = !0) {
1145
- const o = t.get(Z), n = t.get(G), l = [], u = [], d = t.get(F), c = t.get(O), m = Ye(c, { unitId: s, subUnitId: a });
1146
- if (!m)
1170
+ __name(isBlankCell, "isBlankCell");
1171
+ function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, source = "command", fillDefaultValue = !0) {
1172
+ const lexerTreeBuilder = accessor.get(LexerTreeBuilder), validatorRegistryService = accessor.get(DataValidatorRegistryService), redoMutations = [], undoMutations = [], sheetDataValidationModel = accessor.get(SheetDataValidationModel), univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId });
1173
+ if (!target)
1147
1174
  return {
1148
- redoMutations: l,
1149
- undoMutations: u
1175
+ redoMutations,
1176
+ undoMutations
1150
1177
  };
1151
- const { worksheet: _ } = m, g = new ve();
1152
- let R = !1;
1153
- function M(p, w) {
1154
- i && p.forEach((H) => {
1155
- b.foreach(H, (B, W) => {
1156
- const U = _.getCellRaw(B, W), J = ct(U);
1157
- (ft(U) || J === w) && !(U != null && U.p) && (R = !0, g.setValue(B, W, {
1158
- v: w,
1178
+ const { worksheet } = target, redoMatrix = new ObjectMatrix();
1179
+ let setRangeValue = !1;
1180
+ function setRangesDefaultValue(ranges, defaultValue) {
1181
+ fillDefaultValue && ranges.forEach((range) => {
1182
+ Range.foreach(range, (row, column) => {
1183
+ const cellData = worksheet.getCellRaw(row, column), value = getStringCellValue(cellData);
1184
+ (isBlankCell(cellData) || value === defaultValue) && !(cellData != null && cellData.p) && (setRangeValue = !0, redoMatrix.setValue(row, column, {
1185
+ v: defaultValue,
1159
1186
  p: null
1160
1187
  }));
1161
1188
  });
1162
1189
  });
1163
1190
  }
1164
- if (e.forEach((p) => {
1165
- switch (p.type) {
1191
+ if (__name(setRangesDefaultValue, "setRangesDefaultValue"), diffs.forEach((diff) => {
1192
+ switch (diff.type) {
1166
1193
  case "delete":
1167
- l.push({
1168
- id: A.id,
1194
+ redoMutations.push({
1195
+ id: RemoveDataValidationMutation.id,
1169
1196
  params: {
1170
- unitId: s,
1171
- subUnitId: a,
1172
- ruleId: p.rule.uid,
1173
- source: r
1197
+ unitId,
1198
+ subUnitId,
1199
+ ruleId: diff.rule.uid,
1200
+ source
1174
1201
  }
1175
- }), u.unshift({
1176
- id: L.id,
1202
+ }), undoMutations.unshift({
1203
+ id: AddDataValidationMutation.id,
1177
1204
  params: {
1178
- unitId: s,
1179
- subUnitId: a,
1180
- rule: p.rule,
1181
- index: p.index,
1182
- source: r
1205
+ unitId,
1206
+ subUnitId,
1207
+ rule: diff.rule,
1208
+ index: diff.index,
1209
+ source
1183
1210
  }
1184
1211
  });
1185
1212
  break;
1186
1213
  case "update": {
1187
- if (de(p.rule.type, n)) {
1188
- const H = p.oldRanges[0].startRow, B = p.oldRanges[0].startColumn, W = p.newRanges[0].startRow, U = p.newRanges[0].startColumn, J = W - H, ce = U - B, he = v(p.rule.formula1) ? o.moveFormulaRefOffset(p.rule.formula1, ce, J) : p.rule.formula1, me = v(p.rule.formula2) ? o.moveFormulaRefOffset(p.rule.formula2, ce, J) : p.rule.formula2;
1189
- he !== p.rule.formula1 || me !== p.rule.formula2 || !rt(p.newRanges, p.oldRanges) ? (l.push({
1190
- id: E.id,
1214
+ if (shouldOffsetFormulaByRange(diff.rule.type, validatorRegistryService)) {
1215
+ const originRow = diff.oldRanges[0].startRow, originColumn = diff.oldRanges[0].startColumn, newRow = diff.newRanges[0].startRow, newColumn = diff.newRanges[0].startColumn, rowDiff = newRow - originRow, columnDiff = newColumn - originColumn, newFormula = isFormulaString(diff.rule.formula1) ? lexerTreeBuilder.moveFormulaRefOffset(diff.rule.formula1, columnDiff, rowDiff) : diff.rule.formula1, newFormula2 = isFormulaString(diff.rule.formula2) ? lexerTreeBuilder.moveFormulaRefOffset(diff.rule.formula2, columnDiff, rowDiff) : diff.rule.formula2;
1216
+ newFormula !== diff.rule.formula1 || newFormula2 !== diff.rule.formula2 || !isRangesEqual(diff.newRanges, diff.oldRanges) ? (redoMutations.push({
1217
+ id: UpdateDataValidationMutation.id,
1191
1218
  params: {
1192
- unitId: s,
1193
- subUnitId: a,
1194
- ruleId: p.ruleId,
1219
+ unitId,
1220
+ subUnitId,
1221
+ ruleId: diff.ruleId,
1195
1222
  payload: {
1196
- type: y.ALL,
1223
+ type: UpdateRuleType.ALL,
1197
1224
  payload: {
1198
- formula1: he,
1199
- formula2: me,
1200
- ranges: p.newRanges
1225
+ formula1: newFormula,
1226
+ formula2: newFormula2,
1227
+ ranges: diff.newRanges
1201
1228
  }
1202
1229
  }
1203
1230
  }
1204
- }), u.unshift({
1205
- id: E.id,
1231
+ }), undoMutations.unshift({
1232
+ id: UpdateDataValidationMutation.id,
1206
1233
  params: {
1207
- unitId: s,
1208
- subUnitId: a,
1209
- ruleId: p.ruleId,
1234
+ unitId,
1235
+ subUnitId,
1236
+ ruleId: diff.ruleId,
1210
1237
  payload: {
1211
- type: y.ALL,
1238
+ type: UpdateRuleType.ALL,
1212
1239
  payload: {
1213
- formula1: p.rule.formula1,
1214
- formula2: p.rule.formula2,
1215
- ranges: p.oldRanges
1240
+ formula1: diff.rule.formula1,
1241
+ formula2: diff.rule.formula2,
1242
+ ranges: diff.oldRanges
1216
1243
  }
1217
1244
  }
1218
1245
  }
1219
- })) : (l.push({
1220
- id: E.id,
1246
+ })) : (redoMutations.push({
1247
+ id: UpdateDataValidationMutation.id,
1221
1248
  params: {
1222
- unitId: s,
1223
- subUnitId: a,
1224
- ruleId: p.ruleId,
1249
+ unitId,
1250
+ subUnitId,
1251
+ ruleId: diff.ruleId,
1225
1252
  payload: {
1226
- type: y.RANGE,
1227
- payload: p.newRanges
1253
+ type: UpdateRuleType.RANGE,
1254
+ payload: diff.newRanges
1228
1255
  },
1229
- source: r
1256
+ source
1230
1257
  }
1231
- }), u.unshift({
1232
- id: E.id,
1258
+ }), undoMutations.unshift({
1259
+ id: UpdateDataValidationMutation.id,
1233
1260
  params: {
1234
- unitId: s,
1235
- subUnitId: a,
1236
- ruleId: p.ruleId,
1261
+ unitId,
1262
+ subUnitId,
1263
+ ruleId: diff.ruleId,
1237
1264
  payload: {
1238
- type: y.RANGE,
1239
- payload: p.oldRanges
1265
+ type: UpdateRuleType.RANGE,
1266
+ payload: diff.oldRanges
1240
1267
  },
1241
- source: r
1268
+ source
1242
1269
  }
1243
1270
  }));
1244
1271
  } else
1245
- l.push({
1246
- id: E.id,
1272
+ redoMutations.push({
1273
+ id: UpdateDataValidationMutation.id,
1247
1274
  params: {
1248
- unitId: s,
1249
- subUnitId: a,
1250
- ruleId: p.ruleId,
1275
+ unitId,
1276
+ subUnitId,
1277
+ ruleId: diff.ruleId,
1251
1278
  payload: {
1252
- type: y.RANGE,
1253
- payload: p.newRanges
1279
+ type: UpdateRuleType.RANGE,
1280
+ payload: diff.newRanges
1254
1281
  },
1255
- source: r
1282
+ source
1256
1283
  }
1257
- }), u.unshift({
1258
- id: E.id,
1284
+ }), undoMutations.unshift({
1285
+ id: UpdateDataValidationMutation.id,
1259
1286
  params: {
1260
- unitId: s,
1261
- subUnitId: a,
1262
- ruleId: p.ruleId,
1287
+ unitId,
1288
+ subUnitId,
1289
+ ruleId: diff.ruleId,
1263
1290
  payload: {
1264
- type: y.RANGE,
1265
- payload: p.oldRanges
1291
+ type: UpdateRuleType.RANGE,
1292
+ payload: diff.oldRanges
1266
1293
  },
1267
- source: r
1294
+ source
1268
1295
  }
1269
1296
  });
1270
- const w = d.getRuleById(s, a, p.ruleId);
1271
- if (w && w.type === T.CHECKBOX) {
1272
- const B = d.getValidator(T.CHECKBOX).parseFormulaSync(w, s, a);
1273
- M(p.newRanges, B.formula2);
1297
+ const rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, diff.ruleId);
1298
+ if (rule && rule.type === DataValidationType.CHECKBOX) {
1299
+ const formula = sheetDataValidationModel.getValidator(DataValidationType.CHECKBOX).parseFormulaSync(rule, unitId, subUnitId);
1300
+ setRangesDefaultValue(diff.newRanges, formula.formula2);
1274
1301
  }
1275
1302
  break;
1276
1303
  }
1277
1304
  case "add": {
1278
- if (l.push({
1279
- id: L.id,
1305
+ if (redoMutations.push({
1306
+ id: AddDataValidationMutation.id,
1280
1307
  params: {
1281
- unitId: s,
1282
- subUnitId: a,
1283
- rule: p.rule,
1284
- source: r
1308
+ unitId,
1309
+ subUnitId,
1310
+ rule: diff.rule,
1311
+ source
1285
1312
  }
1286
- }), u.unshift({
1287
- id: A.id,
1313
+ }), undoMutations.unshift({
1314
+ id: RemoveDataValidationMutation.id,
1288
1315
  params: {
1289
- unitId: s,
1290
- subUnitId: a,
1291
- ruleId: p.rule.uid,
1292
- source: r
1316
+ unitId,
1317
+ subUnitId,
1318
+ ruleId: diff.rule.uid,
1319
+ source
1293
1320
  }
1294
- }), p.rule.type === T.CHECKBOX) {
1295
- const H = d.getValidator(T.CHECKBOX).parseFormulaSync(p.rule, s, a);
1296
- M(p.rule.ranges, H.originFormula2);
1321
+ }), diff.rule.type === DataValidationType.CHECKBOX) {
1322
+ const formula = sheetDataValidationModel.getValidator(DataValidationType.CHECKBOX).parseFormulaSync(diff.rule, unitId, subUnitId);
1323
+ setRangesDefaultValue(diff.rule.ranges, formula.originFormula2);
1297
1324
  }
1298
1325
  break;
1299
1326
  }
1300
1327
  }
1301
- }), R) {
1302
- const p = {
1303
- id: oe.id,
1328
+ }), setRangeValue) {
1329
+ const redoSetRangeValues = {
1330
+ id: SetRangeValuesMutation.id,
1304
1331
  params: {
1305
- unitId: s,
1306
- subUnitId: a,
1307
- cellValue: g.getData()
1332
+ unitId,
1333
+ subUnitId,
1334
+ cellValue: redoMatrix.getData()
1308
1335
  }
1309
- }, w = {
1310
- id: oe.id,
1311
- params: st(t, p.params)
1336
+ }, undoSetRangeValues = {
1337
+ id: SetRangeValuesMutation.id,
1338
+ params: SetRangeValuesUndoMutationFactory(accessor, redoSetRangeValues.params)
1312
1339
  };
1313
- l.push(p), u.push(w);
1340
+ redoMutations.push(redoSetRangeValues), undoMutations.push(undoSetRangeValues);
1314
1341
  }
1315
1342
  return {
1316
- redoMutations: l,
1317
- undoMutations: u
1343
+ redoMutations,
1344
+ undoMutations
1318
1345
  };
1319
1346
  }
1320
- const _a = {
1321
- type: K.COMMAND,
1347
+ __name(getDataValidationDiffMutations, "getDataValidationDiffMutations");
1348
+ const UpdateSheetDataValidationRangeCommand = {
1349
+ type: CommandType.COMMAND,
1322
1350
  id: "sheet.command.updateDataValidationRuleRange",
1323
- handler(s, a) {
1324
- if (!a)
1351
+ handler(accessor, params) {
1352
+ if (!params)
1325
1353
  return !1;
1326
- const { unitId: e, subUnitId: t, ranges: r, ruleId: i } = a, o = s.get(F), n = s.get(x), l = s.get(z);
1327
- if (!o.getRuleById(e, t, i))
1354
+ const { unitId, subUnitId, ranges, ruleId } = params, sheetDataValidationModel = accessor.get(SheetDataValidationModel), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService);
1355
+ if (!sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId))
1328
1356
  return !1;
1329
- const d = o.getRuleObjectMatrix(e, t).clone();
1330
- d.updateRange(i, r);
1331
- const c = d.diff(o.getRules(e, t)), { redoMutations: m, undoMutations: _ } = be(e, t, c, s);
1332
- return l.pushUndoRedo({
1333
- undoMutations: _,
1334
- redoMutations: m,
1335
- unitID: e
1336
- }), Ie(m, n), !0;
1337
- }
1338
- }, pa = {
1339
- type: K.COMMAND,
1357
+ const matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
1358
+ matrix.updateRange(ruleId, ranges);
1359
+ const diffs = matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId)), { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
1360
+ return undoRedoService.pushUndoRedo({
1361
+ undoMutations,
1362
+ redoMutations,
1363
+ unitID: unitId
1364
+ }), sequenceExecute(redoMutations, commandService), !0;
1365
+ }
1366
+ }, AddSheetDataValidationCommand = {
1367
+ type: CommandType.COMMAND,
1340
1368
  id: "sheet.command.addDataValidation",
1341
- handler(s, a) {
1342
- if (!a)
1369
+ handler(accessor, params) {
1370
+ if (!params)
1343
1371
  return !1;
1344
- const { unitId: e, subUnitId: t, rule: r } = a, i = s.get(F), o = s.get(x), n = s.get(z), l = i.getRuleObjectMatrix(e, t).clone();
1345
- l.addRule(r);
1346
- const u = l.diff(i.getRules(e, t)), d = i.getValidator(r.type), c = {
1347
- unitId: e,
1348
- subUnitId: t,
1372
+ const { unitId, subUnitId, rule } = params, sheetDataValidationModel = accessor.get(SheetDataValidationModel), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
1373
+ matrix.addRule(rule);
1374
+ const diffs = matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId)), validator = sheetDataValidationModel.getValidator(rule.type), mutationParams = {
1375
+ unitId,
1376
+ subUnitId,
1349
1377
  rule: {
1350
- ...r,
1351
- ...d == null ? void 0 : d.normalizeFormula(r, e, t)
1378
+ ...rule,
1379
+ ...validator == null ? void 0 : validator.normalizeFormula(rule, unitId, subUnitId)
1352
1380
  }
1353
- }, { redoMutations: m, undoMutations: _ } = be(e, t, u, s);
1354
- return m.push({
1355
- id: L.id,
1356
- params: c
1357
- }), _.unshift({
1358
- id: A.id,
1381
+ }, { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
1382
+ return redoMutations.push({
1383
+ id: AddDataValidationMutation.id,
1384
+ params: mutationParams
1385
+ }), undoMutations.unshift({
1386
+ id: RemoveDataValidationMutation.id,
1359
1387
  params: {
1360
- unitId: e,
1361
- subUnitId: t,
1362
- ruleId: r.uid
1388
+ unitId,
1389
+ subUnitId,
1390
+ ruleId: rule.uid
1363
1391
  }
1364
- }), n.pushUndoRedo({
1365
- unitID: e,
1366
- redoMutations: m,
1367
- undoMutations: _
1368
- }), Ie(m, o), !0;
1369
- }
1370
- }, Ra = {
1371
- type: K.COMMAND,
1392
+ }), undoRedoService.pushUndoRedo({
1393
+ unitID: unitId,
1394
+ redoMutations,
1395
+ undoMutations
1396
+ }), sequenceExecute(redoMutations, commandService), !0;
1397
+ }
1398
+ }, UpdateSheetDataValidationSettingCommand = {
1399
+ type: CommandType.COMMAND,
1372
1400
  id: "sheets.command.update-data-validation-setting",
1373
1401
  // eslint-disable-next-line max-lines-per-function
1374
- handler(s, a) {
1375
- if (!a)
1402
+ handler(accessor, params) {
1403
+ if (!params)
1376
1404
  return !1;
1377
- const e = s.get(x), t = s.get(z), r = s.get(F), i = s.get(G), { unitId: o, subUnitId: n, ruleId: l, setting: u } = a, d = i.getValidatorItem(u.type);
1378
- if (!d)
1405
+ const commandService = accessor.get(ICommandService), redoUndoService = accessor.get(IUndoRedoService), sheetDataValidationModel = accessor.get(SheetDataValidationModel), dataValidatorRegistryService = accessor.get(DataValidatorRegistryService), { unitId, subUnitId, ruleId, setting } = params, validator = dataValidatorRegistryService.getValidatorItem(setting.type);
1406
+ if (!validator)
1379
1407
  return !1;
1380
- const c = r.getRuleById(o, n, l);
1381
- if (!c)
1408
+ const rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1409
+ if (!rule)
1382
1410
  return !1;
1383
- const m = { ...c, ...u };
1384
- if (!d.validatorFormula(m, o, n).success)
1411
+ const newRule = { ...rule, ...setting };
1412
+ if (!validator.validatorFormula(newRule, unitId, subUnitId).success)
1385
1413
  return !1;
1386
- const _ = {
1387
- unitId: o,
1388
- subUnitId: n,
1389
- ruleId: l,
1414
+ const mutationParams = {
1415
+ unitId,
1416
+ subUnitId,
1417
+ ruleId,
1390
1418
  payload: {
1391
- type: y.SETTING,
1419
+ type: UpdateRuleType.SETTING,
1392
1420
  payload: {
1393
- ...u,
1394
- ...d.normalizeFormula(m, o, n)
1421
+ ...setting,
1422
+ ...validator.normalizeFormula(newRule, unitId, subUnitId)
1395
1423
  }
1396
1424
  }
1397
- }, g = [{
1398
- id: E.id,
1399
- params: _
1400
- }], R = {
1401
- unitId: o,
1402
- subUnitId: n,
1403
- ruleId: l,
1425
+ }, redoMutations = [{
1426
+ id: UpdateDataValidationMutation.id,
1427
+ params: mutationParams
1428
+ }], undoMutationParams = {
1429
+ unitId,
1430
+ subUnitId,
1431
+ ruleId,
1404
1432
  payload: {
1405
- type: y.SETTING,
1406
- payload: bt(c)
1433
+ type: UpdateRuleType.SETTING,
1434
+ payload: getRuleSetting(rule)
1407
1435
  }
1408
- }, M = [{
1409
- id: E.id,
1410
- params: R
1436
+ }, undoMutations = [{
1437
+ id: UpdateDataValidationMutation.id,
1438
+ params: undoMutationParams
1411
1439
  }];
1412
- if (u.type === T.CHECKBOX) {
1413
- const w = c.ranges, H = s.get(O), B = Ye(H, { unitId: o, subUnitId: n });
1414
- if (B) {
1415
- const W = new ve(), { worksheet: U } = B, { formula2: J = Me, formula1: ce = Ve } = c, { formula2: he = Me, formula1: me = Ve } = u;
1416
- let Le = !1;
1417
- if (w.forEach((fe) => {
1418
- b.foreach(fe, (ae, xe) => {
1419
- const j = U.getCellRaw(ae, xe), Ke = ct(j);
1420
- (ft(j) || Ke === String(J)) && !(j != null && j.p) ? (W.setValue(ae, xe, {
1421
- v: he,
1440
+ if (setting.type === DataValidationType.CHECKBOX) {
1441
+ const ranges = rule.ranges, univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId });
1442
+ if (target) {
1443
+ const redoMatrix = new ObjectMatrix(), { worksheet } = target, { formula2: oldFormula2 = CHECKBOX_FORMULA_2, formula1: oldFormula1 = CHECKBOX_FORMULA_1 } = rule, { formula2 = CHECKBOX_FORMULA_2, formula1 = CHECKBOX_FORMULA_1 } = setting;
1444
+ let setted = !1;
1445
+ if (ranges.forEach((range) => {
1446
+ Range.foreach(range, (row, column) => {
1447
+ const cellData = worksheet.getCellRaw(row, column), value = getStringCellValue(cellData);
1448
+ (isBlankCell(cellData) || value === String(oldFormula2)) && !(cellData != null && cellData.p) ? (redoMatrix.setValue(row, column, {
1449
+ v: formula2,
1422
1450
  p: null
1423
- }), Le = !0) : Ke === String(ce) && !(j != null && j.p) && (W.setValue(ae, xe, {
1424
- v: me,
1451
+ }), setted = !0) : value === String(oldFormula1) && !(cellData != null && cellData.p) && (redoMatrix.setValue(row, column, {
1452
+ v: formula1,
1425
1453
  p: null
1426
- }), Le = !0);
1454
+ }), setted = !0);
1427
1455
  });
1428
- }), Le) {
1429
- const fe = {
1430
- id: oe.id,
1456
+ }), setted) {
1457
+ const redoSetRangeValues = {
1458
+ id: SetRangeValuesMutation.id,
1431
1459
  params: {
1432
- unitId: o,
1433
- subUnitId: n,
1434
- cellValue: W.getData()
1460
+ unitId,
1461
+ subUnitId,
1462
+ cellValue: redoMatrix.getData()
1435
1463
  }
1436
- }, ae = {
1437
- id: oe.id,
1438
- params: st(s, fe.params)
1464
+ }, undoSetRangeValues = {
1465
+ id: SetRangeValuesMutation.id,
1466
+ params: SetRangeValuesUndoMutationFactory(accessor, redoSetRangeValues.params)
1439
1467
  };
1440
- g.push(fe), M.push(ae);
1468
+ redoMutations.push(redoSetRangeValues), undoMutations.push(undoSetRangeValues);
1441
1469
  }
1442
1470
  }
1443
1471
  }
1444
- return Ie(g, e).result ? (t.pushUndoRedo({
1445
- unitID: o,
1446
- redoMutations: g,
1447
- undoMutations: M
1472
+ return sequenceExecute(redoMutations, commandService).result ? (redoUndoService.pushUndoRedo({
1473
+ unitID: unitId,
1474
+ redoMutations,
1475
+ undoMutations
1448
1476
  }), !0) : !1;
1449
1477
  }
1450
- }, Sa = {
1451
- type: K.COMMAND,
1478
+ }, UpdateSheetDataValidationOptionsCommand = {
1479
+ type: CommandType.COMMAND,
1452
1480
  id: "sheets.command.update-data-validation-options",
1453
- handler(s, a) {
1454
- if (!a)
1481
+ handler(accessor, params) {
1482
+ if (!params)
1455
1483
  return !1;
1456
- const e = s.get(x), t = s.get(z), r = s.get(F), { unitId: i, subUnitId: o, ruleId: n, options: l } = a, u = r.getRuleById(i, o, n);
1457
- if (!u)
1484
+ const commandService = accessor.get(ICommandService), redoUndoService = accessor.get(IUndoRedoService), sheetDataValidationModel = accessor.get(SheetDataValidationModel), { unitId, subUnitId, ruleId, options } = params, rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1485
+ if (!rule)
1458
1486
  return !1;
1459
- const d = {
1460
- unitId: i,
1461
- subUnitId: o,
1462
- ruleId: n,
1487
+ const mutationParams = {
1488
+ unitId,
1489
+ subUnitId,
1490
+ ruleId,
1463
1491
  payload: {
1464
- type: y.OPTIONS,
1465
- payload: l
1492
+ type: UpdateRuleType.OPTIONS,
1493
+ payload: options
1466
1494
  }
1467
- }, c = [{
1468
- id: E.id,
1469
- params: d
1470
- }], m = {
1471
- unitId: i,
1472
- subUnitId: o,
1473
- ruleId: n,
1495
+ }, redoMutations = [{
1496
+ id: UpdateDataValidationMutation.id,
1497
+ params: mutationParams
1498
+ }], undoMutationParams = {
1499
+ unitId,
1500
+ subUnitId,
1501
+ ruleId,
1474
1502
  payload: {
1475
- type: y.OPTIONS,
1476
- payload: Lt(u)
1503
+ type: UpdateRuleType.OPTIONS,
1504
+ payload: getRuleOptions(rule)
1477
1505
  }
1478
- }, _ = [{
1479
- id: E.id,
1480
- params: m
1506
+ }, undoMutations = [{
1507
+ id: UpdateDataValidationMutation.id,
1508
+ params: undoMutationParams
1481
1509
  }];
1482
- return t.pushUndoRedo({
1483
- unitID: i,
1484
- redoMutations: c,
1485
- undoMutations: _
1486
- }), e.executeCommand(E.id, d), !0;
1487
- }
1488
- }, va = {
1489
- type: K.COMMAND,
1510
+ return redoUndoService.pushUndoRedo({
1511
+ unitID: unitId,
1512
+ redoMutations,
1513
+ undoMutations
1514
+ }), commandService.executeCommand(UpdateDataValidationMutation.id, mutationParams), !0;
1515
+ }
1516
+ }, ClearRangeDataValidationCommand = {
1517
+ type: CommandType.COMMAND,
1490
1518
  id: "sheets.command.clear-range-data-validation",
1491
- handler(s, a) {
1492
- if (!a)
1519
+ handler(accessor, params) {
1520
+ if (!params)
1493
1521
  return !1;
1494
- const { unitId: e, subUnitId: t, ranges: r } = a, i = s.get(x), o = s.get(O), n = Ye(o, { unitId: e, subUnitId: t }), l = s.get(F);
1495
- if (!n) return !1;
1496
- const u = s.get(z), d = l.getRuleObjectMatrix(e, t).clone();
1497
- d.removeRange(r);
1498
- const c = d.diff(l.getRules(e, t)), { redoMutations: m, undoMutations: _ } = be(e, t, c, s);
1499
- return u.pushUndoRedo({
1500
- unitID: e,
1501
- redoMutations: m,
1502
- undoMutations: _
1503
- }), Ie(m, i).result;
1504
- }
1505
- }, Va = {
1506
- type: K.COMMAND,
1522
+ const { unitId, subUnitId, ranges } = params, commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId }), sheetDataValidationModel = accessor.get(SheetDataValidationModel);
1523
+ if (!target) return !1;
1524
+ const undoRedoService = accessor.get(IUndoRedoService), matrix = sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
1525
+ matrix.removeRange(ranges);
1526
+ const diffs = matrix.diff(sheetDataValidationModel.getRules(unitId, subUnitId)), { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
1527
+ return undoRedoService.pushUndoRedo({
1528
+ unitID: unitId,
1529
+ redoMutations,
1530
+ undoMutations
1531
+ }), sequenceExecute(redoMutations, commandService).result;
1532
+ }
1533
+ }, RemoveSheetAllDataValidationCommand = {
1534
+ type: CommandType.COMMAND,
1507
1535
  id: "sheet.command.remove-all-data-validation",
1508
- handler(s, a) {
1509
- if (!a)
1536
+ handler(accessor, params) {
1537
+ if (!params)
1510
1538
  return !1;
1511
- const { unitId: e, subUnitId: t } = a, r = s.get(x), i = s.get(F), o = s.get(z), n = [...i.getRules(e, t)], l = {
1512
- unitId: e,
1513
- subUnitId: t,
1514
- ruleId: n.map((c) => c.uid)
1515
- }, u = [{
1516
- id: A.id,
1517
- params: l
1518
- }], d = [{
1519
- id: L.id,
1539
+ const { unitId, subUnitId } = params, commandService = accessor.get(ICommandService), sheetDataValidationModel = accessor.get(SheetDataValidationModel), undoRedoService = accessor.get(IUndoRedoService), currentRules = [...sheetDataValidationModel.getRules(unitId, subUnitId)], redoParams = {
1540
+ unitId,
1541
+ subUnitId,
1542
+ ruleId: currentRules.map((rule) => rule.uid)
1543
+ }, redoMutations = [{
1544
+ id: RemoveDataValidationMutation.id,
1545
+ params: redoParams
1546
+ }], undoMutations = [{
1547
+ id: AddDataValidationMutation.id,
1520
1548
  params: {
1521
- unitId: e,
1522
- subUnitId: t,
1523
- rule: n
1549
+ unitId,
1550
+ subUnitId,
1551
+ rule: currentRules
1524
1552
  }
1525
1553
  }];
1526
- return o.pushUndoRedo({
1527
- redoMutations: u,
1528
- undoMutations: d,
1529
- unitID: e
1530
- }), r.executeCommand(A.id, l), !0;
1531
- }
1532
- }, Ma = (s, a) => {
1533
- const e = s.get(F), { unitId: t, subUnitId: r, ruleId: i, source: o } = a;
1534
- if (Array.isArray(i)) {
1535
- const l = i.map((u) => e.getRuleById(t, r, u)).filter(Boolean);
1554
+ return undoRedoService.pushUndoRedo({
1555
+ redoMutations,
1556
+ undoMutations,
1557
+ unitID: unitId
1558
+ }), commandService.executeCommand(RemoveDataValidationMutation.id, redoParams), !0;
1559
+ }
1560
+ }, removeDataValidationUndoFactory = /* @__PURE__ */ __name((accessor, redoParams) => {
1561
+ const sheetDataValidationModel = accessor.get(SheetDataValidationModel), { unitId, subUnitId, ruleId, source } = redoParams;
1562
+ if (Array.isArray(ruleId)) {
1563
+ const rules = ruleId.map((id) => sheetDataValidationModel.getRuleById(unitId, subUnitId, id)).filter(Boolean);
1536
1564
  return [{
1537
- id: L.id,
1565
+ id: AddDataValidationMutation.id,
1538
1566
  params: {
1539
- unitId: t,
1540
- subUnitId: r,
1541
- rule: l,
1542
- source: o
1567
+ unitId,
1568
+ subUnitId,
1569
+ rule: rules,
1570
+ source
1543
1571
  }
1544
1572
  }];
1545
1573
  }
1546
1574
  return [{
1547
- id: L.id,
1575
+ id: AddDataValidationMutation.id,
1548
1576
  params: {
1549
- unitId: t,
1550
- subUnitId: r,
1577
+ unitId,
1578
+ subUnitId,
1551
1579
  rule: {
1552
- ...e.getRuleById(t, r, i)
1580
+ ...sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId)
1553
1581
  },
1554
- index: e.getRuleIndex(t, r, i)
1582
+ index: sheetDataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
1555
1583
  }
1556
1584
  }];
1557
- }, ya = {
1558
- type: K.COMMAND,
1585
+ }, "removeDataValidationUndoFactory"), RemoveSheetDataValidationCommand = {
1586
+ type: CommandType.COMMAND,
1559
1587
  id: "sheet.command.remove-data-validation-rule",
1560
- handler(s, a) {
1561
- if (!a)
1588
+ handler(accessor, params) {
1589
+ if (!params)
1562
1590
  return !1;
1563
- const { unitId: e, subUnitId: t, ruleId: r } = a, i = s.get(x), o = s.get(z), n = s.get(F), l = [{
1564
- id: A.id,
1565
- params: a
1566
- }], u = [{
1567
- id: L.id,
1591
+ const { unitId, subUnitId, ruleId } = params, commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), sheetDataValidationModel = accessor.get(SheetDataValidationModel), redoMutations = [{
1592
+ id: RemoveDataValidationMutation.id,
1593
+ params
1594
+ }], undoMutations = [{
1595
+ id: AddDataValidationMutation.id,
1568
1596
  params: {
1569
- unitId: e,
1570
- subUnitId: t,
1597
+ unitId,
1598
+ subUnitId,
1571
1599
  rule: {
1572
- ...n.getRuleById(e, t, r)
1600
+ ...sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId)
1573
1601
  },
1574
- index: n.getRuleIndex(e, t, r)
1602
+ index: sheetDataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
1575
1603
  }
1576
1604
  }];
1577
- return o.pushUndoRedo({
1578
- undoMutations: u,
1579
- redoMutations: l,
1580
- unitID: a.unitId
1581
- }), i.executeCommand(A.id, a), !0;
1582
- }
1583
- }, Ea = "sheets-data-validation.config", tt = {};
1584
- var Ta = Object.defineProperty, Fa = Object.getOwnPropertyDescriptor, Na = (s, a, e, t) => {
1585
- for (var r = t > 1 ? void 0 : t ? Fa(a, e) : a, i = s.length - 1, o; i >= 0; i--)
1586
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
1587
- return t && r && Ta(a, e, r), r;
1588
- }, $e = (s, a) => (e, t) => a(e, t, s);
1589
- let Ee = class extends $ {
1590
- constructor(a, e, t) {
1605
+ return undoRedoService.pushUndoRedo({
1606
+ undoMutations,
1607
+ redoMutations,
1608
+ unitID: params.unitId
1609
+ }), commandService.executeCommand(RemoveDataValidationMutation.id, params), !0;
1610
+ }
1611
+ }, SHEETS_DATA_VALIDATION_PLUGIN_CONFIG_KEY = "sheets-data-validation.config", defaultPluginConfig = {};
1612
+ var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1613
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1614
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1615
+ return kind && result && __defProp$6(target, key, result), result;
1616
+ }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a5;
1617
+ let DataValidationFormulaRefRangeController = (_a5 = class extends Disposable {
1618
+ constructor(_dataValidationModel, _formulaRefRangeService, _validatorRegistryService) {
1591
1619
  super();
1592
- f(this, "_disposableMap", /* @__PURE__ */ new Map());
1593
- f(this, "registerRule", (a, e, t) => {
1594
- de(t.type, this._validatorRegistryService) && this.register(a, e, t);
1595
- });
1596
- this._dataValidationModel = a, this._formulaRefRangeService = e, this._validatorRegistryService = t, this._initRefRange();
1620
+ __publicField(this, "_disposableMap", /* @__PURE__ */ new Map());
1621
+ __publicField(this, "registerRule", /* @__PURE__ */ __name((unitId, subUnitId, rule) => {
1622
+ shouldOffsetFormulaByRange(rule.type, this._validatorRegistryService) && this.register(unitId, subUnitId, rule);
1623
+ }, "registerRule"));
1624
+ this._dataValidationModel = _dataValidationModel, this._formulaRefRangeService = _formulaRefRangeService, this._validatorRegistryService = _validatorRegistryService, this._initRefRange();
1597
1625
  }
1598
- _getIdWithUnitId(a, e, t) {
1599
- return `${a}_${e}_${t}`;
1626
+ _getIdWithUnitId(unitID, subUnitId, ruleId) {
1627
+ return `${unitID}_${subUnitId}_${ruleId}`;
1600
1628
  }
1601
1629
  // eslint-disable-next-line max-lines-per-function
1602
- register(a, e, t) {
1603
- const r = t.ranges, i = t.formula1, o = t.formula2, n = this._formulaRefRangeService.registerRangeFormula(a, e, r, [i != null ? i : "", o != null ? o : ""], (u) => {
1604
- if (u.length === 0)
1630
+ register(unitId, subUnitId, rule) {
1631
+ const oldRanges = rule.ranges, oldFormula1 = rule.formula1, oldFormula2 = rule.formula2, disposable = this._formulaRefRangeService.registerRangeFormula(unitId, subUnitId, oldRanges, [oldFormula1 != null ? oldFormula1 : "", oldFormula2 != null ? oldFormula2 : ""], (res) => {
1632
+ if (res.length === 0)
1605
1633
  return {
1606
1634
  undos: [{
1607
- id: L.id,
1635
+ id: AddDataValidationMutation.id,
1608
1636
  params: {
1609
- unitId: a,
1610
- subUnitId: e,
1611
- rule: t,
1637
+ unitId,
1638
+ subUnitId,
1639
+ rule,
1612
1640
  source: "patched"
1613
1641
  }
1614
1642
  }],
1615
1643
  redos: [{
1616
- id: A.id,
1644
+ id: RemoveDataValidationMutation.id,
1617
1645
  params: {
1618
- unitId: a,
1619
- subUnitId: e,
1620
- ruleId: t.uid,
1646
+ unitId,
1647
+ subUnitId,
1648
+ ruleId: rule.uid,
1621
1649
  source: "patched"
1622
1650
  }
1623
1651
  }]
1624
1652
  };
1625
- const d = [], c = [], m = u[0];
1626
- d.push({
1627
- id: E.id,
1653
+ const redos = [], undos = [], first = res[0];
1654
+ redos.push({
1655
+ id: UpdateDataValidationMutation.id,
1628
1656
  params: {
1629
- unitId: a,
1630
- subUnitId: e,
1631
- ruleId: t.uid,
1657
+ unitId,
1658
+ subUnitId,
1659
+ ruleId: rule.uid,
1632
1660
  payload: {
1633
- type: y.ALL,
1661
+ type: UpdateRuleType.ALL,
1634
1662
  payload: {
1635
- ranges: m.ranges,
1636
- formula1: m.formulas[0],
1637
- formula2: m.formulas[1]
1663
+ ranges: first.ranges,
1664
+ formula1: first.formulas[0],
1665
+ formula2: first.formulas[1]
1638
1666
  }
1639
1667
  },
1640
1668
  source: "patched"
1641
1669
  }
1642
- }), c.push({
1643
- id: E.id,
1670
+ }), undos.push({
1671
+ id: UpdateDataValidationMutation.id,
1644
1672
  params: {
1645
- unitId: a,
1646
- subUnitId: e,
1647
- ruleId: t.uid,
1673
+ unitId,
1674
+ subUnitId,
1675
+ ruleId: rule.uid,
1648
1676
  payload: {
1649
- type: y.ALL,
1677
+ type: UpdateRuleType.ALL,
1650
1678
  payload: {
1651
- ranges: r,
1652
- formula1: i,
1653
- formula2: o
1679
+ ranges: oldRanges,
1680
+ formula1: oldFormula1,
1681
+ formula2: oldFormula2
1654
1682
  }
1655
1683
  },
1656
1684
  source: "patched"
1657
1685
  }
1658
1686
  });
1659
- for (let _ = 1; _ < u.length; _++) {
1660
- const g = u[_], R = yt();
1661
- d.push({
1662
- id: L.id,
1687
+ for (let i = 1; i < res.length; i++) {
1688
+ const item = res[i], id2 = generateRandomId();
1689
+ redos.push({
1690
+ id: AddDataValidationMutation.id,
1663
1691
  params: {
1664
- unitId: a,
1665
- subUnitId: e,
1692
+ unitId,
1693
+ subUnitId,
1666
1694
  rule: {
1667
- ...t,
1668
- uid: R,
1669
- formula1: g.formulas[0],
1670
- formula2: g.formulas[1],
1671
- ranges: g.ranges
1695
+ ...rule,
1696
+ uid: id2,
1697
+ formula1: item.formulas[0],
1698
+ formula2: item.formulas[1],
1699
+ ranges: item.ranges
1672
1700
  },
1673
1701
  source: "patched"
1674
1702
  }
1675
- }), c.push({
1676
- id: A.id,
1703
+ }), undos.push({
1704
+ id: RemoveDataValidationMutation.id,
1677
1705
  params: {
1678
- unitId: a,
1679
- subUnitId: e,
1680
- ruleId: R,
1706
+ unitId,
1707
+ subUnitId,
1708
+ ruleId: id2,
1681
1709
  source: "patched"
1682
1710
  }
1683
1711
  });
1684
1712
  }
1685
1713
  return {
1686
- undos: c,
1687
- redos: d
1714
+ undos,
1715
+ redos
1688
1716
  };
1689
- }), l = this._getIdWithUnitId(a, e, t.uid);
1690
- this._disposableMap.set(l, n);
1717
+ }), id = this._getIdWithUnitId(unitId, subUnitId, rule.uid);
1718
+ this._disposableMap.set(id, disposable);
1691
1719
  }
1692
1720
  _initRefRange() {
1693
- const a = this._dataValidationModel.getAll();
1694
- for (const [e, t] of a)
1695
- for (const [r, i] of t)
1696
- for (const o of i)
1697
- this.registerRule(e, r, o);
1721
+ const allRules = this._dataValidationModel.getAll();
1722
+ for (const [unitId, subUnitMap] of allRules)
1723
+ for (const [subUnitId, rules] of subUnitMap)
1724
+ for (const rule of rules)
1725
+ this.registerRule(unitId, subUnitId, rule);
1698
1726
  this.disposeWithMe(
1699
- this._dataValidationModel.ruleChange$.subscribe((e) => {
1700
- const { unitId: t, subUnitId: r, rule: i } = e;
1701
- switch (e.type) {
1727
+ this._dataValidationModel.ruleChange$.subscribe((option) => {
1728
+ const { unitId, subUnitId, rule } = option;
1729
+ switch (option.type) {
1702
1730
  case "add": {
1703
- const o = e.rule;
1704
- this.registerRule(e.unitId, e.subUnitId, o);
1731
+ const rule2 = option.rule;
1732
+ this.registerRule(option.unitId, option.subUnitId, rule2);
1705
1733
  break;
1706
1734
  }
1707
1735
  case "remove": {
1708
- const o = this._disposableMap.get(this._getIdWithUnitId(t, r, i.uid));
1709
- o && o.dispose();
1736
+ const disposeSet = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, rule.uid));
1737
+ disposeSet && disposeSet.dispose();
1710
1738
  break;
1711
1739
  }
1712
1740
  case "update": {
1713
- const o = e.rule, n = this._disposableMap.get(this._getIdWithUnitId(t, r, o.uid));
1714
- n && n.dispose(), this.registerRule(e.unitId, e.subUnitId, o);
1741
+ const rule2 = option.rule, disposeSet = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, rule2.uid));
1742
+ disposeSet && disposeSet.dispose(), this.registerRule(option.unitId, option.subUnitId, rule2);
1715
1743
  break;
1716
1744
  }
1717
1745
  }
1718
1746
  })
1719
- ), this.disposeWithMe(qe(() => {
1720
- this._disposableMap.forEach((e) => {
1721
- e.dispose();
1747
+ ), this.disposeWithMe(toDisposable(() => {
1748
+ this._disposableMap.forEach((item) => {
1749
+ item.dispose();
1722
1750
  }), this._disposableMap.clear();
1723
1751
  }));
1724
1752
  }
1725
- };
1726
- Ee = Na([
1727
- $e(0, S(F)),
1728
- $e(1, S(ut)),
1729
- $e(2, S(G))
1730
- ], Ee);
1731
- var gt = /* @__PURE__ */ ((s) => (s[s.View = 0] = "View", s[s.Edit = 1] = "Edit", s[s.ManageCollaborator = 2] = "ManageCollaborator", s[s.Print = 3] = "Print", s[s.Duplicate = 4] = "Duplicate", s[s.Comment = 5] = "Comment", s[s.Copy = 6] = "Copy", s[s.Share = 7] = "Share", s[s.Export = 8] = "Export", s[s.MoveWorksheet = 9] = "MoveWorksheet", s[s.DeleteWorksheet = 10] = "DeleteWorksheet", s[s.HideWorksheet = 11] = "HideWorksheet", s[s.RenameWorksheet = 12] = "RenameWorksheet", s[s.CreateWorksheet = 13] = "CreateWorksheet", s[s.SetWorksheetStyle = 14] = "SetWorksheetStyle", s[s.EditWorksheetCell = 15] = "EditWorksheetCell", s[s.InsertHyperlink = 16] = "InsertHyperlink", s[s.Sort = 17] = "Sort", s[s.Filter = 18] = "Filter", s[s.PivotTable = 19] = "PivotTable", s[s.FloatImg = 20] = "FloatImg", s[s.History = 21] = "History", s[s.RwHgtClWdt = 22] = "RwHgtClWdt", s[s.ViemRwHgtClWdt = 23] = "ViemRwHgtClWdt", s[s.ViewFilter = 24] = "ViewFilter", s[s.MoveSheet = 25] = "MoveSheet", s[s.DeleteSheet = 26] = "DeleteSheet", s[s.HideSheet = 27] = "HideSheet", s[s.CopySheet = 28] = "CopySheet", s[s.RenameSheet = 29] = "RenameSheet", s[s.CreateSheet = 30] = "CreateSheet", s[s.SelectProtectedCells = 31] = "SelectProtectedCells", s[s.SelectUnProtectedCells = 32] = "SelectUnProtectedCells", s[s.SetCellStyle = 33] = "SetCellStyle", s[s.SetCellValue = 34] = "SetCellValue", s[s.SetRowStyle = 35] = "SetRowStyle", s[s.SetColumnStyle = 36] = "SetColumnStyle", s[s.InsertRow = 37] = "InsertRow", s[s.InsertColumn = 38] = "InsertColumn", s[s.DeleteRow = 39] = "DeleteRow", s[s.DeleteColumn = 40] = "DeleteColumn", s[s.EditExtraObject = 41] = "EditExtraObject", s[s.Delete = 42] = "Delete", s[s.RecoverHistory = 43] = "RecoverHistory", s[s.ViewHistory = 44] = "ViewHistory", s[s.CreatePermissionObject = 45] = "CreatePermissionObject", s[s.UNRECOGNIZED = -1] = "UNRECOGNIZED", s))(gt || {}), Ca = Object.defineProperty, Oa = Object.getOwnPropertyDescriptor, wa = (s, a, e, t) => {
1732
- for (var r = t > 1 ? void 0 : t ? Oa(a, e) : a, i = s.length - 1, o; i >= 0; i--)
1733
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
1734
- return t && r && Ca(a, e, r), r;
1735
- }, He = (s, a) => (e, t) => a(e, t, s);
1736
- let Te = class extends $ {
1737
- constructor(s, a, e) {
1738
- super(), this._univerInstanceService = s, this._permissionService = a, this._lexerTreeBuilder = e;
1739
- }
1740
- getFormulaRefCheck(s) {
1741
- var e, t;
1742
- const a = this._lexerTreeBuilder.sequenceNodesBuilder(s);
1743
- if (!a)
1753
+ }, __name(_a5, "DataValidationFormulaRefRangeController"), _a5);
1754
+ DataValidationFormulaRefRangeController = __decorateClass$6([
1755
+ __decorateParam$6(0, Inject(SheetDataValidationModel)),
1756
+ __decorateParam$6(1, Inject(FormulaRefRangeService)),
1757
+ __decorateParam$6(2, Inject(DataValidatorRegistryService))
1758
+ ], DataValidationFormulaRefRangeController);
1759
+ var R = /* @__PURE__ */ ((E) => (E[E.View = 0] = "View", E[E.Edit = 1] = "Edit", E[E.ManageCollaborator = 2] = "ManageCollaborator", E[E.Print = 3] = "Print", E[E.Duplicate = 4] = "Duplicate", E[E.Comment = 5] = "Comment", E[E.Copy = 6] = "Copy", E[E.Share = 7] = "Share", E[E.Export = 8] = "Export", E[E.MoveWorksheet = 9] = "MoveWorksheet", E[E.DeleteWorksheet = 10] = "DeleteWorksheet", E[E.HideWorksheet = 11] = "HideWorksheet", E[E.RenameWorksheet = 12] = "RenameWorksheet", E[E.CreateWorksheet = 13] = "CreateWorksheet", E[E.SetWorksheetStyle = 14] = "SetWorksheetStyle", E[E.EditWorksheetCell = 15] = "EditWorksheetCell", E[E.InsertHyperlink = 16] = "InsertHyperlink", E[E.Sort = 17] = "Sort", E[E.Filter = 18] = "Filter", E[E.PivotTable = 19] = "PivotTable", E[E.FloatImg = 20] = "FloatImg", E[E.History = 21] = "History", E[E.RwHgtClWdt = 22] = "RwHgtClWdt", E[E.ViemRwHgtClWdt = 23] = "ViemRwHgtClWdt", E[E.ViewFilter = 24] = "ViewFilter", E[E.MoveSheet = 25] = "MoveSheet", E[E.DeleteSheet = 26] = "DeleteSheet", E[E.HideSheet = 27] = "HideSheet", E[E.CopySheet = 28] = "CopySheet", E[E.RenameSheet = 29] = "RenameSheet", E[E.CreateSheet = 30] = "CreateSheet", E[E.SelectProtectedCells = 31] = "SelectProtectedCells", E[E.SelectUnProtectedCells = 32] = "SelectUnProtectedCells", E[E.SetCellStyle = 33] = "SetCellStyle", E[E.SetCellValue = 34] = "SetCellValue", E[E.SetRowStyle = 35] = "SetRowStyle", E[E.SetColumnStyle = 36] = "SetColumnStyle", E[E.InsertRow = 37] = "InsertRow", E[E.InsertColumn = 38] = "InsertColumn", E[E.DeleteRow = 39] = "DeleteRow", E[E.DeleteColumn = 40] = "DeleteColumn", E[E.EditExtraObject = 41] = "EditExtraObject", E[E.Delete = 42] = "Delete", E[E.RecoverHistory = 43] = "RecoverHistory", E[E.ViewHistory = 44] = "ViewHistory", E[E.CreatePermissionObject = 45] = "CreatePermissionObject", E[E.UNRECOGNIZED = -1] = "UNRECOGNIZED", E))(R || {}), __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1760
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1761
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1762
+ return kind && result && __defProp$5(target, key, result), result;
1763
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a6;
1764
+ let DataValidationFormulaController = (_a6 = class extends Disposable {
1765
+ constructor(_univerInstanceService, _permissionService, _lexerTreeBuilder) {
1766
+ super(), this._univerInstanceService = _univerInstanceService, this._permissionService = _permissionService, this._lexerTreeBuilder = _lexerTreeBuilder;
1767
+ }
1768
+ getFormulaRefCheck(formulaString) {
1769
+ var _a12, _b;
1770
+ const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);
1771
+ if (!sequenceNodes)
1744
1772
  return !0;
1745
- for (let r = 0; r < a.length; r++) {
1746
- const i = a[r];
1747
- if (typeof i == "string")
1773
+ for (let i = 0; i < sequenceNodes.length; i++) {
1774
+ const node = sequenceNodes[i];
1775
+ if (typeof node == "string")
1748
1776
  continue;
1749
- const { token: o } = i, n = Gt(o), l = this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET);
1750
- let u = l.getActiveSheet();
1751
- const d = l.getUnitId();
1752
- if (n.sheetName) {
1753
- if (u = l.getSheetBySheetName(n.sheetName), !u)
1777
+ const { token } = node, sequenceGrid = deserializeRangeWithSheetWithCache(token), workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
1778
+ let targetSheet = workbook.getActiveSheet();
1779
+ const unitId = workbook.getUnitId();
1780
+ if (sequenceGrid.sheetName) {
1781
+ if (targetSheet = workbook.getSheetBySheetName(sequenceGrid.sheetName), !targetSheet)
1754
1782
  return !1;
1755
- const R = u == null ? void 0 : u.getSheetId();
1756
- if (!this._permissionService.getPermissionPoint(new Bt(d, R).id)) return !1;
1783
+ const subUnitId = targetSheet == null ? void 0 : targetSheet.getSheetId();
1784
+ if (!this._permissionService.getPermissionPoint(new WorksheetViewPermission(unitId, subUnitId).id)) return !1;
1757
1785
  }
1758
- if (!u)
1786
+ if (!targetSheet)
1759
1787
  return !1;
1760
- const { startRow: c, endRow: m, startColumn: _, endColumn: g } = n.range;
1761
- for (let R = c; R <= m; R++)
1762
- for (let M = _; M <= g; M++) {
1763
- const p = (t = (e = u.getCell(R, M)) == null ? void 0 : e.selectionProtection) == null ? void 0 : t[0];
1764
- if ((p == null ? void 0 : p[gt.View]) === !1)
1788
+ const { startRow, endRow, startColumn, endColumn } = sequenceGrid.range;
1789
+ for (let i2 = startRow; i2 <= endRow; i2++)
1790
+ for (let j = startColumn; j <= endColumn; j++) {
1791
+ const permission = (_b = (_a12 = targetSheet.getCell(i2, j)) == null ? void 0 : _a12.selectionProtection) == null ? void 0 : _b[0];
1792
+ if ((permission == null ? void 0 : permission[R.View]) === !1)
1765
1793
  return !1;
1766
1794
  }
1767
1795
  }
1768
1796
  return !0;
1769
1797
  }
1770
- };
1771
- Te = wa([
1772
- He(0, O),
1773
- He(1, Et),
1774
- He(2, S(Z))
1775
- ], Te);
1776
- var Ia = Object.defineProperty, Aa = Object.getOwnPropertyDescriptor, Da = (s, a, e, t) => {
1777
- for (var r = t > 1 ? void 0 : t ? Aa(a, e) : a, i = s.length - 1, o; i >= 0; i--)
1778
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
1779
- return t && r && Ia(a, e, r), r;
1780
- }, ee = (s, a) => (e, t) => a(e, t, s);
1781
- let Fe = class extends $ {
1782
- constructor(a, e, t, r, i, o) {
1798
+ }, __name(_a6, "DataValidationFormulaController"), _a6);
1799
+ DataValidationFormulaController = __decorateClass$5([
1800
+ __decorateParam$5(0, IUniverInstanceService),
1801
+ __decorateParam$5(1, IPermissionService),
1802
+ __decorateParam$5(2, Inject(LexerTreeBuilder))
1803
+ ], DataValidationFormulaController);
1804
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1805
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1806
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1807
+ return kind && result && __defProp$4(target, key, result), result;
1808
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a7;
1809
+ let DataValidationRefRangeController = (_a7 = class extends Disposable {
1810
+ constructor(_dataValidationModel, _injector, _refRangeService, _dataValidationFormulaService, _formulaRefRangeService, _validatorRegistryService) {
1783
1811
  super();
1784
- f(this, "_disposableMap", /* @__PURE__ */ new Map());
1785
- f(this, "registerRule", (a, e, t) => {
1786
- de(t.type, this._validatorRegistryService) || (this.register(a, e, t), this.registerFormula(a, e, t));
1787
- });
1788
- this._dataValidationModel = a, this._injector = e, this._refRangeService = t, this._dataValidationFormulaService = r, this._formulaRefRangeService = i, this._validatorRegistryService = o, this._initRefRange();
1812
+ __publicField(this, "_disposableMap", /* @__PURE__ */ new Map());
1813
+ __publicField(this, "registerRule", /* @__PURE__ */ __name((unitId, subUnitId, rule) => {
1814
+ shouldOffsetFormulaByRange(rule.type, this._validatorRegistryService) || (this.register(unitId, subUnitId, rule), this.registerFormula(unitId, subUnitId, rule));
1815
+ }, "registerRule"));
1816
+ this._dataValidationModel = _dataValidationModel, this._injector = _injector, this._refRangeService = _refRangeService, this._dataValidationFormulaService = _dataValidationFormulaService, this._formulaRefRangeService = _formulaRefRangeService, this._validatorRegistryService = _validatorRegistryService, this._initRefRange();
1789
1817
  }
1790
- _getIdWithUnitId(a, e, t) {
1791
- return `${a}_${e}_${t}`;
1818
+ _getIdWithUnitId(unitID, subUnitId, ruleId) {
1819
+ return `${unitID}_${subUnitId}_${ruleId}`;
1792
1820
  }
1793
1821
  // eslint-disable-next-line max-lines-per-function
1794
- registerFormula(a, e, t) {
1795
- var u;
1796
- const r = t.uid, i = this._getIdWithUnitId(a, e, r), o = (u = this._disposableMap.get(i)) != null ? u : /* @__PURE__ */ new Set(), n = (d, c) => {
1797
- const m = this._dataValidationModel.getRuleById(a, e, r);
1798
- if (!m)
1822
+ registerFormula(unitId, subUnitId, rule) {
1823
+ var _a12;
1824
+ const ruleId = rule.uid, id = this._getIdWithUnitId(unitId, subUnitId, ruleId), disposeSet = (_a12 = this._disposableMap.get(id)) != null ? _a12 : /* @__PURE__ */ new Set(), handleFormulaChange = /* @__PURE__ */ __name((type, formulaString) => {
1825
+ const oldRule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1826
+ if (!oldRule)
1799
1827
  return { redos: [], undos: [] };
1800
- const _ = m[d];
1801
- if (!_ || _ === c)
1828
+ const oldFormula = oldRule[type];
1829
+ if (!oldFormula || oldFormula === formulaString)
1802
1830
  return { redos: [], undos: [] };
1803
- const g = {
1804
- unitId: a,
1805
- subUnitId: e,
1806
- ruleId: t.uid,
1831
+ const redoParams = {
1832
+ unitId,
1833
+ subUnitId,
1834
+ ruleId: rule.uid,
1807
1835
  payload: {
1808
- type: y.SETTING,
1836
+ type: UpdateRuleType.SETTING,
1809
1837
  payload: {
1810
- type: m.type,
1811
- formula1: m.formula1,
1812
- formula2: m.formula2,
1813
- [d]: c
1838
+ type: oldRule.type,
1839
+ formula1: oldRule.formula1,
1840
+ formula2: oldRule.formula2,
1841
+ [type]: formulaString
1814
1842
  }
1815
1843
  },
1816
1844
  source: "patched"
1817
- }, R = {
1818
- unitId: a,
1819
- subUnitId: e,
1820
- ruleId: t.uid,
1845
+ }, undoParams = {
1846
+ unitId,
1847
+ subUnitId,
1848
+ ruleId: rule.uid,
1821
1849
  payload: {
1822
- type: y.SETTING,
1850
+ type: UpdateRuleType.SETTING,
1823
1851
  payload: {
1824
- type: m.type,
1825
- formula1: m.formula1,
1826
- formula2: m.formula2
1852
+ type: oldRule.type,
1853
+ formula1: oldRule.formula1,
1854
+ formula2: oldRule.formula2
1827
1855
  }
1828
1856
  },
1829
1857
  source: "patched"
1830
- }, M = [
1858
+ }, redos = [
1831
1859
  {
1832
- id: E.id,
1833
- params: g
1860
+ id: UpdateDataValidationMutation.id,
1861
+ params: redoParams
1834
1862
  }
1835
- ], p = [
1863
+ ], undos = [
1836
1864
  {
1837
- id: E.id,
1838
- params: R
1865
+ id: UpdateDataValidationMutation.id,
1866
+ params: undoParams
1839
1867
  }
1840
1868
  ];
1841
- return { redos: M, undos: p };
1842
- }, l = this._dataValidationFormulaService.getRuleFormulaInfo(a, e, r);
1843
- if (l) {
1844
- const [d, c] = l;
1845
- if (d) {
1846
- const m = this._formulaRefRangeService.registerFormula(
1847
- a,
1848
- e,
1849
- d.text,
1850
- (_) => n("formula1", _)
1869
+ return { redos, undos };
1870
+ }, "handleFormulaChange"), currentFormula = this._dataValidationFormulaService.getRuleFormulaInfo(unitId, subUnitId, ruleId);
1871
+ if (currentFormula) {
1872
+ const [formula1, formula2] = currentFormula;
1873
+ if (formula1) {
1874
+ const disposable = this._formulaRefRangeService.registerFormula(
1875
+ unitId,
1876
+ subUnitId,
1877
+ formula1.text,
1878
+ (newFormulaString) => handleFormulaChange("formula1", newFormulaString)
1851
1879
  );
1852
- o.add(() => m.dispose());
1880
+ disposeSet.add(() => disposable.dispose());
1853
1881
  }
1854
- if (c) {
1855
- const m = this._formulaRefRangeService.registerFormula(
1856
- a,
1857
- e,
1858
- c.text,
1859
- (_) => n("formula2", _)
1882
+ if (formula2) {
1883
+ const disposable = this._formulaRefRangeService.registerFormula(
1884
+ unitId,
1885
+ subUnitId,
1886
+ formula2.text,
1887
+ (newFormulaString) => handleFormulaChange("formula2", newFormulaString)
1860
1888
  );
1861
- o.add(() => m.dispose());
1889
+ disposeSet.add(() => disposable.dispose());
1862
1890
  }
1863
1891
  }
1864
1892
  }
1865
- register(a, e, t) {
1866
- var l;
1867
- const r = (u) => {
1868
- const d = [...t.ranges], m = d.map((g) => Pt(g, u)).filter((g) => !!g).flat();
1869
- if (rt(m, d))
1893
+ register(unitId, subUnitId, rule) {
1894
+ var _a12;
1895
+ const handleRangeChange = /* @__PURE__ */ __name((commandInfo) => {
1896
+ const oldRanges = [...rule.ranges], resultRanges = oldRanges.map((range) => handleCommonDefaultRangeChangeWithEffectRefCommands(range, commandInfo)).filter((range) => !!range).flat();
1897
+ if (isRangesEqual(resultRanges, oldRanges))
1870
1898
  return { redos: [], undos: [] };
1871
- if (m.length) {
1872
- const g = {
1873
- unitId: a,
1874
- subUnitId: e,
1875
- ruleId: t.uid,
1899
+ if (resultRanges.length) {
1900
+ const redoParams = {
1901
+ unitId,
1902
+ subUnitId,
1903
+ ruleId: rule.uid,
1876
1904
  payload: {
1877
- type: y.RANGE,
1878
- payload: m
1905
+ type: UpdateRuleType.RANGE,
1906
+ payload: resultRanges
1879
1907
  },
1880
1908
  source: "patched"
1881
- }, R = [{ id: E.id, params: g }], M = [{
1882
- id: E.id,
1909
+ }, redos = [{ id: UpdateDataValidationMutation.id, params: redoParams }], undos = [{
1910
+ id: UpdateDataValidationMutation.id,
1883
1911
  params: {
1884
- unitId: a,
1885
- subUnitId: e,
1886
- ruleId: t.uid,
1912
+ unitId,
1913
+ subUnitId,
1914
+ ruleId: rule.uid,
1887
1915
  payload: {
1888
- type: y.RANGE,
1889
- payload: d
1916
+ type: UpdateRuleType.RANGE,
1917
+ payload: oldRanges
1890
1918
  },
1891
1919
  source: "patched"
1892
1920
  }
1893
1921
  }];
1894
- return { redos: R, undos: M };
1922
+ return { redos, undos };
1895
1923
  } else {
1896
- const g = { unitId: a, subUnitId: e, ruleId: t.uid }, R = [{ id: A.id, params: g }], M = Ma(this._injector, g);
1897
- return { redos: R, undos: M };
1924
+ const redoParams = { unitId, subUnitId, ruleId: rule.uid }, redos = [{ id: RemoveDataValidationMutation.id, params: redoParams }], undos = removeDataValidationUndoFactory(this._injector, redoParams);
1925
+ return { redos, undos };
1898
1926
  }
1899
- }, i = [];
1900
- t.ranges.forEach((u) => {
1901
- const d = this._refRangeService.registerRefRange(u, r, a, e);
1902
- i.push(() => d.dispose());
1927
+ }, "handleRangeChange"), disposeList = [];
1928
+ rule.ranges.forEach((range) => {
1929
+ const disposable = this._refRangeService.registerRefRange(range, handleRangeChange, unitId, subUnitId);
1930
+ disposeList.push(() => disposable.dispose());
1903
1931
  });
1904
- const o = this._getIdWithUnitId(a, e, t.uid), n = (l = this._disposableMap.get(o)) != null ? l : /* @__PURE__ */ new Set();
1905
- n.add(() => i.forEach((u) => u())), this._disposableMap.set(o, n);
1932
+ const id = this._getIdWithUnitId(unitId, subUnitId, rule.uid), current = (_a12 = this._disposableMap.get(id)) != null ? _a12 : /* @__PURE__ */ new Set();
1933
+ current.add(() => disposeList.forEach((dispose) => dispose())), this._disposableMap.set(id, current);
1906
1934
  }
1907
1935
  _initRefRange() {
1908
- const a = this._dataValidationModel.getAll();
1909
- for (const [e, t] of a)
1910
- for (const [r, i] of t)
1911
- for (const o of i)
1912
- this.registerRule(e, r, o);
1936
+ const allRules = this._dataValidationModel.getAll();
1937
+ for (const [unitId, subUnitMap] of allRules)
1938
+ for (const [subUnitId, rules] of subUnitMap)
1939
+ for (const rule of rules)
1940
+ this.registerRule(unitId, subUnitId, rule);
1913
1941
  this.disposeWithMe(
1914
- this._dataValidationModel.ruleChange$.subscribe((e) => {
1915
- const { unitId: t, subUnitId: r, rule: i } = e;
1916
- switch (e.type) {
1942
+ this._dataValidationModel.ruleChange$.subscribe((option) => {
1943
+ const { unitId, subUnitId, rule } = option;
1944
+ switch (option.type) {
1917
1945
  case "add": {
1918
- const o = e.rule;
1919
- this.registerRule(e.unitId, e.subUnitId, o);
1946
+ const rule2 = option.rule;
1947
+ this.registerRule(option.unitId, option.subUnitId, rule2);
1920
1948
  break;
1921
1949
  }
1922
1950
  case "remove": {
1923
- const o = this._disposableMap.get(this._getIdWithUnitId(t, r, i.uid));
1924
- o && o.forEach((n) => n());
1951
+ const disposeSet = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, rule.uid));
1952
+ disposeSet && disposeSet.forEach((dispose) => dispose());
1925
1953
  break;
1926
1954
  }
1927
1955
  case "update": {
1928
- const o = e.rule, n = this._disposableMap.get(this._getIdWithUnitId(t, r, o.uid));
1929
- n && n.forEach((l) => l()), this.registerRule(e.unitId, e.subUnitId, o);
1956
+ const rule2 = option.rule, disposeSet = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, rule2.uid));
1957
+ disposeSet && disposeSet.forEach((dispose) => dispose()), this.registerRule(option.unitId, option.subUnitId, rule2);
1930
1958
  break;
1931
1959
  }
1932
1960
  }
1933
1961
  })
1934
- ), this.disposeWithMe(qe(() => {
1935
- this._disposableMap.forEach((e) => {
1936
- e.forEach((t) => t());
1962
+ ), this.disposeWithMe(toDisposable(() => {
1963
+ this._disposableMap.forEach((item) => {
1964
+ item.forEach((dispose) => dispose());
1937
1965
  }), this._disposableMap.clear();
1938
1966
  }));
1939
1967
  }
1940
- };
1941
- Fe = Da([
1942
- ee(0, S(F)),
1943
- ee(1, S(Ge)),
1944
- ee(2, S(Ut)),
1945
- ee(3, S(X)),
1946
- ee(4, S(ut)),
1947
- ee(5, S(G))
1948
- ], Fe);
1949
- var ba = Object.defineProperty, La = Object.getOwnPropertyDescriptor, xa = (s, a, e, t) => {
1950
- for (var r = t > 1 ? void 0 : t ? La(a, e) : a, i = s.length - 1, o; i >= 0; i--)
1951
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
1952
- return t && r && ba(a, e, r), r;
1953
- }, We = (s, a) => (e, t) => a(e, t, s);
1954
- let Ne = class extends $ {
1955
- constructor(s, a, e) {
1956
- super(), this._sheetInterceptorService = s, this._univerInstanceService = a, this._sheetDataValidationModel = e, this._initSheetChange();
1968
+ }, __name(_a7, "DataValidationRefRangeController"), _a7);
1969
+ DataValidationRefRangeController = __decorateClass$4([
1970
+ __decorateParam$4(0, Inject(SheetDataValidationModel)),
1971
+ __decorateParam$4(1, Inject(Injector)),
1972
+ __decorateParam$4(2, Inject(RefRangeService)),
1973
+ __decorateParam$4(3, Inject(DataValidationFormulaService)),
1974
+ __decorateParam$4(4, Inject(FormulaRefRangeService)),
1975
+ __decorateParam$4(5, Inject(DataValidatorRegistryService))
1976
+ ], DataValidationRefRangeController);
1977
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1978
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1979
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1980
+ return kind && result && __defProp$3(target, key, result), result;
1981
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a8;
1982
+ let SheetDataValidationSheetController = (_a8 = class extends Disposable {
1983
+ constructor(_sheetInterceptorService, _univerInstanceService, _sheetDataValidationModel) {
1984
+ super(), this._sheetInterceptorService = _sheetInterceptorService, this._univerInstanceService = _univerInstanceService, this._sheetDataValidationModel = _sheetDataValidationModel, this._initSheetChange();
1957
1985
  }
1958
1986
  _initSheetChange() {
1959
1987
  this.disposeWithMe(
1960
1988
  this._sheetInterceptorService.interceptCommand({
1961
- getMutations: (s) => {
1962
- var a;
1963
- if (s.id === $t.id) {
1964
- const e = s.params, t = e.unitId || this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET).getUnitId(), r = this._univerInstanceService.getUniverSheetInstance(t);
1965
- if (!r)
1989
+ getMutations: /* @__PURE__ */ __name((commandInfo) => {
1990
+ var _a12;
1991
+ if (commandInfo.id === RemoveSheetCommand.id) {
1992
+ const params = commandInfo.params, unitId = params.unitId || this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET).getUnitId(), workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
1993
+ if (!workbook)
1966
1994
  return { redos: [], undos: [] };
1967
- const i = e.subUnitId || ((a = r.getActiveSheet()) == null ? void 0 : a.getSheetId());
1968
- if (!i)
1995
+ const subUnitId = params.subUnitId || ((_a12 = workbook.getActiveSheet()) == null ? void 0 : _a12.getSheetId());
1996
+ if (!subUnitId)
1969
1997
  return { redos: [], undos: [] };
1970
- const o = this._sheetDataValidationModel.getRules(t, i);
1971
- if (o.length === 0)
1998
+ const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
1999
+ if (rules.length === 0)
1972
2000
  return { redos: [], undos: [] };
1973
- const n = o.map((d) => d.uid), l = {
1974
- unitId: t,
1975
- subUnitId: i,
1976
- ruleId: n,
2001
+ const ids = rules.map((i) => i.uid), redoParams = {
2002
+ unitId,
2003
+ subUnitId,
2004
+ ruleId: ids,
1977
2005
  source: "patched"
1978
- }, u = {
1979
- unitId: t,
1980
- subUnitId: i,
1981
- rule: [...o],
2006
+ }, undoParams = {
2007
+ unitId,
2008
+ subUnitId,
2009
+ rule: [...rules],
1982
2010
  source: "patched"
1983
2011
  };
1984
2012
  return {
1985
2013
  redos: [{
1986
- id: A.id,
1987
- params: l
2014
+ id: RemoveDataValidationMutation.id,
2015
+ params: redoParams
1988
2016
  }],
1989
2017
  undos: [{
1990
- id: L.id,
1991
- params: u
2018
+ id: AddDataValidationMutation.id,
2019
+ params: undoParams
1992
2020
  }]
1993
2021
  };
1994
2022
  }
1995
2023
  return { redos: [], undos: [] };
1996
- }
2024
+ }, "getMutations")
1997
2025
  })
1998
2026
  );
1999
2027
  }
2000
- };
2001
- Ne = xa([
2002
- We(0, S(ot)),
2003
- We(1, S(O)),
2004
- We(2, S(F))
2005
- ], Ne);
2006
- class Ba extends k {
2028
+ }, __name(_a8, "SheetDataValidationSheetController"), _a8);
2029
+ SheetDataValidationSheetController = __decorateClass$3([
2030
+ __decorateParam$3(0, Inject(SheetInterceptorService)),
2031
+ __decorateParam$3(1, Inject(IUniverInstanceService)),
2032
+ __decorateParam$3(2, Inject(SheetDataValidationModel))
2033
+ ], SheetDataValidationSheetController);
2034
+ const _AnyValidator = class _AnyValidator extends BaseDataValidator {
2007
2035
  constructor() {
2008
2036
  super(...arguments);
2009
- f(this, "id", T.ANY);
2010
- f(this, "title", "dataValidation.any.title");
2011
- f(this, "operators", []);
2012
- f(this, "scopes", ["sheet"]);
2013
- f(this, "offsetFormulaByRange", !1);
2037
+ __publicField(this, "id", DataValidationType.ANY);
2038
+ __publicField(this, "title", "dataValidation.any.title");
2039
+ __publicField(this, "operators", []);
2040
+ __publicField(this, "scopes", ["sheet"]);
2041
+ __publicField(this, "offsetFormulaByRange", !1);
2014
2042
  }
2015
- async parseFormula(e, t, r) {
2043
+ async parseFormula(rule, unitId, subUnitId) {
2016
2044
  return {
2017
- formula1: e.formula1,
2018
- formula2: e.formula2,
2045
+ formula1: rule.formula1,
2046
+ formula2: rule.formula2,
2019
2047
  isFormulaValid: !0
2020
2048
  };
2021
2049
  }
2022
- validatorFormula(e, t, r) {
2050
+ validatorFormula(rule, unitId, subUnitId) {
2023
2051
  return {
2024
2052
  success: !0
2025
2053
  };
2026
2054
  }
2027
- async isValidType(e, t, r) {
2055
+ async isValidType(cellInfo, formula, rule) {
2028
2056
  return !0;
2029
2057
  }
2030
- generateRuleErrorMessage(e) {
2058
+ generateRuleErrorMessage(rule) {
2031
2059
  return this.localeService.t("dataValidation.any.error");
2032
2060
  }
2033
- }
2034
- class Ua extends k {
2061
+ };
2062
+ __name(_AnyValidator, "AnyValidator");
2063
+ let AnyValidator = _AnyValidator;
2064
+ const _CustomFormulaValidator = class _CustomFormulaValidator extends BaseDataValidator {
2035
2065
  constructor() {
2036
2066
  super(...arguments);
2037
- f(this, "id", T.CUSTOM);
2038
- f(this, "title", "dataValidation.custom.title");
2039
- f(this, "operators", []);
2040
- f(this, "scopes", ["sheet"]);
2041
- f(this, "_customFormulaService", this.injector.get(P));
2042
- }
2043
- validatorFormula(e, t, r) {
2044
- const i = v(e.formula1);
2067
+ __publicField(this, "id", DataValidationType.CUSTOM);
2068
+ __publicField(this, "title", "dataValidation.custom.title");
2069
+ __publicField(this, "operators", []);
2070
+ __publicField(this, "scopes", ["sheet"]);
2071
+ __publicField(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
2072
+ __publicField(this, "_lexerTreeBuilder", this.injector.get(LexerTreeBuilder));
2073
+ }
2074
+ validatorFormula(rule, unitId, subUnitId) {
2075
+ var _a12;
2076
+ const success = isFormulaString(rule.formula1), formulaText = (_a12 = rule.formula1) != null ? _a12 : "", valid = this._lexerTreeBuilder.checkIfAddBracket(formulaText) === 0 && formulaText.startsWith(operatorToken.EQUALS);
2045
2077
  return {
2046
- success: i,
2047
- formula1: i ? "" : this.localeService.t("dataValidation.validFail.formula")
2078
+ success: success && valid,
2079
+ formula1: success && valid ? "" : this.localeService.t("dataValidation.validFail.formula")
2048
2080
  };
2049
2081
  }
2050
- async parseFormula(e, t, r) {
2082
+ async parseFormula(_rule, _unitId, _subUnitId) {
2051
2083
  return {
2052
2084
  formula1: void 0,
2053
2085
  formula2: void 0,
2054
2086
  isFormulaValid: !0
2055
2087
  };
2056
2088
  }
2057
- async isValidType(e, t, r) {
2058
- const { column: i, row: o, unitId: n, subUnitId: l } = e, u = await this._customFormulaService.getCellFormulaValue(n, l, r.uid, o, i), d = u == null ? void 0 : u.v;
2059
- return C(String(d)) && V.isDefine(d) && d !== "" ? u.t === Tt.BOOLEAN ? !!d : typeof d == "boolean" ? d : typeof d == "number" ? !!d : typeof d == "string" ? C(d) : !!d : !1;
2089
+ async isValidType(cellInfo, _formula, _rule) {
2090
+ const { column, row, unitId, subUnitId } = cellInfo, cellData = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, _rule.uid, row, column), formulaResult = cellData == null ? void 0 : cellData.v;
2091
+ return isLegalFormulaResult(String(formulaResult)) && Tools.isDefine(formulaResult) && formulaResult !== "" ? cellData.t === CellValueType.BOOLEAN ? !!formulaResult : typeof formulaResult == "boolean" ? formulaResult : typeof formulaResult == "number" ? !!formulaResult : typeof formulaResult == "string" ? isLegalFormulaResult(formulaResult) : !!formulaResult : !1;
2060
2092
  }
2061
- generateRuleErrorMessage(e) {
2093
+ generateRuleErrorMessage(rule) {
2062
2094
  return this.localeService.t("dataValidation.custom.error");
2063
2095
  }
2064
- generateRuleName(e) {
2065
- var t;
2066
- return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}", (t = e.formula1) != null ? t : "");
2096
+ generateRuleName(rule) {
2097
+ var _a12;
2098
+ return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}", (_a12 = rule.formula1) != null ? _a12 : "");
2067
2099
  }
2068
- }
2069
- class Pa extends mt {
2100
+ };
2101
+ __name(_CustomFormulaValidator, "CustomFormulaValidator");
2102
+ let CustomFormulaValidator = _CustomFormulaValidator;
2103
+ const _ListMultipleValidator = class _ListMultipleValidator extends ListValidator {
2070
2104
  constructor() {
2071
2105
  super(...arguments);
2072
- f(this, "id", T.LIST_MULTIPLE);
2073
- f(this, "title", "dataValidation.listMultiple.title");
2074
- f(this, "offsetFormulaByRange", !1);
2075
- f(this, "skipDefaultFontRender", () => !0);
2106
+ __publicField(this, "id", DataValidationType.LIST_MULTIPLE);
2107
+ __publicField(this, "title", "dataValidation.listMultiple.title");
2108
+ __publicField(this, "offsetFormulaByRange", !1);
2109
+ __publicField(this, "skipDefaultFontRender", /* @__PURE__ */ __name(() => !0, "skipDefaultFontRender"));
2076
2110
  }
2077
- }
2078
- class $a extends k {
2111
+ };
2112
+ __name(_ListMultipleValidator, "ListMultipleValidator");
2113
+ let ListMultipleValidator = _ListMultipleValidator;
2114
+ const _WholeValidator = class _WholeValidator extends BaseDataValidator {
2079
2115
  constructor() {
2080
2116
  super(...arguments);
2081
- f(this, "_customFormulaService", this.injector.get(P));
2082
- f(this, "_lexerTreeBuilder", this.injector.get(Z));
2083
- f(this, "id", T.WHOLE);
2084
- f(this, "title", "dataValidation.whole.title");
2085
- f(this, "operators", [
2086
- h.BETWEEN,
2087
- h.EQUAL,
2088
- h.GREATER_THAN,
2089
- h.GREATER_THAN_OR_EQUAL,
2090
- h.LESS_THAN,
2091
- h.LESS_THAN_OR_EQUAL,
2092
- h.NOT_BETWEEN,
2093
- h.NOT_EQUAL
2117
+ __publicField(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
2118
+ __publicField(this, "_lexerTreeBuilder", this.injector.get(LexerTreeBuilder));
2119
+ __publicField(this, "id", DataValidationType.WHOLE);
2120
+ __publicField(this, "title", "dataValidation.whole.title");
2121
+ __publicField(this, "operators", [
2122
+ DataValidationOperator.BETWEEN,
2123
+ DataValidationOperator.EQUAL,
2124
+ DataValidationOperator.GREATER_THAN,
2125
+ DataValidationOperator.GREATER_THAN_OR_EQUAL,
2126
+ DataValidationOperator.LESS_THAN,
2127
+ DataValidationOperator.LESS_THAN_OR_EQUAL,
2128
+ DataValidationOperator.NOT_BETWEEN,
2129
+ DataValidationOperator.NOT_EQUAL
2094
2130
  ]);
2095
- f(this, "scopes", ["sheet"]);
2131
+ __publicField(this, "scopes", ["sheet"]);
2096
2132
  }
2097
- _isFormulaOrInt(e) {
2098
- return !V.isBlank(e) && (v(e) || !Number.isNaN(+e) && Number.isInteger(+e));
2133
+ _isFormulaOrInt(formula) {
2134
+ return !Tools.isBlank(formula) && (isFormulaString(formula) || !Number.isNaN(+formula) && Number.isInteger(+formula));
2099
2135
  }
2100
- async isValidType(e, t, r) {
2101
- const { value: i } = e, o = ye(i);
2102
- return !Number.isNaN(o) && Number.isInteger(o);
2136
+ async isValidType(cellInfo, _formula, _rule) {
2137
+ const { value: cellValue } = cellInfo, num = getCellValueNumber(cellValue);
2138
+ return !Number.isNaN(num) && Number.isInteger(num);
2103
2139
  }
2104
- transform(e, t, r) {
2105
- const { value: i } = e;
2140
+ transform(cellInfo, _formula, _rule) {
2141
+ const { value: cellValue } = cellInfo;
2106
2142
  return {
2107
- ...e,
2108
- value: ye(i)
2143
+ ...cellInfo,
2144
+ value: getCellValueNumber(cellValue)
2109
2145
  };
2110
2146
  }
2111
- _parseNumber(e) {
2112
- return e == null ? Number.NaN : +e;
2147
+ _parseNumber(formula) {
2148
+ return formula == null ? Number.NaN : +formula;
2113
2149
  }
2114
- async parseFormula(e, t, r, i, o) {
2115
- const n = await this._customFormulaService.getCellFormulaValue(t, r, e.uid, i, o), l = await this._customFormulaService.getCellFormula2Value(t, r, e.uid, i, o), { formula1: u, formula2: d } = e, c = v(u) ? n == null ? void 0 : n.v : u, m = v(d) ? l == null ? void 0 : l.v : d, _ = C(`${c}`) && C(`${m}`);
2150
+ async parseFormula(rule, unitId, subUnitId, row, column) {
2151
+ const res1 = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, rule.uid, row, column), res2 = await this._customFormulaService.getCellFormula2Value(unitId, subUnitId, rule.uid, row, column), { formula1, formula2 } = rule, formula1Result = isFormulaString(formula1) ? res1 == null ? void 0 : res1.v : formula1, formula2Result = isFormulaString(formula2) ? res2 == null ? void 0 : res2.v : formula2, isFormulaValid = isLegalFormulaResult(`${formula1Result}`) && isLegalFormulaResult(`${formula2Result}`);
2116
2152
  return {
2117
- formula1: this._parseNumber(c),
2118
- formula2: this._parseNumber(m),
2119
- isFormulaValid: _
2153
+ formula1: this._parseNumber(formula1Result),
2154
+ formula2: this._parseNumber(formula2Result),
2155
+ isFormulaValid
2120
2156
  };
2121
2157
  }
2122
- validatorFormula(e, t, r) {
2123
- const i = e.operator;
2124
- if (!i)
2158
+ validatorFormula(rule, _unitId, _subUnitId) {
2159
+ const operator = rule.operator;
2160
+ if (!operator)
2125
2161
  return {
2126
2162
  success: !1
2127
2163
  };
2128
- const o = V.isDefine(e.formula1) && this._isFormulaOrInt(e.formula1), n = V.isDefine(e.formula2) && this._isFormulaOrInt(e.formula2), l = Ae.includes(i), u = this.localeService.t("dataValidation.validFail.number");
2129
- return l ? {
2130
- success: o && n,
2131
- formula1: o ? void 0 : u,
2132
- formula2: n ? void 0 : u
2164
+ const formula1Success = Tools.isDefine(rule.formula1) && this._isFormulaOrInt(rule.formula1), formula2Success = Tools.isDefine(rule.formula2) && this._isFormulaOrInt(rule.formula2), isTwoFormula = TWO_FORMULA_OPERATOR_COUNT.includes(operator), errorMsg = this.localeService.t("dataValidation.validFail.number");
2165
+ return isTwoFormula ? {
2166
+ success: formula1Success && formula2Success,
2167
+ formula1: formula1Success ? void 0 : errorMsg,
2168
+ formula2: formula2Success ? void 0 : errorMsg
2133
2169
  } : {
2134
- success: o,
2135
- formula1: u
2170
+ success: formula1Success,
2171
+ formula1: errorMsg
2136
2172
  };
2137
2173
  }
2138
- generateRuleErrorMessage(e, t) {
2139
- if (!e.operator)
2174
+ generateRuleErrorMessage(rule, position) {
2175
+ if (!rule.operator)
2140
2176
  return this.titleStr;
2141
- const { transformedFormula1: r, transformedFormula2: i } = De(this._lexerTreeBuilder, e, t);
2142
- return `${this.localeService.t(ht[e.operator]).replace(le, r != null ? r : "").replace(ue, i != null ? i : "")}`;
2177
+ const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, position);
2178
+ return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 != null ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 != null ? transformedFormula2 : "")}`;
2143
2179
  }
2144
- }
2145
- var Ha = Object.defineProperty, Wa = Object.getOwnPropertyDescriptor, ja = (s, a, e, t) => {
2146
- for (var r = t > 1 ? void 0 : t ? Wa(a, e) : a, i = s.length - 1, o; i >= 0; i--)
2147
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
2148
- return t && r && Ha(a, e, r), r;
2149
- }, te = (s, a) => (e, t) => a(e, t, s);
2150
- let Ce = class extends Ft {
2151
- constructor(s, a, e, t, r, i) {
2152
- super(), this._univerInstanceService = s, this._dataValidatorRegistryService = a, this._injector = e, this._selectionManagerService = t, this._sheetInterceptorService = r, this._sheetDataValidationModel = i, this._init();
2180
+ };
2181
+ __name(_WholeValidator, "WholeValidator");
2182
+ let WholeValidator = _WholeValidator;
2183
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2184
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2185
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2186
+ return kind && result && __defProp$2(target, key, result), result;
2187
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a9;
2188
+ let DataValidationController = (_a9 = class extends RxDisposable {
2189
+ constructor(_univerInstanceService, _dataValidatorRegistryService, _injector, _selectionManagerService, _sheetInterceptorService, _sheetDataValidationModel) {
2190
+ super(), this._univerInstanceService = _univerInstanceService, this._dataValidatorRegistryService = _dataValidatorRegistryService, this._injector = _injector, this._selectionManagerService = _selectionManagerService, this._sheetInterceptorService = _sheetInterceptorService, this._sheetDataValidationModel = _sheetDataValidationModel, this._init();
2153
2191
  }
2154
2192
  _init() {
2155
2193
  this._registerValidators(), this._initCommandInterceptor();
2156
2194
  }
2157
2195
  _registerValidators() {
2158
2196
  [
2159
- Ba,
2160
- ca,
2161
- $a,
2162
- ga,
2163
- da,
2164
- oa,
2165
- mt,
2166
- Pa,
2167
- Ua
2168
- ].forEach((s) => {
2169
- const a = this._injector.createInstance(s);
2170
- this.disposeWithMe(this._dataValidatorRegistryService.register(a)), this.disposeWithMe(qe(() => this._injector.delete(s)));
2197
+ AnyValidator,
2198
+ DecimalValidator,
2199
+ WholeValidator,
2200
+ TextLengthValidator,
2201
+ DateValidator,
2202
+ CheckboxValidator,
2203
+ ListValidator,
2204
+ ListMultipleValidator,
2205
+ CustomFormulaValidator
2206
+ ].forEach((Validator) => {
2207
+ const validator = this._injector.createInstance(Validator);
2208
+ this.disposeWithMe(this._dataValidatorRegistryService.register(validator)), this.disposeWithMe(toDisposable(() => this._injector.delete(Validator)));
2171
2209
  });
2172
2210
  }
2173
2211
  _initCommandInterceptor() {
2174
2212
  this._sheetInterceptorService.interceptCommand({
2175
- getMutations: (s) => {
2176
- var a;
2177
- if (s.id === Ht.id) {
2178
- const e = this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET), t = e.getUnitId(), r = e.getActiveSheet();
2179
- if (!r)
2213
+ getMutations: /* @__PURE__ */ __name((commandInfo) => {
2214
+ var _a12;
2215
+ if (commandInfo.id === ClearSelectionAllCommand.id) {
2216
+ const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), unitId = workbook.getUnitId(), worksheet = workbook.getActiveSheet();
2217
+ if (!worksheet)
2180
2218
  throw new Error("No active sheet found");
2181
- const i = r.getSheetId(), o = (a = this._selectionManagerService.getCurrentSelections()) == null ? void 0 : a.map((c) => c.range), n = this._sheetDataValidationModel.getRuleObjectMatrix(t, i).clone();
2182
- o && n.removeRange(o);
2183
- const l = n.diff(this._sheetDataValidationModel.getRules(t, i)), { redoMutations: u, undoMutations: d } = be(t, i, l, this._injector, "patched");
2219
+ const subUnitId = worksheet.getSheetId(), selections = (_a12 = this._selectionManagerService.getCurrentSelections()) == null ? void 0 : _a12.map((s) => s.range), ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
2220
+ selections && ruleMatrix.removeRange(selections);
2221
+ const diffs = ruleMatrix.diff(this._sheetDataValidationModel.getRules(unitId, subUnitId)), { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, this._injector, "patched");
2184
2222
  return {
2185
- undos: d,
2186
- redos: u
2223
+ undos: undoMutations,
2224
+ redos: redoMutations
2187
2225
  };
2188
2226
  }
2189
2227
  return {
2190
2228
  undos: [],
2191
2229
  redos: []
2192
2230
  };
2193
- }
2231
+ }, "getMutations")
2194
2232
  });
2195
2233
  }
2196
- };
2197
- Ce = ja([
2198
- te(0, O),
2199
- te(1, S(G)),
2200
- te(2, S(Ge)),
2201
- te(3, S(nt)),
2202
- te(4, S(ot)),
2203
- te(5, S(F))
2204
- ], Ce);
2205
- var Qa = Object.defineProperty, qa = Object.getOwnPropertyDescriptor, Ga = (s, a, e, t) => {
2206
- for (var r = t > 1 ? void 0 : t ? qa(a, e) : a, i = s.length - 1, o; i >= 0; i--)
2207
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
2208
- return t && r && Qa(a, e, r), r;
2209
- }, Re = (s, a) => (e, t) => a(e, t, s);
2210
- let Oe = class extends $ {
2211
- constructor(s, a, e, t) {
2212
- super(), this._univerInstanceService = s, this._sheetDataValidationModel = a, this._dataValidationCacheService = e, this._lifecycleService = t, this._initRecalculate();
2234
+ }, __name(_a9, "DataValidationController"), _a9);
2235
+ DataValidationController = __decorateClass$2([
2236
+ __decorateParam$2(0, IUniverInstanceService),
2237
+ __decorateParam$2(1, Inject(DataValidatorRegistryService)),
2238
+ __decorateParam$2(2, Inject(Injector)),
2239
+ __decorateParam$2(3, Inject(SheetsSelectionsService)),
2240
+ __decorateParam$2(4, Inject(SheetInterceptorService)),
2241
+ __decorateParam$2(5, Inject(SheetDataValidationModel))
2242
+ ], DataValidationController);
2243
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2244
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2245
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2246
+ return kind && result && __defProp$1(target, key, result), result;
2247
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a10;
2248
+ let SheetsDataValidationValidatorService = (_a10 = class extends Disposable {
2249
+ constructor(_univerInstanceService, _sheetDataValidationModel, _dataValidationCacheService, _lifecycleService) {
2250
+ super(), this._univerInstanceService = _univerInstanceService, this._sheetDataValidationModel = _sheetDataValidationModel, this._dataValidationCacheService = _dataValidationCacheService, this._lifecycleService = _lifecycleService, this._initRecalculate();
2213
2251
  }
2214
2252
  _initRecalculate() {
2215
- const s = (a) => {
2216
- if (a.length === 0)
2253
+ const handleDirtyRanges = /* @__PURE__ */ __name((ranges) => {
2254
+ if (ranges.length === 0)
2217
2255
  return;
2218
- const e = this._univerInstanceService.getCurrentUnitForType(N.UNIVER_SHEET), t = e == null ? void 0 : e.getActiveSheet(), r = {};
2219
- a.flat().forEach((i) => {
2220
- r[i.unitId] || (r[i.unitId] = {}), r[i.unitId][i.subUnitId] || (r[i.unitId][i.subUnitId] = []);
2221
- const o = this._univerInstanceService.getUnit(i.unitId, N.UNIVER_SHEET), n = o == null ? void 0 : o.getSheetBySheetId(i.subUnitId);
2222
- n && r[i.unitId][i.subUnitId].push(...i.ranges.map((l) => b.transformRange(l, n)));
2223
- }), Object.entries(r).forEach(([i, o]) => {
2224
- Object.entries(o).forEach(([n, l]) => {
2225
- (e == null ? void 0 : e.getUnitId()) === i && (t == null ? void 0 : t.getSheetId()) === n ? this.validatorRanges(i, n, l) : requestIdleCallback(() => {
2226
- this.validatorRanges(i, n, l);
2256
+ const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), worksheet = workbook == null ? void 0 : workbook.getActiveSheet(), map = {};
2257
+ ranges.flat().forEach((range) => {
2258
+ map[range.unitId] || (map[range.unitId] = {}), map[range.unitId][range.subUnitId] || (map[range.unitId][range.subUnitId] = []);
2259
+ const workbook2 = this._univerInstanceService.getUnit(range.unitId, UniverInstanceType.UNIVER_SHEET), worksheet2 = workbook2 == null ? void 0 : workbook2.getSheetBySheetId(range.subUnitId);
2260
+ worksheet2 && map[range.unitId][range.subUnitId].push(...range.ranges.map((range2) => Range.transformRange(range2, worksheet2)));
2261
+ }), Object.entries(map).forEach(([unitId, subUnitMap]) => {
2262
+ Object.entries(subUnitMap).forEach(([subUnitId, ranges2]) => {
2263
+ (workbook == null ? void 0 : workbook.getUnitId()) === unitId && (worksheet == null ? void 0 : worksheet.getSheetId()) === subUnitId ? this.validatorRanges(unitId, subUnitId, ranges2) : requestIdleCallback(() => {
2264
+ this.validatorRanges(unitId, subUnitId, ranges2);
2227
2265
  });
2228
2266
  });
2229
2267
  });
2230
- };
2231
- this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(Wt(() => this._lifecycleService.lifecycle$.pipe(Ze((a) => a === ze.Rendered)))).subscribe(s)), this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(Ze(() => this._lifecycleService.stage >= ze.Rendered), Ct(20)).subscribe(s));
2232
- }
2233
- async _validatorByCell(s, a, e, t) {
2234
- const r = s.getUnitId(), i = a.getSheetId();
2235
- if (!V.isDefine(e) || !V.isDefine(t))
2236
- throw new Error(`row or col is not defined, row: ${e}, col: ${t}`);
2237
- const o = this._sheetDataValidationModel.getRuleByLocation(r, i, e, t);
2238
- return o ? new Promise((n) => {
2239
- this._sheetDataValidationModel.validator(o, { unitId: r, subUnitId: i, row: e, col: t, worksheet: a, workbook: s }, (l) => {
2240
- n(l);
2268
+ }, "handleDirtyRanges");
2269
+ this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(bufferWhen(() => this._lifecycleService.lifecycle$.pipe(filter((stage) => stage === LifecycleStages.Rendered)))).subscribe(handleDirtyRanges)), this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(filter(() => this._lifecycleService.stage >= LifecycleStages.Rendered), bufferDebounceTime(20)).subscribe(handleDirtyRanges));
2270
+ }
2271
+ async _validatorByCell(workbook, worksheet, row, col) {
2272
+ const unitId = workbook.getUnitId(), subUnitId = worksheet.getSheetId();
2273
+ if (!Tools.isDefine(row) || !Tools.isDefine(col))
2274
+ throw new Error(`row or col is not defined, row: ${row}, col: ${col}`);
2275
+ const rule = this._sheetDataValidationModel.getRuleByLocation(unitId, subUnitId, row, col);
2276
+ return rule ? new Promise((resolve) => {
2277
+ this._sheetDataValidationModel.validator(rule, { unitId, subUnitId, row, col, worksheet, workbook }, (status) => {
2278
+ resolve(status);
2241
2279
  });
2242
- }) : D.VALID;
2243
- }
2244
- async validatorCell(s, a, e, t) {
2245
- const r = this._univerInstanceService.getUnit(s, N.UNIVER_SHEET);
2246
- if (!r)
2247
- throw new Error(`cannot find current workbook, unitId: ${s}`);
2248
- const i = r.getSheetBySheetId(a);
2249
- if (!i)
2250
- throw new Error(`cannot find current worksheet, sheetId: ${a}`);
2251
- return this._validatorByCell(r, i, e, t);
2252
- }
2253
- validatorRanges(s, a, e) {
2254
- if (!e.length)
2280
+ }) : DataValidationStatus.VALID;
2281
+ }
2282
+ async validatorCell(unitId, subUnitId, row, col) {
2283
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
2284
+ if (!workbook)
2285
+ throw new Error(`cannot find current workbook, unitId: ${unitId}`);
2286
+ const worksheet = workbook.getSheetBySheetId(subUnitId);
2287
+ if (!worksheet)
2288
+ throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
2289
+ return this._validatorByCell(workbook, worksheet, row, col);
2290
+ }
2291
+ validatorRanges(unitId, subUnitId, ranges) {
2292
+ if (!ranges.length)
2255
2293
  return Promise.resolve([]);
2256
- const t = this._univerInstanceService.getUnit(s, N.UNIVER_SHEET);
2257
- if (!t)
2258
- throw new Error(`cannot find current workbook, unitId: ${s}`);
2259
- const r = t.getSheetBySheetId(a);
2260
- if (!r)
2261
- throw new Error(`cannot find current worksheet, sheetId: ${a}`);
2262
- return Promise.all(e.map((i) => {
2263
- const o = [];
2264
- return b.foreach(i, (n, l) => {
2265
- o.push(this._validatorByCell(t, r, n, l));
2266
- }), o;
2294
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
2295
+ if (!workbook)
2296
+ throw new Error(`cannot find current workbook, unitId: ${unitId}`);
2297
+ const worksheet = workbook.getSheetBySheetId(subUnitId);
2298
+ if (!worksheet)
2299
+ throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
2300
+ return Promise.all(ranges.map((range) => {
2301
+ const promises = [];
2302
+ return Range.foreach(range, (row, col) => {
2303
+ promises.push(this._validatorByCell(workbook, worksheet, row, col));
2304
+ }), Promise.all(promises);
2267
2305
  }));
2268
2306
  }
2269
- async validatorWorksheet(s, a) {
2270
- const e = this._univerInstanceService.getUnit(s, N.UNIVER_SHEET);
2271
- if (!e)
2272
- throw new Error(`cannot find current workbook, unitId: ${s}`);
2273
- const t = e.getSheetBySheetId(a);
2274
- if (!t)
2275
- throw new Error(`cannot find current worksheet, sheetId: ${a}`);
2276
- const r = this._sheetDataValidationModel.getRules(s, a);
2277
- return await Promise.all(r.map((i) => Promise.all(i.ranges.map((o) => {
2278
- const n = [];
2279
- return b.foreach(o, (l, u) => {
2280
- n.push(this._validatorByCell(e, t, l, u));
2281
- }), n;
2282
- })))), this._dataValidationCacheService.ensureCache(s, a);
2283
- }
2284
- async validatorWorkbook(s) {
2285
- const a = this._sheetDataValidationModel.getSubUnitIds(s), e = await Promise.all(a.map((r) => this.validatorWorksheet(s, r))), t = {};
2286
- return e.forEach((r, i) => {
2287
- t[a[i]] = r;
2288
- }), t;
2289
- }
2290
- getDataValidations(s, a, e) {
2291
- const t = this._sheetDataValidationModel.getRuleObjectMatrix(s, a), r = /* @__PURE__ */ new Set();
2292
- return e.forEach((o) => {
2293
- b.foreach(o, (n, l) => {
2294
- const u = t.getValue(n, l);
2295
- u && r.add(u);
2307
+ async validatorWorksheet(unitId, subUnitId) {
2308
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
2309
+ if (!workbook)
2310
+ throw new Error(`cannot find current workbook, unitId: ${unitId}`);
2311
+ const worksheet = workbook.getSheetBySheetId(subUnitId);
2312
+ if (!worksheet)
2313
+ throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
2314
+ const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
2315
+ return await Promise.all(rules.map((rule) => Promise.all(rule.ranges.map((range) => {
2316
+ const promises = [];
2317
+ return Range.foreach(range, (row, col) => {
2318
+ promises.push(this._validatorByCell(workbook, worksheet, row, col));
2319
+ }), promises;
2320
+ })))), this._dataValidationCacheService.ensureCache(unitId, subUnitId);
2321
+ }
2322
+ async validatorWorkbook(unitId) {
2323
+ const sheetIds = this._sheetDataValidationModel.getSubUnitIds(unitId), results = await Promise.all(sheetIds.map((id) => this.validatorWorksheet(unitId, id))), map = {};
2324
+ return results.forEach((result, i) => {
2325
+ map[sheetIds[i]] = result;
2326
+ }), map;
2327
+ }
2328
+ getDataValidations(unitId, subUnitId, ranges) {
2329
+ const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId), ruleIdSet = /* @__PURE__ */ new Set();
2330
+ return ranges.forEach((range) => {
2331
+ Range.foreach(range, (row, col) => {
2332
+ const ruleId = ruleMatrix.getValue(row, col);
2333
+ ruleId && ruleIdSet.add(ruleId);
2296
2334
  });
2297
- }), Array.from(r).map((o) => this._sheetDataValidationModel.getRuleById(s, a, o)).filter(Boolean);
2298
- }
2299
- getDataValidation(s, a, e) {
2300
- return this.getDataValidations(s, a, e)[0];
2301
- }
2302
- };
2303
- Oe = Ga([
2304
- Re(0, O),
2305
- Re(1, S(F)),
2306
- Re(2, S(q)),
2307
- Re(3, S(Nt))
2308
- ], Oe);
2309
- var _t = Object.defineProperty, ka = Object.getOwnPropertyDescriptor, Ya = (s, a, e) => a in s ? _t(s, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[a] = e, Xa = (s, a, e, t) => {
2310
- for (var r = t > 1 ? void 0 : t ? ka(a, e) : a, i = s.length - 1, o; i >= 0; i--)
2311
- (o = s[i]) && (r = (t ? o(a, e, r) : o(r)) || r);
2312
- return t && r && _t(a, e, r), r;
2313
- }, je = (s, a) => (e, t) => a(e, t, s), pt = (s, a, e) => Ya(s, typeof a != "symbol" ? a + "" : a, e);
2314
- let we = class extends wt {
2315
- constructor(s = tt, a, e, t) {
2316
- super(), this._config = s, this._injector = a, this._commandService = e, this._configService = t;
2317
- const { ...r } = It(
2335
+ }), Array.from(ruleIdSet).map((id) => this._sheetDataValidationModel.getRuleById(unitId, subUnitId, id)).filter(Boolean);
2336
+ }
2337
+ getDataValidation(unitId, subUnitId, ranges) {
2338
+ return this.getDataValidations(unitId, subUnitId, ranges)[0];
2339
+ }
2340
+ }, __name(_a10, "SheetsDataValidationValidatorService"), _a10);
2341
+ SheetsDataValidationValidatorService = __decorateClass$1([
2342
+ __decorateParam$1(0, IUniverInstanceService),
2343
+ __decorateParam$1(1, Inject(SheetDataValidationModel)),
2344
+ __decorateParam$1(2, Inject(DataValidationCacheService)),
2345
+ __decorateParam$1(3, Inject(LifecycleService))
2346
+ ], SheetsDataValidationValidatorService);
2347
+ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2348
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2349
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2350
+ return kind && result && __defProp2(target, key, result), result;
2351
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a11;
2352
+ let UniverSheetsDataValidationPlugin = (_a11 = class extends Plugin {
2353
+ constructor(_config = defaultPluginConfig, _injector, _commandService, _configService) {
2354
+ super(), this._config = _config, this._injector = _injector, this._commandService = _commandService, this._configService = _configService;
2355
+ const { ...rest } = merge(
2318
2356
  {},
2319
- tt,
2357
+ defaultPluginConfig,
2320
2358
  this._config
2321
2359
  );
2322
- this._configService.setConfig(Ea, r);
2360
+ this._configService.setConfig(SHEETS_DATA_VALIDATION_PLUGIN_CONFIG_KEY, rest);
2323
2361
  }
2324
2362
  onStarting() {
2325
2363
  [
2326
- [q],
2327
- [X],
2328
- [P],
2329
- [Oe],
2330
- [F],
2331
- [Ce],
2332
- [Te],
2333
- [Ne],
2334
- [Fe],
2335
- [Ee]
2336
- ].forEach((s) => {
2337
- this._injector.add(s);
2364
+ [DataValidationCacheService],
2365
+ [DataValidationFormulaService],
2366
+ [DataValidationCustomFormulaService],
2367
+ [SheetsDataValidationValidatorService],
2368
+ [SheetDataValidationModel],
2369
+ [DataValidationController],
2370
+ [DataValidationFormulaController],
2371
+ [SheetDataValidationSheetController],
2372
+ [DataValidationRefRangeController],
2373
+ [DataValidationFormulaRefRangeController]
2374
+ ].forEach((dep) => {
2375
+ this._injector.add(dep);
2338
2376
  }), [
2339
- pa,
2340
- _a,
2341
- Ra,
2342
- Sa,
2343
- ya,
2344
- Va,
2345
- va
2346
- ].forEach((s) => {
2347
- this._commandService.registerCommand(s);
2348
- }), this._injector.get(q), this._injector.get(Oe), this._injector.get(Ee), this._injector.get(Fe);
2377
+ AddSheetDataValidationCommand,
2378
+ UpdateSheetDataValidationRangeCommand,
2379
+ UpdateSheetDataValidationSettingCommand,
2380
+ UpdateSheetDataValidationOptionsCommand,
2381
+ RemoveSheetDataValidationCommand,
2382
+ RemoveSheetAllDataValidationCommand,
2383
+ ClearRangeDataValidationCommand
2384
+ ].forEach((command) => {
2385
+ this._commandService.registerCommand(command);
2386
+ }), this._injector.get(DataValidationCacheService), this._injector.get(SheetsDataValidationValidatorService), this._injector.get(DataValidationFormulaRefRangeController), this._injector.get(DataValidationRefRangeController);
2349
2387
  }
2350
2388
  onReady() {
2351
- this._injector.get(Ne);
2389
+ this._injector.get(SheetDataValidationSheetController);
2352
2390
  }
2353
2391
  onRendered() {
2354
- this._injector.get(Ce), this._injector.get(Te);
2355
- }
2356
- };
2357
- pt(we, "pluginName", kt);
2358
- pt(we, "type", N.UNIVER_SHEET);
2359
- we = Xa([
2360
- Ot(xt),
2361
- je(1, S(Ge)),
2362
- je(2, x),
2363
- je(3, At)
2364
- ], we);
2365
- function sr(s) {
2366
- const e = s.get(nt).getCurrentSelections().map((i) => i.range);
2392
+ this._injector.get(DataValidationController), this._injector.get(DataValidationFormulaController);
2393
+ }
2394
+ }, __name(_a11, "UniverSheetsDataValidationPlugin"), _a11);
2395
+ __publicField2(UniverSheetsDataValidationPlugin, "pluginName", DATA_VALIDATION_PLUGIN_NAME);
2396
+ __publicField2(UniverSheetsDataValidationPlugin, "type", UniverInstanceType.UNIVER_SHEET);
2397
+ UniverSheetsDataValidationPlugin = __decorateClass([
2398
+ DependentOn(UniverDataValidationPlugin),
2399
+ __decorateParam(1, Inject(Injector)),
2400
+ __decorateParam(2, ICommandService),
2401
+ __decorateParam(3, IConfigService)
2402
+ ], UniverSheetsDataValidationPlugin);
2403
+ function createDefaultNewRule(accessor) {
2404
+ const currentRanges = accessor.get(SheetsSelectionsService).getCurrentSelections().map((s) => s.range);
2367
2405
  return {
2368
- uid: V.generateRandomId(6),
2369
- type: T.DECIMAL,
2370
- operator: h.EQUAL,
2406
+ uid: Tools.generateRandomId(6),
2407
+ type: DataValidationType.DECIMAL,
2408
+ operator: DataValidationOperator.EQUAL,
2371
2409
  formula1: "100",
2372
- ranges: e != null ? e : [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }]
2410
+ ranges: currentRanges != null ? currentRanges : [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }]
2373
2411
  };
2374
2412
  }
2413
+ __name(createDefaultNewRule, "createDefaultNewRule");
2375
2414
  export {
2376
- pa as AddSheetDataValidationCommand,
2377
- Ve as CHECKBOX_FORMULA_1,
2378
- Me as CHECKBOX_FORMULA_2,
2379
- oa as CheckboxValidator,
2380
- va as ClearRangeDataValidationCommand,
2381
- kt as DATA_VALIDATION_PLUGIN_NAME,
2382
- q as DataValidationCacheService,
2383
- P as DataValidationCustomFormulaService,
2384
- Te as DataValidationFormulaController,
2385
- X as DataValidationFormulaService,
2386
- da as DateValidator,
2387
- Pa as ListMultipleValidator,
2388
- mt as ListValidator,
2389
- Va as RemoveSheetAllDataValidationCommand,
2390
- ya as RemoveSheetDataValidationCommand,
2391
- F as SheetDataValidationModel,
2392
- Oe as SheetsDataValidationValidatorService,
2393
- we as UniverSheetsDataValidationPlugin,
2394
- Sa as UpdateSheetDataValidationOptionsCommand,
2395
- _a as UpdateSheetDataValidationRangeCommand,
2396
- Ra as UpdateSheetDataValidationSettingCommand,
2397
- sr as createDefaultNewRule,
2398
- pe as deserializeListOptions,
2399
- ne as getCellValueOrigin,
2400
- ir as getDataValidationCellValue,
2401
- be as getDataValidationDiffMutations,
2402
- ge as getFormulaCellData,
2403
- se as getFormulaResult,
2404
- C as isLegalFormulaResult,
2405
- rr as serializeListOptions,
2406
- _e as transformCheckboxValue
2415
+ AddSheetDataValidationCommand,
2416
+ CHECKBOX_FORMULA_1,
2417
+ CHECKBOX_FORMULA_2,
2418
+ CheckboxValidator,
2419
+ ClearRangeDataValidationCommand,
2420
+ DATA_VALIDATION_PLUGIN_NAME,
2421
+ DataValidationCacheService,
2422
+ DataValidationCustomFormulaService,
2423
+ DataValidationFormulaController,
2424
+ DataValidationFormulaService,
2425
+ DateValidator,
2426
+ ListMultipleValidator,
2427
+ ListValidator,
2428
+ RemoveSheetAllDataValidationCommand,
2429
+ RemoveSheetDataValidationCommand,
2430
+ SheetDataValidationModel,
2431
+ SheetsDataValidationValidatorService,
2432
+ UniverSheetsDataValidationPlugin,
2433
+ UpdateSheetDataValidationOptionsCommand,
2434
+ UpdateSheetDataValidationRangeCommand,
2435
+ UpdateSheetDataValidationSettingCommand,
2436
+ createDefaultNewRule,
2437
+ deserializeListOptions,
2438
+ getCellValueOrigin,
2439
+ getDataValidationCellValue,
2440
+ getDataValidationDiffMutations,
2441
+ getFormulaCellData,
2442
+ getFormulaResult,
2443
+ isLegalFormulaResult,
2444
+ serializeListOptions,
2445
+ transformCheckboxValue
2407
2446
  };