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