@univerjs/sheets-data-validation-ui 1.0.0-insiders.20260717-1e84621 → 1.0.0-insiders.20260720-e1e8f51

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.
Files changed (88) hide show
  1. package/lib/cjs/index.js +1948 -1721
  2. package/lib/cjs/locale/ar-SA.js +17 -0
  3. package/lib/cjs/locale/ca-ES.js +17 -0
  4. package/lib/cjs/locale/de-DE.js +17 -0
  5. package/lib/cjs/locale/en-US.js +17 -0
  6. package/lib/cjs/locale/es-ES.js +17 -0
  7. package/lib/cjs/locale/fa-IR.js +17 -0
  8. package/lib/cjs/locale/fr-FR.js +17 -0
  9. package/lib/cjs/locale/id-ID.js +17 -0
  10. package/lib/cjs/locale/it-IT.js +17 -0
  11. package/lib/cjs/locale/ja-JP.js +17 -0
  12. package/lib/cjs/locale/ko-KR.js +17 -0
  13. package/lib/cjs/locale/pl-PL.js +17 -0
  14. package/lib/cjs/locale/pt-BR.js +17 -0
  15. package/lib/cjs/locale/ru-RU.js +17 -0
  16. package/lib/cjs/locale/sk-SK.js +17 -0
  17. package/lib/cjs/locale/vi-VN.js +17 -0
  18. package/lib/cjs/locale/zh-CN.js +17 -0
  19. package/lib/cjs/locale/zh-HK.js +17 -0
  20. package/lib/cjs/locale/zh-TW.js +17 -0
  21. package/lib/es/index.js +1953 -1726
  22. package/lib/es/locale/ar-SA.js +17 -0
  23. package/lib/es/locale/ca-ES.js +17 -0
  24. package/lib/es/locale/de-DE.js +17 -0
  25. package/lib/es/locale/en-US.js +17 -0
  26. package/lib/es/locale/es-ES.js +17 -0
  27. package/lib/es/locale/fa-IR.js +17 -0
  28. package/lib/es/locale/fr-FR.js +17 -0
  29. package/lib/es/locale/id-ID.js +17 -0
  30. package/lib/es/locale/it-IT.js +17 -0
  31. package/lib/es/locale/ja-JP.js +17 -0
  32. package/lib/es/locale/ko-KR.js +17 -0
  33. package/lib/es/locale/pl-PL.js +17 -0
  34. package/lib/es/locale/pt-BR.js +17 -0
  35. package/lib/es/locale/ru-RU.js +17 -0
  36. package/lib/es/locale/sk-SK.js +17 -0
  37. package/lib/es/locale/vi-VN.js +17 -0
  38. package/lib/es/locale/zh-CN.js +17 -0
  39. package/lib/es/locale/zh-HK.js +17 -0
  40. package/lib/es/locale/zh-TW.js +17 -0
  41. package/lib/index.css +80 -0
  42. package/lib/index.js +1953 -1726
  43. package/lib/locale/ar-SA.js +17 -0
  44. package/lib/locale/ca-ES.js +17 -0
  45. package/lib/locale/de-DE.js +17 -0
  46. package/lib/locale/en-US.js +17 -0
  47. package/lib/locale/es-ES.js +17 -0
  48. package/lib/locale/fa-IR.js +17 -0
  49. package/lib/locale/fr-FR.js +17 -0
  50. package/lib/locale/id-ID.js +17 -0
  51. package/lib/locale/it-IT.js +17 -0
  52. package/lib/locale/ja-JP.js +17 -0
  53. package/lib/locale/ko-KR.js +17 -0
  54. package/lib/locale/pl-PL.js +17 -0
  55. package/lib/locale/pt-BR.js +17 -0
  56. package/lib/locale/ru-RU.js +17 -0
  57. package/lib/locale/sk-SK.js +17 -0
  58. package/lib/locale/vi-VN.js +17 -0
  59. package/lib/locale/zh-CN.js +17 -0
  60. package/lib/locale/zh-HK.js +17 -0
  61. package/lib/locale/zh-TW.js +17 -0
  62. package/lib/types/commands/commands/data-validation-ui.command.d.ts +15 -2
  63. package/lib/types/controllers/components.controller.d.ts +1 -0
  64. package/lib/types/controllers/ui.controller.d.ts +1 -4
  65. package/lib/types/locale/en-US.d.ts +17 -0
  66. package/lib/types/menu/dv.menu.d.ts +6 -1
  67. package/lib/types/views/components/DropdownPresets.d.ts +18 -0
  68. package/lib/umd/index.js +1 -1
  69. package/lib/umd/locale/ar-SA.js +1 -1
  70. package/lib/umd/locale/ca-ES.js +1 -1
  71. package/lib/umd/locale/de-DE.js +1 -1
  72. package/lib/umd/locale/en-US.js +1 -1
  73. package/lib/umd/locale/es-ES.js +1 -1
  74. package/lib/umd/locale/fa-IR.js +1 -1
  75. package/lib/umd/locale/fr-FR.js +1 -1
  76. package/lib/umd/locale/id-ID.js +1 -1
  77. package/lib/umd/locale/it-IT.js +1 -1
  78. package/lib/umd/locale/ja-JP.js +1 -1
  79. package/lib/umd/locale/ko-KR.js +1 -1
  80. package/lib/umd/locale/pl-PL.js +1 -1
  81. package/lib/umd/locale/pt-BR.js +1 -1
  82. package/lib/umd/locale/ru-RU.js +1 -1
  83. package/lib/umd/locale/sk-SK.js +1 -1
  84. package/lib/umd/locale/vi-VN.js +1 -1
  85. package/lib/umd/locale/zh-CN.js +1 -1
  86. package/lib/umd/locale/zh-HK.js +1 -1
  87. package/lib/umd/locale/zh-TW.js +1 -1
  88. package/package.json +13 -13
package/lib/cjs/index.js CHANGED
@@ -10,10 +10,10 @@ let _univerjs_sheets_numfmt = require("@univerjs/sheets-numfmt");
10
10
  let _univerjs_sheets_ui = require("@univerjs/sheets-ui");
11
11
  let _univerjs_design = require("@univerjs/design");
12
12
  let react = require("react");
13
+ let react_jsx_runtime = require("react/jsx-runtime");
13
14
  let _univerjs_icons = require("@univerjs/icons");
14
15
  let _univerjs_engine_formula = require("@univerjs/engine-formula");
15
16
  let _univerjs_sheets_formula_ui = require("@univerjs/sheets-formula-ui");
16
- let react_jsx_runtime = require("react/jsx-runtime");
17
17
 
18
18
  //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
19
19
  function _typeof(o) {
@@ -676,14 +676,55 @@ const HideDataValidationDropdown = {
676
676
 
677
677
  //#endregion
678
678
  //#region src/commands/commands/data-validation-ui.command.ts
679
+ function createRule(accessor, rule) {
680
+ const defaultRule = (0, _univerjs_sheets_data_validation.createDefaultNewRule)(accessor);
681
+ return {
682
+ ...defaultRule,
683
+ ...rule,
684
+ uid: defaultRule.uid,
685
+ ranges: defaultRule.ranges
686
+ };
687
+ }
688
+ const InsertQuickSheetDataValidationCommand = {
689
+ type: _univerjs_core.CommandType.COMMAND,
690
+ id: "data-validation.command.insert-quick-rule",
691
+ handler(accessor, params) {
692
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService));
693
+ const ranges = accessor.get(_univerjs_sheets.SheetsSelectionsService).getCurrentSelections().map((selection) => selection.range);
694
+ if (!target || !ranges.length || !(params === null || params === void 0 ? void 0 : params.rule)) return false;
695
+ const rule = createRule(accessor, params.rule);
696
+ return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(_univerjs_sheets_data_validation.AddSheetDataValidationCommand.id, {
697
+ unitId: target.workbook.getUnitId(),
698
+ subUnitId: target.worksheet.getSheetId(),
699
+ rule
700
+ });
701
+ }
702
+ };
703
+ const ClearQuickSheetDataValidationCommand = {
704
+ type: _univerjs_core.CommandType.COMMAND,
705
+ id: "data-validation.command.clear-quick-rule",
706
+ handler(accessor, params) {
707
+ var _params$types;
708
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService));
709
+ const ranges = accessor.get(_univerjs_sheets.SheetsSelectionsService).getCurrentSelections().map((selection) => selection.range);
710
+ if (!target || !ranges.length || !(params === null || params === void 0 || (_params$types = params.types) === null || _params$types === void 0 ? void 0 : _params$types.length)) return false;
711
+ return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(_univerjs_sheets_data_validation.ClearRangeDataValidationCommand.id, {
712
+ unitId: target.workbook.getUnitId(),
713
+ subUnitId: target.worksheet.getSheetId(),
714
+ ranges,
715
+ types: params.types
716
+ });
717
+ }
718
+ };
679
719
  const AddSheetDataValidationAndOpenCommand = {
680
720
  type: _univerjs_core.CommandType.COMMAND,
681
721
  id: "data-validation.command.addRuleAndOpen",
682
- handler(accessor) {
722
+ handler(accessor, params) {
683
723
  const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService));
684
724
  if (!target) return false;
685
725
  const { workbook, worksheet } = target;
686
- const rule = (0, _univerjs_sheets_data_validation.createDefaultNewRule)(accessor);
726
+ if (!accessor.get(_univerjs_sheets.SheetsSelectionsService).getCurrentSelections().length) return false;
727
+ const rule = createRule(accessor, params === null || params === void 0 ? void 0 : params.rule);
687
728
  const commandService = accessor.get(_univerjs_core.ICommandService);
688
729
  const addParams = {
689
730
  rule,
@@ -701,9 +742,92 @@ const AddSheetDataValidationAndOpenCommand = {
701
742
  }
702
743
  };
703
744
 
745
+ //#endregion
746
+ //#region src/views/components/DropdownPresets.tsx
747
+ const DROPDOWN_PRESETS_COMPONENT = "SHEETS_DATA_VALIDATION_DROPDOWN_PRESETS";
748
+ function DropdownPresets({ onChange }) {
749
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
750
+ const presets = [
751
+ [localeService.t("sheets-data-validation-ui.ribbon.presets.yes"), localeService.t("sheets-data-validation-ui.ribbon.presets.no")],
752
+ [
753
+ localeService.t("sheets-data-validation-ui.ribbon.presets.notStarted"),
754
+ localeService.t("sheets-data-validation-ui.ribbon.presets.inProgress"),
755
+ localeService.t("sheets-data-validation-ui.ribbon.presets.completed")
756
+ ],
757
+ [
758
+ "A",
759
+ "B",
760
+ "C"
761
+ ]
762
+ ];
763
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
764
+ className: "univer-box-border univer-w-[360px]",
765
+ children: [
766
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
767
+ className: "univer-px-2 univer-text-sm univer-font-semibold",
768
+ children: localeService.t("sheets-data-validation-ui.ribbon.dropdownPresetTitle")
769
+ }),
770
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
771
+ className: "univer-mt-2 univer-grid univer-grid-cols-3 univer-gap-1.5",
772
+ children: presets.map((values) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
773
+ type: "button",
774
+ "aria-label": values.join(" / "),
775
+ className: "univer-flex univer-min-h-20 univer-cursor-pointer univer-flex-col univer-items-start univer-gap-1.5 univer-rounded-md univer-border-0 univer-bg-gray-50 univer-p-3 univer-text-left univer-text-sm univer-leading-5 univer-text-gray-900 univer-transition-colors hover:univer-bg-gray-100 focus-visible:univer-outline-none focus-visible:univer-ring-2 focus-visible:univer-ring-primary-600 focus-visible:univer-ring-offset-0 dark:!univer-bg-gray-800 dark:!univer-text-white dark:hover:!univer-bg-gray-700",
776
+ onClick: () => onChange((0, _univerjs_sheets.serializeListOptions)(values)),
777
+ children: values.map((value) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
778
+ className: "univer-w-full univer-break-words",
779
+ children: value
780
+ }, value))
781
+ }, values.join("\0")))
782
+ }),
783
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Separator, { className: "univer-mt-2" })
784
+ ]
785
+ });
786
+ }
787
+
704
788
  //#endregion
705
789
  //#region src/menu/dv.menu.ts
706
790
  const DATA_VALIDATION_MENU_ID = "sheet.menu.data-validation";
791
+ const QUICK_DROPDOWN_MENU_ID = "sheet.menu.quick-dropdown";
792
+ const QUICK_DATE_MENU_ID = "sheet.menu.quick-date";
793
+ const CHECKBOX_RULE_INPUT = {
794
+ type: _univerjs_core.DataValidationType.CHECKBOX,
795
+ operator: void 0,
796
+ formula1: void 0,
797
+ formula2: void 0
798
+ };
799
+ const DATE_RULE_INPUT = {
800
+ type: _univerjs_core.DataValidationType.DATE,
801
+ operator: void 0,
802
+ formula1: void 0,
803
+ formula2: void 0
804
+ };
805
+ const DATE_TIME_RULE_INPUT = {
806
+ ...DATE_RULE_INPUT,
807
+ bizInfo: { showTime: true }
808
+ };
809
+ function createDropdownRuleInput(formula1) {
810
+ return {
811
+ type: _univerjs_core.DataValidationType.LIST,
812
+ operator: void 0,
813
+ formula1,
814
+ formula2: "",
815
+ renderMode: _univerjs_core.DataValidationRenderMode.CUSTOM
816
+ };
817
+ }
818
+ function createDropdownCommandParams(value) {
819
+ return typeof value === "undefined" ? {} : { rule: createDropdownRuleInput(String(value)) };
820
+ }
821
+ function getQuickDataValidationMenuState(accessor) {
822
+ return {
823
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
824
+ disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
825
+ workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
826
+ worksheetTypes: [_univerjs_sheets.WorksheetSetCellStylePermission, _univerjs_sheets.WorksheetEditPermission],
827
+ rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
828
+ })
829
+ };
830
+ }
707
831
  function dataValidationMenuFactory(accessor) {
708
832
  return {
709
833
  id: DATA_VALIDATION_MENU_ID,
@@ -718,6 +842,97 @@ function dataValidationMenuFactory(accessor) {
718
842
  })
719
843
  };
720
844
  }
845
+ function quickCheckboxMenuFactory(accessor) {
846
+ return {
847
+ id: InsertQuickSheetDataValidationCommand.id,
848
+ type: _univerjs_ui.MenuItemType.BUTTON_SELECTOR,
849
+ icon: "CheckboxIcon",
850
+ tooltip: "sheets-data-validation-ui.checkbox.title",
851
+ params: { rule: CHECKBOX_RULE_INPUT },
852
+ selectionsCommandId: InsertQuickSheetDataValidationCommand.id,
853
+ selections: [{
854
+ label: "sheets-data-validation-ui.ribbon.setCheckbox",
855
+ value: _univerjs_core.DataValidationType.CHECKBOX,
856
+ params: { rule: CHECKBOX_RULE_INPUT }
857
+ }, {
858
+ label: "sheets-data-validation-ui.ribbon.clearCheckbox",
859
+ id: ClearQuickSheetDataValidationCommand.id,
860
+ value: _univerjs_core.DataValidationType.CHECKBOX,
861
+ params: { types: [_univerjs_core.DataValidationType.CHECKBOX] }
862
+ }],
863
+ ...getQuickDataValidationMenuState(accessor)
864
+ };
865
+ }
866
+ function quickDropdownMenuFactory(accessor) {
867
+ const localeService = accessor.get(_univerjs_core.LocaleService);
868
+ const editDropdownValue = (0, _univerjs_sheets.serializeListOptions)([localeService.t("sheets-data-validation-ui.ribbon.presets.option1"), localeService.t("sheets-data-validation-ui.ribbon.presets.option2")]);
869
+ return {
870
+ id: QUICK_DROPDOWN_MENU_ID,
871
+ type: _univerjs_ui.MenuItemType.SUBITEMS,
872
+ icon: "DropdownListIcon",
873
+ tooltip: "sheets-data-validation-ui.list.title",
874
+ selectionsCommandId: InsertQuickSheetDataValidationCommand.id,
875
+ selections: [
876
+ {
877
+ label: {
878
+ name: DROPDOWN_PRESETS_COMPONENT,
879
+ hoverable: false,
880
+ selectable: false
881
+ },
882
+ params: createDropdownCommandParams
883
+ },
884
+ {
885
+ id: AddSheetDataValidationAndOpenCommand.id,
886
+ label: "sheets-data-validation-ui.ribbon.editDropdown",
887
+ value: editDropdownValue,
888
+ params: { rule: createDropdownRuleInput(editDropdownValue) }
889
+ },
890
+ {
891
+ id: ClearQuickSheetDataValidationCommand.id,
892
+ label: "sheets-data-validation-ui.ribbon.clearDropdown",
893
+ value: _univerjs_core.DataValidationType.LIST,
894
+ params: { types: [_univerjs_core.DataValidationType.LIST, _univerjs_core.DataValidationType.LIST_MULTIPLE] }
895
+ }
896
+ ],
897
+ ...getQuickDataValidationMenuState(accessor)
898
+ };
899
+ }
900
+ function quickDateMenuFactory(accessor) {
901
+ return {
902
+ id: QUICK_DATE_MENU_ID,
903
+ commandId: InsertQuickSheetDataValidationCommand.id,
904
+ type: _univerjs_ui.MenuItemType.BUTTON_SELECTOR,
905
+ icon: "DatePickerIcon",
906
+ tooltip: "sheets-data-validation-ui.date.title",
907
+ params: { rule: DATE_RULE_INPUT },
908
+ selectionsCommandId: InsertQuickSheetDataValidationCommand.id,
909
+ selections: [
910
+ {
911
+ label: "sheets-data-validation-ui.date.title",
912
+ value: _univerjs_core.DataValidationType.DATE,
913
+ params: { rule: DATE_RULE_INPUT }
914
+ },
915
+ {
916
+ label: "sheets-data-validation-ui.ribbon.dateTime",
917
+ value: _univerjs_core.DataValidationType.DATE,
918
+ params: { rule: DATE_TIME_RULE_INPUT }
919
+ },
920
+ {
921
+ id: AddSheetDataValidationAndOpenCommand.id,
922
+ label: "sheets-data-validation-ui.list.edit",
923
+ value: _univerjs_core.DataValidationType.DATE,
924
+ params: { rule: DATE_RULE_INPUT }
925
+ },
926
+ {
927
+ id: ClearQuickSheetDataValidationCommand.id,
928
+ label: "sheets-data-validation-ui.panel.removeRule",
929
+ value: _univerjs_core.DataValidationType.DATE,
930
+ params: { types: [_univerjs_core.DataValidationType.DATE] }
931
+ }
932
+ ],
933
+ ...getQuickDataValidationMenuState(accessor)
934
+ };
935
+ }
721
936
  function openDataValidationMenuFactory() {
722
937
  return {
723
938
  id: OpenValidationPanelOperation.id,
@@ -735,1471 +950,1135 @@ function addDataValidationMenuFactory() {
735
950
 
736
951
  //#endregion
737
952
  //#region src/menu/schema.ts
738
- const menuSchema = { [_univerjs_ui.RibbonDataGroup.RULES]: { [DATA_VALIDATION_MENU_ID]: {
739
- order: 0,
740
- menuItemFactory: dataValidationMenuFactory,
741
- [OpenValidationPanelOperation.id]: {
742
- order: 0,
743
- menuItemFactory: openDataValidationMenuFactory
953
+ const menuSchema = {
954
+ [_univerjs_ui.RibbonInsertGroup.CELL]: {
955
+ [InsertQuickSheetDataValidationCommand.id]: {
956
+ order: 0,
957
+ menuItemFactory: quickCheckboxMenuFactory
958
+ },
959
+ [QUICK_DROPDOWN_MENU_ID]: {
960
+ order: 1,
961
+ menuItemFactory: quickDropdownMenuFactory
962
+ },
963
+ [QUICK_DATE_MENU_ID]: {
964
+ order: 2,
965
+ menuItemFactory: quickDateMenuFactory
966
+ }
744
967
  },
745
- [AddSheetDataValidationAndOpenCommand.id]: {
746
- order: 1,
747
- menuItemFactory: addDataValidationMenuFactory
748
- }
749
- } } };
968
+ [_univerjs_ui.RibbonDataGroup.RULES]: { [DATA_VALIDATION_MENU_ID]: {
969
+ order: 0,
970
+ menuItemFactory: dataValidationMenuFactory,
971
+ [OpenValidationPanelOperation.id]: {
972
+ order: 0,
973
+ menuItemFactory: openDataValidationMenuFactory
974
+ },
975
+ [AddSheetDataValidationAndOpenCommand.id]: {
976
+ order: 1,
977
+ menuItemFactory: addDataValidationMenuFactory
978
+ }
979
+ } }
980
+ };
750
981
 
751
982
  //#endregion
752
983
  //#region package.json
753
984
  var name = "@univerjs/sheets-data-validation-ui";
754
- var version = "1.0.0-insiders.20260717-1e84621";
755
-
756
- //#endregion
757
- //#region src/controllers/components.controller.ts
758
- /**
759
- * Copyright 2023-present DreamNum Co., Ltd.
760
- *
761
- * Licensed under the Apache License, Version 2.0 (the "License");
762
- * you may not use this file except in compliance with the License.
763
- * You may obtain a copy of the License at
764
- *
765
- * http://www.apache.org/licenses/LICENSE-2.0
766
- *
767
- * Unless required by applicable law or agreed to in writing, software
768
- * distributed under the License is distributed on an "AS IS" BASIS,
769
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
770
- * See the License for the specific language governing permissions and
771
- * limitations under the License.
772
- */
773
- let ComponentsController = class ComponentsController extends _univerjs_core.Disposable {
774
- constructor(_componentManager, _iconManager) {
775
- super();
776
- this._componentManager = _componentManager;
777
- this._iconManager = _iconManager;
778
- this._registerIcons();
779
- }
780
- _registerIcons() {
781
- this.disposeWithMe(this._iconManager.register({ DataValidationIcon: _univerjs_icons.DataValidationIcon }));
782
- }
783
- };
784
- ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IconManager))], ComponentsController);
985
+ var version = "1.0.0-insiders.20260720-e1e8f51";
785
986
 
786
987
  //#endregion
787
- //#region src/controllers/dv-alert.controller.ts
788
- const ALERT_KEY = "SHEET_DATA_VALIDATION_ALERT";
789
- let DataValidationAlertController = class DataValidationAlertController extends _univerjs_core.Disposable {
790
- constructor(_hoverManagerService, _cellAlertManagerService, _univerInstanceService, _localeService, _dataValidationModel) {
791
- super();
792
- this._hoverManagerService = _hoverManagerService;
793
- this._cellAlertManagerService = _cellAlertManagerService;
794
- this._univerInstanceService = _univerInstanceService;
795
- this._localeService = _localeService;
796
- this._dataValidationModel = _dataValidationModel;
797
- this._init();
798
- }
799
- _init() {
800
- this._initCellAlertPopup();
801
- }
802
- _initCellAlertPopup() {
803
- this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0, rxjs.debounceTime)(100)).subscribe((cellPos) => {
804
- if (cellPos) {
805
- const workbook = this._univerInstanceService.getUnit(cellPos.location.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
806
- const worksheet = workbook.getSheetBySheetId(cellPos.location.subUnitId);
807
- if (!worksheet) return;
808
- const rule = this._dataValidationModel.getRuleByLocation(cellPos.location.unitId, cellPos.location.subUnitId, cellPos.location.row, cellPos.location.col);
809
- if (!rule) {
810
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
811
- return;
812
- }
813
- if (this._dataValidationModel.validator(rule, {
814
- ...cellPos.location,
815
- workbook,
816
- worksheet
817
- }) === _univerjs_core.DataValidationStatus.INVALID) {
818
- var _currentAlert$alert;
819
- const currentAlert = this._cellAlertManagerService.currentAlert.get(ALERT_KEY);
820
- const currentLoc = currentAlert === null || currentAlert === void 0 || (_currentAlert$alert = currentAlert.alert) === null || _currentAlert$alert === void 0 ? void 0 : _currentAlert$alert.location;
821
- if (currentLoc && currentLoc.row === cellPos.location.row && currentLoc.col === cellPos.location.col && currentLoc.subUnitId === cellPos.location.subUnitId && currentLoc.unitId === cellPos.location.unitId) {
822
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
823
- return;
824
- }
825
- const validator = this._dataValidationModel.getValidator(rule.type);
826
- if (!validator) {
827
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
828
- return;
829
- }
830
- this._cellAlertManagerService.showAlert({
831
- type: _univerjs_sheets_ui.CellAlertType.ERROR,
832
- title: this._localeService.t("sheets-data-validation-ui.error.title"),
833
- message: validator === null || validator === void 0 ? void 0 : validator.getRuleFinalError(rule, cellPos.location),
834
- location: cellPos.location,
835
- width: 200,
836
- height: 74,
837
- key: ALERT_KEY
838
- });
839
- return;
840
- }
841
- }
842
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
843
- }));
844
- }
845
- };
846
- DataValidationAlertController = __decorate([
847
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.HoverManagerService)),
848
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.CellAlertManagerService)),
849
- __decorateParam(2, _univerjs_core.IUniverInstanceService),
850
- __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
851
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel))
852
- ], DataValidationAlertController);
988
+ //#region src/views/components/DataValidationOptions.tsx
989
+ function DataValidationOptions(props) {
990
+ var _value$errorStyle;
991
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
992
+ const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
993
+ const { value, onChange, extraComponent } = props;
994
+ const [show, setShow] = (0, react.useState)(false);
995
+ const ExtraOptions = extraComponent ? componentManager.get(extraComponent) : null;
996
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
997
+ className: "univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900 dark:!univer-text-white",
998
+ onClick: () => setShow(!show),
999
+ children: [localeService.t("sheets-data-validation-ui.panel.options"), show ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreUpIcon, { className: "univer-ml-1" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "univer-ml-1" })]
1000
+ }), show && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1001
+ ExtraOptions ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ExtraOptions, {
1002
+ value,
1003
+ onChange
1004
+ }) : null,
1005
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1006
+ label: localeService.t("sheets-data-validation-ui.panel.invalid"),
1007
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
1008
+ value: `${(_value$errorStyle = value.errorStyle) !== null && _value$errorStyle !== void 0 ? _value$errorStyle : _univerjs_core.DataValidationErrorStyle.WARNING}`,
1009
+ onChange: (errorStyle) => onChange({
1010
+ ...value,
1011
+ errorStyle: +errorStyle
1012
+ }),
1013
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
1014
+ value: `${_univerjs_core.DataValidationErrorStyle.WARNING}`,
1015
+ children: localeService.t("sheets-data-validation-ui.panel.showWarning")
1016
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
1017
+ value: `${_univerjs_core.DataValidationErrorStyle.STOP}`,
1018
+ children: localeService.t("sheets-data-validation-ui.panel.rejectInput")
1019
+ })]
1020
+ })
1021
+ }),
1022
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1023
+ label: localeService.t("sheets-data-validation-ui.panel.messageInfo"),
1024
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
1025
+ checked: value.showErrorMessage,
1026
+ onChange: () => onChange({
1027
+ ...value,
1028
+ showErrorMessage: !value.showErrorMessage
1029
+ }),
1030
+ children: localeService.t("sheets-data-validation-ui.panel.showInfo")
1031
+ })
1032
+ }),
1033
+ value.showErrorMessage ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
1034
+ value: value.error,
1035
+ onChange: (error) => onChange({
1036
+ ...value,
1037
+ error
1038
+ })
1039
+ }) }) : null
1040
+ ] })] });
1041
+ }
853
1042
 
