@univerjs/sheets-data-validation-ui 1.0.0-alpha.3 → 1.0.0-alpha.4

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 +1533 -1292
  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 +1539 -1298
  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 +1539 -1298
  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 +15 -15
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,936 +950,251 @@ 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-alpha.3";
985
+ var version = "1.0.0-alpha.4";
755
986
 
756
987
  //#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);
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
+ }
785
1042
 
786
1043
  //#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();
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()) || "";
801
1054
  }
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;
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]);
1102
+ };
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
+ })));
824
1119
  }
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
- }
1120
+ }, 20);
841
1121
  }
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);
853
-
854
- //#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();
863
- }
864
- _initAutoFill() {
865
- const noopReturnFunc = () => ({
866
- redos: [],
867
- undos: []
868
1122
  });
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
- };
927
- };
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;
937
- }
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: () => {}
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);
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
995
1174
  });
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
- });
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());
1181
+ }
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
1003
1192
  });
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
- };
1022
- }
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);
1424
- });
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]);
1581
- };
1582
- }, [sheetSelectionService]);
1583
- (0, react.useEffect)(() => {
1584
- commandService.onCommandExecuted((commandInfo) => {
1585
- if (commandInfo.id === _univerjs_core.UndoCommand.id || commandInfo.id === _univerjs_core.RedoCommand.id) setTimeout(() => {
1586
- const activeRule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1587
- setKey((k) => k + 1);
1588
- if (activeRule) {
1589
- setLocalRule(activeRule);
1590
- setLocalRanges(activeRule.ranges.map((i) => ({
1591
- unitId: "",
1592
- sheetId: "",
1593
- range: i
1594
- })));
1595
- }
1596
- }, 20);
1597
- });
1598
- }, [
1599
- commandService,
1600
- dataValidationModel,
1601
- ruleId,
1602
- subUnitId,
1603
- unitId
1604
- ]);
1605
- if (!validator) return null;
1606
- const operators = validator.operators;
1607
- const operatorNames = validator.operatorNames;
1608
- const isTwoFormula = localRule.operator ? _univerjs_data_validation.TWO_FORMULA_OPERATOR_COUNT.includes(localRule.operator) : false;
1609
- const goBackActiveRuleSheet = () => {
1610
- if ((worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId()) !== subUnitId) commandService.syncExecuteCommand(_univerjs_sheets.SetWorksheetActiveOperation.id, {
1611
- unitId,
1612
- subUnitId
1613
- });
1614
- };
1615
- const handleOk = () => {
1616
- var _rangeSelectorInstanc;
1617
- if ((_rangeSelectorInstanc = rangeSelectorInstance.current) === null || _rangeSelectorInstanc === void 0 || (_rangeSelectorInstanc = _rangeSelectorInstanc.editor) === null || _rangeSelectorInstanc === void 0 ? void 0 : _rangeSelectorInstanc.isFocus()) {
1618
- var _rangeSelectorInstanc2;
1619
- handleUpdateRuleRanges((_rangeSelectorInstanc2 = rangeSelectorInstance.current) === null || _rangeSelectorInstanc2 === void 0 ? void 0 : _rangeSelectorInstanc2.getValue());
1620
- }
1621
- if (!localRule.ranges.length || isRangeError) return;
1622
- if (validator.validatorFormula(localRule, unitId, subUnitId).success) dataValidationPanelService.setActiveRule(null);
1623
- else setShowError(true);
1624
- goBackActiveRuleSheet();
1625
- };
1626
- const handleUpdateRuleRanges = (0, _univerjs_ui.useEvent)((rangeText) => {
1627
- const unitRanges = rangeText.split(",").filter(Boolean).map(_univerjs_engine_formula.deserializeRangeWithSheet).map((unitRange) => {
1628
- const sheetName = unitRange.sheetName;
1629
- if (sheetName) {
1630
- const sheetId = getSheetIdByName(univerInstanceService, unitRange.unitId, sheetName);
1631
- return {
1632
- ...unitRange,
1633
- sheetId
1634
- };
1635
- }
1636
- return {
1637
- ...unitRange,
1638
- sheetId: ""
1639
- };
1640
- });
1641
- if ((0, _univerjs_core.isUnitRangesEqual)(unitRanges, localRanges)) return;
1642
- setLocalRanges(unitRanges);
1643
- const ranges = unitRanges.filter((i) => (!i.unitId || i.unitId === unitId) && (!i.sheetId || i.sheetId === subUnitId)).map((i) => i.range);
1644
- setLocalRule({
1645
- ...localRule,
1646
- ranges
1647
- });
1648
- if (ranges.length === 0) return;
1649
- const params = {
1650
- unitId,
1651
- subUnitId,
1652
- ruleId,
1653
- ranges
1654
- };
1655
- debounceExecute(_univerjs_sheets_data_validation.UpdateSheetDataValidationRangeCommand.id, params);
1656
- });
1657
- const handleUpdateRuleSetting = (setting) => {
1658
- if ((0, _univerjs_core.shallowEqual)(setting, (0, _univerjs_data_validation.getRuleSetting)(localRule))) return;
1659
- setLocalRule({
1660
- ...localRule,
1661
- ...setting
1662
- });
1663
- const params = {
1664
- unitId,
1665
- subUnitId,
1666
- ruleId,
1667
- setting
1193
+ const params = {
1194
+ unitId,
1195
+ subUnitId,
1196
+ ruleId,
1197
+ setting
1668
1198
  };
1669
1199
  debounceExecute(_univerjs_sheets_data_validation.UpdateSheetDataValidationSettingCommand.id, params, void 0);
1670
1200
  };
@@ -1708,7 +1238,6 @@ function DataValidationDetailInner(props) {
1708
1238
  });
