@univerjs/sheets-data-validation 0.4.1 → 0.4.2

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/es/index.js CHANGED
@@ -6,7 +6,7 @@ import { Inject, ICommandService, Disposable, ObjectMatrix, Range, Injector, Uni
6
6
  import { DataValidationModel, DataValidatorRegistryService, UpdateRuleType, BaseDataValidator, TextLengthErrorTitleMap, AddDataValidationMutation, RemoveDataValidationMutation, UpdateDataValidationMutation, getRuleSetting, getRuleOptions, UniverDataValidationPlugin } from "@univerjs/data-validation";
7
7
  import { SetRangeValuesMutation, RemoveSheetMutation, getSheetCommandTarget, SetRangeValuesUndoMutationFactory, SheetsSelectionsService, SheetInterceptorService, ClearSelectionAllCommand, WorksheetViewPermission, RefRangeService, handleCommonDefaultRangeChangeWithEffectRefCommands, RemoveSheetCommand } from "@univerjs/sheets";
8
8
  import { Subject, bufferWhen, filter } from "rxjs";
9
- import { LexerTreeBuilder, isReferenceString, sequenceNodeType, deserializeRangeWithSheet, ERROR_TYPE_SET } from "@univerjs/engine-formula";
9
+ import { LexerTreeBuilder, ERROR_TYPE_SET, isReferenceString, sequenceNodeType, deserializeRangeWithSheet, deserializeRangeWithSheetWithCache } from "@univerjs/engine-formula";
10
10
  import { RegisterOtherFormulaService, FormulaRefRangeService } from "@univerjs/sheets-formula";
11
11
  const DATA_VALIDATION_PLUGIN_NAME = "SHEET_DATA_VALIDATION_PLUGIN";
12
12
  var __defProp$9 = Object.defineProperty, __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor, __decorateClass$9 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
@@ -863,7 +863,8 @@ const _RuleMatrix = class _RuleMatrix {
863
863
  type: "update",
864
864
  ruleId: rule.uid,
865
865
  oldRanges,
866
- newRanges
866
+ newRanges: Rectangle.sort(newRanges),
867
+ rule
867
868
  }), newRanges.length === 0 && (mutations.push({
868
869
  type: "delete",
869
870
  rule,
@@ -881,7 +882,8 @@ const _RuleMatrix = class _RuleMatrix {
881
882
  type: "update",
882
883
  ruleId: rule.uid,
883
884
  oldRanges,
884
- newRanges
885
+ newRanges: Rectangle.sort(newRanges),
886
+ rule
885
887
  }), newRanges.length === 0 && (mutations.push({
886
888
  type: "delete",
887
889
  rule,
@@ -894,7 +896,7 @@ const _RuleMatrix = class _RuleMatrix {
894
896
  type: "add",
895
897
  rule: {
896
898
  ...rule,
897
- ranges: newRanges
899
+ ranges: Rectangle.sort(newRanges)
898
900
  }
899
901
  });
900
902
  }), mutations;
@@ -956,16 +958,16 @@ let SheetDataValidationModel = (_a5 = class extends Disposable {
956
958
  for (const [unitId, subUnitMap] of allRules)
957
959
  for (const [subUnitId, rules] of subUnitMap)
958
960
  for (const rule of rules)
959
- this._ruleChange$.next({
961
+ this._addRule(unitId, subUnitId, rule), this._ruleChange$.next({
960
962
  type: "add",
961
963
  unitId,
962
964
  subUnitId,
963
965
  rule,
964
966
  source: "patched"
965
- }), this._addRule(unitId, subUnitId, rule);
967
+ });
966
968
  this.disposeWithMe(
967
969
  this._dataValidationModel.ruleChange$.subscribe((ruleChange) => {
968
- switch (this._ruleChange$.next(ruleChange), ruleChange.type) {
970
+ switch (ruleChange.type) {
969
971
  case "add":
970
972
  this._addRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
971
973
  break;
@@ -976,6 +978,7 @@ let SheetDataValidationModel = (_a5 = class extends Disposable {
976
978
  this._removeRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
977
979
  break;
978
980
  }
981
+ this._ruleChange$.next(ruleChange);
979
982
  })
980
983
  );
981
984
  }
@@ -1112,6 +1115,10 @@ function getFormulaCellData(result) {
1112
1115
  return (_a12 = result == null ? void 0 : result[0]) == null ? void 0 : _a12[0];
1113
1116
  }
1114
1117
  __name(getFormulaCellData, "getFormulaCellData");
1118
+ function isLegalFormulaResult(res) {
1119
+ return !ERROR_TYPE_SET.has(res);
1120
+ }
1121
+ __name(isLegalFormulaResult, "isLegalFormulaResult");
1115
1122
  const CHECKBOX_FORMULA_1 = 1, CHECKBOX_FORMULA_2 = 0;
1116
1123
  function getFailMessage(formula, localeService) {
1117
1124
  return Tools.isBlank(formula) ? localeService.t("dataValidation.validFail.value") : isFormulaString(formula) ? localeService.t("dataValidation.validFail.primitive") : "";
@@ -1151,12 +1158,13 @@ const transformCheckboxValue = /* @__PURE__ */ __name((value) => Tools.isDefine(
1151
1158
  }
1152
1159
  async parseFormula(rule, unitId, subUnitId) {
1153
1160
  var _a12, _b;
1154
- const { formula1 = CHECKBOX_FORMULA_1, formula2 = CHECKBOX_FORMULA_2 } = rule, results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), originFormula1 = isFormulaString(formula1) ? getFormulaResult((_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result) : formula1, originFormula2 = isFormulaString(formula2) ? getFormulaResult((_b = results == null ? void 0 : results[1]) == null ? void 0 : _b.result) : formula2;
1161
+ const { formula1 = CHECKBOX_FORMULA_1, formula2 = CHECKBOX_FORMULA_2 } = rule, results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), originFormula1 = isFormulaString(formula1) ? getFormulaResult((_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result) : formula1, originFormula2 = isFormulaString(formula2) ? getFormulaResult((_b = results == null ? void 0 : results[1]) == null ? void 0 : _b.result) : formula2, isFormulaValid = isLegalFormulaResult(String(originFormula1)) && isLegalFormulaResult(String(originFormula2));
1155
1162
  return {
1156
1163
  formula1: transformCheckboxValue(originFormula1),
1157
1164
  formula2: transformCheckboxValue(originFormula2),
1158
1165
  originFormula1,
1159
- originFormula2
1166
+ originFormula2,
1167
+ isFormulaValid
1160
1168
  };
1161
1169
  }
1162
1170
  getExtraStyle(rule, value) {
@@ -1213,8 +1221,8 @@ var dayjs_min = { exports: {} };
1213
1221
  return { M: c, y: h, w: o, d: a, D: d, h: u, m: s, s: i, ms: r, Q: f }[t2] || String(t2 || "").toLowerCase().replace(/s$/, "");
1214
1222
  }, "p"), u: /* @__PURE__ */ __name(function(t2) {
1215
1223
  return t2 === void 0;
1216
- }, "u") }, g = "en", D2 = {};
1217
- D2[g] = M;
1224
+ }, "u") }, g = "en", D = {};
1225
+ D[g] = M;
1218
1226
  var p = "$isDayjsObject", S = /* @__PURE__ */ __name(function(t2) {
1219
1227
  return t2 instanceof _ || !(!t2 || !t2[p]);
1220
1228
  }, "S"), w = /* @__PURE__ */ __name(function t2(e2, n2, r2) {
@@ -1222,12 +1230,12 @@ var dayjs_min = { exports: {} };
1222
1230
  if (!e2) return g;
1223
1231
  if (typeof e2 == "string") {
1224
1232
  var s2 = e2.toLowerCase();
1225
- D2[s2] && (i2 = s2), n2 && (D2[s2] = n2, i2 = s2);
1233
+ D[s2] && (i2 = s2), n2 && (D[s2] = n2, i2 = s2);
1226
1234
  var u2 = e2.split("-");
1227
1235
  if (!i2 && u2.length > 1) return t2(u2[0]);
1228
1236
  } else {
1229
1237
  var a2 = e2.name;
1230
- D2[a2] = e2, i2 = a2;
1238
+ D[a2] = e2, i2 = a2;
1231
1239
  }
1232
1240
  return !r2 && i2 && (g = i2), i2 || !r2 && g;
1233
1241
  }, "t"), O = /* @__PURE__ */ __name(function(t2, e2) {
@@ -1292,8 +1300,8 @@ var dayjs_min = { exports: {} };
1292
1300
  case c:
1293
1301
  return r2 ? l2(1, M3) : l2(0, M3 + 1);
1294
1302
  case o:
1295
- var g2 = this.$locale().weekStart || 0, D3 = (y2 < g2 ? y2 + 7 : y2) - g2;
1296
- return l2(r2 ? m3 - D3 : m3 + (6 - D3), M3);
1303
+ var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
1304
+ return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
1297
1305
  case a:
1298
1306
  case d:
1299
1307
  return $2(v2 + "Hours", 0);
@@ -1403,18 +1411,18 @@ var dayjs_min = { exports: {} };
1403
1411
  }, m2.utcOffset = function() {
1404
1412
  return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
1405
1413
  }, m2.diff = function(r2, d2, l2) {
1406
- var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D3 = /* @__PURE__ */ __name(function() {
1414
+ var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = /* @__PURE__ */ __name(function() {
1407
1415
  return b.m(y2, m3);
1408
1416
  }, "D");
1409
1417
  switch (M3) {
1410
1418
  case h:
1411
- $2 = D3() / 12;
1419
+ $2 = D2() / 12;
1412
1420
  break;
1413
1421
  case c:
1414
- $2 = D3();
1422
+ $2 = D2();
1415
1423
  break;
1416
1424
  case f:
1417
- $2 = D3() / 3;
1425
+ $2 = D2() / 3;
1418
1426
  break;
1419
1427
  case o:
1420
1428
  $2 = (g2 - v2) / 6048e5;
@@ -1438,7 +1446,7 @@ var dayjs_min = { exports: {} };
1438
1446
  }, m2.daysInMonth = function() {
1439
1447
  return this.endOf(c).$D;
1440
1448
  }, m2.$locale = function() {
1441
- return D2[this.$L];
1449
+ return D[this.$L];
1442
1450
  }, m2.locale = function(t2, e2) {
1443
1451
  if (!t2) return this.$L;
1444
1452
  var n2 = this.clone(), r2 = w(t2, e2, !0);
@@ -1463,7 +1471,7 @@ var dayjs_min = { exports: {} };
1463
1471
  return t2.$i || (t2(e2, _, O), t2.$i = !0), O;
1464
1472
  }, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
1465
1473
  return O(1e3 * t2);
1466
- }, O.en = D2[g], O.Ls = D2, O.p = {}, O;
1474
+ }, O.en = D[g], O.Ls = D, O.p = {}, O;
1467
1475
  });
1468
1476
  })(dayjs_min);
1469
1477
  var dayjs_minExports = dayjs_min.exports;
@@ -1527,10 +1535,11 @@ const DateOperatorTitleMap = {
1527
1535
  }
1528
1536
  async parseFormula(rule, unitId, subUnitId) {
1529
1537
  var _a12, _b;
1530
- const results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule;
1538
+ const results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule, formulaResult1 = getFormulaResult((_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result), formulaResult2 = getFormulaResult((_b = results == null ? void 0 : results[1]) == null ? void 0 : _b.result), isFormulaValid = isLegalFormulaResult(String(formulaResult1)) && isLegalFormulaResult(String(formulaResult2));
1531
1539
  return {
1532
- formula1: transformDate2SerialNumber(isFormulaString(formula1) ? getFormulaResult((_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result) : formula1),
1533
- formula2: transformDate2SerialNumber(isFormulaString(formula2) ? getFormulaResult((_b = results == null ? void 0 : results[1]) == null ? void 0 : _b.result) : formula2)
1540
+ formula1: transformDate2SerialNumber(isFormulaString(formula1) ? formulaResult1 : formula1),
1541
+ formula2: transformDate2SerialNumber(isFormulaString(formula2) ? formulaResult2 : formula2),
1542
+ isFormulaValid
1534
1543
  };
1535
1544
  }
1536
1545
  parseFormulaSync(rule, unitId, subUnitId) {
@@ -1692,11 +1701,12 @@ const _DecimalValidator = class _DecimalValidator extends BaseDataValidator {
1692
1701
  return formula == null ? Number.NaN : +formula;
1693
1702
  }
1694
1703
  async parseFormula(rule, unitId, subUnitId) {
1695
- var _a12, _b, _c, _d, _e, _f, _g, _h;
1696
- const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule;
1704
+ var _a12, _b;
1705
+ const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule, formulaResult1 = getFormulaResult((_a12 = formulaInfo == null ? void 0 : formulaInfo[0]) == null ? void 0 : _a12.result), formulaResult2 = getFormulaResult((_b = formulaInfo == null ? void 0 : formulaInfo[1]) == null ? void 0 : _b.result), isFormulaValid = isLegalFormulaResult(String(formulaResult1)) && isLegalFormulaResult(String(formulaResult2));
1697
1706
  return {
1698
- formula1: this._parseNumber(isFormulaString(formula1) ? (_d = (_c = (_b = (_a12 = formulaInfo == null ? void 0 : formulaInfo[0]) == null ? void 0 : _a12.result) == null ? void 0 : _b[0]) == null ? void 0 : _c[0]) == null ? void 0 : _d.v : formula1),
1699
- formula2: this._parseNumber(isFormulaString(formula2) ? (_h = (_g = (_f = (_e = formulaInfo == null ? void 0 : formulaInfo[1]) == null ? void 0 : _e.result) == null ? void 0 : _f[0]) == null ? void 0 : _g[0]) == null ? void 0 : _h.v : formula2)
1707
+ formula1: this._parseNumber(isFormulaString(formula1) ? formulaResult1 : formula1),
1708
+ formula2: this._parseNumber(isFormulaString(formula2) ? formulaResult2 : formula2),
1709
+ isFormulaValid
1700
1710
  };
1701
1711
  }
1702
1712
  validatorFormula(rule, unitId, subUnitId) {
@@ -1783,7 +1793,7 @@ function getRuleFormulaResultSet(result) {
1783
1793
  resultSet.add(numfmt.format(cell.s.n.pattern, value, { throws: !1 }));
1784
1794
  return;
1785
1795
  }
1786
- resultSet.add(value.toString());
1796
+ isLegalFormulaResult(value.toString()) && resultSet.add(value.toString());
1787
1797
  }
1788
1798
  });
1789
1799
  }
@@ -1855,11 +1865,12 @@ const _ListValidator = class _ListValidator extends BaseDataValidator {
1855
1865
  return deserializeListOptions(cellString);
1856
1866
  }
1857
1867
  async parseFormula(rule, unitId, subUnitId) {
1858
- var _a12;
1859
- const { formula1 = "" } = rule, results = await this.formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);
1868
+ var _a12, _b;
1869
+ const { formula1 = "" } = rule, results = await this.formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), formulaResult1 = getFormulaResult((_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result), isFormulaValid = isLegalFormulaResult(String(formulaResult1));
1860
1870
  return {
1861
- formula1: isFormulaString(formula1) ? getRuleFormulaResultSet((_a12 = results == null ? void 0 : results[0]) == null ? void 0 : _a12.result) : deserializeListOptions(formula1),
1862
- formula2: void 0
1871
+ formula1: isFormulaString(formula1) ? getRuleFormulaResultSet((_b = results == null ? void 0 : results[0]) == null ? void 0 : _b.result) : deserializeListOptions(formula1),
1872
+ formula2: void 0,
1873
+ isFormulaValid
1863
1874
  };
1864
1875
  }
