@univerjs/sheets-data-validation 1.0.0-alpha.8 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/facade.js CHANGED
@@ -79,7 +79,7 @@ function _defineProperty(e, r, t) {
79
79
  var FDataValidationBuilder = class FDataValidationBuilder {
80
80
  constructor(rule) {
81
81
  _defineProperty(this, "_rule", void 0);
82
- this._rule = rule !== null && rule !== void 0 ? rule : {
82
+ this._rule = rule ?? {
83
83
  uid: generateRandomId(),
84
84
  ranges: void 0,
85
85
  type: DataValidationType.CUSTOM
@@ -812,7 +812,7 @@ var FDataValidationBuilder = class FDataValidationBuilder {
812
812
  this._rule.type = multiple ? DataValidationType.LIST_MULTIPLE : DataValidationType.LIST;
813
813
  this._rule.formula1 = serializeListOptions(values);
814
814
  this._rule.formula2 = void 0;
815
- this._rule.showDropDown = showDropdown !== null && showDropdown !== void 0 ? showDropdown : true;
815
+ this._rule.showDropDown = showDropdown ?? true;
816
816
  return this;
817
817
  }
818
818
  /**
@@ -856,7 +856,7 @@ var FDataValidationBuilder = class FDataValidationBuilder {
856
856
  range: range.getRange()
857
857
  })}`;
858
858
  this._rule.formula2 = void 0;
859
- this._rule.showDropDown = showDropdown !== null && showDropdown !== void 0 ? showDropdown : true;
859
+ this._rule.showDropDown = showDropdown ?? true;
860
860
  return this;
861
861
  }
862
862
  /**
package/lib/index.js CHANGED
@@ -186,9 +186,8 @@ function isLegalFormulaResult(res) {
186
186
  * Judge if the data-validation's formula need to be offseted by ranges
187
187
  */
188
188
  function shouldOffsetFormulaByRange(type, validatorRegistryService) {
189
- var _validator$offsetForm;
190
189
  const validator = validatorRegistryService.getValidatorItem(type);
191
- return (_validator$offsetForm = validator === null || validator === void 0 ? void 0 : validator.offsetFormulaByRange) !== null && _validator$offsetForm !== void 0 ? _validator$offsetForm : false;
190
+ return (validator === null || validator === void 0 ? void 0 : validator.offsetFormulaByRange) ?? false;
192
191
  }
193
192
 
194
193
  //#endregion
@@ -384,8 +383,7 @@ function getCellValueOrigin(cell) {
384
383
  return getOriginCellValue(cell);
385
384
  }
386
385
  function getStringCellValue(cell) {
387
- var _getCellValueOrigin;
388
- return String((_getCellValueOrigin = getCellValueOrigin(cell)) !== null && _getCellValueOrigin !== void 0 ? _getCellValueOrigin : "");
386
+ return String(getCellValueOrigin(cell) ?? "");
389
387
  }
390
388
 
391
389
  //#endregion
@@ -714,8 +712,7 @@ var RuleMatrix = class RuleMatrix {
714
712
  const mutations = [];
715
713
  let deleteIndex = 0;
716
714
  rules.forEach((rule, index) => {
717
- var _this$_map$get;
718
- const newRanges = (_this$_map$get = this._map.get(rule.uid)) !== null && _this$_map$get !== void 0 ? _this$_map$get : [];
715
+ const newRanges = this._map.get(rule.uid) ?? [];
719
716
  const oldRanges = rule.ranges;
720
717
  if (newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i])))) mutations.push({
721
718
  type: "update",
@@ -739,8 +736,7 @@ var RuleMatrix = class RuleMatrix {
739
736
  const mutations = [];
740
737
  let deleteIndex = 0;
741
738
  rules.forEach((rule, index) => {
742
- var _this$_map$get2;
743
- const newRanges = (_this$_map$get2 = this._map.get(rule.uid)) !== null && _this$_map$get2 !== void 0 ? _this$_map$get2 : [];
739
+ const newRanges = this._map.get(rule.uid) ?? [];
744
740
  const oldRanges = rule.ranges;
745
741
  if (newRanges.length !== 0 && (newRanges.length !== oldRanges.length || newRanges.some((range, i) => !Rectangle.equals(range, oldRanges[i])))) mutations.push({
746
742
  type: "update",
@@ -759,8 +755,7 @@ var RuleMatrix = class RuleMatrix {
759
755
  }
760
756
  });
761
757
  Array.from(additionRules).forEach((rule) => {
762
- var _this$_map$get3;
763
- const newRanges = (_this$_map$get3 = this._map.get(rule.uid)) !== null && _this$_map$get3 !== void 0 ? _this$_map$get3 : [];
758
+ const newRanges = this._map.get(rule.uid) ?? [];
764
759
  mutations.push({
765
760
  type: "add",
766
761
  rule: {
@@ -945,8 +940,8 @@ let SheetDataValidationModel = class SheetDataValidationModel extends Disposable
945
940
  });
946
941
  return DataValidationStatus.VALIDATING;
947
942
  }
948
- onCompete(current !== null && current !== void 0 ? current : DataValidationStatus.VALID, false);
949
- return current !== null && current !== void 0 ? current : DataValidationStatus.VALID;
943
+ onCompete(current ?? DataValidationStatus.VALID, false);
944
+ return current ?? DataValidationStatus.VALID;
950
945
  } else {
951
946
  onCompete(DataValidationStatus.VALID, false);
952
947
  return DataValidationStatus.VALID;
@@ -1057,15 +1052,13 @@ var BaseSheetValidator = class extends BaseDataValidator {
1057
1052
  return this.operators.map((operator) => this.localeService.t(OperatorTextMap[operator]));
1058
1053
  }
1059
1054
  generateRuleName(rule) {
1060
- var _rule$formula, _rule$formula2;
1061
1055
  if (!rule.operator) return this.localeService.t(OperatorTitleMap.NONE).replace(TYPE, this.titleStr);
1062
- const ruleName = this.localeService.t(OperatorTitleMap[rule.operator]).replace(FORMULA1$1, (_rule$formula = rule.formula1) !== null && _rule$formula !== void 0 ? _rule$formula : "").replace(FORMULA2$1, (_rule$formula2 = rule.formula2) !== null && _rule$formula2 !== void 0 ? _rule$formula2 : "");
1056
+ const ruleName = this.localeService.t(OperatorTitleMap[rule.operator]).replace(FORMULA1$1, rule.formula1 ?? "").replace(FORMULA2$1, rule.formula2 ?? "");
1063
1057
  return `${this.titleStr} ${ruleName}`;
1064
1058
  }
1065
1059
  generateRuleErrorMessage(rule, _position) {
1066
- var _rule$formula3, _rule$formula4;
1067
1060
  if (!rule.operator) return this.localeService.t(OperatorErrorTitleMap.NONE).replace(TYPE, this.titleStr);
1068
- return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1$1, (_rule$formula3 = rule.formula1) !== null && _rule$formula3 !== void 0 ? _rule$formula3 : "").replace(FORMULA2$1, (_rule$formula4 = rule.formula2) !== null && _rule$formula4 !== void 0 ? _rule$formula4 : "")}`;
1061
+ return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1$1, rule.formula1 ?? "").replace(FORMULA2$1, rule.formula2 ?? "")}`;
1069
1062
  }
1070
1063
  };
1071
1064
 
@@ -1092,7 +1085,7 @@ var CheckboxValidator = class extends BaseSheetValidator {
1092
1085
  _defineProperty(this, "skipDefaultFontRender", (rule, cellValue, pos) => {
1093
1086
  const { unitId, subUnitId } = pos;
1094
1087
  const { formula1, formula2 } = this.parseFormulaSync(rule, unitId, subUnitId);
1095
- const valueStr = `${cellValue !== null && cellValue !== void 0 ? cellValue : ""}`;
1088
+ const valueStr = `${cellValue ?? ""}`;
1096
1089
  return !valueStr || valueStr === `${formula1}` || valueStr === `${formula2}`;
1097
1090
  });
1098
1091
  }
@@ -1150,7 +1143,7 @@ var CheckboxValidator = class extends BaseSheetValidator {
1150
1143
  const { value, unitId, subUnitId } = cellInfo;
1151
1144
  const { formula1, formula2, originFormula1, originFormula2 } = await this.parseFormula(rule, unitId, subUnitId);
1152
1145
  if (!Tools.isDefine(formula1) || !Tools.isDefine(formula2)) return true;
1153
- return Tools.isDefine(value) && (String(value) === String(formula1) || String(value) === String(formula2) || String(value) === String(originFormula1 !== null && originFormula1 !== void 0 ? originFormula1 : "") || String(value) === String(originFormula2 !== null && originFormula2 !== void 0 ? originFormula2 : ""));
1146
+ return Tools.isDefine(value) && (String(value) === String(formula1) || String(value) === String(formula2) || String(value) === String(originFormula1 ?? "") || String(value) === String(originFormula2 ?? ""));
1154
1147
  }
1155
1148
  generateRuleErrorMessage(rule) {
1156
1149
  return this.localeService.t("sheets-data-validation.checkbox.error");
@@ -1376,15 +1369,14 @@ var DateValidator = class extends BaseSheetValidator {
1376
1369
  return this.operators.map((operator) => this.localeService.t(DateOperatorNameMap[operator]));
1377
1370
  }
1378
1371
  generateRuleName(rule) {
1379
- var _rule$formula, _rule$formula2;
1380
1372
  if (!rule.operator) return this.localeService.t(DateOperatorTitleMap.NONE);
1381
- const ruleName = this.localeService.t(DateOperatorTitleMap[rule.operator]).replace(FORMULA1, (_rule$formula = rule.formula1) !== null && _rule$formula !== void 0 ? _rule$formula : "").replace(FORMULA2, (_rule$formula2 = rule.formula2) !== null && _rule$formula2 !== void 0 ? _rule$formula2 : "");
1373
+ const ruleName = this.localeService.t(DateOperatorTitleMap[rule.operator]).replace(FORMULA1, rule.formula1 ?? "").replace(FORMULA2, rule.formula2 ?? "");
1382
1374
  return `${this.titleStr} ${ruleName}`;
1383
1375
  }
1384
1376
  generateRuleErrorMessage(rule, pos) {
1385
1377
  if (!rule.operator) return this.titleStr;
1386
1378
  const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, pos);
1387
- return `${this.localeService.t(DateOperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 !== null && transformedFormula1 !== void 0 ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 !== null && transformedFormula2 !== void 0 ? transformedFormula2 : "")}`;
1379
+ return `${this.localeService.t(DateOperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 ?? "").replace(FORMULA2, transformedFormula2 ?? "")}`;
1388
1380
  }
1389
1381
  };
1390
1382
 
@@ -1462,7 +1454,7 @@ var DecimalValidator = class extends BaseSheetValidator {
1462
1454
  generateRuleErrorMessage(rule, position) {
1463
1455
  if (!rule.operator) return this.localeService.t(OperatorErrorTitleMap.NONE).replace("{TYPE}", this.titleStr);
1464
1456
  const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, position);
1465
- return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 !== null && transformedFormula1 !== void 0 ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 !== null && transformedFormula2 !== void 0 ? transformedFormula2 : "")}`;
1457
+ return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 ?? "").replace(FORMULA2, transformedFormula2 ?? "")}`;
1466
1458
  }
1467
1459
  };
1468
1460
 
@@ -1528,21 +1520,19 @@ var ListValidator = class extends BaseSheetValidator {
1528
1520
  });
1529
1521
  }
1530
1522
  validatorFormula(rule, unitId, subUnitId) {
1531
- var _rule$formula, _this$_univerInstance;
1523
+ var _this$_univerInstance;
1532
1524
  const success = !Tools.isBlank(rule.formula1);
1533
- const valid = isValidListFormula((_rule$formula = rule.formula1) !== null && _rule$formula !== void 0 ? _rule$formula : "", this._lexer);
1534
- const sheetName = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 || (_this$_univerInstance = _this$_univerInstance.getSheetBySheetId(subUnitId)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getName();
1535
- const isIntersects = isRuleIntersects(rule, sheetName !== null && sheetName !== void 0 ? sheetName : "");
1525
+ const valid = isValidListFormula(rule.formula1 ?? "", this._lexer);
1526
+ const isIntersects = isRuleIntersects(rule, ((_this$_univerInstance = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 || (_this$_univerInstance = _this$_univerInstance.getSheetBySheetId(subUnitId)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getName()) ?? "");
1536
1527
  return {
1537
1528
  success: Boolean(success && valid && !isIntersects),
1538
1529
  formula1: success ? valid ? !isIntersects ? void 0 : this.localeService.t("sheets-data-validation.validFail.listIntersects") : this.localeService.t("sheets-data-validation.validFail.listInvalid") : this.localeService.t("sheets-data-validation.validFail.list")
1539
1530
  };
1540
1531
  }
1541
1532
  getExtraStyle(rule, value, { style: defaultStyle }) {
1542
- var _ref;
1543
- const tb = (_ref = defaultStyle.tb !== WrapStrategy.OVERFLOW ? defaultStyle.tb : WrapStrategy.CLIP) !== null && _ref !== void 0 ? _ref : WrapStrategy.WRAP;
1533
+ const tb = (defaultStyle.tb !== WrapStrategy.OVERFLOW ? defaultStyle.tb : WrapStrategy.CLIP) ?? WrapStrategy.WRAP;
1544
1534
  if (rule.type === DataValidationType.LIST && (rule.renderMode === DataValidationRenderMode.ARROW || rule.renderMode === DataValidationRenderMode.TEXT)) {
1545
- const color = this.getListWithColorMap(rule)[`${value !== null && value !== void 0 ? value : ""}`];
1535
+ const color = this.getListWithColorMap(rule)[`${value ?? ""}`];
1546
1536
  if (color) return {
1547
1537
  bg: { rgb: color },
1548
1538
  tb
@@ -1576,10 +1566,9 @@ var ListValidator = class extends BaseSheetValidator {
1576
1566
  return this.localeService.t("sheets-data-validation.list.error");
1577
1567
  }
1578
1568
  _getUnitAndSubUnit(currentUnitId, currentSubUnitId) {
1579
- var _ref2, _ref3;
1580
- const workbook = (_ref2 = currentUnitId ? this._univerInstanceService.getUnit(currentUnitId, UniverInstanceType.UNIVER_SHEET) : void 0) !== null && _ref2 !== void 0 ? _ref2 : this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
1569
+ const workbook = (currentUnitId ? this._univerInstanceService.getUnit(currentUnitId, UniverInstanceType.UNIVER_SHEET) : void 0) ?? this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
1581
1570
  if (!workbook) return null;
1582
- const worksheet = (_ref3 = currentSubUnitId ? workbook.getSheetBySheetId(currentSubUnitId) : void 0) !== null && _ref3 !== void 0 ? _ref3 : workbook.getActiveSheet();
1571
+ const worksheet = (currentSubUnitId ? workbook.getSheetBySheetId(currentSubUnitId) : void 0) ?? workbook.getActiveSheet();
1583
1572
  if (!worksheet) return null;
1584
1573
  return {
1585
1574
  unitId: workbook.getUnitId(),
@@ -1685,17 +1674,17 @@ var TextLengthValidator = class extends BaseSheetValidator {
1685
1674
  generateRuleErrorMessage(rule, pos) {
1686
1675
  if (!rule.operator) return this.titleStr;
1687
1676
  const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, pos);
1688
- return `${this.localeService.t(TextLengthErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 !== null && transformedFormula1 !== void 0 ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 !== null && transformedFormula2 !== void 0 ? transformedFormula2 : "")}`;
1677
+ return `${this.localeService.t(TextLengthErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 ?? "").replace(FORMULA2, transformedFormula2 ?? "")}`;
1689
1678
  }
1690
1679
  };
1691
1680
 
1692
1681
  //#endregion
1693
1682
  //#region src/commands/commands/data-validation.command.ts
1694
1683
  function isBlankCell(cellData) {
1695
- var _cellData$p$body$data, _cellData$p$body;
1684
+ var _cellData$p$body;
1696
1685
  if (!cellData) return true;
1697
1686
  if (!cellData.p) return Tools.isBlank(cellData.v);
1698
- return !((_cellData$p$body$data = (_cellData$p$body = cellData.p.body) === null || _cellData$p$body === void 0 ? void 0 : _cellData$p$body.dataStream) !== null && _cellData$p$body$data !== void 0 ? _cellData$p$body$data : "").slice(0, -2).trim();
1687
+ return !(((_cellData$p$body = cellData.p.body) === null || _cellData$p$body === void 0 ? void 0 : _cellData$p$body.dataStream) ?? "").slice(0, -2).trim();
1699
1688
  }
1700
1689
  function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, source = "command", fillDefaultValue = true) {
1701
1690
  const lexerTreeBuilder = accessor.get(LexerTreeBuilder);
@@ -2310,7 +2299,7 @@ DataValidationFormulaController = __decorate([
2310
2299
  //#endregion
2311
2300
  //#region package.json
2312
2301
  var name = "@univerjs/sheets-data-validation";
2313
- var version = "1.0.0-alpha.8";
2302
+ var version = "1.0.0-beta.0";
2314
2303
 
2315
2304
  //#endregion
2316
2305
  //#region src/config/config.ts
@@ -2355,7 +2344,7 @@ let DataValidationFormulaRefRangeController = class DataValidationFormulaRefRang
2355
2344
  const oldRanges = rule.ranges;
2356
2345
  const oldFormula1 = rule.formula1;
2357
2346
  const oldFormula2 = rule.formula2;
2358
- const disposable = this._formulaRefRangeService.registerRangeFormula(unitId, subUnitId, oldRanges, [oldFormula1 !== null && oldFormula1 !== void 0 ? oldFormula1 : "", oldFormula2 !== null && oldFormula2 !== void 0 ? oldFormula2 : ""], (res) => {
2347
+ const disposable = this._formulaRefRangeService.registerRangeFormula(unitId, subUnitId, oldRanges, [oldFormula1 ?? "", oldFormula2 ?? ""], (res) => {
2359
2348
  if (res.length === 0) return {
2360
2349
  undos: [{
2361
2350
  id: AddDataValidationMutation.id,
@@ -2511,10 +2500,9 @@ let DataValidationRefRangeController = class DataValidationRefRangeController ex
2511
2500
  return `${unitID}_${subUnitId}_${ruleId}`;
2512
2501
  }
2513
2502
  registerFormula(unitId, subUnitId, rule) {
2514
- var _this$_disposableMap$;
2515
2503
  const ruleId = rule.uid;
2516
2504
  const id = this._getIdWithUnitId(unitId, subUnitId, ruleId);
2517
- const disposeSet = (_this$_disposableMap$ = this._disposableMap.get(id)) !== null && _this$_disposableMap$ !== void 0 ? _this$_disposableMap$ : /* @__PURE__ */ new Set();
2505
+ const disposeSet = this._disposableMap.get(id) ?? /* @__PURE__ */ new Set();
2518
2506
  const handleFormulaChange = (type, formulaString) => {
2519
2507
  const oldRule = this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
2520
2508
  if (!oldRule) return {
@@ -2580,7 +2568,6 @@ let DataValidationRefRangeController = class DataValidationRefRangeController ex
2580
2568
  }
2581
2569
  }
2582
2570
  register(unitId, subUnitId, rule) {
2583
- var _this$_disposableMap$2;
2584
2571
  const handleRangeChange = (commandInfo) => {
2585
2572
  const oldRanges = [...rule.ranges];
2586
2573
  const resultRanges = oldRanges.map((range) => {
@@ -2641,7 +2628,7 @@ let DataValidationRefRangeController = class DataValidationRefRangeController ex
2641
2628
  disposeList.push(() => disposable.dispose());
2642
2629
  });
2643
2630
  const id = this._getIdWithUnitId(unitId, subUnitId, rule.uid);
2644
- const current = (_this$_disposableMap$2 = this._disposableMap.get(id)) !== null && _this$_disposableMap$2 !== void 0 ? _this$_disposableMap$2 : /* @__PURE__ */ new Set();
2631
+ const current = this._disposableMap.get(id) ?? /* @__PURE__ */ new Set();
2645
2632
  current.add(() => disposeList.forEach((dispose) => dispose()));
2646
2633
  this._disposableMap.set(id, current);
2647
2634
  }
@@ -2835,9 +2822,8 @@ var CustomFormulaValidator = class extends BaseSheetValidator {
2835
2822
  _defineProperty(this, "_lexerTreeBuilder", this.injector.get(LexerTreeBuilder));
2836
2823
  }
2837
2824
  validatorFormula(rule, unitId, subUnitId) {
2838
- var _rule$formula;
2839
2825
  const success = isFormulaString(rule.formula1);
2840
- const formulaText = (_rule$formula = rule.formula1) !== null && _rule$formula !== void 0 ? _rule$formula : "";
2826
+ const formulaText = rule.formula1 ?? "";
2841
2827
  const valid = this._lexerTreeBuilder.checkIfAddBracket(formulaText) === 0 && formulaText.startsWith(operatorToken.EQUALS);
2842
2828
  return {
2843
2829
  success: success && valid,
@@ -2869,8 +2855,7 @@ var CustomFormulaValidator = class extends BaseSheetValidator {
2869
2855
  return this.localeService.t("sheets-data-validation.custom.error");
2870
2856
  }
2871
2857
  generateRuleName(rule) {
2872
- var _rule$formula2;
2873
- return this.localeService.t("sheets-data-validation.custom.ruleName").replace("{FORMULA1}", (_rule$formula2 = rule.formula1) !== null && _rule$formula2 !== void 0 ? _rule$formula2 : "");
2858
+ return this.localeService.t("sheets-data-validation.custom.ruleName").replace("{FORMULA1}", rule.formula1 ?? "");
2874
2859
  }
2875
2860
  };
2876
2861
 
@@ -2977,7 +2962,7 @@ var WholeValidator = class extends BaseSheetValidator {
2977
2962
  generateRuleErrorMessage(rule, position) {
2978
2963
  if (!rule.operator) return this.localeService.t(OperatorErrorTitleMap.NONE).replace("{TYPE}", this.titleStr);
2979
2964
  const { transformedFormula1, transformedFormula2 } = getTransformedFormula(this._lexerTreeBuilder, rule, position);
2980
- return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 !== null && transformedFormula1 !== void 0 ? transformedFormula1 : "").replace(FORMULA2, transformedFormula2 !== null && transformedFormula2 !== void 0 ? transformedFormula2 : "")}`;
2965
+ return `${this.localeService.t(OperatorErrorTitleMap[rule.operator]).replace(FORMULA1, transformedFormula1 ?? "").replace(FORMULA2, transformedFormula2 ?? "")}`;
2981
2966
  }
2982
2967
  };
2983
2968
 
@@ -3153,10 +3138,7 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
3153
3138
  * Because during the validation process, merged cells are all marked as VALIDATING status in cache.
3154
3139
  */
3155
3140
  if (mergeCells.length) mergeCells.forEach(({ resultRowIndex, resultColIndex, row, col }) => {
3156
- if (result[resultRowIndex][resultColIndex] === DataValidationStatus.VALIDATING) {
3157
- var _this$_dataValidation;
3158
- result[resultRowIndex][resultColIndex] = (_this$_dataValidation = this._dataValidationCacheService.getValue(unitId, subUnitId, row, col)) !== null && _this$_dataValidation !== void 0 ? _this$_dataValidation : DataValidationStatus.VALID;
3159
- }
3141
+ if (result[resultRowIndex][resultColIndex] === DataValidationStatus.VALIDATING) result[resultRowIndex][resultColIndex] = this._dataValidationCacheService.getValue(unitId, subUnitId, row, col) ?? DataValidationStatus.VALID;
3160
3142
  });
3161
3143
  return result;
3162
3144
  }
@@ -3285,7 +3267,7 @@ function createDefaultNewRule(accessor) {
3285
3267
  type: DataValidationType.DECIMAL,
3286
3268
  operator: DataValidationOperator.EQUAL,
3287
3269
  formula1: "100",
3288
- ranges: currentRanges !== null && currentRanges !== void 0 ? currentRanges : [{
3270
+ ranges: currentRanges ?? [{
3289
3271
  startColumn: 0,
3290
3272
  endColumn: 0,
3291
3273
  startRow: 0,
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets-data-validation"),require("@univerjs/sheets/facade"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("@univerjs/core/facade")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-data-validation`,`@univerjs/sheets/facade`,`@univerjs/data-validation`,`@univerjs/engine-formula`,`@univerjs/sheets`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDataValidationFacade={},e.UniverCore,e.UniverSheetsDataValidation,e.UniverSheetsFacade,e.UniverDataValidation,e.UniverEngineFormula,e.UniverSheets,e.UniverCoreFacade))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function c(e){"@babel/helpers - typeof";return c=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},c(e)}function l(e,t){if(c(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(c(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function u(e){var t=l(e,`string`);return c(t)==`symbol`?t:t+``}function d(e,t,n){return(t=u(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var f=class e{constructor(e){d(this,`_rule`,void 0),this._rule=e==null?{uid:(0,t.generateRandomId)(),ranges:void 0,type:t.DataValidationType.CUSTOM}:e}build(){return new p(this._rule)}copy(){return new e({...this._rule,uid:(0,t.generateRandomId)()})}getAllowInvalid(){return this._rule.errorStyle!==t.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(e,n){return this._rule.type=t.DataValidationType.CHECKBOX,this._rule.formula1=e,this._rule.formula2=n,this}requireDateAfter(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.GREATER_THAN,this}requireDateBefore(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN,this}requireDateBetween(e,n){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=n.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.BETWEEN,this}requireDateEqualTo(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.EQUAL,this}requireDateNotBetween(e,n){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=n.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(e){return this._rule.type=t.DataValidationType.CUSTOM,this._rule.formula1=e,this._rule.formula2=void 0,this}requireNumberBetween(e,n,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${n}`,this._rule.operator=t.DataValidationOperator.BETWEEN,this._rule.type=r?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberGreaterThan(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberLessThan(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberNotBetween(e,n,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${n}`,this._rule.operator=t.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.NOT_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireValueInList(e,n,r){return this._rule.type=n?t.DataValidationType.LIST_MULTIPLE:t.DataValidationType.LIST,this._rule.formula1=(0,o.serializeListOptions)(e),this._rule.formula2=void 0,this._rule.showDropDown=r==null||r,this}requireValueInRange(e,n,r){return this._rule.type=n?t.DataValidationType.LIST_MULTIPLE:t.DataValidationType.LIST,this._rule.formula1=`=${(0,a.serializeRangeToRefString)({unitId:e.getUnitId(),sheetName:e.getSheetName(),range:e.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r==null||r,this}setAllowInvalid(e){return this._rule.errorStyle=e?t.DataValidationErrorStyle.WARNING:t.DataValidationErrorStyle.STOP,this}setAllowBlank(e){return this._rule.allowBlank=e,this}setOptions(e){return Object.assign(this._rule,e),this}},p=class{constructor(e,t,n){d(this,`rule`,void 0),d(this,`_worksheet`,void 0),d(this,`_injector`,void 0),this._injector=n,this.rule=e,this._worksheet=t}getAllowInvalid(){return this.rule.errorStyle!==t.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 f(this.rule)}getApplied(){if(!this._worksheet)return!1;let e=this._injector.get(i.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){if(!this.getApplied())return[];let e=this._injector.get(t.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(t=>this._injector.createInstance(r.FRange,e,this._worksheet,t))}getUnitId(){var e;return(e=this._worksheet)==null?void 0:e.getUnitId()}getSheetId(){var e;return(e=this._worksheet)==null?void 0:e.getSheetId()}setCriteria(e,r,i=!0){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:r[0],formula1:r[1],formula2:r[2],type:this.rule.type,allowBlank:i}}))throw Error(`setCriteria failed`);return this.rule.operator=r[0],this.rule.formula1=r[1],this.rule.formula2=r[2],this.rule.type=e,this.rule.allowBlank=i,this}setOptions(e){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...(0,i.getRuleOptions)(this.rule),...e}}))throw Error(`setOptions failed`);return Object.assign(this.rule,e),this}setRanges(e){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:e.map(e=>e.getRange())}))throw Error(`setRanges failed`);return this.rule.ranges=e.map(e=>e.getRange()),this}delete(){return this.getApplied()?this._injector.get(t.ICommandService).syncExecuteCommand(n.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}},m=class extends r.FRange{setDataValidation(e){if(!e)return this._commandService.syncExecuteCommand(n.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;let t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...e.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(n.AddSheetDataValidationCommand.id,t),this}getDataValidation(){let 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])}async getDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return this._collectValidationErrorsForRange(e,t,[this._range])}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,s=o.getName(),c=[];for(let l of i){let i=[];for(let u=l.startRow;u<=l.endRow;u++)for(let d=l.startColumn;d<=l.endColumn;d++)i.push((async()=>{try{if(await a.validatorCell(e,r,u,d)!==t.DataValidationStatus.VALID){let t=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(e,r,u,d);if(t){var i;let e=((i=o.getCell(u,d))==null?void 0:i.v)||null,n=this._createDataValidationError(s,u,d,t,e);c.push(n)}}}catch(e){console.warn(`Failed to validate cell [${u}, ${d}]:`,e)}})());await Promise.all(i)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}};r.FRange.extend(m);var h=class extends s.FUniver{newDataValidation(){return new f}_initialize(e){let r=e.get(t.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetDataValidationChanged,()=>e.has(n.SheetDataValidationModel)?e.get(n.SheetDataValidationModel).ruleChange$.subscribe(e=>{let{unitId:t,subUnitId:n,rule:r,oldRule:i,type:a}=e,o=this.getSheetCommandTarget({unitId:t,subUnitId:n});if(!o)return;let{workbook:s,worksheet:c}=o,l={origin:e,worksheet:c,workbook:s,changeType:a,oldRule:i,rule:new p(r,c.getSheet(),this._injector)};this.fireEvent(this.Event.SheetDataValidationChanged,l)}):{dispose:()=>{}})),this.disposeWithMe(this.registerEventHandler(this.Event.SheetDataValidatorStatusChanged,()=>e.has(n.SheetDataValidationModel)?e.get(n.SheetDataValidationModel).validStatusChange$.subscribe(e=>{let{unitId:t,subUnitId:n,ruleId:r,status:i,row:a,col:o}=e,s=this.getSheetCommandTarget({unitId:t,subUnitId:n});if(!s)return;let{workbook:c,worksheet:l}=s,u=l.getDataValidation(r);if(!u)return;let d={workbook:c,worksheet:l,row:a,column:o,rule:u,status:i};this.fireEvent(this.Event.SheetDataValidatorStatusChanged,d)}):{dispose:()=>{}})),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd,()=>r.beforeCommandExecuted(e=>{if(e.id===n.AddSheetDataValidationCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{rule:o}=n,s={worksheet:a,workbook:i,rule:o};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,s),s.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationSettingCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o,setting:s}=n,c=a.getDataValidation(o);if(!c)return;let l={worksheet:a,workbook:i,rule:c,ruleId:o,newCriteria:s};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,l),l.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationRangeCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o,ranges:s}=n,c=a.getDataValidation(o);if(!c)return;let l={worksheet:a,workbook:i,rule:c,ruleId:o,newRanges:s};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,l),l.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationOptionsCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o,options:s}=n,c=a.getDataValidation(o);if(!c)return;let l={worksheet:a,workbook:i,rule:c,ruleId:o,newOptions:s};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,l),l.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete,()=>r.beforeCommandExecuted(e=>{if(e.id===n.RemoveSheetDataValidationCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o}=n,s=a.getDataValidation(o);if(!s)return;let c={worksheet:a,workbook:i,rule:s,ruleId:o};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,c),c.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll,()=>r.beforeCommandExecuted(e=>{if(e.id===n.RemoveSheetAllDataValidationCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,o={worksheet:a,workbook:i,rules:a.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,o),o.cancel)throw new t.CanceledError}})))}};s.FUniver.extend(h);var g=class extends r.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(n.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}async getAllDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._dataValidationModel.getSubUnitIds(e),n=[];for(let r of t){let t=await this._collectValidationErrorsForSheet(e,r);n.push(...t)}return n}async _collectValidationErrorsForSheet(e,t){let n=this._dataValidationModel.getRules(e,t);if(!n.length)return[];let r=n.flatMap(e=>e.ranges);return this._collectValidationErrorsForRange(e,t,r)}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._workbook.getSheetBySheetId(r);if(!o)throw Error(`Cannot find worksheet with sheetId: ${r}`);let s=o.getName(),c=[];for(let n of i){let i=[];for(let l=n.startRow;l<=n.endRow;l++)for(let u=n.startColumn;u<=n.endColumn;u++)i.push((async()=>{try{if(await a.validatorCell(e,r,l,u)!==t.DataValidationStatus.VALID){let t=this._dataValidationModel.getRuleByLocation(e,r,l,u);if(t){var n;let e=((n=o.getCell(l,u))==null?void 0:n.v)||null,r=this._createDataValidationError(s,l,u,t,e);c.push(r)}}}catch(e){console.warn(`Failed to validate cell [${l}, ${u}]:`,e)}})());await Promise.all(i)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}};r.FWorkbook.extend(g);var _=class extends r.FWorksheet{getDataValidations(){return this._injector.get(i.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new p(e,this._worksheet,this._injector))}getValidatorStatusAsync(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getDataValidation(e){let t=this._injector.get(i.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);return t?new p(t,this._worksheet,this._injector):null}async getAllDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return this._collectValidationErrorsForSheet(e,t)}async _collectValidationErrorsForSheet(e,t){let n=this._injector.get(i.DataValidationModel).getRules(e,t);if(!n.length)return[];let r=n.flatMap(e=>e.ranges);return this._collectValidationErrorsForRange(e,t,r)}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,s=o.getName(),c=[];for(let l of i){let i=[];for(let u=l.startRow;u<=l.endRow;u++)for(let d=l.startColumn;d<=l.endColumn;d++)i.push((async()=>{try{if(await a.validatorCell(e,r,u,d)!==t.DataValidationStatus.VALID){let t=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(e,r,u,d);if(t){var i;let e=((i=o.getCell(u,d))==null?void 0:i.v)||null,n=this._createDataValidationError(s,u,d,t,e);c.push(n)}}}catch(e){console.warn(`Failed to validate cell [${u}, ${d}]:`,e)}})());await Promise.all(i)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}};r.FWorksheet.extend(_);var v=class extends s.FEventName{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`}};s.FEventName.extend(v),e.FDataValidation=p,e.FDataValidationBuilder=f});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets-data-validation"),require("@univerjs/sheets/facade"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("@univerjs/core/facade")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-data-validation`,`@univerjs/sheets/facade`,`@univerjs/data-validation`,`@univerjs/engine-formula`,`@univerjs/sheets`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDataValidationFacade={},e.UniverCore,e.UniverSheetsDataValidation,e.UniverSheetsFacade,e.UniverDataValidation,e.UniverEngineFormula,e.UniverSheets,e.UniverCoreFacade))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function c(e){"@babel/helpers - typeof";return c=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},c(e)}function l(e,t){if(c(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(c(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function u(e){var t=l(e,`string`);return c(t)==`symbol`?t:t+``}function d(e,t,n){return(t=u(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var f=class e{constructor(e){d(this,`_rule`,void 0),this._rule=e??{uid:(0,t.generateRandomId)(),ranges:void 0,type:t.DataValidationType.CUSTOM}}build(){return new p(this._rule)}copy(){return new e({...this._rule,uid:(0,t.generateRandomId)()})}getAllowInvalid(){return this._rule.errorStyle!==t.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(e,n){return this._rule.type=t.DataValidationType.CHECKBOX,this._rule.formula1=e,this._rule.formula2=n,this}requireDateAfter(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.GREATER_THAN,this}requireDateBefore(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN,this}requireDateBetween(e,n){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=n.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.BETWEEN,this}requireDateEqualTo(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.EQUAL,this}requireDateNotBetween(e,n){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=n.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(e){return this._rule.type=t.DataValidationType.CUSTOM,this._rule.formula1=e,this._rule.formula2=void 0,this}requireNumberBetween(e,n,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${n}`,this._rule.operator=t.DataValidationOperator.BETWEEN,this._rule.type=r?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberGreaterThan(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberLessThan(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberNotBetween(e,n,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${n}`,this._rule.operator=t.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.NOT_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireValueInList(e,n,r){return this._rule.type=n?t.DataValidationType.LIST_MULTIPLE:t.DataValidationType.LIST,this._rule.formula1=(0,o.serializeListOptions)(e),this._rule.formula2=void 0,this._rule.showDropDown=r??!0,this}requireValueInRange(e,n,r){return this._rule.type=n?t.DataValidationType.LIST_MULTIPLE:t.DataValidationType.LIST,this._rule.formula1=`=${(0,a.serializeRangeToRefString)({unitId:e.getUnitId(),sheetName:e.getSheetName(),range:e.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r??!0,this}setAllowInvalid(e){return this._rule.errorStyle=e?t.DataValidationErrorStyle.WARNING:t.DataValidationErrorStyle.STOP,this}setAllowBlank(e){return this._rule.allowBlank=e,this}setOptions(e){return Object.assign(this._rule,e),this}},p=class{constructor(e,t,n){d(this,`rule`,void 0),d(this,`_worksheet`,void 0),d(this,`_injector`,void 0),this._injector=n,this.rule=e,this._worksheet=t}getAllowInvalid(){return this.rule.errorStyle!==t.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 f(this.rule)}getApplied(){if(!this._worksheet)return!1;let e=this._injector.get(i.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){if(!this.getApplied())return[];let e=this._injector.get(t.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(t=>this._injector.createInstance(r.FRange,e,this._worksheet,t))}getUnitId(){var e;return(e=this._worksheet)==null?void 0:e.getUnitId()}getSheetId(){var e;return(e=this._worksheet)==null?void 0:e.getSheetId()}setCriteria(e,r,i=!0){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:r[0],formula1:r[1],formula2:r[2],type:this.rule.type,allowBlank:i}}))throw Error(`setCriteria failed`);return this.rule.operator=r[0],this.rule.formula1=r[1],this.rule.formula2=r[2],this.rule.type=e,this.rule.allowBlank=i,this}setOptions(e){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...(0,i.getRuleOptions)(this.rule),...e}}))throw Error(`setOptions failed`);return Object.assign(this.rule,e),this}setRanges(e){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:e.map(e=>e.getRange())}))throw Error(`setRanges failed`);return this.rule.ranges=e.map(e=>e.getRange()),this}delete(){return this.getApplied()?this._injector.get(t.ICommandService).syncExecuteCommand(n.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}},m=class extends r.FRange{setDataValidation(e){if(!e)return this._commandService.syncExecuteCommand(n.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;let t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...e.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(n.AddSheetDataValidationCommand.id,t),this}getDataValidation(){let 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])}async getDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return this._collectValidationErrorsForRange(e,t,[this._range])}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,s=o.getName(),c=[];for(let l of i){let i=[];for(let u=l.startRow;u<=l.endRow;u++)for(let d=l.startColumn;d<=l.endColumn;d++)i.push((async()=>{try{if(await a.validatorCell(e,r,u,d)!==t.DataValidationStatus.VALID){let t=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(e,r,u,d);if(t){var i;let e=((i=o.getCell(u,d))==null?void 0:i.v)||null,n=this._createDataValidationError(s,u,d,t,e);c.push(n)}}}catch(e){console.warn(`Failed to validate cell [${u}, ${d}]:`,e)}})());await Promise.all(i)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}};r.FRange.extend(m);var h=class extends s.FUniver{newDataValidation(){return new f}_initialize(e){let r=e.get(t.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetDataValidationChanged,()=>e.has(n.SheetDataValidationModel)?e.get(n.SheetDataValidationModel).ruleChange$.subscribe(e=>{let{unitId:t,subUnitId:n,rule:r,oldRule:i,type:a}=e,o=this.getSheetCommandTarget({unitId:t,subUnitId:n});if(!o)return;let{workbook:s,worksheet:c}=o,l={origin:e,worksheet:c,workbook:s,changeType:a,oldRule:i,rule:new p(r,c.getSheet(),this._injector)};this.fireEvent(this.Event.SheetDataValidationChanged,l)}):{dispose:()=>{}})),this.disposeWithMe(this.registerEventHandler(this.Event.SheetDataValidatorStatusChanged,()=>e.has(n.SheetDataValidationModel)?e.get(n.SheetDataValidationModel).validStatusChange$.subscribe(e=>{let{unitId:t,subUnitId:n,ruleId:r,status:i,row:a,col:o}=e,s=this.getSheetCommandTarget({unitId:t,subUnitId:n});if(!s)return;let{workbook:c,worksheet:l}=s,u=l.getDataValidation(r);if(!u)return;let d={workbook:c,worksheet:l,row:a,column:o,rule:u,status:i};this.fireEvent(this.Event.SheetDataValidatorStatusChanged,d)}):{dispose:()=>{}})),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd,()=>r.beforeCommandExecuted(e=>{if(e.id===n.AddSheetDataValidationCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{rule:o}=n,s={worksheet:a,workbook:i,rule:o};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,s),s.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationSettingCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o,setting:s}=n,c=a.getDataValidation(o);if(!c)return;let l={worksheet:a,workbook:i,rule:c,ruleId:o,newCriteria:s};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,l),l.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationRangeCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o,ranges:s}=n,c=a.getDataValidation(o);if(!c)return;let l={worksheet:a,workbook:i,rule:c,ruleId:o,newRanges:s};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,l),l.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationOptionsCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o,options:s}=n,c=a.getDataValidation(o);if(!c)return;let l={worksheet:a,workbook:i,rule:c,ruleId:o,newOptions:s};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,l),l.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete,()=>r.beforeCommandExecuted(e=>{if(e.id===n.RemoveSheetDataValidationCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o}=n,s=a.getDataValidation(o);if(!s)return;let c={worksheet:a,workbook:i,rule:s,ruleId:o};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,c),c.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll,()=>r.beforeCommandExecuted(e=>{if(e.id===n.RemoveSheetAllDataValidationCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,o={worksheet:a,workbook:i,rules:a.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,o),o.cancel)throw new t.CanceledError}})))}};s.FUniver.extend(h);var g=class extends r.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(n.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}async getAllDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._dataValidationModel.getSubUnitIds(e),n=[];for(let r of t){let t=await this._collectValidationErrorsForSheet(e,r);n.push(...t)}return n}async _collectValidationErrorsForSheet(e,t){let n=this._dataValidationModel.getRules(e,t);if(!n.length)return[];let r=n.flatMap(e=>e.ranges);return this._collectValidationErrorsForRange(e,t,r)}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._workbook.getSheetBySheetId(r);if(!o)throw Error(`Cannot find worksheet with sheetId: ${r}`);let s=o.getName(),c=[];for(let n of i){let i=[];for(let l=n.startRow;l<=n.endRow;l++)for(let u=n.startColumn;u<=n.endColumn;u++)i.push((async()=>{try{if(await a.validatorCell(e,r,l,u)!==t.DataValidationStatus.VALID){let t=this._dataValidationModel.getRuleByLocation(e,r,l,u);if(t){var n;let e=((n=o.getCell(l,u))==null?void 0:n.v)||null,r=this._createDataValidationError(s,l,u,t,e);c.push(r)}}}catch(e){console.warn(`Failed to validate cell [${l}, ${u}]:`,e)}})());await Promise.all(i)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}};r.FWorkbook.extend(g);var _=class extends r.FWorksheet{getDataValidations(){return this._injector.get(i.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new p(e,this._worksheet,this._injector))}getValidatorStatusAsync(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getDataValidation(e){let t=this._injector.get(i.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);return t?new p(t,this._worksheet,this._injector):null}async getAllDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return this._collectValidationErrorsForSheet(e,t)}async _collectValidationErrorsForSheet(e,t){let n=this._injector.get(i.DataValidationModel).getRules(e,t);if(!n.length)return[];let r=n.flatMap(e=>e.ranges);return this._collectValidationErrorsForRange(e,t,r)}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,s=o.getName(),c=[];for(let l of i){let i=[];for(let u=l.startRow;u<=l.endRow;u++)for(let d=l.startColumn;d<=l.endColumn;d++)i.push((async()=>{try{if(await a.validatorCell(e,r,u,d)!==t.DataValidationStatus.VALID){let t=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(e,r,u,d);if(t){var i;let e=((i=o.getCell(u,d))==null?void 0:i.v)||null,n=this._createDataValidationError(s,u,d,t,e);c.push(n)}}}catch(e){console.warn(`Failed to validate cell [${u}, ${d}]:`,e)}})());await Promise.all(i)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}};r.FWorksheet.extend(_);var v=class extends s.FEventName{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`}};s.FEventName.extend(v),e.FDataValidation=p,e.FDataValidationBuilder=f});