@univerjs/sheets-data-validation-ui 1.0.0-alpha.2 → 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 (91) hide show
  1. package/lib/cjs/index.js +1591 -1377
  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 +1590 -1349
  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 +1590 -1349
  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/index.d.ts +1 -0
  66. package/lib/types/locale/en-US.d.ts +17 -0
  67. package/lib/types/menu/dv.menu.d.ts +6 -1
  68. package/lib/types/views/components/DataValidationItem.d.ts +1 -2
  69. package/lib/types/views/components/DropdownPresets.d.ts +18 -0
  70. package/lib/types/views/components/formula-input/index.d.ts +0 -2
  71. package/lib/umd/index.js +1 -1
  72. package/lib/umd/locale/ar-SA.js +1 -1
  73. package/lib/umd/locale/ca-ES.js +1 -1
  74. package/lib/umd/locale/de-DE.js +1 -1
  75. package/lib/umd/locale/en-US.js +1 -1
  76. package/lib/umd/locale/es-ES.js +1 -1
  77. package/lib/umd/locale/fa-IR.js +1 -1
  78. package/lib/umd/locale/fr-FR.js +1 -1
  79. package/lib/umd/locale/id-ID.js +1 -1
  80. package/lib/umd/locale/it-IT.js +1 -1
  81. package/lib/umd/locale/ja-JP.js +1 -1
  82. package/lib/umd/locale/ko-KR.js +1 -1
  83. package/lib/umd/locale/pl-PL.js +1 -1
  84. package/lib/umd/locale/pt-BR.js +1 -1
  85. package/lib/umd/locale/ru-RU.js +1 -1
  86. package/lib/umd/locale/sk-SK.js +1 -1
  87. package/lib/umd/locale/vi-VN.js +1 -1
  88. package/lib/umd/locale/zh-CN.js +1 -1
  89. package/lib/umd/locale/zh-HK.js +1 -1
  90. package/lib/umd/locale/zh-TW.js +1 -1
  91. package/package.json +16 -16
package/lib/cjs/index.js CHANGED
@@ -1,53 +1,20 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- //#region \0rolldown/runtime.js
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
- key = keys[i];
13
- if (!__hasOwnProp.call(to, key) && key !== except) {
14
- __defProp(to, key, {
15
- get: ((k) => from[k]).bind(null, key),
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
- });
18
- }
19
- }
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
- value: mod,
25
- enumerable: true
26
- }) : target, mod));
27
-
28
- //#endregion
2
+ let _univerjs_ui = require("@univerjs/ui");
29
3
  let _univerjs_core = require("@univerjs/core");
30
- let _univerjs_engine_render = require("@univerjs/engine-render");
31
4
  let _univerjs_sheets = require("@univerjs/sheets");
32
5
  let _univerjs_sheets_data_validation = require("@univerjs/sheets-data-validation");
33
6
  let _univerjs_data_validation = require("@univerjs/data-validation");
34
- let _univerjs_ui = require("@univerjs/ui");
35
7
  let rxjs = require("rxjs");
8
+ let _univerjs_engine_render = require("@univerjs/engine-render");
36
9
  let _univerjs_sheets_numfmt = require("@univerjs/sheets-numfmt");
37
10
  let _univerjs_sheets_ui = require("@univerjs/sheets-ui");
38
11
  let _univerjs_design = require("@univerjs/design");
39
12
  let react = require("react");
40
- react = __toESM(react);
13
+ let react_jsx_runtime = require("react/jsx-runtime");
41
14
  let _univerjs_icons = require("@univerjs/icons");
42
15
  let _univerjs_engine_formula = require("@univerjs/engine-formula");
43
16
  let _univerjs_sheets_formula_ui = require("@univerjs/sheets-formula-ui");
44
- let react_jsx_runtime = require("react/jsx-runtime");
45
-
46
- //#region package.json
47
- var name = "@univerjs/sheets-data-validation-ui";
48
- var version = "1.0.0-alpha.2";
49
17
 
50
- //#endregion
51
18
  //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
52
19
  function _typeof(o) {
53
20
  "@babel/helpers - typeof";
@@ -709,14 +676,55 @@ const HideDataValidationDropdown = {
709
676
 
710
677
  //#endregion
711
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
+ };
712
719
  const AddSheetDataValidationAndOpenCommand = {
713
720
  type: _univerjs_core.CommandType.COMMAND,
714
721
  id: "data-validation.command.addRuleAndOpen",
715
- handler(accessor) {
722
+ handler(accessor, params) {
716
723
  const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService));
717
724
  if (!target) return false;
718
725
  const { workbook, worksheet } = target;
719
- 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);
720
728
  const commandService = accessor.get(_univerjs_core.ICommandService);
721
729
  const addParams = {
722
730
  rule,
@@ -735,982 +743,476 @@ const AddSheetDataValidationAndOpenCommand = {
735
743
  };
736
744
 
737
745
  //#endregion
738
- //#region src/controllers/components.controller.ts
739
- /**
740
- * Copyright 2023-present DreamNum Co., Ltd.
741
- *
742
- * Licensed under the Apache License, Version 2.0 (the "License");
743
- * you may not use this file except in compliance with the License.
744
- * You may obtain a copy of the License at
745
- *
746
- * http://www.apache.org/licenses/LICENSE-2.0
747
- *
748
- * Unless required by applicable law or agreed to in writing, software
749
- * distributed under the License is distributed on an "AS IS" BASIS,
750
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
751
- * See the License for the specific language governing permissions and
752
- * limitations under the License.
753
- */
754
- let ComponentsController = class ComponentsController extends _univerjs_core.Disposable {
755
- constructor(_componentManager, _iconManager) {
756
- super();
757
- this._componentManager = _componentManager;
758
- this._iconManager = _iconManager;
759
- this._registerIcons();
760
- }
761
- _registerIcons() {
762
- this.disposeWithMe(this._iconManager.register({ DataValidationIcon: _univerjs_icons.DataValidationIcon }));
763
- }
764
- };
765
- ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IconManager))], ComponentsController);
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
+ }
766
787
 
767
788
  //#endregion
768
- //#region src/controllers/dv-alert.controller.ts
769
- const ALERT_KEY = "SHEET_DATA_VALIDATION_ALERT";
770
- let DataValidationAlertController = class DataValidationAlertController extends _univerjs_core.Disposable {
771
- constructor(_hoverManagerService, _cellAlertManagerService, _univerInstanceService, _localeService, _dataValidationModel) {
772
- super();
773
- this._hoverManagerService = _hoverManagerService;
774
- this._cellAlertManagerService = _cellAlertManagerService;
775
- this._univerInstanceService = _univerInstanceService;
776
- this._localeService = _localeService;
777
- this._dataValidationModel = _dataValidationModel;
778
- this._init();
779
- }
780
- _init() {
781
- this._initCellAlertPopup();
782
- }
783
- _initCellAlertPopup() {
784
- this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0, rxjs.debounceTime)(100)).subscribe((cellPos) => {
785
- if (cellPos) {
786
- const workbook = this._univerInstanceService.getUnit(cellPos.location.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
787
- const worksheet = workbook.getSheetBySheetId(cellPos.location.subUnitId);
788
- if (!worksheet) return;
789
- const rule = this._dataValidationModel.getRuleByLocation(cellPos.location.unitId, cellPos.location.subUnitId, cellPos.location.row, cellPos.location.col);
790
- if (!rule) {
791
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
792
- return;
793
- }
794
- if (this._dataValidationModel.validator(rule, {
795
- ...cellPos.location,
796
- workbook,
797
- worksheet
798
- }) === _univerjs_core.DataValidationStatus.INVALID) {
799
- var _currentAlert$alert;
800
- const currentAlert = this._cellAlertManagerService.currentAlert.get(ALERT_KEY);
801
- const currentLoc = currentAlert === null || currentAlert === void 0 || (_currentAlert$alert = currentAlert.alert) === null || _currentAlert$alert === void 0 ? void 0 : _currentAlert$alert.location;
802
- if (currentLoc && currentLoc.row === cellPos.location.row && currentLoc.col === cellPos.location.col && currentLoc.subUnitId === cellPos.location.subUnitId && currentLoc.unitId === cellPos.location.unitId) {
803
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
804
- return;
805
- }
806
- const validator = this._dataValidationModel.getValidator(rule.type);
807
- if (!validator) {
808
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
809
- return;
810
- }
811
- this._cellAlertManagerService.showAlert({
812
- type: _univerjs_sheets_ui.CellAlertType.ERROR,
813
- title: this._localeService.t("sheets-data-validation-ui.error.title"),
814
- message: validator === null || validator === void 0 ? void 0 : validator.getRuleFinalError(rule, cellPos.location),
815
- location: cellPos.location,
816
- width: 200,
817
- height: 74,
818
- key: ALERT_KEY
819
- });
820
- return;
821
- }
789
+ //#region src/menu/dv.menu.ts
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
+ }
831
+ function dataValidationMenuFactory(accessor) {
832
+ return {
833
+ id: DATA_VALIDATION_MENU_ID,
834
+ type: _univerjs_ui.MenuItemType.SUBITEMS,
835
+ icon: "DataValidationIcon",
836
+ tooltip: "sheets-data-validation-ui.title",
837
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
838
+ disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
839
+ workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
840
+ worksheetTypes: [_univerjs_sheets.WorksheetSetCellStylePermission, _univerjs_sheets.WorksheetEditPermission],
841
+ rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
842
+ })
843
+ };
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] }
822
895
  }
823
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
824
- }));
825
- }
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
+ }
936
+ function openDataValidationMenuFactory() {
937
+ return {
938
+ id: OpenValidationPanelOperation.id,
939
+ title: "sheets-data-validation-ui.panel.title",
940
+ type: _univerjs_ui.MenuItemType.BUTTON
941
+ };
942
+ }
943
+ function addDataValidationMenuFactory() {
944
+ return {
945
+ id: AddSheetDataValidationAndOpenCommand.id,
946
+ title: "sheets-data-validation-ui.panel.add",
947
+ type: _univerjs_ui.MenuItemType.BUTTON
948
+ };
949
+ }
950
+
951
+ //#endregion
952
+ //#region src/menu/schema.ts
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
+ }
967
+ },
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
+ } }
826
980
  };