854
1043
  //#endregion
855
- //#region src/controllers/dv-auto-fill.controller.ts
856
- let DataValidationAutoFillController = class DataValidationAutoFillController extends _univerjs_core.Disposable {
857
- constructor(_autoFillService, _sheetDataValidationModel, _injector) {
858
- super();
859
- this._autoFillService = _autoFillService;
860
- this._sheetDataValidationModel = _sheetDataValidationModel;
861
- this._injector = _injector;
862
- this._initAutoFill();
1044
+ //#region src/views/components/DataValidationDetail.tsx
1045
+ const debounceExecuteFactory = (commandService) => (0, _univerjs_core.debounce)(async (id, params, options, callback) => {
1046
+ const res = await commandService.executeCommand(id, params, options);
1047
+ callback === null || callback === void 0 || callback(res);
1048
+ }, 1e3);
1049
+ function getSheetIdByName(univerInstanceService, unitId, name) {
1050
+ var _univerInstanceServic2;
1051
+ if (unitId) {
1052
+ var _univerInstanceServic;
1053
+ return ((_univerInstanceServic = univerInstanceService.getUnit(unitId)) === null || _univerInstanceServic === void 0 || (_univerInstanceServic = _univerInstanceServic.getSheetBySheetName(name)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getSheetId()) || "";
863
1054
  }
864
- _initAutoFill() {
865
- const noopReturnFunc = () => ({
866
- redos: [],
867
- undos: []
868
- });
869
- const generalApplyFunc = (location, applyType) => {
870
- const { source: sourceRange, target: targetRange, unitId, subUnitId } = location;
871
- const ruleMatrixCopy = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
872
- const virtualRange = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([sourceRange, targetRange]);
873
- const [vSourceRange, vTargetRange] = virtualRange.ranges;
874
- const { mapFunc } = virtualRange;
875
- const sourceStartCell = {
876
- row: vSourceRange.startRow,
877
- col: vSourceRange.startColumn
878
- };
879
- const repeats = _univerjs_sheets.AutoFillTools.getAutoFillRepeatRange(vSourceRange, vTargetRange);
880
- const additionMatrix = new _univerjs_core.ObjectMatrix();
881
- const additionRules = /* @__PURE__ */ new Set();
882
- repeats.forEach((repeat) => {
883
- const targetStartCell = repeat.repeatStartCell;
884
- const relativeRange = repeat.relativeRange;
885
- const sourceRange = {
886
- startRow: sourceStartCell.row,
887
- startColumn: sourceStartCell.col,
888
- endColumn: sourceStartCell.col,
889
- endRow: sourceStartCell.row
890
- };
891
- const targetRange = {
892
- startRow: targetStartCell.row,
893
- startColumn: targetStartCell.col,
894
- endColumn: targetStartCell.col,
895
- endRow: targetStartCell.row
896
- };
897
- _univerjs_core.Range.foreach(relativeRange, (row, col) => {
898
- const sourcePositionRange = _univerjs_core.Rectangle.getPositionRange({
899
- startRow: row,
900
- startColumn: col,
901
- endColumn: col,
902
- endRow: row
903
- }, sourceRange);
904
- const { row: sourceRow, col: sourceCol } = mapFunc(sourcePositionRange.startRow, sourcePositionRange.startColumn);
905
- const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, sourceRow, sourceCol) || "";
906
- const targetPositionRange = _univerjs_core.Rectangle.getPositionRange({
907
- startRow: row,
908
- startColumn: col,
909
- endColumn: col,
910
- endRow: row
911
- }, targetRange);
912
- const { row: targetRow, col: targetCol } = mapFunc(targetPositionRange.startRow, targetPositionRange.startColumn);
913
- additionMatrix.setValue(targetRow, targetCol, ruleId);
914
- additionRules.add(ruleId);
915
- });
916
- });
917
- const additions = Array.from(additionRules).map((id) => ({
918
- id,
919
- ranges: (0, _univerjs_core.queryObjectMatrix)(additionMatrix, (value) => value === id)
920
- }));
921
- ruleMatrixCopy.addRangeRules(additions);
922
- const { redoMutations, undoMutations } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(unitId, subUnitId, ruleMatrixCopy.diff(this._sheetDataValidationModel.getRules(unitId, subUnitId)), this._injector, "patched", applyType === _univerjs_sheets.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT);
923
- return {
924
- undos: undoMutations,
925
- redos: redoMutations
926
- };
1055
+ return ((_univerInstanceServic2 = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _univerInstanceServic2 === void 0 || (_univerInstanceServic2 = _univerInstanceServic2.getSheetBySheetName(name)) === null || _univerInstanceServic2 === void 0 ? void 0 : _univerInstanceServic2.getSheetId()) || "";
1056
+ }
1057
+ function DataValidationDetail() {
1058
+ const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
1059
+ const { unitId, subUnitId, rule } = (0, _univerjs_ui.useObservable)(dataValidationPanelService.activeRule$, dataValidationPanelService.activeRule) || {};
1060
+ if (!unitId || !subUnitId || !rule) return null;
1061
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationDetailInner, { activeRuleInfo: {
1062
+ unitId,
1063
+ subUnitId,
1064
+ rule
1065
+ } });
1066
+ }
1067
+ function DataValidationDetailInner(props) {
1068
+ var _validators$sort, _localRule$allowBlank;
1069
+ const [key, setKey] = (0, react.useState)(0);
1070
+ const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
1071
+ const { unitId, subUnitId, rule } = props.activeRuleInfo;
1072
+ const ruleId = rule.uid;
1073
+ const validatorService = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidatorRegistryService);
1074
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
1075
+ const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
1076
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
1077
+ const dataValidationModel = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidationModel);
1078
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1079
+ const workbook = (0, _univerjs_ui.useObservable)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), void 0, void 0, []);
1080
+ const worksheet = (0, _univerjs_ui.useObservable)(() => {
1081
+ var _workbook$activeSheet;
1082
+ return (_workbook$activeSheet = workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) !== null && _workbook$activeSheet !== void 0 ? _workbook$activeSheet : (0, rxjs.of)(null);
1083
+ }, void 0, void 0, []);
1084
+ const [localRule, setLocalRule] = (0, react.useState)(rule);
1085
+ const validator = validatorService.getValidatorItem(localRule.type);
1086
+ const [showError, setShowError] = (0, react.useState)(false);
1087
+ const validators = validatorService.getValidatorsByScope(_univerjs_data_validation.DataValidatorRegistryScope.SHEET);
1088
+ const [localRanges, setLocalRanges] = (0, react.useState)(() => localRule.ranges.map((i) => ({
1089
+ unitId: "",
1090
+ sheetId: "",
1091
+ range: i
1092
+ })));
1093
+ const debounceExecute = (0, react.useMemo)(() => debounceExecuteFactory(commandService), [commandService]);
1094
+ const [isRangeError, setIsRangeError] = (0, react.useState)(false);
1095
+ const [isFocusRangeSelector, setIsFocusRangeSelector] = (0, react.useState)(false);
1096
+ const rangeSelectorInstance = (0, react.useRef)(null);
1097
+ const sheetSelectionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.SheetsSelectionsService);
1098
+ (0, react.useEffect)(() => {
1099
+ return () => {
1100
+ const currentSelection = sheetSelectionService.getCurrentLastSelection();
1101
+ if (currentSelection) sheetSelectionService.setSelections([currentSelection]);
927
1102
  };
928
- const hook = {
929
- id: _univerjs_sheets_data_validation.DATA_VALIDATION_PLUGIN_NAME,
930
- onBeforeFillData: (location) => {
931
- const { source: sourceRange, unitId, subUnitId } = location;
932
- for (const row of sourceRange.rows) for (const col of sourceRange.cols) {
933
- const dv = this._sheetDataValidationModel.getRuleByLocation(unitId, subUnitId, row, col);
934
- if (dv && dv.type === _univerjs_core.DataValidationType.CHECKBOX) {
935
- this._autoFillService.setDisableApplyType(_univerjs_sheets.AUTO_FILL_APPLY_TYPE.SERIES, true);
936
- return;
1103
+ }, [sheetSelectionService]);
1104
+ (0, react.useEffect)(() => {
1105
+ let timer;
1106
+ const disposable = commandService.onCommandExecuted((commandInfo) => {
1107
+ if (commandInfo.id === _univerjs_core.UndoCommand.id || commandInfo.id === _univerjs_core.RedoCommand.id) {
1108
+ if (timer !== void 0) clearTimeout(timer);
1109
+ timer = setTimeout(() => {
1110
+ const activeRule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1111
+ setKey((k) => k + 1);
1112
+ if (activeRule) {
1113
+ setLocalRule(activeRule);
1114
+ setLocalRanges(activeRule.ranges.map((i) => ({
1115
+ unitId: "",
1116
+ sheetId: "",
1117
+ range: i
1118
+ })));
937
1119
  }
938
- }
939
- },
940
- onFillData: (location, direction, applyType) => {
941
- if (applyType === _univerjs_sheets.AUTO_FILL_APPLY_TYPE.COPY || applyType === _univerjs_sheets.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT || applyType === _univerjs_sheets.AUTO_FILL_APPLY_TYPE.SERIES) return generalApplyFunc(location, applyType);
942
- return noopReturnFunc();
943
- },
944
- onAfterFillData: () => {}
1120
+ }, 20);
1121
+ }
1122
+ });
1123
+ return () => {
1124
+ disposable.dispose();
1125
+ if (timer !== void 0) clearTimeout(timer);
945
1126
  };
946
- this.disposeWithMe(this._autoFillService.addHook(hook));
947
- }
948
- };
949
- DataValidationAutoFillController = __decorate([
950
- __decorateParam(0, _univerjs_sheets.IAutoFillService),
951
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
952
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
953
- ], DataValidationAutoFillController);
954
-
955
- //#endregion
956
- //#region src/controllers/dv-copy-paste.controller.ts
957
- const specialPastes = [
958
- _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,
959
- _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,
960
- _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,
961
- _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA
962
- ];
963
- let DataValidationCopyPasteController = class DataValidationCopyPasteController extends _univerjs_core.Disposable {
964
- constructor(_sheetClipboardService, _sheetDataValidationModel, _injector, _univerInstanceService) {
965
- super();
966
- this._sheetClipboardService = _sheetClipboardService;
967
- this._sheetDataValidationModel = _sheetDataValidationModel;
968
- this._injector = _injector;
969
- this._univerInstanceService = _univerInstanceService;
970
- _defineProperty(this, "_copyInfo", void 0);
971
- this._initCopyPaste();
972
- }
973
- _initCopyPaste() {
974
- this._sheetClipboardService.addClipboardHook({
975
- id: _univerjs_sheets_data_validation.DATA_VALIDATION_PLUGIN_NAME,
976
- onBeforeCopy: (unitId, subUnitId, range) => this._collect(unitId, subUnitId, range),
977
- onPasteCells: (pasteFrom, pasteTo, data, payload) => {
978
- if (!pasteFrom || !this._copyInfo || specialPastes.includes(payload.pasteType)) return {
979
- redos: [],
980
- undos: []
1127
+ }, [
1128
+ commandService,
1129
+ dataValidationModel,
1130
+ ruleId,
1131
+ subUnitId,
1132
+ unitId
1133
+ ]);
1134
+ const handleUpdateRuleRanges = (0, _univerjs_ui.useEvent)((rangeText) => {
1135
+ const unitRanges = rangeText.split(",").filter(Boolean).map(_univerjs_engine_formula.deserializeRangeWithSheet).map((unitRange) => {
1136
+ const sheetName = unitRange.sheetName;
1137
+ if (sheetName) {
1138
+ const sheetId = getSheetIdByName(univerInstanceService, unitRange.unitId, sheetName);
1139
+ return {
1140
+ ...unitRange,
1141
+ sheetId
981
1142
  };
982
- return this._generateMutations(pasteFrom, pasteTo, payload);
983
1143
  }
1144
+ return {
1145
+ ...unitRange,
1146
+ sheetId: ""
1147
+ };
984
1148
  });
985
- }
986
- _collect(unitId, subUnitId, range) {
987
- const matrix = new _univerjs_core.ObjectMatrix();
988
- this._copyInfo = {
1149
+ if ((0, _univerjs_core.isUnitRangesEqual)(unitRanges, localRanges)) return;
1150
+ setLocalRanges(unitRanges);
1151
+ const ranges = unitRanges.filter((i) => (!i.unitId || i.unitId === unitId) && (!i.sheetId || i.sheetId === subUnitId)).map((i) => i.range);
1152
+ setLocalRule({
1153
+ ...localRule,
1154
+ ranges
1155
+ });
1156
+ if (ranges.length === 0) return;
1157
+ const params = {
989
1158
  unitId,
990
1159
  subUnitId,
991
- matrix
1160
+ ruleId,
1161
+ ranges
992
1162
  };
993
- const discreteRange = this._injector.invoke((accessor) => {
994
- return (0, _univerjs_sheets.rangeToDiscreteRange)(range, accessor, unitId, subUnitId);
995
- });
996
- if (!discreteRange) return;
997
- const { rows, cols } = discreteRange;
998
- rows.forEach((row, rowIndex) => {
999
- cols.forEach((col, colIndex) => {
1000
- const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, row, col);
1001
- matrix.setValue(rowIndex, colIndex, ruleId !== null && ruleId !== void 0 ? ruleId : "");
1002
- });
1163
+ debounceExecute(_univerjs_sheets_data_validation.UpdateSheetDataValidationRangeCommand.id, params);
1164
+ });
1165
+ const rangeStr = (0, react.useMemo)(() => localRanges.map((i) => (0, _univerjs_engine_formula.serializeRange)(i.range)).join(","), []);
1166
+ if (!validator) return null;
1167
+ const operators = validator.operators;
1168
+ const operatorNames = validator.operatorNames;
1169
+ const isTwoFormula = localRule.operator ? _univerjs_data_validation.TWO_FORMULA_OPERATOR_COUNT.includes(localRule.operator) : false;
1170
+ const goBackActiveRuleSheet = () => {
1171
+ if ((worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId()) !== subUnitId) commandService.syncExecuteCommand(_univerjs_sheets.SetWorksheetActiveOperation.id, {
1172
+ unitId,
1173
+ subUnitId
1003
1174
  });
1004
- }
1005
- _generateMutations(pasteFrom, pasteTo, payload) {
1006
- const { unitId: copyUnitId, subUnitId: copySubUnitId, range: copyRange } = pasteFrom;
1007
- const { unitId: pastedUnitId, subUnitId: pastedSubUnitId, range: pastedRange } = pasteTo;
1008
- const { copyType = _univerjs_sheets_ui.COPY_TYPE.COPY } = payload;
1009
- if (!(0, _univerjs_sheets.getSheetCommandTarget)(this._univerInstanceService, {
1010
- unitId: pastedUnitId,
1011
- subUnitId: pastedSubUnitId
1012
- })) return {
1013
- redos: [],
1014
- undos: []
1015
- };
1016
- if (copyType === _univerjs_sheets_ui.COPY_TYPE.CUT && pastedUnitId === copyUnitId && pastedSubUnitId === copySubUnitId) {
1017
- this._copyInfo = null;
1018
- return {
1019
- redos: [],
1020
- undos: []
1021
- };
1175
+ };
1176
+ const handleOk = () => {
1177
+ var _rangeSelectorInstanc;
1178
+ if ((_rangeSelectorInstanc = rangeSelectorInstance.current) === null || _rangeSelectorInstanc === void 0 || (_rangeSelectorInstanc = _rangeSelectorInstanc.editor) === null || _rangeSelectorInstanc === void 0 ? void 0 : _rangeSelectorInstanc.isFocus()) {
1179
+ var _rangeSelectorInstanc2;
1180
+ handleUpdateRuleRanges((_rangeSelectorInstanc2 = rangeSelectorInstance.current) === null || _rangeSelectorInstanc2 === void 0 ? void 0 : _rangeSelectorInstanc2.getValue());
1022
1181
  }
1023
- if (pastedUnitId !== copyUnitId || pastedSubUnitId !== copySubUnitId) {
1024
- const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(pastedUnitId, pastedSubUnitId).clone();
1025
- const additionMatrix = new _univerjs_core.ObjectMatrix();
1026
- const addRules = /* @__PURE__ */ new Set();
1027
- const { ranges: [vCopyRange, vPastedRange], mapFunc } = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([copyRange, pastedRange]);
1028
- const repeatRange = (0, _univerjs_sheets_ui.getRepeatRange)(vCopyRange, vPastedRange, true);
1029
- const additionRules = /* @__PURE__ */ new Map();
1030
- repeatRange.forEach(({ startRange }) => {
1031
- var _this$_copyInfo;
1032
- (_this$_copyInfo = this._copyInfo) === null || _this$_copyInfo === void 0 || _this$_copyInfo.matrix.forValue((row, col, ruleId) => {
1033
- const range = _univerjs_core.Rectangle.getPositionRange({
1034
- startRow: row,
1035
- endRow: row,
1036
- startColumn: col,
1037
- endColumn: col
1038
- }, startRange);
1039
- const transformedRuleId = `${copySubUnitId}-${ruleId}`;
1040
- const oldRule = this._sheetDataValidationModel.getRuleById(copyUnitId, copySubUnitId, ruleId);
1041
- if (!this._sheetDataValidationModel.getRuleById(pastedUnitId, pastedSubUnitId, transformedRuleId) && oldRule) additionRules.set(transformedRuleId, {
1042
- ...oldRule,
1043
- uid: transformedRuleId
1044
- });
1045
- const { row: startRow, col: startColumn } = mapFunc(range.startRow, range.startColumn);
1046
- addRules.add(transformedRuleId);
1047
- additionMatrix.setValue(startRow, startColumn, transformedRuleId);
1048
- });
1049
- });
1050
- const additions = Array.from(addRules).map((id) => ({
1051
- id,
1052
- ranges: (0, _univerjs_core.queryObjectMatrix)(additionMatrix, (value) => value === id)
1053
- }));
1054
- ruleMatrix.addRangeRules(additions);
1055
- const { redoMutations, undoMutations } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(pastedUnitId, pastedSubUnitId, ruleMatrix.diffWithAddition(this._sheetDataValidationModel.getRules(pastedUnitId, pastedSubUnitId), additionRules.values()), this._injector, "patched", false);
1056
- if (copyType === _univerjs_sheets_ui.COPY_TYPE.CUT) {
1057
- const copySheetRuleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyUnitId, copySubUnitId).clone();
1058
- const deleteRangeStartCell = mapFunc(vCopyRange.startRow, vCopyRange.startColumn);
1059
- const deleteRangeEndCell = mapFunc(vCopyRange.endRow, vCopyRange.endColumn);
1060
- copySheetRuleMatrix.addRangeRules([{
1061
- id: "",
1062
- ranges: [{
1063
- startRow: deleteRangeStartCell.row,
1064
- endRow: deleteRangeEndCell.row,
1065
- startColumn: deleteRangeStartCell.col,
1066
- endColumn: deleteRangeEndCell.col
1067
- }]
1068
- }]);
1069
- const { redoMutations: cutRedos, undoMutations: cutUndos } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(copyUnitId, copySubUnitId, copySheetRuleMatrix.diff(this._sheetDataValidationModel.getRules(copyUnitId, copySubUnitId)), this._injector, "patched", false);
1070
- redoMutations.push(...cutRedos);
1071
- undoMutations.push(...cutUndos);
1072
- }
1073
- return {
1074
- redos: redoMutations,
1075
- undos: undoMutations
1076
- };
1077
- } else {
1078
- const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyUnitId, copySubUnitId).clone();
1079
- const additionMatrix = new _univerjs_core.ObjectMatrix();
1080
- const additionRules = /* @__PURE__ */ new Set();
1081
- const { ranges: [vCopyRange, vPastedRange], mapFunc } = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([copyRange, pastedRange]);
1082
- (0, _univerjs_sheets_ui.getRepeatRange)(vCopyRange, vPastedRange, true).forEach(({ startRange }) => {
1083
- var _this$_copyInfo2;
1084
- (_this$_copyInfo2 = this._copyInfo) === null || _this$_copyInfo2 === void 0 || _this$_copyInfo2.matrix.forValue((row, col, ruleId) => {
1085
- const range = _univerjs_core.Rectangle.getPositionRange({
1086
- startRow: row,
1087
- endRow: row,
1088
- startColumn: col,
1089
- endColumn: col
1090
- }, startRange);
1091
- const { row: startRow, col: startColumn } = mapFunc(range.startRow, range.startColumn);
1092
- additionMatrix.setValue(startRow, startColumn, ruleId);
1093
- additionRules.add(ruleId);
1094
- });
1095
- });
1096
- const additions = Array.from(additionRules).map((id) => ({
1097
- id,
1098
- ranges: (0, _univerjs_core.queryObjectMatrix)(additionMatrix, (value) => value === id)
1099
- }));
1100
- ruleMatrix.addRangeRules(additions);
1101
- const { redoMutations, undoMutations } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(pastedUnitId, pastedSubUnitId, ruleMatrix.diff(this._sheetDataValidationModel.getRules(copyUnitId, copySubUnitId)), this._injector, "patched", false);
1102
- return {
1103
- redos: redoMutations,
1104
- undos: undoMutations
1105
- };
1106
- }
1107
- }
1108
- };
1109
- DataValidationCopyPasteController = __decorate([
1110
- __decorateParam(0, _univerjs_sheets_ui.ISheetClipboardService),
1111
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
1112
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
1113
- __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService))
1114
- ], DataValidationCopyPasteController);
1115
-
1116
- //#endregion
1117
- //#region src/controllers/dv-permission.controller.ts
1118
- let DataValidationPermissionController = class DataValidationPermissionController extends _univerjs_core.Disposable {
1119
- constructor(_localeService, _commandService, _sheetPermissionCheckController) {
1120
- super();
1121
- this._localeService = _localeService;
1122
- this._commandService = _commandService;
1123
- this._sheetPermissionCheckController = _sheetPermissionCheckController;
1124
- this._commandExecutedListener();
1125
- }
1126
- _commandExecutedListener() {
1127
- this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
1128
- if (command.id === _univerjs_sheets_data_validation.AddSheetDataValidationCommand.id) {
1129
- const { unitId, subUnitId, rule: { ranges } } = command.params;
1130
- if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
1131
- workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
1132
- rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint],
1133
- worksheetTypes: [_univerjs_sheets.WorksheetEditPermission, _univerjs_sheets.WorksheetSetCellStylePermission]
1134
- }, ranges, unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-data-validation-ui.permission.dialog.setStyleErr"));
1135
- }
1136
- if (command.id === _univerjs_sheets_data_validation.UpdateSheetDataValidationRangeCommand.id) {
1137
- const { unitId, subUnitId, ranges } = command.params;
1138
- if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
1139
- workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
1140
- rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint],
1141
- worksheetTypes: [_univerjs_sheets.WorksheetEditPermission, _univerjs_sheets.WorksheetSetCellStylePermission]
1142
- }, ranges, unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-data-validation-ui.permission.dialog.setStyleErr"));
1143
- }
1144
- }));
1145
- }
1146
- };
1147
- DataValidationPermissionController = __decorate([
1148
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
1149
- __decorateParam(1, _univerjs_core.ICommandService),
1150
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetPermissionCheckController))
1151
- ], DataValidationPermissionController);
1152
-
1153
- //#endregion
1154
- //#region src/controllers/dv-render.controller.ts
1155
- const INVALID_MARK = { tr: {
1156
- size: 6,
1157
- color: "#fe4b4b"
1158
- } };
1159
- let SheetsDataValidationRenderController = class SheetsDataValidationRenderController extends _univerjs_core.RxDisposable {
1160
- constructor(_commandService, _menuManagerService, _renderManagerService, _univerInstanceService, _autoHeightController, _dropdownManagerService, _sheetDataValidationModel, _dataValidatorRegistryService, _sheetInterceptorService, _dataValidationCacheService, _editorBridgeService) {
1161
- super();
1162
- this._commandService = _commandService;
1163
- this._menuManagerService = _menuManagerService;
1164
- this._renderManagerService = _renderManagerService;
1165
- this._univerInstanceService = _univerInstanceService;
1166
- this._autoHeightController = _autoHeightController;
1167
- this._dropdownManagerService = _dropdownManagerService;
1168
- this._sheetDataValidationModel = _sheetDataValidationModel;
1169
- this._dataValidatorRegistryService = _dataValidatorRegistryService;
1170
- this._sheetInterceptorService = _sheetInterceptorService;
1171
- this._dataValidationCacheService = _dataValidationCacheService;
1172
- this._editorBridgeService = _editorBridgeService;
1173
- this._initMenu();
1174
- this._initDropdown();
1175
- this._initViewModelIntercept();
1176
- this._initAutoHeight();
1177
- }
1178
- _initMenu() {
1179
- this._menuManagerService.mergeMenu(menuSchema);
1180
- }
1181
- _initDropdown() {
1182
- if (!this._editorBridgeService) return;
1183
- this.disposeWithMe(this._editorBridgeService.visible$.subscribe((visible) => {
1184
- if (!visible.visible) {
1185
- var _this$_dropdownManage;
1186
- if (((_this$_dropdownManage = this._dropdownManagerService.activeDropdown) === null || _this$_dropdownManage === void 0 ? void 0 : _this$_dropdownManage.trigger) === "editor-bridge") this._dropdownManagerService.hideDropdown();
1187
- return;
1188
- }
1189
- const state = this._editorBridgeService.getEditCellState();
1190
- if (state) {
1191
- const { unitId, sheetId, row, column } = state;
1192
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
1193
- if (!workbook) return;
1194
- const rule = this._sheetDataValidationModel.getRuleByLocation(unitId, sheetId, row, column);
1195
- if (!rule) return;
1196
- const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
1197
- if (!(validator === null || validator === void 0 ? void 0 : validator.dropdownType)) return;
1198
- const worksheet = workbook.getActiveSheet();
1199
- if (!worksheet) return;
1200
- const activeDropdown = this._dropdownManagerService.activeDropdown;
1201
- const currLoc = activeDropdown === null || activeDropdown === void 0 ? void 0 : activeDropdown.location;
1202
- if (currLoc && currLoc.unitId === unitId && currLoc.subUnitId === sheetId && currLoc.row === row && currLoc.col === column) return;
1203
- this._dropdownManagerService.showDropdown({
1204
- location: {
1205
- unitId,
1206
- subUnitId: sheetId,
1207
- row,
1208
- col: column,
1209
- workbook,
1210
- worksheet
1211
- },
1212
- trigger: "editor-bridge",
1213
- closeOnOutSide: false
1214
- });
1215
- }
1216
- }));
1217
- }
1218
- _initViewModelIntercept() {
1219
- this.disposeWithMe(this._sheetInterceptorService.intercept(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, {
1220
- effect: _univerjs_core.InterceptorEffectEnum.Style,
1221
- priority: _univerjs_sheets.InterceptCellContentPriority.DATA_VALIDATION,
1222
- handler: (cell, pos, next) => {
1223
- var _this$_dataValidation, _cell$customRender, _cell$fontRenderExten, _validator$skipDefaul, _cell$coverable;
1224
- const { row, col, unitId, subUnitId, workbook, worksheet } = pos;
1225
- const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, row, col);
1226
- if (!ruleId) return next(cell);
1227
- const rule = this._sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1228
- if (!rule) return next(cell);
1229
- const validStatus = (_this$_dataValidation = this._dataValidationCacheService.getValue(unitId, subUnitId, row, col)) !== null && _this$_dataValidation !== void 0 ? _this$_dataValidation : _univerjs_core.DataValidationStatus.VALID;
1230
- const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
1231
- const cellOrigin = pos.rawData;
1232
- let cache;
1233
- const cellValue = { get value() {
1234
- var _getCellValueOrigin;
1235
- if (cache !== void 0) return cache;
1236
- cache = (_getCellValueOrigin = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(cellOrigin)) !== null && _getCellValueOrigin !== void 0 ? _getCellValueOrigin : null;
1237
- return cache;
1238
- } };
1239
- const valueStr = { get value() {
1240
- var _cellValue$value;
1241
- return `${(_cellValue$value = cellValue.value) !== null && _cellValue$value !== void 0 ? _cellValue$value : ""}`;
1242
- } };
1243
- if (!cell || cell === pos.rawData) cell = { ...pos.rawData };
1244
- cell.markers = {
1245
- ...cell === null || cell === void 0 ? void 0 : cell.markers,
1246
- ...validStatus === _univerjs_core.DataValidationStatus.INVALID ? INVALID_MARK : null
1247
- };
1248
- cell.customRender = [...(_cell$customRender = cell === null || cell === void 0 ? void 0 : cell.customRender) !== null && _cell$customRender !== void 0 ? _cell$customRender : [], ...(validator === null || validator === void 0 ? void 0 : validator.canvasRender) ? [validator.canvasRender] : []];
1249
- cell.fontRenderExtension = {
1250
- ...cell === null || cell === void 0 ? void 0 : cell.fontRenderExtension,
1251
- isSkip: (cell === null || cell === void 0 || (_cell$fontRenderExten = cell.fontRenderExtension) === null || _cell$fontRenderExten === void 0 ? void 0 : _cell$fontRenderExten.isSkip) || (validator === null || validator === void 0 || (_validator$skipDefaul = validator.skipDefaultFontRender) === null || _validator$skipDefaul === void 0 ? void 0 : _validator$skipDefaul.call(validator, rule, cellValue.value, pos))
1252
- };
1253
- cell.interceptorStyle = {
1254
- ...cell === null || cell === void 0 ? void 0 : cell.interceptorStyle,
1255
- ...validator === null || validator === void 0 ? void 0 : validator.getExtraStyle(rule, valueStr.value, { get style() {
1256
- const styleMap = workbook.getStyles();
1257
- return (typeof (cell === null || cell === void 0 ? void 0 : cell.s) === "string" ? styleMap.get(cell === null || cell === void 0 ? void 0 : cell.s) : cell === null || cell === void 0 ? void 0 : cell.s) || {};
1258
- } }, row, col)
1259
- };
1260
- cell.interceptorAutoHeight = () => {
1261
- var _this$_renderManagerS, _mergeCell$startRow, _mergeCell$startColum, _validator$canvasRend, _validator$canvasRend2;
1262
- const skeleton = (_this$_renderManagerS = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS === void 0 || (_this$_renderManagerS = _this$_renderManagerS.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.skeleton;
1263
- if (!skeleton) return;
1264
- const mergeCell = skeleton.worksheet.getMergedCell(row, col);
1265
- const info = {
1266
- data: cell,
1267
- style: skeleton.getStyles().getStyleByCell(cell),
1268
- primaryWithCoord: skeleton.getCellWithCoordByIndex((_mergeCell$startRow = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startRow) !== null && _mergeCell$startRow !== void 0 ? _mergeCell$startRow : row, (_mergeCell$startColum = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startColumn) !== null && _mergeCell$startColum !== void 0 ? _mergeCell$startColum : col),
1269
- unitId,
1270
- subUnitId,
1271
- row,
1272
- col,
1273
- workbook,
1274
- worksheet
1275
- };
1276
- return validator === null || validator === void 0 || (_validator$canvasRend = validator.canvasRender) === null || _validator$canvasRend === void 0 || (_validator$canvasRend2 = _validator$canvasRend.calcCellAutoHeight) === null || _validator$canvasRend2 === void 0 ? void 0 : _validator$canvasRend2.call(_validator$canvasRend, info);
1277
- };
1278
- cell.interceptorAutoWidth = () => {
1279
- var _this$_renderManagerS2, _mergeCell$startRow2, _mergeCell$startColum2, _validator$canvasRend3, _validator$canvasRend4;
1280
- const skeleton = (_this$_renderManagerS2 = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS2 === void 0 || (_this$_renderManagerS2 = _this$_renderManagerS2.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.skeleton;
1281
- if (!skeleton) return;
1282
- const mergeCell = skeleton.worksheet.getMergedCell(row, col);
1283
- const info = {
1284
- data: cell,
1285
- style: skeleton.getStyles().getStyleByCell(cell),
1286
- primaryWithCoord: skeleton.getCellWithCoordByIndex((_mergeCell$startRow2 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startRow) !== null && _mergeCell$startRow2 !== void 0 ? _mergeCell$startRow2 : row, (_mergeCell$startColum2 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startColumn) !== null && _mergeCell$startColum2 !== void 0 ? _mergeCell$startColum2 : col),
1287
- unitId,
1288
- subUnitId,
1289
- row,
1290
- col,
1291
- workbook,
1292
- worksheet
1293
- };
1294
- return validator === null || validator === void 0 || (_validator$canvasRend3 = validator.canvasRender) === null || _validator$canvasRend3 === void 0 || (_validator$canvasRend4 = _validator$canvasRend3.calcCellAutoWidth) === null || _validator$canvasRend4 === void 0 ? void 0 : _validator$canvasRend4.call(_validator$canvasRend3, info);
1295
- };
1296
- cell.coverable = ((_cell$coverable = cell === null || cell === void 0 ? void 0 : cell.coverable) !== null && _cell$coverable !== void 0 ? _cell$coverable : true) && !(rule.type === _univerjs_core.DataValidationType.LIST || rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE);
1297
- return next(cell);
1298
- }
1299
- }));
1300
- }
1301
- _initAutoHeight() {
1302
- this._sheetDataValidationModel.ruleChange$.pipe((0, rxjs.filter)((change) => change.source === "command"), (0, rxjs.bufferTime)(100)).subscribe((infos) => {
1303
- if (infos.length === 0) return;
1304
- const ranges = [];
1305
- infos.forEach((info) => {
1306
- if (info.rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE || info.rule.type === _univerjs_core.DataValidationType.LIST) {
1307
- var _info$rule;
1308
- if ((_info$rule = info.rule) === null || _info$rule === void 0 ? void 0 : _info$rule.ranges) ranges.push(...info.rule.ranges);
1309
- }
1310
- });
1311
- if (ranges.length) (0, _univerjs_core.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(ranges).redos, this._commandService);
1312
- });
1313
- }
1314
- };
1315
- SheetsDataValidationRenderController = __decorate([
1316
- __decorateParam(0, _univerjs_core.ICommandService),
1317
- __decorateParam(1, _univerjs_ui.IMenuManagerService),
1318
- __decorateParam(2, _univerjs_engine_render.IRenderManagerService),
1319
- __decorateParam(3, _univerjs_core.IUniverInstanceService),
1320
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.AutoHeightController)),
1321
- __decorateParam(5, (0, _univerjs_core.Inject)(DataValidationDropdownManagerService)),
1322
- __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
1323
- __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService)),
1324
- __decorateParam(8, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
1325
- __decorateParam(9, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.DataValidationCacheService)),
1326
- __decorateParam(10, (0, _univerjs_core.Optional)(_univerjs_sheets_ui.IEditorBridgeService))
1327
- ], SheetsDataValidationRenderController);
1328
- let SheetsDataValidationMobileRenderController = class SheetsDataValidationMobileRenderController extends _univerjs_core.RxDisposable {
1329
- constructor(_commandService, _renderManagerService, _autoHeightController, _dataValidatorRegistryService, _sheetInterceptorService, _sheetDataValidationModel, _dataValidationCacheService) {
1330
- super();
1331
- this._commandService = _commandService;
1332
- this._renderManagerService = _renderManagerService;
1333
- this._autoHeightController = _autoHeightController;
1334
- this._dataValidatorRegistryService = _dataValidatorRegistryService;
1335
- this._sheetInterceptorService = _sheetInterceptorService;
1336
- this._sheetDataValidationModel = _sheetDataValidationModel;
1337
- this._dataValidationCacheService = _dataValidationCacheService;
1338
- this._initViewModelIntercept();
1339
- this._initAutoHeight();
1340
- }
1341
- _initViewModelIntercept() {
1342
- this.disposeWithMe(this._sheetInterceptorService.intercept(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, {
1343
- effect: _univerjs_core.InterceptorEffectEnum.Style,
1344
- priority: _univerjs_sheets.InterceptCellContentPriority.DATA_VALIDATION,
1345
- handler: (cell, pos, next) => {
1346
- var _this$_dataValidation2, _cell$customRender2, _cell$fontRenderExten2, _validator$skipDefaul2, _cell$coverable2;
1347
- const { row, col, unitId, subUnitId, workbook, worksheet } = pos;
1348
- const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, row, col);
1349
- if (!ruleId) return next(cell);
1350
- const rule = this._sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1351
- if (!rule) return next(cell);
1352
- const validStatus = (_this$_dataValidation2 = this._dataValidationCacheService.getValue(unitId, subUnitId, row, col)) !== null && _this$_dataValidation2 !== void 0 ? _this$_dataValidation2 : _univerjs_core.DataValidationStatus.VALID;
1353
- const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
1354
- const cellValue = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(worksheet.getCellRaw(row, col));
1355
- const valueStr = `${cellValue !== null && cellValue !== void 0 ? cellValue : ""}`;
1356
- if (!cell || cell === pos.rawData) cell = { ...pos.rawData };
1357
- cell.markers = {
1358
- ...cell === null || cell === void 0 ? void 0 : cell.markers,
1359
- ...validStatus === _univerjs_core.DataValidationStatus.INVALID ? INVALID_MARK : null
1360
- };
1361
- cell.customRender = [...(_cell$customRender2 = cell === null || cell === void 0 ? void 0 : cell.customRender) !== null && _cell$customRender2 !== void 0 ? _cell$customRender2 : [], ...(validator === null || validator === void 0 ? void 0 : validator.canvasRender) ? [validator.canvasRender] : []];
1362
- cell.fontRenderExtension = {
1363
- ...cell === null || cell === void 0 ? void 0 : cell.fontRenderExtension,
1364
- isSkip: (cell === null || cell === void 0 || (_cell$fontRenderExten2 = cell.fontRenderExtension) === null || _cell$fontRenderExten2 === void 0 ? void 0 : _cell$fontRenderExten2.isSkip) || (validator === null || validator === void 0 || (_validator$skipDefaul2 = validator.skipDefaultFontRender) === null || _validator$skipDefaul2 === void 0 ? void 0 : _validator$skipDefaul2.call(validator, rule, cellValue, pos))
1365
- };
1366
- cell.interceptorStyle = {
1367
- ...cell === null || cell === void 0 ? void 0 : cell.interceptorStyle,
1368
- ...validator === null || validator === void 0 ? void 0 : validator.getExtraStyle(rule, valueStr, { get style() {
1369
- const styleMap = workbook.getStyles();
1370
- return (typeof (cell === null || cell === void 0 ? void 0 : cell.s) === "string" ? styleMap.get(cell === null || cell === void 0 ? void 0 : cell.s) : cell === null || cell === void 0 ? void 0 : cell.s) || {};
1371
- } }, row, col)
1372
- };
1373
- cell.interceptorAutoHeight = () => {
1374
- var _this$_renderManagerS3, _mergeCell$startRow3, _mergeCell$startColum3, _validator$canvasRend5, _validator$canvasRend6;
1375
- const skeleton = (_this$_renderManagerS3 = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS3 === void 0 || (_this$_renderManagerS3 = _this$_renderManagerS3.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _this$_renderManagerS3 === void 0 ? void 0 : _this$_renderManagerS3.skeleton;
1376
- if (!skeleton) return;
1377
- const mergeCell = skeleton.worksheet.getMergedCell(row, col);
1378
- const info = {
1379
- data: cell,
1380
- style: skeleton.getStyles().getStyleByCell(cell),
1381
- primaryWithCoord: skeleton.getCellWithCoordByIndex((_mergeCell$startRow3 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startRow) !== null && _mergeCell$startRow3 !== void 0 ? _mergeCell$startRow3 : row, (_mergeCell$startColum3 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startColumn) !== null && _mergeCell$startColum3 !== void 0 ? _mergeCell$startColum3 : col),
1382
- unitId,
1383
- subUnitId,
1384
- row,
1385
- col,
1386
- workbook,
1387
- worksheet
1388
- };
1389
- return validator === null || validator === void 0 || (_validator$canvasRend5 = validator.canvasRender) === null || _validator$canvasRend5 === void 0 || (_validator$canvasRend6 = _validator$canvasRend5.calcCellAutoHeight) === null || _validator$canvasRend6 === void 0 ? void 0 : _validator$canvasRend6.call(_validator$canvasRend5, info);
1390
- };
1391
- cell.interceptorAutoWidth = () => {
1392
- var _this$_renderManagerS4, _mergeCell$startRow4, _mergeCell$startColum4, _validator$canvasRend7, _validator$canvasRend8;
1393
- const skeleton = (_this$_renderManagerS4 = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS4 === void 0 || (_this$_renderManagerS4 = _this$_renderManagerS4.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _this$_renderManagerS4 === void 0 ? void 0 : _this$_renderManagerS4.skeleton;
1394
- if (!skeleton) return;
1395
- const mergeCell = skeleton.worksheet.getMergedCell(row, col);
1396
- const info = {
1397
- data: cell,
1398
- style: skeleton.getStyles().getStyleByCell(cell),
1399
- primaryWithCoord: skeleton.getCellWithCoordByIndex((_mergeCell$startRow4 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startRow) !== null && _mergeCell$startRow4 !== void 0 ? _mergeCell$startRow4 : row, (_mergeCell$startColum4 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startColumn) !== null && _mergeCell$startColum4 !== void 0 ? _mergeCell$startColum4 : col),
1400
- unitId,
1401
- subUnitId,
1402
- row,
1403
- col,
1404
- workbook,
1405
- worksheet
1406
- };
1407
- return validator === null || validator === void 0 || (_validator$canvasRend7 = validator.canvasRender) === null || _validator$canvasRend7 === void 0 || (_validator$canvasRend8 = _validator$canvasRend7.calcCellAutoWidth) === null || _validator$canvasRend8 === void 0 ? void 0 : _validator$canvasRend8.call(_validator$canvasRend7, info);
1408
- };
1409
- cell.coverable = ((_cell$coverable2 = cell === null || cell === void 0 ? void 0 : cell.coverable) !== null && _cell$coverable2 !== void 0 ? _cell$coverable2 : true) && !(rule.type === _univerjs_core.DataValidationType.LIST || rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE);
1410
- return next(cell);
1411
- }
1412
- }));
1413
- }
1414
- _initAutoHeight() {
1415
- this._sheetDataValidationModel.ruleChange$.pipe((0, rxjs.filter)((change) => change.source === "command"), (0, rxjs.bufferTime)(16)).subscribe((infos) => {
1416
- const ranges = [];
1417
- infos.forEach((info) => {
1418
- if (info.rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE || info.rule.type === _univerjs_core.DataValidationType.LIST) {
1419
- var _info$rule2;
1420
- if ((_info$rule2 = info.rule) === null || _info$rule2 === void 0 ? void 0 : _info$rule2.ranges) ranges.push(...info.rule.ranges);
1421
- }
1422
- });
1423
- if (ranges.length) (0, _univerjs_core.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(ranges).redos, this._commandService);
1182
+ if (!localRule.ranges.length || isRangeError) return;
1183
+ if (validator.validatorFormula(localRule, unitId, subUnitId).success) dataValidationPanelService.setActiveRule(null);
1184
+ else setShowError(true);
1185
+ goBackActiveRuleSheet();
1186
+ };
1187
+ const handleUpdateRuleSetting = (setting) => {
1188
+ if ((0, _univerjs_core.shallowEqual)(setting, (0, _univerjs_data_validation.getRuleSetting)(localRule))) return;
1189
+ setLocalRule({
1190
+ ...localRule,
1191
+ ...setting
1424
1192
  });
1425
- }
1426
- };
1427
- SheetsDataValidationMobileRenderController = __decorate([
1428
- __decorateParam(0, _univerjs_core.ICommandService),
1429
- __decorateParam(1, _univerjs_engine_render.IRenderManagerService),
1430
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.AutoHeightController)),
1431
- __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService)),
1432
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
1433
- __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
1434
- __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.DataValidationCacheService))
1435
- ], SheetsDataValidationMobileRenderController);
1436
-
1437
- //#endregion
1438
- //#region src/controllers/dv-rerender.controller.ts
1439
- let SheetsDataValidationReRenderController = class SheetsDataValidationReRenderController extends _univerjs_core.Disposable {
1440
- constructor(_context, _sheetDataValidationModel, _sheetSkeletonManagerService) {
1441
- super();
1442
- this._context = _context;
1443
- this._sheetDataValidationModel = _sheetDataValidationModel;
1444
- this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
1445
- this._initSkeletonChange();
1446
- }
1447
- _initSkeletonChange() {
1448
- const reRender = (values) => {
1449
- var _this$_context$mainCo;
1450
- if (!values.length) return;
1451
- const sheetIds = /* @__PURE__ */ new Set();
1452
- values.forEach((value) => {
1453
- sheetIds.add(value.subUnitId);
1454
- });
1455
- sheetIds.forEach((sheetId) => {
1456
- var _this$_sheetSkeletonM;
1457
- (_this$_sheetSkeletonM = this._sheetSkeletonManagerService.getSkeletonParam(sheetId)) === null || _this$_sheetSkeletonM === void 0 || _this$_sheetSkeletonM.skeleton.makeDirty(true);
1458
- });
1459
- (_this$_context$mainCo = this._context.mainComponent) === null || _this$_context$mainCo === void 0 || _this$_context$mainCo.makeForceDirty();
1460
- };
1461
- this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe((0, _univerjs_core.bufferDebounceTime)(16)).subscribe(reRender));
1462
- }
1463
- };
1464
- SheetsDataValidationReRenderController = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)), __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.SheetSkeletonManagerService))], SheetsDataValidationReRenderController);
1465
-
1466
- //#endregion
1467
- //#region src/views/components/DataValidationOptions.tsx
1468
- function DataValidationOptions(props) {
1469
- var _value$errorStyle;
1470
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1471
- const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
1472
- const { value, onChange, extraComponent } = props;
1473
- const [show, setShow] = (0, react.useState)(false);
1474
- const ExtraOptions = extraComponent ? componentManager.get(extraComponent) : null;
1475
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1476
- className: "univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900 dark:!univer-text-white",
1477
- onClick: () => setShow(!show),
1478
- children: [localeService.t("sheets-data-validation-ui.panel.options"), show ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreUpIcon, { className: "univer-ml-1" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "univer-ml-1" })]
1479
- }), show && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1480
- ExtraOptions ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ExtraOptions, {
1481
- value,
1482
- onChange
1483
- }) : null,
1484
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1485
- label: localeService.t("sheets-data-validation-ui.panel.invalid"),
1486
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
1487
- value: `${(_value$errorStyle = value.errorStyle) !== null && _value$errorStyle !== void 0 ? _value$errorStyle : _univerjs_core.DataValidationErrorStyle.WARNING}`,
1488
- onChange: (errorStyle) => onChange({
1489
- ...value,
1490
- errorStyle: +errorStyle
1491
- }),
1492
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
1493
- value: `${_univerjs_core.DataValidationErrorStyle.WARNING}`,
1494
- children: localeService.t("sheets-data-validation-ui.panel.showWarning")
1495
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
1496
- value: `${_univerjs_core.DataValidationErrorStyle.STOP}`,
1497
- children: localeService.t("sheets-data-validation-ui.panel.rejectInput")
1498
- })]
1499
- })
1500
- }),
1501
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1502
- label: localeService.t("sheets-data-validation-ui.panel.messageInfo"),
1503
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
1504
- checked: value.showErrorMessage,
1505
- onChange: () => onChange({
1506
- ...value,
1507
- showErrorMessage: !value.showErrorMessage
1508
- }),
1509
- children: localeService.t("sheets-data-validation-ui.panel.showInfo")
1510
- })
1511
- }),
1512
- value.showErrorMessage ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
1513
- value: value.error,
1514
- onChange: (error) => onChange({
1515
- ...value,
1516
- error
1517
- })
1518
- }) }) : null
1519
- ] })] });
1520
- }
1521
-
1522
- //#endregion
1523
- //#region src/views/components/DataValidationDetail.tsx
1524
- const debounceExecuteFactory = (commandService) => (0, _univerjs_core.debounce)(async (id, params, options, callback) => {
1525
- const res = await commandService.executeCommand(id, params, options);
1526
- callback === null || callback === void 0 || callback(res);
1527
- }, 1e3);
1528
- function getSheetIdByName(univerInstanceService, unitId, name) {
1529
- var _univerInstanceServic2;
1530
- if (unitId) {
1531
- var _univerInstanceServic;
1532
- return ((_univerInstanceServic = univerInstanceService.getUnit(unitId)) === null || _univerInstanceServic === void 0 || (_univerInstanceServic = _univerInstanceServic.getSheetBySheetName(name)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getSheetId()) || "";
1533
- }
1534
- return ((_univerInstanceServic2 = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _univerInstanceServic2 === void 0 || (_univerInstanceServic2 = _univerInstanceServic2.getSheetBySheetName(name)) === null || _univerInstanceServic2 === void 0 ? void 0 : _univerInstanceServic2.getSheetId()) || "";
1535
- }
1536
- function DataValidationDetail() {
1537
- const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
1538
- const { unitId, subUnitId, rule } = (0, _univerjs_ui.useObservable)(dataValidationPanelService.activeRule$, dataValidationPanelService.activeRule) || {};
1539
- if (!unitId || !subUnitId || !rule) return null;
1540
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationDetailInner, { activeRuleInfo: {
1541
- unitId,
1542
- subUnitId,
1543
- rule
1544
- } });
1545
- }
1546
- function DataValidationDetailInner(props) {
1547
- var _validators$sort, _localRule$allowBlank;
1548
- const [key, setKey] = (0, react.useState)(0);
1549
- const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
1550
- const { unitId, subUnitId, rule } = props.activeRuleInfo;
1551
- const ruleId = rule.uid;
1552
- const validatorService = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidatorRegistryService);
1553
- const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
1554
- const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
1555
- const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
1556
- const dataValidationModel = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidationModel);
1557
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1558
- const workbook = (0, _univerjs_ui.useObservable)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), void 0, void 0, []);
1559
- const worksheet = (0, _univerjs_ui.useObservable)(() => {
1560
- var _workbook$activeSheet;
1561
- return (_workbook$activeSheet = workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) !== null && _workbook$activeSheet !== void 0 ? _workbook$activeSheet : (0, rxjs.of)(null);
1562
- }, void 0, void 0, []);
1563
- const [localRule, setLocalRule] = (0, react.useState)(rule);
1564
- const validator = validatorService.getValidatorItem(localRule.type);
1565
- const [showError, setShowError] = (0, react.useState)(false);
1566
- const validators = validatorService.getValidatorsByScope(_univerjs_data_validation.DataValidatorRegistryScope.SHEET);
1567
- const [localRanges, setLocalRanges] = (0, react.useState)(() => localRule.ranges.map((i) => ({
1568
- unitId: "",
1569
- sheetId: "",
1570
- range: i
1571
- })));
1572
- const debounceExecute = (0, react.useMemo)(() => debounceExecuteFactory(commandService), [commandService]);
1573
- const [isRangeError, setIsRangeError] = (0, react.useState)(false);
1574
- const [isFocusRangeSelector, setIsFocusRangeSelector] = (0, react.useState)(false);
1575
- const rangeSelectorInstance = (0, react.useRef)(null);
1576
- const sheetSelectionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.SheetsSelectionsService);
1577
- (0, react.useEffect)(() => {
1578
- return () => {
1579
- const currentSelection = sheetSelectionService.getCurrentLastSelection();
1580
- if (currentSelection) sheetSelectionService.setSelections([currentSelection]);
1193
+ const params = {
1194
+ unitId,
1195
+ subUnitId,
1196
+ ruleId,
1197
+ setting
1581
1198
  };
1582
- }, [sheetSelectionService]);
1583
- (0, react.useEffect)(() => {
1584
- let timer;
1585
- const disposable = commandService.onCommandExecuted((commandInfo) => {
1586
- if (commandInfo.id === _univerjs_core.UndoCommand.id || commandInfo.id === _univerjs_core.RedoCommand.id) {
1587
- if (timer !== void 0) clearTimeout(timer);
1588
- timer = setTimeout(() => {
1589
- const activeRule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1590
- setKey((k) => k + 1);
1591
- if (activeRule) {
1592
- setLocalRule(activeRule);
1593
- setLocalRanges(activeRule.ranges.map((i) => ({
1594
- unitId: "",
1595
- sheetId: "",
1596
- range: i
1597
- })));
1598
- }
1599
- }, 20);
1600
- }
1199
+ debounceExecute(_univerjs_sheets_data_validation.UpdateSheetDataValidationSettingCommand.id, params, void 0);
1200
+ };
1201
+ const handleDelete = async () => {
1202
+ await commandService.executeCommand(_univerjs_sheets_data_validation.RemoveSheetDataValidationCommand.id, {
1203
+ ruleId,
1204
+ unitId,
1205
+ subUnitId
1601
1206
  });
1602
- return () => {
1603
- disposable.dispose();
1604
- if (timer !== void 0) clearTimeout(timer);
1605
- };
1606
- }, [
1607
- commandService,
1608
- dataValidationModel,
1609
- ruleId,
1610
- subUnitId,
1611
- unitId
1612
- ]);
1613
- const handleUpdateRuleRanges = (0, _univerjs_ui.useEvent)((rangeText) => {
1614
- const unitRanges = rangeText.split(",").filter(Boolean).map(_univerjs_engine_formula.deserializeRangeWithSheet).map((unitRange) => {
1615
- const sheetName = unitRange.sheetName;
1616
- if (sheetName) {
1617
- const sheetId = getSheetIdByName(univerInstanceService, unitRange.unitId, sheetName);
1618
- return {
1619
- ...unitRange,
1620
- sheetId
1621
- };
1622
- }
1623
- return {
1624
- ...unitRange,
1625
- sheetId: ""
1626
- };
1207
+ dataValidationPanelService.setActiveRule(null);
1208
+ goBackActiveRuleSheet();
1209
+ };
1210
+ const baseRule = {
1211
+ type: localRule.type,
1212
+ operator: localRule.operator,
1213
+ formula1: localRule.formula1,
1214
+ formula2: localRule.formula2,
1215
+ allowBlank: localRule.allowBlank
1216
+ };
1217
+ const handleChangeType = (newType) => {
1218
+ const validator = validatorService.getValidatorItem(newType);
1219
+ if (!validator) return;
1220
+ const operators = validator.operators;
1221
+ const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1222
+ const newRule = newType === (rule === null || rule === void 0 ? void 0 : rule.type) || newType.includes("list") && (rule === null || rule === void 0 ? void 0 : rule.type.includes("list")) ? {
1223
+ ...rule,
1224
+ type: newType
1225
+ } : {
1226
+ ...localRule,
1227
+ type: newType,
1228
+ operator: operators[0],
1229
+ formula1: void 0,
1230
+ formula2: void 0
1231
+ };
1232
+ setLocalRule(newRule);
1233
+ commandService.executeCommand(_univerjs_sheets_data_validation.UpdateSheetDataValidationSettingCommand.id, {
1234
+ unitId,
1235
+ subUnitId,
1236
+ ruleId: localRule.uid,
1237
+ setting: (0, _univerjs_data_validation.getRuleSetting)(newRule)
1627
1238
  });
1628
- if ((0, _univerjs_core.isUnitRangesEqual)(unitRanges, localRanges)) return;
1629
- setLocalRanges(unitRanges);
1630
- const ranges = unitRanges.filter((i) => (!i.unitId || i.unitId === unitId) && (!i.sheetId || i.sheetId === subUnitId)).map((i) => i.range);
1239
+ };
1240
+ const FormulaInput = componentManager.get(validator.formulaInput);
1241
+ const options = (0, _univerjs_data_validation.getRuleOptions)(localRule);
1242
+ const handleUpdateRuleOptions = (newOptions) => {
1243
+ if ((0, _univerjs_core.shallowEqual)(newOptions, (0, _univerjs_data_validation.getRuleOptions)(localRule))) return;
1631
1244
  setLocalRule({
1632
1245
  ...localRule,
1633
- ranges
1246
+ ...newOptions
1634
1247
  });
1635
- if (ranges.length === 0) return;
1636
- const params = {
1248
+ debounceExecute(_univerjs_sheets_data_validation.UpdateSheetDataValidationOptionsCommand.id, {
1637
1249
  unitId,
1638
1250
  subUnitId,
1639
1251
  ruleId,
1640
- ranges
1641
- };
1642
- debounceExecute(_univerjs_sheets_data_validation.UpdateSheetDataValidationRangeCommand.id, params);
1252
+ options: newOptions
1253
+ });
1254
+ };
1255
+ const shouldHideFormula = operators.length && !localRule.operator;
1256
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1257
+ "data-u-comp": "data-validation-detail",
1258
+ className: "univer-py-2",
1259
+ children: [
1260
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1261
+ label: localeService.t("sheets-data-validation-ui.panel.range"),
1262
+ error: !localRule.ranges.length || isRangeError ? localeService.t("sheets-data-validation-ui.panel.rangeError") : "",
1263
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_sheets_formula_ui.RangeSelector, {
1264
+ selectorRef: rangeSelectorInstance,
1265
+ unitId,
1266
+ subUnitId,
1267
+ initialValue: rangeStr,
1268
+ onChange: (doc, str) => {
1269
+ var _rangeSelectorInstanc3;
1270
+ if (!isFocusRangeSelector && ((_rangeSelectorInstanc3 = rangeSelectorInstance.current) === null || _rangeSelectorInstanc3 === void 0 ? void 0 : _rangeSelectorInstanc3.verify())) handleUpdateRuleRanges(str);
1271
+ },
1272
+ onFocusChange: (focusing, str) => {
1273
+ var _rangeSelectorInstanc4;
1274
+ setIsFocusRangeSelector(focusing);
1275
+ if (!focusing && str && ((_rangeSelectorInstanc4 = rangeSelectorInstance.current) === null || _rangeSelectorInstanc4 === void 0 ? void 0 : _rangeSelectorInstanc4.verify())) handleUpdateRuleRanges(str);
1276
+ },
1277
+ onVerify: (isValid) => setIsRangeError(!isValid)
1278
+ })
1279
+ }),
1280
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1281
+ label: localeService.t("sheets-data-validation-ui.panel.type"),
1282
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
1283
+ className: "univer-w-full",
1284
+ value: localRule.type,
1285
+ options: validators === null || validators === void 0 || (_validators$sort = validators.sort((a, b) => a.order - b.order)) === null || _validators$sort === void 0 ? void 0 : _validators$sort.map((validator) => ({
1286
+ label: localeService.t(validator.title),
1287
+ value: validator.id
1288
+ })),
1289
+ onChange: handleChangeType
1290
+ })
1291
+ }),
1292
+ (operators === null || operators === void 0 ? void 0 : operators.length) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1293
+ label: localeService.t("sheets-data-validation-ui.panel.operator"),
1294
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
1295
+ className: "univer-w-full",
1296
+ value: `${localRule.operator}`,
1297
+ options: [{
1298
+ value: "",
1299
+ label: localeService.t("sheets-data-validation-ui.operators.legal")
1300
+ }, ...operators.map((op, i) => ({
1301
+ value: `${op}`,
1302
+ label: operatorNames[i]
1303
+ }))],
1304
+ onChange: (operator) => {
1305
+ handleUpdateRuleSetting({
1306
+ ...baseRule,
1307
+ operator
1308
+ });
1309
+ }
1310
+ })
1311
+ }) : null,
1312
+ FormulaInput && !shouldHideFormula ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormulaInput, {
1313
+ isTwoFormula,
1314
+ value: {
1315
+ formula1: localRule.formula1,
1316
+ formula2: localRule.formula2
1317
+ },
1318
+ onChange: (value) => {
1319
+ handleUpdateRuleSetting({
1320
+ ...baseRule,
1321
+ ...value
1322
+ });
1323
+ },
1324
+ showError,
1325
+ validResult: validator.validatorFormula(localRule, unitId, subUnitId),
1326
+ unitId,
1327
+ subUnitId,
1328
+ ruleId
1329
+ }, key + localRule.type) : null,
1330
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
1331
+ checked: (_localRule$allowBlank = localRule.allowBlank) !== null && _localRule$allowBlank !== void 0 ? _localRule$allowBlank : true,
1332
+ onChange: () => {
1333
+ var _localRule$allowBlank2;
1334
+ return handleUpdateRuleSetting({
1335
+ ...baseRule,
1336
+ allowBlank: !((_localRule$allowBlank2 = localRule.allowBlank) !== null && _localRule$allowBlank2 !== void 0 ? _localRule$allowBlank2 : true)
1337
+ });
1338
+ },
1339
+ children: localeService.t("sheets-data-validation-ui.panel.allowBlank")
1340
+ }) }),
1341
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationOptions, {
1342
+ value: options,
1343
+ onChange: handleUpdateRuleOptions,
1344
+ extraComponent: validator.optionsInput
1345
+ }),
1346
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1347
+ className: "univer-mt-5 univer-flex univer-flex-row univer-justify-end",
1348
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
1349
+ className: "univer-ml-3",
1350
+ onClick: handleDelete,
1351
+ children: localeService.t("sheets-data-validation-ui.panel.removeRule")
1352
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
1353
+ className: "univer-ml-3",
1354
+ variant: "primary",
1355
+ onClick: handleOk,
1356
+ children: localeService.t("sheets-data-validation-ui.panel.done")
1357
+ })]
1358
+ })
1359
+ ]
1643
1360
  });
