@univerjs/sheets-data-validation 1.0.0-insiders.20260813-7c9aa50 → 1.0.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.
Files changed (96) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +10 -2
  3. package/lib/cjs/facade.js +19 -12
  4. package/lib/cjs/index.js +122 -68
  5. package/lib/cjs/locale/ar-SA.js +5 -26
  6. package/lib/cjs/locale/ca-ES.js +5 -26
  7. package/lib/cjs/locale/de-DE.js +5 -26
  8. package/lib/cjs/locale/en-US.js +5 -26
  9. package/lib/cjs/locale/es-ES.js +5 -26
  10. package/lib/cjs/locale/fa-IR.js +5 -26
  11. package/lib/cjs/locale/fr-FR.js +5 -26
  12. package/lib/cjs/locale/id-ID.js +5 -26
  13. package/lib/cjs/locale/it-IT.js +5 -26
  14. package/lib/cjs/locale/ja-JP.js +5 -26
  15. package/lib/cjs/locale/ko-KR.js +5 -26
  16. package/lib/cjs/locale/pl-PL.js +5 -26
  17. package/lib/cjs/locale/pt-BR.js +5 -26
  18. package/lib/cjs/locale/ru-RU.js +5 -26
  19. package/lib/cjs/locale/sk-SK.js +5 -26
  20. package/lib/cjs/locale/vi-VN.js +5 -26
  21. package/lib/cjs/locale/zh-CN.js +5 -26
  22. package/lib/cjs/locale/zh-HK.js +5 -26
  23. package/lib/cjs/locale/zh-TW.js +5 -26
  24. package/lib/es/facade.js +20 -13
  25. package/lib/es/index.js +123 -70
  26. package/lib/es/locale/ar-SA.js +5 -25
  27. package/lib/es/locale/ca-ES.js +5 -25
  28. package/lib/es/locale/de-DE.js +5 -25
  29. package/lib/es/locale/en-US.js +5 -25
  30. package/lib/es/locale/es-ES.js +5 -25
  31. package/lib/es/locale/fa-IR.js +5 -25
  32. package/lib/es/locale/fr-FR.js +5 -25
  33. package/lib/es/locale/id-ID.js +5 -25
  34. package/lib/es/locale/it-IT.js +5 -25
  35. package/lib/es/locale/ja-JP.js +5 -25
  36. package/lib/es/locale/ko-KR.js +5 -25
  37. package/lib/es/locale/pl-PL.js +5 -25
  38. package/lib/es/locale/pt-BR.js +5 -25
  39. package/lib/es/locale/ru-RU.js +5 -25
  40. package/lib/es/locale/sk-SK.js +5 -25
  41. package/lib/es/locale/vi-VN.js +5 -25
  42. package/lib/es/locale/zh-CN.js +5 -25
  43. package/lib/es/locale/zh-HK.js +5 -25
  44. package/lib/es/locale/zh-TW.js +5 -25
  45. package/lib/facade.js +20 -13
  46. package/lib/index.js +123 -70
  47. package/lib/locale/ar-SA.js +5 -25
  48. package/lib/locale/ca-ES.js +5 -25
  49. package/lib/locale/de-DE.js +5 -25
  50. package/lib/locale/en-US.js +5 -25
  51. package/lib/locale/es-ES.js +5 -25
  52. package/lib/locale/fa-IR.js +5 -25
  53. package/lib/locale/fr-FR.js +5 -25
  54. package/lib/locale/id-ID.js +5 -25
  55. package/lib/locale/it-IT.js +5 -25
  56. package/lib/locale/ja-JP.js +5 -25
  57. package/lib/locale/ko-KR.js +5 -25
  58. package/lib/locale/pl-PL.js +5 -25
  59. package/lib/locale/pt-BR.js +5 -25
  60. package/lib/locale/ru-RU.js +5 -25
  61. package/lib/locale/sk-SK.js +5 -25
  62. package/lib/locale/vi-VN.js +5 -25
  63. package/lib/locale/zh-CN.js +5 -25
  64. package/lib/locale/zh-HK.js +5 -25
  65. package/lib/locale/zh-TW.js +5 -25
  66. package/lib/types/facade/f-data-validation.d.ts +5 -2
  67. package/lib/types/facade/f-range.d.ts +1 -1
  68. package/lib/types/facade/f-workbook.d.ts +3 -3
  69. package/lib/types/facade/f-worksheet.d.ts +5 -2
  70. package/lib/types/index.d.ts +1 -0
  71. package/lib/types/locale/en-US.d.ts +0 -18
  72. package/lib/types/services/dv-cache.service.d.ts +1 -0
  73. package/lib/types/utils/range.d.ts +18 -0
  74. package/lib/types/validators/date-validator.d.ts +3 -1
  75. package/lib/umd/facade.js +1 -1
  76. package/lib/umd/index.js +1 -1
  77. package/lib/umd/locale/ar-SA.js +1 -1
  78. package/lib/umd/locale/ca-ES.js +1 -1
  79. package/lib/umd/locale/de-DE.js +1 -1
  80. package/lib/umd/locale/en-US.js +1 -1
  81. package/lib/umd/locale/es-ES.js +1 -1
  82. package/lib/umd/locale/fa-IR.js +1 -1
  83. package/lib/umd/locale/fr-FR.js +1 -1
  84. package/lib/umd/locale/id-ID.js +1 -1
  85. package/lib/umd/locale/it-IT.js +1 -1
  86. package/lib/umd/locale/ja-JP.js +1 -1
  87. package/lib/umd/locale/ko-KR.js +1 -1
  88. package/lib/umd/locale/pl-PL.js +1 -1
  89. package/lib/umd/locale/pt-BR.js +1 -1
  90. package/lib/umd/locale/ru-RU.js +1 -1
  91. package/lib/umd/locale/sk-SK.js +1 -1
  92. package/lib/umd/locale/vi-VN.js +1 -1
  93. package/lib/umd/locale/zh-CN.js +1 -1
  94. package/lib/umd/locale/zh-HK.js +1 -1
  95. package/lib/umd/locale/zh-TW.js +1 -1
  96. package/package.json +9 -9
