@univerjs/sheets-data-validation-ui 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -15,7 +15,7 @@ let _univerjs_icons = require("@univerjs/icons");
15
15
  let _univerjs_engine_formula = require("@univerjs/engine-formula");
16
16
  let _univerjs_sheets_formula_ui = require("@univerjs/sheets-formula-ui");
17
17
 
18
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
18
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
19
19
  function _typeof(o) {
20
20
  "@babel/helpers - typeof";
21
21
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -26,7 +26,7 @@ function _typeof(o) {
26
26
  }
27
27
 
28
28
  //#endregion
29
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
29
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
30
30
  function toPrimitive(t, r) {
31
31
  if ("object" != _typeof(t) || !t) return t;
32
32
  var e = t[Symbol.toPrimitive];
@@ -39,14 +39,14 @@ function toPrimitive(t, r) {
39
39
  }
40
40
 
41
41
  //#endregion
42
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
42
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
43
43
  function toPropertyKey(t) {
44
44
  var i = toPrimitive(t, "string");
45
45
  return "symbol" == _typeof(i) ? i : i + "";
46
46
  }
47
47
 
48
48
  //#endregion
49
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
49
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
50
50
  function _defineProperty(e, r, t) {
51
51
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
52
52
  value: t,
@@ -57,7 +57,7 @@ function _defineProperty(e, r, t) {
57
57
  }
58
58
 
59
59
  //#endregion
60
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
60
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
61
61
  function __decorateParam(paramIndex, decorator) {
62
62
  return function(target, key) {
63
63
  decorator(target, key, paramIndex);
@@ -65,7 +65,7 @@ function __decorateParam(paramIndex, decorator) {
65
65
  }
66
66
 
67
67
  //#endregion
68
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
68
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
69
69
  function __decorate(decorators, target, key, desc) {
70
70
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
71
71
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1055,8 +1055,7 @@ const menuSchema = {
1055
1055
  order: 0,
1056
1056
  gridLayout: {
1057
1057
  row: 1,
1058
- column: 1,
1059
- showLabel: true
1058
+ column: 1
1060
1059
  },
1061
1060
  menuItemFactory: dataValidationMenuFactory,
1062
1061
  [OpenValidationPanelOperation.id]: {
@@ -1073,80 +1072,132 @@ const menuSchema = {
1073
1072
  //#endregion
1074
1073
  //#region package.json
1075
1074
  var name = "@univerjs/sheets-data-validation-ui";
1076
- var version = "1.0.4";
1075
+ var version = "1.1.0";
1077
1076
 
1078
1077
  //#endregion
1079
1078
  //#region src/controllers/dv-alert.controller.ts
1080
1079
  const ALERT_KEY = "SHEET_DATA_VALIDATION_ALERT";
1081
1080
  let DataValidationAlertController = class DataValidationAlertController extends _univerjs_core.Disposable {
1082
- constructor(_hoverManagerService, _cellAlertManagerService, _univerInstanceService, _localeService, _dataValidationModel) {
1081
+ constructor(_hoverManagerService, _cellAlertManagerService, _univerInstanceService, _localeService, _dataValidationModel, _dataValidationCacheService) {
1083
1082
  super();
1084
1083
  this._hoverManagerService = _hoverManagerService;
1085
1084
  this._cellAlertManagerService = _cellAlertManagerService;
1086
1085
  this._univerInstanceService = _univerInstanceService;
1087
1086
  this._localeService = _localeService;
1088
1087
  this._dataValidationModel = _dataValidationModel;
1088
+ this._dataValidationCacheService = _dataValidationCacheService;
1089
+ _defineProperty(this, "_hoveredCell", null);
1089
1090
  this._init();
1090
1091
  }
1091
1092
  _init() {
1092
1093
  this._initCellAlertPopup();
1093
1094
  }
1094
1095
  _initCellAlertPopup() {
1095
- this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.switchMap)((workbook) => (workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) ?? (0, rxjs.of)(null))).subscribe(() => this._cellAlertManagerService.removeAlert(ALERT_KEY)));
1096
- this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0, rxjs.debounceTime)(100)).subscribe((cellPos) => {
1097
- if (cellPos) {
1098
- var _workbook$getActiveSh;
1099
- const workbook = this._univerInstanceService.getUnit(cellPos.location.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1100
- if (!workbook || ((_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId()) !== cellPos.location.subUnitId) {
1101
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
1102
- return;
1103
- }
1104
- const worksheet = workbook.getSheetBySheetId(cellPos.location.subUnitId);
1105
- if (!worksheet) return;
1106
- const rule = this._dataValidationModel.getRuleByLocation(cellPos.location.unitId, cellPos.location.subUnitId, cellPos.location.row, cellPos.location.col);
1107
- if (!rule) {
1108
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
1109
- return;
1110
- }
1111
- if (this._dataValidationModel.validator(rule, {
1112
- ...cellPos.location,
1113
- workbook,
1114
- worksheet
1115
- }) === _univerjs_core.DataValidationStatus.INVALID) {
1116
- var _currentAlert$alert;
1117
- const currentAlert = this._cellAlertManagerService.currentAlert.get(ALERT_KEY);
1118
- const currentLoc = currentAlert === null || currentAlert === void 0 || (_currentAlert$alert = currentAlert.alert) === null || _currentAlert$alert === void 0 ? void 0 : _currentAlert$alert.location;
1119
- if (currentLoc && currentLoc.row === cellPos.location.row && currentLoc.col === cellPos.location.col && currentLoc.subUnitId === cellPos.location.subUnitId && currentLoc.unitId === cellPos.location.unitId) {
1120
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
1121
- return;
1122
- }
1123
- const validator = this._dataValidationModel.getValidator(rule.type);
1124
- if (!validator) {
1125
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
1126
- return;
1127
- }
1128
- this._cellAlertManagerService.showAlert({
1129
- type: _univerjs_sheets_ui.CellAlertType.ERROR,
1130
- title: this._localeService.t("sheets-data-validation-ui.error.title"),
1131
- message: validator === null || validator === void 0 ? void 0 : validator.getRuleFinalError(rule, cellPos.location),
1132
- location: cellPos.location,
1133
- width: 200,
1134
- height: 74,
1135
- key: ALERT_KEY
1136
- });
1137
- return;
1138
- }
1096
+ this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.switchMap)((workbook) => (workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) ?? (0, rxjs.of)(null))).subscribe(() => {
1097
+ this._hoveredCell = null;
1098
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
1099
+ }));
1100
+ this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0, rxjs.tap)(() => {
1101
+ this._hoveredCell = null;
1102
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
1103
+ }), (0, rxjs.debounceTime)(100)).subscribe((cellPos) => {
1104
+ this._hoveredCell = cellPos;
1105
+ this._refreshAlert();
1106
+ }));
1107
+ this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe((change) => {
1108
+ var _change$oldRule;
1109
+ if (this._affectsHoveredCell(change, [...change.rule.ranges, ...((_change$oldRule = change.oldRule) === null || _change$oldRule === void 0 ? void 0 : _change$oldRule.ranges) ?? []])) this._refreshAlert();
1110
+ }));
1111
+ this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe((0, rxjs.filter)((change) => this._affectsHoveredCell(change, change.ranges)), (0, rxjs.tap)(() => this._cellAlertManagerService.removeAlert(ALERT_KEY)), (0, rxjs.auditTime)(0)).subscribe(() => this._refreshAlert()));
1112
+ this.disposeWithMe(this._dataValidationModel.validStatusChange$.subscribe((change) => {
1113
+ if (this._isHoveredLocation(change)) {
1114
+ const rule = this._dataValidationModel.getRuleByLocation(change.unitId, change.subUnitId, change.row, change.col);
1115
+ if ((rule === null || rule === void 0 ? void 0 : rule.uid) === change.ruleId) this._updateAlert(change.status);
1139
1116
  }
1117
+ }));
1118
+ this.disposeWithMe(() => {
1119
+ this._hoveredCell = null;
1140
1120
  this._cellAlertManagerService.removeAlert(ALERT_KEY);
1121
+ });
1122
+ }
1123
+ _isHoveredLocation(location) {
1124
+ var _this$_hoveredCell;
1125
+ const current = (_this$_hoveredCell = this._hoveredCell) === null || _this$_hoveredCell === void 0 ? void 0 : _this$_hoveredCell.location;
1126
+ return (current === null || current === void 0 ? void 0 : current.unitId) === location.unitId && (current === null || current === void 0 ? void 0 : current.subUnitId) === location.subUnitId && (current === null || current === void 0 ? void 0 : current.row) === location.row && (current === null || current === void 0 ? void 0 : current.col) === location.col;
1127
+ }
1128
+ _affectsHoveredCell(location, ranges) {
1129
+ var _this$_hoveredCell2;
1130
+ const current = (_this$_hoveredCell2 = this._hoveredCell) === null || _this$_hoveredCell2 === void 0 ? void 0 : _this$_hoveredCell2.location;
1131
+ return (current === null || current === void 0 ? void 0 : current.unitId) === location.unitId && (current === null || current === void 0 ? void 0 : current.subUnitId) === location.subUnitId && ranges.some((range) => _univerjs_core.Rectangle.contains(range, {
1132
+ startRow: current.row,
1133
+ endRow: current.row,
1134
+ startColumn: current.col,
1135
+ endColumn: current.col
1141
1136
  }));
1142
1137
  }
1138
+ _getHoveredContext() {
1139
+ var _this$_hoveredCell3;
1140
+ const location = (_this$_hoveredCell3 = this._hoveredCell) === null || _this$_hoveredCell3 === void 0 ? void 0 : _this$_hoveredCell3.location;
1141
+ if (!location) return;
1142
+ const workbook = this._univerInstanceService.getUnit(location.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1143
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
1144
+ if (!workbook || !worksheet || worksheet.getSheetId() !== location.subUnitId) return;
1145
+ const rule = this._dataValidationModel.getRuleByLocation(location.unitId, location.subUnitId, location.row, location.col);
1146
+ if (rule) return {
1147
+ location,
1148
+ workbook,
1149
+ worksheet,
1150
+ rule
1151
+ };
1152
+ }
1153
+ _refreshAlert() {
1154
+ const context = this._getHoveredContext();
1155
+ if (!context) {
1156
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
1157
+ return;
1158
+ }
1159
+ const { location, workbook, worksheet, rule } = context;
1160
+ this._updateAlert(this._dataValidationModel.validator(rule, {
1161
+ ...location,
1162
+ workbook,
1163
+ worksheet
1164
+ }));
1165
+ }
1166
+ _updateAlert(status) {
1167
+ var _this$_cellAlertManag;
1168
+ const context = this._getHoveredContext();
1169
+ if (!context || status !== _univerjs_core.DataValidationStatus.INVALID) {
1170
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
1171
+ return;
1172
+ }
1173
+ const { location, rule } = context;
1174
+ const validator = this._dataValidationModel.getValidator(rule.type);
1175
+ if (!validator) {
1176
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
1177
+ return;
1178
+ }
1179
+ const title = this._localeService.t("sheets-data-validation-ui.error.title");
1180
+ const message = validator.getRuleFinalError(rule, location);
1181
+ const currentAlert = (_this$_cellAlertManag = this._cellAlertManagerService.currentAlert.get(ALERT_KEY)) === null || _this$_cellAlertManag === void 0 ? void 0 : _this$_cellAlertManag.alert;
1182
+ if (currentAlert && this._isHoveredLocation(currentAlert.location) && currentAlert.title === title && currentAlert.message === message) return;
1183
+ this._cellAlertManagerService.showAlert({
1184
+ type: _univerjs_sheets_ui.CellAlertType.ERROR,
1185
+ title,
1186
+ message,
1187
+ location,
1188
+ width: 200,
1189
+ height: 74,
1190
+ key: ALERT_KEY
1191
+ });
1192
+ }
1143
1193
  };
1144
1194
  DataValidationAlertController = __decorate([
1145
1195
  __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.HoverManagerService)),
1146
1196
  __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.CellAlertManagerService)),
1147
1197
  __decorateParam(2, _univerjs_core.IUniverInstanceService),
1148
1198
  __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
1149
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel))
1199
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
1200
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.DataValidationCacheService))
1150
1201
  ], DataValidationAlertController);