1644
- const rangeStr = (0, react.useMemo)(() => localRanges.map((i) => (0, _univerjs_engine_formula.serializeRange)(i.range)).join(","), []);
1645
- if (!validator) return null;
1646
- const operators = validator.operators;
1647
- const operatorNames = validator.operatorNames;
1648
- const isTwoFormula = localRule.operator ? _univerjs_data_validation.TWO_FORMULA_OPERATOR_COUNT.includes(localRule.operator) : false;
1649
- const goBackActiveRuleSheet = () => {
1650
- if ((worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId()) !== subUnitId) commandService.syncExecuteCommand(_univerjs_sheets.SetWorksheetActiveOperation.id, {
1361
+ }
1362
+
1363
+ //#endregion
1364
+ //#region src/views/components/DataValidationItem.tsx
1365
+ const DataValidationItem = (props) => {
1366
+ const { rule, onClick, unitId, subUnitId, disable } = props;
1367
+ const validatorRegistry = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidatorRegistryService);
1368
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
1369
+ const markSelectionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets_ui.IMarkSelectionService);
1370
+ const validator = validatorRegistry.getValidatorItem(rule.type);
1371
+ const ids = (0, react.useRef)(void 0);
1372
+ const [isHover, setIsHover] = (0, react.useState)(false);
1373
+ const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
1374
+ const style = (0, react.useMemo)(() => {
1375
+ var _themeService$getColo;
1376
+ const defaultColor = themeService.getColorFromTheme("primary.600");
1377
+ const key = themeService.getColorFromTheme("loop-color.2");
1378
+ const color = (_themeService$getColo = themeService.getColorFromTheme(key)) !== null && _themeService$getColo !== void 0 ? _themeService$getColo : defaultColor;
1379
+ const rgb = new _univerjs_core.ColorKit(color).toRgb();
1380
+ return {
1381
+ fill: `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, 0.1)`,
1382
+ stroke: color
1383
+ };
1384
+ }, [(0, _univerjs_ui.useObservable)(themeService.currentTheme$)]);
1385
+ const handleDelete = (e) => {
1386
+ commandService.executeCommand(_univerjs_sheets_data_validation.RemoveSheetDataValidationCommand.id, {
1387
+ ruleId: rule.uid,
1651
1388
  unitId,
1652
1389
  subUnitId
1653
1390
  });
1391
+ e.stopPropagation();
1654
1392
  };
1655
- const handleOk = () => {
1656
- var _rangeSelectorInstanc;
1657
- if ((_rangeSelectorInstanc = rangeSelectorInstance.current) === null || _rangeSelectorInstanc === void 0 || (_rangeSelectorInstanc = _rangeSelectorInstanc.editor) === null || _rangeSelectorInstanc === void 0 ? void 0 : _rangeSelectorInstanc.isFocus()) {
1658
- var _rangeSelectorInstanc2;
1659
- handleUpdateRuleRanges((_rangeSelectorInstanc2 = rangeSelectorInstance.current) === null || _rangeSelectorInstanc2 === void 0 ? void 0 : _rangeSelectorInstanc2.getValue());
1660
- }
1661
- if (!localRule.ranges.length || isRangeError) return;
1662
- if (validator.validatorFormula(localRule, unitId, subUnitId).success) dataValidationPanelService.setActiveRule(null);
1663
- else setShowError(true);
1664
- goBackActiveRuleSheet();
1665
- };
1666
- const handleUpdateRuleSetting = (setting) => {
1667
- if ((0, _univerjs_core.shallowEqual)(setting, (0, _univerjs_data_validation.getRuleSetting)(localRule))) return;
1668
- setLocalRule({
1669
- ...localRule,
1670
- ...setting
1671
- });
1393
+ (0, react.useEffect)(() => {
1394
+ return () => {
1395
+ if (ids.current) {
1396
+ var _ids$current;
1397
+ (_ids$current = ids.current) === null || _ids$current === void 0 || _ids$current.forEach((id) => {
1398
+ id && markSelectionService.removeShape(id);
1399
+ });
1400
+ }
1401
+ };
1402
+ }, [markSelectionService]);
1403
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1404
+ className: (0, _univerjs_design.clsx)("univer-bg-secondary univer-relative univer--mx-2 univer-box-border univer-flex univer-w-[287px] univer-cursor-pointer univer-flex-col univer-justify-between univer-overflow-hidden univer-rounded-md univer-p-2 univer-pr-9", {
1405
+ "hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700": !disable,
1406
+ "univer-opacity-50": disable
1407
+ }),
1408
+ onClick,
1409
+ onMouseEnter: () => {
1410
+ if (disable) return;
1411
+ setIsHover(true);
1412
+ ids.current = rule.ranges.map((range) => markSelectionService.addShape({
1413
+ range,
1414
+ style,
1415
+ primary: null
1416
+ }));
1417
+ },
1418
+ onMouseLeave: () => {
1419
+ var _ids$current2;
1420
+ setIsHover(false);
1421
+ (_ids$current2 = ids.current) === null || _ids$current2 === void 0 || _ids$current2.forEach((id) => {
1422
+ id && markSelectionService.removeShape(id);
1423
+ });
1424
+ ids.current = void 0;
1425
+ },
1426
+ children: [
1427
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1428
+ className: "univer-truncate univer-text-sm univer-font-medium univer-leading-[22px] univer-text-gray-900 dark:!univer-text-white",
1429
+ children: validator === null || validator === void 0 ? void 0 : validator.generateRuleName(rule)
1430
+ }),
1431
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1432
+ className: "univer-text-secondary univer-truncate univer-text-xs univer-leading-[18px] dark:!univer-text-gray-300",
1433
+ children: rule.ranges.map((range) => (0, _univerjs_engine_formula.serializeRange)(range)).join(",")
1434
+ }),
1435
+ isHover && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1436
+ className: "univer-absolute univer-right-2 univer-top-[19px] univer-flex univer-size-5 univer-items-center univer-justify-center univer-rounded hover:univer-bg-gray-200 dark:!univer-text-gray-300 dark:hover:!univer-bg-gray-700",
1437
+ onClick: handleDelete,
1438
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, {})
1439
+ })
1440
+ ]
1441
+ });
1442
+ };
1443
+
1444
+ //#endregion
1445
+ //#region src/views/components/DataValidationList.tsx
1446
+ function DataValidationList(props) {
1447
+ const sheetDataValidationModel = (0, _univerjs_ui.useDependency)(_univerjs_sheets_data_validation.SheetDataValidationModel);
1448
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
1449
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
1450
+ const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
1451
+ const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
1452
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1453
+ const { workbook } = props;
1454
+ const worksheet = (0, _univerjs_ui.useObservable)(workbook.activeSheet$, void 0, true);
1455
+ const unitId = workbook.getUnitId();
1456
+ const subUnitId = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId();
1457
+ const rules = (0, _univerjs_ui.useObservable)(() => sheetDataValidationModel.ruleChange$.pipe((0, rxjs.filter)((change) => change.unitId === unitId && change.subUnitId === subUnitId), (0, rxjs.map)(() => sheetDataValidationModel.getRules(unitId, subUnitId)), (0, rxjs.startWith)(sheetDataValidationModel.getRules(unitId, subUnitId))), [], false, [
1458
+ sheetDataValidationModel,
1459
+ subUnitId,
1460
+ unitId
1461
+ ]);
1462
+ const handleAddRule = async () => {
1463
+ const rule = (0, _univerjs_sheets_data_validation.createDefaultNewRule)(injector);
1672
1464
  const params = {
1673
1465
  unitId,
1674
1466
  subUnitId,
1675
- ruleId,
1676
- setting
1467
+ rule
1677
1468
  };
1678
- debounceExecute(_univerjs_sheets_data_validation.UpdateSheetDataValidationSettingCommand.id, params, void 0);
1679
- };
1680
- const handleDelete = async () => {
1681
- await commandService.executeCommand(_univerjs_sheets_data_validation.RemoveSheetDataValidationCommand.id, {
1682
- ruleId,
1469
+ await commandService.executeCommand(_univerjs_sheets_data_validation.AddSheetDataValidationCommand.id, params);
1470
+ dataValidationPanelService.setActiveRule({
1683
1471
  unitId,
1684
- subUnitId
1472
+ subUnitId,
1473
+ rule
1685
1474
  });
1686
- dataValidationPanelService.setActiveRule(null);
1687
- goBackActiveRuleSheet();
1688
- };
1689
- const baseRule = {
1690
- type: localRule.type,
1691
- operator: localRule.operator,
1692
- formula1: localRule.formula1,
1693
- formula2: localRule.formula2,
1694
- allowBlank: localRule.allowBlank
1695
1475
  };
1696
- const handleChangeType = (newType) => {
1697
- const validator = validatorService.getValidatorItem(newType);
1698
- if (!validator) return;
1699
- const operators = validator.operators;
1700
- const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1701
- const newRule = newType === (rule === null || rule === void 0 ? void 0 : rule.type) || newType.includes("list") && (rule === null || rule === void 0 ? void 0 : rule.type.includes("list")) ? {
1702
- ...rule,
1703
- type: newType
1704
- } : {
1705
- ...localRule,
1706
- type: newType,
1707
- operator: operators[0],
1708
- formula1: void 0,
1709
- formula2: void 0
1710
- };
1711
- setLocalRule(newRule);
1712
- commandService.executeCommand(_univerjs_sheets_data_validation.UpdateSheetDataValidationSettingCommand.id, {
1476
+ const handleRemoveAll = () => {
1477
+ commandService.executeCommand(_univerjs_sheets_data_validation.RemoveSheetAllDataValidationCommand.id, {
1713
1478
  unitId,
1714
- subUnitId,
1715
- ruleId: localRule.uid,
1716
- setting: (0, _univerjs_data_validation.getRuleSetting)(newRule)
1479
+ subUnitId
1717
1480
  });
1718
1481
  };
1719
- const FormulaInput = componentManager.get(validator.formulaInput);
1720
- const options = (0, _univerjs_data_validation.getRuleOptions)(localRule);
1721
- const handleUpdateRuleOptions = (newOptions) => {
1722
- if ((0, _univerjs_core.shallowEqual)(newOptions, (0, _univerjs_data_validation.getRuleOptions)(localRule))) return;
1723
- setLocalRule({
1724
- ...localRule,
1725
- ...newOptions
1726
- });
1727
- debounceExecute(_univerjs_sheets_data_validation.UpdateSheetDataValidationOptionsCommand.id, {
1728
- unitId,
1729
- subUnitId,
1730
- ruleId,
1731
- options: newOptions
1482
+ const getDvRulesByPermissionCorrect = (rules) => {
1483
+ const workbook = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
1484
+ const worksheet = workbook.getActiveSheet();
1485
+ const unitId = workbook.getUnitId();
1486
+ const subUnitId = worksheet.getSheetId();
1487
+ return rules.map((rule) => {
1488
+ if ((0, _univerjs_sheets.checkRangesEditablePermission)(injector, unitId, subUnitId, rule.ranges)) return { ...rule };
1489
+ else return {
1490
+ ...rule,
1491
+ disable: true
1492
+ };
1732
1493
  });
1733
1494
  };
1734
- const shouldHideFormula = operators.length && !localRule.operator;
1495
+ const rulesByPermissionCheck = getDvRulesByPermissionCorrect(rules);
1496
+ const hasDisableRule = rulesByPermissionCheck === null || rulesByPermissionCheck === void 0 ? void 0 : rulesByPermissionCheck.some((rule) => rule.disable);
1735
1497
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1736
- "data-u-comp": "data-validation-detail",
1737
- className: "univer-py-2",
1738
- children: [
1739
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1740
- label: localeService.t("sheets-data-validation-ui.panel.range"),
1741
- error: !localRule.ranges.length || isRangeError ? localeService.t("sheets-data-validation-ui.panel.rangeError") : "",
1742
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_sheets_formula_ui.RangeSelector, {
1743
- selectorRef: rangeSelectorInstance,
1744
- unitId,
1745
- subUnitId,
1746
- initialValue: rangeStr,
1747
- onChange: (doc, str) => {
1748
- var _rangeSelectorInstanc3;
1749
- if (!isFocusRangeSelector && ((_rangeSelectorInstanc3 = rangeSelectorInstance.current) === null || _rangeSelectorInstanc3 === void 0 ? void 0 : _rangeSelectorInstanc3.verify())) handleUpdateRuleRanges(str);
1750
- },
1751
- onFocusChange: (focusing, str) => {
1752
- var _rangeSelectorInstanc4;
1753
- setIsFocusRangeSelector(focusing);
1754
- if (!focusing && str && ((_rangeSelectorInstanc4 = rangeSelectorInstance.current) === null || _rangeSelectorInstanc4 === void 0 ? void 0 : _rangeSelectorInstanc4.verify())) handleUpdateRuleRanges(str);
1755
- },
1756
- onVerify: (isValid) => setIsRangeError(!isValid)
1757
- })
1758
- }),
1759
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1760
- label: localeService.t("sheets-data-validation-ui.panel.type"),
1761
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
1762
- className: "univer-w-full",
1763
- value: localRule.type,
1764
- options: validators === null || validators === void 0 || (_validators$sort = validators.sort((a, b) => a.order - b.order)) === null || _validators$sort === void 0 ? void 0 : _validators$sort.map((validator) => ({
1765
- label: localeService.t(validator.title),
1766
- value: validator.id
1767
- })),
1768
- onChange: handleChangeType
1769
- })
1770
- }),
1771
- (operators === null || operators === void 0 ? void 0 : operators.length) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1772
- label: localeService.t("sheets-data-validation-ui.panel.operator"),
1773
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
1774
- className: "univer-w-full",
1775
- value: `${localRule.operator}`,
1776
- options: [{
1777
- value: "",
1778
- label: localeService.t("sheets-data-validation-ui.operators.legal")
1779
- }, ...operators.map((op, i) => ({
1780
- value: `${op}`,
1781
- label: operatorNames[i]
1782
- }))],
1783
- onChange: (operator) => {
1784
- handleUpdateRuleSetting({
1785
- ...baseRule,
1786
- operator
1787
- });
1788
- }
1789
- })
1790
- }) : null,
1791
- FormulaInput && !shouldHideFormula ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormulaInput, {
1792
- isTwoFormula,
1793
- value: {
1794
- formula1: localRule.formula1,
1795
- formula2: localRule.formula2
1796
- },
1797
- onChange: (value) => {
1798
- handleUpdateRuleSetting({
1799
- ...baseRule,
1800
- ...value
1801
- });
1802
- },
1803
- showError,
1804
- validResult: validator.validatorFormula(localRule, unitId, subUnitId),
1498
+ className: "univer-pb-4",
1499
+ children: [rulesByPermissionCheck === null || rulesByPermissionCheck === void 0 ? void 0 : rulesByPermissionCheck.map((rule) => {
1500
+ var _rule$disable;
1501
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationItem, {
1805
1502
  unitId,
1806
1503
  subUnitId,
1807
- ruleId
1808
- }, key + localRule.type) : null,
1809
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
1810
- checked: (_localRule$allowBlank = localRule.allowBlank) !== null && _localRule$allowBlank !== void 0 ? _localRule$allowBlank : true,
1811
- onChange: () => {
1812
- var _localRule$allowBlank2;
1813
- return handleUpdateRuleSetting({
1814
- ...baseRule,
1815
- allowBlank: !((_localRule$allowBlank2 = localRule.allowBlank) !== null && _localRule$allowBlank2 !== void 0 ? _localRule$allowBlank2 : true)
1504
+ onClick: () => {
1505
+ if (rule.disable) return;
1506
+ dataValidationPanelService.setActiveRule({
1507
+ unitId,
1508
+ subUnitId,
1509
+ rule
1510
+ });
1511
+ },
1512
+ rule,
1513
+ disable: (_rule$disable = rule.disable) !== null && _rule$disable !== void 0 ? _rule$disable : false
1514
+ }, rule.uid);
1515
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1516
+ className: "univer-mt-4 univer-flex univer-flex-row univer-justify-end univer-gap-2",
1517
+ children: [rules.length && !hasDisableRule ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
1518
+ onClick: handleRemoveAll,
1519
+ children: localeService.t("sheets-data-validation-ui.panel.removeAll")
1520
+ }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
1521
+ variant: "primary",
1522
+ onClick: handleAddRule,
1523
+ children: localeService.t("sheets-data-validation-ui.panel.add")
1524
+ })]
1525
+ })]
1526
+ });
1527
+ }
1528
+
1529
+ //#endregion
1530
+ //#region src/views/components/DataValidationPanel.tsx
1531
+ const DataValidationPanel = () => {
1532
+ const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
1533
+ const activeRule = (0, _univerjs_ui.useObservable)(dataValidationPanelService.activeRule$, dataValidationPanelService.activeRule);
1534
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
1535
+ const workbook = (0, _univerjs_ui.useObservable)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), void 0, void 0, []);
1536
+ const worksheet = (0, _univerjs_ui.useObservable)(() => {
1537
+ var _workbook$activeSheet;
1538
+ return (_workbook$activeSheet = workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) !== null && _workbook$activeSheet !== void 0 ? _workbook$activeSheet : (0, rxjs.of)(null);
1539
+ }, void 0, void 0, []);
1540
+ if (!workbook || !worksheet) return null;
1541
+ return activeRule && (activeRule.subUnitId === worksheet.getSheetId() || activeRule.subUnitId === dataValidationPanelService.getFocusFormulaEditorActiveRuleSubUnitId()) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationDetail, {}, activeRule.rule.uid) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationList, { workbook });
1542
+ };
1543
+
1544
+ //#endregion
1545
+ //#region src/views/components/DateShowTimeOption.tsx
1546
+ const DATE_SHOW_TIME_OPTION = "DATE_SHOW_TIME_OPTION";
1547
+ function DateShowTimeOption(props) {
1548
+ var _value$bizInfo;
1549
+ const { value, onChange } = props;
1550
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1551
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
1552
+ checked: (_value$bizInfo = value.bizInfo) === null || _value$bizInfo === void 0 ? void 0 : _value$bizInfo.showTime,
1553
+ onChange: (showTime) => {
1554
+ onChange({
1555
+ ...value,
1556
+ bizInfo: {
1557
+ ...value.bizInfo,
1558
+ showTime
1559
+ }
1560
+ });
1561
+ },
1562
+ children: localeService.t("sheets-data-validation-ui.showTime.label")
1563
+ }) });
1564
+ }
1565
+ DateShowTimeOption.componentKey = DATE_SHOW_TIME_OPTION;
1566
+
1567
+ //#endregion
1568
+ //#region src/views/components/formula-input/BaseFormulaInput.tsx
1569
+ const BaseFormulaInput = (props) => {
1570
+ const { isTwoFormula = false, value, onChange, showError, validResult } = props;
1571
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1572
+ const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : "";
1573
+ const formula2Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula2 : "";
1574
+ if (isTwoFormula) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1575
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1576
+ error: formula1Res,
1577
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
1578
+ className: "univer-w-full",
1579
+ placeholder: localeService.t("sheets-data-validation-ui.panel.formulaPlaceholder"),
1580
+ value: value === null || value === void 0 ? void 0 : value.formula1,
1581
+ onChange: (newValue) => {
1582
+ onChange === null || onChange === void 0 || onChange({
1583
+ ...value,
1584
+ formula1: newValue
1585
+ });
1586
+ }
1587
+ })
1588
+ }),
1589
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1590
+ className: "-univer-mt-2 univer-mb-1 univer-text-sm univer-text-gray-400",
1591
+ children: localeService.t("sheets-data-validation-ui.panel.formulaAnd")
1592
+ }),
1593
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1594
+ error: formula2Res,
1595
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
1596
+ className: "univer-w-full",
1597
+ placeholder: localeService.t("sheets-data-validation-ui.panel.formulaPlaceholder"),
1598
+ value: value === null || value === void 0 ? void 0 : value.formula2,
1599
+ onChange: (newValue) => {
1600
+ onChange === null || onChange === void 0 || onChange({
1601
+ ...value,
1602
+ formula2: newValue
1816
1603
  });
1817
- },
1818
- children: localeService.t("sheets-data-validation-ui.panel.allowBlank")
1819
- }) }),
1820
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationOptions, {
1821
- value: options,
1822
- onChange: handleUpdateRuleOptions,
1823
- extraComponent: validator.optionsInput
1824
- }),
1825
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1826
- className: "univer-mt-5 univer-flex univer-flex-row univer-justify-end",
1827
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
1828
- className: "univer-ml-3",
1829
- onClick: handleDelete,
1830
- children: localeService.t("sheets-data-validation-ui.panel.removeRule")
1831
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
1832
- className: "univer-ml-3",
1833
- variant: "primary",
1834
- onClick: handleOk,
1835
- children: localeService.t("sheets-data-validation-ui.panel.done")
1836
- })]
1604
+ }
1837
1605
  })
