@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/index.js
CHANGED
|
@@ -6,7 +6,36 @@ import { Subject, bufferWhen, filter, skip } from "rxjs";
|
|
|
6
6
|
import { UnitAction } from "@univerjs/protocol";
|
|
7
7
|
import { FormulaRefRangeService, UniverSheetsFormulaPlugin } from "@univerjs/sheets-formula";
|
|
8
8
|
|
|
9
|
-
//#region
|
|
9
|
+
//#region src/utils/range.ts
|
|
10
|
+
function getRangeInWorksheet(range, worksheet) {
|
|
11
|
+
const maxRows = worksheet.getMaxRows();
|
|
12
|
+
const maxColumns = worksheet.getMaxColumns();
|
|
13
|
+
if (maxRows <= 0 || maxColumns <= 0) return null;
|
|
14
|
+
const effectiveRange = getIntersectRange(Range.transformRange(range, worksheet), {
|
|
15
|
+
startRow: 0,
|
|
16
|
+
endRow: maxRows - 1,
|
|
17
|
+
startColumn: 0,
|
|
18
|
+
endColumn: maxColumns - 1
|
|
19
|
+
});
|
|
20
|
+
if (!effectiveRange) return null;
|
|
21
|
+
return {
|
|
22
|
+
startRow: effectiveRange.startRow,
|
|
23
|
+
endRow: effectiveRange.endRow,
|
|
24
|
+
startColumn: effectiveRange.startColumn,
|
|
25
|
+
endColumn: effectiveRange.endColumn
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function getRangesInWorksheet(ranges, worksheet) {
|
|
29
|
+
const effectiveRanges = [];
|
|
30
|
+
ranges.forEach((range) => {
|
|
31
|
+
const effectiveRange = getRangeInWorksheet(range, worksheet);
|
|
32
|
+
if (effectiveRange) effectiveRanges.push(effectiveRange);
|
|
33
|
+
});
|
|
34
|
+
return effectiveRanges;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
|
|
10
39
|
function _typeof(o) {
|
|
11
40
|
"@babel/helpers - typeof";
|
|
12
41
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -17,7 +46,7 @@ function _typeof(o) {
|
|
|
17
46
|
}
|
|
18
47
|
|
|
19
48
|
//#endregion
|
|
20
|
-
//#region \0@oxc-project+runtime@0.
|
|
49
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
|
|
21
50
|
function toPrimitive(t, r) {
|
|
22
51
|
if ("object" != _typeof(t) || !t) return t;
|
|
23
52
|
var e = t[Symbol.toPrimitive];
|
|
@@ -30,14 +59,14 @@ function toPrimitive(t, r) {
|
|
|
30
59
|
}
|
|
31
60
|
|
|
32
61
|
//#endregion
|
|
33
|
-
//#region \0@oxc-project+runtime@0.
|
|
62
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
|
|
34
63
|
function toPropertyKey(t) {
|
|
35
64
|
var i = toPrimitive(t, "string");
|
|
36
65
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
37
66
|
}
|
|
38
67
|
|
|
39
68
|
//#endregion
|
|
40
|
-
//#region \0@oxc-project+runtime@0.
|
|
69
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
|
|
41
70
|
function _defineProperty(e, r, t) {
|
|
42
71
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
43
72
|
value: t,
|
|
@@ -48,7 +77,7 @@ function _defineProperty(e, r, t) {
|
|
|
48
77
|
}
|
|
49
78
|
|
|
50
79
|
//#endregion
|
|
51
|
-
//#region \0@oxc-project+runtime@0.
|
|
80
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
|
|
52
81
|
function __decorateParam(paramIndex, decorator) {
|
|
53
82
|
return function(target, key) {
|
|
54
83
|
decorator(target, key, paramIndex);
|
|
@@ -56,7 +85,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
56
85
|
}
|
|
57
86
|
|
|
58
87
|
//#endregion
|
|
59
|
-
//#region \0@oxc-project+runtime@0.
|
|
88
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
|
|
60
89
|
function __decorate(decorators, target, key, desc) {
|
|
61
90
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
62
91
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -132,9 +161,15 @@ let DataValidationCacheService = class DataValidationCacheService extends Dispos
|
|
|
132
161
|
removeRule(unitId, subUnitId, rule) {
|
|
133
162
|
this._deleteRange(unitId, subUnitId, rule.ranges);
|
|
134
163
|
}
|
|
164
|
+
_getEffectiveRanges(unitId, subUnitId, ranges) {
|
|
165
|
+
var _this$_univerInstance;
|
|
166
|
+
const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
|
|
167
|
+
if (!worksheet) return [];
|
|
168
|
+
return getRangesInWorksheet(ranges, worksheet);
|
|
169
|
+
}
|
|
135
170
|
markRangeDirty(unitId, subUnitId, ranges, isSetRange) {
|
|
136
171
|
const cache = this._ensureCache(unitId, subUnitId);
|
|
137
|
-
ranges.forEach((range) => {
|
|
172
|
+
this._getEffectiveRanges(unitId, subUnitId, ranges).forEach((range) => {
|
|
138
173
|
Range.foreach(range, (row, col) => {
|
|
139
174
|
if (cache.getValue(row, col) !== void 0) cache.setValue(row, col, void 0);
|
|
140
175
|
});
|
|
@@ -148,7 +183,7 @@ let DataValidationCacheService = class DataValidationCacheService extends Dispos
|
|
|
148
183
|
}
|
|
149
184
|
_deleteRange(unitId, subUnitId, ranges) {
|
|
150
185
|
const cache = this._ensureCache(unitId, subUnitId);
|
|
151
|
-
ranges.forEach((range) => {
|
|
186
|
+
this._getEffectiveRanges(unitId, subUnitId, ranges).forEach((range) => {
|
|
152
187
|
Range.foreach(range, (row, col) => {
|
|
153
188
|
cache.realDeleteValue(row, col);
|
|
154
189
|
});
|
|
@@ -285,11 +320,16 @@ let DataValidationCustomFormulaService = class DataValidationCustomFormulaServic
|
|
|
285
320
|
}
|
|
286
321
|
}
|
|
287
322
|
_addFormulaByRange(unitId, subUnitId, ruleId, formula, formula2, ranges) {
|
|
323
|
+
var _this$_instanceSrv$ge;
|
|
288
324
|
const { ruleFormulaMap, ruleFormulaMap2 } = this._ensureMaps(unitId, subUnitId);
|
|
289
|
-
const
|
|
290
|
-
|
|
325
|
+
const worksheet = (_this$_instanceSrv$ge = this._instanceSrv.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_instanceSrv$ge === void 0 ? void 0 : _this$_instanceSrv$ge.getSheetBySheetId(subUnitId);
|
|
326
|
+
if (!worksheet) return;
|
|
327
|
+
const effectiveRanges = getRangesInWorksheet(ranges, worksheet);
|
|
328
|
+
if (!effectiveRanges.length) return;
|
|
329
|
+
const originRow = effectiveRanges[0].startRow;
|
|
330
|
+
const originCol = effectiveRanges[0].startColumn;
|
|
291
331
|
if (formula && isFormulaString(formula)) {
|
|
292
|
-
const formulaId = this._registerFormula(unitId, subUnitId, ruleId, formula,
|
|
332
|
+
const formulaId = this._registerFormula(unitId, subUnitId, ruleId, formula, effectiveRanges);
|
|
293
333
|
ruleFormulaMap.set(ruleId, {
|
|
294
334
|
formula,
|
|
295
335
|
originCol,
|
|
@@ -298,7 +338,7 @@ let DataValidationCustomFormulaService = class DataValidationCustomFormulaServic
|
|
|
298
338
|
});
|
|
299
339
|
}
|
|
300
340
|
if (formula2 && isFormulaString(formula2)) {
|
|
301
|
-
const formulaId2 = this._registerFormula(unitId, subUnitId, ruleId, formula2,
|
|
341
|
+
const formulaId2 = this._registerFormula(unitId, subUnitId, ruleId, formula2, effectiveRanges);
|
|
302
342
|
ruleFormulaMap2.set(ruleId, {
|
|
303
343
|
formula: formula2,
|
|
304
344
|
originCol,
|
|
@@ -837,9 +877,7 @@ let SheetDataValidationModel = class SheetDataValidationModel extends Disposable
|
|
|
837
877
|
case "update":
|
|
838
878
|
this._updateRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule.uid, ruleChange.oldRule, ruleChange.updatePayload);
|
|
839
879
|
break;
|
|
840
|
-
case "remove":
|
|
841
|
-
this._removeRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
|
|
842
|
-
break;
|
|
880
|
+
case "remove": this._removeRule(ruleChange.unitId, ruleChange.subUnitId, ruleChange.rule);
|
|
843
881
|
}
|
|
844
882
|
this._ruleChange$.next(ruleChange);
|
|
845
883
|
}));
|
|
@@ -1551,7 +1589,8 @@ var ListValidator = class extends BaseSheetValidator {
|
|
|
1551
1589
|
return { tb };
|
|
1552
1590
|
}
|
|
1553
1591
|
parseCellValue(cellValue) {
|
|
1554
|
-
|
|
1592
|
+
const cellString = cellValue.toString();
|
|
1593
|
+
return deserializeListOptions(cellString);
|
|
1555
1594
|
}
|
|
1556
1595
|
async parseFormula(rule, unitId, subUnitId) {
|
|
1557
1596
|
var _results$;
|
|
@@ -1702,7 +1741,8 @@ function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, sour
|
|
|
1702
1741
|
const redoMutations = [];
|
|
1703
1742
|
const undoMutations = [];
|
|
1704
1743
|
const sheetDataValidationModel = accessor.get(SheetDataValidationModel);
|
|
1705
|
-
const
|
|
1744
|
+
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1745
|
+
const target = getSheetCommandTarget(univerInstanceService, {
|
|
1706
1746
|
unitId,
|
|
1707
1747
|
subUnitId
|
|
1708
1748
|
});
|
|
@@ -1715,7 +1755,7 @@ function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, sour
|
|
|
1715
1755
|
let setRangeValue = false;
|
|
1716
1756
|
function setRangesDefaultValue(ranges, defaultValue) {
|
|
1717
1757
|
if (!fillDefaultValue) return;
|
|
1718
|
-
ranges.forEach((range) => {
|
|
1758
|
+
getRangesInWorksheet(ranges, worksheet).forEach((range) => {
|
|
1719
1759
|
Range.foreach(range, (row, column) => {
|
|
1720
1760
|
const cellData = worksheet.getCellRaw(row, column);
|
|
1721
1761
|
const value = getStringCellValue(cellData);
|
|
@@ -1881,8 +1921,6 @@ function getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor, sour
|
|
|
1881
1921
|
const formula = sheetDataValidationModel.getValidator(DataValidationType.CHECKBOX).parseFormulaSync(diff.rule, unitId, subUnitId);
|
|
1882
1922
|
setRangesDefaultValue(diff.rule.ranges, formula.originFormula2);
|
|
1883
1923
|
}
|
|
1884
|
-
break;
|
|
1885
|
-
default: break;
|
|
1886
1924
|
}
|
|
1887
1925
|
});
|
|
1888
1926
|
if (setRangeValue) {
|
|
@@ -2021,7 +2059,8 @@ const UpdateSheetDataValidationSettingCommand = {
|
|
|
2021
2059
|
}];
|
|
2022
2060
|
if (setting.type === DataValidationType.CHECKBOX) {
|
|
2023
2061
|
const ranges = rule.ranges;
|
|
2024
|
-
const
|
|
2062
|
+
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
2063
|
+
const target = getSheetCommandTarget(univerInstanceService, {
|
|
2025
2064
|
unitId,
|
|
2026
2065
|
subUnitId
|
|
2027
2066
|
});
|
|
@@ -2031,7 +2070,7 @@ const UpdateSheetDataValidationSettingCommand = {
|
|
|
2031
2070
|
const { formula2: oldFormula2 = 0, formula1: oldFormula1 = 1 } = rule;
|
|
2032
2071
|
const { formula2 = 0, formula1 = 1 } = setting;
|
|
2033
2072
|
let setted = false;
|
|
2034
|
-
ranges.forEach((range) => {
|
|
2073
|
+
getRangesInWorksheet(ranges, worksheet).forEach((range) => {
|
|
2035
2074
|
Range.foreach(range, (row, column) => {
|
|
2036
2075
|
const cellData = worksheet.getCellRaw(row, column);
|
|
2037
2076
|
const value = getStringCellValue(cellData);
|
|
@@ -2132,7 +2171,8 @@ const ClearRangeDataValidationCommand = {
|
|
|
2132
2171
|
if (!params) return false;
|
|
2133
2172
|
const { unitId, subUnitId, ranges, types } = params;
|
|
2134
2173
|
const commandService = accessor.get(ICommandService);
|
|
2135
|
-
const
|
|
2174
|
+
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
2175
|
+
const target = getSheetCommandTarget(univerInstanceService, {
|
|
2136
2176
|
unitId,
|
|
2137
2177
|
subUnitId
|
|
2138
2178
|
});
|
|
@@ -2290,7 +2330,9 @@ let DataValidationFormulaController = class DataValidationFormulaController exte
|
|
|
2290
2330
|
if (!this._permissionService.getPermissionPoint(new WorksheetViewPermission(unitId, subUnitId).id)) return false;
|
|
2291
2331
|
}
|
|
2292
2332
|
if (!targetSheet) return false;
|
|
2293
|
-
const
|
|
2333
|
+
const range = getRangeInWorksheet(sequenceGrid.range, targetSheet);
|
|
2334
|
+
if (!range) continue;
|
|
2335
|
+
const { startRow, endRow, startColumn, endColumn } = range;
|
|
2294
2336
|
for (let i = startRow; i <= endRow; i++) for (let j = startColumn; j <= endColumn; j++) {
|
|
2295
2337
|
var _targetSheet$getCell;
|
|
2296
2338
|
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];
|
|
@@ -2309,7 +2351,7 @@ DataValidationFormulaController = __decorate([
|
|
|
2309
2351
|
//#endregion
|
|
2310
2352
|
//#region package.json
|
|
2311
2353
|
var name = "@univerjs/sheets-data-validation";
|
|
2312
|
-
var version = "1.0.
|
|
2354
|
+
var version = "1.0.1";
|
|
2313
2355
|
|
|
2314
2356
|
//#endregion
|
|
2315
2357
|
//#region src/config/config.ts
|
|
@@ -3022,7 +3064,8 @@ let DataValidationController = class DataValidationController extends RxDisposab
|
|
|
3022
3064
|
const selections = (_this$_selectionManag = this._selectionManagerService.getCurrentSelections()) === null || _this$_selectionManag === void 0 ? void 0 : _this$_selectionManag.map((s) => s.range);
|
|
3023
3065
|
const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
|
|
3024
3066
|
if (selections) ruleMatrix.removeRange(selections);
|
|
3025
|
-
const
|
|
3067
|
+
const diffs = ruleMatrix.diff(this._sheetDataValidationModel.getRules(unitId, subUnitId));
|
|
3068
|
+
const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, this._injector, "patched");
|
|
3026
3069
|
return {
|
|
3027
3070
|
undos: undoMutations,
|
|
3028
3071
|
redos: redoMutations
|
|
@@ -3060,14 +3103,14 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
|
|
|
3060
3103
|
if (ranges.length === 0) return;
|
|
3061
3104
|
const workbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
|
|
3062
3105
|
const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
|
|
3063
|
-
const map =
|
|
3106
|
+
const map = Object.create(null);
|
|
3064
3107
|
ranges.flat().forEach((range) => {
|
|
3065
|
-
if (!map[range.unitId]) map[range.unitId] =
|
|
3108
|
+
if (!map[range.unitId]) map[range.unitId] = Object.create(null);
|
|
3066
3109
|
if (!map[range.unitId][range.subUnitId]) map[range.unitId][range.subUnitId] = [];
|
|
3067
3110
|
const workbook = this._univerInstanceService.getUnit(range.unitId, UniverInstanceType.UNIVER_SHEET);
|
|
3068
3111
|
const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(range.subUnitId);
|
|
3069
3112
|
if (!worksheet) return;
|
|
3070
|
-
map[range.unitId][range.subUnitId].push(...range.ranges
|
|
3113
|
+
map[range.unitId][range.subUnitId].push(...getRangesInWorksheet(range.ranges, worksheet));
|
|
3071
3114
|
});
|
|
3072
3115
|
Object.entries(map).forEach(([unitId, subUnitMap]) => {
|
|
3073
3116
|
Object.entries(subUnitMap).forEach(([subUnitId, ranges]) => {
|
|
@@ -3120,11 +3163,10 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
|
|
|
3120
3163
|
if (!workbook) throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
3121
3164
|
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
3122
3165
|
if (!worksheet) throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
3123
|
-
const
|
|
3124
|
-
const ruleRanges =
|
|
3125
|
-
for (const rule of allRules) ruleRanges.push(...rule.ranges);
|
|
3166
|
+
const effectiveRanges = getRangesInWorksheet(ranges, worksheet);
|
|
3167
|
+
const ruleRanges = getRangesInWorksheet(this._sheetDataValidationModel.getRules(unitId, subUnitId).flatMap((rule) => rule.ranges), worksheet);
|
|
3126
3168
|
const intersectRanges = [];
|
|
3127
|
-
for (const range of
|
|
3169
|
+
for (const range of effectiveRanges) for (const ruleRange of ruleRanges) {
|
|
3128
3170
|
const intersect = getIntersectRange(range, ruleRange);
|
|
3129
3171
|
if (intersect) intersectRanges.push(intersect);
|
|
3130
3172
|
}
|
|
@@ -3157,31 +3199,32 @@ let SheetsDataValidationValidatorService = class SheetsDataValidationValidatorSe
|
|
|
3157
3199
|
if (!workbook) throw new Error(`cannot find current workbook, unitId: ${unitId}`);
|
|
3158
3200
|
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
3159
3201
|
if (!worksheet) throw new Error(`cannot find current worksheet, sheetId: ${subUnitId}`);
|
|
3160
|
-
const
|
|
3161
|
-
await Promise.all(
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
return Promise.all(promises);
|
|
3168
|
-
}));
|
|
3202
|
+
const ranges = getRangesInWorksheet(this._sheetDataValidationModel.getRules(unitId, subUnitId).flatMap((rule) => rule.ranges), worksheet);
|
|
3203
|
+
await Promise.all(ranges.map((range) => {
|
|
3204
|
+
const promises = [];
|
|
3205
|
+
Range.foreach(range, (row, col) => {
|
|
3206
|
+
promises.push(this._validatorByCell(workbook, worksheet, row, col));
|
|
3207
|
+
});
|
|
3208
|
+
return Promise.all(promises);
|
|
3169
3209
|
}));
|
|
3170
3210
|
return this._dataValidationCacheService.ensureCache(unitId, subUnitId);
|
|
3171
3211
|
}
|
|
3172
3212
|
async validatorWorkbook(unitId) {
|
|
3173
3213
|
const sheetIds = this._sheetDataValidationModel.getSubUnitIds(unitId);
|
|
3174
3214
|
const results = await Promise.all(sheetIds.map((id) => this.validatorWorksheet(unitId, id)));
|
|
3175
|
-
const map =
|
|
3215
|
+
const map = Object.create(null);
|
|
3176
3216
|
results.forEach((result, i) => {
|
|
3177
3217
|
map[sheetIds[i]] = result;
|
|
3178
3218
|
});
|
|
3179
3219
|
return map;
|
|
3180
3220
|
}
|
|
3181
3221
|
getDataValidations(unitId, subUnitId, ranges) {
|
|
3222
|
+
var _this$_univerInstance;
|
|
3223
|
+
const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
|
|
3224
|
+
if (!worksheet) return [];
|
|
3182
3225
|
const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId);
|
|
3183
3226
|
const ruleIdSet = /* @__PURE__ */ new Set();
|
|
3184
|
-
ranges.forEach((range) => {
|
|
3227
|
+
getRangesInWorksheet(ranges, worksheet).forEach((range) => {
|
|
3185
3228
|
Range.foreach(range, (row, col) => {
|
|
3186
3229
|
const ruleId = ruleMatrix.getValue(row, col);
|
|
3187
3230
|
if (ruleId) ruleIdSet.add(ruleId);
|
|
@@ -3294,4 +3337,4 @@ const LIST_FORMULA_INPUT_NAME = "sheets-data-validation.list-formula-input";
|
|
|
3294
3337
|
const CHECKBOX_FORMULA_INPUT_NAME = "sheets-data-validation.checkbox-formula-input";
|
|
3295
3338
|
|
|
3296
3339
|
//#endregion
|
|
3297
|
-
export { AddSheetDataValidationCommand, BASE_FORMULA_INPUT_NAME, CHECKBOX_FORMULA_1, CHECKBOX_FORMULA_2, CHECKBOX_FORMULA_INPUT_NAME, CUSTOM_FORMULA_INPUT_NAME, CheckboxValidator, ClearRangeDataValidationCommand, DATA_VALIDATION_PLUGIN_NAME, DataValidationCacheService, DataValidationCustomFormulaService, DataValidationFormulaController, DataValidationFormulaService, DataValidationListCacheService, DateValidator, LIST_FORMULA_INPUT_NAME, ListMultipleValidator, ListValidator, RemoveSheetAllDataValidationCommand, RemoveSheetDataValidationCommand, SheetDataValidationModel, SheetsDataValidationValidatorService, UniverSheetsDataValidationPlugin, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationRangeCommand, UpdateSheetDataValidationSettingCommand, createDefaultNewRule, getCellValueNumber, getCellValueOrigin, getDataValidationCellValue, getDataValidationDiffMutations, getFormulaCellData, getFormulaResult, getTransformedFormula, isLegalFormulaResult, transformCheckboxValue };
|
|
3340
|
+
export { AddSheetDataValidationCommand, BASE_FORMULA_INPUT_NAME, CHECKBOX_FORMULA_1, CHECKBOX_FORMULA_2, CHECKBOX_FORMULA_INPUT_NAME, CUSTOM_FORMULA_INPUT_NAME, CheckboxValidator, ClearRangeDataValidationCommand, DATA_VALIDATION_PLUGIN_NAME, DataValidationCacheService, DataValidationCustomFormulaService, DataValidationFormulaController, DataValidationFormulaService, DataValidationListCacheService, DateValidator, LIST_FORMULA_INPUT_NAME, ListMultipleValidator, ListValidator, RemoveSheetAllDataValidationCommand, RemoveSheetDataValidationCommand, SheetDataValidationModel, SheetsDataValidationValidatorService, UniverSheetsDataValidationPlugin, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationRangeCommand, UpdateSheetDataValidationSettingCommand, createDefaultNewRule, getCellValueNumber, getCellValueOrigin, getDataValidationCellValue, getDataValidationDiffMutations, getFormulaCellData, getFormulaResult, getRangesInWorksheet, getTransformedFormula, isLegalFormulaResult, transformCheckboxValue };
|
|
@@ -20,6 +20,9 @@ import { FDataValidationBuilder } from './f-data-validation-builder';
|
|
|
20
20
|
* @hideconstructor
|
|
21
21
|
*/
|
|
22
22
|
export declare class FDataValidation {
|
|
23
|
+
/**
|
|
24
|
+
* The underlying validation rule data. Use the Facade setters to update a rule attached to a worksheet.
|
|
25
|
+
*/
|
|
23
26
|
rule: IDataValidationRule;
|
|
24
27
|
private _worksheet;
|
|
25
28
|
private _injector;
|
|
@@ -162,8 +165,8 @@ export declare class FDataValidation {
|
|
|
162
165
|
*/
|
|
163
166
|
getRanges(): FRange[];
|
|
164
167
|
/**
|
|
165
|
-
* Gets the unit ID of the
|
|
166
|
-
* @returns {string | undefined} The unit ID of the
|
|
168
|
+
* Gets the unit ID of the workbook
|
|
169
|
+
* @returns {string | undefined} The unit ID of the workbook
|
|
167
170
|
* @example
|
|
168
171
|
* ```typescript
|
|
169
172
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
@@ -146,7 +146,7 @@ export interface IFRangeSheetsDataValidationMixin {
|
|
|
146
146
|
getValidatorStatus(): Promise<DataValidationStatus[][]>;
|
|
147
147
|
/**
|
|
148
148
|
* Get data validation errors for a specific range in current worksheet.
|
|
149
|
-
* @returns A promise that resolves to an array of validation errors in the specified range.
|
|
149
|
+
* @returns {Promise<IDataValidationError[]>} A promise that resolves to an array of validation errors in the specified range.
|
|
150
150
|
* @example
|
|
151
151
|
* ```ts
|
|
152
152
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
@@ -35,7 +35,7 @@ export interface IDataValidationError {
|
|
|
35
35
|
export interface IFWorkbookSheetsDataValidationMixin {
|
|
36
36
|
/**
|
|
37
37
|
* Get data validation validator status for current workbook.
|
|
38
|
-
* @returns A promise
|
|
38
|
+
* @returns {Promise<Record<string, ObjectMatrix<Nullable<DataValidationStatus>>>>} A promise resolving to an object keyed by sheet ID, with a validation-status matrix for each sheet.
|
|
39
39
|
* @example
|
|
40
40
|
* ```ts
|
|
41
41
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
@@ -46,11 +46,11 @@ export interface IFWorkbookSheetsDataValidationMixin {
|
|
|
46
46
|
getValidatorStatus(): Promise<Record<string, ObjectMatrix<Nullable<DataValidationStatus>>>>;
|
|
47
47
|
/**
|
|
48
48
|
* Get all data validation errors for current workbook.
|
|
49
|
-
* @returns A promise that resolves to an array of validation errors.
|
|
49
|
+
* @returns {Promise<IDataValidationError[]>} A promise that resolves to an array of validation errors.
|
|
50
50
|
* @example
|
|
51
51
|
* ```ts
|
|
52
52
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
53
|
-
* const errors = await fWorkbook.
|
|
53
|
+
* const errors = await fWorkbook.getAllDataValidationErrorAsync();
|
|
54
54
|
* console.log(errors);
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
|
@@ -25,6 +25,7 @@ export interface IFWorksheetDataValidationMixin {
|
|
|
25
25
|
/**
|
|
26
26
|
* Get all data validation rules in current sheet.
|
|
27
27
|
* @returns {FDataValidation[]} All data validation rules
|
|
28
|
+
* @example
|
|
28
29
|
* ```ts
|
|
29
30
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
30
31
|
* const fWorksheet = fWorkbook.getSheetByName('Sheet1');
|
|
@@ -37,6 +38,7 @@ export interface IFWorksheetDataValidationMixin {
|
|
|
37
38
|
/**
|
|
38
39
|
* Get data validation validator status for current sheet.
|
|
39
40
|
* @returns {Promise<ObjectMatrix<Nullable<DataValidationStatus>>>} matrix of validator status
|
|
41
|
+
* @example
|
|
40
42
|
* ```ts
|
|
41
43
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
42
44
|
* const fWorksheet = fWorkbook.getSheetByName('Sheet1');
|
|
@@ -50,6 +52,7 @@ export interface IFWorksheetDataValidationMixin {
|
|
|
50
52
|
* get data validation rule by rule id
|
|
51
53
|
* @param ruleId - the rule id
|
|
52
54
|
* @returns {Nullable<FDataValidation>} data validation rule
|
|
55
|
+
* @example
|
|
53
56
|
* ```ts
|
|
54
57
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
55
58
|
* const fWorksheet = fWorkbook.getSheetByName('Sheet1');
|
|
@@ -61,13 +64,13 @@ export interface IFWorksheetDataValidationMixin {
|
|
|
61
64
|
getDataValidation(ruleId: string): Nullable<FDataValidation>;
|
|
62
65
|
/**
|
|
63
66
|
* Get all data validation errors for current worksheet.
|
|
64
|
-
* @returns A promise that resolves to an array of validation errors.
|
|
67
|
+
* @returns {Promise<IDataValidationError[]>} A promise that resolves to an array of validation errors.
|
|
65
68
|
* @example
|
|
66
69
|
* ```ts
|
|
67
70
|
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
68
71
|
* const fWorksheet = fWorkbook.getSheetByName('Sheet1');
|
|
69
72
|
* if (!fWorksheet) return;
|
|
70
|
-
* const errors = await fWorksheet.
|
|
73
|
+
* const errors = await fWorksheet.getAllDataValidationErrorAsync();
|
|
71
74
|
* console.log(errors);
|
|
72
75
|
* ```
|
|
73
76
|
*/
|
package/lib/types/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export { createDefaultNewRule } from './utils/create';
|
|
|
31
31
|
export { getFormulaCellData, getFormulaResult } from './utils/formula';
|
|
32
32
|
export { isLegalFormulaResult } from './utils/formula';
|
|
33
33
|
export { getCellValueOrigin } from './utils/get-cell-data-origin';
|
|
34
|
+
export { getRangesInWorksheet } from './utils/range';
|
|
34
35
|
export { CHECKBOX_FORMULA_1, CHECKBOX_FORMULA_2, CheckboxValidator, transformCheckboxValue, } from './validators/checkbox-validator';
|
|
35
36
|
export { DateValidator } from './validators/date-validator';
|
|
36
37
|
export { getCellValueNumber } from './validators/decimal-validator';
|
|
@@ -35,6 +35,7 @@ export declare class DataValidationCacheService extends Disposable {
|
|
|
35
35
|
ensureCache(unitId: string, subUnitId: string): ObjectMatrix<Nullable<DataValidationStatus>>;
|
|
36
36
|
addRule(unitId: string, subUnitId: string, rule: ISheetDataValidationRule): void;
|
|
37
37
|
removeRule(unitId: string, subUnitId: string, rule: ISheetDataValidationRule): void;
|
|
38
|
+
private _getEffectiveRanges;
|
|
38
39
|
markRangeDirty(unitId: string, subUnitId: string, ranges: IRange[], isSetRange?: boolean): void;
|
|
39
40
|
private _deleteRange;
|
|
40
41
|
getValue(unitId: string, subUnitId: string, row: number, col: number): Nullable<Nullable<DataValidationStatus>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { IRange, Nullable, Worksheet } from '@univerjs/core';
|
|
17
|
+
export declare function getRangeInWorksheet(range: IRange, worksheet: Worksheet): Nullable<IRange>;
|
|
18
|
+
export declare function getRangesInWorksheet(ranges: IRange[], worksheet: Worksheet): IRange[];
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets-data-validation"),require("@univerjs/sheets/facade"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("@univerjs/core/facade")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-data-validation`,`@univerjs/sheets/facade`,`@univerjs/data-validation`,`@univerjs/engine-formula`,`@univerjs/sheets`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDataValidationFacade={},e.UniverCore,e.UniverSheetsDataValidation,e.UniverSheetsFacade,e.UniverDataValidation,e.UniverEngineFormula,e.UniverSheets,e.UniverCoreFacade))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function c(e){"@babel/helpers - typeof";return c=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},c(e)}function l(e,t){if(c(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(c(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function u(e){var t=l(e,`string`);return c(t)==`symbol`?t:t+``}function d(e,t,n){return(t=u(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var f=class e{constructor(e){d(this,`_rule`,void 0),this._rule=e??{uid:(0,t.generateRandomId)(),ranges:void 0,type:t.DataValidationType.CUSTOM}}build(){return new p(this._rule)}copy(){return new e({...this._rule,uid:(0,t.generateRandomId)()})}getAllowInvalid(){return this._rule.errorStyle!==t.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(e,n){return this._rule.type=t.DataValidationType.CHECKBOX,this._rule.formula1=e,this._rule.formula2=n,this}requireDateAfter(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.GREATER_THAN,this}requireDateBefore(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN,this}requireDateBetween(e,n){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=n.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.BETWEEN,this}requireDateEqualTo(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.EQUAL,this}requireDateNotBetween(e,n){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=n.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(e){return this._rule.type=t.DataValidationType.CUSTOM,this._rule.formula1=e,this._rule.formula2=void 0,this}requireNumberBetween(e,n,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${n}`,this._rule.operator=t.DataValidationOperator.BETWEEN,this._rule.type=r?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberGreaterThan(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberLessThan(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberNotBetween(e,n,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${n}`,this._rule.operator=t.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.NOT_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireValueInList(e,n,r){return this._rule.type=n?t.DataValidationType.LIST_MULTIPLE:t.DataValidationType.LIST,this._rule.formula1=(0,o.serializeListOptions)(e),this._rule.formula2=void 0,this._rule.showDropDown=r??!0,this}requireValueInRange(e,n,r){return this._rule.type=n?t.DataValidationType.LIST_MULTIPLE:t.DataValidationType.LIST,this._rule.formula1=`=${(0,a.serializeRangeToRefString)({unitId:e.getUnitId(),sheetName:e.getSheetName(),range:e.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r??!0,this}setAllowInvalid(e){return this._rule.errorStyle=e?t.DataValidationErrorStyle.WARNING:t.DataValidationErrorStyle.STOP,this}setAllowBlank(e){return this._rule.allowBlank=e,this}setOptions(e){return Object.assign(this._rule,e),this}},p=class{constructor(e,t,n){d(this,`rule`,void 0),d(this,`_worksheet`,void 0),d(this,`_injector`,void 0),this._injector=n,this.rule=e,this._worksheet=t}getAllowInvalid(){return this.rule.errorStyle!==t.DataValidationErrorStyle.STOP}getCriteriaType(){return this.rule.type}getCriteriaValues(){return[this.rule.operator,this.rule.formula1,this.rule.formula2]}getHelpText(){return this.rule.error}copy(){return new f(this.rule)}getApplied(){if(!this._worksheet)return!1;let e=this._injector.get(i.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){if(!this.getApplied())return[];let e=this._injector.get(t.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(t=>this._injector.createInstance(r.FRange,e,this._worksheet,t))}getUnitId(){var e;return(e=this._worksheet)==null?void 0:e.getUnitId()}getSheetId(){var e;return(e=this._worksheet)==null?void 0:e.getSheetId()}setCriteria(e,r,i=!0){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:r[0],formula1:r[1],formula2:r[2],type:this.rule.type,allowBlank:i}}))throw Error(`setCriteria failed`);return this.rule.operator=r[0],this.rule.formula1=r[1],this.rule.formula2=r[2],this.rule.type=e,this.rule.allowBlank=i,this}setOptions(e){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...(0,i.getRuleOptions)(this.rule),...e}}))throw Error(`setOptions failed`);return Object.assign(this.rule,e),this}setRanges(e){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:e.map(e=>e.getRange())}))throw Error(`setRanges failed`);return this.rule.ranges=e.map(e=>e.getRange()),this}delete(){return this.getApplied()?this._injector.get(t.ICommandService).syncExecuteCommand(n.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}},m=class extends r.FRange{setDataValidation(e){if(!e)return this._commandService.syncExecuteCommand(n.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;let t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...e.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(n.AddSheetDataValidationCommand.id,t),this}getDataValidation(){let e=this._injector.get(n.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new p(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(n.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new p(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}async getDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return this._collectValidationErrorsForRange(e,t,[this._range])}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,s=o.getName(),c=[];for(let l of i){let i=[];for(let u=l.startRow;u<=l.endRow;u++)for(let d=l.startColumn;d<=l.endColumn;d++)i.push((async()=>{try{if(await a.validatorCell(e,r,u,d)!==t.DataValidationStatus.VALID){let t=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(e,r,u,d);if(t){var i;let e=((i=o.getCell(u,d))==null?void 0:i.v)||null,n=this._createDataValidationError(s,u,d,t,e);c.push(n)}}}catch(e){console.warn(`Failed to validate cell [${u}, ${d}]:`,e)}})());await Promise.all(i)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}};r.FRange.extend(m);var h=class extends s.FUniver{newDataValidation(){return new f}_initialize(e){let r=e.get(t.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetDataValidationChanged,()=>e.has(n.SheetDataValidationModel)?e.get(n.SheetDataValidationModel).ruleChange$.subscribe(e=>{let{unitId:t,subUnitId:n,rule:r,oldRule:i,type:a}=e,o=this.getSheetCommandTarget({unitId:t,subUnitId:n});if(!o)return;let{workbook:s,worksheet:c}=o,l={origin:e,worksheet:c,workbook:s,changeType:a,oldRule:i,rule:new p(r,c.getSheet(),this._injector)};this.fireEvent(this.Event.SheetDataValidationChanged,l)}):{dispose:()=>{}})),this.disposeWithMe(this.registerEventHandler(this.Event.SheetDataValidatorStatusChanged,()=>e.has(n.SheetDataValidationModel)?e.get(n.SheetDataValidationModel).validStatusChange$.subscribe(e=>{let{unitId:t,subUnitId:n,ruleId:r,status:i,row:a,col:o}=e,s=this.getSheetCommandTarget({unitId:t,subUnitId:n});if(!s)return;let{workbook:c,worksheet:l}=s,u=l.getDataValidation(r);if(!u)return;let d={workbook:c,worksheet:l,row:a,column:o,rule:u,status:i};this.fireEvent(this.Event.SheetDataValidatorStatusChanged,d)}):{dispose:()=>{}})),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd,()=>r.beforeCommandExecuted(e=>{if(e.id===n.AddSheetDataValidationCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{rule:o}=n,s={worksheet:a,workbook:i,rule:o};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,s),s.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationSettingCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o,setting:s}=n,c=a.getDataValidation(o);if(!c)return;let l={worksheet:a,workbook:i,rule:c,ruleId:o,newCriteria:s};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,l),l.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationRangeCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o,ranges:s}=n,c=a.getDataValidation(o);if(!c)return;let l={worksheet:a,workbook:i,rule:c,ruleId:o,newRanges:s};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,l),l.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationOptionsCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o,options:s}=n,c=a.getDataValidation(o);if(!c)return;let l={worksheet:a,workbook:i,rule:c,ruleId:o,newOptions:s};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,l),l.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete,()=>r.beforeCommandExecuted(e=>{if(e.id===n.RemoveSheetDataValidationCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o}=n,s=a.getDataValidation(o);if(!s)return;let c={worksheet:a,workbook:i,rule:s,ruleId:o};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,c),c.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll,()=>r.beforeCommandExecuted(e=>{if(e.id===n.RemoveSheetAllDataValidationCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,o={worksheet:a,workbook:i,rules:a.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,o),o.cancel)throw new t.CanceledError}})))}};s.FUniver.extend(h);var g=class extends r.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(n.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}async getAllDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._dataValidationModel.getSubUnitIds(e),n=[];for(let r of t){let t=await this._collectValidationErrorsForSheet(e,r);n.push(...t)}return n}async _collectValidationErrorsForSheet(e,t){let n=this._dataValidationModel.getRules(e,t);if(!n.length)return[];let r=n.flatMap(e=>e.ranges);return this._collectValidationErrorsForRange(e,t,r)}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._workbook.getSheetBySheetId(r);if(!o)throw Error(`Cannot find worksheet with sheetId: ${r}`);let s=o.getName(),c=[];for(let n of i){let i=[];for(let l=n.startRow;l<=n.endRow;l++)for(let u=n.startColumn;u<=n.endColumn;u++)i.push((async()=>{try{if(await a.validatorCell(e,r,l,u)!==t.DataValidationStatus.VALID){let t=this._dataValidationModel.getRuleByLocation(e,r,l,u);if(t){var n;let e=((n=o.getCell(l,u))==null?void 0:n.v)||null,r=this._createDataValidationError(s,l,u,t,e);c.push(r)}}}catch(e){console.warn(`Failed to validate cell [${l}, ${u}]:`,e)}})());await Promise.all(i)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}};r.FWorkbook.extend(g);var _=class extends r.FWorksheet{getDataValidations(){return this._injector.get(i.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new p(e,this._worksheet,this._injector))}getValidatorStatusAsync(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getDataValidation(e){let t=this._injector.get(i.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);return t?new p(t,this._worksheet,this._injector):null}async getAllDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return this._collectValidationErrorsForSheet(e,t)}async _collectValidationErrorsForSheet(e,t){let n=this._injector.get(i.DataValidationModel).getRules(e,t);if(!n.length)return[];let r=n.flatMap(e=>e.ranges);return this._collectValidationErrorsForRange(e,t,r)}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,s=o.getName(),c=[];for(let l of i){let i=[];for(let u=l.startRow;u<=l.endRow;u++)for(let d=l.startColumn;d<=l.endColumn;d++)i.push((async()=>{try{if(await a.validatorCell(e,r,u,d)!==t.DataValidationStatus.VALID){let t=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(e,r,u,d);if(t){var i;let e=((i=o.getCell(u,d))==null?void 0:i.v)||null,n=this._createDataValidationError(s,u,d,t,e);c.push(n)}}}catch(e){console.warn(`Failed to validate cell [${u}, ${d}]:`,e)}})());await Promise.all(i)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}};r.FWorksheet.extend(_);var v=class extends s.FEventName{get SheetDataValidationChanged(){return`SheetDataValidationChanged`}get SheetDataValidatorStatusChanged(){return`SheetDataValidatorStatusChanged`}get BeforeSheetDataValidationAdd(){return`BeforeSheetDataValidationAdd`}get BeforeSheetDataValidationDelete(){return`BeforeSheetDataValidationDelete`}get BeforeSheetDataValidationDeleteAll(){return`BeforeSheetDataValidationDeleteAll`}get BeforeSheetDataValidationCriteriaUpdate(){return`BeforeSheetDataValidationCriteriaUpdate`}get BeforeSheetDataValidationRangeUpdate(){return`BeforeSheetDataValidationRangeUpdate`}get BeforeSheetDataValidationOptionsUpdate(){return`BeforeSheetDataValidationOptionsUpdate`}};s.FEventName.extend(v),e.FDataValidation=p,e.FDataValidationBuilder=f});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets-data-validation"),require("@univerjs/sheets/facade"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("@univerjs/core/facade")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-data-validation`,`@univerjs/sheets/facade`,`@univerjs/data-validation`,`@univerjs/engine-formula`,`@univerjs/sheets`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDataValidationFacade={},e.UniverCore,e.UniverSheetsDataValidation,e.UniverSheetsFacade,e.UniverDataValidation,e.UniverEngineFormula,e.UniverSheets,e.UniverCoreFacade))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function c(e){"@babel/helpers - typeof";return c=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},c(e)}function l(e,t){if(c(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(c(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function u(e){var t=l(e,`string`);return c(t)==`symbol`?t:t+``}function d(e,t,n){return(t=u(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var f=class e{constructor(e){d(this,`_rule`,void 0),this._rule=e??{uid:(0,t.generateRandomId)(),ranges:void 0,type:t.DataValidationType.CUSTOM}}build(){return new p(this._rule)}copy(){return new e({...this._rule,uid:(0,t.generateRandomId)()})}getAllowInvalid(){return this._rule.showErrorMessage===!1||this._rule.errorStyle!==t.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(e,n){return this._rule.type=t.DataValidationType.CHECKBOX,this._rule.formula1=e,this._rule.formula2=n,this}requireDateAfter(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.GREATER_THAN,this}requireDateBefore(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN,this}requireDateBetween(e,n){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=n.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.BETWEEN,this}requireDateEqualTo(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.EQUAL,this}requireDateNotBetween(e,n){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=n.toLocaleDateString(),this._rule.operator=t.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(e){return this._rule.type=t.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(e){return this._rule.type=t.DataValidationType.CUSTOM,this._rule.formula1=e,this._rule.formula2=void 0,this}requireNumberBetween(e,n,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${n}`,this._rule.operator=t.DataValidationOperator.BETWEEN,this._rule.type=r?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberGreaterThan(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberLessThan(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberNotBetween(e,n,r){return this._rule.formula1=`${e}`,this._rule.formula2=`${n}`,this._rule.operator=t.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(e,n){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=t.DataValidationOperator.NOT_EQUAL,this._rule.type=n?t.DataValidationType.WHOLE:t.DataValidationType.DECIMAL,this}requireValueInList(e,n,r){return this._rule.type=n?t.DataValidationType.LIST_MULTIPLE:t.DataValidationType.LIST,this._rule.formula1=(0,o.serializeListOptions)(e),this._rule.formula2=void 0,this._rule.showDropDown=r??!0,this}requireValueInRange(e,n,r){return this._rule.type=n?t.DataValidationType.LIST_MULTIPLE:t.DataValidationType.LIST,this._rule.formula1=`=${(0,a.serializeRangeToRefString)({unitId:e.getUnitId(),sheetName:e.getSheetName(),range:e.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r??!0,this}setAllowInvalid(e){return this._rule.errorStyle=e?t.DataValidationErrorStyle.WARNING:t.DataValidationErrorStyle.STOP,this}setAllowBlank(e){return this._rule.allowBlank=e,this}setOptions(e){return Object.assign(this._rule,e),this}},p=class{constructor(e,t,n){d(this,`rule`,void 0),d(this,`_worksheet`,void 0),d(this,`_injector`,void 0),this._injector=n,this.rule=e,this._worksheet=t}getAllowInvalid(){return this.rule.showErrorMessage===!1||this.rule.errorStyle!==t.DataValidationErrorStyle.STOP}getCriteriaType(){return this.rule.type}getCriteriaValues(){return[this.rule.operator,this.rule.formula1,this.rule.formula2]}getHelpText(){return this.rule.error}copy(){return new f(this.rule)}getApplied(){if(!this._worksheet)return!1;let e=this._injector.get(i.DataValidationModel).getRuleById(this._worksheet.getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){if(!this.getApplied())return[];let e=this._injector.get(t.IUniverInstanceService).getUnit(this._worksheet.getUnitId());return this.rule.ranges.map(t=>this._injector.createInstance(r.FRange,e,this._worksheet,t))}getUnitId(){var e;return(e=this._worksheet)==null?void 0:e.getUnitId()}getSheetId(){var e;return(e=this._worksheet)==null?void 0:e.getSheetId()}setCriteria(e,r,i=!0){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:r[0],formula1:r[1],formula2:r[2],type:this.rule.type,allowBlank:i}}))throw Error(`setCriteria failed`);return this.rule.operator=r[0],this.rule.formula1=r[1],this.rule.formula2=r[2],this.rule.type=e,this.rule.allowBlank=i,this}setOptions(e){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...(0,i.getRuleOptions)(this.rule),...e}}))throw Error(`setOptions failed`);return Object.assign(this.rule,e),this}setRanges(e){if(this.getApplied()&&!this._injector.get(t.ICommandService).syncExecuteCommand(n.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:e.map(e=>e.getRange())}))throw Error(`setRanges failed`);return this.rule.ranges=e.map(e=>e.getRange()),this}delete(){return this.getApplied()?this._injector.get(t.ICommandService).syncExecuteCommand(n.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}},m=class extends r.FRange{setDataValidation(e){if(!e)return this._commandService.syncExecuteCommand(n.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;let t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...e.rule,ranges:[this._range]}};return this._commandService.syncExecuteCommand(n.AddSheetDataValidationCommand.id,t),this}getDataValidation(){let e=this._injector.get(n.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new p(e,this._worksheet,this._injector)}getDataValidations(){return this._injector.get(n.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new p(e,this._worksheet,this._injector))}async getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}async getDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return this._collectValidationErrorsForRange(e,t,[this._range])}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,s=o.getName(),c=[];for(let l of(0,n.getRangesInWorksheet)(i,o)){let i=[];for(let u=l.startRow;u<=l.endRow;u++)for(let d=l.startColumn;d<=l.endColumn;d++)i.push((async()=>{try{if(await a.validatorCell(e,r,u,d)!==t.DataValidationStatus.VALID){let t=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(e,r,u,d);if(t){var i;let e=((i=o.getCell(u,d))==null?void 0:i.v)||null,n=this._createDataValidationError(s,u,d,t,e);c.push(n)}}}catch(e){console.warn(`Failed to validate cell [${u}, ${d}]:`,e)}})());await Promise.all(i)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}};r.FRange.extend(m);var h=class extends s.FUniver{newDataValidation(){return new f}_initialize(e){let r=e.get(t.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetDataValidationChanged,()=>e.has(n.SheetDataValidationModel)?e.get(n.SheetDataValidationModel).ruleChange$.subscribe(e=>{let{unitId:t,subUnitId:n,rule:r,oldRule:i,type:a}=e,o=this.getSheetCommandTarget({unitId:t,subUnitId:n});if(!o)return;let{workbook:s,worksheet:c}=o,l={origin:e,worksheet:c,workbook:s,changeType:a,oldRule:i,rule:new p(r,c.getSheet(),this._injector)};this.fireEvent(this.Event.SheetDataValidationChanged,l)}):{dispose:()=>{}})),this.disposeWithMe(this.registerEventHandler(this.Event.SheetDataValidatorStatusChanged,()=>e.has(n.SheetDataValidationModel)?e.get(n.SheetDataValidationModel).validStatusChange$.subscribe(e=>{let{unitId:t,subUnitId:n,ruleId:r,status:i,row:a,col:o}=e,s=this.getSheetCommandTarget({unitId:t,subUnitId:n});if(!s)return;let{workbook:c,worksheet:l}=s,u=l.getDataValidation(r);if(!u)return;let d={workbook:c,worksheet:l,row:a,column:o,rule:u,status:i};this.fireEvent(this.Event.SheetDataValidatorStatusChanged,d)}):{dispose:()=>{}})),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd,()=>r.beforeCommandExecuted(e=>{if(e.id===n.AddSheetDataValidationCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{rule:o}=n,s={worksheet:a,workbook:i,rule:o};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,s),s.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationSettingCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o,setting:s}=n,c=a.getDataValidation(o);if(!c)return;let l={worksheet:a,workbook:i,rule:c,ruleId:o,newCriteria:s};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,l),l.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationRangeCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o,ranges:s}=n,c=a.getDataValidation(o);if(!c)return;let l={worksheet:a,workbook:i,rule:c,ruleId:o,newRanges:s};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,l),l.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate,()=>r.beforeCommandExecuted(e=>{if(e.id===n.UpdateSheetDataValidationOptionsCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o,options:s}=n,c=a.getDataValidation(o);if(!c)return;let l={worksheet:a,workbook:i,rule:c,ruleId:o,newOptions:s};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,l),l.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete,()=>r.beforeCommandExecuted(e=>{if(e.id===n.RemoveSheetDataValidationCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,{ruleId:o}=n,s=a.getDataValidation(o);if(!s)return;let c={worksheet:a,workbook:i,rule:s,ruleId:o};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,c),c.cancel)throw new t.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll,()=>r.beforeCommandExecuted(e=>{if(e.id===n.RemoveSheetAllDataValidationCommand.id){let n=e.params,r=this.getSheetCommandTarget(n);if(!r)return;let{workbook:i,worksheet:a}=r,o={worksheet:a,workbook:i,rules:a.getDataValidations()};if(this.fireEvent(this.Event.BeforeSheetDataValidationDeleteAll,o),o.cancel)throw new t.CanceledError}})))}};s.FUniver.extend(h);var g=class extends r.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(n.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}async getAllDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._dataValidationModel.getSubUnitIds(e),n=[];for(let r of t){let t=await this._collectValidationErrorsForSheet(e,r);n.push(...t)}return n}async _collectValidationErrorsForSheet(e,t){let n=this._dataValidationModel.getRules(e,t);if(!n.length)return[];let r=n.flatMap(e=>e.ranges);return this._collectValidationErrorsForRange(e,t,r)}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._workbook.getSheetBySheetId(r);if(!o)throw Error(`Cannot find worksheet with sheetId: ${r}`);let s=o.getName(),c=[];for(let l of(0,n.getRangesInWorksheet)(i,o)){let n=[];for(let i=l.startRow;i<=l.endRow;i++)for(let u=l.startColumn;u<=l.endColumn;u++)n.push((async()=>{try{if(await a.validatorCell(e,r,i,u)!==t.DataValidationStatus.VALID){let t=this._dataValidationModel.getRuleByLocation(e,r,i,u);if(t){var n;let e=((n=o.getCell(i,u))==null?void 0:n.v)||null,r=this._createDataValidationError(s,i,u,t,e);c.push(r)}}}catch(e){console.warn(`Failed to validate cell [${i}, ${u}]:`,e)}})());await Promise.all(n)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}};r.FWorkbook.extend(g);var _=class extends r.FWorksheet{getDataValidations(){return this._injector.get(i.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new p(e,this._worksheet,this._injector))}getValidatorStatusAsync(){return this._injector.get(n.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}getDataValidation(e){let t=this._injector.get(i.DataValidationModel).getRuleById(this._workbook.getUnitId(),this._worksheet.getSheetId(),e);return t?new p(t,this._worksheet,this._injector):null}async getAllDataValidationErrorAsync(){let e=this._workbook.getUnitId(),t=this._worksheet.getSheetId();return this._collectValidationErrorsForSheet(e,t)}async _collectValidationErrorsForSheet(e,t){let n=this._injector.get(i.DataValidationModel).getRules(e,t);if(!n.length)return[];let r=n.flatMap(e=>e.ranges);return this._collectValidationErrorsForRange(e,t,r)}async _collectValidationErrorsForRange(e,r,i){if(!i.length)return[];let a=this._injector.get(n.SheetsDataValidationValidatorService),o=this._worksheet,s=o.getName(),c=[];for(let l of(0,n.getRangesInWorksheet)(i,o)){let i=[];for(let u=l.startRow;u<=l.endRow;u++)for(let d=l.startColumn;d<=l.endColumn;d++)i.push((async()=>{try{if(await a.validatorCell(e,r,u,d)!==t.DataValidationStatus.VALID){let t=this._injector.get(n.SheetDataValidationModel).getRuleByLocation(e,r,u,d);if(t){var i;let e=((i=o.getCell(u,d))==null?void 0:i.v)||null,n=this._createDataValidationError(s,u,d,t,e);c.push(n)}}}catch(e){console.warn(`Failed to validate cell [${u}, ${d}]:`,e)}})());await Promise.all(i)}return c}_createDataValidationError(e,t,n,r,i){return{sheetName:e,row:t,column:n,ruleId:r.uid,inputValue:i,rule:r}}};r.FWorksheet.extend(_);var v=class extends s.FEventName{get SheetDataValidationChanged(){return`SheetDataValidationChanged`}get SheetDataValidatorStatusChanged(){return`SheetDataValidatorStatusChanged`}get BeforeSheetDataValidationAdd(){return`BeforeSheetDataValidationAdd`}get BeforeSheetDataValidationDelete(){return`BeforeSheetDataValidationDelete`}get BeforeSheetDataValidationDeleteAll(){return`BeforeSheetDataValidationDeleteAll`}get BeforeSheetDataValidationCriteriaUpdate(){return`BeforeSheetDataValidationCriteriaUpdate`}get BeforeSheetDataValidationRangeUpdate(){return`BeforeSheetDataValidationRangeUpdate`}get BeforeSheetDataValidationOptionsUpdate(){return`BeforeSheetDataValidationOptionsUpdate`}};s.FEventName.extend(v),e.FDataValidation=p,e.FDataValidationBuilder=f});
|