1865
1876
  async isValidType(cellInfo, formula, rule) {
@@ -1947,11 +1958,12 @@ const FORMULA1 = "{FORMULA1}", FORMULA2 = "{FORMULA2}", _TextLengthValidator = c
1947
1958
  return !Number.isNaN(formula);
1948
1959
  }
1949
1960
  async parseFormula(rule, unitId, subUnitId) {
1950
- var _a12, _b, _c, _d, _e, _f, _g, _h;
1951
- const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule;
1961
+ var _a12, _b;
1962
+ const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule, formulaResult1 = getFormulaResult((_a12 = formulaInfo == null ? void 0 : formulaInfo[0]) == null ? void 0 : _a12.result), formulaResult2 = getFormulaResult((_b = formulaInfo == null ? void 0 : formulaInfo[1]) == null ? void 0 : _b.result), isFormulaValid = isLegalFormulaResult(String(formulaResult1)) && isLegalFormulaResult(String(formulaResult2));
1952
1963
  return {
1953
- formula1: this._parseNumber(isFormulaString(formula1) ? (_d = (_c = (_b = (_a12 = formulaInfo == null ? void 0 : formulaInfo[0]) == null ? void 0 : _a12.result) == null ? void 0 : _b[0]) == null ? void 0 : _c[0]) == null ? void 0 : _d.v : formula1),
1954
- formula2: this._parseNumber(isFormulaString(formula2) ? (_h = (_g = (_f = (_e = formulaInfo == null ? void 0 : formulaInfo[1]) == null ? void 0 : _e.result) == null ? void 0 : _f[0]) == null ? void 0 : _g[0]) == null ? void 0 : _h.v : formula2)
1964
+ formula1: this._parseNumber(isFormulaString(formula1) ? formulaResult1 : formula1),
1965
+ formula2: this._parseNumber(isFormulaString(formula2) ? formulaResult2 : formula2),
1966
+ isFormulaValid
1955
1967
  };
1956
1968
  }