1838
- ]
1606
+ })
1607
+ ] });
1608
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1609
+ error: formula1Res,
1610
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
1611
+ className: "univer-w-full",
1612
+ placeholder: localeService.t("sheets-data-validation-ui.panel.formulaPlaceholder"),
1613
+ value: value === null || value === void 0 ? void 0 : value.formula1,
1614
+ onChange: (newValue) => {
1615
+ onChange === null || onChange === void 0 || onChange({ formula1: newValue });
1616
+ }
1617
+ })
1839
1618
  });
1619
+ };
1620
+
1621
+ //#endregion
1622
+ //#region src/views/components/formula-input/CheckboxFormulaInput.tsx
1623
+ function CheckboxFormulaInput(props) {
1624
+ const { value, onChange, showError, validResult } = props;
1625
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1626
+ const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : "";
1627
+ const formula2Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula2 : "";
1628
+ const [checked, setChecked] = (0, react.useState)(!((value === null || value === void 0 ? void 0 : value.formula1) === void 0 && (value === null || value === void 0 ? void 0 : value.formula2) === void 0));
1629
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1630
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
1631
+ checked,
1632
+ onChange: (newValue) => {
1633
+ if (newValue) setChecked(true);
1634
+ else {
1635
+ setChecked(false);
1636
+ onChange === null || onChange === void 0 || onChange({
1637
+ ...value,
1638
+ formula1: void 0,
1639
+ formula2: void 0
1640
+ });
1641
+ }
1642
+ },
1643
+ children: localeService.t("sheets-data-validation-ui.checkbox.tips")
1644
+ }) }),
1645
+ checked ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1646
+ label: localeService.t("sheets-data-validation-ui.checkbox.checked"),
1647
+ error: formula1Res,
1648
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
1649
+ className: "univer-w-full",
1650
+ placeholder: localeService.t("sheets-data-validation-ui.panel.valuePlaceholder"),
1651
+ value: value === null || value === void 0 ? void 0 : value.formula1,
1652
+ onChange: (newValue) => {
1653
+ onChange === null || onChange === void 0 || onChange({
1654
+ ...value,
1655
+ formula1: newValue || void 0
1656
+ });
1657
+ }
1658
+ })
1659
+ }) : null,
1660
+ checked ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1661
+ label: localeService.t("sheets-data-validation-ui.checkbox.unchecked"),
1662
+ error: formula2Res,
1663
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
1664
+ className: "univer-w-full",
1665
+ placeholder: localeService.t("sheets-data-validation-ui.panel.valuePlaceholder"),
1666
+ value: value === null || value === void 0 ? void 0 : value.formula2,
1667
+ onChange: (newValue) => {
1668
+ onChange === null || onChange === void 0 || onChange({
1669
+ ...value,
1670
+ formula2: newValue || void 0
1671
+ });
1672
+ }
1673
+ })
1674
+ }) : null
1675
+ ] });
1840
1676
  }