827
- DataValidationAlertController = __decorate([
828
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.HoverManagerService)),
829
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.CellAlertManagerService)),
830
- __decorateParam(2, _univerjs_core.IUniverInstanceService),
831
- __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
832
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel))
833
- ], DataValidationAlertController);
834
981
 
835
982
  //#endregion
836
- //#region src/controllers/dv-auto-fill.controller.ts
837
- let DataValidationAutoFillController = class DataValidationAutoFillController extends _univerjs_core.Disposable {
838
- constructor(_autoFillService, _sheetDataValidationModel, _injector) {
839
- super();
840
- this._autoFillService = _autoFillService;
841
- this._sheetDataValidationModel = _sheetDataValidationModel;
842
- this._injector = _injector;
843
- this._initAutoFill();
844
- }
845
- _initAutoFill() {
846
- const noopReturnFunc = () => ({
847
- redos: [],
848
- undos: []
849
- });
850
- const generalApplyFunc = (location, applyType) => {
851
- const { source: sourceRange, target: targetRange, unitId, subUnitId } = location;
852
- const ruleMatrixCopy = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
853
- const virtualRange = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([sourceRange, targetRange]);
854
- const [vSourceRange, vTargetRange] = virtualRange.ranges;
855
- const { mapFunc } = virtualRange;
856
- const sourceStartCell = {
857
- row: vSourceRange.startRow,
858
- col: vSourceRange.startColumn
859
- };
860
- const repeats = _univerjs_sheets.AutoFillTools.getAutoFillRepeatRange(vSourceRange, vTargetRange);
861
- const additionMatrix = new _univerjs_core.ObjectMatrix();
862
- const additionRules = /* @__PURE__ */ new Set();
863
- repeats.forEach((repeat) => {
864
- const targetStartCell = repeat.repeatStartCell;
865
- const relativeRange = repeat.relativeRange;
866
- const sourceRange = {
867
- startRow: sourceStartCell.row,
868
- startColumn: sourceStartCell.col,
869
- endColumn: sourceStartCell.col,
870
- endRow: sourceStartCell.row
871
- };
872
- const targetRange = {
873
- startRow: targetStartCell.row,
874
- startColumn: targetStartCell.col,
875
- endColumn: targetStartCell.col,
876
- endRow: targetStartCell.row
877
- };
878
- _univerjs_core.Range.foreach(relativeRange, (row, col) => {
879
- const sourcePositionRange = _univerjs_core.Rectangle.getPositionRange({
880
- startRow: row,
881
- startColumn: col,
882
- endColumn: col,
883
- endRow: row
884
- }, sourceRange);
885
- const { row: sourceRow, col: sourceCol } = mapFunc(sourcePositionRange.startRow, sourcePositionRange.startColumn);
886
- const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, sourceRow, sourceCol) || "";
887
- const targetPositionRange = _univerjs_core.Rectangle.getPositionRange({
888
- startRow: row,
889
- startColumn: col,
890
- endColumn: col,
891
- endRow: row
892
- }, targetRange);
893
- const { row: targetRow, col: targetCol } = mapFunc(targetPositionRange.startRow, targetPositionRange.startColumn);
894
- additionMatrix.setValue(targetRow, targetCol, ruleId);
895
- additionRules.add(ruleId);
896
- });
897
- });
898
- const additions = Array.from(additionRules).map((id) => ({
899
- id,
900
- ranges: (0, _univerjs_core.queryObjectMatrix)(additionMatrix, (value) => value === id)
901
- }));
902
- ruleMatrixCopy.addRangeRules(additions);
903
- 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);
904
- return {
905
- undos: undoMutations,
906
- redos: redoMutations
907
- };
908
- };
909
- const hook = {
910
- id: _univerjs_sheets_data_validation.DATA_VALIDATION_PLUGIN_NAME,
911
- onBeforeFillData: (location) => {
912
- const { source: sourceRange, unitId, subUnitId } = location;
913
- for (const row of sourceRange.rows) for (const col of sourceRange.cols) {
914
- const dv = this._sheetDataValidationModel.getRuleByLocation(unitId, subUnitId, row, col);
915
- if (dv && dv.type === _univerjs_core.DataValidationType.CHECKBOX) {
916
- this._autoFillService.setDisableApplyType(_univerjs_sheets.AUTO_FILL_APPLY_TYPE.SERIES, true);
917
- return;
918
- }
919
- }
920
- },
921
- onFillData: (location, direction, applyType) => {
922
- 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);
923
- return noopReturnFunc();
924
- },
925
- onAfterFillData: () => {}
926
- };
927
- this.disposeWithMe(this._autoFillService.addHook(hook));
928
- }
929
- };
930
- DataValidationAutoFillController = __decorate([
931
- __decorateParam(0, _univerjs_sheets.IAutoFillService),
932
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
933
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
934
- ], DataValidationAutoFillController);
983
+ //#region package.json
984
+ var name = "@univerjs/sheets-data-validation-ui";
985
+ var version = "1.0.0-alpha.4";
935
986
 
936
987
  //#endregion
937
- //#region src/controllers/dv-copy-paste.controller.ts
938
- const specialPastes = [
939
- _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,
940
- _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,
941
- _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,
942
- _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA
943
- ];
944
- let DataValidationCopyPasteController = class DataValidationCopyPasteController extends _univerjs_core.Disposable {
945
- constructor(_sheetClipboardService, _sheetDataValidationModel, _injector, _univerInstanceService) {
946
- super();
947
- this._sheetClipboardService = _sheetClipboardService;
948
- this._sheetDataValidationModel = _sheetDataValidationModel;
949
- this._injector = _injector;
950
- this._univerInstanceService = _univerInstanceService;
951
- _defineProperty(this, "_copyInfo", void 0);
952
- this._initCopyPaste();
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
+ }
1042
+
1043
+ //#endregion
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()) || "";
953
1054
  }
954
- _initCopyPaste() {
955
- this._sheetClipboardService.addClipboardHook({
956
- id: _univerjs_sheets_data_validation.DATA_VALIDATION_PLUGIN_NAME,
957
- onBeforeCopy: (unitId, subUnitId, range) => this._collect(unitId, subUnitId, range),
958
- onPasteCells: (pasteFrom, pasteTo, data, payload) => {
959
- if (!pasteFrom || !this._copyInfo || specialPastes.includes(payload.pasteType)) return {
960
- redos: [],
961
- undos: []
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
+ })));
1119
+ }
1120
+ }, 20);
1121
+ }
1122
+ });
1123
+ return () => {
1124
+ disposable.dispose();
1125
+ if (timer !== void 0) clearTimeout(timer);
1126
+ };
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
962
1142
  };
963
- return this._generateMutations(pasteFrom, pasteTo, payload);
964
1143
  }
1144
+ return {
1145
+ ...unitRange,
1146
+ sheetId: ""
1147
+ };
965
1148
  });
966
- }
967
- _collect(unitId, subUnitId, range) {
968
- const matrix = new _univerjs_core.ObjectMatrix();
969
- 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 = {
970
1158
  unitId,
971
1159
  subUnitId,
972
- matrix
1160
+ ruleId,
1161
+ ranges
973
1162
  };
974
- const discreteRange = this._injector.invoke((accessor) => {
975
- 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
976
1174
  });
977
- if (!discreteRange) return;
978
- const { rows, cols } = discreteRange;
979
- rows.forEach((row, rowIndex) => {
980
- cols.forEach((col, colIndex) => {
981
- const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, row, col);
982
- matrix.setValue(rowIndex, colIndex, ruleId !== null && ruleId !== void 0 ? ruleId : "");
983
- });
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
984
1192
  });