1709
1239
  };
1710
1240
  const FormulaInput = componentManager.get(validator.formulaInput);
1711
- const rangeStr = (0, react.useMemo)(() => localRanges.map((i) => (0, _univerjs_engine_formula.serializeRange)(i.range)).join(","), []);
1712
1241
  const options = (0, _univerjs_data_validation.getRuleOptions)(localRule);
1713
1242
  const handleUpdateRuleOptions = (newOptions) => {
1714
1243
  if ((0, _univerjs_core.shallowEqual)(newOptions, (0, _univerjs_data_validation.getRuleOptions)(localRule))) return;
@@ -1921,23 +1450,14 @@ function DataValidationList(props) {
1921
1450
  const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
1922
1451
  const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
1923
1452
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1924
- const [rules, setRules] = (0, react.useState)([]);
1925
1453
  const { workbook } = props;
1926
1454
  const worksheet = (0, _univerjs_ui.useObservable)(workbook.activeSheet$, void 0, true);
1927
1455
  const unitId = workbook.getUnitId();
1928
1456
  const subUnitId = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId();
1929
- (0, react.useEffect)(() => {
1930
- setRules(sheetDataValidationModel.getRules(unitId, subUnitId));
1931
- const subscription = sheetDataValidationModel.ruleChange$.subscribe((change) => {
1932
- if (change.unitId === unitId && change.subUnitId === subUnitId) setRules(sheetDataValidationModel.getRules(unitId, subUnitId));
1933
- });
1934
- return () => {
1935
- subscription.unsubscribe();
1936
- };
1937
- }, [
1938
- unitId,
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,
1939
1459
  subUnitId,
1940
- sheetDataValidationModel
1460
+ unitId
1941
1461
  ]);
1942
1462
  const handleAddRule = async () => {
1943
1463
  const rule = (0, _univerjs_sheets_data_validation.createDefaultNewRule)(injector);
@@ -2151,47 +1671,414 @@ function CheckboxFormulaInput(props) {
2151
1671
  });
2152
1672
  }
2153
1673
  })
2154
- }) : null
2155
- ] });
2156
- }
2157
-
2158
- //#endregion
2159
- //#region src/views/components/formula-input/CustomFormulaInput.tsx
2160
- function CustomFormulaInput(props) {
2161
- var _value$formula;
2162
- const { unitId, subUnitId, value, onChange, showError, validResult } = props;
2163
- const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : void 0;
1674
+ }) : null
1675
+ ] });
1676
+ }
1677
+
1678
+ //#endregion
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 : "=",
1696
+ unitId,
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
1706
+ });
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),
1805
+ children: [
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, {})
1809
+ }),
1810
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ColorSelect, {
1811
+ value: item.color,
1812
+ onChange: (color) => {
1813
+ onItemChange(item.id, item.label, color);
1814
+ }
1815
+ }),
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) })
1826
+ })
1827
+ ]
1828
+ });
1829
+ };
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 : "=");
1837
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
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);
1849
+ (0, react.useEffect)(() => {
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);
1857
+ return () => {
1858
+ cancelled = true;
1859
+ clearTimeout(timer);
1860
+ };
1861
+ }, [
1862
+ dataValidationModel,
1863
+ ruleChange,
1864
+ listValidator,
1865
+ ruleId,
1866
+ subUnitId,
1867
+ unitId
1868
+ ]);
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]);
1891
+ };
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
+ }
1898
+ };
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(",")
1912
+ });
1913
+ };
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
1942
+ });
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
+ }
1952
+ });
2164
1953
  const formulaEditorRef = (0, react.useRef)(null);