1841
1677
 
1842
1678
  //#endregion
1843
- //#region src/views/components/DataValidationItem.tsx
1844
- const DataValidationItem = (props) => {
1845
- const { rule, onClick, unitId, subUnitId, disable } = props;
1846
- const validatorRegistry = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidatorRegistryService);
1847
- const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
1848
- const markSelectionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets_ui.IMarkSelectionService);
1849
- const validator = validatorRegistry.getValidatorItem(rule.type);
1850
- const ids = (0, react.useRef)(void 0);
1851
- const [isHover, setIsHover] = (0, react.useState)(false);
1852
- const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
1853
- const style = (0, react.useMemo)(() => {
1854
- var _themeService$getColo;
1855
- const defaultColor = themeService.getColorFromTheme("primary.600");
1856
- const key = themeService.getColorFromTheme("loop-color.2");
1857
- const color = (_themeService$getColo = themeService.getColorFromTheme(key)) !== null && _themeService$getColo !== void 0 ? _themeService$getColo : defaultColor;
1858
- const rgb = new _univerjs_core.ColorKit(color).toRgb();
1859
- return {
1860
- fill: `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, 0.1)`,
1861
- stroke: color
1862
- };
1863
- }, [(0, _univerjs_ui.useObservable)(themeService.currentTheme$)]);
1864
- const handleDelete = (e) => {
1865
- commandService.executeCommand(_univerjs_sheets_data_validation.RemoveSheetDataValidationCommand.id, {
1866
- ruleId: rule.uid,
1679
+ //#region src/views/components/formula-input/CustomFormulaInput.tsx
1680
+ function CustomFormulaInput(props) {
1681
+ var _value$formula;
1682
+ const { unitId, subUnitId, value, onChange, showError, validResult } = props;
1683
+ const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : void 0;
1684
+ const formulaEditorRef = (0, react.useRef)(null);
1685
+ const [isFocusFormulaEditor, setIsFocusFormulaEditor] = (0, react.useState)(false);
1686
+ (0, _univerjs_ui.useSidebarClick)((e) => {
1687
+ var _formulaEditorRef$cur;
1688
+ !((_formulaEditorRef$cur = formulaEditorRef.current) === null || _formulaEditorRef$cur === void 0) && _formulaEditorRef$cur.isClickOutSide(e) && setIsFocusFormulaEditor(false);
1689
+ });
1690
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1691
+ error: formula1Res,
1692
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_sheets_formula_ui.FormulaEditor, {
1693
+ ref: formulaEditorRef,
1694
+ className: (0, _univerjs_design.clsx)("univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent", _univerjs_design.borderClassName),
1695
+ initValue: (_value$formula = value === null || value === void 0 ? void 0 : value.formula1) !== null && _value$formula !== void 0 ? _value$formula : "=",
1867
1696
  unitId,
1868
- subUnitId
1869
- });
1870
- e.stopPropagation();
1871
- };
1872
- (0, react.useEffect)(() => {
1873
- return () => {
1874
- if (ids.current) {
1875
- var _ids$current;
1876
- (_ids$current = ids.current) === null || _ids$current === void 0 || _ids$current.forEach((id) => {
1877
- id && markSelectionService.removeShape(id);
1697
+ subUnitId,
1698
+ isFocus: isFocusFormulaEditor,
1699
+ isSupportAcrossSheet: true,
1700
+ onChange: (newValue) => {
1701
+ const newFormula = (newValue !== null && newValue !== void 0 ? newValue : "").trim();
1702
+ if (newFormula === (value === null || value === void 0 ? void 0 : value.formula1)) return;
1703
+ onChange === null || onChange === void 0 || onChange({
1704
+ ...value,
1705
+ formula1: newFormula
1878
1706
  });
1879
- }
1880
- };
1881
- }, [markSelectionService]);
1882
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1883
- className: (0, _univerjs_design.clsx)("univer-bg-secondary univer-relative univer--mx-2 univer-box-border univer-flex univer-w-[287px] univer-cursor-pointer univer-flex-col univer-justify-between univer-overflow-hidden univer-rounded-md univer-p-2 univer-pr-9", {
1884
- "hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700": !disable,
1885
- "univer-opacity-50": disable
1886
- }),
1887
- onClick,
1888
- onMouseEnter: () => {
1889
- if (disable) return;
1890
- setIsHover(true);
1891
- ids.current = rule.ranges.map((range) => markSelectionService.addShape({
1892
- range,
1893
- style,
1894
- primary: null
1895
- }));
1896
- },
1897
- onMouseLeave: () => {
1898
- var _ids$current2;
1899
- setIsHover(false);
1900
- (_ids$current2 = ids.current) === null || _ids$current2 === void 0 || _ids$current2.forEach((id) => {
1901
- id && markSelectionService.removeShape(id);
1902
- });
1903
- ids.current = void 0;
1904
- },
1707
+ },
1708
+ onFocus: () => setIsFocusFormulaEditor(true)
1709
+ })
1710
+ });
1711
+ }
1712
+
1713
+ //#endregion
1714
+ //#region src/views/components/formula-input/utils.ts
1715
+ /**
1716
+ * Copyright 2023-present DreamNum Co., Ltd.
1717
+ *
1718
+ * Licensed under the Apache License, Version 2.0 (the "License");
1719
+ * you may not use this file except in compliance with the License.
1720
+ * You may obtain a copy of the License at
1721
+ *
1722
+ * http://www.apache.org/licenses/LICENSE-2.0
1723
+ *
1724
+ * Unless required by applicable law or agreed to in writing, software
1725
+ * distributed under the License is distributed on an "AS IS" BASIS,
1726
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1727
+ * See the License for the specific language governing permissions and
1728
+ * limitations under the License.
1729
+ */
1730
+ function buildCustomListFormulaPayload(items, defaultColor) {
1731
+ const labelSet = /* @__PURE__ */ new Set();
1732
+ const finalList = [];
1733
+ items.forEach((item) => {
1734
+ if (!item.label || labelSet.has(item.label)) return;
1735
+ labelSet.add(item.label);
1736
+ finalList.push(item);
1737
+ });
1738
+ return {
1739
+ formula1: (0, _univerjs_sheets.serializeListOptions)(finalList.map((item) => item.label)),
1740
+ formula2: finalList.map((item) => item.color === defaultColor ? "" : item.color).join(",")
1741
+ };
1742
+ }
1743
+
1744
+ //#endregion
1745
+ //#region src/views/components/formula-input/ListFormulaInput.tsx
1746
+ const DEFAULT_COLOR_PRESET = [
1747
+ "#FFFFFF",
1748
+ "#FEE7E7",
1749
+ "#FEF0E6",
1750
+ "#EFFBD0",
1751
+ "#E4F4FE",
1752
+ "#E8ECFD",
1753
+ "#F1EAFA",
1754
+ "#FDE8F3",
1755
+ "#E5E5E5",
1756
+ "#FDCECE",
1757
+ "#FDC49B",
1758
+ "#DEF6A2",
1759
+ "#9FDAFF",
1760
+ "#D0D9FB",
1761
+ "#E3D5F6",
1762
+ "#FBD0E8",
1763
+ "#656565",
1764
+ "#FE4B4B",
1765
+ "#FF8C51",
1766
+ "#8BBB11",
1767
+ "#0B9EFB",
1768
+ "#3A60F7",
1769
+ "#9E6DE3",
1770
+ "#F248A6"
1771
+ ];
1772
+ const ColorSelect = (props) => {
1773
+ const { value, onChange, disabled } = props;
1774
+ const [open, setOpen] = (0, react.useState)(false);
1775
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
1776
+ align: "start",
1777
+ disabled,
1778
+ open,
1779
+ onOpenChange: setOpen,
1780
+ overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1781
+ className: "univer-box-border univer-grid univer-w-fit univer-grid-cols-6 univer-flex-wrap univer-gap-2 univer-p-1.5",
1782
+ children: DEFAULT_COLOR_PRESET.map((color) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1783
+ className: (0, _univerjs_design.clsx)("univer-box-border univer-size-4 univer-cursor-pointer univer-rounded", _univerjs_design.borderClassName),
1784
+ style: { background: color },
1785
+ onClick: () => {
1786
+ onChange(color);
1787
+ setOpen(false);
1788
+ }
1789
+ }, color))
1790
+ }),
1791
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1792
+ className: (0, _univerjs_design.clsx)("univer-box-border univer-inline-flex univer-h-8 univer-w-16 univer-cursor-pointer univer-items-center univer-justify-between univer-gap-2 univer-rounded-lg univer-bg-white univer-px-2.5 univer-transition-colors univer-duration-200 hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white", _univerjs_design.borderClassName),
1793
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1794
+ className: "univer-box-border univer-size-4 univer-rounded univer-text-base",
1795
+ style: { background: value }
1796
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, {})]
1797
+ })
1798
+ });
1799
+ };
1800
+ const Template = (props) => {
1801
+ const { item, commonProps, className } = props;
1802
+ const { onItemChange, onItemDelete } = commonProps;
1803
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1804
+ className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-gap-2", className),
1905
1805
  children: [
1906
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1907
- className: "univer-truncate univer-text-sm univer-font-medium univer-leading-[22px] univer-text-gray-900 dark:!univer-text-white",
1908
- children: validator === null || validator === void 0 ? void 0 : validator.generateRuleName(rule)
1806
+ !item.isRef && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1807
+ className: (0, _univerjs_design.clsx)("univer-cursor-move", "draggableHandle"),
1808
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.GripVerticalIcon, {})
1909
1809
  }),
1910
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1911
- className: "univer-text-secondary univer-truncate univer-text-xs univer-leading-[18px] dark:!univer-text-gray-300",
1912
- children: rule.ranges.map((range) => (0, _univerjs_engine_formula.serializeRange)(range)).join(",")
1810
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ColorSelect, {
1811
+ value: item.color,
1812
+ onChange: (color) => {
1813
+ onItemChange(item.id, item.label, color);
1814
+ }
1913
1815
  }),
1914
- isHover && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1915
- className: "univer-absolute univer-right-2 univer-top-[19px] univer-flex univer-size-5 univer-items-center univer-justify-center univer-rounded hover:univer-bg-gray-200 dark:!univer-text-gray-300 dark:hover:!univer-bg-gray-700",
1916
- onClick: handleDelete,
1917
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, {})
1816
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
1817
+ disabled: item.isRef,
1818
+ value: item.label,
1819
+ onChange: (label) => {
1820
+ onItemChange(item.id, label, item.color);
1821
+ }
1822
+ }),
1823
+ item.isRef ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1824
+ className: "univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base hover:univer-bg-gray-200",
1825
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, { onClick: () => onItemDelete(item.id) })
1918
1826
  })
1919
1827
  ]
1920
1828
  });
1921
1829
  };
1922
-
1923
- //#endregion
1924
- //#region src/views/components/DataValidationList.tsx
1925
- function DataValidationList(props) {
1926
- const sheetDataValidationModel = (0, _univerjs_ui.useDependency)(_univerjs_sheets_data_validation.SheetDataValidationModel);
1927
- const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
1928
- const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
1929
- const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
1930
- const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
1830
+ const NOOP = () => {};
1831
+ function ListFormulaInput(props) {
1832
+ const { value, onChange: _onChange = NOOP, unitId, subUnitId, validResult, showError, ruleId } = props;
1833
+ const { formula1 = "", formula2 = "" } = value || {};
1834
+ const [isFormulaStr, setIsFormulaStr] = (0, react.useState)(() => (0, _univerjs_core.isFormulaString)(formula1) ? "1" : "0");
1835
+ const [formulaStr, setFormulaStr] = (0, react.useState)(isFormulaStr === "1" ? formula1 : "=");
1836
+ const [formulaStrCopy, setFormulaStrCopy] = (0, react.useState)(isFormulaStr === "1" ? formula1 : "=");
1931
1837
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1932
- const [rules, setRules] = (0, react.useState)([]);
1933
- const { workbook } = props;
1934
- const worksheet = (0, _univerjs_ui.useObservable)(workbook.activeSheet$, void 0, true);
1935
- const unitId = workbook.getUnitId();
1936
- const subUnitId = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId();
1838
+ const dataValidatorRegistryService = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidatorRegistryService);
1839
+ const dataValidationModel = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidationModel);
1840
+ const dataValidationFormulaController = (0, _univerjs_ui.useDependency)(_univerjs_sheets_data_validation.DataValidationFormulaController);
1841
+ const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
1842
+ const [refColors, setRefColors] = (0, react.useState)(() => formula2.split(","));
1843
+ const listValidator = dataValidatorRegistryService.getValidatorItem(_univerjs_core.DataValidationType.LIST);
1844
+ const [refOptions, setRefOptions] = (0, react.useState)([]);
1845
+ const [localError, setLocalError] = (0, react.useState)("");
1846
+ const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : "";
1847
+ const ruleChange = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => dataValidationModel.ruleChange$.pipe((0, rxjs.debounceTime)(16)), []));
1848
+ const onChange = (0, _univerjs_ui.useEvent)(_onChange);
1937
1849
  (0, react.useEffect)(() => {
1938
- setRules(sheetDataValidationModel.getRules(unitId, subUnitId));
1939
- const subscription = sheetDataValidationModel.ruleChange$.subscribe((change) => {
1940
- if (change.unitId === unitId && change.subUnitId === subUnitId) setRules(sheetDataValidationModel.getRules(unitId, subUnitId));
1941
- });
1850
+ let cancelled = false;
1851
+ const timer = setTimeout(() => {
1852
+ const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1853
+ if ((0, _univerjs_core.isFormulaString)(rule === null || rule === void 0 ? void 0 : rule.formula1) && listValidator && rule) listValidator.getListAsync(rule, unitId, subUnitId).then((options) => {
1854
+ if (!cancelled) setRefOptions(options);
1855
+ });
1856
+ }, 100);
1942
1857
  return () => {
1943
- subscription.unsubscribe();
1858
+ cancelled = true;
1859
+ clearTimeout(timer);
1944
1860
  };
1945
1861
  }, [
1946
- unitId,
1862
+ dataValidationModel,
1863
+ ruleChange,
1864
+ listValidator,
1865
+ ruleId,
1947
1866
  subUnitId,
1948
- sheetDataValidationModel
1867
+ unitId
1949
1868
  ]);