985
- }
986
- _generateMutations(pasteFrom, pasteTo, payload) {
987
- const { unitId: copyUnitId, subUnitId: copySubUnitId, range: copyRange } = pasteFrom;
988
- const { unitId: pastedUnitId, subUnitId: pastedSubUnitId, range: pastedRange } = pasteTo;
989
- const { copyType = _univerjs_sheets_ui.COPY_TYPE.COPY } = payload;
990
- if (!(0, _univerjs_sheets.getSheetCommandTarget)(this._univerInstanceService, {
991
- unitId: pastedUnitId,
992
- subUnitId: pastedSubUnitId
993
- })) return {
994
- redos: [],
995
- undos: []
1193
+ const params = {
1194
+ unitId,
1195
+ subUnitId,
1196
+ ruleId,
1197
+ setting
996
1198
  };
997
- if (copyType === _univerjs_sheets_ui.COPY_TYPE.CUT && pastedUnitId === copyUnitId && pastedSubUnitId === copySubUnitId) {
998
- this._copyInfo = null;
999
- return {
1000
- redos: [],
1001
- undos: []
1002
- };
1003
- }
1004
- if (pastedUnitId !== copyUnitId || pastedSubUnitId !== copySubUnitId) {
1005
- const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(pastedUnitId, pastedSubUnitId).clone();
1006
- const additionMatrix = new _univerjs_core.ObjectMatrix();
1007
- const addRules = /* @__PURE__ */ new Set();
1008
- const { ranges: [vCopyRange, vPastedRange], mapFunc } = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([copyRange, pastedRange]);
1009
- const repeatRange = (0, _univerjs_sheets_ui.getRepeatRange)(vCopyRange, vPastedRange, true);
1010
- const additionRules = /* @__PURE__ */ new Map();
1011
- repeatRange.forEach(({ startRange }) => {
1012
- var _this$_copyInfo;
1013
- (_this$_copyInfo = this._copyInfo) === null || _this$_copyInfo === void 0 || _this$_copyInfo.matrix.forValue((row, col, ruleId) => {
1014
- const range = _univerjs_core.Rectangle.getPositionRange({
1015
- startRow: row,
1016
- endRow: row,
1017
- startColumn: col,
1018
- endColumn: col
1019
- }, startRange);
1020
- const transformedRuleId = `${copySubUnitId}-${ruleId}`;
1021
- const oldRule = this._sheetDataValidationModel.getRuleById(copyUnitId, copySubUnitId, ruleId);
1022
- if (!this._sheetDataValidationModel.getRuleById(pastedUnitId, pastedSubUnitId, transformedRuleId) && oldRule) additionRules.set(transformedRuleId, {
1023
- ...oldRule,
1024
- uid: transformedRuleId
1025
- });
1026
- const { row: startRow, col: startColumn } = mapFunc(range.startRow, range.startColumn);
1027
- addRules.add(transformedRuleId);
1028
- additionMatrix.setValue(startRow, startColumn, transformedRuleId);
1029
- });
1030
- });
1031
- const additions = Array.from(addRules).map((id) => ({
1032
- id,
1033
- ranges: (0, _univerjs_core.queryObjectMatrix)(additionMatrix, (value) => value === id)
1034
- }));
1035
- ruleMatrix.addRangeRules(additions);
1036
- const { redoMutations, undoMutations } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(pastedUnitId, pastedSubUnitId, ruleMatrix.diffWithAddition(this._sheetDataValidationModel.getRules(pastedUnitId, pastedSubUnitId), additionRules.values()), this._injector, "patched", false);
1037
- if (copyType === _univerjs_sheets_ui.COPY_TYPE.CUT) {
1038
- const copySheetRuleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyUnitId, copySubUnitId).clone();
1039
- const deleteRangeStartCell = mapFunc(vCopyRange.startRow, vCopyRange.startColumn);
1040
- const deleteRangeEndCell = mapFunc(vCopyRange.endRow, vCopyRange.endColumn);
1041
- copySheetRuleMatrix.addRangeRules([{
1042
- id: "",
1043
- ranges: [{
1044
- startRow: deleteRangeStartCell.row,
1045
- endRow: deleteRangeEndCell.row,
1046
- startColumn: deleteRangeStartCell.col,
1047
- endColumn: deleteRangeEndCell.col
1048
- }]
1049
- }]);
1050
- const { redoMutations: cutRedos, undoMutations: cutUndos } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(copyUnitId, copySubUnitId, copySheetRuleMatrix.diff(this._sheetDataValidationModel.getRules(copyUnitId, copySubUnitId)), this._injector, "patched", false);
1051
- redoMutations.push(...cutRedos);
1052
- undoMutations.push(...cutUndos);
1053
- }
1054
- return {
1055
- redos: redoMutations,
1056
- undos: undoMutations
1057
- };
1058
- } else {
1059
- const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyUnitId, copySubUnitId).clone();
1060
- const additionMatrix = new _univerjs_core.ObjectMatrix();
1061
- const additionRules = /* @__PURE__ */ new Set();
1062
- const { ranges: [vCopyRange, vPastedRange], mapFunc } = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([copyRange, pastedRange]);
1063
- (0, _univerjs_sheets_ui.getRepeatRange)(vCopyRange, vPastedRange, true).forEach(({ startRange }) => {
1064
- var _this$_copyInfo2;
1065
- (_this$_copyInfo2 = this._copyInfo) === null || _this$_copyInfo2 === void 0 || _this$_copyInfo2.matrix.forValue((row, col, ruleId) => {
1066
- const range = _univerjs_core.Rectangle.getPositionRange({
1067
- startRow: row,
1068
- endRow: row,
1069
- startColumn: col,
1070
- endColumn: col
1071
- }, startRange);
1072
- const { row: startRow, col: startColumn } = mapFunc(range.startRow, range.startColumn);
1073
- additionMatrix.setValue(startRow, startColumn, ruleId);
1074
- additionRules.add(ruleId);
1075
- });
1076
- });
1077
- const additions = Array.from(additionRules).map((id) => ({
1078
- id,
1079
- ranges: (0, _univerjs_core.queryObjectMatrix)(additionMatrix, (value) => value === id)
1080
- }));
1081
- ruleMatrix.addRangeRules(additions);
1082
- const { redoMutations, undoMutations } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(pastedUnitId, pastedSubUnitId, ruleMatrix.diff(this._sheetDataValidationModel.getRules(copyUnitId, copySubUnitId)), this._injector, "patched", false);
1083
- return {
1084
- redos: redoMutations,
1085
- undos: undoMutations
1086
- };
1087
- }
1088
- }
1089
- };
1090
- DataValidationCopyPasteController = __decorate([
1091
- __decorateParam(0, _univerjs_sheets_ui.ISheetClipboardService),
1092
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
1093
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
1094
- __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService))
1095
- ], DataValidationCopyPasteController);
1096
-
1097
- //#endregion
1098
- //#region src/controllers/dv-permission.controller.ts
1099
- let DataValidationPermissionController = class DataValidationPermissionController extends _univerjs_core.Disposable {
1100
- constructor(_localeService, _commandService, _sheetPermissionCheckController) {
1101
- super();
1102
- this._localeService = _localeService;
1103
- this._commandService = _commandService;
1104
- this._sheetPermissionCheckController = _sheetPermissionCheckController;
1105
- this._commandExecutedListener();
1106
- }
1107
- _commandExecutedListener() {
1108
- this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
1109
- if (command.id === _univerjs_sheets_data_validation.AddSheetDataValidationCommand.id) {
1110
- const { unitId, subUnitId, rule: { ranges } } = command.params;
1111
- if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
1112
- workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
1113
- rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint],
1114
- worksheetTypes: [_univerjs_sheets.WorksheetEditPermission, _univerjs_sheets.WorksheetSetCellStylePermission]
1115
- }, ranges, unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-data-validation-ui.permission.dialog.setStyleErr"));
1116
- }
1117
- if (command.id === _univerjs_sheets_data_validation.UpdateSheetDataValidationRangeCommand.id) {
1118
- const { unitId, subUnitId, ranges } = command.params;
1119
- if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
1120
- workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
1121
- rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint],
1122
- worksheetTypes: [_univerjs_sheets.WorksheetEditPermission, _univerjs_sheets.WorksheetSetCellStylePermission]
1123
- }, ranges, unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("sheets-data-validation-ui.permission.dialog.setStyleErr"));
1124
- }
1125
- }));
1126
- }
1127
- };
1128
- DataValidationPermissionController = __decorate([
1129
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
1130
- __decorateParam(1, _univerjs_core.ICommandService),
1131
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetPermissionCheckController))
1132
- ], DataValidationPermissionController);
1133
-
1134
- //#endregion
1135
- //#region src/menu/dv.menu.ts
1136
- const DATA_VALIDATION_MENU_ID = "sheet.menu.data-validation";
1137
- function dataValidationMenuFactory(accessor) {
1138
- return {
1139
- id: DATA_VALIDATION_MENU_ID,
1140
- type: _univerjs_ui.MenuItemType.SUBITEMS,
1141
- icon: "DataValidationIcon",
1142
- tooltip: "sheets-data-validation-ui.title",
1143
- hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
1144
- disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
1145
- workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
1146
- worksheetTypes: [_univerjs_sheets.WorksheetSetCellStylePermission, _univerjs_sheets.WorksheetEditPermission],
1147
- rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
1148
- })
1199
+ debounceExecute(_univerjs_sheets_data_validation.UpdateSheetDataValidationSettingCommand.id, params, void 0);
1149
1200
  };