2165
1954
  const [isFocusFormulaEditor, setIsFocusFormulaEditor] = (0, react.useState)(false);
2166
1955
  (0, _univerjs_ui.useSidebarClick)((e) => {
2167
1956
  var _formulaEditorRef$cur;
2168
1957
  !((_formulaEditorRef$cur = formulaEditorRef.current) === null || _formulaEditorRef$cur === void 0) && _formulaEditorRef$cur.isClickOutSide(e) && setIsFocusFormulaEditor(false);
2169
1958
  });
2170
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2171
- error: formula1Res,
2172
- 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, {
2173
1990
  ref: formulaEditorRef,
2174
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),
2175
- initValue: (_value$formula = value === null || value === void 0 ? void 0 : value.formula1) !== null && _value$formula !== void 0 ? _value$formula : "=",
1992
+ initValue: formulaStr,
2176
1993
  unitId,
2177
1994
  subUnitId,
2178
1995
  isFocus: isFocusFormulaEditor,
2179
1996
  isSupportAcrossSheet: true,
2180
- onChange: (newValue) => {
2181
- const newFormula = (newValue !== null && newValue !== void 0 ? newValue : "").trim();
2182
- if (newFormula === (value === null || value === void 0 ? void 0 : value.formula1)) return;
2183
- onChange === null || onChange === void 0 || onChange({
2184
- ...value,
2185
- formula1: newFormula
2186
- });
2187
- },
2188
- 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
+ ]
2189
2075
  })
2190
2076
  });
2191
2077
  }
2078
+ ListRenderModeInput.componentKey = LIST_RENDER_MODE_OPTION_INPUT;
2192
2079
 
2193
2080
  //#endregion
2194
- //#region src/views/components/formula-input/utils.ts
2081
+ //#region src/controllers/components.controller.ts
2195
2082
  /**
2196
2083
  * Copyright 2023-present DreamNum Co., Ltd.
2197
2084
  *
@@ -2207,349 +2094,715 @@ function CustomFormulaInput(props) {
2207
2094
  * See the License for the specific language governing permissions and
2208
2095
  * limitations under the License.
2209
2096
  */
2210
- function buildCustomListFormulaPayload(items, defaultColor) {
2211
- const labelSet = /* @__PURE__ */ new Set();
2212
- const finalList = [];
2213
- items.forEach((item) => {
2214
- if (!item.label || labelSet.has(item.label)) return;
2215
- labelSet.add(item.label);
2216
- finalList.push(item);
2217
- });
2218
- return {
2219
- formula1: (0, _univerjs_sheets.serializeListOptions)(finalList.map((item) => item.label)),
2220
- formula2: finalList.map((item) => item.color === defaultColor ? "" : item.color).join(",")
2221
- };
2222
- }
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);
2223
2126
 
2224
2127
  //#endregion