1950
- const handleAddRule = async () => {
1951
- const rule = (0, _univerjs_sheets_data_validation.createDefaultNewRule)(injector);
1952
- const params = {
1953
- unitId,
1954
- subUnitId,
1955
- rule
1956
- };
1957
- await commandService.executeCommand(_univerjs_sheets_data_validation.AddSheetDataValidationCommand.id, params);
1958
- dataValidationPanelService.setActiveRule({
1959
- unitId,
1960
- subUnitId,
1961
- rule
1962
- });
1869
+ (0, react.useEffect)(() => {
1870
+ if ((0, _univerjs_core.isFormulaString)(formula1) && formula1 !== formulaStrCopy) {
1871
+ setFormulaStr(formula1);
1872
+ setFormulaStrCopy(formula1);
1873
+ }
1874
+ }, [formulaStrCopy, formula1]);
1875
+ const [strList, setStrList] = (0, react.useState)(() => {
1876
+ const strOptions = isFormulaStr !== "1" ? (0, _univerjs_sheets.deserializeListOptions)(formula1) : [];
1877
+ const strColors = formula2.split(",");
1878
+ return strOptions.map((label, i) => ({
1879
+ label,
1880
+ color: strColors[i] || "#ECECEC",
1881
+ isRef: false,
1882
+ id: (0, _univerjs_core.generateRandomId)(4)
1883
+ }));
1884
+ });
1885
+ const handleStrItemChange = (id, value, color) => {
1886
+ const item = strList.find((i) => i.id === id);
1887
+ if (!item) return;
1888
+ item.label = value;
1889
+ item.color = color;
1890
+ setStrList([...strList]);
1963
1891
  };
1964
- const handleRemoveAll = () => {
1965
- commandService.executeCommand(_univerjs_sheets_data_validation.RemoveSheetAllDataValidationCommand.id, {
1966
- unitId,
1967
- subUnitId
1968
- });
1892
+ const handleStrItemDelete = (id) => {
1893
+ const index = strList.findIndex((i) => i.id === id);
1894
+ if (index !== -1) {
1895
+ strList.splice(index, 1);
1896
+ setStrList([...strList]);
1897
+ }
1969
1898
  };
1970
- const getDvRulesByPermissionCorrect = (rules) => {
1971
- const workbook = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
1972
- const worksheet = workbook.getActiveSheet();
1973
- const unitId = workbook.getUnitId();
1974
- const subUnitId = worksheet.getSheetId();
1975
- return rules.map((rule) => {
1976
- if ((0, _univerjs_sheets.checkRangesEditablePermission)(injector, unitId, subUnitId, rule.ranges)) return { ...rule };
1977
- else return {
1978
- ...rule,
1979
- disable: true
1980
- };
1899
+ const refFinalList = (0, react.useMemo)(() => refOptions.map((label, i) => ({
1900
+ label,
1901
+ color: refColors[i] || "#ECECEC",
1902
+ id: `${i}`,
1903
+ isRef: true
1904
+ })), [refColors, refOptions]);
1905
+ const handleRefItemChange = (id, value, color) => {
1906
+ const newColors = [...refColors];
1907
+ newColors[+id] = color;
1908
+ setRefColors(newColors);
1909
+ onChange({
1910
+ formula1,
1911
+ formula2: newColors.join(",")
1981
1912
  });
1982
1913
  };
1983
- const rulesByPermissionCheck = getDvRulesByPermissionCorrect(rules);
1984
- const hasDisableRule = rulesByPermissionCheck === null || rulesByPermissionCheck === void 0 ? void 0 : rulesByPermissionCheck.some((rule) => rule.disable);
1985
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1986
- className: "univer-pb-4",
1987
- children: [rulesByPermissionCheck === null || rulesByPermissionCheck === void 0 ? void 0 : rulesByPermissionCheck.map((rule) => {
1988
- var _rule$disable;
1989
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationItem, {
1990
- unitId,
1991
- subUnitId,
1992
- onClick: () => {
1993
- if (rule.disable) return;
1994
- dataValidationPanelService.setActiveRule({
1995
- unitId,
1996
- subUnitId,
1997
- rule
1998
- });
1999
- },
2000
- rule,
2001
- disable: (_rule$disable = rule.disable) !== null && _rule$disable !== void 0 ? _rule$disable : false
2002
- }, rule.uid);
2003
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2004
- className: "univer-mt-4 univer-flex univer-flex-row univer-justify-end univer-gap-2",
2005
- children: [rules.length && !hasDisableRule ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
2006
- onClick: handleRemoveAll,
2007
- children: localeService.t("sheets-data-validation-ui.panel.removeAll")
2008
- }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
2009
- variant: "primary",
2010
- onClick: handleAddRule,
2011
- children: localeService.t("sheets-data-validation-ui.panel.add")
2012
- })]
2013
- })]
2014
- });
2015
- }
2016
-
2017
- //#endregion
2018
- //#region src/views/components/DataValidationPanel.tsx
2019
- const DataValidationPanel = () => {
2020
- const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
2021
- const activeRule = (0, _univerjs_ui.useObservable)(dataValidationPanelService.activeRule$, dataValidationPanelService.activeRule);
2022
- const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
2023
- const workbook = (0, _univerjs_ui.useObservable)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), void 0, void 0, []);
2024
- const worksheet = (0, _univerjs_ui.useObservable)(() => {
2025
- var _workbook$activeSheet;
2026
- return (_workbook$activeSheet = workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) !== null && _workbook$activeSheet !== void 0 ? _workbook$activeSheet : (0, rxjs.of)(null);
2027
- }, void 0, void 0, []);
2028
- if (!workbook || !worksheet) return null;
2029
- return activeRule && (activeRule.subUnitId === worksheet.getSheetId() || activeRule.subUnitId === dataValidationPanelService.getFocusFormulaEditorActiveRuleSubUnitId()) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationDetail, {}, activeRule.rule.uid) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationList, { workbook });
2030
- };
2031
-
2032
- //#endregion
2033
- //#region src/views/components/DateShowTimeOption.tsx
2034
- const DATE_SHOW_TIME_OPTION = "DATE_SHOW_TIME_OPTION";
2035
- function DateShowTimeOption(props) {
2036
- var _value$bizInfo;
2037
- const { value, onChange } = props;
2038
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2039
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
2040
- checked: (_value$bizInfo = value.bizInfo) === null || _value$bizInfo === void 0 ? void 0 : _value$bizInfo.showTime,
2041
- onChange: (showTime) => {
2042
- onChange({
2043
- ...value,
2044
- bizInfo: {
2045
- ...value.bizInfo,
2046
- showTime
2047
- }
1914
+ const handleAdd = () => {
1915
+ setStrList([...strList, {
1916
+ label: "",
1917
+ color: DROP_DOWN_DEFAULT_COLOR,
1918
+ isRef: false,
1919
+ id: (0, _univerjs_core.generateRandomId)(4)
1920
+ }]);
1921
+ };
1922
+ (0, react.useEffect)(() => {
1923
+ if (isFormulaStr === "1") return;
1924
+ onChange(buildCustomListFormulaPayload(strList, DROP_DOWN_DEFAULT_COLOR));
1925
+ }, [
1926
+ strList,
1927
+ onChange,
1928
+ isFormulaStr
1929
+ ]);
1930
+ const updateFormula = (0, _univerjs_ui.useEvent)(async (str) => {
1931
+ if (!(0, _univerjs_core.isFormulaString)(str)) {
1932
+ onChange === null || onChange === void 0 || onChange({
1933
+ formula1: "",
1934
+ formula2
1935
+ });
1936
+ return;
1937
+ }
1938
+ if (dataValidationFormulaController.getFormulaRefCheck(str)) {
1939
+ onChange === null || onChange === void 0 || onChange({
1940
+ formula1: (0, _univerjs_core.isFormulaString)(str) ? str : "",
1941
+ formula2
2048
1942
  });
2049
- },
2050
- children: localeService.t("sheets-data-validation-ui.showTime.label")
2051
- }) });
2052
- }
2053
- DateShowTimeOption.componentKey = DATE_SHOW_TIME_OPTION;
2054
-
2055
- //#endregion
2056
- //#region src/views/components/formula-input/BaseFormulaInput.tsx
2057
- const BaseFormulaInput = (props) => {
2058
- const { isTwoFormula = false, value, onChange, showError, validResult } = props;
2059
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2060
- const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : "";
2061
- const formula2Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula2 : "";
2062
- if (isTwoFormula) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
2063
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2064
- error: formula1Res,
2065
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
2066
- className: "univer-w-full",
2067
- placeholder: localeService.t("sheets-data-validation-ui.panel.formulaPlaceholder"),
2068
- value: value === null || value === void 0 ? void 0 : value.formula1,
2069
- onChange: (newValue) => {
2070
- onChange === null || onChange === void 0 || onChange({
2071
- ...value,
2072
- formula1: newValue
2073
- });
2074
- }
2075
- })
2076
- }),
2077
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2078
- className: "-univer-mt-2 univer-mb-1 univer-text-sm univer-text-gray-400",
2079
- children: localeService.t("sheets-data-validation-ui.panel.formulaAnd")
2080
- }),
2081
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2082
- error: formula2Res,
2083
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
2084
- className: "univer-w-full",
2085
- placeholder: localeService.t("sheets-data-validation-ui.panel.formulaPlaceholder"),
2086
- value: value === null || value === void 0 ? void 0 : value.formula2,
2087
- onChange: (newValue) => {
2088
- onChange === null || onChange === void 0 || onChange({
2089
- ...value,
2090
- formula2: newValue
2091
- });
2092
- }
2093
- })
2094
- })
2095
- ] });
2096
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2097
- error: formula1Res,
2098
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
2099
- className: "univer-w-full",
2100
- placeholder: localeService.t("sheets-data-validation-ui.panel.formulaPlaceholder"),
2101
- value: value === null || value === void 0 ? void 0 : value.formula1,
2102
- onChange: (newValue) => {
2103
- onChange === null || onChange === void 0 || onChange({ formula1: newValue });
2104
- }
2105
- })
1943
+ setLocalError("");
1944
+ } else {
1945
+ onChange === null || onChange === void 0 || onChange({
1946
+ formula1: "",
1947
+ formula2
1948
+ });
1949
+ setFormulaStr("=");
1950
+ setLocalError(localeService.t("sheets-data-validation-ui.validFail.formulaError"));
1951
+ }
2106
1952
  });
2107
- };
2108
-
2109
- //#endregion
2110
- //#region src/views/components/formula-input/CheckboxFormulaInput.tsx
2111
- function CheckboxFormulaInput(props) {
2112
- const { value, onChange, showError, validResult } = props;
2113
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2114
- const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : "";
2115
- const formula2Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula2 : "";
2116
- const [checked, setChecked] = (0, react.useState)(!((value === null || value === void 0 ? void 0 : value.formula1) === void 0 && (value === null || value === void 0 ? void 0 : value.formula2) === void 0));
2117
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
2118
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
2119
- checked,
2120
- onChange: (newValue) => {
2121
- if (newValue) setChecked(true);
2122
- else {
2123
- setChecked(false);
2124
- onChange === null || onChange === void 0 || onChange({
2125
- ...value,
2126
- formula1: void 0,
2127
- formula2: void 0
2128
- });
2129
- }
2130
- },
2131
- children: localeService.t("sheets-data-validation-ui.checkbox.tips")
2132
- }) }),
2133
- checked ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2134
- label: localeService.t("sheets-data-validation-ui.checkbox.checked"),
2135
- error: formula1Res,
2136
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
2137
- className: "univer-w-full",
2138
- placeholder: localeService.t("sheets-data-validation-ui.panel.valuePlaceholder"),
2139
- value: value === null || value === void 0 ? void 0 : value.formula1,
2140
- onChange: (newValue) => {
2141
- onChange === null || onChange === void 0 || onChange({
2142
- ...value,
2143
- formula1: newValue || void 0
2144
- });
2145
- }
2146
- })
2147
- }) : null,
2148
- checked ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2149
- label: localeService.t("sheets-data-validation-ui.checkbox.unchecked"),
2150
- error: formula2Res,
2151
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
2152
- className: "univer-w-full",
2153
- placeholder: localeService.t("sheets-data-validation-ui.panel.valuePlaceholder"),
2154
- value: value === null || value === void 0 ? void 0 : value.formula2,
2155
- onChange: (newValue) => {
2156
- onChange === null || onChange === void 0 || onChange({
2157
- ...value,
2158
- formula2: newValue || void 0
2159
- });
2160
- }
2161
- })
2162
- }) : null
2163
- ] });
2164
- }
2165
-
2166
- //#endregion
2167
- //#region src/views/components/formula-input/CustomFormulaInput.tsx
2168
- function CustomFormulaInput(props) {
2169
- var _value$formula;
2170
- const { unitId, subUnitId, value, onChange, showError, validResult } = props;
2171
- const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : void 0;
2172
1953
  const formulaEditorRef = (0, react.useRef)(null);
2173
1954
  const [isFocusFormulaEditor, setIsFocusFormulaEditor] = (0, react.useState)(false);
2174
1955
  (0, _univerjs_ui.useSidebarClick)((e) => {
2175
1956
  var _formulaEditorRef$cur;
2176
1957
  !((_formulaEditorRef$cur = formulaEditorRef.current) === null || _formulaEditorRef$cur === void 0) && _formulaEditorRef$cur.isClickOutSide(e) && setIsFocusFormulaEditor(false);
2177
1958
  });
2178
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2179
- error: formula1Res,
2180
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_sheets_formula_ui.FormulaEditor, {
1959
+ (0, react.useEffect)(() => {
1960
+ if (isFocusFormulaEditor) dataValidationPanelService.setFocusFormulaEditorActiveRuleSubUnitId(subUnitId);
1961
+ else dataValidationPanelService.setFocusFormulaEditorActiveRuleSubUnitId(null);
1962
+ }, [
1963
+ isFocusFormulaEditor,
1964
+ subUnitId,
1965
+ dataValidationPanelService
1966
+ ]);
1967
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1968
+ label: localeService.t("sheets-data-validation-ui.list.options"),
1969
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
1970
+ value: isFormulaStr,
1971
+ onChange: (v) => {
1972
+ setIsFormulaStr(v);
1973
+ setFormulaStr(formulaStrCopy);
1974
+ if (v === "1") onChange({
1975
+ formula1: formulaStrCopy === "=" ? "" : formulaStrCopy,
1976
+ formula2: refColors.join(",")
1977
+ });
1978
+ },
1979
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
1980
+ value: "0",
1981
+ children: localeService.t("sheets-data-validation-ui.list.customOptions")
1982
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
1983
+ value: "1",
1984
+ children: localeService.t("sheets-data-validation-ui.list.refOptions")
1985
+ })]
1986
+ })
1987
+ }), isFormulaStr === "1" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.FormLayout, {
1988
+ error: formula1Res || localError || void 0,
1989
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_sheets_formula_ui.FormulaEditor, {
2181
1990
  ref: formulaEditorRef,
2182
1991
  className: (0, _univerjs_design.clsx)("univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent", _univerjs_design.borderClassName),
2183
- initValue: (_value$formula = value === null || value === void 0 ? void 0 : value.formula1) !== null && _value$formula !== void 0 ? _value$formula : "=",
1992
+ initValue: formulaStr,
2184
1993
  unitId,
2185
1994
  subUnitId,
2186
1995
  isFocus: isFocusFormulaEditor,
2187
1996
  isSupportAcrossSheet: true,
2188
- onChange: (newValue) => {
2189
- const newFormula = (newValue !== null && newValue !== void 0 ? newValue : "").trim();
2190
- if (newFormula === (value === null || value === void 0 ? void 0 : value.formula1)) return;
2191
- onChange === null || onChange === void 0 || onChange({
2192
- ...value,
2193
- formula1: newFormula
2194
- });
2195
- },
2196
- onFocus: () => setIsFocusFormulaEditor(true)
1997
+ onFocus: () => setIsFocusFormulaEditor(true),
1998
+ onChange: (v = "") => {
1999
+ const str = (v !== null && v !== void 0 ? v : "").trim();
2000
+ setFormulaStrCopy(str);
2001
+ updateFormula(str);
2002
+ }
2003
+ }), refFinalList.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2004
+ className: "univer-mt-3",
2005
+ children: refFinalList.map((item) => {
2006
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Template, {
2007
+ className: "univer-mb-3",
2008
+ item,
2009
+ commonProps: { onItemChange: handleRefItemChange }
2010
+ }, item.id);
2011
+ })
2012
+ })]
2013
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2014
+ error: formula1Res,
2015
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DraggableList, {
2016
+ list: strList,
2017
+ onListChange: setStrList,
2018
+ rowHeight: 28,
2019
+ margin: [0, 12],
2020
+ draggableHandle: ".draggableHandle",
2021
+ itemRender: (item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Template, {
2022
+ item,
2023
+ commonProps: {
2024
+ onItemChange: handleStrItemChange,
2025
+ onItemDelete: handleStrItemDelete
2026
+ }
2027
+ }, item.id),
2028
+ idKey: "id"
2029
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", {
2030
+ className: "univer-text-primary univer-flex univer-w-fit univer-cursor-pointer univer-flex-row univer-items-center univer-rounded univer-p-1 univer-px-2 univer-text-sm hover:univer-bg-primary-50 dark:hover:!univer-bg-gray-800",
2031
+ onClick: handleAdd,
2032
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.IncreaseIcon, { className: "univer-mr-1" }), localeService.t("sheets-data-validation-ui.list.add")]
2033
+ })] })
2034
+ })] });
2035
+ }
2036
+
2037
+ //#endregion
2038
+ //#region src/views/components/formula-input/index.ts
2039
+ const FORMULA_INPUTS = [
2040
+ [_univerjs_sheets_data_validation.CUSTOM_FORMULA_INPUT_NAME, CustomFormulaInput],
2041
+ [_univerjs_sheets_data_validation.BASE_FORMULA_INPUT_NAME, BaseFormulaInput],
2042
+ [_univerjs_sheets_data_validation.LIST_FORMULA_INPUT_NAME, ListFormulaInput],
2043
+ [_univerjs_sheets_data_validation.CHECKBOX_FORMULA_INPUT_NAME, CheckboxFormulaInput]
2044
+ ];
2045
+
2046
+ //#endregion
2047
+ //#region src/views/components/ListRenderModeInput.tsx
2048
+ const LIST_RENDER_MODE_OPTION_INPUT = "LIST_RENDER_MODE_OPTION_INPUT";
2049
+ function ListRenderModeInput(props) {
2050
+ var _value$renderMode;
2051
+ const { value, onChange } = props;
2052
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2053
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2054
+ label: localeService.t("sheets-data-validation-ui.renderMode.label"),
2055
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
2056
+ value: `${(_value$renderMode = value.renderMode) !== null && _value$renderMode !== void 0 ? _value$renderMode : _univerjs_core.DataValidationRenderMode.CUSTOM}`,
2057
+ onChange: (renderMode) => onChange({
2058
+ ...value,
2059
+ renderMode: +renderMode
2060
+ }),
2061
+ children: [
2062
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2063
+ value: `${_univerjs_core.DataValidationRenderMode.CUSTOM}`,
2064
+ children: localeService.t("sheets-data-validation-ui.renderMode.chip")
2065
+ }),
2066
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2067
+ value: `${_univerjs_core.DataValidationRenderMode.ARROW}`,
2068
+ children: localeService.t("sheets-data-validation-ui.renderMode.arrow")
2069
+ }),
2070
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2071
+ value: `${_univerjs_core.DataValidationRenderMode.TEXT}`,
2072
+ children: localeService.t("sheets-data-validation-ui.renderMode.text")
2073
+ })
2074
+ ]
2197
2075
  })
2198
2076
  });
2199
2077
  }
2078
+ ListRenderModeInput.componentKey = LIST_RENDER_MODE_OPTION_INPUT;
2200
2079
 
2201
2080
  //#endregion
2202
- //#region src/views/components/formula-input/utils.ts
2081
+ //#region src/controllers/components.controller.ts
2203
2082
  /**
2204
2083
  * Copyright 2023-present DreamNum Co., Ltd.
2205
2084
  *
@@ -2215,355 +2094,715 @@ function CustomFormulaInput(props) {
2215
2094
  * See the License for the specific language governing permissions and
2216
2095
  * limitations under the License.
2217
2096
  */
2218
- function buildCustomListFormulaPayload(items, defaultColor) {
2219
- const labelSet = /* @__PURE__ */ new Set();
2220
- const finalList = [];
2221
- items.forEach((item) => {
2222
- if (!item.label || labelSet.has(item.label)) return;
2223
- labelSet.add(item.label);
2224
- finalList.push(item);
2225
- });
2226
- return {
2227
- formula1: (0, _univerjs_sheets.serializeListOptions)(finalList.map((item) => item.label)),
2228
- formula2: finalList.map((item) => item.color === defaultColor ? "" : item.color).join(",")
2229
- };
2230
- }
2097
+ let ComponentsController = class ComponentsController extends _univerjs_core.Disposable {
2098
+ constructor(_componentManager, _iconManager) {
2099
+ super();
2100
+ this._componentManager = _componentManager;
2101
+ this._iconManager = _iconManager;
2102
+ this._registerIcons();
2103
+ this._registerComponents();
2104
+ }
2105
+ _registerIcons() {
2106
+ this.disposeWithMe(this._iconManager.register({
2107
+ CheckboxIcon: _univerjs_icons.CheckboxIcon,
2108
+ DataValidationIcon: _univerjs_icons.DataValidationIcon,
2109
+ DatePickerIcon: _univerjs_icons.DatePickerIcon,
2110
+ DropdownListIcon: _univerjs_icons.DropdownListIcon
2111
+ }));
2112
+ }
2113
+ _registerComponents() {
2114
+ [
2115
+ [DATA_VALIDATION_PANEL, DataValidationPanel],
2116
+ [ListRenderModeInput.componentKey, ListRenderModeInput],
2117
+ [DateShowTimeOption.componentKey, DateShowTimeOption],
2118
+ [DROPDOWN_PRESETS_COMPONENT, DropdownPresets],
2119
+ ...FORMULA_INPUTS
2120
+ ].forEach(([key, component]) => {
2121
+ this.disposeWithMe(this._componentManager.register(key, component));
2122
+ });
2123
+ }
2124
+ };
2125
+ ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IconManager))], ComponentsController);
2231
2126
 
2232
2127
  //#endregion
2233
- //#region src/views/components/formula-input/ListFormulaInput.tsx
2234
- const DEFAULT_COLOR_PRESET = [
2235
- "#FFFFFF",
2236
- "#FEE7E7",
2237
- "#FEF0E6",
2238
- "#EFFBD0",
2239
- "#E4F4FE",
2240
- "#E8ECFD",
2241
- "#F1EAFA",
2242
- "#FDE8F3",
2243
- "#E5E5E5",
2244
- "#FDCECE",
2245
- "#FDC49B",
2246
- "#DEF6A2",
2247
- "#9FDAFF",
2248
- "#D0D9FB",
2249
- "#E3D5F6",
2250
- "#FBD0E8",
2251
- "#656565",
2252
- "#FE4B4B",
2253
- "#FF8C51",
2254
- "#8BBB11",
2255
- "#0B9EFB",
2256
- "#3A60F7",
2257
- "#9E6DE3",
2258
- "#F248A6"
2259
- ];
2260
- const ColorSelect = (props) => {
2261
- const { value, onChange, disabled } = props;
2262
- const [open, setOpen] = (0, react.useState)(false);
2263
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
2264
- align: "start",
2265
- disabled,
2266
- open,
2267
- onOpenChange: setOpen,
2268
- overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2269
- className: "univer-box-border univer-grid univer-w-fit univer-grid-cols-6 univer-flex-wrap univer-gap-2 univer-p-1.5",
2270
- children: DEFAULT_COLOR_PRESET.map((color) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2271
- className: (0, _univerjs_design.clsx)("univer-box-border univer-size-4 univer-cursor-pointer univer-rounded", _univerjs_design.borderClassName),
2272
- style: { background: color },
2273
- onClick: () => {
2274
- onChange(color);
2275
- setOpen(false);
2128
+ //#region src/controllers/dv-alert.controller.ts
2129
+ const ALERT_KEY = "SHEET_DATA_VALIDATION_ALERT";
2130
+ let DataValidationAlertController = class DataValidationAlertController extends _univerjs_core.Disposable {
2131
+ constructor(_hoverManagerService, _cellAlertManagerService, _univerInstanceService, _localeService, _dataValidationModel) {
2132
+ super();
2133
+ this._hoverManagerService = _hoverManagerService;
2134
+ this._cellAlertManagerService = _cellAlertManagerService;
2135
+ this._univerInstanceService = _univerInstanceService;
2136
+ this._localeService = _localeService;
2137
+ this._dataValidationModel = _dataValidationModel;
2138
+ this._init();
2139
+ }
2140
+ _init() {
2141
+ this._initCellAlertPopup();
2142
+ }
2143
+ _initCellAlertPopup() {
2144
+ this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0, rxjs.debounceTime)(100)).subscribe((cellPos) => {
2145
+ if (cellPos) {
2146
+ const workbook = this._univerInstanceService.getUnit(cellPos.location.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
2147
+ const worksheet = workbook.getSheetBySheetId(cellPos.location.subUnitId);
2148
+ if (!worksheet) return;
2149
+ const rule = this._dataValidationModel.getRuleByLocation(cellPos.location.unitId, cellPos.location.subUnitId, cellPos.location.row, cellPos.location.col);
2150
+ if (!rule) {
2151
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
2152
+ return;
2276
2153
  }
2277
- }, color))
2278
- }),
2279
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2280
- className: (0, _univerjs_design.clsx)("univer-box-border univer-inline-flex univer-h-8 univer-w-16 univer-cursor-pointer univer-items-center univer-justify-between univer-gap-2 univer-rounded-lg univer-bg-white univer-px-2.5 univer-transition-colors univer-duration-200 hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white", _univerjs_design.borderClassName),
2281
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2282
- className: "univer-box-border univer-size-4 univer-rounded univer-text-base",
2283
- style: { background: value }
2284
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, {})]
2285
- })
2286
- });
2287
- };
2288
- const Template = (props) => {
2289
- const { item, commonProps, className } = props;
2290
- const { onItemChange, onItemDelete } = commonProps;
2291
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2292
- className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-gap-2", className),
2293
- children: [
2294
- !item.isRef && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2295
- className: (0, _univerjs_design.clsx)("univer-cursor-move", "draggableHandle"),
2296
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.GripVerticalIcon, {})
2297
- }),
2298
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ColorSelect, {
2299
- value: item.color,
2300
- onChange: (color) => {
2301
- onItemChange(item.id, item.label, color);
2154
+ if (this._dataValidationModel.validator(rule, {
2155
+ ...cellPos.location,
2156
+ workbook,
2157
+ worksheet
2158
+ }) === _univerjs_core.DataValidationStatus.INVALID) {
2159
+ var _currentAlert$alert;
2160
+ const currentAlert = this._cellAlertManagerService.currentAlert.get(ALERT_KEY);
2161
+ const currentLoc = currentAlert === null || currentAlert === void 0 || (_currentAlert$alert = currentAlert.alert) === null || _currentAlert$alert === void 0 ? void 0 : _currentAlert$alert.location;
2162
+ if (currentLoc && currentLoc.row === cellPos.location.row && currentLoc.col === cellPos.location.col && currentLoc.subUnitId === cellPos.location.subUnitId && currentLoc.unitId === cellPos.location.unitId) {
2163
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
2164
+ return;
2165
+ }
2166
+ const validator = this._dataValidationModel.getValidator(rule.type);
2167
+ if (!validator) {
2168
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
2169
+ return;
2170
+ }
2171
+ this._cellAlertManagerService.showAlert({
2172
+ type: _univerjs_sheets_ui.CellAlertType.ERROR,
2173
+ title: this._localeService.t("sheets-data-validation-ui.error.title"),
2174
+ message: validator === null || validator === void 0 ? void 0 : validator.getRuleFinalError(rule, cellPos.location),
2175
+ location: cellPos.location,
2176
+ width: 200,
2177
+ height: 74,
2178
+ key: ALERT_KEY
2179
+ });
2180
+ return;
2302
2181
  }
2303
- }),
2304
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
2305
- disabled: item.isRef,
2306
- value: item.label,
2307
- onChange: (label) => {
2308
- onItemChange(item.id, label, item.color);
2182
+ }
2183
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
2184
+ }));
2185
+ }
2186
+ };
2187
+ DataValidationAlertController = __decorate([
2188
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.HoverManagerService)),
2189
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.CellAlertManagerService)),
2190
+ __decorateParam(2, _univerjs_core.IUniverInstanceService),
2191
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
2192
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel))
2193
+ ], DataValidationAlertController);
2194
+
2195
+ //#endregion
2196
+ //#region src/controllers/dv-auto-fill.controller.ts
2197
+ let DataValidationAutoFillController = class DataValidationAutoFillController extends _univerjs_core.Disposable {
2198
+ constructor(_autoFillService, _sheetDataValidationModel, _injector) {
2199
+ super();
2200
+ this._autoFillService = _autoFillService;
2201
+ this._sheetDataValidationModel = _sheetDataValidationModel;
2202
+ this._injector = _injector;
2203
+ this._initAutoFill();
2204
+ }
2205
+ _initAutoFill() {
2206
+ const noopReturnFunc = () => ({
2207
+ redos: [],
2208
+ undos: []
2209
+ });
2210
+ const generalApplyFunc = (location, applyType) => {
2211
+ const { source: sourceRange, target: targetRange, unitId, subUnitId } = location;
2212
+ const ruleMatrixCopy = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
2213
+ const virtualRange = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([sourceRange, targetRange]);
2214
+ const [vSourceRange, vTargetRange] = virtualRange.ranges;
2215
+ const { mapFunc } = virtualRange;
2216
+ const sourceStartCell = {
2217
+ row: vSourceRange.startRow,
2218
+ col: vSourceRange.startColumn
2219
+ };
2220
+ const repeats = _univerjs_sheets.AutoFillTools.getAutoFillRepeatRange(vSourceRange, vTargetRange);
2221
+ const additionMatrix = new _univerjs_core.ObjectMatrix();
2222
+ const additionRules = /* @__PURE__ */ new Set();
2223
+ repeats.forEach((repeat) => {
2224
+ const targetStartCell = repeat.repeatStartCell;
2225
+ const relativeRange = repeat.relativeRange;
2226
+ const sourceRange = {
2227
+ startRow: sourceStartCell.row,
2228
+ startColumn: sourceStartCell.col,
2229
+ endColumn: sourceStartCell.col,
2230
+ endRow: sourceStartCell.row
2231
+ };
2232
+ const targetRange = {
2233
+ startRow: targetStartCell.row,
2234
+ startColumn: targetStartCell.col,
2235
+ endColumn: targetStartCell.col,
2236
+ endRow: targetStartCell.row
2237
+ };
2238
+ _univerjs_core.Range.foreach(relativeRange, (row, col) => {
2239
+ const sourcePositionRange = _univerjs_core.Rectangle.getPositionRange({
2240
+ startRow: row,
2241
+ startColumn: col,
2242
+ endColumn: col,
2243
+ endRow: row
2244
+ }, sourceRange);
2245
+ const { row: sourceRow, col: sourceCol } = mapFunc(sourcePositionRange.startRow, sourcePositionRange.startColumn);
2246
+ const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, sourceRow, sourceCol) || "";
2247
+ const targetPositionRange = _univerjs_core.Rectangle.getPositionRange({
2248
+ startRow: row,
2249
+ startColumn: col,
2250
+ endColumn: col,
2251
+ endRow: row
2252
+ }, targetRange);
2253
+ const { row: targetRow, col: targetCol } = mapFunc(targetPositionRange.startRow, targetPositionRange.startColumn);
2254
+ additionMatrix.setValue(targetRow, targetCol, ruleId);
2255
+ additionRules.add(ruleId);
2256
+ });
2257
+ });
2258
+ const additions = Array.from(additionRules).map((id) => ({
2259
+ id,
2260
+ ranges: (0, _univerjs_core.queryObjectMatrix)(additionMatrix, (value) => value === id)
2261
+ }));
2262
+ ruleMatrixCopy.addRangeRules(additions);
2263
+ const { redoMutations, undoMutations } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(unitId, subUnitId, ruleMatrixCopy.diff(this._sheetDataValidationModel.getRules(unitId, subUnitId)), this._injector, "patched", applyType === _univerjs_sheets.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT);
2264
+ return {
2265
+ undos: undoMutations,
2266
+ redos: redoMutations
2267
+ };
2268
+ };
2269
+ const hook = {
2270
+ id: _univerjs_sheets_data_validation.DATA_VALIDATION_PLUGIN_NAME,
2271
+ onBeforeFillData: (location) => {
2272
+ const { source: sourceRange, unitId, subUnitId } = location;
2273
+ for (const row of sourceRange.rows) for (const col of sourceRange.cols) {
2274
+ const dv = this._sheetDataValidationModel.getRuleByLocation(unitId, subUnitId, row, col);
2275
+ if (dv && dv.type === _univerjs_core.DataValidationType.CHECKBOX) {
2276
+ this._autoFillService.setDisableApplyType(_univerjs_sheets.AUTO_FILL_APPLY_TYPE.SERIES, true);
2277
+ return;
2278
+ }
2309
2279
  }
2310
- }),
2311
- item.isRef ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2312
- className: "univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base hover:univer-bg-gray-200",
2313
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, { onClick: () => onItemDelete(item.id) })
2314
- })
2315
- ]
2316
- });
2280
+ },
2281
+ onFillData: (location, direction, applyType) => {
2282
+ if (applyType === _univerjs_sheets.AUTO_FILL_APPLY_TYPE.COPY || applyType === _univerjs_sheets.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT || applyType === _univerjs_sheets.AUTO_FILL_APPLY_TYPE.SERIES) return generalApplyFunc(location, applyType);
2283
+ return noopReturnFunc();
2284
+ },
2285
+ onAfterFillData: () => {}
2286
+ };
2287
+ this.disposeWithMe(this._autoFillService.addHook(hook));
2288
+ }
2317
2289
  };
