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