1151
1202
 
1152
1203
  //#endregion
@@ -1488,6 +1539,7 @@ let SheetsDataValidationRenderController = class SheetsDataValidationRenderContr
1488
1539
  this._dataValidationCacheService = _dataValidationCacheService;
1489
1540
  this._editorBridgeService = _editorBridgeService;
1490
1541
  this._initMenu();
1542
+ this._initEditor();
1491
1543
  this._initDropdown();
1492
1544
  this._initViewModelIntercept();
1493
1545
  this._initAutoHeight();
@@ -1495,6 +1547,19 @@ let SheetsDataValidationRenderController = class SheetsDataValidationRenderContr
1495
1547
  _initMenu() {
1496
1548
  this._menuManagerService.mergeMenu(menuSchema);
1497
1549
  }
1550
+ _initEditor() {
1551
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
1552
+ var _this$_editorBridgeSe;
1553
+ if (command.id !== _univerjs_sheets_ui.SetCellEditVisibleOperation.id) return;
1554
+ const params = command.params;
1555
+ if (!(params === null || params === void 0 ? void 0 : params.visible) || params.eventType !== _univerjs_engine_render.DeviceInputEventType.Dblclick || !params.pointerPosition) return;
1556
+ const location = (_this$_editorBridgeSe = this._editorBridgeService) === null || _this$_editorBridgeSe === void 0 ? void 0 : _this$_editorBridgeSe.getEditLocation();
1557
+ if (!location || params.unitId && params.unitId !== location.unitId) return;
1558
+ const { unitId, sheetId, row, column } = location;
1559
+ const rule = this._sheetDataValidationModel.getRuleByLocation(unitId, sheetId, row, column);
1560
+ if (rule && (rule.type === _univerjs_core.DataValidationType.LIST || rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE || rule.type === _univerjs_core.DataValidationType.CHECKBOX)) throw new _univerjs_core.CanceledError();
1561
+ }));
1562
+ }
1498
1563
  _initDropdown() {
1499
1564
  if (!this._editorBridgeService) return;
1500
1565
  this.disposeWithMe(this._editorBridgeService.visible$.subscribe((visible) => {
@@ -4016,20 +4081,20 @@ UniverSheetsDataValidationUIPlugin = __decorate([
4016
4081
 
4017
4082
  //#endregion
4018
4083
  exports.DATA_VALIDATION_PANEL = DATA_VALIDATION_PANEL;
4019
- Object.defineProperty(exports, 'DataValidationPanelService', {
4084
+ Object.defineProperty(exports, "DataValidationPanelService", {
4020
4085
  enumerable: true,
4021
4086
  get: function () {
4022
4087
  return DataValidationPanelService;
4023
4088
  }
4024
4089
  });
4025
4090
  exports.SheetsDataValidationUIMenuSchema = menuSchema;
4026
- Object.defineProperty(exports, 'UniverSheetsDataValidationMobileUIPlugin', {
4091
+ Object.defineProperty(exports, "UniverSheetsDataValidationMobileUIPlugin", {
4027
4092
  enumerable: true,
4028
4093
  get: function () {
4029
4094
  return UniverSheetsDataValidationMobileUIPlugin;
4030
4095
  }
4031
4096
  });
4032
- Object.defineProperty(exports, 'UniverSheetsDataValidationUIPlugin', {
4097
+ Object.defineProperty(exports, "UniverSheetsDataValidationUIPlugin", {
4033
4098
  enumerable: true,
4034
4099
  get: function () {
4035
4100
  return UniverSheetsDataValidationUIPlugin;
package/lib/es/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { CellValueType, ColorKit, CommandType, DEFAULT_STYLES, DataValidationErrorStyle, DataValidationRenderMode, DataValidationStatus, DataValidationType, DateSystem, DependentOn, Disposable, DisposableCollection, HorizontalAlign, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, Optional, Plugin, Rectangle, RedoCommand, RxDisposable, ThemeService, UndoCommand, UniverInstanceType, VerticalAlign, WrapStrategy, bufferDebounceTime, dateKit, debounce, excelDateTimePartsToSerial, excelSerialToDateTimeParts, generateRandomId, getIntersectRange, isFormulaString, isUnitRangesEqual, merge, numfmt, sequenceExecute, shallowEqual, toDisposable } from "@univerjs/core";
1
+ import { CanceledError, CellValueType, ColorKit, CommandType, DEFAULT_STYLES, DataValidationErrorStyle, DataValidationRenderMode, DataValidationStatus, DataValidationType, DateSystem, DependentOn, Disposable, DisposableCollection, HorizontalAlign, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, Optional, Plugin, Rectangle, RedoCommand, RxDisposable, ThemeService, UndoCommand, UniverInstanceType, VerticalAlign, WrapStrategy, bufferDebounceTime, dateKit, debounce, excelDateTimePartsToSerial, excelSerialToDateTimeParts, generateRandomId, getIntersectRange, isFormulaString, isUnitRangesEqual, merge, numfmt, sequenceExecute, shallowEqual, toDisposable } from "@univerjs/core";
2
2
  import { DataValidationModel, DataValidatorDropdownType, DataValidatorRegistryScope, DataValidatorRegistryService, TWO_FORMULA_OPERATOR_COUNT, UniverDataValidationPlugin, getRuleOptions, getRuleSetting } from "@univerjs/data-validation";
3
3
  import { AUTO_FILL_APPLY_TYPE, AutoFillTools, IAutoFillService, INTERCEPTOR_POINT, InterceptCellContentPriority, RangeProtectionPermissionEditPoint, SetRangeValuesCommand, SetWorksheetActiveOperation, SheetInterceptorService, SheetPermissionCheckController, SheetsSelectionsService, UniverSheetsPlugin, VALIDATE_CELL, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, checkRangesEditablePermission, deserializeListOptions, getSheetCommandTarget, rangeToDiscreteRange, serializeListOptions } from "@univerjs/sheets";
4
4
  import { ComponentManager, IDialogService, IMenuManagerService, ISidebarService, IconManager, KeyCode, MenuItemType, RibbonDataGroup, RibbonInsertGroup, UniverMobileUIPlugin, getMenuHiddenObservable, useDependency, useEvent, useObservable, useSidebarClick } from "@univerjs/ui";
5
- import { BehaviorSubject, Subject, bufferTime, debounceTime, distinctUntilChanged, filter, map, of, startWith, switchMap, takeUntil } from "rxjs";
5
+ import { BehaviorSubject, Subject, auditTime, bufferTime, debounceTime, distinctUntilChanged, filter, map, of, startWith, switchMap, takeUntil, tap } from "rxjs";
6
6
  import { CURSOR_TYPE, CheckboxShape, DeviceInputEventType, DocSimpleSkeleton, FontCache, IRenderManagerService, Rect, Shape, Text, Transform, UniverRenderEnginePlugin, fixLineWidthByScale, getCurrentTypeOfRenderer, getFontStyleString } from "@univerjs/engine-render";
7
7
  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";
8
8
  import { getPatternType } from "@univerjs/sheets-numfmt";
@@ -14,7 +14,7 @@ import { CheckboxIcon, DataValidationIcon, DatePickerIcon, DeleteIcon, DropdownL
14
14
  import { deserializeRangeWithSheet, serializeRange } from "@univerjs/engine-formula";
15
15
  import { FormulaEditor, RangeSelector } from "@univerjs/sheets-formula-ui";
16
16
 
17
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
17
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
18
18
  function _typeof(o) {
19
19
  "@babel/helpers - typeof";
20
20
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -25,7 +25,7 @@ function _typeof(o) {
25
25
  }
26
26
 
27
27
  //#endregion
28
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
28
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
29
29
  function toPrimitive(t, r) {
30
30
  if ("object" != _typeof(t) || !t) return t;
31
31
  var e = t[Symbol.toPrimitive];
@@ -38,14 +38,14 @@ function toPrimitive(t, r) {
38
38
  }
39
39
 
40
40
  //#endregion
41
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
41
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
42
42
  function toPropertyKey(t) {
43
43
  var i = toPrimitive(t, "string");
44
44
  return "symbol" == _typeof(i) ? i : i + "";
45
45
  }
46
46
 
47
47
  //#endregion
48
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
48
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
49
49
  function _defineProperty(e, r, t) {
50
50
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
51
51
  value: t,
@@ -56,7 +56,7 @@ function _defineProperty(e, r, t) {
56
56
  }
57
57
 
58
58
  //#endregion
59
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
59
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
60
60
  function __decorateParam(paramIndex, decorator) {
61
61
  return function(target, key) {
62
62
  decorator(target, key, paramIndex);
@@ -64,7 +64,7 @@ function __decorateParam(paramIndex, decorator) {
64
64
  }
65
65
 
66
66
  //#endregion
67
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
67
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
68
68
  function __decorate(decorators, target, key, desc) {
69
69
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
70
70
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1054,8 +1054,7 @@ const menuSchema = {
1054
1054
  order: 0,
1055
1055
  gridLayout: {
1056
1056
  row: 1,
1057
- column: 1,
1058
- showLabel: true
1057
+ column: 1
1059
1058
  },
1060
1059
  menuItemFactory: dataValidationMenuFactory,
1061
1060
  [OpenValidationPanelOperation.id]: {
@@ -1072,80 +1071,132 @@ const menuSchema = {
1072
1071
  //#endregion
1073
1072
  //#region package.json
1074
1073
  var name = "@univerjs/sheets-data-validation-ui";
1075
- var version = "1.0.4";
1074
+ var version = "1.1.0";
1076
1075
 
1077
1076
  //#endregion
1078
1077
  //#region src/controllers/dv-alert.controller.ts
1079
1078
  const ALERT_KEY = "SHEET_DATA_VALIDATION_ALERT";
1080
1079
  let DataValidationAlertController = class DataValidationAlertController extends Disposable {
1081
- constructor(_hoverManagerService, _cellAlertManagerService, _univerInstanceService, _localeService, _dataValidationModel) {
1080
+ constructor(_hoverManagerService, _cellAlertManagerService, _univerInstanceService, _localeService, _dataValidationModel, _dataValidationCacheService) {
1082
1081
  super();
1083
1082
  this._hoverManagerService = _hoverManagerService;
1084
1083
  this._cellAlertManagerService = _cellAlertManagerService;
1085
1084
  this._univerInstanceService = _univerInstanceService;
1086
1085
  this._localeService = _localeService;
1087
1086
  this._dataValidationModel = _dataValidationModel;
1087
+ this._dataValidationCacheService = _dataValidationCacheService;
1088
+ _defineProperty(this, "_hoveredCell", null);
1088
1089
  this._init();
1089
1090
  }
1090
1091
  _init() {
1091
1092
  this._initCellAlertPopup();
1092
1093
  }
1093
1094
  _initCellAlertPopup() {
1094
- this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(switchMap((workbook) => (workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) ?? of(null))).subscribe(() => this._cellAlertManagerService.removeAlert(ALERT_KEY)));
1095
- this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(debounceTime(100)).subscribe((cellPos) => {
1096
- if (cellPos) {
1097
- var _workbook$getActiveSh;
1098
- const workbook = this._univerInstanceService.getUnit(cellPos.location.unitId, UniverInstanceType.UNIVER_SHEET);
1099
- if (!workbook || ((_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId()) !== cellPos.location.subUnitId) {
1100
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
1101
- return;
1102
- }
1103
- const worksheet = workbook.getSheetBySheetId(cellPos.location.subUnitId);
1104
- if (!worksheet) return;
1105
- const rule = this._dataValidationModel.getRuleByLocation(cellPos.location.unitId, cellPos.location.subUnitId, cellPos.location.row, cellPos.location.col);
1106
- if (!rule) {
1107
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
1108
- return;
1109
- }
1110
- if (this._dataValidationModel.validator(rule, {
1111
- ...cellPos.location,
1112
- workbook,
1113
- worksheet
1114
- }) === DataValidationStatus.INVALID) {
1115
- var _currentAlert$alert;
1116
- const currentAlert = this._cellAlertManagerService.currentAlert.get(ALERT_KEY);
1117
- const currentLoc = currentAlert === null || currentAlert === void 0 || (_currentAlert$alert = currentAlert.alert) === null || _currentAlert$alert === void 0 ? void 0 : _currentAlert$alert.location;
1118
- if (currentLoc && currentLoc.row === cellPos.location.row && currentLoc.col === cellPos.location.col && currentLoc.subUnitId === cellPos.location.subUnitId && currentLoc.unitId === cellPos.location.unitId) {
1119
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
1120
- return;
1121
- }
1122
- const validator = this._dataValidationModel.getValidator(rule.type);
1123
- if (!validator) {
1124
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
1125
- return;
1126
- }
1127
- this._cellAlertManagerService.showAlert({
1128
- type: CellAlertType.ERROR,
1129
- title: this._localeService.t("sheets-data-validation-ui.error.title"),
1130
- message: validator === null || validator === void 0 ? void 0 : validator.getRuleFinalError(rule, cellPos.location),
1131
- location: cellPos.location,
1132
- width: 200,
1133
- height: 74,
1134
- key: ALERT_KEY
1135
- });
1136
- return;
1137
- }
1095
+ this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(switchMap((workbook) => (workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) ?? of(null))).subscribe(() => {
1096
+ this._hoveredCell = null;
1097
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
1098
+ }));
1099
+ this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(tap(() => {
1100
+ this._hoveredCell = null;
1101
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
1102
+ }), debounceTime(100)).subscribe((cellPos) => {
1103
+ this._hoveredCell = cellPos;
1104
+ this._refreshAlert();
1105
+ }));
1106
+ this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe((change) => {
1107
+ var _change$oldRule;
1108
+ if (this._affectsHoveredCell(change, [...change.rule.ranges, ...((_change$oldRule = change.oldRule) === null || _change$oldRule === void 0 ? void 0 : _change$oldRule.ranges) ?? []])) this._refreshAlert();
1109
+ }));
1110
+ this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(filter((change) => this._affectsHoveredCell(change, change.ranges)), tap(() => this._cellAlertManagerService.removeAlert(ALERT_KEY)), auditTime(0)).subscribe(() => this._refreshAlert()));
1111
+ this.disposeWithMe(this._dataValidationModel.validStatusChange$.subscribe((change) => {
1112
+ if (this._isHoveredLocation(change)) {
1113
+ const rule = this._dataValidationModel.getRuleByLocation(change.unitId, change.subUnitId, change.row, change.col);
1114
+ if ((rule === null || rule === void 0 ? void 0 : rule.uid) === change.ruleId) this._updateAlert(change.status);
1138
1115
  }
1116
+ }));
1117
+ this.disposeWithMe(() => {
1118
+ this._hoveredCell = null;
1119
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
1120
+ });
1121
+ }
1122
+ _isHoveredLocation(location) {
1123
+ var _this$_hoveredCell;
1124
+ const current = (_this$_hoveredCell = this._hoveredCell) === null || _this$_hoveredCell === void 0 ? void 0 : _this$_hoveredCell.location;
1125
+ return (current === null || current === void 0 ? void 0 : current.unitId) === location.unitId && (current === null || current === void 0 ? void 0 : current.subUnitId) === location.subUnitId && (current === null || current === void 0 ? void 0 : current.row) === location.row && (current === null || current === void 0 ? void 0 : current.col) === location.col;
1126
+ }
1127
+ _affectsHoveredCell(location, ranges) {
1128
+ var _this$_hoveredCell2;
1129
+ const current = (_this$_hoveredCell2 = this._hoveredCell) === null || _this$_hoveredCell2 === void 0 ? void 0 : _this$_hoveredCell2.location;
1130
+ return (current === null || current === void 0 ? void 0 : current.unitId) === location.unitId && (current === null || current === void 0 ? void 0 : current.subUnitId) === location.subUnitId && ranges.some((range) => Rectangle.contains(range, {
1131
+ startRow: current.row,
1132
+ endRow: current.row,
1133
+ startColumn: current.col,
1134
+ endColumn: current.col
1135
+ }));
1136
+ }
1137
+ _getHoveredContext() {
1138
+ var _this$_hoveredCell3;
1139
+ const location = (_this$_hoveredCell3 = this._hoveredCell) === null || _this$_hoveredCell3 === void 0 ? void 0 : _this$_hoveredCell3.location;
1140
+ if (!location) return;
1141
+ const workbook = this._univerInstanceService.getUnit(location.unitId, UniverInstanceType.UNIVER_SHEET);
1142
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
1143
+ if (!workbook || !worksheet || worksheet.getSheetId() !== location.subUnitId) return;
1144
+ const rule = this._dataValidationModel.getRuleByLocation(location.unitId, location.subUnitId, location.row, location.col);
1145
+ if (rule) return {
1146
+ location,
1147
+ workbook,
1148
+ worksheet,
1149
+ rule
1150
+ };
1151
+ }
1152
+ _refreshAlert() {
1153
+ const context = this._getHoveredContext();
1154
+ if (!context) {
1139
1155
  this._cellAlertManagerService.removeAlert(ALERT_KEY);
1156
+ return;
1157
+ }
1158
+ const { location, workbook, worksheet, rule } = context;
1159
+ this._updateAlert(this._dataValidationModel.validator(rule, {
1160
+ ...location,
1161
+ workbook,
1162
+ worksheet
1140
1163
  }));
1141
1164
  }
1165
+ _updateAlert(status) {
1166
+ var _this$_cellAlertManag;
1167
+ const context = this._getHoveredContext();
1168
+ if (!context || status !== DataValidationStatus.INVALID) {
1169
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
1170
+ return;
1171
+ }
1172
+ const { location, rule } = context;
1173
+ const validator = this._dataValidationModel.getValidator(rule.type);
1174
+ if (!validator) {
1175
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
1176
+ return;
1177
+ }
1178
+ const title = this._localeService.t("sheets-data-validation-ui.error.title");
1179
+ const message = validator.getRuleFinalError(rule, location);
1180
+ const currentAlert = (_this$_cellAlertManag = this._cellAlertManagerService.currentAlert.get(ALERT_KEY)) === null || _this$_cellAlertManag === void 0 ? void 0 : _this$_cellAlertManag.alert;
1181
+ if (currentAlert && this._isHoveredLocation(currentAlert.location) && currentAlert.title === title && currentAlert.message === message) return;
1182
+ this._cellAlertManagerService.showAlert({
1183
+ type: CellAlertType.ERROR,
1184
+ title,
1185
+ message,
1186
+ location,
1187
+ width: 200,
1188
+ height: 74,
1189
+ key: ALERT_KEY
1190
+ });
1191
+ }
1142
1192
  };
1143
1193
  DataValidationAlertController = __decorate([
1144
1194
  __decorateParam(0, Inject(HoverManagerService)),
1145
1195
  __decorateParam(1, Inject(CellAlertManagerService)),
1146
1196
  __decorateParam(2, IUniverInstanceService),
1147
1197
  __decorateParam(3, Inject(LocaleService)),
1148
- __decorateParam(4, Inject(SheetDataValidationModel))
1198
+ __decorateParam(4, Inject(SheetDataValidationModel)),
1199
+ __decorateParam(5, Inject(DataValidationCacheService))
1149
1200
  ], DataValidationAlertController);
1150
1201
 
1151
1202
  //#endregion
@@ -1487,6 +1538,7 @@ let SheetsDataValidationRenderController = class SheetsDataValidationRenderContr
1487
1538
  this._dataValidationCacheService = _dataValidationCacheService;
1488
1539
  this._editorBridgeService = _editorBridgeService;
1489
1540
  this._initMenu();
1541
+ this._initEditor();
1490
1542
  this._initDropdown();
1491
1543
  this._initViewModelIntercept();
1492
1544
  this._initAutoHeight();
@@ -1494,6 +1546,19 @@ let SheetsDataValidationRenderController = class SheetsDataValidationRenderContr
1494
1546
  _initMenu() {
1495
1547
  this._menuManagerService.mergeMenu(menuSchema);
1496
1548
  }
1549
+ _initEditor() {
1550
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
1551
+ var _this$_editorBridgeSe;
1552
+ if (command.id !== SetCellEditVisibleOperation.id) return;
1553
+ const params = command.params;
1554
+ if (!(params === null || params === void 0 ? void 0 : params.visible) || params.eventType !== DeviceInputEventType.Dblclick || !params.pointerPosition) return;
1555
+ const location = (_this$_editorBridgeSe = this._editorBridgeService) === null || _this$_editorBridgeSe === void 0 ? void 0 : _this$_editorBridgeSe.getEditLocation();
1556
+ if (!location || params.unitId && params.unitId !== location.unitId) return;
1557
+ const { unitId, sheetId, row, column } = location;
1558
+ const rule = this._sheetDataValidationModel.getRuleByLocation(unitId, sheetId, row, column);
1559
+ if (rule && (rule.type === DataValidationType.LIST || rule.type === DataValidationType.LIST_MULTIPLE || rule.type === DataValidationType.CHECKBOX)) throw new CanceledError();
1560
+ }));
1561
+ }
1497
1562
  _initDropdown() {
1498
1563
  if (!this._editorBridgeService) return;
1499
1564
  this.disposeWithMe(this._editorBridgeService.visible$.subscribe((visible) => {