2225
- //#region src/views/components/formula-input/ListFormulaInput.tsx
2226
- const DEFAULT_COLOR_PRESET = [
2227
- "#FFFFFF",
2228
- "#FEE7E7",
2229
- "#FEF0E6",
2230
- "#EFFBD0",
2231
- "#E4F4FE",
2232
- "#E8ECFD",
2233
- "#F1EAFA",
2234
- "#FDE8F3",
2235
- "#E5E5E5",
2236
- "#FDCECE",
2237
- "#FDC49B",
2238
- "#DEF6A2",
2239
- "#9FDAFF",
2240
- "#D0D9FB",
2241
- "#E3D5F6",
2242
- "#FBD0E8",
2243
- "#656565",
2244
- "#FE4B4B",
2245
- "#FF8C51",
2246
- "#8BBB11",
2247
- "#0B9EFB",
2248
- "#3A60F7",
2249
- "#9E6DE3",
2250
- "#F248A6"
2251
- ];
2252
- const ColorSelect = (props) => {
2253
- const { value, onChange, disabled } = props;
2254
- const [open, setOpen] = (0, react.useState)(false);
2255
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
2256
- align: "start",
2257
- disabled,
2258
- open,
2259
- onOpenChange: setOpen,
2260
- overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2261
- className: "univer-box-border univer-grid univer-w-fit univer-grid-cols-6 univer-flex-wrap univer-gap-2 univer-p-1.5",
2262
- children: DEFAULT_COLOR_PRESET.map((color) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2263
- className: (0, _univerjs_design.clsx)("univer-box-border univer-size-4 univer-cursor-pointer univer-rounded", _univerjs_design.borderClassName),
2264
- style: { background: color },
2265
- onClick: () => {
2266
- onChange(color);
2267
- 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;
2268
2153
  }
2269
- }, color))
2270
- }),
2271
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2272
- 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),
2273
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2274
- className: "univer-box-border univer-size-4 univer-rounded univer-text-base",
2275
- style: { background: value }
2276
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, {})]
2277
- })
2278
- });
2279
- };
2280
- const Template = (props) => {
2281
- const { item, commonProps, className } = props;
2282
- const { onItemChange, onItemDelete } = commonProps;
2283
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2284
- className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-gap-2", className),
2285
- children: [
2286
- !item.isRef && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2287
- className: (0, _univerjs_design.clsx)("univer-cursor-move", "draggableHandle"),
2288
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.GripVerticalIcon, {})
2289
- }),
2290
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ColorSelect, {
2291
- value: item.color,
2292
- onChange: (color) => {
2293
- 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;
2294
2181
  }
2295
- }),
2296
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
2297
- disabled: item.isRef,
2298
- value: item.label,
2299
- onChange: (label) => {
2300
- 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
+ }
2301
2279
  }
2302
- }),
2303
- item.isRef ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2304
- className: "univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base hover:univer-bg-gray-200",
2305
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, { onClick: () => onItemDelete(item.id) })
2306
- })
2307
- ]
2308
- });
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
+ }
2309
2289
  };
2310
- const NOOP = () => {};
2311
- function ListFormulaInput(props) {
2312
- const { value, onChange: _onChange = NOOP, unitId, subUnitId, validResult, showError, ruleId } = props;
2313
- const { formula1 = "", formula2 = "" } = value || {};
2314
- const [isFormulaStr, setIsFormulaStr] = (0, react.useState)(() => (0, _univerjs_core.isFormulaString)(formula1) ? "1" : "0");
2315
- const [formulaStr, setFormulaStr] = (0, react.useState)(isFormulaStr === "1" ? formula1 : "=");
2316
- const [formulaStrCopy, setFormulaStrCopy] = (0, react.useState)(isFormulaStr === "1" ? formula1 : "=");
2317
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2318
- const dataValidatorRegistryService = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidatorRegistryService);
2319
- const dataValidationModel = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidationModel);
2320
- const dataValidationFormulaController = (0, _univerjs_ui.useDependency)(_univerjs_sheets_data_validation.DataValidationFormulaController);
2321
- const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
2322
- const [refColors, setRefColors] = (0, react.useState)(() => formula2.split(","));
2323
- const listValidator = dataValidatorRegistryService.getValidatorItem(_univerjs_core.DataValidationType.LIST);
2324
- const [refOptions, setRefOptions] = (0, react.useState)([]);
2325
- const [localError, setLocalError] = (0, react.useState)("");
2326
- const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : "";
2327
- const ruleChange = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => dataValidationModel.ruleChange$.pipe((0, rxjs.debounceTime)(16)), []));
2328
- const onChange = (0, _univerjs_ui.useEvent)(_onChange);
2329
- (0, react.useEffect)(() => {
2330
- (async () => {
2331
- await (0, _univerjs_core.awaitTime)(100);
2332
- const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
2333
- if ((0, _univerjs_core.isFormulaString)(rule === null || rule === void 0 ? void 0 : rule.formula1) && listValidator && rule) setRefOptions(await listValidator.getListAsync(rule, unitId, subUnitId));
2334
- })();
2335
- }, [
2336
- dataValidationModel,
2337
- ruleChange,
2338
- listValidator,
2339
- ruleId,
2340
- subUnitId,
2341
- unitId
2342
- ]);
2343
- (0, react.useEffect)(() => {
2344
- if ((0, _univerjs_core.isFormulaString)(formula1) && formula1 !== formulaStrCopy) {
2345
- setFormulaStr(formula1);
2346
- setFormulaStrCopy(formulaStrCopy);
2347
- }
2348
- }, [formulaStrCopy, formula1]);
2349
- const [strList, setStrList] = (0, react.useState)(() => {
2350
- const strOptions = isFormulaStr !== "1" ? (0, _univerjs_sheets.deserializeListOptions)(formula1) : [];
2351
- const strColors = formula2.split(",");
2352
- return strOptions.map((label, i) => ({
2353
- label,
2354
- color: strColors[i] || "#ECECEC",
2355
- isRef: false,
2356
- id: (0, _univerjs_core.generateRandomId)(4)
2357
- }));
2358
- });
2359
- const handleStrItemChange = (id, value, color) => {
2360
- const item = strList.find((i) => i.id === id);
2361
- if (!item) return;
2362
- item.label = value;
2363
- item.color = color;
2364
- setStrList([...strList]);
2365
- };
2366
- const handleStrItemDelete = (id) => {
2367
- const index = strList.findIndex((i) => i.id === id);
2368
- if (index !== -1) {
2369
- strList.splice(index, 1);
2370
- setStrList([...strList]);
2371
- }
2372
- };
2373
- const refFinalList = (0, react.useMemo)(() => refOptions.map((label, i) => ({
2374
- label,
2375
- color: refColors[i] || "#ECECEC",
2376
- id: `${i}`,
2377
- isRef: true
2378
- })), [refColors, refOptions]);
2379
- const handleRefItemChange = (id, value, color) => {
2380
- const newColors = [...refColors];
2381
- newColors[+id] = color;
2382
- setRefColors(newColors);
2383
- onChange({
2384
- formula1,
2385
- formula2: newColors.join(",")
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
+ }
2386
2325
  });