1957
1969
  transform(cellInfo, _formula, _rule) {
@@ -2015,7 +2027,7 @@ function isBlankCell(cellData) {
2015
2027
  }
2016
2028
  __name(isBlankCell, "isBlankCell");
2017
2029
  function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, source = "command", fillDefaultValue = !0) {
2018
- const redoMutations = [], undoMutations = [], sheetDataValidationModel = accessor.get(SheetDataValidationModel), univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId });
2030
+ const lexerTreeBuilder = accessor.get(LexerTreeBuilder), redoMutations = [], undoMutations = [], sheetDataValidationModel = accessor.get(SheetDataValidationModel), univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId });
2019
2031
  if (!target)
2020
2032
  return {
2021
2033
  redoMutations,
@@ -2056,7 +2068,7 @@ function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, sour
2056
2068
  });
2057
2069
  break;
2058
2070
  case "update": {
2059
- redoMutations.push({
2071
+ if (redoMutations.push({
2060
2072
  id: UpdateDataValidationMutation.id,
2061
2073
  params: {
2062
2074
  unitId,
@@ -2080,7 +2092,35 @@ function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, sour
2080
2092
  },
2081
2093
  source
2082
2094
  }
2083
- });
2095
+ }), diff.rule.type === DataValidationType.CUSTOM) {
2096
+ const originRow = diff.oldRanges[0].startRow, originColumn = diff.oldRanges[0].startColumn, newRow = diff.newRanges[0].startRow, newColumn = diff.newRanges[0].startColumn, rowDiff = newRow - originRow, columnDiff = newColumn - originColumn, newFormula = lexerTreeBuilder.moveFormulaRefOffset(diff.rule.formula1, columnDiff, rowDiff);
2097
+ newFormula !== diff.rule.formula1 && (redoMutations.push({
2098
+ id: UpdateDataValidationMutation.id,
2099
+ params: {
2100
+ unitId,
2101
+ subUnitId,
2102
+ ruleId: diff.ruleId,
2103
+ payload: {
2104
+ type: UpdateRuleType.SETTING,
2105
+ payload: {
2106
+ ...getRuleSetting(diff.rule),
2107
+ formula1: newFormula
2108
+ }
2109
+ }
2110
+ }
2111
+ }), undoMutations.unshift({
2112
+ id: UpdateDataValidationMutation.id,
2113
+ params: {
2114
+ unitId,
2115
+ subUnitId,
2116
+ ruleId: diff.ruleId,
2117
+ payload: {
2118
+ type: UpdateRuleType.SETTING,
2119
+ payload: getRuleSetting(diff.rule)
2120
+ }
2121
+ }
2122
+ }));
2123
+ }
2084
2124
  const rule = sheetDataValidationModel.getRuleById(unitId, subUnitId, diff.ruleId);