1150
- }
1151
- function openDataValidationMenuFactory() {
1152
- return {
1153
- id: OpenValidationPanelOperation.id,
1154
- title: "sheets-data-validation-ui.panel.title",
1155
- type: _univerjs_ui.MenuItemType.BUTTON
1201
+ const handleDelete = async () => {
1202
+ await commandService.executeCommand(_univerjs_sheets_data_validation.RemoveSheetDataValidationCommand.id, {
1203
+ ruleId,
1204
+ unitId,
1205
+ subUnitId
1206
+ });
1207
+ dataValidationPanelService.setActiveRule(null);
1208
+ goBackActiveRuleSheet();
1156
1209
  };
1157
- }
1158
- function addDataValidationMenuFactory() {
1159
- return {
1160
- id: AddSheetDataValidationAndOpenCommand.id,
1161
- title: "sheets-data-validation-ui.panel.add",
1162
- type: _univerjs_ui.MenuItemType.BUTTON
1163
- };
1164
- }
1165
-
1166
- //#endregion
1167
- //#region src/menu/schema.ts
1168
- const menuSchema = { [_univerjs_ui.RibbonDataGroup.RULES]: { [DATA_VALIDATION_MENU_ID]: {
1169
- order: 0,
1170
- menuItemFactory: dataValidationMenuFactory,
1171
- [OpenValidationPanelOperation.id]: {
1172
- order: 0,
1173
- menuItemFactory: openDataValidationMenuFactory
1174
- },
1175
- [AddSheetDataValidationAndOpenCommand.id]: {
1176
- order: 1,
1177
- menuItemFactory: addDataValidationMenuFactory
1178
- }
1179
- } } };
1180
-
1181
- //#endregion
1182
- //#region src/controllers/dv-render.controller.ts
1183
- const INVALID_MARK = { tr: {
1184
- size: 6,
1185
- color: "#fe4b4b"
1186
- } };
1187
- let SheetsDataValidationRenderController = class SheetsDataValidationRenderController extends _univerjs_core.RxDisposable {
1188
- constructor(_commandService, _menuManagerService, _renderManagerService, _univerInstanceService, _autoHeightController, _dropdownManagerService, _sheetDataValidationModel, _dataValidatorRegistryService, _sheetInterceptorService, _dataValidationCacheService, _editorBridgeService) {
1189
- super();
1190
- this._commandService = _commandService;
1191
- this._menuManagerService = _menuManagerService;
1192
- this._renderManagerService = _renderManagerService;
1193
- this._univerInstanceService = _univerInstanceService;
1194
- this._autoHeightController = _autoHeightController;
1195
- this._dropdownManagerService = _dropdownManagerService;
1196
- this._sheetDataValidationModel = _sheetDataValidationModel;
1197
- this._dataValidatorRegistryService = _dataValidatorRegistryService;
1198
- this._sheetInterceptorService = _sheetInterceptorService;
1199
- this._dataValidationCacheService = _dataValidationCacheService;
1200
- this._editorBridgeService = _editorBridgeService;
1201
- this._initMenu();
1202
- this._initDropdown();
1203
- this._initViewModelIntercept();
1204
- this._initAutoHeight();
1205
- }
1206
- _initMenu() {
1207
- this._menuManagerService.mergeMenu(menuSchema);
1208
- }
1209
- _initDropdown() {
1210
- if (!this._editorBridgeService) return;
1211
- this.disposeWithMe(this._editorBridgeService.visible$.subscribe((visible) => {
1212
- if (!visible.visible) {
1213
- var _this$_dropdownManage;
1214
- if (((_this$_dropdownManage = this._dropdownManagerService.activeDropdown) === null || _this$_dropdownManage === void 0 ? void 0 : _this$_dropdownManage.trigger) === "editor-bridge") this._dropdownManagerService.hideDropdown();
1215
- return;
1216
- }
1217
- const state = this._editorBridgeService.getEditCellState();
1218
- if (state) {
1219
- const { unitId, sheetId, row, column } = state;
1220
- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
1221
- if (!workbook) return;
1222
- const rule = this._sheetDataValidationModel.getRuleByLocation(unitId, sheetId, row, column);
1223
- if (!rule) return;
1224
- const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
1225
- if (!(validator === null || validator === void 0 ? void 0 : validator.dropdownType)) return;
1226
- const worksheet = workbook.getActiveSheet();
1227
- if (!worksheet) return;
1228
- const activeDropdown = this._dropdownManagerService.activeDropdown;
1229
- const currLoc = activeDropdown === null || activeDropdown === void 0 ? void 0 : activeDropdown.location;
1230
- if (currLoc && currLoc.unitId === unitId && currLoc.subUnitId === sheetId && currLoc.row === row && currLoc.col === column) return;
1231
- this._dropdownManagerService.showDropdown({
1232
- location: {
1233
- unitId,
1234
- subUnitId: sheetId,
1235
- row,
1236
- col: column,
1237
- workbook,
1238
- worksheet
1239
- },
1240
- trigger: "editor-bridge",
1241
- closeOnOutSide: false
1242
- });
1243
- }
1244
- }));
1245
- }
1246
- _initViewModelIntercept() {
1247
- this.disposeWithMe(this._sheetInterceptorService.intercept(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, {
1248
- effect: _univerjs_core.InterceptorEffectEnum.Style,
1249
- priority: _univerjs_sheets.InterceptCellContentPriority.DATA_VALIDATION,
1250
- handler: (cell, pos, next) => {
1251
- var _this$_dataValidation, _cell$customRender, _cell$fontRenderExten, _validator$skipDefaul, _cell$coverable;
1252
- const { row, col, unitId, subUnitId, workbook, worksheet } = pos;
1253
- const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, row, col);
1254
- if (!ruleId) return next(cell);
1255
- const rule = this._sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1256
- if (!rule) return next(cell);
1257
- const validStatus = (_this$_dataValidation = this._dataValidationCacheService.getValue(unitId, subUnitId, row, col)) !== null && _this$_dataValidation !== void 0 ? _this$_dataValidation : _univerjs_core.DataValidationStatus.VALID;
1258
- const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
1259
- const cellOrigin = pos.rawData;
1260
- let cache;
1261
- const cellValue = { get value() {
1262
- var _getCellValueOrigin;
1263
- if (cache !== void 0) return cache;
1264
- cache = (_getCellValueOrigin = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(cellOrigin)) !== null && _getCellValueOrigin !== void 0 ? _getCellValueOrigin : null;
1265
- return cache;
1266
- } };
1267
- const valueStr = { get value() {
1268
- var _cellValue$value;
1269
- return `${(_cellValue$value = cellValue.value) !== null && _cellValue$value !== void 0 ? _cellValue$value : ""}`;
1270
- } };
1271
- if (!cell || cell === pos.rawData) cell = { ...pos.rawData };
1272
- cell.markers = {
1273
- ...cell === null || cell === void 0 ? void 0 : cell.markers,
1274
- ...validStatus === _univerjs_core.DataValidationStatus.INVALID ? INVALID_MARK : null
1275
- };
1276
- 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] : []];
1277
- cell.fontRenderExtension = {
1278
- ...cell === null || cell === void 0 ? void 0 : cell.fontRenderExtension,
1279
- 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))
1280
- };
1281
- cell.interceptorStyle = {
1282
- ...cell === null || cell === void 0 ? void 0 : cell.interceptorStyle,
1283
- ...validator === null || validator === void 0 ? void 0 : validator.getExtraStyle(rule, valueStr.value, { get style() {
1284
- const styleMap = workbook.getStyles();
1285
- 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) || {};
1286
- } }, row, col)
1287
- };
1288
- cell.interceptorAutoHeight = () => {
1289
- var _this$_renderManagerS, _mergeCell$startRow, _mergeCell$startColum, _validator$canvasRend, _validator$canvasRend2;
1290
- 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;
1291
- if (!skeleton) return;
1292
- const mergeCell = skeleton.worksheet.getMergedCell(row, col);
1293
- const info = {
1294
- data: cell,
1295
- style: skeleton.getStyles().getStyleByCell(cell),
1296
- 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),
1297
- unitId,
1298
- subUnitId,
1299
- row,
1300
- col,
1301
- workbook,
1302
- worksheet
1303
- };
1304
- 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);
1305
- };
1306
- cell.interceptorAutoWidth = () => {
1307
- var _this$_renderManagerS2, _mergeCell$startRow2, _mergeCell$startColum2, _validator$canvasRend3, _validator$canvasRend4;
1308
- 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;
1309
- if (!skeleton) return;
1310
- const mergeCell = skeleton.worksheet.getMergedCell(row, col);
1311
- const info = {
1312
- data: cell,
1313
- style: skeleton.getStyles().getStyleByCell(cell),
1314
- 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),
1315
- unitId,
1316
- subUnitId,
1317
- row,
1318
- col,
1319
- workbook,
1320
- worksheet
1321
- };
1322
- 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);
1323
- };
1324
- 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);
1325
- return next(cell);
1326
- }
1327
- }));
1328
- }
1329
- _initAutoHeight() {
1330
- this._sheetDataValidationModel.ruleChange$.pipe((0, rxjs.filter)((change) => change.source === "command"), (0, rxjs.bufferTime)(100)).subscribe((infos) => {
1331
- if (infos.length === 0) return;
1332
- const ranges = [];
1333
- infos.forEach((info) => {
1334
- if (info.rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE || info.rule.type === _univerjs_core.DataValidationType.LIST) {
1335
- var _info$rule;
1336
- if ((_info$rule = info.rule) === null || _info$rule === void 0 ? void 0 : _info$rule.ranges) ranges.push(...info.rule.ranges);
1337
- }
1338
- });
1339
- if (ranges.length) (0, _univerjs_core.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(ranges).redos, this._commandService);
1340
- });
1341
- }
1342
- };
1343
- SheetsDataValidationRenderController = __decorate([
1344
- __decorateParam(0, _univerjs_core.ICommandService),
1345
- __decorateParam(1, _univerjs_ui.IMenuManagerService),
1346
- __decorateParam(2, _univerjs_engine_render.IRenderManagerService),
1347
- __decorateParam(3, _univerjs_core.IUniverInstanceService),
1348
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.AutoHeightController)),
1349
- __decorateParam(5, (0, _univerjs_core.Inject)(DataValidationDropdownManagerService)),
1350
- __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
1351
- __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService)),
1352
- __decorateParam(8, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
1353
- __decorateParam(9, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.DataValidationCacheService)),
1354
- __decorateParam(10, (0, _univerjs_core.Optional)(_univerjs_sheets_ui.IEditorBridgeService))
1355
- ], SheetsDataValidationRenderController);
1356
- let SheetsDataValidationMobileRenderController = class SheetsDataValidationMobileRenderController extends _univerjs_core.RxDisposable {
1357
- constructor(_commandService, _renderManagerService, _autoHeightController, _dataValidatorRegistryService, _sheetInterceptorService, _sheetDataValidationModel, _dataValidationCacheService) {
1358
- super();
1359
- this._commandService = _commandService;
1360
- this._renderManagerService = _renderManagerService;
1361
- this._autoHeightController = _autoHeightController;
1362
- this._dataValidatorRegistryService = _dataValidatorRegistryService;
1363
- this._sheetInterceptorService = _sheetInterceptorService;
1364
- this._sheetDataValidationModel = _sheetDataValidationModel;
1365
- this._dataValidationCacheService = _dataValidationCacheService;
1366
- this._initViewModelIntercept();
1367
- this._initAutoHeight();
1368
- }
1369
- _initViewModelIntercept() {
1370
- this.disposeWithMe(this._sheetInterceptorService.intercept(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, {
1371
- effect: _univerjs_core.InterceptorEffectEnum.Style,
1372
- priority: _univerjs_sheets.InterceptCellContentPriority.DATA_VALIDATION,
1373
- handler: (cell, pos, next) => {
1374
- var _this$_dataValidation2, _cell$customRender2, _cell$fontRenderExten2, _validator$skipDefaul2, _cell$coverable2;
1375
- const { row, col, unitId, subUnitId, workbook, worksheet } = pos;
1376
- const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, row, col);
1377
- if (!ruleId) return next(cell);
1378
- const rule = this._sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1379
- if (!rule) return next(cell);
1380
- const validStatus = (_this$_dataValidation2 = this._dataValidationCacheService.getValue(unitId, subUnitId, row, col)) !== null && _this$_dataValidation2 !== void 0 ? _this$_dataValidation2 : _univerjs_core.DataValidationStatus.VALID;
1381
- const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
1382
- const cellValue = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(worksheet.getCellRaw(row, col));
1383
- const valueStr = `${cellValue !== null && cellValue !== void 0 ? cellValue : ""}`;
1384
- if (!cell || cell === pos.rawData) cell = { ...pos.rawData };
1385
- cell.markers = {
1386
- ...cell === null || cell === void 0 ? void 0 : cell.markers,
1387
- ...validStatus === _univerjs_core.DataValidationStatus.INVALID ? INVALID_MARK : null
1388
- };
1389
- 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] : []];
1390
- cell.fontRenderExtension = {
1391
- ...cell === null || cell === void 0 ? void 0 : cell.fontRenderExtension,
1392
- 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))
1393
- };
1394
- cell.interceptorStyle = {
1395
- ...cell === null || cell === void 0 ? void 0 : cell.interceptorStyle,
1396
- ...validator === null || validator === void 0 ? void 0 : validator.getExtraStyle(rule, valueStr, { get style() {
1397
- const styleMap = workbook.getStyles();
1398
- 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) || {};
1399
- } }, row, col)
1400
- };
1401
- cell.interceptorAutoHeight = () => {
1402
- var _this$_renderManagerS3, _mergeCell$startRow3, _mergeCell$startColum3, _validator$canvasRend5, _validator$canvasRend6;
1403
- 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;
1404
- if (!skeleton) return;
1405
- const mergeCell = skeleton.worksheet.getMergedCell(row, col);
1406
- const info = {
1407
- data: cell,
1408
- style: skeleton.getStyles().getStyleByCell(cell),
1409
- 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),
1410
- unitId,
1411
- subUnitId,
1412
- row,
1413
- col,
1414
- workbook,
1415
- worksheet
1416
- };
1417
- 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);
1418
- };
1419
- cell.interceptorAutoWidth = () => {
1420
- var _this$_renderManagerS4, _mergeCell$startRow4, _mergeCell$startColum4, _validator$canvasRend7, _validator$canvasRend8;
1421
- 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;
1422
- if (!skeleton) return;
1423
- const mergeCell = skeleton.worksheet.getMergedCell(row, col);
1424
- const info = {
1425
- data: cell,
1426
- style: skeleton.getStyles().getStyleByCell(cell),
1427
- 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),
1428
- unitId,
1429
- subUnitId,
1430
- row,
1431
- col,
1432
- workbook,
1433
- worksheet
1434
- };
1435
- 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);
1436
- };
1437
- 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);
1438
- return next(cell);
1439
- }
1440
- }));
1441
- }
1442
- _initAutoHeight() {
1443
- this._sheetDataValidationModel.ruleChange$.pipe((0, rxjs.filter)((change) => change.source === "command"), (0, rxjs.bufferTime)(16)).subscribe((infos) => {
1444
- const ranges = [];
1445
- infos.forEach((info) => {
1446
- if (info.rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE || info.rule.type === _univerjs_core.DataValidationType.LIST) {
1447
- var _info$rule2;
1448
- if ((_info$rule2 = info.rule) === null || _info$rule2 === void 0 ? void 0 : _info$rule2.ranges) ranges.push(...info.rule.ranges);
1449
- }
1450
- });
1451
- if (ranges.length) (0, _univerjs_core.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(ranges).redos, this._commandService);
1452
- });
1453
- }
1454
- };
1455
- SheetsDataValidationMobileRenderController = __decorate([
1456
- __decorateParam(0, _univerjs_core.ICommandService),
1457
- __decorateParam(1, _univerjs_engine_render.IRenderManagerService),
1458
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.AutoHeightController)),
1459
- __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService)),
1460
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
1461
- __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
1462
- __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.DataValidationCacheService))
1463
- ], SheetsDataValidationMobileRenderController);
1464
-
1465
- //#endregion
1466
- //#region src/controllers/dv-rerender.controller.ts
1467
- let SheetsDataValidationReRenderController = class SheetsDataValidationReRenderController extends _univerjs_core.Disposable {
1468
- constructor(_context, _sheetDataValidationModel, _sheetSkeletonManagerService) {
1469
- super();
1470
- this._context = _context;
1471
- this._sheetDataValidationModel = _sheetDataValidationModel;
1472
- this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
1473
- this._initSkeletonChange();
1474
- }
1475
- _initSkeletonChange() {
1476
- const reRender = (values) => {
1477
- var _this$_context$mainCo;
1478
- if (!values.length) return;
1479
- const sheetIds = /* @__PURE__ */ new Set();
1480
- values.forEach((value) => {
1481
- sheetIds.add(value.subUnitId);
1482
- });
1483
- sheetIds.forEach((sheetId) => {
1484
- var _this$_sheetSkeletonM;
1485
- (_this$_sheetSkeletonM = this._sheetSkeletonManagerService.getSkeletonParam(sheetId)) === null || _this$_sheetSkeletonM === void 0 || _this$_sheetSkeletonM.skeleton.makeDirty(true);
1486
- });
1487
- (_this$_context$mainCo = this._context.mainComponent) === null || _this$_context$mainCo === void 0 || _this$_context$mainCo.makeForceDirty();
1488
- };
1489
- this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe((0, _univerjs_core.bufferDebounceTime)(16)).subscribe(reRender));
1490
- }
1491
- };
1492
- SheetsDataValidationReRenderController = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)), __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.SheetSkeletonManagerService))], SheetsDataValidationReRenderController);
1493
-
1494
- //#endregion
1495
- //#region src/views/components/DataValidationOptions.tsx
1496
- function DataValidationOptions(props) {
1497
- var _value$errorStyle;
1498
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1499
- const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
1500
- const { value, onChange, extraComponent } = props;
1501
- const [show, setShow] = (0, react.useState)(false);
1502
- const ExtraOptions = extraComponent ? componentManager.get(extraComponent) : null;
1503
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1504
- className: "univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900 dark:!univer-text-white",
1505
- onClick: () => setShow(!show),
1506
- 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" })]
1507
- }), show && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1508
- ExtraOptions ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ExtraOptions, {
1509
- value,
1510
- onChange
1511
- }) : null,
1512
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1513
- label: localeService.t("sheets-data-validation-ui.panel.invalid"),
1514
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
1515
- value: `${(_value$errorStyle = value.errorStyle) !== null && _value$errorStyle !== void 0 ? _value$errorStyle : _univerjs_core.DataValidationErrorStyle.WARNING}`,
1516
- onChange: (errorStyle) => onChange({
1517
- ...value,
1518
- errorStyle: +errorStyle
1519
- }),
1520
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
1521
- value: `${_univerjs_core.DataValidationErrorStyle.WARNING}`,
1522
- children: localeService.t("sheets-data-validation-ui.panel.showWarning")
1523
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
1524
- value: `${_univerjs_core.DataValidationErrorStyle.STOP}`,
1525
- children: localeService.t("sheets-data-validation-ui.panel.rejectInput")
1526
- })]
1527
- })
1528
- }),
1529
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1530
- label: localeService.t("sheets-data-validation-ui.panel.messageInfo"),
1531
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
1532
- checked: value.showErrorMessage,
1533
- onChange: () => onChange({
1534
- ...value,
1535
- showErrorMessage: !value.showErrorMessage
1536
- }),
1537
- children: localeService.t("sheets-data-validation-ui.panel.showInfo")
1538
- })
1539
- }),
1540
- value.showErrorMessage ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
1541
- value: value.error,
1542
- onChange: (error) => onChange({
1543
- ...value,
1544
- error
1545
- })
1546
- }) }) : null
1547
- ] })] });
1548
- }
1549
-
1550
- //#endregion
1551
- //#region src/views/components/DataValidationDetail.tsx
1552
- const debounceExecuteFactory = (commandService) => (0, _univerjs_core.debounce)(async (id, params, options, callback) => {
1553
- const res = await commandService.executeCommand(id, params, options);
1554
- callback === null || callback === void 0 || callback(res);
1555
- }, 1e3);
1556
- function getSheetIdByName(univerInstanceService, unitId, name) {
1557
- var _univerInstanceServic2;
1558
- if (unitId) {
1559
- var _univerInstanceServic;
1560
- return ((_univerInstanceServic = univerInstanceService.getUnit(unitId)) === null || _univerInstanceServic === void 0 || (_univerInstanceServic = _univerInstanceServic.getSheetBySheetName(name)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getSheetId()) || "";
1561
- }
1562
- 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()) || "";
1563
- }
1564
- function DataValidationDetail() {
1565
- const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
1566
- const { unitId, subUnitId, rule } = (0, _univerjs_ui.useObservable)(dataValidationPanelService.activeRule$, dataValidationPanelService.activeRule) || {};
1567
- if (!unitId || !subUnitId || !rule) return null;
1568
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationDetailInner, { activeRuleInfo: {
1569
- unitId,
1570
- subUnitId,
1571
- rule
1572
- } });
1573
- }
1574
- function DataValidationDetailInner(props) {
1575
- var _validators$sort, _localRule$allowBlank;
1576
- const [key, setKey] = (0, react.useState)(0);
1577
- const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
1578
- const { unitId, subUnitId, rule } = props.activeRuleInfo;
1579
- const ruleId = rule.uid;
1580
- const validatorService = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidatorRegistryService);
1581
- const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
1582
- const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
1583
- const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
1584
- const dataValidationModel = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidationModel);
1585
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1586
- const workbook = (0, _univerjs_ui.useObservable)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), void 0, void 0, []);
1587
- const worksheet = (0, _univerjs_ui.useObservable)(() => {
1588
- var _workbook$activeSheet;
1589
- return (_workbook$activeSheet = workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) !== null && _workbook$activeSheet !== void 0 ? _workbook$activeSheet : (0, rxjs.of)(null);
1590
- }, void 0, void 0, []);
1591
- const [localRule, setLocalRule] = (0, react.useState)(rule);
1592
- const validator = validatorService.getValidatorItem(localRule.type);
1593
- const [showError, setShowError] = (0, react.useState)(false);
1594
- const validators = validatorService.getValidatorsByScope(_univerjs_data_validation.DataValidatorRegistryScope.SHEET);
1595
- const [localRanges, setLocalRanges] = (0, react.useState)(() => localRule.ranges.map((i) => ({
1596
- unitId: "",
1597
- sheetId: "",
1598
- range: i
1599
- })));
1600
- const debounceExecute = (0, react.useMemo)(() => debounceExecuteFactory(commandService), [commandService]);
1601
- const [isRangeError, setIsRangeError] = (0, react.useState)(false);
1602
- const [isFocusRangeSelector, setIsFocusRangeSelector] = (0, react.useState)(false);
1603
- const rangeSelectorInstance = (0, react.useRef)(null);
1604
- const sheetSelectionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.SheetsSelectionsService);
1605
- (0, react.useEffect)(() => {
1606
- return () => {
1607
- const currentSelection = sheetSelectionService.getCurrentLastSelection();
1608
- if (currentSelection) sheetSelectionService.setSelections([currentSelection]);
1609
- };
1610
- }, [sheetSelectionService]);
1611
- (0, react.useEffect)(() => {
1612
- commandService.onCommandExecuted((commandInfo) => {
1613
- if (commandInfo.id === _univerjs_core.UndoCommand.id || commandInfo.id === _univerjs_core.RedoCommand.id) setTimeout(() => {
1614
- const activeRule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1615
- setKey((k) => k + 1);
1616
- if (activeRule) {
1617
- setLocalRule(activeRule);
1618
- setLocalRanges(activeRule.ranges.map((i) => ({
1619
- unitId: "",
1620
- sheetId: "",
1621
- range: i
1622
- })));
1623
- }
1624
- }, 20);
1625
- });
1626
- }, [
1627
- commandService,
1628
- dataValidationModel,
1629
- ruleId,
1630
- subUnitId,
1631
- unitId
1632
- ]);
1633
- if (!validator) return null;
1634
- const operators = validator.operators;
1635
- const operatorNames = validator.operatorNames;
1636
- const isTwoFormula = localRule.operator ? _univerjs_data_validation.TWO_FORMULA_OPERATOR_COUNT.includes(localRule.operator) : false;
1637
- const goBackActiveRuleSheet = () => {
1638
- if ((worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId()) !== subUnitId) commandService.syncExecuteCommand(_univerjs_sheets.SetWorksheetActiveOperation.id, {
1639
- unitId,
1640
- subUnitId
1641
- });
1642
- };
1643
- const handleOk = () => {
1644
- var _rangeSelectorInstanc;
1645
- if ((_rangeSelectorInstanc = rangeSelectorInstance.current) === null || _rangeSelectorInstanc === void 0 || (_rangeSelectorInstanc = _rangeSelectorInstanc.editor) === null || _rangeSelectorInstanc === void 0 ? void 0 : _rangeSelectorInstanc.isFocus()) {
1646
- var _rangeSelectorInstanc2;
1647
- handleUpdateRuleRanges((_rangeSelectorInstanc2 = rangeSelectorInstance.current) === null || _rangeSelectorInstanc2 === void 0 ? void 0 : _rangeSelectorInstanc2.getValue());
1648
- }
1649
- if (!localRule.ranges.length || isRangeError) return;
1650
- if (validator.validatorFormula(localRule, unitId, subUnitId).success) dataValidationPanelService.setActiveRule(null);
1651
- else setShowError(true);
1652
- goBackActiveRuleSheet();
1653
- };
1654
- const handleUpdateRuleRanges = (0, _univerjs_ui.useEvent)((rangeText) => {
1655
- const unitRanges = rangeText.split(",").filter(Boolean).map(_univerjs_engine_formula.deserializeRangeWithSheet).map((unitRange) => {
1656
- const sheetName = unitRange.sheetName;
1657
- if (sheetName) {
1658
- const sheetId = getSheetIdByName(univerInstanceService, unitRange.unitId, sheetName);
1659
- return {
1660
- ...unitRange,
1661
- sheetId
1662
- };
1663
- }
1664
- return {
1665
- ...unitRange,
1666
- sheetId: ""
1667
- };
1668
- });
1669
- if ((0, _univerjs_core.isUnitRangesEqual)(unitRanges, localRanges)) return;
1670
- setLocalRanges(unitRanges);
1671
- const ranges = unitRanges.filter((i) => (!i.unitId || i.unitId === unitId) && (!i.sheetId || i.sheetId === subUnitId)).map((i) => i.range);
1672
- setLocalRule({
1673
- ...localRule,
1674
- ranges
1675
- });
1676
- if (ranges.length === 0) return;
1677
- const params = {
1678
- unitId,
1679
- subUnitId,
1680
- ruleId,
1681
- ranges
1682
- };
1683
- debounceExecute(_univerjs_sheets_data_validation.UpdateSheetDataValidationRangeCommand.id, params);
1684
- });
1685
- const handleUpdateRuleSetting = (setting) => {
1686
- if ((0, _univerjs_core.shallowEqual)(setting, (0, _univerjs_data_validation.getRuleSetting)(localRule))) return;
1687
- setLocalRule({
1688
- ...localRule,
1689
- ...setting
1690
- });
1691
- const params = {
1692
- unitId,
1693
- subUnitId,
1694
- ruleId,
1695
- setting
1696
- };
1697
- debounceExecute(_univerjs_sheets_data_validation.UpdateSheetDataValidationSettingCommand.id, params, void 0);
1698
- };
1699
- const handleDelete = async () => {
1700
- await commandService.executeCommand(_univerjs_sheets_data_validation.RemoveSheetDataValidationCommand.id, {
1701
- ruleId,
1702
- unitId,
1703
- subUnitId
1704
- });
1705
- dataValidationPanelService.setActiveRule(null);
1706
- goBackActiveRuleSheet();
1707
- };
1708
- const baseRule = {
1709
- type: localRule.type,
1710
- operator: localRule.operator,
1711
- formula1: localRule.formula1,
1712
- formula2: localRule.formula2,
1713
- allowBlank: localRule.allowBlank
1210
+ const baseRule = {
1211
+ type: localRule.type,
1212
+ operator: localRule.operator,
1213
+ formula1: localRule.formula1,
1214
+ formula2: localRule.formula2,
1215
+ allowBlank: localRule.allowBlank
1714
1216
  };
1715
1217
  const handleChangeType = (newType) => {
1716
1218
  const validator = validatorService.getValidatorItem(newType);
@@ -1736,7 +1238,6 @@ function DataValidationDetailInner(props) {
1736
1238
  });
1737
1239
  };