2387
- };
2388
- const handleAdd = () => {
2389
- setStrList([...strList, {
2390
- label: "",
2391
- color: DROP_DOWN_DEFAULT_COLOR,
2392
- isRef: false,
2393
- id: (0, _univerjs_core.generateRandomId)(4)
2394
- }]);
2395
- };
2396
- (0, react.useEffect)(() => {
2397
- if (isFormulaStr === "1") return;
2398
- onChange(buildCustomListFormulaPayload(strList, DROP_DOWN_DEFAULT_COLOR));
2399
- }, [
2400
- strList,
2401
- onChange,
2402
- isFormulaStr
2403
- ]);
2404
- const updateFormula = (0, _univerjs_ui.useEvent)(async (str) => {
2405
- if (!(0, _univerjs_core.isFormulaString)(str)) {
2406
- onChange === null || onChange === void 0 || onChange({
2407
- formula1: "",
2408
- formula2
2326
+ }
2327
+ _collect(unitId, subUnitId, range) {
2328
+ const matrix = new _univerjs_core.ObjectMatrix();
2329
+ this._copyInfo = {
2330
+ unitId,
2331
+ subUnitId,
2332
+ matrix
2333
+ };
2334
+ const discreteRange = this._injector.invoke((accessor) => {
2335
+ return (0, _univerjs_sheets.rangeToDiscreteRange)(range, accessor, unitId, subUnitId);
2336
+ });
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 : "");
2409
2343
  });
2410
- 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
+ };
2411
2363
  }
2412
- if (dataValidationFormulaController.getFormulaRefCheck(str)) {
2413
- onChange === null || onChange === void 0 || onChange({
2414
- formula1: (0, _univerjs_core.isFormulaString)(str) ? str : "",
2415
- 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
+ });
2416
2390
  });
2417
- setLocalError("");
2418
- } else {
2419
- onChange === null || onChange === void 0 || onChange({
2420
- formula1: "",
2421
- 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
+ });
2422
2436
  });
2423
- setFormulaStr("=");
2424
- 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
+ };
2425
2447
  }
