@univerjs/sheets-data-validation 0.25.0-insiders.20260623-012b5a8 → 0.25.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/LICENSE +176 -0
- package/lib/cjs/facade.js +24 -35
- package/lib/cjs/index.js +7 -7
- package/lib/es/facade.js +24 -35
- package/lib/es/index.js +7 -7
- package/lib/facade.js +24 -35
- package/lib/index.js +7 -7
- package/lib/types/index.d.ts +4 -7
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
- package/lib/types/locale/types.d.ts +0 -18
package/lib/facade.js
CHANGED
|
@@ -6,7 +6,7 @@ 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.133.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.133.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.133.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.133.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,
|
|
@@ -1415,10 +1415,7 @@ var FUniverSheetsDataValidationMixin = class extends FUniver {
|
|
|
1415
1415
|
if (!injector.has(SheetDataValidationModel)) return { dispose: () => {} };
|
|
1416
1416
|
return injector.get(SheetDataValidationModel).ruleChange$.subscribe((ruleChange) => {
|
|
1417
1417
|
const { unitId, subUnitId, rule, oldRule, type } = ruleChange;
|
|
1418
|
-
const target = this.
|
|
1419
|
-
unitId,
|
|
1420
|
-
subUnitId
|
|
1421
|
-
});
|
|
1418
|
+
const target = this.getSheetTarget(unitId, subUnitId);
|
|
1422
1419
|
if (!target) return;
|
|
1423
1420
|
const { workbook, worksheet } = target;
|
|
1424
1421
|
const eventParams = {
|
|
@@ -1436,10 +1433,7 @@ var FUniverSheetsDataValidationMixin = class extends FUniver {
|
|
|
1436
1433
|
if (!injector.has(SheetDataValidationModel)) return { dispose: () => {} };
|
|
1437
1434
|
return injector.get(SheetDataValidationModel).validStatusChange$.subscribe((statusChange) => {
|
|
1438
1435
|
const { unitId, subUnitId, ruleId, status, row, col } = statusChange;
|
|
1439
|
-
const target = this.
|
|
1440
|
-
unitId,
|
|
1441
|
-
subUnitId
|
|
1442
|
-
});
|
|
1436
|
+
const target = this.getSheetTarget(unitId, subUnitId);
|
|
1443
1437
|
if (!target) return;
|
|
1444
1438
|
const { workbook, worksheet } = target;
|
|
1445
1439
|
const rule = worksheet.getDataValidation(ruleId);
|
|
@@ -1458,14 +1452,13 @@ var FUniverSheetsDataValidationMixin = class extends FUniver {
|
|
|
1458
1452
|
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationAdd, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
1459
1453
|
if (commandInfo.id === AddSheetDataValidationCommand.id) {
|
|
1460
1454
|
const params = commandInfo.params;
|
|
1461
|
-
const target = this.
|
|
1455
|
+
const target = this.getSheetTarget(params.unitId, params.subUnitId);
|
|
1462
1456
|
if (!target) return;
|
|
1463
1457
|
const { workbook, worksheet } = target;
|
|
1464
|
-
const { rule } = params;
|
|
1465
1458
|
const eventParams = {
|
|
1466
1459
|
worksheet,
|
|
1467
1460
|
workbook,
|
|
1468
|
-
rule
|
|
1461
|
+
rule: params.rule
|
|
1469
1462
|
};
|
|
1470
1463
|
this.fireEvent(this.Event.BeforeSheetDataValidationAdd, eventParams);
|
|
1471
1464
|
if (eventParams.cancel) throw new CanceledError();
|
|
@@ -1474,18 +1467,17 @@ var FUniverSheetsDataValidationMixin = class extends FUniver {
|
|
|
1474
1467
|
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationCriteriaUpdate, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
1475
1468
|
if (commandInfo.id === UpdateSheetDataValidationSettingCommand.id) {
|
|
1476
1469
|
const params = commandInfo.params;
|
|
1477
|
-
const target = this.
|
|
1470
|
+
const target = this.getSheetTarget(params.unitId, params.subUnitId);
|
|
1478
1471
|
if (!target) return;
|
|
1479
1472
|
const { workbook, worksheet } = target;
|
|
1480
|
-
const
|
|
1481
|
-
const rule = worksheet.getDataValidation(ruleId);
|
|
1473
|
+
const rule = worksheet.getDataValidation(params.ruleId);
|
|
1482
1474
|
if (!rule) return;
|
|
1483
1475
|
const eventParams = {
|
|
1484
1476
|
worksheet,
|
|
1485
1477
|
workbook,
|
|
1486
1478
|
rule,
|
|
1487
|
-
ruleId,
|
|
1488
|
-
newCriteria
|
|
1479
|
+
ruleId: params.ruleId,
|
|
1480
|
+
newCriteria: params.setting
|
|
1489
1481
|
};
|
|
1490
1482
|
this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate, eventParams);
|
|
1491
1483
|
if (eventParams.cancel) throw new CanceledError();
|
|
@@ -1494,18 +1486,17 @@ var FUniverSheetsDataValidationMixin = class extends FUniver {
|
|
|
1494
1486
|
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationRangeUpdate, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
1495
1487
|
if (commandInfo.id === UpdateSheetDataValidationRangeCommand.id) {
|
|
1496
1488
|
const params = commandInfo.params;
|
|
1497
|
-
const target = this.
|
|
1489
|
+
const target = this.getSheetTarget(params.unitId, params.subUnitId);
|
|
1498
1490
|
if (!target) return;
|
|
1499
1491
|
const { workbook, worksheet } = target;
|
|
1500
|
-
const
|
|
1501
|
-
const rule = worksheet.getDataValidation(ruleId);
|
|
1492
|
+
const rule = worksheet.getDataValidation(params.ruleId);
|
|
1502
1493
|
if (!rule) return;
|
|
1503
1494
|
const eventParams = {
|
|
1504
1495
|
worksheet,
|
|
1505
1496
|
workbook,
|
|
1506
1497
|
rule,
|
|
1507
|
-
ruleId,
|
|
1508
|
-
newRanges
|
|
1498
|
+
ruleId: params.ruleId,
|
|
1499
|
+
newRanges: params.ranges
|
|
1509
1500
|
};
|
|
1510
1501
|
this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate, eventParams);
|
|
1511
1502
|
if (eventParams.cancel) throw new CanceledError();
|
|
@@ -1514,18 +1505,17 @@ var FUniverSheetsDataValidationMixin = class extends FUniver {
|
|
|
1514
1505
|
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationOptionsUpdate, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
1515
1506
|
if (commandInfo.id === UpdateSheetDataValidationOptionsCommand.id) {
|
|
1516
1507
|
const params = commandInfo.params;
|
|
1517
|
-
const target = this.
|
|
1508
|
+
const target = this.getSheetTarget(params.unitId, params.subUnitId);
|
|
1518
1509
|
if (!target) return;
|
|
1519
1510
|
const { workbook, worksheet } = target;
|
|
1520
|
-
const
|
|
1521
|
-
const rule = worksheet.getDataValidation(ruleId);
|
|
1511
|
+
const rule = worksheet.getDataValidation(params.ruleId);
|
|
1522
1512
|
if (!rule) return;
|
|
1523
1513
|
const eventParams = {
|
|
1524
1514
|
worksheet,
|
|
1525
1515
|
workbook,
|
|
1526
1516
|
rule,
|
|
1527
|
-
ruleId,
|
|
1528
|
-
newOptions
|
|
1517
|
+
ruleId: params.ruleId,
|
|
1518
|
+
newOptions: params.options
|
|
1529
1519
|
};
|
|
1530
1520
|
this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate, eventParams);
|
|
1531
1521
|
if (eventParams.cancel) throw new CanceledError();
|
|
@@ -1534,17 +1524,16 @@ var FUniverSheetsDataValidationMixin = class extends FUniver {
|
|
|
1534
1524
|
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDelete, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
1535
1525
|
if (commandInfo.id === RemoveSheetDataValidationCommand.id) {
|
|
1536
1526
|
const params = commandInfo.params;
|
|
1537
|
-
const target = this.
|
|
1527
|
+
const target = this.getSheetTarget(params.unitId, params.subUnitId);
|
|
1538
1528
|
if (!target) return;
|
|
1539
1529
|
const { workbook, worksheet } = target;
|
|
1540
|
-
const
|
|
1541
|
-
const rule = worksheet.getDataValidation(ruleId);
|
|
1530
|
+
const rule = worksheet.getDataValidation(params.ruleId);
|
|
1542
1531
|
if (!rule) return;
|
|
1543
1532
|
const eventParams = {
|
|
1544
1533
|
worksheet,
|
|
1545
1534
|
workbook,
|
|
1546
1535
|
rule,
|
|
1547
|
-
ruleId
|
|
1536
|
+
ruleId: params.ruleId
|
|
1548
1537
|
};
|
|
1549
1538
|
this.fireEvent(this.Event.BeforeSheetDataValidationDelete, eventParams);
|
|
1550
1539
|
if (eventParams.cancel) throw new CanceledError();
|
|
@@ -1553,7 +1542,7 @@ var FUniverSheetsDataValidationMixin = class extends FUniver {
|
|
|
1553
1542
|
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetDataValidationDeleteAll, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
1554
1543
|
if (commandInfo.id === RemoveSheetAllDataValidationCommand.id) {
|
|
1555
1544
|
const params = commandInfo.params;
|
|
1556
|
-
const target = this.
|
|
1545
|
+
const target = this.getSheetTarget(params.unitId, params.subUnitId);
|
|
1557
1546
|
if (!target) return;
|
|
1558
1547
|
const { workbook, worksheet } = target;
|
|
1559
1548
|
const eventParams = {
|
package/lib/index.js
CHANGED
|
@@ -6,7 +6,7 @@ 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 \0@oxc-project+runtime@0.
|
|
9
|
+
//#region \0@oxc-project+runtime@0.133.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.133.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.133.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.133.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,
|
|
@@ -48,7 +48,7 @@ function _defineProperty(e, r, t) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
//#endregion
|
|
51
|
-
//#region \0@oxc-project+runtime@0.
|
|
51
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
|
|
52
52
|
function __decorateParam(paramIndex, decorator) {
|
|
53
53
|
return function(target, key) {
|
|
54
54
|
decorator(target, key, paramIndex);
|
|
@@ -56,7 +56,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
//#endregion
|
|
59
|
-
//#region \0@oxc-project+runtime@0.
|
|
59
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
|
|
60
60
|
function __decorate(decorators, target, key, desc) {
|
|
61
61
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
62
62
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2308,7 +2308,7 @@ DataValidationFormulaController = __decorate([
|
|
|
2308
2308
|
//#endregion
|
|
2309
2309
|
//#region package.json
|
|
2310
2310
|
var name = "@univerjs/sheets-data-validation";
|
|
2311
|
-
var version = "0.25.
|
|
2311
|
+
var version = "0.25.1";
|
|
2312
2312
|
|
|
2313
2313
|
//#endregion
|
|
2314
2314
|
//#region src/config/config.ts
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,25 +13,22 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export { AddSheetDataValidationCommand, ClearRangeDataValidationCommand, getDataValidationDiffMutations, RemoveSheetAllDataValidationCommand, RemoveSheetDataValidationCommand, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationRangeCommand, UpdateSheetDataValidationSettingCommand, } from './commands/commands/data-validation.command';
|
|
17
|
-
export type { IAddSheetDataValidationCommandParams, IClearRangeDataValidationCommandParams, IRemoveSheetAllDataValidationCommandParams, IRemoveSheetDataValidationCommandParams, IUpdateSheetDataValidationOptionsCommandParams, IUpdateSheetDataValidationRangeCommandParams, IUpdateSheetDataValidationSettingCommandParams, } from './commands/commands/data-validation.command';
|
|
16
|
+
export { AddSheetDataValidationCommand, ClearRangeDataValidationCommand, getDataValidationDiffMutations, type IAddSheetDataValidationCommandParams, type IClearRangeDataValidationCommandParams, type IRemoveSheetAllDataValidationCommandParams, type IRemoveSheetDataValidationCommandParams, type IUpdateSheetDataValidationOptionsCommandParams, type IUpdateSheetDataValidationRangeCommandParams, type IUpdateSheetDataValidationSettingCommandParams, RemoveSheetAllDataValidationCommand, RemoveSheetDataValidationCommand, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationRangeCommand, UpdateSheetDataValidationSettingCommand, } from './commands/commands/data-validation.command';
|
|
18
17
|
export { DATA_VALIDATION_PLUGIN_NAME } from './common/const';
|
|
19
18
|
export type { IUniverSheetsDataValidationConfig } from './config/config';
|
|
20
19
|
export { DataValidationFormulaController } from './controllers/dv-formula.controller';
|
|
21
|
-
export { SheetDataValidationModel } from './models/sheet-data-validation-model';
|
|
22
|
-
export type { IValidStatusChange } from './models/sheet-data-validation-model';
|
|
20
|
+
export { type IValidStatusChange, SheetDataValidationModel } from './models/sheet-data-validation-model';
|
|
23
21
|
export { UniverSheetsDataValidationPlugin } from './plugin';
|
|
24
22
|
export { DataValidationCacheService } from './services/dv-cache.service';
|
|
25
23
|
export { DataValidationCustomFormulaService } from './services/dv-custom-formula.service';
|
|
26
24
|
export { DataValidationFormulaService } from './services/dv-formula.service';
|
|
27
|
-
export { DataValidationListCacheService } from './services/dv-list-cache.service';
|
|
28
|
-
export type { IListCacheItem } from './services/dv-list-cache.service';
|
|
25
|
+
export { DataValidationListCacheService, type IListCacheItem } from './services/dv-list-cache.service';
|
|
29
26
|
export { SheetsDataValidationValidatorService } from './services/dv-validator.service';
|
|
30
27
|
export { createDefaultNewRule } from './utils/create';
|
|
31
28
|
export { getFormulaCellData, getFormulaResult } from './utils/formula';
|
|
32
29
|
export { isLegalFormulaResult } from './utils/formula';
|
|
33
30
|
export { getCellValueOrigin } from './utils/get-cell-data-origin';
|
|
34
|
-
export { CHECKBOX_FORMULA_1, CHECKBOX_FORMULA_2, CheckboxValidator, transformCheckboxValue
|
|
31
|
+
export { CHECKBOX_FORMULA_1, CHECKBOX_FORMULA_2, CheckboxValidator, transformCheckboxValue } from './validators/checkbox-validator';
|
|
35
32
|
export { DateValidator } from './validators/date-validator';
|
|
36
33
|
export { getCellValueNumber } from './validators/decimal-validator';
|
|
37
34
|
export { ListMultipleValidator } from './validators/list-multiple-validator';
|
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==null?{uid:(0,t.generateRandomId)(),ranges:void 0,type:t.DataValidationType.CUSTOM}:e}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==null?!0:r,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==null?!0:r,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{static newDataValidation(){return new f}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==null?{uid:(0,t.generateRandomId)(),ranges:void 0,type:t.DataValidationType.CUSTOM}:e}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==null?!0:r,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==null?!0:r,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{static newDataValidation(){return new f}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.getSheetTarget(t,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.getSheetTarget(t,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.getSheetTarget(n.unitId,n.subUnitId);if(!r)return;let{workbook:i,worksheet:a}=r,o={worksheet:a,workbook:i,rule:n.rule};if(this.fireEvent(this.Event.BeforeSheetDataValidationAdd,o),o.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.getSheetTarget(n.unitId,n.subUnitId);if(!r)return;let{workbook:i,worksheet:a}=r,o=a.getDataValidation(n.ruleId);if(!o)return;let s={worksheet:a,workbook:i,rule:o,ruleId:n.ruleId,newCriteria:n.setting};if(this.fireEvent(this.Event.BeforeSheetDataValidationCriteriaUpdate,s),s.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.getSheetTarget(n.unitId,n.subUnitId);if(!r)return;let{workbook:i,worksheet:a}=r,o=a.getDataValidation(n.ruleId);if(!o)return;let s={worksheet:a,workbook:i,rule:o,ruleId:n.ruleId,newRanges:n.ranges};if(this.fireEvent(this.Event.BeforeSheetDataValidationRangeUpdate,s),s.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.getSheetTarget(n.unitId,n.subUnitId);if(!r)return;let{workbook:i,worksheet:a}=r,o=a.getDataValidation(n.ruleId);if(!o)return;let s={worksheet:a,workbook:i,rule:o,ruleId:n.ruleId,newOptions:n.options};if(this.fireEvent(this.Event.BeforeSheetDataValidationOptionsUpdate,s),s.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.getSheetTarget(n.unitId,n.subUnitId);if(!r)return;let{workbook:i,worksheet:a}=r,o=a.getDataValidation(n.ruleId);if(!o)return;let s={worksheet:a,workbook:i,rule:o,ruleId:n.ruleId};if(this.fireEvent(this.Event.BeforeSheetDataValidationDelete,s),s.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.getSheetTarget(n.unitId,n.subUnitId);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});
|