1738
1240
  const FormulaInput = componentManager.get(validator.formulaInput);
1739
- const rangeStr = (0, react.useMemo)(() => localRanges.map((i) => (0, _univerjs_engine_formula.serializeRange)(i.range)).join(","), []);
1740
1241
  const options = (0, _univerjs_data_validation.getRuleOptions)(localRule);
1741
1242
  const handleUpdateRuleOptions = (newOptions) => {
1742
1243
  if ((0, _univerjs_core.shallowEqual)(newOptions, (0, _univerjs_data_validation.getRuleOptions)(localRule))) return;
@@ -1931,11 +1432,11 @@ const DataValidationItem = (props) => {
1931
1432
  className: "univer-text-secondary univer-truncate univer-text-xs univer-leading-[18px] dark:!univer-text-gray-300",
1932
1433
  children: rule.ranges.map((range) => (0, _univerjs_engine_formula.serializeRange)(range)).join(",")
1933
1434
  }),
1934
- isHover ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1435
+ isHover && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1935
1436
  className: "univer-absolute univer-right-2 univer-top-[19px] univer-flex univer-size-5 univer-items-center univer-justify-center univer-rounded hover:univer-bg-gray-200 dark:!univer-text-gray-300 dark:hover:!univer-bg-gray-700",