package/lib/cjs/index.js CHANGED
@@ -7,7 +7,36 @@ let rxjs = require("rxjs");
7
7
  let _univerjs_protocol = require("@univerjs/protocol");
8
8
  let _univerjs_sheets_formula = require("@univerjs/sheets-formula");
9
9
 
10
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
10
+ //#region src/utils/range.ts
11
+ function getRangeInWorksheet(range, worksheet) {
12
+ const maxRows = worksheet.getMaxRows();
13
+ const maxColumns = worksheet.getMaxColumns();
14
+ if (maxRows <= 0 || maxColumns <= 0) return null;
15
+ const effectiveRange = (0, _univerjs_core.getIntersectRange)(_univerjs_core.Range.transformRange(range, worksheet), {
16
+ startRow: 0,
17
+ endRow: maxRows - 1,
18
+ startColumn: 0,
19
+ endColumn: maxColumns - 1
20
+ });
21
+ if (!effectiveRange) return null;
22
+ return {
23
+ startRow: effectiveRange.startRow,
24
+ endRow: effectiveRange.endRow,
25
+ startColumn: effectiveRange.startColumn,
26
+ endColumn: effectiveRange.endColumn
27
+ };
28
+ }
29
+ function getRangesInWorksheet(ranges, worksheet) {
30
+ const effectiveRanges = [];
31
+ ranges.forEach((range) => {
32
+ const effectiveRange = getRangeInWorksheet(range, worksheet);
33
+ if (effectiveRange) effectiveRanges.push(effectiveRange);
34
+ });
35
+ return effectiveRanges;
36
+ }
37
+
38
+ //#endregion
39
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
11
40
  function _typeof(o) {
12
41
  "@babel/helpers - typeof";
13
42
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -18,7 +47,7 @@ function _typeof(o) {
18
47
  }
19
48
 
20
49
  //#endregion
21
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
50
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
22
51
  function toPrimitive(t, r) {
23
52
  if ("object" != _typeof(t) || !t) return t;
24
53
  var e = t[Symbol.toPrimitive];
@@ -31,14 +60,14 @@ function toPrimitive(t, r) {
31
60
  }
32
61
 
33
62
  //#endregion
34
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
63
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
35
64
  function toPropertyKey(t) {
36
65
  var i = toPrimitive(t, "string");
37
66
  return "symbol" == _typeof(i) ? i : i + "";
38
67
  }
39
68
 
40
69
  //#endregion
41
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
70
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
42
71
  function _defineProperty(e, r, t) {
43
72
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
44
73
  value: t,
@@ -49,7 +78,7 @@ function _defineProperty(e, r, t) {
49
78
  }
50
79
 
51
80
  //#endregion
52
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
81
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
53
82
  function __decorateParam(paramIndex, decorator) {
54
83
  return function(target, key) {
55
84
  decorator(target, key, paramIndex);
@@ -57,7 +86,7 @@ function __decorateParam(paramIndex, decorator) {
57
86
  }
58
87
 
59
88
  //#endregion
60
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
89
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
61
90
  function __decorate(decorators, target, key, desc) {
62
91
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
63
92
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -133,9 +162,15 @@ let DataValidationCacheService = class DataValidationCacheService extends _unive
133
162
  removeRule(unitId, subUnitId, rule) {
134
163
  this._deleteRange(unitId, subUnitId, rule.ranges);
135
164
  }
165
+ _getEffectiveRanges(unitId, subUnitId, ranges) {
166
+ var _this$_univerInstance;
167
+ const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
168
+ if (!worksheet) return [];
169
+ return getRangesInWorksheet(ranges, worksheet);
170
+ }
136
171
  markRangeDirty(unitId, subUnitId, ranges, isSetRange) {
137
172
  const cache = this._ensureCache(unitId, subUnitId);
138
- ranges.forEach((range) => {
173
+ this._getEffectiveRanges(unitId, subUnitId, ranges).forEach((range) => {
139
174
  _univerjs_core.Range.foreach(range, (row, col) => {
140
175
  if (cache.getValue(row, col) !== void 0) cache.setValue(row, col, void 0);
141
176
  });
@@ -149,7 +184,7 @@ let DataValidationCacheService = class DataValidationCacheService extends _unive
149
184
  }
150
185
  _deleteRange(unitId, subUnitId, ranges) {
151
186
  const cache = this._ensureCache(unitId, subUnitId);
152
- ranges.forEach((range) => {
187
+ this._getEffectiveRanges(unitId, subUnitId, ranges).forEach((range) => {
153
188
  _univerjs_core.Range.foreach(range, (row, col) => {
154
189
  cache.realDeleteValue(row, col);
155
190
  });
@@ -286,11 +321,16 @@ let DataValidationCustomFormulaService = class DataValidationCustomFormulaServic
286
321
  }
287
322
  }
288
323
  _addFormulaByRange(unitId, subUnitId, ruleId, formula, formula2, ranges) {
324
+ var _this$_instanceSrv$ge;
289
325
  const { ruleFormulaMap, ruleFormulaMap2 } = this._ensureMaps(unitId, subUnitId);
290
- const originRow = ranges[0].startRow;
291
- const originCol = ranges[0].startColumn;
326
+ const worksheet = (_this$_instanceSrv$ge = this._instanceSrv.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_instanceSrv$ge === void 0 ? void 0 : _this$_instanceSrv$ge.getSheetBySheetId(subUnitId);
327
+ if (!worksheet) return;
328
+ const effectiveRanges = getRangesInWorksheet(ranges, worksheet);
329
+ if (!effectiveRanges.length) return;
330
+ const originRow = effectiveRanges[0].startRow;
331
+ const originCol = effectiveRanges[0].startColumn;
292
332
  if (formula && (0, _univerjs_core.isFormulaString)(formula)) {
293
- const formulaId = this._registerFormula(unitId, subUnitId, ruleId, formula, ranges);
333
+ const formulaId = this._registerFormula(unitId, subUnitId, ruleId, formula, effectiveRanges);
294
334
  ruleFormulaMap.set(ruleId, {
295
335
  formula,
296
336
  originCol,
@@ -299,7 +339,7 @@ let DataValidationCustomFormulaService = class DataValidationCustomFormulaServic
299
339
  });
300
340
  }
301
341
  if (formula2 && (0, _univerjs_core.isFormulaString)(formula2)) {
302
- const formulaId2 = this._registerFormula(unitId, subUnitId, ruleId, formula2, ranges);
342
+ const formulaId2 = this._registerFormula(unitId, subUnitId, ruleId, formula2, effectiveRanges);
303
343
  ruleFormulaMap2.set(ruleId, {
304
344
  formula: formula2,
305
345
  originCol,
@@ -838,9 +878,7 @@ let SheetDataValidationModel = class SheetDataValidationModel extends _univerjs_
838
878
  case "update":
839
879
  this._updateRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule.uid, ruleChange.oldRule, ruleChange.updatePayload);
840
880
  break;
841
- case "remove":
842
- this._removeRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
843
- break;
881
+ case "remove": this._removeRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
844
882
  }
845
883
  this._ruleChange$.next(ruleChange);
846
884
  }));
@@ -1274,14 +1312,15 @@ function getTransformedFormula(lexerTreeBuilder, rule, position) {
1274
1312
 
1275
1313
  //#endregion
1276
1314
  //#region src/validators/date-validator.ts
1277
- const transformDate2SerialNumber = (value) => {
1278
- var _numfmt$parseDate, _numfmt$parseDate2;
1315
+ const transformDate2SerialNumber = (value, options = {}) => {
1316
+ var _numfmt$parseDate;
1279
1317
  if (value === void 0 || value === null || typeof value === "boolean") return;
1280
1318
  if (typeof value === "number" || !Number.isNaN(+value)) return +value;
1281
- const v = (_numfmt$parseDate = _univerjs_core.numfmt.parseDate(value)) === null || _numfmt$parseDate === void 0 ? void 0 : _numfmt$parseDate.v;
1282
- if (_univerjs_core.Tools.isDefine(v)) return v;
1283
- return (_numfmt$parseDate2 = _univerjs_core.numfmt.parseDate((0, _univerjs_core.dateKit)(value).format("YYYY-MM-DD HH:mm:ss"))) === null || _numfmt$parseDate2 === void 0 ? void 0 : _numfmt$parseDate2.v;
1319
+ return (_numfmt$parseDate = _univerjs_core.numfmt.parseDate(value, options)) === null || _numfmt$parseDate === void 0 ? void 0 : _numfmt$parseDate.v;
1284
1320
  };
1321
+ function pad(value) {
1322
+ return String(value).padStart(2, "0");
1323
+ }
1285
1324
  var DateValidator = class extends BaseSheetValidator {
1286
1325
  constructor(..._args) {
1287
1326
  super(..._args);
@@ -1301,6 +1340,14 @@ var DateValidator = class extends BaseSheetValidator {
1301
1340
  _defineProperty(this, "scopes", ["sheet"]);
1302
1341
  _defineProperty(this, "_customFormulaService", this.injector.get(DataValidationCustomFormulaService));
1303
1342
  _defineProperty(this, "_lexerTreeBuilder", this.injector.get(_univerjs_engine_formula.LexerTreeBuilder));
1343
+ _defineProperty(this, "_univerInstanceService", this.injector.get(_univerjs_core.IUniverInstanceService));
1344
+ }
1345
+ _getParseOptions(unitId, workbook) {
1346
+ const targetWorkbook = workbook ?? (unitId ? this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET) : void 0);
1347
+ return targetWorkbook ? {
1348
+ locale: (0, _univerjs_core.getNumfmtLocaleTag)(targetWorkbook.getSnapshot().locale),
1349
+ dateSystem: targetWorkbook.getDateSystem()
1350
+ } : { dateSystem: _univerjs_core.DateSystem.Date1900 };
1304
1351
  }
1305
1352
  async parseFormula(rule, unitId, subUnitId, row, column) {
1306
1353
  const formulaResult1 = await this._customFormulaService.getCellFormulaValue(unitId, subUnitId, rule.uid, row, column);
@@ -1308,27 +1355,29 @@ var DateValidator = class extends BaseSheetValidator {
1308
1355
  const { formula1, formula2 } = rule;
1309
1356
  const isFormulaValid = isLegalFormulaResult(String(formulaResult1 === null || formulaResult1 === void 0 ? void 0 : formulaResult1.v)) && isLegalFormulaResult(String(formulaResult2 === null || formulaResult2 === void 0 ? void 0 : formulaResult2.v));
1310
1357
  return {
1311
- formula1: transformDate2SerialNumber((0, _univerjs_core.isFormulaString)(formula1) ? formulaResult1 === null || formulaResult1 === void 0 ? void 0 : formulaResult1.v : formula1),
1312
- formula2: transformDate2SerialNumber((0, _univerjs_core.isFormulaString)(formula2) ? formulaResult2 === null || formulaResult2 === void 0 ? void 0 : formulaResult2.v : formula2),
1358
+ formula1: transformDate2SerialNumber((0, _univerjs_core.isFormulaString)(formula1) ? formulaResult1 === null || formulaResult1 === void 0 ? void 0 : formulaResult1.v : formula1, this._getParseOptions(unitId)),
1359
+ formula2: transformDate2SerialNumber((0, _univerjs_core.isFormulaString)(formula2) ? formulaResult2 === null || formulaResult2 === void 0 ? void 0 : formulaResult2.v : formula2, this._getParseOptions(unitId)),
1313
1360
  isFormulaValid
1314
1361
  };
1315
1362
  }
1316
1363
  async isValidType(info) {
1317
1364
  const { interceptValue, value } = info;
1318
- if (typeof value === "number" && typeof interceptValue === "string") return Boolean(_univerjs_core.numfmt.parseDate(interceptValue));
1319
- if (typeof interceptValue === "string") return Boolean(_univerjs_core.numfmt.parseDate(interceptValue));
1365
+ const options = this._getParseOptions(info.unitId, info.workbook);
1366
+ if (typeof value === "number" && typeof interceptValue === "string") return Boolean(_univerjs_core.numfmt.parseDate(interceptValue, options));
1367
+ if (typeof interceptValue === "string") return Boolean(_univerjs_core.numfmt.parseDate(interceptValue, options));
1320
1368
  return false;
1321
1369
  }
1322
- _validatorSingleFormula(formula) {
1323
- return !_univerjs_core.Tools.isBlank(formula) && ((0, _univerjs_core.isFormulaString)(formula) || !Number.isNaN(+formula) || Boolean(formula && _univerjs_core.numfmt.parseDate(formula)));
1370
+ _validatorSingleFormula(formula, options) {
1371
+ return !_univerjs_core.Tools.isBlank(formula) && ((0, _univerjs_core.isFormulaString)(formula) || !Number.isNaN(+formula) || Boolean(formula && _univerjs_core.numfmt.parseDate(formula, options)));
1324
1372
  }
1325
1373
  validatorFormula(rule, unitId, subUnitId) {
1326
1374
  const operator = rule.operator;
1327
1375
  if (!operator) return { success: true };
1328
- const formula1Success = this._validatorSingleFormula(rule.formula1);
1376
+ const options = this._getParseOptions(unitId);
1377
+ const formula1Success = this._validatorSingleFormula(rule.formula1, options);
1329
1378
  const errorMsg = this.localeService.t("sheets-data-validation.validFail.date");
1330
1379
  if (TWO_FORMULA_OPERATOR_COUNT.includes(operator)) {
1331
- const formula2Success = this._validatorSingleFormula(rule.formula2);
1380
+ const formula2Success = this._validatorSingleFormula(rule.formula2, options);
1332
1381
  return {
1333
1382
  success: formula1Success && formula2Success,
1334
1383
  formula1: formula1Success ? void 0 : errorMsg,
@@ -1340,19 +1389,18 @@ var DateValidator = class extends BaseSheetValidator {
1340
1389
  formula1: formula1Success ? void 0 : errorMsg
1341
1390
  };
1342
1391
  }
1343
- normalizeFormula(rule, _unitId, _subUnitId) {
1392
+ normalizeFormula(rule, unitId, _subUnitId) {
1344
1393
  const { formula1, formula2, bizInfo } = rule;
1394
+ const options = this._getParseOptions(unitId);
1345
1395
  const normlizeSingleFormula = (formula) => {
1396
+ var _numfmt$parseDate2;
1346
1397
  if (!formula) return formula;
1347
- let date;
1348
- if (!Number.isNaN(+formula)) date = _univerjs_core.numfmt.dateFromSerial(+formula);
1349
- else {
1350
- var _numfmt$parseDate3;
1351
- const res = (_numfmt$parseDate3 = _univerjs_core.numfmt.parseDate(formula)) === null || _numfmt$parseDate3 === void 0 ? void 0 : _numfmt$parseDate3.v;
1352
- if (res === void 0 || res === null) return "";
1353
- date = _univerjs_core.numfmt.dateFromSerial(res);
1354
- }
1355
- return (0, _univerjs_core.dateKit)(`${date[0]}/${date[1]}/${date[2]} ${date[3]}:${date[4]}:${date[5]}`).format((bizInfo === null || bizInfo === void 0 ? void 0 : bizInfo.showTime) ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD");
1398
+ const serial = !Number.isNaN(+formula) ? +formula : (_numfmt$parseDate2 = _univerjs_core.numfmt.parseDate(formula, options)) === null || _numfmt$parseDate2 === void 0 ? void 0 : _numfmt$parseDate2.v;
1399
+ if (typeof serial !== "number") return "";
1400
+ const date = (0, _univerjs_core.excelSerialToDateTimeParts)(serial, { dateSystem: options.dateSystem ?? _univerjs_core.DateSystem.Date1900 });
1401
+ if (!date) return "";
1402
+ const dateText = `${String(date.year).padStart(4, "0")}-${pad(date.month)}-${pad(date.day)}`;
1403
+ return (bizInfo === null || bizInfo === void 0 ? void 0 : bizInfo.showTime) ? `${dateText} ${pad(date.hours)}:${pad(date.minutes)}:${pad(date.seconds)}` : dateText;
1356
1404
  };
1357
1405
  return {
1358
1406
  formula1: (0, _univerjs_core.isFormulaString)(formula1) ? formula1 : normlizeSingleFormula(`${formula1}`),
@@ -1363,7 +1411,7 @@ var DateValidator = class extends BaseSheetValidator {
1363
1411
  const { value } = cellInfo;
1364
1412
  return {
1365
1413
  ...cellInfo,
1366
- value: transformDate2SerialNumber(value)
1414
+ value: transformDate2SerialNumber(value, this._getParseOptions(cellInfo.unitId, cellInfo.workbook))
1367
1415
  };
1368
1416
  }
1369
1417
  get operatorNames() {
@@ -1542,7 +1590,8 @@ var ListValidator = class extends BaseSheetValidator {
1542
1590
  return { tb };
1543
1591
  }
1544
1592
  parseCellValue(cellValue) {
1545
- return (0, _univerjs_sheets.deserializeListOptions)(cellValue.toString());
1593
+ const cellString = cellValue.toString();
1594
+ return (0, _univerjs_sheets.deserializeListOptions)(cellString);
1546
1595
  }
1547
1596
  async parseFormula(rule, unitId, subUnitId) {
1548
1597
  var _results$;
@@ -1693,7 +1742,8 @@ function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, sour
1693
1742
  const redoMutations = [];
1694
1743
  const undoMutations = [];
1695
1744
  const sheetDataValidationModel = accessor.get(SheetDataValidationModel);
1696
- const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService), {
1745
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
1746
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService, {
1697
1747
  unitId,
1698
1748
  subUnitId
1699
1749
  });
@@ -1706,7 +1756,7 @@ function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, sour
1706
1756
  let setRangeValue = false;
1707
1757
  function setRangesDefaultValue(ranges, defaultValue) {
1708
1758
  if (!fillDefaultValue) return;
1709
- ranges.forEach((range) => {
1759
+ getRangesInWorksheet(ranges, worksheet).forEach((range) => {
1710
1760
  _univerjs_core.Range.foreach(range, (row, column) => {
1711
1761
  const cellData = worksheet.getCellRaw(row, column);
1712
1762
  const value = getStringCellValue(cellData);
@@ -1872,8 +1922,6 @@ function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, sour
1872
1922
  const formula = sheetDataValidationModel.getValidator(_univerjs_core.DataValidationType.CHECKBOX).parseFormulaSync(diff.rule, unitId, subUnitId);
1873
1923
  setRangesDefaultValue(diff.rule.ranges, formula.originFormula2);
1874
1924
  }
1875
- break;
1876
- default: break;
1877
1925
  }
1878
1926
  });
1879
1927
  if (setRangeValue) {
@@ -2012,7 +2060,8 @@ const UpdateSheetDataValidationSettingCommand = {
2012
2060
  }];
2013
2061
  if (setting.type === _univerjs_core.DataValidationType.CHECKBOX) {
2014
2062
  const ranges = rule.ranges;
2015
- const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService), {
2063
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
2064
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService, {
2016
2065
  unitId,
2017
2066
  subUnitId
2018
2067
  });
@@ -2022,7 +2071,7 @@ const UpdateSheetDataValidationSettingCommand = {
2022
2071
  const { formula2: oldFormula2 = 0, formula1: oldFormula1 = 1 } = rule;
2023
2072
  const { formula2 = 0, formula1 = 1 } = setting;
2024
2073
  let setted = false;
2025
- ranges.forEach((range) => {
2074
+ getRangesInWorksheet(ranges, worksheet).forEach((range) => {
2026
2075
  _univerjs_core.Range.foreach(range, (row, column) => {
2027
2076
  const cellData = worksheet.getCellRaw(row, column);
2028
2077
  const value = getStringCellValue(cellData);
@@ -2123,7 +2172,8 @@ const ClearRangeDataValidationCommand = {
2123
2172
  if (!params) return false;
2124
2173
  const { unitId, subUnitId, ranges, types } = params;
2125
2174
  const commandService = accessor.get(_univerjs_core.ICommandService);
2126
- const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService), {
2175
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
2176
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService, {
2127
2177
  unitId,
2128
2178
  subUnitId
2129
2179
  });
@@ -2281,7 +2331,9 @@ let DataValidationFormulaController = class DataValidationFormulaController exte
2281
2331
  if (!this._permissionService.getPermissionPoint(new _univerjs_sheets.WorksheetViewPermission(unitId, subUnitId).id)) return false;
2282
2332
  }
2283
2333
  if (!targetSheet) return false;
2284
- const { startRow, endRow, startColumn, endColumn } = sequenceGrid.range;
2334
+ const range = getRangeInWorksheet(sequenceGrid.range, targetSheet);
2335
+ if (!range) continue;
2336
+ const { startRow, endRow, startColumn, endColumn } = range;
2285
2337
  for (let i = startRow; i <= endRow; i++) for (let j = startColumn; j <= endColumn; j++) {
2286
2338
  var _targetSheet$getCell;
2287
2339
  const permission = (_targetSheet$getCell = targetSheet.getCell(i, j)) === null || _targetSheet$getCell === void 0 || (_targetSheet$getCell = _targetSheet$getCell.selectionProtection) === null || _targetSheet$getCell === void 0 ? void 0 : _targetSheet$getCell[0];
@@ -2300,7 +2352,7 @@ DataValidationFormulaController = __decorate([
2300
2352
  //#endregion
2301
2353
  //#region package.json
2302
2354
  var name = "@univerjs/sheets-data-validation";
2303
- var version = "1.0.0-insiders.20260813-7c9aa50";
2355
+ var version = "1.0.0";
2304
2356
 
2305
2357
  //#endregion
2306
2358
  //#region src/config/config.ts
@@ -3013,7 +3065,8 @@ let DataValidationController = class DataValidationController extends _univerjs_
3013
3065
  const selections = (_this$_selectionManag = this._selectionManagerService.getCurrentSelections()) === null || _this$_selectionManag === void 0 ? void 0 : _this$_selectionManag.map((s) => s.range);
3014
3066
  const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
3015
3067
  if (selections) ruleMatrix.removeRange(selections);
3016
- const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, ruleMatrix.diff(this._sheetDataValidationModel.getRules(unitId, subUnitId)), this._injector, "patched");
3068
+ const diffs = ruleMatrix.diff(this._sheetDataValidationModel.getRules(unitId, subUnitId));
3069
+ const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, this._injector, "patched");
3017
3070
  return {
3018
3071
  undos: undoMutations,
3019
3072
  redos: redoMutations
@@ -3051,14 +3104,14 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
3051
3104
  if (ranges.length === 0) return;
3052
3105
  const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
3053
3106
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
3054
- const map = {};
3107
+ const map = Object.create(null);
3055
3108
  ranges.flat().forEach((range) => {
3056
- if (!map[range.unitId]) map[range.unitId] = {};
3109
+ if (!map[range.unitId]) map[range.unitId] = Object.create(null);
3057
3110
  if (!map[range.unitId][range.subUnitId]) map[range.unitId][range.subUnitId] = [];
3058
3111
  const workbook = this._univerInstanceService.getUnit(range.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
3059
3112
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(range.subUnitId);
3060
3113
  if (!worksheet) return;
3061
- map[range.unitId][range.subUnitId].push(...range.ranges.map((range) => _univerjs_core.Range.transformRange(range, worksheet)));
3114
+ map[range.unitId][range.subUnitId].push(...getRangesInWorksheet(range.ranges, worksheet));
3062
3115
  });
3063
3116
  Object.entries(map).forEach(([unitId, subUnitMap]) => {
3064
3117
  Object.entries(subUnitMap).forEach(([subUnitId, ranges]) => {
@@ -3111,11 +3164,10 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
3111
3164
  if (!workbook) throw new Error(`cannot find current workbook, unitId: ${unitId}`);
3112
3165
  const worksheet = workbook.getSheetBySheetId(subUnitId);
3113
3166
  if (!worksheet) throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
3114
- const allRules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
3115
- const ruleRanges = [];
3116
- for (const rule of allRules) ruleRanges.push(...rule.ranges);
3167
+ const effectiveRanges = getRangesInWorksheet(ranges, worksheet);
3168
+ const ruleRanges = getRangesInWorksheet(this._sheetDataValidationModel.getRules(unitId, subUnitId).flatMap((rule) => rule.ranges), worksheet);
3117
3169
  const intersectRanges = [];
3118
- for (const range of ranges) for (const ruleRange of ruleRanges) {
3170
+ for (const range of effectiveRanges) for (const ruleRange of ruleRanges) {
3119
3171
  const intersect = (0, _univerjs_core.getIntersectRange)(range, ruleRange);
3120
3172
  if (intersect) intersectRanges.push(intersect);
3121
3173
  }
@@ -3148,31 +3200,32 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
3148
3200
  if (!workbook) throw new Error(`cannot find current workbook, unitId: ${unitId}`);
3149
3201
  const worksheet = workbook.getSheetBySheetId(subUnitId);
3150
3202
  if (!worksheet) throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
3151
- const rules = this._sheetDataValidationModel.getRules(unitId, subUnitId);
3152
- await Promise.all(rules.map((rule) => {
3153
- return Promise.all(rule.ranges.map((range) => {
3154
- const promises = [];
3155
- _univerjs_core.Range.foreach(range, (row, col) => {
3156
- promises.push(this._validatorByCell(workbook, worksheet, row, col));
3157
- });
3158
- return Promise.all(promises);
3159
- }));
3203
+ const ranges = getRangesInWorksheet(this._sheetDataValidationModel.getRules(unitId, subUnitId).flatMap((rule) => rule.ranges), worksheet);
3204
+ await Promise.all(ranges.map((range) => {
3205
+ const promises = [];
3206
+ _univerjs_core.Range.foreach(range, (row, col) => {
3207
+ promises.push(this._validatorByCell(workbook, worksheet, row, col));
3208
+ });
3209
+ return Promise.all(promises);
3160
3210
  }));
3161
3211
  return this._dataValidationCacheService.ensureCache(unitId, subUnitId);
3162
3212
  }
3163
3213
  async validatorWorkbook(unitId) {
3164
3214
  const sheetIds = this._sheetDataValidationModel.getSubUnitIds(unitId);
3165
3215
  const results = await Promise.all(sheetIds.map((id) => this.validatorWorksheet(unitId, id)));
3166
- const map = {};
3216
+ const map = Object.create(null);
3167
3217
  results.forEach((result, i) => {
3168
3218
  map[sheetIds[i]] = result;
3169
3219
  });
3170
3220
  return map;
3171
3221
  }
3172
3222
  getDataValidations(unitId, subUnitId, ranges) {
3223
+ var _this$_univerInstance;
3224
+ const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
3225
+ if (!worksheet) return [];
3173
3226
  const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId);
3174
3227
  const ruleIdSet = /* @__PURE__ */ new Set();
3175
- ranges.forEach((range) => {
3228
+ getRangesInWorksheet(ranges, worksheet).forEach((range) => {
3176
3229
  _univerjs_core.Range.foreach(range, (row, col) => {
3177
3230
  const ruleId = ruleMatrix.getValue(row, col);
3178
3231
  if (ruleId) ruleIdSet.add(ruleId);
@@ -3358,6 +3411,7 @@ exports.getDataValidationCellValue = getDataValidationCellValue;
3358
3411
  exports.getDataValidationDiffMutations = getDataValidationDiffMutations;
3359
3412
  exports.getFormulaCellData = getFormulaCellData;
3360
3413
  exports.getFormulaResult = getFormulaResult;
3414
+ exports.getRangesInWorksheet = getRangesInWorksheet;
3361
3415
  exports.getTransformedFormula = getTransformedFormula;
3362
3416
  exports.isLegalFormulaResult = isLegalFormulaResult;
3363
3417
  exports.transformCheckboxValue = transformCheckboxValue;
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/ar-SA.ts
3
2
  const locale = { "sheets-data-validation": {
4
3
  operators: {
@@ -9,8 +8,7 @@ const locale = { "sheets-data-validation": {
9
8
  lessThanOrEqual: "أقل من أو يساوي",
10
9
  equal: "يساوي",
11
10
  notEqual: "لا يساوي",
12
- notBetween: "ليس بين",
13
- legal: "نوع قانوني"
11
+ notBetween: "ليس بين"
14
12
  },
15
13
  ruleName: {
16
14
  between: "بين {FORMULA1} و{FORMULA2}",
@@ -43,8 +41,7 @@ const locale = { "sheets-data-validation": {
43
41
  lessThanOrEqual: "في أو قبل",
44
42
  equal: "يساوي",
45
43
  notEqual: "لا يساوي",
46
- notBetween: "ليس بين",
47
- legal: "تاريخ قانوني"
44
+ notBetween: "ليس بين"
48
45
  },
49
46
  ruleName: {
50
47
  between: "بين {FORMULA1} و{FORMULA2}",
@@ -86,20 +83,16 @@ const locale = { "sheets-data-validation": {
86
83
  custom: {
87
84
  ruleName: "الصيغة المخصصة هي {FORMULA1}",
88
85
  title: "صيغة مخصصة",
89
- validFail: "يرجى إدخال صيغة صالحة",
90
86
  error: "محتويات هذه الخلية تنتهك قاعدة التحقق"
91
87
  },
92
88
  validFail: {
93
89
  value: "يرجى إدخال قيمة",
94
- common: "يرجى إدخال قيمة أو صيغة",
95
90
  number: "يرجى إدخال رقم أو صيغة",
96
91
  formula: "يرجى إدخال صيغة",
97
- integer: "يرجى إدخال عدد صحيح أو صيغة",
98
92
  date: "يرجى إدخال تاريخ أو صيغة",
99
93
  list: "يرجى إدخال خيارات",
100
94
  listInvalid: "يجب أن يكون مصدر القائمة قائمة محددة بفواصل أو مرجعًا لصف أو عمود واحد",
101
95
  checkboxEqual: "أدخل قيمًا مختلفة لمحتويات الخلية المحددة وغير المحددة.",
102
- formulaError: "يحتوي نطاق المرجع على بيانات غير مرئية، يرجى إعادة ضبط النطاق",
103
96
  listIntersects: "لا يمكن أن يتقاطع النطاق المحدد مع نطاق القواعد",
104
97
  primitive: "غير مسموح بالصيغ لقيم المحدد وغير المحدد المخصصة."
105
98
  },
@@ -110,28 +103,14 @@ const locale = { "sheets-data-validation": {
110
103
  list: {
111
104
  title: "قائمة منسدلة",
112
105
  name: "القيمة تحتوي على واحدة من النطاق",
113
- error: "يجب أن يكون الإدخال ضمن النطاق المحدد",
114
- emptyError: "يرجى إدخال قيمة",
115
- add: "إضافة",
116
- dropdown: "تحديد",
117
- options: "خيارات",
118
- customOptions: "مخصص",
119
- refOptions: "من نطاق",
120
- formulaError: "يجب أن يكون مصدر القائمة قائمة بيانات محددة بفواصل، أو مرجعًا لصف أو عمود واحد.",
121
- edit: "تحرير"
122
- },
123
- listMultiple: {
124
- title: "قائمة منسدلة - متعددة",
125
- dropdown: "تحديد متعدد"
106
+ error: "يجب أن يكون الإدخال ضمن النطاق المحدد"
126
107
  },
108
+ listMultiple: { title: "قائمة منسدلة - متعددة" },
127
109
  decimal: { title: "رقم" },
128
110
  whole: { title: "عدد صحيح" },
129
111
  checkbox: {
130
112
  title: "خانة اختيار",
131
- error: "محتويات هذه الخلية تنتهك قاعدة التحقق",
132
- tips: "استخدم قيمًا مخصصة داخل الخلايا",
133
- checked: "القيمة المحددة",
134
- unchecked: "القيمة غير المحددة"
113
+ error: "محتويات هذه الخلية تنتهك قاعدة التحقق"
135
114
  }
136
115
  } };
137
116
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/ca-ES.ts
3
2
  const locale = { "sheets-data-validation": {
4
3
  operators: {
@@ -9,8 +8,7 @@ const locale = { "sheets-data-validation": {
9
8
  lessThanOrEqual: "menys o igual que",
10
9
  equal: "igual",
11
10
  notEqual: "no igual",
12
- notBetween: "no entre",
13
- legal: "és tipus legal"
11
+ notBetween: "no entre"
14
12
  },
15
13
  ruleName: {
16
14
  between: "Està entre {FORMULA1} i {FORMULA2}",
@@ -43,8 +41,7 @@ const locale = { "sheets-data-validation": {
43
41
  lessThanOrEqual: "en o abans de",
44
42
  equal: "igual",
45
43
  notEqual: "no igual",
46
- notBetween: "no entre",
47
- legal: "és una data legal"
44
+ notBetween: "no entre"
48
45
  },
49
46
  ruleName: {
50
47
  between: "està entre {FORMULA1} i {FORMULA2}",
@@ -86,20 +83,16 @@ const locale = { "sheets-data-validation": {
86
83
  custom: {
87
84
  ruleName: "La fórmula personalitzada és {FORMULA1}",
88
85
  title: "Fórmula personalitzada",
89
- validFail: "Si us plau, introdueix una fórmula vàlida",
90
86
  error: "El contingut d’aquesta cel·la incompleix la seva regla de validació"
91
87
  },
92
88
  validFail: {
93
89
  value: "Si us plau, introdueix un valor",
94
- common: "Si us plau, introdueix un valor o una fórmula",
95
90
  number: "Si us plau, introdueix un número o una fórmula",
96
91
  formula: "Si us plau, introdueix una fórmula",
97
- integer: "Si us plau, introdueix un enter o una fórmula",
98
92
  date: "Si us plau, introdueix una data o una fórmula",
99
93
  list: "Si us plau, introdueix opcions",
100
94
  listInvalid: "La font de la llista ha de ser una llista delimitada o una referència a una sola fila o columna",
101
95
  checkboxEqual: "Introdueix valors diferents per als continguts de cel·la marcats i desmarcats.",
102
- formulaError: "L’interval de referència conté dades invisibles, ajusta l’interval",
103
96
  listIntersects: "L’interval seleccionat no pot creuar-se amb l’àmbit de les regles",
104
97
  primitive: "No es permeten fórmules per a valors personalitzats marcats i desmarcats."
105
98
  },
@@ -110,28 +103,14 @@ const locale = { "sheets-data-validation": {
110
103
  list: {
111
104
  title: "Desplegable",
112
105
  name: "El valor conté un del rang",
113
- error: "L’entrada ha d’estar dins del rang especificat",
114
- emptyError: "Si us plau, introdueix un valor",
115
- add: "Afegeix",
116
- dropdown: "Selecciona",
117
- options: "Opcions",
118
- customOptions: "Personalitzat",
119
- refOptions: "D’un interval",
120
- formulaError: "La font de la llista ha de ser una llista delimitada de dades o una referència a una sola fila o columna.",
121
- edit: "Edita"
122
- },
123
- listMultiple: {
124
- title: "Desplegable-múltiple",
125
- dropdown: "Selecció múltiple"
106
+ error: "L’entrada ha d’estar dins del rang especificat"
126
107
  },
108
+ listMultiple: { title: "Desplegable-múltiple" },
127
109
  decimal: { title: "Número" },
128
110
  whole: { title: "Enter" },
129
111
  checkbox: {
130
112
  title: "Casella de selecció",
131
- error: "El contingut d’aquesta cel·la incompleix la seva regla de validació",
132
- tips: "Utilitza valors personalitzats dins de les cel·les",
133
- checked: "Valor seleccionat",
134
- unchecked: "Valor no seleccionat"
113
+ error: "El contingut d’aquesta cel·la incompleix la seva regla de validació"
135
114
  }
136
115
  } };
137
116