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