1936
1437
  onClick: handleDelete,
1937
1438
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, {})
1938
- }) : null
1439
+ })
1939
1440
  ]
1940
1441
  });
1941
1442
  };
@@ -1949,23 +1450,14 @@ function DataValidationList(props) {
1949
1450
  const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
1950
1451
  const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
1951
1452
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1952
- const [rules, setRules] = (0, react.useState)([]);
1953
1453
  const { workbook } = props;
1954
1454
  const worksheet = (0, _univerjs_ui.useObservable)(workbook.activeSheet$, void 0, true);
1955
1455
  const unitId = workbook.getUnitId();
1956
1456
  const subUnitId = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId();
1957
- (0, react.useEffect)(() => {
1958
- setRules(sheetDataValidationModel.getRules(unitId, subUnitId));
1959
- const subscription = sheetDataValidationModel.ruleChange$.subscribe((change) => {
1960
- if (change.unitId === unitId && change.subUnitId === subUnitId) setRules(sheetDataValidationModel.getRules(unitId, subUnitId));
1961
- });
1962
- return () => {
1963
- subscription.unsubscribe();
1964
- };
1965
- }, [
1966
- 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,
1967
1459
  subUnitId,
1968
- sheetDataValidationModel
1460
+ unitId
1969
1461
  ]);
1970
1462
  const handleAddRule = async () => {
1971
1463
  const rule = (0, _univerjs_sheets_data_validation.createDefaultNewRule)(injector);
@@ -2179,47 +1671,414 @@ function CheckboxFormulaInput(props) {
2179
1671
  });
2180
1672
  }
2181
1673
  })
2182
- }) : null
2183
- ] });
2184
- }
2185
-
2186
- //#endregion
2187
- //#region src/views/components/formula-input/CustomFormulaInput.tsx
2188
- function CustomFormulaInput(props) {
2189
- var _value$formula;
2190
- const { unitId, subUnitId, value, onChange, showError, validResult } = props;
2191
- 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
+ });
2192
1953
  const formulaEditorRef = (0, react.useRef)(null);
2193
1954
  const [isFocusFormulaEditor, setIsFocusFormulaEditor] = (0, react.useState)(false);
2194
1955
  (0, _univerjs_ui.useSidebarClick)((e) => {
2195
1956
  var _formulaEditorRef$cur;
2196
1957
  !((_formulaEditorRef$cur = formulaEditorRef.current) === null || _formulaEditorRef$cur === void 0) && _formulaEditorRef$cur.isClickOutSide(e) && setIsFocusFormulaEditor(false);
2197
1958
  });
