Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat(sheets-data-validation): data validation hover optimize (#4051)

zhangw17bbe40a6a41
diff --git a/packages/sheets-data-validation-ui/src/views/widgets/checkbox-widget.ts b/packages/sheets-data-validation-ui/src/views/widgets/checkbox-widget.ts
index adf177406a..f3b1784982 100644
--- a/packages/sheets-data-validation-ui/src/views/widgets/checkbox-widget.ts
+++ b/packages/sheets-data-validation-ui/src/views/widgets/checkbox-widget.ts
@@ -19,8 +19,8 @@ import type { BaseDataValidator, IBaseDataValidationWidget, IFormulaResult } fro
import type { IMouseEvent, IPointerEvent, UniverRenderingContext, UniverRenderingContext2D } from '@univerjs/engine-render';
import type { ISetRangeValuesCommandParams } from '@univerjs/sheets';
import type { CheckboxValidator } from '@univerjs/sheets-data-validation';
-import { HorizontalAlign, ICommandService, Inject, isFormulaString, ThemeService, VerticalAlign } from '@univerjs/core';
-import { Checkbox, fixLineWidthByScale, Transform } from '@univerjs/engine-render';
+import { HorizontalAlign, ICommandService, Inject, isFormulaString, ThemeService, UniverInstanceType, VerticalAlign } from '@univerjs/core';
+import { Checkbox, CURSOR_TYPE, fixLineWidthByScale, IRenderManagerService, Transform } from '@univerjs/engine-render';
import { SetRangeValuesCommand } from '@univerjs/sheets';
import { CHECKBOX_FORMULA_1, CHECKBOX_FORMULA_2, DataValidationFormulaService, getCellValueOrigin, getFormulaResult, isLegalFormulaResult, transformCheckboxValue } from '@univerjs/sheets-data-validation';
@@ -70,9 +70,9 @@ export class CheckboxRender implements IBaseDataValidationWidget {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@Inject(DataValidationFormulaService) private readonly _formulaService: DataValidationFormulaService,
- @Inject(ThemeService) private readonly _themeService: ThemeService
+ @Inject(ThemeService) private readonly _themeService: ThemeService,
+ @Inject(IRenderManagerService) private readonly _renderManagerService: IRenderManagerService
) {
- // super
}
calcCellAutoHeight(info: ICellRenderContext): number | undefined {
@@ -208,4 +208,12 @@ export class CheckboxRender implements IBaseDataValidationWidget {
params
);
};
+
+ onPointerEnter(info: ICellRenderContext, evt: IPointerEvent | IMouseEvent) {
+ this._renderManagerService.getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_SHEET)?.mainComponent?.setCursor(CURSOR_TYPE.POINTER);
+ }
+
+ onPointerLeave(info: ICellRenderContext, evt: IPointerEvent | IMouseEvent) {
+ this._renderManagerService.getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_SHEET)?.mainComponent?.setCursor(CURSOR_TYPE.DEFAULT);
+ }
}
diff --git a/packages/sheets-data-validation-ui/src/views/widgets/dropdown-multiple-widget.ts b/packages/sheets-data-validation-ui/src/views/widgets/dropdown-multiple-widget.ts
index d61a5cb43d..b13aaf7e85 100644
--- a/packages/sheets-data-validation-ui/src/views/widgets/dropdown-multiple-widget.ts
+++ b/packages/sheets-data-validation-ui/src/views/widgets/dropdown-multiple-widget.ts
@@ -20,8 +20,8 @@ import type { IMouseEvent, IPointerEvent, Spreadsheet, SpreadsheetSkeleton, Univ
import type { ListMultipleValidator } from '@univerjs/sheets-data-validation';
import type { IShowDataValidationDropdownParams } from '../../commands/operations/data-validation.operation';
import type { IDropdownInfo } from './dropdown-widget';
-import { HorizontalAlign, ICommandService, VerticalAlign } from '@univerjs/core';
-import { getFontStyleString } from '@univerjs/engine-render';
+import { HorizontalAlign, ICommandService, Inject, UniverInstanceType, VerticalAlign } from '@univerjs/core';
+import { CURSOR_TYPE, getFontStyleString, IRenderManagerService } from '@univerjs/engine-render';
import { getCellValueOrigin } from '@univerjs/sheets-data-validation';
import { ShowDataValidationDropdown } from '../../commands/operations/data-validation.operation';
import { CELL_PADDING_H, CELL_PADDING_V, Dropdown, ICON_PLACE, layoutDropdowns, MARGIN_V } from './shape';
@@ -33,7 +33,8 @@ export class DropdownMultipleWidget implements IBaseDataValidationWidget {
private _dropdownInfoMap: Map<string, Map<string, IDropdownInfo>> = new Map();
constructor(
- @ICommandService private readonly _commandService: ICommandService
+ @ICommandService private readonly _commandService: ICommandService,
+ @Inject(IRenderManagerService) private readonly _renderManagerService: IRenderManagerService
) {
// empty
}
@@ -246,4 +247,12 @@ export class DropdownMultipleWidget implements IBaseDataValidationWidget {
this._commandService.executeCommand(ShowDataValidationDropdown.id, params);
}
+
+ onPointerEnter(info: ICellRenderContext, evt: IPointerEvent | IMouseEvent) {
+ this._renderManagerService.getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_SHEET)?.mainComponent?.setCursor(CURSOR_TYPE.POINTER);
+ }
+
+ onPointerLeave(info: ICellRenderContext, evt: IPointerEvent | IMouseEvent) {
+ this._renderManagerService.getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_SHEET)?.mainComponent?.setCursor(CURSOR_TYPE.DEFAULT);
+ }
}
diff --git a/packages/sheets-data-validation-ui/src/views/widgets/dropdown-widget.ts b/packages/sheets-data-validation-ui/src/views/widgets/dropdown-widget.ts
index e8647f3561..a6df12a6a5 100644
--- a/packages/sheets-data-validation-ui/src/views/widgets/dropdown-widget.ts
+++ b/packages/sheets-data-validation-ui/src/views/widgets/dropdown-widget.ts
@@ -19,8 +19,8 @@ import type { IBaseDataValidationWidget } from '@univerjs/data-validation';
import type { IMouseEvent, IPointerEvent, SpreadsheetSkeleton, UniverRenderingContext, UniverRenderingContext2D } from '@univerjs/engine-render';
import type { ListValidator } from '@univerjs/sheets-data-validation';
import type { IShowDataValidationDropdownParams } from '../../commands/operations/data-validation.operation';
-import { BooleanNumber, DataValidationRenderMode, DataValidationType, DEFAULT_EMPTY_DOCUMENT_VALUE, DEFAULT_STYLES, DocumentDataModel, HorizontalAlign, ICommandService, Inject, LocaleService, Tools, VerticalAlign, WrapStrategy } from '@univerjs/core';
-import { Documents, DocumentSkeleton, DocumentViewModel, getDocsSkeletonPageSize, Rect } from '@univerjs/engine-render';
+import { BooleanNumber, DataValidationRenderMode, DataValidationType, DEFAULT_EMPTY_DOCUMENT_VALUE, DEFAULT_STYLES, DocumentDataModel, HorizontalAlign, ICommandService, Inject, LocaleService, Tools, UniverInstanceType, VerticalAlign, WrapStrategy } from '@univerjs/core';
+import { CURSOR_TYPE, Documents, DocumentSkeleton, DocumentViewModel, getDocsSkeletonPageSize, IRenderManagerService, Rect } from '@univerjs/engine-render';
import { getCellValueOrigin } from '@univerjs/sheets-data-validation';
import { ShowDataValidationDropdown } from '../../commands/operations/data-validation.operation';
import { DROP_DOWN_DEFAULT_COLOR } from '../../const';
@@ -167,14 +167,13 @@ export class DropdownWidget implements IBaseDataValidationWidget {
constructor(
@Inject(LocaleService) private readonly _localeService: LocaleService,
- @ICommandService private readonly _commandService: ICommandService
+ @ICommandService private readonly _commandService: ICommandService,
+ @Inject(IRenderManagerService) private readonly _renderManagerService: IRenderManagerService
) {
// super
}
zIndex?: number | undefined;
- onPointerEnter?: ((info: ICellRenderContext) => void) | undefined;
- onPointerLeave?: ((info: ICellRenderContext) => void) | undefined;
private _ensureMap(subUnitId: string) {
let map = this._dropdownInfoMap.get(subUnitId);
@@ -506,4 +505,12 @@ export class DropdownWidget implements IBaseDataValidationWidget {
this._commandService.executeCommand(ShowDataValidationDropdown.id, params);
};
+
+ onPointerEnter(info: ICellRenderContext, evt: IPointerEvent | IMouseEvent) {
+ this._renderManagerService.getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_SHEET)?.mainComponent?.setCursor(CURSOR_TYPE.POINTER);
+ }
+
+ onPointerLeave(info: ICellRenderContext, evt: IPointerEvent | IMouseEvent) {
+ this._renderManagerService.getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_SHEET)?.mainComponent?.setCursor(CURSOR_TYPE.DEFAULT);
+ }
}
diff --git a/packages/sheets-ui/src/controllers/cell-custom-render.controller.ts b/packages/sheets-ui/src/controllers/cell-custom-render.controller.ts
index 32385b4c9a..3fdf6941b9 100644
--- a/packages/sheets-ui/src/controllers/cell-custom-render.controller.ts
+++ b/packages/sheets-ui/src/controllers/cell-custom-render.controller.ts
@@ -18,9 +18,10 @@ import type { ICellCustomRender, ICellDataForSheetInterceptor, ICellRenderContex
import type { IMouseEvent, IPointerEvent, IRenderContext, IRenderModule, RenderManagerService, Spreadsheet } from '@univerjs/engine-render';
import type { ICellPermission } from '@univerjs/sheets';
import type { ISheetSkeletonManagerParam } from '../services/sheet-skeleton-manager.service';
-import { Disposable, DisposableCollection, Inject, IPermissionService, sortRules } from '@univerjs/core';
+import { Disposable, DisposableCollection, fromEventSubject, Inject, IPermissionService, sortRules } from '@univerjs/core';
import { IRenderManagerService, Vector2 } from '@univerjs/engine-render';
import { UnitAction, WorkbookEditablePermission, WorksheetEditPermission } from '@univerjs/sheets';
+import { throttleTime } from 'rxjs';
import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';
export class CellCustomRenderController extends Disposable implements IRenderModule {
@@ -162,7 +163,7 @@ export class CellCustomRenderController extends Disposable implements IRenderMod
}
});
- const moveDisposable = spreadsheet.onPointerMove$.subscribeEvent((evt) => {
+ const moveDisposable = fromEventSubject(spreadsheet.onPointerMove$).pipe(throttleTime(30)).subscribe((evt) => {
const activeRenderInfo = getActiveRender(evt);
if (activeRenderInfo) {
const [activeRender, cellContext] = activeRenderInfo;
@@ -182,6 +183,11 @@ export class CellCustomRenderController extends Disposable implements IRenderMod
};
activeRender.onPointerEnter?.(cellContext, evt);
}
+ } else {
+ if (this._enterActiveRender) {
+ this._enterActiveRender.render.onPointerLeave?.(this._enterActiveRender.cellContext, evt);
+ this._enterActiveRender = null;
+ }
}
});