@univerjs/sheets-data-validation 1.0.0-alpha.7 → 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/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { CellValueType, CommandType, DataValidationOperator, DataValidationRenderMode, DataValidationStatus, DataValidationType, DependentOn, Disposable, ICommandService, IConfigService, IPermissionService, IUndoRedoService, IUniverInstanceService, Inject, Injector, LifecycleService, LifecycleStages, ObjectMatrix, Plugin, RBush, Range, Rectangle, RxDisposable, Tools, UniverInstanceType, WrapStrategy, bufferDebounceTime, dateKit, debounce, generateRandomId, getIntersectRange, getOriginCellValue, isFormulaString, isRangesEqual, merge, numfmt, sequenceExecute, toDisposable } from "@univerjs/core";
2
2
  import { AddDataValidationMutation, BaseDataValidator, DataValidationModel, DataValidatorRegistryService, RemoveDataValidationMutation, UniverDataValidationPlugin, UpdateDataValidationMutation, UpdateRuleType, getRuleOptions, getRuleSetting } from "@univerjs/data-validation";
3
- import { ERROR_TYPE_SET, LexerTreeBuilder, OtherFormulaBizType, RegisterOtherFormulaService, deserializeRangeWithSheet, deserializeRangeWithSheetWithCache, isReferenceString, operatorToken, sequenceNodeType } from "@univerjs/engine-formula";
4
- import { ClearSelectionAllCommand, CopySheetCommand, RefRangeService, RemoveSheetCommand, RemoveSheetMutation, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SheetInterceptorService, SheetsSelectionsService, WorksheetViewPermission, deserializeListOptions, getSheetCommandTarget, handleCommonDefaultRangeChangeWithEffectRefCommands } from "@univerjs/sheets";
3
+ import { ERROR_TYPE_SET, LexerTreeBuilder, OtherFormulaBizType, RegisterOtherFormulaService, UniverFormulaEnginePlugin, deserializeRangeWithSheet, deserializeRangeWithSheetWithCache, isReferenceString, operatorToken, sequenceNodeType } from "@univerjs/engine-formula";
4
+ import { ClearSelectionAllCommand, CopySheetCommand, RefRangeService, RemoveSheetCommand, RemoveSheetMutation, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SheetInterceptorService, SheetsSelectionsService, UniverSheetsPlugin, WorksheetViewPermission, deserializeListOptions, getSheetCommandTarget, handleCommonDefaultRangeChangeWithEffectRefCommands } from "@univerjs/sheets";
5
5
  import { Subject, bufferWhen, filter, skip } from "rxjs";
6
6
  import { UnitAction } from "@univerjs/protocol";
7
7
  import { FormulaRefRangeService, UniverSheetsFormulaPlugin } from "@univerjs/sheets-formula";
8
8
 
9
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
9
+ //#region \0@oxc-project+runtime@0.140.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) {
@@ -17,7 +17,7 @@ function _typeof(o) {
17
17
  }
18
18
 
19
19
  //#endregion
