@univerjs/sheets-data-validation 1.4.0 → 1.5.1

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