@univerjs/data-validation 1.0.0-insiders.20260728-e98f416 → 1.0.0-insiders.20260729-84ae2bd

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/index.js CHANGED
@@ -364,7 +364,28 @@ DataValidationResourceController = __decorate([
364
364
  //#endregion
365
365
  //#region package.json
366
366
  var name = "@univerjs/data-validation";
367
- var version = "1.0.0-insiders.20260728-e98f416";
367
+ var version = "1.0.0-insiders.20260729-84ae2bd";
368
+
369
+ //#endregion
370
+ //#region src/config/config.ts
371
+ /**
372
+ * Copyright 2023-present DreamNum Co., Ltd.
373
+ *
374
+ * Licensed under the Apache License, Version 2.0 (the "License");
375
+ * you may not use this file except in compliance with the License.
376
+ * You may obtain a copy of the License at
377
+ *
378
+ * http://www.apache.org/licenses/LICENSE-2.0
379
+ *
380
+ * Unless required by applicable law or agreed to in writing, software
381
+ * distributed under the License is distributed on an "AS IS" BASIS,
382
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
383
+ * See the License for the specific language governing permissions and
384
+ * limitations under the License.
385
+ */
386
+ const DATA_VALIDATION_PLUGIN_CONFIG_KEY = "data-validation.config";
387
+ const configSymbol = Symbol(DATA_VALIDATION_PLUGIN_CONFIG_KEY);
388
+ const defaultPluginConfig = {};
368
389
 
369
390
  //#endregion
370
391
  //#region src/services/data-validator-registry.service.ts
@@ -418,256 +439,6 @@ var DataValidatorRegistryService = class {
418
439
  }
419
440
  };
420
441
 
421
- //#endregion
422
- //#region src/commands/commands/data-validation.command.ts
423
- /**
424
- * @deprecated `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!
425
- */
426
- const AddDataValidationCommand = {
427
- type: _univerjs_core.CommandType.COMMAND,
428
- id: "data-validation.command.addRule",
429
- async handler(accessor, params) {
430
- accessor.get(_univerjs_core.ILogService).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!");
431
- if (!params) return false;
432
- const { rule, unitId, subUnitId } = params;
433
- const commandService = accessor.get(_univerjs_core.ICommandService);
434
- const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
435
- const mutationParams = {
436
- ...params,
437
- rule: {
438
- ...params.rule,
439
- ranges: [params.rule.range]
440
- }
441
- };
442
- const redoMutations = [{
443
- id: AddDataValidationMutation.id,
444
- params: mutationParams
445
- }];
446
- const undoMutations = [{
447
- id: RemoveDataValidationMutation.id,
448
- params: {
449
- unitId,
450
- subUnitId,
451
- ruleId: rule.uid
452
- }
453
- }];
454
- undoRedoService.pushUndoRedo({
455
- unitID: unitId,
456
- redoMutations,
457
- undoMutations
458
- });
459
- await commandService.executeCommand(AddDataValidationMutation.id, mutationParams);
460
- return true;
461
- }
462
- };
463
- /**
464
- * @deprecated `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!
465
- */
466
- const RemoveDataValidationCommand = {
467
- type: _univerjs_core.CommandType.COMMAND,
468
- id: "data-validation.command.removeRule",
469
- handler(accessor, params) {
470
- accessor.get(_univerjs_core.ILogService).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!");
471
- if (!params) return false;
472
- const { unitId, subUnitId, ruleId } = params;
473
- const commandService = accessor.get(_univerjs_core.ICommandService);
474
- const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
475
- const dataValidationModel = accessor.get(DataValidationModel);
476
- const redoMutations = [{
477
- id: RemoveDataValidationMutation.id,
478
- params
479
- }];
480
- const undoMutations = [{
481
- id: AddDataValidationMutation.id,
482
- params: {
483
- unitId,
484
- subUnitId,
485
- rule: { ...dataValidationModel.getRuleById(unitId, subUnitId, ruleId) },
486
- index: dataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
487
- }
488
- }];
489
- undoRedoService.pushUndoRedo({
490
- undoMutations,
491
- redoMutations,
492
- unitID: params.unitId
493
- });
494
- commandService.executeCommand(RemoveDataValidationMutation.id, params);
495
- return true;
496
- }
497
- };
498
- /**
499
- * @deprecated `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!
500
- */
501
- const UpdateDataValidationOptionsCommand = {
502
- type: _univerjs_core.CommandType.COMMAND,
503
- id: "data-validation.command.updateDataValidationSetting",
504
- handler(accessor, params) {
505
- accessor.get(_univerjs_core.ILogService).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!");
506
- if (!params) return false;
507
- const commandService = accessor.get(_univerjs_core.ICommandService);
508
- const redoUndoService = accessor.get(_univerjs_core.IUndoRedoService);
509
- const dataValidationModel = accessor.get(DataValidationModel);
510
- const { unitId, subUnitId, ruleId, options } = params;
511
- const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
512
- if (!rule) return false;
513
- const mutationParams = {
514
- unitId,
515
- subUnitId,
516
- ruleId,
517
- payload: {
518
- type: 2,
519
- payload: options
520
- }
521
- };
522
- const redoMutations = [{
523
- id: UpdateDataValidationMutation.id,
524
- params: mutationParams
525
- }];
526
- const undoMutationParams = {
527
- unitId,
528
- subUnitId,
529
- ruleId,
530
- payload: {
531
- type: 2,
532
- payload: getRuleOptions(rule)
533
- }
534
- };
535
- const undoMutations = [{
536
- id: UpdateDataValidationMutation.id,
537
- params: undoMutationParams
538
- }];
539
- redoUndoService.pushUndoRedo({
540
- unitID: unitId,
541
- redoMutations,
542
- undoMutations
543
- });
544
- commandService.executeCommand(UpdateDataValidationMutation.id, mutationParams);
545
- return true;
546
- }
547
- };
548
- /**
549
- * @deprecated `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!
550
- */
551
- const UpdateDataValidationSettingCommand = {
552
- type: _univerjs_core.CommandType.COMMAND,
553
- id: "data-validation.command.updateDataValidationOptions",
554
- handler(accessor, params) {
555
- accessor.get(_univerjs_core.ILogService).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!");
556
- if (!params) return false;
557
- const commandService = accessor.get(_univerjs_core.ICommandService);
558
- const redoUndoService = accessor.get(_univerjs_core.IUndoRedoService);
559
- const dataValidationModel = accessor.get(DataValidationModel);
560
- const dataValidatorRegistryService = accessor.get(DataValidatorRegistryService);
561
- const { unitId, subUnitId, ruleId, setting } = params;
562
- const validator = dataValidatorRegistryService.getValidatorItem(setting.type);
563
- if (!validator) return false;
564
- const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
565
- if (!rule) return false;
566
- const newRule = {
567
- ...rule,
568
- ...setting
569
- };
570
- if (!validator.validatorFormula(newRule, unitId, subUnitId).success) return false;
571
- const mutationParams = {
572
- unitId,
573
- subUnitId,
574
- ruleId,
575
- payload: {
576
- type: 0,
577
- payload: {
578
- ...setting,
579
- ...validator.normalizeFormula(newRule, unitId, subUnitId)
580
- }
581
- }
582
- };
583
- const redoMutations = [{
584
- id: UpdateDataValidationMutation.id,
585
- params: mutationParams
586
- }];
587
- const undoMutationParams = {
588
- unitId,
589
- subUnitId,
590
- ruleId,
591
- payload: {
592
- type: 0,
593
- payload: getRuleSetting(rule)
594
- }
595
- };
596
- const undoMutations = [{
597
- id: UpdateDataValidationMutation.id,
598
- params: undoMutationParams
599
- }];
600
- redoUndoService.pushUndoRedo({
601
- unitID: unitId,
602
- redoMutations,
603
- undoMutations
604
- });
605
- commandService.executeCommand(UpdateDataValidationMutation.id, mutationParams);
606
- return true;
607
- }
608
- };
609
- /**
610
- * @deprecated `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!
611
- */
612
- const RemoveAllDataValidationCommand = {
613
- type: _univerjs_core.CommandType.COMMAND,
614
- id: "data-validation.command.removeAll",
615
- handler(accessor, params) {
616
- accessor.get(_univerjs_core.ILogService).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!");
617
- if (!params) return false;
618
- const { unitId, subUnitId } = params;
619
- const commandService = accessor.get(_univerjs_core.ICommandService);
620
- const dataValidationModel = accessor.get(DataValidationModel);
621
- const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
622
- const currentRules = [...dataValidationModel.getRules(unitId, subUnitId)];
623
- const redoParams = {
624
- unitId,
625
- subUnitId,
626
- ruleId: currentRules.map((rule) => rule.uid)
627
- };
628
- const redoMutations = [{
629
- id: RemoveDataValidationMutation.id,
630
- params: redoParams
631
- }];
632
- const undoMutations = [{
633
- id: AddDataValidationMutation.id,
634
- params: {
635
- unitId,
636
- subUnitId,
637
- rule: currentRules
638
- }
639
- }];
640
- undoRedoService.pushUndoRedo({
641
- redoMutations,
642
- undoMutations,
643
- unitID: unitId
644
- });
645
- commandService.executeCommand(RemoveDataValidationMutation.id, redoParams);
646
- return true;
647
- }
648
- };
649
-
650
- //#endregion
651
- //#region src/config/config.ts
652
- /**
653
- * Copyright 2023-present DreamNum Co., Ltd.
654
- *
655
- * Licensed under the Apache License, Version 2.0 (the "License");
656
- * you may not use this file except in compliance with the License.
657
- * You may obtain a copy of the License at
658
- *
659
- * http://www.apache.org/licenses/LICENSE-2.0
660
- *
661
- * Unless required by applicable law or agreed to in writing, software
662
- * distributed under the License is distributed on an "AS IS" BASIS,
663
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
664
- * See the License for the specific language governing permissions and
665
- * limitations under the License.
666
- */
667
- const DATA_VALIDATION_PLUGIN_CONFIG_KEY = "data-validation.config";
668
- const configSymbol = Symbol(DATA_VALIDATION_PLUGIN_CONFIG_KEY);
669
- const defaultPluginConfig = {};
670
-
671
442
  //#endregion
672
443
  //#region src/plugin.ts
673
444
  let UniverDataValidationPlugin = class UniverDataValidationPlugin extends _univerjs_core.Plugin {
@@ -687,11 +458,6 @@ let UniverDataValidationPlugin = class UniverDataValidationPlugin extends _unive
687
458
  [DataValidationResourceController]
688
459
  ].forEach((d) => this._injector.add(d));
689
460
  [
690
- AddDataValidationCommand,
691
- RemoveAllDataValidationCommand,
692
- UpdateDataValidationOptionsCommand,
693
- UpdateDataValidationSettingCommand,
694
- RemoveDataValidationCommand,
695
461
  AddDataValidationMutation,
696
462
  UpdateDataValidationMutation,
697
463
  RemoveDataValidationMutation
package/lib/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { CommandType, DataValidationOperator, Disposable, ICommandService, IConfigService, ILogService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, Tools, UniverInstanceType, merge, toDisposable } from "@univerjs/core";
1
+ import { CommandType, DataValidationOperator, Disposable, ICommandService, IConfigService, ILogService, IResourceManagerService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, Tools, UniverInstanceType, merge, toDisposable } from "@univerjs/core";
2
2
  import { BehaviorSubject, Subject, debounceTime } from "rxjs";
3
3
 
4
4
  //#region src/common/util.ts
@@ -363,7 +363,28 @@ DataValidationResourceController = __decorate([
363
363
  //#endregion
364
364
  //#region package.json
365
365
  var name = "@univerjs/data-validation";
366
- var version = "1.0.0-insiders.20260728-e98f416";
366
+ var version = "1.0.0-insiders.20260729-84ae2bd";
367
+
368
+ //#endregion
369
+ //#region src/config/config.ts
370
+ /**
371
+ * Copyright 2023-present DreamNum Co., Ltd.
372
+ *
373
+ * Licensed under the Apache License, Version 2.0 (the "License");
374
+ * you may not use this file except in compliance with the License.
375
+ * You may obtain a copy of the License at
376
+ *
377
+ * http://www.apache.org/licenses/LICENSE-2.0
378
+ *
379
+ * Unless required by applicable law or agreed to in writing, software
380
+ * distributed under the License is distributed on an "AS IS" BASIS,
381
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
382
+ * See the License for the specific language governing permissions and
383
+ * limitations under the License.
384
+ */
385
+ const DATA_VALIDATION_PLUGIN_CONFIG_KEY = "data-validation.config";
386
+ const configSymbol = Symbol(DATA_VALIDATION_PLUGIN_CONFIG_KEY);
387
+ const defaultPluginConfig = {};
367
388
 
368
389
  //#endregion
369
390
  //#region src/services/data-validator-registry.service.ts
@@ -417,256 +438,6 @@ var DataValidatorRegistryService = class {
417
438
  }
418
439
  };
419
440
 
420
- //#endregion
421
- //#region src/commands/commands/data-validation.command.ts
422
- /**
423
- * @deprecated `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!
424
- */
425
- const AddDataValidationCommand = {
426
- type: CommandType.COMMAND,
427
- id: "data-validation.command.addRule",
428
- async handler(accessor, params) {
429
- accessor.get(ILogService).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!");
430
- if (!params) return false;
431
- const { rule, unitId, subUnitId } = params;
432
- const commandService = accessor.get(ICommandService);
433
- const undoRedoService = accessor.get(IUndoRedoService);
434
- const mutationParams = {
435
- ...params,
436
- rule: {
437
- ...params.rule,
438
- ranges: [params.rule.range]
439
- }
440
- };
441
- const redoMutations = [{
442
- id: AddDataValidationMutation.id,
443
- params: mutationParams
444
- }];
445
- const undoMutations = [{
446
- id: RemoveDataValidationMutation.id,
447
- params: {
448
- unitId,
449
- subUnitId,
450
- ruleId: rule.uid
451
- }
452
- }];
453
- undoRedoService.pushUndoRedo({
454
- unitID: unitId,
455
- redoMutations,
456
- undoMutations
457
- });
458
- await commandService.executeCommand(AddDataValidationMutation.id, mutationParams);
459
- return true;
460
- }
461
- };
462
- /**
463
- * @deprecated `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!
464
- */
465
- const RemoveDataValidationCommand = {
466
- type: CommandType.COMMAND,
467
- id: "data-validation.command.removeRule",
468
- handler(accessor, params) {
469
- accessor.get(ILogService).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!");
470
- if (!params) return false;
471
- const { unitId, subUnitId, ruleId } = params;
472
- const commandService = accessor.get(ICommandService);
473
- const undoRedoService = accessor.get(IUndoRedoService);
474
- const dataValidationModel = accessor.get(DataValidationModel);
475
- const redoMutations = [{
476
- id: RemoveDataValidationMutation.id,
477
- params
478
- }];
479
- const undoMutations = [{
480
- id: AddDataValidationMutation.id,
481
- params: {
482
- unitId,
483
- subUnitId,
484
- rule: { ...dataValidationModel.getRuleById(unitId, subUnitId, ruleId) },
485
- index: dataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
486
- }
487
- }];
488
- undoRedoService.pushUndoRedo({
489
- undoMutations,
490
- redoMutations,
491
- unitID: params.unitId
492
- });
493
- commandService.executeCommand(RemoveDataValidationMutation.id, params);
494
- return true;
495
- }
496
- };
497
- /**
498
- * @deprecated `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!
499
- */
500
- const UpdateDataValidationOptionsCommand = {
501
- type: CommandType.COMMAND,
502
- id: "data-validation.command.updateDataValidationSetting",
503
- handler(accessor, params) {
504
- accessor.get(ILogService).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!");
505
- if (!params) return false;
506
- const commandService = accessor.get(ICommandService);
507
- const redoUndoService = accessor.get(IUndoRedoService);
508
- const dataValidationModel = accessor.get(DataValidationModel);
509
- const { unitId, subUnitId, ruleId, options } = params;
510
- const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
511
- if (!rule) return false;
512
- const mutationParams = {
513
- unitId,
514
- subUnitId,
515
- ruleId,
516
- payload: {
517
- type: 2,
518
- payload: options
519
- }
520
- };
521
- const redoMutations = [{
522
- id: UpdateDataValidationMutation.id,
523
- params: mutationParams
524
- }];
525
- const undoMutationParams = {
526
- unitId,
527
- subUnitId,
528
- ruleId,
529
- payload: {
530
- type: 2,
531
- payload: getRuleOptions(rule)
532
- }
533
- };
534
- const undoMutations = [{
535
- id: UpdateDataValidationMutation.id,
536
- params: undoMutationParams
537
- }];
538
- redoUndoService.pushUndoRedo({
539
- unitID: unitId,
540
- redoMutations,
541
- undoMutations
542
- });
543
- commandService.executeCommand(UpdateDataValidationMutation.id, mutationParams);
544
- return true;
545
- }
546
- };
547
- /**
548
- * @deprecated `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!
549
- */
550
- const UpdateDataValidationSettingCommand = {
551
- type: CommandType.COMMAND,
552
- id: "data-validation.command.updateDataValidationOptions",
553
- handler(accessor, params) {
554
- accessor.get(ILogService).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!");
555
- if (!params) return false;
556
- const commandService = accessor.get(ICommandService);
557
- const redoUndoService = accessor.get(IUndoRedoService);
558
- const dataValidationModel = accessor.get(DataValidationModel);
559
- const dataValidatorRegistryService = accessor.get(DataValidatorRegistryService);
560
- const { unitId, subUnitId, ruleId, setting } = params;
561
- const validator = dataValidatorRegistryService.getValidatorItem(setting.type);
562
- if (!validator) return false;
563
- const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
564
- if (!rule) return false;
565
- const newRule = {
566
- ...rule,
567
- ...setting
568
- };
569
- if (!validator.validatorFormula(newRule, unitId, subUnitId).success) return false;
570
- const mutationParams = {
571
- unitId,
572
- subUnitId,
573
- ruleId,
574
- payload: {
575
- type: 0,
576
- payload: {
577
- ...setting,
578
- ...validator.normalizeFormula(newRule, unitId, subUnitId)
579
- }
580
- }
581
- };
582
- const redoMutations = [{
583
- id: UpdateDataValidationMutation.id,
584
- params: mutationParams
585
- }];
586
- const undoMutationParams = {
587
- unitId,
588
- subUnitId,
589
- ruleId,
590
- payload: {
591
- type: 0,
592
- payload: getRuleSetting(rule)
593
- }
594
- };
595
- const undoMutations = [{
596
- id: UpdateDataValidationMutation.id,
597
- params: undoMutationParams
598
- }];
599
- redoUndoService.pushUndoRedo({
600
- unitID: unitId,
601
- redoMutations,
602
- undoMutations
603
- });
604
- commandService.executeCommand(UpdateDataValidationMutation.id, mutationParams);
605
- return true;
606
- }
607
- };
608
- /**
609
- * @deprecated `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!
610
- */
611
- const RemoveAllDataValidationCommand = {
612
- type: CommandType.COMMAND,
613
- id: "data-validation.command.removeAll",
614
- handler(accessor, params) {
615
- accessor.get(ILogService).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!");
616
- if (!params) return false;
617
- const { unitId, subUnitId } = params;
618
- const commandService = accessor.get(ICommandService);
619
- const dataValidationModel = accessor.get(DataValidationModel);
620
- const undoRedoService = accessor.get(IUndoRedoService);
621
- const currentRules = [...dataValidationModel.getRules(unitId, subUnitId)];
622
- const redoParams = {
623
- unitId,
624
- subUnitId,
625
- ruleId: currentRules.map((rule) => rule.uid)
626
- };
627
- const redoMutations = [{
628
- id: RemoveDataValidationMutation.id,
629
- params: redoParams
630
- }];
631
- const undoMutations = [{
632
- id: AddDataValidationMutation.id,
633
- params: {
634
- unitId,
635
- subUnitId,
636
- rule: currentRules
637
- }
638
- }];
639
- undoRedoService.pushUndoRedo({
640
- redoMutations,
641
- undoMutations,
642
- unitID: unitId
643
- });
644
- commandService.executeCommand(RemoveDataValidationMutation.id, redoParams);
645
- return true;
646
- }
647
- };
648
-
649
- //#endregion
650
- //#region src/config/config.ts
651
- /**
652
- * Copyright 2023-present DreamNum Co., Ltd.
653
- *
654
- * Licensed under the Apache License, Version 2.0 (the "License");
655
- * you may not use this file except in compliance with the License.
656
- * You may obtain a copy of the License at
657
- *
658
- * http://www.apache.org/licenses/LICENSE-2.0
659
- *
660
- * Unless required by applicable law or agreed to in writing, software
661
- * distributed under the License is distributed on an "AS IS" BASIS,
662
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
663
- * See the License for the specific language governing permissions and
664
- * limitations under the License.
665
- */
666
- const DATA_VALIDATION_PLUGIN_CONFIG_KEY = "data-validation.config";
667
- const configSymbol = Symbol(DATA_VALIDATION_PLUGIN_CONFIG_KEY);
668
- const defaultPluginConfig = {};
669
-
670
441
  //#endregion
671
442
  //#region src/plugin.ts
672
443
  let UniverDataValidationPlugin = class UniverDataValidationPlugin extends Plugin {
@@ -686,11 +457,6 @@ let UniverDataValidationPlugin = class UniverDataValidationPlugin extends Plugin
686
457
  [DataValidationResourceController]
687
458
  ].forEach((d) => this._injector.add(d));
688
459
  [
689
- AddDataValidationCommand,
690
- RemoveAllDataValidationCommand,
691
- UpdateDataValidationOptionsCommand,
692
- UpdateDataValidationSettingCommand,
693
- RemoveDataValidationCommand,
694
460
  AddDataValidationMutation,
695
461
  UpdateDataValidationMutation,
696
462
  RemoveDataValidationMutation
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { CommandType, DataValidationOperator, Disposable, ICommandService, IConfigService, ILogService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, Tools, UniverInstanceType, merge, toDisposable } from "@univerjs/core";
1
+ import { CommandType, DataValidationOperator, Disposable, ICommandService, IConfigService, ILogService, IResourceManagerService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, Tools, UniverInstanceType, merge, toDisposable } from "@univerjs/core";
2
2
  import { BehaviorSubject, Subject, debounceTime } from "rxjs";
3
3
 
4
4
  //#region src/common/util.ts
@@ -363,7 +363,28 @@ DataValidationResourceController = __decorate([
363
363
  //#endregion
364
364
  //#region package.json
365
365
  var name = "@univerjs/data-validation";
366
- var version = "1.0.0-insiders.20260728-e98f416";
366
+ var version = "1.0.0-insiders.20260729-84ae2bd";
367
+
368
+ //#endregion
369
+ //#region src/config/config.ts
370
+ /**
371
+ * Copyright 2023-present DreamNum Co., Ltd.
372
+ *
373
+ * Licensed under the Apache License, Version 2.0 (the "License");
374
+ * you may not use this file except in compliance with the License.
375
+ * You may obtain a copy of the License at
376
+ *
377
+ * http://www.apache.org/licenses/LICENSE-2.0
378
+ *
379
+ * Unless required by applicable law or agreed to in writing, software
380
+ * distributed under the License is distributed on an "AS IS" BASIS,
381
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
382
+ * See the License for the specific language governing permissions and
383
+ * limitations under the License.
384
+ */
385
+ const DATA_VALIDATION_PLUGIN_CONFIG_KEY = "data-validation.config";
386
+ const configSymbol = Symbol(DATA_VALIDATION_PLUGIN_CONFIG_KEY);
387
+ const defaultPluginConfig = {};
367
388
 
368
389
  //#endregion
369
390
  //#region src/services/data-validator-registry.service.ts
@@ -417,256 +438,6 @@ var DataValidatorRegistryService = class {
417
438
  }
418
439
  };
419
440
 
420
- //#endregion
421
- //#region src/commands/commands/data-validation.command.ts
422
- /**
423
- * @deprecated `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!
424
- */
425
- const AddDataValidationCommand = {
426
- type: CommandType.COMMAND,
427
- id: "data-validation.command.addRule",
428
- async handler(accessor, params) {
429
- accessor.get(ILogService).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!");
430
- if (!params) return false;
431
- const { rule, unitId, subUnitId } = params;
432
- const commandService = accessor.get(ICommandService);
433
- const undoRedoService = accessor.get(IUndoRedoService);
434
- const mutationParams = {
435
- ...params,
436
- rule: {
437
- ...params.rule,
438
- ranges: [params.rule.range]
439
- }
440
- };
441
- const redoMutations = [{
442
- id: AddDataValidationMutation.id,
443
- params: mutationParams
444
- }];
445
- const undoMutations = [{
446
- id: RemoveDataValidationMutation.id,
447
- params: {
448
- unitId,
449
- subUnitId,
450
- ruleId: rule.uid
451
- }
452
- }];
453
- undoRedoService.pushUndoRedo({
454
- unitID: unitId,
455
- redoMutations,
456
- undoMutations
457
- });
458
- await commandService.executeCommand(AddDataValidationMutation.id, mutationParams);
459
- return true;
460
- }
461
- };
462
- /**
463
- * @deprecated `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!
464
- */
465
- const RemoveDataValidationCommand = {
466
- type: CommandType.COMMAND,
467
- id: "data-validation.command.removeRule",
468
- handler(accessor, params) {
469
- accessor.get(ILogService).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!");
470
- if (!params) return false;
471
- const { unitId, subUnitId, ruleId } = params;
472
- const commandService = accessor.get(ICommandService);
473
- const undoRedoService = accessor.get(IUndoRedoService);
474
- const dataValidationModel = accessor.get(DataValidationModel);
475
- const redoMutations = [{
476
- id: RemoveDataValidationMutation.id,
477
- params
478
- }];
479
- const undoMutations = [{
480
- id: AddDataValidationMutation.id,
481
- params: {
482
- unitId,
483
- subUnitId,
484
- rule: { ...dataValidationModel.getRuleById(unitId, subUnitId, ruleId) },
485
- index: dataValidationModel.getRuleIndex(unitId, subUnitId, ruleId)
486
- }
487
- }];
488
- undoRedoService.pushUndoRedo({
489
- undoMutations,
490
- redoMutations,
491
- unitID: params.unitId
492
- });
493
- commandService.executeCommand(RemoveDataValidationMutation.id, params);
494
- return true;
495
- }
496
- };
497
- /**
498
- * @deprecated `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!
499
- */
500
- const UpdateDataValidationOptionsCommand = {
501
- type: CommandType.COMMAND,
502
- id: "data-validation.command.updateDataValidationSetting",
503
- handler(accessor, params) {
504
- accessor.get(ILogService).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!");
505
- if (!params) return false;
506
- const commandService = accessor.get(ICommandService);
507
- const redoUndoService = accessor.get(IUndoRedoService);
508
- const dataValidationModel = accessor.get(DataValidationModel);
509
- const { unitId, subUnitId, ruleId, options } = params;
510
- const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
511
- if (!rule) return false;
512
- const mutationParams = {
513
- unitId,
514
- subUnitId,
515
- ruleId,
516
- payload: {
517
- type: 2,
518
- payload: options
519
- }
520
- };
521
- const redoMutations = [{
522
- id: UpdateDataValidationMutation.id,
523
- params: mutationParams
524
- }];
525
- const undoMutationParams = {
526
- unitId,
527
- subUnitId,
528
- ruleId,
529
- payload: {
530
- type: 2,
531
- payload: getRuleOptions(rule)
532
- }
533
- };
534
- const undoMutations = [{
535
- id: UpdateDataValidationMutation.id,
536
- params: undoMutationParams
537
- }];
538
- redoUndoService.pushUndoRedo({
539
- unitID: unitId,
540
- redoMutations,
541
- undoMutations
542
- });
543
- commandService.executeCommand(UpdateDataValidationMutation.id, mutationParams);
544
- return true;
545
- }
546
- };
547
- /**
548
- * @deprecated `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!
549
- */
550
- const UpdateDataValidationSettingCommand = {
551
- type: CommandType.COMMAND,
552
- id: "data-validation.command.updateDataValidationOptions",
553
- handler(accessor, params) {
554
- accessor.get(ILogService).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!");
555
- if (!params) return false;
556
- const commandService = accessor.get(ICommandService);
557
- const redoUndoService = accessor.get(IUndoRedoService);
558
- const dataValidationModel = accessor.get(DataValidationModel);
559
- const dataValidatorRegistryService = accessor.get(DataValidatorRegistryService);
560
- const { unitId, subUnitId, ruleId, setting } = params;
561
- const validator = dataValidatorRegistryService.getValidatorItem(setting.type);
562
- if (!validator) return false;
563
- const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
564
- if (!rule) return false;
565
- const newRule = {
566
- ...rule,
567
- ...setting
568
- };
569
- if (!validator.validatorFormula(newRule, unitId, subUnitId).success) return false;
570
- const mutationParams = {
571
- unitId,
572
- subUnitId,
573
- ruleId,
574
- payload: {
575
- type: 0,
576
- payload: {
577
- ...setting,
578
- ...validator.normalizeFormula(newRule, unitId, subUnitId)
579
- }
580
- }
581
- };
582
- const redoMutations = [{
583
- id: UpdateDataValidationMutation.id,
584
- params: mutationParams
585
- }];
586
- const undoMutationParams = {
587
- unitId,
588
- subUnitId,
589
- ruleId,
590
- payload: {
591
- type: 0,
592
- payload: getRuleSetting(rule)
593
- }
594
- };
595
- const undoMutations = [{
596
- id: UpdateDataValidationMutation.id,
597
- params: undoMutationParams
598
- }];
599
- redoUndoService.pushUndoRedo({
600
- unitID: unitId,
601
- redoMutations,
602
- undoMutations
603
- });
604
- commandService.executeCommand(UpdateDataValidationMutation.id, mutationParams);
605
- return true;
606
- }
607
- };
608
- /**
609
- * @deprecated `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!
610
- */
611
- const RemoveAllDataValidationCommand = {
612
- type: CommandType.COMMAND,
613
- id: "data-validation.command.removeAll",
614
- handler(accessor, params) {
615
- accessor.get(ILogService).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!");
616
- if (!params) return false;
617
- const { unitId, subUnitId } = params;
618
- const commandService = accessor.get(ICommandService);
619
- const dataValidationModel = accessor.get(DataValidationModel);
620
- const undoRedoService = accessor.get(IUndoRedoService);
621
- const currentRules = [...dataValidationModel.getRules(unitId, subUnitId)];
622
- const redoParams = {
623
- unitId,
624
- subUnitId,
625
- ruleId: currentRules.map((rule) => rule.uid)
626
- };
627
- const redoMutations = [{
628
- id: RemoveDataValidationMutation.id,
629
- params: redoParams
630
- }];
631
- const undoMutations = [{
632
- id: AddDataValidationMutation.id,
633
- params: {
634
- unitId,
635
- subUnitId,
636
- rule: currentRules
637
- }
638
- }];
639
- undoRedoService.pushUndoRedo({
640
- redoMutations,
641
- undoMutations,
642
- unitID: unitId
643
- });
644
- commandService.executeCommand(RemoveDataValidationMutation.id, redoParams);
645
- return true;
646
- }
647
- };
648
-
649
- //#endregion
650
- //#region src/config/config.ts
651
- /**
652
- * Copyright 2023-present DreamNum Co., Ltd.
653
- *
654
- * Licensed under the Apache License, Version 2.0 (the "License");
655
- * you may not use this file except in compliance with the License.
656
- * You may obtain a copy of the License at
657
- *
658
- * http://www.apache.org/licenses/LICENSE-2.0
659
- *
660
- * Unless required by applicable law or agreed to in writing, software
661
- * distributed under the License is distributed on an "AS IS" BASIS,
662
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
663
- * See the License for the specific language governing permissions and
664
- * limitations under the License.
665
- */
666
- const DATA_VALIDATION_PLUGIN_CONFIG_KEY = "data-validation.config";
667
- const configSymbol = Symbol(DATA_VALIDATION_PLUGIN_CONFIG_KEY);
668
- const defaultPluginConfig = {};
669
-
670
441
  //#endregion
671
442
  //#region src/plugin.ts
672
443
  let UniverDataValidationPlugin = class UniverDataValidationPlugin extends Plugin {
@@ -686,11 +457,6 @@ let UniverDataValidationPlugin = class UniverDataValidationPlugin extends Plugin
686
457
  [DataValidationResourceController]
687
458
  ].forEach((d) => this._injector.add(d));
688
459
  [
689
- AddDataValidationCommand,
690
- RemoveAllDataValidationCommand,
691
- UpdateDataValidationOptionsCommand,
692
- UpdateDataValidationSettingCommand,
693
- RemoveDataValidationCommand,
694
460
  AddDataValidationMutation,
695
461
  UpdateDataValidationMutation,
696
462
  RemoveDataValidationMutation
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDataValidation={},e.UniverCore,e.rxjs))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function r(e){return{type:e.type,operator:e.operator,formula1:e.formula1,formula2:e.formula2,allowBlank:e.allowBlank}}function i(e){return{error:e.error,errorStyle:e.errorStyle,errorTitle:e.errorTitle,imeMode:e.imeMode,prompt:e.prompt,promptTitle:e.promptTitle,showDropDown:e.showDropDown,showErrorMessage:e.showErrorMessage,showInputMessage:e.showInputMessage,renderMode:e.renderMode,bizInfo:e.bizInfo}}let a=function(e){return e[e.SETTING=0]=`SETTING`,e[e.RANGE=1]=`RANGE`,e[e.OPTIONS=2]=`OPTIONS`,e[e.ALL=3]=`ALL`,e}({});function o(e){"@babel/helpers - typeof";return o=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},o(e)}function s(e,t){if(o(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(o(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function c(e){var t=s(e,`string`);return o(t)==`symbol`?t:t+``}function l(e,t,n){return(t=c(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){return function(n,r){t(n,r,e)}}function d(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let f=class extends t.Disposable{constructor(e){super(),this._logService=e,l(this,`_model`,new Map),l(this,`_ruleChange$`,new n.Subject),l(this,`ruleChange$`,this._ruleChange$.asObservable()),l(this,`ruleChangeDebounce$`,this.ruleChange$.pipe((0,n.debounceTime)(20))),this.disposeWithMe({dispose:()=>{this._ruleChange$.complete()}})}_ensureMap(e,t){this._model.has(e)||this._model.set(e,new Map);let n=this._model.get(e);if(n.has(t))return n.get(t);let r={map:new Map,list:[]};return n.set(t,r),r}_addSubUnitRule(e,t,n){let{map:r,list:i}=e,a=(Array.isArray(t)?t:[t]).filter(e=>!r.has(e.uid));typeof n==`number`&&n<i.length?i.splice(n,0,...a):i.push(...a),a.forEach(e=>{r.set(e.uid,e)})}_removeSubUnitRule(e,t){let{map:n,list:r}=e,i=r.findIndex(e=>e.uid===t);i>-1&&(r.splice(i,1),n.delete(t))}_updateSubUnitRule(e,t,n){let{map:a,list:o}=e,s=a.get(t),c=o.findIndex(e=>t===e.uid);if(!s)throw Error(`Data validation rule is not found, ruleId: ${t}.`);let l={...s};switch(n.type){case 1:l.ranges=n.payload;break;case 0:Object.assign(l,r(n.payload));break;case 2:Object.assign(l,i(n.payload));break;case 3:Object.assign(l,n.payload);break;default:break}return o[c]=l,a.set(t,l),l}_addRuleSideEffect(e,t,n,r){if(!this._ensureMap(e,t).map.get(n.uid))return{rule:n,type:`add`,unitId:e,subUnitId:t,source:r}}addRule(e,t,n,r,i){try{let a=this._ensureMap(e,t),o=(Array.isArray(n)?n:[n]).map(n=>this._addRuleSideEffect(e,t,n,r));this._addSubUnitRule(a,n,i),o.forEach(e=>{e&&this._ruleChange$.next(e)})}catch(e){this._logService.error(e)}}updateRule(e,n,r,i,a){try{let o=this._ensureMap(e,n),s=t.Tools.deepClone(o.map.get(r));if(!s)throw Error(`Data validation rule is not found, ruleId: ${r}.`);let c=this._updateSubUnitRule(o,r,i);this._ruleChange$.next({rule:c,type:`update`,unitId:e,subUnitId:n,source:a,updatePayload:i,oldRule:s})}catch(e){this._logService.error(e)}}removeRule(e,t,n,r){try{let i=this._ensureMap(e,t),a=i.map.get(n);a&&(this._removeSubUnitRule(i,n),this._ruleChange$.next({rule:a,type:`remove`,unitId:e,subUnitId:t,source:r}))}catch(e){this._logService.error(e)}}getRuleById(e,t,n){return this._ensureMap(e,t).map.get(n)}getRuleIndex(e,t,n){return this._ensureMap(e,t).list.findIndex(e=>e.uid===n)}getRules(e,t){return[...this._ensureMap(e,t).list]}getUnitRules(e){let t=this._model.get(e);if(!t)return[];let n=[];return t.forEach((e,t)=>{n.push([t,e.list])}),n}deleteUnitRules(e){this._model.delete(e)}getSubUnitIds(e){var t,n;return Array.from((t=(n=this._model.get(e))==null?void 0:n.keys())==null?[]:t)}getAll(){return Array.from(this._model.keys()).map(e=>[e,this.getUnitRules(e)])}};f=d([u(0,t.ILogService)],f);let p={type:t.CommandType.MUTATION,id:`data-validation.mutation.addRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,rule:i,index:a,source:o=`command`}=t;return e.get(f).addRule(n,r,i,o,a),!0}},m={type:t.CommandType.MUTATION,id:`data-validation.mutation.removeRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,ruleId:i,source:a=`command`}=t,o=e.get(f);return Array.isArray(i)?i.forEach(e=>{o.removeRule(n,r,e,a)}):o.removeRule(n,r,i,a),!0}},h={type:t.CommandType.MUTATION,id:`data-validation.mutation.updateRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,ruleId:i,payload:a,source:o=`command`}=t;return e.get(f).updateRule(n,r,i,a,o),!0}},g=class extends t.Disposable{constructor(e,t,n){super(),this._resourceManagerService=e,this._univerInstanceService=t,this._dataValidationModel=n,this._initSnapshot()}_initSnapshot(){let e=e=>{let t=this._dataValidationModel.getUnitRules(e),n={};return t?(t.forEach(([e,t])=>{n[e]=t}),JSON.stringify(n)):``},n=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_DATA_VALIDATION_PLUGIN`,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:t=>e(t),parseJson:e=>n(e),onUnLoad:e=>{this._dataValidationModel.deleteUnitRules(e)},onLoad:(e,t)=>{Object.keys(t).forEach(n=>{t[n].forEach(t=>{this._dataValidationModel.addRule(e,n,t,`patched`)})})}}))}};g=d([u(0,t.IResourceManagerService),u(1,t.IUniverInstanceService),u(2,(0,t.Inject)(f))],g);var _=`@univerjs/data-validation`,v=`1.0.0-insiders.20260728-e98f416`;let y=function(e){return e.SHEET=`sheet`,e}({});var b=class{constructor(){l(this,`_validatorByScopes`,new Map),l(this,`_validatorMap`,new Map),l(this,`_validatorsChange$`,new n.BehaviorSubject(void 0)),l(this,`validatorsChange$`,this._validatorsChange$.asObservable())}_addValidatorToScope(e,t){this._validatorByScopes.has(t)||this._validatorByScopes.set(t,[]);let n=this._validatorByScopes.get(t);if(n.findIndex(t=>t.id===e.id)>-1)throw Error(`Validator item with the same id ${e.id} has already been added!`);n.push(e)}_removeValidatorFromScope(e,t){let n=this._validatorByScopes.get(t);if(!n)return;let r=n.findIndex(t=>t.id===e.id);r>-1&&n.splice(r,1)}register(e){return this._validatorMap.set(e.id,e),Array.isArray(e.scopes)?e.scopes.forEach(t=>{this._addValidatorToScope(e,t)}):this._addValidatorToScope(e,e.scopes),this._validatorsChange$.next(),(0,t.toDisposable)(()=>{this._validatorMap.delete(e.id),Array.isArray(e.scopes)?e.scopes.forEach(t=>{this._removeValidatorFromScope(e,t)}):this._removeValidatorFromScope(e,e.scopes),this._validatorsChange$.next()})}getValidatorItem(e){return this._validatorMap.get(e)}getValidatorsByScope(e){return this._validatorByScopes.get(e)}};let x={type:t.CommandType.COMMAND,id:`data-validation.command.addRule`,async handler(e,n){if(e.get(t.ILogService).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!n)return!1;let{rule:r,unitId:i,subUnitId:a}=n,o=e.get(t.ICommandService),s=e.get(t.IUndoRedoService),c={...n,rule:{...n.rule,ranges:[n.rule.range]}},l=[{id:p.id,params:c}],u=[{id:m.id,params:{unitId:i,subUnitId:a,ruleId:r.uid}}];return s.pushUndoRedo({unitID:i,redoMutations:l,undoMutations:u}),await o.executeCommand(p.id,c),!0}},S={type:t.CommandType.COMMAND,id:`data-validation.command.removeRule`,handler(e,n){if(e.get(t.ILogService).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!n)return!1;let{unitId:r,subUnitId:i,ruleId:a}=n,o=e.get(t.ICommandService),s=e.get(t.IUndoRedoService),c=e.get(f),l=[{id:m.id,params:n}],u=[{id:p.id,params:{unitId:r,subUnitId:i,rule:{...c.getRuleById(r,i,a)},index:c.getRuleIndex(r,i,a)}}];return s.pushUndoRedo({undoMutations:u,redoMutations:l,unitID:n.unitId}),o.executeCommand(m.id,n),!0}},C={type:t.CommandType.COMMAND,id:`data-validation.command.updateDataValidationSetting`,handler(e,n){if(e.get(t.ILogService).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"),!n)return!1;let r=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(f),{unitId:s,subUnitId:c,ruleId:l,options:u}=n,d=o.getRuleById(s,c,l);if(!d)return!1;let p={unitId:s,subUnitId:c,ruleId:l,payload:{type:2,payload:u}},m=[{id:h.id,params:p}],g={unitId:s,subUnitId:c,ruleId:l,payload:{type:2,payload:i(d)}},_=[{id:h.id,params:g}];return a.pushUndoRedo({unitID:s,redoMutations:m,undoMutations:_}),r.executeCommand(h.id,p),!0}},w={type:t.CommandType.COMMAND,id:`data-validation.command.updateDataValidationOptions`,handler(e,n){if(e.get(t.ILogService).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"),!n)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(f),s=e.get(b),{unitId:c,subUnitId:l,ruleId:u,setting:d}=n,p=s.getValidatorItem(d.type);if(!p)return!1;let m=o.getRuleById(c,l,u);if(!m)return!1;let g={...m,...d};if(!p.validatorFormula(g,c,l).success)return!1;let _={unitId:c,subUnitId:l,ruleId:u,payload:{type:0,payload:{...d,...p.normalizeFormula(g,c,l)}}},v=[{id:h.id,params:_}],y={unitId:c,subUnitId:l,ruleId:u,payload:{type:0,payload:r(m)}},x=[{id:h.id,params:y}];return a.pushUndoRedo({unitID:c,redoMutations:v,undoMutations:x}),i.executeCommand(h.id,_),!0}},T={type:t.CommandType.COMMAND,id:`data-validation.command.removeAll`,handler(e,n){if(e.get(t.ILogService).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!n)return!1;let{unitId:r,subUnitId:i}=n,a=e.get(t.ICommandService),o=e.get(f),s=e.get(t.IUndoRedoService),c=[...o.getRules(r,i)],l={unitId:r,subUnitId:i,ruleId:c.map(e=>e.uid)},u=[{id:m.id,params:l}],d=[{id:p.id,params:{unitId:r,subUnitId:i,rule:c}}];return s.pushUndoRedo({redoMutations:u,undoMutations:d,unitID:r}),a.executeCommand(m.id,l),!0}},E={},D=class extends t.Plugin{constructor(e=E,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{...a}=(0,t.merge)({},E,this._config);this._configService.setConfig(`data-validation.config`,a)}onStarting(){[[f],[b],[g]].forEach(e=>this._injector.add(e)),[x,T,C,w,S,p,h,m].forEach(e=>{this._commandService.registerCommand(e)})}onReady(){this._injector.get(g)}};l(D,`pluginName`,`UNIVER_DATA_VALIDATION_PLUGIN`),l(D,`packageName`,_),l(D,`version`,v),l(D,`type`,t.UniverInstanceType.UNIVER_SHEET),D=d([u(1,(0,t.Inject)(t.Injector)),u(2,t.ICommandService),u(3,t.IConfigService)],D);let O=[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.NOT_BETWEEN];t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL;let k={[t.DataValidationOperator.BETWEEN]:`data-validation.ruleName.between`,[t.DataValidationOperator.EQUAL]:`data-validation.ruleName.equal`,[t.DataValidationOperator.GREATER_THAN]:`data-validation.ruleName.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`data-validation.ruleName.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`data-validation.ruleName.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`data-validation.ruleName.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`data-validation.ruleName.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`data-validation.ruleName.notEqual`,NONE:`data-validation.ruleName.legal`},A={[t.DataValidationOperator.BETWEEN]:`data-validation.errorMsg.between`,[t.DataValidationOperator.EQUAL]:`data-validation.errorMsg.equal`,[t.DataValidationOperator.GREATER_THAN]:`data-validation.errorMsg.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`data-validation.errorMsg.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`data-validation.errorMsg.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`data-validation.errorMsg.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`data-validation.errorMsg.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`data-validation.errorMsg.notEqual`,NONE:`data-validation.errorMsg.legal`},j=`{FORMULA1}`,M=`{FORMULA2}`,N=`{TYPE}`,P={[t.DataValidationOperator.BETWEEN]:`data-validation.operators.between`,[t.DataValidationOperator.EQUAL]:`data-validation.operators.equal`,[t.DataValidationOperator.GREATER_THAN]:`data-validation.operators.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`data-validation.operators.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`data-validation.operators.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`data-validation.operators.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`data-validation.operators.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`data-validation.operators.notEqual`},F=function(e){return e.DATE=`date`,e.TIME=`time`,e.DATETIME=`datetime`,e.LIST=`list`,e.MULTIPLE_LIST=`multipleList`,e.COLOR=`color`,e.CASCADE=`cascade`,e}({}),I=class{constructor(e,t){this.localeService=e,this.injector=t,l(this,`offsetFormulaByRange`,!0),l(this,`formulaInput`,void 0),l(this,`canvasRender`,null),l(this,`dropdownType`,void 0),l(this,`optionsInput`,void 0),l(this,`skipDefaultFontRender`,void 0)}get operatorNames(){return this.operators.map(e=>this.localeService.t(P[e]))}get titleStr(){return this.localeService.t(this.title)}generateRuleName(e){var t,n;if(!e.operator)return this.localeService.t(k.NONE).replace(N,this.titleStr);let r=this.localeService.t(k[e.operator]).replace(j,(t=e.formula1)==null?``:t).replace(M,(n=e.formula2)==null?``:n);return`${this.titleStr} ${r}`}generateRuleErrorMessage(e,t){var n,r;return e.operator?`${this.localeService.t(A[e.operator]).replace(j,(n=e.formula1)==null?``:n).replace(M,(r=e.formula2)==null?``:r)}`:this.localeService.t(A.NONE).replace(N,this.titleStr)}getExtraStyle(e,t,n,r,i){}getRuleFinalError(e,t){return e.showErrorMessage&&e.error?e.error:this.generateRuleErrorMessage(e,t)}isEmptyCellValue(e){return e===``||e==null}normalizeFormula(e,t,n){return{formula1:e.formula1,formula2:e.formula2}}async isValidType(e,t,n){return!0}transform(e,t,n){return e}async validatorIsEqual(e,t,n){let{formula1:r}=t,{value:i}=e;return Number.isNaN(r)?!0:i===r}async validatorIsNotEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value!==r}async validatorIsBetween(e,t,n){let{formula1:r,formula2:i}=t;if(Number.isNaN(r)||Number.isNaN(i))return!0;let a=Math.min(r,i),o=Math.max(r,i);return e.value>=a&&e.value<=o}async validatorIsNotBetween(e,t,n){let{formula1:r,formula2:i}=t;if(Number.isNaN(r)||Number.isNaN(i))return!0;let a=Math.min(r,i),o=Math.max(r,i);return e.value<a||e.value>o}async validatorIsGreaterThan(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value>r}async validatorIsGreaterThanOrEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value>=r}async validatorIsLessThan(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value<r}async validatorIsLessThanOrEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value<=r}async validator(e,n){let{value:r,unitId:i,subUnitId:a}=e,o=this.isEmptyCellValue(r),{allowBlank:s=!0,operator:c}=n;if(o)return s;let l=await this.parseFormula(n,i,a,e.row,e.column);if(!l.isFormulaValid||!await this.isValidType(e,l,n))return!1;if(!c)return!0;let u=this.transform(e,l,n);switch(c){case t.DataValidationOperator.BETWEEN:return this.validatorIsBetween(u,l,n);case t.DataValidationOperator.EQUAL:return this.validatorIsEqual(u,l,n);case t.DataValidationOperator.GREATER_THAN:return this.validatorIsGreaterThan(u,l,n);case t.DataValidationOperator.GREATER_THAN_OR_EQUAL:return this.validatorIsGreaterThanOrEqual(u,l,n);case t.DataValidationOperator.LESS_THAN:return this.validatorIsLessThan(u,l,n);case t.DataValidationOperator.LESS_THAN_OR_EQUAL:return this.validatorIsLessThanOrEqual(u,l,n);case t.DataValidationOperator.NOT_BETWEEN:return this.validatorIsNotBetween(u,l,n);case t.DataValidationOperator.NOT_EQUAL:return this.validatorIsNotEqual(u,l,n);default:throw Error(`Unknown operator.`)}}};I=d([u(0,(0,t.Inject)(t.LocaleService)),u(1,(0,t.Inject)(t.Injector))],I),e.AddDataValidationMutation=p,Object.defineProperty(e,"BaseDataValidator",{enumerable:!0,get:function(){return I}}),Object.defineProperty(e,"DataValidationModel",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"DataValidationResourceController",{enumerable:!0,get:function(){return g}}),e.DataValidatorDropdownType=F,e.DataValidatorRegistryScope=y,e.DataValidatorRegistryService=b,e.FORMULA1=j,e.FORMULA2=M,e.RemoveDataValidationMutation=m,e.TWO_FORMULA_OPERATOR_COUNT=O,e.TYPE=N,Object.defineProperty(e,"UniverDataValidationPlugin",{enumerable:!0,get:function(){return D}}),e.UpdateDataValidationMutation=h,e.UpdateRuleType=a,e.getRuleOptions=i,e.getRuleSetting=r});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDataValidation={},e.UniverCore,e.rxjs))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function r(e){return{type:e.type,operator:e.operator,formula1:e.formula1,formula2:e.formula2,allowBlank:e.allowBlank}}function i(e){return{error:e.error,errorStyle:e.errorStyle,errorTitle:e.errorTitle,imeMode:e.imeMode,prompt:e.prompt,promptTitle:e.promptTitle,showDropDown:e.showDropDown,showErrorMessage:e.showErrorMessage,showInputMessage:e.showInputMessage,renderMode:e.renderMode,bizInfo:e.bizInfo}}let a=function(e){return e[e.SETTING=0]=`SETTING`,e[e.RANGE=1]=`RANGE`,e[e.OPTIONS=2]=`OPTIONS`,e[e.ALL=3]=`ALL`,e}({});function o(e){"@babel/helpers - typeof";return o=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},o(e)}function s(e,t){if(o(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(o(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function c(e){var t=s(e,`string`);return o(t)==`symbol`?t:t+``}function l(e,t,n){return(t=c(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){return function(n,r){t(n,r,e)}}function d(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let f=class extends t.Disposable{constructor(e){super(),this._logService=e,l(this,`_model`,new Map),l(this,`_ruleChange$`,new n.Subject),l(this,`ruleChange$`,this._ruleChange$.asObservable()),l(this,`ruleChangeDebounce$`,this.ruleChange$.pipe((0,n.debounceTime)(20))),this.disposeWithMe({dispose:()=>{this._ruleChange$.complete()}})}_ensureMap(e,t){this._model.has(e)||this._model.set(e,new Map);let n=this._model.get(e);if(n.has(t))return n.get(t);let r={map:new Map,list:[]};return n.set(t,r),r}_addSubUnitRule(e,t,n){let{map:r,list:i}=e,a=(Array.isArray(t)?t:[t]).filter(e=>!r.has(e.uid));typeof n==`number`&&n<i.length?i.splice(n,0,...a):i.push(...a),a.forEach(e=>{r.set(e.uid,e)})}_removeSubUnitRule(e,t){let{map:n,list:r}=e,i=r.findIndex(e=>e.uid===t);i>-1&&(r.splice(i,1),n.delete(t))}_updateSubUnitRule(e,t,n){let{map:a,list:o}=e,s=a.get(t),c=o.findIndex(e=>t===e.uid);if(!s)throw Error(`Data validation rule is not found, ruleId: ${t}.`);let l={...s};switch(n.type){case 1:l.ranges=n.payload;break;case 0:Object.assign(l,r(n.payload));break;case 2:Object.assign(l,i(n.payload));break;case 3:Object.assign(l,n.payload);break;default:break}return o[c]=l,a.set(t,l),l}_addRuleSideEffect(e,t,n,r){if(!this._ensureMap(e,t).map.get(n.uid))return{rule:n,type:`add`,unitId:e,subUnitId:t,source:r}}addRule(e,t,n,r,i){try{let a=this._ensureMap(e,t),o=(Array.isArray(n)?n:[n]).map(n=>this._addRuleSideEffect(e,t,n,r));this._addSubUnitRule(a,n,i),o.forEach(e=>{e&&this._ruleChange$.next(e)})}catch(e){this._logService.error(e)}}updateRule(e,n,r,i,a){try{let o=this._ensureMap(e,n),s=t.Tools.deepClone(o.map.get(r));if(!s)throw Error(`Data validation rule is not found, ruleId: ${r}.`);let c=this._updateSubUnitRule(o,r,i);this._ruleChange$.next({rule:c,type:`update`,unitId:e,subUnitId:n,source:a,updatePayload:i,oldRule:s})}catch(e){this._logService.error(e)}}removeRule(e,t,n,r){try{let i=this._ensureMap(e,t),a=i.map.get(n);a&&(this._removeSubUnitRule(i,n),this._ruleChange$.next({rule:a,type:`remove`,unitId:e,subUnitId:t,source:r}))}catch(e){this._logService.error(e)}}getRuleById(e,t,n){return this._ensureMap(e,t).map.get(n)}getRuleIndex(e,t,n){return this._ensureMap(e,t).list.findIndex(e=>e.uid===n)}getRules(e,t){return[...this._ensureMap(e,t).list]}getUnitRules(e){let t=this._model.get(e);if(!t)return[];let n=[];return t.forEach((e,t)=>{n.push([t,e.list])}),n}deleteUnitRules(e){this._model.delete(e)}getSubUnitIds(e){var t,n;return Array.from((t=(n=this._model.get(e))==null?void 0:n.keys())==null?[]:t)}getAll(){return Array.from(this._model.keys()).map(e=>[e,this.getUnitRules(e)])}};f=d([u(0,t.ILogService)],f);let p={type:t.CommandType.MUTATION,id:`data-validation.mutation.addRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,rule:i,index:a,source:o=`command`}=t;return e.get(f).addRule(n,r,i,o,a),!0}},m={type:t.CommandType.MUTATION,id:`data-validation.mutation.removeRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,ruleId:i,source:a=`command`}=t,o=e.get(f);return Array.isArray(i)?i.forEach(e=>{o.removeRule(n,r,e,a)}):o.removeRule(n,r,i,a),!0}},h={type:t.CommandType.MUTATION,id:`data-validation.mutation.updateRule`,handler(e,t){if(!t)return!1;let{unitId:n,subUnitId:r,ruleId:i,payload:a,source:o=`command`}=t;return e.get(f).updateRule(n,r,i,a,o),!0}},g=class extends t.Disposable{constructor(e,t,n){super(),this._resourceManagerService=e,this._univerInstanceService=t,this._dataValidationModel=n,this._initSnapshot()}_initSnapshot(){let e=e=>{let t=this._dataValidationModel.getUnitRules(e),n={};return t?(t.forEach(([e,t])=>{n[e]=t}),JSON.stringify(n)):``},n=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:`SHEET_DATA_VALIDATION_PLUGIN`,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:t=>e(t),parseJson:e=>n(e),onUnLoad:e=>{this._dataValidationModel.deleteUnitRules(e)},onLoad:(e,t)=>{Object.keys(t).forEach(n=>{t[n].forEach(t=>{this._dataValidationModel.addRule(e,n,t,`patched`)})})}}))}};g=d([u(0,t.IResourceManagerService),u(1,t.IUniverInstanceService),u(2,(0,t.Inject)(f))],g);var _=`@univerjs/data-validation`,v=`1.0.0-insiders.20260729-84ae2bd`;let y={},b=function(e){return e.SHEET=`sheet`,e}({});var x=class{constructor(){l(this,`_validatorByScopes`,new Map),l(this,`_validatorMap`,new Map),l(this,`_validatorsChange$`,new n.BehaviorSubject(void 0)),l(this,`validatorsChange$`,this._validatorsChange$.asObservable())}_addValidatorToScope(e,t){this._validatorByScopes.has(t)||this._validatorByScopes.set(t,[]);let n=this._validatorByScopes.get(t);if(n.findIndex(t=>t.id===e.id)>-1)throw Error(`Validator item with the same id ${e.id} has already been added!`);n.push(e)}_removeValidatorFromScope(e,t){let n=this._validatorByScopes.get(t);if(!n)return;let r=n.findIndex(t=>t.id===e.id);r>-1&&n.splice(r,1)}register(e){return this._validatorMap.set(e.id,e),Array.isArray(e.scopes)?e.scopes.forEach(t=>{this._addValidatorToScope(e,t)}):this._addValidatorToScope(e,e.scopes),this._validatorsChange$.next(),(0,t.toDisposable)(()=>{this._validatorMap.delete(e.id),Array.isArray(e.scopes)?e.scopes.forEach(t=>{this._removeValidatorFromScope(e,t)}):this._removeValidatorFromScope(e,e.scopes),this._validatorsChange$.next()})}getValidatorItem(e){return this._validatorMap.get(e)}getValidatorsByScope(e){return this._validatorByScopes.get(e)}};let S=class extends t.Plugin{constructor(e=y,n,r,i){super(),this._config=e,this._injector=n,this._commandService=r,this._configService=i;let{...a}=(0,t.merge)({},y,this._config);this._configService.setConfig(`data-validation.config`,a)}onStarting(){[[f],[x],[g]].forEach(e=>this._injector.add(e)),[p,h,m].forEach(e=>{this._commandService.registerCommand(e)})}onReady(){this._injector.get(g)}};l(S,`pluginName`,`UNIVER_DATA_VALIDATION_PLUGIN`),l(S,`packageName`,_),l(S,`version`,v),l(S,`type`,t.UniverInstanceType.UNIVER_SHEET),S=d([u(1,(0,t.Inject)(t.Injector)),u(2,t.ICommandService),u(3,t.IConfigService)],S);let C=[t.DataValidationOperator.BETWEEN,t.DataValidationOperator.NOT_BETWEEN];t.DataValidationOperator.BETWEEN,t.DataValidationOperator.EQUAL,t.DataValidationOperator.GREATER_THAN,t.DataValidationOperator.GREATER_THAN_OR_EQUAL,t.DataValidationOperator.LESS_THAN,t.DataValidationOperator.LESS_THAN_OR_EQUAL,t.DataValidationOperator.NOT_BETWEEN,t.DataValidationOperator.NOT_EQUAL;let w={[t.DataValidationOperator.BETWEEN]:`data-validation.ruleName.between`,[t.DataValidationOperator.EQUAL]:`data-validation.ruleName.equal`,[t.DataValidationOperator.GREATER_THAN]:`data-validation.ruleName.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`data-validation.ruleName.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`data-validation.ruleName.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`data-validation.ruleName.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`data-validation.ruleName.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`data-validation.ruleName.notEqual`,NONE:`data-validation.ruleName.legal`},T={[t.DataValidationOperator.BETWEEN]:`data-validation.errorMsg.between`,[t.DataValidationOperator.EQUAL]:`data-validation.errorMsg.equal`,[t.DataValidationOperator.GREATER_THAN]:`data-validation.errorMsg.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`data-validation.errorMsg.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`data-validation.errorMsg.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`data-validation.errorMsg.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`data-validation.errorMsg.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`data-validation.errorMsg.notEqual`,NONE:`data-validation.errorMsg.legal`},E=`{FORMULA1}`,D=`{FORMULA2}`,O=`{TYPE}`,k={[t.DataValidationOperator.BETWEEN]:`data-validation.operators.between`,[t.DataValidationOperator.EQUAL]:`data-validation.operators.equal`,[t.DataValidationOperator.GREATER_THAN]:`data-validation.operators.greaterThan`,[t.DataValidationOperator.GREATER_THAN_OR_EQUAL]:`data-validation.operators.greaterThanOrEqual`,[t.DataValidationOperator.LESS_THAN]:`data-validation.operators.lessThan`,[t.DataValidationOperator.LESS_THAN_OR_EQUAL]:`data-validation.operators.lessThanOrEqual`,[t.DataValidationOperator.NOT_BETWEEN]:`data-validation.operators.notBetween`,[t.DataValidationOperator.NOT_EQUAL]:`data-validation.operators.notEqual`},A=function(e){return e.DATE=`date`,e.TIME=`time`,e.DATETIME=`datetime`,e.LIST=`list`,e.MULTIPLE_LIST=`multipleList`,e.COLOR=`color`,e.CASCADE=`cascade`,e}({}),j=class{constructor(e,t){this.localeService=e,this.injector=t,l(this,`offsetFormulaByRange`,!0),l(this,`formulaInput`,void 0),l(this,`canvasRender`,null),l(this,`dropdownType`,void 0),l(this,`optionsInput`,void 0),l(this,`skipDefaultFontRender`,void 0)}get operatorNames(){return this.operators.map(e=>this.localeService.t(k[e]))}get titleStr(){return this.localeService.t(this.title)}generateRuleName(e){var t,n;if(!e.operator)return this.localeService.t(w.NONE).replace(O,this.titleStr);let r=this.localeService.t(w[e.operator]).replace(E,(t=e.formula1)==null?``:t).replace(D,(n=e.formula2)==null?``:n);return`${this.titleStr} ${r}`}generateRuleErrorMessage(e,t){var n,r;return e.operator?`${this.localeService.t(T[e.operator]).replace(E,(n=e.formula1)==null?``:n).replace(D,(r=e.formula2)==null?``:r)}`:this.localeService.t(T.NONE).replace(O,this.titleStr)}getExtraStyle(e,t,n,r,i){}getRuleFinalError(e,t){return e.showErrorMessage&&e.error?e.error:this.generateRuleErrorMessage(e,t)}isEmptyCellValue(e){return e===``||e==null}normalizeFormula(e,t,n){return{formula1:e.formula1,formula2:e.formula2}}async isValidType(e,t,n){return!0}transform(e,t,n){return e}async validatorIsEqual(e,t,n){let{formula1:r}=t,{value:i}=e;return Number.isNaN(r)?!0:i===r}async validatorIsNotEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value!==r}async validatorIsBetween(e,t,n){let{formula1:r,formula2:i}=t;if(Number.isNaN(r)||Number.isNaN(i))return!0;let a=Math.min(r,i),o=Math.max(r,i);return e.value>=a&&e.value<=o}async validatorIsNotBetween(e,t,n){let{formula1:r,formula2:i}=t;if(Number.isNaN(r)||Number.isNaN(i))return!0;let a=Math.min(r,i),o=Math.max(r,i);return e.value<a||e.value>o}async validatorIsGreaterThan(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value>r}async validatorIsGreaterThanOrEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value>=r}async validatorIsLessThan(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value<r}async validatorIsLessThanOrEqual(e,t,n){let{formula1:r}=t;return Number.isNaN(r)?!0:e.value<=r}async validator(e,n){let{value:r,unitId:i,subUnitId:a}=e,o=this.isEmptyCellValue(r),{allowBlank:s=!0,operator:c}=n;if(o)return s;let l=await this.parseFormula(n,i,a,e.row,e.column);if(!l.isFormulaValid||!await this.isValidType(e,l,n))return!1;if(!c)return!0;let u=this.transform(e,l,n);switch(c){case t.DataValidationOperator.BETWEEN:return this.validatorIsBetween(u,l,n);case t.DataValidationOperator.EQUAL:return this.validatorIsEqual(u,l,n);case t.DataValidationOperator.GREATER_THAN:return this.validatorIsGreaterThan(u,l,n);case t.DataValidationOperator.GREATER_THAN_OR_EQUAL:return this.validatorIsGreaterThanOrEqual(u,l,n);case t.DataValidationOperator.LESS_THAN:return this.validatorIsLessThan(u,l,n);case t.DataValidationOperator.LESS_THAN_OR_EQUAL:return this.validatorIsLessThanOrEqual(u,l,n);case t.DataValidationOperator.NOT_BETWEEN:return this.validatorIsNotBetween(u,l,n);case t.DataValidationOperator.NOT_EQUAL:return this.validatorIsNotEqual(u,l,n);default:throw Error(`Unknown operator.`)}}};j=d([u(0,(0,t.Inject)(t.LocaleService)),u(1,(0,t.Inject)(t.Injector))],j),e.AddDataValidationMutation=p,Object.defineProperty(e,"BaseDataValidator",{enumerable:!0,get:function(){return j}}),Object.defineProperty(e,"DataValidationModel",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"DataValidationResourceController",{enumerable:!0,get:function(){return g}}),e.DataValidatorDropdownType=A,e.DataValidatorRegistryScope=b,e.DataValidatorRegistryService=x,e.FORMULA1=E,e.FORMULA2=D,e.RemoveDataValidationMutation=m,e.TWO_FORMULA_OPERATOR_COUNT=C,e.TYPE=O,Object.defineProperty(e,"UniverDataValidationPlugin",{enumerable:!0,get:function(){return S}}),e.UpdateDataValidationMutation=h,e.UpdateRuleType=a,e.getRuleOptions=i,e.getRuleSetting=r});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/data-validation",
3
- "version": "1.0.0-insiders.20260728-e98f416",
3
+ "version": "1.0.0-insiders.20260729-84ae2bd",
4
4
  "private": false,
5
5
  "description": "Shared data validation models and rule services for Univer.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -57,15 +57,15 @@
57
57
  "rxjs": ">=7.0.0"
58
58
  },
59
59
  "dependencies": {
60
- "@univerjs/core": "1.0.0-insiders.20260728-e98f416"
60
+ "@univerjs/core": "1.0.0-insiders.20260729-84ae2bd"
61
61
  },
62
62
  "devDependencies": {
63
63
  "rxjs": "^7.8.2",
64
64
  "typescript": "^6.0.3",
65
65
  "vitest": "^4.1.10",
66
- "@univerjs/protocol": "1.0.0-insiders.20260728-e98f416",
67
66
  "@univerjs-infra/shared": "1.0.0-alpha.7",
68
- "@univerjs/sheets": "1.0.0-insiders.20260728-e98f416"
67
+ "@univerjs/protocol": "1.0.0-insiders.20260729-84ae2bd",
68
+ "@univerjs/sheets": "1.0.0-insiders.20260729-84ae2bd"
69
69
  },
70
70
  "scripts": {
71
71
  "test": "vitest run",
@@ -1,62 +0,0 @@
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 { ICommand, IDataValidationRule, IDataValidationRuleBase, IDataValidationRuleOptions, IMutationInfo, Injector, IRange } from '@univerjs/core';
17
- import type { IRemoveDataValidationMutationParams } from '../mutations/data-validation.mutation';
18
- interface ISheetCommandSharedParams {
19
- unitId: string;
20
- subUnitId: string;
21
- }
22
- export interface IAddDataValidationCommandParams extends ISheetCommandSharedParams {
23
- rule: Omit<IDataValidationRule, 'ranges'> & {
24
- range: IRange;
25
- };
26
- index?: number;
27
- }
28
- /**
29
- * @deprecated `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!
30
- */
31
- export declare const AddDataValidationCommand: ICommand<IAddDataValidationCommandParams>;
32
- export interface IRemoveDataValidationCommandParams extends ISheetCommandSharedParams {
33
- ruleId: string;
34
- }
35
- export declare const removeDataValidationUndoFactory: (accessor: Injector, redoParams: IRemoveDataValidationMutationParams) => IMutationInfo<object>[];
36
- /**
37
- * @deprecated `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!
38
- */
39
- export declare const RemoveDataValidationCommand: ICommand<IRemoveDataValidationCommandParams>;
40
- export interface IUpdateDataValidationOptionsCommandParams extends ISheetCommandSharedParams {
41
- ruleId: string;
42
- options: IDataValidationRuleOptions;
43
- }
44
- /**
45
- * @deprecated `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!
46
- */
47
- export declare const UpdateDataValidationOptionsCommand: ICommand<IUpdateDataValidationOptionsCommandParams>;
48
- export interface IUpdateDataValidationSettingCommandParams extends ISheetCommandSharedParams {
49
- ruleId: string;
50
- setting: IDataValidationRuleBase;
51
- }
52
- /**
53
- * @deprecated `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!
54
- */
55
- export declare const UpdateDataValidationSettingCommand: ICommand<IUpdateDataValidationSettingCommandParams>;
56
- export interface IRemoveAllDataValidationCommandParams extends ISheetCommandSharedParams {
57
- }
58
- /**
59
- * @deprecated `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!
60
- */
61
- export declare const RemoveAllDataValidationCommand: ICommand<IRemoveAllDataValidationCommandParams>;
62
- export {};