2426
- });
2427
- const formulaEditorRef = (0, react.useRef)(null);
2428
- const [isFocusFormulaEditor, setIsFocusFormulaEditor] = (0, react.useState)(false);
2429
- (0, _univerjs_ui.useSidebarClick)((e) => {
2430
- var _formulaEditorRef$cur;
2431
- !((_formulaEditorRef$cur = formulaEditorRef.current) === null || _formulaEditorRef$cur === void 0) && _formulaEditorRef$cur.isClickOutSide(e) && setIsFocusFormulaEditor(false);
2432
- });
2433
- (0, react.useEffect)(() => {
2434
- if (isFocusFormulaEditor) dataValidationPanelService.setFocusFormulaEditorActiveRuleSubUnitId(subUnitId);
2435
- else dataValidationPanelService.setFocusFormulaEditorActiveRuleSubUnitId(null);
2436
- }, [
2437
- isFocusFormulaEditor,
2438
- subUnitId,
2439
- dataValidationPanelService
2440
- ]);
2441
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2442
- label: localeService.t("sheets-data-validation-ui.list.options"),
2443
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
2444
- value: isFormulaStr,
2445
- onChange: (v) => {
2446
- setIsFormulaStr(v);
2447
- setFormulaStr(formulaStrCopy);
2448
- if (v === "1") onChange({
2449
- formula1: formulaStrCopy === "=" ? "" : formulaStrCopy,
2450
- 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
2451
2555
  });
2452
- },
2453
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2454
- value: "0",
2455
- children: localeService.t("sheets-data-validation-ui.list.customOptions")
2456
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2457
- value: "1",
2458
- children: localeService.t("sheets-data-validation-ui.list.refOptions")
2459
- })]
2460
- })
2461
- }), isFormulaStr === "1" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.FormLayout, {
2462
- error: formula1Res || localError || void 0,
2463
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_sheets_formula_ui.FormulaEditor, {
2464
- ref: formulaEditorRef,
2465
- 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),
2466
- initValue: formulaStr,
2467
- unitId,
2468
- subUnitId,
2469
- isFocus: isFocusFormulaEditor,
2470
- isSupportAcrossSheet: true,
2471
- onFocus: () => setIsFocusFormulaEditor(true),
2472
- onChange: (v = "") => {
2473
- const str = (v !== null && v !== void 0 ? v : "").trim();
2474
- setFormulaStrCopy(str);
2475
- updateFormula(str);
2476
2556
  }
2477
- }), refFinalList.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2478
- className: "univer-mt-3",
2479
- children: refFinalList.map((item) => {
2480
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Template, {
2481
- className: "univer-mb-3",
2482
- item,
2483
- commonProps: { onItemChange: handleRefItemChange }
2484
- }, item.id);
2485
- })
2486
- })]
2487
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2488
- error: formula1Res,
2489
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DraggableList, {
2490
- list: strList,
2491
- onListChange: setStrList,
2492
- rowHeight: 28,
2493
- margin: [0, 12],
2494
- draggableHandle: ".draggableHandle",
2495
- itemRender: (item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Template, {
2496
- item,
2497
- commonProps: {
2498
- onItemChange: handleStrItemChange,
2499
- 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);
2500
2650
  }
2501
- }, item.id),
2502
- idKey: "id"
2503
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", {
2504
- 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",
2505
- onClick: handleAdd,
2506
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.IncreaseIcon, { className: "univer-mr-1" }), localeService.t("sheets-data-validation-ui.list.add")]
2507
- })] })
2508
- })] });
2509
- }
2510
-
2511
- //#endregion
2512
- //#region src/views/components/formula-input/index.ts
2513
- const FORMULA_INPUTS = [
2514
- [_univerjs_sheets_data_validation.CUSTOM_FORMULA_INPUT_NAME, CustomFormulaInput],
2515
- [_univerjs_sheets_data_validation.BASE_FORMULA_INPUT_NAME, BaseFormulaInput],
2516
- [_univerjs_sheets_data_validation.LIST_FORMULA_INPUT_NAME, ListFormulaInput],
2517
- [_univerjs_sheets_data_validation.CHECKBOX_FORMULA_INPUT_NAME, CheckboxFormulaInput]
2518
- ];
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);
2519
2777
 
2520
2778
  //#endregion
