@univerjs/sheets-data-validation 0.6.3 → 0.6.4
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/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +142 -141
- package/lib/es/index.js +64 -48
- package/lib/types/services/dv-cache.service.d.ts +2 -1
- package/lib/types/services/dv-custom-formula.service.d.ts +3 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
package/lib/es/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var ft = Object.defineProperty;
|
|
2
2
|
var vt = (o, a, e) => a in o ? ft(o, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[a] = e;
|
|
3
3
|
var g = (o, a, e) => vt(o, typeof a != "symbol" ? a + "" : a, e);
|
|
4
|
-
import { Inject as R, ICommandService as x, IUniverInstanceService as w, Disposable as W, ObjectMatrix as Se, UniverInstanceType as N, Range as b, isFormulaString as S, DataValidationType as T, getOriginCellValue as Rt, RBush as St, debounce as Vt,
|
|
4
|
+
import { Inject as R, ICommandService as x, IUniverInstanceService as w, Disposable as W, ObjectMatrix as Se, UniverInstanceType as N, Range as b, Rectangle as I, isFormulaString as S, DataValidationType as T, getOriginCellValue as Rt, RBush as St, debounce as Vt, Tools as V, DataValidationStatus as D, WrapStrategy as Re, DataValidationOperator as h, numfmt as j, dayjs as at, DataValidationRenderMode as Be, CommandType as z, IUndoRedoService as Z, sequenceExecute as Ie, isRangesEqual as rt, generateRandomId as Mt, toDisposable as Qe, IPermissionService as yt, Injector as qe, CellValueType as Et, RxDisposable as Tt, LifecycleService as Ft, LifecycleStages as ze, bufferDebounceTime as Nt, DependentOn as Ct, IConfigService as wt, Plugin as Ot, merge as It } from "@univerjs/core";
|
|
5
5
|
import { DataValidationModel as Ge, DataValidatorRegistryService as q, UpdateRuleType as y, BaseDataValidator as G, TextLengthErrorTitleMap as At, AddDataValidationMutation as L, RemoveDataValidationMutation as A, UpdateDataValidationMutation as E, getRuleSetting as Dt, getRuleOptions as bt, UniverDataValidationPlugin as Lt } from "@univerjs/data-validation";
|
|
6
6
|
import { SetRangeValuesMutation as se, RemoveSheetMutation as it, getSheetCommandTarget as Ye, SetRangeValuesUndoMutationFactory as ot, WorksheetViewPermission as xt, RefRangeService as Bt, handleCommonDefaultRangeChangeWithEffectRefCommands as Ut, SheetInterceptorService as st, RemoveSheetCommand as Ht, SheetsSelectionsService as nt, ClearSelectionAllCommand as Wt } from "@univerjs/sheets";
|
|
7
7
|
import { Subject as je, bufferWhen as Pt, filter as Ze } from "rxjs";
|
|
@@ -28,7 +28,7 @@ let Q = class extends W {
|
|
|
28
28
|
if (e) {
|
|
29
29
|
const i = new Se(e).getDataRange();
|
|
30
30
|
if (i.endRow === -1) return;
|
|
31
|
-
this.markRangeDirty(t, r, [i]);
|
|
31
|
+
this.markRangeDirty(t, r, [i], !0);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
}));
|
|
@@ -59,13 +59,13 @@ let Q = class extends W {
|
|
|
59
59
|
removeRule(a, e, t) {
|
|
60
60
|
this._deleteRange(a, e, t.ranges);
|
|
61
61
|
}
|
|
62
|
-
markRangeDirty(a, e, t) {
|
|
63
|
-
const
|
|
64
|
-
t.forEach((
|
|
65
|
-
b.foreach(
|
|
66
|
-
|
|
62
|
+
markRangeDirty(a, e, t, r) {
|
|
63
|
+
const i = this._ensureCache(a, e);
|
|
64
|
+
t.forEach((s) => {
|
|
65
|
+
b.foreach(s, (n, l) => {
|
|
66
|
+
i.setValue(n, l, void 0);
|
|
67
67
|
});
|
|
68
|
-
}), this._dirtyRanges$.next({ unitId: a, subUnitId: e, ranges: t });
|
|
68
|
+
}), this._dirtyRanges$.next({ unitId: a, subUnitId: e, ranges: t, isSetRange: r });
|
|
69
69
|
}
|
|
70
70
|
_deleteRange(a, e, t) {
|
|
71
71
|
const r = this._ensureCache(a, e);
|
|
@@ -112,7 +112,7 @@ let H = class extends W {
|
|
|
112
112
|
*/
|
|
113
113
|
g(this, "_ruleFormulaMap", /* @__PURE__ */ new Map());
|
|
114
114
|
g(this, "_ruleFormulaMap2", /* @__PURE__ */ new Map());
|
|
115
|
-
this._instanceSrv = a, this._registerOtherFormulaService = e, this._dataValidationModel = t, this._dataValidationCacheService = r, this._validatorRegistryService = i, this._initFormulaResultHandler();
|
|
115
|
+
this._instanceSrv = a, this._registerOtherFormulaService = e, this._dataValidationModel = t, this._dataValidationCacheService = r, this._validatorRegistryService = i, this._initFormulaResultHandler(), this._initDirtyRanges();
|
|
116
116
|
}
|
|
117
117
|
_initFormulaResultHandler() {
|
|
118
118
|
this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe((a) => {
|
|
@@ -141,6 +141,17 @@ let H = class extends W {
|
|
|
141
141
|
_registerFormula(a, e, t, r, i) {
|
|
142
142
|
return this._registerOtherFormulaService.registerFormulaWithRange(a, e, r, i, { ruleId: t });
|
|
143
143
|
}
|
|
144
|
+
_handleDirtyRanges(a, e, t) {
|
|
145
|
+
this._dataValidationModel.getRules(a, e).forEach((i) => {
|
|
146
|
+
const s = i.ranges;
|
|
147
|
+
I.doAnyRangesIntersect(s, t) && this.makeRuleDirty(a, e, i.uid);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
_initDirtyRanges() {
|
|
151
|
+
this._dataValidationCacheService.dirtyRanges$.subscribe((a) => {
|
|
152
|
+
a.isSetRange && this._handleDirtyRanges(a.unitId, a.subUnitId, a.ranges);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
144
155
|
deleteByRuleId(a, e, t) {
|
|
145
156
|
const { ruleFormulaMap: r, ruleFormulaMap2: i } = this._ensureMaps(a, e), s = this._dataValidationModel.getRuleById(a, e, t), n = r.get(t);
|
|
146
157
|
if (!s || !n)
|
|
@@ -213,6 +224,11 @@ let H = class extends W {
|
|
|
213
224
|
const { ruleFormulaMap: r } = this._ensureMaps(a, e);
|
|
214
225
|
return r.get(t);
|
|
215
226
|
}
|
|
227
|
+
makeRuleDirty(a, e, t) {
|
|
228
|
+
var s, n, l, u;
|
|
229
|
+
const r = (n = (s = this._ruleFormulaMap.get(a)) == null ? void 0 : s.get(e)) == null ? void 0 : n.get(t), i = (u = (l = this._ruleFormulaMap2.get(a)) == null ? void 0 : l.get(e)) == null ? void 0 : u.get(t);
|
|
230
|
+
r && this._registerOtherFormulaService.markFormulaDirty(a, e, r.formulaId), i && this._registerOtherFormulaService.markFormulaDirty(a, e, i.formulaId);
|
|
231
|
+
}
|
|
216
232
|
};
|
|
217
233
|
H = zt([
|
|
218
234
|
re(0, w),
|
|
@@ -352,9 +368,9 @@ class Xe {
|
|
|
352
368
|
_addRule(a, e) {
|
|
353
369
|
if (!this._worksheet)
|
|
354
370
|
return;
|
|
355
|
-
const t =
|
|
371
|
+
const t = I.mergeRanges(e.map((r) => b.transformRange(r, this._worksheet)));
|
|
356
372
|
this._map.forEach((r, i) => {
|
|
357
|
-
const s =
|
|
373
|
+
const s = I.subtractMulti(r, t);
|
|
358
374
|
s.length === 0 ? this._map.delete(i) : this._map.set(i, s);
|
|
359
375
|
}), this._dirty = !0, this._map.set(a, t), this._debonceBuildTree();
|
|
360
376
|
}
|
|
@@ -366,7 +382,7 @@ class Xe {
|
|
|
366
382
|
return;
|
|
367
383
|
const e = a.map((t) => b.transformRange(t, this._worksheet));
|
|
368
384
|
this._map.forEach((t, r) => {
|
|
369
|
-
const i =
|
|
385
|
+
const i = I.subtractMulti(t, e);
|
|
370
386
|
i.length === 0 ? this._map.delete(r) : this._map.set(r, i);
|
|
371
387
|
}), this._dirty = !0, this._debonceBuildTree();
|
|
372
388
|
}
|
|
@@ -384,10 +400,10 @@ class Xe {
|
|
|
384
400
|
if (!t.length)
|
|
385
401
|
return;
|
|
386
402
|
let r = this._map.get(e);
|
|
387
|
-
r ? (this._map.set(e,
|
|
403
|
+
r ? (this._map.set(e, I.mergeRanges([...r, ...t])), r = this._map.get(e)) : (r = t, this._map.set(e, r)), this._map.forEach((i, s) => {
|
|
388
404
|
if (s === e)
|
|
389
405
|
return;
|
|
390
|
-
const n =
|
|
406
|
+
const n = I.subtractMulti(i, t);
|
|
391
407
|
n.length === 0 ? this._map.delete(s) : this._map.set(s, n);
|
|
392
408
|
});
|
|
393
409
|
}), this._dirty = !0, this._debonceBuildTree();
|
|
@@ -398,11 +414,11 @@ class Xe {
|
|
|
398
414
|
return a.forEach((r, i) => {
|
|
399
415
|
var l;
|
|
400
416
|
const s = (l = this._map.get(r.uid)) != null ? l : [], n = r.ranges;
|
|
401
|
-
s.length !== 0 && (s.length !== n.length || s.some((u, d) => !
|
|
417
|
+
s.length !== 0 && (s.length !== n.length || s.some((u, d) => !I.equals(u, n[d]))) && e.push({
|
|
402
418
|
type: "update",
|
|
403
419
|
ruleId: r.uid,
|
|
404
420
|
oldRanges: n,
|
|
405
|
-
newRanges:
|
|
421
|
+
newRanges: I.sort(s),
|
|
406
422
|
rule: r
|
|
407
423
|
}), s.length === 0 && (e.push({
|
|
408
424
|
type: "delete",
|
|
@@ -417,11 +433,11 @@ class Xe {
|
|
|
417
433
|
return a.forEach((i, s) => {
|
|
418
434
|
var u;
|
|
419
435
|
const n = (u = this._map.get(i.uid)) != null ? u : [], l = i.ranges;
|
|
420
|
-
n.length !== 0 && (n.length !== l.length || n.some((d, c) => !
|
|
436
|
+
n.length !== 0 && (n.length !== l.length || n.some((d, c) => !I.equals(d, l[c]))) && t.push({
|
|
421
437
|
type: "update",
|
|
422
438
|
ruleId: i.uid,
|
|
423
439
|
oldRanges: l,
|
|
424
|
-
newRanges:
|
|
440
|
+
newRanges: I.sort(n),
|
|
425
441
|
rule: i
|
|
426
442
|
}), n.length === 0 && (t.push({
|
|
427
443
|
type: "delete",
|
|
@@ -435,7 +451,7 @@ class Xe {
|
|
|
435
451
|
type: "add",
|
|
436
452
|
rule: {
|
|
437
453
|
...i,
|
|
438
|
-
ranges:
|
|
454
|
+
ranges: I.sort(s)
|
|
439
455
|
}
|
|
440
456
|
});
|
|
441
457
|
}), t;
|
|
@@ -585,8 +601,8 @@ let F = class extends W {
|
|
|
585
601
|
).then((M) => {
|
|
586
602
|
const f = M ? D.VALID : D.INVALID;
|
|
587
603
|
f === D.VALID ? _.realDeleteValue(i, r) : _.setValue(i, r, f);
|
|
588
|
-
const
|
|
589
|
-
u(f, v !==
|
|
604
|
+
const O = _.getValue(i, r);
|
|
605
|
+
u(f, v !== O);
|
|
590
606
|
}), D.VALIDATING) : (u(v != null ? v : D.VALID, !1), v != null ? v : D.VALID);
|
|
591
607
|
} else
|
|
592
608
|
return u(D.VALID, !1), D.VALID;
|
|
@@ -975,7 +991,7 @@ function da(o, a) {
|
|
|
975
991
|
const { formula1: e = "", ranges: t } = o;
|
|
976
992
|
if (dt(e.slice(1))) {
|
|
977
993
|
const i = jt(e.slice(1));
|
|
978
|
-
if ((!i.sheetName || i.sheetName === a) && t.some((s) =>
|
|
994
|
+
if ((!i.sheetName || i.sheetName === a) && t.some((s) => I.intersects(s, i.range)))
|
|
979
995
|
return !0;
|
|
980
996
|
}
|
|
981
997
|
return !1;
|
|
@@ -1150,12 +1166,12 @@ function be(o, a, e, t, r = "command", i = !0) {
|
|
|
1150
1166
|
};
|
|
1151
1167
|
const { worksheet: p } = m, _ = new Se();
|
|
1152
1168
|
let v = !1;
|
|
1153
|
-
function M(f,
|
|
1169
|
+
function M(f, O) {
|
|
1154
1170
|
i && f.forEach((P) => {
|
|
1155
1171
|
b.foreach(P, (B, $) => {
|
|
1156
1172
|
const U = p.getCellRaw(B, $), J = ct(U);
|
|
1157
|
-
(gt(U) || J ===
|
|
1158
|
-
v:
|
|
1173
|
+
(gt(U) || J === O) && !(U != null && U.p) && (v = !0, _.setValue(B, $, {
|
|
1174
|
+
v: O,
|
|
1159
1175
|
p: null
|
|
1160
1176
|
}));
|
|
1161
1177
|
});
|
|
@@ -1267,9 +1283,9 @@ function be(o, a, e, t, r = "command", i = !0) {
|
|
|
1267
1283
|
source: r
|
|
1268
1284
|
}
|
|
1269
1285
|
});
|
|
1270
|
-
const
|
|
1271
|
-
if (
|
|
1272
|
-
const B = d.getValidator(T.CHECKBOX).parseFormulaSync(
|
|
1286
|
+
const O = d.getRuleById(o, a, f.ruleId);
|
|
1287
|
+
if (O && O.type === T.CHECKBOX) {
|
|
1288
|
+
const B = d.getValidator(T.CHECKBOX).parseFormulaSync(O, o, a);
|
|
1273
1289
|
M(f.newRanges, B.formula2);
|
|
1274
1290
|
}
|
|
1275
1291
|
break;
|
|
@@ -1306,11 +1322,11 @@ function be(o, a, e, t, r = "command", i = !0) {
|
|
|
1306
1322
|
subUnitId: a,
|
|
1307
1323
|
cellValue: _.getData()
|
|
1308
1324
|
}
|
|
1309
|
-
},
|
|
1325
|
+
}, O = {
|
|
1310
1326
|
id: se.id,
|
|
1311
1327
|
params: ot(t, f.params)
|
|
1312
1328
|
};
|
|
1313
|
-
l.push(f), u.push(
|
|
1329
|
+
l.push(f), u.push(O);
|
|
1314
1330
|
}
|
|
1315
1331
|
return {
|
|
1316
1332
|
redoMutations: l,
|
|
@@ -1333,7 +1349,7 @@ const ha = {
|
|
|
1333
1349
|
undoMutations: p,
|
|
1334
1350
|
redoMutations: m,
|
|
1335
1351
|
unitID: e
|
|
1336
|
-
}),
|
|
1352
|
+
}), Ie(m, n), !0;
|
|
1337
1353
|
}
|
|
1338
1354
|
}, ma = {
|
|
1339
1355
|
type: z.COMMAND,
|
|
@@ -1365,7 +1381,7 @@ const ha = {
|
|
|
1365
1381
|
unitID: e,
|
|
1366
1382
|
redoMutations: m,
|
|
1367
1383
|
undoMutations: p
|
|
1368
|
-
}),
|
|
1384
|
+
}), Ie(m, s), !0;
|
|
1369
1385
|
}
|
|
1370
1386
|
}, ga = {
|
|
1371
1387
|
type: z.COMMAND,
|
|
@@ -1410,11 +1426,11 @@ const ha = {
|
|
|
1410
1426
|
params: v
|
|
1411
1427
|
}];
|
|
1412
1428
|
if (u.type === T.CHECKBOX) {
|
|
1413
|
-
const
|
|
1429
|
+
const O = c.ranges, P = o.get(w), B = Ye(P, { unitId: s, subUnitId: n });
|
|
1414
1430
|
if (B) {
|
|
1415
1431
|
const $ = new Se(), { worksheet: U } = B, { formula2: J = Me, formula1: ce = Ve } = c, { formula2: he = Me, formula1: me = Ve } = u;
|
|
1416
1432
|
let Le = !1;
|
|
1417
|
-
if (
|
|
1433
|
+
if (O.forEach((ge) => {
|
|
1418
1434
|
b.foreach(ge, (ae, xe) => {
|
|
1419
1435
|
const k = U.getCellRaw(ae, xe), Ke = ct(k);
|
|
1420
1436
|
(gt(k) || Ke === String(J)) && !(k != null && k.p) ? ($.setValue(ae, xe, {
|
|
@@ -1441,7 +1457,7 @@ const ha = {
|
|
|
1441
1457
|
}
|
|
1442
1458
|
}
|
|
1443
1459
|
}
|
|
1444
|
-
return
|
|
1460
|
+
return Ie(_, e).result ? (t.pushUndoRedo({
|
|
1445
1461
|
unitID: s,
|
|
1446
1462
|
redoMutations: _,
|
|
1447
1463
|
undoMutations: M
|
|
@@ -1500,7 +1516,7 @@ const ha = {
|
|
|
1500
1516
|
unitID: e,
|
|
1501
1517
|
redoMutations: m,
|
|
1502
1518
|
undoMutations: p
|
|
1503
|
-
}),
|
|
1519
|
+
}), Ie(m, i).result;
|
|
1504
1520
|
}
|
|
1505
1521
|
}, fa = {
|
|
1506
1522
|
type: z.COMMAND,
|
|
@@ -2031,7 +2047,7 @@ class wa extends G {
|
|
|
2031
2047
|
return this.localeService.t("dataValidation.any.error");
|
|
2032
2048
|
}
|
|
2033
2049
|
}
|
|
2034
|
-
class
|
|
2050
|
+
class Oa extends G {
|
|
2035
2051
|
constructor() {
|
|
2036
2052
|
super(...arguments);
|
|
2037
2053
|
g(this, "id", T.CUSTOM);
|
|
@@ -2068,7 +2084,7 @@ class Ia extends G {
|
|
|
2068
2084
|
return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}", (t = e.formula1) != null ? t : "");
|
|
2069
2085
|
}
|
|
2070
2086
|
}
|
|
2071
|
-
class
|
|
2087
|
+
class Ia extends mt {
|
|
2072
2088
|
constructor() {
|
|
2073
2089
|
super(...arguments);
|
|
2074
2090
|
g(this, "id", T.LIST_MULTIPLE);
|
|
@@ -2165,8 +2181,8 @@ let Ce = class extends Tt {
|
|
|
2165
2181
|
sa,
|
|
2166
2182
|
aa,
|
|
2167
2183
|
mt,
|
|
2168
|
-
|
|
2169
|
-
|
|
2184
|
+
Ia,
|
|
2185
|
+
Oa
|
|
2170
2186
|
].forEach((o) => {
|
|
2171
2187
|
const a = this._injector.createInstance(o);
|
|
2172
2188
|
this.disposeWithMe(this._dataValidatorRegistryService.register(a)), this.disposeWithMe(Qe(() => this._injector.delete(o)));
|
|
@@ -2313,10 +2329,10 @@ var Ba = Object.defineProperty, Ua = Object.getOwnPropertyDescriptor, Ha = (o, a
|
|
|
2313
2329
|
(s = o[i]) && (r = s(r) || r);
|
|
2314
2330
|
return r;
|
|
2315
2331
|
}, ke = (o, a) => (e, t) => a(e, t, o), pt = (o, a, e) => Ha(o, typeof a != "symbol" ? a + "" : a, e);
|
|
2316
|
-
let
|
|
2332
|
+
let Oe = class extends Ot {
|
|
2317
2333
|
constructor(o = tt, a, e, t) {
|
|
2318
2334
|
super(), this._config = o, this._injector = a, this._commandService = e, this._configService = t;
|
|
2319
|
-
const { ...r } =
|
|
2335
|
+
const { ...r } = It(
|
|
2320
2336
|
{},
|
|
2321
2337
|
tt,
|
|
2322
2338
|
this._config
|
|
@@ -2356,14 +2372,14 @@ let Ie = class extends It {
|
|
|
2356
2372
|
this._injector.get(Te);
|
|
2357
2373
|
}
|
|
2358
2374
|
};
|
|
2359
|
-
pt(
|
|
2360
|
-
pt(
|
|
2361
|
-
|
|
2375
|
+
pt(Oe, "pluginName", Gt);
|
|
2376
|
+
pt(Oe, "type", N.UNIVER_SHEET);
|
|
2377
|
+
Oe = Wa([
|
|
2362
2378
|
Ct(Lt),
|
|
2363
2379
|
ke(1, R(qe)),
|
|
2364
2380
|
ke(2, x),
|
|
2365
2381
|
ke(3, wt)
|
|
2366
|
-
],
|
|
2382
|
+
], Oe);
|
|
2367
2383
|
function Ka(o) {
|
|
2368
2384
|
const e = o.get(nt).getCurrentSelections().map((i) => i.range);
|
|
2369
2385
|
return {
|
|
@@ -2386,13 +2402,13 @@ export {
|
|
|
2386
2402
|
Te as DataValidationFormulaController,
|
|
2387
2403
|
K as DataValidationFormulaService,
|
|
2388
2404
|
sa as DateValidator,
|
|
2389
|
-
|
|
2405
|
+
Ia as ListMultipleValidator,
|
|
2390
2406
|
mt as ListValidator,
|
|
2391
2407
|
fa as RemoveSheetAllDataValidationCommand,
|
|
2392
2408
|
Ra as RemoveSheetDataValidationCommand,
|
|
2393
2409
|
F as SheetDataValidationModel,
|
|
2394
2410
|
we as SheetsDataValidationValidatorService,
|
|
2395
|
-
|
|
2411
|
+
Oe as UniverSheetsDataValidationPlugin,
|
|
2396
2412
|
_a as UpdateSheetDataValidationOptionsCommand,
|
|
2397
2413
|
ha as UpdateSheetDataValidationRangeCommand,
|
|
2398
2414
|
ga as UpdateSheetDataValidationSettingCommand,
|
|
@@ -8,6 +8,7 @@ export declare class DataValidationCacheService extends Disposable {
|
|
|
8
8
|
unitId: string;
|
|
9
9
|
subUnitId: string;
|
|
10
10
|
ranges: IRange[];
|
|
11
|
+
isSetRange?: boolean;
|
|
11
12
|
}>;
|
|
12
13
|
constructor(_commandService: ICommandService, _univerInstanceService: IUniverInstanceService);
|
|
13
14
|
private _initDirtyRanges;
|
|
@@ -16,7 +17,7 @@ export declare class DataValidationCacheService extends Disposable {
|
|
|
16
17
|
ensureCache(unitId: string, subUnitId: string): ObjectMatrix<Nullable<DataValidationStatus>>;
|
|
17
18
|
addRule(unitId: string, subUnitId: string, rule: ISheetDataValidationRule): void;
|
|
18
19
|
removeRule(unitId: string, subUnitId: string, rule: ISheetDataValidationRule): void;
|
|
19
|
-
markRangeDirty(unitId: string, subUnitId: string, ranges: IRange[]): void;
|
|
20
|
+
markRangeDirty(unitId: string, subUnitId: string, ranges: IRange[], isSetRange?: boolean): void;
|
|
20
21
|
private _deleteRange;
|
|
21
22
|
getValue(unitId: string, subUnitId: string, row: number, col: number): Nullable<Nullable<DataValidationStatus>>;
|
|
22
23
|
}
|
|
@@ -23,6 +23,8 @@ export declare class DataValidationCustomFormulaService extends Disposable {
|
|
|
23
23
|
private _initFormulaResultHandler;
|
|
24
24
|
private _ensureMaps;
|
|
25
25
|
private _registerFormula;
|
|
26
|
+
private _handleDirtyRanges;
|
|
27
|
+
private _initDirtyRanges;
|
|
26
28
|
deleteByRuleId(unitId: string, subUnitId: string, ruleId: string): void;
|
|
27
29
|
private _addFormulaByRange;
|
|
28
30
|
addRule(unitId: string, subUnitId: string, rule: ISheetDataValidationRule): void;
|
|
@@ -31,5 +33,6 @@ export declare class DataValidationCustomFormulaService extends Disposable {
|
|
|
31
33
|
getCellFormulaValueSync(unitId: string, subUnitId: string, ruleId: string, row: number, column: number): import('@univerjs/core').Nullable<import('@univerjs/core').ICellData>;
|
|
32
34
|
getCellFormula2ValueSync(unitId: string, subUnitId: string, ruleId: string, row: number, column: number): import('@univerjs/core').Nullable<import('@univerjs/core').ICellData>;
|
|
33
35
|
getRuleFormulaInfo(unitId: string, subUnitId: string, ruleId: string): IFormulaData | undefined;
|
|
36
|
+
makeRuleDirty(unitId: string, subUnitId: string, ruleId: string): void;
|
|
34
37
|
}
|
|
35
38
|
export {};
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(l,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/sheets-data-validation"),require("@univerjs/sheets/facade"),require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/core/facade"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/sheets-data-validation","@univerjs/sheets/facade","@univerjs/core","@univerjs/data-validation","@univerjs/engine-formula","@univerjs/core/facade","rxjs"],n):(l=typeof globalThis<"u"?globalThis:l||self,n(l.UniverSheetsDataValidationFacade={},l.UniverSheetsDataValidation,l.UniverSheetsFacade,l.UniverCore,l.UniverDataValidation,l.UniverEngineFormula,l.UniverCoreFacade,l.rxjs))})(this,function(l,n,g,a,D,w,E,I){"use strict";var A=Object.defineProperty;var O=(l,n,g)=>n in l?A(l,n,{enumerable:!0,configurable:!0,writable:!0,value:g}):l[n]=g;var S=(l,n,g)=>O(l,typeof n!="symbol"?n+"":n,g);class _{constructor(t){S(this,"_rule");this._rule=t!=null?t:{uid:a.generateRandomId(),ranges:void 0,type:a.DataValidationType.CUSTOM}}build(){return new p(this._rule)}copy(){return new _({...this._rule,uid:a.generateRandomId()})}getAllowInvalid(){return this._rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(t,e){return this._rule.type=a.DataValidationType.CHECKBOX,this._rule.formula1=t,this._rule.formula2=e,this}requireDateAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.GREATER_THAN,this}requireDateBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this}requireDateBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.BETWEEN,this}requireDateEqualTo(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this}requireDateNotBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(t){return this._rule.type=a.DataValidationType.CUSTOM,this._rule.formula1=t,this._rule.formula2=void 0,this}requireNumberBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.NOT_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireValueInList(t,e,r){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=t.join(","),this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}requireValueInRange(t,e,r){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=`=${w.serializeRangeToRefString({unitId:t.getUnitId(),sheetName:t.getSheetName(),range:t.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}setAllowInvalid(t){return this._rule.errorStyle=t?a.DataValidationErrorStyle.WARNING:a.DataValidationErrorStyle.STOP,this}setAllowBlank(t){return this._rule.allowBlank=t,this}setOptions(t){return Object.assign(this._rule,t),this}}class p{constructor(t,e,r){S(this,"rule");S(this,"_worksheet");S(this,"_injector");this._injector=r,this.rule=t,this._worksheet=e}getAllowInvalid(){return this.rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this.rule.type}getCriteriaValues(){return[this.rule.operator,this.rule.formula1,this.rule.formula2]}getHelpText(){return this.rule.error}copy(){return new _(this.rule)}getApplied(){if(!this._worksheet)return!1;const e=this._injector.get(D.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){if(!this.getApplied())return[];const t=this._injector.get(a.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(e=>this._injector.createInstance(g.FRange,t,this._worksheet,e))}getUnitId(){var t;return(t=this._worksheet)==null?void 0:t.getUnitId()}getSheetId(){var t;return(t=this._worksheet)==null?void 0:t.getSheetId()}setCriteria(t,e,r=!0){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:e[0],formula1:e[1],formula2:e[2],type:this.rule.type,allowBlank:r}}))throw new Error("setCriteria failed");return this.rule.operator=e[0],this.rule.formula1=e[1],this.rule.formula2=e[2],this.rule.type=t,this.rule.allowBlank=r,this}setOptions(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...D.getRuleOptions(this.rule),...t}}))throw new Error("setOptions failed");return Object.assign(this.rule,t),this}setRanges(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:t.map(i=>i.getRange())}))throw new Error("setRanges failed");return this.rule.ranges=t.map(e=>e.getRange()),this}delete(){return this.getApplied()?this._injector.get(a.ICommandService).syncExecuteCommand(n.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}}class C extends g.FRange{setDataValidation(t){if(!t)return this._commandService.syncExecuteCommand(n.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;const e={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...t.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(n.AddSheetDataValidationCommand.id,e),this}getDataValidation(){const e=this._injector.get(n.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new p(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(n.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new p(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}g.FRange.extend(C);class T extends E.FUniver{static newDataValidation(){return new _}newDataValidation(){return new _}_initialize(t){if(!t.has(n.SheetDataValidationModel))return;const e=t.get(n.SheetDataValidationModel),r=t.get(a.ICommandService);this.registerEventHandler(this.Event.SheetDataValidationChanged,()=>e.ruleChange$.subscribe(i=>{const{unitId:o,subUnitId:s,rule:m,oldRule:u,type:d}=i,h=this.getSheetTarget(o,s);if(!h)return;const{workbook:c,worksheet:V}=h,v=new p(m,V.getSheet(),this._injector);this.fireEvent(this.Event.SheetDataValidationChanged,{origin:i,worksheet:V,workbook:c,changeType:d,oldRule:u,rule:v})})),this.registerEventHandler(this.Event.SheetDataValidatorStatusChanged,()=>e.validStatusChange$.subscribe(i=>{const{unitId:o,subUnitId:s,ruleId:m,status:u,row:d,col:h}=i,c=this.getSheetTarget(o,s);if(!c)return;const{workbook:V,worksheet:v}=c,k=v.getDataValidation(m);k&&this.fireEvent(this.Event.SheetDataValidatorStatusChanged,{workbook:V,worksheet:v,row:d,column:h,rule:k,status:u})})),this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd,()=>r.beforeCommandExecuted(i=>{if(i.id===n.AddSheetDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:u}=s,d={worksheet:u,workbook:m,rule:o.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,d),d.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationSettingCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:u}=s,d=u.getDataValidation(o.ruleId);if(!d)return;const h={worksheet:u,workbook:m,rule:d,ruleId:o.ruleId,newCriteria:o.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationRangeCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:u}=s,d=u.getDataValidation(o.ruleId);if(!d)return;const h={worksheet:u,workbook:m,rule:d,ruleId:o.ruleId,newRanges:o.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate,()=>r.beforeCommandExecuted(i=>{if(i.id===n.UpdateSheetDataValidationOptionsCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:u}=s,d=u.getDataValidation(o.ruleId);if(!d)return;const h={worksheet:u,workbook:m,rule:d,ruleId:o.ruleId,newOptions:o.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete,()=>r.beforeCommandExecuted(i=>{if(i.id===n.RemoveSheetDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:u}=s,d=u.getDataValidation(o.ruleId);if(!d)return;const h={worksheet:u,workbook:m,rule:d,ruleId:o.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll,()=>r.beforeCommandExecuted(i=>{if(i.id===n.RemoveSheetAllDataValidationCommand.id){const o=i.params,s=this.getSheetTarget(o.unitId,o.subUnitId);if(!s)return;const{workbook:m,worksheet:u}=s,d={worksheet:u,workbook:m,rules:u.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,d),d.cancel)throw new a.CanceledError}}))}}E.FUniver.extend(T);class U extends g.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(n.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}onDataValidationChange(t){return a.toDisposable(this._dataValidationModel.ruleChange$.pipe(I.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(I.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.AddSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.UpdateSheetDataValidationSettingCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.UpdateSheetDataValidationRangeCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.UpdateSheetDataValidationOptionsCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.RemoveSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.RemoveSheetAllDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}g.FWorkbook.extend(U);class y extends g.FWorksheet{getDataValidations(){return this._injector.get(D.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new p(e,this._worksheet,this._injector))}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getValidatorStatusAsync(){return this.getValidatorStatus()}getDataValidation(t){const r=this._injector.get(D.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),t);return r?new p(r,this._worksheet,this._injector):null}}g.FWorksheet.extend(y);class b{get SheetDataValidationChanged(){return"SheetDataValidationChanged"}get SheetDataValidatorStatusChanged(){return"SheetDataValidatorStatusChanged"}get BeforeSheetDataValidationAdd(){return"BeforeSheetDataValidationAdd"}get BeforeSheetDataValidationDelete(){return"BeforeSheetDataValidationDelete"}get BeforeSheetDataValidationDeleteAll(){return"BeforeSheetDataValidationDeleteAll"}get BeforeSheetDataValidationCriteriaUpdate(){return"BeforeSheetDataValidationCriteriaUpdate"}get BeforeSheetDataValidationRangeUpdate(){return"BeforeSheetDataValidationRangeUpdate"}get BeforeSheetDataValidationOptionsUpdate(){return"BeforeSheetDataValidationOptionsUpdate"}}E.FEventName.extend(b),l.FDataValidation=p,l.FDataValidationBuilder=_,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(d,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/sheets-data-validation"),require("@univerjs/sheets/facade"),require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/core/facade"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/sheets-data-validation","@univerjs/sheets/facade","@univerjs/core","@univerjs/data-validation","@univerjs/engine-formula","@univerjs/core/facade","rxjs"],n):(d=typeof globalThis<"u"?globalThis:d||self,n(d.UniverSheetsDataValidationFacade={},d.UniverSheetsDataValidation,d.UniverSheetsFacade,d.UniverCore,d.UniverDataValidation,d.UniverEngineFormula,d.UniverCoreFacade,d.rxjs))})(this,function(d,n,m,a,S,w,E,I){"use strict";var A=Object.defineProperty;var O=(d,n,m)=>n in d?A(d,n,{enumerable:!0,configurable:!0,writable:!0,value:m}):d[n]=m;var f=(d,n,m)=>O(d,typeof n!="symbol"?n+"":n,m);class p{constructor(t){f(this,"_rule");this._rule=t!=null?t:{uid:a.generateRandomId(),ranges:void 0,type:a.DataValidationType.CUSTOM}}build(){return new g(this._rule)}copy(){return new p({...this._rule,uid:a.generateRandomId()})}getAllowInvalid(){return this._rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(t,e){return this._rule.type=a.DataValidationType.CHECKBOX,this._rule.formula1=t,this._rule.formula2=e,this}requireDateAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.GREATER_THAN,this}requireDateBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this}requireDateBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.BETWEEN,this}requireDateEqualTo(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this}requireDateNotBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(t){return this._rule.type=a.DataValidationType.CUSTOM,this._rule.formula1=t,this._rule.formula2=void 0,this}requireNumberBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.NOT_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireValueInList(t,e,r){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=t.join(","),this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}requireValueInRange(t,e,r){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=`=${w.serializeRangeToRefString({unitId:t.getUnitId(),sheetName:t.getSheetName(),range:t.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}setAllowInvalid(t){return this._rule.errorStyle=t?a.DataValidationErrorStyle.WARNING:a.DataValidationErrorStyle.STOP,this}setAllowBlank(t){return this._rule.allowBlank=t,this}setOptions(t){return Object.assign(this._rule,t),this}}class g{constructor(t,e,r){f(this,"rule");f(this,"_worksheet");f(this,"_injector");this._injector=r,this.rule=t,this._worksheet=e}getAllowInvalid(){return this.rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this.rule.type}getCriteriaValues(){return[this.rule.operator,this.rule.formula1,this.rule.formula2]}getHelpText(){return this.rule.error}copy(){return new p(this.rule)}getApplied(){if(!this._worksheet)return!1;const e=this._injector.get(S.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){if(!this.getApplied())return[];const t=this._injector.get(a.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(e=>this._injector.createInstance(m.FRange,t,this._worksheet,e))}getUnitId(){var t;return(t=this._worksheet)==null?void 0:t.getUnitId()}getSheetId(){var t;return(t=this._worksheet)==null?void 0:t.getSheetId()}setCriteria(t,e,r=!0){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:e[0],formula1:e[1],formula2:e[2],type:this.rule.type,allowBlank:r}}))throw new Error("setCriteria failed");return this.rule.operator=e[0],this.rule.formula1=e[1],this.rule.formula2=e[2],this.rule.type=t,this.rule.allowBlank=r,this}setOptions(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...S.getRuleOptions(this.rule),...t}}))throw new Error("setOptions failed");return Object.assign(this.rule,t),this}setRanges(t){if(this.getApplied()&&!this._injector.get(a.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:t.map(i=>i.getRange())}))throw new Error("setRanges failed");return this.rule.ranges=t.map(e=>e.getRange()),this}delete(){return this.getApplied()?this._injector.get(a.ICommandService).syncExecuteCommand(n.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}}class C extends m.FRange{setDataValidation(t){if(!t)return this._commandService.syncExecuteCommand(n.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;const e={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...t.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(n.AddSheetDataValidationCommand.id,e),this}getDataValidation(){const e=this._injector.get(n.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new g(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(n.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new g(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}m.FRange.extend(C);class T extends E.FUniver{static newDataValidation(){return new p}newDataValidation(){return new p}_initialize(t){const e=t.get(a.ICommandService);this.registerEventHandler(this.Event.SheetDataValidationChanged,()=>t.has(n.SheetDataValidationModel)?t.get(n.SheetDataValidationModel).ruleChange$.subscribe(i=>{const{unitId:o,subUnitId:u,rule:l,oldRule:s,type:h}=i,D=this.getSheetTarget(o,u);if(!D)return;const{workbook:V,worksheet:c}=D,v=new g(l,c.getSheet(),this._injector);this.fireEvent(this.Event.SheetDataValidationChanged,{origin:i,worksheet:c,workbook:V,changeType:h,oldRule:s,rule:v})}):{dispose:()=>{}}),this.registerEventHandler(this.Event.SheetDataValidatorStatusChanged,()=>t.has(n.SheetDataValidationModel)?t.get(n.SheetDataValidationModel).validStatusChange$.subscribe(i=>{const{unitId:o,subUnitId:u,ruleId:l,status:s,row:h,col:D}=i,V=this.getSheetTarget(o,u);if(!V)return;const{workbook:c,worksheet:v}=V,k=v.getDataValidation(l);k&&this.fireEvent(this.Event.SheetDataValidatorStatusChanged,{workbook:c,worksheet:v,row:h,column:D,rule:k,status:s})}):{dispose:()=>{}}),this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd,()=>e.beforeCommandExecuted(r=>{if(r.id===n.AddSheetDataValidationCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:u,worksheet:l}=o,s={worksheet:l,workbook:u,rule:i.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,s),s.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate,()=>e.beforeCommandExecuted(r=>{if(r.id===n.UpdateSheetDataValidationSettingCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:u,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const h={worksheet:l,workbook:u,rule:s,ruleId:i.ruleId,newCriteria:i.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate,()=>e.beforeCommandExecuted(r=>{if(r.id===n.UpdateSheetDataValidationRangeCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:u,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const h={worksheet:l,workbook:u,rule:s,ruleId:i.ruleId,newRanges:i.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate,()=>e.beforeCommandExecuted(r=>{if(r.id===n.UpdateSheetDataValidationOptionsCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:u,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const h={worksheet:l,workbook:u,rule:s,ruleId:i.ruleId,newOptions:i.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete,()=>e.beforeCommandExecuted(r=>{if(r.id===n.RemoveSheetDataValidationCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:u,worksheet:l}=o,s=l.getDataValidation(i.ruleId);if(!s)return;const h={worksheet:l,workbook:u,rule:s,ruleId:i.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,h),h.cancel)throw new a.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll,()=>e.beforeCommandExecuted(r=>{if(r.id===n.RemoveSheetAllDataValidationCommand.id){const i=r.params,o=this.getSheetTarget(i.unitId,i.subUnitId);if(!o)return;const{workbook:u,worksheet:l}=o,s={worksheet:l,workbook:u,rules:l.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,s),s.cancel)throw new a.CanceledError}}))}}E.FUniver.extend(T);class U extends m.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(n.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}onDataValidationChange(t){return a.toDisposable(this._dataValidationModel.ruleChange$.pipe(I.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(I.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.AddSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.UpdateSheetDataValidationSettingCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.UpdateSheetDataValidationRangeCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.UpdateSheetDataValidationOptionsCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.RemoveSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===n.RemoveSheetAllDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}m.FWorkbook.extend(U);class y extends m.FWorksheet{getDataValidations(){return this._injector.get(S.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new g(e,this._worksheet,this._injector))}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getValidatorStatusAsync(){return this.getValidatorStatus()}getDataValidation(t){const r=this._injector.get(S.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),t);return r?new g(r,this._worksheet,this._injector):null}}m.FWorksheet.extend(y);class b{get SheetDataValidationChanged(){return"SheetDataValidationChanged"}get SheetDataValidatorStatusChanged(){return"SheetDataValidatorStatusChanged"}get BeforeSheetDataValidationAdd(){return"BeforeSheetDataValidationAdd"}get BeforeSheetDataValidationDelete(){return"BeforeSheetDataValidationDelete"}get BeforeSheetDataValidationDeleteAll(){return"BeforeSheetDataValidationDeleteAll"}get BeforeSheetDataValidationCriteriaUpdate(){return"BeforeSheetDataValidationCriteriaUpdate"}get BeforeSheetDataValidationRangeUpdate(){return"BeforeSheetDataValidationRangeUpdate"}get BeforeSheetDataValidationOptionsUpdate(){return"BeforeSheetDataValidationOptionsUpdate"}}E.FEventName.extend(b),d.FDataValidation=g,d.FDataValidationBuilder=p,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|