2198
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2199
- error: formula1Res,
2200
- 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, {
2201
1990
  ref: formulaEditorRef,
2202
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),
2203
- initValue: (_value$formula = value === null || value === void 0 ? void 0 : value.formula1) !== null && _value$formula !== void 0 ? _value$formula : "=",
1992
+ initValue: formulaStr,
2204
1993
  unitId,
2205
1994
  subUnitId,
2206
1995
  isFocus: isFocusFormulaEditor,
2207
1996
  isSupportAcrossSheet: true,
2208
- onChange: (newValue) => {
2209
- const newFormula = (newValue !== null && newValue !== void 0 ? newValue : "").trim();
2210
- if (newFormula === (value === null || value === void 0 ? void 0 : value.formula1)) return;
2211
- onChange === null || onChange === void 0 || onChange({
2212
- ...value,
2213
- formula1: newFormula
2214
- });
2215
- },
2216
- 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
+ ]
2217
2075
  })
2218
2076
  });
2219
2077
  }
2078
+ ListRenderModeInput.componentKey = LIST_RENDER_MODE_OPTION_INPUT;
2220
2079
 
2221
2080
  //#endregion
2222
- //#region src/views/components/formula-input/utils.ts
2081
+ //#region src/controllers/components.controller.ts
2223
2082
  /**
2224
2083
  * Copyright 2023-present DreamNum Co., Ltd.
2225
2084
  *
@@ -2235,349 +2094,715 @@ function CustomFormulaInput(props) {
2235
2094
  * See the License for the specific language governing permissions and
2236
2095
  * limitations under the License.
2237
2096
  */
2238
- function buildCustomListFormulaPayload(items, defaultColor) {
2239
- const labelSet = /* @__PURE__ */ new Set();
2240
- const finalList = [];
2241
- items.forEach((item) => {
2242
- if (!item.label || labelSet.has(item.label)) return;
2243
- labelSet.add(item.label);
2244
- finalList.push(item);
2245
- });
2246
- return {
2247
- formula1: (0, _univerjs_sheets.serializeListOptions)(finalList.map((item) => item.label)),
2248
- formula2: finalList.map((item) => item.color === defaultColor ? "" : item.color).join(",")
2249
- };
2250
- }
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);
2251
2126
 
2252
2127
  //#endregion
2253
- //#region src/views/components/formula-input/ListFormulaInput.tsx
2254
- const DEFAULT_COLOR_PRESET = [
2255
- "#FFFFFF",
2256
- "#FEE7E7",
2257
- "#FEF0E6",
2258
- "#EFFBD0",
2259
- "#E4F4FE",
2260
- "#E8ECFD",
2261
- "#F1EAFA",
2262
- "#FDE8F3",
2263
- "#E5E5E5",
2264
- "#FDCECE",
2265
- "#FDC49B",
2266
- "#DEF6A2",
2267
- "#9FDAFF",
2268
- "#D0D9FB",
2269
- "#E3D5F6",
2270
- "#FBD0E8",
2271
- "#656565",
2272
- "#FE4B4B",
2273
- "#FF8C51",
2274
- "#8BBB11",
2275
- "#0B9EFB",
2276
- "#3A60F7",
2277
- "#9E6DE3",
2278
- "#F248A6"
2279
- ];
2280
- const ColorSelect = (props) => {
2281
- const { value, onChange, disabled } = props;
2282
- const [open, setOpen] = (0, react.useState)(false);
2283
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
2284
- align: "start",
2285
- disabled,
2286
- open,
2287
- onOpenChange: setOpen,
2288
- overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2289
- className: "univer-box-border univer-grid univer-w-fit univer-grid-cols-6 univer-flex-wrap univer-gap-2 univer-p-1.5",
2290
- children: DEFAULT_COLOR_PRESET.map((color) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2291
- className: (0, _univerjs_design.clsx)("univer-box-border univer-size-4 univer-cursor-pointer univer-rounded", _univerjs_design.borderClassName),
2292
- style: { background: color },
2293
- onClick: () => {
2294
- onChange(color);
2295
- 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;
2296
2153
  }
2297
- }, color))
2298
- }),
2299
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2300
- 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),
2301
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2302
- className: "univer-box-border univer-size-4 univer-rounded univer-text-base",
2303
- style: { background: value }
2304
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, {})]
2305
- })
2306
- });
2307
- };
2308
- const Template = (props) => {
2309
- const { item, commonProps, className } = props;
2310
- const { onItemChange, onItemDelete } = commonProps;
2311
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2312
- className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-gap-2", className),
2313
- children: [
2314
- !item.isRef && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2315
- className: (0, _univerjs_design.clsx)("univer-cursor-move", "draggableHandle"),
2316
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.GripVerticalIcon, {})
2317
- }),
2318
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ColorSelect, {
2319
- value: item.color,
2320
- onChange: (color) => {
2321
- 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;
2322
2181
  }
2323
- }),
2324
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
2325
- disabled: item.isRef,
2326
- value: item.label,
2327
- onChange: (label) => {
2328
- 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
+ }
2329
2279
  }
2330
- }),
2331
- item.isRef ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2332
- className: "univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base hover:univer-bg-gray-200",
2333
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, { onClick: () => onItemDelete(item.id) })
2334
- })
2335
- ]
2336
- });
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
+ }
2337
2289
  };
2338
- const NOOP = () => {};
2339
- function ListFormulaInput(props) {
2340
- const { value, onChange: _onChange = NOOP, unitId, subUnitId, validResult, showError, ruleId } = props;
2341
- const { formula1 = "", formula2 = "" } = value || {};
2342
- const [isFormulaStr, setIsFormulaStr] = (0, react.useState)(() => (0, _univerjs_core.isFormulaString)(formula1) ? "1" : "0");
2343
- const [formulaStr, setFormulaStr] = (0, react.useState)(isFormulaStr === "1" ? formula1 : "=");
2344
- const [formulaStrCopy, setFormulaStrCopy] = (0, react.useState)(isFormulaStr === "1" ? formula1 : "=");
2345
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2346
- const dataValidatorRegistryService = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidatorRegistryService);
2347
- const dataValidationModel = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidationModel);
2348
- const dataValidationFormulaController = (0, _univerjs_ui.useDependency)(_univerjs_sheets_data_validation.DataValidationFormulaController);
2349
- const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
2350
- const [refColors, setRefColors] = (0, react.useState)(() => formula2.split(","));
2351
- const listValidator = dataValidatorRegistryService.getValidatorItem(_univerjs_core.DataValidationType.LIST);
2352
- const [refOptions, setRefOptions] = (0, react.useState)([]);
2353
- const [localError, setLocalError] = (0, react.useState)("");
2354
- const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : "";
2355
- const ruleChange = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => dataValidationModel.ruleChange$.pipe((0, rxjs.debounceTime)(16)), []));
2356
- const onChange = (0, _univerjs_ui.useEvent)(_onChange);
2357
- (0, react.useEffect)(() => {
2358
- (async () => {
2359
- await (0, _univerjs_core.awaitTime)(100);
2360
- const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
2361
- if ((0, _univerjs_core.isFormulaString)(rule === null || rule === void 0 ? void 0 : rule.formula1) && listValidator && rule) setRefOptions(await listValidator.getListAsync(rule, unitId, subUnitId));
2362
- })();
2363
- }, [
2364
- dataValidationModel,
2365
- ruleChange,
2366
- listValidator,
2367
- ruleId,
2368
- subUnitId,
2369
- unitId
2370
- ]);
2371
- (0, react.useEffect)(() => {
2372
- if ((0, _univerjs_core.isFormulaString)(formula1) && formula1 !== formulaStrCopy) {
2373
- setFormulaStr(formula1);
2374
- setFormulaStrCopy(formulaStrCopy);
2375
- }
2376
- }, [formulaStrCopy, formula1]);
2377
- const [strList, setStrList] = (0, react.useState)(() => {
2378
- const strOptions = isFormulaStr !== "1" ? (0, _univerjs_sheets.deserializeListOptions)(formula1) : [];
2379
- const strColors = formula2.split(",");
2380
- return strOptions.map((label, i) => ({
2381
- label,
2382
- color: strColors[i] || "#ECECEC",
2383
- isRef: false,
2384
- id: (0, _univerjs_core.generateRandomId)(4)
2385
- }));
2386
- });
2387
- const handleStrItemChange = (id, value, color) => {
2388
- const item = strList.find((i) => i.id === id);
2389
- if (!item) return;
2390
- item.label = value;
2391
- item.color = color;
2392
- setStrList([...strList]);
2393
- };
2394
- const handleStrItemDelete = (id) => {
2395
- const index = strList.findIndex((i) => i.id === id);
2396
- if (index !== -1) {
2397
- strList.splice(index, 1);
2398
- setStrList([...strList]);
2399
- }
2400
- };
2401
- const refFinalList = (0, react.useMemo)(() => refOptions.map((label, i) => ({
2402
- label,
2403
- color: refColors[i] || "#ECECEC",
2404
- id: `${i}`,
2405
- isRef: true
2406
- })), [refColors, refOptions]);
2407
- const handleRefItemChange = (id, value, color) => {
2408
- const newColors = [...refColors];
2409
- newColors[+id] = color;
2410
- setRefColors(newColors);
2411
- onChange({
2412
- formula1,
2413
- 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
+ }
2414
2325
  });
2415
- };
2416
- const handleAdd = () => {
2417
- setStrList([...strList, {
2418
- label: "",
2419
- color: DROP_DOWN_DEFAULT_COLOR,
2420
- isRef: false,
2421
- id: (0, _univerjs_core.generateRandomId)(4)
2422
- }]);
2423
- };
2424
- (0, react.useEffect)(() => {
2425
- if (isFormulaStr === "1") return;
2426
- onChange(buildCustomListFormulaPayload(strList, DROP_DOWN_DEFAULT_COLOR));
2427
- }, [
2428
- strList,
2429
- onChange,
2430
- isFormulaStr
2431
- ]);
2432
- const updateFormula = (0, _univerjs_ui.useEvent)(async (str) => {
2433
- if (!(0, _univerjs_core.isFormulaString)(str)) {
2434
- onChange === null || onChange === void 0 || onChange({
2435
- formula1: "",
2436
- 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 : "");
2437
2343
  });
2438
- 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
+ };
2439
2363
  }