2521
- //#region src/views/components/ListRenderModeInput.tsx
2522
- const LIST_RENDER_MODE_OPTION_INPUT = "LIST_RENDER_MODE_OPTION_INPUT";
2523
- function ListRenderModeInput(props) {
2524
- var _value$renderMode;
2525
- const { value, onChange } = props;
2526
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2527
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2528
- label: localeService.t("sheets-data-validation-ui.renderMode.label"),
2529
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
2530
- value: `${(_value$renderMode = value.renderMode) !== null && _value$renderMode !== void 0 ? _value$renderMode : _univerjs_core.DataValidationRenderMode.CUSTOM}`,
2531
- onChange: (renderMode) => onChange({
2532
- ...value,
2533
- renderMode: +renderMode
2534
- }),
2535
- children: [
2536
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2537
- value: `${_univerjs_core.DataValidationRenderMode.CUSTOM}`,
2538
- children: localeService.t("sheets-data-validation-ui.renderMode.chip")
2539
- }),
2540
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2541
- value: `${_univerjs_core.DataValidationRenderMode.ARROW}`,
2542
- children: localeService.t("sheets-data-validation-ui.renderMode.arrow")
2543
- }),
2544
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2545
- value: `${_univerjs_core.DataValidationRenderMode.TEXT}`,
2546
- children: localeService.t("sheets-data-validation-ui.renderMode.text")
2547
- })
2548
- ]
2549
- })
2550
- });
2551
- }
2552
- 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);
2553
2806
 
2554
2807
  //#endregion
2555
2808
  //#region src/views/widgets/checkbox-widget.ts
@@ -3547,24 +3800,12 @@ var WholeValidatorView = class extends BaseSheetDataValidatorView {
3547
3800
  //#endregion
3548
3801
  //#region src/controllers/ui.controller.ts
3549
3802
  let SheetsDataValidationUIController = class SheetsDataValidationUIController extends _univerjs_core.RxDisposable {
3550
- constructor(_injector, _componentManger, _dataValidatorRegistryService) {
3803
+ constructor(_injector, _dataValidatorRegistryService) {
3551
3804
  super();
3552
3805
  this._injector = _injector;
3553
- this._componentManger = _componentManger;
3554
3806
  this._dataValidatorRegistryService = _dataValidatorRegistryService;
3555
- this._initComponents();
3556
3807
  this._registerValidatorViews();
3557
3808
  }
3558
- _initComponents() {
3559
- [
3560
- [DATA_VALIDATION_PANEL, DataValidationPanel],
3561
- [ListRenderModeInput.componentKey, ListRenderModeInput],
3562
- [DateShowTimeOption.componentKey, DateShowTimeOption],
3563
- ...FORMULA_INPUTS
3564
- ].forEach(([key, comp]) => {
3565
- this.disposeWithMe(this._componentManger.register(key, comp));
3566
- });
3567
- }
3568
3809
  _registerValidatorViews() {
3569
3810
  [
3570
3811
  DecimalValidatorView,
@@ -3587,11 +3828,7 @@ let SheetsDataValidationUIController = class SheetsDataValidationUIController ex
3587
3828
  });
3588
3829
  }
3589
3830
  };
3590
- SheetsDataValidationUIController = __decorate([
3591
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
3592
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)),
3593
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService))
3594
- ], SheetsDataValidationUIController);
3831
+ SheetsDataValidationUIController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService))], SheetsDataValidationUIController);
3595
3832
 
3596
3833
  //#endregion
3597
3834
  //#region src/mobile-plugin.ts
@@ -3623,6 +3860,8 @@ let UniverSheetsDataValidationMobileUIPlugin = class UniverSheetsDataValidationM
3623
3860
  });
3624
3861
  [
3625
3862
  AddSheetDataValidationAndOpenCommand,
3863
+ InsertQuickSheetDataValidationCommand,
3864
+ ClearQuickSheetDataValidationCommand,
3626
3865
  ShowDataValidationDropdown,
3627
3866
  HideDataValidationDropdown,
3628
3867
  CloseValidationPanelOperation,
@@ -3686,6 +3925,8 @@ let UniverSheetsDataValidationUIPlugin = class UniverSheetsDataValidationUIPlugi
3686
3925
  });
3687
3926
  [
3688
3927
  AddSheetDataValidationAndOpenCommand,
3928
+ InsertQuickSheetDataValidationCommand,
3929
+ ClearQuickSheetDataValidationCommand,
3689
3930
  ShowDataValidationDropdown,
3690
3931
  HideDataValidationDropdown,
3691
3932
  CloseValidationPanelOperation,