@univerjs/data-validation 0.1.6
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/LICENSE +176 -0
- package/README.md +28 -0
- package/lib/cjs/index.js +1 -0
- package/lib/es/index.js +667 -0
- package/lib/types/commands/commands/data-validation.command.d.ts +30 -0
- package/lib/types/commands/mutations/data-validation.mutation.d.ts +18 -0
- package/lib/types/common/util.d.ts +12 -0
- package/lib/types/index.d.ts +35 -0
- package/lib/types/models/data-validation-manager.d.ts +22 -0
- package/lib/types/models/data-validation-model.d.ts +39 -0
- package/lib/types/plugin.d.ts +9 -0
- package/lib/types/services/data-validator-registry.service.d.ts +19 -0
- package/lib/types/types/const/operator-text-map.d.ts +5 -0
- package/lib/types/types/const/two-formula-operators.d.ts +3 -0
- package/lib/types/types/enum/update-rule-type.d.ts +20 -0
- package/lib/types/types/interfaces/i-data-validation-drop-down.d.ts +25 -0
- package/lib/types/types/interfaces/i-data-validator-operator-config.d.ts +9 -0
- package/lib/types/types/interfaces/i-formula-input.d.ts +16 -0
- package/lib/types/types/interfaces/i-update-rule-payload.d.ts +16 -0
- package/lib/types/validators/base-data-validator.d.ts +53 -0
- package/lib/types/validators/base-widget.d.ts +5 -0
- package/lib/umd/index.js +1 -0
- package/package.json +60 -0
package/lib/es/index.js
ADDED
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
var P = Object.defineProperty;
|
|
2
|
+
var q = (e, a, t) => a in e ? P(e, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[a] = t;
|
|
3
|
+
var c = (e, a, t) => (q(e, typeof a != "symbol" ? a + "" : a, t), t);
|
|
4
|
+
import { toDisposable as G, Disposable as U, ILogService as H, CommandType as m, Tools as L, DataValidationType as Q, DataValidationOperator as s, ICommandService as T, IUndoRedoService as M, Plugin as W, LocaleService as j, DataValidationStatus as F } from "@univerjs/core";
|
|
5
|
+
import { Inject as I, Injector as B } from "@wendellhu/redi";
|
|
6
|
+
import { BehaviorSubject as J, Subject as S, debounceTime as A } from "rxjs";
|
|
7
|
+
import { SelectionManagerService as z } from "@univerjs/sheets";
|
|
8
|
+
var K = /* @__PURE__ */ ((e) => (e.SHEET = "sheet", e))(K || {});
|
|
9
|
+
class b {
|
|
10
|
+
constructor() {
|
|
11
|
+
c(this, "_validatorByScopes", /* @__PURE__ */ new Map());
|
|
12
|
+
c(this, "_validatorMap", /* @__PURE__ */ new Map());
|
|
13
|
+
c(this, "_validatorsChange$", new J(void 0));
|
|
14
|
+
c(this, "validatorsChange$", this._validatorsChange$.asObservable());
|
|
15
|
+
}
|
|
16
|
+
_addValidatorToScope(a, t) {
|
|
17
|
+
this._validatorByScopes.has(t) || this._validatorByScopes.set(t, []);
|
|
18
|
+
const r = this._validatorByScopes.get(t);
|
|
19
|
+
if (r.findIndex((o) => o.id === a.id) > -1)
|
|
20
|
+
throw new Error(`Validator item with the same id ${a.id} has already been added!`);
|
|
21
|
+
r.push(a);
|
|
22
|
+
}
|
|
23
|
+
_removeValidatorFromScope(a, t) {
|
|
24
|
+
const r = this._validatorByScopes.get(t);
|
|
25
|
+
if (!r)
|
|
26
|
+
return;
|
|
27
|
+
const o = r.findIndex((n) => n.id === a.id);
|
|
28
|
+
o > -1 && r.splice(o, 1);
|
|
29
|
+
}
|
|
30
|
+
register(a) {
|
|
31
|
+
return this._validatorMap.set(a.id, a), Array.isArray(a.scopes) ? a.scopes.forEach((t) => {
|
|
32
|
+
this._addValidatorToScope(a, t);
|
|
33
|
+
}) : this._addValidatorToScope(a, a.scopes), this._validatorsChange$.next(), G(() => {
|
|
34
|
+
this._validatorMap.delete(a.id), Array.isArray(a.scopes) ? a.scopes.forEach((t) => {
|
|
35
|
+
this._removeValidatorFromScope(a, t);
|
|
36
|
+
}) : this._removeValidatorFromScope(a, a.scopes), this._validatorsChange$.next();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
getValidatorItem(a) {
|
|
40
|
+
return this._validatorMap.get(a);
|
|
41
|
+
}
|
|
42
|
+
getValidatorsByScope(a) {
|
|
43
|
+
return this._validatorByScopes.get(a);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
var X = Object.defineProperty, Y = Object.getOwnPropertyDescriptor, Z = (e, a, t, r) => {
|
|
47
|
+
for (var o = r > 1 ? void 0 : r ? Y(a, t) : a, n = e.length - 1, i; n >= 0; n--)
|
|
48
|
+
(i = e[n]) && (o = (r ? i(a, t, o) : i(o)) || o);
|
|
49
|
+
return r && o && X(a, t, o), o;
|
|
50
|
+
}, k = (e, a) => (t, r) => a(t, r, e);
|
|
51
|
+
let h = class extends U {
|
|
52
|
+
constructor(a) {
|
|
53
|
+
super();
|
|
54
|
+
c(this, "_model", /* @__PURE__ */ new Map());
|
|
55
|
+
c(this, "_managerCreator");
|
|
56
|
+
c(this, "_ruleChange$", new S());
|
|
57
|
+
c(this, "_validStatusChange$", new S());
|
|
58
|
+
c(this, "ruleChange$", this._ruleChange$.asObservable());
|
|
59
|
+
c(this, "ruleChangeDebounce$", this.ruleChange$.pipe(A(20)));
|
|
60
|
+
c(this, "validStatusChange$", this._validStatusChange$.asObservable().pipe(A(20)));
|
|
61
|
+
this._logService = a, this.disposeWithMe({
|
|
62
|
+
dispose: () => {
|
|
63
|
+
this._ruleChange$.complete(), this._validStatusChange$.complete();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
setManagerCreator(a) {
|
|
68
|
+
this._managerCreator = a;
|
|
69
|
+
}
|
|
70
|
+
ensureManager(a, t) {
|
|
71
|
+
this._model.has(a) || this._model.set(a, /* @__PURE__ */ new Map());
|
|
72
|
+
const r = this._model.get(a);
|
|
73
|
+
if (r.has(t))
|
|
74
|
+
return r.get(t);
|
|
75
|
+
const o = this._managerCreator(a, t);
|
|
76
|
+
return r.set(t, o), o;
|
|
77
|
+
}
|
|
78
|
+
addRule(a, t, r, o) {
|
|
79
|
+
try {
|
|
80
|
+
this.ensureManager(a, t).addRule(r, o), this._ruleChange$.next({
|
|
81
|
+
rule: r,
|
|
82
|
+
type: "add",
|
|
83
|
+
unitId: a,
|
|
84
|
+
subUnitId: t
|
|
85
|
+
});
|
|
86
|
+
} catch (n) {
|
|
87
|
+
this._logService.error(n);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
updateRule(a, t, r, o) {
|
|
91
|
+
try {
|
|
92
|
+
const i = this.ensureManager(a, t).updateRule(r, o);
|
|
93
|
+
this._ruleChange$.next({
|
|
94
|
+
rule: i,
|
|
95
|
+
type: "update",
|
|
96
|
+
unitId: a,
|
|
97
|
+
subUnitId: t
|
|
98
|
+
});
|
|
99
|
+
} catch (n) {
|
|
100
|
+
this._logService.error(n);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
removeRule(a, t, r) {
|
|
104
|
+
try {
|
|
105
|
+
const o = this.ensureManager(a, t), n = o.getRuleById(r);
|
|
106
|
+
o.removeRule(r), this._ruleChange$.next({
|
|
107
|
+
rule: n,
|
|
108
|
+
type: "remove",
|
|
109
|
+
unitId: a,
|
|
110
|
+
subUnitId: t
|
|
111
|
+
});
|
|
112
|
+
} catch (o) {
|
|
113
|
+
this._logService.error(o);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
getRuleById(a, t, r) {
|
|
117
|
+
return this.ensureManager(a, t).getRuleById(r);
|
|
118
|
+
}
|
|
119
|
+
getRuleIndex(a, t, r) {
|
|
120
|
+
return this.ensureManager(a, t).getRuleIndex(r);
|
|
121
|
+
}
|
|
122
|
+
getRules(a, t) {
|
|
123
|
+
return this.ensureManager(a, t).getDataValidations();
|
|
124
|
+
}
|
|
125
|
+
validator(a, t, r) {
|
|
126
|
+
const { unitId: o, subUnitId: n } = r;
|
|
127
|
+
return this.ensureManager(o, n).validator(a, t, r, (d) => {
|
|
128
|
+
this._validStatusChange$.next({
|
|
129
|
+
unitId: o,
|
|
130
|
+
subUnitId: n,
|
|
131
|
+
ruleId: t.uid,
|
|
132
|
+
status: d
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
getUnitRules(a) {
|
|
137
|
+
const t = this._model.get(a);
|
|
138
|
+
if (!t)
|
|
139
|
+
return [];
|
|
140
|
+
const r = [];
|
|
141
|
+
return t.forEach((o) => {
|
|
142
|
+
r.push([o.subUnitId, o.getDataValidations()]);
|
|
143
|
+
}), r;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
h = Z([
|
|
147
|
+
k(0, H)
|
|
148
|
+
], h);
|
|
149
|
+
const E = {
|
|
150
|
+
type: m.MUTATION,
|
|
151
|
+
id: "data-validation.mutation.addRule",
|
|
152
|
+
handler(e, a) {
|
|
153
|
+
if (!a)
|
|
154
|
+
return !1;
|
|
155
|
+
const { unitId: t, subUnitId: r, rule: o, index: n } = a, i = e.get(h);
|
|
156
|
+
return Array.isArray(o) ? o.forEach((d) => {
|
|
157
|
+
i.addRule(t, r, d, n);
|
|
158
|
+
}) : i.addRule(t, r, o, n), !0;
|
|
159
|
+
}
|
|
160
|
+
}, v = {
|
|
161
|
+
type: m.MUTATION,
|
|
162
|
+
id: "data-validation.mutation.removeRule",
|
|
163
|
+
handler(e, a) {
|
|
164
|
+
if (!a)
|
|
165
|
+
return !1;
|
|
166
|
+
const { unitId: t, subUnitId: r, ruleId: o } = a, n = e.get(h);
|
|
167
|
+
return Array.isArray(o) ? o.forEach((i) => {
|
|
168
|
+
n.removeRule(t, r, i);
|
|
169
|
+
}) : n.removeRule(t, r, o), !0;
|
|
170
|
+
}
|
|
171
|
+
}, g = {
|
|
172
|
+
type: m.MUTATION,
|
|
173
|
+
id: "data-validation.mutation.updateRule",
|
|
174
|
+
handler(e, a) {
|
|
175
|
+
if (!a)
|
|
176
|
+
return !1;
|
|
177
|
+
const { unitId: t, subUnitId: r, ruleId: o, payload: n } = a;
|
|
178
|
+
return e.get(h).updateRule(t, r, o, n), !0;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
function aa(e) {
|
|
182
|
+
return {
|
|
183
|
+
type: e.type,
|
|
184
|
+
operator: e.operator,
|
|
185
|
+
formula1: e.formula1,
|
|
186
|
+
formula2: e.formula2,
|
|
187
|
+
allowBlank: e.allowBlank
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function ta(e) {
|
|
191
|
+
return {
|
|
192
|
+
error: e.error,
|
|
193
|
+
errorStyle: e.errorStyle,
|
|
194
|
+
errorTitle: e.errorTitle,
|
|
195
|
+
imeMode: e.imeMode,
|
|
196
|
+
prompt: e.prompt,
|
|
197
|
+
promptTitle: e.promptTitle,
|
|
198
|
+
showDropDown: e.showDropDown,
|
|
199
|
+
showErrorMessage: e.showErrorMessage,
|
|
200
|
+
showInputMessage: e.showInputMessage,
|
|
201
|
+
renderMode: e.renderMode
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function Ra(e) {
|
|
205
|
+
const t = e.get(z).getSelectionRanges();
|
|
206
|
+
return {
|
|
207
|
+
uid: L.generateRandomId(6),
|
|
208
|
+
type: Q.DECIMAL,
|
|
209
|
+
operator: s.EQUAL,
|
|
210
|
+
formula1: "100",
|
|
211
|
+
ranges: t != null ? t : [{ startColumn: 0, endColumn: 0, startRow: 0, endRow: 0 }]
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
var p = /* @__PURE__ */ ((e) => (e[e.SETTING = 0] = "SETTING", e[e.RANGE = 1] = "RANGE", e[e.OPTIONS = 2] = "OPTIONS", e))(p || {});
|
|
215
|
+
const ea = {
|
|
216
|
+
type: m.COMMAND,
|
|
217
|
+
id: "data-validation.command.addRule",
|
|
218
|
+
async handler(e, a) {
|
|
219
|
+
if (!a)
|
|
220
|
+
return !1;
|
|
221
|
+
const { rule: t, unitId: r, subUnitId: o } = a, n = e.get(T), i = e.get(M), d = {
|
|
222
|
+
...a,
|
|
223
|
+
rule: {
|
|
224
|
+
...a.rule,
|
|
225
|
+
ranges: [a.rule.range]
|
|
226
|
+
}
|
|
227
|
+
}, l = [{
|
|
228
|
+
id: E.id,
|
|
229
|
+
params: d
|
|
230
|
+
}], u = [{
|
|
231
|
+
id: v.id,
|
|
232
|
+
params: {
|
|
233
|
+
unitId: r,
|
|
234
|
+
subUnitId: o,
|
|
235
|
+
ruleId: t.uid
|
|
236
|
+
}
|
|
237
|
+
}];
|
|
238
|
+
return i.pushUndoRedo({
|
|
239
|
+
unitID: r,
|
|
240
|
+
redoMutations: l,
|
|
241
|
+
undoMutations: u
|
|
242
|
+
}), await n.executeCommand(E.id, d), !0;
|
|
243
|
+
}
|
|
244
|
+
}, Va = (e, a) => {
|
|
245
|
+
const t = e.get(h), { unitId: r, subUnitId: o, ruleId: n } = a;
|
|
246
|
+
if (Array.isArray(n)) {
|
|
247
|
+
const d = n.map((l) => t.getRuleById(r, o, l)).filter(Boolean);
|
|
248
|
+
return [{
|
|
249
|
+
id: E.id,
|
|
250
|
+
params: {
|
|
251
|
+
unitId: r,
|
|
252
|
+
subUnitId: o,
|
|
253
|
+
rule: d
|
|
254
|
+
}
|
|
255
|
+
}];
|
|
256
|
+
}
|
|
257
|
+
return [{
|
|
258
|
+
id: E.id,
|
|
259
|
+
params: {
|
|
260
|
+
unitId: r,
|
|
261
|
+
subUnitId: o,
|
|
262
|
+
rule: {
|
|
263
|
+
...t.getRuleById(r, o, n)
|
|
264
|
+
},
|
|
265
|
+
index: t.getRuleIndex(r, o, n)
|
|
266
|
+
}
|
|
267
|
+
}];
|
|
268
|
+
}, ra = {
|
|
269
|
+
type: m.COMMAND,
|
|
270
|
+
id: "data-validation.command.removeRule",
|
|
271
|
+
handler(e, a) {
|
|
272
|
+
if (!a)
|
|
273
|
+
return !1;
|
|
274
|
+
const { unitId: t, subUnitId: r, ruleId: o } = a, n = e.get(T), i = e.get(M), d = e.get(h), l = [{
|
|
275
|
+
id: v.id,
|
|
276
|
+
params: a
|
|
277
|
+
}], u = [{
|
|
278
|
+
id: E.id,
|
|
279
|
+
params: {
|
|
280
|
+
unitId: t,
|
|
281
|
+
subUnitId: r,
|
|
282
|
+
rule: {
|
|
283
|
+
...d.getRuleById(t, r, o)
|
|
284
|
+
},
|
|
285
|
+
index: d.getRuleIndex(t, r, o)
|
|
286
|
+
}
|
|
287
|
+
}];
|
|
288
|
+
return i.pushUndoRedo({
|
|
289
|
+
undoMutations: u,
|
|
290
|
+
redoMutations: l,
|
|
291
|
+
unitID: a.unitId
|
|
292
|
+
}), n.executeCommand(v.id, a), !0;
|
|
293
|
+
}
|
|
294
|
+
}, oa = {
|
|
295
|
+
type: m.COMMAND,
|
|
296
|
+
id: "data-validation.command.updateDataValidationSetting",
|
|
297
|
+
handler(e, a) {
|
|
298
|
+
if (!a)
|
|
299
|
+
return !1;
|
|
300
|
+
const t = e.get(T), r = e.get(M), o = e.get(h), { unitId: n, subUnitId: i, ruleId: d, options: l } = a, u = o.getRuleById(n, i, d);
|
|
301
|
+
if (!u)
|
|
302
|
+
return !1;
|
|
303
|
+
const _ = {
|
|
304
|
+
unitId: n,
|
|
305
|
+
subUnitId: i,
|
|
306
|
+
ruleId: d,
|
|
307
|
+
payload: {
|
|
308
|
+
type: p.OPTIONS,
|
|
309
|
+
payload: l
|
|
310
|
+
}
|
|
311
|
+
}, f = [{
|
|
312
|
+
id: g.id,
|
|
313
|
+
params: _
|
|
314
|
+
}], R = {
|
|
315
|
+
unitId: n,
|
|
316
|
+
subUnitId: i,
|
|
317
|
+
ruleId: d,
|
|
318
|
+
payload: {
|
|
319
|
+
type: p.OPTIONS,
|
|
320
|
+
payload: ta(u)
|
|
321
|
+
}
|
|
322
|
+
}, V = [{
|
|
323
|
+
id: g.id,
|
|
324
|
+
params: R
|
|
325
|
+
}];
|
|
326
|
+
return r.pushUndoRedo({
|
|
327
|
+
unitID: n,
|
|
328
|
+
redoMutations: f,
|
|
329
|
+
undoMutations: V
|
|
330
|
+
}), t.executeCommand(g.id, _), !0;
|
|
331
|
+
}
|
|
332
|
+
}, na = {
|
|
333
|
+
type: m.COMMAND,
|
|
334
|
+
id: "data-validation.command.updateDataValidationOptions",
|
|
335
|
+
handler(e, a) {
|
|
336
|
+
if (!a)
|
|
337
|
+
return !1;
|
|
338
|
+
const t = e.get(T), r = e.get(M), o = e.get(h), n = e.get(b), { unitId: i, subUnitId: d, ruleId: l, setting: u } = a, _ = n.getValidatorItem(u.type);
|
|
339
|
+
if (!_ || !_.validatorFormula(u).success)
|
|
340
|
+
return !1;
|
|
341
|
+
const f = o.getRuleById(i, d, l);
|
|
342
|
+
if (!f)
|
|
343
|
+
return !1;
|
|
344
|
+
const R = {
|
|
345
|
+
unitId: i,
|
|
346
|
+
subUnitId: d,
|
|
347
|
+
ruleId: l,
|
|
348
|
+
payload: {
|
|
349
|
+
type: p.SETTING,
|
|
350
|
+
payload: u
|
|
351
|
+
}
|
|
352
|
+
}, V = [{
|
|
353
|
+
id: g.id,
|
|
354
|
+
params: R
|
|
355
|
+
}], $ = {
|
|
356
|
+
unitId: i,
|
|
357
|
+
subUnitId: d,
|
|
358
|
+
ruleId: l,
|
|
359
|
+
payload: {
|
|
360
|
+
type: p.SETTING,
|
|
361
|
+
payload: aa(f)
|
|
362
|
+
}
|
|
363
|
+
}, x = [{
|
|
364
|
+
id: g.id,
|
|
365
|
+
params: $
|
|
366
|
+
}];
|
|
367
|
+
return r.pushUndoRedo({
|
|
368
|
+
unitID: i,
|
|
369
|
+
redoMutations: V,
|
|
370
|
+
undoMutations: x
|
|
371
|
+
}), t.executeCommand(g.id, R), !0;
|
|
372
|
+
}
|
|
373
|
+
}, ia = {
|
|
374
|
+
type: m.COMMAND,
|
|
375
|
+
id: "data-validation.command.removeAll",
|
|
376
|
+
handler(e, a) {
|
|
377
|
+
if (!a)
|
|
378
|
+
return !1;
|
|
379
|
+
const { unitId: t, subUnitId: r } = a, o = e.get(T), n = e.get(h), i = e.get(M), d = [...n.getRules(t, r)], l = {
|
|
380
|
+
unitId: t,
|
|
381
|
+
subUnitId: r,
|
|
382
|
+
ruleId: d.map((f) => f.uid)
|
|
383
|
+
}, u = [{
|
|
384
|
+
id: v.id,
|
|
385
|
+
params: l
|
|
386
|
+
}], _ = [{
|
|
387
|
+
id: E.id,
|
|
388
|
+
params: {
|
|
389
|
+
unitId: t,
|
|
390
|
+
subUnitId: r,
|
|
391
|
+
rule: d
|
|
392
|
+
}
|
|
393
|
+
}];
|
|
394
|
+
return i.pushUndoRedo({
|
|
395
|
+
redoMutations: u,
|
|
396
|
+
undoMutations: _,
|
|
397
|
+
unitID: t
|
|
398
|
+
}), o.executeCommand(v.id, l), !0;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
var sa = Object.defineProperty, da = Object.getOwnPropertyDescriptor, la = (e, a, t, r) => {
|
|
402
|
+
for (var o = r > 1 ? void 0 : r ? da(a, t) : a, n = e.length - 1, i; n >= 0; n--)
|
|
403
|
+
(i = e[n]) && (o = (r ? i(a, t, o) : i(o)) || o);
|
|
404
|
+
return r && o && sa(a, t, o), o;
|
|
405
|
+
}, N = (e, a) => (t, r) => a(t, r, e);
|
|
406
|
+
const ua = "data-validation";
|
|
407
|
+
let O = class extends W {
|
|
408
|
+
constructor(e, a) {
|
|
409
|
+
super(ua), this._injector = e, this._commandService = a;
|
|
410
|
+
}
|
|
411
|
+
onStarting(e) {
|
|
412
|
+
[
|
|
413
|
+
// model
|
|
414
|
+
[h],
|
|
415
|
+
// service
|
|
416
|
+
[b]
|
|
417
|
+
].forEach(
|
|
418
|
+
(a) => {
|
|
419
|
+
e.add(a);
|
|
420
|
+
}
|
|
421
|
+
), [
|
|
422
|
+
// command
|
|
423
|
+
ea,
|
|
424
|
+
ia,
|
|
425
|
+
oa,
|
|
426
|
+
na,
|
|
427
|
+
ra,
|
|
428
|
+
// mutation
|
|
429
|
+
E,
|
|
430
|
+
g,
|
|
431
|
+
v
|
|
432
|
+
].forEach((a) => {
|
|
433
|
+
this._commandService.registerCommand(a);
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
O = la([
|
|
438
|
+
N(0, I(B)),
|
|
439
|
+
N(1, T)
|
|
440
|
+
], O);
|
|
441
|
+
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 + "";
|
|
442
|
+
const ca = {
|
|
443
|
+
[s.BETWEEN]: "dataValidation.ruleName.between",
|
|
444
|
+
[s.EQUAL]: "dataValidation.ruleName.equal",
|
|
445
|
+
[s.GREATER_THAN]: "dataValidation.ruleName.greaterThan",
|
|
446
|
+
[s.GREATER_THAN_OR_EQUAL]: "dataValidation.ruleName.greaterThanOrEqual",
|
|
447
|
+
[s.LESS_THAN]: "dataValidation.ruleName.lessThan",
|
|
448
|
+
[s.LESS_THAN_OR_EQUAL]: "dataValidation.ruleName.lessThanOrEqual",
|
|
449
|
+
[s.NOT_BETWEEN]: "dataValidation.ruleName.notBetween",
|
|
450
|
+
[s.NOT_EQUAL]: "dataValidation.ruleName.notEqual"
|
|
451
|
+
}, ha = {
|
|
452
|
+
[s.BETWEEN]: "dataValidation.errorMsg.between",
|
|
453
|
+
[s.EQUAL]: "dataValidation.errorMsg.equal",
|
|
454
|
+
[s.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
|
|
455
|
+
[s.GREATER_THAN_OR_EQUAL]: "dataValidation.errorMsg.greaterThanOrEqual",
|
|
456
|
+
[s.LESS_THAN]: "dataValidation.errorMsg.lessThan",
|
|
457
|
+
[s.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
|
|
458
|
+
[s.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
|
|
459
|
+
[s.NOT_EQUAL]: "dataValidation.errorMsg.notEqual"
|
|
460
|
+
};
|
|
461
|
+
var pa = Object.defineProperty, ma = Object.getOwnPropertyDescriptor, _a = (e, a, t, r) => {
|
|
462
|
+
for (var o = r > 1 ? void 0 : r ? ma(a, t) : a, n = e.length - 1, i; n >= 0; n--)
|
|
463
|
+
(i = e[n]) && (o = (r ? i(a, t, o) : i(o)) || o);
|
|
464
|
+
return r && o && pa(a, t, o), o;
|
|
465
|
+
}, y = (e, a) => (t, r) => a(t, r, e);
|
|
466
|
+
const w = "{FORMULA1}", C = "{FORMULA2}", ga = {
|
|
467
|
+
[s.BETWEEN]: "dataValidation.operators.between",
|
|
468
|
+
[s.EQUAL]: "dataValidation.operators.equal",
|
|
469
|
+
[s.GREATER_THAN]: "dataValidation.operators.greaterThan",
|
|
470
|
+
[s.GREATER_THAN_OR_EQUAL]: "dataValidation.operators.greaterThanOrEqual",
|
|
471
|
+
[s.LESS_THAN]: "dataValidation.operators.lessThan",
|
|
472
|
+
[s.LESS_THAN_OR_EQUAL]: "dataValidation.operators.lessThanOrEqual",
|
|
473
|
+
[s.NOT_BETWEEN]: "dataValidation.operators.notBetween",
|
|
474
|
+
[s.NOT_EQUAL]: "dataValidation.operators.notEqual"
|
|
475
|
+
};
|
|
476
|
+
let D = class {
|
|
477
|
+
constructor(e, a) {
|
|
478
|
+
c(this, "canvasRender", null);
|
|
479
|
+
c(this, "dropdown");
|
|
480
|
+
c(this, "optionsInput");
|
|
481
|
+
this.localeService = e, this.injector = a;
|
|
482
|
+
}
|
|
483
|
+
get operatorNames() {
|
|
484
|
+
return this.operators.map((e) => this.localeService.t(ga[e]));
|
|
485
|
+
}
|
|
486
|
+
get titleStr() {
|
|
487
|
+
return this.localeService.t(this.title);
|
|
488
|
+
}
|
|
489
|
+
skipDefaultFontRender(e, a, t) {
|
|
490
|
+
return !1;
|
|
491
|
+
}
|
|
492
|
+
generateRuleName(e) {
|
|
493
|
+
var t, r;
|
|
494
|
+
if (!e.operator)
|
|
495
|
+
return this.titleStr;
|
|
496
|
+
const a = this.localeService.t(ca[e.operator]).replace(w, (t = e.formula1) != null ? t : "").replace(C, (r = e.formula2) != null ? r : "");
|
|
497
|
+
return `${this.titleStr} ${a}`;
|
|
498
|
+
}
|
|
499
|
+
generateRuleErrorMessage(e) {
|
|
500
|
+
var t, r;
|
|
501
|
+
return e.operator ? `${this.localeService.t(ha[e.operator]).replace(w, (t = e.formula1) != null ? t : "").replace(C, (r = e.formula2) != null ? r : "")}` : this.titleStr;
|
|
502
|
+
}
|
|
503
|
+
getRuleFinalError(e) {
|
|
504
|
+
return e.showInputMessage && e.error ? e.error : this.generateRuleErrorMessage(e);
|
|
505
|
+
}
|
|
506
|
+
isEmptyCellValue(e) {
|
|
507
|
+
return e === "" || e === void 0 || e === null;
|
|
508
|
+
}
|
|
509
|
+
async isValidType(e, a, t) {
|
|
510
|
+
return !0;
|
|
511
|
+
}
|
|
512
|
+
transform(e, a, t) {
|
|
513
|
+
return e;
|
|
514
|
+
}
|
|
515
|
+
async validatorIsEqual(e, a, t) {
|
|
516
|
+
return !0;
|
|
517
|
+
}
|
|
518
|
+
async validatorIsNotEqual(e, a, t) {
|
|
519
|
+
return !0;
|
|
520
|
+
}
|
|
521
|
+
async validatorIsBetween(e, a, t) {
|
|
522
|
+
return !0;
|
|
523
|
+
}
|
|
524
|
+
async validatorIsNotBetween(e, a, t) {
|
|
525
|
+
return !0;
|
|
526
|
+
}
|
|
527
|
+
async validatorIsGreaterThan(e, a, t) {
|
|
528
|
+
return !0;
|
|
529
|
+
}
|
|
530
|
+
async validatorIsGreaterThanOrEqual(e, a, t) {
|
|
531
|
+
return !0;
|
|
532
|
+
}
|
|
533
|
+
async validatorIsLessThan(e, a, t) {
|
|
534
|
+
return !0;
|
|
535
|
+
}
|
|
536
|
+
async validatorIsLessThanOrEqual(e, a, t) {
|
|
537
|
+
return !0;
|
|
538
|
+
}
|
|
539
|
+
async validator(e, a) {
|
|
540
|
+
const { value: t, unitId: r, subUnitId: o } = e, n = this.isEmptyCellValue(t), { allowBlank: i = !0, operator: d } = a;
|
|
541
|
+
if (n)
|
|
542
|
+
return i;
|
|
543
|
+
const l = await this.parseFormula(a, r, o);
|
|
544
|
+
if (!await this.isValidType(e, l, a))
|
|
545
|
+
return !1;
|
|
546
|
+
if (!L.isDefine(d))
|
|
547
|
+
return !0;
|
|
548
|
+
const u = this.transform(e, l, a);
|
|
549
|
+
switch (d) {
|
|
550
|
+
case s.BETWEEN:
|
|
551
|
+
return this.validatorIsBetween(u, l, a);
|
|
552
|
+
case s.EQUAL:
|
|
553
|
+
return this.validatorIsEqual(u, l, a);
|
|
554
|
+
case s.GREATER_THAN:
|
|
555
|
+
return this.validatorIsGreaterThan(u, l, a);
|
|
556
|
+
case s.GREATER_THAN_OR_EQUAL:
|
|
557
|
+
return this.validatorIsGreaterThanOrEqual(u, l, a);
|
|
558
|
+
case s.LESS_THAN:
|
|
559
|
+
return this.validatorIsLessThan(u, l, a);
|
|
560
|
+
case s.LESS_THAN_OR_EQUAL:
|
|
561
|
+
return this.validatorIsLessThanOrEqual(u, l, a);
|
|
562
|
+
case s.NOT_BETWEEN:
|
|
563
|
+
return this.validatorIsNotBetween(u, l, a);
|
|
564
|
+
case s.NOT_EQUAL:
|
|
565
|
+
return this.validatorIsNotEqual(u, l, a);
|
|
566
|
+
default:
|
|
567
|
+
throw new Error("Unknown operator.");
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
D = _a([
|
|
572
|
+
y(0, I(j)),
|
|
573
|
+
y(1, I(B))
|
|
574
|
+
], D);
|
|
575
|
+
class Ia extends U {
|
|
576
|
+
constructor(t, r, o) {
|
|
577
|
+
super();
|
|
578
|
+
c(this, "_dataValidations");
|
|
579
|
+
c(this, "_dataValidationMap", /* @__PURE__ */ new Map());
|
|
580
|
+
c(this, "_dataValidations$", new S());
|
|
581
|
+
c(this, "unitId");
|
|
582
|
+
c(this, "subUnitId");
|
|
583
|
+
c(this, "dataValidations$", this._dataValidations$.asObservable());
|
|
584
|
+
this.unitId = t, this.subUnitId = r, o && (this._insertRules(o), this._notice(), this.disposeWithMe({
|
|
585
|
+
dispose: () => {
|
|
586
|
+
this._dataValidations$.complete();
|
|
587
|
+
}
|
|
588
|
+
}));
|
|
589
|
+
}
|
|
590
|
+
_notice() {
|
|
591
|
+
this._dataValidations$.next(this._dataValidations);
|
|
592
|
+
}
|
|
593
|
+
_insertRules(t) {
|
|
594
|
+
this._dataValidations = t, t.forEach((r) => {
|
|
595
|
+
this._dataValidationMap.set(r.uid, r);
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
getRuleById(t) {
|
|
599
|
+
return this._dataValidationMap.get(t);
|
|
600
|
+
}
|
|
601
|
+
getRuleIndex(t) {
|
|
602
|
+
return this._dataValidations.findIndex((r) => r.uid === t);
|
|
603
|
+
}
|
|
604
|
+
addRule(t, r) {
|
|
605
|
+
typeof r == "number" && r < this._dataValidations.length ? this._dataValidations.splice(r, 0, t) : this._dataValidations.push(t), this._dataValidationMap.set(t.uid, t), this._notice();
|
|
606
|
+
}
|
|
607
|
+
removeRule(t) {
|
|
608
|
+
const r = this._dataValidations.findIndex((o) => o.uid === t);
|
|
609
|
+
this._dataValidations.splice(r, 1), this._dataValidationMap.delete(t), this._notice();
|
|
610
|
+
}
|
|
611
|
+
updateRule(t, r) {
|
|
612
|
+
const o = this._dataValidationMap.get(t), n = this._dataValidations.findIndex((d) => t === d.uid);
|
|
613
|
+
if (!o)
|
|
614
|
+
throw new Error(`Data validation rule is not found, ruleId: ${t}.`);
|
|
615
|
+
const i = { ...o };
|
|
616
|
+
switch (r.type) {
|
|
617
|
+
case p.RANGE: {
|
|
618
|
+
i.ranges = r.payload;
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
case p.SETTING: {
|
|
622
|
+
Object.assign(i, r.payload);
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
case p.OPTIONS: {
|
|
626
|
+
Object.assign(i, r.payload);
|
|
627
|
+
break;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return this._dataValidations[n] = i, this._dataValidationMap.set(t, i), this._notice(), i;
|
|
631
|
+
}
|
|
632
|
+
getDataValidations() {
|
|
633
|
+
return this._dataValidations;
|
|
634
|
+
}
|
|
635
|
+
toJSON() {
|
|
636
|
+
return this._dataValidations;
|
|
637
|
+
}
|
|
638
|
+
validator(t, r, o, n) {
|
|
639
|
+
return F.VALID;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
const Sa = [
|
|
643
|
+
s.BETWEEN,
|
|
644
|
+
s.NOT_BETWEEN
|
|
645
|
+
];
|
|
646
|
+
export {
|
|
647
|
+
ea as AddDataValidationCommand,
|
|
648
|
+
E as AddDataValidationMutation,
|
|
649
|
+
D as BaseDataValidator,
|
|
650
|
+
Ia as DataValidationManager,
|
|
651
|
+
h as DataValidationModel,
|
|
652
|
+
K as DataValidatorRegistryScope,
|
|
653
|
+
b as DataValidatorRegistryService,
|
|
654
|
+
ia as RemoveAllDataValidationCommand,
|
|
655
|
+
ra as RemoveDataValidationCommand,
|
|
656
|
+
v as RemoveDataValidationMutation,
|
|
657
|
+
Sa as TWO_FORMULA_OPERATOR_COUNT,
|
|
658
|
+
O as UniverDataValidationPlugin,
|
|
659
|
+
g as UpdateDataValidationMutation,
|
|
660
|
+
oa as UpdateDataValidationOptionsCommand,
|
|
661
|
+
na as UpdateDataValidationSettingCommand,
|
|
662
|
+
p as UpdateRuleType,
|
|
663
|
+
Ra as createDefaultNewRule,
|
|
664
|
+
ta as getRuleOptions,
|
|
665
|
+
aa as getRuleSetting,
|
|
666
|
+
Va as removeDataValidationUndoFactory
|
|
667
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IRemoveDataValidationMutationParams } from '../mutations/data-validation.mutation';
|
|
2
|
+
import { ISheetCommandSharedParams } from '@univerjs/sheets';
|
|
3
|
+
import { Injector } from '@wendellhu/redi';
|
|
4
|
+
import { ICommand, IDataValidationRule, IDataValidationRuleBase, IDataValidationRuleOptions, IMutationInfo, IRange } from '@univerjs/core';
|
|
5
|
+
|
|
6
|
+
export interface IAddDataValidationCommandParams extends ISheetCommandSharedParams {
|
|
7
|
+
rule: Omit<IDataValidationRule, 'ranges'> & {
|
|
8
|
+
range: IRange;
|
|
9
|
+
};
|
|
10
|
+
index?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const AddDataValidationCommand: ICommand<IAddDataValidationCommandParams>;
|
|
13
|
+
export interface IRemoveDataValidationCommandParams extends ISheetCommandSharedParams {
|
|
14
|
+
ruleId: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const removeDataValidationUndoFactory: (accessor: Injector, redoParams: IRemoveDataValidationMutationParams) => IMutationInfo<object>[];
|
|
17
|
+
export declare const RemoveDataValidationCommand: ICommand<IRemoveDataValidationCommandParams>;
|
|
18
|
+
export interface IUpdateDataValidationOptionsCommandParams extends ISheetCommandSharedParams {
|
|
19
|
+
ruleId: string;
|
|
20
|
+
options: IDataValidationRuleOptions;
|
|
21
|
+
}
|
|
22
|
+
export declare const UpdateDataValidationOptionsCommand: ICommand<IUpdateDataValidationOptionsCommandParams>;
|
|
23
|
+
export interface IUpdateDataValidationSettingCommandParams extends ISheetCommandSharedParams {
|
|
24
|
+
ruleId: string;
|
|
25
|
+
setting: IDataValidationRuleBase;
|
|
26
|
+
}
|
|
27
|
+
export declare const UpdateDataValidationSettingCommand: ICommand<IUpdateDataValidationSettingCommandParams>;
|
|
28
|
+
export interface IRemoveAllDataValidationCommandParams extends ISheetCommandSharedParams {
|
|
29
|
+
}
|
|
30
|
+
export declare const RemoveAllDataValidationCommand: ICommand<IRemoveAllDataValidationCommandParams>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IUpdateRulePayload } from '../../types/interfaces/i-update-rule-payload';
|
|
2
|
+
import { ISheetCommandSharedParams } from '@univerjs/sheets';
|
|
3
|
+
import { ICommand, IDataValidationRule } from '@univerjs/core';
|
|
4
|
+
|
|
5
|
+
export interface IAddDataValidationMutationParams extends ISheetCommandSharedParams {
|
|
6
|
+
rule: IDataValidationRule | IDataValidationRule[];
|
|
7
|
+
index?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const AddDataValidationMutation: ICommand<IAddDataValidationMutationParams>;
|
|
10
|
+
export interface IRemoveDataValidationMutationParams extends ISheetCommandSharedParams {
|
|
11
|
+
ruleId: string | string[];
|
|
12
|
+
}
|
|
13
|
+
export declare const RemoveDataValidationMutation: ICommand<IRemoveDataValidationMutationParams>;
|
|
14
|
+
export interface IUpdateDataValidationMutationParams extends ISheetCommandSharedParams {
|
|
15
|
+
payload: IUpdateRulePayload;
|
|
16
|
+
ruleId: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const UpdateDataValidationMutation: ICommand<IUpdateDataValidationMutationParams>;
|