2440
- if (dataValidationFormulaController.getFormulaRefCheck(str)) {
2441
- onChange === null || onChange === void 0 || onChange({
2442
- formula1: (0, _univerjs_core.isFormulaString)(str) ? str : "",
2443
- 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
+ });
2444
2390
  });
2445
- setLocalError("");
2446
- } else {
2447
- onChange === null || onChange === void 0 || onChange({
2448
- formula1: "",
2449
- 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
+ });
2450
2436
  });
2451
- setFormulaStr("=");
2452
- 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
+ };
2453
2447
  }
2454
- });
2455
- const formulaEditorRef = (0, react.useRef)(null);
2456
- const [isFocusFormulaEditor, setIsFocusFormulaEditor] = (0, react.useState)(false);
2457
- (0, _univerjs_ui.useSidebarClick)((e) => {
2458
- var _formulaEditorRef$cur;
2459
- !((_formulaEditorRef$cur = formulaEditorRef.current) === null || _formulaEditorRef$cur === void 0) && _formulaEditorRef$cur.isClickOutSide(e) && setIsFocusFormulaEditor(false);
2460
- });
2461
- (0, react.useEffect)(() => {
2462
- if (isFocusFormulaEditor) dataValidationPanelService.setFocusFormulaEditorActiveRuleSubUnitId(subUnitId);
2463
- else dataValidationPanelService.setFocusFormulaEditorActiveRuleSubUnitId(null);
2464
- }, [
2465
- isFocusFormulaEditor,
2466
- subUnitId,
2467
- dataValidationPanelService
2468
- ]);
2469
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2470
- label: localeService.t("sheets-data-validation-ui.list.options"),
2471
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
2472
- value: isFormulaStr,
2473
- onChange: (v) => {
2474
- setIsFormulaStr(v);
2475
- setFormulaStr(formulaStrCopy);
2476
- if (v === "1") onChange({
2477
- formula1: formulaStrCopy === "=" ? "" : formulaStrCopy,
2478
- 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
2479
2555
  });
2480
- },
2481
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2482
- value: "0",
2483
- children: localeService.t("sheets-data-validation-ui.list.customOptions")
2484
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2485
- value: "1",
2486
- children: localeService.t("sheets-data-validation-ui.list.refOptions")
2487
- })]
2488
- })
2489
- }), isFormulaStr === "1" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.FormLayout, {
2490
- error: formula1Res || localError || void 0,
2491
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_sheets_formula_ui.FormulaEditor, {
2492
- ref: formulaEditorRef,
2493
- 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),
2494
- initValue: formulaStr,
2495
- unitId,
2496
- subUnitId,
2497
- isFocus: isFocusFormulaEditor,
2498
- isSupportAcrossSheet: true,
2499
- onFocus: () => setIsFocusFormulaEditor(true),
2500
- onChange: (v = "") => {
2501
- const str = (v !== null && v !== void 0 ? v : "").trim();
2502
- setFormulaStrCopy(str);
2503
- updateFormula(str);
2504
2556
  }
2505
- }), refFinalList.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2506
- className: "univer-mt-3",
2507
- children: refFinalList.map((item) => {
2508
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Template, {
2509
- className: "univer-mb-3",
2510
- item,
2511
- commonProps: { onItemChange: handleRefItemChange }
2512
- }, item.id);
2513
- })
2514
- })]
2515
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2516
- error: formula1Res,
2517
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DraggableList, {
2518
- list: strList,
2519
- onListChange: setStrList,
2520
- rowHeight: 28,
2521
- margin: [0, 12],
2522
- draggableHandle: ".draggableHandle",
2523
- itemRender: (item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Template, {
2524
- item,
2525
- commonProps: {
2526
- onItemChange: handleStrItemChange,
2527
- 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);
2528
2650
  }
2529
- }, item.id),
2530
- idKey: "id"
2531
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", {
2532
- 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",
2533
- onClick: handleAdd,
2534
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.IncreaseIcon, { className: "univer-mr-1" }), localeService.t("sheets-data-validation-ui.list.add")]
2535
- })] })
2536
- })] });
2537
- }
2538
-
2539
- //#endregion
2540
- //#region src/views/components/formula-input/index.ts
2541
- const FORMULA_INPUTS = [
2542
- [_univerjs_sheets_data_validation.CUSTOM_FORMULA_INPUT_NAME, CustomFormulaInput],
2543
- [_univerjs_sheets_data_validation.BASE_FORMULA_INPUT_NAME, BaseFormulaInput],
2544
- [_univerjs_sheets_data_validation.LIST_FORMULA_INPUT_NAME, ListFormulaInput],
2545
- [_univerjs_sheets_data_validation.CHECKBOX_FORMULA_INPUT_NAME, CheckboxFormulaInput]
2546
- ];
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);
2547
2777
 
2548
2778
  //#endregion
2549
- //#region src/views/components/ListRenderModeInput.tsx
2550
- const LIST_RENDER_MODE_OPTION_INPUT = "LIST_RENDER_MODE_OPTION_INPUT";
2551
- function ListRenderModeInput(props) {
2552
- var _value$renderMode;
2553
- const { value, onChange } = props;
2554
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2555
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2556
- label: localeService.t("sheets-data-validation-ui.renderMode.label"),
2557
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
2558
- value: `${(_value$renderMode = value.renderMode) !== null && _value$renderMode !== void 0 ? _value$renderMode : _univerjs_core.DataValidationRenderMode.CUSTOM}`,
2559
- onChange: (renderMode) => onChange({
2560
- ...value,
2561
- renderMode: +renderMode
2562
- }),
2563
- children: [
2564
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2565
- value: `${_univerjs_core.DataValidationRenderMode.CUSTOM}`,
2566
- children: localeService.t("sheets-data-validation-ui.renderMode.chip")
2567
- }),
2568
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2569
- value: `${_univerjs_core.DataValidationRenderMode.ARROW}`,
2570
- children: localeService.t("sheets-data-validation-ui.renderMode.arrow")
2571
- }),
2572
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2573
- value: `${_univerjs_core.DataValidationRenderMode.TEXT}`,
2574
- children: localeService.t("sheets-data-validation-ui.renderMode.text")
2575
- })
2576
- ]
2577
- })
2578
- });
2579
- }
2580
- 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);
2581
2806
 
2582
2807
  //#endregion
2583
2808
  //#region src/views/widgets/checkbox-widget.ts
@@ -3575,24 +3800,12 @@ var WholeValidatorView = class extends BaseSheetDataValidatorView {
3575
3800
  //#endregion
3576
3801
  //#region src/controllers/ui.controller.ts
3577
3802
  let SheetsDataValidationUIController = class SheetsDataValidationUIController extends _univerjs_core.RxDisposable {
3578
- constructor(_injector, _componentManger, _dataValidatorRegistryService) {
3803
+ constructor(_injector, _dataValidatorRegistryService) {
3579
3804
  super();
3580
3805
  this._injector = _injector;
3581
- this._componentManger = _componentManger;
3582
3806
  this._dataValidatorRegistryService = _dataValidatorRegistryService;
3583
- this._initComponents();
3584
3807
  this._registerValidatorViews();
3585
3808
  }
3586
- _initComponents() {
3587
- [
3588
- [DATA_VALIDATION_PANEL, DataValidationPanel],
3589
- [ListRenderModeInput.componentKey, ListRenderModeInput],
3590
- [DateShowTimeOption.componentKey, DateShowTimeOption],
3591
- ...FORMULA_INPUTS
3592
- ].forEach(([key, comp]) => {
3593
- this.disposeWithMe(this._componentManger.register(key, comp));
3594
- });
3595
- }
3596
3809
  _registerValidatorViews() {
3597
3810
  [
3598
3811
  DecimalValidatorView,
@@ -3615,11 +3828,7 @@ let SheetsDataValidationUIController = class SheetsDataValidationUIController ex
3615
3828
  });
3616
3829
  }
3617
3830
  };
3618
- SheetsDataValidationUIController = __decorate([
3619
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
3620
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)),
3621
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService))
3622
- ], SheetsDataValidationUIController);
3831
+ SheetsDataValidationUIController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService))], SheetsDataValidationUIController);
3623
3832
 
3624
3833
  //#endregion
3625
3834
  //#region src/mobile-plugin.ts
@@ -3651,6 +3860,8 @@ let UniverSheetsDataValidationMobileUIPlugin = class UniverSheetsDataValidationM
3651
3860
  });
3652
3861
  [
3653
3862
  AddSheetDataValidationAndOpenCommand,
3863
+ InsertQuickSheetDataValidationCommand,
3864
+ ClearQuickSheetDataValidationCommand,
3654
3865
  ShowDataValidationDropdown,
3655
3866
  HideDataValidationDropdown,
3656
3867
  CloseValidationPanelOperation,
@@ -3714,6 +3925,8 @@ let UniverSheetsDataValidationUIPlugin = class UniverSheetsDataValidationUIPlugi
3714
3925
  });
3715
3926
  [
3716
3927
  AddSheetDataValidationAndOpenCommand,
3928
+ InsertQuickSheetDataValidationCommand,
3929
+ ClearQuickSheetDataValidationCommand,
3717
3930
  ShowDataValidationDropdown,
3718
3931
  HideDataValidationDropdown,
3719
3932
  CloseValidationPanelOperation,
@@ -3750,6 +3963,7 @@ UniverSheetsDataValidationUIPlugin = __decorate([
3750
3963
  ], UniverSheetsDataValidationUIPlugin);
3751
3964
 
3752
3965
  //#endregion
3966
+ exports.SheetsDataValidationUIMenuSchema = menuSchema;
3753
3967
  Object.defineProperty(exports, 'UniverSheetsDataValidationMobileUIPlugin', {
3754
3968
  enumerable: true,
3755
3969
  get: function () {