2085
2125
  if (rule && rule.type === DataValidationType.CHECKBOX) {
2086
2126
  const formula = sheetDataValidationModel.getValidator(DataValidationType.CHECKBOX).parseFormulaSync(rule, unitId, subUnitId);
@@ -2388,11 +2428,35 @@ const UpdateSheetDataValidationRangeCommand = {
2388
2428
  unitID: params.unitId
2389
2429
  }), commandService.executeCommand(RemoveDataValidationMutation.id, params), !0;
2390
2430
  }
2391
- }, PLUGIN_CONFIG_KEY = "sheets-data-validation.config", defaultPluginConfig = {};
2392
- function isLegalFormulaResult(res) {
2393
- return !ERROR_TYPE_SET.has(res);
2394
- }
2395
- __name(isLegalFormulaResult, "isLegalFormulaResult");
2431
+ }, PLUGIN_CONFIG_KEY = "sheets-data-validation.config", defaultPluginConfig = {}, _AnyValidator = class _AnyValidator extends BaseDataValidator {
2432
+ constructor() {
2433
+ super(...arguments);
2434
+ __publicField(this, "id", DataValidationType.ANY);
2435
+ __publicField(this, "title", "dataValidation.any.title");
2436
+ __publicField(this, "operators", []);
2437
+ __publicField(this, "scopes", ["sheet"]);
2438
+ }
2439
+ async parseFormula(rule, unitId, subUnitId) {
2440
+ return {
2441
+ formula1: rule.formula1,
2442
+ formula2: rule.formula2,
2443
+ isFormulaValid: !0
2444
+ };
2445
+ }
2446
+ validatorFormula(rule, unitId, subUnitId) {
2447
+ return {
2448
+ success: !0
2449
+ };
2450
+ }
2451
+ async isValidType(cellInfo, formula, rule) {
2452
+ return !0;
2453
+ }
2454
+ generateRuleErrorMessage(rule) {
2455
+ return this.localeService.t("dataValidation.any.error");
2456
+ }
2457
+ };
2458
+ __name(_AnyValidator, "AnyValidator");
2459
+ let AnyValidator = _AnyValidator;
2396
2460
  const _CustomFormulaValidator = class _CustomFormulaValidator extends BaseDataValidator {
2397
2461
  constructor() {
2398
2462
  super(...arguments);
@@ -2412,16 +2476,21 @@ const _CustomFormulaValidator = class _CustomFormulaValidator extends BaseDataVa
2412
2476
  async parseFormula(_rule, _unitId, _subUnitId) {
2413
2477
  return {
2414
2478
  formula1: void 0,
2415
- formula2: void 0
2479
+ formula2: void 0,
2480
+ isFormulaValid: !1
2416
2481
  };
2417
2482
  }
2418
2483
  async isValidType(cellInfo, _formula, _rule) {
2419
2484
  const { column, row, unitId, subUnitId } = cellInfo, result = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, row, column), cellData = getFormulaCellData(result == null ? void 0 : result.result), formulaResult = cellData == null ? void 0 : cellData.v;
2420
- return Tools.isDefine(formulaResult) && formulaResult !== "" ? cellData.t === CellValueType.BOOLEAN ? !!formulaResult : typeof formulaResult == "boolean" ? formulaResult : typeof formulaResult == "number" ? !!formulaResult : typeof formulaResult == "string" ? isLegalFormulaResult(formulaResult) : !!formulaResult : !1;
2485
+ return isLegalFormulaResult(String(formulaResult)) && Tools.isDefine(formulaResult) && formulaResult !== "" ? cellData.t === CellValueType.BOOLEAN ? !!formulaResult : typeof formulaResult == "boolean" ? formulaResult : typeof formulaResult == "number" ? !!formulaResult : typeof formulaResult == "string" ? isLegalFormulaResult(formulaResult) : !!formulaResult : !1;
2421
2486
  }
2422
2487
  generateRuleErrorMessage(rule) {
2423
2488
  return this.localeService.t("dataValidation.custom.error");
2424
2489
  }
2490
+ generateRuleName(rule) {
2491
+ var _a12;
2492
+ return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}", (_a12 = rule.formula1) != null ? _a12 : "");
2493
+ }
2425
2494
  };
