@univerjs/sheets-data-validation 1.0.0-rc.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +19 -12
- package/lib/cjs/index.js +88 -44
- package/lib/cjs/locale/ar-SA.js +0 -1
- package/lib/cjs/locale/ca-ES.js +0 -1
- package/lib/cjs/locale/de-DE.js +0 -1
- package/lib/cjs/locale/en-US.js +0 -1
- package/lib/cjs/locale/es-ES.js +0 -1
- package/lib/cjs/locale/fa-IR.js +0 -1
- package/lib/cjs/locale/fr-FR.js +0 -1
- package/lib/cjs/locale/id-ID.js +0 -1
- package/lib/cjs/locale/it-IT.js +0 -1
- package/lib/cjs/locale/ja-JP.js +0 -1
- package/lib/cjs/locale/ko-KR.js +0 -1
- package/lib/cjs/locale/pl-PL.js +0 -1
- package/lib/cjs/locale/pt-BR.js +0 -1
- package/lib/cjs/locale/ru-RU.js +0 -1
- package/lib/cjs/locale/sk-SK.js +0 -1
- package/lib/cjs/locale/vi-VN.js +0 -1
- package/lib/cjs/locale/zh-CN.js +0 -1
- package/lib/cjs/locale/zh-HK.js +0 -1
- package/lib/cjs/locale/zh-TW.js +0 -1
- package/lib/es/facade.js +20 -13
- package/lib/es/index.js +88 -45
- package/lib/facade.js +20 -13
- package/lib/index.js +88 -45
- package/lib/types/facade/f-data-validation.d.ts +5 -2
- package/lib/types/facade/f-range.d.ts +1 -1
- package/lib/types/facade/f-workbook.d.ts +3 -3
- package/lib/types/facade/f-worksheet.d.ts +5 -2
- package/lib/types/index.d.ts +1 -0
- package/lib/types/services/dv-cache.service.d.ts +1 -0
- package/lib/types/utils/range.d.ts +18 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
package/lib/cjs/facade.js
CHANGED
|
@@ -7,7 +7,7 @@ let _univerjs_engine_formula = require("@univerjs/engine-formula");
|
|
|
7
7
|
let _univerjs_sheets = require("@univerjs/sheets");
|
|
8
8
|
let _univerjs_core_facade = require("@univerjs/core/facade");
|
|
9
9
|
|
|
10
|
-
//#region \0@oxc-project+runtime@0.
|
|
10
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
|
|
11
11
|
function _typeof(o) {
|
|
12
12
|
"@babel/helpers - typeof";
|
|
13
13
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -18,7 +18,7 @@ function _typeof(o) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
//#endregion
|
|
21
|
-
//#region \0@oxc-project+runtime@0.
|
|
21
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
|
|
22
22
|
function toPrimitive(t, r) {
|
|
23
23
|
if ("object" != _typeof(t) || !t) return t;
|
|
24
24
|
var e = t[Symbol.toPrimitive];
|
|
@@ -31,14 +31,14 @@ function toPrimitive(t, r) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
//#endregion
|
|
34
|
-
//#region \0@oxc-project+runtime@0.
|
|
34
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
|
|
35
35
|
function toPropertyKey(t) {
|
|
36
36
|
var i = toPrimitive(t, "string");
|
|
37
37
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
//#endregion
|
|
41
|
-
//#region \0@oxc-project+runtime@0.
|
|
41
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
|
|
42
42
|
function _defineProperty(e, r, t) {
|
|
43
43
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
44
44
|
value: t,
|
|
@@ -153,7 +153,7 @@ var FDataValidationBuilder = class FDataValidationBuilder {
|
|
|
153
153
|
* ```
|
|
154
154
|
*/
|
|
155
155
|
getAllowInvalid() {
|
|
156
|
-
return this._rule.errorStyle !== _univerjs_core.DataValidationErrorStyle.STOP;
|
|
156
|
+
return this._rule.showErrorMessage === false || this._rule.errorStyle !== _univerjs_core.DataValidationErrorStyle.STOP;
|
|
157
157
|
}
|
|
158
158
|
/**
|
|
159
159
|
* Gets the data validation type of the rule
|
|
@@ -961,7 +961,14 @@ var FDataValidationBuilder = class FDataValidationBuilder {
|
|
|
961
961
|
*/
|
|
962
962
|
var FDataValidation = class {
|
|
963
963
|
constructor(rule, worksheet, _injector) {
|
|
964
|
-
_defineProperty(
|
|
964
|
+
_defineProperty(
|
|
965
|
+
this,
|
|
966
|
+
/**
|
|
967
|
+
* The underlying validation rule data. Use the Facade setters to update a rule attached to a worksheet.
|
|
968
|
+
*/
|
|
969
|
+
"rule",
|
|
970
|
+
void 0
|
|
971
|
+
);
|
|
965
972
|
_defineProperty(this, "_worksheet", void 0);
|
|
966
973
|
_defineProperty(this, "_injector", void 0);
|
|
967
974
|
this._injector = _injector;
|
|
@@ -983,7 +990,7 @@ var FDataValidation = class {
|
|
|
983
990
|
* ```
|
|
984
991
|
*/
|
|
985
992
|
getAllowInvalid() {
|
|
986
|
-
return this.rule.errorStyle !== _univerjs_core.DataValidationErrorStyle.STOP;
|
|
993
|
+
return this.rule.showErrorMessage === false || this.rule.errorStyle !== _univerjs_core.DataValidationErrorStyle.STOP;
|
|
987
994
|
}
|
|
988
995
|
/**
|
|
989
996
|
* Gets the data validation type of the rule
|
|
@@ -1129,8 +1136,8 @@ var FDataValidation = class {
|
|
|
1129
1136
|
return this.rule.ranges.map((range) => this._injector.createInstance(_univerjs_sheets_facade.FRange, workbook, this._worksheet, range));
|
|
1130
1137
|
}
|
|
1131
1138
|
/**
|
|
1132
|
-
* Gets the unit ID of the
|
|
1133
|
-
* @returns {string | undefined} The unit ID of the
|
|
1139
|
+
* Gets the unit ID of the workbook
|
|
1140
|
+
* @returns {string | undefined} The unit ID of the workbook
|
|
1134
1141
|
* @example
|
|
1135
1142
|
* ```typescript
|
|
1136
1143
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
@@ -1360,7 +1367,7 @@ var FRangeSheetsDataValidationMixin = class extends _univerjs_sheets_facade.FRan
|
|
|
1360
1367
|
const worksheet = this._worksheet;
|
|
1361
1368
|
const sheetName = worksheet.getName();
|
|
1362
1369
|
const errors = [];
|
|
1363
|
-
for (const range of ranges) {
|
|
1370
|
+
for (const range of (0, _univerjs_sheets_data_validation.getRangesInWorksheet)(ranges, worksheet)) {
|
|
1364
1371
|
const promises = [];
|
|
1365
1372
|
for (let row = range.startRow; row <= range.endRow; row++) for (let col = range.startColumn; col <= range.endColumn; col++) promises.push((async () => {
|
|
1366
1373
|
try {
|
|
@@ -1600,7 +1607,7 @@ var FWorkbookSheetsDataValidationMixin = class extends _univerjs_sheets_facade.F
|
|
|
1600
1607
|
if (!worksheet) throw new Error(`Cannot find worksheet with sheetId: ${sheetId}`);
|
|
1601
1608
|
const sheetName = worksheet.getName();
|
|
1602
1609
|
const errors = [];
|
|
1603
|
-
for (const range of ranges) {
|
|
1610
|
+
for (const range of (0, _univerjs_sheets_data_validation.getRangesInWorksheet)(ranges, worksheet)) {
|
|
1604
1611
|
const promises = [];
|
|
1605
1612
|
for (let row = range.startRow; row <= range.endRow; row++) for (let col = range.startColumn; col <= range.endColumn; col++) promises.push((async () => {
|
|
1606
1613
|
try {
|
|
@@ -1668,7 +1675,7 @@ var FWorksheetDataValidationMixin = class extends _univerjs_sheets_facade.FWorks
|
|
|
1668
1675
|
const worksheet = this._worksheet;
|
|
1669
1676
|
const sheetName = worksheet.getName();
|
|
1670
1677
|
const errors = [];
|
|
1671
|
-
for (const range of ranges) {
|
|
1678
|
+
for (const range of (0, _univerjs_sheets_data_validation.getRangesInWorksheet)(ranges, worksheet)) {
|
|
1672
1679
|
const promises = [];
|
|
1673
1680
|
for (let row = range.startRow; row <= range.endRow; row++) for (let col = range.startColumn; col <= range.endColumn; col++) promises.push((async () => {
|
|
1674
1681
|
try {
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
291
|
-
|
|
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,
|
|
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,
|
|
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
|
}));
|
|
@@ -1552,7 +1590,8 @@ var ListValidator = class extends BaseSheetValidator {
|
|
|
1552
1590
|
return { tb };
|
|
1553
1591
|
}
|
|
1554
1592
|
parseCellValue(cellValue) {
|
|
1555
|
-
|
|
1593
|
+
const cellString = cellValue.toString();
|
|
1594
|
+
return (0, _univerjs_sheets.deserializeListOptions)(cellString);
|
|
1556
1595
|
}
|
|
1557
1596
|
async parseFormula(rule, unitId, subUnitId) {
|
|
1558
1597
|
var _results$;
|
|
@@ -1703,7 +1742,8 @@ function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, sour
|
|
|
1703
1742
|
const redoMutations = [];
|
|
1704
1743
|
const undoMutations = [];
|
|
1705
1744
|
const sheetDataValidationModel = accessor.get(SheetDataValidationModel);
|
|
1706
|
-
const
|
|
1745
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
1746
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService, {
|
|
1707
1747
|
unitId,
|
|
1708
1748
|
subUnitId
|
|
1709
1749
|
});
|
|
@@ -1716,7 +1756,7 @@ function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, sour
|
|
|
1716
1756
|
let setRangeValue = false;
|
|
1717
1757
|
function setRangesDefaultValue(ranges, defaultValue) {
|
|
1718
1758
|
if (!fillDefaultValue) return;
|
|
1719
|
-
ranges.forEach((range) => {
|
|
1759
|
+
getRangesInWorksheet(ranges, worksheet).forEach((range) => {
|
|
1720
1760
|
_univerjs_core.Range.foreach(range, (row, column) => {
|
|
1721
1761
|
const cellData = worksheet.getCellRaw(row, column);
|
|
1722
1762
|
const value = getStringCellValue(cellData);
|
|
@@ -1882,8 +1922,6 @@ function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, sour
|
|
|
1882
1922
|
const formula = sheetDataValidationModel.getValidator(_univerjs_core.DataValidationType.CHECKBOX).parseFormulaSync(diff.rule, unitId, subUnitId);
|
|
1883
1923
|
setRangesDefaultValue(diff.rule.ranges, formula.originFormula2);
|
|
1884
1924
|
}
|
|
1885
|
-
break;
|
|
1886
|
-
default: break;
|
|
1887
1925
|
}
|
|
1888
1926
|
});
|
|
1889
1927
|
if (setRangeValue) {
|
|
@@ -2022,7 +2060,8 @@ const UpdateSheetDataValidationSettingCommand = {
|
|
|
2022
2060
|
}];
|
|
2023
2061
|
if (setting.type === _univerjs_core.DataValidationType.CHECKBOX) {
|
|
2024
2062
|
const ranges = rule.ranges;
|
|
2025
|
-
const
|
|
2063
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
2064
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService, {
|
|
2026
2065
|
unitId,
|
|
2027
2066
|
subUnitId
|
|
2028
2067
|
});
|
|
@@ -2032,7 +2071,7 @@ const UpdateSheetDataValidationSettingCommand = {
|
|
|
2032
2071
|
const { formula2: oldFormula2 = 0, formula1: oldFormula1 = 1 } = rule;
|
|
2033
2072
|
const { formula2 = 0, formula1 = 1 } = setting;
|
|
2034
2073
|
let setted = false;
|
|
2035
|
-
ranges.forEach((range) => {
|
|
2074
|
+
getRangesInWorksheet(ranges, worksheet).forEach((range) => {
|
|
2036
2075
|
_univerjs_core.Range.foreach(range, (row, column) => {
|
|
2037
2076
|
const cellData = worksheet.getCellRaw(row, column);
|
|
2038
2077
|
const value = getStringCellValue(cellData);
|
|
@@ -2133,7 +2172,8 @@ const ClearRangeDataValidationCommand = {
|
|
|
2133
2172
|
if (!params) return false;
|
|
2134
2173
|
const { unitId, subUnitId, ranges, types } = params;
|
|
2135
2174
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
2136
|
-
const
|
|
2175
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
2176
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService, {
|
|
2137
2177
|
unitId,
|
|
2138
2178
|
subUnitId
|
|
2139
2179
|
});
|
|
@@ -2291,7 +2331,9 @@ let DataValidationFormulaController = class DataValidationFormulaController exte
|
|
|
2291
2331
|
if (!this._permissionService.getPermissionPoint(new _univerjs_sheets.WorksheetViewPermission(unitId, subUnitId).id)) return false;
|
|
2292
2332
|
}
|
|
2293
2333
|
if (!targetSheet) return false;
|
|
2294
|
-
const
|
|
2334
|
+
const range = getRangeInWorksheet(sequenceGrid.range, targetSheet);
|
|
2335
|
+
if (!range) continue;
|
|
2336
|
+
const { startRow, endRow, startColumn, endColumn } = range;
|
|
2295
2337
|
for (let i = startRow; i <= endRow; i++) for (let j = startColumn; j <= endColumn; j++) {
|
|
2296
2338
|
var _targetSheet$getCell;
|
|
2297
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];
|
|
@@ -2310,7 +2352,7 @@ DataValidationFormulaController = __decorate([
|
|
|
2310
2352
|
//#endregion
|
|
2311
2353
|
//#region package.json
|
|
2312
2354
|
var name = "@univerjs/sheets-data-validation";
|
|
2313
|
-
var version = "1.0.
|
|
2355
|
+
var version = "1.0.1";
|
|
2314
2356
|
|
|
2315
2357
|
//#endregion
|
|
2316
2358
|
//#region src/config/config.ts
|
|
@@ -3023,7 +3065,8 @@ let DataValidationController = class DataValidationController extends _univerjs_
|
|
|
3023
3065
|
const selections = (_this$_selectionManag = this._selectionManagerService.getCurrentSelections()) === null || _this$_selectionManag === void 0 ? void 0 : _this$_selectionManag.map((s) => s.range);
|
|
3024
3066
|
const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
3025
3067
|
if (selections) ruleMatrix.removeRange(selections);
|
|
3026
|
-
const
|
|
3068
|
+
const diffs = ruleMatrix.diff(this._sheetDataValidationModel.getRules(unitId, subUnitId));
|
|
3069
|
+
const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, this._injector, "patched");
|
|
3027
3070
|
return {
|
|
3028
3071
|
undos: undoMutations,
|
|
3029
3072
|
redos: redoMutations
|
|
@@ -3061,14 +3104,14 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
|
|
|
3061
3104
|
if (ranges.length === 0) return;
|
|
3062
3105
|
const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
3063
3106
|
const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
|
|
3064
|
-
const map =
|
|
3107
|
+
const map = Object.create(null);
|
|
3065
3108
|
ranges.flat().forEach((range) => {
|
|
3066
|
-
if (!map[range.unitId]) map[range.unitId] =
|
|
3109
|
+
if (!map[range.unitId]) map[range.unitId] = Object.create(null);
|
|
3067
3110
|
if (!map[range.unitId][range.subUnitId]) map[range.unitId][range.subUnitId] = [];
|
|
3068
3111
|
const workbook = this._univerInstanceService.getUnit(range.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
3069
3112
|
const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(range.subUnitId);
|
|
3070
3113
|
if (!worksheet) return;
|
|
3071
|
-
map[range.unitId][range.subUnitId].push(...range.ranges
|
|
3114
|
+
map[range.unitId][range.subUnitId].push(...getRangesInWorksheet(range.ranges, worksheet));
|
|
3072
3115
|
});
|
|
3073
3116
|
Object.entries(map).forEach(([unitId, subUnitMap]) => {
|
|
3074
3117
|
Object.entries(subUnitMap).forEach(([subUnitId, ranges]) => {
|
|
@@ -3121,11 +3164,10 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
|
|
|
3121
3164
|
if (!workbook) throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
3122
3165
|
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
3123
3166
|
if (!worksheet) throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
3124
|
-
const
|
|
3125
|
-
const ruleRanges =
|
|
3126
|
-
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);
|
|
3127
3169
|
const intersectRanges = [];
|
|
3128
|
-
for (const range of
|
|
3170
|
+
for (const range of effectiveRanges) for (const ruleRange of ruleRanges) {
|
|
3129
3171
|
const intersect = (0, _univerjs_core.getIntersectRange)(range, ruleRange);
|
|
3130
3172
|
if (intersect) intersectRanges.push(intersect);
|
|
3131
3173
|
}
|
|
@@ -3158,31 +3200,32 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
|
|
|
3158
3200
|
if (!workbook) throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
3159
3201
|
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
3160
3202
|
if (!worksheet) throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
3161
|
-
const
|
|
3162
|
-
await Promise.all(
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
return Promise.all(promises);
|
|
3169
|
-
}));
|
|
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);
|
|
3170
3210
|
}));
|
|
3171
3211
|
return this._dataValidationCacheService.ensureCache(unitId, subUnitId);
|
|
3172
3212
|
}
|
|
3173
3213
|
async validatorWorkbook(unitId) {
|
|
3174
3214
|
const sheetIds = this._sheetDataValidationModel.getSubUnitIds(unitId);
|
|
3175
3215
|
const results = await Promise.all(sheetIds.map((id) => this.validatorWorksheet(unitId, id)));
|
|
3176
|
-
const map =
|
|
3216
|
+
const map = Object.create(null);
|
|
3177
3217
|
results.forEach((result, i) => {
|
|
3178
3218
|
map[sheetIds[i]] = result;
|
|
3179
3219
|
});
|
|
3180
3220
|
return map;
|
|
3181
3221
|
}
|
|
3182
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 [];
|
|
3183
3226
|
const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId);
|
|
3184
3227
|
const ruleIdSet = /* @__PURE__ */ new Set();
|
|
3185
|
-
ranges.forEach((range) => {
|
|
3228
|
+
getRangesInWorksheet(ranges, worksheet).forEach((range) => {
|
|
3186
3229
|
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
3187
3230
|
const ruleId = ruleMatrix.getValue(row, col);
|
|
3188
3231
|
if (ruleId) ruleIdSet.add(ruleId);
|
|
@@ -3368,6 +3411,7 @@ exports.getDataValidationCellValue = getDataValidationCellValue;
|
|
|
3368
3411
|
exports.getDataValidationDiffMutations = getDataValidationDiffMutations;
|
|
3369
3412
|
exports.getFormulaCellData = getFormulaCellData;
|
|
3370
3413
|
exports.getFormulaResult = getFormulaResult;
|
|
3414
|
+
exports.getRangesInWorksheet = getRangesInWorksheet;
|
|
3371
3415
|
exports.getTransformedFormula = getTransformedFormula;
|
|
3372
3416
|
exports.isLegalFormulaResult = isLegalFormulaResult;
|
|
3373
3417
|
exports.transformCheckboxValue = transformCheckboxValue;
|
package/lib/cjs/locale/ar-SA.js
CHANGED
package/lib/cjs/locale/ca-ES.js
CHANGED
package/lib/cjs/locale/de-DE.js
CHANGED
package/lib/cjs/locale/en-US.js
CHANGED
package/lib/cjs/locale/es-ES.js
CHANGED
package/lib/cjs/locale/fa-IR.js
CHANGED
package/lib/cjs/locale/fr-FR.js
CHANGED
package/lib/cjs/locale/id-ID.js
CHANGED
package/lib/cjs/locale/it-IT.js
CHANGED
package/lib/cjs/locale/ja-JP.js
CHANGED
package/lib/cjs/locale/ko-KR.js
CHANGED
package/lib/cjs/locale/pl-PL.js
CHANGED
package/lib/cjs/locale/pt-BR.js
CHANGED
package/lib/cjs/locale/ru-RU.js
CHANGED
package/lib/cjs/locale/sk-SK.js
CHANGED
package/lib/cjs/locale/vi-VN.js
CHANGED
package/lib/cjs/locale/zh-CN.js
CHANGED
package/lib/cjs/locale/zh-HK.js
CHANGED
package/lib/cjs/locale/zh-TW.js
CHANGED
package/lib/es/facade.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { CanceledError, DataValidationErrorStyle, DataValidationOperator, DataValidationStatus, DataValidationType, ICommandService, IUniverInstanceService, generateRandomId } from "@univerjs/core";
|
|
2
|
-
import { AddSheetDataValidationCommand, ClearRangeDataValidationCommand, RemoveSheetAllDataValidationCommand, RemoveSheetDataValidationCommand, SheetDataValidationModel, SheetsDataValidationValidatorService, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationRangeCommand, UpdateSheetDataValidationSettingCommand } from "@univerjs/sheets-data-validation";
|
|
2
|
+
import { AddSheetDataValidationCommand, ClearRangeDataValidationCommand, RemoveSheetAllDataValidationCommand, RemoveSheetDataValidationCommand, SheetDataValidationModel, SheetsDataValidationValidatorService, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationRangeCommand, UpdateSheetDataValidationSettingCommand, getRangesInWorksheet } from "@univerjs/sheets-data-validation";
|
|
3
3
|
import { FRange, FWorkbook, FWorksheet } from "@univerjs/sheets/facade";
|
|
4
4
|
import { DataValidationModel, getRuleOptions } from "@univerjs/data-validation";
|
|
5
5
|
import { serializeRangeToRefString } from "@univerjs/engine-formula";
|
|
6
6
|
import { serializeListOptions } from "@univerjs/sheets";
|
|
7
7
|
import { FEventName, FUniver } from "@univerjs/core/facade";
|
|
8
8
|
|
|
9
|
-
//#region \0@oxc-project+runtime@0.
|
|
9
|
+
//#region \0@oxc-project+runtime@0.149.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.
|
|
20
|
+
//#region \0@oxc-project+runtime@0.149.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.
|
|
33
|
+
//#region \0@oxc-project+runtime@0.149.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.
|
|
40
|
+
//#region \0@oxc-project+runtime@0.149.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,
|
|
@@ -152,7 +152,7 @@ var FDataValidationBuilder = class FDataValidationBuilder {
|
|
|
152
152
|
* ```
|
|
153
153
|
*/
|
|
154
154
|
getAllowInvalid() {
|
|
155
|
-
return this._rule.errorStyle !== DataValidationErrorStyle.STOP;
|
|
155
|
+
return this._rule.showErrorMessage === false || this._rule.errorStyle !== DataValidationErrorStyle.STOP;
|
|
156
156
|
}
|
|
157
157
|
/**
|
|
158
158
|
* Gets the data validation type of the rule
|
|
@@ -960,7 +960,14 @@ var FDataValidationBuilder = class FDataValidationBuilder {
|
|
|
960
960
|
*/
|
|
961
961
|
var FDataValidation = class {
|
|
962
962
|
constructor(rule, worksheet, _injector) {
|
|
963
|
-
_defineProperty(
|
|
963
|
+
_defineProperty(
|
|
964
|
+
this,
|
|
965
|
+
/**
|
|
966
|
+
* The underlying validation rule data. Use the Facade setters to update a rule attached to a worksheet.
|
|
967
|
+
*/
|
|
968
|
+
"rule",
|
|
969
|
+
void 0
|
|
970
|
+
);
|
|
964
971
|
_defineProperty(this, "_worksheet", void 0);
|
|
965
972
|
_defineProperty(this, "_injector", void 0);
|
|
966
973
|
this._injector = _injector;
|
|
@@ -982,7 +989,7 @@ var FDataValidation = class {
|
|
|
982
989
|
* ```
|
|
983
990
|
*/
|
|
984
991
|
getAllowInvalid() {
|
|
985
|
-
return this.rule.errorStyle !== DataValidationErrorStyle.STOP;
|
|
992
|
+
return this.rule.showErrorMessage === false || this.rule.errorStyle !== DataValidationErrorStyle.STOP;
|
|
986
993
|
}
|
|
987
994
|
/**
|
|
988
995
|
* Gets the data validation type of the rule
|
|
@@ -1128,8 +1135,8 @@ var FDataValidation = class {
|
|
|
1128
1135
|
return this.rule.ranges.map((range) => this._injector.createInstance(FRange, workbook, this._worksheet, range));
|
|
1129
1136
|
}
|
|
1130
1137
|
/**
|
|
1131
|
-
* Gets the unit ID of the
|
|
1132
|
-
* @returns {string | undefined} The unit ID of the
|
|
1138
|
+
* Gets the unit ID of the workbook
|
|
1139
|
+
* @returns {string | undefined} The unit ID of the workbook
|
|
1133
1140
|
* @example
|
|
1134
1141
|
* ```typescript
|
|
1135
1142
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
@@ -1359,7 +1366,7 @@ var FRangeSheetsDataValidationMixin = class extends FRange {
|
|
|
1359
1366
|
const worksheet = this._worksheet;
|
|
1360
1367
|
const sheetName = worksheet.getName();
|
|
1361
1368
|
const errors = [];
|
|
1362
|
-
for (const range of ranges) {
|
|
1369
|
+
for (const range of getRangesInWorksheet(ranges, worksheet)) {
|
|
1363
1370
|
const promises = [];
|
|
1364
1371
|
for (let row = range.startRow; row <= range.endRow; row++) for (let col = range.startColumn; col <= range.endColumn; col++) promises.push((async () => {
|
|
1365
1372
|
try {
|
|
@@ -1599,7 +1606,7 @@ var FWorkbookSheetsDataValidationMixin = class extends FWorkbook {
|
|
|
1599
1606
|
if (!worksheet) throw new Error(`Cannot find worksheet with sheetId: ${sheetId}`);
|
|
1600
1607
|
const sheetName = worksheet.getName();
|
|
1601
1608
|
const errors = [];
|
|
1602
|
-
for (const range of ranges) {
|
|
1609
|
+
for (const range of getRangesInWorksheet(ranges, worksheet)) {
|
|
1603
1610
|
const promises = [];
|
|
1604
1611
|
for (let row = range.startRow; row <= range.endRow; row++) for (let col = range.startColumn; col <= range.endColumn; col++) promises.push((async () => {
|
|
1605
1612
|
try {
|
|
@@ -1667,7 +1674,7 @@ var FWorksheetDataValidationMixin = class extends FWorksheet {
|
|
|
1667
1674
|
const worksheet = this._worksheet;
|
|
1668
1675
|
const sheetName = worksheet.getName();
|
|
1669
1676
|
const errors = [];
|
|
1670
|
-
for (const range of ranges) {
|
|
1677
|
+
for (const range of getRangesInWorksheet(ranges, worksheet)) {
|
|
1671
1678
|
const promises = [];
|
|
1672
1679
|
for (let row = range.startRow; row <= range.endRow; row++) for (let col = range.startColumn; col <= range.endColumn; col++) promises.push((async () => {
|
|
1673
1680
|
try {
|