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