2426
2495
  __name(_CustomFormulaValidator, "CustomFormulaValidator");
2427
2496
  let CustomFormulaValidator = _CustomFormulaValidator;
@@ -2472,10 +2541,11 @@ const _WholeValidator = class _WholeValidator extends BaseDataValidator {
2472
2541
  }
2473
2542
  async parseFormula(rule, unitId, subUnitId) {
2474
2543
  var _a12, _b, _c, _d, _e, _f, _g, _h;
2475
- const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule;
2544
+ const formulaInfo = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid), { formula1, formula2 } = rule, formula1Result = isFormulaString(formula1) ? (_d = (_c = (_b = (_a12 = formulaInfo == null ? void 0 : formulaInfo[0]) == null ? void 0 : _a12.result) == null ? void 0 : _b[0]) == null ? void 0 : _c[0]) == null ? void 0 : _d.v : formula1, formula2Result = isFormulaString(formula2) ? (_h = (_g = (_f = (_e = formulaInfo == null ? void 0 : formulaInfo[1]) == null ? void 0 : _e.result) == null ? void 0 : _f[0]) == null ? void 0 : _g[0]) == null ? void 0 : _h.v : formula2, isFormulaValid = isLegalFormulaResult(`${formula1Result}`) && isLegalFormulaResult(`${formula2Result}`);
2476
2545
  return {
2477
- formula1: this._parseNumber(isFormulaString(formula1) ? (_d = (_c = (_b = (_a12 = formulaInfo == null ? void 0 : formulaInfo[0]) == null ? void 0 : _a12.result) == null ? void 0 : _b[0]) == null ? void 0 : _c[0]) == null ? void 0 : _d.v : formula1),
2478
- formula2: this._parseNumber(isFormulaString(formula2) ? (_h = (_g = (_f = (_e = formulaInfo == null ? void 0 : formulaInfo[1]) == null ? void 0 : _e.result) == null ? void 0 : _f[0]) == null ? void 0 : _g[0]) == null ? void 0 : _h.v : formula2)
2546
+ formula1: this._parseNumber(formula1Result),
2547
+ formula2: this._parseNumber(formula2Result),
2548
+ isFormulaValid
2479
2549
  };
