@univerjs/sheets-data-validation 1.4.0 → 1.5.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/README.md +6 -5
- package/lib/cjs/facade.js +9 -9
- package/lib/cjs/index.js +181 -143
- package/lib/es/facade.js +9 -9
- package/lib/es/index.js +181 -143
- package/lib/facade.js +9 -9
- package/lib/index.js +181 -143
- package/lib/types/facade/f-range.d.ts +5 -1
- package/lib/types/models/rule-matrix.d.ts +13 -0
- package/lib/types/services/dv-formula.service.d.ts +7 -3
- package/lib/types/services/dv-list-cache.service.d.ts +4 -3
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +10 -10
package/lib/es/index.js
CHANGED
|
@@ -34,7 +34,7 @@ function getRangesInWorksheet(ranges, worksheet) {
|
|
|
34
34
|
return effectiveRanges;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
// \0@oxc-project+runtime@0.
|
|
37
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
38
38
|
function _typeof(o) {
|
|
39
39
|
"@babel/helpers - typeof";
|
|
40
40
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -44,25 +44,25 @@ function _typeof(o) {
|
|
|
44
44
|
}, _typeof(o);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
// \0@oxc-project+runtime@0.
|
|
48
|
-
function toPrimitive(t,
|
|
47
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
48
|
+
function toPrimitive(t, e) {
|
|
49
49
|
if ("object" != _typeof(t) || !t) return t;
|
|
50
|
-
var
|
|
51
|
-
if (void 0 !==
|
|
52
|
-
var i =
|
|
50
|
+
var r;
|
|
51
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
52
|
+
var i = r.call(t, e || "default");
|
|
53
53
|
if ("object" != _typeof(i)) return i;
|
|
54
54
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
55
55
|
}
|
|
56
|
-
return ("string" ===
|
|
56
|
+
return ("string" === e ? String : Number)(t);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
// \0@oxc-project+runtime@0.
|
|
59
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
60
60
|
function toPropertyKey(t) {
|
|
61
61
|
var i = toPrimitive(t, "string");
|
|
62
62
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
// \0@oxc-project+runtime@0.
|
|
65
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
66
66
|
function _defineProperty(e, r, t) {
|
|
67
67
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
68
68
|
value: t,
|
|
@@ -72,14 +72,14 @@ function _defineProperty(e, r, t) {
|
|
|
72
72
|
}) : e[r] = t, e;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
// \0@oxc-project+runtime@0.
|
|
75
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
76
76
|
function __decorateParam(paramIndex, decorator) {
|
|
77
77
|
return function(target, key) {
|
|
78
78
|
decorator(target, key, paramIndex);
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
// \0@oxc-project+runtime@0.
|
|
82
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
83
83
|
function __decorate(decorators, target, key, desc) {
|
|
84
84
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
85
85
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -408,139 +408,19 @@ DataValidationCustomFormulaService = __decorate([
|
|
|
408
408
|
__decorateParam(4, Inject(DataValidatorRegistryService))
|
|
409
409
|
], DataValidationCustomFormulaService);
|
|
410
410
|
|
|
411
|
-
// src/utils/get-cell-data-origin.ts
|
|
412
|
-
function getCellValueOrigin(cell) {
|
|
413
|
-
return getOriginCellValue(cell);
|
|
414
|
-
}
|
|
415
|
-
function getStringCellValue(cell) {
|
|
416
|
-
return String(getCellValueOrigin(cell) ?? "");
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
// src/services/dv-list-cache.service.ts
|
|
420
|
-
let DataValidationListCacheService = class DataValidationListCacheService extends Disposable {
|
|
421
|
-
constructor(_injector, _dataValidationModel) {
|
|
422
|
-
super();
|
|
423
|
-
this._injector = _injector;
|
|
424
|
-
this._dataValidationModel = _dataValidationModel;
|
|
425
|
-
_defineProperty(this, "_cache", /* @__PURE__ */ new Map());
|
|
426
|
-
this._initRuleChangeListener();
|
|
427
|
-
}
|
|
428
|
-
_initRuleChangeListener() {
|
|
429
|
-
this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe((change) => {
|
|
430
|
-
if (change.type === "remove" || change.type === "update") this.markRuleDirty(change.unitId, change.subUnitId, change.rule.uid);
|
|
431
|
-
}));
|
|
432
|
-
}
|
|
433
|
-
/**
|
|
434
|
-
* Get cached list data or compute and cache it if not exists.
|
|
435
|
-
*/
|
|
436
|
-
getOrCompute(unitId, subUnitId, rule) {
|
|
437
|
-
const cached = this.getCache(unitId, subUnitId, rule.uid);
|
|
438
|
-
if (cached) return cached;
|
|
439
|
-
const results = this._injector.get(DataValidationFormulaService).getRuleFormulaResultSync(unitId, subUnitId, rule.uid);
|
|
440
|
-
return this.computeAndCache(unitId, subUnitId, rule, results);
|
|
441
|
-
}
|
|
442
|
-
_ensureCache(unitId, subUnitId) {
|
|
443
|
-
let unitMap = this._cache.get(unitId);
|
|
444
|
-
if (!unitMap) {
|
|
445
|
-
unitMap = /* @__PURE__ */ new Map();
|
|
446
|
-
this._cache.set(unitId, unitMap);
|
|
447
|
-
}
|
|
448
|
-
let subUnitMap = unitMap.get(subUnitId);
|
|
449
|
-
if (!subUnitMap) {
|
|
450
|
-
subUnitMap = /* @__PURE__ */ new Map();
|
|
451
|
-
unitMap.set(subUnitId, subUnitMap);
|
|
452
|
-
}
|
|
453
|
-
return subUnitMap;
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Get cached list data for a rule. Returns undefined if not cached.
|
|
457
|
-
*/
|
|
458
|
-
getCache(unitId, subUnitId, ruleId) {
|
|
459
|
-
var _this$_cache$get;
|
|
460
|
-
return (_this$_cache$get = this._cache.get(unitId)) === null || _this$_cache$get === void 0 || (_this$_cache$get = _this$_cache$get.get(subUnitId)) === null || _this$_cache$get === void 0 ? void 0 : _this$_cache$get.get(ruleId);
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Set cache for a rule.
|
|
464
|
-
*/
|
|
465
|
-
setCache(unitId, subUnitId, ruleId, item) {
|
|
466
|
-
this._ensureCache(unitId, subUnitId).set(ruleId, item);
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Mark a rule's cache as dirty (invalidate it).
|
|
470
|
-
* Called when formula results change.
|
|
471
|
-
*/
|
|
472
|
-
markRuleDirty(unitId, subUnitId, ruleId) {
|
|
473
|
-
var _this$_cache$get2;
|
|
474
|
-
(_this$_cache$get2 = this._cache.get(unitId)) === null || _this$_cache$get2 === void 0 || (_this$_cache$get2 = _this$_cache$get2.get(subUnitId)) === null || _this$_cache$get2 === void 0 || _this$_cache$get2.delete(ruleId);
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Clear all caches.
|
|
478
|
-
*/
|
|
479
|
-
clear() {
|
|
480
|
-
this._cache.clear();
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Compute list data from formula result and cache it.
|
|
484
|
-
*/
|
|
485
|
-
computeAndCache(unitId, subUnitId, rule, formulaResult) {
|
|
486
|
-
var _formulaResult$;
|
|
487
|
-
const { formula1 = "", formula2 = "" } = rule;
|
|
488
|
-
const list = isFormulaString(formula1) ? this._getRuleFormulaResultSet(formulaResult === null || formulaResult === void 0 || (_formulaResult$ = formulaResult[0]) === null || _formulaResult$ === void 0 || (_formulaResult$ = _formulaResult$.result) === null || _formulaResult$ === void 0 || (_formulaResult$ = _formulaResult$[0]) === null || _formulaResult$ === void 0 ? void 0 : _formulaResult$[0]) : deserializeListOptions(formula1);
|
|
489
|
-
const colorList = formula2.split(",");
|
|
490
|
-
const listWithColor = list.map((label, i) => ({
|
|
491
|
-
label,
|
|
492
|
-
color: colorList[i] || ""
|
|
493
|
-
}));
|
|
494
|
-
const colorMap = {};
|
|
495
|
-
for (const item of listWithColor) if (item.color) colorMap[item.label] = item.color;
|
|
496
|
-
const cacheItem = {
|
|
497
|
-
list,
|
|
498
|
-
listWithColor,
|
|
499
|
-
colorMap,
|
|
500
|
-
set: new Set(list)
|
|
501
|
-
};
|
|
502
|
-
this.setCache(unitId, subUnitId, rule.uid, cacheItem);
|
|
503
|
-
return cacheItem;
|
|
504
|
-
}
|
|
505
|
-
/**
|
|
506
|
-
* Extract string list from formula result cells.
|
|
507
|
-
*/
|
|
508
|
-
_getRuleFormulaResultSet(result) {
|
|
509
|
-
if (!result) return [];
|
|
510
|
-
const resultSet = /* @__PURE__ */ new Set();
|
|
511
|
-
for (let i = 0, rowLen = result.length; i < rowLen; i++) {
|
|
512
|
-
const row = result[i];
|
|
513
|
-
if (!row) continue;
|
|
514
|
-
for (let j = 0, colLen = row.length; j < colLen; j++) {
|
|
515
|
-
const cell = row[j];
|
|
516
|
-
const value = getCellValueOrigin(cell);
|
|
517
|
-
if (value !== null && value !== void 0) {
|
|
518
|
-
var _cell$s;
|
|
519
|
-
if (typeof value !== "string" && typeof (cell === null || cell === void 0 ? void 0 : cell.s) === "object" && ((_cell$s = cell.s) === null || _cell$s === void 0 || (_cell$s = _cell$s.n) === null || _cell$s === void 0 ? void 0 : _cell$s.pattern)) {
|
|
520
|
-
resultSet.add(numfmt.format(cell.s.n.pattern, value, { throws: false }));
|
|
521
|
-
continue;
|
|
522
|
-
}
|
|
523
|
-
const valueStr = typeof value === "string" ? value : String(value);
|
|
524
|
-
if (isLegalFormulaResult(valueStr)) resultSet.add(valueStr);
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
return [...resultSet];
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
DataValidationListCacheService = __decorate([__decorateParam(0, Inject(Injector)), __decorateParam(1, Inject(DataValidationModel))], DataValidationListCacheService);
|
|
532
|
-
|
|
533
411
|
// src/services/dv-formula.service.ts
|
|
534
412
|
let DataValidationFormulaService = class DataValidationFormulaService extends Disposable {
|
|
535
|
-
constructor(_instanceService, _registerOtherFormulaService, _dataValidationCacheService, _dataValidationModel, _validatorRegistryService
|
|
413
|
+
constructor(_instanceService, _registerOtherFormulaService, _dataValidationCacheService, _dataValidationModel, _validatorRegistryService) {
|
|
536
414
|
super();
|
|
537
415
|
this._instanceService = _instanceService;
|
|
538
416
|
this._registerOtherFormulaService = _registerOtherFormulaService;
|
|
539
417
|
this._dataValidationCacheService = _dataValidationCacheService;
|
|
540
418
|
this._dataValidationModel = _dataValidationModel;
|
|
541
419
|
this._validatorRegistryService = _validatorRegistryService;
|
|
542
|
-
this._listCacheService = _listCacheService;
|
|
543
420
|
_defineProperty(this, "_formulaRuleMap", /* @__PURE__ */ new Map());
|
|
421
|
+
_defineProperty(this, "_ruleFormulaResultChanged$", new Subject());
|
|
422
|
+
_defineProperty(this, "ruleFormulaResultChanged$", this._ruleFormulaResultChanged$.asObservable());
|
|
423
|
+
this.disposeWithMe(() => this._ruleFormulaResultChanged$.complete());
|
|
544
424
|
this._initFormulaResultHandler();
|
|
545
425
|
}
|
|
546
426
|
_initFormulaResultHandler() {
|
|
@@ -557,7 +437,11 @@ let DataValidationFormulaService = class DataValidationFormulaService extends Di
|
|
|
557
437
|
if (ruleId && formulaMap.get(ruleId)) {
|
|
558
438
|
const rule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
|
|
559
439
|
if (rule) {
|
|
560
|
-
this.
|
|
440
|
+
this._ruleFormulaResultChanged$.next({
|
|
441
|
+
unitId,
|
|
442
|
+
subUnitId,
|
|
443
|
+
ruleId
|
|
444
|
+
});
|
|
561
445
|
this._dataValidationCacheService.markRangeDirty(unitId, subUnitId, rule.ranges);
|
|
562
446
|
}
|
|
563
447
|
}
|
|
@@ -635,10 +519,17 @@ DataValidationFormulaService = __decorate([
|
|
|
635
519
|
__decorateParam(1, Inject(RegisterOtherFormulaService)),
|
|
636
520
|
__decorateParam(2, Inject(DataValidationCacheService)),
|
|
637
521
|
__decorateParam(3, Inject(DataValidationModel)),
|
|
638
|
-
__decorateParam(4, Inject(DataValidatorRegistryService))
|
|
639
|
-
__decorateParam(5, Inject(DataValidationListCacheService))
|
|
522
|
+
__decorateParam(4, Inject(DataValidatorRegistryService))
|
|
640
523
|
], DataValidationFormulaService);
|
|
641
524
|
|
|
525
|
+
// src/utils/get-cell-data-origin.ts
|
|
526
|
+
function getCellValueOrigin(cell) {
|
|
527
|
+
return getOriginCellValue(cell);
|
|
528
|
+
}
|
|
529
|
+
function getStringCellValue(cell) {
|
|
530
|
+
return String(getCellValueOrigin(cell) ?? "");
|
|
531
|
+
}
|
|
532
|
+
|
|
642
533
|
// src/models/rule-matrix.ts
|
|
643
534
|
var RuleMatrix = class RuleMatrix {
|
|
644
535
|
constructor(value, _unitId, _subUnitId, _univerInstanceService, _disableTree = false) {
|
|
@@ -678,13 +569,14 @@ var RuleMatrix = class RuleMatrix {
|
|
|
678
569
|
_addRule(ruleId, _ranges) {
|
|
679
570
|
if (!this._worksheet) return;
|
|
680
571
|
const ranges = Rectangle.mergeRanges(_ranges.map((range) => Range.transformRange(range, this._worksheet)));
|
|
572
|
+
const ruleRanges = this._withInputRangeType(ranges, _ranges);
|
|
681
573
|
this._map.forEach((value, key) => {
|
|
682
574
|
const newRanges = Rectangle.subtractMulti(value, ranges);
|
|
683
575
|
if (newRanges.length === 0) this._map.delete(key);
|
|
684
576
|
else this._map.set(key, newRanges);
|
|
685
577
|
});
|
|
686
578
|
this._dirty = true;
|
|
687
|
-
this._map.set(ruleId,
|
|
579
|
+
this._map.set(ruleId, ruleRanges);
|
|
688
580
|
this._debonceBuildTree();
|
|
689
581
|
}
|
|
690
582
|
addRule(rule) {
|
|
@@ -714,6 +606,35 @@ var RuleMatrix = class RuleMatrix {
|
|
|
714
606
|
this._removeRule(ruleId);
|
|
715
607
|
this._addRule(ruleId, _newRanges);
|
|
716
608
|
}
|
|
609
|
+
/**
|
|
610
|
+
* The matrix stores concrete coordinates, while the rule keeps its semantic range type (a whole
|
|
611
|
+
* column/row). `Range.transformRange` and `Rectangle.mergeRanges` rebuild ranges from bounds only,
|
|
612
|
+
* so the type of the ranges handed to the matrix has to be carried over explicitly.
|
|
613
|
+
*/
|
|
614
|
+
_withInputRangeType(ranges, inputRanges) {
|
|
615
|
+
var _inputRanges$;
|
|
616
|
+
const rangeType = (_inputRanges$ = inputRanges[0]) === null || _inputRanges$ === void 0 ? void 0 : _inputRanges$.rangeType;
|
|
617
|
+
if (!rangeType || !inputRanges.every((range) => range.rangeType === rangeType)) return ranges;
|
|
618
|
+
return ranges.map((range) => ({
|
|
619
|
+
...range,
|
|
620
|
+
rangeType
|
|
621
|
+
}));
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* A rule range that the matrix rebuilt from coordinates keeps its type when the rebuilt range
|
|
625
|
+
* still covers exactly the same cells as the rule's own range. This is what makes an auto fill
|
|
626
|
+
* or a paste that only rewrites cells inside the rule a no-op instead of a downgrade: the
|
|
627
|
+
* intermediate subtract/add steps drop the type, but the net coverage is unchanged.
|
|
628
|
+
*/
|
|
629
|
+
_keepRuleRangeType(ranges, ruleRanges) {
|
|
630
|
+
return ranges.map((range) => {
|
|
631
|
+
const source = ruleRanges.find((item) => item.rangeType && item.startRow === range.startRow && item.endRow === range.endRow && item.startColumn === range.startColumn && item.endColumn === range.endColumn);
|
|
632
|
+
return source ? {
|
|
633
|
+
...range,
|
|
634
|
+
rangeType: source.rangeType
|
|
635
|
+
} : range;
|
|
636
|
+
});
|
|
637
|
+
}
|
|
717
638
|
addRangeRules(rules) {
|
|
718
639
|
rules.forEach(({ id: ruleId, ranges }) => {
|
|
719
640
|
if (!ranges.length) return;
|
|
@@ -739,7 +660,7 @@ var RuleMatrix = class RuleMatrix {
|
|
|
739
660
|
const mutations = [];
|
|
740
661
|
let deleteIndex = 0;
|
|
741
662
|
rules.forEach((rule, index) => {
|
|
742
|
-
const newRanges = this._map.get(rule.uid) ?? [];
|
|
663
|
+
const newRanges = this._keepRuleRangeType(this._map.get(rule.uid) ?? [], rule.ranges);
|
|
743
664
|
const oldRanges = rule.ranges;
|
|
744
665
|
if (newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i])))) mutations.push({
|
|
745
666
|
type: "update",
|
|
@@ -763,7 +684,7 @@ var RuleMatrix = class RuleMatrix {
|
|
|
763
684
|
const mutations = [];
|
|
764
685
|
let deleteIndex = 0;
|
|
765
686
|
rules.forEach((rule, index) => {
|
|
766
|
-
const newRanges = this._map.get(rule.uid) ?? [];
|
|
687
|
+
const newRanges = this._keepRuleRangeType(this._map.get(rule.uid) ?? [], rule.ranges);
|
|
767
688
|
const oldRanges = rule.ranges;
|
|
768
689
|
if (newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i])))) mutations.push({
|
|
769
690
|
type: "update",
|
|
@@ -782,7 +703,7 @@ var RuleMatrix = class RuleMatrix {
|
|
|
782
703
|
}
|
|
783
704
|
});
|
|
784
705
|
Array.from(additionRules).forEach((rule) => {
|
|
785
|
-
const newRanges = this._map.get(rule.uid) ?? [];
|
|
706
|
+
const newRanges = this._keepRuleRangeType(this._map.get(rule.uid) ?? [], rule.ranges);
|
|
786
707
|
mutations.push({
|
|
787
708
|
type: "add",
|
|
788
709
|
rule: {
|
|
@@ -1483,6 +1404,123 @@ var DecimalValidator = class extends BaseSheetValidator {
|
|
|
1483
1404
|
}
|
|
1484
1405
|
};
|
|
1485
1406
|
|
|
1407
|
+
// src/services/dv-list-cache.service.ts
|
|
1408
|
+
let DataValidationListCacheService = class DataValidationListCacheService extends Disposable {
|
|
1409
|
+
constructor(_formulaService, _dataValidationModel) {
|
|
1410
|
+
super();
|
|
1411
|
+
this._formulaService = _formulaService;
|
|
1412
|
+
this._dataValidationModel = _dataValidationModel;
|
|
1413
|
+
_defineProperty(this, "_cache", /* @__PURE__ */ new Map());
|
|
1414
|
+
this.disposeWithMe(this._formulaService.ruleFormulaResultChanged$.subscribe(({ unitId, subUnitId, ruleId }) => {
|
|
1415
|
+
this.markRuleDirty(unitId, subUnitId, ruleId);
|
|
1416
|
+
}));
|
|
1417
|
+
this._initRuleChangeListener();
|
|
1418
|
+
}
|
|
1419
|
+
_initRuleChangeListener() {
|
|
1420
|
+
this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe((change) => {
|
|
1421
|
+
if (change.type === "remove" || change.type === "update") this.markRuleDirty(change.unitId, change.subUnitId, change.rule.uid);
|
|
1422
|
+
}));
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* Get cached list data or compute and cache it if not exists.
|
|
1426
|
+
*/
|
|
1427
|
+
getOrCompute(unitId, subUnitId, rule) {
|
|
1428
|
+
const cached = this.getCache(unitId, subUnitId, rule.uid);
|
|
1429
|
+
if (cached) return cached;
|
|
1430
|
+
const results = this._formulaService.getRuleFormulaResultSync(unitId, subUnitId, rule.uid);
|
|
1431
|
+
return this.computeAndCache(unitId, subUnitId, rule, results);
|
|
1432
|
+
}
|
|
1433
|
+
_ensureCache(unitId, subUnitId) {
|
|
1434
|
+
let unitMap = this._cache.get(unitId);
|
|
1435
|
+
if (!unitMap) {
|
|
1436
|
+
unitMap = /* @__PURE__ */ new Map();
|
|
1437
|
+
this._cache.set(unitId, unitMap);
|
|
1438
|
+
}
|
|
1439
|
+
let subUnitMap = unitMap.get(subUnitId);
|
|
1440
|
+
if (!subUnitMap) {
|
|
1441
|
+
subUnitMap = /* @__PURE__ */ new Map();
|
|
1442
|
+
unitMap.set(subUnitId, subUnitMap);
|
|
1443
|
+
}
|
|
1444
|
+
return subUnitMap;
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Get cached list data for a rule. Returns undefined if not cached.
|
|
1448
|
+
*/
|
|
1449
|
+
getCache(unitId, subUnitId, ruleId) {
|
|
1450
|
+
var _this$_cache$get;
|
|
1451
|
+
return (_this$_cache$get = this._cache.get(unitId)) === null || _this$_cache$get === void 0 || (_this$_cache$get = _this$_cache$get.get(subUnitId)) === null || _this$_cache$get === void 0 ? void 0 : _this$_cache$get.get(ruleId);
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Set cache for a rule.
|
|
1455
|
+
*/
|
|
1456
|
+
setCache(unitId, subUnitId, ruleId, item) {
|
|
1457
|
+
this._ensureCache(unitId, subUnitId).set(ruleId, item);
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* Mark a rule's cache as dirty (invalidate it).
|
|
1461
|
+
* Called when formula results change.
|
|
1462
|
+
*/
|
|
1463
|
+
markRuleDirty(unitId, subUnitId, ruleId) {
|
|
1464
|
+
var _this$_cache$get2;
|
|
1465
|
+
(_this$_cache$get2 = this._cache.get(unitId)) === null || _this$_cache$get2 === void 0 || (_this$_cache$get2 = _this$_cache$get2.get(subUnitId)) === null || _this$_cache$get2 === void 0 || _this$_cache$get2.delete(ruleId);
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1468
|
+
* Clear all caches.
|
|
1469
|
+
*/
|
|
1470
|
+
clear() {
|
|
1471
|
+
this._cache.clear();
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Compute list data from formula result and cache it.
|
|
1475
|
+
*/
|
|
1476
|
+
computeAndCache(unitId, subUnitId, rule, formulaResult) {
|
|
1477
|
+
var _formulaResult$;
|
|
1478
|
+
const { formula1 = "", formula2 = "" } = rule;
|
|
1479
|
+
const list = isFormulaString(formula1) ? this._getRuleFormulaResultSet(formulaResult === null || formulaResult === void 0 || (_formulaResult$ = formulaResult[0]) === null || _formulaResult$ === void 0 || (_formulaResult$ = _formulaResult$.result) === null || _formulaResult$ === void 0 || (_formulaResult$ = _formulaResult$[0]) === null || _formulaResult$ === void 0 ? void 0 : _formulaResult$[0]) : deserializeListOptions(formula1);
|
|
1480
|
+
const colorList = formula2.split(",");
|
|
1481
|
+
const listWithColor = list.map((label, i) => ({
|
|
1482
|
+
label,
|
|
1483
|
+
color: colorList[i] || ""
|
|
1484
|
+
}));
|
|
1485
|
+
const colorMap = {};
|
|
1486
|
+
for (const item of listWithColor) if (item.color) colorMap[item.label] = item.color;
|
|
1487
|
+
const cacheItem = {
|
|
1488
|
+
list,
|
|
1489
|
+
listWithColor,
|
|
1490
|
+
colorMap,
|
|
1491
|
+
set: new Set(list)
|
|
1492
|
+
};
|
|
1493
|
+
this.setCache(unitId, subUnitId, rule.uid, cacheItem);
|
|
1494
|
+
return cacheItem;
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Extract string list from formula result cells.
|
|
1498
|
+
*/
|
|
1499
|
+
_getRuleFormulaResultSet(result) {
|
|
1500
|
+
if (!result) return [];
|
|
1501
|
+
const resultSet = /* @__PURE__ */ new Set();
|
|
1502
|
+
for (let i = 0, rowLen = result.length; i < rowLen; i++) {
|
|
1503
|
+
const row = result[i];
|
|
1504
|
+
if (!row) continue;
|
|
1505
|
+
for (let j = 0, colLen = row.length; j < colLen; j++) {
|
|
1506
|
+
const cell = row[j];
|
|
1507
|
+
const value = getCellValueOrigin(cell);
|
|
1508
|
+
if (value !== null && value !== void 0) {
|
|
1509
|
+
var _cell$s;
|
|
1510
|
+
if (typeof value !== "string" && typeof (cell === null || cell === void 0 ? void 0 : cell.s) === "object" && ((_cell$s = cell.s) === null || _cell$s === void 0 || (_cell$s = _cell$s.n) === null || _cell$s === void 0 ? void 0 : _cell$s.pattern)) {
|
|
1511
|
+
resultSet.add(numfmt.format(cell.s.n.pattern, value, { throws: false }));
|
|
1512
|
+
continue;
|
|
1513
|
+
}
|
|
1514
|
+
const valueStr = typeof value === "string" ? value : String(value);
|
|
1515
|
+
if (isLegalFormulaResult(valueStr)) resultSet.add(valueStr);
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
return [...resultSet];
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
DataValidationListCacheService = __decorate([__decorateParam(0, Inject(DataValidationFormulaService)), __decorateParam(1, Inject(DataValidationModel))], DataValidationListCacheService);
|
|
1523
|
+
|
|
1486
1524
|
// src/validators/list-validator.ts
|
|
1487
1525
|
function getRuleFormulaResultSet(result) {
|
|
1488
1526
|
if (!result) return [];
|
|
@@ -2322,7 +2360,7 @@ DataValidationFormulaController = __decorate([
|
|
|
2322
2360
|
|
|
2323
2361
|
// package.json
|
|
2324
2362
|
var name = "@univerjs/sheets-data-validation";
|
|
2325
|
-
var version = "1.
|
|
2363
|
+
var version = "1.5.0";
|
|
2326
2364
|
|
|
2327
2365
|
// src/config/config.ts
|
|
2328
2366
|
/**
|
package/lib/facade.js
CHANGED
|
@@ -6,7 +6,7 @@ import { serializeRangeToRefString } from "@univerjs/engine-formula";
|
|
|
6
6
|
import { serializeListOptions } from "@univerjs/sheets";
|
|
7
7
|
import { FEventName, FUniver } from "@univerjs/core/facade";
|
|
8
8
|
|
|
9
|
-
// \0@oxc-project+runtime@0.
|
|
9
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
10
10
|
function _typeof(o) {
|
|
11
11
|
"@babel/helpers - typeof";
|
|
12
12
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -16,25 +16,25 @@ function _typeof(o) {
|
|
|
16
16
|
}, _typeof(o);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
// \0@oxc-project+runtime@0.
|
|
20
|
-
function toPrimitive(t,
|
|
19
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
20
|
+
function toPrimitive(t, e) {
|
|
21
21
|
if ("object" != _typeof(t) || !t) return t;
|
|
22
|
-
var
|
|
23
|
-
if (void 0 !==
|
|
24
|
-
var i =
|
|
22
|
+
var r;
|
|
23
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
24
|
+
var i = r.call(t, e || "default");
|
|
25
25
|
if ("object" != _typeof(i)) return i;
|
|
26
26
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
27
27
|
}
|
|
28
|
-
return ("string" ===
|
|
28
|
+
return ("string" === e ? String : Number)(t);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
// \0@oxc-project+runtime@0.
|
|
31
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
32
32
|
function toPropertyKey(t) {
|
|
33
33
|
var i = toPrimitive(t, "string");
|
|
34
34
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
// \0@oxc-project+runtime@0.
|
|
37
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
38
38
|
function _defineProperty(e, r, t) {
|
|
39
39
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
40
40
|
value: t,
|