2318
- const NOOP = () => {};
2319
- function ListFormulaInput(props) {
2320
- const { value, onChange: _onChange = NOOP, unitId, subUnitId, validResult, showError, ruleId } = props;
2321
- const { formula1 = "", formula2 = "" } = value || {};
2322
- const [isFormulaStr, setIsFormulaStr] = (0, react.useState)(() => (0, _univerjs_core.isFormulaString)(formula1) ? "1" : "0");
2323
- const [formulaStr, setFormulaStr] = (0, react.useState)(isFormulaStr === "1" ? formula1 : "=");
2324
- const [formulaStrCopy, setFormulaStrCopy] = (0, react.useState)(isFormulaStr === "1" ? formula1 : "=");
2325
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2326
- const dataValidatorRegistryService = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidatorRegistryService);
2327
- const dataValidationModel = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidationModel);
2328
- const dataValidationFormulaController = (0, _univerjs_ui.useDependency)(_univerjs_sheets_data_validation.DataValidationFormulaController);
2329
- const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
2330
- const [refColors, setRefColors] = (0, react.useState)(() => formula2.split(","));
2331
- const listValidator = dataValidatorRegistryService.getValidatorItem(_univerjs_core.DataValidationType.LIST);
2332
- const [refOptions, setRefOptions] = (0, react.useState)([]);
2333
- const [localError, setLocalError] = (0, react.useState)("");
2334
- const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : "";
2335
- const ruleChange = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => dataValidationModel.ruleChange$.pipe((0, rxjs.debounceTime)(16)), []));
2336
- const onChange = (0, _univerjs_ui.useEvent)(_onChange);
2337
- (0, react.useEffect)(() => {
2338
- let cancelled = false;
2339
- const timer = setTimeout(() => {
2340
- const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
2341
- if ((0, _univerjs_core.isFormulaString)(rule === null || rule === void 0 ? void 0 : rule.formula1) && listValidator && rule) listValidator.getListAsync(rule, unitId, subUnitId).then((options) => {
2342
- if (!cancelled) setRefOptions(options);
2343
- });
2344
- }, 100);
2345
- return () => {
2346
- cancelled = true;
2347
- clearTimeout(timer);
2290
+ DataValidationAutoFillController = __decorate([
2291
+ __decorateParam(0, _univerjs_sheets.IAutoFillService),
2292
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
2293
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
2294
+ ], DataValidationAutoFillController);
2295
+
2296
+ //#endregion
2297
+ //#region src/controllers/dv-copy-paste.controller.ts
2298
+ const specialPastes = [
2299
+ _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,
2300
+ _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,
2301
+ _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,
2302
+ _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA
2303
+ ];
2304
+ let DataValidationCopyPasteController = class DataValidationCopyPasteController extends _univerjs_core.Disposable {
2305
+ constructor(_sheetClipboardService, _sheetDataValidationModel, _injector, _univerInstanceService) {
2306
+ super();
2307
+ this._sheetClipboardService = _sheetClipboardService;
2308
+ this._sheetDataValidationModel = _sheetDataValidationModel;
2309
+ this._injector = _injector;
2310
+ this._univerInstanceService = _univerInstanceService;
2311
+ _defineProperty(this, "_copyInfo", void 0);
2312
+ this._initCopyPaste();
2313
+ }
2314
+ _initCopyPaste() {
2315
+ this._sheetClipboardService.addClipboardHook({
2316
+ id: _univerjs_sheets_data_validation.DATA_VALIDATION_PLUGIN_NAME,
2317
+ onBeforeCopy: (unitId, subUnitId, range) => this._collect(unitId, subUnitId, range),
2318
+ onPasteCells: (pasteFrom, pasteTo, data, payload) => {
2319
+ if (!pasteFrom || !this._copyInfo || specialPastes.includes(payload.pasteType)) return {
2320
+ redos: [],
2321
+ undos: []
2322
+ };
2323
+ return this._generateMutations(pasteFrom, pasteTo, payload);
2324
+ }
2325
+ });
2326
+ }
2327
+ _collect(unitId, subUnitId, range) {
2328
+ const matrix = new _univerjs_core.ObjectMatrix();
2329
+ this._copyInfo = {
2330
+ unitId,
2331
+ subUnitId,
2332
+ matrix
2348
2333
  };
2349
- }, [
2350
- dataValidationModel,
2351
- ruleChange,
2352
- listValidator,
2353
- ruleId,
2354
- subUnitId,
2355
- unitId
2356
- ]);
2357
- (0, react.useEffect)(() => {
2358
- if ((0, _univerjs_core.isFormulaString)(formula1) && formula1 !== formulaStrCopy) {
2359
- setFormulaStr(formula1);
2360
- setFormulaStrCopy(formula1);
2361
- }
2362
- }, [formulaStrCopy, formula1]);
2363
- const [strList, setStrList] = (0, react.useState)(() => {
2364
- const strOptions = isFormulaStr !== "1" ? (0, _univerjs_sheets.deserializeListOptions)(formula1) : [];
2365
- const strColors = formula2.split(",");
2366
- return strOptions.map((label, i) => ({
2367
- label,
2368
- color: strColors[i] || "#ECECEC",
2369
- isRef: false,
2370
- id: (0, _univerjs_core.generateRandomId)(4)
2371
- }));
2372
- });
2373
- const handleStrItemChange = (id, value, color) => {
2374
- const item = strList.find((i) => i.id === id);
2375
- if (!item) return;
2376
- item.label = value;
2377
- item.color = color;
2378
- setStrList([...strList]);
2379
- };
2380
- const handleStrItemDelete = (id) => {
2381
- const index = strList.findIndex((i) => i.id === id);
2382
- if (index !== -1) {
2383
- strList.splice(index, 1);
2384
- setStrList([...strList]);
2385
- }
2386
- };
2387
- const refFinalList = (0, react.useMemo)(() => refOptions.map((label, i) => ({
2388
- label,
2389
- color: refColors[i] || "#ECECEC",
2390
- id: `${i}`,
2391
- isRef: true
2392
- })), [refColors, refOptions]);
2393
- const handleRefItemChange = (id, value, color) => {
2394
- const newColors = [...refColors];
2395
- newColors[+id] = color;
2396
- setRefColors(newColors);
2397
- onChange({
2398
- formula1,
2399
- formula2: newColors.join(",")
2334
+ const discreteRange = this._injector.invoke((accessor) => {
2335
+ return (0, _univerjs_sheets.rangeToDiscreteRange)(range, accessor, unitId, subUnitId);
2400
2336
  });
2401
- };
2402
- const handleAdd = () => {
2403
- setStrList([...strList, {
2404
- label: "",
2405
- color: DROP_DOWN_DEFAULT_COLOR,
2406
- isRef: false,
2407
- id: (0, _univerjs_core.generateRandomId)(4)
2408
- }]);
2409
- };
2410
- (0, react.useEffect)(() => {
2411
- if (isFormulaStr === "1") return;
2412
- onChange(buildCustomListFormulaPayload(strList, DROP_DOWN_DEFAULT_COLOR));
2413
- }, [
2414
- strList,
2415
- onChange,
2416
- isFormulaStr
2417
- ]);
2418
- const updateFormula = (0, _univerjs_ui.useEvent)(async (str) => {
2419
- if (!(0, _univerjs_core.isFormulaString)(str)) {
2420
- onChange === null || onChange === void 0 || onChange({
2421
- formula1: "",
2422
- formula2
2337
+ if (!discreteRange) return;
2338
+ const { rows, cols } = discreteRange;
2339
+ rows.forEach((row, rowIndex) => {
2340
+ cols.forEach((col, colIndex) => {
2341
+ const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, row, col);
2342
+ matrix.setValue(rowIndex, colIndex, ruleId !== null && ruleId !== void 0 ? ruleId : "");
2423
2343
  });
2424
- return;
2344
+ });
2345
+ }
2346
+ _generateMutations(pasteFrom, pasteTo, payload) {
2347
+ const { unitId: copyUnitId, subUnitId: copySubUnitId, range: copyRange } = pasteFrom;
2348
+ const { unitId: pastedUnitId, subUnitId: pastedSubUnitId, range: pastedRange } = pasteTo;
2349
+ const { copyType = _univerjs_sheets_ui.COPY_TYPE.COPY } = payload;
2350
+ if (!(0, _univerjs_sheets.getSheetCommandTarget)(this._univerInstanceService, {
2351
+ unitId: pastedUnitId,
2352
+ subUnitId: pastedSubUnitId
2353
+ })) return {
2354
+ redos: [],
2355
+ undos: []
2356
+ };
2357
+ if (copyType === _univerjs_sheets_ui.COPY_TYPE.CUT && pastedUnitId === copyUnitId && pastedSubUnitId === copySubUnitId) {
2358
+ this._copyInfo = null;
2359
+ return {
2360
+ redos: [],
2361
+ undos: []
2362
+ };
2425
2363
  }
2426
- if (dataValidationFormulaController.getFormulaRefCheck(str)) {
2427
- onChange === null || onChange === void 0 || onChange({
2428
- formula1: (0, _univerjs_core.isFormulaString)(str) ? str : "",
2429
- formula2
2364
+ if (pastedUnitId !== copyUnitId || pastedSubUnitId !== copySubUnitId) {
2365
+ const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(pastedUnitId, pastedSubUnitId).clone();
2366
+ const additionMatrix = new _univerjs_core.ObjectMatrix();
2367
+ const addRules = /* @__PURE__ */ new Set();
2368
+ const { ranges: [vCopyRange, vPastedRange], mapFunc } = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([copyRange, pastedRange]);
2369
+ const repeatRange = (0, _univerjs_sheets_ui.getRepeatRange)(vCopyRange, vPastedRange, true);
2370
+ const additionRules = /* @__PURE__ */ new Map();
2371
+ repeatRange.forEach(({ startRange }) => {
2372
+ var _this$_copyInfo;
2373
+ (_this$_copyInfo = this._copyInfo) === null || _this$_copyInfo === void 0 || _this$_copyInfo.matrix.forValue((row, col, ruleId) => {
2374
+ const range = _univerjs_core.Rectangle.getPositionRange({
2375
+ startRow: row,
2376
+ endRow: row,
2377
+ startColumn: col,
2378
+ endColumn: col
2379
+ }, startRange);
2380
+ const transformedRuleId = `${copySubUnitId}-${ruleId}`;
2381
+ const oldRule = this._sheetDataValidationModel.getRuleById(copyUnitId, copySubUnitId, ruleId);
2382
+ if (!this._sheetDataValidationModel.getRuleById(pastedUnitId, pastedSubUnitId, transformedRuleId) && oldRule) additionRules.set(transformedRuleId, {
2383
+ ...oldRule,
2384
+ uid: transformedRuleId
2385
+ });
2386
+ const { row: startRow, col: startColumn } = mapFunc(range.startRow, range.startColumn);
2387
+ addRules.add(transformedRuleId);
2388
+ additionMatrix.setValue(startRow, startColumn, transformedRuleId);
2389
+ });
2430
2390
  });
2431
- setLocalError("");
2432
- } else {
2433
- onChange === null || onChange === void 0 || onChange({
2434
- formula1: "",
2435
- formula2
2391
+ const additions = Array.from(addRules).map((id) => ({
2392
+ id,
2393
+ ranges: (0, _univerjs_core.queryObjectMatrix)(additionMatrix, (value) => value === id)
2394
+ }));
2395
+ ruleMatrix.addRangeRules(additions);
2396
+ const { redoMutations, undoMutations } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(pastedUnitId, pastedSubUnitId, ruleMatrix.diffWithAddition(this._sheetDataValidationModel.getRules(pastedUnitId, pastedSubUnitId), additionRules.values()), this._injector, "patched", false);
2397
+ if (copyType === _univerjs_sheets_ui.COPY_TYPE.CUT) {
2398
+ const copySheetRuleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyUnitId, copySubUnitId).clone();
2399
+ const deleteRangeStartCell = mapFunc(vCopyRange.startRow, vCopyRange.startColumn);
2400
+ const deleteRangeEndCell = mapFunc(vCopyRange.endRow, vCopyRange.endColumn);
2401
+ copySheetRuleMatrix.addRangeRules([{
2402
+ id: "",
2403
+ ranges: [{
2404
+ startRow: deleteRangeStartCell.row,
2405
+ endRow: deleteRangeEndCell.row,
2406
+ startColumn: deleteRangeStartCell.col,
2407
+ endColumn: deleteRangeEndCell.col
2408
+ }]
2409
+ }]);
2410
+ const { redoMutations: cutRedos, undoMutations: cutUndos } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(copyUnitId, copySubUnitId, copySheetRuleMatrix.diff(this._sheetDataValidationModel.getRules(copyUnitId, copySubUnitId)), this._injector, "patched", false);
2411
+ redoMutations.push(...cutRedos);
2412
+ undoMutations.push(...cutUndos);
2413
+ }
2414
+ return {
2415
+ redos: redoMutations,
2416
+ undos: undoMutations
2417
+ };
2418
+ } else {
2419
+ const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyUnitId, copySubUnitId).clone();
2420
+ const additionMatrix = new _univerjs_core.ObjectMatrix();
2421
+ const additionRules = /* @__PURE__ */ new Set();
2422
+ const { ranges: [vCopyRange, vPastedRange], mapFunc } = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([copyRange, pastedRange]);
2423
+ (0, _univerjs_sheets_ui.getRepeatRange)(vCopyRange, vPastedRange, true).forEach(({ startRange }) => {
2424
+ var _this$_copyInfo2;
2425
+ (_this$_copyInfo2 = this._copyInfo) === null || _this$_copyInfo2 === void 0 || _this$_copyInfo2.matrix.forValue((row, col, ruleId) => {
2426
+ const range = _univerjs_core.Rectangle.getPositionRange({
2427
+ startRow: row,
2428
+ endRow: row,
2429
+ startColumn: col,
2430
+ endColumn: col
2431
+ }, startRange);
2432
+ const { row: startRow, col: startColumn } = mapFunc(range.startRow, range.startColumn);
2433
+ additionMatrix.setValue(startRow, startColumn, ruleId);
2434
+ additionRules.add(ruleId);
2435
+ });
2436
2436
  });
2437
- setFormulaStr("=");
2438
- setLocalError(localeService.t("sheets-data-validation-ui.validFail.formulaError"));
2437
+ const additions = Array.from(additionRules).map((id) => ({
2438
+ id,
2439
+ ranges: (0, _univerjs_core.queryObjectMatrix)(additionMatrix, (value) => value === id)
2440
+ }));
2441
+ ruleMatrix.addRangeRules(additions);
2442
+ const { redoMutations, undoMutations } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(pastedUnitId, pastedSubUnitId, ruleMatrix.diff(this._sheetDataValidationModel.getRules(copyUnitId, copySubUnitId)), this._injector, "patched", false);
2443
+ return {
2444
+ redos: redoMutations,
2445
+ undos: undoMutations
2446
+ };
2439
2447
  }
2440
- });
2441
- const formulaEditorRef = (0, react.useRef)(null);
2442
- const [isFocusFormulaEditor, setIsFocusFormulaEditor] = (0, react.useState)(false);
2443
- (0, _univerjs_ui.useSidebarClick)((e) => {
2444
- var _formulaEditorRef$cur;
2445
- !((_formulaEditorRef$cur = formulaEditorRef.current) === null || _formulaEditorRef$cur === void 0) && _formulaEditorRef$cur.isClickOutSide(e) && setIsFocusFormulaEditor(false);
2446
- });
2447
- (0, react.useEffect)(() => {
2448
- if (isFocusFormulaEditor) dataValidationPanelService.setFocusFormulaEditorActiveRuleSubUnitId(subUnitId);
2449
- else dataValidationPanelService.setFocusFormulaEditorActiveRuleSubUnitId(null);
2450
- }, [
2451
- isFocusFormulaEditor,
2452
- subUnitId,
2453
- dataValidationPanelService
2454
- ]);
2455
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2456
- label: localeService.t("sheets-data-validation-ui.list.options"),
2457
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
2458
- value: isFormulaStr,
2459
- onChange: (v) => {
2460
- setIsFormulaStr(v);
2461
- setFormulaStr(formulaStrCopy);
2462
- if (v === "1") onChange({
2463
- formula1: formulaStrCopy === "=" ? "" : formulaStrCopy,
2464
- formula2: refColors.join(",")
2448
+ }
2449
+ };
2450
+ DataValidationCopyPasteController = __decorate([
2451
+ __decorateParam(0, _univerjs_sheets_ui.ISheetClipboardService),
2452
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
2453
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
2454
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService))
2455
+ ], DataValidationCopyPasteController);
2456
+
2457
+ //#endregion
2458
+ //#region src/controllers/dv-permission.controller.ts
2459
+ let DataValidationPermissionController = class DataValidationPermissionController extends _univerjs_core.Disposable {
2460
+ constructor(_localeService, _commandService, _sheetPermissionCheckController) {
2461
+ super();
2462
+ this._localeService = _localeService;
2463
+ this._commandService = _commandService;
2464
+ this._sheetPermissionCheckController = _sheetPermissionCheckController;
2465
+ this._commandExecutedListener();
2466
+ }
2467
+ _commandExecutedListener() {
2468
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
2469
+ if (command.id === _univerjs_sheets_data_validation.AddSheetDataValidationCommand.id) {
2470
+ const { unitId, subUnitId, rule: { ranges } } = command.params;
2471
+ if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
2472
+ workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
2473
+ rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint],
2474
+ worksheetTypes: [_univerjs_sheets.WorksheetEditPermission, _univerjs_sheets.WorksheetSetCellStylePermission]
2475
+ }, ranges, unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-data-validation-ui.permission.dialog.setStyleErr"));
2476
+ }
2477
+ if (command.id === _univerjs_sheets_data_validation.UpdateSheetDataValidationRangeCommand.id) {
2478
+ const { unitId, subUnitId, ranges } = command.params;
2479
+ if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
2480
+ workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
2481
+ rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint],
2482
+ worksheetTypes: [_univerjs_sheets.WorksheetEditPermission, _univerjs_sheets.WorksheetSetCellStylePermission]
2483
+ }, ranges, unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-data-validation-ui.permission.dialog.setStyleErr"));
2484
+ }
2485
+ }));
2486
+ }
2487
+ };
2488
+ DataValidationPermissionController = __decorate([
2489
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
2490
+ __decorateParam(1, _univerjs_core.ICommandService),
2491
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetPermissionCheckController))
2492
+ ], DataValidationPermissionController);
2493
+
2494
+ //#endregion
2495
+ //#region src/controllers/dv-render.controller.ts
2496
+ const INVALID_MARK = { tr: {
2497
+ size: 6,
2498
+ color: "#fe4b4b"
2499
+ } };
2500
+ let SheetsDataValidationRenderController = class SheetsDataValidationRenderController extends _univerjs_core.RxDisposable {
2501
+ constructor(_commandService, _menuManagerService, _renderManagerService, _univerInstanceService, _autoHeightController, _dropdownManagerService, _sheetDataValidationModel, _dataValidatorRegistryService, _sheetInterceptorService, _dataValidationCacheService, _editorBridgeService) {
2502
+ super();
2503
+ this._commandService = _commandService;
2504
+ this._menuManagerService = _menuManagerService;
2505
+ this._renderManagerService = _renderManagerService;
2506
+ this._univerInstanceService = _univerInstanceService;
2507
+ this._autoHeightController = _autoHeightController;
2508
+ this._dropdownManagerService = _dropdownManagerService;
2509
+ this._sheetDataValidationModel = _sheetDataValidationModel;
2510
+ this._dataValidatorRegistryService = _dataValidatorRegistryService;
2511
+ this._sheetInterceptorService = _sheetInterceptorService;
2512
+ this._dataValidationCacheService = _dataValidationCacheService;
2513
+ this._editorBridgeService = _editorBridgeService;
2514
+ this._initMenu();
2515
+ this._initDropdown();
2516
+ this._initViewModelIntercept();
2517
+ this._initAutoHeight();
2518
+ }
2519
+ _initMenu() {
2520
+ this._menuManagerService.mergeMenu(menuSchema);
2521
+ }
2522
+ _initDropdown() {
2523
+ if (!this._editorBridgeService) return;
2524
+ this.disposeWithMe(this._editorBridgeService.visible$.subscribe((visible) => {
2525
+ if (!visible.visible) {
2526
+ var _this$_dropdownManage;
2527
+ if (((_this$_dropdownManage = this._dropdownManagerService.activeDropdown) === null || _this$_dropdownManage === void 0 ? void 0 : _this$_dropdownManage.trigger) === "editor-bridge") this._dropdownManagerService.hideDropdown();
2528
+ return;
2529
+ }
2530
+ const state = this._editorBridgeService.getEditCellState();
2531
+ if (state) {
2532
+ const { unitId, sheetId, row, column } = state;
2533
+ const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
2534
+ if (!workbook) return;
2535
+ const rule = this._sheetDataValidationModel.getRuleByLocation(unitId, sheetId, row, column);
2536
+ if (!rule) return;
2537
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
2538
+ if (!(validator === null || validator === void 0 ? void 0 : validator.dropdownType)) return;
2539
+ const worksheet = workbook.getActiveSheet();
2540
+ if (!worksheet) return;
2541
+ const activeDropdown = this._dropdownManagerService.activeDropdown;
2542
+ const currLoc = activeDropdown === null || activeDropdown === void 0 ? void 0 : activeDropdown.location;
2543
+ if (currLoc && currLoc.unitId === unitId && currLoc.subUnitId === sheetId && currLoc.row === row && currLoc.col === column) return;
2544
+ this._dropdownManagerService.showDropdown({
2545
+ location: {
2546
+ unitId,
2547
+ subUnitId: sheetId,
2548
+ row,
2549
+ col: column,
2550
+ workbook,
2551
+ worksheet
2552
+ },
2553
+ trigger: "editor-bridge",
2554
+ closeOnOutSide: false
2465
2555
  });
2466
- },
2467
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2468
- value: "0",
2469
- children: localeService.t("sheets-data-validation-ui.list.customOptions")
2470
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2471
- value: "1",
2472
- children: localeService.t("sheets-data-validation-ui.list.refOptions")
2473
- })]
2474
- })
2475
- }), isFormulaStr === "1" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.FormLayout, {
2476
- error: formula1Res || localError || void 0,
2477
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_sheets_formula_ui.FormulaEditor, {
2478
- ref: formulaEditorRef,
2479
- className: (0, _univerjs_design.clsx)("univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent", _univerjs_design.borderClassName),
2480
- initValue: formulaStr,
2481
- unitId,
2482
- subUnitId,
2483
- isFocus: isFocusFormulaEditor,
2484
- isSupportAcrossSheet: true,
2485
- onFocus: () => setIsFocusFormulaEditor(true),
2486
- onChange: (v = "") => {
2487
- const str = (v !== null && v !== void 0 ? v : "").trim();
2488
- setFormulaStrCopy(str);
2489
- updateFormula(str);
2490
2556
  }
2491
- }), refFinalList.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2492
- className: "univer-mt-3",
2493
- children: refFinalList.map((item) => {
2494
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Template, {
2495
- className: "univer-mb-3",
2496
- item,
2497
- commonProps: { onItemChange: handleRefItemChange }
2498
- }, item.id);
2499
- })
2500
- })]
2501
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2502
- error: formula1Res,
2503
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DraggableList, {
2504
- list: strList,
2505
- onListChange: setStrList,
2506
- rowHeight: 28,
2507
- margin: [0, 12],
2508
- draggableHandle: ".draggableHandle",
2509
- itemRender: (item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Template, {
2510
- item,
2511
- commonProps: {
2512
- onItemChange: handleStrItemChange,
2513
- onItemDelete: handleStrItemDelete
2557
+ }));
2558
+ }
2559
+ _initViewModelIntercept() {
2560
+ this.disposeWithMe(this._sheetInterceptorService.intercept(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, {
2561
+ effect: _univerjs_core.InterceptorEffectEnum.Style,
2562
+ priority: _univerjs_sheets.InterceptCellContentPriority.DATA_VALIDATION,
2563
+ handler: (cell, pos, next) => {
2564
+ var _this$_dataValidation, _cell$customRender, _cell$fontRenderExten, _validator$skipDefaul, _cell$coverable;
2565
+ const { row, col, unitId, subUnitId, workbook, worksheet } = pos;
2566
+ const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, row, col);
2567
+ if (!ruleId) return next(cell);
2568
+ const rule = this._sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
2569
+ if (!rule) return next(cell);
2570
+ const validStatus = (_this$_dataValidation = this._dataValidationCacheService.getValue(unitId, subUnitId, row, col)) !== null && _this$_dataValidation !== void 0 ? _this$_dataValidation : _univerjs_core.DataValidationStatus.VALID;
2571
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
2572
+ const cellOrigin = pos.rawData;
2573
+ let cache;
2574
+ const cellValue = { get value() {
2575
+ var _getCellValueOrigin;
2576
+ if (cache !== void 0) return cache;
2577
+ cache = (_getCellValueOrigin = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(cellOrigin)) !== null && _getCellValueOrigin !== void 0 ? _getCellValueOrigin : null;
2578
+ return cache;
2579
+ } };
2580
+ const valueStr = { get value() {
2581
+ var _cellValue$value;
2582
+ return `${(_cellValue$value = cellValue.value) !== null && _cellValue$value !== void 0 ? _cellValue$value : ""}`;
2583
+ } };
2584
+ if (!cell || cell === pos.rawData) cell = { ...pos.rawData };
2585
+ cell.markers = {
2586
+ ...cell === null || cell === void 0 ? void 0 : cell.markers,
2587
+ ...validStatus === _univerjs_core.DataValidationStatus.INVALID ? INVALID_MARK : null
2588
+ };
2589
+ cell.customRender = [...(_cell$customRender = cell === null || cell === void 0 ? void 0 : cell.customRender) !== null && _cell$customRender !== void 0 ? _cell$customRender : [], ...(validator === null || validator === void 0 ? void 0 : validator.canvasRender) ? [validator.canvasRender] : []];
2590
+ cell.fontRenderExtension = {
2591
+ ...cell === null || cell === void 0 ? void 0 : cell.fontRenderExtension,
2592
+ isSkip: (cell === null || cell === void 0 || (_cell$fontRenderExten = cell.fontRenderExtension) === null || _cell$fontRenderExten === void 0 ? void 0 : _cell$fontRenderExten.isSkip) || (validator === null || validator === void 0 || (_validator$skipDefaul = validator.skipDefaultFontRender) === null || _validator$skipDefaul === void 0 ? void 0 : _validator$skipDefaul.call(validator, rule, cellValue.value, pos))
2593
+ };
2594
+ cell.interceptorStyle = {
2595
+ ...cell === null || cell === void 0 ? void 0 : cell.interceptorStyle,
2596
+ ...validator === null || validator === void 0 ? void 0 : validator.getExtraStyle(rule, valueStr.value, { get style() {
2597
+ const styleMap = workbook.getStyles();
2598
+ return (typeof (cell === null || cell === void 0 ? void 0 : cell.s) === "string" ? styleMap.get(cell === null || cell === void 0 ? void 0 : cell.s) : cell === null || cell === void 0 ? void 0 : cell.s) || {};
2599
+ } }, row, col)
2600
+ };
2601
+ cell.interceptorAutoHeight = () => {
2602
+ var _this$_renderManagerS, _mergeCell$startRow, _mergeCell$startColum, _validator$canvasRend, _validator$canvasRend2;
2603
+ const skeleton = (_this$_renderManagerS = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS === void 0 || (_this$_renderManagerS = _this$_renderManagerS.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.skeleton;
2604
+ if (!skeleton) return;
2605
+ const mergeCell = skeleton.worksheet.getMergedCell(row, col);
2606
+ const info = {
2607
+ data: cell,
2608
+ style: skeleton.getStyles().getStyleByCell(cell),
2609
+ primaryWithCoord: skeleton.getCellWithCoordByIndex((_mergeCell$startRow = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startRow) !== null && _mergeCell$startRow !== void 0 ? _mergeCell$startRow : row, (_mergeCell$startColum = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startColumn) !== null && _mergeCell$startColum !== void 0 ? _mergeCell$startColum : col),
2610
+ unitId,
2611
+ subUnitId,
2612
+ row,
2613
+ col,
2614
+ workbook,
2615
+ worksheet
2616
+ };
2617
+ return validator === null || validator === void 0 || (_validator$canvasRend = validator.canvasRender) === null || _validator$canvasRend === void 0 || (_validator$canvasRend2 = _validator$canvasRend.calcCellAutoHeight) === null || _validator$canvasRend2 === void 0 ? void 0 : _validator$canvasRend2.call(_validator$canvasRend, info);
2618
+ };
2619
+ cell.interceptorAutoWidth = () => {
2620
+ var _this$_renderManagerS2, _mergeCell$startRow2, _mergeCell$startColum2, _validator$canvasRend3, _validator$canvasRend4;
2621
+ const skeleton = (_this$_renderManagerS2 = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS2 === void 0 || (_this$_renderManagerS2 = _this$_renderManagerS2.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.skeleton;
2622
+ if (!skeleton) return;
2623
+ const mergeCell = skeleton.worksheet.getMergedCell(row, col);
2624
+ const info = {
2625
+ data: cell,
2626
+ style: skeleton.getStyles().getStyleByCell(cell),
2627
+ primaryWithCoord: skeleton.getCellWithCoordByIndex((_mergeCell$startRow2 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startRow) !== null && _mergeCell$startRow2 !== void 0 ? _mergeCell$startRow2 : row, (_mergeCell$startColum2 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startColumn) !== null && _mergeCell$startColum2 !== void 0 ? _mergeCell$startColum2 : col),
2628
+ unitId,
2629
+ subUnitId,
2630
+ row,
2631
+ col,
2632
+ workbook,
2633
+ worksheet
2634
+ };
2635
+ return validator === null || validator === void 0 || (_validator$canvasRend3 = validator.canvasRender) === null || _validator$canvasRend3 === void 0 || (_validator$canvasRend4 = _validator$canvasRend3.calcCellAutoWidth) === null || _validator$canvasRend4 === void 0 ? void 0 : _validator$canvasRend4.call(_validator$canvasRend3, info);
2636
+ };
2637
+ cell.coverable = ((_cell$coverable = cell === null || cell === void 0 ? void 0 : cell.coverable) !== null && _cell$coverable !== void 0 ? _cell$coverable : true) && !(rule.type === _univerjs_core.DataValidationType.LIST || rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE);
2638
+ return next(cell);
2639
+ }
2640
+ }));
2641
+ }
2642
+ _initAutoHeight() {
2643
+ this._sheetDataValidationModel.ruleChange$.pipe((0, rxjs.filter)((change) => change.source === "command"), (0, rxjs.bufferTime)(100)).subscribe((infos) => {
2644
+ if (infos.length === 0) return;
2645
+ const ranges = [];
2646
+ infos.forEach((info) => {
2647
+ if (info.rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE || info.rule.type === _univerjs_core.DataValidationType.LIST) {
2648
+ var _info$rule;
2649
+ if ((_info$rule = info.rule) === null || _info$rule === void 0 ? void 0 : _info$rule.ranges) ranges.push(...info.rule.ranges);
2514
2650
  }
2515
- }, item.id),
2516
- idKey: "id"
2517
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", {
2518
- className: "univer-text-primary univer-flex univer-w-fit univer-cursor-pointer univer-flex-row univer-items-center univer-rounded univer-p-1 univer-px-2 univer-text-sm hover:univer-bg-primary-50 dark:hover:!univer-bg-gray-800",
2519
- onClick: handleAdd,
2520
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.IncreaseIcon, { className: "univer-mr-1" }), localeService.t("sheets-data-validation-ui.list.add")]
2521
- })] })
2522
- })] });
2523
- }
2524
-
2525
- //#endregion
2526
- //#region src/views/components/formula-input/index.ts
2527
- const FORMULA_INPUTS = [
2528
- [_univerjs_sheets_data_validation.CUSTOM_FORMULA_INPUT_NAME, CustomFormulaInput],
2529
- [_univerjs_sheets_data_validation.BASE_FORMULA_INPUT_NAME, BaseFormulaInput],
2530
- [_univerjs_sheets_data_validation.LIST_FORMULA_INPUT_NAME, ListFormulaInput],
2531
- [_univerjs_sheets_data_validation.CHECKBOX_FORMULA_INPUT_NAME, CheckboxFormulaInput]
2532
- ];
2651
+ });
2652
+ if (ranges.length) (0, _univerjs_core.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(ranges).redos, this._commandService);
2653
+ });
2654
+ }
2655
+ };
2656
+ SheetsDataValidationRenderController = __decorate([
2657
+ __decorateParam(0, _univerjs_core.ICommandService),
2658
+ __decorateParam(1, _univerjs_ui.IMenuManagerService),
2659
+ __decorateParam(2, _univerjs_engine_render.IRenderManagerService),
2660
+ __decorateParam(3, _univerjs_core.IUniverInstanceService),
2661
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.AutoHeightController)),
2662
+ __decorateParam(5, (0, _univerjs_core.Inject)(DataValidationDropdownManagerService)),
2663
+ __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
2664
+ __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService)),
2665
+ __decorateParam(8, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
2666
+ __decorateParam(9, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.DataValidationCacheService)),
2667
+ __decorateParam(10, (0, _univerjs_core.Optional)(_univerjs_sheets_ui.IEditorBridgeService))
2668
+ ], SheetsDataValidationRenderController);
2669
+ let SheetsDataValidationMobileRenderController = class SheetsDataValidationMobileRenderController extends _univerjs_core.RxDisposable {
2670
+ constructor(_commandService, _renderManagerService, _autoHeightController, _dataValidatorRegistryService, _sheetInterceptorService, _sheetDataValidationModel, _dataValidationCacheService) {
2671
+ super();
2672
+ this._commandService = _commandService;
2673
+ this._renderManagerService = _renderManagerService;
2674
+ this._autoHeightController = _autoHeightController;
2675
+ this._dataValidatorRegistryService = _dataValidatorRegistryService;
2676
+ this._sheetInterceptorService = _sheetInterceptorService;
2677
+ this._sheetDataValidationModel = _sheetDataValidationModel;
2678
+ this._dataValidationCacheService = _dataValidationCacheService;
2679
+ this._initViewModelIntercept();
2680
+ this._initAutoHeight();
2681
+ }
2682
+ _initViewModelIntercept() {
2683
+ this.disposeWithMe(this._sheetInterceptorService.intercept(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, {
2684
+ effect: _univerjs_core.InterceptorEffectEnum.Style,
2685
+ priority: _univerjs_sheets.InterceptCellContentPriority.DATA_VALIDATION,
2686
+ handler: (cell, pos, next) => {
2687
+ var _this$_dataValidation2, _cell$customRender2, _cell$fontRenderExten2, _validator$skipDefaul2, _cell$coverable2;
2688
+ const { row, col, unitId, subUnitId, workbook, worksheet } = pos;
2689
+ const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, row, col);
2690
+ if (!ruleId) return next(cell);
2691
+ const rule = this._sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
2692
+ if (!rule) return next(cell);
2693
+ const validStatus = (_this$_dataValidation2 = this._dataValidationCacheService.getValue(unitId, subUnitId, row, col)) !== null && _this$_dataValidation2 !== void 0 ? _this$_dataValidation2 : _univerjs_core.DataValidationStatus.VALID;
2694
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
2695
+ const cellValue = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(worksheet.getCellRaw(row, col));
2696
+ const valueStr = `${cellValue !== null && cellValue !== void 0 ? cellValue : ""}`;
2697
+ if (!cell || cell === pos.rawData) cell = { ...pos.rawData };
2698
+ cell.markers = {
2699
+ ...cell === null || cell === void 0 ? void 0 : cell.markers,
2700
+ ...validStatus === _univerjs_core.DataValidationStatus.INVALID ? INVALID_MARK : null
2701
+ };
2702
+ cell.customRender = [...(_cell$customRender2 = cell === null || cell === void 0 ? void 0 : cell.customRender) !== null && _cell$customRender2 !== void 0 ? _cell$customRender2 : [], ...(validator === null || validator === void 0 ? void 0 : validator.canvasRender) ? [validator.canvasRender] : []];
2703
+ cell.fontRenderExtension = {
2704
+ ...cell === null || cell === void 0 ? void 0 : cell.fontRenderExtension,
2705
+ isSkip: (cell === null || cell === void 0 || (_cell$fontRenderExten2 = cell.fontRenderExtension) === null || _cell$fontRenderExten2 === void 0 ? void 0 : _cell$fontRenderExten2.isSkip) || (validator === null || validator === void 0 || (_validator$skipDefaul2 = validator.skipDefaultFontRender) === null || _validator$skipDefaul2 === void 0 ? void 0 : _validator$skipDefaul2.call(validator, rule, cellValue, pos))
2706
+ };
2707
+ cell.interceptorStyle = {
2708
+ ...cell === null || cell === void 0 ? void 0 : cell.interceptorStyle,
2709
+ ...validator === null || validator === void 0 ? void 0 : validator.getExtraStyle(rule, valueStr, { get style() {
2710
+ const styleMap = workbook.getStyles();
2711
+ return (typeof (cell === null || cell === void 0 ? void 0 : cell.s) === "string" ? styleMap.get(cell === null || cell === void 0 ? void 0 : cell.s) : cell === null || cell === void 0 ? void 0 : cell.s) || {};
2712
+ } }, row, col)
2713
+ };
2714
+ cell.interceptorAutoHeight = () => {
2715
+ var _this$_renderManagerS3, _mergeCell$startRow3, _mergeCell$startColum3, _validator$canvasRend5, _validator$canvasRend6;
2716
+ const skeleton = (_this$_renderManagerS3 = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS3 === void 0 || (_this$_renderManagerS3 = _this$_renderManagerS3.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _this$_renderManagerS3 === void 0 ? void 0 : _this$_renderManagerS3.skeleton;
2717
+ if (!skeleton) return;
2718
+ const mergeCell = skeleton.worksheet.getMergedCell(row, col);
2719
+ const info = {
2720
+ data: cell,
2721
+ style: skeleton.getStyles().getStyleByCell(cell),
2722
+ primaryWithCoord: skeleton.getCellWithCoordByIndex((_mergeCell$startRow3 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startRow) !== null && _mergeCell$startRow3 !== void 0 ? _mergeCell$startRow3 : row, (_mergeCell$startColum3 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startColumn) !== null && _mergeCell$startColum3 !== void 0 ? _mergeCell$startColum3 : col),
2723
+ unitId,
2724
+ subUnitId,
2725
+ row,
2726
+ col,
2727
+ workbook,
2728
+ worksheet
2729
+ };
2730
+ return validator === null || validator === void 0 || (_validator$canvasRend5 = validator.canvasRender) === null || _validator$canvasRend5 === void 0 || (_validator$canvasRend6 = _validator$canvasRend5.calcCellAutoHeight) === null || _validator$canvasRend6 === void 0 ? void 0 : _validator$canvasRend6.call(_validator$canvasRend5, info);
2731
+ };
2732
+ cell.interceptorAutoWidth = () => {
2733
+ var _this$_renderManagerS4, _mergeCell$startRow4, _mergeCell$startColum4, _validator$canvasRend7, _validator$canvasRend8;
2734
+ const skeleton = (_this$_renderManagerS4 = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS4 === void 0 || (_this$_renderManagerS4 = _this$_renderManagerS4.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _this$_renderManagerS4 === void 0 ? void 0 : _this$_renderManagerS4.skeleton;
2735
+ if (!skeleton) return;
2736
+ const mergeCell = skeleton.worksheet.getMergedCell(row, col);
2737
+ const info = {
2738
+ data: cell,
2739
+ style: skeleton.getStyles().getStyleByCell(cell),
2740
+ primaryWithCoord: skeleton.getCellWithCoordByIndex((_mergeCell$startRow4 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startRow) !== null && _mergeCell$startRow4 !== void 0 ? _mergeCell$startRow4 : row, (_mergeCell$startColum4 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startColumn) !== null && _mergeCell$startColum4 !== void 0 ? _mergeCell$startColum4 : col),
2741
+ unitId,
2742
+ subUnitId,
2743
+ row,
2744
+ col,
2745
+ workbook,
2746
+ worksheet
2747
+ };
2748
+ return validator === null || validator === void 0 || (_validator$canvasRend7 = validator.canvasRender) === null || _validator$canvasRend7 === void 0 || (_validator$canvasRend8 = _validator$canvasRend7.calcCellAutoWidth) === null || _validator$canvasRend8 === void 0 ? void 0 : _validator$canvasRend8.call(_validator$canvasRend7, info);
2749
+ };
2750
+ cell.coverable = ((_cell$coverable2 = cell === null || cell === void 0 ? void 0 : cell.coverable) !== null && _cell$coverable2 !== void 0 ? _cell$coverable2 : true) && !(rule.type === _univerjs_core.DataValidationType.LIST || rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE);
2751
+ return next(cell);
2752
+ }
2753
+ }));
2754
+ }
2755
+ _initAutoHeight() {
2756
+ this._sheetDataValidationModel.ruleChange$.pipe((0, rxjs.filter)((change) => change.source === "command"), (0, rxjs.bufferTime)(16)).subscribe((infos) => {
2757
+ const ranges = [];
2758
+ infos.forEach((info) => {
2759
+ if (info.rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE || info.rule.type === _univerjs_core.DataValidationType.LIST) {
2760
+ var _info$rule2;
2761
+ if ((_info$rule2 = info.rule) === null || _info$rule2 === void 0 ? void 0 : _info$rule2.ranges) ranges.push(...info.rule.ranges);
2762
+ }
2763
+ });
2764
+ if (ranges.length) (0, _univerjs_core.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(ranges).redos, this._commandService);
2765
+ });
2766
+ }
2767
+ };
2768
+ SheetsDataValidationMobileRenderController = __decorate([
2769
+ __decorateParam(0, _univerjs_core.ICommandService),
2770
+ __decorateParam(1, _univerjs_engine_render.IRenderManagerService),
2771
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.AutoHeightController)),
2772
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService)),
2773
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
2774
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
2775
+ __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.DataValidationCacheService))
2776
+ ], SheetsDataValidationMobileRenderController);
2533
2777
 
