@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/es/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 };
|
package/lib/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 {
|