2480
2550
  }
2481
2551
  validatorFormula(rule, unitId, subUnitId) {
@@ -2549,6 +2619,7 @@ let DataValidationController = (_a6 = class extends RxDisposable {
2549
2619
  }
2550
2620
  _registerValidators() {
2551
2621
  [
2622
+ AnyValidator,
2552
2623
  DecimalValidator,
2553
2624
  WholeValidator,
2554
2625
  TextLengthValidator,
@@ -2594,7 +2665,7 @@ DataValidationController = __decorateClass$5([
2594
2665
  __decorateParam$5(4, Inject(SheetInterceptorService)),
2595
2666
  __decorateParam$5(5, Inject(SheetDataValidationModel))
2596
2667
  ], DataValidationController);
2597
- var D = /* @__PURE__ */ ((E) => (E[E.View = 0] = "View", E[E.Edit = 1] = "Edit", E[E.ManageCollaborator = 2] = "ManageCollaborator", E[E.Print = 3] = "Print", E[E.Duplicate = 4] = "Duplicate", E[E.Comment = 5] = "Comment", E[E.Copy = 6] = "Copy", E[E.Share = 7] = "Share", E[E.Export = 8] = "Export", E[E.MoveWorksheet = 9] = "MoveWorksheet", E[E.DeleteWorksheet = 10] = "DeleteWorksheet", E[E.HideWorksheet = 11] = "HideWorksheet", E[E.RenameWorksheet = 12] = "RenameWorksheet", E[E.CreateWorksheet = 13] = "CreateWorksheet", E[E.SetWorksheetStyle = 14] = "SetWorksheetStyle", E[E.EditWorksheetCell = 15] = "EditWorksheetCell", E[E.InsertHyperlink = 16] = "InsertHyperlink", E[E.Sort = 17] = "Sort", E[E.Filter = 18] = "Filter", E[E.PivotTable = 19] = "PivotTable", E[E.FloatImg = 20] = "FloatImg", E[E.History = 21] = "History", E[E.RwHgtClWdt = 22] = "RwHgtClWdt", E[E.ViemRwHgtClWdt = 23] = "ViemRwHgtClWdt", E[E.ViewFilter = 24] = "ViewFilter", E[E.MoveSheet = 25] = "MoveSheet", E[E.DeleteSheet = 26] = "DeleteSheet", E[E.HideSheet = 27] = "HideSheet", E[E.CopySheet = 28] = "CopySheet", E[E.RenameSheet = 29] = "RenameSheet", E[E.CreateSheet = 30] = "CreateSheet", E[E.SelectProtectedCells = 31] = "SelectProtectedCells", E[E.SelectUnProtectedCells = 32] = "SelectUnProtectedCells", E[E.SetCellStyle = 33] = "SetCellStyle", E[E.SetCellValue = 34] = "SetCellValue", E[E.SetRowStyle = 35] = "SetRowStyle", E[E.SetColumnStyle = 36] = "SetColumnStyle", E[E.InsertRow = 37] = "InsertRow", E[E.InsertColumn = 38] = "InsertColumn", E[E.DeleteRow = 39] = "DeleteRow", E[E.DeleteColumn = 40] = "DeleteColumn", E[E.EditExtraObject = 41] = "EditExtraObject", E[E.Delete = 42] = "Delete", E[E.RecoverHistory = 43] = "RecoverHistory", E[E.ViewHistory = 44] = "ViewHistory", E[E.UNRECOGNIZED = -1] = "UNRECOGNIZED", E))(D || {}), __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2668
+ var R = /* @__PURE__ */ ((E) => (E[E.View = 0] = "View", E[E.Edit = 1] = "Edit", E[E.ManageCollaborator = 2] = "ManageCollaborator", E[E.Print = 3] = "Print", E[E.Duplicate = 4] = "Duplicate", E[E.Comment = 5] = "Comment", E[E.Copy = 6] = "Copy", E[E.Share = 7] = "Share", E[E.Export = 8] = "Export", E[E.MoveWorksheet = 9] = "MoveWorksheet", E[E.DeleteWorksheet = 10] = "DeleteWorksheet", E[E.HideWorksheet = 11] = "HideWorksheet", E[E.RenameWorksheet = 12] = "RenameWorksheet", E[E.CreateWorksheet = 13] = "CreateWorksheet", E[E.SetWorksheetStyle = 14] = "SetWorksheetStyle", E[E.EditWorksheetCell = 15] = "EditWorksheetCell", E[E.InsertHyperlink = 16] = "InsertHyperlink", E[E.Sort = 17] = "Sort", E[E.Filter = 18] = "Filter", E[E.PivotTable = 19] = "PivotTable", E[E.FloatImg = 20] = "FloatImg", E[E.History = 21] = "History", E[E.RwHgtClWdt = 22] = "RwHgtClWdt", E[E.ViemRwHgtClWdt = 23] = "ViemRwHgtClWdt", E[E.ViewFilter = 24] = "ViewFilter", E[E.MoveSheet = 25] = "MoveSheet", E[E.DeleteSheet = 26] = "DeleteSheet", E[E.HideSheet = 27] = "HideSheet", E[E.CopySheet = 28] = "CopySheet", E[E.RenameSheet = 29] = "RenameSheet", E[E.CreateSheet = 30] = "CreateSheet", E[E.SelectProtectedCells = 31] = "SelectProtectedCells", E[E.SelectUnProtectedCells = 32] = "SelectUnProtectedCells", E[E.SetCellStyle = 33] = "SetCellStyle", E[E.SetCellValue = 34] = "SetCellValue", E[E.SetRowStyle = 35] = "SetRowStyle", E[E.SetColumnStyle = 36] = "SetColumnStyle", E[E.InsertRow = 37] = "InsertRow", E[E.InsertColumn = 38] = "InsertColumn", E[E.DeleteRow = 39] = "DeleteRow", E[E.DeleteColumn = 40] = "DeleteColumn", E[E.EditExtraObject = 41] = "EditExtraObject", E[E.Delete = 42] = "Delete", E[E.RecoverHistory = 43] = "RecoverHistory", E[E.ViewHistory = 44] = "ViewHistory", E[E.CreatePermissionObject = 45] = "CreatePermissionObject", E[E.UNRECOGNIZED = -1] = "UNRECOGNIZED", E))(R || {}), __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2598
2669
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2599
2670
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2600
2671
  return kind && result && __defProp$4(target, key, result), result;
@@ -2612,7 +2683,7 @@ let DataValidationFormulaController = (_a7 = class extends Disposable {
2612
2683
  const node = sequenceNodes[i];
2613
2684
  if (typeof node == "string")
2614
2685
  continue;
2615
- const { token } = node, sequenceGrid = deserializeRangeWithSheet(token), workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
2686
+ const { token } = node, sequenceGrid = deserializeRangeWithSheetWithCache(token), workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
2616
2687
  let targetSheet = workbook.getActiveSheet();
2617
2688
  const unitId = workbook.getUnitId();
2618
2689
  if (sequenceGrid.sheetName) {
@@ -2627,7 +2698,7 @@ let DataValidationFormulaController = (_a7 = class extends Disposable {
2627
2698
  for (let i2 = startRow; i2 <= endRow; i2++)
2628
2699
  for (let j = startColumn; j <= endColumn; j++) {
2629
2700
  const permission = (_b = (_a12 = targetSheet.getCell(i2, j)) == null ? void 0 : _a12.selectionProtection) == null ? void 0 : _b[0];
2630
- if ((permission == null ? void 0 : permission[D.View]) === !1)
2701
+ if ((permission == null ? void 0 : permission[R.View]) === !1)
2631
2702
  return !1;
2632
2703
  }
2633
2704
  }
@@ -2708,18 +2779,21 @@ let DataValidationRefRangeController = (_a8 = class extends Disposable {
2708
2779
  const currentFormula = this._dataValidationCustomFormulaService.getRuleFormulaInfo(unitId, subUnitId, ruleId);
2709
2780
  if (currentFormula) {
2710
2781
  const disposable = this._formulaRefRangeService.registerFormula(
2782
+ unitId,
2783
+ subUnitId,
2711
2784
  currentFormula.formula,
2712
2785
  (newFormulaString) => handleFormulaChange("formula1", newFormulaString)
2713
2786
  );
2714
2787
  disposeSet.add(() => disposable.dispose());
2715
2788
  }
2716
- }
2717
- if (rule.type !== DataValidationType.CUSTOM) {
2789
+ } else {
2718
2790
  const currentFormula = this._dataValidationFormulaService.getRuleFormulaInfo(unitId, subUnitId, ruleId);
2719
2791
  if (currentFormula) {
2720
2792
  const [formula1, formula2] = currentFormula;
2721
2793
  if (formula1) {
2722
2794
  const disposable = this._formulaRefRangeService.registerFormula(
2795
+ unitId,
2796
+ subUnitId,
2723
2797
  formula1.text,
2724
2798
  (newFormulaString) => handleFormulaChange("formula1", newFormulaString)
2725
2799
  );
@@ -2727,6 +2801,8 @@ let DataValidationRefRangeController = (_a8 = class extends Disposable {
2727
2801
  }
2728
2802
  if (formula2) {
2729
2803
  const disposable = this._formulaRefRangeService.registerFormula(
2804
+ unitId,
2805
+ subUnitId,
2730
2806
  formula2.text,
2731
2807
  (newFormulaString) => handleFormulaChange("formula2", newFormulaString)
2732
2808
  );
@@ -3053,6 +3129,7 @@ export {
3053
3129
  getDataValidationDiffMutations,
3054
3130
  getFormulaCellData,
3055
3131
  getFormulaResult,
3132
+ isLegalFormulaResult,
3056
3133
  serializeListOptions,
3057
3134
  transformCheckboxValue
3058
3135
  };
@@ -30,4 +30,5 @@ export { DateValidator } from './validators/date-validator';
30
30
  export { CHECKBOX_FORMULA_1, CHECKBOX_FORMULA_2, CheckboxValidator, transformCheckboxValue } from './validators/checkbox-validator';
31
31
  export { ListMultipleValidator } from './validators/list-multiple-validator';
32
32
  export { deserializeListOptions, getDataValidationCellValue, serializeListOptions } from './validators/util';
33
+ export { isLegalFormulaResult } from './utils/formula';
33
34
  export { AddSheetDataValidationCommand, ClearRangeDataValidationCommand, getDataValidationDiffMutations, type IAddSheetDataValidationCommandParams, type IClearRangeDataValidationCommandParams, type IRemoveSheetAllDataValidationCommandParams, type IRemoveSheetDataValidationCommandParams, type IUpdateSheetDataValidationOptionsCommandParams, type IUpdateSheetDataValidationRangeCommandParams, type IUpdateSheetDataValidationSettingCommandParams, RemoveSheetAllDataValidationCommand, RemoveSheetDataValidationCommand, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationRangeCommand, UpdateSheetDataValidationSettingCommand, } from './commands/commands/data-validation.command';
@@ -4,6 +4,7 @@ export type RangeMutation = {
4
4
  ruleId: string;
5
5
  oldRanges: IRange[];
6
6
  newRanges: IRange[];
7
+ rule: ISheetDataValidationRule;
7
8
  } | {
8
9
  type: 'delete';
9
10
  rule: ISheetDataValidationRule;
@@ -1,3 +1,4 @@
1
1
  import { ICellData, Nullable } from '@univerjs/core';
2
2
  export declare function getFormulaResult(result: Nullable<Nullable<ICellData>[][]>): Nullable<import('@univerjs/core').CellValue>;
3
3
  export declare function getFormulaCellData(result: Nullable<Nullable<ICellData>[][]>): Nullable<ICellData>;
4
+ export declare function isLegalFormulaResult(res: string): boolean;
@@ -0,0 +1,12 @@
1
+ import { CellValue, DataValidationOperator, IDataValidationRule, IDataValidationRuleBase } from '@univerjs/core';
2
+ import { IFormulaResult, IFormulaValidResult, IValidatorCellInfo, BaseDataValidator } from '@univerjs/data-validation';
3
+ export declare class AnyValidator extends BaseDataValidator {
4
+ id: string;
5
+ title: string;
6
+ operators: DataValidationOperator[];
7
+ scopes: string | string[];
8
+ parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult>;
9
+ validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult;
10
+ isValidType(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean>;
11
+ generateRuleErrorMessage(rule: IDataValidationRuleBase): string;
12
+ }
@@ -10,4 +10,5 @@ export declare class CustomFormulaValidator extends BaseDataValidator {
10
10
  parseFormula(_rule: IDataValidationRule, _unitId: string, _subUnitId: string): Promise<IFormulaResult>;
11
11
  isValidType(cellInfo: IValidatorCellInfo<CellValue>, _formula: IFormulaResult, _rule: IDataValidationRule): Promise<boolean>;
12
12
  generateRuleErrorMessage(rule: IDataValidationRuleBase): string;
13
+ generateRuleName(rule: IDataValidationRuleBase): string;
13
14
  }
@@ -24,6 +24,7 @@ export declare class DecimalValidator extends BaseDataValidator<number> {
24
24
  parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<{
25
25
  formula1: number;
26
26
  formula2: number;
27
+ isFormulaValid: boolean;
27
28
  }>;
28
29
  validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult;
29
30
  validatorIsEqual(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean>;
@@ -23,6 +23,7 @@ export declare class WholeValidator extends BaseDataValidator<number> {
23
23
  parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<{
24
24
  formula1: number;
25
25
  formula2: number;
26
+ isFormulaValid: boolean;
26
27
  }>;
27
28
  validatorFormula(rule: IDataValidationRuleBase, unitId: string, subUnitId: string): IFormulaValidResult;
28
29
  validatorIsEqual(cellInfo: IValidatorCellInfo<CellValue>, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean>;