2534
2778
  //#endregion
2535
- //#region src/views/components/ListRenderModeInput.tsx
2536
- const LIST_RENDER_MODE_OPTION_INPUT = "LIST_RENDER_MODE_OPTION_INPUT";
2537
- function ListRenderModeInput(props) {
2538
- var _value$renderMode;
2539
- const { value, onChange } = props;
2540
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2541
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2542
- label: localeService.t("sheets-data-validation-ui.renderMode.label"),
2543
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
2544
- value: `${(_value$renderMode = value.renderMode) !== null && _value$renderMode !== void 0 ? _value$renderMode : _univerjs_core.DataValidationRenderMode.CUSTOM}`,
2545
- onChange: (renderMode) => onChange({
2546
- ...value,
2547
- renderMode: +renderMode
2548
- }),
2549
- children: [
2550
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2551
- value: `${_univerjs_core.DataValidationRenderMode.CUSTOM}`,
2552
- children: localeService.t("sheets-data-validation-ui.renderMode.chip")
2553
- }),
2554
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2555
- value: `${_univerjs_core.DataValidationRenderMode.ARROW}`,
2556
- children: localeService.t("sheets-data-validation-ui.renderMode.arrow")
2557
- }),
2558
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2559
- value: `${_univerjs_core.DataValidationRenderMode.TEXT}`,
2560
- children: localeService.t("sheets-data-validation-ui.renderMode.text")
2561
- })
2562
- ]
2563
- })
2564
- });
2565
- }
2566
- ListRenderModeInput.componentKey = LIST_RENDER_MODE_OPTION_INPUT;
2779
+ //#region src/controllers/dv-rerender.controller.ts
2780
+ let SheetsDataValidationReRenderController = class SheetsDataValidationReRenderController extends _univerjs_core.Disposable {
2781
+ constructor(_context, _sheetDataValidationModel, _sheetSkeletonManagerService) {
2782
+ super();
2783
+ this._context = _context;
2784
+ this._sheetDataValidationModel = _sheetDataValidationModel;
2785
+ this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
2786
+ this._initSkeletonChange();
2787
+ }
2788
+ _initSkeletonChange() {
2789
+ const reRender = (values) => {
2790
+ var _this$_context$mainCo;
2791
+ if (!values.length) return;
2792
+ const sheetIds = /* @__PURE__ */ new Set();
2793
+ values.forEach((value) => {
2794
+ sheetIds.add(value.subUnitId);
2795
+ });
2796
+ sheetIds.forEach((sheetId) => {
2797
+ var _this$_sheetSkeletonM;
2798
+ (_this$_sheetSkeletonM = this._sheetSkeletonManagerService.getSkeletonParam(sheetId)) === null || _this$_sheetSkeletonM === void 0 || _this$_sheetSkeletonM.skeleton.makeDirty(true);
2799
+ });
2800
+ (_this$_context$mainCo = this._context.mainComponent) === null || _this$_context$mainCo === void 0 || _this$_context$mainCo.makeForceDirty();
2801
+ };
2802
+ this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe((0, _univerjs_core.bufferDebounceTime)(16)).subscribe(reRender));
2803
+ }
2804
+ };
2805
+ SheetsDataValidationReRenderController = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)), __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.SheetSkeletonManagerService))], SheetsDataValidationReRenderController);
2567
2806
 
2568
2807
  //#endregion
2569
2808
  //#region src/views/widgets/checkbox-widget.ts
@@ -3561,24 +3800,12 @@ var WholeValidatorView = class extends BaseSheetDataValidatorView {
3561
3800
  //#endregion
3562
3801
  //#region src/controllers/ui.controller.ts
3563
3802
  let SheetsDataValidationUIController = class SheetsDataValidationUIController extends _univerjs_core.RxDisposable {
3564
- constructor(_injector, _componentManger, _dataValidatorRegistryService) {
3803
+ constructor(_injector, _dataValidatorRegistryService) {
3565
3804
  super();
3566
3805
  this._injector = _injector;
3567
- this._componentManger = _componentManger;
3568
3806
  this._dataValidatorRegistryService = _dataValidatorRegistryService;
3569
- this._initComponents();
3570
3807
  this._registerValidatorViews();
3571
3808
  }
3572
- _initComponents() {
3573
- [
3574
- [DATA_VALIDATION_PANEL, DataValidationPanel],
3575
- [ListRenderModeInput.componentKey, ListRenderModeInput],
3576
- [DateShowTimeOption.componentKey, DateShowTimeOption],
3577
- ...FORMULA_INPUTS
3578
- ].forEach(([key, comp]) => {
3579
- this.disposeWithMe(this._componentManger.register(key, comp));
3580
- });
3581
- }
3582
3809
  _registerValidatorViews() {
3583
3810
  [
3584
3811
  DecimalValidatorView,
@@ -3601,11 +3828,7 @@ let SheetsDataValidationUIController = class SheetsDataValidationUIController ex
3601
3828
  });
3602
3829
  }
3603
3830
  };
3604
- SheetsDataValidationUIController = __decorate([
3605
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
3606
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)),
3607
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService))
3608
- ], SheetsDataValidationUIController);
3831
+ SheetsDataValidationUIController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService))], SheetsDataValidationUIController);
3609
3832
 
3610
3833
  //#endregion
3611
3834
  //#region src/mobile-plugin.ts
@@ -3637,6 +3860,8 @@ let UniverSheetsDataValidationMobileUIPlugin = class UniverSheetsDataValidationM
3637
3860
  });
3638
3861
  [
3639
3862
  AddSheetDataValidationAndOpenCommand,
3863
+ InsertQuickSheetDataValidationCommand,
3864
+ ClearQuickSheetDataValidationCommand,
3640
3865
  ShowDataValidationDropdown,
3641
3866
  HideDataValidationDropdown,
3642
3867
  CloseValidationPanelOperation,
@@ -3700,6 +3925,8 @@ let UniverSheetsDataValidationUIPlugin = class UniverSheetsDataValidationUIPlugi
3700
3925
  });
3701
3926
  [
3702
3927
  AddSheetDataValidationAndOpenCommand,
3928
+ InsertQuickSheetDataValidationCommand,
3929
+ ClearQuickSheetDataValidationCommand,
3703
3930
  ShowDataValidationDropdown,
3704
3931
  HideDataValidationDropdown,
3705
3932
  CloseValidationPanelOperation,