@univerjs/data-validation 0.2.12 → 0.2.13
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/cjs/index.js +1 -1
- package/lib/es/index.js +176 -328
- package/lib/types/commands/commands/data-validation.command.d.ts +14 -4
- package/lib/types/commands/mutations/data-validation.mutation.d.ts +9 -4
- package/lib/types/common/util.d.ts +1 -8
- package/lib/types/index.d.ts +10 -13
- package/lib/types/models/data-validation-model.d.ts +16 -16
- package/lib/types/plugin.d.ts +1 -1
- package/lib/types/services/data-validator-registry.service.d.ts +1 -1
- package/lib/types/validators/base-data-validator.d.ts +2 -2
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
- package/lib/types/controllers/dv-sheet.controller.d.ts +0 -10
- package/lib/types/models/data-validation-manager.d.ts +0 -26
package/lib/es/index.js
CHANGED
|
@@ -2,50 +2,8 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { SheetsSelectionsService, RemoveSheetCommand, SheetInterceptorService } from "@univerjs/sheets";
|
|
8
|
-
var DataValidatorRegistryScope = /* @__PURE__ */ ((DataValidatorRegistryScope2) => (DataValidatorRegistryScope2.SHEET = "sheet", DataValidatorRegistryScope2))(DataValidatorRegistryScope || {});
|
|
9
|
-
const _DataValidatorRegistryService = class _DataValidatorRegistryService {
|
|
10
|
-
constructor() {
|
|
11
|
-
__publicField(this, "_validatorByScopes", /* @__PURE__ */ new Map());
|
|
12
|
-
__publicField(this, "_validatorMap", /* @__PURE__ */ new Map());
|
|
13
|
-
__publicField(this, "_validatorsChange$", new BehaviorSubject(void 0));
|
|
14
|
-
__publicField(this, "validatorsChange$", this._validatorsChange$.asObservable());
|
|
15
|
-
}
|
|
16
|
-
_addValidatorToScope(validator, scope) {
|
|
17
|
-
this._validatorByScopes.has(scope) || this._validatorByScopes.set(scope, []);
|
|
18
|
-
const validators = this._validatorByScopes.get(scope);
|
|
19
|
-
if (validators.findIndex((m) => m.id === validator.id) > -1)
|
|
20
|
-
throw new Error(`Validator item with the same id ${validator.id} has already been added!`);
|
|
21
|
-
validators.push(validator);
|
|
22
|
-
}
|
|
23
|
-
_removeValidatorFromScope(validator, scope) {
|
|
24
|
-
const validators = this._validatorByScopes.get(scope);
|
|
25
|
-
if (!validators)
|
|
26
|
-
return;
|
|
27
|
-
const index = validators.findIndex((v) => v.id === validator.id);
|
|
28
|
-
index > -1 && validators.splice(index, 1);
|
|
29
|
-
}
|
|
30
|
-
register(validator) {
|
|
31
|
-
return this._validatorMap.set(validator.id, validator), Array.isArray(validator.scopes) ? validator.scopes.forEach((scope) => {
|
|
32
|
-
this._addValidatorToScope(validator, scope);
|
|
33
|
-
}) : this._addValidatorToScope(validator, validator.scopes), this._validatorsChange$.next(), toDisposable(() => {
|
|
34
|
-
this._validatorMap.delete(validator.id), Array.isArray(validator.scopes) ? validator.scopes.forEach((scope) => {
|
|
35
|
-
this._removeValidatorFromScope(validator, scope);
|
|
36
|
-
}) : this._removeValidatorFromScope(validator, validator.scopes), this._validatorsChange$.next();
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
getValidatorItem(id) {
|
|
40
|
-
return this._validatorMap.get(id);
|
|
41
|
-
}
|
|
42
|
-
getValidatorsByScope(scope) {
|
|
43
|
-
return this._validatorByScopes.get(scope);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
__name(_DataValidatorRegistryService, "DataValidatorRegistryService");
|
|
47
|
-
let DataValidatorRegistryService = _DataValidatorRegistryService;
|
|
48
|
-
var UpdateRuleType = /* @__PURE__ */ ((UpdateRuleType2) => (UpdateRuleType2[UpdateRuleType2.SETTING = 0] = "SETTING", UpdateRuleType2[UpdateRuleType2.RANGE = 1] = "RANGE", UpdateRuleType2[UpdateRuleType2.OPTIONS = 2] = "OPTIONS", UpdateRuleType2))(UpdateRuleType || {});
|
|
5
|
+
import { Disposable, Tools, ILogService, CommandType, UniverInstanceType, OnLifecycle, LifecycleStages, Inject, IResourceManagerService, IUniverInstanceService, toDisposable, ICommandService, IUndoRedoService, Plugin, Injector, IConfigService, DataValidationOperator, LocaleService } from "@univerjs/core";
|
|
6
|
+
import { Subject, debounceTime, BehaviorSubject } from "rxjs";
|
|
49
7
|
function getRuleSetting(rule) {
|
|
50
8
|
return {
|
|
51
9
|
type: rule.type,
|
|
@@ -72,53 +30,44 @@ function getRuleOptions(rule) {
|
|
|
72
30
|
};
|
|
73
31
|
}
|
|
74
32
|
__name(getRuleOptions, "getRuleOptions");
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
ranges: currentRanges != null ? currentRanges : [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }]
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
__name(createDefaultNewRule, "createDefaultNewRule");
|
|
86
|
-
const _DataValidationManager = class _DataValidationManager extends Disposable {
|
|
87
|
-
constructor(unitId, subUnitId) {
|
|
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) {
|
|
88
40
|
super();
|
|
89
|
-
__publicField(this, "
|
|
90
|
-
__publicField(this, "
|
|
91
|
-
__publicField(this, "
|
|
92
|
-
__publicField(this, "
|
|
93
|
-
|
|
94
|
-
__publicField(this, "dataValidations$", this._dataValidations$.asObservable());
|
|
95
|
-
this.unitId = unitId, this.subUnitId = subUnitId, this._notice(), this.disposeWithMe({
|
|
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({
|
|
96
46
|
dispose: /* @__PURE__ */ __name(() => {
|
|
97
|
-
this.
|
|
47
|
+
this._ruleChange$.complete();
|
|
98
48
|
}, "dispose")
|
|
99
49
|
});
|
|
100
50
|
}
|
|
101
|
-
|
|
102
|
-
this.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return this._dataValidations.findIndex((rule) => rule.uid === id);
|
|
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;
|
|
109
58
|
}
|
|
110
|
-
|
|
111
|
-
const rules = (Array.isArray(rule) ? rule : [rule]).filter((item) => !
|
|
112
|
-
typeof index == "number" && index <
|
|
113
|
-
|
|
114
|
-
})
|
|
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);
|
|
63
|
+
});
|
|
115
64
|
}
|
|
116
|
-
|
|
117
|
-
const index =
|
|
118
|
-
index > -1 && (
|
|
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));
|
|
119
68
|
}
|
|
120
|
-
|
|
121
|
-
const oldRule =
|
|
69
|
+
_updateSubUnitRule(subUnit, ruleId, payload) {
|
|
70
|
+
const { map: dataValidationMap, list: dataValidations } = subUnit, oldRule = dataValidationMap.get(ruleId), index = dataValidations.findIndex((rule2) => ruleId === rule2.uid);
|
|
122
71
|
if (!oldRule)
|
|
123
72
|
throw new Error(`Data validation rule is not found, ruleId: ${ruleId}.`);
|
|
124
73
|
const rule = { ...oldRule };
|
|
@@ -136,54 +85,10 @@ const _DataValidationManager = class _DataValidationManager extends Disposable {
|
|
|
136
85
|
break;
|
|
137
86
|
}
|
|
138
87
|
}
|
|
139
|
-
return
|
|
140
|
-
}
|
|
141
|
-
getDataValidations() {
|
|
142
|
-
return this._dataValidations;
|
|
143
|
-
}
|
|
144
|
-
toJSON() {
|
|
145
|
-
return this._dataValidations;
|
|
146
|
-
}
|
|
147
|
-
validator(_value, _rule, _pos, _onComplete) {
|
|
148
|
-
return DataValidationStatus.VALID;
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
__name(_DataValidationManager, "DataValidationManager");
|
|
152
|
-
let DataValidationManager = _DataValidationManager;
|
|
153
|
-
var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
154
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
155
|
-
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
156
|
-
return kind && result && __defProp$4(target, key, result), result;
|
|
157
|
-
}, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a;
|
|
158
|
-
let DataValidationModel = (_a = class extends Disposable {
|
|
159
|
-
constructor(_logService) {
|
|
160
|
-
super();
|
|
161
|
-
__publicField(this, "_model", /* @__PURE__ */ new Map());
|
|
162
|
-
__publicField(this, "_managerCreator", /* @__PURE__ */ __name((unitId, subUnitId) => new DataValidationManager(unitId, subUnitId), "_managerCreator"));
|
|
163
|
-
__publicField(this, "_ruleChange$", new Subject());
|
|
164
|
-
__publicField(this, "_validStatusChange$", new Subject());
|
|
165
|
-
__publicField(this, "ruleChange$", this._ruleChange$.asObservable());
|
|
166
|
-
__publicField(this, "ruleChangeDebounce$", this.ruleChange$.pipe(debounceTime(20)));
|
|
167
|
-
__publicField(this, "validStatusChange$", this._validStatusChange$.asObservable().pipe(debounceTime(20)));
|
|
168
|
-
this._logService = _logService, this.disposeWithMe({
|
|
169
|
-
dispose: /* @__PURE__ */ __name(() => {
|
|
170
|
-
this._ruleChange$.complete(), this._validStatusChange$.complete();
|
|
171
|
-
}, "dispose")
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
setManagerCreator(creator) {
|
|
175
|
-
this._managerCreator = creator;
|
|
176
|
-
}
|
|
177
|
-
ensureManager(unitId, subUnitId) {
|
|
178
|
-
this._model.has(unitId) || this._model.set(unitId, /* @__PURE__ */ new Map());
|
|
179
|
-
const unitMap = this._model.get(unitId);
|
|
180
|
-
if (unitMap.has(subUnitId))
|
|
181
|
-
return unitMap.get(subUnitId);
|
|
182
|
-
const manager = this._managerCreator(unitId, subUnitId);
|
|
183
|
-
return unitMap.set(subUnitId, manager), this.disposeWithMe(manager), manager;
|
|
88
|
+
return dataValidations[index] = rule, dataValidationMap.set(ruleId, rule), rule;
|
|
184
89
|
}
|
|
185
90
|
_addRuleSideEffect(unitId, subUnitId, rule, source) {
|
|
186
|
-
this.
|
|
91
|
+
this._ensureMap(unitId, subUnitId).map.get(rule.uid) || this._ruleChange$.next({
|
|
187
92
|
rule,
|
|
188
93
|
type: "add",
|
|
189
94
|
unitId,
|
|
@@ -193,23 +98,28 @@ let DataValidationModel = (_a = class extends Disposable {
|
|
|
193
98
|
}
|
|
194
99
|
addRule(unitId, subUnitId, rule, source, index) {
|
|
195
100
|
try {
|
|
196
|
-
const
|
|
101
|
+
const subUnitMap = this._ensureMap(unitId, subUnitId);
|
|
197
102
|
(Array.isArray(rule) ? rule : [rule]).forEach((item) => {
|
|
198
103
|
this._addRuleSideEffect(unitId, subUnitId, item, source);
|
|
199
|
-
}),
|
|
104
|
+
}), this._addSubUnitRule(subUnitMap, rule, index);
|
|
200
105
|
} catch (error) {
|
|
201
106
|
this._logService.error(error);
|
|
202
107
|
}
|
|
203
108
|
}
|
|
204
109
|
updateRule(unitId, subUnitId, ruleId, payload, source) {
|
|
205
110
|
try {
|
|
206
|
-
const
|
|
111
|
+
const subUnitMap = this._ensureMap(unitId, subUnitId), oldRule = Tools.deepClone(subUnitMap.map.get(ruleId));
|
|
112
|
+
if (!oldRule)
|
|
113
|
+
throw new Error(`Data validation rule is not found, ruleId: ${ruleId}.`);
|
|
114
|
+
const rule = this._updateSubUnitRule(subUnitMap, ruleId, payload);
|
|
207
115
|
this._ruleChange$.next({
|
|
208
116
|
rule,
|
|
209
117
|
type: "update",
|
|
210
118
|
unitId,
|
|
211
119
|
subUnitId,
|
|
212
|
-
source
|
|
120
|
+
source,
|
|
121
|
+
updatePayload: payload,
|
|
122
|
+
oldRule
|
|
213
123
|
});
|
|
214
124
|
} catch (error) {
|
|
215
125
|
this._logService.error(error);
|
|
@@ -217,8 +127,8 @@ let DataValidationModel = (_a = class extends Disposable {
|
|
|
217
127
|
}
|
|
218
128
|
removeRule(unitId, subUnitId, ruleId, source) {
|
|
219
129
|
try {
|
|
220
|
-
const
|
|
221
|
-
oldRule && (
|
|
130
|
+
const map = this._ensureMap(unitId, subUnitId), oldRule = map.map.get(ruleId);
|
|
131
|
+
oldRule && (this._removeSubUnitRule(map, ruleId), this._ruleChange$.next({
|
|
222
132
|
rule: oldRule,
|
|
223
133
|
type: "remove",
|
|
224
134
|
unitId,
|
|
@@ -230,44 +140,36 @@ let DataValidationModel = (_a = class extends Disposable {
|
|
|
230
140
|
}
|
|
231
141
|
}
|
|
232
142
|
getRuleById(unitId, subUnitId, ruleId) {
|
|
233
|
-
return this.
|
|
143
|
+
return this._ensureMap(unitId, subUnitId).map.get(ruleId);
|
|
234
144
|
}
|
|
235
145
|
getRuleIndex(unitId, subUnitId, ruleId) {
|
|
236
|
-
return this.
|
|
146
|
+
return this._ensureMap(unitId, subUnitId).list.findIndex((rule) => rule.uid === ruleId);
|
|
237
147
|
}
|
|
238
148
|
getRules(unitId, subUnitId) {
|
|
239
|
-
return this.
|
|
240
|
-
}
|
|
241
|
-
validator(rule, pos, value) {
|
|
242
|
-
const { unitId, subUnitId } = pos;
|
|
243
|
-
return this.ensureManager(unitId, subUnitId).validator(value, rule, pos, (status, changed) => {
|
|
244
|
-
changed && this._validStatusChange$.next({
|
|
245
|
-
unitId,
|
|
246
|
-
subUnitId,
|
|
247
|
-
ruleId: rule.uid,
|
|
248
|
-
status
|
|
249
|
-
});
|
|
250
|
-
});
|
|
149
|
+
return [...this._ensureMap(unitId, subUnitId).list];
|
|
251
150
|
}
|
|
252
151
|
getUnitRules(unitId) {
|
|
253
152
|
const unitMap = this._model.get(unitId);
|
|
254
153
|
if (!unitMap)
|
|
255
154
|
return [];
|
|
256
155
|
const res = [];
|
|
257
|
-
return unitMap.forEach((manager) => {
|
|
258
|
-
res.push([
|
|
156
|
+
return unitMap.forEach((manager, subUnitId) => {
|
|
157
|
+
res.push([subUnitId, manager.list]);
|
|
259
158
|
}), res;
|
|
260
159
|
}
|
|
261
160
|
deleteUnitRules(unitId) {
|
|
262
161
|
this._model.delete(unitId);
|
|
263
162
|
}
|
|
264
163
|
getSubUnitIds(unitId) {
|
|
265
|
-
var
|
|
266
|
-
return Array.from((_b = (
|
|
164
|
+
var _a5, _b;
|
|
165
|
+
return Array.from((_b = (_a5 = this._model.get(unitId)) == null ? void 0 : _a5.keys()) != null ? _b : []);
|
|
166
|
+
}
|
|
167
|
+
getAll() {
|
|
168
|
+
return Array.from(this._model.keys()).map((unitId) => [unitId, this.getUnitRules(unitId)]);
|
|
267
169
|
}
|
|
268
170
|
}, __name(_a, "DataValidationModel"), _a);
|
|
269
|
-
DataValidationModel = __decorateClass$
|
|
270
|
-
__decorateParam$
|
|
171
|
+
DataValidationModel = __decorateClass$3([
|
|
172
|
+
__decorateParam$3(0, ILogService)
|
|
271
173
|
], DataValidationModel);
|
|
272
174
|
const AddDataValidationMutation = {
|
|
273
175
|
type: CommandType.MUTATION,
|
|
@@ -298,11 +200,104 @@ const AddDataValidationMutation = {
|
|
|
298
200
|
const { unitId, subUnitId, ruleId, payload, source = "command" } = params;
|
|
299
201
|
return accessor.get(DataValidationModel).updateRule(unitId, subUnitId, ruleId, payload, source), !0;
|
|
300
202
|
}
|
|
301
|
-
}
|
|
203
|
+
};
|
|
204
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
205
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
206
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
207
|
+
return kind && result && __defProp$2(target, key, result), result;
|
|
208
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2");
|
|
209
|
+
const DATA_VALIDATION_PLUGIN_NAME = "SHEET_DATA_VALIDATION_PLUGIN";
|
|
210
|
+
var _a2;
|
|
211
|
+
let DataValidationResourceController = (_a2 = class extends Disposable {
|
|
212
|
+
constructor(_resourceManagerService, _univerInstanceService, _dataValidationModel) {
|
|
213
|
+
super(), this._resourceManagerService = _resourceManagerService, this._univerInstanceService = _univerInstanceService, this._dataValidationModel = _dataValidationModel, this._initSnapshot();
|
|
214
|
+
}
|
|
215
|
+
_initSnapshot() {
|
|
216
|
+
const toJson = /* @__PURE__ */ __name((unitID) => {
|
|
217
|
+
const map = this._dataValidationModel.getUnitRules(unitID), resultMap = {};
|
|
218
|
+
return map ? (map.forEach(([key, v]) => {
|
|
219
|
+
resultMap[key] = v;
|
|
220
|
+
}), JSON.stringify(resultMap)) : "";
|
|
221
|
+
}, "toJson"), parseJson = /* @__PURE__ */ __name((json) => {
|
|
222
|
+
if (!json)
|
|
223
|
+
return {};
|
|
224
|
+
try {
|
|
225
|
+
return JSON.parse(json);
|
|
226
|
+
} catch {
|
|
227
|
+
return {};
|
|
228
|
+
}
|
|
229
|
+
}, "parseJson");
|
|
230
|
+
this.disposeWithMe(
|
|
231
|
+
this._resourceManagerService.registerPluginResource({
|
|
232
|
+
pluginName: DATA_VALIDATION_PLUGIN_NAME,
|
|
233
|
+
businesses: [UniverInstanceType.UNIVER_SHEET],
|
|
234
|
+
toJson: /* @__PURE__ */ __name((unitID) => toJson(unitID), "toJson"),
|
|
235
|
+
parseJson: /* @__PURE__ */ __name((json) => parseJson(json), "parseJson"),
|
|
236
|
+
onUnLoad: /* @__PURE__ */ __name((unitID) => {
|
|
237
|
+
this._dataValidationModel.deleteUnitRules(unitID);
|
|
238
|
+
}, "onUnLoad"),
|
|
239
|
+
onLoad: /* @__PURE__ */ __name((unitID, value) => {
|
|
240
|
+
Object.keys(value).forEach((subunitId) => {
|
|
241
|
+
value[subunitId].forEach((rule) => {
|
|
242
|
+
this._dataValidationModel.addRule(unitID, subunitId, rule, "patched");
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
}, "onLoad")
|
|
246
|
+
})
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
}, __name(_a2, "DataValidationResourceController"), _a2);
|
|
250
|
+
DataValidationResourceController = __decorateClass$2([
|
|
251
|
+
OnLifecycle(LifecycleStages.Ready, DataValidationResourceController),
|
|
252
|
+
__decorateParam$2(0, IResourceManagerService),
|
|
253
|
+
__decorateParam$2(1, IUniverInstanceService),
|
|
254
|
+
__decorateParam$2(2, Inject(DataValidationModel))
|
|
255
|
+
], DataValidationResourceController);
|
|
256
|
+
var DataValidatorRegistryScope = /* @__PURE__ */ ((DataValidatorRegistryScope2) => (DataValidatorRegistryScope2.SHEET = "sheet", DataValidatorRegistryScope2))(DataValidatorRegistryScope || {});
|
|
257
|
+
const _DataValidatorRegistryService = class _DataValidatorRegistryService {
|
|
258
|
+
constructor() {
|
|
259
|
+
__publicField(this, "_validatorByScopes", /* @__PURE__ */ new Map());
|
|
260
|
+
__publicField(this, "_validatorMap", /* @__PURE__ */ new Map());
|
|
261
|
+
__publicField(this, "_validatorsChange$", new BehaviorSubject(void 0));
|
|
262
|
+
__publicField(this, "validatorsChange$", this._validatorsChange$.asObservable());
|
|
263
|
+
}
|
|
264
|
+
_addValidatorToScope(validator, scope) {
|
|
265
|
+
this._validatorByScopes.has(scope) || this._validatorByScopes.set(scope, []);
|
|
266
|
+
const validators = this._validatorByScopes.get(scope);
|
|
267
|
+
if (validators.findIndex((m) => m.id === validator.id) > -1)
|
|
268
|
+
throw new Error(`Validator item with the same id ${validator.id} has already been added!`);
|
|
269
|
+
validators.push(validator);
|
|
270
|
+
}
|
|
271
|
+
_removeValidatorFromScope(validator, scope) {
|
|
272
|
+
const validators = this._validatorByScopes.get(scope);
|
|
273
|
+
if (!validators)
|
|
274
|
+
return;
|
|
275
|
+
const index = validators.findIndex((v) => v.id === validator.id);
|
|
276
|
+
index > -1 && validators.splice(index, 1);
|
|
277
|
+
}
|
|
278
|
+
register(validator) {
|
|
279
|
+
return this._validatorMap.set(validator.id, validator), Array.isArray(validator.scopes) ? validator.scopes.forEach((scope) => {
|
|
280
|
+
this._addValidatorToScope(validator, scope);
|
|
281
|
+
}) : this._addValidatorToScope(validator, validator.scopes), this._validatorsChange$.next(), toDisposable(() => {
|
|
282
|
+
this._validatorMap.delete(validator.id), Array.isArray(validator.scopes) ? validator.scopes.forEach((scope) => {
|
|
283
|
+
this._removeValidatorFromScope(validator, scope);
|
|
284
|
+
}) : this._removeValidatorFromScope(validator, validator.scopes), this._validatorsChange$.next();
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
getValidatorItem(id) {
|
|
288
|
+
return this._validatorMap.get(id);
|
|
289
|
+
}
|
|
290
|
+
getValidatorsByScope(scope) {
|
|
291
|
+
return this._validatorByScopes.get(scope);
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
__name(_DataValidatorRegistryService, "DataValidatorRegistryService");
|
|
295
|
+
let DataValidatorRegistryService = _DataValidatorRegistryService;
|
|
296
|
+
const AddDataValidationCommand = {
|
|
302
297
|
type: CommandType.COMMAND,
|
|
303
298
|
id: "data-validation.command.addRule",
|
|
304
299
|
async handler(accessor, params) {
|
|
305
|
-
if (accessor.get(ILogService).
|
|
300
|
+
if (accessor.get(ILogService).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !params)
|
|
306
301
|
return !1;
|
|
307
302
|
const { rule, unitId, subUnitId } = params, commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), mutationParams = {
|
|
308
303
|
...params,
|
|
@@ -327,36 +322,11 @@ const AddDataValidationMutation = {
|
|
|
327
322
|
undoMutations
|
|
328
323
|
}), await commandService.executeCommand(AddDataValidationMutation.id, mutationParams), !0;
|
|
329
324
|
}
|
|
330
|
-
},
|
|
331
|
-
const dataValidationModel = accessor.get(DataValidationModel), { unitId, subUnitId, ruleId, source } = redoParams;
|
|
332
|
-
if (Array.isArray(ruleId)) {
|
|
333
|
-
const rules = ruleId.map((id) => dataValidationModel.getRuleById(unitId, subUnitId, id)).filter(Boolean);
|
|
334
|
-
return [{
|
|
335
|
-
id: AddDataValidationMutation.id,
|
|
336
|
-
params: {
|
|
337
|
-
unitId,
|
|
338
|
-
subUnitId,
|
|
339
|
-
rule: rules,
|
|
340
|
-
source
|
|
341
|
-
}
|
|
342
|
-
}];
|
|
343
|
-
}
|
|
344
|
-
return [{
|
|
345
|
-
id: AddDataValidationMutation.id,
|
|
346
|
-
params: {
|
|
347
|
-
unitId,
|
|
348
|
-
subUnitId,
|
|
349
|
-
rule: {
|
|
350
|
-
...dataValidationModel.getRuleById(unitId, subUnitId, ruleId)
|
|
351
|
-
},
|
|
352
|
-
index: dataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
|
|
353
|
-
}
|
|
354
|
-
}];
|
|
355
|
-
}, "removeDataValidationUndoFactory"), RemoveDataValidationCommand = {
|
|
325
|
+
}, RemoveDataValidationCommand = {
|
|
356
326
|
type: CommandType.COMMAND,
|
|
357
327
|
id: "data-validation.command.removeRule",
|
|
358
328
|
handler(accessor, params) {
|
|
359
|
-
if (!params)
|
|
329
|
+
if (accessor.get(ILogService).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !params)
|
|
360
330
|
return !1;
|
|
361
331
|
const { unitId, subUnitId, ruleId } = params, commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), dataValidationModel = accessor.get(DataValidationModel), redoMutations = [{
|
|
362
332
|
id: RemoveDataValidationMutation.id,
|
|
@@ -382,7 +352,7 @@ const AddDataValidationMutation = {
|
|
|
382
352
|
type: CommandType.COMMAND,
|
|
383
353
|
id: "data-validation.command.updateDataValidationSetting",
|
|
384
354
|
handler(accessor, params) {
|
|
385
|
-
if (accessor.get(ILogService).warn("[Deprecated] UpdateDataValidationOptionsCommand is deprecated, please use UpdateSheetDataValidationOptionsCommand in
|
|
355
|
+
if (accessor.get(ILogService).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"), !params)
|
|
386
356
|
return !1;
|
|
387
357
|
const commandService = accessor.get(ICommandService), redoUndoService = accessor.get(IUndoRedoService), dataValidationModel = accessor.get(DataValidationModel), { unitId, subUnitId, ruleId, options } = params, rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
388
358
|
if (!rule)
|
|
@@ -420,7 +390,7 @@ const AddDataValidationMutation = {
|
|
|
420
390
|
type: CommandType.COMMAND,
|
|
421
391
|
id: "data-validation.command.updateDataValidationOptions",
|
|
422
392
|
handler(accessor, params) {
|
|
423
|
-
if (accessor.get(ILogService).
|
|
393
|
+
if (accessor.get(ILogService).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"), !params)
|
|
424
394
|
return !1;
|
|
425
395
|
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);
|
|
426
396
|
if (!validator)
|
|
@@ -439,7 +409,7 @@ const AddDataValidationMutation = {
|
|
|
439
409
|
type: UpdateRuleType.SETTING,
|
|
440
410
|
payload: {
|
|
441
411
|
...setting,
|
|
442
|
-
...validator.
|
|
412
|
+
...validator.normalizeFormula(newRule, unitId, subUnitId)
|
|
443
413
|
}
|
|
444
414
|
}
|
|
445
415
|
}, redoMutations = [{
|
|
@@ -467,7 +437,7 @@ const AddDataValidationMutation = {
|
|
|
467
437
|
type: CommandType.COMMAND,
|
|
468
438
|
id: "data-validation.command.removeAll",
|
|
469
439
|
handler(accessor, params) {
|
|
470
|
-
if (!params)
|
|
440
|
+
if (accessor.get(ILogService).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !params)
|
|
471
441
|
return !1;
|
|
472
442
|
const { unitId, subUnitId } = params, commandService = accessor.get(ICommandService), dataValidationModel = accessor.get(DataValidationModel), undoRedoService = accessor.get(IUndoRedoService), currentRules = [...dataValidationModel.getRules(unitId, subUnitId)], redoParams = {
|
|
473
443
|
unitId,
|
|
@@ -490,126 +460,15 @@ const AddDataValidationMutation = {
|
|
|
490
460
|
unitID: unitId
|
|
491
461
|
}), commandService.executeCommand(RemoveDataValidationMutation.id, redoParams), !0;
|
|
492
462
|
}
|
|
493
|
-
};
|
|
494
|
-
var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
495
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
496
|
-
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
497
|
-
return kind && result && __defProp$3(target, key, result), result;
|
|
498
|
-
}, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3");
|
|
499
|
-
const DATA_VALIDATION_PLUGIN_NAME = "SHEET_DATA_VALIDATION_PLUGIN";
|
|
500
|
-
var _a2;
|
|
501
|
-
let DataValidationResourceController = (_a2 = class extends Disposable {
|
|
502
|
-
constructor(_resourceManagerService, _univerInstanceService, _dataValidationModel) {
|
|
503
|
-
super(), this._resourceManagerService = _resourceManagerService, this._univerInstanceService = _univerInstanceService, this._dataValidationModel = _dataValidationModel, this._initSnapshot();
|
|
504
|
-
}
|
|
505
|
-
_initSnapshot() {
|
|
506
|
-
const toJson = /* @__PURE__ */ __name((unitID) => {
|
|
507
|
-
const map = this._dataValidationModel.getUnitRules(unitID), resultMap = {};
|
|
508
|
-
return map ? (map.forEach(([key, v]) => {
|
|
509
|
-
resultMap[key] = v;
|
|
510
|
-
}), JSON.stringify(resultMap)) : "";
|
|
511
|
-
}, "toJson"), parseJson = /* @__PURE__ */ __name((json) => {
|
|
512
|
-
if (!json)
|
|
513
|
-
return {};
|
|
514
|
-
try {
|
|
515
|
-
return JSON.parse(json);
|
|
516
|
-
} catch {
|
|
517
|
-
return {};
|
|
518
|
-
}
|
|
519
|
-
}, "parseJson");
|
|
520
|
-
this.disposeWithMe(
|
|
521
|
-
this._resourceManagerService.registerPluginResource({
|
|
522
|
-
pluginName: DATA_VALIDATION_PLUGIN_NAME,
|
|
523
|
-
businesses: [UniverInstanceType.UNIVER_SHEET],
|
|
524
|
-
toJson: /* @__PURE__ */ __name((unitID) => toJson(unitID), "toJson"),
|
|
525
|
-
parseJson: /* @__PURE__ */ __name((json) => parseJson(json), "parseJson"),
|
|
526
|
-
onUnLoad: /* @__PURE__ */ __name((unitID) => {
|
|
527
|
-
this._dataValidationModel.deleteUnitRules(unitID);
|
|
528
|
-
}, "onUnLoad"),
|
|
529
|
-
onLoad: /* @__PURE__ */ __name((unitID, value) => {
|
|
530
|
-
Object.keys(value).forEach((subunitId) => {
|
|
531
|
-
value[subunitId].forEach((rule) => {
|
|
532
|
-
this._dataValidationModel.addRule(unitID, subunitId, rule, "patched");
|
|
533
|
-
});
|
|
534
|
-
});
|
|
535
|
-
}, "onLoad")
|
|
536
|
-
})
|
|
537
|
-
);
|
|
538
|
-
}
|
|
539
|
-
}, __name(_a2, "DataValidationResourceController"), _a2);
|
|
540
|
-
DataValidationResourceController = __decorateClass$3([
|
|
541
|
-
OnLifecycle(LifecycleStages.Ready, DataValidationResourceController),
|
|
542
|
-
__decorateParam$3(0, IResourceManagerService),
|
|
543
|
-
__decorateParam$3(1, IUniverInstanceService),
|
|
544
|
-
__decorateParam$3(2, Inject(DataValidationModel))
|
|
545
|
-
], DataValidationResourceController);
|
|
546
|
-
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
547
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
548
|
-
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
549
|
-
return kind && result && __defProp$2(target, key, result), result;
|
|
550
|
-
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a3;
|
|
551
|
-
let DataValidationSheetController = (_a3 = class extends Disposable {
|
|
552
|
-
constructor(_sheetInterceptorService, _univerInstanceService, _dataValidationModel) {
|
|
553
|
-
super(), this._sheetInterceptorService = _sheetInterceptorService, this._univerInstanceService = _univerInstanceService, this._dataValidationModel = _dataValidationModel, this._initSheetChange();
|
|
554
|
-
}
|
|
555
|
-
_initSheetChange() {
|
|
556
|
-
this.disposeWithMe(
|
|
557
|
-
this._sheetInterceptorService.interceptCommand({
|
|
558
|
-
getMutations: /* @__PURE__ */ __name((commandInfo) => {
|
|
559
|
-
var _a6;
|
|
560
|
-
if (commandInfo.id === RemoveSheetCommand.id) {
|
|
561
|
-
const params = commandInfo.params, unitId = params.unitId || this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET).getUnitId(), workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
|
|
562
|
-
if (!workbook)
|
|
563
|
-
return { redos: [], undos: [] };
|
|
564
|
-
const subUnitId = params.subUnitId || ((_a6 = workbook.getActiveSheet()) == null ? void 0 : _a6.getSheetId());
|
|
565
|
-
if (!subUnitId)
|
|
566
|
-
return { redos: [], undos: [] };
|
|
567
|
-
const manager = this._dataValidationModel.ensureManager(unitId, subUnitId);
|
|
568
|
-
if (!manager)
|
|
569
|
-
return { redos: [], undos: [] };
|
|
570
|
-
const rules = manager.getDataValidations(), ids = rules.map((i) => i.uid), redoParams = {
|
|
571
|
-
unitId,
|
|
572
|
-
subUnitId,
|
|
573
|
-
ruleId: ids,
|
|
574
|
-
source: "patched"
|
|
575
|
-
}, undoParams = {
|
|
576
|
-
unitId,
|
|
577
|
-
subUnitId,
|
|
578
|
-
rule: [...rules],
|
|
579
|
-
source: "patched"
|
|
580
|
-
};
|
|
581
|
-
return {
|
|
582
|
-
redos: [{
|
|
583
|
-
id: RemoveDataValidationMutation.id,
|
|
584
|
-
params: redoParams
|
|
585
|
-
}],
|
|
586
|
-
undos: [{
|
|
587
|
-
id: AddDataValidationMutation.id,
|
|
588
|
-
params: undoParams
|
|
589
|
-
}]
|
|
590
|
-
};
|
|
591
|
-
}
|
|
592
|
-
return { redos: [], undos: [] };
|
|
593
|
-
}, "getMutations")
|
|
594
|
-
})
|
|
595
|
-
);
|
|
596
|
-
}
|
|
597
|
-
}, __name(_a3, "DataValidationSheetController"), _a3);
|
|
598
|
-
DataValidationSheetController = __decorateClass$2([
|
|
599
|
-
OnLifecycle(LifecycleStages.Ready, DataValidationSheetController),
|
|
600
|
-
__decorateParam$2(0, Inject(SheetInterceptorService)),
|
|
601
|
-
__decorateParam$2(1, Inject(IUniverInstanceService)),
|
|
602
|
-
__decorateParam$2(2, Inject(DataValidationModel))
|
|
603
|
-
], DataValidationSheetController);
|
|
604
|
-
const PLUGIN_CONFIG_KEY = "data-validation.config", defaultPluginConfig = {};
|
|
463
|
+
}, PLUGIN_CONFIG_KEY = "data-validation.config", defaultPluginConfig = {};
|
|
605
464
|
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
606
465
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
607
466
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
608
467
|
return kind && result && __defProp$1(target, key, result), result;
|
|
609
468
|
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1");
|
|
610
469
|
const PLUGIN_NAME = "UNIVER_DATA_VALIDATION_PLUGIN";
|
|
611
|
-
var
|
|
612
|
-
let UniverDataValidationPlugin = (
|
|
470
|
+
var _a3;
|
|
471
|
+
let UniverDataValidationPlugin = (_a3 = class extends Plugin {
|
|
613
472
|
constructor(_config = defaultPluginConfig, _injector, _commandService, _configService) {
|
|
614
473
|
super(), this._config = _config, this._injector = _injector, this._commandService = _commandService, this._configService = _configService;
|
|
615
474
|
const { ...rest } = this._config;
|
|
@@ -619,8 +478,7 @@ let UniverDataValidationPlugin = (_a4 = class extends Plugin {
|
|
|
619
478
|
[
|
|
620
479
|
[DataValidationModel],
|
|
621
480
|
[DataValidatorRegistryService],
|
|
622
|
-
[DataValidationResourceController]
|
|
623
|
-
[DataValidationSheetController]
|
|
481
|
+
[DataValidationResourceController]
|
|
624
482
|
].forEach((d) => this._injector.add(d)), [
|
|
625
483
|
// command
|
|
626
484
|
AddDataValidationCommand,
|
|
@@ -636,7 +494,7 @@ let UniverDataValidationPlugin = (_a4 = class extends Plugin {
|
|
|
636
494
|
this._commandService.registerCommand(command);
|
|
637
495
|
});
|
|
638
496
|
}
|
|
639
|
-
}, __name(
|
|
497
|
+
}, __name(_a3, "UniverDataValidationPlugin"), __publicField(_a3, "pluginName", PLUGIN_NAME), __publicField(_a3, "type", UniverInstanceType.UNIVER_SHEET), _a3);
|
|
640
498
|
UniverDataValidationPlugin = __decorateClass$1([
|
|
641
499
|
__decorateParam$1(1, Inject(Injector)),
|
|
642
500
|
__decorateParam$1(2, ICommandService),
|
|
@@ -670,7 +528,10 @@ const OperatorTitleMap = {
|
|
|
670
528
|
[DataValidationOperator.LESS_THAN_OR_EQUAL]: "dataValidation.textLength.errorMsg.lessThanOrEqual",
|
|
671
529
|
[DataValidationOperator.NOT_BETWEEN]: "dataValidation.textLength.errorMsg.notBetween",
|
|
672
530
|
[DataValidationOperator.NOT_EQUAL]: "dataValidation.textLength.errorMsg.notEqual"
|
|
673
|
-
}
|
|
531
|
+
}, TWO_FORMULA_OPERATOR_COUNT = [
|
|
532
|
+
DataValidationOperator.BETWEEN,
|
|
533
|
+
DataValidationOperator.NOT_BETWEEN
|
|
534
|
+
];
|
|
674
535
|
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
675
536
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
676
537
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
@@ -686,8 +547,8 @@ const FORMULA1 = "{FORMULA1}", FORMULA2 = "{FORMULA2}", operatorNameMap = {
|
|
|
686
547
|
[DataValidationOperator.NOT_BETWEEN]: "dataValidation.operators.notBetween",
|
|
687
548
|
[DataValidationOperator.NOT_EQUAL]: "dataValidation.operators.notEqual"
|
|
688
549
|
};
|
|
689
|
-
var
|
|
690
|
-
let BaseDataValidator = (
|
|
550
|
+
var _a4;
|
|
551
|
+
let BaseDataValidator = (_a4 = class {
|
|
691
552
|
constructor(localeService, injector) {
|
|
692
553
|
__publicField(this, "canvasRender", null);
|
|
693
554
|
__publicField(this, "dropdown");
|
|
@@ -704,15 +565,15 @@ let BaseDataValidator = (_a5 = class {
|
|
|
704
565
|
return !1;
|
|
705
566
|
}
|
|
706
567
|
generateRuleName(rule) {
|
|
707
|
-
var
|
|
568
|
+
var _a5, _b;
|
|
708
569
|
if (!rule.operator)
|
|
709
570
|
return this.titleStr;
|
|
710
|
-
const ruleName = this.localeService.t(OperatorTitleMap[rule.operator]).replace(FORMULA1, (
|
|
571
|
+
const ruleName = this.localeService.t(OperatorTitleMap[rule.operator]).replace(FORMULA1, (_a5 = rule.formula1) != null ? _a5 : "").replace(FORMULA2, (_b = rule.formula2) != null ? _b : "");
|
|
711
572
|
return `${this.titleStr} ${ruleName}`;
|
|
712
573
|
}
|
|
713
574
|
generateRuleErrorMessage(rule) {
|
|
714
|
-
var
|
|
715
|
-
return rule.operator ? `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, (
|
|
575
|
+
var _a5, _b;
|
|
576
|
+
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;
|
|
716
577
|
}
|
|
717
578
|
getRuleFinalError(rule) {
|
|
718
579
|
return rule.showErrorMessage && rule.error ? rule.error : this.generateRuleErrorMessage(rule);
|
|
@@ -720,7 +581,7 @@ let BaseDataValidator = (_a5 = class {
|
|
|
720
581
|
isEmptyCellValue(cellValue) {
|
|
721
582
|
return cellValue === "" || cellValue === void 0 || cellValue === null;
|
|
722
583
|
}
|
|
723
|
-
|
|
584
|
+
normalizeFormula(rule, unitId, subUnitId) {
|
|
724
585
|
return {
|
|
725
586
|
formula1: rule.formula1,
|
|
726
587
|
formula2: rule.formula2
|
|
@@ -787,37 +648,24 @@ let BaseDataValidator = (_a5 = class {
|
|
|
787
648
|
throw new Error("Unknown operator.");
|
|
788
649
|
}
|
|
789
650
|
}
|
|
790
|
-
}, __name(
|
|
651
|
+
}, __name(_a4, "BaseDataValidator"), _a4);
|
|
791
652
|
BaseDataValidator = __decorateClass([
|
|
792
653
|
__decorateParam(0, Inject(LocaleService)),
|
|
793
654
|
__decorateParam(1, Inject(Injector))
|
|
794
655
|
], BaseDataValidator);
|
|
795
|
-
const TWO_FORMULA_OPERATOR_COUNT = [
|
|
796
|
-
DataValidationOperator.BETWEEN,
|
|
797
|
-
DataValidationOperator.NOT_BETWEEN
|
|
798
|
-
];
|
|
799
656
|
export {
|
|
800
|
-
AddDataValidationCommand,
|
|
801
657
|
AddDataValidationMutation,
|
|
802
658
|
BaseDataValidator,
|
|
803
|
-
DataValidationManager,
|
|
804
659
|
DataValidationModel,
|
|
805
660
|
DataValidationResourceController,
|
|
806
|
-
DataValidationSheetController,
|
|
807
661
|
DataValidatorRegistryScope,
|
|
808
662
|
DataValidatorRegistryService,
|
|
809
|
-
RemoveAllDataValidationCommand,
|
|
810
|
-
RemoveDataValidationCommand,
|
|
811
663
|
RemoveDataValidationMutation,
|
|
812
664
|
TWO_FORMULA_OPERATOR_COUNT,
|
|
813
665
|
TextLengthErrorTitleMap,
|
|
814
666
|
UniverDataValidationPlugin,
|
|
815
667
|
UpdateDataValidationMutation,
|
|
816
|
-
UpdateDataValidationOptionsCommand,
|
|
817
|
-
UpdateDataValidationSettingCommand,
|
|
818
668
|
UpdateRuleType,
|
|
819
|
-
createDefaultNewRule,
|
|
820
669
|
getRuleOptions,
|
|
821
|
-
getRuleSetting
|
|
822
|
-
removeDataValidationUndoFactory
|
|
670
|
+
getRuleSetting
|
|
823
671
|
};
|