20
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
20
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
21
21
  function toPrimitive(t, r) {
22
22
  if ("object" != _typeof(t) || !t) return t;
23
23
  var e = t[Symbol.toPrimitive];
@@ -30,14 +30,14 @@ function toPrimitive(t, r) {
30
30
  }
31
31
 
32
32
  //#endregion
33
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
33
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
34
34
  function toPropertyKey(t) {
35
35
  var i = toPrimitive(t, "string");
36
36
  return "symbol" == _typeof(i) ? i : i + "";
37
37
  }
38
38
 
39
39
  //#endregion
40
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
40
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
41
41
  function _defineProperty(e, r, t) {
42
42
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
43
43
  value: t,
@@ -48,7 +48,7 @@ function _defineProperty(e, r, t) {
48
48
  }
49
49
 
50
50
  //#endregion
51
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
51
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
52
52
  function __decorateParam(paramIndex, decorator) {
53
53
  return function(target, key) {
54
54
  decorator(target, key, paramIndex);
@@ -56,7 +56,7 @@ function __decorateParam(paramIndex, decorator) {
56
56
  }
57
57
 
58
58
  //#endregion
59
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
59
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
60
60
  function __decorate(decorators, target, key, desc) {
61
61
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
62
62
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -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.getUniverSheetInstance(currentUnitId) : 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);
@@ -1892,7 +1881,7 @@ function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, sour
1892
1881
  params: {
1893
1882
  unitId,
1894
1883
  subUnitId,
1895
- cellValue: redoMatrix.getData()
1884
+ cellValue: redoMatrix.clone()
1896
1885
  }
1897
1886
  };
1898
1887
  const undoSetRangeValues = {
@@ -2057,7 +2046,7 @@ const UpdateSheetDataValidationSettingCommand = {
2057
2046
  params: {
2058
2047
  unitId,
2059
2048
  subUnitId,
2060
- cellValue: redoMatrix.getData()
2049
+ cellValue: redoMatrix.clone()
2061
2050
  }
2062
2051
  };
2063
2052
  const undoSetRangeValues = {
@@ -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.7";
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
  }
@@ -2703,7 +2690,7 @@ let SheetDataValidationSheetController = class SheetDataValidationSheetControlle
2703
2690
  var _workbook$getActiveSh;
2704
2691
  const params = commandInfo.params;
2705
2692
  const unitId = params.unitId || this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET).getUnitId();
2706
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
2693
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
2707
2694
  if (!workbook) return {
2708
2695
  redos: [],
2709
2696
  undos: []
@@ -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
  }
@@ -3270,7 +3252,7 @@ _defineProperty(UniverSheetsDataValidationPlugin, "packageName", name);
3270
3252
  _defineProperty(UniverSheetsDataValidationPlugin, "version", version);
3271
3253
  _defineProperty(UniverSheetsDataValidationPlugin, "type", UniverInstanceType.UNIVER_SHEET);
3272
3254
  UniverSheetsDataValidationPlugin = __decorate([
3273
- DependentOn(UniverSheetsFormulaPlugin, UniverDataValidationPlugin),
3255
+ DependentOn(UniverDataValidationPlugin, UniverFormulaEnginePlugin, UniverSheetsPlugin, UniverSheetsFormulaPlugin),
3274
3256
  __decorateParam(1, Inject(Injector)),
3275
3257
  __decorateParam(2, ICommandService),
3276
3258
  __decorateParam(3, IConfigService)
@@ -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,
@@ -24,7 +24,7 @@ import { FDataValidation } from './f-data-validation';
24
24
  export interface IFRangeSheetsDataValidationMixin {
25
25
  /**
26
26
  * Set a data validation rule to current range. if rule is null, clear data validation rule.
27
- * @param {Nullable<FDataValidation>} rule data validation rule, build by `FUniver.newDataValidation`
27
+ * @param {Nullable<FDataValidation>} rule data validation rule, built by `univerAPI.newDataValidation()`
28
28
  * @returns current range
29
29
  * @example
30
30
  * ```ts
@@ -45,11 +45,6 @@ export interface IFUniverSheetsDataValidationMixin {
45
45
  newDataValidation(): FDataValidationBuilder;
46
46
  }
47
47
  export declare class FUniverSheetsDataValidationMixin extends FUniver implements IFUniverSheetsDataValidationMixin {
48
- /**
49
- * @deprecated use `univerAPI.newDataValidation()` as instead.
50
- * @returns {FDataValidationBuilder} A new instance of the FDataValidationBuilder class
51
- */
52
- static newDataValidation(): FDataValidationBuilder;
53
48
  newDataValidation(): FDataValidationBuilder;
54
49
  /**
55
50
  * @ignore
@@ -57,16 +52,6 @@ export declare class FUniverSheetsDataValidationMixin extends FUniver implements
57
52
  _initialize(injector: Injector): void;
58
53
  }
59
54
  declare module '@univerjs/core/facade' {
60
- /**
61
- * @ignore
62
- */
63
- namespace FUniver {
64
- /**
65
- * @deprecated use `univerAPI.newDataValidation()` as instead.
66
- * @returns {FDataValidationBuilder} A new instance of the FDataValidationBuilder class
67
- */
68
- function newDataValidation(): FDataValidationBuilder;
69
- }
70
55
  interface FUniver extends IFUniverSheetsDataValidationMixin {
71
56
  }
72
57
  }
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?!0: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?!0: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{static newDataValidation(){return new f}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});