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