@univerjs/data-validation 0.4.2 → 0.5.0-beta.0

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,676 +1,673 @@
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 { Disposable, Tools, ILogService, Inject, UniverInstanceType, IResourceManagerService, IUniverInstanceService, toDisposable, CommandType, ICommandService, IUndoRedoService, Plugin, Injector, IConfigService, DataValidationOperator, LocaleService } from "@univerjs/core";
6
- import { Subject, debounceTime, BehaviorSubject } from "rxjs";
7
- function getRuleSetting(rule) {
1
+ var F = Object.defineProperty;
2
+ var J = (t, e, a) => e in t ? F(t, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[e] = a;
3
+ var c = (t, e, a) => J(t, typeof e != "symbol" ? e + "" : e, a);
4
+ import { Disposable as P, Tools as B, ILogService as T, Inject as O, UniverInstanceType as x, IResourceManagerService as z, IUniverInstanceService as K, toDisposable as Y, CommandType as E, ICommandService as S, IUndoRedoService as M, Plugin as X, Injector as $, IConfigService as Z, DataValidationOperator as s, LocaleService as k } from "@univerjs/core";
5
+ import { Subject as ee, debounceTime as te, BehaviorSubject as ae } from "rxjs";
6
+ function G(t) {
8
7
  return {
9
- type: rule.type,
10
- operator: rule.operator,
11
- formula1: rule.formula1,
12
- formula2: rule.formula2,
13
- allowBlank: rule.allowBlank
8
+ type: t.type,
9
+ operator: t.operator,
10
+ formula1: t.formula1,
11
+ formula2: t.formula2,
12
+ allowBlank: t.allowBlank
14
13
  };
15
14
  }
16
- __name(getRuleSetting, "getRuleSetting");
17
- function getRuleOptions(rule) {
15
+ function q(t) {
18
16
  return {
19
- error: rule.error,
20
- errorStyle: rule.errorStyle,
21
- errorTitle: rule.errorTitle,
22
- imeMode: rule.imeMode,
23
- prompt: rule.prompt,
24
- promptTitle: rule.promptTitle,
25
- showDropDown: rule.showDropDown,
26
- showErrorMessage: rule.showErrorMessage,
27
- showInputMessage: rule.showInputMessage,
28
- renderMode: rule.renderMode,
29
- bizInfo: rule.bizInfo
17
+ error: t.error,
18
+ errorStyle: t.errorStyle,
19
+ errorTitle: t.errorTitle,
20
+ imeMode: t.imeMode,
21
+ prompt: t.prompt,
22
+ promptTitle: t.promptTitle,
23
+ showDropDown: t.showDropDown,
24
+ showErrorMessage: t.showErrorMessage,
25
+ showInputMessage: t.showInputMessage,
26
+ renderMode: t.renderMode,
27
+ bizInfo: t.bizInfo
30
28
  };
31
29
  }
32
- __name(getRuleOptions, "getRuleOptions");
33
- var UpdateRuleType = /* @__PURE__ */ ((UpdateRuleType2) => (UpdateRuleType2[UpdateRuleType2.SETTING = 0] = "SETTING", UpdateRuleType2[UpdateRuleType2.RANGE = 1] = "RANGE", UpdateRuleType2[UpdateRuleType2.OPTIONS = 2] = "OPTIONS", UpdateRuleType2))(UpdateRuleType || {}), __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
34
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
35
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
36
- return kind && result && __defProp$3(target, key, result), result;
37
- }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a;
38
- let DataValidationModel = (_a = class extends Disposable {
39
- constructor(_logService) {
30
+ var m = /* @__PURE__ */ ((t) => (t[t.SETTING = 0] = "SETTING", t[t.RANGE = 1] = "RANGE", t[t.OPTIONS = 2] = "OPTIONS", t[t.ALL = 3] = "ALL", t))(m || {}), re = Object.defineProperty, oe = Object.getOwnPropertyDescriptor, ne = (t, e, a, r) => {
31
+ for (var o = r > 1 ? void 0 : r ? oe(e, a) : e, n = t.length - 1, i; n >= 0; n--)
32
+ (i = t[n]) && (o = (r ? i(e, a, o) : i(o)) || o);
33
+ return r && o && re(e, a, o), o;
34
+ }, ie = (t, e) => (a, r) => e(a, r, t);
35
+ let h = class extends P {
36
+ constructor(e) {
40
37
  super();
41
- __publicField(this, "_model", /* @__PURE__ */ new Map());
42
- __publicField(this, "_ruleChange$", new Subject());
43
- __publicField(this, "ruleChange$", this._ruleChange$.asObservable());
44
- __publicField(this, "ruleChangeDebounce$", this.ruleChange$.pipe(debounceTime(20)));
45
- this._logService = _logService, this.disposeWithMe({
46
- dispose: /* @__PURE__ */ __name(() => {
38
+ c(this, "_model", /* @__PURE__ */ new Map());
39
+ c(this, "_ruleChange$", new ee());
40
+ c(this, "ruleChange$", this._ruleChange$.asObservable());
41
+ c(this, "ruleChangeDebounce$", this.ruleChange$.pipe(te(20)));
42
+ this._logService = e, this.disposeWithMe({
43
+ dispose: () => {
47
44
  this._ruleChange$.complete();
48
- }, "dispose")
45
+ }
49
46
  });
50
47
  }
51
- _ensureMap(unitId, subUnitId) {
52
- this._model.has(unitId) || this._model.set(unitId, /* @__PURE__ */ new Map());
53
- const unitMap = this._model.get(unitId);
54
- if (unitMap.has(subUnitId))
55
- return unitMap.get(subUnitId);
56
- const map = { map: /* @__PURE__ */ new Map(), list: [] };
57
- return unitMap.set(subUnitId, map), map;
58
- }
59
- _addSubUnitRule(subUnit, rule, index) {
60
- const { map: dataValidationMap, list: dataValidations } = subUnit, rules = (Array.isArray(rule) ? rule : [rule]).filter((item) => !dataValidationMap.has(item.uid));
61
- typeof index == "number" && index < dataValidations.length ? dataValidations.splice(index, 0, ...rules) : dataValidations.push(...rules), rules.forEach((item) => {
62
- dataValidationMap.set(item.uid, item);
48
+ _ensureMap(e, a) {
49
+ this._model.has(e) || this._model.set(e, /* @__PURE__ */ new Map());
50
+ const r = this._model.get(e);
51
+ if (r.has(a))
52
+ return r.get(a);
53
+ const o = { map: /* @__PURE__ */ new Map(), list: [] };
54
+ return r.set(a, o), o;
55
+ }
56
+ _addSubUnitRule(e, a, r) {
57
+ const { map: o, list: n } = e, l = (Array.isArray(a) ? a : [a]).filter((d) => !o.has(d.uid));
58
+ typeof r == "number" && r < n.length ? n.splice(r, 0, ...l) : n.push(...l), l.forEach((d) => {
59
+ o.set(d.uid, d);
63
60
  });
64
61
  }
65
- _removeSubUnitRule(subUnit, ruleId) {
66
- const { map: dataValidationMap, list: dataValidations } = subUnit, index = dataValidations.findIndex((item) => item.uid === ruleId);
67
- index > -1 && (dataValidations.splice(index, 1), dataValidationMap.delete(ruleId));
68
- }
69
- _updateSubUnitRule(subUnit, ruleId, payload) {
70
- const { map: dataValidationMap, list: dataValidations } = subUnit, oldRule = dataValidationMap.get(ruleId), index = dataValidations.findIndex((rule2) => ruleId === rule2.uid);
71
- if (!oldRule)
72
- throw new Error(`Data validation rule is not found, ruleId: ${ruleId}.`);
73
- const rule = { ...oldRule };
74
- switch (payload.type) {
75
- case UpdateRuleType.RANGE: {
76
- rule.ranges = payload.payload;
62
+ _removeSubUnitRule(e, a) {
63
+ const { map: r, list: o } = e, n = o.findIndex((i) => i.uid === a);
64
+ n > -1 && (o.splice(n, 1), r.delete(a));
65
+ }
66
+ _updateSubUnitRule(e, a, r) {
67
+ const { map: o, list: n } = e, i = o.get(a), l = n.findIndex((u) => a === u.uid);
68
+ if (!i)
69
+ throw new Error(`Data validation rule is not found, ruleId: ${a}.`);
70
+ const d = { ...i };
71
+ switch (r.type) {
72
+ case m.RANGE: {
73
+ d.ranges = r.payload;
74
+ break;
75
+ }
76
+ case m.SETTING: {
77
+ Object.assign(d, G(r.payload));
77
78
  break;
78
79
  }
79
- case UpdateRuleType.SETTING: {
80
- Object.assign(rule, getRuleSetting(payload.payload));
80
+ case m.OPTIONS: {
81
+ Object.assign(d, q(r.payload));
81
82
  break;
82
83
  }
83
- case UpdateRuleType.OPTIONS: {
84
- Object.assign(rule, getRuleOptions(payload.payload));
84
+ case m.ALL: {
85
+ Object.assign(d, r.payload);
85
86
  break;
86
87
  }
87
88
  }
88
- return dataValidations[index] = rule, dataValidationMap.set(ruleId, rule), rule;
89
+ return n[l] = d, o.set(a, d), d;
89
90
  }
90
- _addRuleSideEffect(unitId, subUnitId, rule, source) {
91
- if (!this._ensureMap(unitId, subUnitId).map.get(rule.uid))
91
+ _addRuleSideEffect(e, a, r, o) {
92
+ if (!this._ensureMap(e, a).map.get(r.uid))
92
93
  return {
93
- rule,
94
+ rule: r,
94
95
  type: "add",
95
- unitId,
96
- subUnitId,
97
- source
96
+ unitId: e,
97
+ subUnitId: a,
98
+ source: o
98
99
  };
99
100
  }
100
- addRule(unitId, subUnitId, rule, source, index) {
101
+ addRule(e, a, r, o, n) {
101
102
  try {
102
- const subUnitMap = this._ensureMap(unitId, subUnitId), effects = (Array.isArray(rule) ? rule : [rule]).map((item) => this._addRuleSideEffect(unitId, subUnitId, item, source));
103
- this._addSubUnitRule(subUnitMap, rule, index), effects.forEach((effect) => {
104
- effect && this._ruleChange$.next(effect);
103
+ const i = this._ensureMap(e, a), d = (Array.isArray(r) ? r : [r]).map((u) => this._addRuleSideEffect(e, a, u, o));
104
+ this._addSubUnitRule(i, r, n), d.forEach((u) => {
105
+ u && this._ruleChange$.next(u);
105
106
  });
106
- } catch (error) {
107
- this._logService.error(error);
107
+ } catch (i) {
108
+ this._logService.error(i);
108
109
  }
109
110
  }
110
- updateRule(unitId, subUnitId, ruleId, payload, source) {
111
+ updateRule(e, a, r, o, n) {
111
112
  try {
112
- const subUnitMap = this._ensureMap(unitId, subUnitId), oldRule = Tools.deepClone(subUnitMap.map.get(ruleId));
113
- if (!oldRule)
114
- throw new Error(`Data validation rule is not found, ruleId: ${ruleId}.`);
115
- const rule = this._updateSubUnitRule(subUnitMap, ruleId, payload);
113
+ const i = this._ensureMap(e, a), l = B.deepClone(i.map.get(r));
114
+ if (!l)
115
+ throw new Error(`Data validation rule is not found, ruleId: ${r}.`);
116
+ const d = this._updateSubUnitRule(i, r, o);
116
117
  this._ruleChange$.next({
117
- rule,
118
+ rule: d,
118
119
  type: "update",
119
- unitId,
120
- subUnitId,
121
- source,
122
- updatePayload: payload,
123
- oldRule
120
+ unitId: e,
121
+ subUnitId: a,
122
+ source: n,
123
+ updatePayload: o,
124
+ oldRule: l
124
125
  });
125
- } catch (error) {
126
- this._logService.error(error);
126
+ } catch (i) {
127
+ this._logService.error(i);
127
128
  }
128
129
  }
129
- removeRule(unitId, subUnitId, ruleId, source) {
130
+ removeRule(e, a, r, o) {
130
131
  try {
131
- const map = this._ensureMap(unitId, subUnitId), oldRule = map.map.get(ruleId);
132
- oldRule && (this._removeSubUnitRule(map, ruleId), this._ruleChange$.next({
133
- rule: oldRule,
132
+ const n = this._ensureMap(e, a), i = n.map.get(r);
133
+ i && (this._removeSubUnitRule(n, r), this._ruleChange$.next({
134
+ rule: i,
134
135
  type: "remove",
135
- unitId,
136
- subUnitId,
137
- source
136
+ unitId: e,
137
+ subUnitId: a,
138
+ source: o
138
139
  }));
139
- } catch (error) {
140
- this._logService.error(error);
140
+ } catch (n) {
141
+ this._logService.error(n);
141
142
  }
142
143
  }
143
- getRuleById(unitId, subUnitId, ruleId) {
144
- return this._ensureMap(unitId, subUnitId).map.get(ruleId);
144
+ getRuleById(e, a, r) {
145
+ return this._ensureMap(e, a).map.get(r);
145
146
  }
146
- getRuleIndex(unitId, subUnitId, ruleId) {
147
- return this._ensureMap(unitId, subUnitId).list.findIndex((rule) => rule.uid === ruleId);
147
+ getRuleIndex(e, a, r) {
148
+ return this._ensureMap(e, a).list.findIndex((n) => n.uid === r);
148
149
  }
149
- getRules(unitId, subUnitId) {
150
- return [...this._ensureMap(unitId, subUnitId).list];
150
+ getRules(e, a) {
151
+ return [...this._ensureMap(e, a).list];
151
152
  }
152
- getUnitRules(unitId) {
153
- const unitMap = this._model.get(unitId);
154
- if (!unitMap)
153
+ getUnitRules(e) {
154
+ const a = this._model.get(e);
155
+ if (!a)
155
156
  return [];
156
- const res = [];
157
- return unitMap.forEach((manager, subUnitId) => {
158
- res.push([subUnitId, manager.list]);
159
- }), res;
157
+ const r = [];
158
+ return a.forEach((o, n) => {
159
+ r.push([n, o.list]);
160
+ }), r;
160
161
  }
161
- deleteUnitRules(unitId) {
162
- this._model.delete(unitId);
162
+ deleteUnitRules(e) {
163
+ this._model.delete(e);
163
164
  }
164
- getSubUnitIds(unitId) {
165
- var _a5, _b;
166
- return Array.from((_b = (_a5 = this._model.get(unitId)) == null ? void 0 : _a5.keys()) != null ? _b : []);
165
+ getSubUnitIds(e) {
166
+ var a, r;
167
+ return Array.from((r = (a = this._model.get(e)) == null ? void 0 : a.keys()) != null ? r : []);
167
168
  }
168
169
  getAll() {
169
- return Array.from(this._model.keys()).map((unitId) => [unitId, this.getUnitRules(unitId)]);
170
- }
171
- }, __name(_a, "DataValidationModel"), _a);
172
- DataValidationModel = __decorateClass$3([
173
- __decorateParam$3(0, ILogService)
174
- ], DataValidationModel);
175
- var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
176
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
177
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
178
- return kind && result && __defProp$2(target, key, result), result;
179
- }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2");
180
- const DATA_VALIDATION_PLUGIN_NAME = "SHEET_DATA_VALIDATION_PLUGIN";
181
- var _a2;
182
- let DataValidationResourceController = (_a2 = class extends Disposable {
183
- constructor(_resourceManagerService, _univerInstanceService, _dataValidationModel) {
184
- super(), this._resourceManagerService = _resourceManagerService, this._univerInstanceService = _univerInstanceService, this._dataValidationModel = _dataValidationModel, this._initSnapshot();
170
+ return Array.from(this._model.keys()).map((e) => [e, this.getUnitRules(e)]);
171
+ }
172
+ };
173
+ h = ne([
174
+ ie(0, T)
175
+ ], h);
176
+ var se = Object.defineProperty, de = Object.getOwnPropertyDescriptor, le = (t, e, a, r) => {
177
+ for (var o = r > 1 ? void 0 : r ? de(e, a) : e, n = t.length - 1, i; n >= 0; n--)
178
+ (i = t[n]) && (o = (r ? i(e, a, o) : i(o)) || o);
179
+ return r && o && se(e, a, o), o;
180
+ }, y = (t, e) => (a, r) => e(a, r, t);
181
+ const ue = "SHEET_DATA_VALIDATION_PLUGIN";
182
+ let I = class extends P {
183
+ constructor(t, e, a) {
184
+ super(), this._resourceManagerService = t, this._univerInstanceService = e, this._dataValidationModel = a, this._initSnapshot();
185
185
  }
186
186
  _initSnapshot() {
187
- const toJson = /* @__PURE__ */ __name((unitID) => {
188
- const map = this._dataValidationModel.getUnitRules(unitID), resultMap = {};
189
- return map ? (map.forEach(([key, v]) => {
190
- resultMap[key] = v;
191
- }), JSON.stringify(resultMap)) : "";
192
- }, "toJson"), parseJson = /* @__PURE__ */ __name((json) => {
193
- if (!json)
187
+ const t = (a) => {
188
+ const r = this._dataValidationModel.getUnitRules(a), o = {};
189
+ return r ? (r.forEach(([n, i]) => {
190
+ o[n] = i;
191
+ }), JSON.stringify(o)) : "";
192
+ }, e = (a) => {
193
+ if (!a)
194
194
  return {};
195
195
  try {
196
- return JSON.parse(json);
196
+ return JSON.parse(a);
197
197
  } catch {
198
198
  return {};
199
199
  }
200
- }, "parseJson");
200
+ };
201
201
  this.disposeWithMe(
202
202
  this._resourceManagerService.registerPluginResource({
203
- pluginName: DATA_VALIDATION_PLUGIN_NAME,
204
- businesses: [UniverInstanceType.UNIVER_SHEET],
205
- toJson: /* @__PURE__ */ __name((unitID) => toJson(unitID), "toJson"),
206
- parseJson: /* @__PURE__ */ __name((json) => parseJson(json), "parseJson"),
207
- onUnLoad: /* @__PURE__ */ __name((unitID) => {
208
- this._dataValidationModel.deleteUnitRules(unitID);
209
- }, "onUnLoad"),
210
- onLoad: /* @__PURE__ */ __name((unitID, value) => {
211
- Object.keys(value).forEach((subunitId) => {
212
- value[subunitId].forEach((rule) => {
213
- this._dataValidationModel.addRule(unitID, subunitId, rule, "patched");
203
+ pluginName: ue,
204
+ businesses: [x.UNIVER_SHEET],
205
+ toJson: (a) => t(a),
206
+ parseJson: (a) => e(a),
207
+ onUnLoad: (a) => {
208
+ this._dataValidationModel.deleteUnitRules(a);
209
+ },
210
+ onLoad: (a, r) => {
211
+ Object.keys(r).forEach((o) => {
212
+ r[o].forEach((i) => {
213
+ this._dataValidationModel.addRule(a, o, i, "patched");
214
214
  });
215
215
  });
216
- }, "onLoad")
216
+ }
217
217
  })
218
218
  );
219
219
  }
220
- }, __name(_a2, "DataValidationResourceController"), _a2);
221
- DataValidationResourceController = __decorateClass$2([
222
- __decorateParam$2(0, IResourceManagerService),
223
- __decorateParam$2(1, IUniverInstanceService),
224
- __decorateParam$2(2, Inject(DataValidationModel))
225
- ], DataValidationResourceController);
226
- var DataValidatorRegistryScope = /* @__PURE__ */ ((DataValidatorRegistryScope2) => (DataValidatorRegistryScope2.SHEET = "sheet", DataValidatorRegistryScope2))(DataValidatorRegistryScope || {});
227
- const _DataValidatorRegistryService = class _DataValidatorRegistryService {
220
+ };
221
+ I = le([
222
+ y(0, z),
223
+ y(1, K),
224
+ y(2, O(h))
225
+ ], I);
226
+ var ce = /* @__PURE__ */ ((t) => (t.SHEET = "sheet", t))(ce || {});
227
+ class H {
228
228
  constructor() {
229
- __publicField(this, "_validatorByScopes", /* @__PURE__ */ new Map());
230
- __publicField(this, "_validatorMap", /* @__PURE__ */ new Map());
231
- __publicField(this, "_validatorsChange$", new BehaviorSubject(void 0));
232
- __publicField(this, "validatorsChange$", this._validatorsChange$.asObservable());
233
- }
234
- _addValidatorToScope(validator, scope) {
235
- this._validatorByScopes.has(scope) || this._validatorByScopes.set(scope, []);
236
- const validators = this._validatorByScopes.get(scope);
237
- if (validators.findIndex((m) => m.id === validator.id) > -1)
238
- throw new Error(`Validator item with the same id ${validator.id} has already been added!`);
239
- validators.push(validator);
240
- }
241
- _removeValidatorFromScope(validator, scope) {
242
- const validators = this._validatorByScopes.get(scope);
243
- if (!validators)
229
+ c(this, "_validatorByScopes", /* @__PURE__ */ new Map());
230
+ c(this, "_validatorMap", /* @__PURE__ */ new Map());
231
+ c(this, "_validatorsChange$", new ae(void 0));
232
+ c(this, "validatorsChange$", this._validatorsChange$.asObservable());
233
+ }
234
+ _addValidatorToScope(e, a) {
235
+ this._validatorByScopes.has(a) || this._validatorByScopes.set(a, []);
236
+ const r = this._validatorByScopes.get(a);
237
+ if (r.findIndex((o) => o.id === e.id) > -1)
238
+ throw new Error(`Validator item with the same id ${e.id} has already been added!`);
239
+ r.push(e);
240
+ }
241
+ _removeValidatorFromScope(e, a) {
242
+ const r = this._validatorByScopes.get(a);
243
+ if (!r)
244
244
  return;
245
- const index = validators.findIndex((v) => v.id === validator.id);
246
- index > -1 && validators.splice(index, 1);
247
- }
248
- register(validator) {
249
- return this._validatorMap.set(validator.id, validator), Array.isArray(validator.scopes) ? validator.scopes.forEach((scope) => {
250
- this._addValidatorToScope(validator, scope);
251
- }) : this._addValidatorToScope(validator, validator.scopes), this._validatorsChange$.next(), toDisposable(() => {
252
- this._validatorMap.delete(validator.id), Array.isArray(validator.scopes) ? validator.scopes.forEach((scope) => {
253
- this._removeValidatorFromScope(validator, scope);
254
- }) : this._removeValidatorFromScope(validator, validator.scopes), this._validatorsChange$.next();
245
+ const o = r.findIndex((n) => n.id === e.id);
246
+ o > -1 && r.splice(o, 1);
247
+ }
248
+ register(e) {
249
+ return this._validatorMap.set(e.id, e), Array.isArray(e.scopes) ? e.scopes.forEach((a) => {
250
+ this._addValidatorToScope(e, a);
251
+ }) : this._addValidatorToScope(e, e.scopes), this._validatorsChange$.next(), Y(() => {
252
+ this._validatorMap.delete(e.id), Array.isArray(e.scopes) ? e.scopes.forEach((a) => {
253
+ this._removeValidatorFromScope(e, a);
254
+ }) : this._removeValidatorFromScope(e, e.scopes), this._validatorsChange$.next();
255
255
  });
256
256
  }
257
- getValidatorItem(id) {
258
- return this._validatorMap.get(id);
257
+ getValidatorItem(e) {
258
+ return this._validatorMap.get(e);
259
259
  }
260
- getValidatorsByScope(scope) {
261
- return this._validatorByScopes.get(scope);
260
+ getValidatorsByScope(e) {
261
+ return this._validatorByScopes.get(e);
262
262
  }
263
- };
264
- __name(_DataValidatorRegistryService, "DataValidatorRegistryService");
265
- let DataValidatorRegistryService = _DataValidatorRegistryService;
266
- const AddDataValidationMutation = {
267
- type: CommandType.MUTATION,
263
+ }
264
+ const A = {
265
+ type: E.MUTATION,
268
266
  id: "data-validation.mutation.addRule",
269
- handler(accessor, params) {
270
- if (!params)
267
+ handler(t, e) {
268
+ if (!e)
271
269
  return !1;
272
- const { unitId, subUnitId, rule, index, source = "command" } = params;
273
- return accessor.get(DataValidationModel).addRule(unitId, subUnitId, rule, source, index), !0;
270
+ const { unitId: a, subUnitId: r, rule: o, index: n, source: i = "command" } = e;
271
+ return t.get(h).addRule(a, r, o, i, n), !0;
274
272
  }
275
- }, RemoveDataValidationMutation = {
276
- type: CommandType.MUTATION,
273
+ }, v = {
274
+ type: E.MUTATION,
277
275
  id: "data-validation.mutation.removeRule",
278
- handler(accessor, params) {
279
- if (!params)
276
+ handler(t, e) {
277
+ if (!e)
280
278
  return !1;
281
- const { unitId, subUnitId, ruleId, source = "command" } = params, dataValidationModel = accessor.get(DataValidationModel);
282
- return Array.isArray(ruleId) ? ruleId.forEach((item) => {
283
- dataValidationModel.removeRule(unitId, subUnitId, item, source);
284
- }) : dataValidationModel.removeRule(unitId, subUnitId, ruleId, source), !0;
279
+ const { unitId: a, subUnitId: r, ruleId: o, source: n = "command" } = e, i = t.get(h);
280
+ return Array.isArray(o) ? o.forEach((l) => {
281
+ i.removeRule(a, r, l, n);
282
+ }) : i.removeRule(a, r, o, n), !0;
285
283
  }
286
- }, UpdateDataValidationMutation = {
287
- type: CommandType.MUTATION,
284
+ }, f = {
285
+ type: E.MUTATION,
288
286
  id: "data-validation.mutation.updateRule",
289
- handler(accessor, params) {
290
- if (!params)
287
+ handler(t, e) {
288
+ if (!e)
291
289
  return !1;
292
- const { unitId, subUnitId, ruleId, payload, source = "command" } = params;
293
- return accessor.get(DataValidationModel).updateRule(unitId, subUnitId, ruleId, payload, source), !0;
290
+ const { unitId: a, subUnitId: r, ruleId: o, payload: n, source: i = "command" } = e;
291
+ return t.get(h).updateRule(a, r, o, n, i), !0;
294
292
  }
295
- }, AddDataValidationCommand = {
296
- type: CommandType.COMMAND,
293
+ }, pe = {
294
+ type: E.COMMAND,
297
295
  id: "data-validation.command.addRule",
298
- async handler(accessor, params) {
299
- if (accessor.get(ILogService).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !params)
296
+ async handler(t, e) {
297
+ if (t.get(T).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
300
298
  return !1;
301
- const { rule, unitId, subUnitId } = params, commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), mutationParams = {
302
- ...params,
299
+ const { rule: r, unitId: o, subUnitId: n } = e, i = t.get(S), l = t.get(M), d = {
300
+ ...e,
303
301
  rule: {
304
- ...params.rule,
305
- ranges: [params.rule.range]
302
+ ...e.rule,
303
+ ranges: [e.rule.range]
306
304
  }
307
- }, redoMutations = [{
308
- id: AddDataValidationMutation.id,
309
- params: mutationParams
310
- }], undoMutations = [{
311
- id: RemoveDataValidationMutation.id,
305
+ }, u = [{
306
+ id: A.id,
307
+ params: d
308
+ }], p = [{
309
+ id: v.id,
312
310
  params: {
313
- unitId,
314
- subUnitId,
315
- ruleId: rule.uid
311
+ unitId: o,
312
+ subUnitId: n,
313
+ ruleId: r.uid
316
314
  }
317
315
  }];
318
- return undoRedoService.pushUndoRedo({
319
- unitID: unitId,
320
- redoMutations,
321
- undoMutations
322
- }), await commandService.executeCommand(AddDataValidationMutation.id, mutationParams), !0;
323
- }
324
- }, RemoveDataValidationCommand = {
325
- type: CommandType.COMMAND,
316
+ return l.pushUndoRedo({
317
+ unitID: o,
318
+ redoMutations: u,
319
+ undoMutations: p
320
+ }), await i.executeCommand(A.id, d), !0;
321
+ }
322
+ }, he = {
323
+ type: E.COMMAND,
326
324
  id: "data-validation.command.removeRule",
327
- handler(accessor, params) {
328
- if (accessor.get(ILogService).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !params)
325
+ handler(t, e) {
326
+ if (t.get(T).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
329
327
  return !1;
330
- const { unitId, subUnitId, ruleId } = params, commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), dataValidationModel = accessor.get(DataValidationModel), redoMutations = [{
331
- id: RemoveDataValidationMutation.id,
332
- params
333
- }], undoMutations = [{
334
- id: AddDataValidationMutation.id,
328
+ const { unitId: r, subUnitId: o, ruleId: n } = e, i = t.get(S), l = t.get(M), d = t.get(h), u = [{
329
+ id: v.id,
330
+ params: e
331
+ }], p = [{
332
+ id: A.id,
335
333
  params: {
336
- unitId,
337
- subUnitId,
334
+ unitId: r,
335
+ subUnitId: o,
338
336
  rule: {
339
- ...dataValidationModel.getRuleById(unitId, subUnitId, ruleId)
337
+ ...d.getRuleById(r, o, n)
340
338
  },
341
- index: dataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
339
+ index: d.getRuleIndex(r, o, n)
342
340
  }
343
341
  }];
344
- return undoRedoService.pushUndoRedo({
345
- undoMutations,
346
- redoMutations,
347
- unitID: params.unitId
348
- }), commandService.executeCommand(RemoveDataValidationMutation.id, params), !0;
349
- }
350
- }, UpdateDataValidationOptionsCommand = {
351
- type: CommandType.COMMAND,
342
+ return l.pushUndoRedo({
343
+ undoMutations: p,
344
+ redoMutations: u,
345
+ unitID: e.unitId
346
+ }), i.executeCommand(v.id, e), !0;
347
+ }
348
+ }, me = {
349
+ type: E.COMMAND,
352
350
  id: "data-validation.command.updateDataValidationSetting",
353
- handler(accessor, params) {
354
- if (accessor.get(ILogService).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"), !params)
351
+ handler(t, e) {
352
+ if (t.get(T).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
355
353
  return !1;
356
- const commandService = accessor.get(ICommandService), redoUndoService = accessor.get(IUndoRedoService), dataValidationModel = accessor.get(DataValidationModel), { unitId, subUnitId, ruleId, options } = params, rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
357
- if (!rule)
354
+ const r = t.get(S), o = t.get(M), n = t.get(h), { unitId: i, subUnitId: l, ruleId: d, options: u } = e, p = n.getRuleById(i, l, d);
355
+ if (!p)
358
356
  return !1;
359
- const mutationParams = {
360
- unitId,
361
- subUnitId,
362
- ruleId,
357
+ const _ = {
358
+ unitId: i,
359
+ subUnitId: l,
360
+ ruleId: d,
363
361
  payload: {
364
- type: UpdateRuleType.OPTIONS,
365
- payload: options
362
+ type: m.OPTIONS,
363
+ payload: u
366
364
  }
367
- }, redoMutations = [{
368
- id: UpdateDataValidationMutation.id,
369
- params: mutationParams
370
- }], undoMutationParams = {
371
- unitId,
372
- subUnitId,
373
- ruleId,
365
+ }, g = [{
366
+ id: f.id,
367
+ params: _
368
+ }], R = {
369
+ unitId: i,
370
+ subUnitId: l,
371
+ ruleId: d,
374
372
  payload: {
375
- type: UpdateRuleType.OPTIONS,
376
- payload: getRuleOptions(rule)
373
+ type: m.OPTIONS,
374
+ payload: q(p)
377
375
  }
378
- }, undoMutations = [{
379
- id: UpdateDataValidationMutation.id,
380
- params: undoMutationParams
376
+ }, N = [{
377
+ id: f.id,
378
+ params: R
381
379
  }];
382
- return redoUndoService.pushUndoRedo({
383
- unitID: unitId,
384
- redoMutations,
385
- undoMutations
386
- }), commandService.executeCommand(UpdateDataValidationMutation.id, mutationParams), !0;
387
- }
388
- }, UpdateDataValidationSettingCommand = {
389
- type: CommandType.COMMAND,
380
+ return o.pushUndoRedo({
381
+ unitID: i,
382
+ redoMutations: g,
383
+ undoMutations: N
384
+ }), r.executeCommand(f.id, _), !0;
385
+ }
386
+ }, _e = {
387
+ type: E.COMMAND,
390
388
  id: "data-validation.command.updateDataValidationOptions",
391
- handler(accessor, params) {
392
- if (accessor.get(ILogService).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"), !params)
389
+ handler(t, e) {
390
+ if (t.get(T).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
393
391
  return !1;
394
- const commandService = accessor.get(ICommandService), redoUndoService = accessor.get(IUndoRedoService), dataValidationModel = accessor.get(DataValidationModel), dataValidatorRegistryService = accessor.get(DataValidatorRegistryService), { unitId, subUnitId, ruleId, setting } = params, validator = dataValidatorRegistryService.getValidatorItem(setting.type);
395
- if (!validator)
392
+ const r = t.get(S), o = t.get(M), n = t.get(h), i = t.get(H), { unitId: l, subUnitId: d, ruleId: u, setting: p } = e, _ = i.getValidatorItem(p.type);
393
+ if (!_)
396
394
  return !1;
397
- const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
398
- if (!rule)
395
+ const g = n.getRuleById(l, d, u);
396
+ if (!g)
399
397
  return !1;
400
- const newRule = { ...rule, ...setting };
401
- if (!validator.validatorFormula(newRule, unitId, subUnitId).success)
398
+ const R = { ...g, ...p };
399
+ if (!_.validatorFormula(R, l, d).success)
402
400
  return !1;
403
- const mutationParams = {
404
- unitId,
405
- subUnitId,
406
- ruleId,
401
+ const N = {
402
+ unitId: l,
403
+ subUnitId: d,
404
+ ruleId: u,
407
405
  payload: {
408
- type: UpdateRuleType.SETTING,
406
+ type: m.SETTING,
409
407
  payload: {
410
- ...setting,
411
- ...validator.normalizeFormula(newRule, unitId, subUnitId)
408
+ ...p,
409
+ ..._.normalizeFormula(R, l, d)
412
410
  }
413
411
  }
414
- }, redoMutations = [{
415
- id: UpdateDataValidationMutation.id,
416
- params: mutationParams
417
- }], undoMutationParams = {
418
- unitId,
419
- subUnitId,
420
- ruleId,
412
+ }, j = [{
413
+ id: f.id,
414
+ params: N
415
+ }], Q = {
416
+ unitId: l,
417
+ subUnitId: d,
418
+ ruleId: u,
421
419
  payload: {
422
- type: UpdateRuleType.SETTING,
423
- payload: getRuleSetting(rule)
420
+ type: m.SETTING,
421
+ payload: G(g)
424
422
  }
425
- }, undoMutations = [{
426
- id: UpdateDataValidationMutation.id,
427
- params: undoMutationParams
423
+ }, W = [{
424
+ id: f.id,
425
+ params: Q
428
426
  }];
429
- return redoUndoService.pushUndoRedo({
430
- unitID: unitId,
431
- redoMutations,
432
- undoMutations
433
- }), commandService.executeCommand(UpdateDataValidationMutation.id, mutationParams), !0;
434
- }
435
- }, RemoveAllDataValidationCommand = {
436
- type: CommandType.COMMAND,
427
+ return o.pushUndoRedo({
428
+ unitID: l,
429
+ redoMutations: j,
430
+ undoMutations: W
431
+ }), r.executeCommand(f.id, N), !0;
432
+ }
433
+ }, Ee = {
434
+ type: E.COMMAND,
437
435
  id: "data-validation.command.removeAll",
438
- handler(accessor, params) {
439
- if (accessor.get(ILogService).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !params)
436
+ handler(t, e) {
437
+ if (t.get(T).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
440
438
  return !1;
441
- const { unitId, subUnitId } = params, commandService = accessor.get(ICommandService), dataValidationModel = accessor.get(DataValidationModel), undoRedoService = accessor.get(IUndoRedoService), currentRules = [...dataValidationModel.getRules(unitId, subUnitId)], redoParams = {
442
- unitId,
443
- subUnitId,
444
- ruleId: currentRules.map((rule) => rule.uid)
445
- }, redoMutations = [{
446
- id: RemoveDataValidationMutation.id,
447
- params: redoParams
448
- }], undoMutations = [{
449
- id: AddDataValidationMutation.id,
439
+ const { unitId: r, subUnitId: o } = e, n = t.get(S), i = t.get(h), l = t.get(M), d = [...i.getRules(r, o)], u = {
440
+ unitId: r,
441
+ subUnitId: o,
442
+ ruleId: d.map((g) => g.uid)
443
+ }, p = [{
444
+ id: v.id,
445
+ params: u
446
+ }], _ = [{
447
+ id: A.id,
450
448
  params: {
451
- unitId,
452
- subUnitId,
453
- rule: currentRules
449
+ unitId: r,
450
+ subUnitId: o,
451
+ rule: d
454
452
  }
455
453
  }];
456
- return undoRedoService.pushUndoRedo({
457
- redoMutations,
458
- undoMutations,
459
- unitID: unitId
460
- }), commandService.executeCommand(RemoveDataValidationMutation.id, redoParams), !0;
461
- }
462
- }, PLUGIN_CONFIG_KEY = "data-validation.config", defaultPluginConfig = {};
463
- var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
464
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
465
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
466
- return kind && result && __defProp$1(target, key, result), result;
467
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1");
468
- const PLUGIN_NAME = "UNIVER_DATA_VALIDATION_PLUGIN";
469
- var _a3;
470
- let UniverDataValidationPlugin = (_a3 = class extends Plugin {
471
- constructor(_config = defaultPluginConfig, _injector, _commandService, _configService) {
472
- super(), this._config = _config, this._injector = _injector, this._commandService = _commandService, this._configService = _configService;
473
- const { ...rest } = this._config;
474
- this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
454
+ return l.pushUndoRedo({
455
+ redoMutations: p,
456
+ undoMutations: _,
457
+ unitID: r
458
+ }), n.executeCommand(v.id, u), !0;
459
+ }
460
+ }, ge = "data-validation.config", fe = {};
461
+ var ve = Object.defineProperty, Te = Object.getOwnPropertyDescriptor, Se = (t, e, a, r) => {
462
+ for (var o = r > 1 ? void 0 : r ? Te(e, a) : e, n = t.length - 1, i; n >= 0; n--)
463
+ (i = t[n]) && (o = (r ? i(e, a, o) : i(o)) || o);
464
+ return r && o && ve(e, a, o), o;
465
+ }, L = (t, e) => (a, r) => e(a, r, t);
466
+ const Ae = "UNIVER_DATA_VALIDATION_PLUGIN";
467
+ var V;
468
+ let U = (V = class extends X {
469
+ constructor(t = fe, e, a, r) {
470
+ super(), this._config = t, this._injector = e, this._commandService = a, this._configService = r;
471
+ const { ...o } = this._config;
472
+ this._configService.setConfig(ge, o);
475
473
  }
476
474
  onStarting() {
477
475
  [
478
- [DataValidationModel],
479
- [DataValidatorRegistryService],
480
- [DataValidationResourceController]
481
- ].forEach((d) => this._injector.add(d)), [
476
+ [h],
477
+ [H],
478
+ [I]
479
+ ].forEach((t) => this._injector.add(t)), [
482
480
  // command
483
- AddDataValidationCommand,
484
- RemoveAllDataValidationCommand,
485
- UpdateDataValidationOptionsCommand,
486
- UpdateDataValidationSettingCommand,
487
- RemoveDataValidationCommand,
481
+ pe,
482
+ Ee,
483
+ me,
484
+ _e,
485
+ he,
488
486
  // mutation
489
- AddDataValidationMutation,
490
- UpdateDataValidationMutation,
491
- RemoveDataValidationMutation
492
- ].forEach((command) => {
493
- this._commandService.registerCommand(command);
487
+ A,
488
+ f,
489
+ v
490
+ ].forEach((t) => {
491
+ this._commandService.registerCommand(t);
494
492
  });
495
493
  }
496
494
  onReady() {
497
- this._injector.get(DataValidationResourceController);
498
- }
499
- }, __name(_a3, "UniverDataValidationPlugin"), __publicField(_a3, "pluginName", PLUGIN_NAME), __publicField(_a3, "type", UniverInstanceType.UNIVER_SHEET), _a3);
500
- UniverDataValidationPlugin = __decorateClass$1([
501
- __decorateParam$1(1, Inject(Injector)),
502
- __decorateParam$1(2, ICommandService),
503
- __decorateParam$1(3, IConfigService)
504
- ], UniverDataValidationPlugin);
505
- 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 + "";
506
- const OperatorTitleMap = {
507
- [DataValidationOperator.BETWEEN]: "dataValidation.ruleName.between",
508
- [DataValidationOperator.EQUAL]: "dataValidation.ruleName.equal",
509
- [DataValidationOperator.GREATER_THAN]: "dataValidation.ruleName.greaterThan",
510
- [DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.ruleName.greaterThanOrEqual",
511
- [DataValidationOperator.LESS_THAN]: "dataValidation.ruleName.lessThan",
512
- [DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.ruleName.lessThanOrEqual",
513
- [DataValidationOperator.NOT_BETWEEN]: "dataValidation.ruleName.notBetween",
514
- [DataValidationOperator.NOT_EQUAL]: "dataValidation.ruleName.notEqual"
515
- }, OperatorErrorTitleMap = {
516
- [DataValidationOperator.BETWEEN]: "dataValidation.errorMsg.between",
517
- [DataValidationOperator.EQUAL]: "dataValidation.errorMsg.equal",
518
- [DataValidationOperator.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
519
- [DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual",
520
- [DataValidationOperator.LESS_THAN]: "dataValidation.errorMsg.lessThan",
521
- [DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
522
- [DataValidationOperator.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
523
- [DataValidationOperator.NOT_EQUAL]: "dataValidation.errorMsg.notEqual"
524
- }, TextLengthErrorTitleMap = {
525
- [DataValidationOperator.BETWEEN]: "dataValidation.textLength.errorMsg.between",
526
- [DataValidationOperator.EQUAL]: "dataValidation.textLength.errorMsg.equal",
527
- [DataValidationOperator.GREATER_THAN]: "dataValidation.textLength.errorMsg.greaterThan",
528
- [DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.textLength.errorMsg.greaterThanOrEqual",
529
- [DataValidationOperator.LESS_THAN]: "dataValidation.textLength.errorMsg.lessThan",
530
- [DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.textLength.errorMsg.lessThanOrEqual",
531
- [DataValidationOperator.NOT_BETWEEN]: "dataValidation.textLength.errorMsg.notBetween",
532
- [DataValidationOperator.NOT_EQUAL]: "dataValidation.textLength.errorMsg.notEqual"
533
- }, TWO_FORMULA_OPERATOR_COUNT = [
534
- DataValidationOperator.BETWEEN,
535
- DataValidationOperator.NOT_BETWEEN
495
+ this._injector.get(I);
496
+ }
497
+ }, c(V, "pluginName", Ae), c(V, "type", x.UNIVER_SHEET), V);
498
+ U = Se([
499
+ L(1, O($)),
500
+ L(2, S),
501
+ L(3, Z)
502
+ ], U);
503
+ s.BETWEEN + "", s.EQUAL + "", s.GREATER_THAN + "", s.GREATER_THAN_OR_EQUAL + "", s.LESS_THAN + "", s.LESS_THAN_OR_EQUAL + "", s.NOT_BETWEEN + "", s.NOT_EQUAL + "";
504
+ const Me = {
505
+ [s.BETWEEN]: "dataValidation.ruleName.between",
506
+ [s.EQUAL]: "dataValidation.ruleName.equal",
507
+ [s.GREATER_THAN]: "dataValidation.ruleName.greaterThan",
508
+ [s.GREATER_THAN_OR_EQUAL]: "dataValidation.ruleName.greaterThanOrEqual",
509
+ [s.LESS_THAN]: "dataValidation.ruleName.lessThan",
510
+ [s.LESS_THAN_OR_EQUAL]: "dataValidation.ruleName.lessThanOrEqual",
511
+ [s.NOT_BETWEEN]: "dataValidation.ruleName.notBetween",
512
+ [s.NOT_EQUAL]: "dataValidation.ruleName.notEqual"
513
+ }, Re = {
514
+ [s.BETWEEN]: "dataValidation.errorMsg.between",
515
+ [s.EQUAL]: "dataValidation.errorMsg.equal",
516
+ [s.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
517
+ [s.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual",
518
+ [s.LESS_THAN]: "dataValidation.errorMsg.lessThan",
519
+ [s.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
520
+ [s.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
521
+ [s.NOT_EQUAL]: "dataValidation.errorMsg.notEqual"
522
+ }, De = {
523
+ [s.BETWEEN]: "dataValidation.textLength.errorMsg.between",
524
+ [s.EQUAL]: "dataValidation.textLength.errorMsg.equal",
525
+ [s.GREATER_THAN]: "dataValidation.textLength.errorMsg.greaterThan",
526
+ [s.GREATER_THAN_OR_EQUAL]: "dataValidation.textLength.errorMsg.greaterThanOrEqual",
527
+ [s.LESS_THAN]: "dataValidation.textLength.errorMsg.lessThan",
528
+ [s.LESS_THAN_OR_EQUAL]: "dataValidation.textLength.errorMsg.lessThanOrEqual",
529
+ [s.NOT_BETWEEN]: "dataValidation.textLength.errorMsg.notBetween",
530
+ [s.NOT_EQUAL]: "dataValidation.textLength.errorMsg.notEqual"
531
+ }, we = [
532
+ s.BETWEEN,
533
+ s.NOT_BETWEEN
536
534
  ];
537
- var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
538
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
539
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
540
- return kind && result && __defProp2(target, key, result), result;
541
- }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam");
542
- const FORMULA1 = "{FORMULA1}", FORMULA2 = "{FORMULA2}", operatorNameMap = {
543
- [DataValidationOperator.BETWEEN]: "dataValidation.operators.between",
544
- [DataValidationOperator.EQUAL]: "dataValidation.operators.equal",
545
- [DataValidationOperator.GREATER_THAN]: "dataValidation.operators.greaterThan",
546
- [DataValidationOperator.GREATER_THAN_OR_EQUAL]: "dataValidation.operators.greaterThanOrEqual",
547
- [DataValidationOperator.LESS_THAN]: "dataValidation.operators.lessThan",
548
- [DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.operators.lessThanOrEqual",
549
- [DataValidationOperator.NOT_BETWEEN]: "dataValidation.operators.notBetween",
550
- [DataValidationOperator.NOT_EQUAL]: "dataValidation.operators.notEqual"
535
+ var Ne = Object.defineProperty, Ve = Object.getOwnPropertyDescriptor, Oe = (t, e, a, r) => {
536
+ for (var o = r > 1 ? void 0 : r ? Ve(e, a) : e, n = t.length - 1, i; n >= 0; n--)
537
+ (i = t[n]) && (o = (r ? i(e, a, o) : i(o)) || o);
538
+ return r && o && Ne(e, a, o), o;
539
+ }, D = (t, e) => (a, r) => e(a, r, t);
540
+ const w = "{FORMULA1}", C = "{FORMULA2}", Ie = {
541
+ [s.BETWEEN]: "dataValidation.operators.between",
542
+ [s.EQUAL]: "dataValidation.operators.equal",
543
+ [s.GREATER_THAN]: "dataValidation.operators.greaterThan",
544
+ [s.GREATER_THAN_OR_EQUAL]: "dataValidation.operators.greaterThanOrEqual",
545
+ [s.LESS_THAN]: "dataValidation.operators.lessThan",
546
+ [s.LESS_THAN_OR_EQUAL]: "dataValidation.operators.lessThanOrEqual",
547
+ [s.NOT_BETWEEN]: "dataValidation.operators.notBetween",
548
+ [s.NOT_EQUAL]: "dataValidation.operators.notEqual"
551
549
  };
552
- var _a4;
553
- let BaseDataValidator = (_a4 = class {
550
+ let b = class {
554
551
  // #endregion
555
- constructor(localeService, injector) {
552
+ constructor(t, e) {
556
553
  // #region UI related
557
- __publicField(this, "formulaInput");
558
- __publicField(this, "canvasRender", null);
559
- __publicField(this, "dropdown");
560
- __publicField(this, "optionsInput");
561
- __publicField(this, "skipDefaultFontRender");
562
- this.localeService = localeService, this.injector = injector;
554
+ c(this, "formulaInput");
555
+ c(this, "canvasRender", null);
556
+ c(this, "dropdown");
557
+ c(this, "optionsInput");
558
+ c(this, "skipDefaultFontRender");
559
+ this.localeService = t, this.injector = e;
563
560
  }
564
561
  get operatorNames() {
565
- return this.operators.map((operator) => this.localeService.t(operatorNameMap[operator]));
562
+ return this.operators.map((t) => this.localeService.t(Ie[t]));
566
563
  }
567
564
  get titleStr() {
568
565
  return this.localeService.t(this.title);
569
566
  }
570
- generateRuleName(rule) {
571
- var _a5, _b;
572
- if (!rule.operator)
567
+ generateRuleName(t) {
568
+ var a, r;
569
+ if (!t.operator)
573
570
  return this.titleStr;
574
- const ruleName = this.localeService.t(OperatorTitleMap[rule.operator]).replace(FORMULA1, (_a5 = rule.formula1) != null ? _a5 : "").replace(FORMULA2, (_b = rule.formula2) != null ? _b : "");
575
- return `${this.titleStr} ${ruleName}`;
571
+ const e = this.localeService.t(Me[t.operator]).replace(w, (a = t.formula1) != null ? a : "").replace(C, (r = t.formula2) != null ? r : "");
572
+ return `${this.titleStr} ${e}`;
576
573
  }
577
- generateRuleErrorMessage(rule) {
578
- var _a5, _b;
579
- return rule.operator ? `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, (_a5 = rule.formula1) != null ? _a5 : "").replace(FORMULA2, (_b = rule.formula2) != null ? _b : "")}` : this.titleStr;
574
+ generateRuleErrorMessage(t, e) {
575
+ var r, o;
576
+ return t.operator ? `${this.localeService.t(Re[t.operator]).replace(w, (r = t.formula1) != null ? r : "").replace(C, (o = t.formula2) != null ? o : "")}` : this.titleStr;
580
577
  }
581
- getExtraStyle(rule, value, ctx) {
578
+ getExtraStyle(t, e, a, r, o) {
582
579
  }
583
- getRuleFinalError(rule) {
584
- return rule.showErrorMessage && rule.error ? rule.error : this.generateRuleErrorMessage(rule);
580
+ getRuleFinalError(t, e) {
581
+ return t.showErrorMessage && t.error ? t.error : this.generateRuleErrorMessage(t, e);
585
582
  }
586
- isEmptyCellValue(cellValue) {
587
- return cellValue === "" || cellValue === void 0 || cellValue === null;
583
+ isEmptyCellValue(t) {
584
+ return t === "" || t === void 0 || t === null;
588
585
  }
589
- normalizeFormula(rule, unitId, subUnitId) {
586
+ normalizeFormula(t, e, a) {
590
587
  return {
591
- formula1: rule.formula1,
592
- formula2: rule.formula2
588
+ formula1: t.formula1,
589
+ formula2: t.formula2
593
590
  };
594
591
  }
595
- async isValidType(cellInfo, formula, rule) {
592
+ async isValidType(t, e, a) {
596
593
  return !0;
597
594
  }
598
- transform(cellInfo, formula, rule) {
599
- return cellInfo;
595
+ transform(t, e, a) {
596
+ return t;
600
597
  }
601
- async validatorIsEqual(cellInfo, formula, rule) {
598
+ async validatorIsEqual(t, e, a) {
602
599
  return !0;
603
600
  }
604
- async validatorIsNotEqual(cellInfo, formula, rule) {
601
+ async validatorIsNotEqual(t, e, a) {
605
602
  return !0;
606
603
  }
607
- async validatorIsBetween(cellInfo, formula, rule) {
604
+ async validatorIsBetween(t, e, a) {
608
605
  return !0;
609
606
  }
610
- async validatorIsNotBetween(cellInfo, formula, rule) {
607
+ async validatorIsNotBetween(t, e, a) {
611
608
  return !0;
612
609
  }
613
- async validatorIsGreaterThan(cellInfo, formula, rule) {
610
+ async validatorIsGreaterThan(t, e, a) {
614
611
  return !0;
615
612
  }
616
- async validatorIsGreaterThanOrEqual(cellInfo, formula, rule) {
613
+ async validatorIsGreaterThanOrEqual(t, e, a) {
617
614
  return !0;
618
615
  }
619
- async validatorIsLessThan(cellInfo, formula, rule) {
616
+ async validatorIsLessThan(t, e, a) {
620
617
  return !0;
621
618
  }
622
- async validatorIsLessThanOrEqual(cellInfo, formula, rule) {
619
+ async validatorIsLessThanOrEqual(t, e, a) {
623
620
  return !0;
624
621
  }
625
- async validator(cellInfo, rule) {
626
- const { value: cellValue, unitId, subUnitId } = cellInfo, isEmpty = this.isEmptyCellValue(cellValue), { allowBlank = !0, operator } = rule;
627
- if (isEmpty)
628
- return allowBlank;
629
- const formulaInfo = await this.parseFormula(rule, unitId, subUnitId);
630
- if (!formulaInfo.isFormulaValid || !await this.isValidType(cellInfo, formulaInfo, rule))
622
+ async validator(t, e) {
623
+ const { value: a, unitId: r, subUnitId: o } = t, n = this.isEmptyCellValue(a), { allowBlank: i = !0, operator: l } = e;
624
+ if (n)
625
+ return i;
626
+ const d = await this.parseFormula(e, r, o, t.row, t.column);
627
+ if (!d.isFormulaValid || !await this.isValidType(t, d, e))
631
628
  return !1;
632
- if (!Tools.isDefine(operator))
629
+ if (!B.isDefine(l))
633
630
  return !0;
634
- const transformedCell = this.transform(cellInfo, formulaInfo, rule);
635
- switch (operator) {
636
- case DataValidationOperator.BETWEEN:
637
- return this.validatorIsBetween(transformedCell, formulaInfo, rule);
638
- case DataValidationOperator.EQUAL:
639
- return this.validatorIsEqual(transformedCell, formulaInfo, rule);
640
- case DataValidationOperator.GREATER_THAN:
641
- return this.validatorIsGreaterThan(transformedCell, formulaInfo, rule);
642
- case DataValidationOperator.GREATER_THAN_OR_EQUAL:
643
- return this.validatorIsGreaterThanOrEqual(transformedCell, formulaInfo, rule);
644
- case DataValidationOperator.LESS_THAN:
645
- return this.validatorIsLessThan(transformedCell, formulaInfo, rule);
646
- case DataValidationOperator.LESS_THAN_OR_EQUAL:
647
- return this.validatorIsLessThanOrEqual(transformedCell, formulaInfo, rule);
648
- case DataValidationOperator.NOT_BETWEEN:
649
- return this.validatorIsNotBetween(transformedCell, formulaInfo, rule);
650
- case DataValidationOperator.NOT_EQUAL:
651
- return this.validatorIsNotEqual(transformedCell, formulaInfo, rule);
631
+ const u = this.transform(t, d, e);
632
+ switch (l) {
633
+ case s.BETWEEN:
634
+ return this.validatorIsBetween(u, d, e);
635
+ case s.EQUAL:
636
+ return this.validatorIsEqual(u, d, e);
637
+ case s.GREATER_THAN:
638
+ return this.validatorIsGreaterThan(u, d, e);
639
+ case s.GREATER_THAN_OR_EQUAL:
640
+ return this.validatorIsGreaterThanOrEqual(u, d, e);
641
+ case s.LESS_THAN:
642
+ return this.validatorIsLessThan(u, d, e);
643
+ case s.LESS_THAN_OR_EQUAL:
644
+ return this.validatorIsLessThanOrEqual(u, d, e);
645
+ case s.NOT_BETWEEN:
646
+ return this.validatorIsNotBetween(u, d, e);
647
+ case s.NOT_EQUAL:
648
+ return this.validatorIsNotEqual(u, d, e);
652
649
  default:
653
650
  throw new Error("Unknown operator.");
654
651
  }
655
652
  }
656
- }, __name(_a4, "BaseDataValidator"), _a4);
657
- BaseDataValidator = __decorateClass([
658
- __decorateParam(0, Inject(LocaleService)),
659
- __decorateParam(1, Inject(Injector))
660
- ], BaseDataValidator);
653
+ };
654
+ b = Oe([
655
+ D(0, O(k)),
656
+ D(1, O($))
657
+ ], b);
661
658
  export {
662
- AddDataValidationMutation,
663
- BaseDataValidator,
664
- DataValidationModel,
665
- DataValidationResourceController,
666
- DataValidatorRegistryScope,
667
- DataValidatorRegistryService,
668
- RemoveDataValidationMutation,
669
- TWO_FORMULA_OPERATOR_COUNT,
670
- TextLengthErrorTitleMap,
671
- UniverDataValidationPlugin,
672
- UpdateDataValidationMutation,
673
- UpdateRuleType,
674
- getRuleOptions,
675
- getRuleSetting
659
+ A as AddDataValidationMutation,
660
+ b as BaseDataValidator,
661
+ h as DataValidationModel,
662
+ I as DataValidationResourceController,
663
+ ce as DataValidatorRegistryScope,
664
+ H as DataValidatorRegistryService,
665
+ v as RemoveDataValidationMutation,
666
+ we as TWO_FORMULA_OPERATOR_COUNT,
667
+ De as TextLengthErrorTitleMap,
668
+ U as UniverDataValidationPlugin,
669
+ f as UpdateDataValidationMutation,
670
+ m as UpdateRuleType,
671
+ q as getRuleOptions,
672
+ G as getRuleSetting
676
673
  };